Revision 7e2bc8a0
Von Moritz Bunkus vor fast 8 Jahren hinzugefügt
bin/mozilla/ap.pl | ||
---|---|---|
33 | 33 |
#====================================================================== |
34 | 34 |
|
35 | 35 |
use POSIX qw(strftime); |
36 |
use List::Util qw(max sum); |
|
36 |
use List::Util qw(first max sum);
|
|
37 | 37 |
use List::UtilsBy qw(sort_by); |
38 | 38 |
|
39 | 39 |
use SL::AP; |
40 | 40 |
use SL::FU; |
41 | 41 |
use SL::GL; |
42 |
use SL::Helper::Flash qw(flash); |
|
42 | 43 |
use SL::IR; |
43 | 44 |
use SL::IS; |
44 | 45 |
use SL::ReportGenerator; |
45 | 46 |
use SL::DB::Currency; |
46 | 47 |
use SL::DB::Default; |
47 | 48 |
use SL::DB::PurchaseInvoice; |
49 |
use SL::DB::RecordTemplate; |
|
50 |
use SL::DB::Tax; |
|
48 | 51 |
use SL::Webdav; |
49 | 52 |
use SL::Locale::String qw(t8); |
50 | 53 |
|
... | ... | |
85 | 88 |
# $locale->text('Nov') |
86 | 89 |
# $locale->text('Dec') |
87 | 90 |
|
91 |
sub load_record_template { |
|
92 |
$::auth->assert('ap_transactions'); |
|
93 |
|
|
94 |
# Load existing template and verify that its one for this module. |
|
95 |
my $template = SL::DB::RecordTemplate |
|
96 |
->new(id => $::form->{id}) |
|
97 |
->load( |
|
98 |
with_object => [ qw(customer payment currency record_items record_items.chart) ], |
|
99 |
); |
|
100 |
|
|
101 |
die "invalid template type" unless $template->template_type eq 'ap_transaction'; |
|
102 |
|
|
103 |
$template->substitute_variables; |
|
104 |
|
|
105 |
# Clean the current $::form before rebuilding it from the template. |
|
106 |
delete @{ $::form }{ grep { !m{^(?:script|login)$}i } keys %{ $::form } }; |
|
107 |
|
|
108 |
# Fill $::form from the template. |
|
109 |
my $today = DateTime->today_local; |
|
110 |
$::form->{title} = "Add"; |
|
111 |
$::form->{currency} = $template->currency->name; |
|
112 |
$::form->{direct_debit} = $template->direct_debit; |
|
113 |
$::form->{globalproject_id} = $template->project_id; |
|
114 |
$::form->{AP_chart_id} = $template->ar_ap_chart_id; |
|
115 |
$::form->{transdate} = $today->to_kivitendo; |
|
116 |
$::form->{duedate} = $today->to_kivitendo; |
|
117 |
$::form->{rowcount} = @{ $template->items } + 1; |
|
118 |
$::form->{paidaccounts} = 1; |
|
119 |
$::form->{$_} = $template->$_ for qw(department_id ordnumber taxincluded notes); |
|
120 |
|
|
121 |
if ($template->vendor) { |
|
122 |
$::form->{vendor_id} = $template->vendor_id; |
|
123 |
$::form->{vendor} = $template->vendor->name; |
|
124 |
$::form->{duedate} = $template->vendor->payment->calc_date(reference_date => $today)->to_kivitendo if $template->vendor->payment; |
|
125 |
} |
|
126 |
|
|
127 |
my $row = 0; |
|
128 |
foreach my $item (@{ $template->items }) { |
|
129 |
$row++; |
|
130 |
|
|
131 |
my $active_taxkey = $item->chart->get_active_taxkey; |
|
132 |
my $taxes = SL::DB::Manager::Tax->get_all( |
|
133 |
where => [ chart_categories => { like => '%' . $item->chart->category . '%' }], |
|
134 |
sort_by => 'taxkey, rate', |
|
135 |
); |
|
136 |
|
|
137 |
my $tax = first { $item->tax_id == $_->id } @{ $taxes }; |
|
138 |
$tax //= first { $active_taxkey->tax_id == $_->id } @{ $taxes }; |
|
139 |
$tax //= $taxes->[0]; |
|
140 |
|
|
141 |
if (!$tax) { |
|
142 |
$row--; |
|
143 |
next; |
|
144 |
} |
|
145 |
|
|
146 |
$::form->{"AP_amount_chart_id_${row}"} = $item->chart_id; |
|
147 |
$::form->{"previous_AP_amount_chart_id_${row}"} = $item->chart_id; |
|
148 |
$::form->{"amount_${row}"} = $::form->format_amount(\%::myconfig, $item->amount1, 2); |
|
149 |
$::form->{"taxchart_${row}"} = $item->tax_id . '--' . $tax->rate; |
|
150 |
$::form->{"project_id_${row}"} = $item->project_id; |
|
151 |
} |
|
152 |
|
|
153 |
flash('info', $::locale->text("The record template '#1' has been loaded.", $template->template_name)); |
|
154 |
|
|
155 |
update(); |
|
156 |
} |
|
157 |
|
|
88 | 158 |
sub add { |
89 | 159 |
$main::lxdebug->enter_sub(); |
90 | 160 |
|
Auch abrufbar als: Unified diff
Belegvorlagen: Laden bei Kreditorenbuchungen