blob: 0002f66259cd3146cc33f94040c82fd160b9c0a2 [file] [log] [blame]
Anand Doshi3543f302013-05-24 19:25:01 +05301// ERPNext - web based ERP (http://erpnext.com)
2// Copyright (C) 2012 Web Notes Technologies Pvt Ltd
3//
4// This program is free software: you can redistribute it and/or modify
5// it under the terms of the GNU General Public License as published by
6// the Free Software Foundation, either version 3 of the License, or
7// (at your option) any later version.
8//
9// This program is distributed in the hope that it will be useful,
10// but WITHOUT ANY WARRANTY; without even the implied warranty of
11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12// GNU General Public License for more details.
13//
14// You should have received a copy of the GNU General Public License
15// along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17wn.provide("erpnext");
18
19erpnext.TransactionController = wn.ui.form.Controller.extend({
20 onload: function() {
21 if(this.frm.doc.__islocal) {
22 var me = this,
23 today = get_today(),
24 currency = wn.defaults.get_default("currency");
25
26 $.each({
Anand Doshifc777182013-05-27 19:29:07 +053027 posting_date: today,
28 due_date: today,
29 transaction_date: today,
30 currency: currency,
31 price_list_currency: currency,
32 status: "Draft",
33 company: wn.defaults.get_default("company"),
34 fiscal_year: wn.defaults.get_default("fiscal_year"),
35 is_subcontracted: "No",
36 conversion_rate: 1.0,
37 plc_conversion_rate: 1.0
Anand Doshi3543f302013-05-24 19:25:01 +053038 }, function(fieldname, value) {
39 if(me.frm.fields_dict[fieldname] && !me.frm.doc[fieldname])
40 me.frm.set_value(fieldname, value);
41 });
42 }
43 },
44
45 refresh: function() {
46 this.frm.clear_custom_buttons();
47 erpnext.hide_naming_series();
48 this.show_item_wise_taxes();
Anand Doshi923d41d2013-05-28 17:23:36 +053049 this.frm.fields_dict.currency ? this.currency() : this.set_dynamic_labels();
Anand Doshi3543f302013-05-24 19:25:01 +053050 },
51
52 onload_post_render: function() {
53 if(this.frm.doc.__islocal && this.frm.doc.company) {
54 var me = this;
55 this.frm.call({
56 doc: this.frm.doc,
57 method: "onload_post_render",
58 freeze: true,
59 callback: function(r) {
60 // remove this call when using client side mapper
61 me.set_default_values();
62 me.frm.refresh();
63 }
64 });
65 }
66 },
67
Anand Doshi923d41d2013-05-28 17:23:36 +053068 validate: function() {
69 this.calculate_taxes_and_totals();
70 },
71
Anand Doshi3543f302013-05-24 19:25:01 +053072 company: function() {
Anand Doshid52b03a2013-06-21 12:22:52 +053073 if(this.frm.doc.company && this.frm.fields_dict.currency) {
Anand Doshi3543f302013-05-24 19:25:01 +053074 var me = this;
75 var company_currency = this.get_company_currency();
76 $.each(["currency", "price_list_currency"], function(i, fieldname) {
77 if(!me.doc[fieldname]) {
78 me.frm.set_value(fieldname, company_currency);
Anand Doshi61a2f682013-06-21 17:55:31 +053079 me[fieldname]();
Anand Doshi3543f302013-05-24 19:25:01 +053080 }
81 });
Anand Doshi3543f302013-05-24 19:25:01 +053082 }
83 },
84
85 get_company_currency: function() {
86 return erpnext.get_currency(this.frm.doc.company);
87 },
88
89 currency: function() {
Anand Doshi61a2f682013-06-21 17:55:31 +053090 var me = this;
91 this.set_dynamic_labels();
Anand Doshid52b03a2013-06-21 12:22:52 +053092
Anand Doshi61a2f682013-06-21 17:55:31 +053093 var company_currency = this.get_company_currency();
94 if(this.frm.doc.currency !== company_currency) {
95 this.get_exchange_rate(this.frm.doc.currency, company_currency,
96 function(exchange_rate) {
97 if(exchange_rate) {
98 me.frm.set_value("conversion_rate", exchange_rate);
99 me.conversion_rate();
100 }
101 });
102 } else {
103 this.conversion_rate();
104 }
105 },
106
107 conversion_rate: function() {
108 if(this.frm.doc.currency === this.get_company_currency() &&
109 this.frm.doc.conversion_rate !== 1.0) {
110 this.frm.set_value("conversion_rate", 1.0);
111 } else if(this.frm.doc.currency === this.frm.doc.price_list_currency &&
112 this.frm.doc.plc_conversion_rate !== this.frm.doc.conversion_rate) {
113 this.frm.set_value("plc_conversion_rate", this.frm.doc.conversion_rate);
114 }
115
116 this.calculate_taxes_and_totals();
Anand Doshi3543f302013-05-24 19:25:01 +0530117 },
118
Anand Doshi060d9242013-06-12 17:40:36 +0530119 price_list_name: function(buying_or_selling) {
Anand Doshi3543f302013-05-24 19:25:01 +0530120 var me = this;
121 if(this.frm.doc.price_list_name) {
122 this.frm.call({
123 method: "setup.utils.get_price_list_currency",
Anand Doshi61a2f682013-06-21 17:55:31 +0530124 args: { args: {
Anand Doshi3543f302013-05-24 19:25:01 +0530125 price_list_name: this.frm.doc.price_list_name,
Anand Doshi060d9242013-06-12 17:40:36 +0530126 buying_or_selling: buying_or_selling
Anand Doshi3543f302013-05-24 19:25:01 +0530127 }},
128 callback: function(r) {
129 if(!r.exc) {
130 me.price_list_currency();
131 }
132 }
133 });
134 }
135 },
136
Anand Doshi61a2f682013-06-21 17:55:31 +0530137 get_exchange_rate: function(from_currency, to_currency, callback) {
138 var exchange_name = from_currency + "-" + to_currency;
139 wn.model.with_doc("Currency Exchange", exchange_name, function(name) {
140 var exchange_doc = wn.model.get_doc("Currency Exchange", exchange_name);
141 callback(exchange_doc ? flt(exchange_doc.exchange_rate)) : 0);
142 });
143 },
144
Anand Doshi3543f302013-05-24 19:25:01 +0530145 price_list_currency: function() {
Anand Doshi3543f302013-05-24 19:25:01 +0530146 this.set_dynamic_labels();
Anand Doshi61a2f682013-06-21 17:55:31 +0530147
148 var company_currency = this.get_company_currency();
149 if(this.frm.doc.price_list_currency !== company_currency) {
150 this.get_exchange_rate(this.frm.doc.price_list_currency, company_currency,
151 function(exchange_rate) {
152 if(exchange_rate) {
153 me.frm.set_value("price_list_currency", exchange_rate);
154 me.plc_conversion_rate();
155 }
156 });
157 } else {
158 this.plc_conversion_rate();
159 }
Anand Doshi3543f302013-05-24 19:25:01 +0530160 },
161
162 plc_conversion_rate: function() {
Anand Doshi61a2f682013-06-21 17:55:31 +0530163 if(this.frm.doc.price_list_currency === this.get_company_currency()) {
164 this.frm.set_value("plc_conversion_rate", 1.0);
165 } else if(this.frm.doc.price_list_currency === this.frm.doc.currency) {
166 this.frm.set_value("conversion_rate", this.frm.doc.plc_conversion_rate);
167 this.calculate_taxes_and_totals();
168 }
Anand Doshi3543f302013-05-24 19:25:01 +0530169 },
170
171 qty: function(doc, cdt, cdn) {
172 this.calculate_taxes_and_totals();
173 },
174
Anand Doshi923d41d2013-05-28 17:23:36 +0530175 tax_rate: function(doc, cdt, cdn) {
176 this.calculate_taxes_and_totals();
177 },
178
179 row_id: function(doc, cdt, cdn) {
180 var tax = wn.model.get_doc(cdt, cdn);
181 try {
182 this.validate_on_previous_row(tax);
183 this.calculate_taxes_and_totals();
184 } catch(e) {
185 tax.row_id = null;
186 refresh_field("row_id", tax.name, tax.parentfield);
187 throw e;
188 }
189 },
190
Anand Doshi61a2f682013-06-21 17:55:31 +0530191 set_dynamic_labels: function() {
192 // What TODO? should we make price list system non-mandatory?
193 this.frm.toggle_reqd("plc_conversion_rate",
194 !!(this.frm.doc.price_list_name && this.frm.doc.price_list_currency));
195
196 var company_currency = this.get_company_currency();
197 this.change_form_labels(company_currency);
198 this.change_grid_labels(company_currency);
199 },
200
Anand Doshi923d41d2013-05-28 17:23:36 +0530201 recalculate: function() {
202 this.calculate_taxes_and_totals();
203 },
204
205 recalculate_values: function() {
206 this.calculate_taxes_and_totals();
207 },
208
Anand Doshid0b00722013-05-28 18:54:48 +0530209 calculate_charges: function() {
210 this.calculate_taxes_and_totals();
211 },
212
Anand Doshi3543f302013-05-24 19:25:01 +0530213 included_in_print_rate: function(doc, cdt, cdn) {
214 var tax = wn.model.get_doc(cdt, cdn);
215 try {
216 this.validate_on_previous_row(tax);
217 this.validate_inclusive_tax(tax);
218 this.calculate_taxes_and_totals();
219 } catch(e) {
220 tax.included_in_print_rate = 0;
221 refresh_field("included_in_print_rate", tax.name, tax.parentfield);
222 throw e;
223 }
224 },
225
226 validate_on_previous_row: function(tax) {
227 // validate if a valid row id is mentioned in case of
228 // On Previous Row Amount and On Previous Row Total
229 if((["On Previous Row Amount", "On Previous Row Total"].indexOf(tax.charge_type) != -1) &&
230 (!tax.row_id || cint(tax.row_id) >= tax.idx)) {
231 var msg = repl(wn._("Row") + " # %(idx)s [%(doctype)s]: " +
232 wn._("Please specify a valid") + " %(row_id_label)s", {
233 idx: tax.idx,
234 doctype: tax.doctype,
235 row_id_label: wn.meta.get_label(tax.doctype, "row_id", tax.name)
236 });
237 msgprint(msg);
238 throw msg;
239 }
240 },
241
242 validate_inclusive_tax: function(tax) {
243 if(!this.frm.tax_doclist) this.frm.tax_doclist = this.get_tax_doclist();
244
245 var actual_type_error = function() {
246 var msg = repl(wn._("For row") + " # %(idx)s [%(doctype)s]: " +
247 "%(charge_type_label)s = \"%(charge_type)s\" " +
248 wn._("cannot be included in Item's rate"), {
249 idx: tax.idx,
250 doctype: tax.doctype,
251 charge_type_label: wn.meta.get_label(tax.doctype, "charge_type", tax.name),
252 charge_type: tax.charge_type
253 });
254 msgprint(msg);
255 throw msg;
256 };
257
258 var on_previous_row_error = function(row_range) {
259 var msg = repl(wn._("For row") + " # %(idx)s [%(doctype)s]: " +
260 wn._("to be included in Item's rate, it is required that: ") +
261 " [" + wn._("Row") + " # %(row_range)s] " + wn._("also be included in Item's rate"), {
262 idx: tax.idx,
263 doctype: tax.doctype,
264 charge_type_label: wn.meta.get_label(tax.doctype, "charge_type", tax.name),
265 charge_type: tax.charge_type,
266 inclusive_label: wn.meta.get_label(tax.doctype, "included_in_print_rate", tax.name),
267 row_range: row_range,
268 });
269
270 msgprint(msg);
271 throw msg;
272 };
273
274 if(cint(tax.included_in_print_rate)) {
275 if(tax.charge_type == "Actual") {
276 // inclusive tax cannot be of type Actual
277 actual_type_error();
278 } else if(tax.charge_type == "On Previous Row Amount" &&
279 !cint(this.frm.tax_doclist[tax.row_id - 1].included_in_print_rate)) {
280 // referred row should also be an inclusive tax
281 on_previous_row_error(tax.row_id);
282 } else if(tax.charge_type == "On Previous Row Total") {
283 var taxes_not_included = $.map(this.frm.tax_doclist.slice(0, tax.row_id),
284 function(t) { return cint(t.included_in_print_rate) ? null : t; });
285 if(taxes_not_included.length > 0) {
286 // all rows above this tax should be inclusive
287 on_previous_row_error(tax.row_id == 1 ? "1" : "1 - " + tax.row_id);
288 }
289 }
290 }
291 },
292
293 _load_item_tax_rate: function(item_tax_rate) {
294 return item_tax_rate ? JSON.parse(item_tax_rate) : {};
295 },
296
297 _get_tax_rate: function(tax, item_tax_map) {
298 return (keys(item_tax_map).indexOf(tax.account_head) != -1) ?
299 flt(item_tax_map[tax.account_head], precision("rate", tax)) :
300 tax.rate;
301 },
302
303 get_item_wise_taxes_html: function() {
304 var item_tax = {};
305 var tax_accounts = [];
306 var company_currency = this.get_company_currency();
307
308 $.each(this.get_tax_doclist(), function(i, tax) {
309 var tax_amount_precision = precision("tax_amount", tax);
Anand Doshi53b73422013-05-31 11:50:01 +0530310 var tax_rate_precision = precision("rate", tax);
Anand Doshi3543f302013-05-24 19:25:01 +0530311 $.each(JSON.parse(tax.item_wise_tax_detail || '{}'),
Anand Doshi53b73422013-05-31 11:50:01 +0530312 function(item_code, tax_data) {
Anand Doshi3543f302013-05-24 19:25:01 +0530313 if(!item_tax[item_code]) item_tax[item_code] = {};
Anand Doshi53b73422013-05-31 11:50:01 +0530314 if($.isArray(tax_data)) {
315 var tax_rate = tax_data[0] == null ? "" : (flt(tax_data[0], tax_rate_precision) + "%"),
316 tax_amount = format_currency(flt(tax_data[1], tax_amount_precision), company_currency);
317
318 item_tax[item_code][tax.account_head] = [tax_rate, tax_amount];
319 } else {
320 item_tax[item_code][tax.account_head] = [flt(tax_data, tax_rate_precision) + "%", ""];
321 }
Anand Doshi3543f302013-05-24 19:25:01 +0530322 });
323 tax_accounts.push(tax.account_head);
324 });
325
326 var headings = $.map([wn._("Item Name")].concat(tax_accounts),
327 function(head) { return '<th style="min-width: 100px;">' + (head || "") + "</th>" }).join("\n");
328
329 var rows = $.map(this.get_item_doclist(), function(item) {
330 var item_tax_record = item_tax[item.item_code || item.item_name];
Anand Doshi53b73422013-05-31 11:50:01 +0530331 if(!item_tax_record) { return null; }
Anand Doshi3543f302013-05-24 19:25:01 +0530332 return repl("<tr><td>%(item_name)s</td>%(taxes)s</tr>", {
333 item_name: item.item_name,
334 taxes: $.map(tax_accounts, function(head) {
Anand Doshi53b73422013-05-31 11:50:01 +0530335 return "<td>(" + item_tax_record[head][0] + ") " + item_tax_record[head][1] + "</td>"
Anand Doshi3543f302013-05-24 19:25:01 +0530336 }).join("\n")
337 });
338 }).join("\n");
339
Anand Doshi53b73422013-05-31 11:50:01 +0530340 if(!rows) return "";
Anand Doshi3543f302013-05-24 19:25:01 +0530341 return '<div style="overflow-x: scroll;"><table class="table table-bordered table-hover">\
342 <thead><tr>' + headings + '</tr></thead> \
343 <tbody>' + rows + '</tbody> \
344 </table></div>';
345 },
346
347 set_default_values: function() {
348 $.each(wn.model.get_doclist(this.frm.doctype, this.frm.docname), function(i, doc) {
349 var updated = wn.model.set_default_values(doc);
350 if(doc.parentfield) {
351 refresh_field(doc.parentfield);
352 } else {
353 refresh_field(updated);
354 }
355 });
356 },
357
Anand Doshi923d41d2013-05-28 17:23:36 +0530358 _validate_before_fetch: function(fieldname) {
359 var me = this;
360 if(!me.frm.doc[fieldname]) {
361 return (wn._("Please specify") + ": " +
362 wn.meta.get_label(me.frm.doc.doctype, fieldname, me.frm.doc.name) +
363 ". " + wn._("It is needed to fetch Item Details."));
364 }
365 return null;
366 },
367
Anand Doshi3543f302013-05-24 19:25:01 +0530368 validate_company_and_party: function(party_field) {
Anand Doshi923d41d2013-05-28 17:23:36 +0530369 var me = this;
Anand Doshi3543f302013-05-24 19:25:01 +0530370 var valid = true;
Anand Doshi923d41d2013-05-28 17:23:36 +0530371 var msg = "";
Anand Doshi3543f302013-05-24 19:25:01 +0530372 $.each(["company", party_field], function(i, fieldname) {
Anand Doshi923d41d2013-05-28 17:23:36 +0530373 var msg_for_fieldname = me._validate_before_fetch(fieldname);
374 if(msg_for_fieldname) {
375 msgprint(msg_for_fieldname);
Anand Doshi3543f302013-05-24 19:25:01 +0530376 valid = false;
Anand Doshi3543f302013-05-24 19:25:01 +0530377 }
378 });
379 return valid;
380 },
381
382 get_item_doclist: function() {
383 return wn.model.get_doclist(this.frm.doc.doctype, this.frm.doc.name,
384 {parentfield: this.fname});
385 },
386
387 get_tax_doclist: function() {
388 return wn.model.get_doclist(this.frm.doc.doctype, this.frm.doc.name,
389 {parentfield: this.other_fname});
390 },
391
392 validate_conversion_rate: function() {
393 this.frm.doc.conversion_rate = flt(this.frm.doc.conversion_rate, precision("conversion_rate"));
394 var conversion_rate_label = wn.meta.get_label(this.frm.doc.doctype, "conversion_rate",
395 this.frm.doc.name);
396
397 if(this.frm.doc.conversion_rate == 0) {
398 wn.throw(wn._(conversion_rate_label) + " " + wn._("cannot be 0"));
399 }
400
401 var company_currency = this.get_company_currency();
Anand Doshi923d41d2013-05-28 17:23:36 +0530402 var valid_conversion_rate = this.frm.doc.conversion_rate ?
Anand Doshi3543f302013-05-24 19:25:01 +0530403 ((this.frm.doc.currency == company_currency && this.frm.doc.conversion_rate == 1.0) ||
404 (this.frm.doc.currency != company_currency && this.frm.doc.conversion_rate != 1.0)) :
405 false;
406
407 if(!valid_conversion_rate) {
408 wn.throw(wn._("Please enter valid") + " " + wn._(conversion_rate_label) +
409 " 1 " + this.frm.doc.currency + " = [?] " + company_currency);
410 }
411 },
412
413 calculate_taxes_and_totals: function() {
414 this.validate_conversion_rate();
415 this.frm.item_doclist = this.get_item_doclist();
416 this.frm.tax_doclist = this.get_tax_doclist();
417
418 this.calculate_item_values();
419 this.initialize_taxes();
420 this.determine_exclusive_rate && this.determine_exclusive_rate();
421 this.calculate_net_total();
422 this.calculate_taxes();
423 this.calculate_totals();
424 this._cleanup();
Anand Doshi923d41d2013-05-28 17:23:36 +0530425
Anand Doshi3543f302013-05-24 19:25:01 +0530426 this.show_item_wise_taxes();
427 },
428
429 initialize_taxes: function() {
430 var me = this;
431 $.each(this.frm.tax_doclist, function(i, tax) {
432 tax.item_wise_tax_detail = {};
433 $.each(["tax_amount", "total",
434 "tax_amount_for_current_item", "grand_total_for_current_item",
435 "tax_fraction_for_current_item", "grand_total_fraction_for_current_item"],
436 function(i, fieldname) { tax[fieldname] = 0.0 });
437
438 me.validate_on_previous_row(tax);
439 me.validate_inclusive_tax(tax);
440 wn.model.round_floats_in(tax);
441 });
442 },
443
444 calculate_taxes: function() {
445 var me = this;
446
447 $.each(this.frm.item_doclist, function(n, item) {
448 var item_tax_map = me._load_item_tax_rate(item.item_tax_rate);
449
450 $.each(me.frm.tax_doclist, function(i, tax) {
451 // tax_amount represents the amount of tax for the current step
452 var current_tax_amount = me.get_current_tax_amount(item, tax, item_tax_map);
Anand Doshi53b73422013-05-31 11:50:01 +0530453
Anand Doshi3543f302013-05-24 19:25:01 +0530454 me.set_item_tax_amount && me.set_item_tax_amount(item, tax, current_tax_amount);
455
456 // case when net total is 0 but there is an actual type charge
457 // in this case add the actual amount to tax.tax_amount
458 // and tax.grand_total_for_current_item for the first such iteration
459 if(tax.charge_type == "Actual" &&
460 !(current_tax_amount || me.frm.doc.net_total || tax.tax_amount)) {
461 var zero_net_total_adjustment = flt(tax.rate, precision("tax_amount", tax));
462 current_tax_amount += zero_net_total_adjustment;
463 }
464
465 // store tax_amount for current item as it will be used for
466 // charge type = 'On Previous Row Amount'
467 tax.tax_amount_for_current_item = current_tax_amount;
468
469 // accumulate tax amount into tax.tax_amount
470 tax.tax_amount += current_tax_amount;
471
Anand Doshi3543f302013-05-24 19:25:01 +0530472 // for buying
473 if(tax.category) {
474 // if just for valuation, do not add the tax amount in total
475 // hence, setting it as 0 for further steps
476 current_tax_amount = (tax.category == "Valuation") ? 0.0 : current_tax_amount;
477
478 current_tax_amount *= (tax.add_deduct_tax == "Deduct") ? -1.0 : 1.0;
479 }
480
481 // Calculate tax.total viz. grand total till that step
482 // note: grand_total_for_current_item contains the contribution of
483 // item's amount, previously applied tax and the current tax on that item
484 if(i==0) {
485 tax.grand_total_for_current_item = flt(item.amount + current_tax_amount,
486 precision("total", tax));
487 } else {
488 tax.grand_total_for_current_item =
489 flt(me.frm.tax_doclist[i-1].grand_total_for_current_item + current_tax_amount,
490 precision("total", tax));
491 }
492
493 // in tax.total, accumulate grand total for each item
494 tax.total += tax.grand_total_for_current_item;
495 });
496 });
497 },
498
499 get_current_tax_amount: function(item, tax, item_tax_map) {
500 var tax_rate = this._get_tax_rate(tax, item_tax_map);
501 var current_tax_amount = 0.0;
502
503 if(tax.charge_type == "Actual") {
504 // distribute the tax amount proportionally to each item row
505 var actual = flt(tax.rate, precision("tax_amount", tax));
506 current_tax_amount = this.frm.doc.net_total ?
507 ((item.amount / this.frm.doc.net_total) * actual) :
508 0.0;
509
510 } else if(tax.charge_type == "On Net Total") {
511 current_tax_amount = (tax_rate / 100.0) * item.amount;
512
513 } else if(tax.charge_type == "On Previous Row Amount") {
514 current_tax_amount = (tax_rate / 100.0) *
515 this.frm.tax_doclist[cint(tax.row_id) - 1].tax_amount_for_current_item;
516
517 } else if(tax.charge_type == "On Previous Row Total") {
518 current_tax_amount = (tax_rate / 100.0) *
519 this.frm.tax_doclist[cint(tax.row_id) - 1].grand_total_for_current_item;
520
521 }
522
Anand Doshi53b73422013-05-31 11:50:01 +0530523 current_tax_amount = flt(current_tax_amount, precision("tax_amount", tax));
524
525 // store tax breakup for each item
526 tax.item_wise_tax_detail[item.item_code || item.item_name] = [tax_rate, current_tax_amount];
527
528 return current_tax_amount;
Anand Doshi3543f302013-05-24 19:25:01 +0530529 },
530
531 _cleanup: function() {
532 $.each(this.frm.tax_doclist, function(i, tax) {
533 $.each(["tax_amount_for_current_item", "grand_total_for_current_item",
534 "tax_fraction_for_current_item", "grand_total_fraction_for_current_item"],
535 function(i, fieldname) { delete tax[fieldname]; });
536
537 tax.item_wise_tax_detail = JSON.stringify(tax.item_wise_tax_detail);
538 });
539 },
Anand Doshifc777182013-05-27 19:29:07 +0530540
541 calculate_total_advance: function(parenttype, advance_parentfield) {
542 if(this.frm.doc.doctype == parenttype && this.frm.doc.docstatus < 2) {
543 var advance_doclist = wn.model.get_doclist(this.frm.doc.doctype, this.frm.doc.name,
544 {parentfield: advance_parentfield});
545 this.frm.doc.total_advance = flt(wn.utils.sum(
546 $.map(advance_doclist, function(adv) { return adv.allocated_amount })
547 ), precision("total_advance"));
548
549 this.calculate_outstanding_amount();
550 }
551 },
Anand Doshi3543f302013-05-24 19:25:01 +0530552
553 _set_in_company_currency: function(item, print_field, base_field) {
554 // set values in base currency
555 item[base_field] = flt(item[print_field] * this.frm.doc.conversion_rate,
556 precision(base_field, item));
557 },
Anand Doshibf3e54a2013-06-05 14:11:32 +0530558
559 get_terms: function() {
560 var me = this;
561 if(this.frm.doc.tc_name) {
562 this.frm.call({
563 method: "webnotes.client.get_value",
564 args: {
565 doctype: "Terms and Conditions",
566 fieldname: "terms",
567 filters: { name: this.frm.doc.tc_name },
568 },
569 });
570 }
571 },
Anand Doshi3543f302013-05-24 19:25:01 +0530572});