mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-11-10 13:12:50 +01:00
Payment exports
This commit is contained in:
parent
1b6534378d
commit
e8c79ded30
@ -15,6 +15,7 @@ use App\Utils\Number;
|
||||
use App\Models\Client;
|
||||
use App\Models\Invoice;
|
||||
use App\Models\GatewayType;
|
||||
use App\Models\Payment;
|
||||
use League\Fractal\Manager;
|
||||
use Illuminate\Support\Carbon;
|
||||
use App\Utils\Traits\MakesHash;
|
||||
@ -299,10 +300,15 @@ class BaseExport
|
||||
return $entity->client->currency() ? $entity->client->currency()->code : $entity->company->currency()->code;
|
||||
}
|
||||
|
||||
if($column == 'client.payment_terms') {
|
||||
return $entity->client->getSetting('payment_terms');
|
||||
}
|
||||
|
||||
if(array_key_exists($column, $transformed_client))
|
||||
return $transformed_client[$column];
|
||||
|
||||
nlog("export: Could not resolve client key: {$column}");
|
||||
|
||||
return '';
|
||||
|
||||
}
|
||||
@ -311,10 +317,31 @@ class BaseExport
|
||||
{
|
||||
if($transformer instanceof PaymentTransformer)
|
||||
$transformed_invoices = $transformer->includeInvoices($entity);
|
||||
|
||||
$manager = new Manager();
|
||||
$manager->setSerializer(new ArraySerializer());
|
||||
$transformed_invoices = $manager->createData($transformed_invoices)->toArray();
|
||||
|
||||
}
|
||||
|
||||
private function resolvePaymentKey($column, $entity, $transformer)
|
||||
{
|
||||
if($entity instanceof Payment){
|
||||
|
||||
$transformed_payment = $transformer->transform($entity);
|
||||
|
||||
if(array_key_exists($column, $transformed_payment)) {
|
||||
return $transformed_payment[$column];
|
||||
} elseif (array_key_exists(str_replace("payment.", "", $column), $transformed_payment)) {
|
||||
return $transformed_payment[$column];
|
||||
}
|
||||
|
||||
nlog("export: Could not resolve payment key: {$column}");
|
||||
|
||||
return '';
|
||||
|
||||
}
|
||||
|
||||
if($column == 'amount')
|
||||
return $entity->payments()->exists() ? Number::formatMoney($entity->payments()->sum('paymentables.amount'), $entity->company) : ctrans('texts.unpaid');
|
||||
|
||||
|
@ -148,14 +148,6 @@ class CreditExport extends BaseExport
|
||||
$entity['country'] = $credit->client->country ? ctrans("texts.country_{$credit->client->country->name}") : '';
|
||||
}
|
||||
|
||||
if (in_array('client.country_id', $this->input['report_keys'])) {
|
||||
$entity['client.country_id'] = $credit->client->country ? ctrans("texts.country_{$credit->client->country->name}") : '';
|
||||
}
|
||||
|
||||
if (in_array('client.shipping_country_id', $this->input['report_keys'])) {
|
||||
$entity['client.shipping_country_id'] = $credit->client->shipping_country ? ctrans("texts.country_{$credit->client->shipping_country->name}") : '';
|
||||
}
|
||||
|
||||
if (in_array('currency_id', $this->input['report_keys'])) {
|
||||
$entity['currency_id'] = $credit->client->currency() ? $credit->client->currency()->code : $credit->company->currency()->code;
|
||||
}
|
||||
@ -176,22 +168,6 @@ class CreditExport extends BaseExport
|
||||
$entity['credit.status'] = $credit->stringStatus($credit->status_id);
|
||||
}
|
||||
|
||||
if(in_array('client.payment_terms', $this->input['report_keys'])) {
|
||||
$entity['client.payment_terms'] = $credit->client->getSetting('payment_terms');
|
||||
}
|
||||
|
||||
if(in_array('client.size_id', $this->input['report_keys'])) {
|
||||
$entity['client.size_id'] = $credit->client->size?->name ?? '';
|
||||
}
|
||||
|
||||
if(in_array('client.industry_id', $this->input['report_keys'])) {
|
||||
$entity['client.industry_id'] = $credit->client->industry?->name ?? '';
|
||||
}
|
||||
|
||||
|
||||
|
||||
nlog($entity);
|
||||
|
||||
return $entity;
|
||||
}
|
||||
}
|
||||
|
@ -112,10 +112,21 @@ class PaymentExport extends BaseExport
|
||||
foreach (array_values($this->input['report_keys']) as $key) {
|
||||
$keyval = array_search($key, $this->entity_keys);
|
||||
|
||||
if(!$keyval) {
|
||||
$keyval = array_search(str_replace("payment.", "", $key), $this->entity_keys) ?? $key;
|
||||
}
|
||||
|
||||
if(!$keyval) {
|
||||
$keyval = $key;
|
||||
}
|
||||
|
||||
if (array_key_exists($key, $transformed_entity)) {
|
||||
$entity[$keyval] = $transformed_entity[$key];
|
||||
} else {
|
||||
$entity[$keyval] = '';
|
||||
} elseif (array_key_exists($keyval, $transformed_entity)) {
|
||||
$entity[$keyval] = $transformed_entity[$keyval];
|
||||
}
|
||||
else {
|
||||
$entity[$keyval] = $this->resolveKey($keyval, $payment, $this->entity_transformer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -140,6 +151,10 @@ class PaymentExport extends BaseExport
|
||||
$entity['currency'] = $payment->currency()->exists() ? $payment->currency->code : '';
|
||||
}
|
||||
|
||||
if (in_array('payment.currency', $this->input['report_keys'])) {
|
||||
$entity['payment.currency'] = $payment->currency()->exists() ? $payment->currency->code : '';
|
||||
}
|
||||
|
||||
if (in_array('exchange_currency_id', $this->input['report_keys'])) {
|
||||
$entity['exchange_currency'] = $payment->exchange_currency()->exists() ? $payment->exchange_currency->code : '';
|
||||
}
|
||||
@ -152,11 +167,19 @@ class PaymentExport extends BaseExport
|
||||
$entity['type'] = $payment->translatedType();
|
||||
}
|
||||
|
||||
if (in_array('payment.method', $this->input['report_keys'])) {
|
||||
$entity['payment.method'] = $payment->translatedType();
|
||||
}
|
||||
|
||||
if (in_array('payment.status', $this->input['report_keys'])) {
|
||||
$entity['payment.status'] = $payment->stringStatus($payment->status_id);
|
||||
}
|
||||
|
||||
if (in_array('gateway_type_id', $this->input['report_keys'])) {
|
||||
$entity['gateway'] = $payment->gateway_type ? $payment->gateway_type->name : 'Unknown Type';
|
||||
}
|
||||
|
||||
$entity['invoices'] = $payment->invoices()->exists() ? $payment->invoices->pluck('number')->implode(',') : '';
|
||||
// $entity['invoices'] = $payment->invoices()->exists() ? $payment->invoices->pluck('number')->implode(',') : '';
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user