Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 42ea98b4

Von Moritz Bunkus vor fast 14 Jahren hinzugefügt

  • ID 42ea98b4883178877c2bd47a032cea5891998e5a
  • Vorgänger 22150c52
  • Nachfolger f4dca613

Umwandeln von Angebot/Auftrag in Rechnung implementiert

Conflicts:

SL/DB/Order.pm

Unterschiede anzeigen:

SL/DB/Order.pm
3 3
use utf8;
4 4
use strict;
5 5

  
6
use SL::RecordLinks;
6
use Carp;
7
use DateTime;
8
use List::Util qw(max);
7 9

  
8 10
use SL::DB::MetaSetup::Order;
9 11
use SL::DB::Manager::Order;
......
11 13
use SL::DB::Helper::LinkedRecords;
12 14
use SL::DB::Helper::PriceTaxCalculator;
13 15
use SL::DB::Helper::TransNumberGenerator;
16
use SL::RecordLinks;
14 17

  
15 18
__PACKAGE__->meta->add_relationship(
16 19
  orderitems => {
......
83 86
  return shift()->invoices(query => [ abschlag => 0 ]);
84 87
}
85 88

  
89
sub convert_to {
90
  my ($self, %params) = @_;
91

  
92
  my $destination_type = lc(delete $params{destination_type});
93

  
94
  if ($destination_type eq 'invoice') {
95
    $self->convert_to_invoice(%params);
96
  } else {
97
    croak("Unsupported destination type `$destination_type'");
98
  }
99
}
100

  
101
sub convert_to_invoice {
102
  my ($self, %params) = @_;
103

  
104
  if (!$params{ar_id}) {
105
    my $chart = SL::DB::Manager::Chart->get_all(query   => [ SL::DB::Manager::Chart->link_filter('AR') ],
106
                                                sort_by => 'id ASC',
107
                                                limit   => 1)->[0];
108
    croak("No AR chart found and no parameter `ar_id' given") unless $chart;
109
    $params{ar_id} = $chart->id;
110
  }
111

  
112
  my $invoice;
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);
117
    # die;
118
  })) {
119
    return undef;
120
  }
121

  
122
  return $invoice;
123
}
124

  
86 125
1;
87 126

  
88 127
__END__

Auch abrufbar als: Unified diff