gaoluyang
19 小时以前 3ab45f295fb26c7794b4829976f3fb20c68a012e
新疆海川开心
1.采购模块的计算都改为保留三位小数并且不四舍五入
已修改10个文件
171 ■■■■■ 文件已修改
src/utils/index.js 38 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/summarizeTable.js 6 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/procurementManagement/invoiceEntry/components/ExpandTable.vue 13 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/procurementManagement/invoiceEntry/components/Modal.vue 31 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/procurementManagement/invoiceEntry/index.vue 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/procurementManagement/paymentEntry/index.vue 12 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/procurementManagement/paymentHistory/index.vue 3 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/procurementManagement/procurementInvoiceLedger/Form/EditForm.vue 14 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/procurementManagement/procurementInvoiceLedger/index.vue 7 ●●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/views/procurementManagement/procurementLedger/index.vue 40 ●●●● 补丁 | 查看 | 原始文档 | blame | 历史
src/utils/index.js
@@ -409,3 +409,41 @@
  return `${year}-${month}-${day}`;
}
/**
 * 截断(舍去)指定位数后不四舍五入
 * @param {number} num - 要处理的数字
 * @param {number} decimals - 要保留的小数位数,默认为0
 * @returns {number} 截断后的数字
 * @example
 * truncate(3.14159, 2) // 返回 3.14
 * truncate(3.999, 2) // 返回 3.99
 * truncate(-3.14159, 2) // 返回 -3.14
 * truncate(123.456, 0) // 返回 123
 */
export function truncate(num, decimals = 0) {
  // 参数验证
  if (typeof num !== 'number' || isNaN(num)) {
    console.warn('truncate: 第一个参数必须是有效数字');
    return num;
  }
  if (typeof decimals !== 'number' || decimals < 0 || !Number.isInteger(decimals)) {
    console.warn('truncate: 第二个参数必须是非负整数');
    return num;
  }
  // 如果保留0位小数,直接使用 Math.trunc
  if (decimals === 0) {
    return Math.trunc(num);
  }
  // 计算倍数(10的decimals次方)
  const multiplier = Math.pow(10, decimals);
  // 对于负数,使用 Math.ceil 来确保正确截断
  // 对于正数,使用 Math.floor 来截断
  if (num < 0) {
    return Math.ceil(num * multiplier) / multiplier;
  } else {
    return Math.floor(num * multiplier) / multiplier;
  }
}
src/utils/summarizeTable.js
@@ -28,7 +28,7 @@
        } else {
          // 默认保留两位小数
          sums[index] = parseFloat(sum).toFixed(
            specialFormat[prop]?.decimalPlaces ?? 2
            specialFormat[prop]?.decimalPlaces ?? 3
          );
        }
      } else {
@@ -43,11 +43,11 @@
// 不含税总价计算
const calculateTaxExclusiveTotalPrice = (taxInclusiveTotalPrice, taxRate) => {
  const taxRateDecimal = taxRate / 100;
  return (taxInclusiveTotalPrice / (1 + taxRateDecimal)).toFixed(2);
  return (taxInclusiveTotalPrice / (1 + taxRateDecimal)).toFixed(3);
};
// 含税总价计算
const calculateTaxIncludeTotalPrice = (taxInclusiveUnitPrice, quantity) => {
  return (taxInclusiveUnitPrice * quantity).toFixed(2);
  return (taxInclusiveUnitPrice * quantity).toFixed(3);
};
// 导出函数供其他文件使用
export {
src/views/procurementManagement/invoiceEntry/components/ExpandTable.vue
@@ -14,7 +14,8 @@
<script setup>
import { usePaginationApi } from "@/hooks/usePaginationApi";
import { productList } from "@/api/procurementManagement/procurementLedger.js";
import { nextTick } from "vue";
import { nextTick, getCurrentInstance } from "vue";
import { truncate } from "@/utils/index.js";
const { proxy } = getCurrentInstance();
defineOptions({
@@ -61,7 +62,7 @@
      prop: "taxInclusiveUnitPrice",
            width:200,
      formatData: (val) => {
        return val ? parseFloat(val).toFixed(2) : "-";
        return val ? truncate(parseFloat(val), 3) : "-";
      },
    },
    {
@@ -69,7 +70,7 @@
      prop: "taxInclusiveTotalPrice",
            width:200,
      formatData: (val) => {
        return val ? parseFloat(val).toFixed(2) : "-";
        return val ? truncate(parseFloat(val), 3) : "-";
      },
    },
    {
@@ -77,7 +78,7 @@
      prop: "taxExclusiveTotalPrice",
            width:200,
      formatData: (val) => {
        return val ? parseFloat(val).toFixed(2) : "-";
        return val ? truncate(parseFloat(val), 3) : "-";
      },
    },
    {
@@ -85,7 +86,7 @@
      prop: "ticketsAmount",
            width:200,
      formatData: (val) => {
        return val ? parseFloat(val).toFixed(2) : "-";
        return val ? truncate(parseFloat(val), 3) : "-";
      },
    },
    {
@@ -97,7 +98,7 @@
      prop: "futureTicketsAmount",
            width:200,
      formatData: (val) => {
        return val ? parseFloat(val).toFixed(2) : "-";
        return val ? truncate(parseFloat(val), 3) : "-";
      },
    },
  ],
src/views/procurementManagement/invoiceEntry/components/Modal.vue
@@ -149,7 +149,7 @@
                <el-table-column label="本次开票数" prop="ticketsNum" width="180">
                    <template #default="scope">
                        <el-input-number :step="0.1" :min="0" style="width: 100%"
                                                         :precision="2"
                                                         :precision="3"
                                                         v-model="scope.row.ticketsNum"
                                                         @change="invoiceNumBlur(scope.row)"
                        />
@@ -162,7 +162,7 @@
                >
                    <template #default="scope">
                        <el-input-number :step="0.01" :min="0" style="width: 100%"
                                                         :precision="2"
                                                         :precision="3"
                                                         v-model="scope.row.ticketsAmount"
                                                         @change="invoiceAmountBlur(scope.row)"
                        />
@@ -214,6 +214,7 @@
import { getToken } from "@/utils/auth";
import useUserStore from "@/store/modules/user";
import dayjs from "dayjs";
import { truncate } from "@/utils/index.js";
defineOptions({
    name: "来票登记模态框",
@@ -303,7 +304,7 @@
        prop: "taxInclusiveUnitPrice",
        width: 150,
        formatData: (val) => {
            return val ? parseFloat(val).toFixed(2) : 0;
            return val ? truncate(parseFloat(val), 3) : 0;
        },
    },
    {
@@ -311,7 +312,7 @@
        prop: "taxInclusiveTotalPrice",
        width: 150,
        formatData: (val) => {
            return parseFloat(val).toFixed(2) ?? 0;
            return val ? truncate(parseFloat(val), 3) : 0;
        },
    },
    {
@@ -319,7 +320,7 @@
        prop: "taxExclusiveTotalPrice",
        width: 150,
        formatData: (val) => {
            return parseFloat(val).toFixed(2) ?? 0;
            return val ? truncate(parseFloat(val), 3) : 0;
        },
    },
    {
@@ -351,10 +352,10 @@
];
const formattedNumber = (row, column, cellValue) => {
    if (cellValue == 0) {
        return parseFloat(cellValue).toFixed(2);
        return truncate(parseFloat(cellValue), 3);
    }
    if (cellValue) {
        return parseFloat(cellValue).toFixed(2);
        return truncate(parseFloat(cellValue), 3);
    } else {
        return cellValue;
    }
@@ -438,7 +439,7 @@
            const totalAmount = allProductData.reduce((sum, item) => {
                return sum + (Number(item.taxInclusiveTotalPrice) || 0);
            }, 0);
            form.invoiceAmount = totalAmount.toFixed(2);
            form.invoiceAmount = truncate(totalAmount, 3);
            
            // 存储选中的合同数据
            selectedContracts.value = selectedRows;
@@ -480,11 +481,11 @@
        return;
    }
    // 计算本次来票金额
    row.ticketsAmount = (row.ticketsNum * row.taxInclusiveUnitPrice).toFixed(2)
    row.ticketsAmount = truncate(row.ticketsNum * row.taxInclusiveUnitPrice, 3)
    // 计算未来票数
    row.futureTickets = (row.tempFutureTickets - row.ticketsNum).toFixed(2)
    row.futureTickets = truncate(row.tempFutureTickets - row.ticketsNum, 3)
    // 计算未来票金额
    row.futureTicketsAmount = (row.tempFutureTicketsAmount - row.ticketsAmount).toFixed(2)
    row.futureTicketsAmount = truncate(row.tempFutureTicketsAmount - row.ticketsAmount, 3)
    calculateinvoiceAmount();
};
@@ -500,12 +501,12 @@
    }
    // 计算本次来票数
    row.ticketsNum = Number(
        (row.ticketsAmount / row.taxInclusiveUnitPrice).toFixed(2)
        truncate(row.ticketsAmount / row.taxInclusiveUnitPrice, 3)
    );
    // 计算未来票数
    row.futureTickets = (row.tempFutureTickets - row.ticketsNum).toFixed(2)
    row.futureTickets = truncate(row.tempFutureTickets - row.ticketsNum, 3)
    // 计算未来票金额
    row.futureTicketsAmount = (row.tempFutureTicketsAmount - row.ticketsAmount).toFixed(2)
    row.futureTicketsAmount = truncate(row.tempFutureTicketsAmount - row.ticketsAmount, 3)
    calculateinvoiceAmount();
};
@@ -516,7 +517,7 @@
            invoiceAmountTotal += Number(item.ticketsAmount);
        }
    });
    form.invoiceAmount = invoiceAmountTotal.toFixed(2);
    form.invoiceAmount = truncate(invoiceAmountTotal, 3);
};
const open = async (type, selectedRows) => {
src/views/procurementManagement/invoiceEntry/index.vue
@@ -89,6 +89,7 @@
import ExpandTable from "./components/ExpandTable.vue";
import Modal from "./components/Modal.vue";
import {ElMessageBox} from "element-plus";
import { truncate } from "@/utils/index.js";
defineOptions({
  name: "来票登记",
@@ -149,7 +150,7 @@
      prop: "contractAmount",
      width:200,
      formatData: (val) => {
        return val ? parseFloat(val).toFixed(2) : 0;
        return val ? truncate(parseFloat(val), 3) : 0;
      },
    },
    {
@@ -157,7 +158,7 @@
      prop: "receiptPaymentAmount",
      width:200,
      formatData: (val) => {
        return val ? parseFloat(val).toFixed(2) : 0;
        return val ? truncate(parseFloat(val), 3) : 0;
      },
    },
    {
@@ -165,7 +166,7 @@
      prop: "unReceiptPaymentAmount",
      width:200,
      formatData: (val) => {
        return val ? parseFloat(val).toFixed(2) : 0;
        return val ? truncate(parseFloat(val), 3) : 0;
      },
    },
    // {
src/views/procurementManagement/paymentEntry/index.vue
@@ -75,7 +75,7 @@
                                <el-input-number :step="0.01" :min="0" style="width: 100%"
                                                                 v-model="scope.row.currentPaymentAmount"
                                                                 :disabled="!scope.row.editType"
                                                                 :precision="2"
                                                                 :precision="3"
                                                                 placeholder="请输入"
                                                                 clearable
                                />
@@ -199,7 +199,7 @@
          <el-col :span="12">
            <el-form-item label="本次付款金额:" prop="currentPaymentAmount">
              <el-input-number :step="0.01" :min="0" style="width: 100%"
                                                             :precision="2"
                                                             :precision="3"
                v-model="form.currentPaymentAmount"
                placeholder="请输入"
                clearable
@@ -284,7 +284,7 @@
    updatePaymentRegistration
} from "@/api/procurementManagement/procurementInvoiceLedger.js";
import useFormData from "@/hooks/useFormData";
import { getCurrentDate } from "@/utils/index.js";
import { getCurrentDate, truncate } from "@/utils/index.js";
const { proxy } = getCurrentInstance();
const tableColumn = ref([
@@ -329,21 +329,21 @@
    label: "发票金额(元)",
    prop: "invoiceAmount",
    formatData: (params) => {
      return params ? parseFloat(params).toFixed(2) : 0;
      return params ? truncate(parseFloat(params), 3) : 0;
    },
  },
  {
    label: "已付款金额(元)",
    prop: "paymentAmountTotal",
    formatData: (params) => {
      return params ? parseFloat(params).toFixed(2) : 0;
      return params ? truncate(parseFloat(params), 3) : 0;
    },
  },
  {
    label: "待付款金额(元)",
    prop: "unPaymentAmountTotal",
    formatData: (params) => {
      return params ? parseFloat(params).toFixed(2) : 0;
      return params ? truncate(parseFloat(params), 3) : 0;
    },
  },
  {
src/views/procurementManagement/paymentHistory/index.vue
@@ -69,6 +69,7 @@
import { paymentHistoryListPage } from "@/api/procurementManagement/paymentEntry.js";
import useFormData from "@/hooks/useFormData";
import dayjs from "dayjs";
import { truncate } from "@/utils/index.js";
const { proxy } = getCurrentInstance();
const isShowSummarySon = ref(true);
@@ -90,7 +91,7 @@
    label: "付款金额",
    prop: "currentPaymentAmount",
    formatData: (params) => {
      return params ? parseFloat(params).toFixed(2) : 0;
      return params ? truncate(parseFloat(params), 3) : 0;
    },
  },
  {
src/views/procurementManagement/procurementInvoiceLedger/Form/EditForm.vue
@@ -46,8 +46,10 @@
</template>
<script setup>
import { getCurrentInstance, ref } from "vue";
import useFormData from "@/hooks/useFormData";
import { getProductRecordById } from "@/api/procurementManagement/procurementInvoiceLedger";
import { truncate } from "@/utils/index.js";
const { proxy } = getCurrentInstance()
defineOptions({
@@ -75,7 +77,7 @@
    form.createdAt = data.createdAt;
    form.invoiceNumber = data.invoiceNumber;
    form.ticketsNum = data.ticketsNum;
    form.ticketsAmount = data.ticketsAmount.toFixed(2);
    form.ticketsAmount = truncate(data.ticketsAmount, 3);
    form.taxInclusiveUnitPrice = data.taxInclusiveUnitPrice;
    form.futureTickets = data.futureTickets;
    temFutureTickets.value = data.futureTickets;
@@ -97,8 +99,8 @@
    // 确保所有数值都转换为数字类型进行计算
    const ticketsAmount = Number(form.ticketsNum) * Number(form.taxInclusiveUnitPrice);
    const futureTickets = Number(temFutureTickets.value) - Number(form.ticketsNum);
    form.futureTickets = Number(futureTickets.toFixed(2));
    form.ticketsAmount = Number(ticketsAmount.toFixed(2));
    form.futureTickets = Number(truncate(futureTickets, 3));
    form.ticketsAmount = Number(truncate(ticketsAmount, 3));
};
const inputTicketsAmount = (val) => {
    // 确保含税单价存在且不为零
@@ -109,15 +111,15 @@
    
    if (Number(val) > Number(form.futureTickets*form.taxInclusiveUnitPrice)) {
        proxy.$modal.msgWarning("本次来票金额不得大于总金额");
        form.ticketsAmount = (form.futureTickets*form.taxInclusiveUnitPrice).toFixed(2)
        form.ticketsAmount = truncate(form.futureTickets*form.taxInclusiveUnitPrice, 3)
        const ticketsNum = Number(form.ticketsAmount) / Number(form.taxInclusiveUnitPrice);
        form.ticketsNum = Number(ticketsNum.toFixed(2))
        form.ticketsNum = Number(truncate(ticketsNum, 3))
        return;
    }
    
    // 确保所有数值都转换为数字类型进行计算
    const ticketsNum = Number(val) / Number(form.taxInclusiveUnitPrice);
    form.ticketsNum = Number(ticketsNum.toFixed(2));
    form.ticketsNum = Number(truncate(ticketsNum, 3));
};
defineExpose({
src/views/procurementManagement/procurementInvoiceLedger/index.vue
@@ -119,6 +119,7 @@
import useUserStore from "@/store/modules/user.js";
import dayjs from "dayjs";
import FileList from "./fileList.vue";
import { truncate } from "@/utils/index.js";
defineOptions({
  name: "来票台账",
@@ -177,7 +178,7 @@
      prop: "taxInclusiveTotalPrice",
      width: 200,
      formatData: (cell) => {
        return cell ? parseFloat(cell).toFixed(2) : 0;
        return cell ? truncate(parseFloat(cell), 3) : 0;
      },
    },
    {
@@ -190,7 +191,7 @@
      prop: "ticketsAmount",
      width: 200,
      formatData: (cell) => {
        return cell ? parseFloat(cell).toFixed(2) : 0;
        return cell ? truncate(parseFloat(cell), 3) : 0;
      },
    },
    {
@@ -198,7 +199,7 @@
      prop: "unTicketsPrice",
      width: 200,
      formatData: (cell) => {
        return cell ? parseFloat(cell).toFixed(2) : 0;
        return cell ? truncate(parseFloat(cell), 3) : 0;
      },
    },
    {
src/views/procurementManagement/procurementLedger/index.vue
@@ -490,7 +490,7 @@
            <el-form-item label="含税单价(元):" prop="taxInclusiveUnitPrice">
              <el-input-number
                v-model="productForm.taxInclusiveUnitPrice"
                :precision="2"
                :precision="3"
                :step="0.1"
                clearable
                style="width: 100%"
@@ -503,7 +503,7 @@
                            <el-input-number
                                :step="0.1"
                                clearable
                                :precision="2"
                                :precision="3"
                                style="width: 100%"
                                v-model="productForm.quantity"
                                placeholder="请输入"
@@ -517,7 +517,7 @@
            <el-form-item label="含税总价(元):" prop="taxInclusiveTotalPrice">
              <el-input-number
                v-model="productForm.taxInclusiveTotalPrice"
                :precision="2"
                :precision="3"
                :step="0.1"
                clearable
                style="width: 100%"
@@ -554,7 +554,7 @@
                        <el-form-item label="库存预警数量:" prop="warnNum">
                            <el-input-number
                                v-model="productForm.warnNum"
                                :precision="2"
                                :precision="3"
                                :step="0.1"
                                clearable
                                style="width: 100%"
@@ -638,7 +638,7 @@
            <el-form-item label="合同金额(元):" prop="contractAmount">
              <el-input-number
                v-model="scanAddForm.contractAmount"
                :precision="2"
                :precision="3"
                :step="0.1"
                clearable
                style="width: 100%"
@@ -822,7 +822,7 @@
import useUserStore from "@/store/modules/user";
import { modelList, productTreeList } from "@/api/basicData/product.js";
import dayjs from "dayjs";
import { getCurrentDate } from "@/utils/index.js";
import { getCurrentDate, truncate } from "@/utils/index.js";
const userStore = useUserStore();
@@ -930,7 +930,7 @@
};
const formattedNumber = (row, column, cellValue) => {
  return parseFloat(cellValue).toFixed(2);
  return truncate(parseFloat(cellValue), 3);
};
// 查询列表
/** 搜索按钮操作 */
@@ -1340,16 +1340,18 @@
  }
  // 含税总价计算
  productForm.value.taxInclusiveTotalPrice =
    proxy.calculateTaxIncludeTotalPrice(
      productForm.value.taxInclusiveUnitPrice,
      productForm.value.quantity
    truncate(
      Number(productForm.value.taxInclusiveUnitPrice) * Number(productForm.value.quantity),
      3
    );
  if (productForm.value.taxRate) {
    // 不含税总价计算
    const taxRate = Number(productForm.value.taxRate);
    const taxRateDecimal = taxRate / 100;
    productForm.value.taxExclusiveTotalPrice =
      proxy.calculateTaxExclusiveTotalPrice(
        productForm.value.taxInclusiveTotalPrice,
        productForm.value.taxRate
      truncate(
        Number(productForm.value.taxInclusiveTotalPrice) / (1 + taxRateDecimal),
        3
      );
  }
};
@@ -1364,29 +1366,29 @@
    // 已知含税总价和数量,反算含税单价
    if (productForm.value.quantity) {
      productForm.value.taxInclusiveUnitPrice = 
        (Number(productForm.value.taxInclusiveTotalPrice) / Number(productForm.value.quantity)).toFixed(2);
        truncate(Number(productForm.value.taxInclusiveTotalPrice) / Number(productForm.value.quantity), 3);
    }
    // 已知含税总价和含税单价,反算数量
    else if (productForm.value.taxInclusiveUnitPrice) {
      productForm.value.quantity = 
        (Number(productForm.value.taxInclusiveTotalPrice) / Number(productForm.value.taxInclusiveUnitPrice)).toFixed(2);
        truncate(Number(productForm.value.taxInclusiveTotalPrice) / Number(productForm.value.taxInclusiveUnitPrice), 3);
    }
    // 反算不含税总价
    productForm.value.taxExclusiveTotalPrice = 
      (Number(productForm.value.taxInclusiveTotalPrice) / (1 + taxRate / 100)).toFixed(2);
      truncate(Number(productForm.value.taxInclusiveTotalPrice) / (1 + taxRate / 100), 3);
  } else if (field === 'taxExclusiveTotalPrice') {
    // 反算含税总价
    productForm.value.taxInclusiveTotalPrice = 
      (Number(productForm.value.taxExclusiveTotalPrice) * (1 + taxRate / 100)).toFixed(2);
      truncate(Number(productForm.value.taxExclusiveTotalPrice) * (1 + taxRate / 100), 3);
    // 已知数量,反算含税单价
    if (productForm.value.quantity) {
      productForm.value.taxInclusiveUnitPrice = 
        (Number(productForm.value.taxInclusiveTotalPrice) / Number(productForm.value.quantity)).toFixed(2);
        truncate(Number(productForm.value.taxInclusiveTotalPrice) / Number(productForm.value.quantity), 3);
    }
    // 已知含税单价,反算数量
    else if (productForm.value.taxInclusiveUnitPrice) {
      productForm.value.quantity = 
        (Number(productForm.value.taxInclusiveTotalPrice) / Number(productForm.value.taxInclusiveUnitPrice)).toFixed(2);
        truncate(Number(productForm.value.taxInclusiveTotalPrice) / Number(productForm.value.taxInclusiveUnitPrice), 3);
    }
  }
};