Exemplo n.º 1
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);
            }
        }
        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);
        }
Exemplo n.º 4
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));//回退到初始状态“已开单”
        }