Browse Source

已采购pdf

cz 1 year ago
parent
commit
d4863855ba

+ 105 - 3
src/utils/util.js

@@ -1,5 +1,8 @@
 import moment from "moment";
-import { post, get } from "@/utils/request";
+import {
+  post,
+  get
+} from "@/utils/request";
 import Cookies from "js-cookie";
 import html2Canvas from "html2canvas";
 import JsPDF from "jspdf";
@@ -353,9 +356,19 @@ export function timeInterval(smallTime, largeTime) {
     //计算相差秒数
     let leave3 = leave2 % (60 * 1000); //计算分钟数后剩余的毫秒数
     let seconds = Math.round(leave3 / 1000);
-    return { days: days, hours: hours, minutes: minutes, seconds: seconds };
+    return {
+      days: days,
+      hours: hours,
+      minutes: minutes,
+      seconds: seconds
+    };
   }
-  return { days: 0, hours: 0, minutes: 0, seconds: 0 };
+  return {
+    days: 0,
+    hours: 0,
+    minutes: 0,
+    seconds: 0
+  };
 }
 
 // 比较时间大小
@@ -368,3 +381,92 @@ export function compareTime(date1, date2) {
     return false; //第二个大
   }
 }
+
+// 金额转大写
+export function numberChinese(money) {
+  // 汉字的数字
+  let cnNums = ['零', '壹', '贰', '叁', '肆', '伍', '陆', '柒', '捌', '玖']
+  // 基本单位
+  let cnIntRadice = ['', '拾', '佰', '仟']
+  // 对应整数部分扩展单位
+  let cnIntUnits = ['', '万', '亿', '兆']
+  // 对应小数部分单位
+  let cnDecUnits = ['角', '分', '厘', '毫']
+  // 整数金额时后面跟的字符
+  let cnInteger = '整'
+  // 整型完以后的单位
+  let cnIntLast = '元'
+  // 最大处理的数字
+  let maxNum = 999999999999999.9999
+  // 金额整数部分
+  let integerNum
+  // 金额小数部分
+  let decimalNum
+  // 输出的中文金额字符串
+  let chineseStr = ''
+  // 分离金额后用的数组,预定义
+  let parts
+  if (money === '') {
+    return ''
+  }
+  money = parseFloat(money)
+  if (money >= maxNum) {
+    // 超出最大处理数字
+    return ''
+  }
+  if (money === 0) {
+    chineseStr = cnNums[0] + cnIntLast + cnInteger
+    return chineseStr
+  }
+  // 转换为字符串
+  money = money.toString()
+  if (money.indexOf('.') === -1) {
+    integerNum = money
+    decimalNum = ''
+  } else {
+    parts = money.split('.')
+    integerNum = parts[0]
+    decimalNum = parts[1].substr(0, 4)
+  }
+  // 获取整型部分转换
+  if (parseInt(integerNum, 10) > 0) {
+    let zeroCount = 0
+    let IntLen = integerNum.length
+    for (let i = 0; i < IntLen; i++) {
+      let n = integerNum.substr(i, 1)
+      let p = IntLen - i - 1
+      let q = p / 4
+      let m = p % 4
+      if (n === '0') {
+        zeroCount++
+      } else {
+        if (zeroCount > 0) {
+          chineseStr += cnNums[0]
+        }
+        // 归零
+        zeroCount = 0
+        chineseStr += cnNums[parseInt(n)] + cnIntRadice[m]
+      }
+      if (m === 0 && zeroCount < 4) {
+        chineseStr += cnIntUnits[q]
+      }
+    }
+    chineseStr += cnIntLast
+  }
+  // 小数部分
+  if (decimalNum !== '') {
+    let decLen = decimalNum.length
+    for (let i = 0; i < decLen; i++) {
+      const n = decimalNum.substr(i, 1)
+      if (n !== '0') {
+        chineseStr += cnNums[Number(n)] + cnDecUnits[i]
+      }
+    }
+  }
+  if (chineseStr === '') {
+    chineseStr += cnNums[0] + cnIntLast + cnInteger
+  } else if (decimalNum === '') {
+    chineseStr += cnInteger
+  }
+  return chineseStr
+}

+ 119 - 37
src/views/purchaseManage/purchaseManage/alreadyPurchase/index.vue

@@ -130,7 +130,9 @@
     <el-dialog title="打印" v-if="openPdf" v-model="openPdf" width="840px">
       <div id="pdfDom" ref="pdfDom" style="width: 776px">
         <div style="border: 1px solid #000; border-collapse: collapse">
-          <div style="text-align: right; padding: 2px 4px 0 0">合同号:aa</div>
+          <div style="text-align: right; padding: 2px 4px 0 0">
+            合同号:{{ pdfData.code }}
+          </div>
           <div class="title">购销合同</div>
           <div style="display: flex">
             <div style="display: flex; width: 50%; padding-right: 20px">
@@ -142,17 +144,23 @@
             </div>
             <div style="display: flex; width: 50%; padding-left: 20px">
               <div style="width: 60px">卖方:</div>
-              <div style="width: calc(100% - 60px)">供应商</div>
+              <div style="width: calc(100% - 60px)">
+                {{ pdfData.supplyName }}
+              </div>
             </div>
           </div>
           <div style="display: flex">
             <div style="display: flex; width: 50%; padding-right: 20px">
               <div style="width: 60px">经手人:</div>
-              <div style="width: calc(100% - 60px)">翁本娟</div>
+              <div style="width: calc(100% - 60px)">
+                {{ pdfData.purchaseName }}
+              </div>
             </div>
             <div style="display: flex; width: 50%; padding-left: 20px">
               <div style="width: 60px">经手人:</div>
-              <div style="width: calc(100% - 60px)">供应商联系人</div>
+              <div style="width: calc(100% - 60px)">
+                {{ pdfData.contactPerson }}
+              </div>
             </div>
           </div>
           <div>买卖双方经协商,一致同意签订以下合同</div>
@@ -162,30 +170,41 @@
               <td style="width: 70px">序号</td>
               <td>品名</td>
               <td>规格型号</td>
-              <td style="width: 60px">数量</td>
               <td style="width: 60px">单位</td>
+              <td style="width: 60px">数量</td>
               <td style="width: 100px">单价</td>
               <td style="width: 100px">金额</td>
             </tr>
-            <tr v-for="(row, index) in 5" :key="row">
+            <tr
+              v-for="(row, index) in pdfData.purchaseDetailList"
+              :key="row.id"
+            >
               <td style="width: 70px">{{ index + 1 }}</td>
-              <td>品名</td>
-              <td>规格型号</td>
-              <td style="width: 60px">数量</td>
-              <td style="width: 60px">单位</td>
-              <td style="width: 100px">单价</td>
-              <td style="width: 100px">金额</td>
+              <td>{{ row.productName }}</td>
+              <td>{{ row.productSpec }}</td>
+              <td style="width: 60px">{{ row.productUnitName }}</td>
+              <td style="width: 60px">{{ row.count }}</td>
+              <td style="width: 100px">
+                <span v-if="pdfData.currency">{{ pdfData.currency }}</span
+                >{{ row.price }}
+              </td>
+              <td style="width: 100px">
+                <span v-if="pdfData.currency">{{ pdfData.currency }}</span
+                >{{ row.amount }}
+              </td>
             </tr>
             <tr>
-              <td colspan="3" style="text-align: right">合计:</td>
-              <td>300</td>
+              <td colspan="4" style="text-align: right">合计:</td>
+              <td>{{ pdfData.countTotal }}</td>
               <td></td>
-              <td></td>
-              <td>$300</td>
+              <td>
+                <span v-if="pdfData.currency">{{ pdfData.currency }}</span
+                >{{ pdfData.productMoney }}
+              </td>
             </tr>
             <tr>
               <td colspan="7" style="text-align: left">
-                合计人民币金额(大写):
+                合计人民币金额(大写):{{ pdfData.moneyChinese }}
               </td>
             </tr>
             <tr>
@@ -194,10 +213,10 @@
                 福建省福州市鼓楼区软件大道89号福州软件园A区28号楼五层
               </td>
             </tr>
-            <tr>
+            <!-- <tr>
               <td>交货时间:</td>
               <td colspan="6" style="text-align: left"></td>
-            </tr>
+            </tr> -->
             <tr>
               <td>保修期:</td>
               <td colspan="6" style="text-align: left">一年</td>
@@ -235,18 +254,42 @@
               <div>
                 地址:福建省福州市鼓楼区软件大道89号福州软件园A区28号楼五层
               </div>
-              <div>电话:18750510253</div>
-              <div>传真:18750510253</div>
+              <div>电话:</div>
+              <div>传真:</div>
+              <div style="opacity: 0">|</div>
               <div style="margin-top: auto">代表人签字:</div>
             </div>
             <div style="width: 50%; padding-left: 20px">
               <div>卖方:</div>
-              <div>单位名称:供应商</div>
-              <div>统一社会信用代码:供应商</div>
-              <div>开户银行:工商银行常州市武进支行</div>
-              <div>帐号:1105021009000038765</div>
-              <div>地址:1105021009000038765</div>
-              <div>电话:1105021009000038765</div>
+              <div>单位名称:{{ pdfData.supplyName }}</div>
+              <div>统一社会信用代码:</div>
+              <div>开户银行:{{ pdfData.openingBank }}</div>
+              <div>帐号:{{ pdfData.accountOpening }}</div>
+              <div>
+                地址:<span
+                  v-if="
+                    pdfData.supplyAddress && pdfData.supplyAddress.countryName
+                  "
+                  >{{ pdfData.supplyAddress.countryName }}</span
+                >
+                <span
+                  v-if="
+                    pdfData.supplyAddress && pdfData.supplyAddress.provinceName
+                  "
+                  >,{{ pdfData.supplyAddress.provinceName }}</span
+                >
+                <span
+                  v-if="pdfData.supplyAddress && pdfData.supplyAddress.cityName"
+                  >,{{ pdfData.supplyAddress.cityName }}</span
+                >
+                <span
+                  v-if="
+                    pdfData.supplyAddress && pdfData.supplyAddress.areaDetail
+                  "
+                  >,{{ pdfData.supplyAddress.areaDetail }}</span
+                >
+              </div>
+              <div>电话:{{ pdfData.contactNumber }}</div>
               <div>代表人签字:</div>
             </div>
           </div>
@@ -257,7 +300,7 @@
               border-top: 1px solid #000;
             "
           >
-            签订日期:2023-04-13
+            签订日期:{{ pdfData.approvedDate }}
           </div>
         </div>
       </div>
@@ -278,6 +321,7 @@
 import { ElMessage, ElMessageBox } from "element-plus";
 import byTable from "@/components/byTable/index";
 import byForm from "@/components/byForm/index";
+import { numberChinese } from "@/utils/util.js";
 
 const loading = ref(false);
 const submitLoading = ref(false);
@@ -645,12 +689,16 @@ const handleArrival = (row) => {
       purchaseId: row.id,
       code: res.code,
       supplyId: res.supplyId,
-      arrivalDetailList: res.purchaseDetailList.map((x) => ({
-        ...x,
-        purchaseDetailId: x.id,
-        purchaseCount: x.count,
-        count: Number(x.count) - Number(x.sumArrivalCount),
-      })),
+      arrivalDetailList: res.purchaseDetailList.map((x) => {
+        let obj = {
+          ...x,
+          purchaseDetailId: x.id,
+          purchaseCount: x.count,
+          count: Number(x.count) - Number(x.sumArrivalCount),
+        };
+        delete obj.status;
+        return obj;
+      }),
       arrivalStatus: "",
     };
     dialogVisible.value = true;
@@ -681,11 +729,45 @@ const handleClickCode = (row) => {
     },
   });
 };
+
 const openPdf = ref(false);
-let rowData = ref({});
+let pdfData = ref({});
 const handlePrintPdf = (row) => {
-  rowData.value = row;
-  openPdf.value = true;
+  proxy.post("/purchase/detail", { id: row.id }).then((res) => {
+    proxy
+      .post("/supplierInfo/detail", { id: res.supplyId })
+      .then((supplyData) => {
+        res.contactPerson = supplyData.contactPerson;
+        res.contactNumber = supplyData.contactNumber;
+        res.openingBank = supplyData.openingBank;
+        res.accountOpening = supplyData.accountOpening;
+        let countTotal = 0;
+        let productMoney = 0;
+        for (let i = 0; i < res.purchaseDetailList.length; i++) {
+          const e = res.purchaseDetailList[i];
+          e.productUnitName = proxy.dictValueLabel(
+            e.productUnit,
+            productUnit.value
+          );
+          countTotal += Number(e.count);
+          productMoney += Number(e.amount);
+        }
+        res.countTotal = countTotal;
+        res.productMoney = productMoney;
+        res.moneyChinese = numberChinese(res.productMoney);
+        res.supplyAddress = {
+          countryName: supplyData.countryName,
+          provinceName: supplyData.provinceName,
+          cityName: supplyData.cityName,
+          areaDetail: supplyData.areaDetail,
+        };
+        if (res.approvedDate) {
+          res.approvedDate = res.approvedDate.slice(0, 10);
+        }
+        pdfData.value = res;
+        openPdf.value = true;
+      });
+  });
 };
 const clickDownload = () => {
   proxy.getPdf("请款PDF文件");

+ 72 - 23
src/views/purchaseSales/outAndInWarehouse/record/index.vue

@@ -28,34 +28,54 @@
 
     <el-dialog title="打印" v-if="openPdf" v-model="openPdf" width="840px">
       <div id="pdfDom" ref="pdfDom" style="width: 776px">
-        <div class="title">{{ dictValueLabel(rowData.type, typeList) }}单</div>
+        <div class="title">
+          {{ dictValueLabel(printData.type, typeList) }}单
+        </div>
         <div class="flex-top-bottom">
-          <div>福建宏星电子科技有限公司 (SO2301-001)</div>
-          <div>2023-01-01</div>
+          <div>
+            <span v-show="printData.corporateName && printData.code">
+              {{ printData.corporateName }} ({{ printData.code }})</span
+            >
+          </div>
+          <div>{{ printData.createTime }}</div>
         </div>
         <table border="1" style="width: 100%" class="table">
           <tr>
-            <td style="width: 100px">物品编码</td>
+            <td style="width: 80px">物品编码</td>
             <td>物品名称</td>
             <td>规格型号</td>
-            <td style="width: 80px">单位</td>
-            <td style="width: 80px">数量</td>
-            <td style="width: 80px">单价</td>
-            <td style="width: 80px">金额</td>
+            <td style="width: 60px">单位</td>
+            <td style="width: 60px">数量</td>
+            <td style="width: 70px">单价</td>
+            <td style="width: 90px">金额</td>
           </tr>
-          <tr v-for="row in 5" :key="row">
-            <td>物品编码</td>
-            <td>物品名称</td>
-            <td>规格型号</td>
-            <td>单位</td>
-            <td>数量</td>
-            <td>单价</td>
-            <td>金额</td>
+          <tr v-for="(row, index) in printData.list" :key="row.id">
+            <td>{{ row.productCode }}</td>
+            <td>{{ row.productName }}</td>
+            <td>{{ row.productSpec }}</td>
+            <td>{{ dictValueLabel(row.productUnit, productUnit) }}</td>
+            <td>{{ row.quantity }}</td>
+            <td>
+              <!-- {{ dictValueLabel(printData.currency, currencyType) }} -->
+              <span v-show="row.price">
+                {{ printData.currency }}
+                {{ row.price }}
+              </span>
+            </td>
+            <td>
+              <!-- {{ dictValueLabel(printData.currency, currencyType) }} -->
+              <span v-show="row.amount">
+                {{ printData.currency }}
+                {{ row.amount }}
+              </span>
+            </td>
           </tr>
         </table>
         <div class="flex-top-bottom">
-          <div>仓库名称:一楼面料仓库</div>
-          <div>合计金额: USD 3,000.00</div>
+          <div>仓库名称:{{ printData.warehouseName }}</div>
+          <div>
+            合计金额:{{ getTotalAmount(printData.currency, printData.list) }}
+          </div>
         </div>
       </div>
       <template #footer ref="printBtn">
@@ -149,12 +169,21 @@ const typeList = ref([
     value: "15",
   },
   {
+    label: "采购到货",
+    value: "18",
+  },
+  {
+    label: "到货质检",
+    value: "19",
+  },
+  {
     label: "生产任务出库",
     value: "20",
   },
 ]);
 const warehouseList = ref([]);
 const productUnit = ref([]);
+const currencyType = ref([]);
 const sourceList = ref({
   data: [],
   pagination: {
@@ -168,7 +197,7 @@ const sourceList = ref({
 });
 const loading = ref(false);
 const openPdf = ref(false);
-let rowData = ref({});
+let printData = ref({});
 const selectConfig = computed(() => {
   return [
     {
@@ -296,11 +325,15 @@ const getDict = () => {
       });
     }
   });
-  proxy.getDictOne(["unit"]).then((res) => {
+  proxy.getDictOne(["unit", "account_currency"]).then((res) => {
     productUnit.value = res["unit"].map((x) => ({
       label: x.dictValue,
       value: x.dictKey,
     }));
+    currencyType.value = res["account_currency"].map((x) => ({
+      label: x.dictValue,
+      value: x.dictKey,
+    }));
   });
 };
 const getList = async (req) => {
@@ -330,11 +363,27 @@ const deriveExcel = () => {
 };
 
 const handlePrintPdf = (row) => {
-  rowData.value = row;
-  openPdf.value = true;
+  proxy.post("/stockJournal/detail", { id: row.stockJournalId }).then((res) => {
+    printData.value = res;
+    printData.value.createTime = printData.value.createTime.slice(0, 10);
+    openPdf.value = true;
+  });
 };
+
+const getTotalAmount = (currency, arr) => {
+  let total = arr.reduce((total, cur) => (total += cur.amount), 0);
+  total = total ? total : "";
+  if (currency && total) {
+    return currency + " " + proxy.moneyFormat(total, 2);
+  } else {
+    return proxy.moneyFormat(total, 2);
+  }
+};
+
 const clickDownload = () => {
-  proxy.getPdf("请款PDF文件");
+  proxy.getPdf(
+    proxy.dictValueLabel(printData.value.type, typeList.value) + "单"
+  );
 };
 const pdfDom = ref(null);
 const printObj = ref({