Javascript recalcAccount superseded by 'combo' class behaviour binding
[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
56         if (count($order->gl_items)) $th[] = '';
57
58         table_header($th);      
59
60         $k = 0;
61
62         foreach ($order->gl_items as $item) 
63         {
64                 if (!isset($_GET['Edit']) || $_GET['Edit'] != $item->index)
65                 {
66                 alt_table_row_color($k);
67
68                         label_cells($item->code_id, $item->description);
69                 if ($dim >= 1)
70                                 label_cell(get_dimension_string($item->dimension_id, true));
71                 if ($dim > 1)
72                                 label_cell(get_dimension_string($item->dimension2_id, true));
73                 if ($item->amount > 0)
74                 {
75                         amount_cell(abs($item->amount));
76                         label_cell("");
77                 }       
78                 else
79                 {
80                         label_cell("");
81                         amount_cell(abs($item->amount));
82                 }       
83                         label_cell($item->reference);
84                         edit_link_cell("Edit=$item->index");
85                         delete_link_cell("Delete=$item->index");
86                 end_row();;
87                 } 
88                 else 
89                 {
90                         gl_edit_item_controls($order, $dim, $item->index);
91                 }
92         }
93
94         if (!isset($_GET['Edit']))
95                 gl_edit_item_controls($order, $dim);
96
97         if ($order->count_gl_items()) 
98         {
99                 $colspan = ($dim == 2 ? "4" : ($dim == 1 ? "3" : "2"));
100                 start_row();
101                 label_cell(_("Total"), "align=right colspan=" . $colspan);
102                 amount_cell($order->gl_items_total_debit());
103                 amount_cell(abs($order->gl_items_total_credit()));
104                 end_row();
105         }
106
107     end_table();
108 }
109
110 //---------------------------------------------------------------------------------
111
112 function gl_edit_item_controls(&$order, $dim, $Index=null)
113 {
114         start_row();
115
116         if (isset($_GET['Edit']) && $Index != null)
117         {
118                 $item = $order->gl_items[$Index];
119                 if (!isset($_POST['code_id']))
120                         $_POST['code_id'] = $item->code_id;
121                 if (!isset($_POST['dimension_id']))
122                         $_POST['dimension_id'] = $item->dimension_id;
123                 if (!isset($_POST['dimension2_id']))
124                         $_POST['dimension2_id'] = $item->dimension2_id;
125
126                 if ((!isset($_POST['AmountDebit']) || ($_POST['AmountDebit']=="")) && $item->amount > 0)
127                         $_POST['AmountDebit'] = price_format($item->amount);
128
129                 if ((!isset($_POST['AmountCredit']) || ($_POST['AmountCredit']=="")) && $item->amount <= 0)
130                         $_POST['AmountCredit'] = price_format(abs($item->amount));
131
132                 if (!isset($_POST['description']) || ($_POST['description'] == ""))
133                         $_POST['description'] = $item->description;
134                 if (!isset($_POST['LineMemo']) || ($_POST['LineMemo'] == ""))
135                         $_POST['LineMemo'] = $item->reference;
136
137                 hidden('Index', $item->index);
138                 hidden('code_id', $item->code_id);
139                 label_cell($_POST['code_id']);
140                 label_cell($item->description);
141                 if ($dim >= 1) 
142                         dimensions_list_cells(null, 'dimension_id', $_POST['dimension_id'], true, " ", false, 1);
143                 if ($dim > 1) 
144                         dimensions_list_cells(null, 'dimension2_id', $_POST['dimension2_id'], true, " ", false, 2);
145         }
146         else
147         {
148                 $_POST['AmountDebit'] = '';  //price_format(0);
149                 $_POST['AmountCredit'] = ''; //price_format(0);
150                 $_POST['dimension_id'] = 0;
151                 $_POST['dimension2_id'] = 0;
152                 $_POST['LineMemo'] = "";
153                 $_POST['CodeID2'] = "";
154                 $_POST['code_id'] = "";
155                 
156                 text_cells(null, "CodeID2", "", 12, 10, "", "", "class='combo' rel='code_id'");
157                 $skip_bank = ($_SESSION["wa_current_user"]->access != 2);
158                 gl_all_accounts_list_cells(null, 'code_id', null, $skip_bank, false, "class='combo' rel='CodeID2'");
159                 if ($dim >= 1)
160                         dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
161                 if ($dim > 1)
162                         dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
163         }
164         if ($dim < 1)
165                 hidden('dimension_id', 0);
166         if ($dim < 2)
167                 hidden('dimension2_id', 0);
168
169         small_amount_cells(null, 'AmountDebit');
170         small_amount_cells(null, 'AmountCredit');
171         text_cells_ex(null, 'LineMemo', 35, 50);
172
173         if (isset($_GET['Edit'])) 
174         {
175         submit_cells('UpdateItem', _("Update"));
176         submit_cells('CancelItemChanges', _("Cancel"));
177         } 
178         else 
179                 submit_cells('AddItem', _("Add item"), "colspan=2");
180
181         end_row();
182 }
183
184
185 //---------------------------------------------------------------------------------
186
187 function gl_options_controls()
188 {
189           echo "<br><table align='center'>";
190
191           textarea_row(_("Memo"), 'memo_', null, 50, 3);
192
193           echo "</table>";
194 }
195
196
197 //---------------------------------------------------------------------------------
198
199 ?>