#!/usr/bin/perl BEGIN { use lib '/usr/home/cfg' ; require push_inc ; } require cfg ; #--------------------------------------------------------------------------------------------------------------------------------------------------------------------- use CGI::Carp qw(fatalsToBrowser); use CGI; use Time::Piece ; &today; #--------------------------------------------------------------------------------------------------------------------------------------------------------------------- @ARGV = split(/\\*\&/, $ENV{'QUERY_STRING'}); $action = $ARGV[0] ; our ($q) = CGI -> new() ; our $iaction = $q -> param('iaction') || $action ; our $isaved = $q -> param('isaved') || '' ; our $debug = 1 ; our $testing = 1 ; #-------- page opts -------------------------------------------------------------------------------------------------------------------------------------------------- &page_opts ; #--------------------------------------------------------------------------------------------------------------------------------------------------------------------- print "Content-type: text/html\n\n"; &common_min_action; exit; #------------------------------------------------------------------------------------------ sub validate { my $exists = 0 ; # $i{name} = &common_fix_str($i{name}) ; &db_min_ro($table,'*','','','') ; my $cost = '' ; my $seen_start = '' ; my $seen_end = '' ; my %seen_date = () ; foreach my $id (keys %{$db{$table}}) { $seen_date{$id}{valid_from} = $db{$table}{$id}{valid_from} ; $seen_date{$id}{valid_to} = $db{$table}{$id}{valid_to} ; $seen_date{$id}{cost} = $db{$table}{$id}{cost} ; } foreach my $id2 (keys %seen_date) { if (&common_min_greater_date($seen_date{$id2}{valid_from},$i{valid_from}) && &common_min_greater_date($i{valid_from},$seen_date{$id2}{valid_to})) { $exists = 1 ; } if (!$exists) { if (&common_min_greater_date($seen_date{$id2}{valid_from},$i{valid_to}) && &common_min_greater_date($i{valid_to},$seen_date{$id2}{valid_to})) { $exists = 1 ; } if (!$exists) { if (&common_min_greater_date($i{valid_from},$seen_date{$id2}{valid_from}) && &common_min_greater_date($seen_date{$id2}{valid_to},$i{valid_to})) { $exists = 1 ; } if (!$exists) { if (&common_min_greater_date($seen_date{$id2}{valid_from},$i{valid_from}) && &common_min_greater_date($i{valid_to},$seen_date{$id2}{valid_to})) { $exists = 1 ; } } } } if ($exists) { $cost = $seen_date{$id2}{cost} ; $seen_start = $seen_date{$id2}{valid_from} ; $seen_end = $seen_date{$id2}{valid_to} ; last ; } } if ($exists) { $alert = &common_min_alert('warning',"YOUR DATE RANGE OVERLAPS WITH THE COST $cost FROM $seen_start TO $seen_end!!!",'ok') ; %col_name = () ; &common_min_error_screen ; &common_min_screen1 ; } } #------------------------------------------------------------------------------------------ sub insert { &add_db_fields ; $i{id} = &db_min_get_max($table,'id') ; &db_min_insert($table) ; } #------------------------------------------------------------------------------------------ sub update { unless ($i{id}) { $error = qq(NO ID) ; return ; } &edit_db_fields ; &db_min_upd($table,"id='$i{id}'") ; } #------------------------------------------------------------------------------------------ sub list_screen { # &db_min_ro('event_systems','*',"(`system_type` = 'solo' OR `system_type` = 'mobile' OR `description` lIKE 'cricket%')",'','') ; &db_min_ro($table,'*','','','') ; foreach my $id (keys %{$db{$table}}) { $cost_dates{$id}{valid_from} = $db{$table}{$id}{valid_from} ; $cost_dates{$id}{valid_from} =~ s/\-//g ; $cost_dates{$id}{valid_to} = $db{$table}{$id}{valid_to} ; $cost_dates{$id}{valid_to} =~ s/\-//g ; } &db_min_ro('event_quotes',"id,date_from,date_to,logistics_shipment_operator_id","logistics_shipment_operator_id IS NOT NULL AND logistics_shipment_operator_id != '-'",'','') ; foreach my $id (keys %{$db{event_quotes}}) { my @operators = split(/\-/,$db{event_quotes}{$id}{logistics_shipment_operator_id}) ; my $date_from = substr($db{event_quotes}{$id}{date_from},0,10) ; $date_from =~ s/\-//g ; my $date_to = substr($db{event_quotes}{$id}{date_to},0,10) ; $date_to =~ s/\-//g ; foreach my $id2 (keys %cost_dates) { if ($operators[0] && $cost_dates{$id2}{valid_from} <= $date_from && $date_from <= $cost_dates{$id2}{valid_to}) { $cost_id_used{$id2} = 1 ; } if (!$cost_id_used{$id2} && $operators[1] && $cost_dates{$id2}{valid_from} <= $date_to && $date_to <= $cost_dates{$id2}{valid_to}) { $cost_id_used{$id2} = 1 ; } } } # local @system_name_ids = split(/\;/,$db{$table}{$id}{event_system_id_multiple}) ; # my $cnt = 0 ; # foreach my $event_sys_id (@system_name_ids) { # next unless $event_sys_id ; # next unless $db{event_systems}{$event_sys_id}{system_type} ; # $cnt++ ; # } # next unless $cnt ; # } our @months = ("","Jan","Feb","Mar","Apr","May","Jun","Jul","Aug","Sep","Oct","Nov","Dec") ; foreach my $id (keys %{$db{$table}}) { my $edit_butt = qq~ ~ ; my $del_butt = qq~ ~ ; if ($glod_user_level >= 3) { $edit_butt = qq~ ~ ; } if ($glod_user_level >= 3) { $del_butt = qq~ ~ ; } if ($cost_id_used{$id}) { # $edit_butt = qq~ ~ ; $del_butt = qq~ ~ ; } my $valid_from = &common_min_date_as_string($db{$table}{$id}{valid_from}) ; my $valid_to = &common_min_date_as_string($db{$table}{$id}{valid_to}) ; $print_tbody .= qq~