Fixes for credit payments

This commit is contained in:
David Bomba 2020-10-21 15:03:22 +11:00
parent a0b269ce99
commit 3d59717776
5 changed files with 17 additions and 9 deletions

View File

@ -322,11 +322,10 @@ class CheckData extends Command
$total_invoice_payments = 0;
foreach ($client->invoices as $invoice) {
info(print_r($invoice->payments,1));
$total_amount = $invoice->payments->sum('pivot.amount'); // the problem with this is that this also will sum the credits
$total_amount = $invoice->payments->sum('pivot.amount');
$total_refund = $invoice->payments->sum('pivot.refunded');
$total_invoice_payments += ($total_amount - $total_refund);
$total_invoice_payments += ($total_amount - $total_refund);
}
foreach($client->payments as $payment)

View File

@ -202,7 +202,7 @@ class BaseController extends Controller
$updated_at = date('Y-m-d H:i:s', $updated_at);
$query->with(
[ 'user.company_users',
[
'company' => function ($query) use ($updated_at) {
$query->whereNotNull('updated_at')->with('documents');
},

View File

@ -73,6 +73,9 @@ class PaymentAmountsBalanceRule implements Rule
return true;
} // if no invoices are present, then this is an unapplied payment, let this pass validation!
info("payment amounts = {$payment_amounts}");
info("invoice amounts = {$invoice_amounts}");
//return true;
return $payment_amounts >= $invoice_amounts;
}
}

View File

@ -93,12 +93,18 @@ info("client paid to date {$client->paid_to_date}");
}
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'));
}
$_credit_totals = array_sum(array_column($data['credits'], 'amount'));
info("client paid to date {$client->paid_to_date}");
$data['amount'] -= $_credit_totals;
info("credit totals = {$_credit_totals}");
$client->service()->updatePaidToDate($_credit_totals)->save();
info("client paid to date {$client->paid_to_date}");
}

View File

@ -29,7 +29,7 @@ class CompanyUserTransformer extends EntityTransformer
protected $defaultIncludes = [
// 'account',
// 'company',
// 'user',
'user',
// 'token'
];