This commit is contained in:
2021-06-01 23:58:19 +00:00
parent 73d6c7c219
commit 2ddf8b9ddf
4 changed files with 80 additions and 7 deletions

View File

@@ -79,6 +79,8 @@ todo: Contract override by TAGS
todo: form field customization add a "reset" feature to reset to default for when people fuck it up
basically just show all fields and remove the required from fields
todo: add NOW button to date picker just like time picker that does the same thing
todo: Not in love with the "Error api2200" as the only error text in the box
sometimes it has things you can't see in the form
ideally I'd like to see it have a string of text as a duplicate showing the errors translated in a list

View File

@@ -179,6 +179,25 @@ export default {
return true;
},
///////////////////////////////
// ROUNDING
// //https://medium.com/swlh/how-to-round-to-a-certain-number-of-decimal-places-in-javascript-ed74c471c1b8
roundAccurately: function(number, decimalPlaces) {
if (!number || number == 0 || number == NaN) {
return number;
}
let wasNegative = number < 0;
if (wasNegative) {
number = Match.abs(number); //make sure it's positive because rounding negative numbers is weird in JS
}
number = Number(
Math.round(number + "e" + decimalPlaces) + "e-" + decimalPlaces
);
if (wasNegative) {
number = 0 - number;
}
return number;
},
///////////////////////////////
// CLEAN TAG NAME
// Clean up a tag with same rules as server
//

View File

@@ -243,11 +243,47 @@ export default {
}
//instantiate a luxon date object from val which is assumed to be an iso string
let dt = window.$gz.DateTime.fromISO(val);
if (!dt.isValid) {
console.error("locale::addMinutes, input not valid:", {
val: val,
dt: dt
});
return val;
}
//add minutes
dt = dt.plus({ minutes: minutes });
return dt.toUTC().toString();
},
///////////////////////////////////////////////
// parse UTC ISO 8601 strings, diff, return hours
//
diffHoursFromUTC8601String(start, stop) {
if (!start || start == "" || !stop == null || stop == "") {
return 0;
}
//instantiate a luxon date object from val which is assumed to be an iso string
const startDate = window.$gz.DateTime.fromISO(start);
if (!startDate.isValid) {
console.error("locale::diffHours, start not valid:", {
start: start,
startDate: startDate
});
return 0;
}
const stopDate = window.$gz.DateTime.fromISO(stop);
if (!stopDate.isValid) {
console.error("locale::diffHours, start not valid:", {
stop: stop,
stopDate: stopDate
});
return 0;
}
return window.$gz.util.roundAccurately(
stopDate.diff(startDate, "hours").toObject().hours,
2
);
},
///////////////////////////////////////////////
// Local now timestamp converted to timeZoneName
// and output as ISO 8601
// (used to inform server of local client time)

View File

@@ -408,17 +408,33 @@ export default {
}
},
handleStartDateChange: function(isNew) {
const dt = this.value.items[this.activeWoItemIndex].scheduledUsers[
const dStart = this.value.items[this.activeWoItemIndex].scheduledUsers[
this.activeItemIndex
].startDate;
console.log("IsNew:", isNew);
const globalMinutes =
window.$gz.store.state.globalSettings.workLaborScheduleDefaultMinutes;
if (globalMinutes == 0) {
return;
if (isNew) {
// (ONLY IF GLOBAL DEFAULT QTY) enter start date when stop date is null then it will add global default to start and set stop and qty
// (ONLY IF GLOBAL DEFAULT QTY) enter stop date when start date is null then it will back calc and set start and qty based on global default
// If no global default then it acts like existing and updates qty or stop date when qty changes (if there are dates to go on)
const globalMinutes =
window.$gz.store.state.globalSettings.workLaborScheduleDefaultMinutes;
if (globalMinutes == 0) {
return;
}
let d = window.$gz.locale.addMinutesToUTC8601String(dStart);
} else {
const dStop = this.value.items[this.activeWoItemIndex].scheduledUsers[
this.activeItemIndex
].stopDate;
// Existing
// update quantity when dates change or update stop date when quantity changes to match
// no consideration for global default, once it's made that shit doesn't apply
console.log(
"existing record - DIFF HOURS IS:",
window.$gz.locale.diffHoursFromUTC8601String(dStart, dStop)
);
}
let d = window.$gz.locale.addMinutesToUTC8601String(dt);
},
handleStopDateChange: function(isNew) {
let val = this.value.items[this.activeWoItemIndex].scheduledUsers[