|
@@ -1,560 +1,24 @@
|
|
|
package beans.stockbill;
|
|
|
|
|
|
-import beans.accountbalance.Accountbalance;
|
|
|
-import beans.accountbalance.CashbillEntity;
|
|
|
-import beans.datacontrllog.DataContrlLog;
|
|
|
-import beans.invbal.Invbal;
|
|
|
-import beans.parameter.Parameter;
|
|
|
-import com.alibaba.fastjson.JSONObject;
|
|
|
+import beans.stockbill.bills.BasicBill;
|
|
|
import common.BaseClass;
|
|
|
import common.Controller;
|
|
|
+import common.UserInfo;
|
|
|
import common.YosException;
|
|
|
-import common.data.*;
|
|
|
-import org.apache.commons.lang.StringUtils;
|
|
|
+import common.data.db.DBConnect;
|
|
|
+import org.apache.poi.ss.formula.functions.T;
|
|
|
|
|
|
-import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
|
|
|
public class Stockbill extends BaseClass {
|
|
|
- private static void checkValidate(Controller controller, long st_stockbillid, boolean ischeck) throws YosException {
|
|
|
- Rows rows = controller.dbConnect.runSqlQuery("select * from st_stockbill where st_stockbillid ='"
|
|
|
- + st_stockbillid + "' and siteid='" + controller.siteid + "'");
|
|
|
- Rows rowsdetail = controller.dbConnect.runSqlQuery("select t1.*,t2.skucontrol from st_stockbill_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid where t1.st_stockbillid ='"
|
|
|
- + st_stockbillid + "' and t1.siteid='" + controller.siteid + "'");
|
|
|
- String type=rows.get(0).getString("type");
|
|
|
- String str="success";
|
|
|
- if(type.equals("销售出库")){
|
|
|
- if(ischeck){
|
|
|
- str=xsckcheckValidate(controller,rows,rowsdetail);
|
|
|
- }else{
|
|
|
- str =unxsckcheckValidate(controller,rows,rowsdetail);
|
|
|
- }
|
|
|
- }else if (type.equals("外购入库")) {
|
|
|
|
|
|
- } else if (type.equals("生产领料出库")) {
|
|
|
-
|
|
|
- } else if (type.equals("委外领料出库")) {
|
|
|
-
|
|
|
- } else if (type.equals("生产入库") || type.equals("委外入库")) {
|
|
|
-
|
|
|
- } else if (type.equals("其他入库")) {
|
|
|
-
|
|
|
- } else if (type.equals("返修入库")) {// 云链
|
|
|
-
|
|
|
- } else if (type.equals("返修出库")) {// 云链
|
|
|
-
|
|
|
- }
|
|
|
- if(!str.equals("success")){
|
|
|
- throw new YosException(str);
|
|
|
- }
|
|
|
- }
|
|
|
public static ArrayList<String> getCheckSql(Controller controller, long st_stockbillid, boolean ischeck) throws YosException {
|
|
|
- Rows rows = controller.dbConnect.runSqlQuery("select * from st_stockbill where st_stockbillid ='"
|
|
|
- + st_stockbillid + "' and siteid='" + controller.siteid + "'");
|
|
|
- Rows rowsdetail = controller.dbConnect.runSqlQuery("select t1.*,t2.skucontrol from st_stockbill_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid where t1.st_stockbillid ='"
|
|
|
- + st_stockbillid + "' and t1.siteid='" + controller.siteid + "'");
|
|
|
- ArrayList<String> sqlList = new ArrayList<>();
|
|
|
- String type=rows.get(0).getString("type");
|
|
|
- boolean isinstock = isinstock(type,rows.get(0).getString("rb"),ischeck);
|
|
|
- checkValidate(controller,st_stockbillid,ischeck);
|
|
|
- if(type.equals("销售出库")){
|
|
|
- if(ischeck){
|
|
|
- sqlList.addAll(xsckcheck(controller,rows,rowsdetail,isinstock));
|
|
|
- }else{
|
|
|
- sqlList.addAll(unxsckcheck(controller,rows,rowsdetail,isinstock));
|
|
|
- }
|
|
|
-
|
|
|
- }else if (type.equals("外购入库")) {
|
|
|
-
|
|
|
- } else if (type.equals("生产领料出库")) {
|
|
|
-
|
|
|
- } else if (type.equals("委外领料出库")) {
|
|
|
-
|
|
|
- } else if (type.equals("生产入库") || type.equals("委外入库")) {
|
|
|
-
|
|
|
- } else if (type.equals("其他入库")) {
|
|
|
-
|
|
|
- } else if (type.equals("返修入库")) {// 云链
|
|
|
-
|
|
|
- } else if (type.equals("返修出库")) {// 云链
|
|
|
-
|
|
|
- }
|
|
|
- sqlList.addAll(updateIcinvbal(controller,isinstock,0,st_stockbillid));// 即时库存计算
|
|
|
- if(ischeck){
|
|
|
- SQLFactory sqlFactoryupdate = new SQLFactory(controller, "出入库单审核");
|
|
|
- sqlFactoryupdate.addParameter("siteid", controller.siteid);
|
|
|
- sqlFactoryupdate.addParameter("st_stockbillid", st_stockbillid);
|
|
|
- sqlFactoryupdate.addParameter("checkby", controller.username);
|
|
|
- sqlList.add(sqlFactoryupdate.getSQL());
|
|
|
- sqlList.add(DataContrlLog.createLog(controller, "st_stockbill", st_stockbillid, "审核", "出入库单审核成功").getSQL());
|
|
|
- }else{
|
|
|
- SQLFactory sqlFactoryupdate = new SQLFactory(controller, "出入库单反审核");
|
|
|
- sqlFactoryupdate.addParameter("siteid", controller.siteid);
|
|
|
- sqlFactoryupdate.addParameter("st_stockbillid", st_stockbillid);
|
|
|
- sqlFactoryupdate.addParameter("checkby", controller.username);
|
|
|
- sqlList.add(sqlFactoryupdate.getSQL());
|
|
|
- sqlList.add(DataContrlLog.createLog(controller, "st_stockbill", st_stockbillid, "反审核", "出入库单反审核成功").getSQL());
|
|
|
- }
|
|
|
- return sqlList;
|
|
|
+ BasicBill basicBill = BasicBill.getBill(controller, st_stockbillid);
|
|
|
+ basicBill.checkValidate(ischeck);
|
|
|
+ return basicBill.getCheckSql(ischeck);
|
|
|
}
|
|
|
|
|
|
public static void check(Controller controller, long st_stockbillid, boolean ischeck) throws YosException {
|
|
|
- controller.dbConnect.runSqlUpdate(getCheckSql(controller,st_stockbillid,ischeck));
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- public static String xsckcheckValidate(Controller controller, Rows rows, Rows rowsdetail) throws YosException {
|
|
|
- long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
|
|
|
- if (rows.isEmpty()) {
|
|
|
- return "该出入库单不存在";
|
|
|
- } else {
|
|
|
- if (!rows.get(0).getString("status").equals("新建")) {
|
|
|
- return "单号为:【" + rows.get(0).getString("billno") + "】的出入库单为非新建状态,无法审核";
|
|
|
- }
|
|
|
- }
|
|
|
- for(Row row : rowsdetail){
|
|
|
- if (row.getBigDecimal("qty").compareTo(BigDecimal.ZERO)<1) {
|
|
|
- return "表体数量不能小于0";
|
|
|
- }
|
|
|
- }
|
|
|
- if (rows.get(0).getBigDecimal("payamount").compareTo(BigDecimal.ZERO)<=0) {
|
|
|
- return "扣款金额需大于0";
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(rows.get(0).getString("outplace"))) {
|
|
|
- return "发货地不可为空";
|
|
|
- }
|
|
|
- if ((rows.get(0).getBigDecimal("payamount").add(rows.get(0).getBigDecimal("paydiscountamount"))).compareTo(rowsdetail.sum("amount"))!=0) {
|
|
|
- return "扣款金额与应扣金额不符,不能审核";
|
|
|
- }
|
|
|
- Rows accountbalancerows = controller.dbConnect.runSqlQuery("select * from sa_accountbalance t1 inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t2.accountname='现金账户' and t1.sys_enterpriseid="+sys_enterpriseid);
|
|
|
- if (accountbalancerows.isNotEmpty()) {
|
|
|
- BigDecimal discountamount = accountbalancerows.get(0).getBigDecimal("discountamount");
|
|
|
- if (rows.get(0).getBigDecimal("paydiscountamount").compareTo(discountamount)>0) {
|
|
|
- return "优惠金额不能大于可用优惠金额";
|
|
|
- }
|
|
|
- }else{
|
|
|
- return "账户不存在";
|
|
|
- }
|
|
|
- ArrayList<String> sqlList = new ArrayList<>();
|
|
|
-// Rows stockRows= dbConnect.runSqlQuery("select * from st_stock where siteid='"+siteid+"'");
|
|
|
-// RowsMap stockRowsMap =stockRows.toRowsMap("itemid");
|
|
|
-
|
|
|
- String order_paymentnode = Parameter.getString(controller.siteid, "order_paymentnode");
|
|
|
- if(rows.get(0).getBoolean("rb")){
|
|
|
- if(rows.get(0).getString("type").equals("销售出库")){
|
|
|
- if (order_paymentnode.equals("3")) {
|
|
|
- if (Accountbalance.judgeBalance(controller, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"),rowsdetail.sum("amount"))) {
|
|
|
-// CashbillEntity entity = getCashbillEntity(rows.get(0).getBigDecimal("payamount"),rows.get(0).getBigDecimal("paydiscountamount"), st_stockbillid, "销售出库单审核", rows.get(0).getString("billno"), "由销售出库单" + rows.get(0).getString("billno") + "审核时生成");
|
|
|
-// JSONObject createCashbillPay = Accountbalance.createCashbillPay(controller, sys_enterpriseid,accountbalancerows.get(0).getLong("sa_accountclassid"), entity, true);
|
|
|
-// sqlList.addAll(createCashbillPay.getJSONArray("sqlList").toJavaList(String.class));
|
|
|
- } else {
|
|
|
- return "账户余额不足,还差" + Accountbalance.InsufficientBalance(controller, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"),rowsdetail.sum("amount")) + "元!";
|
|
|
- }
|
|
|
- }
|
|
|
-// Rows rowsOrderDetail = dbConnect.runSqlQuery("select t1.undeliqty,t1.deliedqty,t1.qty,t1.sa_orderitemsid from sa_orderitems t1 where t1.sa_orderitemsid in (select sa_orderitemsid from st_stockbill_items where st_stockbillid=" + st_stockbillid + ")");
|
|
|
-// RowsMap rowsMap = rowsOrderDetail.toRowsMap("sa_orderitemsid");
|
|
|
-// Rows rowsDispatchDetailGroup = dbConnect.runSqlQuery("select sum(t1.qty) qty,t1.sa_orderitemsid,t1.siteid from st_stockbill_items t1 where t1.st_stockbillid=" + st_stockbillid + " group by t1.sa_orderitemsid,t1.siteid");
|
|
|
- Rows rowsjudge =controller.dbConnect.runSqlQuery("select * from (select sa_orderitemsid,sum(qty) qty from st_stockbill_items where st_stockbillid ='"+rows.get(0).getLong("st_stockbillid")+"' group by sa_orderitemsid) t1 inner join sa_orderitems t2 on t1.sa_orderitemsid=t2.sa_orderitemsid where t1.qty>t2.undeliqty");
|
|
|
- if(rowsjudge.isNotEmpty()){
|
|
|
- return "存在商品已完全出库,无法审核";
|
|
|
- }
|
|
|
-// for (Row row : rowsDispatchDetailGroup) {
|
|
|
-// sqlList.add("update sa_orderitems set undeliqty=" + rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("undeliqty").subtract(row.getBigDecimal("qty")) + ",deliedqty=" + (row.getBigDecimal("qty").add(rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("deliedqty"))) + " where sa_orderitemsid=" + row.getLong("sa_orderitemsid"));
|
|
|
-// }
|
|
|
-// for(Row row :rowsdetail){
|
|
|
-// if(row.getBoolean("skucontrol")){
|
|
|
-// sqlList.add("update st_stockbill_items set wmsuploadflag2=1 where st_stockbill_itemsid="+row.getLong("st_stockbill_itemsid"));
|
|
|
-// }
|
|
|
-//
|
|
|
-// }
|
|
|
- }
|
|
|
-// for(Row row :rowsdetail){
|
|
|
-// String itemid= row.getString("itemid");
|
|
|
-// long stockid=row.getLong("stockid");
|
|
|
-// if(stockRowsMap.containsKey(itemid)){
|
|
|
-// for(Row row1 :stockRowsMap.get(itemid)){
|
|
|
-// if(row1.getLong("stockid")==stockid){
|
|
|
-// sqlList.add("update st_stock set qty="+row1.getBigDecimal("qty").add(row.getBigDecimal("qty"))+" where stockid="+stockid);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// // String batchno = row.getString("batchno");
|
|
|
-// }
|
|
|
- }else{
|
|
|
-// for(Row row :rowsdetail){
|
|
|
-// String itemid= row.getString("itemid");
|
|
|
-// long stockid=row.getLong("stockid");
|
|
|
-// if(stockRowsMap.containsKey(itemid)){
|
|
|
-// for(Row row1 :stockRowsMap.get(itemid)){
|
|
|
-// if(row1.getLong("stockid")==stockid){
|
|
|
-// sqlList.add("update st_stock set qty="+row1.getBigDecimal("qty").subtract(row.getBigDecimal("qty"))+" where stockid="+stockid);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// // String batchno = row.getString("batchno");
|
|
|
-// }
|
|
|
- }
|
|
|
-// Rows stockbillitems = dbConnect.runSqlQuery("select t2.sa_orderid,sum(t2.price*t1.qty) amount from st_stockbill_items t1 inner join sa_orderitems t2 on t1.siteid=t2.siteid and t1.sa_orderitemsid=t2.sa_orderitemsid where t1.siteid='"+siteid+"'and t1.st_stockbillid="+st_stockbillid+" group by t2.sa_orderid");
|
|
|
-// Rows orderRows =dbConnect.runSqlQuery("select * from sa_order where sa_orderid in(select t2.sa_orderid from st_stockbill_items t1 inner join sa_orderitems t2 on t1.siteid=t2.siteid and t1.sa_orderitemsid=t2.sa_orderitemsid where t1.st_stockbillid='"+st_stockbillid+"')");
|
|
|
-// RowsMap orderRowsMap =orderRows.toRowsMap("sa_orderid");
|
|
|
-
|
|
|
-// sqlList.addAll(updateAccountbalance_freez(st_stockbillid,isinstock));
|
|
|
-//
|
|
|
-// dbConnect.runSqlUpdate(sqlList);
|
|
|
-// Accountbalance.remindSend(this, sys_enterpriseid, sa_cashbillid);
|
|
|
- return "success";
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- public static String unxsckcheckValidate(Controller controller,Rows rows,Rows rowsdetail) throws YosException {
|
|
|
-
|
|
|
- long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
|
|
|
-
|
|
|
- if (rows.isEmpty()) {
|
|
|
- return "该出入库单不存在";
|
|
|
- } else {
|
|
|
- if (!rows.get(0).getString("status").equals("审核")) {
|
|
|
- return "单号为:【" + rows.get(0).getString("billno") + "】的出入库单为非审核状态,无法反审核";
|
|
|
- }
|
|
|
- }
|
|
|
- for(Row row : rowsdetail){
|
|
|
- if (row.getBigDecimal("qty").compareTo(BigDecimal.ZERO)<1) {
|
|
|
- return "表体数量不能小于0";
|
|
|
- }
|
|
|
- }
|
|
|
- if (rows.get(0).getBigDecimal("paydiscountamount").compareTo(BigDecimal.ZERO)<0) {
|
|
|
- return "优惠金额不能小于0";
|
|
|
- }
|
|
|
- if (rows.get(0).getBigDecimal("payamount").compareTo(BigDecimal.ZERO)<=0) {
|
|
|
- return "扣款金额需大于0";
|
|
|
- }
|
|
|
- if (StringUtils.isBlank(rows.get(0).getString("outplace"))) {
|
|
|
- return "发货地不可为空";
|
|
|
- }
|
|
|
- if ((rows.get(0).getBigDecimal("payamount").add(rows.get(0).getBigDecimal("paydiscountamount"))).compareTo(rowsdetail.sum("amount"))!=0) {
|
|
|
- return "扣款金额与应扣金额不符,不能反审核";
|
|
|
- }
|
|
|
- Rows accountbalancerows = controller.dbConnect.runSqlQuery("select * from sa_accountbalance t1 inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t2.accountname='现金账户' and t1.sys_enterpriseid="+sys_enterpriseid);
|
|
|
- if (accountbalancerows.isEmpty()) {
|
|
|
- return "账户不存在";
|
|
|
- }
|
|
|
- if (rows.get(0).getString("type").equals("销售出库") && rows.get(0).getBoolean("isreceiver")) {
|
|
|
- return "经销商已经确认收货,不可进行反审核";
|
|
|
- }
|
|
|
-// Rows stockRows= dbConnect.runSqlQuery("select * from st_stock where siteid='"+siteid+"'");
|
|
|
-// RowsMap stockRowsMap =stockRows.toRowsMap("itemid");
|
|
|
-
|
|
|
- String order_paymentnode = Parameter.getString(controller.siteid, "order_paymentnode");
|
|
|
- if(rows.get(0).getBoolean("rb")){
|
|
|
- if(rows.get(0).getString("type").equals("销售出库")){
|
|
|
- if (order_paymentnode.equals("3")) {
|
|
|
- if (Accountbalance.judgeBalance(controller, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"),rowsdetail.sum("amount").negate())) {
|
|
|
-// CashbillEntity entity = getCashbillEntity(rows.get(0).getBigDecimal("payamount").negate(),rows.get(0).getBigDecimal("paydiscountamount").negate(), st_stockbillid, "销售出库单反审核", rows.get(0).getString("billno"), "由销售出库单" + rows.get(0).getString("billno") + "反审核时生成");
|
|
|
-// JSONObject createCashbillPay = Accountbalance.createCashbillPay(this, sys_enterpriseid,accountbalancerows.get(0).getLong("sa_accountclassid"), entity, true);
|
|
|
-// sqlList.addAll(createCashbillPay.getJSONArray("sqlList").toJavaList(String.class));
|
|
|
- } else {
|
|
|
- return "账户余额不足,还差" + Accountbalance.InsufficientBalance(controller, sys_enterpriseid, accountbalancerows.get(0).getLong("sa_accountclassid"),rowsdetail.sum("amount")) + "元!";
|
|
|
- }
|
|
|
- }
|
|
|
-// Rows rowsOrderDetail = dbConnect.runSqlQuery("select t1.undeliqty,t1.deliedqty,t1.qty,t1.sa_orderitemsid from sa_orderitems t1 where t1.sa_orderitemsid in (select sa_orderitemsid from st_stockbill_items where st_stockbillid=" + st_stockbillid + ")");
|
|
|
-// RowsMap rowsMap = rowsOrderDetail.toRowsMap("sa_orderitemsid");
|
|
|
-// Rows rowsDispatchDetailGroup = dbConnect.runSqlQuery("select sum(t1.qty) qty,t1.sa_orderitemsid,t1.siteid from st_stockbill_items t1 where t1.st_stockbillid=" + st_stockbillid + " group by t1.sa_orderitemsid,t1.siteid");
|
|
|
-// for (Row row : rowsDispatchDetailGroup) {
|
|
|
-// sqlList.add("update sa_orderitems set undeliqty=" + rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("undeliqty").add(row.getBigDecimal("qty")) + ",deliedqty=" + (rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("deliedqty").subtract(row.getBigDecimal("qty"))) + " where sa_orderitemsid=" + row.getLong("sa_orderitemsid"));
|
|
|
-// }
|
|
|
-// for(Row row :rowsdetail){
|
|
|
-// if(row.getBoolean("skucontrol")){
|
|
|
-// sqlList.add("update st_stockbill_items set wmsuploadflag2=0 where st_stockbill_itemsid="+row.getLong("st_stockbill_itemsid"));
|
|
|
-// }
|
|
|
-//
|
|
|
-// }
|
|
|
- }
|
|
|
-// for(Row row :rowsdetail){
|
|
|
-// String itemid= row.getString("itemid");
|
|
|
-// long stockid=row.getLong("stockid");
|
|
|
-// if(stockRowsMap.containsKey(itemid)){
|
|
|
-// for(Row row1 :stockRowsMap.get(itemid)){
|
|
|
-// if(row1.getLong("stockid")==stockid){
|
|
|
-// sqlList.add("update st_stock set qty="+row1.getBigDecimal("qty").subtract(row.getBigDecimal("qty"))+" where stockid="+stockid);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// // String batchno = row.getString("batchno");
|
|
|
-// }
|
|
|
- }else{
|
|
|
-// for(Row row :rowsdetail){
|
|
|
-// String itemid= row.getString("itemid");
|
|
|
-// long stockid=row.getLong("stockid");
|
|
|
-// if(stockRowsMap.containsKey(itemid)){
|
|
|
-// for(Row row1 :stockRowsMap.get(itemid)){
|
|
|
-// if(row1.getLong("stockid")==stockid){
|
|
|
-// sqlList.add("update st_stock set qty="+row1.getBigDecimal("qty").add(row.getBigDecimal("qty"))+" where stockid="+stockid);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// // String batchno = row.getString("batchno");
|
|
|
-// }
|
|
|
- }
|
|
|
-// Rows stockbillitems = dbConnect.runSqlQuery("select t2.sa_orderid,sum(t2.price*t1.qty) amount from st_stockbill_items t1 inner join sa_orderitems t2 on t1.siteid=t2.siteid and t1.sa_orderitemsid=t2.sa_orderitemsid where t1.siteid='"+siteid+"'and t1.st_stockbillid="+st_stockbillid+" group by t2.sa_orderid");
|
|
|
-// Rows orderRows =dbConnect.runSqlQuery("select * from sa_order where sa_orderid in(select t2.sa_orderid from st_stockbill_items t1 inner join sa_orderitems t2 on t1.siteid=t2.siteid and t1.sa_orderitemsid=t2.sa_orderitemsid where t1.st_stockbillid='"+st_stockbillid+"')");
|
|
|
-// RowsMap orderRowsMap =orderRows.toRowsMap("sa_orderid");
|
|
|
-// sqlList.addAll(updateAccountbalance_freez(st_stockbillid,isinstock));
|
|
|
-// dbConnect.runSqlUpdate(sqlList);
|
|
|
-
|
|
|
-// Accountbalance.remindSend(this, sys_enterpriseid, sa_cashbillid);
|
|
|
- return "success";
|
|
|
- }
|
|
|
-
|
|
|
- public static ArrayList<String> xsckcheck(Controller controller,Rows rows,Rows rowsdetail,boolean isinstock) throws YosException {
|
|
|
- long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
|
|
|
-
|
|
|
- Rows accountbalancerows =controller.dbConnect.runSqlQuery("select * from sa_accountbalance t1 inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t2.accountname='现金账户' and t1.sys_enterpriseid="+sys_enterpriseid);
|
|
|
- ArrayList<String> sqlList = new ArrayList<>();
|
|
|
- String order_paymentnode = Parameter.getString(controller.siteid, "order_paymentnode");
|
|
|
- if(rows.get(0).getBoolean("rb")){
|
|
|
- if(rows.get(0).getString("type").equals("销售出库")){
|
|
|
- if (order_paymentnode.equals("3")) {
|
|
|
- CashbillEntity entity = getCashbillEntity(rows.get(0).getBigDecimal("payamount"),rows.get(0).getBigDecimal("paydiscountamount"), rows.get(0).getLong("st_stockbillid"), "销售出库单审核", rows.get(0).getString("billno"), "由销售出库单" + rows.get(0).getString("billno") + "审核时生成");
|
|
|
- JSONObject createCashbillPay = Accountbalance.createCashbillPay(controller, sys_enterpriseid,accountbalancerows.get(0).getLong("sa_accountclassid"), entity, true);
|
|
|
- sqlList.addAll(createCashbillPay.getJSONArray("sqlList").toJavaList(String.class));
|
|
|
- }
|
|
|
- Rows rowsOrderDetail = controller.dbConnect.runSqlQuery("select t1.undeliqty,t1.deliedqty,t1.qty,t1.sa_orderitemsid from sa_orderitems t1 where t1.sa_orderitemsid in (select sa_orderitemsid from st_stockbill_items where st_stockbillid=" + rows.get(0).getLong("st_stockbillid") + ")");
|
|
|
- RowsMap rowsMap = rowsOrderDetail.toRowsMap("sa_orderitemsid");
|
|
|
- Rows rowsDispatchDetailGroup = controller.dbConnect.runSqlQuery("select sum(t1.qty) qty,t1.sa_orderitemsid,t1.siteid from st_stockbill_items t1 where t1.st_stockbillid=" + rows.get(0).getLong("st_stockbillid") + " group by t1.sa_orderitemsid,t1.siteid");
|
|
|
- for (Row row : rowsDispatchDetailGroup) {
|
|
|
- sqlList.add("update sa_orderitems set undeliqty=" + rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("undeliqty").subtract(row.getBigDecimal("qty")) + ",deliedqty=" + (row.getBigDecimal("qty").add(rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("deliedqty"))) + " where sa_orderitemsid=" + row.getLong("sa_orderitemsid"));
|
|
|
- }
|
|
|
- for(Row row :rowsdetail){
|
|
|
- if(row.getBoolean("skucontrol")){
|
|
|
- sqlList.add("update st_stockbill_items set wmsuploadflag2=1 where st_stockbill_itemsid="+row.getLong("st_stockbill_itemsid"));
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }else{
|
|
|
-// for(Row row :rowsdetail){
|
|
|
-// String itemid= row.getString("itemid");
|
|
|
-// long stockid=row.getLong("stockid");
|
|
|
-// if(stockRowsMap.containsKey(itemid)){
|
|
|
-// for(Row row1 :stockRowsMap.get(itemid)){
|
|
|
-// if(row1.getLong("stockid")==stockid){
|
|
|
-// sqlList.add("update st_stock set qty="+row1.getBigDecimal("qty").subtract(row.getBigDecimal("qty"))+" where stockid="+stockid);
|
|
|
-// }
|
|
|
-// }
|
|
|
-// }
|
|
|
-// // String batchno = row.getString("batchno");
|
|
|
-// }
|
|
|
- }
|
|
|
- sqlList.addAll(updateAccountbalance_freez(controller,rows.get(0).getLong("st_stockbillid"),isinstock));
|
|
|
-
|
|
|
- return sqlList;
|
|
|
- }
|
|
|
-
|
|
|
- public static ArrayList<String> unxsckcheck(Controller controller,Rows rows,Rows rowsdetail,boolean isinstock) throws YosException {
|
|
|
-
|
|
|
-
|
|
|
- long sys_enterpriseid = rows.get(0).getLong("sys_enterpriseid");
|
|
|
-
|
|
|
- Rows accountbalancerows = controller.dbConnect.runSqlQuery("select * from sa_accountbalance t1 inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t2.accountname='现金账户' and t1.sys_enterpriseid="+sys_enterpriseid);
|
|
|
- ArrayList<String> sqlList = new ArrayList<>();
|
|
|
- String order_paymentnode = Parameter.getString(controller.siteid, "order_paymentnode");
|
|
|
- if(rows.get(0).getBoolean("rb")){
|
|
|
- if(rows.get(0).getString("type").equals("销售出库")){
|
|
|
- if (order_paymentnode.equals("3")) {
|
|
|
- CashbillEntity entity = getCashbillEntity(rows.get(0).getBigDecimal("payamount").negate(),rows.get(0).getBigDecimal("paydiscountamount").negate(), rows.get(0).getLong("st_stockbillid"), "销售出库单反审核", rows.get(0).getString("billno"), "由销售出库单" + rows.get(0).getString("billno") + "反审核时生成");
|
|
|
- JSONObject createCashbillPay = Accountbalance.createCashbillPay(controller, sys_enterpriseid,accountbalancerows.get(0).getLong("sa_accountclassid"), entity, true);
|
|
|
- sqlList.addAll(createCashbillPay.getJSONArray("sqlList").toJavaList(String.class));
|
|
|
- }
|
|
|
- Rows rowsOrderDetail = controller.dbConnect.runSqlQuery("select t1.undeliqty,t1.deliedqty,t1.qty,t1.sa_orderitemsid from sa_orderitems t1 where t1.sa_orderitemsid in (select sa_orderitemsid from st_stockbill_items where st_stockbillid=" + rows.get(0).getLong("st_stockbillid") + ")");
|
|
|
- RowsMap rowsMap = rowsOrderDetail.toRowsMap("sa_orderitemsid");
|
|
|
- Rows rowsDispatchDetailGroup = controller.dbConnect.runSqlQuery("select sum(t1.qty) qty,t1.sa_orderitemsid,t1.siteid from st_stockbill_items t1 where t1.st_stockbillid=" + rows.get(0).getLong("st_stockbillid") + " group by t1.sa_orderitemsid,t1.siteid");
|
|
|
- for (Row row : rowsDispatchDetailGroup) {
|
|
|
- sqlList.add("update sa_orderitems set undeliqty=" + rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("undeliqty").add(row.getBigDecimal("qty")) + ",deliedqty=" + (rowsMap.get(row.getLong("sa_orderitemsid")).get(0).getBigDecimal("deliedqty").subtract(row.getBigDecimal("qty"))) + " where sa_orderitemsid=" + row.getLong("sa_orderitemsid"));
|
|
|
- }
|
|
|
- for(Row row :rowsdetail){
|
|
|
- if(row.getBoolean("skucontrol")){
|
|
|
- sqlList.add("update st_stockbill_items set wmsuploadflag2=0 where st_stockbill_itemsid="+row.getLong("st_stockbill_itemsid"));
|
|
|
- }
|
|
|
-
|
|
|
- }
|
|
|
- }
|
|
|
- }else{
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
- sqlList.addAll(updateAccountbalance_freez(controller,rows.get(0).getLong("st_stockbillid"),isinstock));
|
|
|
- return sqlList;
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
- public static boolean isinstock(String type,String rb,boolean fischeck){
|
|
|
- if (type.equals("其他出库") || type.equals("销售出库")
|
|
|
- || type.equals("生产领料出库") || type.equals("委外领料出库")
|
|
|
- || type.equals("返修出库")) {
|
|
|
- if ((fischeck && rb.equals("1")) || (!fischeck && rb.equals("0"))) {
|
|
|
- return false;
|
|
|
- } else {
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
- } else if (type.equals("其他入库") || type.equals("外购入库")
|
|
|
- || type.equals("生产入库") || type.equals("委外入库")
|
|
|
- || type.equals("返修入库")) {
|
|
|
- if ((fischeck && rb.equals("1")) || (!fischeck && rb.equals("0"))) {
|
|
|
- return true;
|
|
|
- } else {
|
|
|
- return false;
|
|
|
- }
|
|
|
- }
|
|
|
- return false;
|
|
|
- }
|
|
|
-
|
|
|
- public static CashbillEntity getCashbillEntity(BigDecimal amount,BigDecimal discountamount, Long ownerid, String source, String sourcenotes, String remarks) throws YosException {
|
|
|
- CashbillEntity entity = new CashbillEntity();
|
|
|
- entity.setAmount(amount);
|
|
|
- entity.setDiscountamountamount(discountamount);
|
|
|
- entity.setOwnerid(ownerid);
|
|
|
- entity.setOwnertable("st_stockbill");
|
|
|
- entity.setSource(source);
|
|
|
- entity.setRemarks(remarks);
|
|
|
- entity.setSourcenote(sourcenotes);
|
|
|
- return entity;
|
|
|
-
|
|
|
- }
|
|
|
-
|
|
|
-
|
|
|
- /**
|
|
|
- * @param isinstock 是否增加库存
|
|
|
- * @param type 库存更新类型 0为默认形式。1表示生产领料更新现场仓 2表示委外领料更新现场仓
|
|
|
- * @throws YosException
|
|
|
- */
|
|
|
- public static ArrayList<String> updateIcinvbal(Controller controller,boolean isinstock, int type,Long st_stockbillid) throws YosException {
|
|
|
- ArrayList<String> sqlList =new ArrayList();
|
|
|
- Rows icstockbilldetail =controller.dbConnect.runSqlQuery("select t1.*,t2.skucontrol from st_stockbill_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid where t1.st_stockbillid ='"
|
|
|
- + st_stockbillid + "' and t1.siteid='" + controller.siteid + "'");// 出入库表体
|
|
|
- ArrayList<Long> itemids = new ArrayList<Long>();
|
|
|
- itemids = icstockbilldetail.toArrayList("itemid",new ArrayList<>());
|
|
|
- itemids.add((long) 0);
|
|
|
- int i = 0;
|
|
|
- String sql="select * from st_invbal where itemid in"+itemids;
|
|
|
- sql = sql.replace("[", "(").replace("]", ")");
|
|
|
- Rows invbals = controller.dbConnect.runSqlQuery(sql);
|
|
|
- RowsMap invbalsRowsMap=invbals.toRowsMap("itemid");
|
|
|
- for(Row row : icstockbilldetail){
|
|
|
- String itemid = row.getString("itemid");
|
|
|
- //String batchno = row.getString("batchno");
|
|
|
- //String fdcspno = row.getString("fdcspno");
|
|
|
- String stockid = row.getString("stockid");
|
|
|
-
|
|
|
-// if (type == 1 && !getSysVars().getBoolean("FISBATCHFORXC")) {
|
|
|
-// fdcspno = "**********";
|
|
|
-// fbatchno = "**********";
|
|
|
-// fstockno = getPaoSet("TDEPARTMENT").getPao(0)
|
|
|
-// .getPaoSet("TSTOCKXC").getPao(0).getString("fstockno");
|
|
|
-// icinvbal = detailpao.getPaoSet("$icinvbal", "icinvbal",
|
|
|
-// "fitemno='" + fitemno + "' and fstockno='" + fstockno
|
|
|
-// + "' and fdcspno='" + fdcspno
|
|
|
-// + "' and fbatchno='" + fbatchno + "'");
|
|
|
-// } else if (type == 2 && !getSysVars().getBoolean("FISBATCHFORXC")) {
|
|
|
-// fdcspno = "**********";
|
|
|
-// fbatchno = "**********";
|
|
|
-// fstockno = getPaoSet("TSUPPLIER").getPao(0)
|
|
|
-// .getPaoSet("TSTOCKXC").getPao(0).getString("fstockno");
|
|
|
-// icinvbal = detailpao.getPaoSet("$icinvbal", "icinvbal",
|
|
|
-// "fitemno='" + fitemno + "' and fstockno='" + fstockno
|
|
|
-// + "' and fdcspno='" + fdcspno
|
|
|
-// + "' and fbatchno='" + fbatchno + "'");
|
|
|
-// }
|
|
|
- BigDecimal qty = isinstock ? row.getBigDecimal("qty") : row.getBigDecimal("qty").negate();
|
|
|
- if(!invbalsRowsMap.containsKey(itemid)){
|
|
|
- SQLFactory sqlFactory = new SQLFactory(controller, "即时库存新增");
|
|
|
- sqlFactory.addParameter("st_invbalid", controller.createTableID("st_invbal"));
|
|
|
- sqlFactory.addParameter("qty", qty);
|
|
|
- sqlFactory.addParameter("itemid", itemid);
|
|
|
- sqlFactory.addParameter("stockid", stockid);
|
|
|
- sqlFactory.addParameter("siteid",controller.siteid);
|
|
|
- sqlFactory.addParameter("userid", controller.userid);
|
|
|
- sqlFactory.addParameter("username", controller.username);
|
|
|
- sqlList.add(sqlFactory.getSQL());
|
|
|
- }else{
|
|
|
- if(invbalsRowsMap.get(itemid).toRowsMap("stockid").containsKey(stockid)){
|
|
|
- SQLFactory sqlFactory = new SQLFactory(controller, "即时库存更新");
|
|
|
- sqlFactory.addParameter("st_invbalid", controller.createTableID("st_invbal"));
|
|
|
- sqlFactory.addParameter("qty", invbalsRowsMap.get(itemid).toRowsMap("stockid").get(stockid).get(0).getBigDecimal("qty").add(qty));
|
|
|
- sqlFactory.addParameter("itemid", itemid);
|
|
|
- sqlFactory.addParameter("stockid", stockid);
|
|
|
- sqlFactory.addParameter("siteid",controller.siteid);
|
|
|
- sqlFactory.addParameter("userid", controller.userid);
|
|
|
- sqlFactory.addParameter("username", controller.username);
|
|
|
- sqlList.add(sqlFactory.getSQL());
|
|
|
- }else{
|
|
|
- SQLFactory sqlFactory = new SQLFactory(new Invbal(), "即时库存新增");
|
|
|
- sqlFactory.addParameter("st_invbalid", controller.createTableID("st_invbal"));
|
|
|
- sqlFactory.addParameter("qty", qty);
|
|
|
- sqlFactory.addParameter("itemid", itemid);
|
|
|
- sqlFactory.addParameter("stockid", stockid);
|
|
|
- sqlFactory.addParameter("siteid",controller.siteid);
|
|
|
- sqlFactory.addParameter("userid", controller.userid);
|
|
|
- sqlFactory.addParameter("username", controller.username);
|
|
|
- sqlList.add(sqlFactory.getSQL());
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return sqlList;
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 账户余额冻结
|
|
|
- * @param addorsub
|
|
|
- */
|
|
|
- public static ArrayList<String> updateAccountbalance_freez(Controller controller,long st_stockbillid,boolean addorsub) throws YosException {
|
|
|
- ArrayList<String> sqllist= new ArrayList<>();
|
|
|
- /******** 冻结数据 ********/
|
|
|
- Rows rows = controller.dbConnect.runSqlQuery("select t4.sa_accountbalanceid,t3.sa_orderid,t3.sonum,ROUND(sum(t1.qty*t2.price*ifnull(t2.pricerate,1)*ifnull(t2.rwpricerate,1)), 2) amount from st_stockbill_items t1 \n" +
|
|
|
- " inner join sa_orderitems t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid\n" +
|
|
|
- " inner join sa_order t3 on t2.sa_orderid=t3.sa_orderid and t2.siteid=t3.siteid\n" +
|
|
|
- "\t\t\t\t\t\t\t\t\tleft join sa_accountbalance t4 on t4.sa_accountclassid=t3.sa_accountclassid and t4.sys_enterpriseid=t3.sys_enterpriseid and t4.siteid=t3.siteid\n" +
|
|
|
- " where t1.st_stockbillid="+st_stockbillid+" group by t4.sa_accountbalanceid,t3.sa_orderid,t3.sonum");
|
|
|
- if (addorsub) {
|
|
|
- for(Row row :rows) {
|
|
|
- String sonum = row.getString("sonum");
|
|
|
- long sa_orderid = row.getLong("sa_orderid");
|
|
|
- long sa_accountbalanceid = row.getLong("sa_accountbalanceid");
|
|
|
- BigDecimal amount = row.getBigDecimal("amount");
|
|
|
- Rows accountbalancefreezrows = controller.dbConnect.runSqlQuery("select sa_accountbalance_freezid from sa_accountbalance_freez where sourceid=" + sa_orderid + " and sourcetable='sa_order' and siteid='" + controller.siteid + "'");
|
|
|
-
|
|
|
- sqllist.add("update sa_accountbalance set freezamount=ifnull(freezamount,0)+" + amount + " where sa_accountbalanceid=" + sa_accountbalanceid + " and siteid='" + controller.siteid + "'");
|
|
|
-
|
|
|
- if (accountbalancefreezrows.isNotEmpty()) {
|
|
|
- sqllist.add("update sa_accountbalance_freez set amount=amount+" + amount + " where sa_accountbalance_freezid=" + accountbalancefreezrows.get(0).getLong("sa_accountbalance_freezid"));
|
|
|
- } else {
|
|
|
- long sa_accountbalance_freezid = controller.createTableID("sa_accountbalance_freez");
|
|
|
- InsertSQL insertSQL = SQLFactory.createInsertSQL(controller, "sa_accountbalance_freez");
|
|
|
- insertSQL.setUniqueid(sa_accountbalance_freezid);
|
|
|
- insertSQL.setSiteid(controller.siteid);
|
|
|
- insertSQL.setValue("sa_accountbalanceid", sa_accountbalanceid);
|
|
|
- insertSQL.setValue("sourcetable", "sa_order");
|
|
|
- insertSQL.setValue("sourceid", sa_orderid);
|
|
|
- insertSQL.setValue("amount", amount);
|
|
|
- insertSQL.setValue("remarks", "由销售订单" + sonum + "审核时冻结");
|
|
|
- insertSQL.setValue("createby", controller.username);
|
|
|
- insertSQL.setDateValue("createdate");
|
|
|
- sqllist.add(insertSQL.getSQL());
|
|
|
- }
|
|
|
- }
|
|
|
- } else {
|
|
|
- for(Row row : rows){
|
|
|
- long sa_orderid = row.getLong("sa_orderid");
|
|
|
- long sa_accountbalanceid = row.getLong("sa_accountbalanceid");
|
|
|
- BigDecimal amount = row.getBigDecimal("amount");
|
|
|
- Rows accountbalancefreezrows = controller.dbConnect.runSqlQuery("select sa_accountbalance_freezid,amount from sa_accountbalance_freez where sourceid=" + sa_orderid + " and sourcetable='sa_order' and siteid='" + controller.siteid + "'");
|
|
|
- if (accountbalancefreezrows.size() > 0) {
|
|
|
- sqllist.add("update sa_accountbalance set freezamount=ifnull(freezamount,0)-"+amount+" where sa_accountbalanceid="+sa_accountbalanceid);
|
|
|
- sqllist.add("update sa_accountbalance_freez set amount=amount-"+amount+" where sa_accountbalance_freezid="+accountbalancefreezrows.get(0).getLong("sa_accountbalance_freezid"));
|
|
|
- }
|
|
|
- }
|
|
|
- }
|
|
|
- return sqllist;
|
|
|
+ controller.dbConnect.runSqlUpdate(getCheckSql(controller, st_stockbillid, ischeck));
|
|
|
}
|
|
|
}
|