[feature] [customer login] send links in email for portal access of Sales Order, Sales Invoice, Delivery Note and Suppor Ticket
diff --git a/config.json b/config.json
index d30c697..e0f98d8 100644
--- a/config.json
+++ b/config.json
@@ -103,7 +103,12 @@
 				"no_cache": true,
 				"template": "app/website/templates/pages/sale",
 				"args_method": "website.helpers.transaction.get_order_args",
-				"for_doctype": "Sales Order"
+				"portal": {
+					"doctype": "Sales Order",
+					"conditions": {
+						"docstatus": 1
+					}
+				}
 			},
 			"orders": {
 				"no_cache": true,
@@ -114,7 +119,12 @@
 				"no_cache": true,
 				"template": "app/website/templates/pages/sale",
 				"args_method": "website.helpers.transaction.get_invoice_args",
-				"for_doctype": "Sales Invoice"
+				"portal": {
+					"doctype": "Sales Invoice",
+					"conditions": {
+						"docstatus": 1
+					}
+				}
 			},
 			"invoices": {
 				"no_cache": true,
@@ -125,7 +135,12 @@
 				"no_cache": true,
 				"template": "app/website/templates/pages/sale",
 				"args_method": "website.helpers.transaction.get_shipment_args",
-				"for_doctype": "Delivery Note"
+				"portal": {
+					"doctype": "Delivery Note",
+					"conditions": {
+						"docstatus": 1
+					}
+				}
 			},
 			"shipments": {
 				"no_cache": true,
@@ -139,7 +154,9 @@
 				"no_cache": true,
 				"template": "app/website/templates/pages/ticket",
 				"args_method": "support.doctype.support_ticket.support_ticket.get_website_args",
-				"for_doctype": "Support Ticket"
+				"portal": {
+					"doctype": "Support Ticket"
+				}
 			},
 			"tickets": {
 				"template": "app/website/templates/pages/tickets",
diff --git a/public/js/website_utils.js b/public/js/website_utils.js
index 1b7f0f7..9b78326 100644
--- a/public/js/website_utils.js
+++ b/public/js/website_utils.js
@@ -1,7 +1,6 @@
 // Copyright (c) 2013, Web Notes Technologies Pvt. Ltd.
 // License: GNU General Public License v3. See license.txt
 
-
 if(!window.erpnext) erpnext = {};
 if(!window.wn) wn = {};
 
@@ -200,7 +199,7 @@
 	update_cart: function(opts) {
 		if(!full_name) {
 			if(localStorage) {
-				localStorage.setItem("last_visited", window.location.pathname.slice(1));
+				localStorage.setItem("last_visited", window.location.href.split("/").slice(-1)[0]);
 				localStorage.setItem("pending_add_to_cart", opts.item_code);
 			}
 			window.location.href = "login";
@@ -242,4 +241,13 @@
 		return false;
 	}
 	return true;
+}
+
+function ask_to_login() {
+	if(!full_name) {
+		if(localStorage) {
+			localStorage.setItem("last_visited", window.location.href.split("/").slice(-1)[0]);
+		}
+		window.location.href = "login";
+	}
 }
\ No newline at end of file
diff --git a/website/templates/pages/sale.html b/website/templates/pages/sale.html
index 669a380..1c03da2 100644
--- a/website/templates/pages/sale.html
+++ b/website/templates/pages/sale.html
@@ -11,6 +11,9 @@
     	<li class="active"><i class="icon-file icon-fixed-width"></i> {{ doc.name }}</li>
     </ul>
 	<h3><i class="icon-file icon-fixed-width"></i> {{ doc.name }}</h3>
+	{% if doc.name == "Not Allowed" -%}
+		<script>ask_to_login();</script>
+	{% else %}
 	<hr>
 	<div>
 	<div class="row">
@@ -82,5 +85,6 @@
 		</div>
 	</div>
 	</div>
+	{%- endif %}
 </div>
 {% endblock %}
\ No newline at end of file
diff --git a/website/templates/pages/ticket.html b/website/templates/pages/ticket.html
index eeb485a..6622ed1 100644
--- a/website/templates/pages/ticket.html
+++ b/website/templates/pages/ticket.html
@@ -17,6 +17,9 @@
     	<li class="active"><i class="icon-ticket icon-fixed-width"></i> {{ doc.name }}</li>
     </ul>
 	<h3><i class="icon-ticket icon-fixed-width"></i> {{ doc.name }}</h3>
+	{% if doc.name == "Not Allowed" -%}
+		<script>ask_to_login();</script>
+	{% else %}
 	<hr>
 	{%- if doc.status -%}
 	{% if doc.status == "Waiting for Customer" -%}
@@ -46,6 +49,7 @@
 					<td>
 					<h5 style="text-transform: none">
 						{{ comm.sender }} on {{ utils.formatdate(doc.modified) }}</h5>
+					<hr>
 					<p>{{ webnotes.utils.is_html(comm.content) and comm.content or
 						comm.content.replace("\n", "<br>")}}</p>
 					</td>
@@ -58,5 +62,6 @@
 	<div class="alert">No messages</div>
 	{%- endif -%}
 	{%- endif -%}
+	{% endif -%}
 </div>
 {% endblock %}
\ No newline at end of file
diff --git a/website/templates/pages/transaction_list.html b/website/templates/pages/transaction_list.html
new file mode 100644
index 0000000..967a6a8
--- /dev/null
+++ b/website/templates/pages/transaction_list.html
@@ -0,0 +1,77 @@
+{% extends "app/website/templates/html/page.html" %}
+
+{% block content %}
+<div class="col-md-12">
+    <ul class="breadcrumb">
+    	<li><a href="index">Home</a></li>
+    	<li><a href="account">My Account</a></li>
+    	<li class="active"><i class="{{ icon }} icon-fixed-width"></i> {{ title }}</li>
+    </ul>
+	<div class="list-group transaction-list">
+		<div class="progress progress-striped active">
+			<div class="progress-bar progress-bar-info" style="width: 100%;"></div>
+		</div>
+	</div>
+	<div class="text-center">
+		<button class="btn btn-default btn-show-more" style="display: none;">More</button></div>
+</div>
+{% endblock %}
+
+{% block javascript %}
+global_number_format = "{{ global_number_format }}";
+currency = "{{ currency }}";
+wn.currency_symbols = {{ currency_symbols }};
+
+$(document).ready(function() {
+	var start = 0;
+	var $list = $(".transaction-list");
+	
+	var $show_more = $(".btn-show-more").on("click", function() {
+		get_transactions(this);
+	});
+	
+	var get_transactions = function(btn) {
+		wn.call({
+			method: "{{ method }}",
+			args: { start: start },
+			btn: btn,
+			callback: function(r) {
+				$list.find(".progress").remove();
+				$show_more.toggle(!(r.message && r.message.length===20));
+				
+				if(!(r.message && r.message.length)) {
+					console.log("empty");
+					if(!$list.html().trim()) {
+						$list.html("<div class='alert alert-warning'>\
+							{{ empty_list_message }}</div>");
+					}
+					return;
+				}
+			
+				start += r.message.length;
+			
+				$.each(r.message, function(i, doc) {
+					render(doc);
+				});
+			}
+		})
+	};
+	
+	var render = function(doc) {
+		doc.grand_total_export = format_currency(doc.grand_total_export, doc.currency);
+		
+		var $row = $(repl('<a href="{{ page }}?name=%(name)s" class="list-group-item">\
+				<div class="row">\
+					<div class="col-md-6">\
+						<div class="row col-md-12">%(name)s</div>\
+						<div class="row col-md-12 text-muted">%(items)s...</div>\
+					</div>\
+					<div class="col-md-3 text-right">%(grand_total_export)s</div>\
+					<div class="col-md-3 text-right text-muted">%(creation)s</div>\
+				</div>\
+			</a>', doc)).appendTo($list);
+	};
+	
+	get_transactions();
+});
+{% endblock %}
\ No newline at end of file