1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 13:12:50 +01:00

Decorators for export

This commit is contained in:
David Bomba 2023-11-22 17:52:02 +11:00
parent 9839a82109
commit 149c5b6a0e
19 changed files with 332 additions and 10 deletions

View File

@ -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}");

View File

@ -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;

View File

@ -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;
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Export\Decorators;
class ClientDecorator implements DecoratorInterface
{
public function transform(): string
{
return 'Payment Decorator';
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Export\Decorators;
class CreditDecorator implements DecoratorInterface
{
public function transform(): string
{
return 'Payment Decorator';
}
}

View File

@ -0,0 +1,51 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Export\Decorators;
use App\Models\Task;
use App\Models\Quote;
use App\Models\Client;
use App\Models\Credit;
use App\Models\Vendor;
use App\Models\Expense;
use App\Models\Invoice;
use App\Models\Payment;
use App\Models\Product;
use App\Models\Project;
use App\Models\PurchaseOrder;
use App\Models\RecurringInvoice;
class Decorator {
public function __invoke(mixed $entity, string $key)
{
return match($entity){
($entity instanceof Client) => $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;
}
}

View File

@ -0,0 +1,16 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Export\Decorators;
interface DecoratorInterface {
public function transform(): string;
}

View File

@ -0,0 +1,20 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Export\Decorators;
class ExpenseDecorator implements DecoratorInterface
{
public function transform(): string
{
return 'Payment Decorator';
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Export\Decorators;
class InvoiceDecorator implements DecoratorInterface
{
public function transform(): string
{
return 'Payment Decorator';
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Export\Decorators;
class PaymentDecorator implements DecoratorInterface{
public function transform(): string
{
return 'Payment Decorator';
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Export\Decorators;
class ProductDecorator implements DecoratorInterface
{
public function transform(): string
{
return 'Payment Decorator';
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Export\Decorators;
class ProjectDecorator implements DecoratorInterface
{
public function transform(): string
{
return 'Payment Decorator';
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Export\Decorators;
class PurchaseOrderDecorator implements DecoratorInterface
{
public function transform(): string
{
return 'Payment Decorator';
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Export\Decorators;
class QuoteDecorator implements DecoratorInterface
{
public function transform(): string
{
return 'Payment Decorator';
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Export\Decorators;
class RecurringInvoiceDecorator implements DecoratorInterface
{
public function transform(): string
{
return 'Payment Decorator';
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Export\Decorators;
class TaskDecorator implements DecoratorInterface
{
public function transform(): string
{
return 'Payment Decorator';
}
}

View File

@ -0,0 +1,20 @@
<?php
/**
* Invoice Ninja (https://invoiceninja.com).
*
* @link https://github.com/invoiceninja/invoiceninja source repository
*
* @copyright Copyright (c) 2023. Invoice Ninja LLC (https://invoiceninja.com)
*
* @license https://www.elastic.co/licensing/elastic-license
*/
namespace App\Export\Decorators;
class VendorDecorator implements DecoratorInterface
{
public function transform(): string
{
return 'Payment Decorator';
}
}

View File

@ -96,8 +96,6 @@ class EmailRefundPayment implements ShouldQueue
}
}
$nmo->mailable = new TemplateEmail($email_builder, $this->contact, $invitation);
$nmo->to_user = $this->contact;
$nmo->settings = $this->settings;

View File

@ -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;
}