|
|
@@ -9,13 +9,13 @@ import common.data.db.DBConnect;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
-import java.util.ArrayList;
|
|
|
|
|
|
public abstract class BasicBill {
|
|
|
Controller controller;
|
|
|
DBConnect dbConnect;
|
|
|
UserInfo userInfo;
|
|
|
long sys_enterprise_stockbillid;
|
|
|
+ long sys_enterprise_stockid;
|
|
|
boolean issale;//是否销售出库
|
|
|
String billType;//单据类型
|
|
|
String billTypeMX;//单据类型
|
|
|
@@ -71,6 +71,17 @@ public abstract class BasicBill {
|
|
|
* @throws YosException
|
|
|
*/
|
|
|
public void checkValidate(boolean ischeck) throws YosException {
|
|
|
+ String billdate = billRow.getString("billdate");
|
|
|
+ if (billdate.isBlank()) {
|
|
|
+ throw new YosException("单据日期不能为空");
|
|
|
+ }
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(controller, "sys_enterprise_stockbill");
|
|
|
+ querySQL.setWhere("sys_enterprise_stockbillid", sys_enterprise_stockbillid);
|
|
|
+ querySQL.setWhere("DATE_FORMAT(billdate, '%Y-%m')>= DATE_FORMAT(NOW(), '%Y-%m')");
|
|
|
+ if (querySQL.query().isEmpty()) {
|
|
|
+ throw new YosException("单号为:【" + billno + "】的出入库单所在单据月份已关账,不可进行" + (ischeck ? "审核" : "反审核") + "操作!");
|
|
|
+ }
|
|
|
if (ischeck) {
|
|
|
if (!status.equals("新建")) {
|
|
|
throw new YosException("单号为:【" + billno + "】的出入库单为非新建状态,无法审核");
|
|
|
@@ -116,8 +127,8 @@ public abstract class BasicBill {
|
|
|
throw new YosException("单号为:【" + billno + "】的出入库单为非审核状态,无法反审核");
|
|
|
}
|
|
|
}
|
|
|
+ RowsMap itemskuRowsMap = SQLFactory.createQuerySQL(dbConnect, "sa_itemsku", "sys_enterpriseid", "sys_enterprise_stockid", "stockid", "sku").setWhere("sku", codeRows.toArrayList("sku")).query().toRowsMap("sku");
|
|
|
|
|
|
- RowsMap itemskuRowsMap = SQLFactory.createQuerySQL(dbConnect, "sa_itemsku", "sys_enterpriseid", "stockid", "sku").setWhere("sku", codeRows.toArrayList("sku")).query().toRowsMap("sku");
|
|
|
for (Row codeRow : codeRows) {
|
|
|
String sku = codeRow.getString("sku");
|
|
|
if (!itemskuRowsMap.containsKey(sku)) {
|
|
|
@@ -127,13 +138,18 @@ public abstract class BasicBill {
|
|
|
throw new YosException("序列号【" + sku + "】非当前经销商所属");
|
|
|
}
|
|
|
if (!isInStock(ischeck) && itemskuRowsMap.get(sku).get(0).getLong("stockid") != getAgentStockID()) {
|
|
|
+ throw new YosException("序列号【" + sku + "】不在经销商仓库中");
|
|
|
+ }
|
|
|
+ if (!isInStock(ischeck) && itemskuRowsMap.get(sku).get(0).getLong("sys_enterprise_stockid") != sys_enterprise_stockid) {
|
|
|
throw new YosException("序列号【" + sku + "】不在仓库中");
|
|
|
}
|
|
|
if (isInStock(ischeck) && itemskuRowsMap.get(sku).get(0).getLong("stockid") != 0) {
|
|
|
throw new YosException("序列号【" + sku + "】正在仓库中");
|
|
|
}
|
|
|
+ if (isInStock(ischeck) && itemskuRowsMap.get(sku).get(0).getLong("sys_enterprise_stockid") != 0) {
|
|
|
+ throw new YosException("序列号【" + sku + "】正在仓库中");
|
|
|
+ }
|
|
|
}
|
|
|
-
|
|
|
}
|
|
|
|
|
|
public SQLDump getCheckSql(boolean ischeck) throws YosException {
|
|
|
@@ -159,29 +175,26 @@ public abstract class BasicBill {
|
|
|
*/
|
|
|
|
|
|
private SQLDump updateInvbal(boolean ischeck) throws YosException {
|
|
|
+ for (String sys_enterprise_itemid : itemRows.toArrayList("sys_enterprise_itemid")) {
|
|
|
+ InsertSQL invbalInsert = SQLFactory.createInsertSQL(controller, "sys_enterprise_invbal");
|
|
|
+ invbalInsert.setValue("siteid", siteid);
|
|
|
+ invbalInsert.setValue("sys_enterpriseid", sys_enterpriseid);
|
|
|
+ invbalInsert.setValue("sys_enterprise_stockid", sys_enterprise_stockid);
|
|
|
+ invbalInsert.setValue("sys_enterprise_itemid", sys_enterprise_itemid);
|
|
|
+ invbalInsert.setValue("qty", 0);
|
|
|
+ invbalInsert.setWhere("not exists(select * from sys_enterprise_invbal where siteid='" + siteid + "' and sys_enterpriseid=" + sys_enterpriseid + " and sys_enterprise_stockid=" + sys_enterprise_stockid + " and sys_enterprise_itemid=" + sys_enterprise_itemid + " )");
|
|
|
+ invbalInsert.insert();
|
|
|
+ }
|
|
|
SQLDump sqlDump = new SQLDump();
|
|
|
- RowsMap invbalsRowsMap = SQLFactory.createQuerySQL(dbConnect, "sys_enterprise_invbal").setWhere("siteid", siteid).setWhere("sys_enterpriseid", sys_enterpriseid).setWhere("sys_enterprise_itemid", itemRows.toArrayList("sys_enterprise_itemid")).query().toRowsMap("sys_enterprise_itemid");
|
|
|
for (Row row : itemRows) {
|
|
|
- long sys_enterprise_itemid = row.getLong("sys_enterprise_itemid");
|
|
|
- long sys_enterprise_stockid = row.getLong("sys_enterprise_stockid");
|
|
|
BigDecimal qty = isInStock(ischeck) ? row.getBigDecimal("qty") : row.getBigDecimal("qty").negate();
|
|
|
- if (!invbalsRowsMap.containsKey(String.valueOf(sys_enterprise_itemid)) || !invbalsRowsMap.get(String.valueOf(sys_enterprise_itemid)).toRowsMap("sys_enterprise_stockid").containsKey(String.valueOf(sys_enterprise_stockid))) {
|
|
|
- InsertSQL invbalInsert = SQLFactory.createInsertSQL(controller, "sys_enterprise_invbal");
|
|
|
- invbalInsert.setValue("siteid", siteid);
|
|
|
- invbalInsert.setValue("sys_enterpriseid", sys_enterpriseid);
|
|
|
- invbalInsert.setValue("sys_enterprise_stockid", sys_enterprise_stockid);
|
|
|
- invbalInsert.setValue("sys_enterprise_itemid", sys_enterprise_itemid);
|
|
|
- invbalInsert.setValue("qty", qty.doubleValue());
|
|
|
- sqlDump.add(invbalInsert.getSQL());
|
|
|
- } else {
|
|
|
- UpdateSQL invbalUpdate = SQLFactory.createUpdateSQL(controller, "sys_enterprise_invbal");
|
|
|
- invbalUpdate.addValue("qty", qty);
|
|
|
- invbalUpdate.setValue("sys_enterpriseid", sys_enterpriseid);
|
|
|
- invbalUpdate.setWhere("sys_enterprise_itemid", sys_enterprise_itemid);
|
|
|
- invbalUpdate.setWhere("sys_enterprise_stockid", sys_enterprise_stockid);
|
|
|
- invbalUpdate.setWhere("siteid", siteid);
|
|
|
- sqlDump.add(invbalUpdate.getSQL());
|
|
|
- }
|
|
|
+ UpdateSQL invbalUpdate = SQLFactory.createUpdateSQL(controller, "sys_enterprise_invbal");
|
|
|
+ invbalUpdate.addValue("qty", qty.doubleValue());
|
|
|
+ invbalUpdate.setWhere("sys_enterpriseid", sys_enterpriseid);
|
|
|
+ invbalUpdate.setWhere("sys_enterprise_stockid", sys_enterprise_stockid);
|
|
|
+ invbalUpdate.setWhere("sys_enterprise_itemid", row.getLong("sys_enterprise_itemid"));
|
|
|
+ invbalUpdate.setWhere("siteid", siteid);
|
|
|
+ sqlDump.add(invbalUpdate.getSQL());
|
|
|
}
|
|
|
return sqlDump;
|
|
|
}
|
|
|
@@ -238,14 +251,17 @@ public abstract class BasicBill {
|
|
|
UpdateSQL saItemsku = SQLFactory.createUpdateSQL(controller, "sa_itemsku");
|
|
|
if (isInStock(ischeck)) {
|
|
|
saItemsku.setValue("stockid", getAgentStockID());
|
|
|
+ saItemsku.setValue("sys_enterprise_stockid", sys_enterprise_stockid);
|
|
|
saItemsku.setValue("status", "售出");
|
|
|
saItemsku.setValue("sys_enterpriseid", sys_enterpriseid);
|
|
|
} else {
|
|
|
saItemsku.setValue("stockid", 0);
|
|
|
+ saItemsku.setValue("sys_enterprise_stockid", 0);
|
|
|
saItemsku.setValue("status", "终端客户售出");
|
|
|
saItemsku.setValue("sys_enterpriseid", sys_enterpriseid);
|
|
|
}
|
|
|
saItemsku.setWhere("sku", sku);
|
|
|
+ saItemsku.setSiteid(siteid);
|
|
|
sqlDump.add(saItemsku.getSQL());
|
|
|
}
|
|
|
return sqlDump;
|
|
|
@@ -271,6 +287,7 @@ public abstract class BasicBill {
|
|
|
this.siteid = billRow.getString("siteid");
|
|
|
this.status = billRow.getString("status");
|
|
|
this.sys_enterpriseid = billRow.getLong("sys_enterpriseid");
|
|
|
+ this.sys_enterprise_stockid = billRow.getLong("sys_enterprise_stockid");
|
|
|
itemRows = dbConnect.runSqlQuery("select t1.* from sys_enterprise_stockbill_items t1 where sys_enterpriseid=" + sys_enterpriseid + " and t1.sys_enterprise_stockbillid ='" + sys_enterprise_stockbillid + "'");
|
|
|
codeRows = dbConnect.runSqlQuery("select t1.* from sys_enterprise_stockbill_skus t1 where sys_enterpriseid=" + sys_enterpriseid + " and t1.sys_enterprise_stockbillid ='" + sys_enterprise_stockbillid + "'");
|
|
|
}
|