use SL::CVar;
sub flatten_to_form {
- my ($self, $form, $format_amounts) = @_;
+ my ($self, $form, %params) = @_;
my $vc = $self->can('customer_id') && $self->customer_id ? 'customer' : 'vendor';
$form->{$transdate_idx} = $self->transdate->to_lxoffice;
}
- $self->{vc} = $vc if ref($self) =~ /^SL::DB::.*Invoice/;
+ $form->{vc} = $vc if ref($self) =~ /^SL::DB::.*Invoice/;
my @vc_fields = (qw(account_number bank bank_code bic business city contact country creditlimit discount
email fax homepage iban language name payment_terms phone street taxnumber zipcode),
_copy($self->salesman, $form, 'salesman', '', 0, map { $_->name } SL::DB::Employee->meta->columns) if _has($self, 'salesman_id');
_copy($self->acceptance_confirmed_by, $form, 'acceptance_confirmed_by_', '', 0, map { $_->name } SL::DB::Employee->meta->columns) if _has($self, 'acceptance_confirmed_by_id');
- $form->{language} = $self->language_code if _has($self, 'language_id');
+ $form->{employee} = $self->employee->name if _has($self, 'employee_id');
+ $form->{language} = $self->language->template_code if _has($self, 'language_id');
$form->{department} = $self->department->description if _has($self, 'department_id');
$form->{rowcount} = scalar(@{ $self->items });
my $idx = 0;
+ my $format_amounts = $params{format_amounts} ? 1 : 0;
+ my $format_notnull = $params{format_amounts} ? 2 : 0;
foreach my $item (@{ $self->items }) {
next if _has($item, 'assemblyitem');
$idx++;
- $form->{"id_${idx}"} = $item->parts_id;
- $form->{"number_${idx}"} = $item->part->partnumber;
- _copy($item, $form, '', "_${idx}", 0, qw(description project_id ship serialnumber pricegroup_id ordnumber cusordnumber unit
+ $form->{"id_${idx}"} = $item->parts_id;
+ $form->{"partnumber_${idx}"} = $item->part->partnumber;
+ _copy($item, $form, '', "_${idx}", 0, qw(description project_id ship serialnumber pricegroup_id ordnumber cusordnumber unit
subtotal longdescription price_factor_id marge_price_factor approved_sellprice reqdate transdate));
- _copy($item, $form, '', "_${idx}", $format_amounts, qw(qty sellprice discount marge_total marge_percent lastcost));
+ _copy($item, $form, '', "_${idx}", $format_amounts, qw(qty sellprice marge_total marge_percent lastcost));
+ _copy($item, $form, '', "_${idx}", $format_notnull, qw(discount));
_copy($item->project, $form, 'project', "_${idx}", 0, qw(number description)) if _has($item, 'project_id');
_copy_custom_variables($item, $form, 'ic_cvar_', "_${idx}");
}
_copy_custom_variables($self, $form, 'vc_cvar_', '');
- # TODO: CustomVariables
return $self;
}
sub _copy {
my ($src, $form, $prefix, $postfix, $format_amounts, @columns) = @_;
- map { $form->{"${prefix}${_}${postfix}"} = ref($src->$_) eq 'DateTime' ? $src->$_->to_lxoffice : $src->$_ if $src->can($_) } @columns if !$format_amounts;
- map { $form->{"${prefix}${_}${postfix}"} = $::form->format_amount(\%::myconfig, $src->$_ * 1, 2) if $src->can($_) } @columns if $format_amounts;
+ @columns = grep { $src->can($_) } @columns;
+
+ map { $form->{"${prefix}${_}${postfix}"} = ref($src->$_) eq 'DateTime' ? $src->$_->to_lxoffice : $src->$_ } @columns if !$format_amounts;
+ map { $form->{"${prefix}${_}${postfix}"} = $::form->format_amount(\%::myconfig, $src->$_ * 1, 2) } @columns if $format_amounts == 1;
+ map { $form->{"${prefix}${_}${postfix}"} = $src->$_ * 1 ? $::form->format_amount(\%::myconfig, $src->$_ * 1, 2) : 0 } @columns if $format_amounts == 2;
return $src;
}