mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Ensure credit payments auto archive if configured
This commit is contained in:
parent
f4aae330eb
commit
9a5b1e4292
@ -11,22 +11,25 @@
|
|||||||
|
|
||||||
namespace App\Services\Invoice;
|
namespace App\Services\Invoice;
|
||||||
|
|
||||||
use App\Events\Invoice\InvoiceWasPaid;
|
use Carbon\Carbon;
|
||||||
use App\Events\Payment\PaymentWasCreated;
|
use App\Utils\Ninja;
|
||||||
use App\Factory\PaymentFactory;
|
use App\Utils\Number;
|
||||||
use App\Libraries\MultiDB;
|
|
||||||
use App\Models\Client;
|
use App\Models\Client;
|
||||||
use App\Models\ClientGatewayToken;
|
|
||||||
use App\Models\Credit;
|
use App\Models\Credit;
|
||||||
use App\Models\Invoice;
|
use App\Models\Invoice;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
|
use App\Libraries\MultiDB;
|
||||||
use App\Models\PaymentHash;
|
use App\Models\PaymentHash;
|
||||||
use App\Models\PaymentType;
|
use App\Models\PaymentType;
|
||||||
|
use Illuminate\Support\Str;
|
||||||
|
use App\DataMapper\InvoiceItem;
|
||||||
|
use App\Factory\PaymentFactory;
|
||||||
|
use App\Services\AbstractService;
|
||||||
|
use App\Models\ClientGatewayToken;
|
||||||
|
use App\Events\Invoice\InvoiceWasPaid;
|
||||||
use App\Repositories\CreditRepository;
|
use App\Repositories\CreditRepository;
|
||||||
use App\Repositories\PaymentRepository;
|
use App\Repositories\PaymentRepository;
|
||||||
use App\Services\AbstractService;
|
use App\Events\Payment\PaymentWasCreated;
|
||||||
use App\Utils\Ninja;
|
|
||||||
use Illuminate\Support\Str;
|
|
||||||
|
|
||||||
class AutoBillInvoice extends AbstractService
|
class AutoBillInvoice extends AbstractService
|
||||||
{
|
{
|
||||||
@ -205,11 +208,27 @@ class AutoBillInvoice extends AbstractService
|
|||||||
|
|
||||||
info("adjusting credit balance {$current_credit->balance} by this amount ".$credit['amount']);
|
info("adjusting credit balance {$current_credit->balance} by this amount ".$credit['amount']);
|
||||||
|
|
||||||
|
|
||||||
|
$item_date = Carbon::parse($payment->date)->format($payment->client->date_format());
|
||||||
|
$invoice_numbers = $this->invoice->number;
|
||||||
|
|
||||||
|
$item = new InvoiceItem();
|
||||||
|
$item->quantity = 0;
|
||||||
|
$item->cost = $credit['amount'] * -1;
|
||||||
|
$item->notes = "{$item_date} - " . ctrans('texts.credit_payment', ['invoice_number' => $invoice_numbers]) . " ". Number::formatMoney($credit['amount'], $payment->client);
|
||||||
|
$item->type_id = "1";
|
||||||
|
|
||||||
|
$line_items = $current_credit->line_items;
|
||||||
|
$line_items[] = $item;
|
||||||
|
$current_credit->line_items = $line_items;
|
||||||
|
|
||||||
|
|
||||||
$current_credit->service()
|
$current_credit->service()
|
||||||
->adjustBalance($credit['amount'] * -1)
|
->adjustBalance($credit['amount'] * -1)
|
||||||
->updatePaidToDate($credit['amount'])
|
->updatePaidToDate($credit['amount'])
|
||||||
->setCalculatedStatus()
|
->setCalculatedStatus()
|
||||||
->save();
|
->save();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
$payment->ledger()
|
$payment->ledger()
|
||||||
@ -240,6 +259,7 @@ class AutoBillInvoice extends AbstractService
|
|||||||
return $this->invoice
|
return $this->invoice
|
||||||
->service()
|
->service()
|
||||||
->setCalculatedStatus()
|
->setCalculatedStatus()
|
||||||
|
->workFlow() //07-06-2024 - run the workflow if paid!
|
||||||
->save();
|
->save();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user