Faktura set_workflow refactore

This commit is contained in:
Rainer Gümpelein 2022-03-17 20:28:28 +01:00
parent f1285c1c36
commit 6a99d40224
9 changed files with 144 additions and 187 deletions

View file

@ -72,9 +72,11 @@ auswerten',
'search_adr' => 'Kunden suchen',
'search_extrakt' => 'extrakt',
'change_login' => 'ID',
'print_pdf' => 'Print PDF',
'print_pdf' => ' PDF ',
'set_relation' => 'Formular',
'set_workflow' => 'Workflow',
'set_workflow2invoice' => 'Rechnung erstellen',
'set_workflow2storno' => 'Storno erstellen',
'relate_content' => 'Content-Menu Relation',
'relate_dialog' => 'Relation herstellen',
'relate_dialog4menu' => 'Relation herstellen',
@ -573,7 +575,6 @@ sub singlesubmit6(){
return $button;
}
# international hack
sub singlesubmit3(){
my $self = shift;
my ($function,$b_name,$b_img,$style,$title) = @_;
@ -586,13 +587,13 @@ sub singlesubmit3(){
$ib_value = $val;
}
}
my $button = "<button class='ebutton2' style='cursor:default;height:17px;'></button>";
my $button = "<button class='ebutton' style='height:17px;'></button>";
if("$b_name" =~ /delete/){
$button = "<button type='submit' onClick=\"return confirm('Wirklich löschen?')\" class='ebutton2' style='$style' name='$function' value='$ib_key'>$ib_value</button>";
$button = "<button type='submit' onClick=\"return confirm('Wirklich löschen?')\" class='ebutton' style='$style' name='$function' value='$ib_key'>$ib_value</button>";
}elsif($b_img){
$button = "<button type='submit' class='ebutton2' name='$function' value='$ib_key' title='$title' ><img src='$b_img' style='$style' /></button>";
$button = "<button type='submit' class='ebutton' name='$function' value='$ib_key' title='$title' ><img src='$b_img' style='$style' /></button>";
}elsif($b_name){
$button = "<button type='submit' class='ebutton2' style='$style' name='$function' value='$ib_key'>$ib_value</button>";
$button = "<button type='submit' class='ebutton' style='$style' name='$function' value='$ib_key'>$ib_value</button>";
}
return $button;
}

View file

@ -948,7 +948,7 @@ sub insert_contentoid {
my $reset_keys = shift || "";
my $source = $dbh->get_info( $GetInfoType{SQL_DATABASE_NAME} );
if($reset_keys eq "reset_adropkeys"){
if($insert->{table} eq "contentadr" && $reset_keys eq "reset_adropkeys"){
delete $insert->{txt17};#operators
delete $insert->{txt30} if($source ne "sharee_lv" && $insert->{txt30} ne "5511");#Tarif, exception sharee_lv
delete $insert->{txt15};#Bonusnr

View file

@ -18,6 +18,7 @@ use Apache2::RequestIO ();
use Apache2::Const -compile => qw(OK);
use LWP::UserAgent;
use Digest::MD5 qw(md5 md5_hex);
use Scalar::Util qw(looks_like_number);
#use Encode;
#use URI::Encode qw(uri_encode uri_decode);
@ -359,13 +360,17 @@ sub handler {
#DMS Faktura
if($node_meta->{ct_table} eq "contenttrans"){
$bw->log("DMS action from $users_dms->{u_id} on $node_meta->{ct_table}|$R::c_id4trans,$R::tpl_id4trans,$R::kind_of_trans with: $R::ct_trans","","");
$bw->log("DMS action from $users_dms->{u_id} on $node_meta->{ct_table}|$R::c_id4trans,$R::tpl_id4trans with: $R::ct_trans","","");
if($users_dms->{int03} == 1 && $R::ct_trans eq "open"){#DMS Faktura read
$db->update_users4trans($R::c_id4trans,$R::tpl_id4trans,$R::kind_of_trans,$users_dms->{u_id}) if($R::c_id4trans && $R::tpl_id4trans);
$db->update_users4trans($R::c_id4trans,$R::tpl_id4trans,"",$users_dms->{u_id}) if(looks_like_number($R::c_id4trans) && looks_like_number($R::tpl_id4trans));
}elsif($users_dms->{int03} == 2){#DMS Faktura rw
$db->update_users4trans($R::c_id4trans,$R::tpl_id4trans,$R::kind_of_trans,$users_dms->{u_id}) if($R::c_id4trans && $R::tpl_id4trans);
$return .= "|";
$return .= $pre->preinit($users_dms,$lang);#transactions logic
$db->update_users4trans($R::c_id4trans,$R::tpl_id4trans,"",$users_dms->{u_id}) if(looks_like_number($R::c_id4trans) && looks_like_number($R::tpl_id4trans));
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));
}else{
$return .= "|";
$return .= $pre->preinit($users_dms,$lang);#transactions logic
}
}elsif($R::ct_trans){
$return = "failure::Abbruch. Schreibender Zugriff \"Faktura\" verweigert.";
}

View file

@ -213,7 +213,7 @@ sub captureSEPA_main {
my $pref = {
table => "contenttrans",
fetch => "one",
template_id => 218,
#template_id => 218,
c_id => $ctt_rec->{c_id},
};
my $ctt = { c_id => 0 };
@ -350,7 +350,7 @@ sub captureCC_main {
my $pref = {
table => "contenttrans",
fetch => "one",
template_id => 218,
#template_id => 218,
c_id => $ctt_rec->{c_id},
};
my $ctt = { c_id => 0 };

View file

@ -48,6 +48,100 @@ my $now_dt = strftime "%Y-%m-%d %H:%M:%S", localtime;
my $debug=1;
#set Faktura workflow like Rechnung to Storno
sub set_workflow {
my $self = shift;
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};
delete $ctt->{txt16};
delete $ctt->{txt12};
delete $ctt->{txt21};
delete $ctt->{txt22};
delete $ctt->{txt23};
delete $ctt->{txt30};
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);
#print Dumper($insert_ctt);
#exit;
#position copy
if($c_idnew > 0){
my ($cttpos,$rows) = $db->collect_contentpos("contenttrans",$c_id);
foreach my $id (sort { lc($cttpos->{$a}->{sort}) cmp lc($cttpos->{$b}->{sort}) } keys(%$cttpos)){
$cttpos->{$id}->{int02} = $cttpos->{$id}->{int02} * -1 if($cttpos->{$id}->{int02} != 0);
$cttpos->{$id}->{int07} = $cttpos->{$id}->{int07} * -1 if($cttpos->{$id}->{int07} != 0 && $cttpos->{$id}->{int08} == 1);#if Rabatt int08 != 1 alias €;
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);
}
}
$db->update_users4trans($c_idnew,"218","",$users_dms->{u_id});
my $uri_path = $dbt->recurse_node("",$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_workflow
#new node relation with option to create subnode for Servicelog
sub new_relation {
my $self = shift;

View file

@ -486,122 +486,10 @@ sub preinit(){
}
###SET workflow (like copy doc-type)
#follows address copy
#1. counter for WaWi and ReNr
my $c_id4trans = $R::c_id4trans;#It needs hidden posts. Only implemented in Address and Transact
if($R::set_workflow && $R::set_main_id4workflow && $R::ct_name4workflow =~ /\d/){
return "failure::Bitte erst einen Formular-Typ wählen" if($R::set_main_id4workflow <= "300000");
$table = "contenttrans";
my $foreign_key="ct_id";
my $j="1";
$rel = $db->get_rel4tpl("",$lang,$c_id4trans,$R::tpl_id4trans);
my $set_tpl = $db->get_rel4tpl($R::set_main_id4workflow,$lang,"","","ASC");
my $backlink = $R::ct_name4workflow;
my $ct_name = $R::ct_name4workflow;
my $subname= 1;
($ct_name,$subname) = split(/-/,$R::ct_name4workflow) if($R::ct_name4workflow =~ /\d+-\d+/);
my $lastct_name = $db->get_like2sort($table,"ct_name","$ct_name-");
if($lastct_name->{ct_name}){
($ct_name,$subname) = split(/-/,$lastct_name->{ct_name});
$subname++;
}
my $ct_name_new = "$ct_name-$subname";
my $barcode = "$ct_name$subname";
###Vorsicht, redundanter code-abschnitt = set_main_id
my ($node,$ct_exist);
$node = $db->get_node4multi($R::set_main_id4workflow,$lang);
if($node->{main_id} > 300000){
my $rows = $node->{int10} + 1;
$db->updater("nodes","main_id",$node->{main_id},"int10",$rows);
}
#Node abhängige auto Beleg-Nummer
my $journal_nodes = "$ctf->{txt23}";
$journal_nodes .= "|$ctf->{txt24}" if($ctf->{txt24});
$journal_nodes .= "|$ctf->{txt25}" if($ctf->{txt25});
if(($node->{int06} > 0) && ("$R::set_main_id4workflow" != "$rel->{main_id}") && ("$rel->{main_id}" !~ /$journal_nodes/) && ($node->{node_name} !~ /steuerfrei/)){
$ct_exist = $db->get_ctrel2($table,$node->{int06},$R::set_main_id4workflow,$lang);
if($ct_exist->{rel_id}){
return "failure::Konflikt, die Nummer \"$ct_exist->{ct_name}\" ist bereits vergeben.";
}
#$ct_name_new = "$node->{int06}" . "-$ct_name";#neue subNummer
#$barcode = "$node->{int06}" . "$ct_name";
$ct_name_new = "$node->{int06}";
$barcode = "$node->{int06}";
my $int06 = $node->{int06} + 1;
$u_rows += $db->updater("nodes","main_id",$R::set_main_id4workflow,"int06",$int06,"","","","","no_time");
}
###
$ct_exist = $db->get_ctrel2($table,$ct_name_new,"",$lang,"","",$set_tpl->{tpl_id});
if($ct_exist->{ct_name} && $node->{node_name} !~ /Storno/){
return "failure::Der Vorgang mit der Nummer \"$ct_exist->{ct_name}\" ist bereits vorhanden";
}
$c_idnew = $db->insert_content2($table,$ct_name_new,$users_dms->{u_id},"");
$i_rows += 1 if($c_idnew > 0);
my $rel_id = $db->insert_relationlist($table,$R::set_main_id4workflow,$lang,$c_idnew,$set_tpl->{tpl_id},$foreign_key);
$node = $db->get_node4multi($R::set_main_id4workflow,$lang);
$db->updater($table,"c_id",$c_idnew,"close_time","null");
#2017-08-10 adapted from lx-rad, set backlink for workflow documentation
$db->updater($table,"c_id",$c_idnew,"txt04","$backlink");
$db->update_content4change($table,$c_idnew,"",$barcode,"barcode");
$db->update_content4change($table,$c_idnew,"",$parent_trans->{parent_id},"int09");#mandant_id
$db->update_content4change($table,$c_idnew,"",$R::set_main_id4workflow,"int12");#zusätzl. Formtyp
$db->update_content4change($table,$c_idnew,"",$node->{node_name},"txt00");#node_name
$db->update_content4change($table,$c_idnew,"","txt61,txt63","txt21") if($node->{node_name} =~ /Mietvertrag/);#Text-3
$db->update_content4change($table,$c_idnew,"","txt64","txt21") if($node->{node_name} =~ /Rückgabe/);#Text-4
$db->update_content4change($table,$c_idnew,"","txt65","txt21") if($node->{node_name} =~ /steuerfrei/);#Text-5
$db->update_users4trans($c_idnew,$set_tpl->{tpl_id},$R::kind_of_trans,$R::owner);
$node = $db->get_node4multi($R::set_main_id4workflow,$lang);
my $old_node = $db->get_node4multi($rel->{main_id},$lang);
#workflow
#print "$old_node->{node_name} ---> $node->{node_name}";
#position copy
my ($cttpos,$rows) = $db->collect_contentpos("$table",$c_id4trans);
foreach my $id (sort { lc($cttpos->{$a}->{sort}) cmp lc($cttpos->{$b}->{sort}) } keys(%$cttpos)){
#2019-05-24, adding Storno (300009) to Rechnung
if(($node->{node_name} =~ /Storno/) || ($R::set_main_id eq "300009" && $node->{node_name} =~ /Rechnung/)){
$cttpos->{$id}->{int02} = $cttpos->{$id}->{int02} * -1 if($cttpos->{$id}->{int02} != 0);
$cttpos->{$id}->{int07} = $cttpos->{$id}->{int07} * -1 if($cttpos->{$id}->{int07} != 0 && $cttpos->{$id}->{int08} == 1);#if Rabatt int08 != 1 alias €;
if($R::kind_of_trans =~ /Faktur/){
$db->update_content4comp("content",$cttpos->{$id}->{ct_name},"$cttpos->{$id}->{cc_id}","+","$cttpos->{$id}->{int03}","$R::kind_of_trans","$cttpos->{$id}->{txt12}");
}
}
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);
}
$db->update_users4trans($c_idnew,$set_tpl->{tpl_id},$R::kind_of_trans,$R::owner);
$users_dms = $db->select_users($users_dms->{u_id});
$c_id4trans = $users_dms->{c_id4trans};
}
####
#copy ADD ADDRESS from contentadr to contenttrans
#Attention, doupled saved over Terminal AND over set_workflow
#All Verkauf-Terminal submits without Print PDF!
#
if(($R::ct_trans !~ /print_pdf|print/i) && (($ib_key eq "add_transadr") || $R::ct_trans2c_idadr || $R::set_main_id || $R::set_main_id4workflow)){
my $c_id4trans = $R::c_id4trans || "";#It needs hidden posts. Only implemented in Address and Transact
#TODO
if(1==2 && ($R::ct_trans !~ /print_pdf|print/i) && (($ib_key eq "add_transadr") || $R::ct_trans2c_idadr || $R::set_main_id || $R::set_main_id4workflow)){
$c_id4trans = $users_dms->{c_id4trans} if($ib_key eq "add_transadr" && $users_dms->{c_id4trans});
if(!$c_id4trans){
return "failure::Wohin damit? Für die Zuweisung bitte erst ein Ziel öffnen.";