Do not mark a 0 draft invoice as paid automatically

This commit is contained in:
David Bomba 2021-10-25 11:49:11 +11:00
parent e22967f10d
commit 7d896e843b
5 changed files with 24 additions and 20 deletions

View File

@ -92,7 +92,7 @@ class ClientContact extends Authenticatable implements HasLocalePreference
'custom_value4', 'custom_value4',
'email', 'email',
'is_primary', 'is_primary',
// 'client_id', 'send_email',
]; ];
/** /**

View File

@ -113,25 +113,26 @@ class BaseRepository
* @param $action * @param $action
* *
* @return int * @return int
* @deprecated - this doesn't appear to be used anywhere?
*/ */
public function bulk($ids, $action) // public function bulk($ids, $action)
{ // {
if (! $ids) { // if (! $ids) {
return 0; // return 0;
} // }
$ids = $this->transformKeys($ids); // $ids = $this->transformKeys($ids);
$entities = $this->findByPublicIdsWithTrashed($ids); // $entities = $this->findByPublicIdsWithTrashed($ids);
foreach ($entities as $entity) { // foreach ($entities as $entity) {
if (auth()->user()->can('edit', $entity)) { // if (auth()->user()->can('edit', $entity)) {
$this->$action($entity); // $this->$action($entity);
} // }
} // }
return count($entities); // return count($entities);
} // }
/* Returns an invoice if defined as a key in the $resource array*/ /* Returns an invoice if defined as a key in the $resource array*/
public function getInvitation($invitation, $resource) public function getInvitation($invitation, $resource)

View File

@ -134,9 +134,9 @@ class InvoiceService
* *
* @return InvoiceService Parent class object * @return InvoiceService Parent class object
*/ */
public function updateBalance($balance_adjustment) public function updateBalance($balance_adjustment, bool $is_draft = false)
{ {
$this->invoice = (new UpdateBalance($this->invoice, $balance_adjustment))->run(); $this->invoice = (new UpdateBalance($this->invoice, $balance_adjustment, $is_draft))->run();
if ((int)$this->invoice->balance == 0) { if ((int)$this->invoice->balance == 0) {
$this->invoice->next_send_date = null; $this->invoice->next_send_date = null;

View File

@ -47,7 +47,7 @@ class MarkSent extends AbstractService
->service() ->service()
->applyNumber() ->applyNumber()
->setDueDate() ->setDueDate()
->updateBalance($this->invoice->amount) ->updateBalance($this->invoice->amount, true)
->deletePdf() ->deletePdf()
->setReminder() ->setReminder()
->save(); ->save();

View File

@ -20,10 +20,13 @@ class UpdateBalance extends AbstractService
public $balance_adjustment; public $balance_adjustment;
public function __construct($invoice, $balance_adjustment) private $is_draft;
public function __construct($invoice, $balance_adjustment, bool $is_draft)
{ {
$this->invoice = $invoice; $this->invoice = $invoice;
$this->balance_adjustment = $balance_adjustment; $this->balance_adjustment = $balance_adjustment;
$this->is_draft = $is_draft;
} }
public function run() public function run()
@ -34,7 +37,7 @@ class UpdateBalance extends AbstractService
$this->invoice->balance += floatval($this->balance_adjustment); $this->invoice->balance += floatval($this->balance_adjustment);
if ($this->invoice->balance == 0) { if ($this->invoice->balance == 0 && !$this->is_draft) {
$this->invoice->status_id = Invoice::STATUS_PAID; $this->invoice->status_id = Invoice::STATUS_PAID;
} }