#!/usr/bin/perl BEGIN { use lib '/usr/home/cfg' ; require push_inc ; } require cfg ; #--------------------------------------------------------------------------------------------------------------------------------------------------------------------- use CGI::Carp qw(fatalsToBrowser); use DBI; use CGI; use POSIX; # unless ($username eq 'rory') { print "<<<<<<<<<<<<<<<< MAINTENANCE IN PROGRESS >>>>>>>>>>>>>>>" ; exit ; } #--------------------------------------------------------------------------------------------------------------------------------------------------------------------- our ($q) = CGI -> new() ; $iaction = $q -> param('iaction') || '' ; $iall = $q -> param('iall') || '' ; $iboth = $q -> param('iboth') || '' ; $isaved = $q -> param('isaved') || '' ; #--------------------------------------------------------------------------------------------------------------------------------------------------------------------- print "Content-type: text/html\n\n"; &today; if ($iaction eq ''){ &base_screen ; } if ($iaction eq 'edit'){ &common_load_params ; &get_storage_list ; &edit_screen ; &screen1; } if ($iaction eq 'save'){ &common_load_params ; &process_storage_for_save ; $savetype = "SAVED" ; $viewsaved = 0 ; &screen2; } if ($iaction eq 'update'){ &common_load_params ; &check_update_storage ; &update_storage(1) ; $savetype = "UPDATED" ; &screen2; } if ($iaction eq 'delete'){ &common_load_params ; &delete_storage ; $savetype = "DELETED" ; $viewsaved = 1 ; &screen2; } exit; #------------------------------------------------------------------------------------------ sub process_storage_for_save { @input_array = $q -> param('input_array'); our $batchno = &db_get_max_storage_batch_no ; foreach (@input_array) { $at_least_one_input = 1 ; if ($i{storageid}{$_}){ &update_storage($_) ; } else { &insert_storage ; } } unless ($at_least_one_input) { $error = qq(NOTHING SELECTED); &base_screen ; } } #------------------------------------------------------------------------------------------ sub delete_storage { unless ($i{storageid}) { return ; } &db_open_upd ; $sql = qq(DELETE FROM storage WHERE ID = "$i{storageid}" AND HAWB = "$i{hawb}") ; &common_debug($sql) ; $sth = $dbh -> do ($sql) or die "could not execute :
$sql
$!" ; &db_close_conn ; } #------------------------------------------------------------------------------------------ sub check_update_storage { $input = $q -> param('input_array'); unless ($input) { $error = qq(NOTHING SELECTED); &base_screen ; return ; } $viewsaved = 0 ; if (($i{dateout}{1}) and ($i{storageid}{1}) and ($i{waybillno}{1})) { $viewsaved = 1 ; } } #------------------------------------------------------------------------------------------ sub update_storage { my ($field) = @_ ; unless ($i{storageid}{$field}) { return ; } &db_open_upd ; $sql = qq(UPDATE storage SET DateOut = "$i{dateout}{$field}", Remarks = "$i{remarks}{$field}" WHERE ID = "$i{storageid}{$field}" AND HAWB = "$i{waybillno}{$field}") ; &common_debug($sql) ; $sth = $dbh -> do ($sql) or die "could not execute :
$sql
$!" ; &db_close_conn ; } #------------------------------------------------------------------------------------------ sub insert_storage { &db_open_upd ; $sql = qq(INSERT INTO storage (ID,BatchNo,DateCreated,HAWB,DateOut,Remarks) VALUES ("","$batchno","$now_ccyy_mm_dd","$i{waybillno}{$_}","$i{dateout}{$_}","$i{remarks}{$_}");) ; &common_debug($sql) ; $sth = $dbh -> do ($sql) or die "could not execute :
$sql
$!" ; &db_close_conn ; } #------------------------------------------------------------------------------------------ sub db_get_max_storage_batch_no { &db_open_ro ; my $sql = qq(SELECT BatchNo FROM storage ORDER BY BatchNo DESC LIMIT 1) ; my $sth = $dbh->prepare($sql) ; $sth -> execute() or die "Could not execute SQL statement $sql ... maybe invalid? $!"; my $max_batch_no_array_ref = $sth->fetchall_arrayref(); $sth->finish(); &db_close_conn ; my $new_batchno = 1 ; foreach $row (@$max_batch_no_array_ref) { $batchno = @$row[0] ; $new_batchno = $batchno ; $new_batchno++ ; } return ($new_batchno) ; } #------------------------------------------------------------------------------------------ sub get_storage_list { if ($iall) { &db_load_all_parcels ; &get_db_storage_list(1) ; } elsif ($iboth) { &db_load_all_parcels ; &get_db_storage_list(3) ; &get_db_waybill_storage_list ; } else { &db_load_all_parcels ; &get_db_storage_list(2) ; &get_db_waybill_storage_list ; } } #------------------------------------------------------------------------------------------ sub get_db_waybill_storage_list { &db_open_ro ; my $sql = qq(SELECT * FROM waybills WHERE OthSvc1 = 'Storage') ; # my $sql = qq(SELECT * FROM waybills WHERE OthSvc1 = 'Packaging') ; my $sth = $dbh->prepare($sql) ; $sth -> execute() or die "Could not execute SQL statement $sql ... maybe invalid? $!"; my $id_array_ref = $sth->fetchall_arrayref(); $sth->finish(); &db_close_conn ; foreach $row (@$id_array_ref) { &db_waybills_fields ; if ($storage{$wb{waybillno}}{$wb{storageno}}) { next ; } my $checked = '' ; if ($i{hawb}) { unless ($i{hawb} eq $wb{waybillno}) { next ; } $checked = 'CHECKED' ; } $r++ ; if ($i{id}{$wb{waybillno}}) { $hidden_fields_edit = qq() ; } else { $hidden_fields_edit = '' ; } my $invno = sprintf("%.0f",($wb{'invno'})) ; $print_contents = '' ; if ($contents{$wb{waybillno}}){ &db_package_parcels($wb{waybillno}) ; } if ($wb{volmass} > $wb{actmass}) { $chgmass = ceil($wb{volmass}); } else { $chgmass = ceil($wb{actmass}); } my $view_wb_link = qq(dlgMdl('$useropts{scripts}/dialog/view_waybill.pl?$wb{waybillno}','HAWB $wb{waybillno} : $wb{client} : $wb{coldate}','','max-dialog');) ; $tbody .= qq($wb{coldate}$wb{waybillno}$wb{origin}$wb{client}$print_contents$wb{pcs}$chgmass) ; my $dateout = qq(
) ; $tbody .= qq($dateout$invno$hidden_fields_edit) ; } } #------------------------------------------------------------------------------------------ sub get_db_storage_list { my ($type) = @_ ; &db_open_ro ; my $sql = qq(SELECT storage.*,waybills.client,waybills.invno,waybills.coldate,waybills.origin,waybills.pcs,waybills.volmass,waybills.actmass,waybills.othsvc1 FROM storage,waybills WHERE waybills.waybillno = storage.hawb LIMIT 1000) ; my $sth = $dbh->prepare($sql) ; $sth -> execute() or die "Could not execute SQL statement $sql ... maybe invalid? $!"; my $id_array_ref = $sth->fetchall_arrayref(); $sth->finish(); &db_close_conn ; foreach $row (@$id_array_ref) { &db_storage_fields ; $wb{client} = @$row[6] ; $wb{invno} = @$row[7] ; $wb{coldate} = @$row[8] ; $wb{origin} = @$row[9] ; $wb{pcs} = @$row[10] ; $wb{volmass} = @$row[11] ; $wb{actmass} = @$row[12] ; $wb{othsvc1} = @$row[13] ; if (&edit_ifields($st{hawb})) { next ; } if (($i{hawb}) and ($iaction eq 'edit')) { next ; } if ($type == 2) { $storage{$st{hawb}}{$st{othsvc1}} = 1 ; next ; } if ($type == 3) { next ; } my $invno = sprintf("%.0f",($wb{invno})) ; $print_contents = '' ; if ($contents{$wb{waybillno}}){ &db_package_parcels($wb{waybillno}) ; } if ($wb{volmass} > $wb{actmass}) { $chgmass = ceil($wb{volmass}); } else { $chgmass = ceil($wb{actmass}); } my $view_wb_link = qq(dlgMdl('$useropts{scripts}/dialog/view_waybill.pl?$st{hawb}','HAWB $st{hawb} : $wb{client} : $wb{coldate}','','max-dialog');) ; $tbody .= qq($wb{coldate}$st{hawb}$wb{origin}$wb{client}$print_contents$wb{pcs}$chgmass) ; $tbody .= qq($st{dateout}$invno$st{remarks}) ; #   } } #------------------------------------------------------------------------------------------ sub edit_ifields { my ($hawb) = @_ ; $i{id}{$hawb} = $st{id} ; $i{batchno}{$hawb} = $st{batchno} ; $i{dateout}{$hawb} = $st{dateout} ; $i{remarks}{$hawb} = $st{remarks} ; ; my $incomplete = '' ; foreach my $p (keys %i) { $i{$p}{$hawb} =~ s/0000-00-00//g ; unless ($i{$p}{$hawb}) { $incomplete = 1 ;} } return($incomplete) ; } #------------------------------------------------------------------------------------------ sub base_screen { &get_storage_list; &save_screen; &screen1; } #------------------------------------------------------------------------------------------ sub save_screen { $hidden_action = 'save' ; } #------------------------------------------------------------------------------------------ sub edit_screen { $hidden_action = 'update' ; } #------------------------------------------------------------------------------------------ sub screen1 { if ($error) { $alert = qq() ; } if ($isaved) { $alert = qq() ; } my $allbutt = qq( All) ; my $incbutt = qq( Incomplete) ; my $combutt = qq( Completed) ; if ($iall) { $table_title = qq(: Complete) ; $view_butt = qq($incbutt $allbutt); } elsif ($iboth) { $table_title = qq(: All) ; $view_butt = qq($combutt $incbutt); } elsif ($iaction eq 'edit') { $table_title = qq(: Edit) ; $view_butt = qq($combutt $incbutt); } else { $table_title = qq(: Incomplete); $view_butt = qq($combutt $allbutt); } $print_buttons = qq(
 
 
) ; $trigger_jquery_raw .= qq(\$('#storagelist').dataTable({ "iDisplayLength": -1, "aLengthMenu": [[25, 50, 100, -1], [25, 50, 100, "All"]], "sDom": "<'row'<'col-md-6'l><'col-md-6'f>r>t<'row'<'col-md-12'i><'col-md-12 center-block'p>>", "sPaginationType": "bootstrap", "oLanguage": { "sLengthMenu": "_MENU_ records per page" } }); ) ; require st_list ; exit ; } #------------------------------------------------------------------------------------------ sub screen2 { print < Film Freight Admin
ENDOFTEXT # exit ; } #------------------------------------------------------------------------------------------ use db ; use today ; use common ; 1;