|
|
@@ -4,7 +4,6 @@ import beans.data.BatchDeleteErr;
|
|
|
import beans.datacontrllog.DataContrlLog;
|
|
|
import beans.dispatch.Dispatch;
|
|
|
import beans.parameter.Parameter;
|
|
|
-import beans.uploaderpdata.UploadDataToERP;
|
|
|
import com.alibaba.fastjson.JSONArray;
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
import common.Controller;
|
|
|
@@ -17,10 +16,12 @@ import common.data.Rows;
|
|
|
import common.data.RowsMap;
|
|
|
import common.data.SQLFactory;
|
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
+import org.apache.log4j.Logger;
|
|
|
import restcontroller.R;
|
|
|
import restcontroller.webmanage.executorService.Executor;
|
|
|
import restcontroller.webmanage.sale.order.Order;
|
|
|
import restcontroller.webmanage.sale.order.OrderItems;
|
|
|
+import utility.ERPDocking;
|
|
|
|
|
|
import java.math.BigDecimal;
|
|
|
import java.util.ArrayList;
|
|
|
@@ -33,7 +34,7 @@ import static java.time.LocalDate.now;
|
|
|
*/
|
|
|
@API(title = "发货单")
|
|
|
public class dispatch extends Controller {
|
|
|
-
|
|
|
+ private static Logger logger = Logger.getLogger(dispatch.class);
|
|
|
public dispatch(JSONObject arg0) throws YosException {
|
|
|
super(arg0);
|
|
|
// TODO Auto-generated constructor stub
|
|
|
@@ -411,7 +412,14 @@ public class dispatch extends Controller {
|
|
|
.toString();
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ //对接erp生成erp发货单
|
|
|
+ if (Parameter.get("system.ccerp_dockswitch").equalsIgnoreCase("true")) {
|
|
|
+ ERPDocking erpDocking =new ERPDocking();
|
|
|
+ String result =erpDocking.closeErpSainvoice(rows.get(0).getString("billno"),true);
|
|
|
+ if(!result.equals("true")){
|
|
|
+ return getErrReturnObject().setErrMsg(result).toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
ArrayList<String> sqlList = new ArrayList<>();
|
|
|
|
|
|
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 sa_dispatch_items where sa_dispatchid="+ sa_dispatchid+")" );
|
|
|
@@ -444,13 +452,58 @@ public class dispatch extends Controller {
|
|
|
return getSucReturnObject().toString();
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ @API(title = "自动关闭(erp调用)", apiversion = R.ID20230413110103.v1.class)
|
|
|
+ @CACHEING_CLEAN(apiClass = {Order.class, OrderItems.class, restcontroller.sale.order.Order.class, dispatch.class, dispatchItems.class, R.ID20230320160203.v1.class})
|
|
|
+ public String autoClose() throws YosException {
|
|
|
+ String finvonum = content.getString("finvonum");
|
|
|
+
|
|
|
+ Rows rows = dbConnect.runSqlQuery("select * from sa_dispatch where status='复核' and siteid='ZZYOS' and billno='"+finvonum+"'");
|
|
|
+ Rows rowsdetail = dbConnect.runSqlQuery("select t1.* from sa_dispatch_items t1 inner join sa_dispatch t2 on t1.sa_dispatchid=t2.sa_dispatchid and t1.siteid=t2.siteid where t2.status='复核' and t1.siteid='ZZYOS'");
|
|
|
+ RowsMap rowsMap = rowsdetail.toRowsMap("sa_dispatchid");
|
|
|
+ ArrayList<String> sqlList = new ArrayList<>();
|
|
|
+ ERPDocking erpDocking =new ERPDocking();
|
|
|
+ for (Row row : rows) {
|
|
|
+ String sa_dispatchid = row.getString("sa_dispatchid");
|
|
|
+ String billno = row.getString("billno");
|
|
|
+ String result =erpDocking.closeErpSainvoice(billno,false);
|
|
|
+ if(result.equals("true")){
|
|
|
+ sqlList.add("update sa_dispatch set status='关闭' where sa_dispatchid='"+sa_dispatchid+"' and siteid='ZZYOS'");
|
|
|
+ SQLFactory sqlFactory = new SQLFactory(new DataContrlLog(), "数据操作日志新增");
|
|
|
+ sqlFactory.addParameter("ownertable", "sa_dispatch");
|
|
|
+ sqlFactory.addParameter("ownerid", sa_dispatchid);
|
|
|
+ sqlFactory.addParameter("action", "自动关闭");
|
|
|
+ sqlFactory.addParameter("remarks", "发货单自动关闭成功");
|
|
|
+ sqlFactory.addParameter("actionuserid", "1");
|
|
|
+ sqlFactory.addParameter("actionby", "admin");
|
|
|
+ sqlFactory.addParameter("siteid", "ZZYOS");
|
|
|
+ sqlList.add(sqlFactory.getSQL());
|
|
|
+ }else {
|
|
|
+ logger.info("发货单自动关闭错误:"+result);
|
|
|
+ return getErrReturnObject().setErrMsg(result).toString();
|
|
|
+ }
|
|
|
+ JSONArray jsonArray = erpDocking.queryErpSainvoice(billno);
|
|
|
+ if(!jsonArray.isEmpty()){
|
|
|
+ for (Object object:jsonArray) {
|
|
|
+ JSONObject jsonObject = (JSONObject)object;
|
|
|
+ sqlList.add("update sa_dispatch_items set outwarehouseqty="+jsonObject.getBigDecimalValue("fqty1")+" where rowno ="+jsonObject.getIntValue("frownum")+" and sa_dispatchid='"+sa_dispatchid+"' and siteid='ZZYOS'");
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+ return getSucReturnObject().toString();
|
|
|
+ }
|
|
|
+
|
|
|
@API(title = "复核反复核", apiversion = R.ID20221114135803.v1.class)
|
|
|
@CACHEING_CLEAN(apiversions = {R.ID20221114135303.v1.class, R.ID20221114135403.v1.class, R.ID20230320160203.v1.class})
|
|
|
public String recheck() throws YosException {
|
|
|
Long sa_dispatchid = content.getLong("sa_dispatchid");
|
|
|
boolean isrecheck = content.getBooleanValue("isrecheck");
|
|
|
- Rows rows = dbConnect.runSqlQuery("select sa_dispatchid,status,billno from sa_dispatch where sa_dispatchid ='"
|
|
|
- + sa_dispatchid + "' and siteid='" + siteid + "'");
|
|
|
+ Rows rows = dbConnect.runSqlQuery("select t1.*,t3.agentnum,t2.enterprisename,t4.sonum,t5.name,t5.phonenumber,t5.address from sa_dispatch t1 left join sys_enterprise t2 on t1.sys_enterpriseid=t2.sys_enterpriseid and t1.siteid=t2.siteid left join sa_agents t3 on t1.sys_enterpriseid=t3.sys_enterpriseid and t1.siteid=t3.siteid left join sa_order t4 on t1.sa_orderid=t4.sa_orderid and t1.siteid=t4.siteid left join sys_enterprise_contacts t5 on t1.rec_contactsid=t5.contactsid and t1.siteid=t5.siteid where t1.sa_dispatchid ='"
|
|
|
+ + sa_dispatchid + "' and t1.siteid='" + siteid + "'");
|
|
|
+ Rows rowsdetail = dbConnect.runSqlQuery("select t3.sonum,t2.rowno sorowno,t4.itemno,t1.batchno,t1.rowno,t1.qty,t2.price,t1.remarks from sa_dispatch_items t1 inner join sa_orderitems t2 on t1.sa_orderitemsid=t2.sa_orderitemsid and t1.siteid=t2.siteid left join sa_order t3 on t2.sa_orderid=t3.sa_orderid and t2.siteid=t3.siteid left join plm_item t4 on t1.itemid=t4.itemid and t1.siteid=t4.siteid where t1.sa_dispatchid ='"
|
|
|
+ + sa_dispatchid + "' and t1.siteid='" + siteid + "'");
|
|
|
for (Row row : rows) {
|
|
|
if (isrecheck) {
|
|
|
if (!row.getString("status").equals("审核")) {
|
|
|
@@ -470,7 +523,15 @@ public class dispatch extends Controller {
|
|
|
if (isrecheck) {
|
|
|
sqlFactoryupdate = new SQLFactory(this, "发货单复核");
|
|
|
Rows orderRows =dbConnect.runSqlQuery("select distinct t1.sa_orderid from sa_orderitems t1 inner join sa_dispatch_items t2 on t1.siteid=t2.siteid and t1.sa_orderitemsid=t2.sa_orderitemsid where t1.siteid='" + siteid + "' and t2.sa_dispatchid=" + sa_dispatchid);
|
|
|
-
|
|
|
+ //对接erp生成erp发货单
|
|
|
+ if (Parameter.get("system.ccerp_dockswitch").equalsIgnoreCase("true")) {
|
|
|
+ ERPDocking erpDocking =new ERPDocking();
|
|
|
+ String result =erpDocking.createErpSainvoice(rows.get(0),rowsdetail);
|
|
|
+ if(!result.equals("true")){
|
|
|
+ System.out.println(result);
|
|
|
+ return getErrReturnObject().setErrMsg(result).toString();
|
|
|
+ }
|
|
|
+ }
|
|
|
//判断当前订单是否已发完货,如果发完,则生把订单变为关闭状态
|
|
|
//总数量
|
|
|
Rows totalRows = dbConnect.runSqlQuery("select count(1) count,sa_orderid from sa_orderitems where siteid='" + siteid + "' group by sa_orderid");
|
|
|
@@ -485,7 +546,7 @@ public class dispatch extends Controller {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+ Executor.sendEml(this, "dispatchreccheck", sa_dispatchid,new ArrayList<>());
|
|
|
sqlList.add(DataContrlLog.createLog(this, "sa_dispatch", sa_dispatchid, "复核", "发货单复核成功").getSQL());
|
|
|
} else {
|
|
|
sqlFactoryupdate = new SQLFactory(this, "发货单反复核");
|
|
|
@@ -496,18 +557,6 @@ public class dispatch extends Controller {
|
|
|
sqlFactoryupdate.addParameter("recheckby", username);
|
|
|
sqlList.add(sqlFactoryupdate.getSQL());
|
|
|
dbConnect.runSqlUpdate(sqlList);
|
|
|
- if (isrecheck) {
|
|
|
- if (Parameter.get("system.erp_dockswitch").equalsIgnoreCase("true")) {
|
|
|
- UploadDataToERP uploadDataToERP = new UploadDataToERP(this, sa_dispatchid, "");
|
|
|
- boolean issuccess = uploadDataToERP.upload();
|
|
|
- if (!issuccess) {
|
|
|
- content.put("isrecheck", false);
|
|
|
- recheck();
|
|
|
- return getErrReturnObject().setErrMsg("上传ERP失败,当前单据将自动反复核,请检查!").toString();
|
|
|
- }
|
|
|
- }
|
|
|
- Executor.sendEml(this, "dispatchreccheck", sa_dispatchid,new ArrayList<>());
|
|
|
- }
|
|
|
return getSucReturnObject().toString();
|
|
|
}
|
|
|
|