/// <summary>
        /// 台账写入
        /// </summary>
        /// <typeparam name="THead">药房入库单表头模板</typeparam>
        /// <typeparam name="TDetail">药房入库单明细模板</typeparam>
        /// <param name="billHead">药房入库单表头</param>
        /// <param name="billDetails">药房入库单明细</param>
        /// <param name="storeResult">库存处理结果</param>
        /// <param name="packAmount">包装系数</param>
        public void WriteAccount <THead, TDetail>(THead billHead, TDetail billDetails, DGStoreResult storeResult, decimal packAmount)
        {
            //1、构建台账表实体;
            //2、根据台账表内容填写相应的信息;
            //3、保存台账表
            DS_InStoreDetail detail = billDetails as DS_InStoreDetail;
            DS_InstoreHead   head   = billHead as DS_InstoreHead;

            int    actYear;
            int    actMonth;
            string errMsg;

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

            packAmount = packAmount > 0 ? packAmount : GetPackAmount(detail.DrugID);
            DS_Account account = NewObject <DS_Account>();

            account.BalanceYear  = actYear;
            account.BalanceMonth = actMonth;
            account.AccountType  = 0;
            account.BalanceFlag  = 0;
            account.BillNO       = head.BillNO;
            account.BatchNO      = detail.BatchNO;
            account.BusiType     = head.BusiType;
            account.CTypeID      = detail.CTypeID;
            account.DeptID       = head.DeptID;
            account.DetailID     = detail.InDetailID;
            account.DrugID       = detail.DrugID;
            account.UnitID       = detail.UnitID;
            account.UnitName     = detail.UnitName;
            account.RegTime      = System.DateTime.Now;
            account.UnitAmount   = Convert.ToInt32(packAmount);

            if (head.BusiType == DGConstant.OP_DS_RETURNSOTRE)
            {
                account.StockPrice    = storeResult.BatchAllot[0].StockPrice;
                account.RetailPrice   = storeResult.BatchAllot[0].RetailPrice;
                account.LendAmount    = detail.Amount;
                account.LendRetailFee = detail.Amount * (account.RetailPrice / packAmount);
                account.LendStockFee  = detail.Amount * (account.StockPrice / packAmount);
            }
            else
            {
                account.StockPrice    = detail.StockPrice;
                account.RetailPrice   = detail.RetailPrice;
                account.LendAmount    = detail.Amount;
                account.LendRetailFee =
                    detail.Amount * (account.RetailPrice / packAmount);
                account.LendStockFee = detail.Amount * (account.StockPrice / packAmount);
            }

            account.OverAmount    = storeResult.BatchAllot[0].StoreAmount;
            account.OverStockFee  = storeResult.BatchAllot[0].StoreAmount * (account.StockPrice / packAmount);
            account.OverRetailFee = storeResult.BatchAllot[0].StoreAmount * (account.RetailPrice / packAmount);
            account.save();
        }
Exemple #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 "011":    //采购入库
            case "012":    //期初入库
            case "013":    //流通入库
                DS_InStoreDetail inStoreDetail = (DS_InStoreDetail)NewObject <DS_InStoreDetail>().getmodel(detailID);
                if (inStoreDetail != null)
                {
                    DS_InstoreHead instoreHead = (DS_InstoreHead)NewObject <DS_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 "021":    //内耗出库
            case "022":    //报损出库
                DS_OutStoreDetail outStoreDetail = (DS_OutStoreDetail)NewObject <DS_OutStoreDetail>().getmodel(detailID);
                if (outStoreDetail != null)
                {
                    DS_OutStoreHead outStoreHead = (DS_OutStoreHead)NewObject <DS_OutStoreHead>().getmodel(outStoreDetail.OutHeadID);
                    if (outStoreDetail != 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 "031":    //门诊发药
            case "032":    //门诊退药
                DS_OPDispDetail oPDispDetail = (DS_OPDispDetail)NewObject <DS_OPDispDetail>().getmodel(detailID);
                if (oPDispDetail != null)
                {
                    DS_OPDispHead oPDispHead = (DS_OPDispHead)NewObject <DS_OPDispHead>().getmodel(oPDispDetail.DispHeadID);
                    if (oPDispHead != null)
                    {
                        shower.RegTime          = oPDispHead.DispTime;
                        shower.AuditTime        = oPDispHead.DispTime;
                        shower.BillNo           = oPDispHead.BillNO.ToString();
                        shower.RelationPeopleNo = "暂无";
                        shower.RelationPeople   = "暂无";
                        shower.RelationUnit     = oPDispHead.PresDeptName;
                        shower.RetailFee        = oPDispHead.RetailFee;
                        shower.StockFee         = 0;
                        shower.OpType           = GetBusiTypeName(opType);
                        shower.RegPeople        = oPDispHead.PharmacistName;
                        shower.Remark           = string.Empty;
                    }
                }

                break;

            case "033":    //住院发药
                DS_IPDispDetail iPDispDetail = (DS_IPDispDetail)NewObject <DS_IPDispDetail>().getmodel(detailID);
                if (iPDispDetail != null)
                {
                    DS_IPDispHead iPDispHead = (DS_IPDispHead)NewObject <DS_IPDispHead>().getmodel(iPDispDetail.DispHeadID);
                    if (iPDispHead != null)
                    {
                        shower.RegTime          = iPDispHead.DispTime;
                        shower.AuditTime        = iPDispHead.DispTime;
                        shower.BillNo           = iPDispHead.BillNO.ToString();
                        shower.RelationPeopleNo = "暂无";
                        shower.RelationPeople   = "暂无";
                        shower.RelationUnit     = GetDeptName(iPDispHead.DeptID);
                        shower.RetailFee        = iPDispHead.RetailFee;
                        shower.StockFee         = 0;
                        shower.OpType           = GetBusiTypeName(opType);
                        shower.RegPeople        = GetEmpName(iPDispHead.PharmacistID);
                        shower.Remark           = string.Empty;
                    }
                }

                break;

            case "042":    //盘点审核
                DS_AuditDetail auditDetail = (DS_AuditDetail)NewObject <DS_AuditDetail>().getmodel(detailID);
                if (auditDetail != null)
                {
                    DS_AuditHead auditHead = (DS_AuditHead)NewObject <DS_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 "051":    //药房调价
                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);
        }
Exemple #3
0
        public void SaveBill(string frmName)
        {
            Action <ClientRequestData> requestAction = null;
            ServiceResponseData        retdata       = null;

            RefreshHead(frmName);
            if (frmName == "FrmInStoreDetailDW")
            {
                currentDWHead.StockFee  = 0;
                currentDWHead.RetailFee = 0;
                List <DW_InStoreDetail> lstDetails = new List <DW_InStoreDetail>();
                for (int index = 0; index < currentDWDetails.Rows.Count; index++)
                {
                    DW_InStoreDetail detail = ConvertExtend.ToObject <DW_InStoreDetail>(currentDWDetails, index);

                    decimal pAmount = 0;

                    if (currentDWDetails.Rows[index]["pAmount"] != DBNull.Value)
                    {
                        pAmount = Convert.ToDecimal(currentDWDetails.Rows[index]["pAmount"].ToString());
                    }

                    detail.Amount            = pAmount;
                    currentDWHead.StockFee  += detail.StockFee;
                    currentDWHead.RetailFee += detail.RetailFee;
                    lstDetails.Add(detail);
                }

                requestAction = ((ClientRequestData request) =>
                {
                    request.AddData(DGConstant.OP_DW_SYSTEM);
                    request.AddData(currentDWHead.BusiType);
                    request.AddData(currentDWHead);
                    request.AddData <List <DW_InStoreDetail> >(lstDetails);
                    request.AddData <List <int> >(frmInstoreDetailDW.GetDeleteDetails());
                });
                retdata = InvokeWcfService("DrugProject.Service", "InStoreController", "SaveBill", requestAction);

                DGBillResult result = retdata.GetData <DGBillResult>(0);
                if (result.Result == 0)
                {
                    MessageBoxShowSimple("单据已经保存成功,如果没有配置自动审核.请及时审核单据");
                    if (billStatus == DGEnum.BillEditStatus.ADD_STATUS)
                    {
                        frmInstoreDetailDW.NewBillClear();
                    }
                    else
                    {
                        frmInstoreDetailDW.CloseCurrentWindow();
                    }
                }
                else
                {
                    string rtnMsg = result.ErrMsg;
                    MessageBoxShowSimple("单据保存失败:" + result.ErrMsg);
                }
            }
            else
            {
                currentDSHead.StockFee  = 0;
                currentDSHead.RetailFee = 0;
                List <DS_InStoreDetail> lstDetails = new List <DS_InStoreDetail>();
                for (int index = 0; index < currentDSDetails.Rows.Count; index++)
                {
                    DS_InStoreDetail detail = ConvertExtend.ToObject <DS_InStoreDetail>(currentDSDetails, index);

                    var uAmount = 0;
                    if (currentDSDetails.Rows[index]["uAmount"] != DBNull.Value)
                    {
                        uAmount = Convert.ToInt32(currentDSDetails.Rows[index]["uAmount"].ToString());
                    }

                    var pAmount = 0;
                    if (currentDSDetails.Rows[index]["pAmount"] != DBNull.Value)
                    {
                        pAmount = Convert.ToInt32(currentDSDetails.Rows[index]["pAmount"].ToString());
                    }

                    var packAmount = currentDSDetails.Rows[index]["packAmount"] == DBNull.Value ? 0 : Convert.ToInt32(currentDSDetails.Rows[index]["packAmount"]);
                    detail.Amount            = uAmount + (pAmount * packAmount);
                    currentDSHead.StockFee  += detail.StockFee;
                    currentDSHead.RetailFee += detail.RetailFee;
                    lstDetails.Add(detail);
                }

                requestAction = ((ClientRequestData request) =>
                {
                    request.AddData(DGConstant.OP_DS_SYSTEM);
                    request.AddData(currentDSHead.BusiType);
                    request.AddData(currentDSHead);
                    request.AddData <List <DS_InStoreDetail> >(lstDetails);
                    request.AddData <List <int> >(frmInstoreDetailDS.GetDeleteDetails());
                });
                retdata = InvokeWcfService("DrugProject.Service", "InStoreController", "SaveBill", requestAction);

                DGBillResult result = retdata.GetData <DGBillResult>(0);
                if (result.Result == 0)
                {
                    MessageBoxShowSimple("单据已经保存成功,如果没有配置自动审核.请及时审核单据");
                    if (billStatus == DGEnum.BillEditStatus.ADD_STATUS)
                    {
                        frmInstoreDetailDS.NewBillClear();
                    }
                    else
                    {
                        frmInstoreDetailDS.CloseCurrentWindow();
                    }
                }
                else
                {
                    string rtnMsg = result.ErrMsg;
                    MessageBoxShowSimple("单据保存失败:" + result.ErrMsg);
                }

                //bool result = retdata.GetData<bool>(0);
                //if (result)
                //{
                //    MessageBoxShowSimple("单据保存入库,请及时审核...");
                //    if (billStatus == DGEnum.BillEditStatus.ADD_STATUS)
                //        frmInstoreDetailDS.NewBillClear();
                //    else
                //        frmInstoreDetailDS.CloseCurrentWindow();
                //}
                //else
                //{
                //    string rtnMsg = retdata.GetData<string>(1);
                //    MessageBoxShowSimple("单据保存失败:" + rtnMsg);
                //}
            }
        }