X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/mfinanz.git/blobdiff_plain/49f5b7f70599c029e87c494f559a6da5fde0d0c7..4bd1e2f8b588972f10f92728301feacefd5ee4dd:/SL/DB/Invoice.pm diff --git a/SL/DB/Invoice.pm b/SL/DB/Invoice.pm index 6af70994b..3e6c65a49 100644 --- a/SL/DB/Invoice.pm +++ b/SL/DB/Invoice.pm @@ -12,6 +12,7 @@ use Rose::DB::Object::Helpers (); use SL::DB::MetaSetup::Invoice; use SL::DB::Manager::Invoice; +use SL::DB::Helper::AttrHTML; use SL::DB::Helper::FlattenToForm; use SL::DB::Helper::LinkedRecords; use SL::DB::Helper::PriceTaxCalculator; @@ -45,10 +46,21 @@ __PACKAGE__->meta->add_relationship( column_map => { id => 'trans_id' }, query_args => [ module => 'AR' ], }, + transactions => { + type => 'one to many', + class => 'SL::DB::AccTransaction', + column_map => { id => 'trans_id' }, + manager_args => { + with_objects => [ 'chart' ], + sort_by => 'acc_trans_id ASC', + }, + }, ); __PACKAGE__->meta->initialize; +__PACKAGE__->attr_html('notes'); + __PACKAGE__->before_save('_before_save_set_invnumber'); # hooks @@ -69,7 +81,7 @@ sub add_items { goto &add_invoiceitems; } sub items_sorted { my ($self) = @_; - return [ sort {$a->id <=> $b->id } @{ $self->items } ]; + return [ sort {$a->position <=> $b->position } @{ $self->items } ]; } sub is_sales { @@ -184,17 +196,20 @@ sub new_from { $item_parents{$source_item_id} ||= $source_item->$item_parent_column; my $item_parent = $item_parents{$source_item_id}; - - SL::DB::InvoiceItem->new(map({ ( $_ => $source_item->$_ ) } - qw(parts_id description qty sellprice discount project_id serialnumber pricegroup_id transdate cusordnumber unit - base_qty longdescription lastcost price_factor_id), @item_columns), - deliverydate => $source_item->reqdate, - fxsellprice => $source_item->sellprice, - custom_variables => \@custom_variables, - ordnumber => ref($item_parent) eq 'SL::DB::Order' ? $item_parent->ordnumber : $source_item->ordnumber, - donumber => ref($item_parent) eq 'SL::DB::DeliveryOrder' ? $item_parent->donumber : $source_item->can('donumber') ? $source_item->donumber : '', - ); - + my $current_invoice_item = + SL::DB::InvoiceItem->new(map({ ( $_ => $source_item->$_ ) } + qw(parts_id description qty sellprice discount project_id serialnumber pricegroup_id transdate cusordnumber unit + base_qty longdescription lastcost price_factor_id active_discount_source active_price_source), @item_columns), + deliverydate => $source_item->reqdate, + fxsellprice => $source_item->sellprice, + custom_variables => \@custom_variables, + ordnumber => ref($item_parent) eq 'SL::DB::Order' ? $item_parent->ordnumber : $source_item->ordnumber, + donumber => ref($item_parent) eq 'SL::DB::DeliveryOrder' ? $item_parent->donumber : $source_item->can('donumber') ? $source_item->donumber : '', + ); + + $current_invoice_item->{"converted_from_orderitems_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::Order'; + $current_invoice_item->{"converted_from_delivery_order_items_id"} = $_->{id} if ref($item_parent) eq 'SL::DB::DeliveryOrder'; + $current_invoice_item; } @{ $items }; @items = grep { $_->qty * 1 } @items if $params{skip_items_zero_qty}; @@ -343,13 +358,12 @@ sub date { goto &transdate; } -sub transactions { - my ($self) = @_; - - return unless $self->id; +sub reqdate { + goto &duedate; +} - require SL::DB::AccTransaction; - SL::DB::Manager::AccTransaction->get_all(query => [ trans_id => $self->id ]); +sub customervendor { + goto &customer; } 1;