aisa/scripts/db/admin/amend_db_waybills_fix_address.pl

98 lines
2.4 KiB
Perl
Raw Normal View History

2025-11-26 09:31:54 +00:00
#!/usr/bin/perl
print "Content-type: text/html\n\n";
BEGIN { use lib '/usr/home/cfg' ; require push_inc ; }
require cfg ;
&today ;
#------------------------------------------------------------------------------------------
use DBI;
use CGI::Carp qw(fatalsToBrowser);
&load_waybills ;
exit ;
#------------------------------------------------------------------------------------------
sub load_waybills {
&db_open_ro ;
my $sql = qq(SELECT * FROM ffwaypls_filmfreight.waybills WHERE senaddr1 = recaddr1) ;
my $sth = $dbh->prepare($sql) ;
$sth -> execute() or die "Could not execute SQL statement $sql ... maybe invalid? $!";
my $id_array_ref = $sth->fetchall_arrayref();
$sth->finish();
&db_close_conn ;
# &db_open_upd ;
foreach $row (@$id_array_ref) {
&db_waybills_fields ;
# if ($wb{waybillno} > 17534) { next ; }
# if ($wb{waybillno} < 17000) { next ; }
# if ($wb{waybillno} > 17534) { next ; }
if ($wb{waybillno} < 17000) { next ; }
# if ($wb{waybillno} > 100) { next ; }
$get_inline_address = 1 ;
&common_get_addresses ;
$new_wb{senaddr1} = $addr1{sender} ;
$new_wb{senaddr2} = $addr2{sender} ;
$new_wb{senaddr3} = $addr3{sender} ;
# foreach (sort keys %new_wb) {
# # $pre = substr($_,0,3) ;
# if ($new_wb{$_} ne $wb{$_}) { print uc "<br>$wb{waybillno} $_ : $wb{$_} vs <span style='color:orange;'>$new_wb{$_}</span>" ; }
# # $font = 'black' ;
# # if ($new_wb{$_} ne $wb{$_}) { $font = 'red' ; }
# # # print $_ . " = <span style='color:$font'>$new_wb{$_} : $wb{$_}</span>, " ;
# # unless ($wb{$_}) {$wb{$_} = $new_wb{$_} ; }
# # print "<span style='color:$font'>$wb{$_}</span>, " ;
# # $post = $pre ;
# }
&update_waybills($wb{waybillno}) ;
}
# &db_close_conn ;
} #------------------------------------------------------------------------------------------
sub update_waybills {
my ($waybillno) = @_ ;
$sql = qq(UPDATE ffwaypls_filmfreight.waybills SET
SenAddr1 = "$new_wb{senaddr1}",
SenAddr2 = "$new_wb{senaddr2}",
SenAddr3 = "$new_wb{senaddr3}"
WHERE WaybillNo = "$waybillno"
) ;
&common_debug($sql) ;
# $sth = $dbh -> do ($sql) or die "could not execute :<BR>$sql<BR>$!" ;
} #------------------------------------------------------------------------------------------
use db ;
use today ;
use common ;
1;