mirror of
https://github.com/frappe/erpnext.git
synced 2026-05-31 10:49:09 +00:00
[shopping-cart] i'm back
This commit is contained in:
297
erpnext/templates/includes/cart.js
Normal file
297
erpnext/templates/includes/cart.js
Normal file
@@ -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);
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -7,7 +7,7 @@ $(document).ready(function() {
|
||||
|
||||
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 }}"
|
||||
},
|
||||
|
||||
85
erpnext/templates/includes/sale.html
Normal file
85
erpnext/templates/includes/sale.html
Normal file
@@ -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 -->
|
||||
30
erpnext/templates/includes/sales_transactions.html
Normal file
30
erpnext/templates/includes/sales_transactions.html
Normal file
@@ -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 -->
|
||||
53
erpnext/templates/includes/transactions.html
Normal file
53
erpnext/templates/includes/transactions.html
Normal file
@@ -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 -->
|
||||
Reference in New Issue
Block a user