Include bank transactions and bank integrations in company import/exports

This commit is contained in:
David Bomba 2022-11-22 16:14:07 +11:00
parent 1bd1d482ec
commit 08ca5ddb72
3 changed files with 77 additions and 9 deletions

View File

@ -293,7 +293,7 @@ class CompanyExport implements ShouldQueue
$this->export_data['payments'] = $this->company->payments()->orderBy('number', 'DESC')->cursor()->map(function ($payment){ $this->export_data['payments'] = $this->company->payments()->orderBy('number', 'DESC')->cursor()->map(function ($payment){
$payment = $this->transformBasicEntities($payment); $payment = $this->transformBasicEntities($payment);
$payment = $this->transformArrayOfKeys($payment, ['client_id','project_id', 'vendor_id', 'client_contact_id', 'invitation_id', 'company_gateway_id']); $payment = $this->transformArrayOfKeys($payment, ['client_id','project_id', 'vendor_id', 'client_contact_id', 'invitation_id', 'company_gateway_id', 'transaction_id']);
$payment->paymentables = $this->transformPaymentable($payment); $payment->paymentables = $this->transformPaymentable($payment);
@ -456,7 +456,6 @@ class CompanyExport implements ShouldQueue
})->all(); })->all();
$this->export_data['purchase_order_invitations'] = PurchaseOrderInvitation::where('company_id', $this->company->id)->withTrashed()->cursor()->map(function ($purchase_order){ $this->export_data['purchase_order_invitations'] = PurchaseOrderInvitation::where('company_id', $this->company->id)->withTrashed()->cursor()->map(function ($purchase_order){
$purchase_order = $this->transformArrayOfKeys($purchase_order, ['company_id', 'user_id', 'vendor_contact_id', 'purchase_order_id']); $purchase_order = $this->transformArrayOfKeys($purchase_order, ['company_id', 'user_id', 'vendor_contact_id', 'purchase_order_id']);
@ -466,6 +465,21 @@ class CompanyExport implements ShouldQueue
})->all(); })->all();
$this->export_data['bank_integrations'] = $this->company->bank_integrations()->orderBy('id', 'ASC')->cursor()->map(function ($bank_integration){
$bank_integration = $this->transformArrayOfKeys($bank_integration, ['account_id','company_id', 'user_id']);
return $bank_integration->makeVisible(['id','user_id','company_id','account_id']);
})->all();
$this->export_data['bank_transactions'] = $this->company->bank_transactions()->orderBy('id', 'ASC')->cursor()->map(function ($bank_transaction){
$bank_transaction = $this->transformArrayOfKeys($bank_transaction, ['company_id', 'user_id','bank_integration_id','expense_id','category_id','ninja_category_id','vendor_id']);
return $bank_transaction->makeVisible(['id','user_id','company_id']);
})->all();
//write to tmp and email to owner(); //write to tmp and email to owner();
@ -517,9 +531,6 @@ class CompanyExport implements ShouldQueue
$path = 'backups'; $path = 'backups';
// if(!Storage::disk(config('filesystems.default'))->exists($path))
// Storage::disk(config('filesystems.default'))->makeDirectory($path, 0775);
$zip_path = public_path('storage/backups/'.$file_name); $zip_path = public_path('storage/backups/'.$file_name);
$zip = new \ZipArchive(); $zip = new \ZipArchive();

View File

@ -24,6 +24,8 @@ use App\Mail\Import\CompanyImportFailure;
use App\Mail\Import\ImportCompleted; use App\Mail\Import\ImportCompleted;
use App\Models\Activity; use App\Models\Activity;
use App\Models\Backup; use App\Models\Backup;
use App\Models\BankIntegration;
use App\Models\BankTransaction;
use App\Models\Client; use App\Models\Client;
use App\Models\ClientContact; use App\Models\ClientContact;
use App\Models\ClientGatewayToken; use App\Models\ClientGatewayToken;
@ -142,15 +144,16 @@ class CompanyImport implements ShouldQueue
'expenses', 'expenses',
'tasks', 'tasks',
'payments', 'payments',
// 'activities',
// 'backups',
'company_ledger', 'company_ledger',
'designs', 'designs',
'documents', 'documents',
'webhooks', 'webhooks',
'system_logs', 'system_logs',
'purchase_orders', 'purchase_orders',
'purchase_order_invitations' 'purchase_order_invitations',
'bank_integrations',
'bank_transactions',
'payments',
]; ];
private $company_properties = [ private $company_properties = [
@ -527,6 +530,37 @@ class CompanyImport implements ShouldQueue
} }
private function import_bank_integrations()
{
$this->genericImport(BankIntegration::class,
['assigned_user_id','account_id', 'company_id', 'id', 'hashed_id'],
[
['users' => 'user_id'],
],
'bank_integrations',
'description');
return $this;
}
private function import_bank_transactions()
{
$this->genericImport(BankTransaction::class,
['assigned_user_id','company_id', 'id', 'hashed_id', 'user_id'],
[
['users' => 'user_id'],
['expenses' => 'expense_id'],
['vendors' => 'vendor_id'],
['expense_categories' => 'ninja_category_id'],
['expense_categories' => 'category_id'],
['bank_integrations' => 'bank_integration_id']
],
'bank_transactions',
null);
return $this;
}
private function import_recurring_expenses() private function import_recurring_expenses()
{ {
//unset / transforms / object_property / match_key //unset / transforms / object_property / match_key
@ -979,6 +1013,7 @@ class CompanyImport implements ShouldQueue
['vendors' => 'vendor_id'], ['vendors' => 'vendor_id'],
['invoice_invitations' => 'invitation_id'], ['invoice_invitations' => 'invitation_id'],
['company_gateways' => 'company_gateway_id'], ['company_gateways' => 'company_gateway_id'],
['bank_transactions' => 'transaction_id'],
], ],
'payments', 'payments',
'number'); 'number');
@ -1569,6 +1604,28 @@ class CompanyImport implements ShouldQueue
$obj_array, $obj_array,
); );
} }
elseif($class == 'App\Models\BankIntegration'){
$new_obj = new BankIntegration();
$new_obj->company_id = $this->company->id;
$new_obj->account_id = $this->account->id;
$new_obj->fill($obj_array);
$new_obj->save(['timestamps' => false]);
}
elseif($class == 'App\Models\BankTransaction'){
$new_obj = new BankTransaction();
$new_obj->company_id = $this->company->id;
$obj_array['invoice_ids'] = collect(explode(",",$obj_array['invoice_ids']))->map(function ($id) {
return $this->transformId('invoices', $id);
})->map(function ($encodeable){
return $this->encodePrimaryKey($encodeable);
})->implode(",");
$new_obj->fill($obj_array);
$new_obj->save(['timestamps' => false]);
}
else{ else{
$new_obj = $class::withTrashed()->firstOrNew( $new_obj = $class::withTrashed()->firstOrNew(
[$match_key => $obj->{$match_key}, 'company_id' => $this->company->id], [$match_key => $obj->{$match_key}, 'company_id' => $this->company->id],

View File

@ -257,7 +257,7 @@
overflow-wrap: break-word; overflow-wrap: break-word;
} }
.stamp { .stamp {
transform: rotate(12deg); transform: rotate(12deg);
color: #555; color: #555;
font-size: 3rem; font-size: 3rem;