From 01b721f4f0b74cda7b007b80447921cf6bf23fba Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 23 Aug 2017 17:05:14 +0300 Subject: [PATCH] Working on CSV import/export --- app/Ninja/Import/BaseTransformer.php | 2 +- app/Ninja/Import/CSV/InvoiceTransformer.php | 8 +- .../views/export/recurring_invoices.blade.php | 86 +++++++++++++------ 3 files changed, 67 insertions(+), 29 deletions(-) diff --git a/app/Ninja/Import/BaseTransformer.php b/app/Ninja/Import/BaseTransformer.php index f83112c6a7ce..240a36f137a8 100644 --- a/app/Ninja/Import/BaseTransformer.php +++ b/app/Ninja/Import/BaseTransformer.php @@ -215,7 +215,7 @@ class BaseTransformer extends TransformerAbstract */ public function getInvoiceNumber($number) { - return str_pad(trim($number), 4, '0', STR_PAD_LEFT); + return $number ? str_pad(trim($number), 4, '0', STR_PAD_LEFT) : null; } /** diff --git a/app/Ninja/Import/CSV/InvoiceTransformer.php b/app/Ninja/Import/CSV/InvoiceTransformer.php index da9f2d87a652..e09760c44358 100644 --- a/app/Ninja/Import/CSV/InvoiceTransformer.php +++ b/app/Ninja/Import/CSV/InvoiceTransformer.php @@ -41,10 +41,10 @@ class InvoiceTransformer extends BaseTransformer 'notes' => $this->getString($data, 'item_notes') ?: $this->getProduct($data, 'item_product', 'notes', ''), 'cost' => $this->getFloat($data, 'item_notes') ?: $this->getProduct($data, 'item_product', 'cost', 0), 'qty' => $this->getFloat($data, 'item_quantity') ?: 1, - 'tax_name1' => $this->getTaxName($this->getString($data, 'item_tax1')), - 'tax_rate1' => $this->getTaxRate($this->getString($data, 'item_tax1')), - 'tax_name2' => $this->getTaxName($this->getString($data, 'item_tax2')), - 'tax_rate2' => $this->getTaxRate($this->getString($data, 'item_tax2')), + 'tax_name1' => $this->getTaxName($this->getString($data, 'item_tax1')) ?: $this->getProduct($data, 'item_product', 'tax_name1', ''), + 'tax_rate1' => $this->getTaxRate($this->getString($data, 'item_tax1')) ?: $this->getProduct($data, 'item_product', 'tax_rate1', 0), + 'tax_name2' => $this->getTaxName($this->getString($data, 'item_tax2')) ?: $this->getProduct($data, 'item_product', 'tax_name2', ''), + 'tax_rate2' => $this->getTaxRate($this->getString($data, 'item_tax2')) ?: $this->getProduct($data, 'item_product', 'tax_rate2', 0), ], ], ]; diff --git a/resources/views/export/recurring_invoices.blade.php b/resources/views/export/recurring_invoices.blade.php index 8a57dc1c4a20..7e3fe07efb6a 100644 --- a/resources/views/export/recurring_invoices.blade.php +++ b/resources/views/export/recurring_invoices.blade.php @@ -21,33 +21,71 @@ @if ($account->custom_invoice_text_label2) {{ $account->custom_invoice_text_label2 }} @endif + {{ trans('texts.item_product') }} + {{ trans('texts.item_notes') }} + @if ($account->custom_invoice_item_label1) + {{ $account->custom_invoice_item_label1 }} + @endif + @if ($account->custom_invoice_item_label2) + {{ $account->custom_invoice_item_label2 }} + @endif + {{ trans('texts.item_cost') }} + {{ trans('texts.item_quantity') }} + @if ($account->invoice_item_taxes) + {{ trans('texts.item_tax_name') }} + {{ trans('texts.item_tax_rate') }} + @if ($account->enable_second_tax_rate) + {{ trans('texts.item_tax_name') }} + {{ trans('texts.item_tax_rate') }} + @endif + @endif @foreach ($recurringInvoices as $invoice) @if (!$invoice->client->is_deleted) - - {{ $invoice->present()->client }} - {{ $invoice->present()->email }} - @if ($multiUser) - {{ $invoice->present()->user }} - @endif - {{ $invoice->present()->frequency }} - {{ $account->formatMoney($invoice->balance, $invoice->client) }} - {{ $account->formatMoney($invoice->amount, $invoice->client) }} - {{ $invoice->po_number }} - {{ $invoice->present()->status }} - @if ($account->custom_invoice_label1) - {{ $invoice->custom_value1 }} - @endif - @if ($account->custom_invoice_label2) - {{ $invoice->custom_value2 }} - @endif - @if ($account->custom_invoice_label1) - {{ $invoice->custom_text_value1 }} - @endif - @if ($account->custom_invoice_label2) - {{ $invoice->custom_text_value2 }} - @endif - + @foreach ($invoice->invoice_items as $item) + + {{ $invoice->present()->client }} + {{ $invoice->present()->email }} + @if ($multiUser) + {{ $invoice->present()->user }} + @endif + {{ $invoice->present()->frequency }} + {{ $account->formatMoney($invoice->balance, $invoice->client) }} + {{ $account->formatMoney($invoice->amount, $invoice->client) }} + {{ $invoice->po_number }} + {{ $invoice->present()->status }} + @if ($account->custom_invoice_label1) + {{ $invoice->custom_value1 }} + @endif + @if ($account->custom_invoice_label2) + {{ $invoice->custom_value2 }} + @endif + @if ($account->custom_invoice_label1) + {{ $invoice->custom_text_value1 }} + @endif + @if ($account->custom_invoice_label2) + {{ $invoice->custom_text_value2 }} + @endif + {{ $item->product_key }} + {{ $item->notes }} + @if ($account->custom_invoice_item_label1) + {{ $item->custom_value1 }} + @endif + @if ($account->custom_invoice_item_label2) + {{ $item->custom_value2 }} + @endif + {{ $item->cost }} + {{ $item->qty }} + @if ($account->invoice_item_taxes) + {{ $item->tax_name1 }} + {{ $item->tax_rate1 }} + @if ($account->enable_second_tax_rate) + {{ $item->tax_name2 }} + {{ $item->tax_rate2 }} + @endif + @endif + + @endforeach @endif @endforeach