1 use SL::AccTransCorrections;
3 use SL::Locale::String qw(t8);
8 require "bin/mozilla/common.pl";
13 $main::lxdebug->enter_sub();
15 my $form = $main::form;
16 my $locale = $main::locale;
18 setup_analyze_filter_action_bar();
20 $form->{title} = $locale->text('General ledger corrections');
22 print $form->parse_html_template('acctranscorrections/analyze_filter');
24 $main::lxdebug->leave_sub();
28 $main::lxdebug->enter_sub();
30 my $form = $main::form;
31 my $locale = $main::locale;
33 $form->{title} = $locale->text('General ledger corrections');
35 delete @{ $form }{qw(transdate_from transdate_to)} if ($form->{scope} eq 'full');
37 my $callback = 'acctranscorrections.pl?action=analyze';
38 map { $callback .= "&${_}=" . $form->escape($form->{$_}) } grep { $form->{$_} } qw(transdate_from transdate_to);
39 $callback = $form->escape($callback);
41 my $analyzer = AccTransCorrections->new();
43 my %params = map { $_ => $form->{$_} } qw(transdate_from transdate_to);
44 my @problems = $analyzer->analyze(%params, 'callback' => $callback);
46 if (!scalar @problems) {
47 $form->show_generic_information($locale->text('No problems were recognized.'));
49 $main::lxdebug->leave_sub();
53 setup_analyze_action_bar();
56 print $form->parse_html_template('acctranscorrections/analyze_overview',
57 { 'PROBLEMS' => \@problems,
58 'callback' => $callback,
61 $main::lxdebug->leave_sub();
65 $main::lxdebug->enter_sub();
67 my $form = $main::form;
68 my $locale = $main::locale;
70 $form->{title} = $locale->text('Assistant for general ledger corrections');
72 $form->isblank('trans_id', $locale->text('Transaction ID missing.'));
74 my $analyzer = AccTransCorrections->new();
75 my ($problem) = $analyzer->analyze('trans_id' => $form->{trans_id}, 'full_analysis' => 1);
79 $form->{trans_module} eq 'ar' ? $locale->text('AR Transaction')
80 : $form->{trans_module} eq 'ap' ? $locale->text('AP Transaction')
81 : $locale->text('General Ledger Transaction');
83 $form->show_generic_information($locale->text('The assistant could not find anything wrong with #1. Maybe the problem has been solved in the meantime.',
84 "$module $form->{trans_reference}"));
86 $main::lxdebug->leave_sub();
90 if ($problem->{type} eq 'wrong_taxkeys') {
91 assistant_for_wrong_taxkeys($problem);
93 } elsif ($problem->{type} eq 'wrong_taxes') {
94 assistant_for_wrong_taxkeys($problem);
95 # assistant_for_wrong_taxes($problem);
98 $form->show_generic_error($locale->text('Unknown problem type.'));
101 $main::lxdebug->leave_sub();
104 sub assistant_for_ap_ar_wrong_taxkeys {
105 $main::lxdebug->enter_sub();
107 my $form = $main::form;
108 my $locale = $main::locale;
110 $form->{title} = $locale->text('Assistant for general ledger corrections');
113 print $form->parse_html_template('acctranscorrections/assistant_for_ap_ar_wrong_taxkeys');
115 $main::lxdebug->leave_sub();
118 sub fix_ap_ar_wrong_taxkeys {
119 $main::lxdebug->enter_sub();
121 my $form = $main::form;
122 my $locale = $main::locale;
124 my $analyzer = AccTransCorrections->new();
125 $analyzer->fix_ap_ar_wrong_taxkeys();
127 $form->{title} = $locale->text('Assistant for general ledger corrections');
129 print $form->parse_html_template('acctranscorrections/fix_ap_ar_wrong_taxkeys');
131 $main::lxdebug->leave_sub();
134 sub assistant_for_invoice_inventory_with_taxkeys {
135 $main::lxdebug->enter_sub();
137 my $form = $main::form;
138 my $locale = $main::locale;
140 $form->{title} = $locale->text('Assistant for general ledger corrections');
143 print $form->parse_html_template('acctranscorrections/assistant_for_invoice_inventory_with_taxkeys');
145 $main::lxdebug->leave_sub();
148 sub fix_invoice_inventory_with_taxkeys {
149 $main::lxdebug->enter_sub();
151 my $form = $main::form;
152 my $locale = $main::locale;
154 my $analyzer = AccTransCorrections->new();
155 $analyzer->fix_invoice_inventory_with_taxkeys();
157 $form->{title} = $locale->text('Assistant for general ledger corrections');
159 print $form->parse_html_template('acctranscorrections/fix_invoice_inventory_with_taxkeys');
161 $main::lxdebug->leave_sub();
164 sub assistant_for_wrong_taxes {
165 $main::lxdebug->enter_sub();
167 my $form = $main::form;
168 my $locale = $main::locale;
172 $form->{title} = $locale->text('Assistant for general ledger corrections');
175 print $form->parse_html_template('acctranscorrections/assistant_for_wrong_taxes', { 'problem' => $problem, });
177 $main::lxdebug->leave_sub();
180 sub assistant_for_wrong_taxkeys {
181 $main::lxdebug->enter_sub();
183 my $form = $main::form;
184 my $locale = $main::locale;
188 $form->{title} = $locale->text('Assistant for general ledger corrections');
191 print $form->parse_html_template('acctranscorrections/assistant_for_wrong_taxkeys', { 'problem' => $problem, });
193 $main::lxdebug->leave_sub();
196 sub fix_wrong_taxkeys {
197 $main::lxdebug->enter_sub();
199 my $form = $main::form;
200 my $locale = $main::locale;
202 my $fixes = ref $form->{fixes} eq 'ARRAY' ? $form->{fixes} : [];
204 my $analyzer = AccTransCorrections->new();
205 $analyzer->fix_wrong_taxkeys('fixes' => $fixes);
207 $form->{title} = $locale->text('Assistant for general ledger corrections');
209 print $form->parse_html_template('acctranscorrections/fix_wrong_taxkeys');
211 $main::lxdebug->leave_sub();
214 sub delete_transaction {
215 $main::lxdebug->enter_sub();
217 my $form = $main::form;
218 my $locale = $main::locale;
220 $form->{title} = $locale->text('Delete transaction');
223 if (!$form->{confirmation}) {
224 print $form->parse_html_template('acctranscorrections/delete_transaction_confirmation');
226 my $analyzer = AccTransCorrections->new();
227 $analyzer->delete_transaction('trans_id' => $form->{trans_id});
229 print $form->parse_html_template('acctranscorrections/delete_transaction');
232 $main::lxdebug->leave_sub();
236 $main::lxdebug->enter_sub();
238 my $form = $main::form;
240 $form->redirect('Missing callbcak');
242 $main::lxdebug->leave_sub();
246 my $form = $main::form;
247 my $locale = $main::locale;
249 foreach my $action (qw(fix_wrong_taxkeys delete_transaction)) {
250 if ($form->{"action_${action}"}) {
256 $form->error($locale->text('No action defined.'));
259 sub setup_analyze_filter_action_bar {
262 for my $bar ($::request->layout->get('actionbar')) {
266 submit => [ '#form' ],
267 accesskey => 'enter',
273 sub setup_analyze_action_bar {
276 for my $bar ($::request->layout->get('actionbar')) {
280 call => [ 'kivi.history_back' ],