[shopping-cart] i'm back
diff --git a/erpnext/templates/includes/cart.js b/erpnext/templates/includes/cart.js
new file mode 100644
index 0000000..90cfea5
--- /dev/null
+++ b/erpnext/templates/includes/cart.js
@@ -0,0 +1,297 @@
+// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+// License: GNU General Public License v3. See license.txt
+
+// js inside blog page
+
+// shopping cart
+frappe.provide("shopping_cart");
+
+$.extend(shopping_cart, {
+ show_error: function(title, text) {
+ $("#cart-container").html('<div class="well"><h4>' + title + '</h4> ' + text + '</div>');
+ },
+
+ bind_events: function() {
+ // bind update button
+ $(document).on("click", ".item-update-cart button", function() {
+ var item_code = $(this).attr("data-item-code");
+ shopping_cart.update_cart({
+ item_code: item_code,
+ qty: $('input[data-item-code="'+item_code+'"]').val(),
+ with_doc: 1,
+ btn: this,
+ callback: function(r) {
+ if(!r.exc) {
+ shopping_cart.render(r.message);
+ var $button = $('button[data-item-code="'+item_code+'"]').addClass("btn-success");
+ setTimeout(function() { $button.removeClass("btn-success"); }, 1000);
+ }
+ },
+ });
+ });
+
+ $("#cart-add-shipping-address").on("click", function() {
+ window.location.href = "address?address_fieldname=shipping_address_name";
+ });
+
+ $("#cart-add-billing-address").on("click", function() {
+ window.location.href = "address?address_fieldname=customer_address";
+ });
+
+ $(".btn-place-order").on("click", function() {
+ shopping_cart.place_order(this);
+ });
+ },
+
+ render: function(out) {
+ var doc = out.doc;
+ var addresses = out.addresses;
+
+ var $cart_items = $("#cart-items").empty();
+ var $cart_taxes = $("#cart-taxes").empty();
+ var $cart_totals = $("#cart-totals").empty();
+ var $cart_billing_address = $("#cart-billing-address").empty();
+ var $cart_shipping_address = $("#cart-shipping-address").empty();
+
+ var no_items = $.map(doc.quotation_details || [],
+ function(d) { return d.item_code || null;}).length===0;
+ if(no_items) {
+ shopping_cart.show_error("Empty :-(", frappe._("Go ahead and add something to your cart."));
+ $("#cart-addresses").toggle(false);
+ return;
+ }
+
+ var shipping_rule_added = false;
+ var taxes_exist = false;
+ var shipping_rule_labels = $.map(out.shipping_rules || [], function(rule) { return rule[1]; });
+
+ $.each(doc.quotation_details || [], function(i, d) {
+ shopping_cart.render_item_row($cart_items, d);
+ });
+
+ $.each(doc.other_charges || [], function(i, d) {
+ if(out.shipping_rules && out.shipping_rules.length &&
+ shipping_rule_labels.indexOf(d.description)!==-1) {
+ shipping_rule_added = true;
+ shopping_cart.render_tax_row($cart_taxes, d, out.shipping_rules);
+ } else {
+ shopping_cart.render_tax_row($cart_taxes, d);
+ }
+
+ taxes_exist = true;
+ });
+
+ if(out.shipping_rules && out.shipping_rules.length && !shipping_rule_added) {
+ shopping_cart.render_tax_row($cart_taxes, {description: "", formatted_tax_amount: ""},
+ out.shipping_rules);
+ taxes_exist = true;
+ }
+
+ if(taxes_exist)
+ $('<hr>').appendTo($cart_taxes);
+
+ shopping_cart.render_tax_row($cart_totals, {
+ description: "<strong>Total</strong>",
+ formatted_tax_amount: "<strong>" + doc.formatted_grand_total_export + "</strong>"
+ });
+
+ if(!(addresses && addresses.length)) {
+ $cart_shipping_address.html('<div class="well">'+frappe._("Hey! Go ahead and add an address")+'</div>');
+ } else {
+ shopping_cart.render_address($cart_shipping_address, addresses, doc.shipping_address_name);
+ shopping_cart.render_address($cart_billing_address, addresses, doc.customer_address);
+ }
+ },
+
+ render_item_row: function($cart_items, doc) {
+ doc.image_html = doc.website_image ?
+ '<div style="height: 120px; overflow: hidden;"><img src="' + doc.website_image + '" /></div>' :
+ '{% include "templates/includes/product_missing_image.html" %}';
+
+ if(doc.description === doc.item_name) doc.description = "";
+
+ $(repl('<div class="row">\
+ <div class="col-md-9 col-sm-9">\
+ <div class="row">\
+ <div class="col-md-3">%(image_html)s</div>\
+ <div class="col-md-9">\
+ <h4><a href="%(page_name)s">%(item_name)s</a></h4>\
+ <p>%(description)s</p>\
+ </div>\
+ </div>\
+ </div>\
+ <div class="col-md-3 col-sm-3 text-right">\
+ <div class="input-group item-update-cart">\
+ <input type="text" placeholder="Qty" value="%(qty)s" \
+ data-item-code="%(item_code)s" class="text-right form-control">\
+ <div class="input-group-btn">\
+ <button class="btn btn-primary" data-item-code="%(item_code)s">\
+ <i class="icon-ok"></i></button>\
+ </div>\
+ </div>\
+ <p style="margin-top: 10px;">at %(formatted_rate)s</p>\
+ <small class="text-muted" style="margin-top: 10px;">= %(formatted_amount)s</small>\
+ </div>\
+ </div><hr>', doc)).appendTo($cart_items);
+ },
+
+ render_tax_row: function($cart_taxes, doc, shipping_rules) {
+ var shipping_selector;
+ if(shipping_rules) {
+ shipping_selector = '<select class="form-control">' + $.map(shipping_rules, function(rule) {
+ return '<option value="' + rule[0] + '">' + rule[1] + '</option>' }).join("\n") +
+ '</select>';
+ }
+
+ var $tax_row = $(repl('<div class="row">\
+ <div class="col-md-9 col-sm-9">\
+ <div class="row">\
+ <div class="col-md-9 col-md-offset-3">' +
+ (shipping_selector || '<p>%(description)s</p>') +
+ '</div>\
+ </div>\
+ </div>\
+ <div class="col-md-3 col-sm-3 text-right">\
+ <p' + (shipping_selector ? ' style="margin-top: 5px;"' : "") + '>%(formatted_tax_amount)s</p>\
+ </div>\
+ </div>', doc)).appendTo($cart_taxes);
+
+ if(shipping_selector) {
+ $tax_row.find('select option').each(function(i, opt) {
+ if($(opt).html() == doc.description) {
+ $(opt).attr("selected", "selected");
+ }
+ });
+ $tax_row.find('select').on("change", function() {
+ shopping_cart.apply_shipping_rule($(this).val(), this);
+ });
+ }
+ },
+
+ apply_shipping_rule: function(rule, btn) {
+ return frappe.call({
+ btn: btn,
+ type: "POST",
+ method: "erpnext.shopping_cart.cart.apply_shipping_rule",
+ args: { shipping_rule: rule },
+ callback: function(r) {
+ if(!r.exc) {
+ shopping_cart.render(r.message);
+ }
+ }
+ });
+ },
+
+ render_address: function($address_wrapper, addresses, address_name) {
+ $.each(addresses, function(i, address) {
+ $(repl('<div class="panel panel-default"> \
+ <div class="panel-heading"> \
+ <div class="row"> \
+ <div class="col-md-10 address-title" \
+ data-address-name="%(name)s"><strong>%(name)s</strong></div> \
+ <div class="col-md-2"><input type="checkbox" \
+ data-address-name="%(name)s"></div> \
+ </div> \
+ </div> \
+ <div class="panel-collapse collapse" data-address-name="%(name)s"> \
+ <div class="panel-body">%(display)s</div> \
+ </div> \
+ </div>', address))
+ .css({"margin": "10px auto"})
+ .appendTo($address_wrapper);
+ });
+
+ $address_wrapper.find(".panel-heading")
+ .find(".address-title")
+ .css({"cursor": "pointer"})
+ .on("click", function() {
+ $address_wrapper.find('.panel-collapse[data-address-name="'
+ +$(this).attr("data-address-name")+'"]').collapse("toggle");
+ });
+
+ $address_wrapper.find('input[type="checkbox"]').on("click", function() {
+ if($(this).prop("checked")) {
+ var me = this;
+ $address_wrapper.find('input[type="checkbox"]').each(function(i, chk) {
+ if($(chk).attr("data-address-name")!=$(me).attr("data-address-name")) {
+ $(chk).prop("checked", false);
+ }
+ });
+
+ return frappe.call({
+ type: "POST",
+ method: "erpnext.shopping_cart.cart.update_cart_address",
+ args: {
+ address_fieldname: $address_wrapper.attr("data-fieldname"),
+ address_name: $(this).attr("data-address-name")
+ },
+ callback: function(r) {
+ if(!r.exc) {
+ shopping_cart.render(r.message);
+ }
+ }
+ });
+ } else {
+ return false;
+ }
+ });
+
+ $address_wrapper.find('input[type="checkbox"][data-address-name="'+ address_name +'"]')
+ .prop("checked", true);
+
+ $address_wrapper.find(".panel-collapse").collapse({
+ parent: $address_wrapper,
+ toggle: false
+ });
+
+ $address_wrapper.find('.panel-collapse[data-address-name="'+ address_name +'"]')
+ .collapse("show");
+ },
+
+ place_order: function(btn) {
+ return frappe.call({
+ type: "POST",
+ method: "erpnext.shopping_cart.cart.place_order",
+ btn: btn,
+ callback: function(r) {
+ if(r.exc) {
+ var msg = "";
+ if(r._server_messages) {
+ msg = JSON.parse(r._server_messages || []).join("<br>");
+ }
+
+ $("#cart-error")
+ .empty()
+ .html(msg || frappe._("Something went wrong!"))
+ .toggle(true);
+ } else {
+ window.location.href = "order?name=" + encodeURIComponent(r.message);
+ }
+ }
+ });
+ }
+});
+
+$(document).ready(function() {
+ shopping_cart.bind_events();
+ return frappe.call({
+ type: "POST",
+ method: "erpnext.shopping_cart.cart.get_cart_quotation",
+ callback: function(r) {
+ $("#cart-container").removeClass("hide");
+ $(".progress").remove();
+ if(r.exc) {
+ if(r.exc.indexOf("WebsitePriceListMissingError")!==-1) {
+ shopping_cart.show_error("Oops!", frappe._("Price List not configured."));
+ } else if(r["403"]) {
+ shopping_cart.show_error("Hey!", frappe._("You need to be logged in to view your cart."));
+ } else {
+ shopping_cart.show_error("Oops!", frappe._("Something went wrong."));
+ }
+ } else {
+ shopping_cart.set_cart_count();
+ shopping_cart.render(r.message);
+ }
+ }
+ });
+});
diff --git a/erpnext/templates/includes/product_page.js b/erpnext/templates/includes/product_page.js
index 42d4ae7..03520fc 100644
--- a/erpnext/templates/includes/product_page.js
+++ b/erpnext/templates/includes/product_page.js
@@ -7,7 +7,7 @@
frappe.call({
type: "POST",
- method: "shopping_cart.shopping_cart.product.get_product_info",
+ method: "erpnext.shopping_cart.product.get_product_info",
args: {
item_code: "{{ name }}"
},
diff --git a/erpnext/templates/includes/sale.html b/erpnext/templates/includes/sale.html
new file mode 100644
index 0000000..e823248
--- /dev/null
+++ b/erpnext/templates/includes/sale.html
@@ -0,0 +1,85 @@
+<div class="sale-content">
+ <ul class="breadcrumb">
+ <li><a href="index">Home</a></li>
+ <li><a href="{{ parent_link }}">{{ parent_title }}</a></li>
+ <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">
+ <div class="col-xs-6">
+ {% if doc.status -%}{{ doc.status }}{%- endif %}
+ </div>
+ <div class="col-xs-6">
+ <span class="pull-right">{{ frappe.utils.formatdate(doc.posting_date or doc.transaction_date) }}</span>
+ </div>
+ </div>
+ <br>
+ <div class="row">
+ <div class="col-md-12">
+ <table class="table table-bordered">
+ <tbody>
+ <tr>
+ <th>Sr</th>
+ <th>Item Name</th>
+ <th>Description</th>
+ <th>Qty</th>
+ <th>UoM</th>
+ <th>Basic Rate</th>
+ <th>Amount</th>
+ </tr>
+ {%- for row in doc.get({"doctype": doc.doctype + " Item"}) %}
+ <tr>
+ <td style="width: 3%;">{{ row.idx }}</td>
+ <td style="width: 20%;">{{ row.item_name }}</td>
+ <td style="width: 37%;">{{ row.description }}</td>
+ <td style="width: 5%; text-align: right;">{{ row.qty }}</td>
+ <td style="width: 5%;">{{ row.stock_uom }}</td>
+ <td style="width: 15%; text-align: right;">{{ frappe.utils.fmt_money(row.rate, currency=doc.currency) }}</td>
+ <td style="width: 15%; text-align: right;">{{ frappe.utils.fmt_money(row.amount, currency=doc.currency) }}</td>
+ </tr>
+ {% endfor -%}
+ </tbody>
+ </table>
+ </div>
+ </div>
+ <div class="row">
+ <div class="col-md-6"></div>
+ <div class="col-md-6">
+ <table cellspacing=0 width=100%>
+ <tbody>
+ <tr>
+ <td>Net Total</td>
+ <td width=40% style="text-align: right;">{{
+ frappe.utils.fmt_money(doc.net_total/doc.conversion_rate, currency=doc.currency)
+ }}</td>
+ </tr>
+ {%- for charge in doc.get({"doctype":"Sales Taxes and Charges"}) -%}
+ {%- if not charge.included_in_print_rate -%}
+ <tr>
+ <td>{{ charge.description }}</td>
+ <td style="text-align: right;">{{ frappe.utils.fmt_money(charge.tax_amount / doc.conversion_rate, currency=doc.currency) }}</td>
+ </tr>
+ {%- endif -%}
+ {%- endfor -%}
+ <tr>
+ <td>Grand Total</td>
+ <td style="text-align: right;">{{ frappe.utils.fmt_money(doc.grand_total_export, currency=doc.currency) }}</td>
+ </tr>
+ <tr style='font-weight: bold'>
+ <td>Rounded Total</td>
+ <td style="text-align: right;">{{ frappe.utils.fmt_money(doc.rounded_total_export, currency=doc.currency) }}</td>
+ </tr>
+ </tbody>
+ </table>
+ </div>
+ </div>
+ </div>
+ {%- endif %}
+</div>
+
+<!-- no-sidebar -->
diff --git a/erpnext/templates/includes/sales_transactions.html b/erpnext/templates/includes/sales_transactions.html
new file mode 100644
index 0000000..e8717af
--- /dev/null
+++ b/erpnext/templates/includes/sales_transactions.html
@@ -0,0 +1,30 @@
+<script>
+$(document).ready(function() {
+ global_number_format = "{{ global_number_format }}";
+ currency = "{{ currency }}";
+ frappe.currency_symbols = {{ currency_symbols }};
+});
+</script>
+
+{% include "templates/includes/transactions.html" %}
+
+<script>
+ var render = function(doc) {
+ doc.grand_total_export = format_currency(doc.grand_total_export, doc.currency);
+ if(!doc.status) doc.status = "";
+
+ $(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 class="row col-md-12">%(status)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);
+ };
+</script>
+
+<!-- no-sidebar -->
diff --git a/erpnext/templates/includes/transactions.html b/erpnext/templates/includes/transactions.html
new file mode 100644
index 0000000..b0eda19
--- /dev/null
+++ b/erpnext/templates/includes/transactions.html
@@ -0,0 +1,53 @@
+<div class="transactions-content">
+ <ul class="breadcrumb">
+ <li><a href="index">Home</a></li>
+ <li class="active"><i class="{{ icon }} icon-fixed-width"></i> {{ title }}</li>
+ </ul>
+ <p id="msgprint-alert" class="alert alert-danger"
+ style="display: none;"> </p>
+ <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 hide">More</button>
+ </div>
+</div>
+<script>
+var get_transactions = function(btn) {
+ frappe.call({
+ method: "{{ method }}",
+ args: { start: start },
+ btn: btn,
+ callback: function(r) {
+ $list.find(".progress").remove();
+ $show_more.toggleClass("hide", !(r.message && r.message.length===20));
+ if(!(r.message && r.message.length)) {
+ if(!$list.html().trim()) {
+ $list.html("<div class='text-muted'>\
+ {{ empty_list_message }}</div>");
+ }
+ return;
+ }
+
+ start += r.message.length;
+
+ $.each(r.message, function(i, doc) {
+ render(doc);
+ });
+ }
+ })
+};
+
+$(document).ready(function() {
+ window.start = 0;
+ window.$list = $(".transaction-list");
+ window.$list.find(".list-group-item").remove();
+ window.$show_more = $(".btn-show-more").on("click", function() { get_transactions(this); })
+
+ get_transactions();
+});
+</script>
+
+<!-- no-sidebar -->
diff --git a/erpnext/templates/pages/address.html b/erpnext/templates/pages/address.html
new file mode 100644
index 0000000..95ddb76
--- /dev/null
+++ b/erpnext/templates/pages/address.html
@@ -0,0 +1,112 @@
+{% block title %} {{ title }} {% endblock %}
+
+{% block header %}<h2>{{ title }}</h2>{% endblock %}
+
+{% block content %}
+{% macro render_fields(docfields) -%}
+{% for df in docfields -%}
+ {% if df.fieldtype == "Data" -%}
+ <fieldset>
+ <label>{{ df.label }}</label>
+ <input class="form-control" type="text" placeholder="Type {{ df.label }}"
+ data-fieldname="{{ df.fieldname }}" data-fieldtype="{{ df.fieldtype }}"
+ {% if doc and doc.get(df.fieldname) -%} value="{{ doc[df.fieldname] }}" {%- endif %}>
+ </fieldset>
+ {% elif df.fieldtype == "Check" -%}
+ <fieldset class="checkbox">
+ <label><input type="checkbox" data-fieldname="{{ df.fieldname }}"
+ data-fieldtype="{{ df.fieldtype }}"
+ {% if doc and frappe.utils.cint(doc.get(df.fieldname)) -%} checked="checked" {%- endif %}>
+ {{ df.label }}</label>
+ </fieldset>
+ {% elif df.fieldtype in ("Select", "Link") -%}
+ <fieldset>
+ {% set select_options = frappe.get_list(df.options)|map(attribute="name")
+ if df.fieldtype == "Link" else df.options.split("\n") %}
+ <label>{{ df.label }}</label>
+ <select class="form-control" data-fieldname="{{ df.fieldname }}" data-fieldtype="{{ df.fieldtype }}">
+ {% for value in select_options -%}
+ {% if doc and doc.get(df.fieldname) == value -%}
+ <option selected="selected">{{ value }}</option>
+ {% else -%}
+ <option>{{ value }}</option>
+ {%- endif %}
+ {%- endfor %}
+ </select>
+ </fieldset>
+ {%- endif %}
+{%- endfor %}
+{%- endmacro %}
+
+<div class="container content">
+ <ul class="breadcrumb">
+ <li><a href="index">Home</a></li>
+ <li><a href="addresses">My Addresses</a></li>
+ <li class="active"><i class="icon-map-marker icon-fixed-width"></i> {{ title }}</li>
+ </ul>
+ <h3><i class="icon-map-marker icon-fixed-width"></i> {{ title }}</h3>
+ <button type="button" class="btn btn-primary pull-right" id="address-save"><i class="icon-ok"></i>
+ {{ doc and "Save" or "Insert" }}</button>
+ <div class="clearfix"></div>
+ <hr>
+ <div id="address-error" class="alert alert-danger" style="display:none"></div>
+ <form autocomplete="on">
+ <div class="row">
+ <section class="col-md-6">
+ {{ render_fields(meta.left_fields) }}
+ </section>
+ <section class="col-md-6">
+ {{ render_fields(meta.right_fields) }}
+ </section>
+ </section>
+ </form>
+</div>
+
+<script>
+;(function() {
+ console.log("yoyo");
+ frappe.ready(function() {
+ bind_save();
+ });
+
+ var bind_save = function() {
+ $("#address-save").on("click", function() {
+ console.log("clicked!");
+
+ var fields = {
+ name: "{{ docname or '' }}"
+ };
+
+ $("form").find("[data-fieldname]").each(function(i, input) {
+ var $input = $(input);
+ var fieldname = $(input).attr("data-fieldname");
+ var fieldtype = $(input).attr("data-fieldtype");
+
+ if(fieldtype == "Check") {
+ fields[fieldname] = $input.is(":checked") ? 1 : 0;
+ } else {
+ fields[fieldname] = $input.val();
+ }
+ });
+
+ frappe.call({
+ btn: $(this),
+ type: "POST",
+ method: "shopping_cart.templates.pages.address.save_address",
+ args: { fields: fields, address_fieldname: get_url_arg("address_fieldname") },
+ error_msg: "#address-error",
+ callback: function(r) {
+ if(get_url_arg("address_fieldname")) {
+ window.location.href = "cart";
+ } else {
+ window.location.href = "address?name=" + encodeURIComponent(r.message);
+ }
+ }
+ });
+ });
+ };
+})();
+</script>
+
+<!-- no-sidebar -->
+{% endblock %}
diff --git a/erpnext/templates/pages/address.py b/erpnext/templates/pages/address.py
new file mode 100644
index 0000000..46dde92
--- /dev/null
+++ b/erpnext/templates/pages/address.py
@@ -0,0 +1,62 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import json
+
+import frappe
+from erpnext.shopping_cart.cart import get_lead_or_customer, update_cart_address
+from frappe.desk.form.meta import get_meta
+
+no_cache = 1
+no_sitemap = 1
+
+def get_context(context):
+ def _get_fields(fieldnames):
+ return [frappe._dict(zip(["label", "fieldname", "fieldtype", "options"],
+ [df.label, df.fieldname, df.fieldtype, df.options]))
+ for df in get_meta("Address").get("fields", {"fieldname": ["in", fieldnames]})]
+
+ docname = doc = None
+ title = "New Address"
+ if frappe.form_dict.name:
+ doc = frappe.get_doc("Address", frappe.form_dict.name)
+ docname = doc.name
+ title = doc.name
+
+ return {
+ "doc": doc,
+ "meta": frappe._dict({
+ "left_fields": _get_fields(["address_title", "address_type", "address_line1", "address_line2",
+ "city", "state", "pincode", "country"]),
+ "right_fields": _get_fields(["email_id", "phone", "fax", "is_primary_address",
+ "is_shipping_address"])
+ }),
+ "docname": docname,
+ "title": title
+ }
+
+@frappe.whitelist()
+def save_address(fields, address_fieldname=None):
+ party = get_lead_or_customer()
+ fields = json.loads(fields)
+
+ if fields.get("name"):
+ doc = frappe.get_doc("Address", fields.get("name"))
+ else:
+ doc = frappe.get_doc({"doctype": "Address", "__islocal": 1})
+
+ doc.update(fields)
+
+ party_fieldname = party.doctype.lower()
+ doc.update({
+ party_fieldname: party.name,
+ (party_fieldname + "_name"): party.get(party_fieldname + "_name")
+ })
+ doc.ignore_permissions = True
+ doc.save()
+
+ if address_fieldname:
+ update_cart_address(address_fieldname, doc.name)
+
+ return doc.name
diff --git a/erpnext/templates/pages/addresses.html b/erpnext/templates/pages/addresses.html
new file mode 100644
index 0000000..58a9798
--- /dev/null
+++ b/erpnext/templates/pages/addresses.html
@@ -0,0 +1,52 @@
+{% block title %} {{ "My Addresses" }} {% endblock %}
+
+{% block header %}<h2>My Addresses</h2>{% endblock %}
+
+{% block breadcrumbs %}{% include "templates/includes/breadcrumbs.html" %}{% endblock %}
+
+{% block content %}
+<div class="addresses-content">
+ <p><a class="btn btn-default" href="address"><i class="icon-plus"> New Address</i></a></p>
+ <hr>
+ <div id="address-list">
+ <div class="progress progress-striped active">
+ <div class="progress-bar progress-bar-info" style="width: 100%;"></div>
+ </div>
+ </div>
+</div>
+
+<script>
+;(function() {
+ var fetch_addresses = function() {
+ frappe.call({
+ method: "shopping_cart.templates.pages.addresses.get_addresses",
+ callback: function(r) {
+ $("#address-list .progress").remove();
+ var $list = $("#address-list");
+
+ if(!(r.message && r.message.length)) {
+ $list.html("<div class='alert'>No Addresses Found</div>");
+ return;
+ }
+
+ $.each(r.message, function(i, address) {
+ address.url_name = encodeURIComponent(address.name);
+ $(repl('<div> \
+ <p><a href="address?name=%(url_name)s">%(name)s</a></p> \
+ <p>%(display)s</p> \
+ <hr> \
+ </div>', address)).appendTo($list);
+ });
+ }
+ });
+ };
+
+ $(document).ready(function() {
+ fetch_addresses();
+ });
+})();
+</script>
+
+<!-- no-sidebar -->
+{% endblock %}
+
diff --git a/erpnext/templates/pages/addresses.py b/erpnext/templates/pages/addresses.py
new file mode 100644
index 0000000..531d3a3
--- /dev/null
+++ b/erpnext/templates/pages/addresses.py
@@ -0,0 +1,13 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+from erpnext.shopping_cart.cart import get_address_docs
+
+no_cache = 1
+no_sitemap = 1
+
+@frappe.whitelist()
+def get_addresses():
+ return get_address_docs()
diff --git a/erpnext/templates/pages/cart.html b/erpnext/templates/pages/cart.html
new file mode 100644
index 0000000..a8dc03e
--- /dev/null
+++ b/erpnext/templates/pages/cart.html
@@ -0,0 +1,57 @@
+{% block title %} {{ "Shopping Cart" }} {% endblock %}
+
+{% block header %}<h2><i class="icon-shopping-cart"></i> Shopping Cart</h2>{% endblock %}
+
+{% block script %}{% include "templates/includes/cart.js" %}{% endblock %}
+
+{% block content %}
+<div class="cart-content">
+ <div class="progress progress-striped active">
+ <div class="progress-bar progress-bar-info" style="width: 100%;"></div>
+ </div>
+ <div id="cart-container" class="hide">
+ <p class="pull-right"><button class="btn btn-success btn-place-order" type="button">Place Order</button></p>
+ <div class="clearfix"></div>
+ <div id="cart-error" class="alert alert-danger" style="display: none;"></div>
+ <hr>
+ <div class="row">
+ <div class="col-md-9 col-sm-9">
+ <div class="row">
+ <div class="col-md-9 col-md-offset-3"><h4>Item Details</h4></div>
+ </div>
+ </div>
+ <div class="col-md-3 col-sm-3 text-right"><h4>Qty, Amount</h4></div>
+ </div><hr>
+ <div id="cart-items">
+ </div>
+ <div id="cart-taxes">
+ </div>
+ <div id="cart-totals">
+ </div>
+ <hr>
+ <div id="cart-addresses">
+ <div class="row">
+ <div class="col-md-6">
+ <h4>Shipping Address</h4>
+ <div id="cart-shipping-address" class="panel-group"
+ data-fieldname="shipping_address_name"></div>
+ <button class="btn btn-default" type="button" id="cart-add-shipping-address">
+ <span class="icon icon-plus"></span> New Shipping Address</button>
+ </div>
+ <div class="col-md-6">
+ <h4>Billing Address</h4>
+ <div id="cart-billing-address" class="panel-group"
+ data-fieldname="customer_address"></div>
+ <button class="btn btn-default" type="button" id="cart-add-billing-address">
+ <span class="icon icon-plus"></span> New Billing Address</button>
+ </div>
+ </div>
+ <hr>
+ </div>
+ <p class="pull-right"><button class="btn btn-success btn-place-order" type="button">Place Order</button></p>
+ </div>
+</div>
+
+<!-- no-sidebar -->
+{% endblock %}
+
diff --git a/erpnext/templates/pages/cart.py b/erpnext/templates/pages/cart.py
new file mode 100644
index 0000000..9c9f096
--- /dev/null
+++ b/erpnext/templates/pages/cart.py
@@ -0,0 +1,7 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+
+no_cache = 1
+no_sitemap = 1
\ No newline at end of file
diff --git a/erpnext/templates/pages/invoice.html b/erpnext/templates/pages/invoice.html
new file mode 100644
index 0000000..13b0e72
--- /dev/null
+++ b/erpnext/templates/pages/invoice.html
@@ -0,0 +1,6 @@
+{% block title %} {{ doc.name }} {% endblock %}
+
+{% block header %}<h2>{{ doc.name }}</h2>{% endblock %}
+
+{% block content%}{% include "templates/includes/sale.html" %}{% endblock %}
+
diff --git a/erpnext/templates/pages/invoice.py b/erpnext/templates/pages/invoice.py
new file mode 100644
index 0000000..5b55007
--- /dev/null
+++ b/erpnext/templates/pages/invoice.py
@@ -0,0 +1,31 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe import _
+from frappe.utils import flt, fmt_money
+from shopping_cart.templates.utils import get_transaction_context
+
+no_cache = 1
+no_sitemap = 1
+
+def get_context(context):
+ invoice_context = frappe._dict({
+ "parent_link": "invoices",
+ "parent_title": "Invoices"
+ })
+ invoice_context.update(get_transaction_context("Sales Invoice", frappe.form_dict.name))
+ modify_status(invoice_context.doc)
+ return invoice_context
+
+def modify_status(doc):
+ doc.status = ""
+ if flt(doc.outstanding_amount):
+ doc.status = '<span class="label %s"><i class="icon-fixed-width %s"></i> %s</span>' % \
+ ("label-warning", "icon-exclamation-sign",
+ _("To Pay") + " = " + fmt_money(doc.outstanding_amount, currency=doc.currency))
+ else:
+ doc.status = '<span class="label %s"><i class="icon-fixed-width %s"></i> %s</span>' % \
+ ("label-success", "icon-ok", _("Paid"))
+
\ No newline at end of file
diff --git a/erpnext/templates/pages/invoices.html b/erpnext/templates/pages/invoices.html
new file mode 100644
index 0000000..9f493ca
--- /dev/null
+++ b/erpnext/templates/pages/invoices.html
@@ -0,0 +1,6 @@
+{% block title %} {{ title }} {% endblock %}
+
+{% block header %}<h2>{{ title }}</h2>{% endblock %}
+
+{% block content %}{% include "templates/includes/sales_transactions.html" %}{% endblock %}
+
diff --git a/erpnext/templates/pages/invoices.py b/erpnext/templates/pages/invoices.py
new file mode 100644
index 0000000..98c5140
--- /dev/null
+++ b/erpnext/templates/pages/invoices.py
@@ -0,0 +1,29 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+from shopping_cart.templates.utils import get_currency_context
+
+no_cache = 1
+no_sitemap = 1
+
+def get_context(context):
+ invoices_context = get_currency_context()
+ invoices_context.update({
+ "title": "Invoices",
+ "method": "shopping_cart.templates.pages.invoices.get_invoices",
+ "icon": "icon-file-text",
+ "empty_list_message": "No Invoices Found",
+ "page": "invoice"
+ })
+ return invoices_context
+
+@frappe.whitelist()
+def get_invoices(start=0):
+ from shopping_cart.templates.utils import get_transaction_list
+ from shopping_cart.templates.pages.invoice import modify_status
+ invoices = get_transaction_list("Sales Invoice", start, ["outstanding_amount"])
+ for d in invoices:
+ modify_status(d)
+ return invoices
\ No newline at end of file
diff --git a/erpnext/templates/pages/order.html b/erpnext/templates/pages/order.html
new file mode 100644
index 0000000..13b0e72
--- /dev/null
+++ b/erpnext/templates/pages/order.html
@@ -0,0 +1,6 @@
+{% block title %} {{ doc.name }} {% endblock %}
+
+{% block header %}<h2>{{ doc.name }}</h2>{% endblock %}
+
+{% block content%}{% include "templates/includes/sale.html" %}{% endblock %}
+
diff --git a/erpnext/templates/pages/order.py b/erpnext/templates/pages/order.py
new file mode 100644
index 0000000..832a60e
--- /dev/null
+++ b/erpnext/templates/pages/order.py
@@ -0,0 +1,34 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe import _
+from shopping_cart.templates.utils import get_transaction_context
+
+no_cache = 1
+no_sitemap = 1
+
+def get_context(context):
+ order_context = frappe._dict({
+ "parent_link": "orders",
+ "parent_title": "My Orders"
+ })
+
+ order_context.update(get_transaction_context("Sales Order", frappe.form_dict.name))
+ modify_status(order_context.doc)
+ return order_context
+
+def modify_status(doc):
+ doc.status = []
+ if 0 < doc.per_billed < 100:
+ doc.status.append(("label-warning", "icon-ok", _("Partially Billed")))
+ elif doc.per_billed == 100:
+ doc.status.append(("label-success", "icon-ok", _("Billed")))
+
+ if 0 < doc.per_delivered < 100:
+ doc.status.append(("label-warning", "icon-truck", _("Partially Delivered")))
+ elif doc.per_delivered == 100:
+ doc.status.append(("label-success", "icon-truck", _("Delivered")))
+ doc.status = " " + " ".join(('<span class="label %s"><i class="icon-fixed-width %s"></i> %s</span>' % s
+ for s in doc.status))
diff --git a/erpnext/templates/pages/orders.html b/erpnext/templates/pages/orders.html
new file mode 100644
index 0000000..d58cbd8
--- /dev/null
+++ b/erpnext/templates/pages/orders.html
@@ -0,0 +1,5 @@
+{% block title %} {{ title }} {% endblock %}
+
+{% block header %}<h2>{{ title }}</h2>{% endblock %}
+
+{% block content %}{% include "templates/includes/sales_transactions.html" %}{% endblock %}
diff --git a/erpnext/templates/pages/orders.py b/erpnext/templates/pages/orders.py
new file mode 100644
index 0000000..c443b6a
--- /dev/null
+++ b/erpnext/templates/pages/orders.py
@@ -0,0 +1,30 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+from shopping_cart.templates.utils import get_currency_context, get_transaction_list
+from shopping_cart.templates.pages.order import modify_status
+
+no_cache = 1
+no_sitemap = 1
+
+def get_context(context):
+ orders_context = get_currency_context()
+ orders_context.update({
+ "title": "My Orders",
+ "method": "shopping_cart.templates.pages.orders.get_orders",
+ "icon": "icon-list",
+ "empty_list_message": "No Orders Yet",
+ "page": "order",
+ })
+ return orders_context
+
+@frappe.whitelist()
+def get_orders(start=0):
+ orders = get_transaction_list("Sales Order", start, ["per_billed", "per_delivered"])
+ for d in orders:
+ modify_status(d)
+
+ return orders
+
\ No newline at end of file
diff --git a/erpnext/templates/pages/shipment.html b/erpnext/templates/pages/shipment.html
new file mode 100644
index 0000000..13b0e72
--- /dev/null
+++ b/erpnext/templates/pages/shipment.html
@@ -0,0 +1,6 @@
+{% block title %} {{ doc.name }} {% endblock %}
+
+{% block header %}<h2>{{ doc.name }}</h2>{% endblock %}
+
+{% block content%}{% include "templates/includes/sale.html" %}{% endblock %}
+
diff --git a/erpnext/templates/pages/shipment.py b/erpnext/templates/pages/shipment.py
new file mode 100644
index 0000000..ba98e1d
--- /dev/null
+++ b/erpnext/templates/pages/shipment.py
@@ -0,0 +1,17 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+from shopping_cart.templates.utils import get_transaction_context
+
+no_cache = 1
+no_sitemap = 1
+
+def get_context(context):
+ shipment_context = frappe._dict({
+ "parent_link": "shipments",
+ "parent_title": "Shipments"
+ })
+ shipment_context.update(get_transaction_context("Delivery Note", frappe.form_dict.name))
+ return shipment_context
diff --git a/erpnext/templates/pages/shipments.html b/erpnext/templates/pages/shipments.html
new file mode 100644
index 0000000..d58cbd8
--- /dev/null
+++ b/erpnext/templates/pages/shipments.html
@@ -0,0 +1,5 @@
+{% block title %} {{ title }} {% endblock %}
+
+{% block header %}<h2>{{ title }}</h2>{% endblock %}
+
+{% block content %}{% include "templates/includes/sales_transactions.html" %}{% endblock %}
diff --git a/erpnext/templates/pages/shipments.py b/erpnext/templates/pages/shipments.py
new file mode 100644
index 0000000..fe28c7e
--- /dev/null
+++ b/erpnext/templates/pages/shipments.py
@@ -0,0 +1,25 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+from shopping_cart.templates.utils import get_currency_context
+
+no_cache = 1
+no_sitemap = 1
+
+def get_context(context):
+ shipments_context = get_currency_context()
+ shipments_context.update({
+ "title": "Shipments",
+ "method": "shopping_cart.templates.pages.shipments.get_shipments",
+ "icon": "icon-truck",
+ "empty_list_message": "No Shipments Found",
+ "page": "shipment"
+ })
+ return shipments_context
+
+@frappe.whitelist()
+def get_shipments(start=0):
+ from shopping_cart.templates.utils import get_transaction_list
+ return get_transaction_list("Delivery Note", start)
diff --git a/erpnext/templates/pages/ticket.html b/erpnext/templates/pages/ticket.html
new file mode 100644
index 0000000..39c69df
--- /dev/null
+++ b/erpnext/templates/pages/ticket.html
@@ -0,0 +1,116 @@
+{% block title %} {{ title }} {% endblock %}
+
+{% block header %}<h2><i class="icon-ticket icon-fixed-width"></i> {{ title }}</h2>{% endblock %}
+
+{% block content %}
+{% set status_label = {
+ "Open": "label-success",
+ "To Reply": "label-danger",
+ "Closed": "label-default"
+} %}
+
+<div class="ticket-content">
+ <ul class="breadcrumb">
+ <li><a href="index">Home</a></li>
+ <li><a href="tickets">My Tickets</a></li>
+ <li class="active"><i class="icon-ticket icon-fixed-width"></i> {{ doc.name or "" }}</li>
+ </ul>
+ {% if not doc -%}
+ <script>ask_to_login();</script>
+ {% else %}
+ <hr>
+ {%- if doc.status -%}
+ {% if doc.status == "Waiting for Customer" -%}
+ {% set status = "To Reply" %}
+ {% else %}
+ {% set status = doc.status %}
+ {%- endif -%}
+ <div class="row">
+ <div class="col-md-2" style="margin-bottom: 7px;">
+ <span class="label {{ status_label.get(status) or 'label-default' }}">{{ status }}</span>
+ </div>
+ <div class="col-md-8">
+ <div class="row col-md-12">{{ doc.subject }}</div>
+ </div>
+ <div class="col-md-2">
+ <span class="text-muted pull-right">{{ frappe.utils.formatdate(doc.creation) }}</span>
+ </div>
+ </div>
+ <div class="row">
+ <h4 class="col-xs-6">Messages</h4>
+ <div class="col-xs-6">
+ <button class="btn btn-sm btn-primary pull-right" id="ticket-reply">
+ <i class="icon-envelope icon-fixed-width"></i> Reply</button>
+ <button class="btn btn-sm btn-success pull-right hide" id="ticket-reply-send">
+ <i class="icon-arrow-right icon-fixed-width"></i> Send</button>
+ </div>
+ </div>
+ <p id="ticket-alert" class="alert alert-danger"
+ style="display: none;"> </p>
+ <div>
+ <table class="table table-bordered table-striped" id="ticket-thread">
+ <tbody>
+ {%- for comm in
+ (doc.get({"doctype":"Communication"})|sort(reverse=True, attribute="creation")) %}
+ <tr>
+ <td>
+ <h5 style="text-transform: none">
+ {{ comm.sender }} on {{ frappe.utils.formatdate(comm.creation) }}</h5>
+ <hr>
+ <p>{{ frappe.utils.is_html(comm.content) and comm.content or
+ comm.content.replace("\n", "<br>")}}</p>
+ </td>
+ </tr>
+ {% endfor -%}
+ </tbody>
+ </table>
+ </div>
+ {%- endif -%}
+ {% endif -%}
+</div>
+
+<script>
+$(document).ready(function() {
+ $("#ticket-reply").on("click", function() {
+ if(!$("#ticket-reply-editor").length) {
+ $('<tr id="ticket-reply-editor"><td>\
+ <h5 style="text-transform: none">Reply</h5>\
+ <hr>\
+ <textarea rows=10 class="form-control" style="resize: vertical;"></textarea>\
+ </td></tr>').prependTo($("#ticket-thread").find("tbody"));
+ $("#ticket-reply").addClass("hide");
+ $("#ticket-reply-send").removeClass("hide");
+ }
+ });
+
+ $("#ticket-reply-send").on("click", function() {
+ var reply = $("#ticket-reply-editor").find("textarea").val().trim();
+ if(!reply) {
+ msgprint("Please write something in reply!");
+ } else {
+ frappe.call({
+ type: "POST",
+ method: "shopping_cart.templates.pages.ticket.add_reply",
+ btn: this,
+ args: { ticket: "{{ doc.name }}", message: reply },
+ callback: function(r) {
+ if(r.exc) {
+ msgprint(r._server_messages
+ ? JSON.parse(r._server_messages).join("<br>")
+ : "Something went wrong!");
+ } else {
+ window.location.reload();
+ }
+ }
+ })
+ }
+ });
+});
+
+var msgprint = function(txt) {
+ if(txt) $("#ticket-alert").html(txt).toggle(true);
+}
+</script>
+
+<!-- no-sidebar -->
+{% endblock %}
diff --git a/erpnext/templates/pages/ticket.py b/erpnext/templates/pages/ticket.py
new file mode 100644
index 0000000..9582146
--- /dev/null
+++ b/erpnext/templates/pages/ticket.py
@@ -0,0 +1,41 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe import _
+from frappe.utils import today
+
+no_cache = 1
+no_sitemap = 1
+
+def get_context(context):
+ doc = frappe.get_doc("Support Ticket", frappe.form_dict.name)
+ if doc.raised_by == frappe.session.user:
+ ticket_context = {
+ "title": doc.name,
+ "doc": doc
+ }
+ else:
+ ticket_context = {"title": "Not Allowed", "doc": {}}
+
+ return ticket_context
+
+@frappe.whitelist()
+def add_reply(ticket, message):
+ if not message:
+ raise frappe.throw(_("Please write something"))
+
+ doc = frappe.get_doc("Support Ticket", ticket)
+ if doc.raised_by != frappe.session.user:
+ raise frappe.throw(_("You are not allowed to reply to this ticket."), frappe.PermissionError)
+
+ comm = frappe.get_doc({
+ "doctype":"Communication",
+ "subject": doc.subject,
+ "content": message,
+ "sender": doc.raised_by,
+ "sent_or_received": "Received"
+ })
+ comm.insert(ignore_permissions=True)
+
diff --git a/erpnext/templates/pages/tickets.html b/erpnext/templates/pages/tickets.html
new file mode 100644
index 0000000..6c03313
--- /dev/null
+++ b/erpnext/templates/pages/tickets.html
@@ -0,0 +1,92 @@
+{% block title %} {{ title }} {% endblock %}
+
+{% block header %}<h2>{{ title }}</h2>{% endblock %}
+
+{% block content %}
+{% include "templates/includes/transactions.html" %}
+
+<script>
+ var status_label = {
+ "Open": "label-success",
+ "Waiting for Customer": "label-danger",
+ "Closed": "label-default"
+ }
+
+ var render = function(doc) {
+ doc.status = doc.status.trim();
+ doc.label_class = status_label[doc.status] || "label-default";
+ if(doc.status==="Waiting for Customer") doc.status = "To Reply";
+
+ $(repl('<a href="{{ page }}?name=%(name)s" class="list-group-item">\
+ <div class="row">\
+ <div class="col-md-2" style="margin-bottom: 7px;"><span class="label %(label_class)s">\
+ %(status)s</span></div>\
+ <div class="col-md-8">\
+ <div class="row col-md-12">%(name)s</div>\
+ <div class="row col-md-12 text-muted">%(subject)s</div>\
+ </div>\
+ <div class="col-md-2 pull-right">\
+ <span class="text-muted">%(creation)s</span>\
+ </div>\
+ </div>\
+ </a>', doc)).appendTo($list);
+ };
+
+ frappe.ready(function() {
+ if(!window.$new_ticket) {
+ window.$new_ticket = $('<div>\
+ <button class="btn btn-primary" style="margin-bottom: 15px;" id="new-ticket">\
+ <i class="icon-tag icon-fixed-width"></i> New Ticket\
+ </button>\
+ <button class="btn btn-success hide" style="margin-bottom: 15px;" id="new-ticket-send">\
+ <i class="icon-arrow-right icon-fixed-width"></i> Send\
+ </button>\
+ </div>').insertBefore(".transaction-list");
+ }
+
+ window.$new_ticket.find("#new-ticket").on("click", function() {
+ $(this).addClass("hide");
+ $(window.$new_ticket).find("#new-ticket-send").removeClass("hide");
+ $('<div class="well" id="ticket-editor">\
+ <div class="form-group"><input class="form-control" type="data"\
+ placeholder="Subject" data-fieldname="subject"></div>\
+ <div class="form-group"><textarea rows=10 class="form-control" \
+ style="resize: vertical;" placeholder="Message" \
+ data-fieldname="message"></textarea></div>\
+ </div>')
+ .insertAfter(window.$new_ticket);
+ });
+
+ window.$new_ticket.find("#new-ticket-send").on("click", function() {
+ var subject = $("#ticket-editor").find('[data-fieldname="subject"]').val().trim();
+ var message = $("#ticket-editor").find('[data-fieldname="message"]').val().trim();
+ if(!(subject && message)) {
+ msgprint("Please write something in subject and message!");
+ } else {
+ frappe.call({
+ type: "POST",
+ method: "shopping_cart.templates.pages.tickets.make_new_ticket",
+ btn: this,
+ args: { subject: subject, message: message },
+ callback: function(r) {
+ if(r.exc) {
+ msgprint(r._server_messages
+ ? JSON.parse(r._server_messages).join("<br>")
+ : "Something went wrong!");
+ } else {
+ window.location.href = "ticket?name=" + encodeURIComponent(r.message);
+ }
+ }
+ })
+ }
+ });
+ });
+
+ var msgprint = function(txt) {
+ if(txt) $("#msgprint-alert").html(txt).toggle(true);
+ }
+</script>
+
+<!-- no-sidebar -->
+{% endblock %}
+
diff --git a/erpnext/templates/pages/tickets.py b/erpnext/templates/pages/tickets.py
new file mode 100644
index 0000000..158173f
--- /dev/null
+++ b/erpnext/templates/pages/tickets.py
@@ -0,0 +1,54 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe.utils import cint, formatdate
+
+no_cache = 1
+no_sitemap = 1
+
+def get_context(context):
+ return {
+ "title": "My Tickets",
+ "method": "shopping_cart.templates.pages.tickets.get_tickets",
+ "icon": "icon-ticket",
+ "empty_list_message": "No Tickets Raised",
+ "page": "ticket"
+ }
+
+@frappe.whitelist()
+def get_tickets(start=0):
+ tickets = frappe.db.sql("""select name, subject, status, creation
+ from `tabSupport Ticket` where raised_by=%s
+ order by modified desc
+ limit %s, 20""", (frappe.session.user, cint(start)), as_dict=True)
+ for t in tickets:
+ t.creation = formatdate(t.creation)
+
+ return tickets
+
+@frappe.whitelist()
+def make_new_ticket(subject, message):
+ if not (subject and message):
+ raise frappe.throw(_("Please write something in subject and message!"))
+
+ ticket = frappe.get_doc({
+ "doctype":"Support Ticket",
+ "subject": subject,
+ "raised_by": frappe.session.user,
+ })
+ ticket.insert(ignore_permissions=True)
+
+ comm = frappe.get_doc({
+ "doctype":"Communication",
+ "subject": subject,
+ "content": message,
+ "sender": frappe.session.user,
+ "sent_or_received": "Received",
+ "reference_doctype": "Support Ticket",
+ "reference_name": ticket.name
+ })
+ comm.insert(ignore_permissions=True)
+
+ return ticket.name
diff --git a/erpnext/templates/pages/user.html b/erpnext/templates/pages/user.html
new file mode 100644
index 0000000..b4a1a39
--- /dev/null
+++ b/erpnext/templates/pages/user.html
@@ -0,0 +1,57 @@
+{% block title %} {{ "My Profile" }} {% endblock %}
+
+{% block header %}<h2>My Profile</h2>{% endblock %}
+
+{% block content %}
+<div class="user-content" style="max-width: 500px;">
+ <ul class="breadcrumb">
+ <li><a href="index">Home</a></li>
+ <li class="active"><i class="icon-user icon-fixed-width"></i> My Profile</li>
+ </ul>
+ <div class="alert alert-warning" id="message" style="display: none;"></div>
+ <form>
+ <fieldset>
+ <label>Full Name</label>
+ <input class="form-control" type="text" id="fullname" placeholder="Your Name">
+ </fieldset>
+ <fieldset>
+ <label>Company Name</label>
+ <input class="form-control" type="text" id="company_name" placeholder="Company Name" value="{{ company_name }}">
+ </fieldset>
+ <fieldset>
+ <label>Mobile No</label>
+ <input class="form-control" type="text" id="mobile_no" placeholder="Mobile No" value="{{ mobile_no }}">
+ </fieldset>
+ <fieldset>
+ <label>Phone</label>
+ <input class="form-control" type="text" id="phone" placeholder="Phone" value="{{ phone }}">
+ </fieldset>
+ <button id="update_user" type="submit" class="btn btn-default">Update</button>
+ </form>
+</div>
+<script>
+$(document).ready(function() {
+ $("#fullname").val(getCookie("full_name") || "");
+ $("#update_user").click(function() {
+ frappe.call({
+ method: "shopping_cart.templates.pages.user.update_user",
+ type: "POST",
+ args: {
+ fullname: $("#fullname").val(),
+ company_name: $("#company_name").val(),
+ mobile_no: $("#mobile_no").val(),
+ phone: $("#phone").val()
+ },
+ btn: this,
+ msg: $("#message"),
+ callback: function(r) {
+ if(!r.exc) $("#user-full-name").html($("#fullname").val());
+ }
+ });
+ return false;
+ })
+})
+</script>
+<!-- no-sidebar -->
+{% endblock %}
+
diff --git a/erpnext/templates/pages/user.py b/erpnext/templates/pages/user.py
new file mode 100644
index 0000000..5869e98
--- /dev/null
+++ b/erpnext/templates/pages/user.py
@@ -0,0 +1,40 @@
+# Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
+# License: GNU General Public License v3. See license.txt
+
+from __future__ import unicode_literals
+import frappe
+from frappe import _
+from frappe.utils import cstr
+from erpnext.shopping_cart.cart import get_lead_or_customer
+
+no_cache = 1
+no_sitemap = 1
+
+def get_context(context):
+ party = get_lead_or_customer()
+ if party.doctype == "Lead":
+ mobile_no = party.mobile_no
+ phone = party.phone
+ else:
+ mobile_no, phone = frappe.db.get_value("Contact", {"email_id": frappe.session.user,
+ "customer": party.name}, ["mobile_no", "phone"])
+
+ return {
+ "company_name": cstr(party.customer_name if party.doctype == "Customer" else party.company_name),
+ "mobile_no": cstr(mobile_no),
+ "phone": cstr(phone)
+ }
+
+@frappe.whitelist()
+def update_user(fullname, password=None, company_name=None, mobile_no=None, phone=None):
+ from erpnext.shopping_cart.cart import update_party
+ update_party(fullname, company_name, mobile_no, phone)
+
+ if not fullname:
+ return _("Name is required")
+
+ frappe.db.set_value("User", frappe.session.user, "first_name", fullname)
+ frappe.local.cookie_manager.set_cookie("full_name", fullname)
+
+ return _("Updated")
+
\ No newline at end of file
diff --git a/erpnext/templates/utils.py b/erpnext/templates/utils.py
index 9892924..139e63a 100644
--- a/erpnext/templates/utils.py
+++ b/erpnext/templates/utils.py
@@ -2,7 +2,10 @@
# License: GNU General Public License v3. See license.txt
from __future__ import unicode_literals
-import frappe
+
+import frappe, json
+from frappe import _
+from frappe.utils import cint, formatdate
@frappe.whitelist(allow_guest=True)
def send_message(subject="Website Query", message="", sender="", status="Open"):
@@ -18,3 +21,47 @@
"sent_or_received": "Received"
})
comm.insert(ignore_permissions=True)
+
+def get_transaction_list(doctype, start, additional_fields=None):
+ # find customer id
+ customer = frappe.db.get_value("Contact", {"email_id": frappe.session.user},
+ "customer")
+
+ if customer:
+ if additional_fields:
+ additional_fields = ", " + ", ".join(("`%s`" % f for f in additional_fields))
+ else:
+ additional_fields = ""
+
+ transactions = frappe.db.sql("""select name, creation, currency, grand_total_export
+ %s
+ from `tab%s` where customer=%s and docstatus=1
+ order by creation desc
+ limit %s, 20""" % (additional_fields, doctype, "%s", "%s"),
+ (customer, cint(start)), as_dict=True)
+ for doc in transactions:
+ items = frappe.db.sql_list("""select item_name
+ from `tab%s Item` where parent=%s limit 6""" % (doctype, "%s"), doc.name)
+ doc.items = ", ".join(items[:5]) + ("..." if (len(items) > 5) else "")
+ doc.creation = formatdate(doc.creation)
+ return transactions
+ else:
+ return []
+
+def get_currency_context():
+ return {
+ "global_number_format": frappe.db.get_default("number_format") or "#,###.##",
+ "currency": frappe.db.get_default("currency"),
+ "currency_symbols": json.dumps(dict(frappe.db.sql("""select name, symbol
+ from tabCurrency where ifnull(enabled,0)=1""")))
+ }
+
+def get_transaction_context(doctype, name):
+ customer = frappe.db.get_value("Contact", {"email_id": frappe.session.user},
+ "customer")
+
+ doc = frappe.get_doc(doctype, name)
+ if doc.customer != customer:
+ return { "doc": frappe._dict({"name": _("Not Allowed")}) }
+ else:
+ return { "doc": doc }