[Enhancement] POS
diff --git a/erpnext/public/js/controllers/payments.js b/erpnext/public/js/controllers/payments.js
new file mode 100644
index 0000000..7ac2b7b
--- /dev/null
+++ b/erpnext/public/js/controllers/payments.js
@@ -0,0 +1,158 @@
+// Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
+// License: GNU General Public License v3. See license.txt
+
+erpnext.payments = erpnext.stock.StockController.extend({
+	make_payment: function() {
+		var me = this;
+
+		this.dialog = new frappe.ui.Dialog({
+			title: 'Payment'
+		});
+	
+		this.dialog.show();
+		this.$body = this.dialog.body;
+		this.dialog.$wrapper.find('.modal-dialog').css("width", "750px");
+		this.set_payment_primary_action();
+		this.make_keyboard();
+	},
+
+	set_payment_primary_action: function(){
+		var me = this;
+	
+		this.dialog.set_primary_action(__("Submit"), function() {
+			frappe.confirm(__("Do you really want to submit the invoice?"), function () {
+				me.write_off_amount();
+				me.dialog.hide();
+			})
+		})
+	},
+
+	make_keyboard: function(){
+		var me = this;
+		$(this.$body).empty();
+		$(this.$body).html(frappe.render_template('pos_payment', this.frm.doc))
+		this.show_payment_details();
+		this.bind_keyboard_event()
+	},
+
+	pay_amount: function(){
+		var me = this;
+		this.make_multimode_payment();
+		this.calculate_outstanding_amount()
+		this.show_payment_details();
+	},
+
+	make_multimode_payment: function(){
+		var me = this;
+
+		if(this.frm.doc.change_amount > 0){
+			me.payment_val = me.doc.outstanding_amount
+		}
+
+		this.payments = frappe.model.add_child(this.frm.doc, 'Multi Mode Payment', "payments");
+		this.payments.mode_of_payment = this.dialog.fields_dict.mode_of_payment.get_value();
+		this.payments.amount = flt(this.payment_val);
+	},
+
+	show_payment_details: function(){
+		var me = this;
+		multimode_payments = $(this.$body).find('.multimode-payments').empty();
+		if(this.frm.doc.payments.length){
+			$.each(this.frm.doc.payments, function(index, data){
+				$(frappe.render_template('payment_details', {
+					mode_of_payment: data.mode_of_payment,
+					amount: data.amount,
+					idx: data.idx,
+					currency: me.frm.doc.currency,
+					type: data.type
+				})).appendTo(multimode_payments)
+			})
+		}else{
+			$("<p>No payment mode selected in pos profile</p>").appendTo(multimode_payments)
+		}
+	},
+	
+	bind_keyboard_event: function(){
+		var me = this;
+		this.payment_val = '';
+		this.bind_payment_mode_keys_event();
+		this.bind_keyboard_keys_event();
+	},
+	
+	bind_payment_mode_keys_event: function(){
+		var me = this;
+		$(this.$body).find('.pos-payment-row').click(function(){
+			me.idx = $(this).attr("idx");
+			me.selected_mode = $(me.$body).find(repl("input[idx='%(idx)s']",{'idx': me.idx}));
+			me.highlight_selected_row()
+			me.payment_val = 0.0
+			if(me.frm.doc.outstanding_amount > 0 && flt(me.selected_mode.val()) == 0.0){
+				//When user first time click on row
+				me.payment_val = flt(me.frm.doc.outstanding_amount)
+				me.selected_mode.val(format_number(me.payment_val, 2));
+				me.update_paid_amount()
+				me.bind_amount_change_event();
+			}else if(flt(me.selected_mode.val()) > 0){
+				//If user click on existing row which has value
+				me.payment_val = flt(me.selected_mode.val());
+			}
+			me.selected_mode.select()
+		})
+	},
+	
+	highlight_selected_row: function(){
+		var me = this;
+		selected_row = $(this.$body).find(repl(".pos-payment-row[idx='%(idx)s']",{'idx': this.idx}));
+		$(this.$body).find('.pos-payment-row').removeClass('selected-payment-mode')
+		selected_row.addClass('selected-payment-mode')
+		$(this.$body).find('.amount').attr('disabled', true);
+		this.selected_mode.attr('disabled', false);
+	},
+	
+	bind_keyboard_keys_event: function(){
+		var me = this;
+		$(this.$body).find('.pos-keyboard-key').click(function(){
+			me.payment_val += $(this).text();
+			me.selected_mode.val(format_number(me.payment_val, 2))
+			me.idx = me.selected_mode.attr("idx")
+			me.update_paid_amount()
+		})
+		
+		$(this.$body).find('.delete-btn').click(function(){
+			me.payment_val =  cstr(flt(me.selected_mode.val())).slice(0, -1);
+			me.selected_mode.val(format_number(me.payment_val, 2));
+			me.idx = me.selected_mode.attr("idx")
+			me.update_paid_amount();
+		})
+
+	},
+	
+	bind_amount_change_event: function(){
+		var me = this;
+		me.selected_mode.change(function(){
+			me.payment_val =  $(this).val() || 0.0;
+			me.selected_mode.val(format_number(me.payment_val, 2))
+			me.idx = me.selected_mode.attr("idx")
+			me.update_paid_amount()
+		})
+	},
+	
+	update_paid_amount: function(){
+		var me = this;
+		$.each(this.frm.doc.payments, function(index, data){
+			if(cint(me.idx) == cint(data.idx)){
+				data.amount = flt(me.selected_mode.val(), 2)
+			}
+		})
+		this.calculate_outstanding_amount();
+		this.show_amounts();
+	},
+	
+	show_amounts: function(){
+		var me = this;
+		$(this.$body).find('.paid_amount').text(format_currency(this.frm.doc.paid_amount, this.frm.doc.currency));
+		$(this.$body).find('.change_amount').text(format_currency(this.frm.doc.change_amount, this.frm.doc.currency))
+		$(this.$body).find('.outstanding_amount').text(format_currency(this.frm.doc.outstanding_amount, this.frm.doc.currency))
+		this.update_invoice();
+	}
+})
\ No newline at end of file
diff --git a/erpnext/public/js/controllers/taxes_and_totals.js b/erpnext/public/js/controllers/taxes_and_totals.js
index 1a234a3..f775f29 100644
--- a/erpnext/public/js/controllers/taxes_and_totals.js
+++ b/erpnext/public/js/controllers/taxes_and_totals.js
@@ -1,13 +1,30 @@
 // Copyright (c) 2015, Frappe Technologies Pvt. Ltd. and Contributors
 // License: GNU General Public License v3. See license.txt
 
-erpnext.taxes_and_totals = erpnext.stock.StockController.extend({
+erpnext.taxes_and_totals = erpnext.payments.extend({
+	apply_pricing_rule_on_item: function(item){
+		if(!item.margin_type){
+			item.margin_rate_or_amount = 0.0;
+		}
+
+		if(item.margin_type == "Percentage"){
+			item.total_margin = item.price_list_rate + item.price_list_rate * ( item.margin_rate_or_amount / 100);
+		}else{
+			item.total_margin = item.price_list_rate + item.margin_rate_or_amount;
+		}
+
+		item.rate = flt(item.total_margin , 2);
+
+		if(item.discount_percentage){
+			discount_value = flt(item.total_margin) * flt(item.discount_percentage) / 100;
+			item.rate = flt((item.total_margin) - (discount_value), precision('rate'));
+		}
+	},
+
 	calculate_taxes_and_totals: function(update_paid_amount) {
 		this.discount_amount_applied = false;
 		this._calculate_taxes_and_totals();
-
-		if (frappe.meta.get_docfield(this.frm.doc.doctype, "discount_amount"))
-			this.apply_discount_amount();
+		this.calculate_discount_amount();
 
 		// Advance calculation applicable to Sales /Purchase Invoice
 		if(in_list(["Sales Invoice", "Purchase Invoice"], this.frm.doc.doctype)
@@ -24,6 +41,11 @@
 		this.frm.refresh_fields();
 	},
 
+	calculate_discount_amount: function(){
+		if (frappe.meta.get_docfield(this.frm.doc.doctype, "discount_amount"))
+			this.apply_discount_amount();
+	},
+
 	_calculate_taxes_and_totals: function() {
 		this.validate_conversion_rate();
 		this.calculate_item_values();
@@ -98,7 +120,7 @@
 
 			$.each(tax_fields, function(i, fieldname) { tax[fieldname] = 0.0 });
 
-			if (!this.discount_amount_applied) {
+			if (!this.discount_amount_applied && cur_frm) {
 				cur_frm.cscript.validate_taxes_and_charges(tax.doctype, tax.name);
 				me.validate_inclusive_tax(tax);
 			}
@@ -433,13 +455,14 @@
 	apply_discount_amount: function() {
 		var me = this;
 		var distributed_amount = 0.0;
+		this.frm.doc.base_discount_amount = 0.0;
 
 		if (this.frm.doc.discount_amount) {
 			if(!this.frm.doc.apply_discount_on)
 				frappe.throw(__("Please select Apply Discount On"));
-
-			this.frm.set_value("base_discount_amount",
-				flt(this.frm.doc.discount_amount * this.frm.doc.conversion_rate, precision("base_discount_amount")))
+			
+			this.frm.doc.base_discount_amount = flt(this.frm.doc.discount_amount * this.frm.doc.conversion_rate, 
+				precision("base_discount_amount"));
 
 			var total_for_discount_amount = this.get_total_for_discount_amount();
 			// calculate item amount after Discount Amount
@@ -455,8 +478,6 @@
 				this.discount_amount_applied = true;
 				this._calculate_taxes_and_totals();
 			}
-		} else {
-			this.frm.set_value("base_discount_amount", 0);
 		}
 	},
 
@@ -524,18 +545,59 @@
 				this.frm.doc.paid_amount = 0
 			}
 			this.set_in_company_currency(this.frm.doc, ["paid_amount"]);
-			this.frm.refresh_field("paid_amount");
-			this.frm.refresh_field("base_paid_amount");
+
+			if(this.frm.refresh_field){
+				this.frm.refresh_field("paid_amount");
+				this.frm.refresh_field("base_paid_amount");
+			}
+			
+			if(this.frm.doc.doctype == "Sales Invoice"){
+				this.calculate_paid_amount()
+			}
+			
+			var outstanding_amount = 0.0
 
 			var paid_amount = (this.frm.doc.party_account_currency == this.frm.doc.currency) ?
 				this.frm.doc.paid_amount : this.frm.doc.base_paid_amount;
 
-			var outstanding_amount =  flt(total_amount_to_pay - flt(paid_amount),
-				precision("outstanding_amount"));
+			if (total_amount_to_pay > paid_amount){
+				outstanding_amount =  flt(total_amount_to_pay - flt(paid_amount),
+					precision("outstanding_amount"));
+			}
 
 		} else if(this.frm.doc.doctype == "Purchase Invoice") {
 			var outstanding_amount = flt(total_amount_to_pay, precision("outstanding_amount"));
 		}
-		this.frm.set_value("outstanding_amount", outstanding_amount);
-	}
+
+		this.frm.doc.outstanding_amount = outstanding_amount;
+		this.calculate_change_amount()
+	},
+	
+	calculate_paid_amount: function(){
+		var me = this;
+		var paid_amount = base_paid_amount = 0.0;
+		$.each(this.frm.doc['payments'] || [], function(index, data){
+			if(data.amount > 0){
+				data.base_amount = flt(data.amount * me.frm.doc.conversion_rate);
+				paid_amount += data.amount;
+				base_paid_amount += data.base_amount;	
+			}
+		})
+		
+		this.frm.doc.paid_amount = flt(paid_amount, precision("paid_amount"));
+		this.frm.doc.base_paid_amount = flt(base_paid_amount, precision("base_paid_amount"));
+	},
+	
+	calculate_change_amount: function(){
+		var change_amount = 0.0;
+		if(this.frm.doc.paid_amount > this.frm.doc.grand_total){
+			change_amount = flt(this.frm.doc.paid_amount - this.frm.doc.grand_total, 
+				precision("change_amount"))
+		}
+		
+		this.frm.doc.change_amount = flt(change_amount, 
+			precision("change_amount"))
+		this.frm.doc.base_change_amount = flt(change_amount * this.frm.doc.conversion_rate, 
+			precision("base_change_amount"))
+	},
 })
diff --git a/erpnext/public/js/controllers/transaction.js b/erpnext/public/js/controllers/transaction.js
index 3f6ea5a..c622466 100644
--- a/erpnext/public/js/controllers/transaction.js
+++ b/erpnext/public/js/controllers/transaction.js
@@ -165,7 +165,7 @@
 		erpnext.hide_company();
 		this.show_item_wise_taxes();
 		this.set_dynamic_labels();
-		erpnext.pos.make_pos_btn(this.frm);
+		// erpnext.pos.make_pos_btn(this.frm);
 		this.setup_sms();
 		this.make_show_payments_btn();
 	},
@@ -550,7 +550,7 @@
 		setup_field_label_map(["base_total", "base_net_total", "base_total_taxes_and_charges",
 			"base_discount_amount", "base_grand_total", "base_rounded_total", "base_in_words",
 			"base_taxes_and_charges_added", "base_taxes_and_charges_deducted", "total_amount_to_pay",
-			"base_paid_amount", "base_write_off_amount"
+			"base_paid_amount", "base_write_off_amount", "base_change_amount"
 		], company_currency);
 
 		setup_field_label_map(["total", "net_total", "total_taxes_and_charges", "discount_amount",
diff --git a/erpnext/public/js/payment/payment_details.html b/erpnext/public/js/payment/payment_details.html
new file mode 100644
index 0000000..b0f61d8
--- /dev/null
+++ b/erpnext/public/js/payment/payment_details.html
@@ -0,0 +1,4 @@
+<div class="row pos-payment-row" type="{{type}}" idx={{idx}}>
+    <div class="col-xs-6"><h5 class="payment-mode text-ellipsis" idx="{{idx}}"> {{mode_of_payment}} </h5></div>
+	<div class="col-xs-6 text-right"><input disabled data-fieldtype="Currency" class="input-with-feedback form-control text-right amount" idx="{{idx}}" type="text" value="{{format_number(amount, 2)}}"></div>
+</div>
\ No newline at end of file
diff --git a/erpnext/public/js/payment/pos_payment.html b/erpnext/public/js/payment/pos_payment.html
new file mode 100644
index 0000000..e93644d
--- /dev/null
+++ b/erpnext/public/js/payment/pos_payment.html
@@ -0,0 +1,40 @@
+<div class="pos_payment row">
+    	<div class="col-sm-6">
+			<div class="row">
+				<div class="col-xs-6 text-center"> 
+					<p class="amount-label"> Total <h3>{%= format_currency(grand_total, currency) %} </h3></p>
+				</div>
+				<div class="col-xs-6 text-center"> 
+					<p class="amount-label"> Paid <h3 class="paid_amount">{%= format_currency(paid_amount, currency) %}</h3></p>
+				</div>              
+			</div>
+				<hr>
+			<div class="multimode-payments">
+    		</div>
+    	</div>
+    	<div class="col-sm-6">
+            <div class="row">
+				<div class="col-xs-6 text-center"> 
+					<p class="amount-label"> Outstanding <h3 class="outstanding_amount">{%= format_currency(outstanding_amount, currency) %} </h3></p>
+				</div>
+				<div class="col-xs-6 text-center"> 
+					<p class="amount-label"> Change <h3 class="change_amount">{%= format_currency(change_amount, currency) %}</h3></p>
+				</div>              
+            </div>
+			<hr>
+            <div class="payment-toolbar">
+				{% for(var i=0; i<3; i++) { %}
+					<div class="row">
+						{% for(var j=i*3; j<(i+1)*3; j++) { %}
+							<button type="button"  class="btn btn-default pos-keyboard-key">{{j+1}}</button>
+						{% } %}
+					</div>
+				{% } %}   
+				<div class="row">
+					<button type="button"  class="btn btn-default delete-btn"><span class="mega-octicon octicon-triangle-left"></span></button>
+					<button type="button"  class="btn btn-default pos-keyboard-key">0</button>
+					<button type="button"  class="btn btn-default pos-keyboard-key">.</button>
+				</div>
+            </div>
+    	</div>
+</div>
diff --git a/erpnext/public/js/pos/pos.html b/erpnext/public/js/pos/pos.html
index 36ef7c9..9d0ab60 100644
--- a/erpnext/public/js/pos/pos.html
+++ b/erpnext/public/js/pos/pos.html
@@ -24,22 +24,24 @@
 							<div class="tax-table small"></div>
 						</div>
                     </div>
-                    <div class="row pos-bill-row discount-amount-area">
-                        <div class="col-xs-6"><h6 class="text-muted">{%= __("Discount") %}</h6></div>
-						<div class="col-xs-3 discount-field-col">
-							<div class="input-group input-group-sm">
-								<span class="input-group-addon">%</span>
-								<input type="text" class="form-control discount-percentage text-right">
+					{% if (apply_discount_on) { %}
+	                    <div class="row pos-bill-row discount-amount-area">
+	                        <div class="col-xs-6"><h6 class="text-muted">{%= __("Discount") %}</h6></div>
+							<div class="col-xs-3 discount-field-col">
+								<div class="input-group input-group-sm">
+									<span class="input-group-addon">%</span>
+									<input type="text" class="form-control discount-percentage text-right">
+								</div>
 							</div>
-						</div>
-                        <div class="col-xs-3 discount-field-col">
-							<div class="input-group input-group-sm">
-								<span class="input-group-addon">{%= get_currency_symbol(currency) %}</span>
-								<input type="text" class="form-control discount-amount text-right"
-							  		placeholder="{%= 0.00 %}">
+	                        <div class="col-xs-3 discount-field-col">
+								<div class="input-group input-group-sm">
+									<span class="input-group-addon">{%= get_currency_symbol(currency) %}</span>
+									<input type="text" class="form-control discount-amount text-right"
+								  		placeholder="{%= 0.00 %}">
+								</div>
 							</div>
-						</div>
-                    </div>
+	                    </div>
+					{% } %} 
                     <div class="row pos-bill-row grand-total-area">
                         <div class="col-xs-6"><h6>{%= __("Grand Total") %}</h6></div>
                         <div class="col-xs-6"><h6 class="grand-total text-right"></h6></div>
@@ -51,11 +53,12 @@
 			<div class="row pos-item-area">
 
 			</div>
+			<span id="customer-results" style="color:#68a;"></span>
             <div class="row pos-item-toolbar">
             	<div class="search-area col-xs-12"></div>
             </div>
     		<div class="item-list-area">
-				<div class="item-list"></div>
+				<div class="app-listing item-list"></ul>
     		</div>
     	</div>
     </div>
diff --git a/erpnext/public/js/pos/pos_bill_item.html b/erpnext/public/js/pos/pos_bill_item.html
index c93c76c..fe521f6 100644
--- a/erpnext/public/js/pos/pos_bill_item.html
+++ b/erpnext/public/js/pos/pos_bill_item.html
@@ -9,8 +9,7 @@
                 </div>
                 {% if(actual_qty != null) { %}
                 <div style="margin-top: 5px;" class="text-muted small text-right">
-                    <span title="{%= __("In Stock") %}">{%= actual_qty || 0 %}<span>
-                    <span title="{%= __("Projected") %}">({%= projected_qty || 0 %})<span>
+                    <span title="{%= __("In Stock") %}">{%= actual_qty || 0 %}<span>                
                 </div>
                 {% } %}
             </div>
diff --git a/erpnext/public/js/pos/pos_invoice_list.html b/erpnext/public/js/pos/pos_invoice_list.html
new file mode 100644
index 0000000..463b3e7
--- /dev/null
+++ b/erpnext/public/js/pos/pos_invoice_list.html
@@ -0,0 +1,5 @@
+<div class="row list-row pos-invoice-list" invoice-name = "{{name}}">
+	<div class="col-xs-6">{%= customer %}</div>
+	<div class="col-xs-3 text-right">{%= grand_total %}</div>
+	<div class="col-xs-3 text-right">{%= status %}</div>
+</div>
diff --git a/erpnext/public/js/pos/pos_print.html b/erpnext/public/js/pos/pos_print.html
new file mode 100644
index 0000000..d31a885
--- /dev/null
+++ b/erpnext/public/js/pos/pos_print.html
@@ -0,0 +1,25 @@
+<style>
+	.print-format table, .print-format tr, 
+	.print-format td, .print-format div, .print-format p {
+		font-family: Monospace;
+		line-height: 200%;
+		vertical-align: middle;
+	}
+	@media screen {
+		.print-format {
+			width: 4in;
+			padding: 0.25in;
+			min-height: 8in;
+		}
+	}
+</style>
+
+<p class="text-center">
+	{{ company }}<br>
+</p>
+<p>
+	{{currency}}
+</p>
+{% for item in items %}
+	<p> {{item.item_code}} </p>
+{% endfor %}
\ No newline at end of file