X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Far.pl;h=a6e122067512ee8e52fa1535fc68e9ed24969d13;hb=71e8211613ad1bfb473f33588521d70c27be1de3;hp=f03a74b7db99e31804a02c9b305b06f4fa12fad2;hpb=262e507798455abefd32b096875e03b1efe64336;p=kivitendo-erp.git diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl index f03a74b7d..a6e122067 100644 --- a/bin/mozilla/ar.pl +++ b/bin/mozilla/ar.pl @@ -76,8 +76,6 @@ use strict; # $locale->text('Nov') # $locale->text('Dec') -my $totalpaid; - sub add { $main::lxdebug->enter_sub(); @@ -92,12 +90,12 @@ sub add { if(!exists $form->{addition} && ($form->{id} ne "")) { $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; $form->{addition} = "ADDED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->save_history; } # /saving the history $form->{title} = "Add"; - $form->{callback} = "ar.pl?action=add" unless $form->{callback}; + $form->{callback} = "ar.pl?action=add&DONT_LOAD_DRAFT=1" unless $form->{callback}; AR->get_transdate(\%myconfig, $form); $form->{initial_transdate} = $form->{transdate}; @@ -217,7 +215,7 @@ sub form_header { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; my ($title, $readonly, $exchangerate, $rows); my ($taxincluded, $notes, $department, $customer, $employee, $amount, $project); @@ -273,17 +271,9 @@ sub form_header { $form->{exchangerate} = $form->{forex} if $form->{forex}; # format amounts - $form->{exchangerate} = - $form->format_amount(\%myconfig, $form->{exchangerate}); - - if ($form->{exchangerate} == 0) { - $form->{exchangerate} = ""; - } - - $form->{creditlimit} = - $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); - $form->{creditremaining} = - $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0"); + $form->{exchangerate} = $form->{exchangerate} ? $form->format_amount(\%myconfig, $form->{exchangerate}) : ''; + $form->{creditlimit} = $form->format_amount(\%myconfig, $form->{creditlimit}, 0, "0"); + $form->{creditremaining} = $form->format_amount(\%myconfig, $form->{creditremaining}, 0, "0"); $exchangerate = qq| {forex}> @@ -446,6 +436,12 @@ sub form_header { qq|| . qq||; + my $globalprojectnumber = + NTI($cgi->popup_menu('-name' => "globalproject_id", + '-values' => \@project_values, + '-labels' => \%project_labels, + '-default' => $form->{"globalproject_id"} )); + $form->header; $onload = qq|focus()|; $onload .= qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')|; @@ -533,6 +529,10 @@ sub form_header { | . $locale->text('Due Date') . qq| $button2 + + | . $locale->text('Project Number') . qq| + $globalprojectnumber + @@ -705,7 +705,7 @@ $jsscript "; my @triggers = (); - my $totalpaid = 0; + $form->{totalpaid} = 0; $form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); for my $i (1 .. $form->{paidaccounts}) { @@ -720,18 +720,30 @@ $jsscript '-labels' => \%AR_paid_labels, '-default' => $form->{"AR_paid_$i"})); - $totalpaid += $form->{"paid_$i"}; + $form->{totalpaid} += $form->{"paid_$i"}; # format amounts if ($form->{"paid_$i"}) { $form->{"paid_$i"} = $form->format_amount(\%myconfig, $form->{"paid_$i"}, 2); } - $form->{"exchangerate_$i"} = - $form->format_amount(\%myconfig, $form->{"exchangerate_$i"}); - if ($form->{"exchangerate_$i"} == 0) { $form->{"exchangerate_$i"} = ""; + } else { + $form->{"exchangerate_$i"} = + $form->format_amount(\%myconfig, $form->{"exchangerate_$i"}); + } + + print qq|{"acc_trans_id_$i"}>\n|; + print qq|{"gldate_$i"}>\n|; + my $changeable = 1; + if ($::lx_office_conf{features}->{payments_changeable} == 0) { + # never + $changeable = ($form->{"acc_trans_id_$i"})? 0 : 1; + } + if ($::lx_office_conf{features}->{payments_changeable} == 2) { + # on the same day + $changeable = (($form->{"gldate_$i"} eq '') || $form->current_date(\%myconfig) eq $form->{"gldate_$i"}); } $exchangerate = qq| |; @@ -740,8 +752,13 @@ $jsscript $exchangerate = qq|{"exchangerate_$i"}>$form->{"exchangerate_$i"}|; } else { - $exchangerate = - qq|{"exchangerate_$i"}>|; + if ($changeable) { + $exchangerate = + qq|{"exchangerate_$i"}>|; + } else { + $exchangerate = + qq|{"exchangerate_$i"}>$form->{"exchangerate_$i"}|; + } } } @@ -749,43 +766,88 @@ $jsscript {"forex_$i"}> |; - $column_data{paid} = - qq||; - $column_data{AR_paid} = - qq|${selectAR_paid}|; - $column_data{exchangerate} = qq|$exchangerate|; - $column_data{datepaid} = - qq| + my $datepaid; + if ($changeable) { + $datepaid = qq| |; - $column_data{source} = - qq||; - $column_data{memo} = - qq||; + } else { + $datepaid = qq|$form->{"datepaid_$i"}|. + qq|{"datepaid_$i"}>|; + } - $column_data{paid_project_id} = + my $paid; + if ($changeable) { + $paid = qq||; + } else { + $paid = qq|$form->{"paid_$i"}|. + qq|{"paid_$i"}>|; + } + + my $source; + if ($changeable) { + $source = qq||; + } else { + $source = qq|$form->{"source_$i"}|. + qq|{"source_$i"}>|; + } + + my $memo; + if ($changeable) { + $memo = qq||; + } else { + $memo = qq|$form->{"memo_$i"}|. + qq|{"memo_$i"}>|; + } + + my $AR_paid; + if ($changeable) { + $AR_paid = qq|${selectAR_paid}|; + } else { + $AR_paid = qq|$form->{"AR_paid_$i"}|. + qq|{"AR_paid_$i"}>|; + } + + my $paid_project_id; + if ($changeable) { + $paid_project_id = qq|| . NTI($cgi->popup_menu('-name' => "paid_project_id_$i", '-values' => \@project_values, '-labels' => \%project_labels, '-default' => $form->{"paid_project_id_$i"} )) . qq||; + } else { + my $projectnumber = $project_labels{$form->{"paid_project_id_$i"}}; + $paid_project_id = qq|$projectnumber|. + qq|{"paid_project_id_$i"}>|; + } + + $column_data{paid} = $paid; + $column_data{AR_paid} = $AR_paid; + $column_data{exchangerate} = qq|$exchangerate|; + $column_data{datepaid} = $datepaid; + $column_data{source} = $source; + $column_data{memo} = $memo; + $column_data{paid_project_id} = $paid_project_id; map { print qq|$column_data{$_}\n| } @column_index; print " "; - push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i"); + if ($changeable) { + push(@triggers, "datepaid_$i", "BL", "trigger_datepaid_$i"); + } } - my $paid_missing = $form->{invtotal_unformatted} - $totalpaid; + my $paid_missing = $form->{invtotal_unformatted} - $form->{totalpaid}; print qq| | . $locale->text('Total') . qq| - | . H($form->format_amount(\%myconfig, $totalpaid, 2)) . qq| + | . H($form->format_amount(\%myconfig, $form->{totalpaid}, 2)) . qq| @@ -817,7 +879,7 @@ sub form_footer { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; my ($transdate, $closedto); @@ -862,7 +924,7 @@ $follow_ups_block # ToDO: - insert a global check for stornos, so that a storno is only possible a limited time after saving it print qq| | - if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar') && (($totalpaid == 0) || ($totalpaid eq ""))); + if ($form->{id} && !IS->has_storno(\%myconfig, $form, 'ar') && !IS->is_storno(\%myconfig, $form, 'ar') && (($form->{totalpaid} == 0) || ($form->{totalpaid} eq ""))); if ($form->{id}) { if ($form->{radier}) { @@ -984,10 +1046,13 @@ sub update { $form->{invdate} = $form->{transdate}; - my %saved_variables = map +( $_ => $form->{$_} ), qw(AR AR_amount_1 taxchart_1); + my %saved_variables = map +( $_ => $form->{$_} ), qw(AR AR_amount_1 taxchart_1 customer_id); &check_name("customer"); + # check_name loads customer notes into notes, but ar only knows intnotes, so copy them + $form->{notes} = $form->{intnotes} if $saved_variables{customer_id} != $form->{customer_id}; + $form->{AR} = $saved_variables{AR}; if ($saved_variables{AR_amount_1} =~ m/.--./) { map { $form->{$_} = $saved_variables{$_} } qw(AR_amount_1 taxchart_1); @@ -1005,7 +1070,7 @@ sub update { $form->parse_amount(\%myconfig, $form->{"${_}_$i"}) } qw(paid exchangerate); - $totalpaid += $form->{"paid_$i"}; + $form->{totalpaid} += $form->{"paid_$i"}; $form->{"forex_$i"} = $form->check_exchangerate( \%myconfig, $form->{currency}, $form->{"datepaid_$i"}, 'buy'); $form->{"exchangerate_$i"} = $form->{"forex_$i"} if $form->{"forex_$i"}; @@ -1013,10 +1078,10 @@ sub update { } $form->{creditremaining} -= - ($form->{invtotal} - $totalpaid + $form->{oldtotalpaid} - + ($form->{invtotal} - $form->{totalpaid} + $form->{oldtotalpaid} - $form->{oldinvtotal}); $form->{oldinvtotal} = $form->{invtotal}; - $form->{oldtotalpaid} = $totalpaid; + $form->{oldtotalpaid} = $form->{totalpaid}; &display_form; @@ -1037,6 +1102,8 @@ sub post_payment { $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); + my $invdate = $form->datetonum($form->{transdate}, \%myconfig); + for my $i (1 .. $form->{paidaccounts}) { if ($form->parse_amount(\%myconfig, $form->{"paid_$i"})) { @@ -1089,6 +1156,12 @@ sub post { $form->isblank("duedate", $locale->text('Due Date missing!')); $form->isblank("customer", $locale->text('Customer missing!')); + if ($myconfig{mandatory_departments} && !$form->{department}) { + $form->{saved_message} = $::locale->text('You have to specify a department.'); + update(); + exit; + } + my $closedto = $form->datetonum($form->{closedto}, \%myconfig); my $transdate = $form->datetonum($form->{transdate}, \%myconfig); $form->error($locale->text('Cannot post transaction for a closed period!')) if ($form->date_closed($form->{"transdate"}, \%myconfig)); @@ -1121,7 +1194,7 @@ sub post { my ($customer) = split /--/, $form->{customer}; if ($form->{oldcustomer} ne "$customer--$form->{customer_id}") { update(); - exit; + ::end_of_request(); } $form->{AR}{receivables} = $form->{ARselected}; @@ -1134,7 +1207,7 @@ sub post { if(!exists $form->{addition} && $form->{id} ne "") { $form->{snumbers} = "invnumber_$form->{invnumber}"; $form->{addition} = "POSTED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->save_history; } # /saving the history remove_draft() if $form->{remove_draft}; @@ -1157,7 +1230,7 @@ sub post_as_new { if(!exists $form->{addition} && $form->{id} ne "") { $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; $form->{addition} = "POSTED AS NEW"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->save_history; } # /saving the history &post; @@ -1173,7 +1246,7 @@ sub use_as_template { my $form = $main::form; my %myconfig = %main::myconfig; - map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno); + map { delete $form->{$_} } qw(printed emailed queued invnumber invdate deliverydate id datepaid_1 gldate_1 acc_trans_id_1 source_1 memo_1 paid_1 exchangerate_1 AP_paid_1 storno); $form->{paidaccounts} = 1; $form->{rowcount}--; $form->{invdate} = $form->current_date(\%myconfig); @@ -1240,7 +1313,7 @@ sub yes { if(!exists $form->{addition}) { $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; $form->{addition} = "DELETED"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->save_history; } # /saving the history $form->redirect($locale->text('Transaction deleted!')); @@ -1258,7 +1331,7 @@ sub search { my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; - my $cgi = $main::cgi; + my $cgi = $::request->{cgi}; my ($customer, $department); my ($jsscript, $button1, $button2, $onload); @@ -1269,13 +1342,20 @@ sub search { $form->{title} = $locale->text('AR Transactions'); $form->{jsscript} = 1; - $form->get_lists("projects" => { "key" => "ALL_PROJECTS", "all" => 1 }, - "departments" => "ALL_DEPARTMENTS", - "customers" => "ALL_VC"); + # Auch in Rechnungsübersicht nach Kundentyp filtern - jan + $form->get_lists("projects" => { "key" => "ALL_PROJECTS", "all" => 1 }, + "departments" => "ALL_DEPARTMENTS", + "customers" => "ALL_VC", + "employees" => "ALL_EMPLOYEES", + "salesmen" => "ALL_SALESMEN", + "business_types" => "ALL_BUSINESS_TYPES"); + $form->{SHOW_BUSINESS_TYPES} = scalar @{ $form->{ALL_BUSINESS_TYPES} } > 0; # constants and subs for template $form->{jsscript} = 1; $form->{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" }; + $form->{employee_labels} = sub { $_[0]->{"name"} || $_[0]->{"login"} }; + $form->{salesman_labels} = $form->{employee_labels}; $form->header; print $form->parse_html_template('ar/search', { %myconfig }); @@ -1315,7 +1395,6 @@ sub ar_transactions { my ($callback, $href, @columns); - $form->{customer} = $form->unescape($form->{customer}); ($form->{customer}, $form->{customer_id}) = split(/--/, $form->{customer}); report_generator_set_default_sort('transdate', 1); @@ -1329,10 +1408,10 @@ sub ar_transactions { @columns = qw(transdate id type invnumber ordnumber name netamount tax amount paid datepaid due duedate transaction_description notes salesman employee shippingpoint shipvia - marge_total marge_percent globalprojectnumber customernumber country ustid taxzone payment_terms charts); + marge_total marge_percent globalprojectnumber customernumber country ustid taxzone payment_terms charts customertype); my @hidden_variables = map { "l_${_}" } @columns; - push @hidden_variables, "l_subtotal", qw(open closed customer invnumber ordnumber transaction_description notes project_id transdatefrom transdateto); + push @hidden_variables, "l_subtotal", qw(open closed customer invnumber ordnumber transaction_description notes project_id transdatefrom transdateto employee_id salesman_id business_id); $href = build_std_url('action=ar_transactions', grep { $form->{$_} } @hidden_variables); @@ -1356,7 +1435,7 @@ sub ar_transactions { 'employee' => { 'text' => $locale->text('Employee'), }, 'shippingpoint' => { 'text' => $locale->text('Shipping Point'), }, 'shipvia' => { 'text' => $locale->text('Ship via'), }, - 'globalprojectnumber' => { 'text' => $locale->text('Project Number'), }, + 'globalprojectnumber' => { 'text' => $locale->text('Document Project Number'), }, 'marge_total' => { 'text' => $locale->text('Ertrag'), }, 'marge_percent' => { 'text' => $locale->text('Ertrag prozentual'), }, 'customernumber' => { 'text' => $locale->text('Customer Number'), }, @@ -1365,6 +1444,7 @@ sub ar_transactions { 'taxzone' => { 'text' => $locale->text('Steuersatz'), }, 'payment_terms' => { 'text' => $locale->text('Payment Terms'), }, 'charts' => { 'text' => $locale->text('Buchungskonto'), }, + 'customertype' => { 'text' => $locale->text('Customer type'), }, ); foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia transaction_description)) { @@ -1392,6 +1472,9 @@ sub ar_transactions { my ($department) = split /--/, $form->{department}; push @options, $locale->text('Department') . " : $department"; } + if ($form->{department_id}) { + push @options, $locale->text('Department Id') . " : $form->{department_id}"; + } if ($form->{invnumber}) { push @options, $locale->text('Invoice Number') . " : $form->{invnumber}"; } @@ -1413,6 +1496,14 @@ sub ar_transactions { if ($form->{open}) { push @options, $locale->text('Open'); } + if ($form->{employee_id}) { + my $employee = SL::DB::Employee->new(id => $form->{employee_id})->load; + push @options, $locale->text('Employee') . ' : ' . $employee->name; + } + if ($form->{salesman_id}) { + my $salesman = SL::DB::Employee->new(id => $form->{salesman_id})->load; + push @options, $locale->text('Salesman') . ' : ' . $salesman->name; + } if ($form->{closed}) { push @options, $locale->text('Closed'); } @@ -1424,6 +1515,7 @@ sub ar_transactions { 'attachment_basename' => $locale->text('invoice_list') . strftime('_%Y%m%d', localtime time), ); $report->set_options_from_form(); + $locale->set_numberformat_wo_thousands_separator(\%myconfig) if lc($report->{options}->{output_format}) eq 'csv'; # add sort and escape callback, this one we use for the add sub $form->{callback} = $href .= "&sort=$form->{sort}"; @@ -1514,7 +1606,7 @@ sub storno { if(!exists $form->{addition} && $form->{id} ne "") { $form->{snumbers} = "ordnumber_$form->{ordnumber}"; $form->{addition} = "STORNO"; - $form->save_history($form->dbconnect(\%myconfig)); + $form->save_history; } # /saving the history