1 use SL::AccTransCorrections;
 
   7 require "bin/mozilla/common.pl";
 
  10   $lxdebug->enter_sub();
 
  12   $form->{jsscript} = 1;
 
  13   $form->{title}    = $locale->text('General ledger corrections');
 
  15   print $form->parse_html_template('acctranscorrections/analyze_filter');
 
  17   $lxdebug->leave_sub();
 
  21   $lxdebug->enter_sub();
 
  23   $form->{title} = $locale->text('General ledger corrections');
 
  25   delete @{ $form }{qw(transdate_from transdate_to)} if ($form->{scope} eq 'full');
 
  27   my $callback = 'acctranscorrections.pl?action=analyze';
 
  28   map { $callback .= "&${_}=" . $form->escape($form->{$_}) } grep { $form->{$_} } qw(transdate_from transdate_to);
 
  29   $callback = $form->escape($callback);
 
  31   my $analyzer = AccTransCorrections->new();
 
  33   my %params   = map { $_ => $form->{$_} } qw(transdate_from transdate_to);
 
  34   my @problems = $analyzer->analyze(%params, 'callback' => $callback);
 
  36   if (!scalar @problems) {
 
  37     $form->show_generic_information($locale->text('No problems were recognized.'));
 
  39     $lxdebug->leave_sub();
 
  44   print $form->parse_html_template('acctranscorrections/analyze_overview',
 
  45                                    { 'PROBLEMS' => \@problems,
 
  46                                      'callback' => $callback,
 
  49   $lxdebug->leave_sub();
 
  53   $lxdebug->enter_sub();
 
  55   $form->{title} = $locale->text('Assistant for general ledger corrections');
 
  57   $form->isblank('trans_id', $locale->text('Transaction ID missing.'));
 
  59   my $analyzer  = AccTransCorrections->new();
 
  60   my ($problem) = $analyzer->analyze('trans_id' => $form->{trans_id}, 'full_analysis' => 1);
 
  64         $form->{trans_module} eq 'ar' ? $locale->text('AR Transaction')
 
  65       : $form->{trans_module} eq 'ap' ? $locale->text('AP Transaction')
 
  66       :                                 $locale->text('General Ledger Transaction');
 
  68     $form->show_generic_information($locale->text('The assistant could not find anything wrong with #1. Maybe the problem has been solved in the meantime.',
 
  69                                                   "$module $form->{trans_reference}"));
 
  71     $lxdebug->leave_sub();
 
  75   if ($problem->{type} eq 'wrong_taxkeys') {
 
  76     assistant_for_wrong_taxkeys($problem);
 
  78   } elsif ($problem->{type} eq 'wrong_taxes') {
 
  79     assistant_for_wrong_taxkeys($problem);
 
  80 #     assistant_for_wrong_taxes($problem);
 
  83     $form->show_generic_error($locale->text('Unknown problem type.'));
 
  86   $lxdebug->leave_sub();
 
  89 sub assistant_for_ap_ar_wrong_taxkeys {
 
  90   $lxdebug->enter_sub();
 
  92   $form->{title} = $locale->text('Assistant for general ledger corrections');
 
  95   print $form->parse_html_template('acctranscorrections/assistant_for_ap_ar_wrong_taxkeys');
 
  97   $lxdebug->leave_sub();
 
 100 sub fix_ap_ar_wrong_taxkeys {
 
 101   $lxdebug->enter_sub();
 
 103   my $analyzer = AccTransCorrections->new();
 
 104   $analyzer->fix_ap_ar_wrong_taxkeys();
 
 106   $form->{title} = $locale->text('Assistant for general ledger corrections');
 
 108   print $form->parse_html_template('acctranscorrections/fix_ap_ar_wrong_taxkeys');
 
 110   $lxdebug->leave_sub();
 
 113 sub assistant_for_invoice_inventory_with_taxkeys {
 
 114   $lxdebug->enter_sub();
 
 116   $form->{title} = $locale->text('Assistant for general ledger corrections');
 
 119   print $form->parse_html_template('acctranscorrections/assistant_for_invoice_inventory_with_taxkeys');
 
 121   $lxdebug->leave_sub();
 
 124 sub fix_invoice_inventory_with_taxkeys {
 
 125   $lxdebug->enter_sub();
 
 127   my $analyzer  = AccTransCorrections->new();
 
 128   $analyzer->fix_invoice_inventory_with_taxkeys();
 
 130   $form->{title} = $locale->text('Assistant for general ledger corrections');
 
 132   print $form->parse_html_template('acctranscorrections/fix_invoice_inventory_with_taxkeys');
 
 134   $lxdebug->leave_sub();
 
 137 sub assistant_for_wrong_taxes {
 
 138   $lxdebug->enter_sub();
 
 142   $form->{title} = $locale->text('Assistant for general ledger corrections');
 
 145   print $form->parse_html_template('acctranscorrections/assistant_for_wrong_taxes', { 'problem' => $problem, });
 
 147   $lxdebug->leave_sub();
 
 150 sub assistant_for_wrong_taxkeys {
 
 151   $lxdebug->enter_sub();
 
 155   $form->{title} = $locale->text('Assistant for general ledger corrections');
 
 158   print $form->parse_html_template('acctranscorrections/assistant_for_wrong_taxkeys', { 'problem' => $problem, });
 
 160   $lxdebug->leave_sub();
 
 163 sub fix_wrong_taxkeys {
 
 164   $lxdebug->enter_sub();
 
 166   my $fixes = ref $form->{fixes} eq 'ARRAY' ? $form->{fixes} : [];
 
 168   my $analyzer  = AccTransCorrections->new();
 
 169   $analyzer->fix_wrong_taxkeys('fixes' => $fixes);
 
 171   $form->{title} = $locale->text('Assistant for general ledger corrections');
 
 173   print $form->parse_html_template('acctranscorrections/fix_wrong_taxkeys');
 
 175   $lxdebug->leave_sub();
 
 178 sub delete_transaction {
 
 179   $lxdebug->enter_sub();
 
 181   $form->{title} = $locale->text('Delete transaction');
 
 184   if (!$form->{confirmation}) {
 
 185     print $form->parse_html_template('acctranscorrections/delete_transaction_confirmation');
 
 187     my $analyzer  = AccTransCorrections->new();
 
 188     $analyzer->delete_transaction('trans_id' => $form->{trans_id});
 
 190     print $form->parse_html_template('acctranscorrections/delete_transaction');
 
 193   $lxdebug->leave_sub();
 
 197   $lxdebug->enter_sub();
 
 199   $form->redirect('Missing callbcak');
 
 201   $lxdebug->leave_sub();
 
 205   foreach my $action (qw(fix_wrong_taxkeys delete_transaction)) {
 
 206     if ($form->{"action_${action}"}) {
 
 212   $form->error($locale->text('No action defined.'));