diff --git a/app/Factory/CloneQuoteToProjectFactory.php b/app/Factory/CloneQuoteToProjectFactory.php new file mode 100644 index 000000000000..6f304b2e39c6 --- /dev/null +++ b/app/Factory/CloneQuoteToProjectFactory.php @@ -0,0 +1,39 @@ +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; + } +} diff --git a/app/Http/Controllers/QuoteController.php b/app/Http/Controllers/QuoteController.php index b89d9a77ade4..2875af4c0ab0 100644 --- a/app/Http/Controllers/QuoteController.php +++ b/app/Http/Controllers/QuoteController.php @@ -15,6 +15,7 @@ use App\Events\Quote\QuoteWasCreated; use App\Events\Quote\QuoteWasUpdated; use App\Factory\CloneQuoteFactory; use App\Factory\CloneQuoteToInvoiceFactory; +use App\Factory\CloneQuoteToProjectFactory; use App\Factory\QuoteFactory; use App\Filters\QuoteFilters; use App\Http\Requests\Quote\ActionQuoteRequest; @@ -31,9 +32,11 @@ use App\Jobs\Quote\ZipQuotes; use App\Models\Account; use App\Models\Client; use App\Models\Invoice; +use App\Models\Project; use App\Models\Quote; use App\Repositories\QuoteRepository; use App\Transformers\InvoiceTransformer; +use App\Transformers\ProjectTransformer; use App\Transformers\QuoteTransformer; use App\Utils\Ninja; use App\Utils\TempFile; @@ -661,6 +664,16 @@ class QuoteController extends BaseController return $this->itemResponse($quote->service()->convertToInvoice()); 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': $this->entity_type = Invoice::class;