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