3d18c98ae93c451f8e0d1f01a33277297b8b783f
[fa-stable.git] / purchasing / supplier_credit_grns.php
1 <?php
2
3 $page_security = 5;
4
5 $path_to_root="..";
6 include_once($path_to_root . "/purchasing/includes/supp_trans_class.inc");
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 $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."));
19         exit;
20         /*It all stops here if there aint no supplier selected and credit note initiated ie $_SESSION['supp_trans'] started off*/
21 }
22
23 //-----------------------------------------------------------------------------------------
24
25 display_heading($_SESSION['supp_trans']->supplier_name);
26 echo "<br>";
27
28 //-----------------------------------------------------------------------------------------
29
30 function check_data()
31 {
32         if (!check_num('This_QuantityCredited', 0)) 
33         {
34                 display_error(_("The quantity to credit must be numeric and greater than zero."));
35                 return false;
36         }
37
38         if (!check_num('ChgPrice', 0))
39         {
40                 display_error(_("The price is either not numeric or negative."));
41                 return false;
42         }
43
44         return true;
45 }
46
47 //-----------------------------------------------------------------------------------------
48
49 if (isset($_POST['AddGRNToTrans']))
50 {
51
52         if (check_data())
53         {
54                 $complete = False;
55
56                 //$_SESSION['supp_trans']->add_grn_to_trans($_POST['GRNNumber'],
57         //      $_POST['po_detail_item'], $_POST['item_code'],
58         //      $_POST['item_description'], $_POST['qty_recd'],
59         //      $_POST['prev_quantity_inv'], $_POST['This_QuantityCredited'],
60         //      $_POST['order_price'], $_POST['ChgPrice'], $complete,
61         //      $_POST['std_cost_unit'], $_POST['gl_code']);
62                 $_SESSION['supp_trans']->add_grn_to_trans($_POST['GRNNumber'],
63                 $_POST['po_detail_item'], $_POST['item_code'],
64                 $_POST['item_description'], $_POST['qty_recd'],
65                 $_POST['prev_quantity_inv'], input_num('This_QuantityCredited'),
66                 $_POST['order_price'], input_num('ChgPrice'), $complete,
67                 $_POST['std_cost_unit'], "");
68         }
69 }
70
71 //-----------------------------------------------------------------------------------------
72
73 if (isset($_GET['Delete']))
74 {
75         $_SESSION['supp_trans']->remove_grn_from_trans($_GET['Delete']);
76 }
77
78 //-----------------------------------------------------------------------------------------
79
80 display_grn_items($_SESSION['supp_trans'], 1);
81
82 echo "<br>";
83
84 hyperlink_no_params("$path_to_root/purchasing/supplier_credit.php", _("Return to Credit Note Entry"));
85 echo "<hr>";
86
87 //-----------------------------------------------------------------------------------------
88
89 // get the supplier grns that have been invoiced
90 $result = get_grn_items(0, $_SESSION['supp_trans']->supplier_id, false, true);
91
92 if (db_num_rows($result) == 0)
93 {
94         display_note(_("There are no received items for the selected supplier that have been invoiced."));
95         display_note(_("Credits can only be applied to invoiced items."));
96
97         echo "<br>";
98         end_page();
99         exit;
100 }
101
102 /*Set up a table to show the GRN items outstanding for selection */
103 start_form(false, true);
104
105 start_table("$table_style width=95%");
106 $th = array(_("Delivery"), _("Sequence #"), _("Order"), _("Item Code"), _("Description"),
107         _("Delivered"), _("Total Qty Received"), _("Qty Already Invoiced"),
108         _("Qty Yet To Invoice"), _("Order Price"), _("Line Value"));
109 table_header($th);
110 $i = $k =0;
111 while ($myrow = db_fetch($result))
112 {
113
114         $grn_already_on_credit = False;
115
116         foreach ($_SESSION['supp_trans']->grn_items as $entered_grn)
117         {
118                 if ($entered_grn->id == $myrow["id"]) 
119                 {
120                         $grn_already_on_credit = True;
121                 }
122         }
123         if ($grn_already_on_credit == False)
124         {
125
126                 alt_table_row_color($k);
127
128                 label_cell(get_trans_view_str(25, $myrow["grn_batch_id"]));
129                 submit_cells('grn_item_id', $myrow["id"]);
130                 label_cell(get_trans_view_str(systypes::po(), $myrow["purch_order_no"]));
131         label_cell($myrow["item_code"]);
132         label_cell($myrow["description"]);
133         label_cell(sql2date($myrow["delivery_date"]));
134         qty_cell($myrow["qty_recd"]);
135         qty_cell($myrow["quantity_inv"]);
136         qty_cell($myrow["qty_recd"] - $myrow["quantity_inv"]);
137                 amount_cell($myrow["unit_price"]);
138                 amount_cell(round($myrow["unit_price"] * $myrow["quantity_inv"],  user_price_dec()));
139                 end_row();
140                 $i++;
141                 if ($i > 15)
142                 {
143                         $i = 0;
144                         table_header($th);
145                 }
146         }
147 }
148
149 end_table();
150
151 //-----------------------------------------------------------------------------------------
152
153 if (isset($_POST['grn_item_id']) && $_POST['grn_item_id'] != "")
154 {
155
156         $myrow = get_grn_item_detail($_POST['grn_item_id']);
157
158         echo "<br>";
159         display_heading2(_("Delivery Item Selected For Adding To A Supplier Credit Note"));
160         start_table("$table_style width=80%");
161         $th = array(_("Sequence #"), _("Item"), _("Qty Already Invoiced"),
162                 _("Quantity to Credit"), _("Order Price"), _("Credit Price"));
163         table_header($th);      
164
165         start_row();
166         label_cell($_POST['grn_item_id']);
167     label_cell($myrow['item_code'] . " " . $myrow['description']);
168     qty_cell($myrow["quantity_inv"]);
169     qty_cells(null, 'This_QuantityCredited', qty_format(max($myrow['quantity_inv'],0)));
170     amount_cell($myrow['unit_price']);
171     amount_cells(null, 'ChgPrice', price_format($myrow['unit_price']));
172     end_row();
173         end_table(1);
174
175         submit_center('AddGRNToTrans', _("Add to Credit Note"));
176
177         hidden('GRNNumber', $_POST['grn_item_id']);
178         hidden('item_code', $myrow['item_code']);;
179         hidden('item_description', $myrow['description']);
180         hidden('qty_recd', $myrow['qty_recd']);
181         hidden('prev_quantity_inv', $myrow['quantity_inv']);
182         hidden('order_price', $myrow['unit_price']);
183         hidden('std_cost_unit', $myrow['std_cost_unit']);
184
185         hidden('po_detail_item', $myrow['po_detail_item']);
186 }
187
188 end_form();
189 end_page();
190 ?>