2019-04-04 10:17:15 +11:00
|
|
|
<?php
|
2019-05-11 13:32:07 +10:00
|
|
|
/**
|
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
|
*
|
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
|
*
|
2020-01-07 11:13:47 +11:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 13:32:07 +10:00
|
|
|
*
|
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
|
*/
|
2019-04-04 10:17:15 +11:00
|
|
|
|
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
|
2020-04-04 21:32:42 +11:00
|
|
|
use App\Events\Invoice\InvoiceWasDeleted;
|
2019-05-29 14:33:53 +10:00
|
|
|
use App\Factory\InvoiceInvitationFactory;
|
2019-12-27 09:33:07 +11:00
|
|
|
use App\Jobs\Product\UpdateOrCreateProduct;
|
2020-02-26 16:18:38 +11:00
|
|
|
use App\Models\Client;
|
2019-09-23 13:22:24 +10:00
|
|
|
use App\Models\ClientContact;
|
2019-04-04 10:17:15 +11:00
|
|
|
use App\Models\Invoice;
|
2019-05-29 14:33:53 +10:00
|
|
|
use App\Models\InvoiceInvitation;
|
2019-09-23 13:22:24 +10:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2019-04-04 10:17:15 +11:00
|
|
|
|
|
|
|
|
/**
|
2019-04-16 13:28:05 +10:00
|
|
|
* InvoiceRepository
|
2019-04-04 10:17:15 +11:00
|
|
|
*/
|
2020-02-10 20:53:02 +11:00
|
|
|
|
2020-03-21 16:37:30 +11:00
|
|
|
class InvoiceRepository extends BaseRepository
|
|
|
|
|
{
|
|
|
|
|
use MakesHash;
|
2020-02-10 20:53:02 +11:00
|
|
|
|
2020-03-21 16:37:30 +11:00
|
|
|
/**
|
|
|
|
|
* Gets the class name.
|
|
|
|
|
*
|
|
|
|
|
* @return string The class name.
|
|
|
|
|
*/
|
|
|
|
|
public function getClassName()
|
|
|
|
|
{
|
2020-07-27 18:22:57 +10:00
|
|
|
return Invoice::class;
|
2020-03-21 16:37:30 +11:00
|
|
|
}
|
2020-02-10 20:53:02 +11:00
|
|
|
|
2020-03-21 16:37:30 +11:00
|
|
|
/**
|
|
|
|
|
* Saves the invoices
|
|
|
|
|
*
|
|
|
|
|
* @param array. $data The invoice data
|
|
|
|
|
* @param InvoiceSum|\App\Models\Invoice $invoice The invoice
|
|
|
|
|
*
|
|
|
|
|
* @return Invoice|InvoiceSum|\App\Models\Invoice|null Returns the invoice object
|
|
|
|
|
*/
|
|
|
|
|
public function save($data, Invoice $invoice):?Invoice
|
|
|
|
|
{
|
|
|
|
|
return $this->alternativeSave($data, $invoice);
|
|
|
|
|
}
|
2020-02-10 20:53:02 +11:00
|
|
|
|
2020-03-21 16:37:30 +11: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
|
|
|
|
|
{
|
|
|
|
|
return $invoice->service()->markSent()->save();
|
|
|
|
|
}
|
2020-03-02 21:22:37 +11:00
|
|
|
|
|
|
|
|
public function getInvitationByKey($key) :?InvoiceInvitation
|
|
|
|
|
{
|
|
|
|
|
return InvoiceInvitation::whereRaw("BINARY `key`= ?", [$key])->first();
|
|
|
|
|
}
|
2020-04-04 21:32:42 +11:00
|
|
|
|
2020-04-08 20:48:31 +10:00
|
|
|
/**
|
|
|
|
|
* Method is not protected, assumes that
|
|
|
|
|
* other protections have been implemented prior
|
|
|
|
|
* to hitting this method.
|
|
|
|
|
*
|
|
|
|
|
* ie. invoice can be deleted from a business logic perspective.
|
2020-04-15 10:30:52 +10:00
|
|
|
*
|
|
|
|
|
* @param Invoice $invoice
|
|
|
|
|
* @return Invoice $invoice
|
2020-04-08 20:48:31 +10:00
|
|
|
*/
|
2020-04-15 10:30:52 +10:00
|
|
|
public function delete($invoice)
|
2020-04-04 21:32:42 +11:00
|
|
|
{
|
|
|
|
|
if ($invoice->is_deleted) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
|
2020-07-07 20:35:54 +10:00
|
|
|
$invoice->service()->handleCancellation()->save();
|
|
|
|
|
|
2020-07-17 07:15:30 +10:00
|
|
|
$invoice = parent::delete($invoice);
|
2020-04-08 20:48:31 +10:00
|
|
|
|
|
|
|
|
return $invoice;
|
2020-04-04 21:32:42 +11:00
|
|
|
}
|
2020-04-06 22:32:27 +10:00
|
|
|
|
|
|
|
|
public function reverse()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function cancel()
|
|
|
|
|
{
|
|
|
|
|
}
|
2019-12-31 08:59:12 +11:00
|
|
|
}
|