Fixes for paid to datesOM
This commit is contained in:
parent
ae52852ade
commit
41dbbf284e
|
|
@ -102,45 +102,12 @@ class ClientService
|
|||
$this->client->increment('balance', $balance);
|
||||
$this->client->increment('paid_to_date', $paid_to_date);
|
||||
|
||||
/*
|
||||
try {
|
||||
DB::connection(config('database.default'))->transaction(function () use ($balance, $paid_to_date) {
|
||||
$this->client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first();
|
||||
$this->client->balance += $balance;
|
||||
$this->client->paid_to_date += $paid_to_date;
|
||||
$this->client->saveQuietly();
|
||||
}, 2);
|
||||
} catch (\Throwable $throwable) {
|
||||
nlog("DB ERROR " . $throwable->getMessage());
|
||||
|
||||
if (DB::connection(config('database.default'))->transactionLevel() > 0) {
|
||||
DB::connection(config('database.default'))->rollBack();
|
||||
}
|
||||
|
||||
}
|
||||
*/
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function updatePaidToDate(float $amount)
|
||||
{
|
||||
// try {
|
||||
// DB::connection(config('database.default'))->transaction(function () use ($amount) {
|
||||
// $this->client = Client::withTrashed()->where('id', $this->client->id)->lockForUpdate()->first();
|
||||
// $this->client->paid_to_date += $amount;
|
||||
// $this->client->saveQuietly();
|
||||
// }, 2);
|
||||
// } catch (\Throwable $throwable) {
|
||||
// nlog("DB ERROR " . $throwable->getMessage());
|
||||
|
||||
// if (DB::connection(config('database.default'))->transactionLevel() > 0) {
|
||||
// DB::connection(config('database.default'))->rollBack();
|
||||
// }
|
||||
|
||||
// }
|
||||
|
||||
nlog("incrementing paid_to_date by {$amount}");
|
||||
|
||||
$this->client->increment('paid_to_date', $amount);
|
||||
|
||||
return $this;
|
||||
|
|
|
|||
|
|
@ -155,18 +155,16 @@ class DeletePayment
|
|||
}
|
||||
|
||||
//sometimes the payment is NOT created properly, this catches the payment and prevents the paid to date reducing inappropriately.
|
||||
if ($this->update_client_paid_to_date) {
|
||||
// if ($this->update_client_paid_to_date) {
|
||||
|
||||
$reduced_paid_to_date = $this->payment->amount < 0 ? $this->payment->amount * -1 : min(0, ($this->payment->amount - $this->payment->refunded - $this->_paid_to_date_deleted) * -1);
|
||||
// $reduced_paid_to_date = $this->payment->amount < 0 ? $this->payment->amount * -1 : min(0, ($this->payment->amount - $this->payment->refunded - $this->_paid_to_date_deleted) * -1);
|
||||
|
||||
// $reduced_paid_to_date = min(0, ($this->payment->amount - $this->payment->refunded - $this->_paid_to_date_deleted) * -1);
|
||||
|
||||
$this->payment
|
||||
->client
|
||||
->service()
|
||||
->updatePaidToDate($reduced_paid_to_date)
|
||||
->save();
|
||||
}
|
||||
// $this->payment
|
||||
// ->client
|
||||
// ->service()
|
||||
// ->updatePaidToDate($reduced_paid_to_date)
|
||||
// ->save();
|
||||
// }
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue