#!/usr/bin/perl -w
use strict;
+use POSIX;
our(@warn);
our(@fault);
$chr->{MinOrder}= snarf('Minimum Order');
$chr->{Multiple}= snarf('Order Multiple');
$price= snarf('Unit Price', "\n\<!--.*--\\>");
- $price =~ m/\£(\d+\.\d\d)$/ or die "price $price ?";
+ $price =~ m/\£(\d+\.\d\d+)$/ or die "price $price ?";
$chr->{Price}= $1;
# price
return $chr;
sub snarf ($;$) {
my ($thing, $allowbefore) = @_;
- $allowbefore='' if !defined $allowbefore;
+ $allowbefore= defined $allowbefore ? "(?:$allowbefore)?" : '';
m!
\<td class="tabledata"(?: width="\d+%")?\>$thing</td>
-\<td class="tabledata"(?: width="\d+%")?\>(?:$allowbefore)?
+\<td class="tabledata"(?: width="\d+%")?\>$allowbefore
(.+)(?:\n\ \;)*
\</td>
!
local ($_);
my ($section,$sectionper);
for (;;) {
- $!=0; $_=<F>; die unless length $_;
+ $!=0; $_=<F>; die unless defined $_;
chomp; s/\s+$//;
last if m/^end$/;
next if m/^\#/ || !m/\S/;
my ($item,$qty,$ii,$bi,$toorder,$price,$total,$notechar);
foreach $part (keys %partdef) {
$pd= $partdef{$part};
+ $pd->{Desc}= '' if !defined $pd->{Desc};
next if length $pd->{Desc};
$try= $part;
}
foreach $pe (@{ $parts{$sp} }) {
$desc= $pe->{Desc};
+ $desc= '' if !defined $desc;
if ($pe->{Part} =~ m/^\d{3}\-/) {
$item= $pe->{Part};
} elsif (exists $partdef{$pe->{Part}}) {
next unless $bi;
($toorder,$notechar)= calcorder($qty, $bi);
$price= $toorder * $bi->{Price};
- printf("%5d%1s %-11s %.-60s %5.2d %5.2d\n",
+ printf("%5d%1s %-11s %-.60s %6.2f %6.2f %s\n",
$toorder, $notechar, $item, $bi->{Description},
- $bi->{Price}, $price)
+ $bi->{Price}, $price, $bi->{Avail})
or die $!;
$total += $price;
}
- printf((' 'x(5+1+1+11+1+60+5+1))."%5.2d\n", $total) or die $!;
+ printf((' 'x(5+1+1+11+1+60+6+1))."%6.2f\n", $total) or die $!;
dump_warnerrs();
-}
+}
+
+sub addqty ($$$$) {
+ my ($q1, $q2, $m2, $item) = @_;
+ my ($q1numer,$q1denom,$q1exact);
+ my ($q2numer,$q2denom,$q2exact);
+ if ($q2 !~ m!^(\d+)(?:/(\d+))?(\=?)$!) {
+ push @fault, "bad quantity $q2 x$m2 for item $item";
+ return $q1;
+ }
+ $q2numer= $1;
+ $q2denom= defined $2 ? $2 : '';
+ $q2exact= !!length $3;
+
+ $q1 =~ m!^(\d+)(?:/(\d+))?(\=?)$! or die "$q1 ?";
+ $q1numer= $1;
+ $q1denom= defined $2 ? $2 : '';
+ $q2exact= !!length $3;
+ if ($q1denom ne $q2denom) {
+ push @fault, "denominator for item $item changes from".
+ " $q1denom to $q2denom";
+ return $q1;
+ }
+ return sprintf("%d%s%s",
+ ($q1numer+$q2numer),
+ $q1denom,
+ ($q1exact && $q2exact ? '=' : ''));
+}
+
+sub calcorder ($$) {
+ my ($qty, $bi) = @_; # => ($toorder, $notechar);
+ my ($notechar, $exact);
+ $notechar= '';
+ $exact= 0;
+ if ($qty =~ s/\=$//) {
+ $exact= 1;
+ $notechar= '=';
+ }
+ if ($qty =~ m!^(\d+)/(\d+)!) {
+ my ($numer,$denom)= ($1,$2);
+ $numer += $denom/2 if !$exact;
+ $qty= ceil($numer / $denom);
+ $exact= 1;
+ $notechar= '~';
+ }
+ $qty =~ m/^\d+$/ or die "$qty ?";
+ $qty++ if !$exact;
+ if ($qty % $bi->{Multiple}) {
+ $qty= floor(($qty + $bi->{Multiple} - 1) / $bi->{Multiple});
+ $notechar= '*';
+ }
+ if ($qty < $bi->{MinOrder}) {
+ $qty= $bi->{MinOrder};
+ $notechar= '>';
+ }
+ ($qty, $notechar);
+}
sub dump_warnerrs () {
my ($w);