mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Working on credit payments
This commit is contained in:
parent
6f84e07c10
commit
aa0735bb3d
@ -333,7 +333,7 @@ class CheckData extends Command
|
||||
$credit_total_applied += $payment->paymentables->where('paymentable_type', App\Models\Credit::class)->sum(\DB::raw('amount'));
|
||||
}
|
||||
|
||||
$total_invoice_payments += $credit_total_applied;
|
||||
$total_invoice_payments += $credit_total_applied; //todo this is contentious
|
||||
|
||||
info("total invoice payments = {$total_invoice_payments} with client paid to date of of {$client->paid_to_date}");
|
||||
|
||||
|
@ -77,7 +77,7 @@ class StorePaymentRequest extends Request
|
||||
|
||||
if (! isset($input['amount']) || $input['amount'] == 0) {
|
||||
//$input['amount'] = $invoices_total - $credits_total;
|
||||
$input['amount'] = $invoices_total;
|
||||
$input['amount'] = $invoices_total - $credits_total; //todo the payment amount is always less the credit amount applied
|
||||
}
|
||||
|
||||
$input['is_manual'] = true;
|
||||
@ -94,17 +94,15 @@ class StorePaymentRequest extends Request
|
||||
$rules = [
|
||||
'amount' => 'numeric|required',
|
||||
'amount' => [new PaymentAmountsBalanceRule(), new ValidCreditsPresentRule()],
|
||||
//'date' => 'required',
|
||||
'client_id' => 'bail|required|exists:clients,id',
|
||||
'invoices.*.invoice_id' => 'required|distinct|exists:invoices,id',
|
||||
'invoices.*.invoice_id' => 'bail|required|distinct|exists:invoices,id',
|
||||
'invoices.*.invoice_id' => new ValidInvoicesRules($this->all()),
|
||||
'invoices.*.amount' => 'required',
|
||||
'credits.*.credit_id' => 'required|exists:credits,id',
|
||||
'credits.*.credit_id' => 'bail|required|exists:credits,id',
|
||||
'credits.*.credit_id' => new ValidCreditsRules($this->all()),
|
||||
'credits.*.amount' => 'required',
|
||||
'invoices' => new ValidPayableInvoicesRule(),
|
||||
'number' => 'nullable|unique:payments,number,'.$this->id.',id,company_id,'.$this->company_id,
|
||||
//'number' => 'nullable',
|
||||
'number' => 'bail|nullable|unique:payments,number,'.$this->id.',id,company_id,'.$this->company_id,
|
||||
];
|
||||
|
||||
if ($this->input('documents') && is_array($this->input('documents'))) {
|
||||
|
@ -88,6 +88,14 @@ class PaymentRepository extends BaseRepository
|
||||
|
||||
$client->service()->updatePaidToDate($data['amount'])->save();
|
||||
}
|
||||
//todo
|
||||
if (array_key_exists('credits', $data) && is_array($data['credits']) && count($data['credits']) > 0) {
|
||||
if ($data['amount'] == '') {
|
||||
$data['amount'] += array_sum(array_column($data['credits'], 'amount'));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/*Fill the payment*/
|
||||
@ -166,7 +174,7 @@ class PaymentRepository extends BaseRepository
|
||||
// $payment->applied += $invoice_totals;
|
||||
// }
|
||||
|
||||
$payment->applied += $invoice_totals; //wont work because - check tests
|
||||
$payment->applied += ($invoice_totals - $credit_totals); //wont work because - check tests
|
||||
|
||||
$payment->save();
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user