2020-02-11 21:57:25 +01:00
|
|
|
<?php
|
2020-05-09 00:35:49 +02:00
|
|
|
/**
|
|
|
|
* Invoice Ninja (https://invoiceninja.com)
|
|
|
|
*
|
|
|
|
* @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-05-09 00:35:49 +02:00
|
|
|
|
|
|
|
$invoice = new Invoice();
|
|
|
|
|
|
|
|
$quote_array = $quote->toArray();
|
|
|
|
|
|
|
|
unset($quote_array['client']);
|
|
|
|
unset($quote_array['company']);
|
|
|
|
unset($quote_array['hashed_id']);
|
2020-05-20 08:59:29 +02:00
|
|
|
unset($quote_array['invoice_id']);
|
2020-05-09 00:35:49 +02:00
|
|
|
unset($quote_array['id']);
|
2020-05-27 06:46:19 +02:00
|
|
|
|
2020-05-09 00:35:49 +02:00
|
|
|
foreach($quote_array as $key => $value)
|
|
|
|
$invoice->{$key} = $value;
|
|
|
|
|
2020-05-27 06:46:19 +02:00
|
|
|
$invoice->status_id = Invoice::STATUS_DRAFT;
|
2020-05-09 00:35:49 +02:00
|
|
|
$invoice->due_date = null;
|
|
|
|
$invoice->partial_due_date = null;
|
|
|
|
$invoice->number = null;
|
|
|
|
|
|
|
|
return $invoice;
|
|
|
|
|
2020-03-21 06:37:30 +01:00
|
|
|
}
|
2020-02-11 21:57:25 +01:00
|
|
|
}
|