8 use List::Util qw(max);
10 use SL::DB::MetaSetup::Order;
11 use SL::DB::Manager::Order;
13 use SL::DB::Helper::LinkedRecords;
14 use SL::DB::Helper::PriceTaxCalculator;
15 use SL::DB::Helper::TransNumberGenerator;
18 __PACKAGE__->meta->add_relationship(
20 type => 'one to many',
21 class => 'SL::DB::OrderItem',
22 column_map => { id => 'trans_id' },
24 with_objects => [ 'part' ]
27 periodic_invoices_config => {
29 class => 'SL::DB::PeriodicInvoicesConfig',
30 column_map => { id => 'oe_id' },
32 periodic_invoices => {
33 type => 'one to many',
34 class => 'SL::DB::PeriodicInvoice',
35 column_map => { id => 'oe_id' },
39 class => 'SL::DB::PaymentTerm',
40 column_map => { payment_id => 'id' },
44 __PACKAGE__->meta->initialize;
48 sub items { goto &orderitems; }
53 return 'sales_order' if $self->customer_id && ! $self->quotation;
54 return 'purchase_order' if $self->vendor_id && ! $self->quotation;
55 return 'sales_quotation' if $self->customer_id && $self->quotation;
56 return 'request_quotation' if $self->vendor_id && $self->quotation;
62 return shift->type eq shift;
69 if ($self->quotation) {
72 return SL::DB::Manager::Invoice->get_all(
74 ordnumber => $self->ordnumber,
75 @{ $params{query} || [] },
81 sub abschlag_invoices {
82 return shift()->invoices(query => [ abschlag => 1 ]);
86 return shift()->invoices(query => [ abschlag => 0 ]);
90 my ($self, %params) = @_;
92 my $destination_type = lc(delete $params{destination_type});
94 if ($destination_type eq 'invoice') {
95 $self->convert_to_invoice(%params);
97 croak("Unsupported destination type `$destination_type'");
101 sub convert_to_invoice {
102 my ($self, %params) = @_;
104 if (!$params{ar_id}) {
105 my $chart = SL::DB::Manager::Chart->get_all(query => [ SL::DB::Manager::Chart->link_filter('AR') ],
108 croak("No AR chart found and no parameter `ar_id' given") unless $chart;
109 $params{ar_id} = $chart->id;
113 if (!$self->db->do_transaction(sub {
114 $invoice = SL::DB::Invoice->new_from($self)->post(%params) || die;
115 $self->link_to_record($invoice);
116 $self->update_attributes(closed => 1);
131 SL::DB::Order - Order Datenbank Objekt.
137 Returns one of the following string types:
145 =item sales_quotation
147 =item request_quotation
153 Rreturns true if the order is of the given type.
161 Sven Schöling <s.schoeling@linet-services.de>