Changed license type to GPLv3 in top of files
[fa-stable.git] / includes / ui / allocation_cart.inc
1 <?php
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 Debtor Receipt/Credit note allocation class */
13
14 //-----------------------------------------------------------------------------------
15
16 class allocation 
17 {
18
19         var $trans_no; 
20         var $type;
21         var $person_id;
22         var $person_name;
23         var $date_;
24         var $amount; /*Total amount of the transaction in FX */
25         
26         var $allocs; /*array of transactions allocated to */    
27
28         function allocation($trans_no, $type, $person_id, $person_name, $amount, $date_)
29         {
30                 $this->allocs = array();
31                 
32                 $this->trans_no = $trans_no;
33                 $this->type = $type;
34                 $this->person_id = $person_id;
35                 $this->person_name = $person_name;
36                 $this->amount = $amount;
37                 $this->date_ = $date_;
38         }
39
40         function add_item($type, $type_no, $date_, $due_date, $amount, $amount_allocated, 
41                 $current_allocated)
42         {
43                 if ($amount > 0)
44                 {
45                         $this->allocs[count($this->allocs)] = new allocation_item($type, $type_no, 
46                                 $date_, $due_date, $amount, $amount_allocated, $current_allocated);
47                         return true;
48                 } 
49                 else 
50                 {
51                         return false;
52                 }
53         }
54         
55         function update_item($index, $type, $type_no, $date_, $due_date, 
56                 $amount, $amount_allocated, $current_allocated)
57         {
58                 if ($amount > 0)
59                 {
60                         $this->allocs[$index] = new allocation_item($type, $type_no, 
61                                 $date_, $due_date, $amount, $amount_allocated, $current_allocated);
62                         return true;
63                 } 
64                 else 
65                 {
66                         return false;
67                 }
68         }       
69         
70         function add_or_update_item($type, $type_no, $date_, $due_date, 
71                 $amount, $amount_allocated, $current_allocated)
72         {
73                 for ($i = 0; $i < count($this->allocs); $i++) 
74                 {
75                         $item = $this->allocs[$i];
76                         if (($item->type == $type) && ($item->type_no == $type_no)) 
77                         {
78                                 return $this->update_item($i, $type, $type_no, $date_, $due_date, 
79                                         $amount, $amount_allocated, $current_allocated);
80                         }  
81                 }
82         return $this->add_item($type, $type_no, $date_, $due_date, 
83                 $amount, $amount_allocated, $current_allocated);                                
84         }                                               
85
86
87
88 //-----------------------------------------------------------------------------------
89
90 class allocation_item 
91 {
92
93         var $type;
94         var $type_no;
95         
96         var $date_;
97         var $due_date;
98         
99         var $amount_allocated;
100         var $amount;
101         
102         var $current_allocated;
103         
104         function allocation_item ($type, $type_no, $date_, $due_date, $amount, 
105                 $amount_allocated, $current_allocated)
106         {
107
108                 $this->type = $type;
109                 $this->type_no = $type_no;
110                 
111                 $this->date_ = $date_;
112                 $this->due_date = $due_date;
113                 
114                 $this->amount = $amount;
115                 $this->amount_allocated = $amount_allocated;
116                 $this->current_allocated = $current_allocated;
117         }
118 }
119
120 //-----------------------------------------------------------------------------------
121
122 ?>