This commit is contained in:
2021-07-07 17:30:56 +00:00
parent ee995d6679
commit 2944254403
3 changed files with 189 additions and 109 deletions

View File

@@ -145,6 +145,7 @@ export default {
}
return o;
},
/**
* Copy a string to clipboard
* @param {String} string The string to be copied to clipboard

View File

@@ -869,47 +869,124 @@ export default {
},
methods: {
async copyItemToWorkOrder() {
/*
needs to display wo selector dialog as simple input text for workorder number
this is so that there is no need to work with infinite lists to select from when they probably just know the number anyway and we don't care what wo they select with the loosey goosey rules now
Enter wo number and click on ok or cancel
if ok then it looks up that wo number record id, navigates to that workorder with the woitem to be copied in the route param
Wo form needs to spot that route param and insert that item into a new woitem record ** if the wo is not locked** if it's locked then an error message should state so
or do we just let the server tell them about it and assume they will unlock it before save next time
User is left with a existing wo opened, a new woitem added and the wo is dirty and ready to save
*/
if (!this.copyItemWoNumber) {
return;
}
if (this.pvm.formState.dirty) {
if ((await window.$gz.dialog.confirmLeaveUnsaved()) !== true) {
//Self copy to current workorder??
if (this.copyItemWoNumber == this.value.serial) {
let newIndex = this.value.items.length;
// let wi = window.$gz.util.deepCopy(
// this.value.items[this.activeItemIndex]
// );
let wi = JSON.parse(
JSON.stringify(this.value.items[this.activeItemIndex])
);
// //deep copy all children
// wi.expenses.forEach(x => {
// x.id = 0;
// x.workOrderItemId = 0;
// x.concurrency = undefined;
// x.isDirty = true;
// });
// wi.labors.forEach(x => {
// x.id = 0;
// x.workOrderItemId = 0;
// x.concurrency = undefined;
// x.isDirty = true;
// });
// wi.loans.forEach(x => {
// x.id = 0;
// x.workOrderItemId = 0;
// x.concurrency = undefined;
// x.isDirty = true;
// x.cost = 0;
// x.listPrice = 0;
// });
// wi.parts.forEach(x => {
// x.id = 0;
// x.workOrderItemId = 0;
// x.concurrency = undefined;
// x.isDirty = true;
// x.cost = 0;
// x.listPrice = 0;
// });
// wi.scheduledUsers.forEach(x => {
// x.id = 0;
// x.workOrderItemId = 0;
// x.concurrency = undefined;
// x.isDirty = true;
// });
// wi.tasks.forEach(x => {
// x.id = 0;
// x.workOrderItemId = 0;
// x.concurrency = undefined;
// x.isDirty = true;
// });
// wi.travels.forEach(x => {
// x.id = 0;
// x.workOrderItemId = 0;
// x.concurrency = undefined;
// x.isDirty = true;
// });
// wi.units.forEach(x => {
// x.id = 0;
// x.workOrderItemId = 0;
// x.concurrency = undefined;
// x.isDirty = true;
// });
// wi.outsideServices.forEach(x => {
// x.id = 0;
// x.workOrderItemId = 0;
// x.concurrency = undefined;
// x.isDirty = true;
// });
console.log(
"wi equals source",
wi === this.value.items[this.activeItemIndex]
);
console.log(
"wi.labors[0] equals source.labors[0]",
wi.labors[0] === this.value.items[this.activeItemIndex].labors[0]
);
this.pvm.washWorkOrderItem(wi);
wi.workOrderId = this.value.id;
wi.sequence = newIndex + 1;
this.value.items.push(wi);
this.$emit("change");
this.selectedRow = [{ index: newIndex }];
this.activeItemIndex = newIndex;
} else {
if (this.pvm.formState.dirty) {
if ((await window.$gz.dialog.confirmLeaveUnsaved()) !== true) {
return;
}
}
//get id from number then push open
let res = await window.$gz.api.get(
"workorder/id-from-number/" + this.copyItemWoNumber
);
if (res.error) {
window.$gz.eventBus.$emit(
"notify-warning",
window.$gz.errorHandler.errorToString(res, this)
);
return;
}
}
//get id from number then push open
let res = await window.$gz.api.get(
"workorder/id-from-number/" + this.copyItemWoNumber
);
if (res.error) {
window.$gz.eventBus.$emit(
"notify-warning",
window.$gz.errorHandler.errorToString(res, this)
);
return;
this.$router.push({
name: "workorder-edit",
params: {
recordid: res.data,
copyItem: this.value.items[this.activeItemIndex]
}
});
}
this.$router.push({
name: "workorder-edit",
params: {
recordid: res.data,
copyItem: this.value.items[this.activeItemIndex]
}
});
this.copyItemDialog = false;
},
newItem() {

View File

@@ -86,7 +86,7 @@ export default {
//check for copy wo item on route params
let wi = this.$route.params.copyItem;
if (wi) {
washWorkOrderItem(wi);
this.washWorkOrderItem(wi);
wi.workOrderId = vm.obj.id;
wi.sequence = vm.obj.items.length + 1;
vm.obj.items.push(wi);
@@ -104,7 +104,7 @@ export default {
this.obj.isDirty = true;
vm.obj.items.forEach(z => {
z.workOrderId = 0;
washWorkOrderItem(z);
this.washWorkOrderItem(z);
});
setDirty = true;
} else {
@@ -682,6 +682,83 @@ export default {
obj: this.obj
}
});
},
/////////////////////////////////////////////////////////
// Clean woitem and children so it's
// savable as a new record
// (used by duplicate and copy wo item functions
// also called from work-order-items.vue copy woitem when
// self target)
//
washWorkOrderItem(wi) {
if (wi) {
wi.id = 0;
wi.concurrency = 0;
wi.uid = Date.now();
wi.isDirty = true;
if (wi.partRequests) {
wi.partRequests.splice(0);
}
wi.expenses.forEach(x => {
x.id = 0;
x.workOrderItemId = 0;
x.concurrency = undefined;
x.isDirty = true;
});
wi.labors.forEach(x => {
x.id = 0;
x.workOrderItemId = 0;
x.concurrency = undefined;
x.isDirty = true;
});
wi.loans.forEach(x => {
x.id = 0;
x.workOrderItemId = 0;
x.concurrency = undefined;
x.isDirty = true;
x.cost = 0;
x.listPrice = 0;
});
wi.parts.forEach(x => {
x.id = 0;
x.workOrderItemId = 0;
x.concurrency = undefined;
x.isDirty = true;
x.cost = 0;
x.listPrice = 0;
});
wi.scheduledUsers.forEach(x => {
x.id = 0;
x.workOrderItemId = 0;
x.concurrency = undefined;
x.isDirty = true;
});
wi.tasks.forEach(x => {
x.id = 0;
x.workOrderItemId = 0;
x.concurrency = undefined;
x.isDirty = true;
});
wi.travels.forEach(x => {
x.id = 0;
x.workOrderItemId = 0;
x.concurrency = undefined;
x.isDirty = true;
});
wi.units.forEach(x => {
x.id = 0;
x.workOrderItemId = 0;
x.concurrency = undefined;
x.isDirty = true;
});
wi.outsideServices.forEach(x => {
x.id = 0;
x.workOrderItemId = 0;
x.concurrency = undefined;
x.isDirty = true;
});
}
}
//end methods
@@ -1871,81 +1948,6 @@ function generateMenu(vm) {
window.$gz.eventBus.$emit("menu-change", menuOptions);
}
/////////////////////////////////////////////////////////
// Clean woitem and children so it's
// savable as a new record
// (used by duplicate and copy wo item functions)
//
function washWorkOrderItem(wi) {
if (wi) {
wi.id = 0;
wi.concurrency = 0;
wi.uid = Date.now();
wi.isDirty = true;
if (wi.partRequests) {
wi.partRequests.splice(0);
}
wi.expenses.forEach(x => {
x.id = 0;
x.workOrderItemId = 0;
x.concurrency = undefined;
x.isDirty = true;
});
wi.labors.forEach(x => {
x.id = 0;
x.workOrderItemId = 0;
x.concurrency = undefined;
x.isDirty = true;
});
wi.loans.forEach(x => {
x.id = 0;
x.workOrderItemId = 0;
x.concurrency = undefined;
x.isDirty = true;
x.cost = 0;
x.listPrice = 0;
});
wi.parts.forEach(x => {
x.id = 0;
x.workOrderItemId = 0;
x.concurrency = undefined;
x.isDirty = true;
x.cost = 0;
x.listPrice = 0;
});
wi.scheduledUsers.forEach(x => {
x.id = 0;
x.workOrderItemId = 0;
x.concurrency = undefined;
x.isDirty = true;
});
wi.tasks.forEach(x => {
x.id = 0;
x.workOrderItemId = 0;
x.concurrency = undefined;
x.isDirty = true;
});
wi.travels.forEach(x => {
x.id = 0;
x.workOrderItemId = 0;
x.concurrency = undefined;
x.isDirty = true;
});
wi.units.forEach(x => {
x.id = 0;
x.workOrderItemId = 0;
x.concurrency = undefined;
x.isDirty = true;
});
wi.outsideServices.forEach(x => {
x.id = 0;
x.workOrderItemId = 0;
x.concurrency = undefined;
x.isDirty = true;
});
}
}
//####################################################
let JUST_DELETED = false;