fixes in transaction history of customer and supplier

This commit is contained in:
Anand Doshi 2012-05-29 14:14:27 +05:30
parent d1b36ec549
commit 82695ddd90
3 changed files with 169 additions and 142 deletions

View File

@ -105,47 +105,48 @@ cur_frm.cscript.make_contact = function() {
cur_frm.contact_list.run();
}
// make purchase order list
cur_frm.cscript.make_po_list = function(parent, doc){
wn.require('js/listing.js');
var lst = new Listing();
lst.colwidths = ['5%','25%','20%','25%','25%'];
lst.colnames = ['Sr.','Id','Status','PO Date','Grand Total'];
lst.coltypes = ['Data','Link','Data','Data','Currency'];
lst.coloptions = ['','Purchase Order','','','',''];
var q = repl("select name,status,transaction_date, grand_total from `tabPurchase Order` where supplier='%(sup)s' order by transaction_date desc", {'sup':doc.name});
var q_max = repl("select count(name) from `tabPurchase Order` where supplier='%(sup)s'", {'sup':doc.name});
cur_frm.cscript.run_list(lst,parent,q,q_max,doc,'Purchase Order','Purchase Order');
// Transaction History
cur_frm.cscript.make_po_list = function(parent, doc) {
cur_frm.cscript.render_transaction_history(parent, doc, 'Purchase Order',
[
{fieldname: 'name', width: '28%', label: 'Id', type: 'Link'},
{fieldname: 'status', width: '25%', label: 'Status', type: 'Data'},
{fieldname: 'modified', width: '12%', label: 'Last Modified On',
type: 'Date', style: 'text-align: right; color: #777'},
{fieldname: 'currency', width: '0%', label: 'Currency',
style: 'display: hidden'},
{fieldname: 'grand_total', width: '35%', label: 'Grand Total',
type: 'Currency', style: 'text-align: right'},
]);
}
// make purchase receipt list
cur_frm.cscript.make_pr_list = function(parent,doc){
wn.require('js/listing.js');
var lst = new Listing();
lst.colwidths = ['5%','20%','20%','20%','15%','20%'];
lst.colnames = ['Sr.','Id','Status','Receipt Date','% Billed','Grand Total'];
lst.coltypes = ['Data','Link','Data','Data','Currency','Currency'];
lst.coloptions = ['','Purchase Receipt','','','',''];
var q = repl("select name,status,transaction_date,per_billed,grand_total from `tabPurchase Receipt` where supplier='%(sup)s' order by transaction_date desc", {'sup':doc.name});
var q_max = repl("select count(name) from `tabPurchase Receipt` where supplier='%(sup)s'", {'sup':doc.name});
cur_frm.cscript.run_list(lst,parent,q,q_max,doc,'Purchase Receipt','Purchase Receipt');
cur_frm.cscript.make_pr_list = function(parent, doc) {
cur_frm.cscript.render_transaction_history(parent, doc, 'Purchase Receipt',
[
{fieldname: 'name', width: '28%', label: 'Id', type: 'Link'},
{fieldname: 'status', width: '15%', label: 'Status', type: 'Data'},
{fieldname: 'per_billed', width: '10%', label: '% Billed',
type: 'Percentage', style: 'text-align: right'},
{fieldname: 'modified', width: '12%', label: 'Last Modified On',
type: 'Date', style: 'text-align: right; color: #777'},
{fieldname: 'currency', width: '0%', label: 'Currency',
style: 'display: hidden'},
{fieldname: 'grand_total', width: '35%', label: 'Grand Total',
type: 'Currency', style: 'text-align: right'},
]);
}
// make purchase invoice list
cur_frm.cscript.make_pi_list = function(parent,doc){
wn.require('js/listing.js');
var lst = new Listing();
lst.colwidths = ['5%','20%','20%','20%','15%','20%'];
lst.colnames = ['Sr.','Id','Posting Date','Credit To','Bill Date','Grand Total'];
lst.coltypes = ['Data','Link','Data','Data','Currency','Currency'];
lst.coloptions = ['','Purchase Invoice','','','',''];
var q = repl("select name, posting_date, credit_to, bill_date, grand_total from `tabPurchase Invoice` where supplier='%(sup)s' order by posting_date desc", {'sup':doc.name});
var q_max = repl("select count(name) from `tabPurchase Invoice` where supplier='%(sup)s'", {'sup':doc.name});
cur_frm.cscript.run_list(lst,parent,q,q_max,doc,'Purchase Invoice','Purchase Invoice');
}
cur_frm.cscript.make_pi_list = function(parent, doc) {
cur_frm.cscript.render_transaction_history(parent, doc, 'Purchase Invoice',
[
{fieldname: 'name', width: '30%', label: 'Id', type: 'Link'},
{fieldname: 'modified', width: '35%', label: 'Last Modified On',
type: 'Date', style: 'text-align: right; color: #777'},
{fieldname: 'currency', width: '0%', label: 'Currency',
style: 'display: hidden'},
{fieldname: 'grand_total', width: '35%', label: 'Grand Total',
type: 'Currency', style: 'text-align: right'},
]);
}

View File

@ -148,114 +148,63 @@ cur_frm.fields_dict['lead_name'].get_query = function(doc,dt,dn){
return 'SELECT `tabLead`.`name` FROM `tabLead` WHERE `tabLead`.`status`!="Converted" AND `tabLead`.%(key)s LIKE "%s" ORDER BY `tabLead`.`name` ASC LIMIT 50';
}
/* ********************************* transaction history ************************************** */
cur_frm.render_transaction_history_row = function(data) {
data.grand_total = fmt_money(data.grand_total);
data.modified = wn.datetime.only_date(data.modified);
return repl('\
<table><tr> \
<td width="30%" title="Id"> \
<a href="#!Form/%(doctype)s/%(name)s">%(name)s</a> \
</td> \
<td width="20%" title="Status">%(status)s</td> \
<td width="30%" title="Grand Total" style="text-align: right;"> \
%(currency)s %(grand_total)s \
</td> \
<td width="20%" title="Modified Date" style="text-align: right;"> \
%(modified)s \
</td> \
</tr></table>', data);
// Transaction History
// functions called by these functions are defined in contact_control.js
cur_frm.cscript.make_qtn_list = function(parent, doc) {
cur_frm.cscript.render_transaction_history(parent, doc, 'Quotation',
[
{fieldname: 'name', width: '28%', label: 'Id', type: 'Link'},
{fieldname: 'status', width: '25%', label: 'Status', type: 'Data'},
{fieldname: 'modified', width: '12%', label: 'Last Modified On',
type: 'Date', style: 'text-align: right; color: #777'},
{fieldname: 'currency', width: '0%', label: 'Currency',
style: 'display: hidden'},
{fieldname: 'grand_total', width: '35%', label: 'Grand Total',
type: 'Currency', style: 'text-align: right'},
]);
}
cur_frm.get_query_transaction_history = function(args) {
return repl("\
select name, status, modified, currency, \
grand_total \
from `tab%(doctype)s` \
where customer='%(customer)s' \
order by modified desc", args);
cur_frm.cscript.make_so_list = function(parent, doc) {
cur_frm.cscript.render_transaction_history(parent, doc, 'Sales Order',
[
{fieldname: 'name', width: '28%', label: 'Id', type: 'Link'},
{fieldname: 'status', width: '25%', label: 'Status', type: 'Data'},
{fieldname: 'modified', width: '12%', label: 'Last Modified On',
type: 'Date', style: 'text-align: right; color: #777'},
{fieldname: 'currency', width: '0%', label: 'Currency',
style: 'display: hidden'},
{fieldname: 'grand_total', width: '35%', label: 'Grand Total',
type: 'Currency', style: 'text-align: right'},
]);
}
cur_frm.render_transaction_history = function(parent, doc, doctype, get_query, render_row) {
$(parent).css({
'padding-top': '10px',
});
cur_frm.transaction_list = new wn.ui.Listing({
parent: parent,
page_length: 10,
get_query: get_query || function() {
return cur_frm.get_query_transaction_history({
customer: doc.name,
doctype: doctype,
});
},
as_dict: 1,
no_result_message: repl('No %(doctype)s created for this customer', { doctype: doctype }),
render_row: function(wrapper, data) {
data.doctype = doctype;
render_html = render_row
? render_row(data)
: cur_frm.render_transaction_history_row(data);
$(wrapper).html(render_html);
},
});
cur_frm.transaction_list.run();
}
// --------------------
// make quotation list
// --------------------
cur_frm.cscript.make_qtn_list = function(parent,doc){
cur_frm.render_transaction_history(parent, doc, 'Quotation');
cur_frm.cscript.make_dn_list = function(parent, doc) {
cur_frm.cscript.render_transaction_history(parent, doc, 'Delivery Note',
[
{fieldname: 'name', width: '28%', label: 'Id', type: 'Link'},
{fieldname: 'status', width: '25%', label: 'Status', type: 'Data'},
{fieldname: 'modified', width: '12%', label: 'Last Modified On',
type: 'Date', style: 'text-align: right; color: #777'},
{fieldname: 'currency', width: '0%', label: 'Currency',
style: 'display: hidden'},
{fieldname: 'grand_total', width: '35%', label: 'Grand Total',
type: 'Currency', style: 'text-align: right'},
]);
}
// -------------
// make so list
// -------------
cur_frm.cscript.make_so_list = function(parent,doc){
cur_frm.render_transaction_history(parent, doc, 'Sales Order');
}
// -------------
// make dn list
// -------------
cur_frm.cscript.make_dn_list = function(parent,doc){
cur_frm.render_transaction_history(parent, doc, 'Delivery Note');
}
// -------------
// make si list
// -------------
cur_frm.cscript.make_si_list = function(parent,doc){
cur_frm.render_transaction_history(parent, doc, 'Sales Invoice', function() {
return repl("\
select name, outstanding_amount, modified, currency, \
grand_total \
from `tab%(doctype)s` \
where customer='%(customer)s' \
order by modified desc", { doctype: 'Sales Invoice', customer: doc.name });
}, function(data) {
data.grand_total = fmt_money(data.grand_total);
data.modified = wn.datetime.only_date(data.modified);
data.outstanding_amount = fmt_money(data.outstanding_amount);
return repl('\
<table><tr> \
<td width="30%" title="Id"> \
<a href="#!Form/%(doctype)s/%(name)s">%(name)s</a> \
</td> \
<td width="20%" title="Outstanding Amount" \
style="text-align: right; color: #777"> \
%(currency)s %(outstanding_amount)s \
</td>\
<td width="30%" title="Grand Total" style="text-align: right;"> \
%(currency)s %(grand_total)s\
</td> \
<td width="20%" title="Modified Date" style="text-align: right;"> \
%(modified)s \
</td> \
</tr></table>', data);
});
cur_frm.cscript.make_si_list = function(parent, doc) {
cur_frm.cscript.render_transaction_history(parent, doc, 'Sales Invoice',
[
{fieldname: 'name', width: '28%', label: 'Id', type: 'Link'},
{fieldname: 'outstanding_amount', width: '25%',
label: 'Outstanding Amount',
type: 'Currency', style: 'text-align: right; color: #777'},
{fieldname: 'modified', width: '12%', label: 'Last Modified On',
type: 'Date', style: 'text-align: right; color: #777'},
{fieldname: 'currency', width: '0%', label: 'Currency',
style: 'display: hidden'},
{fieldname: 'grand_total', width: '35%', label: 'Grand Total',
type: 'Currency', style: 'text-align: right'},
]);
}

View File

@ -121,3 +121,80 @@ if(cur_frm.fields_dict['territory']){
return 'SELECT `tabTerritory`.`name`,`tabTerritory`.`parent_territory` FROM `tabTerritory` WHERE `tabTerritory`.`is_group` = "No" AND `tabTerritory`.`docstatus`!= 2 AND `tabTerritory`.%(key)s LIKE "%s" ORDER BY `tabTerritory`.`name` ASC LIMIT 50';
}
}
// Transaction History related functions
cur_frm.cscript.render_transaction_history = function(parent, doc, doctype, args) {
$(parent).css({ 'padding-top': '10px' });
cur_frm.transaction_list = new wn.ui.Listing({
parent: parent,
page_length: 10,
get_query: function() {
return cur_frm.cscript.get_query_transaction_history({
parent: doc.doctype.toLowerCase(),
parent_name: doc.name,
doctype: doctype,
fields: (function() {
var fields = [];
for(var i in args) {
fields.push(args[i].fieldname);
}
return fields.join(", ");
})(),
});
},
as_dict: 1,
no_result_message: repl('No %(doctype)s created for this %(parent)s',
{ doctype: doctype, parent: doc.doctype }),
render_row: function(wrapper, data) {
render_html = cur_frm.cscript.render_transaction_history_row(data, args, doctype);
$(wrapper).html(render_html);
},
});
cur_frm.transaction_list.run();
}
cur_frm.cscript.render_transaction_history_row = function(data, args, doctype) {
var content = [];
var currency = data.currency;
for (var a in args) {
for (var d in data) {
if (args[a].fieldname === d && args[a].fieldname !== 'currency') {
if (args[a].type === 'Link') {
data[d] = repl('<a href="#!Form/%(doctype)s/%(name)s">\
%(name)s</a>', { doctype: doctype, name: data[d]});
} else if (args[a].type === 'Currency') {
data[d] = currency + " " + fmt_money(data[d]);
} else if (args[a].type === 'Percentage') {
data[d] = flt(data[d]) + '%';
} else if (args[a].type === 'Date') {
data[d] = wn.datetime.only_date(data[d]);
}
if (args[a].style == undefined) {
args[a].style = '';
}
data[d] = repl('\
<td width="%(width)s" title="%(title)s" style="%(style)s">\
%(content)s</td>',
{
content: data[d],
width: args[a].width,
title: args[a].label,
style: args[a].style,
});
content.push(data[d]);
break;
}
}
}
content = content.join("\n");
return '<table><tr>' + content + '</tr></table>';
}
cur_frm.cscript.get_query_transaction_history = function(args) {
var query = repl("\
select %(fields)s from `tab%(doctype)s` \
where %(parent)s = '%(parent_name)s' \
order by modified desc", args);
return query;
}