2021-12-30 12:05:56 +01:00
package Prelib ;
#
# SPDX-License-Identifier: AGPL-3.0-or-later
# Copyright (c) Rainer Gümpelein, TeilRad GmbH
#
#migrate some methodes form Prelogic and Premain to here
#defined methodes are available for web-app and backend
use strict ;
use warnings ;
use POSIX ;
use File::Path qw( make_path remove_tree ) ;
use CGI ':standard' ;
use CGI::Carp qw( fatalsToBrowser ) ;
use Scalar::Util qw( looks_like_number ) ;
2022-06-02 10:34:03 +02:00
use DateTime ;
use DateTime::Format::Pg ;
2023-03-05 20:01:47 +01:00
use Text::CSV_XS ;
2021-12-30 12:05:56 +01:00
use Lib::Config ;
use Mod::Libenz ;
use Mod::DBtank ;
use Mod::Basework ;
2022-06-02 10:34:03 +02:00
use Mod::Pricing ;
2022-06-24 14:38:22 +02:00
use Mod::APIsigclient ;
2021-12-30 12:05:56 +01:00
use Data::Dumper ;
my $ cf = new Config ;
my $ lb = new Libenz ;
my $ dbt = new DBtank ;
my $ bw = new Basework ;
2022-06-02 10:34:03 +02:00
my $ pri = new Pricing ;
2022-06-24 14:38:22 +02:00
my $ si = new APIsigclient ;
2021-12-30 12:05:56 +01:00
sub new {
my $ class = shift ;
my $ self = { } ;
bless ( $ self , $ class ) ;
return $ self ;
}
my $ i_rows = 0 ;
my $ u_rows = 0 ;
my $ d_rows = 0 ;
my $ lang = "de" ;
my % varenv = $ cf - > envonline ( ) ;
my $ now_dt = strftime "%Y-%m-%d %H:%M:%S" , localtime ;
my $ debug = 1 ;
2023-10-06 06:48:36 +02:00
#payment-type prepaid request
sub prepaid_request {
my $ self = shift ;
my $ dbh = shift ;
my $ ctadr = shift ;
my $ owner = shift ;
my $ feedb = {
u_rows = > 0 ,
prepaid_account = > "" ,
prepaid_id = > 0 ,
message = > "" ,
} ;
my $ pref_ctt = {
table = > "contenttrans" ,
fetch = > "one" ,
main_id = > 300023 ,
template_id = > 219 , #prepaid tpl
ca_id = > "$ctadr->{c_id}" ,
state = > "is::null" ,
close_time = > "is::null" ,
} ;
my $ ctt_prepaid = { c_id = > 0 } ;
$ ctt_prepaid = $ dbt - > fetch_record ( $ dbh , $ pref_ctt ) ;
if ( ! $ ctt_prepaid - > { c_id } ) {
my $ ct_id = $ dbt - > insert_contenttrans ( $ dbh , $ ctadr , "300023" , "219" , "----" , "$owner" ) ;
$ pref_ctt - > { c_id } = $ ct_id ;
$ ctt_prepaid = $ dbt - > fetch_record ( $ dbh , $ pref_ctt ) if ( $ pref_ctt - > { c_id } ) ;
}
my $ pos_id = 0 ;
my $ cttpos = { c_id = > 0 } ;
if ( $ ctt_prepaid - > { c_id } > 0 ) {
my $ posref = {
table = > "contenttrans" ,
table_pos = > "contenttranspos" ,
fetch = > "one" ,
keyfield = > "c_id" ,
ca_id = > "$ctadr->{c_id}" ,
int02 = > "is::null" , #0
} ;
$ cttpos = $ dbt - > collect_post ( $ dbh , $ posref ) ;
if ( ! $ cttpos - > { c_id } ) {
#pseudo part. not available in content
my $ ct = {
c_id = > 0 ,
barcode = > 0 ,
ca_id = > $ ctadr - > { c_id } ,
ct_id = > $ ctt_prepaid - > { c_id } ,
int02 = > 0 , #prepaid price on request is 0
txt01 = > 'Prepaid Position' ,
int16 = > 3 , #fibumark for prepaid
template_id = > 219 ,
} ;
$ cttpos - > { c_id } = $ dbt - > insert_pos ( $ dbh , $ ctt_prepaid - > { c_id } , $ ct , "" , $ ctadr , "" , "" , "" , "0" , $ owner , "" ) ;
$ dbt - > update_one ( $ dbh , { table = > 'contenttranspos' , c_id = > $ cttpos - > { c_id } } , "barcode = $cttpos->{c_id},ct_name = '$cttpos->{c_id}'" ) ;
}
}
$ feedb - > { prepaid_account } = $ ctt_prepaid - > { c_id } ;
$ feedb - > { prepaid_id } = $ cttpos - > { c_id } ;
return $ feedb ;
}
2023-09-14 14:11:37 +02:00
#select rentals for messaging user if bike > 12h ... occupied
sub longterm_occupied {
my $ self = shift ;
my $ varenv = shift ;
my $ dbh = "" ;
my $ search = {
table = > "contenttranspos" ,
int10 = > 3 ,
int34 = > "null" , #if not staff
start_time_interval = > "(now() - interval '1 day')" ,
} ;
my $ update_pos = {
table = > "contenttranspos" ,
} ;
my $ dt1 = DateTime - > now ( time_zone = > "Europe/Berlin" ) ;
my $ cttpos = { c_id = > 0 } ;
$ cttpos = $ dbt - > collect_transpos ( $ dbh , $ search ) ;
my $ longterm_ctadr = { } ;
my $ posting = {
78 = > 'email' ,
36 = > 'sms' ,
24 = > 'email' ,
12 = > 'email' ,
} ;
foreach my $ pid ( sort { $ cttpos - > { $ b } - > { end_time } cmp $ cttpos - > { $ a } - > { end_time } } keys ( %$ cttpos ) ) {
if ( $ cttpos - > { $ pid } - > { int10 } == 3 ) {
my $ dt2 = "" ;
$ dt2 = DateTime::Format::Pg - > parse_datetime ( $ cttpos - > { $ pid } - > { start_time } ) ;
if ( $ dt2 ) {
#foreach $posting {#TODO tests
foreach my $ h_id ( sort { $ a <=> $ b } keys ( %$ posting ) ) {
print "--> hour:$h_id\n" ;
if ( $ dt1 >= $ dt2 - > add ( hours = > $ h_id ) ) {
if ( $ cttpos - > { $ pid } - > { int33 } != $ h_id ) {
$ longterm_ctadr = {
hours = > $ h_id ,
posting = > $ posting - > { $ h_id } ,
c_id = > $ cttpos - > { $ pid } - > { ca_id } ,
pos_id = > $ cttpos - > { $ pid } - > { c_id } ,
bike = > $ cttpos - > { $ pid } - > { ct_name } ,
txt01 = > $ cttpos - > { $ pid } - > { txt08 } ,
txt07 = > $ cttpos - > { $ pid } - > { phone } ,
txt08 = > $ cttpos - > { $ pid } - > { email } ,
txt11 = > $ cttpos - > { $ pid } - > { lang } ,
} ;
print $ dt1 . ">=" . $ dt2 - > add ( hours = > $ h_id ) . "\n" . Dumper ( $ longterm_ctadr ) . "\n" ;
$ dbt - > update_one ( $ dbh , $ update_pos , "int33=78" , $ cttpos - > { $ pid } - > { c_id } ) ;
}
}
}
}
}
}
return $ longterm_ctadr ;
}
2023-04-24 14:49:30 +02:00
#insert/save/delete DMS users
sub manage_dmsusers {
my $ self = shift ;
my $ q = shift ;
my $ varenv = shift ;
my $ base_edit = shift ;
my $ u_id = shift ;
my $ users_dms = shift || { } ;
my $ owner = $ users_dms - > { u_id } || 0 ;
my $ table = "users" ;
$ q - > import_names ( 'R' ) ;
my @ keywords = $ q - > param ;
my $ now_dt = strftime "%Y-%m-%d %H:%M:%S" , localtime ;
my $ feedb = { message = > "" , i_rows = > 0 , u_rows = > 0 , d_rows = > 0 } ;
$ bw - > log ( "manage_dmsusers" , $ q , "" ) ;
my $ dbh = "" ;
my $ adref = {
table = > "contentadr" ,
fetch = > "one" ,
template_id = > "202" ,
c_id = > "$u_id" ,
} ;
my $ ctadr = $ dbt - > fetch_record ( $ dbh , $ adref ) ;
#users have to be exist only if DMS activated
my $ uref = {
table = > "users" ,
fetch = > "one" ,
u_id = > "$u_id" ,
} ;
my $ users = $ dbt - > fetch_tablerecord ( $ dbh , $ uref ) ;
#datahash on update
my $ dmsusers = {
table = > "users" ,
mtime = > "now()" ,
owner = > "$owner" ,
u_id = > "$u_id" ,
} ;
if ( ref ( $ users ) eq "HASH" && $ users - > { u_id } && ( ! $ ctadr - > { c_id } || $ base_edit eq "delete_dmsusers" ) ) {
$ bw - > log ( "delete DMS user from $varenv->{dbname}" , $ ctadr - > { c_id } , "" ) ;
$ feedb - > { d_rows } = $ dbt - > delete_content ( $ dbh , "users" , $ u_id ) ;
$ dbt - > update_one ( $ dbh , $ adref , "int07=null" ) ;
$ dbt - > update_one ( $ dbh , $ adref , "int09=null" ) ;
} elsif ( ref ( $ users ) eq "HASH" && $ users - > { u_id } && $ ctadr - > { c_id } && $ ctadr - > { c_id } == $ users - > { u_id } && $ base_edit eq "save_dmsusers" ) {
$ bw - > log ( "update DMS user to $varenv->{dbname}" , $ ctadr - > { c_id } , "" ) ;
foreach ( @ keywords ) {
my $ val = $ q - > param ( $ _ ) ;
my $ valxx = $ q - > escapeHTML ( "$val" ) ;
$ valxx =~ s/^\s+// ; $ valxx =~ s/\s+$// ;
if ( $ _ =~ /^int\d+/ ) {
$ valxx =~ s/,/./g ;
$ valxx = 0 if ( ! looks_like_number ( $ valxx ) ) ; # set to 0 for using == operator
$ feedb - > { u_rows } = $ dbt - > update_one ( $ dbh , $ dmsusers , "$_=$valxx" ) ;
} elsif ( $ _ =~ /^txt\d+/ ) {
my @ val = $ q - > param ( $ _ ) ;
$ valxx = $ q - > escapeHTML ( "@val" ) ;
$ feedb - > { u_rows } = $ dbt - > update_one ( $ dbh , $ dmsusers , "$_='$valxx'" ) ;
}
}
} elsif ( $ ctadr - > { c_id } && ! $ users - > { u_id } && $ base_edit eq "new_dmsusers" ) {
$ bw - > log ( "insert DMS user to $varenv->{dbname}" , $ ctadr - > { c_id } , "" ) ;
$ feedb - > { i_rows } = $ dbt - > insert_users ( $ dbh , $ ctadr - > { c_id } , $ owner ) ;
$ dbt - > update_one ( $ dbh , $ adref , "int07=100" ) ;
2023-05-05 07:30:00 +02:00
$ dbt - > update_one ( $ dbh , $ adref , "int09=1" ) ;
2023-04-24 14:49:30 +02:00
}
return $ feedb ;
} #end manage_dmsusers
2023-03-05 20:01:47 +01:00
#insert content or contentuser
sub new_content {
2023-01-17 20:43:36 +01:00
my $ self = shift ;
my $ q = shift ;
my $ users_dms = shift ;
2023-06-21 20:21:58 +02:00
my $ node_meta = shift ;
2023-01-17 20:43:36 +01:00
$ q - > import_names ( 'R' ) ;
my $ dbh = "" ;
my $ feedb = { message = > "" } ;
2023-08-02 19:03:27 +02:00
my $ main_id = $ node_meta - > { main_id } ;
$ main_id = $ node_meta - > { parent_id } if ( $ R:: template_id == 194 && $ node_meta - > { main_id } >= 400001 ) ;
2023-03-05 20:01:47 +01:00
my $ pref_cc = {
table = > "$R::ct_table" ,
fetch = > "one" ,
template_id = > "$R::template_id" ,
2023-08-02 19:03:27 +02:00
main_id = > "$main_id" ,
2023-03-05 20:01:47 +01:00
} ;
my $ cc_part = { c_id = > 0 } ;
$ cc_part = $ dbt - > fetch_record ( $ dbh , $ pref_cc ) ; #get last barcode by order barcode DESC
my $ next_barcode = $ cc_part - > { c_id } ;
$ next_barcode = $ cc_part - > { barcode } + 1 if ( $ cc_part - > { barcode } > 0 ) ;
2023-01-17 20:43:36 +01:00
my $ insert_ctu = {
2023-03-05 20:01:47 +01:00
table = > "$R::ct_table" ,
2023-01-17 20:43:36 +01:00
itime = > 'now()' ,
mtime = > 'now()' ,
owner = > "$users_dms->{u_id}" ,
2023-03-05 20:01:47 +01:00
barcode = > "$next_barcode" ,
2023-01-17 20:43:36 +01:00
ct_name = > "---" ,
template_id = > "$R::template_id" ,
2023-08-02 19:03:27 +02:00
main_id = > "$main_id" ,
2023-03-05 20:01:47 +01:00
txt12 = > "$dbt->{operator}->{$varenv{dbname}}->{oprefix}" ,
2023-01-17 20:43:36 +01:00
} ;
my $ c_idnew = 0 ;
2023-06-21 20:21:58 +02:00
$ c_idnew = $ dbt - > insert_contentoid ( $ dbh , $ insert_ctu , "" ) if ( $ R:: ct_table && $ R:: template_id && $ node_meta - > { main_id } ) ;
2023-01-17 20:43:36 +01:00
if ( $ c_idnew ) {
$ feedb - > { c_id } = $ c_idnew ;
$ feedb - > { i_rows } = $ i_rows ;
}
return $ feedb ;
}
2023-03-05 20:01:47 +01:00
#save content or contentuser
2023-01-17 20:43:36 +01:00
sub save_content {
my $ self = shift ;
my $ q = shift ;
my $ users_dms = shift ;
my $ node_meta = shift ;
my $ c_id = shift || "" ;
$ q - > import_names ( 'R' ) ;
my @ keywords = $ q - > param ;
my $ dbh = "" ;
2023-03-05 20:01:47 +01:00
my $ feedb = { message = > "" , u_rows = > 0 } ;
2023-01-17 20:43:36 +01:00
my $ ct = { c_id = > $ c_id } ;
my $ update_ct = {
table = > $ node_meta - > { ct_table } ,
owner = > $ users_dms - > { u_id } ,
mtime = > "now()" ,
} ;
foreach ( @ keywords ) {
2023-03-05 20:01:47 +01:00
#my $val = $q->param($_);
#my $valxx = $q->escapeHTML("$val");
2023-01-17 20:43:36 +01:00
my @ val = $ q - > param ( $ _ ) ;
2023-03-05 20:01:47 +01:00
my $ valxx = $ q - > escapeHTML ( "@val" ) ;
#txt24 bike_node/station_group and txt25 bike_group multiple select
if ( $ node_meta - > { template_id } == 225 && $ _ eq "txt24" ) {
my % station_filter_hash = ( ) ;
my @ _valxx_filter = ( ) ;
my $ node = {
template_id = > 205 ,
parent_id = > 200013 ,
fetch = > "all" ,
keyfield = > "main_id" ,
} ;
my $ bike_nodes = { } ;
$ bike_nodes = $ dbt - > fetch_rel4tpl4nd ( $ dbh , $ node ) ;
foreach my $ bike_node ( @ val ) {
foreach my $ rid ( keys ( %$ bike_nodes ) ) {
if ( $ bike_node == $ bike_nodes - > { $ rid } - > { main_id } && $ bike_nodes - > { $ rid } - > { type_id } ) {
$ station_filter_hash { $ bike_nodes - > { $ rid } - > { type_id } } = 1 ;
}
}
}
foreach my $ type_id ( keys ( % station_filter_hash ) ) {
push ( @ _valxx_filter , "$type_id" ) ;
}
$ update_ct - > { txt25 } = "@_valxx_filter" ;
$ update_ct - > { $ _ } = "$valxx" ;
} elsif ( $ node_meta - > { template_id } == 205 && $ _ eq "txt06" ) { #GPS
if ( $ valxx =~ /^(\d{1,2}\.\d+),\s?(\d{1,2}\.\d+)$/ || ! $ valxx || $ valxx eq "null" ) {
$ update_ct - > { $ _ } = "$valxx" ;
} else {
$ feedb - > { message } = "failure::Eingabefehler \"$valxx\", falsches GPS Format. Bitte folgendes Format mit latitude, longitude verwenden. Bsp: 47.927738,7.973855" ;
}
} elsif ( $ node_meta - > { template_id } == 205 && $ _ =~ /byte/ ) {
if ( ! $ valxx ) {
$ update_ct - > { $ _ } = "" ;
} elsif ( $ valxx !~ /[g-z]/ig && length ( $ valxx ) == 32 ) {
$ update_ct - > { $ _ } = "\\x$valxx" ;
} else {
$ feedb - > { message } = "failure::Eingabefehler \"$valxx\", der Token muss 32 HEX Zeichen enthalten" ;
}
} elsif ( $ _ =~ /^time\d+/ ) {
$ valxx = "00:00" if ( $ valxx !~ /\d{1,2}:\d{2}/ ) ;
$ update_ct - > { $ _ } = "$valxx" ;
} elsif ( $ _ =~ /date_time\d+/ ) {
my ( $ date_time , $ chck ) = $ lb - > checkdate ( $ valxx ) ;
if ( ! $ chck ) {
$ update_ct - > { $ _ } = "$valxx" ;
} else {
$ feedb - > { message } = "failure::Eingabefehler \"$valxx\", falsche Datum Uhrzeit Format" ;
}
2023-06-14 21:48:20 +02:00
} elsif ( $ _ =~ /barcode/ ) {
my $ val = $ q - > param ( "$_" ) ;
$ valxx = $ q - > escapeHTML ( "$val" ) ;
$ valxx =~ s/\s//g ;
if ( $ node_meta - > { ct_table } eq "content" && ( looks_like_number ( $ valxx ) || $ valxx == 0 ) && $ R:: rel_id && $ R:: template_id ) {
my $ pref_cc = {
table = > "content" ,
fetch = > "one" ,
template_id = > "$R::template_id" ,
barcode = > "$valxx" ,
rel_id = > "!=::$R::rel_id" ,
} ;
my $ cc_part = { c_id = > 0 } ;
$ cc_part = $ dbt - > fetch_record ( $ dbh , $ pref_cc ) ;
if ( ! $ cc_part - > { c_id } ) {
$ update_ct - > { $ _ } = "$valxx" ;
} else {
$ feedb - > { message } = "failure::Fehler \"$valxx\", die Artikelnummer ist bereits vorhanden" ;
}
} else {
$ feedb - > { message } = "failure::Eingabefehler \"$valxx\", hier sind nur numerische Werte erlaubt" ;
}
} elsif ( $ _ =~ /^int/ ) {
2023-05-05 07:30:00 +02:00
my $ val = $ q - > param ( "$_" ) ;
$ valxx = $ q - > escapeHTML ( "$val" ) ;
$ valxx =~ s/,/./ ;
$ valxx =~ s/\s//g ;
2023-06-01 07:50:17 +02:00
if ( looks_like_number ( $ valxx ) || $ valxx == 0 ) {
2023-05-05 07:30:00 +02:00
$ update_ct - > { $ _ } = "$valxx" ;
} elsif ( ! $ valxx || $ valxx eq "null" ) {
2023-03-05 20:01:47 +01:00
$ update_ct - > { $ _ } = "null" ;
} else {
$ feedb - > { message } = "failure::Eingabefehler \"$valxx\", hier sind nur numerische Werte erlaubt" ;
}
2023-03-30 17:45:12 +02:00
} elsif ( $ node_meta - > { template_id } == 194 && $ _ =~ /txt/ && ! $ valxx ) {
$ update_ct - > { $ _ } = "null" ; #important for coalesce select alias lang fallback
2023-03-05 20:01:47 +01:00
} elsif ( $ _ =~ /ct_name|txt|state|time/ ) {
2023-01-17 20:43:36 +01:00
$ update_ct - > { $ _ } = "$valxx" ;
}
}
2023-03-05 20:01:47 +01:00
if ( $ ct - > { c_id } ) {
$ feedb - > { u_rows } += $ dbt - > update_record ( $ dbh , $ update_ct , $ ct ) ;
2023-07-27 07:05:23 +02:00
$ dbt - > operators_cms ( $ node_meta - > { ct_table } , $ c_id , "update" ) if ( $ node_meta - > { template_id } == 194 ) ;
2023-03-05 20:01:47 +01:00
}
2023-01-17 20:43:36 +01:00
return $ feedb ;
} #end save_content
2023-06-14 21:48:20 +02:00
#move content (mainly for bike flot)
sub move_content {
my $ self = shift ;
my $ q = shift ;
my $ users_dms = shift ;
my $ node_meta = shift ;
my $ c_id = shift || "" ;
$ q - > import_names ( 'R' ) ;
my $ dbh = "" ;
my $ feedb = { message = > "" , u_rows = > 0 } ;
my $ update_relation = {
table = > "relation" ,
rel_id = > "$R::rel_id" ,
} ;
if ( $ R:: template_id && $ node_meta - > { template_id } == $ R:: template_id && $ R:: rel_id && $ R:: main_id ) {
$ u_rows += $ dbt - > update_one ( $ dbh , $ update_relation , "main_id=$R::main_id" ) ;
my $ uri_path = $ dbt - > recurse_node ( $ dbh , $ R:: main_id ) ;
print redirect ( "$varenv{wwwhost}/$uri_path?node2edit=editpart\&rel_id=$R::rel_id\&return=$i_rows-$u_rows-$d_rows" ) ;
exit 0 ;
} else {
$ feedb - > { message } = "failure::Der Artikel konnte nicht verschoben werden." ;
}
return $ feedb ;
}
2023-03-05 20:01:47 +01:00
#delete content
sub delete_content {
my $ self = shift ;
my $ node_meta = shift || "" ;
my $ c_id = shift || "" ;
2023-07-27 07:05:23 +02:00
my $ users_dms = shift || "" ;
2023-03-05 20:01:47 +01:00
my $ dbh = "" ;
my $ feedb = { d_rows = > 0 , message = > "" } ;
if ( $ node_meta - > { ct_table } , $ c_id ) {
2023-07-27 07:05:23 +02:00
$ dbt - > operators_cms ( $ node_meta - > { ct_table } , $ c_id , "delete" ) if ( $ node_meta - > { template_id } == 194 ) ;
2023-03-05 20:01:47 +01:00
$ feedb - > { d_rows } = $ dbt - > delete_content ( $ dbh , $ node_meta - > { ct_table } , $ c_id ) ;
}
return $ feedb ;
}
2023-01-17 20:43:36 +01:00
2022-12-16 08:37:05 +01:00
#save invoice address or text
sub save_text2contenttrans {
my $ self = shift ;
2022-12-19 14:21:53 +01:00
my $ q = shift ;
2022-12-16 08:37:05 +01:00
my $ users_dms = shift ;
2023-01-17 20:43:36 +01:00
my $ c_id = shift || "" ;
2022-12-16 08:37:05 +01:00
$ q - > import_names ( 'R' ) ;
my @ keywords = $ q - > param ;
my $ dbh = "" ;
my $ feedb = { message = > "" } ;
2023-03-05 20:01:47 +01:00
open ( FILE , ">>$varenv{logdir}/save_text2contenttrans.log" ) if ( $ debug ) ;
print FILE "\n*--> $now_dt| c_id:$c_id | u_id:$users_dms->{u_id}\n" if ( $ debug ) ;
print FILE Dumper ( $ q ) . "\n" if ( $ debug ) ;
2022-12-16 08:37:05 +01:00
my $ ctt = { c_id = > $ c_id } ;
my $ update_ctt = {
table = > "contenttrans" ,
owner = > $ users_dms - > { u_id } ,
mtime = > "now()" ,
} ;
foreach ( @ keywords ) {
my $ val = $ q - > param ( $ _ ) ;
my $ valxx = $ q - > escapeHTML ( "$val" ) ;
my @ val = $ q - > param ( $ _ ) ;
$ valxx = $ q - > escapeHTML ( "@val" ) ;
2023-01-25 07:25:12 +01:00
#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" ;
}
}
2023-03-10 11:35:56 +01:00
elsif ( $ _ =~ /int|time/ ) {
if ( ! $ valxx ) {
$ update_ctt - > { $ _ } = "null" ;
} else {
$ update_ctt - > { $ _ } = "$valxx" ;
}
}
elsif ( $ _ =~ /txt|state/ ) {
2022-12-16 08:37:05 +01:00
$ update_ctt - > { $ _ } = "$valxx" ;
}
}
2023-01-17 20:43:36 +01:00
if ( $ ctt - > { c_id } ) {
$ u_rows += $ dbt - > update_record ( $ dbh , $ update_ctt , $ ctt ) ;
#empty warn_time if warnstate not set
2023-03-10 11:35:56 +01:00
#if(!$R::int06 || !$R::warn_time){
# $dbt->update_one($dbh,$update_ctt,"warn_time=null",$c_id);
#}
2023-02-10 12:04:30 +01:00
if ( $ R:: txt22 && $ R:: txt22 eq "Zahlungseingang" ) {
$ dbt - > update_one ( $ dbh , $ update_ctt , "int14=null" , $ c_id ) ;
$ dbt - > update_one ( $ dbh , $ update_ctt , "pay_time=now()" , $ c_id ) ;
}
if ( $ R:: txt22 && $ R:: txt22 eq "Zahlung offen" ) {
$ dbt - > update_one ( $ dbh , $ update_ctt , "int14=1" , $ c_id ) ;
$ dbt - > update_one ( $ dbh , $ update_ctt , "pay_time=null" , $ c_id ) ;
}
2022-12-16 08:37:05 +01:00
}
2023-03-05 20:01:47 +01:00
close ( FILE ) if ( $ debug ) ;
2022-12-16 08:37:05 +01:00
$ feedb - > { u_rows } = $ u_rows ;
return $ feedb ;
} #end save_text2contenttrans
2022-09-20 16:13:45 +02:00
#part or fee to invoice
sub insert_contenttranspos {
my $ self = shift ;
2022-12-19 14:21:53 +01:00
my $ q = shift ;
2022-09-21 19:24:42 +02:00
my $ cc_id = shift || "" ; #part
2022-09-20 16:13:45 +02:00
my $ ca_id = shift || "" ; #adr
my $ ct_id = shift || "" ; #invoice
my $ owner = shift || "" ;
my $ dbh = "" ;
my $ feedb = { message = > "" } ;
2022-09-21 19:24:42 +02:00
if ( looks_like_number ( $ cc_id ) && looks_like_number ( $ ca_id ) && looks_like_number ( $ ct_id ) ) {
my $ pref = {
table = > "contenttrans" ,
table_pos = > "contenttranspos" ,
fetch = > "one" ,
template_id = > "218" , #Mietjournal tpl_id
ct_id = > $ ct_id ,
"ct.state" = > "is::null" ,
} ;
my $ ctpos = { c_id = > 0 } ;
$ ctpos = $ dbt - > collect_post ( $ dbh , $ pref ) ;
if ( $ ctpos - > { c_id } ) {
my $ pref_cc = {
2022-09-20 16:13:45 +02:00
table = > "content" ,
fetch = > "one" ,
template_id = > "IN::(229)" ,
2022-09-21 19:24:42 +02:00
c_id = > $ cc_id ,
2022-09-20 16:13:45 +02:00
} ;
2022-09-21 19:24:42 +02:00
my $ cc_part = { c_id = > 0 } ;
$ cc_part = $ dbt - > fetch_record ( $ dbh , $ pref_cc ) ;
2022-09-20 16:13:45 +02:00
2022-09-21 19:24:42 +02:00
my $ pref_ca = {
2022-09-20 16:13:45 +02:00
table = > "contentadr" ,
fetch = > "one" ,
template_id = > "202" ,
c_id = > "$ca_id" ,
} ;
2022-09-21 19:24:42 +02:00
my $ ctadr = { c_id = > 0 } ;
$ ctadr = $ dbt - > fetch_record ( $ dbh , $ pref_ca ) ;
2022-09-20 16:13:45 +02:00
2022-09-21 19:24:42 +02:00
my $ pos_id = 0 ;
if ( $ cc_part - > { int02 } ) {
2022-09-20 16:13:45 +02:00
$ pos_id = $ dbt - > insert_pos ( $ dbh , $ ct_id , $ cc_part , "" , $ ctadr , "" , "" , $ cc_part - > { barcode } , "0" , $ owner , "" ) ;
2022-09-21 19:24:42 +02:00
} else {
2022-09-20 16:13:45 +02:00
$ feedb - > { message } = "failure::Fehler, VK Preis von Artikel Nr. $cc_part->{barcode} nicht definiert." ;
2022-09-21 19:24:42 +02:00
}
if ( $ pos_id > 0 ) {
2022-09-20 16:13:45 +02:00
$ i_rows += 1 ;
$ dbt - > update_content4comp ( $ dbh , $ cc_part - > { c_id } , "-" , "1" ) ;
$ feedb - > { message } = "Artikel Nr. $cc_part->{barcode} erfolgreich hinzugefügt." ;
2022-09-21 19:24:42 +02:00
}
} else {
$ feedb - > { message } = "failure::Fehler, die Rechnung ist bereits gebucht. Das hinzufügen einer weiteren Rechnungsposition wird somit abgelehnt." ;
}
2022-09-20 16:13:45 +02:00
} else {
2022-09-21 19:24:42 +02:00
$ feedb - > { message } = "failure::Fehler, es fehlt mindestens ein Key! ($cc_id && $ca_id && $ct_id)" ;
2022-09-20 16:13:45 +02:00
}
$ feedb - > { u_rows } = $ u_rows ;
return $ feedb ;
} #end insert_contenttranspos
2022-06-02 10:34:03 +02:00
sub save_contenttranspos {
my $ self = shift ;
2022-12-19 14:21:53 +01:00
my $ q = shift ;
2022-06-02 10:34:03 +02:00
my $ c_id = shift ;
my $ owner = shift ;
my $ dbh = "" ;
my $ feedb = { message = > "" } ;
if ( $ c_id && $ R:: start_date =~ /\d{1,2}\.\d{1,2}\.\d{4}/ && $ R:: end_date =~ /\d{1,2}\.\d{1,2}\.\d{4}/ ) {
my $ s_hh = $ q - > escapeHTML ( "$R::s_hh" ) || "0" ;
my $ s_mi = $ q - > escapeHTML ( "$R::s_mi" ) || "0" ;
my $ e_hh = $ q - > escapeHTML ( "$R::e_hh" ) || "0" ;
my $ e_mi = $ q - > escapeHTML ( "$R::e_mi" ) || "0" ;
$ s_hh = "24" if ( $ s_hh > "24" ) ;
$ e_hh = "24" if ( $ e_hh > "24" ) ;
$ s_mi = "59" if ( $ s_mi > "59" ) ;
$ e_mi = "59" if ( $ e_mi > "59" ) ;
$ s_hh = sprintf ( '%.2d' , $ s_hh ) ;
$ e_hh = sprintf ( '%.2d' , $ e_hh ) ;
$ s_mi = sprintf ( '%.2d' , $ s_mi ) ;
$ e_mi = sprintf ( '%.2d' , $ e_mi ) ;
my $ start_time = "" ;
my $ end_time = "" ;
my $ dtnow = DateTime - > now ( time_zone = > "Europe/Berlin" ) ;
my $ dt0 = DateTime - > now ( time_zone = > "Europe/Berlin" ) ;
my $ dt1 = DateTime - > now ( time_zone = > "Europe/Berlin" ) ;
if ( $ R:: start_date =~ /(\d{1,2})\.(\d{1,2})\.(\d{4})/ ) {
$ dt0 = DateTime - > new (
year = > $ 3 ,
month = > $ 2 ,
day = > $ 1 ,
hour = > $ s_hh ,
minute = > $ s_mi ,
time_zone = > 'Europe/Berlin' ,
) ;
$ start_time = $ dt0 - > strftime ( "%Y-%m-%d %H:%M:%S" ) ;
#print $start_time;
}
if ( $ R:: end_date =~ /(\d{1,2})\.(\d{1,2})\.(\d{4})/ ) {
$ dt1 = DateTime - > new (
year = > $ 3 ,
month = > $ 2 ,
day = > $ 1 ,
hour = > $ e_hh ,
minute = > $ e_mi ,
time_zone = > 'Europe/Berlin' ,
) ;
$ end_time = $ dt1 - > strftime ( "%Y-%m-%d %H:%M:%S" ) ;
}
2023-07-05 06:23:29 +02:00
$ bw - > log ( "save_contenttranspos time-check: $c_id && $start_time && $end_time" , $ c_id , "" ) ;
2022-06-02 10:34:03 +02:00
if ( $ c_id && $ start_time && $ end_time && $ dt0 < $ dtnow && $ dt1 < $ dtnow ) {
my $ pref = {
table = > "contenttrans" ,
table_pos = > "contenttranspos" ,
fetch = > "one" ,
2023-10-06 06:48:36 +02:00
template_id = > "218" , #open invoice tpl_id
2022-06-02 10:34:03 +02:00
c_id = > $ c_id ,
2022-09-21 19:24:42 +02:00
"ct.state" = > "is::null" ,
2022-06-02 10:34:03 +02:00
} ;
2022-09-21 19:24:42 +02:00
my $ ctpos = { c_id = > 0 } ;
2022-06-24 14:38:22 +02:00
$ ctpos = $ dbt - > collect_post ( $ dbh , $ pref ) ;
2022-06-02 10:34:03 +02:00
my $ pricing = { } ;
my $ counting = { } ;
my $ update_pos = {
table = > "contenttranspos" ,
start_time = > "$start_time" ,
end_time = > "$end_time" ,
2023-07-13 12:10:45 +02:00
int04 = > "null" ,
2022-06-02 10:34:03 +02:00
owner_end = > $ owner ,
mtime = > "now()" ,
} ;
2022-06-24 14:38:22 +02:00
#if sig
if ( $ ctpos - > { int11 } == 3 && $ ctpos - > { ca_id } ) {
#sig booking_request
my $ sig_book = {
bikeId = > "" ,
rentalId = > "" ,
} ;
if ( looks_like_number ( $ R:: int10 ) && $ R:: int10 == 1 ) {
my $ authref = {
table = > "contentadr" ,
fetch = > "one" ,
template_id = > "202" ,
c_id = > "=::$ctpos->{ca_id}" ,
} ;
my $ authraw = { } ;
$ authraw = $ dbt - > fetch_record ( $ dbh , $ authref ) ;
$ sig_book = $ si - > sig_booking ( \ % varenv , "reserve_end" , $ authraw , "" , $ ctpos ) ;
}
} else {
2022-09-15 17:06:08 +02:00
if ( $ ctpos - > { c_id } ) {
2022-06-24 14:38:22 +02:00
$ u_rows += $ dbt - > update_record ( $ dbh , $ update_pos , $ ctpos ) ;
2022-09-15 17:06:08 +02:00
} else {
2022-09-21 19:24:42 +02:00
$ feedb - > { message } = "failure::Fehler, Änderung abgelehnt da Rechnung bereits gebucht" ;
2022-09-15 17:06:08 +02:00
}
2022-06-24 14:38:22 +02:00
}
2022-06-02 10:34:03 +02:00
#again to get setted date-times
2022-06-24 14:38:22 +02:00
$ ctpos = $ dbt - > collect_post ( $ dbh , $ pref ) ;
2022-06-02 10:34:03 +02:00
2022-09-21 19:24:42 +02:00
#print "$R::start_date $s_hh:$s_mi | $R::start_date $e_hh:$e_mi xxxxxxxxx<br>";exit;
2023-04-17 15:30:19 +02:00
( $ pricing , $ counting ) = $ pri - > counting_rental ( \ % varenv , $ ctpos ) ;
2022-06-02 10:34:03 +02:00
$ update_pos - > { int38 } = "$counting->{int38}" if ( looks_like_number ( $ counting - > { int38 } ) ) ;
$ update_pos - > { int39 } = "$counting->{int39}" if ( looks_like_number ( $ counting - > { int39 } ) ) ;
$ update_pos - > { int40 } = "$counting->{int40}" if ( looks_like_number ( $ counting - > { int40 } ) ) ;
$ update_pos - > { int41 } = "$counting->{int41}" if ( looks_like_number ( $ counting - > { int41 } ) ) ;
$ update_pos - > { int10 } = $ R:: int10 if ( looks_like_number ( $ R:: int10 ) ) ;
$ update_pos - > { int20 } = $ R:: int20 if ( looks_like_number ( $ R:: int20 ) ) ;
$ update_pos - > { int04 } = $ R:: int04 if ( looks_like_number ( $ R:: int04 ) ) ;
2022-07-16 16:04:46 +02:00
$ update_pos - > { int07 } = $ R:: int07 if ( looks_like_number ( $ R:: int07 ) ) ;
$ update_pos - > { int08 } = $ R:: int08 if ( looks_like_number ( $ R:: int08 ) ) ;
2022-06-03 06:21:28 +02:00
$ update_pos - > { txt01 } = $ q - > escapeHTML ( $ R:: txt01 ) if ( $ R:: txt01 ) ;
$ update_pos - > { txt23 } = $ q - > escapeHTML ( $ R:: txt23 ) if ( $ R:: txt23 ) ;
2022-06-02 10:34:03 +02:00
#before update bike content check if realy last rental
my $ pref2ck = {
table = > "contenttrans" ,
table_pos = > "contenttranspos" ,
fetch = > "one" ,
2023-10-06 06:48:36 +02:00
template_id = > "218" , #open invoice tpl_id
2022-06-02 10:34:03 +02:00
start_time = > ">::$end_time" ,
2022-07-15 07:11:01 +02:00
barcode = > $ ctpos - > { barcode } ,
2022-09-21 19:24:42 +02:00
"ct.state" = > "is::null" ,
2022-06-02 10:34:03 +02:00
} ;
2022-06-24 14:38:22 +02:00
my $ ctpos2ck = { c_id = > 0 } ;
$ ctpos2ck = $ dbt - > collect_post ( $ dbh , $ pref2ck ) ;
2022-06-02 10:34:03 +02:00
#update bike content only if there is no later rental start
2023-07-05 06:23:29 +02:00
$ bw - > log ( "update bike content only if there is no later rental start: $ctpos->{cc_id} && !$ctpos2ck->{c_id}" , $ c_id , "" ) ;
2022-06-24 14:38:22 +02:00
if ( $ ctpos - > { cc_id } && ! $ ctpos2ck - > { c_id } ) {
2022-06-02 10:34:03 +02:00
my $ ctpref = {
table = > "content" ,
fetch = > "one" ,
2022-06-24 14:38:22 +02:00
c_id = > $ ctpos - > { cc_id } ,
2022-06-02 10:34:03 +02:00
} ;
my $ ctbike = $ dbt - > fetch_tablerecord ( $ dbh , $ ctpref ) ;
$ ctpref - > { int10 } = $ R:: int10 if ( looks_like_number ( $ R:: int10 ) ) ;
$ ctpref - > { int20 } = $ R:: int20 if ( looks_like_number ( $ R:: int20 ) ) ;
$ ctpref - > { int04 } = $ R:: int04 if ( looks_like_number ( $ R:: int04 ) ) ;
$ ctpref - > { owner } = $ owner ;
$ ctpref - > { mtime } = "now()" ;
2022-06-24 14:38:22 +02:00
2022-06-02 10:34:03 +02:00
$ u_rows += $ dbt - > update_record ( $ dbh , $ ctpref , $ ctbike ) ;
$ feedb - > { message } = "Mietdaten gespeichert und Mietrad Stati in Warenstamm übernommen" ;
} else {
$ feedb - > { message } = "Mietdaten gespeichert. Achtung, Mietrad Stati in Warenstamm NICHT übernommen, da es sich nicht um die letzte Miete handelt" ;
}
2022-09-15 17:06:08 +02:00
if ( $ ctpos - > { c_id } ) {
$ u_rows += $ dbt - > update_record ( $ dbh , $ update_pos , $ ctpos ) ;
2022-06-02 10:34:03 +02:00
2022-09-15 17:06:08 +02:00
#
if ( $ ctpos - > { ct_id } ) {
2022-06-02 10:34:03 +02:00
my $ ctpref = {
table = > "contenttrans" ,
2022-06-24 14:38:22 +02:00
c_id = > $ ctpos - > { ct_id } ,
2022-06-02 10:34:03 +02:00
start_time = > "$start_time" ,
end_time = > "$end_time" ,
owner = > $ owner ,
mtime = > "now()" ,
} ;
$ u_rows += $ dbt - > update_record ( $ dbh , $ ctpref , $ ctpref ) ;
2022-09-15 17:06:08 +02:00
}
} else {
2022-09-21 19:24:42 +02:00
$ feedb - > { message } = "failure::Fehler, Änderung abgelehnt da Rechnung bereits gebucht" ;
2022-09-15 17:06:08 +02:00
}
2023-07-05 06:23:29 +02:00
} else {
$ bw - > log ( "save_contenttranspos time-check fails by: $c_id && $start_time && $end_time" , $ c_id , "" ) ;
2022-09-15 17:06:08 +02:00
}
} elsif ( $ R:: int02 && $ R:: int03 ) {
2022-12-06 19:57:49 +01:00
$ R:: int02 =~ s/,/\./ if ( $ R:: int02 =~ /\,/ ) ;
$ R:: int03 =~ s/,/\./ if ( $ R:: int03 =~ /\,/ ) ;
2022-09-15 17:06:08 +02:00
$ R:: txt01 = $ q - > escapeHTML ( $ R:: txt01 ) if ( $ R:: txt01 ) ;
$ R:: txt23 = $ q - > escapeHTML ( $ R:: txt23 ) if ( $ R:: txt23 ) ;
if ( $ c_id && looks_like_number ( $ R:: int02 ) && looks_like_number ( $ R:: int03 ) ) {
my $ pref = {
table = > "contenttrans" ,
table_pos = > "contenttranspos" ,
fetch = > "one" ,
2023-10-06 06:48:36 +02:00
template_id = > "IN::(218,219)" , #open invoices and prepaid tpl_id
2022-09-15 17:06:08 +02:00
c_id = > $ c_id ,
2022-09-21 19:24:42 +02:00
"ct.state" = > "is::null" ,
2022-09-15 17:06:08 +02:00
} ;
2022-09-21 19:24:42 +02:00
my $ ctpos = { c_id = > 0 } ;
2022-09-15 17:06:08 +02:00
$ ctpos = $ dbt - > collect_post ( $ dbh , $ pref ) ;
my $ update_pos = {
table = > "contenttranspos" ,
int02 = > "$R::int02" ,
int03 = > "$R::int03" ,
txt01 = > "$R::txt01" ,
txt23 = > "$R::txt23" ,
owner = > $ owner ,
mtime = > "now()" ,
} ;
if ( $ ctpos - > { c_id } ) {
$ u_rows += $ dbt - > update_record ( $ dbh , $ update_pos , $ ctpos ) ;
2023-10-06 06:48:36 +02:00
#prepaid account Vde management by booking prepaid amount
if ( $ R:: tpl_id4trans && $ R:: tpl_id4trans == 219 ) {
my $ update_adr = {
table = > "contentadr" ,
owner = > $ owner ,
mtime = > "now()" ,
c_id = > $ ctpos - > { ca_id } ,
int12 = > "0" ,
} ;
my $ ctadr = { c_id = > $ ctpos - > { ca_id } } ;
$ u_rows += $ dbt - > update_record ( $ dbh , $ update_adr , $ ctadr ) ; #check int12=0 update
#$dbt->update_one($dbh,$update_adr,"int12=0");#Vde
$ dbt - > update_operatorsloop ( $ varenv { dbname } , $ ctadr - > { c_id } , "update" ) ;
}
2022-09-15 17:06:08 +02:00
} else {
2022-09-21 19:24:42 +02:00
$ feedb - > { message } = "failure::Fehler, Änderung abgelehnt da Rechnung bereits gebucht" ;
2022-06-02 10:34:03 +02:00
}
2022-09-15 17:06:08 +02:00
} else {
2023-10-06 06:48:36 +02:00
$ feedb - > { message } = "failure::Fehler, es sind nur numerische Werte erlaubt ($c_id && $R::int02 && $R::int03)." ;
2022-06-02 10:34:03 +02:00
}
} else {
2022-09-15 17:06:08 +02:00
$ feedb - > { message } = "failure::Fehler, fehlerhafte Eingaben oder Datensatz nicht gefunden!" ;
2022-06-02 10:34:03 +02:00
}
$ feedb - > { u_rows } = $ u_rows ;
return $ feedb ;
} #end save_contenttranspos
2021-12-30 12:05:56 +01:00
2022-03-17 20:28:28 +01:00
#set Faktura workflow like Rechnung to Storno
sub set_workflow {
my $ self = shift ;
2022-12-19 14:21:53 +01:00
my $ q = shift ;
2022-03-17 20:28:28 +01:00
my $ users_dms = shift ;
my $ c_id = shift ;
my $ set_main_id = shift || "" ;
my % varenv = $ cf - > envonline ( ) ;
my $ dbh = "" ;
my $ node = $ dbt - > get_node ( $ dbh , $ set_main_id ) ;
my $ pref = {
table = > "contenttrans" ,
fetch = > "one" ,
c_id = > $ c_id ,
} ;
my $ ctt = { c_id = > 0 } ;
$ ctt = $ dbt - > fetch_tablerecord ( $ dbh , $ pref ) ;
#barcode setting logic reset. keep barcode from orignal for backlinking
#counter invoice subnr
if ( $ ctt - > { ct_name } =~ /\d+-\d+/ ) {
my ( $ ct_name , $ subname ) = split ( /-/ , $ ctt - > { ct_name } ) ;
$ subname + + ;
$ ctt - > { ct_name } = "$ct_name-$subname" ;
} else {
$ ctt - > { ct_name } = "$ctt->{ct_name}-1" ;
}
delete $ ctt - > { c_id } ;
delete $ ctt - > { txt00 } ;
delete $ ctt - > { state } ;
delete $ ctt - > { int01 } ;
delete $ ctt - > { int14 } ;
delete $ ctt - > { int15 } ;
2022-03-18 14:51:25 +01:00
delete $ ctt - > { int16 } ;
delete $ ctt - > { int18 } ;
2022-03-17 20:28:28 +01:00
delete $ ctt - > { txt16 } ;
delete $ ctt - > { txt12 } ;
delete $ ctt - > { txt21 } ;
delete $ ctt - > { txt22 } ;
delete $ ctt - > { txt23 } ;
2022-03-18 14:51:25 +01:00
delete $ ctt - > { txt25 } ;
2022-03-17 20:28:28 +01:00
delete $ ctt - > { txt30 } ;
delete $ ctt - > { itime } ;
delete $ ctt - > { mtime } ;
delete $ ctt - > { close_time } ;
delete $ ctt - > { invoice_time } ;
delete $ ctt - > { pay_time } ;
2023-02-10 12:04:30 +01:00
delete $ ctt - > { warn_time } ;
2022-03-17 20:28:28 +01:00
my $ insert_ctt = {
%$ ctt ,
table = > "contenttrans" ,
itime = > 'now()' ,
mtime = > 'now()' ,
owner = > "$users_dms->{u_id}" ,
ct_name = > "$ctt->{ct_name}" ,
txt00 = > "$node->{node_name}" ,
template_id = > "218" ,
main_id = > "$node->{main_id}" ,
} ;
my $ c_idnew = 0 ;
$ c_idnew = $ dbt - > insert_contentoid ( $ dbh , $ insert_ctt , "" ) ;
$ i_rows = 1 if ( $ c_idnew ) ;
#print Dumper($insert_ctt);
#exit;
#position copy
if ( $ c_idnew > 0 ) {
2023-10-26 06:50:16 +02:00
my ( $ cttpos , $ rows ) = $ dbt - > collect_contentpos ( $ dbh , "contenttrans" , $ c_id ) ;
2022-10-31 08:11:53 +01:00
foreach my $ id ( sort { $ cttpos - > { $ a } - > { c_id } <=> $ cttpos - > { $ b } - > { c_id } } keys ( %$ cttpos ) ) {
2022-08-17 21:22:57 +02:00
#reverse pos sum for example by Storno
$ cttpos - > { $ id } - > { int01 } = $ cttpos - > { $ id } - > { int01 } * - 1 if ( $ cttpos - > { $ id } - > { int01 } != 0 ) ;
2022-10-18 20:15:11 +02:00
$ cttpos - > { $ id } - > { int05 } = $ cttpos - > { $ id } - > { c_id } ; # set source pos id if sub doc
$ cttpos - > { $ id } - > { txt23 } = "workflow doc" if ( $ cttpos - > { $ id } - > { int01 } == - 1 ) ;
2022-03-17 20:28:28 +01:00
delete $ cttpos - > { $ id } - > { c_id } ;
delete $ cttpos - > { $ id } - > { ct_id } ;
delete $ cttpos - > { $ id } - > { itime } ;
delete $ cttpos - > { $ id } - > { mtime } ;
my $ insert_pos = {
% { $ cttpos - > { $ id } } ,
table = > "contenttranspos" ,
ct_id = > $ c_idnew ,
itime = > 'now()' ,
mtime = > 'now()' ,
} ;
my $ ctpos_id = $ dbt - > insert_contentoid ( $ dbh , $ insert_pos , "" ) ;
$ i_rows += 1 if ( $ ctpos_id > 0 ) ;
}
2023-10-26 06:50:16 +02:00
my $ update_users = {
table = > "users" ,
change = > "no_time" ,
u_id = > $ users_dms - > { u_id }
} ;
$ dbt - > update_one ( $ dbh , $ update_users , "c_id4trans=$c_idnew,tpl_id4trans=218" ) ;
2022-03-17 20:28:28 +01:00
2023-10-26 06:50:16 +02:00
print redirect ( "$varenv{wwwhost}/DMS/Faktura?ct_trans=open\&c_id4trans=$c_idnew\&tpl_id4trans=218\&owner=$users_dms->{u_id}\&offset=$R::offset\&limit=$R::limit\&return=$i_rows-$u_rows-$d_rows" ) ;
exit 0 ;
}
2022-03-17 20:28:28 +01:00
} #end set_workflow
2022-10-31 08:11:53 +01:00
#generate invoice from operator accounting
sub set_accounting2invoice {
my $ self = shift ;
2022-12-19 14:21:53 +01:00
my $ q = shift ;
2022-10-31 08:11:53 +01:00
my $ users_dms = shift ;
my $ c_id = shift ;
my $ set_main_id = shift || "" ;
my % varenv = $ cf - > envonline ( ) ;
my $ dbh = "" ;
my $ node = $ dbt - > get_node ( $ dbh , $ set_main_id ) ;
my $ pref = {
table = > "contenttrans" ,
fetch = > "one" ,
c_id = > $ c_id ,
} ;
my $ ctt = { c_id = > 0 } ;
$ ctt = $ dbt - > fetch_tablerecord ( $ dbh , $ pref ) ;
#barcode setting logic reset. keep barcode from orignal for backlinking
#counter invoice subnr
if ( $ ctt - > { ct_name } =~ /\d+-\d+/ ) {
my ( $ ct_name , $ subname ) = split ( /-/ , $ ctt - > { ct_name } ) ;
$ subname + + ;
$ ctt - > { ct_name } = "$ct_name-$subname" ;
} else {
$ ctt - > { ct_name } = "$ctt->{ct_name}-1" ;
}
delete $ ctt - > { c_id } ;
delete $ ctt - > { txt00 } ;
delete $ ctt - > { state } ;
delete $ ctt - > { itime } ;
delete $ ctt - > { mtime } ;
delete $ ctt - > { close_time } ;
delete $ ctt - > { invoice_time } ;
delete $ ctt - > { pay_time } ;
my $ insert_ctt = {
%$ ctt ,
table = > "contenttrans" ,
itime = > 'now()' ,
mtime = > 'now()' ,
owner = > "$users_dms->{u_id}" ,
ct_name = > "$ctt->{ct_name}" ,
txt00 = > "$node->{node_name}" ,
template_id = > "218" ,
main_id = > "$node->{main_id}" ,
} ;
my $ c_idnew = 0 ;
$ c_idnew = $ dbt - > insert_contentoid ( $ dbh , $ insert_ctt , "" ) ;
$ i_rows = 1 if ( $ c_idnew ) ;
#taking just same (operator_accounting) invoices detected by int10=2
2023-10-26 06:50:16 +02:00
my $ update_users = {
table = > "users" ,
change = > "no_time" ,
u_id = > $ users_dms - > { u_id }
} ;
$ dbt - > update_one ( $ dbh , $ update_users , "c_id4trans=$c_idnew,tpl_id4trans=218" ) ;
2022-10-31 08:11:53 +01:00
my $ uri_path = $ dbt - > recurse_node ( $ dbh , $ node - > { main_id } ) ;
print "$varenv{wwwhost}/$uri_path?return=$i_rows-$u_rows-$d_rows\n" ;
print redirect ( "$varenv{wwwhost}/$uri_path?return=$i_rows-$u_rows-$d_rows" ) ;
exit 0 ;
} #end set_accounting2invoice
2021-12-30 12:05:56 +01:00
#new node relation with option to create subnode for Servicelog
sub new_relation {
my $ self = shift ;
2022-12-19 14:21:53 +01:00
my $ q = shift ;
2021-12-30 12:05:56 +01:00
my $ main_id = shift ;
my $ owner = shift ;
my % varenv = $ cf - > envonline ( ) ;
my $ ret = "" ;
my $ dbh = "" ;
#$ret = "failure::temporarily disabled";
#return $ret;
open ( FILE , ">>$varenv{logdir}/new_relation.log" ) if ( $ debug ) ;
print FILE "\n*--> $now_dt| main_id: $main_id | owner: $owner\n" if ( $ debug ) ;
my $ prefix_id = "0" ;
my $ working_parent_id = $ R:: parent_id ;
$ prefix_id = $ 1 if ( $ R:: main_id =~ /^(\d)/ && $ R:: main_id >= "100000" ) ;
$ ret = $ lb - > checkinput ( $ R:: node_name ) ;
return $ ret if ( $ ret =~ /failure/ ) ;
my $ node_name = $ q - > escapeHTML ( $ R:: node_name ) ;
#check multiple node_name
my $ subrelnode = $ dbt - > get_subrelnode ( $ dbh , $ working_parent_id , "" , $ node_name ) ;
if ( $ subrelnode - > { node_name } eq "$R::node_name" ) {
return "failure::Abbruch, der Menuename \"$subrelnode->{node_name}\" ist bereits vorhanden. Bitte eindeutige Menuenamen verwenden." ;
}
if ( $ R:: new_submenu ) {
$ working_parent_id = $ R:: main_id ;
$ prefix_id + + ;
}
my $ new_main_id = $ dbt - > get_freenode ( $ dbh , $ prefix_id ) ;
my $ template_id = 0 ,
my $ n_sort = 1 ;
2023-03-05 20:01:47 +01:00
my $ type_id = 300101 ;
my $ energy_id = 0 ;
2021-12-30 12:05:56 +01:00
$ template_id = $ R:: template_id if ( looks_like_number ( $ R:: template_id ) ) ;
$ n_sort = $ R:: n_sort if ( looks_like_number ( $ R:: n_sort ) ) ;
2023-03-05 20:01:47 +01:00
$ type_id = $ R:: type_id if ( looks_like_number ( $ R:: type_id ) ) ;
$ energy_id = $ R:: energy_id if ( looks_like_number ( $ R:: energy_id ) ) ;
2021-12-30 12:05:56 +01:00
my $ insert = {
main_id = > $ new_main_id ,
parent_id = > $ working_parent_id ,
template_id = > $ template_id ,
content_id = > 0 ,
node_name = > $ node_name ,
n_sort = > $ n_sort ,
2023-03-05 20:01:47 +01:00
type_id = > $ type_id ,
energy_id = > $ energy_id ,
2021-12-30 12:05:56 +01:00
owner = > $ owner ,
change = > "now()" ,
} ;
my $ rel_id = $ dbt - > insert_nodeoid ( $ dbh , $ insert ) ;
$ i_rows = 1 if ( $ rel_id > 0 ) ;
print FILE "new_relation with" . Dumper ( $ insert ) . "\n" if ( $ debug ) ;
#sub Servicelog for rental bikes
if ( $ template_id == 205 ) {
$ prefix_id + + ;
my $ new_submain_id = $ dbt - > get_freenode ( $ dbh , $ prefix_id ) ;
2022-04-04 14:57:43 +02:00
my $ new_subtemplate_id = $ dbt - > get_freetpl ( $ dbh , "401" , "499" ) ;
2021-12-30 12:05:56 +01:00
2023-03-05 20:01:47 +01:00
my $ ret_tpl_id = $ dbt - > copy_template ( $ dbh , "400" , $ new_subtemplate_id , "$node_name Service-Config" , $ owner ) ;
my $ ct_name = "$node_name Service-Config" ;
$ ct_name =~ s/^Flotte // ;
$ dbt - > copy_content ( $ dbh , "contentuser" , "400" , $ ret_tpl_id , "$ct_name" , $ owner ) ;
2021-12-30 12:05:56 +01:00
my $ insert_sub = {
main_id = > $ new_submain_id ,
parent_id = > $ new_main_id ,
template_id = > $ new_subtemplate_id ,
content_id = > 0 ,
node_name = > "$node_name-Servicelog" ,
n_sort = > $ n_sort ,
lang = > "de" ,
owner = > $ owner ,
change = > "now()" ,
} ;
my $ subrel_id = $ dbt - > insert_nodeoid ( $ dbh , $ insert_sub ) ;
$ i_rows += 1 if ( $ subrel_id > 0 ) ;
print FILE "new_subrelation with" . Dumper ( $ insert_sub ) . "\nwith template_id=$ret_tpl_id" if ( $ debug ) ;
}
close ( FILE ) if ( $ debug ) ;
2022-10-14 08:28:51 +02:00
my $ uri_path = $ dbt - > recurse_node ( $ dbh , $ new_main_id ) ;
2023-03-05 20:01:47 +01:00
print "$varenv{wwwhost}/$uri_path?node2edit=edit_relation\&return=$i_rows-$u_rows-$d_rows\n" ;
2021-12-30 12:05:56 +01:00
print redirect ( "$varenv{wwwhost}/$uri_path?return=$i_rows-$u_rows-$d_rows" ) ;
exit 0 ;
}
#end new_relation
#save node relation
sub save_relation {
my $ self = shift ;
2022-07-20 06:54:17 +02:00
my $ q = shift ;
2021-12-30 12:05:56 +01:00
my $ main_id = shift ;
my $ owner = shift ;
my % varenv = $ cf - > envonline ( ) ;
2022-05-18 10:53:29 +02:00
my @ keywords = $ q - > param ;
2021-12-30 12:05:56 +01:00
my $ dbh = "" ;
my $ update_node = {
table = > "nodes" ,
main_id = > "$main_id" ,
} ;
my $ update_relation = {
table = > "relation" ,
main_id = > "$main_id" ,
} ;
my $ subrelnode = $ dbt - > get_subrelnode ( $ dbh , $ main_id , "" , "" ) ;
foreach ( @ keywords ) {
my $ val = $ q - > param ( $ _ ) ;
my $ valxx = $ q - > escapeHTML ( "$val" ) ;
$ valxx =~ s/^\s+// ; $ valxx =~ s/\s+$// ;
if ( ( $ _ eq "node_name" ) && $ valxx ) {
#if defined another path
my $ node_name = $ valxx ;
my $ node_path = $ node_name ;
#internal for splitting node_name node_path
( $ node_name , $ node_path ) = split ( /\|/ , $ node_name ) if ( $ node_name =~ /\|/ ) ;
my $ return ;
$ return = $ lb - > checkinput ( $ node_name ) ;
$ return = $ lb - > checkinput ( $ node_path ) ;
return $ return if ( $ return =~ /failure/ ) ;
$ u_rows = $ dbt - > update_one ( $ dbh , $ update_node , "node_name='$node_name'" ) ;
$ u_rows = $ dbt - > update_one ( $ dbh , $ update_node , "node_path='$node_path'" ) ;
2022-07-12 19:59:44 +02:00
2021-12-30 12:05:56 +01:00
if ( $ subrelnode - > { main_id } && $ subrelnode - > { template_id } >= 400 && $ subrelnode - > { template_id } <= 499 ) {
my $ update_subnode = {
table = > "nodes" ,
main_id = > "$subrelnode->{main_id}" ,
} ;
$ u_rows = $ dbt - > update_one ( $ dbh , $ update_subnode , "node_name='$node_name-Servicelog'" ) ;
$ u_rows = $ dbt - > update_one ( $ dbh , $ update_subnode , "node_path='$node_path-Servicelog'" ) ;
}
2023-03-05 20:01:47 +01:00
} elsif ( $ _ =~ /template_id/ && $ valxx ) {
2021-12-30 12:05:56 +01:00
$ u_rows = $ dbt - > update_one ( $ dbh , $ update_relation , "template_id=$valxx" ) ;
2023-03-05 20:01:47 +01:00
} elsif ( $ _ =~ /int|n_sort|owner/ ) {
2021-12-30 12:05:56 +01:00
$ valxx =~ s/,/./ ;
$ valxx = "null" if ( ! $ valxx && $ valxx ne "0" ) ; #for empty
$ valxx = "0" if ( $ valxx eq "0" ) ;
$ u_rows = $ dbt - > update_one ( $ dbh , $ update_node , "$_=$valxx" ) if ( $ valxx =~ /^\d+$|null|0/ ) ;
2023-03-05 20:01:47 +01:00
} elsif ( $ _ eq "type_id" && $ valxx ) {
$ u_rows = $ dbt - > update_one ( $ dbh , $ update_node , "type_id=$valxx" ) ;
} elsif ( $ _ eq "energy_id" ) {
$ valxx = "null" if ( ! $ valxx || $ valxx eq "null" ) ;
$ u_rows = $ dbt - > update_one ( $ dbh , $ update_node , "energy_id=$valxx" ) ;
} elsif ( $ _ =~ /node_public/ ) {
2022-09-28 13:28:45 +02:00
$ valxx = "t" if ( $ valxx eq "1" || $ valxx eq "t" ) ;
$ valxx = "f" if ( ! $ valxx || $ valxx eq "f" ) ;
$ u_rows = $ dbt - > update_one ( $ dbh , $ update_node , "$_='$valxx'" ) ;
}
2023-03-05 20:01:47 +01:00
2021-12-30 12:05:56 +01:00
if ( ! - d "$varenv{data}/$main_id" ) {
mkdir ( "$varenv{data}/$main_id" , 0777 ) ;
mkdir ( "$varenv{data}/$main_id-thumb" , 0777 ) ;
mkdir ( "$varenv{data}/$main_id-resize" , 0777 ) ;
}
}
2022-10-14 08:28:51 +02:00
my $ uri_path = $ dbt - > recurse_node ( $ dbh , $ main_id ) ;
2023-03-05 20:01:47 +01:00
print redirect ( "$varenv{wwwhost}/$uri_path?node2edit=edit_relation\&return=$i_rows-$u_rows-$d_rows" ) ;
2021-12-30 12:05:56 +01:00
exit 0 ;
}
#delete node relation with some ki deleting sub content
sub delete_relation {
my $ self = shift ;
2022-12-19 14:21:53 +01:00
my $ q = shift ;
2021-12-30 12:05:56 +01:00
my $ main_id = shift ;
my $ owner = shift ;
my % varenv = $ cf - > envonline ( ) ;
my $ dbh = "" ;
my $ ret = "" ;
my $ debug = 1 ;
open ( FILE , ">>$varenv{logdir}/delete_relation.log" ) if ( $ debug ) ;
print FILE "\n*--> $now_dt| main_id: $main_id \n" if ( $ debug ) ;
#get all node para
my $ noderef = {
main_id = > $ main_id ,
fetch = > "one" ,
} ;
my $ noderel = $ dbt - > fetch_rel4tpl4nd ( $ dbh , $ noderef ) ;
my $ ctref = {
table = > "$noderel->{ct_table}" ,
main_id = > $ main_id ,
fetch = > "one" ,
c_id = > ">::0" ,
} ;
my $ ct_record = $ dbt - > fetch_record ( $ dbh , $ ctref ) ;
my $ collect_rows = 0 ;
2022-01-27 20:30:35 +01:00
if ( $ noderel - > { template_id } == 205 ) {
( my $ collect_node , $ collect_rows ) = $ dbt - > collect_noderel ( $ dbh , $ noderel - > { parent_id } , $ noderel - > { template_id } ) ;
2021-12-30 12:05:56 +01:00
}
my $ subrelnode = $ dbt - > get_subrelnode ( $ dbh , $ main_id , "" , "" ) ;
#if 1 then deleteable
my $ deleteable_subnode = 1 ;
my $ deleteable_node = 1 ;
my $ deleteable_last_node = 1 ;
2023-03-05 20:01:47 +01:00
if ( $ subrelnode - > { template_id } > 400 && $ subrelnode - > { template_id } < 499 ) {
2021-12-30 12:05:56 +01:00
$ deleteable_subnode = 1 ;
if ( $ collect_rows <= 1 ) {
$ deleteable_last_node = 0 ;
}
} elsif ( $ subrelnode - > { template_id } ) {
$ deleteable_subnode = 0 ;
}
if ( $ ct_record - > { c_id } > 0 ) {
$ deleteable_node = 0 ;
}
2022-01-27 20:30:35 +01:00
#print "$deleteable_subnode|$deleteable_node|$deleteable_last_node|$collect_rows";
print FILE "deleteable_subnode:$deleteable_subnode | deleteable_node:$deleteable_node | deleteable_last_node:$deleteable_last_node --> collect_rows: $collect_rows|c_id: $ct_record->{c_id}\n" if ( $ debug ) ;
2021-12-30 12:05:56 +01:00
if ( $ deleteable_last_node == 0 ) {
$ ret = "failure::Abbruch, es muss mindestens eine Mietrad Flotte definiert sein. ($collect_rows on $noderel->{parent_id})" ;
} elsif ( $ deleteable_subnode == 0 || $ deleteable_node == 0 ) {
$ ret = "failure::Abbruch, der Ordner enthält Daten. Für die referentielle Integrität ist es notwendig die Ordner Inhalte (content) und/oder Relationen des Ordners zu löschen. ($deleteable_subnode == 0 || $deleteable_node == 0 , $subrelnode->{template_id}, $main_id, $ct_record->{c_id}, $noderel->{ct_table})" ;
} else {
print FILE "delete_relation with $subrelnode->{main_id}, $subrelnode->{template_id}\n" if ( $ debug ) ;
if ( $ deleteable_subnode && $ subrelnode - > { main_id } ) {
2023-03-05 20:01:47 +01:00
if ( $ subrelnode - > { template_id } > 400 && $ subrelnode - > { template_id } < 499 ) {
$ dbt - > delete_content ( $ dbh , "contentpos" , "all" , $ subrelnode - > { template_id } ) ;
$ dbt - > delete_content ( $ dbh , "contentuser" , $ subrelnode - > { template_id } ) ;
}
2021-12-30 12:05:56 +01:00
$ d_rows += $ dbt - > delete_noderel ( $ dbh , $ subrelnode - > { main_id } ) ;
$ d_rows += $ dbt - > delete_template ( $ dbh , $ subrelnode - > { template_id } ) ;
}
$ d_rows += $ dbt - > delete_noderel ( $ dbh , $ main_id ) ;
remove_tree ( "$varenv{data}/$main_id" ) ;
remove_tree ( "$varenv{data}/$main_id-thumb" ) ;
remove_tree ( "$varenv{data}/$main_id-resize" ) ;
my $ uri_path = $ dbt - > recurse_node ( $ dbh , $ noderel - > { parent_id } ) ;
$ uri_path =~ s/\/\w+$// ;
print redirect ( "$varenv{wwwhost}/$uri_path?return=$i_rows-$u_rows-$d_rows" ) ;
exit 0 ;
}
close ( FILE ) if ( $ debug ) ;
return $ ret ;
}
#sharee Bonusnummer with Tarif automatic
sub set_usertarif {
my $ self = shift ;
my $ dbh = shift ;
my $ dbname = shift ;
my $ adr_bonus = shift ;
2022-01-16 12:17:11 +01:00
my $ bonus_collect = shift || { } ;
2021-12-30 12:05:56 +01:00
open ( FILE , ">>$varenv{logdir}/save_account.log" ) if ( $ debug ) ;
2022-07-20 06:54:17 +02:00
print FILE "\n*Prelib--> $now_dt| dbname: $dbname | c_id: $adr_bonus->{c_id} | txt15: $adr_bonus->{txt15}\n" if ( $ debug ) ;
2021-12-30 12:05:56 +01:00
2023-03-10 11:35:56 +01:00
my $ oprefix = $ dbt - > { operator } - > { $ dbname } - > { oprefix } ;
2021-12-30 12:05:56 +01:00
my $ ret = $ adr_bonus - > { ret } ;
my $ i = 0 ;
my $ dbh_operator = $ dbt - > dbconnect_extern ( $ dbname ) ; #operator connect
2023-03-10 11:35:56 +01:00
2023-04-24 14:49:30 +02:00
my $ tariff_all = { barcode = > 0 , int18 = > 0 } ;
2023-03-10 11:35:56 +01:00
my $ tariff = {
table = > "content" ,
fetch = > "all" ,
keyfield = > "barcode" ,
template_id = > "210" , #Tariff tpl_id
} ;
$ tariff_all = $ dbt - > fetch_record ( $ dbh_operator , $ tariff ) ;
my $ dbh_primary = $ dbt - > dbconnect_extern ( $ dbt - > { primary } - > { sharee_primary } - > { database } - > { dbname } ) ;
my $ adref = {
table = > "contentadr" ,
fetch = > "one" ,
template_id = > "202" ,
c_id = > "$adr_bonus->{c_id}" ,
} ;
my $ adr_primary = { c_id = > 0 } ;
$ adr_primary = $ dbt - > fetch_record ( $ dbh_primary , $ adref ) if ( $ adr_bonus - > { c_id } ) ;
#collect Tarif with prefix saving on primary
my % prim_tarif_hash = ( ) ;
if ( $ adr_primary - > { txt30 } && $ adr_primary - > { txt30 } =~ /\w\s\w/ ) {
% prim_tarif_hash = map { $ _ = > 1 } split ( /\s+/ , $ adr_primary - > { txt30 } ) ;
} elsif ( $ adr_primary - > { txt30 } ) {
$ prim_tarif_hash { $ adr_primary - > { txt30 } } = 1 ;
}
#first delete operator tarif in prim_tarif_hash. we will fill up downunder
foreach my $ rid ( sort { $ tariff_all - > { $ a } - > { barcode } <=> $ tariff_all - > { $ b } - > { barcode } } keys ( %$ tariff_all ) ) {
print FILE "--> Cleanup operator specific prim_tarif_hash: $tariff_all->{$rid}->{barcode}\n" ;
delete $ prim_tarif_hash { $ oprefix . $ tariff_all - > { $ rid } - > { barcode } } ;
}
2021-12-30 12:05:56 +01:00
if ( $ adr_bonus - > { txt15 } =~ /\w+/ ) {
if ( 1 == 1 ) {
2022-07-08 07:32:42 +02:00
my % tarif_hash = ( ) ;
2022-01-16 12:17:11 +01:00
my @ new_txt30 = ( ) ;
2023-03-10 11:35:56 +01:00
2022-01-16 12:17:11 +01:00
#collect multiple tarif by bonusnr
2021-12-30 12:05:56 +01:00
my $ pref_cc = {
table = > "content" ,
keyfield = > "c_id" ,
fetch = > "all" ,
template_id = > "228" ,
int03 = > ">::0" ,
2022-07-20 06:54:17 +02:00
ct_name = > "ilike::$adr_bonus->{txt15}" ,
2021-12-30 12:05:56 +01:00
} ;
2022-07-25 18:01:01 +02:00
2023-03-10 11:35:56 +01:00
$ bonus_collect = $ dbt - > fetch_record ( $ dbh_operator , $ pref_cc ) if ( ref ( $ bonus_collect - > { 1 } ) ne "HASH" ) ;
2022-07-25 18:01:01 +02:00
foreach my $ sourcetarif ( @ { $ adr_bonus - > { txt30_array } } ) {
$ tarif_hash { $ sourcetarif } = 1 ;
2023-03-10 11:35:56 +01:00
#additional and only! save privat or hidden tarif to primary to get caching
if ( $ tariff_all - > { $ sourcetarif } - > { int18 } == 3 || $ tariff_all - > { $ sourcetarif } - > { int18 } == 4 ) {
$ prim_tarif_hash { $ oprefix . $ sourcetarif } = 1 ;
}
2022-07-25 18:01:01 +02:00
}
2023-03-10 11:35:56 +01:00
print FILE "Prelib bonus_collect by request txt15: $adr_bonus->{txt15}\n" ;
2022-01-16 12:17:11 +01:00
foreach my $ id ( keys ( %$ bonus_collect ) ) {
2021-12-30 12:05:56 +01:00
$ i + + ;
2022-07-25 18:01:01 +02:00
print FILE "$i)-1-> loop bonus_collect and find $bonus_collect->{$id}->{ct_name} = $adr_bonus->{txt15}\n|==>Take and insert Tarif $bonus_collect->{$id}->{int22}\n" if ( $ debug ) ;
2023-03-10 11:35:56 +01:00
$ tarif_hash { $ bonus_collect - > { $ id } - > { int22 } } = 1 ;
#additional and only! save privat or hidden tarif to primary to get caching
if ( $ tariff_all - > { $ bonus_collect - > { $ id } - > { int22 } } - > { int18 } == 3 || $ tariff_all - > { $ bonus_collect - > { $ id } - > { int22 } } - > { int18 } == 4 ) {
$ prim_tarif_hash { $ oprefix . $ bonus_collect - > { $ id } - > { int22 } } = 1 ;
}
2022-12-21 15:03:45 +01:00
if ( $ bonus_collect - > { $ id } - > { int21 } && $ bonus_collect - > { $ id } - > { int21 } != $ bonus_collect - > { $ id } - > { int22 } ) {
2023-03-10 11:35:56 +01:00
print FILE "$i)-2-> delete if($bonus_collect->{$id}->{int21} && $bonus_collect->{$id}->{int21} != $bonus_collect->{$id}->{int22})\n" if ( $ debug ) ;
2022-07-25 18:01:01 +02:00
delete $ tarif_hash { $ bonus_collect - > { $ id } - > { int21 } } ;
2023-03-10 11:35:56 +01:00
delete $ prim_tarif_hash { $ oprefix . $ bonus_collect - > { $ id } - > { int21 } } ;
2022-12-21 15:03:45 +01:00
print FILE "$i)-3-> delete done $bonus_collect->{$id}->{int21}\n" if ( $ debug ) ;
2021-12-30 12:05:56 +01:00
}
2022-07-25 18:01:01 +02:00
2021-12-30 12:05:56 +01:00
}
2022-07-08 07:32:42 +02:00
@ new_txt30 = keys % tarif_hash ;
2021-12-30 12:05:56 +01:00
if ( @ new_txt30 ) {
2022-07-25 18:01:01 +02:00
print FILE "Final -3-> txt30: @new_txt30\n" if ( $ debug ) ;
2021-12-30 12:05:56 +01:00
$ u_rows = $ dbt - > update_one ( $ dbh_operator , $ adr_bonus , "txt30='@new_txt30'" ) ;
2022-06-02 10:34:03 +02:00
$ u_rows = $ dbt - > update_one ( $ dbh_operator , $ adr_bonus , "txt15='$adr_bonus->{txt15}'" ) ;
2023-03-10 11:35:56 +01:00
#collect Tarif with prefix saving on primary
my @ prim_txt30 = keys % prim_tarif_hash ;
$ u_rows = $ dbt - > update_one ( $ dbh_primary , $ adr_bonus , "txt30='@prim_txt30'" ) ;
2021-12-30 12:05:56 +01:00
}
$ ret = "failure::txt30#top2" if ( ! $ adr_bonus - > { txt30_array } || $ adr_bonus - > { txt30_array } !~ /\d/ ) ;
}
2023-03-10 11:35:56 +01:00
2021-12-30 12:05:56 +01:00
} else {
2023-03-10 11:35:56 +01:00
2021-12-30 12:05:56 +01:00
print FILE "-4-> update Tarif txt30: @{$adr_bonus->{txt30_array}}\n" if ( $ debug ) ;
$ u_rows = $ dbt - > update_one ( $ dbh_operator , $ adr_bonus , "txt30='@{$adr_bonus->{txt30_array}}'" ) ;
$ u_rows = $ dbt - > update_one ( $ dbh_operator , $ adr_bonus , "txt15=''" ) ;
2023-03-10 11:35:56 +01:00
#collect Tarif with prefix saving on primary
#delete bonus tarif on primary if not defined by operator
#additional and only! save privat or hidden tarif to primary to get caching
foreach my $ rid ( sort { $ tariff_all - > { $ a } - > { barcode } <=> $ tariff_all - > { $ b } - > { barcode } } keys ( %$ tariff_all ) ) {
foreach ( @ { $ adr_bonus - > { txt30_array } } ) {
if ( $ tariff_all - > { $ rid } - > { barcode } == $ _ && ( $ tariff_all - > { $ _ } - > { int18 } == 3 || $ tariff_all - > { $ _ } - > { int18 } == 4 ) ) {
print FILE "--> Adding private/hidden key on operator to primary: $_\n" ;
$ prim_tarif_hash { $ oprefix . $ _ } = 1 ;
}
}
}
my @ prim_txt30 = keys % prim_tarif_hash ;
$ u_rows = $ dbt - > update_one ( $ dbh_primary , $ adr_bonus , "txt30='@prim_txt30'" ) ;
2021-12-30 12:05:56 +01:00
$ ret = "failure::txt30#top3" if ( ! $ adr_bonus - > { txt30_array } || $ adr_bonus - > { txt30_array } !~ /\d/ ) ;
}
#if bonus value doesn't match
if ( $ adr_bonus - > { txt15 } && $ i == 0 ) {
print FILE "-5-> failure txt15: ''\n" if ( $ debug ) ;
$ ret = "failure::txt15#top4" ;
}
close ( FILE ) if ( $ debug ) ;
return $ ret ;
}
2022-05-13 10:38:03 +02:00
#save service-config
2022-05-11 08:05:35 +02:00
sub save_service_desc {
my $ self = shift ;
2022-07-20 06:54:17 +02:00
my $ q = shift ;
2022-05-11 08:05:35 +02:00
my $ users_dms = shift ;
2023-06-21 20:21:58 +02:00
my $ c_id = shift ;
2022-05-11 08:05:35 +02:00
my @ keywords = $ q - > param ;
2022-05-13 10:38:03 +02:00
my $ dbh = "" ;
my $ c_tplid = { c_id = > $ c_id } ;
my $ update_ctuser = {
table = > "contentuser" ,
template_id = > "199" ,
mtime = > "now()" ,
owner = > "$users_dms->{u_id}" ,
} ;
my $ update_template = {
table = > "template" ,
tpl_id = > "$c_id" ,
owner = > "$users_dms->{u_id}" ,
} ;
2022-05-11 08:05:35 +02:00
2022-05-13 10:38:03 +02:00
open ( FILE , ">>$varenv{logdir}/save_service_desc.log" ) if ( $ debug ) ;
print FILE "\n*Prelib--> $now_dt | ctpl_id $c_id | owner: $users_dms->{u_id}\n" if ( $ debug ) ;
my $ tpl_order_desc = "c_id=ID=4=0=0,mtime=Zeitstempel=6=0=0,owner=von=3=0=0,barcode=Rad=3=0=0,txt01=Aufgaben=area5-8=0=0" ;
2022-05-11 08:05:35 +02:00
foreach ( @ keywords ) {
my @ val = $ q - > param ( $ _ ) ;
my $ valxx = $ q - > escapeHTML ( "@val" ) ;
2022-05-13 10:38:03 +02:00
$ valxx =~ s/\s/=/g ;
print FILE $ _ . ":" . $ valxx . "<br>\n" ;
2022-05-13 20:00:25 +02:00
my $ count = 0 ;
+ + $ count while $ valxx =~ /=/g ;
return "failure::Abbruch. Die Wartungsnamen dienen als Schlüsselwerte und dürfen somit keine Leer- oder Sonderzeichen enthalten ($valxx). Das Speichern wurde abgebrochen!" if ( $ count > 4 ) ;
2022-05-13 10:38:03 +02:00
#txt01:int01=Reifen-Bremse-Lampe=checkbox=10=2
2022-05-13 20:00:25 +02:00
if ( $ _ =~ /txt\d+/ && $ valxx =~ /int\d+=[a-z-]+=checkbox=\d+=\d/i ) {
2022-05-13 10:38:03 +02:00
$ update_ctuser - > { $ _ } = "$valxx" ;
$ tpl_order_desc . = ",$valxx" ;
2023-02-16 19:52:49 +01:00
} else {
$ update_ctuser - > { $ _ } = "" ;
$ tpl_order_desc . = "" ;
2022-05-11 08:05:35 +02:00
}
}
2022-05-13 10:38:03 +02:00
print FILE "update contentuser c_id:$c_id\n" . Dumper ( $ update_ctuser ) . "\n" ;
print FILE "update template tpl_id:$c_id\n" . $ tpl_order_desc . "\n" ;
my $ rows = 0 ;
$ rows = $ dbt - > update_record ( $ dbh , $ update_ctuser , $ c_tplid ) ;
$ rows = $ dbt - > update_one ( $ dbh , $ update_template , "tpl_order='$tpl_order_desc'" ) ;
2022-05-11 08:05:35 +02:00
2022-05-13 10:38:03 +02:00
close ( FILE ) if ( $ debug ) ;
return $ rows ;
2022-05-11 08:05:35 +02:00
}
2022-10-11 07:00:25 +02:00
#Operator Accounting
sub operator_accounting {
my $ self = shift ;
2022-12-19 14:21:53 +01:00
my $ q = shift ;
2022-10-11 07:00:25 +02:00
my $ users_dms = shift ;
my $ users_sharee = shift ;
my $ accounting_type = shift || "" ;
my $ ck4ex = shift || "" ;
my $ dbh = "" ;
my % varenv = $ cf - > envonline ( ) ;
2022-10-14 08:28:51 +02:00
open ( FILE , ">>$varenv{logdir}/operator_accounting.log" ) if ( $ debug ) ;
print FILE "\n*--> $now_dt| accounting_type: $accounting_type | owner: $users_dms->{u_id}\n" if ( $ debug ) ;
print FILE "Invoice c_id's ck4ex: $ck4ex\n" ;
2022-10-11 07:00:25 +02:00
my $ accounting_main_id = 300029 ;
2022-10-14 08:28:51 +02:00
my $ node_faktura = $ dbt - > get_node ( $ dbh , $ dbt - > { shareedms_conf } - > { faktura } ) ;
my $ node = $ dbt - > get_node ( $ dbh , $ accounting_main_id ) ;
my $ praefix = "$node->{node_name}-$varenv{praefix}" ;
my $ ret = "" ;
my $ c_idnew = "" ;
if ( $ ck4ex ) {
2022-10-18 20:15:11 +02:00
my $ opuser = {
table = > "contentuser" ,
fetch = > "one" ,
c_id = > 2 ,
} ;
my $ ctuser = $ dbt - > fetch_tablerecord ( $ dbh , $ opuser ) ;
$ c_idnew = $ dbt - > insert_contenttrans ( $ dbh , $ ctuser , $ accounting_main_id , "208" , "----" , $ users_dms - > { u_id } ) ;
2022-10-14 08:28:51 +02:00
if ( $ c_idnew ) {
2022-10-18 20:15:11 +02:00
print FILE "c_idnew: $c_idnew\n" ;
2022-10-14 08:28:51 +02:00
$ i_rows + + ;
my $ ctt = { c_id = > $ c_idnew } ;
my $ update_ctt = {
table = > "contenttrans" ,
int12 = > $ node - > { main_id } ,
txt00 = > $ node - > { node_name } ,
mtime = > "now()" ,
owner = > $ users_dms - > { u_id } ,
} ;
2022-10-31 08:11:53 +01:00
my $ tplop = $ dbt - > get_tpl ( $ dbh , "196" ) ; #Operator-Faktura
my @ tplop_order = split /,/ , $ tplop - > { tpl_order } ;
foreach ( @ tplop_order ) {
my ( $ key , $ val , $ size , $ unit ) = split /=/ , $ _ ;
if ( $ key =~ /int(\d+)/ ) {
#take fee values used by creating operator accounting invoice
my $ count_key = $ 1 + 20 ; #cu.int to ctt.int
my $ ctt_key = "int" . $ count_key ;
$ update_ctt - > { $ ctt_key } = $ ctuser - > { $ key } if ( $ ctuser - > { $ key } ) ;
}
}
2022-10-14 08:28:51 +02:00
$ dbt - > update_record ( $ dbh , $ update_ctt , $ ctt ) ;
2022-10-11 07:00:25 +02:00
my $ pref = {
table = > "contenttrans" ,
fetch = > "one" ,
main_id = > $ accounting_main_id ,
template_id = > 208 ,
2022-10-14 08:28:51 +02:00
c_id = > $ c_idnew ,
2022-10-11 07:00:25 +02:00
} ;
$ ctt = $ dbt - > fetch_record ( $ dbh , $ pref ) ;
$ bw - > log ( "operator_accounting used invoice c_id:" , $ ctt - > { c_id } , "" ) ;
2022-10-14 08:28:51 +02:00
$ ck4ex =~ s/\s/,/g ;
$ dbt - > update_sql ( $ dbh , "UPDATE contenttrans set int20='$ctt->{c_id}' where c_id IN ($ck4ex)" ) ;
2022-10-18 20:15:11 +02:00
print FILE "UPDATE contenttrans set int20='$ctt->{c_id}' where c_id IN ($ck4ex)\n" ;
2022-10-14 08:28:51 +02:00
2023-10-26 06:50:16 +02:00
my $ update_users = {
table = > "users" ,
change = > "no_time" ,
u_id = > $ users_dms - > { u_id }
} ;
$ dbt - > update_one ( $ dbh , $ update_users , "c_id4trans=$c_idnew,tpl_id4trans=208" ) ;
2022-10-14 08:28:51 +02:00
}
my $ uri_path = $ dbt - > recurse_node ( $ dbh , $ node - > { main_id } ) ;
print "$varenv{wwwhost}/$uri_path?return=$i_rows-$u_rows-$d_rows\n" ;
print redirect ( "$varenv{wwwhost}/$uri_path?return=$i_rows-$u_rows-$d_rows" ) ;
exit 0 ;
} else {
$ ret = "failure::Abbruch, es wurden keine Belege selektiert." ;
}
2022-10-18 20:15:11 +02:00
close FILE ;
2022-10-14 08:28:51 +02:00
return $ ret ;
2022-10-11 07:00:25 +02:00
}
2023-03-05 20:01:47 +01:00
#CSV Export
sub export_csv {
my $ self = shift ;
my $ node_meta = shift ;
my $ users_dms = shift ;
my $ ct4rel = shift || { } ;
my $ coo = shift || "" ;
my $ time = time ;
my % varenv = $ cf - > envonline ( ) ;
my $ scol = "c_id" ;
my $ feedb = { message = > "" } ;
2023-04-12 16:12:19 +02:00
$ node_meta - > { tpl_order } =~ s/txt06=[\w\s=]+,/byte01=Ilockit Token,/ if ( $ node_meta - > { tpl_id } == 205 ) ;
2023-03-05 20:01:47 +01:00
my @ tpl_order = split ( /,/ , $ node_meta - > { tpl_order } ) ;
my $ csv_export = Text::CSV_XS - > new ( { binary = > 1 , sep_char = > ";" , eol = > "\r\n" } ) ;
my $ filename_csv_export = "$dbt->{operator}->{$varenv{dbname}}->{oprefix}-$node_meta->{node_name}-Export-$time.csv" ;
my @ header_line = ( ) ;
open my $ csv , ">" , "$varenv{csv}/$filename_csv_export" or die "$filename_csv_export: $!\n" ;
foreach ( @ tpl_order ) {
my ( $ key , $ val , $ size , $ title ) = split /=/ , $ _ ;
push @ header_line , $ val ;
}
$ csv_export - > print ( $ csv , \ @ header_line ) ; #header
foreach my $ id ( sort {
if ( $ users_dms - > { sort_updown } eq "down" ) {
if ( $ scol =~ /barcode|int/ ) {
$ ct4rel - > { $ b } - > { $ scol } <=> $ ct4rel - > { $ a } - > { $ scol }
} else {
lc ( $ ct4rel - > { $ b } - > { $ scol } ) cmp lc ( $ ct4rel - > { $ a } - > { $ scol } )
}
} else {
if ( $ scol =~ /barcode|int/ ) {
$ ct4rel - > { $ a } - > { $ scol } <=> $ ct4rel - > { $ b } - > { $ scol }
} else {
lc ( $ ct4rel - > { $ a } - > { $ scol } ) cmp lc ( $ ct4rel - > { $ b } - > { $ scol } )
}
}
} keys ( %$ ct4rel ) ) {
my @ line = ( ) ;
foreach ( @ tpl_order ) {
my ( $ key , $ val , $ size , $ title ) = split /=/ , $ _ ;
2023-04-12 16:12:19 +02:00
if ( $ key =~ /byte/ ) {
my $ K_int = unpack "H*" , $ ct4rel - > { $ id } - > { $ key } ;
push @ line , $ K_int ;
} else {
push @ line , $ ct4rel - > { $ id } - > { $ key } ;
}
2023-03-05 20:01:47 +01:00
}
$ csv_export - > print ( $ csv , \ @ line ) ;
}
if ( - f "$varenv{basedir}/csv/$filename_csv_export" ) {
print "<script type=\"text/javascript\">window.open('$varenv{wwwhost}/FileOut?file=$filename_csv_export\&sessionid=$coo');</script>" ;
} else {
$ feedb - > { message } = "failure:: Der CSV Export von \"$filename_csv_export\" ist fehlgeschlagen." ;
}
return $ feedb ;
}
2023-08-01 07:47:54 +02:00
#prepare email standalone for extern email client posting
#partly adapted from mailTransportcms
#attachement breaks, that's because not used
2023-07-27 07:05:23 +02:00
sub prepare_email {
my $ self = shift ;
2023-08-01 07:47:54 +02:00
my $ varenv = shift ;
my $ ct_id = shift || "" ;
my $ email_select = shift || "" ;
my $ dbh = "" ;
my $ cms_prim = $ varenv - > { cms } - > { $ email_select } - > { txt } ;
#mailxcfg is shareeconf/mailx.cfg <block> selection!
#hash data to send
my $ sendref = {
mailxcfg = > "mailx_default" ,
syshost = > "$varenv->{syshost}" ,
mail_from = > "" ,
mail_to = > "" ,
mail_bcc = > "" ,
c_id = > 0 ,
subject = > "" ,
message = > "" ,
signature = > "" ,
attachment = > "" ,
} ;
my $ fetchctt = {
table = > "contenttrans" ,
fetch = > "one" ,
c_id = > "=::$ct_id" ,
} ;
my $ ctt = { c_id = > 0 } ;
$ ctt = $ dbt - > fetch_tablerecord ( $ dbh , $ fetchctt ) ;
my $ dbh_primary = $ dbt - > dbconnect_extern ( $ dbt - > { primary } - > { sharee_primary } - > { database } - > { dbname } , "iso-8859-1" ) ;
my $ pref_adr = {
table = > "contentadr" ,
fetch = > "one" ,
c_id = > "$ctt->{int10}" ,
} ;
my $ ctadr = { c_id = > 0 } ;
$ ctadr = $ dbt - > fetch_tablerecord ( $ dbh_primary , $ pref_adr ) ;
2023-07-27 07:05:23 +02:00
my $ app_name = "Mietrad App" ;
$ app_name = $ dbt - > { operator } - > { $ varenv { dbname } } - > { app_name } ;
my $ invoice_name = "" ;
my $ sharee_ticket = "" ;
if ( ref ( $ ctt ) eq "HASH" && $ ctt - > { ct_name } ) {
$ invoice_name = "$ctt->{txt00}-$varenv{dbname}-$ctt->{ct_name}.pdf" ;
$ sendref - > { attachment } = "$invoice_name" ;
$ sharee_ticket = "[$varenv{dbname}-$ctt->{ct_name}]" ;
}
my $ subject = "TeilRad Mietradsystem" ; #default
$ subject = $ 1 if ( $ cms_prim =~ /--subject--(.*)--subject--/ ) ;
$ cms_prim =~ s/--subject--$subject--subject--// ;
2023-08-01 07:47:54 +02:00
$ subject . = " $sharee_ticket" if ( $ sharee_ticket ) ;
2023-07-27 07:05:23 +02:00
$ cms_prim =~ s/\n// ;
$ cms_prim =~ s/\n// ;
2022-12-16 08:37:05 +01:00
2023-07-27 07:05:23 +02:00
$ sendref - > { mail_to } = $ ctadr - > { txt08 } ;
$ sendref - > { c_id } = $ ctadr - > { c_id } ;
$ sendref - > { subject } = $ subject ;
$ sendref - > { subject } =~ s/::app_name::/$app_name/ ;
$ sendref - > { subject } =~ s/Mein // if ( $ sendref - > { subject } =~ /^Mein/ ) ;
$ sendref - > { message } = $ cms_prim ;
$ sendref - > { message } =~ s/::user_name::/$ctadr->{txt01}/ ;
$ sendref - > { message } =~ s/::app_name::/$app_name/g ;
$ sendref - > { message } =~ s/::invoice_name::/$invoice_name/ if ( $ invoice_name ) ;
$ sendref - > { message } =~ s/::txid::/$ctt->{txt16}/ ;
$ sendref - > { message } =~ s/::email_temppassword::/\<b\>$ctadr->{txt04}\<\/b\>/g ;
$ sendref - > { message } =~ s/::email_ack_digest::/\<b\>$ctadr->{txt34}\<\/b\>/g ; #send_emailack
#$sendref->{message} =~ s/\n/\<br \/\>/g;
return $ sendref ;
2023-08-01 07:47:54 +02:00
} #end prepare_email
2023-07-27 07:05:23 +02:00
1 ;