blob: ca0a6cb8d2de1a81eda78b887be3cf6e80f126fc [file] [log] [blame]
Anand Doshi885e0742015-03-03 14:55:30 +05301// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
Rushabh Mehtae67d1fb2013-08-05 14:59:54 +05302// License: GNU General Public License v3. See license.txt
Anand Doshi3543f302013-05-24 19:25:01 +05303
Rushabh Mehta793ba6b2014-02-14 15:47:51 +05304frappe.provide("erpnext");
Nabin Haitb4a3dfa2015-01-22 17:13:13 +05305frappe.require("assets/erpnext/js/controllers/taxes_and_totals.js");
Neil Trini Lasrado78fa6952014-10-03 17:43:02 +05306frappe.require("assets/erpnext/js/utils.js");
7
Nabin Haitb4a3dfa2015-01-22 17:13:13 +05308erpnext.TransactionController = erpnext.taxes_and_totals.extend({
Anand Doshi3543f302013-05-24 19:25:01 +05309 onload: function() {
Anand Doshi1e4fb682013-08-23 12:56:33 +053010 var me = this;
Anand Doshi3543f302013-05-24 19:25:01 +053011 if(this.frm.doc.__islocal) {
Anand Doshi1e4fb682013-08-23 12:56:33 +053012 var today = get_today(),
Nabin Hait73083dc2014-03-14 15:10:42 +053013 currency = frappe.defaults.get_user_default("currency");
Rushabh Mehtaff938022014-04-15 18:40:00 +053014
Anand Doshi3543f302013-05-24 19:25:01 +053015 $.each({
Anand Doshifc777182013-05-27 19:29:07 +053016 posting_date: today,
17 due_date: today,
18 transaction_date: today,
19 currency: currency,
20 price_list_currency: currency,
21 status: "Draft",
Anand Doshifc777182013-05-27 19:29:07 +053022 is_subcontracted: "No",
Anand Doshi3543f302013-05-24 19:25:01 +053023 }, function(fieldname, value) {
24 if(me.frm.fields_dict[fieldname] && !me.frm.doc[fieldname])
25 me.frm.set_value(fieldname, value);
Rushabh Mehtaff938022014-04-15 18:40:00 +053026 });
nabinhaitbc408d82014-07-07 16:51:52 +053027
nabinhaitb7392642014-07-28 14:55:08 +053028 if(this.frm.doc.company && !this.frm.doc.amended_from) {
nabinhaitbc408d82014-07-07 16:51:52 +053029 cur_frm.script_manager.trigger("company");
30 }
Anand Doshi3543f302013-05-24 19:25:01 +053031 }
Akhilesh Darjee564c6212013-10-17 11:31:11 +053032
Nabin Haitdd38a262014-12-26 13:15:21 +053033 if(this.frm.fields_dict["taxes"]) {
34 this["taxes_remove"] = this.calculate_taxes_and_totals;
Anand Doshia91c95f2013-08-23 13:00:47 +053035 }
Rushabh Mehtaff938022014-04-15 18:40:00 +053036
Nabin Haitdd38a262014-12-26 13:15:21 +053037 if(this.frm.fields_dict["items"]) {
38 this["items_remove"] = this.calculate_taxes_and_totals;
Anand Doshi1e4fb682013-08-23 12:56:33 +053039 }
Anand Doshi3543f302013-05-24 19:25:01 +053040 },
Rushabh Mehtaff938022014-04-15 18:40:00 +053041
Anand Doshi5e4e5d72013-08-06 17:23:44 +053042 onload_post_render: function() {
Akhilesh Darjee61b5c592013-10-15 20:24:34 +053043 var me = this;
Nabin Haitffc7f3f2015-05-12 15:07:02 +053044 if(this.frm.doc.__islocal && !(this.frm.doc.taxes || []).length
45 && !(this.frm.doc.__onload ? this.frm.doc.__onload.load_after_mapping : false)) {
46 this.apply_default_taxes();
47 }
Rushabh Mehta4a3c8052015-05-19 11:10:12 +053048
Nabin Haitdd38a262014-12-26 13:15:21 +053049 if(this.frm.doc.__islocal && this.frm.doc.company && this.frm.doc["items"] && !this.frm.doc.is_pos) {
Anand Doshib054eb72014-04-22 20:35:22 +053050 this.calculate_taxes_and_totals();
Anand Doshi5e4e5d72013-08-06 17:23:44 +053051 }
Nabin Haitdd38a262014-12-26 13:15:21 +053052 if(frappe.meta.get_docfield(this.frm.doc.doctype + " Item", "item_code")) {
53 cur_frm.get_field("items").grid.set_multiple_add("item_code", "qty");
Rushabh Mehtab6843f22014-06-04 13:10:41 +053054 }
Anand Doshi5e4e5d72013-08-06 17:23:44 +053055 },
Rushabh Mehtaff938022014-04-15 18:40:00 +053056
Anand Doshi3543f302013-05-24 19:25:01 +053057 refresh: function() {
Anand Doshi8bde7f92014-04-24 18:11:49 +053058 erpnext.toggle_naming_series();
Anand Doshibdee6e02013-07-09 13:03:39 +053059 erpnext.hide_company();
Nabin Hait239c2c32015-01-15 14:21:41 +053060 this.hide_currency_and_price_list()
Anand Doshi3543f302013-05-24 19:25:01 +053061 this.show_item_wise_taxes();
Nabin Hait1f996c32013-07-29 19:00:53 +053062 this.set_dynamic_labels();
Anand Doshi50d7e8c2015-01-06 17:14:13 +053063 erpnext.pos.make_pos_btn(this.frm);
Rushabh Mehta614e7ab2015-02-18 19:51:48 +053064 this.setup_sms();
65 },
Rushabh Mehta4a3c8052015-05-19 11:10:12 +053066
Nabin Haitffc7f3f2015-05-12 15:07:02 +053067 apply_default_taxes: function() {
68 var me = this;
Rushabh Mehta4984bcc2015-05-21 12:51:07 +053069 var taxes_and_charges_field = frappe.meta.get_docfield(me.frm.doc.doctype, "taxes_and_charges",
70 me.frm.doc.name);
71
72 if(taxes_and_charges_field) {
73 frappe.call({
74 method: "erpnext.controllers.accounts_controller.get_default_taxes_and_charges",
75 args: {
76 "master_doctype": taxes_and_charges_field.options
77 },
78 callback: function(r) {
79 if(!r.exc) {
80 me.frm.set_value("taxes", r.message);
81 }
Nabin Haitffc7f3f2015-05-12 15:07:02 +053082 }
Rushabh Mehta4984bcc2015-05-21 12:51:07 +053083 });
84 }
Nabin Haitffc7f3f2015-05-12 15:07:02 +053085 },
Rushabh Mehta614e7ab2015-02-18 19:51:48 +053086
87 setup_sms: function() {
88 var me = this;
Rushabh Mehta4a3c8052015-05-19 11:10:12 +053089 if(this.frm.doc.docstatus===1 && !in_list(["Lost", "Stopped"], this.frm.doc.status)
90 && this.frm.doctype != "Purchase Invoice") {
Rushabh Mehta614e7ab2015-02-18 19:51:48 +053091 this.frm.page.add_menu_item(__('Send SMS'), function() { me.send_sms(); });
92 }
93 },
94
95 send_sms: function() {
96 frappe.require("assets/erpnext/js/sms_manager.js");
Rushabh Mehta4a3c8052015-05-19 11:10:12 +053097 var sms_man = new SMSManager(this.frm.doc);
Nabin Hait239c2c32015-01-15 14:21:41 +053098 },
Anand Doshi50d7e8c2015-01-06 17:14:13 +053099
Nabin Hait239c2c32015-01-15 14:21:41 +0530100 hide_currency_and_price_list: function() {
Nabin Hait093beec2015-05-26 10:47:52 +0530101 if(this.frm.doc.conversion_rate == 1 && this.frm.doc.docstatus > 0) {
Nabin Hait239c2c32015-01-15 14:21:41 +0530102 hide_field("currency_and_price_list");
103 } else {
104 unhide_field("currency_and_price_list");
105 }
Akhilesh Darjee6773bc22013-09-17 11:56:17 +0530106 },
107
Neil Trini Lasradod0151952015-06-09 15:21:50 +0530108 barcode: function(doc, cdt, cdn) {
109 var d = locals[cdt][cdn];
110 if(d.barcode=="" || d.barcode==null) {
111 // barcode cleared, remove item
112 d.item_code = "";
113 }
114 this.item_code(doc, cdt, cdn);
115 },
116
Nabin Hait139dc7b2014-02-12 14:53:18 +0530117 item_code: function(doc, cdt, cdn) {
118 var me = this;
Rushabh Mehta66d52b52014-03-27 14:17:33 +0530119 var item = frappe.get_doc(cdt, cdn);
Nabin Hait139dc7b2014-02-12 14:53:18 +0530120 if(item.item_code || item.barcode || item.serial_no) {
121 if(!this.validate_company_and_party()) {
Nabin Haitdd38a262014-12-26 13:15:21 +0530122 cur_frm.fields_dict["items"].grid.grid_rows[item.idx - 1].remove();
Nabin Hait139dc7b2014-02-12 14:53:18 +0530123 } else {
124 return this.frm.call({
125 method: "erpnext.stock.get_item_details.get_item_details",
126 child: item,
127 args: {
128 args: {
129 item_code: item.item_code,
130 barcode: item.barcode,
131 serial_no: item.serial_no,
132 warehouse: item.warehouse,
Nabin Hait444f9562014-06-20 15:59:49 +0530133 parenttype: me.frm.doc.doctype,
134 parent: me.frm.doc.name,
Nabin Hait139dc7b2014-02-12 14:53:18 +0530135 customer: me.frm.doc.customer,
136 supplier: me.frm.doc.supplier,
137 currency: me.frm.doc.currency,
138 conversion_rate: me.frm.doc.conversion_rate,
139 price_list: me.frm.doc.selling_price_list ||
140 me.frm.doc.buying_price_list,
141 price_list_currency: me.frm.doc.price_list_currency,
142 plc_conversion_rate: me.frm.doc.plc_conversion_rate,
143 company: me.frm.doc.company,
144 order_type: me.frm.doc.order_type,
145 is_pos: cint(me.frm.doc.is_pos),
146 is_subcontracted: me.frm.doc.is_subcontracted,
Nabin Haita1bf43b2015-03-17 10:50:47 +0530147 transaction_date: me.frm.doc.transaction_date || me.frm.doc.posting_date,
Nabin Hait444f9562014-06-20 15:59:49 +0530148 ignore_pricing_rule: me.frm.doc.ignore_pricing_rule,
149 doctype: item.doctype,
Anand Doshi43f087c2014-08-26 14:25:53 +0530150 name: item.name,
Anand Doshi9b955fe2015-01-05 16:19:12 +0530151 project_name: item.project_name || me.frm.doc.project_name,
152 qty: item.qty
Nabin Hait139dc7b2014-02-12 14:53:18 +0530153 }
154 },
Anand Doshi13945092014-09-21 19:45:49 +0530155
Nabin Hait139dc7b2014-02-12 14:53:18 +0530156 callback: function(r) {
157 if(!r.exc) {
158 me.frm.script_manager.trigger("price_list_rate", cdt, cdn);
159 }
160 }
161 });
162 }
163 }
Rushabh Mehtaff938022014-04-15 18:40:00 +0530164 },
Akhilesh Darjeefcd70d02013-10-18 14:24:21 +0530165
166 serial_no: function(doc, cdt, cdn) {
167 var me = this;
Rushabh Mehta66d52b52014-03-27 14:17:33 +0530168 var item = frappe.get_doc(cdt, cdn);
Akhilesh Darjeefcd70d02013-10-18 14:24:21 +0530169
170 if (item.serial_no) {
171 if (!item.item_code) {
172 this.frm.script_manager.trigger("item_code", cdt, cdn);
173 }
174 else {
175 var sr_no = [];
176
177 // Replacing all occurences of comma with carriage return
178 var serial_nos = item.serial_no.trim().replace(/,/g, '\n');
179
180 serial_nos = serial_nos.trim().split('\n');
Rushabh Mehtaff938022014-04-15 18:40:00 +0530181
Akhilesh Darjeefcd70d02013-10-18 14:24:21 +0530182 // Trim each string and push unique string to new list
183 for (var x=0; x<=serial_nos.length - 1; x++) {
184 if (serial_nos[x].trim() != "" && sr_no.indexOf(serial_nos[x].trim()) == -1) {
185 sr_no.push(serial_nos[x].trim());
186 }
187 }
188
189 // Add the new list to the serial no. field in grid with each in new line
190 item.serial_no = "";
191 for (var x=0; x<=sr_no.length - 1; x++)
192 item.serial_no += sr_no[x] + '\n';
193
194 refresh_field("serial_no", item.name, item.parentfield);
Rushabh Mehta793ba6b2014-02-14 15:47:51 +0530195 frappe.model.set_value(item.doctype, item.name, "qty", sr_no.length);
Akhilesh Darjeefcd70d02013-10-18 14:24:21 +0530196 }
197 }
198 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530199
Anand Doshi923d41d2013-05-28 17:23:36 +0530200 validate: function() {
Anand Doshi652bc072014-04-16 15:21:46 +0530201 this.calculate_taxes_and_totals(false);
Anand Doshi923d41d2013-05-28 17:23:36 +0530202 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530203
Anand Doshi3543f302013-05-24 19:25:01 +0530204 company: function() {
Neil Trini Lasradoeaae58f2014-10-09 15:00:10 +0530205 var me = this;
206 var fn = function() {
207 if(me.frm.doc.company && me.frm.fields_dict.currency) {
208 var company_currency = me.get_company_currency();
Rushabh Mehta5495bc52015-05-19 12:00:34 +0530209 var company_doc = frappe.get_doc(":Company", me.frm.doc.company);
Neil Trini Lasradoeaae58f2014-10-09 15:00:10 +0530210 if (!me.frm.doc.currency) {
211 me.frm.set_value("currency", company_currency);
212 }
Rushabh Mehtaff938022014-04-15 18:40:00 +0530213
Neil Trini Lasradoeaae58f2014-10-09 15:00:10 +0530214 if (me.frm.doc.currency == company_currency) {
215 me.frm.set_value("conversion_rate", 1.0);
216 }
217 if (me.frm.doc.price_list_currency == company_currency) {
218 me.frm.set_value('plc_conversion_rate', 1.0);
219 }
Rushabh Mehta5495bc52015-05-19 12:00:34 +0530220 if (company_doc.default_letter_head) {
Rushabh Mehtac1857342015-05-27 12:29:57 +0530221 if(me.frm.fields_dict.letter_head) {
222 me.frm.set_value("letter_head", company_doc.default_letter_head);
223 }
Rushabh Mehta5495bc52015-05-19 12:00:34 +0530224 }
Rushabh Mehtac1857342015-05-27 12:29:57 +0530225 if (company_doc.default_terms && me.frm.doc.doctype != "Purchase Invoice") {
Rushabh Mehta5495bc52015-05-19 12:00:34 +0530226 me.frm.set_value("tc_name", company_doc.default_terms);
227 }
Akhilesh Darjee1797cfe2013-10-11 13:34:10 +0530228
Neil Trini Lasradoeaae58f2014-10-09 15:00:10 +0530229 me.frm.script_manager.trigger("currency");
230 me.apply_pricing_rule();
Nabin Haitdd38a262014-12-26 13:15:21 +0530231 }
Anand Doshi3543f302013-05-24 19:25:01 +0530232 }
Nabin Haitdd38a262014-12-26 13:15:21 +0530233
Neil Trini Lasradoeaae58f2014-10-09 15:00:10 +0530234 if (this.frm.doc.posting_date) var date = this.frm.doc.posting_date;
235 else var date = this.frm.doc.transaction_date;
236 erpnext.get_fiscal_year(this.frm.doc.company, date, fn);
Rushabh Mehta45ca8a42015-04-28 16:02:09 +0530237
238 if(this.frm.doc.company) {
239 erpnext.last_selected_company = this.frm.doc.company;
240 }
Neil Trini Lasradoeaae58f2014-10-09 15:00:10 +0530241 },
242
243 transaction_date: function() {
244 erpnext.get_fiscal_year(this.frm.doc.company, this.frm.doc.transaction_date);
Neil Trini Lasrado78fa6952014-10-03 17:43:02 +0530245 },
246
247 posting_date: function() {
Neil Trini Lasrado565d9862014-10-07 18:26:39 +0530248 erpnext.get_fiscal_year(this.frm.doc.company, this.frm.doc.posting_date);
Anand Doshi3543f302013-05-24 19:25:01 +0530249 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530250
Anand Doshi3543f302013-05-24 19:25:01 +0530251 get_company_currency: function() {
252 return erpnext.get_currency(this.frm.doc.company);
253 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530254
Anand Doshi3543f302013-05-24 19:25:01 +0530255 currency: function() {
Anand Doshi61a2f682013-06-21 17:55:31 +0530256 var me = this;
257 this.set_dynamic_labels();
Akhilesh Darjee78378272013-10-11 19:06:30 +0530258
Anand Doshi61a2f682013-06-21 17:55:31 +0530259 var company_currency = this.get_company_currency();
Nabin Hait69cdf592015-05-02 18:46:10 +0530260 // Added `ignore_pricing_rule` to determine if document is loading after mapping from another doc
Pratik Vyas1a84d8e2015-05-19 12:23:52 +0530261 if(this.frm.doc.currency !== company_currency && !this.frm.doc.ignore_pricing_rule) {
Rushabh Mehtaff938022014-04-15 18:40:00 +0530262 this.get_exchange_rate(this.frm.doc.currency, company_currency,
Anand Doshi61a2f682013-06-21 17:55:31 +0530263 function(exchange_rate) {
Akhilesh Darjee78378272013-10-11 19:06:30 +0530264 me.frm.set_value("conversion_rate", exchange_rate);
Anand Doshi61a2f682013-06-21 17:55:31 +0530265 });
266 } else {
Rushabh Mehtaff938022014-04-15 18:40:00 +0530267 this.conversion_rate();
Anand Doshi61a2f682013-06-21 17:55:31 +0530268 }
269 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530270
Anand Doshi61a2f682013-06-21 17:55:31 +0530271 conversion_rate: function() {
Anand Doshi535d8332013-07-19 13:51:07 +0530272 if(this.frm.doc.currency === this.get_company_currency()) {
273 this.frm.set_value("conversion_rate", 1.0);
Akhilesh Darjeeacf65a72013-10-17 13:04:26 +0530274 }
275 if(this.frm.doc.currency === this.frm.doc.price_list_currency &&
Anand Doshi61a2f682013-06-21 17:55:31 +0530276 this.frm.doc.plc_conversion_rate !== this.frm.doc.conversion_rate) {
277 this.frm.set_value("plc_conversion_rate", this.frm.doc.conversion_rate);
278 }
Rushabh Mehta4a3c8052015-05-19 11:10:12 +0530279
Nabin Haita3dd72a2014-05-28 12:49:20 +0530280 if(flt(this.frm.doc.conversion_rate)>0.0) {
Nabin Hait444f9562014-06-20 15:59:49 +0530281 if(this.frm.doc.ignore_pricing_rule) {
282 this.calculate_taxes_and_totals();
Anand Doshi51f722d2014-07-04 15:44:26 +0530283 } else if (!this.in_apply_price_list){
284 this.apply_price_list();
Nabin Hait444f9562014-06-20 15:59:49 +0530285 }
286
Nabin Haita3dd72a2014-05-28 12:49:20 +0530287 }
Anand Doshi3543f302013-05-24 19:25:01 +0530288 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530289
Anand Doshi61a2f682013-06-21 17:55:31 +0530290 get_exchange_rate: function(from_currency, to_currency, callback) {
Rushabh Mehta66fa1ff2015-05-07 12:25:33 +0530291 frappe.call({
292 method: "erpnext.setup.utils.get_exchange_rate",
293 args: {
294 from_currency: from_currency,
295 to_currency: to_currency
296 },
297 callback: function(r) {
298 callback(flt(r.message));
299 }
Anand Doshi61a2f682013-06-21 17:55:31 +0530300 });
301 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530302
Anand Doshi3543f302013-05-24 19:25:01 +0530303 price_list_currency: function() {
Akhilesh Darjeedb59ffb2013-09-11 13:05:24 +0530304 var me=this;
Anand Doshi3543f302013-05-24 19:25:01 +0530305 this.set_dynamic_labels();
Nabin Haitec361ea2015-05-11 18:14:45 +0530306
307 var company_currency = this.get_company_currency();
308 // Added `ignore_pricing_rule` to determine if document is loading after mapping from another doc
309 if(this.frm.doc.price_list_currency !== company_currency && !this.frm.doc.ignore_pricing_rule) {
310 this.get_exchange_rate(this.frm.doc.price_list_currency, company_currency,
311 function(exchange_rate) {
312 me.frm.set_value("plc_conversion_rate", exchange_rate);
313 });
314 } else {
315 this.plc_conversion_rate();
316 }
Anand Doshi3543f302013-05-24 19:25:01 +0530317 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530318
Anand Doshi3543f302013-05-24 19:25:01 +0530319 plc_conversion_rate: function() {
Anand Doshi61a2f682013-06-21 17:55:31 +0530320 if(this.frm.doc.price_list_currency === this.get_company_currency()) {
321 this.frm.set_value("plc_conversion_rate", 1.0);
Nabin Haitec361ea2015-05-11 18:14:45 +0530322 } else if(this.frm.doc.price_list_currency === this.frm.doc.currency && this.frm.doc.plc_conversion_rate && cint(this.frm.doc.plc_conversion_rate) != 1 &&
323 cint(this.frm.doc.plc_conversion_rate) != cint(this.frm.doc.conversion_rate)) {
324 this.frm.set_value("conversion_rate", this.frm.doc.plc_conversion_rate);
Akhilesh Darjee564c6212013-10-17 11:31:11 +0530325 }
Rushabh Mehta4a3c8052015-05-19 11:10:12 +0530326
Nabin Haitec361ea2015-05-11 18:14:45 +0530327 if(!this.in_apply_price_list) {
328 this.apply_price_list();
Anand Doshi61a2f682013-06-21 17:55:31 +0530329 }
Anand Doshi3543f302013-05-24 19:25:01 +0530330 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530331
Anand Doshi3543f302013-05-24 19:25:01 +0530332 qty: function(doc, cdt, cdn) {
Nabin Hait444f9562014-06-20 15:59:49 +0530333 this.apply_pricing_rule(frappe.get_doc(cdt, cdn), true);
Anand Doshi3543f302013-05-24 19:25:01 +0530334 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530335
Anand Doshi61a2f682013-06-21 17:55:31 +0530336 set_dynamic_labels: function() {
337 // What TODO? should we make price list system non-mandatory?
338 this.frm.toggle_reqd("plc_conversion_rate",
339 !!(this.frm.doc.price_list_name && this.frm.doc.price_list_currency));
Rushabh Mehtaff938022014-04-15 18:40:00 +0530340
Anand Doshi61a2f682013-06-21 17:55:31 +0530341 var company_currency = this.get_company_currency();
342 this.change_form_labels(company_currency);
343 this.change_grid_labels(company_currency);
Anand Doshi5013dcb2013-08-05 12:16:04 +0530344 this.frm.refresh_fields();
Anand Doshi61a2f682013-06-21 17:55:31 +0530345 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530346
Nabin Hait613d0812015-02-23 11:58:15 +0530347 change_form_labels: function(company_currency) {
348 var me = this;
349 var field_label_map = {};
350
351 var setup_field_label_map = function(fields_list, currency) {
352 $.each(fields_list, function(i, fname) {
353 var docfield = frappe.meta.docfield_map[me.frm.doc.doctype][fname];
354 if(docfield) {
355 var label = __(docfield.label || "").replace(/\([^\)]*\)/g, "");
356 field_label_map[fname] = label.trim() + " (" + currency + ")";
357 }
358 });
359 };
360 setup_field_label_map(["base_total", "base_net_total", "base_total_taxes_and_charges",
361 "base_discount_amount", "base_grand_total", "base_rounded_total", "base_in_words",
362 "base_taxes_and_charges_added", "base_taxes_and_charges_deducted", "total_amount_to_pay",
Nabin Hait37b047d2015-02-23 16:01:33 +0530363 "outstanding_amount", "total_advance", "paid_amount", "write_off_amount"], company_currency);
Nabin Hait613d0812015-02-23 11:58:15 +0530364
365 setup_field_label_map(["total", "net_total", "total_taxes_and_charges", "discount_amount",
366 "grand_total", "taxes_and_charges_added", "taxes_and_charges_deducted",
367 "rounded_total", "in_words"], this.frm.doc.currency);
368
369 cur_frm.set_df_property("conversion_rate", "description", "1 " + this.frm.doc.currency
370 + " = [?] " + company_currency)
371
372 if(this.frm.doc.price_list_currency && this.frm.doc.price_list_currency!=company_currency) {
373 cur_frm.set_df_property("plc_conversion_rate", "description", "1 " + this.frm.doc.price_list_currency
374 + " = [?] " + company_currency)
375 }
376
377 // toggle fields
378 this.frm.toggle_display(["conversion_rate", "base_total", "base_net_total", "base_total_taxes_and_charges",
379 "base_taxes_and_charges_added", "base_taxes_and_charges_deducted",
380 "base_grand_total", "base_rounded_total", "base_in_words", "base_discount_amount"],
381 this.frm.doc.currency != company_currency);
382
383 this.frm.toggle_display(["plc_conversion_rate", "price_list_currency"],
384 this.frm.doc.price_list_currency != company_currency);
385
386 // set labels
387 $.each(field_label_map, function(fname, label) {
388 me.frm.fields_dict[fname].set_label(label);
389 });
Nabin Hait37b047d2015-02-23 16:01:33 +0530390
Nabin Hait903c42a2015-02-24 15:24:49 +0530391 var show =cint(cur_frm.doc.discount_amount) ||
392 ((cur_frm.doc.taxes || []).filter(function(d) {return d.included_in_print_rate===1}).length);
393
394 if(frappe.meta.get_docfield(cur_frm.doctype, "net_total"))
395 cur_frm.toggle_display("net_total", show);
396
397 if(frappe.meta.get_docfield(cur_frm.doctype, "base_net_total"))
398 cur_frm.toggle_display("base_net_total", (show && (me.frm.doc.currency != company_currency)));
399
Nabin Hait613d0812015-02-23 11:58:15 +0530400 },
401
402 change_grid_labels: function(company_currency) {
403 var me = this;
404 var field_label_map = {};
405
406 var setup_field_label_map = function(fields_list, currency, parentfield) {
407 var grid_doctype = me.frm.fields_dict[parentfield].grid.doctype;
408 $.each(fields_list, function(i, fname) {
409 var docfield = frappe.meta.docfield_map[grid_doctype][fname];
410 if(docfield) {
411 var label = __(docfield.label || "").replace(/\([^\)]*\)/g, "");
412 field_label_map[grid_doctype + "-" + fname] =
413 label.trim() + " (" + currency + ")";
414 }
415 });
416 }
417
418 setup_field_label_map(["base_rate", "base_net_rate", "base_price_list_rate", "base_amount", "base_net_amount"],
419 company_currency, "items");
420
421 setup_field_label_map(["rate", "net_rate", "price_list_rate", "amount", "net_amount"],
422 this.frm.doc.currency, "items");
423
424 if(this.frm.fields_dict["taxes"]) {
425 setup_field_label_map(["tax_amount", "total", "tax_amount_after_discount"], this.frm.doc.currency, "taxes");
426
427 setup_field_label_map(["base_tax_amount", "base_total", "base_tax_amount_after_discount"], company_currency, "taxes");
428 }
429
430 if(this.frm.fields_dict["advances"]) {
431 setup_field_label_map(["advance_amount", "allocated_amount"], company_currency, "advances");
432 }
433
434 // toggle columns
435 var item_grid = this.frm.fields_dict["items"].grid;
436 $.each(["base_rate", "base_price_list_rate", "base_amount"], function(i, fname) {
437 if(frappe.meta.get_docfield(item_grid.doctype, fname))
438 item_grid.set_column_disp(fname, me.frm.doc.currency != company_currency);
439 });
440
441 var show = (cint(cur_frm.doc.discount_amount)) ||
442 ((cur_frm.doc.taxes || []).filter(function(d) {return d.included_in_print_rate===1}).length);
443
444 $.each(["net_rate", "net_amount"], function(i, fname) {
445 if(frappe.meta.get_docfield(item_grid.doctype, fname))
446 item_grid.set_column_disp(fname, show);
447 });
448
449 $.each(["base_net_rate", "base_net_amount"], function(i, fname) {
450 if(frappe.meta.get_docfield(item_grid.doctype, fname))
451 item_grid.set_column_disp(fname, (show && (me.frm.doc.currency != company_currency)));
452 });
453
454 // set labels
455 var $wrapper = $(this.frm.wrapper);
456 $.each(field_label_map, function(fname, label) {
457 fname = fname.split("-");
458 var df = frappe.meta.get_docfield(fname[0], fname[1], me.frm.doc.name);
459 if(df) df.label = label;
460 });
461 },
462
Anand Doshi923d41d2013-05-28 17:23:36 +0530463 recalculate: function() {
464 this.calculate_taxes_and_totals();
465 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530466
Anand Doshi923d41d2013-05-28 17:23:36 +0530467 recalculate_values: function() {
468 this.calculate_taxes_and_totals();
469 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530470
Anand Doshid0b00722013-05-28 18:54:48 +0530471 calculate_charges: function() {
472 this.calculate_taxes_and_totals();
473 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530474
Nabin Hait444f9562014-06-20 15:59:49 +0530475 ignore_pricing_rule: function() {
476 this.apply_pricing_rule();
477 },
478
479 apply_pricing_rule: function(item, calculate_taxes_and_totals) {
Nabin Haita3dd72a2014-05-28 12:49:20 +0530480 var me = this;
Anand Doshidffec8f2014-07-01 17:45:15 +0530481 return this.frm.call({
482 method: "erpnext.accounts.doctype.pricing_rule.pricing_rule.apply_pricing_rule",
483 args: { args: this._get_args(item) },
484 callback: function(r) {
Anand Doshif214bfc2014-07-16 17:52:08 +0530485 if (!r.exc && r.message) {
Anand Doshidffec8f2014-07-01 17:45:15 +0530486 me._set_values_for_item_list(r.message);
487 if(calculate_taxes_and_totals) me.calculate_taxes_and_totals();
488 }
489 }
490 });
491 },
492
493 _get_args: function(item) {
494 var me = this;
495 return {
496 "item_list": this._get_item_list(item),
Nabin Hait444f9562014-06-20 15:59:49 +0530497 "customer": me.frm.doc.customer,
498 "customer_group": me.frm.doc.customer_group,
499 "territory": me.frm.doc.territory,
500 "supplier": me.frm.doc.supplier,
501 "supplier_type": me.frm.doc.supplier_type,
502 "currency": me.frm.doc.currency,
503 "conversion_rate": me.frm.doc.conversion_rate,
504 "price_list": me.frm.doc.selling_price_list || me.frm.doc.buying_price_list,
Nabin Haitdd82bf22015-05-11 16:49:17 +0530505 "price_list_currency": me.frm.doc.price_list_currency,
Nabin Hait444f9562014-06-20 15:59:49 +0530506 "plc_conversion_rate": me.frm.doc.plc_conversion_rate,
507 "company": me.frm.doc.company,
508 "transaction_date": me.frm.doc.transaction_date || me.frm.doc.posting_date,
509 "campaign": me.frm.doc.campaign,
510 "sales_partner": me.frm.doc.sales_partner,
511 "ignore_pricing_rule": me.frm.doc.ignore_pricing_rule,
512 "parenttype": me.frm.doc.doctype,
513 "parent": me.frm.doc.name
514 };
Nabin Hait444f9562014-06-20 15:59:49 +0530515 },
516
517 _get_item_list: function(item) {
518 var item_list = [];
519 var append_item = function(d) {
Anand Doshi39edcbc2014-07-28 16:00:19 +0530520 if (d.item_code) {
521 item_list.push({
522 "doctype": d.doctype,
523 "name": d.name,
524 "item_code": d.item_code,
525 "item_group": d.item_group,
526 "brand": d.brand,
527 "qty": d.qty
528 });
529 }
Nabin Hait444f9562014-06-20 15:59:49 +0530530 };
Nabin Haita3dd72a2014-05-28 12:49:20 +0530531
Nabin Hait444f9562014-06-20 15:59:49 +0530532 if (item) {
533 append_item(item);
Nabin Haitc1367d92014-05-30 11:43:00 +0530534 } else {
Nabin Hait96339342015-01-21 17:22:11 +0530535 $.each(this.frm.doc["items"] || [], function(i, d) {
Nabin Hait444f9562014-06-20 15:59:49 +0530536 append_item(d);
Nabin Haita3dd72a2014-05-28 12:49:20 +0530537 });
538 }
Nabin Hait444f9562014-06-20 15:59:49 +0530539 return item_list;
Nabin Haita3dd72a2014-05-28 12:49:20 +0530540 },
541
Anand Doshidffec8f2014-07-01 17:45:15 +0530542 _set_values_for_item_list: function(children) {
Nabin Hait49a27292014-12-17 11:21:32 +0530543 var me = this;
Nabin Hait7d8fa802014-12-30 15:35:45 +0530544 var price_list_rate_changed = false;
Anand Doshidea3fb02015-02-05 15:05:58 +0530545 for(var i=0, l=children.length; i<l; i++) {
546 var d = children[i];
Nabin Hait49a27292014-12-17 11:21:32 +0530547 var existing_pricing_rule = frappe.model.get_value(d.doctype, d.name, "pricing_rule");
Anand Doshidea3fb02015-02-05 15:05:58 +0530548
549 for(var k in d) {
550 var v = d[k];
Anand Doshidffec8f2014-07-01 17:45:15 +0530551 if (["doctype", "name"].indexOf(k)===-1) {
Nabin Hait7d8fa802014-12-30 15:35:45 +0530552 if(k=="price_list_rate") {
553 if(flt(v) != flt(d.price_list_rate)) price_list_rate_changed = true;
554 }
Anand Doshidffec8f2014-07-01 17:45:15 +0530555 frappe.model.set_value(d.doctype, d.name, k, v);
556 }
Anand Doshidea3fb02015-02-05 15:05:58 +0530557 }
558
Nabin Hait49a27292014-12-17 11:21:32 +0530559 // if pricing rule set as blank from an existing value, apply price_list
Nabin Haitcfe3c542014-12-22 10:42:48 +0530560 if(!me.frm.doc.ignore_pricing_rule && existing_pricing_rule && !d.pricing_rule) {
Nabin Hait49a27292014-12-17 11:21:32 +0530561 me.apply_price_list(frappe.get_doc(d.doctype, d.name));
562 }
Anand Doshidea3fb02015-02-05 15:05:58 +0530563 }
Nabin Hait7d8fa802014-12-30 15:35:45 +0530564
Anand Doshidea3fb02015-02-05 15:05:58 +0530565 if(!price_list_rate_changed) me.calculate_taxes_and_totals();
Anand Doshidffec8f2014-07-01 17:45:15 +0530566 },
567
Nabin Hait49a27292014-12-17 11:21:32 +0530568 apply_price_list: function(item) {
Anand Doshidffec8f2014-07-01 17:45:15 +0530569 var me = this;
Rushabh Mehta052bd622015-01-30 16:57:24 +0530570 var args = this._get_args(item);
Nabin Hait37b047d2015-02-23 16:01:33 +0530571
Anand Doshidffec8f2014-07-01 17:45:15 +0530572 return this.frm.call({
573 method: "erpnext.stock.get_item_details.apply_price_list",
Rushabh Mehta052bd622015-01-30 16:57:24 +0530574 args: { args: args },
Anand Doshidffec8f2014-07-01 17:45:15 +0530575 callback: function(r) {
576 if (!r.exc) {
Anand Doshi51f722d2014-07-04 15:44:26 +0530577 me.in_apply_price_list = true;
Anand Doshidffec8f2014-07-01 17:45:15 +0530578 me.frm.set_value("price_list_currency", r.message.parent.price_list_currency);
579 me.frm.set_value("plc_conversion_rate", r.message.parent.plc_conversion_rate);
Anand Doshi51f722d2014-07-04 15:44:26 +0530580 me.in_apply_price_list = false;
Nabin Hait37b047d2015-02-23 16:01:33 +0530581
582 if(args.item_list.length) {
583 me._set_values_for_item_list(r.message.children);
584 }
Anand Doshidffec8f2014-07-01 17:45:15 +0530585 }
586 }
587 });
588 },
589
Anand Doshi3543f302013-05-24 19:25:01 +0530590 get_item_wise_taxes_html: function() {
591 var item_tax = {};
592 var tax_accounts = [];
593 var company_currency = this.get_company_currency();
Rushabh Mehtaff938022014-04-15 18:40:00 +0530594
Nabin Hait96339342015-01-21 17:22:11 +0530595 $.each(this.frm.doc["taxes"] || [], function(i, tax) {
Anand Doshi3543f302013-05-24 19:25:01 +0530596 var tax_amount_precision = precision("tax_amount", tax);
Anand Doshi53b73422013-05-31 11:50:01 +0530597 var tax_rate_precision = precision("rate", tax);
Rushabh Mehtaff938022014-04-15 18:40:00 +0530598 $.each(JSON.parse(tax.item_wise_tax_detail || '{}'),
Anand Doshi53b73422013-05-31 11:50:01 +0530599 function(item_code, tax_data) {
Anand Doshi3543f302013-05-24 19:25:01 +0530600 if(!item_tax[item_code]) item_tax[item_code] = {};
Anand Doshi53b73422013-05-31 11:50:01 +0530601 if($.isArray(tax_data)) {
Anand Doshi1e4fb682013-08-23 12:56:33 +0530602 var tax_rate = "";
603 if(tax_data[0] != null) {
604 tax_rate = (tax.charge_type === "Actual") ?
605 format_currency(flt(tax_data[0], tax_amount_precision), company_currency, tax_amount_precision) :
606 (flt(tax_data[0], tax_rate_precision) + "%");
607 }
608 var tax_amount = format_currency(flt(tax_data[1], tax_amount_precision), company_currency,
609 tax_amount_precision);
Rushabh Mehtaff938022014-04-15 18:40:00 +0530610
Anand Doshiaa71b5b2013-08-05 13:00:53 +0530611 item_tax[item_code][tax.name] = [tax_rate, tax_amount];
Anand Doshi53b73422013-05-31 11:50:01 +0530612 } else {
Anand Doshiaa71b5b2013-08-05 13:00:53 +0530613 item_tax[item_code][tax.name] = [flt(tax_data, tax_rate_precision) + "%", ""];
Anand Doshi53b73422013-05-31 11:50:01 +0530614 }
Anand Doshi3543f302013-05-24 19:25:01 +0530615 });
Anand Doshiaa71b5b2013-08-05 13:00:53 +0530616 tax_accounts.push([tax.name, tax.account_head]);
Anand Doshi3543f302013-05-24 19:25:01 +0530617 });
Rushabh Mehtaff938022014-04-15 18:40:00 +0530618
619 var headings = $.map([__("Item Name")].concat($.map(tax_accounts, function(head) { return head[1]; })),
Anand Doshi3543f302013-05-24 19:25:01 +0530620 function(head) { return '<th style="min-width: 100px;">' + (head || "") + "</th>" }).join("\n");
Rushabh Mehtaff938022014-04-15 18:40:00 +0530621
Anand Doshi179e3772013-09-05 16:53:57 +0530622 var distinct_item_names = [];
623 var distinct_items = [];
Nabin Hait96339342015-01-21 17:22:11 +0530624 $.each(this.frm.doc["items"] || [], function(i, item) {
Anand Doshi179e3772013-09-05 16:53:57 +0530625 if(distinct_item_names.indexOf(item.item_code || item.item_name)===-1) {
626 distinct_item_names.push(item.item_code || item.item_name);
627 distinct_items.push(item);
628 }
629 });
Rushabh Mehtaff938022014-04-15 18:40:00 +0530630
Anand Doshi179e3772013-09-05 16:53:57 +0530631 var rows = $.map(distinct_items, function(item) {
Anand Doshi3543f302013-05-24 19:25:01 +0530632 var item_tax_record = item_tax[item.item_code || item.item_name];
Anand Doshi53b73422013-05-31 11:50:01 +0530633 if(!item_tax_record) { return null; }
Anand Doshi3543f302013-05-24 19:25:01 +0530634 return repl("<tr><td>%(item_name)s</td>%(taxes)s</tr>", {
635 item_name: item.item_name,
636 taxes: $.map(tax_accounts, function(head) {
Anand Doshiaa71b5b2013-08-05 13:00:53 +0530637 return item_tax_record[head[0]] ?
638 "<td>(" + item_tax_record[head[0]][0] + ") " + item_tax_record[head[0]][1] + "</td>" :
Anand Doshi64f316b2013-07-17 15:12:22 +0530639 "<td></td>";
Anand Doshi3543f302013-05-24 19:25:01 +0530640 }).join("\n")
641 });
642 }).join("\n");
Rushabh Mehtaff938022014-04-15 18:40:00 +0530643
Anand Doshi53b73422013-05-31 11:50:01 +0530644 if(!rows) return "";
Rushabh Mehta7d8b1892013-11-08 16:27:18 +0530645 return '<p><a href="#" onclick="$(\'.tax-break-up\').toggleClass(\'hide\'); return false;">Show / Hide tax break-up</a><br><br></p>\
646 <div class="tax-break-up hide" style="overflow-x: auto;"><table class="table table-bordered table-hover">\
Anand Doshi3543f302013-05-24 19:25:01 +0530647 <thead><tr>' + headings + '</tr></thead> \
648 <tbody>' + rows + '</tbody> \
649 </table></div>';
650 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530651
Nabin Hait139dc7b2014-02-12 14:53:18 +0530652 validate_company_and_party: function() {
Anand Doshi923d41d2013-05-28 17:23:36 +0530653 var me = this;
Anand Doshi3543f302013-05-24 19:25:01 +0530654 var valid = true;
Rushabh Mehtaff938022014-04-15 18:40:00 +0530655
Nabin Hait0f231062014-02-20 11:27:47 +0530656 $.each(["company", "customer"], function(i, fieldname) {
Rushabh Mehta793ba6b2014-02-14 15:47:51 +0530657 if(frappe.meta.has_field(me.frm.doc.doctype, fieldname)) {
Nabin Hait139dc7b2014-02-12 14:53:18 +0530658 if (!me.frm.doc[fieldname]) {
Rushabh Mehtaff938022014-04-15 18:40:00 +0530659 msgprint(__("Please specify") + ": " +
660 frappe.meta.get_label(me.frm.doc.doctype, fieldname, me.frm.doc.name) +
Pratik Vyasb52618c2014-04-14 16:25:30 +0530661 ". " + __("It is needed to fetch Item Details."));
Nabin Hait139dc7b2014-02-12 14:53:18 +0530662 valid = false;
663 }
Anand Doshi3543f302013-05-24 19:25:01 +0530664 }
665 });
666 return valid;
667 },
Rushabh Mehtaff938022014-04-15 18:40:00 +0530668
Anand Doshibf3e54a2013-06-05 14:11:32 +0530669 get_terms: function() {
670 var me = this;
671 if(this.frm.doc.tc_name) {
Anand Doshi1fac2a92013-07-29 19:30:39 +0530672 return this.frm.call({
Rushabh Mehta793ba6b2014-02-14 15:47:51 +0530673 method: "frappe.client.get_value",
Anand Doshibf3e54a2013-06-05 14:11:32 +0530674 args: {
675 doctype: "Terms and Conditions",
676 fieldname: "terms",
677 filters: { name: this.frm.doc.tc_name },
678 },
679 });
680 }
681 },
Akhilesh Darjee4f721562014-01-29 16:31:38 +0530682
683 taxes_and_charges: function() {
684 var me = this;
685 if(this.frm.doc.taxes_and_charges) {
686 return this.frm.call({
Nabin Hait6b039142014-05-02 15:45:10 +0530687 method: "erpnext.controllers.accounts_controller.get_taxes_and_charges",
688 args: {
Nabin Hait03f3a8a2014-05-13 16:38:31 +0530689 "master_doctype": frappe.meta.get_docfield(this.frm.doc.doctype, "taxes_and_charges",
690 this.frm.doc.name).options,
Nabin Hait6b039142014-05-02 15:45:10 +0530691 "master_name": this.frm.doc.taxes_and_charges,
Nabin Hait6b039142014-05-02 15:45:10 +0530692 },
Akhilesh Darjee4f721562014-01-29 16:31:38 +0530693 callback: function(r) {
694 if(!r.exc) {
Nabin Haitdd38a262014-12-26 13:15:21 +0530695 me.frm.set_value("taxes", r.message);
Akhilesh Darjee4f721562014-01-29 16:31:38 +0530696 me.calculate_taxes_and_totals();
697 }
698 }
699 });
Nabin Haitbc83b9c2014-05-02 17:03:18 +0530700 }
Akhilesh Darjee4f721562014-01-29 16:31:38 +0530701 },
702
703 show_item_wise_taxes: function() {
704 if(this.frm.fields_dict.other_charges_calculation) {
Anand Doshidd942bb2015-02-04 18:52:35 +0530705 var html = this.get_item_wise_taxes_html();
706 if (html) {
707 this.frm.toggle_display("other_charges_calculation", true);
708 $(this.frm.fields_dict.other_charges_calculation.wrapper).html(html);
709 } else {
710 this.frm.toggle_display("other_charges_calculation", false);
711 }
Akhilesh Darjee4f721562014-01-29 16:31:38 +0530712 }
713 },
Anand Doshi13945092014-09-21 19:45:49 +0530714
715 is_recurring: function() {
716 // set default values for recurring documents
717 if(this.frm.doc.is_recurring) {
718 var owner_email = this.frm.doc.owner=="Administrator"
719 ? frappe.user_info("Administrator").email
720 : this.frm.doc.owner;
721
722 this.frm.doc.notification_email_address = $.map([cstr(owner_email),
723 cstr(this.frm.doc.contact_email)], function(v) { return v || null; }).join(", ");
724 this.frm.doc.repeat_on_day_of_month = frappe.datetime.str_to_obj(this.frm.doc.posting_date).getDate();
725 }
726
727 refresh_many(["notification_email_address", "repeat_on_day_of_month"]);
728 },
729
730 from_date: function() {
731 // set to_date
732 if(this.frm.doc.from_date) {
733 var recurring_type_map = {'Monthly': 1, 'Quarterly': 3, 'Half-yearly': 6,
734 'Yearly': 12};
735
736 var months = recurring_type_map[this.frm.doc.recurring_type];
737 if(months) {
738 var to_date = frappe.datetime.add_months(this.frm.doc.from_date,
739 months);
740 this.frm.doc.to_date = frappe.datetime.add_days(to_date, -1);
741 refresh_field('to_date');
742 }
743 }
744 }
Rushabh Mehtaff938022014-04-15 18:40:00 +0530745});
Nabin Haitce245122015-02-22 20:14:49 +0530746
Nabin Hait93b3a372015-02-24 17:08:34 +0530747frappe.ui.form.on(cur_frm.doctype + " Item", "rate", function(frm, cdt, cdn) {
Nabin Haitce245122015-02-22 20:14:49 +0530748 var item = frappe.get_doc(cdt, cdn);
749 frappe.model.round_floats_in(item, ["rate", "price_list_rate"]);
750
751 if(item.price_list_rate) {
752 item.discount_percentage = flt((1 - item.rate / item.price_list_rate) * 100.0, precision("discount_percentage", item));
753 } else {
754 item.discount_percentage = 0.0;
755 }
756
757 cur_frm.cscript.calculate_taxes_and_totals();
758})
Nabin Hait613d0812015-02-23 11:58:15 +0530759
760frappe.ui.form.on(cur_frm.cscript.tax_table, "rate", function(frm, cdt, cdn) {
761 cur_frm.cscript.calculate_taxes_and_totals();
762})
763
764frappe.ui.form.on(cur_frm.cscript.tax_table, "tax_amount", function(frm, cdt, cdn) {
765 cur_frm.cscript.calculate_taxes_and_totals();
766})
767
768frappe.ui.form.on(cur_frm.cscript.tax_table, "row_id", function(frm, cdt, cdn) {
769 cur_frm.cscript.calculate_taxes_and_totals();
770})
771
772frappe.ui.form.on(cur_frm.cscript.tax_table, "included_in_print_rate", function(frm, cdt, cdn) {
Nabin Hait903c42a2015-02-24 15:24:49 +0530773 cur_frm.cscript.set_dynamic_labels();
Nabin Hait613d0812015-02-23 11:58:15 +0530774 cur_frm.cscript.calculate_taxes_and_totals();
775})
Nabin Hait37b047d2015-02-23 16:01:33 +0530776
777frappe.ui.form.on(cur_frm.doctype, "apply_discount_on", function(frm) {
778 cur_frm.cscript.calculate_taxes_and_totals();
779})
780
781frappe.ui.form.on(cur_frm.doctype, "discount_amount", function(frm) {
Nabin Hait903c42a2015-02-24 15:24:49 +0530782 cur_frm.cscript.set_dynamic_labels();
Nabin Hait37b047d2015-02-23 16:01:33 +0530783 cur_frm.cscript.calculate_taxes_and_totals();
784})