chiark / gitweb /
sort of on way to working
authorian <ian>
Thu, 8 Apr 2004 01:37:02 +0000 (01:37 +0000)
committerian <ian>
Thu, 8 Apr 2004 01:37:02 +0000 (01:37 +0000)
farnell/farnell-find

index 78bbd4cd907baa2550e3c34c2a73cea5111f0e35..b31fef2519a0e522f3cb014229eb1d50974277e4 100755 (executable)
@@ -1,5 +1,10 @@
 #!/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;
 
@@ -27,6 +32,9 @@ our(%iteminstances);
 # $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
@@ -149,9 +157,8 @@ sub analyse_spec () {
            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;
@@ -179,13 +186,31 @@ sub analyse_spec () {
        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();
 }
 
@@ -235,7 +260,8 @@ sub calcorder ($$) {
     $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}) {
@@ -247,8 +273,9 @@ sub calcorder ($$) {
 
 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;
 }