739ffa9888753d177156031696fb1e19166b0967
[fa-stable.git] / gl / view / gl_payment_view.php
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU Affero General Public License,
5         AGPL, as published by the Free Software Foundation, either version 
6         3 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/agpl-3.0.html>.
11 ***********************************************************************/
12 $page_security = 1;
13 $path_to_root="../..";
14
15 include($path_to_root . "/includes/session.inc");
16
17 page(_("View Bank Payment"), true);
18
19 include_once($path_to_root . "/includes/date_functions.inc");
20 include_once($path_to_root . "/includes/ui.inc");
21
22 include_once($path_to_root . "/gl/includes/gl_db.inc");
23
24 if (isset($_GET["trans_no"]))
25 {
26         $trans_no = $_GET["trans_no"];
27 }
28
29 // get the pay-from bank payment info
30 $result = get_bank_trans(systypes::bank_payment(), $trans_no);
31
32 if (db_num_rows($result) != 1)
33         display_db_error("duplicate payment bank transaction found", "");
34
35 $from_trans = db_fetch($result);
36
37 $company_currency = get_company_currency();
38
39 $show_currencies = false;
40
41 if ($from_trans['bank_curr_code'] != $company_currency)
42 {
43         $show_currencies = true;
44 }
45
46 display_heading(_("GL Payment") . " #$trans_no");
47
48 echo "<br>";
49 start_table("$table_style width=80%");
50
51 if ($show_currencies)
52 {
53         $colspan1 = 5;
54         $colspan2 = 8;
55 }
56 else
57 {
58         $colspan1 = 3;
59         $colspan2 = 6;
60 }
61 start_row();
62 label_cells(_("From Bank Account"), $from_trans['bank_account_name'], "class='tableheader2'");
63 if ($show_currencies)
64         label_cells(_("Currency"), $from_trans['bank_curr_code'], "class='tableheader2'");
65 label_cells(_("Amount"), number_format2(-$from_trans['amount'], user_price_dec()), "class='tableheader2'", "align=right");
66 label_cells(_("Date"), sql2date($from_trans['trans_date']), "class='tableheader2'");
67 end_row();
68 start_row();
69 label_cells(_("Pay To"), payment_person_types::person_name($from_trans['person_type_id'], $from_trans['person_id']), "class='tableheader2'", "colspan=$colspan1");
70 label_cells(_("Payment Type"),bank_account_types::transfer_type($from_trans['account_type']), "class='tableheader2'");
71 end_row();
72 start_row();
73 label_cells(_("Reference"), $from_trans['ref'], "class='tableheader2'", "colspan=$colspan2");
74 end_row();
75 comments_display_row(systypes::bank_payment(), $trans_no);
76
77 end_table(1);
78
79 $voided = is_voided_display(systypes::bank_payment(), $trans_no, _("This payment has been voided."));
80
81 $items = get_gl_trans(systypes::bank_payment(), $trans_no);
82
83 if (db_num_rows($items)==0)
84 {
85         display_note(_("There are no items for this payment."));
86 }
87 else
88 {
89
90         display_heading2(_("Items for this Payment"));
91         if ($show_currencies)
92                 display_heading2(_("Item Amounts are Shown in :") . " " . $company_currency);
93
94     echo "<br>";
95     start_table("$table_style width=80%");
96     $th = array(_("Account Code"), _("Account Description"),
97         _("Amount"), _("Memo"));
98         table_header($th);
99
100     $k = 0; //row colour counter
101         $totalAmount = 0;
102
103     while ($item = db_fetch($items))
104     {
105
106                 if ($item["account"] != $from_trans["account_code"])
107                 {
108                 alt_table_row_color($k);
109
110                 label_cell($item["account"]);
111                 label_cell($item["account_name"]);
112                 amount_cell($item["amount"]);
113                 label_cell($item["memo_"]);
114                 end_row();
115                 $totalAmount += $item["amount"];
116                 }
117         }
118
119         label_row(_("Total"), number_format2($totalAmount, user_price_dec()),"colspan=2 align=right", "align=right");
120
121         end_table(1);
122
123         if (!$voided)
124                 display_allocations_from($from_trans['person_type_id'], $from_trans['person_id'], 1, $trans_no, -$from_trans['amount']);
125 }
126
127 end_page(true);
128 ?>