| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426 |
- 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<Long, Double> 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);
- }
- }
|