Browse Source

合同支付根据资金支付生成及标记

ellisran 3 weeks ago
parent
commit
807094f329

+ 3 - 2
app/public/js/contract_detail.js

@@ -372,8 +372,9 @@ $(document).ready(function() {
             })
             console.log(pays);
             newPays.forEach((pay, idx) => {
+                const operationHtml = !pay.fpcid ? `<a href="javascript:void(0);" class="text-primary pay-edit" data-id="${pay.id}" ${!pay.showEdit ? `style="display:none"` : ''}>编辑</a> <a href="javascript:void(0);" class="text-danger pay-del" data-id="${pay.id}" ${!pay.showEdit ? `style="display:none"` : ''}>删除</a>` : '';
                 paysHtml += `<tr class="text-center" data-cpid="${pay.id}">
-                                        <td>${idx + 1}</td>
+                                        <td>${idx + 1}${ pay.fpcid ? '<a href="javascript:void(0);" class="float-right"><i class="fa fa-cny"></i></a>' : ''}</td>
                                         <td>${moment(pay.pay_time).format('YYYY-MM-DD')}</td>
                                         <td>${pay.pay_price}</td>
                                         <td>${pay.debit_price}</td>
@@ -384,7 +385,7 @@ $(document).ready(function() {
                                         <td>${moment(pay.create_time).format('YYYY-MM-DD HH:mm:ss')}</td>
                                         <td>${pay.remark}</td>
                                         <td><a href="javascript:void(0);" class="text-primary open-pay-files" data-cpid="${pay.id}"><i class="fa fa-paperclip fa-rotate-90"></i></a> <span class="files-num">${pay.files.length > 0 ? pay.files.length : ''}</span></td>
-                                        <td><a href="javascript:void(0);" class="text-primary pay-edit" data-id="${pay.id}" ${ !pay.showEdit ? `style="display:none"` : ''}>编辑</a> <a href="javascript:void(0);" class="text-danger pay-del" data-id="${pay.id}" ${ !pay.showEdit ? `style="display:none"` : ''}>删除</a></td>
+                                        <td>${operationHtml}</td>
                                     </tr>`;
             });
             $('#htpay-table tbody').html(paysHtml);

+ 46 - 0
app/service/contract_pay.js

@@ -106,6 +106,9 @@ module.exports = app => {
             if (!cpInfo) {
                 throw '合同' + contractConst.typeName[cpInfo.contract_type] + '不存在';
             }
+            if (cpInfo.fpcid) {
+                throw '该合同' + contractConst.typeName[cpInfo.contract_type] + '关联了资金支付明细,不能删除';
+            }
             const transaction = await this.db.beginTransaction();
             try {
                 await transaction.delete(this.tableName, { id: cpid });
@@ -141,6 +144,49 @@ module.exports = app => {
             node.exist_pay = paysList.length === 0 ? 0 : 1;
             await transaction.update(this.ctx.service.contract.tableName, node);
         }
+
+        async createContractPays(transaction, fpid, uid, times, pays) {
+            const addPays = [];
+            const contracts = await transaction.select(this.ctx.service.contract.tableName, { where: { id: this._.uniq(this._.map(pays, 'cid')) } });
+            for (const p of pays) {
+                const contract = contracts.find(c => c.id === p.cid);
+                if (contract) {
+                    addPays.push({
+                        spid: contract.spid || null,
+                        tid: contract.tid || null,
+                        contract_type: contract.contract_type,
+                        cid: p.cid,
+                        uid,
+                        fpid,
+                        fpcid: p.id,
+                        pay_time: times,
+                        pay_price: p.pay_price || 0,
+                        debit_price: 0,
+                        yf_price: p.pay_price || 0,
+                        sf_price: p.settle_price || 0,
+                        pay_type: p.pay_type || '',
+                        remark: '',
+                        create_time: times,
+                    });
+                }
+            }
+            if (addPays.length > 0) {
+                await transaction.insert(this.tableName, addPays);
+                for (const c of contracts) {
+                    await this.calcContract(transaction, c);
+                }
+            }
+        }
+
+        async removeContractPays(transaction, fpid, pays) {
+            await transaction.delete(this.tableName, { fpid });
+            const contracts = await transaction.select(this.ctx.service.contract.tableName, { where: { id: this._.uniq(this._.map(pays, 'cid')) } });
+            if (contracts.length > 0) {
+                for (const c of contracts) {
+                    await this.calcContract(transaction, c);
+                }
+            }
+        }
     }
     return ContractPay;
 };

+ 12 - 0
app/service/financial_pay_audit.js

@@ -393,6 +393,12 @@ module.exports = app => {
                             id: fp.id, status: checkData.checkType,
                             entities: await this.ctx.service.financialPayContract.getEntities(fp.id),
                         });
+                        // 合同支付生成对应的支付信息
+                        const pays = await this.ctx.service.financialPayContract.getAllDataByCondition({ where: { fpid: fp.id } });
+                        const contractPays = this._.filter(pays, x => { return x.cid !== null; });
+                        if (contractPays.length > 0) {
+                            await this.ctx.service.contractPay.createContractPays(transaction, fp.id, fp.uid, time, contractPays);
+                        }
                     }
                 } else {
                     // 同步 期信息
@@ -511,6 +517,12 @@ module.exports = app => {
                     entities: '',
                     final_auditor_str: '',
                 });
+                // 合同支付生成对应的支付信息
+                const pays = await this.ctx.service.financialPayContract.getAllDataByCondition({ where: { fpid: fp.id } });
+                const contractPays = this._.filter(pays, x => { return x.cid !== null; });
+                if (contractPays.length > 0) {
+                    await this.ctx.service.contractPay.removeContractPays(transaction, fp.id, contractPays);
+                }
                 await transaction.commit();
                 result = true;
             } catch (error) {

+ 2 - 2
config/menu.js

@@ -102,7 +102,7 @@ const menu = {
     },
     contract: {
         name: '合同管理',
-        icon: 'fa-cny',
+        icon: 'fa-file-text-o',
         display: true,
         // url: '/contract/detail',
         children: null,
@@ -138,7 +138,7 @@ const menu = {
     },
     financial: {
         name: '资金监管',
-        icon: 'fa-money',
+        icon: 'fa-cny',
         display: true,
         // url: '/financial',
         caption: '资金监管',

+ 4 - 0
sql/update.sql

@@ -1382,6 +1382,10 @@ ALTER TABLE `zh_contract_audit`
 ADD COLUMN `permission_edit_contract` tinyint(1) NULL DEFAULT 0 COMMENT '编辑非本人合同权限' AFTER `permission_edit`,
 ADD COLUMN `permission_add_pay` tinyint(1) NULL DEFAULT 0 COMMENT '添加非本人合同支付权限' AFTER `permission_edit_contract`;
 
+ALTER TABLE `zh_contract_pay`
+ADD COLUMN `fpid` int(11) NULL DEFAULT NULL COMMENT '资金支付id' AFTER `uid`,
+ADD COLUMN `fpcid` int(11) NULL DEFAULT NULL COMMENT '资金支付明细id' AFTER `fpid`;
+
 ------------------------------------
 -- 表数据
 ------------------------------------