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
|
|
|
|
*
|
2021-01-03 22:54:54 +01:00
|
|
|
* @copyright Copyright (c) 2021. 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']);
|
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;
|
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
|
|
|
}
|