-# This file has been auto-generated only because it didn't exist.
-# Feel free to modify it at will; it will not be overwritten automatically.
-
package SL::DB::Invoice;
use strict;
use List::Util qw(first);
use Rose::DB::Object::Helpers ();
-
use SL::DB::MetaSetup::Invoice;
use SL::DB::Manager::Invoice;
+use SL::DB::Helper::Payment qw(:ALL);
+use SL::DB::Helper::AttrHTML;
+use SL::DB::Helper::AttrSorted;
use SL::DB::Helper::FlattenToForm;
use SL::DB::Helper::LinkedRecords;
use SL::DB::Helper::PriceTaxCalculator;
use SL::DB::Helper::PriceUpdater;
use SL::DB::Helper::TransNumberGenerator;
use SL::Locale::String qw(t8);
+use SL::DB::CustomVariable;
__PACKAGE__->meta->add_relationship(
invoiceitems => {
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__->attr_sorted('items');
+
__PACKAGE__->before_save('_before_save_set_invnumber');
# hooks
sub items { goto &invoiceitems; }
sub add_items { goto &add_invoiceitems; }
-sub items_sorted {
- my ($self) = @_;
-
- return [ sort {$a->id <=> $b->id } @{ $self->items } ];
-}
-
sub is_sales {
# For compatibility with Order, DeliveryOrder
croak 'not an accessor' if @_ > 1;
$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};
goto &customer;
}
-sub transactions {
+sub link {
my ($self) = @_;
- return unless $self->id;
+ my $html;
+ $html = SL::Presenter->get->sales_invoice($self, display => 'inline') if $self->invoice;
+ $html = SL::Presenter->get->ar_transaction($self, display => 'inline') if !$self->invoice;
- require SL::DB::AccTransaction;
- SL::DB::Manager::AccTransaction->get_all(query => [ trans_id => $self->id ]);
+ return $html;
}
1;