revtrans => { type => 'boolean', default => 'false' },
rfqnumber => { type => 'text' },
rmanumber => { type => 'text' },
+ rndgain_accno_id => { type => 'integer' },
+ rndloss_accno_id => { type => 'integer' },
sales_delivery_order_show_delete => { type => 'boolean', default => 'true' },
sales_order_show_delete => { type => 'boolean', default => 'true' },
sales_purchase_order_ship_missing_column => { type => 'boolean', default => 'false' },
d.closedto, d.revtrans,
(SELECT cu.name FROM currencies cu WHERE cu.id=d.currency_id) AS defaultcurrency,
(SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
- (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
+ (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno,
+ (SELECT c.accno FROM chart c WHERE d.rndgain_accno_id = c.id) AS rndgain_accno,
+ (SELECT c.accno FROM chart c WHERE d.rndloss_accno_id = c.id) AS rndloss_accno
FROM defaults d|;
$ref = selectfirst_hashref_query($self, $dbh, $query);
map { $self->{$_} = $ref->{$_} } keys %$ref;
current_date AS transdate, d.closedto, d.revtrans,
(SELECT cu.name FROM currencies cu WHERE cu.id=d.currency_id) AS defaultcurrency,
(SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
- (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
+ (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno,
+ (SELECT c.accno FROM chart c WHERE d.rndgain_accno_id = c.id) AS rndgain_accno,
+ (SELECT c.accno FROM chart c WHERE d.rndloss_accno_id = c.id) AS rndloss_accno
FROM defaults d|;
$ref = selectfirst_hashref_query($self, $dbh, $query);
map { $self->{$_} = $ref->{$_} } keys %$ref;
}
}
- $form->{amount}{ $form->{id} }{ $form->{AR} } = $netamount + $tax;
- $form->{paid} =
- $form->round_amount($form->{paid} * $form->{exchangerate} + $diff, 2);
+ # Invoice Summary includes Rounding
+ my $grossamount = $netamount + $tax;
+ my $rounding = $form->round_amount(
+ $form->round_amount($grossamount, 2, 1) - $form->round_amount($grossamount, 2),
+ 2
+ );
+ my $rnd_accno = $rounding == 0 ? 0
+ : $rounding > 0 ? $form->{rndgain_accno}
+ : $form->{rndloss_accno}
+ ;
+ $form->{amount}{ $form->{id} }{ $form->{AR} } = $form->round_amount($grossamount, 2, 1);
+ $form->{paid} = $form->round_amount(
+ $form->{paid} * $form->{exchangerate} + $diff,
+ 2
+ );
# reverse AR
$form->{amount}{ $form->{id} }{ $form->{AR} } *= -1;
do_query($form, $dbh, $query, @values);
}
}
+ if (!$payments_only && ($rnd_accno != 0)) {
+ $query =
+ qq|INSERT INTO acc_trans (trans_id, chart_id, amount, transdate, tax_id, taxkey, project_id, chart_link)
+ VALUES (?, (SELECT id FROM chart WHERE accno = ?), ?, ?, (SELECT id FROM tax WHERE taxkey=0), 0, ?, (SELECT link FROM chart WHERE accno = ?))|;
+ @values = (conv_i($trans_id), $rnd_accno, $rounding, conv_date($form->{invdate}), conv_i($project_id), $rnd_accno);
+ do_query($form, $dbh, $query, @values);
+ $rnd_accno = 0;
+ }
}
# deduct payment differences from diff
return;
}
- $amount = $netamount + $tax;
+ $amount = $form->round_amount( $netamount + $tax, 2, 1);
# save AR record
#erweiterung fuer lieferscheinnummer (donumber) 12.02.09 jb
(SELECT c.accno FROM chart c WHERE d.income_accno_id = c.id) AS income_accno,
(SELECT c.accno FROM chart c WHERE d.expense_accno_id = c.id) AS expense_accno,
(SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
- (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
+ (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno,
+ (SELECT c.accno FROM chart c WHERE d.rndgain_accno_id = c.id) AS rndgain_accno,
+ (SELECT c.accno FROM chart c WHERE d.rndloss_accno_id = c.id) AS rndloss_accno
${query_transdate}
FROM defaults d|;
my $tax = 0;
map { $tax += $form->round_amount($taxaccounts{$_}, 2) } keys %taxaccounts;
- $amount = $form->round_amount($netamount + $tax, 2);
+ $amount = $form->round_amount($netamount + $tax, 2, 1);
$netamount = $form->round_amount($netamount, 2);
if ($form->{currency} eq $form->{defaultcurrency}) {
(SELECT c.accno FROM chart c WHERE d.income_accno_id = c.id) AS income_accno,
(SELECT c.accno FROM chart c WHERE d.expense_accno_id = c.id) AS expense_accno,
(SELECT c.accno FROM chart c WHERE d.fxgain_accno_id = c.id) AS fxgain_accno,
- (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno
+ (SELECT c.accno FROM chart c WHERE d.fxloss_accno_id = c.id) AS fxloss_accno,
+ (SELECT c.accno FROM chart c WHERE d.rndgain_accno_id = c.id) AS rndgain_accno,
+ (SELECT c.accno FROM chart c WHERE d.rndloss_accno_id = c.id) AS rndloss_accno
$query_add
FROM defaults d|;
my $ref = selectfirst_hashref_query($form, $dbh, $query);
my ($self, $myconfig, $form) = @_;
$form->{company} = $::instance_conf->get_company;
$form->{address} = $::instance_conf->get_address;
- #injection-filter
- $form->{fromdate} =~ s/[^0-9\.]//g;
- $form->{todate} =~ s/[^0-9\.]//g;
- #input validation
- $form->{fromdate} = "01.01.2000" if $form->{fromdate} !~ m/[0-9]*\.[0-9]*\.[0-9]*/;
- $form->{todate} = $form->current_date(%{$myconfig}) if $form->{todate} !~ m/[0-9]*\.[0-9]*\.[0-9]*/;
+ $form->{fromdate} = DateTime->new(year => 2000, month => 1, day => 1)->to_kivitendo unless $form->{fromdate};
+ $form->{todate} = $form->current_date(%{$myconfig}) unless $form->{todate};
my %categories = (I => "ERTRAG", E => "AUFWAND");
my $fromdate = conv_dateq($form->{fromdate});
my $query = qq|
SELECT id, accno, description, category
FROM chart
- WHERE category = '$category' $inclusion
+ WHERE category = ? $inclusion
ORDER BY accno
|;
- my $accounts = _query($query);
+ my $accounts = _query($query, $category);
$main::lxdebug->leave_sub();
return $accounts;
my $query = qq|
SELECT SUM(amount)
FROM acc_trans
- WHERE chart_id = '$chart_id'
- AND transdate >= $fromdate
- AND transdate <= $todate
+ WHERE chart_id = ?
+ AND transdate >= ?
+ AND transdate <= ?
|;
- $total += _query($query)->[0]->{sum};
+ $total += _query($query, $chart_id, $fromdate, $todate)->[0]->{sum};
$main::lxdebug->leave_sub();
return $total;
$form->{title} = $locale->text('Delete Account');
foreach my $id (
- qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id)
+ qw(inventory_accno_id income_accno_id expense_accno_id fxgain_accno_id fxloss_accno_id rndgain_accno_id rndloss_accno_id)
) {
if ($form->{id} == $form->{$id}) {
$form->error($locale->text('Cannot delete default account!'));
}
}
+ my $grossamount = $form->{invtotal};
+ $form->{invtotal} = $form->round_amount( $form->{invtotal}, 2, 1 );
+ $form->{rounding} = $form->round_amount(
+ $form->{invtotal} - $form->round_amount($grossamount, 2),
+ 2
+ );
+
# follow ups
if ($form->{id}) {
$form->{follow_ups} = FU->follow_ups('trans_id' => $form->{id}) || [];
</tr> |;
}
}
-
-# $form->{invsubtotal} = $form->format_amount(\%myconfig, $form->{invsubtotal}, 2, 0); # template does this
-
} else {
foreach my $item (split / /, $form->{taxaccounts}) {
if ($form->{"${item}_base"}) {
}
}
+ my $grossamount = $form->{invtotal};
+ $form->{invtotal} = $form->round_amount( $form->{invtotal}, 2, 1);
+ $form->{rounding} = $form->round_amount(
+ $form->{invtotal} - $form->round_amount($grossamount, 2),
+ 2
+ );
$form->{oldinvtotal} = $form->{invtotal};
$TMPL_VAR{ALL_DELIVERY_TERMS} = SL::DB::Manager::DeliveryTerm->get_all_sorted();
'Risk' => 'Risiko',
'Risk levels' => 'Risikograde',
'Risks' => 'Risikograde',
+ 'Rounding' => 'Rundung',
+ 'Rounding Gain' => 'Rundungserträge',
+ 'Rounding Loss' => 'Rundungsaufwendungen',
'Row' => 'Zeile',
'Row #1: amount has to be different from zero.' => 'Zeile #1: Der Wert darf nicht 0 sein.',
'Row number' => 'Zeilennummer',
'Revenues EU without UStId' => '',
'Review of Aging list' => '',
'Right' => '',
+ 'Rounding' => '',
+ 'Rounding Gain' => '',
+ 'Rounding Loss' => '',
'Row #1: amount has to be different from zero.' => '',
'Row number' => '',
'Row was created from current record' => '',
--- /dev/null
+-- @tag: defaults_add_rnd_accno_ids
+-- @description: adds new columns 'rndgain_accno_id' and 'rndloss_accno_id' in table defaults, used to book roundings
+-- @depends: release_3_1_0
+ALTER TABLE defaults ADD COLUMN rndgain_accno_id Integer;
+ALTER TABLE defaults ADD COLUMN rndloss_accno_id Integer;
+
<input type="hidden" name="expense_accno_id" value="[% HTML.escape(expense_accno_id) %]">
<input type="hidden" name="fxgain_accno_id" value="[% HTML.escape(fxgain_accno_id) %]">
<input type="hidden" name="fxloss_accno_id" value="[% HTML.escape(fxloss_accno_id) %]">
+<input type="hidden" name="rndgain_accno_id" value="[% HTML.escape(rndgain_accno_id) %]">
+<input type="hidden" name="rndloss_accno_id" value="[% HTML.escape(rndloss_accno_id) %]">
<fieldset>
<legend>
<td>[% L.chart_picker('defaults.fxloss_accno_id', SELF.defaults.fxloss_accno_id, category='E,A', choose=1, style=style) %]<td>
</tr>
+ <tr>
+ <td align="right">[% LxERP.t8("Rounding Gain") %]</td>
+ <td>[% L.chart_picker('defaults.rndgain_accno_id', SELF.defaults.rndgain_accno_id, category='I,A', choose=1, style=style) %]</td>
+ </tr>
+
+ <tr>
+ <td align="right">[% LxERP.t8("Rounding Loss") %]</td>
+ <td>[% L.chart_picker('defaults.rndloss_accno_id', SELF.defaults.rndloss_accno_id, category='E,A', choose=1, style=style) %]</td>
+ </tr>
+
<tr>
<td align="right">[% LxERP.t8("Current assets account") %]</td>
<td>[% L.chart_picker('defaults.ar_paid_accno_id', SELF.defaults.ar_paid_accno_id, type='AR_paid', choose=1, style=style) %]<td>
</tr>
[%- END %]
+[%- IF rounding %]
+ <tr>
+ <th align='right'>[% 'Rounding' | $T8 %]</th>
+ <td align='right'>[% LxERP.format_amount(rounding, 2) %]</td>
+ </tr>
+[%- END %]
+
[%# tax %]
[% FOREACH item = taxaccounts_array %]
[% SET description_ref = item _ '_description' %]
</tr>
[%- END %]
[%- END %]
-
<tr>
<th align="right">[% 'Total' | $T8 %]</th>
<td align="right">[% LxERP.format_amount(invtotal, 2) %]</td>
<td>
<input type="hidden" name="fxgain_accno" value="[% fxgain_accno %]">
<input type="hidden" name="fxloss_accno" value="[% fxloss_accno %]">
+ <input type="hidden" name="rndgain_accno" value="[% rndgain_accno %]">
+ <input type="hidden" name="rndloss_accno" value="[% rndloss_accno %]">
</td>
</tr>
[%- IF show_exchangerate %]
<th align='right'>[% 'Subtotal' | $T8 %]</th>
<td align='right'>[% LxERP.format_amount(invsubtotal, 2) %]</td>
</tr>
+[%- END %]
+[%- IF rounding %]
+ <tr>
+ <th align='right'>[% 'Rounding' | $T8 %]</th>
+ <td align='right'>[% LxERP.format_amount(rounding, 2) %]</td>
+ </tr>
[%- END %]
[% tax %]
<tr>