Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Changelog
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ Added functionalities
* Localization of names in the country selection drop-down (#8749)
* Improved on-boarding experience with new installer supporting more platforms
to handle dependencies than previous methods; see https://get.ledgersmb.org
* Ability to manually enter taxes on orders and quotes

Changed functionalities
* Concurrent logins with different users on one browser throw an error (#8496)
* Confusing menu name 'Add Contact' changed to 'Add entity' (#8003)
* Split toplevel Reports menu over General Journal and Goods & Services (#8850)
* Menu reloaded from file (./locale/menu.xml) on each upgrade (#8876)
* Taxes on orders and quotes no longer recalculated; saved as manual

Removed functionalities

Expand Down
90 changes: 85 additions & 5 deletions old/bin/oe.pl
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,26 @@ sub form_header {
}

sub form_footer {
my $checked0;
my $checked1;
if ($form->{manual_tax}){
$checked1=qq|checked="CHECKED"|;
$checked0="";
} else {
$checked0=qq|checked="CHECKED"|;
$checked1="";
}
my $manual_tax =
qq|<label for="manual-tax-0">|.
$locale->text("Automatic")
. qq|</label>
<input type="radio" data-dojo-type="dijit/form/RadioButton" name="manual_tax" value="0"
id="manual-tax-0" $checked0 $readonly />
<label for="manual-tax-1">|.
$locale->text("Manual")
. qq|</label>
<input type="radio" data-dojo-type="dijit/form/RadioButton" name="manual_tax" value="1"
id="manual-tax-1" $checked1 $readonly >|;
_calc_taxes();

$form->{invtotal} = $form->{invsubtotal};
Expand Down Expand Up @@ -747,20 +767,76 @@ sub form_footer {

$form->{_setting_decimal_places} = $form->get_setting('decimal_places');
if ( !$form->{taxincluded} ) {
if ($form->{manual_tax}){
$tax .= qq|<tr class="listtop">
<td>&nbsp</td>
<th align="center">|.$locale->text('Amount').qq| ($form->{currency})</th>
<th align="center">|.$locale->text('Rate').qq|</th>
<th align="center">|.$locale->text('Basis').qq| ($form->{currency})</th>
<th align="center">|.$locale->text('Tax Code').qq|</th>
<!-- We dont have a database field to bind the memo to; comment it: <th align="center">|.$locale->text('Memo').qq|</th>-->
</tr>|;
}
foreach my $item (keys %{$form->{taxes}}) {
my $taccno = $item;
$form->{invtotal} += $form->round_amount($form->{taxes}{$item}, 2);
if ($form->{manual_tax}){
# Setting defaults from tax calculations
# These are set in io.pl sub _calc_taxes --CT
if ($form->{"mt_rate_$item"} eq '' or
!defined $form->{"mt_rate_$item"}){
$form->{"mt_rate_$item"} = $form->{tax_obj}{$item}->rate;
}
if ($form->{"mt_basis_$item"} eq '' or
!defined $form->{"mt_basis_$item"}){
$form->{"mt_basis_$item"} = $form->{taxbasis}{$item};
}
if ($form->{"mt_amount_$item"} eq '' or
!defined $form->{"mt_amount_$item"}){
$form->{"mt_amount_$item"} =
$form->{"mt_rate_$item"}
* ($form->{"mt_basis_$item"} // 0);
}
$form->{invtotal} += $form->round_amount(
$form->parse_amount( \%myconfig, $form->{"mt_amount_$item"}), 2);
# Setting this up as a table
# Note that the screens may be not wide enough to display
# this in the normal way so we have to change the layout of the
# notes fields. --CT
$tax .= qq|<tr class="invoice-manual-tax">
<th align=right>$form->{"${taccno}_description"}</th>
<td><input data-dojo-type="dijit/form/TextBox" type="text" name="mt_amount_$item"
id="mt-amount-$item" value="|
.$form->format_amount(\%myconfig, $form->{"mt_amount_$item"}, $form->{_setting_decimal_places} )
.qq|" size="10" $readonly /></td>
<td><input data-dojo-type="dijit/form/TextBox" type="text" name="mt_rate_$item"
id="mt-rate-$item" value="|
.$form->format_amount(\%myconfig, $form->{"mt_rate_$item"})
.qq|" size="4" $readonly /></td>
<td><input data-dojo-type="dijit/form/TextBox" type="text" name="mt_basis_$item"
id="mt-basis-$item" value="|
.$form->format_amount(\%myconfig, $form->{"mt_basis_$item"}, $form->{_setting_decimal_places} )
.qq|" size="10" $readonly /></td>
<td><input data-dojo-type="dijit/form/TextBox" type="text" name="mt_ref_$item"
id="mt-ref-$item" value="|
. $form->{"mt_ref_$item"} .qq|" size="10" $readonly /></td>
<!--<td><input data-dojo-type="dijit/form/TextBox" type="text" name="mt_memo_$item"
id="mt-memo-$item" value="|
.$form->{"mt_memo_$item"} .qq|" size="10" $readonly /></td>-->
</tr>|;
} else {
$form->{invtotal} += $form->round_amount($form->{taxes}{$item}, 2);
$form->{"${taccno}_total"} = $form->format_amount(
\%myconfig,
$form->round_amount( $form->{taxes}{$item}, 2 ),
$form->{_setting_decimal_places}
);
next if !$form->{"${taccno}_total"};
$tax .= qq|
<tr>
<th align="right">$form->{"${taccno}_description"}</th>
<td align="right">$form->{"${taccno}_total"}</td>
</tr>|;
<tr>
<th align="right">$form->{"${taccno}_description"}</th>
<td align="right">$form->{"${taccno}_total"}</td>
</tr>|;
}
}

$form->{invsubtotal} =
Expand Down Expand Up @@ -802,6 +878,10 @@ sub form_footer {
<td align=right>
<table>
$subtotal
<tr>
<th>| . $locale->text('Calculate taxes') . qq|</th>
<td>$manual_tax</td>
</tr>
$tax
<tr>
<th align=right>| . $locale->text('Total') . qq|</th>
Expand Down
142 changes: 91 additions & 51 deletions old/lib/LedgerSMB/OE.pm
Original file line number Diff line number Diff line change
Expand Up @@ -298,47 +298,49 @@ sub save {
$form->round_amount( $form->{"sellprice_$i"} * $form->{"qty_$i"},
2 );

@taxaccounts = Tax::init_taxes( $form, $form->{"taxaccounts_$i"},
$form->{taxaccounts} );
if ( $form->{taxincluded} ) {
$taxamount =
Tax::calculate_taxes( \@taxaccounts, $form, $linetotal, 1 );
$form->{"sellprice_$i"} =
Tax::extract_taxes( \@taxaccounts, $form,
$form->{"sellprice_$i"} );
$taxbase =
Tax::extract_taxes( \@taxaccounts, $form, $linetotal );
}
else {
$taxamount =
Tax::apply_taxes( \@taxaccounts, $form, $linetotal );
$taxbase = $linetotal;
}

if ( @taxaccounts && $form->round_amount( $taxamount, 2 ) == 0 ) {
if (!$form->{manual_tax}){
@taxaccounts = Tax::init_taxes( $form, $form->{"taxaccounts_$i"},
$form->{taxaccounts} );
if ( $form->{taxincluded} ) {
foreach my $item (@taxaccounts) {
$taxamount = $form->round_amount( $item->value, 2 );
$taxaccounts{ $item->account } += $taxamount;
$taxdiff += $taxamount;
$taxbase{ $item->account } += $taxbase;
$taxamount =
Tax::calculate_taxes( \@taxaccounts, $form, $linetotal, 1 );
$form->{"sellprice_$i"} =
Tax::extract_taxes( \@taxaccounts, $form,
$form->{"sellprice_$i"} );
$taxbase =
Tax::extract_taxes( \@taxaccounts, $form, $linetotal );
}
else {
$taxamount =
Tax::apply_taxes( \@taxaccounts, $form, $linetotal );
$taxbase = $linetotal;
}

if ( @taxaccounts && $form->round_amount( $taxamount, 2 ) == 0 ) {
if ( $form->{taxincluded} ) {
foreach my $item (@taxaccounts) {
$taxamount = $form->round_amount( $item->value, 2 );
$taxaccounts{ $item->account } += $taxamount;
$taxdiff += $taxamount;
$taxbase{ $item->account } += $taxbase;
}
$taxaccounts{ $taxaccounts[0]->account } += $taxdiff;
}
else {
foreach my $item (@taxaccounts) {
$taxaccounts{ $item->account } += $item->value;
$taxbase{ $item->account } += $taxbase;
}
}
$taxaccounts{ $taxaccounts[0]->account } += $taxdiff;
}
else {
foreach my $item (@taxaccounts) {
$taxaccounts{ $item->account } += $item->value;
$taxbase{ $item->account } += $taxbase;
}
}
push @all_taxes, @taxaccounts;
}
else {
foreach my $item (@taxaccounts) {
$taxaccounts{ $item->account } += $item->value;
$taxbase{ $item->account } += $taxbase;
}
}
push @all_taxes, @taxaccounts;

$netamount += $form->{"sellprice_$i"} * $form->{"qty_$i"};

Expand Down Expand Up @@ -391,34 +393,56 @@ sub save {
$form->{$_} *= 1;
}

# add up the tax
my $tax = 0;
for ( keys %taxaccounts ) { $tax += $taxaccounts{$_} }
if (!$form->{manual_tax}) {
# add up the tax
my $tax = 0;
for ( keys %taxaccounts ) { $tax += $taxaccounts{$_} }

$amount = $form->round_amount( $netamount + $tax, 2 );
$netamount = $form->round_amount( $netamount, 2 );
$amount = $form->round_amount( $netamount + $tax, 2 );
$netamount = $form->round_amount( $netamount, 2 );

if (@all_taxes) {
my (%taxes, %bases, %rates);
my $query = q|
if (@all_taxes) {
my (%taxes, %bases, %rates);
my $query = q|
INSERT INTO oe_tax (oe_id, tax_id, basis, rate, amount)
VALUES (?, (select id from account where accno = ?), ?, ?, ?)
|;
my $sth = $dbh->prepare($query)
or $form->dberror($query);
for my $tax (@all_taxes) {
$taxes{ $tax->account } //= 0;
$taxes{ $tax->account } += $tax->value;
$rates{ $tax->account } = $tax->rate;
$bases{ $tax->account } //= 0;
$bases{ $tax->account } += $tax->base;
}

for my $tax (keys %taxes) {
$sth->execute( $form->{id}, $tax,
$bases{$tax}, $rates{$tax}, $taxes{$tax})
or $form->dberror($query);
}
}
}
else {
my $query = q|
INSERT INTO oe_tax (oe_id, tax_id, basis, rate, source, amount)
VALUES (?, (select id from account where accno = ?), ?, ?, ?, ?)
|;
my $sth = $dbh->prepare($query)
or $form->dberror($query);
for my $tax (@all_taxes) {
$taxes{ $tax->account } //= 0;
$taxes{ $tax->account } += $tax->value;
$rates{ $tax->account } = $tax->rate;
$bases{ $tax->account } //= 0;
$bases{ $tax->account } += $tax->base;
for my $taccno (split / /, $form->{taxaccounts}){
my $taxamount = $form->parse_amount($myconfig,
$form->{"mt_amount_$taccno"});
my $taxbasis = $form->parse_amount($myconfig,
$form->{"mt_basis_$taccno"});
my $taxrate = $form->parse_amount($myconfig,$form->{"mt_rate_$taccno"});
my $source = $form->{"mt_ref_$taccno"};
$sth->execute( $form->{id}, $taccno, $taxbasis, $taxrate, $source, $taxamount )
or $form->dberror($sth->errstr);
}

for my $tax (keys %taxes) {
$sth->execute( $form->{id}, $tax,
$bases{$tax}, $rates{$tax}, $taxes{$tax})
or $form->dberror($query);
}
$sth->finish;
}
if ( $form->{currency} eq $form->{defaultcurrency} ) {
$form->{exchangerate} = 1;
Expand Down Expand Up @@ -640,7 +664,7 @@ sub retrieve {
AND t.language_code = ?)
WHERE o.trans_id = ?
ORDER BY o.id|;
$sth = $dbh->prepare($query);
$sth = $dbh->prepare($query) || $form->dberror($query);
# The use of vendor_id below helps ensure that partsvendor drops out
# for sales orders. --CT
$sth->execute( $form->{vendor_id}, $form->{language_code}, $form->{id} )
Expand Down Expand Up @@ -711,6 +735,22 @@ sub retrieve {
}
$sth->finish;


# get manual taxes
$query = 'SELECT * FROM oe_tax JOIN account ON oe_tax.tax_id = account.id WHERE oe_id = ?';
$sth = $dbh->prepare( $query ) || $form->dberror( $query );

$sth->execute( $form->{id} ) || $form->dberror( $sth->errstr );
while (my $ref = $sth->fetchrow_hashref('NAME_lc')) {
$form->{manual_tax} = 1;

my $taccno = $ref->{accno};
$form->{"mt_amount_$taccno"} = $ref->{amount};
$form->{"mt_basis_$taccno"} = $ref->{basis};
$form->{"mt_rate_$taccno"} = $ref->{rate};
$form->{"mt_ref_$taccno"} = $ref->{source};
}

# get recurring transaction
$form->get_recurring;
}
Expand Down
Loading