Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 73df5fb5

Von Moritz Bunkus vor mehr als 13 Jahren hinzugefügt

  • ID 73df5fb5a78b7fc8576c9b7e3da47e10fc551c85
  • Vorgänger fc61a974
  • Nachfolger b9dbc9e3

Umwandeln von Order-Model in neue Invoice-Instanz

Unterschiede anzeigen:

SL/DB/Invoice.pm
5 5

  
6 6
use strict;
7 7

  
8
use Carp;
8 9
use List::Util qw(first);
9 10

  
10 11
use SL::DB::MetaSetup::Invoice;
11 12
use SL::DB::Manager::Invoice;
12 13
use SL::DB::Helper::LinkedRecords;
13 14
use SL::DB::Helper::PriceTaxCalculator;
15
use SL::DB::Employee;
14 16

  
15 17
__PACKAGE__->meta->add_relationship(
16 18
  invoiceitems => {
......
21 23
      with_objects => [ 'part' ]
22 24
    }
23 25
  },
26
  payment_term => {
27
    type       => 'one to one',
28
    class      => 'SL::DB::PaymentTerm',
29
    column_map => { payment_id => 'id' },
30
  },
24 31
);
25 32

  
26 33
__PACKAGE__->meta->initialize;
......
66 73
  return $self->paid >= $self->amount;
67 74
}
68 75

  
76
sub new_from {
77
  my ($class, $source, %params) = @_;
78

  
79
  croak("Unsupported source object type '" . ref($source) . "'") unless ref($source) =~ m/^ SL::DB:: (?: Order | DeliveryOrder ) $/x;
80
  croak("Cannot create invoices for purchase records")           unless $source->customer_id;
81

  
82
  my $terms = $source->can('payment_id') && $source->payment_id ? $source->payment_term->terms_netto : 0;
83

  
84
  my %args = ( map({ ( $_ => $source->$_ ) } qw(customer_id taxincluded shippingpoint shipvia notes intnotes curr salesman_id cusordnumber ordnumber quonumber
85
                                                department_id cp_id language_id payment_id delivery_customer_id delivery_vendor_id taxzone_id shipto_id
86
                                                globalproject_id transaction_description)),
87
               transdate   => DateTime->today_local,
88
               gldate      => DateTime->today_local,
89
               duedate     => DateTime->today_local->add(days => $terms * 1),
90
               invoice     => 1,
91
               type        => 'invoice',
92
               storno      => 0,
93
               employee_id => (SL::DB::Manager::Employee->current || SL::DB::Employee->new(id => $source->employee_id))->id,
94
            );
95

  
96
  if ($source->type =~ /_order$/) {
97
    $args{deliverydate} = $source->reqdate;
98
    $args{orddate}      = $source->transdate;
99
  } else {
100
    $args{quodate}      = $source->transdate;
101
  }
102

  
103
  my $invoice = $class->new(%args, %params);
104

  
105
  my @items = map {
106
    my $source_item = $_;
107
    SL::DB::InvoiceItem->new(map({ ( $_ => $source_item->$_ ) }
108
                                 qw(parts_id description qty sellprice discount project_id
109
                                    serialnumber pricegroup_id ordnumber transdate cusordnumber unit
110
                                    base_qty subtotal longdescription lastcost price_factor_id)),
111
                            deliverydate => $source_item->reqdate);
112
  } @{ $source->items };
113

  
114
  $invoice->invoiceitems(\@items);
115

  
116
  return $invoice;
117
}
118

  
69 119
sub post {
70 120
  my ($self, %params) = @_;
71 121

  

Auch abrufbar als: Unified diff