*** empty log message ***
[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 page(_("Select Received Items to Add"));
13
14
15 if (!isset($_SESSION['supp_trans']))
16 {
17         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);;
18         exit;
19 }
20
21 //-----------------------------------------------------------------------------------------
22
23 display_heading($_SESSION['supp_trans']->supplier_name);
24
25 echo "<br>";
26
27 //-----------------------------------------------------------------------------------------
28
29 function check_data()
30 {
31         global $check_price_charged_vs_order_price,
32                 $check_qty_charged_vs_del_qty;
33         if (!is_numeric($_POST['this_quantity_inv'])) 
34         {
35                 display_error( _("The quantity to invoice must be numeric."));
36                 return false;
37         }
38
39         if ($_POST['this_quantity_inv'] <= 0) 
40         {
41                 display_error( _("The quantity to invoice must be greater than zero."));
42                 return false;
43         }
44
45         if (!is_numeric($_POST['ChgPrice']))
46         {
47                 display_error( _("The price is not numeric."));
48                 return false;
49         }
50
51         if ($check_price_charged_vs_order_price == True) 
52         {
53                 if ($_POST['ChgPrice']/$_POST['order_price'] > 
54                         (1 + (sys_prefs::over_charge_allowance() / 100)))
55                 {
56                         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.") .
57                         _("The over-charge percentage allowance is :") . sys_prefs::over_charge_allowance() . "%");
58                         return false;
59                 }
60         }
61
62         if ($check_qty_charged_vs_del_qty == True) 
63         {
64                 if ($_POST['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 ($_POST['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'], $_POST['this_quantity_inv'],
95                 //      $_POST['order_price'], $_POST['ChgPrice'], $complete,
96                 //      $_POST['std_cost_unit'], $_POST['gl_code']);
97                 $_SESSION['supp_trans']->add_grn_to_trans($_POST['GRNNumber'], $_POST['po_detail_item'],
98                         $_POST['item_code'], $_POST['item_description'], $_POST['qty_recd'],
99                         $_POST['prev_quantity_inv'], $_POST['this_quantity_inv'],
100                         $_POST['order_price'], $_POST['ChgPrice'], $complete,
101                         $_POST['std_cost_unit'], "");
102         }
103 }
104
105 //-----------------------------------------------------------------------------------------
106
107 if (isset($_GET['Delete']))
108 {
109         $_SESSION['supp_trans']->remove_grn_from_trans($_GET['Delete']);
110 }
111
112 //-----------------------------------------------------------------------------------------
113
114 display_grn_items($_SESSION['supp_trans'], 1);
115
116 echo "<br>";
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
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
150         $grn_already_on_invoice = False;
151
152         foreach ($_SESSION['supp_trans']->grn_items as $entered_grn)
153         {
154                 if ($entered_grn->id == $myrow["id"]) 
155                 {
156                         $grn_already_on_invoice = True;
157                 }
158         }
159         if ($grn_already_on_invoice == False)
160         {
161
162                         alt_table_row_color($k);
163
164                 label_cell(get_trans_view_str(25, $myrow["grn_batch_id"]));
165                 //text_cells(null, 'grn_item_id', $myrow["id"]);
166                 submit_cells('grn_item_id', $myrow["id"]);
167                 label_cell(get_trans_view_str(systypes::po(), $myrow["purch_order_no"]));
168             label_cell($myrow["item_code"]);
169             label_cell($myrow["description"]);
170             label_cell(sql2date($myrow["delivery_date"]));
171             qty_cell($myrow["qty_recd"]);
172             qty_cell($myrow["quantity_inv"]);
173             qty_cell($myrow["qty_recd"] - $myrow["quantity_inv"]);
174             amount_cell($myrow["unit_price"]);
175             amount_cell($myrow["unit_price"] * ($myrow["qty_recd"] - $myrow["quantity_inv"]));
176                         end_row();
177                         
178                 $i++;
179                 if ($i > 15)
180                 {
181                         $i = 0;
182                         table_header($th);
183                 }
184         }
185     }
186
187     end_table();
188 }
189
190 //-----------------------------------------------------------------------------------------
191
192 display_grn_items_for_selection();
193
194 //-----------------------------------------------------------------------------------------
195
196 if (isset($_POST['grn_item_id']) && $_POST['grn_item_id'] != "")
197 {
198
199         $myrow = get_grn_item_detail($_POST['grn_item_id']);
200
201         echo "<br>";
202         display_heading2(_("Delivery Item Selected For Adding To A Supplier Invoice"));
203         start_table("$table_style width=80%");
204         $th = array(_("Sequence #"), _("Item"), _("Description"), _("Quantity Outstanding"),
205                 _("Quantity to Invoice"), _("Order Price"), _("Actual Price"));
206         table_header($th);      
207
208         start_row();
209         label_cell($_POST['grn_item_id']);
210         label_cell($myrow['item_code']);
211         label_cell($myrow['description']);
212         qty_cell($myrow['QtyOstdg']);
213         text_cells(null, 'this_quantity_inv', $myrow['QtyOstdg'], 13, 15);
214         amount_cell($myrow['unit_price']);
215         text_cells(null, 'ChgPrice', $myrow['unit_price'], 13, 15);
216         end_row();
217         end_table(1);;
218
219         submit_center('AddGRNToTrans', _("Add to Invoice"));
220
221         hidden('GRNNumber', $_POST['grn_item_id']);
222         hidden('item_code', $myrow['item_code']);
223         hidden('item_description', $myrow['description']);;
224         hidden('qty_recd', $myrow['qty_recd']);
225         hidden('prev_quantity_inv', $myrow['quantity_inv']);
226         hidden('order_price', $myrow['unit_price']);
227         hidden('std_cost_unit', $myrow['std_cost_unit']);
228
229         hidden('po_detail_item', $myrow['po_detail_item']);
230 }
231
232 //----------------------------------------------------------------------------------------
233
234 end_form();
235 end_page();
236 ?>