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