4e61fef91349cf9967a12ef5815ccb6a07bacdfa
[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"), _("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 $result = get_gl_trans($_GET['type_id'], $_GET['trans_no']);
51
52 if (db_num_rows($result) == 0)
53 {
54     echo "<p><center>" . _("No general ledger transactions have been created for") . " " .$systypes_array[$_GET['type_id']]." " . _("number") . " " . $_GET['trans_no'] . "</center></p><br><br>";
55         end_page(true);
56         exit;
57 }
58
59 /*show a table of the transactions returned by the sql */
60 $dim = get_company_pref('use_dimension');
61
62 if ($dim == 2)
63         $th = array(_("Account Code"), _("Account Name"), _("Dimension")." 1", _("Dimension")." 2",
64                 _("Debit"), _("Credit"), _("Memo"));
65 else if ($dim == 1)
66         $th = array(_("Account Code"), _("Account Name"), _("Dimension"),
67                 _("Debit"), _("Credit"), _("Memo"));
68 else            
69         $th = array(_("Account Code"), _("Account Name"),
70                 _("Debit"), _("Credit"), _("Memo"));
71 $k = 0; //row colour counter
72 $heading_shown = false;
73
74 $credit = $debit = 0;
75 while ($myrow = db_fetch($result)) 
76 {
77         if ($myrow['amount'] == 0) continue;
78         if (!$heading_shown)
79         {
80                 display_gl_heading($myrow);
81                 start_table(TABLESTYLE, "width=95%");
82                 table_header($th);
83                 $heading_shown = true;
84         }       
85
86         alt_table_row_color($k);
87         
88     label_cell($myrow['account']);
89         label_cell($myrow['account_name']);
90         if ($dim >= 1)
91                 label_cell(get_dimension_string($myrow['dimension_id'], true));
92         if ($dim > 1)
93                 label_cell(get_dimension_string($myrow['dimension2_id'], true));
94
95         display_debit_or_credit_cells($myrow['amount']);
96         label_cell($myrow['memo_']);
97         end_row();
98     if ($myrow['amount'] > 0 ) 
99         $debit += $myrow['amount'];
100     else 
101         $credit += $myrow['amount'];
102 }
103 if ($heading_shown)
104 {
105     start_row("class='inquirybg' style='font-weight:bold'");
106     label_cell(_("Total"), "colspan=2");
107     if ($dim >= 1)
108         label_cell('');
109     if ($dim > 1)
110         label_cell('');
111     amount_cell($debit);
112     amount_cell(-$credit);
113     label_cell('');
114     end_row();
115         end_table(1);
116 }
117
118 //end of while loop
119
120 is_voided_display($_GET['type_id'], $_GET['trans_no'], _("This transaction has been voided."));
121
122 end_page(true, false, false, $_GET['type_id'], $_GET['trans_no']);
123
124 ?>