mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Client Paid To Date updates
This commit is contained in:
parent
78d8820dae
commit
ccf8aa1dea
@ -84,23 +84,23 @@ class PaymentRepository extends BaseRepository {
|
||||
$data['amount'] = array_sum(array_column($data['invoices'], 'amount'));
|
||||
}
|
||||
|
||||
// $client->service()->updatePaidToDate($data['amount'])->save();
|
||||
$client->paid_to_date += $data['amount'];
|
||||
$client->service()->updatePaidToDate($data['amount'])->save();
|
||||
// $client->paid_to_date += $data['amount'];
|
||||
$client->save();
|
||||
}
|
||||
|
||||
else{
|
||||
//this fixes an edge case with unapplied payments
|
||||
// $client->service()->updatePaidToDate($data['amount'])->save();
|
||||
$client->paid_to_date += $data['amount'];
|
||||
$client->service()->updatePaidToDate($data['amount'])->save();
|
||||
// $client->paid_to_date += $data['amount'];
|
||||
$client->save();
|
||||
}
|
||||
|
||||
if (array_key_exists('credits', $data) && is_array($data['credits']) && count($data['credits']) > 0) {
|
||||
$_credit_totals = array_sum(array_column($data['credits'], 'amount'));
|
||||
|
||||
// $client->service()->updatePaidToDate($_credit_totals)->save();
|
||||
$client->paid_to_date += $_credit_totals;
|
||||
$client->service()->updatePaidToDate($_credit_totals)->save();
|
||||
// $client->paid_to_date += $_credit_totals;
|
||||
$client->save();
|
||||
}
|
||||
|
||||
|
@ -28,14 +28,46 @@ class ClientService
|
||||
|
||||
public function updateBalance(float $amount)
|
||||
{
|
||||
$this->client->balance += $amount;
|
||||
// $this->client->balance += $amount;
|
||||
|
||||
\DB::connection(config('database.default'))->transaction(function () use($amount) {
|
||||
|
||||
$this->client = Client::where('id', $this->client->id)->lockForUpdate()->first();
|
||||
$this->client->balance += $amount;
|
||||
$this->client->save();
|
||||
|
||||
}, 2);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function updateBalanceAndPaidToDate(float $balance, float $paid_to_date)
|
||||
{
|
||||
// $this->client->balance += $amount;
|
||||
|
||||
\DB::connection(config('database.default'))->transaction(function () use($amount) {
|
||||
|
||||
$this->client = Client::where('id', $this->client->id)->lockForUpdate()->first();
|
||||
$this->client->balance += $balance;
|
||||
$this->client->paid_to_date += $paid_to_date;
|
||||
$this->client->save();
|
||||
|
||||
}, 2);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function updatePaidToDate(float $amount)
|
||||
{
|
||||
$this->client->paid_to_date += $amount;
|
||||
// $this->client->paid_to_date += $amount;
|
||||
|
||||
\DB::connection(config('database.default'))->transaction(function () use($amount) {
|
||||
|
||||
$this->client = Client::where('id', $this->client->id)->lockForUpdate()->first();
|
||||
$this->client->paid_to_date += $amount;
|
||||
$this->client->save();
|
||||
|
||||
}, 2);
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user