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