| Line 1... |
Line 1... |
| 1 |
#!/usr/bin/perl -w
|
1 |
#!/usr/bin/perl -w
|
| 2 |
use strict;
|
2 |
use strict;
|
| 3 |
# $Id: inventory.pl 333 2008-12-29 21:17:29Z agaran $
|
3 |
# $Id: inventory.pl 334 2008-12-29 21:36:34Z agaran $
|
| 4 |
# Thu, 13 Nov 2008 21:06:23 +0100
|
4 |
# Thu, 13 Nov 2008 21:06:23 +0100
|
| 5 |
# Maciej 'agaran' Pijanka <agaran@pld-linux.org>
|
5 |
# Maciej 'agaran' Pijanka <agaran@pld-linux.org>
|
| 6 |
# for OpenARM SBC Project
|
6 |
# for OpenARM SBC Project
|
| 7 |
# license: gpl v3
|
7 |
# license: gpl v3
|
| 8 |
|
8 |
|
| Line 125... |
Line 125... |
| 125 |
return $value;
|
125 |
return $value;
|
| 126 |
}
|
126 |
}
|
| 127 |
|
127 |
|
| 128 |
sub strbreak($$) {
|
128 |
sub strbreak($$) {
|
| 129 |
my ($str,$lim) = @_;
|
129 |
my ($str,$lim) = @_;
|
| 130 |
my @p = split / /,$str;
|
130 |
my @p = split /\ /,$str;
|
| 131 |
$str = '';
|
131 |
$str = '';
|
| 132 |
my $l = 0;
|
132 |
my $l = 0;
|
| 133 |
while (@p) {
|
133 |
while (@p) {
|
| 134 |
my $e = shift @p;
|
134 |
my $e = shift @p;
|
| 135 |
if ($l + length ($e) +1 > $lim) {
|
135 |
if ($l + length ($e) +1 > $lim) {
|
| Line 264... |
Line 264... |
| 264 |
my $id = scalar @Inv;
|
264 |
my $id = scalar @Inv;
|
| 265 |
|
265 |
|
| 266 |
$Inv[$id] = {};
|
266 |
$Inv[$id] = {};
|
| 267 |
|
267 |
|
| 268 |
$Inv[$id]{Datasheet} = delete $data{'datasheet'} if defined $data{'datasheet'};
|
268 |
$Inv[$id]{Datasheet} = delete $data{'datasheet'} if defined $data{'datasheet'};
|
| 269 |
$Inv[$id]{Manufacturer} = delete $data{'manufacturer'} if defined $data{'manufacturer'};
|
269 |
$Inv[$id]{Manufacturer} = etrim(trim(delete $data{'manufacturer'})) if defined $data{'manufacturer'};
|
| 270 |
$Inv[$id]{Description} = delete $data{'desc'} if defined $data{'desc'};
|
270 |
$Inv[$id]{Description} = etrim(trim(delete $data{'desc'})) if defined $data{'desc'};
|
| 271 |
$Inv[$id]{Price} = delete $data{'price'} if defined $data{'price'};
|
271 |
$Inv[$id]{Price} = delete $data{'price'} if defined $data{'price'};
|
| 272 |
$Inv[$id]{Ordercode} = delete $data{'ordercode'} if defined $data{'ordercode'};
|
272 |
$Inv[$id]{Ordercode} = etrim(trim(delete $data{'ordercode'})) if defined $data{'ordercode'};
|
| 273 |
$Inv[$id]{Manufacturer_Partno} = delete $data{'manufact_partno'} if defined $data{'manufact_partno'};
|
273 |
$Inv[$id]{Manufacturer_Partno} = etrim(trim(delete $data{'manufact_partno'})) if defined $data{'manufact_partno'};
|
| 274 |
$Inv[$id]{Supplier} = delete $data{'supplier'} if defined $data{'supplier'};
|
274 |
$Inv[$id]{Supplier} = delete $data{'supplier'} if defined $data{'supplier'};
|
| 275 |
|
275 |
|
| 276 |
unless (defined ($Inv_By_PartNo{$Inv[$id]{Manufacturer_Partno}})) {
|
276 |
unless (defined ($Inv_By_PartNo{$Inv[$id]{Manufacturer_Partno}})) {
|
| 277 |
$Inv_By_PartNo{$Inv[$id]{Manufacturer_Partno}} = $id;
|
277 |
$Inv_By_PartNo{$Inv[$id]{Manufacturer_Partno}} = $id;
|
| 278 |
} else {
|
278 |
} else {
|
| Line 333... |
Line 333... |
| 333 |
next;
|
333 |
next;
|
| 334 |
}
|
334 |
}
|
| 335 |
my $id = $Inv_By_PartNo{$device};
|
335 |
my $id = $Inv_By_PartNo{$device};
|
| 336 |
next if ($Inv[$id]{Manufacturer} =~ /none/i); # skip parts whose manufacturer is none
|
336 |
next if ($Inv[$id]{Manufacturer} =~ /none/i); # skip parts whose manufacturer is none
|
| 337 |
#inf_printf("Found in Inventory at %d %s", $id, $Inv[$id]{Manufacturer_Partno});
|
337 |
#inf_printf("Found in Inventory at %d %s", $id, $Inv[$id]{Manufacturer_Partno});
|
| 338 |
push @{$data{$id}{RefDes}}, $refdes;
|
338 |
push @{$data{$id}{RefDes}}, etrim(trim($refdes));
|
| 339 |
if (!defined $data{$id}{Footprint}) {
|
339 |
if (!defined $data{$id}{Footprint}) {
|
| 340 |
$data{$id}{Footprint} = $footprint;
|
340 |
$data{$id}{Footprint} = $footprint;
|
| 341 |
} else {
|
341 |
} else {
|
| 342 |
if ($data{$id}{Footprint} ne $footprint) {
|
342 |
if ($data{$id}{Footprint} ne $footprint) {
|
| 343 |
err_printf("Different footprints for same device in within single bom file, script ".
|
343 |
err_printf("Different footprints for same device in within single bom file, script ".
|
| Line 567... |
Line 567... |
| 567 |
foreach my $fkey (sort keys %Files) {
|
567 |
foreach my $fkey (sort keys %Files) {
|
| 568 |
my $rowblock = 0;
|
568 |
my $rowblock = 0;
|
| 569 |
foreach my $id ( sort {my $p = $Inv[$a]{Manufacturer} cmp $Inv[$b]{Manufacturer}; if ($p == 0) {
|
569 |
foreach my $id ( sort {my $p = $Inv[$a]{Manufacturer} cmp $Inv[$b]{Manufacturer}; if ($p == 0) {
|
| 570 |
return $Inv[$a]{Description} cmp $Inv[$b]{Description}}; return $p; } keys %{$Files{$fkey}}) {
|
570 |
return $Inv[$a]{Description} cmp $Inv[$b]{Description}}; return $p; } keys %{$Files{$fkey}}) {
|
| 571 |
|
571 |
|
| - |
|
572 |
my @p = split(/\n/, strbreak(join (', ', sort @{$Files{$fkey}{$id}{RefDes}}),43));
|
| - |
|
573 |
while (@p) {
|
| 572 |
$parttable->add($pn++, $Inv[$id]{Description}, $Inv[$id]{Manufacturer_Partno}, $BomData{$id}{Footprint},
|
574 |
$parttable->add($pn, $Inv[$id]{Description}, $Inv[$id]{Manufacturer_Partno}, $BomData{$id}{Footprint},
|
| 573 |
strbreak(join (', ', sort @{$Files{$fkey}{$id}{RefDes}}),43), $fkey);
|
575 |
etrim(trim(shift @p)), $fkey);
|
| 574 |
|
576 |
}
|
| 575 |
|
577 |
|
| - |
|
578 |
$pn++;
|
| 576 |
}
|
579 |
}
|
| 577 |
$parttable->add('--','=========','==========','==========','==========','==========');
|
580 |
$parttable->add('--','=========','==========','==========','==========','==========');
|
| 578 |
}
|
581 |
}
|
| 579 |
|
582 |
|
| 580 |
print $out $parttable->rule('-','+');
|
583 |
print $out $parttable->rule('-','+');
|