From 023de23a4501e288323d80a8271af7c199a8148f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sat, 5 Nov 2022 15:13:08 +1100 Subject: [PATCH] Update validation rules --- app/Http/Controllers/InvoiceController.php | 7 ++++--- app/Http/Requests/Credit/StoreCreditRequest.php | 8 +++++++- app/Http/Requests/Credit/UpdateCreditRequest.php | 8 +++++++- app/Http/Requests/Invoice/ActionInvoiceRequest.php | 2 +- app/Http/Requests/Invoice/StoreInvoiceRequest.php | 8 +++++++- app/Http/Requests/Invoice/UpdateInvoiceRequest.php | 6 ++++++ .../StoreRecurringInvoiceRequest.php | 9 ++++++++- .../UpdateRecurringInvoiceRequest.php | 8 +++++++- app/Services/Payment/UpdateInvoicePayment.php | 12 ------------ 9 files changed, 47 insertions(+), 21 deletions(-) diff --git a/app/Http/Controllers/InvoiceController.php b/app/Http/Controllers/InvoiceController.php index bea85e642f..7a9a199a84 100644 --- a/app/Http/Controllers/InvoiceController.php +++ b/app/Http/Controllers/InvoiceController.php @@ -19,6 +19,7 @@ use App\Factory\CloneInvoiceToQuoteFactory; use App\Factory\InvoiceFactory; use App\Filters\InvoiceFilters; use App\Http\Requests\Invoice\ActionInvoiceRequest; +use App\Http\Requests\Invoice\BulkInvoiceRequest; use App\Http\Requests\Invoice\CreateInvoiceRequest; use App\Http\Requests\Invoice\DestroyInvoiceRequest; use App\Http\Requests\Invoice\EditInvoiceRequest; @@ -546,11 +547,11 @@ class InvoiceController extends BaseController * ), * ) */ - public function bulk() + public function bulk(BulkInvoiceRequest $request) { - $action = request()->input('action'); + $action = $request->input('action'); - $ids = request()->input('ids'); + $ids = $request->input('ids'); if(Ninja::isHosted() && (stripos($action, 'email') !== false) && !auth()->user()->company()->account->account_sms_verified) return response(['message' => 'Please verify your account to send emails.'], 400); diff --git a/app/Http/Requests/Credit/StoreCreditRequest.php b/app/Http/Requests/Credit/StoreCreditRequest.php index 6258893af5..6c9dec07a1 100644 --- a/app/Http/Requests/Credit/StoreCreditRequest.php +++ b/app/Http/Requests/Credit/StoreCreditRequest.php @@ -59,7 +59,13 @@ class StoreCreditRequest extends Request $rules['number'] = ['nullable', Rule::unique('credits')->where('company_id', auth()->user()->company()->id)]; $rules['discount'] = 'sometimes|numeric'; $rules['is_amount_discount'] = ['boolean']; - + $rules['tax_rate1'] = 'bail|sometimes|numeric'; + $rules['tax_rate2'] = 'bail|sometimes|numeric'; + $rules['tax_rate3'] = 'bail|sometimes|numeric'; + $rules['tax_name1'] = 'bail|sometimes|string|nullable'; + $rules['tax_name2'] = 'bail|sometimes|string|nullable'; + $rules['tax_name3'] = 'bail|sometimes|string|nullable'; + if ($this->invoice_id) { $rules['invoice_id'] = new ValidInvoiceCreditRule(); } diff --git a/app/Http/Requests/Credit/UpdateCreditRequest.php b/app/Http/Requests/Credit/UpdateCreditRequest.php index ae10af3b75..09f7c09f75 100644 --- a/app/Http/Requests/Credit/UpdateCreditRequest.php +++ b/app/Http/Requests/Credit/UpdateCreditRequest.php @@ -59,7 +59,13 @@ class UpdateCreditRequest extends Request $rules['line_items'] = 'array'; $rules['discount'] = 'sometimes|numeric'; $rules['is_amount_discount'] = ['boolean']; - + $rules['tax_rate1'] = 'bail|sometimes|numeric'; + $rules['tax_rate2'] = 'bail|sometimes|numeric'; + $rules['tax_rate3'] = 'bail|sometimes|numeric'; + $rules['tax_name1'] = 'bail|sometimes|string|nullable'; + $rules['tax_name2'] = 'bail|sometimes|string|nullable'; + $rules['tax_name3'] = 'bail|sometimes|string|nullable'; + return $rules; } diff --git a/app/Http/Requests/Invoice/ActionInvoiceRequest.php b/app/Http/Requests/Invoice/ActionInvoiceRequest.php index ff19f7e547..599488bf3c 100644 --- a/app/Http/Requests/Invoice/ActionInvoiceRequest.php +++ b/app/Http/Requests/Invoice/ActionInvoiceRequest.php @@ -70,4 +70,4 @@ class ActionInvoiceRequest extends Request 'action' => $this->error_msg, ]; } -} +} \ No newline at end of file diff --git a/app/Http/Requests/Invoice/StoreInvoiceRequest.php b/app/Http/Requests/Invoice/StoreInvoiceRequest.php index d6afd0de56..f52bb016aa 100644 --- a/app/Http/Requests/Invoice/StoreInvoiceRequest.php +++ b/app/Http/Requests/Invoice/StoreInvoiceRequest.php @@ -69,7 +69,13 @@ class StoreInvoiceRequest extends Request $rules['line_items'] = 'array'; $rules['discount'] = 'sometimes|numeric'; - + $rules['tax_rate1'] = 'bail|sometimes|numeric'; + $rules['tax_rate2'] = 'bail|sometimes|numeric'; + $rules['tax_rate3'] = 'bail|sometimes|numeric'; + $rules['tax_name1'] = 'bail|sometimes|string|nullable'; + $rules['tax_name2'] = 'bail|sometimes|string|nullable'; + $rules['tax_name3'] = 'bail|sometimes|string|nullable'; + return $rules; } diff --git a/app/Http/Requests/Invoice/UpdateInvoiceRequest.php b/app/Http/Requests/Invoice/UpdateInvoiceRequest.php index 9dffb29ff6..46d50f3cdf 100644 --- a/app/Http/Requests/Invoice/UpdateInvoiceRequest.php +++ b/app/Http/Requests/Invoice/UpdateInvoiceRequest.php @@ -62,6 +62,12 @@ class UpdateInvoiceRequest extends Request $rules['line_items'] = 'array'; $rules['discount'] = 'sometimes|numeric'; $rules['project_id'] = ['bail', 'sometimes', new ValidProjectForClient($this->all())]; + $rules['tax_rate1'] = 'bail|sometimes|numeric'; + $rules['tax_rate2'] = 'bail|sometimes|numeric'; + $rules['tax_rate3'] = 'bail|sometimes|numeric'; + $rules['tax_name1'] = 'bail|sometimes|string|nullable'; + $rules['tax_name2'] = 'bail|sometimes|string|nullable'; + $rules['tax_name3'] = 'bail|sometimes|string|nullable'; return $rules; } diff --git a/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php b/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php index c220fca528..0d6925dc0d 100644 --- a/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php +++ b/app/Http/Requests/RecurringInvoice/StoreRecurringInvoiceRequest.php @@ -58,7 +58,14 @@ class StoreRecurringInvoiceRequest extends Request $rules['project_id'] = ['bail', 'sometimes', new ValidProjectForClient($this->all())]; $rules['number'] = new UniqueRecurringInvoiceNumberRule($this->all()); - + + $rules['tax_rate1'] = 'bail|sometimes|numeric'; + $rules['tax_rate2'] = 'bail|sometimes|numeric'; + $rules['tax_rate3'] = 'bail|sometimes|numeric'; + $rules['tax_name1'] = 'bail|sometimes|string|nullable'; + $rules['tax_name2'] = 'bail|sometimes|string|nullable'; + $rules['tax_name3'] = 'bail|sometimes|string|nullable'; + return $rules; } diff --git a/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php b/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php index b13dc0efc0..0a719fbc30 100644 --- a/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php +++ b/app/Http/Requests/RecurringInvoice/UpdateRecurringInvoiceRequest.php @@ -54,7 +54,13 @@ class UpdateRecurringInvoiceRequest extends Request } $rules['project_id'] = ['bail', 'sometimes', new ValidProjectForClient($this->all())]; - + $rules['tax_rate1'] = 'bail|sometimes|numeric'; + $rules['tax_rate2'] = 'bail|sometimes|numeric'; + $rules['tax_rate3'] = 'bail|sometimes|numeric'; + $rules['tax_name1'] = 'bail|sometimes|string|nullable'; + $rules['tax_name2'] = 'bail|sometimes|string|nullable'; + $rules['tax_name3'] = 'bail|sometimes|string|nullable'; + return $rules; } diff --git a/app/Services/Payment/UpdateInvoicePayment.php b/app/Services/Payment/UpdateInvoicePayment.php index ddc2fd0399..4efbeddb71 100644 --- a/app/Services/Payment/UpdateInvoicePayment.php +++ b/app/Services/Payment/UpdateInvoicePayment.php @@ -63,16 +63,6 @@ class UpdateInvoicePayment } $client->service()->updateBalanceAndPaidToDate($paid_amount*-1, $paid_amount); - - // \DB::connection(config('database.default'))->transaction(function () use($client, $paid_amount){ - - // $update_client = Client::withTrashed()->where('id', $client->id)->lockForUpdate()->first(); - - // $update_client->paid_to_date += $paid_amount; - // $update_client->balance -= $paid_amount; - // $update_client->save(); - - // }, 1); /* Need to determine here is we have an OVER payment - if YES only apply the max invoice amount */ if($paid_amount > $invoice->partial && $paid_amount > $invoice->balance) @@ -86,8 +76,6 @@ class UpdateInvoicePayment $invoice = $invoice->service() ->clearPartial() - // ->updateBalance($paid_amount * -1) - // ->updatePaidToDate($paid_amount) ->updateStatus() ->touchPdf() ->save();