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
|
|
|
|
*
|
|
|
|
* @copyright Copyright (c) 2020. Invoice Ninja LLC (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @license https://opensource.org/licenses/AAL
|
|
|
|
*/
|
|
|
|
|
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-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;
|
2020-05-09 00:35:49 +02:00
|
|
|
|
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
|
|
|
}
|