operator accounting Invoices

This commit is contained in:
ragu 2022-10-14 08:28:51 +02:00
parent dd84259e6d
commit 819592a77d
14 changed files with 604 additions and 148 deletions

View file

@ -645,23 +645,7 @@ sub service_update(){
$update->{$key} = $q->escapeHTML($q->param('work_val'));
}
}
}elsif(1==2){#TODO template key REST mapping
my @keywords = $q->param;
foreach (@tpl_order){
my ($key,$val,$size,$interval) = split /=/,$_;
foreach(@keywords){
if($_ eq $key){
#key validation will be done by update_record
$update->{$_} = $q->escapeHTML($q->param($key));
}
}
#unchecked checkbox doesn't deliver values. Thats the solution
#disabled delete values at all. Test with json API conflicts because we disabled checkboxes
#$update->{$key} = "null" if($key =~ /^int\d+$/ && $key !~ /^int04/ && !looks_like_number($update->{$key}));
#$update->{$key} = "NaN" if($key =~ /^txt01$/ && !$update->{$key});#sepcial on TINK Service
}
}
my $rows = $dbt->update_record($dbh,$update,$record) if($record->{c_id} > 0);
return $rows;
@ -689,7 +673,7 @@ sub bikestate_update(){
if(ref($update_hash) eq "HASH" && looks_like_number($update_hash->{int04})){
$update->{int04} = "$update_hash->{int04}";
}
$bw->log("check state on bikestate_update 1.",$update,"");
$bw->log("bikestate_update bike to state c_id $c_id | $update->{int04} | $state | auth:$auth->{c_id}",$update,"");
my $record = { c_id => $c_id };
my $rows = $dbt->update_record($dbh,$update,$record) if($record->{c_id} > 0);
@ -1913,10 +1897,10 @@ sub bikes_available(){
my $max_bars = 5;
my $current_bars = 0;
my $charge_view_hidden = 1;#1=hide charge view
$charge_view_hidden = 0 if($dbt->{operator}->{$varenv->{dbname}}->{oprefix} =~ /FR|KN/);
$charge_view_hidden = 0 if($dbt->{operator}->{$varenv->{dbname}}->{oprefix} =~ /BVB|FR|KN/);
my $backend_accessible = 1;
#$backend_accessible = 0 if($record->{$id}->{int11} eq "2");#for asking user
$backend_accessible = 0 if($dbt->{operator}->{$varenv->{dbname}}->{oprefix} =~ /FR|KN/);#for asking user
$backend_accessible = 0 if($dbt->{operator}->{$varenv->{dbname}}->{oprefix} =~ /BVB|FR|KN/);#for asking user
$return->{$id}->{bike_type}->{battery}->{charge_max_bars} = "$max_bars";
$return->{$id}->{bike_type}->{battery}->{charge_current_bars} = "$current_bars";
$return->{$id}->{bike_type}->{battery}->{charge_current_percent} = "0";
@ -2087,10 +2071,10 @@ sub bikes_all(){
my $max_bars = 5;
my $current_bars = 0;
my $charge_view_hidden = 1;#1=hide charge view
$charge_view_hidden = 0 if($dbt->{operator}->{$varenv->{dbname}}->{oprefix} =~ /FR|KN/);
$charge_view_hidden = 0 if($dbt->{operator}->{$varenv->{dbname}}->{oprefix} =~ /BVB|FR|KN/);
my $backend_accessible = 1;#1=battery charge from backend, 0=asking user
#$backend_accessible = 0 if($record->{$id}->{int11} eq "2");#for asking user
$backend_accessible = 0 if($dbt->{operator}->{$varenv->{dbname}}->{oprefix} =~ /FR|KN/);#for asking user
$backend_accessible = 0 if($dbt->{operator}->{$varenv->{dbname}}->{oprefix} =~ /BVB|FR|KN/);#for asking user
$return->{$id}->{bike_type}->{battery}->{charge_max_bars} = "$max_bars";
$return->{$id}->{bike_type}->{battery}->{charge_current_bars} = "$current_bars";
$return->{$id}->{bike_type}->{battery}->{charge_current_percent} = "0";

View file

@ -30,7 +30,6 @@ sub ibuttons(){
'barcode' => 'Barcode Label drucken',
'buchen' => 'buchen',
'send_invoice_again' => 'senden',
'order_state' => 'Auftragsstatus',
'new_contenttver' => 'Neues Arbeitsprofil',
'new_content' => 'NEUER Datensatz',
'new_content_2' => 'Add New Optical Instrument',

View file

@ -531,6 +531,20 @@ sub select_worktime {
return $record;
}
#all accounting position of contenttrans
sub collect_contenttrans(){
my $self = shift;
my $dbh = shift || $dbh_intern;
my $ct_id = shift || "";
my $sth = $dbh->prepare("SELECT * FROM contenttrans where int20 = $ct_id");
my $rc = $sth->execute();
my $cpos = $sth->fetchall_hashref("c_id");
my $rows = $sth->rows;
return ($cpos,$rows);
}
#all position of contenttrans
sub collect_contentpos(){
my $self = shift;

View file

@ -376,7 +376,8 @@ sub handler {
if($R::ct_trans =~ /set_workflow2invoice|set_workflow2storno/){
$return = $pl->set_workflow($users_dms,$R::c_id4trans,$R::set_main_id4workflow) if(looks_like_number($R::c_id4trans) && looks_like_number($R::tpl_id4trans) && looks_like_number($R::set_main_id4workflow));
}elsif($R::detail_search && $R::detail_search eq "operator_accounting"){
$return = $pl->operator_accounting($users_dms,$users_sharee,$R::accounting_type,$R::ck4ex);
my $ck4ex = "@R::ck4ex" || "";
$return = $pl->operator_accounting($users_dms,$users_sharee,$R::accounting_type,$ck4ex);
}else{
$return .= "|";
$return .= $pre->preinit($users_dms,$lang);#transactions logic

View file

@ -648,29 +648,31 @@ sub payone_capture(){
int14 => 2,
};
#Node and HoleCkeck depended auto Rechnungs-Nummer
my $node_faktura = $dbt->get_node($dbh,$dbt->{shareedms_conf}->{faktura});
my $node = $dbt->get_node($dbh,$main_id);#Rechnung node
if($node->{invoice_nr} > 0){
if($node_faktura->{invoice_nr} > 0){
if($ctt->{ct_name} !~ /\d/){
my $nextNr = $node->{invoice_nr};
my $nextNr = $node_faktura->{invoice_nr};
$update_ctt->{ct_name} = "$nextNr";
$update_ctt->{barcode} = "$nextNr";
my $update_node = {
table => "nodes",
main_id => "$main_id",
main_id => "$dbt->{shareedms_conf}->{faktura}",
change => "no_time",
};
my $invoice_nr = $node->{invoice_nr} + 1;
my $invoice_nr = $node_faktura->{invoice_nr} + 1;
$dbt->update_one($dbh,$update_node,"invoice_nr='$invoice_nr'");
}
}else{
$return_text = "payone_cron Payment.pm exit, $node->{invoice_nr} | $ctt->{ct_name} can not generate invoice number\n";
$return_text = "payone_cron Payment.pm exit, $node_faktura->{invoice_nr} | $ctt->{ct_name} can not generate invoice number\n";
return $return_text;
}
my $state = $ctt->{state};
if($varenv->{Zahlungsweise}){
my @_paymentstate = split(/\|/,$varenv->{Zahlungsweise});
if($dbt->{shareedms_conf}->{payment_state}){
my @_paymentstate = split(/\|/,$dbt->{shareedms_conf}->{payment_state});
if($ctadr->{int03} && $ctadr->{int03} == 1 && $ctadr->{ct_name} =~ /\w{2}-\d+/){
$state = "$_paymentstate[0]";
}else{

View file

@ -431,7 +431,7 @@ sub set_workflow {
}
$db->update_users4trans($c_idnew,"218","",$users_dms->{u_id});
my $uri_path = $dbt->recurse_node("",$node->{main_id});
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;
@ -518,7 +518,7 @@ sub new_relation {
close(FILE) if($debug);
my $uri_path = $dbt->recurse_node("",$new_main_id);
my $uri_path = $dbt->recurse_node($dbh,$new_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;
@ -606,7 +606,7 @@ sub save_relation {
mkdir("$varenv{data}/$main_id-resize",0777);
}
}
my $uri_path = $dbt->recurse_node("",$main_id);
my $uri_path = $dbt->recurse_node($dbh,$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;
@ -821,29 +821,55 @@ sub operator_accounting {
my $ck4ex = shift || "";
my $dbh = "";
my %varenv = $cf->envonline();
my $print_return = "";
my $exit_code = 1;
my $ctt = {
ct_name => "Abrechnung-123",
txt00 => "Abrechnung",
};
my $praefix = "$ctt->{txt00}-$varenv{praefix}";
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";
close FILE;
my $accounting_main_id = 300029;
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 $auth = $users_sharee;#workaround, must be operator addr.
my $c_idnew = "";
if($ck4ex){
$c_idnew = $dbt->insert_contenttrans($dbh,$auth,$accounting_main_id,"208","----",$users_dms->{u_id});
if($c_idnew){
$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},
};
$dbt->update_record($dbh,$update_ctt,$ctt);
if(1==1){#TODO
my $auth = $users_sharee;#workaround, must be operator addr.
my $ct_id = $dbt->insert_contenttrans($dbh,$auth,$accounting_main_id,"208","----",$users_dms->{u_id});
my $pref = {
table => "contenttrans",
fetch => "one",
main_id => $accounting_main_id,
template_id => 208,
c_id => $ct_id
c_id => $c_idnew,
};
$ctt = $dbt->fetch_record($dbh,$pref);
$bw->log("operator_accounting used invoice c_id:",$ctt->{c_id},"");
$ck4ex =~ s/\s/,/g;
$dbt->update_sql($dbh,"UPDATE contenttrans set int20='$ctt->{c_id}' where c_id IN ($ck4ex)");
if(1==2){#should only be done on buchen
my $print_return = "";
my $exit_code = 1;
my $psize="A4";
my $wc_line=0;
#$wc_line= $ctt->{int04};#Adresse.Tabelle
@ -857,15 +883,26 @@ sub operator_accounting {
print EMA "$now_dt\n$topdf --page-size $psize $varenv{wwwhost}/Printpreview?printer_id=operator_accounting\&mandant_main_id=$dbt->{shareedms_conf}->{parent_id}\&main_id=$accounting_main_id\&ct_name2print=$ctt->{ct_name}\&c_id4trans=$ctt->{c_id}\&u_id=$users_dms->{u_id}\&wc=$wc_line $varenv{pdf}/$praefix-$ctt->{ct_name}.pdf\n $print_return\nfilesize: $filesize\nexit_code: $exit_code\n\n";
close EMA;
#exit 0;
}
if( -f "$varenv{basedir}/pdf/$praefix-$ctt->{ct_name}.pdf"){
print "<script type=\"text/javascript\">window.open('$varenv{wwwhost}/pdf/$praefix-$ctt->{ct_name}.pdf');</script>";
}else{
return "failure::PDF konnte nicht generiert werden\n $varenv{wwwhost}/pdf/$praefix-$ctt->{ct_name}.pdf";
}
}
return;
$db->update_users4trans($c_idnew,"208","",$users_dms->{u_id});
}
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.";
}
return $ret;
}
1;

View file

@ -114,7 +114,6 @@ sub preinit(){
my $mandant_main_id = 100002;
my $parent_trans = $db->get_node3("$mandant_main_id","Faktura","$lang") if($mandant_main_id);
my $ctf = $db->get_content1("contentuser","$mandant_main_id");
my $ctb = $db->get_content1("contentuser","$users_dms->{u_id}");
if(!$parent_trans->{main_id}){
return "failure::Fehler<br /> keine eindeutige Modulzuweisung vorhanden.";
@ -451,7 +450,7 @@ sub preinit(){
$add_menge = - $ct_exist2->{$_} + $intxx if($op eq "+");
my $rows = $db->update_content4comp("contenttranspos",$R::ct_name,$R::c_idpos,"$op","$add_menge","$R::kind_of_trans");
if($rows){
$u_rows += $db->update_content4comp("content",$R::ct_name,"$R::cc_id","-","$add_menge","$R::kind_of_trans","$ct_exist2->{txt12}") if(($R::kind_of_trans =~ /Faktur|Verleih/) && ($ctt->{txt00} !~ /Angebot|Kostenvoranschlag|Auftrag/) && ("$ctb->{txt02}" ne "aus"));
$u_rows += $db->update_content4comp("content",$R::ct_name,"$R::cc_id","-","$add_menge","$R::kind_of_trans","$ct_exist2->{txt12}");
}
}else{
$u_rows +=$db->updater("$table","c_id",$c_id,"$_","$valxx");
@ -502,16 +501,10 @@ sub preinit(){
$table = "contenttrans" if($ib_key =~ /delete_trans/);
my $ctt = $db->get_content1("$table","$c_id4del");
if(($R::kind_of_trans =~ /Faktur|Verleih/) && ($ctt->{txt00} !~ /Angebot|Kostenvoranschlag|Auftrag|Storno/) && ("$ctb->{txt02}" ne "aus")){
my ($cttpos,$rows) = $db->collect_contentpos("$table","$c_id4del");
foreach my $id (sort { lc($cttpos->{$a}->{sort}) cmp lc($cttpos->{$b}->{sort}) } keys(%$cttpos)){
$db->update_content4comp("content",$cttpos->{$id}->{ct_name},"$cttpos->{$id}->{cc_id}","+","$cttpos->{$id}->{int03}","$users_dms->{kind_of_trans}","$cttpos->{$id}->{txt12}");
#my @packc_ids = split(/,/,$cttpos->{$id}->{txt05});
#foreach(@packc_ids){
# $db->update_content4comp("content","","$_","+","$cttpos->{$id}->{int03}","$R::kind_of_trans","$cttpos->{$id}->{txt12}");
#}
}
}
$d_rows += $db->delete_content("$table","$c_id4del");
$db->update_users4trans("0","0","",$users_dms->{u_id});
@ -543,13 +536,7 @@ sub preinit(){
$d_rows += $db->delete_content("$table","$pos_id");
$db->users_up("ctpos_activ","0",$users_dms->{u_id}) if("$pos_id" eq "$users_dms->{ctpos_activ}");
$ct_name = $1 if($R::ct_name =~ /^(\d+)/);
if(($R::kind_of_trans =~ /Faktur|Verleih/) && ($ctt->{txt00} !~ /Angebot|Kostenvoranschlag|Auftrag/) && ("$ctb->{txt02}" ne "aus")){
$u_rows += $db->update_content4comp("content",$ct_name,"$cttpos->{cc_id}","+","$cttpos->{int03}","$R::kind_of_trans","$cttpos->{txt12}");
#my @packc_ids = split(/,/,$cttpos->{txt05});
# foreach(@packc_ids){
# $db->update_content4comp("content","","$_","+","$cttpos->{int03}","$R::kind_of_trans","$cttpos->{txt12}");
# }
}
$u_rows += $db->update_content4comp("content",$ct_name,"$cttpos->{cc_id}","+","$cttpos->{int03}","$R::kind_of_trans","$cttpos->{txt12}");
}
###
@ -574,15 +561,11 @@ sub preinit(){
my $ctt = { c_id => 0 };
my $rel = $db->get_rel4tpl("",$lang,$users_dms->{c_id4trans},$users_dms->{tpl_id4trans});
$ctt = $db->get_content1("contenttrans",$rel->{content_id});
my ($node,$ct_exist);
return "failure::Bitte erst einen Formular-Typ wählen" if($R::set_main_id <= "300000");
$u_rows += $db->update_relation2("",$lang,$R::set_main_id,"",$rel->{rel_id}) if(!$R::close_time && $rel->{rel_id});
#$node = $db->get_node4multi($R::set_main_id,$lang);
$node = $dbt->get_node($dbh,$R::set_main_id);
#if($node->{main_id} > 300000){
# my $rows = $node->{int10} + 1;
# $db->updater("nodes","main_id",$node->{main_id},"int10",$rows);
#}
my $node_faktura = $dbt->get_node($dbh,$dbt->{shareedms_conf}->{faktura});
my $node = $dbt->get_node($dbh,$R::set_main_id);
my $update_ctt = {
table => "contenttrans",
@ -590,36 +573,22 @@ sub preinit(){
owner => $users_dms->{u_id},
};
#Node and HoleCkeck depended auto Rechnungs-Nummer
if(($node->{invoice_nr} > 0) && ("$ctt->{ct_name}" !~ /\d/ || "$R::set_main_id" != "$rel->{main_id}")){
if(($node_faktura->{invoice_nr} > 0) && ("$ctt->{ct_name}" !~ /\d/ || "$R::set_main_id" != "$rel->{main_id}")){
my $nextNr = $node->{invoice_nr};
my $nextNr = $node_faktura->{invoice_nr};
$update_ctt->{ct_name} = "$nextNr";
$update_ctt->{barcode} = "$nextNr";
my $update_node = {
table => "nodes",
main_id => "$R::set_main_id",
main_id => "$dbt->{shareedms_conf}->{faktura}",
change => "no_time",
};
my $invoice_nr = $node->{invoice_nr} + 1;
my $invoice_nr = $node_faktura->{invoice_nr} + 1;
$dbt->update_one($dbh,$update_node,"invoice_nr='$invoice_nr'");
#}elsif($ctt->{ct_name} !~ /\d/){
#$db->update_content4change($table,$c_id,$c_id,$c_id,"barcode") ;
}
#Change Formular Type -----------------------------------------------
#if("$R::set_main_id" != "$rel->{main_id}"){
if(($R::ct_trans =~ /print_pdf|print/i) || ("$R::set_main_id" != "$rel->{main_id}")){
my $table = "contenttrans";
$u_rows += $db->update_content4change($table,$c_id,"",$R::set_main_id,"int12");#zusätzl. Formtyp
$db->update_content4change($table,$c_id,"",$node->{node_name},"txt00");#node_name
$db->update_content4change($table,$c_id,"",$ctb->{txt06},"txt13") if($ctb->{txt06});#vendor name
$db->update_content4change($table,$c_id,"","txt61,txt63","txt21") if($node->{node_name} =~ /Mietvertrag/);#Text-3
$db->update_content4change($table,$c_id,"","txt64","txt21") if($node->{node_name} =~ /Rückgabe/);#Text-4
$db->update_content4change($table,$c_id,"","$R::mtime_changed","mtime") if($today !~ /$R::mtime_changed/);#invoice date
$update_ctt->{int12} = $node->{main_id};
$update_ctt->{txt00} = $node->{node_name};
$u_rows += $dbt->update_record($dbh,$update_ctt,$ctt);
}
#SET state alias Zahlung buchen
@ -634,7 +603,7 @@ sub preinit(){
$update_ctt->{int01} = "$sum_paid";
$update_ctt->{state} = "$state";
$update_ctt->{int14} = 2 if($state =~ /payone/);#set OPOS
$dbt->update_record($dbh,$update_ctt,$ctt);
$u_rows += $dbt->update_record($dbh,$update_ctt,$ctt);
if($state =~ /payone/){
my $ctadr = $db->get_content1("contentadr",$ctt->{int10});

View file

@ -341,9 +341,6 @@ sub save_account(){
owner => "198",
};
my $c_id_op = $dbt->insert_contentoid($dbh_operator,$insert_op,"reset_adropkeys");
if($bonus_record->{c_id} > 3){#means if not file greped with static kn c_id
$dbt->update_content4comp($dbh_operator,$bonus_record->{c_id},"-","1");
}
if($bonus_collect->{1}->{int22} && $bonus_collect->{2}->{int22} && $bonus_collect->{3}->{int22}){
@txt30_op = ("$bonus_collect->{1}->{int22}","$bonus_collect->{2}->{int22}","$bonus_collect->{3}->{int22}");
@ -364,8 +361,17 @@ sub save_account(){
owner => $owner,
ret => $ret,
};
$ctadr_operator = $dbt->fetch_record($dbh_operator,$authref);
print FILE "operator adr update preview with bonusnr:\n" . Dumper($adr_bonus) . "\n";
$ret = $pl->set_usertarif($dbh,$operator_conf->{database}->{dbname},$adr_bonus,$bonus_collect);
#count down only if not file greped with static kn c_id and not still used
print FILE "bonus_record update_content4comp by: $bonus_record->{c_id} > 3 && $bonus_record->{int03} > 0 && (!$ctadr_operator->{txt15} || $bonus_record->{ct_name} !~ /$ctadr_operator->{txt15}/i)\n";
if($bonus_record->{c_id} > 3 && $bonus_record->{int03} > 0 && (!$ctadr_operator->{txt15} || $bonus_record->{ct_name} !~ /$ctadr_operator->{txt15}/i)){
$dbt->update_content4comp($dbh_operator,$bonus_record->{c_id},"-","1");
}
}else{
$ret = "failure::txt15#top7";
}