| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129 |
- package beans.stockbill.bills;
- import common.BaseClass;
- import common.Controller;
- import common.YosException;
- import common.data.*;
- import java.util.ArrayList;
- public class QTRK extends BasicBill {
- public QTRK(Controller controller, long st_stockbillid) throws YosException {
- super(controller, st_stockbillid);
- }
- @Override
- public void checkValidate(boolean ischeck) throws YosException {
- if (ischeck) {
- RowsMap codeRowsMap = codeRows.toRowsMap("st_stockbill_itemsid");
- for (Row row : itemRows) {
- if (row.getBoolean("skucontrol")) {
- if (codeRowsMap.containsKey(row.getString("st_stockbill_itemsid"))) {
- if (codeRowsMap.get(row.getString("st_stockbill_itemsid")).size() != row.getInteger("qty")) {
- //throw new YosException("行号:"+row.getString("rowno")+"序列号数量和入库数量不一致");
- }
- } else {
- //throw new YosException("受序列号管控的商品,审核时必须有序列号");
- }
- }
- }
- }
- if ("配件入库".equals(billTypeMX) && ischeck) {
- Rows detailrows = dbConnect.runSqlQuery("select sourceid,qty,itemno from st_stockbill_items where st_stockbillid=" + st_stockbillid + " and sourceobject='sa_itemrequestitems' ");
- if (detailrows.isNotEmpty() && rb == 0) {
- throw new YosException("入库明细来源于领料单的其他入库单不可红冲");
- }
- QuerySQL querySQL = SQLFactory.createQuerySQL(dbConnect, "sa_itemrequestitems", "sa_itemrequestitemsid", "qty", "instockqty", "isclose").setTableAlias("t1");
- querySQL.addJoinTable(BaseClass.JOINTYPE.inner, "sa_itemrequest", "t2", "sa_itemrequestid=:sa_itemrequestid", "billno", "status");
- querySQL.setWhere("t1.sa_itemrequestitemsid", detailrows.toArrayList("sourceid"));
- RowsMap itemrequestitemsRowsMap = querySQL.query().toRowsMap("sa_itemrequestitemsid");
- for (Row row : detailrows) {
- long sourceid = row.getLong("sourceid");
- String itemno = row.getString("itemno");
- double intqty = row.getDouble("qty");
- if (!itemrequestitemsRowsMap.containsKey(String.valueOf(sourceid))) {
- throw new YosException("领料单ID:" + sourceid + ",配件编号" + itemno + "已被删除!");
- }
- Row itemrequestitemRow = itemrequestitemsRowsMap.get(String.valueOf(sourceid)).get(0);
- String billno = itemrequestitemRow.getString("billno");
- if (!itemrequestitemRow.getString("status").equals("审核")) {
- throw new YosException("领料单:" + billno + "不在审核状态");
- }
- if (itemrequestitemRow.getBoolean("isclose")) {
- throw new YosException("领料单:" + billno + ",配件" + itemno + "行已关闭");
- }
- if (intqty < 0) {
- throw new YosException("配件:" + row.getString("itemno") + "数量不能小于0");
- }
- }
- }
- super.checkValidate(ischeck);
- }
- @Override
- public ArrayList<String> getCheckSql(boolean ischeck) throws YosException {
- ArrayList<String> sqlList = super.getCheckSql(ischeck);
- if ("配件入库".equals(billTypeMX)) {
- Rows detailrows = dbConnect.runSqlQuery("select sourceid,sum(qty)as qty from st_stockbill_items where st_stockbillid=" + st_stockbillid + " and sourceobject='sa_itemrequestitems' ");
- if (detailrows.isNotEmpty()) {
- for (Row row : detailrows) {
- long sourceid = row.getLong("sourceid");
- double qty = row.getDouble("qty");
- if (ischeck) {
- sqlList.add("update sa_itemrequestitems set instockqty=ifnull(instockqty,0)+" + qty + " where sa_itemrequestitemsid=" + sourceid);
- } else {
- sqlList.add("update sa_itemrequestitems set instockqty=ifnull(instockqty,0)-" + qty + " where sa_itemrequestitemsid=" + sourceid);
- }
- }
- ArrayList<String> sa_itemrequestids = SQLFactory.createQuerySQL(dbConnect, "sa_itemrequestitems", "sa_itemrequestid").setWhere("sa_itemrequestitemsid", detailrows.toArrayList("sourceid")).query().toArrayList("sa_itemrequestid");
- if (ischeck) {
- UpdateSQL itemrequestitemsClose = SQLFactory.createUpdateSQL(dbConnect, "sa_itemrequestitems");
- itemrequestitemsClose.setValue("isclose", true);
- itemrequestitemsClose.setValue("closeby", controller.username);
- itemrequestitemsClose.setDateValue("closedate");
- itemrequestitemsClose.setWhere("instockqty>=qty");
- itemrequestitemsClose.setWhere("sa_itemrequestitemsid", detailrows.toArrayList("sourceid"));
- sqlList.add(itemrequestitemsClose.getSQL());
- UpdateSQL itemrequestClose = SQLFactory.createUpdateSQL(dbConnect, "sa_itemrequest");
- itemrequestClose.setValue("status", "关闭");
- itemrequestClose.setValue("closeby", controller.username);
- itemrequestClose.setDateValue("closedate");
- itemrequestClose.setWhere("sa_itemrequestids", sa_itemrequestids);
- itemrequestClose.setWhere("not exists(select * from sa_itemrequestitems where isclose=0 and sa_itemrequest.sa_itemrequestid=sa_itemrequestitems.sa_itemrequestid)");
- sqlList.add(itemrequestClose.getSQL());
- } else {
- UpdateSQL itemrequestitemsUnClose = SQLFactory.createUpdateSQL(dbConnect, "sa_itemrequestitems");
- itemrequestitemsUnClose.setValue("isclose", false);
- itemrequestitemsUnClose.setValue("closeby", null);
- itemrequestitemsUnClose.setValue("closedate", null);
- itemrequestitemsUnClose.setWhere("ifnull(instockqty,0)<qty");
- itemrequestitemsUnClose.setWhere("sa_itemrequestitemsid", detailrows.toArrayList("sourceid"));
- sqlList.add(itemrequestitemsUnClose.getSQL());
- UpdateSQL itemrequestClose = SQLFactory.createUpdateSQL(dbConnect, "sa_itemrequest");
- itemrequestClose.setValue("status", "审核");
- itemrequestClose.setValue("closeby", null);
- itemrequestClose.setValue("closedate", null);
- itemrequestClose.setWhere("sa_itemrequestids", sa_itemrequestids);
- itemrequestClose.setWhere("exists(select * from sa_itemrequestitems where isclose=0 and sa_itemrequest.sa_itemrequestid=sa_itemrequestitems.sa_itemrequestid)");
- sqlList.add(itemrequestClose.getSQL());
- }
- }
- }
- return sqlList;
- }
- @Override
- public boolean isInStock(boolean fischeck) {
- if (fischeck && rb == 1 || !fischeck && rb == 0) {
- return true;
- }
- return false;
- }
- }
|