2 include_once("classWidgets.php");
4 param_to_global( 'id', '#^[ACTLPJ]-\d+-\d+(\.\d+)?$#i' );
6 list( $et, $ec, $ac ) = explode('-',$id,3);
7 $et = strtoupper(substr($et,0,1));
11 param_to_global('month', '#[0-9:/-]+#');
14 * Add some widgets onto the top of the browser
16 $widget = new Widget();
17 $widget->AddField( 'year', 'int1', "SELECT 0, '--- All Years ---' UNION SELECT financialyearcode, description FROM financialyear ORDER BY 1;" );
18 $widget->AddField( 'status', 'char1', "SELECT '.', '--- Any Status ---' UNION SELECT invoicestatus, description FROM invoicestatus ORDER BY 1;" );
20 $widget->Defaults( array('year' => $year ) );
21 $widget->Layout( '<table> <tr>
22 <th>Status:</th> <td>##status.select##</td>
23 <th>For year:</th> <td>##year.select##</td>
24 <td>##Show.submit##</td> </tr></table>' );
25 $page_elements[] = $widget;
28 $browser = new Browser("Browse Invoices");
30 if ( isset($et) && isset($ec) ) {
31 $qry = new PgQuery( "SELECT get_entity_type_name(?) AS entitytypename, get_entity_name(?,?) AS entityname;", $et, $et, $ec);
32 if ( $qry->Exec("browse-$component") && $row = $qry->Fetch() ) {
33 $browser->Title("$row->entitytypename Invoices for $row->entityname ($et$ec)");
36 $related_menu->AddOption("New Invoice","/edit.php?t=invoice","Create a new invoice", false, 3100);
37 include_once("menus_entityaccount.php");
39 $browser->AddColumn( 'invoiceno', 'Invoice#', 'center' );
40 $browser->AddColumn( 'invoicestatus', '?', 'center' );
41 $browser->AddColumn( 'invoicedate', 'Date', 'center' );
42 $browser->AddColumn( 'todetail', 'Brief', 'left', '<span style="white-space:nowrap;">%s</span>' );
43 $browser->AddColumn( 'blurb', 'Invoice Details' );
44 $browser->AddColumn( 'total', 'Amount', 'right', '%0.2lf' );
45 $browser->AddTotal( 'total' );
46 $browser->SetJoins( "invoice" );
47 // $browser->SetJoins( "invoice JOIN invoiceline USING (invoiceno)" );
48 if ( isset($et) && isset($ec) )
49 $browser->AndWhere( "invoice.entitytype='$et' AND invoice.entitycode=$ec" );
50 if ( $widget->Record
->{'year'} > 0 ) {
51 $browser->SetJoins("invoice JOIN month ON month.startdate <= invoice.invoicedate AND month.enddate >= invoice.invoicedate JOIN financialyear USING (financialyearcode)");
52 $browser->AndWhere( "financialyearcode =".qpg($widget->Record
->{'year'}) );
54 if ( isset($widget->Record
->{'status'}) ) {
55 $browser->AndWhere( "invoicestatus ~* ".qpg($widget->Record
->{'status'}) );
57 $browser->AddOrder( 'invoiceno', 'DESC', 1 );
58 $rowurl = '/view.php?t=invoice&id=%s';
59 $browser->RowFormat( "<tr onclick=\"window.location='$rowurl';\" title=\"Click to Display Invoice Detail\" class=\"r-inv-%s\">\n", "</tr>\n", 'invoiceno', 'invoicestatus' );
61 $c->page_title
= $browser->Title();
62 $page_elements[] = $browser;