Rushabh Mehta | ad45e31 | 2013-11-20 12:59:58 +0530 | [diff] [blame] | 1 | // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors |
Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 2 | // License: GNU General Public License v3. See license.txt |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 3 | |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 4 | frappe.provide("erpnext"); |
| 5 | frappe.require("assets/erpnext/js/controllers/stock_controller.js"); |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 6 | |
Anand Doshi | a648f46 | 2013-07-30 14:42:15 +0530 | [diff] [blame] | 7 | erpnext.TransactionController = erpnext.stock.StockController.extend({ |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 8 | onload: function() { |
Anand Doshi | 1e4fb68 | 2013-08-23 12:56:33 +0530 | [diff] [blame] | 9 | var me = this; |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 10 | if(this.frm.doc.__islocal) { |
Anand Doshi | 1e4fb68 | 2013-08-23 12:56:33 +0530 | [diff] [blame] | 11 | var today = get_today(), |
Nabin Hait | 73083dc | 2014-03-14 15:10:42 +0530 | [diff] [blame] | 12 | currency = frappe.defaults.get_user_default("currency"); |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 13 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 14 | $.each({ |
Anand Doshi | fc77718 | 2013-05-27 19:29:07 +0530 | [diff] [blame] | 15 | posting_date: today, |
| 16 | due_date: today, |
| 17 | transaction_date: today, |
| 18 | currency: currency, |
| 19 | price_list_currency: currency, |
| 20 | status: "Draft", |
Nabin Hait | 73083dc | 2014-03-14 15:10:42 +0530 | [diff] [blame] | 21 | company: frappe.defaults.get_user_default("company"), |
| 22 | fiscal_year: frappe.defaults.get_user_default("fiscal_year"), |
Anand Doshi | fc77718 | 2013-05-27 19:29:07 +0530 | [diff] [blame] | 23 | is_subcontracted: "No", |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 24 | }, function(fieldname, value) { |
| 25 | if(me.frm.fields_dict[fieldname] && !me.frm.doc[fieldname]) |
| 26 | me.frm.set_value(fieldname, value); |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 27 | }); |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 28 | } |
Akhilesh Darjee | 564c621 | 2013-10-17 11:31:11 +0530 | [diff] [blame] | 29 | |
Anand Doshi | 1e4fb68 | 2013-08-23 12:56:33 +0530 | [diff] [blame] | 30 | if(this.other_fname) { |
Anand Doshi | a91c95f | 2013-08-23 13:00:47 +0530 | [diff] [blame] | 31 | this[this.other_fname + "_remove"] = this.calculate_taxes_and_totals; |
| 32 | } |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 33 | |
Anand Doshi | a91c95f | 2013-08-23 13:00:47 +0530 | [diff] [blame] | 34 | if(this.fname) { |
| 35 | this[this.fname + "_remove"] = this.calculate_taxes_and_totals; |
Anand Doshi | 1e4fb68 | 2013-08-23 12:56:33 +0530 | [diff] [blame] | 36 | } |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 37 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 38 | |
Anand Doshi | 5e4e5d7 | 2013-08-06 17:23:44 +0530 | [diff] [blame] | 39 | onload_post_render: function() { |
Akhilesh Darjee | 61b5c59 | 2013-10-15 20:24:34 +0530 | [diff] [blame] | 40 | var me = this; |
| 41 | if(this.frm.doc.__islocal && this.frm.doc.company && !this.frm.doc.is_pos) { |
Anand Doshi | b054eb7 | 2014-04-22 20:35:22 +0530 | [diff] [blame] | 42 | this.calculate_taxes_and_totals(); |
Anand Doshi | 5e4e5d7 | 2013-08-06 17:23:44 +0530 | [diff] [blame] | 43 | } |
| 44 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 45 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 46 | refresh: function() { |
| 47 | this.frm.clear_custom_buttons(); |
Anand Doshi | 8bde7f9 | 2014-04-24 18:11:49 +0530 | [diff] [blame] | 48 | erpnext.toggle_naming_series(); |
Anand Doshi | bdee6e0 | 2013-07-09 13:03:39 +0530 | [diff] [blame] | 49 | erpnext.hide_company(); |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 50 | this.show_item_wise_taxes(); |
Nabin Hait | 1f996c3 | 2013-07-29 19:00:53 +0530 | [diff] [blame] | 51 | this.set_dynamic_labels(); |
Akhilesh Darjee | 6773bc2 | 2013-09-17 11:56:17 +0530 | [diff] [blame] | 52 | |
| 53 | // Show POS button only if it is enabled from features setup |
| 54 | if(cint(sys_defaults.fs_pos_view)===1 && this.frm.doctype!="Material Request") |
Rushabh Mehta | e34090a | 2013-11-15 11:30:23 +0530 | [diff] [blame] | 55 | this.make_pos_btn(); |
Akhilesh Darjee | 6773bc2 | 2013-09-17 11:56:17 +0530 | [diff] [blame] | 56 | }, |
| 57 | |
Rushabh Mehta | e34090a | 2013-11-15 11:30:23 +0530 | [diff] [blame] | 58 | make_pos_btn: function() { |
Akhilesh Darjee | 6773bc2 | 2013-09-17 11:56:17 +0530 | [diff] [blame] | 59 | if(!this.pos_active) { |
Pratik Vyas | b52618c | 2014-04-14 16:25:30 +0530 | [diff] [blame] | 60 | var btn_label = __("POS View"), |
Akhilesh Darjee | 6773bc2 | 2013-09-17 11:56:17 +0530 | [diff] [blame] | 61 | icon = "icon-desktop"; |
| 62 | } else { |
Pratik Vyas | b52618c | 2014-04-14 16:25:30 +0530 | [diff] [blame] | 63 | var btn_label = __(this.frm.doctype) + __(" View"), |
Akhilesh Darjee | 6773bc2 | 2013-09-17 11:56:17 +0530 | [diff] [blame] | 64 | icon = "icon-file-text"; |
Akhilesh Darjee | 6773bc2 | 2013-09-17 11:56:17 +0530 | [diff] [blame] | 65 | } |
| 66 | var me = this; |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 67 | |
Rushabh Mehta | e34090a | 2013-11-15 11:30:23 +0530 | [diff] [blame] | 68 | this.$pos_btn = this.frm.appframe.add_button(btn_label, function() { |
Akhilesh Darjee | 6773bc2 | 2013-09-17 11:56:17 +0530 | [diff] [blame] | 69 | me.toggle_pos(); |
Akhilesh Darjee | 6773bc2 | 2013-09-17 11:56:17 +0530 | [diff] [blame] | 70 | }, icon); |
| 71 | }, |
| 72 | |
| 73 | toggle_pos: function(show) { |
Akhilesh Darjee | f83576b | 2013-09-18 18:35:12 +0530 | [diff] [blame] | 74 | // Check whether it is Selling or Buying cycle |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 75 | var price_list = frappe.meta.has_field(cur_frm.doc.doctype, "selling_price_list") ? |
Akhilesh Darjee | f83576b | 2013-09-18 18:35:12 +0530 | [diff] [blame] | 76 | this.frm.doc.selling_price_list : this.frm.doc.buying_price_list; |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 77 | |
Akhilesh Darjee | f83576b | 2013-09-18 18:35:12 +0530 | [diff] [blame] | 78 | if (!price_list) |
Pratik Vyas | b52618c | 2014-04-14 16:25:30 +0530 | [diff] [blame] | 79 | msgprint(__("Please select Price List")) |
Akhilesh Darjee | 6773bc2 | 2013-09-17 11:56:17 +0530 | [diff] [blame] | 80 | else { |
| 81 | if((show===true && this.pos_active) || (show===false && !this.pos_active)) return; |
| 82 | |
| 83 | // make pos |
Akhilesh Darjee | f624ffa | 2013-09-23 12:27:16 +0530 | [diff] [blame] | 84 | if(!this.frm.pos) { |
Akhilesh Darjee | 6773bc2 | 2013-09-17 11:56:17 +0530 | [diff] [blame] | 85 | this.frm.layout.add_view("pos"); |
| 86 | this.frm.pos = new erpnext.POS(this.frm.layout.views.pos, this.frm); |
| 87 | } |
| 88 | |
| 89 | // toggle view |
| 90 | this.frm.layout.set_view(this.pos_active ? "" : "pos"); |
| 91 | this.pos_active = !this.pos_active; |
| 92 | |
| 93 | // refresh |
| 94 | if(this.pos_active) |
| 95 | this.frm.pos.refresh(); |
Akhilesh Darjee | f83576b | 2013-09-18 18:35:12 +0530 | [diff] [blame] | 96 | this.frm.refresh(); |
Akhilesh Darjee | 6773bc2 | 2013-09-17 11:56:17 +0530 | [diff] [blame] | 97 | } |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 98 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 99 | |
| 100 | |
Nabin Hait | 139dc7b | 2014-02-12 14:53:18 +0530 | [diff] [blame] | 101 | item_code: function(doc, cdt, cdn) { |
| 102 | var me = this; |
Rushabh Mehta | 66d52b5 | 2014-03-27 14:17:33 +0530 | [diff] [blame] | 103 | var item = frappe.get_doc(cdt, cdn); |
Nabin Hait | 139dc7b | 2014-02-12 14:53:18 +0530 | [diff] [blame] | 104 | if(item.item_code || item.barcode || item.serial_no) { |
| 105 | if(!this.validate_company_and_party()) { |
| 106 | cur_frm.fields_dict[me.frm.cscript.fname].grid.grid_rows[item.idx - 1].remove(); |
| 107 | } else { |
| 108 | return this.frm.call({ |
| 109 | method: "erpnext.stock.get_item_details.get_item_details", |
| 110 | child: item, |
| 111 | args: { |
| 112 | args: { |
| 113 | item_code: item.item_code, |
| 114 | barcode: item.barcode, |
| 115 | serial_no: item.serial_no, |
| 116 | warehouse: item.warehouse, |
| 117 | doctype: me.frm.doc.doctype, |
| 118 | docname: me.frm.doc.name, |
| 119 | customer: me.frm.doc.customer, |
| 120 | supplier: me.frm.doc.supplier, |
| 121 | currency: me.frm.doc.currency, |
| 122 | conversion_rate: me.frm.doc.conversion_rate, |
| 123 | price_list: me.frm.doc.selling_price_list || |
| 124 | me.frm.doc.buying_price_list, |
| 125 | price_list_currency: me.frm.doc.price_list_currency, |
| 126 | plc_conversion_rate: me.frm.doc.plc_conversion_rate, |
| 127 | company: me.frm.doc.company, |
| 128 | order_type: me.frm.doc.order_type, |
| 129 | is_pos: cint(me.frm.doc.is_pos), |
| 130 | is_subcontracted: me.frm.doc.is_subcontracted, |
| 131 | transaction_date: me.frm.doc.transaction_date |
| 132 | } |
| 133 | }, |
| 134 | callback: function(r) { |
| 135 | if(!r.exc) { |
| 136 | me.frm.script_manager.trigger("price_list_rate", cdt, cdn); |
| 137 | } |
| 138 | } |
| 139 | }); |
| 140 | } |
| 141 | } |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 142 | }, |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 143 | |
| 144 | serial_no: function(doc, cdt, cdn) { |
| 145 | var me = this; |
Rushabh Mehta | 66d52b5 | 2014-03-27 14:17:33 +0530 | [diff] [blame] | 146 | var item = frappe.get_doc(cdt, cdn); |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 147 | |
| 148 | if (item.serial_no) { |
| 149 | if (!item.item_code) { |
| 150 | this.frm.script_manager.trigger("item_code", cdt, cdn); |
| 151 | } |
| 152 | else { |
| 153 | var sr_no = []; |
| 154 | |
| 155 | // Replacing all occurences of comma with carriage return |
| 156 | var serial_nos = item.serial_no.trim().replace(/,/g, '\n'); |
| 157 | |
| 158 | serial_nos = serial_nos.trim().split('\n'); |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 159 | |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 160 | // Trim each string and push unique string to new list |
| 161 | for (var x=0; x<=serial_nos.length - 1; x++) { |
| 162 | if (serial_nos[x].trim() != "" && sr_no.indexOf(serial_nos[x].trim()) == -1) { |
| 163 | sr_no.push(serial_nos[x].trim()); |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | // Add the new list to the serial no. field in grid with each in new line |
| 168 | item.serial_no = ""; |
| 169 | for (var x=0; x<=sr_no.length - 1; x++) |
| 170 | item.serial_no += sr_no[x] + '\n'; |
| 171 | |
| 172 | refresh_field("serial_no", item.name, item.parentfield); |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 173 | frappe.model.set_value(item.doctype, item.name, "qty", sr_no.length); |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 174 | } |
| 175 | } |
| 176 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 177 | |
Anand Doshi | 923d41d | 2013-05-28 17:23:36 +0530 | [diff] [blame] | 178 | validate: function() { |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 179 | this.calculate_taxes_and_totals(false); |
Anand Doshi | 923d41d | 2013-05-28 17:23:36 +0530 | [diff] [blame] | 180 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 181 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 182 | company: function() { |
Anand Doshi | d52b03a | 2013-06-21 12:22:52 +0530 | [diff] [blame] | 183 | if(this.frm.doc.company && this.frm.fields_dict.currency) { |
Akhilesh Darjee | 1797cfe | 2013-10-11 13:34:10 +0530 | [diff] [blame] | 184 | var company_currency = this.get_company_currency(); |
Akhilesh Darjee | 7837827 | 2013-10-11 19:06:30 +0530 | [diff] [blame] | 185 | if (!this.frm.doc.currency) { |
Akhilesh Darjee | 1797cfe | 2013-10-11 13:34:10 +0530 | [diff] [blame] | 186 | this.frm.set_value("currency", company_currency); |
Anand Doshi | 17350b8 | 2013-08-01 15:45:23 +0530 | [diff] [blame] | 187 | } |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 188 | |
Akhilesh Darjee | 7837827 | 2013-10-11 19:06:30 +0530 | [diff] [blame] | 189 | if (this.frm.doc.currency == company_currency) { |
Akhilesh Darjee | 1797cfe | 2013-10-11 13:34:10 +0530 | [diff] [blame] | 190 | this.frm.set_value("conversion_rate", 1.0); |
Akhilesh Darjee | 7837827 | 2013-10-11 19:06:30 +0530 | [diff] [blame] | 191 | } |
| 192 | if (this.frm.doc.price_list_currency == company_currency) { |
Akhilesh Darjee | 1797cfe | 2013-10-11 13:34:10 +0530 | [diff] [blame] | 193 | this.frm.set_value('plc_conversion_rate', 1.0); |
Akhilesh Darjee | 7837827 | 2013-10-11 19:06:30 +0530 | [diff] [blame] | 194 | } |
Akhilesh Darjee | 1797cfe | 2013-10-11 13:34:10 +0530 | [diff] [blame] | 195 | |
Nabin Hait | 48a0bd3 | 2013-07-23 15:31:39 +0530 | [diff] [blame] | 196 | this.frm.script_manager.trigger("currency"); |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 197 | } |
| 198 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 199 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 200 | get_company_currency: function() { |
| 201 | return erpnext.get_currency(this.frm.doc.company); |
| 202 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 203 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 204 | currency: function() { |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 205 | var me = this; |
| 206 | this.set_dynamic_labels(); |
Akhilesh Darjee | 7837827 | 2013-10-11 19:06:30 +0530 | [diff] [blame] | 207 | |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 208 | var company_currency = this.get_company_currency(); |
| 209 | if(this.frm.doc.currency !== company_currency) { |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 210 | this.get_exchange_rate(this.frm.doc.currency, company_currency, |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 211 | function(exchange_rate) { |
Akhilesh Darjee | 7837827 | 2013-10-11 19:06:30 +0530 | [diff] [blame] | 212 | me.frm.set_value("conversion_rate", exchange_rate); |
| 213 | me.conversion_rate(); |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 214 | }); |
| 215 | } else { |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 216 | this.conversion_rate(); |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 217 | } |
| 218 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 219 | |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 220 | conversion_rate: function() { |
Anand Doshi | 535d833 | 2013-07-19 13:51:07 +0530 | [diff] [blame] | 221 | if(this.frm.doc.currency === this.get_company_currency()) { |
| 222 | this.frm.set_value("conversion_rate", 1.0); |
Akhilesh Darjee | acf65a7 | 2013-10-17 13:04:26 +0530 | [diff] [blame] | 223 | } |
| 224 | if(this.frm.doc.currency === this.frm.doc.price_list_currency && |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 225 | this.frm.doc.plc_conversion_rate !== this.frm.doc.conversion_rate) { |
| 226 | this.frm.set_value("plc_conversion_rate", this.frm.doc.conversion_rate); |
| 227 | } |
Nabin Hait | b338b6e | 2013-10-15 16:55:24 +0530 | [diff] [blame] | 228 | if(flt(this.frm.doc.conversion_rate)>0.0) this.calculate_taxes_and_totals(); |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 229 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 230 | |
Rushabh Mehta | 4a404e9 | 2013-08-09 18:11:35 +0530 | [diff] [blame] | 231 | get_price_list_currency: function(buying_or_selling) { |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 232 | var me = this; |
Rushabh Mehta | 4a404e9 | 2013-08-09 18:11:35 +0530 | [diff] [blame] | 233 | var fieldname = buying_or_selling.toLowerCase() + "_price_list"; |
| 234 | if(this.frm.doc[fieldname]) { |
Anand Doshi | 1fac2a9 | 2013-07-29 19:30:39 +0530 | [diff] [blame] | 235 | return this.frm.call({ |
Rushabh Mehta | 1f84799 | 2013-12-12 19:12:19 +0530 | [diff] [blame] | 236 | method: "erpnext.setup.utils.get_price_list_currency", |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 237 | args: { |
Rushabh Mehta | 4a404e9 | 2013-08-09 18:11:35 +0530 | [diff] [blame] | 238 | price_list: this.frm.doc[fieldname], |
Nabin Hait | 48a0bd3 | 2013-07-23 15:31:39 +0530 | [diff] [blame] | 239 | }, |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 240 | callback: function(r) { |
| 241 | if(!r.exc) { |
| 242 | me.price_list_currency(); |
| 243 | } |
| 244 | } |
| 245 | }); |
| 246 | } |
| 247 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 248 | |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 249 | get_exchange_rate: function(from_currency, to_currency, callback) { |
| 250 | var exchange_name = from_currency + "-" + to_currency; |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 251 | frappe.model.with_doc("Currency Exchange", exchange_name, function(name) { |
Rushabh Mehta | 66d52b5 | 2014-03-27 14:17:33 +0530 | [diff] [blame] | 252 | var exchange_doc = frappe.get_doc("Currency Exchange", exchange_name); |
Nabin Hait | 13f2e4d | 2013-06-25 10:56:39 +0530 | [diff] [blame] | 253 | callback(exchange_doc ? flt(exchange_doc.exchange_rate) : 0); |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 254 | }); |
| 255 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 256 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 257 | price_list_currency: function() { |
Akhilesh Darjee | db59ffb | 2013-09-11 13:05:24 +0530 | [diff] [blame] | 258 | var me=this; |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 259 | this.set_dynamic_labels(); |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 260 | |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 261 | var company_currency = this.get_company_currency(); |
| 262 | if(this.frm.doc.price_list_currency !== company_currency) { |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 263 | this.get_exchange_rate(this.frm.doc.price_list_currency, company_currency, |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 264 | function(exchange_rate) { |
| 265 | if(exchange_rate) { |
Akhilesh Darjee | db59ffb | 2013-09-11 13:05:24 +0530 | [diff] [blame] | 266 | me.frm.set_value("plc_conversion_rate", exchange_rate); |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 267 | me.plc_conversion_rate(); |
| 268 | } |
| 269 | }); |
| 270 | } else { |
| 271 | this.plc_conversion_rate(); |
| 272 | } |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 273 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 274 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 275 | plc_conversion_rate: function() { |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 276 | if(this.frm.doc.price_list_currency === this.get_company_currency()) { |
| 277 | this.frm.set_value("plc_conversion_rate", 1.0); |
Akhilesh Darjee | 564c621 | 2013-10-17 11:31:11 +0530 | [diff] [blame] | 278 | } |
| 279 | if(this.frm.doc.price_list_currency === this.frm.doc.currency) { |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 280 | this.frm.set_value("conversion_rate", this.frm.doc.plc_conversion_rate); |
| 281 | this.calculate_taxes_and_totals(); |
| 282 | } |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 283 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 284 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 285 | qty: function(doc, cdt, cdn) { |
| 286 | this.calculate_taxes_and_totals(); |
| 287 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 288 | |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 289 | // tax rate |
| 290 | rate: function(doc, cdt, cdn) { |
Anand Doshi | 923d41d | 2013-05-28 17:23:36 +0530 | [diff] [blame] | 291 | this.calculate_taxes_and_totals(); |
| 292 | }, |
Akhilesh Darjee | 10dce34 | 2013-09-25 11:09:33 +0530 | [diff] [blame] | 293 | |
Anand Doshi | 923d41d | 2013-05-28 17:23:36 +0530 | [diff] [blame] | 294 | row_id: function(doc, cdt, cdn) { |
Rushabh Mehta | 66d52b5 | 2014-03-27 14:17:33 +0530 | [diff] [blame] | 295 | var tax = frappe.get_doc(cdt, cdn); |
Anand Doshi | 923d41d | 2013-05-28 17:23:36 +0530 | [diff] [blame] | 296 | try { |
| 297 | this.validate_on_previous_row(tax); |
| 298 | this.calculate_taxes_and_totals(); |
| 299 | } catch(e) { |
| 300 | tax.row_id = null; |
| 301 | refresh_field("row_id", tax.name, tax.parentfield); |
| 302 | throw e; |
| 303 | } |
| 304 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 305 | |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 306 | set_dynamic_labels: function() { |
| 307 | // What TODO? should we make price list system non-mandatory? |
| 308 | this.frm.toggle_reqd("plc_conversion_rate", |
| 309 | !!(this.frm.doc.price_list_name && this.frm.doc.price_list_currency)); |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 310 | |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 311 | var company_currency = this.get_company_currency(); |
| 312 | this.change_form_labels(company_currency); |
| 313 | this.change_grid_labels(company_currency); |
Anand Doshi | 5013dcb | 2013-08-05 12:16:04 +0530 | [diff] [blame] | 314 | this.frm.refresh_fields(); |
Anand Doshi | 61a2f68 | 2013-06-21 17:55:31 +0530 | [diff] [blame] | 315 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 316 | |
Anand Doshi | 923d41d | 2013-05-28 17:23:36 +0530 | [diff] [blame] | 317 | recalculate: function() { |
| 318 | this.calculate_taxes_and_totals(); |
| 319 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 320 | |
Anand Doshi | 923d41d | 2013-05-28 17:23:36 +0530 | [diff] [blame] | 321 | recalculate_values: function() { |
| 322 | this.calculate_taxes_and_totals(); |
| 323 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 324 | |
Anand Doshi | d0b0072 | 2013-05-28 18:54:48 +0530 | [diff] [blame] | 325 | calculate_charges: function() { |
| 326 | this.calculate_taxes_and_totals(); |
| 327 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 328 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 329 | included_in_print_rate: function(doc, cdt, cdn) { |
Rushabh Mehta | 66d52b5 | 2014-03-27 14:17:33 +0530 | [diff] [blame] | 330 | var tax = frappe.get_doc(cdt, cdn); |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 331 | try { |
| 332 | this.validate_on_previous_row(tax); |
| 333 | this.validate_inclusive_tax(tax); |
| 334 | this.calculate_taxes_and_totals(); |
| 335 | } catch(e) { |
| 336 | tax.included_in_print_rate = 0; |
| 337 | refresh_field("included_in_print_rate", tax.name, tax.parentfield); |
| 338 | throw e; |
| 339 | } |
| 340 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 341 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 342 | validate_on_previous_row: function(tax) { |
| 343 | // validate if a valid row id is mentioned in case of |
| 344 | // On Previous Row Amount and On Previous Row Total |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 345 | if((["On Previous Row Amount", "On Previous Row Total"].indexOf(tax.charge_type) != -1) && |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 346 | (!tax.row_id || cint(tax.row_id) >= tax.idx)) { |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 347 | var msg = __("Please specify a valid Row ID for row {0} in table {1}", [tax.idx, __(tax.doctype)]) |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 348 | frappe.throw(msg); |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 349 | } |
| 350 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 351 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 352 | validate_inclusive_tax: function(tax) { |
| 353 | if(!this.frm.tax_doclist) this.frm.tax_doclist = this.get_tax_doclist(); |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 354 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 355 | var actual_type_error = function() { |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 356 | var msg = __("Actual type tax cannot be included in Item rate in row {0}", [tax.idx]) |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 357 | frappe.throw(msg); |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 358 | }; |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 359 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 360 | var on_previous_row_error = function(row_range) { |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 361 | var msg = __("For row {0} in {1}. To include {2} in Item rate, rows {3} must also be included", |
| 362 | [tax.idx, __(tax.doctype), tax.charge_type, row_range]) |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 363 | frappe.throw(msg); |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 364 | }; |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 365 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 366 | if(cint(tax.included_in_print_rate)) { |
| 367 | if(tax.charge_type == "Actual") { |
| 368 | // inclusive tax cannot be of type Actual |
| 369 | actual_type_error(); |
| 370 | } else if(tax.charge_type == "On Previous Row Amount" && |
| 371 | !cint(this.frm.tax_doclist[tax.row_id - 1].included_in_print_rate)) { |
| 372 | // referred row should also be an inclusive tax |
| 373 | on_previous_row_error(tax.row_id); |
| 374 | } else if(tax.charge_type == "On Previous Row Total") { |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 375 | var taxes_not_included = $.map(this.frm.tax_doclist.slice(0, tax.row_id), |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 376 | function(t) { return cint(t.included_in_print_rate) ? null : t; }); |
| 377 | if(taxes_not_included.length > 0) { |
| 378 | // all rows above this tax should be inclusive |
| 379 | on_previous_row_error(tax.row_id == 1 ? "1" : "1 - " + tax.row_id); |
| 380 | } |
| 381 | } |
| 382 | } |
| 383 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 384 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 385 | _load_item_tax_rate: function(item_tax_rate) { |
| 386 | return item_tax_rate ? JSON.parse(item_tax_rate) : {}; |
| 387 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 388 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 389 | _get_tax_rate: function(tax, item_tax_map) { |
| 390 | return (keys(item_tax_map).indexOf(tax.account_head) != -1) ? |
| 391 | flt(item_tax_map[tax.account_head], precision("rate", tax)) : |
| 392 | tax.rate; |
| 393 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 394 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 395 | get_item_wise_taxes_html: function() { |
| 396 | var item_tax = {}; |
| 397 | var tax_accounts = []; |
| 398 | var company_currency = this.get_company_currency(); |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 399 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 400 | $.each(this.get_tax_doclist(), function(i, tax) { |
| 401 | var tax_amount_precision = precision("tax_amount", tax); |
Anand Doshi | 53b7342 | 2013-05-31 11:50:01 +0530 | [diff] [blame] | 402 | var tax_rate_precision = precision("rate", tax); |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 403 | $.each(JSON.parse(tax.item_wise_tax_detail || '{}'), |
Anand Doshi | 53b7342 | 2013-05-31 11:50:01 +0530 | [diff] [blame] | 404 | function(item_code, tax_data) { |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 405 | if(!item_tax[item_code]) item_tax[item_code] = {}; |
Anand Doshi | 53b7342 | 2013-05-31 11:50:01 +0530 | [diff] [blame] | 406 | if($.isArray(tax_data)) { |
Anand Doshi | 1e4fb68 | 2013-08-23 12:56:33 +0530 | [diff] [blame] | 407 | var tax_rate = ""; |
| 408 | if(tax_data[0] != null) { |
| 409 | tax_rate = (tax.charge_type === "Actual") ? |
| 410 | format_currency(flt(tax_data[0], tax_amount_precision), company_currency, tax_amount_precision) : |
| 411 | (flt(tax_data[0], tax_rate_precision) + "%"); |
| 412 | } |
| 413 | var tax_amount = format_currency(flt(tax_data[1], tax_amount_precision), company_currency, |
| 414 | tax_amount_precision); |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 415 | |
Anand Doshi | aa71b5b | 2013-08-05 13:00:53 +0530 | [diff] [blame] | 416 | item_tax[item_code][tax.name] = [tax_rate, tax_amount]; |
Anand Doshi | 53b7342 | 2013-05-31 11:50:01 +0530 | [diff] [blame] | 417 | } else { |
Anand Doshi | aa71b5b | 2013-08-05 13:00:53 +0530 | [diff] [blame] | 418 | item_tax[item_code][tax.name] = [flt(tax_data, tax_rate_precision) + "%", ""]; |
Anand Doshi | 53b7342 | 2013-05-31 11:50:01 +0530 | [diff] [blame] | 419 | } |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 420 | }); |
Anand Doshi | aa71b5b | 2013-08-05 13:00:53 +0530 | [diff] [blame] | 421 | tax_accounts.push([tax.name, tax.account_head]); |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 422 | }); |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 423 | |
| 424 | var headings = $.map([__("Item Name")].concat($.map(tax_accounts, function(head) { return head[1]; })), |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 425 | function(head) { return '<th style="min-width: 100px;">' + (head || "") + "</th>" }).join("\n"); |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 426 | |
Anand Doshi | 179e377 | 2013-09-05 16:53:57 +0530 | [diff] [blame] | 427 | var distinct_item_names = []; |
| 428 | var distinct_items = []; |
| 429 | $.each(this.get_item_doclist(), function(i, item) { |
| 430 | if(distinct_item_names.indexOf(item.item_code || item.item_name)===-1) { |
| 431 | distinct_item_names.push(item.item_code || item.item_name); |
| 432 | distinct_items.push(item); |
| 433 | } |
| 434 | }); |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 435 | |
Anand Doshi | 179e377 | 2013-09-05 16:53:57 +0530 | [diff] [blame] | 436 | var rows = $.map(distinct_items, function(item) { |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 437 | var item_tax_record = item_tax[item.item_code || item.item_name]; |
Anand Doshi | 53b7342 | 2013-05-31 11:50:01 +0530 | [diff] [blame] | 438 | if(!item_tax_record) { return null; } |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 439 | return repl("<tr><td>%(item_name)s</td>%(taxes)s</tr>", { |
| 440 | item_name: item.item_name, |
| 441 | taxes: $.map(tax_accounts, function(head) { |
Anand Doshi | aa71b5b | 2013-08-05 13:00:53 +0530 | [diff] [blame] | 442 | return item_tax_record[head[0]] ? |
| 443 | "<td>(" + item_tax_record[head[0]][0] + ") " + item_tax_record[head[0]][1] + "</td>" : |
Anand Doshi | 64f316b | 2013-07-17 15:12:22 +0530 | [diff] [blame] | 444 | "<td></td>"; |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 445 | }).join("\n") |
| 446 | }); |
| 447 | }).join("\n"); |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 448 | |
Anand Doshi | 53b7342 | 2013-05-31 11:50:01 +0530 | [diff] [blame] | 449 | if(!rows) return ""; |
Rushabh Mehta | 7d8b189 | 2013-11-08 16:27:18 +0530 | [diff] [blame] | 450 | return '<p><a href="#" onclick="$(\'.tax-break-up\').toggleClass(\'hide\'); return false;">Show / Hide tax break-up</a><br><br></p>\ |
| 451 | <div class="tax-break-up hide" style="overflow-x: auto;"><table class="table table-bordered table-hover">\ |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 452 | <thead><tr>' + headings + '</tr></thead> \ |
| 453 | <tbody>' + rows + '</tbody> \ |
| 454 | </table></div>'; |
| 455 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 456 | |
Nabin Hait | 139dc7b | 2014-02-12 14:53:18 +0530 | [diff] [blame] | 457 | validate_company_and_party: function() { |
Anand Doshi | 923d41d | 2013-05-28 17:23:36 +0530 | [diff] [blame] | 458 | var me = this; |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 459 | var valid = true; |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 460 | |
Nabin Hait | 0f23106 | 2014-02-20 11:27:47 +0530 | [diff] [blame] | 461 | $.each(["company", "customer"], function(i, fieldname) { |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 462 | if(frappe.meta.has_field(me.frm.doc.doctype, fieldname)) { |
Nabin Hait | 139dc7b | 2014-02-12 14:53:18 +0530 | [diff] [blame] | 463 | if (!me.frm.doc[fieldname]) { |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 464 | msgprint(__("Please specify") + ": " + |
| 465 | frappe.meta.get_label(me.frm.doc.doctype, fieldname, me.frm.doc.name) + |
Pratik Vyas | b52618c | 2014-04-14 16:25:30 +0530 | [diff] [blame] | 466 | ". " + __("It is needed to fetch Item Details.")); |
Nabin Hait | 139dc7b | 2014-02-12 14:53:18 +0530 | [diff] [blame] | 467 | valid = false; |
| 468 | } |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 469 | } |
| 470 | }); |
| 471 | return valid; |
| 472 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 473 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 474 | get_item_doclist: function() { |
Rushabh Mehta | aa355af | 2014-03-26 18:24:30 +0530 | [diff] [blame] | 475 | return this.frm.doc[this.fname] || []; |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 476 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 477 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 478 | get_tax_doclist: function() { |
Rushabh Mehta | aa355af | 2014-03-26 18:24:30 +0530 | [diff] [blame] | 479 | return this.frm.doc[this.other_fname] || []; |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 480 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 481 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 482 | validate_conversion_rate: function() { |
| 483 | this.frm.doc.conversion_rate = flt(this.frm.doc.conversion_rate, precision("conversion_rate")); |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 484 | var conversion_rate_label = frappe.meta.get_label(this.frm.doc.doctype, "conversion_rate", |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 485 | this.frm.doc.name); |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 486 | var company_currency = this.get_company_currency(); |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 487 | |
Akhilesh Darjee | 1797cfe | 2013-10-11 13:34:10 +0530 | [diff] [blame] | 488 | if(!this.frm.doc.conversion_rate) { |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 489 | frappe.throw(repl('%(conversion_rate_label)s' + |
| 490 | __(' is mandatory. Maybe Currency Exchange record is not created for ') + |
| 491 | '%(from_currency)s' + __(" to ") + '%(to_currency)s', |
Akhilesh Darjee | e0b3282 | 2013-11-12 19:27:16 +0530 | [diff] [blame] | 492 | { |
| 493 | "conversion_rate_label": conversion_rate_label, |
Nabin Hait | e505fbe | 2013-11-15 13:38:23 +0530 | [diff] [blame] | 494 | "from_currency": this.frm.doc.currency, |
Akhilesh Darjee | e0b3282 | 2013-11-12 19:27:16 +0530 | [diff] [blame] | 495 | "to_currency": company_currency |
Nabin Hait | e505fbe | 2013-11-15 13:38:23 +0530 | [diff] [blame] | 496 | })); |
Akhilesh Darjee | 6773bc2 | 2013-09-17 11:56:17 +0530 | [diff] [blame] | 497 | } |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 498 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 499 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 500 | calculate_taxes_and_totals: function() { |
Akhilesh Darjee | 57738a0 | 2014-01-03 18:15:07 +0530 | [diff] [blame] | 501 | this.discount_amount_applied = false; |
| 502 | this._calculate_taxes_and_totals(); |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 503 | if (frappe.meta.get_docfield(this.frm.doc.doctype, "discount_amount")) |
Akhilesh Darjee | 57738a0 | 2014-01-03 18:15:07 +0530 | [diff] [blame] | 504 | this.apply_discount_amount(); |
| 505 | }, |
| 506 | |
| 507 | _calculate_taxes_and_totals: function() { |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 508 | this.validate_conversion_rate(); |
| 509 | this.frm.item_doclist = this.get_item_doclist(); |
| 510 | this.frm.tax_doclist = this.get_tax_doclist(); |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 511 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 512 | this.calculate_item_values(); |
| 513 | this.initialize_taxes(); |
| 514 | this.determine_exclusive_rate && this.determine_exclusive_rate(); |
| 515 | this.calculate_net_total(); |
| 516 | this.calculate_taxes(); |
| 517 | this.calculate_totals(); |
| 518 | this._cleanup(); |
Akhilesh Darjee | 57738a0 | 2014-01-03 18:15:07 +0530 | [diff] [blame] | 519 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 520 | this.show_item_wise_taxes(); |
| 521 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 522 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 523 | initialize_taxes: function() { |
| 524 | var me = this; |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 525 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 526 | $.each(this.frm.tax_doclist, function(i, tax) { |
| 527 | tax.item_wise_tax_detail = {}; |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 528 | tax_fields = ["total", "tax_amount_after_discount_amount", |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 529 | "tax_amount_for_current_item", "grand_total_for_current_item", |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 530 | "tax_fraction_for_current_item", "grand_total_fraction_for_current_item"] |
| 531 | |
Akhilesh Darjee | 57738a0 | 2014-01-03 18:15:07 +0530 | [diff] [blame] | 532 | if (!me.discount_amount_applied) |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 533 | tax_fields.push("tax_amount"); |
| 534 | |
| 535 | $.each(tax_fields, function(i, fieldname) { tax[fieldname] = 0.0 }); |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 536 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 537 | me.validate_on_previous_row(tax); |
| 538 | me.validate_inclusive_tax(tax); |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 539 | frappe.model.round_floats_in(tax); |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 540 | }); |
| 541 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 542 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 543 | calculate_taxes: function() { |
| 544 | var me = this; |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 545 | var actual_tax_dict = {}; |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 546 | |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 547 | // maintain actual tax rate based on idx |
| 548 | $.each(this.frm.tax_doclist, function(i, tax) { |
| 549 | if (tax.charge_type == "Actual") { |
| 550 | actual_tax_dict[tax.idx] = flt(tax.rate); |
| 551 | } |
| 552 | }); |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 553 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 554 | $.each(this.frm.item_doclist, function(n, item) { |
| 555 | var item_tax_map = me._load_item_tax_rate(item.item_tax_rate); |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 556 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 557 | $.each(me.frm.tax_doclist, function(i, tax) { |
| 558 | // tax_amount represents the amount of tax for the current step |
| 559 | var current_tax_amount = me.get_current_tax_amount(item, tax, item_tax_map); |
Anand Doshi | 53b7342 | 2013-05-31 11:50:01 +0530 | [diff] [blame] | 560 | |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 561 | // Adjust divisional loss to the last item |
| 562 | if (tax.charge_type == "Actual") { |
| 563 | actual_tax_dict[tax.idx] -= current_tax_amount; |
| 564 | if (n == me.frm.item_doclist.length - 1) { |
| 565 | current_tax_amount += actual_tax_dict[tax.idx] |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 566 | } |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 567 | } |
| 568 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 569 | // store tax_amount for current item as it will be used for |
| 570 | // charge type = 'On Previous Row Amount' |
| 571 | tax.tax_amount_for_current_item = current_tax_amount; |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 572 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 573 | // accumulate tax amount into tax.tax_amount |
Akhilesh Darjee | 57738a0 | 2014-01-03 18:15:07 +0530 | [diff] [blame] | 574 | if (!me.discount_amount_applied) |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 575 | tax.tax_amount += current_tax_amount; |
| 576 | |
Akhilesh Darjee | 57738a0 | 2014-01-03 18:15:07 +0530 | [diff] [blame] | 577 | tax.tax_amount_after_discount_amount += current_tax_amount; |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 578 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 579 | // for buying |
| 580 | if(tax.category) { |
| 581 | // if just for valuation, do not add the tax amount in total |
| 582 | // hence, setting it as 0 for further steps |
| 583 | current_tax_amount = (tax.category == "Valuation") ? 0.0 : current_tax_amount; |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 584 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 585 | current_tax_amount *= (tax.add_deduct_tax == "Deduct") ? -1.0 : 1.0; |
| 586 | } |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 587 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 588 | // Calculate tax.total viz. grand total till that step |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 589 | // note: grand_total_for_current_item contains the contribution of |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 590 | // item's amount, previously applied tax and the current tax on that item |
| 591 | if(i==0) { |
Nabin Hait | 1eb5601 | 2014-02-10 19:20:15 +0530 | [diff] [blame] | 592 | tax.grand_total_for_current_item = flt(item.base_amount + current_tax_amount, |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 593 | precision("total", tax)); |
| 594 | } else { |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 595 | tax.grand_total_for_current_item = |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 596 | flt(me.frm.tax_doclist[i-1].grand_total_for_current_item + current_tax_amount, |
| 597 | precision("total", tax)); |
| 598 | } |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 599 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 600 | // in tax.total, accumulate grand total for each item |
| 601 | tax.total += tax.grand_total_for_current_item; |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 602 | |
| 603 | // set precision in the last item iteration |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 604 | if (n == me.frm.item_doclist.length - 1) { |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 605 | me.round_off_totals(tax); |
| 606 | |
Akhilesh Darjee | 57738a0 | 2014-01-03 18:15:07 +0530 | [diff] [blame] | 607 | // adjust Discount Amount loss in last tax iteration |
| 608 | if ((i == me.frm.tax_doclist.length - 1) && me.discount_amount_applied) |
| 609 | me.adjust_discount_amount_loss(tax); |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 610 | } |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 611 | }); |
| 612 | }); |
| 613 | }, |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 614 | |
| 615 | round_off_totals: function(tax) { |
| 616 | tax.total = flt(tax.total, precision("total", tax)); |
| 617 | tax.tax_amount = flt(tax.tax_amount, precision("tax_amount", tax)); |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 618 | tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount, |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 619 | precision("tax_amount", tax)); |
| 620 | }, |
| 621 | |
Akhilesh Darjee | 57738a0 | 2014-01-03 18:15:07 +0530 | [diff] [blame] | 622 | adjust_discount_amount_loss: function(tax) { |
| 623 | var discount_amount_loss = this.frm.doc.grand_total - flt(this.frm.doc.discount_amount) - tax.total; |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 624 | tax.tax_amount_after_discount_amount = flt(tax.tax_amount_after_discount_amount + |
Akhilesh Darjee | 57738a0 | 2014-01-03 18:15:07 +0530 | [diff] [blame] | 625 | discount_amount_loss, precision("tax_amount", tax)); |
| 626 | tax.total = flt(tax.total + discount_amount_loss, precision("total", tax)); |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 627 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 628 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 629 | get_current_tax_amount: function(item, tax, item_tax_map) { |
| 630 | var tax_rate = this._get_tax_rate(tax, item_tax_map); |
| 631 | var current_tax_amount = 0.0; |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 632 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 633 | if(tax.charge_type == "Actual") { |
| 634 | // distribute the tax amount proportionally to each item row |
| 635 | var actual = flt(tax.rate, precision("tax_amount", tax)); |
| 636 | current_tax_amount = this.frm.doc.net_total ? |
Nabin Hait | 1eb5601 | 2014-02-10 19:20:15 +0530 | [diff] [blame] | 637 | ((item.base_amount / this.frm.doc.net_total) * actual) : |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 638 | 0.0; |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 639 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 640 | } else if(tax.charge_type == "On Net Total") { |
Nabin Hait | 1eb5601 | 2014-02-10 19:20:15 +0530 | [diff] [blame] | 641 | current_tax_amount = (tax_rate / 100.0) * item.base_amount; |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 642 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 643 | } else if(tax.charge_type == "On Previous Row Amount") { |
| 644 | current_tax_amount = (tax_rate / 100.0) * |
| 645 | this.frm.tax_doclist[cint(tax.row_id) - 1].tax_amount_for_current_item; |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 646 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 647 | } else if(tax.charge_type == "On Previous Row Total") { |
| 648 | current_tax_amount = (tax_rate / 100.0) * |
| 649 | this.frm.tax_doclist[cint(tax.row_id) - 1].grand_total_for_current_item; |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 650 | } |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 651 | |
Anand Doshi | 53b7342 | 2013-05-31 11:50:01 +0530 | [diff] [blame] | 652 | current_tax_amount = flt(current_tax_amount, precision("tax_amount", tax)); |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 653 | |
Anand Doshi | 53b7342 | 2013-05-31 11:50:01 +0530 | [diff] [blame] | 654 | // store tax breakup for each item |
| 655 | tax.item_wise_tax_detail[item.item_code || item.item_name] = [tax_rate, current_tax_amount]; |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 656 | |
Anand Doshi | 53b7342 | 2013-05-31 11:50:01 +0530 | [diff] [blame] | 657 | return current_tax_amount; |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 658 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 659 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 660 | _cleanup: function() { |
| 661 | $.each(this.frm.tax_doclist, function(i, tax) { |
| 662 | $.each(["tax_amount_for_current_item", "grand_total_for_current_item", |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 663 | "tax_fraction_for_current_item", "grand_total_fraction_for_current_item"], |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 664 | function(i, fieldname) { delete tax[fieldname]; }); |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 665 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 666 | tax.item_wise_tax_detail = JSON.stringify(tax.item_wise_tax_detail); |
| 667 | }); |
| 668 | }, |
Anand Doshi | fc77718 | 2013-05-27 19:29:07 +0530 | [diff] [blame] | 669 | |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 670 | calculate_total_advance: function(parenttype, advance_parentfield, update_paid_amount) { |
Anand Doshi | fc77718 | 2013-05-27 19:29:07 +0530 | [diff] [blame] | 671 | if(this.frm.doc.doctype == parenttype && this.frm.doc.docstatus < 2) { |
Rushabh Mehta | aa355af | 2014-03-26 18:24:30 +0530 | [diff] [blame] | 672 | var advance_doclist = this.frm.doc[advance_parentfield] || []; |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 673 | this.frm.doc.total_advance = flt(frappe.utils.sum( |
Anand Doshi | fc77718 | 2013-05-27 19:29:07 +0530 | [diff] [blame] | 674 | $.map(advance_doclist, function(adv) { return adv.allocated_amount }) |
| 675 | ), precision("total_advance")); |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 676 | |
Anand Doshi | 652bc07 | 2014-04-16 15:21:46 +0530 | [diff] [blame] | 677 | this.calculate_outstanding_amount(update_paid_amount); |
Anand Doshi | fc77718 | 2013-05-27 19:29:07 +0530 | [diff] [blame] | 678 | } |
| 679 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 680 | |
Anand Doshi | 3543f30 | 2013-05-24 19:25:01 +0530 | [diff] [blame] | 681 | _set_in_company_currency: function(item, print_field, base_field) { |
| 682 | // set values in base currency |
| 683 | item[base_field] = flt(item[print_field] * this.frm.doc.conversion_rate, |
| 684 | precision(base_field, item)); |
| 685 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 686 | |
Anand Doshi | bf3e54a | 2013-06-05 14:11:32 +0530 | [diff] [blame] | 687 | get_terms: function() { |
| 688 | var me = this; |
| 689 | if(this.frm.doc.tc_name) { |
Anand Doshi | 1fac2a9 | 2013-07-29 19:30:39 +0530 | [diff] [blame] | 690 | return this.frm.call({ |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 691 | method: "frappe.client.get_value", |
Anand Doshi | bf3e54a | 2013-06-05 14:11:32 +0530 | [diff] [blame] | 692 | args: { |
| 693 | doctype: "Terms and Conditions", |
| 694 | fieldname: "terms", |
| 695 | filters: { name: this.frm.doc.tc_name }, |
| 696 | }, |
| 697 | }); |
| 698 | } |
| 699 | }, |
Akhilesh Darjee | 4f72156 | 2014-01-29 16:31:38 +0530 | [diff] [blame] | 700 | |
| 701 | taxes_and_charges: function() { |
| 702 | var me = this; |
| 703 | if(this.frm.doc.taxes_and_charges) { |
| 704 | return this.frm.call({ |
Nabin Hait | 6b03914 | 2014-05-02 15:45:10 +0530 | [diff] [blame] | 705 | method: "erpnext.controllers.accounts_controller.get_taxes_and_charges", |
| 706 | args: { |
| 707 | "master_doctype": "Sales Taxes and Charges Master", |
| 708 | "master_name": this.frm.doc.taxes_and_charges, |
| 709 | "tax_parentfield": this.other_fname |
| 710 | }, |
Akhilesh Darjee | 4f72156 | 2014-01-29 16:31:38 +0530 | [diff] [blame] | 711 | callback: function(r) { |
| 712 | if(!r.exc) { |
Nabin Hait | 6b03914 | 2014-05-02 15:45:10 +0530 | [diff] [blame] | 713 | me.frm.set_value(me.other_fname, r.message); |
Akhilesh Darjee | 4f72156 | 2014-01-29 16:31:38 +0530 | [diff] [blame] | 714 | me.calculate_taxes_and_totals(); |
| 715 | } |
| 716 | } |
| 717 | }); |
Nabin Hait | bc83b9c | 2014-05-02 17:03:18 +0530 | [diff] [blame] | 718 | } |
Akhilesh Darjee | 4f72156 | 2014-01-29 16:31:38 +0530 | [diff] [blame] | 719 | }, |
| 720 | |
| 721 | show_item_wise_taxes: function() { |
| 722 | if(this.frm.fields_dict.other_charges_calculation) { |
| 723 | $(this.get_item_wise_taxes_html()) |
| 724 | .appendTo($(this.frm.fields_dict.other_charges_calculation.wrapper).empty()); |
| 725 | } |
| 726 | }, |
Rushabh Mehta | ff93802 | 2014-04-15 18:40:00 +0530 | [diff] [blame] | 727 | }); |