Ensure partials are removed when marked as paid

This commit is contained in:
David Bomba 2023-09-27 07:30:35 +10:00
parent f7e2d13de1
commit d86c3ca5fe
3 changed files with 35 additions and 2 deletions

View File

@ -30,7 +30,10 @@ class StoreUserRequest extends Request
*/
public function authorize() : bool
{
return auth()->user()->isAdmin();
/** @var \App\Models\User $user */
$user = auth()->user();
return $user->isAdmin();
}
public function rules()

View File

@ -52,6 +52,7 @@ class MarkPaid extends AbstractService
$this->invoice
->service()
->setExchangeRate()
->clearPartial()
->updateBalance($this->payable_balance * -1)
->updatePaidToDate($this->payable_balance)
->setStatus(Invoice::STATUS_PAID)

View File

@ -49,7 +49,36 @@ class InvoiceTest extends TestCase
$this->invoice_calc = new InvoiceSum($this->invoice);
}
public function testGrossTaxAmountCalcuations()
public function testMarkPaidWithPartial()
{
$item = InvoiceItemFactory::create();
$item->quantity = 1;
$item->cost = 50;
$line_items[] = $item;
$this->invoice->partial = 5;
$this->invoice->partial_due_date = now()->addDay();
$this->invoice->due_date = now()->addDays(10);
$this->invoice->line_items = $line_items;
$this->invoice->save();
$invoice_calc = new InvoiceSum($this->invoice);
$invoice = $invoice_calc->build()->getInvoice()->service()->markSent()->save();
$this->assertEquals(5, $invoice->partial);
$this->assertNotNull($invoice->partial_due_date);
$this->assertEquals(50, $invoice->amount);
$invoice = $invoice->service()->markPaid()->save();
$this->assertEquals(0, $invoice->partial);
$this->assertEquals(0, $invoice->balance);
$this->assertNull($invoice->partial_due_date);
}
public function testGrossTaxAmountCalcuations()
{
$invoice = InvoiceFactory::create($this->company->id, $this->user->id);
$invoice->client_id = $this->client->id;