brotherton-erpnext/erpnext/stock/page/stock_level/stock_level.js

228 lines
7.3 KiB
JavaScript
Raw Normal View History

2013-11-20 07:29:58 +00:00
// Copyright (c) 2013, Web Notes Technologies Pvt. Ltd. and Contributors
// License: GNU General Public License v3. See license.txt
2012-12-28 10:09:55 +00:00
2014-02-14 10:17:51 +00:00
frappe.pages['stock-level'].onload = function(wrapper) {
frappe.ui.make_app_page({
2012-12-28 10:09:55 +00:00
parent: wrapper,
2014-04-14 10:55:30 +00:00
title: __('Stock Level'),
2012-12-28 10:09:55 +00:00
single_column: true
});
new erpnext.StockLevel(wrapper);
wrapper.appframe.add_module_icon("Stock")
;
2012-12-28 10:09:55 +00:00
}
2014-02-14 10:17:51 +00:00
frappe.require("assets/erpnext/js/stock_grid_report.js");
2012-12-28 10:09:55 +00:00
erpnext.StockLevel = erpnext.StockGridReport.extend({
init: function(wrapper) {
var me = this;
2012-12-28 10:09:55 +00:00
this._super({
2014-04-14 10:55:30 +00:00
title: __("Stock Level"),
2012-12-28 10:09:55 +00:00
page: wrapper,
parent: $(wrapper).find('.layout-main'),
appframe: wrapper.appframe,
doctypes: ["Item", "Warehouse", "Stock Ledger Entry", "Production Order",
"Material Request Item", "Purchase Order Item", "Sales Order Item", "Brand", "Serial No"],
});
this.wrapper.bind("make", function() {
2014-02-14 10:17:51 +00:00
frappe.utils.set_footnote(me, me.wrapper.get(0),
"<ul> \
<li style='font-weight: bold;'> \
Projected Qty = Actual Qty + Planned Qty + Requested Qty \
+ Ordered Qty - Reserved Qty </li> \
<ul> \
2014-04-14 10:55:30 +00:00
<li>"+__("Actual Qty: Quantity available in the warehouse.") +"</li>"+
"<li>"+__("Planned Qty: Quantity, for which, Production Order has been raised, but is pending to be manufactured.")+ "</li> " +
2014-04-14 10:55:30 +00:00
"<li>"+__("Requested Qty: Quantity requested for purchase, but not ordered.") + "</li>" +
"<li>" + __("Ordered Qty: Quantity ordered for purchase, but not received.")+ "</li>" +
"<li>" + __("Reserved Qty: Quantity ordered for sale, but not delivered.") + "</li>" +
2013-10-03 20:28:23 +00:00
"</ul> \
</ul>");
});
2012-12-28 10:09:55 +00:00
},
setup_columns: function() {
this.columns = [
2014-04-14 10:55:30 +00:00
{id: "item_code", name: __("Item Code"), field: "item_code", width: 160,
2012-12-28 10:09:55 +00:00
link_formatter: {
filter_input: "item_code",
open_btn: true,
doctype: '"Item"',
}},
2014-04-14 10:55:30 +00:00
{id: "item_name", name: __("Item Name"), field: "item_name", width: 100,
formatter: this.text_formatter},
2014-04-14 10:55:30 +00:00
{id: "description", name: __("Description"), field: "description", width: 200,
formatter: this.text_formatter},
2014-04-14 10:55:30 +00:00
{id: "brand", name: __("Brand"), field: "brand", width: 100,
link_formatter: {filter_input: "brand"}},
2014-04-14 10:55:30 +00:00
{id: "warehouse", name: __("Warehouse"), field: "warehouse", width: 100,
2012-12-28 10:09:55 +00:00
link_formatter: {filter_input: "warehouse"}},
2014-04-14 10:55:30 +00:00
{id: "uom", name: __("UOM"), field: "uom", width: 60},
{id: "actual_qty", name: __("Actual Qty"),
2012-12-28 10:09:55 +00:00
field: "actual_qty", width: 80, formatter: this.currency_formatter},
2014-04-14 10:55:30 +00:00
{id: "planned_qty", name: __("Planned Qty"),
2012-12-28 10:09:55 +00:00
field: "planned_qty", width: 80, formatter: this.currency_formatter},
2014-04-14 10:55:30 +00:00
{id: "requested_qty", name: __("Requested Qty"),
2012-12-28 10:09:55 +00:00
field: "requested_qty", width: 80, formatter: this.currency_formatter},
2014-04-14 10:55:30 +00:00
{id: "ordered_qty", name: __("Ordered Qty"),
2012-12-28 10:09:55 +00:00
field: "ordered_qty", width: 80, formatter: this.currency_formatter},
2014-04-14 10:55:30 +00:00
{id: "reserved_qty", name: __("Reserved Qty"),
2012-12-28 10:09:55 +00:00
field: "reserved_qty", width: 80, formatter: this.currency_formatter},
2014-04-14 10:55:30 +00:00
{id: "projected_qty", name: __("Projected Qty"),
2012-12-28 10:09:55 +00:00
field: "projected_qty", width: 80, formatter: this.currency_formatter},
2014-04-14 10:55:30 +00:00
{id: "re_order_level", name: __("Re-Order Level"),
field: "re_order_level", width: 80, formatter: this.currency_formatter},
2014-04-14 10:55:30 +00:00
{id: "re_order_qty", name: __("Re-Order Qty"),
field: "re_order_qty", width: 80, formatter: this.currency_formatter},
2012-12-28 10:09:55 +00:00
];
},
filters: [
2014-04-14 10:55:30 +00:00
{fieldtype:"Link", label: __("Item Code"), link:"Item", default_value: "Select Item...",
2012-12-28 10:09:55 +00:00
filter: function(val, item, opts) {
return item.item_code == val || !val;
2012-12-28 10:09:55 +00:00
}},
2014-04-14 10:55:30 +00:00
{fieldtype:"Select", label: __("Warehouse"), link:"Warehouse",
2012-12-28 10:09:55 +00:00
default_value: "Select Warehouse...", filter: function(val, item, opts) {
return item.warehouse == val || val == opts.default_value;
}},
2014-04-14 10:55:30 +00:00
{fieldtype:"Select", label: __("Brand"), link:"Brand",
2012-12-28 10:09:55 +00:00
default_value: "Select Brand...", filter: function(val, item, opts) {
return val == opts.default_value || item.brand == val;
}},
2014-04-14 10:55:30 +00:00
{fieldtype:"Button", label: __("Refresh"), icon:"icon-refresh icon-white"},
{fieldtype:"Button", label: __("Reset Filters")}
2012-12-28 10:09:55 +00:00
],
setup_filters: function() {
var me = this;
this._super();
this.wrapper.bind("apply_filters_from_route", function() { me.toggle_enable_brand(); });
this.filter_inputs.item_code.change(function() { me.toggle_enable_brand(); });
this.trigger_refresh_on_change(["item_code", "warehouse", "brand"]);
},
toggle_enable_brand: function() {
2013-02-08 08:34:13 +00:00
if(!this.filter_inputs.item_code.val()) {
this.filter_inputs.brand.prop("disabled", false);
2012-12-28 10:09:55 +00:00
} else {
this.filter_inputs.brand
.val(this.filter_inputs.brand.get(0).opts.default_value)
.prop("disabled", true);
2012-12-28 10:09:55 +00:00
}
},
init_filter_values: function() {
this._super();
this.filter_inputs.warehouse.get(0).selectedIndex = 0;
},
prepare_data: function() {
var me = this;
if(!this._data) {
this._data = [];
2013-01-02 10:30:25 +00:00
this.item_warehouse_map = {};
2014-02-14 10:17:51 +00:00
this.item_by_name = this.make_name_map(frappe.report_dump.data["Item"]);
2012-12-28 10:09:55 +00:00
this.calculate_quantities();
}
this.data = [].concat(this._data);
this.data = $.map(this.data, function(d) {
return me.apply_filters(d) ? d : null;
});
this.calculate_total();
},
calculate_quantities: function() {
var me = this;
$.each([
["Stock Ledger Entry", "actual_qty"],
["Production Order", "planned_qty"],
["Material Request Item", "requested_qty"],
2012-12-28 10:09:55 +00:00
["Purchase Order Item", "ordered_qty"],
["Sales Order Item", "reserved_qty"]],
function(i, v) {
2014-02-14 10:17:51 +00:00
$.each(frappe.report_dump.data[v[0]], function(i, item) {
2013-01-02 10:30:25 +00:00
var row = me.get_row(item.item_code, item.warehouse);
2012-12-28 10:09:55 +00:00
row[v[1]] += flt(item.qty);
});
}
);
2013-01-02 10:30:25 +00:00
// sort by item, warehouse
this._data = $.map(Object.keys(this.item_warehouse_map).sort(), function(key) {
return me.item_warehouse_map[key];
});
// calculate projected qty
2012-12-28 10:09:55 +00:00
$.each(this._data, function(i, row) {
row.projected_qty = row.actual_qty + row.planned_qty + row.requested_qty
+ row.ordered_qty - row.reserved_qty;
});
2013-01-02 10:30:25 +00:00
// filter out rows with zero values
this._data = $.map(this._data, function(d) {
return me.apply_zero_filter(null, d, null, me) ? d : null;
});
},
get_row: function(item_code, warehouse) {
var key = item_code + ":" + warehouse;
if(!this.item_warehouse_map[key]) {
var item = this.item_by_name[item_code];
var row = {
item_code: item_code,
warehouse: warehouse,
2013-01-21 13:18:26 +00:00
description: item.description,
2013-01-02 10:30:25 +00:00
brand: item.brand,
item_name: item.item_name || item.name,
uom: item.stock_uom,
id: key,
}
this.reset_item_values(row);
row["re_order_level"] = item.re_order_level
row["re_order_qty"] = item.re_order_qty
2013-01-02 10:30:25 +00:00
this.item_warehouse_map[key] = row;
}
return this.item_warehouse_map[key];
2012-12-28 10:09:55 +00:00
},
calculate_total: function() {
var me = this;
// show total if a specific item is selected and warehouse is not filtered
if(this.is_default("warehouse") && !this.is_default("item_code")) {
var total = {
id: "_total",
item_code: "Total",
_style: "font-weight: bold",
_show: true
};
this.reset_item_values(total);
$.each(this.data, function(i, row) {
$.each(me.columns, function(i, col) {
if (col.formatter==me.currency_formatter) {
total[col.id] += row[col.id];
}
});
});
this.data = this.data.concat([total]);
}
}
})