Exemplo n.º 1
0
        public override async Task Handle(FlowSheet flowSheet)
        {
            await base.Handle(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 payUnitId = sheetHeader["payUnit"]["id"].ToObject <int>();//付款代理id
            var payUnit   = await UnitManager.GetByIdAsync(payUnitId);

            var receiveUnitId = sheetHeader["receiveUnit"]["id"].ToObject <int>();//收款供应商id
            var receiveUnit   = await UnitManager.GetByIdAsync(receiveUnitId);

            var fee = sheetHeader["fee"].ToObject <decimal>();//

            flowSheet.SetPropertyValue("Fee", fee);
            flowSheet.SetPropertyValue("OutUnitName", payUnit.UnitName);
            flowSheet.SetPropertyValue("OutCompanyName", sheetHeader["payUnit"]["companyName"].ToObjectWithDefault <string>());
            flowSheet.SetPropertyValue("InUnitName", receiveUnit.UnitName);
            flowSheet.SetPropertyValue("InCompanyName", sheetHeader["receiveUnit"]["companyName"].ToObjectWithDefault <string>());
            //读取对应的账号id
            var accountId = (await FeeAccountManager.GetByName(FeeAccount.StaticAccountName3)).Id;

            flowSheet.SetPropertyValue("AccountId", accountId);
            //往来单位金额变动
            await UnitManager.ChangeFee(payUnitId, accountId, fee, flowSheet);

            await UnitManager.ChangeFee(receiveUnitId, accountId, -fee, flowSheet);
        }
Exemplo n.º 2
0
        public override async Task Action(FlowSheet flowSheet, string action, DateTime?lastModifyTime)
        {
            if (action == "verify")
            {
                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;
                //设置为审核状态
                flowSheet.OrderStatus = "已审核";
                foreach (var sheetItem in sheetData["body"])
                {
                    var materialId = Convert.ToInt32(sheetItem["id"]);            //对应的物料Id

                    var number = sheetItem["number"].ToObjectWithDefault <int>(); //报损报溢数量

                    await StoreMaterialManager.CountMaterial(storeId, materialId, number, flowSheet);
                }
            }
            else if (action == "cancel")
            {
                flowSheet.OrderStatus = "已取消";
            }
        }
Exemplo n.º 3
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);
                    }
                }
            }
        }
Exemplo n.º 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 outStoreId = sheetHeader["outStoreId"].ToObject <int>(); //调出仓库id;
            var inStoreId  = sheetHeader["inStoreId"].ToObject <int>();  //调入仓库id;

            flowSheet.SetPropertyValue("OutStoreName", sheetHeader["outStoreName"].ToObjectWithDefault <string>());
            flowSheet.SetPropertyValue("InStoreName", sheetHeader["inStoreName"].ToObjectWithDefault <string>());
            foreach (var sheetItem in sheetData["body"])
            {
                var materialId = Convert.ToInt32(sheetItem["id"]);            //对应的物料Id

                var number = sheetItem["number"].ToObjectWithDefault <int>(); //调拨数量

                await StoreMaterialManager.TransferMaterial(outStoreId, inStoreId, materialId, number, flowSheet);
            }
        }
Exemplo n.º 5
0
        public override async Task HandleRevert(FlowSheet flowSheet)
        {
            var accountId  = flowSheet.GetPropertyValue <int>("AccountId");
            var feeAccount = await FeeAccountManager.GetByIdAsync(accountId);

            var totalFee       = flowSheet.GetPropertyValue <decimal>("Fee");
            var affectRemain   = flowSheet.GetPropertyValue <bool>("AffectRemain");
            var relCompanyName = flowSheet.GetPropertyValue <string>("RelCompanyName");

            if (affectRemain)
            {
                //往来单位金额变动
                await UnitManager.ChangeFee(flowSheet.UnitId.Value, accountId, totalFee, flowSheet, relCompanyName);
            }
            else
            {
                //账号金额变动
                await FeeAccountManager.BuildFeeHistory(feeAccount, flowSheet.UnitId, totalFee, flowSheet, relCompanyName);
            }
            //将对应的支票设置为收入退回
            if (flowSheet.GetPropertyValue <string>("PayType") == GetPayTypeName(2))
            {
                var feeCheckId = flowSheet.GetPropertyValue <int>("FeeCheckId");
                var feeCheck   = await FeeCheckManager.GetByIdAsync(feeCheckId);

                feeCheck.CheckStatus = CheckStatus.支出退票;
            }
        }
Exemplo n.º 6
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.Remarks   = sheetHeader["remarks"].ToObjectWithDefault <string>();
            flowSheet.SheetDate = sheetHeader["sheetDate"].ToObjectWithDefault <DateTime>();
            var inAccountId  = sheetHeader["inAccountId"].ToObjectWithDefault <int>(); //账号id;
            var outAccountId = sheetHeader["outAccountId"].ToObject <int>();
            var fee          = sheetHeader["fee"].ToObject <decimal>();                //
            var inAccount    = await FeeAccountManager.GetByIdAsync(inAccountId);

            var outAccount = await FeeAccountManager.GetByIdAsync(outAccountId);

            flowSheet.SetPropertyValue("Fee", fee);
            flowSheet.SetPropertyValue("OutAccountId", outAccountId);
            flowSheet.SetPropertyValue("InAccountId", inAccountId);
            flowSheet.SetPropertyValue("OutAccount", outAccount.Name);
            flowSheet.SetPropertyValue("InAccount", inAccount.Name);

            //账户金额变动
            await FeeAccountManager.BuildFeeHistory(inAccount, null, fee, flowSheet);

            await FeeAccountManager.BuildFeeHistory(outAccount, null, -fee, flowSheet);
        }
Exemplo n.º 7
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.Remarks = sheetHeader["remarks"].ToObjectWithDefault <string>();
            var unitId         = sheetHeader["unitId"].ToObject <int>();                //代理id;
            var accountId      = sheetHeader["accountId"].ToObjectWithDefault <int?>(); //账号id;
            var payType        = sheetHeader["payType"].ToObject <int>();
            var totalFee       = sheetHeader["totalFee"].ToObject <decimal>();          //
            var affectRemain   = sheetHeader["affectRemain"].ToObject <bool>();
            var relCompanyName = sheetHeader["relCompanyName"]?.ToObject <string>();

            flowSheet.UnitId = unitId;
            flowSheet.SetPropertyValue("Fee", totalFee);
            flowSheet.SetPropertyValue("PayType", GetPayTypeName(payType));
            flowSheet.SetPropertyValue("AffectRemain", affectRemain);
            flowSheet.SetPropertyValue("RelCompanyName", relCompanyName);
            //读取对应的账号id
            if (payType == 0)
            {
                accountId = (await FeeAccountManager.GetByName(FeeAccount.StaticAccountName1)).Id;
            }
            else if (payType == 2)
            {
                accountId = (await FeeAccountManager.GetByName(FeeAccount.StaticAccountName2)).Id;
                //建立支票信息
                var feeCheckId = sheetHeader["feeCheck"]["id"].ToObject <int>();
                //设置对应支票信息为已支出
                var feeCheck = await FeeCheckManager.GetByIdAsync(feeCheckId);

                if (feeCheck.CheckStatus != CheckStatus.收入)
                {
                    throw new UserFriendlyException("支票状态不是收入,无法进行使用");
                }
                feeCheck.CheckStatus    = CheckStatus.支出;
                feeCheck.OutFlowSheetId = flowSheet.Id;//设置支票的支出单据
                flowSheet.SetPropertyValue("FeeCheckId", feeCheckId);
            }
            var feeAccount = await FeeAccountManager.GetByIdAsync(accountId.Value);

            flowSheet.SetPropertyValue("AccountId", accountId);
            if (affectRemain)
            {
                //往来单位金额变动
                await UnitManager.ChangeFee(unitId, accountId.Value, -totalFee, flowSheet, relCompanyName);
            }
            else
            {
                //账户金额变动
                await FeeAccountManager.BuildFeeHistory(feeAccount, unitId, -totalFee, flowSheet, relCompanyName);
            }
        }
Exemplo n.º 8
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>();
            //更改往来单位金额
            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);
        }
Exemplo n.º 9
0
        public override async Task <IEnumerable <ModuleButton> > GetFlowBtns(FlowSheet flowSheet)
        {
            var result = new List <ModuleButton>();

            //加入打印按钮
            result.Add(new ModuleButton()
            {
                ButtonKey   = "print",
                ButtonName  = "打印",
                ButtonClass = "layui-btn-normal"
            });
            return(result);
        }
Exemplo n.º 10
0
        public override async Task HandleRevert(FlowSheet flowSheet)
        {
            var inAccountId  = flowSheet.GetPropertyValue <int>("InAccountId");
            var outAccountId = flowSheet.GetPropertyValue <int>("OutAccountId");
            var inAccount    = await FeeAccountManager.GetByIdAsync(inAccountId);

            var outAccount = await FeeAccountManager.GetByIdAsync(outAccountId);

            var fee = flowSheet.GetPropertyValue <decimal>("Fee");
            //账户金额变动
            await FeeAccountManager.BuildFeeHistory(inAccount, null, -fee, flowSheet);

            await FeeAccountManager.BuildFeeHistory(outAccount, null, fee, flowSheet);
        }
Exemplo n.º 11
0
        /// <summary>
        /// 构建往来单位变动明细
        /// </summary>
        /// <param name="unit"></param>
        /// <param name="totalFee"></param>
        /// <param name="flowSheet"></param>
        /// <returns></returns>
        public virtual async Task BuildFeeHistory(Unit unit, decimal totalFee, FlowSheet flowSheet)
        {
            unit.Fee += totalFee;
            var unitFeeHistory = new UnitFeeHistory()
            {
                UnitId         = unit.Id,
                Fee            = totalFee,
                RemainFee      = unit.Fee + unit.StartFee,//当前总结余,
                ChangeType     = flowSheet.ChangeType,
                FlowSheetId    = flowSheet.Id,
                RelCompanyName = flowSheet.GetPropertyValue <string>("RelCompanyName")
            };

            await Resolve <UnitFeeHistoryManager>().InsertAsync(unitFeeHistory);
        }
Exemplo n.º 12
0
        public override async Task <IEnumerable <ModuleButton> > GetFlowBtns(FlowSheet flowSheet)
        {
            var btns = new List <ModuleButton>();

            //if (flowSheet.GetPropertyValue<string>("OrderStatus") == "待审核")
            if (flowSheet.OrderStatus == "待出库" || flowSheet.OrderStatus == "待审核")
            {
                btns.Add(new ModuleButton()
                {
                    ButtonKey  = "backToCart",
                    ButtonName = "放回购物车修改",
                    ConfirmMsg = "确认将订单放回购物车?此订单将失效"
                });
            }
            return(btns);
        }
Exemplo n.º 13
0
        public override async Task HandleRevert(FlowSheet flowSheet)
        {
            var accountId      = flowSheet.GetPropertyValue <int>("AccountId");
            var totalFee       = flowSheet.GetPropertyValue <decimal>("Fee");
            var relCompanyName = flowSheet.GetPropertyValue <string>("RelCompanyName");
            //往来单位金额变动
            await UnitManager.ChangeFee(flowSheet.UnitId.Value, accountId, -totalFee, flowSheet, relCompanyName);

            //将对应的支票设置为收入退回
            if (flowSheet.GetPropertyValue <string>("PayType") == GetPayTypeName(2))
            {
                var feeCheckId = flowSheet.GetPropertyValue <int>("FeeCheckId");
                var feeCheck   = await FeeCheckManager.GetByIdAsync(feeCheckId);

                feeCheck.CheckStatus = CheckStatus.收入退票;
            }
        }
Exemplo n.º 14
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 MaterialBuyManager.Back(unitId, startDate, materialId, storeId, number, flowSheet);

                    //产生退货数据
                    var materialBuyBack = new MaterialBuyBack()
                    {
                        UnitId      = unitId,
                        MaterialId  = materialId,
                        BackNumber  = number,
                        FlowSheetId = flowSheet.Id,
                        Discount    = sheetItem["discount"].ToObjectWithDefault <decimal>(),
                        Price       = sheetItem["price"].ToObjectWithDefault <decimal>(),
                    };
                    await MaterialBuyBackManager.InsertAsync(materialBuyBack);
                }
            }
        }
Exemplo n.º 15
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);
            }
        }
Exemplo n.º 16
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);
            }
        }
Exemplo n.º 17
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;
            //foreach (var sheetItem in sheetData["body"])
            //{
            //    var materialId = Convert.ToInt32(sheetItem["id"]);//对应的物料Id

            //    var number = sheetItem["number"].ToObjectWithDefault<int>();//数量

            //    await StoreMaterialManager.CountMaterial(storeId, materialId, -number, flowSheet);

            //}
        }
Exemplo n.º 18
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 outStoreId = sheetHeader["outStoreId"].ToObject <int>(); //调出仓库id;
            var inStoreId  = sheetHeader["inStoreId"].ToObject <int>();  //调入仓库id;

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

                var number = sheetItem["number"].ToObjectWithDefault <int>(); //调拨数量

                await StoreMaterialManager.TransferMaterial(inStoreId, outStoreId, materialId, number, flowSheet);
            }
        }
Exemplo n.º 19
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.Remarks = sheetHeader["remarks"].ToObjectWithDefault <string>();
            var unitId         = sheetHeader["unitId"].ToObject <int>();                //代理id;
            var accountId      = sheetHeader["accountId"].ToObjectWithDefault <int?>(); //账号id;
            var payType        = sheetHeader["payType"].ToObject <int>();
            var totalFee       = sheetHeader["totalFee"].ToObject <decimal>();          //
            var relCompanyName = sheetHeader["relCompanyName"]?.ToObject <string>();

            flowSheet.UnitId = unitId;
            flowSheet.SetPropertyValue("Fee", totalFee);
            flowSheet.SetPropertyValue("PayType", GetPayTypeName(payType));
            flowSheet.SetPropertyValue("RelCompanyName", relCompanyName);
            //读取对应的账号id
            if (payType == 0)
            {
                accountId = (await FeeAccountManager.GetByName(FeeAccount.StaticAccountName1)).Id;
            }
            else if (payType == 2)
            {
                accountId = (await FeeAccountManager.GetByName(FeeAccount.StaticAccountName2)).Id;
                //建立支票信息
                var feeCheck = sheetHeader["feeCheck"].ToObject <FeeCheck>();
                feeCheck.CheckStatus   = CheckStatus.收入;
                feeCheck.InFlowSheetId = flowSheet.Id;
                feeCheck.Remarks       = flowSheet.Remarks;
                var feeCheckId = await FeeCheckManager.InsertAndGetIdAsync(feeCheck);

                flowSheet.SetPropertyValue("FeeCheckId", feeCheckId);
            }
            flowSheet.SetPropertyValue("AccountId", accountId);
            //往来单位金额变动
            await UnitManager.ChangeFee(unitId, accountId.Value, totalFee, flowSheet, relCompanyName);
        }
Exemplo n.º 20
0
        public override async Task <IEnumerable <ModuleButton> > GetFlowBtns(FlowSheet flowSheet)
        {
            var btns = new List <ModuleButton>();

            if (flowSheet.OrderStatus == "待审核")
            //if (true)
            {
                btns.Add(new ModuleButton()
                {
                    ButtonKey  = "verify",
                    ButtonName = "审核",
                    ConfirmMsg = "本操作将对库存产生实际影响,确定继续吗?"
                });
                btns.Add(new ModuleButton()
                {
                    ButtonKey   = "cancel",
                    ButtonName  = "取消",
                    ButtonClass = "layui-btn-danger",
                    ConfirmMsg  = "确认取消此单据?"
                });
            }
            return(btns);
        }
Exemplo n.º 21
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>();
            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);
            }
        }
Exemplo n.º 22
0
 public override async Task HandleRevert(FlowSheet flowSheet)
 {
 }
Exemplo n.º 23
0
        /// <summary>
        /// 退货
        /// </summary>
        /// <param name="unitId"></param>
        /// <param name="startDate"></param>
        /// <param name="materialId"></param>
        /// <param name="storeId"></param>
        /// <param name="number"></param>
        /// <param name="flowSheet"></param>
        /// <returns></returns>
        public virtual async Task Back(int unitId, DateTime startDate, int materialId, int storeId, int number, FlowSheet flowSheet)
        {
            var material = await Resolve <MaterialManager>().GetByIdFromCacheAsync(materialId);

            var toDoNumber   = number;
            var materialBuys = await GetAll().Where(new MaterialBuySpecification(unitId, startDate))
                               .Where(o => o.MaterialId == materialId)
                               .ToListAsync();

            foreach (var materialBuy in materialBuys)
            {
                if (toDoNumber == 0)
                {
                    break;
                }
                else
                {
                    if (materialBuy.CanBackNumber >= toDoNumber)
                    {
                        materialBuy.BackNumber += toDoNumber;
                        toDoNumber              = 0;
                    }
                    else
                    {
                        toDoNumber            -= materialBuy.CanBackNumber;
                        materialBuy.BackNumber = materialBuy.BuyNumber;
                    }
                }
            }

            if (toDoNumber > 0)
            {
                throw new UserFriendlyException($"{material.Name}可退货数量少于{toDoNumber}");
            }

            await Resolve <StoreMaterialManager>().CountMaterial(storeId, materialId, -number, flowSheet);
        }
Exemplo n.º 24
0
        public virtual async Task BuildFeeHistory(FeeAccount account, int?unitId, decimal totalFee, FlowSheet flowSheet, string targetCompany = "")
        {
            account.Fee += totalFee;
            var feeAccountHistory = new FeeAccountHistory()
            {
                FeeAccountId = account.Id,
                Fee          = totalFee,
                UnitId       = unitId,
                RemainFee    = account.Fee + account.StartFee,//当前总结余,
                FeeDirection = totalFee > 0?FeeDirection.进:FeeDirection.出,
                ChangeType   = flowSheet.ChangeType,
                FlowSheetId  = flowSheet.Id
            };

            feeAccountHistory.SetPropertyValue("RelCompanyName", targetCompany);
            await Resolve <FeeAccountHistoryManager>().InsertAsync(feeAccountHistory);
        }
Exemplo n.º 25
0
 public override Task HandleRevert(FlowSheet flowSheet)
 {
     throw new NotImplementedException();
 }
Exemplo n.º 26
0
 public static bool IsAvailableForTenant(this FlowSheet flowSheet, int tenantId)
 {
     return(flowSheet.TenantId == tenantId || flowSheet.Unit?.GetPropertyValue <int?>("TenantId") == tenantId);
 }
Exemplo n.º 27
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>();

            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);
        }
Exemplo n.º 28
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"];

            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);
                }
            }
        }
Exemplo n.º 29
0
        /// <summary>
        /// 销售出货,此操作不改变库存
        /// </summary>
        /// <param name="unitId"></param>
        /// <param name="materialSellId"></param>
        /// <param name="storeId"></param>
        /// <param name="number"></param>
        /// <param name="flowSheet"></param>
        /// <returns></returns>
        public virtual async Task Out(int unitId, int materialSellId, int storeId, int number, FlowSheet flowSheet)
        {
            var materialSell = await GetByIdAsync(materialSellId);

            materialSell.OutNumber += number;
        }
Exemplo n.º 30
0
        public override async Task <IEnumerable <ModuleButton> > GetFlowBtns(FlowSheet flowSheet)
        {
            var btns = new List <ModuleButton>();

            btns.Add(new ModuleButton()
            {
                ButtonKey   = "print",
                ButtonName  = "打印",
                ButtonClass = "layui-btn-normal"
            });
            if (flowSheet.OrderStatus == "待审核")
            {
                //btns.Add(new ModuleButton()
                //{
                //    ButtonKey = "backToCart",
                //    ButtonName = "放回购物车",
                //    ConfirmMsg="确认将订单放回购物车?此订单将失效"
                //});
                if (CurrentUser.Id == flowSheet.CreatorUserId && !CurrentUser.IsCenterUser)
                {
                    btns.Add(new ModuleButton()
                    {
                        ButtonKey  = "modify",
                        ButtonName = "保存修改",
                        ConfirmMsg = "确认修改此单据?"
                    });
                }
                if (CurrentUser.IsCenterUser)
                {
                    btns.Add(new ModuleButton()
                    {
                        ButtonKey  = "verify",
                        ButtonName = "审核",
                        ConfirmMsg = "确认审核通过此订单?"
                    });
                }
                if (CurrentUser.Id == flowSheet.CreatorUserId || CurrentUser.IsCenterUser)
                {
                    btns.Add(new ModuleButton()
                    {
                        ButtonKey   = "cancel",
                        ButtonName  = "取消本单",
                        ButtonClass = "layui-btn-danger",
                        ConfirmMsg  = "确认取消此单据?"
                    });
                }
            }
            else if (flowSheet.OrderStatus == "待发货" && CurrentUser.IsCenterUser)
            {
                btns.Add(new ModuleButton()
                {
                    ButtonKey  = "send",
                    ButtonName = "发货",
                    ConfirmMsg = "确认发货?"
                });
            }
            else if (flowSheet.OrderStatus == "已发货" && CurrentUser.IsCenterUser)
            {
                btns.Add(new ModuleButton()
                {
                    ButtonKey  = "genPRH",
                    ButtonName = "生成入库单",
                    ConfirmMsg = "确认生成入库单?"
                });
                btns.Add(new ModuleButton()
                {
                    ButtonKey  = "back",
                    ButtonName = "退货",
                    ConfirmMsg = "确认退货?"
                });
            }
            return(btns);
        }