|
|
@@ -105,8 +105,10 @@ public class Order extends Controller {
|
|
|
//营销账户类型ID
|
|
|
if ((type.equals("标准订单") || type.equals("特殊订单")) && content.getString("tradefield").equals("整装工程")) {
|
|
|
sqlFactory.addParameter("sa_accountclassid", "69");
|
|
|
+ updateAccountclassinfos(sa_orderid,69);
|
|
|
} else {
|
|
|
sqlFactory.addParameter("sa_accountclassid", beans.order.Order.getDefaultAccount(siteid, type));
|
|
|
+ updateAccountclassinfos(sa_orderid,beans.order.Order.getDefaultAccount(siteid, type));
|
|
|
}
|
|
|
//品牌ID
|
|
|
sqlFactory.addParameter("sa_brandid", sa_brandid);
|
|
|
@@ -164,6 +166,7 @@ public class Order extends Controller {
|
|
|
}
|
|
|
if(content.containsKey("sa_accountclassid")){
|
|
|
sqlFactory.addParameter("sa_accountclassid", content.getLongValue("sa_accountclassid"));
|
|
|
+ updateAccountclassinfos(sa_orderid,content.getLongValue("sa_accountclassid"));
|
|
|
}
|
|
|
} else {
|
|
|
//订单更新时
|
|
|
@@ -181,6 +184,7 @@ public class Order extends Controller {
|
|
|
}
|
|
|
}
|
|
|
sqlFactory.addParameter("sa_accountclassid", content.getLongValue("sa_accountclassid"));
|
|
|
+ updateAccountclassinfos(sa_orderid, content.getLongValue("sa_accountclassid"));
|
|
|
}
|
|
|
if (billdate.equals("")) {
|
|
|
sqlFactory.addParameter_SQL("billdate", "createdate");
|
|
|
@@ -2769,6 +2773,102 @@ public class Order extends Controller {
|
|
|
return getSucReturnObject().setData(rolename).toString();
|
|
|
}
|
|
|
|
|
|
+ /**
|
|
|
+ * 更新订单扣款信息
|
|
|
+ */
|
|
|
+ public void updateAccountclassinfos(Long sa_orderid,long sa_accountclassid) throws YosException {
|
|
|
+
|
|
|
+ Rows orderRows = getOrderRows(this, sa_orderid);
|
|
|
+
|
|
|
+
|
|
|
+ if (orderRows.isEmpty()) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ JSONArray jsonArray =new JSONArray();
|
|
|
+ BigDecimal orderSumamount = BigDecimal.ZERO;
|
|
|
+ Rows classamountrows =dbConnect.runSqlQuery("select t3.topitemclassid,t1.siteid,sum(ifnull(t1.amount,0)) sumamount from sa_orderitems t1 inner join sa_itemsaleclass t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid inner join (select itemclassid,find_top(itemclassid) topitemclassid,siteid from plm_itemclass where siteid!='ZZYOS') t3 on t2.itemclassid=t3.itemclassid and t2.siteid=t3.siteid where t1.sa_orderid="+sa_orderid+" group by t3.topitemclassid,t1.siteid");
|
|
|
+ for (Row classamountrow:classamountrows) {
|
|
|
+ orderSumamount=orderSumamount.add(classamountrow.getBigDecimal("sumamount"));
|
|
|
+ }
|
|
|
+ if(orderSumamount.compareTo(getAmount(this,sa_orderid))!=0){
|
|
|
+ return;
|
|
|
+ }
|
|
|
+
|
|
|
+ RowsMap classamountrowsMap =classamountrows.toRowsMap("topitemclassid");
|
|
|
+ Rows accountclassrows =dbConnect.runSqlQuery("select t1.*,ifnull(t2.balance,0) balance,ifnull(t2.creditquota,0) creditquota from sa_accountclass t1 left join sa_accountbalance t2 on t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid and t2.sys_enterpriseid="+orderRows.get(0).getLong("pay_enterpriseid")+" where isused=1 and t1.siteid='"+siteid+"'");
|
|
|
+ BigDecimal firstpayamount = BigDecimal.ZERO;
|
|
|
+
|
|
|
+
|
|
|
+ if(!accountclassrows.isEmpty()){
|
|
|
+ for (Row row:accountclassrows) {
|
|
|
+ BigDecimal sumamount =BigDecimal.ZERO;
|
|
|
+ JSONObject jsonObject =new JSONObject();
|
|
|
+ if(row.getJSONArray("bindingcategories")!=null && !row.getJSONArray("bindingcategories").isEmpty()){
|
|
|
+ for (Object object:row.getJSONArray("bindingcategories")) {
|
|
|
+ Long topitemclassid = Long.valueOf(object.toString());
|
|
|
+ if(classamountrowsMap.containsKey(object.toString())){
|
|
|
+ if(classamountrowsMap.get(object.toString()).isNotEmpty()){
|
|
|
+ sumamount=sumamount.add(classamountrowsMap.get(object.toString()).get(0).getBigDecimal("sumamount").multiply(row.getBigDecimal("maximumdiscount")).setScale(2, BigDecimal.ROUND_HALF_UP));
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(sumamount.compareTo(BigDecimal.ZERO)>0){
|
|
|
+ if((row.getBigDecimal("balance").add(row.getBigDecimal("creditquota"))).compareTo(BigDecimal.ZERO)<=0){
|
|
|
+ continue;
|
|
|
+ }else if((row.getBigDecimal("balance").add(row.getBigDecimal("creditquota"))).compareTo(sumamount)<0){
|
|
|
+ //部分优先账户扣款,部分现金扣款
|
|
|
+ jsonObject.put("amount",row.getBigDecimal("balance").add(row.getBigDecimal("creditquota")));
|
|
|
+ jsonObject.put("sa_accountclassid",row.getLong("sa_accountclassid"));
|
|
|
+ jsonObject.put("accountname",row.getString("accountname"));
|
|
|
+ jsonObject.put("balance",row.getBigDecimal("balance"));
|
|
|
+ jsonObject.put("creditquota",row.getBigDecimal("creditquota"));
|
|
|
+ jsonArray.add(jsonObject);
|
|
|
+ firstpayamount=firstpayamount.add(row.getBigDecimal("balance").add(row.getBigDecimal("creditquota")));
|
|
|
+
|
|
|
+ }else if((row.getBigDecimal("balance").add(row.getBigDecimal("creditquota"))).compareTo(sumamount)>=0){
|
|
|
+ //全部优先账户扣款
|
|
|
+ jsonObject.put("amount",sumamount);
|
|
|
+ jsonObject.put("sa_accountclassid",row.getLong("sa_accountclassid"));
|
|
|
+ jsonObject.put("accountname",row.getString("accountname"));
|
|
|
+ jsonObject.put("balance",row.getBigDecimal("balance"));
|
|
|
+ jsonObject.put("creditquota",row.getBigDecimal("creditquota"));
|
|
|
+ jsonArray.add(jsonObject);
|
|
|
+ firstpayamount=firstpayamount.add(sumamount);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ if(getAmount(this,sa_orderid).compareTo(BigDecimal.ZERO)==0){
|
|
|
+ Rows xianjinaccountclassrows =dbConnect.runSqlQuery("select t1.*,ifnull(t2.balance,0) balance,ifnull(t2.creditquota,0) creditquota from sa_accountclass t1 left join sa_accountbalance t2 on t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid and t2.sys_enterpriseid="+orderRows.get(0).getLong("pay_enterpriseid")+" where isorder=1 and isused=1 and t1.sa_accountclassid="+(sa_accountclassid==0?orderRows.get(0).getLong("sa_accountclassid"):sa_accountclassid)+" and t1.siteid='"+siteid+"'");
|
|
|
+ if(xianjinaccountclassrows.isNotEmpty()){
|
|
|
+ JSONObject jsonObject =new JSONObject();
|
|
|
+ jsonObject.put("amount", BigDecimal.ZERO);
|
|
|
+ jsonObject.put("sa_accountclassid",xianjinaccountclassrows.get(0).getLong("sa_accountclassid"));
|
|
|
+ jsonObject.put("accountname",xianjinaccountclassrows.get(0).getString("accountname"));
|
|
|
+ jsonObject.put("balance",xianjinaccountclassrows.get(0).getBigDecimal("balance"));
|
|
|
+ jsonObject.put("creditquota",xianjinaccountclassrows.get(0).getBigDecimal("creditquota"));
|
|
|
+ jsonArray.add(jsonObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if(orderSumamount.compareTo(firstpayamount)>0){
|
|
|
+ Rows xianjinaccountclassrows =dbConnect.runSqlQuery("select t1.*,ifnull(t2.balance,0) balance,ifnull(t2.creditquota,0) creditquota from sa_accountclass t1 left join sa_accountbalance t2 on t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid and t2.sys_enterpriseid="+orderRows.get(0).getLong("pay_enterpriseid")+" where isorder=1 and isused=1 and t1.sa_accountclassid="+(sa_accountclassid==0?orderRows.get(0).getLong("sa_accountclassid"):sa_accountclassid)+" and t1.siteid='"+siteid+"'");
|
|
|
+ if(xianjinaccountclassrows.isNotEmpty()){
|
|
|
+ JSONObject jsonObject =new JSONObject();
|
|
|
+ jsonObject.put("amount", orderSumamount.subtract(firstpayamount));
|
|
|
+ jsonObject.put("sa_accountclassid",xianjinaccountclassrows.get(0).getLong("sa_accountclassid"));
|
|
|
+ jsonObject.put("accountname",xianjinaccountclassrows.get(0).getString("accountname"));
|
|
|
+ jsonObject.put("balance",xianjinaccountclassrows.get(0).getBigDecimal("balance"));
|
|
|
+ jsonObject.put("creditquota",xianjinaccountclassrows.get(0).getBigDecimal("creditquota"));
|
|
|
+ jsonArray.add(jsonObject);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ dbConnect.runSqlUpdate("update sa_order set sa_accountclassinfos='"+jsonArray+"' where sa_orderid="+sa_orderid+" and siteid='"+siteid+"'");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
// @API(title = "发货单手动关闭", apiversion = R.ID20230406155302.v1.class)
|
|
|
// @Deprecated
|
|
|
// public String closeDispatch() throws YosException {
|