Working on CSV import/export

This commit is contained in:
Hillel Coren 2017-08-23 15:26:03 +03:00
parent 81ec506f00
commit 6651805349
5 changed files with 62 additions and 22 deletions

View File

@ -109,14 +109,14 @@ class Invoice extends EntityModel implements BalanceAffecting
'po_number', 'po_number',
'invoice_date', 'invoice_date',
'due_date', 'due_date',
'amount',
'paid', 'paid',
'notes',
'terms', 'terms',
'product', 'item_product',
'quantity', 'item_notes',
'tax1', 'item_quantity',
'tax2', 'item_cost',
'item_tax1',
'item_tax2',
]; ];
} }
@ -127,17 +127,17 @@ class Invoice extends EntityModel implements BalanceAffecting
{ {
return [ return [
'number^po' => 'invoice_number', 'number^po' => 'invoice_number',
'amount' => 'amount',
'client|organization' => 'name', 'client|organization' => 'name',
'paid^date' => 'paid', 'paid^date' => 'paid',
'invoice date|create date' => 'invoice_date', 'invoice date|create date' => 'invoice_date',
'po number' => 'po_number', 'po number' => 'po_number',
'due date' => 'due_date', 'due date' => 'due_date',
'terms' => 'terms', 'terms' => 'terms',
'notes' => 'notes', 'product|item' => 'item_product',
'product|item' => 'product', 'notes' => 'item_notes',
'quantity|qty' => 'quantity', 'quantity|qty' => 'item_quantity',
'tax' => 'tax1', 'amount|cost' => 'item_cost',
'tax' => 'item_tax1',
]; ];
} }

View File

@ -37,14 +37,14 @@ class InvoiceTransformer extends BaseTransformer
'due_date_sql' => $this->getDate($data, 'due_date'), 'due_date_sql' => $this->getDate($data, 'due_date'),
'invoice_items' => [ 'invoice_items' => [
[ [
'product_key' => $this->getString($data, 'product'), 'product_key' => $this->getString($data, 'item_product'),
'notes' => $this->getString($data, 'notes') ?: $this->getProduct($data, 'product', 'notes', ''), 'notes' => $this->getString($data, 'item_notes') ?: $this->getProduct($data, 'item_product', 'notes', ''),
'cost' => $this->getFloat($data, 'amount') ?: $this->getProduct($data, 'product', 'cost', 0), 'cost' => $this->getFloat($data, 'item_notes') ?: $this->getProduct($data, 'item_product', 'cost', 0),
'qty' => $this->getFloat($data, 'quantity') ?: 1, 'qty' => $this->getFloat($data, 'item_quantity') ?: 1,
'tax_name1' => $this->getTaxName($this->getString($data, 'tax1')), 'tax_name1' => $this->getTaxName($this->getString($data, 'item_tax1')),
'tax_rate1' => $this->getTaxRate($this->getString($data, 'tax1')), 'tax_rate1' => $this->getTaxRate($this->getString($data, 'item_tax1')),
'tax_name2' => $this->getTaxName($this->getString($data, 'tax2')), 'tax_name2' => $this->getTaxName($this->getString($data, 'item_tax2')),
'tax_rate2' => $this->getTaxRate($this->getString($data, 'tax2')), 'tax_rate2' => $this->getTaxRate($this->getString($data, 'item_tax2')),
], ],
], ],
]; ];

View File

@ -632,8 +632,6 @@ class ImportService
private function getCsvData($fileName) private function getCsvData($fileName)
{ {
require_once app_path().'/Includes/parsecsv.lib.php';
$this->checkForFile($fileName); $this->checkForFile($fileName);
$data = array_map('str_getcsv', file($fileName)); $data = array_map('str_getcsv', file($fileName));

View File

@ -2405,6 +2405,13 @@ $LANG = array(
'currency' => 'Currency', 'currency' => 'Currency',
'ofx_help' => 'In most cases the default values should work, if you\'re unable to connect it may help to adjust the settings.', 'ofx_help' => 'In most cases the default values should work, if you\'re unable to connect it may help to adjust the settings.',
'item_product' => 'Item Product',
'item_notes' => 'Item Notes',
'item_cost' => 'Item Cost',
'item_quantity' => 'Item Quantity',
'item_tax_rate' => 'Item Tax Rate',
'item_tax_name' => 'Item Tax Name',
); );
return $LANG; return $LANG;

View File

@ -25,7 +25,24 @@
@if ($account->custom_invoice_text_label2) @if ($account->custom_invoice_text_label2)
<td>{{ $account->custom_invoice_text_label2 }}</td> <td>{{ $account->custom_invoice_text_label2 }}</td>
@endif @endif
<td>{{ trans('texts.product') }}</td> <td>{{ trans('texts.item_product') }}</td>
<td>{{ trans('texts.item_notes') }}</td>
@if ($account->custom_invoice_item_label1)
<td>{{ $account->custom_invoice_item_label1 }}</td>
@endif
@if ($account->custom_invoice_item_label2)
<td>{{ $account->custom_invoice_item_label2 }}</td>
@endif
<td>{{ trans('texts.item_cost') }}</td>
<td>{{ trans('texts.item_quantity') }}</td>
@if ($account->invoice_item_taxes)
<td>{{ trans('texts.item_tax_name') }}</td>
<td>{{ trans('texts.item_tax_rate') }}</td>
@if ($account->enable_second_tax_rate)
<td>{{ trans('texts.item_tax_name') }}</td>
<td>{{ trans('texts.item_tax_rate') }}</td>
@endif
@endif
</tr> </tr>
@foreach ($invoices as $invoice) @foreach ($invoices as $invoice)
@ -58,6 +75,24 @@
@if ($account->custom_invoice_label2) @if ($account->custom_invoice_label2)
<td>{{ $invoice->custom_text_value2 }}</td> <td>{{ $invoice->custom_text_value2 }}</td>
@endif @endif
<td>{{ $item->product_key }}</td>
<td>{{ $item->notes }}</td>
@if ($account->custom_invoice_item_label1)
<td>{{ $item->custom_value1 }}</td>
@endif
@if ($account->custom_invoice_item_label2)
<td>{{ $item->custom_value2 }}</td>
@endif
<td>{{ $item->cost }}</td>
<td>{{ $item->qty }}</td>
@if ($account->invoice_item_taxes)
<td>{{ $item->tax_name1 }}</td>
<td>{{ $item->tax_rate1 }}</td>
@if ($account->enable_second_tax_rate)
<td>{{ $item->tax_name2 }}</td>
<td>{{ $item->tax_rate2 }}</td>
@endif
@endif
</tr> </tr>
@endforeach @endforeach
@endif @endif