|
|
@@ -24,9 +24,6 @@ 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;
|
|
|
@@ -75,7 +72,7 @@ public class OrderItems extends Controller {
|
|
|
RowsMap itemRowsMap = orderItemsHelper.getItemRowsMap(items);
|
|
|
|
|
|
BigDecimal sumqty = BigDecimal.ZERO;
|
|
|
- ArrayList<Long> sa_orderitemsids_insert =new ArrayList<>();
|
|
|
+ ArrayList<Long> sa_orderitemsids_insert = new ArrayList<>();
|
|
|
for (Object obj : items) {
|
|
|
|
|
|
JSONObject item = (JSONObject) obj;
|
|
|
@@ -145,21 +142,21 @@ public class OrderItems extends Controller {
|
|
|
defaultprice = price;
|
|
|
if (isInsert) {
|
|
|
sa_orderitemsids_insert.add(sa_orderitemsid);
|
|
|
- sqlList.add(orderItemsHelper.getInsertSQL(customproperties, sa_orderitemsid, item, itemRow, type, defaultprice, price, saleprice, itemPrice.getMarketprice(), "", new Rows(), 0, 0, BigDecimal.ZERO, BigDecimal.valueOf(1), BigDecimal.valueOf(1)).getSQL());
|
|
|
+ sqlList.add(orderItemsHelper.getInsertSQL(customproperties, sa_orderitemsid, item, itemRow, type, defaultprice, price, saleprice, itemPrice.getMarketprice(), "", new Rows(), 0, 0, BigDecimal.ZERO, BigDecimal.valueOf(1), BigDecimal.valueOf(1)).getSQL());
|
|
|
if (item.getLongValue("sa_workorderid") != 0) {
|
|
|
sqlList.add("update sa_workorder_node_items set sourceid=" + sa_orderid + ",sourcetable='sa_order' where sa_workorderid=" + item.getLongValue("sa_workorderid") + " and itemid=" + item.getLong("itemid"));
|
|
|
}
|
|
|
} else {
|
|
|
- Rows itemidRows = dbConnect.runSqlQuery("select itemid from sa_orderitems where sa_orderitemsid="+sa_orderitemsid);
|
|
|
+ Rows itemidRows = dbConnect.runSqlQuery("select itemid from sa_orderitems where sa_orderitemsid=" + sa_orderitemsid);
|
|
|
price = item.getBigDecimal("price");
|
|
|
- defaultprice=item.getBigDecimal("defaultprice");
|
|
|
- if(itemidRows.isNotEmpty()){
|
|
|
- if(itemidRows.get(0).getLong("itemid")!=itemid){
|
|
|
+ defaultprice = item.getBigDecimal("defaultprice");
|
|
|
+ if (itemidRows.isNotEmpty()) {
|
|
|
+ if (itemidRows.get(0).getLong("itemid") != itemid) {
|
|
|
defaultprice = orderItemsHelper.getPrice(orderRows.get(0), itemPrice, item);
|
|
|
- price=orderItemsHelper.getPrice(orderRows.get(0), itemPrice, item);
|
|
|
+ price = orderItemsHelper.getPrice(orderRows.get(0), itemPrice, item);
|
|
|
}
|
|
|
}
|
|
|
- sqlList.add(orderItemsHelper.getUpdateSQL(sa_orderitemsid, item, itemRow, type, defaultprice, price, saleprice, 0,0).getSQL());
|
|
|
+ sqlList.add(orderItemsHelper.getUpdateSQL(sa_orderitemsid, item, itemRow, type, defaultprice, price, saleprice, 0, 0).getSQL());
|
|
|
// if(StringUtils.isNotBlank(item.getStringValue("cardno"))){
|
|
|
// Rows aftersalesbomrows = dbConnect.runSqlQuery("select t2.sa_aftersalesbomid from sa_warrantycard t1 inner join sa_aftersalesbom_items t2 on t1.itemid=t2.itemid inner join sa_aftersalesbom t3 on t2.sa_aftersalesbomid=t3.sa_aftersalesbomid where t1.cardno='"+item.getStringValue("cardno")+"' and t3.status='审核'");
|
|
|
// if(aftersalesbomrows.isNotEmpty()){
|
|
|
@@ -184,14 +181,12 @@ public class OrderItems extends Controller {
|
|
|
//更新订单扣款信息
|
|
|
updateAccountclassinfos(sa_orderid);
|
|
|
|
|
|
- if(type.equals("配件订单")){
|
|
|
- dbConnect.runSqlUpdate("UPDATE sa_order o JOIN (SELECT sa_orderid,GROUP_CONCAT(DISTINCT delivery SEPARATOR '+') AS delivery FROM sa_orderitems where sa_orderid="+sa_orderid+" GROUP BY sa_orderid) od ON o.sa_orderid = od.sa_orderid SET o.delivery = od.delivery ");
|
|
|
+ if (type.equals("配件订单")) {
|
|
|
+ dbConnect.runSqlUpdate("UPDATE sa_order o JOIN (SELECT sa_orderid,GROUP_CONCAT(DISTINCT delivery SEPARATOR '+') AS delivery FROM sa_orderitems where sa_orderid=" + sa_orderid + " GROUP BY sa_orderid) od ON o.sa_orderid = od.sa_orderid SET o.delivery = od.delivery ");
|
|
|
}
|
|
|
- sqlList=new ArrayList<>();
|
|
|
+ sqlList = new ArrayList<>();
|
|
|
if (type.equals("配件订单")) {
|
|
|
- Rows rowsdetails = dbConnect.runSqlQuery("select t1.price,t1.amount,t1.sa_orderitemsid,t1.itemid,ifnull(t2.iswriteoff,0) iswriteoff,t3.begdate,t3.enddate from sa_orderitems t1 " +
|
|
|
- "left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid " +
|
|
|
- "left join sa_warrantycard t3 on t1.cardno=t3.cardno and t1.siteid=t3.siteid and t3.isvoid=0 and t3.deleted=0 where t1.sa_orderid=" + sa_orderid);
|
|
|
+ Rows rowsdetails = dbConnect.runSqlQuery("select t1.price,t1.amount,t1.sa_orderitemsid,t1.itemid,ifnull(t2.iswriteoff,0) iswriteoff,t3.begdate,t3.enddate from sa_orderitems t1 " + "left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid " + "left join sa_warrantycard t3 on t1.cardno=t3.cardno and t1.siteid=t3.siteid and t3.isvoid=0 and t3.deleted=0 where t1.sa_orderid=" + sa_orderid);
|
|
|
for (Row rowsdetail : rowsdetails) {
|
|
|
String billingstatus = "";
|
|
|
BigDecimal price = rowsdetail.getBigDecimal("price");
|
|
|
@@ -207,18 +202,18 @@ public class OrderItems extends Controller {
|
|
|
billingstatus = "保内收费";
|
|
|
} else {
|
|
|
billingstatus = "保内免费";
|
|
|
- if(sa_orderitemsids_insert.contains(rowsdetail.getLong("sa_orderitemsid"))){
|
|
|
+ if (sa_orderitemsids_insert.contains(rowsdetail.getLong("sa_orderitemsid"))) {
|
|
|
price = BigDecimal.ZERO;
|
|
|
amount = BigDecimal.ZERO;
|
|
|
}
|
|
|
|
|
|
}
|
|
|
- }else{
|
|
|
+ } else {
|
|
|
billingstatus = "保外收费";
|
|
|
}
|
|
|
}
|
|
|
- if(!billingstatus.equals("保内收费") ){
|
|
|
- if(sa_orderitemsids_insert.contains(rowsdetail.getLong("sa_orderitemsid"))){
|
|
|
+ if (!billingstatus.equals("保内收费")) {
|
|
|
+ if (sa_orderitemsids_insert.contains(rowsdetail.getLong("sa_orderitemsid"))) {
|
|
|
sqlList.add("update sa_orderitems set canoffqty=0 where sa_orderitemsid=" + rowsdetail.getLong("sa_orderitemsid"));
|
|
|
}
|
|
|
|
|
|
@@ -364,10 +359,13 @@ public class OrderItems extends Controller {
|
|
|
custamount = item.getBigDecimal("custamount");
|
|
|
// int year = Year.now().getValue();
|
|
|
// int quarter = YearMonth.now().get(IsoFields.QUARTER_OF_YEAR);
|
|
|
- Rows custamountrows = dbConnect.runSqlQuery("select * from sa_agents where sys_enterpriseid=" + sys_enterpriseid + " and siteid='" + siteid + "'");
|
|
|
- if (custamountrows.isNotEmpty() && !type.equals("配件订单")) {
|
|
|
- if (custamountrows.get(0).getDouble("pricerate") > 0) {
|
|
|
- rwpricerate = custamountrows.get(0).getBigDecimal("pricerate");
|
|
|
+ Rows agentrows = dbConnect.runSqlQuery("select * from sa_agents where sys_enterpriseid=" + sys_enterpriseid + " and siteid='" + siteid + "'");
|
|
|
+ Rows itemrows = dbConnect.runSqlQuery("select topclassnum from plm_item where itemid=" + itemid + " and siteid='" + siteid + "'");
|
|
|
+ if (agentrows.isNotEmpty() && !type.equals("配件订单")) {
|
|
|
+ int year = agentrows.get(0).getInteger("year");
|
|
|
+ int quarter = agentrows.get(0).getInteger("quarter");
|
|
|
+ if (getYear() == year && getQuarterOfYear() >= quarter && "集成灶".equals(itemrows.get(0).getString("topclassnum")) && agentrows.get(0).getDouble("pricerate") > 0) {
|
|
|
+ rwpricerate = agentrows.get(0).getBigDecimal("pricerate");
|
|
|
}
|
|
|
}
|
|
|
|
|
|
@@ -388,8 +386,8 @@ public class OrderItems extends Controller {
|
|
|
}
|
|
|
} else {
|
|
|
price = price.multiply(rwpricerate).add(item.getBigDecimal("custamount"));
|
|
|
- if(item.containsKey("defaultprice")){
|
|
|
- defaultprice=item.getBigDecimal("defaultprice");
|
|
|
+ if (item.containsKey("defaultprice")) {
|
|
|
+ defaultprice = item.getBigDecimal("defaultprice");
|
|
|
price = defaultprice.multiply(rwpricerate).add(custamount);
|
|
|
}
|
|
|
sqlList.add(orderItemsHelper.getUpdateSQL(sa_orderitemsid, item, itemRow, type, defaultprice, price, saleprice, width, length).getSQL());
|
|
|
@@ -443,9 +441,7 @@ public class OrderItems extends Controller {
|
|
|
}
|
|
|
sqlList = new ArrayList<>();
|
|
|
if (type.equals("配件订单")) {
|
|
|
- Rows rowsdetails = dbConnect.runSqlQuery("select t1.price,t1.amount,t1.sa_orderitemsid,t1.itemid,ifnull(t2.iswriteoff,0) iswriteoff,t3.begdate,t3.enddate from sa_orderitems t1 " +
|
|
|
- "left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid " +
|
|
|
- "left join sa_warrantycard t3 on t1.cardno=t3.cardno and t1.siteid=t3.siteid and t3.isvoid=0 and t3.deleted=0 where t1.sa_orderid=" + sa_orderid);
|
|
|
+ Rows rowsdetails = dbConnect.runSqlQuery("select t1.price,t1.amount,t1.sa_orderitemsid,t1.itemid,ifnull(t2.iswriteoff,0) iswriteoff,t3.begdate,t3.enddate from sa_orderitems t1 " + "left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid " + "left join sa_warrantycard t3 on t1.cardno=t3.cardno and t1.siteid=t3.siteid and t3.isvoid=0 and t3.deleted=0 where t1.sa_orderid=" + sa_orderid);
|
|
|
for (Row rowsdetail : rowsdetails) {
|
|
|
String billingstatus = "";
|
|
|
BigDecimal price = rowsdetail.getBigDecimal("price");
|
|
|
@@ -489,11 +485,11 @@ public class OrderItems extends Controller {
|
|
|
|
|
|
@API(title = "一键设置发货方式", apiversion = R.ID2025121316011603.v1.class)
|
|
|
public String oneclickchangedelivery() throws YosException {
|
|
|
- String delivery= content.getString("delivery");
|
|
|
- long sa_orderid= content.getLong("sa_orderid");
|
|
|
+ String delivery = content.getString("delivery");
|
|
|
+ long sa_orderid = content.getLong("sa_orderid");
|
|
|
ArrayList<String> sqlList = new ArrayList<>();
|
|
|
- sqlList.add("update sa_orderitems set delivery='"+delivery+"' where sa_orderid="+sa_orderid);
|
|
|
- sqlList.add("update sa_order set delivery='"+delivery+"' where sa_orderid="+sa_orderid);
|
|
|
+ sqlList.add("update sa_orderitems set delivery='" + delivery + "' where sa_orderid=" + sa_orderid);
|
|
|
+ sqlList.add("update sa_order set delivery='" + delivery + "' where sa_orderid=" + sa_orderid);
|
|
|
dbConnect.runSqlUpdate(sqlList);
|
|
|
return getSucReturnObject().toString();
|
|
|
}
|
|
|
@@ -1343,7 +1339,7 @@ public class OrderItems extends Controller {
|
|
|
itemquery.setSiteid(siteid);
|
|
|
itemquery.setCondition("t1.itemno", "t1.itemname", "t1.model", "t1.spec", "t1.standards", "t3.material", "t3.erpitemno");
|
|
|
itemquery.setWhere("status", "审核");
|
|
|
- if(!ismanage){
|
|
|
+ if (!ismanage) {
|
|
|
itemquery.setWhere("t1.isonsale=1 and t1.isused=1");
|
|
|
}
|
|
|
itemquery.setWhere("t1.ismodule=0");
|
|
|
@@ -1665,8 +1661,7 @@ public class OrderItems extends Controller {
|
|
|
sqlList.add("delete from sa_accountbalance_freez where sa_accountbalance_freezid=" + freezRow.getLong("sa_accountbalance_freezid"));
|
|
|
}
|
|
|
}
|
|
|
- sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "关闭", "行" + rowsdetails.toJsonArray("rowno") + "关闭成功")
|
|
|
- .getSQL());
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "关闭", "行" + rowsdetails.toJsonArray("rowno") + "关闭成功").getSQL());
|
|
|
} 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"));
|
|
|
@@ -1691,8 +1686,7 @@ public class OrderItems extends Controller {
|
|
|
sqlList.add("update sa_accountbalance_freez set amount=" + amount.add(returnamount) + " where sa_accountbalance_freezid=" + freezRow.getLong("sa_accountbalance_freezid"));
|
|
|
sqlList.add("update sa_accountbalance set freezamount=freezamount+" + returnamount + " where sa_accountbalanceid=" + freezRow.getLong("sa_accountbalanceid"));
|
|
|
}
|
|
|
- sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "反关闭", "行" + rowsdetails.toJsonArray("rowno") + "反关闭成功")
|
|
|
- .getSQL());
|
|
|
+ sqlList.add(DataContrlLog.createLog(this, "sa_order", sa_orderid, "反关闭", "行" + rowsdetails.toJsonArray("rowno") + "反关闭成功").getSQL());
|
|
|
}
|
|
|
/******** 增加总仓可销售量 ********/
|
|
|
if (isclose) {
|
|
|
@@ -1700,17 +1694,14 @@ public class OrderItems extends Controller {
|
|
|
} else {
|
|
|
sqlList.addAll(updateIcinvbal_sale(rowsdetails, false, true));
|
|
|
}
|
|
|
- int i=dbConnect.runSqlUpdate(sqlList);
|
|
|
- if(i>=0){
|
|
|
+ int i = dbConnect.runSqlUpdate(sqlList);
|
|
|
+ if (i >= 0) {
|
|
|
if (isclose) {
|
|
|
- if(dbConnect.runSqlQuery("select * from sa_orderitems where isclose=0 and undeliqty!=0 and sa_orderid="+sa_orderid).isEmpty()){
|
|
|
- dbConnect.runSqlUpdate("update sa_order set status='关闭',closeby='"+username+"',closedate=CURRENT_TIME where sa_orderid=" +sa_orderid);
|
|
|
+ if (dbConnect.runSqlQuery("select * from sa_orderitems where isclose=0 and undeliqty!=0 and sa_orderid=" + sa_orderid).isEmpty()) {
|
|
|
+ dbConnect.runSqlUpdate("update sa_order set status='关闭',closeby='" + username + "',closedate=CURRENT_TIME where sa_orderid=" + sa_orderid);
|
|
|
Rows accountbalancerows = 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=" + row.getLong("sys_enterpriseid"));
|
|
|
- dbConnect.runSqlUpdate("UPDATE sa_accountbalance t1 " +
|
|
|
- "INNER JOIN sa_accountbalance_freez t2 ON t1.sa_accountbalanceid = t2.sa_accountbalanceid " +
|
|
|
- "SET t1.freezamount = case when ifnull(t1.freezamount,0)>t2.amount then t1.freezamount-t2.amount else 0 end " +
|
|
|
- "WHERE t1.sa_accountbalanceid="+accountbalancerows.get(0).getLong("sa_accountbalanceid")+" and t2.sourcetable='sa_order' and t2.sourceid="+sa_orderid);
|
|
|
- dbConnect.runSqlUpdate("delete from sa_accountbalance_freez t1 WHERE t1.sourcetable='sa_order' and t1.sourceid="+sa_orderid);
|
|
|
+ dbConnect.runSqlUpdate("UPDATE sa_accountbalance t1 " + "INNER JOIN sa_accountbalance_freez t2 ON t1.sa_accountbalanceid = t2.sa_accountbalanceid " + "SET t1.freezamount = case when ifnull(t1.freezamount,0)>t2.amount then t1.freezamount-t2.amount else 0 end " + "WHERE t1.sa_accountbalanceid=" + accountbalancerows.get(0).getLong("sa_accountbalanceid") + " and t2.sourcetable='sa_order' and t2.sourceid=" + sa_orderid);
|
|
|
+ dbConnect.runSqlUpdate("delete from sa_accountbalance_freez t1 WHERE t1.sourcetable='sa_order' and t1.sourceid=" + sa_orderid);
|
|
|
}
|
|
|
} else {
|
|
|
dbConnect.runSqlUpdate("update sa_order set status='审核',closeby='',closedate=null where sa_orderid=" + sa_orderid);
|
|
|
@@ -1718,7 +1709,6 @@ public class OrderItems extends Controller {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
return getSucReturnObject().toString();
|
|
|
}
|
|
|
|
|
|
@@ -1746,17 +1736,14 @@ public class OrderItems extends Controller {
|
|
|
int rownum = row.getInteger("rowno");
|
|
|
if (isclose) {
|
|
|
if (row.getBoolean("isclose")) {
|
|
|
- throw new YosException("行" + rownum
|
|
|
- + "已经关闭,不可重复关闭");
|
|
|
+ throw new YosException("行" + rownum + "已经关闭,不可重复关闭");
|
|
|
}
|
|
|
if (row.getBigDecimal("undeliqty").compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- throw new YosException("行" + rownum
|
|
|
- + "已发货完毕,不可关闭");
|
|
|
+ throw new YosException("行" + rownum + "已发货完毕,不可关闭");
|
|
|
}
|
|
|
|
|
|
if (rowsMap.containsKey(row.getString("sa_orderitemsid"))) {
|
|
|
- throw new YosException("行" + rownum
|
|
|
- + "存在新建的销售出库单,不可关闭");
|
|
|
+ throw new YosException("行" + rownum + "存在新建的销售出库单,不可关闭");
|
|
|
}
|
|
|
// if (saorderdetail.getPao(i).getPaoSet("SAINVOICEDETAIL")
|
|
|
// .count() > 0) {
|
|
|
@@ -1765,12 +1752,10 @@ public class OrderItems extends Controller {
|
|
|
// }
|
|
|
} else {
|
|
|
if (!row.getBoolean("isclose")) {
|
|
|
- throw new YosException("行" + rownum
|
|
|
- + "未关闭,不可取消关闭");
|
|
|
+ throw new YosException("行" + rownum + "未关闭,不可取消关闭");
|
|
|
}
|
|
|
if (row.getDouble("undeliqty") == 0) {
|
|
|
- throw new YosException("行" + rownum
|
|
|
- + "已发货完毕,不可取消关闭");
|
|
|
+ throw new YosException("行" + rownum + "已发货完毕,不可取消关闭");
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
@@ -1864,8 +1849,7 @@ public class OrderItems extends Controller {
|
|
|
if (close) {
|
|
|
qty = isinstock ? row.getBigDecimal("undeliqty") : row.getBigDecimal("undeliqty").negate();// 如果是扣减则根据数量进行扣减,反之根据未发货数量进行增加
|
|
|
} else {
|
|
|
- qty = isinstock ? row.getBigDecimal("undeliqty")
|
|
|
- : row.getBigDecimal("qty").negate();// 如果是扣减则根据数量进行扣减,反之根据未发货数量进行增加
|
|
|
+ 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);
|
|
|
}
|