Stringsql="select distinct a.* from tSalesOrder a left join tSalesOrderSub b on a.sSalesOrderID = b.sSalesOrderID where a.sShopNO = '"+shopNo+"' and a.sOrgNO = '"+orgNo+"'";
Stringsql4="select sosd.*,PromoSalePrice=CONVERT(NUMERIC(12,2),case when sosd.nSaleQty = 0 then 0 else ROUND((sosd.nSaleAmount)/sosd.nSaleQty,2) end),OriginaSaleAmount=sosd.nSaleAmount+sosd.nDisAmount,ISGift = sosd.nTag&1,"
+" agp.sURL from tSalesOrderSubDtl sosd left join V_GetminAgentGoodsPic agp on agp.nAgentID = sosd.nAgentID and agp.nGoodsID = sosd.nGoodsID and agp.sPicTypeID = 1"
+" where sosd.sSubOrderID in ("+StringUtil.join("', '","'","'",subIds)+")";
Stringsql4="select sosd.*,PromoSalePrice=CONVERT(NUMERIC(12,2),case when sosd.nSaleQty = 0 then 0 else ROUND((sosd.nSaleAmount)/sosd.nSaleQty,2) end),OriginaSaleAmount=sosd.nSaleAmount+sosd.nDisAmount,ISGift = sosd.nTag&1,"
+" agp.sURL from tSalesOrderSubDtl sosd left join V_GetminAgentGoodsPic agp on agp.nAgentID = sosd.nAgentID and agp.nGoodsID = sosd.nGoodsID and agp.sPicTypeID = 1"
+" where sosd.sSubOrderID in ("+StringUtil.join("', '","'","'",subIds)+")";
+" from tSalesOrderSubDtl sosd left join tYWPromoMain pm on pm.sPromoPaperNO = sosd.sPromoPaperNO left join V_GetminAgentGoodsPic agp on agp.nAgentID = sosd.nAgentID and agp.nGoodsID = sosd.nGoodsID and agp.sPicTypeID = 1"
+" where sosd.sSubOrderID in ("+StringUtil.join("', '","'","'",subIds)+")";
+" IsRefund = case when isnull(sos.sBindPaperNO,'') = '' then 1 when sos.nOrderStatus&17=0 then 0 when datediff(dd,dateadd(dd,1,convert(date,sos.dReceiveDate)),getdate()) >= ? then 0 else 1 end, "
+"case when sos.nOrderStatus&145 = 144 then '16' when sos.nOrderStatus&145 = 128 then '8' when sos.nOrderStatus&145 = 0 then '4' when sos.nOrderStatus&5 = 4 then '2' else '0' end nOrderStatus, "
+"case when sos.nOrderStatus&145 = 144 then '已完成' when sos.nOrderStatus&145 = 128 then '配送中' when sos.nOrderStatus&145 = 0 then '待发货' when sos.nOrderStatus&5 = 4 then '已审核' else '未审核' end sOrderStatusText "
+"from tSalesOrderSub sos left join (select sSubOrderID, nSendQty = sum(nSendQty), nReturnQty = sum(nReturnQty) from tSalesOrderSubDtl where sSubOrderID = ? group by sSubOrderID) d on sos.sSubOrderID = d.sSubOrderID "
+" where sos.sSubOrderID = ?",ReturnDay,subOrderID,subOrderID);
+"case when so.nOrderStatus&145 = 144 then '16' when so.nOrderStatus&145 = 128 then '8' when so.nOrderStatus&145 = 0 then '4' when so.nOrderStatus&5 = 4 then '2' else '0' end nOrderStatus, "
+"case when so.nOrderStatus&145 = 144 then '已完成' when so.nOrderStatus&145 = 128 then '配送中' when so.nOrderStatus&145 = 0 then '待发货' when so.nOrderStatus&5 = 4 then '已审核' else '未审核' end sOrderStatusText "
+"from tSalesOrder so where so.sSalesOrderID = ?",subOrderMap.get("sSalesOrderID"));
Map<String,Object>deliver=jdbcTemplate.queryForMap("SELECT sum(a.nNum) nTotalCount, sum(a.nPrice * a.nNum) nTotalAmount FROM tSalesOrderDeliverSubDtl a where a.sSubOrderID = ?",subOrderID);
StringstockSql="select og.sWarehouseNO, og.sAgentContractNO, og.nGoodsID, og.nStockQty, og.nLockedQty from tPromoRuleGoods prg, V_OrgGoods og where prg.sAgentContractNO = og.sAgentContractNO and prg.nGoodsID = og.nGoodsID and og.sOrgNO = ? and prg.sPromoPaperNO = ? and prg.sPromoGroupNO = ?";
Map<String,Object>custMap=jdbcTemplate.queryForMap("select c.* from tCustomer c, tShop s where c.sCustNO = s.sCustNO and s.sShopNO = ? and s.sOrgNO = ?",shopNo,orgNo);
@@ -541,9 +506,11 @@ public class OrderServiceImpl implements OrderService {
nTotalSaleQty=nTotalSaleQty.add(nTotalMeetQty);
gMap.put("WarehouseNO",sWarehouseNO);
}
jdbcTemplate.batchUpdate("update tAgentStockOnline set nLockedQty = (nLockedQty + ?) where sAgentContractNO = ? and nGoodsID = ? and sWarehouseNO = ?",batchArgs);
Map<String,Object>planSum=jdbcTemplate.queryForMap("select sum(nTotalSaleQty) nOrderQty, sum(nTotalSaleAmount) nOrderAmount from tSalesOrder where nPlanID = ? and nOrderStatus&1 = 0",planId);
@@ -777,23 +730,26 @@ public class OrderServiceImpl implements OrderService {
dtl.setsSalesOrderID(sSalesOrderID);
dtl.setsWarehouseNO(sWarehouseNO);
jdbcTemplate.save(dtl);
{
LongnProjectID=jdbcTemplate.queryForLong("select nProjectID from tZHCPlan where nPlanID = ?",planId);
Stringsql="select count(so.sSalesOrderID) nSalePaperQty, isnull(sum(so.nTotalSaleQty), 0) nSaleQty, isnull(sum(so.nTotalSaleAmount), 0) nSaleAmount from tSalesOrder so, tZHCPlan p where so.sB2BOrderTypeID = '3' and so.nTag&1 = 0 and so.nPlanID = p.nPlanID and p.nProjectID = ?";
StringgSql="select t.*, ap.nRealSalePrice nApSalePrice from V_OrgGoods t left join tAgentCustTypePrice ap on ap.sCustTypeID = ? and ap.sAgentContractNO = t.sAgentContractNO and ap.nGoodsID = t.nGoodsID where t.sOrgNO = ? and t.sAgentContractNO = ? and t.nGoodsID = ?";
+"SELECT @OrderStatus = nOrderStatus FROM tSalesOrderSub WHERE sSubOrderID = @SubOrderID "
+"IF @OrderStatus&@TargetStatus = 0 "
+"BEGIN "
+"SELECT @SalesOrderID = sSalesOrderID FROM tSalesOrderSub WHERE sSubOrderID = @SubOrderID "
+"UPDATE tSalesOrderSub SET nOrderStatus = nOrderStatus|@TargetStatus, nOrderStatusName = @OrderStatusName, dLastUpdateTime = GETDATE() WHERE sSubOrderID = @SubOrderID "
+"UPDATE tSalesOrderSubDtl SET nReceiveQty = td.nSendQty, nReceiveAmount = td.nSendAmount, dLastUpdateTime = GETDATE() FROM tSalesOrderSub t, tSalesOrderSubDtl td WHERE t.sSubOrderID = td.sSubOrderID AND t.sSubOrderID = @SubOrderID AND td.nReceiveQty IS NULL "
+"DECLARE @Idx INT "
+"SELECT @Idx = ISNULL(MAX(nIdx), 0) + 1 FROM tSalesOrderSubStatus WHERE sSubOrderID = @SubOrderID "
+"SELECT @SalesOrderID = sSalesOrderID FROM tSalesOrderSub WHERE sSubOrderID = @SubOrderID "
+"UPDATE tSalesOrderSub SET nOrderStatus = nOrderStatus|@TargetStatus, nOrderStatusName = @OrderStatusName, dLastUpdateTime = GETDATE() WHERE sSubOrderID = @SubOrderID "
+"UPDATE tSalesOrderSubDtl SET nReceiveQty = td.nSendQty, nReceiveAmount = td.nSendAmount, dLastUpdateTime = GETDATE() FROM tSalesOrderSub t, tSalesOrderSubDtl td WHERE t.sSubOrderID = td.sSubOrderID AND t.sSubOrderID = @SubOrderID AND td.nReceiveQty IS NULL "
+"DECLARE @Idx INT "
+"SELECT @Idx = ISNULL(MAX(nIdx), 0) + 1 FROM tSalesOrderSubStatus WHERE sSubOrderID = @SubOrderID "