mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2025-06-03 07:34:34 -04:00
Add withTrashed() for queries in migration
This commit is contained in:
parent
9f420ba084
commit
388c0e8467
@ -98,6 +98,24 @@ class MigrationController extends BaseController
|
|||||||
return response()->json(['message' => 'Company purged'], 200);
|
return response()->json(['message' => 'Company purged'], 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function purgeCompanyWithForceFlag(Company $company)
|
||||||
|
{
|
||||||
|
$account = $company->account;
|
||||||
|
$company_id = $company->id;
|
||||||
|
|
||||||
|
$company->delete();
|
||||||
|
|
||||||
|
/*Update the new default company if necessary*/
|
||||||
|
if ($company_id == $account->default_company_id && $account->companies->count() >= 1) {
|
||||||
|
$new_default_company = $account->companies->first();
|
||||||
|
|
||||||
|
if ($new_default_company) {
|
||||||
|
$account->default_company_id = $new_default_company->id;
|
||||||
|
$account->save();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Purge Company but save settings.
|
* Purge Company but save settings.
|
||||||
*
|
*
|
||||||
@ -241,7 +259,7 @@ class MigrationController extends BaseController
|
|||||||
|
|
||||||
// If there's existing company and force ** is provided ** - purge the company and migrate again.
|
// If there's existing company and force ** is provided ** - purge the company and migrate again.
|
||||||
if ($checks['existing_company'] == true && $checks['force'] == true) {
|
if ($checks['existing_company'] == true && $checks['force'] == true) {
|
||||||
$this->purgeCompany($existing_company);
|
$this->purgeCompanyWithForceFlag($existing_company);
|
||||||
|
|
||||||
$account = auth()->user()->account;
|
$account = auth()->user()->account;
|
||||||
$fresh_company = (new ImportMigrations())->getCompany($account);
|
$fresh_company = (new ImportMigrations())->getCompany($account);
|
||||||
|
@ -834,6 +834,10 @@ class Import implements ShouldQueue
|
|||||||
'new' => $payment->id,
|
'new' => $payment->id,
|
||||||
],
|
],
|
||||||
];
|
];
|
||||||
|
|
||||||
|
//depending on the status, we do a final action.
|
||||||
|
$payment = $this->updatePaymentForStatus($payment, $modified['status_id']);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Payment::reguard();
|
Payment::reguard();
|
||||||
@ -843,6 +847,45 @@ class Import implements ShouldQueue
|
|||||||
$payment_repository = null;
|
$payment_repository = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private function updatePaymentForStatus($payment, $status_id) :Payment
|
||||||
|
{
|
||||||
|
// define('PAYMENT_STATUS_PENDING', 1);
|
||||||
|
// define('PAYMENT_STATUS_VOIDED', 2);
|
||||||
|
// define('PAYMENT_STATUS_FAILED', 3);
|
||||||
|
// define('PAYMENT_STATUS_COMPLETED', 4);
|
||||||
|
// define('PAYMENT_STATUS_PARTIALLY_REFUNDED', 5);
|
||||||
|
// define('PAYMENT_STATUS_REFUNDED', 6);
|
||||||
|
|
||||||
|
switch ($status_id) {
|
||||||
|
case 1:
|
||||||
|
return $payment;
|
||||||
|
break;
|
||||||
|
case 2:
|
||||||
|
return $payment->service()->deletePayment();
|
||||||
|
break;
|
||||||
|
case 3:
|
||||||
|
return $payment->service()->deletePayment();
|
||||||
|
break;
|
||||||
|
case 4:
|
||||||
|
return $payment;
|
||||||
|
break;
|
||||||
|
case 5:
|
||||||
|
$payment->status_id = Payment::STATUS_PARTIALLY_REFUNDED;
|
||||||
|
$payment->save();
|
||||||
|
return $payment;
|
||||||
|
break;
|
||||||
|
case 6:
|
||||||
|
$payment->status_id = Payment::STATUS_REFUNDED;
|
||||||
|
$payment->save();
|
||||||
|
return $payment;
|
||||||
|
break;
|
||||||
|
|
||||||
|
default:
|
||||||
|
return $payment;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private function processDocuments(array $data): void
|
private function processDocuments(array $data): void
|
||||||
{
|
{
|
||||||
Document::unguard();
|
Document::unguard();
|
||||||
|
@ -162,9 +162,9 @@ class BaseRepository
|
|||||||
$class = new ReflectionClass($model);
|
$class = new ReflectionClass($model);
|
||||||
|
|
||||||
if (array_key_exists('client_id', $data)) {
|
if (array_key_exists('client_id', $data)) {
|
||||||
$client = Client::find($data['client_id']);
|
$client = Client::where('id', $data['client_id'])->withTrashed()->first();
|
||||||
} else {
|
} else {
|
||||||
$client = Client::find($model->client_id);
|
$client = Client::where('id', $model->client_id)->withTrashed()->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
$state = [];
|
$state = [];
|
||||||
|
@ -46,9 +46,9 @@ class InvoiceMigrationRepository extends BaseRepository
|
|||||||
$class = new ReflectionClass($model);
|
$class = new ReflectionClass($model);
|
||||||
|
|
||||||
if (array_key_exists('client_id', $data)) {
|
if (array_key_exists('client_id', $data)) {
|
||||||
$client = Client::find($data['client_id']);
|
$client = Client::where('id', $data['client_id'])->withTrashed()->first();
|
||||||
} else {
|
} else {
|
||||||
$client = Client::find($model->client_id);
|
$client = Client::where('id', $model->client_id)->withTrashed()->first();
|
||||||
}
|
}
|
||||||
|
|
||||||
$state = [];
|
$state = [];
|
||||||
|
@ -164,7 +164,7 @@ class PaymentMigrationRepository extends BaseRepository
|
|||||||
*/
|
*/
|
||||||
private function processExchangeRates($data, $payment)
|
private function processExchangeRates($data, $payment)
|
||||||
{
|
{
|
||||||
$client = Client::find($data['client_id']);
|
$client = Client::find($data['client_id'])->withTrashed();
|
||||||
|
|
||||||
$client_currency = $client->getSetting('currency_id');
|
$client_currency = $client->getSetting('currency_id');
|
||||||
$company_currency = $client->company->settings->currency_id;
|
$company_currency = $client->company->settings->currency_id;
|
||||||
|
@ -28,7 +28,12 @@ trait CleanLineItems
|
|||||||
$cleaned_items = [];
|
$cleaned_items = [];
|
||||||
|
|
||||||
foreach ($items as $item) {
|
foreach ($items as $item) {
|
||||||
|
|
||||||
|
if(is_array($item))
|
||||||
|
continue;
|
||||||
|
|
||||||
$cleaned_items[] = $this->cleanLineItem($item);
|
$cleaned_items[] = $this->cleanLineItem($item);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return $cleaned_items;
|
return $cleaned_items;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user