mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-06 03:02:34 +01:00
73 lines
1.9 KiB
PHP
73 lines
1.9 KiB
PHP
<?php
|
|
/**
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
*
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
*
|
|
* @copyright Copyright (c) 2019. Invoice Ninja LLC (https://invoiceninja.com)
|
|
*
|
|
* @license https://opensource.org/licenses/AAL
|
|
*/
|
|
|
|
namespace App\Jobs\Invoice;
|
|
|
|
use App\Events\Payment\PaymentWasCreated;
|
|
use App\Factory\PaymentFactory;
|
|
use App\Jobs\Company\UpdateCompanyLedgerWithPayment;
|
|
use App\Jobs\Invoice\ApplyPaymentToInvoice;
|
|
use App\Models\Invoice;
|
|
use App\Models\Payment;
|
|
use App\Repositories\InvoiceRepository;
|
|
use Illuminate\Bus\Queueable;
|
|
use Illuminate\Contracts\Queue\ShouldQueue;
|
|
use Illuminate\Foundation\Bus\Dispatchable;
|
|
use Illuminate\Queue\InteractsWithQueue;
|
|
use Illuminate\Queue\SerializesModels;
|
|
|
|
class MarkInvoicePaid implements ShouldQueue
|
|
{
|
|
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
|
|
|
public $invoice;
|
|
|
|
/**
|
|
* Create a new job instance.
|
|
*
|
|
* @return void
|
|
*/
|
|
public function __construct(Invoice $invoice)
|
|
{
|
|
|
|
$this->invoice = $invoice;
|
|
|
|
}
|
|
|
|
/**
|
|
* Execute the job.
|
|
*
|
|
*
|
|
* @return void
|
|
*/
|
|
public function handle()
|
|
{
|
|
/* Create Payment */
|
|
$payment = PaymentFactory::create($this->invoice->company_id, $this->invoice->user_id);
|
|
|
|
$payment->amount = $this->invoice->balance;
|
|
$payment->status_id = Payment::STATUS_COMPLETED;
|
|
$payment->client_id = $this->invoice->client_id;
|
|
$payment->transaction_reference = ctrans('texts.manual_entry');
|
|
/* Create a payment relationship to the invoice entity */
|
|
$payment->save();
|
|
$payment->invoices()->save($this->invoice);
|
|
$payment->save();
|
|
|
|
/* Update Invoice balance */
|
|
event(new PaymentWasCreated($payment));
|
|
|
|
UpdateCompanyLedgerWithPayment::dispatchNow($payment, ($payment->amount*-1));
|
|
|
|
return $this->invoice;
|
|
}
|
|
}
|