You are on page 1of 5

C:\Users\Omkar\Desktop\orderConf.

js

Monday, February 25, 2013 11:55 PM

function orderConf() { var doc = SpreadsheetApp.getActiveSpreadsheet(); var sheet = doc.getSheetByName("Order_Sheet"); var sheet2 = doc.getSheetByName("Order_Consolidated"); var sheet3 = doc.getSheetByName("Total"); var sheet4 = doc.getSheetByName("Backup"); //var total_amount = sheet3.getRange(1,2).getValue(); var row = sheet.getLastRow(); var inputCode = sheet.getRange(row,6).getValue(); var message = "Following is your order\n\n"; var message2 = ""; var orderNum = sheet3.getRange(8,3).getValue() ; orderNum = (orderNum + 1); var email = sheet.getRange(row,3).getValue(); var emailPattern = /^([a-zA-Z0-9])+([\.a-zA-Z0-9_-])*@([a-zA-Z0-9_-])+(\.[a-zA-Z0-9_-]+)+$/; //email reg expression var validEmailAddress = emailPattern.test(email); var len = email.length; var code=0; for (var i=0;i<len;i++){ code = code + email.charCodeAt(i); } if(inputCode == (code*169-169) ){ var total = 0; var header; var q; //No of items in menu var numOfItems = 64; var rate; //var message3 = "Order limit crossed.\nPlease call on 9637014476/ 9561989868/ 9158751172 to place your order.\n\nThank You"; for (var j=13; j<13+numOfItems;j++){

-1-

C:\Users\Omkar\Desktop\orderConf.js

Monday, February 25, 2013 11:55 PM

if(sheet.getRange(row,j).getValue() != "0"){ header = sheet.getRange(1,j).getValue(); q = sheet.getRange(row,j).getValue() message = message + "\n"+q+" "+header; message2 = message2 + "\n"+q+" "+header; switch(header) { case "Veggie Delight" : rate = 0 break; case "Aloo Patty" : rate = 0 break; case "Paneer Tikka" : rate = 0 break; case "Chicken Tikka" : rate = 0 break; case "Chicken Tandoori" : rate = 0 break; case "Roasted Chicken" : rate = 0 break; case "Double Cheese Margherita - Cheese Burst" : rate = 375 break; case "Double Cheese Margherita - Medium" : rate = 300 break; case "Double Cheese Margherita - Large" : rate = 430 break; case "Fresh Veggie - Medium" : rate = 300 break; case "Fresh Veggie - Cheese Burst" : rate = 375 break; case "Fresh Veggie - Large" : rate = 430 break; case "Country Special - Medium" : rate = 300; break; case "Country Special - Cheese Burst" : rate = 375 break; case "Country Special - Large" : rate = 430 break; case "Farmhouse - Medium" : rate = 300 break; case "Farmhouse - Cheese Burst" : rate = 375 break; case "Farmhouse - Large" : rate = 430 break; case "5 Pepper - Medium" : rate = 380 break; case "5 Pepper - Cheese Burst" : rate = 455 break; case "5 Pepper - Large" : rate = 510 break; case "Peppy Paneer - Medium" : rate = 380 break; case "Peppy Paneer - Cheese Burst" : rate = 455 break; case "Peppy Paneer - Large" : rate = 510
-2-

C:\Users\Omkar\Desktop\orderConf.js

Monday, February 25, 2013 11:55 PM

break; case "Mexican Green Wave - Medium" : rate = 380 break; case "Mexican Green Wave - Cheese Burst" : rate = 455 break; case "Mexican Green Wave - Large" : rate = 510 break; case "Deluxe Veggie - Medium" : rate = 380 break; case "Deluxe Veggie - Cheese Burst" : rate = 455 break; case "Deluxe Veggie - Large" : rate = 510 break; case "Gourmet - Medium" : rate = 380 break; case "Gourmet - Cheese Burst" : rate = 455 break; case "Gourmet - Large" : rate = 510 break; case "Veg Extravaganza - Medium" : rate = 425 break; case "Veg Extravaganza - Cheese Burst" : rate = 500 break; case "Veg Extravaganza - Large" : rate = 560 break; case "Chicken Fiesta - Medium" : rate = 370 break; case "Chicken Fiesta - Cheese Burst" : rate = 445 break; case "Chicken Fiesta - Large" :rate = 500 break; case "Barbeque Chicken - Medium" : rate = 370 break; case "Barbeque Chicken - Cheese Burst": rate = 445 break; case "Barbeque Chicken - Large" :rate = 500 break; case "Spicy Chicken - Medium" : rate = 370 break; case "Spicy Chicken - Cheese Burst": rate = 445; break; case "Spicy Chicken - Large" :rate = 500; break; case "Zesty Chicken - Medium" :rate = 405 break; case "Zesty Chicken - Cheese Burst" :rate = 480 break; case "Zesty Chicken - Large" : rate = 560 break; case "Chicken Mexicana - Medium":rate = 405 break; case "Chicken Mexicana - Cheese Burst":rate = 480 break; case "Chicken Mexicana - Large":rate = 505
-3-

C:\Users\Omkar\Desktop\orderConf.js

Monday, February 25, 2013 11:55 PM

break; case "Keema do Pyaaza - Medium": rate = 405 break; case "Keema do Pyaaza - Cheese Burst": rate = 480 break; case "Keema do Pyaaza - Large":rate = 505 break; case "Chicken Golden Delight - Medium": rate = 405 break; case "Chicken Golden Delight - Cheese Burst": rate = 480 break; case "Chicken Golden Delight - Large": rate = 505 break; case "Meatzaa - Medium" :rate = 450 break; case "Meatzaa - Cheese Burst":rate = 525 break; case "Meatzaa - Large":rate = 610 break; case "Cheese & Pepperoni - Medium" :rate = 450 break; case "Cheese & Pepperoni - Cheese Burst":rate = 525 break; case "Cheese & Pepperoni - Large" : rate = 610 break; case "Non Veg Supreme - Medium": rate = 450 break; case "Non Veg Supreme - Cheese Burst":rate = 525 break; case "Non Veg Supreme - Large" :rate = 610 break; case "Garlic Breadsticks" : rate = 90; break; case "Nutty Choco Lava Cake" : rate = 84; break; case "Butterschotch Mousse Cake":rate = 70; break; case "Cheesy Dip" : rate = 20; break;

default: rate=0; } total = total + rate*q; } } message = message + "\n----------------------------------\nTotal "\n\n"; message2 = message2 + "\n---------------------------------\nTotal = = "+total+

"+total;

message = message + "\n\n In case of any discrepency mail us or call us @ 9637014476/ 9561989868/ 9158751172\n\n Thank You!";

-4-

C:\Users\Omkar\Desktop\orderConf.js

Monday, February 25, 2013 11:55 PM

// = total_amount + total; //sheet3.getRange(1,2).setValue(total_amount); subject = "Order confirmation"; sheet.getRange(row,2).setBackground('green'); // sheet.getRange(row,2).setValue("Ok"); sheet.getRange(row,2).setFontColor('white'); if(validEmailAddress){ MailApp.sendEmail(email,"Your Order", message); MailApp.sendEmail("omkarsayajihande@gmail.com","One more!", message); sheet.getRange(row,2).setValue("Ok"); sheet2.getRange(row,1).setValue(sheet.getRange(row,4).getValue()); sheet4.getRange(row,1).setValue(sheet.getRange(row,4).getValue()); sheet2.getRange(row,2).setValue(sheet.getRange(row,5).getValue()); sheet4.getRange(row,2).setValue(sheet.getRange(row,5).getValue()); sheet2.getRange(row,3).setValue(message2); sheet4.getRange(row,3).setValue(message2); sheet3.getRange(8,3).setValue(orderNum); sheet.getRange(row,77).setValue(total); } else{ sheet.getRange(row,2).setValue("Error"); } } else{ sheet.getRange(row,2).setBackground('red'); sheet.getRange(row,2).setValue("Invalid Code"); sheet.getRange(row,2).setFontColor('white'); if(validEmailAddress){ MailApp.sendEmail(email,"Invalid code", "You have entered an invalid code \n\n In case of any discrepency mail us or call us @ 9637014476/ 9561989868/ 9158751172\n\n Thank You!"); } else{ sheet.getRange(row,2).setValue("Error"); } } }

-5-