e03386d0441beba4a0913db38d79d2bf6cc3acb9
[kivitendo-erp.git] / SL / DB / Manager / Order.pm
1 package SL::DB::Manager::Order;
2
3 use strict;
4
5 use parent qw(SL::DB::Helper::Manager);
6
7 use SL::DB::Helper::Paginated;
8 use SL::DB::Helper::Sorted;
9
10 sub object_class { 'SL::DB::Order' }
11
12 __PACKAGE__->make_manager_methods;
13
14 sub type_filter {
15   my $class  = shift;
16   my $type   = lc(shift || '');
17   my $prefix = shift || '';
18
19   return (and => [ "!${prefix}customer_id" => undef,         "${prefix}quotation" => 1                       ]) if $type eq 'sales_quotation';
20   return (and => [ "!${prefix}vendor_id"   => undef,         "${prefix}quotation" => 1                       ]) if $type eq 'request_quotation';
21   return (and => [ "!${prefix}customer_id" => undef, or => [ "${prefix}quotation" => 0, "${prefix}quotation" => undef ] ]) if $type eq 'sales_order';
22   return (and => [ "!${prefix}vendor_id"   => undef, or => [ "${prefix}quotation" => 0, "${prefix}quotation" => undef ] ]) if $type eq 'purchase_order';
23
24   die "Unknown type $type";
25 }
26
27 sub _sort_spec {
28   return (
29     default                   => [ 'transdate', 1 ],
30     nulls                     => {
31       transaction_description => 'FIRST',
32       customer_name           => 'FIRST',
33       vendor_name             => 'FIRST',
34       default                 => 'LAST',
35     },
36     columns                   => {
37       SIMPLE                  => 'ALL',
38       customer                => 'customer.name',
39       vendor                  => 'vendor.name',
40       globalprojectnumber     => 'lower(globalproject.projectnumber)',
41
42       # Bug in Rose::DB::Object: the next should be
43       # "globalproject.project_type.description". This workaround will
44       # only work if no other table with "project_type" is visible in
45       # the current query
46       globalproject_type      => 'lower(project_type.description)',
47
48       map { ( $_ => "lower(oe.$_)" ) } qw(ordnumber quonumber cusordnumber shippingpoint shipvia notes intnotes transaction_description),
49     });
50 }
51
52 sub default_objects_per_page { 40 }
53
54 1;