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