/// <summary> /// 新增发货单 /// </summary> /// <param name="UserCode"></param> /// <param name="PlainPassword"></param> /// <param name="ModelType"></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, int ModelType, string StrAccID, int AccYear, string Act, int Kind, EntityDispatchListHead entity, out int success) { success = 0; DispatchListBll bll = new DispatchListBll(StrAccID, AccYear, UserCode, PlainPassword); entity.bFirst = 0; //销售期初标志 entity.bReturnFlag = 0; //退货标志 entity.bSettleAll = 0; //结算标志 entity.iExchRate = 1; //汇率 entity.cBusType = Kind == 0 ? "普通销售" : "委托代销"; // 业务类型 entity.cexch_name = "人民币"; //币种名称 entity.cVouchType = Kind == 0 ? "05" : "06"; //单据类型编码 entity.iVTid = Kind == 0 ? 71 : 79; //单据模板号 entity.cSysBarCode = Kind == 0 ? string.Format("||SA01|{0}", entity.cDLCode) : string.Format("||SA53|{0}", entity.cDLCode); entity.cMaker = bll.GetUserName(UserCode); #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("表体中存货信息不能为空,至少要有一条记录!"); } // 必填项验证 string msg = ""; if (!entity.CheckEntity(out msg)) { return(msg); } foreach (EntityDispatchListBody entitybody in entity.Details) { if (!entitybody.CheckEntity(out msg)) { return(msg); } } //获取存货档案信息 var inventorys = GetInventorys("'" + string.Join("','", entity.Details.Select(p => p.cInvCode).Distinct()) + "'"); //获取库存信息 EntityCurrentStock xclEntity = new EntityCurrentStock(); xclEntity.cWhCode = string.Join(",", entity.Details.Select(p => p.cWhCode).Distinct()); xclEntity.cInvCode = string.Join(",", entity.Details.Select(p => p.cInvCode).Distinct()); CurrentStockBll csBll = new CurrentStockBll(StrAccID, AccYear, UserCode, PlainPassword); var csData = csBll.GetCurrentStock(xclEntity, out msg); for (int i = 0; i < entity.Details.Count; i++) { EntityDispatchListBody body = entity.Details[i]; var invInfo = inventorys.FirstOrDefault(p => p.cInvCode == body.cInvCode); #region 验证 // 存货编号 if (invInfo == null) { return(string.Format("U8中不存在存货编码:{0}!", body.cInvCode)); } if (body.iQuantity < 0) { return("发货数量不能小于0!"); } if (body.iQuantity != 0 && body.iSum < 0) //折扣类存货数量为0,金额为负数 { return("发货单价税合计不能小于0!"); } if (!string.IsNullOrWhiteSpace(body.cBatch) && invInfo.bInvBatch == "0") { return(string.Format("U8中存货编码:{0}未启用批次管理,批次信息必须为空!", body.cInvCode)); } if (string.IsNullOrWhiteSpace(body.cBatch) && invInfo.bInvBatch == "1") { body.cBatch = bll.GetInvBatch(body.cWhCode, body.cInvCode); if (string.IsNullOrWhiteSpace(body.cBatch)) { return(string.Format("U8中存货编码:{0}启用批次管理,批次信息不能为空!", body.cInvCode)); } } body.cInvName = invInfo.cInvName; int bInvType = Convert.ToInt32(invInfo.bInvType); if (body.iQuantity == 0 && invInfo.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; 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("||SA01|{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 } string id = string.Empty; if (!string.IsNullOrEmpty(entity.cSOCode)) { int count = 0; count = GetSoMain(entity.cSOCode); if (count <= 0) { return(string.Format("销售订单号{0}在U8中不存在!", entity.cSOCode)); } } id = bll.InsertDispatchList(entity); success = string.IsNullOrWhiteSpace(id) ? 0 : 1; return(id); }
/// <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> /// <returns></returns> public string AddCheckVouch(string UserCode, string PlainPassword, string StrAccID, int AccYear, string Act, EntityCheckVouchHead entity, out int success) { success = 0; CheckVouchBll bll = new CheckVouchBll(StrAccID, AccYear, UserCode, PlainPassword); #region 验证 // 字段必填项验证 string msg = ""; if (!entity.CheckEntity(out msg)) { return(msg); } foreach (EntityCheckVouchBody entitybody in entity.Details) { if (!entitybody.CheckEntity(out msg)) { return(msg); } } if (bll.GetGlmendFlag(entity.dCVDate.Year, entity.dCVDate.Month, "bflag_ST") == true) { return(string.Format("U8单据{0}日期所在月份已经结账!", entity.cCVCode)); } // 仓库 string warehouseName = GetWarehouseName(entity.cWhCode); if (string.IsNullOrWhiteSpace(warehouseName)) { return(string.Format("U8中不存在仓库编码:{0}!", entity.cWhCode)); } entity.cORdCode = GetRdCode(18, 0); entity.cIRdCode = GetRdCode(18, 1); // 出库类别编码 if (string.IsNullOrWhiteSpace(entity.cORdCode) || string.IsNullOrWhiteSpace(GetRdStyleName(entity.cORdCode))) { return(string.Format("U8中不存在收发类别编码:{0}!", entity.cORdCode)); } // 入库类别编码 if (string.IsNullOrWhiteSpace(entity.cIRdCode) && string.IsNullOrWhiteSpace(GetRdStyleName(entity.cIRdCode, 1))) { return(string.Format("U8中不存在收发类别编码:{0}!", entity.cIRdCode)); } #endregion entity.cSysbarCode = "||st18|" + entity.cCVCode; //获取存货档案信息 var inventorys = GetInventorys("'" + string.Join("','", entity.Details.Select(p => p.cInvCode).Distinct()) + "'"); //获取库存信息 EntityCurrentStock xclEntity = new EntityCurrentStock(); xclEntity.cWhCode = entity.cWhCode; xclEntity.cInvCode = string.Join(",", entity.Details.Select(p => p.cInvCode).Distinct()); CurrentStockBll csBll = new CurrentStockBll(StrAccID, AccYear, UserCode, PlainPassword); var csData = csBll.GetCurrentStock(xclEntity, out msg); for (int i = 0; i < entity.Details.Count; i++) { EntityCheckVouchBody body = entity.Details[i]; #region 验证单据明细 var invInfo = inventorys.FirstOrDefault(p => p.cInvCode == body.cInvCode); // 存货编号 if (invInfo == null) { return(string.Format("U8中不存在存货编码:{0}!", body.cInvCode)); } if (!string.IsNullOrWhiteSpace(body.cBatch) && invInfo.bInvBatch == "0") { return(string.Format("U8中存货编码:{0}未启用批次管理,批次信息必须为空!", body.cInvCode)); } if (string.IsNullOrWhiteSpace(body.cBatch) && invInfo.bInvBatch == "1") { return(string.Format("U8中存货编码:{0}启用批次管理,批次信息不能为空!", body.cInvCode)); } // int bInvType = GetbInvType(body.cInvCode); if (body.iCVCQuantity < 0) { return(string.Format("盘点数量不能为小于0!")); } #endregion #region 明细栏目计算 body.iCVQuantity = csData.Where(p => p.cInvCode == body.cInvCode).Sum(p => p.iQuantity); body.iAdInQuantity = 0; body.iAdOutQuantity = 0; body.iActualWaste = 0; //盈亏比例%:=盈亏数量/账面调整数*100 #endregion } // 设置默认值 entity.cMaker = string.IsNullOrWhiteSpace(entity.cMaker) ? bll.GetUserName(UserCode) : entity.cMaker; string id = InsertCheckVouch(entity); success = string.IsNullOrWhiteSpace(id) ? 0 : 1;; return(id); }
/// <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> /// <returns></returns> public string AddRdRecord09(string UserCode, string PlainPassword, string StrAccID, int AccYear, string Act, EntityRdRecord09Head entity, out int success) { success = 0; RdRecord09Bll bll = new RdRecord09Bll(StrAccID, AccYear, UserCode, PlainPassword); #region 验证 // 字段必填项验证 string msg = ""; if (!entity.CheckEntity(out msg)) { return(msg); } foreach (EntityRdRecord09Body entitybody in entity.Details) { if (!entitybody.CheckEntity(out msg)) { return(msg); } } if (bll.GetGlmendFlag(entity.dDate.Year, entity.dDate.Month, "bflag_ST") == true) { return(string.Format("U8单据{0}日期所在月份已经结账!", entity.cCode)); } // 部门 string deptName = GetDepartmentName(entity.cDepCode); if (string.IsNullOrWhiteSpace(deptName)) { return(string.Format("U8中不存在部门编码:{0},或者部门编码非末级!", entity.cDepCode)); } entity.cDefine11 = deptName; // 仓库 string warehouseName = bll.GetWarehouseName(entity.cWhCode); if (string.IsNullOrWhiteSpace(warehouseName)) { return(string.Format("U8中不存在仓库编码:{0}!!", entity.cWhCode)); } // 收发类别编码 if (string.IsNullOrWhiteSpace(bll.GetRdStyleName(entity.cRdCode))) { return(string.Format("U8中不存在收发类别编码:{0}!", entity.cRdCode)); } // 客户编号 string cusName = bll.GetCustomerName(entity.cCusCode); if (string.IsNullOrWhiteSpace(cusName)) { return(string.Format("U8中不存在客户编号:{0}!", entity.cCusCode)); } #endregion string msg1 = ""; for (int i = 0; i < entity.Details.Count; i++) { EntityRdRecord09Body body = entity.Details[i]; #region 验证单据明细 // 存货编号 string invName = bll.GetInventoryName(body.cInvCode); if (string.IsNullOrWhiteSpace(invName)) { return(string.Format("U8中不存在存货编码:{0}!", body.cInvCode)); } 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") { return(string.Format("U8中存货编码:{0}启用批次管理,批次信息不能为空!", body.cInvCode)); } ; if (body.iQuantity == 0) { return(string.Format("U8中存货编码:{0}数量不能等于0!", body.cInvCode)); } // 可用量验证 EntityCurrentStock xclEntity = new EntityCurrentStock(); xclEntity.cInvCode = body.cInvCode; xclEntity.cWhCode = entity.cWhCode; CurrentStockBll csBll = new CurrentStockBll(StrAccID, AccYear, UserCode, PlainPassword); var csData = csBll.GetCurrentStock(xclEntity, out msg).Sum(p => p.iQuantity); if (csData < body.iQuantity) { msg = (string.Format("存货编码:{0}可用量不足,当前可用量为:{1};", body.cInvCode, csData)); msg1 += msg; } #endregion #region 明细栏目计算 body.iUnitCost = bll.GetInvSPrice(body.cInvCode); body.iAPrice = body.iUnitCost * body.iQuantity; body.irowno = (i + 1); body.cDefine22 = string.IsNullOrEmpty(body.cDefine22) ? bll.GetInventoryName(body.cInvCode, 2) : body.cDefine22; body.cDefine23 = string.IsNullOrEmpty(body.cDefine23) ? bll.GetInventoryName(body.cInvCode, 3) : body.cDefine23; body.cbsysbarcode = string.Format("||st09|{0}|{1}", entity.cCode, body.irowno); body.iFlag = 0;//标志 #endregion } if (msg1 != "") { return(msg1); } //设置默认值 entity.bRdFlag = 0; //收发标志 entity.blsSTQc = 0; //库存期初标志 entity.cVouchType = "09"; //单据类型编码 entity.cSource = "库存"; //单据来源 entity.bTransFlag = 0; //是否传递 entity.cMaker = string.IsNullOrWhiteSpace(entity.cMaker) ? bll.GetUserName(UserCode) : entity.cMaker; entity.cBusType = "其他出库"; entity.VT_ID = 85; entity.bOMFirst = 0; entity.dnmaketime = entity.dDate; entity.cDefine11 = cusName; entity.csysbarcode = string.Format("st09|{0}", entity.cCode); string id = bll.InsertRdRecord09(entity); success = string.IsNullOrWhiteSpace(id) ? 0 : 1; return(id); }