Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1 | frappe.provide("erpnext.pos"); |
| 2 | {% include "erpnext/public/js/controllers/taxes_and_totals.js" %} |
| 3 | |
Rushabh Mehta | 06fa46f | 2015-01-29 18:09:11 +0530 | [diff] [blame] | 4 | frappe.pages['pos'].on_page_load = function(wrapper) { |
Rushabh Mehta | 4c36d73 | 2015-01-01 15:59:34 +0530 | [diff] [blame] | 5 | var page = frappe.ui.make_app_page({ |
Rushabh Mehta | 72e1719 | 2014-08-08 15:30:49 +0530 | [diff] [blame] | 6 | parent: wrapper, |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 7 | title: __('Point of Sale'), |
Rushabh Mehta | 72e1719 | 2014-08-08 15:30:49 +0530 | [diff] [blame] | 8 | single_column: true |
| 9 | }); |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 10 | |
| 11 | wrapper.pos = new erpnext.pos.PointOfSale(wrapper) |
Rushabh Mehta | 72e1719 | 2014-08-08 15:30:49 +0530 | [diff] [blame] | 12 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 13 | |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 14 | frappe.pages['pos'].refresh = function(wrapper) { |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 15 | window.onbeforeunload = function () { |
| 16 | return wrapper.pos.beforeunload() |
| 17 | } |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 18 | wrapper.pos.on_refresh_page() |
| 19 | } |
| 20 | |
| 21 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 22 | erpnext.pos.PointOfSale = erpnext.taxes_and_totals.extend({ |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 23 | init: function(wrapper){ |
| 24 | this.load = true; |
| 25 | this.page = wrapper.page; |
| 26 | this.wrapper = $(wrapper).find('.page-content'); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 27 | this.set_indicator(); |
| 28 | this.onload(); |
| 29 | this.make_menu_list(); |
| 30 | this.set_interval_for_si_sync(); |
| 31 | this.si_docs = this.get_doc_from_localstorage(); |
| 32 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 33 | |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 34 | on_refresh_page: function() { |
| 35 | var me = this; |
| 36 | if(this.load){ |
| 37 | this.load = false; |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 38 | }else if(this.connection_status){ |
| 39 | this.onload(); |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 40 | }else{ |
| 41 | this.create_new(); |
| 42 | } |
| 43 | }, |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 44 | |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 45 | beforeunload: function(e){ |
| 46 | if(this.connection_status == false && frappe.get_route()[0] == "pos"){ |
| 47 | e = e || window.event; |
| 48 | |
| 49 | // For IE and Firefox prior to version 4 |
| 50 | if (e) { |
| 51 | e.returnValue = __("You are in offline mode. You will not be able to reload until you have network."); |
| 52 | return |
| 53 | } |
| 54 | |
| 55 | // For Safari |
| 56 | return __("You are in offline mode. You will not be able to reload until you have network."); |
| 57 | } |
| 58 | }, |
| 59 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 60 | check_internet_connection: function(){ |
| 61 | var me = this; |
| 62 | //Check Internet connection after every 30 seconds |
| 63 | setInterval(function(){ |
| 64 | me.set_indicator(); |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 65 | }, 5000) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 66 | }, |
| 67 | |
| 68 | set_indicator: function(){ |
| 69 | var me = this; |
| 70 | // navigator.onLine |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 71 | this.connection_status = false; |
Rohit Waghchaure | 26cf01a | 2016-07-22 13:24:33 +0530 | [diff] [blame] | 72 | this.page.set_indicator(__("Offline"), "grey") |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 73 | frappe.call({ |
| 74 | method:"frappe.handler.ping", |
| 75 | callback: function(r){ |
| 76 | if(r.message){ |
| 77 | me.connection_status = true; |
Rohit Waghchaure | 26cf01a | 2016-07-22 13:24:33 +0530 | [diff] [blame] | 78 | me.page.set_indicator(__("Online"), "green") |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 79 | } |
| 80 | } |
| 81 | }) |
| 82 | }, |
| 83 | |
| 84 | onload: function(){ |
| 85 | var me = this; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 86 | this.get_data_from_server(function(){ |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 87 | me.create_new(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 88 | }); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 89 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 90 | this.check_internet_connection(); |
| 91 | }, |
| 92 | |
| 93 | make_menu_list: function(){ |
| 94 | var me = this; |
| 95 | |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 96 | this.page.add_menu_item(__("New Sales Invoice"), function() { |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 97 | me.save_previous_entry(); |
| 98 | me.create_new(); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 99 | }) |
| 100 | |
| 101 | this.page.add_menu_item(__("View Offline Records"), function(){ |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 102 | me.show_unsync_invoice_list(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 103 | }); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 104 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 105 | this.page.add_menu_item(__("Sync Master Data"), function(){ |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 106 | me.get_data_from_server(function(){ |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 107 | me.load_data(false); |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 108 | me.make_customer(); |
| 109 | me.make_item_list(); |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 110 | me.set_missing_values(); |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 111 | }) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 112 | }); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 113 | |
| 114 | this.page.add_menu_item(__("POS Profile"), function() { |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 115 | frappe.set_route('List', 'POS Profile'); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 116 | }); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 117 | }, |
| 118 | |
| 119 | show_unsync_invoice_list: function(){ |
| 120 | var me = this; |
| 121 | this.si_docs = this.get_doc_from_localstorage(); |
| 122 | |
| 123 | this.list_dialog = new frappe.ui.Dialog({ |
| 124 | title: 'Invoice List' |
| 125 | }); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 126 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 127 | this.list_dialog.show(); |
| 128 | this.list_body = this.list_dialog.body; |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 129 | if(this.si_docs.length > 0){ |
| 130 | $(this.list_body).append('<div class="row list-row list-row-head pos-invoice-list">\ |
| 131 | <div class="col-xs-2">Sr</div>\ |
| 132 | <div class="col-xs-4">Customer</div>\ |
| 133 | <div class="col-xs-2 text-left">Status</div>\ |
| 134 | <div class="col-xs-4 text-right">Grand Total</div>\ |
| 135 | </div>') |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 136 | |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 137 | $.each(this.si_docs, function(index, data){ |
| 138 | for(key in data) { |
| 139 | $(frappe.render_template("pos_invoice_list", { |
| 140 | sr: index + 1, |
| 141 | name: key, |
| 142 | customer: data[key].customer, |
| 143 | grand_total: format_currency(data[key].grand_total, me.frm.doc.currency), |
| 144 | data: me.get_doctype_status(data[key]) |
| 145 | })).appendTo($(me.list_body)); |
| 146 | } |
| 147 | }) |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 148 | |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 149 | $(this.list_body).find('.list-row').click(function() { |
| 150 | me.name = $(this).attr('invoice-name') |
| 151 | doc_data = me.get_invoice_doc(me.si_docs) |
| 152 | if(doc_data){ |
| 153 | me.frm.doc = doc_data[0][me.name]; |
| 154 | me.set_missing_values(); |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 155 | me.refresh(false); |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 156 | me.disable_input_field(); |
| 157 | me.list_dialog.hide(); |
| 158 | } |
| 159 | }) |
| 160 | }else{ |
| 161 | $(this.list_body).append(repl('<div class="media-heading">%(message)s</div>', {'message': __("All records are synced.")})) |
| 162 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 163 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 164 | |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 165 | get_doctype_status: function(doc){ |
| 166 | if(doc.outstanding_amount == 0){ |
| 167 | return {status: "Paid", indicator: "green"} |
| 168 | }else if(doc.docstatus == 0){ |
| 169 | return {status: "Draft", indicator: "red"} |
| 170 | }else if(doc.paid_amount >= 0){ |
| 171 | return {status: "Unpaid", indicator: "orange"} |
| 172 | } |
| 173 | }, |
| 174 | |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 175 | set_missing_values: function(){ |
| 176 | var me = this; |
| 177 | doc = JSON.parse(localStorage.getItem('doc')) |
| 178 | if(this.frm.doc.payments.length == 0){ |
| 179 | this.frm.doc.payments = doc.payments; |
| 180 | } |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 181 | |
| 182 | if(this.frm.doc.customer){ |
| 183 | this.party_field.$input.val(this.frm.doc.customer); |
| 184 | } |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 185 | }, |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 186 | |
| 187 | get_invoice_doc: function(si_docs){ |
| 188 | var me = this; |
| 189 | this.si_docs = this.get_doc_from_localstorage(); |
| 190 | |
| 191 | return $.grep(this.si_docs, function(data){ |
| 192 | for(key in data){ |
| 193 | return key == me.name |
| 194 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 195 | }) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 196 | }, |
| 197 | |
| 198 | get_data_from_server: function(callback){ |
| 199 | var me = this; |
| 200 | frappe.call({ |
| 201 | method: "erpnext.accounts.doctype.sales_invoice.pos.get_pos_data", |
| 202 | freeze: true, |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 203 | freeze_message: __("Master data syncing, it might take some time"), |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 204 | callback: function(r){ |
| 205 | window.items = r.message.items; |
| 206 | window.customers = r.message.customers; |
| 207 | window.pricing_rules = r.message.pricing_rules; |
| 208 | window.meta = r.message.meta; |
| 209 | window.print_template = r.message.print_template; |
Rohit Waghchaure | 539e913 | 2016-07-07 16:44:40 +0530 | [diff] [blame] | 210 | me.default_customer = r.message.default_customer || null; |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 211 | me.write_off_account = r.message.write_off_account; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 212 | localStorage.setItem('doc', JSON.stringify(r.message.doc)); |
| 213 | if(callback){ |
| 214 | callback(); |
| 215 | } |
| 216 | } |
| 217 | }) |
| 218 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 219 | |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 220 | save_previous_entry : function(){ |
| 221 | if(this.frm.doc.items.length > 0){ |
| 222 | this.create_invoice() |
| 223 | } |
| 224 | }, |
| 225 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 226 | create_new: function(){ |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 227 | var me = this; |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 228 | this.frm = {} |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 229 | this.name = ''; |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 230 | this.load_data(true); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 231 | this.setup(); |
| 232 | }, |
| 233 | |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 234 | load_data: function(load_doc){ |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 235 | this.items = window.items; |
| 236 | this.customers = window.customers; |
| 237 | this.pricing_rules = window.pricing_rules; |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 238 | |
| 239 | if(load_doc) { |
| 240 | this.frm.doc = JSON.parse(localStorage.getItem('doc')); |
| 241 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 242 | |
| 243 | $.each(window.meta, function(i, data){ |
| 244 | frappe.meta.sync(data) |
| 245 | }) |
| 246 | |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 247 | this.print_template = frappe.render_template("print_template", |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 248 | {content: window.print_template, title:"POS"}) |
| 249 | }, |
| 250 | |
| 251 | setup: function(){ |
| 252 | this.wrapper.html(frappe.render_template("pos", this.frm.doc)); |
| 253 | this.set_transaction_defaults("Customer"); |
| 254 | this.make(); |
| 255 | this.set_primary_action(); |
| 256 | }, |
| 257 | |
| 258 | set_transaction_defaults: function(party) { |
| 259 | var me = this; |
| 260 | this.party = party; |
| 261 | this.price_list = (party == "Customer" ? |
| 262 | this.frm.doc.selling_price_list : this.frm.doc.buying_price_list); |
| 263 | this.price_list_field = (party == "Customer" ? "selling_price_list" : "buying_price_list"); |
| 264 | this.sales_or_purchase = (party == "Customer" ? "Sales" : "Purchase"); |
| 265 | }, |
| 266 | |
| 267 | make: function() { |
| 268 | this.make_search(); |
| 269 | this.make_customer(); |
| 270 | this.make_item_list(); |
| 271 | this.make_discount_field() |
| 272 | }, |
| 273 | |
| 274 | make_search: function() { |
| 275 | var me = this; |
| 276 | this.search = frappe.ui.form.make_control({ |
| 277 | df: { |
| 278 | "fieldtype": "Data", |
| 279 | "label": "Item", |
| 280 | "fieldname": "pos_item", |
Rohit Waghchaure | 26cf01a | 2016-07-22 13:24:33 +0530 | [diff] [blame] | 281 | "placeholder": __("Search Item") |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 282 | }, |
| 283 | parent: this.wrapper.find(".search-area"), |
| 284 | only_input: true, |
| 285 | }); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 286 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 287 | this.search.make_input(); |
| 288 | this.search.$input.on("keyup", function() { |
| 289 | setTimeout(function() { |
| 290 | me.items = me.get_items(); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 291 | me.make_item_list(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 292 | }, 1000); |
| 293 | }); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 294 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 295 | this.party_field = frappe.ui.form.make_control({ |
| 296 | df: { |
| 297 | "fieldtype": "Data", |
| 298 | "options": this.party, |
| 299 | "label": this.party, |
| 300 | "fieldname": this.party.toLowerCase(), |
Rushabh Mehta | e0686b3 | 2016-06-10 12:34:41 +0530 | [diff] [blame] | 301 | "placeholder": __("Select or add new customer") |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 302 | }, |
| 303 | parent: this.wrapper.find(".party-area"), |
| 304 | only_input: true, |
| 305 | }); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 306 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 307 | this.party_field.make_input(); |
| 308 | }, |
| 309 | |
| 310 | make_customer: function() { |
| 311 | var me = this; |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 312 | |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 313 | if(this.default_customer && !this.frm.doc.customer){ |
Rohit Waghchaure | 539e913 | 2016-07-07 16:44:40 +0530 | [diff] [blame] | 314 | this.party_field.$input.val(this.default_customer); |
| 315 | this.frm.doc.customer = this.default_customer; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 316 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 317 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 318 | this.party_field.$input.autocomplete({ |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 319 | autoFocus: true, |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 320 | source: function (request, response) { |
| 321 | me.customer_data = me.get_customers(request.term) |
| 322 | response($.map(me.customer_data, function(data){ |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 323 | return {label: data.name, value: data.name, |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 324 | customer_group: data.customer_group, territory: data.territory} |
| 325 | })) |
| 326 | }, |
| 327 | change: function(event, ui){ |
| 328 | if(ui.item){ |
| 329 | me.frm.doc.customer = ui.item.label; |
| 330 | me.frm.doc.customer_name = ui.item.customer_name; |
| 331 | me.frm.doc.customer_group = ui.item.customer_group; |
| 332 | me.frm.doc.territory = ui.item.territory; |
| 333 | }else{ |
| 334 | me.frm.doc.customer = me.party_field.$input.val(); |
| 335 | } |
| 336 | me.refresh(); |
| 337 | } |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 338 | }).on("focus", function(){ |
| 339 | setTimeout(function() { |
| 340 | if(!me.party_field.$input.val()) { |
| 341 | me.party_field.$input.autocomplete( "search", " " ); |
| 342 | } |
| 343 | }, 500); |
| 344 | }); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 345 | }, |
| 346 | |
| 347 | get_customers: function(key){ |
| 348 | var me = this; |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 349 | key = key.toLowerCase().trim() |
| 350 | if(key){ |
| 351 | return $.grep(this.customers, function(data) { |
| 352 | if(data.name.toLowerCase().match(key) |
| 353 | || data.customer_name.toLowerCase().match(key) |
| 354 | || (data.customer_group && data.customer_group.toLowerCase().match(key))){ |
| 355 | return data |
| 356 | } |
| 357 | }) |
| 358 | }else{ |
| 359 | customers = this.customers.sort(function(a,b){ return a.idx < b.idx }) |
| 360 | return customers.slice(0, 20) |
| 361 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 362 | }, |
| 363 | |
| 364 | make_item_list: function() { |
| 365 | var me = this; |
| 366 | if(!this.price_list) { |
| 367 | msgprint(__("Price List not found or disabled")); |
| 368 | return; |
| 369 | } |
| 370 | |
| 371 | me.item_timeout = null; |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 372 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 373 | var $wrap = me.wrapper.find(".item-list"); |
| 374 | me.wrapper.find(".item-list").empty(); |
| 375 | |
| 376 | if (this.items) { |
| 377 | $.each(this.items, function(index, obj) { |
| 378 | if(index < 16){ |
| 379 | $(frappe.render_template("pos_item", { |
| 380 | item_code: obj.name, |
| 381 | item_price: format_currency(obj.price_list_rate, obj.currency), |
| 382 | item_name: obj.name===obj.item_name ? "" : obj.item_name, |
| 383 | item_image: obj.image ? "url('" + obj.image + "')" : null, |
| 384 | color: frappe.get_palette(obj.item_name), |
| 385 | abbr: frappe.get_abbr(obj.item_name) |
| 386 | })).tooltip().appendTo($wrap); |
| 387 | } |
| 388 | }); |
| 389 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 390 | |
Rohit Waghchaure | 28c02fe | 2016-06-10 00:48:03 +0530 | [diff] [blame] | 391 | if(this.items.length == 1 |
| 392 | && this.search.$input.val()) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 393 | this.search.$input.val(""); |
| 394 | this.add_to_cart(); |
| 395 | } |
| 396 | |
| 397 | // if form is local then allow this function |
| 398 | $(me.wrapper).find("div.pos-item").on("click", function() { |
| 399 | me.customer_validate(); |
| 400 | if(me.frm.doc.docstatus==0) { |
| 401 | me.items = me.get_items($(this).attr("data-item-code")) |
| 402 | me.add_to_cart(); |
| 403 | } |
| 404 | }); |
| 405 | }, |
| 406 | |
| 407 | get_items: function(item_code){ |
| 408 | // To search item as per the key enter |
| 409 | |
| 410 | var me = this; |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 411 | this.item_serial_no = {}; |
| 412 | this.item_batch_no = {}; |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 413 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 414 | if(item_code){ |
| 415 | return $.grep(window.items, function(item){ |
| 416 | if(item.item_code == item_code ){ |
| 417 | return true |
| 418 | } |
| 419 | }) |
| 420 | } |
| 421 | |
| 422 | key = this.search.$input.val().toLowerCase(); |
| 423 | |
| 424 | if(key){ |
| 425 | return $.grep(window.items, function(item){ |
| 426 | if( (item.item_code.toLowerCase().match(key)) || |
| 427 | (item.item_name.toLowerCase().match(key)) || (item.item_group.toLowerCase().match(key)) ){ |
| 428 | return true |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 429 | }else if(item.barcode == me.search.$input.val()){ |
| 430 | return item.barcode == me.search.$input.val(); |
| 431 | } else if (in_list(Object.keys(item.serial_nos), me.search.$input.val())){ |
| 432 | me.item_serial_no[item.item_code] = [me.search.$input.val(), item.serial_nos[me.search.$input.val()]] |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 433 | return true |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 434 | } else if(in_list(item.batch_nos, me.search.$input.val())){ |
| 435 | return me.item_batch_no[item.item_code] = me.search.$input.val() |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 436 | } |
| 437 | }) |
| 438 | }else{ |
| 439 | return window.items; |
| 440 | } |
| 441 | }, |
| 442 | |
| 443 | update_qty: function() { |
| 444 | var me = this; |
| 445 | |
| 446 | $(this.wrapper).find(".pos-item-qty").on("change", function(){ |
| 447 | var item_code = $(this).parents(".pos-bill-item").attr("data-item-code"); |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 448 | me.update_qty_rate_against_item_code(item_code, "qty", $(this).val()); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 449 | }) |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 450 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 451 | $(this.wrapper).find("[data-action='increase-qty']").on("click", function(){ |
| 452 | var item_code = $(this).parents(".pos-bill-item").attr("data-item-code"); |
| 453 | var qty = flt($(this).parents(".pos-bill-item").find('.pos-item-qty').val()) + 1; |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 454 | me.update_qty_rate_against_item_code(item_code, "qty", qty); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 455 | }) |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 456 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 457 | $(this.wrapper).find("[data-action='decrease-qty']").on("click", function(){ |
| 458 | var item_code = $(this).parents(".pos-bill-item").attr("data-item-code"); |
| 459 | var qty = flt($(this).parents(".pos-bill-item").find('.pos-item-qty').val()) - 1; |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 460 | me.update_qty_rate_against_item_code(item_code, "qty", qty); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 461 | }) |
| 462 | }, |
| 463 | |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 464 | update_rate: function() { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 465 | var me = this; |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 466 | |
| 467 | $(this.wrapper).find(".pos-item-rate").on("change", function(){ |
| 468 | var item_code = $(this).parents(".pos-bill-item").attr("data-item-code"); |
| 469 | me.update_qty_rate_against_item_code(item_code, "rate", $(this).val()); |
| 470 | }) |
| 471 | }, |
| 472 | |
| 473 | update_qty_rate_against_item_code: function(item_code, field, value){ |
| 474 | var me = this; |
| 475 | if(value < 0){ |
| 476 | frappe.throw(__("Enter value must be positive")); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 477 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 478 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 479 | this.remove_item = [] |
| 480 | $.each(this.frm.doc["items"] || [], function(i, d) { |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 481 | if (d.item_code == item_code && d.serial_no |
| 482 | && field == 'qty' && cint(value) != value) { |
| 483 | d.qty = 0.0; |
| 484 | me.refresh(); |
| 485 | frappe.throw(__("Serial no item cannot be a fraction")) |
| 486 | } |
| 487 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 488 | if (d.item_code == item_code) { |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 489 | d[field] = flt(value); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 490 | d.amount = flt(d.rate) * flt(d.qty); |
| 491 | if(d.qty==0){ |
| 492 | me.remove_item.push(d.idx) |
| 493 | } |
| 494 | } |
| 495 | }); |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 496 | |
| 497 | if(field == 'qty'){ |
| 498 | this.remove_zero_qty_item(); |
| 499 | } |
| 500 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 501 | this.refresh(); |
| 502 | }, |
| 503 | |
| 504 | remove_zero_qty_item: function(){ |
| 505 | var me = this; |
| 506 | idx = 0 |
| 507 | this.items = [] |
| 508 | idx = 0 |
| 509 | $.each(this.frm.doc["items"] || [], function(i, d) { |
| 510 | if(!in_list(me.remove_item, d.idx)){ |
| 511 | d.idx = idx; |
| 512 | me.items.push(d); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 513 | idx++; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 514 | } |
| 515 | }); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 516 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 517 | this.frm.doc["items"] = this.items; |
| 518 | }, |
| 519 | |
| 520 | make_discount_field: function(){ |
| 521 | var me = this; |
| 522 | |
| 523 | this.wrapper.find('input.discount-percentage').on("change", function() { |
| 524 | me.frm.doc.additional_discount_percentage = flt($(this).val(), precision("additional_discount_percentage")); |
| 525 | total = me.frm.doc.grand_total |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 526 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 527 | if(me.frm.doc.apply_discount_on == 'Net Total'){ |
| 528 | total = me.frm.doc.net_total |
| 529 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 530 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 531 | me.frm.doc.discount_amount = flt(total*flt(me.frm.doc.additional_discount_percentage) / 100, precision("discount_amount")); |
| 532 | me.wrapper.find('input.discount-amount').val(me.frm.doc.discount_amount) |
| 533 | me.refresh(); |
| 534 | }); |
| 535 | |
| 536 | this.wrapper.find('input.discount-amount').on("change", function() { |
| 537 | me.frm.doc.discount_amount = flt($(this).val(), precision("discount_amount")); |
| 538 | me.frm.doc.additional_discount_percentage = 0.0; |
| 539 | me.wrapper.find('input.discount-percentage').val(0); |
| 540 | me.refresh(); |
| 541 | }); |
| 542 | }, |
| 543 | |
| 544 | customer_validate: function(){ |
| 545 | var me = this; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 546 | if(!this.frm.doc.customer){ |
| 547 | frappe.throw(__("Please select customer")) |
| 548 | } |
| 549 | }, |
| 550 | |
| 551 | add_to_cart: function() { |
| 552 | var me = this; |
| 553 | var caught = false; |
| 554 | var no_of_items = me.wrapper.find(".pos-bill-item").length; |
| 555 | |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 556 | this.customer_validate(); |
| 557 | this.mandatory_batch_no(); |
| 558 | this.validate_serial_no(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 559 | this.validate_warehouse(); |
| 560 | |
| 561 | if (no_of_items != 0) { |
| 562 | $.each(this.frm.doc["items"] || [], function(i, d) { |
| 563 | if (d.item_code == me.items[0].item_code) { |
| 564 | caught = true; |
| 565 | d.qty += 1; |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 566 | d.amount = flt(d.rate) * flt(d.qty); |
| 567 | if(me.item_serial_no[d.item_code]){ |
| 568 | d.serial_no += '\n' + me.item_serial_no[d.item_code][0] |
| 569 | d.warehouse = me.item_serial_no[d.item_code][1] |
| 570 | } |
| 571 | |
| 572 | if(me.item_batch_no.length){ |
| 573 | d.batch_no = me.item_batch_no[d.item_code] |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 574 | } |
| 575 | } |
| 576 | }); |
| 577 | } |
| 578 | |
| 579 | // if item not found then add new item |
| 580 | if (!caught) |
| 581 | this.add_new_item_to_grid(); |
| 582 | |
| 583 | this.refresh(); |
| 584 | }, |
| 585 | |
| 586 | add_new_item_to_grid: function() { |
| 587 | var me = this; |
| 588 | this.child = frappe.model.add_child(this.frm.doc, this.frm.doc.doctype + " Item", "items"); |
| 589 | this.child.item_code = this.items[0].item_code; |
| 590 | this.child.item_name = this.items[0].item_name; |
| 591 | this.child.stock_uom = this.items[0].stock_uom; |
| 592 | this.child.description = this.items[0].description; |
| 593 | this.child.qty = 1; |
| 594 | this.child.item_group = this.items[0].item_group; |
| 595 | this.child.cost_center = this.items[0].cost_center; |
| 596 | this.child.income_account = this.items[0].income_account; |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 597 | this.child.warehouse = (this.item_serial_no[this.child.item_code] |
| 598 | ? this.item_serial_no[this.child.item_code][1] : this.items[0].default_warehouse); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 599 | this.child.price_list_rate = flt(this.items[0].price_list_rate, 9) / flt(this.frm.doc.conversion_rate, 9); |
| 600 | this.child.rate = flt(this.items[0].price_list_rate, 9) / flt(this.frm.doc.conversion_rate, 9); |
| 601 | this.child.actual_qty = this.items[0].actual_qty; |
| 602 | this.child.amount = flt(this.child.qty) * flt(this.child.rate); |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 603 | this.child.batch_no = this.item_batch_no[this.child.item_code]; |
| 604 | this.child.serial_no = (this.item_serial_no[this.child.item_code] |
| 605 | ? this.item_serial_no[this.child.item_code][0] : ''); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 606 | }, |
| 607 | |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 608 | refresh: function(update_paid_amount) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 609 | var me = this; |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 610 | this.refresh_fields(update_paid_amount); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 611 | this.update_qty(); |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 612 | this.update_rate(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 613 | this.set_primary_action(); |
| 614 | }, |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 615 | refresh_fields: function(update_paid_amount) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 616 | this.apply_pricing_rule(); |
| 617 | this.discount_amount_applied = false; |
| 618 | this._calculate_taxes_and_totals(); |
| 619 | this.calculate_discount_amount(); |
| 620 | this.show_items_in_item_cart(); |
| 621 | this.set_taxes(); |
Rohit Waghchaure | ea278b5 | 2016-07-21 23:28:04 +0530 | [diff] [blame] | 622 | this.calculate_outstanding_amount(update_paid_amount); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 623 | this.set_totals(); |
| 624 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 625 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 626 | get_company_currency: function() { |
| 627 | return erpnext.get_currency(this.frm.doc.company); |
| 628 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 629 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 630 | show_item_wise_taxes: function(){ |
| 631 | return null; |
| 632 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 633 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 634 | show_items_in_item_cart: function() { |
| 635 | var me = this; |
| 636 | var $items = this.wrapper.find(".items").empty(); |
| 637 | me.frm.doc.net_total = 0.0 |
| 638 | $.each(this.frm.doc.items|| [], function(i, d) { |
| 639 | $(frappe.render_template("pos_bill_item", { |
| 640 | item_code: d.item_code, |
| 641 | item_name: (d.item_name===d.item_code || !d.item_name) ? "" : ("<br>" + d.item_name), |
| 642 | qty: d.qty, |
| 643 | actual_qty: d.actual_qty, |
| 644 | projected_qty: d.projected_qty, |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 645 | rate: format_number(d.rate, me.frm.doc.currency), |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 646 | amount: format_currency(d.amount, me.frm.doc.currency) |
| 647 | })).appendTo($items); |
| 648 | }); |
| 649 | |
| 650 | this.wrapper.find("input.pos-item-qty").on("focus", function() { |
| 651 | $(this).select(); |
| 652 | }); |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 653 | |
| 654 | this.wrapper.find("input.pos-item-rate").on("focus", function() { |
| 655 | $(this).select(); |
| 656 | }); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 657 | }, |
| 658 | |
| 659 | set_taxes: function(){ |
| 660 | var me = this; |
| 661 | me.frm.doc.total_taxes_and_charges = 0.0 |
| 662 | |
| 663 | var taxes = this.frm.doc.taxes || []; |
| 664 | $(this.wrapper) |
| 665 | .find(".tax-area").toggleClass("hide", (taxes && taxes.length) ? false : true) |
| 666 | .find(".tax-table").empty(); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 667 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 668 | $.each(taxes, function(i, d) { |
| 669 | if (d.tax_amount && cint(d.included_in_print_rate) == 0) { |
| 670 | $(frappe.render_template("pos_tax_row", { |
| 671 | description: d.description, |
| 672 | tax_amount: format_currency(flt(d.tax_amount_after_discount_amount), |
| 673 | me.frm.doc.currency) |
| 674 | })).appendTo(me.wrapper.find(".tax-table")); |
| 675 | } |
| 676 | }); |
| 677 | }, |
| 678 | |
| 679 | set_totals: function() { |
| 680 | var me = this; |
| 681 | this.wrapper.find(".net-total").text(format_currency(me.frm.doc.total, me.frm.doc.currency)); |
| 682 | this.wrapper.find(".grand-total").text(format_currency(me.frm.doc.grand_total, me.frm.doc.currency)); |
| 683 | }, |
| 684 | |
| 685 | set_primary_action: function() { |
| 686 | var me = this; |
| 687 | |
Rohit Waghchaure | 61b4a43 | 2016-07-20 11:21:51 +0530 | [diff] [blame] | 688 | if (this.frm.doc.docstatus==0) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 689 | this.page.set_primary_action(__("Pay"), function() { |
| 690 | me.validate() |
| 691 | me.create_invoice(); |
| 692 | me.make_payment(); |
Faris Ansari | 8908d19 | 2016-07-20 13:59:19 +0530 | [diff] [blame] | 693 | }, "octicon octicon-credit-card"); |
Rohit Waghchaure | 61b4a43 | 2016-07-20 11:21:51 +0530 | [diff] [blame] | 694 | }else if(this.frm.doc.docstatus == 1) { |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 695 | this.page.set_primary_action(__("Print"), function() { |
| 696 | html = frappe.render(me.print_template, me.frm.doc) |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 697 | me.print_document(html) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 698 | }) |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 699 | }else { |
| 700 | this.page.clear_primary_action() |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 701 | } |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 702 | |
| 703 | this.page.set_secondary_action(__("New"), function() { |
| 704 | me.save_previous_entry(); |
| 705 | me.create_new(); |
Faris Ansari | 8908d19 | 2016-07-20 13:59:19 +0530 | [diff] [blame] | 706 | }, "octicon octicon-plus").addClass("btn-primary"); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 707 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 708 | |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 709 | print_document: function(html){ |
| 710 | var w = window.open(); |
| 711 | w.document.write(html); |
| 712 | w.document.close(); |
| 713 | setTimeout(function(){ |
| 714 | w.print(); |
| 715 | w.close(); |
| 716 | }, 1000) |
| 717 | }, |
| 718 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 719 | write_off_amount: function(){ |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 720 | var me = this; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 721 | var value = 0.0; |
| 722 | |
| 723 | if(this.frm.doc.outstanding_amount > 0){ |
| 724 | dialog = new frappe.ui.Dialog({ |
| 725 | title: 'Write Off Amount', |
| 726 | fields: [ |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 727 | {fieldtype: "Check", fieldname: "write_off_amount", label: __("Write off Outstanding Amount")}, |
| 728 | {fieldtype: "Link", options:"Account", default:this.write_off_account, fieldname: "write_off_account", |
| 729 | label: __("Write off Account"), get_query: function() { |
| 730 | return { |
| 731 | filters: {'is_group': 0, 'report_type': 'Profit and Loss'} |
| 732 | } |
| 733 | }} |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 734 | ] |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 735 | }); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 736 | |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 737 | dialog.show(); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 738 | |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 739 | dialog.fields_dict.write_off_amount.$input.change(function(){ |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 740 | write_off_amount = dialog.get_values().write_off_amount; |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 741 | me.frm.doc.write_off_outstanding_amount_automatically = write_off_amount; |
| 742 | me.frm.doc.base_write_off_amount = (write_off_amount==1) ? flt(me.frm.doc.grand_total - me.frm.doc.paid_amount, precision("outstanding_amount")) : 0; |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 743 | me.frm.doc.write_off_account = (write_off_amount==1) ? dialog.get_values().write_off_account : ''; |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 744 | me.frm.doc.write_off_amount = flt(me.frm.doc.base_write_off_amount * me.frm.doc.conversion_rate, precision("write_off_amount")) |
| 745 | me.calculate_outstanding_amount(); |
Rohit Waghchaure | 9fe40d5 | 2016-06-13 21:37:10 +0530 | [diff] [blame] | 746 | me.set_primary_action(); |
| 747 | }) |
| 748 | |
| 749 | dialog.fields_dict.write_off_account.$input.change(function(){ |
| 750 | me.frm.doc.write_off_account = dialog.get_values().write_off_account; |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 751 | }) |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 752 | |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 753 | dialog.set_primary_action(__("Submit"), function(){ |
| 754 | dialog.hide() |
| 755 | me.submit_invoice() |
| 756 | }) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 757 | }else{ |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 758 | this.submit_invoice() |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 759 | } |
| 760 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 761 | |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 762 | submit_invoice: function(){ |
| 763 | var me = this; |
| 764 | frappe.confirm(__("Do you really want to submit the invoice?"), function () { |
| 765 | me.change_status(); |
Rohit Waghchaure | 53bea82 | 2016-07-06 16:09:26 +0530 | [diff] [blame] | 766 | frappe.msgprint(__("Sales invoice submitted sucessfully.")) |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 767 | }) |
| 768 | }, |
| 769 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 770 | change_status: function(){ |
| 771 | if(this.frm.doc.docstatus == 0){ |
| 772 | this.frm.doc.docstatus = 1; |
| 773 | this.update_invoice(); |
| 774 | this.disable_input_field(); |
| 775 | } |
| 776 | }, |
| 777 | |
| 778 | disable_input_field: function(){ |
| 779 | var pointer_events = 'inherit' |
| 780 | $(this.wrapper).find('input').attr("disabled", false); |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 781 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 782 | if(this.frm.doc.docstatus == 1){ |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 783 | pointer_events = 'none'; |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 784 | $(this.wrapper).find('input').attr("disabled", true); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 785 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 786 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 787 | $(this.wrapper).find('.pos-bill-wrapper').css('pointer-events', pointer_events); |
| 788 | $(this.wrapper).find('.pos-items-section').css('pointer-events', pointer_events); |
| 789 | this.set_primary_action(); |
| 790 | }, |
| 791 | |
| 792 | create_invoice: function(){ |
| 793 | var me = this; |
| 794 | var invoice_data = {} |
| 795 | this.si_docs = this.get_doc_from_localstorage(); |
| 796 | if(this.name){ |
| 797 | this.update_invoice() |
| 798 | }else{ |
| 799 | this.name = $.now(); |
| 800 | invoice_data[this.name] = this.frm.doc |
| 801 | this.si_docs.push(invoice_data) |
| 802 | this.update_localstorage(); |
| 803 | this.set_primary_action(); |
| 804 | } |
| 805 | }, |
| 806 | |
| 807 | update_invoice: function(){ |
| 808 | var me = this; |
| 809 | this.si_docs = this.get_doc_from_localstorage(); |
| 810 | $.each(this.si_docs, function(index, data){ |
| 811 | for(key in data){ |
| 812 | if(key == me.name){ |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 813 | me.si_docs[index][key] = me.frm.doc; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 814 | me.update_localstorage(); |
| 815 | } |
| 816 | } |
| 817 | }) |
| 818 | }, |
| 819 | |
| 820 | update_localstorage: function(){ |
| 821 | try{ |
| 822 | localStorage.setItem('sales_invoice_doc', JSON.stringify(this.si_docs)); |
| 823 | }catch(e){ |
| 824 | frappe.throw(__("LocalStorage is full , did not save")) |
| 825 | } |
| 826 | }, |
| 827 | |
| 828 | get_doc_from_localstorage: function(){ |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 829 | try{ |
| 830 | return JSON.parse(localStorage.getItem('sales_invoice_doc')) || []; |
| 831 | }catch(e){ |
| 832 | return [] |
| 833 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 834 | }, |
| 835 | |
| 836 | set_interval_for_si_sync: function(){ |
| 837 | var me = this; |
| 838 | setInterval(function(){ |
| 839 | me.sync_sales_invoice() |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 840 | }, 60000) |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 841 | }, |
| 842 | |
| 843 | sync_sales_invoice: function(){ |
| 844 | var me = this; |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 845 | this.si_docs = this.get_submitted_invoice(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 846 | |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 847 | if(this.si_docs.length){ |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 848 | frappe.call({ |
| 849 | method: "erpnext.accounts.doctype.sales_invoice.pos.make_invoice", |
| 850 | args: { |
| 851 | doc_list: me.si_docs |
| 852 | }, |
| 853 | callback: function(r){ |
| 854 | if(r.message){ |
| 855 | me.removed_items = r.message; |
| 856 | me.remove_doc_from_localstorage(); |
| 857 | } |
| 858 | } |
| 859 | }) |
| 860 | } |
| 861 | }, |
| 862 | |
| 863 | get_submitted_invoice: function(){ |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 864 | var invoices = []; |
| 865 | var index = 1; |
| 866 | docs = this.get_doc_from_localstorage(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 867 | if(docs){ |
| 868 | invoices = $.map(docs, function(data){ |
| 869 | for(key in data){ |
Rohit Waghchaure | f2aa176 | 2016-05-20 23:55:45 +0530 | [diff] [blame] | 870 | if(data[key].docstatus == 1 && index < 50){ |
| 871 | index++ |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 872 | return data |
| 873 | } |
| 874 | } |
| 875 | }); |
| 876 | } |
| 877 | |
| 878 | return invoices |
| 879 | }, |
| 880 | |
| 881 | remove_doc_from_localstorage: function(){ |
| 882 | var me = this; |
| 883 | this.si_docs = this.get_doc_from_localstorage(); |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 884 | this.new_si_docs = []; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 885 | if(this.removed_items){ |
| 886 | $.each(this.si_docs, function(index, data){ |
| 887 | for(key in data){ |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 888 | if(!in_list(me.removed_items, key)){ |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 889 | me.new_si_docs.push(data); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 890 | } |
| 891 | } |
| 892 | }) |
Rohit Waghchaure | e0934d1 | 2016-05-11 15:04:57 +0530 | [diff] [blame] | 893 | this.si_docs = this.new_si_docs; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 894 | this.update_localstorage(); |
| 895 | } |
| 896 | }, |
| 897 | |
| 898 | validate: function(){ |
| 899 | var me = this; |
| 900 | this.customer_validate(); |
| 901 | this.item_validate(); |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 902 | this.validate_mode_of_payments(); |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 903 | }, |
| 904 | |
| 905 | item_validate: function(){ |
| 906 | if(this.frm.doc.items.length == 0){ |
| 907 | frappe.throw(__("Select items to save the invoice")) |
| 908 | } |
| 909 | }, |
Saurabh | 9a6c666 | 2016-06-27 16:51:44 +0530 | [diff] [blame] | 910 | |
| 911 | validate_mode_of_payments: function(){ |
| 912 | if (this.frm.doc.payments.length === 0){ |
| 913 | frappe.throw(__("Payment Mode is not configured. Please check, whether account has been set on Mode of Payments or on POS Profile.")) |
| 914 | } |
| 915 | }, |
| 916 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 917 | validate_serial_no: function(){ |
| 918 | var me = this; |
| 919 | var item_code = serial_no = ''; |
| 920 | for (key in this.item_serial_no){ |
| 921 | item_code = key; |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 922 | serial_no = me.item_serial_no[key][0]; |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 923 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 924 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 925 | if(item_code && serial_no){ |
| 926 | $.each(this.frm.doc.items, function(index, data){ |
| 927 | if(data.item_code == item_code){ |
| 928 | if(in_list(data.serial_no.split('\n'), serial_no)){ |
| 929 | frappe.throw(__(repl("Serial no %(serial_no)s is already taken", { |
| 930 | 'serial_no': serial_no |
| 931 | }))) |
| 932 | } |
| 933 | } |
| 934 | }) |
| 935 | } |
Rohit Waghchaure | 03da40b | 2016-07-16 03:02:20 +0530 | [diff] [blame] | 936 | |
| 937 | if(this.items[0].has_serial_no && serial_no == ""){ |
| 938 | frappe.throw(__(repl("Error: Serial no is mandatory for item %(item)s", { |
| 939 | 'item': this.items[0].item_code |
| 940 | }))) |
| 941 | } |
| 942 | }, |
| 943 | |
| 944 | mandatory_batch_no: function(){ |
| 945 | var me = this; |
| 946 | if(this.items[0].has_batch_no && !this.item_batch_no[this.items[0].item_code]){ |
| 947 | frappe.throw(__(repl("Error: Batch no is mandatory for item %(item)s", { |
| 948 | 'item': this.items[0].item_code |
| 949 | }))) |
| 950 | } |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 951 | }, |
| 952 | |
| 953 | apply_pricing_rule: function(){ |
| 954 | var me = this; |
| 955 | $.each(this.frm.doc["items"], function(n, item) { |
| 956 | pricing_rule = me.get_pricing_rule(item) |
| 957 | me.validate_pricing_rule(pricing_rule) |
| 958 | if(pricing_rule.length){ |
| 959 | item.margin_type = pricing_rule[0].margin_type; |
| 960 | item.price_list_rate = pricing_rule[0].price || item.price_list_rate; |
| 961 | item.margin_rate_or_amount = pricing_rule[0].margin_rate_or_amount; |
| 962 | item.discount_percentage = pricing_rule[0].discount_percentage || 0.0; |
| 963 | me.apply_pricing_rule_on_item(item) |
| 964 | } |
| 965 | }) |
| 966 | }, |
| 967 | |
| 968 | get_pricing_rule: function(item){ |
| 969 | var me = this; |
| 970 | return $.grep(this.pricing_rules, function(data){ |
| 971 | if(data.item_code == item.item_code || in_list(['All Item Groups', item.item_group], data.item_group)) { |
| 972 | if(in_list(['Customer', 'Customer Group', 'Territory'], data.applicable_for)){ |
| 973 | return me.validate_condition(data) |
| 974 | }else{ |
| 975 | return true |
| 976 | } |
| 977 | } |
| 978 | }) |
| 979 | }, |
| 980 | |
| 981 | validate_condition: function(data){ |
| 982 | //This method check condition based on applicable for |
| 983 | condition = this.get_mapper_for_pricing_rule(data)[data.applicable_for] |
| 984 | if(in_list(condition[1], condition[0])){ |
| 985 | return true |
| 986 | } |
| 987 | }, |
| 988 | |
| 989 | get_mapper_for_pricing_rule: function(data){ |
| 990 | return { |
Rohit Waghchaure | 89ee309 | 2016-07-08 15:17:04 +0530 | [diff] [blame] | 991 | 'Customer': [data.customer, [this.frm.doc.customer]], |
| 992 | 'Customer Group': [data.customer_group, [this.frm.doc.customer_group, 'All Customer Groups']], |
| 993 | 'Territory': [data.territory, [this.frm.doc.territory, 'All Territories']], |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 994 | } |
| 995 | }, |
| 996 | |
| 997 | validate_pricing_rule: function(pricing_rule){ |
| 998 | //This method validate duplicate pricing rule |
| 999 | var pricing_rule_name = ''; |
| 1000 | var priority = 0; |
| 1001 | var pricing_rule_list = []; |
| 1002 | var priority_list = [] |
| 1003 | |
| 1004 | if(pricing_rule.length > 1){ |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1005 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1006 | $.each(pricing_rule, function(index, data){ |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1007 | pricing_rule_name += data.name + ',' |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1008 | priority_list.push(data.priority) |
| 1009 | if(priority <= data.priority){ |
| 1010 | priority = data.priority |
| 1011 | pricing_rule_list.push(data) |
| 1012 | } |
| 1013 | }) |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1014 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1015 | count = 0 |
| 1016 | $.each(priority_list, function(index, value){ |
| 1017 | if(value == priority){ |
| 1018 | count++ |
| 1019 | } |
| 1020 | }) |
| 1021 | |
| 1022 | if(priority == 0 || count > 1){ |
| 1023 | frappe.throw(__(repl("Multiple Price Rules exists with same criteria, please resolve conflict by assigning priority. Price Rules: %(pricing_rule)s", { |
| 1024 | 'pricing_rule': pricing_rule_name |
| 1025 | }))) |
| 1026 | } |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1027 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1028 | return pricing_rule_list |
| 1029 | } |
| 1030 | }, |
Rushabh Mehta | d0cee1b | 2016-05-20 12:54:44 +0530 | [diff] [blame] | 1031 | |
Rohit Waghchaure | 6087fe1 | 2016-04-09 14:31:09 +0530 | [diff] [blame] | 1032 | validate_warehouse: function(){ |
| 1033 | if(!this.items[0].default_warehouse){ |
| 1034 | frappe.throw(__("Deafault warehouse is required for selected item")) |
| 1035 | } |
| 1036 | } |
| 1037 | }) |