1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-11 13:42:49 +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
*
2024-04-12 06:15:41 +02:00
* @copyright Copyright (c) 2024. Invoice Ninja LLC (https://invoiceninja.com)
2023-03-15 07:01:55 +01:00
*
* @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) {
2024-01-14 05:05:00 +01:00
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();
2024-01-14 05:05:00 +01:00
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
}