From ab99ef073963834ee1ebbd14a6930ea74bb6071f Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Fri, 30 Mar 2018 14:33:28 +0300 Subject: [PATCH] Support importing vendors --- app/Models/Vendor.php | 19 ++++++++++--------- app/Ninja/Import/BaseTransformer.php | 13 +++++++++++++ app/Ninja/Import/CSV/VendorTransformer.php | 10 +++++----- app/Services/ImportService.php | 1 + resources/lang/en/texts.php | 4 ++++ .../views/export/vendor_contacts.blade.php | 2 +- 6 files changed, 34 insertions(+), 15 deletions(-) diff --git a/app/Models/Vendor.php b/app/Models/Vendor.php index afc48afbc21f..8ed404cd7201 100644 --- a/app/Models/Vendor.php +++ b/app/Models/Vendor.php @@ -98,10 +98,10 @@ class Vendor extends EntityModel self::$fieldPostalCode, self::$fieldCountry, self::$fieldNotes, - VendorContact::$fieldFirstName, - VendorContact::$fieldLastName, - VendorContact::$fieldPhone, - VendorContact::$fieldEmail, + 'contact_first_name', + 'contact_last_name', + 'contact_email', + 'contact_phone', ]; } @@ -111,11 +111,12 @@ class Vendor extends EntityModel public static function getImportMap() { return [ - 'first' => 'first_name', - 'last' => 'last_name', - 'email' => 'email', - 'mobile|phone' => 'phone', - 'name|organization' => 'name', + 'first' => 'contact_first_name', + 'last' => 'contact_last_name', + 'email' => 'contact_email', + 'mobile|phone' => 'contact_phone', + 'work|office' => 'work_phone', + 'name|organization|vendor' => 'name', 'street2|address2' => 'address2', 'street|address|address1' => 'address1', 'city' => 'city', diff --git a/app/Ninja/Import/BaseTransformer.php b/app/Ninja/Import/BaseTransformer.php index 8018685a585b..68333bb4532c 100644 --- a/app/Ninja/Import/BaseTransformer.php +++ b/app/Ninja/Import/BaseTransformer.php @@ -39,6 +39,19 @@ class BaseTransformer extends TransformerAbstract return isset($this->maps[ENTITY_CLIENT][$name]); } + /** + * @param $name + * + * @return bool + */ + public function hasVendor($name) + { + $name = trim(strtolower($name)); + + return isset($this->maps[ENTITY_VENDOR][$name]); + } + + /** * @param $key * diff --git a/app/Ninja/Import/CSV/VendorTransformer.php b/app/Ninja/Import/CSV/VendorTransformer.php index 58270b49d8df..62e83944442d 100644 --- a/app/Ninja/Import/CSV/VendorTransformer.php +++ b/app/Ninja/Import/CSV/VendorTransformer.php @@ -31,12 +31,12 @@ class VendorTransformer extends BaseTransformer 'state' => $this->getString($data, 'state'), 'postal_code' => $this->getString($data, 'postal_code'), 'private_notes' => $this->getString($data, 'notes'), - 'contacts' => [ + 'vendor_contacts' => [ [ - 'first_name' => $this->getString($data, 'first_name'), - 'last_name' => $this->getString($data, 'last_name'), - 'email' => $this->getString($data, 'email'), - 'phone' => $this->getString($data, 'phone'), + 'first_name' => $this->getString($data, 'contact_first_name'), + 'last_name' => $this->getString($data, 'contact_last_name'), + 'email' => $this->getString($data, 'contact_email'), + 'phone' => $this->getString($data, 'contact_phone'), ], ], 'country_id' => isset($data->country) ? $this->getCountryId($data->country) : null, diff --git a/app/Services/ImportService.php b/app/Services/ImportService.php index 6b6ae78dbe24..24869f3707de 100644 --- a/app/Services/ImportService.php +++ b/app/Services/ImportService.php @@ -97,6 +97,7 @@ class ImportService ENTITY_PAYMENT, ENTITY_TASK, ENTITY_PRODUCT, + ENTITY_VENDOR, ENTITY_EXPENSE, ENTITY_CUSTOMER, ]; diff --git a/resources/lang/en/texts.php b/resources/lang/en/texts.php index 255a79f94df3..b85b7f56544a 100644 --- a/resources/lang/en/texts.php +++ b/resources/lang/en/texts.php @@ -2799,6 +2799,10 @@ $LANG = array( 'view_in_portal' => 'View in Portal', 'cookie_message' => 'This website uses cookies to ensure you get the best experience on our website.', 'got_it' => 'Got it!', + 'vendor_will_create' => 'vendor will be created', + 'vendors_will_create' => 'vendors will be created', + 'created_vendors' => 'Successfully created :count vendor(s)', + 'import_vendors' => 'Import Vendors', ); diff --git a/resources/views/export/vendor_contacts.blade.php b/resources/views/export/vendor_contacts.blade.php index e4a8be4318c1..f2be74168824 100644 --- a/resources/views/export/vendor_contacts.blade.php +++ b/resources/views/export/vendor_contacts.blade.php @@ -1,5 +1,5 @@ - {{ trans('texts.client') }} + {{ trans('texts.vendor') }} @if ($multiUser) {{ trans('texts.user') }} @endif