示例#1
0
        public static MyResult IsApprovalSettlement(string PKID)
        {
            MyResult result = new MyResult();

            result.result = true;
            try
            {
                IParkSettlement     factory    = ParkSettlementFactory.GetFactory();
                ParkSettlementModel settlelist = factory.GetMaxPriodSettlement(PKID);
                if (settlelist != null)
                {
                    if (settlelist.SettleStatus != 2 && settlelist.SettleStatus != -1)
                    {
                        //结算单还在审批中 不能建立新的结算单
                        result.msg    = "帐期:" + settlelist.Priod + " 的结算单正在审批中 不能创建新的结算单";
                        result.result = false;
                        return(result);
                    }
                }
            }
            catch
            {
                result.msg    = "其它错误";
                result.result = false;
                return(result);
            }
            return(result);
        }
示例#2
0
        /// <summary>
        /// 获得最后的结算单
        /// </summary>
        /// <param name="PKID">车场编号</param>
        /// <returns></returns>
        public static ParkSettlementModel GetMaxSettlement(string PKID)
        {
            IParkSettlement     factory    = ParkSettlementFactory.GetFactory();
            ParkSettlementModel settlement = factory.GetMaxPriodSettlement(PKID);

            if (settlement != null)
            {
                if (settlement.EndTime > DateTime.MinValue)
                {
                    settlement.EndTimeName  = settlement.EndTime.ToString("yyyy-MM-dd HH:mm:ss");
                    settlement.EndTimeName1 = settlement.EndTime.AddSeconds(1).ToString("yyyy-MM-dd HH:mm:ss");
                }
                else
                {
                    settlement.EndTimeName  = "";
                    settlement.EndTimeName1 = "";
                }
            }
            else
            {
                settlement              = new ParkSettlementModel();
                settlement.EndTimeName  = "";
                settlement.EndTimeName1 = "";
            }
            return(settlement);
        }
示例#3
0
        public bool UpdateSettlementStatus(string RecordID, int SettleStatus)
        {
            ParkSettlementModel settlement = new ParkSettlementModel();
            string strSql = "update parksettlement set SettleStatus=@SettleStatus where recordid=@RecordID";

            using (DbOperator dbOperator = ConnectionManager.CreateReadConnection())
            {
                dbOperator.ClearParameters();
                dbOperator.AddParameter("SettleStatus", SettleStatus);
                dbOperator.AddParameter("RecordID", RecordID);
                return(dbOperator.ExecuteNonQuery(strSql) > 0 ? true : false);
            }
        }
示例#4
0
        public bool SaveFlowOperator(string PKID, string UserID, int FlowID)
        {
            ParkSettlementModel settlement = new ParkSettlementModel();
            string strSql = "update ParkSettlementApprovalFlow set FlowUser=@FlowUser where pkid=@PKID and flowid=@FlowID";

            using (DbOperator dbOperator = ConnectionManager.CreateReadConnection())
            {
                dbOperator.ClearParameters();
                dbOperator.AddParameter("FlowUser", UserID);
                dbOperator.AddParameter("PKID", PKID);
                dbOperator.AddParameter("FlowID", FlowID);
                return(dbOperator.ExecuteNonQuery(strSql) > 0 ? true : false);
            }
        }
示例#5
0
        /// <summary>
        /// 根据车场编号获取下一个帐期
        /// </summary>
        /// <param name="PKID">车场编号</param>
        /// <returns></returns>
        public static string GetNextPriod(string PKID)
        {
            string              priod      = "F00001";
            IParkSettlement     factory    = ParkSettlementFactory.GetFactory();
            ParkSettlementModel settlement = factory.GetMaxPriodSettlement(PKID);

            if (settlement != null)
            {
                int current = int.Parse(settlement.Priod.Substring(1));
                current++;
                priod = "F" + current.ToString().PadLeft(5, '0');
            }
            return(priod);
        }
示例#6
0
        /// <summary>
        /// 获得最大帐期
        /// </summary>
        /// <param name="PKID">车场编号</param>
        /// <returns></returns>
        public ParkSettlementModel GetMaxPriodSettlement(string PKID)
        {
            ParkSettlementModel settlement = null;
            string strSql = "select  top 1 * from parksettlement where pkid=@PKID and settlestatus!=-1 order by priod desc";

            using (DbOperator dbOperator = ConnectionManager.CreateReadConnection())
            {
                dbOperator.ClearParameters();
                dbOperator.AddParameter("PKID", PKID);
                using (DbDataReader reader = dbOperator.ExecuteReader(strSql.ToString()))
                {
                    while (reader.Read())
                    {
                        settlement = new ParkSettlementModel();
                        settlement = DataReaderToModel <ParkSettlementModel> .ToModel(reader);
                    }
                }
            }
            return(settlement);
        }
示例#7
0
        /// <summary>
        /// 生成结算单
        /// </summary>
        /// <param name="settlement">结算单对象</param>
        /// <returns></returns>
        public bool BuildSettlement(ParkSettlementModel settlement)
        {
            bool flag = false;

            using (DbOperator dbOperator = ConnectionManager.CreateConnection())
            {
                string strSql = "insert into parksettlement(recordid,pkid,priod,settlestatus,totalamount,handlingfeeamount,receivableamount,starttime,endtime,createtime,remark,createuser) values(@recordid,@pkid,@priod,0,@totalamount,@handlingfeeamount,@receivableamount,@starttime,@endtime,getdate(),@remark,@createuser)";
                dbOperator.ClearParameters();
                dbOperator.AddParameter("recordid", System.Guid.NewGuid().ToString());
                dbOperator.AddParameter("pkid", settlement.PKID);
                dbOperator.AddParameter("priod", settlement.Priod);
                dbOperator.AddParameter("totalamount", settlement.TotalAmount);
                dbOperator.AddParameter("handlingfeeamount", settlement.HandlingFeeAmount);
                dbOperator.AddParameter("receivableamount", settlement.ReceivableAmount);
                dbOperator.AddParameter("starttime", settlement.StartTime);
                dbOperator.AddParameter("endtime", settlement.EndTime);
                dbOperator.AddParameter("remark", settlement.Remark);
                dbOperator.AddParameter("createuser", settlement.CreateUser);
                flag = dbOperator.ExecuteNonQuery(strSql) > 0;
            }
            return(flag);
        }
示例#8
0
        /// <summary>
        /// 获得所有结算单
        /// </summary>
        /// <param name="PKID">车场编号</param>
        /// <param name="SettleStatus">结算单状态</param>
        /// <param name="Priod">帐期</param>
        /// <returns></returns>
        public List <ParkSettlementModel> GetSettlements(string PKID, int SettleStatus, string Priod, string UserID)
        {
            List <ParkSettlementModel> settlements = new List <ParkSettlementModel>();
            StringBuilder strSql = new StringBuilder();

            strSql.Append(@"select s.ID,s.RecordID,s.PKID,s.Priod,s.SettleStatus,s.TotalAmount,s.HandlingFeeAmount,s.ReceivableAmount,s.StartTime,s.EndTime,s.PayTime,s.CreateTime,s.Receipt,s.CreateUser,p.pkname ParkName,u.UserName,s.Remark from parksettlement s left join baseparkinfo p on s.pkid=p.pkid left join sysuser u on u.RecordID=s.CreateUser where s.pkid=@PKID and settlestatus in (
select flowid from ParkSettlementApprovalFlow where flowuser=@userid
 and pkid=@PKID)");
            if (SettleStatus != -1)
            {
                strSql.Append(" and settlestatus=@settlestatus");
            }
            if (Priod != "-1")
            {
                strSql.Append(" and Priod=@Priod");
            }

            StringBuilder strSql1 = new StringBuilder();

            strSql1.Append(@"select s.ID,s.RecordID,s.PKID,s.Priod,s.SettleStatus,s.TotalAmount,s.HandlingFeeAmount,s.ReceivableAmount,s.StartTime,s.EndTime,s.PayTime,s.CreateTime,s.Receipt,s.CreateUser,p.pkname ParkName,u.UserName,s.Remark from parksettlement s left join baseparkinfo p on s.pkid=p.pkid left join sysuser u on u.RecordID=s.CreateUser where s.pkid=@PKID and createuser=@UserID");
            if (SettleStatus != -1)
            {
                strSql1.Append(" and settlestatus=@settlestatus");
            }
            if (Priod != "-1")
            {
                strSql1.Append(" and Priod=@Priod");
            }

            string s = strSql.ToString() + " union " + strSql1.ToString();


            using (DbOperator dbOperator = ConnectionManager.CreateReadConnection())
            {
                dbOperator.ClearParameters();
                dbOperator.AddParameter("PKID", PKID);
                dbOperator.AddParameter("SettleStatus", SettleStatus);
                dbOperator.AddParameter("Priod", Priod);
                dbOperator.AddParameter("userid", UserID);
                using (DbDataReader reader = dbOperator.ExecuteReader(s))
                {
                    while (reader.Read())
                    {
                        ParkSettlementModel sm = DataReaderToModel <ParkSettlementModel> .ToModel(reader);

                        if (sm.CreateTime > DateTime.MinValue)
                        {
                            sm.CreateTimeName = sm.CreateTime.ToString("yyyy-MM-dd HH:mm:ss");
                        }
                        if (sm.EndTime > DateTime.MinValue)
                        {
                            sm.EndTimeName = sm.EndTime.ToString("yyyy-MM-dd HH:mm:ss");
                        }
                        if (sm.PayTime > DateTime.MinValue)
                        {
                            sm.PayTimeName = sm.PayTime.ToString("yyyy-MM-dd HH:mm:ss");
                        }
                        if (sm.StartTime > DateTime.MinValue)
                        {
                            sm.StartTimeName = sm.StartTime.ToString("yyyy-MM-dd HH:mm:ss");
                        }
                        //申请人为当前人
                        if (UserID == sm.CreateUser)
                        {
                            if (sm.SettleStatus != 0)
                            {
                                if (!IsApprovalFlow(PKID, UserID, sm.SettleStatus))
                                {
                                    sm.IsHide = true;
                                }
                            }
                        }
                        settlements.Add(sm);
                    }
                }
            }
            return(settlements);
        }
示例#9
0
        /// <summary>
        /// 获得所有结算单
        /// </summary>
        /// <param name="PKID">车场编号</param>
        /// <param name="SettleStatus">结算单状态</param>
        /// <param name="Priod">帐期</param>
        /// <returns></returns>
        public List <ParkSettlementModel> GetSettlements(string PKID, int SettleStatus, string Priod, string UserID)
        {
            List <ParkSettlementModel> settlements = new List <ParkSettlementModel>();
            StringBuilder strSql = new StringBuilder();

//            strSql.Append(@"select s.ID,s.RecordID,s.PKID,s.Priod,s.SettleStatus,s.TotalAmount,s.HandlingFeeAmount,s.ReceivableAmount,s.StartTime,s.EndTime,s.PayTime,s.CreateTime,s.Receipt,s.CreateUser,p.pkname ParkName,u.UserName,s.Remark from parksettlement s left join baseparkinfo p on s.pkid=p.pkid left join sysuser u on u.RecordID=s.CreateUser where s.pkid=@PKID and settlestatus in (
//select flowid from ParkSettlementApprovalFlow where flowuser=@userid
// and pkid=@PKID)");
//            if (SettleStatus != -1)
//            {
//                strSql.Append(" and settlestatus=@settlestatus");
//            }
//            if (Priod != "-1")
//            {
//                strSql.Append(" and Priod=@Priod");
//            }

//            StringBuilder strSql1 = new StringBuilder();
//            strSql1.Append(@"select s.ID,s.RecordID,s.PKID,s.Priod,s.SettleStatus,s.TotalAmount,s.HandlingFeeAmount,s.ReceivableAmount,s.StartTime,s.EndTime,s.PayTime,s.CreateTime,s.Receipt,s.CreateUser,p.pkname ParkName,u.UserName,s.Remark from parksettlement s left join baseparkinfo p on s.pkid=p.pkid left join sysuser u on u.RecordID=s.CreateUser where s.pkid=@PKID and createuser=@UserID");
//            if (SettleStatus != -1)
//            {
//                strSql1.Append(" and settlestatus=@settlestatus");
//            }
//            if (Priod != "-1")
//            {
//                strSql1.Append(" and Priod=@Priod");
//            }

//            string s = strSql.ToString() + " union " + strSql1.ToString();


            strSql.Append(@"select s.ID,s.RecordID,s.PKID,s.Priod,s.SettleStatus,s.TotalAmount,s.HandlingFeeAmount,s.ReceivableAmount,s.StartTime,s.EndTime,s.PayTime,s.CreateTime,s.Receipt,s.CreateUser,p.pkname ParkName,u.UserName,s.Remark from parksettlement s left join baseparkinfo p on s.pkid=p.pkid left join sysuser u on u.RecordID=s.CreateUser where s.pkid=@PKID");
            if (SettleStatus != -1)
            {
                strSql.Append(" and settlestatus=@settlestatus");
            }
            if (Priod != "-1")
            {
                strSql.Append(" and Priod=@Priod");
            }
            List <ParkSettlementApprovalFlowModel> approvals = new ParkSettlementApprovalFlowDAL().GetSettlementApprovalFlows(PKID);
            //判断当前帐户是不是项目帐户


            var companys = new CompanyDAL().QueryTopCompany();
            List <Entities.SysUser> users = new List <Entities.SysUser> ();

            if (companys != null)
            {
                users = new SysUserDAL().QuerySysUserByCompanys(companys.Select(u => u.CPID).ToList());
            }
            using (DbOperator dbOperator = ConnectionManager.CreateReadConnection())
            {
                dbOperator.ClearParameters();
                dbOperator.AddParameter("PKID", PKID);
                dbOperator.AddParameter("SettleStatus", SettleStatus);
                dbOperator.AddParameter("Priod", Priod);
                dbOperator.AddParameter("userid", UserID);
                using (DbDataReader reader = dbOperator.ExecuteReader(strSql.ToString()))
                {
                    while (reader.Read())
                    {
                        ParkSettlementModel sm = DataReaderToModel <ParkSettlementModel> .ToModel(reader);

                        if (sm.CreateTime > DateTime.MinValue)
                        {
                            sm.CreateTimeName = sm.CreateTime.ToString("yyyy-MM-dd HH:mm:ss");
                        }
                        if (sm.EndTime > DateTime.MinValue)
                        {
                            sm.EndTimeName = sm.EndTime.ToString("yyyy-MM-dd HH:mm:ss");
                        }
                        if (sm.PayTime > DateTime.MinValue)
                        {
                            sm.PayTimeName = sm.PayTime.ToString("yyyy-MM-dd HH:mm:ss");
                        }
                        if (sm.StartTime > DateTime.MinValue)
                        {
                            sm.StartTimeName = sm.StartTime.ToString("yyyy-MM-dd HH:mm:ss");
                        }
                        //申请人为当前人
                        //if (UserID == sm.CreateUser)
                        //{
                        //    if (sm.SettleStatus != 0)
                        //    {
                        //        if (!IsApprovalFlow(PKID, UserID, sm.SettleStatus))
                        //        {
                        //            sm.IsHide = true;

                        //        }
                        //    }
                        //}
                        if (sm.SettleStatus == 0)
                        {
                            var appro = approvals.Find(u => u.FlowID == 0);
                            if (appro != null)
                            {
                                if (appro.FlowUser == UserID)
                                {
                                    sm.IsHide = false;
                                }
                                else
                                {
                                    sm.IsHide = true;
                                }
                            }
                            else
                            {
                                sm.IsHide = true;
                            }
                        }
                        else if (sm.SettleStatus == 2 || sm.SettleStatus == -1)
                        {
                            sm.IsHide = true;
                        }
                        else
                        {
                            //如果是平台用户,则不可见
                            if (users.Find(u => u.RecordID == UserID) != null)
                            {
                                sm.IsHide = true;
                            }
                            else
                            {
                                sm.IsHide = false;
                            }
                        }
                        settlements.Add(sm);
                    }
                }
            }
            return(settlements);
        }
示例#10
0
        /// <summary>
        /// 生成结算单
        /// </summary>
        /// <param name="PKID">车场编号</param>
        /// <param name="StartTime">开始时间</param>
        /// <param name="EndTime">结束时间</param>
        /// <param name="UserID">用户编号</param>
        /// <returns></returns>
        public static MyResult BuildSettlement(string PKID, DateTime StartTime, DateTime EndTime, string Remark, string UserID)
        {
            MyResult result = new MyResult();

            result.result = false;
            try
            {
                var companys = new Common.SqlRepository.CompanyDAL().QueryTopCompany();
                List <Entities.SysUser> users = new List <Entities.SysUser>();
                if (companys != null)
                {
                    users = new Common.SqlRepository.SysUserDAL().QuerySysUserByCompanys(companys.Select(u => u.CPID).ToList());
                }

                if (users != null && users.Count > 0)
                {
                    if (users.Find(u => u.RecordID == UserID) != null)
                    {
                        result.msg = "平台帐号不能申请结算单";
                        return(result);
                    }
                }

                string              priod      = "F00001";
                IParkSettlement     factory    = ParkSettlementFactory.GetFactory();
                ParkSettlementModel settlelist = factory.GetMaxPriodSettlement(PKID);
                if (settlelist != null)
                {
                    if (settlelist.SettleStatus != 2 && settlelist.SettleStatus != -1)
                    {
                        //结算单还在审批中 不能建立新的结算单
                        result.msg = "帐期:" + settlelist.Priod + " 的结算单正在审批中 不能创建新的结算单";
                        return(result);
                    }
                    else
                    {
                        string maxpriod = settlelist.Priod;
                        priod = maxpriod.Substring(0, 1) + (1 + int.Parse(maxpriod.Substring(1))).ToString().PadLeft(5, '0');
                    }

                    if (StartTime < settlelist.EndTime)
                    {
                        result.msg = "当前结算单的开始时间不能小于前一个结算单结算时间";
                        return(result);
                    }

                    if (settlelist.EndTime.AddSeconds(1) != StartTime)
                    {
                        result.msg = "提现需要日期连续";
                        return(result);
                    }
                }
                //获取结算金额
                decimal          totalamount       = 0;
                decimal          handlingfeeamount = 0;
                decimal          receivableamount  = 0;
                List <ParkOrder> orderlist         = factory.GetSettlementPayAmount(PKID, StartTime, EndTime);
                if (orderlist != null && orderlist.Count > 0)
                {
                    var park = ParkingServices.QueryParkingByParkingID(PKID);
                    if (park == null || park.HandlingFee <= 0)
                    {
                        result.msg = "未配置车场结算费率 不能生成结算单";
                        return(result);
                    }
                    //费率在车场配置
                    decimal handlingfee = park.HandlingFee / 1000;
                    foreach (var order in orderlist)
                    {
                        totalamount       += order.PayAmount;
                        handlingfeeamount += Math.Round(order.PayAmount * handlingfee, 2);
                    }
                    receivableamount = totalamount - handlingfeeamount;
                }
                ParkSettlementModel settlemodel = new ParkSettlementModel()
                {
                    PKID              = PKID,
                    TotalAmount       = totalamount,
                    ReceivableAmount  = receivableamount,
                    HandlingFeeAmount = handlingfeeamount,
                    EndTime           = EndTime,
                    StartTime         = StartTime,
                    Priod             = priod,
                    Remark            = Remark,
                    CreateUser        = UserID
                };
                result.result = factory.BuildSettlement(settlemodel);
            }
            catch
            {
                result.msg = "生成结算单异常";
            }
            return(result);
        }
示例#11
0
        /// <summary>
        /// 生成结算单
        /// </summary>
        /// <param name="PKID">车场编号</param>
        /// <param name="StartTime">开始时间</param>
        /// <param name="EndTime">结束时间</param>
        /// <param name="UserID">用户编号</param>
        /// <returns></returns>
        public static MyResult BuildSettlement(string PKID, DateTime StartTime, DateTime EndTime, string Remark, string UserID)
        {
            MyResult result = new MyResult();

            result.result = false;
            try
            {
                string              priod      = "F00001";
                IParkSettlement     factory    = ParkSettlementFactory.GetFactory();
                ParkSettlementModel settlelist = factory.GetMaxPriodSettlement(PKID);
                if (settlelist != null)
                {
                    if (settlelist.SettleStatus != 2 && settlelist.SettleStatus != -1)
                    {
                        //结算单还在审批中 不能建立新的结算单
                        result.msg = "帐期:" + settlelist.Priod + " 的结算单正在审批中 不能创建新的结算单";
                        return(result);
                    }
                    else
                    {
                        string maxpriod = settlelist.Priod;
                        priod = maxpriod.Substring(0, 1) + int.Parse(maxpriod.Substring(1)).ToString().PadLeft(5, '0');
                    }

                    if (StartTime < settlelist.EndTime)
                    {
                        result.msg = "当前结算单的开始时间不能小于前一个结算单结算时间";
                        return(result);
                    }

                    if (settlelist.EndTime.AddSeconds(1) != StartTime)
                    {
                        result.msg = "提现需要日期连续";
                        return(result);
                    }
                }
                //获取结算金额
                decimal totalamount       = 0;
                decimal handlingfeeamount = 0;
                decimal receivableamount  = 0;
                //List<ParkOrder> orderlist = factory.GetSettlementPayAmount(PKID, StartTime, EndTime);
                List <Statistics_Gather> orderlist = factory.GetSettlementPayAmount(PKID, StartTime, EndTime);
                if (orderlist != null && orderlist.Count > 0)
                {
                    var park = ParkingServices.QueryParkingByParkingID(PKID);
                    if (park == null || park.HandlingFee <= 0)
                    {
                        result.msg = "未配置车场结算费率 不能生成结算单";
                        return(result);
                    }
                    //费率在车场配置
                    decimal handlingfee = park.HandlingFee / 1000;
                    //foreach (var order in orderlist)
                    //{
                    //    //totalamount += order.PayAmount;
                    //    //handlingfeeamount += Math.Round(order.PayAmount * handlingfee, 2);
                    //
                    //}
                    //receivableamount = totalamount - handlingfeeamount;
                    foreach (var order in orderlist)
                    {
                        totalamount += order.OnLine_Amount;
                    }
                    handlingfeeamount = Math.Round(totalamount * handlingfee, 2);
                    receivableamount  = totalamount - handlingfeeamount;
                }
                ParkSettlementModel settlemodel = new ParkSettlementModel()
                {
                    PKID              = PKID,
                    TotalAmount       = totalamount,
                    ReceivableAmount  = receivableamount,
                    HandlingFeeAmount = handlingfeeamount,
                    EndTime           = EndTime,
                    StartTime         = StartTime,
                    Priod             = priod,
                    Remark            = Remark,
                    CreateUser        = UserID
                };
                result.result = factory.BuildSettlement(settlemodel);
            }
            catch
            {
                result.msg = "生成结算单异常";
            }
            return(result);
        }