2019-04-04 10:17:15 +11:00
|
|
|
<?php
|
2019-05-11 13:32:07 +10:00
|
|
|
/**
|
2020-09-06 19:38:10 +10:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2019-05-11 13:32:07 +10:00
|
|
|
*
|
|
|
|
|
* @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;
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
/**
|
2020-09-06 19:38:10 +10:00
|
|
|
* InvoiceRepository.
|
2019-04-04 10:17:15 +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
|
|
|
/**
|
2020-09-06 19:38:10 +10:00
|
|
|
* Saves the invoices.
|
2020-03-21 16:37:30 +11:00
|
|
|
*
|
2020-11-04 00:27:41 +11:00
|
|
|
* @param array $data The invoice data
|
|
|
|
|
* @param Invoice $invoice The invoice
|
2020-03-21 16:37:30 +11:00
|
|
|
*
|
2020-11-04 00:27:41 +11:00
|
|
|
* @return Invoice|null Returns the invoice object
|
2020-03-21 16:37:30 +11:00
|
|
|
*/
|
|
|
|
|
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.
|
|
|
|
|
*
|
2020-10-28 21:10:49 +11:00
|
|
|
* @param Invoice $invoice The invoice
|
2020-03-21 16:37:30 +11:00
|
|
|
*
|
2020-10-28 21:10:49 +11:00
|
|
|
* @return Invoice|null Return the invoice object
|
2020-03-21 16:37:30 +11:00
|
|
|
*/
|
|
|
|
|
public function markSent(Invoice $invoice):?Invoice
|
|
|
|
|
{
|
|
|
|
|
return $invoice->service()->markSent()->save();
|
|
|
|
|
}
|
2020-03-02 21:22:37 +11:00
|
|
|
|
|
|
|
|
public function getInvitationByKey($key) :?InvoiceInvitation
|
|
|
|
|
{
|
2020-09-06 19:38:10 +10:00
|
|
|
return InvoiceInvitation::whereRaw('BINARY `key`= ?', [$key])->first();
|
2020-03-02 21:22:37 +11:00
|
|
|
}
|
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
|
|
|
*
|
2020-10-28 21:10:49 +11:00
|
|
|
* @param Invoice $invoice
|
2020-11-04 00:34:24 +11:00
|
|
|
* @return Invoice $invoice
|
2020-04-08 20:48:31 +10:00
|
|
|
*/
|
2020-11-04 00:34:24 +11:00
|
|
|
public function delete($invoice) :Invoice
|
2020-04-04 21:32:42 +11:00
|
|
|
{
|
|
|
|
|
if ($invoice->is_deleted) {
|
2020-11-04 00:34:24 +11:00
|
|
|
return $invoice;
|
2020-04-04 21:32:42 +11:00
|
|
|
}
|
|
|
|
|
|
2020-12-03 14:56:00 +11:00
|
|
|
// $invoice->service()->markDeleted()->handleCancellation()->save();
|
2020-12-03 15:20:39 +11:00
|
|
|
$invoice = $invoice->service()->markDeleted()->save();
|
2020-09-23 20:52:54 +10:00
|
|
|
|
2020-11-04 07:19:59 +11:00
|
|
|
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
|
|
|
|
2020-12-03 15:30:32 +11:00
|
|
|
/**
|
|
|
|
|
* Handles the restoration on a deleted invoice.
|
2020-12-05 14:24:21 +01:00
|
|
|
*
|
2020-12-03 15:30:32 +11:00
|
|
|
* @param [type] $invoice [description]
|
|
|
|
|
* @return [type] [description]
|
|
|
|
|
*/
|
|
|
|
|
public function restore($invoice) :Invoice
|
2020-12-03 15:20:39 +11:00
|
|
|
{
|
2020-12-03 15:30:32 +11:00
|
|
|
//if we have just archived, only perform a soft restore
|
2020-12-05 14:24:21 +01:00
|
|
|
if (!$invoice->is_deleted) {
|
2020-12-03 15:30:32 +11:00
|
|
|
parent::restore($invoice);
|
|
|
|
|
|
|
|
|
|
return $invoice;
|
|
|
|
|
}
|
2020-12-03 15:20:39 +11:00
|
|
|
|
2020-12-03 15:30:32 +11:00
|
|
|
// reversed delete invoice actions
|
2020-12-03 21:46:36 +11:00
|
|
|
$invoice = $invoice->service()->handleRestore()->save();
|
2020-12-03 15:20:39 +11:00
|
|
|
|
|
|
|
|
parent::restore($invoice);
|
|
|
|
|
|
|
|
|
|
return $invoice;
|
|
|
|
|
}
|
|
|
|
|
|
2020-04-06 22:32:27 +10:00
|
|
|
public function reverse()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function cancel()
|
|
|
|
|
{
|
|
|
|
|
}
|
2019-12-31 08:59:12 +11:00
|
|
|
}
|