package salogis; import baseclass.PaoCust; import baseclass.tools.GetFieldsName; import baseclass.tools.Math; import openapi.base.SQLFactory; import openapi.base.data.Row; import openapi.base.data.Rows; import openapi.base.data.db.DBConnect; import p2.pao.PaoRemote; import p2.pao.PaoSet; import p2.pao.PaoSetRemote; import p2.util.P2AppException; import p2.util.P2Exception; import java.util.HashMap; public class salogis extends PaoCust { public salogis(PaoSet arg0) { super(arg0); } @Override public void canDelete() throws P2Exception { super.canDelete(); if (!"新建".equals(getString("fstatus"))) { throw new P2AppException("", "非新建状态不可进行删除操作"); } } @Override public void init() throws P2Exception { super.init(); if (!toBeAdded() && getThisPaoSet().getApp() != null) { if (!"新建".equals(getString("fstatus"))) { setFieldFlag(new GetFieldsName(getName()).getFields(), READONLY, true); } else { if (!getPaoSet("salogisdetail").isEmpty()) { setFieldFlag(new String[]{"fagentnum"}, READONLY, true); } } } } @Override public void add() throws P2Exception { super.add(); setValue("fbillnum", getBillNum(getThisPaoSet().getApp())); } @Override protected void save() throws P2Exception { super.save(); } public void addBills(PaoSetRemote paoset) throws P2Exception { PaoSetRemote salogisdetailSet = getPaoSet("salogisdetail"); String[] ffreightstatuss = getDistinctString(paoset, "ffreightstatus", true); String[] frecagentnum = getDistinctString(paoset, "frecagentnum", true); String[] faddress = getDistinctString(paoset, "faddress", true); String[] fcontact = getDistinctString(paoset, "fcontact", true); String[] fphonenumber = getDistinctString(paoset, "fphonenumber", true); if (ffreightstatuss.length > 1) { throw new P2AppException("", "不可同时添加两种运费状态的发货单"); } if (ffreightstatuss.length == 1 && !"".equals(getString("ffreightstatus")) && !ffreightstatuss[0].equals(getString("ffreightstatus"))) { throw new P2AppException("", "不可同时添加两种运费状态的发货单"); } if (frecagentnum.length > 1) { throw new P2AppException("", "不可同时添加两个不同收货单位的发货单"); } if (frecagentnum.length == 1 && !"".equals(getString("frecagentnum")) && !frecagentnum[0].equals(getString("frecagentnum"))) { throw new P2AppException("", "不可同时添加两个不同收货单位的发货单"); } if (faddress.length > 1) { throw new P2AppException("", "不可同时添加两个不同收货地址的发货单"); } if (fcontact.length > 1) { throw new P2AppException("", "不可同时添加两个不同收货人的发货单"); } if (fphonenumber.length > 1) { throw new P2AppException("", "不可同时添加两个不同联系方式的发货单"); } if (!salogisdetailSet.isEmpty()) { DBConnect dbConnect = new DBConnect(); Rows rows = dbConnect.runSqlQuery("select t1.faddress,t1.fcontact,t1.fphonenumber from SALOGISDETAIL t1 inner join sainvoice t2 on t1.fsourceid=t2.sainvoiceid and t1.FSOURCEOBJECT='sainvoice'and t1.fparentid=" + getUniqueIDValue()); for (Row row : rows) { if (faddress.length == 1 && !faddress[0].equals(row.getString("faddress"))) { throw new P2AppException("", "不可同时添加两个不同收货地址的发货单"); } if (fcontact.length == 1 && !fcontact[0].equals(row.getString("fcontact"))) { throw new P2AppException("", "不可同时添加两个不同收货人的发货单"); } if (fphonenumber.length == 1 && !fphonenumber[0].equals(row.getString("fphonenumber"))) { throw new P2AppException("", "不可同时添加两个不同联系方式的发货单"); } } } BatchAdd(paoset, new String[]{"sainvoiceid", "$SAINVOICE"}, salogisdetailSet, new String[]{"fsourceid", "fsourceobject"}, true); if (!salogisdetailSet.isEmpty()) { PaoSetRemote sainvoiceSet = salogisdetailSet.getPao(0).getPaoSet("sainvoice"); if (!sainvoiceSet.isEmpty()) { setValue("ffreightstatus", sainvoiceSet.getPao(0).getString("ffreightstatus"), 11L); setValue("frecagentnum", sainvoiceSet.getPao(0).getString("frecagentnum"), 11L); setValue("faddress", sainvoiceSet.getPao(0).getString("faddress"), 11L); setValue("fcontact", sainvoiceSet.getPao(0).getString("fcontact"), 11L); setValue("fphonenumber", sainvoiceSet.getPao(0).getString("fphonenumber"), 11L); setValue("fprovince", sainvoiceSet.getPao(0).getString("fprovince"), 11L); setValue("fcity", sainvoiceSet.getPao(0).getString("fcity"), 11L); setValue("fcounty", sainvoiceSet.getPao(0).getString("fcounty"), 11L); } } String[] sainvocieids = getStrings(salogisdetailSet, "fsourceid"); SQLFactory sqlFactory = new SQLFactory(this, "发货单备注查询"); sqlFactory.addParameter("siteid", getString("siteid")); sqlFactory.addParameter_in("sainvoiceid", sainvocieids); DBConnect dbConnect = new DBConnect(); Rows rows = dbConnect.runSqlQuery(sqlFactory.getSQL()); if (!rows.isEmpty()) { setValue("fnotes", rows.get(0).getString("fnotes"), 11L); } } @Override public void checkvalidate(boolean ischeck) throws P2Exception { super.checkvalidate(ischeck); if (ischeck) { if (!"新建".equals(getString("fstatus"))) { throw new P2AppException("", "非新建状态不可进行审核操作"); } PaoSetRemote salogisdetailSet = getPaoSet("salogisdetail"); if (salogisdetailSet.isEmpty()) { throw new P2AppException("", "物流明细不能为空"); } PaoRemote var = getSysVars(); if (var.getBoolean("fissalogineedboxnum")) { if (getPaoSet("salogisdetail_pack").isEmpty()) { throw new P2AppException("", "装箱列表不能为空"); } } else { //判断有无上传附件 PaoSetRemote doclinksSet = getPaoSet("$doclinks", "doclinks", "ownertable='" + getName() + "' and ownerid=" + getUniqueIDValue()); if (doclinksSet.isEmpty()) { throw new P2AppException("", "请上传装箱明细附件"); } } PaoSetRemote salogis_boxcheck = getPaoSet("salogis_boxcheck"); if (!salogis_boxcheck.isEmpty()) { int i = 0; while (salogis_boxcheck.getPao(i) != null) { throw new P2AppException("", "商品" + salogis_boxcheck.getPao(i).getString("fitemno") + "装箱数量和发货数量不符"); } } int i = 0; while (salogisdetailSet.getPao(i) != null) { PaoSetRemote sainvoiceSet = salogisdetailSet.getPao(i).getPaoSet("sainvoice"); if (sainvoiceSet.isEmpty()) { throw new P2AppException("", "发货单不存在"); } PaoRemote sainvoice = sainvoiceSet.getPao(0); String finvonum = sainvoice.getString("finvonum"); if (!"复核".equals(sainvoice.getString("fstatus"))) { throw new P2AppException("", "发货单" + finvonum + "不在复核状态"); } //工具序列号状态变更 String saordertype = sainvoiceSet.getPao(0).getPaoSet("saorder").getPao(0).getString("ftype"); PaoSetRemote sainvoicedetail = salogisdetailSet.getPao(i).getPaoSet("sainvoicedetail"); int n = 0; while (sainvoicedetail.getPao(n) != null) { PaoSetRemote salogis_toolscodeSet = sainvoicedetail.getPao(n).getPaoSet("salogis_toolscode"); int m = 0; PaoRemote salogis_toolscodePao = null; while ((salogis_toolscodePao = salogis_toolscodeSet.getPao(m)) != null) { String fcode = salogis_toolscodePao.getString("fcode"); if ("".equals(fcode)) { throw new P2AppException("", "工具序列号不可为空"); } if (salogis_toolscodePao.getPaoSet("ttoolscode").isEmpty()) { throw new P2AppException("", "工具序列号" + salogis_toolscodePao.getString("fcode") + "不在工具序列号档案中"); } PaoRemote ttoolscodePao = salogis_toolscodePao.getPaoSet("ttoolscode").getPao(0); if (!"在库".equals(ttoolscodePao.getString("fstatus"))) { throw new P2AppException("", "工具序列号" + fcode + "不是在库状态"); } if ("工具借出单".equals(saordertype)) { ttoolscodePao.setValue("fstatus", ischeck ? "借出" : "在库"); } else { ttoolscodePao.setValue("fstatus", ischeck ? "售出" : "在库"); } ttoolscodePao.setValue("fisused", ischeck, 11L); ttoolscodePao.setValue("foutdate", ischeck ? getDate() : null, 11L); m++; } n++; } i++; } } else { if (!"审核".equals(getString("fstatus"))) { throw new P2AppException("", "非审核状态不可进行反审核操作"); } } } @Override public void check(boolean ischeck) throws P2Exception { super.check(ischeck); DBConnect dbConnect = new DBConnect(); // Rows rows = dbConnect.runSqlQuery("select t.saorderdetailid,t.finvoiceamount-t.finvoiceamount2 as finvoiceamount from (\n" + // "select t4.saorderdetailid,isnull(t4.finvoiceamount,0)as finvoiceamount,sum(isnull(t3.finvoiceamount,0))finvoiceamount2 from salogis t1\n" + // "inner join salogisdetail t2 on t1.salogisid=t2.fparentid\n" + // "inner join sainvoicedetail t3 on t2.fsourceid=t3.fparentid and t2.fsourceobject='SAINVOICE'\n" + // "inner join saorderdetail t4 on t3.fsourceid=t4.saorderdetailid\n" + // "where t1.salogisid='" + getUniqueIDValue() + "'\n" + // "group by t4.saorderdetailid,t4.finvoiceamount\n" + // ")t where t.finvoiceamount-t.finvoiceamount2>0"); Rows rows = dbConnect.runSqlQuery("\n" + "select convert(bigint,t.saorderdetailid)as saorderdetailid,sum(t.finvoiceamount)-sum(t.finvoiceamount2) as finvoiceamount from (\n" + "\tselect t4.saorderdetailid,isnull(t4.finvoiceamount,0)as finvoiceamount,0 finvoiceamount2 from salogis t1\n" + "\tinner join salogisdetail t2 on t1.salogisid=t2.fparentid\n" + "\tinner join sainvoicedetail t3 on t2.fsourceid=t3.fparentid and t2.fsourceobject='SAINVOICE'\n" + "\tinner join saorderdetail t4 on t3.fsourceid=t4.saorderdetailid\n" + "\twhere t1.salogisid='" + getUniqueIDValue() + "'\n" + "\tunion all\n" + "\tselect t4.fsourceid,0 as finvoiceamount,isnull(t4.finvoiceamount,0) as finvoiceamount2 from salogis t1\n" + "\tinner join salogisdetail t2 on t1.salogisid=t2.fparentid\n" + "\tinner join sainvoicedetail t3 on t2.fsourceid=t3.fparentid and t2.fsourceobject='SAINVOICE'\n" + "\tinner join sainvoicedetail t4 on t3.fsourceid=t4.fsourceid\n" + "\twhere t1.salogisid='" + getUniqueIDValue() + "'\n" + "\t\n" + ")t \n" + "group by t.saorderdetailid\n" + "having sum(t.finvoiceamount)-sum(t.finvoiceamount2)>0"); HashMap finvoiceamountmap = new HashMap();//可分配开票金额map for (Row row : rows) { finvoiceamountmap.put(row.getLong("saorderdetailid"), row.getDouble("finvoiceamount")); } PaoSetRemote salogisdetailSet = getPaoSet("salogisdetail"); int i = 0; while (salogisdetailSet.getPao(i) != null) { PaoSetRemote sainvoicedetail = salogisdetailSet.getPao(i).getPaoSet("sainvoicedetail"); PaoSetRemote sainvoiceSet = salogisdetailSet.getPao(i).getPaoSet("sainvoice"); sainvoiceSet.getPao(0).setValue("fstatus", ischeck ? "关闭" : "复核", 11L); sainvoiceSet.getPao(0).setValue("closeby", ischeck ? getUserName() : "", 11L); if (ischeck) { sainvoiceSet.getPao(0).setValue("closedate", getDateTime(), 11L); } else { sainvoiceSet.getPao(0).setValue("closedate", "", 11L); } if ("".equals(getString("frecagentnum"))) { setValue("ffreightstatus", sainvoiceSet.getPao(0).getString("ffreightstatus"), 11L); setValue("frecagentnum", sainvoiceSet.getPao(0).getString("frecagentnum"), 11L); } //工具序列号状态变更 String saordertype = sainvoiceSet.getPao(0).getPaoSet("saorder").getPao(0).getString("ftype"); int n = 0; while (sainvoicedetail.getPao(n) != null) { PaoSetRemote salogis_toolscodeSet = sainvoicedetail.getPao(n).getPaoSet("salogis_toolscode"); int m = 0; PaoRemote salogis_toolscodePao = null; while ((salogis_toolscodePao = salogis_toolscodeSet.getPao(m)) != null) { PaoRemote ttoolscodePao = salogis_toolscodePao.getPaoSet("ttoolscode").getPao(0); if ("工具借出单".equals(saordertype)) { ttoolscodePao.setValue("fstatus", ischeck ? "借出" : "在库"); } else { ttoolscodePao.setValue("fstatus", ischeck ? "售出" : "在库"); } ttoolscodePao.setValue("fisused", ischeck, 11L); ttoolscodePao.setValue("foutdate", ischeck ? getDate() : null, 11L); ttoolscodePao.setValue("fagentnum", ischeck ? getString("fagentnum") : "", 11L); m++; } if (ischeck) { double famount = sainvoicedetail.getPao(n).getDouble("famount"); long saorderdetailid = sainvoicedetail.getPao(n).getLong("fsourceid"); if (finvoiceamountmap.containsKey(saorderdetailid)) { if (famount > finvoiceamountmap.get(saorderdetailid)) { sainvoicedetail.getPao(n).setValue("finvoiceamount", finvoiceamountmap.get(saorderdetailid)); finvoiceamountmap.remove(saorderdetailid); } else { sainvoicedetail.getPao(n).setValue("finvoiceamount", famount); finvoiceamountmap.put(saorderdetailid, Math.sub(finvoiceamountmap.get(saorderdetailid), famount)); } } } else { sainvoicedetail.getPao(n).setValue("finvoiceamount", 0, 11L); } n++; } i++; } if (ischeck) { setValue("fstatus", "审核", 11L); setValue("checkby", getUserName(), 11L); setValue("checkdate", getDateTime(), 11L); //微信消息推送 StringBuffer fcontent = new StringBuffer(); fcontent.append("您的订单已出库!"); sendWechatMsg(getAgentQywechat(getString("fagentnum")), fcontent.toString(), this); try { //业务员邮件提醒 PaoRemote tagent = getPaoSet("tagents").getPao(0); PaoSetRemote tagents_fieldSet = tagent.getPaoSet("TAGENTS_FIELD"); String fsalers[] = getStrings(tagents_fieldSet, "hrid"); //sendEmail(getMailByHrId(fsalers), tagent.getString("FAGENTSHORTNAME") + "物流单已审核", "【物流单审核】物流单:" + getString("fbillnum") + ",订单客户:" + tagent.getString("FAGENTSHORTNAME") + "已审核完成"); //业务员邮件提醒 if (getString("siteid").equalsIgnoreCase("TZ")) { sendReportByEmail(getMailByHrId(fsalers), "TZ_salogis", "where=salogis.salogisid=" + getUniqueIDValue(), "【物流单审核】物流单:" + getString("fbillnum") + ",订单客户:" + tagent.getString("FAGENTSHORTNAME") + "已审核完成"); } else if (getString("siteid").equalsIgnoreCase("NB")) { sendReportByEmail(getMailByHrId(fsalers), "salogis", "where=salogis.salogisid=" + getUniqueIDValue(), "【物流单审核】物流单:" + getString("fbillnum") + ",订单客户:" + tagent.getString("FAGENTSHORTNAME") + "已审核完成"); } else if (getString("siteid").equalsIgnoreCase("HY")) { sendReportByEmail(getMailByHrId(fsalers), "HY_salogis_test", "where=salogis.salogisid=" + getUniqueIDValue(), "【物流单审核】物流单:" + getString("fbillnum") + ",订单客户:" + tagent.getString("FAGENTSHORTNAME") + "已审核完成"); } } catch (Exception e) { e.printStackTrace(); } } else { setValue("fstatus", "新建", 11L); setValue("checkby", "", 11L); setValue("checkdate", "", 11L); } } /** * 更新发货单已核销数量 * * @throws P2Exception */ public void updatesainvoicewriteamount() throws P2Exception { DBConnect dbConnect = new DBConnect(); Rows rows = dbConnect.runSqlQuery("select t2.fsourceid as saorderdetailid from salogisdetail t1 inner join sainvoicedetail t2 on t1.fsourceid=t2.fparentid where t1.fparentid='" + getUniqueIDValue() + "'"); for (Row row : rows) { dbConnect.runSqlUpdate("exec updatesainvoicewriteoffamount " + row.getString("saorderdetailid")); } } /** * 收货确认验证 * * @param fisreceive * @throws P2Exception */ public void receivevalidate(boolean fisreceive) throws P2Exception { if (fisreceive) { if ("到货".equals(getString("fstatus"))) { throw new P2AppException("", "已收货,不能重复进行收货操作"); } if (!"审核".equals(getString("fstatus"))) { throw new P2AppException("", "非审核状态不可进行收货操作"); } } else { if (!"到货".equals(getString("fstatus"))) { throw new P2AppException("", "未收货,不能进行取消收货操作"); } } } /** * 收货确认 * * @param fisreceive * @throws P2Exception */ public void receive(boolean fisreceive) throws P2Exception { PaoSetRemote salogisdetailSet = getPaoSet("salogisdetail"); int i = 0; while (salogisdetailSet.getPao(i) != null) { PaoSetRemote sainvoiceSet = salogisdetailSet.getPao(i).getPaoSet("sainvoice"); if (fisreceive) { sainvoiceSet.getPao(0).setValue("receivedate", getDate(), 11L); } else { sainvoiceSet.getPao(0).setValue("receivedate", "", 11L); } sainvoiceSet.getPao(0).setValue("fisreceiver", fisreceive, 11L); i++; } setValue("fisreceiver", fisreceive, 11L); if (fisreceive) { setValue("fstatus", "到货", 11L); setValue("receiveby", getUserName(), 11L); setValue("receivedate", getDateTime(), 11L); } else { setValue("fstatus", "审核", 11L); setValue("receiveby", "", 11L); setValue("receivedate", "", 11L); } } @Override public void fieldAction(Object paoField, String fieldname) throws P2Exception { super.fieldAction(paoField, fieldname); if ("FLOGISNO".equals(fieldname)) { String flogisno = getString("flogisno").replace(" ", ""); setValue("FLOGISNO", flogisno, 11L); } } @Override public void fieldValidate(Object paoField, String fieldname) throws P2Exception { super.fieldValidate(paoField, fieldname); } @Override public PaoSetRemote fieldGetlist(Object paoField, PaoSetRemote list, String fieldname) throws P2Exception { return super.fieldGetlist(paoField, list, fieldname); } }