Skip to content

Commit

Permalink
close #2923 Enhancement: Missing document item description import/exp…
Browse files Browse the repository at this point in the history
…ort excel
  • Loading branch information
cuneytsenturk committed Mar 9, 2023
1 parent a1da29d commit dfda255
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 2 deletions.
3 changes: 2 additions & 1 deletion app/Exports/Purchases/Sheets/BillItems.php
Expand Up @@ -22,6 +22,7 @@ public function map($model): array

$model->bill_number = $document->document_number;
$model->item_name = $model->item->name;
$model->item_description = $model->item->description;
$model->item_type = $model->item->type;

return parent::map($model);
Expand All @@ -32,7 +33,7 @@ public function fields(): array
return [
'bill_number',
'item_name',
'item_type',
'item_description',
'quantity',
'price',
'total',
Expand Down
2 changes: 2 additions & 0 deletions app/Exports/Sales/Sheets/InvoiceItems.php
Expand Up @@ -22,6 +22,7 @@ public function map($model): array

$model->invoice_number = $document->document_number;
$model->item_name = $model->item->name;
$model->item_description = $model->item->description;
$model->item_type = $model->item->type;

return parent::map($model);
Expand All @@ -32,6 +33,7 @@ public function fields(): array
return [
'invoice_number',
'item_name',
'item_description',
'item_type',
'quantity',
'price',
Expand Down
2 changes: 2 additions & 0 deletions app/Imports/Purchases/Sheets/BillItems.php
Expand Up @@ -34,6 +34,8 @@ public function map($row): array
$row['name'] = $row['item_name'];
}

$row['description'] = !empty($row['item_description']) ? $row['item_description'] : '';

$row['tax'] = (double) $row['tax'];
$row['tax_id'] = 0;
$row['type'] = Document::BILL_TYPE;
Expand Down
4 changes: 3 additions & 1 deletion app/Imports/Sales/Sheets/InvoiceItems.php
Expand Up @@ -28,12 +28,14 @@ public function map($row): array

$row['document_id'] = (int) Document::invoice()->number($row['invoice_number'])->pluck('id')->first();

if (empty($row['item_id']) && !empty($row['item_name'])) {
if (empty($row['item_id']) && ! empty($row['item_name'])) {
$row['item_id'] = $this->getItemIdFromName($row);

$row['name'] = $row['item_name'];
}

$row['description'] = !empty($row['item_description']) ? $row['item_description'] : '';

$row['tax'] = (double) $row['tax'];
$row['tax_id'] = 0;
$row['type'] = Document::INVOICE_TYPE;
Expand Down
1 change: 1 addition & 0 deletions app/Traits/Import.php
Expand Up @@ -332,6 +332,7 @@ public function getItemIdFromName($row)
'company_id' => company_id(),
'type' => $row['item_type'],
'name' => $row['item_name'],
'description' => !empty($row['item_description']) ? $row['item_description'] : null,
'sale_price' => !empty($row['sale_price']) ? $row['sale_price'] : (!empty($row['price']) ? $row['price'] : 0),
'purchase_price' => !empty($row['purchase_price']) ? $row['purchase_price'] : (!empty($row['price']) ? $row['price'] : 0),
'enabled' => 1,
Expand Down

0 comments on commit dfda255

Please sign in to comment.