Check document if exists in update script
This commit is contained in:
parent
84c0b06cda
commit
ad40e1aab8
@ -129,16 +129,18 @@ class Version210 extends Listener
|
|||||||
);
|
);
|
||||||
|
|
||||||
foreach ($invoices as $invoice) {
|
foreach ($invoices as $invoice) {
|
||||||
$documentId = DB::table('documents')
|
$document = DB::table('documents')
|
||||||
->where('document_number', $invoice->invoice_number)
|
->where('document_number', $invoice->invoice_number)
|
||||||
->where('deleted_at', $invoice->deleted_at)
|
->where('deleted_at', $invoice->deleted_at)
|
||||||
->where('company_id', $invoice->company_id)
|
->where('company_id', $invoice->company_id)
|
||||||
->where('type', Document::INVOICE_TYPE)
|
->where('type', Document::INVOICE_TYPE)
|
||||||
->first()
|
->first('id');
|
||||||
->id;
|
|
||||||
|
|
||||||
DB::table('credits_transactions')
|
if ($document) {
|
||||||
->where('id', $invoice->credits_transactions_id)->update(['document_id' => $documentId]);
|
DB::table('credits_transactions')
|
||||||
|
->where('id', $invoice->credits_transactions_id)
|
||||||
|
->update(['document_id' => $document->id]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$credit_notes = DB::table('credits_transactions')
|
$credit_notes = DB::table('credits_transactions')
|
||||||
@ -154,16 +156,18 @@ class Version210 extends Listener
|
|||||||
);
|
);
|
||||||
|
|
||||||
foreach ($credit_notes as $credit_note) {
|
foreach ($credit_notes as $credit_note) {
|
||||||
$documentId = DB::table('documents')
|
$document = DB::table('documents')
|
||||||
->where('document_number', $credit_note->credit_note_number)
|
->where('document_number', $credit_note->credit_note_number)
|
||||||
->where('deleted_at', $credit_note->deleted_at)
|
->where('deleted_at', $credit_note->deleted_at)
|
||||||
->where('company_id', $credit_note->company_id)
|
->where('company_id', $credit_note->company_id)
|
||||||
->where('type', self::CREDIT_NOTE_TYPE)
|
->where('type', self::CREDIT_NOTE_TYPE)
|
||||||
->first()
|
->first('id');
|
||||||
->id;
|
|
||||||
|
|
||||||
DB::table('credits_transactions')
|
if ($document) {
|
||||||
->where('id', $credit_note->credits_transactions_id)->update(['document_id' => $documentId]);
|
DB::table('credits_transactions')
|
||||||
|
->where('id', $credit_note->credits_transactions_id)
|
||||||
|
->update(['document_id' => $document->id]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -235,15 +239,17 @@ class Version210 extends Listener
|
|||||||
$builder->delete();
|
$builder->delete();
|
||||||
}
|
}
|
||||||
|
|
||||||
$documentType = DB::table($new_table)->orderBy('id')->first()->type;
|
|
||||||
|
|
||||||
// To be able to update TYPE_id relations
|
// To be able to update TYPE_id relations
|
||||||
$this->addDocumentIdForeignKeys($documentType);
|
$document = DB::table($new_table)->orderBy('id')->first('type');
|
||||||
|
if ($document) {
|
||||||
|
$this->addDocumentIdForeignKeys($document->type);
|
||||||
|
}
|
||||||
|
|
||||||
// Update relation ids
|
// Update relation ids
|
||||||
DB::table($new_table)
|
$document = DB::table($table)->orderByDesc('id')->first('id');
|
||||||
->orderByDesc('id')
|
if ($document) {
|
||||||
->increment('id', DB::table($table)->orderByDesc('id')->first()->id);
|
DB::table($new_table)->orderByDesc('id')->increment('id', $document->id);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
$insertColumns = collect(Schema::getColumnListing($new_table));
|
$insertColumns = collect(Schema::getColumnListing($new_table));
|
||||||
|
Loading…
x
Reference in New Issue
Block a user