From 0d1c279f64540c25cee20fac53c8c7aa89001d9f Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 28 Oct 2020 16:26:08 +1100 Subject: [PATCH] Fixes for payment meta data types --- .../Controllers/Migration/StepsController.php | 4 +- app/Traits/GenerateMigrationResources.php | 98 +++++++++---------- 2 files changed, 51 insertions(+), 51 deletions(-) diff --git a/app/Http/Controllers/Migration/StepsController.php b/app/Http/Controllers/Migration/StepsController.php index fffb799d5c2d..c4414b9708c1 100644 --- a/app/Http/Controllers/Migration/StepsController.php +++ b/app/Http/Controllers/Migration/StepsController.php @@ -162,7 +162,7 @@ class StepsController extends BaseController $companyService = (new CompanyService(session('MIGRATION_ACCOUNT_TOKEN'))) ->endpoint(session('MIGRATION_ENDPOINT')) ->start(); - + if ($companyService->isSuccessful()) { return view('migration.companies', ['companies' => $companyService->getCompanies()]); } @@ -245,8 +245,8 @@ class StepsController extends BaseController 'invoices' => $this->getInvoices(), 'recurring_invoices' => $this->getRecurringInvoices(), 'quotes' => $this->getQuotes(), - 'payments' => array_merge($this->getPayments(), $this->getCredits()), 'credits' => $this->getCreditsNotes(), + 'payments' => array_merge($this->getPayments(), $this->getCredits()), 'documents' => $this->getDocuments(), 'company_gateways' => $this->getCompanyGateways(), 'client_gateway_tokens' => $this->getClientGatewayTokens(), diff --git a/app/Traits/GenerateMigrationResources.php b/app/Traits/GenerateMigrationResources.php index fcc963e035de..3ad1147f5dae 100644 --- a/app/Traits/GenerateMigrationResources.php +++ b/app/Traits/GenerateMigrationResources.php @@ -217,14 +217,14 @@ trait GenerateMigrationResources 'company_id' => $contact->account_id, 'user_id' => $contact->user_id, 'client_id' => $contact->client_id, - 'first_name' => $contact->first_name, - 'last_name' => $contact->last_name, - 'phone' => $contact->phone, - 'custom_value1' => $contact->custom_value1, - 'custom_value2' => $contact->custom_value2, + 'first_name' => $contact->first_name ?: '', + 'last_name' => $contact->last_name ?: '', + 'phone' => $contact->phone ?: '', + 'custom_value1' => $contact->custom_value1 ?: '', + 'custom_value2' => $contact->custom_value2 ?: '', 'email' => $contact->email, - 'is_primary' => $contact->is_primary, - 'send_email' => $contact->send_invoice, + 'is_primary' => (bool)$contact->is_primary, + 'send_email' => (bool)$contact->send_invoice, 'confirmed' => $contact->confirmation_token ? true : false, 'email_verified_at' => $contact->created_at->toDateTimeString(), 'last_login' => $contact->last_login, @@ -249,10 +249,10 @@ trait GenerateMigrationResources $transformed[] = [ 'company_id' => $product->account_id, 'user_id' => $product->user_id, - 'custom_value1' => $product->custom_value1, - 'custom_value2' => $product->custom_value2, - 'product_key' => $product->product_key, - 'notes' => $product->notes, + 'custom_value1' => $product->custom_value1 ?: '', + 'custom_value2' => $product->custom_value2 ?: '', + 'product_key' => $product->product_key ?: '', + 'notes' => $product->notes ?: '', 'cost' => $product->cost ?: 0, 'quantity' => $product->qty ?: 0, 'tax_name1' => $product->tax_name1, @@ -279,9 +279,9 @@ trait GenerateMigrationResources foreach ($users as $user) { $transformed[] = [ 'id' => $user->id, - 'first_name' => $user->first_name, - 'last_name' => $user->last_name, - 'phone' => $user->phone, + 'first_name' => $user->first_name ?: '', + 'last_name' => $user->last_name ?: '', + 'phone' => $user->phone ?: '', 'email' => $user->email, 'confirmation_code' => $user->confirmation_code, 'failed_logins' => $user->failed_logins, @@ -323,24 +323,24 @@ trait GenerateMigrationResources 'number' => $credit->invoice_number, 'discount' => $credit->discount ?: 0, 'is_amount_discount' => $credit->is_amount_discount ?: false, - 'po_number' => $credit->po_number, + 'po_number' => $credit->po_number ?: '', 'date' => $credit->invoice_date, 'last_sent_date' => $credit->last_sent_date, 'due_date' => $credit->due_date, 'uses_inclusive_taxes' => $this->account->inclusive_taxes, 'is_deleted' => $credit->is_deleted, - 'footer' => $credit->invoice_footer, - 'public_notes' => $credit->public_notes, - 'private_notes' => $credit->private_notes, - 'terms' => $credit->terms, + 'footer' => $credit->invoice_footer ?: '', + 'public_notes' => $credit->public_notes ?: '', + 'private_notes' => $credit->private_notes ?: '', + 'terms' => $credit->terms ?: '', 'tax_name1' => $credit->tax_name1, 'tax_name2' => $credit->tax_name2, 'tax_rate1' => $credit->tax_rate1, 'tax_rate2' => $credit->tax_rate2, 'tax_name3' => '', 'tax_rate3' => 0, - 'custom_value1' => $credit->custom_value1, - 'custom_value2' => $credit->custom_value2, + 'custom_value1' => $credit->custom_value1 ?: '', + 'custom_value2' => $credit->custom_value2 ?: '', 'next_send_date' => null, 'amount' => $credit->amount ?: 0, 'balance' => $credit->balance ?: 0, @@ -379,22 +379,22 @@ trait GenerateMigrationResources 'number' => $invoice->invoice_number, 'discount' => $invoice->discount, 'is_amount_discount' => $invoice->is_amount_discount ?: false, - 'po_number' => $invoice->po_number, + 'po_number' => $invoice->po_number ?: '', 'date' => $invoice->invoice_date, 'last_sent_date' => $invoice->last_sent_date, 'due_date' => $invoice->due_date, 'uses_inclusive_taxes' => $this->account->inclusive_taxes, 'is_deleted' => $invoice->is_deleted, - 'footer' => $invoice->invoice_footer, - 'public_notes' => $invoice->public_notes, - 'private_notes' => $invoice->private_notes, - 'terms' => $invoice->terms, + 'footer' => $invoice->invoice_footer ?: '', + 'public_notes' => $invoice->public_notes ?: '', + 'private_notes' => $invoice->private_notes ?: '', + 'terms' => $invoice->terms ?: '', 'tax_name1' => $invoice->tax_name1, 'tax_name2' => $invoice->tax_name2, 'tax_rate1' => $invoice->tax_rate1, 'tax_rate2' => $invoice->tax_rate2, - 'custom_value1' => $invoice->custom_value1, - 'custom_value2' => $invoice->custom_value2, + 'custom_value1' => $invoice->custom_value1 ?: '', + 'custom_value2' => $invoice->custom_value2 ?: '', 'next_send_date' => null, 'amount' => $invoice->amount ?: 0, 'balance' => $invoice->balance ?: 0, @@ -441,24 +441,24 @@ trait GenerateMigrationResources 'number' => '', 'discount' => $invoice->discount, 'is_amount_discount' => $invoice->is_amount_discount ?: false, - 'po_number' => $invoice->po_number, + 'po_number' => $invoice->po_number ?: '', 'date' => $invoice->invoice_date, 'last_sent_date' => $invoice->last_sent_date, 'due_date' => $invoice->due_date, 'uses_inclusive_taxes' => $this->account->inclusive_taxes, - 'is_deleted' => $invoice->is_deleted, + 'is_deleted' => (bool)$invoice->is_deleted, 'footer' => $invoice->invoice_footer, - 'public_notes' => $invoice->public_notes, - 'private_notes' => $invoice->private_notes, - 'terms' => $invoice->terms, + 'public_notes' => $invoice->public_notes ?: '', + 'private_notes' => $invoice->private_notes ?: '', + 'terms' => $invoice->terms ?: '', 'tax_name1' => $invoice->tax_name1, 'tax_name2' => $invoice->tax_name2, 'tax_rate1' => $invoice->tax_rate1, 'tax_rate2' => $invoice->tax_rate2, 'tax_name3' => '', 'tax_rate3' => 0, - 'custom_value1' => $invoice->custom_value1, - 'custom_value2' => $invoice->custom_value2, + 'custom_value1' => $invoice->custom_value1 ?: '', + 'custom_value2' => $invoice->custom_value2 ?: '', 'custom_value3' => '', 'custom_value4' => '', 'amount' => $invoice->amount ?: 0, @@ -781,22 +781,22 @@ trait GenerateMigrationResources 'number' => $quote->invoice_number, 'discount' => $quote->discount, 'is_amount_discount' => $quote->is_amount_discount ?: false, - 'po_number' => $quote->po_number, + 'po_number' => $quote->po_number ?: '', 'date' => $quote->invoice_date, 'last_sent_date' => $quote->last_sent_date, 'due_date' => $quote->due_date, 'uses_inclusive_taxes' => $this->account->inclusive_taxes, - 'is_deleted' => $quote->is_deleted, - 'footer' => $quote->invoice_footer, - 'public_notes' => $quote->public_notes, - 'private_notes' => $quote->private_notes, - 'terms' => $quote->terms, + 'is_deleted' => (bool)$quote->is_deleted, + 'footer' => $quote->invoice_footer ?: '', + 'public_notes' => $quote->public_notes ?: '', + 'private_notes' => $quote->private_notes ?: '', + 'terms' => $quote->terms ?: '', 'tax_name1' => $quote->tax_name1, 'tax_name2' => $quote->tax_name2, 'tax_rate1' => $quote->tax_rate1, 'tax_rate2' => $quote->tax_rate2, - 'custom_value1' => $quote->custom_value1, - 'custom_value2' => $quote->custom_value2, + 'custom_value1' => $quote->custom_value1 ?: '', + 'custom_value2' => $quote->custom_value2 ?: '', 'next_send_date' => null, 'amount' => $quote->amount ?: 0, 'balance' => $quote->balance ?: 0, @@ -865,9 +865,9 @@ trait GenerateMigrationResources 'applied' => $payment->amount ?: 0, 'refunded' => $payment->refunded ?: 0, 'date' => $payment->payment_date, - 'transaction_reference' => $payment->transaction_reference, + 'transaction_reference' => $payment->transaction_reference ?: '', 'payer_id' => $payment->payer_id, - 'is_deleted' => $payment->is_deleted, + 'is_deleted' => (bool)$payment->is_deleted, 'exchange_rate' => $payment->exchange_rate ? number_format((float) $payment->exchange_rate, 6) : null, 'exchange_currency_id' => $payment->exchange_currency_id, 'currency_id' => isset($payment->client->currency->id) ? $payment->client->currency->id : $this->account->currency_id, @@ -1036,10 +1036,10 @@ trait GenerateMigrationResources } $meta = new \stdClass(); - $meta->exp_month = $exp_month; - $meta->exp_year = $exp_year; - $meta->brand = $payment_method->payment_type->name; - $meta->last4 = str_replace(',', '', ($payment_method->expiration)); + $meta->exp_month = (string)$exp_month; + $meta->exp_year = (string)$exp_year; + $meta->brand = (string)$payment_method->payment_type->name; + $meta->last4 = (string)str_replace(',', '', ($payment_method->expiration)); $meta->type = $payment_method->payment_type->gateway_type_id; return $meta;