mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-03 06:54:34 -04:00
Wrap paid to date in transaction
This commit is contained in:
parent
eaf1e193dd
commit
09d5b7c38f
@ -13,7 +13,7 @@ class PaymentFailed extends Exception
|
|||||||
|
|
||||||
public function render($request)
|
public function render($request)
|
||||||
{
|
{
|
||||||
if (auth()->user() || ($request->has('cko-session-id') && $request->query('cko-session-id') )) {
|
if (auth()->guard('contact')->user() || ($request->has('cko-session-id') && $request->query('cko-session-id') )) {
|
||||||
return render('gateways.unsuccessful', [
|
return render('gateways.unsuccessful', [
|
||||||
'message' => $this->getMessage(),
|
'message' => $this->getMessage(),
|
||||||
'code' => $this->getCode(),
|
'code' => $this->getCode(),
|
||||||
|
@ -44,7 +44,7 @@ class ValidCreditsPresentRule implements Rule
|
|||||||
{
|
{
|
||||||
//todo need to ensure the clients credits are here not random ones!
|
//todo need to ensure the clients credits are here not random ones!
|
||||||
|
|
||||||
if (request()->input('credits') && is_array(request()->input('credits'))) {
|
if (request()->input('credits') && is_array(request()->input('credits')) && count(request()->input('credits')) > 0) {
|
||||||
$credit_collection = Credit::whereIn('id', $this->transformKeys(array_column(request()->input('credits'), 'credit_id')))
|
$credit_collection = Credit::whereIn('id', $this->transformKeys(array_column(request()->input('credits'), 'credit_id')))
|
||||||
->count();
|
->count();
|
||||||
|
|
||||||
|
@ -83,7 +83,7 @@ class PaymentRepository extends BaseRepository {
|
|||||||
|
|
||||||
$client->service()->updatePaidToDate($data['amount'])->save();
|
$client->service()->updatePaidToDate($data['amount'])->save();
|
||||||
}
|
}
|
||||||
// elseif($data['amount'] >0){
|
|
||||||
else{
|
else{
|
||||||
//this fixes an edge case with unapplied payments
|
//this fixes an edge case with unapplied payments
|
||||||
$client->service()->updatePaidToDate($data['amount'])->save();
|
$client->service()->updatePaidToDate($data['amount'])->save();
|
||||||
|
@ -14,6 +14,7 @@ namespace App\Services\Payment;
|
|||||||
use App\Events\Invoice\InvoiceWasUpdated;
|
use App\Events\Invoice\InvoiceWasUpdated;
|
||||||
use App\Jobs\Invoice\InvoiceWorkflowSettings;
|
use App\Jobs\Invoice\InvoiceWorkflowSettings;
|
||||||
use App\Jobs\Ninja\TransactionLog;
|
use App\Jobs\Ninja\TransactionLog;
|
||||||
|
use App\Models\Client;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
use App\Models\PaymentHash;
|
use App\Models\PaymentHash;
|
||||||
@ -48,8 +49,6 @@ class UpdateInvoicePayment
|
|||||||
|
|
||||||
collect($paid_invoices)->each(function ($paid_invoice) use ($invoices, $client) {
|
collect($paid_invoices)->each(function ($paid_invoice) use ($invoices, $client) {
|
||||||
|
|
||||||
$client = $client->fresh();
|
|
||||||
|
|
||||||
$invoice = $invoices->first(function ($inv) use ($paid_invoice) {
|
$invoice = $invoices->first(function ($inv) use ($paid_invoice) {
|
||||||
return $paid_invoice->invoice_id == $inv->hashed_id;
|
return $paid_invoice->invoice_id == $inv->hashed_id;
|
||||||
});
|
});
|
||||||
@ -63,9 +62,15 @@ class UpdateInvoicePayment
|
|||||||
$paid_amount = $paid_invoice->amount;
|
$paid_amount = $paid_invoice->amount;
|
||||||
}
|
}
|
||||||
|
|
||||||
$client->paid_to_date += $paid_amount;
|
\DB::connection(config('database.default'))->transaction(function () use($client, $paid_amount){
|
||||||
$client->balance -= $paid_amount;
|
|
||||||
$client->save();
|
$update_client = Client::withTrashed()->where('id', $client->id)->lockForUpdate()->first();
|
||||||
|
|
||||||
|
$update_client->paid_to_date += $paid_amount;
|
||||||
|
$update_client->balance -= $paid_amount;
|
||||||
|
$update_client->save();
|
||||||
|
|
||||||
|
}, 1);
|
||||||
|
|
||||||
/* Need to determine here is we have an OVER payment - if YES only apply the max invoice amount */
|
/* Need to determine here is we have an OVER payment - if YES only apply the max invoice amount */
|
||||||
if($paid_amount > $invoice->partial && $paid_amount > $invoice->balance)
|
if($paid_amount > $invoice->partial && $paid_amount > $invoice->balance)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user