Revision ad635c66
Von Moritz Bunkus vor fast 8 Jahren hinzugefügt
bin/mozilla/gl.pl | ||
---|---|---|
140 | 140 |
$form->{"project_id_$j"} = $ref->{project_id}; |
141 | 141 |
|
142 | 142 |
} else { |
143 |
$form->{"accno_$i"} = "$ref->{accno}--$ref->{tax_id}";
|
|
143 |
$form->{"accno_id_$i"} = $ref->{chart_id};
|
|
144 | 144 |
for (qw(fx_transaction source memo)) { $form->{"${_}_$i"} = $ref->{$_} } |
145 | 145 |
if ($ref->{amount} < 0) { |
146 | 146 |
$form->{totaldebit} -= $ref->{amount}; |
... | ... | |
650 | 650 |
my %myconfig = %main::myconfig; |
651 | 651 |
my $cgi = $::request->{cgi}; |
652 | 652 |
|
653 |
my %balances = GL->get_chart_balances(map { $_->{id} } @{ $form->{ALL_CHARTS} }); |
|
654 |
|
|
653 | 655 |
$form->{debit_1} = 0 if !$form->{"debit_1"}; |
654 | 656 |
$form->{totaldebit} = 0; |
655 | 657 |
$form->{totalcredit} = 0; |
... | ... | |
661 | 663 |
$project_labels{$item->{"id"}} = $item->{"projectnumber"}; |
662 | 664 |
} |
663 | 665 |
|
664 |
my %chart_labels = (); |
|
665 |
my @chart_values = (); |
|
666 |
my %charts = (); |
|
667 |
my $taxchart_init; |
|
668 |
foreach my $item (@{ $form->{ALL_CHARTS} }) { |
|
669 |
if ($item->{charttype} eq 'H'){ # skip headings |
|
670 |
next; |
|
671 |
} |
|
672 |
my $key = $item->{accno} . "--" . $item->{tax_id}; |
|
673 |
$taxchart_init = $item->{tax_id} unless (@chart_values); |
|
674 |
push(@chart_values, $key); |
|
675 |
$chart_labels{$key} = $item->{accno} . "--" . $item->{description}; |
|
676 |
$charts{$item->{accno}} = $item; |
|
677 |
} |
|
666 |
my %charts_by_id = map { ($_->{id} => $_) } @{ $::form->{ALL_CHARTS} }; |
|
667 |
my $default_chart = $::form->{ALL_CHARTS}[0]; |
|
668 |
my $transdate = $::form->{transdate} ? DateTime->from_kivitendo($::form->{transdate}) : DateTime->today_local; |
|
678 | 669 |
|
679 | 670 |
my ($source, $memo, $source_hidden, $memo_hidden); |
680 | 671 |
for my $i (1 .. $form->{rowcount}) { |
... | ... | |
690 | 681 |
<input type="hidden" name="memo_$i" value="$form->{"memo_$i"}" size="16">|; |
691 | 682 |
} |
692 | 683 |
|
693 |
my $selected_accno_full; |
|
694 |
my ($accno_row) = split(/--/, $form->{"accno_$i"}); |
|
695 |
my $item = $charts{$accno_row}; |
|
696 |
$selected_accno_full = "$item->{accno}--$item->{tax_id}"; |
|
697 |
|
|
698 |
my $selected_taxchart = $form->{"taxchart_$i"}; |
|
699 |
my ($selected_accno, $selected_tax_id) = split(/--/, $selected_accno_full); |
|
700 |
my ($previous_accno, $previous_tax_id) = split(/--/, $form->{"previous_accno_$i"}); |
|
701 |
|
|
702 | 684 |
my %taxchart_labels = (); |
703 | 685 |
my @taxchart_values = (); |
704 |
my %taxcharts = (); |
|
705 |
my $filter_accno; |
|
706 |
$filter_accno = $::form->{ALL_CHARTS}[0]->{accno}; |
|
707 |
$filter_accno = $selected_accno if (!$init and $i < $form->{rowcount}); |
|
708 |
foreach my $item ( GL->get_tax_dropdown($filter_accno) ) { |
|
709 |
my $key = $item->{id} . "--" . $item->{rate}; |
|
710 |
$taxchart_init = $key if ($taxchart_init == $item->{id}); |
|
711 |
push(@taxchart_values, $key); |
|
712 |
$taxchart_labels{$key} = $item->{taxdescription} . " " . $item->{rate} * 100 . ' %'; |
|
713 |
$taxcharts{$item->{id}} = $item; |
|
714 |
} |
|
715 | 686 |
|
716 |
if ($previous_accno && |
|
717 |
($previous_accno eq $selected_accno) && |
|
718 |
($previous_tax_id ne $selected_tax_id)) { |
|
719 |
my $item = $taxcharts{$selected_tax_id}; |
|
720 |
$selected_taxchart = "$item->{id}--$item->{rate}"; |
|
687 |
my $accno_id = $::form->{"accno_id_$i"}; |
|
688 |
my $chart = $charts_by_id{$accno_id} // $default_chart; |
|
689 |
$accno_id = $chart->{id}; |
|
690 |
my $chart_has_changed = $::form->{"previous_accno_id_$i"} && ($accno_id != $::form->{"previous_accno_id_$i"}); |
|
691 |
my ($first_taxchart, $default_taxchart, $taxchart_to_use); |
|
692 |
|
|
693 |
foreach my $item ( GL->get_active_taxes_for_chart($accno_id, $transdate) ) { |
|
694 |
my $key = $item->id . "--" . $item->rate; |
|
695 |
$first_taxchart //= $item; |
|
696 |
$default_taxchart = $item if $item->{is_default}; |
|
697 |
$taxchart_to_use = $item if $key eq $form->{"taxchart_$i"}; |
|
698 |
|
|
699 |
push(@taxchart_values, $key); |
|
700 |
$taxchart_labels{$key} = $item->taxdescription . " " . $item->rate * 100 . ' %'; |
|
721 | 701 |
} |
722 | 702 |
|
723 |
$selected_accno = '' if ($init);
|
|
724 |
$selected_taxchart ||= $taxchart_init;
|
|
703 |
$taxchart_to_use = $default_taxchart // $first_taxchart if $chart_has_changed || !$taxchart_to_use;
|
|
704 |
my $selected_taxchart = $taxchart_to_use->id . '--' . $taxchart_to_use->rate;
|
|
725 | 705 |
|
726 | 706 |
my $accno = qq|<td>| . |
727 |
NTI($cgi->popup_menu('-name' => "accno_$i", |
|
728 |
'-id' => "accno_$i", |
|
729 |
'-onChange' => "updateTaxes($i);", |
|
730 |
'-style' => 'width:200px', |
|
731 |
'-values' => \@chart_values, |
|
732 |
'-labels' => \%chart_labels, |
|
733 |
'-default' => $selected_accno_full)) |
|
734 |
. $cgi->hidden('-name' => "previous_accno_$i", |
|
735 |
'-default' => $selected_accno_full) |
|
707 |
$::request->presenter->chart_picker("accno_id_$i", $accno_id, style => "width: 300px") . |
|
708 |
$::request->presenter->hidden_tag("previous_accno_id_$i", $accno_id) |
|
736 | 709 |
. qq|</td>|; |
737 | 710 |
my $tax_ddbox = qq|<td>| . |
738 | 711 |
NTI($cgi->popup_menu('-name' => "taxchart_$i", |
... | ... | |
808 | 781 |
<input type="hidden" name="project_id_$i" value="$form->{"project_id_$i"}">|; |
809 | 782 |
|
810 | 783 |
my $copy2credit = $i == 1 ? 'onkeyup="copy_debit_to_credit()"' : ''; |
784 |
my $balance = $form->format_amount(\%::myconfig, $balances{$accno_id} // 0, 2, 'DRCR'); |
|
811 | 785 |
|
812 | 786 |
print qq|<tr valign=top> |
813 | 787 |
$accno |
814 |
<td id="chart_balance_$i" align="right"> </td>
|
|
788 |
<td id="chart_balance_$i" align="right">${balance}</td>
|
|
815 | 789 |
$fx_transaction |
816 | 790 |
<td><input name="debit_$i" size="8" value="$form->{"debit_$i"}" accesskey=$i $copy2credit $debitreadonly></td> |
817 | 791 |
<td><input name="credit_$i" size=8 value="$form->{"credit_$i"}" $creditreadonly></td> |
... | ... | |
852 | 826 |
|
853 | 827 |
my ($init) = @_; |
854 | 828 |
|
829 |
$::request->layout->add_javascripts("autocomplete_chart.js", "kivi.GL.js"); |
|
830 |
|
|
855 | 831 |
my @old_project_ids = grep { $_ } map{ $::form->{"project_id_$_"} } 1..$::form->{rowcount}; |
856 | 832 |
|
857 | 833 |
$::form->get_lists("projects" => { "key" => "ALL_PROJECTS", |
... | ... | |
863 | 839 |
|
864 | 840 |
$::form->{ALL_DEPARTMENTS} = SL::DB::Manager::Department->get_all; |
865 | 841 |
|
866 |
GL->get_chart_balances('charts' => $::form->{ALL_CHARTS}); |
|
867 |
|
|
868 | 842 |
my $title = $::form->{title}; |
869 | 843 |
$::form->{title} = $::locale->text("$title General Ledger Transaction"); |
870 | 844 |
# $locale->text('Add General Ledger Transaction') |
... | ... | |
877 | 851 |
$::request->{layout}->focus("#reference"); |
878 | 852 |
$::form->{taxincluded} = "1"; |
879 | 853 |
} else { |
880 |
$::request->{layout}->focus("#accno_$::form->{rowcount}");
|
|
854 |
$::request->{layout}->focus("#accno_id_$::form->{rowcount}_name");
|
|
881 | 855 |
} |
882 | 856 |
|
883 | 857 |
$::form->{previous_id} ||= "--"; |
... | ... | |
1222 | 1196 |
} |
1223 | 1197 |
|
1224 | 1198 |
sub get_tax_dropdown { |
1225 |
$main::lxdebug->enter_sub(); |
|
1199 |
my $transdate = $::form->{transdate} ? DateTime->from_kivitendo($::form->{transdate}) : DateTime->today_local; |
|
1200 |
my @tax_accounts = GL->get_active_taxes_for_chart($::form->{accno_id}, $transdate); |
|
1201 |
my $html = $::form->parse_html_template("gl/update_tax_accounts", { TAX_ACCOUNTS => \@tax_accounts }); |
|
1226 | 1202 |
|
1227 |
my $form = $main::form; |
|
1228 |
my @tax_accounts = GL->get_tax_dropdown($form->{accno}); |
|
1229 |
|
|
1230 |
foreach my $item (@tax_accounts) { |
|
1231 |
$item->{taxdescription} = $::locale->{iconv_utf8}->convert($item->{taxdescription}); |
|
1232 |
$item->{taxdescription} .= ' ' . $form->round_amount($item->{rate} * 100); |
|
1233 |
} |
|
1234 |
|
|
1235 |
$form->{TAX_ACCOUNTS} = [ @tax_accounts ]; |
|
1236 |
|
|
1237 |
print $form->ajax_response_header, $form->parse_html_template("gl/update_tax_accounts"); |
|
1203 |
print $::form->ajax_response_header, $html; |
|
1204 |
} |
|
1238 | 1205 |
|
1239 |
$main::lxdebug->leave_sub(); |
|
1206 |
sub get_chart_balance { |
|
1207 |
my %balances = GL->get_chart_balances($::form->{accno_id}); |
|
1208 |
my $balance = $::form->format_amount(\%::myconfig, $balances{ $::form->{accno_id} }, 2, 'DRCR'); |
|
1240 | 1209 |
|
1210 |
print $::form->ajax_response_header, $balance; |
|
1241 | 1211 |
} |
1242 | 1212 |
|
1243 | 1213 |
1; |
Auch abrufbar als: Unified diff
Dialogbuchen auf Verwendung des Chart-Pickers umgestellt