mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
Merge pull request #8152 from turbo124/v5-develop
Minor fixes for transactions
This commit is contained in:
commit
e630c54ddf
@ -52,27 +52,30 @@ class ClientLedgerBalanceUpdate implements ShouldQueue
|
|||||||
MultiDB::setDb($this->company->db);
|
MultiDB::setDb($this->company->db);
|
||||||
|
|
||||||
CompanyLedger::where('balance', 0)->where('client_id', $this->client->id)->orderBy('updated_at', 'ASC')->cursor()->each(function ($company_ledger) {
|
CompanyLedger::where('balance', 0)->where('client_id', $this->client->id)->orderBy('updated_at', 'ASC')->cursor()->each(function ($company_ledger) {
|
||||||
if ($company_ledger->balance > 0) {
|
|
||||||
return;
|
if ($company_ledger->balance == 0)
|
||||||
}
|
{
|
||||||
|
|
||||||
$last_record = CompanyLedger::where('client_id', $company_ledger->client_id)
|
|
||||||
->where('company_id', $company_ledger->company_id)
|
|
||||||
->where('balance', '!=', 0)
|
|
||||||
->orderBy('id', 'DESC')
|
|
||||||
->first();
|
|
||||||
|
|
||||||
if (! $last_record) {
|
|
||||||
$last_record = CompanyLedger::where('client_id', $company_ledger->client_id)
|
$last_record = CompanyLedger::where('client_id', $company_ledger->client_id)
|
||||||
->where('company_id', $company_ledger->company_id)
|
->where('company_id', $company_ledger->company_id)
|
||||||
->orderBy('id', 'DESC')
|
->where('balance', '!=', 0)
|
||||||
->first();
|
->orderBy('id', 'DESC')
|
||||||
|
->first();
|
||||||
|
|
||||||
|
if (! $last_record) {
|
||||||
|
$last_record = CompanyLedger::where('client_id', $company_ledger->client_id)
|
||||||
|
->where('company_id', $company_ledger->company_id)
|
||||||
|
->orderBy('id', 'DESC')
|
||||||
|
->first();
|
||||||
|
}
|
||||||
|
|
||||||
|
// nlog("Updating Balance NOW");
|
||||||
|
|
||||||
|
$company_ledger->balance = $last_record->balance + $company_ledger->adjustment;
|
||||||
|
$company_ledger->save();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// nlog("Updating Balance NOW");
|
|
||||||
|
|
||||||
$company_ledger->balance = $last_record->balance + $company_ledger->adjustment;
|
|
||||||
$company_ledger->save();
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// nlog("Updating company ledger for client ". $this->client->id);
|
// nlog("Updating company ledger for client ". $this->client->id);
|
||||||
|
@ -167,7 +167,7 @@ class CreditService
|
|||||||
}
|
}
|
||||||
|
|
||||||
public function adjustBalance($adjustment)
|
public function adjustBalance($adjustment)
|
||||||
{nlog("adjusting by {$adjustment}");
|
{
|
||||||
$this->credit->balance += $adjustment;
|
$this->credit->balance += $adjustment;
|
||||||
|
|
||||||
return $this;
|
return $this;
|
||||||
|
@ -14,16 +14,10 @@ namespace App\Services\Invoice;
|
|||||||
use App\Events\Invoice\InvoiceWasPaid;
|
use App\Events\Invoice\InvoiceWasPaid;
|
||||||
use App\Events\Payment\PaymentWasCreated;
|
use App\Events\Payment\PaymentWasCreated;
|
||||||
use App\Factory\PaymentFactory;
|
use App\Factory\PaymentFactory;
|
||||||
use App\Jobs\Invoice\InvoiceWorkflowSettings;
|
|
||||||
use App\Jobs\Ninja\TransactionLog;
|
|
||||||
use App\Jobs\Payment\EmailPayment;
|
|
||||||
use App\Libraries\Currency\Conversion\CurrencyApi;
|
use App\Libraries\Currency\Conversion\CurrencyApi;
|
||||||
use App\Models\Client;
|
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
use App\Models\TransactionEvent;
|
|
||||||
use App\Services\AbstractService;
|
use App\Services\AbstractService;
|
||||||
use App\Services\Client\ClientService;
|
|
||||||
use App\Utils\Ninja;
|
use App\Utils\Ninja;
|
||||||
use App\Utils\Traits\GeneratesCounter;
|
use App\Utils\Traits\GeneratesCounter;
|
||||||
use Illuminate\Support\Carbon;
|
use Illuminate\Support\Carbon;
|
||||||
@ -57,15 +51,18 @@ class MarkPaid extends AbstractService
|
|||||||
|
|
||||||
$this->invoice = Invoice::withTrashed()->where('id', $this->invoice->id)->lockForUpdate()->first();
|
$this->invoice = Invoice::withTrashed()->where('id', $this->invoice->id)->lockForUpdate()->first();
|
||||||
|
|
||||||
$this->payable_balance = $this->invoice->balance;
|
if($this->invoice)
|
||||||
|
{
|
||||||
|
$this->payable_balance = $this->invoice->balance;
|
||||||
|
|
||||||
$this->invoice
|
$this->invoice
|
||||||
->service()
|
->service()
|
||||||
->setExchangeRate()
|
->setExchangeRate()
|
||||||
->updateBalance($this->payable_balance * -1)
|
->updateBalance($this->payable_balance * -1)
|
||||||
->updatePaidToDate($this->payable_balance)
|
->updatePaidToDate($this->payable_balance)
|
||||||
->setStatus(Invoice::STATUS_PAID)
|
->setStatus(Invoice::STATUS_PAID)
|
||||||
->save();
|
->save();
|
||||||
|
}
|
||||||
|
|
||||||
}, 1);
|
}, 1);
|
||||||
|
|
||||||
@ -133,16 +130,6 @@ class MarkPaid extends AbstractService
|
|||||||
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
event(new PaymentWasCreated($payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||||
event(new InvoiceWasPaid($this->invoice, $payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
event(new InvoiceWasPaid($this->invoice, $payment, $payment->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
||||||
|
|
||||||
$transaction = [
|
|
||||||
'invoice' => $this->invoice->transaction_event(),
|
|
||||||
'payment' => $payment->transaction_event(),
|
|
||||||
'client' => $this->invoice->client->transaction_event(),
|
|
||||||
'credit' => [],
|
|
||||||
'metadata' => [],
|
|
||||||
];
|
|
||||||
|
|
||||||
// TransactionLog::dispatch(TransactionEvent::INVOICE_MARK_PAID, $transaction, $this->invoice->company->db);
|
|
||||||
|
|
||||||
event('eloquent.updated: App\Models\Invoice', $this->invoice);
|
event('eloquent.updated: App\Models\Invoice', $this->invoice);
|
||||||
|
|
||||||
return $this->invoice;
|
return $this->invoice;
|
||||||
|
@ -40,7 +40,7 @@ class DeletePayment
|
|||||||
|
|
||||||
$this->payment = Payment::withTrashed()->where('id', $this->payment->id)->lockForUpdate()->first();
|
$this->payment = Payment::withTrashed()->where('id', $this->payment->id)->lockForUpdate()->first();
|
||||||
|
|
||||||
if (!$this->payment->is_deleted) {
|
if ($this->payment && !$this->payment->is_deleted) {
|
||||||
|
|
||||||
$this->setStatus(Payment::STATUS_CANCELLED) //sets status of payment
|
$this->setStatus(Payment::STATUS_CANCELLED) //sets status of payment
|
||||||
->updateCreditables() //return the credits first
|
->updateCreditables() //return the credits first
|
||||||
@ -51,7 +51,6 @@ class DeletePayment
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}, 1);
|
}, 1);
|
||||||
|
|
||||||
return $this->payment;
|
return $this->payment;
|
||||||
|
Loading…
Reference in New Issue
Block a user