Skip to content

Commit

Permalink
completed Product,Sales and Purchases page
Browse files Browse the repository at this point in the history
  • Loading branch information
TemuulenBM committed Dec 6, 2023
1 parent 5c30f6d commit 2a959e9
Show file tree
Hide file tree
Showing 34 changed files with 435 additions and 93 deletions.
5 changes: 3 additions & 2 deletions addon/components/inventory-form-panel.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,9 @@
</ContentPanel>
<ContentPanel @title="Batch" @open={{true}} @pad={{true}} @panelBodyClass="bg-white dark:bg-gray-800">
<InputGroup @name="Batch Number" @type="text" @value={{this.inventory.batch.batch_number}} />
<InputGroup @name="Expiry Date" @type="date" @value={{this.inventory.batch.expiry_date_at}} />
<InputGroup @name="Manufactured Date" @type="date" @value={{this.inventory.batch.manufacture_date_at}} />
<InputGroup @name="Expiry Date">
<input value={{this.inventory.expiryDate}} type="date" class="form-input w-full" {{on "change" this.setExpiryDate}} />
</InputGroup>
</ContentPanel>
</div>
</Overlay::Body>
Expand Down
11 changes: 8 additions & 3 deletions addon/components/inventory-form-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,13 +152,18 @@ export default class InventoryFormPanelComponent extends Component {
@action setDefaultBatchValues() {
const currentDate = new Date().toISOString().split('T')[0];

// unlikely to need but incase batch isn't initialized, do it here
if (!this.inventory.batch) {
this.inventory.batch = this.store.createRecord('batch');
}

this.inventory.batch.set('batch_number', currentDate);
this.inventory.batch.set('expiry_date_at', currentDate);
this.inventory.batch.set('manufacture_date_at', currentDate);
}

@action setExpiryDate(event) {
const {
target: { value },
} = event;

this.inventory.set('expiry_date_at', new Date(value));
}
}
8 changes: 8 additions & 0 deletions addon/components/inventory-panel/details.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,14 @@
<div class="field-name">Batch</div>
<div class="field-value">{{n-a @inventory.batch.batch_number}}</div>
</div>
<div class="field-info-container">
<div class="field-name">Expiry Date</div>
<div class="field-value">{{n-a @inventory.expiry_date_at}}</div>
</div>
<div class="field-info-container">
<div class="field-name">Manufactured Date</div>
<div class="field-value">{{n-a @inventory.created_at}}</div>
</div>
</div>
</ContentPanel>
</div>
10 changes: 9 additions & 1 deletion addon/components/product-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,11 +89,19 @@ export default class ProductPanelComponent extends Component {
constructor() {
super(...arguments);
this.product = this.args.product;
console.log('[this.product]', this.product);
this.getProductSupplier();
this.tab = this.getTabUsingSlug(this.args.tab);
applyContextComponentArguments(this);
}

getProductSupplier() {
if (this.product.supplier_uuid) {
this.store.findRecord('vendor', this.product.supplier_uuid).then((vendor) => {
this.product.set('supplier', vendor);
});
}
}

/**
* Sets the overlay context.
*
Expand Down
25 changes: 22 additions & 3 deletions addon/components/purchase-order-form-panel.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@

<Overlay::Body @wrapperClass="new-service-rate-overlay-body px-4 space-y-4 pt-4" @increaseInnerBodyHeightBy={{1000}}>
<div class="grid grid-cols-1 text-xs dark:text-gray-100">
<InputGroup @name="Supplier">
<ModelSelect
@modelName="vendor"
@selectedModel={{this.purchaseOrder.supplier}}
@placeholder="Select Supplier"
@triggerClass="form-select form-input"
@infiniteScroll={{false}}
@renderInPlace={{true}}
@onChange={{fn (mut this.purchaseOrder.supplier)}}
@onChangeId={{fn (mut this.purchaseOrder.supplier_uuid)}}
as |model|
>
{{model.name}}
</ModelSelect>
</InputGroup>
<InputGroup @name="Status">
<div class="fleetbase-model-select fleetbase-power-select ember-model-select">
<PowerSelect
Expand All @@ -44,13 +59,17 @@
</PowerSelect>
</div>
</InputGroup>
<InputGroup @name="Purchase order description">
<InputGroup @name="Reference Code" @type="text" @value={{this.purchaseOrder.reference_code}} />
<InputGroup @name="Reference URL" @type="text" @value={{this.purchaseOrder.reference_url}} />
<InputGroup @name="Description">
<Textarea @value={{this.purchaseOrder.description}} aria-label="Description" class="w-full form-input" placeholder="Description" rows={{5}} />
</InputGroup>
<InputGroup @name="Purchase order comments">
<InputGroup @name="Comments">
<Textarea @value={{this.purchaseOrder.comments}} aria-label="Comments" class="w-full form-input" placeholder="Comments" rows={{5}} />
</InputGroup>
<InputGroup @name="Delivery date" @type="date" @value={{this.purchaseOrder.deliveredAt}} />
<InputGroup @name="Expected Delivery Date">
<input value={{this.purchaseOrder.expectedDeliveryDate}} type="date" class="form-input w-full" {{on "change" this.setExpectedDeliveryDate}} />
</InputGroup>
</div>
</Overlay::Body>
</Overlay>
12 changes: 7 additions & 5 deletions addon/components/purchase-order-form-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,10 +143,12 @@ export default class PurchaseOrderFormPanelComponent extends Component {
@action onPressCancel() {
return contextComponentCallback(this, 'onPressCancel', this.purchaseOrder);
}

@action setExpectedDeliveryDate(event) {
const {
target: { value },
} = event;

/**
* Uploads a file to the server for the purchaseOrder.
*
* @param {File} file
*/
this.purchaseOrder.set('expected_delivery_at', new Date(value));
}
}
28 changes: 2 additions & 26 deletions addon/components/purchase-order-panel/details.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,10 @@
<div class="field-name">ID</div>
<div class="field-value">{{n-a @purchaseOrder.public_id}}</div>
</div>
<div class="field-info-container col-span-2">
<div class="field-name">Company</div>
<div class="field-value">{{n-a @purchaseOrder.company.name}}</div>
</div>
<div class="field-info-container">
<div class="field-name">Created By</div>
<div class="field-value">{{n-a @purchaseOrder.createdBy.name}}</div>
</div>
<div class="field-info-container">
<div class="field-name">Supplier</div>
<div class="field-value">{{n-a @purchaseOrder.supplier.name}}</div>
</div>
<div class="field-info-container">
<div class="field-name">Transaction</div>
<div class="field-value">{{n-a @purchaseOrder.transaction.name}}</div>
</div>
<div class="field-info-container">
<div class="field-name">Assigned To</div>
<div class="field-value">{{n-a @purchaseOrder.assignedTo.name}}</div>
</div>
<div class="field-info-container">
<div class="field-name">Point of Contact</div>
<div class="field-value">{{n-a @purchaseOrder.pointOfContact.name}}</div>
</div>
<div class="field-info-container">
<div class="field-name">Reference Code</div>
<div class="field-value">{{n-a @purchaseOrder.reference_code}}</div>
Expand All @@ -45,21 +25,17 @@
<div class="field-name">Comments</div>
<div class="field-value">{{n-a @purchaseOrder.comments}}</div>
</div>
<div class="field-info-container">
<div class="field-name">Currency</div>
<div class="field-value">{{n-a @purchaseOrder.currency}}</div>
</div>
<div class="field-info-container">
<div class="field-name">Status</div>
<div class="field-value">{{n-a @purchaseOrder.status}}</div>
</div>
<div class="field-info-container">
<div class="field-name">Order Created At</div>
<div class="field-value">{{n-a @purchaseOrder.orderCreatedAt}}</div>
<div class="field-value">{{n-a @purchaseOrder.created_at}}</div>
</div>
<div class="field-info-container">
<div class="field-name">Expected Delivery At</div>
<div class="field-value">{{n-a @purchaseOrder.expectedDeliveryAt}}</div>
<div class="field-value">{{n-a @purchaseOrder.expected_delivery_at}}</div>
</div>
</div>
</ContentPanel>
Expand Down
8 changes: 5 additions & 3 deletions addon/components/sales-order-form-panel.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,15 @@
</InputGroup>
<InputGroup @name="Reference Code" @type="text" @value={{this.salesOrder.reference_code}} />
<InputGroup @name="Reference URL" @type="text" @value={{this.salesOrder.reference_url}} />
<InputGroup @name="Sales order description">
<InputGroup @name="Sale Description">
<Textarea @value={{this.salesOrder.description}} aria-label="Description" class="w-full form-input" placeholder="Description" rows={{5}} />
</InputGroup>
<InputGroup @name="Sales order comments">
<InputGroup @name="Comments">
<Textarea @value={{this.salesOrder.comments}} aria-label="Comments" class="w-full form-input" placeholder="Comments" rows={{5}} />
</InputGroup>
<InputGroup @name="Delivery date" @type="date" @value={{this.salesOrder.expected_delivery_at}} />
<InputGroup @name="Expected Delivery Date">
<input value={{this.salesOrder.expectedDeliveryDate}} type="date" class="form-input w-full" {{on "change" this.setExpectedDeliveryDate}} />
</InputGroup>
</div>
</Overlay::Body>
</Overlay>
8 changes: 8 additions & 0 deletions addon/components/sales-order-form-panel.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down Expand Up @@ -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));
}
}
2 changes: 1 addition & 1 deletion addon/components/supplier-form-panel.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@
@triggerClass="form-select form-input"
@infiniteScroll={{false}}
@renderInPlace={{true}}
@onChange={{this.selectSupplierAddress}}
@onChange={{this.supplier.place.address}}
as |model|
>
<div class="flex items-center flex-row justify-between">
Expand Down
12 changes: 4 additions & 8 deletions addon/controllers/products/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ export default class ProductsIndexController extends Controller {
'query',
'internal_id',
'public_id',
'supplier',
'sku',
'created_at',
'updated_at',
Expand Down Expand Up @@ -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`
*
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion addon/controllers/purchase-orders/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion addon/controllers/purchase-orders/index/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
5 changes: 2 additions & 3 deletions addon/controllers/sales-orders/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -77,7 +77,6 @@ export default class SalesOrdersIndexController extends Controller {
*/
@tracked page = 1;

@tracked supplier;

/**
* The maximum number of items to show per page
Expand Down Expand Up @@ -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',
},
Expand Down
2 changes: 1 addition & 1 deletion addon/controllers/sales-orders/index/new.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
30 changes: 30 additions & 0 deletions addon/models/inventory.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
Expand All @@ -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');
}
}
Loading

0 comments on commit 2a959e9

Please sign in to comment.