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 Supplier Transactions class to hold all the information for an accounts payable invoice or credit note
15 include_once($path_to_root . "/taxes/tax_calc.inc");
20 var $grn_items; /*array of objects of class GRNDetails using the GRN No as the pointer */
21 var $gl_codes; /*array of objects of class gl_codes using a counter as the pointer */
24 var $terms_description;
41 var $gl_codes_counter=0;
45 /*Constructor function initialises a new Supplier Transaction object */
46 $this->grn_items = array();
47 $this->gl_codes = array();
50 function add_grn_to_trans($grn_item_id, $po_detail_item, $item_code, $item_description,
51 $qty_recd, $prev_quantity_inv, $this_quantity_inv, $order_price, $chg_price,
52 $Complete, $std_cost_unit, $gl_code)
54 $this->grn_items[$grn_item_id] = new grn_item($grn_item_id, $po_detail_item,
55 $item_code, $item_description, $qty_recd, $prev_quantity_inv, $this_quantity_inv,
56 $order_price, $chg_price, $Complete, $std_cost_unit, $gl_code);
60 function add_gl_codes_to_trans($gl_code, $gl_act_name, $gl_dim, $gl_dim2, $amount, $memo_)
62 $this->gl_codes[$this->gl_codes_counter] = new gl_codes($this->gl_codes_counter,
63 $gl_code, $gl_act_name, $gl_dim, $gl_dim2, $amount, $memo_);
64 $this->gl_codes_counter++;
68 function remove_grn_from_trans(&$grn_item_id)
70 unset($this->grn_items[$grn_item_id]);
72 function remove_gl_codes_from_trans(&$gl_code_counter)
74 unset($this->gl_codes[$gl_code_counter]);
77 function is_valid_trans_to_post()
79 return (count($this->grn_items) > 0 || count($this->gl_codes) > 0 ||
80 ($this->ov_amount != 0) || ($this->ov_discount > 0));
83 function clear_items()
85 unset($this->grn_items);
86 unset($this->gl_codes);
87 $this->ov_amount = $this->ov_discount = $this->supplier_id = 0;
89 $this->grn_items = array();
90 $this->gl_codes = array();
93 function get_taxes($tax_group_id=null, $shipping_cost=0)
98 if ($tax_group_id == null)
99 $tax_group_id = $this->tax_group_id;
101 // preload the taxgroup !
102 $tax_group = get_tax_group_items_as_array($tax_group_id);
104 foreach ($this->grn_items as $ln_itm)
106 $items[] = $ln_itm->item_code;
107 $prices[] =round( ($ln_itm->this_quantity_inv * $ln_itm->taxfree_charge_price($tax_group_id, $tax_group)),
111 if ($tax_group_id == null)
112 $tax_group_id = $this->tax_group_id;
114 $taxes = get_tax_for_items($items, $prices, $shipping_cost, $tax_group_id);
119 function get_total_charged($tax_group_id=null)
123 // preload the taxgroup !
124 if ($tax_group_id != null)
125 $tax_group = get_tax_group_items_as_array($tax_group_id);
129 foreach ($this->grn_items as $ln_itm)
130 $total += round(($ln_itm->this_quantity_inv * $ln_itm->taxfree_charge_price($tax_group_id, $tax_group)),
133 foreach ($this->gl_codes as $gl_line)
134 $total += $gl_line->amount;
139 } /* end of class defintion */
144 /* Contains relavent information from the purch_order_details as well to provide in cached form,
145 all the info to do the necessary entries without looking up ie additional queries of the database again */
150 var $item_description;
152 var $prev_quantity_inv;
153 var $this_quantity_inv;
160 function grn_item ($id, $po_detail_item, $item_code, $item_description, $qty_recd,
161 $prev_quantity_inv, $this_quantity_inv, $order_price, $chg_price, $Complete,
162 $std_cost_unit, $gl_code)
166 $this->po_detail_item = $po_detail_item;
167 $this->item_code = $item_code;
168 $this->item_description = $item_description;
169 $this->qty_recd = $qty_recd;
170 $this->prev_quantity_inv = $prev_quantity_inv;
171 $this->this_quantity_inv = $this_quantity_inv;
172 $this->order_price =$order_price;
173 $this->chg_price = $chg_price;
174 $this->Complete = $Complete;
175 $this->std_cost_unit = $std_cost_unit;
176 $this->gl_code = $gl_code;
179 function full_charge_price($tax_group_id, $tax_group=null)
181 return get_full_price_for_item($this->item_code,
182 $this->chg_price, $tax_group_id, 0, $tax_group);
185 function taxfree_charge_price($tax_group_id, $tax_group=null)
187 // if ($tax_group_id==null)
188 // return $this->chg_price;
189 return get_tax_free_price_for_item($this->item_code, $this->chg_price,
190 $tax_group_id, 0, $tax_group);
206 function gl_codes ($Counter, $gl_code, $gl_act_name, $gl_dim, $gl_dim2, $amount, $memo_)
209 /* Constructor function to add a new gl_codes object with passed params */
210 $this->Counter = $Counter;
211 $this->gl_code = $gl_code;
212 $this->gl_act_name = $gl_act_name;
213 $this->gl_dim = $gl_dim;
214 $this->gl_dim2 = $gl_dim2;
215 $this->amount = $amount;
216 $this->memo_= $memo_;