frappe.pages["load-update"].on_page_load = function(wrapper) { var page = frappe.ui.make_app_page({ parent: wrapper, title: "Load Update", single_column: true }); var loadName = frappe.utils.get_url_arg("load"); if (!loadName) { $(page.body).html("

No load specified

Use ?load=MMDDYYYY-XXXX

"); return; } function loadLoad() { frappe.call({ method: "frappe.client.get", args: { doctype: "Load", name: loadName }, callback: function(r) { if (r.message) { renderForm(page, r.message); } else { $(page.body).html("

Load not found

"); } } }); } function renderForm(page, load) { var h = "
"; h += "

Update Load: " + load.name + "

"; h += "

Date: " + (load.incoming_date || "N/A") + " | Customer: " + (load.customer_name || load.customer_number || "N/A") + "

"; h += "
"; h += " "; h += " "; h += "Open Form View"; h += "
"; h += ""; h += ""; h += ""; h += ""; h += ""; h += ""; h += ""; if (load.material_items && load.material_items.length > 0) { load.material_items.forEach(function(item, idx) { var prefix = "item_" + idx + "_"; h += ""; h += ""; h += ""; h += ""; h += ""; h += ""; h += ""; h += ""; h += ""; h += ""; h += ""; h += ""; h += ""; h += ""; h += ""; h += ""; h += ""; }); } h += "
Material TypeCountRecv StatusSend ToRecv'dHDD OutDis Send ToSanitizedTest StatusTest SendR2 SentPhysHDD NeedHDD PhysHDD Logic
" + (item.material_type || "") + "
"; $(page.body).html(h); $("#lu-save").on("click", function() { var items = []; load.material_items.forEach(function(item, idx) { var prefix = "#item_" + idx + "_"; items.push({ name: item.name, total_count: parseInt($(prefix + "total_count").val()) || 0, initial_data_status: $(prefix + "initial_data_status").val(), send_to: $(prefix + "send_to").val(), devices_received: parseInt($(prefix + "devices_received").val()) || 0, hdd_removed: parseInt($(prefix + "hdd_removed").val()) || 0, disassembly_send_to: $(prefix + "disassembly_send_to").val(), units_sanitized_software: parseInt($(prefix + "units_sanitized_software").val()) || 0, test_data_status: $(prefix + "test_data_status").val(), test_send_to: $(prefix + "test_send_to").val(), r2_units_sent: parseInt($(prefix + "r2_units_sent").val()) || 0, units_physical_destruction: parseInt($(prefix + "units_physical_destruction").val()) || 0, hdd_needs_sanitize: parseInt($(prefix + "hdd_needs_sanitize").val()) || 0, hdd_physical_destruction: parseInt($(prefix + "hdd_physical_destruction").val()) || 0, hdd_logical_sanitization: parseInt($(prefix + "hdd_logical_sanitization").val()) || 0 }); }); frappe.call({ method: "westech_r2.page.load-update.load-update.save_load_items", args: { load_name: loadName, items: JSON.stringify(items) }, callback: function(r) { if (r.message && r.message.status === "ok") { frappe.show_alert({message: "Saved", indicator: "green"}); loadLoad(); } else { frappe.show_alert({message: "Save failed", indicator: "red"}); } } }); }); $("#lu-print").on("click", function() { window.print(); }); } loadLoad(); };