Skip to content

Commit

Permalink
added parent id field to import and export
Browse files Browse the repository at this point in the history
  • Loading branch information
CihanSenturk committed Jul 20, 2023
1 parent 7768280 commit 6a07f8a
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions app/Exports/Banking/Transactions.php
Expand Up @@ -20,6 +20,7 @@ public function map($model): array
$model->contact_email = $model->contact->email;
$model->category_name = $model->category->name;
$model->invoice_bill_number = $model->document->document_number ?? 0;
$model->parent_number = Model::isRecurring()->find($model->parent_id)?->number;

return parent::map($model);
}
Expand All @@ -41,6 +42,7 @@ public function fields(): array
'payment_method',
'reference',
'reconciled',
'parent_number',
];
}

Expand Down
2 changes: 2 additions & 0 deletions app/Exports/Purchases/Sheets/Bills.php
Expand Up @@ -26,6 +26,7 @@ public function map($model): array
$model->bill_number = $model->document_number;
$model->billed_at = $model->issued_at;
$model->contact_country = $country;
$model->parent_number = Model::billRecurring()->find($model->parent_id)?->document_number ?? null;

return parent::map($model);
}
Expand All @@ -52,6 +53,7 @@ public function fields(): array
'contact_zip_code',
'contact_city',
'notes',
'parent_number',
];
}

Expand Down
2 changes: 2 additions & 0 deletions app/Exports/Sales/Sheets/Invoices.php
Expand Up @@ -26,6 +26,7 @@ public function map($model): array
$model->invoice_number = $model->document_number;
$model->invoiced_at = $model->issued_at;
$model->contact_country = $country;
$model->parent_number = Model::invoiceRecurring()->find($model->parent_id)?->document_number;

return parent::map($model);
}
Expand Down Expand Up @@ -53,6 +54,7 @@ public function fields(): array
'contact_city',
'notes',
'footer',
'parent_number',
];
}

Expand Down
1 change: 1 addition & 0 deletions app/Imports/Banking/Transactions.php
Expand Up @@ -24,6 +24,7 @@ public function map($row): array
$row['category_id'] = $this->getCategoryId($row);
$row['contact_id'] = $this->getContactId($row);
$row['document_id'] = $this->getDocumentId($row);
$row['parent_id'] = $this->getParentId($row);

return $row;
}
Expand Down
1 change: 1 addition & 0 deletions app/Imports/Purchases/Sheets/Bills.php
Expand Up @@ -35,6 +35,7 @@ public function map($row): array
$row['currency_code'] = $this->getCurrencyCode($row);
$row['type'] = Model::BILL_TYPE;
$row['contact_country'] = !empty($country) ? $country : null;
$row['parent_id'] = $this->getParentId($row);

return $row;
}
Expand Down
1 change: 1 addition & 0 deletions app/Imports/Sales/Sheets/Invoices.php
Expand Up @@ -35,6 +35,7 @@ public function map($row): array
$row['currency_code'] = $this->getCurrencyCode($row);
$row['type'] = Model::INVOICE_TYPE;
$row['contact_country'] = !empty($country) ? $country : null;
$row['parent_id'] = $this->getParentId($row);

return $row;
}
Expand Down
16 changes: 16 additions & 0 deletions app/Traits/Import.php
Expand Up @@ -16,6 +16,7 @@
use App\Jobs\Setting\CreateTax;
use App\Models\Auth\User;
use App\Models\Banking\Account;
use App\Models\Banking\Transaction;
use App\Models\Common\Contact;
use App\Models\Common\Item;
use App\Models\Document\Document;
Expand Down Expand Up @@ -149,6 +150,21 @@ public function getDocumentId($row)
return is_null($id) ? $id : (int) $id;
}

public function getParentId($row)
{
$id = isset($row['parent_id']) ? $row['parent_id'] : null;

if (empty($id) && isset($row['document_number']) && !empty($row['parent_number'])) {
$id = Document::number($row['parent_number'])->pluck('id')->first();
}

if (empty($id) && isset($row['number']) && !empty($row['parent_number'])) {
$id = Transaction::number($row['parent_number'])->pluck('id')->first();
}

return is_null($id) ? $id : (int) $id;
}

public function getItemId($row, $type = null)
{
$id = isset($row['item_id']) ? $row['item_id'] : null;
Expand Down

0 comments on commit 6a07f8a

Please sign in to comment.