public void Execute(JobRunContext context)
        {
            DetachedCriteria criteria = DetachedCriteria.For(typeof(CycleCount));

            criteria.Add(Expression.Eq("Status", BusinessConstants.CODE_MASTER_STATUS_VALUE_SUBMIT));
            criteria.Add(Expression.Not(Expression.Eq("CreateUser", "su")));
            IList <CycleCount> cycleCountList = criteriaMgr.FindAll <CycleCount>(criteria);

            if (cycleCountList.Count > 0)
            {
                int count = 0;
                foreach (CycleCount cycleCount in cycleCountList)
                {
                    if (count < 10)
                    {
                        cycleCountMgr.ProcessCycleCountResult(cycleCount.Code, userMgr.GetMonitorUser());
                        count++;
                    }
                    else
                    {
                        break;
                    }
                }
            }
        }
        public void CreateTransportationActBill(TransportPriceListDetail priceListDetail)
        {
            TransportationActBill actBill = new TransportationActBill();

            actBill.BillAddress = billAddressMgr.GetDefaultBillAddress(priceListDetail.TransportPriceList.Party.Code);

            if (actBill.BillAddress == null)
            {
                throw new BusinessErrorException("Transportation.Error.CarrierPrimaryBillAddressEmpty");
            }

            actBill.PriceListDetail = priceListDetail;
            actBill.PriceList       = priceListDetail.TransportPriceList;
            actBill.UnitPrice       = priceListDetail.UnitPrice * (1 + priceListDetail.ServiceCharge);
            actBill.TransType       = BusinessConstants.TRANSPORTATION_PRICELIST_DETAIL_TYPE_WAREHOUSELEASE;

            actBill.BillQty               = 1;
            actBill.BillAmount            = actBill.BillQty * actBill.UnitPrice;
            actBill.Currency              = priceListDetail.Currency;
            actBill.EffectiveDate         = DateTime.Now.Date;
            actBill.CreateDate            = DateTime.Now;
            actBill.CreateUser            = userMgr.GetMonitorUser();
            actBill.IsIncludeTax          = priceListDetail.IsIncludeTax;
            actBill.IsProvisionalEstimate = priceListDetail.IsProvisionalEstimate;
            actBill.LastModifyDate        = DateTime.Now;
            actBill.LastModifyUser        = userMgr.GetMonitorUser();
            actBill.Status  = BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE;
            actBill.TaxCode = priceListDetail.TaxCode;

            CreateTransportationActBill(actBill);
        }
Exemple #3
0
 public override void CreateRegion(Region entity)
 {
     CreateRegion(entity, userMgr.GetMonitorUser());
 }
Exemple #4
0
        public void RunMes()
        {
            #region 找到所有Mes的生产线,默认一个生产线对应一个线边库位
            log.Info("Flow begin.");
            DetachedCriteria fCriteria = DetachedCriteria.For <Flow>();
            fCriteria.Add(Expression.Eq("Type", BusinessConstants.CODE_MASTER_FLOW_TYPE_VALUE_PRODUCTION));
            fCriteria.Add(Expression.Eq("FlowStrategy", BusinessConstants.CODE_MASTER_FLOW_STRATEGY_VALUE_MES));
            fCriteria.Add(Expression.Eq("IsActive", true));
            fCriteria.Add(Expression.Or(Expression.Le("NextWinTime", DateTime.Now), Expression.IsNull("NextWinTime")));
            IList <Flow> flowList = criteriaMgr.FindAll <Flow>(fCriteria);
            log.Info("Flow end.");
            #endregion

            #region 找到所有Mes的移库路线
            log.Info("TransferFlow begin.");
            DetachedCriteria tCriteria = DetachedCriteria.For <FlowDetail>();
            tCriteria.CreateAlias("Flow", "f");
            tCriteria.Add(Expression.Eq("f.Type", BusinessConstants.CODE_MASTER_FLOW_TYPE_VALUE_TRANSFER));
            tCriteria.Add(Expression.Eq("f.IsActive", true));
            tCriteria.Add(Expression.Ge("f.IsMes", true));
            IList <FlowDetail> transferFlowList = criteriaMgr.FindAll <FlowDetail>(tCriteria);
            log.Info("TransferFlow end.");
            #endregion

            #region 找到所有货架和活动工单
            log.Info("Shelf begin.");
            IList <Shelf> shelfList = shelfMgr.GetAllShelf();
            log.Info("Shelf end.");

            log.Info("ActiveOrder begin.");
            DetachedCriteria oCriteria = DetachedCriteria.For(typeof(OrderLocationTransaction));
            oCriteria.CreateAlias("OrderDetail", "od");
            oCriteria.CreateAlias("od.OrderHead", "oh");
            oCriteria.Add(Expression.In("oh.Status", new string[] { BusinessConstants.CODE_MASTER_STATUS_VALUE_INPROCESS, BusinessConstants.CODE_MASTER_STATUS_VALUE_SUBMIT }));
            oCriteria.Add(Expression.Eq("TransactionType", BusinessConstants.CODE_MASTER_LOCATION_TRANSACTION_TYPE_VALUE_ISS_WO));
            oCriteria.Add(Expression.Gt("Cartons", 0));
            oCriteria.Add(Expression.IsNotNull("Shelf"));
            IList <OrderLocationTransaction> orderLocTransList = criteriaMgr.FindAll <OrderLocationTransaction>(oCriteria);
            log.Info("ActiveOrder end.");

            IDictionary <string, int> rawDemandDic        = new Dictionary <string, int>();
            IDictionary <string, int> nonZeroRawDemandDic = new Dictionary <string, int>();
            #endregion


            #region 找到所有库存
            log.Info("Inventory begin.");
            string hql = @"select h.Location, h.Item.Code,Count(h.HuId)
                    from Hu as h 
                    where h.Status = ? and h.IsMes = ? 
                    group by h.Location, h.Item.Code";

            IList <object[]> invList = hqlMgr.FindAll <object[]>(hql,
                                                                 new Object[] {
                BusinessConstants.CODE_MASTER_STATUS_VALUE_INPROCESS,
                true
            });

            log.Info("Inventory end.");

            #endregion

            #region 获取实时库存和在途,只有待发,全部为一步移库无待收
            log.Info("ToShip begin.");
            hql = @"select olt.Location.Code, olt.Item.Code,olt.Cartons
                    from OrderLocationTransaction as olt 
                    join olt.OrderDetail as od
                    join od.OrderHead as oh
                    where oh.Status in (?, ?) and oh.SubType = ? and  oh.Type=? and olt.IOType = ? and oh.IsMes = ?
                    and olt.Cartons > 0";

            IList <object[]> expectTransitInvList = hqlMgr.FindAll <object[]>(hql,
                                                                              new Object[] {
                BusinessConstants.CODE_MASTER_STATUS_VALUE_SUBMIT,
                BusinessConstants.CODE_MASTER_STATUS_VALUE_INPROCESS,
                BusinessConstants.CODE_MASTER_ORDER_SUB_TYPE_VALUE_NML,
                BusinessConstants.CODE_MASTER_ORDER_TYPE_VALUE_TRANSFER,       //只考虑移库
                BusinessConstants.IO_TYPE_IN,
                true
            });
            log.Info("ToShip end.");

            IList <object[]> totalInvList = new List <object[]>();
            if (invList != null)
            {
                totalInvList = totalInvList.Union(invList).ToList();
            }
            if (expectTransitInvList != null)
            {
                totalInvList = totalInvList.Union(expectTransitInvList).ToList();
            }
            #endregion

            if (flowList != null && flowList.Count > 0)
            {
                foreach (Flow flow in flowList)
                {
                    #region 对每个生产线找到下面的货架
                    IList <Shelf> flowShelfList = shelfList.Where(s => s.ProductLine.Code == flow.Code).ToList();
                    #endregion

                    #region 计算总的毛需求
                    if (flowShelfList != null && flowShelfList.Count > 0)
                    {
                        foreach (Shelf shelf in flowShelfList)
                        {
                            #region 货架找到对应的活动工单
                            IList <OrderLocationTransaction> shelfOrderLocTransList = orderLocTransList.Where(l => l.Shelf.Trim().ToUpper() == shelf.Code.Trim().ToUpper()).OrderByDescending(l => l.OrderDetail.OrderHead.StartTime).ToList();
                            if (shelfOrderLocTransList != null && shelfOrderLocTransList.Count > 0)
                            {
                                int count = shelf.Capacity;
                                foreach (OrderLocationTransaction ol in shelfOrderLocTransList)
                                {
                                    if (rawDemandDic.ContainsKey(ol.Item.Code))
                                    {
                                        rawDemandDic[ol.Item.Code] += ol.Cartons <= count ? ol.Cartons : count;
                                    }
                                    else
                                    {
                                        rawDemandDic.Add(ol.Item.Code, ol.Cartons <= count ? ol.Cartons : count);
                                    }
                                    count -= ol.Cartons <= count ? ol.Cartons : count;
                                    if (count == 0)
                                    {
                                        break;
                                    }
                                }
                            }
                            #endregion
                        }
                    }
                    #endregion

                    #region 计算净需求,和整个库位比较
                    foreach (string item in rawDemandDic.Keys)
                    {
                        var locQty = totalInvList.Where(h => (string)h[0] == flow.LocationFrom.Code && (string)h[1] == item).Sum(h => Convert.ToInt32(h[2]));

                        int requireQty = rawDemandDic[item] > locQty ? rawDemandDic[item] - locQty : 0;
                        if (rawDemandDic[item] > 0)
                        {
                            nonZeroRawDemandDic.Add(item, requireQty);
                        }
                    }
                    #endregion


                    #region 生成要货单

                    var q = from l in transferFlowList
                            where l.DefaultLocationTo.Code == flow.LocationFrom.Code &&
                            nonZeroRawDemandDic.Keys.ToArray <string>().Contains(l.Item.Code)
                            group l by new { l.Flow } into g
                        select new { g.Key };

                    foreach (var f in q)
                    {
                        try
                        {
                            OrderHead oh = orderMgr.TransferFlow2Order(f.Key.Flow);
                            oh.StartTime  = DateTime.Now;
                            oh.WindowTime = DateTime.Now.AddHours(Convert.ToDouble(f.Key.Flow.LeadTime));
                            oh.Priority   = BusinessConstants.CODE_MASTER_ORDER_PRIORITY_VALUE_NORMAL;
                            IList <OrderDetail> nonZeroOrderDetailList = new List <OrderDetail>();
                            foreach (OrderDetail od in oh.OrderDetails)
                            {
                                if (nonZeroRawDemandDic.Count > 0)
                                {
                                    var qty = (from r in nonZeroRawDemandDic where r.Key == od.Item.Code select new { Value = r.Value }).SingleOrDefault();
                                    if (qty != null && Convert.ToDecimal(qty.Value) > 0)
                                    {
                                        OrderDetail newOrderDetail = od;
                                        newOrderDetail.OrderedQty  = Convert.ToDecimal(qty.Value) * od.UnitCount;
                                        newOrderDetail.RequiredQty = Convert.ToDecimal(qty.Value) * od.UnitCount;
                                        nonZeroOrderDetailList.Add(newOrderDetail);
                                        nonZeroRawDemandDic.Remove(od.Item.Code);
                                    }
                                }
                            }
                            if (nonZeroOrderDetailList.Count > 0)
                            {
                                oh.OrderDetails = nonZeroOrderDetailList;
                                orderMgr.CreateOrder(oh, userMgr.GetMonitorUser());
                            }
                        }
                        catch (Exception e)
                        {
                            log.Error("error create order", e);
                            continue;
                        }
                    }



                    #endregion

                    #region 更新路线
                    flow.NextOrderTime = DateTime.Now.AddHours(Convert.ToDouble(flow.Interval));
                    flowMgr.UpdateFlow(flow);

                    #endregion
                }
            }
        }
 public override void CreateSupplier(Supplier entity)
 {
     CreateSupplier(entity, userMgr.GetMonitorUser());
 }
Exemple #6
0
 public override void CreateCarrier(Carrier entity)
 {
     CreateCarrier(entity, userMgr.GetMonitorUser());
 }
Exemple #7
0
        public virtual void TryRawMaterialBackflush(string flowCode)
        {
            IList <ProductLineInProcessLocationDetail> productLineIpList = this.productLineInProcessLocationDetailMgr.GetProductLineInProcessLocationDetailGroupByItem(flowCode, BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE);

            if (productLineIpList != null && productLineIpList.Count > 0)
            {
                IDictionary <string, decimal> itemQtydic = new Dictionary <string, decimal>();
                foreach (ProductLineInProcessLocationDetail plIp in productLineIpList)
                {
                    itemQtydic.Add(plIp.Item.Code, 0);
                }

                this.productLineInProcessLocationDetailMgr.RawMaterialBackflush(flowCode, itemQtydic, userMgr.GetMonitorUser());
            }
        }
        public void Execute(JobRunContext context)
        {
            string hql = @"select t.OrderNo from TransportationOrder as t where t.Status = ?";

            IList <string> orderNoList = hqlMgr.FindAll <string>(hql, BusinessConstants.CODE_MASTER_STATUS_VALUE_INPROCESS);

            if (orderNoList != null && orderNoList.Count > 0)
            {
                foreach (string orderNo in orderNoList)
                {
                    try
                    {
                        string dhql = @"select d from TransportationOrderDetail as d where d.TransportationOrder.OrderNo = ?";

                        IList <TransportationOrderDetail> transportationOrderDetailList = hqlMgr.FindAll <TransportationOrderDetail>(dhql, orderNo);
                        var q = transportationOrderDetailList.Where(t => t.InProcessLocation.Status == BusinessConstants.CODE_MASTER_STATUS_VALUE_CREATE ||
                                                                    t.InProcessLocation.Status == BusinessConstants.CODE_MASTER_STATUS_VALUE_INPROCESS);
                        if (q.ToList() == null || q.ToList().Count == 0)
                        {
                            transportationOrderMgr.CompleteTransportationOrder(orderNo, userMgr.GetMonitorUser());
                        }
                    }
                    catch (Exception ex)
                    {
                        log.Error("CalculateFixPriceList Error.", ex);
                        continue;
                    }
                }
            }
        }