Skip to content

Commit

Permalink
Created Dock
Browse files Browse the repository at this point in the history
  • Loading branch information
TemuulenBM committed Dec 1, 2023
1 parent 017da90 commit 182738f
Show file tree
Hide file tree
Showing 29 changed files with 207 additions and 47 deletions.
1 change: 1 addition & 0 deletions addon/adapters/warehouse-dock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from './pallet';
4 changes: 2 additions & 2 deletions addon/components/cell/product-info.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import Component from '@glimmer/component';
import { action, computed, get } from '@ember/object';

export default class CellProductInfoComponent extends Component {
@computed('args.row', 'args.column.{modelPath}') get product() {
@computed('args.row', 'args.column.modelPath') get product() {
const { column, row } = this.args;

if (typeof column?.modelPath === 'string') {
return get(row, column.modelPath);
}

return row
return row;
}

@action onClick(event) {
Expand Down
3 changes: 0 additions & 3 deletions addon/components/inventory-form-panel.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -96,9 +96,6 @@
</InputGroup>
<InputGroup @name="Batch Quantity" @type="number" @value={{this.inventory.batch.quantity}} />
<InputGroup @name="Batch Number" @type="number" @value={{this.inventory.batch.batch_number}} />
<InputGroup @name="Batch Reason">
<Textarea @value={{this.inventory.batch.reason}} aria-label="Reason" class="w-full form-input" placeholder="Reason" rows={{5}} />
</InputGroup>
</ContentPanel>
</div>
</Overlay::Body>
Expand Down
58 changes: 58 additions & 0 deletions addon/components/warehouse-editor.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -79,4 +79,62 @@
{{/each}}
{{/each}}
</div>
<div class="content-panel mb-2">
<div class="content-panel-header items-center">
<h3 class="text-lg font-semibold dark:text-gray-100">
Docks
</h3>
<Button @text="Add Dock" @icon="plus" @iconPrefix="fas" @onClick={{this.addDock}} />
</div>
<div class="content-panel-body">
{{#each this.warehouse.docks as |dock|}}
<div class="flex flex-row items-center px-4 py-2 border border-gray-700 rounded-md">
<div class="flex flex-row items-center justify-end">
<Button @icon="trash" @type="danger" @onClick={{fn this.removeDock dock}} />
</div>
<div class="p-3">
<div class="grid grid-cols-3 gap-2">
<InputGroup @name="Dock Number" @wrapperClass="col-span-2">
<Input @value={{dock.dock_number}} @type="text" class="w-full form-input" placeholder="Dock Number" />
</InputGroup>
<InputGroup @name="Direction" @wrapperClass="col-span-2">
<Input @value={{dock.direction}} @type="text" class="w-full form-input" placeholder="Direction" />
</InputGroup>
<InputGroup @name="Capacity" @wrapperClass="col-span-2">
<Input @value={{dock.capacity}} @type="text" class="w-full form-input" placeholder="Capacity" />
</InputGroup>
<InputGroup @name="Status">
<div class="fleetbase-model-select fleetbase-power-select ember-model-select">
<PowerSelect
@options={{dock.statusOptions}}
@selected={{dock.status}}
@onChange={{fn (mut dock.status)}}
@placeholder="Select dock status"
@triggerClass="form-select form-input"
as |status|
>
{{smart-humanize status}}
</PowerSelect>
</div>
</InputGroup>
<InputGroup @name="Type">
<div class="fleetbase-model-select fleetbase-power-select ember-model-select">
<PowerSelect
@options={{dock.typeOptions}}
@selected={{dock.type}}
@onChange={{fn (mut dock.type)}}
@placeholder="Select dock type"
@triggerClass="form-select form-input"
as |type|
>
{{smart-humanize type}}
</PowerSelect>
</div>
</InputGroup>
</div>
</div>
</div>
{{/each}}
</div>
</div>
</div>
9 changes: 9 additions & 0 deletions addon/components/warehouse-editor.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,15 @@ export default class WarehouseEditorComponent extends Component {
rack.bins.pushObject(bin);
}

@action addDock() {
const dock = this.store.createRecord('warehouse-dock', { warehouse_uuid: this.warehouse.id });
this.warehouse.docks.pushObject(dock);
}

@action removeDock(dock) {
dock.destroyRecord();
}

@action removeSection(section) {
section.destroyRecord();
}
Expand Down
2 changes: 0 additions & 2 deletions addon/controllers/inventory/index/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ export default class InventoryIndexNewController extends Controller {
@tracked inventory = this.store.createRecord('inventory', {
type: 'pallet-inventory',
meta: {},
batches: [this.store.createRecord('batch')],
});

/**
Expand Down Expand Up @@ -90,7 +89,6 @@ export default class InventoryIndexNewController extends Controller {
this.inventory = this.store.createRecord('inventory', {
type: 'pallet-inventory',
meta: {},
batches: [this.store.createRecord('batch')],
});
}
}
2 changes: 1 addition & 1 deletion addon/controllers/warehouses/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ export default class WarehousesIndexController extends Controller {
* @var {String}
*/
@tracked neighborhood;

@tracked warehouse;

/**
Expand Down
11 changes: 4 additions & 7 deletions addon/controllers/warehouses/index/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,10 @@ export default class WarehousesIndexNewController extends Controller {
meta: {},
sections: [
this.store.createRecord('warehouse-section', {
aisles: [
this.store.createRecord('warehouse-aisle',
{ racks: [
this.store.createRecord('warehouse-rack',
{ bins: [this.store.createRecord('warehouse-bin')]})]
})],
aisles: [this.store.createRecord('warehouse-aisle', { racks: [this.store.createRecord('warehouse-rack', { bins: [this.store.createRecord('warehouse-bin')] })] })],
}),
],
docks: [this.store.createRecord('warehouse-dock')],
});

/**
Expand Down Expand Up @@ -103,9 +99,10 @@ export default class WarehousesIndexNewController extends Controller {
meta: {},
sections: [
this.store.createRecord('warehouse-section', {
aisles: [this.store.createRecord('warehouse-aisle', { racks: [this.store.createRecord('warehouse-rack', {bins: [this.store.createRecord('warehouse-bin')]})] })],
aisles: [this.store.createRecord('warehouse-aisle', { racks: [this.store.createRecord('warehouse-rack', { bins: [this.store.createRecord('warehouse-bin')] })] })],
}),
],
docks: [this.store.createRecord('warehouse-dock')],
});
}
}
1 change: 1 addition & 0 deletions addon/models/batch.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ export default class BatchModel extends Model {
@attr('date') expiry_date_at;
@attr('date') created_at;
@attr('date') updated_at;
@attr('raw') meta;

/** @computed */
@computed('created_at') get createdAgo() {
Expand Down
1 change: 1 addition & 0 deletions addon/models/inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ export default class InventoryModel extends Model {
@attr('number') quantity;
@attr('number') min_quantity;
@attr('number') status;
@attr('raw') meta;

/** @date */
@attr('date') created_at;
Expand Down
1 change: 1 addition & 0 deletions addon/models/warehouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,5 @@ import { hasMany } from '@ember-data/model';

export default class WarehouseModel extends PlaceModel {
@hasMany('warehouse-section') sections;
@hasMany('warehouse-dock') docks;
}
2 changes: 1 addition & 1 deletion addon/routes/inventory/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,6 @@ export default class InventoryIndexRoute extends Route {
};

model(params) {
return this.store.query('inventory', { ...params, with: ['product', 'warehouse', 'batch'] });
return this.store.query('inventory', { ...params, with: ['product', 'warehouse'] });
}
}
2 changes: 1 addition & 1 deletion addon/routes/warehouses/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,6 @@ export default class WarehousesIndexRoute extends Route {
};

model(params) {
return this.store.query('warehouse', { ...params, with: ['sections', 'sections.aisles', 'sections.aisles.racks', 'sections.aisles.racks.bins'] });
return this.store.query('warehouse', { ...params, with: ['sections', 'sections.aisles', 'sections.aisles.racks', 'sections.aisles.racks.bins', 'docks'] });
}
}
4 changes: 4 additions & 0 deletions addon/serializers/warehouse-dock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import ApplicationSerializer from '@fleetbase/ember-core/serializers/application';
import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';

export default class WarehouseDockSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {}
1 change: 1 addition & 0 deletions addon/serializers/warehouse.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ export default class WarehouseSerializer extends ApplicationSerializer.extend(Em
get attrs() {
return {
sections: { embedded: 'always' },
docks: { embedded: 'always' },
};
}
}
1 change: 1 addition & 0 deletions app/adapters/warehouse-dock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@fleetbase/pallet-engine/adapters/warehouse-dock';
1 change: 1 addition & 0 deletions app/serializers/warehouse-dock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export { default } from '@fleetbase/pallet-engine/serializers/warehouse-dock';
23 changes: 0 additions & 23 deletions server/src/Http/Controllers/InventoryController.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,4 @@ public function queryRecord(Request $request)

return IndexInventory::collection($data);
}

public function createRecord(Request $request)
{
try {
$this->validateRequest($request);
$record = $this->model->createRecordFromRequest($request, null, function ($request, $inventory) {
$batch = $request->array('inventory.batch', []);
Batch::create(['uuid' => data_get($batch, 'uuid')], array_merge($batch, ['batch_number' =>('batch_number') ,'company_uuid' => session('company'), 'created_by_uuid' => session('user')]));
});
if (Http::isInternalRequest($request)) {
$this->resource::wrap($this->resourceSingularlName);

return new $this->resource($record);
}
return new $this->resource($record);
} catch (\Exception $e) {
return response()->error($e->getMessage());
} catch (QueryException $e) {
return response()->error($e->getMessage());
} catch (FleetbaseRequestValidationException $e) {
return response()->error($e->getErrors());
}
}
}
18 changes: 16 additions & 2 deletions server/src/Http/Controllers/WarehouseController.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Fleetbase\Pallet\Models\WarehouseAisle;
use Fleetbase\Pallet\Models\WarehouseBin;
use Fleetbase\Pallet\Models\WarehouseRack;
use Fleetbase\Pallet\Models\WarehouseDock;
use Fleetbase\Support\Http;
use Illuminate\Database\QueryException;
use Illuminate\Http\Request;
Expand All @@ -25,8 +26,17 @@ public function createRecord(Request $request)
try {
$this->validateRequest($request);
$record = $this->model->createRecordFromRequest($request, null, function ($request, $warehouse) {
$sections = $request->array('warehouse.sections', []);

$docks = $request->array('warehouse.docks', []);
foreach($docks as $dock) {
WarehouseDock::create((array_merge($dock, [
'warehouse_uuid' => data_get($warehouse, 'uuid'),
'company_uuid' => session('company'),
'created_by_uuid' => session('user')
])));
}

$sections = $request->array('warehouse.sections', []);
foreach ($sections as $section) {
$createdSection = WarehouseSection::create(array_merge($section, [
'warehouse_uuid' => data_get($warehouse, 'uuid'),
Expand Down Expand Up @@ -83,8 +93,12 @@ public function updateRecord(Request $request, string $id)
try {
$this->validateRequest($request);
$record = $this->model->updateRecordFromRequest($request, $id, null, function ($request, $warehouse) {
$sections = $request->array('warehouse.sections', []);
$docks = $request->array('warehouse.docks', []);
foreach($docks as $dock) {
WarehouseDock::updateOrCreate(['uuid' => data_get($dock, 'uuid')], array_merge($dock, ['warehouse_uuid' => $warehouse->uuid, 'company_uuid' => session('company'), 'created_by_uuid' => session('user')]));
}

$sections = $request->array('warehouse.sections', []);
foreach ($sections as $section) {
WarehouseSection::updateOrCreate(['uuid' => data_get($section, 'uuid')], array_merge($section, ['warehouse_uuid' => $warehouse->uuid, 'company_uuid' => session('company'), 'created_by_uuid' => session('user')]));

Expand Down
13 changes: 13 additions & 0 deletions server/src/Http/Controllers/WarehouseDockController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Fleetbase\Pallet\Http\Controllers;

class WarehouseSectionController extends PalletResourceController
{
/**
* The resource to query.
*
* @var string
*/
public $resource = 'warehouse-dock';
}
1 change: 1 addition & 0 deletions server/src/Http/Resources/IndexInventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ public function toArray($request)
'product_uuid' => $this->product_uuid,
'product' => $this->whenLoaded('product', $this->product),
'batch' => $this->whenLoaded('batch', $this->batch),
'batch_uuid' => $this->batch_uuid,
'quantity' => (int) $this->total_quantity,
'comments' => $this->latest_comments,
'updated_at' => $this->latest_updated_at,
Expand Down
27 changes: 27 additions & 0 deletions server/src/Http/Resources/WarehouesDock.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

namespace Fleetbase\Pallet\Http\Resources;

use Fleetbase\Http\Resources\FleetbaseResource;
use Fleetbase\Support\Http;

class WarehouseDock extends FleetbaseResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
*
* @return array|\Illuminate\Contracts\Support\Arrayable|\JsonSerializable
*/
public function toArray($request)
{
return [
'id' => $this->when(Http::isInternalRequest(), $this->id, $this->public_id),
'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
'updated_at' => $this->updated_at,
'created_at' => $this->created_at,
];
}
}
1 change: 1 addition & 0 deletions server/src/Http/Resources/Warehouse.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ public function toArray($request)
'type' => data_get($this, 'type'),
'meta' => data_get($this, 'meta', []),
'sections' => $this->whenLoaded('sections', $this->sections),
'docks' => $this->whenLoaded('docks', $this->docks),
'updated_at' => $this->updated_at,
'created_at' => $this->created_at,
];
Expand Down
4 changes: 3 additions & 1 deletion server/src/Models/Batch.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class Batch extends Model
*
* @var array
*/
protected $casts = [];
protected $casts = [
'meta' => 'json',
];

/**
* Dynamic attributes that are appended to object.
Expand Down
6 changes: 5 additions & 1 deletion server/src/Models/Inventory.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@ class Inventory extends Model
*
* @var array
*/
protected $casts = [];
protected $casts = [
'meta' => 'json',
];

/**
* Dynamic attributes that are appended to object.
Expand All @@ -80,6 +82,8 @@ class Inventory extends Model

protected $filterParams = ['supplier_uuid', 'comments','expiry_date_at', 'status', 'company', 'createdBy', 'supplier'];



/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
Expand Down
5 changes: 5 additions & 0 deletions server/src/Models/Warehouse.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,9 @@ public function sections()
{
return $this->hasMany(WarehouseSection::class, 'warehouse_uuid');
}

public function docks()
{
return $this->hasMany(WarehouseDock::class, 'warehouse_uuid');
}
}
Loading

0 comments on commit 182738f

Please sign in to comment.