2022-11-16 01:44:39 +00:00
|
|
|
import './style.scss';
|
2015-02-01 03:21:54 +00:00
|
|
|
|
2022-11-16 01:44:39 +00:00
|
|
|
export default new Class({
|
2018-05-16 09:36:42 +00:00
|
|
|
Extends: Hedera.Form,
|
2022-11-16 01:44:39 +00:00
|
|
|
Template: require('./ui.xml'),
|
2015-02-01 03:21:54 +00:00
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
activate() {
|
2015-07-10 12:30:08 +00:00
|
|
|
this.autoStepLocked = true;
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.assistant.stepsIndex = this.agencySteps;
|
2015-07-23 15:58:48 +00:00
|
|
|
|
2023-10-09 19:01:11 +00:00
|
|
|
this.today = Date.vnNew();
|
2018-05-16 09:36:42 +00:00
|
|
|
this.today.setHours(0, 0, 0, 0);
|
|
|
|
},
|
2015-07-15 13:39:07 +00:00
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
onValuesReady() {
|
2022-07-15 05:55:18 +00:00
|
|
|
const orderForm = this.$.orderForm;
|
|
|
|
const defaultsForm = this.$.defaults;
|
2015-07-10 12:30:08 +00:00
|
|
|
|
2015-07-15 13:39:07 +00:00
|
|
|
if (!(orderForm.ready && defaultsForm.ready))
|
|
|
|
return;
|
2015-08-27 14:04:34 +00:00
|
|
|
|
2022-07-15 05:55:18 +00:00
|
|
|
let date;
|
|
|
|
const row = orderForm.$ || defaultsForm.$ || {};
|
2015-08-27 14:04:34 +00:00
|
|
|
|
2023-10-09 19:01:11 +00:00
|
|
|
if (!date || date.getTime() < (Date.vnNew()).getTime()) {
|
|
|
|
date = Date.vnNew();
|
2020-05-04 19:55:18 +00:00
|
|
|
date.setHours(0, 0, 0, 0);
|
|
|
|
|
2022-07-15 05:55:18 +00:00
|
|
|
let addDays = 0;
|
2018-09-14 13:13:28 +00:00
|
|
|
|
|
|
|
switch(date.getDay()) {
|
|
|
|
case 6: // Saturday
|
|
|
|
addDays += 2;
|
|
|
|
break;
|
|
|
|
case 0: // Sunday
|
|
|
|
addDays++;
|
|
|
|
break;
|
|
|
|
}
|
2015-08-27 14:04:34 +00:00
|
|
|
|
2022-05-28 15:49:46 +00:00
|
|
|
if (row.deliveryMethod != 'PICKUP')
|
2018-09-14 13:13:28 +00:00
|
|
|
addDays++;
|
|
|
|
|
2020-05-04 19:55:18 +00:00
|
|
|
date.setDate(date.getDate() + addDays);
|
2015-07-10 12:30:08 +00:00
|
|
|
}
|
2015-07-15 13:39:07 +00:00
|
|
|
|
2022-05-30 01:30:33 +00:00
|
|
|
this.$.lot.assign({
|
2023-01-30 10:08:26 +00:00
|
|
|
date,
|
2022-05-30 01:30:33 +00:00
|
|
|
method: row.deliveryMethod,
|
|
|
|
agency: row.agencyModeFk,
|
|
|
|
address: row.addressFk
|
|
|
|
});
|
2015-07-15 13:39:07 +00:00
|
|
|
this.autoStepLocked = false;
|
2018-05-16 09:36:42 +00:00
|
|
|
},
|
2015-12-10 13:48:43 +00:00
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
disableButtons(disable) {
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.assistantBar.disabled = disable;
|
2018-05-16 09:36:42 +00:00
|
|
|
},
|
2015-07-15 13:39:07 +00:00
|
|
|
|
2022-11-28 08:51:31 +00:00
|
|
|
async onConfirmClick() {
|
2018-05-16 09:36:42 +00:00
|
|
|
this.disableButtons(true);
|
2015-12-10 13:48:43 +00:00
|
|
|
|
2023-02-15 13:07:09 +00:00
|
|
|
let id = this.$.params.$.id;
|
2023-01-30 10:08:26 +00:00
|
|
|
const params = Object.assign({}, this.$.lot.$);
|
|
|
|
|
|
|
|
let query;
|
|
|
|
if (id) {
|
|
|
|
params.id = id;
|
|
|
|
query = 'CALL myOrder_configure(#id, #date, #method, #agency, #address)';
|
|
|
|
} else {
|
2023-02-15 13:07:09 +00:00
|
|
|
query = 'CALL myOrder_create(@orderId, #date, #method, #agency, #address); SELECT @orderId;';
|
2023-01-30 10:08:26 +00:00
|
|
|
}
|
|
|
|
|
2022-11-28 08:51:31 +00:00
|
|
|
let resultSet;
|
|
|
|
|
|
|
|
try {
|
2023-01-30 10:08:26 +00:00
|
|
|
resultSet = await this.conn.execQuery(query, params);
|
2022-11-28 08:51:31 +00:00
|
|
|
} finally {
|
|
|
|
this.disableButtons(false);
|
|
|
|
}
|
2015-12-10 13:48:43 +00:00
|
|
|
|
2018-05-16 09:36:42 +00:00
|
|
|
if (!resultSet.fetchResult())
|
2015-07-15 13:39:07 +00:00
|
|
|
return;
|
|
|
|
|
2023-02-23 19:19:56 +00:00
|
|
|
let redirect;
|
|
|
|
const basket = new Hedera.Basket(this.app);
|
|
|
|
|
2023-02-15 13:07:09 +00:00
|
|
|
if (id) {
|
2018-05-16 09:36:42 +00:00
|
|
|
Htk.Toast.showMessage(_('OrderUpdated'));
|
2015-09-30 06:45:42 +00:00
|
|
|
|
2023-02-15 13:07:09 +00:00
|
|
|
switch(this.hash.$.continue) {
|
|
|
|
case 'catalog':
|
2023-02-23 19:19:56 +00:00
|
|
|
redirect = {form: 'ecomerce/catalog'};
|
2023-02-15 13:07:09 +00:00
|
|
|
break;
|
|
|
|
default:
|
2023-02-23 19:19:56 +00:00
|
|
|
redirect = {form: 'ecomerce/basket'};
|
|
|
|
if (id !== basket.orderId)
|
|
|
|
redirect.id = id;
|
2023-02-15 13:07:09 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
basket.loadIntoBasket(resultSet.fetchValue());
|
2023-02-23 19:19:56 +00:00
|
|
|
redirect = {form: 'ecomerce/catalog'};
|
2023-02-15 13:07:09 +00:00
|
|
|
}
|
2023-02-23 19:19:56 +00:00
|
|
|
|
|
|
|
this.hash.setAll(redirect);
|
2018-05-16 09:36:42 +00:00
|
|
|
},
|
2015-07-10 12:30:08 +00:00
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
onCancelClick() {
|
2023-01-30 10:08:26 +00:00
|
|
|
if (this.$.params.$.id)
|
2015-09-30 06:45:42 +00:00
|
|
|
window.history.back();
|
2015-07-15 13:39:07 +00:00
|
|
|
else
|
2022-05-30 01:30:33 +00:00
|
|
|
this.hash.setAll({form: 'ecomerce/orders'});
|
2018-05-16 09:36:42 +00:00
|
|
|
},
|
2015-06-30 12:06:19 +00:00
|
|
|
|
2018-05-16 09:36:42 +00:00
|
|
|
agencySteps: ['method', 'date', 'address', 'agency', 'confirm-delivery'],
|
|
|
|
pickupSteps: ['method', 'date', 'address', 'pickup', 'confirm-pickup'],
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
isDelivery() {
|
2022-05-28 01:18:06 +00:00
|
|
|
return this.$.rgMethod.value != 'PICKUP';
|
2018-05-16 09:36:42 +00:00
|
|
|
},
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
onMethodChange() {
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.assistant.stepsIndex = this.isDelivery() ?
|
2018-05-16 09:36:42 +00:00
|
|
|
this.agencySteps : this.pickupSteps;
|
|
|
|
this.onFieldChange();
|
|
|
|
},
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
methodValidate() {
|
2022-05-28 01:18:06 +00:00
|
|
|
if (!this.$.rgMethod.isSelected())
|
2018-05-16 09:36:42 +00:00
|
|
|
throw new Error(_('Please select an option'));
|
|
|
|
},
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
dateShow() {
|
2022-05-28 01:18:06 +00:00
|
|
|
Vn.Node.setText(this.$.dateQuestion, this.isDelivery() ?
|
2018-05-16 09:36:42 +00:00
|
|
|
_('OrderDateDeliveryQuestion'):
|
|
|
|
_('OrderDatePickupQuestion'));
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.calendar.goToSelectedMonth();
|
2018-05-16 09:36:42 +00:00
|
|
|
},
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
dateValidate() {
|
2022-05-28 01:18:06 +00:00
|
|
|
if (!this.$.calendar.value)
|
2018-05-16 09:36:42 +00:00
|
|
|
throw new Error(_('Please select a date'));
|
|
|
|
},
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
addressShow() {
|
2022-05-28 01:18:06 +00:00
|
|
|
Vn.Node.setText(this.$.addressQuestion, this.isDelivery() ?
|
2018-05-16 09:36:42 +00:00
|
|
|
_('AddressQuestion'):
|
|
|
|
_('AddressQuestionPickup'));
|
|
|
|
},
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
addressValidate() {
|
2022-05-28 01:18:06 +00:00
|
|
|
if (this.$.addressForm.row == -1)
|
2018-05-16 09:36:42 +00:00
|
|
|
throw new Error(_('Please select an address'));
|
|
|
|
},
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
agencyShow() {
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.agencies.refresh();
|
2018-05-16 09:36:42 +00:00
|
|
|
},
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
agencyValidate() {
|
2022-05-28 01:18:06 +00:00
|
|
|
if (this.$.agencyCombo.row == -1 && this.isDelivery())
|
2018-05-16 09:36:42 +00:00
|
|
|
throw new Error(_('Please select an agency'));
|
|
|
|
},
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
pickupShow() {
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.warehouses.refresh();
|
2018-05-16 09:36:42 +00:00
|
|
|
},
|
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
pickupValidate() {
|
2022-05-28 01:18:06 +00:00
|
|
|
if (this.$.warehouseCombo.row == -1)
|
2018-05-16 09:36:42 +00:00
|
|
|
throw new Error(_('Please select a store'));
|
|
|
|
},
|
2015-06-30 12:06:19 +00:00
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
onFieldChange() {
|
2015-07-10 12:30:08 +00:00
|
|
|
if (!this.autoStepLocked)
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.assistant.moveNext();
|
2018-05-16 09:36:42 +00:00
|
|
|
},
|
2015-03-27 19:10:49 +00:00
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
onAddressClick(addressId) {
|
2022-05-30 01:30:33 +00:00
|
|
|
this.$.lot.set('address', addressId);
|
2022-12-09 11:51:51 +00:00
|
|
|
this.$.assistant.moveNext();
|
2018-05-16 09:36:42 +00:00
|
|
|
},
|
2015-06-30 12:06:19 +00:00
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
onAddressChange() {
|
2015-07-23 15:58:48 +00:00
|
|
|
if (this.selectedNode)
|
2018-05-16 09:36:42 +00:00
|
|
|
Vn.Node.removeClass(this.selectedNode, 'selected');
|
2015-07-23 15:58:48 +00:00
|
|
|
|
2022-07-15 05:55:18 +00:00
|
|
|
const row = this.$.addresses.search('id', this.$.lot.$.address);
|
2015-07-23 15:58:48 +00:00
|
|
|
|
2018-05-16 09:36:42 +00:00
|
|
|
if (row != -1) {
|
2022-07-15 05:55:18 +00:00
|
|
|
const builder = this.$.repeater.getBuilder(row);
|
2015-07-23 15:58:48 +00:00
|
|
|
|
2022-05-28 01:18:06 +00:00
|
|
|
this.selectedNode = builder.$.address;
|
2018-05-16 09:36:42 +00:00
|
|
|
Vn.Node.addClass(this.selectedNode, 'selected');
|
2015-07-23 15:58:48 +00:00
|
|
|
}
|
|
|
|
|
2022-05-28 01:18:06 +00:00
|
|
|
this.$.addressForm.row = row;
|
2018-05-16 09:36:42 +00:00
|
|
|
},
|
2015-07-15 13:39:07 +00:00
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
onAgenciesReady(model) {
|
2022-11-29 18:13:32 +00:00
|
|
|
this.selectAgency(model, 'NoAgeciesAvailableForDate');
|
|
|
|
},
|
|
|
|
|
|
|
|
onWarehousesReady(model) {
|
|
|
|
this.selectAgency(model, 'NoWarehousesAvailableForDate');
|
|
|
|
},
|
|
|
|
|
|
|
|
selectAgency(model, emptyMessage) {
|
2018-09-14 13:13:28 +00:00
|
|
|
if (!model.ready) return;
|
2022-11-29 18:13:32 +00:00
|
|
|
let agencyId = null;
|
2018-09-14 13:13:28 +00:00
|
|
|
|
|
|
|
if (model.numRows > 0) {
|
2022-11-29 18:13:32 +00:00
|
|
|
const agencies = [this.$.lot.$.agency];
|
|
|
|
|
|
|
|
const defaults = this.$.defaults.$ || {};
|
|
|
|
if (defaults.agencyModeFk)
|
2022-12-01 08:04:33 +00:00
|
|
|
agencies.push(defaults.agencyModeFk);
|
2022-11-29 18:13:32 +00:00
|
|
|
if (defaults.defaultAgencyFk)
|
2022-12-01 08:04:33 +00:00
|
|
|
agencies.push(defaults.defaultAgencyFk);
|
2022-11-29 18:13:32 +00:00
|
|
|
|
|
|
|
for (const agency of agencies)
|
|
|
|
if (model.search('id', agency) !== -1) {
|
|
|
|
agencyId = agency;
|
|
|
|
break;
|
2018-09-14 13:13:28 +00:00
|
|
|
}
|
|
|
|
} else
|
2022-11-29 18:13:32 +00:00
|
|
|
Htk.Toast.showError(_(emptyMessage));
|
|
|
|
|
|
|
|
this.autoStepLocked = true;
|
|
|
|
this.$.lot.assign({agency: agencyId});
|
|
|
|
this.autoStepLocked = false;
|
2018-05-16 09:36:42 +00:00
|
|
|
},
|
2015-08-17 18:02:14 +00:00
|
|
|
|
2022-11-16 01:46:44 +00:00
|
|
|
calendarRestrict(date) {
|
2018-05-16 09:36:42 +00:00
|
|
|
return date.getTime() >= this.today.getTime();
|
2015-07-15 13:39:07 +00:00
|
|
|
}
|
2015-02-01 03:21:54 +00:00
|
|
|
});
|