aisa/scripts/quote_notes.pl

275 lines
8.4 KiB
Perl
Raw Normal View History

2025-11-26 09:31:54 +00:00
#!/usr/bin/perl
BEGIN { use lib '/usr/home/cfg' ; require push_inc ; }
use CGI::Carp qw(fatalsToBrowser);
require cfg ;
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
use CGI;
use Crypt::PasswdMD5;
&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 --------------------------------------------------------------------------------------------------------------------------------------------------
&page_opts ;
#---------------------------------------------------------------------------------------------------------------------------------------------------------------------
print "Content-type: text/html\n\n";
if ($iaction eq 'add') { unless ($username eq 'rory') { print "UNAUTHORISED" ; exit ; } }
unless ($useropts{super}{$username}) { print "UNAUTHORISED" ; exit ; }
&common_min_action;
exit;
#------------------------------------------------------------------------------------------
sub validate {
my $exists = '' ;
# &db_min_ro($table,'*',"`field_name`='$i{field_name}' AND `type`='$i{type}'",'','') ;
# foreach my $id (keys %{$db{$table}}) { if ($db{$table}{$id}{field_name} eq $i{field_name}) { $exists = 1 ; } }
# if ($exists) {
# $alert = &common_min_alert('warning',"FIELD_NAME ALREADY EXISTS!",'ok') ;
# %col_name = ();
# &common_min_add_screen;
# &common_min_screen1;
# }
} #------------------------------------------------------------------------------------------
sub insert {
&add_db_fields ;
$i{last_updated} = "$now_ccyy_mm_dd $now_hour:$now_min:$now_sec" ;
&db_min_insert($table) ;
} #------------------------------------------------------------------------------------------
sub update {
unless ($i{id}) { $error = qq(NO ID) ; return ; }
&edit_db_fields ;
# unless ($i{Active}) { $i{Active} = '0' ; }
$i{last_updated} = "$now_ccyy_mm_dd $now_hour:$now_min:$now_sec" ;
&db_min_upd($table,"`id`='$i{id}'") ;
} #------------------------------------------------------------------------------------------
sub list_screen {
&db_min_ro($table,'*','','','') ;
# id date_time last_edited_by last_updated note_1 note_2 note_3 note_4 note_5 note_6 note_7 note_8 note_9 note_10 note_11 note_12 note_13 note_14 note_15 payment_term_1 payment_term_2 payment_term_3 payment_term_4 payment_term_5 payment_term_6 payment_term_7 payment_term_8 payment_term_9 payment_term_10 payment_term_11 payment_term_12 payment_term_13 payment_term_14 payment_term_15 roe_1 roe_2 roe_3 roe_4 roe_5 roe_6 roe_7 roe_8 roe_9 roe_10 roe_11 roe_12 roe_13 roe_14 roe_15 delivery_time_1 delivery_time_2 delivery_time_3 delivery_time_4 delivery_time_5 delivery_time_6 delivery_time_7 delivery_time_8 delivery_time_9 delivery_time_10 delivery_time_11 delivery_time_12 delivery_time_13 delivery_time_14 delivery_time_15
&hidden_db_fields;
foreach my $id (keys %{$db{$table}}) {
# $print_tbody .= qq~<tr id="$id">~;
foreach my $col (keys %{$db{$table}{$id}}) {
next if $ignore{$col} || $hidden{$col} ;
next if $col eq 'id' || $col eq '' ;
next unless $db{$table}{$id}{$col} ;
# my $del_butt = qq(&nbsp;<a class="btn btn-danger btn-xs" href="javascript:deleteMinItem('$db{$table}{$id}{SupplierName}','$id')"><i class="glyphicon glyphicon-trash icon-white"></i></a>) ;
my $edit_butt = qq(&nbsp;<a class="btn btn-info btn-xs" href="javascript:editMinItem('$id');"><i class="glyphicon glyphicon-edit icon-white"></i></a>) ;
$print_tbody .= qq~<tr id="$id-$col">
<td>$col</td>
<td>$db{$table}{$id}{$col}</td>
<td nowrap>
$edit_butt
</td></tr>~ ;
}
# $print_tbody .= qq~</tr>~;
}
our $fnsortcol = -1 ;
} #------------------------------------------------------------------------------------------
sub add_db_fields {
&hidden_db_fields;
$hidden{id} = 2 ;
} #------------------------------------------------------------------------------------------
sub edit_db_fields {
&hidden_db_fields;
# $readonly{field_name} = 'READONLY' ;
# $required{field_name} = 1 ;
# $readonly{type} = 'READONLY' ;
# $required{type} = 1 ;
$hidden{id} = 1 ; # 1 = bypass for db update
} #------------------------------------------------------------------------------------------
sub hidden_db_fields {
$ignore{iaction} = 1 ;
$hidden{date_time} = 2 ;
$hidden{last_edited_by} = 2 ;
$hidden{last_updated} = 2 ;
# &sort_fields;
} #------------------------------------------------------------------------------------------
sub sort_fields {
our %sort_field = () ;
my $col_count = 15 ;
for (1 .. $col_count) {
$sort_field{$_ + 0*$col_count} = "delivery_time_$_" ;
$sort_field{$_ + 1*$col_count} = "note_$_" ;
$sort_field{$_ + 2*$col_count} = "payment_term_$_" ;
$sort_field{$_ + 3*$col_count} = "roe_$_" ;
}
for (1 .. 5){
$sort_field{$_ + 4*$col_count} = "terms_$_" ;
}
# $sort_field{1} = 'field_name' ;
# $sort_field{2} = 'type' ;
# $sort_field{3} = 'default_zar' ; $preferred_title{default_zar} = 'Default ZAR' ;
# $sort_field{4} = 'default_qty' ;
# $sort_field{5} = 'min_zar' ; $preferred_title{min_zar} = 'Min ZAR' ;
} #-------------------------------------------------------------------------------
sub add_screen {
# called from common_add_screen
&select_opts('') ;
} #------------------------------------------------------------------------------------------
sub edit_screen {
our ($lcol,$fcol) = &common_min_columns($label_col,$field_col) ;
$selected{field_name}{$db{$table}{$i{id}}{field_name}} = 'SELECTED';
# $selected{type}{$db{$table}{$i{id}}{type}} = 'SELECTED';
# load quote defaults
# &db_min_ro($table,'*','','','') ;
# foreach (keys %{$db{$table}}) {
# $defzar{$db{$table}{$_}{type}}{$db{$table}{$_}{field_name}} = $db{$table}{$_}{default_zar};
# $minzar{$db{$table}{$_}{type}}{$db{$table}{$_}{field_name}} = $db{$table}{$_}{min_zar};
# $defqty{$db{$table}{$_}{type}}{$db{$table}{$_}{field_name}} = $db{$table}{$_}{default_qty};
# }
&select_opts($i{id}) ;
&sort_fields;
# $extra_form_fields .= &common_min_form_input('new_password','','password') ;
} #------------------------------------------------------------------------------------------
sub select_opts {
my ($id) = @_ ;
# unless ($id) { # don't display dropdown on edit
# $select{field_name} = 1 ;
# $select{type} = 1 ;
# }
# $opts{type} = qq(<option $selected{type}{Inbound} value="Inbound">Inbound</option><option $selected{type}{Outbound} value="Outbound">Outbound</option>);
# $print_box_content_rows .= &common_min_form_select('field_name','','',1,'') ;
} #-------------------------------------------------------------------------------
sub clear_hashes {
%cost_desc = () ; %def_qty = () ; %def_zar = () ;
} #-------------------------------------------------------------------------------
sub view_screen {
my ($iid) = @_ ;
our ($lcol,$fcol) = &common_min_columns($label_col,$field_col) ;
foreach my $cnt (sort {$a <=> $b} keys %sort_field) {
my $col = $sort_field{$cnt} ;
if ($ignore{$col}) { next ; }
my $val = $db{$table}{$iid}{$col} ;
$print_box_content_rows .= &common_min_form_view($col,$val) ;
}
} #------------------------------------------------------------------------------------------
sub thead {
$print_thead = qq(<THEAD><TR><TH>NAME</TH><TH>VALUE</TH><TH>&nbsp;</TH></TR></THEAD>) ;
} #-------------------------------------------------------------------------------
sub page_opts {
our $glyphicon = 'qrcode' ;
our $lcpage = 'quote-note' ; # $ucpage = uc $lcpage ; # $ucfirstpage = ucfirst $lcpage ;
my @splitlcpage = split(/\-/,$lcpage) ;
my @ucfirstpage = map(ucfirst, map(lc,@splitlcpage));
$ucfirstpage = join(' ', @ucfirstpage);
$ucpage = uc $ucfirstpage ;
our $table = 'quote_notes' ;
$page_title = 'Quote Notes' ;
our $glob_sort_col = 1 ;
our $glob_sort_asc_desc = 'asc' ;
# &common_min_add_extras ;
} #-------------------------------------------------------------------------------
use tabs ;
use common ;
use today ;
1;