1df77fd8982f92efe895762bb48dae3b68ad7c2b
[kivitendo-erp.git] / SL / DB / ShopPart.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::ShopPart;
5
6 use strict;
7
8 use SL::DBUtils;
9 use SL::DB::MetaSetup::ShopPart;
10 use SL::DB::Manager::ShopPart;
11 use SL::DB::Helper::AttrHTML;
12 #use SL::DB::Helper::ActsAsList;
13
14 __PACKAGE__->meta->initialize;
15 __PACKAGE__->attr_html('shop_description');
16
17 sub get_tax_and_price {
18   my ( $self ) = @_;
19
20   require SL::DB::Part;
21   my $tax_n_price;
22   my ( $price_src_str, $price_src_id ) = split(/\//,$self->active_price_source);
23   my $price;
24   my $part;
25   if ($price_src_str eq "master_data") {
26     $part = SL::DB::Manager::Part->find_by( id => $self->part_id );
27     $price = $part->$price_src_id;
28   }else{
29     $part = SL::DB::Manager::Part->find_by( id => $self->part_id );
30     $price =  $part->prices->[0]->price;
31   }
32
33   my $taxrate;
34   my $dbh  = $::form->get_standard_dbh();
35   my $b_id = $part->buchungsgruppen_id;
36   my $t_id = $self->shop->taxzone_id;
37
38   my $sql_str = "SELECT a.rate AS taxrate from tax a
39   WHERE a.taxkey = (SELECT b.taxkey_id
40   FROM chart b LEFT JOIN taxzone_charts c ON b.id = c.income_accno_id
41   WHERE c.taxzone_id = $t_id
42   AND c.buchungsgruppen_id = $b_id)";
43
44   my $rate = selectall_hashref_query($::form, $dbh, $sql_str);
45   $taxrate = @$rate[0]->{taxrate}*100;
46
47   $tax_n_price->{price} = $price;
48   $tax_n_price->{tax}   = $taxrate;
49   return $tax_n_price;
50 }
51
52 sub get_images {
53   my ( $self ) = @_;
54
55   require SL::DB::ShopImage;
56   my $images = SL::DB::Manager::ShopImage->get_all( where => [ 'files.object_id' => $self->{part_id}, ], with_objects => 'file', sort_by => 'position' );
57   my @upload_img = ();
58   foreach my $img (@{ $images }) {
59     my $file               = SL::File->get(id => $img->file->id );
60     my ($path, $extension) = (split /\./, $file->file_name);
61     my $content            = File::Slurp::read_file($file->get_file);
62     my $temp ={ ( link        => 'data:' . $file->mime_type . ';base64,' . MIME::Base64::encode($content, ""), #$content, # MIME::Base64::encode($content),
63                   description => $img->file->title,
64                   position    => $img->position,
65                   extension   => $extension,
66                   path        => $path,
67                       )}    ;
68     push( @upload_img, $temp);
69   }
70   return @upload_img;
71 }
72
73 1;
74
75 __END__
76
77 =pod
78
79 =encoding utf-8
80
81 =head1 NAME
82
83 SL::DB::ShopPart - Model for the 'shop_parts' table
84
85 =head1 SYNOPSIS
86
87 This is a standard Rose::DB::Object based model and can be used as one.
88
89 =head1 METHODS
90
91 =over 4
92
93 =item C<get_tax_and_price>
94
95 Returns the price and the taxrate for an shop_article
96
97 =item C<get_images>
98
99 Returns the images for the shop_article
100
101 =back
102
103 =head1 TODO
104
105 Prices, pricesources, pricerules could be implemented
106
107 =head1 AUTHORS
108
109 Werner Hahn E<lt>wh@futureworldsearch.netE<gt>
110
111 =cut