Korrekturmodul für das Hauptbuch implementiert
[kivitendo-erp.git] / bin / mozilla / acctranscorrections.pl
1 use SL::AccTransCorrections;
2 use SL::Form;
3 use SL::User;
4 use Data::Dumper;
5 use YAML;
6
7 require "bin/mozilla/common.pl";
8
9 sub analyze_filter {
10   $lxdebug->enter_sub();
11
12   $form->{jsscript} = 1;
13   $form->{title}    = $locale->text('General ledger corrections');
14   $form->header();
15   print $form->parse_html_template('acctranscorrections/analyze_filter');
16
17   $lxdebug->leave_sub();
18 }
19
20 sub analyze {
21   $lxdebug->enter_sub();
22
23   $form->{title} = $locale->text('General ledger corrections');
24
25   delete @{ $form }{qw(transdate_from transdate_to)} if ($form->{scope} eq 'full');
26
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);
30
31   my $analyzer = AccTransCorrections->new();
32
33   my %params   = map { $_ => $form->{$_} } qw(transdate_from transdate_to);
34   my @problems = $analyzer->analyze(%params, 'callback' => $callback);
35
36   if (!scalar @problems) {
37     $form->show_generic_information($locale->text('No problems were recognized.'));
38
39     $lxdebug->leave_sub();
40     return;
41   }
42
43   $form->header();
44   print $form->parse_html_template('acctranscorrections/analyze_overview',
45                                    { 'PROBLEMS' => \@problems,
46                                      'callback' => $callback,
47                                    });
48
49   $lxdebug->leave_sub();
50 }
51
52 sub assistant {
53   $lxdebug->enter_sub();
54
55   $form->{title} = $locale->text('Assistant for general ledger corrections');
56
57   $form->isblank('trans_id', $locale->text('Transaction ID missing.'));
58
59   my $analyzer  = AccTransCorrections->new();
60   my ($problem) = $analyzer->analyze('trans_id' => $form->{trans_id}, 'full_analysis' => 1);
61
62   if (!$problem) {
63     my $module =
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');
67
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}"));
70
71     $lxdebug->leave_sub();
72     return;
73   }
74
75   if ($problem->{type} eq 'wrong_taxkeys') {
76     assistant_for_wrong_taxkeys($problem);
77
78   } elsif ($problem->{type} eq 'wrong_taxes') {
79     assistant_for_wrong_taxkeys($problem);
80 #     assistant_for_wrong_taxes($problem);
81
82   } else {
83     $form->show_generic_error($locale->text('Unknown problem type.'));
84   }
85
86   $lxdebug->leave_sub();
87 }
88
89 sub assistant_for_ap_ar_wrong_taxkeys {
90   $lxdebug->enter_sub();
91
92   $form->{title} = $locale->text('Assistant for general ledger corrections');
93
94   $form->header();
95   print $form->parse_html_template('acctranscorrections/assistant_for_ap_ar_wrong_taxkeys');
96
97   $lxdebug->leave_sub();
98 }
99
100 sub fix_ap_ar_wrong_taxkeys {
101   $lxdebug->enter_sub();
102
103   my $analyzer = AccTransCorrections->new();
104   $analyzer->fix_ap_ar_wrong_taxkeys();
105
106   $form->{title} = $locale->text('Assistant for general ledger corrections');
107   $form->header();
108   print $form->parse_html_template('acctranscorrections/fix_ap_ar_wrong_taxkeys');
109
110   $lxdebug->leave_sub();
111 }
112
113 sub assistant_for_invoice_inventory_with_taxkeys {
114   $lxdebug->enter_sub();
115
116   $form->{title} = $locale->text('Assistant for general ledger corrections');
117
118   $form->header();
119   print $form->parse_html_template('acctranscorrections/assistant_for_invoice_inventory_with_taxkeys');
120
121   $lxdebug->leave_sub();
122 }
123
124 sub fix_invoice_inventory_with_taxkeys {
125   $lxdebug->enter_sub();
126
127   my $analyzer  = AccTransCorrections->new();
128   $analyzer->fix_invoice_inventory_with_taxkeys();
129
130   $form->{title} = $locale->text('Assistant for general ledger corrections');
131   $form->header();
132   print $form->parse_html_template('acctranscorrections/fix_invoice_inventory_with_taxkeys');
133
134   $lxdebug->leave_sub();
135 }
136
137 sub assistant_for_wrong_taxes {
138   $lxdebug->enter_sub();
139
140   my $problem = shift;
141
142   $form->{title} = $locale->text('Assistant for general ledger corrections');
143
144   $form->header();
145   print $form->parse_html_template('acctranscorrections/assistant_for_wrong_taxes', { 'problem' => $problem, });
146
147   $lxdebug->leave_sub();
148 }
149
150 sub assistant_for_wrong_taxkeys {
151   $lxdebug->enter_sub();
152
153   my $problem = shift;
154
155   $form->{title} = $locale->text('Assistant for general ledger corrections');
156
157   $form->header();
158   print $form->parse_html_template('acctranscorrections/assistant_for_wrong_taxkeys', { 'problem' => $problem, });
159
160   $lxdebug->leave_sub();
161 }
162
163 sub fix_wrong_taxkeys {
164   $lxdebug->enter_sub();
165
166   my $fixes = ref $form->{fixes} eq 'ARRAY' ? $form->{fixes} : [];
167
168   my $analyzer  = AccTransCorrections->new();
169   $analyzer->fix_wrong_taxkeys('fixes' => $fixes);
170
171   $form->{title} = $locale->text('Assistant for general ledger corrections');
172   $form->header();
173   print $form->parse_html_template('acctranscorrections/fix_wrong_taxkeys');
174
175   $lxdebug->leave_sub();
176 }
177
178 sub delete_transaction {
179   $lxdebug->enter_sub();
180
181   $form->{title} = $locale->text('Delete transaction');
182   $form->header();
183
184   if (!$form->{confirmation}) {
185     print $form->parse_html_template('acctranscorrections/delete_transaction_confirmation');
186   } else {
187     my $analyzer  = AccTransCorrections->new();
188     $analyzer->delete_transaction('trans_id' => $form->{trans_id});
189
190     print $form->parse_html_template('acctranscorrections/delete_transaction');
191   }
192
193   $lxdebug->leave_sub();
194 }
195
196 sub redirect {
197   $lxdebug->enter_sub();
198
199   $form->redirect('Missing callbcak');
200
201   $lxdebug->leave_sub();
202 }
203
204 sub dispatcher {
205   foreach my $action (qw(fix_wrong_taxkeys delete_transaction)) {
206     if ($form->{"action_${action}"}) {
207       call_sub($action);
208       return;
209     }
210   }
211
212   $form->error($locale->text('No action defined.'));
213 }
214
215 1;