/// <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_OutStoreDetail detail = billDetails as DW_OutStoreDetail;
            DW_OutStoreHead   head   = billHead as DW_OutStoreHead;
            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.BillNO       = detail.BillNO;
            account.BatchNO      = detail.BatchNO;
            account.BillNO       = detail.BillNO;
            account.BusiType     = head.BusiType;
            account.CTypeID      = detail.CTypeID;
            account.DeptID       = head.DeptID;
            account.DetailID     = detail.OutDetailID;
            account.DrugID       = detail.DrugID;
            account.UnitID       = detail.UnitID;
            account.UnitName     = detail.UnitName;
            account.DebitAmount  = detail.Amount;//贷方数量
            account.RegTime      = System.DateTime.Now;
            if (head.BusiType == DGConstant.OP_DW_BACKSTORE)
            {
                account.StockPrice     = storeResult.BatchAllot[0].StockPrice;
                account.RetailPrice    = storeResult.BatchAllot[0].RetailPrice;
                account.DebitAmount    = detail.Amount;
                account.DebitRetailFee = account.DebitAmount * account.RetailPrice;
                account.DebitStockFee  = account.DebitAmount * account.StockPrice;
                account.OverAmount     = storeResult.BatchAllot[0].StoreAmount;
                account.OverRetailFee  = storeResult.BatchAllot[0].StoreAmount * storeResult.BatchAllot[0].RetailPrice;
                account.OverStockFee   = storeResult.BatchAllot[0].StoreAmount * storeResult.BatchAllot[0].StockPrice;
            }
            else
            {
                account.StockPrice     = detail.StockPrice;
                account.RetailPrice    = detail.RetailPrice;
                account.DebitAmount    = detail.Amount;
                account.DebitRetailFee = detail.RetailFee;
                account.DebitStockFee  = detail.StockFee;
                account.OverAmount     = storeResult.BatchAllot[0].StoreAmount;
                account.OverRetailFee  = storeResult.BatchAllot[0].StoreAmount * account.RetailPrice;
                account.OverStockFee   = storeResult.BatchAllot[0].StoreAmount * account.StockPrice;
            }

            account.save();
        }
        /// <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);
        }
Beispiel #3
0
        public void SaveBill(string frmName)
        {
            Action <ClientRequestData> requestAction = null;
            ServiceResponseData        retdata       = null;

            RefreshHead(frmName);
            if (frmName == "FrmOutStoreDetailDW")
            {
                currentDWHead.StockFee  = 0;
                currentDWHead.RetailFee = 0;
                List <DW_OutStoreDetail> lstDetails = new List <DW_OutStoreDetail>();
                for (int index = 0; index < currentDWDetails.Rows.Count; index++)
                {
                    DW_OutStoreDetail detail = ConvertExtend.ToObject <DW_OutStoreDetail>(currentDWDetails, index);
                    var pAmount = 0;
                    if (currentDWDetails.Rows[index]["pAmount"] != DBNull.Value)
                    {
                        pAmount = Convert.ToInt32(currentDWDetails.Rows[index]["pAmount"].ToString());
                    }

                    detail.Amount            = pAmount;
                    detail.DeptID            = currentDWHead.DeptID;
                    detail.ToDeptID          = currentDWHead.ToDeptID;
                    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_OutStoreDetail> >(lstDetails);
                    request.AddData <List <int> >(frmOutstoreDetailDW.GetDeleteDetails());
                });

                if (frmOutstoreDetailDW.IsApplyStatus == true)
                {
                    retdata = InvokeWcfService("DrugProject.Service", "OutStoreController", "SaveBillFromApply", requestAction);
                }
                else
                {
                    retdata = InvokeWcfService("DrugProject.Service", "OutStoreController", "SaveBill", requestAction);
                }

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

                    detail.DeptID            = currentDSHead.DeptID;
                    detail.ToDeptID          = currentDSHead.ToDeptID;
                    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_OutStoreDetail> >(lstDetails);
                    request.AddData <List <int> >(frmOutstoreDetailDS.GetDeleteDetails());
                });
                retdata = InvokeWcfService("DrugProject.Service", "OutStoreController", "SaveBill", requestAction);

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