X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=bin%2Fmozilla%2Fdn.pl;h=0b2b27c582294e72fc36feff3df3efbc0cf1d09b;hb=333003d332756c5f53a33720aea7b714dfd335c8;hp=627f6963340f74c548de25cc519839ecc22383fd;hpb=8de8e5398d67e7afdcf42951f020b813128aea73;p=kivitendo-erp.git diff --git a/bin/mozilla/dn.pl b/bin/mozilla/dn.pl index 627f69633..0b2b27c58 100644 --- a/bin/mozilla/dn.pl +++ b/bin/mozilla/dn.pl @@ -24,18 +24,22 @@ # GNU General Public License for more details. # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, +# MA 02110-1335, USA. #====================================================================== # # Dunning process module # #====================================================================== -use POSIX; +use POSIX qw(strftime); use SL::IS; -use SL::PE; use SL::DN; +use SL::DB::Department; +use SL::DB::Dunning; +use SL::Helper::Flash qw(flash); +use SL::Locale::String qw(t8); use SL::ReportGenerator; require "bin/mozilla/common.pl"; @@ -80,6 +84,8 @@ sub edit_config { $form->{title} = $locale->text('Edit Dunning Process Config'); $form->{callback} ||= build_std_url("action=edit_config"); + setup_dn_edit_config_action_bar(); + $form->header(); print $form->parse_html_template("dunning/edit_config"); @@ -95,18 +101,16 @@ sub add { $main::auth->assert('dunning_edit'); - # setup customer selection - $form->all_vc(\%myconfig, "customer", "AR"); - DN->get_config(\%myconfig, \%$form); - $form->{SHOW_CUSTOMER_SELECTION} = $form->{all_customer} && scalar @{ $form->{all_customer} }; + $form->get_lists("departments" => "ALL_DEPARTMENTS"); + $form->{SHOW_DUNNING_LEVEL_SELECTION} = $form->{DUNNING} && scalar @{ $form->{DUNNING} }; - $form->{SHOW_DEPARTMENT_SELECTION} = $form->{all_departments} && scalar @{ $form->{all_departments} || [] }; + $form->{SHOW_DEPARTMENT_SELECTION} = $form->{ALL_DEPARTMENTS} && scalar @{ $form->{ALL_DEPARTMENTS} || [] }; $form->{title} = $locale->text('Start Dunning Process'); - $form->{jsscript} = 1; - $form->{fokus} = "search.customer"; + + setup_dn_add_action_bar(); $form->header(); print $form->parse_html_template("dunning/add"); @@ -132,7 +136,7 @@ sub show_invoices { if ($row->{next_dunning_config_id}) { map { $_->{SELECTED} = $_->{id} == $row->{next_dunning_config_id} } @{ $row->{DUNNING_CONFIG } }; } - map { $row->{$_} = $form->format_amount(\%myconfig, $row->{$_} * 1, -2) } qw(amount open_amount fee interest); + map { $row->{$_} = $form->format_amount(\%myconfig, $row->{$_} * 1, 2) } qw(amount open_amount fee interest); if ($row->{'language_id'}) { $row->{language} = SL::DB::Manager::Language->find_by_or_create('id' => $row->{'language_id'})->{'description'}; @@ -144,7 +148,6 @@ sub show_invoices { $form->{type} = 'dunning'; $form->{rowcount} = scalar @{ $form->{DUNNINGS} }; - $form->{jsscript} = 1; $form->{callback} ||= build_std_url("action=show_invoices", qw(customer invnumber ordnumber groupinvoices minamount dunning_level notes)); $form->{PRINT_OPTIONS} = print_options('inline' => 1, @@ -153,9 +156,8 @@ sub show_invoices { 'no_html' => 1, 'no_opendocument' => 1,); + setup_dn_show_invoices_action_bar(); $form->header(); - $form->{onload} = "document.getElementsByName('language_id')[0].disabled = - !document.getElementsByName('force_lang')[0].checked;"; print $form->parse_html_template("dunning/show_invoices"); $main::lxdebug->leave_sub(); @@ -256,7 +258,8 @@ sub save_dunning { $form->{language_id} = $saved_language_id; - if($form->{DUNNING_PDFS}) { + if (scalar @{ $form->{DUNNING_PDFS} }) { + $form->{dunning_id} = strftime("%Y%m%d", localtime time) if scalar @{ $form->{DUNNING_PDFS}} > 1; DN->melt_pdfs(\%myconfig, $form, $form->{copies}); } @@ -285,7 +288,7 @@ sub set_email { $main::auth->assert('dunning_edit'); $form->{"title"} = $locale->text("Set eMail text"); - $form->header(); + $form->header(no_layout => 1); print($form->parse_html_template("dunning/set_email")); $main::lxdebug->leave_sub(); @@ -302,24 +305,17 @@ sub search { $form->get_lists("customers" => "ALL_CUSTOMERS", "departments" => "ALL_DEPARTMENTS"); - $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 ]); DN->get_config(\%myconfig, \%$form); - $form->{SHOW_CUSTOMER_DDBOX} = scalar @{ $form->{ALL_CUSTOMERS} } <= $myconfig{vclimit}; - $form->{SHOW_DEPARTMENT_DDBOX} = scalar @{ $form->{ALL_CUSTOMERS} }; $form->{SHOW_DUNNING_LEVELS} = scalar @{ $form->{DUNNING} }; - $form->{jsscript} = 1; $form->{title} = $locale->text('Dunnings'); - $form->{fokus} = "search.customer"; + setup_dn_search_action_bar(); $form->header(); - $form->{onload} = qq|focus()| - . qq|;setupDateFormat('|. $myconfig{dateformat} .qq|', '|. $locale->text("Falsches Datumsformat!") .qq|')| - . qq|;setupPoints('|. $myconfig{numberformat} .qq|', '|. $locale->text("wrongformat") .qq|')|; - print $form->parse_html_template("dunning/search"); $main::lxdebug->leave_sub(); @@ -368,6 +364,7 @@ sub show_dunning { 'checkbox' => { 'text' => '', 'visible' => 'HTML' }, 'dunning_description' => { 'text' => $locale->text('Dunning Level') }, 'customername' => { 'text' => $locale->text('Customername') }, + 'departmentname' => { 'text' => $locale->text('Department') }, 'language' => { 'text' => $locale->text('Language') }, 'invnumber' => { 'text' => $locale->text('Invnumber') }, 'transdate' => { 'text' => $locale->text('Invdate') }, @@ -460,8 +457,7 @@ sub show_dunning { $report->set_options_from_form(); - $form->{onload} = "document.getElementsByName('language_id')[0].disabled = - !document.getElementsByName('force_lang')[0].checked;"; + setup_dn_show_dunning_action_bar(); $report->generate_with_headers(); $main::lxdebug->leave_sub(); @@ -485,6 +481,29 @@ sub print_dunning { $main::lxdebug->leave_sub(); } +sub delete { + $main::auth->assert('dunning_edit'); + + my @dunning_ids = map { $::form->{"dunning_id_$_"} } grep { $::form->{"selected_$_"} } (1..$::form->{rowcount}); + + if (!scalar @dunning_ids) { + $::form->error($::locale->text('No dunnings have been selected for printing.')); + } + + my $dunnings = SL::DB::Manager::Dunning->get_all(query => [ dunning_id => \@dunning_ids ]); + + SL::DB::Dunning->new->db->with_transaction(sub { + for my $dunning (@$dunnings) { + SL::DB::Manager::Invoice->find_by(id => $dunning->trans_id)->update_attributes(dunning_config_id => undef); + $dunning->delete; + } + }); + + flash('info', t8('#1 dunnings have been deleted', scalar @$dunnings)); + + search(); +} + sub print_multiple { $main::lxdebug->enter_sub(); @@ -511,6 +530,7 @@ sub print_multiple { if (!$form->{force_lang}) { $form->{language_id} = $language_ids[$i]; } + $form->{dunning_id} = $dunning_id; DN->print_invoice_for_fees(\%myconfig, $form, $dunning_id); DN->print_dunning(\%myconfig, $form, $dunning_id); $i++; @@ -518,7 +538,7 @@ sub print_multiple { $form->{language_id} = $saved_language_id; if (scalar @{ $form->{DUNNING_PDFS} }) { - $form->{dunning_id} = strftime("%Y%m%d", localtime time); + $form->{dunning_id} = strftime("%Y%m%d", localtime time) if scalar @{ $form->{DUNNING_PDFS}} > 1; DN->melt_pdfs(\%myconfig, $form, $form->{copies}); if ($form->{media} eq 'printer') { @@ -537,4 +557,95 @@ sub continue { call_sub($main::form->{nextsub}); } +sub dispatcher { + foreach my $action (qw(delete print_multiple)) { + if ($::form->{"action_${action}"}) { + call_sub($action); + return; + } + } + + $::form->error($::locale->text('No action defined.')); +} + +sub setup_dn_add_action_bar { + my %params = @_; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + t8('Search'), + submit => [ '#form', { action => "show_invoices" } ], + accesskey => 'enter', + ], + ); + } +} + +sub setup_dn_show_invoices_action_bar { + my %params = @_; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + t8('Create'), + submit => [ '#form', { action => "save_dunning" } ], + checks => [ [ 'kivi.check_if_entries_selected', '[name^=active_]' ] ], + accesskey => 'enter', + only_once => 1, + ], + ); + } +} + +sub setup_dn_search_action_bar { + my %params = @_; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + t8('Search'), + submit => [ '#form', { action => "show_dunning" } ], + accesskey => 'enter', + ], + ); + } +} + +sub setup_dn_show_dunning_action_bar { + my %params = @_; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + t8('Print'), + submit => [ '#form', { action => "print_multiple" } ], + checks => [ [ 'kivi.check_if_entries_selected', '[name^=selected_]' ] ], + accesskey => 'enter', + ], + + action => [ + t8('Delete'), + submit => [ '#form', { action => "delete" } ], + checks => [ [ 'kivi.check_if_entries_selected', '[name^=selected_]' ] ], + confirm => $::locale->text('This resets the dunning process for the selected invoices. Posted dunning invoices will not be changed!'), + ], + ); + } +} + +sub setup_dn_edit_config_action_bar { + my %params = @_; + + for my $bar ($::request->layout->get('actionbar')) { + $bar->add( + action => [ + t8('Save'), + submit => [ '#form', { action => "save" } ], + accesskey => 'enter', + ], + ); + } +} + # end of main