#!/usr/bin/perl -w
+# FIXME
+# this program is broken
+# run it on farnell-1 and you'll see
+# it seems very confused, particularly about defined parts
+
use strict;
use POSIX;
# $iteminstances{$item}[]{SectPer}
# $iteminstances{$item}[]{Mult} number in this sect/sper
+our(%itemdesc);
+# $itemdesc{$item}{$desc}= 1;
+
sub by_item ($) {
my ($itemcode) = @_;
# looks up $itemcode (ddd-d...) at Farnell and returns
if ($pe->{Part} =~ m/^\d{3}\-/) {
$item= $pe->{Part};
} elsif (exists $partdef{$pe->{Part}}) {
- $pd= $partdef{$pe->{Part}};
$item= $pd->{Item};
- $desc= $pd->{Desc}.' '.$desc;
+ $itemdesc{$item}{$pd->{Desc}}= 1;
} else {
push @fault, "unknown part $pe->{Part}";
next;
next unless $bi;
($toorder,$notechar)= calcorder($qty, $bi);
$price= $toorder * $bi->{Price};
- printf("%5d%1s %-11s %-.60s %6.2f %6.2f %s\n",
+ printf("%5d%1s %-11s %-.35s %6.2f %6.2f %s\n",
$toorder, $notechar, $item, $bi->{Description},
$bi->{Price}, $price, $bi->{Avail})
or die $!;
$total += $price;
+ foreach $desc (keys %{ $itemdesc{$item} }) {
+ next if !length $desc;
+ printf("%*s %s\n",
+ (5+1+11+1+5),'',
+ $desc)
+ or die $!;
+ }
+ foreach $ii (@{ $iteminstances{$item} }) {
+ $sp= $ii->{SectPer};
+ $sp =~ s/\n.*//;
+ $desc= "$sp: $ii->{Desc}";
+ $desc =~ s/\: $//;
+ printf("%*s %11s %s\n",
+ (5+1+5),'',
+ $ii->{Qty} eq '1' ? '' : $ii->{Qty},
+ $desc)
+ or die $!;
+ }
}
- printf((' 'x(5+1+1+11+1+60+6+1))."%6.2f\n", $total) or die $!;
+ printf("%*s %6.2f\n", (5+1+1+11+1+35+1+6),'', $total) or die $!;
dump_warnerrs();
}
$qty =~ m/^\d+$/ or die "$qty ?";
$qty++ if !$exact;
if ($qty % $bi->{Multiple}) {
- $qty= floor(($qty + $bi->{Multiple} - 1) / $bi->{Multiple});
+ $qty= floor(($qty + $bi->{Multiple} - 1) / $bi->{Multiple})
+ * $bi->{Multiple};
$notechar= '*';
}
if ($qty < $bi->{MinOrder}) {
sub dump_warnerrs () {
my ($w);
- foreach $w (@warn) { print("WARNING: $w\n") or die $!; }
- foreach $w (@fault) { print("ERROR: $w\n") or die $!; }
+ my (%r);
+ foreach $w (@fault) { next if $r{$w}++; print("ERROR: $w\n") or die $!; }
+ foreach $w (@warn) { next if $r{$w}++; print("WARNING: $w\n") or die $!; }
die "errors\n" if @fault;
}