2022-06-05 05:57:44 +02:00
|
|
|
<?php
|
2022-06-05 11:41:19 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2023-01-28 23:21:40 +01:00
|
|
|
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
2022-06-05 11:41:19 +02:00
|
|
|
*
|
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
|
|
|
*/
|
2022-06-05 05:57:44 +02:00
|
|
|
|
|
|
|
namespace App\Services\PurchaseOrder;
|
|
|
|
|
|
|
|
use App\Models\PurchaseOrder;
|
2023-02-03 12:54:34 +01:00
|
|
|
use App\Models\Webhook;
|
2022-06-05 05:57:44 +02:00
|
|
|
|
|
|
|
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()
|
2022-12-19 04:57:44 +01:00
|
|
|
->adjustBalance($this->purchase_order->amount) //why was this commented out previously?
|
2022-06-05 05:57:44 +02:00
|
|
|
->save();
|
|
|
|
|
2023-02-07 15:46:52 +01:00
|
|
|
$this->purchase_order->sendEvent(Webhook::EVENT_SENT_PURCHASE_ORDER, "vendor");
|
2023-02-03 12:54:34 +01:00
|
|
|
|
2022-06-05 05:57:44 +02:00
|
|
|
return $this->purchase_order;
|
|
|
|
}
|
|
|
|
}
|