2019-04-04 01:17:15 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
2019-04-16 05:28:05 +02:00
|
|
|
use App\Helpers\Invoice\InvoiceCalc;
|
2019-04-04 01:17:15 +02:00
|
|
|
use App\Models\Invoice;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
/**
|
2019-04-16 05:28:05 +02:00
|
|
|
* InvoiceRepository
|
2019-04-04 01:17:15 +02:00
|
|
|
*/
|
|
|
|
class InvoiceRepository extends BaseRepository
|
|
|
|
{
|
|
|
|
|
2019-04-16 05:28:05 +02:00
|
|
|
|
2019-05-09 00:47:38 +02:00
|
|
|
/**
|
|
|
|
* Gets the class name.
|
|
|
|
*
|
|
|
|
* @return ::class The class name.
|
|
|
|
*/
|
2019-04-04 01:17:15 +02:00
|
|
|
public function getClassName()
|
|
|
|
{
|
|
|
|
return Invoice::class;
|
|
|
|
}
|
2019-05-09 00:47:38 +02:00
|
|
|
|
2019-04-04 01:17:15 +02:00
|
|
|
|
2019-05-09 00:47:38 +02:00
|
|
|
/**
|
|
|
|
* Saves the invoices
|
|
|
|
*
|
|
|
|
* @param array. $data The invoice data
|
|
|
|
* @param InvoiceCalc|\App\Models\Invoice $invoice The invoice
|
|
|
|
*
|
|
|
|
* @return Invoice|InvoiceCalc|\App\Models\Invoice|null Returns the invoice object
|
|
|
|
*/
|
|
|
|
public function save($data, Invoice $invoice) : ?Invoice
|
2019-04-04 01:17:15 +02:00
|
|
|
{
|
2019-05-09 07:29:31 +02:00
|
|
|
|
2019-05-06 07:34:59 +02:00
|
|
|
$invoice->fill($data);
|
2019-04-16 07:28:30 +02:00
|
|
|
|
2019-04-04 01:17:15 +02:00
|
|
|
$invoice->save();
|
|
|
|
|
2019-04-24 12:01:40 +02:00
|
|
|
$invoice_calc = new InvoiceCalc($invoice, $invoice->settings);
|
2019-04-16 07:28:30 +02:00
|
|
|
|
|
|
|
$invoice = $invoice_calc->build()->getInvoice();
|
|
|
|
|
2019-05-09 07:29:31 +02:00
|
|
|
$invoice->save();
|
|
|
|
|
2019-04-04 01:17:15 +02:00
|
|
|
return $invoice;
|
2019-05-09 07:29:31 +02:00
|
|
|
|
2019-04-04 01:17:15 +02:00
|
|
|
}
|
|
|
|
|
2019-05-09 00:47:38 +02:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Mark the invoice as sent.
|
|
|
|
*
|
|
|
|
* @param \App\Models\Invoice $invoice The invoice
|
|
|
|
*
|
|
|
|
* @return Invoice|\App\Models\Invoice|null Return the invoice object
|
|
|
|
*/
|
|
|
|
public function markSent(Invoice $invoice) : ?Invoice
|
|
|
|
{
|
|
|
|
|
|
|
|
if($invoice->status_id >= Invoice::STATUS_SENT)
|
|
|
|
return;
|
|
|
|
|
|
|
|
$invoice->status_id = Invoice::STATUS_SENT;
|
|
|
|
$invoice->save();
|
|
|
|
|
|
|
|
return $invoice;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2019-04-04 01:17:15 +02:00
|
|
|
}
|