This commit is contained in:
@@ -862,7 +862,7 @@ async function saveItems(vm) {
|
|||||||
//## GRANDCHILDREN
|
//## GRANDCHILDREN
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// EXPENSES
|
// UNITS
|
||||||
//
|
//
|
||||||
async function deleteUnits(vm, woItemIndex) {
|
async function deleteUnits(vm, woItemIndex) {
|
||||||
//walk the array backwards as items may be spliced out
|
//walk the array backwards as items may be spliced out
|
||||||
@@ -898,7 +898,7 @@ async function saveUnits(vm, woItemIndex) {
|
|||||||
for (let i = 0; i < vm.obj.items[woItemIndex].units.length; i++) {
|
for (let i = 0; i < vm.obj.items[woItemIndex].units.length; i++) {
|
||||||
let o = vm.obj.items[woItemIndex].units[i];
|
let o = vm.obj.items[woItemIndex].units[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/units`, o);
|
let res = await window.$gz.api.upsert(`${API_BASE_URL}items/units`, o);
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
handleSaveError(vm, {
|
handleSaveError(vm, {
|
||||||
@@ -931,7 +931,7 @@ async function saveScheduledUsers(vm, woItemIndex) {
|
|||||||
if (o.isDirty) {
|
if (o.isDirty) {
|
||||||
const isPost = o.id == 0;
|
const isPost = o.id == 0;
|
||||||
let res = await window.$gz.api.upsert(
|
let res = await window.$gz.api.upsert(
|
||||||
`${API_BASE_URL}items/scheduledusers`,
|
`${API_BASE_URL}items/scheduled-users`,
|
||||||
o
|
o
|
||||||
);
|
);
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
@@ -962,7 +962,7 @@ async function deleteScheduledUsers(vm, woItemIndex) {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
let res = await window.$gz.api.remove(
|
let res = await window.$gz.api.remove(
|
||||||
`${API_BASE_URL}items/scheduledusers/${d.id}`
|
`${API_BASE_URL}items/scheduled-users/${d.id}`
|
||||||
);
|
);
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
handleSaveError(vm, {
|
handleSaveError(vm, {
|
||||||
@@ -993,7 +993,7 @@ async function saveTasks(vm, woItemIndex) {
|
|||||||
for (let i = 0; i < vm.obj.items[woItemIndex].tasks.length; i++) {
|
for (let i = 0; i < vm.obj.items[woItemIndex].tasks.length; i++) {
|
||||||
let o = vm.obj.items[woItemIndex].tasks[i];
|
let o = vm.obj.items[woItemIndex].tasks[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/tasks`, o);
|
let res = await window.$gz.api.upsert(`${API_BASE_URL}items/tasks`, o);
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
handleSaveError(vm, {
|
handleSaveError(vm, {
|
||||||
@@ -1072,7 +1072,7 @@ async function saveParts(vm, woItemIndex) {
|
|||||||
for (let i = 0; i < vm.obj.items[woItemIndex].parts.length; i++) {
|
for (let i = 0; i < vm.obj.items[woItemIndex].parts.length; i++) {
|
||||||
let o = vm.obj.items[woItemIndex].parts[i];
|
let o = vm.obj.items[woItemIndex].parts[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/parts`, o);
|
let res = await window.$gz.api.upsert(`${API_BASE_URL}items/parts`, o);
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
handleSaveError(vm, {
|
handleSaveError(vm, {
|
||||||
@@ -1090,6 +1090,66 @@ async function saveParts(vm, woItemIndex) {
|
|||||||
return; //made it
|
return; //made it
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/////////////////////////////
|
||||||
|
// PART REQUESTS
|
||||||
|
//
|
||||||
|
async function deletePartRequests(vm, woItemIndex) {
|
||||||
|
//walk the array backwards as items may be spliced out
|
||||||
|
for (var i = vm.obj.items[woItemIndex].partRequests.length - 1; i >= 0; i--) {
|
||||||
|
const d = vm.obj.items[woItemIndex].partRequests[i];
|
||||||
|
if (!d.deleted) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let res = await window.$gz.api.remove(
|
||||||
|
`${API_BASE_URL}items/part-requests/${d.id}`
|
||||||
|
);
|
||||||
|
if (res.error) {
|
||||||
|
handleSaveError(vm, {
|
||||||
|
error: res.error,
|
||||||
|
itemUid: vm.obj.items[woItemIndex].uid,
|
||||||
|
childKey: "partRequests",
|
||||||
|
childUid: d.uid
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
vm.obj.items[woItemIndex].partRequests.splice(i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function savePartRequests(vm, woItemIndex) {
|
||||||
|
//DELETE FLAGGED ITEMS FIRST
|
||||||
|
await deletePartRequests(vm, woItemIndex);
|
||||||
|
if (vm.saveResult.fatal) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
for (let i = 0; i < vm.obj.items[woItemIndex].partRequests.length; i++) {
|
||||||
|
let o = vm.obj.items[woItemIndex].partRequests[i];
|
||||||
|
if (o.isDirty) {
|
||||||
|
//const isPost = o.id == 0;
|
||||||
|
let res = await window.$gz.api.upsert(
|
||||||
|
`${API_BASE_URL}items/part-requests`,
|
||||||
|
o
|
||||||
|
);
|
||||||
|
if (res.error) {
|
||||||
|
handleSaveError(vm, {
|
||||||
|
error: res.error,
|
||||||
|
itemUid: vm.obj.items[woItemIndex].uid,
|
||||||
|
childKey: "partRequests",
|
||||||
|
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].partRequests.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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return; //made it
|
||||||
|
}
|
||||||
|
|
||||||
/////////////////////////////
|
/////////////////////////////
|
||||||
// LABOR
|
// LABOR
|
||||||
//
|
//
|
||||||
@@ -1244,7 +1304,7 @@ async function saveExpenses(vm, woItemIndex) {
|
|||||||
for (let i = 0; i < vm.obj.items[woItemIndex].expenses.length; i++) {
|
for (let i = 0; i < vm.obj.items[woItemIndex].expenses.length; i++) {
|
||||||
let o = vm.obj.items[woItemIndex].expenses[i];
|
let o = vm.obj.items[woItemIndex].expenses[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/expenses`, o);
|
||||||
if (res.error) {
|
if (res.error) {
|
||||||
handleSaveError(vm, {
|
handleSaveError(vm, {
|
||||||
@@ -1262,7 +1322,119 @@ async function saveExpenses(vm, woItemIndex) {
|
|||||||
return; //made it
|
return; //made it
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo: other grandchildren
|
/////////////////////////////
|
||||||
|
// LOANS
|
||||||
|
//
|
||||||
|
async function deleteExpenses(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];
|
||||||
|
if (!d.deleted) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let res = await window.$gz.api.remove(
|
||||||
|
`${API_BASE_URL}items/expenses/${d.id}`
|
||||||
|
);
|
||||||
|
if (res.error) {
|
||||||
|
handleSaveError(vm, {
|
||||||
|
error: res.error,
|
||||||
|
itemUid: vm.obj.items[woItemIndex].uid,
|
||||||
|
childKey: "expenses",
|
||||||
|
childUid: d.uid
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
vm.obj.items[woItemIndex].expenses.splice(i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveExpenses(vm, woItemIndex) {
|
||||||
|
//DELETE FLAGGED ITEMS FIRST
|
||||||
|
await deleteExpenses(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];
|
||||||
|
if (o.isDirty) {
|
||||||
|
//const isPost = o.id == 0;
|
||||||
|
let res = await window.$gz.api.upsert(`${API_BASE_URL}items/expenses`, o);
|
||||||
|
if (res.error) {
|
||||||
|
handleSaveError(vm, {
|
||||||
|
error: res.error,
|
||||||
|
itemUid: vm.obj.items[woItemIndex].uid,
|
||||||
|
childKey: "expenses",
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return; //made it
|
||||||
|
}
|
||||||
|
|
||||||
|
/////////////////////////////
|
||||||
|
// OUTSIDE SERVICES
|
||||||
|
//
|
||||||
|
async function deleteExpenses(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];
|
||||||
|
if (!d.deleted) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
let res = await window.$gz.api.remove(
|
||||||
|
`${API_BASE_URL}items/expenses/${d.id}`
|
||||||
|
);
|
||||||
|
if (res.error) {
|
||||||
|
handleSaveError(vm, {
|
||||||
|
error: res.error,
|
||||||
|
itemUid: vm.obj.items[woItemIndex].uid,
|
||||||
|
childKey: "expenses",
|
||||||
|
childUid: d.uid
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
vm.obj.items[woItemIndex].expenses.splice(i, 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//----
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function saveExpenses(vm, woItemIndex) {
|
||||||
|
//DELETE FLAGGED ITEMS FIRST
|
||||||
|
await deleteExpenses(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];
|
||||||
|
if (o.isDirty) {
|
||||||
|
//const isPost = o.id == 0;
|
||||||
|
let res = await window.$gz.api.upsert(`${API_BASE_URL}items/expenses`, o);
|
||||||
|
if (res.error) {
|
||||||
|
handleSaveError(vm, {
|
||||||
|
error: res.error,
|
||||||
|
itemUid: vm.obj.items[woItemIndex].uid,
|
||||||
|
childKey: "expenses",
|
||||||
|
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
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return; //made it
|
||||||
|
}
|
||||||
|
|
||||||
//######################################### UTILITY METHODS ###########################################
|
//######################################### UTILITY METHODS ###########################################
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user