Skip to content

Commit

Permalink
fix: rounded off amount
Browse files Browse the repository at this point in the history
  • Loading branch information
nikhilkuyya committed Dec 17, 2024
1 parent 5737198 commit 78b1599
Showing 1 changed file with 27 additions and 1 deletion.
28 changes: 27 additions & 1 deletion src/components/invoices/InvoiceTotals.vue
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,17 @@
</td>
<td class="currency-readable">{{ taxTotal | dineroCurrency }}</td>
</tr>
<tr class="text-right" v-if="roundedOffAmount !== 0">
<td :colspan="colspan">
Rounded Off
</td>
<td class="currency-readable">{{ roundedOffAmount | dineroCurrency }}</td>
</tr>
<tr class="text-right" v-if="invoice.total">
<th :colspan="colspan" >
{{ $t('total') }}
</th>
<th class="text-nowrap currency-readable">{{ invoice.total | dineroCurrency}}</th>
<th class="text-nowrap currency-readable">{{ roundedTotal | dineroCurrency}}</th>
</tr>
</tfoot>
</template>
Expand All @@ -29,6 +35,7 @@ import { mapGetters } from 'vuex';
import { formatDate } from '../../filters/date.filter';
import { formatCurrency } from '../../filters/currency.filter';
import { formatCurrencyWithDinero } from '../../filters/dineroCurrency.filter';
import Dinero from 'dinero.js';
export default {
Expand All @@ -47,12 +54,31 @@ export default {
taxTotal() {
return Object.values(this.invoice.taxes).reduce((taxTotal, taxObject) => taxTotal + taxObject.total, 0);
},
roundedTotal() {
return this.getValue(this.invoice.total);
},
roundedOffAmount() {
const totalDinero = this.getDinero(this.invoice.total);
const roundedDinero = this.getDinero(this.roundedTotal);
return roundedDinero.subtract(totalDinero).toRoundedUnit(2);
},
colspan() {
// return 5 + this.taxes.length;
return 7;
},
},
methods: {
getDinero(value, factor = 10 ** 2) {
const amount = Number.parseFloat((Number.parseFloat(value).toFixed(2) * factor).toFixed(2));
const dineroObject = Dinero({ amount: amount, currency: 'INR' });
return dineroObject;
},
getValue(newValue, factor = 10 ** 2) {
const amount = Number.parseFloat((Number.parseFloat(newValue).toFixed(2) * factor).toFixed(2));
const dineroObject = Dinero({ amount: amount, currency: 'INR' });
const dineroAmount = dineroObject.toRoundedUnit(0, 'HALF_ODD');
return dineroAmount;
},
updateProp(props) {
this.$emit('update', props);
},
Expand Down

0 comments on commit 78b1599

Please sign in to comment.