2020-02-11 21:57:25 +01:00
|
|
|
<?php
|
2020-07-01 03:06:40 +02:00
|
|
|
|
|
|
|
/**
|
2020-09-06 11:38:10 +02:00
|
|
|
* Invoice Ninja (https://invoiceninja.com).
|
2020-07-01 03:06:40 +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\Services\Quote;
|
|
|
|
|
|
|
|
use App\Factory\CloneQuoteToInvoiceFactory;
|
2020-06-02 12:19:29 +02:00
|
|
|
use App\Models\Quote;
|
2020-02-11 21:57:25 +01:00
|
|
|
use App\Repositories\InvoiceRepository;
|
|
|
|
|
|
|
|
class ConvertQuote
|
|
|
|
{
|
|
|
|
private $client;
|
|
|
|
private $invoice_repo;
|
|
|
|
|
2020-05-27 06:46:19 +02:00
|
|
|
public function __construct($client)
|
2020-02-11 21:57:25 +01:00
|
|
|
{
|
|
|
|
$this->client = $client;
|
2020-05-27 06:46:19 +02:00
|
|
|
$this->invoice_repo = new InvoiceRepository();
|
2020-02-11 21:57:25 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @param $quote
|
|
|
|
* @return mixed
|
|
|
|
*/
|
2020-02-14 04:32:22 +01:00
|
|
|
public function run($quote)
|
2020-02-11 21:57:25 +01:00
|
|
|
{
|
2020-10-28 11:10:49 +01:00
|
|
|
$invoice = CloneQuoteToInvoiceFactory::create($quote, $quote->user_id);
|
2020-05-27 06:46:19 +02:00
|
|
|
$invoice = $this->invoice_repo->save([], $invoice);
|
2020-02-11 21:57:25 +01:00
|
|
|
|
2020-05-27 06:46:19 +02:00
|
|
|
$invoice->fresh();
|
|
|
|
|
2020-09-06 11:38:10 +02:00
|
|
|
$invoice->service()
|
2020-05-27 06:46:19 +02:00
|
|
|
->markSent()
|
|
|
|
->createInvitations()
|
|
|
|
->save();
|
|
|
|
|
|
|
|
$quote->invoice_id = $invoice->id;
|
2020-06-02 12:19:29 +02:00
|
|
|
$quote->status_id = Quote::STATUS_CONVERTED;
|
2020-05-27 06:46:19 +02:00
|
|
|
$quote->save();
|
2020-09-06 11:38:10 +02:00
|
|
|
|
2020-02-11 21:57:25 +01:00
|
|
|
// maybe should return invoice here
|
2020-05-27 06:46:19 +02:00
|
|
|
return $invoice;
|
2020-02-11 21:57:25 +01:00
|
|
|
}
|
|
|
|
}
|