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