This commit is contained in:
nguyentrungthat 2026-04-29 14:13:19 +07:00
parent baa3216c69
commit 8d5199342d
4 changed files with 19 additions and 36 deletions

View File

@ -57,10 +57,10 @@ class ElectricityBillController extends Controller
) )
->paginate($request->get('per_page', 15)); ->paginate($request->get('per_page', 15));
return $this->ResultSuccess($responseData); return AbstractController::ResultSuccess($responseData);
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error('Error fetching electricity bills: ' . $e->getMessage()); Log::error('Error fetching electricity bills: ' . $e->getMessage());
return $this->ResultError($e->getMessage()); return AbstractController::ResultError($e->getMessage());
} }
} }
@ -81,7 +81,7 @@ class ElectricityBillController extends Controller
// Check if billing_date already exists // Check if billing_date already exists
$existingBill = ElectricityBill::where('billing_date', $validated['billing_date'])->first(); $existingBill = ElectricityBill::where('billing_date', $validated['billing_date'])->first();
if ($existingBill) { if ($existingBill) {
return $this->ResultError('Bill for this month already exists', 422); return AbstractController::ResultError('Bill for this month already exists', 422);
} }
// Calculate total amount // Calculate total amount
@ -98,10 +98,10 @@ class ElectricityBillController extends Controller
'created_by' => auth('admins')->user()->id ?? null, 'created_by' => auth('admins')->user()->id ?? null,
]); ]);
return $this->ResultSuccess($bill, 'Electricity bill created successfully'); return AbstractController::ResultSuccess($bill, 'Electricity bill created successfully');
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error('Error creating electricity bill: ' . $e->getMessage()); Log::error('Error creating electricity bill: ' . $e->getMessage());
return $this->ResultError($e->getMessage()); return AbstractController::ResultError($e->getMessage());
} }
} }
@ -127,7 +127,7 @@ class ElectricityBillController extends Controller
->where('id', '!=', $id) ->where('id', '!=', $id)
->first(); ->first();
if ($existingBill) { if ($existingBill) {
return $this->ResultError('Bill for this month already exists', 422); return AbstractController::ResultError('Bill for this month already exists', 422);
} }
} }
@ -143,10 +143,10 @@ class ElectricityBillController extends Controller
'updated_by' => auth('admins')->user()->id ?? null, 'updated_by' => auth('admins')->user()->id ?? null,
])); ]));
return $this->ResultSuccess($bill, 'Electricity bill updated successfully'); return AbstractController::ResultSuccess($bill, 'Electricity bill updated successfully');
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error('Error updating electricity bill: ' . $e->getMessage()); Log::error('Error updating electricity bill: ' . $e->getMessage());
return $this->ResultError($e->getMessage()); return AbstractController::ResultError($e->getMessage());
} }
} }
@ -159,10 +159,10 @@ class ElectricityBillController extends Controller
$bill = ElectricityBill::findOrFail($id); $bill = ElectricityBill::findOrFail($id);
$bill->delete(); $bill->delete();
return $this->ResultSuccess(null, 'Electricity bill deleted successfully'); return AbstractController::ResultSuccess(null, 'Electricity bill deleted successfully');
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error('Error deleting electricity bill: ' . $e->getMessage()); Log::error('Error deleting electricity bill: ' . $e->getMessage());
return $this->ResultError($e->getMessage()); return AbstractController::ResultError($e->getMessage());
} }
} }
@ -214,7 +214,7 @@ class ElectricityBillController extends Controller
->header('Content-Disposition', 'attachment; filename="' . $fileName . '"'); ->header('Content-Disposition', 'attachment; filename="' . $fileName . '"');
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error('Error exporting electricity bill to PDF: ' . $e->getMessage()); Log::error('Error exporting electricity bill to PDF: ' . $e->getMessage());
return $this->ResultError($e->getMessage()); return AbstractController::ResultError($e->getMessage());
} }
} }
@ -225,10 +225,10 @@ class ElectricityBillController extends Controller
{ {
try { try {
$bill = ElectricityBill::with(['creator', 'updater'])->findOrFail($id); $bill = ElectricityBill::with(['creator', 'updater'])->findOrFail($id);
return $this->ResultSuccess($bill); return AbstractController::ResultSuccess($bill);
} catch (\Exception $e) { } catch (\Exception $e) {
Log::error('Error fetching electricity bill: ' . $e->getMessage()); Log::error('Error fetching electricity bill: ' . $e->getMessage());
return $this->ResultError($e->getMessage()); return AbstractController::ResultError($e->getMessage());
} }
} }

View File

@ -9,21 +9,4 @@ use Illuminate\Routing\Controller as BaseController;
class Controller extends BaseController class Controller extends BaseController
{ {
use AuthorizesRequests, ValidatesRequests; use AuthorizesRequests, ValidatesRequests;
protected function ResultSuccess($data = null, $message = 'Success', $code = 200)
{
return response()->json([
'success' => true,
'message' => $message,
'data' => $data
], $code);
}
protected function ResultError($message = 'Error', $code = 500)
{
return response()->json([
'success' => false,
'message' => $message
], $code);
}
} }

View File

@ -692,9 +692,9 @@ export const DataTablePagination = ({
}) })
// Request to get data API // Request to get data API
const res = await get(url, Object.fromEntries(urlParams.entries())) const res = await get(url, Object.fromEntries(urlParams.entries()))
if (res.status || res.success) { if (res.status) {
setBaseData(res.success ? res?.data : res) setBaseData(res.data?.links ? res?.data : res)
setTData(res.success ? res.data.data : res.data) setTData(res.data?.data ? res.data?.data : res.data)
setSkeletion(false) setSkeletion(false)
navigate({ navigate({
pathname: location.pathname, pathname: location.pathname,

View File

@ -255,7 +255,7 @@ const OfficeSupport = () => {
res = await put(updateElectricityBill(item.id), params) res = await put(updateElectricityBill(item.id), params)
} }
if (res?.success) { if (res?.status) {
notifications.show({ notifications.show({
title: 'Success', title: 'Success',
message: message:
@ -273,8 +273,8 @@ const OfficeSupport = () => {
} }
getAllBills() getAllBills()
} else if (!res?.success && res?.errors) { } else if (!res?.status && res?.errors) {
if (!res?.data?.success && res?.data?.message) { if (!res?.data?.status && res?.data?.message) {
setConfirmMessage(res.data?.message) setConfirmMessage(res.data?.message)
setConfirmValues(values) setConfirmValues(values)
setConfirmModal(true) setConfirmModal(true)