diff --git a/SL/AA.pm b/SL/AA.pm index e1385a644..076e8be2d 100644 --- a/SL/AA.pm +++ b/SL/AA.pm @@ -21,9 +21,7 @@ sub post_transaction { my $disconnect = ($dbh) ? 0 : 1; # connect to database - if (! $dbh) { - $dbh = $form->dbconnect_noauto($myconfig); - } + $dbh = $form->dbconnect_noauto($myconfig) unless $dbh; my $query; my $sth; @@ -254,6 +252,10 @@ sub post_transaction { $form->{amount} = $invamount; # need for vr batch + + ($paymentaccno) = split /--/, $form->{"$form->{ARAP}_paid_$form->{paidaccounts}"}; + ($null, $paymentmethod_id) = split /--/, $form->{"paymentmethod_$form->{paidaccounts}"}; + $paymentmethod_id *= 1; if ($form->{vc} eq 'customer') { # dcn @@ -269,10 +271,6 @@ sub post_transaction { for my $dcn (qw(dcn rvc)) { $form->{$dcn} = $form->format_dcn($form->{$dcn}) } } - ($paymentaccno) = split /--/, $form->{"$form->{ARAP}_paid_$form->{paidaccounts}"}; - ($null, $paymentmethod_id) = split /--/, $form->{"paymentmethod_$form->{paidaccounts}"}; - $paymentmethod_id *= 1; - $query = qq|UPDATE $table SET invnumber = |.$dbh->quote($form->{invnumber}).qq|, @@ -1260,7 +1258,7 @@ sub company_details { my $disconnect = ($dbh) ? 0 : 1; # connect to database - $dbh = $form->dbconnect($myconfig); + $dbh = $form->dbconnect($myconfig) unless $dbh; # get rest for the customer/vendor my $query = qq|SELECT ct.$form->{vc}number, ct.name, ad.address1, ad.address2, @@ -1343,35 +1341,35 @@ sub ship_to { # connect to database my $dbh = $form->dbconnect($myconfig); - AA->company_details($myconfig, $form, $dbh); - - my $table = ($form->{vc} eq 'customer') ? 'ar' : 'ap'; - - my $query = qq|SELECT - s.shiptoname, s.shiptoaddress1, s.shiptoaddress2, - s.shiptocity, s.shiptostate, s.shiptozipcode, - s.shiptocountry, s.shiptocontact, s.shiptophone, - s.shiptofax, s.shiptoemail - FROM shipto s - WHERE trans_id = $form->{"$form->{vc}_id"} - UNION - SELECT - s.shiptoname, s.shiptoaddress1, s.shiptoaddress2, - s.shiptocity, s.shiptostate, s.shiptozipcode, - s.shiptocountry, s.shiptocontact, s.shiptophone, - s.shiptofax, s.shiptoemail - FROM shipto s - JOIN oe o ON (o.id = s.trans_id) - WHERE o.$form->{vc}_id = $form->{"$form->{vc}_id"} - UNION - SELECT - s.shiptoname, s.shiptoaddress1, s.shiptoaddress2, - s.shiptocity, s.shiptostate, s.shiptozipcode, - s.shiptocountry, s.shiptocontact, s.shiptophone, - s.shiptofax, s.shiptoemail - FROM shipto s - JOIN $table a ON (a.id = s.trans_id) - WHERE a.$form->{vc}_id = $form->{"$form->{vc}_id"}|; + AA->company_details($myconfig, $form, $dbh); + + my $table = ($form->{vc} eq 'customer') ? 'ar' : 'ap'; + + my $query = qq|SELECT + s.shiptoname, s.shiptoaddress1, s.shiptoaddress2, + s.shiptocity, s.shiptostate, s.shiptozipcode, + s.shiptocountry, s.shiptocontact, s.shiptophone, + s.shiptofax, s.shiptoemail + FROM shipto s + WHERE trans_id = $form->{"$form->{vc}_id"} + UNION + SELECT + s.shiptoname, s.shiptoaddress1, s.shiptoaddress2, + s.shiptocity, s.shiptostate, s.shiptozipcode, + s.shiptocountry, s.shiptocontact, s.shiptophone, + s.shiptofax, s.shiptoemail + FROM shipto s + JOIN oe o ON (o.id = s.trans_id) + WHERE o.$form->{vc}_id = $form->{"$form->{vc}_id"} + UNION + SELECT + s.shiptoname, s.shiptoaddress1, s.shiptoaddress2, + s.shiptocity, s.shiptostate, s.shiptozipcode, + s.shiptocountry, s.shiptocontact, s.shiptophone, + s.shiptofax, s.shiptoemail + FROM shipto s + JOIN $table a ON (a.id = s.trans_id) + WHERE a.$form->{vc}_id = $form->{"$form->{vc}_id"}|; if ($form->{id}) { $query .= qq| diff --git a/SL/Form.pm b/SL/Form.pm index f18c40890..49331bf7c 100644 --- a/SL/Form.pm +++ b/SL/Form.pm @@ -78,7 +78,7 @@ sub new { $self->{menubar} = 1 if $self->{path} =~ /lynx/i; - $self->{version} = "2.8.23"; + $self->{version} = "2.8.24"; $self->{dbversion} = "2.8.9"; bless $self, $type; @@ -1099,11 +1099,11 @@ sub format_line { @a = reverse @a; } - $i = $n - 1; + my $j = $n - 1; $newstr = ""; foreach $str (@a) { - $i++; - if (! ($i % $n)) { + $j++; + if (! ($j % $n)) { $newstr .= " $str"; } else { $newstr .= $str; @@ -1142,6 +1142,13 @@ sub format_dcn { my @e; my $i; + my $d; + my @n; + my $n; + my $w; + my $cd; + my $lr; + for (0 .. $#m) { @{ $m{$_} } = @m; $m = shift @m; @@ -1155,7 +1162,7 @@ sub format_dcn { $param = $1; $str = $param; - ($var, $padl) = split / /, $1; + ($var, $padl) = split / /, $param; $padl *= 1; if ($var eq 'membernumber') { @@ -1185,19 +1192,55 @@ sub format_dcn { while (/\x01(modulo.+?)\x01/) { $param = $1; - + + @e = split //, $modulo; + if ($param eq 'modulo10') { - @e = split //, $modulo; $e = 0; - for (@e) { - $e = $m{$e}[$_]; + for $n (@e) { + $e = $m{$e}[$n]; } $str = substr(10 - $e, -1); } - /\x01modulo.+?\x01(.+?)\x01modulo.+?\x01/; - $modulo = $1; + if ($param =~ /modulo(1\d+)?_/) { + ($n, $w, $lr) = split /_/, $param; + $cd = 0; + $m = $1; + + if ($lr eq 'right') { + @e = reverse @e; + } + + if ($w eq '12' || $w eq '21') { + @n = split //, $w; + + for $i (0 .. $#e) { + $n = $i % 2; + if (($d = $e[$i] * $n[$n]) > 9) { + for $n (split //, $d) { + $cd += $n; + } + } else { + $cd += $d; + } + } + } else { + @n = split //, $w; + for $i (0 .. $#e) { + $n = $i % 2; + $cd += $e[$i] * $n[$n]; + } + } + + $str = $cd % $m; + if ($m eq '10') { + if ($str > 0) { + $str = $m - $str; + } + } + } s/\x01$param\x01/$str/; diff --git a/SL/IS.pm b/SL/IS.pm index d07d3e9b5..2a98ade81 100644 --- a/SL/IS.pm +++ b/SL/IS.pm @@ -475,13 +475,12 @@ sub invoice_details { } } - my ($paymentaccno) = split /--/, $form->{"AR_paid_1"}; + my ($paymentaccno) = split /--/, $form->{"AR_paid_$form->{paidaccounts}"}; for $i (1 .. $form->{paidaccounts}) { if ($form->{"paid_$i"}) { push(@{ $form->{payment} }, $form->{"paid_$i"}); my ($accno, $description) = split /--/, $form->{"AR_paid_$i"}; - $paymentaccno = $accno; push(@{ $form->{paymentaccount} }, $description); push(@{ $form->{paymentdate} }, $form->{"datepaid_$i"}); push(@{ $form->{paymentsource} }, $form->{"source_$i"}); diff --git a/SL/RC.pm b/SL/RC.pm index 695224b8c..1d6fa1001 100644 --- a/SL/RC.pm +++ b/SL/RC.pm @@ -189,7 +189,7 @@ sub payment_transactions { $fx_transaction $transdate $cleared - UNION + UNION ALL SELECT ac.transdate, ac.source, ac.fx_transaction, ac.amount, ac.cleared, a.id, n.name FROM acc_trans ac @@ -201,7 +201,7 @@ sub payment_transactions { $fx_transaction $transdate $cleared - UNION + UNION ALL SELECT ac.transdate, ac.source, ac.fx_transaction, ac.amount, ac.cleared, a.id, n.name FROM acc_trans ac diff --git a/SL/RP.pm b/SL/RP.pm index b3096ab42..3079caa62 100644 --- a/SL/RP.pm +++ b/SL/RP.pm @@ -1512,6 +1512,7 @@ sub aging { c.contact, c.email, c.phone as $form->{vc}phone, c.fax as $form->{vc}fax, c.$form->{vc}number, c.taxnumber as $form->{vc}taxnumber, + a.description AS invdescription, a.invnumber, a.transdate, a.till, a.ordnumber, a.ponumber, a.notes, $c{$_}{flds}, a.duedate, a.invoice, a.id, a.curr, @@ -1581,6 +1582,194 @@ sub aging { } +sub reminder { + my ($self, $myconfig, $form) = @_; + + # connect to database + my $dbh = $form->dbconnect($myconfig); + + my $query; + + my $item; + my $curr; + + my @a = qw(company address businessnumber tel fax precision); + my %defaults = $form->get_defaults($dbh, \@a); + for (keys %defaults) { $form->{$_} = $defaults{$_} } + + $form->{currencies} = $form->get_currencies($dbh, $myconfig); + + my $where = "a.approved = '1'"; + my $name; + my $null; + my $ref; + + if ($form->{"$form->{vc}_id"}) { + $where .= qq| AND vc.id = $form->{"$form->{vc}_id"}|; + } else { + if ($form->{$form->{vc}} ne "") { + $name = $form->like(lc $form->{$form->{vc}}); + $where .= qq| AND lower(vc.name) LIKE '$name'|; + } + if ($form->{"$form->{vc}number"} ne "") { + $name = $form->like(lc $form->{"$form->{vc}number"}); + $where .= qq| AND lower(vc.$form->{vc}number) LIKE '$name'|; + } + } + + if ($form->{department}) { + ($null, $department_id) = split /--/, $form->{department}; + $where .= qq| AND a.department_id = $department_id|; + } + + $form->{sort} =~ s/;//g; + my $sortorder = ($form->{sort}) ? "vc.$form->{sort}" : "vc.name"; + + # select outstanding customers + $query = qq|SELECT DISTINCT vc.id, vc.name, vc.$form->{vc}number, + vc.language_code + FROM $form->{vc} vc + JOIN ar a ON (a.$form->{vc}_id = vc.id) + WHERE $where + AND a.paid != a.amount + ORDER BY $sortorder|; + my $sth = $dbh->prepare($query); + $sth->execute || $form->dberror; + + my @ot = (); + while ($ref = $sth->fetchrow_hashref(NAME_lc)) { + push @ot, $ref; + } + $sth->finish; + + $query = qq|SELECT s.formname + FROM status s + JOIN ar a ON (a.id = s.trans_id) + WHERE s.formname LIKE 'reminder_' + AND s.trans_id = ? + AND a.curr = ? + ORDER BY s.formname DESC|; + my $rth = $dbh->prepare($query); + + # for each company that has some stuff outstanding + $form->{currencies} ||= ":"; + + $where = qq| + a.paid != a.amount + AND a.approved = '1' + AND c.id = ? + AND a.curr = ?|; + + if ($department_id) { + $where .= qq| AND a.department_id = $department_id|; + } + + $query = qq|SELECT c.id AS vc_id, c.$form->{vc}number, c.name, c.terms, + ad.address1, ad.address2, ad.city, ad.state, ad.zipcode, ad.country, + c.contact, c.email, + c.phone as $form->{vc}phone, c.fax as $form->{vc}fax, + c.$form->{vc}number, c.taxnumber as $form->{vc}taxnumber, + a.description AS invdescription, + a.invnumber, a.transdate, a.till, a.ordnumber, a.ponumber, a.notes, + a.amount - a.paid AS due, + a.duedate, a.invoice, a.id, a.curr, + (SELECT exchangerate FROM exchangerate e + WHERE a.curr = e.curr + AND e.transdate = a.transdate) AS exchangerate, + ct.firstname, ct.lastname, ct.salutation, ct.typeofcontact, + s.* + FROM ar a + JOIN $form->{vc} c ON (a.$form->{vc}_id = c.id) + JOIN address ad ON (ad.trans_id = c.id) + LEFT JOIN contact ct ON (ct.trans_id = c.id) + LEFT JOIN shipto s ON (a.id = s.trans_id) + WHERE (a.transdate < (current_date - c.terms)) + AND $where + ORDER BY vc_id, transdate, invnumber|; + $sth = $dbh->prepare($query) || $form->dberror($query); + + $form->{AG} = (); + + for $curr (split /:/, $form->{currencies}) { + + for $item (@ot) { + + $sth->execute($item->{id}, $curr); + + while ($ref = $sth->fetchrow_hashref(NAME_lc)) { + $ref->{module} = ($ref->{invoice}) ? 'is' : 'ar'; + $ref->{module} = 'ps' if $ref->{till}; + $ref->{exchangerate} ||= 1; + $ref->{language_code} = $item->{language_code}; + + $rth->execute($ref->{id}, $curr); + $found = 0; + while (($reminder) = $rth->fetchrow_array) { + $ref->{level} = substr($reminder, -1); + $ref->{level}++; + push @{ $form->{AG} }, $ref; + $found = 1; + } + $rth->finish; + + if (! $found) { + $ref->{level}++; + push @{ $form->{AG} }, $ref; + } + } + $sth->finish; + + } + } + + # get language + $form->all_languages($myconfig, $dbh); + + # disconnect + $dbh->disconnect; + +} + + +sub save_level { + my ($self, $myconfig, $form) = @_; + + # connect to database + my $dbh = $form->dbconnect_noauto($myconfig); + + my $query; + + $query = qq|DELETE FROM status + WHERE trans_id = ? + AND formname LIKE 'reminder_'|; + my $dth = $dbh->prepare($query) || $form->dberror($query); + + $query = qq|INSERT INTO status (trans_id, formname) + VALUES (?,?)|; + my $ath = $dbh->prepare($query) || $form->dberror($query); + + for (split / /, $form->{ids}) { + if ($form->{"ndx_$_"}) { + + $dth->execute($_) || $form->dberror; + $dth->finish; + + if ($form->{"level_$_"} *= 1) { + $ath->execute($_, qq|reminder$form->{"level_$_"}|) || $form->dberror; + $ath->finish; + } + } + } + + my $rc = $dbh->commit; + + $dbh->disconnect; + + $rc; + +} + + sub get_customer { my ($self, $myconfig, $form) = @_; diff --git a/VERSION b/VERSION index 37c6fdb60..0668896a2 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -2.8.23 +2.8.24 diff --git a/bin/lynx/aa.pl b/bin/lynx/aa.pl index 008b7f0b3..31c811d93 100644 --- a/bin/lynx/aa.pl +++ b/bin/lynx/aa.pl @@ -484,7 +484,7 @@ sub form_header {