From 4a008f55673aa16595b343a7ecd70c56b8f57067 Mon Sep 17 00:00:00 2001 From: Rushabh Mehta Date: Mon, 29 Jul 2013 15:31:11 +0530 Subject: [PATCH] [sales_invoice] [pos] [minor] Added view for POS --- accounts/doctype/sales_invoice/pos.js | 57 +++++++++++++++++++ .../doctype/sales_invoice/sales_invoice.js | 27 +++++++++ 2 files changed, 84 insertions(+) create mode 100644 accounts/doctype/sales_invoice/pos.js diff --git a/accounts/doctype/sales_invoice/pos.js b/accounts/doctype/sales_invoice/pos.js new file mode 100644 index 0000000000..7dc8186d67 --- /dev/null +++ b/accounts/doctype/sales_invoice/pos.js @@ -0,0 +1,57 @@ +erpnext.POS = Class.extend({ + init: function(wrapper, frm) { + this.wrapper = wrapper; + this.frm = frm; + this.wrapper.html('
\ +
\ +
'); + + this.make(); + + var me = this; + $(this.frm.wrapper).on("refresh-fields", function() { + me.refresh(); + }); + + }, + make: function() { + this.make_customer(); + this.make_items(); + }, + make_customer: function() { + var me = this; + this.customer = wn.ui.form.make_control({ + df: { + "fieldtype": "Link", + "options": "Customer", + "label": "Customer", + "fieldname": "pos_customer" + }, + parent: this.wrapper.find(".customer-area") + }); + this.customer.make_input(); + this.customer.$input.on("change", function() { + if(!me.customer.autocomplete_open) + wn.model.set_value("Sales Invoice", me.frm.docname, "customer", this.value); + }); + }, + make_items: function() { + var me = this; + this.wrapper.find(".btn-add").click(function() { + var child = wn.model.add_child(me.frm.doc, "Sales Invoice Item", "entries"); + child.item_code = "Test Item"; + me.frm.cscript.item_code(me.frm.doc, child.doctype, child.name); + }); + }, + refresh: function() { + var me = this; + this.customer.set_input(this.frm.doc.customer); + + // add items + var $items = me.wrapper.find(".item-area").empty(); + $.each(wn.model.get_children("Sales Invoice Item", this.frm.doc.name, "entries", + "Sales Invoice"), function(i, d) { + $(repl("
%(item_code)s
", d)).appendTo($items); + }); + } +}) \ No newline at end of file diff --git a/accounts/doctype/sales_invoice/sales_invoice.js b/accounts/doctype/sales_invoice/sales_invoice.js index aa21d5dd7e..cfb5e95981 100644 --- a/accounts/doctype/sales_invoice/sales_invoice.js +++ b/accounts/doctype/sales_invoice/sales_invoice.js @@ -25,6 +25,7 @@ cur_frm.pformat.print_heading = 'Invoice'; wn.require('app/accounts/doctype/sales_taxes_and_charges_master/sales_taxes_and_charges_master.js'); wn.require('app/utilities/doctype/sms_control/sms_control.js'); wn.require('app/selling/doctype/sales_common/sales_common.js'); +wn.require('app/accounts/doctype/sales_invoice/pos.js'); wn.provide("erpnext.accounts"); erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.extend({ @@ -37,6 +38,10 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte this.frm.set_df_property("debit_to", "print_hide", 0); } } + + // if(this.frm.doc.is_pos && this.frm.doc.docstatus===0) { + // cur_frm.cscript.toggle_pos(true); + // } }, refresh: function(doc, dt, dn) { @@ -95,12 +100,34 @@ erpnext.accounts.SalesInvoiceController = erpnext.selling.SellingController.exte } }) }); + + // cur_frm.add_custom_button(wn._("POS View"), function() { + // cur_frm.cscript.toggle_pos(); + // }, 'icon-desktop'); } cur_frm.cscript.hide_fields(doc, dt, dn); }, + toggle_pos: function(show) { + if((show===true && cur_frm.pos_active) || (show===false && !cur_frm.pos_active)) return; + + // make pos + if(!cur_frm.pos) { + cur_frm.layout.add_view("pos"); + cur_frm.pos = new erpnext.POS(cur_frm.layout.views.pos, cur_frm); + } + + // toggle view + cur_frm.layout.set_view(cur_frm.pos_active ? "" : "pos"); + cur_frm.pos_active = !cur_frm.pos_active; + + // refresh + if(cur_frm.pos_active) + cur_frm.pos.refresh(); + + }, tc_name: function() { this.get_terms(); },