*** empty log message ***
[fa-stable.git] / gl / includes / ui / gl_journal_ui.inc
1 <?php
2
3 include_once($path_to_root . "/includes/ui.inc");
4 include_once($path_to_root . "/includes/ui/items_cart.inc");
5
6 //--------------------------------------------------------------------------------
7
8 function display_order_header(&$Order)
9 {
10         global $table_style2;
11
12         start_table("$table_style2 width=90%");
13         echo "<tr><td valign=top width=50%>"; // outer table
14
15         echo "<table>";
16         start_row();
17     date_cells(_("Date:"), 'date_');
18         ref_cells(_("Reference:"), 'ref', references::get_next(0));
19         end_row();
20
21         echo "</table>";
22
23         echo "</td><td width=50%>"; // outer table
24
25         echo "<table>";
26
27         check_row(_("Reverse Transaction:"), 'Reverse', null);
28
29         echo "</table>";
30
31         echo "</td></tr>"; // outer table
32         end_table(1);
33 }
34
35 //---------------------------------------------------------------------------------
36
37 function display_gl_items($title, &$order)
38 {
39         global $table_style, $path_to_root;
40
41         display_heading($title);
42
43         $dim = get_company_pref('use_dimension');
44
45         start_table("$table_style colspan=7 width=95%");
46         if ($dim == 2)
47                 $th = array(_("Account Code"), _("Account Description"), _("Dimension")." 1",
48                         _("Dimension")." 2", _("Debit"), _("Credit"), _("Memo"));
49         else if ($dim == 1)
50                 $th = array(_("Account Code"), _("Account Description"), _("Dimension"),
51                         _("Debit"), _("Credit"), _("Memo"));
52         else
53                 $th = array(_("Account Code"), _("Account Description"),
54                         _("Debit"), _("Credit"), _("Memo"));
55         table_header($th);      
56
57         $k = 0;
58
59         foreach ($order->gl_items as $item) 
60         {
61                 if (!isset($_GET['Edit']) || $_GET['Edit'] != $item->index)
62                 {
63                 alt_table_row_color($k);
64
65                         label_cells($item->code_id, $item->description);
66                 if ($dim >= 1)
67                                 label_cell(get_dimension_string($item->dimension_id, true));
68                 if ($dim > 1)
69                                 label_cell(get_dimension_string($item->dimension2_id, true));
70                 if ($item->amount > 0)
71                 {
72                         amount_cell(abs($item->amount));
73                         label_cell("");
74                 }       
75                 else
76                 {
77                         label_cell("");
78                         amount_cell(abs($item->amount));
79                 }       
80                         label_cell($item->reference);
81                         edit_link_cell("Edit=$item->index");
82                         delete_link_cell("Delete=$item->index");
83                 end_row();;
84                 } 
85                 else 
86                 {
87                         gl_edit_item_controls($order, $dim, $item->index);
88                 }
89         }
90
91         if (!isset($_GET['Edit']))
92                 gl_edit_item_controls($order, $dim);
93
94         if ($order->count_gl_items()) 
95         {
96                 $colspan = ($dim == 2 ? "4" : ($dim == 1 ? "3" : "2"));
97                 start_row();
98                 label_cell(_("Total"), "align=right colspan=" . $colspan);
99                 amount_cell($order->gl_items_total_debit());
100                 amount_cell(abs($order->gl_items_total_credit()));
101                 end_row();
102         }
103
104     end_table();
105 }
106
107 //---------------------------------------------------------------------------------
108
109 function gl_edit_item_controls(&$order, $dim, $Index=null)
110 {
111         start_row();
112
113         if (isset($_GET['Edit']) && $Index != null)
114         {
115                 $item = $order->gl_items[$Index];
116                 if (!isset($_POST['code_id']))
117                         $_POST['code_id'] = $item->code_id;
118                 if (!isset($_POST['dimension_id']))
119                         $_POST['dimension_id'] = $item->dimension_id;
120                 if (!isset($_POST['dimension2_id']))
121                         $_POST['dimension2_id'] = $item->dimension2_id;
122
123                 if ((!isset($_POST['AmountDebit']) || ($_POST['AmountDebit']=="")) && $item->amount > 0)
124                         $_POST['AmountDebit'] = $item->amount;
125
126                 if ((!isset($_POST['AmountCredit']) || ($_POST['AmountCredit']=="")) && $item->amount <= 0)
127                         $_POST['AmountCredit'] = abs($item->amount);
128
129                 if (!isset($_POST['description']) || ($_POST['description'] == ""))
130                         $_POST['description'] = $item->description;
131                 if (!isset($_POST['LineMemo']) || ($_POST['LineMemo'] == ""))
132                         $_POST['LineMemo'] = $item->reference;
133
134                 hidden('Index', $item->index);
135                 hidden('code_id', $item->code_id);
136                 label_cell($_POST['code_id']);
137                 label_cell($item->description);
138                 if ($dim >= 1) 
139                         dimensions_list_cells(null, 'dimension_id', $_POST['dimension_id'], true, " ", false, 1);
140                 if ($dim > 1) 
141                         dimensions_list_cells(null, 'dimension2_id', $_POST['dimension2_id'], true, " ", false, 2);
142         }
143         else
144         {
145                 $_POST['AmountDebit'] = 0;
146                 $_POST['AmountCredit'] = 0;
147                 $_POST['dimension_id'] = 0;
148                 $_POST['dimension2_id'] = 0;
149                 $_POST['LineMemo'] = "";
150                 $_POST['CodeID2'] = "";
151                 $_POST['code_id'] = "";
152                 
153                 text_cells(null, "CodeID2", "", 12, 10, "", "", "onkeyup='recalcAccounts();' onKeyDown='if(event.keyCode==13) event.keyCode=9;' onblur='return setAccount(0, false)'");
154                 $skip_bank = ($_SESSION["wa_current_user"]->access != 2);
155                 gl_all_accounts_list_cells(null, 'code_id', null, $skip_bank, false, "return setAccount(1, false)");
156                 if ($dim >= 1)
157                         dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
158                 if ($dim > 1)
159                         dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
160         }
161         if ($dim < 1)
162                 hidden('dimension_id', 0);
163         if ($dim < 2)
164                 hidden('dimension2_id', 0);
165
166         amount_cells(null, 'AmountDebit');
167         amount_cells(null, 'AmountCredit');
168         text_cells_ex(null, 'LineMemo', 35, 50);
169
170         if (isset($_GET['Edit'])) 
171         {
172         submit_cells('UpdateItem', _("Update"));
173         submit_cells('CancelItemChanges', _("Cancel"));
174         } 
175         else 
176                 submit_cells('AddItem', _("Add item"), "colspan=2");
177
178         end_row();
179 }
180
181
182 //---------------------------------------------------------------------------------
183
184 function gl_options_controls()
185 {
186           echo "<br><table align='center'>";
187
188           textarea_row(_("Memo"), 'memo_', null, 50, 3);
189
190           echo "</table>";
191 }
192
193
194 //---------------------------------------------------------------------------------
195
196 ?>