diff --git a/app/Export/CSV/BaseExport.php b/app/Export/CSV/BaseExport.php index a05e61e7b1..55b931550c 100644 --- a/app/Export/CSV/BaseExport.php +++ b/app/Export/CSV/BaseExport.php @@ -628,11 +628,11 @@ class BaseExport } if(in_array($column, ['client.user_id', 'user_id'])) { - return $entity->client->user->present()->name(); + return $entity->client->user ? $entity->client->user->present()->name() : ''; } if(in_array($column, ['client.assigned_user_id', 'assigned_user_id'])) { - return $entity->client->assigned_user->present()->name(); + return $entity->client->assigned_user ? $entity->client->assigned_user->present()->name() : ''; } if(in_array($column, ['client.country_id', 'country_id'])) { @@ -760,7 +760,7 @@ class BaseExport return $transformed_payment[$column]; } elseif (array_key_exists(str_replace("payment.", "", $column), $transformed_payment)) { return $transformed_payment[$column]; - } + } // nlog("export: Could not resolve payment key: {$column}"); diff --git a/app/Export/CSV/PaymentExport.php b/app/Export/CSV/PaymentExport.php index 48f996fae7..c92fc5983f 100644 --- a/app/Export/CSV/PaymentExport.php +++ b/app/Export/CSV/PaymentExport.php @@ -167,6 +167,14 @@ class PaymentExport extends BaseExport $entity['gateway'] = $payment->gateway_type ? $payment->gateway_type->name : 'Unknown Type'; } + if (in_array('payment.assigned_user_id', $this->input['report_keys'])) { + $entity['payment.assigned_user_id'] = $payment->assigned_user ? $payment->assigned_user->present()->name() : ''; + } + + if (in_array('payment.user_id', $this->input['report_keys'])) { + $entity['payment.user_id'] = $payment->user ? $payment->user->present()->name() : ''; + } + // $entity['invoices'] = $payment->invoices()->exists() ? $payment->invoices->pluck('number')->implode(',') : ''; return $entity; diff --git a/app/Export/CSV/RecurringInvoiceExport.php b/app/Export/CSV/RecurringInvoiceExport.php index 02e51cac03..18bf306a03 100644 --- a/app/Export/CSV/RecurringInvoiceExport.php +++ b/app/Export/CSV/RecurringInvoiceExport.php @@ -157,6 +157,15 @@ class RecurringInvoiceExport extends BaseExport $entity['recurring_invoice.auto_bill_enabled'] = $invoice->auto_bill_enabled ? ctrans('texts.yes') : ctrans('texts.no'); } + if (in_array('recurring_invoice.assigned_user_id', $this->input['report_keys'])) { + $entity['recurring_invoice.assigned_user_id'] = $invoice->assigned_user ? $invoice->assigned_user->present()->name() : ''; + } + + if (in_array('recurring_invoice.user_id', $this->input['report_keys'])) { + $entity['recurring_invoice.user_id'] = $invoice->user ? $invoice->user->present()->name() : ''; + } + + return $entity; } } diff --git a/app/Export/Decorators/ClientDecorator.php b/app/Export/Decorators/ClientDecorator.php new file mode 100644 index 0000000000..83fbdad948 --- /dev/null +++ b/app/Export/Decorators/ClientDecorator.php @@ -0,0 +1,20 @@ + $value = (new ClientDecorator($entity, $key))->transform(), + ($entity instanceof Payment) => $value = (new PaymentDecorator($entity, $key))->transform(), + ($entity instanceof Invoice) => $value = (new InvoiceDecorator($entity, $key))->transform(), + ($entity instanceof RecurringInvoice) => $value = (new RecurringInvoiceDecorator($entity, $key))->transform(), + ($entity instanceof Credit) => $value = (new CreditDecorator($entity, $key))->transform(), + ($entity instanceof Quote) => $value = (new QuoteDecorator($entity, $key))->transform(), + ($entity instanceof Task) => $value = (new TaskDecorator($entity, $key))->transform(), + ($entity instanceof Expense) => $value = (new ExpenseDecorator($entity, $key))->transform(), + ($entity instanceof Project) => $value = (new ProjectDecorator($entity, $key))->transform(), + ($entity instanceof Product) => $value = (new ProductDecorator($entity, $key))->transform(), + ($entity instanceof Vendor) => $value = (new VendorDecorator($entity, $key))->transform(), + ($entity instanceof PurchaseOrder) => $value = (new PurchaseOrderDecorator($entity, $key))->transform(), + default => $value = '', + }; + + return $value; + } + +} diff --git a/app/Export/Decorators/DecoratorInterface.php b/app/Export/Decorators/DecoratorInterface.php new file mode 100644 index 0000000000..a19b231f8f --- /dev/null +++ b/app/Export/Decorators/DecoratorInterface.php @@ -0,0 +1,16 @@ +mailable = new TemplateEmail($email_builder, $this->contact, $invitation); $nmo->to_user = $this->contact; $nmo->settings = $this->settings; diff --git a/app/Services/Template/TemplateService.php b/app/Services/Template/TemplateService.php index f42508fccd..e233557f0d 100644 --- a/app/Services/Template/TemplateService.php +++ b/app/Services/Template/TemplateService.php @@ -121,7 +121,7 @@ class TemplateService * @return self */ public function build(array $data): self - {nlog($data); + { $this->compose() ->processData($data) ->parseNinjaBlocks() @@ -215,7 +215,7 @@ class TemplateService { $this->data = $this->preProcessDataBlocks($data); - // nlog($this->data); + nlog($this->data); return $this; } @@ -617,7 +617,7 @@ class TemplateService 'paymentables' => $pivot, 'refund_activity' => $this->getPaymentRefundActivity($payment), ]; - +nlog($data); return $data; } @@ -827,11 +827,11 @@ class TemplateService */ public function processPayments($payments): array { - +nlog("processing payments"); $payments = collect($payments)->map(function ($payment) { return $this->transformPayment($payment); })->toArray(); - +nlog($payments); return $payments; }