Category export missing parent_id column ( 866abh63h )
This commit is contained in:
parent
64d07cb001
commit
c7a2fffd8c
|
|
@ -12,12 +12,20 @@ class Categories extends Export
|
|||
return Model::collectForExport($this->ids);
|
||||
}
|
||||
|
||||
public function map($model): array
|
||||
{
|
||||
$model->parent_name = Model::find($model->parent_id)?->name;
|
||||
|
||||
return parent::map($model);
|
||||
}
|
||||
|
||||
public function fields(): array
|
||||
{
|
||||
return [
|
||||
'name',
|
||||
'type',
|
||||
'color',
|
||||
'parent_name',
|
||||
'enabled',
|
||||
];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,10 @@ class Categories extends Import
|
|||
|
||||
public function model(array $row)
|
||||
{
|
||||
if (self::hasRow($row)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
|
|
@ -20,6 +24,7 @@ class Categories extends Import
|
|||
$row = parent::map($row);
|
||||
|
||||
$row['type'] = $this->getCategoryType($row['type']);
|
||||
$row['parent_id'] = $this->getParentId($row) ?? null;
|
||||
|
||||
return $row;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,6 +16,10 @@ class Taxes extends Import
|
|||
return;
|
||||
}
|
||||
|
||||
if (self::hasRow($row)) {
|
||||
return;
|
||||
}
|
||||
|
||||
return new Model($row);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -212,6 +212,39 @@ class Category extends Model
|
|||
return $query->withoutGlobalScope(new Scope);
|
||||
}
|
||||
|
||||
/**
|
||||
* Scope to export the rows of the current page filtered and sorted.
|
||||
*
|
||||
* @param \Illuminate\Database\Eloquent\Builder $query
|
||||
* @param $ids
|
||||
* @param $sort
|
||||
* @param $id_field
|
||||
*
|
||||
* @return \Illuminate\Support\LazyCollection
|
||||
*/
|
||||
public function scopeCollectForExport($query, $ids = [], $sort = 'name', $id_field = 'id')
|
||||
{
|
||||
$request = request();
|
||||
|
||||
if (!empty($ids)) {
|
||||
$query->whereIn($id_field, (array) $ids);
|
||||
}
|
||||
|
||||
$search = $request->get('search');
|
||||
|
||||
$query->withSubcategory();
|
||||
|
||||
$query->usingSearchString($search)->sortable($sort);
|
||||
|
||||
$page = (int) $request->get('page');
|
||||
$limit = (int) $request->get('limit', setting('default.list_limit', '25'));
|
||||
$offset = $page ? ($page - 1) * $limit : 0;
|
||||
|
||||
$query->offset($offset)->limit($limit);
|
||||
|
||||
return $query->cursor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the hex code of the color.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -157,7 +157,7 @@ trait Import
|
|||
{
|
||||
$id = isset($row['parent_id']) ? $row['parent_id'] : null;
|
||||
|
||||
if (empty($row['parent_number'])) {
|
||||
if (empty($row['parent_number']) && empty($row['parent_name'])){
|
||||
return null;
|
||||
}
|
||||
|
||||
|
|
@ -169,6 +169,10 @@ trait Import
|
|||
$id = Transaction::number($row['parent_number'])->pluck('id')->first();
|
||||
}
|
||||
|
||||
if (empty($id) && isset($row['parent_name'])) {
|
||||
$id = Category::type($row['type'])->withSubCategory()->where('name', $row['parent_name'])->pluck('id')->first();
|
||||
}
|
||||
|
||||
return is_null($id) ? $id : (int) $id;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue