diff --git a/app/Export/CSV/PaymentExport.php b/app/Export/CSV/PaymentExport.php index c92fc5983f34..425375295821 100644 --- a/app/Export/CSV/PaymentExport.php +++ b/app/Export/CSV/PaymentExport.php @@ -11,14 +11,15 @@ namespace App\Export\CSV; -use App\Libraries\MultiDB; +use App\Utils\Ninja; +use League\Csv\Writer; use App\Models\Company; use App\Models\Payment; -use App\Transformers\PaymentTransformer; -use App\Utils\Ninja; -use Illuminate\Database\Eloquent\Builder; +use App\Libraries\MultiDB; use Illuminate\Support\Facades\App; -use League\Csv\Writer; +use App\Transformers\PaymentTransformer; +use Illuminate\Database\Eloquent\Builder; +use App\Export\Decorators\Decorator; class PaymentExport extends BaseExport { @@ -28,13 +29,16 @@ class PaymentExport extends BaseExport public Writer $csv; + private Decorator $decorator; + public function __construct(Company $company, array $input) { $this->company = $company; $this->input = $input; $this->entity_transformer = new PaymentTransformer(); + $this->decorator = new Decorator(); } - + private function init(): Builder { diff --git a/app/Export/Decorators/Decorator.php b/app/Export/Decorators/Decorator.php index 0a55e60ed149..970151dae739 100644 --- a/app/Export/Decorators/Decorator.php +++ b/app/Export/Decorators/Decorator.php @@ -24,28 +24,90 @@ use App\Models\Product; use App\Models\Project; use App\Models\PurchaseOrder; use App\Models\RecurringInvoice; +use App\Export\Decorators\DecoratorInterface; -class Decorator { +class Decorator implements DecoratorInterface{ - public function __invoke(mixed $entity, string $key) + public $entity; + + public function __construct() { - 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; } + public function transform(): string + { + return 'Decorator'; + } + + public function invoice(): InvoiceDecorator + { + return new InvoiceDecorator(); + } + + public function client(): ClientDecorator + { + return new ClientDecorator(); + } + + public function payment(): PaymentDecorator + { + return new PaymentDecorator(); + } + + public function credit(): CreditDecorator + { + return new CreditDecorator(); + } + + public function vendor(): VendorDecorator + { + return new VendorDecorator(); + } + + public function expense(): ExpenseDecorator + { + return new ExpenseDecorator(); + } + + public function product(): ProductDecorator + { + return new ProductDecorator(); + } + + public function project(): ProjectDecorator + { + return new ProjectDecorator(); + } + + public function task(): TaskDecorator + { + return new TaskDecorator(); + } + + public function quote(): QuoteDecorator + { + return new QuoteDecorator(); + } + + public function recurring_invoice(): RecurringInvoiceDecorator + { + return new RecurringInvoiceDecorator(); + } + + public function purchase_order(): PurchaseOrderDecorator + { + return new PurchaseOrderDecorator(); + } + + public function setEntity($entity): self + { + $this->entity = $entity; + + return $this; + } + + public function getEntity(): mixed + { + return $this->entity; + } } diff --git a/app/Export/Decorators/PaymentDecorator.php b/app/Export/Decorators/PaymentDecorator.php index 9a287d4a0816..ae0fea96c4e5 100644 --- a/app/Export/Decorators/PaymentDecorator.php +++ b/app/Export/Decorators/PaymentDecorator.php @@ -11,10 +11,13 @@ namespace App\Export\Decorators; -class PaymentDecorator implements DecoratorInterface{ +use App\Models\Payment; + +class PaymentDecorator extends Decorator implements DecoratorInterface{ public function transform(): string { return 'Payment Decorator'; } + } \ No newline at end of file