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 // LOANS
// //
async function deleteExpenses(vm, woItemIndex) { async function deleteLoans(vm, woItemIndex) {
//walk the array backwards as items may be spliced out //walk the array backwards as items may be spliced out
for (var i = vm.obj.items[woItemIndex].expenses.length - 1; i >= 0; i--) { for (var i = vm.obj.items[woItemIndex].loans.length - 1; i >= 0; i--) {
const d = vm.obj.items[woItemIndex].expenses[i]; const d = vm.obj.items[woItemIndex].loans[i];
if (!d.deleted) { if (!d.deleted) {
continue; continue;
} }
let res = await window.$gz.api.remove( let res = await window.$gz.api.remove(`${API_BASE_URL}items/loans/${d.id}`);
`${API_BASE_URL}items/expenses/${d.id}`
);
if (res.error) { if (res.error) {
handleSaveError(vm, { handleSaveError(vm, {
error: res.error, error: res.error,
itemUid: vm.obj.items[woItemIndex].uid, itemUid: vm.obj.items[woItemIndex].uid,
childKey: "expenses", childKey: "loans",
childUid: d.uid childUid: d.uid
}); });
} else { } 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; return;
} }
async function saveExpenses(vm, woItemIndex) { async function saveLoans(vm, woItemIndex) {
//DELETE FLAGGED ITEMS FIRST //DELETE FLAGGED ITEMS FIRST
await deleteExpenses(vm, woItemIndex); await deleteLoans(vm, woItemIndex);
if (vm.saveResult.fatal) { if (vm.saveResult.fatal) {
return; return;
} }
for (let i = 0; i < vm.obj.items[woItemIndex].expenses.length; i++) { for (let i = 0; i < vm.obj.items[woItemIndex].loans.length; i++) {
let o = vm.obj.items[woItemIndex].expenses[i]; let o = vm.obj.items[woItemIndex].loans[i];
if (o.isDirty) { if (o.isDirty) {
//const isPost = o.id == 0; //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) { if (res.error) {
handleSaveError(vm, { handleSaveError(vm, {
error: res.error, error: res.error,
itemUid: vm.obj.items[woItemIndex].uid, itemUid: vm.obj.items[woItemIndex].uid,
childKey: "expenses", childKey: "loans",
childUid: o.uid childUid: o.uid
}); });
} else { } else {
//Server will update fields on put or post for most workorder graph objecs so need to update entire object here //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 // OUTSIDE SERVICES
// //
async function deleteExpenses(vm, woItemIndex) { async function deleteOutsideServices(vm, woItemIndex) {
//walk the array backwards as items may be spliced out //walk the array backwards as items may be spliced out
for (var i = vm.obj.items[woItemIndex].expenses.length - 1; i >= 0; i--) { for (
const d = vm.obj.items[woItemIndex].expenses[i]; var i = vm.obj.items[woItemIndex].outsideServices.length - 1;
i >= 0;
i--
) {
const d = vm.obj.items[woItemIndex].outsideServices[i];
if (!d.deleted) { if (!d.deleted) {
continue; continue;
} }
let res = await window.$gz.api.remove( 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) { if (res.error) {
handleSaveError(vm, { handleSaveError(vm, {
error: res.error, error: res.error,
itemUid: vm.obj.items[woItemIndex].uid, itemUid: vm.obj.items[woItemIndex].uid,
childKey: "expenses", childKey: "outsideServices",
childUid: d.uid childUid: d.uid
}); });
} else { } 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; return;
} }
async function saveExpenses(vm, woItemIndex) { async function saveOutsideServices(vm, woItemIndex) {
//DELETE FLAGGED ITEMS FIRST //DELETE FLAGGED ITEMS FIRST
await deleteExpenses(vm, woItemIndex); await deleteOutsideServices(vm, woItemIndex);
if (vm.saveResult.fatal) { if (vm.saveResult.fatal) {
return; return;
} }
for (let i = 0; i < vm.obj.items[woItemIndex].expenses.length; i++) { for (let i = 0; i < vm.obj.items[woItemIndex].outsideServices.length; i++) {
let o = vm.obj.items[woItemIndex].expenses[i]; let o = vm.obj.items[woItemIndex].outsideServices[i];
if (o.isDirty) { if (o.isDirty) {
//const isPost = o.id == 0; //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) { if (res.error) {
handleSaveError(vm, { handleSaveError(vm, {
error: res.error, error: res.error,
itemUid: vm.obj.items[woItemIndex].uid, itemUid: vm.obj.items[woItemIndex].uid,
childKey: "expenses", childKey: "outsideServices",
childUid: o.uid childUid: o.uid
}); });
} else { } else {
//Server will update fields on put or post for most workorder graph objecs so need to update entire object here //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
} }
} }
} }