App API bike_returned json extension. Longterm rental messaging by email. Check if invoice was booked before mailing

This commit is contained in:
ragu 2023-09-14 14:11:37 +02:00
parent 8cc46ff9e0
commit e7959e2da9
9 changed files with 207 additions and 71 deletions

View file

@ -29,12 +29,14 @@ use DateTime::Format::Pg;
use Scalar::Util qw(looks_like_number);
use Lib::Config;
use Mod::DBtank;
use Mod::Prelib;
use Mod::MailTransport;
use Data::Dumper;
my $cf = new Config;
my %varenv = $cf->envonline();
my $dbt = new DBtank;
my $pl = new Prelib;
my $mailtrans = new MailTransport;
my $now_dt = strftime "%Y.%m.%d %H:%M:%S", localtime;
@ -106,6 +108,7 @@ if(looks_like_number($adr_id)){
if(($todo eq "send_cpupdate_message" || $todo eq "send_proactive_cpupdate_message")){
$sendmail = send_cpupdate_message($todo,$sendref,$ctadr);
}
}#end user-account message
#send_alarm2hotline, done by Ilockit_cloud.pl
@ -118,38 +121,50 @@ if($todo eq "send_occupied2hotline"){
$sendmail = send_occupied2hotline($sendref);
}
#send_invoice_onwork once a week as reminder [in Arbeit|eMail gesendet]
if($todo eq "send_invoice_onwork"){
#final send
if(ref($sendmail) eq "HASH" && $sendmail->{c_id}){
sendmailjob($sendmail);
}else{
print EMA "Error, can not sendmailjob without c_id\n";
}
#user messaging for all operators by one cronjob
if($todo eq "send_invoice_onwork" || $todo eq "email_longterm_occupied"){
#loop operators DB
while (my ($key, $op_name) = each %{ $dbt->{operator} }) {
if($op_name->{database}->{dbname}){
my $rows = 0;
my $sharee_operator = $op_name->{database}->{dbname};
my $dbh = "";
$dbh = $dbt->dbconnect_extern($sharee_operator);
$dbh = $dbt->dbconnect_extern($sharee_operator,"iso-8859-1");
$oprefix = $op_name->{oprefix} || "";
$sendref->{syshost} = "$syshost";
$sendmail = send_invoice_onwork($dbh,$oprefix,$sendref);
if($sendmail->{c_id}){
#send_invoice_onwork once a week as reminder [in Arbeit|eMail gesendet]
if($todo eq "send_invoice_onwork"){
$sendmail = send_invoice_onwork($dbh,$oprefix,$sendref);
}
#email_longterm_occupied, done by cronjob (enhance/substitute sms_message 24h_occupied job)
if($todo eq "email_longterm_occupied"){
$sendmail = email_longterm_occupied($dbh,$oprefix,$sendref);
}
#final send
if(ref($sendmail) eq "HASH" && $sendmail->{c_id}){
sendmailjob($sendmail);
}
}
}
}
if($sendmail->{c_id}){
sendmailjob($sendmail);
}else{
print EMA "Error, can not sendmailjob without c_id\n";
}
}#end user messaging for all operators by one cronjob
#send_invoice
sub send_invoice {
my $todo = shift || "";
my $sendref = shift || {};
my $ctadr = shift || "";
my $ctadr = shift || {};
my $ct_id = shift || "";
my $cms_message_key = shift || "email-invoice";
my $with_pdf = shift || "";
@ -190,8 +205,8 @@ sub send_invoice {
$ctt->{fibu_user} = "$fibu_owner->{txt01}" if($fibu_owner->{txt01});
}
$sendref = prepare_content($sendref,$ctadr,$uadr,$ctt,$varenv{cms}->{$cms_message_key}->{txt},$with_pdf);
my $ctadr_invoice = $ctt;#take adr from invoice for account-less mailing
$sendref = prepare_content($sendref,$ctadr_invoice,$uadr,$ctt,$varenv{cms}->{$cms_message_key}->{txt},$with_pdf);
my $updatectt = {
table => "contenttrans",
@ -294,6 +309,7 @@ sub send_cpupdate_message {
}#end send_cpupdate_message
#send_alarm2hotline
sub send_alarm2hotline {
my $sendref = shift;
@ -415,7 +431,6 @@ sub send_invoice_onwork {
my $dbh = shift;
my $oprefix = shift || "";
my $sendref = shift;
my $ct_id = shift || "";
my $dbh_primary = $dbt->dbconnect_extern($dbt->{primary}->{sharee_primary}->{database}->{dbname},"iso-8859-1");
@ -470,6 +485,36 @@ EOF
return;
}#end send_invoice_onwork
#greater 12h_mailmessage
#TODO test ....
sub email_longterm_occupied {
my $dbh = shift;
my $oprefix = shift || "";
my $sendref = shift;
#operator contact
my $pref_ctu = {
table => "contentuser",
fetch => "one",
c_id => "1",
};
my $uadr = { c_id => 0 };
$uadr = $dbt->fetch_tablerecord($dbh,$pref_ctu);
my $longterm_ctadr = {};
$longterm_ctadr = $pl->longterm_occupied(\%varenv);
my $lang = $longterm_ctadr->{txt11} || "de";
$varenv{cms} = $dbt->fetch_cms($dbh,{ lang => $lang });
my $cms_message_key = "";
$cms_message_key = "email-" . $longterm_ctadr->{hours} . "h-occupied" if($longterm_ctadr->{hours});
if($longterm_ctadr->{posting} eq "email" && $varenv{cms}->{$cms_message_key}->{txt}){
$sendref = prepare_content($sendref,$longterm_ctadr,$uadr,"",$varenv{cms}->{$cms_message_key}->{txt});
}
return $sendref;
}#end email_longterm_occupied
#prepare email by cms markup
sub prepare_content {
@ -484,15 +529,15 @@ sub prepare_content {
$app_name = $dbt->{operator}->{$varenv{dbname}}->{app_name};
my $invoice_name = "";
my $invoice_nr = "";
my $sum_total = "";
my $total_sum = "";
my $sharee_ticket = "";
my $fibu_user = "";
if(ref($ctt) eq "HASH" && $ctt->{ct_name}){
$invoice_name = "$ctt->{txt00}-$varenv{dbname}-$ctt->{ct_name}.pdf";
$sendref->{attachment} = "$invoice_name" if($with_pdf);
$invoice_nr = "$varenv{dbname}-$ctt->{ct_name}";
$sum_total = "$ctt->{int01}";
$sum_total =~ s/\./,/;
$total_sum = "$ctt->{int01}";
$total_sum =~ s/\./,/;
$sharee_ticket = "[$invoice_nr]";
$fibu_user = "\n$ctt->{fibu_user}\n" if($ctt->{fibu_user});
}
@ -526,9 +571,10 @@ EOF
$sendref->{message} = $cms_prim;
$sendref->{message} =~ s/::user_name::/$ctadr->{txt01}/g;
$sendref->{message} =~ s/::bike::/$ctadr->{bike}/g if($ctadr->{bike});
$sendref->{message} =~ s/::app_name::/$app_name/g;
$sendref->{message} =~ s/::invoice_nr::/\<b\>$invoice_nr\<\/b\>/g if($invoice_nr);
$sendref->{message} =~ s/::sum_total::/\<b\>$sum_total €\<\/b\>/g if($sum_total);
$sendref->{message} =~ s/::total_sum::/\<b\>$total_sum €\<\/b\>/g if($total_sum);
$sendref->{message} =~ s/::invoice_name::/$invoice_name/g if($invoice_name);
$sendref->{message} =~ s/::txid::/$ctt->{txt16}/;
$sendref->{message} =~ s/::email_temppassword::/\<b\>$ctadr->{txt04}\<\/b\>/g;