summaryrefslogtreecommitdiff
path: root/lib/rfq-last/vendor-response/editor/quotation-items-table.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'lib/rfq-last/vendor-response/editor/quotation-items-table.tsx')
-rw-r--r--lib/rfq-last/vendor-response/editor/quotation-items-table.tsx18
1 files changed, 13 insertions, 5 deletions
diff --git a/lib/rfq-last/vendor-response/editor/quotation-items-table.tsx b/lib/rfq-last/vendor-response/editor/quotation-items-table.tsx
index 9f2af046..266ba39b 100644
--- a/lib/rfq-last/vendor-response/editor/quotation-items-table.tsx
+++ b/lib/rfq-last/vendor-response/editor/quotation-items-table.tsx
@@ -32,9 +32,10 @@ import {
interface QuotationItemsTableProps {
prItems: any[]
+ decimalPlaces?: number
}
-export default function QuotationItemsTable({ prItems }: QuotationItemsTableProps) {
+export default function QuotationItemsTable({ prItems, decimalPlaces = 2 }: QuotationItemsTableProps) {
const { control, register, setValue, watch } = useFormContext()
const { fields } = useFieldArray({
control,
@@ -328,7 +329,10 @@ export default function QuotationItemsTable({ prItems }: QuotationItemsTableProp
const unitPriceValue = row.getCell(unitPriceCol).value
const unitPrice = typeof unitPriceValue === 'number' ? unitPriceValue : parseFloat(String(unitPriceValue || 0))
if (!isNaN(unitPrice) && unitPrice >= 0) {
- setValue(`quotationItems.${index}.unitPrice`, Math.floor(unitPrice))
+ const formattedPrice = decimalPlaces === 0
+ ? Math.floor(unitPrice)
+ : parseFloat(unitPrice.toFixed(decimalPlaces))
+ setValue(`quotationItems.${index}.unitPrice`, formattedPrice)
calculateTotal(index)
successCount++
}
@@ -782,15 +786,19 @@ export default function QuotationItemsTable({ prItems }: QuotationItemsTableProp
<Input
type="number"
min="0"
- step="1"
+ step={decimalPlaces === 0 ? "1" : `0.${"1".padStart(decimalPlaces, "0")}`}
{...register(`quotationItems.${index}.unitPrice`, { valueAsNumber: true })}
onChange={(e) => {
- const value = Math.max(0, Math.floor(parseFloat(e.target.value) || 0))
+ const inputValue = parseFloat(e.target.value) || 0
+ const value = Math.max(0, decimalPlaces === 0
+ ? Math.floor(inputValue)
+ : parseFloat(inputValue.toFixed(decimalPlaces))
+ )
setValue(`quotationItems.${index}.unitPrice`, value)
calculateTotal(index)
}}
className="w-[120px]"
- placeholder="0"
+ placeholder={decimalPlaces === 0 ? "0" : `0.${"0".repeat(decimalPlaces)}`}
/>
<span className="text-xs text-muted-foreground">
{currency}