/// <summary> /// 删除单据 /// </summary> /// <param name="UserCode"></param> /// <param name="PlainPassword"></param> /// <param name="StrAccID"></param> /// <param name="AccYear"></param> /// <param name="Act"></param> /// <param name="entity"></param> /// <param name="success"></param> /// <returns></returns> public string DelDispatchList(string UserCode, string PlainPassword, string StrAccID, int AccYear, string Act, EntityDispatchListHead entity, out int success) { success = 1; string msg = ""; DispatchListBll bll = new DispatchListBll(StrAccID, AccYear, UserCode, PlainPassword); if (bll.GetGlmendFlag(entity.dDate.Year, entity.dDate.Month, "bflag_SA") == true) { success = 0; return(string.Format("U8单据{0}日期所在月份已经结账!", entity.cDLCode)); } if (GetDispatchList(entity.cDLCode) != 0) { if (DispatchListChecked(entity.cDLCode) == 0) { msg = string.Format("U8中发/退货单:{0} 已审核,不允许删除!", entity.cDLCode); success = 0; } else { //执行删除发货单操作 DeleteDispatchList(entity.cDLCode); msg = string.Format("U8中发/退货单:{0} 已删除!", entity.cDLCode); success = 1; } } else { msg = string.Format("U8中发/退货单:{0} 不存在!", entity.cDLCode); } return(msg); }
/// <summary> /// 新增退货单 /// </summary> /// <param name="UserCode"></param> /// <param name="PlainPassword"></param> /// <param name="StrAccID"></param> /// <param name="AccYear"></param> /// <param name="Act"></param> /// <param name="Kind">0:普通销售 1:委托代销</param> /// <param name="entity"></param> /// <param name="success"></param> /// <returns></returns> public string AddDispatchList(string UserCode, string PlainPassword, string StrAccID, int AccYear, string Act, int Kind, EntityDispatchListHead entity, out int success) { success = 0; DispatchListBll bll = new DispatchListBll(StrAccID, AccYear, UserCode, PlainPassword); // 必填项验证 string msg = ""; if (!entity.CheckEntity(out msg)) { return(msg); } foreach (EntityDispatchListBody entitybody in entity.Details) { if (!entity.CheckEntity(out msg)) { return(msg); } } #region 验证 if (bll.GetGlmendFlag(entity.dDate.Year, entity.dDate.Month, "bflag_SA") == true) { return(string.Format("U8单据{0}日期所在月份已经结账!", entity.cDLCode)); } // 客户编号 string cusName = bll.GetCustomerName(entity.cCusCode); if (string.IsNullOrWhiteSpace(cusName)) { return(string.Format("U8中不存在客户编号:{0}!", entity.cCusCode)); } entity.cCusName = cusName; // 部门 string deptName = bll.GetDepartmentName(entity.cDepCode); if (string.IsNullOrWhiteSpace(deptName)) { return(string.Format("U8中不存在部门编码:{0},或者部门编码非末级!", entity.cDepCode)); } //销售类型 if (string.IsNullOrWhiteSpace(GetStName(entity.cSTCode))) { return(string.Format("U8中不存在销售类型编码:{0}!", entity.cSTCode)); } if (GetDispatchList(entity.cDLCode) != 0) { return(string.Format("U8中已存在该退货单号{0}!", entity.cDLCode)); } #endregion if (entity.Details == null || entity.Details.Count == 0) { return("表体中存货信息不能为空,至少要有一条记录!"); } var inventorys = GetInventorys("'" + string.Join("','", entity.Details.Select(p => p.cInvCode).Distinct()) + "'"); for (int i = 0; i < entity.Details.Count; i++) { EntityDispatchListBody body = entity.Details[i]; #region 验证单据明细 var invInfo = inventorys.FirstOrDefault(p => p.cInvCode == body.cInvCode); // 存货编号 string invName = bll.GetInventoryName(body.cInvCode); if (invInfo == null) { return(string.Format("U8中不存在存货编码:{0}!", body.cInvCode)); } if (body.iQuantity > 0) { return("退货数量不能大于0!"); } if (body.iQuantity != 0 && body.iSum > 0) { return("退货单价税合计不能大于0"); } if (!string.IsNullOrWhiteSpace(body.cBatch) && bll.GetInventoryName(body.cInvCode, 4) == "0") { return(string.Format("U8中存货编码:{0}未启用批次管理,批次信息必须为空!", body.cInvCode)); } if (string.IsNullOrWhiteSpace(body.cBatch) && bll.GetInventoryName(body.cInvCode, 4) == "1") { body.cBatch = bll.GetInvBatch(body.cWhCode, body.cInvCode); if (string.IsNullOrWhiteSpace(body.cBatch)) { return(string.Format("U8中存货编码:{0}启用批次管理,批次信息不能为空!", body.cInvCode)); } } body.cInvName = invName; int bInvType = GetbInvType(body.cInvCode); if (body.iQuantity == 0 && bInvType == 0) { return(string.Format("非折扣属性商品发货数量不能等于0")); } #endregion #region 单据明细计算 body.bcosting = 1;//标志 是否记账 if (bInvType == 1) { body.cWhCode = null; body.bcosting = 0; body.iQuantity = 0; body.iQuotedPrice = 0; } body.iRowNo = (i + 1); body.KL = 100; //当数量为正数时,求其绝对值转换为负数 if (body.iQuantity > 0) { body.iQuantity = -body.iQuantity; } body.bSettleAll = 0; //结算标志 body.bQAChecked = 0; //是否报险 body.bQAUrgency = 0; //是否急料 body.bQAChecking = 0; //是否再检 body.bQAChecked = 0; //是否报险 body.bQANeedCheck = 0; //是否质检 decimal isum = body.iSum.HasValue ? body.iSum.Value : 0; body.cbSysBarCode = string.Format("||SA03|{0}|{1}", entity.cDLCode, body.iRowNo); body.iTaxUnitPrice = body.iQuantity == 0 ? 0 : isum / body.iQuantity; body.iUnitPrice = body.iQuantity == 0 ? 0 : Math.Round(body.iTaxUnitPrice / ((body.iTaxRate / 100) + 1), 2); body.iMoney = Math.Round(isum / ((body.iTaxRate / 100) + 1), 2); body.iTax = isum - body.iMoney; body.KL2 = body.iQuotedPrice == 0 || !body.iQuotedPrice.HasValue ? 100 : (isum / (body.iQuotedPrice.Value * body.iQuantity)) * 100; body.fSaleCost = body.fSaleCost != 0 ? body.fSaleCost : bll.GetSA_InvPrice(body.cInvCode); body.fSalePrice = body.fSaleCost * body.iQuantity; body.iDisCount = body.iQuotedPrice == 0 || !body.iQuotedPrice.HasValue ? 0 : body.iQuotedPrice.Value * body.iQuantity - isum; body.iNatMoney = body.iMoney; body.iNatSum = isum; body.iNatTax = body.iTax; body.iNatUnitPrice = body.iUnitPrice; body.iNatDisCount = body.iDisCount; #endregion } //设置默认值 entity.bFirst = 0; //销售期初标志 entity.bReturnFlag = 1; //退货标志 entity.bSettleAll = 0; //结算标志 entity.iExchRate = 1; //汇率 entity.cBusType = Kind == 0 ? "普通销售" : "委托代销"; // 业务类型 entity.cexch_name = "人民币"; //币种名称 entity.cVouchType = Kind == 0 ? "05" : "06"; //单据类型编码 entity.iVTid = Kind == 0 ? 75 : 51; //单据模板号 entity.cSysBarCode = Kind == 0 ? string.Format("||SA03|{0}", entity.cDLCode) : string.Format("||SA54|{0}", entity.cDLCode); entity.cMaker = bll.GetUserName(UserCode); string id = string.Empty; id = bll.InsertDispatchList(entity); success = string.IsNullOrWhiteSpace(id) ? 0 : 1; return(id); }