+
-
+
+
+
\ No newline at end of file
diff --git a/addon/components/sales-order-form-panel.js b/addon/components/sales-order-form-panel.js
index f3d6c806..52c07fe9 100644
--- a/addon/components/sales-order-form-panel.js
+++ b/addon/components/sales-order-form-panel.js
@@ -2,6 +2,7 @@ import Component from '@glimmer/component';
import { tracked } from '@glimmer/tracking';
import { inject as service } from '@ember/service';
import { action } from '@ember/object';
+import { isValid as isValidDate } from 'date-fns';
import contextComponentCallback from '../utils/context-component-callback';
import applyContextComponentArguments from '../utils/apply-context-component-arguments';
@@ -149,4 +150,11 @@ export default class SalesOrderFormPanelComponent extends Component {
*
* @param {File} file
*/
+ @action setExpectedDeliveryDate(event) {
+ const {
+ target: { value },
+ } = event;
+
+ this.salesOrder.set('expected_delivery_at', new Date(value));
+ }
}
diff --git a/addon/components/supplier-form-panel.hbs b/addon/components/supplier-form-panel.hbs
index bc01c0b8..ab99f884 100644
--- a/addon/components/supplier-form-panel.hbs
+++ b/addon/components/supplier-form-panel.hbs
@@ -54,7 +54,7 @@
@triggerClass="form-select form-input"
@infiniteScroll={{false}}
@renderInPlace={{true}}
- @onChange={{this.selectSupplierAddress}}
+ @onChange={{this.supplier.place.address}}
as |model|
>
diff --git a/addon/controllers/products/index.js b/addon/controllers/products/index.js
index 3f3aea1e..f39c1a9b 100644
--- a/addon/controllers/products/index.js
+++ b/addon/controllers/products/index.js
@@ -74,7 +74,6 @@ export default class ProductsIndexController extends Controller {
'query',
'internal_id',
'public_id',
- 'supplier',
'sku',
'created_at',
'updated_at',
@@ -130,13 +129,6 @@ export default class ProductsIndexController extends Controller {
*/
@tracked product_id;
- /**
- * The filterable param `supplier`
- *
- * @var {String}
- */
- @tracked supplier;
-
/**
* The filterable param `internal_id`
*
@@ -291,6 +283,10 @@ export default class ProductsIndexController extends Controller {
label: 'Edit Product',
fn: this.editProduct,
},
+ {
+ label: 'Delete Product',
+ fn: this.deleteProduct,
+ },
],
sortable: false,
filterable: false,
diff --git a/addon/controllers/purchase-orders/index.js b/addon/controllers/purchase-orders/index.js
index c91e4f0c..6a8184bc 100644
--- a/addon/controllers/purchase-orders/index.js
+++ b/addon/controllers/purchase-orders/index.js
@@ -68,7 +68,7 @@ export default class PurchaseOrdersIndexController extends Controller {
*
* @var {Array}
*/
- queryParams = ['page', 'limit', 'sort', 'query', 'public_id', 'created_by', 'updated_by', 'status', 'delivered_at'];
+ queryParams = ['page', 'limit', 'sort', 'query', 'public_id', 'created_by', 'updated_by', 'status', 'delivery_date_at'];
/**
* The current page of data being viewed
diff --git a/addon/controllers/purchase-orders/index/new.js b/addon/controllers/purchase-orders/index/new.js
index 0fade89c..0e245694 100644
--- a/addon/controllers/purchase-orders/index/new.js
+++ b/addon/controllers/purchase-orders/index/new.js
@@ -42,7 +42,7 @@ export default class PurchaseOrdersIndexNewController extends Controller {
/**
* The fuel report being created.
*
- * @var {FuelReportModel}
+ * @var {SalesOrderModel}
*/
@tracked purchaseOrder = this.store.createRecord('purchase-order');
diff --git a/addon/controllers/sales-orders/index.js b/addon/controllers/sales-orders/index.js
index af70dee9..904d080b 100644
--- a/addon/controllers/sales-orders/index.js
+++ b/addon/controllers/sales-orders/index.js
@@ -68,7 +68,7 @@ export default class SalesOrdersIndexController extends Controller {
*
* @var {Array}
*/
- queryParams = ['page', 'limit', 'sort', 'query', 'public_id', 'created_by', 'updated_by', 'status', 'delivered_at', 'supplier'];
+ queryParams = ['page', 'limit', 'sort', 'query', 'public_id', 'created_by', 'updated_by', 'status', 'delivered_at'];
/**
* The current page of data being viewed
@@ -77,7 +77,6 @@ export default class SalesOrdersIndexController extends Controller {
*/
@tracked page = 1;
- @tracked supplier;
/**
* The maximum number of items to show per page
@@ -292,7 +291,7 @@ export default class SalesOrdersIndexController extends Controller {
this.crud.bulkDelete(selected, {
modelNamePath: 'public_id',
- acceptButtonText: "Delete Sales Order's",
+ acceptButtonText: "Delete Sales Orders",
fetchOptions: {
namespace: 'pallet/int/v1',
},
diff --git a/addon/controllers/sales-orders/index/new.js b/addon/controllers/sales-orders/index/new.js
index 69f26bcb..1c86b09b 100644
--- a/addon/controllers/sales-orders/index/new.js
+++ b/addon/controllers/sales-orders/index/new.js
@@ -42,7 +42,7 @@ export default class SalesOrdersIndexNewController extends Controller {
/**
* The fuel report being created.
*
- * @var {FuelReportModel}
+ * @var {SalesOrderModel}
*/
@tracked salesOrder = this.store.createRecord('sales-order');
diff --git a/addon/models/inventory.js b/addon/models/inventory.js
index 30025c79..04b322c5 100644
--- a/addon/models/inventory.js
+++ b/addon/models/inventory.js
@@ -32,6 +32,7 @@ export default class InventoryModel extends Model {
@attr('date') created_at;
@attr('date') updated_at;
@attr('date') expiry_date_at;
+ @attr('date') manufactured_date_at;
/** @computed */
@computed('created_at') get createdAgo() {
@@ -41,6 +42,20 @@ export default class InventoryModel extends Model {
return formatDistanceToNow(this.created_at);
}
+ @computed('created_at') get createdAt() {
+ if (!isValidDate(this.created_at)) {
+ return null;
+ }
+ return formatDate(this.created_at, 'PPP p');
+ }
+
+ @computed('created_at') get createdAtShort() {
+ if (!isValidDate(this.created_at)) {
+ return null;
+ }
+ return formatDate(this.created_at, 'PP');
+ }
+
@computed('updated_at') get updatedAgo() {
if (!isValidDate(this.updated_at)) {
return null;
@@ -54,4 +69,19 @@ export default class InventoryModel extends Model {
}
return formatDate(this.updated_at, 'PPP p');
}
+
+ @computed('updated_at') get updatedAtShort() {
+ if (!isValidDate(this.updated_at)) {
+ return null;
+ }
+ return formatDate(this.updated_at, 'PP');
+ }
+
+ @computed('expiry_date_at') get expiryDate() {
+ if (!isValidDate(this.expiry_date_at)) {
+ return null;
+ }
+
+ return formatDate(this.expiry_date_at, 'yyyy-MM-dd');
+ }
}
diff --git a/addon/models/purchase-order.js b/addon/models/purchase-order.js
index 9f267f20..51c63ae3 100644
--- a/addon/models/purchase-order.js
+++ b/addon/models/purchase-order.js
@@ -39,18 +39,25 @@ export default class PurchaseOrderModel extends Model {
@attr('boolean') isDeleted;
/** @computed */
- @computed('order_created_at') get orderCreatedAt() {
- if (!isValidDate(this.order_created_at)) {
+ @computed('created_at') get createdAgo() {
+ if (!isValidDate(this.created_at)) {
return null;
}
- return formatDate(this.order_created_at, 'PPP p');
+ return formatDistanceToNow(this.created_at);
}
- @computed('expected_delivery_at') get expectedDeliveryAt() {
- if (!isValidDate(this.expected_delivery_at)) {
+ @computed('created_at') get createdAt() {
+ if (!isValidDate(this.created_at)) {
+ return null;
+ }
+ return formatDate(this.created_at, 'PPP p');
+ }
+
+ @computed('created_at') get createdAtShort() {
+ if (!isValidDate(this.created_at)) {
return null;
}
- return formatDate(this.expected_delivery_at, 'PPP p');
+ return formatDate(this.created_at, 'PP');
}
@computed('updated_at') get updatedAgo() {
@@ -66,4 +73,19 @@ export default class PurchaseOrderModel extends Model {
}
return formatDate(this.updated_at, 'PPP p');
}
+
+ @computed('updated_at') get updatedAtShort() {
+ if (!isValidDate(this.updated_at)) {
+ return null;
+ }
+ return formatDate(this.updated_at, 'PP');
+ }
+
+ @computed('expected_delivery_at') get expectedDeliveryDate() {
+ if (!isValidDate(this.expected_delivery_at)) {
+ return null;
+ }
+
+ return formatDate(this.expected_delivery_at, 'yyyy-MM-dd');
+ }
}
diff --git a/addon/models/sales-order.js b/addon/models/sales-order.js
index a6529b5d..4aa14530 100644
--- a/addon/models/sales-order.js
+++ b/addon/models/sales-order.js
@@ -34,6 +34,7 @@ export default class SalesOrderModel extends Model {
@attr('date') updated_at;
/** @computed */
+
@computed('created_at') get createdAgo() {
if (!isValidDate(this.created_at)) {
return null;
@@ -41,6 +42,20 @@ export default class SalesOrderModel extends Model {
return formatDistanceToNow(this.created_at);
}
+ @computed('created_at') get createdAt() {
+ if (!isValidDate(this.created_at)) {
+ return null;
+ }
+ return formatDate(this.created_at, 'PPP p');
+ }
+
+ @computed('created_at') get createdAtShort() {
+ if (!isValidDate(this.created_at)) {
+ return null;
+ }
+ return formatDate(this.created_at, 'PP');
+ }
+
@computed('updated_at') get updatedAgo() {
if (!isValidDate(this.updated_at)) {
return null;
@@ -54,4 +69,19 @@ export default class SalesOrderModel extends Model {
}
return formatDate(this.updated_at, 'PPP p');
}
+
+ @computed('updated_at') get updatedAtShort() {
+ if (!isValidDate(this.updated_at)) {
+ return null;
+ }
+ return formatDate(this.updated_at, 'PP');
+ }
+
+ @computed('expected_delivery_at') get expectedDeliveryDate() {
+ if (!isValidDate(this.expected_delivery_at)) {
+ return null;
+ }
+
+ return formatDate(this.expected_delivery_at, 'yyyy-MM-dd');
+ }
}
diff --git a/addon/routes/inventory/index.js b/addon/routes/inventory/index.js
index fc3e01dc..d66b325f 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', 'warehouse', 'batch'] });
+ return this.store.query('inventory', { ...params, with: ['product', 'warehouse', 'batch', 'supplier'] });
}
}
diff --git a/addon/routes/products/index/details.js b/addon/routes/products/index/details.js
index 4343499d..01d3bbff 100644
--- a/addon/routes/products/index/details.js
+++ b/addon/routes/products/index/details.js
@@ -9,6 +9,6 @@ export default class ProductsIndexDetailsRoute extends Route {
};
model({ public_id }) {
- return this.store.queryRecord('pallet-product', { public_id, single: true, with: ['supplier'] });
+ return this.store.findRecord('pallet-product', public_id);
}
}
diff --git a/addon/routes/sales-orders/index.js b/addon/routes/sales-orders/index.js
index cc137bb5..f0e4bc8b 100644
--- a/addon/routes/sales-orders/index.js
+++ b/addon/routes/sales-orders/index.js
@@ -10,7 +10,6 @@ export default class SalesOrdersIndexRoute extends Route {
sort: { refreshModel: true },
query: { refreshModel: true },
status: { refreshModel: true },
- supplier: { refreshModel: true },
};
model(params) {
diff --git a/addon/serializers/pallet-product.js b/addon/serializers/pallet-product.js
index a1445674..a677e950 100644
--- a/addon/serializers/pallet-product.js
+++ b/addon/serializers/pallet-product.js
@@ -15,4 +15,15 @@ export default class PalletProductSerializer extends ApplicationSerializer.exten
payloadKeyFromModelName() {
return 'product';
}
+
+ /**
+ * Embedded relationship attributes
+ *
+ * @var {Object}
+ */
+ get attrs() {
+ return {
+ supplier: { embedded: 'always' },
+ };
+ }
}
diff --git a/addon/serializers/purchase-order.js b/addon/serializers/purchase-order.js
index bf275a1f..6bcb95c1 100644
--- a/addon/serializers/purchase-order.js
+++ b/addon/serializers/purchase-order.js
@@ -1,4 +1,15 @@
import ApplicationSerializer from '@fleetbase/ember-core/serializers/application';
import { EmbeddedRecordsMixin } from '@ember-data/serializer/rest';
-export default class PurchaseOrderSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {}
+export default class PurchaseOrderSerializer extends ApplicationSerializer.extend(EmbeddedRecordsMixin) {
+ /**
+ * Embedded relationship attributes
+ *
+ * @var {Object}
+ */
+ get attrs() {
+ return {
+ supplier: { embedded: 'always' },
+ };
+ }
+}
diff --git a/server/migrations/2023_12_06_090936_add_manufactured_date_column_on_inventory.php b/server/migrations/2023_12_06_090936_add_manufactured_date_column_on_inventory.php
new file mode 100644
index 00000000..ca36aab6
--- /dev/null
+++ b/server/migrations/2023_12_06_090936_add_manufactured_date_column_on_inventory.php
@@ -0,0 +1,30 @@
+timestamp('manufactured_date_at')->nullable();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('pallet_inventories');
+ }
+}
diff --git a/server/src/Http/Controllers/InventoryController.php b/server/src/Http/Controllers/InventoryController.php
index 6bdcf462..d0ba6038 100644
--- a/server/src/Http/Controllers/InventoryController.php
+++ b/server/src/Http/Controllers/InventoryController.php
@@ -64,10 +64,8 @@ public function createRecord(Request $request)
'company_uuid' => session('company'),
'created_by_uuid' => session('user'),
'product_uuid' => data_get($data, 'product_uuid'),
- 'batch_number' => data_get($data, 'batch.batch_number', now()->format('Y-m-d')),
+ 'batch_number' => data_get($data, 'batch_number', now()->format('Y-m-d')),
'quantity' => data_get($data, 'quantity', 0),
- 'expiry_date_at' => data_get($data, 'batch.expiry_date_at'),
- 'manufacture_date_at' => data_get($data, 'batch.manufacture_date_at'),
]);
$batch->save();
@@ -80,7 +78,9 @@ public function createRecord(Request $request)
'status' => data_get($data, 'status'),
'quantity' => data_get($data, 'quantity', 0),
'min_quantity' => data_get($data, 'min_quantity', 0),
- 'comments' => data_get($data, 'commetns')
+ 'comments' => data_get($data, 'comments'),
+ 'expiry_date_at' => data_get($data, 'expiry_date_at'),
+ 'manufactured_date_at' => data_get($data, 'manufactured_date_at')
]);
$inventory->batch()->associate($batch);
diff --git a/server/src/Http/Controllers/PurchaseOrderController.php b/server/src/Http/Controllers/PurchaseOrderController.php
index bad8916d..070d68d7 100644
--- a/server/src/Http/Controllers/PurchaseOrderController.php
+++ b/server/src/Http/Controllers/PurchaseOrderController.php
@@ -2,6 +2,12 @@
namespace Fleetbase\Pallet\Http\Controllers;
+use Fleetbase\Pallet\Models\PurchaseOrder;
+use Fleetbase\Exceptions\FleetbaseRequestValidationException;
+use Fleetbase\Support\Http;
+use Illuminate\Http\Request;
+use Illuminate\Database\QueryException;
+
class PurchaseOrderController extends PalletResourceController
{
/**
@@ -10,4 +16,39 @@ class PurchaseOrderController extends PalletResourceController
* @var string
*/
public $resource = 'purchase-order';
+
+ public function createRecord(Request $request)
+ {
+ try {
+ $this->validateRequest($request);
+ $data = $request->input('purchaseOrder');
+
+ $salesOrder = new PurchaseOrder([
+ 'company_uuid' => session('company'),
+ 'created_by_uuid' => session('user'),
+ 'supplier_uuid' => data_get($data, 'supplier_uuid'),
+ 'transaction_uuid' => data_get($data, 'transaction_uuid'),
+ 'assigned_to_uuid' => data_get($data, 'user'),
+ 'status' => data_get($data, 'status'),
+ 'reference_code' => data_get($data, 'reference_code'),
+ 'reference_url' => data_get($data, 'reference_url'),
+ 'description' => data_get($data, 'description'),
+ 'comments' => data_get($data, 'comments'),
+ 'expected_delivery_at' => data_get($data, 'expected_delivery_at'),
+ 'order_date_at' => data_get($data, 'order_date_at'),
+ ]);
+ $salesOrder->save();
+
+ if (Http::isInternalRequest($request)) {
+ $this->resource::wrap($this->resourceSingularlName);
+ }
+ return new $this->resource($salesOrder);
+ } 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/SalesOrderController.php b/server/src/Http/Controllers/SalesOrderController.php
index d7dd47eb..354eb974 100644
--- a/server/src/Http/Controllers/SalesOrderController.php
+++ b/server/src/Http/Controllers/SalesOrderController.php
@@ -2,6 +2,12 @@
namespace Fleetbase\Pallet\Http\Controllers;
+use Fleetbase\Pallet\Models\SalesOrder;
+use Fleetbase\Exceptions\FleetbaseRequestValidationException;
+use Fleetbase\Support\Http;
+use Illuminate\Http\Request;
+use Illuminate\Database\QueryException;
+
class SalesOrderController extends PalletResourceController
{
/**
@@ -10,4 +16,39 @@ class SalesOrderController extends PalletResourceController
* @var string
*/
public $resource = 'sales-order';
+
+ public function createRecord(Request $request)
+ {
+ try {
+ $this->validateRequest($request);
+ $data = $request->input('salesOrder');
+
+ $salesOrder = new SalesOrder([
+ 'company_uuid' => session('company'),
+ 'created_by_uuid' => session('user'),
+ 'supplier_uuid' => data_get($data, 'supplier_uuid'),
+ 'transaction_uuid' => data_get($data, 'transaction_uuid'),
+ 'assigned_to_uuid' => data_get($data, 'user'),
+ 'status' => data_get($data, 'status'),
+ 'reference_code' => data_get($data, 'reference_code'),
+ 'reference_url' => data_get($data, 'reference_url'),
+ 'description' => data_get($data, 'description'),
+ 'comments' => data_get($data, 'comments'),
+ 'expected_delivery_at' => data_get($data, 'expected_delivery_at'),
+ 'order_date_at' => data_get($data, 'order_date_at'),
+ ]);
+ $salesOrder->save();
+
+ if (Http::isInternalRequest($request)) {
+ $this->resource::wrap($this->resourceSingularlName);
+ }
+ return new $this->resource($salesOrder);
+ } 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/Resources/IndexInventory.php b/server/src/Http/Resources/IndexInventory.php
index 74d360aa..7115dea5 100644
--- a/server/src/Http/Resources/IndexInventory.php
+++ b/server/src/Http/Resources/IndexInventory.php
@@ -22,6 +22,8 @@ public function toArray($request)
'product' => $this->whenLoaded('product', $this->product),
'batch' => $this->whenLoaded('batch', new Batch($this->batch)),
'batch_uuid' => $this->batch_uuid,
+ 'supplier_uuid' => $this->supplier_uuid,
+ 'supplier' => $this->whenLoaded('supplier', $this->supplier),
'quantity' => (int) $this->total_quantity,
'min_quantity' => (int) $this->minimum_quantity,
'comments' => $this->latest_comments,
diff --git a/server/src/Http/Resources/Inventory.php b/server/src/Http/Resources/Inventory.php
index 60659871..09d01c54 100644
--- a/server/src/Http/Resources/Inventory.php
+++ b/server/src/Http/Resources/Inventory.php
@@ -17,21 +17,24 @@ class Inventory extends FleetbaseResource
public function toArray($request)
{
return [
- 'id' => $this->when(Http::isInternalRequest(), $this->incrementing_id, $this->public_id),
- 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
- 'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
- 'product_uuid' => $this->product_uuid,
- 'batch_uuid' => $this->batch_uuid,
- 'warehouse_uuid' => $this->warehouse_uuid,
- 'product' => $this->whenLoaded('product', $this->product),
- 'batch' => $this->whenLoaded('batch', new Batch($this->batch)),
- 'warehouse' => $this->whenLoaded('warehouse', new Warehouse($this->warehouse)),
- 'quantity' => (int) $this->quantity,
- 'min_quantity' => (int) $this->min_quantity,
- 'comments' => $this->comments,
- 'expiry_date_at' => $this->expiry_date_at,
- 'updated_at' => $this->updated_at,
- 'created_at' => $this->created_at,
+ 'id' => $this->when(Http::isInternalRequest(), $this->incrementing_id, $this->public_id),
+ 'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
+ 'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
+ 'product_uuid' => $this->product_uuid,
+ 'batch_uuid' => $this->batch_uuid,
+ 'warehouse_uuid' => $this->warehouse_uuid,
+ 'supplier_uuid' => $this->supplier_uuid,
+ 'supplier' => $this->whenLoaded('supplier', $this->supplier),
+ 'product' => $this->whenLoaded('product', $this->product),
+ 'batch' => $this->whenLoaded('batch', new Batch($this->batch)),
+ 'warehouse' => $this->whenLoaded('warehouse', new Warehouse($this->warehouse)),
+ 'quantity' => (int) $this->quantity,
+ 'min_quantity' => (int) $this->min_quantity,
+ 'comments' => $this->comments,
+ 'expiry_date_at' => $this->expiry_date_at,
+ 'manufactured_date_at' => $this->manufactured_date_at,
+ 'updated_at' => $this->updated_at,
+ 'created_at' => $this->created_at,
];
}
}
diff --git a/server/src/Http/Resources/PurchaseOrder.php b/server/src/Http/Resources/PurchaseOrder.php
new file mode 100644
index 00000000..1d35f47d
--- /dev/null
+++ b/server/src/Http/Resources/PurchaseOrder.php
@@ -0,0 +1,37 @@
+ $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),
+ 'supplier_uuid' => $this->supplier_uuid,
+ 'supplier' => $this->whenLoaded('supplier', $this->supplier),
+ 'status' => $this->status,
+ 'comments' => $this->comments,
+ 'description' => $this->description,
+ 'reference_code' => $this->reference_code,
+ 'reference_url' => $this->reference_url,
+ 'customer_reference_code' => $this->customer_reference_code,
+ 'order_date_at' => $this->orde_date_at,
+ 'expected_delivery_at' => $this->expected_delivery_at,
+ 'updated_at' => $this->updated_at,
+ 'created_at' => $this->created_at,
+ ];
+ }
+}
diff --git a/server/src/Http/Resources/SalesOrder.php b/server/src/Http/Resources/SalesOrder.php
index f10f9768..d3725878 100644
--- a/server/src/Http/Resources/SalesOrder.php
+++ b/server/src/Http/Resources/SalesOrder.php
@@ -3,7 +3,6 @@
namespace Fleetbase\Pallet\Http\Resources;
use Fleetbase\Http\Resources\FleetbaseResource;
-use Fleetbase\Pallet\Models\WarehouseRack;
use Fleetbase\Support\Http;
class SalesOrder extends FleetbaseResource
@@ -22,6 +21,7 @@ public function toArray($request)
'uuid' => $this->when(Http::isInternalRequest(), $this->uuid),
'public_id' => $this->when(Http::isInternalRequest(), $this->public_id),
'supplier_uuid' => $this->supplier_uuid,
+ 'supplier' => $this->whenLoaded('supplier', $this->supplier),
'status' => $this->status,
'comments' => $this->comments,
'description' => $this->description,
diff --git a/server/src/Models/Inventory.php b/server/src/Models/Inventory.php
index 30856191..8d7581dd 100644
--- a/server/src/Models/Inventory.php
+++ b/server/src/Models/Inventory.php
@@ -48,6 +48,10 @@ class Inventory extends Model
* @var array
*/
protected $fillable = [
+ 'manufactured_date_at',
+ 'expiry_date_at',
+ 'created_at',
+ 'updated_at',
'product_uuid',
'warehouse_uuid',
'batch_uuid',
@@ -57,6 +61,10 @@ class Inventory extends Model
'status',
];
+ public $timestamps = true;
+
+ protected $dates = ['expiry_date_at'];
+
/**
* The attributes that should be cast to native types.
*
@@ -99,6 +107,14 @@ public function product()
return $this->belongsTo(Product::class);
}
+ /**
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+ */
+ public function supplier()
+ {
+ return $this->belongsTo(Supplier::class, 'supplier_uuid', 'uuid');
+ }
+
/**
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
@@ -141,4 +157,14 @@ public function scopeSummarizeByProduct($query)
->leftJoin('pallet_batches', 'pallet_inventories.batch_uuid', '=', 'pallet_batches.uuid')
->groupBy('pallet_inventories.product_uuid');
}
+
+ protected static function boot()
+ {
+ parent::boot();
+
+ static::creating(function ($model) {
+ $model->created_at = now();
+ $model->manufactured_date_at = now();
+ });
+ }
}
diff --git a/server/src/Models/PurchaseOrder.php b/server/src/Models/PurchaseOrder.php
index 8d2adb90..669ea467 100644
--- a/server/src/Models/PurchaseOrder.php
+++ b/server/src/Models/PurchaseOrder.php
@@ -2,6 +2,7 @@
namespace Fleetbase\Pallet\Models;
+use Fleetbase\Casts\Json;
use Fleetbase\Models\Model;
use Fleetbase\Traits\HasApiModelBehavior;
use Fleetbase\Traits\HasPublicId;
@@ -39,7 +40,7 @@ class PurchaseOrder extends Model
*
* @var array
*/
- protected $searchableColumns = ['uuid', 'public_id', 'company_uuid', 'created_by_uuid', 'supplier_uuid', 'transaction_uuid', 'assigned_to_uuid', 'point_of_contact_uuid', 'reference_code', 'reference_url', 'description', 'comments', 'currency', 'status', 'order_created_at', 'expected_delivery_at', 'created_at'];
+ protected $searchableColumns = ['reference_code', 'reference_url', 'description', 'comments', 'currency', 'status'];
/**
* The attributes that are mass assignable.
@@ -67,13 +68,17 @@ class PurchaseOrder extends Model
'updated_at',
];
+ public $timestamps = true;
+
+ protected $dates = ['expected_delivery_at'];
+
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
- 'meta' => 'json',
+ 'meta' => JSON::class,
];
/**
@@ -117,7 +122,7 @@ public function createdBy()
*/
public function supplier()
{
- return $this->belongsTo(Vendor::class, 'supplier_uuid', 'uuid');
+ return $this->belongsTo(Supplier::class, 'supplier_uuid', 'uuid');
}
/**
@@ -149,4 +154,14 @@ public function pointOfContact()
{
return $this->belongsTo(Contact::class, 'point_of_contact_uuid', 'uuid');
}
+
+ protected static function boot()
+ {
+ parent::boot();
+
+ static::creating(function ($model) {
+ $model->created_at = now();
+ $model->order_created_at = now();
+ });
+ }
}
diff --git a/server/src/Models/SalesOrder.php b/server/src/Models/SalesOrder.php
index 142cc4fc..751d7d33 100644
--- a/server/src/Models/SalesOrder.php
+++ b/server/src/Models/SalesOrder.php
@@ -40,7 +40,7 @@ class SalesOrder extends Model
*
* @var array
*/
- protected $searchableColumns = [ 'customer_type', 'status', 'reference_code', 'reference_url', 'description', 'comments'];
+ protected $searchableColumns = ['customer_type', 'status', 'reference_code', 'reference_url', 'description', 'comments'];
/**
* The attributes that are mass assignable.
@@ -69,6 +69,10 @@ class SalesOrder extends Model
'updated_at',
];
+ public $timestamps = true;
+
+ protected $dates = ['expected_delivery_at'];
+
/**
* The attributes that should be cast to native types.
*
@@ -147,8 +151,24 @@ public function pointOfContact()
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
+
+ /**
+ * Relationship with the supplier associated with the purchase order.
+ *
+ * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
+ */
public function supplier()
{
- return $this->belongsTo(Supplier::class, 'uuid');
+ return $this->belongsTo(Supplier::class, 'supplier_uuid', 'uuid');
+ }
+
+ protected static function boot()
+ {
+ parent::boot();
+
+ static::creating(function ($model) {
+ $model->created_at = now();
+ $model->order_date_at = now();
+ });
}
}