Convert quote to project

This commit is contained in:
= 2022-08-15 12:31:20 +10:00
parent 528c96addb
commit 02b38316f2
2 changed files with 52 additions and 0 deletions

View File

@ -0,0 +1,39 @@
<?php
/**
* Project Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2022. Project Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Factory;
use App\Models\Project;
use App\Models\Quote;
class CloneQuoteToProjectFactory
{
public static function create(Quote $quote, $user_id) : ?Project
{
$project = new Project();
$project->company_id = $quote->company_id;
$project->user_id = $user_id;
$project->public_notes = $quote->public_notes;
$project->private_notes = $quote->private_notes;
$project->budgeted_hours = 0;
$project->task_rate = 0;
$project->name = ctrans('texts.quote_number_short') . " " . $quote->number;
$project->custom_value1 = '';
$project->custom_value2 = '';
$project->custom_value3 = '';
$project->custom_value4 = '';
$project->is_deleted = 0;
return $project;
}
}

View File

@ -15,6 +15,7 @@ use App\Events\Quote\QuoteWasCreated;
use App\Events\Quote\QuoteWasUpdated; use App\Events\Quote\QuoteWasUpdated;
use App\Factory\CloneQuoteFactory; use App\Factory\CloneQuoteFactory;
use App\Factory\CloneQuoteToInvoiceFactory; use App\Factory\CloneQuoteToInvoiceFactory;
use App\Factory\CloneQuoteToProjectFactory;
use App\Factory\QuoteFactory; use App\Factory\QuoteFactory;
use App\Filters\QuoteFilters; use App\Filters\QuoteFilters;
use App\Http\Requests\Quote\ActionQuoteRequest; use App\Http\Requests\Quote\ActionQuoteRequest;
@ -31,9 +32,11 @@ use App\Jobs\Quote\ZipQuotes;
use App\Models\Account; use App\Models\Account;
use App\Models\Client; use App\Models\Client;
use App\Models\Invoice; use App\Models\Invoice;
use App\Models\Project;
use App\Models\Quote; use App\Models\Quote;
use App\Repositories\QuoteRepository; use App\Repositories\QuoteRepository;
use App\Transformers\InvoiceTransformer; use App\Transformers\InvoiceTransformer;
use App\Transformers\ProjectTransformer;
use App\Transformers\QuoteTransformer; use App\Transformers\QuoteTransformer;
use App\Utils\Ninja; use App\Utils\Ninja;
use App\Utils\TempFile; use App\Utils\TempFile;
@ -661,6 +664,16 @@ class QuoteController extends BaseController
return $this->itemResponse($quote->service()->convertToInvoice()); return $this->itemResponse($quote->service()->convertToInvoice());
break; break;
case 'convert_to_project':
$this->entity_type = Project::class;
$this->entity_transformer = ProjectTransformer::class;
$project = CloneQuoteToProjectFactory::create($quote, auth()->user()->id);
return $this->itemResponse($project);
case 'clone_to_invoice': case 'clone_to_invoice':
$this->entity_type = Invoice::class; $this->entity_type = Invoice::class;