From ed32db6e8fca5dc7c0f0ba971606d8b35e1dc1ea Mon Sep 17 00:00:00 2001 From: TemuulenBM Date: Thu, 16 Nov 2023 18:01:47 +0800 Subject: [PATCH] added delete_at column on the tables and created supplier --- addon/components/sales-order-form-panel.hbs | 42 ++- addon/components/sales-order-form-panel.js | 158 ++++++++++- addon/components/sales-order-panel.hbs | 53 +++- addon/components/sales-order-panel.js | 159 ++++++++++- .../components/sales-order-panel/details.hbs | 42 +++ addon/components/supplier-form-panel.hbs | 89 +++++- addon/components/supplier-form-panel.js | 189 ++++++++++++- .../supplier-form-panel/create-form.hbs | 175 ++++++++++++ .../supplier-form-panel/create-form.js | 158 +++++++++++ .../supplier-form-panel/edit-form.hbs | 98 +++++++ .../supplier-form-panel/edit-form.js | 51 ++++ addon/components/supplier-panel.hbs | 73 ++++- addon/components/supplier-panel.js | 160 ++++++++++- addon/components/supplier-panel/details.hbs | 77 +++++ addon/components/supplier-panel/details.js | 12 + addon/controllers/sales-orders/index.js | 28 +- .../controllers/sales-orders/index/details.js | 54 +++- addon/controllers/sales-orders/index/edit.js | 110 +++++++- addon/controllers/sales-orders/index/new.js | 87 +++++- addon/controllers/suppliers/index.js | 267 +++++++++++++++--- addon/controllers/suppliers/index/details.js | 2 +- addon/controllers/suppliers/index/edit.js | 24 +- addon/controllers/suppliers/index/new.js | 24 +- addon/models/sales-order.js | 62 +++- addon/models/supplier.js | 4 +- addon/routes.js | 24 +- addon/routes/sales-orders/index.js | 2 +- addon/routes/sales-orders/index/details.js | 14 +- addon/routes/sales-orders/index/edit.js | 8 +- addon/serializers/sales-order.js | 11 +- addon/serializers/supplier.js | 14 +- addon/services/context-panel.js | 30 ++ .../templates/sales-orders/index/details.hbs | 3 +- addon/templates/sales-orders/index/edit.hbs | 3 +- addon/templates/sales-orders/index/new.hbs | 3 +- addon/utils/get-supplier-status-options.js | 3 + addon/utils/get-supplier-type-options.js | 41 +++ .../supplier-form-panel/create-form.js | 1 + .../supplier-form-panel/edit-form.js | 1 + app/components/supplier-panel/details.js | 1 + app/utils/get-supplier-status-options.js | 1 + app/utils/get-supplier-type-options.js | 1 + .../2023_11_15_023331_create_audits_table.php | 7 +- ...2023_11_15_023340_create_batches_table.php | 3 +- ...23_11_15_023348_create_inventory_table.php | 3 +- ...15_023356_create_purchase_orders_table.php | 2 + ...11_15_023404_create_sales_orders_table.php | 2 + ...023411_create_stock_transactions_table.php | 3 +- ...5_034937_create_stock_adjustment_table.php | 3 +- server/src/Models/SalesOrder.php | 16 +- server/src/routes.php | 9 +- .../supplier-form-panel/create-form-test.js | 26 ++ .../supplier-form-panel/edit-form-test.js | 26 ++ .../components/supplier-panel/details-test.js | 26 ++ .../utils/get-supplier-status-options-test.js | 10 + .../utils/get-supplier-type-options-test.js | 10 + 56 files changed, 2362 insertions(+), 143 deletions(-) create mode 100644 addon/components/supplier-form-panel/create-form.hbs create mode 100644 addon/components/supplier-form-panel/create-form.js create mode 100644 addon/components/supplier-form-panel/edit-form.hbs create mode 100644 addon/components/supplier-form-panel/edit-form.js create mode 100644 addon/components/supplier-panel/details.js create mode 100644 addon/utils/get-supplier-status-options.js create mode 100644 addon/utils/get-supplier-type-options.js create mode 100644 app/components/supplier-form-panel/create-form.js create mode 100644 app/components/supplier-form-panel/edit-form.js create mode 100644 app/components/supplier-panel/details.js create mode 100644 app/utils/get-supplier-status-options.js create mode 100644 app/utils/get-supplier-type-options.js create mode 100644 tests/integration/components/supplier-form-panel/create-form-test.js create mode 100644 tests/integration/components/supplier-form-panel/edit-form-test.js create mode 100644 tests/integration/components/supplier-panel/details-test.js create mode 100644 tests/unit/utils/get-supplier-status-options-test.js create mode 100644 tests/unit/utils/get-supplier-type-options-test.js diff --git a/addon/components/sales-order-form-panel.hbs b/addon/components/sales-order-form-panel.hbs index fb5c4b15..8b6ada56 100644 --- a/addon/components/sales-order-form-panel.hbs +++ b/addon/components/sales-order-form-panel.hbs @@ -1 +1,41 @@ -{{yield}} \ No newline at end of file + + +
+
+ {{#if this.salesOrder.id}} +
+
+
+
+
+
+
+
+ +
+
+
+ + +
+ +
+ + + + {{else}} + + {{/if}} + {{/each}} + + + + + + + {{#if this.showAdvancedOptions}} +
+ + + +
+ {{/if}} +
+ {{else}} +
+

Select an integrated supplier provider.

+
+ {{/if}} + {{else}} + + + + + + +
+ + {{smart-humanize type}} + +
+
+ +
+ + {{smart-humanize status}} + +
+
+ +
+ +
+
+
+ +
+
{{n-a model.address}}
+ {{model.public_id}} +
+
+
+ + + +
+ {{/if}} + {{/if}} +
\ No newline at end of file diff --git a/addon/components/supplier-form-panel/create-form.js b/addon/components/supplier-form-panel/create-form.js new file mode 100644 index 00000000..357e1cce --- /dev/null +++ b/addon/components/supplier-form-panel/create-form.js @@ -0,0 +1,158 @@ +import Component from '@glimmer/component'; +import { tracked } from '@glimmer/tracking'; +import { inject as service } from '@ember/service'; +import { action } from '@ember/object'; +import { isArray } from '@ember/array'; +import apiUrl from '@fleetbase/ember-core/utils/api-url'; +import contextComponentCallback from '../../utils/context-component-callback'; + +export default class SupplierFormPanelCreateFormComponent extends Component { + /** + * @service store + */ + @service store; + + /** + * @service fetch + */ + @service fetch; + + /** + * @service contextPanel + */ + @service contextPanel; + /** + * State of whether editing credentials is enabled. + * @type {Boolean} + */ + @tracked isEditingCredentials = false; + + /** + * State of whether to show advanced options for integrated supplier. + * @type {Boolean} + */ + @tracked showAdvancedOptions = false; + + /** + * The selectable types of suppliers. + * @type {Array} + */ + @tracked supplierTypes = [ + { label: 'Choose a integrated supplier', value: 'integrated-supplier' }, + { label: 'Create a custom supplier', value: 'supplier' }, + ]; + + /** + * The selected type of supplier being created or edited. + * @type {String} + */ + @tracked selectedSupplierType = this.supplierTypes[1]; + + /** + * The supported integrated suppliers. + * @type {Array} + */ + @tracked supportedIntegratedSuppliers = []; + + /** + * The selected integrated supplier provider. + * @type {Object} + */ + @tracked selectedIntegratedSupplier; + + constructor() { + super(...arguments); + this.supplier = this.args.supplier; + this.fetchSupportedIntegratedSuppliers(); + } + + @action toggleCredentialsReset() { + if (this.isEditingCredentials) { + this.isEditingCredentials = false; + } else { + this.isEditingCredentials = true; + } + } + + @action toggleAdvancedOptions() { + if (this.showAdvancedOptions) { + this.showAdvancedOptions = false; + } else { + this.showAdvancedOptions = true; + } + } + + @action onSelectSupplierType(selectedSupplierType) { + this.selectedSupplierType = selectedSupplierType; + } + + @action onSelectIntegratedSupplier(integratedSupplier) { + this.selectedIntegratedSupplier = integratedSupplier; + const { credential_params, option_params } = integratedSupplier; + + // create credentials object + const credentials = {}; + if (isArray(integratedSupplier.credential_params)) { + for (let i = 0; i < integratedSupplier.credential_params.length; i++) { + const param = integratedSupplier.credential_params.objectAt(i); + credentials[param] = null; + } + } + + // create options object + const options = {}; + if (isArray(integratedSupplier.option_params)) { + for (let i = 0; i < integratedSupplier.option_params.length; i++) { + const param = integratedSupplier.option_params.objectAt(i); + options[param.key] = null; + } + } + + const supplier = this.store.createRecord('integrated-supplier', { + provider: integratedSupplier.code, + webhook_url: apiUrl(`listeners/${integratedSupplier.code}`), + credentials: {}, + options: {}, + credential_params, + option_params, + }); + + this.supplier = supplier; + + // trigger callback + contextComponentCallback(this, 'onSupplierChanged', supplier); + } + + @action selectSupplierAddress(warehouse) { + this.supplier.warehouse = warehouse; + this.supplier.warehouse_uuid = warehouse.id; + } + + @action async editAddress() { + let warehouse; + + if (this.supplier.has_warehouse) { + warehouse = await this.supplier.warehouse; + } else { + warehouse = this.store.createRecord('warehouse'); + } + + return this.contextPanel.focus(warehouse, 'editing', { + onAfterSave: (warehouse) => { + this.supplier.warehouse = warehouse; + this.contextPanel.clear(); + }, + }); + } + + /** + * Fetches the supported integrated suppliers. + * + * @returns {Promise} + */ + fetchSupportedIntegratedSuppliers() { + return this.fetch.get('integrated-suppliers/supported').then((supportedIntegratedSuppliers) => { + this.supportedIntegratedSuppliers = supportedIntegratedSuppliers; + }); + } +} diff --git a/addon/components/supplier-form-panel/edit-form.hbs b/addon/components/supplier-form-panel/edit-form.hbs new file mode 100644 index 00000000..593101a7 --- /dev/null +++ b/addon/components/supplier-form-panel/edit-form.hbs @@ -0,0 +1,98 @@ +
+ {{#if this.isIntegratedSupplier}} + +
+ {{this.supplier.provider_settings.code}} +

{{this.supplier.provider_settings.name}}

+
+
+ + {{#if this.isEditingCredentials}} + {{#each this.supplier.provider_settings.credential_params as |param|}} + + {{/each}} + + {{else}} +
+

Sensitive credentials can only be reset, to update credentials you must re-enter the credentials.

+ Click here to reset credentials +
+
+ {{#each this.supplier.provider_settings.credential_params as |param|}} + + {{/each}} +
+ {{/if}} +
+ + {{#each this.supplier.provider_settings.option_params as |param|}} + {{#if param.options}} + +