alarm trigger fix, warning_state concept

This commit is contained in:
ragu 2023-01-25 07:25:12 +01:00
parent b63e00e982
commit 38a72a3eed
11 changed files with 77 additions and 49 deletions

View file

@ -665,7 +665,7 @@ elsif($q->param('request') eq "stations_available"){
$user_agent_subversion = $3 if($user_agent =~ /3\.0\.(\d+)/);
#for tests only contributors with service-tour defined
if($user_agent_subversion <= 348 && $authraw->{txt18} && $authraw->{c_id} =~ /$dbt->{copri_conf}->{contributors}/){
if($user_agent_subversion <= 398 && $authraw->{txt18} && $authraw->{c_id} =~ /$dbt->{copri_conf}->{contributors}/){
my $pref_ctu = {
table => "contentuser",
fetch => "one",
@ -675,7 +675,8 @@ elsif($q->param('request') eq "stations_available"){
$uadr = $dbt->fetch_tablerecord($dbh,$pref_ctu);
$response->{merchant_message} = $uadr->{txt01};
$response->{merchant_message} = $uadr->{txt02} if($q->param('lang') eq "en");
#$response->{merchant_message} .= " ($user_agent)";
$response->{merchant_message} .= "\n\nWill be disabled --> debug contributor App version ($user_agent)";
$response->{merchant_message} .= "\n\nWill be disabled --> debug contributor user_device (" . $q->param('user_device') . ")";
}
$response = { %$response, %$auth };

View file

@ -75,7 +75,7 @@ print<<EOF
</script>
EOF
;
print $q->div({-id=>'retm'},"$feedb->{message} $debug"),"\n" if($feedb->{message} && $feedb->{message} =~ /[a-z]/);
print $q->div({-id=>'retm'},"$feedb->{message} $debug"),"\n" if($feedb->{message} && $feedb->{message} =~ /[a-z]/ && $feedb->{message} !~ /failure::/);
print $q->div({-id=>'retm'},"$node_meta->{node_name} angelegt $debug"),"\n" if($feedb->{i_rows});
print $q->div({-id=>'retm'},"$node_meta->{node_name} aktualisiert $debug"),"\n" if($feedb->{u_rows});
print $q->div({-id=>'retm'},"$node_meta->{node_name} gelöscht $debug"),"\n" if($feedb->{d_rows});

View file

@ -1187,13 +1187,16 @@ sub collect_theftpos {
my $where = "where 1=1";
foreach my $key (keys (%$search)){
$search->{$key} =~ s/\s//g;
if($search->{$key} =~ /::/ && $key =~ /int\d+/){
$search->{$key} =~ s/\s//g;
my $op = "=";
my $value = $search->{$key};
($op, $value) = split(/::/, $search->{$key});
$where .= " and $key $op $value";
}elsif($key eq "speedORmeter"){
$where .= " and $search->{$key}";
}else{
$search->{$key} =~ s/\s//g;
$where .= " and cp.c_id = $search->{$key}" if($key eq "cttpos_id" && $search->{$key});
$where .= " and cp.end_time >= '$search->{$key}'" if($key eq "start_date_time");
$where .= " and cp.end_time <= '$search->{$key}'" if($key eq "end_date_time");

View file

@ -725,7 +725,7 @@ sub payone_capture(){
my $topdf = "$varenv->{basedir}/src/wkhtmltopdf-amd64";
my $exit_code = 1;
my $print_return = "";
$print_return = `$topdf --page-size A4 "$varenv->{wwwhost}/Printpreview?printer_id=PDF\&mandant_main_id=$mandant_id\&main_id=$main_id\&ct_name2print=$ctt->{ct_name}\&c_id4trans=$ctt->{c_id}\&u_id=$owner\&pkey=$apikeyconf{pdfprinter}->{pkey}" $varenv->{pdf}/$praefix-$ctt->{ct_name}.pdf 2>&1`;
$print_return = `$topdf --page-size A4 "$varenv->{wwwhost}/Printpreview?printer_id=PDF\&mandant_main_id=$mandant_id\&main_id=$main_id\&ct_name2print=$ctt->{ct_name}\&c_id4trans=$ctt->{c_id}\&u_id=$owner\&pkey=$apikeyconf{pdfprinter}->{pkey}" "$varenv->{pdf}/$praefix-$ctt->{ct_name}.pdf" 2>&1`;
$exit_code = $?;
sleep 2;

View file

@ -140,7 +140,24 @@ sub save_text2contenttrans {
my $valxx = $q->escapeHTML("$val");
my @val = $q->param($_);
$valxx = $q->escapeHTML("@val");
if($_ =~ /txt|int|state|time/){
#Set formular title if Mahnung
if($_ eq "int06"){
my $s_hash = {};
$s_hash = $dbt->{shareedms_conf}->{warning_state};
if($valxx > 0){
foreach my $s_key (sort keys (%{ $s_hash })) {
if($valxx eq $s_key){
$update_ctt->{txt00} = $s_hash->{$s_key} if($s_hash->{$s_key} =~ /Mahnung/);
$update_ctt->{$_} = "$valxx";
}
}
}else{
$update_ctt->{txt00} = "Rechnung";
$update_ctt->{$_} = "$valxx";
}
}
elsif($_ =~ /txt|int|state|time/){
$update_ctt->{$_} = "$valxx";
}
}

View file

@ -684,7 +684,7 @@ sub preinit(){
if("$R::printer_id" =~ /PDF/){
#without system() because we have to wait until PDF is ready
$print_return = `$topdf --page-size $psize "$varenv{wwwhost}$script/Printpreview?printer_id=$R::printer_id\&mandant_main_id=$mandant_main_id\&main_id=$node->{main_id}\&ct_name2print=$ctt->{ct_name}\&c_id4trans=$c_id4print\&u_id=$users_dms->{u_id}\&pkey=$apikeyconf{pdfprinter}->{pkey}" $varenv{pdf}/$praefix-$ctt->{ct_name}.pdf 2>&1`;
$print_return = `$topdf --page-size $psize "$varenv{wwwhost}$script/Printpreview?printer_id=$R::printer_id\&mandant_main_id=$mandant_main_id\&main_id=$node->{main_id}\&ct_name2print=$ctt->{ct_name}\&c_id4trans=$c_id4print\&u_id=$users_dms->{u_id}\&pkey=$apikeyconf{pdfprinter}->{pkey}" "$varenv{pdf}/$praefix-$ctt->{ct_name}.pdf" 2>&1`;
$exit_code = $?;
if(1==1){#debugging
@ -697,11 +697,9 @@ sub preinit(){
if($R::set_state ne "buchen"){#no redirect if buchen incl. print_pdf
if( -f "$varenv{basedir}/pdf/$praefix-$ctt->{ct_name}.pdf"){
#print redirect("$varenv{wwwhost}/pdf/$praefix-$ctt->{ct_name}.pdf");
#exit 0;
print "<script type=\"text/javascript\">window.open('$varenv{wwwhost}$script/pdf/$praefix-$ctt->{ct_name}.pdf');</script>";
print "<script type=\"text/javascript\">window.open('$varenv{wwwhost}/FileOut?file=$praefix-$ctt->{ct_name}.pdf');</script>";
}else{
return "failure::PDF konnte nicht generiert werden, bitte Info an: info\@gnu-systems.de\n $varenv{wwwhost}/pdf/$praefix-$ctt->{ct_name}.pdf";
return "failure::PDF konnte nicht generiert werden, bitte Info an: admin\@sharee.bike\n $varenv{wwwhost}/pdf/$praefix-$ctt->{ct_name}.pdf";
}
}

View file

@ -153,7 +153,7 @@ EOF
print $but->singlesubmit3("ct_trans","set_workflow2invoice","","",""),"\n";
print $q->hidden(-name=>'set_main_id4workflow', -override=>'1', -value=>"300008"), "\n";
}
if($ctt->{ct_name} =~ /\d+/ && $ctt->{txt00} eq "Rechnung" && $ctt->{int10} != 2){#only for client invoice
if($ctt->{ct_name} =~ /\d+/ && $ctt->{txt00} =~ /Rechnung|Mahnung/ && $ctt->{int10} != 2){#only for client invoice
print $but->singlesubmit3("ct_trans","set_workflow2storno","","",""), "\n";
print $q->hidden(-name=>'set_main_id4workflow', -override=>'1', -value=>"300009"), "\n";
}
@ -362,20 +362,34 @@ EOF
print $q->hidden(-name=>'set_main_id', -override=>'1', -value=>"$set_main_id"),"\n";
#Text save area
print "<tr><td colspan='5' style='font-size:1.1em;padding-top:1em;'>\n";
print "<tr><td colspan='5' style='font-size:1.1em;border:1px dashed silver;'>\n";
print $q->start_table({-class=>'list', -border=>'0', -width=>'100%',-align=>'left', -cellpadding=>'0', -cellspacing=>'0'}),"\n";
my @s_valxx = ("");
my $s_hash = {};
$s_hash = $dbt->{shareedms_conf}->{warning_state};
foreach my $s_key (sort keys (%{ $s_hash })) {
push @s_valxx, "$s_key:($s_key) $s_hash->{$s_key}";
}
my @_warningstate = ("","1","2","3","4","5");
print $q->Tr(),"\n";
print $q->td({-class=>'tdval5',-colspan=>"1"},$q->span({-style=>'font-weight:bold;'},"Internas und Bearbeitungstatus")),"\n";
print $q->td({-class=>'tdval5',-colspan=>"1"},"Mahnstatus",$but->selector("int06","30px",$ctt->{int06},@_warningstate)),"\n";
if($ctt->{txt00} eq "Storno"){
print $q->td({-class=>'tdval5',-colspan=>"1"},""),"\n";
}else{
print $q->td({-class=>'tdval5',-colspan=>"1"},"Mahnstufe",$but->selector_class("int06","","",$ctt->{int06},@s_valxx)),"\n";
}
print $q->td({-class=>'tdval5',-colspan=>"2"},$q->span({-style=>'font-weight:bold;'},"PDF Formular Text "),$q->span({-style=>'color:silver;font-weight:normal;'}," ( für den Kunden sichtbar )")),"\n";
if($dbt->{shareedms_conf}->{order_state}){
print $q->Tr(),"\n";
my @_orderstate = split(/\|/,$dbt->{shareedms_conf}->{order_state});
print $q->td({-class=>'tdval5',-colspan=>1},$but->selector("txt22","180px",$ctt->{txt22},@_orderstate)),"\n";
if($ctt->{txt00} eq "Storno"){
print $q->td({-class=>'tdval5',-colspan=>"1"},""),"\n";
}else{
print $q->td({-class=>'tdval5',-colspan=>1},"Fälligkeit",$q->textfield(-id=>'datepicker3',-class=>'etxt',-name=>"warn_time",-default=>"$warn_time",-override=>1,-size=>"8",-maxlength=>10)),"\n";
}
}
$ctt->{txt23} = $q->unescapeHTML("$ctt->{txt23}") if($ctt->{txt23});

View file

@ -222,8 +222,9 @@ sub tpl(){
if(!$R::theft_details){
$search->{int10} = "IN::(7,8)";
$search->{int03} = ">::$dbt->{copri_conf}->{theftalarm}->{move_count}";#move count
$search->{int07} = ">::$dbt->{copri_conf}->{theftalarm}->{speed}";#speed
$search->{int08} = ">::$dbt->{copri_conf}->{theftalarm}->{meter}";#meter
#$search->{int07} = ">::$dbt->{copri_conf}->{theftalarm}->{speed}";#speed
#$search->{int08} = ">::$dbt->{copri_conf}->{theftalarm}->{meter}";#meter
$search->{speedORmeter} = "(cp.int07 > $dbt->{copri_conf}->{theftalarm}->{speed} OR cp.int08 > $dbt->{copri_conf}->{theftalarm}->{meter})";
}
$cttpos = $dbt->collect_theftpos($dbh,$search);
}

View file

@ -809,10 +809,6 @@ sub tpl(){
$set_style = "background-color:#d39c9c;" if($sum_error && $sum_error == 1 && $node_meta->{node_name} eq "Faktura");
$set_style4nr = $set_style;
my $m_id;
my $nodeline2;
my $nodeline_name2;
my $nodelist;
#Instanz Buttons-Logic
print $q->Tr(),"\n";
@ -876,7 +872,7 @@ sub tpl(){
$search_key = "s_int04=$ct4rel->{$id}->{int04}" if($ct4rel->{$id}->{template_id} == 225);#station
print $q->td({-class=>'tdtxt',-colspan=>1,-style=>"$set_style", -nowrap=>1}, $q->a({-class=>"editnav",-href=>"$path/$node_names?detail_search=1\&$search_key",-title=>"zur Liste der Rad $ct4rel->{$id}->{barcode} Servicearbeiten $ct4rel->{$id}->{main_id}"},"$node_names")), "\n";
}else{
print $q->td({-class=>'tdtxt',-colspan=>1,-style=>"$set_style", -nowrap=>1},"$node_names"),"\n";
print $q->td({-class=>'tdtxt',-colspan=>1,-style=>"$set_style", -nowrap=>1},"$ct4rel->{$id}->{txt00}"),"\n";
}
}else{
$ecol++;

View file

@ -199,12 +199,14 @@ EOF
#max. Rechnungspositionen
if(1==1){
$i++;
if($i==1){
if($ctt->{ct_name} =~ /^\d+$/){
if($i==1){
$accounting_end = "$3.$2.$1" if($cttpos->{$id}->{itime} =~ /(\d+)\-(\d+)\-(\d+)/);
$accounting_end = "$3.$2.$1" if($cttpos->{$id}->{end_time} =~ /(\d+)\-(\d+)\-(\d+)/);
$accounting_start = $accounting_end;
}else{
}else{
$accounting_start = "$3.$2.$1" if($cttpos->{$id}->{itime} =~ /(\d+)\-(\d+)\-(\d+)/);
}
}
#print "$accounting_start - $accounting_end<br>";

View file

@ -26,22 +26,15 @@ use lib "/var/www/copri-bike/$syshost/src";
use strict;
use warnings;
use POSIX;
use CGI;
use Lib::Config;
use JSON;
use LWP::UserAgent;
use DateTime;
use Time::Piece;
my $cf = new Config;
use Mod::DBtank;
use Data::Dumper;
my $q = new CGI;
my $dbt = new DBtank;
my %varenv = $cf->envonline($syshost);
my $lang = "de";
my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
my $api_file = "/var/www/copri4/shareeconf/apikeys.cfg";
@ -60,7 +53,7 @@ my $todo = $ARGV[1];
my $groupId = $ARGV[2] || "";
my $deviceId = $ARGV[3] || "";
open(FILE,">>$varenv{logdir}/Ilockit_cloud.log");
open(FILE,">>$dbt->{copri_conf}->{logdir}/Ilockit_cloud.log");
print FILE "\n\n*** $now_dt\n";
#2022-11-08 looping and rest changed to groupId and limit (max 10000)
@ -74,26 +67,26 @@ print FILE "\n\n*** $now_dt\n";
#main
#loop operators DB
while (my ($key, $value) = each %{ $dbt->{operator} }) {
if($value->{database}->{dbname} && $value->{hwtype} ne "sigo"){
print FILE "\nON----------$value->{database}->{dbname}---$now_dt | $todo\n";
while (my ($key, $op_name) = each %{ $dbt->{operator} }) {
if($op_name->{database}->{dbname} && $op_name->{hwtype} ne "sigo"){
print FILE "\nON----------$op_name->{database}->{dbname}---$now_dt | $todo\n";
my $rows = 0;
my $sharee_operator = $value->{database}->{dbname};
my $sharee_operator = $op_name->{database}->{dbname};
my $dbh = "";
$dbh = $dbt->dbconnect_extern($sharee_operator);
#per cronjob once a day to get and update content with cloud device id
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_devices"
&get_devices($dbh) if($todo eq "get_devices");
&get_devices($dbh,$op_name) if($todo eq "get_devices");
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_events 95"
if($todo eq "get_events"){
&get_events($dbh,$response_in,$value->{oprefix});
&get_positions($dbh,$value->{oprefix});
&get_events($dbh,$op_name,$response_in);
&get_positions($dbh,$op_name);
}
#sudo su www-data -c "./src/scripts/Ilockit_cloud.pl shareedms-fr01 get_positions 6572"
#&get_positions($dbh,$value->{oprefix}) if($todo eq "get_positions");
#&get_positions($dbh,$op_name->{oprefix}) if($todo eq "get_positions");
}
}
@ -210,6 +203,7 @@ sub get_devicesONcontenttheftpos {
sub get_devices {
my $dbh = shift;
my $op_name = shift;
my $endpoint = "https://tracking.ilockit.bike/api/devices";
my $rest = "";
@ -252,8 +246,8 @@ sub get_devices {
#get_events
sub get_events {
my $dbh = shift;
my $op_name = shift;
my $response_in = shift;
my $oprefix = shift || "";
#1. select all devices on content
print FILE "ilockit get_events get_devicesONcontent_all\n";
@ -284,7 +278,7 @@ sub get_events {
$theft_record = get_devicesONcontenttheftpos($dbh,"int01",$resp->{id},"");#Alarm detected
print FILE "shareeTime: $today\n";
print FILE "bike: $oprefix$record_cc->{$id}->{barcode}\n";
print FILE "bike: $op_name->{oprefix}$record_cc->{$id}->{barcode}\n";
print FILE "id: $resp->{id}\n";
print FILE "deviceId: $resp->{deviceId}\n";
print FILE "type: $resp->{type}\n";
@ -317,7 +311,8 @@ sub get_events {
end_time => "$serverTime",
};
my $c_id = $dbt->insert_contentoid($dbh,$insert);
my $c_id = 0;
$c_id = $dbt->insert_contentoid($dbh,$insert);
print FILE "insert theft_record:" . Dumper($insert);
}
}
@ -328,7 +323,7 @@ sub get_events {
sub get_positions {
my $dbh = shift;
my $oprefix = shift || "";
my $op_name = shift;
my $record_cc = get_devicesONcontent_all($dbh,"C2-04");
my $endpoint = "https://tracking.ilockit.bike/api/positions";
@ -398,7 +393,7 @@ sub get_positions {
$theftmove_count++;#count if move holds on for min 2 times
my $theft_record = get_devicesONcontenttheftpos($dbh,"int02",$resp->{id},"");#Alarm movement
print FILE "shareeTime: $today\n";
print FILE "bike: $oprefix$record_cc->{$id}->{barcode}\n";
print FILE "bike: $op_name->{oprefix}$record_cc->{$id}->{barcode}\n";
print FILE "id: $resp->{id}\n";
print FILE "deviceId: $resp->{deviceId}\n";
print FILE "serverTime: $resp->{serverTime}\n\n";
@ -424,14 +419,15 @@ sub get_positions {
end_time => "$serverTime",
};
my $c_id = $dbt->insert_contentoid($dbh,$insert);
my $c_id = 0;
$c_id = $dbt->insert_contentoid($dbh,$insert);
print FILE "insert sub get_positions:" . Dumper($insert);
#theft mailing
if($theftmove_count > $dbt->{copri_conf}->{theftalarm}->{move_count} && $resp->{speed} > $dbt->{copri_conf}->{theftalarm}->{speed} && $resp->{attributes}->{distance} > $dbt->{copri_conf}->{theftalarm}->{meter}){
if($c_id && $theftmove_count > $dbt->{copri_conf}->{theftalarm}->{move_count} && ($resp->{speed} > $dbt->{copri_conf}->{theftalarm}->{speed} || $resp->{attributes}->{distance} > $dbt->{copri_conf}->{theftalarm}->{meter})){
#send mail
system("$varenv{basedir}/src/scripts/mailTransportcms.pl '$varenv{syshost}' 'send_alarm2hotline' '1' '$c_id' ''");
print FILE "send_alarm2hotline, condition: $theftmove_count > $dbt->{copri_conf}->{theftalarm}->{move_count} && $resp->{speed} > $dbt->{copri_conf}->{theftalarm}->{speed} && $resp->{attributes}->{distance} > $dbt->{copri_conf}->{theftalarm}->{meter}\n";
system("$dbt->{copri_conf}->{basedir}/src/scripts/mailTransportcms.pl '$op_name->{syshost}' 'send_alarm2hotline' '1' '$c_id' ''");
print FILE "send_alarm2hotline, condition: c_id:$c_id && $theftmove_count > $dbt->{copri_conf}->{theftalarm}->{move_count} && ($resp->{speed} > $dbt->{copri_conf}->{theftalarm}->{speed} || $resp->{attributes}->{distance} > $dbt->{copri_conf}->{theftalarm}->{meter})\n";
}
}