diff --git a/addon/components/cell/product-info.js b/addon/components/cell/product-info.js
index 7cb945af..d44a6d64 100644
--- a/addon/components/cell/product-info.js
+++ b/addon/components/cell/product-info.js
@@ -2,14 +2,14 @@ import Component from '@glimmer/component';
import { action, computed, get } from '@ember/object';
export default class CellProductInfoComponent extends Component {
- @computed('args.{column.modelPath,row}') 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) {
diff --git a/addon/components/inventory-form-panel.hbs b/addon/components/inventory-form-panel.hbs
index 02488c3f..c7cc5f3e 100644
--- a/addon/components/inventory-form-panel.hbs
+++ b/addon/components/inventory-form-panel.hbs
@@ -46,21 +46,6 @@
{{model.name}}
-
-
- {{model.name}}
-
-
-
+
diff --git a/addon/components/warehouse-editor.js b/addon/components/warehouse-editor.js
index 8a7c4767..c2c1141b 100644
--- a/addon/components/warehouse-editor.js
+++ b/addon/components/warehouse-editor.js
@@ -23,66 +23,54 @@ export default class WarehouseEditorComponent extends Component {
this.warehouse = this.args.warehouse;
}
- @action removeSection(section) {
- section.destroyRecord();
- }
-
- @action removeAisle(aisle) {
- aisle.destroyRecord();
- }
-
- @action removeRack(rack) {
- rack.destroyRecord();
- }
-
- @action removeBin(bin) {
- bin.destroyRecord();
- }
-
@action addSection() {
const section = this.store.createRecord('warehouse-section', { warehouse_uuid: this.warehouse.id });
this.warehouse.sections.pushObject(section);
}
@action addAisle(section) {
- if (section && section.uuid) {
- const aisle = this.store.createRecord('warehouse-aisle', {
- section: section,
- });
-
- if (!section.aisles) {
- section.set('aisles', []);
- }
+ const aisle = this.store.createRecord('warehouse-aisle', { section: section });
- section.aisles.pushObject(aisle);
+ if (!section.aisles) {
+ section.set('aisles', []);
}
+
+ section.aisles.pushObject(aisle);
}
@action addRacks(aisle) {
- if (aisle && aisle.uuid) {
- const rack = this.store.createRecord('warehouse-rack', {
- aisle: aisle,
- });
-
- if (!aisle.racks) {
- aisle.set('racks', []);
- }
+ const rack = this.store.createRecord('warehouse-rack', { aisle: aisle });
- aisle.racks.pushObject(rack);
+ if (!aisle.racks) {
+ aisle.set('racks', []);
}
+
+ aisle.racks.pushObject(rack);
}
@action addBins(rack) {
- if (rack && rack.uuid) {
- const bin = this.store.createRecord('warehouse-bin', {
- rack: rack,
- });
-
- if (!rack.bins) {
- rack.set('bins', []);
- }
+ const bin = this.store.createRecord('warehouse-bin', { rack: rack });
- rack.bins.pushObject(bin);
+ if (!rack.bins) {
+ rack.set('bins', []);
}
+
+ rack.bins.pushObject(bin);
+ }
+
+ @action removeSection(section) {
+ section.destroyRecord();
+ }
+
+ @action removeAisle(aisle) {
+ aisle.destroyRecord();
+ }
+
+ @action removeRack(rack) {
+ rack.destroyRecord();
+ }
+
+ @action removeBin(bin) {
+ bin.destroyRecord();
}
}
diff --git a/addon/components/warehouse-form-panel.js b/addon/components/warehouse-form-panel.js
index 6215c431..21b47520 100644
--- a/addon/components/warehouse-form-panel.js
+++ b/addon/components/warehouse-form-panel.js
@@ -86,10 +86,6 @@ export default class WarehouseFormPanelComponent extends Component {
@action save() {
const { warehouse } = this;
- // if (warehouse.sections) {
- // all(warehouse.sections.map((section) => section.save()));
- // }
-
this.loader.showLoader('.next-content-overlay-panel-container', { loadingMessage: 'Saving place...', preserveTargetPosition: true });
this.isLoading = true;
diff --git a/addon/controllers/inventory/index/new.js b/addon/controllers/inventory/index/new.js
index e588cc47..6d5e4daf 100644
--- a/addon/controllers/inventory/index/new.js
+++ b/addon/controllers/inventory/index/new.js
@@ -37,7 +37,11 @@ export default class InventoryIndexNewController extends Controller {
*
* @var {InventoryModel}
*/
- @tracked inventory = this.store.createRecord('inventory');
+ @tracked inventory = this.store.createRecord('inventory', {
+ type: 'pallet-inventory',
+ meta: {},
+ batches: [this.store.createRecord('batch')],
+ });
/**
* Set the overlay component context object.
@@ -83,6 +87,10 @@ export default class InventoryIndexNewController extends Controller {
* @memberof InventoryIndexNewController
*/
resetForm() {
- this.inventory = this.store.createRecord('inventory');
+ this.inventory = this.store.createRecord('inventory', {
+ type: 'pallet-inventory',
+ meta: {},
+ batches: [this.store.createRecord('batch')],
+ });
}
}
diff --git a/addon/controllers/warehouses/index.js b/addon/controllers/warehouses/index.js
index 8bcd32ac..e474bf6c 100644
--- a/addon/controllers/warehouses/index.js
+++ b/addon/controllers/warehouses/index.js
@@ -131,6 +131,8 @@ export default class WarehousesIndexController extends Controller {
* @var {String}
*/
@tracked neighborhood;
+
+ @tracked warehouse;
/**
* All columns applicable for orders
diff --git a/addon/routes/inventory/index.js b/addon/routes/inventory/index.js
index 1a4c2df7..fc3e01dc 100644
--- a/addon/routes/inventory/index.js
+++ b/addon/routes/inventory/index.js
@@ -15,6 +15,6 @@ export default class InventoryIndexRoute extends Route {
};
model(params) {
- return this.store.query('inventory', { ...params, with: ['product'] });
+ return this.store.query('inventory', { ...params, with: ['product', 'warehouse', 'batch'] });
}
}
diff --git a/addon/serializers/inventory.js b/addon/serializers/inventory.js
index 27f46409..fb14ff4e 100644
--- a/addon/serializers/inventory.js
+++ b/addon/serializers/inventory.js
@@ -11,6 +11,7 @@ export default class InventorySerializer extends ApplicationSerializer.extend(Em
return {
product: { embedded: 'always' },
warehouse: { embedded: 'always' },
+ batch: { embedded: 'always' },
};
}
}
diff --git a/addon/serializers/warehouse.js b/addon/serializers/warehouse.js
index 40d5ef3f..2db429a2 100644
--- a/addon/serializers/warehouse.js
+++ b/addon/serializers/warehouse.js
@@ -10,9 +10,6 @@ export default class WarehouseSerializer extends ApplicationSerializer.extend(Em
get attrs() {
return {
sections: { embedded: 'always' },
- aisles: { embedded: 'always' },
- racks: { embedded: 'always' },
- bins: { embedded: 'always' },
};
}
}
diff --git a/server/src/Http/Controllers/InventoryController.php b/server/src/Http/Controllers/InventoryController.php
index 5bda60ce..6a6b2ac3 100644
--- a/server/src/Http/Controllers/InventoryController.php
+++ b/server/src/Http/Controllers/InventoryController.php
@@ -2,9 +2,13 @@
namespace Fleetbase\Pallet\Http\Controllers;
+use Fleetbase\Exceptions\FleetbaseRequestValidationException;
use Fleetbase\Pallet\Http\Resources\IndexInventory;
+use Fleetbase\Pallet\Models\Batch;
use Fleetbase\Pallet\Models\Inventory;
use Illuminate\Http\Request;
+use Fleetbase\Support\Http;
+use Illuminate\Database\QueryException;
class InventoryController extends PalletResourceController
{
@@ -24,4 +28,27 @@ 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());
+ }
+ }
}
diff --git a/server/src/Http/Controllers/WarehouseController.php b/server/src/Http/Controllers/WarehouseController.php
index ffcc631e..a8dc8ba4 100644
--- a/server/src/Http/Controllers/WarehouseController.php
+++ b/server/src/Http/Controllers/WarehouseController.php
@@ -20,6 +20,64 @@ class WarehouseController extends PalletResourceController
*/
public $resource = 'warehouse';
+ public function createRecord(Request $request)
+ {
+ try {
+ $this->validateRequest($request);
+ $record = $this->model->createRecordFromRequest($request, null, function ($request, $warehouse) {
+ $sections = $request->array('warehouse.sections', []);
+
+ foreach ($sections as $section) {
+ $createdSection = WarehouseSection::create(array_merge($section, [
+ 'warehouse_uuid' => data_get($warehouse, 'uuid'),
+ 'company_uuid' => session('company'),
+ 'created_by_uuid' => session('user')
+ ]));
+
+ $aisles = data_get($section, 'aisles', []);
+ foreach ($aisles as $aisle) {
+ $createdAisle = WarehouseAisle::create(array_merge($aisle, [
+ 'section_uuid' => $createdSection->uuid,
+ 'company_uuid' => session('company'),
+ 'created_by_uuid' => session('user')
+ ]));
+
+ $racks = data_get($aisle, 'racks', []);
+ foreach ($racks as $rack) {
+ $createdRack = WarehouseRack::create(array_merge($rack, [
+ 'aisle_uuid' => $createdAisle->uuid,
+ 'company_uuid' => session('company'),
+ 'created_by_uuid' => session('user')
+ ]));
+
+ $bins = data_get($rack, 'bins', []);
+ foreach ($bins as $bin) {
+ WarehouseBin::create(array_merge($bin, [
+ 'rack_uuid' => $createdRack->uuid,
+ '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());
+ }
+ }
+
public function updateRecord(Request $request, string $id)
{
try {
@@ -33,7 +91,7 @@ public function updateRecord(Request $request, string $id)
$aisles = data_get($section, 'aisles', []);
foreach ($aisles as $aisle) {
WarehouseAisle::updateOrCreate(['uuid' => data_get($aisle, 'uuid')], array_merge($aisle, ['section_uuid' => data_get($section, 'uuid'), 'company_uuid' => session('company'), 'created_by_uuid' => session('user')]));
-
+
$racks = data_get($aisle, 'racks', []);
foreach ($racks as $rack) {
WarehouseRack::updateOrCreate(['uuid' => data_get($rack, 'uuid')], array_merge($rack, ['aisle_uuid' => data_get($aisle, 'uuid'), 'company_uuid' => session('company'), 'created_by_uuid' => session('user')]));
diff --git a/server/src/Http/Resources/Batch.php b/server/src/Http/Resources/Batch.php
new file mode 100644
index 00000000..67345e2c
--- /dev/null
+++ b/server/src/Http/Resources/Batch.php
@@ -0,0 +1,31 @@
+ $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),
+ 'batch_number' => $this->batch_number,
+ 'batch_quantity' => $this->batch_quantity,
+ 'racks' => WarehouseRack::collection($this->racks),
+ 'updated_at' => $this->updated_at,
+ 'created_at' => $this->created_at,
+ ];
+ }
+}
diff --git a/server/src/Http/Resources/IndexInventory.php b/server/src/Http/Resources/IndexInventory.php
index 75754606..5f323b0f 100644
--- a/server/src/Http/Resources/IndexInventory.php
+++ b/server/src/Http/Resources/IndexInventory.php
@@ -20,6 +20,7 @@ public function toArray($request)
'public_id' => $this->latest_public_id,
'product_uuid' => $this->product_uuid,
'product' => $this->whenLoaded('product', $this->product),
+ 'batch' => $this->whenLoaded('batch', $this->batch),
'quantity' => (int) $this->total_quantity,
'comments' => $this->latest_comments,
'updated_at' => $this->latest_updated_at,
diff --git a/server/src/Http/Resources/Warehouse.php b/server/src/Http/Resources/Warehouse.php
new file mode 100644
index 00000000..faba6931
--- /dev/null
+++ b/server/src/Http/Resources/Warehouse.php
@@ -0,0 +1,83 @@
+ $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),
+ 'name' => $this->name,
+ 'location' => data_get($this, 'location', new Point(0, 0)),
+ 'address' => $this->address,
+ 'address_html' => $this->when(Http::isInternalRequest(), $this->address_html),
+ 'street1' => data_get($this, 'street1'),
+ 'street2' => data_get($this, 'street2'),
+ 'city' => data_get($this, 'city'),
+ 'province' => data_get($this, 'province'),
+ 'postal_code' => data_get($this, 'postal_code'),
+ 'neighborhood' => data_get($this, 'neighborhood'),
+ 'district' => data_get($this, 'district'),
+ 'building' => data_get($this, 'building'),
+ 'security_access_code' => data_get($this, 'security_access_code'),
+ 'country' => data_get($this, 'country'),
+ 'country_name' => $this->when(Http::isInternalRequest(), $this->country_name),
+ 'phone' => data_get($this, 'phone'),
+ 'owner' => $this->when(!Http::isInternalRequest(), Resolve::resourceForMorph($this->owner_type, $this->owner_uuid)),
+ 'tracking_number' => $this->whenLoaded('trackingNumber', $this->trackingNumber),
+ 'type' => data_get($this, 'type'),
+ 'meta' => data_get($this, 'meta', []),
+ 'sections' => $this->whenLoaded('sections', $this->sections),
+ 'updated_at' => $this->updated_at,
+ 'created_at' => $this->created_at,
+ ];
+ }
+
+ /**
+ * Transform the resource into an webhook payload.
+ *
+ * @return array
+ */
+ public function toWebhookPayload()
+ {
+ return [
+ 'id' => $this->public_id,
+ 'internal_id' => $this->internal_id,
+ 'name' => $this->name,
+ 'latitude' => $this->latitude ?? null,
+ 'longitude' => $this->longitude ?? null,
+ 'street1' => $this->street1 ?? null,
+ 'street2' => $this->street2 ?? null,
+ 'city' => $this->city ?? null,
+ 'province' => $this->province ?? null,
+ 'postal_code' => $this->postal_code ?? null,
+ 'neighborhood' => $this->neighborhood ?? null,
+ 'district' => $this->district ?? null,
+ 'building' => $this->building ?? null,
+ 'security_access_code' => $this->security_access_code ?? null,
+ 'country' => $this->country ?? null,
+ 'phone' => $this->phone ?? null,
+ 'owner' => Resolve::resourceForMorph($this->owner_type, $this->owner_uuid),
+ 'type' => $this->type ?? null,
+ 'meta' => $this->meta ?? [],
+ 'sections' => $this->sections ?? [],
+ 'updated_at' => $this->updated_at,
+ 'created_at' => $this->created_at,
+ ];
+ }
+}
diff --git a/server/src/Http/Resources/WarehouseAisle.php b/server/src/Http/Resources/WarehouseAisle.php
new file mode 100644
index 00000000..471e8ee3
--- /dev/null
+++ b/server/src/Http/Resources/WarehouseAisle.php
@@ -0,0 +1,30 @@
+ $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),
+ 'aisle_number' => $this->aisle_number,
+ 'racks' => WarehouseRack::collection($this->racks),
+ 'updated_at' => $this->updated_at,
+ 'created_at' => $this->created_at,
+ ];
+ }
+}
diff --git a/server/src/Http/Resources/WarehouseBin.php b/server/src/Http/Resources/WarehouseBin.php
new file mode 100644
index 00000000..0bd1b2a3
--- /dev/null
+++ b/server/src/Http/Resources/WarehouseBin.php
@@ -0,0 +1,30 @@
+ $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),
+ 'bin_number' => $this->bin_number,
+ 'size' => $this->size,
+ 'max_weight' => $this->max_weight,
+ 'updated_at' => $this->updated_at,
+ 'created_at' => $this->created_at,
+ ];
+ }
+}
diff --git a/server/src/Http/Resources/WarehouseRack.php b/server/src/Http/Resources/WarehouseRack.php
new file mode 100644
index 00000000..7bd5ded2
--- /dev/null
+++ b/server/src/Http/Resources/WarehouseRack.php
@@ -0,0 +1,31 @@
+ $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),
+ 'bins' => WarehouseBin::collection($this->bins),
+ 'capacity' => $this->capacity,
+ 'rack_number' => $this->rack_number,
+ 'updated_at' => $this->updated_at,
+ 'created_at' => $this->created_at,
+ ];
+ }
+}
diff --git a/server/src/Http/Resources/WarehouseSection.php b/server/src/Http/Resources/WarehouseSection.php
new file mode 100644
index 00000000..51e9b7bd
--- /dev/null
+++ b/server/src/Http/Resources/WarehouseSection.php
@@ -0,0 +1,30 @@
+ $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),
+ 'name' => $this->name,
+ 'description' => $this->description,
+ 'aisles' => WarehouseAisle::collection($this->aisles),
+ 'updated_at' => $this->updated_at,
+ 'created_at' => $this->created_at,
+ ];
+ }
+}
diff --git a/server/src/Models/Batch.php b/server/src/Models/Batch.php
index 3bafd644..f3b40b4b 100644
--- a/server/src/Models/Batch.php
+++ b/server/src/Models/Batch.php
@@ -76,6 +76,8 @@ class Batch extends Model
*/
protected $hidden = [];
+ protected $with = ['inventory'];
+
/**
* Relationship with the company associated with the batch.
*
diff --git a/server/src/Models/Inventory.php b/server/src/Models/Inventory.php
index a192de80..23184886 100644
--- a/server/src/Models/Inventory.php
+++ b/server/src/Models/Inventory.php
@@ -76,6 +76,10 @@ class Inventory extends Model
*/
protected $hidden = [];
+ protected $with = ['product', 'batch', 'warehouse'];
+
+ protected $filterParams = ['supplier_uuid', 'comments','expiry_date_at', 'status', 'company', 'createdBy', 'supplier'];
+
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
diff --git a/server/src/Models/Warehouse.php b/server/src/Models/Warehouse.php
index c84f5c7d..f0a56096 100644
--- a/server/src/Models/Warehouse.php
+++ b/server/src/Models/Warehouse.php
@@ -20,6 +20,8 @@ class Warehouse extends Place
*/
protected $publicIdType = 'warehouse';
+ protected $with = ['sections'];
+
/**
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/