re-factor / cleanup

This commit is contained in:
2022-01-11 22:08:38 +00:00
parent e871708b20
commit e0be8a7cfe
251 changed files with 14680 additions and 15693 deletions

View File

@@ -58,10 +58,10 @@
<!-- ############################################################### -->
<v-col cols="12" class="mb-10">
<v-data-table
v-model="selectedRow"
:headers="headerList"
:items="itemList"
item-key="index"
v-model="selectedRow"
class="elevation-1"
disable-pagination
disable-filtering
@@ -70,9 +70,9 @@
data-cy="laborsTable"
dense
:item-class="itemRowClasses"
@click:row="handleRowClick"
:show-select="$vuetify.breakpoint.xs"
single-select
@click:row="handleRowClick"
>
</v-data-table>
</v-col>
@@ -82,8 +82,8 @@
<v-btn
v-if="canDelete && isDeleted"
large
@click="unDeleteItem"
color="primary"
@click="unDeleteItem"
>{{ $ay.t("Undelete")
}}<v-icon right large>$ayiTrashRestoreAlt</v-icon></v-btn
>
@@ -96,16 +96,16 @@
xl="3"
>
<gz-date-time-picker
:label="$ay.t('WorkOrderItemLaborServiceStartDate')"
:ref="
`Items[${activeWoItemIndex}].labors[${activeItemIndex}].serviceStartDate`
"
v-model="
value.items[activeWoItemIndex].labors[activeItemIndex]
.serviceStartDate
"
:label="$ay.t('WorkOrderItemLaborServiceStartDate')"
:readonly="formState.readOnly"
:disabled="isDeleted"
:ref="
`Items[${activeWoItemIndex}].labors[${activeItemIndex}].serviceStartDate`
"
data-cy="serviceStartDate"
:error-messages="
form().serverErrors(
@@ -129,16 +129,16 @@
xl="3"
>
<gz-date-time-picker
:label="$ay.t('WorkOrderItemLaborServiceStopDate')"
:ref="
`Items[${activeWoItemIndex}].labors[${activeItemIndex}].serviceStopDate`
"
v-model="
value.items[activeWoItemIndex].labors[activeItemIndex]
.serviceStopDate
"
:label="$ay.t('WorkOrderItemLaborServiceStopDate')"
:readonly="formState.readOnly"
:disabled="isDeleted"
:ref="
`Items[${activeWoItemIndex}].labors[${activeItemIndex}].serviceStopDate`
"
data-cy="serviceStopDate"
:rules="[
form().datePrecedence(
@@ -169,6 +169,9 @@
xl="3"
>
<gz-decimal
:ref="
`Items[${activeWoItemIndex}].labors[${activeItemIndex}].serviceRateQuantity`
"
v-model="
value.items[activeWoItemIndex].labors[activeItemIndex]
.serviceRateQuantity
@@ -176,9 +179,6 @@
:readonly="formState.readOnly || isDeleted"
:disabled="isDeleted"
:label="$ay.t('WorkOrderItemLaborServiceRateQuantity')"
:ref="
`Items[${activeWoItemIndex}].labors[${activeItemIndex}].serviceRateQuantity`
"
data-cy="laborServiceRateQuantity"
:error-messages="
form().serverErrors(
@@ -212,19 +212,19 @@
xl="3"
>
<gz-pick-list
:aya-type="$ay.ayt().ServiceRate"
:variant="'contractid:' + value.contractId"
:show-edit-icon="!value.userIsRestrictedType"
:ref="
`Items[${activeWoItemIndex}].labors[${activeItemIndex}].serviceRateId`
"
v-model="
value.items[activeWoItemIndex].labors[activeItemIndex]
.serviceRateId
"
:aya-type="$ay.ayt().ServiceRate"
:variant="'contractid:' + value.contractId"
:show-edit-icon="!value.userIsRestrictedType"
:readonly="formState.readOnly || isDeleted"
:disabled="isDeleted"
:label="$ay.t('WorkOrderItemLaborServiceRateID')"
:ref="
`Items[${activeWoItemIndex}].labors[${activeItemIndex}].serviceRateId`
"
data-cy="labors.serviceRateId"
:error-messages="
form().serverErrors(
@@ -249,20 +249,20 @@
xl="3"
>
<gz-pick-list
:aya-type="$ay.ayt().User"
variant="tech"
:show-edit-icon="!value.userIsRestrictedType"
:ref="
`Items[${activeWoItemIndex}].labors[${activeItemIndex}].userId`
"
v-model="
value.items[activeWoItemIndex].labors[activeItemIndex].userId
"
:aya-type="$ay.ayt().User"
variant="tech"
:show-edit-icon="!value.userIsRestrictedType"
:readonly="
formState.readOnly || isDeleted || value.userIsRestrictedType
"
:disabled="isDeleted"
:label="$ay.t('WorkOrderItemLaborUserID')"
:ref="
`Items[${activeWoItemIndex}].labors[${activeItemIndex}].userId`
"
data-cy="labors.userid"
:error-messages="
form().serverErrors(
@@ -287,6 +287,9 @@
xl="3"
>
<gz-decimal
:ref="
`Items[${activeWoItemIndex}].labors[${activeItemIndex}].noChargeQuantity`
"
v-model="
value.items[activeWoItemIndex].labors[activeItemIndex]
.noChargeQuantity
@@ -294,9 +297,6 @@
:readonly="formState.readOnly || isDeleted"
:disabled="isDeleted"
:label="$ay.t('WorkOrderItemLaborNoChargeQuantity')"
:ref="
`Items[${activeWoItemIndex}].labors[${activeItemIndex}].noChargeQuantity`
"
data-cy="laborNoChargeQuantity"
:error-messages="
form().serverErrors(
@@ -333,18 +333,18 @@
xl="3"
>
<gz-pick-list
:aya-type="$ay.ayt().TaxCode"
show-edit-icon
:ref="
`Items[${activeWoItemIndex}].labors[${activeItemIndex}].taxCodeSaleId`
"
v-model="
value.items[activeWoItemIndex].labors[activeItemIndex]
.taxCodeSaleId
"
:aya-type="$ay.ayt().TaxCode"
show-edit-icon
:readonly="formState.readOnly || isDeleted"
:disabled="isDeleted"
:label="$ay.t('WorkOrderItemLaborTaxRateSaleID')"
:ref="
`Items[${activeWoItemIndex}].labors[${activeItemIndex}].taxCodeSaleId`
"
data-cy="laborTaxCodeSaleId"
:error-messages="
form().serverErrors(
@@ -372,6 +372,9 @@
xl="3"
>
<gz-currency
:ref="
`Items[${activeWoItemIndex}].labors[${activeItemIndex}].priceOverride`
"
v-model="
value.items[activeWoItemIndex].labors[activeItemIndex]
.priceOverride
@@ -380,9 +383,6 @@
:readonly="formState.readOnly || isDeleted"
:disabled="isDeleted"
:label="$ay.t('PriceOverride')"
:ref="
`Items[${activeWoItemIndex}].labors[${activeItemIndex}].priceOverride`
"
data-cy="laborpriceoverride"
:error-messages="
form().serverErrors(
@@ -409,6 +409,9 @@
cols="12"
>
<v-textarea
:ref="
`Items[${activeWoItemIndex}].labors[${activeItemIndex}].serviceDetails`
"
v-model="
value.items[activeWoItemIndex].labors[activeItemIndex]
.serviceDetails
@@ -422,16 +425,13 @@
`Items[${activeWoItemIndex}].labors[${activeItemIndex}].serviceDetails`
)
"
:ref="
`Items[${activeWoItemIndex}].labors[${activeItemIndex}].serviceDetails`
"
data-cy="laborserviceDetails"
auto-grow
@input="
fieldValueChanged(
`Items[${activeWoItemIndex}].labors[${activeItemIndex}].serviceDetails`
)
"
auto-grow
></v-textarea>
</v-col>
</template>
@@ -440,15 +440,6 @@
</template>
<script>
export default {
created() {
this.setDefaultView();
},
data() {
return {
activeItemIndex: null,
selectedRow: []
};
},
props: {
value: {
default: null,
@@ -467,238 +458,11 @@ export default {
type: Number
}
},
watch: {
activeWoItemIndex(val, oldVal) {
if (val != oldVal) {
this.setDefaultView();
}
},
gotoIndex(val, oldVal) {
if (val != oldVal) {
let gotoIndex = val;
if (val < 0) {
//it's a create request
gotoIndex = this.newItem();
}
this.selectedRow = [{ index: gotoIndex }];
this.activeItemIndex = gotoIndex;
this.$nextTick(() => {
const el = this.$refs.labortopform;
if (el) {
el.scrollIntoView({ behavior: "smooth" });
}
});
}
}
},
methods: {
appendTasks() {
const tasks = this.value.items[this.activeWoItemIndex].tasks;
if (tasks.length == 0) {
return;
}
const l = this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
];
let at = "";
tasks.forEach(z => {
at += `${z.task} - ${z.statusViz}\n`;
});
l.serviceDetails += `\n${at}`;
},
userChange(newName) {
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].userViz = newName;
},
rateChange(newName) {
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].serviceRateViz = newName;
},
taxCodeChange(newName) {
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].taxCodeViz = newName;
},
newItem() {
const newIndex = this.value.items[this.activeWoItemIndex].labors.length;
this.value.items[this.activeWoItemIndex].labors.push({
id: 0,
concurrency: 0,
userId: this.$store.getters.isScheduleableUser
? this.$store.state.userId
: null,
serviceStartDate: null,
serviceStopDate: null,
serviceRateId: null,
serviceDetails: null,
serviceRateQuantity: 0,
noChargeQuantity: 0,
taxCodeSaleId:
window.$gz.store.state.globalSettings.defaultTaxRateSaleId,
price: 0,
priceOverride: null,
isDirty: true,
workOrderItemId: this.value.items[this.activeWoItemIndex].id,
uid: Date.now(),
userViz: this.$store.getters.isScheduleableUser
? this.$store.state.userName
: null,
serviceRateViz: null,
taxCodeViz: null
});
this.$emit("change");
this.selectedRow = [{ index: newIndex }];
this.activeItemIndex = newIndex;
return newIndex; //for create new on goto
},
unDeleteItem() {
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].deleted = false;
this.setDefaultView();
},
deleteItem() {
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].deleted = true;
this.setDefaultView();
this.$emit("change");
},
deleteAllItem() {
this.value.items[this.activeWoItemIndex].labors.forEach(
z => (z.deleted = true)
);
this.setDefaultView();
this.$emit("change");
},
setDefaultView: function() {
//if only one record left then display it otherwise just let the datatable show what the user can click on
if (this.value.items[this.activeWoItemIndex].labors.length == 1) {
this.selectedRow = [{ index: 0 }];
this.activeItemIndex = 0;
} else {
this.selectedRow = [];
this.activeItemIndex = null; //select nothing in essence resetting a child selects and this one too clearing form
}
},
handleRowClick: function(item) {
this.activeItemIndex = item.index;
this.selectedRow = [{ index: item.index }];
},
form() {
return window.$gz.form;
},
fieldValueChanged(ref) {
if (!this.formState.loading && !this.formState.readonly) {
//flag this record dirty so it gets picked up by save
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].isDirty = true;
window.$gz.form.fieldValueChanged(this.pvm, ref);
//------- SPECIAL HANDLING OF CHANGES -----------
const isNew =
this.value.items[this.activeWoItemIndex].labors[this.activeItemIndex]
.id == 0;
//Auto calculate dates / quantities / global defaults
const dStart = this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].serviceStartDate;
const dStop = this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].serviceStopDate;
if (ref.includes("serviceStartDate") && dStart != null) {
this.handleStartDateChange(isNew, dStart, dStop);
}
if (ref.includes("serviceStopDate") && dStop != null) {
this.handleStopDateChange(isNew, dStart, dStop);
}
//------------------------------------------------------
}
},
handleStartDateChange: function(isNew, dStart, dStop) {
const globalMinutes =
window.$gz.store.state.globalSettings.workLaborScheduleDefaultMinutes;
if (isNew && dStop == null) {
if (globalMinutes != 0) {
//set stop date based on start date and global minutes
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].serviceStopDate = window.$gz.locale.addMinutesToUTC8601String(
dStart,
globalMinutes
);
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].serviceRateQuantity = globalMinutes;
}
} else {
//Existing record or both dates filled, just update quantity
if (dStop != null) {
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].serviceRateQuantity = window.$gz.locale.diffHoursFromUTC8601String(
dStart,
dStop
);
}
}
},
handleStopDateChange: function(isNew, dStart, dStop) {
const globalMinutes =
window.$gz.store.state.globalSettings.workLaborScheduleDefaultMinutes;
if (isNew && dStart == null) {
if (globalMinutes != 0) {
//set start date based on stop date and global minutes
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].serviceStartDate = window.$gz.locale.addMinutesToUTC8601String(
dStop,
0 - globalMinutes
);
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].serviceRateQuantity = globalMinutes;
}
} else {
//Existing record or both dates filled, just update quantity
if (dStart != null) {
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].serviceRateQuantity = window.$gz.locale.diffHoursFromUTC8601String(
dStart,
dStop
);
}
}
},
itemRowClasses: function(item) {
let ret = "";
const isDeleted =
this.value.items[this.activeWoItemIndex].labors[item.index].deleted ===
true;
const hasError = this.form().childRowHasError(
this,
`Items[${this.activeWoItemIndex}].Labors[${item.index}].`
);
if (isDeleted) {
ret += this.form().tableRowDeletedClass();
}
if (hasError) {
ret += this.form().tableRowErrorClass();
}
return ret;
}
//---
data() {
return {
activeItemIndex: null,
selectedRow: []
};
},
computed: {
isDeleted: function() {
@@ -985,6 +749,242 @@ export default {
return this.pvm.rights.change && !this.value.userIsRestrictedType;
}
//----
},
watch: {
activeWoItemIndex(val, oldVal) {
if (val != oldVal) {
this.setDefaultView();
}
},
gotoIndex(val, oldVal) {
if (val != oldVal) {
let gotoIndex = val;
if (val < 0) {
//it's a create request
gotoIndex = this.newItem();
}
this.selectedRow = [{ index: gotoIndex }];
this.activeItemIndex = gotoIndex;
this.$nextTick(() => {
const el = this.$refs.labortopform;
if (el) {
el.scrollIntoView({ behavior: "smooth" });
}
});
}
}
},
created() {
this.setDefaultView();
},
methods: {
appendTasks() {
const tasks = this.value.items[this.activeWoItemIndex].tasks;
if (tasks.length == 0) {
return;
}
const l = this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
];
let at = "";
tasks.forEach(z => {
at += `${z.task} - ${z.statusViz}\n`;
});
l.serviceDetails += `\n${at}`;
},
userChange(newName) {
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].userViz = newName;
},
rateChange(newName) {
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].serviceRateViz = newName;
},
taxCodeChange(newName) {
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].taxCodeViz = newName;
},
newItem() {
const newIndex = this.value.items[this.activeWoItemIndex].labors.length;
this.value.items[this.activeWoItemIndex].labors.push({
id: 0,
concurrency: 0,
userId: this.$store.getters.isScheduleableUser
? this.$store.state.userId
: null,
serviceStartDate: null,
serviceStopDate: null,
serviceRateId: null,
serviceDetails: null,
serviceRateQuantity: 0,
noChargeQuantity: 0,
taxCodeSaleId:
window.$gz.store.state.globalSettings.defaultTaxRateSaleId,
price: 0,
priceOverride: null,
isDirty: true,
workOrderItemId: this.value.items[this.activeWoItemIndex].id,
uid: Date.now(),
userViz: this.$store.getters.isScheduleableUser
? this.$store.state.userName
: null,
serviceRateViz: null,
taxCodeViz: null
});
this.$emit("change");
this.selectedRow = [{ index: newIndex }];
this.activeItemIndex = newIndex;
return newIndex; //for create new on goto
},
unDeleteItem() {
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].deleted = false;
this.setDefaultView();
},
deleteItem() {
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].deleted = true;
this.setDefaultView();
this.$emit("change");
},
deleteAllItem() {
this.value.items[this.activeWoItemIndex].labors.forEach(
z => (z.deleted = true)
);
this.setDefaultView();
this.$emit("change");
},
setDefaultView: function() {
//if only one record left then display it otherwise just let the datatable show what the user can click on
if (this.value.items[this.activeWoItemIndex].labors.length == 1) {
this.selectedRow = [{ index: 0 }];
this.activeItemIndex = 0;
} else {
this.selectedRow = [];
this.activeItemIndex = null; //select nothing in essence resetting a child selects and this one too clearing form
}
},
handleRowClick: function(item) {
this.activeItemIndex = item.index;
this.selectedRow = [{ index: item.index }];
},
form() {
return window.$gz.form;
},
fieldValueChanged(ref) {
if (!this.formState.loading && !this.formState.readonly) {
//flag this record dirty so it gets picked up by save
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].isDirty = true;
window.$gz.form.fieldValueChanged(this.pvm, ref);
//------- SPECIAL HANDLING OF CHANGES -----------
const isNew =
this.value.items[this.activeWoItemIndex].labors[this.activeItemIndex]
.id == 0;
//Auto calculate dates / quantities / global defaults
const dStart = this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].serviceStartDate;
const dStop = this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].serviceStopDate;
if (ref.includes("serviceStartDate") && dStart != null) {
this.handleStartDateChange(isNew, dStart, dStop);
}
if (ref.includes("serviceStopDate") && dStop != null) {
this.handleStopDateChange(isNew, dStart, dStop);
}
//------------------------------------------------------
}
},
handleStartDateChange: function(isNew, dStart, dStop) {
const globalMinutes =
window.$gz.store.state.globalSettings.workLaborScheduleDefaultMinutes;
if (isNew && dStop == null) {
if (globalMinutes != 0) {
//set stop date based on start date and global minutes
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].serviceStopDate = window.$gz.locale.addMinutesToUTC8601String(
dStart,
globalMinutes
);
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].serviceRateQuantity = globalMinutes;
}
} else {
//Existing record or both dates filled, just update quantity
if (dStop != null) {
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].serviceRateQuantity = window.$gz.locale.diffHoursFromUTC8601String(
dStart,
dStop
);
}
}
},
handleStopDateChange: function(isNew, dStart, dStop) {
const globalMinutes =
window.$gz.store.state.globalSettings.workLaborScheduleDefaultMinutes;
if (isNew && dStart == null) {
if (globalMinutes != 0) {
//set start date based on stop date and global minutes
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].serviceStartDate = window.$gz.locale.addMinutesToUTC8601String(
dStop,
0 - globalMinutes
);
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].serviceRateQuantity = globalMinutes;
}
} else {
//Existing record or both dates filled, just update quantity
if (dStart != null) {
this.value.items[this.activeWoItemIndex].labors[
this.activeItemIndex
].serviceRateQuantity = window.$gz.locale.diffHoursFromUTC8601String(
dStart,
dStop
);
}
}
},
itemRowClasses: function(item) {
let ret = "";
const isDeleted =
this.value.items[this.activeWoItemIndex].labors[item.index].deleted ===
true;
const hasError = this.form().childRowHasError(
this,
`Items[${this.activeWoItemIndex}].Labors[${item.index}].`
);
if (isDeleted) {
ret += this.form().tableRowDeletedClass();
}
if (hasError) {
ret += this.form().tableRowErrorClass();
}
return ret;
}
//---
}
};
</script>