From 579b2addd36a89204dc68413389777b20c49876f Mon Sep 17 00:00:00 2001 From: John Cardinal Date: Wed, 2 Jun 2021 16:02:03 +0000 Subject: [PATCH] --- .../src/components/work-order-item-labors.vue | 3 +- .../components/work-order-item-travels.vue | 85 ++++++++++++++++++- 2 files changed, 83 insertions(+), 5 deletions(-) diff --git a/ayanova/src/components/work-order-item-labors.vue b/ayanova/src/components/work-order-item-labors.vue index 08759d61..3e337317 100644 --- a/ayanova/src/components/work-order-item-labors.vue +++ b/ayanova/src/components/work-order-item-labors.vue @@ -482,7 +482,7 @@ export default { // serviceStopDate: window.$gz.locale.nowUTC8601String(), //TODO:sb now plus one hour to match v7 serviceRateId: null, serviceDetails: null, - serviceRateQuantity: 1, + serviceRateQuantity: 0, noChargeQuantity: 0, serviceBankId: null, taxCodeSaleId: null, @@ -605,7 +605,6 @@ export default { } else { //Existing record or both dates filled, just update quantity if (dStart != null) { - console.log("setting serviceRateQuantity"); this.value.items[this.activeWoItemIndex].labors[ this.activeItemIndex ].serviceRateQuantity = window.$gz.locale.diffHoursFromUTC8601String( diff --git a/ayanova/src/components/work-order-item-travels.vue b/ayanova/src/components/work-order-item-travels.vue index c40e3a5e..fcf5b6ad 100644 --- a/ayanova/src/components/work-order-item-travels.vue +++ b/ayanova/src/components/work-order-item-travels.vue @@ -475,11 +475,11 @@ export default { id: 0, concurrency: 0, userId: null, - travelStartDate: window.$gz.locale.nowUTC8601String(), - travelStopDate: window.$gz.locale.nowUTC8601String(), //TODO:sb now plus one hour to match v7 + travelStartDate: null, + travelStopDate: null, travelRateId: null, travelDetails: null, - travelRateQuantity: 1, + travelRateQuantity: 0, noChargeQuantity: 0, serviceBankId: null, taxCodeSaleId: null, @@ -530,6 +530,85 @@ export default { this.activeItemIndex ].isDirty = true; window.$gz.form.fieldValueChanged(this.pvm, ref); + //------- SPECIAL HANDLING OF CHANGES ----------- + const isNew = + this.value.items[this.activeWoItemIndex].travels[this.activeItemIndex] + .id == 0; + + //Auto calculate dates / quantities / global defaults + const dStart = this.value.items[this.activeWoItemIndex].travels[ + this.activeItemIndex + ].travelStartDate; + const dStop = this.value.items[this.activeWoItemIndex].travels[ + this.activeItemIndex + ].travelStopDate; + if (ref.includes("travelStartDate") && dStart != null) { + this.handleStartDateChange(isNew, dStart, dStop); + } + if (ref.includes("travelStopDate") && dStop != null) { + this.handleStopDateChange(isNew, dStart, dStop); + } + //------------------------------------------------------ + } + }, + handleStartDateChange: function(isNew, dStart, dStop) { + const globalMinutes = + window.$gz.store.state.globalSettings.workOrderTravelDefaultMinutes; + + if (isNew && dStop == null) { + if (globalMinutes != 0) { + //set stop date based on start date and global minutes + this.value.items[this.activeWoItemIndex].travels[ + this.activeItemIndex + ].travelStopDate = window.$gz.locale.addMinutesToUTC8601String( + dStart, + globalMinutes + ); + + this.value.items[this.activeWoItemIndex].travels[ + this.activeItemIndex + ].travelRateQuantity = globalMinutes; + } + } else { + //Existing record or both dates filled, just update quantity + if (dStop != null) { + this.value.items[this.activeWoItemIndex].travels[ + this.activeItemIndex + ].travelRateQuantity = window.$gz.locale.diffHoursFromUTC8601String( + dStart, + dStop + ); + } + } + }, + handleStopDateChange: function(isNew, dStart, dStop) { + const globalMinutes = + window.$gz.store.state.globalSettings.workOrderTravelDefaultMinutes; + + if (isNew && dStart == null) { + if (globalMinutes != 0) { + //set start date based on stop date and global minutes + this.value.items[this.activeWoItemIndex].travels[ + this.activeItemIndex + ].travelStartDate = window.$gz.locale.addMinutesToUTC8601String( + dStop, + 0 - globalMinutes + ); + + this.value.items[this.activeWoItemIndex].travels[ + this.activeItemIndex + ].travelRateQuantity = globalMinutes; + } + } else { + //Existing record or both dates filled, just update quantity + if (dStart != null) { + this.value.items[this.activeWoItemIndex].travels[ + this.activeItemIndex + ].travelRateQuantity = window.$gz.locale.diffHoursFromUTC8601String( + dStart, + dStop + ); + } } }, itemRowClasses: function(item) {