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; |
Rushabh Mehta | 3d65d96 | 2014-11-28 14:56:10 +0530 | [diff] [blame] | 138 | if(!this.price_list) { |
| 139 | msgprint(__("Price List not found or disabled")); |
| 140 | return; |
| 141 | } |
| 142 | |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 143 | me.item_timeout = null; |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 144 | frappe.call({ |
Rushabh Mehta | 1f84799 | 2013-12-12 19:12:19 +0530 | [diff] [blame] | 145 | method: 'erpnext.accounts.doctype.sales_invoice.pos.get_items', |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 146 | args: { |
Akhilesh Darjee | e947081 | 2013-09-19 19:09:15 +0530 | [diff] [blame] | 147 | sales_or_purchase: this.sales_or_purchase, |
| 148 | price_list: this.price_list, |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 149 | item_group: this.item_group.$input.val(), |
| 150 | item: this.search.$input.val() |
| 151 | }, |
| 152 | callback: function(r) { |
| 153 | var $wrap = me.wrapper.find(".item-list"); |
| 154 | me.wrapper.find(".item-list").empty(); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 155 | if (r.message) { |
| 156 | $.each(r.message, function(index, obj) { |
| 157 | if (obj.image) |
| 158 | image = '<img src="' + obj.image + '" class="img-responsive" \ |
| 159 | style="border:1px solid #eee; max-height: 140px;">'; |
| 160 | else |
Rushabh Mehta | bfaf0a8 | 2015-01-01 12:49:18 +0530 | [diff] [blame] | 161 | image = '<div class="missing-image"><i class="octicon octicon-circle-slash"></i></div>'; |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 162 | |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 163 | $(repl('<div class="col-xs-3 pos-item" data-item_code="%(item_code)s">\ |
| 164 | <div style="height: 140px; overflow: hidden;">%(item_image)s</div>\ |
| 165 | <div class="small">%(item_code)s</div>\ |
| 166 | <div class="small">%(item_name)s</div>\ |
| 167 | <div class="small">%(item_price)s</div>\ |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 168 | </div>', |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 169 | { |
| 170 | item_code: obj.name, |
Nabin Hait | a7f757a | 2014-02-10 17:54:04 +0530 | [diff] [blame] | 171 | item_price: format_currency(obj.price_list_rate, obj.currency), |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 172 | item_name: obj.name===obj.item_name ? "" : obj.item_name, |
| 173 | item_image: image |
| 174 | })).appendTo($wrap); |
| 175 | }); |
| 176 | } |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 177 | |
Akhilesh Darjee | 12425ce | 2013-09-02 18:48:39 +0530 | [diff] [blame] | 178 | // if form is local then allow this function |
Nabin Hait | cf30118 | 2013-10-01 18:14:16 +0530 | [diff] [blame] | 179 | $(me.wrapper).find("div.pos-item").on("click", function() { |
| 180 | if(me.frm.doc.docstatus==0) { |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 181 | console.log($(this).attr("data-item_code")); |
| 182 | me.add_to_cart($(this).attr("data-item_code")); |
Nabin Hait | cf30118 | 2013-10-01 18:14:16 +0530 | [diff] [blame] | 183 | } |
| 184 | }); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 185 | } |
| 186 | }); |
| 187 | }, |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 188 | add_to_cart: function(item_code, serial_no) { |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 189 | var me = this; |
| 190 | var caught = false; |
| 191 | |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 192 | if(!me.frm.doc[me.party.toLowerCase()] && ((me.frm.doctype == "Quotation" && |
| 193 | me.frm.doc.quotation_to == "Customer") |
| 194 | || me.frm.doctype != "Quotation")) { |
| 195 | msgprint(__("Please select {0} first.", [me.party])); |
| 196 | return; |
| 197 | } |
| 198 | |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 199 | // get no_of_items |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 200 | var no_of_items = me.wrapper.find(".pos-bill-item").length; |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 201 | |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 202 | // check whether the item is already added |
| 203 | if (no_of_items != 0) { |
Nabin Hait | dd38a26 | 2014-12-26 13:15:21 +0530 | [diff] [blame] | 204 | $.each(this.frm.doc["items"] || [], function(i, d) { |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 205 | if (d.item_code == item_code) { |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 206 | caught = true; |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 207 | if (serial_no) |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 208 | 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] | 209 | else |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 210 | frappe.model.set_value(d.doctype, d.name, "qty", d.qty + 1); |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 211 | } |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 212 | }); |
| 213 | } |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 214 | |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 215 | // if item not found then add new item |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 216 | if (!caught) |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 217 | this.add_new_item_to_grid(item_code, serial_no); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 218 | |
| 219 | this.refresh(); |
| 220 | this.refresh_search_box(); |
| 221 | }, |
| 222 | add_new_item_to_grid: function(item_code, serial_no) { |
| 223 | var me = this; |
| 224 | |
Nabin Hait | dd38a26 | 2014-12-26 13:15:21 +0530 | [diff] [blame] | 225 | var child = frappe.model.add_child(me.frm.doc, this.frm.doctype + " Item", "items"); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 226 | child.item_code = item_code; |
| 227 | |
| 228 | if (serial_no) |
| 229 | child.serial_no = serial_no; |
| 230 | |
| 231 | this.frm.script_manager.trigger("item_code", child.doctype, child.name); |
| 232 | }, |
| 233 | refresh_search_box: function() { |
| 234 | var me = this; |
| 235 | |
| 236 | // Clear Item Box and remake item list |
| 237 | if (this.search.$input.val()) { |
| 238 | this.search.set_input(""); |
| 239 | this.make_item_list(); |
| 240 | } |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 241 | }, |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 242 | update_qty: function(item_code, qty) { |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 243 | console.log([item_code, qty]); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 244 | var me = this; |
Nabin Hait | dd38a26 | 2014-12-26 13:15:21 +0530 | [diff] [blame] | 245 | $.each(this.frm.doc["items"] || [], function(i, d) { |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 246 | if (d.item_code == item_code) { |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 247 | if (qty == 0) { |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 248 | frappe.model.clear_doc(d.doctype, d.name); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 249 | me.refresh_grid(); |
| 250 | } else { |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 251 | frappe.model.set_value(d.doctype, d.name, "qty", qty); |
Akhilesh Darjee | d271431 | 2013-08-28 19:35:22 +0530 | [diff] [blame] | 252 | } |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 253 | } |
| 254 | }); |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 255 | this.refresh(); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 256 | }, |
Rushabh Mehta | 4a008f5 | 2013-07-29 15:31:11 +0530 | [diff] [blame] | 257 | refresh: function() { |
| 258 | var me = this; |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 259 | |
| 260 | this.refresh_item_list(); |
Akhilesh Darjee | f83576b | 2013-09-18 18:35:12 +0530 | [diff] [blame] | 261 | this.party_field.set_input(this.frm.doc[this.party.toLowerCase()]); |
Akhilesh Darjee | 57738a0 | 2014-01-03 18:15:07 +0530 | [diff] [blame] | 262 | this.wrapper.find('input.discount-amount').val(this.frm.doc.discount_amount); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 263 | this.barcode.set_input(""); |
| 264 | |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 265 | this.show_items_in_item_cart(); |
| 266 | this.show_taxes(); |
| 267 | this.set_totals(); |
| 268 | |
| 269 | // if form is local then only run all these functions |
| 270 | if (this.frm.doc.docstatus===0) { |
| 271 | this.call_when_local(); |
| 272 | } |
| 273 | |
| 274 | this.disable_text_box_and_button(); |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 275 | this.hide_payment_button(); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 276 | |
| 277 | // If quotation to is not Customer then remove party |
Rushabh Mehta | 72e1719 | 2014-08-08 15:30:49 +0530 | [diff] [blame] | 278 | if (this.frm.doctype == "Quotation" && this.frm.doc.quotation_to!="Customer") { |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 279 | this.party_field.$input.prop("disabled", true); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 280 | } |
| 281 | }, |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 282 | refresh_item_list: function() { |
| 283 | var me = this; |
| 284 | // refresh item list on change of price list |
| 285 | if (this.frm.doc[this.price_list_field] != this.price_list) { |
| 286 | this.price_list = this.frm.doc[this.price_list_field]; |
| 287 | this.make_item_list(); |
| 288 | } |
| 289 | }, |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 290 | show_items_in_item_cart: function() { |
| 291 | var me = this; |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 292 | var $items = this.wrapper.find(".items").empty(); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 293 | |
Rushabh Mehta | 419ae33 | 2014-12-31 15:03:14 +0530 | [diff] [blame] | 294 | $.each(this.frm.doc.items|| [], function(i, d) { |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 295 | $(frappe.render_template("pos_bill_item", { |
| 296 | item_code: d.item_code, |
| 297 | item_name: d.item_name===d.item_code ? "" : ("<br>" + d.item_name), |
| 298 | qty: d.qty, |
| 299 | actual_qty: d.actual_qty, |
| 300 | rate: format_currency(d.rate, me.frm.doc.currency), |
| 301 | amount: format_currency(d.amount, me.frm.doc.currency) |
| 302 | })).appendTo($items); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 303 | }); |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 304 | |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 305 | this.wrapper.find("input.pos-item-qty").on("focus", function() { |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 306 | $(this).select(); |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 307 | }); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 308 | }, |
| 309 | show_taxes: function() { |
| 310 | var me = this; |
Nabin Hait | dd38a26 | 2014-12-26 13:15:21 +0530 | [diff] [blame] | 311 | var taxes = this.frm.doc["taxes"] || []; |
Akhilesh Darjee | 4233ae2 | 2013-09-30 18:18:19 +0530 | [diff] [blame] | 312 | $(this.wrapper).find(".tax-table") |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 313 | .toggle((taxes && taxes.length) ? true : false) |
Rushabh Mehta | 16a62fa | 2013-08-23 13:16:22 +0530 | [diff] [blame] | 314 | .find("tbody").empty(); |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 315 | |
Rushabh Mehta | 16a62fa | 2013-08-23 13:16:22 +0530 | [diff] [blame] | 316 | $.each(taxes, function(i, d) { |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 317 | if (d.tax_amount) { |
| 318 | $(repl('<tr>\ |
| 319 | <td>%(description)s %(rate)s</td>\ |
| 320 | <td style="text-align: right;">%(tax_amount)s</td>\ |
| 321 | <tr>', { |
| 322 | description: d.description, |
| 323 | rate: ((d.charge_type == "Actual") ? '' : ("(" + d.rate + "%)")), |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 324 | 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] | 325 | me.frm.doc.currency) |
| 326 | })).appendTo(".tax-table tbody"); |
| 327 | } |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 328 | }); |
| 329 | }, |
| 330 | set_totals: function() { |
| 331 | var me = this; |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 332 | 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] | 333 | me.frm.doc.currency)); |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 334 | 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] | 335 | me.frm.doc.currency)); |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 336 | |
Rushabh Mehta | d8de921 | 2014-03-06 15:40:22 +0530 | [diff] [blame] | 337 | $(".paid-amount-area").toggle(!!this.frm.doc.paid_amount); |
| 338 | if(this.frm.doc.paid_amount) { |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 339 | 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] | 340 | me.frm.doc.currency)); |
| 341 | } |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 342 | }, |
| 343 | call_when_local: function() { |
| 344 | var me = this; |
| 345 | |
| 346 | // append quantity to the respective item after change from input box |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 347 | $(this.wrapper).find("input.pos-item-qty").on("change", function() { |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 348 | var item_code = $(this).closest("tr").attr("id"); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 349 | me.update_qty(item_code, $(this).val()); |
Rushabh Mehta | 16a62fa | 2013-08-23 13:16:22 +0530 | [diff] [blame] | 350 | }); |
| 351 | |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 352 | // increase/decrease qty on plus/minus button |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 353 | $(this.wrapper).find(".pos-qty-btn").on("click", function() { |
| 354 | var $item = $(this).parents(".pos-bill-item:first"); |
| 355 | me.increase_decrease_qty($item, $(this).attr("data-action")); |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 356 | }); |
| 357 | |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 358 | // on td click toggle the highlighting of row |
| 359 | $(this.wrapper).find("#cart tbody tr td").on("click", function() { |
| 360 | var row = $(this).closest("tr"); |
| 361 | if (row.attr("data-selected") == "false") { |
| 362 | row.attr("class", "warning"); |
| 363 | row.attr("data-selected", "true"); |
| 364 | } |
| 365 | else { |
| 366 | row.prop("class", null); |
| 367 | row.attr("data-selected", "false"); |
| 368 | } |
Rushabh Mehta | 16a62fa | 2013-08-23 13:16:22 +0530 | [diff] [blame] | 369 | me.refresh_delete_btn(); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 370 | }); |
Akhilesh Darjee | 12425ce | 2013-09-02 18:48:39 +0530 | [diff] [blame] | 371 | |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 372 | me.refresh_delete_btn(); |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 373 | //me.focus(); |
| 374 | }, |
| 375 | focus: function() { |
Rushabh Mehta | 7a8f009 | 2014-12-31 15:34:37 +0530 | [diff] [blame] | 376 | if(me.frm.doc[this.party].toLowerCase()) { |
Rushabh Mehta | ab8bde0 | 2014-08-12 15:15:39 +0530 | [diff] [blame] | 377 | this.barcode.$input.focus(); |
| 378 | } else { |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 379 | if(!(this.frm.doctype == "Quotation" && this.frm.doc.quotation_to!="Customer")) |
| 380 | this.party_field.$input.focus(); |
Rushabh Mehta | ab8bde0 | 2014-08-12 15:15:39 +0530 | [diff] [blame] | 381 | } |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 382 | }, |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 383 | increase_decrease_qty: function($item, operation) { |
| 384 | var item_code = $item.attr("data-item-code"); |
| 385 | var item_qty = cint($item.find("input.pos-item-qty").val()); |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 386 | |
| 387 | if (operation == "increase-qty") |
| 388 | this.update_qty(item_code, item_qty + 1); |
Rushabh Mehta | 72e1719 | 2014-08-08 15:30:49 +0530 | [diff] [blame] | 389 | else if (operation == "decrease-qty" && item_qty != 0) |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 390 | this.update_qty(item_code, item_qty - 1); |
| 391 | }, |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 392 | disable_text_box_and_button: function() { |
| 393 | var me = this; |
Akhilesh Darjee | 12425ce | 2013-09-02 18:48:39 +0530 | [diff] [blame] | 394 | // if form is submitted & cancelled then disable all input box & buttons |
Rushabh Mehta | d8de921 | 2014-03-06 15:40:22 +0530 | [diff] [blame] | 395 | $(this.wrapper) |
Rushabh Mehta | a9ba5ef | 2014-12-19 16:20:32 +0530 | [diff] [blame] | 396 | .find(".remove-items, .make-payment, .pos-qty-btn") |
Rushabh Mehta | d8de921 | 2014-03-06 15:40:22 +0530 | [diff] [blame] | 397 | .toggle(this.frm.doc.docstatus===0); |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 398 | |
Rushabh Mehta | d8de921 | 2014-03-06 15:40:22 +0530 | [diff] [blame] | 399 | $(this.wrapper).find('input, button').prop("disabled", !(this.frm.doc.docstatus===0)); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 400 | }, |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 401 | hide_payment_button: function() { |
Rushabh Mehta | d8de921 | 2014-03-06 15:40:22 +0530 | [diff] [blame] | 402 | $(this.wrapper) |
| 403 | .find(".make-payment") |
| 404 | .toggle(this.frm.doctype == "Sales Invoice" && this.frm.doc.is_pos); |
Rushabh Mehta | 16a62fa | 2013-08-23 13:16:22 +0530 | [diff] [blame] | 405 | }, |
| 406 | refresh_delete_btn: function() { |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 407 | $(this.wrapper).find(".remove-items").toggle($(".item-cart .warning").length ? true : false); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 408 | }, |
| 409 | add_item_thru_barcode: function() { |
| 410 | var me = this; |
Akhilesh Darjee | d271431 | 2013-08-28 19:35:22 +0530 | [diff] [blame] | 411 | me.barcode_timeout = null; |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 412 | frappe.call({ |
Rushabh Mehta | 1f84799 | 2013-12-12 19:12:19 +0530 | [diff] [blame] | 413 | method: 'erpnext.accounts.doctype.sales_invoice.pos.get_item_code', |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 414 | args: {barcode_serial_no: this.barcode.$input.val()}, |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 415 | callback: function(r) { |
| 416 | if (r.message) { |
Akhilesh Darjee | fcd70d0 | 2013-10-18 14:24:21 +0530 | [diff] [blame] | 417 | if (r.message[1] == "serial_no") |
| 418 | me.add_to_cart(r.message[0][0].item_code, r.message[0][0].name); |
| 419 | else |
| 420 | me.add_to_cart(r.message[0][0].name); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 421 | } |
| 422 | else |
Pratik Vyas | b52618c | 2014-04-14 16:25:30 +0530 | [diff] [blame] | 423 | msgprint(__("Invalid Barcode")); |
Akhilesh Darjee | 1f0b860 | 2013-08-23 18:22:32 +0530 | [diff] [blame] | 424 | |
| 425 | me.refresh(); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 426 | } |
| 427 | }); |
| 428 | }, |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 429 | remove_selected_items: function() { |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 430 | var me = this; |
| 431 | var selected_items = []; |
Akhilesh Darjee | 4233ae2 | 2013-09-30 18:18:19 +0530 | [diff] [blame] | 432 | var no_of_items = $(this.wrapper).find("#cart tbody tr").length; |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 433 | for(var x=0; x<=no_of_items - 1; x++) { |
Akhilesh Darjee | 4233ae2 | 2013-09-30 18:18:19 +0530 | [diff] [blame] | 434 | var row = $(this.wrapper).find("#cart tbody tr:eq(" + x + ")"); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 435 | if(row.attr("data-selected") == "true") { |
| 436 | selected_items.push(row.attr("id")); |
| 437 | } |
| 438 | } |
Akhilesh Darjee | e947081 | 2013-09-19 19:09:15 +0530 | [diff] [blame] | 439 | |
Nabin Hait | dd38a26 | 2014-12-26 13:15:21 +0530 | [diff] [blame] | 440 | var child = this.frm.doc["items"] || []; |
Akhilesh Darjee | e947081 | 2013-09-19 19:09:15 +0530 | [diff] [blame] | 441 | |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 442 | $.each(child, function(i, d) { |
| 443 | for (var i in selected_items) { |
| 444 | if (d.item_code == selected_items[i]) { |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 445 | frappe.model.clear_doc(d.doctype, d.name); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 446 | } |
| 447 | } |
| 448 | }); |
Nabin Hait | dc15b4f | 2014-01-20 16:48:49 +0530 | [diff] [blame] | 449 | |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 450 | this.refresh_grid(); |
| 451 | }, |
| 452 | refresh_grid: function() { |
Anand Doshi | cb39e08 | 2014-01-24 21:44:36 +0530 | [diff] [blame] | 453 | this.frm.dirty(); |
Nabin Hait | dd38a26 | 2014-12-26 13:15:21 +0530 | [diff] [blame] | 454 | this.frm.fields_dict["items"].grid.refresh(); |
Akhilesh Darjee | 2428e8d | 2013-09-27 12:32:26 +0530 | [diff] [blame] | 455 | this.frm.script_manager.trigger("calculate_taxes_and_totals"); |
Akhilesh Darjee | a8e704d | 2013-11-27 16:16:32 +0530 | [diff] [blame] | 456 | this.refresh(); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 457 | }, |
| 458 | make_payment: function() { |
| 459 | var me = this; |
Akhilesh Darjee | 4233ae2 | 2013-09-30 18:18:19 +0530 | [diff] [blame] | 460 | var no_of_items = $(this.wrapper).find("#cart tbody tr").length; |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 461 | var mode_of_payment = []; |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 462 | |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 463 | if (no_of_items == 0) |
Pratik Vyas | b52618c | 2014-04-14 16:25:30 +0530 | [diff] [blame] | 464 | msgprint(__("Payment cannot be made for empty cart")); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 465 | else { |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 466 | frappe.call({ |
Rushabh Mehta | 1f84799 | 2013-12-12 19:12:19 +0530 | [diff] [blame] | 467 | method: 'erpnext.accounts.doctype.sales_invoice.pos.get_mode_of_payment', |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 468 | callback: function(r) { |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 469 | if(!r.message) { |
Rushabh Mehta | d8de921 | 2014-03-06 15:40:22 +0530 | [diff] [blame] | 470 | msgprint(__("Please add to Modes of Payment from Setup.")) |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 471 | return; |
Rushabh Mehta | d8de921 | 2014-03-06 15:40:22 +0530 | [diff] [blame] | 472 | } |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 473 | for (x=0; x<=r.message.length - 1; x++) { |
| 474 | mode_of_payment.push(r.message[x].name); |
| 475 | } |
| 476 | |
| 477 | // show payment wizard |
Rushabh Mehta | 793ba6b | 2014-02-14 15:47:51 +0530 | [diff] [blame] | 478 | var dialog = new frappe.ui.Dialog({ |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 479 | width: 400, |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 480 | title: 'Payment', |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 481 | fields: [ |
| 482 | {fieldtype:'Data', fieldname:'total_amount', label:'Total Amount', read_only:1}, |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 483 | {fieldtype:'Select', fieldname:'mode_of_payment', label:'Mode of Payment', |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 484 | options:mode_of_payment.join('\n'), reqd: 1}, |
| 485 | {fieldtype:'Button', fieldname:'pay', label:'Pay'} |
| 486 | ] |
| 487 | }); |
| 488 | dialog.set_values({ |
| 489 | "total_amount": $(".grand-total").text() |
| 490 | }); |
| 491 | dialog.show(); |
Anand Doshi | c8e39b0 | 2013-08-30 18:22:58 +0530 | [diff] [blame] | 492 | dialog.get_input("total_amount").prop("disabled", true); |
Nabin Hait | ed8a845 | 2014-05-05 11:01:32 +0530 | [diff] [blame] | 493 | |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 494 | dialog.fields_dict.pay.input.onclick = function() { |
Akhilesh Darjee | 2428e8d | 2013-09-27 12:32:26 +0530 | [diff] [blame] | 495 | me.frm.set_value("mode_of_payment", dialog.get_values().mode_of_payment); |
| 496 | me.frm.set_value("paid_amount", dialog.get_values().total_amount); |
| 497 | me.frm.cscript.mode_of_payment(me.frm.doc); |
| 498 | me.frm.save(); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 499 | dialog.hide(); |
| 500 | me.refresh(); |
| 501 | }; |
| 502 | } |
Rushabh Mehta | 4a008f5 | 2013-07-29 15:31:11 +0530 | [diff] [blame] | 503 | }); |
Akhilesh Darjee | d6aa4bf | 2013-08-22 17:26:43 +0530 | [diff] [blame] | 504 | } |
| 505 | }, |
Pratik Vyas | b0f279a | 2014-04-14 17:14:23 +0530 | [diff] [blame] | 506 | }); |