2 include_once("classWidgets.php");
4 param_to_global( 'creditorcode', 'int' );
5 param_to_global( 'id', '#^[ACTLPJ]-\d+-\d+(\.\d+)?$#i' );
6 if ( isset($creditorcode) ) {
10 else if ( isset($id) ) {
11 list( $et, $ec, $ac ) = explode('-',$id,3);
12 $et = strtoupper(substr($et,0,1));
17 param_to_global('month', '#[0-9:/-]+#');
20 * Add some widgets onto the top of the browser
22 $widget = new Widget();
23 $widget->AddField( 'year', 'int1', "SELECT 0, '--- All Years ---' UNION SELECT financialyearcode, description FROM financialyear ORDER BY 1;" );
25 $widget->Defaults( array('year' => $year ) );
26 $widget->Layout( '<table> <tr> <th>For year:</th> <td>##year.select##</td> <td>##Show.submit##</td> </tr></table>' );
27 $page_elements[] = $widget;
30 $browser = new Browser("Browse Cheques");
32 if ( isset($et) && isset($ec) ) {
33 $qry = new PgQuery( "SELECT get_entity_type_name(?) AS entitytypename, get_entity_name(?,?) AS entityname;", $et, $et, $ec);
34 if ( $qry->Exec("browse-$component") && $row = $qry->Fetch() ) {
35 $browser->Title("$row->entitytypename Cheques for $row->entityname ($et$ec)");
38 include_once("menus_entityaccount.php");
40 // chequeno | bankaccountcode | creditorcode | amount | batchcode | documentcode | payeename | date | cancelled | datepresented | presentedamount | datesent
42 $browser->AddColumn( 'bankaccountcode', 'Bank', 'center' );
43 $browser->AddColumn( 'chequeno', 'Cheque#', 'center' );
44 $browser->AddColumn( 'date', 'Date', 'center' );
45 $browser->AddColumn( 'payeename', 'Payee', 'left', null, 'chq.payeename' );
46 $browser->AddColumn( 'amount', 'Amount', 'right', '%0.2lf' );
47 $browser->AddTotal( 'amount' );
48 $browser->SetJoins( "cheque chq JOIN creditor cr USING(creditorcode)" );
49 if ( $widget->Record
->{'year'} > 0 ) {
50 $browser->SetJoins("cheque chq JOIN creditor cr USING(creditorcode) JOIN month ON chq.date BETWEEN month.startdate AND month.enddate JOIN financialyear USING (financialyearcode)");
51 $browser->AndWhere( "financialyearcode =".qpg($widget->Record
->{'year'}) );
53 if ( isset($month) ) $browser->AndWhere( sprintf("(month.startdate <= %s AND month.enddate >= %s) ", qpg($month), qpg($month)) );
54 $browser->SetOrdering( 'chequeno', 'DESC', 1 );
55 $rowurl = '/view.php?t=cheque&id=%s';
56 $browser->RowFormat( "<tr onclick=\"window.location='$rowurl';\" title=\"Click to Display Cheque Detail\" class=\"r%d\">\n", "</tr>\n", 'chequeno', '#even' );
58 $c->page_title
= $browser->Title();
59 $page_elements[] = $browser;