Example #1
0
        /// <summary>
        /// 台账写入
        /// </summary>
        /// <typeparam name="THead">物资库盘点单表头模板</typeparam>
        /// <typeparam name="TDetail">物资库盘点单明细模板</typeparam>
        /// <param name="billHead">物资库盘点单头</param>
        /// <param name="billDetails">物资库盘点单明细</param>
        /// <param name="storeResult">库存返回结果</param>
        public void WriteAccount <THead, TDetail>(THead billHead, TDetail billDetails, MWStoreResult storeResult)
        {
            MW_AuditDetail detail = billDetails as MW_AuditDetail;
            MW_AuditHead   head   = billHead as MW_AuditHead;
            int            actYear;
            int            actMonth;
            string         errMsg;

            if (!GetAccountTime(head.DeptID, out errMsg, out actYear, out actMonth))
            {
                throw new Exception(errMsg);
            }

            MW_Account account = NewObject <MW_Account>();

            account.BalanceYear  = actYear;
            account.BalanceMonth = actMonth;
            account.AccountType  = 0;
            account.BalanceFlag  = 0;
            account.BatchNO      = detail.BatchNO;
            account.BusiType     = head.BusiType;
            account.DeptID       = head.DeptID;
            account.DetailID     = detail.AuditDetailID;
            account.MaterialID   = detail.MaterialID;
            account.UnitID       = detail.UnitID;
            account.UnitName     = detail.UnitName;
            account.BillNO       = head.BillNO;
            account.RegTime      = DateTime.Now;
            //盘盈 借方
            //盘亏 贷方
            //借方
            if (detail.FactAmount - detail.ActAmount > 0)
            {
                account.StockPrice    = detail.StockPrice;
                account.RetailPrice   = detail.RetailPrice;
                account.LendAmount    = detail.FactAmount - detail.ActAmount;
                account.LendRetailFee = (detail.FactAmount - detail.ActAmount) * detail.RetailPrice;
                account.LendStockFee  = (detail.FactAmount - detail.ActAmount) * detail.StockPrice;

                account.OverAmount    = storeResult.StoreAmount;
                account.OverRetailFee = storeResult.StoreAmount * account.RetailPrice;
                account.OverStockFee  = storeResult.StoreAmount * account.StockPrice;
            }
            else
            {
                //贷方
                account.StockPrice     = detail.StockPrice;
                account.RetailPrice    = detail.RetailPrice;
                account.DebitAmount    = detail.ActAmount - detail.FactAmount;
                account.DebitRetailFee = (detail.ActAmount - detail.FactAmount) * detail.RetailPrice;
                account.DebitStockFee  = (detail.ActAmount - detail.FactAmount) * detail.StockPrice;

                account.OverAmount    = storeResult.StoreAmount;
                account.OverRetailFee = storeResult.StoreAmount * account.RetailPrice;
                account.OverStockFee  = storeResult.StoreAmount * account.StockPrice;
            }

            account.save();
        }
Example #2
0
        /// <summary>
        /// 审核物资库盘点单
        /// </summary>
        /// <param name="deptId">库房ID</param>
        /// <param name="auditEmpID">审核人ID</param>
        /// <param name="auditEmpName">审核人姓名</param>
        /// <returns>单据处理结果</returns>
        public MWBillResult AuditBill(int deptId, int auditEmpID, string auditEmpName)
        {
            string serialNO = string.Empty;//审核单据号
            //1.检查库房状态是否处于盘点状态
            int checkStatus = NewDao <SqlMWDao>().GetStoreRoomStatus(deptId);

            if (checkStatus == 0)
            {
                throw new Exception("系统没有进入盘点状态,请启用盘点状态");
            }

            //2.提取所有未审核的单据返回DataTable;
            DataTable dtNotAuditDetail = NewDao <SqlMWDao>().GetAllNotAuditDetail(deptId);
            //3.创建盘点审核单据头
            MW_AuditHead auditHead = NewObject <MW_AuditHead>();
            decimal      profitRetailFee = 0, profitStockFee = 0, lossRetailFee = 0, lossStockFee = 0;
            decimal      checkStockFee = 0, actStockFee = 0, checkRetailFee = 0, actRetailFee = 0;

            checkStockFee             = Convert.ToDecimal(dtNotAuditDetail.Compute("sum(FactStockFee)", "true"));        //盘存进货金额
            actStockFee               = Convert.ToDecimal(dtNotAuditDetail.Compute("sum(ActStockFee)", "true"));         //账存进货金额
            checkRetailFee            = Convert.ToDecimal(dtNotAuditDetail.Compute("sum(FactRetailFee)", "true"));       //盘存零售金额
            actRetailFee              = Convert.ToDecimal(dtNotAuditDetail.Compute("sum(ActRetailFee)", "true"));        //账存零售金额
            profitRetailFee           = checkRetailFee - actRetailFee > 0 ? checkRetailFee - actRetailFee : 0;           //盘盈零售金额
            profitStockFee            = checkStockFee - actStockFee > 0 ? checkStockFee - actStockFee : 0;               //盘盈进货金额
            lossRetailFee             = checkRetailFee - actRetailFee < 0 ? Math.Abs(checkRetailFee - actRetailFee) : 0; //盘亏零售金额
            lossStockFee              = checkStockFee - actStockFee < 0 ? Math.Abs(checkStockFee - actStockFee) : 0;     //盘亏进货金额
            serialNO                  = NewObject <SerialNumberSource>().GetSerialNumber(SnType.物资, deptId, MWConstant.OP_MW_AUDITCHECK);
            auditHead.BillNO          = Convert.ToInt64(serialNO);
            auditHead.EmpID           = auditEmpID;
            auditHead.EmpName         = auditEmpName;
            auditHead.AuditTime       = System.DateTime.Now;
            auditHead.Remark          = string.Empty;
            auditHead.DelFlag         = 0;
            auditHead.AuditFlag       = 1;
            auditHead.BusiType        = MWConstant.OP_MW_AUDITCHECK;
            auditHead.DeptID          = deptId;
            auditHead.ProfitRetailFee = profitRetailFee;
            auditHead.ProfitStockFee  = profitStockFee;
            auditHead.LossRetailFee   = lossRetailFee;
            auditHead.LossStockFee    = lossStockFee;
            auditHead.CheckStockFee   = checkStockFee;
            auditHead.ActStockFee     = actStockFee;
            auditHead.CheckRetailFee  = checkRetailFee;
            auditHead.ActRetailFee    = actRetailFee;
            BindDb(auditHead);
            auditHead.save();
            //循环DataTable,根据DataTable的每一行的值去构建盘点审核单明细和盘点审核单头;
            //4.保存盘点审核单表头和明细
            //5、按盘点审核单内容更新物资库库存
            MWBillResult result = new MWBillResult();

            foreach (DataRow drNotAuditRow in dtNotAuditDetail.Rows)
            {
                MW_AuditDetail auditdetail = NewObject <MW_AuditDetail>();
                auditdetail.StorageID     = Convert.ToInt32(drNotAuditRow["StorageID"]);
                auditdetail.MaterialID    = Convert.ToInt32(drNotAuditRow["MaterialID"]);
                auditdetail.Place         = drNotAuditRow["Place"].ToString();
                auditdetail.BatchNO       = drNotAuditRow["BatchNO"].ToString();
                auditdetail.ValidityDate  = Convert.ToDateTime(drNotAuditRow["ValidityDate"]);
                auditdetail.DeptID        = deptId;
                auditdetail.BillNO        = Convert.ToInt64(serialNO);
                auditdetail.FactAmount    = Convert.ToDecimal(drNotAuditRow["FactAmount"]);
                auditdetail.FactStockFee  = Convert.ToDecimal(drNotAuditRow["FactStockFee"]);
                auditdetail.FactRetailFee = Convert.ToDecimal(drNotAuditRow["FactRetailFee"]);
                auditdetail.ActAmount     = Convert.ToDecimal(drNotAuditRow["ActAmount"]);
                auditdetail.ActStockFee   = Convert.ToDecimal(drNotAuditRow["ActStockFee"]);
                auditdetail.ActRetailFee  = Convert.ToDecimal(drNotAuditRow["ActRetailFee"]);
                auditdetail.UnitID        = Convert.ToInt32(drNotAuditRow["UnitID"]);
                auditdetail.UnitName      = drNotAuditRow["UnitName"].ToString();
                auditdetail.RetailPrice   = Convert.ToDecimal(drNotAuditRow["RetailPrice"]);
                auditdetail.StockPrice    = Convert.ToDecimal(drNotAuditRow["StockPrice"]);
                auditdetail.AuditHeadID   = auditHead.AuditHeadID;
                BindDb(auditdetail);
                auditdetail.save();
                StoreParam storeParam = new StoreParam();
                storeParam.Amount       = auditdetail.FactAmount - auditdetail.ActAmount;
                storeParam.BatchNO      = auditdetail.BatchNO;
                storeParam.DeptID       = auditdetail.DeptID;
                storeParam.MaterialId   = auditdetail.MaterialID;
                storeParam.RetailPrice  = auditdetail.RetailPrice;
                storeParam.StockPrice   = auditdetail.StockPrice;
                storeParam.UnitID       = auditdetail.UnitID;
                storeParam.UnitName     = auditdetail.UnitName;
                storeParam.ValidityTime = auditdetail.ValidityDate;
                MWStoreResult storeRtn = NewObject <MwStore>().AddStore(storeParam);
                if (storeRtn.Result != 0)
                {
                    result.Result = 1;
                    if (storeRtn.Result == 1)
                    {
                        result.LstNotEnough = new List <MWNotEnoughInfo>();
                        MWNotEnoughInfo notEnough = new MWNotEnoughInfo();
                        notEnough.DeptID       = auditdetail.DeptID;
                        notEnough.MaterialId   = auditdetail.MaterialID;
                        notEnough.LackAmount   = storeRtn.StoreAmount + auditdetail.FactAmount - auditdetail.ActAmount;
                        notEnough.MaterialInfo = "物资批次号:" + auditdetail.BatchNO.ToString();
                        result.LstNotEnough.Add(notEnough);
                        result.ErrMsg = "【" + notEnough.MaterialInfo + "】库存不足";
                    }
                    else
                    {
                        result.ErrMsg = "物资更新库存出错";
                    }

                    return(result);
                }
                else
                {
                    //6、按盘点审核单内容写入台账
                    WriteAccount(auditHead, auditdetail, storeRtn);
                }
            }

            //7、更新所有未审核的盘点录入单状态
            MW_CheckHead checkHead = NewObject <MW_CheckHead>();

            checkHead.AuditEmpID   = auditEmpID;
            checkHead.AuditEmpName = auditEmpName;
            checkHead.AuditHeadID  = auditHead.AuditHeadID;
            checkHead.AuditNO      = auditHead.BillNO;
            checkHead.DeptID       = deptId;
            int ret = NewDao <IMWDao>().UpdateCheckHeadStatus(checkHead);

            if (ret > 0)
            {
                //8、设置库房盘点状态为运营状态
                NewDao <IMWDao>().SetCheckStatus(deptId, 0);
                result.Result = 0;
            }
            else
            {
                result.Result = 1;
            }

            return(result);
        }
        /// <summary>
        /// 获取头表信息
        /// </summary>
        /// <param name="opType">业务类型</param>
        /// <param name="deptId">科室Id</param>
        /// <param name="detailID">明细Id</param>
        /// <returns>头表信息</returns>
        public BillMasterShower GetBillHeadInfo(string opType, int deptId, int detailID)
        {
            BillMasterShower shower = new BillMasterShower();

            switch (opType)
            {
            case "211":    //采购入库
            case "212":    //期初入库
            case "213":    //物资库退货
                MW_InStoreDetail inStoreDetail = (MW_InStoreDetail)NewObject <MW_InStoreDetail>().getmodel(detailID);
                if (inStoreDetail != null)
                {
                    MW_InStoreHead instoreHead = (MW_InStoreHead)NewObject <MW_InStoreHead>().getmodel(inStoreDetail.InHeadID);
                    if (instoreHead != null)
                    {
                        shower.RegTime          = instoreHead.RegTime;
                        shower.AuditTime        = instoreHead.AuditTime;
                        shower.BillNo           = instoreHead.BillNo.ToString();
                        shower.RelationPeopleNo = instoreHead.OpEmpID.ToString();
                        shower.RelationPeople   = GetEmpName(instoreHead.OpEmpID);
                        shower.RelationUnit     = instoreHead.SupplierName;
                        shower.RetailFee        = instoreHead.RetailFee;
                        shower.StockFee         = instoreHead.StockFee;
                        shower.OpType           = GetBusiTypeName(opType);
                        shower.RegPeople        = instoreHead.RegEmpName;
                        shower.Remark           = instoreHead.Remark;
                    }
                }

                break;

            case "221":    //流通出库
            case "222":    //内耗出库
            case "223":    //物资库报损
            case "224":    //物资库退库
                MW_OutStoreDetail outStoreDetail = (MW_OutStoreDetail)NewObject <MW_OutStoreDetail>().getmodel(detailID);
                if (outStoreDetail != null)
                {
                    MW_OutStoreHead outStoreHead = (MW_OutStoreHead)NewObject <MW_OutStoreHead>().getmodel(outStoreDetail.OutHeadID);
                    if (outStoreHead != null)
                    {
                        shower.RegTime          = outStoreHead.RegTime;
                        shower.AuditTime        = outStoreHead.AuditTime;
                        shower.BillNo           = outStoreHead.BillNO.ToString();
                        shower.RelationPeopleNo = "暂无";
                        shower.RelationPeople   = "暂无";
                        shower.RelationUnit     = outStoreHead.ToDeptName;
                        shower.RetailFee        = outStoreHead.RetailFee;
                        shower.StockFee         = outStoreHead.StockFee;
                        shower.OpType           = GetBusiTypeName(opType);
                        shower.RegPeople        = outStoreHead.RegEmpName;
                        shower.Remark           = outStoreHead.Remark;
                    }
                }

                break;

            case "242":    //盘点审核
                MW_AuditDetail auditDetail = (MW_AuditDetail)NewObject <MW_AuditDetail>().getmodel(detailID);
                if (auditDetail != null)
                {
                    MW_AuditHead auditHead = (MW_AuditHead)NewObject <MW_AuditHead>().getmodel(auditDetail.AuditHeadID);
                    if (auditHead != null)
                    {
                        shower.RegTime          = auditHead.AuditTime;
                        shower.AuditTime        = auditHead.AuditTime;
                        shower.BillNo           = auditHead.BillNO.ToString();
                        shower.RelationPeopleNo = auditHead.EmpID.ToString();
                        shower.RelationPeople   = auditHead.EmpName;
                        shower.RelationUnit     = GetDeptName(auditHead.DeptID);
                        shower.RetailFee        = auditHead.CheckRetailFee;
                        shower.StockFee         = auditHead.CheckStockFee;
                        shower.OpType           = GetBusiTypeName(opType);
                        shower.RegPeople        = auditHead.EmpName;
                        shower.Remark           = string.Empty;
                    }
                }

                break;

            case "251":    //物资库调价
                DG_AdjDetail adjDetail = (DG_AdjDetail)NewObject <DG_AdjDetail>().getmodel(detailID);
                if (adjDetail != null)
                {
                    DG_AdjHead adjHead = (DG_AdjHead)NewObject <DG_AdjHead>().getmodel(adjDetail.AdjHeadID);
                    if (adjHead != null)
                    {
                        shower.RegTime          = adjHead.RegTime;
                        shower.AuditTime        = adjHead.ExecTime;
                        shower.BillNo           = adjHead.BillNO.ToString();
                        shower.RelationPeopleNo = adjHead.RegEmpID.ToString();
                        shower.RelationPeople   = GetEmpName(adjHead.RegEmpID);
                        shower.RelationUnit     = GetDeptName(adjHead.DeptID);
                        shower.RetailFee        = 0;
                        shower.StockFee         = 0;
                        shower.OpType           = GetBusiTypeName(opType);
                        shower.RegPeople        = GetEmpName(adjHead.RegEmpID);
                        shower.Remark           = adjHead.Remark;
                    }
                }

                break;
            }

            return(shower);
        }