Ajax additions
[fa-stable.git] / purchasing / supplier_invoice_grns.php
1 <?php
2
3 $page_security = 5;
4 $path_to_root="..";
5
6 include_once($path_to_root . "/purchasing/includes/supp_trans_class.inc");
7 include_once($path_to_root . "/includes/session.inc");
8 include_once($path_to_root . "/purchasing/includes/purchasing_ui.inc");
9 include_once($path_to_root . "/purchasing/includes/purchasing_db.inc");
10
11 $js = "";
12 if ($use_date_picker)
13         $js .= get_js_date_picker();
14 page(_("Select Received Items to Add"), false, false, "", $js);
15
16 if (!isset($_SESSION['supp_trans']))
17 {
18         display_note("To enter supplier transactions the supplier must first be selected from the supplier selection screen, then the link to enter a supplier credit note must be clicked on.", 1, 0);;
19         exit;
20 }
21
22 //-----------------------------------------------------------------------------------------
23
24 display_heading($_SESSION['supp_trans']->supplier_name);
25
26 echo "<br>";
27
28 //-----------------------------------------------------------------------------------------
29
30 function check_data()
31 {
32         global $check_price_charged_vs_order_price,
33                 $check_qty_charged_vs_del_qty;
34         if (!check_num('this_quantity_inv', 0) || input_num('this_quantity_inv')==0)
35         {
36                 display_error( _("The quantity to invoice must be numeric and greater than zero."));
37                 set_focus('this_quantity_inv');
38                 return false;
39         }
40
41         if (!check_num('ChgPrice'))
42         {
43                 display_error( _("The price is not numeric."));
44                 set_focus('ChgPrice');
45                 return false;
46         }
47
48         if ($check_price_charged_vs_order_price == True)
49         {
50                 if ($_POST['order_price']!=input_num('ChgPrice')) {
51                      if ($_POST['order_price']==0 ||
52                         input_num('ChgPrice')/$_POST['order_price'] >
53                             (1 + (sys_prefs::over_charge_allowance() / 100)))
54                     {
55                         display_error(_("The price being invoiced is more than the purchase order price by more than the allowed over-charge percentage. The system is set up to prohibit this. See the system administrator to modify the set up parameters if necessary.") .
56                         _("The over-charge percentage allowance is :") . sys_prefs::over_charge_allowance() . "%");
57                         set_focus('ChgPrice');
58                         return false;
59                     }
60                 }
61         }
62
63         if ($check_qty_charged_vs_del_qty == True)
64         {
65                 if (input_num('this_quantity_inv') / ($_POST['qty_recd'] - $_POST['prev_quantity_inv']) >
66                         (1+ (sys_prefs::over_charge_allowance() / 100)))
67                 {
68                         display_error( _("The quantity being invoiced is more than the outstanding quantity by more than the allowed over-charge percentage. The system is set up to prohibit this. See the system administrator to modify the set up parameters if necessary.")
69                         . _("The over-charge percentage allowance is :") . sys_prefs::over_charge_allowance() . "%");
70                         set_focus('this_quantity_inv');
71                         return false;
72                 }
73         }
74
75         return true;
76 }
77
78 //-----------------------------------------------------------------------------------------
79
80 if (isset($_POST['AddGRNToTrans']))
81 {
82
83         if (check_data())
84         {
85         if (input_num('this_quantity_inv') >= ($_POST['qty_recd'] - $_POST['prev_quantity_inv']))
86         {
87                 $complete = true;
88         }
89         else
90         {
91                 $complete = false;
92         }
93
94                 $_SESSION['supp_trans']->add_grn_to_trans($_POST['GRNNumber'], $_POST['po_detail_item'],
95                         $_POST['item_code'], $_POST['item_description'], $_POST['qty_recd'],
96                         $_POST['prev_quantity_inv'], input_num('this_quantity_inv'),
97                         $_POST['order_price'], input_num('ChgPrice'), $complete,
98                         $_POST['std_cost_unit'], "");
99         }
100 }
101
102 //-----------------------------------------------------------------------------------------
103 $id = find_submit('Delete');
104 if ($id != -1)
105 {
106         $_SESSION['supp_trans']->remove_grn_from_trans($id);
107         $Ajax->activate('grn_items');
108         $Ajax->activate('grn_table');
109 }
110
111 //-----------------------------------------------------------------------------------------
112 display_grn_items($_SESSION['supp_trans'], 1);
113 echo "<br>";
114
115 hyperlink_no_params("$path_to_root/purchasing/supplier_invoice.php", _("Back to Supplier Invoice Entry"));
116 echo "<hr>";
117
118 //-----------------------------------------------------------------------------------------
119
120 function display_grn_items_for_selection()
121 {
122         global $table_style;
123
124         $result = get_grn_items(0, $_SESSION['supp_trans']->supplier_id, true);
125
126     if (db_num_rows($result) == 0)
127     {
128         display_note(_("There are no outstanding items received from this supplier that have not been invoiced by them."), 0, 1);
129         end_page();
130         exit;
131     }
132
133     /*Set up a table to show the outstanding GRN items for selection */
134     start_form(false, true);
135
136     display_heading2(_("Items Received Yet to be Invoiced"));
137         div_start('grn_table');
138     start_table("$table_style colspan=7 width=95%");
139     $th = array(_("Delivery"), _("Sequence #"), _("P.O."), _("Item"), _("Description"),
140         _("Received On"), _("Quantity Received"), _("Quantity Invoiced"),
141         _("Uninvoiced Quantity"), _("Order Price"), _("Total"));
142     table_header($th);
143     $i = $k = 0;
144
145     while ($myrow = db_fetch($result))
146     {
147                 $grn_already_on_invoice = false;
148
149         foreach ($_SESSION['supp_trans']->grn_items as $entered_grn)
150         {
151                 if ($entered_grn->id == $myrow["id"])
152                 {
153                         $grn_already_on_invoice = true;
154                 }
155         }
156         if ($grn_already_on_invoice == false)
157         {
158
159                         alt_table_row_color($k);
160
161                 label_cell(get_trans_view_str(25, $myrow["grn_batch_id"]));
162                 //text_cells(null, 'grn_item_id', $myrow["id"]);
163                 submit_cells('grn_item_id'.$myrow["id"], $myrow["id"], '', '', true);
164                 label_cell(get_trans_view_str(systypes::po(), $myrow["purch_order_no"]));
165             label_cell($myrow["item_code"]);
166             label_cell($myrow["description"]);
167             label_cell(sql2date($myrow["delivery_date"]));
168             $dec = get_qty_dec($myrow["item_code"]);
169             qty_cell($myrow["qty_recd"], false, $dec);
170             qty_cell($myrow["quantity_inv"], false, $dec);
171             qty_cell($myrow["qty_recd"] - $myrow["quantity_inv"], false, $dec);
172             amount_cell($myrow["unit_price"]);
173             amount_cell(round($myrow["unit_price"] * ($myrow["qty_recd"] - $myrow["quantity_inv"]),
174                            user_price_dec()));
175                         end_row();
176
177                 $i++;
178                 if ($i > 15)
179                 {
180                         $i = 0;
181                         table_header($th);
182                 }
183         }
184     }
185
186     end_table();
187         div_end();
188 }
189
190 //-----------------------------------------------------------------------------------------
191 if (find_submit('grn_item_id') || get_post('AddGRNToTrans'))
192 {
193         $Ajax->activate('grn_selector');
194 }
195 if (get_post('AddGRNToTrans')) 
196 {
197         $Ajax->activate('grn_table');
198         $Ajax->activate('grn_items');
199 }
200
201 display_grn_items_for_selection();
202
203 //-----------------------------------------------------------------------------------------
204
205 div_start('grn_selector');
206
207 $id = find_submit('grn_item_id');
208 if ($id != -1)
209 {
210
211         $myrow = get_grn_item_detail($id);
212
213         echo "<br>";
214         display_heading2(_("Delivery Item Selected For Adding To A Supplier Invoice"));
215         start_table("$table_style width=80%");
216         $th = array(_("Sequence #"), _("Item"), _("Description"), _("Quantity Outstanding"),
217                 _("Quantity to Invoice"), _("Order Price"), _("Actual Price"));
218         table_header($th);
219
220         start_row();
221         label_cell($id);
222         label_cell($myrow['item_code']);
223         label_cell($myrow['description']);
224         $dec = get_qty_dec($myrow['item_code']);
225         qty_cell($myrow['QtyOstdg'], false, $dec);
226         qty_cells(null, 'this_quantity_inv', number_format2($myrow['QtyOstdg'], $dec), null, null, $dec);
227         amount_cell($myrow['unit_price']);
228         small_amount_cells(null, 'ChgPrice', price_format($myrow['unit_price']));
229         end_row();
230         end_table(1);;
231
232         submit_center('AddGRNToTrans', _("Add to Invoice"), true, '', true);
233
234         hidden('GRNNumber', $id);
235         hidden('item_code', $myrow['item_code']);
236         hidden('item_description', $myrow['description']);;
237         hidden('qty_recd', $myrow['qty_recd']);
238         hidden('prev_quantity_inv', $myrow['quantity_inv']);
239         hidden('order_price', $myrow['unit_price']);
240         hidden('std_cost_unit', $myrow['std_cost_unit']);
241
242         hidden('po_detail_item', $myrow['po_detail_item']);
243 }
244 div_end();
245
246 //----------------------------------------------------------------------------------------
247
248 end_form();
249 echo '<br>';
250 end_page(false, true);
251
252 ?>