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