2016-03-03 08:30:35 +00:00
|
|
|
// 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 }}"
|
2016-03-30 07:54:42 +00:00
|
|
|
doc.currency = "{{ doc.currency }}"
|
|
|
|
doc.number_format = "{{ doc.number_format }}"
|
|
|
|
doc.buying_price_list = "{{ doc.buying_price_list }}"
|
2016-03-03 08:30:35 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
rfq = Class.extend({
|
|
|
|
init: function(){
|
|
|
|
this.onfocus_select_all();
|
|
|
|
this.change_qty();
|
|
|
|
this.change_rate();
|
|
|
|
this.terms();
|
|
|
|
this.submit_rfq();
|
2016-10-03 13:35:18 +00:00
|
|
|
this.navigate_quotations();
|
2016-03-03 08:30:35 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
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'));
|
2016-09-01 12:31:27 +00:00
|
|
|
me.qty = parseFloat($(this).val()) || 0;
|
2016-03-03 08:30:35 +00:00
|
|
|
me.rate = parseFloat($(repl('.rfq-rate[data-idx=%(idx)s]',{'idx': me.idx})).val());
|
|
|
|
me.update_qty_rate();
|
2017-04-17 06:54:11 +00:00
|
|
|
$(this).val(format_number(me.qty, doc.number_format, 2));
|
2016-03-03 08:30:35 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
change_rate: function(){
|
|
|
|
var me = this;
|
|
|
|
$(".rfq-items").on("change", ".rfq-rate", function(){
|
|
|
|
me.idx = parseFloat($(this).attr('data-idx'));
|
2016-09-01 12:31:27 +00:00
|
|
|
me.rate = parseFloat($(this).val()) || 0;
|
2016-03-03 08:30:35 +00:00
|
|
|
me.qty = parseFloat($(repl('.rfq-qty[data-idx=%(idx)s]',{'idx': me.idx})).val());
|
|
|
|
me.update_qty_rate();
|
2017-04-17 06:54:11 +00:00
|
|
|
$(this).val(format_number(me.rate, doc.number_format, 2));
|
2016-03-03 08:30:35 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
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;
|
2016-03-30 07:54:42 +00:00
|
|
|
$(repl('.rfq-amount[data-idx=%(idx)s]',{'idx': me.idx})).text(format_number(data.amount, doc.number_format, 2));
|
2016-03-03 08:30:35 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
doc.grand_total += flt(data.amount);
|
2016-03-30 07:54:42 +00:00
|
|
|
$('.tax-grand-total').text(format_number(doc.grand_total, doc.number_format, 2));
|
2016-03-03 08:30:35 +00:00
|
|
|
})
|
|
|
|
},
|
|
|
|
|
|
|
|
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();
|
2016-09-21 11:19:58 +00:00
|
|
|
if(r.message){
|
|
|
|
$('.btn-sm').hide()
|
2017-09-27 07:23:38 +00:00
|
|
|
window.location.href = "/supplier-quotations/" + encodeURIComponent(r.message);
|
2016-09-21 11:19:58 +00:00
|
|
|
}
|
2016-03-03 08:30:35 +00:00
|
|
|
}
|
|
|
|
})
|
|
|
|
})
|
2016-10-03 13:35:18 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
navigate_quotations: function() {
|
|
|
|
$('.quotations').click(function(){
|
|
|
|
name = $(this).attr('idx')
|
|
|
|
window.location.href = "/quotations/" + encodeURIComponent(name);
|
|
|
|
})
|
2016-03-03 08:30:35 +00:00
|
|
|
}
|
|
|
|
})
|