Moving 2.0 development version to main trunk.
[fa-stable.git] / purchasing / supplier_credit_grns.php
1 <?php
2
3 $page_security = 5;
4 $path_to_root="..";
5
6 include_once($path_to_root . "/purchasing/includes/supp_trans_class.inc");
7 include_once($path_to_root . "/includes/session.inc");
8 include_once($path_to_root . "/purchasing/includes/purchasing_ui.inc");
9 include_once($path_to_root . "/purchasing/includes/purchasing_db.inc");
10
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 $id = find_submit('Delete');
75 if ($id != -1)
76 {
77         $_SESSION['supp_trans']->remove_grn_from_trans($id);
78         $Ajax->activate('grn_items');
79         $Ajax->activate('grn_table');
80 }
81
82 //-----------------------------------------------------------------------------------------
83 start_form(false,true);
84 display_grn_items($_SESSION['supp_trans'], 1);
85 end_form();
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 div_start('grn_table');
110 start_table("$table_style width=95%");
111 $th = array(_("Delivery"), _("Sequence #"), _("Order"), _("Item Code"), _("Description"),
112         _("Delivered"), _("Total Qty Received"), _("Qty Already Invoiced"),
113         _("Qty Yet To Invoice"), _("Order Price"), _("Line Value"));
114 table_header($th);
115 $i = $k =0;
116 while ($myrow = db_fetch($result))
117 {
118
119         $grn_already_on_credit = False;
120
121         foreach ($_SESSION['supp_trans']->grn_items as $entered_grn)
122         {
123                 if ($entered_grn->id == $myrow["id"])
124                 {
125                         $grn_already_on_credit = True;
126                 }
127         }
128         if ($grn_already_on_credit == False)
129         {
130
131                 alt_table_row_color($k);
132
133                 label_cell(get_trans_view_str(25, $myrow["grn_batch_id"]));
134         submit_cells('grn_item_id'.$myrow["id"], $myrow["id"], '', '', true);
135                 label_cell(get_trans_view_str(systypes::po(), $myrow["purch_order_no"]));
136         label_cell($myrow["item_code"]);
137         label_cell($myrow["description"]);
138         label_cell(sql2date($myrow["delivery_date"]));
139         $dec = get_qty_dec($myrow["item_code"]);
140         qty_cell($myrow["qty_recd"], false, $dec);
141         qty_cell($myrow["quantity_inv"], false, $dec);
142         qty_cell($myrow["qty_recd"] - $myrow["quantity_inv"], false, $dec);
143                 amount_cell($myrow["unit_price"]);
144                 amount_cell(round($myrow["unit_price"] * $myrow["quantity_inv"],  user_price_dec()));
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 div_end();
157
158 //-----------------------------------------------------------------------------------------
159 $id = find_submit('grn_item_id');
160 if ($id || get_post('AddGRNToTrans'))
161 {
162         $Ajax->activate('grn_selector');
163 }
164 if (get_post('AddGRNToTrans')) 
165 {
166         $Ajax->activate('grn_table');
167         $Ajax->activate('grn_items');
168 }
169
170
171 div_start('grn_selector');
172 $id = find_submit('grn_item_id');
173 if ($id != -1)
174 {
175
176         $myrow = get_grn_item_detail($id);
177
178         echo "<br>";
179         display_heading2(_("Delivery Item Selected For Adding To A Supplier Credit Note"));
180         start_table("$table_style width=80%");
181         $th = array(_("Sequence #"), _("Item"), _("Qty Already Invoiced"),
182                 _("Quantity to Credit"), _("Order Price"), _("Credit Price"));
183         table_header($th);
184
185         start_row();
186         label_cell($id);
187     label_cell($myrow['item_code'] . " " . $myrow['description']);
188     $dec = get_qty_dec($myrow['item_code']);
189     qty_cell($myrow["quantity_inv"], false, $dec);
190     qty_cells(null, 'This_QuantityCredited', number_format2(max($myrow['quantity_inv'],0), $dec), null, null, $dec);
191     amount_cell($myrow['unit_price']);
192     amount_cells(null, 'ChgPrice', price_format($myrow['unit_price']));
193     end_row();
194         end_table(1);
195
196         submit_center('AddGRNToTrans', _("Add to Credit Note"), true, '', true);
197
198         hidden('GRNNumber', $id);
199         hidden('item_code', $myrow['item_code']);;
200         hidden('item_description', $myrow['description']);
201         hidden('qty_recd', $myrow['qty_recd']);
202         hidden('prev_quantity_inv', $myrow['quantity_inv']);
203         hidden('order_price', $myrow['unit_price']);
204         hidden('std_cost_unit', $myrow['std_cost_unit']);
205
206         hidden('po_detail_item', $myrow['po_detail_item']);
207 }
208 div_end();
209
210 end_form();
211 echo '<br>';
212 end_page(false, true);
213 ?>