X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Far.pl;h=28c8efbab54d4f6a9a6d062cd63177e0e5db48c8;hb=14d71a6d1215e4fc67136c060fd21cd6c59602af;hp=a05a9717869dd96aa7471b0ab4be194de897089a;hpb=ee2b1ef305f1723d7ad39a44e195c7e15f8af810;p=kivitendo-erp.git diff --git a/bin/mozilla/ar.pl b/bin/mozilla/ar.pl index a05a97178..28c8efbab 100644 --- a/bin/mozilla/ar.pl +++ b/bin/mozilla/ar.pl @@ -33,12 +33,14 @@ use POSIX qw(strftime); use List::Util qw(sum first max); +use List::UtilsBy qw(sort_by); use SL::AR; use SL::FU; use SL::IS; use SL::PE; use SL::DB::Default; +use SL::DB::Invoice; use SL::ReportGenerator; require "bin/mozilla/arap.pl"; @@ -100,7 +102,7 @@ sub add { AR->get_transdate(\%myconfig, $form); $form->{initial_transdate} = $form->{transdate}; - &create_links; + create_links(dont_save => 1); $form->{transdate} = $form->{initial_transdate}; &display_form; $main::lxdebug->leave_sub(); @@ -119,7 +121,7 @@ sub edit { $form->{javascript} .= qq||; $form->{title} = "Edit"; - &create_links; + create_links(); &display_form; $main::lxdebug->leave_sub(); @@ -138,17 +140,29 @@ sub display_form { $main::lxdebug->leave_sub(); } +sub _retrieve_invoice_object { + return undef if !$::form->{id}; + return $::form->{invoice_obj} if $::form->{invoice_obj} && $::form->{invoice_obj}->id == $::form->{id}; + return SL::DB::Invoice->new(id => $::form->{id})->load; +} + sub create_links { $main::lxdebug->enter_sub(); $main::auth->assert('general_ledger'); + my %params = @_; my $form = $main::form; my %myconfig = %main::myconfig; $form->create_links("AR", \%myconfig, "customer"); + $form->{invoice_obj} = _retrieve_invoice_object(); - my %saved = map { ($_ => $form->{$_}) } qw(direct_debit duedate id taxincluded); + my %saved; + if (!$params{dont_save}) { + %saved = map { ($_ => $form->{$_}) } qw(direct_debit id taxincluded); + $saved{duedate} = $form->{duedate} if $form->{duedate}; + } IS->get_customer(\%myconfig, \%$form); @@ -210,6 +224,8 @@ sub form_header { my $locale = $main::locale; my $cgi = $::request->{cgi}; + $form->{invoice_obj} = _retrieve_invoice_object(); + my ($title, $readonly, $exchangerate, $rows); my ($notes, $department, $customer, $employee, $amount, $project); my ($ARselected); @@ -310,8 +326,6 @@ sub form_header { $taxcharts{$item->{id}} = $item; } - $::request->{layout}->focus("#customer"); - my $follow_up_vc = $form->{customer}; $follow_up_vc =~ s/--.*?//; my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)"; @@ -406,12 +420,15 @@ sub form_header { gldate => $form->{"gldate_$i"}, }; + # default account for current assets (i.e. 1801 - SKR04) if no account is selected + $form->{accno_arap} = IS->get_standard_accno_current_assets(\%myconfig, \%$form); + $payment->{selectAR_paid} = NTI($cgi->popup_menu('-name' => "AR_paid_$i", '-id' => "AR_paid_$i", '-values' => \@AR_paid_values, '-labels' => \%chart_labels, - '-default' => $payment->{AR_paid})); + '-default' => $payment->{AR_paid} || $form->{accno_arap})); @@ -423,6 +440,12 @@ sub form_header { push @payments, $payment; } + my @empty = grep { $_->{paid} eq '' } @payments; + @payments = ( + (sort_by { DateTime->from_kivitendo($_->{datepaid}) } grep { $_->{paid} ne '' } @payments), + @empty, + ); + $form->{totalpaid} = sum map { $_->{paid} } @payments; $form->header; @@ -436,6 +459,7 @@ sub form_header { ARselected => $ARselected, title_str => $title, follow_up_trans_info => $follow_up_trans_info, + today => DateTime->today, }); $main::lxdebug->leave_sub(); @@ -516,21 +540,13 @@ sub update { for my $i (1 .. $form->{rowcount}) { $form->{"amount_$i"} = $form->parse_amount(\%myconfig, $form->{"amount_$i"}); - $form->{"tax_$i"} = $form->parse_amount(\%myconfig, $form->{"tax_$i"}); if ($form->{"amount_$i"}) { push @a, {}; my $j = $#a; my ($taxkey, $rate) = split(/--/, $form->{"taxchart_$i"}); - if ($taxkey > 1) { - if ($form->{taxincluded}) { - $form->{"tax_$i"} = $form->{"amount_$i"} / ($rate + 1) * $rate; - } else { - $form->{"tax_$i"} = $form->{"amount_$i"} * $rate; - } - } else { - $form->{"tax_$i"} = 0; - } - $form->{"tax_$i"} = $form->round_amount($form->{"tax_$i"}, 2); + + my $tmpnetamount; + ($tmpnetamount,$form->{"tax_$i"}) = $form->calculate_tax($form->{"amount_$i"},$rate,$form->{taxincluded},2); $totaltax += $form->{"tax_$i"}; map { $a[$j]->{$_} = $form->{"${_}_$i"} } @flds; @@ -600,6 +616,7 @@ sub post_payment { my %myconfig = %main::myconfig; my $locale = $main::locale; + $form->mtime_ischanged('ar'); $form->{defaultcurrency} = $form->get_default_currency(\%myconfig); my $invdate = $form->datetonum($form->{transdate}, \%myconfig); @@ -622,8 +639,15 @@ sub post_payment { ($form->{AR}) = split /--/, $form->{AR}; ($form->{AR_paid}) = split /--/, $form->{AR_paid}; - $form->redirect($locale->text('Payment posted!')) if (AR->post_payment(\%myconfig, \%$form)); - $form->error($locale->text('Cannot post payment!')); + if (AR->post_payment(\%myconfig, \%$form)) { + $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; + $form->{what_done} = 'invoice'; + $form->{addition} = "PAYMENT POSTED"; + $form->save_history; + $form->redirect($locale->text('Payment posted!')) + } else { + $form->error($locale->text('Cannot post payment!')); + }; $main::lxdebug->leave_sub(); } @@ -649,6 +673,8 @@ sub post { my ($inline) = @_; + $form->mtime_ischanged('ar'); + my ($datepaid); # check if there is an invoice number, invoice and due date @@ -664,6 +690,9 @@ sub post { my $closedto = $form->datetonum($form->{closedto}, \%myconfig); my $transdate = $form->datetonum($form->{transdate}, \%myconfig); + + $form->error($locale->text('Cannot post transaction above the maximum future booking date!')) + if ($form->date_max_future($transdate, \%myconfig)); $form->error($locale->text('Cannot post transaction for a closed period!')) if ($form->date_closed($form->{"transdate"}, \%myconfig)); $form->error($locale->text('Zero amount posting!')) @@ -705,8 +734,9 @@ sub post { # saving the history if(!exists $form->{addition} && $form->{id} ne "") { - $form->{snumbers} = "invnumber_$form->{invnumber}"; - $form->{addition} = "POSTED"; + $form->{snumbers} = "invnumber_$form->{invnumber}"; + $form->{what_done} = "invoice"; + $form->{addition} = "POSTED"; $form->save_history; } # /saving the history @@ -728,8 +758,9 @@ sub post_as_new { $form->{postasnew} = 1; # saving the history if(!exists $form->{addition} && $form->{id} ne "") { - $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; - $form->{addition} = "POSTED AS NEW"; + $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; + $form->{what_done} = "invoice"; + $form->{addition} = "POSTED AS NEW"; $form->save_history; } # /saving the history @@ -806,8 +837,9 @@ sub yes { if (AR->delete_transaction(\%myconfig, \%$form)) { # saving the history if(!exists $form->{addition}) { - $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; - $form->{addition} = "DELETED"; + $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; + $form->{what_done} = "invoice"; + $form->{addition} = "DELETED"; $form->save_history; } # /saving the history @@ -821,32 +853,33 @@ sub yes { sub search { $main::lxdebug->enter_sub(); - $main::auth->assert('general_ledger | invoice_edit'); + $main::auth->assert('invoice_edit'); my $form = $main::form; my %myconfig = %main::myconfig; my $locale = $main::locale; my $cgi = $::request->{cgi}; - my ($customer, $department); - my ($jsscript, $button1, $button2); - # setup customer selection $form->all_vc(\%myconfig, "customer", "AR"); $form->{title} = $locale->text('AR Transactions'); - $form->{jsscript} = 1; # Auch in Rechnungsübersicht nach Kundentyp filtern - jan $form->get_lists("projects" => { "key" => "ALL_PROJECTS", "all" => 1 }, "departments" => "ALL_DEPARTMENTS", "customers" => "ALL_VC", "business_types" => "ALL_BUSINESS_TYPES"); - $form->{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all(query => [ deleted => 0 ]); + $form->{ALL_EMPLOYEES} = SL::DB::Manager::Employee->get_all_sorted(query => [ deleted => 0 ]); $form->{SHOW_BUSINESS_TYPES} = scalar @{ $form->{ALL_BUSINESS_TYPES} } > 0; + $form->{CT_CUSTOM_VARIABLES} = CVar->get_configs('module' => 'CT'); + ($form->{CT_CUSTOM_VARIABLES_FILTER_CODE}, + $form->{CT_CUSTOM_VARIABLES_INCLUSION_CODE}) = CVar->render_search_options('variables' => $form->{CT_CUSTOM_VARIABLES}, + 'include_prefix' => 'l_', + 'include_value' => 'Y'); + # constants and subs for template - $form->{jsscript} = 1; $form->{vc_keys} = sub { "$_[0]->{name}--$_[0]->{id}" }; $form->header; @@ -879,7 +912,7 @@ sub create_subtotal_row { sub ar_transactions { $main::lxdebug->enter_sub(); - $main::auth->assert('general_ledger | invoice_edit'); + $main::auth->assert('invoice_edit'); my $form = $main::form; my %myconfig = %main::myconfig; @@ -898,12 +931,20 @@ sub ar_transactions { my $report = SL::ReportGenerator->new(\%myconfig, $form); @columns = - qw(transdate id type invnumber ordnumber name netamount tax amount paid + qw(transdate id type invnumber ordnumber cusordnumber 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 customertype); + marge_total marge_percent globalprojectnumber customernumber country ustid taxzone payment_terms charts customertype direct_debit dunning_description); + + my $ct_cvar_configs = CVar->get_configs('module' => 'CT'); + my @ct_includeable_custom_variables = grep { $_->{includeable} } @{ $ct_cvar_configs }; + my @ct_searchable_custom_variables = grep { $_->{searchable} } @{ $ct_cvar_configs }; + + my %column_defs_cvars = map { +"cvar_$_->{name}" => { 'text' => $_->{description} } } @ct_includeable_custom_variables; + push @columns, map { "cvar_$_->{name}" } @ct_includeable_custom_variables; my @hidden_variables = map { "l_${_}" } @columns; - push @hidden_variables, "l_subtotal", qw(open closed customer invnumber ordnumber transaction_description notes project_id transdatefrom transdateto employee_id salesman_id business_id); + push @hidden_variables, "l_subtotal", qw(open closed customer invnumber ordnumber cusordnumber transaction_description notes project_id transdatefrom transdateto duedatefrom duedateto employee_id salesman_id business_id); + push @hidden_variables, map { "cvar_$_->{name}" } @ct_searchable_custom_variables; $href = build_std_url('action=ar_transactions', grep { $form->{$_} } @hidden_variables); @@ -913,6 +954,7 @@ sub ar_transactions { 'type' => { 'text' => $locale->text('Type'), }, 'invnumber' => { 'text' => $locale->text('Invoice'), }, 'ordnumber' => { 'text' => $locale->text('Order'), }, + 'cusordnumber' => { 'text' => $locale->text('Customer Order Number'), }, 'name' => { 'text' => $locale->text('Customer'), }, 'netamount' => { 'text' => $locale->text('Amount'), }, 'tax' => { 'text' => $locale->text('Tax'), }, @@ -937,9 +979,12 @@ sub ar_transactions { 'payment_terms' => { 'text' => $locale->text('Payment Terms'), }, 'charts' => { 'text' => $locale->text('Buchungskonto'), }, 'customertype' => { 'text' => $locale->text('Customer type'), }, + 'direct_debit' => { 'text' => $locale->text('direct debit'), }, + dunning_description => { 'text' => $locale->text('Dunning level'), }, + %column_defs_cvars, ); - foreach my $name (qw(id transdate duedate invnumber ordnumber name datepaid employee shippingpoint shipvia transaction_description)) { + foreach my $name (qw(id transdate duedate invnumber ordnumber cusordnumber name datepaid employee shippingpoint shipvia transaction_description direct_debit)) { my $sortdir = $form->{sort} eq $name ? 1 - $form->{sortdir} : $form->{sortdir}; $column_defs{$name}->{link} = $href . "&sort=$name&sortdir=$sortdir"; } @@ -956,10 +1001,19 @@ sub ar_transactions { $report->set_sort_indicator($form->{sort}, $form->{sortdir}); + CVar->add_custom_variables_to_report('module' => 'CT', + 'trans_id_field' => 'customer_id', + 'configs' => $ct_cvar_configs, + 'column_defs' => \%column_defs, + 'data' => $form->{AR}); + my @options; if ($form->{customer}) { push @options, $locale->text('Customer') . " : $form->{customer}"; } + if ($form->{cp_name}) { + push @options, $locale->text('Contact Person') . " : $form->{cp_name}"; + } if ($form->{department}) { my ($department) = split /--/, $form->{department}; push @options, $locale->text('Department') . " : $department"; @@ -973,6 +1027,9 @@ sub ar_transactions { if ($form->{ordnumber}) { push @options, $locale->text('Order Number') . " : $form->{ordnumber}"; } + if ($form->{cusordnumber}) { + push @options, $locale->text('Customer Order Number') . " : $form->{cusordnumber}"; + } if ($form->{notes}) { push @options, $locale->text('Notes') . " : $form->{notes}"; } @@ -1044,6 +1101,8 @@ sub ar_transactions { $ar->{invoice} ? $locale->text("Invoice (one letter abbreviation)") : $locale->text("AR Transaction (abbreviation)"); + $ar->{direct_debit} = $ar->{direct_debit} ? $::locale->text('yes') : $::locale->text('no'); + my $row = { }; foreach my $column (@columns) { @@ -1096,8 +1155,9 @@ sub storno { # saving the history if(!exists $form->{addition} && $form->{id} ne "") { - $form->{snumbers} = "ordnumber_$form->{ordnumber}"; - $form->{addition} = "STORNO"; + $form->{snumbers} = qq|invnumber_| . $form->{invnumber}; + $form->{addition} = "STORNO"; + $form->{what_done} = "invoice"; $form->save_history; } # /saving the history