diff --git a/app/Console/Kernel.php b/app/Console/Kernel.php index 00c38da9b33a..7d1a640ecb4a 100644 --- a/app/Console/Kernel.php +++ b/app/Console/Kernel.php @@ -43,6 +43,7 @@ class Kernel extends ConsoleKernel /* Run queue's in shared hosting with this*/ if (Ninja::isSelfHost()) { $schedule->command('queue:work')->everyMinute()->withoutOverlapping(); + $schedule->command('queue:restart')->everyFiveMinutes(); //we need to add this as we are seeing cached queues mess up the system on first load. } } diff --git a/app/Services/Invoice/HandleReversal.php b/app/Services/Invoice/HandleReversal.php index c6e736972d4b..8a45c13b4269 100644 --- a/app/Services/Invoice/HandleReversal.php +++ b/app/Services/Invoice/HandleReversal.php @@ -64,29 +64,33 @@ class HandleReversal extends AbstractService }); /* Generate a credit for the $total_paid amount */ - $credit = CreditFactory::create($this->invoice->company_id, $this->invoice->user_id); - $credit->client_id = $this->invoice->client_id; + $notes = "Credit for reversal of ".$this->invoice->number; - $item = InvoiceItemFactory::create(); - $item->quantity = 1; - $item->cost = (float)$total_paid; - $item->notes = "Credit for reversal of ".$this->invoice->number; + if($total_paid > 0) + { + $credit = CreditFactory::create($this->invoice->company_id, $this->invoice->user_id); + $credit->client_id = $this->invoice->client_id; - $line_items[] = $item; + $item = InvoiceItemFactory::create(); + $item->quantity = 1; + $item->cost = (float)$total_paid; + $item->notes = $notes; - $credit->line_items = $line_items; + $line_items[] = $item; - $credit->save(); + $credit->line_items = $line_items; - $credit_calc = new InvoiceSum($credit); - $credit_calc->build(); + $credit->save(); - $credit = $credit_calc->getCredit(); + $credit_calc = new InvoiceSum($credit); + $credit_calc->build(); - $credit->service()->markSent()->save(); + $credit = $credit_calc->getCredit(); + $credit->service()->markSent()->save(); + } /* Set invoice balance to 0 */ - $this->invoice->ledger()->updateInvoiceBalance($balance_remaining, $item->notes)->save(); + $this->invoice->ledger()->updateInvoiceBalance($balance_remaining, $notes)->save(); $this->invoice->balance= 0; diff --git a/config/ninja.php b/config/ninja.php index ce51168c6cba..913b2ff825ea 100644 --- a/config/ninja.php +++ b/config/ninja.php @@ -11,8 +11,8 @@ return [ 'app_env' => env('APP_ENV', 'local'), 'app_url' => env('APP_URL', ''), 'app_domain' => env('APP_DOMAIN', ''), - 'app_version' => '0.0.2', - 'api_version' => '0.0.1', + 'app_version' => '0.0.3', + 'api_version' => '0.0.3', 'terms_version' => '1.0.1', 'api_secret' => env('API_SECRET', ''), 'google_maps_api_key' => env('GOOGLE_MAPS_API_KEY'), diff --git a/tests/Unit/InvoiceActionsTest.php b/tests/Unit/InvoiceActionsTest.php index 52739faa56cd..3969a3286f5f 100644 --- a/tests/Unit/InvoiceActionsTest.php +++ b/tests/Unit/InvoiceActionsTest.php @@ -28,7 +28,7 @@ class InvoiceActionsTest extends TestCase public function testInvoiceIsDeletable() { $this->assertTrue($this->invoiceDeletable($this->invoice)); - $this->assertFalse($this->invoiceReversable($this->invoice)); + $this->assertTrue($this->invoiceReversable($this->invoice)); $this->assertFalse($this->invoiceCancellable($this->invoice)); }