Files
portal-api/app/Http/Controllers/Api/Admin/Customer/Concerns/ManagesCustomerBilling.php
T

99 lines
3.7 KiB
PHP

<?php
namespace App\Http\Controllers\Api\Admin\Customer\Concerns;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
trait ManagesCustomerBilling
{
public function getInvoices(string $uuid): JsonResponse
{
return response()->json(['error' => false, 'data' => $this->billingService->getInvoices($uuid)]);
}
public function updateInvoice(string $uuid, int $invoiceId, Request $request): JsonResponse
{
$data = $request->validate([
'invoice_number' => 'nullable|string|max:50',
'status' => 'nullable|integer|in:1,2,3,4,5',
'payment_method' => 'nullable|in:transfer,balance',
'date' => 'nullable|date',
'due_date' => 'nullable|date',
'date_paid' => 'nullable|date',
'note' => 'nullable|string|max:2000',
'amount_paid' => 'nullable|integer|min:0',
'sub_total' => 'nullable|integer|min:0',
'tax' => 'nullable|integer|min:0',
'total' => 'nullable|integer|min:0',
]);
$invoice = $this->billingService->updateInvoice($uuid, $invoiceId, $data);
return response()->json(['error' => false, 'message' => 'Đã cập nhật hóa đơn', 'data' => $invoice]);
}
public function getTransactions(string $uuid): JsonResponse
{
return response()->json(['error' => false, 'data' => $this->billingService->getTransactions($uuid)]);
}
public function updateTransaction(string $uuid, int $transactionId, Request $request): JsonResponse
{
$data = $request->validate([
'trans' => 'nullable|string|max:255',
'note' => 'nullable|string',
'type' => 'nullable|string|max:50',
'amount' => 'nullable|integer',
]);
$transaction = $this->billingService->updateTransaction($uuid, $transactionId, $data);
return response()->json(['error' => false, 'message' => 'Đã cập nhật giao dịch', 'data' => $transaction]);
}
public function createTransaction(string $uuid, Request $request): JsonResponse
{
$data = $request->validate([
'trans' => 'nullable|string|max:255',
'note' => 'nullable|string',
'amount' => 'required|integer|min:0',
'status' => 'nullable|integer|in:0,1,2',
]);
$transaction = $this->billingService->createTransaction($uuid, $data, $request->user()?->id);
return response()->json(['error' => false, 'message' => 'Đã thêm giao dịch', 'data' => $transaction], 201);
}
public function deleteTransaction(string $uuid, int $transactionId): JsonResponse
{
$this->billingService->deleteTransaction($uuid, $transactionId);
return response()->json(['error' => false, 'message' => 'Đã xoá giao dịch']);
}
public function getOrders(string $uuid): JsonResponse
{
return response()->json(['error' => false, 'data' => $this->billingService->getOrders($uuid)]);
}
public function updateOrder(string $uuid, int $orderId, Request $request): JsonResponse
{
$data = $request->validate([
'order_num' => 'nullable|string|max:255',
'status' => 'nullable|integer|in:0,1,2,3',
'payment_method' => 'nullable|in:transfer,balance',
'date' => 'nullable|date',
'sub_total' => 'nullable|integer|min:0',
'discount_amount' => 'nullable|integer|min:0',
'total' => 'nullable|integer|min:0',
'note' => 'nullable|string|max:5000',
]);
$order = $this->billingService->updateOrder($uuid, $orderId, $data);
return response()->json(['error' => false, 'message' => 'Đã cập nhật đơn hàng', 'data' => $order]);
}
}