1 use SL::AccTransCorrections;
3 use SL::Locale::String qw(t8);
7 require "bin/mozilla/common.pl";
12 $main::lxdebug->enter_sub();
14 my $form = $main::form;
15 my $locale = $main::locale;
17 setup_analyze_filter_action_bar();
19 $form->{title} = $locale->text('General ledger corrections');
21 print $form->parse_html_template('acctranscorrections/analyze_filter');
23 $main::lxdebug->leave_sub();
27 $main::lxdebug->enter_sub();
29 my $form = $main::form;
30 my $locale = $main::locale;
32 $form->{title} = $locale->text('General ledger corrections');
34 delete @{ $form }{qw(transdate_from transdate_to)} if ($form->{scope} eq 'full');
36 my $callback = 'acctranscorrections.pl?action=analyze';
37 map { $callback .= "&${_}=" . $form->escape($form->{$_}) } grep { $form->{$_} } qw(transdate_from transdate_to);
38 $callback = $form->escape($callback);
40 my $analyzer = AccTransCorrections->new();
42 my %params = map { $_ => $form->{$_} } qw(transdate_from transdate_to);
43 my @problems = $analyzer->analyze(%params, 'callback' => $callback);
45 if (!scalar @problems) {
46 $form->show_generic_information($locale->text('No problems were recognized.'));
48 $main::lxdebug->leave_sub();
52 setup_analyze_action_bar();
55 print $form->parse_html_template('acctranscorrections/analyze_overview',
56 { 'PROBLEMS' => \@problems,
57 'callback' => $callback,
60 $main::lxdebug->leave_sub();
64 $main::lxdebug->enter_sub();
66 my $form = $main::form;
67 my $locale = $main::locale;
69 $form->{title} = $locale->text('Assistant for general ledger corrections');
71 $form->isblank('trans_id', $locale->text('Transaction ID missing.'));
73 my $analyzer = AccTransCorrections->new();
74 my ($problem) = $analyzer->analyze('trans_id' => $form->{trans_id}, 'full_analysis' => 1);
78 $form->{trans_module} eq 'ar' ? $locale->text('AR Transaction')
79 : $form->{trans_module} eq 'ap' ? $locale->text('AP Transaction')
80 : $locale->text('General Ledger Transaction');
82 $form->show_generic_information($locale->text('The assistant could not find anything wrong with #1. Maybe the problem has been solved in the meantime.',
83 "$module $form->{trans_reference}"));
85 $main::lxdebug->leave_sub();
89 if ($problem->{type} eq 'wrong_taxkeys') {
90 assistant_for_wrong_taxkeys($problem);
92 } elsif ($problem->{type} eq 'wrong_taxes') {
93 assistant_for_wrong_taxkeys($problem);
94 # assistant_for_wrong_taxes($problem);
97 $form->show_generic_error($locale->text('Unknown problem type.'));
100 $main::lxdebug->leave_sub();
103 sub assistant_for_ap_ar_wrong_taxkeys {
104 $main::lxdebug->enter_sub();
106 my $form = $main::form;
107 my $locale = $main::locale;
109 $form->{title} = $locale->text('Assistant for general ledger corrections');
112 print $form->parse_html_template('acctranscorrections/assistant_for_ap_ar_wrong_taxkeys');
114 $main::lxdebug->leave_sub();
117 sub fix_ap_ar_wrong_taxkeys {
118 $main::lxdebug->enter_sub();
120 my $form = $main::form;
121 my $locale = $main::locale;
123 my $analyzer = AccTransCorrections->new();
124 $analyzer->fix_ap_ar_wrong_taxkeys();
126 $form->{title} = $locale->text('Assistant for general ledger corrections');
128 print $form->parse_html_template('acctranscorrections/fix_ap_ar_wrong_taxkeys');
130 $main::lxdebug->leave_sub();
133 sub assistant_for_invoice_inventory_with_taxkeys {
134 $main::lxdebug->enter_sub();
136 my $form = $main::form;
137 my $locale = $main::locale;
139 $form->{title} = $locale->text('Assistant for general ledger corrections');
142 print $form->parse_html_template('acctranscorrections/assistant_for_invoice_inventory_with_taxkeys');
144 $main::lxdebug->leave_sub();
147 sub fix_invoice_inventory_with_taxkeys {
148 $main::lxdebug->enter_sub();
150 my $form = $main::form;
151 my $locale = $main::locale;
153 my $analyzer = AccTransCorrections->new();
154 $analyzer->fix_invoice_inventory_with_taxkeys();
156 $form->{title} = $locale->text('Assistant for general ledger corrections');
158 print $form->parse_html_template('acctranscorrections/fix_invoice_inventory_with_taxkeys');
160 $main::lxdebug->leave_sub();
163 sub assistant_for_wrong_taxes {
164 $main::lxdebug->enter_sub();
166 my $form = $main::form;
167 my $locale = $main::locale;
171 $form->{title} = $locale->text('Assistant for general ledger corrections');
174 print $form->parse_html_template('acctranscorrections/assistant_for_wrong_taxes', { 'problem' => $problem, });
176 $main::lxdebug->leave_sub();
179 sub assistant_for_wrong_taxkeys {
180 $main::lxdebug->enter_sub();
182 my $form = $main::form;
183 my $locale = $main::locale;
187 $form->{title} = $locale->text('Assistant for general ledger corrections');
190 print $form->parse_html_template('acctranscorrections/assistant_for_wrong_taxkeys', { 'problem' => $problem, });
192 $main::lxdebug->leave_sub();
195 sub fix_wrong_taxkeys {
196 $main::lxdebug->enter_sub();
198 my $form = $main::form;
199 my $locale = $main::locale;
201 my $fixes = ref $form->{fixes} eq 'ARRAY' ? $form->{fixes} : [];
203 my $analyzer = AccTransCorrections->new();
204 $analyzer->fix_wrong_taxkeys('fixes' => $fixes);
206 $form->{title} = $locale->text('Assistant for general ledger corrections');
208 print $form->parse_html_template('acctranscorrections/fix_wrong_taxkeys');
210 $main::lxdebug->leave_sub();
213 sub delete_transaction {
214 $main::lxdebug->enter_sub();
216 my $form = $main::form;
217 my $locale = $main::locale;
219 $form->{title} = $locale->text('Delete transaction');
222 if (!$form->{confirmation}) {
223 print $form->parse_html_template('acctranscorrections/delete_transaction_confirmation');
225 my $analyzer = AccTransCorrections->new();
226 $analyzer->delete_transaction('trans_id' => $form->{trans_id});
228 print $form->parse_html_template('acctranscorrections/delete_transaction');
231 $main::lxdebug->leave_sub();
235 $main::lxdebug->enter_sub();
237 my $form = $main::form;
239 $form->redirect('Missing callbcak');
241 $main::lxdebug->leave_sub();
245 my $form = $main::form;
246 my $locale = $main::locale;
248 foreach my $action (qw(fix_wrong_taxkeys delete_transaction)) {
249 if ($form->{"action_${action}"}) {
255 $form->error($locale->text('No action defined.'));
258 sub setup_analyze_filter_action_bar {
261 for my $bar ($::request->layout->get('actionbar')) {
265 submit => [ '#form' ],
266 accesskey => 'enter',
272 sub setup_analyze_action_bar {
275 for my $bar ($::request->layout->get('actionbar')) {
279 call => [ 'kivi.history_back' ],