fixed underline in db pager for sortable columns.
[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[] =round( ($ln_itm->this_quantity_inv * $ln_itm->taxfree_charge_price($tax_group_id, $tax_group)),
99                          user_price_dec());
100         }
101         
102         if ($tax_group_id == null)
103                 $tax_group_id = $this->tax_group_id;            
104         
105         $taxes = get_tax_for_items($items, $prices, $shipping_cost, $tax_group_id);
106         
107         return $taxes;
108     }           
109     
110     function get_total_charged($tax_group_id=null)
111     {
112         $total = 0;
113         
114                 // preload the taxgroup !
115                 if ($tax_group_id != null)
116                         $tax_group = get_tax_group_items_as_array($tax_group_id);
117                 else            
118                         $tax_group = null;      
119         
120                 foreach ($this->grn_items as $ln_itm)
121                 $total += round(($ln_itm->this_quantity_inv * $ln_itm->taxfree_charge_price($tax_group_id, $tax_group)),
122                          user_price_dec());
123
124                 foreach ($this->gl_codes as $gl_line)
125                         $total += $gl_line->amount;
126                         
127                 return $total;
128     }
129
130 } /* end of class defintion */
131
132 class grn_item 
133 {
134
135 /* Contains relavent information from the purch_order_details as well to provide in cached form,
136 all the info to do the necessary entries without looking up ie additional queries of the database again */
137
138         var $id;
139         var $po_detail_item;
140         var $item_code;
141         var $item_description;
142         var $qty_recd;
143         var $prev_quantity_inv;
144         var $this_quantity_inv;
145         var $order_price;
146         var $chg_price;
147         var $Complete;
148         var $std_cost_unit;
149         var $gl_code;
150
151         function grn_item ($id, $po_detail_item, $item_code, $item_description, $qty_recd, 
152                 $prev_quantity_inv, $this_quantity_inv, $order_price, $chg_price, $Complete, 
153                 $std_cost_unit, $gl_code)
154         {
155
156                 $this->id = $id;
157                 $this->po_detail_item = $po_detail_item;
158                 $this->item_code = $item_code;
159                 $this->item_description = $item_description;
160                 $this->qty_recd = $qty_recd;
161                 $this->prev_quantity_inv = $prev_quantity_inv;
162                 $this->this_quantity_inv = $this_quantity_inv;
163                 $this->order_price =$order_price;
164                 $this->chg_price = $chg_price;
165                 $this->Complete = $Complete;
166                 $this->std_cost_unit = $std_cost_unit;
167                 $this->gl_code = $gl_code;
168         }
169         
170         function full_charge_price($tax_group_id, $tax_group=null)
171         {
172                 return get_full_price_for_item($this->item_code, 
173                   $this->chg_price, $tax_group_id, 0, $tax_group);
174         }
175         
176         function taxfree_charge_price($tax_group_id, $tax_group=null)
177         {
178 //              if ($tax_group_id==null)
179 //                      return $this->chg_price;
180                 return get_tax_free_price_for_item($this->item_code, $this->chg_price, 
181                   $tax_group_id, 0, $tax_group);
182         }
183 }
184
185
186 class gl_codes 
187 {
188
189         var $Counter;
190         var $gl_code;
191         var $gl_act_name;
192         var $gl_dim;
193         var $gl_dim2;
194         var $amount;
195         var $memo_;
196
197         function gl_codes ($Counter, $gl_code, $gl_act_name, $gl_dim, $gl_dim2, $amount, $memo_)
198         {
199
200         /* Constructor function to add a new gl_codes object with passed params */
201                 $this->Counter = $Counter;
202                 $this->gl_code = $gl_code;
203                 $this->gl_act_name = $gl_act_name;
204                 $this->gl_dim = $gl_dim;
205                 $this->gl_dim2 = $gl_dim2;
206                 $this->amount = $amount;
207                 $this->memo_= $memo_;
208         }
209 }
210
211 ?>