Exemplo n.º 1
0
 public ActionResult Edit(string Id)
 {
     if (string.IsNullOrEmpty(Id))
     {
         return(HttpNotFound());
     }
     else
     {
         com.Sconit.Entity.SYS.CodeMaster codeMaster = base.genericMgr.FindById <com.Sconit.Entity.SYS.CodeMaster>(Id);
         return(View(codeMaster));
     }
 }
Exemplo n.º 2
0
        public override bool Equals(object obj)
        {
            CodeMaster another = obj as CodeMaster;

            if (another == null)
            {
                return(false);
            }
            else
            {
                return(this.Code == another.Code);
            }
        }
Exemplo n.º 3
0
 private long GetSpecifiedStatusOrderCount(OrderMaster orderMaster, CodeMaster.OrderStatus orderStatus)
 {
     string hql = "select count(*) as counter from OrderMaster where Type = ? and Flow = ? and Status = ? and Sequence <= ? and IsPause = ?";
     return this.genericMgr.FindAll<long>(hql, new object[] { orderMaster.Type, orderMaster.Flow, orderStatus, orderMaster.Sequence, false })[0];
 }
Exemplo n.º 4
0
        ////[Transaction(TransactionMode.Requires)]
        //private void AsyncCreateBindOrder(OrderMaster orderMaster, CodeMaster.BindType bindType)
        //{
        //    AsyncCreateBindOrderDelegate asyncDelegate = new AsyncCreateBindOrderDelegate(this.CreateBindOrder);
        //    asyncDelegate.BeginInvoke(orderMaster, bindType, SecurityContextHolder.Get(), null, null);
        //}

        //private delegate void AsyncCreateBindOrderDelegate(OrderMaster orderMaster, CodeMaster.BindType bindType, User user);

        //private void CreateBindOrder(OrderMaster orderMaster, CodeMaster.BindType bindType, User user)
        private void CreateBindOrder(OrderMaster orderMaster, CodeMaster.BindType bindType)
        {
            //SecurityContextHolder.Set(user);
            if (orderMaster.SubType == CodeMaster.OrderSubType.Normal)  //只有普通订单才支持绑定
            {
                TryLoadOrderBindings(orderMaster);

                #region 根据绑定类型
                IList<OrderBinding> orderBindingList = new List<OrderBinding>();
                if (orderMaster.OrderBindings != null && orderMaster.OrderBindings.Count > 0)
                {
                    foreach (OrderBinding orderBinding in orderMaster.OrderBindings)
                    {
                        //过滤掉已经创建订单的绑定
                        if (orderBinding.BindType == bindType && string.IsNullOrWhiteSpace(orderBinding.BindOrderNo))
                        {
                            orderBindingList.Add(orderBinding);
                        }
                    }
                }
                #endregion

                #region 创建绑定订单
                DoCreateBindingOrder(orderMaster, orderBindingList);
                #endregion
            }
        }
Exemplo n.º 5
0
        public ReceiptMaster TransferIpGap2Receipt(IpMaster ipMaster, CodeMaster.IpGapAdjustOption ipGapAdjustOption)
        {
            ReceiptMaster receiptMaster = Mapper.Map<IpMaster, ReceiptMaster>(ipMaster);
            receiptMaster.Type = CodeMaster.IpDetailType.Gap;

            if (ipGapAdjustOption == CodeMaster.IpGapAdjustOption.GI)
            {
                receiptMaster.PartyFrom = ipMaster.PartyTo;
                receiptMaster.PartyFromName = ipMaster.PartyToName;
                receiptMaster.PartyTo = ipMaster.PartyFrom;
                receiptMaster.PartyToName = ipMaster.PartyFromName;
                receiptMaster.ShipFrom = ipMaster.ShipTo;
                receiptMaster.ShipFromAddress = ipMaster.ShipToAddress;
                receiptMaster.ShipFromTel = ipMaster.ShipToTel;
                receiptMaster.ShipFromCell = ipMaster.ShipToCell;
                receiptMaster.ShipFromFax = ipMaster.ShipToFax;
                receiptMaster.ShipFromContact = ipMaster.ShipToContact;
                receiptMaster.ShipTo = ipMaster.ShipFrom;
                receiptMaster.ShipToAddress = ipMaster.ShipFromAddress;
                receiptMaster.ShipToTel = ipMaster.ShipFromTel;
                receiptMaster.ShipToCell = ipMaster.ShipFromCell;
                receiptMaster.ShipToFax = ipMaster.ShipFromFax;
                receiptMaster.ShipToContact = ipMaster.ShipFromContact;
                receiptMaster.Dock = string.Empty;
            }

            foreach (IpDetail ipDetail in ipMaster.IpDetails)
            {
                ReceiptDetail receiptDetail = Mapper.Map<IpDetail, ReceiptDetail>(ipDetail);

                if (ipGapAdjustOption == CodeMaster.IpGapAdjustOption.GI)
                {
                    receiptDetail.LocationFrom = ipDetail.LocationTo;
                    receiptDetail.LocationFromName = ipDetail.LocationToName;
                    receiptDetail.LocationTo = ipDetail.LocationFrom;
                    receiptDetail.LocationToName = ipDetail.LocationFromName;
                    receiptDetail.IsInspect = false;
                }

                receiptDetail.IpDetailId = ipDetail.Id;
                receiptDetail.IpNo = ipDetail.IpNo;
                receiptDetail.IpDetailSequence = ipDetail.Sequence;
                receiptDetail.IpDetailType = ipDetail.Type;
                receiptDetail.IpGapAdjustOption = ipGapAdjustOption;

                foreach (IpDetailInput ipDetailInput in ipDetail.IpDetailInputs)
                {
                    ReceiptDetailInput receiptDetailInput = new ReceiptDetailInput();
                    receiptDetailInput.ReceiveQty = ipDetailInput.ReceiveQty;
                    receiptDetailInput.QualityType = ipDetail.QualityType;
                    //receiptDetailInput.RejectQty = ipDetailInput.RejectQty;
                    receiptDetailInput.HuId = ipDetailInput.HuId;
                    receiptDetailInput.LotNo = ipDetailInput.LotNo;
                    receiptDetailInput.IsCreatePlanBill = ipDetailInput.IsCreatePlanBill;
                    receiptDetailInput.IsConsignment = ipDetailInput.IsConsignment;
                    receiptDetailInput.PlanBill = ipDetailInput.PlanBill;
                    receiptDetailInput.ActingBill = ipDetailInput.ActingBill;
                    receiptDetailInput.IsFreeze = ipDetailInput.IsFreeze;
                    receiptDetailInput.IsATP = ipDetailInput.IsATP;
                    receiptDetailInput.OccupyType = ipDetailInput.OccupyType;
                    receiptDetailInput.OccupyReferenceNo = ipDetailInput.OccupyReferenceNo;
                    receiptDetailInput.SequenceNo = ipMaster.SequenceNo;
                    receiptDetailInput.ReceivedIpLocationDetailList = ipDetailInput.ReceivedIpLocationDetailList;

                    receiptDetail.AddReceiptDetailInput(receiptDetailInput);
                }

                receiptMaster.AddReceiptDetail(receiptDetail);
            }

            return receiptMaster;
        }
Exemplo n.º 6
0
        public string GetMrpInvIn(DateTime planVersion, CodeMaster.ResourceGroup resourceGroup, string flow, bool isShowDetail)
        {
            StringBuilder str = new StringBuilder(@"<table cellpadding='0' cellspacing='0' border='0' class='display'
                                                    id='datatable' width='100%'><tr>");

            var flowMasters = this.genericMgr.FindAll<FlowMaster>
                (" from FlowMaster where ResourceGroup = ? ", resourceGroup);
            if (!string.IsNullOrWhiteSpace(flow))
            {
                flowMasters = flowMasters.Where(p => p.Code == flow).ToList();
            }

            //var shipGroupList = this.genericMgr.FindAllIn<MrpShipPlanGroup>
            //    (" from MrpShipPlanGroup  where PlanVersion =? and StartTime>=? and Flow in (?",
            //    flowMasters.Select(p => p.Code), new object[] { planVersion, planVersion.Date });

            //var g1 = shipGroupList.GroupBy(p => p.WindowTime, (k, g) => new { k, g }).OrderBy(p => p.k);

            var shipPlanList = this.genericMgr.FindAllIn<MrpShipPlan>
                (" from MrpShipPlan  where PlanVersion =? and Flow in (?",
                flowMasters.Select(p => p.Code), new object[] { planVersion });

            var g1 = shipPlanList.GroupBy(p => p.WindowTime.Date)
                .Where(p => p.Key >= planVersion.Date)
                .OrderBy(p => p.Key);

            #region head
            str.Append("<th style=\"text-align:center\" >");
            str.Append("序号");
            str.Append("</th>");

            str.Append("<th style=\"text-align:center\" >");
            str.Append("物料号");
            str.Append("</th>");

            str.Append("<th style=\"text-align:center;min-width:150px\" >");
            str.Append("物料描述");
            str.Append("</th>");

            str.Append("<th>");
            str.Append("单位");
            str.Append("</th>");

            foreach (var g in g1)
            {
                str.Append("<th style=\"text-align:center;min-width:40px\" >");
                str.Append(g.Key.ToString("MM-dd"));
                str.Append("</th>");
            }
            str.Append("</tr>");
            #endregion

            #region body
            var g2 = shipPlanList.GroupBy(p => p.Item).OrderBy(p => p.Key)
                .Select(p => new
                {
                    Item = p.Key,
                    Dic = p.GroupBy(q => q.WindowTime.Date).ToDictionary(d => d.Key, d => d.ToList())
                }).ToList();

            int l = 0;
            foreach (var gPlan in g2)
            {
                var item = itemMgr.GetCacheItem(gPlan.Item);
                l++;
                if (l % 2 == 0)
                {
                    str.Append("<tr class=\"t-alt\">");
                }
                else
                {
                    str.Append("<tr>");
                }
                str.Append("<td>");
                str.Append(l);
                str.Append("</td>");

                str.Append("<td>");
                str.Append(item.Code);
                str.Append("</td>");

                str.Append("<td>");
                str.Append(item.FullDescription);
                str.Append("</td>");

                str.Append("<td>");
                str.Append(item.Uom);
                str.Append("</td>");

                foreach (var g in g1)
                {
                    double qty = 0;
                    StringBuilder title = new StringBuilder();
                    var plans = gPlan.Dic.ValueOrDefault(g.Key);
                    if (plans != null)
                    {
                        qty = plans.Sum(p => p.Qty);
                        if (isShowDetail)
                        {
                            title.Append("cssbody=[obbd] cssheader=[obhd] header=[库位:");
                            title.Append(plans.First().LocationTo);
                            title.Append(" 来源明细:] body=[<table width=100%>");
                            title.Append("<tr><td>区域</td><td>路线</td><td>物料</td><td>数量</td><td>类型</td></tr>");
                            foreach (var plan in plans)
                            {
                                string parentItemDescription = "-";
                                if (!string.IsNullOrWhiteSpace(plan.ParentItem))
                                {
                                    parentItemDescription = this.itemMgr.GetCacheItem(plan.ParentItem).Description;
                                }
                                title.Append("<tr><td>");
                                title.Append(string.IsNullOrWhiteSpace(plan.SourceParty) ? "-" : plan.SourceParty);
                                title.Append("</td><td>");
                                title.Append(string.IsNullOrWhiteSpace(plan.SourceFlow) ? "-" : plan.SourceFlow);
                                title.Append("</td><td>");
                                title.Append(parentItemDescription);
                                title.Append("</td><td>");
                                title.Append(plan.Qty.ToString("0.##"));
                                title.Append("</td><td>");
                                title.Append(systemMgr.GetCodeDetailDescription(CodeMaster.CodeMaster.MrpSourceType, (int)plan.SourceType));
                                title.Append("</td></tr>");
                            }
                            title.Append("</table>]");
                        }
                    }
                    str.Append(string.Format("<td style='text-align:center' title ='{1}'>{0}</td>", qty.ToString("0.##"), title.ToString()));
                }
                str.Append("</tr>");
            }
            str.Append("</table>");
            #endregion
            return str.ToString();
        }
Exemplo n.º 7
0
        public IList<MrpPlanTraceView> GetPlanTraceViewList(CodeMaster.ResourceGroup resourceGroup, string flow, string item, bool onlyShowUrgent = true)
        {
            //物料号	物料描述	最大	最小	待收	待发	当前库存
            var items = new List<string>();
            var flows = new List<string>();

            #region //根据路线得到物料明细
            var snapTime = this.genericMgr.FindAll<MrpSnapMaster>
                (@"from MrpSnapMaster m where m.IsRelease =? and m.Type=? order by m.SnapTime desc",
                new object[] { true, CodeMaster.SnapType.Mrp }, 0, 1)
                .First().SnapTime;

            var flowParam = new List<object>();
            flowParam.Add(snapTime);
            var hql = @"from MrpFlowDetail as m where m.SnapTime = ? ";
            if (!string.IsNullOrWhiteSpace(item))
            {
                items.Add(item);
                flowParam.Add(item);
                hql += " and m.Item=? ";
            }
            if (!string.IsNullOrWhiteSpace(flow))
            {
                flows.Add(flow);
            }
            else
            {
                flows = this.genericMgr.FindAll<FlowMaster>("from FlowMaster where ResourceGroup = ? ", resourceGroup)
                    .Select(p => p.Code).ToList();
            }
            hql += " and StartDate<=? and EndDate>? ";
            flowParam.Add(snapTime);
            flowParam.Add(snapTime);
            var mrpFlowDetailList = this.genericMgr.FindAll<MrpFlowDetail>(hql, flowParam);
            items = mrpFlowDetailList.Where(q => flows.Contains(q.Flow)).Select(q => q.Item).Distinct().ToList();

            var flowDetailDic = (from p in mrpFlowDetailList
                                 where items.Contains(p.Item)
                                 group p by new
                                 {
                                     Item = p.Item,
                                 } into g
                                 select new
                                 {
                                     Item = g.Key.Item,
                                     SafeStock = g.Sum(b => b.SafeStock),
                                     MaxStock = g.Sum(b => b.MaxStock),
                                 }).ToDictionary(d => d.Item, d => d);
            #endregion

            #region //期末库存
            var locationDetailViewList = this.genericMgr.FindEntityWithNativeSqlIn<LocationDetailView>(
               @"select l.* from VIEW_LocationDet as l inner join MD_Location as loc on l.Location = loc.Code 
                where loc.IsMrp = ? and l.Item in(? ", items, new object[] { true });
            var locationDetailDic = (from p in locationDetailViewList
                                     group p by new { p.Item } into g
                                     select new
                                     {
                                         Item = g.Key.Item,
                                         Qty = (double)g.Sum(q => q.ATPQty)
                                     }).ToDictionary(d => d.Item, d => d.Qty);
            #endregion

            #region //期末在途//移库
            var endTransitOrderList = (this.genericMgr.FindEntityWithNativeSqlIn<TransitOrder>
                        (@" select 
                            det.Id as Id,
                            det.OrderNo as OrderNo,
                            det.OrderDetId as OrderDetId,
                            det.IpNo as IpNo,
                            det.Flow as Flow,
                            det.OrderType as OrderType,
                            det.LocTo as Location,
                            det.Item as Item,
                            det.Qty * det.UnitQty as ShipQty,
                            det.RecQty * det.UnitQty as RecQty,
                            det.StartTime as StartTime,
                            det.Windowtime as Windowtime,
                            getdate() as SnapTime
                            from ORD_IpDet_2 as det
                            where det.IsClose = ? and det.Item in(?",
                        items, new object[] { false })).ToList();
            endTransitOrderList.AddRange(this.genericMgr.FindEntityWithNativeSqlIn<TransitOrder>
                        (@" select 
                            det.Id as Id,
                            det.OrderNo as OrderNo,
                            det.OrderDetId as OrderDetId,
                            det.IpNo as IpNo,
                            det.Flow as Flow,
                            det.OrderType as OrderType,
                            det.LocTo as Location,
                            det.Item as Item,
                            det.Qty * det.UnitQty as ShipQty,
                            det.RecQty * det.UnitQty as RecQty,
                            det.StartTime as StartTime,
                            det.Windowtime as Windowtime,
                            getdate() as SnapTime
                            from ORD_IpDet_7 as det
                            where det.IsClose = ? and det.Item in(?",
                        items, new object[] { false }));

            var endTransitOrderListDic = (from p in endTransitOrderList
                                          group p by new { p.Item } into g
                                          select new
                                          {
                                              Item = g.Key.Item,
                                              Qty = g.Sum(q => q.TransitQty)
                                          }).ToDictionary(d => d.Item, d => d.Qty);
            #endregion

            #region //得到PlanSimulationView
            var planTraceViews = (from p in mrpFlowDetailList
                                  where p.ResourceGroup == resourceGroup
                                  group p by p.Item into g
                                  select new MrpPlanTraceView
                                  {
                                      Item = g.Key,
                                      MaxStock = flowDetailDic.ValueOrDefault(g.Key) == null ? 0 : flowDetailDic.ValueOrDefault(g.Key).MaxStock,
                                      SafeStock = flowDetailDic.ValueOrDefault(g.Key) == null ? 0 : flowDetailDic.ValueOrDefault(g.Key).SafeStock,
                                      EndQty = locationDetailDic.ValueOrDefault(g.Key),
                                      EndTransQty = endTransitOrderListDic.ValueOrDefault(g.Key),
                                  }).ToList();

            if (onlyShowUrgent && string.IsNullOrWhiteSpace(item))
            {
                planTraceViews = planTraceViews
                    .Where(p => p.EndQty + p.EndTransQty > p.MaxStock || p.EndQty + p.EndTransQty < p.SafeStock)
                    .ToList();
                items = planTraceViews.Select(p => p.Item).Distinct().ToList();
            }
            #endregion

            #region //期初库存
            var inventoryBalanceList = this.genericMgr.FindAllIn<InventoryBalance>
                (@"from InventoryBalance as m where m.SnapTime = ? and m.Item in(? ", items, new object[] { snapTime });
            var inventoryBalanceDic = (from p in (inventoryBalanceList ?? new List<InventoryBalance>())
                                       group p by new { p.Item } into g
                                       select new
                                       {
                                           Item = g.Key.Item,
                                           Qty = g.Sum(q => q.Qty)
                                       }).ToDictionary(d => d.Item, d => d.Qty);
            #endregion

            #region //期初在途
            var startTransitOrderList = this.genericMgr.FindAllIn<TransitOrder>
             (@"from TransitOrder as m where m.SnapTime = ? and (m.OrderType = ? or m.OrderType =? )  and m.Item in(? ",
             items, new object[] { snapTime, CodeMaster.OrderType.Transfer, CodeMaster.OrderType.SubContractTransfer });
            var startTransitOrderDic = (from p in (startTransitOrderList ?? new List<TransitOrder>())
                                        group p by new { p.Item } into g
                                        select new
                                        {
                                            Item = g.Key.Item,
                                            Qty = g.Sum(q => q.TransitQty)
                                        }).ToDictionary(d => d.Item, d => d.Qty);
            #endregion

            #region //库存事务LocTrans,尚未考虑移库到不是MRP库位对库存的影响 //排除库内事务
            //可能原因(质量,生产,采购,销售,委外,检验,调整) 订单号 时间 库位 单位 数量
            //Item OrderNo Qty UnitQty QualityType TransType IOType LocFrom LocTo CreateDate
            var locTransList = this.genericMgr.FindAllWithNativeSqlIn<object[]>(
               @"select Item,OrderNo,Qty*UnitQty,QualityType,TransType,IOType,LocFrom,LocTo,CreateDate 
                from VIEW_LocTrans where CreateDate>=? and TransType not like ? and TransType not in(?,?,?,?) and Item in(? ",
                items,
                new object[]
                {
                    snapTime,
                    "3%",//移库等
                    CodeMaster.TransactionType.ISS_INP,          //报验出库
                    CodeMaster.TransactionType.RCT_INP,          //报验入库
                    CodeMaster.TransactionType.ISS_INP_QDII,     //检验合格出库 
                    CodeMaster.TransactionType.RCT_INP_QDII,     //检验合格入库 
                }
               );

            var planSimulationDetailViewDic = (new List<MrpPlanTraceDetailView>())
                .GroupBy(p => p.Item, (k, g) => new { Item = k, g }).ToDictionary(r => r.Item, r => r.g.ToList());

            if (locTransList != null)
            {
                planSimulationDetailViewDic = (from p in locTransList
                                               group p by p[0] into g
                                               select new
                                               {
                                                   Item = (string)g.Key,
                                                   List = (from q in g
                                                           select new MrpPlanTraceDetailView
                                                           {
                                                               Item = (string)q[0],
                                                               OrderNo = (string)q[1],
                                                               Qty = (double)((decimal)q[2]),
                                                               QualityType = (CodeMaster.QualityType)(int.Parse(q[3].ToString())),
                                                               TransType = (CodeMaster.TransactionType)(int.Parse(q[4].ToString())),
                                                               IOType = (CodeMaster.TransactionIOType)(int.Parse(q[5].ToString())),
                                                               LocationFrom = (string)q[6],
                                                               LocationTo = (string)q[7],
                                                               CreateDate = (DateTime)q[8],
                                                           }).ToList()
                                               }).ToDictionary(r => r.Item, r => r.List);
            }
            #endregion

            #region 计划收发
            var planInDic = new Dictionary<string, double>();
            var planOutDic = new Dictionary<string, double>();
            if (resourceGroup == CodeMaster.ResourceGroup.FI)
            {
                var fiShiftPlan = this.genericMgr.FindAll<MrpFiShiftPlan>
                    (@" from MrpFiShiftPlan where WindowTime between ? and ? ",
                    new object[] { snapTime, DateTime.Now });
                planInDic = (from p in fiShiftPlan
                             group p by p.Item into g
                             select new
                             {
                                 Item = g.Key,
                                 Qty = g.Sum(q => q.Qty)
                             }).ToDictionary(d => d.Item, d => d.Qty);

                var mrpPlan = this.genericMgr.FindAll<MrpPlan>
                    (@" from MrpPlan where PlanDate between ? and ? ",
                    new object[] { snapTime.Date, DateTime.Now });
                planOutDic = (from p in fiShiftPlan
                              group p by p.Item into g
                              select new
                              {
                                  Item = g.Key,
                                  Qty = g.Sum(q => q.Qty)
                              }).ToDictionary(d => d.Item, d => d.Qty);
            }
            else if (resourceGroup == CodeMaster.ResourceGroup.EX)
            {
                var exShiftPlan = this.genericMgr.FindAll<MrpExShiftPlan>
                    (@" from MrpExShiftPlan where WindowTime between ? and ? ",
                    new object[] { snapTime, DateTime.Now });
                planInDic = (from p in exShiftPlan
                             group p by p.Item into g
                             select new
                             {
                                 Item = g.Key,
                                 Qty = g.Sum(q => q.Qty)
                             }).ToDictionary(d => d.Item, d => d.Qty);

                var fiShiftPlan = this.genericMgr.FindAll<MrpFiShiftPlan>
                 (@" from MrpFiShiftPlan where WindowTime between ? and ? ",
                 new object[] { snapTime, DateTime.Now });
                planOutDic = (from p in fiShiftPlan
                              group p by p.Item into g
                              select new
                              {
                                  Item = g.Key,
                                  Qty = g.Sum(q => q.Qty)
                              }).ToDictionary(d => d.Item, d => d.Qty);

            }
            else if (resourceGroup == CodeMaster.ResourceGroup.MI)
            {
                var miShiftPlan = this.genericMgr.FindAll<MrpMiShiftPlan>
              (@" from MrpMiShiftPlan where WindowTime between ? and ? ",
              new object[] { snapTime, DateTime.Now });
                planInDic = (from p in miShiftPlan ?? new List<MrpMiShiftPlan>()
                             group p by p.Item into g
                             select new
                             {
                                 Item = g.Key,
                                 Qty = g.Sum(q => q.Qty)
                             }).ToDictionary(d => d.Item, d => d.Qty);

                var exShiftPlan = this.genericMgr.FindAll<MrpExShiftPlan>
                    (@" from MrpExShiftPlan where WindowTime between ? and ? ",
                    new object[] { snapTime, DateTime.Now });
                planOutDic = (from p in exShiftPlan ?? new List<MrpExShiftPlan>()
                              group p by p.Item into g
                              select new
                              {
                                  Item = g.Key,
                                  Qty = g.Sum(q => q.Qty)
                              }).ToDictionary(d => d.Item, d => d.Qty);
            }
            #endregion

            #region  赋值 期初库存 期初在途 库存事务(收/发)
            foreach (var plan in planTraceViews)
            {
                double startQty = 0;
                inventoryBalanceDic.TryGetValue(plan.Item, out startQty);
                plan.StartQty = startQty;

                double startTransQty = 0;
                startTransitOrderDic.TryGetValue(plan.Item, out startTransQty);
                plan.StartTransQty = startTransQty;

                List<MrpPlanTraceDetailView> detail = null;
                planSimulationDetailViewDic.TryGetValue(plan.Item, out detail);
                plan.MrpPlanTraceDetailViewList = detail;

                plan.InQty = detail != null ? detail.Where(p => p.Qty > 0).Sum(p => p.Qty) : 0;
                plan.OutQty = detail != null ? detail.Where(p => p.Qty < 0).Sum(p => p.Qty) : 0;
                plan.ItemDescription = itemMgr.GetCacheItem(plan.Item).Description;

                double planInQty = 0;
                planInDic.TryGetValue(plan.Item, out planInQty);
                plan.PlanInQty = planInQty;

                double planOutQty = 0;
                planOutDic.TryGetValue(plan.Item, out planOutQty);
                plan.PlanOutQty = planOutQty;
            }
            #endregion

            return planTraceViews;
        }
Exemplo n.º 8
0
        public Boolean CanInventoryOccupy(string supplier, string location, string item, CodeMaster.QualityType qualityType, decimal qty)
        {
            IList<LocationLotDetail> locationLotDetailList = new List<LocationLotDetail>();
            string hql = "from LocationLotDetail where Item = ? and Location = ? and HuId is null and IsFreeze = ? and Qty > 0 and QualityType = ? and OccupyType = ? order by CreateDate";
            if (!String.IsNullOrEmpty(supplier))
            {
                hql += " and ConsignmentSupplier = ? ";
                locationLotDetailList = this.genericMgr.FindAll<LocationLotDetail>(hql,
                new object[] { item, location, false, qualityType, CodeMaster.OccupyType.None, supplier });
            }
            else
            {
                locationLotDetailList = this.genericMgr.FindAll<LocationLotDetail>(hql,
                new object[] { item, location, false, qualityType, CodeMaster.OccupyType.None });
            }

            if (locationLotDetailList == null)
            {
                return false;
            }

            decimal availableQty = 0;
            for (int i = 0; i < locationLotDetailList.Count; i++)
            {
                availableQty += locationLotDetailList[i].Qty;
            }

            if (qty > availableQty)
            {
                return false;
            }
            else
            {
                return true;
            }
        }
Exemplo n.º 9
0
        public ReceiptMaster AdjustIpGap(IList<IpDetail> ipDetailList, CodeMaster.IpGapAdjustOption ipGapAdjustOption, DateTime effectiveDate)
        {
            #region 判断送货单明细是否差异类型是否合并收货
            if (ipDetailList.Where(det => det.Type == CodeMaster.IpDetailType.Normal).Count() > 0)
            {
                throw new TechnicalException("送货单差异明细类型不正确。");
            }
            #endregion

            #region 判断送货单是否合并调整
            if ((from det in ipDetailList select det.IpNo).Distinct().Count() > 1)
            {
                throw new TechnicalException("送货单不能合并调整差异。");
            }
            #endregion

            #region 判断是否全0发货
            if (ipDetailList == null || ipDetailList.Count == 0)
            {
                throw new BusinessException("收货差异调整明细不能为空。");
            }

            IList<IpDetail> nonZeroIpDetailList = ipDetailList.Where(o => o.ReceiveQtyInput != 0).ToList();

            if (nonZeroIpDetailList.Count == 0)
            {
                throw new BusinessException("收货差异调整明细不能为空。");
            }
            #endregion

            #region 查询送货单头对象
            string ipNo = (from det in ipDetailList select det.IpNo).Distinct().Single();
            IpMaster ipMaster = this.genericMgr.FindById<IpMaster>(ipNo);
            ipMaster.IpDetails = nonZeroIpDetailList;
            #endregion

            #region 查询订单头对象
            IList<OrderMaster> orderMasterList = LoadOrderMasters((from det in nonZeroIpDetailList
                                                                   select det.OrderNo).Distinct().ToArray());
            #endregion

            #region 获取收货订单类型
            IList<com.Sconit.CodeMaster.OrderType> orderTypeList = (from orderMaster in orderMasterList
                                                                    group orderMaster by orderMaster.Type into result
                                                                    select result.Key).ToList();

            if (orderTypeList.Count > 1)
            {
                throw new BusinessException(Resources.ORD.OrderMaster.Errors_CannotMixOrderTypeReceive);
            }

            com.Sconit.CodeMaster.OrderType orderType = orderTypeList.First();
            #endregion

            #region 查询送货单库存对象
            IList<IpLocationDetail> ipLocationDetailList = LoadIpLocationDetails((from det in nonZeroIpDetailList
                                                                                  select det.Id).ToArray());
            #endregion

            #region 循环检查发货明细
            foreach (IpDetail ipDetail in nonZeroIpDetailList)
            {
                #region 是否过量收货判断
                if (Math.Abs(ipDetail.ReceivedQty) >= Math.Abs(ipDetail.Qty))
                {
                    //送货单的收货数已经大于等于发货数
                    throw new BusinessException("送货单{0}行号{1}零件{2}的收货数量超出了差异数量。", ipMaster.IpNo, ipDetail.Sequence.ToString(), ipDetail.Item);
                }
                else if (!ipMaster.IsReceiveExceed && Math.Abs(ipDetail.ReceivedQty + ipDetail.ReceiveQtyInput) > Math.Abs(ipDetail.Qty))
                {
                    //送货单的收货数 + 本次收货数大于发货数
                    throw new BusinessException("送货单{0}行号{1}零件{2}的收货数量超出了差异数量。", ipMaster.IpNo, ipDetail.Sequence.ToString(), ipDetail.Item);
                }
                #endregion

                #region 差异明细是否已经关闭
                if (ipDetail.IsClose)
                {
                    throw new BusinessException("送货单{0}行号{1}零件{2}已经关闭,不能进行差异调整。", ipMaster.IpNo, ipDetail.Sequence.ToString(), ipDetail.Item);
                }
                #endregion
            }
            #endregion

            #region 循环更新订单明细
            BusinessException businessException = new BusinessException();

            if (orderType != CodeMaster.OrderType.ScheduleLine)
            {
                #region 非计划协议
                #region 查询订单明细对象
                IList<OrderDetail> orderDetailList = LoadOrderDetails((from det in nonZeroIpDetailList
                                                                       where det.OrderDetailId.HasValue
                                                                       select det.OrderDetailId.Value).Distinct().ToArray());
                #endregion

                foreach (OrderDetail orderDetail in orderDetailList)
                {
                    IList<IpDetail> targetIpDetailList = (from det in nonZeroIpDetailList
                                                          where det.OrderDetailId == orderDetail.Id
                                                          select det).ToList();

                    #region 调整发货方库存
                    if (ipGapAdjustOption == CodeMaster.IpGapAdjustOption.GI)
                    {
                        //更新订单的发货数
                        orderDetail.ShippedQty -= targetIpDetailList.Sum(det => det.ReceiveQtyInput);
                        genericMgr.Update(orderDetail);
                    }
                    #endregion

                    #region 调整收货方库存
                    else
                    {
                        //更新订单的收货数
                        orderDetail.ReceivedQty += targetIpDetailList.Sum(det => det.ReceiveQtyInput);
                        genericMgr.Update(orderDetail);
                    }
                    #endregion
                }
                #endregion
            }
            else
            {
                #region 计划协议
                foreach (IpDetail ipDetail in nonZeroIpDetailList)
                {
                    decimal remainReceiveQty = ipDetail.ReceiveQtyInput;

                    if (ipGapAdjustOption == CodeMaster.IpGapAdjustOption.GI)
                    {
                        #region 调整发货方库存
                        //更新订单的发货数
                        IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq like ? and ScheduleType = ? and ShipQty > RecQty order by EndDate desc",
                                                new object[] { ipDetail.ExternalOrderNo, ipDetail.ExternalSequence + "-%", CodeMaster.ScheduleType.Firm });

                        if (scheduleOrderDetailList != null && scheduleOrderDetailList.Count > 0)
                        {
                            foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList)
                            {
                                if (remainReceiveQty > (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty))
                                {
                                    remainReceiveQty -= (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty);
                                    scheduleOrderDetail.ShippedQty = scheduleOrderDetail.ReceivedQty;
                                }
                                else
                                {
                                    scheduleOrderDetail.ShippedQty -= remainReceiveQty;
                                    remainReceiveQty = 0;
                                    break;
                                }

                                this.genericMgr.Update(scheduleOrderDetail);
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        #region 调整收货方库存
                        //更新订单的收货数
                        IList<OrderDetail> scheduleOrderDetailList = this.genericMgr.FindEntityWithNativeSql<OrderDetail>("select * from ORD_OrderDet_8 where ExtNo = ? and ExtSeq like ? and ScheduleType = ? and ShipQty > RecQty order by EndDate",
                                                new object[] { ipDetail.ExternalOrderNo, ipDetail.ExternalSequence + "-%", CodeMaster.ScheduleType.Firm });

                        if (scheduleOrderDetailList != null && scheduleOrderDetailList.Count > 0)
                        {
                            foreach (OrderDetail scheduleOrderDetail in scheduleOrderDetailList)
                            {
                                if (remainReceiveQty > (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty))
                                {
                                    remainReceiveQty -= (scheduleOrderDetail.ShippedQty - scheduleOrderDetail.ReceivedQty);
                                    scheduleOrderDetail.ReceivedQty = scheduleOrderDetail.ShippedQty;
                                }
                                else
                                {
                                    scheduleOrderDetail.ReceivedQty += remainReceiveQty;
                                    remainReceiveQty = 0;
                                    break;
                                }

                                this.genericMgr.Update(scheduleOrderDetail);
                            }
                        }
                        #endregion
                    }

                    if (remainReceiveQty > 0)
                    {
                        businessException.AddMessage(Resources.ORD.IpMaster.Errors_ReceiveQtyExcceedOrderQty, ipMaster.IpNo, ipDetail.Item);
                    }
                }
                #endregion
            }

            #region 循环IpDetail,更新收货数
            foreach (IpDetail targetIpDetail in nonZeroIpDetailList)
            {
                #region 收货输入和送货单库存明细匹配
                IList<IpLocationDetail> targetIpLocationDetailList = (from ipLocDet in ipLocationDetailList
                                                                      where ipLocDet.IpDetailId == targetIpDetail.Id
                                                                      select ipLocDet).OrderByDescending(d => d.IsConsignment).ToList();  //排序为了先匹配寄售的

                bool isContainHu = targetIpLocationDetailList.Where(ipLocDet => !string.IsNullOrWhiteSpace(ipLocDet.HuId)).Count() > 0;

                if (ipMaster.IsReceiveScanHu)
                {
                    #region 收货扫描条码
                    if (isContainHu)
                    {
                        #region 条码匹配条码
                        foreach (IpDetailInput targetIpDetailInput in targetIpDetail.IpDetailInputs)
                        {
                            IpLocationDetail matchedIpLocationDetail = targetIpLocationDetailList.Where(ipLocDet => ipLocDet.HuId == targetIpDetailInput.HuId).SingleOrDefault();
                            if (matchedIpLocationDetail != null)
                            {
                                #region 更新库存状态
                                matchedIpLocationDetail.ReceivedQty = matchedIpLocationDetail.Qty;
                                matchedIpLocationDetail.IsClose = true;
                                targetIpDetailInput.AddReceivedIpLocationDetail(matchedIpLocationDetail);

                                genericMgr.Update(matchedIpLocationDetail);
                                #endregion
                            }
                            else
                            {
                                #region 未匹配到的条码,报错
                                businessException.AddMessage("条码{0}不在送货单差异调整明细中。", targetIpDetailInput.HuId);
                                #endregion
                            }
                        }
                        #endregion
                    }
                    else
                    {
                        #region 数量匹配条码
                        IpDetail gapIpDetail = CycleMatchIpDetailInput(targetIpDetail, targetIpDetail.IpDetailInputs, targetIpLocationDetailList);
                        if (gapIpDetail != null)
                        {
                            businessException.AddMessage("送货单{0}行号{1}零件{2}差异调整不正确。", ipMaster.IpNo, targetIpDetail.Sequence.ToString(), targetIpDetail.Item);
                        }
                        #endregion
                    }
                    #endregion
                }
                else
                {
                    #region 收货不扫描条码
                    if (isContainHu)
                    {
                        #region 条码匹配数量
                        IpDetail gapIpDetail = CycleMatchIpDetailInput(targetIpDetail, targetIpDetail.IpDetailInputs, targetIpLocationDetailList);
                        if (gapIpDetail != null)
                        {
                            businessException.AddMessage("送货单{0}行号{1}零件{2}差异调整不正确。", ipMaster.IpNo, targetIpDetail.Sequence.ToString(), targetIpDetail.Item);
                        }
                        #endregion
                    }
                    else
                    {
                        #region 数量匹配数量
                        IpDetail gapIpDetail = CycleMatchIpDetailInput(targetIpDetail, targetIpDetail.IpDetailInputs, targetIpLocationDetailList);
                        if (gapIpDetail != null)
                        {
                            businessException.AddMessage("送货单{0}行号{1}零件{2}差异调整不正确。", ipMaster.IpNo, targetIpDetail.Sequence.ToString(), targetIpDetail.Item);
                        }
                        #endregion
                    }
                    #endregion
                }
                #endregion

                #region 更新IpDetail上的收货数
                targetIpDetail.ReceivedQty += targetIpDetail.ReceiveQtyInput;
                if (targetIpLocationDetailList.Where(i => !i.IsClose).Count() == 0)
                {
                    //只有所有的IpLocationDetail关闭才能关闭
                    targetIpDetail.IsClose = true;
                }
                genericMgr.Update(targetIpDetail);
                #endregion
            }
            #endregion

            if (businessException.HasMessage)
            {
                throw businessException;
            }
            #endregion

            #region 差异调整
            ReceiptMaster receiptMaster = null;
            receiptMaster = this.receiptMgr.TransferIpGap2Receipt(ipMaster, ipGapAdjustOption);
            this.receiptMgr.CreateReceipt(receiptMaster, effectiveDate);
            #endregion

            #region 尝试关闭送货单
            this.ipMgr.TryCloseIp(ipMaster);
            #endregion

            #region 尝试关闭订单
            //处理超收的不能关闭订单
            //foreach (OrderMaster orderMaster in orderMasterList)
            //{
            //    TryCloseOrder(orderMaster);
            //}
            #endregion

            return receiptMaster;
        }
Exemplo n.º 10
0
        private void SetLocationDetailIOB(LocationDetailIOB totalIob, LocationDetailIOB iob, CodeMaster.TransactionType transType, CodeMaster.QualityType qualityType, decimal qty, decimal csqty)
        {
            #region  库存事务
            /*
                other	LOC_INI	100	//库存初始化	
                issso	ISS_SO	101	//销售出库	
                issso	ISS_SO_VOID	102	//销售出库冲销	
                rctso	RCT_SO	103	//销售退货入库	
                rctso	RCT_SO_VOID	104	//销售退货入库冲销	
                rctpo	RCT_PO	201	//采购入库	
                rctpo	RCT_PO_VOID	202	//采购入库冲销	
                isspo	ISS_PO	203	//采购退货	
                isspo	ISS_PO_VOID	204	//采购退货冲销	
                rctpo	RCT_SL	205	//计划协议入库	
                rctpo	RCT_SL_VOID	206	//计划协议入库冲销	
                isspo	ISS_SL	207	//计划协议退货	
                isspo	ISS_SL_VOID	208	//计划协议退货冲销	
                isstr	ISS_TR	301	//移库出库	
                isstr	ISS_TR_VOID	302	//移库出库冲销	
                rcttr	RCT_TR	303	//移库入库	
                rcttr	RCT_TR_VOID	304	//移库入库冲销	
                isstr	ISS_TR_RTN	311	//移库退货出库	
                isstr	ISS_TR_RTN_VOID	312	//移库退货出库冲销	
                rcttr	RCT_TR_RTN	313	//移库退货入库	
                rcttr	RCT_TR_RTN_VOID	314	//移库退货入库冲销	
                issstr	ISS_STR	305	//委外移库出库	
                issstr	ISS_STR_VOID	306	//委外移库出库冲销	
                rctstr	RCT_STR	307	//委外移库入库	
                rctstr	RCT_STR_VOID	308	//委外移库入库冲销	
                issstr	ISS_STR_RTN	315	//委外移库退货出库	
                issstr	ISS_STR_RTN_VOID	316	//委外移库退货出库冲销	
                rctstr	RCT_STR_RTN	317	//委外移库退货入库	
                rctstr	RCT_STR_RTN_VOID	318	//委外移库退货入库冲销	
                isswo	ISS_WO	401	//生产出库/原材料	
                isswo	ISS_WO_VOID	402	//生产出库/原材料冲销	
                isswo	ISS_WO_BF	403	//生产投料回冲出库/出生产线	
                isswo	ISS_WO_BF_VOID	404	//生产投料回冲出库/出生产线冲销	
                rctwo	RCT_WO	405	//生产入库/成品	
                rctwo	RCT_WO_VOID	406	//生产入库/成品冲销	
                -	ISS_MIN	407	//生产投料出库	
                -	ISS_MIN_RTN	408	//生产投料退库出库	
                -	RCT_MIN	409	//生产投料入库/入生产线	
                -	RCT_MIN_RTN	410	//生产投料出库/出生产线	
                issswo	ISS_SWO	411	//委外生产出库/原材料	
                issswo	ISS_SWO_VOID	412	//委外生产出库/原材料冲销	
                issswo	ISS_SWO_BF	413	//委外生产投料回冲出库/出生产线	
                issswo	ISS_SWO_BF_VOID	414	//委外生产投料回冲出库/出生产线冲销	
                rctswo	RCT_SWO	415	//委外生产入库/成品	
                rctswo	RCT_SWO_VOID	416	//委外生产入库/成品冲销	
                -	ISS_INP	501	//报验出库	
                inp	RCT_INP	502	//报验入库	
                -	ISS_ISL	503	//隔离出库	
                inp	RCT_ISL	504	//隔离入库	
                -	ISS_INP_QDII	505	//检验合格出库	
                qdii	RCT_INP_QDII	506	//检验合格入库	
                -	ISS_INP_REJ	507	//检验不合格出库	
                rej	RCT_INP_REJ	508	//检验不合格入库	
                -	ISS_INP_CCS	509	//让步使用出库	
                css	RCT_INP_CCS	510	//让步使用入库	
                cyccnt	CYC_CNT	601	//盘点差异出入库	
                cyccnt	CYC_CNT_VOID	602	//盘点差异出入库	
                issunp	ISS_UNP	603	//计划外出库	
                issunp	ISS_UNP_VOID	604	//计划外出库冲销	
                rctunp	RCT_UNP	605	//计划外入库	
                rctunp	RCT_UNP_VOID	606	//计划外入库冲销	
                -	ISS_REP	607	//翻箱出库	
                -	RCT_REP	608	//翻箱入库	
                -	ISS_PUT	609	//上架出库	
                -	RCT_PUT	610	//上架入库	
                -	ISS_PIK	611	//下架出库	
                -	RCT_PIK	612	//下架入库	
                issiic	ISS_IIC	613	//库存物料替换出库	
                issiic	ISS_IIC_VOID	614	//库存物料替换出库冲销	
                rctiic	RCT_IIC	615	//库存物料替换入库	
                rctiic	RCT_IIC_VOID	616	//库存物料替换入库冲销	
                -	ISS_AGE	901	//老化出库	
                -	ISS_AGE_VOID	902	//老化出库冲销	
                -	RCT_AGE	903	//老化入库	
                -	RCT_AGE_VOID	904	//老化入库冲销	
                issiic	ISS_FLT	905	//过滤出库	
                issiic	ISS_FLT_VOID	906	//过滤出库冲销	
                rctiic	RCT_FLT	907	//过滤入库	
                rctiic	RCT_FLT_VOID	908	//过滤入库冲销	
                */
            #endregion

            switch (transType)
            {
                case CodeMaster.TransactionType.CYC_CNT:
                case CodeMaster.TransactionType.CYC_CNT_VOID:
                    iob.CycCnt += qty;
                    totalIob.CycCnt++;
                    break;
                case CodeMaster.TransactionType.ISS_IIC:
                case CodeMaster.TransactionType.ISS_IIC_VOID:
                    iob.IssIic += qty;
                    totalIob.IssIic++;
                    break;
                case CodeMaster.TransactionType.ISS_PO:
                case CodeMaster.TransactionType.ISS_PO_VOID:
                case CodeMaster.TransactionType.ISS_SL:
                case CodeMaster.TransactionType.ISS_SL_VOID:
                    iob.IssPo += qty;
                    totalIob.IssPo++;
                    break;
                case CodeMaster.TransactionType.ISS_SO:
                case CodeMaster.TransactionType.ISS_SO_VOID:
                    iob.IssSo += qty;
                    totalIob.IssSo++;
                    break;
                case CodeMaster.TransactionType.ISS_STR:
                case CodeMaster.TransactionType.ISS_STR_VOID:
                case CodeMaster.TransactionType.ISS_STR_RTN:
                case CodeMaster.TransactionType.ISS_STR_RTN_VOID:
                    iob.IssStr += qty;
                    totalIob.IssStr++;
                    break;
                case CodeMaster.TransactionType.ISS_SWO:
                case CodeMaster.TransactionType.ISS_SWO_VOID:
                case CodeMaster.TransactionType.ISS_SWO_BF:
                case CodeMaster.TransactionType.ISS_SWO_BF_VOID:
                case CodeMaster.TransactionType.ISS_SWO_RTN:
                case CodeMaster.TransactionType.ISS_SWO_RTN_VOID:
                    iob.IssSwo += qty;
                    totalIob.IssSwo++;
                    break;
                case CodeMaster.TransactionType.ISS_TR:
                case CodeMaster.TransactionType.ISS_TR_VOID:
                case CodeMaster.TransactionType.ISS_TR_RTN:
                case CodeMaster.TransactionType.ISS_TR_RTN_VOID:
                    iob.IssTr += qty;
                    totalIob.IssTr++;
                    break;
                case CodeMaster.TransactionType.ISS_UNP:
                case CodeMaster.TransactionType.ISS_UNP_VOID:
                    iob.IssUnp += qty;
                    totalIob.IssUnp++;
                    break;
                case CodeMaster.TransactionType.ISS_WO:
                case CodeMaster.TransactionType.ISS_WO_VOID:
                case CodeMaster.TransactionType.ISS_WO_BF:
                case CodeMaster.TransactionType.ISS_WO_BF_VOID:
                case CodeMaster.TransactionType.ISS_WO_RTN:
                case CodeMaster.TransactionType.ISS_WO_RTN_VOID:
                    iob.IssWo += qty;
                    totalIob.IssWo++;
                    break;
                case CodeMaster.TransactionType.RCT_IIC:
                case CodeMaster.TransactionType.RCT_IIC_VOID:
                    iob.RctIic += qty;
                    totalIob.RctIic++;
                    break;
                case CodeMaster.TransactionType.RCT_PO:
                case CodeMaster.TransactionType.RCT_PO_VOID:
                case CodeMaster.TransactionType.RCT_SL:
                case CodeMaster.TransactionType.RCT_SL_VOID:
                    iob.RctPo += qty;
                    totalIob.RctPo++;
                    break;
                case CodeMaster.TransactionType.RCT_SO:
                case CodeMaster.TransactionType.RCT_SO_VOID:
                    iob.RctSo += qty;
                    totalIob.RctSo++;
                    break;
                case CodeMaster.TransactionType.RCT_STR:
                case CodeMaster.TransactionType.RCT_STR_VOID:
                case CodeMaster.TransactionType.RCT_STR_RTN:
                case CodeMaster.TransactionType.RCT_STR_RTN_VOID:
                    iob.RctStr += qty;
                    totalIob.RctStr++;
                    break;
                case CodeMaster.TransactionType.RCT_SWO:
                case CodeMaster.TransactionType.RCT_SWO_VOID:
                case CodeMaster.TransactionType.RCT_SWO_RTN:
                case CodeMaster.TransactionType.RCT_SWO_RTN_VOID:
                    iob.RctSwo += qty;
                    totalIob.RctSwo++;
                    break;
                case CodeMaster.TransactionType.RCT_TR:
                case CodeMaster.TransactionType.RCT_TR_VOID:
                case CodeMaster.TransactionType.RCT_TR_RTN:
                case CodeMaster.TransactionType.RCT_TR_RTN_VOID:
                    iob.RctTr += qty;
                    totalIob.RctTr++;
                    break;
                case CodeMaster.TransactionType.RCT_UNP:
                case CodeMaster.TransactionType.RCT_UNP_VOID:
                    iob.RctUnp += qty;
                    totalIob.RctUnp++;
                    break;
                case CodeMaster.TransactionType.RCT_WO:
                case CodeMaster.TransactionType.RCT_WO_VOID:
                case CodeMaster.TransactionType.RCT_WO_RTN:
                case CodeMaster.TransactionType.RCT_WO_RTN_VOID:
                    iob.RctWo += qty;
                    totalIob.RctWo++;
                    break;
                //其他-库存初始化
                case CodeMaster.TransactionType.LOC_INI:
                    iob.Other += qty;
                    totalIob.Other++;
                    break;
                default:
                    iob.Other += qty;
                    totalIob.Other++;
                    break;
            }
            switch (qualityType)
            {
                case CodeMaster.QualityType.Inspect:
                    iob.StartInp -= qty;
                    break;
                case CodeMaster.QualityType.Qualified:
                    iob.StartNml -= qty;
                    break;
                case CodeMaster.QualityType.Reject:
                    iob.StartRej -= qty;
                    break;
            }
            iob.Start -= qty;
            iob.StartCs -= csqty;
        }
Exemplo n.º 11
0
        public IList<LocationLotDetail> CancelInventoryOccupy(CodeMaster.OccupyType occupyType, string occupyReferenceNo, IList<string> huIdList)
        {
            string hql = "from LocationLotDetail where OccupyType = ? and OccupyReferenceNo = ?";
            IList<LocationLotDetail> locationLotDetailList = this.genericMgr.FindAll<LocationLotDetail>(hql, new object[] { occupyType, occupyReferenceNo });
            locationLotDetailList = locationLotDetailList.Where(l => l.Qty > 0).ToList();

            if (huIdList != null && huIdList.Count > 0)
            {
                BusinessException businessException = new BusinessException();
                foreach (string huId in huIdList)
                {
                    LocationLotDetail locationLotDetail = locationLotDetailList.Where(l => l.HuId == huId).SingleOrDefault();
                    if (locationLotDetail == null)
                    {
                        businessException.AddMessage("条码{0}没有被订单{1}占用。", huId, occupyReferenceNo);
                    }
                }

                if (businessException.HasMessage)
                {
                    throw businessException;
                }
            }

            IList<LocationLotDetail> returnLocationLotDetailList = new List<LocationLotDetail>();
            foreach (LocationLotDetail locationLotDetail in locationLotDetailList)
            {
                if (huIdList == null || huIdList.Contains(locationLotDetail.HuId))
                {
                    locationLotDetail.OccupyType = CodeMaster.OccupyType.None;
                    locationLotDetail.OccupyReferenceNo = null;
                    this.genericMgr.Update(locationLotDetail);

                    returnLocationLotDetailList.Add(locationLotDetail);
                }
            }

            return returnLocationLotDetailList;
        }
Exemplo n.º 12
0
 public IList<LocationLotDetail> CancelInventoryOccupy(CodeMaster.OccupyType occupyType, string occupyReferenceNo)
 {
     return CancelInventoryOccupy(occupyType, occupyReferenceNo, null);
 }
Exemplo n.º 13
0
        public IList<LocationLotDetail> CancelInventoryOccupy(CodeMaster.OccupyType occupyType, string occupyNo, string supplier, string location, string item, CodeMaster.QualityType qualityType, decimal qty)
        {
            //string hql = "from LocationLotDetail where HuId is null and IsFreeze = ? and QualityType = ? and OccupyType = ? and OccupyReferenceNo = ? and Location = ? and Item = ? and Qty > 0 order by CreateDate";
            //IList<LocationLotDetail> locationLotDetailList = this.genericMgr.FindAll<LocationLotDetail>(hql,
            //    new object[] { false, qualityType, occupyType, occupyNo, location, item });

            IList<LocationLotDetail> locationLotDetailList = new List<LocationLotDetail>();
            string hql = "from LocationLotDetail where Item = ? and Location = ? and HuId is null and IsFreeze = ? and Qty > 0 and QualityType = ? and OccupyType = ? order by CreateDate";
            if (!String.IsNullOrEmpty(supplier))
            {
                hql += " and ConsignmentSupplier = ? ";
                locationLotDetailList = this.genericMgr.FindAll<LocationLotDetail>(hql,
                new object[] { item, location, false, qualityType, CodeMaster.OccupyType.None, supplier });
            }
            else
            {
                locationLotDetailList = this.genericMgr.FindAll<LocationLotDetail>(hql,
                new object[] { item, location, false, qualityType, CodeMaster.OccupyType.None });
            }

            decimal remainingCancelQty = qty;
            IList<LocationLotDetail> returnLocationLotDetailList = new List<LocationLotDetail>();
            for (int i = 0; i < locationLotDetailList.Count; i++)
            {
                if (remainingCancelQty <= 0)
                {
                    break;
                }

                if (locationLotDetailList[i].Qty > remainingCancelQty)
                {
                    decimal remainOccupied = locationLotDetailList[i].Qty - remainingCancelQty;
                    locationLotDetailList[i].Qty = remainOccupied;
                    this.genericMgr.Update(locationLotDetailList[i]);

                    LocationLotDetail cancelLld = Mapper.Map<LocationLotDetail, LocationLotDetail>(locationLotDetailList[i]);
                    cancelLld.OccupyType = CodeMaster.OccupyType.None;
                    cancelLld.OccupyReferenceNo = null;
                    cancelLld.Qty = remainingCancelQty;
                    this.genericMgr.Create(cancelLld);

                    //取消部分占用应该把remainqty置成0
                    remainingCancelQty = 0;
                    returnLocationLotDetailList.Add(cancelLld);

                    break;
                }
                else
                {
                    locationLotDetailList[i].OccupyType = CodeMaster.OccupyType.None;
                    locationLotDetailList[i].OccupyReferenceNo = null;
                    this.genericMgr.Update(locationLotDetailList[i]);

                    remainingCancelQty -= locationLotDetailList[i].Qty;
                    returnLocationLotDetailList.Add(locationLotDetailList[i]);
                }
            }

            if (remainingCancelQty > 0)
            {
                throw new BusinessException("库位{0}零件{1}的库存数不足,取消占用失败。", location, item);
            }

            return returnLocationLotDetailList;
        }
Exemplo n.º 14
0
 public ReceiptMaster AdjustIpGap(IList<IpDetail> ipDetailList, CodeMaster.IpGapAdjustOption ipGapAdjustOption)
 {
     return AdjustIpGap(ipDetailList, ipGapAdjustOption, DateTime.Now);
 }
Exemplo n.º 15
0
        public void CreateRccpPlan(CodeMaster.TimeUnit dateType, List<RccpPlanLog> rccpPlanLogList)
        {
            var flowStategyDic = new Dictionary<string, FlowStrategy>();
            var flowCodes = rccpPlanLogList.Select(p => p.Flow).Where(p => !string.IsNullOrWhiteSpace(p)).Distinct();
            if (flowCodes != null && flowCodes.Count() > 0)
            {
                flowStategyDic = this.genericMgr.FindAllIn<FlowStrategy>
                 (" from FlowStrategy where Flow in(? ", rccpPlanLogList.Select(p => p.Flow).Where(p => !string.IsNullOrWhiteSpace(p)).Distinct())
                 .ToDictionary(d => d.Flow, d => d);
            }

            var user = SecurityContextHolder.Get();
            var oldRccpPlanDic = (this.genericMgr.FindAllIn<RccpPlan>
                    ("from RccpPlan as w where w.DateType = ? and w.DateIndexTo in(?",
                    rccpPlanLogList.Select(p => p.DateIndexTo).Distinct(), new object[] { dateType }) ?? new List<RccpPlan>())
                    .GroupBy(p => p.Item, (k, g) => new { k, g }).ToDictionary(d => d.k, d => d.g.ToList());

            int planVersion = 0;
            if (dateType == CodeMaster.TimeUnit.Month)
            {
                planVersion = int.Parse(numberControlMgr.GetNextSequence(com.Sconit.Entity.MRP.BusinessConstants.NUMBERCONTROL_MONTHLYPLAN));
            }
            else if (dateType == CodeMaster.TimeUnit.Week)
            {
                planVersion = int.Parse(numberControlMgr.GetNextSequence(com.Sconit.Entity.MRP.BusinessConstants.NUMBERCONTROL_WEEKLYPLAN));
            }
            else if (dateType == CodeMaster.TimeUnit.Day)
            {
                planVersion = int.Parse(numberControlMgr.GetNextSequence(com.Sconit.Entity.MRP.BusinessConstants.NUMBERCONTROL_DAILYLYPLAN));
            }

            foreach (var rccpPlanLog in rccpPlanLogList)
            {
                string dateIndexFrom = rccpPlanLog.DateIndexTo;
                if (!string.IsNullOrWhiteSpace(rccpPlanLog.Flow))
                {
                    var flowStategy = flowStategyDic.ValueOrDefault(rccpPlanLog.Flow);
                    if (flowStategy != null)
                    {
                        decimal _leadTime = dateType == CodeMaster.TimeUnit.Day ? flowStategy.LeadTime : flowStategy.RccpLeadTime;
                        double leadTime = Math.Round(DateTimeHelper.TimeTranfer(_leadTime, flowStategy.TimeUnit, CodeMaster.TimeUnit.Day));
                        if (leadTime > 0)
                        {
                            if (dateType == CodeMaster.TimeUnit.Day)
                            {
                                dateIndexFrom = DateTime.Parse(rccpPlanLog.DateIndex).AddDays(-leadTime).ToString("yyyy-MM-dd");
                            }
                            else if (dateType == CodeMaster.TimeUnit.Week)
                            {
                                dateIndexFrom = Utility.DateTimeHelper.GetWeekOfYear(
                                    Utility.DateTimeHelper.GetWeekIndexDateFrom(rccpPlanLog.DateIndex).AddDays(3 - leadTime)
                                    );
                            }
                            else if (dateType == CodeMaster.TimeUnit.Month)
                            {
                                dateIndexFrom = DateTime.Parse(rccpPlanLog.DateIndex + "-15").AddDays(-leadTime).ToString("yyyy-MM");
                            }
                        }
                    }
                }

                var oldRccpPlans = (oldRccpPlanDic.ValueOrDefault(rccpPlanLog.Item) ?? new List<RccpPlan>())
                    .Where(p => p.DateIndex == rccpPlanLog.DateIndex && p.Flow == rccpPlanLog.Flow && p.DateType == rccpPlanLog.DateType);
                if (oldRccpPlans.Count() == 0)
                {
                    #region New RccpPlan
                    var rccpPlan = new RccpPlan();
                    rccpPlan.DateIndex = dateIndexFrom;
                    rccpPlan.DateIndexTo = rccpPlanLog.DateIndexTo;
                    rccpPlan.Item = rccpPlanLog.Item;
                    rccpPlan.Flow = rccpPlanLog.Flow;
                    rccpPlan.Qty = rccpPlanLog.Qty * (double)rccpPlanLog.UnitQty;
                    rccpPlan.PlanVersion = planVersion;
                    rccpPlan.DateType = dateType;

                    this.genericMgr.Create(rccpPlan);
                    #endregion

                    #region New RccpPlanLog
                    rccpPlanLog.PlanId = rccpPlan.Id;
                    rccpPlanLog.PlanVersion = planVersion;
                    rccpPlanLog.DateIndex = dateIndexFrom;
                    rccpPlanLog.DateType = dateType;
                    rccpPlanLog.CreateDate = System.DateTime.Now;
                    rccpPlanLog.CreateUserId = user.Id;
                    rccpPlanLog.CreateUserName = user.FullName;
                    this.genericMgr.Create(rccpPlanLog);
                    #endregion
                }
                else if (oldRccpPlans.Count() == 1)
                {
                    var oldRccpPlan = oldRccpPlans.First();
                    if (oldRccpPlan.Qty != rccpPlanLog.Qty * (double)rccpPlanLog.UnitQty
                        || oldRccpPlan.Flow != rccpPlanLog.Flow)
                    {
                        oldRccpPlan.Qty = rccpPlanLog.Qty * (double)rccpPlanLog.UnitQty;
                        oldRccpPlan.DateIndex = dateIndexFrom;
                        oldRccpPlan.PlanVersion = planVersion;
                        oldRccpPlan.Flow = rccpPlanLog.Flow;
                        this.genericMgr.Update(oldRccpPlan);

                        #region New RccpPlanLog
                        rccpPlanLog.PlanId = oldRccpPlan.Id;
                        rccpPlanLog.DateIndex = dateIndexFrom;
                        rccpPlanLog.PlanVersion = planVersion;
                        rccpPlanLog.DateType = dateType;
                        rccpPlanLog.CreateDate = System.DateTime.Now;
                        rccpPlanLog.CreateUserId = user.Id;
                        rccpPlanLog.CreateUserName = user.FullName;
                        this.genericMgr.Create(rccpPlanLog);
                        #endregion
                    }
                }
                else
                {
                    throw new TechnicalException("Error:DateException");
                }
            }
        }
Exemplo n.º 16
0
 public IList<OrderDetail> TransformFlowMster2OrderDetailList(FlowMaster flow, CodeMaster.OrderSubType orderSubType)
 {
     IList<FlowDetail> flowDetailList = flowMgr.GetFlowDetailList(flow, false, true);
     IList<OrderDetail> orderDetailList = new List<OrderDetail>();
     foreach (FlowDetail flowDetail in flowDetailList)
     {
         OrderDetail orderDetail = Mapper.Map<FlowDetail, OrderDetail>(flowDetail);
         if (orderSubType == com.Sconit.CodeMaster.OrderSubType.Return)
         {
             orderDetail.LocationFrom = string.IsNullOrWhiteSpace(flowDetail.LocationTo) ? flow.LocationTo : flowDetail.LocationTo;
             orderDetail.LocationTo = string.IsNullOrWhiteSpace(flowDetail.LocationFrom) ? flow.LocationFrom : flowDetail.LocationFrom;
         }
         else
         {
             orderDetail.LocationFrom = string.IsNullOrWhiteSpace(flowDetail.LocationFrom) ? flow.LocationFrom : flowDetail.LocationFrom;
             orderDetail.LocationTo = string.IsNullOrWhiteSpace(flowDetail.LocationTo) ? flow.LocationTo : flowDetail.LocationTo;
         }
         if (flow.Type == CodeMaster.OrderType.Production)
         {
             orderDetail.Bom = string.IsNullOrWhiteSpace(orderDetail.Bom) ? orderDetail.Item : orderDetail.Bom;
         }
         //orderDetail.Id = flowDetail.Id;
         var item = itemMgr.GetCacheItem(flowDetail.Item);
         orderDetail.ItemDescription = item.Description;
         if (string.IsNullOrWhiteSpace(orderDetail.ReferenceItemCode))
         {
             orderDetail.ReferenceItemCode = item.ReferenceCode;
         }
         orderDetailList.Add(orderDetail);
     }
     return orderDetailList;
 }
Exemplo n.º 17
0
 public void ReadRccpPlanFromXls(Stream inputStream, string startDateIndex, string endDateIndex, bool isItemRef, CodeMaster.TimeUnit dateType)
 {
     DateTime startDate = DateTime.Now;
     DateTime endDate = DateTime.Now;
     #region  判断
     if (!string.IsNullOrEmpty(startDateIndex))
     {
         if (dateType == CodeMaster.TimeUnit.Week)
         {
             startDate = DateTimeHelper.GetWeekIndexDateFrom(startDateIndex);
         }
         else if (dateType == CodeMaster.TimeUnit.Month)
         {
             startDate = DateTime.Parse(startDateIndex + "-01");
         }
         else
         {
             throw new BusinessException("不能导入此计划类型:" + dateType.ToString());
         }
     }
     if (!string.IsNullOrEmpty(endDateIndex))
     {
         if (dateType == CodeMaster.TimeUnit.Week)
         {
             endDate = DateTimeHelper.GetWeekIndexDateFrom(endDateIndex);
         }
         else
         {
             endDate = DateTime.Parse(endDateIndex + "-01");
         }
     }
     #endregion 判断
     ReadRccpPlanFromXls(inputStream, startDate, endDate, isItemRef, dateType);
 }
Exemplo n.º 18
0
        public string CreateProcurementOrderFromXls(Stream inputStream,
            string flowCode, string extOrderNo, string refOrderNo,
            DateTime startTime, DateTime windowTime, CodeMaster.OrderPriority priority)
        {
            #region 导入数据
            if (inputStream.Length == 0)
            {
                throw new BusinessException("Import.Stream.Empty");
            }

            HSSFWorkbook workbook = new HSSFWorkbook(inputStream);

            ISheet sheet = workbook.GetSheetAt(0);
            IEnumerator rows = sheet.GetRowEnumerator();

            ImportHelper.JumpRows(rows, 1);

            #region 列定义
            int colSeqNo = 0;//序号
            int colItem = 1;//物料代码
            //int colItemDescription = 2;// 物料描述
            int colQty = 3;//数量
            int colUom = 4;//单位
            int colUnitCount = 5;//单包装
            int colLocationTo = 6;//来源库位
            #endregion

            IList<OrderDetail> exactOrderDetailList = new List<OrderDetail>();

            var flowMaster = this.genericMgr.FindById<FlowMaster>(flowCode);

            var flowDetailList = this.flowMgr.GetFlowDetailList(flowCode, false, true);

            while (rows.MoveNext())
            {
                HSSFRow row = (HSSFRow)rows.Current;
                if (!ImportHelper.CheckValidDataRow(row, 1, 9))
                {
                    break;//边界
                }
                int seqNo = 0;
                string itemCode = string.Empty;
                decimal qty = 0;
                string uom = string.Empty;
                decimal unitCount = 0;
                Location locationTo = null;

                #region 读取数据

                #region 读取序号
                try
                {
                    seqNo = Convert.ToInt32(row.GetCell(colSeqNo).NumericCellValue);
                }
                catch
                {
                    seqNo = 0;
                }
                #endregion

                #region 读取物料代码
                itemCode = ImportHelper.GetCellStringValue(row.GetCell(colItem));
                if (string.IsNullOrWhiteSpace(itemCode))
                {
                    ImportHelper.ThrowCommonError(row.RowNum, colItem, row.GetCell(colItem));
                }
                #endregion

                #region 读取数量
                try
                {
                    qty = Convert.ToDecimal(row.GetCell(colQty).NumericCellValue);
                }
                catch
                {
                    ImportHelper.ThrowCommonError(row.RowNum, colQty, row.GetCell(colQty));
                }
                #endregion

                #region 读取单位
                uom = ImportHelper.GetCellStringValue(row.GetCell(colUom));
                #endregion

                #region 读取单包装
                try
                {
                    unitCount = Convert.ToDecimal(row.GetCell(colUnitCount).NumericCellValue);
                }
                catch
                {
                    unitCount = 0;
                }
                #endregion

                #region 读取目的库位
                string locationToCode = ImportHelper.GetCellStringValue(row.GetCell(colLocationTo));
                if (!string.IsNullOrWhiteSpace(locationToCode))
                {
                    locationTo = this.genericMgr.FindById<Location>(locationToCode);
                    if (locationTo.Region != flowMaster.PartyTo)
                    {
                        throw new BusinessException("库位{0}不在区域{1}下", locationTo.Code, flowMaster.PartyTo);
                    }
                }
                #endregion

                #endregion

                #region 填充数据
                var flowDetail = flowDetailList.Where(f => f.Item == itemCode && f.LocationTo == locationToCode).FirstOrDefault();
                if (flowDetail == null)
                {
                    if (flowMaster.IsManualCreateDetail)
                    {
                        flowDetail = new FlowDetail();

                        var item = this.genericMgr.FindById<Entity.MD.Item>(itemCode);
                        flowDetail.OrderQty = qty;
                        flowDetail.BaseUom = item.Uom;
                        flowDetail.Item = itemCode;
                        if (seqNo > 0)
                        {
                            flowDetail.ExternalSequence = seqNo;
                        }
                        if (!string.IsNullOrWhiteSpace(uom))
                        {
                            flowDetail.Uom = uom;
                        }
                        else
                        {
                            flowDetail.Uom = item.Uom;
                        }
                        if (unitCount > 0)
                        {
                            flowDetail.UnitCount = unitCount;
                        }
                        else
                        {
                            flowDetail.UnitCount = item.UnitCount;
                        }
                        if (locationToCode == null)
                        {
                            flowDetail.LocationTo = flowMaster.LocationTo;
                        }
                        else
                        {
                            flowDetail.LocationTo = locationTo.Code;
                        }
                    }
                    else
                    {
                        throw new BusinessException("没有找到匹配的物流路线明细", itemCode, uom, unitCount.ToString());
                    }
                }
                else
                {
                    if (seqNo > 0)
                    {
                        flowDetail.ExternalSequence = seqNo;
                    }
                    flowDetail.OrderQty = qty;
                }
                flowMaster.AddFlowDetail(flowDetail);

                #endregion
            }

            #endregion

            #region 创建要货单
            OrderMaster orderMaster = TransferFlow2Order(flowMaster, true);

            orderMaster.ReferenceOrderNo = refOrderNo;
            orderMaster.ExternalOrderNo = extOrderNo;
            orderMaster.StartTime = startTime;
            orderMaster.WindowTime = windowTime;
            orderMaster.Priority = priority;
            this.CreateOrder(orderMaster);

            #endregion

            return orderMaster.OrderNo;
        }
Exemplo n.º 19
0
        public decimal GetAvailableInventoryOccupied(CodeMaster.OccupyType occupyType, string occupyNo, string supplier, string location, string item, CodeMaster.QualityType qualityType)
        {
            string hql = "from LocationLotDetail where HuId is null and IsFreeze = ? and Qty > 0 and QualityType = ? and Item = ? and  Location = ? and OccupyType = ? and OccupyReferenceNo = ? ";

            IList<object> paramList = new List<object>();
            paramList.Add(false);
            paramList.Add((int)qualityType);
            paramList.Add(item);
            paramList.Add(location);
            paramList.Add((int)occupyType);
            paramList.Add(occupyNo);
            if (!String.IsNullOrEmpty(supplier))
            {
                hql += " and ConsignmentSupplier = ? ";
                paramList.Add(supplier);
            }
            IList<LocationLotDetail> locdetList = this.genericMgr.FindAll<LocationLotDetail>(hql, paramList.ToArray());
            if (locdetList == null)
            {
                return 0;
            }
            else
            {
                decimal totalQty = 0;
                foreach (LocationLotDetail ld in locdetList)
                {
                    totalQty += ld.Qty;
                }

                return totalQty;
            }
        }