1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-09-21 08:51:34 +02:00
invoiceninja/app/Services/Quote/QuoteService.php
David Bomba ba75a44eb8
Laravel 7.x Shift (#40)
* Adopt Laravel coding style

The Laravel framework adopts the PSR-2 coding style with some additions.
Laravel apps *should* adopt this coding style as well.

However, Shift allows you to customize the adopted coding style by
adding your own [PHP CS Fixer][1] `.php_cs` config to your project.

You may use [Shift's .php_cs][2] file as a base.

[1]: https://github.com/FriendsOfPHP/PHP-CS-Fixer
[2]: https://gist.github.com/laravel-shift/cab527923ed2a109dda047b97d53c200

* Shift bindings

PHP 5.5.9+ adds the new static `class` property which provides the fully qualified class name. This is preferred over using class name strings as these references are checked by the parser.

* Shift core files

* Shift to Throwable

* Add laravel/ui dependency

* Unindent vendor mail templates

* Shift config files

* Default config files

In an effort to make upgrading the constantly changing config files
easier, Shift defaulted them so you can review the commit diff for
changes. Moving forward, you should use ENV variables or create a
separate config file to allow the core config files to remain
automatically upgradeable.

* Shift Laravel dependencies

* Shift cleanup

* Upgrade to Laravel 7

Co-authored-by: Laravel Shift <shift@laravelshift.com>
2020-09-06 19:38:10 +10:00

165 lines
3.5 KiB
PHP

<?php
/**
* 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
*/
namespace App\Services\Quote;
use App\Factory\CloneQuoteToInvoiceFactory;
use App\Models\Invoice;
use App\Models\Quote;
use App\Repositories\QuoteRepository;
use App\Services\Quote\CreateInvitations;
use App\Services\Quote\GetQuotePdf;
class QuoteService
{
protected $quote;
public $invoice;
public function __construct($quote)
{
$this->quote = $quote;
}
public function createInvitations()
{
$create_invitation = new CreateInvitations();
$this->quote = $create_invitation->run($this->quote);
return $this;
}
public function markApproved()
{
$mark_approved = new MarkApproved($this->quote->client);
$this->quote = $mark_approved->run($this->quote);
if ($this->quote->client->getSetting('auto_convert_quote') === true) {
$this->convert();
}
return $this;
}
public function convert() :self
{
if ($this->quote->invoice_id) {
return $this;
}
$convert_quote = new ConvertQuote($this->quote->client);
$this->invoice = $convert_quote->run($this->quote);
$this->quote->fresh();
return $this;
}
public function getQuotePdf($contact = null)
{
return (new GetQuotePdf($this->quote, $contact))->run();
}
public function sendEmail($contact = null) :self
{
$send_email = new SendEmail($this->quote, null, $contact);
$send_email->run();
return $this;
}
/**
* Applies the invoice number.
* @return $this InvoiceService object
*/
public function applyNumber() :self
{
$apply_number = new ApplyNumber($this->quote->client);
$this->quote = $apply_number->run($this->quote);
return $this;
}
public function markSent() :self
{
$mark_sent = new MarkSent($this->quote->client, $this->quote);
$this->quote = $mark_sent->run();
return $this;
}
public function setStatus($status) :self
{
$this->quote->status_id = $status;
return $this;
}
public function approve() :self
{
$this->setStatus(Quote::STATUS_APPROVED)->save();
$invoice = null;
if ($this->quote->client->getSetting('auto_convert_quote')) {
$this->convert();
}
if ($this->quote->client->getSetting('auto_archive_quote')) {
$quote_repo = new QuoteRepository();
$quote_repo->archive($this->quote);
}
return $this;
}
public function convertToInvoice()
{
//to prevent circular references we need to explicit call this here.
$mark_approved = new MarkApproved($this->quote->client);
$this->quote = $mark_approved->run($this->quote);
$this->convert();
return $this->invoice;
}
public function isConvertable() :bool
{
if ($this->quote->invoice_id) {
return false;
}
if ($this->quote->status_id == Quote::STATUS_EXPIRED) {
return false;
}
return true;
}
/**
* Saves the quote.
* @return Quote|null
*/
public function save() : ?Quote
{
$this->quote->save();
return $this->quote;
}
}