예제 #1
0
        /// <summary>
        /// 发货单上的数量
        /// </summary>
        /// <param name="taskId"></param>
        /// <param name="pumpDate"></param>
        /// <returns></returns>
        public decimal?getShipSum(string taskId, DateTime?pumpDate)
        {
            ShippingDocumentService sdserv = new ShippingDocumentService(this.m_UnitOfWork);

            return(sdserv.Query()
                   .Where(s => s.TaskID == taskId && s.IsEffective == true)
                   .Where(s => s.ProduceDate > Convert.ToDateTime(pumpDate) &&
                          s.ProduceDate < Convert.ToDateTime(pumpDate).AddDays(1))
                   .Select(s => s.ParCube)
                   .Cast <decimal?>()
                   .Sum());
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="entity"></param>
        public void CompareShipAndPump(PumpWork entity)
        {
            ShippingDocumentService sdserv = new ShippingDocumentService(this.m_UnitOfWork);

            /*
             * 先找出发货单中该任务单与输入泵送日期相符的出票方量总计值,如果当天无发货,则提示错误信息
             * 若有,则与泵送作业表中该任务单已泵混凝土与砂浆总计值比较,如果超出则提示超出数值
             */
            //发货单上的数量
            decimal?shippSum = this.getShipSum(entity.TaskID, entity.PumpDate);

            //已有的混凝土泵送数量
            decimal?pumpBSum = this.Query()
                               .Where(p => p.TaskID == entity.TaskID)
                               .Where(p => p.PumpDate == Convert.ToDateTime(entity.PumpDate))
                               .Where(p => p.ID != entity.ID)
                               .Select(p => p.CustNum)
                               .Cast <decimal?>()
                               .Sum();

            //已有的砂浆泵送数量
            decimal?pumpSSum = this.Query()
                               .Where(p => p.TaskID == entity.TaskID)
                               .Where(p => p.PumpDate == Convert.ToDateTime(entity.PumpDate))
                               .Where(p => p.ID != entity.ID)
                               .Select(p => p.SlurryCustNum)
                               .Cast <decimal?>()
                               .Sum();

            //未泵数量
            shippSum = shippSum == null ? 0 : shippSum;
            pumpBSum = pumpBSum == null ? 0 : pumpBSum;
            pumpSSum = pumpSSum == null ? 0 : pumpSSum;

            decimal?notPunp = shippSum - (pumpBSum + pumpSSum);

            if (entity.CustNum + entity.SlurryCustNum > notPunp)   //超出了数量
            {
                throw new Exception("累计泵送数量超过发货数量,发货数量:" + shippSum + ",已泵数量:" + (pumpBSum + pumpSSum) + "");
            }
        }
예제 #3
0
        /// <summary>
        /// 查询合同指定时间段内的价格项
        /// </summary>
        /// <param name="contractId"></param>
        /// <param name="beginDate"></param>
        /// <param name="endDate"></param>
        /// <param name="priceType"></param>
        /// <param name="rate"></param>
        /// <returns></returns>
        public dynamic FindValueItems(string contractId, string beginDate, string endDate, string priceType, decimal?rate)
        {
            if (IsSettlementExists(contractId, beginDate, endDate))
            {
                throw new ApplicationException(Lang.Settlement_Error_DateRangeDuplicate);
            }
            DateTime                dtBegin = Convert.ToDateTime(beginDate);
            DateTime                dtEnd   = Convert.ToDateTime(endDate);
            ContractService         conSvr  = new ContractService(this.m_UnitOfWork);
            ShippingDocumentService shipSvr = new ShippingDocumentService(this.m_UnitOfWork);

            ProduceTaskService pt = new ProduceTaskService(this.m_UnitOfWork);


            var contract = conSvr.Get(contractId);

            if (contract != null)
            {
                //查询指定范围生产过的合同明细id

                /*   var conStrengthList =  shipSvr.Query()
                 *     .Where(p => p.IsEffective == true)
                 *     .Where(p => p.ContractID == contractId
                 *         && p.ProduceDate >= dtBegin
                 *         && p.ProduceDate <= dtEnd)
                 *     .Where(p => p.ProduceTask.ContractItem != null)
                 *     .Select(p => p.ProduceTask.ContractItem)
                 *     .Distinct()
                 *     .ToList();
                 */
                //提升发货单页面效率相应修改,发货单对象没有ProduceTask关联对象,此处采用替代方法
                //modify by: Sky
                //date: 2012-12-10
                var produceTaskIds = shipSvr.Query()
                                     .Where(p => p.IsEffective == true)
                                     .Where(p => p.ContractID == contractId &&
                                            p.ProduceDate >= dtBegin &&
                                            p.ProduceDate <= dtEnd)
                                     .Select(p => p.TaskID).ToList();

                var conStrengthList = pt.Query()
                                      .Where(p => produceTaskIds.Contains(p.ID) && p.ContractItem != null)
                                      .Select(p => p.ContractItem)
                                      .Distinct()
                                      .ToList();


                //信息价
                if (priceType == ContractValuationType.InformationValue)
                {
                    var informationPrice = this.m_UnitOfWork.GetRepositoryBase <ConPrice>().Query();
                    var query            = from ci in conStrengthList
                                           join ip in informationPrice
                                           on ci.ConStrength equals ip.ConStrengthCode
                                           select new SettlementItem
                    {
                        ContractItemsID = ci.ID ?? 0,
                        //强度
                        TypeCode  = ci.ConStrength,
                        UnitPrice = ip.InfoPrice,
                        PumpPrice = ip.PumpPrice,
                        //特性
                        PriceType     = "",
                        SlurryPrice   = ip.SlurryPrice,
                        IdentityPrice = 0
                    };
                    // .Join(conStrengthList,ip=>ip.ConStrengthCode, ci=>ci.ConStrength,  (ip,ci)=>ip.ConStrengthCode==ci.ConStrength)
                    // .Select(p => new { ConStrength = p., ConcretePrice = p.InfoPrice, PumpPrice = p.PumpPrice, SlurryPrice = p.SlurryPrice, IdentityPrice = 0 })
                    //.Where(p => conStrengthList.Select(i => i.ConStrength).Contains(p.ConStrength))
                    //.OrderBy(p => p.ConStrength)
                    //.ToList();

                    return(new
                    {
                        OtherPrice = contract.OtherPrice.Select(o => new SettlementItem
                        {
                            //typecode
                            ContractItemsID = o.ID,
                            //加价项目
                            PriceType = o.PriceType,
                            //计算方式
                            TypeCode = o.CalcType,
                            UnitPrice = o.UnitPrice ?? 0
                        }),
                        PumpPrice = contract.ContractPumps.Select(o => new SettlementItem
                        {
                            ContractItemsID = 0,
                            //泵车类型
                            PriceType = o.PumpType,
                            //泵车类型
                            TypeCode = o.PumpType,
                            UnitPrice = o.PumpPrice ?? 0
                        }),
                        ItemPrice = query.ToList()
                    });
                }
                else
                {
                    return(new
                    {
                        OtherPrice = contract.OtherPrice.Select(o => new SettlementItem
                        {
                            //typecode
                            ContractItemsID = o.ID,
                            //加价项目
                            PriceType = o.PriceType,
                            //计算方式
                            TypeCode = o.CalcType,
                            UnitPrice = o.UnitPrice ?? 0
                        }),
                        PumpPrice = contract.ContractPumps.Select(o => new SettlementItem
                        {
                            ContractItemsID = 0,
                            //泵车类型
                            PriceType = o.PumpType,
                            //泵车类型
                            TypeCode = o.PumpType,
                            UnitPrice = o.PumpPrice ?? 0
                        }),
                        ItemPrice = contract.ContractItems
                                    .Where(p => conStrengthList.Select(i => i.ConStrength).Contains(p.ConStrength))
                                    .Select(p => new SettlementItem
                        {
                            ContractItemsID = p.ID ?? 0,
                            //强度
                            TypeCode = p.ConStrength,
                            UnitPrice = p.UnPumpPrice ?? 0,
                            PumpPrice = p.PumpCost ?? 0,
                            //特性
                            PriceType = string.Join(",", p.IdentitySettings.Select(t => t.IdentityName).ToArray()),
                            SlurryPrice = p.SlurryPrice ?? 0,
                            IdentityPrice = p.IdentitySettings.Sum(i => i.IdentityPrice)
                        })
                                    .ToList()
                    });
                }
            }
            return(null);
        }
예제 #4
0
        /// <summary>
        /// 整车转发
        /// </summary>
        /// <param name="sourceShipDocID">源运输单ID</param>
        /// <param name="targetTaskId">转至任务单</param>
        /// <param name="isOriginComplete">原任务单已完成(不需要转料后补)</param>
        /// <param name="isTrashOrigin">原任务单作废</param>
        /// <param name="returnReason">转发原因</param>
        /// <returns></returns>
        public ShippingDocument Forward(string sourceShipDocID, string targetTaskId, bool isOriginComplete, bool isTrashOrigin, string returnReason, out string message, string[] _carids)
        {
            var shipDocRepo         = this.m_UnitOfWork.GetRepositoryBase <ShippingDocument>();
            ShippingDocument oldDoc = shipDocRepo.Get(sourceShipDocID);
            ProduceTask      task   = this.m_UnitOfWork.GetRepositoryBase <ProduceTask>().Get(targetTaskId);

            message = Lang.Msg_Operate_Success;
            if (oldDoc != null && task != null)
            {
                //UNDONE: 转发方量和生产方量是否要处理
                ShippingDocument newDoc = new ShippingDocument();// oldDoc.Clone() as ShippingDocument;\

                //如果有_carids说明不光转发还要换车
                if (_carids == null || _carids.Length == 0 || string.IsNullOrEmpty(_carids[0]))
                {
                    newDoc.CarID = oldDoc.CarID;
                }
                else
                {
                    newDoc.CarID = _carids[0];
                }

                newDoc.IsEffective = true;
                newDoc.ContractID  = task.ContractID;

                newDoc.ContractName = task.Contract.ContractName;
                newDoc.CustName     = task.Contract.CustName;
                newDoc.CustomerID   = task.Contract.CustomerID;

                newDoc.CustMixpropID = task.CustMixpropID;

                newDoc.ProductLineName = oldDoc.ProductLineName;
                newDoc.ProductLineID   = oldDoc.ProductLineID;

                newDoc.DeliveryTime = DateTime.Now;
                //newDoc.ProduceDate = oldDoc.ProduceDate;
                newDoc.ProduceDate = DateTime.Now;

                newDoc.ConsMixpropID       = oldDoc.ConsMixpropID;
                newDoc.SlurryConsMixpropID = oldDoc.SlurryConsMixpropID;
                newDoc.FormulaName         = oldDoc.FormulaName;
                newDoc.ProjectName         = task.ProjectName;
                newDoc.ProjectAddr         = task.ProjectAddr;
                newDoc.ProjectID           = task.ProjectID;
                newDoc.ShipDocType         = "0";
                newDoc.ConStrength         = task.ConStrength;
                newDoc.CastMode            = task.CastMode;
                newDoc.ConsPos             = task.ConsPos;
                newDoc.ImpGrade            = task.ImpGrade;
                newDoc.ImyGrade            = task.ImyGrade;
                newDoc.ImdGrade            = task.ImdGrade;
                newDoc.CarpRadii           = task.CarpRadii;
                newDoc.CementBreed         = task.CementBreed;
                newDoc.Distance            = oldDoc.Distance;
                newDoc.RealSlump           = task.Slump;//oldDoc.RealSlump;此处换成目标工地的坍落度,保持与票面一致
                newDoc.BetonCount          = oldDoc.BetonCount;
                newDoc.SlurryCount         = oldDoc.SlurryCount;
                newDoc.OtherCube           = oldDoc.OtherCube;
                newDoc.XuCube     = oldDoc.XuCube;
                newDoc.RemainCube = oldDoc.RemainCube;


                newDoc.ShippingCube = oldDoc.ShippingCube;
                newDoc.PlanCube     = task.PlanCube;



                //调度方量 = 混凝土 + 砂浆
                newDoc.SendCube = newDoc.BetonCount + newDoc.SlurryCount;
                //出票方量 = 调度方量 + 其它方量 + 剩余方量
                decimal?parCube = newDoc.SendCube + newDoc.OtherCube + (newDoc.RemainCube ?? 0);
                newDoc.ParCube      = parCube ?? 0;
                newDoc.SignInCube   = newDoc.ParCube;
                newDoc.ScrapCube    = 0;
                newDoc.TransferCube = 0;
                newDoc.Surveyor     = oldDoc.Surveyor;

                newDoc.Operator  = oldDoc.Operator;
                newDoc.RegionID  = task.RegionID;
                newDoc.ForkLift  = task.ForkLift;
                newDoc.PlanClass = task.PlanClass;
                //newDoc.ProduceDate = DateTime.Now;
                newDoc.SupplyUnit    = task.SupplyUnit;
                newDoc.ConstructUnit = task.ConstructUnit;

                newDoc.Signer  = AuthorizationService.CurrentUserID;
                newDoc.LinkMan = task.LinkMan;
                newDoc.Tel     = task.Tel;
                //是否代外生产.
                newDoc.EntrustUnit = task.IsCommission ? task.SupplyUnit : "";
                newDoc.Remark      = string.Format("CODEADD由运输单:{0}整车转发生成", sourceShipDocID);
                newDoc.IsProduce   = oldDoc.IsProduce;

                newDoc.ID     = null;
                newDoc.TaskID = targetTaskId;

                //从最后一个发货单取得累计方量和车数
                ShippingDocumentService sdService = new ShippingDocumentService(this.m_UnitOfWork);
                ShippingDocument        doc       = sdService.Query()
                                                    .Where(p => p.TaskID == targetTaskId && p.IsEffective == true && p.ShipDocType == "0")
                                                    .OrderByDescending(p => p.BuildTime)
                                                    .FirstOrDefault();
                if (doc != null)
                {
                    newDoc.ProvidedTimes = doc.ProvidedTimes + 1;
                    newDoc.ProvidedCube  = doc.ProvidedCube + newDoc.ParCube;

                    newDoc.PumpName = doc.PumpName;
                }
                else
                {
                    newDoc.ProvidedTimes = 1;
                    newDoc.ProvidedCube  = newDoc.ParCube;
                }

                //newDoc.ProjectName = task.ProjectName;
                //newDoc.ConStrength = task.ConStrength;
                //newDoc.CastMode = task.CastMode;
                //newDoc.ConsPos = task.ConsPos;
                //newDoc.ImpGrade = task.ImpGrade;
                //newDoc.ImyGrade = task.ImyGrade;
                //newDoc.ImdGrade = task.ImdGrade;
                //newDoc.CarpRadii = task.CarpRadii;
                //newDoc.CementBreed = task.CementBreed;  
                //newDoc.ForkLift = task.ForkLift;
                //newDoc.PlanClass = task.PlanClass;
                //newDoc.ProduceDate = DateTime.Now;
                //newDoc.SupplyUnit = task.SupplyUnit;
                //newDoc.ConstructUnit = task.ConstructUnit;

                ////是否托外生产.
                //newDoc.EntrustUnit = task.IsCommission ? task.SupplyUnit : "";
                //newDoc.IsEffective = true;

                //生产登记关系转移到新发货单

                newDoc.DispatchLists = new List <DispatchList>();
                //newDoc.DispatchLists.Clear();
                //newDoc.DispatchLists = null;
                newDoc.TZRalations = null;
                foreach (var d in oldDoc.DispatchLists)
                {
                    newDoc.DispatchLists.Add(d);
                }

                //原调度关系清空
                oldDoc.DispatchLists.Clear();
                //原运输单是否作废
                oldDoc.IsEffective = !isTrashOrigin;

                //记录作废原因
                if (oldDoc.IsEffective)
                {
                    oldDoc.Remark = (string.IsNullOrEmpty(oldDoc.Remark) ? "" : oldDoc.Remark + " ") + "CODEADD整车转发";
                }
                else
                {
                    oldDoc.Remark = (string.IsNullOrEmpty(oldDoc.Remark) ? "" : oldDoc.Remark + " ") + "CODEADD整车转发作废";
                }

                //退转料记录
                TZRalation tzRelation = new TZRalation
                {
                    SourceShipDocID = oldDoc.ID,
                    SourceCube      = oldDoc.ParCube,
                    CarID           = oldDoc.CarID,
                    Driver          = oldDoc.Driver,
                    Cube            = oldDoc.ParCube,
                    ReturnType      = ZLERP.Model.Enums.ReturnType.Forward,
                    ActionType      = ZLERP.Model.Enums.ActionType.Transfer,
                    IsCompleted     = true,
                    ReturnReason    = returnReason
                };
                //UNDONE:目标任务单是否要更新已供和累计方量
                using (IGenericTransaction tx = this.m_UnitOfWork.BeginTransaction())
                {
                    try
                    {
                        oldDoc.IsProduce = false;
                        shipDocRepo.Update(oldDoc, null);
                        //this.m_UnitOfWork.Flush();
                        shipDocRepo.Add(newDoc);
                        // this.m_UnitOfWork.Flush();
                        tzRelation.TargetShipDocID = newDoc.ID;
                        //整车转发时,生产记录自动转
                        List <ProductRecord> prList = this.m_UnitOfWork.GetRepositoryBase <ProductRecord>().Query()
                                                      .Where(m => m.ShipDocID == oldDoc.ID)
                                                      .ToList();
                        foreach (ProductRecord pr in prList)
                        {
                            pr.ShipDocID = newDoc.ID;
                            this.m_UnitOfWork.GetRepositoryBase <ProductRecord>().Update(pr, null);
                        }
                        DateTime ts = DateTime.Now;
                        tzRelation.ActionTime = ts;
                        tzRelation.ActionCube = tzRelation.Cube;

                        //整车转发状态设置为3
                        tzRelation.IsLock = "3";
                        //转退料单号
                        tzRelation.TzRalationFlag = getZtlDh() + "ZC";

                        base.Add(tzRelation);
                        tx.Commit();
                        return(newDoc);
                    }
                    catch (Exception ex)
                    {
                        message = ex.Message;
                        tx.Rollback();
                        logger.Error(ex.Message, ex);
                    }
                }
            }
            return(null);
        }