Exemple #1
0
        public void InsertInfoExcel(string billNo, DataTable infoTable)
        {
            IMaterialRequisitionServer billServer    = ServerModuleFactory.GetServerModule <IMaterialRequisitionServer>();
            BillNumberControl          billNoControl = new BillNumberControl("领料单", billServer);
            DepotManagementDataContext ctx           = CommentParameter.DepotDataContext;

            ctx.Connection.Open();
            ctx.Transaction = ctx.Connection.BeginTransaction();

            IStoreServer storeService = ServerModuleFactory.GetServerModule <IStoreServer>();

            try
            {
                List <string> lstStorage = new List <string>();

                if (infoTable.Columns.Contains("库房"))
                {
                    lstStorage = DataSetHelper.ColumnsToList_Distinct(infoTable, "库房");

                    foreach (string storage in lstStorage)
                    {
                        string temp = UniversalFunction.GetStorageID(storage);

                        if (temp.Trim().Length == 0)
                        {
                            throw new Exception("【库房名称】:" + storage + "有误, 无法匹配到库房ID");
                        }
                    }
                }

                if (!infoTable.Columns.Contains("物品ID"))
                {
                    infoTable.Columns.Add("物品ID");

                    foreach (DataRow dr in infoTable.Rows)
                    {
                        int goodsID = UniversalFunction.GetGoodsID(dr["图号型号"] == null ? "" : dr["图号型号"].ToString(),
                                                                   dr["物品名称"] == null ? "" : dr["物品名称"].ToString(),
                                                                   dr["规格"] == null ? "" : dr["规格"].ToString());

                        if (goodsID == 0)
                        {
                            throw new Exception(string.Format("【图号型号】:{0} 【物品名称】:{1} 【规格】:{2}有误," +
                                                              " 无法匹配到物品ID", dr["图号型号"], dr["物品名称"], dr["规格"]));
                        }

                        dr["物品ID"] = goodsID;
                    }
                }

                var varData = from a in ctx.S_MaterialRequisition
                              where a.Bill_ID == billNo
                              select a;

                if (varData.Count() != 1)
                {
                    throw new Exception("无法获取【单据号】: " + billNo + " 的基本信息");
                }

                S_MaterialRequisition requisition = varData.Single();

                if (BillIsFinish(ctx, requisition.Bill_ID))
                {
                    throw new Exception("单据已完成,无法进行操作");
                }

                if (lstStorage.Count == 0)
                {
                    lstStorage.Add(UniversalFunction.GetStorageName(requisition.StorageID));
                }

                foreach (string storage in lstStorage)
                {
                    DataTable tempTable = infoTable;

                    if (lstStorage.Count > 1)
                    {
                        tempTable = DataSetHelper.SiftDataTable(infoTable, "库房 = '" + storage + "'");
                    }

                    string tempBillNo = "";
                    string storageID  = UniversalFunction.GetStorageID(storage);

                    if (requisition.StorageID != storageID)
                    {
                        S_MaterialRequisition tempRequisition = new S_MaterialRequisition();

                        tempBillNo = billNoControl.GetNewBillNo(ctx);

                        tempRequisition.Bill_ID             = tempBillNo;
                        tempRequisition.AssociatedBillNo    = requisition.AssociatedBillNo;
                        tempRequisition.AssociatedBillType  = requisition.AssociatedBillType;
                        tempRequisition.AuthorizeDate       = requisition.AuthorizeDate;
                        tempRequisition.AuthorizePersonnel  = requisition.AuthorizePersonnel;
                        tempRequisition.Bill_Time           = requisition.Bill_Time;
                        tempRequisition.BillStatus          = requisition.BillStatus;
                        tempRequisition.Department          = requisition.Department;
                        tempRequisition.DepartmentDirector  = requisition.DepartmentDirector;
                        tempRequisition.DepotManager        = requisition.DepotManager;
                        tempRequisition.FetchCount          = requisition.FetchCount;
                        tempRequisition.FetchType           = requisition.FetchType;
                        tempRequisition.FillInPersonnel     = requisition.FillInPersonnel;
                        tempRequisition.FillInPersonnelCode = requisition.FillInPersonnelCode;
                        tempRequisition.OutDepotDate        = requisition.OutDepotDate;
                        tempRequisition.ProductType         = requisition.ProductType;
                        tempRequisition.PurposeCode         = requisition.PurposeCode;
                        tempRequisition.Remark                = requisition.Remark;
                        tempRequisition.StorageID             = storageID;
                        tempRequisition.TechnologistDate      = requisition.TechnologistDate;
                        tempRequisition.TechnologistPersonnel = requisition.TechnologistPersonnel;

                        ctx.S_MaterialRequisition.InsertOnSubmit(tempRequisition);
                        ctx.SubmitChanges();
                    }
                    else
                    {
                        tempBillNo = billNo;
                    }

                    foreach (DataRow dr in tempTable.Rows)
                    {
                        S_MaterialRequisitionGoods goodsInfo = new S_MaterialRequisitionGoods();

                        goodsInfo.RequestCount = dr["数量"] == null ? 0 : Convert.ToDecimal(dr["数量"]);
                        goodsInfo.BatchNo      = dr["批次号"] == null ? "" : dr["批次号"].ToString();

                        if (dr["物品ID"] == null || Convert.ToInt32(dr["物品ID"]) == 0)
                        {
                            throw new Exception("【物品ID】无效");
                        }

                        goodsInfo.GoodsID = Convert.ToInt32(dr["物品ID"]);
                        goodsInfo.Bill_ID = tempBillNo;

                        StoreQueryCondition condition = new StoreQueryCondition();

                        condition.BatchNo   = goodsInfo.BatchNo;
                        condition.GoodsID   = goodsInfo.GoodsID;
                        condition.StorageID = storageID;

                        S_Stock stockInfo = storeService.GetStockInfo(condition);

                        if (stockInfo == null)
                        {
                            throw new Exception(string.Format("【物品ID】:{0} 【批次号】:{1} 【库房】:{2} 未找到匹配的库存记录",
                                                              goodsInfo.GoodsID, goodsInfo.BatchNo, storage));
                        }

                        goodsInfo.ProviderCode = stockInfo.Provider;
                        goodsInfo.BasicCount   = 0;
                        goodsInfo.Remark       = "由Excel导入";
                        goodsInfo.RepairStatus = null;
                        goodsInfo.RealCount    = goodsInfo.RequestCount;
                        goodsInfo.ShowPosition = 1;

                        ctx.S_MaterialRequisitionGoods.InsertOnSubmit(goodsInfo);
                        ctx.SubmitChanges();
                    }
                }

                ctx.SubmitChanges();
                ctx.Transaction.Commit();
            }
            catch (Exception ex)
            {
                ctx.Transaction.Rollback();
                throw new Exception(ex.Message);
            }
        }
Exemple #2
0
        /// <summary>
        /// 赋值账务信息
        /// </summary>
        /// <param name="context">数据上下文</param>
        /// <param name="bill">单据信息</param>
        /// <param name="item">明细信息</param>
        /// <returns>返回账务信息对象</returns>
        public S_FetchGoodsDetailBill AssignDetailInfo(DepotManagementDataContext context, S_MaterialRequisition bill,
                                                       S_MaterialRequisitionGoods item)
        {
            IBillTypeServer server   = ServerModuleFactory.GetServerModule <IBillTypeServer>();
            BASE_BillType   billType = server.GetBillTypeFromName("领料单");

            if (billType == null)
            {
                throw new Exception("获取不到单据类型信息");
            }

            View_Department           department       = UniversalFunction.GetDeptInfo(context, bill.Department);
            IStoreServer              storeServer      = ServerModuleFactory.GetServerModule <IStoreServer>();
            IProductLendReturnService serverLendReturn = ServerModuleFactory.GetServerModule <IProductLendReturnService>();
            F_GoodsPlanCost           basicGoods       = m_basicGoodsServer.GetGoodsInfo(context, item.GoodsID);

            if (basicGoods == null)
            {
                throw new Exception(string.Format("物品ID [{0}] 的物品在基础物品表中没有查到,请与系统管理员联系!", item.GoodsID));
            }

            StoreQueryCondition condition = new StoreQueryCondition();

            condition.GoodsID   = item.GoodsID;
            condition.Provider  = item.ProviderCode;
            condition.BatchNo   = item.BatchNo;
            condition.StorageID = bill.StorageID;

            S_Stock stock = storeServer.GetStockInfoOverLoad(context, condition);

            if (stock == null && GlobalObject.GeneralFunction.IsNullOrEmpty(basicGoods.GoodsType))
            {
                throw new Exception(string.Format("图号:{0}, 名称:{1}, 规格:{2}, 供应商:{3}, 批次号:{4} 的物品在库存中没有查到相关物品,请仓管员核实!",
                                                  basicGoods.GoodsCode, basicGoods.GoodsName, basicGoods.Spec, item.ProviderCode, item.BatchNo));
            }

            //S_FetchGoodsDetailBill用于存放每次领料、领料退库的明细信息
            decimal dcRealCount = item.RealCount;
            decimal dcSumCount  = 0;

            var varData = from a in context.View_S_MaterialRequisitionProductReturnList
                          where a.单据号 == item.Bill_ID &&
                          a.还账物品ID == item.GoodsID &&
                          a.还账物品批次号 == item.BatchNo &&
                          a.还账物品供应商 == item.ProviderCode
                          select a;

            if (varData.Count() > 0)
            {
                dcSumCount = varData.Sum(a => a.还账数量);

                if (dcRealCount < dcSumCount)
                {
                    throw new Exception("实际领用数量不能大于还货数量,请重新核对");
                }
            }

            S_FetchGoodsDetailBill detailBill = new S_FetchGoodsDetailBill();

            detailBill.ID                 = Guid.NewGuid();
            detailBill.FetchBIllID        = bill.Bill_ID;
            detailBill.BillTime           = (DateTime)bill.OutDepotDate;
            detailBill.AssociatedBillType = bill.AssociatedBillType;
            detailBill.AssociatedBillNo   = bill.AssociatedBillNo;
            detailBill.Department         = department.部门名称;
            detailBill.FetchCount         = item.RealCount;
            detailBill.GoodsID            = item.GoodsID;
            detailBill.StorageID          = bill.StorageID;
            detailBill.Price              = dcSumCount;
            detailBill.UnitPrice          = stock == null ? 0 : stock.UnitPrice;
            detailBill.OperationType      = (int)CE_SubsidiaryOperationType.领料;
            detailBill.Provider           = item.ProviderCode;

            if (stock != null)
            {
                detailBill.ProviderBatchNo = stock.ProviderBatchNo;
            }
            else
            {
                detailBill.ProviderBatchNo = "";
            }

            detailBill.BatchNo = item.BatchNo;

            detailBill.FillInPersonnel  = bill.FillInPersonnel;
            detailBill.FinanceSignatory = null;
            detailBill.DepartDirector   = bill.DepartmentDirector;
            detailBill.DepotManager     = bill.DepotManager;
            detailBill.Remark           = (bill.Remark == null ? "" : bill.Remark.Trim()) + (item.Remark == null ? "" : item.Remark.Trim());
            detailBill.FillInDate       = bill.Bill_Time;

            IMaterialRequisitionPurposeServer purposeServer =
                ServerModuleFactory.GetServerModule <IMaterialRequisitionPurposeServer>();

            detailBill.Using = purposeServer.GetBillPurpose(context, bill.PurposeCode).Purpose;

            return(detailBill);
        }
        /// <summary>
        /// 自动插入报检入库单
        /// </summary>
        /// <param name="dateTable">需要插入的数据集</param>
        /// <param name="storageID">库房ID</param>
        /// <param name="version">版次号</param>
        /// <param name="error">出错时返回错误信息,无错时返回null</param>
        /// <returns>操作成功返回True,操作失败返回False</returns>
        public bool AddCheckInDepotBill(DataTable dateTable, string storageID, string version, out string error)
        {
            error = null;

            BargainInfoServer serverBargainInfo = new BargainInfoServer();

            CheckOutInDepotServer serverCheckInDepot = new CheckOutInDepotServer();

            try
            {
                string strBatchNo = serverCheckInDepot.GetNextBillNo(1);

                DepotManagementDataContext dataContext = CommentParameter.DepotDataContext;

                for (int i = 0; i < dateTable.Rows.Count; i++)
                {
                    S_CheckOutInDepotBill bill = new S_CheckOutInDepotBill();

                    decimal dcUnitPrice = serverBargainInfo.GetBargainUnitPrice(dateTable.Rows[i]["订单号"].ToString(),
                                                                                Convert.ToInt32(dateTable.Rows[i]["物品ID"]));

                    F_GoodsPlanCost lnqGoods = ServerModuleFactory.GetServerModule <IBasicGoodsServer>().GetGoodsInfo(
                        Convert.ToInt32(dateTable.Rows[i]["物品ID"]));

                    bill.Bill_ID              = GetBillID(strBatchNo, i);
                    bill.OrderFormNumber      = dateTable.Rows[i]["订单号"].ToString();
                    bill.ArriveGoods_Time     = ServerTime.Time;                            // 到货日期
                    bill.Bill_Time            = ServerTime.Time;                            // 报检日期
                    bill.BillStatus           = CheckInDepotBillStatus.新建单据.ToString();
                    bill.Buyer                = dateTable.Rows[i]["订货人"].ToString();        // 采购员签名
                    bill.DeclarePersonnelCode = dateTable.Rows[i]["订货人编号"].ToString();      // 报检员编码
                    bill.DeclarePersonnel     = dateTable.Rows[i]["订货人"].ToString();        // 报检员签名
                    bill.DeclareCount         = Convert.ToInt32(dateTable.Rows[i]["到货数量"]); // 报检数
                    bill.Provider             = dateTable.Rows[i]["供应商"].ToString();        // 供应商编码
                    bill.ProviderBatchNo      = "";                                         // 供应商批次
                    bill.GoodsID              = (int)dateTable.Rows[i]["物品ID"];
                    bill.BatchNo              = strBatchNo + "Auto";                        // xsy, 没有废除OA前暂用
                    bill.Remark               = "由自动订单自动生成的报检入库单";
                    bill.CheckOutGoodsType    = 1;
                    bill.OnlyForRepairFlag    = false;
                    bill.UnitPrice            = dcUnitPrice;
                    bill.Price                = decimal.Round(bill.UnitPrice * Convert.ToDecimal(dateTable.Rows[i]["到货数量"]), 2);
                    bill.PlanUnitPrice        = Convert.ToDecimal(lnqGoods.GoodsUnitPrice);
                    bill.PlanPrice            = decimal.Round(bill.PlanUnitPrice * Convert.ToDecimal(dateTable.Rows[i]["到货数量"]), 2);
                    bill.TotalPrice           = CalculateClass.GetTotalPrice(bill.Price);
                    bill.StorageID            = storageID;
                    bill.Version              = version;
                    bill.IsExigenceCheck      = false;
                    bill.UnitInvoicePrice     = 0;
                    bill.InvoicePrice         = 0;

                    if (UniversalFunction.GetStorageInfo_View(bill.StorageID).零成本控制)
                    {
                        throw new Exception("【零成本】库房,无法通过【报检入库单】入库");
                    }

                    dataContext.S_CheckOutInDepotBill.InsertOnSubmit(bill);
                }

                dataContext.SubmitChanges();

                return(true);
            }
            catch (Exception ex)
            {
                error = ex.Message;
                return(false);
            }
        }
Exemple #4
0
        /// <summary>
        /// 修改订单信息
        /// </summary>
        /// <param name="listRole">角色列表</param>
        /// <param name="loginName">登录名</param>
        /// <param name="oldOrderFormNumber">旧订单号</param>
        /// <param name="orderFormInfo">订单信息</param>
        /// <param name="returnOrderFormInfo">返回查询到的订单信息</param>
        /// <param name="error">错误信息, 没有则为null</param>
        /// <returns>操作是否成功的标志</returns>
        public bool UpdateOrderFormInfo(List <string> listRole, string loginName, string oldOrderFormNumber,
                                        B_OrderFormInfo orderFormInfo, out IQueryable <View_B_OrderFormInfo> returnOrderFormInfo, out string error)
        {
            returnOrderFormInfo = null;
            error = null;

            DepotManagementDataContext dataContxt = CommentParameter.DepotDataContext;

            try
            {
                var result = from r in dataContxt.B_OrderFormInfo where r.OrderFormNumber == oldOrderFormNumber select r;

                if (result.Count() == 0)
                {
                    error = string.Format("找不到订单号为 [{0}] 的信息!", oldOrderFormNumber);
                    return(false);
                }

                B_OrderFormInfo record = result.Single();

                IOrderFormGoodsServer goodsServer = ServerModuleFactory.GetServerModule <IOrderFormGoodsServer>();

                if (oldOrderFormNumber != orderFormInfo.OrderFormNumber)
                {
                    IQueryable <View_B_OrderFormGoods> returnOrderFormGoods;

                    if (!goodsServer.GetOrderFormGoods(listRole, loginName, oldOrderFormNumber,
                                                       out returnOrderFormGoods, out error))
                    {
                        return(false);
                    }

                    goodsServer.AutoSubmitToDatabase = false;

                    foreach (var item in returnOrderFormGoods)
                    {
                        if (!goodsServer.UpdateOrderFormNumber(dataContxt, listRole, loginName, item.序号,
                                                               orderFormInfo.OrderFormNumber, out error))
                        {
                            return(false);
                        }
                    }

                    dataContxt.B_OrderFormInfo.DeleteOnSubmit(record);
                    record = new B_OrderFormInfo();
                }

                record.OrderFormNumber = orderFormInfo.OrderFormNumber;
                record.Provider        = orderFormInfo.Provider;
                record.Buyer           = orderFormInfo.Buyer;
                record.BargainNumber   = orderFormInfo.BargainNumber;
                record.TypeID          = orderFormInfo.TypeID;
                record.InputPerson     = orderFormInfo.InputPerson;
                record.ProviderLinkman = orderFormInfo.ProviderLinkman;
                record.ProviderEmail   = orderFormInfo.ProviderEmail;
                record.ProviderPhone   = orderFormInfo.ProviderPhone;
                record.ProviderFax     = orderFormInfo.ProviderFax;
                record.Remark          = orderFormInfo.Remark;
                record.TypeID          = orderFormInfo.TypeID;
                record.CreateDate      = orderFormInfo.CreateDate;

                if (oldOrderFormNumber != orderFormInfo.OrderFormNumber)
                {
                    dataContxt.B_OrderFormInfo.InsertOnSubmit(record);
                }

                dataContxt.SubmitChanges();

                goodsServer.AutoSubmitToDatabase = true;

                return(GetAllOrderFormInfo(listRole, loginName, out returnOrderFormInfo, out error));
            }
            catch (Exception exce)
            {
                error = exce.Message;
                return(false);
            }
        }
        /// <summary>
        /// 完成领料退库单
        /// </summary>
        /// <param name="billNo">单据号</param>
        /// <param name="storeManager">仓库管理员</param>
        /// <param name="returnBill">返回更新后重新查询的领料退库单数据集</param>
        /// <param name="error">出错时返回错误信息,无错时返回null</param>
        /// <returns>返回是否成功添加领料退库单</returns>
        public bool FinishBill(string billNo, string storeManager, out IQueryResult returnBill, out string error)
        {
            returnBill = null;
            error      = null;

            try
            {
                DepotManagementDataContext ctx = CommentParameter.DepotDataContext;

                if (!FinishFrock(ctx, billNo, out error))
                {
                    return(false);
                }

                //检查总成领用数量是否都设置了流水码
                if (!m_serverProductCode.IsFitCountInReturnBill(billNo, out error))
                {
                    return(false);
                }

                var result = from r in ctx.S_MaterialReturnedInTheDepot where r.Bill_ID == billNo select r;

                if (result.Count() == 0)
                {
                    error = string.Format("没有找到单据号为 {0} 的领料退库单信息,无法进行此操作", billNo);
                    return(false);
                }

                S_MaterialReturnedInTheDepot bill = result.Single();

                if (bill.BillStatus == MaterialReturnedInTheDepotBillStatus.已完成.ToString())
                {
                    error = "单据不能重复退库";
                    return(false);
                }

                bill.DepotManager = storeManager;
                bill.BillStatus   = MaterialReturnedInTheDepotBillStatus.已完成.ToString();
                bill.InDepotDate  = ServerTime.Time;

                if (bill.ReturnMode == "领料退库")
                {
                    DetailCheck(ctx, bill);//在退库模式为领料退库的模式情况下,只能退库房存在的库存记录的物品
                }

                IMaterialListReturnedInTheDepot goodsServer = ServerModuleFactory.GetServerModule <IMaterialListReturnedInTheDepot>();

                //操作账务信息与库存信息
                OpertaionDetailAndStock(ctx, bill);

                //操作总成库存状态
                var varList = from a in ctx.S_MaterialListReturnedInTheDepot
                              where a.Bill_ID == bill.Bill_ID
                              select a;

                foreach (var item in varList)
                {
                    bool blIsRepaired = false;

                    if (bill.StorageID == "05" && Convert.ToBoolean(item.RepairStatus))
                    {
                        blIsRepaired = true;
                    }

                    if (!m_serverProductCode.UpdateProductStock(ctx, bill.Bill_ID, "领料退库", bill.StorageID, blIsRepaired, item.GoodsID, out error))
                    {
                        return(false);
                    }

                    IStoreServer serverStore = ServerModuleFactory.GetServerModule <IStoreServer>();

                    YX_AfterServiceStock lnqAfterService = new YX_AfterServiceStock();

                    lnqAfterService.GoodsID        = item.GoodsID;
                    lnqAfterService.OperationCount = Convert.ToDecimal(item.ReturnedAmount);
                    lnqAfterService.RepairStatus   = Convert.ToBoolean(item.RepairStatus);
                    lnqAfterService.StorageID      = bill.StorageID;

                    if (!serverStore.OperationYXAfterService(ctx, lnqAfterService, out error))
                    {
                        return(false);
                    }
                }

                // 正式使用单据号
                m_assignBill.UseBillNo(ctx, "领料退库单", bill.Bill_ID);

                ctx.SubmitChanges();

                return(GetAllBill(out returnBill, out error));
            }
            catch (Exception exce)
            {
                error = exce.Message;
                return(false);
            }
        }