#!/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);

&create_db_loc_table ;

exit ;

#------------------------------------------------------------------------------------------

sub create_db_loc_table {

&db_open_ro ;

# my $sql = qq(SELECT originopshub,originhub,origin,originreg,originoutlying,originhubid,originid FROM ffwaypls_filmfreight.waybills) ;
my $sql = qq(SELECT * FROM ffwaypls_filmfreight.waybills) ;

my $sth = $dbh->prepare($sql) ;

$sth -> execute() or die "Could not execute SQL statement $sql ... maybe invalid? $!";
$waybill_array_ref = $sth->fetchall_arrayref();

$sth->finish();

&db_close_conn ;

foreach $row (@$waybill_array_ref) {
    &db_waybills_fields ;
    
    if ($done{'loc'}{$wb_origin}) { next ; }    
    if ($done{'locid'}{$wb_originid}) { print "<br>DUPLICATE - $wb_originid" ; next ; }
    
    $wbcnt++ ;    
    
    # print qq(<br>$wbcnt. $wb_originopshub,$wb_originhub,$wb_origin,$wb_originreg,$wb_originoutlying,$wb_originhubid,$wb_originid) ;
    print qq(<br>$wb_originid,$wb_origin,$wb_originopshub,$wb_originhub,$wb_originreg,$wb_originoutlying,$wb_originhubid) ;
    
    $done{'loc'}{$wb_origin} = 1 ;
    $done{'locid'}{$wb_originid} = 1 ;     
    }
    
foreach $row (@$waybill_array_ref) {
    &db_waybills_fields ;
    
    if ($done{'loc'}{$wb_dest})   { next ; }    
    if ($done{'locid'}{$wb_destid}) { print "<br>DUPLICATE - $wb_destid" ; next ; }
    
    $wbcnt++ ;    
    
    # print qq(<br>$wbcnt. $wb_destopshub,$wb_desthub,$wb_dest,$wb_destreg,$wb_destoutlying,$wb_desthubid,$wb_destid) ;
    print qq(<br>$wb_destid,$wb_dest,$wb_destopshub,$wb_desthub,$wb_destreg,$wb_destoutlying,$wb_desthubid) ;
    
    $done{'loc'}{$wb_dest} = 1 ;
    $done{'locid'}{$wb_destid} = 1 ;     
    }

} #------------------------------------------------------------------------------------------

use db ;
use today ;

1;