1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 00:41:34 +02:00

Working on credit payments

This commit is contained in:
David Bomba 2020-10-20 16:14:11 +11:00
parent 90494547c5
commit fd19e9dc2c
4 changed files with 11 additions and 12 deletions

View File

@ -34,12 +34,13 @@ class UpdatePaymentRequest extends Request
}
public function rules()
{//min:1 removed, 'required'
{
$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'))) {

View File

@ -39,10 +39,4 @@ class UpdateTaskStatusRequest extends Request
return $rules;
}
// protected function prepareForValidation()
// {
// $input = $this->all();
// $this->replace($input);
// }
}

View File

@ -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,6 +147,7 @@ class PaymentRepository extends BaseRepository
}
}
if(!$is_existing_payment)
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars()));
/*info("invoice totals = {$invoice_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();