package TransInvoices; # # SPDX-License-Identifier: AGPL-3.0-or-later # Copyright (c) Rainer Gümpelein, TeilRad GmbH # # use strict; use warnings; use POSIX; use CGI; use CGI::Carp qw(fatalsToBrowser); use CGI ':standard'; use DateTime; use DateTime::Format::Pg; use Date::Calc::Object qw(:ALL); use Scalar::Util qw(looks_like_number); use Data::Dumper; use Lib::Config; use Mod::Buttons; use Mod::Libenz; use Mod::DBtank; use Mod::APIfunc; use Mod::Pricing; sub new { my $class = shift; my $self = {}; bless($self,$class); return $self; } #Template sub tpl(){ my $self = shift; my $varenv = shift; my $node_meta = shift; my $users_dms = shift; my $ctf = shift; my $ctadr = shift; my $ctt = shift; my $q = new CGI; my $cf = new Config; my $lb = new Libenz; my $dbt = new DBtank; my $apif = new APIfunc; my $but = new Buttons; my $pri = new Pricing; my %ib = $but->ibuttons(); my $today = strftime "%d.%m.%Y",localtime; my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime; my $coo = $q->cookie(-name=>'domcookie'); my $dbh = ""; my $line_count2 = 0; my $tc=0; my $vibuchen_mtime = $lb->time4de($ctt->{mtime},1); my $txt20 = $R::txt20 || $ctt->{txt20} || "";#Leistungsdatum my $int05 = $R::int05 || $ctt->{int05} || "";#manuell my $rows = 0; my @tpl_order = (); my $cttpos = { c_id => 0 }; my $ctf_operator = { c_id => 0 }; my $pref_cuop = { table => "contentuser", fetch => "one", c_id => 2, }; $ctf_operator = $dbt->fetch_tablerecord($dbh,$pref_cuop); #take original operator accounting c_id to collect related invoices #operator invoice if($ctt->{template_id} != 208){#not equal Abrechnung my $pref = { table => "contenttrans", fetch => "one", barcode => $ctt->{barcode}, txt00 => "Abrechnung", }; my $ctt_accounting = $dbt->fetch_record($dbh,$pref); ($cttpos,$rows) = $dbt->collect_contenttrans($dbh,$ctt_accounting->{content_id}); #int9x are not in db @tpl_order = ("c_id=ID","int01=Netto Erlös","state=Zahlungsart","int93=Entgelt TeilRad GmbH"); } #operator accounting else{ ($cttpos,$rows) = $dbt->collect_contenttrans($dbh,$ctt->{content_id}); #int9x are not in db if($varenv->{dbname} eq "sharee_sx"){ @tpl_order = ("c_id=ID","int01=Netto Erlös","state=Zahlungsart","int94=Disagio","int02=Gutschrift"); }else{ @tpl_order = ("c_id=ID","int01=Netto Erlös","state=Zahlungsart","int94=Disagio","int95=Transaktion","int96=Zahlungsmeldung","int97=Kreditkarte Zuordnung","int02=Gutschrift"); } } my $tplf = $dbt->get_tpl($dbh,201);#Kunden-Faktura Firma my @tplf_order = split /,/,$tplf->{tpl_order}; print $q->start_table({-class=>'list', -border=>'0', -width=>'100%',-align=>'left', -cellpadding=>'3', -cellspacing=>'0'}),"\n"; print $q->hidden(-name=>'offset', -override=>'1', -value=>"$R::offset"),"\n" if($R::offset); print $q->hidden(-name=>'limit', -override=>'1', -value=>"$R::limit"),"\n" if($R::limit); print $q->hidden(-name=>'c_id4trans', -override=>'1', -value=>"$ctt->{content_id}"),"\n"; print $q->hidden(-name=>'tpl_id4trans', -override=>'1', -value=>"$ctt->{template_id}"),"\n"; $line_count2++; print $q->Tr(),"\n"; #print $q->th("Pos."),"\n"; foreach (@tpl_order){ my ($key,$val) = split /=/,$_; $tc++ if($val); $val .= " ($key)" if($users_dms->{u_id} eq $varenv->{superu_id}); print $q->th("$val"),"\n"; } print $q->start_form(-name=>'transposform'),"\n"; my $sum_operatorcredit=0; my $sum_netto=0; my $sum_brutto=0; my $sum_all=0; my $sum_umst19=0; my $i=0; my $accounting_start = ""; my $accounting_end = ""; foreach my $id (sort { $cttpos->{$b}->{c_id} <=> $cttpos->{$a}->{c_id} } keys(%$cttpos)){ my $oac = $pri->operator_accounting2calc($varenv,$cttpos->{$id},$ctf_operator); $sum_operatorcredit += $oac->{int02};#Abrechnung Gutschrift $sum_netto += $oac->{int100};#Operator invoice (TeilRad Gebühren netto) $sum_all += $oac->{int99};#capture brutto $oac->{int01} = sprintf('%.2f', $oac->{int01});#capture netto if(1==1){ $i++; $line_count2++; if($i==1){ #pay_time only if payone capture, else invoice_time my $pitime = $cttpos->{$id}->{pay_time} || $cttpos->{$id}->{invoice_time}; if($pitime && $pitime =~ /(\d+)\-(\d+)\-(\d+)/){ my $year = $1; my $month = $2; my $days4month = Days_in_Month($year,$month); $accounting_start = "01.$month.$year"; $accounting_end = "$days4month.$month.$year"; } } print $q->Tr(),"\n"; #print $q->td({-class=>'tdint'},"$i"),"\n"; foreach (@tpl_order){ my ($key,$val) = split /=/,$_; $cttpos->{$id}->{$key} = $q->unescapeHTML($cttpos->{$id}->{$key}); my $txtstyle = "text-align:left;min-width:100px;"; if($key =~ /int\d+/){ $txtstyle = "text-align:right;min-width:50px;"; } if(1==1){ if($key =~ /ct_name/){ #print $q->td({-class=>'tdtxt'},"\# $cttpos->{$id}->{$key} $cttpos->{$id}->{txt01}"),"\n"; print $q->td({-class=>'tdtxt'},"\# $cttpos->{$id}->{$key}"),"\n"; } elsif($key =~ /c_id/){ print $q->td({-class=>'tdint'},"$cttpos->{$id}->{$key}"),"\n"; } elsif($key =~ /int/){ $oac->{$key} =~ s/\./,/; print $q->td({-class=>'tdint',-nowrap=>1},"$oac->{$key} €"),"\n"; } elsif($key =~ /state/){ print $q->td({-class=>'tdint',-nowrap=>1},"$cttpos->{$id}->{$key}"),"\n"; } elsif($key =~ /txt/){ print $q->td({-class=>'tdtxt'},"$cttpos->{$id}->{$key}"),"\n"; } } } } }#foreach end #sum int100 netto if($sum_netto && $sum_netto != 0){ $sum_brutto = $sum_netto * 1.19; $sum_netto = $pri->round($sum_netto); $sum_brutto = $pri->round($sum_brutto); $sum_umst19 = $sum_brutto - $sum_netto; } $sum_operatorcredit = $pri->round($sum_operatorcredit); my $total_operatorcredit = $sum_operatorcredit - $sum_brutto; my $sum_paid = $sum_brutto; $sum_netto = sprintf('%.2f', $sum_netto); $sum_netto =~ s/\./,/; $sum_brutto = sprintf('%.2f', $sum_brutto); $sum_brutto =~ s/\./,/; $sum_umst19 = sprintf('%.2f', $sum_umst19); $sum_umst19 =~ s/\./,/; $sum_operatorcredit = sprintf('%.2f', $sum_operatorcredit); $sum_operatorcredit =~ s/\./,/; $total_operatorcredit = sprintf('%.2f', $total_operatorcredit); $total_operatorcredit =~ s/\./,/; $sum_all = sprintf('%.2f', $sum_all); $sum_all =~ s/\./,/; my $payment_text = ""; foreach(@tplf_order){ my ($key,$des,$size) = split /=/,$_; if($key =~ /txt5\d/){ $ctf->{$key} = $q->unescapeHTML("$ctf->{$key}"); $ctf->{$key} = $lb->newline($ctf->{$key},"",""); $ctt->{state} =~ s/\(payone.*//; if($des =~ /$ctt->{state}/){ $payment_text = "($key) " if($users_dms->{u_id} eq $varenv->{superu_id}); if($sum_netto < 0){ $payment_text .= "$ctf->{txt58}"; }else{ $payment_text .= "$ctf->{$key}"; } } } } my $sc = 2; $sc = 1 if($ctt->{template_id} != 208); my $pt = $tc - $sc; print "