From abaf8d97b93d9d4c5c42b79c9f7c3ff45f19f132 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Thu, 13 Apr 2017 10:25:49 +0300 Subject: [PATCH] Imporvement to CSV import --- app/Models/Invoice.php | 55 +++++--------------- app/Ninja/Import/CSV/InvoiceTransformer.php | 4 +- app/Ninja/Repositories/PaymentRepository.php | 2 +- 3 files changed, 16 insertions(+), 45 deletions(-) diff --git a/app/Models/Invoice.php b/app/Models/Invoice.php index 570d14e28d35..9549cb32cf36 100644 --- a/app/Models/Invoice.php +++ b/app/Models/Invoice.php @@ -93,54 +93,23 @@ class Invoice extends EntityModel implements BalanceAffecting INVOICE_STATUS_PAID => 'success', ]; - /** - * @var string - */ - public static $fieldInvoiceNumber = 'invoice_number'; - /** - * @var string - */ - public static $fieldPONumber = 'po_number'; - /** - * @var string - */ - public static $fieldInvoiceDate = 'invoice_date'; - /** - * @var string - */ - public static $fieldDueDate = 'due_date'; - /** - * @var string - */ - public static $fieldAmount = 'amount'; - /** - * @var string - */ - public static $fieldPaid = 'paid'; - /** - * @var string - */ - public static $fieldNotes = 'notes'; - /** - * @var string - */ - public static $fieldTerms = 'terms'; - /** * @return array */ public static function getImportColumns() { return [ - Client::$fieldName, - self::$fieldInvoiceNumber, - self::$fieldPONumber, - self::$fieldInvoiceDate, - self::$fieldDueDate, - self::$fieldAmount, - self::$fieldPaid, - self::$fieldNotes, - self::$fieldTerms, + 'name', + 'invoice_number', + 'po_number', + 'invoice_date', + 'due_date', + 'amount', + 'paid', + 'notes', + 'terms', + 'product', + 'quantity', ]; } @@ -159,6 +128,8 @@ class Invoice extends EntityModel implements BalanceAffecting 'due date' => 'due_date', 'terms' => 'terms', 'notes' => 'notes', + 'product|item' => 'product', + 'quantity|qty' => 'quantity', ]; } diff --git a/app/Ninja/Import/CSV/InvoiceTransformer.php b/app/Ninja/Import/CSV/InvoiceTransformer.php index 5cec4b6cc7e1..146f7a5846a6 100644 --- a/app/Ninja/Import/CSV/InvoiceTransformer.php +++ b/app/Ninja/Import/CSV/InvoiceTransformer.php @@ -37,10 +37,10 @@ class InvoiceTransformer extends BaseTransformer 'due_date_sql' => $this->getDate($data, 'due_date'), 'invoice_items' => [ [ - 'product_key' => '', + 'product_key' => $this->getString($data, 'product'), 'notes' => $this->getString($data, 'notes'), 'cost' => $this->getFloat($data, 'amount'), - 'qty' => 1, + 'qty' => $this->getFloat($data, 'quantity') ?: 1, ], ], ]; diff --git a/app/Ninja/Repositories/PaymentRepository.php b/app/Ninja/Repositories/PaymentRepository.php index 6d472485a07a..4d6683744a5a 100644 --- a/app/Ninja/Repositories/PaymentRepository.php +++ b/app/Ninja/Repositories/PaymentRepository.php @@ -163,7 +163,7 @@ class PaymentRepository extends BaseRepository } else { $payment = Payment::createNew(); - if (Auth::check()) { + if (Auth::check() && Auth::user()->account->payment_type_id) { $payment->payment_type_id = Auth::user()->account->payment_type_id; } }