diff --git a/app/Http/Requests/Payment/StorePaymentRequest.php b/app/Http/Requests/Payment/StorePaymentRequest.php index 60e178160c..bfff80355b 100644 --- a/app/Http/Requests/Payment/StorePaymentRequest.php +++ b/app/Http/Requests/Payment/StorePaymentRequest.php @@ -38,7 +38,7 @@ class StorePaymentRequest extends Request { $input = $this->all(); - //info(print_r($input,1)); + // info(print_r($input,1)); $invoices_total = 0; $credits_total = 0; diff --git a/app/Http/Requests/Payment/UpdatePaymentRequest.php b/app/Http/Requests/Payment/UpdatePaymentRequest.php index 910ef9002d..dbc6331405 100644 --- a/app/Http/Requests/Payment/UpdatePaymentRequest.php +++ b/app/Http/Requests/Payment/UpdatePaymentRequest.php @@ -34,12 +34,13 @@ class UpdatePaymentRequest extends Request } public function rules() - {//min:1 removed, 'required' - $rules = [ + { + + $rules = [ + 'number' => 'nullable|unique:payments,number,'.$this->id.',id,company_id,'.$this->payment->company_id, 'invoices' => ['array', new PaymentAppliedValidAmount, new ValidCreditsPresentRule], 'invoices.*.invoice_id' => 'distinct', 'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx', - 'number' => 'nullable|unique:payments,number,'.$this->id.',id,company_id,'.$this->company_id, ]; if ($this->input('documents') && is_array($this->input('documents'))) { diff --git a/app/Http/Requests/TaskStatus/UpdateTaskStatusRequest.php b/app/Http/Requests/TaskStatus/UpdateTaskStatusRequest.php index 17587dd817..d6e550427f 100644 --- a/app/Http/Requests/TaskStatus/UpdateTaskStatusRequest.php +++ b/app/Http/Requests/TaskStatus/UpdateTaskStatusRequest.php @@ -39,10 +39,4 @@ class UpdateTaskStatusRequest extends Request return $rules; } - // protected function prepareForValidation() - // { - // $input = $this->all(); - - // $this->replace($input); - // } } diff --git a/app/Repositories/PaymentRepository.php b/app/Repositories/PaymentRepository.php index 366610d906..b3b0efb61b 100644 --- a/app/Repositories/PaymentRepository.php +++ b/app/Repositories/PaymentRepository.php @@ -70,11 +70,14 @@ class PaymentRepository extends BaseRepository */ private function applyPayment(array $data, Payment $payment): ?Payment { + $is_existing_payment = true; //check currencies here and fill the exchange rate data if necessary if (! $payment->id) { $this->processExchangeRates($data, $payment); + $is_existing_payment = false; + /*We only update the paid to date ONCE per payment*/ if (array_key_exists('invoices', $data) && is_array($data['invoices']) && count($data['invoices']) > 0) { if ($data['amount'] == '') { @@ -144,7 +147,8 @@ class PaymentRepository extends BaseRepository } } - event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); + if(!$is_existing_payment) + event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars())); /*info("invoice totals = {$invoice_totals}"); info("credit totals = {$credit_totals}"); @@ -162,7 +166,7 @@ class PaymentRepository extends BaseRepository // $payment->applied += $invoice_totals; // } - $payment->applied = $invoice_totals; //wont work because - check tests + $payment->applied += $invoice_totals; //wont work because - check tests $payment->save();