2011-06-08 09:07:15 +00:00
report . customize _filters = function ( ) {
this . hide _all _filters ( ) ;
this . add _filter ( { fieldname : 'transaction' , label : 'Transaction' , fieldtype : 'Select' , options : 'Quotation' + NEWLINE + 'Sales Order' + NEWLINE + 'Delivery Note' + NEWLINE + 'Sales Invoice' + NEWLINE + 'Purchase Order' + NEWLINE + 'Purchase Receipt' + NEWLINE + 'Purchase Invoice' , report _default : 'Delivery Note' , ignore : 1 , parent : 'Profile' , in _first _page : 1 , single _select : 1 } ) ;
this . add _filter ( { fieldname : 'period' , label : 'Period' , fieldtype : 'Select' , options : 'Monthly' + NEWLINE + 'Quarterly' + NEWLINE + 'Half Yearly' + NEWLINE + 'Annual' , report _default : 'Quarterly' , ignore : 1 , parent : 'Profile' , in _first _page : 1 , single _select : 1 } ) ;
this . add _filter ( { fieldname : 'based_on' , label : 'Based On' , fieldtype : 'Select' , options : 'Item' + NEWLINE + 'Item Group' + NEWLINE + 'Customer' + NEWLINE + 'Customer Group' + NEWLINE + 'Territory' + NEWLINE + 'Supplier' + NEWLINE + 'Supplier Type' , ignore : 1 , parent : 'Profile' , report _default : 'Item' , in _first _page : 1 , single _select : 1 } ) ;
this . add _filter ( { fieldname : 'group_by' , label : 'Group By' , fieldtype : 'Select' , options : NEWLINE + 'Item' + NEWLINE + 'Customer' + NEWLINE + 'Supplier' , ignore : 1 , parent : 'Profile' , single _select : 1 } ) ;
this . add _filter ( { fieldname : 'order_type' , label : 'Order Type' , fieldtype : 'Select' , options : NEWLINE + 'Sales' + NEWLINE + 'Maintenance' , ignore : 1 , parent : 'Profile' , single _select : 1 } ) ;
this . add _filter ( { fieldname : 'company' , label : 'Company' , fieldtype : 'Link' , options : 'Company' , report _default : sys _defaults . company , ignore : 1 , parent : 'Profile' } ) ;
2011-09-27 05:27:14 +00:00
this . add _filter ( { fieldname : 'fiscal_year' , label : 'Fiscal Year' , fieldtype : 'Link' , options : 'Fiscal Year' , report _default : sys _defaults . fiscal _year , ignore : 1 , parent : 'Profile' , in _first _page : 1 } ) ;
2011-06-08 09:07:15 +00:00
// Add Filters
this . add _filter ( { fieldname : 'item' , label : 'Item' , fieldtype : 'Link' , options : 'Item' , ignore : 1 , parent : 'Profile' } ) ;
this . add _filter ( { fieldname : 'item_group' , label : 'Item Group' , fieldtype : 'Link' , options : 'Item Group' , ignore : 1 , parent : 'Profile' } ) ;
this . add _filter ( { fieldname : 'customer' , label : 'Customer' , fieldtype : 'Link' , options : 'Customer' , ignore : 1 , parent : 'Profile' } ) ;
this . add _filter ( { fieldname : 'customer_group' , label : 'Customer Group' , fieldtype : 'Link' , options : 'Customer Group' , ignore : 1 , parent : 'Profile' } ) ;
this . add _filter ( { fieldname : 'territory' , label : 'Territory' , fieldtype : 'Link' , options : 'Territory' , ignore : 1 , parent : 'Profile' } ) ;
this . add _filter ( { fieldname : 'supplier' , label : 'Supplier' , fieldtype : 'Link' , options : 'Supplier' , ignore : 1 , parent : 'Profile' } ) ;
this . add _filter ( { fieldname : 'supplier_type' , label : 'Supplier Type' , fieldtype : 'Link' , options : 'Supplier Type' , ignore : 1 , parent : 'Profile' } ) ;
}
this . mytabs . tabs [ 'Select Columns' ] . hide ( ) ;
report . aftertableprint = function ( t ) {
$yt ( t , '*' , 1 , { whiteSpace : 'pre' } ) ;
}
var validate _values = function ( trans , based _on , order _type ) {
if ( ! fiscal _year ) {
msgprint ( "Please select Fiscal Year" ) ;
return 0 ;
}
if ( ( in _list ( [ 'Quotation' , 'Sales Order' , 'Delivery Note' , 'Sales Invoice' ] , trans ) && in _list ( [ 'Supplier' , 'Supplier Type' ] , based _on ) ) || ( in _list ( [ 'Purchase Order' , 'Purchase Receipt' , 'Purchase Invoice' ] , trans ) && in _list ( [ 'Customer' , 'Customer Group' , 'Territory' ] , based _on ) ) ) {
msgprint ( "Sorry! You cannot fetch " + trans + " trend based on " + based _on ) ;
return 0 ;
}
if ( in _list ( [ 'Purchase Order' , 'Purchase Receipt' , 'Purchase Invoice' ] , trans ) && order _type ) {
msgprint ( "Please deselect Order Type for " + trans ) ;
return 0 ;
}
return 1 ;
}
report . get _query = function ( ) {
trans = this . get _filter ( 'Profile' , 'Transaction' ) . get _value ( ) ;
order _type = this . get _filter ( 'Profile' , 'Order Type' ) . get _value ( ) ;
based _on = this . get _filter ( 'Profile' , 'Based On' ) . get _value ( ) ;
company = this . get _filter ( 'Profile' , 'Company' ) . get _value ( ) ;
fiscal _year = this . get _filter ( 'Profile' , 'Fiscal Year' ) . get _value ( ) ;
if ( validate _values ( trans , based _on , order _type ) ) {
col = '' ;
add _cond = '' ;
add _col = '' ;
add _tables = '' ;
sp _cond = '' ;
if ( trans == 'Sales Invoice' ) trans = 'Receivable Voucher' ;
else if ( trans == 'Purchase Invoice' ) trans = 'Payable Voucher' ;
trans _det = trans + ' Detail'
if ( trans == 'Receivable Voucher' ) trans _det = 'RV Detail' ;
else if ( trans == 'Payable Voucher' ) trans _det = 'PV Detail' ;
else if ( trans == 'Purchase Order' ) trans _det = 'PO Detail' ;
if ( order _type != '' ) add _code += ' AND t1.order_type = ' + order _type ;
switch ( based _on ) {
case 'Item' : item = this . get _filter ( 'Profile' , 'Item' ) . get _value ( ) ;
col = 'DISTINCT t2.item_code, t3.item_name' ;
add _tables = ',tabItem t3' ;
add _cond += ' AND t2.item_code = t3.name' ;
if ( item ) add _cond += ' AND t2.item_code = "' + item + '"' ;
break ;
case 'Customer' : cust = this . get _filter ( 'Profile' , 'Customer' ) . get _value ( ) ;
col = 'DISTINCT t1.customer, t3.territory' ;
add _tables = ',tabCustomer t3' ;
add _cond += ' AND t1.customer = t3.name' ;
if ( cust ) add _cond += ' AND t1.customer = "' + cust + '"' ;
break ;
case 'Supplier' : supp = this . get _filter ( 'Profile' , 'Supplier' ) . get _value ( ) ;
col = 'DISTINCT t1.supplier, t3.supplier_type' ;
add _tables = ',tabSupplier t3' ;
add _cond += ' AND t1.supplier = t3.name' ;
if ( supp ) add _cond += ' AND t1.supplier = "' + supp + '"' ;
break ;
case 'Supplier Type' : supp _type = this . get _filter ( 'Profile' , 'Supplier Type' ) . get _value ( ) ;
col = 'DISTINCT t3.supplier_type' ;
add _tables = ',tabSupplier t3' ;
add _cond += ' AND t1.supplier = t3.name' ;
if ( supp _type ) add _cond += ' AND t1.supplier_type = "' + supp _type + '"' ;
break ;
case 'Item Group' : ig = this . get _filter ( 'Profile' , 'Item Group' ) . get _value ( ) ;
if ( ig ) sp _cond += ' AND parent.name = "' + ig + '"' ;
break ;
case 'Customer Group' : cg = this . get _filter ( 'Profile' , 'Customer Group' ) . get _value ( ) ;
if ( cg ) sp _cond += ' AND parent.name = "' + cg + '"' ;
break ;
case 'Territory' : ter = this . get _filter ( 'Profile' , 'Territory' ) . get _value ( ) ;
if ( ter ) sp _cond += ' AND parent.name = "' + ter + '"' ;
break ;
}
if ( based _on == 'Item' || based _on == 'Customer' || based _on == 'Supplier' || based _on == 'Supplier Type' )
var q = 'SELECT ' + col + ' FROM `tab' + trans + '` t1, `tab' + trans _det + '` t2 ' + add _tables + ' WHERE t1.fiscal_year = "' + fiscal _year + '" and t1.company = "' + company + '" and t2.parent = t1.name ' + add _cond ;
else
var q = 'SELECT CONCAT(REPEAT(" ", COUNT(parent.name) - 1), node.name) AS "Name" FROM `tab' + based _on + '` node,`tab' + based _on + '` parent WHERE node.lft BETWEEN parent.lft and parent.rgt and node.docstatus !=2 ' + sp _cond + ' GROUP BY node.name ORDER BY node.lft' ;
return q ;
}
2011-09-27 05:27:14 +00:00
}