mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-23 20:00:33 -04:00
Working on export decoration
This commit is contained in:
parent
8367b388ef
commit
6d36f57d35
@ -11,14 +11,15 @@
|
|||||||
|
|
||||||
namespace App\Export\CSV;
|
namespace App\Export\CSV;
|
||||||
|
|
||||||
use App\Libraries\MultiDB;
|
use App\Utils\Ninja;
|
||||||
|
use League\Csv\Writer;
|
||||||
use App\Models\Company;
|
use App\Models\Company;
|
||||||
use App\Models\Payment;
|
use App\Models\Payment;
|
||||||
use App\Transformers\PaymentTransformer;
|
use App\Libraries\MultiDB;
|
||||||
use App\Utils\Ninja;
|
|
||||||
use Illuminate\Database\Eloquent\Builder;
|
|
||||||
use Illuminate\Support\Facades\App;
|
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
|
class PaymentExport extends BaseExport
|
||||||
{
|
{
|
||||||
@ -28,11 +29,14 @@ class PaymentExport extends BaseExport
|
|||||||
|
|
||||||
public Writer $csv;
|
public Writer $csv;
|
||||||
|
|
||||||
|
private Decorator $decorator;
|
||||||
|
|
||||||
public function __construct(Company $company, array $input)
|
public function __construct(Company $company, array $input)
|
||||||
{
|
{
|
||||||
$this->company = $company;
|
$this->company = $company;
|
||||||
$this->input = $input;
|
$this->input = $input;
|
||||||
$this->entity_transformer = new PaymentTransformer();
|
$this->entity_transformer = new PaymentTransformer();
|
||||||
|
$this->decorator = new Decorator();
|
||||||
}
|
}
|
||||||
|
|
||||||
private function init(): Builder
|
private function init(): Builder
|
||||||
|
@ -24,28 +24,90 @@ use App\Models\Product;
|
|||||||
use App\Models\Project;
|
use App\Models\Project;
|
||||||
use App\Models\PurchaseOrder;
|
use App\Models\PurchaseOrder;
|
||||||
use App\Models\RecurringInvoice;
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -11,10 +11,13 @@
|
|||||||
|
|
||||||
namespace App\Export\Decorators;
|
namespace App\Export\Decorators;
|
||||||
|
|
||||||
class PaymentDecorator implements DecoratorInterface{
|
use App\Models\Payment;
|
||||||
|
|
||||||
|
class PaymentDecorator extends Decorator implements DecoratorInterface{
|
||||||
|
|
||||||
public function transform(): string
|
public function transform(): string
|
||||||
{
|
{
|
||||||
return 'Payment Decorator';
|
return 'Payment Decorator';
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user