titem.java 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  1. package titem;
  2. import baseclass.PaoCust;
  3. import baseclass.tools.GetFieldsName;
  4. import baseclass.tools.Math;
  5. import icstockbill.icstockbill;
  6. import openapi.base.SQLFactory;
  7. import openapi.base.data.Rows;
  8. import openapi.base.data.db.DBConnect;
  9. import org.krysalis.barcode4j.impl.upcean.EAN13Bean;
  10. import org.krysalis.barcode4j.output.bitmap.BitmapCanvasProvider;
  11. import org.krysalis.barcode4j.tools.UnitConv;
  12. import p2.application.doclink.Doclinks;
  13. import p2.p2server.P2Server;
  14. import p2.pao.PaoFieldInfo;
  15. import p2.pao.PaoRemote;
  16. import p2.pao.PaoSet;
  17. import p2.pao.PaoSetRemote;
  18. import p2.util.P2AppException;
  19. import p2.util.P2Exception;
  20. import saorder.saorder;
  21. import saorderdetail.saorderdetail;
  22. import titemsaleprice.titemsaleprice;
  23. import java.awt.image.BufferedImage;
  24. import java.io.File;
  25. import java.io.FileOutputStream;
  26. import java.io.IOException;
  27. import java.util.Arrays;
  28. public class titem extends PaoCust {
  29. public String fprojectnum = "";
  30. public titem(PaoSet arg0) {
  31. super(arg0);
  32. }
  33. @Override
  34. public void select() throws P2Exception {
  35. super.select();
  36. }
  37. @Override
  38. public void add() throws P2Exception {
  39. super.add();
  40. String appname = getThisPaoSet().getApp();
  41. if ("TOOL".equalsIgnoreCase(appname)) {
  42. setValue("fistool", true, 11L);
  43. }
  44. }
  45. @Override
  46. public void init() throws P2Exception {
  47. super.init();
  48. try {
  49. if (!toBeAdded()) {
  50. if (getOwner() == null && !"".equals(getThisPaoSet().getApp()) && getThisPaoSet().getApp() != null) {
  51. if ("新建".equals(getString("fstatus"))) {
  52. setFieldFlag(
  53. new String[]{"funitid", "FISABSTRACT",},
  54. READONLY, true);
  55. } else {
  56. setFieldFlag(
  57. new GetFieldsName(getName()).getFields(new String[]{
  58. "FADDQTY", "FSALEPRICE"}), READONLY,
  59. true);
  60. }
  61. }
  62. String fagentnum = "";
  63. boolean flag = (getOwner() instanceof saorder || getOwner() instanceof saorderdetail || (getOwner() instanceof icstockbill && "销售出库".equals(getOwner().getString("ftype"))));
  64. if (flag) {
  65. fagentnum = getOwner().getString("fagentnum");
  66. if ((getOwner() instanceof saorder || getOwner() instanceof saorderdetail) && "特殊订单".equals(getOwner().getString("ftype"))) {
  67. setValue("fsaleprice", getCardPriceByAagentnum(fagentnum));
  68. } else {
  69. setValue("fsaleprice", getAgentSalePrice(fagentnum));
  70. }
  71. PaoSetRemote tfavorites = getPaoSet("tfavorites");
  72. tfavorites.setWhere("fagentnum='" + fagentnum + "' and fiscollection=1");
  73. tfavorites.reset();
  74. if (!tfavorites.isEmpty()) {
  75. setValue("fiscollection", true, 11L);
  76. }
  77. }
  78. String appname = getThisPaoSet().getApp();
  79. // 商品信息查询
  80. if ("TITEMQUERY".equalsIgnoreCase(appname)) {
  81. fagentnum = getAgentnumByHrid(getUserName());
  82. setValue("fsaleprice", getAgentSalePrice(fagentnum));
  83. }
  84. if (!"".equals(fagentnum)) {
  85. PaoSetRemote tfavorites = getPaoSet("tfavorites");
  86. tfavorites.setWhere("fagentnum='" + fagentnum + "' and fiscollection=1");
  87. tfavorites.reset();
  88. if (!tfavorites.isEmpty()) {
  89. setValue("fiscollection", true, 11L);
  90. }
  91. }
  92. if ("TOOLBOOK".equalsIgnoreCase(appname)) {
  93. //工具借出台账借出数量查询
  94. PaoSetRemote saorderdetailSet = getPaoSet("SAORDERDETAIL");
  95. saorderdetailSet.setWhere("ftype='工具借出单' and (isnull(fqty, 0) - isnull(fundeliqty, 0) - isnull(freturnqty, 0)) > 0");
  96. saorderdetailSet.reset();
  97. setValue("faddqty", saorderdetailSet.sum("fqty") - saorderdetailSet.sum("fundeliqty") - saorderdetailSet.sum("freturnqty"), 11L);
  98. }
  99. }
  100. } catch (Exception e) {
  101. }
  102. }
  103. /**
  104. * 图片上传显示
  105. */
  106. public void refreshimg() throws P2Exception {
  107. PaoSetRemote DOCLINKS = P2Server.getP2Server().getPaoSet("DOCLINKS",
  108. getUserInfo());
  109. DOCLINKS.setWhere("ownertable='"
  110. + getName()
  111. + "' and ownerid='"
  112. + getUniqueIDValue()
  113. + "' and docinfoid in(select docinfoid from docinfo where postfix in('JPG','JPEG','PNG','GIF','BMP'))");
  114. DOCLINKS.reset();
  115. setValue("fpic1", "", 11L);
  116. setValue("fpic2", "", 11L);
  117. setValue("fpic3", "", 11L);
  118. setValue("fpic4", "", 11L);
  119. int n = 1;
  120. for (int i = 0; i < DOCLINKS.count(); i++) {
  121. if (!DOCLINKS.getPao(i).getString("document").contains("BarCode")) {
  122. if (n <= 3) {
  123. setValue("fpic" + (n++),
  124. DOCLINKS.getPao(i).getInt("docinfoid"), 11L);
  125. }
  126. } else {
  127. setValue("fpic4", DOCLINKS.getPao(i).getInt("docinfoid"), 11L);
  128. }
  129. }
  130. for (int i = 0; i < DOCLINKS.count(); i++) {
  131. if (DOCLINKS.getPao(i).getString("document").contains("BarCode")) {
  132. setValue("fpic4", DOCLINKS.getPao(i).getInt("docinfoid"), 11L);
  133. }
  134. }
  135. getThisPaoSet().save();
  136. }
  137. @Override
  138. protected void save() throws P2Exception {
  139. super.save();
  140. PaoSetRemote paoset = getPaoSet("titemsaleprice");
  141. if (paoset.isEmpty()) {
  142. if (toBeAdded() || !isModified("fitemno")) {
  143. int count = getSysVars(getString("siteid")).getInt("fitemsalepricecount");
  144. for (int i = 1; i <= count; i++) {
  145. PaoRemote pao = paoset.addAtEnd();
  146. pao.setValue("fitemno", getString("fitemno"), 11L);
  147. pao.setValue("fpricegrade", i + "", 11L);
  148. pao.setValue("fprice", 0, 11L);
  149. }
  150. }
  151. }
  152. if (toBeAdded()) {
  153. distinctfieldcheck("fitemno");
  154. }
  155. }
  156. @Override
  157. public void modify() throws P2Exception {
  158. super.modify();
  159. }
  160. @Override
  161. public void checkvalidate(boolean fischeck) throws P2Exception {
  162. if (fischeck) {
  163. if (!"新建".equals(getString("fstatus"))) {
  164. throw new P2AppException("", "非新建状态不能审核");
  165. }
  166. if (getDouble("fpackingqty") <= 0) {
  167. throw new P2AppException("", "每件数量必须大于0");
  168. }
  169. if (getDouble("fsaleaddqty") <= 0) {
  170. throw new P2AppException("", "销售增量必须大于0");
  171. }
  172. if (getDouble("fsaleminqty") <= 0) {
  173. throw new P2AppException("", "销售起订量必须大于0");
  174. }
  175. } else {
  176. if (!"审核".equals(getString("fstatus"))) {
  177. throw new P2AppException("", "非审核状态不能反审核");
  178. }
  179. if (getBoolean("FISONSALE")) {
  180. throw new P2AppException("", "非下架状态不能反审核");
  181. }
  182. if (getBoolean("FISUSED")) {
  183. throw new P2AppException("", "非停用状态不能反审核");
  184. }
  185. }
  186. }
  187. @Override
  188. public void check(boolean fischeck) throws P2Exception {
  189. setValue("fstatus", fischeck ? "审核" : "新建", 11L);
  190. setValue("checkby", fischeck ? getUserName() : "", 11L);
  191. setValue("checkdate", fischeck ? getDateTime() : null, 11L);
  192. }
  193. @Override
  194. public void usedvalidate(boolean used) throws P2Exception {
  195. if (used) {
  196. if (getBoolean("fisused")) {
  197. throw new P2AppException("", "非停用状态不能启用");
  198. }
  199. if (!"审核".equals(getString("fstatus"))) {
  200. throw new P2AppException("", "非审核状态不能启用");
  201. }
  202. } else {
  203. if (!getBoolean("fisused")) {
  204. throw new P2AppException("", "非启用状态不能停用");
  205. }
  206. if (getBoolean("FISONSALE")) {
  207. throw new P2AppException("", "非下架状态不能停用");
  208. }
  209. }
  210. }
  211. @Override
  212. public void used(boolean used) throws P2Exception {
  213. setValue("fisused", used, 11L);
  214. }
  215. public void salevalidate(boolean sale) throws P2Exception {
  216. if (sale) {
  217. if (getBoolean("fisonsale")) {
  218. throw new P2AppException("", "非下架状态不能上架");
  219. }
  220. if (!getBoolean("fisused")) {
  221. throw new P2AppException("", "非启用状态不能上架");
  222. }
  223. if (!"审核".equals(getString("fstatus"))) {
  224. throw new P2AppException("", "非审核状态不能上架");
  225. }
  226. if ("".equals(getString("fsaleclsnum"))) {
  227. throw new P2AppException("", "营销类别为空不能上架");
  228. }
  229. if (getDouble("fsaleminqty") <= 0) {
  230. throw new P2AppException("", "销售起订量必须大于0");
  231. }
  232. if (getDouble("fsaleaddqty") <= 0) {
  233. throw new P2AppException("", "销售赠量必须大于0");
  234. }
  235. } else {
  236. if (!getBoolean("fisonsale")) {
  237. throw new P2AppException("", "非上架状态不能下架");
  238. }
  239. if (!getPaoSet("titemgroup").isEmpty()) {
  240. throw new P2AppException("", "当前商品为商品组" + getPaoSet("titemgroup").getPao(0).getString("fgroupnum") + "的默认商品,不能下架");
  241. }
  242. }
  243. }
  244. public void sale(boolean sale) throws P2Exception {
  245. setValue("fisonsale", sale, 11L);
  246. }
  247. @Override
  248. public void canDelete() throws P2Exception {
  249. super.canDelete();
  250. if (!"新建".equals(getString("fstatus"))) {
  251. throw new P2AppException("", "非新建状态下不能删除");
  252. }
  253. if (getBoolean("fisused")) {
  254. throw new P2AppException("", "非停用状态下不能删除");
  255. }
  256. if (getBoolean("fisonsale")) {
  257. throw new P2AppException("", "非下架状态下不能删除");
  258. }
  259. checkused("不可删除");
  260. }
  261. /**
  262. * 检查物料是否被使用过
  263. *
  264. * @throws P2Exception
  265. */
  266. public void checkused() throws P2Exception {
  267. checkused();
  268. }
  269. /**
  270. * 检查物料是否被使用过
  271. *
  272. * @param msg
  273. * @throws P2Exception
  274. */
  275. public void checkused(String msg) throws P2Exception {
  276. if (getPaoSet("ICINVBAL").count() > 0) {
  277. throw new P2AppException("", "该物料存在库存信息," + msg);
  278. }
  279. if (getPaoSet("saorderdetail").count() > 0) {
  280. throw new P2AppException("", "该物料存在订单信息," + msg);
  281. }
  282. if (getPaoSet("icstockbilldetail").count() > 0) {
  283. throw new P2AppException("", "该物料存在出入库信息," + msg);
  284. }
  285. if (getPaoSet("BOMHEAD").count() > 0) {
  286. throw new P2AppException("", "该物料存在BOM信息," + msg);
  287. }
  288. if (getPaoSet("BOM").count() > 0) {
  289. throw new P2AppException("", "该物料存在BOM信息," + msg);
  290. }
  291. if (getPaoSet("TPRDETAIL").count() > 0) {
  292. throw new P2AppException("", "该物料存在请购信息," + msg);
  293. }
  294. if (getPaoSet("TPODETAIL").count() > 0) {
  295. throw new P2AppException("", "该物料存在采购信息," + msg);
  296. }
  297. }
  298. public void modifycustvalidate() throws P2Exception {
  299. if (!"新建".equals(getString("fstatus"))) {
  300. throw new P2AppException("", "非新建状态不能修改");
  301. }
  302. checkused("不能修改");
  303. }
  304. public void modifycust() throws P2Exception {
  305. setFieldFlag(new String[]{"funitid", "fitemclsnum", "FISABSTRACT",
  306. "fbarcode"}, READONLY, false);
  307. }
  308. @Override
  309. public void delete(long arg0) throws P2Exception {
  310. super.delete(arg0);
  311. }
  312. /**
  313. * 根据经销商编号获取商品牌价
  314. *
  315. * @param fagentnum
  316. * @return
  317. * @throws P2Exception
  318. */
  319. public double getCardPriceByAagentnum(String fagentnum)
  320. throws P2Exception {
  321. PaoSetRemote agentpricegrade_view = P2Server.getP2Server()
  322. .getPaoSet("agentpricegrade_view", getUserInfo());
  323. agentpricegrade_view.setWhere("fagentnum='" + fagentnum
  324. + "' and siteid='" + getSite() + "'");
  325. agentpricegrade_view.reset();
  326. if (agentpricegrade_view.isEmpty()) {
  327. throw new P2AppException("", "找不到经销商对应价格等级信息");
  328. }
  329. String fpricegrade = agentpricegrade_view.getPao(0).getString(
  330. "fpricegrade");
  331. String mapkey = getSite() + "_" + getString("fitemno") + "_"
  332. + fpricegrade;
  333. if (!titemsaleprice.itemsalepricemap.containsKey(mapkey)) {
  334. PaoSetRemote titemsalepriceset = P2Server.getP2Server().getPaoSet(
  335. "titemsaleprice", getUserInfo());
  336. int i = 0;
  337. PaoRemote pao = null;
  338. while ((pao = titemsalepriceset.getPao(i)) != null) {
  339. String mapkey1 = pao.getString("siteid") + "_"
  340. + pao.getString("fitemno") + "_"
  341. + pao.getString("fpricegrade");
  342. titemsaleprice.itemsalepricemap.put(mapkey1,
  343. pao.getDouble("fprice"));
  344. i++;
  345. }
  346. }
  347. if (titemsaleprice.itemsalepricemap.containsKey(mapkey)) {
  348. return titemsaleprice.itemsalepricemap.get(mapkey);
  349. } else {
  350. return 0;
  351. }
  352. }
  353. /**
  354. * 根据价格等级获取商品牌价
  355. *
  356. * @param fpricegrade
  357. * @return
  358. * @throws P2Exception
  359. */
  360. public double getCardPriceByGrade(String fpricegrade)
  361. throws P2Exception {
  362. String mapkey = getSite() + "_" + getString("fitemno") + "_" + fpricegrade;
  363. if (!titemsaleprice.itemsalepricemap.containsKey(mapkey)) {
  364. PaoSetRemote titemsalepriceset = P2Server.getP2Server().getPaoSet(
  365. "titemsaleprice", getUserInfo());
  366. int i = 0;
  367. PaoRemote pao = null;
  368. while ((pao = titemsalepriceset.getPao(i)) != null) {
  369. String mapkey1 = pao.getString("siteid") + "_"
  370. + pao.getString("fitemno") + "_"
  371. + pao.getString("fpricegrade");
  372. titemsaleprice.itemsalepricemap.put(mapkey1,
  373. pao.getDouble("fprice"));
  374. i++;
  375. }
  376. }
  377. if (titemsaleprice.itemsalepricemap.containsKey(mapkey)) {
  378. return titemsaleprice.itemsalepricemap.get(mapkey);
  379. } else {
  380. return 0;
  381. }
  382. }
  383. /**
  384. * 获取经销商单价
  385. *
  386. * @return
  387. */
  388. public double getAgentSalePrice(String fagentnum) throws P2Exception {
  389. //牌价
  390. double fprice = getCardPriceByAagentnum(fagentnum);
  391. return getAgentSalePrice(fprice, fagentnum);
  392. }
  393. /**
  394. * 获取经销商单价
  395. *
  396. * @return
  397. */
  398. public double getAgentSalePrice(double fprice, String fagentnum) throws P2Exception {
  399. boolean fisprojectorder = false;
  400. if ("".equals(fprojectnum)) {
  401. if (getOwner() != null && getOwner() instanceof saorderdetail) {
  402. fisprojectorder = "项目订单".equals(getOwner().getString("ftype"));
  403. if (!getOwner().getPaoSet("saorder").isEmpty()) {
  404. fprojectnum = getOwner().getPaoSet("saorder").getPao(0).getString("fprojectnum");
  405. } else if (getOwner().getOwner() instanceof saorder) {
  406. fprojectnum = getOwner().getOwner().getString("fprojectnum");
  407. }
  408. }
  409. } else {
  410. fisprojectorder = true;
  411. }
  412. if (fisprojectorder) {
  413. //项目订单
  414. //项目管理商品折扣表
  415. PaoSetRemote tproject_pricecartelSet = getPaoSet("$tproject_pricecartel", "tproject_pricecartel", "fprojectnum='" + fprojectnum + "' and fitemno='" + getString("fitemno") + "'");
  416. if (!tproject_pricecartelSet.isEmpty()) {
  417. PaoRemote pao = tproject_pricecartelSet.getPao(0);
  418. if ("折扣系数".equals(pao.getString("ftype"))) {
  419. if ("HY".equals(getString("siteid"))) {
  420. return Math.mul(pao.getDouble("fdiscountrate"), fprice, 0);
  421. } else {
  422. return Math.mul(pao.getDouble("fdiscountrate"), fprice, 2);
  423. }
  424. } else if ("固定单价".equals(pao.getString("ftype"))) {
  425. return pao.getDouble("fdiscountrate");
  426. }
  427. }
  428. //项目管理类别折扣表
  429. PaoSetRemote tproject_cartelitemclass = getPaoSet("$tproject_cartelitemclass", "tproject_cartelitemclass", "fprojectnum='" + fprojectnum + "'");
  430. String flongsaleclsnum = getString("flongsaleclsnum");
  431. if (!tproject_cartelitemclass.isEmpty() && !"".equals(flongsaleclsnum)) {
  432. String[] fsaleclsnums = flongsaleclsnum.split("/");
  433. int length = fsaleclsnums.length;
  434. while (length > 0) {
  435. length--;
  436. //营销类别
  437. String fsaleclsnum = fsaleclsnums[length];
  438. int i = 0;
  439. while (tproject_cartelitemclass.getPao(i) != null) {
  440. //价格协议营销类别
  441. String fsaleclsnum2 = tproject_cartelitemclass.getPao(i).getString("fsaleclsnum");
  442. if (fsaleclsnum.equals(fsaleclsnum2)) {
  443. if ("HY".equals(getString("siteid"))) {
  444. return Math.mul(tproject_cartelitemclass.getPao(i).getDouble("fdiscountrate"), fprice, 0);
  445. } else {
  446. return Math.mul(tproject_cartelitemclass.getPao(i).getDouble("fdiscountrate"), fprice, 2);
  447. }
  448. }
  449. i++;
  450. }
  451. }
  452. }
  453. //项目管理折扣表
  454. PaoSetRemote tprojectSet = getPaoSet("$tproject", "tproject", "fprojectnum='" + fprojectnum + "'");
  455. if ("HY".equals(getString("siteid"))) {
  456. return Math.mul(tprojectSet.getPao(0).getDouble("fdiscountrate"), fprice, 0);
  457. } else {
  458. return Math.mul(tprojectSet.getPao(0).getDouble("fdiscountrate"), fprice, 2);
  459. }
  460. } else {
  461. if (getBoolean("fiswuliao") || getBoolean("fistool")) {
  462. return fprice;
  463. }
  464. PaoSetRemote tpricecarteldetailSet = getPaoSet("$tpricecarteldetail", "tpricecarteldetail", "fagentnum='" + fagentnum + "' and fitemno='" + getString("fitemno") + "'");
  465. if (!tpricecarteldetailSet.isEmpty()) {
  466. PaoRemote pao = tpricecarteldetailSet.getPao(0);
  467. if ("折扣系数".equals(pao.getString("ftype"))) {
  468. if ("HY".equals(getString("siteid"))) {
  469. return Math.mul(pao.getDouble("fdiscountrate"), fprice, 0);
  470. } else {
  471. return Math.mul(pao.getDouble("fdiscountrate"), fprice, 2);
  472. }
  473. } else if ("固定单价".equals(pao.getString("ftype"))) {
  474. return pao.getDouble("fdiscountrate");
  475. }
  476. }
  477. PaoSetRemote tpricecartelSet = getPaoSet("$tpricecartel", "tpricecartel", "fagentnum='" + fagentnum + "' and fstatus='审核' and fbegdate<=GETDATE() and fenddate>=GETDATE()");
  478. if (!tpricecartelSet.isEmpty()) {
  479. //价格协议类别折扣表
  480. PaoSetRemote tpricecartel_itemclass = tpricecartelSet.getPao(0).getPaoSet("tpricecartel_itemclass");
  481. String flongsaleclsnum = getString("flongsaleclsnum");
  482. if (!tpricecartel_itemclass.isEmpty() && !"".equals(flongsaleclsnum)) {
  483. String[] fsaleclsnums = flongsaleclsnum.split("/");
  484. int length = fsaleclsnums.length;
  485. while (length > 0) {
  486. length--;
  487. //营销类别
  488. String fsaleclsnum = fsaleclsnums[length];
  489. int i = 0;
  490. while (tpricecartel_itemclass.getPao(i) != null) {
  491. //价格协议营销类别
  492. String fsaleclsnum2 = tpricecartel_itemclass.getPao(i).getString("fsaleclsnum");
  493. if (fsaleclsnum.equals(fsaleclsnum2)) {
  494. if ("HY".equals(getString("siteid"))) {
  495. return Math.mul(tpricecartel_itemclass.getPao(i).getDouble("fdiscountrate"), fprice, 0);
  496. } else {
  497. return Math.mul(tpricecartel_itemclass.getPao(i).getDouble("fdiscountrate"), fprice, 2);
  498. }
  499. }
  500. i++;
  501. }
  502. }
  503. }
  504. if ("HY".equals(getString("siteid"))) {
  505. return Math.mul(tpricecartelSet.getPao(0).getDouble("fdiscountrate"), fprice, 0);
  506. } else {
  507. return Math.mul(tpricecartelSet.getPao(0).getDouble("fdiscountrate"), fprice, 2);
  508. }
  509. }
  510. if ("HY".equals(getString("siteid"))) {
  511. return Math.mul(fprice, getPriceRate1(fagentnum), 0);
  512. } else {
  513. return Math.mul(fprice, getPriceRate1(fagentnum), 2);
  514. }
  515. }
  516. }
  517. /**
  518. * 获取等级价格系数
  519. *
  520. * @return
  521. */
  522. public double getPriceRate1(String fagentnum) throws P2Exception {
  523. PaoSetRemote AGENTPRICEGRADE_VIEW = getPaoSet("$agentpricegrade_view",
  524. "agentpricegrade_view", "fagentnum='" + fagentnum
  525. + "' and siteid='" + getString("siteid") + "'");
  526. if (!AGENTPRICEGRADE_VIEW.isEmpty()) {
  527. return AGENTPRICEGRADE_VIEW.getPao(0).getDouble("fpricerate");
  528. }
  529. return 1;
  530. }
  531. @Override
  532. public void fieldAction(Object paoField, String fieldname)
  533. throws P2Exception {
  534. super.fieldAction(paoField, fieldname);
  535. if ("FBARCODE".equals(fieldname)) {
  536. if (!"".equals(getString("FBARCODE"))
  537. && getSysVars().getBoolean("FISCREATEBARCODEPIC")) {
  538. String filename = getString("fitemno") + "_BarCode";
  539. String objectname = getName();
  540. PaoSetRemote DOCLINKS = P2Server.getP2Server().getPaoSet(
  541. "DOCLINKS", getUserInfo());
  542. DOCLINKS.setWhere("document='" + filename
  543. + ".png' and ownerid='" + getUniqueIDValue()
  544. + "' and ownertable='" + objectname + "'");
  545. DOCLINKS.reset();
  546. try {
  547. createBarCode(getString("FBARCODE"), filename);
  548. refreshimg();
  549. } catch (Exception e) {
  550. throw new P2AppException("", "条形码生成失败");
  551. }
  552. }
  553. } else if ("FSALECLSNUM".equals(fieldname)) {
  554. String fsaleclsnum = getString("fsaleclsnum");
  555. if ("".equals(fsaleclsnum)) {
  556. setValue("flongsaleclsnum", "", 11L);
  557. } else {
  558. String flongsaleclsnum = fsaleclsnum;
  559. boolean hasup = true;
  560. while (hasup) {
  561. PaoSetRemote titemclass = P2Server.getP2Server().getPaoSet("titemclass", getUserInfo());
  562. titemclass.setWhere("fitemclsnum='" + fsaleclsnum + "' and fclasstype='营销类别' and fupclass is not null");
  563. titemclass.reset();
  564. if (titemclass.isEmpty()) {
  565. hasup = false;
  566. } else {
  567. fsaleclsnum = titemclass.getPao(0).getString("fupclass");
  568. flongsaleclsnum = fsaleclsnum + "/" + flongsaleclsnum;
  569. }
  570. }
  571. setValue("flongsaleclsnum", flongsaleclsnum, 11L);
  572. }
  573. }
  574. }
  575. @Override
  576. public PaoSetRemote fieldGetlist(Object paoField, PaoSetRemote list,
  577. String fieldname) throws P2Exception {
  578. PaoSetRemote paoset = super.fieldGetlist(paoField, list, fieldname);
  579. if (fieldname.equals("FSALECLSNUM")) {
  580. if(getBoolean("FISTOOL")){
  581. paoset.setWhere("fistool=1");
  582. }else{
  583. paoset.setWhere("fistool=0");
  584. }
  585. }
  586. return paoset;
  587. }
  588. @Override
  589. public void fieldValidate(Object paoField, String fieldname)
  590. throws P2Exception {
  591. super.fieldValidate(paoField, fieldname);
  592. if ("FITEMNO".equals(fieldname)) {
  593. distinctfieldcheck(fieldname);
  594. } else if ("FSALECLSNUM".equals(fieldname)) {
  595. if (getBoolean("FISABSTRACT")
  596. && !"".equals(getString("FSALECLSNUM"))) {
  597. throw new P2AppException("", "虚拟件,不可销售");
  598. }
  599. } else if ("FISABSTRACT".equals(fieldname)) {
  600. if (getBoolean("FISABSTRACT")
  601. && !"".equals(getString("FSALECLSNUM"))) {
  602. throw new P2AppException("", "已设置营销类别,不可设置为虚拟件");
  603. }
  604. } else if ("FPACKINGQTY".equals(fieldname)) {
  605. if (getDouble("FPACKINGQTY") <= 0) {
  606. throw new P2AppException("", "每件数量必须大于0");
  607. }
  608. } else if ("FISSINGLE".equals(fieldname)) {
  609. if (getPaoSet("ICINVBAL").count() > 0) {
  610. throw new P2AppException("", "存在库存,不可修改");
  611. }
  612. } else if ("FBARCODE".equals(fieldname)) {
  613. /*
  614. * if (!getString("FBARCODE").equals("") &&
  615. * getString("FBARCODE").length() != 12) { throw new
  616. * P2AppException("", "条形码必须为12位(最后一位打印时自动生成)"); }
  617. */
  618. }
  619. }
  620. /**
  621. * 生成69条形码
  622. *
  623. * @param message
  624. * @param filename
  625. * @throws IOException
  626. */
  627. public void createBarCode(String message, String filename)
  628. throws P2Exception, IOException {
  629. StringBuffer stringBuffer = new StringBuffer(P2Server.getP2Server()
  630. .getConfig().getProperty("p2.attachment.defaultpath"));
  631. PaoSetRemote PS_SYSVARS = getPaoSet("$PS_SYSVARS", "PS_SYSVARS");
  632. PS_SYSVARS.setWhere("varname='DOCUMENT_DIR_RULE'");
  633. PS_SYSVARS.reset();
  634. if (!PS_SYSVARS.isEmpty()) {
  635. String[] a = PS_SYSVARS.getPao(0).getString("varvalue").split("/");
  636. String site = getSite();
  637. stringBuffer.append(File.separator + site);
  638. for (int i = 1; i < a.length; i++) {
  639. if ("DOCTYPE".equalsIgnoreCase(a[i])) {
  640. stringBuffer.append(File.separator + getString("doctype"));
  641. } else if ("TABLE".equalsIgnoreCase(a[i])) {
  642. stringBuffer.append(File.separator + getName());
  643. }
  644. }
  645. }
  646. EAN13Bean bean = new EAN13Bean();// 条形码类型
  647. final int dpi = 150;
  648. final double moduleWidth = UnitConv.in2mm(2.0f / dpi);
  649. bean.setModuleWidth(moduleWidth);
  650. bean.doQuietZone(true);
  651. String format = "image/png";
  652. FileOutputStream stream = new FileOutputStream(stringBuffer.toString()
  653. + "/" + filename);
  654. BitmapCanvasProvider canvas = new BitmapCanvasProvider(stream, format,
  655. dpi, BufferedImage.TYPE_BYTE_BINARY, false, 0);
  656. bean.generateBarcode(canvas, message);
  657. canvas.finish();
  658. stream.flush();
  659. stream.close();
  660. String serialnumber = filename;
  661. String document = filename + ".png";
  662. String objectname = getName();
  663. PaoSetRemote DOCINFOSET = P2Server.getP2Server().getPaoSet("DOCINFO",
  664. getUserInfo());
  665. DOCINFOSET.setWhere("document='" + document + "' and ownertable='"
  666. + objectname + "' and description='69条形码' and serialnumber='"
  667. + serialnumber + "'");
  668. DOCINFOSET.reset();
  669. if (DOCINFOSET.isEmpty()) {
  670. PaoRemote docinfo = DOCINFOSET.addAtEnd();
  671. docinfo.setValue("document", document, 11L);
  672. docinfo.setValue("ownertable", objectname, 11L);
  673. docinfo.setValue("description", "69条形码", 11L);
  674. docinfo.setValue("postfix", "PNG", 11L);
  675. docinfo.setValue("doctype", "Attachments", 11L);
  676. docinfo.setValue("serialnumber", serialnumber, 11L);
  677. DOCINFOSET.save();
  678. if (docinfo.getPaoSet("DOCLINKS").isEmpty()) {
  679. PaoSetRemote DOCLINKSSET = docinfo.getPaoSet("DOCLINKS");
  680. PaoRemote doclinks = DOCLINKSSET.addAtEnd();
  681. doclinks.setValue("document", document, 11L);
  682. doclinks.setValue("docinfoid", docinfo.getLong("docinfoid"),
  683. 11L);
  684. doclinks.setValue("ownertable", objectname, 11L);
  685. doclinks.setValue("DOCTYPE", "Attachments", 11L);
  686. doclinks.setValue("description", "69条形码", 11L);
  687. doclinks.setValue("OWNERID", getUniqueIDValue(), 11L);
  688. docinfo.getPaoSet("DOCLINKS").save();
  689. PaoSetRemote DOCHISTORY = doclinks.getPaoSet("$DOCHISTORY",
  690. "DOCHISTORY", "");
  691. ((Doclinks) doclinks).addDochistory(DOCHISTORY, "ADD");
  692. DOCHISTORY.save();
  693. }
  694. }
  695. }
  696. @Override
  697. public PaoRemote duplicate() throws P2Exception {
  698. PaoRemote copyPao = copy();
  699. return copyPao;
  700. }
  701. /**
  702. * 复制时跳过的字段
  703. */
  704. @Override
  705. protected boolean skipCopyField(PaoFieldInfo arg0) throws P2Exception {
  706. String[] fields = {"FSTATUS", "CREATEDATE", "CREATEBY", "CHECKBY",
  707. "CHECKDATE", "FISUSED", "FISONSALE", "FLOWESTBOMCODE",
  708. "FLOWESTCOSTCODE"};
  709. return Arrays.asList(fields).contains(arg0.getName());
  710. }
  711. public void copyitemmsg() throws P2Exception {
  712. PaoSetRemote paoset = getPaoSet("$Titem", "titem", "fitemno='"
  713. + getString("FCOPYITEMNO") + "'");
  714. if (paoset.count() == 1) {
  715. titem titem = (titem) paoset.getPao(0);
  716. setValue("FITEMCLSNUM", titem.getString("FITEMCLSNUM"), 11L);
  717. setValue("FSALECLSNUM", titem.getString("FSALECLSNUM"), 11L);
  718. setValue("FGROSSWEIGHT", titem.getString("FGROSSWEIGHT"), 11L);
  719. setValue("FNETWEIGHT", titem.getString("FNETWEIGHT"), 11L);
  720. setValue("FSHAPESIZE", titem.getString("FSHAPESIZE"), 11L);
  721. setValue("FDEPNO", titem.getString("FDEPNO"), 11L);
  722. setValue("EXECUTIONSTANDARD", titem.getString("EXECUTIONSTANDARD"),
  723. 11L);
  724. setValue("FYGIENICLICENSE", titem.getString("FYGIENICLICENSE"), 11L);
  725. setValue("PRODUCTNAME", titem.getString("PRODUCTNAME"), 11L);
  726. setValue("FISPART", titem.getBoolean("FISPART"), 11L);
  727. setValue("FISLIMITITEMPARTS",
  728. titem.getBoolean("FISLIMITITEMPARTS"), 11L);
  729. setValue("FSTOCKNO", titem.getString("FSTOCKNO"), 11L);
  730. setValue("FICMINQTY", titem.getDouble("FICMINQTY"), 11L);
  731. setValue("FICADDQTY", titem.getDouble("FICADDQTY"), 11L);
  732. setValue("FPACKINGQTY", titem.getDouble("FPACKINGQTY"), 11L);
  733. setValue("FSALEMINQTY", titem.getDouble("FSALEMINQTY"), 11L);
  734. setValue("FSALEADDQTY", titem.getDouble("FSALEADDQTY"), 11L);
  735. setValue("FWARRANTYDAY", titem.getDouble("FWARRANTYDAY"), 11L);
  736. setValue("FSALEDAY", titem.getDouble("FSALEDAY"), 11L);
  737. } else {
  738. throw new P2AppException("", "请输入正确的货品编号");
  739. }
  740. }
  741. public void collection(boolean isclooection) throws P2Exception {
  742. PaoSetRemote tfavorites = getPaoSet("tfavorites");
  743. String fagentnum = getAgentnumByHrid(getUserName());
  744. tfavorites.setWhere("fagentnum='" + fagentnum + "'");
  745. tfavorites.reset();
  746. if (isclooection) {
  747. if (tfavorites.isEmpty()) {
  748. PaoRemote pao = tfavorites.addAtEnd();
  749. pao.setValue("fitemno", getString("fitemno"), 11L);
  750. pao.setValue("fagentnum", fagentnum, 11L);
  751. pao.setValue("fiscollection", true, 11L);
  752. } else {
  753. tfavorites.getPao(0).setValue("fiscollection", true, 11L);
  754. }
  755. } else {
  756. if (!tfavorites.isEmpty()) {
  757. tfavorites.getPao(0).setValue("fiscollection", false, 11L);
  758. }
  759. }
  760. }
  761. public void initStockMsg() throws P2Exception {
  762. icinvbalMsg icinvbal = new icinvbalMsg();
  763. icinvbal.caculate(getString("siteid"), new String[]{getString("fitemno")}, true);
  764. }
  765. public void changeitemno() throws P2Exception {
  766. String fitemnoxn = getString("fitemnoxn");
  767. if (fitemnoxn.equals("")) {
  768. throw new P2AppException("", "请填写新的产品编码");
  769. }
  770. String ferpitemnoxn = getString("ferpitemnoxn");
  771. if (ferpitemnoxn.equals("")) {
  772. throw new P2AppException("", "请填写新的erp品号");
  773. }
  774. DBConnect dbConnect = new DBConnect();
  775. Rows rows = dbConnect.runSqlQuery("select * from titem where fitemno='" + fitemnoxn + "' and siteid='" + getString("siteid") + "'");
  776. if (!rows.isEmpty()) {
  777. throw new P2AppException("", "品号" + fitemnoxn + "已被使用!");
  778. }
  779. setValue("fitemno", fitemnoxn, 11L);
  780. setValue("ferpitemno", ferpitemnoxn, 11L);
  781. }
  782. public void fielditemnamechange() throws P2Exception {
  783. DBConnect dbConnect = new DBConnect();
  784. if (!dbConnect.runSqlQuery("select *from ps_databind_list where value='" + getString("fieldnamelistnewvalue") + "' where siteid='" + getString("siteid") + "' and databindid='TAGENTS_FIELDNAME'").isEmpty()) {
  785. throw new P2AppException("", "新领域名称已存在!");
  786. }
  787. SQLFactory sqlFactory = new SQLFactory(this, "领域更新");
  788. sqlFactory.addParameter("fnewfieldname", getString("fieldnamelistnewvalue"));
  789. sqlFactory.addParameter("foldfieldname", getString("fieldnamelistoldvalue"));
  790. sqlFactory.addParameter("siteid", getString("siteid"));
  791. String status = dbConnect.runSqlUpdate(sqlFactory.getSQL());
  792. if (status.equals("true")) {
  793. throw new P2AppException("", "调整成功");
  794. } else {
  795. throw new P2AppException("", status);
  796. }
  797. }
  798. public void branditemnamechange() throws P2Exception {
  799. DBConnect dbConnect = new DBConnect();
  800. if (!dbConnect.runSqlQuery("select *from ps_databind_list where value='" + getString("brandlistnewvalue") + "' where siteid='" + getString("siteid") + "' and databindid='TITEM_FBRAND'").isEmpty()) {
  801. throw new P2AppException("", "新品牌名称已存在!");
  802. }
  803. SQLFactory sqlFactory = new SQLFactory(this, "品牌更新");
  804. sqlFactory.addParameter("fnewbrand", getString("brandlistnewvalue"));
  805. sqlFactory.addParameter("foldbrand", getString("brandlistoldvalue"));
  806. sqlFactory.addParameter("siteid", getString("siteid"));
  807. String status = dbConnect.runSqlUpdate(sqlFactory.getSQL());
  808. if (status.equals("true")) {
  809. throw new P2AppException("", "调整成功");
  810. } else {
  811. throw new P2AppException("", status);
  812. }
  813. }
  814. }