1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-14 15:13:29 +01:00
invoiceninja/app/Services/Recurring/UpdatePrice.php
2023-03-15 17:01:55 +11:00

50 lines
1.1 KiB
PHP

<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Services\Recurring;
use App\Models\Product;
use App\Models\RecurringInvoice;
use App\Services\AbstractService;
class UpdatePrice extends AbstractService
{
public function __construct(public RecurringInvoice $recurring_invoice)
{
}
public function run()
{
$line_items = $this->recurring_invoice->line_items;
foreach($line_items as $key => $line_item)
{
$product = Product::where('company_id', $this->recurring_invoice->company_id)
->where('product_key', $line_item->product_key)
->where('is_deleted', 0)
->first();
if($product){
$line_items[$key]->cost = $product->cost;
}
}
$this->recurring_invoice->line_items = $line_items;
$this->recurring_invoice->calc()->getInvoice()->save();
}
}