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

46 lines
1.2 KiB
PHP
Raw Normal View History

2023-03-15 07:01:55 +01:00
<?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;
2023-03-18 08:24:56 +01:00
foreach ($line_items as $key => $line_item) {
2023-08-06 04:20:18 +02:00
/** @var \App\Models\Product $product **/
2023-08-06 09:35:19 +02:00
$product = Product::query()->where('company_id', $this->recurring_invoice->company_id)
2023-03-15 07:01:55 +01:00
->where('product_key', $line_item->product_key)
->where('is_deleted', 0)
->first();
2023-03-18 08:24:56 +01:00
if ($product) {
2023-03-30 04:33:35 +02:00
$line_items[$key]->cost = floatval($product->price);
2023-03-15 07:01:55 +01:00
}
}
$this->recurring_invoice->line_items = $line_items;
2023-03-15 07:01:55 +01:00
$this->recurring_invoice->calc()->getInvoice()->save();
}
2023-03-18 08:24:56 +01:00
}