295e551a36a66fcbd0ad61a7ea3b74e7d16e5c5f
[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         echo "<p>" . _("The script must be called with a valid transaction type and transaction number to review the general ledger postings for.") . "</p>";
27         exit;
28 }
29
30 function display_gl_heading($myrow)
31 {
32         global $table_style, $systypes_array;
33         $trans_name = $systypes_array[$_GET['type_id']];
34     start_table("$table_style width=95%");
35     $th = array(_("General Ledger Transaction Details"), _("Reference"),
36         _("Date"), _("Person/Item"));
37     table_header($th);  
38     start_row();        
39     label_cell("$trans_name #" . $_GET['trans_no']);
40     label_cell($myrow["reference"]);
41         label_cell(sql2date($myrow["tran_date"]));
42         label_cell(payment_person_name($myrow["person_type_id"],$myrow["person_id"]));
43         
44         end_row();
45
46         comments_display_row($_GET['type_id'], $_GET['trans_no']);
47
48     end_table(1);
49 }
50
51 $sql = "SELECT gl.*, cm.account_name, refs.reference FROM "
52         .TB_PREF."gl_trans as gl, ".TB_PREF."chart_master as cm, ".TB_PREF."refs as refs"
53         ." WHERE gl.account = cm.account_code"
54         ." AND gl.type= ".db_escape($_GET['type_id']) 
55         ." AND gl.type_no = ".db_escape($_GET['trans_no'])
56         ." AND gl.type=refs.type AND gl.type_no=refs.id"
57         ." ORDER BY counter";
58 $result = db_query($sql,"could not get transactions");
59 //alert("sql = ".$sql);
60
61 if (db_num_rows($result) == 0)
62 {
63     echo "<p><center>" . _("No general ledger transactions have been created for") . " " .$systypes_array[$_GET['type_id']]." " . _("number") . " " . $_GET['trans_no'] . "</center></p><br><br>";
64         end_page(true);
65         exit;
66 }
67
68 /*show a table of the transactions returned by the sql */
69 $dim = get_company_pref('use_dimension');
70
71 if ($dim == 2)
72         $th = array(_("Account Code"), _("Account Name"), _("Dimension")." 1", _("Dimension")." 2",
73                 _("Debit"), _("Credit"), _("Memo"));
74 else if ($dim == 1)
75         $th = array(_("Account Code"), _("Account Name"), _("Dimension"),
76                 _("Debit"), _("Credit"), _("Memo"));
77 else            
78         $th = array(_("Account Code"), _("Account Name"),
79                 _("Debit"), _("Credit"), _("Memo"));
80 $k = 0; //row colour counter
81 $heading_shown = false;
82
83 while ($myrow = db_fetch($result)) 
84 {
85         if ($myrow['amount'] == 0) continue;
86         if (!$heading_shown)
87         {
88                 display_gl_heading($myrow);
89                 start_table("$table_style width=95%");
90                 table_header($th);
91                 $heading_shown = true;
92         }       
93
94         alt_table_row_color($k);
95         
96     label_cell($myrow['account']);
97         label_cell($myrow['account_name']);
98         if ($dim >= 1)
99                 label_cell(get_dimension_string($myrow['dimension_id'], true));
100         if ($dim > 1)
101                 label_cell(get_dimension_string($myrow['dimension2_id'], true));
102
103         display_debit_or_credit_cells($myrow['amount']);
104         label_cell($myrow['memo_']);
105         end_row();
106
107 }
108 //end of while loop
109 if ($heading_shown)
110         end_table(1);
111
112 is_voided_display($_GET['type_id'], $_GET['trans_no'], _("This transaction has been voided."));
113
114 end_page(true);
115
116 ?>