aisa/scripts/_FromProd/v1.0/logistics_locations.pl
2026-02-03 14:35:43 +02:00

200 lines
5.6 KiB
Perl

#!/usr/bin/perl
BEGIN { use lib '/usr/home/cfg' ; require push_inc ; }
require cfg ;
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
use CGI::Carp qw(fatalsToBrowser);
use CGI;
&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 ;
#-------- page opts --------------------------------------------------------------------------------------------------------------------------------------------------
# print ">>>>>MAINTENANCE IN PROGRESS<<<<<" ; exit ;
&page_opts ;
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
print "Content-type: text/html\n\n";
&common_min_action;
exit;
#------------------------------------------------------------------------------------------
sub validate {
my $exists = '' ;
$i{location} = &common_fix_str($i{location}) ;
&db_min_ro($table,'*',"location='$i{location}'",'location','') ;
foreach my $id (keys %{$db{$table}}) { if ($db{$table}{$id}{location} eq $i{location}) { $exists = 1 ; } }
if ($exists) {
$alert = &common_min_alert('warning',"Location ALREADY EXISTS!",'ok') ;
%col_name = ();
&common_min_add_screen;
&common_min_screen1;
}
} #------------------------------------------------------------------------------------------
sub insert {
&add_db_fields ;
&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','DISTINCT logistics_location_id',"logistics_location_id <> '0'",'','') ;
my %type_id_used = () ;
foreach my $id (keys %{$db{event_systems}}) {
# my @sups = split(/;/,$db{event_quotes}{$id}{logistics_address_ids}) ; #$db{event_quotes}{$id}{logistics_suppliers} = "4-;;;1-2;;;;-"
# foreach my $sups (@sups) {
# foreach my $sup_id (split(/-/,$sups)) {
$type_id_used{$id} = 1 ;
# }
# }
}
&db_min_ro($table,'*','','location','') ;
foreach my $id (keys %{$db{$table}}) {
my $edit_butt = '' ; my $del_butt = '' ;
if ($glod_user_level > 3) {
$edit_butt = qq~&nbsp;<a class="btn btn-info btn-xs" href="javascript:editMinItem('$db{$table}{$id}{id}');"><i class="glyphicon glyphicon-edit icon-white"></i></a>~ ;
}
if ($glod_user_level > 4) {
$del_butt = qq~&nbsp;<a class="btn btn-danger btn-xs" href="javascript:deleteMinItem('$db{$table}{$id}{name}','$db{$table}{$id}{id}')"><i class="glyphicon glyphicon-trash icon-white"></i></a>~ ;
}
if ($type_id_used{$id}) {
$edit_butt = qq~&nbsp;<a class="btn btn-default btn-xs" href="#" title="In system use!" data-toggle="tooltip"><i class="glyphicon glyphicon-edit icon-white"></i></a>~ ;
$del_butt = qq~&nbsp;<a class="btn btn-default btn-xs" href="#" title="In system use!" data-toggle="tooltip"><i class="glyphicon glyphicon-trash icon-white"></i></a>~ ;
}
$print_tbody .= qq~<tr id="$id">
<td>$id</td>
<td>$db{$table}{$id}{location}</td>
<td nowrap>
$edit_butt
$del_butt
</td>
</tr>~ ;
}
} #------------------------------------------------------------------------------------------
sub add_db_fields {
&sort_fields;
&hidden_db_fields;
$ignore{id} = 1 ;
} #------------------------------------------------------------------------------------------
sub edit_db_fields {
&sort_fields;
&hidden_db_fields;
$hidden{id} = 1 ; # 1 = bypass for db update
} #------------------------------------------------------------------------------------------
sub hidden_db_fields {
$ignore{iaction} = 1 ;
$required{location} = 1 ;
} #------------------------------------------------------------------------------------------
sub sort_fields {
%sort_field = () ;
$sort_field{1} = 'location' ;
} #-------------------------------------------------------------------------------
sub add_screen {
# called from common_add_screen
&select_opts ;
} #------------------------------------------------------------------------------------------
sub edit_screen {
&select_opts ;
} #------------------------------------------------------------------------------------------
sub select_opts {
# $required{based_in} = 1 ;
# $select{based_in} = 1 ;
# $opts{based_in} = qq~<option value="JNB" $selected{based_in}{'JNB'}>Johannesburg</option><option value="CPT" $selected{based_in}{'CPT'}>Cape Town</option>~ ;
} #------------------------------------------------------------------------------------------
sub thead {
$print_thead = qq~<THEAD><TR><TH>ID</TH><TH>LOCATION</TH><TH>&nbsp;</TH></TR></THEAD>~ ;
} #-------------------------------------------------------------------------------
sub page_opts {
our $glyphicon = 'list' ;
our $lcpage = 'logistics-location' ; $ucpage = uc $lcpage ; $ucfirstpage = ucfirst $lcpage ;
our $page_title = 'Logistics Locations' ;
our $table = 'logistics_locations' ;
&common_min_add_extras ;
} #-------------------------------------------------------------------------------
use common ;
use today ;
1;