#!/usr/bin/perl

BEGIN { use lib '/usr/home/cfg' ; require push_inc ; }
    
require cfg ;

use CGI::Carp qw(fatalsToBrowser) ;

# https://itvadmin.co.za/cgi-bin/scripts/admin/oneoff/compare_sss_aisa_poc.pl?1&poc
# https://itvadmin.co.za/cgi-bin/scripts/admin/oneoff/compare_sss_aisa_poc.pl?1&recipient

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

my  @ARGV     = split(/\&/, $ENV{'QUERY_STRING'});
our $debug    = $ARGV[0] ;
our $poc_or_recipient 	= $ARGV[1] ;
# our $username = 'rory' ;

if ($debug) { print "Content-type: text/html\n\n"; }

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

&today ;
	
&db_open_upd ;
# &db_open_ro ;
    our $db_ignore_open_close = 1 ; # do one open and one close instead of repeating it
		&load_vars ;
	$db_ignore_open_close = 0 ; # do one open and one close instead of repeating it
&db_close_conn ;

if ($debug) { print "Done."; }

exit;

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

sub load_vars {
 
	# $poc_or_recipient = "poc" ;
	
	exit unless $poc_or_recipient ;
	# my $poc_or_recipient = "poc" ; 	
	my $id_field = "$poc_or_recipient\_id" ;
	my $table_ = "event_quotes_$poc_or_recipient" ;
	my $name_field = "$poc_or_recipient\_name" ;
	my $nr_field = ($poc_or_recipient eq 'poc') ? "$poc_or_recipient\_contact_nr" : "$poc_or_recipient\_nr" ;
	
	my $table_aisa = 'event_quotes aisa' ;
	my $table_sss = 'event_quotes sss' ;
	
	&db_min_ro($table_aisa,"id,$id_field","sss_quote_nr <> '0'","","") ; 
	# foreach (keys %{$db{$table_aisa}}) {
		# $aisa_poc_id{$_} = $db{$table_aisa}{$_}{$id_field} ;
	# }
	&db_switch_conn('sss') ;
	&db_min_ro($table_sss,"id,aisa_quote_nr,$id_field","aisa_quote_nr <> '0'","","") ; 
	foreach (keys %{$db{$table_sss}}) {
		print "\n sss_poc_id : $db{$table_sss}{$_}{$id_field} , aisa_poc_id : $db{$table_aisa}{$db{$table_sss}{$_}{aisa_quote_nr}}{$id_field}" if $db{$table_sss}{$_}{$id_field} ne $db{$table_aisa}{$db{$table_sss}{$_}{aisa_quote_nr}}{$id_field} ;
	}

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

use db ;
use today ;
use common ;
use common_min ;
