mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-12-06 15:25:33 -05:00
Shift automatically applies the Laravel coding style - which uses the PSR-2 coding style as a base with some minor additions. You may customize the code style applied by adding a [PHP CS Fixer][1] or [PHP CodeSniffer][2] ruleset to your project root. Feel free to use [Shift's Laravel ruleset][3] to help you get started. For more information on customizing the code style applied by Shift, [watch this short video][4]. [1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer [2]: https://github.com/squizlabs/PHP_CodeSniffer [3]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200 [4]: https://laravelshift.com/videos/shift-code-style
121 lines
3.4 KiB
PHP
121 lines
3.4 KiB
PHP
<?php
|
|
/**
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
*
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
*
|
|
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
|
*
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
*/
|
|
|
|
namespace App\Services\PurchaseOrder;
|
|
|
|
use App\Jobs\Vendor\CreatePurchaseOrderPdf;
|
|
use App\Models\PurchaseOrder;
|
|
use App\Services\PurchaseOrder\ApplyNumber;
|
|
use App\Services\PurchaseOrder\CreateInvitations;
|
|
use App\Services\PurchaseOrder\GetPurchaseOrderPdf;
|
|
use App\Services\PurchaseOrder\TriggeredActions;
|
|
use App\Utils\Traits\MakesHash;
|
|
|
|
class PurchaseOrderService
|
|
{
|
|
use MakesHash;
|
|
|
|
public PurchaseOrder $purchase_order;
|
|
|
|
public function __construct(PurchaseOrder $purchase_order)
|
|
{
|
|
$this->purchase_order = $purchase_order;
|
|
}
|
|
|
|
public function createInvitations()
|
|
{
|
|
$this->purchase_order = (new CreateInvitations($this->purchase_order))->run();
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function applyNumber()
|
|
{
|
|
$this->invoice = (new ApplyNumber($this->purchase_order->vendor, $this->purchase_order))->run();
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function fillDefaults()
|
|
{
|
|
// $settings = $this->purchase_order->client->getMergedSettings();
|
|
|
|
// //TODO implement design, footer, terms
|
|
|
|
// /* If client currency differs from the company default currency, then insert the client exchange rate on the model.*/
|
|
// if (!isset($this->purchase_order->exchange_rate) && $this->purchase_order->client->currency()->id != (int)$this->purchase_order->company->settings->currency_id)
|
|
// $this->purchase_order->exchange_rate = $this->purchase_order->client->currency()->exchange_rate;
|
|
|
|
// if (!isset($this->purchase_order->public_notes))
|
|
// $this->purchase_order->public_notes = $this->purchase_order->client->public_notes;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function triggeredActions($request)
|
|
{
|
|
$this->purchase_order = (new TriggeredActions($this->purchase_order->load('invitations'), $request))->run();
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getPurchaseOrderPdf($contact = null)
|
|
{
|
|
return (new GetPurchaseOrderPdf($this->purchase_order, $contact))->run();
|
|
}
|
|
|
|
public function setStatus($status)
|
|
{
|
|
$this->purchase_order->status_id = $status;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function markSent()
|
|
{
|
|
$this->purchase_order = (new MarkSent($this->purchase_order->vendor, $this->purchase_order))->run();
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function touchPdf($force = false)
|
|
{
|
|
try {
|
|
if ($force) {
|
|
$this->purchase_order->invitations->each(function ($invitation) {
|
|
CreatePurchaseOrderPdf::dispatchNow($invitation);
|
|
});
|
|
|
|
return $this;
|
|
}
|
|
|
|
$this->purchase_order->invitations->each(function ($invitation) {
|
|
CreatePurchaseOrderPdf::dispatch($invitation);
|
|
});
|
|
} catch (\Exception $e) {
|
|
nlog('failed creating purchase orders in Touch PDF');
|
|
}
|
|
|
|
return $this;
|
|
}
|
|
|
|
/**
|
|
* Saves the purchase order.
|
|
* @return \App\Models\PurchaseOrder object
|
|
*/
|
|
public function save(): ?PurchaseOrder
|
|
{
|
|
$this->purchase_order->saveQuietly();
|
|
|
|
return $this->purchase_order;
|
|
}
|
|
}
|