1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 21:22:58 +01:00
invoiceninja/app/Factory/RecurringInvoiceToInvoiceFactory.php

80 lines
3.2 KiB
PHP
Raw Normal View History

2019-05-23 07:08:31 +02:00
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
2019-05-23 07:08:31 +02:00
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2021. Invoice Ninja LLC (https://invoiceninja.com)
2019-05-23 07:08:31 +02:00
*
2021-06-16 08:58:16 +02:00
* @license https://www.elastic.co/licensing/elastic-license
2019-05-23 07:08:31 +02:00
*/
namespace App\Factory;
use App\Models\Client;
2019-05-23 07:08:31 +02:00
use App\Models\Invoice;
use App\Models\RecurringInvoice;
2021-09-26 04:13:03 +02:00
use App\Utils\Helpers;
2019-05-23 07:08:31 +02:00
class RecurringInvoiceToInvoiceFactory
2019-05-23 07:08:31 +02:00
{
public static function create(RecurringInvoice $recurring_invoice, Client $client) :Invoice
{
$invoice = new Invoice();
$invoice->status_id = Invoice::STATUS_DRAFT;
$invoice->discount = $recurring_invoice->discount;
$invoice->is_amount_discount = $recurring_invoice->is_amount_discount;
$invoice->po_number = $recurring_invoice->po_number;
$invoice->footer = $recurring_invoice->footer;
$invoice->terms = $recurring_invoice->terms;
$invoice->public_notes = $recurring_invoice->public_notes;
$invoice->private_notes = $recurring_invoice->private_notes;
2020-10-07 05:00:32 +02:00
//$invoice->date = now()->format($client->date_format());
2021-08-06 01:34:45 +02:00
//$invoice->due_date = $recurring_invoice->calculateDueDate(now());
$invoice->is_deleted = $recurring_invoice->is_deleted;
2021-09-26 04:13:03 +02:00
// $invoice->line_items = $recurring_invoice->line_items;
$invoice->line_items = self::transformItems($recurring_invoice, $client);
$invoice->tax_name1 = $recurring_invoice->tax_name1;
$invoice->tax_rate1 = $recurring_invoice->tax_rate1;
$invoice->tax_name2 = $recurring_invoice->tax_name2;
$invoice->tax_rate2 = $recurring_invoice->tax_rate2;
$invoice->tax_name3 = $recurring_invoice->tax_name3;
$invoice->tax_rate3 = $recurring_invoice->tax_rate3;
$invoice->total_taxes = $recurring_invoice->total_taxes;
$invoice->subscription_id = $recurring_invoice->subscription_id;
$invoice->custom_value1 = $recurring_invoice->custom_value1;
$invoice->custom_value2 = $recurring_invoice->custom_value2;
$invoice->custom_value3 = $recurring_invoice->custom_value3;
$invoice->custom_value4 = $recurring_invoice->custom_value4;
$invoice->amount = $recurring_invoice->amount;
2021-09-26 04:13:03 +02:00
$invoice->uses_inclusive_taxes = $recurring_invoice->uses_inclusive_taxes;
// $invoice->balance = $recurring_invoice->balance;
$invoice->user_id = $recurring_invoice->user_id;
$invoice->assigned_user_id = $recurring_invoice->assigned_user_id;
$invoice->company_id = $recurring_invoice->company_id;
$invoice->recurring_id = $recurring_invoice->id;
$invoice->client_id = $client->id;
$invoice->auto_bill_enabled = $recurring_invoice->auto_bill_enabled;
$invoice->paid_to_date = 0;
$invoice->design_id = $recurring_invoice->design_id;
return $invoice;
}
2021-09-26 04:13:03 +02:00
private static function transformItems($recurring_invoice, $client)
{
$line_items = $recurring_invoice->line_items;
foreach($line_items as $key => $item){
if(property_exists($line_items[$key], 'notes'))
$line_items[$key]->notes = Helpers::processReservedKeywords($item->notes, $client);
}
return $line_items;
}
2019-05-23 07:08:31 +02:00
}