Jump to content

needs_upgrade

Members
  • Posts

    126
  • Joined

  • Last visited

Everything posted by needs_upgrade

  1. Hello guys. I have a very large javascript file used for validating inputs. I want to make it shorter but it's not working. I'll be showing the new JS function code and the old one. Pls feel free to criticize or suggest something better. More power to you guys! thanks. New JS code: function valAddCReturn() { if (checkAddCReturn()) { document.AddCReturn.submit(); } } function checkAddCReturn() { if (document.AddCReturn.rc_id.value == "") { if (document.AddCReturn.whouse_id.selectedIndex == 0) { alert("Please select from the list of warehouses!"); document.AddCReturn.whouse_id.focus(); document.AddCReturn.whouse_id.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.ref_num.value.length == 0) { alert("Please enter the reference number!"); document.AddCReturn.ref_num.focus(); document.AddCReturn.ref_num.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.customer_id.selectedIndex == 0) { alert("Please select from the list of customers!"); document.AddCReturn.customer_id.focus(); document.AddCReturn.customer_id.style.backgroundColor = "#FFFF00"; return false; } } if ((document.AddCReturn.product_id1.value.length == 0) && (document.AddCReturn.product_id2.value.length == 0) && (document.AddCReturn.product_id3.value.length == 0) && (document.AddCReturn.product_id4.value.length == 0) && (document.AddCReturn.product_id5.value.length == 0) && (document.AddCReturn.product_id6.value.length == 0) && (document.AddCReturn.product_id7.value.length == 0) && (document.AddCReturn.product_id8.value.length == 0) && (document.AddCReturn.product_id9.value.length == 0) && (document.AddCReturn.product_id10.value.length == 0) && (document.AddCReturn.product_id11.value.length == 0) && (document.AddCReturn.product_id12.value.length == 0) && (document.AddCReturn.product_id13.value.length == 0) && (document.AddCReturn.product_id14.value.length == 0) && (document.AddCReturn.product_id15.value.length == 0) && (document.AddCReturn.product_id16.value.length == 0) && (document.AddCReturn.product_id17.value.length == 0) && (document.AddCReturn.product_id18.value.length == 0) && (document.AddCReturn.product_id19.value.length == 0) && (document.AddCReturn.product_id20.value.length == 0)) { alert("Product Return should contain at least one (1) product!"); return false; } else { for (var i = 1; i < 21; i++) { if (document.AddCReturn.product_id[i].value.length != 0 && document.AddCReturn.quantity[i].value == 0 && document.AddCReturn.unit_price[i].value == 0) { alert("All entries for Item #" + i + "should have values"); document.AddCReturn.product_id[i].style.backgroundColor = "#FFFF00"; return false; } } } for (var x = 1; x < 20; x++) { if (document.AddCReturn.product_id[x].value.length != 0) { for (var y = x+1; y < 21; y++) { if (document.AddCReturn.product_id[x].value == document.AddCReturn.product_id[y].value) { alert("Entries for products " + x + "and" + y + "are the same!"); document.AddCReturn.product_id[x].style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id[y].style.backgroundColor = "#FFFF00"; return false; } } } } return true; } Old JS code but i have to cut it short because of length limit: function valAddCReturn() { if (checkAddCReturn()) { document.AddCReturn.submit(); } } function checkAddCReturn() { if (document.AddCReturn.rc_id.value == "") { if (document.AddCReturn.whouse_id.selectedIndex == 0) { alert("Please select from the list of warehouses!"); document.AddCReturn.whouse_id.focus(); document.AddCReturn.whouse_id.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.ref_num.value.length == 0) { alert("Please enter the reference number!"); document.AddCReturn.ref_num.focus(); document.AddCReturn.ref_num.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.customer_id.selectedIndex == 0) { alert("Please select from the list of customers!"); document.AddCReturn.customer_id.focus(); document.AddCReturn.customer_id.style.backgroundColor = "#FFFF00"; return false; } } if ((document.AddCReturn.product_id1.value.length == 0) && (document.AddCReturn.product_id2.value.length == 0) && (document.AddCReturn.product_id3.value.length == 0) && (document.AddCReturn.product_id4.value.length == 0) && (document.AddCReturn.product_id5.value.length == 0) && (document.AddCReturn.product_id6.value.length == 0) && (document.AddCReturn.product_id7.value.length == 0) && (document.AddCReturn.product_id8.value.length == 0) && (document.AddCReturn.product_id9.value.length == 0) && (document.AddCReturn.product_id10.value.length == 0) && (document.AddCReturn.product_id11.value.length == 0) && (document.AddCReturn.product_id12.value.length == 0) && (document.AddCReturn.product_id13.value.length == 0) && (document.AddCReturn.product_id14.value.length == 0) && (document.AddCReturn.product_id15.value.length == 0) && (document.AddCReturn.product_id16.value.length == 0) && (document.AddCReturn.product_id17.value.length == 0) && (document.AddCReturn.product_id18.value.length == 0) && (document.AddCReturn.product_id19.value.length == 0) && (document.AddCReturn.product_id20.value.length == 0)) { alert("Product Return should contain at least one (1) product!"); return false; } else { if (document.AddCReturn.product_id1.value.length != 0 && document.AddCReturn.quantity1.value == 0 && document.AddCReturn.unit_price1.value == 0) { alert("All entries for Item #1 should have values"); document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id2.value.length != 0 && document.AddCReturn.quantity2.value == 0 && document.AddCReturn.unit_price2.value == 0) { alert("All entries for Item #2 should have values"); document.AddCReturn.product_id2.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id3.value.length != 0 && document.AddCReturn.quantity3.value == 0 && document.AddCReturn.unit_price3.value == 0) { alert("All entries for Item #3 should have values"); document.AddCReturn.product_id3.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id4.value.length != 0 && document.AddCReturn.quantity4.value == 0 && document.AddCReturn.unit_price4.value == 0) { alert("All entries for Item #4 should have values"); document.AddCReturn.product_id4.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id5.value.length != 0 && document.AddCReturn.quantity5.value == 0 && document.AddCReturn.unit_price5.value == 0) { alert("All entries for Item #5 should have values"); document.AddCReturn.product_id5.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id6.value.length != 0 && document.AddCReturn.quantity6.value == 0 && document.AddCReturn.unit_price6.value == 0) { alert("All entries for Item #6 should have values"); document.AddCReturn.product_id6.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id7.value.length != 0 && document.AddCReturn.quantity7.value == 0 && document.AddCReturn.unit_price7.value == 0) { alert("All entries for Item #7 should have values"); document.AddCReturn.product_id7.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id8.value.length != 0 && document.AddCReturn.quantity8.value == 0 && document.AddCReturn.unit_price8.value == 0) { alert("All entries for Item #8 should have values"); document.AddCReturn.product_id8.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id9.value.length != 0 && document.AddCReturn.quantity9.value == 0 && document.AddCReturn.unit_price9.value == 0) { alert("All entries for Item #9 should have values"); document.AddCReturn.product_id9.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id10.value.length != 0 && document.AddCReturn.quantity10.value == 0 && document.AddCReturn.unit_price10.value == 0) { alert("All entries for Item #10 should have values"); document.AddCReturn.product_id10.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id11.value.length != 0 && document.AddCReturn.quantity11.value == 0 && document.AddCReturn.unit_price11.value == 0) { alert("All entries for Item #11 should have values"); document.AddCReturn.product_id11.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id12.value.length != 0 && document.AddCReturn.quantity12.value == 0 && document.AddCReturn.unit_price12.value == 0) { alert("All entries for Item #12 should have values"); document.AddCReturn.product_id12.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id13.value.length != 0 && document.AddCReturn.quantity13.value == 0 && document.AddCReturn.unit_price13.value == 0) { alert("All entries for Item #13 should have values"); document.AddCReturn.product_id13.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id14.value.length != 0 && document.AddCReturn.quantity14.value == 0 && document.AddCReturn.unit_price14.value == 0) { alert("All entries for Item #14 should have values"); document.AddCReturn.product_id14.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id15.value.length != 0 && document.AddCReturn.quantity15.value == 0 && document.AddCReturn.unit_price15.value == 0) { alert("All entries for Item #15 should have values"); document.AddCReturn.product_id15.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id16.value.length != 0 && document.AddCReturn.quantity16.value == 0 && document.AddCReturn.unit_price16.value == 0) { alert("All entries for Item #16 should have values"); document.AddCReturn.product_id16.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id17.value.length != 0 && document.AddCReturn.quantity17.value == 0 && document.AddCReturn.unit_price17.value == 0) { alert("All entries for Item #17 should have values"); document.AddCReturn.product_id17.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id18.value.length != 0 && document.AddCReturn.quantity18.value == 0 && document.AddCReturn.unit_price18.value == 0) { alert("All entries for Item #18 should have values"); document.AddCReturn.product_id18.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id19.value.length != 0 && document.AddCReturn.quantity19.value == 0 && document.AddCReturn.unit_price19.value == 0) { alert("All entries for Item #19 should have values"); document.AddCReturn.product_id19.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id20.value.length != 0 && document.AddCReturn.quantity20.value == 0 && document.AddCReturn.unit_price20.value == 0) { alert("All entries for Item #20 should have values"); document.AddCReturn.product_id20.style.backgroundColor = "#FFFF00"; return false; } } if (document.AddCReturn.product_id1.value.length != 0) { if (document.AddCReturn.product_id1.value == document.AddCReturn.product_id2.value) { alert("Entries for products 1 and 2 are the same!"); document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id2.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id1.value == document.AddCReturn.product_id3.value) { alert("Entries for products 1 and 3 are the same!"); document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id3.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id1.value == document.AddCReturn.product_id4.value) { alert("Entries for products 1 and 4 are the same!"); document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id4.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id1.value == document.AddCReturn.product_id5.value) { alert("Entries for products 1 and 5 are the same!"); document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id5.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id1.value == document.AddCReturn.product_id6.value) { alert("Entries for products 1 and 6 are the same!"); document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id6.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id1.value == document.AddCReturn.product_id7.value) { alert("Entries for products 1 and 7 are the same!"); document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id7.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id1.value == document.AddCReturn.product_id8.value) { alert("Entries for products 1 and 8 are the same!"); document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id8.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id1.value == document.AddCReturn.product_id9.value) { alert("Entries for products 1 and 9 are the same!"); document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id9.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id1.value == document.AddCReturn.product_id10.value) { alert("Entries for products 1 and 10 are the same!"); document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id10.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id1.value == document.AddCReturn.product_id11.value) { alert("Entries for products 1 and 11 are the same!"); document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id11.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id1.value == document.AddCReturn.product_id12.value) { alert("Entries for products 1 and 12 are the same!"); document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id12.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id1.value == document.AddCReturn.product_id13.value) { alert("Entries for products 1 and 13 are the same!"); document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id13.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id1.value == document.AddCReturn.product_id14.value) { alert("Entries for products 1 and 14 are the same!"); document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id14.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id1.value == document.AddCReturn.product_id15.value) { alert("Entries for products 1 and 15 are the same!"); document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id15.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id1.value == document.AddCReturn.product_id16.value) { alert("Entries for products 1 and 16 are the same!"); document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id16.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id1.value == document.AddCReturn.product_id17.value) { alert("Entries for products 1 and 17 are the same!"); document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id17.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id1.value == document.AddCReturn.product_id18.value) { alert("Entries for products 1 and 18 are the same!"); document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id18.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id1.value == document.AddCReturn.product_id19.value) { alert("Entries for products 1 and 19 are the same!"); document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id19.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id1.value == document.AddCReturn.product_id20.value) { alert("Entries for products 1 and 20 are the same!"); document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id20.style.backgroundColor = "#FFFF00"; return false; } } if (document.AddCReturn.product_id2.value.length != 0) { if (document.AddCReturn.product_id2.value == document.AddCReturn.product_id3.value) { alert("Entries for products 2 and 3 are the same!"); document.AddCReturn.product_id2.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id3.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id2.value == document.AddCReturn.product_id4.value) { alert("Entries for products 2 and 4 are the same!"); document.AddCReturn.product_id2.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id4.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id2.value == document.AddCReturn.product_id5.value) { alert("Entries for products 2 and 5 are the same!"); document.AddCReturn.product_id2.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id5.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id2.value == document.AddCReturn.product_id6.value) { alert("Entries for products 2 and 6 are the same!"); document.AddCReturn.product_id2.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id6.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id2.value == document.AddCReturn.product_id7.value) { alert("Entries for products 2 and 7 are the same!"); document.AddCReturn.product_id2.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id7.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id2.value == document.AddCReturn.product_id8.value) { alert("Entries for products 2 and 8 are the same!"); document.AddCReturn.product_id2.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id8.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id2.value == document.AddCReturn.product_id9.value) { alert("Entries for products 2 and 9 are the same!"); document.AddCReturn.product_id2.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id9.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id2.value == document.AddCReturn.product_id10.value) { alert("Entries for products 2 and 10 are the same!"); document.AddCReturn.product_id2.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id10.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id2.value == document.AddCReturn.product_id11.value) { alert("Entries for products 2 and 11 are the same!"); document.AddCReturn.product_id2.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id11.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id2.value == document.AddCReturn.product_id12.value) { alert("Entries for products 2 and 12 are the same!"); document.AddCReturn.product_id2.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id12.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id2.value == document.AddCReturn.product_id13.value) { alert("Entries for products 2 and 13 are the same!"); document.AddCReturn.product_id2.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id13.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id2.value == document.AddCReturn.product_id14.value) { alert("Entries for products 2 and 14 are the same!"); document.AddCReturn.product_id2.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id14.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id2.value == document.AddCReturn.product_id15.value) { alert("Entries for products 2 and 15 are the same!"); document.AddCReturn.product_id2.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id15.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id2.value == document.AddCReturn.product_id16.value) { alert("Entries for products 2 and 16 are the same!"); document.AddCReturn.product_id2.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id16.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id2.value == document.AddCReturn.product_id17.value) { alert("Entries for products 2 and 17 are the same!"); document.AddCReturn.product_id2.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id17.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id2.value == document.AddCReturn.product_id18.value) { alert("Entries for products 2 and 18 are the same!"); document.AddCReturn.product_id2.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id18.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id2.value == document.AddCReturn.product_id19.value) { alert("Entries for products 2 and 19 are the same!"); document.AddCReturn.product_id2.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id19.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id2.value == document.AddCReturn.product_id20.value) { alert("Entries for products 2 and 20 are the same!"); document.AddCReturn.product_id2.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id20.style.backgroundColor = "#FFFF00"; return false; } } if (document.AddCReturn.product_id3.value.length != 0) { if (document.AddCReturn.product_id3.value == document.AddCReturn.product_id4.value) { alert("Entries for products 3 and 4 are the same!"); document.AddCReturn.product_id3.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id4.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id3.value == document.AddCReturn.product_id5.value) { alert("Entries for products 3 and 5 are the same!"); document.AddCReturn.product_id3.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id5.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id3.value == document.AddCReturn.product_id6.value) { alert("Entries for products 3 and 6 are the same!"); document.AddCReturn.product_id3.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id6.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id3.value == document.AddCReturn.product_id7.value) { alert("Entries for products 3 and 7 are the same!"); document.AddCReturn.product_id3.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id7.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id3.value == document.AddCReturn.product_id8.value) { alert("Entries for products 3 and 8 are the same!"); document.AddCReturn.product_id3.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id8.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id3.value == document.AddCReturn.product_id9.value) { alert("Entries for products 3 and 9 are the same!"); document.AddCReturn.product_id3.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id9.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id3.value == document.AddCReturn.product_id10.value) { alert("Entries for products 3 and 10 are the same!"); document.AddCReturn.product_id3.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id10.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id3.value == document.AddCReturn.product_id11.value) { alert("Entries for products 3 and 11 are the same!"); document.AddCReturn.product_id3.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id3.value == document.AddCReturn.product_id12.value) { alert("Entries for products 3 and 12 are the same!"); document.AddCReturn.product_id3.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id3.value == document.AddCReturn.product_id13.value) { alert("Entries for products 3 and 13 are the same!"); document.AddCReturn.product_id3.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id3.value == document.AddCReturn.product_id14.value) { alert("Entries for products 3 and 14 are the same!"); document.AddCReturn.product_id3.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id3.value == document.AddCReturn.product_id15.value) { alert("Entries for products 3 and 15 are the same!"); document.AddCReturn.product_id3.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id3.value == document.AddCReturn.product_id16.value) { alert("Entries for products 3 and 16 are the same!"); document.AddCReturn.product_id3.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id3.value == document.AddCReturn.product_id17.value) { alert("Entries for products 3 and 17 are the same!"); document.AddCReturn.product_id3.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id3.value == document.AddCReturn.product_id18.value) { alert("Entries for products 3 and 18 are the same!"); document.AddCReturn.product_id3.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id3.value == document.AddCReturn.product_id19.value) { alert("Entries for products 3 and 19 are the same!"); document.AddCReturn.product_id3.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id3.value == document.AddCReturn.product_id20.value) { alert("Entries for products 3 and 20 are the same!"); document.AddCReturn.product_id3.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id1.style.backgroundColor = "#FFFF00"; return false; } } if (document.AddCReturn.product_id4.value.length != 0) { if (document.AddCReturn.product_id4.value == document.AddCReturn.product_id5.value) { alert("Entries for products 4 and 5 are the same!"); document.AddCReturn.product_id4.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id5.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id4.value == document.AddCReturn.product_id6.value) { alert("Entries for products 4 and 6 are the same!"); document.AddCReturn.product_id4.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id6.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id4.value == document.AddCReturn.product_id7.value) { alert("Entries for products 4 and 7 are the same!"); document.AddCReturn.product_id4.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id7.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id4.value == document.AddCReturn.product_id8.value) { alert("Entries for products 4 and 8 are the same!"); document.AddCReturn.product_id4.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id8.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id4.value == document.AddCReturn.product_id9.value) { alert("Entries for products 4 and 9 are the same!"); document.AddCReturn.product_id4.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id9.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id4.value == document.AddCReturn.product_id10.value) { alert("Entries for products 4 and 10 are the same!"); document.AddCReturn.product_id4.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id10.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id4.value == document.AddCReturn.product_id11.value) { alert("Entries for products 4 and 11 are the same!"); document.AddCReturn.product_id4.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id11.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id4.value == document.AddCReturn.product_id12.value) { alert("Entries for products 4 and 12 are the same!"); document.AddCReturn.product_id4.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id12.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id4.value == document.AddCReturn.product_id13.value) { alert("Entries for products 4 and 13 are the same!"); document.AddCReturn.product_id4.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id13.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id4.value == document.AddCReturn.product_id14.value) { alert("Entries for products 4 and 14 are the same!"); document.AddCReturn.product_id4.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id14.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id4.value == document.AddCReturn.product_id15.value) { alert("Entries for products 4 and 15 are the same!"); document.AddCReturn.product_id4.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id15.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id4.value == document.AddCReturn.product_id16.value) { alert("Entries for products 4 and 16 are the same!"); document.AddCReturn.product_id4.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id16.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id4.value == document.AddCReturn.product_id17.value) { alert("Entries for products 4 and 17 are the same!"); document.AddCReturn.product_id4.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id17.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id4.value == document.AddCReturn.product_id18.value) { alert("Entries for products 4 and 18 are the same!"); document.AddCReturn.product_id4.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id18.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id4.value == document.AddCReturn.product_id19.value) { alert("Entries for products 4 and 19 are the same!"); document.AddCReturn.product_id4.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id19.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id4.value == document.AddCReturn.product_id20.value) { alert("Entries for products 4 and 20 are the same!"); document.AddCReturn.product_id4.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id20.style.backgroundColor = "#FFFF00"; return false; } } if (document.AddCReturn.product_id5.value.length != 0) { if (document.AddCReturn.product_id5.value == document.AddCReturn.product_id6.value) { alert("Entries for products 5 and 6 are the same!"); document.AddCReturn.product_id5.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id6.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id5.value == document.AddCReturn.product_id7.value) { alert("Entries for products 5 and 7 are the same!"); document.AddCReturn.product_id5.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id7.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id5.value == document.AddCReturn.product_id8.value) { alert("Entries for products 5 and 8 are the same!"); document.AddCReturn.product_id5.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id8.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id5.value == document.AddCReturn.product_id9.value) { alert("Entries for products 5 and 9 are the same!"); document.AddCReturn.product_id5.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id9.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id5.value == document.AddCReturn.product_id10.value) { alert("Entries for products 5 and 10 are the same!"); document.AddCReturn.product_id5.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id10.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id5.value == document.AddCReturn.product_id11.value) { alert("Entries for products 5 and 11 are the same!"); document.AddCReturn.product_id5.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id11.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id5.value == document.AddCReturn.product_id12.value) { alert("Entries for products 5 and 12 are the same!"); document.AddCReturn.product_id5.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id12.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id5.value == document.AddCReturn.product_id13.value) { alert("Entries for products 5 and 13 are the same!"); document.AddCReturn.product_id5.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id13.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id5.value == document.AddCReturn.product_id14.value) { alert("Entries for products 5 and 14 are the same!"); document.AddCReturn.product_id5.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id14.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id5.value == document.AddCReturn.product_id15.value) { alert("Entries for products 5 and 15 are the same!"); document.AddCReturn.product_id5.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id15.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id5.value == document.AddCReturn.product_id16.value) { alert("Entries for products 5 and 16 are the same!"); document.AddCReturn.product_id5.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id16.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id5.value == document.AddCReturn.product_id17.value) { alert("Entries for products 5 and 17 are the same!"); document.AddCReturn.product_id5.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id17.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id5.value == document.AddCReturn.product_id18.value) { alert("Entries for products 5 and 18 are the same!"); document.AddCReturn.product_id5.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id18.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id5.value == document.AddCReturn.product_id19.value) { alert("Entries for products 5 and 19 are the same!"); document.AddCReturn.product_id5.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id19.style.backgroundColor = "#FFFF00"; return false; } if (document.AddCReturn.product_id5.value == document.AddCReturn.product_id20.value) { alert("Entries for products 5 and 20 are the same!"); document.AddCReturn.product_id5.style.backgroundColor = "#FFFF00"; document.AddCReturn.product_id20.style.backgroundColor = "#FFFF00"; return false; } } return true; }
  2. Hi guys. My client has been using the system i made him for months now. But he realized he has to add new products having expiration dates. So i have to update my tables design. These are my current tables. CREATE TABLE `branch_products` ( `bp_id` int( NOT NULL AUTO_INCREMENT, `branch_id` tinyint(4) NOT NULL, `product_id` int(5) NOT NULL, `stocks` int(10) NOT NULL, `reorder_level` int(6) NOT NULL, `ave_acquisition` decimal(10,2) NOT NULL, `last_movement` date NOT NULL, PRIMARY KEY (`bp_id`) ) ENGINE=MyISAM; CREATE TABLE `purchases` ( `purchase_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `branch_id` int(2) NOT NULL, `or_num` varchar(10) COLLATE latin1_general_ci NOT NULL, `supplier_id` int(4) unsigned NOT NULL, `delivery` date NOT NULL DEFAULT '0000-00-00', `received_by` int(2) NOT NULL, `notes` varchar(255) COLLATE latin1_general_ci NOT NULL, `line_total` decimal(13,2) unsigned NOT NULL DEFAULT '0.00', `balance` decimal(13,2) unsigned NOT NULL DEFAULT '0.00', PRIMARY KEY (`purchase_id`) ) ENGINE=MyISAM; CREATE TABLE IF NOT EXISTS `purchase_details` ( `pd_id` int(15) unsigned NOT NULL AUTO_INCREMENT, `purchase_id` int(10) unsigned NOT NULL, `product_id` int(5) unsigned NOT NULL, `quantity` int(6) unsigned NOT NULL, `unit_price` decimal(10,2) unsigned NOT NULL DEFAULT '0.00', `net_price` decimal(13,2) NOT NULL, PRIMARY KEY (`pd_id`) ) ENGINE=MyISAM; CREATE TABLE IF NOT EXISTS `sales` ( `sale_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `or_num` int(6) unsigned zerofill NOT NULL, `branch_id` tinyint(4) NOT NULL, `customer_id` int(4) unsigned NOT NULL DEFAULT '0', `sale_dtime` datetime NOT NULL, `due_date` date NOT NULL, `notes` text COLLATE latin1_general_ci NOT NULL, `line_total` decimal(13,2) unsigned NOT NULL DEFAULT '0.00', `balance` decimal(13,2) unsigned NOT NULL DEFAULT '0.00', `revenue` decimal(10,2) NOT NULL, PRIMARY KEY (`sale_id`) ) ENGINE=MyISAM; CREATE TABLE IF NOT EXISTS `sale_details` ( `sd_id` int(15) unsigned NOT NULL AUTO_INCREMENT, `sale_id` int(10) unsigned NOT NULL, `product_id` int(5) unsigned NOT NULL, `acq_price` decimal(10,2) NOT NULL, `quantity` int(6) unsigned NOT NULL, `price` decimal(10,2) unsigned NOT NULL DEFAULT '0.00', `net_price` decimal(13,2) NOT NULL, PRIMARY KEY (`sd_id`) ) ENGINE=MyISAM; What fields should i add to existing tables, and what new tables should i make to be able to handle if my client wants to know how many product 'A' are there in branch '1' that will expire on sept 30, 2011? Thanks so much guys.
  3. I'm having problems with my scripts. Javascipt output is inconsistent. What i mean is that if i'm accessing the system on my machine, the system outputs the correct figures. But when it is accessed using another machine, incorrect figures are displayed. We are all using google chrome so i guess the browser is not the issue. Javascript is enabled. The operating system might be the issue but im not sure. The system is launched at brinkster.com here are the codes: <form name="AddOrder" action="add_order.php" method="POST"> <tbody class="data"> <?PHP for ($i=1; $i<11; $i++) { $m = fmod($i, 2); if ($m == 0) { ?><tr class="even"><?PHP } else { ?><tr class="odd"><?PHP } ?> <td align="center"><?PHP echo $i ?></td><td align="left"><select id="product_id<?PHP echo $i ?>" name="product_id<?PHP echo $i ?>" onchange="OrderRequest('sell_price<?PHP echo $i ?>', 'get_price.php?product_id=', 'promo<?PHP echo $i ?>', 'get_promo.php?product_id=', 'qty_mul<?PHP echo $i ?>', 'get_qty_mul.php?product_id=', 'price_mul<?PHP echo $i ?>', 'get_price_mul.php?product_id=', 'product_id<?PHP echo $i ?>')"><option value="0">Product Name</option> <?PHP $sql = "SELECT product_id, product_name FROM products WHERE ptype = 1 ORDER BY product_name"; $pres = mysql_query($sql); while ($prow = mysql_fetch_array($pres)) { print "<option value=$prow[0]>$prow[1]</option>"; } mysql_free_result($pres); ?></select></td> <td align="center"><input type="text" size="10" id="promo<?PHP echo $i ?>" name="promo<?PHP echo $i ?>" readonly="true"></td> <td align="center"><input type="text" size="7" id="price_mul<?PHP echo $i ?>" name="price_mul<?PHP echo $i ?>" style="text-align:right;"></td> <td align="center"><input type="text" size="7" id="qty_mul<?PHP echo $i ?>" name="qty_mul<?PHP echo $i ?>" style="text-align:right;"></td> <td align="center"><input type="text" size="7" id="sell_price<?PHP echo $i ?>" name="sell_price<?PHP echo $i ?>" readonly="true" style="text-align:right;"></td> <td align="center"><input type="text" size="7" id="quantity<?PHP echo $i ?>" name="quantity<?PHP echo $i ?>" onblur="PromoRequest('sell_price<?PHP echo $i ?>', 'get_promo_price.php', 'net_price<?PHP echo $i ?>', 'get_net_price.php', 'tquantity<?PHP echo $i ?>', 'product_id<?PHP echo $i ?>', 'quantity<?PHP echo $i ?>', 'sell_price<?PHP echo $i ?>', 'price_mul<?PHP echo $i ?>', 'qty_mul<?PHP echo $i ?>')" style="text-align:right;"></td> <td align="center"><input type="text" size="7" id="tquantity<?PHP echo $i ?>" name="tquantity<?PHP echo $i ?>" readonly="true" style="text-align:right;" onblur="getOrderTPrice()"></td> <td align="center"><input type="text" size="7" id="net_price<?PHP echo $i ?>" name="net_price<?PHP echo $i ?>" readonly="true" style="text-align:right;" onblur="getOrderTPrice()"></td> </tr> <?PHP } ?> <tr class="odd"> <td colspan="7" align="right"><b>Line Totals</b></td> <td align="center"><input type="text" size="7" id="tqty" name="tqty" readonly="true" style="text-align:right;"></td> <td align="center"><input type="text" size="7" id="tnet_price" name="tnet_price" readonly="true" style="text-align:right;"></td> </tr> <tr class="odd"><td align="center" colspan="9"> <input type="hidden" name="submitted" value="1"> <input type="hidden" name="token" value="<?PHP echo $token ?>"> <input type="hidden" name="order_id" value="<?PHP echo $order_id ?>"> <input type="reset"> <input onClick="valAddOrder()" type="button" value="Submit"></td></tr> </tbody> </form> javascript: function PromoRequest(target_div1, file1, target_div2, file2, target_div3, product_id, quantity, sell_price, price_mul, qty_mul) { var MyHttpRequest = false; var MyHttpRequest2 = false; var MyHttpLoading = 'Loading...'; var ErrorMSG = 'Sorry - No XMLHTTP support in your browser, buy a newspaper instead'; var customer_id = document.AddOrder.customer_id.value; var product_id = document.getElementById(product_id).value; var quantity = document.getElementById(quantity).value; var sell_price = document.getElementById(sell_price).value; var price_mul = document.getElementById(price_mul).value; var qty_mul = document.getElementById(qty_mul).value; if(window.XMLHttpRequest) { // client use Firefox, Opera etc - Non Microsoft product try { MyHttpRequest = new XMLHttpRequest(); MyHttpRequest2 = new XMLHttpRequest(); MyHttpRequest3 = new XMLHttpRequest(); } catch(e) { MyHttpRequest = false; MyHttpRequest2 = false; MyHttpRequest3 = false; } } else if(window.ActiveXObject) { // client use Internet Explorer try { MyHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); MyHttpRequest2 = new ActiveXObject("Msxml2.XMLHTTP"); MyHttpRequest3 = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { MyHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); MyHttpRequest2 = new ActiveXObject("Microsoft.XMLHTTP"); MyHttpRequest3 = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { MyHttpRequest = false; MyHttpRequest2 = false; MyHttpRequest3 = false; } } } else { MyHttpRequest = false; MyHttpRequest2 = false; MyHttpRequest3 = false; } if(MyHttpRequest) { // browser supports httprequest var query_string = '?product_id=' + product_id + '&quantity=' + quantity + '&sell_price=' + sell_price + '&customer_id=' + customer_id; MyHttpRequest.open("get", url_encode(file1 + query_string), true); // <-- run the httprequest using GET MyHttpRequest.onreadystatechange = function () { if(MyHttpRequest.readyState == 4) { // done and responded document.getElementById(target_div1).value = MyHttpRequest.responseText; // display result } else { document.getElementById(target_div1).value = MyHttpLoading; // still working } } MyHttpRequest.send(null); } else { document.getElementById(target_div1).value = ErrorMSG; // the browser was unable to create a httprequest } if(MyHttpRequest2) { // browser supports httprequest var query_string = '?product_id=' + product_id + '&quantity=' + quantity + '&sell_price=' + sell_price + '&price_mul=' + price_mul + '&customer_id=' + customer_id; MyHttpRequest2.open("get", url_encode(file2 + query_string), true); // <-- run the httprequest using GET MyHttpRequest2.onreadystatechange = function () { if(MyHttpRequest2.readyState == 4) { // done and responded document.getElementById(target_div2).value = MyHttpRequest2.responseText; // display result } else { document.getElementById(target_div2).value = MyHttpLoading; // still working } } MyHttpRequest2.send(null); } else { document.getElementById(target_div2).value = ErrorMSG; // the browser was unable to create a httprequest } if(MyHttpRequest3) { // browser supports httprequest var tqty = quantity * qty_mul; document.getElementById(target_div3).value = tqty; } else { document.getElementById(target_div3).value = ErrorMSG; // the browser was unable to create a httprequest } } function OrderRequest(target_div, file, target_div2, file2, target_div3, file3, target_div4, file4, check_div) { // get the branch selected var customer_id = document.AddOrder.customer_id.value; if (customer_id == 0) { alert("Please select the dealer first!"); document.AddOrder.customer_id.style.backgroundColor = "#FFFF00"; } else { var MyHttpRequest = false; var MyHttpRequest2 = false; var MyHttpRequest3 = false; var MyHttpRequest4 = false; var MyHttpLoading = 'Loading...'; var ErrorMSG = 'Sorry - No XMLHTTP support in your browser, buy a newspaper instead'; if(check_div) { var check_value = document.getElementById(check_div).value; } else { var check_value = ''; } if(window.XMLHttpRequest) { // client use Firefox, Opera etc - Non Microsoft product try { MyHttpRequest = new XMLHttpRequest(); MyHttpRequest2 = new XMLHttpRequest(); MyHttpRequest3 = new XMLHttpRequest(); MyHttpRequest4 = new XMLHttpRequest(); } catch(e) { MyHttpRequest = false; MyHttpRequest2 = false; MyHttpRequest3 = false; MyHttpRequest4 = false; } } else if(window.ActiveXObject) { // client use Internet Explorer try { MyHttpRequest = new ActiveXObject("Msxml2.XMLHTTP"); MyHttpRequest2 = new ActiveXObject("Msxml2.XMLHTTP"); MyHttpRequest3 = new ActiveXObject("Msxml2.XMLHTTP"); MyHttpRequest4 = new ActiveXObject("Msxml2.XMLHTTP"); } catch(e) { try { MyHttpRequest = new ActiveXObject("Microsoft.XMLHTTP"); MyHttpRequest2 = new ActiveXObject("Microsoft.XMLHTTP"); MyHttpRequest3 = new ActiveXObject("Microsoft.XMLHTTP"); MyHttpRequest4 = new ActiveXObject("Microsoft.XMLHTTP"); } catch(e) { MyHttpRequest = false; MyHttpRequest2 = false; MyHttpRequest3 = false; MyHttpRequest4 = false; } } } else { MyHttpRequest = false; MyHttpRequest2 = false; MyHttpRequest3 = false; MyHttpRequest4 = false; } if(MyHttpRequest) { // browser supports httprequest var random = Math.random() * Date.parse(new Date()); // make a random string to prevent caching var file_array = file.split('.'); // prepare to check if we have a query string or a html/htm file if(file_array[1] == 'php') { // no query string, just calling a php file var query_string = '?rand=' + random; } else if(file_array[1] == 'htm' || file_array[1] == 'html') { // calling a htm or html file var query_string = ''; } else { // we have presumable a php file with a query string attached var query_string = check_value + '&customer_id=' + customer_id + '&rand=' + random; } MyHttpRequest.open("get", url_encode(file + query_string), true); // <-- run the httprequest using GET // handle the httprequest MyHttpRequest.onreadystatechange = function () { if(MyHttpRequest.readyState == 4) { // done and responded document.getElementById(target_div).value = MyHttpRequest.responseText; // display result } else { document.getElementById(target_div).value = MyHttpLoading; // still working } } MyHttpRequest.send(null); } else { document.getElementById(target_div).value = ErrorMSG; // the browser was unable to create a httprequest } if(MyHttpRequest2) // browser supports httprequest { var random = Math.random() * Date.parse(new Date()); // make a random string to prevent caching var file_array = file2.split('.'); // prepare to check if we have a query string or a html/htm file if(file_array[1] == 'php') // no query string, just calling a php file { var query_string = '?rand=' + random; } else if(file_array[1] == 'htm' || file_array[1] == 'html') // calling a htm or html file { var query_string = ''; } else // we have presumable a php file with a query string attached { var query_string = check_value + '&rand=' + random; } MyHttpRequest2.open("get", url_encode(file2 + query_string), true); // <-- run the httprequest using GET // handle the httprequest MyHttpRequest2.onreadystatechange = function () { if(MyHttpRequest2.readyState == 4) // done and responded { document.getElementById(target_div2).value = MyHttpRequest2.responseText; // display result } else { document.getElementById(target_div2).value = MyHttpLoading; // still working } } MyHttpRequest2.send(null); } else { document.getElementById(target_div2).value = ErrorMSG; // the browser was unable to create a httprequest } if(MyHttpRequest3) // browser supports httprequest { var random = Math.random() * Date.parse(new Date()); // make a random string to prevent caching var file_array = file3.split('.'); // prepare to check if we have a query string or a html/htm file if(file_array[1] == 'php') // no query string, just calling a php file { var query_string = '?rand=' + random; } else if(file_array[1] == 'htm' || file_array[1] == 'html') // calling a htm or html file { var query_string = ''; } else // we have presumable a php file with a query string attached { var query_string = check_value + '&rand=' + random; } MyHttpRequest3.open("get", url_encode(file3 + query_string), true); // <-- run the httprequest using GET // handle the httprequest MyHttpRequest3.onreadystatechange = function () { if(MyHttpRequest3.readyState == 4) // done and responded { document.getElementById(target_div3).value = MyHttpRequest3.responseText; // display result } else { document.getElementById(target_div3).value = MyHttpLoading; // still working } } MyHttpRequest3.send(null); } else { document.getElementById(target_div3).value = ErrorMSG; // the browser was unable to create a httprequest } if(MyHttpRequest4) // browser supports httprequest { var random = Math.random() * Date.parse(new Date()); // make a random string to prevent caching var file_array = file4.split('.'); // prepare to check if we have a query string or a html/htm file if(file_array[1] == 'php') // no query string, just calling a php file { var query_string = '?rand=' + random; } else if(file_array[1] == 'htm' || file_array[1] == 'html') // calling a htm or html file { var query_string = ''; } else // we have presumable a php file with a query string attached { var query_string = check_value + '&rand=' + random; } MyHttpRequest4.open("get", url_encode(file4 + query_string), true); // <-- run the httprequest using GET // handle the httprequest MyHttpRequest4.onreadystatechange = function () { if(MyHttpRequest4.readyState == 4) // done and responded { document.getElementById(target_div4).value = MyHttpRequest4.responseText; // display result } else { document.getElementById(target_div4).value = MyHttpLoading; // still working } } MyHttpRequest4.send(null); } else { document.getElementById(target_div4).value = ErrorMSG; // the browser was unable to create a httprequest } } } function getOrderTPrice() { var tquantity1 = +document.AddOrder.tquantity1.value; var tquantity2 = +document.AddOrder.tquantity2.value; var tquantity3 = +document.AddOrder.tquantity3.value; var tquantity4 = +document.AddOrder.tquantity4.value; var tquantity5 = +document.AddOrder.tquantity5.value; var tquantity6 = +document.AddOrder.tquantity6.value; var tquantity7 = +document.AddOrder.tquantity7.value; var tquantity8 = +document.AddOrder.tquantity8.value; var tquantity9 = +document.AddOrder.tquantity9.value; var tquantity10 = +document.AddOrder.tquantity10.value; var net_price1 = +document.AddOrder.net_price1.value; var net_price2 = +document.AddOrder.net_price2.value; var net_price3 = +document.AddOrder.net_price3.value; var net_price4 = +document.AddOrder.net_price4.value; var net_price5 = +document.AddOrder.net_price5.value; var net_price6 = +document.AddOrder.net_price6.value; var net_price7 = +document.AddOrder.net_price7.value; var net_price8 = +document.AddOrder.net_price8.value; var net_price9 = +document.AddOrder.net_price9.value; var net_price10 = +document.AddOrder.net_price10.value; var tqty = (tquantity1 * 1) + (tquantity2 * 1) + (tquantity3 * 1) + (tquantity4 * 1) + (tquantity5 * 1) + (tquantity6 * 1) + (tquantity7 * 1) + (tquantity8 * 1) + (tquantity9 * 1) + (tquantity10 * 1); var tnet_price = (net_price1 * 1) + (net_price2 * 1) + (net_price3 * 1) + (net_price4 * 1) + (net_price5 * 1) + (net_price6 * 1) + (net_price7 * 1) + (net_price8 * 1) + (net_price9 * 1) + (net_price10 * 1); document.AddOrder.tqty.value = tqty; document.AddOrder.tnet_price.value = tnet_price; } The problem is that the net price and line total are sometimes correct but sometimes incorrect. I really dont know where is the problem. Please give me insights. A million thanks.
  4. Im sorry, my mistake... here it is: $host = "MySQL8.someserver.com"; $username = "username"; $password = "password"; $database = "mydb"; $server = mysql_connect($host, $username, $password) or die(mysql_error()); // Select the database now $connection = mysql_select_db($database, $server) or die(mysql_error()); $sql = "SET time_zone = '+8:00'"; mysql_query($sql) or die(mysql_error());
  5. Error Message: Warning: mysql_connect() [function.mysql-connect]: Can't create a new thread (errno 12); if you are not out of available memory, you can consult the manual for a possible OS-dependent bug in C:\sites\Single56\innoserve\webroot\lib\dai\ka\pwede\digdi\connect.php on line 8 Can't create a new thread (errno 12); if you are not out of available memory, you can consult the manual for a possible OS-dependent bug This is the first time i've encountered this. Please give me insights. This is my code: <?php // ****** connect.php ****** $host = "localhost"; $username = "username"; $password = "password"; $database = "db"; $server = mysql_connect($host, $username, $password) or die(mysql_error()); // Select the database now $connection = mysql_select_db($database, $server) or die(mysql_error()); $sql = "SET time_zone = '+8:00'"; mysql_query($sql) or die(mysql_error());
  6. Hello guys! I've just tried this someone else's CSS code. It is about pop-up navigation. It works fine with chrome but not with firefox and IE. Only the first child nav is shown. Any insight/suggestion? Thanks! Here are the codes: /* RULES FOR THE "MENUDIV" OBJECT */ /* An absolutely positioned and hidden DIV (treated as a layer in NS4). */ .menudiv { position: absolute; visibility: hidden; z-index: 1000; border: 2px outset #FFFFCC; /* Borders: Top Right Bottom Left */ border-color: #FFFFCC #666633 #666633 #FFFFCC; background-color: #CCCC99; /* layer-background-color is non-standard and NS4 only. */ layer-background-color: #CCCC99; padding: 5px; font: 14px/22px Arial, Helvetica, sans-serif; /* Here's a cool effect, try uncommenting this, althought it's non-standard: */ /* filter: alpha(opacity=80); -moz-opacity: 0.8; opacity: 0.8 */ } /* Formatting to apply to the elements inside the "menudiv" class elements. */ /* Of course, you can put whatever you want within the menu divs, these are just examples. */ .menudiv .header { width: 100%; font-weight: bold; text-align: center; border-bottom: 2px dashed #999966; margin-bottom: 5px; } .menudiv a { display: block; /* I've specified borders for each side individually so NS4 ignores this setting */ border-top: 1px solid #CCCC99; border-right: 1px solid #CCCC99; border-bottom: 1px solid #CCCC99; border-left: 1px solid #CCCC99; color: #003333; text-indent: 5px; text-decoration: none; } /* I'm using :hover and :active pseudo-classes for link mouse effects. */ .menudiv a:hover { border: 1px solid #336699; border-color: #6699CC #003366 #003366 #6699CC; background-color: #336699; color: #FFFFFF; } .menudiv a:active { border: 1px solid #003366; border-color: #000000 #3366CC #3366CC #000000; background-color: #003366; color: #FFFFFF; } /* The script will automatically assign a class of "highlighted" to elements that currently have an active submenu, so here's a little CSS to format links within a .menudiv element. */ .menudiv .highlighted { background-color: #336699; border-color: #336699; color: #FFFFFF; } /* The links in the upper-left that pop out 'divMenu' menus. */ .trigger a { font: Bold 14px Arial, Helvetica, sans-serif; color: #003366; text-decoration: none; } /* Likewise, style active trigger links */ .trigger a.highlighted { color: #CC9966; } /* All <ul> tags in the menu including the first level */ .menulist, .menulist ul { margin: 0; padding: 1px; width: 150px; list-style: none; background: #F0F0F8 url(listmenu_o.png) left repeat-y; border: 1px solid #CDCDCD; } /* Submenus (<ul> tags) are hidden and absolutely positioned across from their parent */ .menulist ul { display: none; position: absolute; top: 0; left: 150px; } /* All menu items (<li> tags) are relatively positioned (to correctly offset submenus). */ .menulist li { border: 1px solid #CDCDCD; position: relative; font-size: 11px; } /* Links inside the menu */ .menulist li a { display: block; padding: 1px 3px 1px 3px; color: #000; text-decoration: none; border: 1px solid transparent; margin: 0 } /* HACKS: MSIE6 doesn't support transparent borders, mimic with margins */ * html .menulist li a { border-width: 0; margin: 1px; } .menulist a:hover, .menulist a.highlighted:hover, .menulist a:focus { color: #FFF; background-color: #220066; padding: 1px 3px 1px 3px; border: 1px solid #ADF; margin: 0; } .menulist a.highlighted { color: #FFF; background-color: #440099; border: 1px solid #CDE; margin: 0; } /* 'subind' submenu indicators, which are automatically prepended to 'A' tag contents. */ .menulist a .subind { float: right; } *:first-child+html .menulist li { float: left; width: 100%; } * html .menulist li { float: left; height: 1%; } * html .menulist a { height: 1%; } /* End Hacks */
  7. Good day to you guys! The mysql function NOW() selects the date and time of server. What if the server is in the USA, how can i get the date and time here in GMT + 8:00? Thank you very much.
  8. Example scenario: Workstation #1: User #1 is entering sales with these items: Qty Product Price Total 5 ItemA $10 $50 5 ItemB $9 $45 5 ItemC $10 $50 Line Total $145 Workstation #2: User #2 is entering sales with these items: Qty Product Price Total 10 ItemD $10 $100 10 ItemE $12 $120 10 ItemF $15 $150 Line Total $370 After the sales were submitted: Sale entered in workstation #1: Qty Product Price Total 5 ItemA $10 $50 5 ItemB $9 $45 10 ItemF $15 $150 Line Total $245 Sale entered in workstation #2: Qty Product Price Total 10 ItemD $10 $100 10 ItemE $12 $120 5 ItemC $10 $50 Line Total $270 ItemC which is supposed to be in sale entered in workstation#1 is now in sale entered in workstation#2. ItemF which is supposed to be in sale entered in workstation#2 is now in sale entered in workstation#1. Line Total of sales are now changed since there were alteration in the items entered.
  9. Thanks PFMaBiSmAd for your reply. Please take a look at my tables and my code. Tables: CREATE TABLE IF NOT EXISTS `purchases` ( `purchase_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `or_num` varchar(10) COLLATE latin1_general_ci NOT NULL, `supplier_id` int(4) unsigned NOT NULL DEFAULT '0', `user_id` int(2) unsigned NOT NULL DEFAULT '0', `delivery_date` date NOT NULL DEFAULT '0000-00-00', `received_by` int(2) NOT NULL, `notes` varchar(255) COLLATE latin1_general_ci NOT NULL, `line_total` decimal(13,2) unsigned NOT NULL DEFAULT '0.00', `balance` decimal(13,2) unsigned NOT NULL DEFAULT '0.00', PRIMARY KEY (`purchase_id`) ); CREATE TABLE IF NOT EXISTS `purchase_details` ( `purchase_detail_id` int(15) unsigned NOT NULL AUTO_INCREMENT, `purchase_id` int(10) unsigned NOT NULL, `product_id` int(5) unsigned NOT NULL, `quantity` int(6) unsigned NOT NULL, `unit_price` decimal(10,2) unsigned NOT NULL DEFAULT '0.000', `unit_discount` decimal(8,2) unsigned NOT NULL DEFAULT '0.000', `net_price` decimal(13,2) NOT NULL, `balance` int(6) NOT NULL, PRIMARY KEY (`purchase_detail_id`) ); CREATE TABLE IF NOT EXISTS `sales` ( `sale_id` int(10) unsigned NOT NULL AUTO_INCREMENT, `or_num` varchar(10) COLLATE latin1_general_ci NOT NULL, `customer_id` int(4) unsigned NOT NULL DEFAULT '0', `user_id` int(2) unsigned NOT NULL DEFAULT '0', `delivery_date` date DEFAULT '0000-00-00', `due_date` date NOT NULL, `received_by` varchar(150) COLLATE latin1_general_ci NOT NULL, `notes` varchar(255) COLLATE latin1_general_ci DEFAULT NULL, `line_total` decimal(13,2) unsigned NOT NULL DEFAULT '0.00', `balance` decimal(13,2) unsigned NOT NULL DEFAULT '0.00', `revenue` decimal(10,2) NOT NULL, PRIMARY KEY (`sale_id`) ); CREATE TABLE IF NOT EXISTS `sale_details` ( `sale_detail_id` int(15) unsigned NOT NULL AUTO_INCREMENT, `sale_id` int(10) unsigned NOT NULL, `purchase_detail_id` int(15) unsigned NOT NULL, `product_id` int(5) unsigned NOT NULL, `quantity` int(6) unsigned NOT NULL, `issued` int(6) NOT NULL COMMENT 'actual issued quantity', `unit_price` decimal(10,2) unsigned NOT NULL DEFAULT '0.000', `unit_discount` decimal(8,2) unsigned NOT NULL DEFAULT '0.000', `net_price` decimal(13,2) NOT NULL, PRIMARY KEY (`sale_detail_id`) ); PHP Code: <?PHP if(isset($_POST['submit'])) { // if submit button has been pressed $sale_id = mysql_real_escape_string($_POST['sale_id']); $customer_id = mysql_real_escape_string($_POST['customer_id']); $received_by = mysql_real_escape_string($_POST['received_by']); $notes = mysql_real_escape_string($_POST['notes']); $due_date = mysql_real_escape_string($_POST['due_date']); if ($customer_id != "") { $a = TRUE; } else { $a = FALSE; $message[] = "Please select from the list of customers."; } if ($received_by != "") { $b = TRUE; } else { $b = FALSE; $message[] = "Please enter the person who received the product sale."; } if ($due_date != "") { $c = TRUE; } else { $c = FALSE; $message[] = "Please enter the due date of payment."; } // If the data pass all tests, add the patient to the database. if ( $a && $b && $c ) { // check if the sale already exists $sql = "SELECT sale_id FROM sales WHERE customer_id = '$customer_id' AND delivery_date = CURDATE()"; $sres = mysql_query($sql); $snum = mysql_num_rows($sres); $srow = mysql_fetch_array($sres); if ($snum > 0) { print "Sale already exists in the database.<br>Click <a class=paging href='sale.php?sale_id=$srow[0]'>here</a> to view the product sale.<br>"; } else { $sql = "INSERT INTO sales( customer_id, user_id, delivery_date, due_date, received_by, notes ) VALUES( '$customer_id', '$_SESSION[user_id]', CURDATE(), '$due_date', '$received_by', '$notes' )"; if (mysql_query($sql)) { $sale_id = mysql_insert_id(); $sql = "UPDATE customers SET lastsale = CURDATE() WHERE customer_id = '$customer_id' LIMIT 1"; mysql_query($sql) or die(mysql_error()); } else { echo "Could not add sale into database<br>"; } if ($_POST[product_id1] != "" && $_POST[quantity1] != "") { Add2Sale($_POST[product_id1], $_POST[quantity1], $sale_id, $_POST[unit_price1], $_POST[unit_discount1], $_POST[net_price1]); } // end of product # 1 if ($_POST[product_id2] != "" && $_POST[quantity2] != "") { Add2Sale($_POST[product_id2], $_POST[quantity2], $sale_id, $_POST[unit_price2], $_POST[unit_discount2], $_POST[net_price2]); } // end of product # 2 if ($_POST[product_id3] != "" && $_POST[quantity3] != "") { Add2Sale($_POST[product_id3], $_POST[quantity3], $sale_id, $_POST[unit_price3], $_POST[unit_discount3], $_POST[net_price3]); } // end of product # 3 if ($_POST[product_id4] != "" && $_POST[quantity4] != "") { Add2Sale($_POST[product_id4], $_POST[quantity4], $sale_id, $_POST[unit_price4], $_POST[unit_discount4], $_POST[net_price4]); } // end of product # 4 if ($_POST[product_id5] != "" && $_POST[quantity5] != "") { Add2Sale($_POST[product_id5], $_POST[quantity5], $sale_id, $_POST[unit_price5], $_POST[unit_discount5], $_POST[net_price5]); } // end of product # 5 if ($_POST[product_id6] != "" && $_POST[quantity6] != "") { Add2Sale($_POST[product_id6], $_POST[quantity6], $sale_id, $_POST[unit_price6], $_POST[unit_discount6], $_POST[net_price6]); } // end of product # 6 if ($_POST[product_id7] != "" && $_POST[quantity7] != "") { Add2Sale($_POST[product_id7], $_POST[quantity7], $sale_id, $_POST[unit_price7], $_POST[unit_discount7], $_POST[net_price7]); } // end of product # 7 if ($_POST[product_id8] != "" && $_POST[quantity8] != "") { Add2Sale($_POST[product_id8], $_POST[quantity8], $sale_id, $_POST[unit_price8], $_POST[unit_discount8], $_POST[net_price8]); } // end of product # 8 if ($_POST[product_id9] != "" && $_POST[quantity9] != "") { Add2Sale($_POST[product_id9], $_POST[quantity9], $sale_id, $_POST[unit_price9], $_POST[unit_discount9], $_POST[net_price9]); } // end of product # 9 if ($_POST[product_id10] != "" && $_POST[quantity10] != "") { Add2Sale($_POST[product_id10], $_POST[quantity10], $sale_id, $_POST[unit_price10], $_POST[unit_discount10], $_POST[net_price10]); } // end of product # 10 $sql = "SELECT SUM(quantity*(unit_price - unit_discount)), SUM((quantity * ((unit_price - unit_discount) - acq_price))) FROM sale_details WHERE sale_id = '$sale_id'"; $lt_res = mysql_query($sql); $lt_row = mysql_fetch_array($lt_res); $line_total = $lt_row[0]; $revenue = $lt_row[1]; $sql = "SELECT sale_detail_id FROM sale_details WHERE sale_id = '$sale_id'"; $res = mysql_query($sql); $num = mysql_num_rows($res); if ($num > 0) { $sql = "UPDATE sales SET or_num = '$sale_id', line_total = '$line_total', balance = 0, revenue = '$revenue' WHERE sale_id = '$sale_id' LIMIT 1"; // if suceessful to insert the sale if (mysql_query($sql)) { print "Sale has been added into the database</b>.<br>"; show_sale($sale_id); } else { print "Could not insert sale into the database because: <b> ".mysql_error()." </b>.<br>"; } } else { print "Error! No product has been added into the sale.<br>"; } } } else { // Print out any error messages. if ($message) { echo "<center><table><tr><td bgcolor=#FF0000><table bgcolor=#FFE4B5><tr><td><font color=red face=arial size=2><b>The following problems occurred:</b><br>\n"; foreach ($message as $key => $value) { echo "$value <br>\n"; } echo "</font></td></tr></table></td></tr></table></center>\n"; } show_form(); } } else { show_form(); } function show_form() { ?> <form name="AddSale" action="add_sale.php" method="POST"> <div class="post"> <h1 class="title">Add Sale</h1> <div class="entry"> <table align="center"> <tbody class="data"> <tr class="odd"><td align="right" width="100">Customer </td> <td align="left" width="275"><select name="customer_id"><option value="0">Customer</option> <?PHP $sql = "SELECT customer_id, company_name FROM customers ORDER BY company_name"; $sres = mysql_query($sql) or die(mysql_error()); while ($srow = mysql_fetch_array($sres)) { print "<option value=$srow[0]>$srow[1]</option>"; } ?></select> <font color="red">*</font></td> <td align="right" width="100"> </td> <td align="left" width="275"></td></tr> <tr class="odd"><td align="right">Received By </td> <td align="left"><input type="text" size="33" name="received_by"> <font color="red">*</font></td> <td align="right">Due Date </td> <td align="left"><input readonly type="text" size="10" name="due_date"><a class="td_img" href="javascript:due_date.popup();"><img src="lib/b_calendar.png"></a> <font color="red">*</font></td></tr> <script language="JavaScript"> <!-- // create calendar object(s) just after form tag closed var due_date = new calendar(document.forms['AddSale'].elements['due_date']); due_date.year_scroll = true; due_date.time_comp = false; //--> </script> <tr class="even"><td align="right">Notes </td> <td colspan="3" align="left"><input type="text" size="106" name="notes"></td></tr> </tbody> </table> </div> </div> <br> <div class="post"> <h1 class="title">Product Sale Details</h1> <div class="entry"> <table align="center"> <thead class="data"><tr> <td align="center" width="30"></td> <td align="center" width="260">Product</td> <td align="center" width="60"># Avail</td> <td align="center" width="70">Price</td> <td align="center" width="70">Disc.</td> <td align="center" width="60">Qty</td> <td align="center" width="80">Net</td> </tr></thead> <tbody class="data"> <?PHP for ($i=1; $i<11; $i++) { $m = fmod($i, 2); if ($m == 0) { ?><tr class="even"><?PHP } else { ?><tr class="odd"><?PHP } ?> <td align="center"><?PHP echo $i ?></td><td align="left"><select id="product_id<?PHP echo $i ?>" name="product_id<?PHP echo $i ?>" onchange="MyAjaxRequest('unit_price<?PHP echo $i ?>', 'get_price.php?product_id=', 'available<?PHP echo $i ?>', 'get_avail.php?product_id=', 'product_id<?PHP echo $i ?>')"> <option>Product Name</option> <?PHP $sql = "SELECT product_id, product_name FROM products ORDER BY product_name"; $pres = mysql_query($sql); while ($prow = mysql_fetch_array($pres)) { print "<option value=$prow[0]>$prow[1]</option>"; } ?></select></td> <td align="center"><input type="text" size="5" id="available<?PHP echo $i ?>" name="available<?PHP echo $i ?>" readonly="true" style="text-align:right;"></td> <td align="center"><input type="text" size="5" id="unit_price<?PHP echo $i ?>" name="unit_price<?PHP echo $i ?>" readonly="true" style="text-align:right;"></td> <td align="center"><input type="text" size="4" id="unit_discount<?PHP echo $i ?>" name="unit_discount<?PHP echo $i ?>" onblur="getSTPrice()"></td> <td align="center"><input type="text" size="2" id="quantity<?PHP echo $i ?>" name="quantity<?PHP echo $i ?>" onblur="getSTPrice()"></td> <td align="center"><input type="text" size="7" id="net_price<?PHP echo $i ?>" name="net_price<?PHP echo $i ?>" readonly="true" style="text-align:right;"></td> </tr> <?PHP } ?> <tr class="odd"><td align="center" colspan="7"> <input type="reset"> <input type="submit" name="submit" value="Submit"></td></tr> </tbody> </table> </div> </div> </form> <?PHP } function Add2Sale($product_id, $quantity, $sale_id, $unit_price, $unit_discount, $net_price) { // items are sold FIFO // while quantity requested is not zero while ($quantity > 0) { // get the oldest purchase in the inventory $sql = "SELECT DATEDIFF(p.delivery_date, NOW()) AS diff, pd.purchase_detail_id, pd.unit_price - pd.unit_discount, pd.balance FROM purchases p, purchase_details pd WHERE p.purchase_id=pd.purchase_id AND pd.balance > 0 AND pd.product_id = '$product_id' ORDER BY diff, p.purchase_id LIMIT 0, 1"; $res = mysql_query($sql); $num = mysql_num_rows($res); if ($num > 0) { $row = mysql_fetch_array($res); // information about the purchase of the product $purchase_detail_id = $row[1]; $acq_price = $row[2]; $bal = $row[3]; if ($quantity <= $bal) { // get the changes in purchae_detail after the insert of sale_detail $new_pdbal = $bal - $quantity; $net_price = $quantity * ($unit_price - $unit_discount); // update the purchase details table $upd8_pd = "UPDATE purchase_details SET balance = '$new_pdbal' WHERE purchase_detail_id = '$purchase_detail_id' LIMIT 1"; mysql_query($upd8_pd); if (mysql_affected_rows() == 1) { // insert into sale details table $insert_sale = "INSERT INTO sale_details ( sale_id, purchase_detail_id, product_id, acq_price, quantity, unit_price, unit_discount, net_price ) VALUES ( '$sale_id', '$purchase_detail_id', '$product_id', '$acq_price', '$quantity', '$unit_price', '$unit_discount', '$net_price' )"; if (mysql_query($insert_sale)) { // quantity requested will be zero $quantity = 0; } else { print "<center><font face=arial size=2 color=red>ERROR!!! Failed to add into sale details.</font></center>"; } } else { print "<center><font face=arial size=2 color=red>ERROR!!! Failed to update purchase details table.</font></center>"; } } else { // insert the sale detail and update the purchase_detail balance to zero $net_price = $bal * ($unit_price - $unit_discount); // update the purchase details table $upd8_pd = "UPDATE purchase_details SET balance = 0 WHERE purchase_detail_id = '$purchase_detail_id' LIMIT 1"; mysql_query($upd8_pd); if (mysql_affected_rows() == 1) { // insert into sale details table $insert_sale = "INSERT INTO sale_details ( sale_id, purchase_detail_id, product_id, acq_price, quantity, unit_price, unit_discount, net_price ) VALUES ( '$sale_id', '$purchase_detail_id', '$product_id', '$acq_price', '$bal', '$unit_price', '$unit_discount', '$net_price' )"; if (mysql_query($insert_sale)) { // update the remaining balance of quantity $quantity = $quantity - $bal; } else { print "<center><font face=arial size=2 color=red>ERROR!!! Failed to add into sale details.</font></center>"; } } else { print "<center><font face=arial size=2 color=red>ERROR!!! Failed to update purchase details table.</font></center>"; } } } else { $quantity = 0; } mysql_free_result($res); } $sql = "UPDATE products SET lastsale = NOW() WHERE product_id = '$product_id' LIMIT 1"; mysql_query($sql) or die(mysql_error()); } // end ?> Due to limitation of allowed number of characters in posts, i have removed parts that I strongly believe have nothing to do with the error. Please feel free to criticize my work. Thank you so much.
  10. Hello guys! I made a point of sale / inventory system. My problem is that there are instances when users enter sales and press the submit button at the same time (or almost at the same time), the items contained within those sales get interchanged. For example items a, b and c are supposed to be contained in sale #1 and items d, e and f in sale #2. but since the submit buttons were pressed at the same time, sale #1 contains items a, b and e and sale #2 contains c, d and f. What could be the possible reasons? I suspect that the LAN wires has something to do with it. Somebody told me that i should consider having a queueing function. How should i do that? Any insight is highly appreciated. Thanks so much.
  11. Hello Guys! My system needs to print billing accounts of all subscribers in bulk. Accounts must be printed in a 8.5" x 5.5" paper. Accounts may consume a page or more. My problem is that if the previous account consumed a page and a half, the next account will start from the lower half of the last page of the previous account. My question is how to insert a page break so that every account starts at the top of a page. What i have in mind so far is to generate an excel file with all the accounts and with page breaks after every account. If there's a way on how to print accounts with page breaks directly on the browser, that would be great. Other insights are highly appreciated. Thank you guys in advanced!
  12. Hello guys. Im just wondering if it is possible to integrate a barcode generator in PHP. Any idea is highly appreciated. Thanks a lot. (",)
  13. Hi guys! How can i update the php files in my client's server if the server is using a dynamic ip address? Thanks for your response.
  14. how can i make a picture pop up during mouseover on a link? just like how they do on facebook. for example: <a class="myclass" href="member.php?client_id=<?PHP echo $member_id ?>"><?PHP ?><?PHP echo $name ?></a> thanks guys!
  15. My client's employees get used with a system developed from VB where in they use the enter key to go to the next text box or select box or radio button etc. He wants me to develop a new system that is web-based. But instead of using the Tab key to move from text boxes, he wants the use the Enter key. Is it possible in web applications? Thanks for your insights.
  16. Thanks a lot Harristweed. But what if the admin wants to download the .xls file? Still, thanks for your code.
  17. Hello guys. By the end of the day, my client wants the daily report sent to his email account in .xls format. how can i attain this? I know the php mail() function but i dont know how will php create an excel file and email it to my client automatically. Where should i start? Thanks guys!
  18. Hello again guys! What if i have 2 databases, db1 and db2. i want to read raw data from db1 and match it's content with data from db2, then produce some information. How can i do it at the same time? I know that to be able to access mysql data, we have to use the mysql_connect() and mysql_select_db(). mysql_select_db() only allows to connect to single database. what should i do? thanks for your help in advance.
×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.