This commit is contained in:
David Bomba 2021-07-31 19:59:04 +10:00
parent 3929d1fd64
commit 9acc02a7df
5 changed files with 48 additions and 11 deletions

View File

@ -293,7 +293,7 @@ class Import implements ShouldQueue
private function setInitialCompanyLedgerBalances() private function setInitialCompanyLedgerBalances()
{ {
Client::cursor()->each(function ($client) { Client::where('company_id', $this->company->id)->cursor()->each(function ($client) {
$invoice_balances = $client->invoices->where('is_deleted', false)->where('status_id', '>', 1)->sum('balance'); $invoice_balances = $client->invoices->where('is_deleted', false)->where('status_id', '>', 1)->sum('balance');

View File

@ -54,6 +54,9 @@ class CompanyPresenter extends EntityPresenter
$settings = $this->entity->settings; $settings = $this->entity->settings;
} }
if(config('ninja.is_docker'))
return $this->logo($settings);
$context_options =array( $context_options =array(
"ssl"=>array( "ssl"=>array(
"verify_peer"=>false, "verify_peer"=>false,

View File

@ -46,6 +46,15 @@ class HandleRestore extends AbstractService
->where('paymentable_type', '=', 'invoices') ->where('paymentable_type', '=', 'invoices')
->sum(\DB::raw('amount')); ->sum(\DB::raw('amount'));
nlog("first pre restore amount = {$pre_restore_amount}");
$pre_restore_amount -= $payment->paymentables()
->where('paymentable_type', '=', 'invoices')
->sum(\DB::raw('refunded'));
nlog("second pre restore amount = {$pre_restore_amount}");
//restore the paymentables //restore the paymentables
$payment->paymentables() $payment->paymentables()
->where('paymentable_type', '=', 'invoices') ->where('paymentable_type', '=', 'invoices')
@ -57,7 +66,15 @@ class HandleRestore extends AbstractService
->where('paymentable_type', '=', 'invoices') ->where('paymentable_type', '=', 'invoices')
->sum(\DB::raw('amount')); ->sum(\DB::raw('amount'));
info($payment->amount . " == " . $payment_amount); nlog("first payment_amount = {$payment_amount}");
$payment_amount -= $payment->paymentables()
->where('paymentable_type', '=', 'invoices')
->sum(\DB::raw('refunded'));
nlog("second payment_amount = {$payment_amount}");
nlog($payment->amount . " == " . $payment_amount);
if ($payment->amount == $payment_amount) { if ($payment->amount == $payment_amount) {
$payment->is_deleted = false; $payment->is_deleted = false;

View File

@ -36,7 +36,7 @@ class MarkInvoiceDeleted extends AbstractService
if ($this->invoice->is_deleted) { if ($this->invoice->is_deleted) {
return $this->invoice; return $this->invoice;
} }
$this->cleanup() $this->cleanup()
->setAdjustmentAmount() ->setAdjustmentAmount()
->deletePaymentables() ->deletePaymentables()
@ -86,6 +86,11 @@ class MarkInvoiceDeleted extends AbstractService
->where('paymentable_id', $this->invoice->id) ->where('paymentable_id', $this->invoice->id)
->sum(DB::raw('amount')); ->sum(DB::raw('amount'));
$payment_adjustment -= $payment->paymentables
->where('paymentable_type', '=', 'invoices')
->where('paymentable_id', $this->invoice->id)
->sum(DB::raw('refunded'));
$payment->amount -= $payment_adjustment; $payment->amount -= $payment_adjustment;
$payment->applied -= $payment_adjustment; $payment->applied -= $payment_adjustment;
$payment->save(); $payment->save();
@ -108,12 +113,19 @@ class MarkInvoiceDeleted extends AbstractService
->where('paymentable_type', '=', 'invoices') ->where('paymentable_type', '=', 'invoices')
->where('paymentable_id', $this->invoice->id) ->where('paymentable_id', $this->invoice->id)
->sum(DB::raw('amount')); ->sum(DB::raw('amount'));
//->sum(DB::raw('amount - refunded'));
$this->adjustment_amount -= $payment->paymentables
->where('paymentable_type', '=', 'invoices')
->where('paymentable_id', $this->invoice->id)
->sum(DB::raw('refunded'));
} }
$this->total_payments = $this->invoice->payments->sum('amount'); $this->total_payments = $this->invoice->payments->sum('amount') - $this->invoice->payments->sum('refunded');;
// $this->total_payments = $this->invoice->payments->sum('amount - refunded'); //$this->total_payments = $this->invoice->payments->sum('amount - refunded');
nlog("adjustment amount = {$this->adjustment_amount}");
nlog("total payments = {$this->total_payments}");
return $this; return $this;
} }

View File

@ -40,9 +40,6 @@ class DeleteInvoiceTest extends TestCase
); );
} }
public function testInvoiceDeletionAfterCancellation() public function testInvoiceDeletionAfterCancellation()
{ {
$data = [ $data = [
@ -137,18 +134,26 @@ class DeleteInvoiceTest extends TestCase
$payment->refund($data); $payment->refund($data);
//test balances
$this->assertEquals(10, $payment->fresh()->refunded); $this->assertEquals(10, $payment->fresh()->refunded);
$this->assertEquals(10, $invoice->client->fresh()->paid_to_date); $this->assertEquals(10, $invoice->client->fresh()->paid_to_date);
$this->assertEquals(10, $invoice->fresh()->balance);
//test balances
//cancel invoice and paid_to_date //cancel invoice and paid_to_date
$invoice->fresh()->service()->handleCancellation()->save();
//test balances and paid_to_date //test balances and paid_to_date
$this->assertEquals(0, $invoice->fresh()->balance);
$this->assertEquals(0, $invoice->client->fresh()->balance);
$this->assertEquals(10, $invoice->client->fresh()->paid_to_date);
//delete invoice //delete invoice
$invoice->fresh()->service()->markDeleted()->save();
//test balances and paid_to_date //test balances and paid_to_date
$this->assertEquals(0, $invoice->fresh()->balance);
$this->assertEquals(0, $invoice->client->fresh()->balance);
$this->assertEquals(0, $invoice->client->fresh()->paid_to_date);
} }