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