Пример #1
0
        /// <summary>
        /// 更新采购单
        /// </summary>
        /// <param name="inputDto"></param>
        /// <returns></returns>
        public ReturnInfo UpdateSalesOrder(ConSalesOrderInputDto inputDto)
        {
            ReturnInfo    RInfo = new ReturnInfo();
            StringBuilder sb    = new StringBuilder();
            ConSalesOrder Order = _ConSalesOrderReposity.GetById(inputDto.SOID).FirstOrDefault();

            if (Order == null)
            {
                sb.Append("该采购单不存在,请检查!");
                RInfo.IsSuccess = false;
                RInfo.ErrorInfo = sb.ToString();
                return(RInfo);
            }
            else      //采购单存在
            {
                Order.REALID      = inputDto.REALID;
                Order.NAME        = inputDto.NAME;
                Order.CUSID       = inputDto.CUSID;
                Order.SALESPERSON = inputDto.SALESPERSON;
                Order.MODIFYDATE  = inputDto.MODIFYDATE;
                Order.MODIFYUSER  = inputDto.MODIFYUSER;
                _unitOfWork.RegisterDirty(Order);

                //如果原来存在行项,则先删除
                List <ConSalesOrderRow> Rows = _ConSalesOrderRowReposity.GetBySOID(inputDto.SOID).ToList();
                if (Rows.Count > 0)    //如果存在行项
                {
                    foreach (ConSalesOrderRow Row in Rows)
                    {
                        _unitOfWork.RegisterDeleted(Row);
                    }
                }
                ///添加新的选择行项
                foreach (ConSalesOrderRowInputDto Row in inputDto.RowData)
                {
                    ConSalesOrderRow salesOrderRow = new ConSalesOrderRow();
                    salesOrderRow            = Mapper.Map <ConSalesOrderRowInputDto, ConSalesOrderRow>(Row);
                    salesOrderRow.SOID       = inputDto.SOID;
                    salesOrderRow.CREATEUSER = inputDto.CREATEUSER;
                    salesOrderRow.CREATEDATE = DateTime.Now;
                    salesOrderRow.MODIFYUSER = inputDto.MODIFYUSER;
                    salesOrderRow.MODIFYDATE = DateTime.Now;
                    salesOrderRow.STATUS     = 0;
                    _unitOfWork.RegisterNew(salesOrderRow);
                }
                try
                {
                    _unitOfWork.Commit();
                    RInfo.IsSuccess = true;
                    return(RInfo);
                }
                catch (Exception ex)
                {
                    sb.Append(ex.Message);
                    RInfo.IsSuccess = false;
                    RInfo.ErrorInfo = sb.ToString();
                    return(RInfo);
                }
            }
        }
Пример #2
0
        /// <summary>
        /// 删除销售单
        /// </summary>
        /// <param name="SOID"></param>
        /// <returns></returns>
        public ReturnInfo DeleteSalesOrder(string SOID)
        {
            ReturnInfo    RInfo = new ReturnInfo();
            StringBuilder sb    = new StringBuilder();
            ConSalesOrder Order = _ConSalesOrderReposity.GetById(SOID).FirstOrDefault();

            if (Order == null)
            {
                sb.Append("未找到该销售单!");
                RInfo.IsSuccess = false;
                RInfo.ErrorInfo = sb.ToString();
                return(RInfo);
            }
            else
            {
                ///根据销售单状态进行操作
                if (Order.STATUS == (int)SalesOrderStatus.销售中)
                {
                    _unitOfWork.RegisterDeleted(Order);

                    List <ConSalesOrderRow> Rows = _ConSalesOrderRowReposity.GetBySOID(SOID).ToList();
                    if (Rows.Count > 0)    //如果存在行项
                    {
                        foreach (ConSalesOrderRow Row in Rows)
                        {
                            _unitOfWork.RegisterDeleted(Row);
                        }
                    }
                    //可以删除
                    try
                    {
                        _unitOfWork.Commit();
                        RInfo.IsSuccess = true;
                        return(RInfo);
                    }
                    catch (Exception ex)
                    {
                        _unitOfWork.Rollback();
                        sb.Append(ex.Message);
                        RInfo.IsSuccess = false;
                        RInfo.ErrorInfo = sb.ToString();
                        return(RInfo);
                    }
                }
                else
                {
                    sb.Append("已经开始采购,无法删除采购单!");
                    RInfo.IsSuccess = false;
                    RInfo.ErrorInfo = sb.ToString();
                    return(RInfo);
                }
            }
        }
Пример #3
0
        /// <summary>
        /// 创建销售单
        /// </summary>
        /// <param name="inputDto"></param>
        /// <returns></returns>
        public ReturnInfo AddSalesOrder(ConSalesOrderInputDto inputDto)
        {
            ReturnInfo RInfo = new ReturnInfo();

            if (string.IsNullOrEmpty(inputDto.NAME))
            {
                throw new Exception("销售单名称不能为空!");
            }
            if (string.IsNullOrEmpty(inputDto.SALESPERSON))
            {
                throw new Exception("请选择销售人!");
            }
            String MaxID = _ConSalesOrderReposity.GetMaxID();       //获取最大采购单ID
            String NowID = Helper.GenerateID("SO", MaxID);

            //产生销售单编号
            inputDto.SOID = NowID;
            try
            {
                ConSalesOrder salesOrder = new ConSalesOrder();
                salesOrder        = Mapper.Map <ConSalesOrderInputDto, ConSalesOrder>(inputDto);
                salesOrder.STATUS = 0;
                _unitOfWork.RegisterNew(salesOrder);

                foreach (var Row in inputDto.RowData)
                {
                    ConSalesOrderRow salesOrderRow = new ConSalesOrderRow();
                    salesOrderRow            = Mapper.Map <ConSalesOrderRowInputDto, ConSalesOrderRow>(Row);
                    salesOrderRow.SOID       = NowID;
                    salesOrderRow.CREATEUSER = inputDto.CREATEUSER;
                    salesOrderRow.CREATEDATE = DateTime.Now;
                    salesOrderRow.MODIFYUSER = inputDto.MODIFYUSER;
                    salesOrderRow.MODIFYDATE = DateTime.Now;
                    salesOrderRow.STATUS     = 0;
                    _unitOfWork.RegisterNew(salesOrderRow);
                }
                bool result = _unitOfWork.Commit();
                RInfo.IsSuccess = result;
                RInfo.ErrorInfo = inputDto.SOID;
                return(RInfo);
            }
            catch (Exception ex)
            {
                _unitOfWork.Rollback();
                RInfo.IsSuccess = false;
                RInfo.ErrorInfo = ex.Message;
                return(RInfo);
            }
        }
Пример #4
0
        /// <summary>
        /// 耗材销售单出库
        /// </summary>
        /// <param name="entity"></param>
        /// <returns></returns>
        public ReturnInfo OutboundConSalesOrder(ConSOOutboundInputDto entity)
        {
            ReturnInfo    RInfo    = new ReturnInfo();
            StringBuilder sb       = new StringBuilder();
            int           thisOver = 0; //此次完成出库的行项数

            foreach (ConSalesOrderRowInputDto Row in entity.RowDatas)
            {
                decimal quantSum = _ConQuantRepository.GetSumByCID(Row.CID);
                if (quantSum < Row.QUANTOUT)
                {
                    throw new Exception("耗材" + Row.CID + "库存不足,请先补充库存!");
                }
                List <ConQuant> conQuantList = _ConQuantRepository.GetQuantByCID(Row.CID).ToList();
                decimal         quantOut     = Row.QUANTOUT;
                while (quantOut > 0)
                {
                    foreach (ConQuant conQuant in conQuantList)
                    {
                        ConSalesOrderOutbound outbound = new ConSalesOrderOutbound();
                        outbound.SOID    = entity.SOID;
                        outbound.SOROWID = Row.SOROWID;
                        outbound.WAREID  = conQuant.WAREID;
                        outbound.STID    = conQuant.STID;
                        outbound.SLID    = conQuant.SLID;
                        if (conQuant.QUANTITY > quantOut)
                        {
                            conQuant.QUANTITY = conQuant.QUANTITY - quantOut;
                            _unitOfWork.RegisterDirty(conQuant);
                            outbound.QUANT = quantOut;
                            quantOut       = 0;
                            _unitOfWork.RegisterNew(outbound);
                            break;
                        }
                        else if (conQuant.QUANTITY == quantOut)
                        {
                            outbound.QUANT = quantOut;
                            _unitOfWork.RegisterDeleted(conQuant);
                            quantOut = 0;
                            _unitOfWork.RegisterNew(outbound);
                            break;
                        }
                        else
                        {
                            outbound.QUANT = conQuant.QUANTITY;
                            quantOut       = quantOut - conQuant.QUANTITY;
                            _unitOfWork.RegisterDeleted(conQuant);
                            _unitOfWork.RegisterNew(outbound);
                        }
                    }
                }

                ConSalesOrderRow orderRow = _ConSalesOrderRowReposity.GetOrderRowByCID(entity.SOID, Row.CID).FirstOrDefault();
                orderRow.QUANTOUT = orderRow.QUANTOUT + Row.QUANTOUT;
                orderRow.STATUS   = (int)SalesOrderStatus.出库中;
                if (orderRow.QUANTOUT == orderRow.QUANTSALED)
                {
                    orderRow.STATUS = (int)PurchaseOrderStatus.已完成;
                    thisOver       += 1;
                }
                if (orderRow.QUANTOUT > orderRow.QUANTSALED)
                {
                    throw new Exception("出库数量不可大于实际销售数量!");
                }
                _unitOfWork.RegisterDirty(orderRow);
            }

            ConSalesOrder conSalesOrder = _ConSalesOrderReposity.GetById(entity.SOID).AsNoTracking().FirstOrDefault();
            int           allRowsCount  = _ConSalesOrderRowReposity.GetBySOID(entity.SOID).ToList().Count;
            int           hasOverCount  = _ConSalesOrderRowReposity.GetOrderRowsByStatus(entity.SOID, (int)PurchaseOrderStatus.已完成).ToList().Count;

            if (allRowsCount == hasOverCount + thisOver)
            {
                conSalesOrder.STATUS = (int)PurchaseOrderStatus.已完成;
            }
            else
            {
                conSalesOrder.STATUS = (int)PurchaseOrderStatus.入库中;
            }
            _unitOfWork.RegisterDirty(conSalesOrder);
            try
            {
                _unitOfWork.Commit();
                RInfo.IsSuccess = true;
                return(RInfo);
            }
            catch (Exception ex)
            {
                _unitOfWork.Rollback();
                sb.Append(ex.Message);
                RInfo.IsSuccess = false;
                RInfo.ErrorInfo = sb.ToString();
                return(RInfo);
            }
        }