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

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'; 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) { // Transaction History
data.grand_total = fmt_money(data.grand_total); // functions called by these functions are defined in contact_control.js
data.modified = wn.datetime.only_date(data.modified); cur_frm.cscript.make_qtn_list = function(parent, doc) {
return repl('\ cur_frm.cscript.render_transaction_history(parent, doc, 'Quotation',
<table><tr> \ [
<td width="30%" title="Id"> \ {fieldname: 'name', width: '28%', label: 'Id', type: 'Link'},
<a href="#!Form/%(doctype)s/%(name)s">%(name)s</a> \ {fieldname: 'status', width: '25%', label: 'Status', type: 'Data'},
</td> \ {fieldname: 'modified', width: '12%', label: 'Last Modified On',
<td width="20%" title="Status">%(status)s</td> \ type: 'Date', style: 'text-align: right; color: #777'},
<td width="30%" title="Grand Total" style="text-align: right;"> \ {fieldname: 'currency', width: '0%', label: 'Currency',
%(currency)s %(grand_total)s \ style: 'display: hidden'},
</td> \ {fieldname: 'grand_total', width: '35%', label: 'Grand Total',
<td width="20%" title="Modified Date" style="text-align: right;"> \ type: 'Currency', style: 'text-align: right'},
%(modified)s \ ]);
</td> \
</tr></table>', data);
} }
cur_frm.get_query_transaction_history = function(args) { cur_frm.cscript.make_so_list = function(parent, doc) {
return repl("\ cur_frm.cscript.render_transaction_history(parent, doc, 'Sales Order',
select name, status, modified, currency, \ [
grand_total \ {fieldname: 'name', width: '28%', label: 'Id', type: 'Link'},
from `tab%(doctype)s` \ {fieldname: 'status', width: '25%', label: 'Status', type: 'Data'},
where customer='%(customer)s' \ {fieldname: 'modified', width: '12%', label: 'Last Modified On',
order by modified desc", args); 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) { cur_frm.cscript.make_dn_list = function(parent, doc) {
$(parent).css({ cur_frm.cscript.render_transaction_history(parent, doc, 'Delivery Note',
'padding-top': '10px', [
}); {fieldname: 'name', width: '28%', label: 'Id', type: 'Link'},
{fieldname: 'status', width: '25%', label: 'Status', type: 'Data'},
cur_frm.transaction_list = new wn.ui.Listing({ {fieldname: 'modified', width: '12%', label: 'Last Modified On',
parent: parent, type: 'Date', style: 'text-align: right; color: #777'},
page_length: 10, {fieldname: 'currency', width: '0%', label: 'Currency',
get_query: get_query || function() { style: 'display: hidden'},
return cur_frm.get_query_transaction_history({ {fieldname: 'grand_total', width: '35%', label: 'Grand Total',
customer: doc.name, type: 'Currency', style: 'text-align: right'},
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_si_list = function(parent, doc) {
// make so list cur_frm.cscript.render_transaction_history(parent, doc, 'Sales Invoice',
// ------------- [
cur_frm.cscript.make_so_list = function(parent,doc){ {fieldname: 'name', width: '28%', label: 'Id', type: 'Link'},
cur_frm.render_transaction_history(parent, doc, 'Sales Order'); {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'},
// make dn list {fieldname: 'currency', width: '0%', label: 'Currency',
// ------------- style: 'display: hidden'},
cur_frm.cscript.make_dn_list = function(parent,doc){ {fieldname: 'grand_total', width: '35%', label: 'Grand Total',
cur_frm.render_transaction_history(parent, doc, 'Delivery Note'); type: 'Currency', style: 'text-align: right'},
} ]);
// -------------
// 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);
});
} }

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'; 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;
}