mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Store Invoice Job
This commit is contained in:
parent
79ed18d9ff
commit
98d1480450
@ -14,6 +14,7 @@ use App\Http\Requests\Invoice\ShowInvoiceRequest;
|
||||
use App\Http\Requests\Invoice\StoreInvoiceRequest;
|
||||
use App\Http\Requests\Invoice\UpdateInvoiceRequest;
|
||||
use App\Jobs\Entity\ActionEntity;
|
||||
use App\Jobs\Invoice\StoreInvoice;
|
||||
use App\Models\Invoice;
|
||||
use App\Repositories\BaseRepository;
|
||||
use App\Repositories\InvoiceRepository;
|
||||
@ -102,6 +103,8 @@ class InvoiceController extends BaseController
|
||||
|
||||
$invoice = $this->invoice_repo->save($request->all(), InvoiceFactory::create(auth()->user()->company()->id, auth()->user()->id));
|
||||
|
||||
$invoice = StoreInvoice::dispatchNow($invoice, $request->all());
|
||||
|
||||
return $this->itemResponse($invoice);
|
||||
|
||||
}
|
||||
|
@ -3,6 +3,7 @@
|
||||
namespace App\Http\Requests\Invoice;
|
||||
|
||||
use App\Http\Requests\Request;
|
||||
use App\Models\ClientContact;
|
||||
use App\Models\Invoice;
|
||||
|
||||
class StoreInvoiceRequest extends Request
|
||||
@ -20,7 +21,10 @@ class StoreInvoiceRequest extends Request
|
||||
|
||||
public function rules()
|
||||
{
|
||||
$this->sanitize();
|
||||
|
||||
return [
|
||||
'client_id' => 'required',
|
||||
'documents' => 'mimes:png,ai,svg,jpeg,tiff,pdf,gif,psd,txt,doc,xls,ppt,xlsx,docx,pptx',
|
||||
];
|
||||
}
|
||||
@ -28,7 +32,18 @@ class StoreInvoiceRequest extends Request
|
||||
|
||||
public function sanitize()
|
||||
{
|
||||
//do post processing of invoice request here, ie. invoice_items
|
||||
$input = $this->all();
|
||||
|
||||
/** If we have an email address instead of a client_id - harvest the client_id here */
|
||||
if(isset($input['email']) && !$input['client_id'])
|
||||
{
|
||||
$contact = ClientContact::company()->whereEmail($input['email'])->first();
|
||||
|
||||
if($contact)
|
||||
$input['client_id'] = $contact->client_id;
|
||||
}
|
||||
|
||||
$this->replace($input);
|
||||
}
|
||||
|
||||
public function messages()
|
||||
|
97
app/Jobs/Invoice/StoreInvoice.php
Normal file
97
app/Jobs/Invoice/StoreInvoice.php
Normal file
@ -0,0 +1,97 @@
|
||||
<?php
|
||||
|
||||
namespace App\Jobs\Invoice;
|
||||
|
||||
use App\Repositories\InvoiceRepository;
|
||||
use Illuminate\Bus\Queueable;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
use Illuminate\Foundation\Bus\Dispatchable;
|
||||
use Illuminate\Queue\InteractsWithQueue;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
class StoreInvoice implements ShouldQueue
|
||||
{
|
||||
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
|
||||
|
||||
public $invoice;
|
||||
|
||||
protected $data;
|
||||
|
||||
/**
|
||||
* Create a new job instance.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function __construct(Invoice $invoice, array $data)
|
||||
{
|
||||
|
||||
$this->invoice = $invoice;
|
||||
|
||||
$this->data = $data;
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Execute the job.
|
||||
*
|
||||
* We expect the Invoice object along with
|
||||
* the request in array form
|
||||
*
|
||||
* Embedded in the request may be additionals
|
||||
* attributes which require additional work to be
|
||||
* done in this job, these include - but are not limited to:
|
||||
*
|
||||
* 1. email_invoice - Email the Invoice
|
||||
* 2. mark_paid - Mark the invoice as paid (Generates a payment against the invoice)
|
||||
* 3. ......
|
||||
*
|
||||
* @return NULL|Invoice
|
||||
*/
|
||||
public function handle(InvoiceRepository $invoice_repo) : ?Invoice
|
||||
{
|
||||
|
||||
$payment = false;
|
||||
|
||||
/* Test if we should auto-bill the invoice */
|
||||
if((bool)$invoice->settings->auto_bill)
|
||||
{
|
||||
|
||||
$this->invoice = $invoice_repo->markSent($this->invoice);
|
||||
|
||||
//fire autobill - todo - the PAYMENT class will update the INVOICE status.
|
||||
// $payment =
|
||||
|
||||
}
|
||||
|
||||
if(isset($this->data['email_invoice']) && (bool)$this->data['email_invoice'])
|
||||
{
|
||||
|
||||
$this->invoice = $invoice_repo->markSent($this->invoice);
|
||||
|
||||
//fire invoice job (the job performs the filtering logic of the email recipients... if any.)
|
||||
}
|
||||
|
||||
if(isset($this->data['mark_paid']) && (bool)$this->data['mark_paid'])
|
||||
{
|
||||
|
||||
$this->invoice = $invoice_repo->markSent($this->invoice);
|
||||
|
||||
// generate a manual payment against the invoice
|
||||
// the PAYMENT class will update the INVOICE status.
|
||||
//$payment =
|
||||
|
||||
}
|
||||
|
||||
/* Payment Notifications */
|
||||
if($payment)
|
||||
{
|
||||
//fire payment notifications here
|
||||
}
|
||||
|
||||
if(isset($data['download_invoice']) && (bool)$this->data['download_invoice'])
|
||||
{
|
||||
//fire invoice download and return PDF response from here
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -34,19 +34,19 @@ class InvoiceRepository extends BaseRepository
|
||||
*/
|
||||
public function save($data, Invoice $invoice) : ?Invoice
|
||||
{
|
||||
|
||||
$invoice->fill($data);
|
||||
|
||||
$invoice->save();
|
||||
|
||||
|
||||
$invoice_calc = new InvoiceCalc($invoice, $invoice->settings);
|
||||
|
||||
$invoice = $invoice_calc->build()->getInvoice();
|
||||
|
||||
//fire events here that cascading from the saving of an invoice
|
||||
//ie. client balance update...
|
||||
$invoice->save();
|
||||
|
||||
return $invoice;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user