|
|
@@ -1,9 +1,19 @@
|
|
|
package common.crm.bean;
|
|
|
|
|
|
+import beans.enterprise.Enterprise;
|
|
|
+import beans.itemprice.ItemPrice;
|
|
|
import com.alibaba.fastjson2.JSONArray;
|
|
|
+import com.alibaba.fastjson2.JSONObject;
|
|
|
+import common.Controller;
|
|
|
import common.YosException;
|
|
|
-import org.apache.logging.log4j.Logger;
|
|
|
import common.crm.bean.core.CrmBase;
|
|
|
+import common.data.*;
|
|
|
+import org.apache.logging.log4j.Logger;
|
|
|
+
|
|
|
+import java.math.BigDecimal;
|
|
|
+import java.time.Year;
|
|
|
+import java.time.YearMonth;
|
|
|
+import java.time.temporal.IsoFields;
|
|
|
|
|
|
public class saorder extends CrmBase {
|
|
|
public saorder(Logger logger) {
|
|
|
@@ -16,8 +26,158 @@ public class saorder extends CrmBase {
|
|
|
}
|
|
|
|
|
|
//根据订单号,查询网销订单
|
|
|
- public JSONArray querySaorderList(String fagentnum, String[] fsonums) {
|
|
|
+ public JSONObject querySaorderList(String fagentnum, String[] fsonums) {
|
|
|
+ logger.info("网销订单查询", String.join(",", fsonums));
|
|
|
+ JSONObject resultObject = new JSONObject();
|
|
|
+ JSONObject dataObject = new JSONObject();
|
|
|
+ dataObject.put("fagentnum", fagentnum);
|
|
|
+ try {
|
|
|
+ dataObject.put("data", querySaorder(fsonums));
|
|
|
+ resultObject.put("msg", "成功");
|
|
|
+ resultObject.put("code", 1);
|
|
|
+ resultObject.put("data", dataObject);
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("网销订单查询失败", e);
|
|
|
+ resultObject.put("msg", e.getMessage());
|
|
|
+ resultObject.put("code", 0);
|
|
|
+ }
|
|
|
+ return resultObject;
|
|
|
+ }
|
|
|
+
|
|
|
+ public JSONObject insertSaorder(JSONObject crmOrder) {
|
|
|
+ logger.info("网销订单生成", crmOrder);
|
|
|
+ JSONObject resultObject = new JSONObject();
|
|
|
+ try {
|
|
|
+ Controller controller = getSysController("MD");
|
|
|
+ Rows agentRows = dbConnect.runSqlQuery("select * from sa_agents where agentnum ='" + crmOrder.getStringValue("fagentnum") + "'");
|
|
|
+
|
|
|
+ Rows accountclassRows = dbConnect.runSqlQuery("select * from sa_accountclass where siteid='MD' and accountno='01'");
|
|
|
+ if (agentRows.isNotEmpty()) {
|
|
|
+
|
|
|
+ SQLDump sqlDump = new SQLDump();
|
|
|
+ long sys_enterpriseid = agentRows.get(0).getLong("sys_enterpriseid");
|
|
|
+
|
|
|
+ BigDecimal rwpricerate = new BigDecimal(1);
|
|
|
+ if (agentRows.get(0).getDouble("pricerate") > 0 && agentRows.get(0).getInteger("year") == Year.now().getValue() && agentRows.get(0).getInteger("quarter") == YearMonth.now().get(IsoFields.QUARTER_OF_YEAR)) {
|
|
|
+ rwpricerate = agentRows.get(0).getBigDecimal("pricerate");
|
|
|
+ }
|
|
|
+
|
|
|
+ Row enterprise = Enterprise.getEnterprise(controller, sys_enterpriseid);
|
|
|
+
|
|
|
+ Rows financeRows = dbConnect.runSqlQuery("select * from sys_enterprise_finance where siteid='MD' and sys_enterpriseid='" + sys_enterpriseid + "' and isdefault=1");
|
|
|
+
|
|
|
+ InsertSQL orderInsert = SQLFactory.createInsertSQL(dbConnect, "sa_order");
|
|
|
+ String sonum = orderInsert.createBillCode("MD", "orderbill");
|
|
|
+ orderInsert.setValue("siteid", "MD");
|
|
|
+ orderInsert.setValue("sonum", sonum);
|
|
|
+ orderInsert.setValue("contact", crmOrder.getStringValue("fcontact"));
|
|
|
+ orderInsert.setValue("address", crmOrder.getStringValue("faddress"));
|
|
|
+ orderInsert.setValue("phonenumber", crmOrder.getStringValue("fphonenumber"));
|
|
|
+ orderInsert.setValue("billdate", getDate_Str());
|
|
|
+ orderInsert.setValue("sys_enterpriseid", sys_enterpriseid);
|
|
|
+ orderInsert.setValue("pay_enterpriseid", sys_enterpriseid);
|
|
|
+ orderInsert.setValue("sa_accountclassid", accountclassRows.get(0).getLong("sa_accountclassid"));
|
|
|
+ orderInsert.setValue("type", crmOrder.getStringValue("ftype"));
|
|
|
+ if (financeRows.isNotEmpty()) {
|
|
|
+ orderInsert.setValue("sys_enterprise_financeid", financeRows.get(0).getLong("sys_enterprise_financeid"));
|
|
|
+ orderInsert.setValue("invoicetaxno", financeRows.get(0).getString("taxno"));
|
|
|
+ orderInsert.setValue("invoiceaddress", financeRows.get(0).getString("address"));
|
|
|
+ orderInsert.setValue("invoicename", financeRows.get(0).getString("enterprisename"));
|
|
|
+ }
|
|
|
+ orderInsert.setValue("county", enterprise.getString("county"));
|
|
|
+ orderInsert.setValue("province", enterprise.getString("province"));
|
|
|
+ orderInsert.setValue("city", enterprise.getString("city"));
|
|
|
+ orderInsert.setValue("status", "新建");
|
|
|
+ orderInsert.setValue("tradefield", "默认");
|
|
|
+ orderInsert.setValue("sa_brandid", 1);
|
|
|
+ orderInsert.setValue("createflag", 0);
|
|
|
+ orderInsert.setValue("custnum", crmOrder.getStringValue("fcustomnum"));
|
|
|
+ orderInsert.setValue("custsonum", crmOrder.getStringValue("forderno"));
|
|
|
+ orderInsert.setValue("createby", crmOrder.getStringValue("createby"));
|
|
|
+ orderInsert.setValue("changeby", crmOrder.getStringValue("createby"));
|
|
|
|
|
|
- return new JSONArray();
|
|
|
+ sqlDump.add(orderInsert);
|
|
|
+
|
|
|
+
|
|
|
+ JSONArray saorderdetail = crmOrder.getJSONArray("saorderdetail");
|
|
|
+ for (int i = 0; i < saorderdetail.size(); i++) {
|
|
|
+ JSONObject detail = saorderdetail.getJSONObject(i);
|
|
|
+ String fitemno = detail.getStringValue("fitemno");
|
|
|
+ Rows itemRows = dbConnect.runSqlQuery("select * from plm_item where siteid='MD' and itemno='" + fitemno + "'");
|
|
|
+ BigDecimal custamount = itemRows.get(0).getBigDecimal("custamount");
|
|
|
+
|
|
|
+ BigDecimal qty = detail.getBigDecimal("fqty");
|
|
|
+ long itemid = itemRows.get(0).getLong("itemid");
|
|
|
+ ItemPrice itemPrice = ItemPrice.getItemPrice(controller, sys_enterpriseid, itemid);
|
|
|
+ InsertSQL orderitemInsert = SQLFactory.createInsertSQL(dbConnect, "sa_orderitems");
|
|
|
+ orderitemInsert.setValue("siteid", "MD");
|
|
|
+ orderitemInsert.setValue("sa_orderid", orderInsert.getUniqueid());
|
|
|
+ orderitemInsert.setValue("sonum", sonum);
|
|
|
+ orderitemInsert.setValue("rowno", i + 1);
|
|
|
+ orderitemInsert.setValue("itemid", itemid);
|
|
|
+ orderitemInsert.setValue("itemno", fitemno);
|
|
|
+ orderitemInsert.setValue("itemname", itemRows.get(0).getString("itemname"));
|
|
|
+ orderitemInsert.setValue("model", itemRows.get(0).getString("model"));
|
|
|
+ Rows unitRows = itemRows.get(0).getRows("plm_unit", "unitid=:unitid");
|
|
|
+ if (unitRows.isNotEmpty()) {
|
|
|
+ orderitemInsert.setValue("unit", unitRows.get(0).getString("unitname"));
|
|
|
+ }
|
|
|
+ orderitemInsert.setValue("undeliqty", qty.doubleValue());
|
|
|
+ orderitemInsert.setValue("saleprice", itemPrice.getGraderateprice().doubleValue());//销售单价
|
|
|
+ orderitemInsert.setValue("custamount", custamount.doubleValue());//客户档案资料费
|
|
|
+ BigDecimal defaultprice = itemPrice.getGraderateprice().multiply(rwpricerate);
|
|
|
+ orderitemInsert.setValue("defaultprice", defaultprice.doubleValue());//折前价(元)
|
|
|
+ orderitemInsert.setValue("defaultamount", defaultprice.multiply(qty).doubleValue());//折前金额(元)
|
|
|
+ orderitemInsert.setValue("marketprice", itemPrice.getMarketprice().doubleValue());//牌价(元)
|
|
|
+ orderitemInsert.setValue("price", defaultprice.add(custamount).doubleValue());//单价,折后价(元)
|
|
|
+ orderitemInsert.setValue("amount", defaultprice.add(custamount).multiply(qty).doubleValue());//金额,折后金额(元)
|
|
|
+ //orderitemInsert.setValue("needdate", "");//需求日期,根据交期计算
|
|
|
+ orderitemInsert.setValue("qty", qty.doubleValue());
|
|
|
+ orderitemInsert.setValue("batchcontrol", itemRows.get(0).getBoolean("batchcontrol"));
|
|
|
+ orderitemInsert.setValue("spec", itemRows.get(0).getBoolean("spec"));
|
|
|
+ orderitemInsert.setValue("pricerate", itemPrice.getGradediscountrate().doubleValue());
|
|
|
+
|
|
|
+ orderitemInsert.setValue("rwpricerate", rwpricerate.doubleValue());
|
|
|
+ orderitemInsert.setValue("delivery", detail.getStringValue("fsendmode"));
|
|
|
+ orderitemInsert.setValue("remarks", detail.getStringValue("fnotes"));
|
|
|
+ sqlDump.add(orderitemInsert);
|
|
|
+ }
|
|
|
+ sqlDump.commit();
|
|
|
+
|
|
|
+ resultObject.put("fagentnum", crmOrder.getStringValue("fagentnum"));
|
|
|
+ resultObject.put("data", querySaorder(sonum));
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ logger.error("网销订单创建失败", e);
|
|
|
+ resultObject.put("code", 0);
|
|
|
+ resultObject.put("msg", e.getMessage());
|
|
|
+ return resultObject;
|
|
|
+ }
|
|
|
+ resultObject.put("code", 1);
|
|
|
+ resultObject.put("msg", "");
|
|
|
+ return resultObject;
|
|
|
}
|
|
|
+
|
|
|
+ public JSONArray querySaorder(String... sonums) throws YosException {
|
|
|
+ SQLFactory orderQuery = new SQLFactory(this, "订单表头查询");
|
|
|
+ orderQuery.addParameter_in("sonum", sonums);
|
|
|
+ Rows orderHead = orderQuery.runSqlQuery(dbConnect);
|
|
|
+ for (Row row : orderHead) {
|
|
|
+ long sa_orderid = row.getLong("saorderid");
|
|
|
+ SQLFactory orderDetailQuery = new SQLFactory(this, "订单表体查询");
|
|
|
+ orderDetailQuery.addParameter("sa_orderid", sa_orderid);
|
|
|
+ Rows orderDetail = orderDetailQuery.runSqlQuery(dbConnect);
|
|
|
+ row.put("qty", orderDetail.sum("qty"));
|
|
|
+ row.put("amount", orderDetail.sum("amount"));
|
|
|
+ row.put("saorderdetail", orderDetail);
|
|
|
+
|
|
|
+ SQLFactory outLogQuery = new SQLFactory(this, "订单出库记录查询");
|
|
|
+ outLogQuery.addParameter("sa_orderid", sa_orderid);
|
|
|
+ Rows outlog = outLogQuery.runSqlQuery(dbConnect);
|
|
|
+ row.put("icstockbilldetail", outlog);
|
|
|
+ }
|
|
|
+ return orderHead.toJsonArray();
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
}
|