mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Append DELETED to invoice number on delete action
This commit is contained in:
parent
2627ec8894
commit
a43688fd30
@ -83,7 +83,9 @@ class InvoiceRepository extends BaseRepository
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
$invoice->service()->handleCancellation()->save();
|
$invoice->service()->markDeleted()->handleCancellation()->save();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$invoice = parent::delete($invoice);
|
$invoice = parent::delete($invoice);
|
||||||
|
|
||||||
|
@ -24,6 +24,7 @@ use App\Services\Invoice\CreateInvitations;
|
|||||||
use App\Services\Invoice\GetInvoicePdf;
|
use App\Services\Invoice\GetInvoicePdf;
|
||||||
use App\Services\Invoice\HandleCancellation;
|
use App\Services\Invoice\HandleCancellation;
|
||||||
use App\Services\Invoice\HandleReversal;
|
use App\Services\Invoice\HandleReversal;
|
||||||
|
use App\Services\Invoice\MarkInvoiceDeleted;
|
||||||
use App\Services\Invoice\MarkInvoicePaid;
|
use App\Services\Invoice\MarkInvoicePaid;
|
||||||
use App\Services\Invoice\MarkSent;
|
use App\Services\Invoice\MarkSent;
|
||||||
use App\Services\Invoice\TriggeredActions;
|
use App\Services\Invoice\TriggeredActions;
|
||||||
@ -154,6 +155,13 @@ class InvoiceService
|
|||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function markDeleted()
|
||||||
|
{
|
||||||
|
$this->invoice = (new MarkInvoiceDeleted($this->invoice))->run();
|
||||||
|
|
||||||
|
return $this;
|
||||||
|
}
|
||||||
|
|
||||||
public function reverseCancellation()
|
public function reverseCancellation()
|
||||||
{
|
{
|
||||||
$this->invoice = (new HandleCancellation($this->invoice))->reverse();
|
$this->invoice = (new HandleCancellation($this->invoice))->reverse();
|
||||||
|
71
app/Services/Invoice/MarkInvoiceDeleted.php
Normal file
71
app/Services/Invoice/MarkInvoiceDeleted.php
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
<?php
|
||||||
|
/**
|
||||||
|
* Invoice Ninja (https://invoiceninja.com).
|
||||||
|
*
|
||||||
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||||
|
*
|
||||||
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
||||||
|
*
|
||||||
|
* @license https://opensource.org/licenses/AAL
|
||||||
|
*/
|
||||||
|
|
||||||
|
namespace App\Services\Invoice;
|
||||||
|
|
||||||
|
use App\Events\Invoice\InvoiceWasCancelled;
|
||||||
|
use App\Events\Payment\PaymentWasCreated;
|
||||||
|
use App\Factory\CreditFactory;
|
||||||
|
use App\Factory\InvoiceItemFactory;
|
||||||
|
use App\Factory\PaymentFactory;
|
||||||
|
use App\Helpers\Invoice\InvoiceSum;
|
||||||
|
use App\Models\Client;
|
||||||
|
use App\Models\Invoice;
|
||||||
|
use App\Models\Payment;
|
||||||
|
use App\Models\Paymentable;
|
||||||
|
use App\Services\AbstractService;
|
||||||
|
use App\Services\Client\ClientService;
|
||||||
|
use App\Services\Payment\PaymentService;
|
||||||
|
use App\Utils\Ninja;
|
||||||
|
use App\Utils\Traits\GeneratesCounter;
|
||||||
|
|
||||||
|
class MarkInvoiceDeleted extends AbstractService
|
||||||
|
{
|
||||||
|
use GeneratesCounter;
|
||||||
|
|
||||||
|
private $invoice;
|
||||||
|
|
||||||
|
public function __construct(Invoice $invoice)
|
||||||
|
{
|
||||||
|
$this->invoice = $invoice;
|
||||||
|
}
|
||||||
|
|
||||||
|
public function run()
|
||||||
|
{
|
||||||
|
$check = false;
|
||||||
|
$x=0;
|
||||||
|
|
||||||
|
do {
|
||||||
|
|
||||||
|
$number = $this->calcNumber($x);
|
||||||
|
$check = $this->checkNumberAvailable(Invoice::class, $this->invoice, $number);
|
||||||
|
$x++;
|
||||||
|
|
||||||
|
} while (!$check);
|
||||||
|
|
||||||
|
$this->invoice->number = $number;
|
||||||
|
|
||||||
|
return $this->invoice;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private function calcNumber($x)
|
||||||
|
{
|
||||||
|
if($x==0)
|
||||||
|
$number = $this->invoice->number . '_' . ctrans('texts.deleted');
|
||||||
|
else
|
||||||
|
$number = $this->invoice->number . '_' . ctrans('texts.deleted') . '_'. $x;
|
||||||
|
|
||||||
|
return $number;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -306,6 +306,16 @@ trait GeneratesCounter
|
|||||||
return $number;
|
return $number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/*Check if a number is available for use. */
|
||||||
|
public function checkNumberAvailable($class, $entity, $number) :bool
|
||||||
|
{
|
||||||
|
if($entity = $class::whereCompanyId($entity->company_id)->whereNumber($number)->withTrashed()->first())
|
||||||
|
return false;
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Saves counters at both the company and client level.
|
* Saves counters at both the company and client level.
|
||||||
*
|
*
|
||||||
|
@ -53,6 +53,7 @@ trait HasRecurrence
|
|||||||
*/
|
*/
|
||||||
public function setDayOfMonth($date, $day_of_month)
|
public function setDayOfMonth($date, $day_of_month)
|
||||||
{
|
{
|
||||||
|
$data = Carbon::parse($date);
|
||||||
|
|
||||||
$set_date = $date->copy()->setUnitNoOverflow('day', $day_of_month, 'month');
|
$set_date = $date->copy()->setUnitNoOverflow('day', $day_of_month, 'month');
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user