1 package SL::DB::Manager::Invoice;
5 use parent qw(SL::DB::Helper::Manager);
7 use SL::DB::Helper::Paginated;
8 use SL::DB::Helper::Sorted;
10 sub object_class { 'SL::DB::Invoice' }
12 __PACKAGE__->make_manager_methods;
16 my $type = lc(shift || '');
18 return (or => [ invoice => 0, invoice => undef ]) if $type eq 'ar_transaction';
19 return (and => [ invoice => 1, amount => { ge => 0 }, or => [ storno => 0, storno => undef ] ]) if $type =~ m/^(?:sales_)?invoice$/;
20 return (and => [ invoice => 1, amount => { lt => 0 }, or => [ storno => 0, storno => undef ] ]) if $type eq 'credit_note';
21 return (and => [ invoice => 1, amount => { lt => 0 }, storno => 1 ]) if $type =~ m/(?:invoice_)?storno/;
22 return (and => [ invoice => 1, amount => { ge => 0 }, storno => 1 ]) if $type eq 'credit_note_storno';
23 return (amount => {gt => 'paid'}) if $type eq 'open';
25 die "Unknown type $type";
30 default => [ 'transdate', 1 ],
32 transaction_description => 'FIRST',
33 customer_name => 'FIRST',
38 customer => 'lower(customer.name)',
39 globalprojectnumber => 'lower(globalproject.projectnumber)',
41 # Bug in Rose::DB::Object: the next should be
42 # "globalproject.project_type.description". This workaround will
43 # only work if no other table with "project_type" is visible in
45 globalproject_type => 'lower(project_type.description)',
47 map { ( $_ => "lower(ar.$_)" ) } qw(invnumber ordnumber quonumber cusordnumber shippingpoint shipvia notes intnotes transaction_description),
51 sub default_objects_per_page { 40 }