|
|
@@ -22,9 +22,7 @@ import common.annotation.CACHEING;
|
|
|
import common.annotation.CACHEING_CLEAN;
|
|
|
import common.data.*;
|
|
|
import common.data.db.DBConnect;
|
|
|
-import common.data.db.SQLiteTable;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
-import org.apache.ibatis.jdbc.SQL;
|
|
|
import restcontroller.R;
|
|
|
import restcontroller.sale.cashbill.cashbill;
|
|
|
import restcontroller.sale.promotion.promotion;
|
|
|
@@ -34,10 +32,12 @@ import restcontroller.webmanage.sale.accessoryorder.accessoryorder;
|
|
|
import java.io.IOException;
|
|
|
import java.math.BigDecimal;
|
|
|
import java.text.SimpleDateFormat;
|
|
|
-import java.util.*;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Calendar;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
|
|
|
import static beans.order.Order.*;
|
|
|
-import static com.alibaba.fastjson.util.TypeUtils.castToBigDecimal;
|
|
|
|
|
|
/**
|
|
|
* 销售订单
|
|
|
@@ -907,191 +907,50 @@ public class Order extends Controller {
|
|
|
StringBuffer where = new StringBuffer(" 1=1 ");
|
|
|
if (content.containsKey("where")) {
|
|
|
JSONObject whereObject = content.getJSONObject("where");
|
|
|
- if (whereObject.containsKey("condition") && !"".equals(whereObject.getString("condition"))) {
|
|
|
- where.append(" and(");
|
|
|
- where.append("t1.sonum like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
- where.append("or t2.enterprisename like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
- where.append("or t2.abbreviation like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
-// where.append("or t5.erpbillno like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
- where.append("or t1.remarks like'%").append(whereObject.getString("condition")).append("%' ");
|
|
|
- where.append(")");
|
|
|
- }
|
|
|
- //状态
|
|
|
- if (whereObject.containsKey("status") && !"".equals(whereObject.getString("status"))) {
|
|
|
- where.append(" and(");
|
|
|
- where.append("t1.status ='").append(whereObject.getString("status")).append("' ");
|
|
|
- where.append(")");
|
|
|
- }
|
|
|
- if (whereObject.containsKey("type") && !"".equals(whereObject.getString("type"))) {
|
|
|
- where.append(" and(");
|
|
|
- where.append("t1.type like'%").append(whereObject.getString("type")).append("%' ");
|
|
|
- where.append(")");
|
|
|
- }
|
|
|
- //品牌
|
|
|
- if (whereObject.containsKey("brandname") && !"".equals(whereObject.getString("brandname"))) {
|
|
|
- where.append(" and(");
|
|
|
- where.append("t3.brandname like'%").append(whereObject.getString("brandname")).append("%' ");
|
|
|
- where.append(")");
|
|
|
- }
|
|
|
- //领域
|
|
|
- if (whereObject.containsKey("tradefield") && !"".equals(whereObject.getString("tradefield"))) {
|
|
|
- where.append(" and(");
|
|
|
- where.append("t1.tradefield like'%").append(whereObject.getString("tradefield")).append("%' ");
|
|
|
- where.append(")");
|
|
|
- }
|
|
|
if (whereObject.containsKey("begindate") && !"".equals(whereObject.getString("begindate"))) {
|
|
|
where.append(" and DATE_FORMAT(t1.billdate, '%Y-%m-%d') >='").append(whereObject.getString("begindate")).append("' ");
|
|
|
}
|
|
|
if (whereObject.containsKey("enddate") && !"".equals(whereObject.getString("enddate"))) {
|
|
|
where.append(" and DATE_FORMAT(t1.billdate, '%Y-%m-%d') <='").append(whereObject.getString("enddate")).append("' ");
|
|
|
}
|
|
|
- if (whereObject.containsKey("begindate1") && !"".equals(whereObject.getString("begindate1"))) {
|
|
|
- where.append(" and DATE_FORMAT(t1.submitdate, '%Y-%m-%d') >='").append(whereObject.getString("begindate1")).append("' ");
|
|
|
- }
|
|
|
- if (whereObject.containsKey("enddate1") && !"".equals(whereObject.getString("enddate1"))) {
|
|
|
- where.append(" and DATE_FORMAT(t1.submitdate, '%Y-%m-%d') <='").append(whereObject.getString("enddate1")).append("' ");
|
|
|
- }
|
|
|
- if (whereObject.containsKey("begindate2") && !"".equals(whereObject.getString("begindate2"))) {
|
|
|
- where.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') >='").append(whereObject.getString("begindate2")).append("' ");
|
|
|
- }
|
|
|
- if (whereObject.containsKey("enddate2") && !"".equals(whereObject.getString("enddate2"))) {
|
|
|
- where.append(" and DATE_FORMAT(t1.checkdate, '%Y-%m-%d') <='").append(whereObject.getString("enddate2")).append("' ");
|
|
|
- }
|
|
|
- if (whereObject.containsKey("remarks") && !"".equals(whereObject.getString("remarks"))) {
|
|
|
- where.append("and t1.remarks like'%").append(whereObject.getString("remarks")).append("%' ");
|
|
|
- }
|
|
|
- if (whereObject.containsKey("createby") && !"".equals(whereObject.getString("createby"))) {
|
|
|
- where.append("and t1.createby like'%").append(whereObject.getString("createby")).append("%' ");
|
|
|
- }
|
|
|
- if (whereObject.containsKey("checkby") && !"".equals(whereObject.getString("checkby"))) {
|
|
|
- where.append("and t1.checkby like'%").append(whereObject.getString("checkby")).append("%' ");
|
|
|
- }
|
|
|
- if (whereObject.containsKey("agentinfo") && !"".equals(whereObject.getString("agentinfo"))) {
|
|
|
- where.append(" and(");
|
|
|
- where.append(" t2.enterprisename like'%").append(whereObject.getString("agentinfo")).append("%' ");
|
|
|
- where.append("or t7.agentnum like'%").append(whereObject.getString("agentinfo")).append("%' ");
|
|
|
- where.append(")");
|
|
|
- }
|
|
|
-
|
|
|
-// if (whereObject.containsKey("writeoffstatus") && !"".equals(whereObject.getString("writeoffstatus"))) {
|
|
|
-// String writeoffstatus = whereObject.getStringValue("writeoffstatus");
|
|
|
-// if (writeoffstatus.equals("未核销")) {
|
|
|
-// where.append(" and t7.writeoffamount = 0");
|
|
|
-// } else if (writeoffstatus.equals("已核销")) {
|
|
|
-// where.append(" and t7.writeoffamount = t7.amount and t7.amount > 0");
|
|
|
-// } else {
|
|
|
-// where.append(" and t7.writeoffamount < t7.amount and t7.writeoffamount > 0");
|
|
|
-// }
|
|
|
-//
|
|
|
-// }
|
|
|
-// if (whereObject.containsKey("invoicestatus") && !"".equals(whereObject.getString("invoicestatus"))) {
|
|
|
-// String invoicestatus = whereObject.getStringValue("invoicestatus");
|
|
|
-// if (invoicestatus.equals("未开票")) {
|
|
|
-// where.append(" and t7.invoiceamount = 0");
|
|
|
-// } else if (invoicestatus.equals("已开票")) {
|
|
|
-// where.append(" and t7.invoiceamount = t7.amount and t7.amount > 0");
|
|
|
-// } else {
|
|
|
-// where.append(" and t7.invoiceamount < t7.amount and t7.invoiceamount > 0");
|
|
|
-// }
|
|
|
-//
|
|
|
-// }
|
|
|
- if (whereObject.containsKey("isreturn") && !"".equals(whereObject.getString("isreturn"))) {
|
|
|
- String isreturn = whereObject.getStringValue("isreturn");
|
|
|
- if (isreturn.equals("1")) {
|
|
|
- where.append(" and exists (select 1 from sa_orderitems where sa_orderid=t1.sa_orderid and siteid=t1.siteid and ifnull(returnqty,0)>0) ");
|
|
|
- } else {
|
|
|
- where.append(" and not exists (select 1 from sa_orderitems where sa_orderid=t1.sa_orderid and siteid=t1.siteid and ifnull(returnqty,0)=0) ");
|
|
|
- }
|
|
|
- }
|
|
|
- if (whereObject.containsKey("ischange") && !"".equals(whereObject.getString("ischange"))) {
|
|
|
- String ischange = whereObject.getStringValue("ischange");
|
|
|
- if (ischange.equals("0")) {
|
|
|
- where.append(" and not exists(SELECT * from sa_orderitems_change WHERE sa_orderid = t1.sa_orderid and siteid = t1.siteid)");
|
|
|
- } else {
|
|
|
- where.append(" and exists(SELECT * from sa_orderitems_change WHERE sa_orderid = t1.sa_orderid and siteid = t1.siteid)");
|
|
|
- }
|
|
|
- }
|
|
|
- if (whereObject.containsKey("tobeclosebyhand") && !"".equals(whereObject.getString("tobeclosebyhand"))) {
|
|
|
- String tobeclosebyhand = whereObject.getStringValue("tobeclosebyhand");
|
|
|
- if (tobeclosebyhand.equals("1")) {
|
|
|
- where.append(" and t1.status !='手工关闭' and sa_orderid in (select sa_orderid from sa_orderitems t1 left join (select t2.sa_orderitemsid,t2.siteid,sum(outwarehouseqty) sumoutwarehouseqty from sa_dispatch_items t2 inner join sa_dispatch t3 on t2.sa_dispatchid=t3.sa_dispatchid and t2.siteid=t3.siteid GROUP BY sa_orderitemsid,siteid) t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid where t1.qty>ifnull(t2.sumoutwarehouseqty,0) and t1.isfreeze=1) and sa_orderid in(select t1.sa_orderid from (select sa_orderid,t1.siteid,count(1) count from sa_orderitems t1 inner join (select t2.sa_orderitemsid,t2.siteid,sum(outwarehouseqty) sumoutwarehouseqty from sa_dispatch_items t2 inner join sa_dispatch t3 on t2.sa_dispatchid=t3.sa_dispatchid and t2.siteid=t3.siteid GROUP BY sa_orderitemsid,siteid) t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid where t1.isfreeze=0 and t1.qty=t2.sumoutwarehouseqty group by sa_orderid,t1.siteid) t1 inner join (select sa_orderid,t1.siteid,count(1) count from sa_orderitems t1 where t1.isfreeze=0 group by sa_orderid,t1.siteid) t2 on t1.siteid=t2.siteid and t1.sa_orderid=t2.sa_orderid where t1.count=t2.count)");
|
|
|
- } else {
|
|
|
- where.append(" and 1=1");
|
|
|
- }
|
|
|
- }
|
|
|
}
|
|
|
-// SQLFactory sqlFactory = new SQLFactory(this, "订单(管理端)_列表", pageSize, pageNumber, pageSorting);
|
|
|
-// if (isExport) {
|
|
|
-// sqlFactory = new SQLFactory(this, "订单(管理端)_列表");
|
|
|
-// }
|
|
|
-// sqlFactory.addParameter("siteid", siteid);
|
|
|
-// sqlFactory.addParameter("hrid", hrid);
|
|
|
-// sqlFactory.addParameter("userid", userid);
|
|
|
-// sqlFactory.addParameter_SQL("where", where);
|
|
|
-// String sql = sqlFactory.getSQL();
|
|
|
- QuerySQL querySQL = queryListManage1(where.toString());
|
|
|
- Rows rows;
|
|
|
+
|
|
|
+ QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_order",
|
|
|
+ "sa_orderid", "sonum", "type", "status", "submitdate", "checkdate", "remarks", "createby", "checkby", "billdate", "tradefield", "rec_contactsid", "delivery", "tracknumber", "mailno");
|
|
|
+
|
|
|
+ querySQL.setTableAlias("t1");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t2", "t2.sys_enterpriseid = t1.sys_enterpriseid and t2.siteid = t1.siteid",
|
|
|
+ "enterprisename");
|
|
|
+ querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t6", "t6.sys_enterpriseid=t1.sys_enterpriseid and t6.siteid = t1.siteid",
|
|
|
+ "agentnum");
|
|
|
+ querySQL.addQueryFields("amount", "CAST(0 AS CHAR(20))");
|
|
|
+ querySQL.addQueryFields("qty", "CAST(0 AS CHAR(20))");
|
|
|
+ querySQL.setCondition("t1.sonum", "t2.enterprisename", "t1.remarks");
|
|
|
+ querySQL.setWhere("t1.siteid", siteid);
|
|
|
+ querySQL.setWhere(where);
|
|
|
+ querySQL.setWhere("t1.deleted=0 and t1.type!='配件订单' and t1.status in('新建') and t1.createflag=0");
|
|
|
querySQL.setPage(pageSize, pageNumber);
|
|
|
- rows = querySQL.query();
|
|
|
+ querySQL.setOrderBy("t1.sa_orderid desc");
|
|
|
+ Rows rows = querySQL.query();
|
|
|
|
|
|
ArrayList<Long> ids = rows.toArrayList("sa_orderid", new ArrayList<>());
|
|
|
//查询数量金额
|
|
|
RowsMap OrderAmountRowsMap = beans.order.Order.getSumOrderAmount(this, ids);
|
|
|
|
|
|
-// SQLFactory ischangeSQl = new SQLFactory("sql:SELECT distinct sa_orderid from sa_orderitems_change WHERE siteid='" + siteid + "' and sa_orderid in $sa_orderids$ ");
|
|
|
-// ischangeSQl.addParameter_in("sa_orderids", rows.toArrayList("sa_orderid"));
|
|
|
- ArrayList<Long> sa_orderids = rows.toArrayList("sa_orderid", new ArrayList<>());
|
|
|
- sa_orderids.add(0l);
|
|
|
- ArrayList<Long> ischangesa_orderidList = dbConnect.runSqlQuery("SELECT distinct sa_orderid from sa_orderitems_change WHERE siteid='" + siteid + "' and sa_orderid in" + sa_orderids.toString().replace("[", "(").replace("]", ")")).toArrayList("sa_orderid", new ArrayList<>());
|
|
|
-
|
|
|
for (Row row : rows) {
|
|
|
Long id = row.getLong("sa_orderid");
|
|
|
if (OrderAmountRowsMap.get(id.toString()).isNotEmpty()) {
|
|
|
row.put("amount", OrderAmountRowsMap.get(id.toString()).get(0).getBigDecimal("amount"));
|
|
|
row.put("defaultamount", OrderAmountRowsMap.get(id.toString()).get(0).getBigDecimal("defaultamount"));
|
|
|
row.put("qty", OrderAmountRowsMap.get(id.toString()).get(0).getBigDecimal("qty"));
|
|
|
- row.put("writeoffamount", OrderAmountRowsMap.get(id.toString()).get(0).getBigDecimal("writeoffamount"));
|
|
|
- row.put("invoiceamount", OrderAmountRowsMap.get(id.toString()).get(0).getBigDecimal("invoiceamount"));
|
|
|
- if (OrderAmountRowsMap.get(id.toString()).get(0).getBigDecimal("returnqty").compareTo(BigDecimal.ZERO) > 0) {
|
|
|
- row.put("isreturn", "1");
|
|
|
- } else {
|
|
|
- row.put("isreturn", "0");
|
|
|
- }
|
|
|
} else {
|
|
|
row.put("amount", 0);
|
|
|
row.put("defaultamount", 0);
|
|
|
- row.put("sumamount", 0);
|
|
|
row.put("qty", 0);
|
|
|
- row.put("writeoffamount", 0);
|
|
|
- row.put("invoiceamount", 0);
|
|
|
- row.put("isreturn", "0");
|
|
|
- }
|
|
|
- BigDecimal writeoffamount = row.getBigDecimal("writeoffamount");
|
|
|
- BigDecimal invoiceamount = row.getBigDecimal("invoiceamount");
|
|
|
- BigDecimal amount = row.getBigDecimal("amount");
|
|
|
- row.put("ischange", ischangesa_orderidList.contains(row.getLong("sa_orderid")) ? "1" : "0");
|
|
|
-
|
|
|
- if (writeoffamount.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- row.put("writeoffstatus", "未核销");
|
|
|
- } else if (writeoffamount.compareTo(amount) == 0) {
|
|
|
- row.put("writeoffstatus", "已核销");
|
|
|
- } else {
|
|
|
- row.put("writeoffstatus", "部分核销");
|
|
|
- }
|
|
|
- if (invoiceamount.compareTo(BigDecimal.ZERO) == 0) {
|
|
|
- row.put("invoicestatus", "未开票");
|
|
|
- } else if (invoiceamount.compareTo(amount) == 0) {
|
|
|
- row.put("invoicestatus", "已开票");
|
|
|
- } else {
|
|
|
- row.put("invoicestatus", "部分开票");
|
|
|
}
|
|
|
-
|
|
|
//收货信息
|
|
|
row.put("contacts", beans.order.Order.getContactsRow(this, row.getLong("rec_contactsid")));
|
|
|
-
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
return getSucReturnObject().setData(rows).toString();
|
|
|
}
|
|
|
|
|
|
@@ -1283,24 +1142,6 @@ public class Order extends Controller {
|
|
|
return querySQL;
|
|
|
}
|
|
|
|
|
|
- public QuerySQL queryListManage1(String where) throws YosException {
|
|
|
- QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_order",
|
|
|
- "sa_orderid", "sonum", "type", "status", "submitdate", "checkdate", "remarks", "createby", "checkby", "billdate", "tradefield", "rec_contactsid", "delivery", "tracknumber", "mailno");
|
|
|
-
|
|
|
- querySQL.setTableAlias("t1");
|
|
|
- querySQL.addJoinTable(JOINTYPE.left, "sys_enterprise", "t2", "t2.sys_enterpriseid = t1.sys_enterpriseid and t2.siteid = t1.siteid",
|
|
|
- "enterprisename");
|
|
|
- querySQL.addJoinTable(JOINTYPE.left, "sa_agents", "t6", "t6.sys_enterpriseid=t1.sys_enterpriseid and t6.siteid = t1.siteid",
|
|
|
- "agentnum");
|
|
|
- querySQL.addJoinTable(JOINTYPE.left, "sa_promotion", "t7", "t7.sa_promotionid=t1.sa_promotionid and t7.siteid = t1.siteid",
|
|
|
- "promnum", "promname");
|
|
|
- querySQL.addQueryFields("amount", "CAST(0 AS CHAR(20))");
|
|
|
- querySQL.addQueryFields("qty", "CAST(0 AS CHAR(20))");
|
|
|
- querySQL.setWhere("t1.siteid", siteid);
|
|
|
- querySQL.setWhere(where);
|
|
|
- querySQL.setWhere("t1.deleted=0 and t1.type!='配件订单' and t1.status in('新建','提交') and t1.createflag=0");
|
|
|
- return querySQL;
|
|
|
- }
|
|
|
|
|
|
@API(title = "查询订单列表(业务员)", apiversion = R.ID20221111145202.v1.class)
|
|
|
public String selectList() throws YosException, IOException {
|