Additional access control related ui helpers added: check_edit_access, access_post...
[fa-stable.git] / gl / view / gl_trans_view.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU General Public License, GPL, 
5         as published by the Free Software Foundation, either version 3 
6         of the License, or (at your option) any later version.
7     This program is distributed in the hope that it will be useful,
8     but WITHOUT ANY WARRANTY; without even the implied warranty of
9     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  
10     See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 'SA_GLTRANSVIEW';
13 $path_to_root = "../..";
14 include_once($path_to_root . "/includes/session.inc");
15
16 page(_($help_context = "General Ledger Transaction Details"), true);
17
18 include_once($path_to_root . "/includes/date_functions.inc");
19 include_once($path_to_root . "/includes/ui.inc");
20
21 include_once($path_to_root . "/gl/includes/gl_db.inc");
22
23 if (!isset($_GET['type_id']) || !isset($_GET['trans_no'])) 
24 { /*Script was not passed the correct parameters */
25
26         display_note(_("The script must be called with a valid transaction type and transaction number to review the general ledger postings for."));
27         end_page();
28 }
29
30 function display_gl_heading($myrow)
31 {
32         global $systypes_array;
33         $trans_name = $systypes_array[$_GET['type_id']];
34     start_table(TABLESTYLE, "width=95%");
35     $th = array(_("General Ledger Transaction Details"), _("Reference"),
36         _("Date"));
37
38         if ($_GET['type_id'] != ST_JOURNAL)
39                 $th[] = _("Counterparty");
40
41     table_header($th);
42     start_row();
43     label_cell("$trans_name #" . $_GET['trans_no']);
44     label_cell($myrow["reference"]);
45         label_cell(sql2date($myrow["tran_date"]));
46         if ($_GET['type_id'] != ST_JOURNAL)
47                 label_cell(get_counterparty_name($_GET['type_id'],$_GET['trans_no']));
48
49         end_row();
50
51         comments_display_row($_GET['type_id'], $_GET['trans_no']);
52
53     end_table(1);
54 }
55 $result = get_gl_trans($_GET['type_id'], $_GET['trans_no']);
56
57 if (db_num_rows($result) == 0)
58 {
59     echo "<p><center>" . _("No general ledger transactions have been created for") . " " .$systypes_array[$_GET['type_id']]." " . _("number") . " " . $_GET['trans_no'] . "</center></p><br><br>";
60         end_page(true);
61         exit;
62 }
63
64 /*show a table of the transactions returned by the sql */
65 $dim = get_company_pref('use_dimension');
66
67 if ($dim == 2)
68         $th = array(_("Account Code"), _("Account Name"), _("Dimension")." 1", _("Dimension")." 2",
69                 _("Debit"), _("Credit"), _("Memo"));
70 else if ($dim == 1)
71         $th = array(_("Account Code"), _("Account Name"), _("Dimension"),
72                 _("Debit"), _("Credit"), _("Memo"));
73 else            
74         $th = array(_("Account Code"), _("Account Name"),
75                 _("Debit"), _("Credit"), _("Memo"));
76
77 $k = 0; //row colour counter
78 $heading_shown = false;
79
80 $credit = $debit = 0;
81 while ($myrow = db_fetch($result)) 
82 {
83         if ($myrow['amount'] == 0) continue;
84         if (!$heading_shown)
85         {
86                 display_gl_heading($myrow);
87                 start_table(TABLESTYLE, "width=95%");
88                 table_header($th);
89                 $heading_shown = true;
90         }
91
92         alt_table_row_color($k);
93
94         $counterpartyname = get_subaccount_name($myrow["account"], $myrow["person_id"]);
95         $counterparty_id = $counterpartyname ? sprintf(' %05d', $myrow["person_id"]) : '';
96
97     label_cell($myrow['account'].$counterparty_id);
98         label_cell($myrow['account_name'] . ($counterpartyname ? ': '.$counterpartyname : ''));
99         if ($dim >= 1)
100                 label_cell(get_dimension_string($myrow['dimension_id'], true));
101         if ($dim > 1)
102                 label_cell(get_dimension_string($myrow['dimension2_id'], true));
103
104         display_debit_or_credit_cells($myrow['amount']);
105         label_cell($myrow['memo_']);
106         end_row();
107     if ($myrow['amount'] > 0 ) 
108         $debit += $myrow['amount'];
109     else 
110         $credit += $myrow['amount'];
111 }
112 if ($heading_shown)
113 {
114     start_row("class='inquirybg' style='font-weight:bold'");
115     label_cell(_("Total"), "colspan=2");
116     if ($dim >= 1)
117         label_cell('');
118     if ($dim > 1)
119         label_cell('');
120     amount_cell($debit);
121     amount_cell(-$credit);
122     label_cell('');
123     end_row();
124         end_table(1);
125 }
126
127 //end of while loop
128
129 is_voided_display($_GET['type_id'], $_GET['trans_no'], _("This transaction has been voided."));
130
131 end_page(true, false, false, $_GET['type_id'], $_GET['trans_no']);
132