new update here i already make the history and added a new function for quantity and sooner or later, im going to make so app can read a data for quantity item. But here im stuck again cuz i want to make a list view and every listed item in the list view can have an individual barcode scanner function there is about 77 more item i want to list in and a search for the listed item in the search bar is it possible?
here is my progress so far
and as i did for the list view code block its does call for both at one time
var sheet1Url = "https://docs.google.com/spreadsheets/d/1v7ApBU-FHyuDY1J-56dJ8SfFH6UCx5ne8S5dxU4KmAY/edit#gid=0";
var sheet2Url = "https://docs.google.com/spreadsheets/d/1v7ApBU-FHyuDY1J-56dJ8SfFH6UCx5ne8S5dxU4KmAY/edit#gid=906968515";
var sheet3Url = "https://docs.google.com/spreadsheets/d/1v7ApBU-FHyuDY1J-56dJ8SfFH6UCx5ne8S5dxU4KmAY/edit#gid=1439910358";
var sheet1 = SpreadsheetApp.openByUrl(sheet1Url);
var sheet2 = SpreadsheetApp.openByUrl(sheet2Url);
var sheet3 = SpreadsheetApp.openByUrl(sheet3Url);
var sheet = sheet1.getSheetByName("ItemID");
var historySheet = sheet2.getSheetByName("History");
var itemQuantitiesSheet = sheet3.getSheetByName("ItemQuantities");
function doGet(e) {
var actions = e.parameter.action.split(',');
var response = '';
for (var i = 0; i < actions.length; i++) {
var action = actions[i].trim();
var name = e.parameter.name;
var item = e.parameter.item;
var quantity = parseInt(e.parameter.quantity);
var id = e.parameter.id;
if (action == "in") {
response += inTime(e, id, name, item);
} else if (action == "out") {
response += outTime(e, id, name, item);
} else if (action == "add" || action == "remove") {
updateItemQuantity(action, item, quantity);
response += "Item quantity updated successfully for action: " + action + "\n";
} else {
response += "Invalid action parameter: " + action + "\n";
}
}
return ContentService.createTextOutput(response).setMimeType(ContentService.MimeType.TEXT);
}
function doPost(e) {
return doGet(e);
}
function inTime(e, id, name, item) {
var values = sheet.getRange(2, 1, sheet.getLastRow(), 1).getValues();
for (var i = 0; i < values.length; i++) {
if (values[i][0] == id) {
i = i + 2;
var in_time = Utilities.formatDate(new Date(), "GMT+8", "d/M/yy , HH:mm:ss");
sheet.getRange(i, 3).setValue(in_time);
sheet.getRange(i, 4).setValue("in");
historySheet.appendRow([id, name, item, in_time, "in"]);
return "Thank You! Your In Time is " + in_time + "\n";
}
}
return "ID Not Found\n";
}
function outTime(e, id, name, item) {
var values = sheet.getRange(2, 1, sheet.getLastRow(), 1).getValues();
for (var i = 0; i < values.length; i++) {
if (values[i][0] == id) {
i = i + 2;
var out_time = Utilities.formatDate(new Date(), "GMT+8", "d/M/yy , HH:mm:ss");
sheet.getRange(i, 3).setValue(out_time);
sheet.getRange(i, 4).setValue("out");
historySheet.appendRow([id, name, item, out_time, "out"]);
return "Thank You! Your Out Time is " + out_time + "\n";
}
}
return "ID Not Found\n";
}
function updateItemQuantity(action, item, quantity) {
var itemRow = findItemRow(item, itemQuantitiesSheet);
if (itemRow !== -1) {
var currentQuantity = parseInt(itemQuantitiesSheet.getRange(itemRow, 2).getValue());
if (action === "add") {
itemQuantitiesSheet.getRange(itemRow, 2).setValue(currentQuantity + quantity);
} else if (action === "remove") {
itemQuantitiesSheet.getRange(itemRow, 2).setValue(currentQuantity - quantity);
}
} else {
itemQuantitiesSheet.appendRow([item, quantity]);
}
}
function findItemRow(item, sheet) {
var data = sheet.getDataRange().getValues();
for (var i = 0; i < data.length; i++) {
if (data[i][0] == item) {
return i + 1;
}
}
return -1;
}
thank you TIMAI2 for having me, sorry