From 715998e67a196e0c1fee1d1c6b1aa1c621af485e Mon Sep 17 00:00:00 2001 From: David Bomba Date: Mon, 23 Nov 2020 23:55:17 +1100 Subject: [PATCH 1/4] Reorder migrations --- app/Http/Controllers/Migration/StepsController.php | 2 +- app/Traits/GenerateMigrationResources.php | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/app/Http/Controllers/Migration/StepsController.php b/app/Http/Controllers/Migration/StepsController.php index 890b6f0e0c28..9e15ad0d9adc 100644 --- a/app/Http/Controllers/Migration/StepsController.php +++ b/app/Http/Controllers/Migration/StepsController.php @@ -233,10 +233,10 @@ class StepsController extends BaseController 'vendors' => $this->getVendors(), 'projects' => $this->getProjects(), 'products' => $this->getProducts(), + 'credits' => $this->getCreditsNotes(), 'invoices' => $this->getInvoices(), 'recurring_invoices' => $this->getRecurringInvoices(), 'quotes' => $this->getQuotes(), - 'credits' => $this->getCreditsNotes(), 'payments' => array_merge($this->getPayments(), $this->getCredits()), 'documents' => $this->getDocuments(), 'company_gateways' => $this->getCompanyGateways(), diff --git a/app/Traits/GenerateMigrationResources.php b/app/Traits/GenerateMigrationResources.php index 63cd88fd6742..a1c99bce05af 100644 --- a/app/Traits/GenerateMigrationResources.php +++ b/app/Traits/GenerateMigrationResources.php @@ -1189,7 +1189,6 @@ trait GenerateMigrationResources foreach ($tasks as $task) { - if(!($task->deleted_at instanceof Carbon)) $task->deleted_at = Carbon::parse($task->deleted_at); From fdaf5132678afa6631a5202b68313e014d2adb02 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 24 Nov 2020 14:20:44 +1100 Subject: [PATCH 2/4] sort alphabetically --- app/Http/Controllers/Migration/StepsController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Http/Controllers/Migration/StepsController.php b/app/Http/Controllers/Migration/StepsController.php index 9e15ad0d9adc..325581318494 100644 --- a/app/Http/Controllers/Migration/StepsController.php +++ b/app/Http/Controllers/Migration/StepsController.php @@ -253,7 +253,7 @@ class StepsController extends BaseController $zip = new \ZipArchive(); $zip->open($file, \ZipArchive::CREATE | \ZipArchive::OVERWRITE); - $zip->addFromString('migration.json', json_encode($localMigrationData, JSON_PRETTY_PRINT)); + $zip->addFromString('migration.json', json_encode(ksort($localMigrationData), JSON_PRETTY_PRINT)); $zip->close(); $localMigrationData['file'] = $file; From ae52ea5971757e5e72817781a431e0656044edab Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 25 Nov 2020 11:23:51 +1100 Subject: [PATCH 3/4] Random migration datasets --- app/Console/Commands/ExportMigrations.php | 11 ++++- .../Controllers/Migration/StepsController.php | 1 + app/Traits/GenerateMigrationResources.php | 44 +++++++++++++++++-- 3 files changed, 51 insertions(+), 5 deletions(-) diff --git a/app/Console/Commands/ExportMigrations.php b/app/Console/Commands/ExportMigrations.php index 2ed9f42a9229..382e91ea4037 100644 --- a/app/Console/Commands/ExportMigrations.php +++ b/app/Console/Commands/ExportMigrations.php @@ -17,7 +17,7 @@ class ExportMigrations extends Command * * @var string */ - protected $signature = 'migrations:export {--user=}'; + protected $signature = 'migrations:export {--user=} {--random=}'; /** * The console command description. @@ -50,6 +50,15 @@ class ExportMigrations extends Command return $this->export($record); } + if($this->option('random')){ + + User::all()->random(50)->each(function ($user){ + $this->export($user); + }); + + return; + } + $users = User::all(); foreach($users as $user) { diff --git a/app/Http/Controllers/Migration/StepsController.php b/app/Http/Controllers/Migration/StepsController.php index 325581318494..4a9889281d28 100644 --- a/app/Http/Controllers/Migration/StepsController.php +++ b/app/Http/Controllers/Migration/StepsController.php @@ -245,6 +245,7 @@ class StepsController extends BaseController 'task_statuses' => $this->getTaskStatuses(), 'expenses' => $this->getExpenses(), 'tasks' => $this->getTasks(), + 'documents' => $this->getDocuments(), ]; $localMigrationData['force'] = array_key_exists('force', $company) ? true : false; diff --git a/app/Traits/GenerateMigrationResources.php b/app/Traits/GenerateMigrationResources.php index a1c99bce05af..171fad522aca 100644 --- a/app/Traits/GenerateMigrationResources.php +++ b/app/Traits/GenerateMigrationResources.php @@ -354,11 +354,11 @@ trait GenerateMigrationResources 'custom_value1' => $credit->custom_value1 ?: '', 'custom_value2' => $credit->custom_value2 ?: '', 'next_send_date' => null, - 'amount' => $credit->amount ?: 0, - 'balance' => $credit->balance ?: 0, - 'partial' => $credit->partial ?: 0, + 'amount' => $credit->amount ? $credit->amount * -1: 0, + 'balance' => $credit->balance ? $credit->balance * -1 : 0, + 'partial' => $credit->partial ? $credit->partial * -1 : 0, 'partial_due_date' => $credit->partial_due_date, - 'line_items' => $this->getInvoiceItems($credit->invoice_items), + 'line_items' => $this->getCreditItems($credit->invoice_items), 'created_at' => $credit->created_at ? Carbon::parse($credit->created_at)->toDateString() : null, 'updated_at' => $credit->updated_at ? Carbon::parse($credit->updated_at)->toDateString() : null, 'deleted_at' => $credit->deleted_at ? Carbon::parse($credit->deleted_at)->toDateString() : null, @@ -752,6 +752,41 @@ trait GenerateMigrationResources return $transformed; } + public function getCreditItems($items) + { + $transformed = []; + + foreach ($items as $item) { + + if($item->cost < 0) + $item->cost = $item->cost * -1; + + if($item->qty < 0) + $item->qty = $item->qty * -1; + + $transformed[] = [ + 'id' => $item->id, + 'quantity' => (float) $item->qty, + 'cost' => (float) $item->cost, + 'product_key' => $item->product_key, + 'notes' => $item->notes, + 'discount' => (float) $item->discount, + 'tax_name1' => (string)$item->tax_name1, + 'tax_rate1' => (float) $item->tax_rate1, + 'tax_name2' => (string) $item->tax_name2, + 'tax_rate2' => (float) $item->tax_rate2, + 'tax_name3' => (string) '', + 'tax_rate3' => (float) 0, + 'date' => Carbon::parse($item->created_at)->toDateString(), + 'custom_value1' => $item->custom_value1, + 'custom_value2' => $item->custom_value2, + 'type_id' => (string)$item->invoice_item_type_id, + ]; + } + + return $transformed; + } + public function getInvoiceItems($items) { $transformed = []; @@ -958,6 +993,7 @@ trait GenerateMigrationResources 'height' => $document->height, 'created_at' => $document->created_at ? Carbon::parse($document->created_at)->toDateString() : null, 'updated_at' => $document->updated_at ? Carbon::parse($document->updated_at)->toDateString() : null, + 'url' => $document->getUrl(), ]; } From 7968b2bb5f0a06d33069732e935f71bba606e4ed Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 25 Nov 2020 20:06:37 +1100 Subject: [PATCH 4/4] Fixes for migrations --- app/Console/Commands/ExportMigrations.php | 2 +- app/Traits/GenerateMigrationResources.php | 13 ++++++++----- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/app/Console/Commands/ExportMigrations.php b/app/Console/Commands/ExportMigrations.php index 382e91ea4037..bc9f4c223699 100644 --- a/app/Console/Commands/ExportMigrations.php +++ b/app/Console/Commands/ExportMigrations.php @@ -52,7 +52,7 @@ class ExportMigrations extends Command if($this->option('random')){ - User::all()->random(50)->each(function ($user){ + User::all()->random(200)->each(function ($user){ $this->export($user); }); diff --git a/app/Traits/GenerateMigrationResources.php b/app/Traits/GenerateMigrationResources.php index 171fad522aca..78cf9a69ec7b 100644 --- a/app/Traits/GenerateMigrationResources.php +++ b/app/Traits/GenerateMigrationResources.php @@ -321,6 +321,7 @@ trait GenerateMigrationResources $export_credits = Invoice::where('account_id', $this->account->id) ->where('amount', '<', '0') ->where('invoice_type_id', '=', INVOICE_TYPE_STANDARD) + ->where('is_public', true) ->withTrashed() ->get(); @@ -333,7 +334,7 @@ trait GenerateMigrationResources 'status_id' => $credit->invoice_status_id, 'design_id' => $this->getDesignId($credit->invoice_design_id), 'number' => $credit->invoice_number, - 'discount' => $credit->discount ?: 0, + 'discount' => $credit->discount ? $credit->discount*-1: 0, 'is_amount_discount' => $credit->is_amount_discount ?: false, 'po_number' => $credit->po_number ?: '', 'date' => $credit->invoice_date, @@ -758,11 +759,13 @@ trait GenerateMigrationResources foreach ($items as $item) { - if($item->cost < 0) - $item->cost = $item->cost * -1; + // if($item->cost < 0) + // $item->cost = $item->cost * -1; - if($item->qty < 0) - $item->qty = $item->qty * -1; + $item->qty = $item->qty * -1; + + // if($item->discount < 0) + // $item->discount = $item->discount * -1; $transformed[] = [ 'id' => $item->id,