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',
'email',
'is_primary',
// 'client_id',
'send_email',
];
/**

View File

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

View File

@ -134,9 +134,9 @@ class InvoiceService
*
* @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) {
$this->invoice->next_send_date = null;

View File

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

View File

@ -20,10 +20,13 @@ class UpdateBalance extends AbstractService
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->balance_adjustment = $balance_adjustment;
$this->is_draft = $is_draft;
}
public function run()
@ -34,7 +37,7 @@ class UpdateBalance extends AbstractService
$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;
}