diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 6277825cae..25a069e96c 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -607,7 +607,7 @@ class ProjectController extends BaseController $this->entity_transformer = InvoiceTransformer::class; $this->entity_type = Invoice::class; - $invoice = $this->project_repo->invoice($project); + $invoice = $this->project_repo->invoice(collect([$project])); return $this->itemResponse($invoice); } diff --git a/app/Repositories/ProjectRepository.php b/app/Repositories/ProjectRepository.php index b11c65b5b5..fdc6fb459d 100644 --- a/app/Repositories/ProjectRepository.php +++ b/app/Repositories/ProjectRepository.php @@ -21,13 +21,23 @@ use App\Models\Project; * Class for project repository. */ class ProjectRepository extends BaseRepository -{ +{ + /** + * Invoices a collection of projects into a single invoice. + * + * @param mixed $projects + * @return App\Models\Invoice + */ public function invoice(mixed $projects) { $_project = $projects->first(); $invoice = InvoiceFactory::create($_project->company_id, $_project->user_id); $invoice->client_id = $_project->client_id; + + if(count($projects) == 1) { + $invoice->project_id = $_project->id; + } // $invoice->project_id = $project->id; $lines = [];