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