예제 #1
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();
 }
예제 #2
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();
 }