diff --git a/app/Http/Controllers/Migration/StepsController.php b/app/Http/Controllers/Migration/StepsController.php index fdd89b1301e5..18fdad9a3c73 100644 --- a/app/Http/Controllers/Migration/StepsController.php +++ b/app/Http/Controllers/Migration/StepsController.php @@ -266,6 +266,7 @@ class StepsController extends BaseController 'expenses' => $this->getExpenses(), 'tasks' => $this->getTasks(), 'documents' => $this->getDocuments(), + 'ninja_tokens' => $this->getNinjaTokens(), ]; $localMigrationData['force'] = array_key_exists('force', $company); diff --git a/app/Traits/GenerateMigrationResources.php b/app/Traits/GenerateMigrationResources.php index 0bac5b2a816c..f9239df278eb 100644 --- a/app/Traits/GenerateMigrationResources.php +++ b/app/Traits/GenerateMigrationResources.php @@ -6,6 +6,7 @@ use App\Models\AccountGateway; use App\Models\AccountGatewaySettings; use App\Models\AccountGatewayToken; use App\Models\AccountToken; +use App\Models\Client; use App\Models\Contact; use App\Models\Credit; use App\Models\Document; @@ -345,6 +346,40 @@ info("get company"); return $transformed; } + protected function getNinjaToken() + { + $transformed = []; + + $ninja_client = Client::where('public_id', $this->account->id)->first(); + + if(!$ninja_client) + return $transformed; + + $agts = AccountGatewayToken::where('client_id', $ninja_client->id)->get(); + $is_default = true; + + foreach($agts as $agt) { + + $payment_method = $agt->default_payment_method; + $contact = Contact::where('id', $payment_method->contact_id)->withTrashed()->first(); + + $transformed[] = [ + 'id' => $payment_method->id, + 'company_id' => $this->account->id, + 'client_id' => $contact->client_id, + 'token' => $payment_method->source_reference, + 'company_gateway_id' => $agt->account_gateway_id, + 'gateway_customer_reference' => $agt->token, + 'gateway_type_id' => $payment_method->payment_type->gateway_type_id, + 'is_default' => $is_default, + 'meta' => $this->convertMeta($payment_method), + ]; + } + + return $transformed; + + } + protected function getProducts() { info("get products"); @@ -363,7 +398,8 @@ info("get company"); 'custom_value2' => $product->custom_value2 ?: '', 'product_key' => $product->product_key ?: '', 'notes' => $product->notes ?: '', - 'cost' => $product->cost ?: 0, + 'price' => $product->cost ?: 0, + 'cost' => 0, 'quantity' => $product->qty ?: 0, 'tax_name1' => $product->tax_name1, 'tax_name2' => $product->tax_name2,