1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 05:32:39 +01:00
invoiceninja/app/Http/Controllers/Shop/InvoiceController.php

86 lines
2.4 KiB
PHP
Raw Normal View History

2020-07-28 13:19:51 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com)
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://opensource.org/licenses/AAL
*/
namespace App\Http\Controllers\Shop;
2020-07-28 13:30:11 +02:00
use App\Events\Invoice\InvoiceWasCreated;
2020-07-28 13:19:51 +02:00
use App\Factory\InvoiceFactory;
use App\Http\Controllers\BaseController;
use App\Http\Requests\Invoice\StoreInvoiceRequest;
use App\Models\Client;
use App\Models\CompanyToken;
use App\Models\Invoice;
use App\Models\InvoiceInvitation;
use App\Repositories\InvoiceRepository;
use App\Transformers\InvoiceTransformer;
2020-07-28 13:30:11 +02:00
use App\Utils\Ninja;
2020-07-28 13:19:51 +02:00
use App\Utils\Traits\MakesHash;
use Illuminate\Http\Request;
class InvoiceController extends BaseController
{
use MakesHash;
protected $entity_type = Invoice::class;
protected $entity_transformer = InvoiceTransformer::class;
/**
* @var InvoiceRepository
*/
protected $invoice_repo;
/**
* InvoiceController constructor.
*
* @param \App\Repositories\InvoiceRepository $invoice_repo The invoice repo
*/
public function __construct(InvoiceRepository $invoice_repo)
{
parent::__construct();
$this->invoice_repo = $invoice_repo;
}
public function show(string $invitation_key)
{
$company = Company::where('company_key', $request->header('X-API-COMPANY_KEY'))->first();
2020-07-28 13:19:51 +02:00
$invitation = InvoiceInvitation::with(['invoice'])
->where('company_id', $company->id)
2020-07-28 13:19:51 +02:00
->where('key',$invitation_key)
->firstOrFail();
return $this->itemResponse($invitation->invoice);
}
2020-07-28 13:30:11 +02:00
2020-07-28 13:19:51 +02:00
public function store(StoreInvoiceRequest $request)
{
app('queue')->createPayloadUsing(function () use ($company) {
return ['db' => $company->db];
});
$company = Company::where('company_key', $request->header('X-API-COMPANY_KEY'))->first();
2020-07-28 13:19:51 +02:00
$client = Client::find($request->input('client_id'));
$invoice = $this->invoice_repo->save($request->all(), InvoiceFactory::create($company_id, $company->owner()->id));
2020-07-28 13:19:51 +02:00
event(new InvoiceWasCreated($invoice, $company, Ninja::eventVars()));
2020-07-28 13:19:51 +02:00
$invoice = $invoice->service()->triggeredActions($request)->save();
return $this->itemResponse($invoice);
}
}