fix floating errors

This commit is contained in:
Mohit Panjwani
2020-12-31 12:16:04 +05:30
parent 0f1d7627ea
commit b55f8e5391
11 changed files with 498 additions and 466 deletions

View File

@ -43,7 +43,7 @@
:options="itemUnits"
:searchable="true"
:show-labels="false"
:maxHeight="200"
:max-height="200"
label="name"
>
</sw-select>
@ -160,7 +160,7 @@ export default {
return this.formData.price / 100
},
set: function (newValue) {
this.formData.price = newValue * 100
this.formData.price = Math.round(newValue * 100)
},
},

View File

@ -73,7 +73,7 @@ export default {
callbacks: {
label: function (tooltipItem, data) {
return self.FormatGraphMoney(
tooltipItem.value * 100,
Math.round(tooltipItem.value * 100),
self.defaultCurrency
)
},

View File

@ -7,23 +7,23 @@
<sw-page-header :title="pageTitle">
<sw-breadcrumb slot="breadcrumbs">
<sw-breadcrumb-item
to="/admin/dashboard"
:title="$t('general.home')"
to="/admin/dashboard"
/>
<sw-breadcrumb-item
to="/admin/estimates"
:title="$tc('estimates.estimate', 2)"
to="/admin/estimates"
/>
<sw-breadcrumb-item
v-if="$route.name === 'estimates.edit'"
to="#"
:title="$t('estimates.edit_estimate')"
to="#"
active
/>
<sw-breadcrumb-item
v-else
to="#"
:title="$t('estimates.new_estimate')"
to="#"
active
/>
</sw-breadcrumb>
@ -31,8 +31,8 @@
<template slot="actions">
<sw-button
v-if="$route.name === 'estimates.edit'"
tag-name="a"
:href="`/estimates/pdf/${newEstimate.unique_hash}`"
tag-name="a"
target="_blank"
class="mr-3"
variant="primary-outline"
@ -59,9 +59,9 @@
<!-- Select Customer & Basic Fields -->
<div class="grid-cols-12 gap-8 mt-6 mb-8 lg:grid">
<customer-select
class="col-span-5 pr-0"
:valid="$v.selectedCustomer"
:customer-id="customerId"
class="col-span-5 pr-0"
/>
<div
@ -235,8 +235,8 @@
</div>
<div
class="grid gap-x-4 gap-y-2 md:gap-x-8 md:gap-y-4 grid-col-1 md:grid-cols-2"
v-if="customFields.length > 0"
class="grid gap-x-4 gap-y-2 md:gap-x-8 md:gap-y-4 grid-col-1 md:grid-cols-2"
>
<sw-input-group
v-for="(field, index) in customFields"
@ -247,7 +247,7 @@
<component
:type="field.type.label"
:field="field"
:isEdit="isEdit"
:is-edit="isEdit"
:is="field.type + 'Field'"
:invalid-fields="invalidFields"
@update="setCustomFieldValue"
@ -366,8 +366,8 @@
</div>
<sw-popup
ref="taxModal"
v-if="taxPerItem === 'NO' || taxPerItem === null"
ref="taxModal"
class="my-3 text-sm font-semibold leading-5 text-primary-400"
>
<div slot="activator" class="float-right pt-2 pb-4">
@ -425,8 +425,6 @@ const {
} = require('vuelidate/lib/validators')
export default {
mixins: [CustomFieldsMixin],
components: {
EstimateItem,
CustomerSelect,
@ -438,6 +436,7 @@ export default {
PlusSmIcon,
HashtagIcon,
},
mixins: [CustomFieldsMixin],
data() {
return {
@ -563,7 +562,7 @@ export default {
if (this.newEstimate.discount_type === 'percentage') {
this.newEstimate.discount_val = (this.subtotal * newValue) / 100
} else {
this.newEstimate.discount_val = newValue * 100
this.newEstimate.discount_val = Math.round(newValue * 100)
}
this.newEstimate.discount = newValue
@ -727,7 +726,9 @@ export default {
return
}
this.newEstimate.discount_val = this.newEstimate.discount * 100
this.newEstimate.discount_val = Math.round(
this.newEstimate.discount * 100
)
this.newEstimate.discount_type = 'fixed'
},

View File

@ -256,7 +256,7 @@ export default {
if (this.item.discount_type === 'percentage') {
this.item.discount_val = (this.subtotal * newValue) / 100
} else {
this.item.discount_val = newValue * 100
this.item.discount_val = Math.round(newValue * 100)
}
this.item.discount = newValue
@ -296,7 +296,7 @@ export default {
},
set: function (newValue) {
if (parseFloat(newValue) > 0) {
this.item.price = (newValue * 100).toFixed(2)
this.item.price = Math.round(newValue * 100)
this.maxDiscount = this.item.price
} else {
this.item.price = newValue
@ -411,7 +411,7 @@ export default {
return
}
this.item.discount_val = this.item.discount * 100
this.item.discount_val = Math.round(this.item.discount * 100)
this.item.discount_type = 'fixed'
},
selectPercentage() {

View File

@ -2,29 +2,29 @@
<base-page class="relative">
<form action="" @submit.prevent="sendData">
<!-- Page Header -->
<sw-page-header class="mb-5" :title="pageTitle">
<sw-page-header :title="pageTitle" class="mb-5">
<sw-breadcrumb slot="breadcrumbs">
<sw-breadcrumb-item
to="/admin/dashboard"
:title="$t('general.home')"
to="/admin/dashboard"
/>
<sw-breadcrumb-item
to="/admin/expenses"
:title="$tc('expenses.expense', 2)"
to="/admin/expenses"
/>
<sw-breadcrumb-item
v-if="$route.name === 'expenses.edit'"
to="#"
:title="$t('expenses.edit_expense')"
to="#"
active
/>
<sw-breadcrumb-item
v-else
to="#"
:title="$t('expenses.new_expense')"
to="#"
active
/>
</sw-breadcrumb>
@ -32,8 +32,8 @@
<template slot="actions">
<sw-button
v-if="isReceiptAvailable"
tag-name="a"
:href="getReceiptUrl"
tag-name="a"
variant="primary"
outline
size="lg"
@ -122,8 +122,8 @@
<sw-money
v-model="amount"
:currency="defaultCurrencyForInput"
class="focus:border focus:border-solid focus:border-primary-500"
:invalid="$v.formData.amount.$error"
class="focus:border focus:border-solid focus:border-primary-500"
@input="$v.formData.amount.$touch()"
/>
</sw-input-group>
@ -176,9 +176,9 @@
</div>
<sw-avatar
trigger="#receipt-box"
:preview-avatar="previewReceipt"
:enable-cropper="false"
trigger="#receipt-box"
@changed="onChange"
>
<template v-slot:icon>
@ -201,7 +201,7 @@
<component
:type="field.type.label"
:field="field"
:isEdit="isEdit"
:is-edit="isEdit"
:is="field.type + 'Field'"
:invalid-fields="invalidFields"
@update="setCustomFieldValue"
@ -242,13 +242,12 @@ import { CloudUploadIcon, ShoppingCartIcon } from '@vue-hero-icons/solid'
import CustomFieldsMixin from '../../mixins/customFields'
export default {
mixins: [CustomFieldsMixin],
components: {
CloudUploadIcon,
ShoppingCartIcon,
DownloadIcon,
},
mixins: [CustomFieldsMixin],
props: {
addname: {
@ -315,7 +314,7 @@ export default {
return this.formData.amount / 100
},
set: function (newValue) {
this.formData.amount = newValue * 100
this.formData.amount = Math.round(newValue * 100)
},
},

View File

@ -7,23 +7,23 @@
<sw-page-header :title="pageTitle">
<sw-breadcrumb slot="breadcrumbs">
<sw-breadcrumb-item
to="/admin/dashboard"
:title="$t('general.home')"
to="/admin/dashboard"
/>
<sw-breadcrumb-item
to="/admin/invoices"
:title="$tc('invoices.invoice', 2)"
to="/admin/invoices"
/>
<sw-breadcrumb-item
v-if="$route.name === 'invoice.edit'"
to="#"
:title="$t('invoices.edit_invoice')"
to="#"
active
/>
<sw-breadcrumb-item
v-else
to="#"
:title="$t('invoices.new_invoice')"
to="#"
active
/>
</sw-breadcrumb>
@ -32,8 +32,8 @@
<sw-button
v-if="$route.name === 'invoices.edit'"
:disabled="isLoading"
tag-name="a"
:href="`/invoices/pdf/${newInvoice.unique_hash}`"
tag-name="a"
variant="primary-outline"
class="mr-3"
target="_blank"
@ -58,9 +58,9 @@
<!-- Select Customer & Basic Fields -->
<div class="grid-cols-12 gap-8 mt-6 mb-8 lg:grid">
<customer-select
class="col-span-5 pr-0"
:valid="$v.selectedCustomer"
:customer-id="customerId"
class="col-span-5 pr-0"
/>
<div
@ -227,8 +227,8 @@
</div>
<div
class="grid gap-x-4 gap-y-2 md:gap-x-8 md:gap-y-4 grid-col-1 md:grid-cols-2"
v-if="customFields.length > 0"
class="grid gap-x-4 gap-y-2 md:gap-x-8 md:gap-y-4 grid-col-1 md:grid-cols-2"
>
<sw-input-group
v-for="(field, index) in customFields"
@ -239,7 +239,7 @@
<component
:type="field.type.label"
:field="field"
:isEdit="isEdit"
:is-edit="isEdit"
:is="field.type + 'Field'"
:invalid-fields="invalidFields"
@update="setCustomFieldValue"
@ -418,8 +418,6 @@ const {
} = require('vuelidate/lib/validators')
export default {
mixins: [CustomFieldsMixin],
components: {
InvoiceItem,
CustomerSelect,
@ -431,6 +429,7 @@ export default {
ShoppingCartIcon,
HashtagIcon,
},
mixins: [CustomFieldsMixin],
data() {
return {
@ -558,7 +557,7 @@ export default {
if (this.newInvoice.discount_type === 'percentage') {
this.newInvoice.discount_val = (this.subtotal * newValue) / 100
} else {
this.newInvoice.discount_val = newValue * 100
this.newInvoice.discount_val = Math.round(newValue * 100)
}
this.newInvoice.discount = newValue
@ -722,7 +721,7 @@ export default {
return
}
this.newInvoice.discount_val = this.newInvoice.discount * 100
this.newInvoice.discount_val = Math.round(this.newInvoice.discount * 100)
this.newInvoice.discount_type = 'fixed'
},

View File

@ -256,7 +256,7 @@ export default {
if (this.item.discount_type === 'percentage') {
this.item.discount_val = (this.subtotal * newValue) / 100
} else {
this.item.discount_val = newValue * 100
this.item.discount_val = Math.round(newValue * 100)
}
this.item.discount = newValue
@ -296,7 +296,7 @@ export default {
},
set: function (newValue) {
if (parseFloat(newValue) > 0) {
this.item.price = (newValue * 100).toFixed(2)
this.item.price = Math.round(newValue * 100)
this.maxDiscount = this.item.price
} else {
this.item.price = newValue
@ -412,7 +412,7 @@ export default {
return
}
this.item.discount_val = this.item.discount * 100
this.item.discount_val = Math.round(this.item.discount * 100)
this.item.discount_type = 'fixed'
},
selectPercentage() {

View File

@ -1,20 +1,20 @@
<template>
<base-page>
<!-- Page Header -->
<sw-page-header class="mb-3" :title="pageTitle">
<sw-page-header :title="pageTitle" class="mb-3">
<sw-breadcrumb slot="breadcrumbs">
<sw-breadcrumb-item to="/admin/dashboard" :title="$t('general.home')" />
<sw-breadcrumb-item to="/admin/items" :title="$tc('items.item', 2)" />
<sw-breadcrumb-item :title="$t('general.home')" to="/admin/dashboard" />
<sw-breadcrumb-item :title="$tc('items.item', 2)" to="/admin/items" />
<sw-breadcrumb-item
v-if="$route.name === 'items.edit'"
to="#"
:title="$t('items.edit_item')"
to="#"
active
/>
<sw-breadcrumb-item
v-else
to="#"
:title="$t('items.new_item')"
to="#"
active
/>
</sw-breadcrumb>
@ -59,11 +59,11 @@
<sw-input-group :label="$t('items.unit')" class="mb-4">
<sw-select
v-model="formData.unit"
class="mt-2"
:options="itemUnits"
:searchable="true"
:show-labels="false"
:placeholder="$t('items.select_a_unit')"
class="mt-2"
label="name"
>
<div
@ -89,12 +89,12 @@
>
<sw-select
v-model="formData.taxes"
class="mt-2"
:options="getTaxTypes"
:searchable="true"
:show-labels="false"
:allow-empty="true"
:multiple="true"
class="mt-2"
track-by="tax_type_id"
label="tax_name"
/>
@ -187,7 +187,7 @@ export default {
return this.formData.price / 100
},
set: function (newValue) {
this.formData.price = newValue * 100
this.formData.price = Math.round(newValue * 100)
},
},

View File

@ -2,8 +2,8 @@
<base-page>
<sw-page-header :title="$t('items.title')">
<sw-breadcrumb slot="breadcrumbs">
<sw-breadcrumb-item to="dashboard" :title="$t('general.home')" />
<sw-breadcrumb-item to="#" :title="$tc('items.item', 2)" active />
<sw-breadcrumb-item :title="$t('general.home')" to="dashboard" />
<sw-breadcrumb-item :title="$tc('items.item', 2)" to="#" active />
</sw-breadcrumb>
<template slot="actions">
@ -50,9 +50,9 @@
v-model="filters.unit"
:options="itemUnits"
:searchable="true"
class="mt-2"
:show-labels="false"
:placeholder="$t('items.select_a_unit')"
class="mt-2"
label="name"
autocomplete="off"
/>
@ -225,8 +225,8 @@
<dot-icon slot="activator" />
<sw-dropdown-item
tag-name="router-link"
:to="`items/${row.id}/edit`"
tag-name="router-link"
>
<pencil-icon class="h-5 mr-3 text-gray-600" />
{{ $t('general.edit') }}
@ -356,7 +356,7 @@ export default {
let data = {
search: this.filters.name !== null ? this.filters.name : '',
unit_id: this.filters.unit !== null ? this.filters.unit.id : '',
price: this.filters.price * 100,
price: Math.round(this.filters.price * 100),
orderByField: sort.fieldName || 'created_at',
orderBy: sort.order || 'desc',
page,

View File

@ -1,26 +1,26 @@
<template>
<base-page class="relative payment-create">
<form action="" @submit.prevent="submitPaymentData">
<sw-page-header class="mb-5" :title="pageTitle">
<sw-page-header :title="pageTitle" class="mb-5">
<sw-breadcrumb slot="breadcrumbs">
<sw-breadcrumb-item
to="/admin/dashboard"
:title="$t('general.home')"
to="/admin/dashboard"
/>
<sw-breadcrumb-item
to="/admin/payments"
:title="$tc('payments.payment', 2)"
to="/admin/payments"
/>
<sw-breadcrumb-item
v-if="$route.name === 'payments.edit'"
to="#"
:title="$t('payments.edit_payment')"
to="#"
active
/>
<sw-breadcrumb-item
v-else
to="#"
:title="$t('payments.new_payment')"
to="#"
active
/>
</sw-breadcrumb>
@ -134,8 +134,8 @@
:searchable="true"
:show-labels="false"
:placeholder="$t('payments.select_payment_mode')"
:max-height="150"
label="name"
:maxHeight="150"
class="mt-1"
>
<div slot="afterList">
@ -165,7 +165,7 @@
<component
:type="field.type.label"
:field="field"
:isEdit="isEdit"
:is-edit="isEdit"
:is="field.type + 'Field'"
:invalid-fields="invalidFields"
@update="setCustomFieldValue"
@ -218,9 +218,8 @@ import CustomFieldsMixin from '../../mixins/customFields'
const { required, between, numeric } = require('vuelidate/lib/validators')
export default {
mixins: [CustomFieldsMixin],
components: { ShoppingCartIcon },
mixins: [CustomFieldsMixin],
data() {
return {
@ -288,7 +287,7 @@ export default {
return this.formData.amount / 100
},
set: function (newValue) {
this.formData.amount = (newValue * 100).toFixed(2)
this.formData.amount = Math.round(newValue * 100)
},
},
pageTitle() {
@ -552,9 +551,11 @@ export default {
},
id: this.$route.params.id,
}
try {
this.isLoading = true
let response = await this.updatePayment(data)
if (response.data.success) {
this.isLoading = false
this.$router.push(
@ -563,17 +564,21 @@ export default {
window.toastr['success'](this.$t('payments.updated_message'))
return true
}
if (response.data.error === 'invalid_amount') {
window.toastr['error'](this.$t('invalid_amount_message'))
return false
}
window.toastr['error'](response.data.error)
} catch (err) {
this.isLoading = false
if (err.response.data.errors.payment_number) {
window.toastr['error'](err.response.data.errors.payment_number)
return true
}
window.toastr['error'](err.response.data.message)
}
} else {
@ -584,9 +589,12 @@ export default {
: null,
payment_date: moment(this.formData.payment_date).format('YYYY-MM-DD'),
}
this.isLoading = true
try {
let response = await this.addPayment(data)
if (response.data.success) {
this.$router.push(
`/admin/payments/${response.data.payment.id}/view`
@ -595,17 +603,21 @@ export default {
this.isLoading = true
return true
}
if (response.data.error === 'invalid_amount') {
window.toastr['error'](this.$t('invalid_amount_message'))
return false
}
window.toastr['error'](response.data.error)
} catch (err) {
this.isLoading = false
if (err.response.data.errors.payment_number) {
window.toastr['error'](err.response.data.errors.payment_number)
return true
}
window.toastr['error'](err.response.data.message)
}
}

815
yarn.lock

File diff suppressed because it is too large Load Diff