1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-06 03:02:34 +01:00
invoiceninja/app/Repositories/InvoiceRepository.php

103 lines
2.4 KiB
PHP
Raw Normal View History

2019-04-04 01:17:15 +02:00
<?php
2019-05-11 05:32:07 +02:00
/**
* Invoice Ninja (https://invoiceninja.com).
2019-05-11 05:32:07 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @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;
use App\Events\Invoice\InvoiceWasDeleted;
2019-05-29 06:33:53 +02:00
use App\Factory\InvoiceInvitationFactory;
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
/**
* InvoiceRepository.
2019-04-04 01:17:15 +02:00
*/
class InvoiceRepository extends BaseRepository
{
use MakesHash;
/**
* Gets the class name.
*
* @return string The class name.
*/
public function getClassName()
{
2020-07-27 10:22:57 +02:00
return Invoice::class;
}
/**
* 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);
}
/**
* 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();
}
public function getInvitationByKey($key) :?InvoiceInvitation
{
return InvoiceInvitation::whereRaw('BINARY `key`= ?', [$key])->first();
}
/**
* 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.
*
* @param Invoice $invoice
* @return Invoice $invoice
*/
public function delete($invoice)
{
if ($invoice->is_deleted) {
return;
}
$invoice->service()->markDeleted()->handleCancellation()->save();
$invoice = parent::delete($invoice);
return $invoice;
}
public function reverse()
{
}
public function cancel()
{
}
}