|
@@ -0,0 +1,415 @@
|
|
|
+package nc.mc.br.plugin;
|
|
|
+
|
|
|
+import java.io.PrintWriter;
|
|
|
+import java.io.StringWriter;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+import org.jeecg.common.util.GetDataUtil;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+
|
|
|
+import nc.bs.framework.common.NCLocator;
|
|
|
+import nc.bs.pub.taskcenter.BgWorkingContext;
|
|
|
+import nc.bs.pub.taskcenter.IBackgroundWorkPlugin;
|
|
|
+import nc.itf.gl.pub.IFreevaluePub;
|
|
|
+import nc.itf.mc.IEteamsService;
|
|
|
+import nc.vo.bd.b04.DeptdocVO;
|
|
|
+import nc.vo.gl.pubvoucher.DetailVO;
|
|
|
+import nc.vo.gl.pubvoucher.VoucherVO;
|
|
|
+import nc.vo.glcom.ass.AssVO;
|
|
|
+import nc.vo.pub.BusinessException;
|
|
|
+import nc.vo.pub.VOStatus;
|
|
|
+import nc.vo.pub.lang.UFBoolean;
|
|
|
+import nc.vo.pub.lang.UFDate;
|
|
|
+import nc.vo.pub.lang.UFDouble;
|
|
|
+import u8c.log.NcLog;
|
|
|
+
|
|
|
+
|
|
|
+ * 项目费用支付(分对公和对私) XMFY
|
|
|
+ * @author
|
|
|
+ */
|
|
|
+public class ProjectCostPaymentPlugin implements IBackgroundWorkPlugin{
|
|
|
+
|
|
|
+ public String id = "&id=923838841108717575";
|
|
|
+ private IEteamsService service = NCLocator.getInstance().lookup(IEteamsService.class);
|
|
|
+ private IFreevaluePub freepub = NCLocator.getInstance().lookup(IFreevaluePub.class);
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public String executeTask(BgWorkingContext context) throws BusinessException {
|
|
|
+ try {
|
|
|
+ String code = service.getCode();
|
|
|
+ String token = service.getToken(code);
|
|
|
+ JSONArray alldata = service.getAllId(id,token);
|
|
|
+ List<String> ids = new ArrayList<String>();
|
|
|
+ for (int i = 0; i < alldata.size(); i++) {
|
|
|
+ JSONObject json = JSONObject.parseObject(alldata.getString(i));
|
|
|
+ ids.add("&id="+json.getString("id"));
|
|
|
+ }
|
|
|
+ String serNum = null;
|
|
|
+ for (int i = 0; i < ids.size(); i++) {
|
|
|
+ try {
|
|
|
+ JSONObject json = service.getInfoByID(token, ids.get(i));
|
|
|
+
|
|
|
+ serNum = json.getJSONObject("flowRequest").getString("serNum");
|
|
|
+ String currentNode = json.getJSONObject("flowRequest").getString("currentNode");
|
|
|
+ String batchLine = json.getJSONObject("formData").getJSONObject("dataDetails").getString("审批线路");
|
|
|
+ if((!"结束节点".equals(currentNode) && !"出纳打款".equals(currentNode)) || !"上海欣畅门窗有限公司".equals(batchLine)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ JSONObject formData = json.getJSONObject("formData");
|
|
|
+ JSONObject dataDetails = formData.getJSONObject("dataDetails");
|
|
|
+ String fkfs= dataDetails.getString("付款方式");
|
|
|
+ JSONObject fkrqJson = dataDetails.getJSONObject("付款日期_*");
|
|
|
+ JSONObject sfjeJson = dataDetails.getJSONObject("实付金额_*");
|
|
|
+ JSONObject companyJson = dataDetails.getJSONObject("公司名称_*");
|
|
|
+
|
|
|
+ JSONObject hbfkJson = dataDetails.getJSONObject("是否合并付款_*");
|
|
|
+
|
|
|
+ if (null != fkrqJson) {
|
|
|
+ UFDate prepareddate = null;
|
|
|
+ for (String key : fkrqJson.keySet()) {
|
|
|
+
|
|
|
+ if(null!=hbfkJson) {
|
|
|
+ String hbfkStr = hbfkJson.getString(key);
|
|
|
+ if("是".equals(hbfkStr)) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ String prepareddateStr = fkrqJson.getString(key);
|
|
|
+ String sfjeMoneyStr = sfjeJson.getString(key);
|
|
|
+ String companyStr = "";
|
|
|
+ if("公对公付款".equals(fkfs)) {
|
|
|
+ companyStr = companyJson.getString(key);
|
|
|
+ }
|
|
|
+ prepareddate = new UFDate(prepareddateStr);
|
|
|
+ String zdyearmont = prepareddate.getYear() + "" + prepareddate.getMonth();
|
|
|
+ UFDate nowDate = new UFDate();
|
|
|
+ String yearmonth = nowDate.getYear() + "" + nowDate.getMonth();
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ if (yearmonth.equals(zdyearmont)) {
|
|
|
+
|
|
|
+ List<String> serNums = new ArrayList<String>();
|
|
|
+ String free2 = serNum + "#" + prepareddateStr;
|
|
|
+ serNums.add(free2);
|
|
|
+ Map<String, String> map = GetDataUtil.getVoucher(serNums);
|
|
|
+ if (map.get(free2) != null) {
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ saveVoucher(json, prepareddateStr, sfjeMoneyStr, companyStr);
|
|
|
+ } else {
|
|
|
+ NcLog.info("项目费用支付生成凭证失败,单号:" + serNum + "\n年月" + zdyearmont);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ NcLog.info("项目费用支付生成凭证失败,单号:" + serNum + "\n付款日期不存在");
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ StringWriter stringWriter = new StringWriter();
|
|
|
+ e.printStackTrace(new PrintWriter(stringWriter));
|
|
|
+
|
|
|
+ String msg = stringWriter.getBuffer().toString();
|
|
|
+ NcLog.info("项目费用支付生成凭证失败,单号:"+serNum+"\n"+msg);
|
|
|
+ e.printStackTrace();
|
|
|
+ continue;
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ StringWriter stringWriter = new StringWriter();
|
|
|
+ e.printStackTrace(new PrintWriter(stringWriter));
|
|
|
+
|
|
|
+ String msg = stringWriter.getBuffer().toString();
|
|
|
+ NcLog.info("项目费用支付生成凭证失败"+"\n"+msg);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 凭证保存方法
|
|
|
+ * @param createStrJs
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ private void saveVoucher(JSONObject createStrJs, String prepareddateStr, String sfjeMoneyStr, String companyStr) throws Exception{
|
|
|
+ VoucherVO newvo = interfaceService(createStrJs, prepareddateStr, sfjeMoneyStr, companyStr);
|
|
|
+ service.saveVoucher_RequiresNew(newvo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 拼装凭证vo
|
|
|
+ * @param map
|
|
|
+ * @return
|
|
|
+ * @throws Exception
|
|
|
+ */
|
|
|
+ public VoucherVO interfaceService(JSONObject map, String prepareddateStr, String sfjeMoneyStr, String companyStr) throws Exception {
|
|
|
+
|
|
|
+ VoucherVO voucher = new VoucherVO();
|
|
|
+
|
|
|
+ setVoucher(map,voucher, prepareddateStr, sfjeMoneyStr, companyStr);
|
|
|
+
|
|
|
+ setDetail(map,voucher, prepareddateStr, sfjeMoneyStr, companyStr);
|
|
|
+
|
|
|
+ sumAmount(voucher);
|
|
|
+ voucher.setExplanation(voucher.getDetails()[0].getExplanation());
|
|
|
+ return voucher;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 凭证主表
|
|
|
+ * @param map
|
|
|
+ * @param obj
|
|
|
+ * @param voucher
|
|
|
+ * @throws BusinessException
|
|
|
+ */
|
|
|
+ private void setVoucher(JSONObject json,VoucherVO voucher, String prepareddateStr, String sfjeMoneyStr, String companyStr) throws Exception {
|
|
|
+ JSONObject formData = json.getJSONObject("formData");
|
|
|
+ JSONObject dataDetails = formData.getJSONObject("dataDetails");
|
|
|
+
|
|
|
+ voucher.setPk_prepared(GetDataUtil.getUserid("15800802186"));
|
|
|
+
|
|
|
+ voucher.setPk_vouchertype(GetDataUtil.getVoucherType("银行凭证"));
|
|
|
+
|
|
|
+ voucher.setPk_corp(GetDataUtil.getCorpPK("1001"));
|
|
|
+
|
|
|
+ UFDate prepareddate = new UFDate(prepareddateStr);
|
|
|
+
|
|
|
+ voucher.setYear(String.valueOf(prepareddate.getYear()));
|
|
|
+
|
|
|
+ voucher.setPeriod(String.valueOf(prepareddate).substring(5,7));
|
|
|
+
|
|
|
+ voucher.setPrepareddate(prepareddate);
|
|
|
+
|
|
|
+ voucher.setPk_manager("N/A");
|
|
|
+
|
|
|
+ voucher.setSignflag(UFBoolean.TRUE);
|
|
|
+
|
|
|
+ voucher.setDetailmodflag(UFBoolean.TRUE);
|
|
|
+
|
|
|
+ voucher.setDiscardflag(UFBoolean.FALSE);
|
|
|
+
|
|
|
+ voucher.setPk_system("GL");
|
|
|
+
|
|
|
+ voucher.setVoucherkind(0);
|
|
|
+
|
|
|
+ voucher.setTotaldebit(new UFDouble(sfjeMoneyStr));
|
|
|
+
|
|
|
+ voucher.setTotalcredit(new UFDouble(sfjeMoneyStr));
|
|
|
+
|
|
|
+ String free2 = dataDetails.getString("自动编号") + "#" + prepareddateStr;
|
|
|
+ voucher.setFree2(free2);
|
|
|
+ String pk_glorg = GetDataUtil.getGlorg("1001");
|
|
|
+
|
|
|
+ voucher.setPk_glorg(pk_glorg);
|
|
|
+
|
|
|
+ voucher.setPk_glorgbook(GetDataUtil.getGlorgbook(pk_glorg));
|
|
|
+ voucher.setIsdifflag(UFBoolean.FALSE);
|
|
|
+ voucher.setStatus(VOStatus.NEW);
|
|
|
+
|
|
|
+ voucher.setModifyflag("Y");
|
|
|
+ voucher.setHasCashflowModified(false);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 凭证分录
|
|
|
+ * @param map
|
|
|
+ * @param obj
|
|
|
+ * @param voucher
|
|
|
+ * @throws BusinessException
|
|
|
+ * @throws SQLException
|
|
|
+ */
|
|
|
+ private void setDetail(JSONObject map, VoucherVO voucher, String prepareddateStr, String sfjeMoneyStr, String companyStr) throws Exception {
|
|
|
+ JSONObject formData = map.getJSONObject("formData");
|
|
|
+ JSONObject dataDetails = formData.getJSONObject("dataDetails");
|
|
|
+ JSONArray datas = new JSONArray();
|
|
|
+ String pk_accsubj_jf = "";
|
|
|
+ String pk_accsubj = GetDataUtil.getAccSubject("100201",voucher.getPk_glorgbook());
|
|
|
+ String pk_currtype = GetDataUtil.getCurrType("CNY");
|
|
|
+ AssVO jobAssVO = null;
|
|
|
+ String fkfs = dataDetails.getString("付款方式");
|
|
|
+ if("公对私付款".equals(fkfs)) {
|
|
|
+ pk_accsubj_jf = GetDataUtil.getAccSubject("560201",voucher.getPk_glorgbook());
|
|
|
+ String deptName = dataDetails.getString("部门");
|
|
|
+ DeptdocVO deptdocVO = GetDataUtil.getDept(deptName, voucher.getPk_corp());
|
|
|
+ jobAssVO = getPubAssid("部门档案",deptdocVO,voucher.getPk_corp());
|
|
|
+ }else {
|
|
|
+ pk_accsubj_jf = GetDataUtil.getAccSubject("220201",voucher.getPk_glorgbook());
|
|
|
+ String custname = companyStr;
|
|
|
+
|
|
|
+ if(null != custname) {
|
|
|
+ custname = custname.replaceAll("\\s", "");
|
|
|
+ }
|
|
|
+ String pk_cubasdoc = GetDataUtil.getPk_cubasdoc(custname);
|
|
|
+ jobAssVO = getPubAssid2("供应商辅助核算",pk_cubasdoc,custname,voucher.getPk_corp());
|
|
|
+ }
|
|
|
+
|
|
|
+ JSONObject jsonObject = new JSONObject();
|
|
|
+ jsonObject.put("money", sfjeMoneyStr);
|
|
|
+ jsonObject.put("costName", dataDetails.getString("自动编号"));
|
|
|
+ jsonObject.put("pk_accsubj_jf", pk_accsubj_jf);
|
|
|
+ jsonObject.put("pk_accsubj", pk_accsubj);
|
|
|
+ jsonObject.put("pk_currtype", pk_currtype);
|
|
|
+ datas.add(jsonObject);
|
|
|
+ List<DetailVO> details = new ArrayList<DetailVO>();
|
|
|
+ for (int i = 0; i < datas.size(); i++) {
|
|
|
+ JSONObject data = datas.getJSONObject(i);
|
|
|
+
|
|
|
+
|
|
|
+ setDebitVO(details, voucher,data,map,jobAssVO);
|
|
|
+
|
|
|
+ setCreditVO(details, voucher, data,map,jobAssVO);
|
|
|
+ }
|
|
|
+
|
|
|
+ int detailindex = 0;
|
|
|
+ for(DetailVO dDetailVO : details){
|
|
|
+ detailindex++;
|
|
|
+ dDetailVO.setDetailindex(detailindex);
|
|
|
+ }
|
|
|
+ DetailVO[] detailVOs = new DetailVO[details.size()];
|
|
|
+ details.toArray(detailVOs);
|
|
|
+ voucher.setDetails(detailVOs);
|
|
|
+ voucher.setModifyflag("Y");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 凭证分录借方
|
|
|
+ * @param details
|
|
|
+ * @param voucher
|
|
|
+ * @param data
|
|
|
+ * @param map
|
|
|
+ * @throws BusinessException
|
|
|
+ * @throws SQLException
|
|
|
+ */
|
|
|
+ private void setDebitVO(List<DetailVO> details, VoucherVO voucher, JSONObject data, JSONObject map, AssVO jobAssVO) throws Exception {
|
|
|
+ DetailVO vo = new DetailVO();
|
|
|
+ List<AssVO> listAss = new ArrayList<AssVO>();
|
|
|
+ listAss.add(jobAssVO);
|
|
|
+ AssVO[] assVOs = new AssVO[listAss.size()];
|
|
|
+ listAss.toArray(assVOs);
|
|
|
+ vo.setAssid(freepub.getAssID(assVOs, true));
|
|
|
+ vo.setPk_accsubj(data.getString("pk_accsubj_jf"));
|
|
|
+ vo.setCreditamount(UFDouble.ZERO_DBL);
|
|
|
+ vo.setCreditquantity(UFDouble.ZERO_DBL);
|
|
|
+ vo.setDebitamount(new UFDouble(data.getString("money")));
|
|
|
+ vo.setDirection("D");
|
|
|
+ vo.setDiscardflag(UFBoolean.FALSE);
|
|
|
+ vo.setExcrate1(UFDouble.ZERO_DBL);
|
|
|
+ vo.setExcrate2(UFDouble.ONE_DBL);
|
|
|
+ vo.setExplanation(data.getString("costName"));
|
|
|
+ vo.setFraccreditamount(UFDouble.ZERO_DBL);
|
|
|
+ vo.setFracdebitamount(UFDouble.ZERO_DBL);
|
|
|
+ vo.setLocalcreditamount(UFDouble.ZERO_DBL);
|
|
|
+ vo.setLocaldebitamount(new UFDouble(data.getString("money")));
|
|
|
+ vo.setPeriod(voucher.getPeriod());
|
|
|
+ vo.setPk_corp(voucher.getPk_corp());
|
|
|
+ vo.setPk_currtype(data.getString("pk_currtype"));
|
|
|
+ vo.setPk_glbook(voucher.getPk_glbook());
|
|
|
+ vo.setPk_glorg(voucher.getPk_glorg());
|
|
|
+ vo.setPk_glorgbook(voucher.getPk_glorgbook());
|
|
|
+ vo.setPk_manager(voucher.getPk_manager());
|
|
|
+ vo.setPk_system(voucher.getPk_system());
|
|
|
+ vo.setPk_vouchertype(voucher.getPk_vouchertype());
|
|
|
+ vo.setPrepareddate(voucher.getPrepareddate());
|
|
|
+ vo.setYear(voucher.getYear());
|
|
|
+ details.add(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 凭证分录贷方
|
|
|
+ * @param details
|
|
|
+ * @param voucher
|
|
|
+ * @param data
|
|
|
+ * @param map
|
|
|
+ * @throws BusinessException
|
|
|
+ */
|
|
|
+ private void setCreditVO( List<DetailVO> details,VoucherVO voucher, JSONObject data, JSONObject map, AssVO jobAssVO) throws Exception {
|
|
|
+ DetailVO vo = new DetailVO();
|
|
|
+ vo.setPk_accsubj(data.getString("pk_accsubj"));
|
|
|
+ vo.setCreditamount(new UFDouble(data.getString("money")));
|
|
|
+ vo.setDebitamount(UFDouble.ZERO_DBL);
|
|
|
+ vo.setDirection("C");
|
|
|
+ vo.setDiscardflag(UFBoolean.FALSE);
|
|
|
+ vo.setExcrate1(UFDouble.ZERO_DBL);
|
|
|
+ vo.setExcrate2(UFDouble.ONE_DBL);
|
|
|
+ vo.setExplanation(data.getString("costName"));
|
|
|
+ vo.setFraccreditamount(UFDouble.ZERO_DBL);
|
|
|
+ vo.setFracdebitamount(UFDouble.ZERO_DBL);
|
|
|
+ vo.setLocalcreditamount(new UFDouble(data.getString("money")));
|
|
|
+ vo.setLocaldebitamount(UFDouble.ZERO_DBL);
|
|
|
+ vo.setPeriod(voucher.getPeriod());
|
|
|
+ vo.setPk_corp(voucher.getPk_corp());
|
|
|
+ vo.setPk_currtype(data.getString("pk_currtype"));
|
|
|
+ vo.setPk_glbook(voucher.getPk_glbook());
|
|
|
+ vo.setPk_glorg(voucher.getPk_glorg());
|
|
|
+ vo.setPk_glorgbook(voucher.getPk_glorgbook());
|
|
|
+ vo.setPk_manager(voucher.getPk_manager());
|
|
|
+ vo.setPk_system(voucher.getPk_system());
|
|
|
+ vo.setPk_vouchertype(voucher.getPk_vouchertype());
|
|
|
+ vo.setPrepareddate(voucher.getPrepareddate());
|
|
|
+ vo.setYear(voucher.getYear());
|
|
|
+ details.add(vo);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 凭证分录生成后需要把原币金额回写到表头金额
|
|
|
+ * @param voucher
|
|
|
+ */
|
|
|
+ private void sumAmount(VoucherVO voucher) {
|
|
|
+ UFDouble amount1 = new UFDouble(0);
|
|
|
+ UFDouble amount2 = new UFDouble(0);
|
|
|
+ DetailVO[] vos = voucher.getDetails();
|
|
|
+ for(DetailVO vo : vos){
|
|
|
+ amount1 = amount1.add(vo.getCreditamount());
|
|
|
+ amount2 = amount2.add(vo.getDebitamount());
|
|
|
+ }
|
|
|
+ voucher.setTotalcredit(amount1);
|
|
|
+ voucher.setTotaldebit(amount2);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 通用辅助核算借方对公
|
|
|
+ * @param pk_bdinfo
|
|
|
+ * @throws SQLException
|
|
|
+ */
|
|
|
+ private AssVO getPubAssid2(String checktype,String pk_cubasdoc,String custname,String pk_corp) throws Exception {
|
|
|
+ List<AssVO> list = new ArrayList<AssVO>();
|
|
|
+ AssVO vo = new AssVO();
|
|
|
+ vo.setChecktypecode(pk_cubasdoc);
|
|
|
+ vo.setChecktypename(checktype);
|
|
|
+ vo.setPk_Checktype(GetDataUtil.getBdpkByBdInfo(checktype));
|
|
|
+ vo.setPk_Checkvalue(pk_cubasdoc);
|
|
|
+ vo.setCheckvaluecode(pk_cubasdoc);
|
|
|
+ vo.setCheckvaluename(custname);
|
|
|
+ vo.setUserData(true);
|
|
|
+ list.add(vo);
|
|
|
+ AssVO[] assVOs = new AssVO[list.size()];
|
|
|
+ list.toArray(assVOs);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ * 通用辅助核算
|
|
|
+ * @param pk_bdinfo
|
|
|
+ * @throws SQLException
|
|
|
+ */
|
|
|
+ private AssVO getPubAssid(String checktype,DeptdocVO deptdocVO,String pk_corp) throws Exception {
|
|
|
+ List<AssVO> list = new ArrayList<AssVO>();
|
|
|
+ AssVO vo = new AssVO();
|
|
|
+ vo.setChecktypecode(deptdocVO.getDeptcode());
|
|
|
+ vo.setChecktypename(checktype);
|
|
|
+ vo.setPk_Checktype(GetDataUtil.getBdpkByBdInfo(checktype));
|
|
|
+ vo.setPk_Checkvalue(deptdocVO.getPrimaryKey());
|
|
|
+ vo.setCheckvaluecode(deptdocVO.getDeptcode());
|
|
|
+ vo.setCheckvaluename(deptdocVO.getDeptname());
|
|
|
+ vo.setUserData(true);
|
|
|
+ list.add(vo);
|
|
|
+ AssVO[] assVOs = new AssVO[list.size()];
|
|
|
+ list.toArray(assVOs);
|
|
|
+ return vo;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|