견적서 pkgAsp

This commit is contained in:
basssy 2024-12-07 07:01:24 +09:00
parent b2293962c5
commit 655b8f29cd

View File

@ -493,19 +493,37 @@ export default function Estimate({ params }) {
setSelection(newSelection)
}
function formatNumberWithComma(number) {
return number.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ',')
}
//PKG input
const onChangePkgAsp = (value) => {
if (estimateContextState.estimateType === 'YJSS') {
let pkgAsp = Number(value.replace(/[^-\.0-9]/g, '').replaceAll(',', ''))
if (isNaN(pkgAsp)) {
pkgAsp = 0
} else {
pkgAsp = pkgAsp.toLocaleString()
let newValue = value.replace(/[^0-9.]/g, '')
if (newValue.length > 1) {
newValue = newValue.replace(/(^0+)/, '')
if (newValue.length === 0) {
newValue = '0'
}
}
// PKG
const parts = newValue.split('.')
if (parts.length > 2) {
newValue = parts[0] + '.' + parts.slice(1).join('')
}
if (parts[1] && parts[1].length > 2) {
newValue = parts[0] + '.' + parts[1].substring(0, 2)
}
let pkgAsp = newValue || '0'
// PKG
let totVolKw = estimateContextState.totVolKw * 1000
let pkgTotPrice = pkgAsp?.replaceAll(',', '') * totVolKw * 1000
let pkgTotPrice = parseFloat(pkgAsp?.replaceAll(',', '')) * totVolKw * 1000
// pkgAsp = formatNumberWithComma(parseFloat(pkgAsp).toFixed(2))
setEstimateContextState({
pkgAsp: pkgAsp,