diff --git a/app/Http/Requests/EInvoice/Peppol/UpdateEntityRequest.php b/app/Http/Requests/EInvoice/Peppol/UpdateEntityRequest.php index d2ad78995d..ad70160035 100644 --- a/app/Http/Requests/EInvoice/Peppol/UpdateEntityRequest.php +++ b/app/Http/Requests/EInvoice/Peppol/UpdateEntityRequest.php @@ -53,14 +53,4 @@ class UpdateEntityRequest extends FormRequest $this->replace($input); } - // public function after(): array - // { - // return [ - // function (Validator $validator) { - // if ($this->input('acts_as_sender') === false && $this->input('acts_as_receiver') === false) { - // $validator->errors()->add('acts_as_receiver', ctrans('texts.acts_as_must_be_true')); - // } - // } - // ]; - // } } diff --git a/app/Http/Requests/Invoice/UpdateInvoiceRequest.php b/app/Http/Requests/Invoice/UpdateInvoiceRequest.php index a40d002a66..fc5e3239d6 100644 --- a/app/Http/Requests/Invoice/UpdateInvoiceRequest.php +++ b/app/Http/Requests/Invoice/UpdateInvoiceRequest.php @@ -100,9 +100,14 @@ class UpdateInvoiceRequest extends Request public function withValidator($validator) { - if($this->invoice->company->verifactuEnabled() && $this->invoice->status_id !== \App\Models\Invoice::STATUS_DRAFT){ - $validator->errors()->add('status_id', ctrans('texts.locked_invoice')); - } + $validator->after(function ($validator) { + + if($this->invoice->company->verifactuEnabled() && $this->invoice->status_id !== \App\Models\Invoice::STATUS_DRAFT){ + $validator->errors()->add('status_id', ctrans('texts.locked_invoice')); + } + + }); + } diff --git a/app/Http/Requests/Payment/BulkActionPaymentRequest.php b/app/Http/Requests/Payment/BulkActionPaymentRequest.php index b9acb72ed6..43e9ffbbf2 100644 --- a/app/Http/Requests/Payment/BulkActionPaymentRequest.php +++ b/app/Http/Requests/Payment/BulkActionPaymentRequest.php @@ -38,26 +38,4 @@ class BulkActionPaymentRequest extends Request ]; } - - // public function withValidator($validator) - // { - - // $validator->after(function ($validator) { - // if($this->action == 'delete'){ - // $attached_credits = \App\Models\Payment::withTrashed() - // ->with('credits.payments') - // ->whereIn('id', $this->transformKeys($this->ids)) - // ->company() - // ->map(function ($payment) { - // return $payment->credits()->whereHas('payments', function ($q){ - // $q->withTrashed()->where('is_deleted',0); - // })->count(); - // })->sum(); - - // if($attached_credits > 0){ - // $validator->errors()->add('status_id', 'Payment has attached credits and can not be deleted'); - // } - // } - // }); - // } } diff --git a/app/Http/Requests/Payment/DestroyPaymentRequest.php b/app/Http/Requests/Payment/DestroyPaymentRequest.php index bc172aa16a..765af0b3cf 100644 --- a/app/Http/Requests/Payment/DestroyPaymentRequest.php +++ b/app/Http/Requests/Payment/DestroyPaymentRequest.php @@ -26,18 +26,4 @@ class DestroyPaymentRequest extends Request return auth()->user()->can('edit', $this->payment) && $this->payment->is_deleted === false; } - // public function withValidator($validator) - // { -// $validator->after(function ($validator) { - // $attached_credits = $this->payment - // ->credits() - // ->whereHas('payments', function ($q){ - // $q->withTrashed()->where('is_deleted',0); - // })->count(); - - // if($attached_credits > 0){ - // $validator->errors()->add('status_id', 'Payment has attached credits and can not be deleted'); - // } - // }); - // } } diff --git a/app/Http/Requests/Report/GenericReportRequest.php b/app/Http/Requests/Report/GenericReportRequest.php index 63751418b7..57b4d586eb 100644 --- a/app/Http/Requests/Report/GenericReportRequest.php +++ b/app/Http/Requests/Report/GenericReportRequest.php @@ -12,12 +12,13 @@ namespace App\Http\Requests\Report; -use App\Utils\Ninja; +use App\Models\Design; use App\Http\Requests\Request; -use Illuminate\Auth\Access\AuthorizationException; +use App\Utils\Traits\MakesHash; class GenericReportRequest extends Request { + use MakesHash; /** * Determine if the user is authorized to make this request. * @@ -40,10 +41,24 @@ class GenericReportRequest extends Request 'pdf_email_attachment' => 'sometimes|bool', 'include_deleted' => 'required|bool', 'product_key' => 'sometimes|string|nullable', + 'template_id' => 'sometimes|string|nullable', // 'status' => 'sometimes|string|nullable|in:all,draft,sent,viewed,paid,unpaid,overdue', ]; } + public function withValidator(\Illuminate\Validation\Validator $validator) + { + + $validator->after(function ($validator) { + + if(!empty($this->template_id) && Design::where('id', $this->decodePrimaryKey($this->template_id))->where('is_template',true)->company()->doesntExist()) { + $validator->errors()->add('template_id', 'Invalid Template ID Selected'); + } + + }); + + } + public function prepareForValidation() { $input = $this->all(); diff --git a/app/Http/Requests/TaskScheduler/StoreSchedulerRequest.php b/app/Http/Requests/TaskScheduler/StoreSchedulerRequest.php index 995caee4bf..eec016dd11 100644 --- a/app/Http/Requests/TaskScheduler/StoreSchedulerRequest.php +++ b/app/Http/Requests/TaskScheduler/StoreSchedulerRequest.php @@ -12,12 +12,13 @@ namespace App\Http\Requests\TaskScheduler; +use App\Models\Design; +use App\Models\Invoice; use App\Http\Requests\Request; use App\Utils\Traits\MakesHash; +use Illuminate\Validation\Rule; use App\Http\ValidationRules\Scheduler\ValidClientIds; use App\Http\ValidationRules\Scheduler\InvoiceWithNoExistingSchedule; -use App\Models\Invoice; -use Illuminate\Validation\Rule; class StoreSchedulerRequest extends Request { @@ -102,11 +103,21 @@ class StoreSchedulerRequest extends Request 'parameters.schedule.*.date' => ['bail','sometimes', 'date:Y-m-d'], 'parameters.schedule.*.amount' => ['bail','sometimes', 'numeric'], 'parameters.schedule.*.is_amount' => ['bail','sometimes', 'boolean'], + 'parameters.template_id' => ['bail','sometimes', 'string', 'nullable'], ]; return $rules; } + public function withValidator(\Illuminate\Validation\Validator $validator) + { + $validator->after(function ($validator) { + if(!empty($this->parameters['template_id']) && Design::where('id', $this->decodePrimaryKey($this->parameters['template_id']))->where('is_template',true)->company()->doesntExist()) { + $validator->errors()->add('template_id', 'Invalid Template ID Selected'); + } + }); + } + public function prepareForValidation() { $input = $this->all(); @@ -164,4 +175,4 @@ class StoreSchedulerRequest extends Request 'parameters.invoice_id.required_if' => 'The invoice is required for the payment schedule template.' ]; } -} + | 'include_deleted' \ No newline at end of file diff --git a/app/Http/Requests/TaskScheduler/UpdateSchedulerRequest.php b/app/Http/Requests/TaskScheduler/UpdateSchedulerRequest.php index 97a8981d6d..48280a25bb 100644 --- a/app/Http/Requests/TaskScheduler/UpdateSchedulerRequest.php +++ b/app/Http/Requests/TaskScheduler/UpdateSchedulerRequest.php @@ -12,9 +12,10 @@ namespace App\Http\Requests\TaskScheduler; +use App\Models\Design; use App\Http\Requests\Request; -use App\Http\ValidationRules\Scheduler\ValidClientIds; use Illuminate\Validation\Rule; +use App\Http\ValidationRules\Scheduler\ValidClientIds; class UpdateSchedulerRequest extends Request { @@ -100,11 +101,22 @@ class UpdateSchedulerRequest extends Request 'parameters.schedule.*.date' => ['bail','sometimes', 'date:Y-m-d'], 'parameters.schedule.*.amount' => ['bail','sometimes', 'numeric'], 'parameters.schedule.*.is_amount' => ['bail','sometimes', 'boolean'], + 'parameters.template_id' => ['bail','sometimes', 'string', 'nullable'], ]; return $rules; } + + public function withValidator(\Illuminate\Validation\Validator $validator) + { + $validator->after(function ($validator) { + if(!empty($this->parameters['template_id']) && Design::where('id', $this->decodePrimaryKey($this->parameters['template_id']))->where('is_template',true)->company()->doesntExist()) { + $validator->errors()->add('template_id', 'Invalid Template ID Selected'); + } + }); + } + public function prepareForValidation() { $input = $this->all(); diff --git a/app/Http/Requests/Twilio/GenerateSmsRequest.php b/app/Http/Requests/Twilio/GenerateSmsRequest.php index 18398d4d63..b92d51d188 100644 --- a/app/Http/Requests/Twilio/GenerateSmsRequest.php +++ b/app/Http/Requests/Twilio/GenerateSmsRequest.php @@ -44,7 +44,10 @@ class GenerateSmsRequest extends Request if($count && $count > 1) { \Illuminate\Support\Facades\Cache::put($key, $count + 1, 300); - $validator->errors()->add('phone', 'You requested a verification code recently. Please retry again in a few minutes.'); + $validator->after(function ($validator) { + $validator->errors()->add('phone', 'You requested a verification code recently. Please retry again in a few minutes.'); + }); + } else{ \Illuminate\Support\Facades\Cache::put($key, 1, 300);