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->{jsscript} = 1;
18 $form->{title} = $locale->text('General ledger corrections');
20 print $form->parse_html_template('acctranscorrections/analyze_filter');
22 $main::lxdebug->leave_sub();
26 $main::lxdebug->enter_sub();
28 my $form = $main::form;
29 my $locale = $main::locale;
31 $form->{title} = $locale->text('General ledger corrections');
33 delete @{ $form }{qw(transdate_from transdate_to)} if ($form->{scope} eq 'full');
35 my $callback = 'acctranscorrections.pl?action=analyze';
36 map { $callback .= "&${_}=" . $form->escape($form->{$_}) } grep { $form->{$_} } qw(transdate_from transdate_to);
37 $callback = $form->escape($callback);
39 my $analyzer = AccTransCorrections->new();
41 my %params = map { $_ => $form->{$_} } qw(transdate_from transdate_to);
42 my @problems = $analyzer->analyze(%params, 'callback' => $callback);
44 if (!scalar @problems) {
45 $form->show_generic_information($locale->text('No problems were recognized.'));
47 $main::lxdebug->leave_sub();
52 print $form->parse_html_template('acctranscorrections/analyze_overview',
53 { 'PROBLEMS' => \@problems,
54 'callback' => $callback,
57 $main::lxdebug->leave_sub();
61 $main::lxdebug->enter_sub();
63 my $form = $main::form;
64 my $locale = $main::locale;
66 $form->{title} = $locale->text('Assistant for general ledger corrections');
68 $form->isblank('trans_id', $locale->text('Transaction ID missing.'));
70 my $analyzer = AccTransCorrections->new();
71 my ($problem) = $analyzer->analyze('trans_id' => $form->{trans_id}, 'full_analysis' => 1);
75 $form->{trans_module} eq 'ar' ? $locale->text('AR Transaction')
76 : $form->{trans_module} eq 'ap' ? $locale->text('AP Transaction')
77 : $locale->text('General Ledger Transaction');
79 $form->show_generic_information($locale->text('The assistant could not find anything wrong with #1. Maybe the problem has been solved in the meantime.',
80 "$module $form->{trans_reference}"));
82 $main::lxdebug->leave_sub();
86 if ($problem->{type} eq 'wrong_taxkeys') {
87 assistant_for_wrong_taxkeys($problem);
89 } elsif ($problem->{type} eq 'wrong_taxes') {
90 assistant_for_wrong_taxkeys($problem);
91 # assistant_for_wrong_taxes($problem);
94 $form->show_generic_error($locale->text('Unknown problem type.'));
97 $main::lxdebug->leave_sub();
100 sub assistant_for_ap_ar_wrong_taxkeys {
101 $main::lxdebug->enter_sub();
103 my $form = $main::form;
104 my $locale = $main::locale;
106 $form->{title} = $locale->text('Assistant for general ledger corrections');
109 print $form->parse_html_template('acctranscorrections/assistant_for_ap_ar_wrong_taxkeys');
111 $main::lxdebug->leave_sub();
114 sub fix_ap_ar_wrong_taxkeys {
115 $main::lxdebug->enter_sub();
117 my $form = $main::form;
118 my $locale = $main::locale;
120 my $analyzer = AccTransCorrections->new();
121 $analyzer->fix_ap_ar_wrong_taxkeys();
123 $form->{title} = $locale->text('Assistant for general ledger corrections');
125 print $form->parse_html_template('acctranscorrections/fix_ap_ar_wrong_taxkeys');
127 $main::lxdebug->leave_sub();
130 sub assistant_for_invoice_inventory_with_taxkeys {
131 $main::lxdebug->enter_sub();
133 my $form = $main::form;
134 my $locale = $main::locale;
136 $form->{title} = $locale->text('Assistant for general ledger corrections');
139 print $form->parse_html_template('acctranscorrections/assistant_for_invoice_inventory_with_taxkeys');
141 $main::lxdebug->leave_sub();
144 sub fix_invoice_inventory_with_taxkeys {
145 $main::lxdebug->enter_sub();
147 my $form = $main::form;
148 my $locale = $main::locale;
150 my $analyzer = AccTransCorrections->new();
151 $analyzer->fix_invoice_inventory_with_taxkeys();
153 $form->{title} = $locale->text('Assistant for general ledger corrections');
155 print $form->parse_html_template('acctranscorrections/fix_invoice_inventory_with_taxkeys');
157 $main::lxdebug->leave_sub();
160 sub assistant_for_wrong_taxes {
161 $main::lxdebug->enter_sub();
163 my $form = $main::form;
164 my $locale = $main::locale;
168 $form->{title} = $locale->text('Assistant for general ledger corrections');
171 print $form->parse_html_template('acctranscorrections/assistant_for_wrong_taxes', { 'problem' => $problem, });
173 $main::lxdebug->leave_sub();
176 sub assistant_for_wrong_taxkeys {
177 $main::lxdebug->enter_sub();
179 my $form = $main::form;
180 my $locale = $main::locale;
184 $form->{title} = $locale->text('Assistant for general ledger corrections');
187 print $form->parse_html_template('acctranscorrections/assistant_for_wrong_taxkeys', { 'problem' => $problem, });
189 $main::lxdebug->leave_sub();
192 sub fix_wrong_taxkeys {
193 $main::lxdebug->enter_sub();
195 my $form = $main::form;
196 my $locale = $main::locale;
198 my $fixes = ref $form->{fixes} eq 'ARRAY' ? $form->{fixes} : [];
200 my $analyzer = AccTransCorrections->new();
201 $analyzer->fix_wrong_taxkeys('fixes' => $fixes);
203 $form->{title} = $locale->text('Assistant for general ledger corrections');
205 print $form->parse_html_template('acctranscorrections/fix_wrong_taxkeys');
207 $main::lxdebug->leave_sub();
210 sub delete_transaction {
211 $main::lxdebug->enter_sub();
213 my $form = $main::form;
214 my $locale = $main::locale;
216 $form->{title} = $locale->text('Delete transaction');
219 if (!$form->{confirmation}) {
220 print $form->parse_html_template('acctranscorrections/delete_transaction_confirmation');
222 my $analyzer = AccTransCorrections->new();
223 $analyzer->delete_transaction('trans_id' => $form->{trans_id});
225 print $form->parse_html_template('acctranscorrections/delete_transaction');
228 $main::lxdebug->leave_sub();
232 $main::lxdebug->enter_sub();
234 my $form = $main::form;
236 $form->redirect('Missing callbcak');
238 $main::lxdebug->leave_sub();
242 my $form = $main::form;
243 my $locale = $main::locale;
245 foreach my $action (qw(fix_wrong_taxkeys delete_transaction)) {
246 if ($form->{"action_${action}"}) {
252 $form->error($locale->text('No action defined.'));