// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors // License: GNU General Public License v3. See license.txt window.doc={{ doc.as_json() }}; $(document).ready(function() { new rfq(); doc.supplier = "{{ doc.supplier }}" }); rfq = Class.extend({ init: function(){ this.onfocus_select_all(); this.change_qty(); this.change_rate(); this.terms(); this.submit_rfq(); }, onfocus_select_all: function(){ $("input").click(function(){ $(this).select(); }) }, change_qty: function(){ var me = this; $('.rfq-items').on("change", ".rfq-qty", function(){ me.idx = parseFloat($(this).attr('data-idx')); me.qty = parseFloat($(this).val()); me.rate = parseFloat($(repl('.rfq-rate[data-idx=%(idx)s]',{'idx': me.idx})).val()); me.update_qty_rate(); }) }, change_rate: function(){ var me = this; $(".rfq-items").on("change", ".rfq-rate", function(){ me.idx = parseFloat($(this).attr('data-idx')); me.rate = parseFloat($(this).val()); me.qty = parseFloat($(repl('.rfq-qty[data-idx=%(idx)s]',{'idx': me.idx})).val()); me.update_qty_rate(); }) }, terms: function(){ $(".terms").on("change", ".terms-feedback", function(){ doc.terms = $(this).val(); }) }, update_qty_rate: function(){ var me = this; doc.grand_total = 0.0; $.each(doc.items, function(idx, data){ if(data.idx == me.idx){ data.qty = me.qty; data.rate = me.rate; data.amount = (me.rate * me.qty) || 0.0; $(repl('.rfq-amount[data-idx=%(idx)s]',{'idx': me.idx})).text(data.amount.toFixed(2)); } doc.grand_total += flt(data.amount); $('.tax-grand-total').text(doc.grand_total.toFixed(2)); }) }, submit_rfq: function(){ $('.btn-sm').click(function(){ frappe.freeze(); frappe.call({ type: "POST", method: "erpnext.buying.doctype.request_for_quotation.request_for_quotation.create_supplier_quotation", args: { doc: doc }, btn: this, callback: function(r){ frappe.unfreeze(); } }) }) } })