198912c0f33752f5169fe5b25dc2c9b712264d37
[fa-stable.git] / purchasing / includes / po_class.inc
1 <?php
2 /**********************************************************************
3     Copyright (C) FrontAccounting, LLC.
4         Released under the terms of the GNU Affero General Public License,
5         AGPL, as published by the Free Software Foundation, either version 
6         3 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/agpl-3.0.html>.
11 ***********************************************************************/
12 /* Definition of the purch_order class to hold all the information for a purchase order and delivery
13 */
14
15 class purch_order 
16 {
17
18         var $supplier_id;
19         
20         var $line_items; /*array of objects of class line_details using the product id as the pointer */
21         var $curr_code;
22         var $requisition_no;
23         var $delivery_address;
24         var $Comments;
25         var $Location;
26         var $supplier_name;
27         var $orig_order_date;
28         var $order_no; /*Only used for modification of existing orders otherwise only established when order committed */
29         var $lines_on_order;
30         
31         var $reference;
32         
33         function purch_order()
34         {
35                 /*Constructor function initialises a new purchase order object */
36                 $this->line_items = array();
37                 $this->lines_on_order = $this->order_no = $this->supplier_id = 0;
38         }
39
40         function add_to_order($line_no, $stock_id, $qty, $item_descr, $price, $uom, $req_del_date, $qty_inv, $qty_recd)
41         {
42                 if ($qty != 0 && isset($qty))
43                 {
44                         $this->line_items[$line_no] = new line_details($line_no, $stock_id, $item_descr, $qty, $price, $uom, $req_del_date, $qty_inv, $qty_recd);
45                         $this->lines_on_order++;
46                         Return 1;
47                 }
48                 Return 0;
49         }
50
51         function update_order_item($line_no, $qty, $price, $req_del_date)
52         {
53                 $this->line_items[$line_no]->quantity = $qty;
54                 $this->line_items[$line_no]->price = $price;
55                 $this->line_items[$line_no]->req_del_date = $req_del_date;
56                 $this->line_items[$line_no]->price = $price;
57         }
58
59         function remove_from_order($line_no)
60         {
61                  $this->line_items[$line_no]->Deleted = true;
62         }
63         
64         function order_has_items() 
65         {
66                 if (count($this->line_items) > 0)
67                 {
68                         foreach ($this->line_items as $ordered_items) 
69                         {
70                                 if ($ordered_items->Deleted == false)
71                                 {
72                                         return true;
73                                 }
74                         }
75                 }
76                 return false;           
77         }
78         
79         function clear_items() 
80         {
81         unset($this->line_items);
82                 $this->line_items = array();
83                 
84                 $this->lines_on_order = 0;  
85                 $this->order_no = 0;
86         }
87
88         
89         function any_already_received()
90         {
91                 /* Checks if there have been deliveries or invoiced entered against any of the line items */
92                 if (count($this->line_items) > 0)
93                 {
94                         foreach ($this->line_items as $ordered_items) 
95                         {
96                                 if ($ordered_items->qty_received != 0 || $ordered_items->qty_inv != 0)
97                                 {
98                                         return 1;
99                                 }
100                         }
101                 }
102                 return 0;
103         }
104
105         function some_already_received($line_no)
106         {
107                 /* Checks if there have been deliveries or amounts invoiced against a specific line item */
108                 if (count($this->line_items) > 0)
109                 {
110                         if ($this->line_items[$line_no]->qty_received != 0 || 
111                                 $this->line_items[$line_no]->qty_inv != 0)
112                         {
113                                 return 1;
114                         }
115                 }
116                 return 0;
117         }
118 } /* end of class defintion */
119
120 class line_details 
121 {
122
123         Var $line_no;
124         Var $po_detail_rec;
125         Var $stock_id;
126         Var $item_description;
127         Var $quantity;
128         Var $price;
129         Var $units;
130         Var $req_del_date;
131         Var $qty_inv;
132         Var $qty_received;
133         Var $standard_cost;
134         Var $receive_qty;
135         Var $Deleted;   
136         
137         function line_details($line_no, $stock_item, $item_descr, $qty, $prc, $uom, $req_del_date, $qty_inv, $qty_recd)
138         {
139
140                 /* Constructor function to add a new LineDetail object with passed params */
141                 $this->line_no = $line_no;
142                 $this->stock_id = $stock_item;
143                 $this->item_description = $item_descr;
144                 $this->quantity = $qty;
145                 $this->req_del_date = $req_del_date;
146                 $this->price = $prc;
147                 $this->units = $uom;
148                 $this->qty_received = $qty_recd;
149                 $this->qty_inv = $qty_inv;
150                 $this->receive_qty = 0; /*initialise these last two only */
151                 $this->standard_cost =0;
152                 $this->Deleted = false;
153         }
154 }
155
156 ?>