Current code.
[capital-apms.git] / inc / browse / debtors.php
blob413e43a80fa0b8004a4f714ef0ad7faec88ca64c
1 <?php
2 $related_menu->AddOption("Create Debtor","/edit.php?t=debtor","Create a new debtor", false, 7001);
4 include_once("classWidgets.php");
6 /**
7 * Add some widgets onto the top of the browser
8 */
9 $widget = new Widget();
10 $widget->AddField( 'active', 'log1' );
11 $widget->AddField( 'showzero', 'log2' );
12 $widget->ReadWrite();
13 $widget->Defaults( array('active' => 't', 'showzero' => 'f' ) );
14 $widget->Layout( '<table> <tr>
15 <th>Active:</th> <td>##active.checkbox##</td>
16 <th>Show zero balances:</th> <td>##showzero.checkbox##</td>
17 <td>##Show.submit##</td> </tr></table>'
19 $page_elements[] = $widget;
21 $show_zero = ($widget->Record->{'showzero'} == 't');
22 $show_active = ($widget->Record->{'active'} == 't');
25 /**
26 * Now build the browser
28 $browser = new Browser("Debtors");
29 $browser->AddColumn( 'tenantcode', 'Debtor', 'center' );
30 $browser->AddColumn( 'name', 'Debtor Name' );
31 $browser->AddColumn( 'parent', 'Parent', 'right', '%s', '(t.entitytype || t.entitycode::text)' );
32 $browser->AddColumn( 'balance', 'Balance', 'right', '%0.2lf', 'COALESCE(balance,0.0)' );
33 $browser->AddTotal( 'balance' );
35 $new_invoice_link = '<a href="/edit.php?t=invoice&et=T&ec=##tenantcode##" class="submit">New Invoice</a>';
36 $browser->AddColumn( 'actions', 'Actions', 'center', '&nbsp;%s&nbsp;', "'$new_invoice_link'");
38 $browser->SetJoins( "tenant t LEFT JOIN accountsummary a ON a.entitytype = 'T' AND a.entitycode = t.tenantcode" );
39 $browser->SetWhere( 'TRUE' );
40 if ( ! $show_zero ) $browser->AndWhere( '(ABS(balance) > 1.0)' );
41 if ( $show_active ) $browser->AndWhere( 'active' );
42 $browser->SetOrdering( 'name' );
43 $rowurl = '/view.php?t=debtor&id=%d';
44 $browser->RowFormat( "<tr onclick=\"window.location='$rowurl';\" title=\"Click to Display Debtor Detail\" class=\"r%d\">\n", "</tr>\n", 'tenantcode', '#even' );
45 $browser->DoQuery();
47 $c->page_title = "Browse Debtors";
49 $page_elements[] = $browser;