package titem; import baseclass.PaoCust; import baseclass.tools.GetFieldsName; import baseclass.tools.Math; import icstockbill.icstockbill; import openapi.base.SQLFactory; import openapi.base.data.Rows; import openapi.base.data.db.DBConnect; import org.krysalis.barcode4j.impl.upcean.EAN13Bean; import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider; import org.krysalis.barcode4j.tools.UnitConv; import p2.application.doclink.Doclinks; import p2.p2server.P2Server; import p2.pao.PaoFieldInfo; import p2.pao.PaoRemote; import p2.pao.PaoSet; import p2.pao.PaoSetRemote; import p2.util.P2AppException; import p2.util.P2Exception; import saorder.saorder; import saorderdetail.saorderdetail; import titemsaleprice.titemsaleprice; import java.awt.image.BufferedImage; import java.io.File; import java.io.FileOutputStream; import java.io.IOException; import java.util.Arrays; public class titem extends PaoCust { public String fprojectnum = ""; public titem(PaoSet arg0) { super(arg0); } @Override public void select() throws P2Exception { super.select(); } @Override public void add() throws P2Exception { super.add(); String appname = getThisPaoSet().getApp(); if ("TOOL".equalsIgnoreCase(appname)) { setValue("fistool", true, 11L); } } @Override public void init() throws P2Exception { super.init(); try { if (!toBeAdded()) { if (getOwner() == null && !"".equals(getThisPaoSet().getApp()) && getThisPaoSet().getApp() != null) { if ("新建".equals(getString("fstatus"))) { setFieldFlag( new String[]{"funitid", "FISABSTRACT",}, READONLY, true); } else { setFieldFlag( new GetFieldsName(getName()).getFields(new String[]{ "FADDQTY", "FSALEPRICE"}), READONLY, true); } } String fagentnum = ""; boolean flag = (getOwner() instanceof saorder || getOwner() instanceof saorderdetail || (getOwner() instanceof icstockbill && "销售出库".equals(getOwner().getString("ftype")))); if (flag) { fagentnum = getOwner().getString("fagentnum"); if ((getOwner() instanceof saorder || getOwner() instanceof saorderdetail) && "特殊订单".equals(getOwner().getString("ftype"))) { setValue("fsaleprice", getCardPriceByAagentnum(fagentnum)); } else { setValue("fsaleprice", getAgentSalePrice(fagentnum)); } PaoSetRemote tfavorites = getPaoSet("tfavorites"); tfavorites.setWhere("fagentnum='" + fagentnum + "' and fiscollection=1"); tfavorites.reset(); if (!tfavorites.isEmpty()) { setValue("fiscollection", true, 11L); } } String appname = getThisPaoSet().getApp(); // 商品信息查询 if ("TITEMQUERY".equalsIgnoreCase(appname)) { fagentnum = getAgentnumByHrid(getUserName()); setValue("fsaleprice", getAgentSalePrice(fagentnum)); } if (!"".equals(fagentnum)) { PaoSetRemote tfavorites = getPaoSet("tfavorites"); tfavorites.setWhere("fagentnum='" + fagentnum + "' and fiscollection=1"); tfavorites.reset(); if (!tfavorites.isEmpty()) { setValue("fiscollection", true, 11L); } } if ("TOOLBOOK".equalsIgnoreCase(appname)) { //工具借出台账借出数量查询 PaoSetRemote saorderdetailSet = getPaoSet("SAORDERDETAIL"); saorderdetailSet.setWhere("ftype='工具借出单' and (isnull(fqty, 0) - isnull(fundeliqty, 0) - isnull(freturnqty, 0)) > 0"); saorderdetailSet.reset(); setValue("faddqty", saorderdetailSet.sum("fqty") - saorderdetailSet.sum("fundeliqty") - saorderdetailSet.sum("freturnqty"), 11L); } } } catch (Exception e) { } } /** * 图片上传显示 */ public void refreshimg() throws P2Exception { PaoSetRemote DOCLINKS = P2Server.getP2Server().getPaoSet("DOCLINKS", getUserInfo()); DOCLINKS.setWhere("ownertable='" + getName() + "' and ownerid='" + getUniqueIDValue() + "' and docinfoid in(select docinfoid from docinfo where postfix in('JPG','JPEG','PNG','GIF','BMP'))"); DOCLINKS.reset(); setValue("fpic1", "", 11L); setValue("fpic2", "", 11L); setValue("fpic3", "", 11L); setValue("fpic4", "", 11L); int n = 1; for (int i = 0; i < DOCLINKS.count(); i++) { if (!DOCLINKS.getPao(i).getString("document").contains("BarCode")) { if (n <= 3) { setValue("fpic" + (n++), DOCLINKS.getPao(i).getInt("docinfoid"), 11L); } } else { setValue("fpic4", DOCLINKS.getPao(i).getInt("docinfoid"), 11L); } } for (int i = 0; i < DOCLINKS.count(); i++) { if (DOCLINKS.getPao(i).getString("document").contains("BarCode")) { setValue("fpic4", DOCLINKS.getPao(i).getInt("docinfoid"), 11L); } } getThisPaoSet().save(); } @Override protected void save() throws P2Exception { super.save(); PaoSetRemote paoset = getPaoSet("titemsaleprice"); if (paoset.isEmpty()) { if (toBeAdded() || !isModified("fitemno")) { int count = getSysVars(getString("siteid")).getInt("fitemsalepricecount"); for (int i = 1; i <= count; i++) { PaoRemote pao = paoset.addAtEnd(); pao.setValue("fitemno", getString("fitemno"), 11L); pao.setValue("fpricegrade", i + "", 11L); pao.setValue("fprice", 0, 11L); } } } if (toBeAdded()) { distinctfieldcheck("fitemno"); } } @Override public void modify() throws P2Exception { super.modify(); } @Override public void checkvalidate(boolean fischeck) throws P2Exception { if (fischeck) { if (!"新建".equals(getString("fstatus"))) { throw new P2AppException("", "非新建状态不能审核"); } if (getDouble("fpackingqty") <= 0) { throw new P2AppException("", "每件数量必须大于0"); } if (getDouble("fsaleaddqty") <= 0) { throw new P2AppException("", "销售增量必须大于0"); } if (getDouble("fsaleminqty") <= 0) { throw new P2AppException("", "销售起订量必须大于0"); } } else { if (!"审核".equals(getString("fstatus"))) { throw new P2AppException("", "非审核状态不能反审核"); } if (getBoolean("FISONSALE")) { throw new P2AppException("", "非下架状态不能反审核"); } if (getBoolean("FISUSED")) { throw new P2AppException("", "非停用状态不能反审核"); } } } @Override public void check(boolean fischeck) throws P2Exception { setValue("fstatus", fischeck ? "审核" : "新建", 11L); setValue("checkby", fischeck ? getUserName() : "", 11L); setValue("checkdate", fischeck ? getDateTime() : null, 11L); } @Override public void usedvalidate(boolean used) throws P2Exception { if (used) { if (getBoolean("fisused")) { throw new P2AppException("", "非停用状态不能启用"); } if (!"审核".equals(getString("fstatus"))) { throw new P2AppException("", "非审核状态不能启用"); } } else { if (!getBoolean("fisused")) { throw new P2AppException("", "非启用状态不能停用"); } if (getBoolean("FISONSALE")) { throw new P2AppException("", "非下架状态不能停用"); } } } @Override public void used(boolean used) throws P2Exception { setValue("fisused", used, 11L); } public void salevalidate(boolean sale) throws P2Exception { if (sale) { if (getBoolean("fisonsale")) { throw new P2AppException("", "非下架状态不能上架"); } if (!getBoolean("fisused")) { throw new P2AppException("", "非启用状态不能上架"); } if (!"审核".equals(getString("fstatus"))) { throw new P2AppException("", "非审核状态不能上架"); } if ("".equals(getString("fsaleclsnum"))) { throw new P2AppException("", "营销类别为空不能上架"); } if (getDouble("fsaleminqty") <= 0) { throw new P2AppException("", "销售起订量必须大于0"); } if (getDouble("fsaleaddqty") <= 0) { throw new P2AppException("", "销售赠量必须大于0"); } } else { if (!getBoolean("fisonsale")) { throw new P2AppException("", "非上架状态不能下架"); } if (!getPaoSet("titemgroup").isEmpty()) { throw new P2AppException("", "当前商品为商品组" + getPaoSet("titemgroup").getPao(0).getString("fgroupnum") + "的默认商品,不能下架"); } } } public void sale(boolean sale) throws P2Exception { setValue("fisonsale", sale, 11L); } @Override public void canDelete() throws P2Exception { super.canDelete(); if (!"新建".equals(getString("fstatus"))) { throw new P2AppException("", "非新建状态下不能删除"); } if (getBoolean("fisused")) { throw new P2AppException("", "非停用状态下不能删除"); } if (getBoolean("fisonsale")) { throw new P2AppException("", "非下架状态下不能删除"); } checkused("不可删除"); } /** * 检查物料是否被使用过 * * @throws P2Exception */ public void checkused() throws P2Exception { checkused(); } /** * 检查物料是否被使用过 * * @param msg * @throws P2Exception */ public void checkused(String msg) throws P2Exception { if (getPaoSet("ICINVBAL").count() > 0) { throw new P2AppException("", "该物料存在库存信息," + msg); } if (getPaoSet("saorderdetail").count() > 0) { throw new P2AppException("", "该物料存在订单信息," + msg); } if (getPaoSet("icstockbilldetail").count() > 0) { throw new P2AppException("", "该物料存在出入库信息," + msg); } if (getPaoSet("BOMHEAD").count() > 0) { throw new P2AppException("", "该物料存在BOM信息," + msg); } if (getPaoSet("BOM").count() > 0) { throw new P2AppException("", "该物料存在BOM信息," + msg); } if (getPaoSet("TPRDETAIL").count() > 0) { throw new P2AppException("", "该物料存在请购信息," + msg); } if (getPaoSet("TPODETAIL").count() > 0) { throw new P2AppException("", "该物料存在采购信息," + msg); } } public void modifycustvalidate() throws P2Exception { if (!"新建".equals(getString("fstatus"))) { throw new P2AppException("", "非新建状态不能修改"); } checkused("不能修改"); } public void modifycust() throws P2Exception { setFieldFlag(new String[]{"funitid", "fitemclsnum", "FISABSTRACT", "fbarcode"}, READONLY, false); } @Override public void delete(long arg0) throws P2Exception { super.delete(arg0); } /** * 根据经销商编号获取商品牌价 * * @param fagentnum * @return * @throws P2Exception */ public double getCardPriceByAagentnum(String fagentnum) throws P2Exception { PaoSetRemote agentpricegrade_view = P2Server.getP2Server() .getPaoSet("agentpricegrade_view", getUserInfo()); agentpricegrade_view.setWhere("fagentnum='" + fagentnum + "' and siteid='" + getSite() + "'"); agentpricegrade_view.reset(); if (agentpricegrade_view.isEmpty()) { throw new P2AppException("", "找不到经销商对应价格等级信息"); } String fpricegrade = agentpricegrade_view.getPao(0).getString( "fpricegrade"); String mapkey = getSite() + "_" + getString("fitemno") + "_" + fpricegrade; if (!titemsaleprice.itemsalepricemap.containsKey(mapkey)) { PaoSetRemote titemsalepriceset = P2Server.getP2Server().getPaoSet( "titemsaleprice", getUserInfo()); int i = 0; PaoRemote pao = null; while ((pao = titemsalepriceset.getPao(i)) != null) { String mapkey1 = pao.getString("siteid") + "_" + pao.getString("fitemno") + "_" + pao.getString("fpricegrade"); titemsaleprice.itemsalepricemap.put(mapkey1, pao.getDouble("fprice")); i++; } } if (titemsaleprice.itemsalepricemap.containsKey(mapkey)) { return titemsaleprice.itemsalepricemap.get(mapkey); } else { return 0; } } /** * 根据价格等级获取商品牌价 * * @param fpricegrade * @return * @throws P2Exception */ public double getCardPriceByGrade(String fpricegrade) throws P2Exception { String mapkey = getSite() + "_" + getString("fitemno") + "_" + fpricegrade; if (!titemsaleprice.itemsalepricemap.containsKey(mapkey)) { PaoSetRemote titemsalepriceset = P2Server.getP2Server().getPaoSet( "titemsaleprice", getUserInfo()); int i = 0; PaoRemote pao = null; while ((pao = titemsalepriceset.getPao(i)) != null) { String mapkey1 = pao.getString("siteid") + "_" + pao.getString("fitemno") + "_" + pao.getString("fpricegrade"); titemsaleprice.itemsalepricemap.put(mapkey1, pao.getDouble("fprice")); i++; } } if (titemsaleprice.itemsalepricemap.containsKey(mapkey)) { return titemsaleprice.itemsalepricemap.get(mapkey); } else { return 0; } } /** * 获取经销商单价 * * @return */ public double getAgentSalePrice(String fagentnum) throws P2Exception { //牌价 double fprice = getCardPriceByAagentnum(fagentnum); return getAgentSalePrice(fprice, fagentnum); } /** * 获取经销商单价 * * @return */ public double getAgentSalePrice(double fprice, String fagentnum) throws P2Exception { boolean fisprojectorder = false; if ("".equals(fprojectnum)) { if (getOwner() != null && getOwner() instanceof saorderdetail) { fisprojectorder = "项目订单".equals(getOwner().getString("ftype")); if (!getOwner().getPaoSet("saorder").isEmpty()) { fprojectnum = getOwner().getPaoSet("saorder").getPao(0).getString("fprojectnum"); } else if (getOwner().getOwner() instanceof saorder) { fprojectnum = getOwner().getOwner().getString("fprojectnum"); } } } else { fisprojectorder = true; } if (fisprojectorder) { //项目订单 //项目管理商品折扣表 PaoSetRemote tproject_pricecartelSet = getPaoSet("$tproject_pricecartel", "tproject_pricecartel", "fprojectnum='" + fprojectnum + "' and fitemno='" + getString("fitemno") + "'"); if (!tproject_pricecartelSet.isEmpty()) { PaoRemote pao = tproject_pricecartelSet.getPao(0); if ("折扣系数".equals(pao.getString("ftype"))) { if ("HY".equals(getString("siteid"))) { return Math.mul(pao.getDouble("fdiscountrate"), fprice, 0); } else { return Math.mul(pao.getDouble("fdiscountrate"), fprice, 2); } } else if ("固定单价".equals(pao.getString("ftype"))) { return pao.getDouble("fdiscountrate"); } } //项目管理类别折扣表 PaoSetRemote tproject_cartelitemclass = getPaoSet("$tproject_cartelitemclass", "tproject_cartelitemclass", "fprojectnum='" + fprojectnum + "'"); String flongsaleclsnum = getString("flongsaleclsnum"); if (!tproject_cartelitemclass.isEmpty() && !"".equals(flongsaleclsnum)) { String[] fsaleclsnums = flongsaleclsnum.split("/"); int length = fsaleclsnums.length; while (length > 0) { length--; //营销类别 String fsaleclsnum = fsaleclsnums[length]; int i = 0; while (tproject_cartelitemclass.getPao(i) != null) { //价格协议营销类别 String fsaleclsnum2 = tproject_cartelitemclass.getPao(i).getString("fsaleclsnum"); if (fsaleclsnum.equals(fsaleclsnum2)) { if ("HY".equals(getString("siteid"))) { return Math.mul(tproject_cartelitemclass.getPao(i).getDouble("fdiscountrate"), fprice, 0); } else { return Math.mul(tproject_cartelitemclass.getPao(i).getDouble("fdiscountrate"), fprice, 2); } } i++; } } } //项目管理折扣表 PaoSetRemote tprojectSet = getPaoSet("$tproject", "tproject", "fprojectnum='" + fprojectnum + "'"); if ("HY".equals(getString("siteid"))) { return Math.mul(tprojectSet.getPao(0).getDouble("fdiscountrate"), fprice, 0); } else { return Math.mul(tprojectSet.getPao(0).getDouble("fdiscountrate"), fprice, 2); } } else { if (getBoolean("fiswuliao") || getBoolean("fistool")) { return fprice; } PaoSetRemote tpricecarteldetailSet = getPaoSet("$tpricecarteldetail", "tpricecarteldetail", "fagentnum='" + fagentnum + "' and fitemno='" + getString("fitemno") + "'"); if (!tpricecarteldetailSet.isEmpty()) { PaoRemote pao = tpricecarteldetailSet.getPao(0); if ("折扣系数".equals(pao.getString("ftype"))) { if ("HY".equals(getString("siteid"))) { return Math.mul(pao.getDouble("fdiscountrate"), fprice, 0); } else { return Math.mul(pao.getDouble("fdiscountrate"), fprice, 2); } } else if ("固定单价".equals(pao.getString("ftype"))) { return pao.getDouble("fdiscountrate"); } } PaoSetRemote tpricecartelSet = getPaoSet("$tpricecartel", "tpricecartel", "fagentnum='" + fagentnum + "' and fstatus='审核' and fbegdate<=GETDATE() and fenddate>=GETDATE()"); if (!tpricecartelSet.isEmpty()) { //价格协议类别折扣表 PaoSetRemote tpricecartel_itemclass = tpricecartelSet.getPao(0).getPaoSet("tpricecartel_itemclass"); String flongsaleclsnum = getString("flongsaleclsnum"); if (!tpricecartel_itemclass.isEmpty() && !"".equals(flongsaleclsnum)) { String[] fsaleclsnums = flongsaleclsnum.split("/"); int length = fsaleclsnums.length; while (length > 0) { length--; //营销类别 String fsaleclsnum = fsaleclsnums[length]; int i = 0; while (tpricecartel_itemclass.getPao(i) != null) { //价格协议营销类别 String fsaleclsnum2 = tpricecartel_itemclass.getPao(i).getString("fsaleclsnum"); if (fsaleclsnum.equals(fsaleclsnum2)) { if ("HY".equals(getString("siteid"))) { return Math.mul(tpricecartel_itemclass.getPao(i).getDouble("fdiscountrate"), fprice, 0); } else { return Math.mul(tpricecartel_itemclass.getPao(i).getDouble("fdiscountrate"), fprice, 2); } } i++; } } } if ("HY".equals(getString("siteid"))) { return Math.mul(tpricecartelSet.getPao(0).getDouble("fdiscountrate"), fprice, 0); } else { return Math.mul(tpricecartelSet.getPao(0).getDouble("fdiscountrate"), fprice, 2); } } if ("HY".equals(getString("siteid"))) { return Math.mul(fprice, getPriceRate1(fagentnum), 0); } else { return Math.mul(fprice, getPriceRate1(fagentnum), 2); } } } /** * 获取等级价格系数 * * @return */ public double getPriceRate1(String fagentnum) throws P2Exception { PaoSetRemote AGENTPRICEGRADE_VIEW = getPaoSet("$agentpricegrade_view", "agentpricegrade_view", "fagentnum='" + fagentnum + "' and siteid='" + getString("siteid") + "'"); if (!AGENTPRICEGRADE_VIEW.isEmpty()) { return AGENTPRICEGRADE_VIEW.getPao(0).getDouble("fpricerate"); } return 1; } @Override public void fieldAction(Object paoField, String fieldname) throws P2Exception { super.fieldAction(paoField, fieldname); if ("FBARCODE".equals(fieldname)) { if (!"".equals(getString("FBARCODE")) && getSysVars().getBoolean("FISCREATEBARCODEPIC")) { String filename = getString("fitemno") + "_BarCode"; String objectname = getName(); PaoSetRemote DOCLINKS = P2Server.getP2Server().getPaoSet( "DOCLINKS", getUserInfo()); DOCLINKS.setWhere("document='" + filename + ".png' and ownerid='" + getUniqueIDValue() + "' and ownertable='" + objectname + "'"); DOCLINKS.reset(); try { createBarCode(getString("FBARCODE"), filename); refreshimg(); } catch (Exception e) { throw new P2AppException("", "条形码生成失败"); } } } else if ("FSALECLSNUM".equals(fieldname)) { String fsaleclsnum = getString("fsaleclsnum"); if ("".equals(fsaleclsnum)) { setValue("flongsaleclsnum", "", 11L); } else { String flongsaleclsnum = fsaleclsnum; boolean hasup = true; while (hasup) { PaoSetRemote titemclass = P2Server.getP2Server().getPaoSet("titemclass", getUserInfo()); titemclass.setWhere("fitemclsnum='" + fsaleclsnum + "' and fclasstype='营销类别' and fupclass is not null"); titemclass.reset(); if (titemclass.isEmpty()) { hasup = false; } else { fsaleclsnum = titemclass.getPao(0).getString("fupclass"); flongsaleclsnum = fsaleclsnum + "/" + flongsaleclsnum; } } setValue("flongsaleclsnum", flongsaleclsnum, 11L); } } } @Override public PaoSetRemote fieldGetlist(Object paoField, PaoSetRemote list, String fieldname) throws P2Exception { PaoSetRemote paoset = super.fieldGetlist(paoField, list, fieldname); if (fieldname.equals("FSALECLSNUM")) { if(getBoolean("FISTOOL")){ paoset.setWhere("fistool=1"); }else{ paoset.setWhere("fistool=0"); } } return paoset; } @Override public void fieldValidate(Object paoField, String fieldname) throws P2Exception { super.fieldValidate(paoField, fieldname); if ("FITEMNO".equals(fieldname)) { distinctfieldcheck(fieldname); } else if ("FSALECLSNUM".equals(fieldname)) { if (getBoolean("FISABSTRACT") && !"".equals(getString("FSALECLSNUM"))) { throw new P2AppException("", "虚拟件,不可销售"); } } else if ("FISABSTRACT".equals(fieldname)) { if (getBoolean("FISABSTRACT") && !"".equals(getString("FSALECLSNUM"))) { throw new P2AppException("", "已设置营销类别,不可设置为虚拟件"); } } else if ("FPACKINGQTY".equals(fieldname)) { if (getDouble("FPACKINGQTY") <= 0) { throw new P2AppException("", "每件数量必须大于0"); } } else if ("FISSINGLE".equals(fieldname)) { if (getPaoSet("ICINVBAL").count() > 0) { throw new P2AppException("", "存在库存,不可修改"); } } else if ("FBARCODE".equals(fieldname)) { /* * if (!getString("FBARCODE").equals("") && * getString("FBARCODE").length() != 12) { throw new * P2AppException("", "条形码必须为12位(最后一位打印时自动生成)"); } */ } } /** * 生成69条形码 * * @param message * @param filename * @throws IOException */ public void createBarCode(String message, String filename) throws P2Exception, IOException { StringBuffer stringBuffer = new StringBuffer(P2Server.getP2Server() .getConfig().getProperty("p2.attachment.defaultpath")); PaoSetRemote PS_SYSVARS = getPaoSet("$PS_SYSVARS", "PS_SYSVARS"); PS_SYSVARS.setWhere("varname='DOCUMENT_DIR_RULE'"); PS_SYSVARS.reset(); if (!PS_SYSVARS.isEmpty()) { String[] a = PS_SYSVARS.getPao(0).getString("varvalue").split("/"); String site = getSite(); stringBuffer.append(File.separator + site); for (int i = 1; i < a.length; i++) { if ("DOCTYPE".equalsIgnoreCase(a[i])) { stringBuffer.append(File.separator + getString("doctype")); } else if ("TABLE".equalsIgnoreCase(a[i])) { stringBuffer.append(File.separator + getName()); } } } EAN13Bean bean = new EAN13Bean();// 条形码类型 final int dpi = 150; final double moduleWidth = UnitConv.in2mm(2.0f / dpi); bean.setModuleWidth(moduleWidth); bean.doQuietZone(true); String format = "image/png"; FileOutputStream stream = new FileOutputStream(stringBuffer.toString() + "/" + filename); BitmapCanvasProvider canvas = new BitmapCanvasProvider(stream, format, dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0); bean.generateBarcode(canvas, message); canvas.finish(); stream.flush(); stream.close(); String serialnumber = filename; String document = filename + ".png"; String objectname = getName(); PaoSetRemote DOCINFOSET = P2Server.getP2Server().getPaoSet("DOCINFO", getUserInfo()); DOCINFOSET.setWhere("document='" + document + "' and ownertable='" + objectname + "' and description='69条形码' and serialnumber='" + serialnumber + "'"); DOCINFOSET.reset(); if (DOCINFOSET.isEmpty()) { PaoRemote docinfo = DOCINFOSET.addAtEnd(); docinfo.setValue("document", document, 11L); docinfo.setValue("ownertable", objectname, 11L); docinfo.setValue("description", "69条形码", 11L); docinfo.setValue("postfix", "PNG", 11L); docinfo.setValue("doctype", "Attachments", 11L); docinfo.setValue("serialnumber", serialnumber, 11L); DOCINFOSET.save(); if (docinfo.getPaoSet("DOCLINKS").isEmpty()) { PaoSetRemote DOCLINKSSET = docinfo.getPaoSet("DOCLINKS"); PaoRemote doclinks = DOCLINKSSET.addAtEnd(); doclinks.setValue("document", document, 11L); doclinks.setValue("docinfoid", docinfo.getLong("docinfoid"), 11L); doclinks.setValue("ownertable", objectname, 11L); doclinks.setValue("DOCTYPE", "Attachments", 11L); doclinks.setValue("description", "69条形码", 11L); doclinks.setValue("OWNERID", getUniqueIDValue(), 11L); docinfo.getPaoSet("DOCLINKS").save(); PaoSetRemote DOCHISTORY = doclinks.getPaoSet("$DOCHISTORY", "DOCHISTORY", ""); ((Doclinks) doclinks).addDochistory(DOCHISTORY, "ADD"); DOCHISTORY.save(); } } } @Override public PaoRemote duplicate() throws P2Exception { PaoRemote copyPao = copy(); return copyPao; } /** * 复制时跳过的字段 */ @Override protected boolean skipCopyField(PaoFieldInfo arg0) throws P2Exception { String[] fields = {"FSTATUS", "CREATEDATE", "CREATEBY", "CHECKBY", "CHECKDATE", "FISUSED", "FISONSALE", "FLOWESTBOMCODE", "FLOWESTCOSTCODE"}; return Arrays.asList(fields).contains(arg0.getName()); } public void copyitemmsg() throws P2Exception { PaoSetRemote paoset = getPaoSet("$Titem", "titem", "fitemno='" + getString("FCOPYITEMNO") + "'"); if (paoset.count() == 1) { titem titem = (titem) paoset.getPao(0); setValue("FITEMCLSNUM", titem.getString("FITEMCLSNUM"), 11L); setValue("FSALECLSNUM", titem.getString("FSALECLSNUM"), 11L); setValue("FGROSSWEIGHT", titem.getString("FGROSSWEIGHT"), 11L); setValue("FNETWEIGHT", titem.getString("FNETWEIGHT"), 11L); setValue("FSHAPESIZE", titem.getString("FSHAPESIZE"), 11L); setValue("FDEPNO", titem.getString("FDEPNO"), 11L); setValue("EXECUTIONSTANDARD", titem.getString("EXECUTIONSTANDARD"), 11L); setValue("FYGIENICLICENSE", titem.getString("FYGIENICLICENSE"), 11L); setValue("PRODUCTNAME", titem.getString("PRODUCTNAME"), 11L); setValue("FISPART", titem.getBoolean("FISPART"), 11L); setValue("FISLIMITITEMPARTS", titem.getBoolean("FISLIMITITEMPARTS"), 11L); setValue("FSTOCKNO", titem.getString("FSTOCKNO"), 11L); setValue("FICMINQTY", titem.getDouble("FICMINQTY"), 11L); setValue("FICADDQTY", titem.getDouble("FICADDQTY"), 11L); setValue("FPACKINGQTY", titem.getDouble("FPACKINGQTY"), 11L); setValue("FSALEMINQTY", titem.getDouble("FSALEMINQTY"), 11L); setValue("FSALEADDQTY", titem.getDouble("FSALEADDQTY"), 11L); setValue("FWARRANTYDAY", titem.getDouble("FWARRANTYDAY"), 11L); setValue("FSALEDAY", titem.getDouble("FSALEDAY"), 11L); } else { throw new P2AppException("", "请输入正确的货品编号"); } } public void collection(boolean isclooection) throws P2Exception { PaoSetRemote tfavorites = getPaoSet("tfavorites"); String fagentnum = getAgentnumByHrid(getUserName()); tfavorites.setWhere("fagentnum='" + fagentnum + "'"); tfavorites.reset(); if (isclooection) { if (tfavorites.isEmpty()) { PaoRemote pao = tfavorites.addAtEnd(); pao.setValue("fitemno", getString("fitemno"), 11L); pao.setValue("fagentnum", fagentnum, 11L); pao.setValue("fiscollection", true, 11L); } else { tfavorites.getPao(0).setValue("fiscollection", true, 11L); } } else { if (!tfavorites.isEmpty()) { tfavorites.getPao(0).setValue("fiscollection", false, 11L); } } } public void initStockMsg() throws P2Exception { icinvbalMsg icinvbal = new icinvbalMsg(); icinvbal.caculate(getString("siteid"), new String[]{getString("fitemno")}, true); } public void changeitemno() throws P2Exception { String fitemnoxn = getString("fitemnoxn"); if (fitemnoxn.equals("")) { throw new P2AppException("", "请填写新的产品编码"); } String ferpitemnoxn = getString("ferpitemnoxn"); if (ferpitemnoxn.equals("")) { throw new P2AppException("", "请填写新的erp品号"); } DBConnect dbConnect = new DBConnect(); Rows rows = dbConnect.runSqlQuery("select * from titem where fitemno='" + fitemnoxn + "' and siteid='" + getString("siteid") + "'"); if (!rows.isEmpty()) { throw new P2AppException("", "品号" + fitemnoxn + "已被使用!"); } setValue("fitemno", fitemnoxn, 11L); setValue("ferpitemno", ferpitemnoxn, 11L); } public void fielditemnamechange() throws P2Exception { DBConnect dbConnect = new DBConnect(); if (!dbConnect.runSqlQuery("select *from ps_databind_list where value='" + getString("fieldnamelistnewvalue") + "' where siteid='" + getString("siteid") + "' and databindid='TAGENTS_FIELDNAME'").isEmpty()) { throw new P2AppException("", "新领域名称已存在!"); } SQLFactory sqlFactory = new SQLFactory(this, "领域更新"); sqlFactory.addParameter("fnewfieldname", getString("fieldnamelistnewvalue")); sqlFactory.addParameter("foldfieldname", getString("fieldnamelistoldvalue")); sqlFactory.addParameter("siteid", getString("siteid")); String status = dbConnect.runSqlUpdate(sqlFactory.getSQL()); if (status.equals("true")) { throw new P2AppException("", "调整成功"); } else { throw new P2AppException("", status); } } public void branditemnamechange() throws P2Exception { DBConnect dbConnect = new DBConnect(); if (!dbConnect.runSqlQuery("select *from ps_databind_list where value='" + getString("brandlistnewvalue") + "' where siteid='" + getString("siteid") + "' and databindid='TITEM_FBRAND'").isEmpty()) { throw new P2AppException("", "新品牌名称已存在!"); } SQLFactory sqlFactory = new SQLFactory(this, "品牌更新"); sqlFactory.addParameter("fnewbrand", getString("brandlistnewvalue")); sqlFactory.addParameter("foldbrand", getString("brandlistoldvalue")); sqlFactory.addParameter("siteid", getString("siteid")); String status = dbConnect.runSqlUpdate(sqlFactory.getSQL()); if (status.equals("true")) { throw new P2AppException("", "调整成功"); } else { throw new P2AppException("", status); } } }