From e780f661a7ca2cbc18be910d14aaccfd47ffb488 Mon Sep 17 00:00:00 2001 From: Anand Doshi Date: Tue, 22 May 2012 17:04:33 +0530 Subject: [PATCH] fix in transaction history --- erpnext/selling/doctype/customer/customer.js | 138 ++++++++++++------- 1 file changed, 88 insertions(+), 50 deletions(-) diff --git a/erpnext/selling/doctype/customer/customer.js b/erpnext/selling/doctype/customer/customer.js index 791c4448f9..cc88ca42bb 100644 --- a/erpnext/selling/doctype/customer/customer.js +++ b/erpnext/selling/doctype/customer/customer.js @@ -150,75 +150,113 @@ cur_frm.fields_dict['lead_name'].get_query = function(doc,dt,dn){ /* ********************************* transaction history ************************************** */ +cur_frm.render_transaction_history_row = function(data) { + console.log(data.modified); + data.grand_total = fmt_money(data.grand_total); + data.modified = wn.datetime.only_date(data.modified); + return repl('\ + \ + \ + \ + \ + \ +
\ + %(name)s \ + %(status)s \ + %(currency)s %(grand_total)s \ + \ + %(modified)s \ +
', data); +} + +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.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){ - wn.require('js/listing.js'); - - var lst = new Listing(); - lst.colwidths = ['5%','20%','20%','20%','20%','15%']; - lst.colnames = ['Sr.','Id','Status','Quotation Date','Contact Person','Grand Total']; - lst.coltypes = ['Data','Link','Data','Data','Data','Currency']; - lst.coloptions = ['','Quotation','','','','']; - - var q = repl("select name,status,transaction_date, contact_person, grand_total from tabQuotation where customer='%(cust)s' order by transaction_date desc", {'cust':doc.name}); - var q_max = repl("select count(name) from tabQuotation where customer='%(cust)s'", {'cust':doc.name}); - - cur_frm.cscript.run_list(lst,parent,q,q_max,doc,'Quotation','Quotation'); + cur_frm.render_transaction_history(parent, doc, 'Quotation'); } // ------------- // make so list // ------------- cur_frm.cscript.make_so_list = function(parent,doc){ - wn.require('js/listing.js'); - - var lst = new Listing(); - lst.colwidths = ['5%','20%','20%','30%','25%']; - lst.colnames = ['Sr.','Id','Status','Sales Order Date','Grand Total']; - lst.coltypes = ['Data','Link','Data','Data','Currency']; - lst.coloptions = ['','Sales Order','','','']; - - var q = repl("select name,status,transaction_date, grand_total from `tabSales Order` where customer='%(cust)s' order by transaction_date desc", {'cust':doc.name}); - var q_max = repl("select count(name) from `tabSales Order` where customer='%(cust)s'", {'cust':doc.name}); - - cur_frm.cscript.run_list(lst,parent,q,q_max,doc,'Sales Order','Sales Order'); + cur_frm.render_transaction_history(parent, doc, 'Sales Order'); } + // ------------- // make dn list // ------------- cur_frm.cscript.make_dn_list = function(parent,doc){ - wn.require('js/listing.js'); - - var lst = new Listing(); - lst.colwidths = ['5%','20%','20%','20%','20%','15%']; - lst.colnames = ['Sr.','Id','Status','Delivery Note Date','Territory','Grand Total']; - lst.coltypes = ['Data','Link','Data','Data','Link','Currency']; - lst.coloptions = ['','Delivery Note','','','Territory','']; - - var q = repl("select name,status,transaction_date,territory,grand_total from `tabDelivery Note` where customer='%(cust)s' order by transaction_date desc", {'cust':doc.name}); - var q_max = repl("select count(name) from `tabDelivery Note` where customer='%(cust)s'", {'cust':doc.name}); - - cur_frm.cscript.run_list(lst,parent,q,q_max,doc,'Delivery Note','Delivery Note'); + cur_frm.render_transaction_history(parent, doc, 'Delivery Note'); } // ------------- // make si list // ------------- cur_frm.cscript.make_si_list = function(parent,doc){ - wn.require('js/listing.js'); - - var lst = new Listing(); - lst.colwidths = ['5%','20%','20%','20%','20%','15%']; - lst.colnames = ['Sr.','Id','Posting Date','Due Date','Debit To','Grand Total']; - lst.coltypes = ['Data','Link','Data','Data','Link','Currency']; - lst.coloptions = ['','Sales Invoice','','','Account','']; - - - var q = repl("select name,posting_date,due_date,debit_to,grand_total from `tabSales Invoice` where customer='%(cust)s' order by posting_date desc", {'cust':doc.name}); - var q_max = repl("select count(name) from `tabSales Invoice` where customer='%(cust)s'", {'cust':doc.name}); - - cur_frm.cscript.run_list(lst,parent,q,q_max,doc,'Sales Invoice','Sales Invoice'); -} + 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('\ + \ + \ + \ + \ + \ +
\ + %(name)s \ + \ + %(currency)s %(outstanding_amount)s \ + \ + %(currency)s %(grand_total)s\ + \ + %(modified)s \ +
', data); + }); +} \ No newline at end of file