/// <summary>
        /// 作废单据
        /// </summary>
        /// <param name="id"></param>
        /// <param name="delReason"></param>
        /// <returns></returns>
        public Purchase SetIsDel(int id, string delReason)
        {
            var purchase = FirstOrDefault(p => p.Id == id);

            if (purchase == null)
            {
                throw new Exception("所选择的单据不存在");
            }
            //如果单据施工状态为已完成,则往仓库入库相应油量
            if (purchase.State == Purchase.UnloadState.完工)
            {
                StoreRepository st_r        = new StoreRepository(_dbContext);
                bool            isUpdateOil = false;
                foreach (var item in purchase.ToStoresList)
                {
                    isUpdateOil = st_r.UpdateOil(item.Id, item.Count, false);
                    //增加出仓记录
                    InAndOutLogRepository io_r = new InAndOutLogRepository(_dbContext);
                    io_r.Insert(new InAndOutLog
                    {
                        Name       = "作废单据",
                        StoreId    = item.Id,
                        Value      = item.Count,
                        ValueLitre = item.Count,
                        Operators  = CurrentUser,
                        Unit       = "升",
                        Type       = LogType.出仓
                    });
                }
            }
            purchase.IsDel     = true;
            purchase.DelReason = delReason;
            Save();
            return(purchase);
        }
Beispiel #2
0
        /// <summary>
        /// 作废单据
        /// </summary>
        /// <param name="id"></param>
        /// <param name="delReason"></param>
        /// <returns></returns>
        public Order SetIsDel(int id, string delReason)
        {
            var order = FirstOrDefault(o => o.Id == id);

            if (order == null)
            {
                throw new Exception("所选择的单据不存在");
            }
            //如果单据施工状态为已完成,则往仓库入库相应油量
            if (order.State == OrderState.已完成)
            {
                StoreRepository st_r        = new StoreRepository(_dbContext);
                bool            isUpdateOil = st_r.UpdateOil(int.Parse(order.StoreId.ToString()), order.OilCountLitre, true);
                //增加入仓记录
                InAndOutLogRepository io_r = new InAndOutLogRepository(_dbContext);
                io_r.Insert(new InAndOutLog
                {
                    Name       = "作废单据",
                    StoreId    = int.Parse(order.StoreId.ToString()),
                    Value      = order.OilCount,
                    ValueLitre = order.OilCountLitre,
                    Operators  = CurrentUser,
                    Unit       = order.Unit,
                    Type       = LogType.入仓
                });
            }
            order.IsDel     = true;
            order.DelReason = delReason;
            Save();
            return(order);
        }
        public MoveStore UpdateInOutFact(MoveStore m)
        {
            MoveStore ms = _dbContext.MoveStores.Find(m.Id);

            ms.InFact  = m.InFact;
            ms.OutFact = m.OutFact;
            ms.State   = MoveStoreState.已完成;

            //更新油仓数量
            StoreRepository st_r   = new StoreRepository(_dbContext);
            bool            isSucc = st_r.UpdateOil(m.InStoreId, m.OutStoreId, m.InFact, m.OutFact);

            if (isSucc)
            {
                //增加出入仓记录
                InAndOutLogRepository io_r  = new InAndOutLogRepository(_dbContext);
                InAndOutLog           io_in = io_r.Insert(new InAndOutLog {
                    Name       = "生产转仓",
                    StoreId    = m.InStoreId,
                    Value      = m.InFact,
                    ValueLitre = m.InFact,
                    Operators  = CurrentUser,
                    Unit       = "升",
                    Type       = LogType.入仓
                });
                InAndOutLog io_out = io_r.Insert(new InAndOutLog {
                    Name       = "生产转仓",
                    StoreId    = m.OutStoreId,
                    Value      = m.OutFact,
                    ValueLitre = m.OutFact,
                    Operators  = CurrentUser,
                    Unit       = "升",
                    Type       = LogType.出仓
                });

                Save();
            }
            return(ms);
        }
Beispiel #4
0
 /// <summary>
 /// 更改订单状态
 /// </summary>
 /// <param name="model">Model</param>
 /// <returns></returns>
 public Order ChangeState(Order order)
 {
     if (order.State == OrderState.空车过磅)
     {
         order.StartOilDateTime = DateTime.Now;
     }
     if (order.State == OrderState.油车过磅)
     {
         order.EndOilDateTime = DateTime.Now;
     }
     //更新对应销售仓的数量
     if (order.State == OrderState.已完成)
     {
         if (order.Unit == "吨")
         {
             order.OilCount = UnitExchange.ToTon(order.OilCountLitre, order.Density);
         }
         StoreRepository st_r = new StoreRepository(_dbContext);
         //更新油仓数量
         bool isUpdateStore;
         isUpdateStore = st_r.UpdateOil(int.Parse(order.StoreId.ToString()), Math.Round(order.OilCountLitre, 2), false);
         if (isUpdateStore)
         {
             //增加出仓记录
             InAndOutLogRepository io_r = new InAndOutLogRepository(_dbContext);
             io_r.Insert(new InAndOutLog
             {
                 Name       = Enum.GetName(typeof(SalesPlanType), order.OrderType),
                 StoreId    = int.Parse(order.StoreId.ToString()),
                 Value      = Math.Round(order.OilCount, 2),
                 ValueLitre = Math.Round(order.OilCountLitre, 2),
                 Operators  = CurrentUser,
                 Unit       = order.Unit,
                 Type       = LogType.出仓
             });
         }
     }
     order.LastUpdatedBy = CurrentUser;
     return(Update(order));//更改状态
 }
        /// <summary>
        /// 卸油审核后更新油仓油量,平均单价;新增出入记录
        /// </summary>
        /// <param name="model">进油单model</param>
        /// <returns>实际入仓总升数</returns>
        public decimal UpdateStoreOil(Purchase model)
        {
            decimal infactTotal = 0;

            try {
                //更新油仓
                StoreRepository       st_r;
                InAndOutLogRepository io_r;
                st_r = new StoreRepository(_dbContext);
                foreach (ToStoreModel ts in model.ToStoresList)
                {
                    //更新平均单价
                    bool isUpdateAvgPrice = st_r.UpdateAvgPrice(ts.Id, model.Price, ts.Count);
                    //更新油仓当前数量
                    bool isUpdateStore = st_r.UpdateOil(ts.Id, ts.Count, true);
                    if (isUpdateStore && isUpdateAvgPrice)
                    {
                        //增加入仓记录
                        io_r = new InAndOutLogRepository(_dbContext);
                        io_r.Insert(new InAndOutLog
                        {
                            Name       = "卸油入库",
                            StoreId    = ts.Id,
                            Value      = ts.Count,
                            ValueLitre = ts.Count,
                            Operators  = CurrentUser,
                            Unit       = "升",
                            Type       = LogType.入仓
                        });
                        infactTotal += ts.Count;
                    }
                }
                return(infactTotal);
            }
            catch
            {
                return(0);
            }
        }
Beispiel #6
0
        /// <summary>
        /// 重新施工
        /// </summary>
        /// <param name="order">model</param>
        /// <returns></returns>
        public Order Restart(Order order)
        {
            StoreRepository st_r = new StoreRepository(_dbContext);
            //更新油仓数量
            bool isUpdateStore = st_r.UpdateOil(int.Parse(order.StoreId.ToString()), order.OilCountLitre, true);

            if (isUpdateStore)
            {
                //增加入仓记录
                InAndOutLogRepository io_r = new InAndOutLogRepository(_dbContext);
                io_r.Insert(new InAndOutLog
                {
                    Name       = "重新施工",
                    StoreId    = int.Parse(order.StoreId.ToString()),
                    Value      = order.OilCount,
                    ValueLitre = order.OilCountLitre,
                    Operators  = CurrentUser,
                    Unit       = order.Unit,
                    Type       = LogType.入仓
                });
            }
            order.State = OrderState.已开单;
            return(Update(order));//回退到初始状态“已开单”
        }