diff --git a/app/Services/Invoice/GenerateDeliveryNote.php b/app/Services/Invoice/GenerateDeliveryNote.php index b54d89184b2f..5b40a550ded8 100644 --- a/app/Services/Invoice/GenerateDeliveryNote.php +++ b/app/Services/Invoice/GenerateDeliveryNote.php @@ -43,7 +43,7 @@ class GenerateDeliveryNote { $delivery_note_design_id = $this->invoice->client->getSetting('delivery_note_design_id'); - $design = Design::find($this->decodePrimaryKey($delivery_note_design_id)); + $design = Design::withTrashed()->find($this->decodePrimaryKey($delivery_note_design_id)); if($design && $design->is_template) { diff --git a/app/Services/Template/TemplateAction.php b/app/Services/Template/TemplateAction.php new file mode 100644 index 000000000000..12125f83fedc --- /dev/null +++ b/app/Services/Template/TemplateAction.php @@ -0,0 +1,140 @@ +db); + + $key = $this->resolveEntityString(); + + $entity = new $this->entity(); + + $template = Design::withTrashed()->find($this->decodePrimaryKey($this->template)); + + $template_service = new TemplateService($template); + + $resource = $entity->query() + ->withTrashed() + ->whereIn('id', $this->transformKeys($this->ids)) + ->where('company_id', $this->company->id) + ->get(); + + if(count($resource) <= 1) + $data[$key] = [$resource]; + else + $data[$key] = $resource; + + $pdf = $template_service->build($data)->getPdf(); + + if($this->send_email) + return $this->sendEmail($pdf); + + return $pdf; + } + + private function sendEmail(mixed $pdf): void + { + //send the email. + } + + /** + * Context + * + * If I have an array of invoices, what could I possib + * + * + */ + private function resolveEntityString() + { + return match ($this->entity) { + Invoice::class => 'invoices', + Quote::class => 'quotes', + Task::class => 'tasks', + Credit::class => 'credits', + RecurringInvoice::class => 'recurring_invoices', + Project::class => 'projects', + Expense::class => 'expenses', + Payment::class => 'payments', + Product::class => 'products', + PurchaseOrder::class => 'purchase_orders', + Project::class => 'projects', + Client::class => 'clients', + Vendor::class => 'vendors', + }; + } + + public function middleware() + { + return [new WithoutOverlapping("template-{$this->company->company_key}")]; + } + +} + + +