From c8419c14d1a1ae7f2c416a3814410939ca01e506 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 15 Jan 2017 20:38:36 +0200 Subject: [PATCH] Improvements to CSV import/export --- app/Http/Controllers/ExportController.php | 16 +++++++++++++++- app/Models/Invoice.php | 11 +++++++++-- resources/lang/en/texts.php | 1 + resources/views/export/invoices.blade.php | 6 +++--- 4 files changed, 28 insertions(+), 6 deletions(-) diff --git a/app/Http/Controllers/ExportController.php b/app/Http/Controllers/ExportController.php index f1e74bd2a924..ed0d1480e12e 100644 --- a/app/Http/Controllers/ExportController.php +++ b/app/Http/Controllers/ExportController.php @@ -32,7 +32,21 @@ class ExportController extends BaseController { $format = $request->input('format'); $date = date('Y-m-d'); - $fileName = "invoice-ninja-{$date}"; + + // set the filename based on the entity types selected + if ($request->include == 'all') { + $fileName = "invoice-ninja-{$date}"; + } else { + $fields = $request->all(); + $fields = array_filter(array_map(function ($key) { + if ( ! in_array($key, ['format', 'include', '_token'])) { + return $key; + } else { + return null; + } + }, array_keys($fields), $fields)); + $fileName = "invoice-ninja-" . join('-', $fields) . "-{$date}"; + } if ($format === 'JSON') { return $this->returnJSON($request, $fileName); diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 1e125117b769..16929178c816 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -77,6 +77,10 @@ class Invoice extends EntityModel implements BalanceAffecting * @var string */ public static $fieldInvoiceNumber = 'invoice_number'; + /** + * @var string + */ + public static $fieldPONumber = 'po_number'; /** * @var string */ @@ -110,6 +114,7 @@ class Invoice extends EntityModel implements BalanceAffecting return [ Client::$fieldName, Invoice::$fieldInvoiceNumber, + Invoice::$fieldPONumber, Invoice::$fieldInvoiceDate, Invoice::$fieldDueDate, Invoice::$fieldAmount, @@ -127,9 +132,11 @@ class Invoice extends EntityModel implements BalanceAffecting return [ 'number^po' => 'invoice_number', 'amount' => 'amount', - 'organization' => 'name', + 'client|organization' => 'name', 'paid^date' => 'paid', - 'invoice_date|create_date' => 'invoice_date', + 'invoice date|create date' => 'invoice_date', + 'po number' => 'po_number', + 'due date' => 'due_date', 'terms' => 'terms', 'notes' => 'notes', ]; diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index ed7013b2b25a..f49705cfb42a 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2317,6 +2317,7 @@ $LANG = array( 'domain_help' => 'Used in the client portal and when sending emails.', 'domain_help_website' => 'Used when sending emails.', 'preview' => 'Preview', + 'import_invoices' => 'Import Invoices', ); diff --git a/resources/views/export/invoices.blade.php b/resources/views/export/invoices.blade.php index 6aa9fd65169e..9f5dc26b21a6 100644 --- a/resources/views/export/invoices.blade.php +++ b/resources/views/export/invoices.blade.php @@ -5,8 +5,8 @@ {{ trans('texts.user') }} @endif {{ trans(isset($entityType) && $entityType == ENTITY_QUOTE ? 'texts.quote_number' : 'texts.invoice_number') }} - {{ trans('texts.balance') }} {{ trans('texts.amount') }} + {{ trans('texts.paid') }} {{ trans('texts.po_number') }} {{ trans('texts.status') }} {{ trans(isset($entityType) && $entityType == ENTITY_QUOTE ? 'texts.quote_date' : 'texts.invoice_date') }} @@ -34,8 +34,8 @@ {{ $invoice->present()->user }} @endif {{ $invoice->invoice_number }} - {{ $account->formatMoney($invoice->balance, $invoice->client) }} {{ $account->formatMoney($invoice->amount, $invoice->client) }} + {{ $account->formatMoney($invoice->amount - $invoice->balance, $invoice->client) }} {{ $invoice->po_number }} {{ $invoice->present()->status }} {{ $invoice->present()->invoice_date }} @@ -56,4 +56,4 @@ @endif @endforeach - \ No newline at end of file +