Working on data import tranformers

This commit is contained in:
Hillel Coren 2016-01-06 09:52:26 +02:00
parent 373c2e7736
commit 18155a9482
17 changed files with 95 additions and 96 deletions

View File

@ -13,20 +13,20 @@ class ClientTransformer extends BaseTransformer
return new Item($data, function ($data) { return new Item($data, function ($data) {
return [ return [
'name' => $data->organization, 'name' => $this->getString($data, 'organization'),
'work_phone' => $data->busphone, 'work_phone' => $this->getString($data, 'busphone'),
'address1' => $data->street, 'address1' => $this->getString($data, 'street'),
'address2' => $data->street2, 'address2' => $this->getString($data, 'street2'),
'city' => $data->city, 'city' => $this->getString($data, 'city'),
'state' => $data->province, 'state' => $this->getString($data, 'province'),
'postal_code' => $data->postalcode, 'postal_code' => $this->getString($data, 'postalcode'),
'private_notes' => $data->notes, 'private_notes' => $this->getString($data, 'notes'),
'contacts' => [ 'contacts' => [
[ [
'first_name' => $data->firstname, 'first_name' => $this->getString($data, 'firstname'),
'last_name' => $data->lastname, 'last_name' => $this->getString($data, 'lastname'),
'email' => $data->email, 'email' => $this->getString($data, 'email'),
'phone' => $data->mobphone ?: $data->homephone, 'phone' => $this->getString($data, 'mobphone') ?: $this->getString($data, 'homephone'),
], ],
], ],
'country_id' => $this->getCountryId($data->country), 'country_id' => $this->getCountryId($data->country),

View File

@ -20,14 +20,13 @@ class InvoiceTransformer extends BaseTransformer
'client_id' => $this->getClientId($data->organization), 'client_id' => $this->getClientId($data->organization),
'invoice_number' => $this->getInvoiceNumber($data->invoice_number), 'invoice_number' => $this->getInvoiceNumber($data->invoice_number),
'paid' => (float) $data->paid, 'paid' => (float) $data->paid,
'po_number' => $data->po_number, 'po_number' => $this->getString($data, 'po_number'),
'terms' => $data->terms, 'terms' => $this->getString($data, 'terms'),
'public_notes' => $data->notes,
'invoice_date_sql' => $data->create_date, 'invoice_date_sql' => $data->create_date,
'invoice_items' => [ 'invoice_items' => [
[ [
'product_key' => '', 'product_key' => '',
'notes' => $data->notes, 'notes' => $this->getString($data, 'notes'),
'cost' => (float) $data->amount, 'cost' => (float) $data->amount,
'qty' => 1, 'qty' => 1,
] ]

View File

@ -13,7 +13,7 @@ class ClientTransformer extends BaseTransformer
return new Item($data, function ($data) { return new Item($data, function ($data) {
return [ return [
'name' => $data->client_name, 'name' => $this->getString($data, 'client_name'),
]; ];
}); });
} }

View File

@ -14,10 +14,10 @@ class ContactTransformer extends BaseTransformer
return new Item($data, function ($data) { return new Item($data, function ($data) {
return [ return [
'client_id' => $this->getClientId($data->client), 'client_id' => $this->getClientId($data->client),
'first_name' => $data->first_name, 'first_name' => $this->getString($data, 'first_name'),
'last_name' => $data->last_name, 'last_name' => $this->getString($data, 'last_name'),
'email' => $data->email, 'email' => $this->getString($data, 'email'),
'phone' => $data->office_phone ?: $data->mobile_phone, 'phone' => $this->getString($data, 'office_phone') ?: $this->getString($data, 'mobile_phone'),
]; ];
}); });
} }

View File

@ -20,12 +20,12 @@ class InvoiceTransformer extends BaseTransformer
'client_id' => $this->getClientId($data->client), 'client_id' => $this->getClientId($data->client),
'invoice_number' => $this->getInvoiceNumber($data->id), 'invoice_number' => $this->getInvoiceNumber($data->id),
'paid' => (float) $data->paid_amount, 'paid' => (float) $data->paid_amount,
'po_number' => $data->po_number, 'po_number' => $this->getString($data, 'po_number'),
'invoice_date_sql' => $this->getDate($data->issue_date, 'm/d/Y'), 'invoice_date_sql' => $this->getDate($data->issue_date, 'm/d/Y'),
'invoice_items' => [ 'invoice_items' => [
[ [
'product_key' => '', 'product_key' => '',
'notes' => $data->subject, 'notes' => $this->getString($data, 'subject'),
'cost' => (float) $data->invoice_amount, 'cost' => (float) $data->invoice_amount,
'qty' => 1, 'qty' => 1,
] ]

View File

@ -13,21 +13,21 @@ class ClientTransformer extends BaseTransformer
return new Item($data, function ($data) { return new Item($data, function ($data) {
return [ return [
'name' => $data->name, 'name' => $this->getString($data, 'name'),
'contacts' => [ 'contacts' => [
[ [
'first_name' => $this->getFirstName($data->primary_contact), 'first_name' => $this->getFirstName($data->primary_contact),
'last_name' => $this->getLastName($data->primary_contactk), 'last_name' => $this->getLastName($data->primary_contactk),
'email' => $data->business_email, 'email' => $this->getString($data, 'business_email'),
], ],
], ],
'address1' => $data->address_1, 'address1' => $this->getString($data, 'address_1'),
'address2' => $data->address_2, 'address2' => $this->getString($data, 'address_2'),
'city' => $data->city, 'city' => $this->getString($data, 'city'),
'state' => $data->state_name, 'state' => $this->getString($data, 'state_name'),
'postal_code' => $data->zip_code, 'postal_code' => $this->getString($data, 'zip_code'),
'work_phone' => $data->phone, 'work_phone' => $this->getString($data, 'phone'),
'website' => $data->website, 'website' => $this->getString($data, 'website'),
'country_id' => $this->getCountryId($data->country), 'country_id' => $this->getCountryId($data->country),
]; ];
}); });

View File

@ -25,7 +25,7 @@ class InvoiceTransformer extends BaseTransformer
'invoice_items' => [ 'invoice_items' => [
[ [
'product_key' => '', 'product_key' => '',
'notes' => $data->summary, 'notes' => $this->getString($data, 'summary'),
'cost' => (float) $data->billed_total, 'cost' => (float) $data->billed_total,
'qty' => 1, 'qty' => 1,
] ]

View File

@ -13,19 +13,19 @@ class ClientTransformer extends BaseTransformer
return new Item($data, function ($data) { return new Item($data, function ($data) {
return [ return [
'name' => $data->client_name, 'name' => $this->getString($data, 'client_name'),
'work_phone' => $data->tel, 'work_phone' => $this->getString($data, 'tel'),
'website' => $data->website, 'website' => $this->getString($data, 'website'),
'address1' => $data->address, 'address1' => $this->getString($data, 'address'),
'city' => $data->city, 'city' => $this->getString($data, 'city'),
'state' => $data->state, 'state' => $this->getString($data, 'state'),
'postal_code' => $data->postcode, 'postal_code' => $this->getString($data, 'postcode'),
'country_id' => $this->getCountryIdBy2($data->country), 'country_id' => $this->getCountryIdBy2($data->country),
'private_notes' => $data->notes, 'private_notes' => $this->getString($data, 'notes'),
'contacts' => [ 'contacts' => [
[ [
'email' => $data->email, 'email' => $this->getString($data, 'email'),
'phone' => $data->mobile, 'phone' => $this->getString($data, 'mobile'),
], ],
], ],
]; ];

View File

@ -19,15 +19,15 @@ class InvoiceTransformer extends BaseTransformer
return [ return [
'client_id' => $this->getClientId($data->client_name), 'client_id' => $this->getClientId($data->client_name),
'invoice_number' => $this->getInvoiceNumber($data->ref), 'invoice_number' => $this->getInvoiceNumber($data->ref),
'po_number' => $data->po_number, 'po_number' => $this->getString($data, 'po_number'),
'invoice_date_sql' => $data->date, 'invoice_date_sql' => $data->date,
'due_date_sql' => $data->due_date, 'due_date_sql' => $data->due_date,
'invoice_footer' => $data->footer, 'invoice_footer' => $this->getString($data, 'footer'),
'paid' => (float) $data->paid, 'paid' => (float) $data->paid,
'invoice_items' => [ 'invoice_items' => [
[ [
'product_key' => '', 'product_key' => '',
'notes' => $data->description, 'notes' => $this->getString($data, 'description'),
'cost' => (float) $data->total, 'cost' => (float) $data->total,
'qty' => 1, 'qty' => 1,
] ]

View File

@ -13,19 +13,19 @@ class ClientTransformer extends BaseTransformer
return new Item($data, function ($data) { return new Item($data, function ($data) {
return [ return [
'name' => $data->name, 'name' => $this->getString($data, 'name'),
'city' => isset($data->city) ? $data->city : '', 'city' => $this->getString($data, 'city'),
'state' => isset($data->city) ? $data->stateprovince : '', 'state' => $this->getString($data, 'stateprovince'),
'id_number' => isset($data->registration_number) ? $data->registration_number : '', 'id_number' => $this->getString($data, 'registration_number'),
'postal_code' => isset($data->postalzip_code) ? $data->postalzip_code : '', 'postal_code' => $this->getString($data, 'postalzip_code'),
'private_notes' => isset($data->notes) ? $data->notes : '', 'private_notes' => $this->getString($data, 'notes'),
'work_phone' => isset($data->phone) ? $data->phone : '', 'work_phone' => $this->getString($data, 'phone'),
'contacts' => [ 'contacts' => [
[ [
'first_name' => isset($data->contact_name) ? $this->getFirstName($data->contact_name) : '', 'first_name' => isset($data->contact_name) ? $this->getFirstName($data->contact_name) : '',
'last_name' => isset($data->contact_name) ? $this->getLastName($data->contact_name) : '', 'last_name' => isset($data->contact_name) ? $this->getLastName($data->contact_name) : '',
'email' => $data->email, 'email' => $this->getString($data, 'email'),
'phone' => isset($data->mobile) ? $data->mobile : '', 'phone' => $this->getString($data, 'mobile'),
], ],
], ],
'country_id' => isset($data->country) ? $this->getCountryId($data->country) : null, 'country_id' => isset($data->country) ? $this->getCountryId($data->country) : null,

View File

@ -20,15 +20,15 @@ class InvoiceTransformer extends BaseTransformer
'client_id' => $this->getClientId($data->client), 'client_id' => $this->getClientId($data->client),
'invoice_number' => $this->getInvoiceNumber($data->document_no), 'invoice_number' => $this->getInvoiceNumber($data->document_no),
'paid' => (float) $data->paid_to_date, 'paid' => (float) $data->paid_to_date,
'po_number' => $data->purchase_order, 'po_number' => $this->getString($data, 'purchase_order'),
'terms' => $data->terms, 'terms' => $this->getString($data, 'terms'),
'public_notes' => $data->notes, 'public_notes' => $this->getString($data, 'notes'),
'invoice_date_sql' => $this->getDate($data->date), 'invoice_date_sql' => $this->getDate($data->date),
'due_date_sql' => $this->getDate($data->due_date), 'due_date_sql' => $this->getDate($data->due_date),
'invoice_items' => [ 'invoice_items' => [
[ [
'product_key' => '', 'product_key' => '',
'notes' => $data->description, 'notes' => $this->getString($data, 'description'),
'cost' => (float) $data->total, 'cost' => (float) $data->total,
'qty' => 1, 'qty' => 1,
] ]

View File

@ -13,13 +13,13 @@ class ClientTransformer extends BaseTransformer
return new Item($data, function ($data) { return new Item($data, function ($data) {
return [ return [
'name' => $data->company, 'name' => $this->getString($data, 'company'),
'work_phone' => $data->phone, 'work_phone' => $this->getString($data, 'phone'),
'contacts' => [ 'contacts' => [
[ [
'first_name' => $this->getFirstName($data->name), 'first_name' => $this->getFirstName($data->name),
'last_name' => $this->getLastName($data->name), 'last_name' => $this->getLastName($data->name),
'email' => $data->email, 'email' => $this->getString($data, 'email'),
], ],
], ],
]; ];

View File

@ -20,13 +20,13 @@ class InvoiceTransformer extends BaseTransformer
'client_id' => $this->getClientId($data->client), 'client_id' => $this->getClientId($data->client),
'invoice_number' => $this->getInvoiceNumber($data->number), 'invoice_number' => $this->getInvoiceNumber($data->number),
'paid' => (float) $data->total - (float) $data->balance, 'paid' => (float) $data->total - (float) $data->balance,
'public_notes' => $data->subject, 'public_notes' => $this->getString($data, 'subject'),
'invoice_date_sql' => $data->date_sent, 'invoice_date_sql' => $data->date_sent,
'due_date_sql' => $data->date_due, 'due_date_sql' => $data->date_due,
'invoice_items' => [ 'invoice_items' => [
[ [
'product_key' => '', 'product_key' => '',
'notes' => $data->line_item, 'notes' => $this->getString($data, 'line_item'),
'cost' => (float) $data->total, 'cost' => (float) $data->total,
'qty' => 1, 'qty' => 1,
] ]

View File

@ -13,22 +13,22 @@ class ClientTransformer extends BaseTransformer
return new Item($data, function ($data) { return new Item($data, function ($data) {
return [ return [
'name' => $data->customer_name, 'name' => $this->getString($data, 'customer_name'),
'id_number' => $data->account_number, 'id_number' => $this->getString($data, 'account_number'),
'work_phone' => $data->phone, 'work_phone' => $this->getString($data, 'phone'),
'website' => $data->website, 'website' => $this->getString($data, 'website'),
'address1' => $data->address_line_1, 'address1' => $this->getString($data, 'address_line_1'),
'address2' => $data->address_line_2, 'address2' => $this->getString($data, 'address_line_2'),
'city' => $data->city, 'city' => $this->getString($data, 'city'),
'state' => $data->provincestate, 'state' => $this->getString($data, 'provincestate'),
'postal_code' => $data->postal_codezip_code, 'postal_code' => $this->getString($data, 'postal_codezip_code'),
'private_notes' => $data->delivery_instructions, 'private_notes' => $this->getString($data, 'delivery_instructions'),
'contacts' => [ 'contacts' => [
[ [
'first_name' => $data->contact_first_name, 'first_name' => $this->getString($data, 'contact_first_name'),
'last_name' => $data->contact_last_name, 'last_name' => $this->getString($data, 'contact_last_name'),
'email' => $data->email, 'email' => $this->getString($data, 'email'),
'phone' => $data->mobile, 'phone' => $this->getString($data, 'mobile'),
], ],
], ],
'country_id' => $this->getCountryId($data->country), 'country_id' => $this->getCountryId($data->country),

View File

@ -19,14 +19,14 @@ class InvoiceTransformer extends BaseTransformer
return [ return [
'client_id' => $this->getClientId($data->customer), 'client_id' => $this->getClientId($data->customer),
'invoice_number' => $this->getInvoiceNumber($data->invoice_num), 'invoice_number' => $this->getInvoiceNumber($data->invoice_num),
'po_number' => $data->po_so, 'po_number' => $this->getString($data, 'po_so'),
'invoice_date_sql' => $this->getDate($data->invoice_date), 'invoice_date_sql' => $this->getDate($data->invoice_date),
'due_date_sql' => $this->getDate($data->due_date), 'due_date_sql' => $this->getDate($data->due_date),
'paid' => 0, 'paid' => 0,
'invoice_items' => [ 'invoice_items' => [
[ [
'product_key' => $data->product, 'product_key' => $this->getString($data, 'product'),
'notes' => $data->description, 'notes' => $this->getString($data, 'description'),
'cost' => (float) $data->amount, 'cost' => (float) $data->amount,
'qty' => (float) $data->quantity, 'qty' => (float) $data->quantity,
] ]

View File

@ -13,21 +13,21 @@ class ClientTransformer extends BaseTransformer
return new Item($data, function ($data) { return new Item($data, function ($data) {
return [ return [
'name' => $data->customer_name, 'name' => $this->getString($data, 'customer_name'),
'id_number' => $data->customer_id, 'id_number' => $this->getString($data, 'customer_id'),
'work_phone' => $data->phonek, 'work_phone' => $this->getString($data, 'phone'),
'address1' => $data->billing_address, 'address1' => $this->getString($data, 'billing_address'),
'city' => $data->billing_city, 'city' => $this->getString($data, 'billing_city'),
'state' => $data->billing_state, 'state' => $this->getString($data, 'billing_state'),
'postal_code' => $data->billing_code, 'postal_code' => $this->getString($data, 'billing_code'),
'private_notes' => $data->notes, 'private_notes' => $this->getString($data, 'notes'),
'website' => $data->website, 'website' => $this->getString($data, 'website'),
'contacts' => [ 'contacts' => [
[ [
'first_name' => $data->first_name, 'first_name' => $this->getString($data, 'first_name'),
'last_name' => $data->last_name, 'last_name' => $this->getString($data, 'last_name'),
'email' => $data->emailid, 'email' => $this->getString($data, 'emailid'),
'phone' => $data->mobilephone, 'phone' => $this->getString($data, 'mobilephone'),
], ],
], ],
'country_id' => $this->getCountryId($data->billing_country), 'country_id' => $this->getCountryId($data->billing_country),

View File

@ -20,13 +20,13 @@ class InvoiceTransformer extends BaseTransformer
'client_id' => $this->getClientId($data->customer_name), 'client_id' => $this->getClientId($data->customer_name),
'invoice_number' => $this->getInvoiceNumber($data->invoice_number), 'invoice_number' => $this->getInvoiceNumber($data->invoice_number),
'paid' => (float) $data->total - (float) $data->balance, 'paid' => (float) $data->total - (float) $data->balance,
'po_number' => $data->purchaseorder, 'po_number' => $this->getString($data, 'purchaseorder'),
'due_date_sql' => $data->due_date, 'due_date_sql' => $data->due_date,
'invoice_date_sql' => $data->invoice_date, 'invoice_date_sql' => $data->invoice_date,
'invoice_items' => [ 'invoice_items' => [
[ [
'product_key' => '', 'product_key' => '',
'notes' => $data->item_desc, 'notes' => $this->getString($data, 'item_desc'),
'cost' => (float) $data->total, 'cost' => (float) $data->total,
'qty' => 1, 'qty' => 1,
] ]