2022-06-05 05:57:44 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
|
|
namespace App\Services\PurchaseOrder;
|
|
|
|
|
|
|
|
|
|
|
|
use App\Events\PurchaseOrder\PurchaseOrderWasMarkedSent;
|
|
|
|
use App\Models\PurchaseOrder;
|
|
|
|
use App\Utils\Ninja;
|
|
|
|
|
|
|
|
class MarkSent
|
|
|
|
{
|
2022-06-05 11:22:58 +02:00
|
|
|
private $vendor;
|
2022-06-05 05:57:44 +02:00
|
|
|
|
|
|
|
private $purchase_order;
|
|
|
|
|
2022-06-05 11:22:58 +02:00
|
|
|
public function __construct($vendor, $purchase_order)
|
2022-06-05 05:57:44 +02:00
|
|
|
{
|
2022-06-05 11:22:58 +02:00
|
|
|
$this->vendor = $vendor;
|
2022-06-05 05:57:44 +02:00
|
|
|
$this->purchase_order = $purchase_order;
|
|
|
|
}
|
|
|
|
|
|
|
|
public function run()
|
|
|
|
{
|
|
|
|
|
|
|
|
/* Return immediately if status is not draft */
|
|
|
|
if ($this->purchase_order->status_id != PurchaseOrder::STATUS_DRAFT) {
|
|
|
|
return $this->purchase_order;
|
|
|
|
}
|
|
|
|
|
|
|
|
$this->purchase_order->markInvitationsSent();
|
|
|
|
|
|
|
|
$this->purchase_order
|
|
|
|
->service()
|
|
|
|
->setStatus(PurchaseOrder::STATUS_SENT)
|
|
|
|
->applyNumber()
|
|
|
|
// ->adjustBalance($this->purchase_order->amount)
|
|
|
|
// ->touchPdf()
|
|
|
|
->save();
|
|
|
|
|
|
|
|
event(new PurchaseOrderWasMarkedSent($this->purchase_order, $this->purchase_order->company, Ninja::eventVars(auth()->user() ? auth()->user()->id : null)));
|
|
|
|
|
|
|
|
return $this->purchase_order;
|
|
|
|
}
|
|
|
|
}
|