Ajax additions.
[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     div_start('items_table');
46         start_table("$table_style colspan=7 width=95%");
47         if ($dim == 2)
48                 $th = array(_("Account Code"), _("Account Description"), _("Dimension")." 1",
49                         _("Dimension")." 2", _("Debit"), _("Credit"), _("Memo"));
50         else if ($dim == 1)
51                 $th = array(_("Account Code"), _("Account Description"), _("Dimension"),
52                         _("Debit"), _("Credit"), _("Memo"));
53         else
54                 $th = array(_("Account Code"), _("Account Description"),
55                         _("Debit"), _("Credit"), _("Memo"));
56
57         if (count($order->gl_items)) $th[] = '';
58
59         table_header($th);      
60
61         $k = 0;
62
63         $id = find_submit('Edit');
64         foreach ($order->gl_items as $item) 
65         {
66                 if ($id != $item->index)
67                 {
68                 alt_table_row_color($k);
69
70                         label_cells($item->code_id, $item->description);
71                 if ($dim >= 1)
72                                 label_cell(get_dimension_string($item->dimension_id, true));
73                 if ($dim > 1)
74                                 label_cell(get_dimension_string($item->dimension2_id, true));
75                 if ($item->amount > 0)
76                 {
77                         amount_cell(abs($item->amount));
78                         label_cell("");
79                 }       
80                 else
81                 {
82                         label_cell("");
83                         amount_cell(abs($item->amount));
84                 }       
85                         label_cell($item->reference);
86
87                         edit_button_cell("Edit$item->index", _("Edit"),
88                                 _('Edit journal line'));
89                         edit_button_cell("Delete$item->index", _("Delete"),
90                                 _('Remove line from journal'));
91                 end_row();
92                 } 
93                 else 
94                 {
95                         gl_edit_item_controls($order, $dim, $item->index);
96                 }
97         }
98
99         if ($id == -1)
100                 gl_edit_item_controls($order, $dim);
101
102         if ($order->count_gl_items()) 
103         {
104                 $colspan = ($dim == 2 ? "4" : ($dim == 1 ? "3" : "2"));
105                 start_row();
106                 label_cell(_("Total"), "align=right colspan=" . $colspan);
107                 amount_cell($order->gl_items_total_debit());
108                 amount_cell(abs($order->gl_items_total_credit()));
109                 end_row();
110         }
111
112     end_table();
113         div_end();
114 }
115
116 //---------------------------------------------------------------------------------
117
118 function gl_edit_item_controls(&$order, $dim, $Index=null)
119 {
120         global $Ajax;
121         start_row();
122
123         $id = find_submit('Edit');
124         if ($Index != -1 && $Index == $id)
125         {
126                 $item = $order->gl_items[$Index];
127                 $_POST['code_id'] = $item->code_id;
128                 $_POST['dimension_id'] = $item->dimension_id;
129                 $_POST['dimension2_id'] = $item->dimension2_id;
130                 $_POST['AmountDebit'] = price_format($item->amount);
131                 $_POST['AmountCredit'] = price_format(abs($item->amount));
132                 $_POST['description'] = $item->description;
133                 $_POST['LineMemo'] = $item->reference;
134
135                 hidden('Index', $item->index);
136                 hidden('code_id', $item->code_id);
137                 label_cell($_POST['code_id']);
138                 label_cell($item->description);
139                 if ($dim >= 1) 
140                         dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
141                 if ($dim > 1) 
142                         dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
143             $Ajax->activate('items_table');
144         }
145         else
146         {
147                 $_POST['AmountDebit'] = '';  //price_format(0);
148                 $_POST['AmountCredit'] = ''; //price_format(0);
149                 $_POST['dimension_id'] = 0;
150                 $_POST['dimension2_id'] = 0;
151                 $_POST['LineMemo'] = "";
152                 $_POST['_code_id_edit'] = "";
153                 $_POST['code_id'] = "";
154                 if(isset($_POST['_code_id_update'])) {
155                             $Ajax->activate('code_id');
156                 }
157                 
158                 $skip_bank = ($_SESSION["wa_current_user"]->access != 2);
159                 gl_all_accounts_list('code_id', null, $skip_bank, false, true);
160                 if ($dim >= 1)
161                         dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
162                 if ($dim > 1)
163                         dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
164         }
165         if ($dim < 1)
166                 hidden('dimension_id', 0);
167         if ($dim < 2)
168                 hidden('dimension2_id', 0);
169
170         small_amount_cells(null, 'AmountDebit');
171         small_amount_cells(null, 'AmountCredit');
172         text_cells_ex(null, 'LineMemo', 35, 50);
173
174         if ($id != -1)
175         {
176                 edit_button_cell('UpdateItem', _("Update"),
177                                 _('Confirm changes'));
178                 edit_button_cell('CancelItemChanges', _("Cancel"),
179                                 _('Cancel changes'));
180                 set_focus('amount');
181         } 
182         else 
183                 submit_cells('AddItem', _("Add Item"), "colspan=2",
184                     _('Add new line to journal'), true);
185
186         end_row();
187 }
188
189 //---------------------------------------------------------------------------------
190
191 function gl_options_controls()
192 {
193           echo "<br><table align='center'>";
194
195           textarea_row(_("Memo"), 'memo_', null, 50, 3);
196
197           echo "</table>";
198 }
199
200
201 //---------------------------------------------------------------------------------
202
203 ?>