|
|
@@ -23,10 +23,12 @@ import utility.ERPDocking;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
+import java.math.RoundingMode;
|
|
|
import java.time.Year;
|
|
|
import java.time.YearMonth;
|
|
|
import java.time.temporal.IsoFields;
|
|
|
import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
import java.util.HashMap;
|
|
|
|
|
|
import static beans.order.Order.*;
|
|
|
@@ -615,25 +617,6 @@ public class OrderItems extends Controller {
|
|
|
return getSucReturnObject().toString();
|
|
|
}
|
|
|
|
|
|
- @API(title = "关闭", apiversion = R.ID20221109093802.v1.class)
|
|
|
- @CACHEING_CLEAN(apiClass = {Order.class, OrderItems.class, restcontroller.sale.order.Order.class})
|
|
|
- public String close() throws YosException {
|
|
|
- Long sa_orderid = content.getLong("sa_orderid");
|
|
|
- //通过版本更新订单表头数据
|
|
|
- beans.order.Order.updateOrderWithVersion(this);
|
|
|
-
|
|
|
- JSONArray sa_orderitemsids = content.getJSONArray("sa_orderitemsids");
|
|
|
- SQLFactory sqlFactory = new SQLFactory(this, "订单商品明细_行关闭");
|
|
|
- sqlFactory.addParameter("siteid", siteid);
|
|
|
- sqlFactory.addParameter("userid", userid);
|
|
|
- sqlFactory.addParameter("username", username);
|
|
|
- sqlFactory.addParameter("closereason", content.getStringValue("closereason"));
|
|
|
- sqlFactory.addParameter_in("sa_orderitemsid", sa_orderitemsids.toArray());
|
|
|
- dbConnect.runSqlUpdate(sqlFactory);
|
|
|
- //重新排序
|
|
|
- updateRowNo(sa_orderid);
|
|
|
- return getSucReturnObject().toString();
|
|
|
- }
|
|
|
|
|
|
@API(title = "查询列表", apiversion = R.ID20221109093902.v1.class)
|
|
|
public String selectList() throws YosException, IOException {
|
|
|
@@ -1314,6 +1297,143 @@ public class OrderItems extends Controller {
|
|
|
//
|
|
|
// }
|
|
|
|
|
|
+ @API(title = "行关闭", apiversion = R.ID2025102210393903.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiClass = {Order.class, OrderItems.class, restcontroller.sale.order.Order.class})
|
|
|
+ public String close() throws YosException {
|
|
|
+ boolean isclose= content.getBoolean("isclose");
|
|
|
+ long sa_orderid=content.getLong("sa_orderid");
|
|
|
+ JSONArray sa_orderitemsids = content.getJSONArray("sa_orderitemsids");
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+ Rows rows = getOrderRows(this, sa_orderid);
|
|
|
+ if (rows.isEmpty()) {
|
|
|
+ return getErrReturnObject().setErrMsg("订单不存在").toString();
|
|
|
+ }
|
|
|
+ Row row = rows.get(0);
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_orderitems", "*").setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.inner, "sa_order", "t2", "t1.siteid = t2.siteid and t1.sa_orderid = t2.sa_orderid");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere("t1.sa_orderitemsid",sa_orderitemsids);
|
|
|
+ querySQL.setWhere("t2.sa_orderid",sa_orderid);
|
|
|
+ Rows rowsdetails = querySQL.query();
|
|
|
+ closevalidate(isclose,row,rowsdetails);
|
|
|
+
|
|
|
+ /******** 行关闭状态更新 ********/
|
|
|
+ Date date = getDate();
|
|
|
+ BigDecimal returnamount =BigDecimal.ZERO;// 退还金额
|
|
|
+ for(Row rowsdetail :rowsdetails){
|
|
|
+ BigDecimal amount = rowsdetail.getBigDecimal("amount");// 订单金额
|
|
|
+ BigDecimal price = rowsdetail.getBigDecimal("price");// 单价
|
|
|
+ BigDecimal qty = rowsdetail.getBigDecimal("qty");// 订单数量
|
|
|
+ BigDecimal undeliqty = rowsdetail.getBigDecimal("undeliqty");;// 订单未发货数量
|
|
|
+ BigDecimal sendqty = qty.subtract(undeliqty);
|
|
|
+ BigDecimal sendamount =price.multiply(sendqty).setScale(2, RoundingMode.HALF_UP);
|
|
|
+ returnamount = returnamount.add(amount.subtract(sendamount));
|
|
|
+
|
|
|
+ sqlList.add("update sa_orderitems set isclose="+isclose+" where sa_orderitemsid="+rowsdetail.getLong("sa_orderitemsid"));
|
|
|
+ }
|
|
|
+
|
|
|
+ Rows freezRows = dbConnect.runSqlQuery("select * from sa_accountbalance_freez where sourcetable='sa_order' and sourceid="+sa_orderid);
|
|
|
+ Row freezRow= null;
|
|
|
+ if (!freezRows.isEmpty()) {
|
|
|
+ freezRow = freezRows.get(0);
|
|
|
+ }
|
|
|
+ if (isclose) {
|
|
|
+ if (freezRow != null) {
|
|
|
+ BigDecimal amount = freezRow.getBigDecimal("amount");// 冻结金额
|
|
|
+ sqlList.add("update sa_accountbalance_freez set amount="+amount.subtract(returnamount)+" where sa_accountbalance_freezid="+freezRow.getLong("sa_accountbalance_freezid"));
|
|
|
+
|
|
|
+ if (amount.subtract(returnamount).compareTo(BigDecimal.ZERO)<=0) {
|
|
|
+ sqlList.add("delete from sa_accountbalance_freez where sa_accountbalance_freezid="+freezRow.getLong("sa_accountbalance_freezid"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ if (freezRow == null) {
|
|
|
+ Rows accountbalanceRows = dbConnect.runSqlQuery("select * from sa_accountbalance where sys_enterpriseid="+row.getLong("sys_enterpriseid")+" and sa_accountclassid="+row.getLong("sa_accountclassid"));
|
|
|
+ if(accountbalanceRows.isNotEmpty()){
|
|
|
+ InsertSQL frezzInsertSQL = SQLFactory.createInsertSQL(this, "sa_accountbalance_freez");
|
|
|
+ frezzInsertSQL.setUniqueid(createTableID("sa_accountbalance_freez"));
|
|
|
+ frezzInsertSQL.setSiteid(siteid);
|
|
|
+ frezzInsertSQL.setValue("sa_accountbalanceid", accountbalanceRows.get(0).getLong("sa_accountbalanceid"));
|
|
|
+ frezzInsertSQL.setValue("sourcetable", "sa_order");
|
|
|
+ frezzInsertSQL.setValue("sourceid", sa_orderid);
|
|
|
+ frezzInsertSQL.setValue("amount", returnamount);
|
|
|
+ frezzInsertSQL.setValue("remarks", "订单反关闭冻结");
|
|
|
+ frezzInsertSQL.setValue("createby", username);
|
|
|
+ frezzInsertSQL.setDateValue("createdate");
|
|
|
+ sqlList.add(frezzInsertSQL.getSQL());
|
|
|
+ }else{
|
|
|
+ return getErrReturnObject().setErrMsg("账户不存在").toString();
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ BigDecimal amount = freezRow.getBigDecimal("amount");// 冻结金额
|
|
|
+ sqlList.add("update sa_accountbalance_freez set amount="+amount.add(returnamount)+" where sa_accountbalance_freezid="+freezRow.getLong("sa_accountbalance_freezid"));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ /******** 增加总仓可销售量 ********/
|
|
|
+ if (isclose) {
|
|
|
+ sqlList.addAll(updateIcinvbal_sale(rowsdetails,true, true));
|
|
|
+ } else {
|
|
|
+ sqlList.addAll(updateIcinvbal_sale(rowsdetails,false, true));
|
|
|
+ }
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public void closevalidate(boolean isclose,Row order,Rows orderdetails) throws YosException {
|
|
|
+ if (isclose && !order.getString("status").equals("审核")) {
|
|
|
+ throw new YosException("非审核状态下不可关闭");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isclose && orderdetails.size() == 0) {
|
|
|
+ throw new YosException("请购选行再进行关闭操作");
|
|
|
+ }
|
|
|
+ if (!isclose && orderdetails.size() == 0) {
|
|
|
+ throw new YosException("请购选行再进行取消关闭操作");
|
|
|
+ }
|
|
|
+ int i = 0;
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "st_stockbill_items", "*").setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.inner, "st_stockbill", "t2", "t1.siteid = t2.siteid and t1.st_stockbillid = t2.st_stockbillid");
|
|
|
+ querySQL.setSiteid(siteid);
|
|
|
+ querySQL.setWhere("t1.sa_orderitemsid",orderdetails.toArrayList("sa_orderitemsid"));
|
|
|
+ querySQL.setWhere("t2.status='新建'");
|
|
|
+ Rows rows = querySQL.query();
|
|
|
+ RowsMap rowsMap = rows.toRowsMap("sa_orderitemsid");
|
|
|
+ for(Row row :orderdetails){
|
|
|
+ int rownum = row.getInteger("rowno");
|
|
|
+ if (isclose) {
|
|
|
+ if (row.getBoolean("isclose")) {
|
|
|
+ throw new YosException("行" + rownum
|
|
|
+ + "已经关闭,不可重复关闭");
|
|
|
+ }
|
|
|
+ if (row.getBigDecimal("undeliqty").compareTo(BigDecimal.ZERO)==0) {
|
|
|
+ throw new YosException("行" + rownum
|
|
|
+ + "已发货完毕,不可关闭");
|
|
|
+ }
|
|
|
+
|
|
|
+ if (rowsMap.containsKey(row.getString("sa_orderitemsid"))) {
|
|
|
+ throw new YosException("行" + rownum
|
|
|
+ + "存在新建的销售出库单,不可关闭");
|
|
|
+ }
|
|
|
+// if (saorderdetail.getPao(i).getPaoSet("SAINVOICEDETAIL")
|
|
|
+// .count() > 0) {
|
|
|
+// throw new YosException("行" + rownum
|
|
|
+// + "存在发货单,不可关闭");
|
|
|
+// }
|
|
|
+ } else {
|
|
|
+ if (!row.getBoolean("isclose")) {
|
|
|
+ throw new YosException("行" + rownum
|
|
|
+ + "未关闭,不可取消关闭");
|
|
|
+ }
|
|
|
+ if (row.getDouble("undeliqty") == 0) {
|
|
|
+ throw new YosException("行" + rownum
|
|
|
+ + "已发货完毕,不可取消关闭");
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
|
|
|
/**
|
|
|
* 获取当前订单的最大行号
|
|
|
@@ -1371,5 +1491,43 @@ public class OrderItems extends Controller {
|
|
|
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * @param isinstock 是否增加库存
|
|
|
+ * @throws YosException
|
|
|
+ */
|
|
|
+ public ArrayList<String> updateIcinvbal_sale(Rows rowsdetails, boolean isinstock, boolean close) throws YosException {
|
|
|
+ Rows ICINVBAL_SALE = SQLFactory.createQuerySQL(this, "st_invbal_sale").setSiteid(siteid).setWhere("itemid", rowsdetails.toArrayList("itemid")).query();
|
|
|
+ RowsMap ICINVBAL_SALERowsMap = ICINVBAL_SALE.toRowsMap("itemid");
|
|
|
+ int i = 0;
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+ for (Row row : rowsdetails) {
|
|
|
+ long st_invbal_saleid;
|
|
|
+ if (ICINVBAL_SALERowsMap.containsKey(row.getString("itemid"))) {
|
|
|
+ st_invbal_saleid = ICINVBAL_SALERowsMap.get(row.getString("itemid")).get(0).getLong("st_invbal_saleid");
|
|
|
+ } else {
|
|
|
+ st_invbal_saleid = createTableID("st_invbal_sale");
|
|
|
+ InsertSQL insertSQL = SQLFactory.createInsertSQL(this, "st_invbal_sale");
|
|
|
+ insertSQL.setUniqueid(st_invbal_saleid);
|
|
|
+ insertSQL.setSiteid(siteid);
|
|
|
+ insertSQL.setValue("itemid", row.getString("itemid"));
|
|
|
+ insertSQL.setValue("candispatchqty", 0);
|
|
|
+ insertSQL.setValue("cansaleqty", 0);
|
|
|
+ insertSQL.setValue("qty", 0);
|
|
|
+ insertSQL.setValue("changeuserid", userid);
|
|
|
+ insertSQL.setValue("changeby", username);
|
|
|
+ insertSQL.setDateValue("changedate");
|
|
|
+ sqlList.add(insertSQL.getSQL());
|
|
|
+ }
|
|
|
+ BigDecimal qty = BigDecimal.ZERO;
|
|
|
+ if (close) {
|
|
|
+ qty = isinstock ? row.getBigDecimal("undeliqty") : row.getBigDecimal("undeliqty").negate();// 如果是扣减则根据数量进行扣减,反之根据未发货数量进行增加
|
|
|
+ } else {
|
|
|
+ qty = isinstock ? row.getBigDecimal("undeliqty")
|
|
|
+ : row.getBigDecimal("qty").negate();// 如果是扣减则根据数量进行扣减,反之根据未发货数量进行增加
|
|
|
+ }
|
|
|
+ sqlList.add("update st_invbal_sale set cansaleqty=cansaleqty+" + qty + " where st_invbal_saleid=" + st_invbal_saleid);
|
|
|
+ }
|
|
|
+ return sqlList;
|
|
|
+ }
|
|
|
|
|
|
}
|