mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2024-09-19 16:01:34 +02:00
Merge pull request #6645 from turbo124/master
Improve migration dataset v4->v5
This commit is contained in:
commit
956f2fda33
@ -303,13 +303,13 @@ trait GenerateMigrationResources
|
|||||||
|
|
||||||
public function getTaxRates()
|
public function getTaxRates()
|
||||||
{
|
{
|
||||||
info("get tax rates");
|
|
||||||
|
|
||||||
|
|
||||||
$rates = TaxRate::where('account_id', $this->account->id)
|
$rates = TaxRate::where('account_id', $this->account->id)
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
info("get tax rates => " . $rates->count());
|
||||||
|
|
||||||
$transformed = [];
|
$transformed = [];
|
||||||
|
|
||||||
foreach ($rates as $rate) {
|
foreach ($rates as $rate) {
|
||||||
@ -328,10 +328,12 @@ trait GenerateMigrationResources
|
|||||||
}
|
}
|
||||||
|
|
||||||
protected function getClients()
|
protected function getClients()
|
||||||
{info("get clients");
|
{
|
||||||
|
|
||||||
$clients = [];
|
$clients = [];
|
||||||
|
|
||||||
|
info("get clients => ". $this->account->clients()->count());
|
||||||
|
|
||||||
foreach ($this->account->clients()->withTrashed()->get() as $client) {
|
foreach ($this->account->clients()->withTrashed()->get() as $client) {
|
||||||
|
|
||||||
$number = $client->id_number;
|
$number = $client->id_number;
|
||||||
@ -401,6 +403,8 @@ trait GenerateMigrationResources
|
|||||||
|
|
||||||
$transformed = [];
|
$transformed = [];
|
||||||
|
|
||||||
|
info("Importing contacts => " . $contacts->count());
|
||||||
|
|
||||||
foreach ($contacts as $contact) {
|
foreach ($contacts as $contact) {
|
||||||
$transformed[] = [
|
$transformed[] = [
|
||||||
'id' => $contact->id,
|
'id' => $contact->id,
|
||||||
@ -475,12 +479,13 @@ trait GenerateMigrationResources
|
|||||||
|
|
||||||
protected function getProducts()
|
protected function getProducts()
|
||||||
{
|
{
|
||||||
info("get products");
|
|
||||||
|
|
||||||
$products = Product::where('account_id', $this->account->id)
|
$products = Product::where('account_id', $this->account->id)
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
info("get products " . $products->count());
|
||||||
|
|
||||||
$transformed = [];
|
$transformed = [];
|
||||||
|
|
||||||
foreach ($products as $product) {
|
foreach ($products as $product) {
|
||||||
@ -509,12 +514,13 @@ trait GenerateMigrationResources
|
|||||||
|
|
||||||
public function getUsers()
|
public function getUsers()
|
||||||
{
|
{
|
||||||
info("get users");
|
|
||||||
|
|
||||||
$users = User::where('account_id', $this->account->id)
|
$users = User::where('account_id', $this->account->id)
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
info("get users " . $users->count());
|
||||||
|
|
||||||
$transformed = [];
|
$transformed = [];
|
||||||
|
|
||||||
foreach ($users as $user) {
|
foreach ($users as $user) {
|
||||||
@ -545,7 +551,6 @@ trait GenerateMigrationResources
|
|||||||
|
|
||||||
private function getCreditsNotes()
|
private function getCreditsNotes()
|
||||||
{
|
{
|
||||||
info("get credit notes");
|
|
||||||
|
|
||||||
$credits = [];
|
$credits = [];
|
||||||
|
|
||||||
@ -556,6 +561,8 @@ trait GenerateMigrationResources
|
|||||||
->withTrashed()
|
->withTrashed()
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
info("get credit notes => " . $export_credits->count());
|
||||||
|
|
||||||
foreach ($export_credits as $credit) {
|
foreach ($export_credits as $credit) {
|
||||||
$credits[] = [
|
$credits[] = [
|
||||||
'id' => $credit->id,
|
'id' => $credit->id,
|
||||||
@ -602,7 +609,7 @@ trait GenerateMigrationResources
|
|||||||
|
|
||||||
|
|
||||||
protected function getInvoices()
|
protected function getInvoices()
|
||||||
{ info("get invoices");
|
{
|
||||||
|
|
||||||
$invoices = [];
|
$invoices = [];
|
||||||
|
|
||||||
@ -613,6 +620,8 @@ trait GenerateMigrationResources
|
|||||||
->withTrashed()
|
->withTrashed()
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
info("get invoices -> ". $export_invoices->count());
|
||||||
|
|
||||||
foreach ($export_invoices as $invoice) {
|
foreach ($export_invoices as $invoice) {
|
||||||
$invoices[] = [
|
$invoices[] = [
|
||||||
'id' => $invoice->id,
|
'id' => $invoice->id,
|
||||||
@ -685,8 +694,6 @@ trait GenerateMigrationResources
|
|||||||
|
|
||||||
protected function getRecurringExpenses()
|
protected function getRecurringExpenses()
|
||||||
{
|
{
|
||||||
info("get recurring Expenses");
|
|
||||||
|
|
||||||
|
|
||||||
$expenses = [];
|
$expenses = [];
|
||||||
|
|
||||||
@ -694,8 +701,10 @@ trait GenerateMigrationResources
|
|||||||
->withTrashed()
|
->withTrashed()
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
info("get recurring Expenses => " . $export_expenses->count());
|
||||||
|
|
||||||
foreach ($export_expenses as $expense) {
|
foreach ($export_expenses as $expense) {
|
||||||
$invoices[] = [
|
$expenses[] = [
|
||||||
'id' => $expense->id,
|
'id' => $expense->id,
|
||||||
'amount' => $expense->amount,
|
'amount' => $expense->amount,
|
||||||
'company_id' => $this->account->id,
|
'company_id' => $this->account->id,
|
||||||
@ -728,7 +737,7 @@ trait GenerateMigrationResources
|
|||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
return $invoices;
|
return $expenses;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@ -736,8 +745,6 @@ trait GenerateMigrationResources
|
|||||||
|
|
||||||
protected function getRecurringInvoices()
|
protected function getRecurringInvoices()
|
||||||
{
|
{
|
||||||
info("get recurring invoices");
|
|
||||||
|
|
||||||
|
|
||||||
$invoices = [];
|
$invoices = [];
|
||||||
|
|
||||||
@ -745,7 +752,9 @@ trait GenerateMigrationResources
|
|||||||
->where('amount', '>=', 0)
|
->where('amount', '>=', 0)
|
||||||
->where('is_recurring', true)
|
->where('is_recurring', true)
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
info("get recurring invoices => " . $export_invoices->count());
|
||||||
|
|
||||||
foreach ($export_invoices as $invoice) {
|
foreach ($export_invoices as $invoice) {
|
||||||
$invoices[] = [
|
$invoices[] = [
|
||||||
@ -791,7 +800,8 @@ trait GenerateMigrationResources
|
|||||||
'due_date_days' => $this->transformDueDate($invoice),
|
'due_date_days' => $this->transformDueDate($invoice),
|
||||||
'remaining_cycles' => $this->getRemainingCycles($invoice),
|
'remaining_cycles' => $this->getRemainingCycles($invoice),
|
||||||
'invitations' => $this->getResourceInvitations($invoice->invitations, 'recurring_invoice_id'),
|
'invitations' => $this->getResourceInvitations($invoice->invitations, 'recurring_invoice_id'),
|
||||||
'auto_bill_enabled' => $invoice->auto_bill,
|
'auto_bill_enabled' => $this->calcAutoBillEnabled($invoice),
|
||||||
|
'auto_bill' => $this->calcAutoBill($invoice),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -799,6 +809,29 @@ trait GenerateMigrationResources
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function calcAutoBillEnabled($invoice)
|
||||||
|
{
|
||||||
|
if($invoice->auto_bill == 1)
|
||||||
|
return 'off';
|
||||||
|
elseif($invoice->auto_bill == 2)
|
||||||
|
return 'optin';
|
||||||
|
elseif($invoice->auto_bill == 3)
|
||||||
|
return 'optout';
|
||||||
|
elseif($invoice->auto_bill == 4)
|
||||||
|
return 'always';
|
||||||
|
else
|
||||||
|
return 'off';
|
||||||
|
}
|
||||||
|
|
||||||
|
private function calcAutoBill($invoice)
|
||||||
|
{
|
||||||
|
if($invoice->auto_bill == 4)
|
||||||
|
return 1;
|
||||||
|
|
||||||
|
return $invoice->client_enable_auto_bill;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
private function getNextSendDateForMigration($invoice)
|
private function getNextSendDateForMigration($invoice)
|
||||||
{
|
{
|
||||||
|
|
||||||
@ -1178,8 +1211,6 @@ trait GenerateMigrationResources
|
|||||||
|
|
||||||
public function getQuotes()
|
public function getQuotes()
|
||||||
{
|
{
|
||||||
info("get quotes");
|
|
||||||
|
|
||||||
|
|
||||||
$transformed = [];
|
$transformed = [];
|
||||||
|
|
||||||
@ -1188,6 +1219,8 @@ trait GenerateMigrationResources
|
|||||||
->withTrashed()
|
->withTrashed()
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
info("get quotes => " . $quotes->count());
|
||||||
|
|
||||||
foreach ($quotes as $quote) {
|
foreach ($quotes as $quote) {
|
||||||
$transformed[] = [
|
$transformed[] = [
|
||||||
'id' => $quote->id,
|
'id' => $quote->id,
|
||||||
@ -1213,7 +1246,7 @@ trait GenerateMigrationResources
|
|||||||
'tax_name2' => $quote->tax_name2,
|
'tax_name2' => $quote->tax_name2,
|
||||||
'tax_rate1' => $quote->tax_rate1,
|
'tax_rate1' => $quote->tax_rate1,
|
||||||
'tax_rate2' => $quote->tax_rate2,
|
'tax_rate2' => $quote->tax_rate2,
|
||||||
'invoice_id' => $quote->quote_invoice_id,
|
'invoice_id' => Invoice::getPrivateId($quote->quote_invoice_id),
|
||||||
'custom_surcharge1' => $quote->custom_value1 ?: '',
|
'custom_surcharge1' => $quote->custom_value1 ?: '',
|
||||||
'custom_surcharge2' => $quote->custom_value2 ?: '',
|
'custom_surcharge2' => $quote->custom_value2 ?: '',
|
||||||
'custom_value1' => $quote->custom_text_value1 ?: '',
|
'custom_value1' => $quote->custom_text_value1 ?: '',
|
||||||
@ -1263,7 +1296,6 @@ trait GenerateMigrationResources
|
|||||||
|
|
||||||
public function getPayments()
|
public function getPayments()
|
||||||
{
|
{
|
||||||
info("get payments");
|
|
||||||
|
|
||||||
$transformed = [];
|
$transformed = [];
|
||||||
|
|
||||||
@ -1272,6 +1304,9 @@ trait GenerateMigrationResources
|
|||||||
->withTrashed()
|
->withTrashed()
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
info("get payments => " . $payments->count());
|
||||||
|
|
||||||
|
|
||||||
foreach ($payments as $payment) {
|
foreach ($payments as $payment) {
|
||||||
$transformed[] = [
|
$transformed[] = [
|
||||||
'id' => $payment->id,
|
'id' => $payment->id,
|
||||||
@ -1399,12 +1434,13 @@ trait GenerateMigrationResources
|
|||||||
|
|
||||||
private function getCredits()
|
private function getCredits()
|
||||||
{
|
{
|
||||||
info("get credits");
|
|
||||||
|
|
||||||
$credits = Credit::where('account_id', $this->account->id)->where('balance', '>', 0)->whereIsDeleted(false)
|
$credits = Credit::where('account_id', $this->account->id)->where('balance', '>', 0)->whereIsDeleted(false)
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
info("get credits => " . $credits->count());
|
||||||
|
|
||||||
$transformed = [];
|
$transformed = [];
|
||||||
|
|
||||||
foreach ($credits as $credit) {
|
foreach ($credits as $credit) {
|
||||||
@ -1429,10 +1465,12 @@ trait GenerateMigrationResources
|
|||||||
|
|
||||||
private function getDocuments()
|
private function getDocuments()
|
||||||
{
|
{
|
||||||
info("get documents");
|
|
||||||
|
|
||||||
$documents = Document::where('account_id', $this->account->id)->get();
|
$documents = Document::where('account_id', $this->account->id)->get();
|
||||||
|
|
||||||
|
info("get documents => " . $documents->count());
|
||||||
|
|
||||||
|
|
||||||
$transformed = [];
|
$transformed = [];
|
||||||
|
|
||||||
foreach ($documents as $document) {
|
foreach ($documents as $document) {
|
||||||
@ -1484,10 +1522,11 @@ trait GenerateMigrationResources
|
|||||||
|
|
||||||
private function getCompanyGateways()
|
private function getCompanyGateways()
|
||||||
{
|
{
|
||||||
info("get get company gateways");
|
|
||||||
|
|
||||||
$account_gateways = AccountGateway::where('account_id', $this->account->id)->withTrashed()->get();
|
$account_gateways = AccountGateway::where('account_id', $this->account->id)->withTrashed()->get();
|
||||||
|
|
||||||
|
info("get get company gateways => " . $account_gateways->count());
|
||||||
|
|
||||||
$transformed = [];
|
$transformed = [];
|
||||||
|
|
||||||
foreach ($account_gateways as $account_gateway) {
|
foreach ($account_gateways as $account_gateway) {
|
||||||
@ -1684,11 +1723,10 @@ trait GenerateMigrationResources
|
|||||||
private function getClientGatewayTokens()
|
private function getClientGatewayTokens()
|
||||||
{
|
{
|
||||||
|
|
||||||
info("get client gateway tokens");
|
|
||||||
|
|
||||||
|
|
||||||
$payment_methods = PaymentMethod::where('account_id', $this->account->id)->withTrashed()->get();
|
$payment_methods = PaymentMethod::where('account_id', $this->account->id)->withTrashed()->get();
|
||||||
|
|
||||||
|
info("get client gateway tokens => " . $payment_methods->count());
|
||||||
|
|
||||||
$transformed = [];
|
$transformed = [];
|
||||||
|
|
||||||
$is_default = true;
|
$is_default = true;
|
||||||
@ -1720,11 +1758,11 @@ trait GenerateMigrationResources
|
|||||||
|
|
||||||
private function getPaymentTerms()
|
private function getPaymentTerms()
|
||||||
{
|
{
|
||||||
info("get payment terms");
|
|
||||||
|
|
||||||
|
|
||||||
$payment_terms = PaymentTerm::where('account_id', 0)->orWhere('account_id', $this->account->id)->withTrashed()->get();
|
$payment_terms = PaymentTerm::where('account_id', 0)->orWhere('account_id', $this->account->id)->withTrashed()->get();
|
||||||
|
|
||||||
|
info("get payment terms => " . $payment_terms->count());
|
||||||
|
|
||||||
$transformed = [];
|
$transformed = [];
|
||||||
|
|
||||||
foreach($payment_terms as $payment_term)
|
foreach($payment_terms as $payment_term)
|
||||||
@ -1751,10 +1789,10 @@ trait GenerateMigrationResources
|
|||||||
|
|
||||||
private function getTaskStatuses()
|
private function getTaskStatuses()
|
||||||
{
|
{
|
||||||
info("get task statuses");
|
|
||||||
|
|
||||||
$task_statuses = TaskStatus::where('account_id', $this->account->id)->withTrashed()->get();
|
$task_statuses = TaskStatus::where('account_id', $this->account->id)->withTrashed()->get();
|
||||||
|
|
||||||
|
info("get task statuses => " . $task_statuses->count());
|
||||||
|
|
||||||
if($task_statuses->count() == 0)
|
if($task_statuses->count() == 0)
|
||||||
{
|
{
|
||||||
$defaults = [
|
$defaults = [
|
||||||
@ -1797,10 +1835,10 @@ trait GenerateMigrationResources
|
|||||||
|
|
||||||
private function getExpenseCategories()
|
private function getExpenseCategories()
|
||||||
{
|
{
|
||||||
info("get expense categories");
|
|
||||||
|
|
||||||
$expense_categories = ExpenseCategory::where('account_id', $this->account->id)->withTrashed()->get();
|
$expense_categories = ExpenseCategory::where('account_id', $this->account->id)->withTrashed()->get();
|
||||||
|
|
||||||
|
info("get expense categories => " . $expense_categories->count());
|
||||||
|
|
||||||
$transformed = [];
|
$transformed = [];
|
||||||
|
|
||||||
foreach ($expense_categories as $category)
|
foreach ($expense_categories as $category)
|
||||||
@ -1822,10 +1860,10 @@ trait GenerateMigrationResources
|
|||||||
|
|
||||||
private function getExpenses()
|
private function getExpenses()
|
||||||
{
|
{
|
||||||
info("get expenses");
|
|
||||||
|
|
||||||
$expenses = Expense::where('account_id', $this->account->id)->withTrashed()->get();
|
$expenses = Expense::where('account_id', $this->account->id)->withTrashed()->get();
|
||||||
|
|
||||||
|
info("get expenses => " . $expenses->count());
|
||||||
|
|
||||||
$transformed = [];
|
$transformed = [];
|
||||||
|
|
||||||
foreach ($expenses as $expense)
|
foreach ($expenses as $expense)
|
||||||
@ -1877,13 +1915,13 @@ trait GenerateMigrationResources
|
|||||||
|
|
||||||
private function getTasks()
|
private function getTasks()
|
||||||
{
|
{
|
||||||
info("get tasks");
|
|
||||||
|
|
||||||
|
|
||||||
$tasks = Task::where('account_id', $this->account->id)
|
$tasks = Task::where('account_id', $this->account->id)
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
info("get tasks => " . $tasks->count());
|
||||||
|
|
||||||
$transformed = [];
|
$transformed = [];
|
||||||
|
|
||||||
foreach ($tasks as $task)
|
foreach ($tasks as $task)
|
||||||
@ -1920,12 +1958,14 @@ trait GenerateMigrationResources
|
|||||||
|
|
||||||
private function getProjects()
|
private function getProjects()
|
||||||
{
|
{
|
||||||
info("get projects");
|
|
||||||
|
|
||||||
$projects = Project::where('account_id', $this->account->id)
|
$projects = Project::where('account_id', $this->account->id)
|
||||||
->withTrashed()
|
->withTrashed()
|
||||||
->get();
|
->get();
|
||||||
|
|
||||||
|
info("get projects => " . $projects);
|
||||||
|
|
||||||
|
|
||||||
$transformed = [];
|
$transformed = [];
|
||||||
|
|
||||||
foreach ($projects as $project)
|
foreach ($projects as $project)
|
||||||
@ -1962,10 +2002,10 @@ trait GenerateMigrationResources
|
|||||||
|
|
||||||
protected function getVendors()
|
protected function getVendors()
|
||||||
{
|
{
|
||||||
info("get vendors");
|
|
||||||
|
|
||||||
$vendor_query = Vendor::where('account_id', $this->account->id)->withTrashed()->get();
|
$vendor_query = Vendor::where('account_id', $this->account->id)->withTrashed()->get();
|
||||||
|
|
||||||
|
info("get vendors => " . $vendor_query->count());
|
||||||
|
|
||||||
$vendors = [];
|
$vendors = [];
|
||||||
|
|
||||||
foreach ($vendor_query as $vendor) {
|
foreach ($vendor_query as $vendor) {
|
||||||
@ -2009,7 +2049,7 @@ trait GenerateMigrationResources
|
|||||||
|
|
||||||
protected function getVendorContacts($contacts)
|
protected function getVendorContacts($contacts)
|
||||||
{
|
{
|
||||||
info("get vendor contacts");
|
info("get vendor contacts => " . $contacts->count());
|
||||||
|
|
||||||
$transformed = [];
|
$transformed = [];
|
||||||
|
|
||||||
@ -2084,8 +2124,8 @@ trait GenerateMigrationResources
|
|||||||
}
|
}
|
||||||
|
|
||||||
$fees_and_limits = new \stdClass();
|
$fees_and_limits = new \stdClass();
|
||||||
$fees_and_limits->min_limit = $ags->min_limit ?: -1;
|
$fees_and_limits->min_limit = $ags->min_limit > 0 ? $ags->min_limit : -1;
|
||||||
$fees_and_limits->max_limit = $ags->max_limit ?: -1;
|
$fees_and_limits->max_limit = $ags->max_limit > 0 ? $ags->max_limit : -1;
|
||||||
$fees_and_limits->fee_amount = $ags->fee_amount;
|
$fees_and_limits->fee_amount = $ags->fee_amount;
|
||||||
$fees_and_limits->fee_percent = $ags->fee_percent;
|
$fees_and_limits->fee_percent = $ags->fee_percent;
|
||||||
$fees_and_limits->fee_tax_name1 = $ags->tax_name1;
|
$fees_and_limits->fee_tax_name1 = $ags->tax_name1;
|
||||||
|
Loading…
Reference in New Issue
Block a user