blob: 3623d7793263bc7d59627458c0f158bc763bef37 [file] [log] [blame]
rohitwaghchaurea1064a62016-03-03 14:00:35 +05301// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
2// License: GNU General Public License v3. See license.txt
3
4window.doc={{ doc.as_json() }};
5
6$(document).ready(function() {
7 new rfq();
8 doc.supplier = "{{ doc.supplier }}"
9});
10
11rfq = Class.extend({
12 init: function(){
13 this.onfocus_select_all();
14 this.change_qty();
15 this.change_rate();
16 this.terms();
17 this.submit_rfq();
18 },
19
20 onfocus_select_all: function(){
21 $("input").click(function(){
22 $(this).select();
23 })
24 },
25
26 change_qty: function(){
27 var me = this;
28 $('.rfq-items').on("change", ".rfq-qty", function(){
29 me.idx = parseFloat($(this).attr('data-idx'));
30 me.qty = parseFloat($(this).val());
31 me.rate = parseFloat($(repl('.rfq-rate[data-idx=%(idx)s]',{'idx': me.idx})).val());
32 me.update_qty_rate();
33 })
34 },
35
36 change_rate: function(){
37 var me = this;
38 $(".rfq-items").on("change", ".rfq-rate", function(){
39 me.idx = parseFloat($(this).attr('data-idx'));
40 me.rate = parseFloat($(this).val());
41 me.qty = parseFloat($(repl('.rfq-qty[data-idx=%(idx)s]',{'idx': me.idx})).val());
42 me.update_qty_rate();
43 })
44 },
45
46 terms: function(){
47 $(".terms").on("change", ".terms-feedback", function(){
48 doc.terms = $(this).val();
49 })
50 },
51
52 update_qty_rate: function(){
53 var me = this;
54 doc.grand_total = 0.0;
55 $.each(doc.items, function(idx, data){
56 if(data.idx == me.idx){
57 data.qty = me.qty;
58 data.rate = me.rate;
59 data.amount = (me.rate * me.qty) || 0.0;
60 $(repl('.rfq-amount[data-idx=%(idx)s]',{'idx': me.idx})).text(data.amount.toFixed(2));
61 }
62
63 doc.grand_total += flt(data.amount);
64 $('.tax-grand-total').text(doc.grand_total.toFixed(2));
65 })
66 },
67
68 submit_rfq: function(){
69 $('.btn-sm').click(function(){
70 frappe.freeze();
71 frappe.call({
72 type: "POST",
73 method: "erpnext.buying.doctype.request_for_quotation.request_for_quotation.create_supplier_quotation",
74 args: {
75 doc: doc
76 },
77 btn: this,
78 callback: function(r){
79 frappe.unfreeze();
80 }
81 })
82 })
83 }
84})