mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-05-24 02:14:21 -04:00
Working on conversion of quotes to projects
This commit is contained in:
parent
a368daac09
commit
b47e31e23a
55
app/Services/Quote/ConvertQuoteToProject.php
Normal file
55
app/Services/Quote/ConvertQuoteToProject.php
Normal file
@ -0,0 +1,55 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Services\Quote;
|
||||
|
||||
use App\Models\Quote;
|
||||
use App\Factory\ProjectFactory;
|
||||
use App\Models\Project;
|
||||
use App\Utils\Traits\GeneratesCounter;
|
||||
|
||||
class ConvertQuoteToProject
|
||||
{
|
||||
use GeneratesCounter;
|
||||
|
||||
public function __construct(private Quote $quote)
|
||||
{
|
||||
}
|
||||
|
||||
public function run(): Project
|
||||
{
|
||||
|
||||
$quote_items = collect($this->quote->line_items);
|
||||
|
||||
$project = ProjectFactory::create($this->quote->company_id, $this->quote->user_id);
|
||||
$project->name = ctrans('texts.quote_number_short'). " " . $this->quote->number . "[{$this->quote->client->present()->name()}]";
|
||||
$project->client_id = $this->quote->client_id;
|
||||
$project->public_notes = $this->quote->public_notes;
|
||||
$project->private_notes = $this->quote->private_notes;
|
||||
$project->budgeted_hours = $quote_items->sum('quantity') ?? 0;
|
||||
$project->task_rate = ($this->quote->amount / $project->budgeted_hours) ?? 0;
|
||||
$project->saveQuietly();
|
||||
$project->number = $this->getNextProjectNumber($project);
|
||||
$project->saveQuietly();
|
||||
|
||||
$this->quote->project_id = $project->id;
|
||||
$this->quote->saveQuietly();
|
||||
|
||||
event('eloquent.created: App\Models\Project', $project);
|
||||
|
||||
$quote_items->each(function($item){
|
||||
|
||||
});
|
||||
|
||||
return $project;
|
||||
}
|
||||
}
|
@ -663,6 +663,12 @@ class HtmlEngine
|
||||
$data['$payment.custom3'] = ['value' => '', 'label' => ctrans('texts.payment')];
|
||||
$data['$payment.custom4'] = ['value' => '', 'label' => ctrans('texts.payment')];
|
||||
|
||||
$data['$payment.amount'] = ['value' => '', 'label' => ctrans('texts.payment')];
|
||||
$data['$payment.date'] = ['value' => '', 'label' => ctrans('texts.payment_date')];
|
||||
$data['$payment.number'] = ['value' => '', 'label' => ctrans('texts.payment_number')];
|
||||
$data['$payment.transaction_reference'] = ['value' => '', 'label' => ctrans('texts.transaction_reference')];
|
||||
|
||||
|
||||
if ($this->entity_string == 'invoice' && $this->entity->payments()->exists()) {
|
||||
$payment_list = '<br><br>';
|
||||
|
||||
@ -672,7 +678,6 @@ class HtmlEngine
|
||||
|
||||
$data['$payments'] = ['value' => $payment_list, 'label' => ctrans('texts.payments')];
|
||||
|
||||
|
||||
$payment = $this->entity->payments()->first();
|
||||
|
||||
$data['$payment.custom1'] = ['value' => $payment->custom_value1, 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'payment1')];
|
||||
@ -680,6 +685,11 @@ class HtmlEngine
|
||||
$data['$payment.custom3'] = ['value' => $payment->custom_value3, 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'payment3')];
|
||||
$data['$payment.custom4'] = ['value' => $payment->custom_value4, 'label' => $this->helpers->makeCustomField($this->company->custom_fields, 'payment4')];
|
||||
|
||||
$data['$payment.amount'] = ['value' => Number::formatMoney($payment->amount, $this->client), 'label' => ctrans('texts.payment')];
|
||||
$data['$payment.date'] = ['value' => $this->formatDate($payment->date, $this->client->date_format()), 'label' => ctrans('texts.payment_date')];
|
||||
$data['$payment.number'] = ['value' => $payment->number, 'label' => ctrans('texts.payment_number')];
|
||||
$data['$payment.transaction_reference'] = ['value' => $payment->transaction_reference, 'label' => ctrans('texts.transaction_reference')];
|
||||
|
||||
}
|
||||
|
||||
if (($this->entity_string == 'invoice' || $this->entity_string == 'recurring_invoice') && isset($this->company?->custom_fields?->company1)) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user