This commit is contained in:
2021-05-26 18:33:38 +00:00
parent 7ec8410e88
commit ae523387a2

View File

@@ -1325,25 +1325,23 @@ async function saveExpenses(vm, woItemIndex) {
/////////////////////////////
// LOANS
//
async function deleteExpenses(vm, woItemIndex) {
async function deleteLoans(vm, woItemIndex) {
//walk the array backwards as items may be spliced out
for (var i = vm.obj.items[woItemIndex].expenses.length - 1; i >= 0; i--) {
const d = vm.obj.items[woItemIndex].expenses[i];
for (var i = vm.obj.items[woItemIndex].loans.length - 1; i >= 0; i--) {
const d = vm.obj.items[woItemIndex].loans[i];
if (!d.deleted) {
continue;
}
let res = await window.$gz.api.remove(
`${API_BASE_URL}items/expenses/${d.id}`
);
let res = await window.$gz.api.remove(`${API_BASE_URL}items/loans/${d.id}`);
if (res.error) {
handleSaveError(vm, {
error: res.error,
itemUid: vm.obj.items[woItemIndex].uid,
childKey: "expenses",
childKey: "loans",
childUid: d.uid
});
} else {
vm.obj.items[woItemIndex].expenses.splice(i, 1);
vm.obj.items[woItemIndex].loans.splice(i, 1);
}
}
@@ -1351,28 +1349,28 @@ async function deleteExpenses(vm, woItemIndex) {
return;
}
async function saveExpenses(vm, woItemIndex) {
async function saveLoans(vm, woItemIndex) {
//DELETE FLAGGED ITEMS FIRST
await deleteExpenses(vm, woItemIndex);
await deleteLoans(vm, woItemIndex);
if (vm.saveResult.fatal) {
return;
}
for (let i = 0; i < vm.obj.items[woItemIndex].expenses.length; i++) {
let o = vm.obj.items[woItemIndex].expenses[i];
for (let i = 0; i < vm.obj.items[woItemIndex].loans.length; i++) {
let o = vm.obj.items[woItemIndex].loans[i];
if (o.isDirty) {
//const isPost = o.id == 0;
let res = await window.$gz.api.upsert(`${API_BASE_URL}items/expenses`, o);
let res = await window.$gz.api.upsert(`${API_BASE_URL}items/loans`, o);
if (res.error) {
handleSaveError(vm, {
error: res.error,
itemUid: vm.obj.items[woItemIndex].uid,
childKey: "expenses",
childKey: "loans",
childUid: o.uid
});
} else {
//Server will update fields on put or post for most workorder graph objecs so need to update entire object here
vm.obj.items[woItemIndex].expenses.splice(i, 1, res.data); //vue needs the splice rather than just setting the value in order to trigger reactivity or else the UI won't update
vm.obj.items[woItemIndex].loans.splice(i, 1, res.data); //vue needs the splice rather than just setting the value in order to trigger reactivity or else the UI won't update
}
}
}
@@ -1382,25 +1380,29 @@ async function saveExpenses(vm, woItemIndex) {
/////////////////////////////
// OUTSIDE SERVICES
//
async function deleteExpenses(vm, woItemIndex) {
async function deleteOutsideServices(vm, woItemIndex) {
//walk the array backwards as items may be spliced out
for (var i = vm.obj.items[woItemIndex].expenses.length - 1; i >= 0; i--) {
const d = vm.obj.items[woItemIndex].expenses[i];
for (
var i = vm.obj.items[woItemIndex].outsideServices.length - 1;
i >= 0;
i--
) {
const d = vm.obj.items[woItemIndex].outsideServices[i];
if (!d.deleted) {
continue;
}
let res = await window.$gz.api.remove(
`${API_BASE_URL}items/expenses/${d.id}`
`${API_BASE_URL}items/outside-services/${d.id}`
);
if (res.error) {
handleSaveError(vm, {
error: res.error,
itemUid: vm.obj.items[woItemIndex].uid,
childKey: "expenses",
childKey: "outsideServices",
childUid: d.uid
});
} else {
vm.obj.items[woItemIndex].expenses.splice(i, 1);
vm.obj.items[woItemIndex].outsideServices.splice(i, 1);
}
}
@@ -1408,28 +1410,31 @@ async function deleteExpenses(vm, woItemIndex) {
return;
}
async function saveExpenses(vm, woItemIndex) {
async function saveOutsideServices(vm, woItemIndex) {
//DELETE FLAGGED ITEMS FIRST
await deleteExpenses(vm, woItemIndex);
await deleteOutsideServices(vm, woItemIndex);
if (vm.saveResult.fatal) {
return;
}
for (let i = 0; i < vm.obj.items[woItemIndex].expenses.length; i++) {
let o = vm.obj.items[woItemIndex].expenses[i];
for (let i = 0; i < vm.obj.items[woItemIndex].outsideServices.length; i++) {
let o = vm.obj.items[woItemIndex].outsideServices[i];
if (o.isDirty) {
//const isPost = o.id == 0;
let res = await window.$gz.api.upsert(`${API_BASE_URL}items/expenses`, o);
let res = await window.$gz.api.upsert(
`${API_BASE_URL}items/outside-services`,
o
);
if (res.error) {
handleSaveError(vm, {
error: res.error,
itemUid: vm.obj.items[woItemIndex].uid,
childKey: "expenses",
childKey: "outsideServices",
childUid: o.uid
});
} else {
//Server will update fields on put or post for most workorder graph objecs so need to update entire object here
vm.obj.items[woItemIndex].expenses.splice(i, 1, res.data); //vue needs the splice rather than just setting the value in order to trigger reactivity or else the UI won't update
vm.obj.items[woItemIndex].outsideServices.splice(i, 1, res.data); //vue needs the splice rather than just setting the value in order to trigger reactivity or else the UI won't update
}
}
}