"alle" E-Mail-Adressen per Anhaken als Empfänger hinzufügen können
[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, %params) = @_;
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     # no good: split("\." , 202.220.pdf) -> invaild extension 220
61     # file->extension should be in SL::File, a valid extension may also be 'tar.gz'
62     my ($path, $extension) = split(/\.([^\.]+)$/, $file->file_name);
63     my $content            = File::Slurp::read_file($file->get_file);
64
65     my $temp ={ (
66                   link        => $params{want_binary} ? $content : 'data:' . $file->mime_type . ';base64,' . MIME::Base64::encode($content, ""),
67                   description => $img->file->title,
68                   position    => $img->position,
69                   extension   => $extension,
70                   path        => $path,
71                       )}    ;
72     push( @upload_img, $temp);
73   }
74   return @upload_img;
75 }
76
77 1;
78
79 __END__
80
81 =pod
82
83 =encoding utf-8
84
85 =head1 NAME
86
87 SL::DB::ShopPart - Model for the 'shop_parts' table
88
89 =head1 SYNOPSIS
90
91 This is a standard Rose::DB::Object based model and can be used as one.
92
93 =head1 METHODS
94
95 =over 4
96
97 =item C<get_tax_and_price>
98
99 Returns the price and the taxrate for an shop_article
100
101 =item C<get_images>
102
103 Returns the images for the shop_article
104
105 =back
106
107 =head1 TODO
108
109 Prices, pricesources, pricerules could be implemented
110
111 =head1 AUTHORS
112
113 Werner Hahn E<lt>wh@futureworldsearch.netE<gt>
114
115 =cut