mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-08 12:12:48 +01:00
Updates for decorators
This commit is contained in:
parent
fd66e2f59b
commit
9b4382b451
@ -141,35 +141,20 @@ class ClientDecorator extends Decorator implements DecoratorInterface
|
||||
ctrans("texts.{$client->classification}") ?? '';
|
||||
}
|
||||
|
||||
public function status(Client $client)
|
||||
{
|
||||
if ($client->is_deleted) {
|
||||
return ctrans('texts.deleted');
|
||||
}
|
||||
|
||||
if ($client->deleted_at) {
|
||||
return ctrans('texts.archived');
|
||||
}
|
||||
|
||||
////////contact details/////////////////
|
||||
/*
|
||||
public function phone(Client $client) {
|
||||
|
||||
return ctrans('texts.active');
|
||||
}
|
||||
public function first_name(Client $client) {
|
||||
|
||||
}
|
||||
public function last_name(Client $client) {
|
||||
|
||||
}
|
||||
public function email(Client $client) {
|
||||
|
||||
}
|
||||
public function custom_value1(Client $client) {
|
||||
|
||||
}
|
||||
public function custom_value2(Client $client) {
|
||||
|
||||
}
|
||||
public function custom_value3(Client $client) {
|
||||
|
||||
}
|
||||
public function custom_value4(Client $client) {
|
||||
|
||||
}
|
||||
*/
|
||||
|
||||
|
||||
}
|
||||
|
@ -11,10 +11,51 @@
|
||||
|
||||
namespace App\Export\Decorators;
|
||||
|
||||
use App\Models\ClientContact;
|
||||
|
||||
class ContactDecorator implements DecoratorInterface
|
||||
{
|
||||
public function transform(string $key, mixed $entity): mixed
|
||||
{
|
||||
return 'Payment Decorator';
|
||||
$contact = false;
|
||||
|
||||
if($entity instanceof ClientContact) {
|
||||
$contact = $entity;
|
||||
} elseif($entity->contacts) {
|
||||
$contact = $entity->contacts()->first();
|
||||
}
|
||||
|
||||
if($contact && method_exists($this, $key)) {
|
||||
return $this->{$key}($contact);
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
}
|
||||
|
||||
public function phone(ClientContact $contact) {
|
||||
return $contact->phone ?? '';
|
||||
}
|
||||
public function first_name(ClientContact $contact) {
|
||||
return $contact->first_name ?? '';
|
||||
}
|
||||
public function last_name(ClientContact $contact) {
|
||||
return $contact->last_name ?? '';
|
||||
}
|
||||
public function email(ClientContact $contact) {
|
||||
return $contact->email ?? '';
|
||||
}
|
||||
public function custom_value1(ClientContact $contact) {
|
||||
return $contact->custom_value1 ?? '';
|
||||
}
|
||||
public function custom_value2(ClientContact $contact) {
|
||||
return $contact->custom_value2 ?? '';
|
||||
}
|
||||
public function custom_value3(ClientContact $contact) {
|
||||
return $contact->custom_value3 ?? '';
|
||||
}
|
||||
public function custom_value4(ClientContact $contact) {
|
||||
return $contact->custom_value4 ?? '';
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,10 +11,114 @@
|
||||
|
||||
namespace App\Export\Decorators;
|
||||
|
||||
use App\Models\Credit;
|
||||
|
||||
class CreditDecorator implements DecoratorInterface
|
||||
{
|
||||
public function transform(string $key, mixed $entity): mixed
|
||||
{
|
||||
return 'Payment Decorator';
|
||||
$credit = false;
|
||||
|
||||
if($entity instanceof Credit) {
|
||||
$credit = $entity;
|
||||
} elseif($entity->credit) {
|
||||
$credit = $entity->credit;
|
||||
}
|
||||
|
||||
if($credit && method_exists($this, $key)) {
|
||||
return $this->{$key}($credit);
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
}
|
||||
|
||||
public function number(Credit $credit ) {
|
||||
return $credit->number ?? '';
|
||||
}
|
||||
public function amount(Credit $credit ) {
|
||||
return $credit->amount ?? 0;
|
||||
}
|
||||
public function balance(Credit $credit ) {
|
||||
return $credit->balance ?? 0;
|
||||
}
|
||||
public function paid_to_date(Credit $credit ) {
|
||||
return $credit->paid_to_date ?? 0;
|
||||
}
|
||||
public function po_number(Credit $credit ) {
|
||||
return $credit->po_number ?? '';
|
||||
}
|
||||
public function date(Credit $credit ) {
|
||||
return $credit->date ?? '';
|
||||
}
|
||||
public function due_date(Credit $credit ) {
|
||||
return $credit->due_date ?? '';
|
||||
}
|
||||
public function terms(Credit $credit ) {
|
||||
return $credit->terms ?? '';
|
||||
}
|
||||
public function discount(Credit $credit ) {
|
||||
return $credit->discount ?? 0;
|
||||
}
|
||||
public function footer(Credit $credit ) {
|
||||
return $credit->footer ?? '';
|
||||
}
|
||||
public function status(Credit $credit ) {
|
||||
return $credit->stringStatus($credit->status_id);
|
||||
}
|
||||
public function public_notes(Credit $credit ) {
|
||||
return $credit->public_notes ?? '';
|
||||
}
|
||||
public function private_notes(Credit $credit ) {
|
||||
return $credit->private_notes ?? '';
|
||||
}
|
||||
public function uses_inclusive_taxes(Credit $credit ) {
|
||||
return $credit->uses_inclusive_taxes ? ctrans('texts.yes') : ctrans('texts.no');
|
||||
}
|
||||
public function is_amount_discount(Credit $credit ) {
|
||||
return $credit->is_amount_discount ? ctrans('texts.yes') : ctrans('texts.no');
|
||||
}
|
||||
public function partial(Credit $credit ) {
|
||||
return $credit->partial ?? 0;
|
||||
}
|
||||
public function partial_due_date(Credit $credit ) {
|
||||
return $credit->partial_due_date ?? '';
|
||||
}
|
||||
public function custom_surcharge1(Credit $credit ) {
|
||||
return $credit->custom_surcharge1 ?? 0;
|
||||
}
|
||||
public function custom_surcharge2(Credit $credit ) {
|
||||
return $credit->custom_surcharge2 ?? 0;
|
||||
}
|
||||
public function custom_surcharge3(Credit $credit ) {
|
||||
return $credit->custom_surcharge3 ?? 0;
|
||||
}
|
||||
public function custom_surcharge4(Credit $credit ) {
|
||||
return $credit->custom_surcharge4 ?? 0;
|
||||
}
|
||||
public function custom_value1(Credit $credit ) {
|
||||
return $credit->custom_value1 ?? '';
|
||||
}
|
||||
public function custom_value2(Credit $credit ) {
|
||||
return $credit->custom_value2 ?? '';
|
||||
}
|
||||
public function custom_value3(Credit $credit ) {
|
||||
return $credit->custom_value3 ?? '';
|
||||
}
|
||||
public function custom_value4(Credit $credit ) {
|
||||
return $credit->custom_value4 ?? '';
|
||||
}
|
||||
public function exchange_rate(Credit $credit ) {
|
||||
return $credit->exchange_rate ?? 0;
|
||||
}
|
||||
public function total_taxes(Credit $credit ) {
|
||||
return $credit->total_taxes ?? 0;
|
||||
}
|
||||
public function assigned_user_id(Credit $credit ) {
|
||||
return $credit->assigned_user ? $credit->assigned_user->present()->name(): '';
|
||||
}
|
||||
public function user_id(Credit $credit ) {
|
||||
return $credit->user ? $credit->user->present()->name(): '';
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,10 +11,123 @@
|
||||
|
||||
namespace App\Export\Decorators;
|
||||
|
||||
use App\Models\Expense;
|
||||
|
||||
class ExpenseDecorator implements DecoratorInterface
|
||||
{
|
||||
public function transform(string $key, mixed $entity): mixed
|
||||
{
|
||||
return 'Payment Decorator';
|
||||
$expense = false;
|
||||
|
||||
if($entity instanceof Expense) {
|
||||
$expense = $entity;
|
||||
} elseif($entity->expense) {
|
||||
$expense = $entity->expense;
|
||||
}
|
||||
|
||||
if($expense && method_exists($this, $key)) {
|
||||
return $this->{$key}($expense);
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
}
|
||||
|
||||
public function amount(Expense $expense) {
|
||||
return $expense->amount ?? 0;
|
||||
}
|
||||
public function category_id(Expense $expense) {
|
||||
return $expense->category ? $expense->category->name : '';
|
||||
}
|
||||
public function client_id(Expense $expense) {
|
||||
return $expense->client ? $expense->client->present()->name() : '';
|
||||
}
|
||||
public function custom_value1(Expense $expense) {
|
||||
return $expense->custom_value1 ?? '';
|
||||
}
|
||||
public function custom_value2(Expense $expense) {
|
||||
return $expense->custom_value2 ?? '';
|
||||
}
|
||||
public function custom_value3(Expense $expense) {
|
||||
return $expense->custom_value3 ?? '';
|
||||
}
|
||||
public function custom_value4(Expense $expense) {
|
||||
return $expense->custom_value4 ?? '';
|
||||
}
|
||||
public function currency_id(Expense $expense) {
|
||||
return $expense->currency ? $expense->currency->code : $expense->company->currency()->code;
|
||||
}
|
||||
public function date(Expense $expense) {
|
||||
return $expense->date ?? '';
|
||||
}
|
||||
public function exchange_rate(Expense $expense) {
|
||||
return $expense->exchange_rate ?? 0;
|
||||
}
|
||||
public function foreign_amount(Expense $expense) {
|
||||
return $expense->foreign_amount ?? 0;
|
||||
}
|
||||
public function invoice_currency_id(Expense $expense) {
|
||||
return $expense->invoice_currency ? $expense->invoice_currency->code : $expense->company->currency()->code;
|
||||
}
|
||||
public function payment_date(Expense $expense) {
|
||||
return $expense->payment_date ?? '';
|
||||
}
|
||||
public function number(Expense $expense) {
|
||||
return $expense->number ?? '';
|
||||
}
|
||||
public function payment_type_id(Expense $expense) {
|
||||
return $expense->payment_type ? $expense->payment_type->name : '';
|
||||
}
|
||||
public function private_notes(Expense $expense) {
|
||||
return $expense->private_notes ?? '';
|
||||
}
|
||||
public function project_id(Expense $expense) {
|
||||
return $expense->project ? $expense->project->name : '';
|
||||
}
|
||||
public function public_notes(Expense $expense) {
|
||||
return $expense->public_notes ?? '';
|
||||
}
|
||||
public function tax_amount1(Expense $expense) {
|
||||
return $expense->tax_amount1 ?? 0;
|
||||
}
|
||||
public function tax_amount2(Expense $expense) {
|
||||
return $expense->tax_amount2 ?? 0;
|
||||
}
|
||||
public function tax_amount3(Expense $expense) {
|
||||
return $expense->tax_amount3 ?? 0;
|
||||
}
|
||||
public function tax_name1(Expense $expense) {
|
||||
return $expense->tax_name1 ?? '';
|
||||
}
|
||||
public function tax_name2(Expense $expense) {
|
||||
return $expense->tax_name2 ?? '';
|
||||
}
|
||||
public function tax_name3(Expense $expense) {
|
||||
return $expense->tax_name3 ?? '';
|
||||
}
|
||||
public function tax_rate1(Expense $expense) {
|
||||
return $expense->tax_rate1 ?? 0;
|
||||
}
|
||||
public function tax_rate2(Expense $expense) {
|
||||
return $expense->tax_rate2 ?? 0;
|
||||
}
|
||||
public function tax_rate3(Expense $expense) {
|
||||
return $expense->tax_rate3 ?? 0;
|
||||
}
|
||||
public function transaction_reference(Expense $expense) {
|
||||
return $expense->transaction_reference ?? '';
|
||||
}
|
||||
public function vendor_id(Expense $expense) {
|
||||
return $expense->vendor ? $expense->vendor->name : '';
|
||||
}
|
||||
public function invoice_id(Expense $expense) {
|
||||
return $expense->invoice ? $expense->invoice->number : '';
|
||||
}
|
||||
public function user(Expense $expense) {
|
||||
return $expense->user ? $expense->user->present()->name() : '';
|
||||
}
|
||||
public function assigned_user(Expense $expense) {
|
||||
return $expense->assigned_user ? $expense->assigned_user->present()->name() : '';
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,10 +11,141 @@
|
||||
|
||||
namespace App\Export\Decorators;
|
||||
|
||||
use App\Models\Invoice;
|
||||
|
||||
class InvoiceDecorator extends Decorator implements DecoratorInterface
|
||||
{
|
||||
public function transform(string $key, mixed $entity): mixed
|
||||
{
|
||||
return 'Payment Decorator';
|
||||
$invoice = false;
|
||||
|
||||
if($entity instanceof Invoice) {
|
||||
$invoice = $entity;
|
||||
} elseif($entity->invoice) {
|
||||
$invoice = $entity->invoice;
|
||||
}
|
||||
|
||||
if($invoice && method_exists($this, $key)) {
|
||||
return $this->{$key}($invoice);
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
}
|
||||
|
||||
|
||||
public function number(Invoice $invoice) {
|
||||
return $invoice->number ?? '';
|
||||
}
|
||||
public function amount(Invoice $invoice) {
|
||||
return $invoice->amount ?? 0;
|
||||
}
|
||||
public function balance(Invoice $invoice) {
|
||||
return $invoice->balance ?? 0;
|
||||
}
|
||||
public function paid_to_date(Invoice $invoice) {
|
||||
return $invoice->paid_to_date ?? 0;
|
||||
}
|
||||
public function po_number(Invoice $invoice) {
|
||||
return $invoice->po_number ?? '';
|
||||
}
|
||||
public function date(Invoice $invoice) {
|
||||
return $invoice->date ?? '';
|
||||
}
|
||||
public function due_date(Invoice $invoice) {
|
||||
return $invoice->due_date ?? '';
|
||||
}
|
||||
public function terms(Invoice $invoice) {
|
||||
return $invoice->terms ?? '';
|
||||
}
|
||||
public function footer(Invoice $invoice) {
|
||||
return $invoice->footer ?? '';
|
||||
}
|
||||
public function status(Invoice $invoice) {
|
||||
return $invoice->stringStatus($invoice->status_id);
|
||||
}
|
||||
public function public_notes(Invoice $invoice) {
|
||||
return $invoice->public_notes ?? '';
|
||||
}
|
||||
public function private_notes(Invoice $invoice) {
|
||||
return $invoice->private_notes ?? '';
|
||||
}
|
||||
public function uses_inclusive_taxes(Invoice $invoice) {
|
||||
return $invoice->uses_inclusive_taxes ? ctrans('texts.yes') : ctrans('texts.no');
|
||||
}
|
||||
public function is_amount_discount(Invoice $invoice) {
|
||||
return $invoice->is_amount_discount ? ctrans('texts.yes') : ctrans('texts.no');
|
||||
}
|
||||
public function discount(Invoice $invoice) {
|
||||
return $invoice->discount ?? 0;
|
||||
}
|
||||
public function partial(Invoice $invoice) {
|
||||
return $invoice->partial ?? 0;
|
||||
}
|
||||
public function partial_due_date(Invoice $invoice) {
|
||||
return $invoice->partial_due_date ?? '';
|
||||
}
|
||||
public function custom_surcharge1(Invoice $invoice) {
|
||||
return $invoice->custom_surcharge1 ?? 0;
|
||||
}
|
||||
public function custom_surcharge2(Invoice $invoice) {
|
||||
return $invoice->custom_surcharge2 ?? 0;
|
||||
}
|
||||
public function custom_surcharge3(Invoice $invoice) {
|
||||
return $invoice->custom_surcharge3 ?? 0;
|
||||
}
|
||||
public function custom_surcharge4(Invoice $invoice) {
|
||||
return $invoice->custom_surcharge4 ?? 0;
|
||||
}
|
||||
public function exchange_rate(Invoice $invoice) {
|
||||
return $invoice->exchange_rate ?? 0;
|
||||
}
|
||||
public function total_taxes(Invoice $invoice) {
|
||||
return $invoice->total_taxes ?? 0;
|
||||
}
|
||||
public function assigned_user_id(Invoice $invoice) {
|
||||
return $invoice->assigned_user ? $invoice->assigned_user->present()->name(): '';
|
||||
}
|
||||
public function user_id(Invoice $invoice) {
|
||||
return $invoice->user ? $invoice->user->present()->name(): '';
|
||||
}
|
||||
public function custom_value1(Invoice $invoice) {
|
||||
return $invoice->custom_value1 ?? '';
|
||||
}
|
||||
public function custom_value2(Invoice $invoice) {
|
||||
return $invoice->custom_value2 ?? '';
|
||||
}
|
||||
public function custom_value3(Invoice $invoice) {
|
||||
return $invoice->custom_value3 ?? '';
|
||||
}
|
||||
public function custom_value4(Invoice $invoice) {
|
||||
return $invoice->custom_value4 ?? '';
|
||||
}
|
||||
public function tax_name1(Invoice $invoice) {
|
||||
return $invoice->tax_name1 ?? '';
|
||||
}
|
||||
public function tax_name2(Invoice $invoice) {
|
||||
return $invoice->tax_name2 ?? '';
|
||||
}
|
||||
public function tax_name3(Invoice $invoice) {
|
||||
return $invoice->tax_name3 ?? '';
|
||||
}
|
||||
public function tax_rate1(Invoice $invoice) {
|
||||
return $invoice->tax_rate1 ?? 0;
|
||||
}
|
||||
public function tax_rate2(Invoice $invoice) {
|
||||
return $invoice->tax_rate2 ?? 0;
|
||||
}
|
||||
public function tax_rate3(Invoice $invoice) {
|
||||
return $invoice->tax_rate3 ?? 0;
|
||||
}
|
||||
public function recurring_id(Invoice $invoice) {
|
||||
return $invoice->recurring_invoice ? $invoice->recurring_invoice->number : '';
|
||||
}
|
||||
public function auto_bill_enabled(Invoice $invoice) {
|
||||
return $invoice->auto_bill_enabled ? ctrans('texts.yes') : ctrans('texts.no');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
@ -11,10 +11,62 @@
|
||||
|
||||
namespace App\Export\Decorators;
|
||||
|
||||
use App\Models\Product;
|
||||
|
||||
class ProductDecorator implements DecoratorInterface
|
||||
{
|
||||
public function transform(string $key, mixed $entity): mixed
|
||||
{
|
||||
return 'Payment Decorator';
|
||||
$product = false;
|
||||
|
||||
if($entity instanceof Product) {
|
||||
$product = $entity;
|
||||
} elseif($entity->product) {
|
||||
$product = $entity->product;
|
||||
}
|
||||
|
||||
if($product && method_exists($this, $key)) {
|
||||
return $this->{$key}($product);
|
||||
}
|
||||
elseif($product->{$key})
|
||||
return $product->{$key} ?? '';
|
||||
|
||||
return '';
|
||||
|
||||
}
|
||||
|
||||
/*
|
||||
public const PRODUCT_TYPE_PHYSICAL = 1;
|
||||
public const PRODUCT_TYPE_SERVICE = 2;
|
||||
public const PRODUCT_TYPE_DIGITAL = 3;
|
||||
public const PRODUCT_TYPE_SHIPPING = 4;
|
||||
public const PRODUCT_TYPE_EXEMPT = 5;
|
||||
public const PRODUCT_TYPE_REDUCED_TAX = 6;
|
||||
public const PRODUCT_TYPE_OVERRIDE_TAX = 7;
|
||||
public const PRODUCT_TYPE_ZERO_RATED = 8;
|
||||
public const PRODUCT_TYPE_REVERSE_TAX = 9;
|
||||
*/
|
||||
public function tax_category(Product $product) {
|
||||
|
||||
$category = ctrans('texts.physical_goods');
|
||||
|
||||
match($product->tax_id){
|
||||
1 => $category = ctrans('texts.physical_goods'),
|
||||
2 => $category = ctrans('texts.services'),
|
||||
3 => $category = ctrans('texts.digital_products'),
|
||||
4 => $category = ctrans('texts.shipping'),
|
||||
5 => $category = ctrans('texts.tax_exempt'),
|
||||
6 => $category = ctrans('texts.reduced_tax'),
|
||||
7 => $category = ctrans('texts.override_tax'),
|
||||
8 => $category = ctrans('texts.zero_rated'),
|
||||
9 => $category = ctrans('texts.reverse_tax'),
|
||||
default => $category = ctrans('texts.physical_goods'),
|
||||
};
|
||||
|
||||
return $category;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
@ -11,10 +11,36 @@
|
||||
|
||||
namespace App\Export\Decorators;
|
||||
|
||||
use App\Models\PurchaseOrder;
|
||||
|
||||
class PurchaseOrderDecorator extends Decorator implements DecoratorInterface
|
||||
{
|
||||
public function transform(string $key, mixed $entity): mixed
|
||||
{
|
||||
return 'Payment Decorator';
|
||||
$purchase_order = false;
|
||||
|
||||
if($entity instanceof PurchaseOrder) {
|
||||
$purchase_order = $entity;
|
||||
} elseif($entity->purchase_order) {
|
||||
$purchase_order = $entity->purchase_order;
|
||||
}
|
||||
|
||||
if($purchase_order && method_exists($this, $key)) {
|
||||
return $this->{$key}($purchase_order);
|
||||
}
|
||||
elseif($purchase_order->{$key})
|
||||
return $purchase_order->{$key} ?? '';
|
||||
|
||||
return '';
|
||||
|
||||
}
|
||||
|
||||
public function status(PurchaseOrder $purchase_order) {
|
||||
return $purchase_order->stringStatus($purchase_order->status_id);
|
||||
}
|
||||
|
||||
public function currency_id(PurchaseOrder $purchase_order) {
|
||||
return $purchase_order->currency ? $purchase_order->currency->code : $purchase_order->company->currency()->code;
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,10 +11,45 @@
|
||||
|
||||
namespace App\Export\Decorators;
|
||||
|
||||
use App\Models\Quote;
|
||||
|
||||
class QuoteDecorator extends Decorator implements DecoratorInterface
|
||||
{
|
||||
public function transform(string $key, mixed $entity): mixed
|
||||
{
|
||||
return 'Payment Decorator';
|
||||
$quote = false;
|
||||
|
||||
if($entity instanceof Quote) {
|
||||
$quote = $entity;
|
||||
} elseif($entity->quote) {
|
||||
$quote = $entity->quote;
|
||||
}
|
||||
|
||||
if($quote && method_exists($this, $key)) {
|
||||
return $this->{$key}($quote);
|
||||
} elseif($quote->{$key}) {
|
||||
return $quote->{$key} ?? '';
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
}
|
||||
|
||||
public function status(Quote $quote) {
|
||||
return $quote->stringStatus($quote->status_id);
|
||||
}
|
||||
public function uses_inclusive_taxes(Quote $quote) {
|
||||
return $quote->uses_inclusive_taxes ? ctrans('texts.yes') : ctrans('texts.no');
|
||||
}
|
||||
public function is_amount_discount(Quote $quote) {
|
||||
return $quote->is_amount_discount ? ctrans('texts.yes') : ctrans('texts.no');
|
||||
}
|
||||
public function assigned_user_id(Quote $quote) {
|
||||
return $quote->assigned_user ? $quote->assigned_user->present()->name() : '';
|
||||
}
|
||||
public function user_id(Quote $quote) {
|
||||
return $quote->user->present()->name();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
@ -11,10 +11,53 @@
|
||||
|
||||
namespace App\Export\Decorators;
|
||||
|
||||
use App\Models\RecurringInvoice;
|
||||
|
||||
class RecurringInvoiceDecorator extends Decorator implements DecoratorInterface
|
||||
{
|
||||
public function transform(string $key, mixed $entity): mixed
|
||||
{
|
||||
return 'Payment Decorator';
|
||||
$recurring_invoice = false;
|
||||
|
||||
if($entity instanceof RecurringInvoice) {
|
||||
$recurring_invoice = $entity;
|
||||
} elseif($entity->recurring_invoice) {
|
||||
$recurring_invoice = $entity->recurring_invoice;
|
||||
}
|
||||
|
||||
if($recurring_invoice && method_exists($this, $key)) {
|
||||
return $this->{$key}($recurring_invoice);
|
||||
} elseif($recurring_invoice->{$key}) {
|
||||
return $recurring_invoice->{$key} ?? '';
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
}
|
||||
|
||||
public function status(RecurringInvoice $recurring_invoice) {
|
||||
return $recurring_invoice->stringStatus($recurring_invoice->status_id);
|
||||
}
|
||||
public function uses_inclusive_taxes(RecurringInvoice $recurring_invoice) {
|
||||
return $recurring_invoice->uses_inclusive_taxes ? ctrans('texts.yes') : ctrans('texts.no');
|
||||
}
|
||||
public function is_amount_discount(RecurringInvoice $recurring_invoice) {
|
||||
return $recurring_invoice->is_amount_discount ? ctrans('texts.yes') : ctrans('texts.no');
|
||||
}
|
||||
public function assigned_user_id(RecurringInvoice $recurring_invoice) {
|
||||
return $recurring_invoice->assigned_user ? $recurring_invoice->assigned_user->present()->name() : '';
|
||||
}
|
||||
public function user_id(RecurringInvoice $recurring_invoice) {
|
||||
return $recurring_invoice->user->present()->name() ?? '';
|
||||
}
|
||||
public function frequency_id(RecurringInvoice $recurring_invoice) {
|
||||
return $recurring_invoice->frequency_id ? $recurring_invoice->frequencyForKey($recurring_invoice->frequency_id) : '';
|
||||
}
|
||||
public function auto_bill(RecurringInvoice $recurring_invoice) {
|
||||
return $recurring_invoice->auto_bill ? ctrans("texts.{$recurring_invoice->auto_bill}") : '';
|
||||
}
|
||||
public function auto_bill_enabled(RecurringInvoice $recurring_invoice) {
|
||||
return $recurring_invoice->auto_bill_enabled ? ctrans('texts.yes') : ctrans('texts.no');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -11,10 +11,97 @@
|
||||
|
||||
namespace App\Export\Decorators;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use App\Models\Task;
|
||||
use App\Models\Timezone;
|
||||
use App\Models\DateFormat;
|
||||
|
||||
class TaskDecorator extends Decorator implements DecoratorInterface
|
||||
{
|
||||
public function transform(string $key, mixed $entity): mixed
|
||||
{
|
||||
return 'Payment Decorator';
|
||||
$task = false;
|
||||
|
||||
if($entity instanceof Task) {
|
||||
$task = $entity;
|
||||
} elseif($entity->task) {
|
||||
$task = $entity->task;
|
||||
}
|
||||
|
||||
if($task && method_exists($this, $key)) {
|
||||
return $this->{$key}($task);
|
||||
} elseif($task->{$key}) {
|
||||
return $task->{$key} ?? '';
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
}
|
||||
|
||||
public function start_date(Task $task){
|
||||
|
||||
$timezone = Timezone::find($task->company->settings->timezone_id);
|
||||
$timezone_name = 'US/Eastern';
|
||||
|
||||
if ($timezone) {
|
||||
$timezone_name = $timezone->name;
|
||||
}
|
||||
|
||||
$logs = json_decode($task->time_log, 1);
|
||||
|
||||
$date_format_default = 'Y-m-d';
|
||||
|
||||
$date_format = DateFormat::find($task->company->settings->date_format_id);
|
||||
|
||||
if ($date_format) {
|
||||
$date_format_default = $date_format->format;
|
||||
}
|
||||
|
||||
if(is_array($logs)){
|
||||
$item = $logs[0];
|
||||
return Carbon::createFromTimeStamp($item[0])->setTimezone($timezone_name)->format($date_format_default);
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
}
|
||||
|
||||
public function end_date(Task $task){
|
||||
|
||||
$timezone = Timezone::find($task->company->settings->timezone_id);
|
||||
$timezone_name = 'US/Eastern';
|
||||
|
||||
if ($timezone) {
|
||||
$timezone_name = $timezone->name;
|
||||
}
|
||||
|
||||
$logs = json_decode($task->time_log, 1);
|
||||
|
||||
$date_format_default = 'Y-m-d';
|
||||
|
||||
$date_format = DateFormat::find($task->company->settings->date_format_id);
|
||||
|
||||
if ($date_format) {
|
||||
$date_format_default = $date_format->format;
|
||||
}
|
||||
|
||||
if(is_array($logs)) {
|
||||
$item = $logs[1];
|
||||
return Carbon::createFromTimeStamp($item[1])->setTimezone($timezone_name)->format($date_format_default);
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
}
|
||||
public function duration(Task $task){
|
||||
return $task->calcDuration();
|
||||
}
|
||||
public function status_id(Task $task){
|
||||
return $task->status()->exists() ? $task->status->name : '';
|
||||
}
|
||||
public function project_id(Task $task){
|
||||
return $task->project()->exists() ? $task->project->name : '';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -11,10 +11,29 @@
|
||||
|
||||
namespace App\Export\Decorators;
|
||||
|
||||
use App\Models\VendorContact;
|
||||
|
||||
class VendorContactDecorator implements DecoratorInterface
|
||||
{
|
||||
public function transform(string $key, mixed $entity): mixed
|
||||
{
|
||||
return 'Payment Decorator';
|
||||
$contact = false;
|
||||
|
||||
if($entity instanceof VendorContact) {
|
||||
$contact = $entity;
|
||||
} elseif($entity->contacts) {
|
||||
$contact = $entity->contacts()->first();
|
||||
}
|
||||
|
||||
if($contact && method_exists($this, $key)) {
|
||||
return $this->{$key}($contact);
|
||||
}
|
||||
elseif($contact->{$key})
|
||||
return $contact->{$key} ?? '';
|
||||
|
||||
return '';
|
||||
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -11,10 +11,54 @@
|
||||
|
||||
namespace App\Export\Decorators;
|
||||
|
||||
use App\Models\Vendor;
|
||||
|
||||
class VendorDecorator extends Decorator implements DecoratorInterface
|
||||
{
|
||||
public function transform(string $key, mixed $entity): mixed
|
||||
{
|
||||
return 'Payment Decorator';
|
||||
$vendor = false;
|
||||
|
||||
if($entity instanceof Vendor) {
|
||||
$vendor = $entity;
|
||||
} elseif($entity->vendor) {
|
||||
$vendor = $entity->vendor;
|
||||
}
|
||||
|
||||
if($vendor && method_exists($this, $key)) {
|
||||
return $this->{$key}($vendor);
|
||||
} elseif($vendor->{$key}) {
|
||||
return $vendor->{$key} ?? '';
|
||||
}
|
||||
|
||||
return '';
|
||||
|
||||
}
|
||||
|
||||
public function country_id(Vendor $vendor){
|
||||
return $vendor->country ? $vendor->country->name : '';
|
||||
}
|
||||
public function name(Vendor $vendor){
|
||||
return $vendor->present()->name();
|
||||
}
|
||||
public function currency(Vendor $vendor){
|
||||
return $vendor->currency_id ? $vendor->currency()->code : $vendor->company->currency()->code;
|
||||
}
|
||||
public function classification(Vendor $vendor) {
|
||||
ctrans("texts.{$vendor->classification}") ?? '';
|
||||
}
|
||||
|
||||
public function status(Vendor $vendor)
|
||||
{
|
||||
if ($vendor->is_deleted) {
|
||||
return ctrans('texts.deleted');
|
||||
}
|
||||
|
||||
if ($vendor->deleted_at) {
|
||||
return ctrans('texts.archived');
|
||||
}
|
||||
|
||||
return ctrans('texts.active');
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -203,6 +203,11 @@ class Expense extends BaseModel
|
||||
return $this->belongsTo(Currency::class);
|
||||
}
|
||||
|
||||
public function invoice_currency(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Currency::class);
|
||||
}
|
||||
|
||||
public function category(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(ExpenseCategory::class)->withTrashed();
|
||||
|
@ -269,6 +269,11 @@ class PurchaseOrder extends BaseModel
|
||||
return $this->belongsTo(Client::class)->withTrashed();
|
||||
}
|
||||
|
||||
public function currency(): \Illuminate\Database\Eloquent\Relations\BelongsTo
|
||||
{
|
||||
return $this->belongsTo(Currency::class);
|
||||
}
|
||||
|
||||
public function markInvitationsSent(): void
|
||||
{
|
||||
$this->invitations->each(function ($invitation) {
|
||||
|
Loading…
Reference in New Issue
Block a user