1 use SL::AccTransCorrections;
7 require "bin/mozilla/common.pl";
12 $main::lxdebug->enter_sub();
14 my $form = $main::form;
15 my $locale = $main::locale;
17 $form->{title} = $locale->text('General ledger corrections');
19 print $form->parse_html_template('acctranscorrections/analyze_filter');
21 $main::lxdebug->leave_sub();
25 $main::lxdebug->enter_sub();
27 my $form = $main::form;
28 my $locale = $main::locale;
30 $form->{title} = $locale->text('General ledger corrections');
32 delete @{ $form }{qw(transdate_from transdate_to)} if ($form->{scope} eq 'full');
34 my $callback = 'acctranscorrections.pl?action=analyze';
35 map { $callback .= "&${_}=" . $form->escape($form->{$_}) } grep { $form->{$_} } qw(transdate_from transdate_to);
36 $callback = $form->escape($callback);
38 my $analyzer = AccTransCorrections->new();
40 my %params = map { $_ => $form->{$_} } qw(transdate_from transdate_to);
41 my @problems = $analyzer->analyze(%params, 'callback' => $callback);
43 if (!scalar @problems) {
44 $form->show_generic_information($locale->text('No problems were recognized.'));
46 $main::lxdebug->leave_sub();
51 print $form->parse_html_template('acctranscorrections/analyze_overview',
52 { 'PROBLEMS' => \@problems,
53 'callback' => $callback,
56 $main::lxdebug->leave_sub();
60 $main::lxdebug->enter_sub();
62 my $form = $main::form;
63 my $locale = $main::locale;
65 $form->{title} = $locale->text('Assistant for general ledger corrections');
67 $form->isblank('trans_id', $locale->text('Transaction ID missing.'));
69 my $analyzer = AccTransCorrections->new();
70 my ($problem) = $analyzer->analyze('trans_id' => $form->{trans_id}, 'full_analysis' => 1);
74 $form->{trans_module} eq 'ar' ? $locale->text('AR Transaction')
75 : $form->{trans_module} eq 'ap' ? $locale->text('AP Transaction')
76 : $locale->text('General Ledger Transaction');
78 $form->show_generic_information($locale->text('The assistant could not find anything wrong with #1. Maybe the problem has been solved in the meantime.',
79 "$module $form->{trans_reference}"));
81 $main::lxdebug->leave_sub();
85 if ($problem->{type} eq 'wrong_taxkeys') {
86 assistant_for_wrong_taxkeys($problem);
88 } elsif ($problem->{type} eq 'wrong_taxes') {
89 assistant_for_wrong_taxkeys($problem);
90 # assistant_for_wrong_taxes($problem);
93 $form->show_generic_error($locale->text('Unknown problem type.'));
96 $main::lxdebug->leave_sub();
99 sub assistant_for_ap_ar_wrong_taxkeys {
100 $main::lxdebug->enter_sub();
102 my $form = $main::form;
103 my $locale = $main::locale;
105 $form->{title} = $locale->text('Assistant for general ledger corrections');
108 print $form->parse_html_template('acctranscorrections/assistant_for_ap_ar_wrong_taxkeys');
110 $main::lxdebug->leave_sub();
113 sub fix_ap_ar_wrong_taxkeys {
114 $main::lxdebug->enter_sub();
116 my $form = $main::form;
117 my $locale = $main::locale;
119 my $analyzer = AccTransCorrections->new();
120 $analyzer->fix_ap_ar_wrong_taxkeys();
122 $form->{title} = $locale->text('Assistant for general ledger corrections');
124 print $form->parse_html_template('acctranscorrections/fix_ap_ar_wrong_taxkeys');
126 $main::lxdebug->leave_sub();
129 sub assistant_for_invoice_inventory_with_taxkeys {
130 $main::lxdebug->enter_sub();
132 my $form = $main::form;
133 my $locale = $main::locale;
135 $form->{title} = $locale->text('Assistant for general ledger corrections');
138 print $form->parse_html_template('acctranscorrections/assistant_for_invoice_inventory_with_taxkeys');
140 $main::lxdebug->leave_sub();
143 sub fix_invoice_inventory_with_taxkeys {
144 $main::lxdebug->enter_sub();
146 my $form = $main::form;
147 my $locale = $main::locale;
149 my $analyzer = AccTransCorrections->new();
150 $analyzer->fix_invoice_inventory_with_taxkeys();
152 $form->{title} = $locale->text('Assistant for general ledger corrections');
154 print $form->parse_html_template('acctranscorrections/fix_invoice_inventory_with_taxkeys');
156 $main::lxdebug->leave_sub();
159 sub assistant_for_wrong_taxes {
160 $main::lxdebug->enter_sub();
162 my $form = $main::form;
163 my $locale = $main::locale;
167 $form->{title} = $locale->text('Assistant for general ledger corrections');
170 print $form->parse_html_template('acctranscorrections/assistant_for_wrong_taxes', { 'problem' => $problem, });
172 $main::lxdebug->leave_sub();
175 sub assistant_for_wrong_taxkeys {
176 $main::lxdebug->enter_sub();
178 my $form = $main::form;
179 my $locale = $main::locale;
183 $form->{title} = $locale->text('Assistant for general ledger corrections');
186 print $form->parse_html_template('acctranscorrections/assistant_for_wrong_taxkeys', { 'problem' => $problem, });
188 $main::lxdebug->leave_sub();
191 sub fix_wrong_taxkeys {
192 $main::lxdebug->enter_sub();
194 my $form = $main::form;
195 my $locale = $main::locale;
197 my $fixes = ref $form->{fixes} eq 'ARRAY' ? $form->{fixes} : [];
199 my $analyzer = AccTransCorrections->new();
200 $analyzer->fix_wrong_taxkeys('fixes' => $fixes);
202 $form->{title} = $locale->text('Assistant for general ledger corrections');
204 print $form->parse_html_template('acctranscorrections/fix_wrong_taxkeys');
206 $main::lxdebug->leave_sub();
209 sub delete_transaction {
210 $main::lxdebug->enter_sub();
212 my $form = $main::form;
213 my $locale = $main::locale;
215 $form->{title} = $locale->text('Delete transaction');
218 if (!$form->{confirmation}) {
219 print $form->parse_html_template('acctranscorrections/delete_transaction_confirmation');
221 my $analyzer = AccTransCorrections->new();
222 $analyzer->delete_transaction('trans_id' => $form->{trans_id});
224 print $form->parse_html_template('acctranscorrections/delete_transaction');
227 $main::lxdebug->leave_sub();
231 $main::lxdebug->enter_sub();
233 my $form = $main::form;
235 $form->redirect('Missing callbcak');
237 $main::lxdebug->leave_sub();
241 my $form = $main::form;
242 my $locale = $main::locale;
244 foreach my $action (qw(fix_wrong_taxkeys delete_transaction)) {
245 if ($form->{"action_${action}"}) {
251 $form->error($locale->text('No action defined.'));