/// <summary> /// 根据车场编号 获取所有公司 /// </summary> /// <param name="PKID">车场编号</param> /// <returns></returns> public static List <string> GetParentCompany() { List <string> companys = new List <string>(); //获得当前车场编号编号 var company = new Common.SqlRepository.CompanyDAL().QueryTopCompany(); if (company != null) { companys = company.Select(u => u.CPID).ToList(); } return(companys); }
/// <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); }