mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Tets
This commit is contained in:
parent
3929d1fd64
commit
9acc02a7df
@ -293,7 +293,7 @@ class Import implements ShouldQueue
|
||||
|
||||
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');
|
||||
|
||||
|
@ -54,6 +54,9 @@ class CompanyPresenter extends EntityPresenter
|
||||
$settings = $this->entity->settings;
|
||||
}
|
||||
|
||||
if(config('ninja.is_docker'))
|
||||
return $this->logo($settings);
|
||||
|
||||
$context_options =array(
|
||||
"ssl"=>array(
|
||||
"verify_peer"=>false,
|
||||
|
@ -46,6 +46,15 @@ class HandleRestore extends AbstractService
|
||||
->where('paymentable_type', '=', 'invoices')
|
||||
->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
|
||||
$payment->paymentables()
|
||||
->where('paymentable_type', '=', 'invoices')
|
||||
@ -57,7 +66,15 @@ class HandleRestore extends AbstractService
|
||||
->where('paymentable_type', '=', 'invoices')
|
||||
->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) {
|
||||
$payment->is_deleted = false;
|
||||
|
@ -86,6 +86,11 @@ class MarkInvoiceDeleted extends AbstractService
|
||||
->where('paymentable_id', $this->invoice->id)
|
||||
->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->applied -= $payment_adjustment;
|
||||
$payment->save();
|
||||
@ -108,12 +113,19 @@ class MarkInvoiceDeleted extends AbstractService
|
||||
->where('paymentable_type', '=', 'invoices')
|
||||
->where('paymentable_id', $this->invoice->id)
|
||||
->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 - refunded');
|
||||
$this->total_payments = $this->invoice->payments->sum('amount') - $this->invoice->payments->sum('refunded');;
|
||||
//$this->total_payments = $this->invoice->payments->sum('amount - refunded');
|
||||
|
||||
nlog("adjustment amount = {$this->adjustment_amount}");
|
||||
nlog("total payments = {$this->total_payments}");
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
@ -40,9 +40,6 @@ class DeleteInvoiceTest extends TestCase
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public function testInvoiceDeletionAfterCancellation()
|
||||
{
|
||||
$data = [
|
||||
@ -137,18 +134,26 @@ class DeleteInvoiceTest extends TestCase
|
||||
|
||||
$payment->refund($data);
|
||||
|
||||
//test balances
|
||||
$this->assertEquals(10, $payment->fresh()->refunded);
|
||||
$this->assertEquals(10, $invoice->client->fresh()->paid_to_date);
|
||||
|
||||
//test balances
|
||||
$this->assertEquals(10, $invoice->fresh()->balance);
|
||||
|
||||
//cancel invoice and paid_to_date
|
||||
$invoice->fresh()->service()->handleCancellation()->save();
|
||||
|
||||
//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
|
||||
$invoice->fresh()->service()->markDeleted()->save();
|
||||
|
||||
//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);
|
||||
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user