-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathQuote-Price-From-Items
96 lines (96 loc) · 3.29 KB
/
Quote-Price-From-Items
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
getAllProduct = zoho.crm.getRecordById("Quotes",input.Quote_Id);
//info getAllProduct;
list_product=(getAllProduct).get("product");
tot_Discount=(getAllProduct).get(("Discount"));
tot_Tax=(getAllProduct).get("Tax");
update_product_list=List();
Sub_Total=0.0;
for each recProductList in list_product.toJSONList()
{
// get Product id from Quote
pro_detail=map();
mapProductFL=recProductList.toMap();
mapProductFLList=mapProductFL.get("Product Id");
quoteQuantity=mapProductFL.get("Quantity");
quoteDiscount=mapProductFL.get(("Discount"));
quoteTax=mapProductFL.get("Tax");
//info mapProductFLList;
// get pricebook details related to product
AUTHTOKEN = "";
getPricebookdetails = getUrl((("https://crm.zoho.com/crm/private/json/PriceBooks/getRelatedRecords?authtoken=" + AUTHTOKEN + "&scope=crmapi&id=") + mapProductFLList) + "&parentModule=Products");
getPricebook_res=(getPricebookdetails).toMap();
getres=((getPricebook_res).get("response")).toMap();
getresult=((getres).get("result")).toMap();
getPriceBook=((getresult).get("PriceBooks")).toMap();
//info "getPriceBook " + getPriceBook;
getRow1=(getPriceBook).get("row");
info ("getRow ") + getRow1;
if(getRow1 != null)
{
getRow=(getPriceBook).get("row").toJSONList();
for each getRowPrice in getRow
{
getRowPrice_map=(getRowPrice).toMap();
getFL=(getRowPrice_map).get("FL");
getFL_Map=getFL.toJSONList();
st_range="";
ed_range="";
list_price="";
for each checkPriceBook in getFL_Map
{
childPriceBook=checkPriceBook.toMap();
//info "childPriceBook " + childPriceBook;
if(childPriceBook.get("val") == "Start Range")
{
st_range=childPriceBook.get("content");
}
if(childPriceBook.get("val") == "End Range")
{
ed_range=childPriceBook.get("content");
}
if(childPriceBook.get("val") == "List Price")
{
list_price=childPriceBook.get("content");
}
}
//info "st_range "+st_range;
//info "ed_range "+ed_range;
//info "quantity" + quoteQuantity;
//info "list_price "+list_price;
// Check quantity between start and end range
if((quoteQuantity.toLong() >= st_range.toLong()) && (quoteQuantity.toLong() <= ed_range.toLong()))
{
//info "st_range " + st_range;
//info "ed_range " + ed_range;
//info "quantity" + quoteQuantity;
//info "id" + mapProductFLList;
update_map=map();
update_map.put("Product Id",mapProductFLList);
update_map.put("List Price",list_price);
total=(ifnull(list_price.toDecimal(),0.0) * ifnull(quoteQuantity.toDecimal(),0.0));
afterDiscount=(total - ifnull((quoteDiscount).toDecimal(),0.0));
afterTax=(afterDiscount + ifnull(quoteTax.toDecimal(),0.0));
update_map.put("Total",total);
update_map.put("Net Total",afterTax);
update_map.put(("Total After Discount"),afterDiscount);
update_product_list.add(update_map);
Sub_Total=(ifnull(Sub_Total,0.0) + ifnull(afterTax,0.0));
//info "dsgdsgdfgds";
}
}
}
//listFL=getFL.toJSONList();
//info "listFL "+listFL;
}
grand_total=(ifnull(Sub_Total,0.0) + ifnull(tot_Tax.toDecimal(),0.0) - ifnull((tot_Discount).toDecimal(),0.0));
mainMap=map();
mainMap.put("Sub Total",Sub_Total);
mainMap.put("Grand Total",grand_total);
mainMap.put("Products",update_product_list);
//info "update_product_list" + update_product_list;
//tot_map=map();
//tot_map.put("xmlData",mainMap);
//update Quote
//updateQuote = zoho.crm.updateRecord("Quotes", input.Quote_Id.toString(), tot_map);
updateQuote = zoho.crm.updateRecord("Quotes",input.Quote_Id.toString(),mainMap);
info updateQuote;