QTRK.java 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. package beans.stockbill.bills;
  2. import common.BaseClass;
  3. import common.Controller;
  4. import common.YosException;
  5. import common.data.*;
  6. import java.util.ArrayList;
  7. public class QTRK extends BasicBill {
  8. public QTRK(Controller controller, long st_stockbillid) throws YosException {
  9. super(controller, st_stockbillid);
  10. }
  11. @Override
  12. public void checkValidate(boolean ischeck) throws YosException {
  13. if (ischeck) {
  14. RowsMap codeRowsMap = codeRows.toRowsMap("st_stockbill_itemsid");
  15. for (Row row : itemRows) {
  16. if (row.getBoolean("skucontrol")) {
  17. if (codeRowsMap.containsKey(row.getString("st_stockbill_itemsid"))) {
  18. if (codeRowsMap.get(row.getString("st_stockbill_itemsid")).size() != row.getInteger("qty")) {
  19. //throw new YosException("行号:"+row.getString("rowno")+"序列号数量和入库数量不一致");
  20. }
  21. } else {
  22. //throw new YosException("受序列号管控的商品,审核时必须有序列号");
  23. }
  24. }
  25. }
  26. }
  27. if ("配件入库".equals(billTypeMX) && ischeck) {
  28. Rows detailrows = dbConnect.runSqlQuery("select sourceid,qty,itemno from st_stockbill_items where st_stockbillid=" + st_stockbillid + " and sourceobject='sa_itemrequestitems' ");
  29. if (detailrows.isNotEmpty() && rb == 0) {
  30. throw new YosException("入库明细来源于领料单的其他入库单不可红冲");
  31. }
  32. QuerySQL querySQL = SQLFactory.createQuerySQL(dbConnect, "sa_itemrequestitems", "sa_itemrequestitemsid", "qty", "instockqty", "isclose").setTableAlias("t1");
  33. querySQL.addJoinTable(BaseClass.JOINTYPE.inner, "sa_itemrequest", "t2", "sa_itemrequestid=:sa_itemrequestid", "billno", "status");
  34. querySQL.setWhere("t1.sa_itemrequestitemsid", detailrows.toArrayList("sourceid"));
  35. RowsMap itemrequestitemsRowsMap = querySQL.query().toRowsMap("sa_itemrequestitemsid");
  36. for (Row row : detailrows) {
  37. long sourceid = row.getLong("sourceid");
  38. String itemno = row.getString("itemno");
  39. double intqty = row.getDouble("qty");
  40. if (!itemrequestitemsRowsMap.containsKey(String.valueOf(sourceid))) {
  41. throw new YosException("领料单ID:" + sourceid + ",配件编号" + itemno + "已被删除!");
  42. }
  43. Row itemrequestitemRow = itemrequestitemsRowsMap.get(String.valueOf(sourceid)).get(0);
  44. String billno = itemrequestitemRow.getString("billno");
  45. if (!itemrequestitemRow.getString("status").equals("审核")) {
  46. throw new YosException("领料单:" + billno + "不在审核状态");
  47. }
  48. if (itemrequestitemRow.getBoolean("isclose")) {
  49. throw new YosException("领料单:" + billno + ",配件" + itemno + "行已关闭");
  50. }
  51. if (intqty < 0) {
  52. throw new YosException("配件:" + row.getString("itemno") + "数量不能小于0");
  53. }
  54. }
  55. }
  56. super.checkValidate(ischeck);
  57. }
  58. @Override
  59. public ArrayList<String> getCheckSql(boolean ischeck) throws YosException {
  60. ArrayList<String> sqlList = super.getCheckSql(ischeck);
  61. if ("配件入库".equals(billTypeMX)) {
  62. Rows detailrows = dbConnect.runSqlQuery("select sourceid,sum(qty)as qty from st_stockbill_items where st_stockbillid=" + st_stockbillid + " and sourceobject='sa_itemrequestitems' ");
  63. if (detailrows.isNotEmpty()) {
  64. for (Row row : detailrows) {
  65. long sourceid = row.getLong("sourceid");
  66. double qty = row.getDouble("qty");
  67. if (ischeck) {
  68. sqlList.add("update sa_itemrequestitems set instockqty=ifnull(instockqty,0)+" + qty + " where sa_itemrequestitemsid=" + sourceid);
  69. } else {
  70. sqlList.add("update sa_itemrequestitems set instockqty=ifnull(instockqty,0)-" + qty + " where sa_itemrequestitemsid=" + sourceid);
  71. }
  72. }
  73. ArrayList<String> sa_itemrequestids = SQLFactory.createQuerySQL(dbConnect, "sa_itemrequestitems", "sa_itemrequestid").setWhere("sa_itemrequestitemsid", detailrows.toArrayList("sourceid")).query().toArrayList("sa_itemrequestid");
  74. if (ischeck) {
  75. UpdateSQL itemrequestitemsClose = SQLFactory.createUpdateSQL(dbConnect, "sa_itemrequestitems");
  76. itemrequestitemsClose.setValue("isclose", true);
  77. itemrequestitemsClose.setValue("closeby", controller.username);
  78. itemrequestitemsClose.setDateValue("closedate");
  79. itemrequestitemsClose.setWhere("instockqty>=qty");
  80. itemrequestitemsClose.setWhere("sa_itemrequestitemsid", detailrows.toArrayList("sourceid"));
  81. sqlList.add(itemrequestitemsClose.getSQL());
  82. UpdateSQL itemrequestClose = SQLFactory.createUpdateSQL(dbConnect, "sa_itemrequest");
  83. itemrequestClose.setValue("status", "关闭");
  84. itemrequestClose.setValue("closeby", controller.username);
  85. itemrequestClose.setDateValue("closedate");
  86. itemrequestClose.setWhere("sa_itemrequestids", sa_itemrequestids);
  87. itemrequestClose.setWhere("not exists(select * from sa_itemrequestitems where isclose=0 and sa_itemrequest.sa_itemrequestid=sa_itemrequestitems.sa_itemrequestid)");
  88. sqlList.add(itemrequestClose.getSQL());
  89. } else {
  90. UpdateSQL itemrequestitemsUnClose = SQLFactory.createUpdateSQL(dbConnect, "sa_itemrequestitems");
  91. itemrequestitemsUnClose.setValue("isclose", false);
  92. itemrequestitemsUnClose.setValue("closeby", null);
  93. itemrequestitemsUnClose.setValue("closedate", null);
  94. itemrequestitemsUnClose.setWhere("ifnull(instockqty,0)<qty");
  95. itemrequestitemsUnClose.setWhere("sa_itemrequestitemsid", detailrows.toArrayList("sourceid"));
  96. sqlList.add(itemrequestitemsUnClose.getSQL());
  97. UpdateSQL itemrequestClose = SQLFactory.createUpdateSQL(dbConnect, "sa_itemrequest");
  98. itemrequestClose.setValue("status", "审核");
  99. itemrequestClose.setValue("closeby", null);
  100. itemrequestClose.setValue("closedate", null);
  101. itemrequestClose.setWhere("sa_itemrequestids", sa_itemrequestids);
  102. itemrequestClose.setWhere("exists(select * from sa_itemrequestitems where isclose=0 and sa_itemrequest.sa_itemrequestid=sa_itemrequestitems.sa_itemrequestid)");
  103. sqlList.add(itemrequestClose.getSQL());
  104. }
  105. }
  106. }
  107. return sqlList;
  108. }
  109. @Override
  110. public boolean isInStock(boolean fischeck) {
  111. if (fischeck && rb == 1 || !fischeck && rb == 0) {
  112. return true;
  113. }
  114. return false;
  115. }
  116. }