Exemple #1
0
        public override async Task HandleRevert(FlowSheet flowSheet)
        {
            //数据处理
            var formObj     = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(flowSheet.FlowInstance.FormData);
            var sheetData   = formObj["sheetData"];
            var sheetHeader = sheetData["header"];

            var storeId   = sheetHeader["storeId"].ToObject <int>(); //调出仓库id;
            var unitId    = sheetHeader["unitId"].ToObject <int>();  //供货商id
            var totalFee  = sheetHeader["totalFee"].ToObjectWithDefault <decimal>();
            var startDate = sheetHeader["startDate"].ToObjectWithDefault <DateTime>();
            //更改往来单位金额
            await UnitManager.ChangeFee(unitId, null, -totalFee, flowSheet);

            foreach (var sheetItem in sheetData["body"])
            {
                var materialId = Convert.ToInt32(sheetItem["id"]);            //对应的物料Id

                var number = sheetItem["number"].ToObjectWithDefault <int>(); //退货数量
                if (number > 0)
                {
                    await MaterialSellManager.Back(unitId, startDate, materialId, storeId, -number, flowSheet);

                    //清除退货数据
                    var materialSellBack = await MaterialSellBackManager.GetAll()
                                           .Where(o => o.UnitId == unitId && o.MaterialId == materialId && o.BackNumber == number && o.FlowSheetId == flowSheet.RelSheetId)
                                           .FirstOrDefaultAsync();

                    if (materialSellBack != null)
                    {
                        await MaterialSellBackManager.DeleteAsync(materialSellBack);
                    }
                }
            }
        }
        public override async Task HandleRevert(FlowSheet flowSheet)
        {
            //数据处理
            var formObj     = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(flowSheet.FlowInstance.FormData);
            var sheetData   = formObj["sheetData"];
            var sheetHeader = sheetData["header"];

            var storeId  = sheetHeader["storeId"].ToObject <int>(); //出货仓库id;
            var unitId   = sheetHeader["unitId"].ToObject <int>();  //代理商id
            var totalFee = sheetHeader["totalFee"].ToObjectWithDefault <decimal>();
            //更改往来单位金额
            await UnitManager.ChangeFee(unitId, null, totalFee, flowSheet);

            var materialSellIds = new List <int>();
            var toOutMaterials  = new Dictionary <int, int>();

            foreach (var sheetItem in sheetData["body"])
            {
                var materialId     = sheetItem["materialId"].ToObjectWithDefault <int>(); //商品Id
                var sellMaterialId = Convert.ToInt32(sheetItem["id"]);                    //对应的销售物料Id
                var number         = sheetItem["number"].ToObjectWithDefault <int>();     //出货数量
                if (number == 0)
                {
                    continue;
                }
                //取消销售出库记录
                var materialSellOut = await MaterialSellOutManager.GetAll()
                                      .Where(o => o.UnitId == unitId && o.FlowSheetId == sheetItem["flowSheetId"].ToObjectWithDefault <int>() && o.OutNumber == number && o.MaterialId == materialId)
                                      .FirstOrDefaultAsync();

                if (materialSellOut != null)
                {
                    await MaterialSellOutManager.DeleteAsync(materialSellOut);
                }

                materialSellIds.Add(sellMaterialId);
                //加入待出库集合
                if (!toOutMaterials.ContainsKey(materialId))
                {
                    toOutMaterials.Add(materialId, number);
                }
                else
                {
                    toOutMaterials[materialId] += number;
                }

                await MaterialSellManager.Out(unitId, sellMaterialId, storeId, -number, flowSheet);
            }
            //出库
            foreach (var item in toOutMaterials)
            {
                await StoreMaterialManager.CountMaterial(storeId, item.Key, item.Value, flowSheet);
            }
            await MaterialSellManager.CheckSellSheetStatus(materialSellIds);
        }
Exemple #3
0
        public override async Task Handle(FlowSheet flowSheet)
        {
            await base.Handle(flowSheet);

            //数据处理
            var formObj     = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(flowSheet.FlowInstance.FormData);
            var sheetData   = formObj["sheetData"];
            var sheetHeader = sheetData["header"];

            flowSheet.SheetDate = sheetHeader["sheetDate"].ToObjectWithDefault <DateTime>();
            flowSheet.Remarks   = sheetHeader["remarks"].ToObjectWithDefault <string>();
            var storeId   = sheetHeader["storeId"].ToObject <int>(); //退货仓库id;
            var unitId    = sheetHeader["unitId"].ToObject <int>();  //代理商id
            var totalFee  = sheetHeader["totalFee"].ToObjectWithDefault <decimal>();
            var startDate = sheetHeader["startDate"].ToObjectWithDefault <DateTime>();

            flowSheet.UnitId = unitId;
            flowSheet.SetPropertyValue("StoreName", sheetHeader["storeName"].ToObjectWithDefault <string>());
            flowSheet.SetPropertyValue("Fee", totalFee);

            //更改往来单位金额
            await UnitManager.ChangeFee(unitId, null, totalFee, flowSheet);

            foreach (var sheetItem in sheetData["body"])
            {
                var materialId = Convert.ToInt32(sheetItem["id"]);            //对应的物料Id

                var number = sheetItem["number"].ToObjectWithDefault <int>(); //退货数量
                if (number > 0)
                {
                    await MaterialSellManager.Back(unitId, startDate, materialId, storeId, number, flowSheet);

                    //产生退货数据
                    var materialSellBack = new MaterialSellBack()
                    {
                        UnitId      = unitId,
                        MaterialId  = materialId,
                        BackNumber  = number,
                        FlowSheetId = flowSheet.Id,
                        Discount    = sheetItem["discount"].ToObjectWithDefault <decimal>(),
                        Price       = sheetItem["price"].ToObjectWithDefault <decimal>(),
                    };
                    await MaterialSellBackManager.InsertAsync(materialSellBack);
                }
            }
        }
Exemple #4
0
        public override async Task Handle(FlowSheet flowSheet)
        {
            await base.Handle(flowSheet);

            //数据处理
            var formObj     = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(flowSheet.FlowInstance.FormData);
            var sheetData   = formObj["sheetData"];
            var sheetHeader = sheetData["header"];

            flowSheet.SheetDate = sheetHeader["sheetDate"].ToObjectWithDefault <DateTime>();
            flowSheet.Remarks   = sheetHeader["remarks"].ToObjectWithDefault <string>();
            var unitId = sheetHeader["unitId"].ToObject <int>();//代理商id

            flowSheet.UnitId = unitId;
            //flowSheet.OrderStatus=CurrentUser.IsCenterUser?"待出库": "待审核";
            //todo:暂不做票劵订单的审核 20200227
            flowSheet.OrderStatus = "待出库";
            flowSheet.SetPropertyValue("OrderType", CurrentUser.IsCenterUser?"中心代为下单": "代理商自助下单");
            //清空对应代理商的票劵购物车
            await CartRepository.DeleteAsync(o => o.CreatorUserId == AbpSession.UserId && o.UnitId == unitId && o.Material.MaterialNature == MaterialNature.票券);

            foreach (var sheetItem in sheetData["body"])
            {
                var materialId = Convert.ToInt32(sheetItem["id"]);                //对应的物料Id
                var number     = sheetItem["number"].ToObjectWithDefault <int>(); //订购数量
                //检测库存
                //var material = await MaterialManager.GetByIdAsync(materialId);
                //var sellMode = await MaterialManager.GetMaterialUnitSellMode(material, unitId);
                //var storeNumber = await StoreMaterialManager.GetMaterialNumber(materialId);
                //if (sellMode==UnitSellMode.售完为止 && number > storeNumber)
                //{
                //    throw new UserFriendlyException($"产品\"{material.Name}\"库存数量不足,无法下单");
                //}
                //记录销售
                var materialSell = new MaterialSell()
                {
                    MaterialId  = materialId,
                    FlowSheetId = flowSheet.Id,
                    SellNumber  = number,
                    Discount    = sheetItem["discount"].ToObjectWithDefault <decimal>(),//折扣
                    UnitId      = unitId
                };
                await MaterialSellManager.InsertAsync(materialSell);
            }
        }
Exemple #5
0
        public override async Task Action(FlowSheet flowSheet, string action, DateTime?lastModifyTime)
        {
            //数据处理
            var formObj     = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(flowSheet.FlowInstance.FormData);
            var sheetData   = formObj["sheetData"];
            var sheetHeader = sheetData["header"];
            var unitId      = sheetHeader["unitId"].ToObject <int>();//代理商id

            if (action == "backToCart")
            {
                foreach (var sheetItem in sheetData["body"])
                {
                    var materialId = Convert.ToInt32(sheetItem["id"]);                //对应的物料Id
                    var number     = sheetItem["number"].ToObjectWithDefault <int>(); //订购数量
                    //销售记录取消
                    var materialSell = await MaterialSellManager.GetAll()
                                       .Where(o => o.MaterialId == materialId && o.FlowSheetId == flowSheet.RelSheetId && o.SellNumber == number && o.UnitId == unitId).FirstOrDefaultAsync();

                    if (materialSell != null)
                    {
                        await MaterialSellManager.DeleteAsync(materialSell);
                    }

                    var materialCart = await CartRepository.GetAll().Where(o => o.UnitId == unitId && o.CreatorUserId == AbpSession.UserId && o.MaterialId == materialId).FirstOrDefaultAsync();

                    if (materialCart != null)
                    {
                        materialCart.Number += number;
                        await CartRepository.UpdateAsync(materialCart);
                    }
                    else
                    {
                        materialCart = new MaterialSellCart()
                        {
                            MaterialId = materialId,
                            Number     = number,
                            UnitId     = unitId
                        };
                        await CartRepository.InsertAsync(materialCart);
                    }
                }
                //删除订单
                await FlowSheetManager.DeleteAsync(flowSheet);
            }
        }
        public override async Task Handle(FlowSheet flowSheet)
        {
            await base.Handle(flowSheet);

            //数据处理
            var formObj     = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(flowSheet.FlowInstance.FormData);
            var sheetData   = formObj["sheetData"];
            var sheetHeader = sheetData["header"];

            flowSheet.SheetDate = sheetHeader["sheetDate"].ToObjectWithDefault <DateTime>();
            flowSheet.Remarks   = sheetHeader["remarks"].ToObjectWithDefault <string>();
            flowSheet.Fee       = sheetHeader["totalFee"].ToObjectWithDefault <decimal>();
            var unitId = sheetHeader["unitId"].ToObject <int>();//代理商id

            flowSheet.UnitId      = unitId;
            flowSheet.OrderStatus = "待审核";
            flowSheet.SetPropertyValue("OrderType", CurrentUser.IsCenterUser?"中心代为下单": "代理商自助下单");
            //清空对应代理商的实物购物车
            await CartRepository.DeleteAsync(o => o.CreatorUserId == AbpSession.UserId && o.UnitId == unitId && o.Material.MaterialNature == MaterialNature.实物);

            foreach (var sheetItem in sheetData["body"])
            {
                var materialId = Convert.ToInt32(sheetItem["id"]);            //对应的物料Id

                var number = sheetItem["number"].ToObjectWithDefault <int>(); //订购数量
                //记录销售
                var materialSell = new MaterialSell()
                {
                    MaterialId  = materialId,
                    FlowSheetId = flowSheet.Id,
                    SellNumber  = number,
                    UnitId      = unitId
                };
                await MaterialSellManager.InsertAsync(materialSell);
            }
        }
        public override async Task Handle(FlowSheet flowSheet)
        {
            await base.Handle(flowSheet);

            //数据处理
            var formObj     = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(flowSheet.FlowInstance.FormData);
            var sheetData   = formObj["sheetData"];
            var sheetHeader = sheetData["header"];

            flowSheet.SheetDate = sheetHeader["sheetDate"].ToObjectWithDefault <DateTime>();
            flowSheet.Remarks   = sheetHeader["remarks"].ToObjectWithDefault <string>();
            var storeId  = sheetHeader["storeId"].ToObject <int>(); //出货仓库id;
            var unitId   = sheetHeader["unitId"].ToObject <int>();  //代理商id
            var totalFee = sheetHeader["totalFee"].ToObjectWithDefault <decimal>();

            flowSheet.UnitId = unitId;
            flowSheet.SetPropertyValue("StoreName", sheetHeader["storeName"].ToObjectWithDefault <string>());
            flowSheet.SetPropertyValue("Fee", totalFee);

            //更改往来单位金额
            await UnitManager.ChangeFee(unitId, null, -totalFee, flowSheet);

            var materialSellIds = new List <int>();
            var toOutMaterials  = new Dictionary <int, int>();

            foreach (var sheetItem in sheetData["body"])
            {
                var materialId     = sheetItem["materialId"].ToObjectWithDefault <int>(); //商品Id
                var sellMaterialId = Convert.ToInt32(sheetItem["id"]);                    //对应的销售物料Id
                var number         = sheetItem["number"].ToObjectWithDefault <int>();     //出货数量
                if (number == 0)
                {
                    continue;
                }
                //建立销售出库记录
                var materialSellOut = new MaterialSellOut()
                {
                    UnitId      = unitId,
                    FlowSheetId = sheetItem["flowSheetId"].ToObjectWithDefault <int>(),
                    MaterialId  = materialId,
                    OutNumber   = number,
                    Price       = sheetItem["price"].ToObjectWithDefault <decimal>(),
                    Discount    = sheetItem["discount"].ToObjectWithDefault <decimal>()
                };
                await MaterialSellOutManager.InsertAsync(materialSellOut);

                materialSellIds.Add(sellMaterialId);
                //加入待出库集合
                if (!toOutMaterials.ContainsKey(materialId))
                {
                    toOutMaterials.Add(materialId, number);
                }
                else
                {
                    toOutMaterials[materialId] += number;
                }

                await MaterialSellManager.Out(unitId, sellMaterialId, storeId, number, flowSheet);
            }
            //出库
            foreach (var item in toOutMaterials)
            {
                //检测库存是否足够
                if (!StoreMaterialManager.IsSatisfied(item.Key, storeId, unitId, item.Value, out var message))
                {
                    throw new UserFriendlyException(message);
                }
                await StoreMaterialManager.CountMaterial(storeId, item.Key, -item.Value, flowSheet);
            }
            await MaterialSellManager.CheckSellSheetStatus(materialSellIds);
        }
        public override async Task Action(FlowSheet flowSheet, string action, DateTime?lastModifyTime)
        {
            //数据处理
            var formObj     = Newtonsoft.Json.JsonConvert.DeserializeObject <JObject>(flowSheet.FlowInstance.FormData);
            var sheetData   = formObj["sheetData"];
            var sheetHeader = sheetData["header"];

            flowSheet.Fee = sheetHeader["totalFee"].ToObjectWithDefault <decimal>();
            var unitId = sheetHeader["unitId"].ToObject <int>();//代理商id

            if (action == "backToCart")
            {
                foreach (var sheetItem in sheetData["body"])
                {
                    var materialId = Convert.ToInt32(sheetItem["id"]);                //对应的物料Id
                    var number     = sheetItem["number"].ToObjectWithDefault <int>(); //订购数量

                    var materialCart = await CartRepository.GetAll().Where(o => o.UnitId == unitId && o.CreatorUserId == AbpSession.UserId && o.MaterialId == materialId).FirstOrDefaultAsync();

                    if (materialCart != null)
                    {
                        materialCart.Number += number;
                        await CartRepository.UpdateAsync(materialCart);
                    }
                    else
                    {
                        materialCart = new MaterialSellCart()
                        {
                            MaterialId = materialId,
                            Number     = number,
                            UnitId     = unitId
                        };
                        await CartRepository.InsertAsync(materialCart);
                    }
                }
                //删除订单
                await FlowSheetManager.DeleteAsync(flowSheet);
            }
            else if (action == "modify")
            {
                if (flowSheet.OrderStatus != "待审核")
                {
                    throw new UserFriendlyException("本单据已被审核,当前操作无效,请重新查看");
                }
            }
            else if (action == "verify")
            {
                if (flowSheet.FlowInstance.LastModificationTime != null && (!lastModifyTime.HasValue || (flowSheet.FlowInstance.LastModificationTime.Value - lastModifyTime.Value).TotalSeconds > 1))
                {
                    throw new UserFriendlyException($"本单据已在{flowSheet.FlowInstance.LastModificationTime?.ToString("yyyy-MM-dd HH:mm:ss")}被{flowSheet.FlowInstance.LastModifierUser?.Name}修改,当前操作无效,请重新查看后再提交");
                }
                flowSheet.OrderStatus = "待发货";
            }
            else if (action == "cancel")
            {
                flowSheet.OrderStatus = "已取消";
            }
            else if (action == "send")
            {
                flowSheet.OrderStatus = "已发货";
                //‘收货时间’‘收货人姓名’‘联系方式’‘收货地址’
                flowSheet.SetPropertyValue("Receiver", sheetHeader["receiver"].ToObjectWithDefault <string>());
                flowSheet.SetPropertyValue("DeliverDate", sheetHeader["deliverDate"].ToObjectWithDefault <DateTime>());
                flowSheet.SetPropertyValue("ReceiverMobile", sheetHeader["receiverMobile"].ToObjectWithDefault <string>());
                flowSheet.SetPropertyValue("ReceiverAddress", sheetHeader["receiverAddress"].ToObjectWithDefault <string>());
                var totalFee = sheetHeader["totalFee"].ToObjectWithDefault <decimal>();
                //更改往来单位金额
                await UnitManager.ChangeFee(unitId, null, -totalFee, flowSheet);

                var materialSellIds = new List <int>();
                var toOutMaterials  = new Dictionary <int, int>();
                var outStoreId      = sheetHeader["storeId"].ToObjectWithDefault <int?>();
                if (outStoreId == null)
                {
                    throw new UserFriendlyException("请选择发货仓库");
                }

                var logs = new List <string>();

                foreach (var sheetItem in sheetData["body"])
                {
                    var materialId   = sheetItem["materialId"].ToObjectWithDefault <int>(); //商品Id
                    var number       = sheetItem["number"].ToObjectWithDefault <int>();     //出货数量
                    var materialSell = await MaterialSellManager.GetAll().Include(o => o.Material)
                                       .Where(o => o.FlowSheetId == flowSheet.Id && o.MaterialId == materialId).FirstOrDefaultAsync();

                    if (materialSell != null)
                    {
                        if (materialSell.SellNumber != number)
                        {
                            //发生订购数量更改需要进行记录
                            logs.Add($"商品\"{materialSell.Material.Name}\"订购数量从{materialSell.SellNumber}调整为{number}");
                        }
                        materialSell.SellNumber = number;
                        materialSell.OutNumber  = materialSell.SellNumber;//设置销售记录的出货数量等于订货数量
                    }
                    //建立销售出库记录
                    var materialSellOut = new MaterialSellOut()
                    {
                        UnitId      = unitId,
                        FlowSheetId = flowSheet.Id,
                        MaterialId  = materialId,
                        OutNumber   = number,
                        Price       = sheetItem["price"].ToObjectWithDefault <decimal>(),
                        Discount    = sheetItem["discount"].ToObjectWithDefault <decimal>()
                    };
                    await MaterialSellOutManager.InsertAsync(materialSellOut);

                    //检测库存是否足够
                    if (!StoreMaterialManager.IsSatisfied(materialId, outStoreId.Value, unitId, number, out var message))
                    {
                        throw new UserFriendlyException(message);
                    }
                    //库存变化
                    await StoreMaterialManager.CountMaterial(outStoreId.Value, materialId, -number, flowSheet);
                }
                if (logs.Count > 0)
                {
                    flowSheet.SetPropertyValue("Log", $"{AbpSession.Name()}于{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")}将{string.Join(';', logs)}");
                }
            }
            else if (action == "back")
            {
                var totalFee = sheetHeader["totalFee"].ToObjectWithDefault <decimal>();
                flowSheet.OrderStatus = "已退货";
                //更改往来单位金额
                await UnitManager.ChangeFee(unitId, null, totalFee, flowSheet);

                var materialSellIds = new List <int>();
                var toOutMaterials  = new Dictionary <int, int>();
                var backStoreId     = sheetHeader["backStoreId"].ToObjectWithDefault <int?>();
                if (backStoreId == null)
                {
                    throw new UserFriendlyException("请选择退入仓库");
                }

                foreach (var sheetItem in sheetData["body"])
                {
                    var materialId = sheetItem["materialId"].ToObjectWithDefault <int>(); //商品Id
                    var number     = sheetItem["number"].ToObjectWithDefault <int>();     //出货数量
                    //库存变化
                    await StoreMaterialManager.CountMaterial(backStoreId.Value, materialId, number, flowSheet);

                    //产生退货数据
                    var materialSellBack = new MaterialSellBack()
                    {
                        UnitId      = unitId,
                        MaterialId  = materialId,
                        BackNumber  = number,
                        FlowSheetId = flowSheet.Id,
                        Discount    = sheetItem["discount"].ToObjectWithDefault <decimal>(),
                        Price       = sheetItem["price"].ToObjectWithDefault <decimal>(),
                    };
                    await MaterialSellBackManager.InsertAsync(materialSellBack);
                }
            }
        }