hu 4 mesi fa
parent
commit
b7d0ace81f

+ 11 - 2
src/custom/restcontroller/webmanage/sale/order/OrderItems.java

@@ -80,6 +80,7 @@ public class OrderItems extends Controller {
             JSONObject item = (JSONObject) obj;
             Long itemid = item.getLong("itemid");
             Long sa_orderitemsid = item.getLong("sa_orderitemsid");
+            long sa_customersid =item.getLongValue("sa_customersid");
             BigDecimal qty = item.getBigDecimal("qty");
             sumqty = sumqty.add(qty);
 
@@ -113,7 +114,14 @@ public class OrderItems extends Controller {
                 }
 
                 spec = orderItemsHelper.getCustomSpec(itemRowsMap, item);
-                Rows rows = dbConnect.runSqlQuery("SELECT sa_orderitemsid,price from sa_orderitems WHERE siteid='" + siteid + "' and itemid=" + itemid + " and sa_orderid=" + sa_orderid + " and sa_promotion_itemsid=" + item.getLongValue("sa_promotion_itemsid"));
+                Rows rows = new Rows();
+                if(!type.equals("配件订单")){
+                    rows= dbConnect.runSqlQuery("SELECT sa_orderitemsid,price from sa_orderitems WHERE siteid='" + siteid + "' and itemid=" + itemid + " and sa_orderid=" + sa_orderid + " and sa_promotion_itemsid=" + item.getLongValue("sa_promotion_itemsid"));
+                }else{
+                    if(sa_customersid!=0){
+                        rows= dbConnect.runSqlQuery("SELECT t1.sa_orderitemsid,qty from sa_orderitems t1 left join sa_warrantycard t2 on t1.cardno=t2.cardno  WHERE t1.siteid='" + siteid + "' and t1.itemid=" + itemid + " and t1.sa_orderid=" + sa_orderid + " and t2.sa_customersid=" +sa_customersid);
+                    }
+                }
 
                 if (rows.isEmpty()) {
                     sa_orderitemsid = createTableID("sa_orderitems");
@@ -123,8 +131,9 @@ public class OrderItems extends Controller {
                         sa_orderitemsid = createTableID("sa_orderitems");
                         isInsert = true;
                     } else {
-                        price1 = rows.get(0).getBigDecimal("price");
+                        //price1 = rows.get(0).getBigDecimal("price");
                         sa_orderitemsid = rows.get(0).getLong("sa_orderitemsid");
+                        item.put("qty",item.getBigDecimal("qty").add(rows.get(0).getBigDecimal("qty")));
                         isInsert = false;
                     }
 

+ 39 - 10
src/custom/restcontroller/webmanage/sale/stockbill/stockbillitems.java

@@ -278,14 +278,30 @@ public class stockbillitems extends Controller {
         }
 
         dbConnect.runSqlUpdate(sqlList);
+
+
         Rows rowsdetail = dbConnect.runSqlQuery("select amount,qty from st_stockbill_items where st_stockbillid=" + st_stockbillid);
-        Rows stockbillrows= dbConnect.runSqlQuery("select paydiscountamount from st_stockbill where st_stockbillid=" + st_stockbillid);
-        if(stockbillrows.isNotEmpty()){
-            if(stockbillrows.get(0).getBigDecimal("paydiscountamount").compareTo(rowsdetail.sum("amount"))>0){
-                dbConnect.runSqlUpdate("update st_stockbill set paydiscountamount="+rowsdetail.sum("amount")+",payamount=0 where st_stockbillid="+st_stockbillid);
+        Rows stockbillrows= dbConnect.runSqlQuery("select t1.sys_enterpriseid,t1.paydiscountamount,t2.depname from st_stockbill t1 left join sys_department t2 on t1.departmentid=t2.departmentid where t1.st_stockbillid=" + st_stockbillid);
+        Rows accountbalancerows = dbConnect.runSqlQuery("select * from  sa_accountbalance t1 inner join sa_accountclass t2 on  t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t2.accountname='现金账户' and t1.sys_enterpriseid=" + stockbillrows.get(0).getLong("sys_enterpriseid"));
+        String depname= stockbillrows.get(0).getString("depname");
+        BigDecimal payamount=rowsdetail.sum("amount");
+        if(depname.equals("售后部")){
+            if(accountbalancerows.isNotEmpty()){
+                if(accountbalancerows.get(0).getBigDecimal("discountamount").compareTo(BigDecimal.ZERO)>0){
+                    if(accountbalancerows.get(0).getBigDecimal("discountamount").compareTo(payamount)>0){
+                        dbConnect.runSqlUpdate("update st_stockbill set payamount=0,paydiscountamount="+payamount+" where st_stockbillid="+st_stockbillid);
+                    }else{
+                        dbConnect.runSqlUpdate("update st_stockbill set payamount="+payamount.subtract(accountbalancerows.get(0).getBigDecimal("discountamount"))+",paydiscountamount="+accountbalancerows.get(0).getBigDecimal("discountamount")+" where st_stockbillid="+st_stockbillid);
+                    }
+                }else{
+                    dbConnect.runSqlUpdate("update st_stockbill set payamount="+payamount+",paydiscountamount=0 where st_stockbillid="+st_stockbillid);
+                }
+
             }else{
-                dbConnect.runSqlUpdate("update st_stockbill set payamount="+rowsdetail.sum("amount")+"-paydiscountamount where st_stockbillid="+st_stockbillid);
+                dbConnect.runSqlUpdate("update st_stockbill set payamount="+payamount+",paydiscountamount=0 where st_stockbillid="+st_stockbillid);
             }
+        }else{
+            dbConnect.runSqlUpdate("update st_stockbill set payamount="+payamount+",paydiscountamount=0 where st_stockbillid="+st_stockbillid);
         }
         return querStcokbillItemsList();
     }
@@ -378,14 +394,27 @@ public class stockbillitems extends Controller {
         updateRowNo(st_stockbillid);
 
         Rows rowsdetail = dbConnect.runSqlQuery("select amount,qty from st_stockbill_items where st_stockbillid=" + st_stockbillid);
-        Rows stockbillrows= dbConnect.runSqlQuery("select paydiscountamount from st_stockbill where st_stockbillid=" + st_stockbillid);
+        Rows stockbillrows= dbConnect.runSqlQuery("select t1.sys_enterpriseid,t1.paydiscountamount,t2.depname from st_stockbill t1 left join sys_department t2 on t1.departmentid=t2.departmentid where t1.st_stockbillid=" + st_stockbillid);
+        Rows accountbalancerows = dbConnect.runSqlQuery("select * from sa_accountbalance t1 inner join sa_accountclass t2 on t1.sa_accountclassid=t2.sa_accountclassid and t1.siteid=t2.siteid where t2.accountname='现金账户' and t1.sys_enterpriseid=" + stockbillrows.get(0).getLong("sys_enterpriseid"));
+        String depname= stockbillrows.get(0).getString("depname");
+        BigDecimal payamount=rowsdetail.sum("amount");
+        if(depname.equals("售后部")){
+            if(accountbalancerows.isNotEmpty()){
+                if(accountbalancerows.get(0).getBigDecimal("discountamount").compareTo(BigDecimal.ZERO)>0){
+                    if(accountbalancerows.get(0).getBigDecimal("discountamount").compareTo(payamount)>0){
+                        dbConnect.runSqlUpdate("update st_stockbill set payamount=0,paydiscountamount="+payamount+" where st_stockbillid="+st_stockbillid);
+                    }else{
+                        dbConnect.runSqlUpdate("update st_stockbill set payamount="+payamount.subtract(accountbalancerows.get(0).getBigDecimal("discountamount"))+",paydiscountamount="+accountbalancerows.get(0).getBigDecimal("discountamount")+" where st_stockbillid="+st_stockbillid);
+                    }
+                }else{
+                    dbConnect.runSqlUpdate("update st_stockbill set payamount="+payamount+",paydiscountamount=0 where st_stockbillid="+st_stockbillid);
+                }
 
-        if(stockbillrows.isNotEmpty()){
-            if(stockbillrows.get(0).getBigDecimal("paydiscountamount").compareTo(rowsdetail.sum("amount"))>0){
-                dbConnect.runSqlUpdate("update st_stockbill set paydiscountamount="+rowsdetail.sum("amount")+",payamount=0 where st_stockbillid="+st_stockbillid);
             }else{
-                dbConnect.runSqlUpdate("update st_stockbill set payamount="+rowsdetail.sum("amount")+"-paydiscountamount where st_stockbillid="+st_stockbillid);
+                dbConnect.runSqlUpdate("update st_stockbill set payamount="+payamount+",paydiscountamount=0 where st_stockbillid="+st_stockbillid);
             }
+        }else{
+            dbConnect.runSqlUpdate("update st_stockbill set payamount="+payamount+",paydiscountamount=0 where st_stockbillid="+st_stockbillid);
         }
 
         return batchDeleteErr.getReturnObject().toString();

+ 4 - 1
src/custom/restcontroller/webmanage/sale/u8prodprice/u8prodprice.java

@@ -130,10 +130,13 @@ public class u8prodprice extends Controller {
 
         QuerySQL querySQL = SQLFactory.createQuerySQL(this, "sa_u8prodprice", "*");
         querySQL.setTableAlias("t1");
-
+        querySQL.addQueryFields("begindate","DATE(t1.begindate)");
+        querySQL.addQueryFields("enddate","DATE(t1.enddate)");
         querySQL.setSiteid(siteid);
+
         querySQL.setWhere(where.toString());
         querySQL.setPage(pageSize, pageNumber);
+        querySQL.setOrderBy("t1.sa_u8prodpriceid desc");
         Rows rows = querySQL.query();
 
         return getSucReturnObject().setData(rows).toString();