#!/usr/bin/perl

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

# unless ($username eq 'handre') { print "<<<<<<<<<<<< MAINTENANCE IN PROGRESS >>>>>>>>>" ; exit ; }

use DBI;
use CGI::Carp qw(fatalsToBrowser);
use Date::Manip;
use Date::Calc qw(:all);

use PDF::API2::Lite;
use constant mm => 25.4/72;
use constant in =>    1/72;
use constant pt =>    1;

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

@ARGV = split(/\\*\&/, $ENV{'QUERY_STRING'});

our $qt_id     = $ARGV[0] ;
our $tab_no    = $ARGV[1] ;
our $tab_secs  = $ARGV[2] ;

# my @sections  = split(/\|/,$tab_secs); 

my @prefix_arr = qw( cost_desc_ curr_amnt_ qty_cost_ zar_amnt_ );

# our $debug = 1 ;
our $label = 1 ; # used in pdf_check_value_of_up

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

print "Content-type: text/html\n\n";

&today ;
&pdf_curr_symbols ;

my $table = 'event_quotes' ;

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

&exclusions ;
&start_pdf ;
&build_pdf ;
&finish_pdf ;
&screen2 ;
    
exit ;

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

sub process_date {
	
	my ($date_string) = @_ ; 
	
	my $year = substr($date_string, 0, 4) ; 
	my $month = substr($date_string, 5, 2) ; 
	$month = int($month); 
	$month = $month_array[$month - 1] ;
	my $day = substr($date_string, 8, 2) ; 
	my $date_return = "$day-" ; 
	$date_return .= "$month-" ;
	$date_return .= "$year" ;
	$date_return .= " @ " . substr($date_string,11,5) ; 
	
	return $date_return ;
	
} #------------------------------------------------------------------------------------------

sub prep_pdf {

	my @cols = () ;

	&tab_hash ;

	&db_min_ro('event_quotes',"*","`id`='$qt_id'",'','') ;
	
	our @month_array = ( "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ) ; 
	
	our $countryid = $db{$table}{$qt_id}{country_id} ;
	our $custid = $db{$table}{$qt_id}{quote_to} ;
	our $date_from_for_pdf = &process_date($db{$table}{$qt_id}{date_from}) ;
	our $date_to_for_pdf = &process_date($db{$table}{$qt_id}{date_to}) ;
	
	our $type_id = $db{$table}{$qt_id}{type} ;
	our %country = () ;
	
	# print "COUNTty ID: $countryid, $custid \n" ;

	&db_min_ro('customers','id,name,physical_address,contact_email,phone,contact_name,vat_nr',"`id`='$custid'",'','') ;
	$customer_name{$custid}         = $db{customers}{$custid}{name} ; 
	$customer_address{$custid}      = $db{customers}{$custid}{physical_address} ; 
	$customer_email{$custid}        = $db{customers}{$custid}{contact_email} ; 
	$customer_phone{$custid}        = $db{customers}{$custid}{phone} ; 
	$customer_contact_name{$custid} = $db{customers}{$custid}{contact_name} ; 
	$customer_vat_nr{$custid}       = $db{customers}{$custid}{vat_nr} ; 

	&db_min_ro('event_cost_items','id,name','','','') ;
	foreach my $id (keys %{$db{event_cost_items}}) { $price_list{$id} = $db{event_cost_items}{$id}{name} ; }

	
	&db_min_ro('countries','*',"`id`='$countryid'",'','') ;
	$country{$countryid} = $db{countries}{$countryid}{name} ;
	# print "Country : $country{$countryid}" ; 
	$country{$countryid} = "Unknown" if not $country{$countryid} ;

	our $camera_system_id = $db{$table}{$qt_id}{camera_system_id} ;
	&db_min_ro('camera_systems','*',"`id`='$camera_system_id'",'','') ;
	$camera_system{$camera_system_id} = $db{camera_systems}{$camera_system_id}{name} ;
	
	our %event_type_for_pdf = () ; 
	&db_min_ro('event_types','id, name',"`id`='$type_id'",'','') ;
	$event_type_for_pdf{$type_id} = $db{event_types}{$type_id}{name} ;
	
	&db_min_ro('event_quotes_min','id,excl_costing_event,item_costing_event,qty_costing_event,usd_amnt_costing_event,item_ttl_costing_event,vat_costing_event,curr_amnt_costing_event,category_details',"`id`='$qt_id'",'','') ;	
	&db_min_ro('event_systems','id,name,description','','','') ; 	
	&db_min_ro('event_type_details','id,name','','','') ; 	
	&db_min_ro('users','id,name','','','') ; 
	&db_min_ro('sport_types','id,name','','','') ;
	&db_min_ro('regions','id,name','','','') ;
	&db_min_ro('cities','id,city','','','') ;
	&db_min_ro('organisations','id,name','','','') ;
	&db_min_ro('event_quotes_categories','*','','','') ;
	&db_min_ro('clubs','*','','','') ;
	
} #------------------------------------------------------------------------------------------
    
sub exclusions {

	our $exclude_rate = 0 ;
	our $exclude_vat  = 0 ;
		
	if ($db{$table}{$qt_id}{currency} ne 'ZAR') {
		$exclude_vat = 1 ;
	}
	
} #------------------------------------------------------------------------------------------
    
sub start_pdf {

	my  $qtpdfpath = "$pdfpath/event_details" ;
	our $pdfname = "Event_Details-$qt_id" . '.pdf' ;

	# &pdf_delete_previous_pdf($qtpdfpath) ;
	
	if (-f "$qtpdfpath/$pdfname") {
            unlink ("$qtpdfpath/$pdfname") or print "unable to unlink - $qtpdfpath/$pdfname : $!";
	}
	
	&pdf_initialise($qtpdfpath,$pdfname,'ITV Event Quote') ;
    
} #------------------------------------------------------------------------------------------
    
sub build_pdf {

	&tab_curr_symbols;
	&pdf_initialise_page ;

	$up = 292 ;
	# &quote_pdf_page_header ;

	&pdf_box_block_top(5,205,'#009bc8') ;
	
	$up       = 260 ;
	$across   = 1 ;
	$blue_box = 1 ;
	
	&pdf_page_header ;
	&quote_pdf_vars ;
	&quote_out_to_pdf ;
	# &quote_pdf_footer ;

	$up = 5 ;	
	&pdf_box_block_bottom(5,205,'#009bc8') ;
		
} #------------------------------------------------------------------------------------------

sub quote_out_to_pdf {

	&pdf_nl_t;
	# unless ($db{$table}{$qt_id}{currency} eq 'ZAR') { &pdf_medium_red_bold_text (70, $up, "$db{$table}{$qt_id}{currency} ROE : $db{$table}{$qt_id}{roe}") ; } # hidden for client
	# &pdf_medium_bold_text (157, $up, "Nr. :") ;

	&pdf_small_bold_text(150, $up, "Date") ; 
	my $dttxt = &custom_date_txt($db{$table}{$qt_id}{quote_date});

	&pdf_small_bold_text_right (198, $up, $dttxt) ;

	&pdf_nl;

	&pdf_small_bold_text(150, $up, "Event Nr") ;
	# &pdf_small_text_right (198, $up, $qt_id) ;
	&pdf_small_bold_text_right (198, $up, $db{$table}{$qt_id}{quote_nr}) ;

	# &pdf_large_bold_text (10, $up, $db{$table}{$qt_id}{ref}) if $db{$table}{$qt_id}{ref} ;

	# &pdf_nl_gap_1;
	&pdf_nl;

	&pdf_nl_t;
	&pdf_bar(10,$up,200,$up,'#009bc8','EVENT INFO',20,93) ;
	$up = $up - 5;

	&pdf_box_block_top(10,200,'#009bc8') ; # start block -------------------------------------

	our $top = 0 ;

	if ($custid) {

		my ($expiry_year,$expiry_month,$expiry_day) = split(/\-/,$db{$table}{$qt_id}{quote_expiry});
		my $expiry_date = &custom_date_txt("$expiry_year-$expiry_month-$expiry_day") if $db{$table}{$qt_id}{quote_expiry} ;
		
		&pdf_nl;
		
		$top = $up;
		
		&pdf_thin_box_block_top(15,100,'#009bc8'); 

		my $top_ref = $up ;
		our $pos = 37 ;
		our $pos2 = $pos + 1 ;
		our $pos3 = 132 ;
		our $pos4 = $pos3 + 1 ;
		
		$up = $up - 3.25 ;
		
		&pdf_small_bold_text (16, $up, "Customer") ;
		&pdf_small_text ($pos2, $up, $customer_name{$custid}) ;	
		
		$up = $up -1.25;

		&pdf_extra_thin_black_line ($pos,$top, $pos ,$up,'#009bc8') ;	
		&pdf_thin_box_block_bottom(15,100,'#009bc8') ;	
	
		&pdf_thin_box_block_top(15,100,'#009bc8') ;

		$up = $up - 3.25 ;		
		
		&pdf_small_bold_text (16, $up, "Address") ;		
		
		my @waypoint = split(/\, / , $customer_address{$custid}) ;	

		my $top2 = $up ;
		my $count = 0 ;
		for my $py (@waypoint) {
			&pdf_small_text ($pos2, $up, $waypoint[$count]) ;
			$count++;
			$up = $up - 3.25;
		}
		$up = $up - 1.25 if $count ;
		$up = $up - 4.55 unless $count ;
		# $up = $top2;
		$up = $up + 3.25;		
		&pdf_extra_thin_black_line ($pos,$top, $pos ,$up,'#009bc8') ;	
		&pdf_thin_box_block_bottom(15,100,'#009bc8');	
		&pdf_extra_thin_black_line ($pos,$top, $pos ,$up,'#009bc8') ;	
		# &pdf_extra_thin_black_line ($pos3,$top, $pos3 ,$up,'#009bc8') ;			
		# &pdf_thin_box_block_top(15,100,'#009bc8'); 
		my $top_address = $up ; 
		$up = $top ; 
		&pdf_thin_box_block_top(110,195,'#009bc8'); 
		$up = $up - 3.25;
		# &pdf_small_bold_text (16, $up, "Contact") ;
		# &pdf_small_text ($pos2, $up, $customer_contact_name{$custid}) ;		
		&pdf_small_bold_text (111, $up, "Reference") ;
		&pdf_small_text ($pos4, $up, $db{$table}{$qt_id}{ref}) ;	
		$up = $up -1.25;
		# &pdf_thin_box_block_bottom(15,100,'#009bc8');
		&pdf_thin_box_block_bottom(110,195,'#009bc8');	
		# &pdf_thin_box_block_top(110,195,'#009bc8');
		# &pdf_thin_box_block_top(15,100,'#009bc8');
		
		$up = $up - 3.25;
		&pdf_small_bold_text (111,$up,"Date From") ;		
		&pdf_small_text ($pos4, $up, $date_from_for_pdf) ;	
		$up = $up - 1.25;
		&pdf_thin_box_block_bottom(110,195,'#009bc8');
		
		$up = $up - 3.25;
		&pdf_small_bold_text (111,$up,"Date To") ;		
		&pdf_small_text ($pos4, $up, $date_to_for_pdf) ;	
		$up = $up - 1.25;
		&pdf_thin_box_block_bottom(110,195,'#009bc8');
		
		$up = $up - 3.25 ;
		&pdf_small_bold_text (111,$up,"Days") ;
		&pdf_small_text ($pos4, $up, $db{$table}{$qt_id}{qty}) ;
		$up = $up - 1.25 ;
		&pdf_thin_box_block_bottom(110,195,'#009bc8');
		my $days_bottom = $up ; 
		# &pdf_extra_thin_black_line ($pos3,$top,$pos3,$up,'#009bc8') ;	
		
		# &pdf_thin_box_block_bottom(15,100,'#009bc8');
		&pdf_extra_thin_black_line ($pos3,$top, $pos3 ,$up,'#009bc8') ;			
		# &pdf_thin_box_block_top(15,100,'#009bc8');
		
		my $dates_up = $up ;

		$up = $up - 3.25;	
		# &pdf_small_bold_text (16, $up, "Email") ;
		# &pdf_small_text ($pos2, $up, $customer_email{$custid}) ;
		$up = $up - 1.25;		
		# &pdf_extra_thin_black_line ($pos,$top, $pos ,$up,'#009bc8') ;	
		# &pdf_thin_box_block_bottom(15,100,'#009bc8');
		&pdf_nl;
		
		$up = $top_address ;
		$up = $dates_up if $dates_up < $up ;
		
		$up = $up - 4.5 ;
		$top = $up ; 
		my $top_type = $up ;

		&display_text (0,"Type of System",$event_type_for_pdf{$type_id}) ;
		
		$up = $top_type ;
		
		if ($usertype ne 'schools_manager') {
			
			&display_text_block ("System Details",$db{$table}{$qt_id}{type_details_id},'event_type_details','name',$pos3,$pos4,$up,1,",") ; 	

		}
		
		$up = $up - 4.5 ; 
		
		my $top_region = $up ; 
		&pdf_thin_box_block_top(15,100,'#009bc8'); 
		$up = $up - 3.25 ;
		&pdf_small_bold_text (16,$up,"Region") ;
		&pdf_small_text ($pos2, $up, $db{regions}{$db{$table}{$qt_id}{region_id}}{name}) ;
		$up = $up - 1.25 ;
		&pdf_extra_thin_black_line (15,$up,100,$up,'#009bc8') ;
		$up = $up - 3.25 ;
		
		&pdf_small_bold_text (16,$up,"City") ;
		
		foreach my $city_id (split(",",$db{$table}{$qt_id}{city_id})) {
			
			&pdf_small_text ($pos2, $up,$db{cities}{$city_id}{city}) ;
			$up = $up - 3.25 ;
		}
		$up = $up + 3.25 if $db{$table}{$qt_id}{city_id} ;
		# &pdf_small_text ($pos2, $up, $db{cities}{$db{$table}{$qt_id}{city_id}}{city}) ;
		$up = $up - 1.25 ;
		&pdf_extra_thin_black_line (15,$up,100,$up,'#009bc8') ;
		$up = $up - 3.25 ;
		&pdf_small_bold_text (16,$up,"Venue") ;
		foreach (split(",",$db{$table}{$qt_id}{organisation_ids})) {			
			&pdf_text_block ($pos2,"$db{organisations}{$_}{name}",45,6) ; 		
			$up = $up - 2 ;
		}
		$up = $up + 2 if $db{$table}{$qt_id}{organisation_ids} ;
		$up = $up - 1.25 unless $db{$table}{$qt_id}{organisation_ids} ;
		# $up = $up + 2.7 ;
		&pdf_extra_thin_black_line (15,$up,100,$up,'#009bc8') ;
		
		# $up = $up - 3.25 ;
		# &pdf_small_bold_text (16,$up,"Club Name") ;
		# &pdf_small_text ($pos2,$up,$db{$table}{$qt_id}{club_name}) ;
		# $up = $up - 1.25 ;
		# # &pdf_extra_thin_black_line (15,$up,100,$up,'#009bc8') ;		
		&pdf_extra_thin_black_line ($pos,$top_region,$pos,$up,'#009bc8') ;	
		
		&pdf_thin_box_block_bottom(15,100,'#009bc8');
		
		my $venue_bottom = $up ; 
		$up = $up - 4.5;
		$up = $top_region ;
		# $preferred_title{type} = "Type of System" ; $preferred_title{type_details_id} = "System Details" ; $preferred_title{event_system_id} = "System Name" ; 
		
		&display_text (1,"Poc Name",$db{$table}{$qt_id}{poc_name}) ;
		
		# $up = $up - 4.5;	
		
		&display_text (1,"Poc Contact Nr",$db{$table}{$qt_id}{poc_contact_nr}) ;
		
		$up = $venue_bottom;	
		$up = $up - 4.5;	
		$top = $up;
		
		if ($usertype ne 'schools_manager') {
			
			&display_text_block ("Club Name",$db{$table}{$qt_id}{event_system_id_multiple},'event_systems','name',$pos,$pos2,$up,2,";",'description',$db{$table}{$qt_id}{club_ids},'clubs','name') ; 
			
			$up = $up - 4.5 ;			
		}
		
		# &display_text (1,"Club Name",$db{$table}{$qt_id}{club_name}) ;

		# # &pdf_thin_box_block_top(110,195,'#009bc8');
		# # $top = $up;
		# # $up = $up - 3.25 ;
		# # &pdf_small_bold_text (111,$up,"Club Name") ;
		# # my $club_ids_exist = 0 ; 
		
		# # foreach (split(";",$db{$table}{$qt_id}{club_ids}))	{
			# # next unless $_ ; 
			 # # $club_ids_exist = 1 ; 
			# # &pdf_text_block ($pos4+1,$db{clubs}{$_}{name},40,6) ; 	
			# # $up -= 2 ; 
		# # }	
		# # $up += 2 ; 
		# # $up -= 3.25 unless $club_ids_exist ;
		# # &pdf_thin_box_block_bottom(110,195,'#009bc8');
		# # &pdf_extra_thin_black_line ($pos3+1,$top,$pos3+1,$up,'#009bc8') ;	
	
		# # $up = $up - 4.5 ; 
		
				# $up = $up - 3.25 ;
		# &pdf_small_bold_text (16,$up,"Club Name") ;
		# &pdf_small_text ($pos2,$up,$db{$table}{$qt_id}{club_name}) ;
		# $up = $up - 1.25 ;
		# # &pdf_extra_thin_black_line (15,$up,100,$up,'#009bc8') ;		
		# &pdf_extra_thin_black_line ($pos,$top_region,$pos,$up,'#009bc8') ;	
		

		&pdf_thin_box_block_top (15,195,'#009bc8') ;
		$top = $up ;
		$up = $up - 3.25 ;
		
		&pdf_small_bold_text (16,$up,"Format of Title") ;
		&pdf_text_block ($pos2 ,$db{$table}{$qt_id}{format_of_title},100,6) ; 		
		
		# $up = $up + 1.3 ;
		# $up = $up - 1.25 ;
		&pdf_thin_box_block_bottom (15,195,'#009bc8') ;
	
		&pdf_extra_thin_black_line ($pos,$top,$pos,$up,'#009bc8') ;	
		
		my $event_up = $up ;
		
		$up = $event_up ; 
		$up = $venue_bottom if $venue_bottom < $up ;
		$up = $up - 4.5 ;
		
		
		
		my $up_ops = $up ; 
		# $up = $up - 3.25 ;
		$top = $up;
		
		&display_text_block("Operators",$db{$table}{$qt_id}{operator_ids},'users','name',$pos,$pos2,$top,0,",") ; 
		
		my $top_op = $up ; 
		
		$up = $days_bottom ; 
		$up = $up - 4.5;
		
		
		$up = $up_ops ;
		$top = $up;
		
		&display_text_block("Sport Types",$db{$table}{$qt_id}{sport_type_ids},'sport_types','name',$pos3,$pos4,$top,1,",") ; 
		
		my $top_sport = $up ;

		$up = $top_sport ; 
		
		$up = $top_op if $top_op < $up  ; 
		
		$up = $up - 4.5;	
		
		# &display_text (0,"Poc Name",$db{$table}{$qt_id}{poc_name}) ;
		
		# $up = $up + 4.5;	
		
		# &display_text (1,"Poc Contact Nr",$db{$table}{$qt_id}{poc_contact_nr}) ;
		
		# $up = $up - 4.5;	
		
		my $cat1_top = $up ; 
	
		&display_text (0,"Category 1",$db{event_quotes_categories}{$db{$table}{$qt_id}{category_id_1}}{category}) ;

		my @category_details = split(/\|\;\|/,$db{event_quotes_min}{$qt_id}{category_details}) ;
	
		$up = $up - 4.5;
		&pdf_thin_box_block_top(15,100,'#009bc8');
		$top = $up;
		$up = $up - 3.25 ;
		&pdf_small_bold_text (16,$up,"Category 1") ;
		&pdf_small_bold_text (16,$up-3.25,"Sub-Categories") ;
		my $title_bottom = $up - 4.5 ; 
		# foreach (split(";",$db{$table}{$qt_id}{category_1})) {			
		&pdf_text_block ($pos2+1,$category_details[0],40,6) ; 		
			# $up = $up - 1.3 ;
		# }
		# $up = $up + 2.7 ;
		$up = $title_bottom if $title_bottom < $up ;
		&pdf_thin_box_block_bottom(15,100,'#009bc8');
		&pdf_extra_thin_black_line ($pos+1,$top,$pos+1,$up,'#009bc8') ;	
		
		my $cat1_botm = $up ; 
		$up = $cat1_top ;	

		&display_text (1,"Category 2",$db{event_quotes_categories}{$db{$table}{$qt_id}{category_id_2}}{category}) ;

		$up = $up - 4.5;
		&pdf_thin_box_block_top(110,195,'#009bc8');
		$top = $up;
		$up = $up - 3.25 ;
		&pdf_small_bold_text (111,$up,"Category 2") ;
		&pdf_small_bold_text (111,$up-3.25,"Sub-Categories") ;
		$title_bottom = $up - 4.5 ; 
		# foreach (split(";",$db{$table}{$qt_id}{category_1})) {			
			&pdf_text_block ($pos4+1,$category_details[1],40,6) ; 		
			# $up = $up - 1.3 ;
		# }
		# $up = $up + 2.7 ;
		$up = $title_bottom if $title_bottom < $up ;
		&pdf_thin_box_block_bottom(110,195,'#009bc8');
		&pdf_extra_thin_black_line ($pos3+1,$top,$pos3+1,$up,'#009bc8') ;	
		
	
		$up = $cat1_botm if $cat1_botm < $up ; 	
		$up = $up - 4.5;	
		&pdf_thin_box_block_top(15,195,'#009bc8');
		$top = $up;
		$up = $up - 3.25 ;
		&pdf_small_bold_text (16,$up,"Additional") ;
		&pdf_small_bold_text (16,$up-3.25,"Notes") ;
		my $top_add_notes = $up - 4.5 ; 
		&pdf_text_block ($pos2 ,$db{$table}{$qt_id}{additional_notes},100,6) ; 		
		if ($top_add_notes < $up) {
			$up = $top_add_notes ;
		}
		&pdf_thin_box_block_bottom(15,195,'#009bc8');
		&pdf_extra_thin_black_line ($pos,$top,$pos,$up,'#009bc8') ;
		
		$up = $up - 4.5;	
		
	}

	&pdf_box_block_bottom(10,200,'#009bc8') ; # end block -------------------------------------


	$inner_blue_box = 0 ;

	unless ($db{$table}{$qt_id}{excl_purchase_summary}) {

	}

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

sub display_text_block {
	
	my ($name,$list_ids,$table_ids,$name_from_ids,$l_pos,$r_pos,$top_frame,$left_or_right,$split_by,$name_from_ids_2,$list_ids_2,$table_ids_2,$name_from_list_ids_2) = @_ ; 
	
	my $default_left = 15 ; my $default_right = 100 ; my $text_width = 48 ; 
	
	if ($left_or_right == 1) {
		 $default_left = 110 ; $default_right = 195 ; 
	} elsif ($left_or_right == 2) {
		 $default_left = 15 ; $default_right = 195 ; $text_width = 100 ; 
	}
	
	&pdf_thin_box_block_top($default_left,$default_right,'#009bc8');
	$up = $up - 3.25 ;
	&pdf_small_bold_text ($default_left+1,$up,$name) ;
	
	my @list_ids_2 = () ; 
	@list_ids_2 = split($split_by,$list_ids_2) if $list_ids_2 ;
	
	my $cnt = 0 ; 
	foreach (split($split_by,$list_ids)) {	
		if ($db{$table_ids}{$_}{$name_from_ids_2} and not $list_ids_2[$cnt]) {
			&pdf_text_block ($r_pos,"$db{$table_ids}{$_}{$name_from_ids} ($db{$table_ids}{$_}{$name_from_ids_2})",$text_width,6) ;
		} elsif (not $db{$table_ids}{$_}{$name_from_ids_2} and not $list_ids_2[$cnt]) {
			&pdf_text_block ($r_pos,"$db{$table_ids}{$_}{$name_from_ids}",$text_width,6) ;
		} elsif ($db{$table_ids}{$_}{$name_from_ids_2} and $list_ids_2[$cnt]) {
			&pdf_text_block ($r_pos,"$db{$table_ids}{$_}{$name_from_ids} ($db{$table_ids}{$_}{$name_from_ids_2}) >>> $db{$table_ids_2}{$list_ids_2[$cnt]}{$name_from_list_ids_2}",$text_width,6) ;
		} elsif (not $db{$table_ids}{$_}{$name_from_ids_2} and $list_ids_2[$cnt]) {
			&pdf_text_block ($r_pos,"$db{$table_ids}{$_}{$name_from_ids} >>> $db{$table_ids_2}{$list_ids_2[$cnt]}{$name_from_list_ids_2}",$text_width,6) ;
		}
		$up = $up - 2 ;
		
		$cnt++ ; 
	}
	$up = $up + 2 if $list_ids ;
	$up = $up - 1.25 unless $list_ids ;
	&pdf_thin_box_block_bottom($default_left,$default_right,'#009bc8');
	&pdf_extra_thin_black_line ($l_pos,$top_frame,$l_pos,$up,'#009bc8') ;	
	
} #------------------------------------------------------------------------------------------

sub display_text {
	
	my ($left_or_right,$heading,$text) = @_ ; 
	
	my $default_left = 15 ; my $default_right = 100 ; my $text_pos = $pos2 ; my $line_pos = $pos ; 
	
	if ($heading eq "Type of System") { $text_pos++ ; $line_pos++ ; }
	
	if ($left_or_right) {
		 $default_left = 110 ; $default_right = 195 ; $text_pos = $pos4 ; $line_pos = $pos3 ; 
	} 
	
	$top = $up;
	&pdf_thin_box_block_top($default_left,$default_right,'#009bc8');
	$up = $up - 3.25 ;
	&pdf_small_bold_text ($default_left+1,$up,$heading) ;
	&pdf_small_text ($text_pos,$up,$text) ;
	$up = $up - 1.25 ;
	&pdf_thin_box_block_bottom($default_left,$default_right,'#009bc8');
	&pdf_extra_thin_black_line ($line_pos,$top,$line_pos,$up,'#009bc8') ;	
	
} #------------------------------------------------------------------------------------------

sub vertical_lines_inner_box {
	
	&pdf_thin_black_line ($blocks[1],$top,$blocks[1],$up,'#009bc8') ; # vertical
	&pdf_thin_black_line ($blocks[2],$top,$blocks[2],$up,'#009bc8') ; # vertical
	&pdf_thin_black_line ($blocks[3],$top,$blocks[3],$up,'#009bc8') ; # vertical
	&pdf_thin_black_line ($blocks[4],$top,$blocks[4],$up,'#009bc8') ; # vertical
	&pdf_thin_black_line ($blocks[5],$top,$blocks[5],$up,'#009bc8') ; # vertical	
	
} #----------------------------------------------------------------------------------------------------

sub vertical_lines_inner_box_t {
	&pdf_thin_black_line ($tblocks[1],$top,$tblocks[1],$up,'#009bc8') ; # vertical
	&pdf_thin_black_line ($tblocks[2],$top,$tblocks[2],$up,'#009bc8') ; # vertical
	&pdf_thin_black_line ($tblocks[3],$top,$tblocks[3],$up,'#009bc8') ; # vertical
	&pdf_thin_black_line ($tblocks[4],$top,$tblocks[4],$up,'#009bc8') ; # vertical
	&pdf_thin_black_line ($tblocks[5],$top,$tblocks[5],$up,'#009bc8') ; # vertical	
	
} #----------------------------------------------------------------------------------------------------

sub quote_pdf_footer {
	
	&pdf_check_value_of_up(60);
	$up = 90;
	my $txt = qq~The parties hereby accept and agree to this quote, which incorporates by reference all the terms and conditions set forth in the Interactive Television Africa's Terms and Conditions document, attached hereto as Annexure A and the Service Level Agreement attached hereto as Annexure B (all, collectively with this quote, the "Agreement") effective as of the later of the signature dates below.~;
	&pdf_text_block (10,$txt,120,3) ;
	$up = $up - 10;
	&pdf_medium_bold_text (10, $up, "Name:")  ; &pdf_thin_black_line (30,$up,100,$up,'#009bc8') ; #&pdf_tiny_text (25, $up, "________________________________________________") ;
	&pdf_medium_bold_text (110, $up, "Date:") ; &pdf_thin_black_line (130,$up,200,$up,'#009bc8') ;
	$up = $up - 5;
	&pdf_small_text (10, $up, "(Duly Authorised)") ;
	$up = $up - 10;
	&pdf_medium_bold_text (10, $up, "Company:") ;    &pdf_thin_black_line (30,$up,100,$up,'#009bc8') ;
	&pdf_medium_bold_text (110, $up, "Signature:") ; &pdf_thin_black_line (130,$up,200,$up,'#009bc8') ;
	$up = $up - 15;
	&pdf_medium_bold_text (10, $up, "Name:")  ;     &pdf_thin_black_line (30,$up,100,$up,'#009bc8') ;
	&pdf_medium_bold_text (110, $up, "Date:") ;     &pdf_thin_black_line (130,$up,200,$up,'#009bc8') ;
	$up = $up - 5;
	&pdf_small_text (10, $up, "(Duly Authorised on behalf of Interactive Television Africa)") ;
	$up = $up - 10;
	&pdf_medium_bold_text (110, $up, "Signature:") ; 
	&pdf_thin_black_line (130,$up,200,$up,'#009bc8') ;
	
} #------------------------------------------------------------------------------------------

sub quote_pdf_vars {

	# our @htxt   = (0,0,115,0,146,172,0) ;
	# our @boxtxt = (0,12,102,117,142,167) ;
	# our @blocks = (0,10,100,115,140,165) ;

	# our @rboxtxt = (0,97,122,147,172,197) ;
	# our @boxtxt  = (0,12,102,127,152,177) ;
	# our @blocks  = (0,10,100,125,150,175) ;

	our @rboxtxt  = (0,103,116,143,170,197) ;
	our @boxtxt   = (0,12,106,120,147,174) ;
	our @blocks   = (0,10,104,118,145,172) ;

	our @tboxrtxt = (0,77,107,137,167,197) ;
	our @tboxtxt  = (0,12,82,112,142,172) ;
	our @tblocks  = (0,10,80,110,140,170) ;
} #-------------------------------------------------------------------------------

sub custom_date_txt {

	my ($date) = @_ ;
	
	return "Unknown" if not $date; 
	
	my $dt_txt = Date_to_Text(substr($date,0,4),substr($date,5,2),substr($date,8,2));

	$dt_txt =  substr($dt_txt,4) ;

	return ($dt_txt) ;
} #------------------------------------------------------------------------------------------

sub check_space_on_page_custom {

	my ($value) = @_ ;

	if ($up < $value) {
		&pdf_thin_black_line (10,$top,10,$up) ; 
		&vertical_lines_table; # draw vertical_lines on prematurely ended table
		&pdf_initialise_page ;
		$up=282 ; 
		$top=$up; 
		&pdf_thin_black_line(10,$up,200,$up) ; 
		$across = 1 ;
	}
} #----------------------------------------------------------------------------------------------------
  
sub get_val {

	my ($val,$cur) = @_ ;

	my $disp_val = $val ;

	if ($val eq '0.00') { 
		$disp_val = '' ; 
	
	} elsif ($val) {
		$disp_val = $cur . ' ' . $val ;
	}
	# &common_min_debug($val);
	
	return($disp_val);
} #------------------------------------------------------------------------------------------
  
sub vertical_lines_table {

	unless ($exclude_rate) {
		&pdf_thin_black_line ($blocks[2],$top,$blocks[2],$up) ; # vertical
		&pdf_thin_black_line ($blocks[3],$top,$blocks[3],$up) ; # vertical
	}

	unless ($exclude_vat) {
		&pdf_thin_black_line ($blocks[4],$top,$blocks[4],$up) ; # vertical
	}

	&pdf_thin_black_line ($blocks[5],$top,$blocks[5],$up) ; # vertical
	&pdf_thin_black_line ($blocks[6],$top,$blocks[6],$up) ; # vertical

} #------------------------------------------------------------------------------------------
  
sub screen2 {

	print <<ENDOFTEXT;
	$dialog{'common'}{'head'}    
		<div id="content" class="col-lg-12 col-sm-12">                       
			<CENTER>
			<table height='100%' width='100%'>
			<tr>
				<td align='center'>
					<iframe src='$useropts{'$domain'}/pdf/event_details/$pdfname' width='100%' height='100%' frameborder='0'></iframe>
				</td>
			</tr>
			</table>    
		</div>
	</body>
	</html>
ENDOFTEXT
#

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

use db ;
use db_min ;
use dialog ;
use today ;
use common ;
use pdf ;
use tabs ;

1;