mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 21:22:58 +01:00
Merge branch 'v5-develop' of https://github.com/turbo124/invoiceninja into v5-develop
This commit is contained in:
commit
a7b9e85262
@ -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
|
||||
{
|
||||
|
||||
@ -113,6 +117,8 @@ class PaymentExport extends BaseExport
|
||||
} elseif (array_key_exists($key, $transformed_entity)) {
|
||||
$entity[$key] = $transformed_entity[$key];
|
||||
} else {
|
||||
|
||||
// $entity[$key] = $this->decorator->transform($key, $payment);
|
||||
$entity[$key] = $this->resolveKey($key, $payment, $this->entity_transformer);
|
||||
}
|
||||
|
||||
|
@ -24,28 +24,97 @@ 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 $key, mixed $entity): 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;
|
||||
}
|
||||
|
||||
public function getKeyPart(int $index, string $key): string
|
||||
{
|
||||
$parts = explode('.', $key ?? '');
|
||||
|
||||
return $parts[$index];
|
||||
}
|
||||
}
|
||||
|
@ -12,5 +12,5 @@
|
||||
namespace App\Export\Decorators;
|
||||
|
||||
interface DecoratorInterface {
|
||||
public function transform(): string;
|
||||
public function transform(string $key, mixed $entity): string;
|
||||
}
|
||||
|
@ -11,10 +11,20 @@
|
||||
|
||||
namespace App\Export\Decorators;
|
||||
|
||||
class PaymentDecorator implements DecoratorInterface{
|
||||
use App\Models\Payment;
|
||||
|
||||
public function transform(): string
|
||||
class PaymentDecorator extends Decorator implements DecoratorInterface{
|
||||
|
||||
private $key = 'payment';
|
||||
|
||||
public function transform(string $key, $payment): string
|
||||
{
|
||||
$index = $this->getKeyPart(0,$key);
|
||||
|
||||
// match($index)
|
||||
return 'Payment Decorator';
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user