2019-04-04 01:17:15 +02:00
|
|
|
<?php
|
2019-05-11 05:32:07 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2020-01-07 01:13:47 +01:00
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
2019-05-11 05:32:07 +02:00
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
2019-04-04 01:17:15 +02:00
|
|
|
|
|
|
|
namespace App\Repositories;
|
|
|
|
|
2020-04-04 12:32:42 +02:00
|
|
|
use App\Events\Invoice\InvoiceWasDeleted;
|
2019-05-29 06:33:53 +02:00
|
|
|
use App\Factory\InvoiceInvitationFactory;
|
2019-12-26 23:33:07 +01:00
|
|
|
use App\Jobs\Product\UpdateOrCreateProduct;
|
2020-02-26 06:18:38 +01:00
|
|
|
use App\Models\Client;
|
2019-09-23 05:22:24 +02:00
|
|
|
use App\Models\ClientContact;
|
2019-04-04 01:17:15 +02:00
|
|
|
use App\Models\Invoice;
|
2019-05-29 06:33:53 +02:00
|
|
|
use App\Models\InvoiceInvitation;
|
2019-09-23 05:22:24 +02:00
|
|
|
use App\Utils\Traits\MakesHash;
|
2019-04-04 01:17:15 +02:00
|
|
|
|
|
|
|
/**
|
2019-04-16 05:28:05 +02:00
|
|
|
* InvoiceRepository
|
2019-04-04 01:17:15 +02:00
|
|
|
*/
|
2020-02-10 10:53:02 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
class InvoiceRepository extends BaseRepository
|
|
|
|
{
|
|
|
|
use MakesHash;
|
2020-02-10 10:53:02 +01:00
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
/**
|
|
|
|
* Gets the class name.
|
|
|
|
*
|
|
|
|
* @return string The class name.
|
|
|
|
*/
|
|
|
|
public function getClassName()
|
|
|
|
{
|
|
|
|
return Invoice::class ;
|
|
|
|
}
|
2020-02-10 10:53:02 +01:00
|
|
|
|
2020-03-21 06:37:30 +01: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 10:53:02 +01:00
|
|
|
|
2020-03-21 06:37:30 +01: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 11:22:37 +01:00
|
|
|
|
|
|
|
public function getInvitationByKey($key) :?InvoiceInvitation
|
|
|
|
{
|
|
|
|
return InvoiceInvitation::whereRaw("BINARY `key`= ?", [$key])->first();
|
|
|
|
}
|
2020-04-04 12:32:42 +02:00
|
|
|
|
|
|
|
public function delete($invoice)
|
|
|
|
{
|
|
|
|
if ($invoice->is_deleted) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
$invoice->is_deleted = true;
|
|
|
|
$invoice->save();
|
|
|
|
|
|
|
|
$invoice->delete();
|
|
|
|
|
|
|
|
if (class_exists($className)) {
|
|
|
|
event(new InvoiceWasDeleted($invoice));
|
|
|
|
}
|
|
|
|
}
|
2020-04-06 14:32:27 +02:00
|
|
|
|
|
|
|
public function reverse()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
public function cancel()
|
|
|
|
{
|
|
|
|
|
|
|
|
}
|
2019-12-30 22:59:12 +01:00
|
|
|
}
|