From 598b4743d87ce7433ac381c1315e908667b58fab Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 16 Apr 2018 13:48:25 +0300 Subject: [PATCH] Added Pancake import --- app/Constants.php | 1 + .../Import/Pancake/ClientTransformer.php | 41 +++++++++++ .../Import/Pancake/InvoiceTransformer.php | 71 +++++++++++++++++++ app/Services/ImportService.php | 1 + 4 files changed, 114 insertions(+) create mode 100644 app/Ninja/Import/Pancake/ClientTransformer.php create mode 100644 app/Ninja/Import/Pancake/InvoiceTransformer.php diff --git a/app/Constants.php b/app/Constants.php index a305b7cc64..ed421c38c9 100644 --- a/app/Constants.php +++ b/app/Constants.php @@ -180,6 +180,7 @@ if (! defined('APP_NAME')) { define('IMPORT_INVOICEPLANE', 'InvoicePlane'); define('IMPORT_HARVEST', 'Harvest'); define('IMPORT_STRIPE', 'Stripe'); + define('IMPORT_PANCAKE', 'Pancake'); define('MAX_NUM_CLIENTS', 100); define('MAX_NUM_CLIENTS_PRO', 20000); diff --git a/app/Ninja/Import/Pancake/ClientTransformer.php b/app/Ninja/Import/Pancake/ClientTransformer.php new file mode 100644 index 0000000000..ef83346062 --- /dev/null +++ b/app/Ninja/Import/Pancake/ClientTransformer.php @@ -0,0 +1,41 @@ +hasClient($data->company)) { + return false; + } + + return new Item($data, function ($data) { + return [ + 'name' => $this->getString($data, 'company'), + 'work_phone' => $this->getString($data, 'telephone_number'), + 'website' => $this->getString($data, 'website_url'), + 'private_notes' => $this->getString($data, 'notes'), + 'contacts' => [ + [ + 'first_name' => $this->getString($data, 'first_name'), + 'last_name' => $this->getString($data, 'last_name'), + 'email' => $this->getString($data, 'email'), + 'phone' => $this->getString($data, 'mobile_number'), + ], + ], + ]; + }); + } +} diff --git a/app/Ninja/Import/Pancake/InvoiceTransformer.php b/app/Ninja/Import/Pancake/InvoiceTransformer.php new file mode 100644 index 0000000000..1be89bf36a --- /dev/null +++ b/app/Ninja/Import/Pancake/InvoiceTransformer.php @@ -0,0 +1,71 @@ +getClientId($data->client)) { + return false; + } + + if ($this->hasInvoice($data->invoice)) { + return false; + } + + if ($data->recurring == 'Yes') { + return false; + } + + return new Item($data, function ($data) { + return [ + 'client_id' => $this->getClientId($data->client), + 'invoice_number' => $this->getInvoiceNumber($data->invoice), + 'invoice_date' => ! empty($data->date_of_creation) ? date('Y-m-d', strtotime($data->date_of_creation)) : null, + 'due_date' => ! empty($data->due_date) ? date('Y-m-d', strtotime($data->due_date)) : null, + 'paid' => (float) $data->amount_paid, + 'public_notes' => $this->getString($data, 'notes'), + 'private_notes' => $this->getString($data, 'description'), + 'invoice_date_sql' => $data->create_date, + 'invoice_items' => [ + [ + 'product_key' => $data->item_1_gross_discount > 0 ? trans('texts.discount') : $data->item_1_name, + 'notes' => $data->item_1_description, + 'cost' => (float) $data->item_1_gross_discount > 0 ? $data->item_1_gross_discount * -1 : $data->item_1_rate, + 'qty' => $data->item_1_quantity, + ], + [ + 'product_key' => $data->item_2_gross_discount > 0 ? trans('texts.discount') : $data->item_2_name, + 'notes' => $data->item_2_description, + 'cost' => (float) $data->item_2_gross_discount > 0 ? $data->item_2_gross_discount * -1 : $data->item_2_rate, + 'qty' => $data->item_2_quantity, + ], + [ + 'product_key' => $data->item_3_gross_discount > 0 ? trans('texts.discount') : $data->item_3_name, + 'notes' => $data->item_3_description, + 'cost' => (float) $data->item_3_gross_discount > 0 ? $data->item_3_gross_discount * -1 : $data->item_3_rate, + 'qty' => $data->item_3_quantity, + ], + [ + 'product_key' => $data->item_4_gross_discount > 0 ? trans('texts.discount') : $data->item_4_name, + 'notes' => $data->item_4_description, + 'cost' => (float) $data->item_4_gross_discount > 0 ? $data->item_4_gross_discount * -1 : $data->item_4_rate, + 'qty' => $data->item_4_quantity, + ], + ], + ]; + }); + } +} diff --git a/app/Services/ImportService.php b/app/Services/ImportService.php index 24869f3707..bf5c1b8e1b 100644 --- a/app/Services/ImportService.php +++ b/app/Services/ImportService.php @@ -113,6 +113,7 @@ class ImportService IMPORT_INVOICEABLE, IMPORT_INVOICEPLANE, IMPORT_NUTCACHE, + IMPORT_PANCAKE, IMPORT_RONIN, IMPORT_STRIPE, IMPORT_WAVE,