mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Decorators for export
This commit is contained in:
parent
9839a82109
commit
149c5b6a0e
@ -628,11 +628,11 @@ class BaseExport
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(in_array($column, ['client.user_id', 'user_id'])) {
|
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'])) {
|
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'])) {
|
if(in_array($column, ['client.country_id', 'country_id'])) {
|
||||||
@ -760,7 +760,7 @@ class BaseExport
|
|||||||
return $transformed_payment[$column];
|
return $transformed_payment[$column];
|
||||||
} elseif (array_key_exists(str_replace("payment.", "", $column), $transformed_payment)) {
|
} elseif (array_key_exists(str_replace("payment.", "", $column), $transformed_payment)) {
|
||||||
return $transformed_payment[$column];
|
return $transformed_payment[$column];
|
||||||
}
|
}
|
||||||
|
|
||||||
// nlog("export: Could not resolve payment key: {$column}");
|
// nlog("export: Could not resolve payment key: {$column}");
|
||||||
|
|
||||||
|
@ -167,6 +167,14 @@ class PaymentExport extends BaseExport
|
|||||||
$entity['gateway'] = $payment->gateway_type ? $payment->gateway_type->name : 'Unknown Type';
|
$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(',') : '';
|
// $entity['invoices'] = $payment->invoices()->exists() ? $payment->invoices->pluck('number')->implode(',') : '';
|
||||||
|
|
||||||
return $entity;
|
return $entity;
|
||||||
|
@ -157,6 +157,15 @@ class RecurringInvoiceExport extends BaseExport
|
|||||||
$entity['recurring_invoice.auto_bill_enabled'] = $invoice->auto_bill_enabled ? ctrans('texts.yes') : ctrans('texts.no');
|
$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;
|
return $entity;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
20
app/Export/Decorators/ClientDecorator.php
Normal file
20
app/Export/Decorators/ClientDecorator.php
Normal 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';
|
||||||
|
}
|
||||||
|
}
|
20
app/Export/Decorators/CreditDecorator.php
Normal file
20
app/Export/Decorators/CreditDecorator.php
Normal 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';
|
||||||
|
}
|
||||||
|
}
|
51
app/Export/Decorators/Decorator.php
Normal file
51
app/Export/Decorators/Decorator.php
Normal 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
16
app/Export/Decorators/DecoratorInterface.php
Normal file
16
app/Export/Decorators/DecoratorInterface.php
Normal 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;
|
||||||
|
}
|
20
app/Export/Decorators/ExpenseDecorator.php
Normal file
20
app/Export/Decorators/ExpenseDecorator.php
Normal 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';
|
||||||
|
}
|
||||||
|
}
|
20
app/Export/Decorators/InvoiceDecorator.php
Normal file
20
app/Export/Decorators/InvoiceDecorator.php
Normal 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';
|
||||||
|
}
|
||||||
|
}
|
20
app/Export/Decorators/PaymentDecorator.php
Normal file
20
app/Export/Decorators/PaymentDecorator.php
Normal 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';
|
||||||
|
}
|
||||||
|
}
|
20
app/Export/Decorators/ProductDecorator.php
Normal file
20
app/Export/Decorators/ProductDecorator.php
Normal 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';
|
||||||
|
}
|
||||||
|
}
|
20
app/Export/Decorators/ProjectDecorator.php
Normal file
20
app/Export/Decorators/ProjectDecorator.php
Normal 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';
|
||||||
|
}
|
||||||
|
}
|
20
app/Export/Decorators/PurchaseOrderDecorator.php
Normal file
20
app/Export/Decorators/PurchaseOrderDecorator.php
Normal 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';
|
||||||
|
}
|
||||||
|
}
|
20
app/Export/Decorators/QuoteDecorator.php
Normal file
20
app/Export/Decorators/QuoteDecorator.php
Normal 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';
|
||||||
|
}
|
||||||
|
}
|
20
app/Export/Decorators/RecurringInvoiceDecorator.php
Normal file
20
app/Export/Decorators/RecurringInvoiceDecorator.php
Normal 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';
|
||||||
|
}
|
||||||
|
}
|
20
app/Export/Decorators/TaskDecorator.php
Normal file
20
app/Export/Decorators/TaskDecorator.php
Normal 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';
|
||||||
|
}
|
||||||
|
}
|
20
app/Export/Decorators/VendorDecorator.php
Normal file
20
app/Export/Decorators/VendorDecorator.php
Normal 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';
|
||||||
|
}
|
||||||
|
}
|
@ -96,8 +96,6 @@ class EmailRefundPayment implements ShouldQueue
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
$nmo->mailable = new TemplateEmail($email_builder, $this->contact, $invitation);
|
$nmo->mailable = new TemplateEmail($email_builder, $this->contact, $invitation);
|
||||||
$nmo->to_user = $this->contact;
|
$nmo->to_user = $this->contact;
|
||||||
$nmo->settings = $this->settings;
|
$nmo->settings = $this->settings;
|
||||||
|
@ -121,7 +121,7 @@ class TemplateService
|
|||||||
* @return self
|
* @return self
|
||||||
*/
|
*/
|
||||||
public function build(array $data): self
|
public function build(array $data): self
|
||||||
{nlog($data);
|
{
|
||||||
$this->compose()
|
$this->compose()
|
||||||
->processData($data)
|
->processData($data)
|
||||||
->parseNinjaBlocks()
|
->parseNinjaBlocks()
|
||||||
@ -215,7 +215,7 @@ class TemplateService
|
|||||||
{
|
{
|
||||||
|
|
||||||
$this->data = $this->preProcessDataBlocks($data);
|
$this->data = $this->preProcessDataBlocks($data);
|
||||||
// nlog($this->data);
|
nlog($this->data);
|
||||||
return $this;
|
return $this;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -617,7 +617,7 @@ class TemplateService
|
|||||||
'paymentables' => $pivot,
|
'paymentables' => $pivot,
|
||||||
'refund_activity' => $this->getPaymentRefundActivity($payment),
|
'refund_activity' => $this->getPaymentRefundActivity($payment),
|
||||||
];
|
];
|
||||||
|
nlog($data);
|
||||||
return $data;
|
return $data;
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -827,11 +827,11 @@ class TemplateService
|
|||||||
*/
|
*/
|
||||||
public function processPayments($payments): array
|
public function processPayments($payments): array
|
||||||
{
|
{
|
||||||
|
nlog("processing payments");
|
||||||
$payments = collect($payments)->map(function ($payment) {
|
$payments = collect($payments)->map(function ($payment) {
|
||||||
return $this->transformPayment($payment);
|
return $this->transformPayment($payment);
|
||||||
})->toArray();
|
})->toArray();
|
||||||
|
nlog($payments);
|
||||||
return $payments;
|
return $payments;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user