コード例 #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 override void WriteAccount <THead, TDetail>(THead billHead, TDetail billDetails, DGStoreResult storeResult)
        {
            DW_AuditDetail detail = billDetails as DW_AuditDetail;
            DW_AuditHead   head   = billHead as DW_AuditHead;
            int            actYear;
            int            actMonth;
            string         errMsg;

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

            DW_Account account = NewObject <DW_Account>();

            account.BalanceYear  = actYear;
            account.BalanceMonth = actMonth;
            account.AccountType  = 0;
            account.BalanceFlag  = 0;
            account.BatchNO      = detail.BatchNO;
            account.BusiType     = head.BusiType;
            account.CTypeID      = detail.CTypeID;
            account.DeptID       = head.DeptID;
            account.DetailID     = detail.AuditDetailID;
            account.DrugID       = detail.DrugID;
            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();
        }
コード例 #2
0
        /// <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 "111":    //采购入库
            case "112":    //期初入库
            case "113":    //药库退货
                DW_InStoreDetail inStoreDetail = (DW_InStoreDetail)NewObject <DW_InStoreDetail>().getmodel(detailID);
                if (inStoreDetail != null)
                {
                    DW_InStoreHead instoreHead = (DW_InStoreHead)NewObject <DW_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   = instoreHead.OpEmpName;
                        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 "121":    //流通出库
            case "122":    //内耗出库
            case "123":    //药库报损
            case "124":    //药库退库
                DW_OutStoreDetail outStoreDetail = (DW_OutStoreDetail)NewObject <DW_OutStoreDetail>().getmodel(detailID);
                if (outStoreDetail != null)
                {
                    DW_OutStoreHead outStoreHead = (DW_OutStoreHead)NewObject <DW_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 "142":    //盘点审核
                DW_AuditDetail auditDetail = (DW_AuditDetail)NewObject <DW_AuditDetail>().getmodel(detailID);
                if (auditDetail != null)
                {
                    DW_AuditHead auditHead = (DW_AuditHead)NewObject <DW_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 "151":    //药库调价
                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);
        }
コード例 #3
0
        /// <summary>
        /// 审核药库盘点单
        /// </summary>
        /// <param name="deptId">库房ID</param>
        /// <param name="auditEmpID">审核人ID</param>
        /// <param name="auditEmpName">审核人姓名</param>
        /// <returns>单据处理结果</returns>
        public override DGBillResult AuditBill(int deptId, int auditEmpID, string auditEmpName)
        {
            string serialNO = string.Empty;//审核单据号

            //1.检查库房状态是否处于盘点状态
            int checkStatus = NewDao <SqlDWDao>().GetStoreRoomStatus(deptId);

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

            //2.提取所有未审核的单据返回DataTable;
            DataTable dtNotAuditDetail = NewDao <SqlDWDao>().GetAllNotAuditDetail(deptId);

            //3.创建盘点审核单据头
            DW_AuditHead auditHead = NewObject <DW_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, DGConstant.OP_DW_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        = DGConstant.OP_DW_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、按盘点审核单内容更新药库库存
            DGBillResult result = new DGBillResult();

            foreach (DataRow drNotAuditRow in dtNotAuditDetail.Rows)
            {
                DW_AuditDetail auditdetail = NewObject <DW_AuditDetail>();
                auditdetail.DrugStoreID   = Convert.ToInt32(drNotAuditRow["DrugStoreID"]);
                auditdetail.CTypeID       = Convert.ToInt32(drNotAuditRow["CTypeID"]);
                auditdetail.DrugID        = Convert.ToInt32(drNotAuditRow["DrugID"]);
                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.DrugID       = auditdetail.DrugID;
                storeParam.RetailPrice  = auditdetail.RetailPrice;
                storeParam.StockPrice   = auditdetail.StockPrice;
                storeParam.UnitID       = auditdetail.UnitID;
                storeParam.UnitName     = auditdetail.UnitName;
                storeParam.ValidityTime = auditdetail.ValidityDate;
                DGStoreResult storeRtn = iStore.AddStore(storeParam);
                if (storeRtn.Result != 0)
                {
                    result.Result = 1;
                    if (storeRtn.Result == 1)
                    {
                        result.LstNotEnough = new List <DGNotEnough>();
                        DGNotEnough notEnough = new DGNotEnough();
                        notEnough.DeptID     = auditdetail.DeptID;
                        notEnough.DrugID     = auditdetail.DrugID;
                        notEnough.LackAmount = storeRtn.StoreAmount + auditdetail.FactAmount - auditdetail.ActAmount;
                        notEnough.DrugInfo   = "药品批次号:" + auditdetail.BatchNO.ToString();
                        result.LstNotEnough.Add(notEnough);
                        result.ErrMsg = "【" + notEnough.DrugInfo + "】库存不足";
                    }
                    else
                    {
                        result.ErrMsg = "药品更新库存出错";
                    }

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

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

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

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

            return(result);
        }