Ejemplo n.º 1
0
 public static void DepotActInRedo(this DepotEntities db, Guid depotId, DepotIn @in, decimal backed, Guid operatorId)
 {
     var obj = db.DepotObject.Single(o => o.Id == @in.ObjectId);
     var order = db.DepotOrder.Single(o => o.Id == @in.OrderId);
     decimal amount = @in.Amount - backed;
     decimal money = (@in.Amount - backed) * @in.Price;
     decimal plusAmount = -backed;
     decimal plusMoney = -backed * @in.Price;
     db.DepotActStatistics(obj.Id, @in.Time, plusAmount, plusMoney, 0, 0, 0, 0, 0, 0, 0, 0);
     if (obj.Single)
     {
         return;
     }
     else
     {
         var x = @in.DepotInX.First();
         if (x.DepotUseX.Count > 0)
             return;
         if (amount > 0 && money > 0)
         {
             @in.Amount = amount;
             @in.AvailableAmount = amount;
             @in.Total = money;
             @in.Price = decimal.Divide(money, amount);
             obj.Amount += plusAmount;
             obj.Money += plusMoney;
             order.Paid += plusMoney;
             var flow = new DepotFlow
             {
                 Id = db.GlobalId(),
                 ObjectId = @in.ObjectId,
                 UserId = operatorId,
                 Type = FlowType.退货,
                 TypeName = FlowType.退货.ToString(),
                 Time = @in.Time,
                 Amount = plusAmount,
                 Money = plusMoney,
                 Note = (new InMemoryRedo { Amount = backed, Name = @in.DepotObject.Name, OrderId = @in.OrderId }).ToJson()
             };
             db.DepotFlow.Add(flow);
             x.Amount = @in.Amount;
             x.AvailableAmount = @in.Amount;
             x.Total = @in.Total;
         }
     }
     db.SaveChanges();
 }
Ejemplo n.º 2
0
 public static void DepotActIn(this DepotEntities db, Guid depotId, Guid orderId, DateTime inTime, Guid operatorId, List<InMemoryIn> list)
 {
     foreach (var item in list)
     {
         if (!item.ObjectId.HasValue || !item.Amount.HasValue || item.Amount.Value == 0)
             continue;
         var objId = item.ObjectId.Value;
         var obj = db.DepotObject.Single(o => o.Id == objId);
         var @in = new DepotIn
         {
             Id = db.GlobalId(),
             OrderId = orderId,
             ObjectId = item.ObjectId.Value,
             Age = item.Age,
             Place = item.Place,
             ResponsibleId = null,
             Note = item.Note,
             Time = inTime,
             OperatorId = operatorId,
             OperationTime = DateTime.Now,
             Amount = item.Amount.Value,
             AvailableAmount = item.Amount.Value,
             Price = decimal.Divide(item.Money.Value, item.Amount.Value),
             PriceSet = item.PriceSet.HasValue ? item.PriceSet.Value : 0M,
             Total = item.Money.Value,
         };
         db.DepotIn.Add(@in);
         obj.Amount += @in.Amount;
         obj.Money += @in.Total;
         if (obj.Single)
         {
             var current = db.DepotInX.Count(o => o.ObjectId == obj.Id) == 0 ? 0 : db.DepotInX.Where(o => o.ObjectId == obj.Id).Max(o => o.Ordinal);
             for (var j = 0; j < @in.Amount; j++)
             {
                 current++;
                 var inx = new DepotInX
                 {
                     Id = db.GlobalId(),
                     InId = @in.Id,
                     OrderId = @in.OrderId,
                     ObjectId = @in.ObjectId,
                     Age = @in.Age,
                     Place = @in.Place,
                     Ordinal = current,
                     Amount = 1,
                     PriceSet = @in.PriceSet,
                     Price = @in.Price,
                     Total = @in.Price,
                     AvailableAmount = 1,
                     Code = obj.Code
                 };
                 db.DepotInX.Add(inx);
                 db.SaveChanges();
                 inx.Code = db.ToQR(CodeType.Single, inx.AutoId);
                 var flowx = new DepotFlowX
                 {
                     Id = db.GlobalId(),
                     ObjectId = @in.ObjectId,
                     ObjectOrdinal = inx.Ordinal,
                     UserId = operatorId,
                     Type = FlowType.入库,
                     TypeName = FlowType.入库.ToString(),
                     Time = inTime,
                     Amount = 1,
                     Money = @in.Price,
                     Note = @in.Note
                 };
                 db.DepotFlowX.Add(flowx);
             }
         }
         else
         {
             var inx = new DepotInX
             {
                 Id = db.GlobalId(),
                 InId = @in.Id,
                 OrderId = @in.OrderId,
                 ObjectId = @in.ObjectId,
                 Age = @in.Age,
                 Place = @in.Place,
                 Ordinal = -1,
                 Amount = @in.Amount,
                 PriceSet = @in.PriceSet,
                 Price = @in.Price,
                 Total = @in.Total,
                 AvailableAmount = @in.AvailableAmount,
                 Code = obj.Code
             };
             db.DepotInX.Add(inx);
             var flow = new DepotFlow
             {
                 Id = db.GlobalId(),
                 ObjectId = @in.ObjectId,
                 UserId = operatorId,
                 Type = FlowType.入库,
                 TypeName = FlowType.入库.ToString(),
                 Time = inTime,
                 Amount = @in.Amount,
                 Money = @in.Total,
                 Note = @in.Note
             };
             db.DepotFlow.Add(flow);
         }
         db.DepotActStatistics(@in.ObjectId, inTime, @in.Amount, @in.Total, 0, 0, 0, 0, 0, 0, 0, 0);
         db.SaveChanges();
         db.DepotDictionaryAdd(depotId, DictionaryType.年龄段, item.Age);
         db.DepotDictionaryAdd(depotId, DictionaryType.存放地, item.Place);
     }
 }
Ejemplo n.º 3
0
 public static void DepotActInEdit(this DepotEntities db, Guid depotId, DepotIn @in, DateTime day, decimal amount, decimal priceSet, decimal money, string age, string place, string note, Guid operatorId)
 {
     var obj = db.DepotObject.Single(o => o.Id == @in.ObjectId);
     var order = db.DepotOrder.Single(o => o.Id == @in.OrderId);
     decimal plusAmount = amount - @in.Amount;
     decimal plusMoney = money - @in.Total;
     if (day.Year == @in.Time.Year && day.Month == @in.Time.Month)
     {
         db.DepotActStatistics(obj.Id, day, plusAmount, plusMoney, 0, 0, 0, 0, 0, 0, 0, 0);
     }
     else
     {
         db.DepotActStatistics(obj.Id, @in.Time, [email protected], [email protected], 0, 0, 0, 0, 0, 0, 0, 0);
         db.DepotActStatistics(obj.Id, day, amount, money, 0, 0, 0, 0, 0, 0, 0, 0);
     }
     if (obj.Single)
     {
         return;
     }
     else
     {
         @in.Age = age;
         @in.Place = place;
         @in.Note = note;
         @in.Time = day;
         var x = @in.DepotInX.First();
         x.Age = @in.Age;
         x.Place = @in.Place;
         if (amount != @in.Amount || money != @in.Total)
         {
             if (amount > 0 && money > 0)
             {
                 @in.Amount = amount;
                 @in.AvailableAmount = amount;
                 @in.Total = money;
                 @in.PriceSet = priceSet;
                 @in.Price = decimal.Divide(money, amount);
                 obj.Amount += plusAmount;
                 obj.Money += plusMoney;
                 order.Paid += plusMoney;
                 var flow = new DepotFlow
                 {
                     Id = db.GlobalId(),
                     ObjectId = @in.ObjectId,
                     UserId = operatorId,
                     Type = FlowType.入库修改,
                     TypeName = FlowType.入库修改.ToString(),
                     Time = day,
                     Amount = plusAmount,
                     Money = plusMoney,
                     Note = @in.Note
                 };
                 db.DepotFlow.Add(flow);
                 x.Amount = @in.Amount;
                 x.AvailableAmount = @in.Amount;
                 x.Total = @in.Total;
                 x.PriceSet = @in.PriceSet;
                 x.Price = @in.Price;
             }
             else
             {
                 db.DepotInX.Remove(x);
                 db.DepotIn.Remove(@in);
                 obj.Amount += plusAmount;
                 obj.Money += plusMoney;
                 order.Paid += plusMoney;
                 var flow = new DepotFlow
                 {
                     Id = db.GlobalId(),
                     ObjectId = @in.ObjectId,
                     UserId = operatorId,
                     Type = FlowType.入库修改,
                     TypeName = FlowType.入库修改.ToString(),
                     Time = day,
                     Amount = plusAmount,
                     Money = plusMoney,
                     Note = @in.Note
                 };
                 db.DepotFlow.Add(flow);
             }
         }
     }
     db.SaveChanges();
     db.DepotDictionaryAdd(depotId, DictionaryType.年龄段, age);
     db.DepotDictionaryAdd(depotId, DictionaryType.存放地, place);
 }
Ejemplo n.º 4
0
 public static void DepotActInRedo(this DepotEntities db, Guid depotId, DepotIn @in, decimal backed, Guid operatorId)
 {
     if (backed == 0)
         return;
     var obj = db.DepotObject.Single(o => o.Id == @in.ObjectId);
     var order = db.DepotOrder.Single(o => o.Id == @in.OrderId);
     decimal amount = @in.Amount - backed;
     decimal money = (@in.Amount - backed) * @in.Price;
     decimal plusAmount = -backed;
     decimal plusMoney = -backed * @in.Price;
     db.DepotActStatistics(obj.Id, @in.Time, plusAmount, plusMoney, 0, 0, 0, 0, 0, 0, 0, 0);
     if (obj.Single)
     {
         if (amount >= 0 && money >= 0)
         {
             foreach (var inx in @in.DepotInX)
             {
                 if (inx.DepotUseX.Count > 0)
                     return;
             }
             @in.Amount = amount;
             @in.AvailableAmount = amount;
             @in.Total = money;
             @in.Price = decimal.Divide(money, amount);
             obj.Amount += plusAmount;
             obj.Money += plusMoney;
             order.Paid += plusMoney;
             var dr = new DepotRedo
             {
                 Id = db.GlobalId(),
                 DepotId = depotId,
                 UserId = operatorId,
                 ObjectId = obj.Id,
                 InId = @in.Id,
                 Amount = backed,
                 Money = backed * @in.Price,
                 Time = DateTime.Now,
                 Note = ""
             };
             db.DepotRedo.Add(dr);
             var left = backed;
             foreach (var inx in @in.DepotInX.OrderByDescending(o => o.Ordinal).ToList())
             {
                 inx.Amount = 0;
                 inx.AvailableAmount = 0;
                 inx.Total = 0;
                 var flowx = new DepotFlowX
                 {
                     Id = db.GlobalId(),
                     ObjectId = @in.ObjectId,
                     ObjectOrdinal = inx.Ordinal,
                     UserId = operatorId,
                     Type = FlowType.退货,
                     TypeName = FlowType.退货.ToString(),
                     Time = @in.Time,
                     Amount = plusAmount,
                     Money = plusMoney,
                     Note = ""
                 };
                 db.DepotFlowX.Add(flowx);
                 left--;
                 if (left == 0)
                     break;
             }
         }
     }
     else
     {
         var x = @in.DepotInX.First();
         if (x.DepotUseX.Count(o => o.InXId == x.Id) > 0)
             return;
         if (amount >= 0 && money >= 0)
         {
             @in.Amount = amount;
             @in.AvailableAmount = amount;
             @in.Total = money;
             @in.Price = amount == 0 ? 0 : decimal.Divide(money, amount);
             obj.Amount += plusAmount;
             obj.Money += plusMoney;
             order.Paid += plusMoney;
             var flow = new DepotFlow
             {
                 Id = db.GlobalId(),
                 ObjectId = @in.ObjectId,
                 UserId = operatorId,
                 Type = FlowType.退货,
                 TypeName = FlowType.退货.ToString(),
                 Time = @in.Time,
                 Amount = plusAmount,
                 Money = plusMoney,
                 Note = ""
             };
             db.DepotFlow.Add(flow);
             x.Amount = @in.Amount;
             x.AvailableAmount = @in.Amount;
             x.Total = @in.Total;
             var dr = new DepotRedo
             {
                 Id = db.GlobalId(),
                 DepotId = depotId,
                 UserId = operatorId,
                 ObjectId = obj.Id,
                 InId = @in.Id,
                 Amount = backed,
                 Money = backed * @in.Price,
                 Time = DateTime.Now,
                 Note = ""
             };
             db.DepotRedo.Add(dr);
         }
     }
     db.SaveChanges();
 }