add ProductStockPackageSummary.vue

This commit is contained in:
Timi
2026-10-05 16:11:24 +08:00
parent f643656eb4
commit 58d99e52c5
3 changed files with 103 additions and 0 deletions
+23
View File
@@ -100,6 +100,29 @@ export function convertBaseQuantityToPackageQuantity(baseQuantity: number | stri
return formatDecimal(rounded, 3, 3);
}
/** 将非负基础数量精确拆分为整包装和基础单位余数,不对余数取整。 */
export function splitBaseQuantityIntoPackages(baseQuantity: number | string, baseQuantityPerUnit: number | string): { whole: string; remainder: string } | undefined {
const quantityParts = toDecimalParts(baseQuantity, 3);
const unitParts = toDecimalParts(baseQuantityPerUnit, 6);
if (!quantityParts || !unitParts) {
return undefined;
}
const scale = Math.max(quantityParts.scale, unitParts.scale);
const factor = 10n ** BigInt(scale);
const quantity = quantityParts.value * 10n ** BigInt(scale - quantityParts.scale);
const unit = unitParts.value * 10n ** BigInt(scale - unitParts.scale);
if (unit <= factor) {
return undefined;
}
const remainder = quantity % unit;
const integer = (remainder / factor).toString();
const fraction = (remainder % factor).toString().padStart(scale, "0").replace(/0+$/, "");
return {
whole: (quantity / unit).toString(),
remainder: fraction ? `${integer}.${fraction}` : integer
};
}
/** 精确相加两个最多三位小数的数量。 */
export function addPackageQuantity(left: number | string, right: number | string): string | undefined {
const leftParts = toQuantityParts(left);