فهرست منبع

发货单,返退单,促销方案逻辑变更

hu 3 سال پیش
والد
کامیت
8a6885f531

+ 48 - 72
src/custom/restcontroller/webmanage/sale/aftersalesmag/aftersalesmag.java

@@ -369,7 +369,7 @@ public class aftersalesmag extends Controller {
         Long sa_aftersalesmagid = content.getLong("sa_aftersalesmagid");
         Long sa_orderid = 0L;
         Rows rows = dbConnect.runSqlQuery(
-                "select t1.sa_aftersalesmagid,t1.status,t1.billno,t1.sa_orderid,t1.returnamount,t1.payamount,t1.sys_enterpriseid,t1.sa_accountclassid,t2.sonum,t1.type from sa_aftersalesmag t1 left join sa_order t2 on t1.sa_orderid=t2.sa_orderid and t1.siteid=t2.siteid  where t1.sa_aftersalesmagid ='"
+                "select t1.sa_aftersalesmagid,t1.status,t1.billno,ifnull(t1.sa_orderid,0) sa_orderid ,t1.returnamount,t1.payamount,t1.sys_enterpriseid,t1.sa_accountclassid,t2.sonum,t1.type from sa_aftersalesmag t1 left join sa_order t2 on t1.sa_orderid=t2.sa_orderid and t1.siteid=t2.siteid  where t1.sa_aftersalesmagid ='"
                         + sa_aftersalesmagid + "' and  t1.siteid='" + siteid + "'");
         if (rows.isEmpty()) {
             return getErrReturnObject().setErrMsg("该返退单不存在").toString();
@@ -382,77 +382,53 @@ public class aftersalesmag extends Controller {
         }
 
         ArrayList<String> sqlList = new ArrayList<>();
-        if (rows.get(0).getString("type").equals("借用归还单")) {
-            if (rows.get(0).getDouble("returnamount") != 0) {
-                /******** 生成负数收入凭证 ********/
-                BigDecimal returnamount = rows.get(0).getBigDecimal("returnamount").negate();
-                CashbillEntity cashbillEntity = new CashbillEntity();
-                cashbillEntity.setAmount(returnamount);
-                cashbillEntity.setOwnerid(sa_aftersalesmagid);
-                cashbillEntity.setOwnertable("sa_aftersalesmag");
-                cashbillEntity.setRemarks("借用归还单号:" + rows.get(0).getString("billno") + ";借出单号:" + rows.get(0).getString("sonum"));
-                cashbillEntity.setSource("借用归还单复核");
-
-                sqlList.addAll(Accountbalance.createCashbillIncome(this, rows.get(0).getLong("sys_enterpriseid"), rows.get(0).getLong("sa_accountclassid"), cashbillEntity, true));
-
-
-            }
-            if (rows.get(0).getDouble("payamount") != 0) {
-                /******** 生成支出凭证 ********/
-                BigDecimal payamount = rows.get(0).getBigDecimal("payamount");
-                CashbillEntity cashbillEntity = new CashbillEntity();
-                cashbillEntity.setAmount(payamount);
-                cashbillEntity.setOwnerid(sa_aftersalesmagid);
-                cashbillEntity.setOwnertable("sa_aftersalesmag");
-                cashbillEntity.setRemarks("借用归还单号:" + rows.get(0).getString("billno") + ";借出单号:" + rows.get(0).getString("sonum"));
-                cashbillEntity.setSource("借用归还单复核");
-                sqlList.addAll(Accountbalance.createCashbillPay(this, rows.get(0).getLong("sys_enterpriseid"), rows.get(0).getLong("sa_accountclassid"), cashbillEntity, true));
-            }
-
-        } else {
-            if (rows.get(0).getDouble("returnamount") != 0) {
-                /******** 生成支出凭证 ********/
-                BigDecimal returnamount = rows.get(0).getBigDecimal("returnamount").negate();
-                CashbillEntity cashbillEntity = new CashbillEntity();
-                cashbillEntity.setAmount(returnamount);
-                cashbillEntity.setOwnerid(sa_aftersalesmagid);
-                cashbillEntity.setOwnertable("sa_aftersalesmag");
-                cashbillEntity.setRemarks("退货单号:" + rows.get(0).getString("billno") + ";订单号:" + rows.get(0).getString("sonum"));
-                cashbillEntity.setSource("返退单复核");
-
-                sqlList.addAll(Accountbalance.createCashbillPay(this, rows.get(0).getLong("sys_enterpriseid"), rows.get(0).getLong("sa_accountclassid"), cashbillEntity, true));
-            }
-
-            /**
-             * * 核销对冲计算
-             */
-            {
-                HashMap<Long, Row> orderdetailmap = new HashMap<>();
-                HashMap<Long, BigDecimal> orderdetailchangeamount = new HashMap<>();
-                Rows rowsOrder = dbConnect.runSqlQuery("select * from sa_order t1 where t1.sa_orderid=" + sa_orderid);
-                Rows rowsOrderDetail = dbConnect.runSqlQuery("select t1.undeliqty,t1.deliedqty,t1.qty,t1.price,t1.returnqty,t1.amount,t1.sa_orderitemsid,t1.writeoffamount from sa_orderitems t1 where t1.sa_orderid=" + sa_orderid);
-                RowsMap rowsMap = rowsOrderDetail.toRowsMap("sa_orderitemsid");
-                Rows sa_aftersalesmag_itemsRows = dbConnect.runSqlQuery("select t1.qty,t1.sa_orderitemsid,t2.itemno,t2.itemname from sa_aftersalesmag_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid  where t1.sa_aftersalesmagid=" + sa_aftersalesmagid);
-                for (Row row : sa_aftersalesmag_itemsRows) {
-                    Rows orderitemsRows = rowsMap.get(row.getString("sa_orderitemsid"));
-                    BigDecimal price = orderitemsRows.get(0).getBigDecimal("price");
-                    BigDecimal qty = row.getBigDecimal("qty");
-                    BigDecimal returnamount_detail = qty.multiply(price);//退货金额
-                    BigDecimal writeoffamount = orderitemsRows.get(0).getBigDecimal("writeoffamount");//订单行已核销金额
-                    if (writeoffamount.compareTo(BigDecimal.ZERO) > 0 && (orderitemsRows.get(0).getBigDecimal("amount").subtract(returnamount_detail)).compareTo(writeoffamount) < 0) {
-                        //如果已核销金额大于0 且调整后折后金额小于已核销金额,则需要将差价进行回冲
-                        orderdetailmap.put(orderitemsRows.get(0).getLong("sa_orderitemsid"), orderitemsRows.get(0));
-                        orderdetailchangeamount.put(orderitemsRows.get(0).getLong("sa_orderitemsid"), writeoffamount.subtract(orderitemsRows.get(0).getBigDecimal("amount").subtract(returnamount_detail)));
-                    }
-                }
-
-                /**
-                 * * 核销对冲
-                 */
-                if (!orderdetailmap.isEmpty()) {
-                    sqlList.addAll(new twriteoffbill_orderchange(rowsOrder.get(0), orderdetailmap, orderdetailchangeamount).hedging());
-                }
-            }
+       if(rows.get(0).getString("type").equals("退货单")) {
+           if( rows.get(0).getLong("sa_orderid") !=0){
+               if (rows.get(0).getDouble("returnamount") != 0) {
+                   /******** 生成支出凭证 ********/
+                   BigDecimal returnamount = rows.get(0).getBigDecimal("returnamount").negate();
+                   CashbillEntity cashbillEntity = new CashbillEntity();
+                   cashbillEntity.setAmount(returnamount);
+                   cashbillEntity.setOwnerid(sa_aftersalesmagid);
+                   cashbillEntity.setOwnertable("sa_aftersalesmag");
+                   cashbillEntity.setRemarks("退货单号:" + rows.get(0).getString("billno") + ";订单号:" + rows.get(0).getString("sonum"));
+                   cashbillEntity.setSource("退货单复核");
+
+                   sqlList.addAll(Accountbalance.createCashbillPay(this, rows.get(0).getLong("sys_enterpriseid"), rows.get(0).getLong("sa_accountclassid"), cashbillEntity, true));
+               }
+           }
+
+
+//            /**
+//             * * 核销对冲计算
+//             */
+//            {
+//                HashMap<Long, Row> orderdetailmap = new HashMap<>();
+//                HashMap<Long, BigDecimal> orderdetailchangeamount = new HashMap<>();
+//                Rows rowsOrder = dbConnect.runSqlQuery("select * from sa_order t1 where t1.sa_orderid=" + sa_orderid);
+//                Rows rowsOrderDetail = dbConnect.runSqlQuery("select t1.undeliqty,t1.deliedqty,t1.qty,t1.price,t1.returnqty,t1.amount,t1.sa_orderitemsid,t1.writeoffamount from sa_orderitems t1 where t1.sa_orderid=" + sa_orderid);
+//                RowsMap rowsMap = rowsOrderDetail.toRowsMap("sa_orderitemsid");
+//                Rows sa_aftersalesmag_itemsRows = dbConnect.runSqlQuery("select t1.qty,t1.sa_orderitemsid,t2.itemno,t2.itemname from sa_aftersalesmag_items t1 left join plm_item t2 on t1.itemid=t2.itemid and t1.siteid=t2.siteid  where t1.sa_aftersalesmagid=" + sa_aftersalesmagid);
+//                for (Row row : sa_aftersalesmag_itemsRows) {
+//                    Rows orderitemsRows = rowsMap.get(row.getString("sa_orderitemsid"));
+//                    BigDecimal price = orderitemsRows.get(0).getBigDecimal("price");
+//                    BigDecimal qty = row.getBigDecimal("qty");
+//                    BigDecimal returnamount_detail = qty.multiply(price);//退货金额
+//                    BigDecimal writeoffamount = orderitemsRows.get(0).getBigDecimal("writeoffamount");//订单行已核销金额
+//                    if (writeoffamount.compareTo(BigDecimal.ZERO) > 0 && (orderitemsRows.get(0).getBigDecimal("amount").subtract(returnamount_detail)).compareTo(writeoffamount) < 0) {
+//                        //如果已核销金额大于0 且调整后折后金额小于已核销金额,则需要将差价进行回冲
+//                        orderdetailmap.put(orderitemsRows.get(0).getLong("sa_orderitemsid"), orderitemsRows.get(0));
+//                        orderdetailchangeamount.put(orderitemsRows.get(0).getLong("sa_orderitemsid"), writeoffamount.subtract(orderitemsRows.get(0).getBigDecimal("amount").subtract(returnamount_detail)));
+//                    }
+//                }
+//
+//                /**
+//                 * * 核销对冲
+//                 */
+//                if (!orderdetailmap.isEmpty()) {
+//                    sqlList.addAll(new twriteoffbill_orderchange(rowsOrder.get(0), orderdetailmap, orderdetailchangeamount).hedging());
+//                }
+//            }
         }
 
 

+ 3 - 1
src/custom/restcontroller/webmanage/sale/dispatch/SQL/发货商品列表查询.sql

@@ -11,7 +11,9 @@ SELECT t1.sa_orderitemsid,
        t1.rowno
 FROM sa_orderitems t1
          inner join plm_item t2 on t1.siteid = t2.siteid and t1.itemid = t2.itemid
-WHERE t1.sa_orderid = $sa_orderid$
+         inner join sa_order t3 on t1.siteid=t3.siteid and t1.sa_orderid=t3.sa_orderid
+WHERE t3.STATUS = '审核'
   and ifnull(t1.undeliqty, 0) !=0
 	AND t1.siteid = $siteid$
+	and t3.sys_enterpriseid=$sys_enterpriseid$
 	AND ifnull( t1.isclose, 0 )= 0

+ 1 - 1
src/custom/restcontroller/webmanage/sale/dispatch/dispatchItems.java

@@ -79,7 +79,7 @@ public class dispatchItems extends Controller {
         }
         SQLFactory sqlFactory = new SQLFactory(this, "发货商品列表查询", pageSize, pageNumber, pageSorting);
         sqlFactory.addParameter_SQL("where", where);
-        sqlFactory.addParameter("sa_orderid", sa_orderid);
+        sqlFactory.addParameter("sys_enterpriseid", content.getLongValue("sys_enterpriseid"));
         sqlFactory.addParameter("siteid", siteid);
         Rows rows = dbConnect.runSqlQuery(sqlFactory);
 

+ 1 - 0
src/custom/restcontroller/webmanage/sale/order/SQL/订单_详情.sql

@@ -41,6 +41,7 @@ SELECT t1.sa_orderid,
        t1.tradefieldmx,
        t1.reviewtype,
        (SELECT promname from sa_promotion WHERE sa_promotionid = t1.sa_promotionid and siteid = t1.siteid) promname,
+       (SELECT promnum from sa_promotion WHERE sa_promotionid = t1.sa_promotionid and siteid = t1.siteid) promnum,
        t9.subvalues,
        t5.freefreightamount,
        t1.rebateamount,