Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
- tax computation
  • Loading branch information
Blair2004 committed Aug 12, 2023
1 parent 3373380 commit fefe9fb
Show file tree
Hide file tree
Showing 7 changed files with 687 additions and 710 deletions.
12 changes: 0 additions & 12 deletions app/Settings/pos/vat.php
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,6 @@
];
}

$fields[] = [
'type' => 'select',
'name' => 'ns_pos_tax_compute_group_separately',
'value' => ns()->option->get( 'ns_pos_tax_compute_group_separately', 'no' ),
'options' => Helper::kvToJsOptions([
'yes' => __( 'Yes' ),
'no' => __( 'No' )
]),
'label' => __( 'Tax Group Computing' ),
'description' => __( 'If disabled, the rates are summed and computed. Otherwise it\'s computed separately.' ),
];

return [
'label' => __( 'VAT Settings' ),
'fields' => $fields,
Expand Down
2 changes: 1 addition & 1 deletion public/js/pos-init.min.js

Large diffs are not rendered by default.

1,330 changes: 665 additions & 665 deletions public/js/vendor.js

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions resources/ts/libraries/tax.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@ export default class Tax {
switch ( type ) {
case 'inclusive':
return Tax.computeInclusive( value, rate );
break;
case 'exclusive':
return Tax.computeExclusive( value, rate )
break;
}
}

Expand Down
2 changes: 1 addition & 1 deletion resources/ts/pages/dashboard/pos/ns-pos-cart.vue
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ export default {
POS.refreshCart();
} catch( exception ) {
console.error( exception );
// popup is closed... not needed to log or do anything else
}
},
Expand Down
2 changes: 1 addition & 1 deletion resources/ts/popups/ns-pos-tax-popup.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<ns-tabs-item padding="0" :label="__( 'Summary' )" identifier="summary" :active="false">
<div class="p-2" v-if="order">
<div v-for="tax of order.taxes" :key="tax.id" class="mb-2 border shadow p-2 w-full flex justify-between items-center elevation-surface">
<span>{{ tax.tax_name }}</span>
<span>{{ tax.name }}</span>
<span>{{ tax.tax_value | currency }}</span>
</div>
<div class="p-2 text-center text-primary" v-if="order.taxes.length === 0">{{ __( 'No tax is active' ) }}</div>
Expand Down
47 changes: 19 additions & 28 deletions resources/ts/pos-init.ts
Original file line number Diff line number Diff line change
Expand Up @@ -558,20 +558,9 @@ export class POS {
* order we should then get the real VAT value.
*/
if ( groups[order.tax_group_id] !== undefined ) {
order.taxes = groups[order.tax_group_id].taxes.map(tax => {
/**
* @todo tax should be computed
* on the discounted price
* should deduct "subtotal" with "discount"
*/
tax.tax_value = this.getVatValue(order.subtotal - order.discount, tax.rate, order.tax_type);

return tax;
});
order = this.computeOrderTaxGroup( order, groups[order.tax_group_id] );
}

order = this.computeOrderTaxes( order );

return resolve({
status: 'success',
data: { tax: groups[order.tax_group_id], order }
Expand Down Expand Up @@ -604,15 +593,23 @@ export class POS {

computeOrderTaxGroup( order, tax ) {

const posVat = this.options.getValue().ns_pos_vat;
const priceWithTax = this.options.getValue().ns_pos_price_with_tax === 'yes';
const posVat = this.options.getValue().ns_pos_vat;
const priceWithTax = this.options.getValue().ns_pos_price_with_tax === 'yes';
const summarizedRates = <number>tax.taxes.map( tax => parseFloat( tax.rate ) ).reduce( ( b, a ) => b + a );
const currentVatValue = this.getVatValue( order.subtotal - order.discount, summarizedRates, order.tax_type );

tax.taxes = tax.taxes.map( _tax => {
const currentPercentage = math.chain(
math.chain( _tax.rate ).divide( summarizedRates ).done()
).multiply( 100 ).done();

tax.taxes = tax.taxes.map(_tax => {
return {
tax_id: _tax.id,
tax_name: _tax.name,
id: _tax.id,
name: _tax.name,
rate: parseFloat(_tax.rate),
tax_value: this.getVatValue(order.subtotal - order.discount, _tax.rate, order.tax_type)
tax_value: math.chain(
math.chain( currentVatValue ).multiply( currentPercentage ).done()
).divide(100).done()
};
});

Expand Down Expand Up @@ -1645,16 +1642,13 @@ export class POS {
}

computeNormalProductTax( product: OrderProduct ) {
const originalProduct = product.$original();
const quantities = product.$quantities();
const result = this.proceedProductTaxComputation( product, quantities.sale_price_edit );

quantities.sale_price_without_tax = result.price_without_tax;
quantities.sale_price_with_tax = result.price_with_tax;
quantities.sale_price_without_tax = result.price_without_tax;
quantities.sale_price_with_tax = result.price_with_tax;
quantities.sale_price_tax = result.tax_value;

console.log({ quantities });

product.$quantities = () => {
return <ProductUnitQuantity>quantities
}
Expand All @@ -1663,12 +1657,11 @@ export class POS {
}

computeWholesaleProductTax( product: OrderProduct ) {
const originalProduct = product.$original();
const quantities = product.$quantities();
const result = this.proceedProductTaxComputation( product, quantities.wholesale_price_edit );

quantities.wholesale_price_without_tax = result.price_without_tax;
quantities.wholesale_price_with_tax = result.price_with_tax;
quantities.wholesale_price_without_tax = result.price_without_tax;
quantities.wholesale_price_with_tax = result.price_with_tax;
quantities.wholesale_price_tax = result.tax_value;

product.$quantities = () => {
Expand Down Expand Up @@ -1755,8 +1748,6 @@ export class POS {
math.chain( price_without_tax ).multiply( product.quantity ).done()
).subtract( discount_without_tax ).done();

console.log( product );

nsHooks.doAction('ns-after-product-computed', product);
}

Expand Down

0 comments on commit fefe9fb

Please sign in to comment.