]> wagnertech.de Git - mfinanz.git/blob - SL/DB/Manager/Invoice.pm
kivitendo 3.9.2-0.2
[mfinanz.git] / SL / DB / Manager / Invoice.pm
1 package SL::DB::Manager::Invoice;
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::Invoice' }
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 'ar_transaction';
19   return (type => 'invoice_for_advance_payment'                                                  ) if $type eq 'invoice_for_advance_payment';
20   return (and => [ type => 'invoice_for_advance_payment', amount => { lt => 0 }                 ]) if $type eq 'invoice_for_advance_payment_storno';
21   return (type => 'final_invoice'                                                                ) if $type eq 'final_invoice';
22   return (and => [ invoice => 1, amount  => { ge => 0 }, or => [ storno => 0, storno => undef ] ]) if $type =~ m/^(?:sales_)?invoice$/;
23   return (and => [ invoice => 1, amount  => { lt => 0 }, or => [ storno => 0, storno => undef ] ]) if $type eq 'credit_note';
24   return (and => [ invoice => 1, amount  => { lt => 0 },         storno => 1                    ]) if $type =~ m/(?:invoice_)?storno/;
25   return (and => [ invoice => 1, amount  => { ge => 0 },         storno => 1                    ]) if $type eq 'credit_note_storno';
26   return (amount => {gt => \'paid'}) if $type eq 'open';
27
28   die "Unknown type $type";
29 }
30
31 sub _sort_spec {
32   return (
33     default                   => [ 'transdate', 1 ],
34     nulls                     => {
35       transaction_description => 'FIRST',
36       customer_name           => 'FIRST',
37       default                 => 'LAST',
38     },
39     columns                   => {
40       SIMPLE                  => 'ALL',
41       customer                => 'lower(customer.name)',
42       globalprojectnumber     => 'lower(globalproject.projectnumber)',
43
44       # Bug in Rose::DB::Object: the next should be
45       # "globalproject.project_type.description". This workaround will
46       # only work if no other table with "project_type" is visible in
47       # the current query
48       globalproject_type      => 'lower(project_type.description)',
49
50       map { ( $_ => "lower(ar.$_)" ) } qw(invnumber ordnumber quonumber cusordnumber shippingpoint shipvia notes intnotes transaction_description),
51     });
52 }
53
54 sub default_objects_per_page { 40 }
55
56 1;