2020-02-11 21:57:25 +01:00
|
|
|
<?php
|
2020-05-09 00:35:49 +02:00
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-05-09 00:35:49 +02:00
|
|
|
*
|
|
|
|
* @link https://github.com/invoiceninja/invoiceninja source repository
|
|
|
|
*
|
2022-04-27 05:20:41 +02:00
|
|
|
* @copyright Copyright (c) 2022. Invoice Ninja LLC (https://invoiceninja.com)
|
2020-05-09 00:35:49 +02:00
|
|
|
*
|
2021-06-16 08:58:16 +02:00
|
|
|
* @license https://www.elastic.co/licensing/elastic-license
|
2020-05-09 00:35:49 +02:00
|
|
|
*/
|
|
|
|
|
2020-02-11 21:57:25 +01:00
|
|
|
namespace App\Factory;
|
|
|
|
|
|
|
|
use App\Models\Invoice;
|
|
|
|
use App\Models\Quote;
|
|
|
|
|
|
|
|
class CloneQuoteToInvoiceFactory
|
|
|
|
{
|
2020-02-19 21:44:12 +01:00
|
|
|
public static function create(Quote $quote, $user_id) : ?Invoice
|
2020-03-21 06:37:30 +01:00
|
|
|
{
|
2020-09-06 11:38:10 +02:00
|
|
|
$invoice = new Invoice();
|
2020-05-09 00:35:49 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$quote_array = $quote->toArray();
|
2020-05-09 00:35:49 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
unset($quote_array['client']);
|
|
|
|
unset($quote_array['company']);
|
|
|
|
unset($quote_array['hashed_id']);
|
|
|
|
unset($quote_array['invoice_id']);
|
|
|
|
unset($quote_array['id']);
|
2020-11-03 13:35:05 +01:00
|
|
|
unset($quote_array['invitations']);
|
2022-06-21 11:57:17 +02:00
|
|
|
|
2022-04-18 13:02:06 +02:00
|
|
|
//preserve terms if they exist on Quotes
|
2022-05-17 09:36:28 +02:00
|
|
|
//if(array_key_exists('terms', $quote_array) && strlen($quote_array['terms']) < 2)
|
2022-06-21 11:57:17 +02:00
|
|
|
if (! $quote->company->use_quote_terms_on_conversion) {
|
2022-04-18 13:02:06 +02:00
|
|
|
unset($quote_array['terms']);
|
2022-06-21 11:57:17 +02:00
|
|
|
}
|
2022-04-18 13:02:06 +02:00
|
|
|
|
2021-10-14 01:08:26 +02:00
|
|
|
// unset($quote_array['public_notes']);
|
2021-10-08 12:27:50 +02:00
|
|
|
unset($quote_array['footer']);
|
2021-07-25 10:05:53 +02:00
|
|
|
unset($quote_array['design_id']);
|
2021-10-17 05:21:13 +02:00
|
|
|
unset($quote_array['user']);
|
2020-05-09 00:35:49 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
foreach ($quote_array as $key => $value) {
|
|
|
|
$invoice->{$key} = $value;
|
|
|
|
}
|
2020-05-27 06:46:19 +02:00
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$invoice->status_id = Invoice::STATUS_DRAFT;
|
|
|
|
$invoice->due_date = null;
|
|
|
|
$invoice->partial_due_date = null;
|
|
|
|
$invoice->number = null;
|
2021-01-13 11:12:14 +01:00
|
|
|
$invoice->date = now()->format('Y-m-d');
|
2021-01-19 22:30:04 +01:00
|
|
|
$invoice->balance = 0;
|
2021-08-23 00:05:34 +02:00
|
|
|
$invoice->deleted_at = null;
|
2021-11-30 21:22:17 +01:00
|
|
|
$invoice->next_send_date = null;
|
|
|
|
$invoice->reminder1_sent = null;
|
|
|
|
$invoice->reminder2_sent = null;
|
|
|
|
$invoice->reminder3_sent = null;
|
|
|
|
$invoice->reminder_last_sent = null;
|
|
|
|
$invoice->last_sent_date = null;
|
|
|
|
$invoice->last_viewed = null;
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
return $invoice;
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-02-11 21:57:25 +01:00
|
|
|
}
|