| | |
| | | @Override |
| | | @Transactional |
| | | public String saveContractInvoice(FieldSetEntity fs) { |
| | | FieldSetEntity fsinvo = baseDao.getFieldSetEntityByFilter(CmnConst.LX_PROJECT_CONTRACT_INFO_SUB,"contract_info_uuid=?",new Object[]{fs.getString("contract_name")},false); |
| | | Double invoiced_amount = fs.getDouble("invoiced_amount");//已开票金额 |
| | | //回写已开票金额到合同子表 |
| | | FieldSetEntity fcosub = new FieldSetEntity(); |
| | | if(fsinvo!=null){ |
| | | fcosub.setTableName(CmnConst.LX_PROJECT_CONTRACT_INFO_SUB); |
| | | fcosub.setValue("uuid",fsinvo.getUUID()); |
| | | fcosub.setValue("invoiced",invoiced_amount);//已开票金额 |
| | | baseDao.update(fcosub); |
| | | } |
| | | if(StringUtils.isEmpty(fs.getString(CmnConst.UUID))){ |
| | | fs.setValue("org_level_uuid", SpringMVCContextHolder.getCurrentUser().getOrg_level_uuid()); |
| | | fs.setValue("created_by", SpringMVCContextHolder.getCurrentUser().getUser_id()); |
| | | fs.setValue("org_level_uuid", SpringMVCContextHolder.getCurrentUser().getOrg_level_uuid()); |
| | | fs.setValue("created_utc_datetime",new Date()); |
| | | return baseDao.add(fs,true); |
| | | String add = baseDao.add(fs, true); |
| | | writeBackInvoice(fs); |
| | | return add; |
| | | } else { |
| | | fs.setValue("updated_by", SpringMVCContextHolder.getCurrentUser().getUser_id()); |
| | | fs.setValue("updated_utc_datetime",new Date()); |
| | | baseDao.update(fs); |
| | | writeBackInvoice(fs); |
| | | return fs.getString(CmnConst.UUID); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 回写回款金额到合同 |
| | | * @param fs |
| | | */ |
| | | private void writeBackInvoice(FieldSetEntity fs){ |
| | | //按照条款回写到合同子表 |
| | | DataTableEntity subDataTable = fs.getSubDataTable(CmnConst.LX_PROJECT_CONTRACT_INVOICE_INFO); |
| | | for (int i = 0; i <subDataTable.getRows() ; i++) { |
| | | FieldSetEntity fsData = subDataTable.getFieldSetEntity(i); |
| | | FieldSetEntity fsinvo = baseDao.getFieldSetEntityByFilter(CmnConst.LX_PROJECT_CONTRACT_INVOICE_INFO,"contract_terms=?",new Object[]{fsData.getString("contract_terms")},false); |
| | | |
| | | FieldSetEntity contractTerms = baseDao.getFieldSetEntityBySQL("SELECT sum(invoice_amount) invoice_amount FROM product_project_contract_invoice_info where contract_terms=? GROUP BY contract_terms", new Object[]{fsData.getString("contract_terms")}, false); |
| | | |
| | | Double invoiced_amount = contractTerms.getDouble("invoice_amount");//已开票金额 |
| | | //回写已开票金额到合同子表 |
| | | FieldSetEntity fcosub = new FieldSetEntity(); |
| | | if(fsinvo!=null){ |
| | | fcosub.setTableName(CmnConst.LX_PROJECT_CONTRACT_INFO_SUB); |
| | | fcosub.setValue("uuid",fsData.getString("contract_terms")); |
| | | fcosub.setValue("invoice_amount",invoiced_amount);//已开票金额 |
| | | baseDao.update(fcosub); |
| | | } |
| | | } |
| | | //按照合同回写到合同主表 |
| | | FieldSetEntity invoice_amount_fs = baseDao.getFieldSetEntityBySQL("SELECT sum(invoice_amount) invoice_amount FROM product_project_contract_invoice_info \n" + |
| | | "where contract_invoice_uuid in (SELECT uuid FROM product_project_contract_invoice where contract_name=?)", new Object[]{fs.getString("contract_name")}, false); |
| | | if(invoice_amount_fs!=null) { |
| | | FieldSetEntity invoiceFs = new FieldSetEntity(); |
| | | invoiceFs.setTableName(CmnConst.LX_PROJECT_CONTRACT_INFO); |
| | | invoiceFs.setValue("uuid",fs.getString("contract_name")); |
| | | invoiceFs.setValue("invoice_amount",invoice_amount_fs.getString("invoice_amount"));//已开票金额 |
| | | baseDao.update(invoiceFs); |
| | | } |
| | | } |
| | | /** |
| | | * 删除合同开票 |
| | | * @param fs |
| | | * @return |