|
|
@@ -0,0 +1,173 @@
|
|
|
+package restcontroller.webmanage.lsak3.stockbill;
|
|
|
+
|
|
|
+import com.alibaba.fastjson.JSONArray;
|
|
|
+import com.alibaba.fastjson.JSONObject;
|
|
|
+import common.Controller;
|
|
|
+import common.YosException;
|
|
|
+import common.annotation.API;
|
|
|
+import common.data.Rows;
|
|
|
+import common.data.RowsMap;
|
|
|
+import common.data.SQLFactory;
|
|
|
+import restcontroller.R;
|
|
|
+
|
|
|
+import javax.swing.text.StyledEditorKit;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.Date;
|
|
|
+
|
|
|
+public class stockbill extends Controller {
|
|
|
+ /**
|
|
|
+ * 构造函数
|
|
|
+ *
|
|
|
+ * @param content
|
|
|
+ */
|
|
|
+ public stockbill(JSONObject content) throws YosException {
|
|
|
+ super(content);
|
|
|
+ }
|
|
|
+ ArrayList<String> sqlList =new ArrayList<>();
|
|
|
+ /**
|
|
|
+ * 更新YOS销售出库单
|
|
|
+ * @return
|
|
|
+ * @throws YosException
|
|
|
+ */
|
|
|
+ @API(title = "更新YOS销售出库单", apiversion = R.ID20230717144803.v1.class)
|
|
|
+ public String updateIcstockbill() throws YosException{
|
|
|
+ String msg = "";
|
|
|
+ int code = 1;
|
|
|
+
|
|
|
+ // 单据编号
|
|
|
+ String fbillnum = content.getString("fbillnum");
|
|
|
+ try {
|
|
|
+ // 经销商编号
|
|
|
+ String fagentnum = content.getString("fagentnum");
|
|
|
+ long sys_enterpriseid=0;
|
|
|
+ if(dbConnect.runSqlQuery("select sys_enterpriseid from sa_agents where siteid='lsa' and agentnum='"+fagentnum+"'").isNotEmpty()){
|
|
|
+ sys_enterpriseid=dbConnect.runSqlQuery("select sys_enterpriseid from sa_agents where siteid='lsa' and agentnum='"+fagentnum+"'").get(0).getLong("sys_enterpriseid");
|
|
|
+ }else{
|
|
|
+ msg ="yos中不存在【"+fagentnum+"】经销商";
|
|
|
+ return getErrReturnObject().setErrMsg(msg).toString();
|
|
|
+ }
|
|
|
+ // 单据日期
|
|
|
+ String fdate = content.getString("fdate");
|
|
|
+ // 会计期间
|
|
|
+ // String fperiod = content.getString("fperiod");
|
|
|
+ // 红蓝字
|
|
|
+ String frb = content.getString("frb");
|
|
|
+ // 表头仓库
|
|
|
+ // String fstockno = content.getString("fstockno");
|
|
|
+ // 单据类型明细
|
|
|
+ //String ftypemx = content.getString("ftypemx");
|
|
|
+ // 单据状态
|
|
|
+ String fstatus = content.getString("fstatus");
|
|
|
+ // 制单人
|
|
|
+ String createby = content.getString("createby");
|
|
|
+ // 制单日期
|
|
|
+ String createdate = content.getString("createdate");
|
|
|
+ // 审核人
|
|
|
+ String checkby = content.getString("checkby");
|
|
|
+ // 审核日期
|
|
|
+ String checkdate = content.getString("checkdate");
|
|
|
+ // 备注
|
|
|
+ String fnotes = content.getString("fnotes");
|
|
|
+ // 是否删除
|
|
|
+ String isdelete = content.getString("isdelete");
|
|
|
+
|
|
|
+
|
|
|
+ Rows stockbillRows = dbConnect.runSqlQuery("select * from st_stockbill where siteid='lsa' and status='审核' and billno='"+fbillnum+"'");
|
|
|
+ if(stockbillRows.isEmpty() && "0".equals(isdelete) && "审核".equals(fstatus)){
|
|
|
+ /**
|
|
|
+ * DRP不存在销售出库单,且中间表状态为审核且不在删除状态时,DRP中需新增该销售出库单
|
|
|
+ */
|
|
|
+ SQLFactory sqlFactory =new SQLFactory("销售出库单新增");
|
|
|
+ long st_stockbillid=createTableID("st_stockbill");
|
|
|
+ sqlFactory.addParameter("siteid","lsa");
|
|
|
+ sqlFactory.addParameter("st_stockbillid",st_stockbillid);
|
|
|
+ sqlFactory.addParameter("sys_enterpriseid",sys_enterpriseid);
|
|
|
+ sqlFactory.addParameter("billno",fbillnum);
|
|
|
+ sqlFactory.addParameter("type","销售出库");
|
|
|
+ sqlFactory.addParameter("rb",frb.equals("蓝")?1:0);
|
|
|
+ sqlFactory.addParameter("billdate",fdate);
|
|
|
+ sqlFactory.addParameter("createby",createby);
|
|
|
+ sqlFactory.addParameter("createdate",getDate(createdate));
|
|
|
+ sqlFactory.addParameter("changeby",createby);
|
|
|
+ sqlFactory.addParameter("changedate",getDate(createdate));
|
|
|
+ sqlFactory.addParameter("checkby",checkby);
|
|
|
+ sqlFactory.addParameter("checkdate",getDate(checkdate));
|
|
|
+ sqlFactory.addParameter("remarks",fnotes);
|
|
|
+ sqlList.add(sqlFactory.getSQL());
|
|
|
+
|
|
|
+ JSONArray detailarray = content.getJSONArray("icstockbilldetails");
|
|
|
+ Rows rows = dbConnect.runSqlQuery("select * from plm_item where siteid='lsa' ");
|
|
|
+ RowsMap itemRowsMap =rows.toRowsMap("itemno");
|
|
|
+ for (Object object:detailarray) {
|
|
|
+ JSONObject jsonObject = (JSONObject)object;
|
|
|
+ String frownum = jsonObject.getString("frownum");
|
|
|
+ String fitemno = jsonObject.getString("fitemno");
|
|
|
+ double fqty = Double.parseDouble(jsonObject.getString("fqty"));
|
|
|
+ fqty=fqty<0?-fqty:fqty;
|
|
|
+ //String fdetailstockno = jsonObject.getString("fstockno");
|
|
|
+ long sainvoicedetailid = jsonObject.getLong("sainvoicedetailid");
|
|
|
+ //String fbatchno = jsonObject.getString("fbatchno");
|
|
|
+ String fdetailnotes = jsonObject.getString("fnotes");
|
|
|
+ SQLFactory sqlFactorydetail =new SQLFactory("销售出库单明细新增");
|
|
|
+ sqlFactorydetail.addParameter("siteid","lsa");
|
|
|
+ sqlFactorydetail.addParameter("st_stockbill_itemsid", createTableID("st_stockbill_items"));
|
|
|
+ sqlFactorydetail.addParameter("st_stockbillid", st_stockbillid);
|
|
|
+ sqlFactorydetail.addParameter("rowno", frownum);
|
|
|
+ sqlFactorydetail.addParameter("sa_dispatch_itemsid", sainvoicedetailid);
|
|
|
+ sqlFactorydetail.addParameter("remarks", fnotes);
|
|
|
+ if(itemRowsMap.containsKey(fitemno) && itemRowsMap.get(fitemno).isNotEmpty()){
|
|
|
+ sqlFactorydetail.addParameter("itemid", itemRowsMap.get(fitemno).get(0).getLong("itemid"));
|
|
|
+ }else{
|
|
|
+ sqlFactorydetail.addParameter("itemid", 0);
|
|
|
+ }
|
|
|
+ sqlFactorydetail.addParameter("remarks", fdetailnotes);
|
|
|
+ sqlFactorydetail.addParameter("qty", fqty);
|
|
|
+ sqlList.add(sqlFactorydetail.getSQL());
|
|
|
+ }
|
|
|
+ //销售出库单审核逻辑待添加
|
|
|
+
|
|
|
+ }else if (!stockbillRows.isEmpty() && "0".equals(isdelete) && "审核".equals(fstatus)) {
|
|
|
+ /**
|
|
|
+ * DRP存在销售出库单,且中间表状态为审核且不在删除状态时,DRP中需将当前销售出库单先反审核,修改内容后再进行审核
|
|
|
+ */
|
|
|
+ //销售出库单反审核逻辑待添加
|
|
|
+
|
|
|
+ msg = "DRP单据状态为审核,现已反审核,下次同步时进行审核操作";
|
|
|
+ code = 0;
|
|
|
+ }else if (!stockbillRows.isEmpty() && ("1".equals(isdelete) || "新建".equals(fstatus))) {
|
|
|
+ /**
|
|
|
+ * DRP存在收入凭证,且中间表状态为新建或在删除状态时,DRP中需将当前收入销售出库单先反审核
|
|
|
+ */
|
|
|
+ //销售出库单反审核逻辑待添加
|
|
|
+
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ msg = e.getMessage();
|
|
|
+ if(msg==null) {
|
|
|
+ msg = "";
|
|
|
+ }
|
|
|
+ code = 0;
|
|
|
+ }
|
|
|
+ /**
|
|
|
+ * 如单据为新建状态,则,先把单据强行删除掉
|
|
|
+ */
|
|
|
+ dbConnect.runSqlUpdate(sqlList);
|
|
|
+ dbConnect.runSqlUpdate("delete from st_stockbill where status='新建'");
|
|
|
+ JSONObject returnObject =new JSONObject();
|
|
|
+ returnObject.put("msg", msg);
|
|
|
+ returnObject.put("code", code);
|
|
|
+ return returnObject.toString();
|
|
|
+ }
|
|
|
+
|
|
|
+ public Date getDate(String date) {
|
|
|
+ try {
|
|
|
+ Date a = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").parse(date);
|
|
|
+ return a;
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|