예제 #1
0
 public static Guid ActionUseExt(this StoreEntity db, List<CachedUse> list, Guid userId, DateTime time, Guid operatorId, Guid storeId, string code = "")
 {
     if (list.Count == 0)
     {
         return Guid.Empty;
     }
     var gid = db.GlobalId();
     var su = new StoreUse
     {
         Id = gid,
         UserId = userId,
         Time = time,
         TimeNode = time.ToTimeNode(),
         OperationUserId = operatorId,
         OperationTime = DateTime.Now,
         UsageTarget = list.First().UserTarget,
         StoreId = storeId,
         Money = 0
     };
     db.StoreUse.Add(su);
     db.SaveChanges();
     foreach (var use in list)
     {
         decimal _money = 0;
         var objId = use.ObjectId.Value;
         var obj = db.StoreObject.Single(o => o.Id == objId);
         if (!obj.Single)
         {
             if (obj.Amount < use.Amount.Value)
                 use.Amount = obj.Amount;
             if (use.Type == "领用")
             {
                 var consume = new StoreConsume
                 {
                     Id = db.GlobalId(),
                     ObjectId = use.ObjectId.Value,
                     ConsumeUserId = userId,
                     Note = use.Note,
                     TimeNode = time.ToTimeNode(),
                     Time = time,
                     OperationUserId = operatorId,
                     OperationTime = DateTime.Now,
                     Code = code,
                     Amount = use.Amount.Value,
                     Money = 0
                 };
                 db.StoreConsume.Add(consume);
                 var counter = 0;
                 var left = consume.Amount;
                 foreach (var @in in obj.StoreIn.Where(o => o.Amount > 0).OrderBy(o => o.TimeNode))
                 {
                     counter++;
                     if (@in.Amount >= left)
                     {
                         var @single = new StoreConsumeSingle();
                         @single.Id = db.GlobalId();
                         var us = new StoreUseSingle
                         {
                             Id = db.GlobalId(),
                             UseId = gid,
                             Type = 0,
                             InId = @in.Id,
                             SingleInId = null,
                             ObjectId = obj.Id,
                             Note = use.Note,
                             Amount = left,
                             Money = (decimal.Divide(@in.SourceMoney, @in.SourceAmount)) * left,
                             SingleConsumeId = @single.Id
                         };
                         db.StoreUseSingle.Add(us);
                         consume.Money += (decimal.Divide(@in.SourceMoney, @in.SourceAmount)) * left;
                         @single.InId = @in.Id;
                         @single.ConsumeId = consume.Id;
                         @single.Ordinal = counter;
                         @single.Amount = left;
                         @single.PerPrice = @in.PerPrice;
                         @single.SourcePerPrice = @in.SourcePerPrice;
                         @single.Fee = (decimal.Divide(@in.Fee, @in.Amount)) * left;
                         @single.Money = (decimal.Divide(@in.SourceMoney, @in.SourceAmount)) * left;
                         @in.Amount -= left;
                         if (@in.Amount == 0)
                             @in.Money = 0;
                         else
                             @in.Money -= (decimal.Divide(@in.SourceMoney, @in.SourceAmount)) * left;
                         db.StoreConsumeSingle.Add(@single);
                         break;
                     }
                     else
                     {
                         left -= @in.Amount;
                         var @single = new StoreConsumeSingle();
                         @single.Id = db.GlobalId();
                         var us = new StoreUseSingle
                         {
                             Id = db.GlobalId(),
                             UseId = gid,
                             Type = 0,
                             InId = @in.Id,
                             SingleInId = null,
                             ObjectId = obj.Id,
                             Note = use.Note,
                             Amount = @in.Amount,
                             Money = @in.Amount * (decimal.Divide(@in.SourceMoney, @in.SourceAmount)),
                             SingleConsumeId = @single.Id
                         };
                         db.StoreUseSingle.Add(us);
                         consume.Money += @in.Amount * (decimal.Divide(@in.SourceMoney, @in.SourceAmount));
                         @single.InId = @in.Id;
                         @single.ConsumeId = consume.Id;
                         @single.Ordinal = counter;
                         @single.Amount = @in.Amount;
                         @single.PerPrice = @in.PerPrice;
                         @single.SourcePerPrice = @in.SourcePerPrice;
                         @single.Fee = @in.Fee;
                         @single.Money = @in.Amount * (decimal.Divide(@in.SourceMoney, @in.SourceAmount));
                         @in.Amount = 0;
                         @in.Money = 0;
                         db.StoreConsumeSingle.Add(@single);
                     }
                 }
                 _money = consume.Money;
                 su.Money += consume.Money;
                 obj.Amount -= use.Amount.Value;
                 obj.Money -= _money;
                 var flow = new StoreFlow
                 {
                     Id = db.GlobalId(),
                     ObjectId = objId,
                     UserId = operatorId,
                     Type = FlowType.领用出库,
                     TypeName = FlowType.领用出库.ToString(),
                     TimeNode = time.ToTimeNode(),
                     Time = time,
                     Amount = -use.Amount.Value,
                     Money = -consume.Money,
                     Note = use.Note
                 };
                 db.StoreFlow.Add(flow);
                 db.ActionRecord(objId, time, 0M, 0M, 0M, 0M, use.Amount.Value, _money, 0M, 0M, 0M, 0M);
                 db.SaveChanges();
             }
         }
     }
     return gid;
 }
예제 #2
0
 public static void ActionInExt(this StoreEntity db, Guid targetId, Guid objectId, string age, string place, string image, Guid? responsibleId, string note, DateTime inTime, Guid operatorId, string code, decimal amount, decimal totalPrice, decimal sourcePerPrice, decimal fee, decimal money)
 {
     var @in = new StoreIn
     {
         Id = db.GlobalId(),
         TargetId = targetId,
         ObjectId = objectId,
         Age = age,
         Place = place,
         Image = image,
         ResponsibleUserId = responsibleId,
         Note = note,
         TimeNode = inTime.ToTimeNode(),
         Time = inTime,
         OperationUserId = operatorId,
         OperationTime = DateTime.Now,
         Code = code,
         Amount = amount,
         SourceAmount = amount,
         OriginalAmount = amount,
         PerPrice = decimal.Divide(totalPrice, amount),
         SourcePerPrice = sourcePerPrice,
         Fee = fee,
         Money = totalPrice + fee,
         SourceMoney = totalPrice + fee,
         OriginalMoney = totalPrice + fee
     };
     db.StoreIn.Add(@in);
     var obj = db.StoreObject.Single(o => o.Id == objectId);
     obj.Amount += amount;
     obj.Money += money;
     var catalog = obj.StoreCatalog;
     var store = catalog.Store;
     if (store.State != StoreState.食品 && db.StoreDictionary.Count(o => o.StoreId == store.Id && o.Type == DictionaryType.年龄段 && o.Name == age) == 0)
     {
         var dictionary = new StoreDictionary
         {
             StoreId = catalog.StoreId,
             Type = DictionaryType.年龄段,
             Name = age,
             PinYin = db.ToPinYin(age).Single()
         };
         db.StoreDictionary.Add(dictionary);
     }
     var flow = new StoreFlow
     {
         Id = db.GlobalId(),
         ObjectId = objectId,
         UserId = operatorId,
         Type = FlowType.入库,
         TypeName = FlowType.入库.ToString(),
         TimeNode = inTime.ToTimeNode(),
         Time = inTime,
         Amount = amount,
         Money = money,
         Note = note
     };
     db.StoreFlow.Add(flow);
     db.ActionRecord(objectId, inTime, amount, money, 0M, 0M, 0M, 0M, 0M, 0M, 0M, 0M);
     if (obj.Single)
     {
         // To Do
     }
     db.SaveChanges();
 }
예제 #3
0
 public static void ActionInEditExt(this StoreEntity db, StoreIn @in, DateTime day, decimal amount, decimal perPrice, decimal money, string place, string note, Guid operatorId)
 {
     var obj = db.StoreObject.Single(o => o.Id == @in.ObjectId);
     var target = db.StoreTarget.Single(o => o.Id == @in.TargetId);
     if (obj.Single)
         return;
     decimal plusAmount = amount - @in.Amount;
     decimal plusMoney = money - @in.Money;
     if (day.Year == @in.Time.Year || day.Month == @in.Time.Month)
     {
         db.ActionRecord(obj.Id, day, plusAmount, plusMoney, 0, 0, 0, 0, 0, 0, 0, 0);
     }
     else
     {
         db.ActionRecord(obj.Id, @in.Time, plusAmount, plusMoney, 0, 0, 0, 0, 0, 0, 0, 0);
         db.ActionRecord(obj.Id, day, amount, money, 0, 0, 0, 0, 0, 0, 0, 0);
     }
     if (amount != @in.OriginalAmount || money != @in.OriginalMoney)
     {
         if (amount > 0 && money > 0)
         {
             @in.Amount = amount;
             @in.OriginalAmount = amount;
             @in.SourceAmount = amount;
             @in.Money = money;
             @in.OriginalMoney = money;
             @in.SourceMoney = money;
             @in.SourcePerPrice = perPrice;
             @in.PerPrice = decimal.Divide(money, amount);
             @in.Place = place;
             @in.Note = note;
             @in.Time = day;
             @in.TimeNode = day.ToTimeNode();
             obj.Amount += plusAmount;
             obj.Money += plusMoney;
             target.Paid += plusMoney;
             var flow = new StoreFlow
             {
                 Id = db.GlobalId(),
                 ObjectId = obj.Id,
                 UserId = operatorId,
                 Type = FlowType.入库修改,
                 TypeName = FlowType.入库修改.ToString(),
                 TimeNode = day.ToTimeNode(),
                 Time = day,
                 Amount = plusAmount,
                 Money = plusMoney,
                 Note = note
             };
             db.StoreFlow.Add(flow);
         }
         else
         {
             db.StoreIn.Remove(@in);
             obj.Amount += plusAmount;
             obj.Money += plusMoney;
             target.Paid += plusMoney;
             var flow = new StoreFlow
             {
                 Id = db.GlobalId(),
                 ObjectId = obj.Id,
                 UserId = operatorId,
                 Type = FlowType.入库修改,
                 TypeName = FlowType.入库修改.ToString(),
                 TimeNode = day.ToTimeNode(),
                 Time = day,
                 Amount = plusAmount,
                 Money = plusMoney,
                 Note = note
             };
             db.StoreFlow.Add(flow);
         }
     }
     db.SaveChanges();
 }