Merge branch 'b-3.6.1' of ../kivitendo-erp_20220811
[kivitendo-erp.git] / SL / DB / AssortmentItem.pm
1 # This file has been auto-generated only because it didn't exist.
2 # Feel free to modify it at will; it will not be overwritten automatically.
3
4 package SL::DB::AssortmentItem;
5
6 use strict;
7
8 use SL::DB::MetaSetup::AssortmentItem;
9 use SL::DB::Manager::AssortmentItem;
10 use Rose::DB::Object::Helpers qw(clone);
11
12 __PACKAGE__->meta->initialize;
13
14 sub linetotal_sellprice {
15   my ($self, %params) = @_;
16
17   my $sellprice = $self->part->sellprice;
18   if ($params{pricegroup}) {
19     my $pricegroup = SL::DB::Manager::Pricegroup->find_by( pricegroup => $params{pricegroup});
20     die "Can't find pricegroup with name " . $params{pricegroup} unless $pricegroup;
21     $params{pricegroup_id} = $pricegroup->id if $pricegroup;
22   }
23   if ($params{pricegroup_id}) {
24     my $price = SL::DB::Manager::Price->find_by(pricegroup_id => $params{pricegroup_id}, parts_id => $self->part->id);
25     $sellprice = $price->price if $price;
26   }
27
28   return 0 unless $self->qty > 0 and $sellprice > 0;
29   return $self->qty * $sellprice / ( $self->part->price_factor_id ? $self->part->price_factor->factor : 1 );
30 }
31
32 sub linetotal_lastcost {
33   my ($self) = @_;
34
35   return 0 unless $self->qty > 0 and $self->part->lastcost > 0;
36   return $self->qty * $self->part->lastcost / ( $self->part->price_factor_id ? $self->part->price_factor->factor : 1 );
37 }
38
39 1;