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.
 
   4 package SL::DB::AssortmentItem;
 
   8 use SL::DB::MetaSetup::AssortmentItem;
 
   9 use SL::DB::Manager::AssortmentItem;
 
  10 use Rose::DB::Object::Helpers qw(clone);
 
  12 __PACKAGE__->meta->initialize;
 
  14 sub linetotal_sellprice {
 
  15   my ($self, %params) = @_;
 
  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;
 
  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;
 
  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 );
 
  32 sub linetotal_lastcost {
 
  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 );