blob: 29ca2f0ef885173b171bdafc7f39d6068b7306e9 (
plain)
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
|
<?
class UniquePartList
{
public $uniques = array();
public $type_list = array();
public $raw_list = array();
public function addUnique(UniquePart $part)
{
//only add the part in if its the first instance.
if (!$this->getUnique($part->id))
{
$this->uniques[$part->id] = $part;
$this->type_list[$part->get('type')][$part->get('name')] = $part->id;
ksort($this->type_list);
}
}
public function addRaw(RawPart $part)
{
//add in our unique part.
$unique = new UniquePart($part->get('part_id'));
//is it legit?
if ($unique->id)
{
$this->addUnique($unique);
$this->raw_list[$unique->id][] = $part;
}
}
public function getUnique($unique_id)
{
return $this->uniques[$unique_id];
}
public function getUniqueQuantity($unique_id)
{
$total = 0;
foreach ($this->raw_list[$unique_id] AS $raw)
$total += $raw->getRealQuantity();
return $total;
}
public function getTypeList($type)
{
$sql = "
SELECT id
FROM unique_parts
WHERE id IN (" . implode(",", $this->type_list[$type]) . ")
ORDER BY name
";
return new Collection($sql, array('UniquePart' => id));
}
public function getSupplierList()
{
$sql = "
SELECT distinct(s.id)
FROM supplier_parts sp
INNER JOIN suppliers s
ON s.id = sp.supplier_id
WHERE sp.part_id IN (" . implode(",", array_keys($this->uniques)) . ")
ORDER BY s.name
";
return new Collection ($sql, array('Supplier' => 'id'));
}
}
?>
|