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");
16 page(_($help_context = "General Ledger Transaction Details"), true);
18 include_once($path_to_root . "/includes/date_functions.inc");
19 include_once($path_to_root . "/includes/ui.inc");
21 include_once($path_to_root . "/gl/includes/gl_db.inc");
23 if (!isset($_GET['type_id']) || !isset($_GET['trans_no']))
24 { /*Script was not passed the correct parameters */
26 display_note(_("The script must be called with a valid transaction type and transaction number to review the general ledger postings for."));
30 function display_gl_heading($myrow)
32 global $systypes_array, $SysPrefs;
34 if (!empty($SysPrefs->prefs['company_logo_on_views']))
35 company_logo_on_view();
37 $trans_name = $systypes_array[$_GET['type_id']];
38 $journal = $_GET['type_id'] == ST_JOURNAL;
40 start_table(TABLESTYLE, "width='95%'");
41 $th = array(_("General Ledger Transaction Details"), _("Reference"),
42 _("Transaction Date"), _("GL #"));
44 if ($_GET['type_id'] == ST_JOURNAL)
45 array_insert($th, 3, array(_("Document Date"), _("Event Date")));
47 array_insert($th, 3, array(_("Counterparty")));
49 if($myrow['supp_reference'])
51 array_insert($th, 2, array(_("Supplier Reference")));
55 label_cell("$trans_name #" . $_GET['trans_no']);
56 label_cell($myrow["reference"], "align='center'");
57 if($myrow['supp_reference'])
59 label_cell($myrow["supp_reference"], "align='center'");
61 label_cell(sql2date($myrow["doc_date"]), "align='center'");
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'");
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'");
73 label_cells(_('Entered By'), $myrow["real_name"], "class='tableheader2'", "colspan=" .
74 ($journal ? ($header['rate']==1 ? '3':'1'):'6'));
77 if ($header['rate'] != 1)
78 label_cells(_('Exchange rate'), $header["rate"].' ', "class='tableheader2'");
79 label_cells(_('Source document'), $header["source_ref"], "class='tableheader2'");
82 comments_display_row($_GET['type_id'], $_GET['trans_no']);
85 $result = get_gl_trans($_GET['type_id'], $_GET['trans_no']);
87 if (db_num_rows($result) == 0)
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>";
94 /*show a table of the transactions returned by the sql */
95 $dim = get_company_pref('use_dimension');
98 $th = array(_("Journal Date"), _("Account Code"), _("Account Name"), _("Dimension")." 1", _("Dimension")." 2",
99 _("Debit"), _("Credit"), _("Memo"));
101 $th = array(_("Journal Date"), _("Account Code"), _("Account Name"), _("Dimension"),
102 _("Debit"), _("Credit"), _("Memo"));
104 $th = array(_("Journal Date"), _("Account Code"), _("Account Name"),
105 _("Debit"), _("Credit"), _("Memo"));
107 $k = 0; //row colour counter
108 $heading_shown = false;
110 $credit = $debit = 0;
111 while ($myrow = db_fetch($result))
113 if ($myrow['amount'] == 0) continue;
116 display_gl_heading($myrow);
117 start_table(TABLESTYLE, "width='95%'");
119 $heading_shown = true;
122 alt_table_row_color($k);
124 $counterpartyname = get_subaccount_name($myrow["account"], $myrow["person_id"]);
125 $counterparty_id = $counterpartyname ? sprintf(' %05d', $myrow["person_id"]) : '';
127 label_cell(sql2date($myrow['tran_date']));
128 label_cell($myrow['account'].$counterparty_id);
129 label_cell($myrow['account_name'] . ($counterpartyname ? ': '.$counterpartyname : ''));
131 label_cell(get_dimension_string($myrow['dimension_id'], true));
133 label_cell(get_dimension_string($myrow['dimension2_id'], true));
135 display_debit_or_credit_cells($myrow['amount']);
136 label_cell($myrow['memo_']);
138 if ($myrow['amount'] > 0 )
139 $debit += $myrow['amount'];
141 $credit += $myrow['amount'];
146 start_row("class='inquirybg' style='font-weight:bold'");
147 label_cell(_("Total"), "colspan=3");
153 amount_cell(-$credit);
161 is_voided_display($_GET['type_id'], $_GET['trans_no'], _("This transaction has been voided."));
163 end_page(true, false, false, $_GET['type_id'], $_GET['trans_no']);