Current code.
[capital-apms.git] / inc / browse / accounts.php
blobac6eda4b9d95bf6ff41214b11cfa0852b3615de1
1 <?php
3 require_once('classWidgets.php');
5 param_to_global( 'id', '#^[ACTLPJ]-\d+-\d+(\.\d+)?$#i' );
6 if ( isset($id) ) {
7 list( $et, $ec, $ac ) = explode('-',$id,3);
8 $et = strtoupper(substr($et,0,1));
9 $ec = intval($ec);
10 $ac = floatval($ac);
12 param_to_global('accountgroup', '#^[a-z0-9_-]+$#i'); if (isset($accountgroup) ) $accountgroup = strtoupper($accountgroup);
14 $show_balances = ( (isset($et) && isset($ec)) || isset($ac) );
16 /**
17 * Add some widgets onto the top of the browser
19 $widget = new Widget('accounts');
20 $widget->AddField( 'updates', 'char1', "SELECT ' ', '--Show All--' UNION SELECT 'Z', '--No Manual Posting--' UNION SELECT entitytype, description FROM entitytype ORDER BY 1" );
21 $widget->ReadWrite();
22 $widget->Defaults( array('updates' => ' ' ) );
23 $widget->Layout( '<table> <tr> <th>Update to:</th> <td>##updates.select##</td> <td>##Show.submit##</td> </tr></table>' );
25 $allow_updates = ' ';
26 if ( isset($widget->Record->{'updates'}) && preg_match( '#([ACTLPJZ]+)#i', $widget->Record->{'updates'}, $matches) ) $allow_updates = strtoupper($matches[1]);
28 $page_elements[] = $widget;
31 $browser = new Browser("Accounts");
32 $c->page_title = "Browse Accounts";
34 if ( !isset($ac) ) {
35 if ( !isset($accountgroup) ) $browser->AddColumn( 'accountgroupcode', 'Group', 'left' );
36 $browser->AddColumn( 'accountcode', 'Account', 'right', '', "TO_CHAR(accountcode,'FM0009.00')" );
39 if ( ! $show_balances ) {
40 $browser->AddColumn( 'shortname', 'ShortName' );
43 if ( $show_balances ) {
44 $browser->AddHidden( 'account', "entitytype || '-' || TO_CHAR(entitycode,'FM00009') || '-' || TO_CHAR(accountcode,'FM0009.00')" );
45 if ( !isset($ec) ) {
46 $browser->AddColumn( 'entitycode', "Entity", 'left', '', "entitytype || entitycode" );
47 $browser->AddColumn( 'entityname', "Entity Name", 'left', '', "get_entity_name(entitytype,entitycode)" );
49 else {
50 $browser->AddColumn( 'name', 'Name', 'left', '<td class="left" style="width:30em;">%s</td>', 'chartofaccount.name' );
52 $browser->SetJoins( "accountsummary LEFT JOIN chartofaccount USING ( accountcode ) LEFT JOIN accountgroup USING ( accountgroupcode )" );
53 $browser->AddColumn( 'balance', 'Balance', 'right', '%0.2lf' );
54 $browser->AddTotal( 'balance' );
56 $rowurl = '/view.php?t=account&id=%s';
57 $browser->RowFormat( "<tr onclick=\"window.location='$rowurl';\" class=\"r%d\">\n", "</tr>\n", 'account', '#even' );
59 else {
60 $browser->AddColumn( 'name', 'Name', 'left', '<td class="left" style="width:30em;" title="##alternativecode##">%s</td>', 'chartofaccount.name' );
61 $browser->AddHidden( 'alternativecode' );
62 $browser->AddColumn( 'updateto', 'Updates' );
63 $browser->AddColumn( 'highvolume', 'Volume', 'left', '', "CASE WHEN highvolume THEN 'Yes' ELSE 'No' END" );
64 $browser->SetJoins( "chartofaccount LEFT JOIN accountgroup USING ( accountgroupcode )" );
65 $rowurl = '/browse.php?t=accounts&ac=%s';
66 $browser->RowFormat( "<tr onclick=\"window.location='$rowurl';\" class=\"r%d\">\n", "</tr>\n", 'accountcode', '#even' );
67 $browser->SetWhere( "TRUE" );
70 $browser->SetOrdering( 'accountcode' );
72 if ( isset($et) ) $browser->AndWhere( "entitytype = '$et'" );
73 if ( isset($ec) ) $browser->AndWhere( "entitycode = $ec" );
74 if ( isset($ac) ) $browser->AndWhere( "accountcode = $ac" );
75 if ( isset($accountgroup) ) $browser->AndWhere( "accountgroupcode = ".qpg($accountgroup) );
77 if ( $allow_updates != ' ' ) {
78 if ( $allow_updates != 'Z' )
79 $browser->AndWhere( "updateto ~ '[$allow_updates]'" );
80 else
81 $browser->AndWhere( "updateto IS NULL OR updateto = ''" );
84 include_once("menus_entityaccount.php");
86 $rowurl = '/view.php?t=document&id=%s';
87 $browser->DoQuery();
88 $page_elements[] = $browser;