]> wagnertech.de Git - mfinanz.git/blob - SL/DB/Manager/PurchaseInvoice.pm
Merge branch 'master' of http://wagnertech.de/git/mfinanz
[mfinanz.git] / SL / DB / Manager / PurchaseInvoice.pm
1 package SL::DB::Manager::PurchaseInvoice;
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::PurchaseInvoice' }
11
12 __PACKAGE__->make_manager_methods;
13
14 sub type_filter {
15   my $class = shift;
16   my $type  = lc(shift || '');
17
18   return (or  => [ invoice => 0, invoice => undef                       ]) if $type eq 'ap_transaction';
19   return (and => [ invoice => 1, amount => { lt => 0 }, or => [ storno => 0, storno => undef ] ]) if $type eq 'purchase_credit_note';
20   return (and => [ invoice => 1, amount => { ge => 0 }, or => [ storno => 0, storno => undef ] ]) if $type =~ m/^(?:purchase_)?invoice$/;
21   return (and => [ invoice => 1,         storno => 1                    ]) if $type =~ m/(?:invoice_)?storno/;
22
23   die "Unknown type $type";
24 }
25
26 sub _sort_spec {
27   return (
28     default                   => [ 'transdate', 1 ],
29     nulls                     => {
30       transaction_description => 'FIRST',
31       vendor_name             => 'FIRST',
32       default                 => 'LAST',
33     },
34     columns                   => {
35       SIMPLE                  => 'ALL',
36       vendor                  => 'lower(vendor.name)',
37       globalprojectnumber     => 'lower(globalproject.projectnumber)',
38
39       # Bug in Rose::DB::Object: the next should be
40       # "globalproject.project_type.description". This workaround will
41       # only work if no other table with "project_type" is visible in
42       # the current query
43       globalproject_type      => 'lower(project_type.description)',
44
45       map { ( $_ => "lower(ap.$_)" ) } qw(invnumber ordnumber quonumber shipvia notes intnotes transaction_description),
46     });
47 }
48
49 sub default_objects_per_page { 40 }
50
51 1;