Better layout. Copyright notes. Mailto links, outer table routines. (3. run)
[fa-stable.git] / gl / includes / ui / gl_journal_ui.inc
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 include_once($path_to_root . "/includes/ui.inc");
13 include_once($path_to_root . "/includes/ui/items_cart.inc");
14
15 //--------------------------------------------------------------------------------
16
17 function display_order_header(&$Order)
18 {
19         global $table_style2;
20
21         $qes = has_quick_entries(-1, 0);
22
23         start_outer_table("$table_style2 width=90%");
24         table_section(1);
25
26         start_row();
27     date_cells(_("Date:"), 'date_');
28         ref_cells(_("Reference:"), 'ref', '', references::get_next(0));
29         end_row();
30
31         if ($qes)
32                 table_section(2, "20%");
33         else    
34                 table_section(2, "50%");
35
36         start_row();
37         check_cells(_("Reverse Transaction:"), 'Reverse', null);
38         end_row();
39         if ($qes !== false)
40         {
41                 table_section(3, "50%");
42                 start_row();
43                 quick_entries_list_cells(_("Quick Entry:"), 'person_id', null, -1, 0);
44                 amount_cells(_("Total Amount"), 'totamount', null, null, "&nbsp;&nbsp;".submit('go', _("Go"), false, false, true));                     
45                 end_row();
46         }
47                 
48         end_outer_table(1);
49 }
50
51 //---------------------------------------------------------------------------------
52
53 function display_gl_items($title, &$order)
54 {
55         global $table_style, $path_to_root;
56
57         display_heading($title);
58
59         $dim = get_company_pref('use_dimension');
60
61     div_start('items_table');
62         start_table("$table_style colspan=7 width=95%");
63         if ($dim == 2)
64                 $th = array(_("Account Code"), _("Account Description"), _("Dimension")." 1",
65                         _("Dimension")." 2", _("Debit"), _("Credit"), _("Memo"), "");
66         else if ($dim == 1)
67                 $th = array(_("Account Code"), _("Account Description"), _("Dimension"),
68                         _("Debit"), _("Credit"), _("Memo"), "");
69         else
70                 $th = array(_("Account Code"), _("Account Description"),
71                         _("Debit"), _("Credit"), _("Memo"), "");
72
73         if (count($order->gl_items)) $th[] = '';
74
75         table_header($th);      
76
77         $k = 0;
78
79         $id = find_submit('Edit');
80         foreach ($order->gl_items as $item) 
81         {
82                 if ($id != $item->index)
83                 {
84                 alt_table_row_color($k);
85
86                         label_cells($item->code_id, $item->description);
87                 if ($dim >= 1)
88                                 label_cell(get_dimension_string($item->dimension_id, true));
89                 if ($dim > 1)
90                                 label_cell(get_dimension_string($item->dimension2_id, true));
91                 if ($item->amount > 0)
92                 {
93                         amount_cell(abs($item->amount));
94                         label_cell("");
95                 }       
96                 else
97                 {
98                         label_cell("");
99                         amount_cell(abs($item->amount));
100                 }       
101                         label_cell($item->reference);
102
103                         edit_button_cell("Edit$item->index", _("Edit"),
104                                 _('Edit journal line'));
105                         delete_button_cell("Delete$item->index", _("Delete"),
106                                 _('Remove line from journal'));
107                 end_row();
108                 } 
109                 else 
110                 {
111                         gl_edit_item_controls($order, $dim, $item->index);
112                 }
113         }
114
115         if ($id == -1)
116                 gl_edit_item_controls($order, $dim);
117
118         if ($order->count_gl_items()) 
119         {
120                 $colspan = ($dim == 2 ? "4" : ($dim == 1 ? "3" : "2"));
121                 start_row();
122                 label_cell(_("Total"), "align=right colspan=" . $colspan);
123                 amount_cell($order->gl_items_total_debit());
124                 amount_cell(abs($order->gl_items_total_credit()));
125                 end_row();
126         }
127
128     end_table();
129         div_end();
130 }
131
132 //---------------------------------------------------------------------------------
133
134 function gl_edit_item_controls(&$order, $dim, $Index=null)
135 {
136         global $Ajax;
137         start_row();
138
139         $id = find_submit('Edit');
140         if ($Index != -1 && $Index == $id)
141         {
142                 $item = $order->gl_items[$Index];
143                 $_POST['code_id'] = $item->code_id;
144                 $_POST['dimension_id'] = $item->dimension_id;
145                 $_POST['dimension2_id'] = $item->dimension2_id;
146                 if ($item->amount > 0)
147                 {
148                         $_POST['AmountDebit'] = price_format($item->amount);
149                         $_POST['AmountCredit'] = "";
150                 }
151                 else
152                 {
153                         $_POST['AmountDebit'] = "";
154                         $_POST['AmountCredit'] = price_format(abs($item->amount));
155                 }       
156                 $_POST['description'] = $item->description;
157                 $_POST['LineMemo'] = $item->reference;
158
159                 hidden('Index', $item->index);
160                 hidden('code_id', $item->code_id);
161                 label_cell($_POST['code_id']);
162                 label_cell($item->description);
163                 if ($dim >= 1) 
164                         dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
165                 if ($dim > 1) 
166                         dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
167             $Ajax->activate('items_table');
168         }
169         else
170         {
171                 $_POST['AmountDebit'] = '';  //price_format(0);
172                 $_POST['AmountCredit'] = ''; //price_format(0);
173                 $_POST['dimension_id'] = 0;
174                 $_POST['dimension2_id'] = 0;
175                 $_POST['LineMemo'] = "";
176                 $_POST['_code_id_edit'] = "";
177                 $_POST['code_id'] = "";
178                 if(isset($_POST['_code_id_update'])) {
179                             $Ajax->activate('code_id');
180                 }
181                 
182                 $skip_bank = ($_SESSION["wa_current_user"]->access != 2);
183                 gl_all_accounts_list('code_id', null, $skip_bank, false, true);
184                 if ($dim >= 1)
185                         dimensions_list_cells(null, 'dimension_id', null, true, " ", false, 1);
186                 if ($dim > 1)
187                         dimensions_list_cells(null, 'dimension2_id', null, true, " ", false, 2);
188         }
189         if ($dim < 1)
190                 hidden('dimension_id', 0);
191         if ($dim < 2)
192                 hidden('dimension2_id', 0);
193
194         small_amount_cells(null, 'AmountDebit');
195         small_amount_cells(null, 'AmountCredit');
196         text_cells_ex(null, 'LineMemo', 35, 50);
197
198         if ($id != -1)
199         {
200                 button_cell('UpdateItem', _("Update"),
201                                 _('Confirm changes'), ICON_UPDATE);
202                 button_cell('CancelItemChanges', _("Cancel"),
203                                 _('Cancel changes'), ICON_CANCEL);
204                 set_focus('amount');
205         } 
206         else 
207                 submit_cells('AddItem', _("Add Item"), "colspan=2",
208                     _('Add new line to journal'), true);
209
210         end_row();
211 }
212
213 //---------------------------------------------------------------------------------
214
215 function gl_options_controls()
216 {
217           echo "<br><table align='center'>";
218
219           textarea_row(_("Memo"), 'memo_', null, 50, 3);
220
221           echo "</table>";
222 }
223
224
225 //---------------------------------------------------------------------------------
226
227 ?>