Revision 41cceb1e
Von Moritz Bunkus vor fast 8 Jahren hinzugefügt
bin/mozilla/ar.pl | ||
---|---|---|
38 | 38 |
|
39 | 39 |
use SL::AR; |
40 | 40 |
use SL::FU; |
41 |
use SL::GL; |
|
41 | 42 |
use SL::IS; |
42 | 43 |
use SL::DB::Default; |
43 | 44 |
use SL::DB::Invoice; |
... | ... | |
101 | 102 |
$form->{initial_transdate} = $form->{transdate}; |
102 | 103 |
create_links(dont_save => 1); |
103 | 104 |
$form->{transdate} = $form->{initial_transdate}; |
105 |
|
|
106 |
if ($form->{customer_id}) { |
|
107 |
my $last_used_ar_chart = SL::DB::Customer->load_cached($form->{customer_id})->last_used_ar_chart; |
|
108 |
$form->{"AR_amount_chart_id_1"} = $last_used_ar_chart->id if $last_used_ar_chart; |
|
109 |
} |
|
110 |
|
|
104 | 111 |
&display_form; |
105 | 112 |
$main::lxdebug->leave_sub(); |
106 | 113 |
} |
... | ... | |
167 | 174 |
$form->{$_} = $saved{$_} for keys %saved; |
168 | 175 |
$form->{oldcustomer} = "$form->{customer}--$form->{customer_id}"; |
169 | 176 |
$form->{rowcount} = 1; |
177 |
$form->{AR_chart_id} = $form->{acc_trans} && $form->{acc_trans}->{AR} ? $form->{acc_trans}->{AR}->[0]->{chart_id} : $form->{AR_links}->{AR}->[0]->{chart_id}; |
|
170 | 178 |
|
171 | 179 |
# currencies |
172 | 180 |
$form->{defaultcurrency} = $form->get_default_currency(\%myconfig); |
... | ... | |
218 | 226 |
|
219 | 227 |
my ($title, $readonly, $exchangerate, $rows); |
220 | 228 |
my ($notes, $customer, $employee, $amount, $project); |
221 |
my ($ARselected); |
|
222 | 229 |
|
230 |
$form->{initial_focus} = !($form->{amount_1} * 1) ? 'customer' : 'row_' . $form->{rowcount}; |
|
223 | 231 |
|
224 | 232 |
$title = $form->{title}; |
225 | 233 |
# $locale->text('Add Accounts Receivables Transaction') |
226 | 234 |
# $locale->text('Edit Accounts Receivables Transaction') |
227 | 235 |
$form->{title} = $locale->text("$title Accounts Receivables Transaction"); |
228 | 236 |
|
229 |
$form->{javascript} = qq|<script type="text/javascript"> |
|
230 |
<!-- |
|
231 |
function setTaxkey(accno, row) { |
|
232 |
var taxkey = accno.options[accno.selectedIndex].value; |
|
233 |
var reg = /--([0-9]*)/; |
|
234 |
var found = reg.exec(taxkey); |
|
235 |
var index = found[1]; |
|
236 |
index = parseInt(index); |
|
237 |
var tax = 'taxchart_' + row; |
|
238 |
for (var i = 0; i < document.getElementById(tax).options.length; ++i) { |
|
239 |
var reg2 = new RegExp("^"+ index, ""); |
|
240 |
if (reg2.exec(document.getElementById(tax).options[i].value)) { |
|
241 |
document.getElementById(tax).options[i].selected = true; |
|
242 |
break; |
|
243 |
} |
|
244 |
} |
|
245 |
}; |
|
246 |
//--> |
|
247 |
</script>|; |
|
248 |
# show history button js |
|
249 |
$form->{javascript} .= qq|<script type="text/javascript" src="js/show_history.js"></script>|; |
|
250 |
#/show history button js |
|
251 | 237 |
$readonly = ($form->{id}) ? "readonly" : ""; |
252 | 238 |
|
253 | 239 |
$form->{radier} = ($::instance_conf->get_ar_changeable == 2) |
... | ... | |
285 | 271 |
|
286 | 272 |
my %project_labels = map { $_->{id} => $_->{projectnumber} } @{ $form->{"ALL_PROJECTS"} }; |
287 | 273 |
|
288 |
my (@AR_amount_values); |
|
289 |
my (@AR_values); |
|
290 |
my (@AR_paid_values); |
|
291 |
my %chart_labels; |
|
292 |
my %charts; |
|
293 |
my $taxchart_init; |
|
274 |
my (@AR_paid_values, %AR_paid_labels); |
|
275 |
my $default_ar_amount_chart_id; |
|
294 | 276 |
|
295 | 277 |
foreach my $item (@{ $form->{ALL_CHARTS} }) { |
296 | 278 |
if ($item->{link_split}{AR_amount}) { |
297 |
$taxchart_init = $item->{tax_id} if ($taxchart_init eq ""); |
|
298 |
my $key = "$item->{accno}--$item->{tax_id}"; |
|
299 |
push(@AR_amount_values, $key); |
|
300 |
} elsif ($item->{link_split}{AR}) { |
|
301 |
push(@AR_values, $item->{accno}); |
|
279 |
$default_ar_amount_chart_id //= $item->{id}; |
|
280 |
|
|
302 | 281 |
} elsif ($item->{link_split}{AR_paid}) { |
303 | 282 |
push(@AR_paid_values, $item->{accno}); |
283 |
$AR_paid_labels{$item->{accno}} = "$item->{accno}--$item->{description}"; |
|
304 | 284 |
} |
305 |
|
|
306 |
# weirdness for AR_amount |
|
307 |
$chart_labels{$item->{accno}} = "$item->{accno}--$item->{description}"; |
|
308 |
$chart_labels{"$item->{accno}--$item->{tax_id}"} = "$item->{accno}--$item->{description}"; |
|
309 |
|
|
310 |
$charts{$item->{accno}} = $item; |
|
311 |
} |
|
312 |
|
|
313 |
my %taxchart_labels = (); |
|
314 |
my @taxchart_values = (); |
|
315 |
my %taxcharts = (); |
|
316 |
foreach my $item (@{ $form->{ALL_TAXCHARTS} }) { |
|
317 |
my $key = "$item->{id}--$item->{rate}"; |
|
318 |
$taxchart_init = $key if ($taxchart_init eq $item->{id}); |
|
319 |
push(@taxchart_values, $key); |
|
320 |
$taxchart_labels{$key} = "$item->{taxdescription} " . ($item->{rate} * 100) . ' %'; |
|
321 |
$taxcharts{$item->{id}} = $item; |
|
322 | 285 |
} |
323 | 286 |
|
324 | 287 |
my $follow_up_vc = $form->{customer}; |
325 | 288 |
$follow_up_vc =~ s/--.*?//; |
326 | 289 |
my $follow_up_trans_info = "$form->{invnumber} ($follow_up_vc)"; |
327 | 290 |
|
328 |
$form->{javascript} .= |
|
329 |
qq|<script type="text/javascript" src="js/show_vc_details.js"></script>| . |
|
330 |
qq|<script type="text/javascript" src="js/follow_up.js"></script>| . |
|
331 |
qq|<script type="text/javascript" src="js/kivi.Draft.js"></script>|; |
|
291 |
$::request->layout->add_javascripts("autocomplete_chart.js", "show_vc_details.js", "show_history.js", "follow_up.js", "kivi.Draft.js", "kivi.GL.js"); |
|
332 | 292 |
|
333 |
# $amount = $locale->text('Amount');
|
|
334 |
# $project = $locale->text('Project');
|
|
293 |
my $transdate = $::form->{transdate} ? DateTime->from_kivitendo($::form->{transdate}) : DateTime->today_local;
|
|
294 |
my $first_taxchart;
|
|
335 | 295 |
|
336 | 296 |
my @transactions; |
337 | 297 |
for my $i (1 .. $form->{rowcount}) { |
... | ... | |
341 | 301 |
project_id => ($i==$form->{rowcount}) ? $form->{globalproject_id} : $form->{"project_id_$i"}, |
342 | 302 |
}; |
343 | 303 |
|
344 |
my $selected_accno_full; |
|
345 |
my ($accno_row) = split(/--/, $form->{"AR_amount_$i"}); |
|
346 |
my $item = $charts{$accno_row}; |
|
347 |
$selected_accno_full = "$item->{accno}--$item->{tax_id}"; |
|
304 |
my (%taxchart_labels, @taxchart_values, $default_taxchart, $taxchart_to_use); |
|
305 |
my $amount_chart_id = $form->{"AR_amount_chart_id_$i"} // $default_ar_amount_chart_id; |
|
306 |
my $chart_has_changed = $::form->{"previous_AR_amount_chart_id_$i"} && ($amount_chart_id != $::form->{"previous_AR_amount_chart_id_$i"}); |
|
348 | 307 |
|
349 |
my $selected_taxchart = $form->{"taxchart_$i"}; |
|
350 |
my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full); |
|
351 |
my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_AR_amount_$i"}); |
|
308 |
foreach my $item ( GL->get_active_taxes_for_chart($amount_chart_id, $transdate) ) { |
|
309 |
my $key = $item->id . "--" . $item->rate; |
|
310 |
$first_taxchart //= $item; |
|
311 |
$default_taxchart = $item if $item->{is_default}; |
|
312 |
$taxchart_to_use = $item if $key eq $form->{"taxchart_$i"}; |
|
352 | 313 |
|
353 |
if ($previous_accno && |
|
354 |
($previous_accno eq $selected_accno) && |
|
355 |
($previous_tax_id ne $selected_tax_id)) { |
|
356 |
my $item = $taxcharts{$selected_tax_id}; |
|
357 |
$selected_taxchart = "$item->{id}--$item->{rate}"; |
|
314 |
push(@taxchart_values, $key); |
|
315 |
$taxchart_labels{$key} = $item->taxdescription . " " . $item->rate * 100 . ' %'; |
|
358 | 316 |
} |
359 | 317 |
|
360 |
if (!$form->{"taxchart_$i"}) { |
|
361 |
if ($form->{"AR_amount_$i"} =~ m/.--./) { |
|
362 |
$selected_taxchart = join '--', map { ($_->{id}, $_->{rate}) } first { $_->{id} == $item->{tax_id} } @{ $form->{ALL_TAXCHARTS} }; |
|
363 |
} else { |
|
364 |
$selected_taxchart = $taxchart_init; |
|
365 |
} |
|
366 |
} |
|
318 |
$taxchart_to_use = $default_taxchart // $first_taxchart if $chart_has_changed || !$taxchart_to_use; |
|
319 |
my $selected_taxchart = $taxchart_to_use->id . '--' . $taxchart_to_use->rate; |
|
367 | 320 |
|
368 | 321 |
$transaction->{selectAR_amount} = |
369 |
NTI($cgi->popup_menu('-name' => "AR_amount_$i", |
|
370 |
'-id' => "AR_amount_$i", |
|
371 |
'-style' => 'width:400px', |
|
372 |
'-onChange' => "setTaxkey(this, $i)", |
|
373 |
'-values' => \@AR_amount_values, |
|
374 |
'-labels' => \%chart_labels, |
|
375 |
'-default' => $selected_accno_full)) |
|
376 |
. $cgi->hidden('-name' => "previous_AR_amount_$i", |
|
377 |
'-default' => $selected_accno_full); |
|
322 |
$::request->presenter->chart_picker("AR_amount_chart_id_$i", $amount_chart_id, style => "width: 400px", type => "AR_amount", class => ($form->{initial_focus} eq "row_$i" ? "initial_focus" : "")) |
|
323 |
. $::request->presenter->hidden_tag("previous_AR_amount_chart_id_$i", $amount_chart_id); |
|
378 | 324 |
|
379 | 325 |
$transaction->{taxchart} = |
380 | 326 |
NTI($cgi->popup_menu('-name' => "taxchart_$i", |
... | ... | |
389 | 335 |
|
390 | 336 |
$form->{invtotal_unformatted} = $form->{invtotal}; |
391 | 337 |
|
392 |
$ARselected = |
|
393 |
NTI($cgi->popup_menu('-name' => "ARselected", '-id' => "ARselected", |
|
394 |
'-style' => 'width:400px', |
|
395 |
'-values' => \@AR_values, '-labels' => \%chart_labels, |
|
396 |
'-default' => $form->{ARselected})); |
|
397 |
|
|
398 |
|
|
399 | 338 |
$form->{paidaccounts}++ if ($form->{"paid_$form->{paidaccounts}"}); |
400 | 339 |
|
401 | 340 |
my $now = $form->current_date(\%myconfig); |
... | ... | |
423 | 362 |
NTI($cgi->popup_menu('-name' => "AR_paid_$i", |
424 | 363 |
'-id' => "AR_paid_$i", |
425 | 364 |
'-values' => \@AR_paid_values, |
426 |
'-labels' => \%chart_labels,
|
|
365 |
'-labels' => \%AR_paid_labels,
|
|
427 | 366 |
'-default' => $payment->{AR_paid} || $form->{accno_arap})); |
428 | 367 |
|
429 | 368 |
|
... | ... | |
457 | 396 |
transactions => \@transactions, |
458 | 397 |
project_labels => \%project_labels, |
459 | 398 |
rows => $rows, |
460 |
ARselected => $ARselected,
|
|
399 |
AR_chart_id => $form->{AR_chart_id},
|
|
461 | 400 |
title_str => $title, |
462 | 401 |
follow_up_trans_info => $follow_up_trans_info, |
463 | 402 |
today => DateTime->today, |
... | ... | |
570 | 509 |
|
571 | 510 |
$form->{invdate} = $form->{transdate}; |
572 | 511 |
|
573 |
my %saved_variables = map +( $_ => $form->{$_} ), qw(AR AR_amount_1 taxchart_1 customer_id notes); |
|
574 |
|
|
575 | 512 |
&check_name("customer"); |
576 | 513 |
|
577 |
$form->{AR} = $saved_variables{AR}; |
|
578 |
if ($saved_variables{AR_amount_1} =~ m/.--./) { |
|
579 |
map { $form->{$_} = $saved_variables{$_} } qw(AR_amount_1 taxchart_1); |
|
580 |
} else { |
|
581 |
delete $form->{taxchart_1}; |
|
582 |
} |
|
583 |
|
|
584 | 514 |
$form->{invtotal} = |
585 | 515 |
($form->{taxincluded}) ? $form->{invtotal} : $form->{invtotal} + $totaltax; |
586 | 516 |
|
Auch abrufbar als: Unified diff
Debitorenbuchungen auf Verwendung des Chart-Pickers umgestellt