Moving 2.0 development version to main trunk.
[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 start_form(false,true);
113 display_grn_items($_SESSION['supp_trans'], 1);
114 end_form();
115 echo "<br>";
116
117 hyperlink_no_params("$path_to_root/purchasing/supplier_invoice.php", _("Back to Supplier Invoice Entry"));
118 echo "<hr>";
119
120 //-----------------------------------------------------------------------------------------
121
122 function display_grn_items_for_selection()
123 {
124         global $table_style;
125
126         $result = get_grn_items(0, $_SESSION['supp_trans']->supplier_id, true);
127
128     if (db_num_rows($result) == 0)
129     {
130         display_note(_("There are no outstanding items received from this supplier that have not been invoiced by them."), 0, 1);
131         end_page();
132         exit;
133     }
134
135     /*Set up a table to show the outstanding GRN items for selection */
136     start_form(false, true);
137
138     display_heading2(_("Items Received Yet to be Invoiced"));
139         div_start('grn_table');
140     start_table("$table_style colspan=7 width=95%");
141     $th = array(_("Delivery"), _("Sequence #"), _("P.O."), _("Item"), _("Description"),
142         _("Received On"), _("Quantity Received"), _("Quantity Invoiced"),
143         _("Uninvoiced Quantity"), _("Order Price"), _("Total"));
144     table_header($th);
145     $i = $k = 0;
146
147     while ($myrow = db_fetch($result))
148     {
149                 $grn_already_on_invoice = false;
150
151         foreach ($_SESSION['supp_trans']->grn_items as $entered_grn)
152         {
153                 if ($entered_grn->id == $myrow["id"])
154                 {
155                         $grn_already_on_invoice = true;
156                 }
157         }
158         if ($grn_already_on_invoice == false)
159         {
160
161                         alt_table_row_color($k);
162
163                 label_cell(get_trans_view_str(25, $myrow["grn_batch_id"]));
164                 //text_cells(null, 'grn_item_id', $myrow["id"]);
165                 submit_cells('grn_item_id'.$myrow["id"], $myrow["id"], '', '', true);
166                 label_cell(get_trans_view_str(systypes::po(), $myrow["purch_order_no"]));
167             label_cell($myrow["item_code"]);
168             label_cell($myrow["description"]);
169             label_cell(sql2date($myrow["delivery_date"]));
170             $dec = get_qty_dec($myrow["item_code"]);
171             qty_cell($myrow["qty_recd"], false, $dec);
172             qty_cell($myrow["quantity_inv"], false, $dec);
173             qty_cell($myrow["qty_recd"] - $myrow["quantity_inv"], false, $dec);
174             amount_cell($myrow["unit_price"]);
175             amount_cell(round($myrow["unit_price"] * ($myrow["qty_recd"] - $myrow["quantity_inv"]),
176                            user_price_dec()));
177                         end_row();
178
179                 $i++;
180                 if ($i > 15)
181                 {
182                         $i = 0;
183                         table_header($th);
184                 }
185         }
186     }
187
188     end_table();
189         div_end();
190 }
191
192 //-----------------------------------------------------------------------------------------
193 if (find_submit('grn_item_id') || get_post('AddGRNToTrans'))
194 {
195         $Ajax->activate('grn_selector');
196 }
197 if (get_post('AddGRNToTrans')) 
198 {
199         $Ajax->activate('grn_table');
200         $Ajax->activate('grn_items');
201 }
202
203 display_grn_items_for_selection();
204
205 //-----------------------------------------------------------------------------------------
206
207 div_start('grn_selector');
208
209 $id = find_submit('grn_item_id');
210 if ($id != -1)
211 {
212
213         $myrow = get_grn_item_detail($id);
214
215         echo "<br>";
216         display_heading2(_("Delivery Item Selected For Adding To A Supplier Invoice"));
217         start_table("$table_style width=80%");
218         $th = array(_("Sequence #"), _("Item"), _("Description"), _("Quantity Outstanding"),
219                 _("Quantity to Invoice"), _("Order Price"), _("Actual Price"));
220         table_header($th);
221
222         start_row();
223         label_cell($id);
224         label_cell($myrow['item_code']);
225         label_cell($myrow['description']);
226         $dec = get_qty_dec($myrow['item_code']);
227         qty_cell($myrow['QtyOstdg'], false, $dec);
228         qty_cells(null, 'this_quantity_inv', number_format2($myrow['QtyOstdg'], $dec), null, null, $dec);
229         amount_cell($myrow['unit_price']);
230         small_amount_cells(null, 'ChgPrice', price_format($myrow['unit_price']));
231         end_row();
232         end_table(1);;
233
234         submit_center('AddGRNToTrans', _("Add to Invoice"), true, '', true);
235
236         hidden('GRNNumber', $id);
237         hidden('item_code', $myrow['item_code']);
238         hidden('item_description', $myrow['description']);;
239         hidden('qty_recd', $myrow['qty_recd']);
240         hidden('prev_quantity_inv', $myrow['quantity_inv']);
241         hidden('order_price', $myrow['unit_price']);
242         hidden('std_cost_unit', $myrow['std_cost_unit']);
243
244         hidden('po_detail_item', $myrow['po_detail_item']);
245 }
246 div_end();
247
248 //----------------------------------------------------------------------------------------
249
250 end_form();
251 echo '<br>';
252 end_page(false, true);
253
254 ?>