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