[sales_invoice] [pos] [minor] Added view for POS
diff --git a/accounts/doctype/sales_invoice/pos.js b/accounts/doctype/sales_invoice/pos.js
new file mode 100644
index 0000000..7dc8186
--- /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('<div class="customer-area"></div>\
+ <div class="item-area"></div>\
+ <div><button class="btn btn-default btn-add">Add</button>');
+
+ 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("<div>%(item_code)s</div>", 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 aa21d5d..cfb5e95 100644
--- a/accounts/doctype/sales_invoice/sales_invoice.js
+++ b/accounts/doctype/sales_invoice/sales_invoice.js
@@ -25,6 +25,7 @@
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 @@
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 @@
}
})
});
+
+ // 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();
},