75ee82a3f66ff498a482c16103f08958a7652b1a
[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
34         $trans_name = $systypes_array[$_GET['type_id']];
35         $journal = $_GET['type_id'] == ST_JOURNAL;
36
37     start_table(TABLESTYLE, "width='95%'");
38     $th = array(_("General Ledger Transaction Details"), _("Reference"),
39         _("Transaction Date"), _("GL #"));
40
41         if ($_GET['type_id'] == ST_JOURNAL)
42                 array_insert($th, 3, array(_("Document Date"), _("Event Date")));
43         else
44                 array_insert($th, 3, array(_("Counterparty")));
45         
46         if($myrow['supp_reference'])
47         {
48                 array_insert($th, 2, array(_("Supplier Reference")));
49         }
50     table_header($th);  
51     start_row();        
52     label_cell("$trans_name #" . $_GET['trans_no']);
53     label_cell($myrow["reference"], "align='center'");
54         if($myrow['supp_reference'])
55         {
56         label_cell($myrow["supp_reference"], "align='center'");
57         }
58         label_cell(sql2date($myrow["doc_date"]), "align='center'");
59         if ($journal)
60         {
61                 $header = get_journal($myrow['type'], $_GET['trans_no']);
62                 label_cell($header["doc_date"] == '0000-00-00' ? '-' : sql2date($header["doc_date"]), "align='center'");
63                 label_cell($header["event_date"] == '0000-00-00' ? '-' : sql2date($header["event_date"]), "align='center'");
64         } else
65                 label_cell(get_counterparty_name($_GET['type_id'],$_GET['trans_no']));
66         label_cell( get_journal_number($myrow['type'], $_GET['trans_no']), "align='center'");
67         end_row();
68
69         start_row();
70         label_cells(_('Entered By'), $myrow["real_name"], "class='tableheader2'", "colspan=" .
71                  ($journal ? ($header['rate']==1 ? '3':'1'):'6'));
72         if ($journal)
73         {
74                 if ($header['rate'] != 1)
75                         label_cells(_('Exchange rate'), $header["rate"].' ', "class='tableheader2'");
76                 label_cells(_('Source document'), $header["source_ref"], "class='tableheader2'");
77         }
78         end_row();
79         comments_display_row($_GET['type_id'], $_GET['trans_no']);
80     end_table(1);
81 }
82 $result = get_gl_trans($_GET['type_id'], $_GET['trans_no']);
83
84 if (db_num_rows($result) == 0)
85 {
86     echo "<p><center>" . _("No general ledger transactions have been created for") . " " .$systypes_array[$_GET['type_id']]." " . _("number") . " " . $_GET['trans_no'] . "</center></p><br><br>";
87         end_page(true);
88         exit;
89 }
90
91 /*show a table of the transactions returned by the sql */
92 $dim = get_company_pref('use_dimension');
93
94 if ($dim == 2)
95         $th = array(_("Journal Date"), _("Account Code"), _("Account Name"), _("Dimension")." 1", _("Dimension")." 2",
96                 _("Debit"), _("Credit"), _("Memo"));
97 elseif ($dim == 1)
98         $th = array(_("Journal Date"), _("Account Code"), _("Account Name"), _("Dimension"),
99                 _("Debit"), _("Credit"), _("Memo"));
100 else            
101         $th = array(_("Journal Date"), _("Account Code"), _("Account Name"),
102                 _("Debit"), _("Credit"), _("Memo"));
103
104 $k = 0; //row colour counter
105 $heading_shown = false;
106
107 $credit = $debit = 0;
108 while ($myrow = db_fetch($result)) 
109 {
110         if ($myrow['amount'] == 0) continue;
111         if (!$heading_shown)
112         {
113                 display_gl_heading($myrow);
114                 start_table(TABLESTYLE, "width='95%'");
115                 table_header($th);
116                 $heading_shown = true;
117         }
118
119         alt_table_row_color($k);
120
121         $counterpartyname = get_subaccount_name($myrow["account"], $myrow["person_id"]);
122         $counterparty_id = $counterpartyname ? sprintf(' %05d', $myrow["person_id"]) : '';
123
124     label_cell(sql2date($myrow['tran_date']));
125     label_cell($myrow['account'].$counterparty_id);
126         label_cell($myrow['account_name'] . ($counterpartyname ? ': '.$counterpartyname : ''));
127         if ($dim >= 1)
128                 label_cell(get_dimension_string($myrow['dimension_id'], true));
129         if ($dim > 1)
130                 label_cell(get_dimension_string($myrow['dimension2_id'], true));
131
132         display_debit_or_credit_cells($myrow['amount']);
133         label_cell($myrow['memo_']);
134         end_row();
135     if ($myrow['amount'] > 0 ) 
136         $debit += $myrow['amount'];
137     else 
138         $credit += $myrow['amount'];
139 }
140
141 if ($heading_shown)
142 {
143     start_row("class='inquirybg' style='font-weight:bold'");
144     label_cell(_("Total"), "colspan=3");
145     if ($dim >= 1)
146         label_cell('');
147     if ($dim > 1)
148         label_cell('');
149     amount_cell($debit);
150     amount_cell(-$credit);
151     label_cell('');
152     end_row();
153         end_table(1);
154 }
155
156 //end of while loop
157
158 is_voided_display($_GET['type_id'], $_GET['trans_no'], _("This transaction has been voided."));
159
160 end_page(true, false, false, $_GET['type_id'], $_GET['trans_no']);