Much refactoring to use $page_element generically, and to use newer
[capital-apms.git] / inc / view / debtor.php
blobe09ddcf40584870bb447b15d0904f4e8c19202d4
1 <?php
3 // Viewer component for tenant records
4 $viewer = new Viewer("Debtor", 'debtor_maintenance');
5 $viewer->AddField( 'entityname', 'get_entity_name(debtor_et,debtor_ec)' );
6 $viewer->AddField( 'balance', "(SELECT TO_CHAR( COALESCE(balance,0.0),'999G999G990D00PR') FROM accountsummary WHERE entitytype='T' AND entitycode=debtorcode)" );
7 $viewer->AddField( 'billto', "billperson_first || ' ' || billperson_last" );
8 $viewer->AddField( 'debtclassification_name', "COALESCE( debtclassification.description, 'Unknown')" );
9 $viewer->AddField( 'varianceclassification_name', "COALESCE( varianceclassification.description, 'Unknown')" );
10 $viewer->SetJoins( 'debtor_maintenance LEFT JOIN debtclassification USING ( debtclassification ) LEFT JOIN varianceclassification USING ( varianceclassification ) ' );
11 $viewer->SetWhere( 'debtorcode=' . intval($id) );
13 $template = <<<EOTEMPLATE
14 <table>
15 <tr>
16 <th class="right">Debtor:</th>
17 <td class="center">##debtorcode.value##</td>
18 <td class="left">##debtor_name.value##</td>
19 </tr>
20 <tr>
21 <th colspan="1" rowspan="3">Billing Details</th>
22 <th class="right">Address:</th>
23 <td class="left">##bill_address.textarea.40x2##</td>
24 </tr>
25 <tr>
26 <th class="right">City:</th>
27 <td class="left">##bill_city.input.16##, ##bill_state.input.16##</td>
28 </tr>
29 <tr>
30 <th class="right">Country:</th>
31 <td class="left">##bill_country.input.20## ##bill_zip.input.11##</td>
32 </tr>
33 <tr>
34 <th colspan="1" rowspan="3">Contact</th>
35 <th class="right">Person:</th>
36 <td class="left">##billperson_title.options## ##billperson_first.input.15## ##billperson_last.input.20##</td>
37 </tr>
38 <tr>
39 <th class="right">Job Title:</th>
40 <td class="left">##billperson_job.input.41##</td>
41 </tr>
42 <tr>
43 <th class="right">Phone</th>
44 <td class="left">+##busphone_isd.input.5## ( ##busphone_std.input.6## ) ##busphone_no.input.33##</td>
45 </tr>
46 <tr>
47 <th class="right" colspan="2">Active:</th>
48 <td class="left">##debtor_active.yesno##</td>
49 </tr>
50 <tr>
51 <th class="right" colspan="2">Debt class:</th>
52 <td class="left">##debtclassification_name.options##</td>
53 </tr>
54 <tr>
55 <th class="right" colspan="2">Variance class:</th>
56 <td class="left">##varianceclassification_name.options##</td>
57 </tr>
58 <tr>
59 <th class="right" colspan="2">Account Ledger:</th>
60 <td class="left">##debtor_et.options## ##debtor_ec.input.5## - ##debtor_entity_name.enc##</td>
61 </tr>
62 <tr>
63 <th class="right">Balance:</th>
64 <td class="left" colspan="2">##balance.value##</td>
65 </tr>
66 </table>
68 EOTEMPLATE;
70 $viewer->SetTemplate( $template );
71 $viewer->GetRecord();
72 $viewer->SetTitle("Debtor: ".$viewer->Record->{'debtor_name'});
73 $page_elements[] = $viewer;
74 $c->page_title = $viewer->Title;
76 include_once("menus_entityaccount.php");
78 // And let's show a transaction browser below the tenant details...
79 require_once('classBrowser.php');
80 $browser = new Browser("Outstanding Transactions");
81 $browser->AddHidden( 'document', "batchcode || '.' || documentcode" );
82 $browser->AddColumn( 'date', 'Date', 'center' );
83 $browser->AddColumn( 'reference', 'Reference', 'left', '', "COALESCE(accttran.reference, document.reference)" );
84 $browser->AddColumn( 'description', 'Description', 'left', '', "COALESCE(accttran.description, document.description)" );
85 $browser->AddColumn( 'amount', 'Amount', 'right', '%0.2lf' );
86 $browser->AddTotal( 'amount' );
87 $browser->SetJoins( "accttran JOIN document USING (batchcode, documentcode)" );
88 $browser->SetWhere( "entitytype='T' AND entitycode=".intval($id)." AND closedstate != 'F'" );
89 $browser->AddOrder( 'date', 'ASC' );
90 $rowurl = '/view.php?t=document&id=%s';
91 $browser->RowFormat( "<tr onclick=\"window.location='$rowurl';\" class=\"r%d\">\n", "</tr>\n", 'document', '#even' );
92 $browser->DoQuery();
93 $page_elements[] = $browser;
95 // Now for an Invoice browser
96 $browser = new Browser("Invoices in Last 12 Months");
97 $browser->AddColumn( 'invoiceno', 'Invoice#', 'center' );
98 $browser->AddColumn( 'invoicedate', 'Date', 'center' );
99 $browser->AddColumn( 'todetail', 'Brief', 'left', '<span style="white-space:nowrap;">%s</span>' );
100 $browser->AddColumn( 'blurb', 'Invoice Details' );
101 $browser->AddColumn( 'total', 'Amount', 'right', '%0.2lf' );
102 $browser->AddTotal( 'total' );
103 $browser->SetJoins( "invoice" );
104 // $browser->SetJoins( "invoice JOIN invoiceline USING (invoiceno)" );
105 $browser->SetWhere( "invoice.entitytype='T' AND invoice.entitycode=".intval($id)." " );
106 $browser->AndWhere( "invoicedate >= (current_timestamp - '1 year'::interval)" );
107 $browser->AddOrder( 'invoiceno', 'ASC', 1 );
108 $rowurl = '/view.php?t=invoice&id=%s';
109 $browser->RowFormat( "<tr onclick=\"window.location='$rowurl';\" class=\"r%d\">\n", "</tr>\n", 'invoiceno', '#even' );
110 $browser->DoQuery();
111 $page_elements[] = $browser;