-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathinventory.class.php
More file actions
executable file
·166 lines (136 loc) · 3.59 KB
/
Copy pathinventory.class.php
File metadata and controls
executable file
·166 lines (136 loc) · 3.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
<?php /* INVENTORY $id: inventory.class.php,v 1.00 2003/11/02 17:32:00 dylan_cuthbert Exp $ */
error_reporting( E_ALL );
require_once( $AppUI->getSystemClass ('dp' ) );
require_once( $AppUI->getLibraryClass( 'PEAR/Date' ) );
class CInventory extends CDpObject
{
var $inventory_id = NULL;
var $inventory_user = NULL;
var $inventory_company = NULL;
var $inventory_department = NULL;
var $inventory_project = NULL;
var $inventory_category = NULL;
var $inventory_brand = NULL;
var $inventory_purchased = NULL;
var $inventory_cost = NULL;
var $inventory_rental_period = NULL;
var $inventory_name = NULL;
var $inventory_description = NULL;
var $inventory_serial = NULL;
var $inventory_asset_no = NULL;
var $inventory_costcode = NULL;
var $inventory_parent = NULL;
var $inventory_assign_from = NULL;
var $inventory_assign_until = NULL;
// v0.2
var $inventory_purchase_state = NULL;
var $inventory_purchase_company = NULL;
var $inventory_delivered = NULL;
// v0.3
var $inventory_quantity = NULL;
function CInventory()
{
$this->CDpObject( 'inventory', 'inventory_id' );
}
function check()
{
if ( !isset( $this->inventory_cost) )
{
$this->inventory_cost = 0;
}
return NULL;
}
// calculates the price of this object *and* all its children
// you can pass in the globals item_list and item_list_parents (created by load_all_items
// in utility.php to speed up the process
function calcChildrenTotal( $idx = 0, $item_list = NULL, $item_list_parents = NULL )
{
$total = 0;
if ( !$idx ) $idx = $this->inventory_id;
// do we have a cache of items?
if ( count( $item_list ) )
{
if ( isset( $item_list_parents[ $idx ] ) )
{
reset( $item_list_parents[ $idx ] );
foreach ( $item_list_parents[ $idx ] as $id )
{
$total += $item_list[ $id ][ 'inventory_cost' ];
$total += $this->calcChildrenTotal( $id, $item_list, $item_list_parents );
}
}
}
else
{
$sql = "SELECT inventory_id,inventory_cost FROM inventory WHERE inventory_parent=$idx";
$child_list = db_loadList( $sql );
echo db_error();
foreach ( $child_list as $child )
{
$total += $child[ 'inventory_cost' ];
$total += $this->calcChildrenTotal( $child[ 'inventory_id' ] );
}
}
global $drawn_array;
$drawn_array[ $idx ] = true;
return $total;
}
function getAssetNo()
{
if ( isset( $this->inventory_asset_no ) && $this->inventory_asset_no )
{
return $this->inventory_asset_no;
}
return sprintf( "%06d", $this->inventory_id );
}
// if "delete_children" is true then all children are also deleted
function delete( $idx, $delete_children = 0 )
{
$sql = "SELECT inventory_id FROM inventory WHERE inventory_parent=".$idx;
$child_list = db_loadList( $sql );
foreach ( $child_list as $row )
{
if ( $delete_children ) // recursive delete of children
{
$this->delete( $row[ "inventory_id" ], $delete_children );
}
else
{
$child = new CInventory();
if ( $child->load( $row[ "inventory_id" ] ) )
{
$child->inventory_parent = 0;
$child->store();
}
}
}
parent::delete( $idx );
}
}
class CInventoryCategory extends CDpObject
{
var $inventory_category_id = NULL;
var $inventory_category_name = NULL;
function CInventoryCategory()
{
$this->CDpObject( 'inventory_categories', 'inventory_category_id' );
}
function check()
{
return NULL;
}
}
class CInventoryBrand extends CDpObject
{
var $inventory_brand_id = NULL;
var $inventory_brand_name = NULL;
function CInventoryBrand()
{
$this->CDpObject( 'inventory_brands', 'inventory_brand_id' );
}
function check()
{
return NULL;
}
}
?>