2012-05-07 12:30:57 +00:00
/ *
* lib / js / legacy / widgets / report _builder / report _builder . js
* /
_r . ReportContainer = function ( ) { if ( user == 'Guest' ) { msgprint ( "Not Allowed" ) ; return ; }
var page = wn . container . add _page ( "Report Builder" ) ; this . wrapper = $a ( page , 'div' , 'layout-wrapper' , { padding : '0px' } ) ; this . appframe = new wn . ui . AppFrame ( this . wrapper ) ; this . appframe . $titlebar . append ( '<span class="report-title">' ) ; this . rb _area = $a ( this . wrapper , 'div' , '' , { padding : '15px' } ) ; var me = this ; this . rb _dict = { } ; var run _fn = function ( ) { if ( me . cur _rb ) { me . cur _rb . dt . start _rec = 1 ; me . cur _rb . dt . run ( ) ; } }
var runbtn = this . appframe . add _button ( 'Run' , run _fn , 'icon-refresh' ) ; this . appframe . add _button ( 'Export' , function ( ) { me . cur _rb && me . cur _rb . dt . do _export ( ) ; } , 'icon-download-alt' ) ; this . appframe . add _button ( 'Print' , function ( ) { me . cur _rb && me . cur _rb . dt . do _print ( ) ; } , 'icon-print' ) ; this . appframe . add _button ( 'Calc' , function ( ) { me . cur _rb && me . cur _rb . dt . do _calc ( ) ; } , 'icon-plus' ) ; if ( has _common ( [ 'Administrator' , 'System Manager' ] , user _roles ) ) { var savebtn = this . appframe . add _button ( 'Save' , function ( ) { if ( me . cur _rb ) me . cur _rb . save _criteria ( ) ; } ) ; var fn = function ( ) { if ( me . cur _rb ) { if ( ! me . cur _rb . current _loaded ) { msgprint ( "error:You must save the report before you can set Advanced features" ) ; return ; }
loaddoc ( 'Search Criteria' , me . cur _rb . sc _dict [ me . cur _rb . current _loaded ] ) ; } } ; var advancedbtn = this . appframe . add _button ( 'Advanced Settings' , fn , 'icon-cog' ) ; }
this . set _dt = function ( dt , onload ) { my _onload = function ( f ) { if ( ! f . forbidden ) { me . cur _rb = f ; me . cur _rb . mytabs . items [ 'Result' ] . expand ( ) ; if ( onload ) onload ( f ) ; } }
if ( me . cur _rb )
me . cur _rb . hide ( ) ; if ( me . rb _dict [ dt ] ) { me . rb _dict [ dt ] . show ( my _onload ) ; } else { me . rb _dict [ dt ] = new _r . ReportBuilder ( me . rb _area , dt , my _onload ) ; } } }
_r . ReportBuilder = function ( parent , doctype , onload ) { this . menuitems = { } ; this . has _primary _filters = false ; this . doctype = doctype ; this . forbidden = 0 ; this . filter _fields = [ ] ; this . filter _fields _dict = { } ; var me = this ; this . fn _list = [ 'beforetableprint' , 'beforerowprint' , 'afterrowprint' , 'aftertableprint' , 'customize_filters' , 'get_query' ] ; this . wrapper = $a ( parent , 'div' , 'finder_wrapper' ) ; this . make _tabs ( ) ; this . current _loaded = null ; this . setup _doctype ( onload ) ; this . hide = function ( ) { $dh ( me . wrapper ) ; }
this . show = function ( my _onload ) { $ds ( me . wrapper ) ; this . set _main _title ( 'Report: ' + get _doctype _label ( me . doctype ) ) ; if ( my _onload ) my _onload ( me ) ; } }
_r . ReportBuilder . prototype . make _tabs = function ( ) { this . tab _wrapper = $a ( this . wrapper , 'div' , 'finder_tab_area' ) ; this . mytabs = new TabbedPage ( this . tab _wrapper ) ; this . mytabs . add _item ( 'Result' , null , null , 1 ) ; this . mytabs . add _item ( 'More Filters' , null , null , 1 ) ; this . mytabs . add _item ( 'Select Columns' , null , null , 1 ) ; this . mytabs . tabs = this . mytabs . items ; }
_r . ReportBuilder . prototype . make _body = function ( ) { this . set _main _title ( 'Report: ' + get _doctype _label ( this . doctype ) ) ; var me = this ; this . make _save _criteria ( ) ; this . column _picker = new _r . ReportColumnPicker ( this ) ; this . report _filters = new _r . ReportFilters ( this ) ; }
_r . ReportBuilder . prototype . make _save _criteria = function ( ) { var me = this ; this . sc _list = [ ] ; this . sc _dict = { } ; for ( var n in locals [ 'Search Criteria' ] ) { var d = locals [ 'Search Criteria' ] [ n ] ; if ( d . doc _type == this . doctype ) { this . sc _list [ this . sc _list . length ] = d . criteria _name ; this . sc _dict [ d . criteria _name ] = n ; } } }
_r . ReportBuilder . prototype . save _criteria = function ( save _as ) { var overwrite = 0 ; if ( this . current _loaded && ( ! save _as ) ) { var overwrite = confirm ( 'Do you want to overwrite the saved criteria "' + this . current _loaded + '"' ) ; if ( overwrite ) { var doc = locals [ 'Search Criteria' ] [ this . sc _dict [ this . current _loaded ] ] ; var criteria _name = this . current _loaded ; } }
if ( ! overwrite ) { var criteria _name = prompt ( 'Select a name for the criteria:' , '' ) ; if ( ! criteria _name )
return ; var dn = createLocal ( 'Search Criteria' ) ; var doc = locals [ 'Search Criteria' ] [ dn ] ; doc . criteria _name = criteria _name ; doc . doc _type = this . doctype ; }
var cl = [ ] ; var fl = { } ; var t = this . column _picker . get _selected ( ) ; for ( var i = 0 ; i < t . length ; i ++ )
cl . push ( t [ i ] . parent + '\1' + t [ i ] . label ) ; for ( var i = 0 ; i < this . filter _fields . length ; i ++ ) { var t = this . filter _fields [ i ] ; var v = t . get _value ? t . get _value ( ) : '' ; if ( v ) fl [ t . df . parent + '\1' + t . df . label + ( t . bound ? ( '\1' + t . bound ) : '' ) ] = v ; }
doc . columns = cl . join ( ',' ) ; doc . filters = JSON . stringify ( fl ) ; doc . sort _by = sel _val ( this . dt . sort _sel ) ; doc . sort _order = this . dt . sort _order ; doc . page _len = this . dt . page _len ; if ( this . parent _dt )
doc . parent _doc _type = this . parent _dt
var me = this ; var fn = function ( r ) { me . sc _dict [ criteria _name ] = r . main _doc _name ; me . set _criteria _sel ( criteria _name ) ; }
save _doclist ( doc . doctype , doc . name , 'Save' , fn ) ; }
_r . ReportBuilder . prototype . hide _all _filters = function ( ) { for ( var i = 0 ; i < this . filter _fields . length ; i ++ ) { this . filter _fields [ i ] . df . filter _hide = 1 ; } }
_r . ReportBuilder . prototype . run = function ( ) { this . dt . run ( ) ; }
_r . ReportBuilder . prototype . clear _criteria = function ( ) { this . column _picker . clear ( ) ; this . column _picker . set _defaults ( ) ; for ( var i = 0 ; i < this . filter _fields . length ; i ++ ) { this . filter _fields [ i ] . df . filter _hide = 0 ; this . filter _fields [ i ] . df . ignore = 0 ; if ( this . filter _fields [ i ] . is _custom ) { this . filter _fields [ i ] . df . filter _hide = 1 ; this . filter _fields [ i ] . df . ignore = 1 ; }
this . filter _fields [ i ] . set _input ( null ) ; }
this . set _sort _options ( ) ; this . set _main _title ( 'Report: ' + get _doctype _label ( this . doctype ) ) ; this . current _loaded = null ; this . customized _filters = null ; this . sc = null ; this . has _index = 1 ; this . has _headings = 1 ; for ( var i in this . fn _list ) this [ this . fn _list [ i ] ] = null ; }
_r . ReportBuilder . prototype . set _main _title = function ( t , t1 ) { var title = t + ( t1 ? t1 : '' ) ; _r . rb _con . appframe . $titlebar . find ( '.report-title' ) . html ( title ) ; set _title ( title ) ; }
_r . ReportBuilder . prototype . select _column = function ( dt , label , value ) { if ( value == null ) value = 1 ; this . column _picker . set ( dt , label , value ) ; }
_r . ReportBuilder . prototype . set _filter = function ( dt , label , value ) { if ( this . filter _fields _dict [ dt + '\1' + label ] )
this . filter _fields _dict [ dt + '\1' + label ] . set _input ( value ) ; }
_r . ReportBuilder . prototype . load _criteria = function ( criteria _name ) { this . clear _criteria ( ) ; if ( ! this . sc _dict [ criteria _name ] ) { alert ( criteria _name + ' could not be loaded. Please Refresh and try again' ) ; }
this . sc = locals [ 'Search Criteria' ] [ this . sc _dict [ criteria _name ] ] ; var report = this ; if ( this . sc && this . sc . report _script ) eval ( this . sc . report _script ) ; this . large _report = 0 ; if ( report . customize _filters ) { try { report . customize _filters ( this ) ; } catch ( err ) { errprint ( 'Error in "customize_filters":\n' + err ) ; } }
this . report _filters . refresh ( ) ; this . column _picker . clear ( ) ; var cl = this . sc . columns ? this . sc . columns . split ( ',' ) : [ ] ; for ( var c = 0 ; c < cl . length ; c ++ ) { var key = cl [ c ] . split ( '\1' ) ; this . select _column ( key [ 0 ] , key [ 1 ] , 1 ) ; }
eval ( 'var fl=' + this . sc . filters ) ; for ( var n in fl ) { if ( fl [ n ] ) { var key = n . split ( '\1' ) ; if ( key [ 1 ] == 'docstatus' ) { }
this . set _filter ( key [ 0 ] , key [ 1 ] , fl [ n ] ) ; } }
this . set _criteria _sel ( criteria _name ) ; this . set _filters _from _route ( ) ; }
_r . ReportBuilder . prototype . set _criteria _sel = function ( criteria _name ) { var sc = locals [ 'Search Criteria' ] [ this . sc _dict [ criteria _name ] ] ; if ( sc && sc . add _col )
var acl = sc . add _col . split ( '\n' ) ; else
var acl = [ ] ; var new _sl = [ ] ; for ( var i = 0 ; i < acl . length ; i ++ ) { var tmp = acl [ i ] . split ( ' AS ' ) ; if ( tmp [ 1 ] ) { var t = eval ( tmp [ 1 ] ) ; new _sl [ new _sl . length ] = [ t , "`" + t + "`" ] ; } }
this . set _sort _options ( new _sl ) ; if ( sc && sc . sort _by ) { this . dt . sort _sel . value = sc . sort _by ; }
if ( sc && sc . sort _order ) { sc . sort _order == 'ASC' ? this . dt . set _asc ( ) : this . dt . set _desc ( ) ; }
if ( sc && sc . page _len ) { this . dt . page _len _sel . inp . value = sc . page _len ; }
this . current _loaded = criteria _name ; this . set _main _title ( criteria _name , sc . description ) ; }
_r . ReportBuilder . prototype . setup _filters _and _cols = function ( ) { function can _dt _be _submitted ( dt ) { if ( locals . DocType && locals . DocType [ dt ] && locals . DocType [ dt ] . allow _trash ) return 1 ; var plist = getchildren ( 'DocPerm' , dt , 'permissions' , 'DocType' ) ; for ( var pidx in plist ) { if ( plist [ pidx ] . submit ) return 1 ; }
return 0 ; }
var me = this ; var dt = me . parent _dt ? me . parent _dt : me . doctype ; var fl = [ { 'fieldtype' : 'Data' , 'label' : 'ID' , 'fieldname' : 'name' , 'in_filter' : 1 , 'parent' : dt } , { 'fieldtype' : 'Data' , 'label' : 'Owner' , 'fieldname' : 'owner' , 'in_filter' : 1 , 'parent' : dt } , { 'fieldtype' : 'Date' , 'label' : 'Created on' , 'fieldname' : 'creation' , 'in_filter' : 0 , 'parent' : dt } , { 'fieldtype' : 'Date' , 'label' : 'Last modified on' , 'fieldname' : 'modified' , 'in_filter' : 0 , 'parent' : dt } , ] ; if ( can _dt _be _submitted ( dt ) ) { fl [ fl . length ] = { 'fieldtype' : 'Check' , 'label' : 'Saved' , 'fieldname' : 'docstatus' , 'search_index' : 1 , 'in_filter' : 1 , 'def_filter' : 1 , 'parent' : dt } ; fl [ fl . length ] = { 'fieldtype' : 'Check' , 'label' : 'Submitted' , 'fieldname' : 'docstatus' , 'search_index' : 1 , 'in_filter' : 1 , 'def_filter' : 1 , 'parent' : dt } ; fl [ fl . length ] = { 'fieldtype' : 'Check' , 'label' : 'Cancelled' , 'fieldname' : 'docstatus' , 'search_index' : 1 , 'in_filter' : 1 , 'parent' : dt } ; }
me . make _datatable ( ) ; me . orig _sort _list = [ ] ; if ( me . parent _dt ) { me . setup _dt _filters _and _cols ( fl , me . parent _dt ) ; var fl = [ ] ; }
me . setup _dt _filters _and _cols ( fl , me . doctype ) ; if ( ! this . has _primary _filters )
$dh ( this . report _filters . first _page _filter ) ; this . column _picker . refresh ( ) ; $ds ( me . body ) ; }
_r . ReportBuilder . prototype . set _filters _from _route = function ( ) { var route = wn . get _route ( ) ; if ( route . length > 3 ) { for ( var i = 3 ; i < route . length ; i ++ ) { var p = route [ i ] . split ( '=' ) ; if ( p . length == 2 ) { var dt = this . parent _dt ? this . parent _dt : this . doctype ; this . set _filter ( dt , p [ 0 ] , p [ 1 ] ) ; } } } }
_r . ReportBuilder . prototype . add _filter = function ( f ) { if ( this . filter _fields _dict [ f . parent + '\1' + f . label ] ) { this . filter _fields _dict [ f . parent + '\1' + f . label ] . df = f ; } else { this . report _filters . add _field ( f , f . parent , null , 1 ) ; } }
_r . ReportBuilder . prototype . setup _dt _filters _and _cols = function ( fl , dt ) { var me = this ; var lab = $a ( me . filter _area , 'div' , 'filter_dt_head' ) ; lab . innerHTML = 'Filters for ' + get _doctype _label ( dt ) ; var lab = $a ( me . picker _area , 'div' , 'builder_dt_head' ) ; lab . innerHTML = 'Select columns for ' + get _doctype _label ( dt ) ; var dt _fields = wn . meta . docfield _list [ dt ] ; for ( var i = 0 ; i < dt _fields . length ; i ++ ) { fl [ fl . length ] = dt _fields [ i ] ; }
var sf _list = locals . DocType [ dt ] . search _fields ? locals . DocType [ dt ] . search _fields . split ( ',' ) : [ ] ; for ( var i in sf _list ) sf _list [ i ] = strip ( sf _list [ i ] ) ; for ( var i = 0 ; i < fl . length ; i ++ ) { var f = fl [ i ] ; if ( f && cint ( f . in _filter ) ) { me . report _filters . add _field ( f , dt , in _list ( sf _list , f . fieldname ) ) ; }
if ( f && ! in _list ( no _value _fields , f . fieldtype ) && f . fieldname != 'docstatus' && ( ! f . report _hide ) ) { me . column _picker . add _field ( f ) ; } }
me . set _sort _options ( ) ; }
_r . ReportBuilder . prototype . set _sort _options = function ( l ) { var sl = this . orig _sort _list ; empty _select ( this . dt . sort _sel ) ; if ( l ) sl = add _lists ( l , this . orig _sort _list ) ; if ( ! l ) l = [ ] ; if ( ! l . length ) { l . push ( [ 'ID' , 'name' ] ) }
for ( var i = 0 ; i < sl . length ; i ++ ) { this . dt . add _sort _option ( sl [ i ] [ 0 ] , sl [ i ] [ 1 ] ) ; } }
_r . ReportBuilder . prototype . validate _permissions = function ( onload ) { this . perm = get _perm ( this . parent _dt ? this . parent _dt : this . doctype ) ; if ( ! this . perm [ 0 ] [ READ ] ) { this . forbidden = 1 ; if ( user == 'Guest' ) { msgprint ( 'You must log in to view this page' ) ; } else { msgprint ( 'No Read Permission' ) ; }
window . back ( ) ; return 0 ; }
return 1 ; }
_r . ReportBuilder . prototype . setup _doctype = function ( onload ) { var me = this ; if ( ! locals [ 'DocType' ] [ this . doctype ] ) { this . load _doctype _from _server ( onload ) ; } else { for ( var key in locals . DocField ) { var f = locals . DocField [ key ] ; if ( f . fieldtype == 'Table' && f . options == this . doctype )
this . parent _dt = f . parent ; }
if ( ! me . validate _permissions ( ) )
return ; me . validate _permissions ( ) ; me . make _body ( ) ; me . setup _filters _and _cols ( ) ; if ( onload ) onload ( me ) ; } }
_r . ReportBuilder . prototype . load _doctype _from _server = function ( onload ) { var me = this ; $c ( 'webnotes.widgets.form.load.getdoctype' , args = { 'doctype' : this . doctype , 'with_parent' : 1 } , function ( r , rt ) { if ( r . parent _dt ) me . parent _dt = r . parent _dt ; if ( ! me . validate _permissions ( ) )
return ; me . make _body ( ) ; me . setup _filters _and _cols ( ) ; if ( onload ) onload ( me ) ; } ) ; }
_r . ReportBuilder . prototype . reset _report = function ( ) { this . clear _criteria ( ) ; this . mytabs . items [ 'Select Columns' ] . show ( ) ; this . mytabs . items [ 'More Filters' ] . show ( ) ; this . report _filters . refresh ( ) ; this . column _picker . refresh ( ) ; var dt = this . parent _dt ? this . parent _dt : this . doctype ; this . set _filter ( dt , 'Saved' , 1 ) ; this . set _filter ( dt , 'Submitted' , 1 ) ; this . set _filter ( dt , 'Cancelled' , 0 ) ; this . column _picker . set _defaults ( ) ; this . dt . clear _all ( ) ; this . dt . sort _sel . value = 'ID' ; this . dt . page _len _sel . inp . value = '50' ; this . dt . set _no _limit ( 0 ) ; this . dt . set _desc ( ) ; this . set _filters _from _route ( ) ; }
_r . ReportBuilder . prototype . make _datatable = function ( ) { var me = this ; this . dt _area = $a ( this . mytabs . items [ 'Result' ] . body , 'div' ) ; var clear _area = $a ( this . mytabs . items [ 'Result' ] . body , 'div' ) ; clear _area . style . marginTop = '8px' ; clear _area . style . textAlign = 'right' ; this . clear _btn = $a ( $a ( clear _area , 'span' ) , 'button' ) ; this . clear _btn . innerHTML = 'Clear Settings' ; this . clear _btn . onclick = function ( ) { me . reset _report ( ) ; }
var d = $a ( clear _area , 'span' , '' , { marginLeft : '16px' } ) ; d . innerHTML = '<span>Show Query: </span>' ; this . show _query = $a _input ( d , 'checkbox' ) ; this . show _query . checked = false ; this . dt = new _r . DataTable ( this . dt _area , '' ) ; this . dt . finder = this ; this . dt . make _query = function ( ) { var report = me ; if ( me . current _loaded && me . sc _dict [ me . current _loaded ] ) { var sc = get _local ( 'Search Criteria' , me . sc _dict [ me . current _loaded ] ) ; }
if ( sc ) me . dt . search _criteria = sc ; else me . dt . search _criteria = null ; if ( sc && sc . server _script ) me . dt . server _script = sc . server _script ; else me . dt . server _script = null ; for ( var i = 0 ; i < me . fn _list . length ; i ++ ) { if ( me [ me . fn _list [ i ] ] ) me . dt [ me . fn _list [ i ] ] = me [ me . fn _list [ i ] ] ; else me . dt [ me . fn _list [ i ] ] = null ; }
var fl = [ ] ; var docstatus _cl = [ ] ; var cl = [ ] ; var table _name = function ( t ) { return '`tab' + t + '`' ; }
var dis _filters _list = [ ] ; if ( sc && sc . dis _filters )
var dis _filters _list = sc . dis _filters . split ( '\n' ) ; var t = me . column _picker . get _selected ( ) ; for ( var i = 0 ; i < t . length ; i ++ ) { fl . push ( table _name ( t [ i ] . parent ) + '.`' + t [ i ] . fieldname + '` AS `' + t [ i ] . parent + '.' + t [ i ] . fieldname + '`' ) ; }
me . selected _fields = fl ; if ( sc && sc . add _col ) { var adv _fl = sc . add _col . split ( '\n' ) ; for ( var i = 0 ; i < adv _fl . length ; i ++ ) { fl [ fl . length ] = adv _fl [ i ] ; } }
me . dt . filter _vals = { }
add _to _filter = function ( k , v , is _select ) { if ( v == null ) v = '' ; if ( ! in _list ( keys ( me . dt . filter _vals ) , k ) ) { me . dt . filter _vals [ k ] = v ; } else { if ( is _select )
me . dt . filter _vals [ k ] += '\n' + v ; else
me . dt . filter _vals [ k + '1' ] = v ; } }
for ( var i = 0 ; i < me . filter _fields . length ; i ++ ) { var t = me . filter _fields [ i ] ; var v = t . get _value ? t . get _value ( ) : '' ; if ( t . df . fieldtype == 'Select' ) { if ( t . input . multiple ) { for ( var sel _i = 0 ; sel _i < v . length ; sel _i ++ ) { add _to _filter ( t . df . fieldname , v [ sel _i ] , 1 ) ; }
if ( ! v . length ) add _to _filter ( t . df . fieldname , "" , 1 ) ; } else { add _to _filter ( t . df . fieldname , v ) ; } } else add _to _filter ( t . df . fieldname , v ) ; if ( ! in _list ( dis _filters _list , t . df . fieldname ) && ! t . df . ignore ) { if ( t . df . fieldname == 'docstatus' ) { if ( t . df . label == 'Saved' ) { if ( t . get _value ( ) ) docstatus _cl [ docstatus _cl . length ] = table _name ( t . df . parent ) + '.docstatus=0' ; else cl [ cl . length ] = table _name ( t . df . parent ) + '.docstatus!=0' ; }
else if ( t . df . label == 'Submitted' ) { if ( t . get _value ( ) ) docstatus _cl [ docstatus _cl . length ] = table _name ( t . df . parent ) + '.docstatus=1' ; else cl [ cl . length ] = table _name ( t . df . parent ) + '.docstatus!=1' ; }
else if ( t . df . label == 'Cancelled' ) { if ( t . get _value ( ) ) docstatus _cl [ docstatus _cl . length ] = table _name ( t . df . parent ) + '.docstatus=2' ; else cl [ cl . length ] = table _name ( t . df . parent ) + '.docstatus!=2' ; } } else { var fn = '`' + t . df . fieldname + '`' ; var v = t . get _value ? t . get _value ( ) : '' ; if ( v ) { if ( in _list ( [ 'Data' , 'Link' , 'Small Text' , 'Text' ] , t . df . fieldtype ) ) { cl [ cl . length ] = table _name ( t . df . parent ) + '.' + fn + ' LIKE "' + v + '%"' ; } else if ( t . df . fieldtype == 'Select' ) { if ( t . input . multiple ) { var tmp _cl = [ ] ; for ( var sel _i = 0 ; sel _i < v . length ; sel _i ++ ) { if ( v [ sel _i ] ) { tmp _cl [ tmp _cl . length ] = table _name ( t . df . parent ) + '.' + fn + ' = "' + v [ sel _i ] + '"' ; } }
if ( tmp _cl . length ) cl [ cl . length ] = '(' + tmp _cl . join ( ' OR ' ) + ')' ; } else { cl [ cl . length ] = table _name ( t . df . parent ) + '.' + fn + ' = "' + v + '"' ; } } else { var condition = '=' ; if ( t . sql _condition ) condition = t . sql _condition ; cl [ cl . length ] = table _name ( t . df . parent ) + '.' + fn + condition + '"' + v + '"' ; } } } } }
me . dt . filter _vals . user = user ; me . dt . filter _vals . user _email = user _email ; me . filter _vals = me . dt . filter _vals ; this . is _simple = 0 ; if ( sc && sc . custom _query ) { this . query = repl ( sc . custom _query , me . dt . filter _vals ) ; this . is _simple = 1 ; return }
if ( me . get _query ) { this . query = me . get _query ( ) ; this . is _simple = 1 ; } else { if ( docstatus _cl . length )
cl [ cl . length ] = '(' + docstatus _cl . join ( ' OR ' ) + ')' ; if ( sc && sc . add _cond ) { var adv _cl = sc . add _cond . split ( '\n' ) ; for ( var i = 0 ; i < adv _cl . length ; i ++ ) { cl [ cl . length ] = adv _cl [ i ] ; } }
if ( ! fl . length ) { alert ( 'You must select atleast one column to view' ) ; this . query = '' ; return ; }
var tn = table _name ( me . doctype ) ; if ( me . parent _dt ) { tn = tn + ',' + table _name ( me . parent _dt ) ; cl [ cl . length ] = table _name ( me . doctype ) + '.`parent` = ' + table _name ( me . parent _dt ) + '.`name`' ; }
if ( sc && sc . add _tab ) { var adv _tl = sc . add _tab . split ( '\n' ) ; tn = tn + ',' + adv _tl . join ( ',' ) ; }
if ( ! cl . length )
this . query = 'SELECT ' + fl . join ( ',\n' ) + ' FROM ' + tn
else
this . query = 'SELECT ' + fl . join ( ',' ) + ' FROM ' + tn + ' WHERE ' + cl . join ( '\n AND ' ) ; if ( sc && sc . group _by ) { this . query += ' GROUP BY ' + sc . group _by ; }
this . query = repl ( this . query , me . dt . filter _vals ) }
if ( me . show _query . checked ) { this . show _query = 1 ; }
if ( me . current _loaded ) this . rep _name = me . current _loaded ; else this . rep _name = me . doctype ; } }
_r . ReportBuilder . prototype . get _filter = function ( dt , label ) { return this . filter _fields _dict [ dt + FILTER _SEP + label ] ; }
_r . ReportBuilder . prototype . set _filter _properties = function ( dt , label , properties ) { var f = this . filter _fields _dict [ dt + FILTER _SEP + label ] ; for ( key in properties ) { f . df [ key ] = properties [ key ] ; } }
_r . ReportFilters = function ( rb ) { this . rb = rb ; this . first _page _filter = $a ( rb . mytabs . items [ 'Result' ] . body , 'div' , 'finder_filter_area' ) ; this . filter _area = $a ( rb . mytabs . items [ 'More Filters' ] . body , 'div' , 'finder_filter_area' ) ; this . filter _fields _area = $a ( this . filter _area , 'div' ) ; }
_r . ReportFilters . prototype . refresh = function ( ) { var fl = this . rb . filter _fields
for ( var i = 0 ; i < fl . length ; i ++ ) { var f = fl [ i ] ; if ( f . df . filter _hide ) { $dh ( f . wrapper ) ; } else { $ds ( f . wrapper ) ; }
if ( f . df . bold ) { if ( f . label _cell )
$y ( f . label _cell , { fontWeight : 'bold' } ) } else { if ( f . label _cell ) $y ( f . label _cell , { fontWeight : 'normal' } ) }
if ( f . df [ 'report_default' ] )
f . set _input ( f . df [ 'report_default' ] ) ; if ( f . df . in _first _page && f . df . filter _cell ) { f . df . filter _cell . parentNode . removeChild ( f . df . filter _cell ) ; this . first _page _filter . appendChild ( f . df . filter _cell ) ; this . rb . has _primary _filters = 1 ; $ds ( this . first _page _filter ) ; } } }
_r . ReportFilters . prototype . add _date _field = function ( cell , f , dt , is _custom ) { var my _div = $a ( cell , 'div' , '' , { } ) ; var f1 = copy _dict ( f ) ; f1 . label = 'From ' + f1 . label ; var tmp1 = this . make _field _obj ( f1 , dt , my _div , is _custom ) ; tmp1 . sql _condition = '>=' ; tmp1 . bound = 'lower' ; var f2 = copy _dict ( f ) ; f2 . label = 'To ' + f2 . label ; var tmp2 = this . make _field _obj ( f2 , dt , my _div , is _custom ) ; tmp2 . sql _condition = '<=' ; tmp2 . bound = 'upper' ; }
_r . ReportFilters . prototype . add _numeric _field = function ( cell , f , dt , is _custom ) { var my _div = $a ( cell , 'div' , '' , { } ) ; var f1 = copy _dict ( f ) ; f1 . label = f1 . label + ' >=' ; var tmp1 = this . make _field _obj ( f1 , dt , my _div , is _custom ) ; tmp1 . sql _condition = '>=' ; tmp1 . bound = 'lower' ; var f2 = copy _dict ( f ) ; f2 . label = f2 . label + ' <=' ; var tmp2 = this . make _field _obj ( f2 , dt , my _div , is _custom ) ; tmp2 . sql _condition = '<=' ; tmp2 . bound = 'upper' ; }
_r . ReportFilters . prototype . make _field _obj = function ( f , dt , parent , is _custom ) { var tmp = make _field ( f , dt , parent , this . rb , false ) ; tmp . not _in _form = 1 ; tmp . in _filter = 1 ; tmp . refresh ( ) ; this . rb . filter _fields [ this . rb . filter _fields . length ] = tmp ; this . rb . filter _fields _dict [ f . parent + '\1' + f . label ] = tmp ; if ( is _custom ) tmp . is _custom = 1 ; return tmp ; }
_r . ReportFilters . prototype . add _field = function ( f , dt , in _primary , is _custom ) { var me = this ; if ( f . in _first _page ) in _primary = true ; var fparent = this . filter _fields _area ; if ( in _primary ) { fparent = this . first _page _filter ; this . rb . has _primary _filters = 1 ; }
if ( f . on _top ) { var cell = document . createElement ( 'div' ) ; fparent . insertBefore ( cell , fparent . firstChild ) ; $y ( cell , { width : '70%' } ) ; } else if ( f . insert _before ) { var cell = document . createElement ( 'div' ) ; fparent . insertBefore ( cell , fparent [ f . df . insert _before ] . filter _cell ) ; $y ( cell , { width : '70%' } ) ; }
else
var cell = $a ( fparent , 'div' , '' , { width : '70%' } ) ; f . filter _cell = cell ; if ( f . fieldtype == 'Date' ) { this . add _date _field ( cell , f , dt ) ; } else if ( in _list ( [ 'Currency' , 'Int' , 'Float' ] , f . fieldtype ) ) { this . add _numeric _field ( cell , f , dt ) ; } else if ( ! in _list ( [ 'Section Break' , 'Column Break' , 'Read Only' , 'HTML' , 'Table' , 'Image' , 'Button' ] , f . fieldtype ) ) { var tmp = this . make _field _obj ( f , dt , cell , is _custom ) ; }
if ( f . fieldname != 'docstatus' )
me . rb . orig _sort _list . push ( [ f . label , '`tab' + f . parent + '`.`' + f . fieldname + '`' ] ) ; if ( f . def _filter )
tmp . input . checked = true ; }
_r . ReportColumnPicker = function ( rb ) { this . rb = rb ; this . picker _area = $a ( this . rb . mytabs . items [ 'Select Columns' ] . body , 'div' , 'finder_picker_area' ) ; this . all _fields = [ ] ; this . sel _idx = 0 ; this . make _body ( ) ; }
_r . ReportColumnPicker . prototype . make _body = function ( ) { var t = make _table ( this . picker _area , 1 , 3 , '100%' , [ '35%' , '30%' , '35%' ] , { verticalAlign : 'middle' , textAlign : 'center' } ) ; $a ( $td ( t , 0 , 0 ) , 'h3' , '' , { marginBottom : '8px' } ) . innerHTML = 'Columns' ; this . unsel _fields = $a ( $td ( t , 0 , 0 ) , 'select' , '' , { height : '200px' , width : '100%' , border : '1px solid #AAA' } ) ; this . unsel _fields . multiple = true ; this . unsel _fields . onchange = function ( ) { for ( var i = 0 ; i < this . options . length ; i ++ ) this . options [ i ] . field . is _selected = this . options [ i ] . selected ; }
var me = this ; this . up _btn = $a ( $a ( $td ( t , 0 , 1 ) , 'div' ) , 'button' , '' , { width : '70px' } ) ; this . up _btn . innerHTML = 'Up ↑' ; this . up _btn . onclick = function ( ) { me . move _up ( ) ; }
this . add _all = $a ( $a ( $td ( t , 0 , 1 ) , 'div' ) , 'button' , '' , { width : '40px' } ) ; this . add _all . innerHTML = '>>' ; this . add _all . onclick = function ( ) { me . move ( me . unsel _fields , 'add' , 1 ) ; }
this . add _btn = $a ( $a ( $td ( t , 0 , 1 ) , 'div' ) , 'button' , '' , { width : '110px' } ) ; this . add _btn . innerHTML = '<b>Add ></b>' ; this . add _btn . onclick = function ( ) { me . move ( me . unsel _fields , 'add' ) ; }
this . remove _btn = $a ( $a ( $td ( t , 0 , 1 ) , 'div' ) , 'button' , '' , { width : '110px' } ) ; this . remove _btn . innerHTML = '<b>< Remove</b>' ; this . remove _btn . onclick = function ( ) { me . move ( me . sel _fields , 'remove' ) ; }
this . remove _all = $a ( $a ( $td ( t , 0 , 1 ) , 'div' ) , 'button' , '' , { width : '40px' } ) ; this . remove _all . innerHTML = '<<' ; this . remove _all . onclick = function ( ) { me . move ( me . sel _fields , 'remove' , 1 ) ; }
this . dn _btn = $a ( $a ( $td ( t , 0 , 1 ) , 'div' ) , 'button' , '' , { width : '70px' } ) ; this . dn _btn . innerHTML = 'Down ↓' ; this . dn _btn . onclick = function ( ) { me . move _down ( ) ; }
$a ( $td ( t , 0 , 2 ) , 'h3' , '' , { marginBottom : '8px' } ) . innerHTML = 'Selected Columns' ; this . sel _fields = $a ( $td ( t , 0 , 2 ) , 'select' , '' , { height : '200px' , width : '100%' , border : '1px solid #AAA' } ) ; this . sel _fields . multiple = true ; this . sel _fields . onchange = function ( ) { for ( var i = 0 ; i < this . options . length ; i ++ ) this . options [ i ] . field . is _selected = this . options [ i ] . selected ; } }
_r . ReportColumnPicker . prototype . get _by _sel _idx = function ( s , idx ) { for ( var j = 0 ; j < s . options . length ; j ++ ) { if ( s . options [ j ] . field . sel _idx == idx )
return s . options [ j ] . field ; }
return { } }
_r . ReportColumnPicker . prototype . move _up = function ( ) { var s = this . sel _fields ; for ( var i = 1 ; i < s . options . length ; i ++ ) { if ( s . options [ i ] . selected ) { s . options [ i ] . field . sel _idx -- ; this . get _by _sel _idx ( s , i - 1 ) . sel _idx ++ ; } }
this . refresh ( ) ; }
_r . ReportColumnPicker . prototype . move _down = function ( ) { var s = this . sel _fields ; if ( s . options . length <= 1 ) return ; for ( var i = s . options . length - 2 ; i >= 0 ; i -- ) { if ( s . options [ i ] . selected ) { this . get _by _sel _idx ( s , i + 1 ) . sel _idx -- ; s . options [ i ] . field . sel _idx ++ ; } }
this . refresh ( ) ; }
_r . ReportColumnPicker . prototype . move = function ( s , type , all ) { for ( var i = 0 ; i < s . options . length ; i ++ ) { if ( s . options [ i ] . selected || all ) { if ( type == 'add' ) { s . options [ i ] . field . selected = 1 ; s . options [ i ] . field . sel _idx = this . sel _idx ; this . sel _idx ++ ; } else { s . options [ i ] . field . selected = 0 ; s . options [ i ] . field . sel _idx = 0 ; this . sel _idx -- ; } } }
this . refresh ( ) ; }
_r . ReportColumnPicker . prototype . refresh = function ( ) { var ul = [ ] ; var sl = [ ] ; for ( var i = 0 ; i < this . all _fields . length ; i ++ ) { var o = this . all _fields [ i ] ; if ( o . selected ) { sl . push ( o ) ; if ( this . rb . dt ) this . rb . dt . set _sort _option _disabled ( o . df . label , 0 ) ; } else { ul . push ( o ) ; if ( this . rb . dt ) this . rb . dt . set _sort _option _disabled ( o . df . label , 1 ) ; } }
ul . sort ( function ( a , b ) { return ( cint ( a . df . idx ) - cint ( b . df . idx ) ) } ) ; sl . sort ( function ( a , b ) { return ( cint ( a . sel _idx ) - cint ( b . sel _idx ) ) } )
for ( var i = 0 ; i < sl . length ; i ++ ) { sl [ i ] . sel _idx = i ; }
this . set _options ( this . unsel _fields , ul ) ; this . set _options ( this . sel _fields , sl ) ; }
_r . ReportColumnPicker . prototype . set _options = function ( s , l ) { empty _select ( s ) ; for ( var i = 0 ; i < l . length ; i ++ ) { var v = l [ i ] . df . parent + '.' + l [ i ] . df . label ; var v _label = get _doctype _label ( l [ i ] . df . parent ) + '.' + l [ i ] . df . label ; var o = new Option ( v _label , v , false , false ) ; o . field = l [ i ] ; if ( o . field . is _selected ) o . selected = 1 ; s . options [ s . options . length ] = o ; } }
_r . ReportColumnPicker . prototype . clear = function ( ) { this . sel _idx = 0 ; for ( var i = 0 ; i < this . all _fields . length ; i ++ ) { this . all _fields [ i ] . selected = 0 ; }
this . refresh ( ) ; }
_r . ReportColumnPicker . prototype . get _selected = function ( ) { var sl = [ ] ; for ( var i = 0 ; i < this . all _fields . length ; i ++ ) { var o = this . all _fields [ i ] ; if ( o . selected ) { sl [ sl . length ] = o . df ; o . df . sel _idx = o . sel _idx ; } }
return sl . sort ( function ( a , b ) { return ( cint ( a . sel _idx ) - cint ( b . sel _idx ) ) } ) ; }
_r . ReportColumnPicker . prototype . set _defaults = function ( ) { for ( var i = 0 ; i < this . all _fields . length ; i ++ ) { if ( this . all _fields [ i ] . selected _by _default )
this . all _fields [ i ] . selected = 1 ; } }
_r . ReportColumnPicker . prototype . add _field = function ( f ) { if ( ! f . label ) return ; var by _default = ( f . in _filter ) ? 1 : 0 ; this . all _fields . push ( { selected : by _default , df : f , sel _idx : ( by _default ? this . sel _idx : 0 ) , selected _by _default : by _default } ) ; this . sel _idx += by _default ; }
_r . ReportColumnPicker . prototype . set = function ( dt , label , selected ) { for ( var i = 0 ; i < this . all _fields . length ; i ++ ) { if ( this . all _fields [ i ] . df . parent == dt && this . all _fields [ i ] . df . label == label ) { this . all _fields [ i ] . selected = selected ; this . all _fields [ i ] . sel _idx = this . sel _idx ; this . sel _idx += cint ( selected ) ; this . refresh ( ) ; return ; } } }
/ *
* lib / js / legacy / widgets / report _builder / datatable . js
* /
_r . scroll _head = function ( ele ) { var h = ele . childNodes [ 0 ] ; h . style . top = cint ( ele . scrollTop ) + 'px' ; }
_r . DataTable = function ( html _fieldname , dt , repname , hide _toolbar ) { var me = this ; if ( html _fieldname . substr ) { var html _field = cur _frm . fields _dict [ html _fieldname ] ; html _field . onrefresh = function ( ) { if ( me . docname != cur _frm . docname ) { me . clear _all ( ) ; me . docname = cur _frm . docname ; } }
var parent = html _field . wrapper ; datatables [ html _fieldname ] = this ; } else { var parent = html _fieldname ; }
this . start _rec = 1 ; this . page _len = 50 ; this . repname = repname ; this . dt = dt ; this . no _limit = false ; this . query = '' ; this . has _index = 1 ; this . has _headings = 1 ; this . disabled _options = { } ; this . levels = [ ] ; if ( this . dt ) { var tw = $a ( parent , 'div' ) ; var t = $a ( tw , 'div' , 'link_type' ) ; t . style . cssFloat = 'right' ; $h ( tw , '14px' ) ; t . style . margin = '2px 0px' ; t . style . fontSize = '11px' ; t . onclick = function ( ) { new _doc ( me . dt ) ; }
t . innerHTML = 'New ' + this . dt ; }
if ( ! hide _toolbar ) this . make _toolbar ( parent ) ; this . wrapper = $a ( parent , 'div' , 'report_tab' ) ; $h ( this . wrapper , cint ( screen . height * 0.35 ) + 'px' ) ; this . wrapper . onscroll = function ( ) { _r . scroll _head ( this ) ; }
this . hwrapper = $a ( this . wrapper , 'div' , 'report_head_wrapper' ) ; this . twrapper = $a ( this . wrapper , 'div' , 'report_tab_wrapper' ) ; this . no _data _tag = $a ( this . wrapper , 'div' , 'report_no_data' ) ; this . no _data _tag . innerHTML = 'No Records Found' ; this . fetching _tag = $a ( this . wrapper , 'div' , '' , { height : '100%' , background : 'url("images/lib/ui/square_loading.gif") center no-repeat' , display : 'none' } ) ; }
_r . DataTable . prototype . add _icon = function ( parent , imgsrc ) { var i = $a ( parent , 'img' ) ; i . style . padding = '2px' ; i . style . cursor = 'pointer' ; i . setAttribute ( 'src' , 'images/lib/icons/' + imgsrc + '.gif' ) ; return i ; }
_r . DataTable . prototype . set _no _limit = function ( v ) { if ( v ) { this . no _limit = 1 ; $dh ( this . page _len _sel . wrapper ) ; } else { this . no _limit = 0 ; $ds ( this . page _len _sel . wrapper ) ; } }
_r . DataTable . prototype . make _toolbar = function ( parent ) { var me = this ; this . hbar = $a ( parent , 'div' , '' , { margin : '8px 0px 16px 0px' } ) ; var ht = make _table ( this . hbar , 1 , 3 , '100%' , [ '40%' , '40%' , '20%' ] , { verticalAlign : 'middle' } ) ; var div = $a ( $td ( ht , 0 , 0 ) , 'div' ) ; var t = make _table ( $td ( ht , 0 , 1 ) , 1 , 6 , null , [ null , null , null , '20px' , null , null ] , { verticalAlign : 'middle' } ) ; $td ( t , 0 , 0 ) . innerHTML = 'Sort By:' ; $y ( $td ( t , 0 , 1 ) , { textAlign : 'right' , paddingRight : '4px' } ) ; this . sort _sel = $a ( $td ( t , 0 , 2 ) , 'select' , '' , { width : '100px' } ) ; this . sort _sel . onchange = function ( ) { me . start _rec = 1 ; me . run ( ) ; }
this . sort _icon = this . add _icon ( $td ( t , 0 , 3 ) , 'arrow_down' ) ; this . sort _order = 'DESC' ; this . sort _icon . onclick = function ( ) { if ( me . sort _order == 'ASC' ) me . set _desc ( ) ; else me . set _asc ( ) ; me . start _rec = 1 ; me . run ( ) ; }
$td ( t , 0 , 4 ) . innerHTML = 'Per Page:' ; $y ( $td ( t , 0 , 4 ) , { textAlign : 'right' , paddingRight : '4px' } ) ; var s = new SelectWidget ( $td ( t , 0 , 5 ) , [ '50' , '100' , '500' , '1000' ] , '70px' ) ; s . inp . value = '50' ; s . inp . onchange = function ( ) { me . page _len = flt ( this . value ) ; }
this . page _len _sel = s ; var c1 = $td ( ht , 0 , 2 ) ; c1 . style . textAlign = 'right' ; var ic = this . add _icon ( c1 , 'resultset_first' ) ; ic . onclick = function ( ) { me . start _rec = 1 ; me . run ( ) ; }
var ic = this . add _icon ( c1 , 'resultset_previous' ) ; ic . onclick = function ( ) { if ( me . start _rec - me . page _len <= 0 ) return ; me . start _rec = me . start _rec - me . page _len ; me . run ( ) ; }
this . has _next = false ; var ic = this . add _icon ( c1 , 'resultset_next' ) ; ic . onclick = function ( ) { if ( ! me . has _next ) return ; me . start _rec = me . start _rec + me . page _len ; me . run ( ) ; } }
_r . DataTable . prototype . set _desc = function ( ) { this . sort _icon . src = 'images/lib/icons/arrow_down.gif' ; this . sort _order = 'DESC' ; }
_r . DataTable . prototype . set _asc = function ( icon ) { this . sort _icon . src = 'images/lib/icons/arrow_up.gif' ; this . sort _order = 'ASC' ; }
_r . DataTable . prototype . set _sort _option _disabled = function ( label , disabled ) { var s = this . sort _sel ; if ( disabled ) { for ( var i = 0 ; i < s . options . length ; i ++ ) { if ( s . options [ i ] && s . options [ i ] . text == label ) { this . disabled _options [ label ] = s . options [ i ] ; s . remove ( i ) ; } } } else { if ( this . disabled _options [ label ] ) { try { s . add ( this . disabled _options [ label ] , s . options [ s . options . length - 1 ] ) ; } catch ( e ) { try { s . add ( this . disabled _options [ label ] , s . options . length - 1 ) ; } catch ( e ) { } }
this . disabled _options [ label ] = null ; } } }
_r . DataTable . prototype . add _sort _option = function ( label , val ) { var s = this . sort _sel ; s . options [ s . options . length ] = new Option ( label , val , false , s . options . length == 0 ? true : false ) ; }
_r . DataTable . prototype . update _query = function ( no _limit ) { if ( ( _r . rb _con . cur _rb && _r . rb _con . cur _rb . get _query ) || ( this . search _criteria && this . search _criteria . custom _query ) ) { } else { if ( ! sel _val ( this . sort _sel ) ) { this . sort _sel . selectedIndex = 0 ; }
this . query += NEWLINE
+ ' ORDER BY ' + sel _val ( this . sort _sel )
+ ' ' + this . sort _order ; }
if ( no _limit || this . no _limit ) { if ( this . show _query ) alert ( this . query ) ; return ; }
this . query += ' LIMIT ' + ( this . start _rec - 1 ) + ',' + this . page _len ; if ( this . show _query )
alert ( this . query ) ; }
_r . DataTable . prototype . _get _query = function ( no _limit ) { $dh ( this . no _data _tag ) ; this . show _query = 0 ; if ( this . make _query )
this . make _query ( ) ; this . update _query ( no _limit ) ; }
_r . DataTable . prototype . run = function ( ) { if ( this . validate && ! this . validate ( ) )
return ; if ( _r . rb _con . cur _rb ) { if ( _r . rb _con . cur _rb . large _report == 1 ) { msgprint ( "This is a very large report and cannot be shown in the browser as it is likely to make your browser very slow.<br><br>Please click on 'Export' to open in a spreadsheet" ) ; return ; }
_r . rb _con . cur _rb . mytabs . items [ 'Result' ] . expand ( ) ; }
var me = this ; this . _get _query ( ) ; if ( this . set _data ) { this . show _result ( this . set _data ) ; this . set _data = null ; return ; }
$ds ( this . fetching _tag ) ; if ( $ . browser . mozilla ) this . clear _all ( ) ; var args = { 'query' : me . query , 'report_name' : '_r.DataTable' , 'show_deleted' : 1 , 'sc_id' : me . search _criteria ? me . search _criteria . name : '' , 'filter_values' : me . filter _vals ? docstring ( me . filter _vals ) : '' , 'roles' : '["' + user _roles . join ( '","' ) + '"]' }
if ( this . is _simple ) args . is _simple = 1 ; $c ( 'webnotes.widgets.query_builder.runquery' , args , function ( r , rt ) { $dh ( me . fetching _tag ) ; me . show _result ( r , rt ) ; } ) ; }
_r . DataTable . prototype . clear _all = function ( ) { if ( this . htab && this . htab . parentNode ) { this . htab . parentNode . removeChild ( this . htab ) ; delete this . htab ; }
if ( this . tab && this . tab . parentNode ) { this . tab . parentNode . removeChild ( this . tab ) ; delete this . tab ; }
$dh ( this . no _data _tag ) ; }
_r . DataTable . prototype . has _data = function ( ) { if ( this . htab && this . htab . rows . length ) return 1 ; else return 0 ; }
_r . DataTable . prototype . show _result = function ( r , rt ) { var me = this ; this . clear _all ( ) ; this . rset = eval ( r . values ) ; if ( this . rset && this . rset . length ) { if ( this . has _headings ) { this . htab = $a ( this . hwrapper , 'table' ) ; $y ( this . twrapper , { top : '25px' , borderTop : '0px' } ) ; }
this . tab = $a ( this . twrapper , 'table' ) ; this . colwidths = eval ( r . colwidths ) ; this . coltypes = eval ( r . coltypes ) ; this . coloptions = eval ( r . coloptions ) ; this . colnames = eval ( r . colnames ) ; $y ( this . tab , { tableLayout : 'fixed' } ) ; if ( this . beforetableprint ) this . beforetableprint ( this ) ; if ( this . has _headings ) this . make _head _tab ( this . colnames ) ; var start = this . start _rec ; var rset _len = this . rset . length ; if ( rset _len > 1000 ) { msgprint ( "Showing only 1000 records out of " + rset _len + ". Use 'Export' to see all records" ) ; rset _len = 1000 ; }
for ( var vi = 0 ; vi < rset _len ; vi ++ ) { var row = this . tab . insertRow ( vi ) ; if ( this . has _index ) { var c0 = row . insertCell ( 0 ) ; $w ( c0 , '30px' ) ; $a ( c0 , 'div' , '' , { width : '23px' } ) . innerHTML = start ; }
start ++ ; for ( var ci = 0 ; ci < this . rset [ vi ] . length ; ci ++ ) { this . make _data _cell ( vi , ci , this . rset [ vi ] [ ci ] ) ; }
if ( this . afterrowprint ) { row . data _cells = { } ; row . data = { } ; for ( var ci = 0 ; ci < this . colnames . length ; ci ++ ) { row . data [ this . colnames [ ci ] ] = this . rset [ vi ] [ ci ] ; row . data _cells [ this . colnames [ ci ] ] = row . cells [ ci + 1 ] ; } f
this . afterrowprint ( row ) ; } }
if ( this . rset . length && this . rset . length >= this . page _len ) this . has _next = true ; if ( r . style ) { for ( var i = 0 ; i < r . style . length ; i ++ ) { $yt ( this . tab , r . style [ i ] [ 0 ] , r . style [ i ] [ 1 ] , r . style [ i ] [ 2 ] ) ; } }
if ( this . aftertableprint ) this . aftertableprint ( this . tab ) ; } else { $ds ( this . no _data _tag ) ; } }
_r . DataTable . prototype . get _col _width = function ( i ) { if ( this . colwidths && this . colwidths . length && this . colwidths [ i ] )
return cint ( this . colwidths [ i ] ) + 'px' ; else return '100px' ; }
_r . DataTable . prototype . make _head _tab = function ( colnames ) { var r0 = this . htab . insertRow ( 0 ) ; if ( this . has _index ) { var c0 = r0 . insertCell ( 0 ) ; c0 . className = 'report_head_cell' ; $w ( c0 , '30px' ) ; $a ( c0 , 'div' ) . innerHTML = 'Sr' ; this . total _width = 30 ; }
for ( var i = 0 ; i < colnames . length ; i ++ ) { var w = this . get _col _width ( i ) ; this . total _width += cint ( w ) ; var c = r0 . insertCell ( r0 . cells . length ) ; c . className = 'report_head_cell' ; if ( w ) $w ( c , w ) ; $a ( c , 'div' ) . innerHTML = colnames [ i ] ; c . val = colnames [ i ] ; }
$w ( this . htab , this . total _width + 'px' ) ; $w ( this . tab , this . total _width + 'px' ) ; }
_r . DataTable . prototype . make _data _cell = function ( ri , ci , val ) { var row = this . tab . rows [ ri ] ; var c = row . insertCell ( row . cells . length ) ; if ( row . style . color )
c . style . color = row . style . color ; if ( row . style . backgroundColor )
c . style . backgroundColor = row . style . backgroundColor ; if ( row . style . fontWeight )
c . style . fontWeight = row . style . fontWeight ; if ( row . style . fontSize )
c . style . fontSize = row . style . fontSize ; var w = this . get _col _width ( ci ) ; if ( w ) $w ( c , w ) ; c . val = val ; var me = this ; c . div = $a ( c , 'div' , '' , { width : ( cint ( w ) - 7 ) + 'px' } ) ; $s ( c . div , val , this . coltypes [ ci ] , this . coloptions [ ci ] ) }
2012-05-23 08:11:11 +00:00
_r . DataTable . prototype . do _print = function ( ) { this . _get _query ( true ) ; args = { query : this . query , title : this . rep _name ? this . rep _name : this . dt , colnames : null , colwidhts : null , coltypes : null , has _index : this . has _index , has _headings : this . has _headings , check _limit : 1 , is _simple : ( this . is _simple ? 'Yes' : '' ) , sc _id : ( this . search _criteria ? this . search _criteria . name : '' ) , filter _values : docstring ( this . filter _vals ) , } ; wn . require ( 'js/print_query.js' ) ; _p . print _query = new _p . PrintQuery ( ) ; _p . print _query . show _dialog ( args ) ; }
2012-05-07 12:30:57 +00:00
_r . DataTable . prototype . do _export = function ( ) { this . _get _query ( true ) ; var me = this ; export _query ( this . query , function ( q ) { export _csv ( q , ( me . rep _name ? me . rep _name : me . dt ) , ( me . search _criteria ? me . search _criteria . name : '' ) , me . is _simple , docstring ( me . filter _vals ) ) ; } ) ; }
_r . DataTable . prototype . do _calc = function ( ) { _r . show _calc ( this . tab , this . colnames , this . coltypes , 1 ) ; }
_r . DataTable . prototype . get _col _data = function ( colname ) { var ci = 0 ; if ( ! this . htab ) return [ ] ; for ( var i = 1 ; i < this . htab . rows [ 0 ] . cells . length ; i ++ ) { var hc = this . htab . rows [ 0 ] . cells [ i ] ; if ( hc . val == colname ) { ci = i ; break ; } }
var ret = [ ] ; for ( var ri = 0 ; ri < this . tab . rows . length ; ri ++ ) { ret [ ret . length ] = this . tab . rows [ ri ] . cells [ ci ] . val ; }
return ret ; }
_r . DataTable . prototype . get _html = function ( ) { var w = document . createElement ( 'div' ) ; w = $a ( w , 'div' ) ; w . style . marginTop = '16px' ; var tab = $a ( w , 'table' ) ; var add _head _style = function ( c , w ) { c . style . fontWeight = 'bold' ; c . style . border = '1px solid #000' ; c . style . padding = '2px' ; if ( w ) $w ( c , w ) ; return c ; }
var add _cell _style = function ( c ) { c . style . padding = '2px' ; c . style . border = '1px solid #000' ; return c ; }
tab . style . borderCollapse = 'collapse' ; var hr = tab . insertRow ( 0 ) ; var c0 = add _head _style ( hr . insertCell ( 0 ) , '30px' ) ; c0 . innerHTML = 'Sr' ; for ( var i = 1 ; i < this . htab . rows [ 0 ] . cells . length ; i ++ ) { var hc = this . htab . rows [ 0 ] . cells [ i ] ; var c = add _head _style ( hr . insertCell ( i ) , hc . style . width ) ; c . innerHTML = hc . innerHTML ; }
for ( var ri = 0 ; ri < this . tab . rows . length ; ri ++ ) { var row = this . tab . rows [ ri ] ; var dt _row = tab . insertRow ( tab . rows . length ) ; for ( var ci = 0 ; ci < row . cells . length ; ci ++ ) { var c = add _cell _style ( dt _row . insertCell ( ci ) ) ; c . innerHTML = row . cells [ ci ] . innerHTML ; } }
return w . innerHTML ; }
/ *
* lib / js / legacy / widgets / report _builder / calculator . js
* /
_r . calc _dialog = null ; _r . show _calc = function ( tab , colnames , coltypes , add _idx ) { if ( ! add _idx ) add _idx = 0 ; if ( ! tab || ! tab . rows . length ) { msgprint ( "No Data" ) ; return ; }
if ( ! _r . calc _dialog ) { var d = new Dialog ( 400 , 400 , "Calculator" )
d . make _body ( [ [ 'Select' , 'Column' ] , [ 'Data' , 'Sum' ] , [ 'Data' , 'Average' ] , [ 'Data' , 'Min' ] , [ 'Data' , 'Max' ] ] )
d . widgets [ 'Sum' ] . readonly = 'readonly' ; d . widgets [ 'Average' ] . readonly = 'readonly' ; d . widgets [ 'Min' ] . readonly = 'readonly' ; d . widgets [ 'Max' ] . readonly = 'readonly' ; d . widgets [ 'Column' ] . onchange = function ( ) { d . set _calc ( ) ; }
d . set _calc = function ( ) { var cn = sel _val ( this . widgets [ 'Column' ] ) ; var cidx = 0 ; var sum = 0 ; var avg = 0 ; var minv = null ; var maxv = null ; for ( var i = 0 ; i < this . colnames . length ; i ++ ) { if ( this . colnames [ i ] == cn ) { cidx = i + add _idx ; break ; } }
for ( var i = 0 ; i < this . datatab . rows . length ; i ++ ) { var c = this . datatab . rows [ i ] . cells [ cidx ] ; var v = c . div ? flt ( c . div . innerHTML ) : flt ( c . innerHTML ) ; sum += v ; if ( minv == null ) minv = v ; if ( maxv == null ) maxv = v ; if ( v > maxv ) maxv = v ; if ( v < minv ) minv = v ; }
d . widgets [ 'Sum' ] . value = fmt _money ( sum ) ; d . widgets [ 'Average' ] . value = fmt _money ( sum / this . datatab . rows . length ) ; d . widgets [ 'Min' ] . value = fmt _money ( minv ) ; d . widgets [ 'Max' ] . value = fmt _money ( maxv ) ; _r . calc _dialog = d ; }
d . onshow = function ( ) { var cl = [ ] ; for ( var i in _r . calc _dialog . colnames ) { if ( in _list ( [ 'Currency' , 'Int' , 'Float' ] , _r . calc _dialog . coltypes [ i ] ) )
cl . push ( _r . calc _dialog . colnames [ i ] ) ; }
if ( ! cl . length ) { this . hide ( ) ; alert ( "No Numeric Column" ) ; return ; }
var s = this . widgets [ 'Column' ] ; empty _select ( s ) ; add _sel _options ( s , cl ) ; if ( s . inp ) s . inp . value = cl [ 0 ] ; else s . value = cl [ 0 ] ; this . set _calc ( ) ; }
_r . calc _dialog = d ; }
_r . calc _dialog . datatab = tab ; _r . calc _dialog . colnames = colnames ; _r . calc _dialog . coltypes = coltypes ; _r . calc _dialog . show ( ) ; }