Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision b2bedb6b

Von Werner Hahn vor mehr als 7 Jahren hinzugefügt

  • ID b2bedb6b5eff41a17ddb194df1c75213b841f3bb
  • Vorgänger 397e706b
  • Nachfolger d3ae6850

WebshopApi: Shoptabellen

Unterschiede anzeigen:

SL/DB/Helper/ALL.pm
115 115
use SL::DB::SepaExportItem;
116 116
use SL::DB::SepaExportMessageId;
117 117
use SL::DB::Shipto;
118
use SL::DB::Shop;
119
use SL::DB::ShopOrder;
120
use SL::DB::ShopOrderItem;
121
use SL::DB::ShopPart;
118 122
use SL::DB::Status;
119 123
use SL::DB::Tax;
120 124
use SL::DB::TaxKey;
SL/DB/Helper/Mappings.pm
195 195
  sepa_export_message_ids        => 'SepaExportMessageId',
196 196
  schema_info                    => 'schema_info',
197 197
  shipto                         => 'shipto',
198
  shops                          => 'shop',
199
  shop_orders                    => 'shop_order',
200
  shop_order_items               => 'shop_order_item',
201
  shop_parts                     => 'shop_part',
198 202
  status                         => 'status',
199 203
  tax                            => 'tax',
200 204
  taxkeys                        => 'tax_key',
SL/DB/Manager/Shop.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::Manager::Shop;
5

  
6
use strict;
7

  
8
use SL::DB::Helper::Manager;
9
use base qw(SL::DB::Helper::Manager);
10

  
11
sub object_class { 'SL::DB::Shop' }
12

  
13
use SL::DB::Helper::Sorted;
14

  
15
__PACKAGE__->make_manager_methods;
16

  
17
sub _sort_spec {
18
  return ( default => [ 'sortkey', 1 ],
19
           columns => { SIMPLE => 'ALL' } );
20
}
21

  
22
sub get_default {
23
    return $_[0]->get_first(where => [ obsolete => 0 ], sort_by => 'sortkey');
24
}
25

  
26
1;
27

  
28
1;
SL/DB/Manager/ShopOrder.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::Manager::ShopOrder;
5

  
6
use strict;
7

  
8
use SL::DB::Helper::Manager;
9
use base qw(SL::DB::Helper::Manager);
10

  
11
sub object_class { 'SL::DB::ShopOrder' }
12

  
13
__PACKAGE__->make_manager_methods;
14

  
15
1;
SL/DB/Manager/ShopOrderItem.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::Manager::ShopOrderItem;
5

  
6
use strict;
7

  
8
use SL::DB::Helper::Manager;
9
use base qw(SL::DB::Helper::Manager);
10

  
11
sub object_class { 'SL::DB::ShopOrderItem' }
12

  
13
__PACKAGE__->make_manager_methods;
14

  
15
1;
SL/DB/Manager/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::Manager::ShopPart;
5
#package SL::DB::Manager::ShopPart;
6

  
7
use strict;
8

  
9
use SL::DB::Helper::Manager;
10
use base qw(SL::DB::Helper::Manager);
11

  
12
sub object_class { 'SL::DB::ShopPart' }
13

  
14
__PACKAGE__->make_manager_methods;
15

  
16
1;
SL/DB/MetaSetup/Shop.pm
1
# This file has been auto-generated. Do not modify it; it will be overwritten
2
# by rose_auto_create_model.pl automatically.
3
package SL::DB::Shop;
4

  
5
use strict;
6

  
7
use parent qw(SL::DB::Object);
8

  
9
__PACKAGE__->meta->table('shops');
10

  
11
__PACKAGE__->meta->columns(
12
  connector               => { type => 'text' },
13
  description             => { type => 'text' },
14
  id                      => { type => 'serial', not_null => 1 },
15
  itime                   => { type => 'timestamp', default => 'now()' },
16
  last_order_number       => { type => 'integer' },
17
  login                   => { type => 'text' },
18
  mtime                   => { type => 'timestamp', default => 'now()' },
19
  obsolete                => { type => 'boolean', default => 'false', not_null => 1 },
20
  orders_to_fetch         => { type => 'integer' },
21
  password                => { type => 'text' },
22
  path                    => { type => 'text', default => '/', not_null => 1 },
23
  port                    => { type => 'integer' },
24
  price_source            => { type => 'text' },
25
  pricetype               => { type => 'text' },
26
  protocol                => { type => 'text', default => 'http', not_null => 1 },
27
  realm                   => { type => 'text' },
28
  server                  => { type => 'text' },
29
  sortkey                 => { type => 'integer' },
30
  taxzone_id              => { type => 'integer' },
31
  transaction_description => { type => 'text' },
32
);
33

  
34
__PACKAGE__->meta->primary_key_columns([ 'id' ]);
35

  
36
__PACKAGE__->meta->allow_inline_column_values(1);
37

  
38
1;
39
;
SL/DB/MetaSetup/ShopOrder.pm
1
# This file has been auto-generated. Do not modify it; it will be overwritten
2
# by rose_auto_create_model.pl automatically.
3
package SL::DB::ShopOrder;
4

  
5
use strict;
6

  
7
use parent qw(SL::DB::Object);
8

  
9
__PACKAGE__->meta->table('shop_orders');
10

  
11
__PACKAGE__->meta->columns(
12
  amount                 => { type => 'numeric', precision => 15, scale => 5 },
13
  billing_city           => { type => 'text' },
14
  billing_company        => { type => 'text' },
15
  billing_country        => { type => 'text' },
16
  billing_department     => { type => 'text' },
17
  billing_email          => { type => 'text' },
18
  billing_fax            => { type => 'text' },
19
  billing_firstname      => { type => 'text' },
20
  billing_greeting       => { type => 'text' },
21
  billing_lastname       => { type => 'text' },
22
  billing_phone          => { type => 'text' },
23
  billing_street         => { type => 'text' },
24
  billing_vat            => { type => 'text' },
25
  billing_zipcode        => { type => 'text' },
26
  customer_city          => { type => 'text' },
27
  customer_company       => { type => 'text' },
28
  customer_country       => { type => 'text' },
29
  customer_department    => { type => 'text' },
30
  customer_email         => { type => 'text' },
31
  customer_fax           => { type => 'text' },
32
  customer_firstname     => { type => 'text' },
33
  customer_greeting      => { type => 'text' },
34
  customer_lastname      => { type => 'text' },
35
  customer_newsletter    => { type => 'boolean' },
36
  customer_phone         => { type => 'text' },
37
  customer_street        => { type => 'text' },
38
  customer_vat           => { type => 'text' },
39
  customer_zipcode       => { type => 'text' },
40
  delivery_city          => { type => 'text' },
41
  delivery_company       => { type => 'text' },
42
  delivery_country       => { type => 'text' },
43
  delivery_department    => { type => 'text' },
44
  delivery_email         => { type => 'text' },
45
  delivery_fax           => { type => 'text' },
46
  delivery_firstname     => { type => 'text' },
47
  delivery_greeting      => { type => 'text' },
48
  delivery_lastname      => { type => 'text' },
49
  delivery_phone         => { type => 'text' },
50
  delivery_street        => { type => 'text' },
51
  delivery_vat           => { type => 'text' },
52
  delivery_zipcode       => { type => 'text' },
53
  host                   => { type => 'text' },
54
  id                     => { type => 'serial', not_null => 1 },
55
  itime                  => { type => 'timestamp', default => 'now()' },
56
  kivi_customer_id       => { type => 'integer' },
57
  mtime                  => { type => 'timestamp' },
58
  netamount              => { type => 'numeric', precision => 15, scale => 5 },
59
  obsolete               => { type => 'boolean', default => 'false', not_null => 1 },
60
  order_date             => { type => 'timestamp' },
61
  payment_description    => { type => 'text' },
62
  payment_id             => { type => 'integer' },
63
  positions              => { type => 'integer' },
64
  remote_ip              => { type => 'text' },
65
  sepa_account_holder    => { type => 'text' },
66
  sepa_bic               => { type => 'text' },
67
  sepa_iban              => { type => 'text' },
68
  shipping_costs         => { type => 'numeric', precision => 15, scale => 5 },
69
  shipping_costs_id      => { type => 'integer' },
70
  shipping_costs_net     => { type => 'numeric', precision => 15, scale => 5 },
71
  shop_c_billing_id      => { type => 'integer' },
72
  shop_c_billing_number  => { type => 'text' },
73
  shop_c_delivery_id     => { type => 'integer' },
74
  shop_c_delivery_number => { type => 'text' },
75
  shop_customer_comment  => { type => 'text' },
76
  shop_customer_id       => { type => 'integer' },
77
  shop_customer_number   => { type => 'text' },
78
  shop_id                => { type => 'integer' },
79
  shop_ordernumber       => { type => 'text' },
80
  shop_trans_id          => { type => 'integer', not_null => 1 },
81
  tax_included           => { type => 'boolean' },
82
  transfer_date          => { type => 'date' },
83
  transferred            => { type => 'boolean', default => 'false' },
84
);
85

  
86
__PACKAGE__->meta->primary_key_columns([ 'id' ]);
87

  
88
__PACKAGE__->meta->allow_inline_column_values(1);
89

  
90
__PACKAGE__->meta->foreign_keys(
91
  kivi_customer => {
92
    class       => 'SL::DB::Customer',
93
    key_columns => { kivi_customer_id => 'id' },
94
  },
95

  
96
  shop => {
97
    class       => 'SL::DB::Shop',
98
    key_columns => { shop_id => 'id' },
99
  },
100
);
101

  
102
1;
103
;
SL/DB/MetaSetup/ShopOrderItem.pm
1
# This file has been auto-generated. Do not modify it; it will be overwritten
2
# by rose_auto_create_model.pl automatically.
3
package SL::DB::ShopOrderItem;
4

  
5
use strict;
6

  
7
use parent qw(SL::DB::Object);
8

  
9
__PACKAGE__->meta->table('shop_order_items');
10

  
11
__PACKAGE__->meta->columns(
12
  active_price_source => { type => 'text' },
13
  description         => { type => 'text' },
14
  id                  => { type => 'serial', not_null => 1 },
15
  partnumber          => { type => 'text' },
16
  position            => { type => 'integer' },
17
  price               => { type => 'numeric', precision => 15, scale => 5 },
18
  quantity            => { type => 'numeric', precision => 25, scale => 5 },
19
  shop_order_id       => { type => 'integer' },
20
  shop_trans_id       => { type => 'integer', not_null => 1 },
21
  tax_rate            => { type => 'numeric', precision => 15, scale => 2 },
22
);
23

  
24
__PACKAGE__->meta->primary_key_columns([ 'id' ]);
25

  
26
__PACKAGE__->meta->foreign_keys(
27
  shop_order => {
28
    class       => 'SL::DB::ShopOrder',
29
    key_columns => { shop_order_id => 'id' },
30
  },
31
);
32

  
33
1;
34
;
SL/DB/MetaSetup/ShopPart.pm
1
# This file has been auto-generated. Do not modify it; it will be overwritten
2
# by rose_auto_create_model.pl automatically.
3
package SL::DB::ShopPart;
4

  
5
use strict;
6

  
7
use parent qw(SL::DB::Object);
8

  
9
__PACKAGE__->meta->table('shop_parts');
10

  
11
__PACKAGE__->meta->columns(
12
  active              => { type => 'boolean', default => 'false', not_null => 1 },
13
  active_price_source => { type => 'text' },
14
  front_page          => { type => 'boolean', default => 'false', not_null => 1 },
15
  id                  => { type => 'serial', not_null => 1 },
16
  itime               => { type => 'timestamp', default => 'now()' },
17
  last_update         => { type => 'timestamp' },
18
  metatag_description => { type => 'text' },
19
  metatag_keywords    => { type => 'text' },
20
  metatag_title       => { type => 'text' },
21
  mtime               => { type => 'timestamp' },
22
  part_id             => { type => 'integer', not_null => 1 },
23
  shop_category       => { type => 'array' },
24
  shop_description    => { type => 'text' },
25
  shop_id             => { type => 'integer', not_null => 1 },
26
  show_date           => { type => 'date' },
27
  sortorder           => { type => 'integer' },
28
);
29

  
30
__PACKAGE__->meta->primary_key_columns([ 'id' ]);
31

  
32
__PACKAGE__->meta->unique_keys([ 'shop_id', 'part_id' ]);
33

  
34
__PACKAGE__->meta->allow_inline_column_values(1);
35

  
36
__PACKAGE__->meta->foreign_keys(
37
  part => {
38
    class       => 'SL::DB::Part',
39
    key_columns => { part_id => 'id' },
40
  },
41

  
42
  shop => {
43
    class       => 'SL::DB::Shop',
44
    key_columns => { shop_id => 'id' },
45
  },
46
);
47

  
48
1;
49
;
SL/DB/Part.pm
54 54
    query_args      => [ what_done => 'part' ],
55 55
    manager_args    => { sort_by => 'itime' },
56 56
  },
57
  shop_parts     => {
58
    type         => 'one to many',
59
    class        => 'SL::DB::ShopPart',
60
    column_map   => { id => 'part_id' },
61
    manager_args => { with_objects => [ 'shop' ] },
62
  },
57 63
);
58 64

  
59 65
__PACKAGE__->meta->initialize;
SL/DB/Shop.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::Shop;
5

  
6
use strict;
7

  
8
use SL::DB::MetaSetup::Shop;
9
use SL::DB::Manager::Shop;
10
use SL::DB::Helper::ActsAsList;
11
use SL::Locale::String qw(t8);
12

  
13
__PACKAGE__->meta->initialize;
14

  
15
sub validate {
16
  my ($self) = @_;
17

  
18
  my @errors;
19

  
20
  push @errors, $::locale->text('The description is missing.') unless $self->{description};
21
  push @errors, $::locale->text('The path is missing.') unless $self->{path};
22

  
23
  return @errors;
24
}
25

  
26
sub shops_dd {
27
  my ( $self ) = @_;
28

  
29
  my @shops_dd = ( { title => t8("all") ,   value =>'' } );
30
  my $shops = SL::DB::Manager::Shop->get_all( where => [ obsolete => 0 ] );
31
  my @tmp = map { { title => $_->{description}, value => $_->{id} } } @{ $shops } ;
32
  push @shops_dd, @tmp;
33
  return \@shops_dd;
34
}
35

  
36
1;
37

  
38
__END__
39

  
40
=pod
41

  
42
=encoding utf-8
43

  
44
=head1 NAME
45

  
46
SL::DB::Shop - Model for the 'shops' table
47

  
48
=head1 SYNOPSIS
49

  
50
This is a standard Rose::DB::Object based model and can be used as one.
51

  
52
=head1 METHODS
53

  
54
=over 4
55

  
56
=item C<validate>
57

  
58
Returns an error if the shop description is missing
59

  
60
=item C<shops_dd>
61

  
62
Returns an array of hashes for dropdowns in filters
63

  
64
=back
65

  
66
=head1 AUTHORS
67

  
68
Werner Hahn E<lt>wh@futureworldsearch.netE<gt>
69

  
70
G. Richardson E<lt>grichardson@kivitendo-premium.deE<gt>
71

  
72
=cut
SL/DB/ShopOrder.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::ShopOrder;
5

  
6
use strict;
7

  
8
use SL::DBUtils;
9
use SL::DB::Shop;
10
use SL::DB::MetaSetup::ShopOrder;
11
use SL::DB::Manager::ShopOrder;
12
use SL::DB::Helper::LinkedRecords;
13
use SL::Locale::String qw(t8);
14
use Carp;
15

  
16
__PACKAGE__->meta->add_relationships(
17
  shop_order_items => {
18
    class      => 'SL::DB::ShopOrderItem',
19
    column_map => { id => 'shop_order_id' },
20
    type       => 'one to many',
21
  },
22
);
23

  
24
__PACKAGE__->meta->initialize;
25

  
26
sub convert_to_sales_order {
27
  my ($self, %params) = @_;
28

  
29
  my $customer = delete $params{customer};
30
  my $employee = delete $params{employee};
31
  croak "param customer is missing" unless ref($customer) eq 'SL::DB::Customer';
32
  croak "param employee is missing" unless ref($employee) eq 'SL::DB::Employee';
33

  
34
  require SL::DB::Order;
35
  require SL::DB::OrderItem;
36
  require SL::DB::Part;
37
  require SL::DB::Shipto;
38
  my @error_report;
39

  
40
  my @items = map{
41

  
42
    my $part = SL::DB::Manager::Part->find_by(partnumber => $_->partnumber);
43

  
44
    unless($part){
45
      push @error_report, t8('Part with partnumber: #1 not found', $_->partnumber);
46
    }else{
47
      my $current_order_item = SL::DB::OrderItem->new(
48
        parts_id            => $part->id,
49
        description         => $part->description,
50
        qty                 => $_->quantity,
51
        sellprice           => $_->price,
52
        unit                => $part->unit,
53
        position            => $_->position,
54
        active_price_source => $_->active_price_source,
55
      );
56
    }
57
  }@{ $self->shop_order_items };
58

  
59
  if(!scalar(@error_report)){
60

  
61
    my $shipto_id;
62
    if ($self->billing_firstname ne $self->delivery_firstname || $self->billing_lastname ne $self->delivery_lastname || $self->billing_city ne $self->delivery_city || $self->billing_street ne $self->delivery_street) {
63
      if(my $address = SL::DB::Manager::Shipto->find_by( shiptoname   => $self->delivery_firstname . " " . $self->delivery_lastname,
64
                                                         shiptostreet => $self->delivery_street,
65
                                                         shiptocity   => $self->delivery_city,
66
                                                        )) {
67
        $shipto_id = $address->{shipto_id};
68
      } else {
69
        my $deliveryaddress = SL::DB::Shipto->new;
70
        $deliveryaddress->assign_attributes(
71
          shiptoname         => $self->delivery_firstname . " " . $self->delivery_lastname,
72
          shiptodepartment_1 => $self->delivery_company,
73
          shiptodepartment_2 => $self->delivery_department,
74
          shiptostreet       => $self->delivery_street,
75
          shiptozipcode      => $self->delivery_zipcode,
76
          shiptocity         => $self->delivery_city,
77
          shiptocountry      => $self->delivery_country,
78
          trans_id           => $customer->id,
79
          module             => "CT",
80
        );
81
        $deliveryaddress->save;
82
        $shipto_id = $deliveryaddress->{shipto_id};
83
      }
84
    }
85

  
86
    my $shop = SL::DB::Manager::Shop->find_by(id => $self->shop_id);
87
    my $order = SL::DB::Order->new(
88
      amount                  => $self->amount,
89
      cusordnumber            => $self->shop_ordernumber,
90
      customer_id             => $customer->id,
91
      shipto_id               => $shipto_id,
92
      orderitems              => [ @items ],
93
      employee_id             => $employee->id,
94
      intnotes                => $customer->notes,
95
      salesman_id             => $employee->id,
96
      taxincluded             => $self->tax_included,
97
      payment_id              => $customer->payment_id,
98
      taxzone_id              => $customer->taxzone_id,
99
      currency_id             => $customer->currency_id,
100
      transaction_description => $shop->transaction_description,
101
      transdate               => DateTime->today_local
102
    );
103
     return $order;
104
   }else{
105
     my %error_order = (error   => 1,
106
                        errors  => [ @error_report ],
107
                       );
108
     return \%error_order;
109
   }
110
};
111

  
112
sub check_for_existing_customers {
113
  my ($self, %params) = @_;
114

  
115
  my $name     = $self->billing_lastname ne '' ? $self->billing_firstname . " " . $self->billing_lastname : '';
116
  my $lastname = $self->billing_lastname ne '' ? "%" . $self->billing_lastname . "%"                      : '';
117
  my $company  = $self->billing_company  ne '' ? "%" . $self->billing_company  . "%"                      : '';
118
  my $street   = $self->billing_street   ne '' ?  $self->billing_street                                   : '';
119

  
120
  # Fuzzysearch for street to find e.g. "Dorfstrasse - Dorfstr. - Dorfstraße"
121
  my $fs_query = <<SQL;
122
SELECT *
123
FROM customer
124
WHERE (
125
   (
126
    ( name ILIKE ? OR name ILIKE ? )
127
      AND
128
    zipcode ILIKE ?
129
   )
130
 OR
131
   ( street % ?  AND zipcode ILIKE ?)
132
 OR
133
   email ILIKE ?
134
) AND obsolete = 'F'
135
SQL
136

  
137
  my @values = ($lastname, $company, $self->billing_zipcode, $street, $self->billing_zipcode, $self->billing_email);
138

  
139
  my $customers = SL::DB::Manager::Customer->get_objects_from_sql(
140
    sql  => $fs_query,
141
    args => \@values,
142
  );
143

  
144
  return $customers;
145
}
146

  
147
sub get_customer{
148
  my ($self, %params) = @_;
149
  my $shop = SL::DB::Manager::Shop->find_by(id => $self->shop_id);
150
  my $customer_proposals = $self->check_for_existing_customers;
151
  my $name = $self->billing_firstname . " " . $self->billing_lastname;
152
  my $customer = 0;
153
  if(!scalar(@{$customer_proposals})){
154
    my %address = ( 'name'                  => $name,
155
                    'department_1'          => $self->billing_company,
156
                    'department_2'          => $self->billing_department,
157
                    'street'                => $self->billing_street,
158
                    'zipcode'               => $self->billing_zipcode,
159
                    'city'                  => $self->billing_city,
160
                    'email'                 => $self->billing_email,
161
                    'country'               => $self->billing_country,
162
                    'greeting'              => $self->billing_greeting,
163
                    'fax'                   => $self->billing_fax,
164
                    'phone'                 => $self->billing_phone,
165
                    'ustid'                 => $self->billing_vat,
166
                    'taxincluded_checked'   => $shop->pricetype eq "brutto" ? 1 : 0,
167
                    'taxincluded'           => $shop->pricetype eq "brutto" ? 1 : 0,
168
                    'pricegroup_id'         => (split '\/',$shop->price_source)[0] eq "pricegroup" ?  (split '\/',$shop->price_source)[1] : undef,
169
                    'taxzone_id'            => $shop->taxzone_id,
170
                    'currency'              => $::instance_conf->get_currency_id,
171
                    #'payment_id'            => 7345,# TODO hardcoded
172
                  );
173
    $customer = SL::DB::Customer->new(%address);
174

  
175
    $customer->save;
176
    my $snumbers = "customernumber_" . $customer->customernumber;
177
    SL::DB::History->new(
178
                      trans_id    => $customer->id,
179
                      snumbers    => $snumbers,
180
                      employee_id => SL::DB::Manager::Employee->current->id,
181
                      addition    => 'SAVED',
182
                      what_done   => 'Shopimport',
183
                    )->save();
184

  
185
  }elsif(scalar(@{$customer_proposals}) == 1){
186
    # check if the proposal is the right customer, could be different names under the same address. Depends on how first- and familyname is handled. Here is for customername = companyname or customername = "firstname familyname"
187
    $customer = SL::DB::Manager::Customer->find_by( id       => $customer_proposals->[0]->id,
188
                                                    name     => $name,
189
                                                    email    => $self->billing_email,
190
                                                    street   => $self->billing_street,
191
                                                    zipcode  => $self->billing_zipcode,
192
                                                    city     => $self->billing_city,
193
                                                    obsolete => 'F',
194
                                                  );
195
  }
196

  
197
  return $customer;
198
}
199

  
200
sub compare_to {
201
  my ($self, $other) = @_;
202

  
203
  return  1 if  $self->transfer_date && !$other->transfer_date;
204
  return -1 if !$self->transfer_date &&  $other->transfer_date;
205

  
206
  my $result = 0;
207
  $result    = $self->transfer_date <=> $other->transfer_date if $self->transfer_date;
208
  return $result || ($self->id <=> $other->id);
209
}
210

  
211
1;
212

  
213
__END__
214

  
215
=pod
216

  
217
=encoding utf-8
218

  
219
=head1 NAME
220

  
221
SL::DB::ShopOrder - Model for the 'shop_orders' table
222

  
223
=head1 SYNOPSIS
224

  
225
This is a standard Rose::DB::Object based model and can be used as one.
226

  
227
=head1 METHODS
228

  
229
=over 4
230

  
231
=item C<convert_to_sales_order>
232

  
233
=item C<check_for_existing_customers>
234

  
235
Inexact search for possible matches with existing customers in the database.
236

  
237
Returns all found customers as an arrayref of SL::DB::Customer objects.
238

  
239
=item C<get_customer>
240

  
241
returns only one customer from the check_for_existing_customers if the return from it is 0 or 1 customer.
242

  
243
When it is 0 get customer creates a new customer object of the shop order billing data and returns it
244

  
245
=item C<compare_to>
246

  
247
=back
248

  
249
=head1 TODO
250

  
251
some variables like payments could be better implemented. Transaction description is hardcoded
252

  
253
=head1 AUTHORS
254

  
255
Werner Hahn E<lt>wh@futureworldsearch.netE<gt>
256

  
257
G. Richardson E<lt>grichardson@kivitendo-premium.deE<gt>
258

  
259
=cut
SL/DB/ShopOrderItem.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::ShopOrderItem;
5

  
6
use strict;
7

  
8
use SL::DB::MetaSetup::ShopOrderItem;
9
use SL::DB::Manager::ShopOrderItem;
10

  
11
__PACKAGE__->meta->initialize;
12

  
13
1;
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
sql/Pg-upgrade2/shop_orders.sql
1
-- @tag: shop_orders
2
-- @description: Erstellen der Tabellen shop_orders und shop_order_items
3
-- @depends: release_3_5_0 shops
4

  
5
CREATE TABLE shop_orders (
6
  id SERIAL PRIMARY KEY,
7
  shop_trans_id integer NOT NULL, --id vom shop
8
  shop_ordernumber TEXT, --Bestellnummer vom Shop
9
  shop_data text,        -- store whole order as json
10
  shop_customer_comment text, --Bestellkommentar des Kunden
11
  amount numeric(15,5),  --Bruttogesamtbetrag
12
  netamount numeric(15,5),--Nettogesamtbetrag
13
  order_date timestamp, --Bestelldatum und Zeit
14
  shipping_costs numeric(15,5),
15
  shipping_costs_net numeric(15,5),
16
  shipping_costs_id integer,
17
  tax_included boolean,
18
  payment_id integer, --Bezahlart
19
  payment_description TEXT,  --Bezahlart
20
  shop_id integer,               --welcher shop bei mehreren
21
  host TEXT,             --Hostname vom Shop
22
  remote_ip text,        --IP Besteller
23
  transferred boolean DEFAULT FALSE,    -- übernommen
24
  transfer_date date, -- Zeit wann übernommen
25
  kivi_customer_id integer,  -- Kundenid von Tbl customer wenn übernommen
26
  oe_transid integer,  -- id to
27
-- Bestell-, Rechnungs- und Lieferadresse. !!Manche Shops bieten sowas!!
28
-- In der Regel ist aber die Rechnungsadresse die Kundenadresse
29
  -- Bestelldaten des Kunden
30
  shop_customer_id integer,
31
  shop_customer_number TEXT,
32
  customer_lastname TEXT,
33
  customer_firstname TEXT,
34
  customer_company TEXT,
35
  customer_street TEXT,
36
  customer_zipcode TEXT,
37
  customer_city TEXT,
38
  customer_country TEXT,
39
  customer_greeting TEXT,
40
  customer_department TEXT,
41
  customer_vat TEXT,
42
  customer_phone TEXT,
43
  customer_fax TEXT,
44
  customer_email TEXT,
45
  customer_newsletter boolean,
46
  -- Rechnungsadresse
47
  shop_c_billing_id integer,
48
  shop_c_billing_number TEXT,
49
  billing_lastname TEXT,
50
  billing_firstname TEXT,
51
  billing_company TEXT,
52
  billing_street TEXT,
53
  billing_zipcode TEXT,
54
  billing_city TEXT,
55
  billing_country TEXT,
56
  billing_greeting TEXT,
57
  billing_department TEXT,
58
  billing_vat TEXT,
59
  billing_phone TEXT,
60
  billing_fax TEXT,
61
  billing_email TEXT,
62

  
63
  -- SEPA
64
  sepa_account_holder TEXT,
65
  sepa_iban TEXT,
66
  sepa_bic TEXT,
67

  
68
  -- Lieferadresse
69
  shop_c_delivery_id integer,
70
  shop_c_delivery_number TEXT,
71
  delivery_lastname TEXT,
72
  delivery_firstname TEXT,
73
  delivery_company TEXT,
74
  delivery_street TEXT,
75
  delivery_zipcode TEXT,
76
  delivery_city TEXT,
77
  delivery_country TEXT,
78
  delivery_greeting TEXT,
79
  delivery_department TEXT,
80
  delivery_vat TEXT,
81
  delivery_phone TEXT,
82
  delivery_fax TEXT,
83
  delivery_email TEXT,
84

  
85
  obsolete boolean DEFAULT FALSE NOT NULL,
86
  positions integer,
87

  
88
  itime timestamp DEFAULT now(),
89
  mtime timestamp
90
);
91

  
92
CREATE TABLE shop_order_items (
93
  id            SERIAL PRIMARY KEY,
94
  shop_trans_id INTEGER NOT NULL, --id vom shop in shop-db? -> could use $order_item->shop_order->shop_trans_id instead
95
  shop_order_id INTEGER REFERENCES shop_orders (id) ON DELETE CASCADE,
96
  description   TEXT,  -- Artikelbezeichnung
97
  partnumber    TEXT,
98
  shop_id       INTEGER,
99
  position      INTEGER,
100
  tax_rate      NUMERIC(15,2),
101
  quantity      NUMERIC(25,5),   -- qty in invoice and orderitems is real, doi is numeric(25,5)
102
  price         NUMERIC(15,5)
103
);
sql/Pg-upgrade2/shop_orders_add_active_pricesource.sql
1
-- @tag: shop_orders_add_active_price_source
2
-- @description: Erstellen der Tabellen shop_orders und shop_order_items
3
-- @depends: release_3_5_0 shop_orders
4

  
5
ALTER TABLE shop_order_items ADD COLUMN active_price_source TEXT;
sql/Pg-upgrade2/shop_orders_update_1.sql
1
-- @tag: shop_orders_update_1
2
-- @description: Ändern der Tabellen shop_orders und shop_order_items. Trigger für oe
3
-- @depends: release_3_5_0 shop_orders shop_orders_add_active_price_source
4
-- @ignore: 0
5

  
6
ALTER TABLE shop_orders ADD FOREIGN KEY (shop_id) REFERENCES shops(id);
7
ALTER TABLE shop_orders ADD FOREIGN KEY (kivi_customer_id) REFERENCES customer(id);
8
ALTER TABLE shop_orders DROP COLUMN shop_data;
9
ALTER TABLE shop_order_items DROP COLUMN shop_id;
10

  
11
CREATE OR REPLACE FUNCTION update_shop_orders_on_delete_oe() RETURNS TRIGGER AS $$
12
  BEGIN
13
    UPDATE shop_orders SET oe_trans_id = NULL WHERE oe_trans_id = OLD.id;
14

  
15
    RETURN OLD.id;
16
  END;
17
$$ LANGUAGE plpgsql;
18

  
19
CREATE TRIGGER after_delete_oe_trigger
20
AFTER DELETE ON oe FOR EACH ROW EXECUTE
21
PROCEDURE update_shop_orders_on_delete_oe();
sql/Pg-upgrade2/shop_orders_update_2.sql
1
-- @tag: shop_orders_update_2
2
-- @description: Ändern der Tabellen shop_orders für Trigger spalte war falsch benannt
3
-- @depends: shop_orders_update_1
4
-- @ignore: 0
5

  
6
ALTER TABLE shop_orders RENAME COLUMN oe_transid TO oe_trans_id;
sql/Pg-upgrade2/shop_orders_update_3.sql
1
-- @tag: shop_orders_update_3
2
-- @description: Ändern der Tabellen shop_orders und shop_order_items. Trigger für oe
3
-- @depends: shop_orders_update_1 shop_orders_update_2
4
-- @ignore: 0
5

  
6
ALTER TABLE shop_orders DROP COLUMN oe_trans_id;
7

  
8
DROP FUNCTION update_shop_orders_on_delete_oe() CASCADE;
sql/Pg-upgrade2/shop_parts.sql
1
-- @tag: shop_parts
2
-- @description: Add tables for part information for shop
3
-- @charset: UTF-8
4
-- @depends: release_3_5_0 shops
5
-- @ignore: 0
6

  
7
CREATE TABLE shop_parts (
8
  id               SERIAL PRIMARY KEY,
9
  shop_id          INTEGER NOT NULL REFERENCES shops(id),
10
  part_id          INTEGER NOT NULL REFERENCES parts(id),
11
  shop_description TEXT,
12
  itime            TIMESTAMP DEFAULT now(),
13
  mtime            TIMESTAMP,
14
  last_update      TIMESTAMP,
15
  show_date        DATE,   -- the starting date for displaying part in shop
16
  sortorder        INTEGER,
17
  front_page       BOOLEAN NOT NULL DEFAULT false,
18
  active           BOOLEAN NOT NULL DEFAULT false,  -- rather than obsolete
19
  shop_category TEXT[][],
20
  active_price_source TEXT,
21
  metatag_keywords TEXT,
22
  metatag_description TEXT,
23
  metatag_title TEXT,
24
  UNIQUE (part_id, shop_id)  -- make sure a shop_part appears only once per shop and part
25
);
26

  
27
CREATE TRIGGER mtime_shop_parts BEFORE UPDATE ON shop_parts
28
    FOR EACH ROW EXECUTE PROCEDURE set_mtime();
sql/Pg-upgrade2/shops.sql
1
-- @tag: shops
2
-- @description: Tabelle für Shops
3
-- @depends: release_3_5_0 customer_klass_rename_to_pricegroup_id_and_foreign_key
4
-- @ignore: 0
5

  
6
CREATE TABLE shops (
7
  id SERIAL PRIMARY KEY,
8
  description text,
9
  obsolete BOOLEAN NOT NULL DEFAULT false,
10
  sortkey INTEGER,
11
  connector text,     -- hardcoded options, e.g. xtcommerce, shopware
12
  pricetype text,     -- netto/brutto
13
  price_source text,  -- sellprice/listprice/lastcost or pricegroup id
14
  taxzone_id INTEGER,
15
  last_order_number INTEGER,
16
  orders_to_fetch INTEGER,
17
  url text,
18
  port INTEGER,
19
  login text,  -- "user" is reserved
20
  password text
21
);
sql/Pg-upgrade2/shops_1.sql
1
-- @tag: shop_1
2
-- @description: Add tables for part information for shop
3
-- @charset: UTF-8
4
-- @depends: shops
5
-- @ignore: 0
6

  
7
ALTER TABLE shops ADD COLUMN protocol TEXT NOT NULL DEFAULT 'http';
8
ALTER TABLE shops ADD COLUMN path TEXT NOT NULL DEFAULT '/';
9
ALTER TABLE shops RENAME COLUMN url TO server;
sql/Pg-upgrade2/shops_2.sql
1
-- @tag: shop_2
2
-- @description: Add tables for part information for shop
3
-- @charset: UTF-8
4
-- @depends: shops
5
-- @ignore: 0
6

  
7
ALTER TABLE shops ADD COLUMN realm TEXT;
sql/Pg-upgrade2/shops_3.sql
1
-- @tag: shop_3
2
-- @description: Add columns itime and mtime and transaction_description for table shops
3
-- @charset: UTF-8
4
-- @depends: shops
5
-- @ignore: 0
6

  
7
ALTER TABLE shops ADD COLUMN transaction_description TEXT;
8
ALTER TABLE shops ADD COLUMN itime timestamp DEFAULT now();
9
ALTER TABLE shops ADD COLUMN mtime timestamp DEFAULT now();
10

  
11
CREATE TRIGGER mtime_shops
12
    BEFORE UPDATE ON shops
13
    FOR EACH ROW
14
    EXECUTE PROCEDURE set_mtime();

Auch abrufbar als: Unified diff