//public string Inproportion(string idStr, string weightStr, string totalQtyStr, string adjQtyStr, string Location, string Item)
        public string Inproportion(string idStr, string Location, string Item)
        {
            QuotaSearchModel searchModel=new QuotaSearchModel{Location=Location,Item=Item};
            TempData["QuotaSearchModel"] = searchModel;
            try
            {
                if (string.IsNullOrEmpty(idStr))
                {
                    throw new BusinessException(Resources.EXT.ControllerLan.Con_FlowDetailCanNotBeEmpty);
                }
                string[] idArr = idStr.Split(',');
                //string[] qtyArr = adjQtyStr.Split(',');
                //string[] weightArr = weightStr.Split(',');
                //string[] totalQtyArr = totalQtyStr.Split(',');

                decimal allWeight = 0;
                decimal allTotalQty = 0;
                decimal maxProportion = 0;
                IList<FlowDetail> FlowDetailList = new List<FlowDetail>();
                FlowDetail noNeedAdjDetail = new FlowDetail();
                for (int i = 0; i < idArr.Count(); i++)
                {
                    FlowDetail flowDetail = QueryMgr.FindById<FlowDetail>(Convert.ToInt32(idArr[i]));
                    allWeight += flowDetail.MrpWeight;
                    allTotalQty += flowDetail.MrpTotal;
                    if (flowDetail.MrpTotal / flowDetail.MrpWeight > maxProportion)
                    {
                        maxProportion = flowDetail.MrpTotal / flowDetail.MrpWeight;
                        noNeedAdjDetail = flowDetail;
                    }

                    FlowDetailList.Add(flowDetail);  
                }
                FlowDetailList.Remove(noNeedAdjDetail);
                if (noNeedAdjDetail.MrpTotalAdjust != 0)
                {
                    noNeedAdjDetail.MrpTotalAdjust = 0;
                    GenericMgr.Update(noNeedAdjDetail);
                }

                foreach (var flowDetail in FlowDetailList)
                {
                    flowDetail.MrpTotalAdjust = (noNeedAdjDetail.MrpTotal * flowDetail.MrpWeight) / noNeedAdjDetail.MrpWeight - flowDetail.MrpTotal;
                    GenericMgr.Update(flowDetail);
                }

                //pickListMgr.CreatePickList(orderDetailList);
                SaveSuccessMessage(Resources.MRP.Quota.Quota_Adjusted);
                return "Succeed";
            }
            catch (BusinessException ex)
            {
                Response.TrySkipIisCustomErrors = true;
                Response.StatusCode = 500;
                Response.Write(ex.GetMessages()[0].GetMessageString());
                return string.Empty;
            }
        }
        public ActionResult List(GridCommand command, QuotaSearchModel searchModel)
        {
            if (!string.IsNullOrEmpty(searchModel.Item) && !string.IsNullOrEmpty(searchModel.Location))
            {
                TempData["QuotaSearchModel"] = searchModel;
            }

            return View();
        }
Beispiel #3
0
 public ActionResult List(GridCommand command, QuotaSearchModel searchModel)
 {
     ViewBag.ItemCode = searchModel.ItemCode;
     SearchCacheModel searchCacheModel = this.ProcessSearchModel(command, searchModel);
     //if (string.IsNullOrWhiteSpace(searchModel.ItemCode))
     //{
     //    SaveWarningMessage("物料代码不能为空。");
     //}
     ViewBag.PageSize = base.ProcessPageSize(command.PageSize);
     return View();
 }
Beispiel #4
0
        public ActionResult _AjaxList(GridCommand command, QuotaSearchModel searchModel)
        {
            TempData["GridCommand"] = command;
            //if (string.IsNullOrWhiteSpace(searchModel.ItemCode))
            //{
            //    return PartialView(new GridModel(new List<Quota>()));
            //}
            SearchStatementModel searchStatementModel = PrepareSearchStatement(command, searchModel);
            var data = GetAjaxPageData<Quota>(searchStatementModel, command);
            return PartialView(data);
            //foreach (var flowDet in data.Data)
            //{
            //    var flowMaster=this.genericMgr.FindById<FlowMaster>(flowDet.Flow);
            //    flowDet.PartyFrom = flowMaster.PartyFrom;
            //    flowDet.LocationTo = flowMaster.LocationTo;

            //    var supplier = this.genericMgr.FindById<Supplier>(flowMaster.PartyFrom);
            //    flowDet.ManufactureParty = supplier.Code;
            //    flowDet.ManufacturePartyDesc = supplier.CodeDescription;
            //    flowDet.ManufacturePartyShortCode = supplier.ShortCode;

            //    var location = this.genericMgr.FindById<Location>(flowDet.LocationTo);
            //    flowDet.SapLocation = location.SAPLocation;

            //    var item = this.genericMgr.FindById<Item>(flowDet.Item);
            //    flowDet.ItemDescription = item.Description;
            //}
            //data.Data = data.Data.OrderBy(d => d.LocationTo).ToList();
            //string locTo = string.Empty;
            //foreach (var flowDet in data.Data)
            //{
            //    var mrpWeight = data.Data.Where(d => d.LocationTo == flowDet.LocationTo).Sum(d => d.MrpWeight);
            //    if (mrpWeight > 0)
            //    {
            //        flowDet.AverageRatio = decimal.Round((Convert.ToDecimal(flowDet.MrpWeight * 100.00) / mrpWeight)).ToString() + "%";
            //    }
            //    else
            //    {
            //        flowDet.AverageRatio = "0%";
            //    }
            //    if (flowDet.LocationTo.Equals(locTo))
            //    {
            //        flowDet.LocationTo = string.Empty;
            //        flowDet.SapLocation = string.Empty;
            //    }
            //    else
            //    {
            //        locTo = flowDet.LocationTo;
            //    }
            //}
            //return PartialView(data);
        }
 public ActionResult _AjaxList(GridCommand command, QuotaSearchModel searchModel)
 {
     SearchStatementModel searchStatementModel = PrepareSearchStatement(command, searchModel);
     return PartialView(GetAjaxPageData<FlowDetail>(searchStatementModel, command));
 }
Beispiel #6
0
 public ActionResult _Update(Int32 id, Quota quota, QuotaSearchModel searchModel)
 {
     ViewBag.ItemCode = searchModel.ItemCode;
     try
     {
         if (quota.AdjQty < 0)
         {
             throw new BusinessException(" 调整数不能小于0");
         }
         Quota upQuota = this.genericMgr.FindById<Quota>(id);
         var c = this.genericMgr.FindAll<QuotaCycleQty>("select q from QuotaCycleQty as q where q.Item=?", upQuota.Item);
         if (c==null || c.Count == 0)
         {
             throw new BusinessException(string.Format(" 物料{0}没有维护配额循环量,更新失败。",quota.Item));
         }
         upQuota.AdjQty = quota.AdjQty;
         this.genericMgr.Update(upQuota);
     }
     catch (BusinessException ex)
     {
         SaveErrorMessage("修改失败。" + ex.GetMessages()[0].GetMessageString());
     }
     catch (Exception ex)
     {
         SaveErrorMessage("修改失败。" + ex.Message);
     }
     GridCommand command = (GridCommand)TempData["GridCommand"];
     TempData["GridCommand"] = command;
     SearchStatementModel searchStatementModel = PrepareSearchStatement(command, searchModel);
     var data = GetAjaxPageData<Quota>(searchStatementModel, command);
     return PartialView(data);
 }
        private SearchStatementModel PrepareSearchStatement(GridCommand command, QuotaSearchModel searchModel)
        {
            string whereStatement = string.Empty;

            IList<object> param = new List<object>();

            whereStatement = " where fd.MrpWeight!=0 and fd.LocationTo = ? and fd.Item = ?";
            param.Add(string.IsNullOrEmpty(searchModel.Location) ? string.Empty : searchModel.Location);
            param.Add(string.IsNullOrEmpty(searchModel.Item) ? string.Empty : searchModel.Item);

            string sortingStatement = HqlStatementHelper.GetSortingStatement(command.SortDescriptors);

            SearchStatementModel searchStatementModel = new SearchStatementModel();
            searchStatementModel.SelectCountStatement = selectCountStatement;
            searchStatementModel.SelectStatement = selectStatement;
            searchStatementModel.WhereStatement = whereStatement;
            searchStatementModel.SortingStatement = sortingStatement;
            searchStatementModel.Parameters = param.ToArray<object>();

            return searchStatementModel;
        }
Beispiel #8
0
 public ActionResult _AjaxCycleQtyList(GridCommand command, QuotaSearchModel searchModel)
 {
     TempData["CycleQtyGridCommand"] = command;
     //if (string.IsNullOrWhiteSpace(searchModel.ItemCode))
     //{
     //    return PartialView(new GridModel(new List<QuotaCycleQty>()));
     //}
     SearchStatementModel searchStatementModel = PrepareCycleQtySearchStatement(command, searchModel);
     return PartialView(GetAjaxPageData<QuotaCycleQty>(searchStatementModel, command));
 }
Beispiel #9
0
 private string SupplierCycleSearchStatement(QuotaSearchModel searchModel)
 {
     string searchSql = " select quota.Supplier,quota.SupplierNm,quota.SupplierShortCode,quota.Item,quota.ItemDesc,quota.RefItemCode,quota.Weight,quota.AccumulateQty,quota.AdjQty,qc.CycleQty from SCM_Quota as quota left join SCM_QuotaCycleQty as qc on quota.Item=qc.Item  where 1=1 and quota.Weight not in(0,100) ";
     if (!string.IsNullOrWhiteSpace(searchModel.ItemCode))
     {
         searchSql += string.Format(" and quota.Item in (select Item from SCM_Quota where Supplier='{0}' and Item ='{1}') ", new object[]{ CurrentUser.Code,searchModel.ItemCode});
     }
     else
     {
         searchSql += string.Format(" and quota.Item in (select Item from SCM_Quota where Supplier='{0}') ", CurrentUser.Code);
     }
     return searchSql;
 }
        public string Save(string idStr, string adjQtyStr, string Location, string Item)
        {
            QuotaSearchModel searchModel = new QuotaSearchModel { Location = Location, Item = Item };
            TempData["QuotaSearchModel"] = searchModel;
            try
            {
                if (string.IsNullOrEmpty(idStr))
                {
                    throw new BusinessException(Resources.EXT.ControllerLan.Con_FlowDetailCanNotBeEmpty);
                }
                string[] idArr = idStr.Split(',');
                string[] qtyArr = adjQtyStr.Split(',');

                for (int i = 0; i < idArr.Count(); i++)
                {
                    FlowDetail flowDetail = QueryMgr.FindById<FlowDetail>(Convert.ToInt32(idArr[i]));
                    flowDetail.MrpTotalAdjust = decimal.Parse(qtyArr[i]);
                    GenericMgr.Update(flowDetail);

                }

                //pickListMgr.CreatePickList(orderDetailList);
                SaveSuccessMessage(Resources.MRP.Quota.Quota_Saved);
                return "Succeed";
            }
            catch (BusinessException ex)
            {
                Response.TrySkipIisCustomErrors = true;
                Response.StatusCode = 500;
                Response.Write(ex.GetMessages()[0].GetMessageString());
                return string.Empty;
            }
        }
Beispiel #11
0
 public ActionResult _AjaxSupplierCycleList(GridCommand command, QuotaSearchModel searchModel)
 {
     string searchSql = SupplierCycleSearchStatement(searchModel);
     var searchResult = this.genericMgr.FindAllWithNativeSql<object[]>(searchSql);
     //quota.Supplier,quota.SupplierNm,quota.SupplierShortCode,quota.Item,quota.ItemDesc,
     //quota.RefItemCode,quota.Weight,quota.AccumulateQty,quota.AdjQty,qc.CycleQty 
     var allResult = (from tak in searchResult
                      select new Quota
                      {
                          Supplier = (string)tak[0],
                          SupplierName = (string)tak[1],
                          SupplierShortCode = (string)tak[2],
                          Item = (string)tak[3],
                          ItemDesc = (string)tak[4],
                          RefItemCode = (string)tak[5],
                          Weight = (decimal?)tak[6],
                          AccumulateQty = (decimal?)tak[7],
                          AdjQty = (decimal?)tak[8],
                          CycleQty = (decimal?)tak[9],
                      }).ToList();
     GridModel<Quota> gridModel = new GridModel<Quota>();
     gridModel.Total = allResult.Count;
     gridModel.Data = allResult.Skip((command.Page - 1) * command.PageSize).Take(command.PageSize);
     return PartialView(gridModel);
 }
Beispiel #12
0
 public void ExportSupplierXLS(QuotaSearchModel searchModel)
 {
     string searchSql = SupplierCycleSearchStatement(searchModel);
     var searchResult = this.genericMgr.FindAllWithNativeSql<object[]>(searchSql);
     //quota.Supplier,quota.SupplierNm,quota.SupplierShortCode,quota.Item,quota.ItemDesc,
     //quota.RefItemCode,quota.Weight,quota.AccumulateQty,quota.AdjQty,qc.CycleQty 
     var allResult = (from tak in searchResult
                      select new Quota
                      {
                          Supplier = (string)tak[0],
                          SupplierName = (string)tak[1],
                          SupplierShortCode = (string)tak[2],
                          Item = (string)tak[3],
                          ItemDesc = (string)tak[4],
                          RefItemCode = (string)tak[5],
                          Weight = (decimal?)tak[6],
                          AccumulateQty = (decimal?)tak[7],
                          AdjQty = (decimal?)tak[8],
                          CycleQty = (decimal?)tak[9],
                      }).ToList();
     ExportToXLS<Quota>("ExportSupplierXLS", "xls", allResult);
 }
Beispiel #13
0
 public ActionResult CycleQtyList(GridCommand command, QuotaSearchModel searchModel)
 {
     ViewBag.HaveCycleEditPermission = CurrentUser.Permissions.Where(p => p.PermissionCode == "Url_QuotaCycleQty_Edit").Count() > 0;
     ViewBag.ItemCode = searchModel.ItemCode;
     SearchCacheModel searchCacheModel = this.ProcessSearchModel(command, searchModel);
     //if (string.IsNullOrWhiteSpace(searchModel.ItemCode))
     //{
     //    SaveWarningMessage("物料代码不能为空。");
     //}
     ViewBag.PageSize = base.ProcessPageSize(command.PageSize);
     return View();
 }
Beispiel #14
0
 public ActionResult SupplierCycleList(GridCommand command, QuotaSearchModel searchModel)
 {
     SearchCacheModel searchCacheModel = this.ProcessSearchModel(command, searchModel);
     ViewBag.PageSize = 100;
     return View();
 }
Beispiel #15
0
        private SearchStatementModel PrepareCycleQtySearchStatement(GridCommand command, QuotaSearchModel searchModel)
        {
            string whereStatement = string.Empty;
            IList<object> param = new List<object>();

            HqlStatementHelper.AddEqStatement("Item", searchModel.ItemCode, "q", ref whereStatement, param);

            string sortingStatement = HqlStatementHelper.GetSortingStatement(command.SortDescriptors);

            SearchStatementModel searchStatementModel = new SearchStatementModel();
            searchStatementModel.SelectCountStatement = selectQuotaCycleQtyCountStatement;
            searchStatementModel.SelectStatement = selectQuotaCycleQtyStatement;
            searchStatementModel.WhereStatement = whereStatement;
            searchStatementModel.SortingStatement = sortingStatement;
            searchStatementModel.Parameters = param.ToArray<object>();

            return searchStatementModel;
        }
Beispiel #16
0
        public ActionResult _CycleQtyUpdate(Int32 id, QuotaCycleQty quotaCycleQty, QuotaSearchModel searchModel)
        {
            try
            {
                ViewBag.HaveCycleEditPermission = CurrentUser.Permissions.Where(p => p.PermissionCode == "Url_QuotaCycleQty_Edit").Count() > 0;
                ViewBag.ItemCode = searchModel.ItemCode;
                if (quotaCycleQty.CycleQty <= 0)
                {
                    throw new BusinessException(" 循环数不能小于等于0");
                }
                QuotaCycleQty upQuotaCycleQty = this.genericMgr.FindById<QuotaCycleQty>(id);
                var quotaList = this.genericMgr.FindAll<Quota>("select q from Quota as q where q.Item=? and Isactive=?", new object[] { upQuotaCycleQty.Item, true });
                if (quotaList == null || quotaList.Count == 0)
                {
                    throw new BusinessException(string.Format(" 物料编号{0}没有维护有效的调整数,请确认。 ", upQuotaCycleQty.Item));
                }
                else
                {
                    var supplierCodes = quotaList.Select(q => q.Supplier).ToArray();
                    var flowMasters = new List<FlowMaster>();
                    foreach (var supplier in supplierCodes)
                    {
                        var flowMasterBySupplier = this.genericMgr.FindAll<FlowMaster>("select f from FlowMaster as f where f.IsActive=1 and f.PartyFrom=? and exists( select 1 from FlowDetail as d where d.Flow=f.Code and d.Item=? )", new object[] { supplier, upQuotaCycleQty.Item});
                        if (flowMasterBySupplier == null || flowMasterBySupplier.Count == 0)
                        {
                            throw new BusinessException(string.Format(" 物料编号{0},供应商{1}没有找到有效的采购路线,请确认。 ", upQuotaCycleQty.Item, supplier));
                        }
                        else
                        {
                            flowMasters.Add(flowMasterBySupplier.First());
                        }
                    }
                    var locTos = flowMasters.Select(f => f.LocationTo).ToList();
                    var flowMasterGrooups = (from tak in flowMasters
                                             group tak by tak.PartyFrom
                                                 into result
                                                 select new
                                                 {
                                                     Supplier = result.Key,
                                                     FlowMasters = result.ToList()
                                                 });

                    foreach (var groups in flowMasterGrooups)
                    {
                        foreach (var locTo in locTos)
                        {
                            if (groups.FlowMasters.Where(f => f.LocationTo == locTo).Count() == 0)
                            {
                                throw new BusinessException(string.Format(" 物料编号{0},供应商{1}目的库位{2}没有找到有效的采购路线,与其他供应商不一致,请确认。 ", upQuotaCycleQty.Item, groups.FlowMasters.First().PartyFrom, locTo));
                            }
                        }
                    }
                }
                upQuotaCycleQty.CycleQty = quotaCycleQty.CycleQty;
                this.genericMgr.Update(upQuotaCycleQty);
            }
            catch (BusinessException ex)
            {
                SaveErrorMessage("修改失败。" + ex.GetMessages()[0].GetMessageString());
            }
            catch (Exception ex)
            {
                SaveErrorMessage("修改失败。" + ex.Message);
            }
            ViewBag.HaveCycleEditPermission = CurrentUser.Permissions.Where(p => p.PermissionCode == "Url_QuotaCycleQty_Edit").Count() > 0;
            GridCommand command = (GridCommand)TempData["CycleQtyGridCommand"];
            TempData["CycleQtyGridCommand"] = command;
            SearchStatementModel searchStatementModel = PrepareCycleQtySearchStatement(command, searchModel);
            return PartialView(GetAjaxPageData<QuotaCycleQty>(searchStatementModel, command));
        }
Beispiel #17
0
 public ActionResult _CycleQtyDelete(Int32 id, QuotaSearchModel searchModel)
 {
     try
     {
         ViewBag.HaveCycleEditPermission = CurrentUser.Permissions.Where(p => p.PermissionCode == "Url_QuotaCycleQty_Edit").Count() > 0;
         ViewBag.ItemCode = searchModel.ItemCode;
         this.genericMgr.DeleteById<QuotaCycleQty>(id);
         SaveSuccessMessage("删除成功。");
     }
     catch (BusinessException ex)
     {
         SaveErrorMessage("删除失败。" + ex.GetMessages()[0].GetMessageString());
     }
     catch (Exception ex)
     {
         SaveErrorMessage("删除失败。" + ex.Message);
     }
     ViewBag.HaveCycleEditPermission = CurrentUser.Permissions.Where(p => p.PermissionCode == "Url_QuotaCycleQty_Edit").Count() > 0;
     GridCommand command = (GridCommand)TempData["CycleQtyGridCommand"];
     TempData["CycleQtyGridCommand"] = command;
     SearchStatementModel searchStatementModel = PrepareCycleQtySearchStatement(command, searchModel);
     return PartialView(GetAjaxPageData<QuotaCycleQty>(searchStatementModel, command));
 }