Projekt

Allgemein

Profil

« Zurück | Weiter » 

Revision 6ee486a5

Von Moritz Bunkus vor fast 11 Jahren hinzugefügt

  • ID 6ee486a53d467fe2cb5aa5a971e5de0755ab6d0c
  • Vorgänger bb7e2e85
  • Nachfolger f4de41a2

SL::DB::Invoice->new_from: Positionsfelder ordnumber, donumber aus Quellbelegen setzen

Unterschiede anzeigen:

SL/DB/Invoice.pm
131 131
  require SL::DB::Employee;
132 132

  
133 133
  my $terms = $source->can('payment_id') && $source->payment_id ? $source->payment_terms->terms_netto : 0;
134
  my (@columns, @item_columns);
134
  my (@columns, @item_columns, $item_parent_id_column, $item_parent_column);
135 135

  
136 136
  if (ref($source) eq 'SL::DB::Order') {
137 137
    @columns      = qw(quonumber payment_id delivery_customer_id delivery_vendor_id);
138 138
    @item_columns = qw(subtotal);
139 139

  
140
    $item_parent_id_column = 'trans_id';
141
    $item_parent_column    = 'order';
142

  
140 143
  } else {
141 144
    @columns      = qw(donumber);
145

  
146
    $item_parent_id_column = 'delivery_order_id';
147
    $item_parent_column    = 'delivery_order';
142 148
  }
143 149

  
144 150
  my %args = ( map({ ( $_ => $source->$_ ) } qw(customer_id taxincluded shippingpoint shipvia notes intnotes salesman_id cusordnumber ordnumber department_id
......
162 168

  
163 169
  my $invoice = $class->new(%args, %{ $params{attributes} || {} });
164 170
  my $items   = delete($params{items}) || $source->items_sorted;
171
  my %item_parents;
165 172

  
166 173
  my @items = map {
167 174
    my $source_item      = $_;
175
    my $source_item_id   = $_->$item_parent_id_column;
168 176
    my @custom_variables = map { _clone_orderitem_delivery_order_item_cvar($_) } @{ $source_item->custom_variables };
169 177

  
178
    $item_parents{$source_item_id} ||= $source_item->$item_parent_column;
179
    my $item_parent                  = $item_parents{$source_item_id};
180

  
170 181
    SL::DB::InvoiceItem->new(map({ ( $_ => $source_item->$_ ) }
171
                                 qw(parts_id description qty sellprice discount project_id serialnumber pricegroup_id ordnumber transdate cusordnumber unit
182
                                 qw(parts_id description qty sellprice discount project_id serialnumber pricegroup_id transdate cusordnumber unit
172 183
                                    base_qty longdescription lastcost price_factor_id), @item_columns),
173 184
                             deliverydate     => $source_item->reqdate,
174 185
                             fxsellprice      => $source_item->sellprice,
175 186
                             custom_variables => \@custom_variables,
187
                             ordnumber        => ref($item_parent) eq 'SL::DB::Order'         ? $item_parent->ordnumber : $source_item->ordnumber,
188
                             donumber         => ref($item_parent) eq 'SL::DB::DeliveryOrder' ? $item_parent->donumber  : $source_item->can('donumber') ? $source_item->donumber : '',
176 189
                           );
177 190

  
178 191
  } @{ $items };

Auch abrufbar als: Unified diff