Revision b1267126
Von Kivitendo Admin vor mehr als 8 Jahren hinzugefügt
SL/DB/PurchaseInvoice.pm | ||
---|---|---|
115 | 115 |
join ' ', grep $_, map $_[0]->$_, qw(displayable_type record_number); |
116 | 116 |
}; |
117 | 117 |
|
118 |
sub create_ap_row { |
|
119 |
my ($self, %params) = @_; |
|
120 |
# needs chart as param |
|
121 |
# to be called after adding all AP_amount rows |
|
122 |
|
|
123 |
# only allow this method for ap invoices (Kreditorenbuchung) |
|
124 |
die if $self->invoice and not $self->vendor_id; |
|
125 |
|
|
126 |
my $acc_trans = []; |
|
127 |
my $chart = $params{chart} || SL::DB::Manager::Chart->find_by(id => $::instance_conf->get_ap_chart_id); |
|
128 |
die "illegal chart in create_ap_row" unless $chart; |
|
129 |
|
|
130 |
die "receivables chart must have link 'AP'" . Dumper($chart) unless $chart->link eq 'AP'; |
|
131 |
|
|
132 |
# hardcoded entry for no tax, tax_id and taxkey should be 0 |
|
133 |
my $tax = SL::DB::Manager::Tax->find_by(id => 0, taxkey => 0) || die "Can't find tax with id 0 and taxkey 0"; |
|
134 |
|
|
135 |
my $sign = $self->vendor_id ? 1 : -1; |
|
136 |
my $acc = SL::DB::AccTransaction->new( |
|
137 |
amount => $self->amount * $sign, |
|
138 |
chart_id => $params{chart}->id, |
|
139 |
chart_link => $params{chart}->link, |
|
140 |
transdate => $self->transdate, |
|
141 |
taxkey => $tax->taxkey, |
|
142 |
tax_id => $tax->id, |
|
143 |
); |
|
144 |
$self->add_transactions( $acc ); |
|
145 |
push( @$acc_trans, $acc ); |
|
146 |
return $acc_trans; |
|
147 |
}; |
|
148 |
|
|
149 |
sub add_ap_amount_row { |
|
150 |
my ($self, %params ) = @_; |
|
151 |
|
|
152 |
# only allow this method for ap invoices (Kreditorenbuchung) |
|
153 |
die "not an ap invoice" if $self->invoice and not $self->vendor_id; |
|
154 |
|
|
155 |
die "add_ap_amount_row needs a chart object as chart param" unless $params{chart} && $params{chart}->isa('SL::DB::Chart'); |
|
156 |
die unless $params{chart}->link =~ /AP_amount/; |
|
157 |
|
|
158 |
my $acc_trans = []; |
|
159 |
|
|
160 |
my $roundplaces = 2; |
|
161 |
my ($netamount,$taxamount); |
|
162 |
|
|
163 |
$netamount = $params{amount} * 1; |
|
164 |
my $tax = SL::DB::Manager::Tax->find_by(id => $params{tax_id}) || die "Can't find tax with id " . $params{tax_id}; |
|
165 |
|
|
166 |
if ( $tax and $tax->rate != 0 ) { |
|
167 |
($netamount, $taxamount) = Form->calculate_tax($params{amount}, $tax->rate, $self->taxincluded, $roundplaces); |
|
168 |
}; |
|
169 |
next unless $netamount; # netamount mustn't be zero |
|
170 |
|
|
171 |
my $sign = $self->vendor_id ? -1 : 1; |
|
172 |
my $acc = SL::DB::AccTransaction->new( |
|
173 |
amount => $netamount * $sign, |
|
174 |
chart_id => $params{chart}->id, |
|
175 |
chart_link => $params{chart}->link, |
|
176 |
transdate => $self->transdate, |
|
177 |
taxkey => $tax->taxkey, |
|
178 |
tax_id => $tax->id, |
|
179 |
project_id => $params{project_id}, |
|
180 |
); |
|
181 |
|
|
182 |
$self->add_transactions( $acc ); |
|
183 |
push( @$acc_trans, $acc ); |
|
184 |
|
|
185 |
if ( $taxamount ) { |
|
186 |
my $acc = SL::DB::AccTransaction->new( |
|
187 |
amount => $taxamount * $sign, |
|
188 |
chart_id => $tax->chart_id, |
|
189 |
chart_link => $tax->chart->link, |
|
190 |
transdate => $self->transdate, |
|
191 |
taxkey => $tax->taxkey, |
|
192 |
tax_id => $tax->id, |
|
193 |
project_id => $params{project_id}, |
|
194 |
); |
|
195 |
$self->add_transactions( $acc ); |
|
196 |
push( @$acc_trans, $acc ); |
|
197 |
}; |
|
198 |
return $acc_trans; |
|
199 |
}; |
|
200 |
|
|
118 | 201 |
1; |
Auch abrufbar als: Unified diff
PurchaseInvoice - create_ap_row und add_ap_amount_row
Für Erstellung von Kreditorenbuchungen, analog zu create_ar_row und
add_ar_amount in SL::DB::Invoice.