From 9372a304c7e01ab82dc89cfb3b0d4176f937c12b Mon Sep 17 00:00:00 2001 From: David Bomba Date: Wed, 4 Aug 2021 09:38:22 +1000 Subject: [PATCH 1/4] minor fixes for migrations --- app/Console/Commands/ExportMigrations.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/Console/Commands/ExportMigrations.php b/app/Console/Commands/ExportMigrations.php index dfdc295eed91..c635a5efd469 100644 --- a/app/Console/Commands/ExportMigrations.php +++ b/app/Console/Commands/ExportMigrations.php @@ -7,6 +7,7 @@ use App\Models\User; use App\Traits\GenerateMigrationResources; use Illuminate\Console\Command; use Illuminate\Support\Facades\Auth; +use Illuminate\Support\Facades\Storage; class ExportMigrations extends Command { @@ -63,12 +64,12 @@ class ExportMigrations extends Command if($this->option('email')) { - $record = User::on(DB_NINJA_1)->where('email', $this->option('user'))->first(); + $record = User::on(DB_NINJA_1)->where('email', $this->option('email'))->first(); if($record) return $this->export($record); - $record = User::on(DB_NINJA_2)->where('email', $this->option('user'))->first(); + $record = User::on(DB_NINJA_2)->where('email', $this->option('email'))->first(); if($record) return $this->export($record); @@ -132,6 +133,7 @@ class ExportMigrations extends Command 'ninja_tokens' => $this->getNinjaToken(), ]; + Storage::makeDirectory('migrations'); $file = storage_path("migrations/{$fileName}.zip"); $zip = new \ZipArchive(); From fd4cf132345d0baa71061899aff9048cde6cfc90 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 24 Aug 2021 20:42:56 +1000 Subject: [PATCH 2/4] Minor fixes --- app/Traits/GenerateMigrationResources.php | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/app/Traits/GenerateMigrationResources.php b/app/Traits/GenerateMigrationResources.php index 5518c663af5c..0ba2d9f18dec 100644 --- a/app/Traits/GenerateMigrationResources.php +++ b/app/Traits/GenerateMigrationResources.php @@ -826,8 +826,13 @@ trait GenerateMigrationResources $due_date_parts = explode("-", $invoice->due_date); - if(is_array($due_date_parts) && count($due_date_parts) >=3) + if(is_array($due_date_parts) && count($due_date_parts) >=3){ + + if($due_date_parts[2] == "00") + return "0"; + return (string)$due_date_parts[2]; + } return 'terms'; } From a66b500fc6b76861d85e1c6bbf6a38fdd2870890 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Sun, 29 Aug 2021 22:40:09 +1000 Subject: [PATCH 3/4] Recurring Expenses migration --- app/Console/Commands/ExportMigrations.php | 1 + .../Controllers/Migration/StepsController.php | 1 + app/Jobs/HostedMigration.php | 1 + app/Traits/GenerateMigrationResources.php | 53 +++++++++++++++++++ 4 files changed, 56 insertions(+) diff --git a/app/Console/Commands/ExportMigrations.php b/app/Console/Commands/ExportMigrations.php index c635a5efd469..982d7810fead 100644 --- a/app/Console/Commands/ExportMigrations.php +++ b/app/Console/Commands/ExportMigrations.php @@ -121,6 +121,7 @@ class ExportMigrations extends Command 'products' => $this->getProducts(), 'credits' => $this->getCreditsNotes(), 'invoices' => $this->getInvoices(), + 'recurring_expenses' => $this->getRecurringExpenses(), 'recurring_invoices' => $this->getRecurringInvoices(), 'quotes' => $this->getQuotes(), 'payments' => array_merge($this->getPayments(), $this->getCredits()), diff --git a/app/Http/Controllers/Migration/StepsController.php b/app/Http/Controllers/Migration/StepsController.php index c6bc6cb3110d..a6320a82cd24 100644 --- a/app/Http/Controllers/Migration/StepsController.php +++ b/app/Http/Controllers/Migration/StepsController.php @@ -322,6 +322,7 @@ class StepsController extends BaseController 'products' => $this->getProducts(), 'credits' => $this->getCreditsNotes(), 'invoices' => $this->getInvoices(), + 'recurring_expenses' => $this->getRecurringExpenses(), 'recurring_invoices' => $this->getRecurringInvoices(), 'quotes' => $this->getQuotes(), 'payments' => array_merge($this->getPayments(), $this->getCredits()), diff --git a/app/Jobs/HostedMigration.php b/app/Jobs/HostedMigration.php index 4eb2873630be..d74ae1193087 100644 --- a/app/Jobs/HostedMigration.php +++ b/app/Jobs/HostedMigration.php @@ -141,6 +141,7 @@ class HostedMigration extends Job 'products' => $this->getProducts(), 'credits' => $this->getCreditsNotes(), 'invoices' => $this->getInvoices(), + 'recurring_expenses' => $this->getRecurringExpenses(), 'recurring_invoices' => $this->getRecurringInvoices(), 'quotes' => $this->getQuotes(), 'payments' => array_merge($this->getPayments(), $this->getCredits()), diff --git a/app/Traits/GenerateMigrationResources.php b/app/Traits/GenerateMigrationResources.php index 0ba2d9f18dec..f7052ae7eae5 100644 --- a/app/Traits/GenerateMigrationResources.php +++ b/app/Traits/GenerateMigrationResources.php @@ -20,6 +20,7 @@ use App\Models\PaymentMethod; use App\Models\PaymentTerm; use App\Models\Product; use App\Models\Project; +use App\Models\RecurringExpense; use App\Models\Task; use App\Models\TaskStatus; use App\Models\TaxRate; @@ -656,6 +657,7 @@ trait GenerateMigrationResources 'deleted_at' => $invoice->deleted_at ? Carbon::parse($invoice->deleted_at)->toDateString() : null, 'invitations' => $this->getResourceInvitations($invoice->invitations, 'invoice_id'), 'auto_bill_enabled' => $invoice->auto_bill, + 'recurring_id' => $invoice->recurring_invoice_id, ]; } @@ -681,6 +683,57 @@ trait GenerateMigrationResources return $design_id; } + protected function getRecurringExpenses() + { + info("get recurring Expenses"); + + + $expenses = []; + + $export_expenses = RecurringExpense::where('account_id', $this->account->id) + ->withTrashed() + ->get(); + + foreach ($export_expenses as $expense) { + $invoices[] = [ + 'id' => $expense->id, + 'amount' => $expense->amount, + 'company_id' => $this->account->id, + 'client_id' => $expense->client_id, + 'user_id' => $expense->user_id, + 'custom_value1' => '', + 'custom_value2' => '', + 'custom_value3' => '', + 'custom_value4' => '', + 'category_id' => $expense->expense_category_id, + 'currency_id' => $expense->expense_currency_id, + 'frequency_id' => $this->transformFrequencyId($expense->frequency_id), + 'invoice_currency_id' => $expense->invoice_currency_id, + 'private_notes' => $expense->private_notes, + 'public_notes' => $expense->public_notes, + 'should_be_invoiced' => $expense->should_be_invoiced, + 'tax_name1' => $expense->tax_name1, + 'tax_name2' => $expense->tax_name2, + 'tax_name3' => '', + 'tax_rate1' => $expense->tax_rate1, + 'tax_rate2' => $expense->tax_rate2, + 'tax_rate3' => 0, + 'vendor_id' => $expense->vendor_id, + 'is_deleted' => $expense->is_deleted, + 'next_send_date' => $this->getNextSendDateForMigration($expense), + 'remaining_cycles' => $this->getRemainingCycles($expense), + 'created_at' => $expense->created_at ? Carbon::parse($expense->created_at)->toDateString() : null, + 'updated_at' => $expense->updated_at ? Carbon::parse($expense->updated_at)->toDateString() : null, + 'deleted_at' => $expense->deleted_at ? Carbon::parse($expense->deleted_at)->toDateString() : null, + ]; + } + + return $invoices; + + + + } + protected function getRecurringInvoices() { info("get recurring invoices"); From 21cc00747423429f3d4a1d6f44022a831b064f29 Mon Sep 17 00:00:00 2001 From: David Bomba Date: Tue, 31 Aug 2021 10:20:43 +1000 Subject: [PATCH 4/4] Adjust send_invoice to always true --- app/Traits/GenerateMigrationResources.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/app/Traits/GenerateMigrationResources.php b/app/Traits/GenerateMigrationResources.php index f7052ae7eae5..66b32c3c58c7 100644 --- a/app/Traits/GenerateMigrationResources.php +++ b/app/Traits/GenerateMigrationResources.php @@ -2028,7 +2028,7 @@ trait GenerateMigrationResources 'custom_value4' => '', 'email' => $contact->email, 'is_primary' => (bool)$contact->is_primary, - 'send_email' => (bool)$contact->send_invoice ?: false, + 'send_email' => (bool)$contact->send_invoice ?: true, 'confirmed' => $contact->confirmation_token ? true : false, 'email_verified_at' => $contact->created_at->toDateTimeString(), 'last_login' => $contact->last_login,