*** empty log message ***
[fa-stable.git] / purchasing / includes / supp_trans_class.inc
1 <?php
2
3 /* Definition of the Supplier Transactions class to hold all the information for an accounts payable invoice or credit note
4 */
5
6 include_once($path_to_root . "/taxes/tax_calc.inc");
7
8 class supp_trans 
9 {
10
11         var $grn_items; /*array of objects of class GRNDetails using the GRN No as the pointer */
12         var $gl_codes; /*array of objects of class gl_codes using a counter as the pointer */
13         var $supplier_id;
14         var $supplier_name;
15         var $terms_description;
16         var $terms;
17         
18         var $tax_description;
19         var $tax_group_id;
20         
21         var $is_invoice;
22
23         var $Comments;
24         var $tran_date;
25         var $due_date;
26
27         var $supp_reference;
28         var $reference;
29         var $ov_amount;
30         var $ov_discount;
31         var $ov_gst;
32         var $gl_codes_counter=0;
33
34         function supp_trans()
35         {
36                 /*Constructor function initialises a new Supplier Transaction object */
37                 $this->grn_items = array();
38                 $this->gl_codes = array();
39         }
40
41         function add_grn_to_trans($grn_item_id, $po_detail_item, $item_code, $item_description, 
42                 $qty_recd, $prev_quantity_inv, $this_quantity_inv, $order_price, $chg_price, 
43                 $Complete, $std_cost_unit, $gl_code)
44         {
45                 $this->grn_items[$grn_item_id] = new grn_item($grn_item_id, $po_detail_item, 
46                         $item_code, $item_description, $qty_recd, $prev_quantity_inv, $this_quantity_inv, 
47                         $order_price, $chg_price, $Complete, $std_cost_unit, $gl_code);
48                 return 1;
49         }
50
51         function add_gl_codes_to_trans($gl_code, $gl_act_name, $gl_dim, $gl_dim2, $amount, $memo_)
52         {
53                 $this->gl_codes[$this->gl_codes_counter] = new gl_codes($this->gl_codes_counter, 
54                         $gl_code, $gl_act_name, $gl_dim, $gl_dim2, $amount, $memo_);
55                 $this->gl_codes_counter++;
56                 return 1;
57         }
58
59         function remove_grn_from_trans(&$grn_item_id)
60         {
61             unset($this->grn_items[$grn_item_id]);
62         }
63         function remove_gl_codes_from_trans(&$gl_code_counter)
64         {
65              unset($this->gl_codes[$gl_code_counter]);
66         }
67         
68         function is_valid_trans_to_post()
69         {
70                 return (count($this->grn_items) > 0 || count($this->gl_codes) > 0 || 
71                         ($this->ov_amount != 0) || ($this->ov_discount > 0));
72         }
73         
74         function clear_items()
75         {
76                 unset($this->grn_items);
77                 unset($this->gl_codes);
78                 $this->ov_amount = $this->ov_discount = $this->supplier_id = 0;
79                 
80                 $this->grn_items = array();
81                 $this->gl_codes = array();              
82         }
83         
84     function get_taxes($tax_group_id=null, $shipping_cost=0)
85     {
86         $items = array();
87         $prices = array();
88         
89         if ($tax_group_id == null)
90                 $tax_group_id = $this->tax_group_id;
91                 
92                 // preload the taxgroup !
93                 $tax_group = get_tax_group_items_as_array($tax_group_id);       
94         
95         foreach ($this->grn_items as $ln_itm) 
96         {
97                 $items[] = $ln_itm->item_code;
98                 $prices[] = ($ln_itm->this_quantity_inv * $ln_itm->taxfree_charge_price($tax_group_id, $tax_group));
99         }
100         
101         if ($tax_group_id == null)
102                 $tax_group_id = $this->tax_group_id;            
103         
104         $taxes = get_tax_for_items($items, $prices, $shipping_cost, $tax_group_id);
105         
106         return $taxes;
107     }           
108     
109     function get_total_charged($tax_group_id=null)
110     {
111         $total = 0;
112         
113                 // preload the taxgroup !
114                 if ($tax_group_id != null)
115                         $tax_group = get_tax_group_items_as_array($tax_group_id);
116                 else            
117                         $tax_group = null;      
118         
119                 foreach ($this->grn_items as $ln_itm)
120                 $total += ($ln_itm->this_quantity_inv * $ln_itm->taxfree_charge_price($tax_group_id, $tax_group));
121
122                 foreach ($this->gl_codes as $gl_line)
123                         $total += $gl_line->amount;
124                         
125                 return $total;
126     }
127
128 } /* end of class defintion */
129
130 class grn_item 
131 {
132
133 /* Contains relavent information from the purch_order_details as well to provide in cached form,
134 all the info to do the necessary entries without looking up ie additional queries of the database again */
135
136         var $id;
137         var $po_detail_item;
138         var $item_code;
139         var $item_description;
140         var $qty_recd;
141         var $prev_quantity_inv;
142         var $this_quantity_inv;
143         var $order_price;
144         var $chg_price;
145         var $Complete;
146         var $std_cost_unit;
147         var $gl_code;
148
149         function grn_item ($id, $po_detail_item, $item_code, $item_description, $qty_recd, 
150                 $prev_quantity_inv, $this_quantity_inv, $order_price, $chg_price, $Complete, 
151                 $std_cost_unit, $gl_code)
152         {
153
154                 $this->id = $id;
155                 $this->po_detail_item = $po_detail_item;
156                 $this->item_code = $item_code;
157                 $this->item_description = $item_description;
158                 $this->qty_recd = $qty_recd;
159                 $this->prev_quantity_inv = $prev_quantity_inv;
160                 $this->this_quantity_inv = $this_quantity_inv;
161                 $this->order_price =$order_price;
162                 $this->chg_price = $chg_price;
163                 $this->Complete = $Complete;
164                 $this->std_cost_unit = $std_cost_unit;
165                 $this->gl_code = $gl_code;
166         }
167         
168         function full_charge_price()
169         {
170                 return $this->chg_price;
171         }
172         
173         function taxfree_charge_price($tax_group_id, $tax_group=null)
174         {
175                 if ($tax_group_id==null)
176                         return $this->chg_price;
177                 return get_tax_free_price_for_item($this->item_code, $this->chg_price, $tax_group_id, $tax_group);
178         }
179 }
180
181
182 class gl_codes 
183 {
184
185         var $Counter;
186         var $gl_code;
187         var $gl_act_name;
188         var $gl_dim;
189         var $gl_dim2;
190         var $amount;
191         var $memo_;
192
193         function gl_codes ($Counter, $gl_code, $gl_act_name, $gl_dim, $gl_dim2, $amount, $memo_)
194         {
195
196         /* Constructor function to add a new gl_codes object with passed params */
197                 $this->Counter = $Counter;
198                 $this->gl_code = $gl_code;
199                 $this->gl_act_name = $gl_act_name;
200                 $this->gl_dim = $gl_dim;
201                 $this->gl_dim2 = $gl_dim2;
202                 $this->amount = $amount;
203                 $this->memo_= $memo_;
204         }
205 }
206
207 ?>