Beispiel #1
0
 public bool AuditSaleReturn(int id, bool isAudit, string operatorCode)
 {
     using (TransactionScope ts = new TransactionScope()) //开启DTC事务
     {
         TSaleReturn           tsale   = dao.GetSaleReturn(id);
         MMS_SaleReturnContent content = tsale.Content;
         if (content.AuditFlag == true) //??存在缓存
         {
             throw new Exception("该单据已经审核" + content.SaleBillCode);
         }
         foreach (TSaleReturnDetail tSaleDetail in tsale.Detail)
         {
             MMS_Store storeParam = new MMS_Store();
             storeParam.Warehouse   = content.WareHouse;
             storeParam.ProductCode = tSaleDetail.DetDetail.ProductCode;
             MMS_Store sto = null;
             sto = daoStore.GetStore(storeParam);
             if (sto == null) //库存中没有该商品
             {
                 sto             = new MMS_Store();
                 sto.Warehouse   = tsale.Content.WareHouse;
                 sto.ProductCode = tSaleDetail.DetDetail.ProductCode;
                 sto.Quantity    = tSaleDetail.DetDetail.Quantity;
                 sto.Price       = tSaleDetail.DetDetail.Price;
                 sto.Amount      = sto.Quantity * sto.Price;
                 sto.Memo        = "";
                 daoStore.InsertInfo(sto);
             }
             else
             {
                 sto.Quantity += tSaleDetail.DetDetail.Quantity;
                 sto.Amount   += tSaleDetail.DetDetail.Quantity * sto.Price; //* tSaleDetail.DetDetail.Price;
                 if (sto.Quantity > 0)
                 {
                     sto.Price = sto.Amount / sto.Quantity;
                 }
                 daoStore.UpdateInfo(sto);
             }
             //更新销售退回成本价
             MMS_SaleReturnDetail saleRetDet = tSaleDetail.DetDetail;
             saleRetDet.Cost = sto.Price;
             dao.UpdateSaleReturnDetail(saleRetDet);
         }
         content.AuditFlag   = isAudit;
         content.Operator    = operatorCode;
         content.OperateDate = DateTime.Now;
         dao.UpdateInfo(content);
         ts.Complete();
     }
     return(true);
 }
Beispiel #2
0
 /// <summary>
 ///   打印销售单
 /// </summary>
 /// <param name="id"> </param>
 /// <param name="isAudit"> </param>
 /// <param name="operatorCode"> </param>
 /// <returns> </returns>
 public bool AuditSale(int id, bool isAudit, string operatorCode)
 {
     using (TransactionScope ts = new TransactionScope()) //开启DTC事务
     {
         TSale           tsale   = dao.GetSale(id);       //取销售单组合实体
         MMS_SaleContent content = tsale.Content;         //取入销售主内容实体
         if (content.AuditFlag == true)                   //如果销售单已审核
         {
             throw new Exception("该单据已经审核" + content.SaleBillCode);
         }
         foreach (TSaleDetail tSaleDetail in tsale.Detail) //遍历销售单货品
         {
             MMS_Store storeParam = new MMS_Store();
             storeParam.Warehouse   = content.WareHouse;
             storeParam.ProductCode = tSaleDetail.DetDetail.ProductCode;
             MMS_Store sto = null;
             //根据仓库、货品代码取库存表中该货品信息
             sto = daoStore.GetStore(storeParam);
             if (sto == null) //库存中没有该商品
             {
                 throw new Exception("库存中没有该商品,不能销售" + tSaleDetail.DetDetail.ProductCode);
             }
             else
             {
                 if (tSaleDetail.DetDetail.Quantity > sto.Quantity) //如果销售数量大于库存数量
                 {
                     throw new Exception("库存数据不足,不能销售" + tSaleDetail.DetDetail.ProductCode);
                 }
                 sto.Quantity -= tSaleDetail.DetDetail.Quantity;             //销售冲减数量
                 sto.Amount   -= tSaleDetail.DetDetail.Quantity * sto.Price; //销售冲减金额
                 if (sto.Quantity > 0)
                 {
                     sto.Price = sto.Amount / sto.Quantity; //生新计算单价
                 }
                 daoStore.UpdateInfo(sto);                  //更新库存表
             }
             //更新成本价
             MMS_SaleDetail saleDet = tSaleDetail.DetDetail;
             saleDet.Cost = sto.Price;
             dao.UpdateSaleDetail(saleDet);
         }
         content.AuditFlag   = isAudit; //设销售单已审核
         content.Operator    = operatorCode;
         content.OperateDate = DateTime.Now;
         dao.UpdateInfo(content);
         ts.Complete(); //提交事务
     }
     return(true);
 }
 /// <summary>
 ///   入库单审核确认
 /// </summary>
 /// <param name="id"> </param>
 /// <param name="isAudit"> </param>
 /// <param name="operatorCode"> </param>
 /// <returns> </returns>
 public bool AuditPurchase(int id, bool isAudit, string operatorCode)
 {
     using (TransactionScope ts = new TransactionScope())   //开启DTC事务
     {
         TPurchase           tPur    = dao.GetPurchase(id); //取入库单组合实体
         MMS_PurchaseContent content = tPur.Content;        //取入库单主内容实体
         if (content.AuditFlag == true)                     //如果入库单已审核
         {
             throw new Exception("该单据已经审核" + content.PurchaseBillCode);
         }
         foreach (TPurchaseDetail tPurDetail in tPur.Detail) //遍历入库单货品
         {
             MMS_Store storeParam = new MMS_Store();
             storeParam.Warehouse   = tPur.Content.WareHouse;
             storeParam.ProductCode = tPurDetail.DetDetail.ProductCode;
             MMS_Store sto = null;
             //根据仓库、货品代码取库存表中该货品信息
             sto = daoStore.GetStore(storeParam);
             if (sto == null)                       //库存中没有该货品
             {
                 sto             = new MMS_Store(); //创建库存表实例
                 sto.Warehouse   = tPur.Content.WareHouse;
                 sto.ProductCode = tPurDetail.DetDetail.ProductCode;
                 sto.Quantity    = tPurDetail.DetDetail.Quantity;
                 sto.Price       = tPurDetail.DetDetail.Price;
                 sto.Amount      = sto.Quantity * sto.Price;
                 daoStore.InsertInfo(sto); //将该货品信息插入到库存表
                 sto.Memo = "";
             }
             else //库存中有该货品
             {
                 sto.Quantity += tPurDetail.DetDetail.Quantity; //累加货品数量
                 //累加计算货品金额
                 sto.Amount += tPurDetail.DetDetail.Quantity * tPurDetail.DetDetail.Price;
                 if (sto.Quantity > 0)
                 {
                     sto.Price = sto.Amount / sto.Quantity; //根据金额、数量计算单价
                 }
                 daoStore.UpdateInfo(sto);                  //更新库存表
             }
         }
         content.AuditFlag   = isAudit; //入库审核标志
         content.Operator    = operatorCode;
         content.OperateDate = DateTime.Now;
         dao.UpdateInfo(content); //更新入库单的审核标志
         ts.Complete();           //提交事务
     }
     return(true);
 }
Beispiel #4
0
 public bool AuditPurchaseReturn(int id, bool isAudit, string operatorCode)
 {
     using (TransactionScope ts = new TransactionScope()) //开启DTC事务
     {
         TPurchaseReturn           tPur    = dao.GetPurchaseReturn(id);
         MMS_PurchaseReturnContent content = tPur.Content;
         if (content.AuditFlag == true)
         {
             throw new Exception("该单据已经审核" + content.PurchaseBillCode);
         }
         foreach (TPurchaseReturnDetail tPurDetail in tPur.Detail)
         {
             MMS_Store storeParam = new MMS_Store();
             storeParam.Warehouse   = tPur.Content.WareHouse;
             storeParam.ProductCode = tPurDetail.DetDetail.ProductCode;
             MMS_Store sto = null;
             sto = daoStore.GetStore(storeParam);
             if (sto == null) //库存中没有该商品
             {
                 throw new Exception("库存中没有该商品,不能退货" + tPurDetail.DetDetail.ProductCode);
             }
             else
             {
                 if (tPurDetail.DetDetail.Quantity > sto.Quantity)
                 {
                     throw new Exception("库存数据不足,不能退货" + tPurDetail.DetDetail.ProductCode);
                 }
                 sto.Quantity -= tPurDetail.DetDetail.Quantity;
                 sto.Amount   -= tPurDetail.DetDetail.Quantity * tPurDetail.DetDetail.Price;
                 if (sto.Quantity > 0)
                 {
                     sto.Price = sto.Amount / sto.Quantity;
                 }
                 daoStore.UpdateInfo(sto);
             }
         }
         content.AuditFlag   = isAudit;
         content.Operator    = operatorCode;
         content.OperateDate = DateTime.Now;
         dao.UpdateInfo(content);
         ts.Complete();
     }
     return(true);
 }
Beispiel #5
0
 /// <summary>
 ///   更新库存信息
 /// </summary>
 /// <param name="info"> </param>
 /// <returns> </returns>
 public bool UpdateInfo(MMS_Store info)
 {
     return(dao.UpdateInfo(info));
 }
Beispiel #6
0
        /// <summary>
        ///   打印调拨单时调用
        /// </summary>
        /// <param name="id"> </param>
        /// <param name="isAudit"> </param>
        /// <param name="operatorCode"> </param>
        /// <returns> </returns>
        public bool AuditAdjust(int id, bool isAudit, string operatorCode)
        {
            using (TransactionScope ts = new TransactionScope())
            {
                TAdjust           tad       = dao.GetAdjust(id);
                MMS_AdjustContent adContent = tad.Content;

                foreach (TAdjustDetail adDetail in tad.Detail)
                {
                    string productCode = adDetail.DetDetail.ProductCode;
                    int    qty         = adDetail.DetDetail.Quantity;
                    double price       = adDetail.DetDetail.Price;
                    if (qty != 0)
                    {
                        MMS_Store Param1 = new MMS_Store();
                        Param1.Warehouse   = adContent.SourceWareHouse;
                        Param1.ProductCode = productCode;
                        MMS_Store sourceStore = daoStore.GetStore(Param1);
                        if (sourceStore == null)
                        {
                            throw new Exception("货品在源仓库不存在");
                        }
                        if (qty > sourceStore.Quantity)
                        {
                            throw new Exception("源仓库货品数量不足");
                        }
                        sourceStore.Quantity -= qty;
                        sourceStore.Amount   -= qty * price;
                        if (sourceStore.Quantity != 0)
                        {
                            sourceStore.Price = sourceStore.Amount / sourceStore.Quantity;
                        }
                        daoStore.UpdateInfo(sourceStore);

                        MMS_Store Param2 = new MMS_Store();
                        Param2.Warehouse   = adContent.TargetWareHouse;
                        Param2.ProductCode = productCode;
                        MMS_Store targetStore = daoStore.GetStore(Param2);
                        if (targetStore != null)
                        {
                            targetStore.Quantity += qty;
                            targetStore.Amount   += qty * price;
                            if (targetStore.Quantity != 0)
                            {
                                targetStore.Price = targetStore.Amount / targetStore.Quantity;
                            }
                            daoStore.UpdateInfo(targetStore);
                        }
                        else
                        {
                            MMS_Store newTarSto = new MMS_Store();
                            newTarSto.Warehouse   = adContent.TargetWareHouse;
                            newTarSto.ProductCode = productCode;
                            newTarSto.Quantity    = qty;
                            newTarSto.Price       = price;
                            newTarSto.Amount      = qty * price;
                            daoStore.InsertInfo(newTarSto);
                        }
                    }
                }
                adContent.AuditFlag = true;
                dao.UpdateInfo(adContent);
                ts.Complete();
            }
            return(true);
        }