2 /**********************************************************************
3 Copyright (C) FrontAccounting, LLC.
4 Released under the terms of the GNU General Public License, GPL,
5 as published by the Free Software Foundation, either version 3
6 of the License, or (at your option) any later version.
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
10 See the License here <http://www.gnu.org/licenses/gpl-3.0.html>.
11 ***********************************************************************/
12 /* Definition of the purch_order class to hold all the information for a purchase order and delivery
18 var $trans_type; // order/grn/invoice (direct)
22 var $delivery_address;
29 var $order_no; /*Only used for modification of existing orders otherwise only established when order committed */
30 var $lines_on_order = 0;
33 var $tax_group_array = null; // saves db queries
34 var $tax_included; // type of prices
39 function purch_order()
41 /*Constructor function initialises a new purchase order object */
42 $this->line_items = array();
43 $this->lines_on_order = $this->order_no = $this->supplier_id = 0;
46 function set_supplier($supplier_id, $supplier_name, $curr_code, $tax_group_id, $tax_included)
48 $this->supplier_id = $supplier_id;
49 $this->supplier_name = $supplier_name;
50 $this->curr_code = $curr_code;
51 $this->tax_group_id = $tax_group_id;
52 $this->tax_included = $tax_included;
53 $this->tax_group_array = get_tax_group_items_as_array($tax_group_id);
56 function add_to_order($line_no, $stock_id, $qty, $item_descr, $price, $uom, $req_del_date, $qty_inv, $qty_recd)
58 if ($qty != 0 && isset($qty))
60 $this->line_items[$line_no] = new po_line_details($line_no, $stock_id, $item_descr, $qty, $price, $uom,
61 $req_del_date, $qty_inv, $qty_recd);
62 $this->lines_on_order++;
68 function update_order_item($line_no, $qty, $price, $req_del_date, $description="")
70 if ($description != "")
71 $this->line_items[$line_no]->item_description = $description;
72 $this->line_items[$line_no]->quantity = $qty;
73 $this->line_items[$line_no]->price = $price;
74 $this->line_items[$line_no]->req_del_date = $req_del_date;
75 $this->line_items[$line_no]->item_description = $description;
78 function remove_from_order($line_no)
80 array_splice($this->line_items, $line_no, 1);
83 function order_has_items()
85 return count($this->line_items) != 0;
88 function clear_items()
90 unset($this->line_items);
91 $this->line_items = array();
93 $this->lines_on_order = 0;
98 function any_already_received()
100 /* Checks if there have been deliveries or invoiced entered against any of the line items */
101 if (count($this->line_items) > 0)
103 foreach ($this->line_items as $ordered_items)
105 if ($ordered_items->qty_received != 0 || $ordered_items->qty_inv != 0)
114 function some_already_received($line_no)
116 /* Checks if there have been deliveries or amounts invoiced against a specific line item */
117 if (count($this->line_items) > 0)
119 if ($this->line_items[$line_no]->qty_received != 0 ||
120 $this->line_items[$line_no]->qty_inv != 0)
128 function get_taxes($shipping_cost=null)
132 if($shipping_cost==null)
133 $shipping_cost = 0;//$this->freight_cost;
135 foreach ($this->line_items as $ln_itm) {
136 $items[] = $ln_itm->stock_id;
137 $prices[] = round($ln_itm->quantity * $ln_itm->price, user_price_dec());
139 $taxes = get_tax_for_items($items, $prices, $shipping_cost,
140 $this->tax_group_id, $this->tax_included, $this->tax_group_array);
142 // Adjustment for swiss franken, we always have 5 rappen = 1/20 franken
143 if ($this->curr_code == 'CHF') {
144 $val = $taxes['1']['Value'];
145 $val1 = (floatval((intval(round(($val*20),0)))/20));
146 $taxes['1']['Value'] = $val1;
152 Returns order value including all taxes
154 function get_trans_total() {
157 $dec = user_price_dec();
159 foreach ($this->line_items as $ln_itm) {
160 $items[] = $ln_itm->stock_id;
161 $value = round($ln_itm->quantity * $ln_itm->price, $dec);
166 if (!$this->tax_included ) {
167 $taxes = get_tax_for_items($items, $prices, 0, $this->tax_group_id,
168 $this->tax_included, $this->tax_group_array);
170 foreach($taxes as $tax)
171 $total += round($tax['Value'], $dec);
176 } /* end of class defintion */
178 class po_line_details
185 var $item_description;
192 var $quantity; // current/entry quantity of PO line
193 var $qty_inv; // quantity already invoiced against this line
194 var $receive_qty; // current/entry GRN quantity
195 var $qty_received; // quantity already received against this line
200 function po_line_details($line_no, $stock_item, $item_descr, $qty, $prc, $uom, $req_del_date,
201 $qty_inv, $qty_recd, $grn_item_id=0)
204 /* Constructor function to add a new LineDetail object with passed params */
205 $this->line_no = $line_no;
206 $this->stock_id = $stock_item;
207 $item_row = get_item($stock_item);
211 $this->descr_editable = $item_row["editable"];
212 if ($item_descr == null || !$this->descr_editable)
213 $this->item_description = $item_row["description"];
215 $this->item_description = $item_descr;
216 $this->quantity = $qty;
217 $this->req_del_date = $req_del_date;
219 // $this->units = $uom;
220 $this->tax_type = $item_row["tax_type_id"];
221 $this->tax_type_name = $item_row["tax_type_name"];
222 $this->units = $item_row["units"];
223 $this->qty_received = $qty_recd;
224 $this->qty_inv = $qty_inv;
225 $this->receive_qty = 0; /*initialise these last two only */
226 $this->standard_cost =0;
227 $this->grn_item_id = $grn_item_id;