rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 1 | // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors |
| 2 | // License: GNU General Public License v3. See license.txt |
| 3 | |
| 4 | window.doc={{ doc.as_json() }}; |
| 5 | |
| 6 | $(document).ready(function() { |
| 7 | new rfq(); |
| 8 | doc.supplier = "{{ doc.supplier }}" |
rohitwaghchaure | 62fea03 | 2016-03-30 13:24:42 +0530 | [diff] [blame] | 9 | doc.currency = "{{ doc.currency }}" |
| 10 | doc.number_format = "{{ doc.number_format }}" |
| 11 | doc.buying_price_list = "{{ doc.buying_price_list }}" |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 12 | }); |
| 13 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 14 | rfq = class rfq { |
| 15 | constructor(){ |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 16 | this.onfocus_select_all(); |
| 17 | this.change_qty(); |
| 18 | this.change_rate(); |
| 19 | this.terms(); |
| 20 | this.submit_rfq(); |
Rohit Waghchaure | a26f685 | 2016-10-03 19:05:18 +0530 | [diff] [blame] | 21 | this.navigate_quotations(); |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 22 | } |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 23 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 24 | onfocus_select_all(){ |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 25 | $("input").click(function(){ |
| 26 | $(this).select(); |
| 27 | }) |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 28 | } |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 29 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 30 | change_qty(){ |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 31 | var me = this; |
| 32 | $('.rfq-items').on("change", ".rfq-qty", function(){ |
| 33 | me.idx = parseFloat($(this).attr('data-idx')); |
Rohit Waghchaure | b34ba6b | 2016-09-01 18:01:27 +0530 | [diff] [blame] | 34 | me.qty = parseFloat($(this).val()) || 0; |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 35 | me.rate = parseFloat($(repl('.rfq-rate[data-idx=%(idx)s]',{'idx': me.idx})).val()); |
| 36 | me.update_qty_rate(); |
mbauskar | 22cedeb | 2017-04-17 12:24:11 +0530 | [diff] [blame] | 37 | $(this).val(format_number(me.qty, doc.number_format, 2)); |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 38 | }) |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 39 | } |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 40 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 41 | change_rate(){ |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 42 | var me = this; |
| 43 | $(".rfq-items").on("change", ".rfq-rate", function(){ |
| 44 | me.idx = parseFloat($(this).attr('data-idx')); |
Rohit Waghchaure | b34ba6b | 2016-09-01 18:01:27 +0530 | [diff] [blame] | 45 | me.rate = parseFloat($(this).val()) || 0; |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 46 | me.qty = parseFloat($(repl('.rfq-qty[data-idx=%(idx)s]',{'idx': me.idx})).val()); |
| 47 | me.update_qty_rate(); |
mbauskar | 22cedeb | 2017-04-17 12:24:11 +0530 | [diff] [blame] | 48 | $(this).val(format_number(me.rate, doc.number_format, 2)); |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 49 | }) |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 50 | } |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 51 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 52 | terms(){ |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 53 | $(".terms").on("change", ".terms-feedback", function(){ |
| 54 | doc.terms = $(this).val(); |
| 55 | }) |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 56 | } |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 57 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 58 | update_qty_rate(){ |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 59 | var me = this; |
| 60 | doc.grand_total = 0.0; |
| 61 | $.each(doc.items, function(idx, data){ |
| 62 | if(data.idx == me.idx){ |
| 63 | data.qty = me.qty; |
| 64 | data.rate = me.rate; |
| 65 | data.amount = (me.rate * me.qty) || 0.0; |
rohitwaghchaure | 62fea03 | 2016-03-30 13:24:42 +0530 | [diff] [blame] | 66 | $(repl('.rfq-amount[data-idx=%(idx)s]',{'idx': me.idx})).text(format_number(data.amount, doc.number_format, 2)); |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 67 | } |
| 68 | |
| 69 | doc.grand_total += flt(data.amount); |
rohitwaghchaure | 62fea03 | 2016-03-30 13:24:42 +0530 | [diff] [blame] | 70 | $('.tax-grand-total').text(format_number(doc.grand_total, doc.number_format, 2)); |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 71 | }) |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 72 | } |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 73 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 74 | submit_rfq(){ |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 75 | $('.btn-sm').click(function(){ |
| 76 | frappe.freeze(); |
| 77 | frappe.call({ |
| 78 | type: "POST", |
| 79 | method: "erpnext.buying.doctype.request_for_quotation.request_for_quotation.create_supplier_quotation", |
| 80 | args: { |
| 81 | doc: doc |
| 82 | }, |
| 83 | btn: this, |
| 84 | callback: function(r){ |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 85 | frappe.unfreeze(); |
Rohit Waghchaure | 21499e8 | 2016-09-21 16:49:58 +0530 | [diff] [blame] | 86 | if(r.message){ |
| 87 | $('.btn-sm').hide() |
Brown-Harry Boma | d3fa191 | 2017-09-27 08:23:38 +0100 | [diff] [blame] | 88 | window.location.href = "/supplier-quotations/" + encodeURIComponent(r.message); |
Rohit Waghchaure | 21499e8 | 2016-09-21 16:49:58 +0530 | [diff] [blame] | 89 | } |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 90 | } |
| 91 | }) |
| 92 | }) |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 93 | } |
Rohit Waghchaure | a26f685 | 2016-10-03 19:05:18 +0530 | [diff] [blame] | 94 | |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 95 | navigate_quotations() { |
Rohit Waghchaure | a26f685 | 2016-10-03 19:05:18 +0530 | [diff] [blame] | 96 | $('.quotations').click(function(){ |
| 97 | name = $(this).attr('idx') |
| 98 | window.location.href = "/quotations/" + encodeURIComponent(name); |
| 99 | }) |
rohitwaghchaure | a1064a6 | 2016-03-03 14:00:35 +0530 | [diff] [blame] | 100 | } |
Faris Ansari | 1fe891b | 2021-04-23 08:04:00 +0530 | [diff] [blame] | 101 | } |