mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-07-09 03:14:30 -04:00
Working on exports
This commit is contained in:
parent
e8c79ded30
commit
68ff1a6c86
@ -81,7 +81,6 @@ class BaseExport
|
||||
"amount" => "invoice.amount",
|
||||
"balance" => "invoice.balance",
|
||||
"paid_to_date" => "invoice.paid_to_date",
|
||||
"discount" => "item.discount",
|
||||
"po_number" => "invoice.po_number",
|
||||
"date" => "invoice.date",
|
||||
"due_date" => "invoice.due_date",
|
||||
@ -94,16 +93,17 @@ class BaseExport
|
||||
"is_amount_discount" => "invoice.is_amount_discount",
|
||||
"partial" => "invoice.partial",
|
||||
"partial_due_date" => "invoice.partial_due_date",
|
||||
"custom_value1" => "item.custom_value1",
|
||||
"custom_value2" => "item.custom_value2",
|
||||
"custom_value3" => "item.custom_value3",
|
||||
"custom_value4" => "item.custom_value4",
|
||||
"surcharge1" => "invoice.custom_surcharge1",
|
||||
"surcharge2" => "invoice.custom_surcharge2",
|
||||
"surcharge3" => "invoice.custom_surcharge3",
|
||||
"surcharge4" => "invoice.custom_surcharge4",
|
||||
"exchange_rate" => "invoice.exchange_rate",
|
||||
"tax_amount" => "invoice.total_taxes",
|
||||
"assigned_user" => "invoice.assigned_user_id",
|
||||
"user" => "invoice.user_id",
|
||||
];
|
||||
|
||||
protected array $item_report_keys = [
|
||||
"quantity" => "item.quantity",
|
||||
"cost" => "item.cost",
|
||||
"product_key" => "item.product_key",
|
||||
@ -114,10 +114,13 @@ class BaseExport
|
||||
"item_tax_rate2" => "item.tax_rate2",
|
||||
"item_tax3" => "item.tax_name3",
|
||||
"item_tax_rate3" => "item.tax_rate3",
|
||||
"custom_value1" => "item.custom_value1",
|
||||
"custom_value2" => "item.custom_value2",
|
||||
"custom_value3" => "item.custom_value3",
|
||||
"custom_value4" => "item.custom_value4",
|
||||
"discount" => "item.discount",
|
||||
"type" => "item.type_id",
|
||||
"tax_category" => "item.tax_id",
|
||||
"assigned_user" => "invoice.assigned_user_id",
|
||||
"user" => "invoice.user_id",
|
||||
];
|
||||
|
||||
protected array $quote_report_keys = [
|
||||
@ -125,7 +128,6 @@ class BaseExport
|
||||
"amount" => "quote.amount",
|
||||
"balance" => "quote.balance",
|
||||
"paid_to_date" => "quote.paid_to_date",
|
||||
"discount" => "item.discount",
|
||||
"po_number" => "quote.po_number",
|
||||
"date" => "quote.date",
|
||||
"due_date" => "quote.due_date",
|
||||
@ -138,28 +140,12 @@ class BaseExport
|
||||
"is_amount_discount" => "quote.is_amount_discount",
|
||||
"partial" => "quote.partial",
|
||||
"partial_due_date" => "quote.partial_due_date",
|
||||
"custom_value1" => "item.custom_value1",
|
||||
"custom_value2" => "item.custom_value2",
|
||||
"custom_value3" => "item.custom_value3",
|
||||
"custom_value4" => "item.custom_value4",
|
||||
"surcharge1" => "quote.custom_surcharge1",
|
||||
"surcharge2" => "quote.custom_surcharge2",
|
||||
"surcharge3" => "quote.custom_surcharge3",
|
||||
"surcharge4" => "quote.custom_surcharge4",
|
||||
"exchange_rate" => "quote.exchange_rate",
|
||||
"tax_amount" => "quote.total_taxes",
|
||||
"quantity" => "item.quantity",
|
||||
"cost" => "item.cost",
|
||||
"product_key" => "item.product_key",
|
||||
"notes" => "item.notes",
|
||||
"item_tax1" => "item.tax_name1",
|
||||
"item_tax_rate1" => "item.tax_rate1",
|
||||
"item_tax2" => "item.tax_name2",
|
||||
"item_tax_rate2" => "item.tax_rate2",
|
||||
"item_tax3" => "item.tax_name3",
|
||||
"item_tax_rate3" => "item.tax_rate3",
|
||||
"type" => "item.type_id",
|
||||
"tax_category" => "item.tax_id",
|
||||
"assigned_user" => "quote.assigned_user_id",
|
||||
"user" => "quote.user_id",
|
||||
];
|
||||
@ -169,7 +155,6 @@ class BaseExport
|
||||
"amount" => "credit.amount",
|
||||
"balance" => "credit.balance",
|
||||
"paid_to_date" => "credit.paid_to_date",
|
||||
"discount" => "item.discount",
|
||||
"po_number" => "credit.po_number",
|
||||
"date" => "credit.date",
|
||||
"due_date" => "credit.due_date",
|
||||
@ -182,28 +167,12 @@ class BaseExport
|
||||
"is_amount_discount" => "credit.is_amount_discount",
|
||||
"partial" => "credit.partial",
|
||||
"partial_due_date" => "credit.partial_due_date",
|
||||
"custom_value1" => "item.custom_value1",
|
||||
"custom_value2" => "item.custom_value2",
|
||||
"custom_value3" => "item.custom_value3",
|
||||
"custom_value4" => "item.custom_value4",
|
||||
"surcharge1" => "credit.custom_surcharge1",
|
||||
"surcharge2" => "credit.custom_surcharge2",
|
||||
"surcharge3" => "credit.custom_surcharge3",
|
||||
"surcharge4" => "credit.custom_surcharge4",
|
||||
"exchange_rate" => "credit.exchange_rate",
|
||||
"tax_amount" => "credit.total_taxes",
|
||||
"quantity" => "item.quantity",
|
||||
"cost" => "item.cost",
|
||||
"product_key" => "item.product_key",
|
||||
"notes" => "item.notes",
|
||||
"item_tax1" => "item.tax_name1",
|
||||
"item_tax_rate1" => "item.tax_rate1",
|
||||
"item_tax2" => "item.tax_name2",
|
||||
"item_tax_rate2" => "item.tax_rate2",
|
||||
"item_tax3" => "item.tax_name3",
|
||||
"item_tax_rate3" => "item.tax_rate3",
|
||||
"type" => "item.type_id",
|
||||
"tax_category" => "item.tax_id",
|
||||
"assigned_user" => "credit.assigned_user_id",
|
||||
"user" => "credit.user_id",
|
||||
];
|
||||
@ -315,13 +284,22 @@ class BaseExport
|
||||
|
||||
private function resolveInvoiceKey($column, $entity, $transformer)
|
||||
{
|
||||
if($transformer instanceof PaymentTransformer)
|
||||
nlog("searching for {$column}");
|
||||
|
||||
if($transformer instanceof PaymentTransformer) {
|
||||
$transformed_invoices = $transformer->includeInvoices($entity);
|
||||
|
||||
$manager = new Manager();
|
||||
$manager->setSerializer(new ArraySerializer());
|
||||
$transformed_invoices = $manager->createData($transformed_invoices)->toArray();
|
||||
$manager = new Manager();
|
||||
$manager->setSerializer(new ArraySerializer());
|
||||
$transformed_invoices = $manager->createData($transformed_invoices)->toArray();
|
||||
}
|
||||
|
||||
$transformed_invoice = $transformer->transform($entity);
|
||||
|
||||
if($column == 'status')
|
||||
return $entity->stringStatus($entity->status_id);
|
||||
|
||||
return '';
|
||||
}
|
||||
|
||||
private function resolvePaymentKey($column, $entity, $transformer)
|
||||
@ -505,8 +483,6 @@ class BaseExport
|
||||
|
||||
foreach (array_merge($this->input['report_keys'], $this->forced_keys) as $value) {
|
||||
|
||||
$prefix = '';
|
||||
|
||||
$key = array_search($value, $this->entity_keys);
|
||||
|
||||
if(!$key) {
|
||||
@ -519,6 +495,12 @@ class BaseExport
|
||||
$key = array_search($value, $this->invoice_report_keys);
|
||||
}
|
||||
|
||||
if(!$key) {
|
||||
$prefix = ctrans('texts.payment');
|
||||
$key = array_search($value, $this->payment_report_keys);
|
||||
}
|
||||
|
||||
|
||||
if(!$key) {
|
||||
$prefix = ctrans('texts.quote');
|
||||
$key = array_search($value, $this->quote_report_keys);
|
||||
@ -530,8 +512,12 @@ class BaseExport
|
||||
}
|
||||
|
||||
if(!$key) {
|
||||
$prefix = ctrans('texts.payment');
|
||||
$key = array_search($value, $this->payment_report_keys);
|
||||
$prefix = ctrans('texts.item');
|
||||
$key = array_search($value, $this->item_report_keys);
|
||||
}
|
||||
|
||||
if(!$key) {
|
||||
$prefix = '';
|
||||
}
|
||||
|
||||
$key = str_replace('item.', '', $key);
|
||||
|
@ -143,9 +143,9 @@ class ClientExport extends BaseExport
|
||||
|
||||
$keyval = array_search($key, $this->entity_keys);
|
||||
|
||||
if ($parts[0] == 'client' && array_key_exists($parts[1], $transformed_client)) {
|
||||
if (is_array($parts) && $parts[0] == 'client' && array_key_exists($parts[1], $transformed_client)) {
|
||||
$entity[$keyval] = $transformed_client[$parts[1]];
|
||||
} elseif ($parts[0] == 'contact' && array_key_exists($parts[1], $transformed_contact)) {
|
||||
} elseif (is_array($parts) && $parts[0] == 'contact' && array_key_exists($parts[1], $transformed_contact)) {
|
||||
$entity[$keyval] = $transformed_contact[$parts[1]];
|
||||
} else {
|
||||
$entity[$keyval] = '';
|
||||
|
@ -135,10 +135,21 @@ class InvoiceExport 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("invoice.", "", $key), $this->entity_keys) ?? $key;
|
||||
}
|
||||
|
||||
if(!$keyval) {
|
||||
$keyval = $key;
|
||||
}
|
||||
|
||||
if (array_key_exists($key, $transformed_invoice)) {
|
||||
$entity[$keyval] = $transformed_invoice[$key];
|
||||
} else {
|
||||
$entity[$keyval] = '';
|
||||
} elseif (array_key_exists($keyval, $transformed_invoice)) {
|
||||
$entity[$keyval] = $transformed_invoice[$keyval];
|
||||
}
|
||||
else {
|
||||
$entity[$keyval] = $this->resolveKey($keyval, $invoice, $this->invoice_transformer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -163,15 +174,15 @@ class InvoiceExport extends BaseExport
|
||||
$entity['status'] = $invoice->stringStatus($invoice->status_id);
|
||||
}
|
||||
|
||||
$payment_exists = $invoice->payments()->exists();
|
||||
// $payment_exists = $invoice->payments()->exists();
|
||||
|
||||
$entity['payment_number'] = $payment_exists ? $invoice->payments()->pluck('number')->implode(',') : '';
|
||||
// $entity['payment_number'] = $payment_exists ? $invoice->payments()->pluck('number')->implode(',') : '';
|
||||
|
||||
$entity['payment_date'] = $payment_exists ? $invoice->payments()->pluck('date')->implode(',') : '';
|
||||
// $entity['payment_date'] = $payment_exists ? $invoice->payments()->pluck('date')->implode(',') : '';
|
||||
|
||||
$entity['payment_amount'] = $payment_exists ? Number::formatMoney($invoice->payments()->sum('paymentables.amount'), $invoice->company) : ctrans('texts.unpaid');
|
||||
// $entity['payment_amount'] = $payment_exists ? Number::formatMoney($invoice->payments()->sum('paymentables.amount'), $invoice->company) : ctrans('texts.unpaid');
|
||||
|
||||
$entity['method'] = $payment_exists ? $invoice->payments()->first()->translatedType() : "";
|
||||
// $entity['method'] = $payment_exists ? $invoice->payments()->first()->translatedType() : "";
|
||||
|
||||
return $entity;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user