Rushabh Mehta | ad45e31 | 2013-11-20 12:59:58 +0530 | [diff] [blame] | 1 | // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors |
Rushabh Mehta | e67d1fb | 2013-08-05 14:59:54 +0530 | [diff] [blame] | 2 | // License: GNU General Public License v3. See license.txt |
| 3 | |
Rushabh Mehta | 4a008f5 | 2013-07-29 15:31:11 +0530 | [diff] [blame] | 4 | erpnext.POS = Class.extend({ |
| 5 | init: function(wrapper, frm) { |
| 6 | this.wrapper = wrapper; |
| 7 | this.frm = frm; |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 8 | this.wrapper.html(frappe.render_template("pos", {})); |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 9 | |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 10 | this.check_transaction_type(); |
Rushabh Mehta | 4a008f5 | 2013-07-29 15:31:11 +0530 | [diff] [blame] | 11 | this.make(); |
| 12 | |
| 13 | var me = this; |
| 14 | $(this.frm.wrapper).on("refresh-fields", function() { |
| 15 | me.refresh(); |
| 16 | }); |
| 17 | |
Akhilesh Darjee | 57738a0 | 2014-01-03 18:15:07 +0530 | [diff] [blame] | 18 | this.wrapper.find('input.discount-amount').on("change", function() { |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 19 | frappe.model.set_value(me.frm.doctype, me.frm.docname, "discount_amount", this.value); |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 20 | }); |
| 21 | |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 22 | this.call_function("remove-items", function() {me.remove_selected_items();}); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 23 | this.call_function("make-payment", function() {me.make_payment();}); |
| 24 | }, |
| 25 | check_transaction_type: function() { |
| 26 | var me = this; |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 27 | |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 28 | // Check whether the transaction is "Sales" or "Purchase" |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 29 | if (frappe.meta.has_field(cur_frm.doc.doctype, "customer")) { |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 30 | this.set_transaction_defaults("Customer", "export"); |
| 31 | } |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 32 | else if (frappe.meta.has_field(cur_frm.doc.doctype, "supplier")) { |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 33 | this.set_transaction_defaults("Supplier", "import"); |
| 34 | } |
| 35 | }, |
| 36 | set_transaction_defaults: function(party, export_or_import) { |
| 37 | var me = this; |
| 38 | this.party = party; |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 39 | this.price_list = (party == "Customer" ? |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 40 | this.frm.doc.selling_price_list : this.frm.doc.buying_price_list); |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 41 | this.price_list_field = (party == "Customer" ? "selling_price_list" : "buying_price_list"); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 42 | this.sales_or_purchase = (party == "Customer" ? "Sales" : "Purchase"); |
| 43 | this.net_total = "net_total_" + export_or_import; |
| 44 | this.grand_total = "grand_total_" + export_or_import; |
Nabin Hait | 1eb5601 | 2014-02-10 19:20:15 +0530 | [diff] [blame] | 45 | // this.amount = export_or_import + "_amount"; |
| 46 | // this.rate = export_or_import + "_rate"; |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 47 | }, |
| 48 | call_function: function(class_name, fn, event_name) { |
| 49 | this.wrapper.find("." + class_name).on(event_name || "click", fn); |
Rushabh Mehta | 4a008f5 | 2013-07-29 15:31:11 +0530 | [diff] [blame] | 50 | }, |
| 51 | make: function() { |
Akhilesh Darjee | f83576b | 2013-09-18 18:35:12 +0530 | [diff] [blame] | 52 | this.make_party(); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 53 | this.make_barcode(); |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 54 | this.make_search(); |
| 55 | this.make_item_group(); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 56 | this.make_item_list(); |
Rushabh Mehta | 4a008f5 | 2013-07-29 15:31:11 +0530 | [diff] [blame] | 57 | }, |
Akhilesh Darjee | f83576b | 2013-09-18 18:35:12 +0530 | [diff] [blame] | 58 | make_party: function() { |
Akhilesh Darjee | f624ffa | 2013-09-23 12:27:16 +0530 | [diff] [blame] | 59 | var me = this; |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 60 | this.party_field = frappe.ui.form.make_control({ |
Rushabh Mehta | 4a008f5 | 2013-07-29 15:31:11 +0530 | [diff] [blame] | 61 | df: { |
| 62 | "fieldtype": "Link", |
Akhilesh Darjee | f83576b | 2013-09-18 18:35:12 +0530 | [diff] [blame] | 63 | "options": this.party, |
| 64 | "label": this.party, |
| 65 | "fieldname": "pos_party", |
| 66 | "placeholder": this.party |
Rushabh Mehta | 4a008f5 | 2013-07-29 15:31:11 +0530 | [diff] [blame] | 67 | }, |
Rushabh Mehta | 069672e | 2013-10-28 18:21:07 +0530 | [diff] [blame] | 68 | parent: this.wrapper.find(".party-area"), |
| 69 | only_input: true, |
Rushabh Mehta | 4a008f5 | 2013-07-29 15:31:11 +0530 | [diff] [blame] | 70 | }); |
Akhilesh Darjee | f83576b | 2013-09-18 18:35:12 +0530 | [diff] [blame] | 71 | this.party_field.make_input(); |
| 72 | this.party_field.$input.on("change", function() { |
| 73 | if(!me.party_field.autocomplete_open) |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 74 | frappe.model.set_value(me.frm.doctype, me.frm.docname, |
Akhilesh Darjee | f83576b | 2013-09-18 18:35:12 +0530 | [diff] [blame] | 75 | me.party.toLowerCase(), this.value); |
Rushabh Mehta | 4a008f5 | 2013-07-29 15:31:11 +0530 | [diff] [blame] | 76 | }); |
| 77 | }, |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 78 | make_barcode: function() { |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 79 | var me = this; |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 80 | this.barcode = frappe.ui.form.make_control({ |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 81 | df: { |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 82 | "fieldtype": "Data", |
| 83 | "label": "Barcode", |
| 84 | "fieldname": "pos_barcode", |
| 85 | "placeholder": "Barcode / Serial No" |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 86 | }, |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 87 | parent: this.wrapper.find(".barcode-area"), |
Rushabh Mehta | 069672e | 2013-10-28 18:21:07 +0530 | [diff] [blame] | 88 | only_input: true, |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 89 | }); |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 90 | this.barcode.make_input(); |
| 91 | this.barcode.$input.on("keypress", function() { |
| 92 | if(me.barcode_timeout) |
| 93 | clearTimeout(me.barcode_timeout); |
| 94 | me.barcode_timeout = setTimeout(function() { me.add_item_thru_barcode(); }, 1000); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 95 | }); |
| 96 | }, |
| 97 | make_search: function() { |
| 98 | var me = this; |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 99 | this.search = frappe.ui.form.make_control({ |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 100 | df: { |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 101 | "fieldtype": "Data", |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 102 | "label": "Item", |
Rushabh Mehta | 16a62fa | 2013-08-23 13:16:22 +0530 | [diff] [blame] | 103 | "fieldname": "pos_item", |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 104 | "placeholder": "Search Item" |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 105 | }, |
Rushabh Mehta | 069672e | 2013-10-28 18:21:07 +0530 | [diff] [blame] | 106 | parent: this.wrapper.find(".search-area"), |
| 107 | only_input: true, |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 108 | }); |
| 109 | this.search.make_input(); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 110 | this.search.$input.on("keypress", function() { |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 111 | if(!me.search.autocomplete_open) |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 112 | if(me.item_timeout) |
| 113 | clearTimeout(me.item_timeout); |
| 114 | me.item_timeout = setTimeout(function() { me.make_item_list(); }, 1000); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 115 | }); |
| 116 | }, |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 117 | make_item_group: function() { |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 118 | var me = this; |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 119 | this.item_group = frappe.ui.form.make_control({ |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 120 | df: { |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 121 | "fieldtype": "Link", |
| 122 | "options": "Item Group", |
| 123 | "label": "Item Group", |
| 124 | "fieldname": "pos_item_group", |
| 125 | "placeholder": "Item Group" |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 126 | }, |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 127 | parent: this.wrapper.find(".item-group-area"), |
Rushabh Mehta | 069672e | 2013-10-28 18:21:07 +0530 | [diff] [blame] | 128 | only_input: true, |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 129 | }); |
Akhilesh Darjee | d203aea | 2013-12-27 17:49:57 +0530 | [diff] [blame] | 130 | this.item_group.make_input(); |
| 131 | this.item_group.$input.on("change", function() { |
| 132 | if(!me.item_group.autocomplete_open) |
| 133 | me.make_item_list(); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 134 | }); |
| 135 | }, |
| 136 | make_item_list: function() { |
Akhilesh Darjee | f624ffa | 2013-09-23 12:27:16 +0530 | [diff] [blame] | 137 | var me = this; |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 138 | me.item_timeout = null; |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 139 | frappe.call({ |
Rushabh Mehta | 1f84799 | 2013-12-12 19:12:19 +0530 | [diff] [blame] | 140 | method: 'erpnext.accounts.doctype.sales_invoice.pos.get_items', |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 141 | args: { |
Akhilesh Darjee | e947081 | 2013-09-19 19:09:15 +0530 | [diff] [blame] | 142 | sales_or_purchase: this.sales_or_purchase, |
| 143 | price_list: this.price_list, |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 144 | item_group: this.item_group.$input.val(), |
| 145 | item: this.search.$input.val() |
| 146 | }, |
| 147 | callback: function(r) { |
| 148 | var $wrap = me.wrapper.find(".item-list"); |
| 149 | me.wrapper.find(".item-list").empty(); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 150 | if (r.message) { |
| 151 | $.each(r.message, function(index, obj) { |
| 152 | if (obj.image) |
| 153 | image = '<img src="' + obj.image + '" class="img-responsive" \ |
| 154 | style="border:1px solid #eee; max-height: 140px;">'; |
| 155 | else |
| 156 | image = '<div class="missing-image"><i class="icon-camera"></i></div>'; |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 157 | |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 158 | $(repl('<div class="col-xs-3 pos-item" data-item_code="%(item_code)s">\ |
| 159 | <div style="height: 140px; overflow: hidden;">%(item_image)s</div>\ |
| 160 | <div class="small">%(item_code)s</div>\ |
| 161 | <div class="small">%(item_name)s</div>\ |
| 162 | <div class="small">%(item_price)s</div>\ |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 163 | </div>', |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 164 | { |
| 165 | item_code: obj.name, |
Nabin Hait | a7f757a | 2014-02-10 17:54:04 +0530 | [diff] [blame] | 166 | item_price: format_currency(obj.price_list_rate, obj.currency), |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 167 | item_name: obj.name===obj.item_name ? "" : obj.item_name, |
| 168 | item_image: image |
| 169 | })).appendTo($wrap); |
| 170 | }); |
| 171 | } |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 172 | |
Akhilesh Darjee | 12425ce | 2013-09-02 18:48:39 +0530 | [diff] [blame] | 173 | // if form is local then allow this function |
Nabin Hait | cf30118 | 2013-10-01 18:14:16 +0530 | [diff] [blame] | 174 | $(me.wrapper).find("div.pos-item").on("click", function() { |
| 175 | if(me.frm.doc.docstatus==0) { |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 176 | console.log($(this).attr("data-item_code")); |
| 177 | me.add_to_cart($(this).attr("data-item_code")); |
Nabin Hait | cf30118 | 2013-10-01 18:14:16 +0530 | [diff] [blame] | 178 | } |
| 179 | }); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 180 | } |
| 181 | }); |
| 182 | }, |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 183 | add_to_cart: function(item_code, serial_no) { |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 184 | var me = this; |
| 185 | var caught = false; |
| 186 | |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 187 | if(!me.frm.doc[me.party.toLowerCase()] && ((me.frm.doctype == "Quotation" && |
| 188 | me.frm.doc.quotation_to == "Customer") |
| 189 | || me.frm.doctype != "Quotation")) { |
| 190 | msgprint(__("Please select {0} first.", [me.party])); |
| 191 | return; |
| 192 | } |
| 193 | |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 194 | // get no_of_items |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 195 | var no_of_items = me.wrapper.find(".pos-bill-item").length; |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 196 | |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 197 | // check whether the item is already added |
| 198 | if (no_of_items != 0) { |
Rushabh Mehta | 66d52b5 | 2014-03-27 14:17:33 +0530 | [diff] [blame] | 199 | $.each(this.frm.doc[this.frm.cscript.fname] || [], function(i, d) { |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 200 | if (d.item_code == item_code) { |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 201 | caught = true; |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 202 | if (serial_no) |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 203 | frappe.model.set_value(d.doctype, d.name, "serial_no", d.serial_no + '\n' + serial_no); |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 204 | else |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 205 | frappe.model.set_value(d.doctype, d.name, "qty", d.qty + 1); |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 206 | } |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 207 | }); |
| 208 | } |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 209 | |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 210 | // if item not found then add new item |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 211 | if (!caught) |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 212 | this.add_new_item_to_grid(item_code, serial_no); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 213 | |
| 214 | this.refresh(); |
| 215 | this.refresh_search_box(); |
| 216 | }, |
| 217 | add_new_item_to_grid: function(item_code, serial_no) { |
| 218 | var me = this; |
| 219 | |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 220 | var child = frappe.model.add_child(me.frm.doc, this.frm.doctype + " Item", |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 221 | this.frm.cscript.fname); |
| 222 | child.item_code = item_code; |
| 223 | |
| 224 | if (serial_no) |
| 225 | child.serial_no = serial_no; |
| 226 | |
| 227 | this.frm.script_manager.trigger("item_code", child.doctype, child.name); |
| 228 | }, |
| 229 | refresh_search_box: function() { |
| 230 | var me = this; |
| 231 | |
| 232 | // Clear Item Box and remake item list |
| 233 | if (this.search.$input.val()) { |
| 234 | this.search.set_input(""); |
| 235 | this.make_item_list(); |
| 236 | } |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 237 | }, |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 238 | update_qty: function(item_code, qty) { |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 239 | console.log([item_code, qty]); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 240 | var me = this; |
Rushabh Mehta | 66d52b5 | 2014-03-27 14:17:33 +0530 | [diff] [blame] | 241 | $.each(this.frm.doc[this.frm.cscript.fname] || [], function(i, d) { |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 242 | if (d.item_code == item_code) { |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 243 | if (qty == 0) { |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 244 | frappe.model.clear_doc(d.doctype, d.name); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 245 | me.refresh_grid(); |
| 246 | } else { |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 247 | frappe.model.set_value(d.doctype, d.name, "qty", qty); |
Akhilesh Darjee | d271431 | 2013-08-28 19:35:22 +0530 | [diff] [blame] | 248 | } |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 249 | } |
| 250 | }); |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 251 | this.refresh(); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 252 | }, |
Rushabh Mehta | 4a008f5 | 2013-07-29 15:31:11 +0530 | [diff] [blame] | 253 | refresh: function() { |
| 254 | var me = this; |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 255 | |
| 256 | this.refresh_item_list(); |
Akhilesh Darjee | f83576b | 2013-09-18 18:35:12 +0530 | [diff] [blame] | 257 | this.party_field.set_input(this.frm.doc[this.party.toLowerCase()]); |
Akhilesh Darjee | 57738a0 | 2014-01-03 18:15:07 +0530 | [diff] [blame] | 258 | this.wrapper.find('input.discount-amount').val(this.frm.doc.discount_amount); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 259 | this.barcode.set_input(""); |
| 260 | |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 261 | this.show_items_in_item_cart(); |
| 262 | this.show_taxes(); |
| 263 | this.set_totals(); |
| 264 | |
| 265 | // if form is local then only run all these functions |
| 266 | if (this.frm.doc.docstatus===0) { |
| 267 | this.call_when_local(); |
| 268 | } |
| 269 | |
| 270 | this.disable_text_box_and_button(); |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 271 | this.hide_payment_button(); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 272 | |
| 273 | // If quotation to is not Customer then remove party |
Rushabh Mehta | 72e1719 | 2014-08-08 15:30:49 +0530 | [diff] [blame] | 274 | if (this.frm.doctype == "Quotation" && this.frm.doc.quotation_to!="Customer") { |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 275 | this.party_field.$input.prop("disabled", true); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 276 | } |
| 277 | }, |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 278 | refresh_item_list: function() { |
| 279 | var me = this; |
| 280 | // refresh item list on change of price list |
| 281 | if (this.frm.doc[this.price_list_field] != this.price_list) { |
| 282 | this.price_list = this.frm.doc[this.price_list_field]; |
| 283 | this.make_item_list(); |
| 284 | } |
| 285 | }, |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 286 | show_items_in_item_cart: function() { |
| 287 | var me = this; |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 288 | var $items = this.wrapper.find(".items").empty(); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 289 | |
Rushabh Mehta | 66d52b5 | 2014-03-27 14:17:33 +0530 | [diff] [blame] | 290 | $.each(this.frm.doc[this.frm.cscript.fname] || [], function(i, d) { |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 291 | $(frappe.render_template("pos_bill_item", { |
| 292 | item_code: d.item_code, |
| 293 | item_name: d.item_name===d.item_code ? "" : ("<br>" + d.item_name), |
| 294 | qty: d.qty, |
| 295 | actual_qty: d.actual_qty, |
| 296 | rate: format_currency(d.rate, me.frm.doc.currency), |
| 297 | amount: format_currency(d.amount, me.frm.doc.currency) |
| 298 | })).appendTo($items); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 299 | }); |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 300 | |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 301 | this.wrapper.find("input.pos-item-qty").on("focus", function() { |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 302 | $(this).select(); |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 303 | }); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 304 | }, |
| 305 | show_taxes: function() { |
| 306 | var me = this; |
Rushabh Mehta | 66d52b5 | 2014-03-27 14:17:33 +0530 | [diff] [blame] | 307 | var taxes = this.frm.doc[this.frm.cscript.other_fname] || []; |
Akhilesh Darjee | 4233ae2 | 2013-09-30 18:18:19 +0530 | [diff] [blame] | 308 | $(this.wrapper).find(".tax-table") |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 309 | .toggle((taxes && taxes.length) ? true : false) |
Rushabh Mehta | 16a62fa | 2013-08-23 13:16:22 +0530 | [diff] [blame] | 310 | .find("tbody").empty(); |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 311 | |
Rushabh Mehta | 16a62fa | 2013-08-23 13:16:22 +0530 | [diff] [blame] | 312 | $.each(taxes, function(i, d) { |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 313 | if (d.tax_amount) { |
| 314 | $(repl('<tr>\ |
| 315 | <td>%(description)s %(rate)s</td>\ |
| 316 | <td style="text-align: right;">%(tax_amount)s</td>\ |
| 317 | <tr>', { |
| 318 | description: d.description, |
| 319 | rate: ((d.charge_type == "Actual") ? '' : ("(" + d.rate + "%)")), |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 320 | tax_amount: format_currency(flt(d.tax_amount)/flt(me.frm.doc.conversion_rate), |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 321 | me.frm.doc.currency) |
| 322 | })).appendTo(".tax-table tbody"); |
| 323 | } |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 324 | }); |
| 325 | }, |
| 326 | set_totals: function() { |
| 327 | var me = this; |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 328 | this.wrapper.find(".net-total").text(format_currency(this.frm.doc[this.net_total], |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 329 | me.frm.doc.currency)); |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 330 | this.wrapper.find(".grand-total").text(format_currency(this.frm.doc[this.grand_total], |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 331 | me.frm.doc.currency)); |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 332 | |
Rushabh Mehta | d8de921 | 2014-03-06 15:40:22 +0530 | [diff] [blame] | 333 | $(".paid-amount-area").toggle(!!this.frm.doc.paid_amount); |
| 334 | if(this.frm.doc.paid_amount) { |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 335 | this.wrapper.find(".paid-amount").text(format_currency(this.frm.doc.paid_amount, |
Rushabh Mehta | d8de921 | 2014-03-06 15:40:22 +0530 | [diff] [blame] | 336 | me.frm.doc.currency)); |
| 337 | } |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 338 | }, |
| 339 | call_when_local: function() { |
| 340 | var me = this; |
| 341 | |
| 342 | // append quantity to the respective item after change from input box |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 343 | $(this.wrapper).find("input.pos-item-qty").on("change", function() { |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 344 | var item_code = $(this).closest("tr").attr("id"); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 345 | me.update_qty(item_code, $(this).val()); |
Rushabh Mehta | 16a62fa | 2013-08-23 13:16:22 +0530 | [diff] [blame] | 346 | }); |
| 347 | |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 348 | // increase/decrease qty on plus/minus button |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 349 | $(this.wrapper).find(".pos-qty-btn").on("click", function() { |
| 350 | var $item = $(this).parents(".pos-bill-item:first"); |
| 351 | me.increase_decrease_qty($item, $(this).attr("data-action")); |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 352 | }); |
| 353 | |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 354 | // on td click toggle the highlighting of row |
| 355 | $(this.wrapper).find("#cart tbody tr td").on("click", function() { |
| 356 | var row = $(this).closest("tr"); |
| 357 | if (row.attr("data-selected") == "false") { |
| 358 | row.attr("class", "warning"); |
| 359 | row.attr("data-selected", "true"); |
| 360 | } |
| 361 | else { |
| 362 | row.prop("class", null); |
| 363 | row.attr("data-selected", "false"); |
| 364 | } |
Rushabh Mehta | 16a62fa | 2013-08-23 13:16:22 +0530 | [diff] [blame] | 365 | me.refresh_delete_btn(); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 366 | }); |
Akhilesh Darjee | 12425ce | 2013-09-02 18:48:39 +0530 | [diff] [blame] | 367 | |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 368 | me.refresh_delete_btn(); |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 369 | //me.focus(); |
| 370 | }, |
| 371 | focus: function() { |
Rushabh Mehta | ab8bde0 | 2014-08-12 15:15:39 +0530 | [diff] [blame] | 372 | if(me.frm.doc[this.party]) { |
| 373 | this.barcode.$input.focus(); |
| 374 | } else { |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 375 | if(!(this.frm.doctype == "Quotation" && this.frm.doc.quotation_to!="Customer")) |
| 376 | this.party_field.$input.focus(); |
Rushabh Mehta | ab8bde0 | 2014-08-12 15:15:39 +0530 | [diff] [blame] | 377 | } |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 378 | }, |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 379 | increase_decrease_qty: function($item, operation) { |
| 380 | var item_code = $item.attr("data-item-code"); |
| 381 | var item_qty = cint($item.find("input.pos-item-qty").val()); |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 382 | |
| 383 | if (operation == "increase-qty") |
| 384 | this.update_qty(item_code, item_qty + 1); |
Rushabh Mehta | 72e1719 | 2014-08-08 15:30:49 +0530 | [diff] [blame] | 385 | else if (operation == "decrease-qty" && item_qty != 0) |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 386 | this.update_qty(item_code, item_qty - 1); |
| 387 | }, |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 388 | disable_text_box_and_button: function() { |
| 389 | var me = this; |
Akhilesh Darjee | 12425ce | 2013-09-02 18:48:39 +0530 | [diff] [blame] | 390 | // if form is submitted & cancelled then disable all input box & buttons |
Rushabh Mehta | d8de921 | 2014-03-06 15:40:22 +0530 | [diff] [blame] | 391 | $(this.wrapper) |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 392 | .find(".remove-items, .make-payment, .pos-qty-btn") |
Rushabh Mehta | d8de921 | 2014-03-06 15:40:22 +0530 | [diff] [blame] | 393 | .toggle(this.frm.doc.docstatus===0); |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 394 | |
Rushabh Mehta | d8de921 | 2014-03-06 15:40:22 +0530 | [diff] [blame] | 395 | $(this.wrapper).find('input, button').prop("disabled", !(this.frm.doc.docstatus===0)); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 396 | }, |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 397 | hide_payment_button: function() { |
Rushabh Mehta | d8de921 | 2014-03-06 15:40:22 +0530 | [diff] [blame] | 398 | $(this.wrapper) |
| 399 | .find(".make-payment") |
| 400 | .toggle(this.frm.doctype == "Sales Invoice" && this.frm.doc.is_pos); |
Rushabh Mehta | 16a62fa | 2013-08-23 13:16:22 +0530 | [diff] [blame] | 401 | }, |
| 402 | refresh_delete_btn: function() { |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 403 | $(this.wrapper).find(".remove-items").toggle($(".item-cart .warning").length ? true : false); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 404 | }, |
| 405 | add_item_thru_barcode: function() { |
| 406 | var me = this; |
Akhilesh Darjee | d271431 | 2013-08-28 19:35:22 +0530 | [diff] [blame] | 407 | me.barcode_timeout = null; |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 408 | frappe.call({ |
Rushabh Mehta | 1f84799 | 2013-12-12 19:12:19 +0530 | [diff] [blame] | 409 | method: 'erpnext.accounts.doctype.sales_invoice.pos.get_item_code', |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 410 | args: {barcode_serial_no: this.barcode.$input.val()}, |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 411 | callback: function(r) { |
| 412 | if (r.message) { |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 413 | if (r.message[1] == "serial_no") |
| 414 | me.add_to_cart(r.message[0][0].item_code, r.message[0][0].name); |
| 415 | else |
| 416 | me.add_to_cart(r.message[0][0].name); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 417 | } |
| 418 | else |
Pratik Vyas | b52618c | 2014-04-14 16:25:30 +0530 | [diff] [blame] | 419 | msgprint(__("Invalid Barcode")); |
Akhilesh Darjee | 1f0b860 | 2013-08-23 18:22:32 +0530 | [diff] [blame] | 420 | |
| 421 | me.refresh(); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 422 | } |
| 423 | }); |
| 424 | }, |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 425 | remove_selected_items: function() { |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 426 | var me = this; |
| 427 | var selected_items = []; |
Akhilesh Darjee | 4233ae2 | 2013-09-30 18:18:19 +0530 | [diff] [blame] | 428 | var no_of_items = $(this.wrapper).find("#cart tbody tr").length; |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 429 | for(var x=0; x<=no_of_items - 1; x++) { |
Akhilesh Darjee | 4233ae2 | 2013-09-30 18:18:19 +0530 | [diff] [blame] | 430 | var row = $(this.wrapper).find("#cart tbody tr:eq(" + x + ")"); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 431 | if(row.attr("data-selected") == "true") { |
| 432 | selected_items.push(row.attr("id")); |
| 433 | } |
| 434 | } |
Akhilesh Darjee | e947081 | 2013-09-19 19:09:15 +0530 | [diff] [blame] | 435 | |
Rushabh Mehta | 66d52b5 | 2014-03-27 14:17:33 +0530 | [diff] [blame] | 436 | var child = this.frm.doc[this.frm.cscript.fname] || []; |
Akhilesh Darjee | e947081 | 2013-09-19 19:09:15 +0530 | [diff] [blame] | 437 | |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 438 | $.each(child, function(i, d) { |
| 439 | for (var i in selected_items) { |
| 440 | if (d.item_code == selected_items[i]) { |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 441 | frappe.model.clear_doc(d.doctype, d.name); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 442 | } |
| 443 | } |
| 444 | }); |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 445 | |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 446 | this.refresh_grid(); |
| 447 | }, |
| 448 | refresh_grid: function() { |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 449 | this.frm.dirty(); |
Akhilesh Darjee | 2428e8d | 2013-09-27 12:32:26 +0530 | [diff] [blame] | 450 | this.frm.fields_dict[this.frm.cscript.fname].grid.refresh(); |
| 451 | this.frm.script_manager.trigger("calculate_taxes_and_totals"); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 452 | this.refresh(); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 453 | }, |
| 454 | make_payment: function() { |
| 455 | var me = this; |
Akhilesh Darjee | 4233ae2 | 2013-09-30 18:18:19 +0530 | [diff] [blame] | 456 | var no_of_items = $(this.wrapper).find("#cart tbody tr").length; |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 457 | var mode_of_payment = []; |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 458 | |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 459 | if (no_of_items == 0) |
Pratik Vyas | b52618c | 2014-04-14 16:25:30 +0530 | [diff] [blame] | 460 | msgprint(__("Payment cannot be made for empty cart")); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 461 | else { |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 462 | frappe.call({ |
Rushabh Mehta | 1f84799 | 2013-12-12 19:12:19 +0530 | [diff] [blame] | 463 | method: 'erpnext.accounts.doctype.sales_invoice.pos.get_mode_of_payment', |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 464 | callback: function(r) { |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 465 | if(!r.message) { |
Rushabh Mehta | d8de921 | 2014-03-06 15:40:22 +0530 | [diff] [blame] | 466 | msgprint(__("Please add to Modes of Payment from Setup.")) |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 467 | return; |
Rushabh Mehta | d8de921 | 2014-03-06 15:40:22 +0530 | [diff] [blame] | 468 | } |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 469 | for (x=0; x<=r.message.length - 1; x++) { |
| 470 | mode_of_payment.push(r.message[x].name); |
| 471 | } |
| 472 | |
| 473 | // show payment wizard |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 474 | var dialog = new frappe.ui.Dialog({ |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 475 | width: 400, |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 476 | title: 'Payment', |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 477 | fields: [ |
| 478 | {fieldtype:'Data', fieldname:'total_amount', label:'Total Amount', read_only:1}, |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 479 | {fieldtype:'Select', fieldname:'mode_of_payment', label:'Mode of Payment', |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 480 | options:mode_of_payment.join('\n'), reqd: 1}, |
| 481 | {fieldtype:'Button', fieldname:'pay', label:'Pay'} |
| 482 | ] |
| 483 | }); |
| 484 | dialog.set_values({ |
| 485 | "total_amount": $(".grand-total").text() |
| 486 | }); |
| 487 | dialog.show(); |
Anand Doshi | c8e39b0 | 2013-08-30 18:22:58 +0530 | [diff] [blame] | 488 | dialog.get_input("total_amount").prop("disabled", true); |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 489 | |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 490 | dialog.fields_dict.pay.input.onclick = function() { |
Akhilesh Darjee | 2428e8d | 2013-09-27 12:32:26 +0530 | [diff] [blame] | 491 | me.frm.set_value("mode_of_payment", dialog.get_values().mode_of_payment); |
| 492 | me.frm.set_value("paid_amount", dialog.get_values().total_amount); |
| 493 | me.frm.cscript.mode_of_payment(me.frm.doc); |
| 494 | me.frm.save(); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 495 | dialog.hide(); |
| 496 | me.refresh(); |
| 497 | }; |
| 498 | } |
Rushabh Mehta | 4a008f5 | 2013-07-29 15:31:11 +0530 | [diff] [blame] | 499 | }); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 500 | } |
| 501 | }, |
Pratik Vyas | b0f279a | 2014-04-14 17:14:23 +0530 | [diff] [blame] | 502 | }); |