示例#1
0
        /// <summary>
        /// 根据采购单和采购入库单对比自动生成采购退货单     如 采购数量 大于采购入库数量       被拒件(采购数量-采购入库数量 )
        /// </summary>
        /// <param name="PurchaseNumber">采购单号</param>
        /// <param name="refNumber">入库单号</param>
        public void AutoInsertPurchaseRejectedData(string PurchaseNumber, string refNumber)
        {
            var PurchaseRejecteds = base.XMPurchaseRejectedService.GetXMPurchaseRejectedsByRef(PurchaseNumber);
            var Purchase          = base.XMPurchaseService.GetXMPurchaseBypurChaseCode(PurchaseNumber);
            var Purchasede        = base.XMPurchaseProductDetailsService.GetXMPurchaseProductDetailsByPurchaseID(Purchase[0].Id);
            var XM_Storage        = base.XMStorageService.GetXMStorageByRef(refNumber);
            var XM_Storagede      = base.XMStorageProductDetailsService.GetXMStorageProductDetailsByStorageID(XM_Storage[0].Id);
            List <StorageProductDetailInfos> Lists = new List <StorageProductDetailInfos>();

            foreach (XMStorageProductDetails paramXMStorageProductDetails in XM_Storagede)
            {
                StorageProductDetailInfos storageDeatail = new StorageProductDetailInfos();
                var Purchasedeone = Purchasede.Where(p => p.PlatformMerchantCode.Equals(paramXMStorageProductDetails.PlatformMerchantCode)).ToList();
                storageDeatail.refNumber         = refNumber;
                storageDeatail.ManufacturersCode = paramXMStorageProductDetails.PlatformMerchantCode;
                storageDeatail.purcahseCount     = Purchasedeone[0].ProductCount;
                storageDeatail.storageCount      = paramXMStorageProductDetails.ProductsCount;
                storageDeatail.puchasePrice      = paramXMStorageProductDetails.ProductsPrice;
                Lists.Add(storageDeatail);
            }
            if (PurchaseRejecteds == null)
            {
                List <XMPurchaseRejectedProductDetails> PurchaseRejectedList = new List <XMPurchaseRejectedProductDetails>();
                if (Lists != null && Lists.Count > 0)
                {
                    foreach (StorageProductDetailInfos Info in Lists)
                    {
                        int ccCount = Info.purcahseCount - Info.storageCount;
                        if (ccCount > 0)
                        {
                            //生成采购退货单
                            XMPurchaseRejectedProductDetails detaisl = new XMPurchaseRejectedProductDetails();
                            var products = base.XMProductService.getXMProductByManufacturersCode(Info.ManufacturersCode);
                            if (products != null)
                            {
                                detaisl.ProductId = products.Id;
                            }
                            detaisl.PlatformMerchantCode  = Info.ManufacturersCode;
                            detaisl.RejectionCount        = ccCount; //残次件数量
                            detaisl.RejectionProductPrice = Info.puchasePrice;
                            detaisl.RejectionMoney        = ccCount * Info.puchasePrice;
                            detaisl.CreateDate            = detaisl.UpdateDate = DateTime.Now;
                            detaisl.CreateID   = detaisl.UpdateID = HozestERPContext.Current.User.CustomerID;
                            detaisl.IsEnable   = false;
                            detaisl.BillStatus = 0;    //默认为待退回
                            PurchaseRejectedList.Add(detaisl);
                        }
                    }
                }

                //自动生成采购退货单主表及从表数据
                if (PurchaseRejectedList.Count > 0)
                {
                    //生成采购退货单主表
                    XMPurchaseRejected d = new XMPurchaseRejected();
                    d.Ref = PurchaseNumber;
                    var purchaseInfo2 = base.XMPurchaseService.GetXMPurchaseBypurChaseCode(PurchaseNumber);
                    if (purchaseInfo2 != null && purchaseInfo2.Count > 0)
                    {
                        d.MId         = purchaseInfo2[0].Id;
                        d.EmitFactory = purchaseInfo2[0].EmitFactory;   //发出工厂
                    }
                    d.SupplierId     = 1;
                    d.BizUserId      = HozestERPContext.Current.User.CustomerID;
                    d.BizDt          = DateTime.Now;
                    d.BillStatus     = 0;   //状态 待退货
                    d.RejectionMoney = PurchaseRejectedList.Sum(p => p.RejectionMoney);
                    d.ReceivingType  = 700;
                    d.CreateDate     = d.UpdateDate = DateTime.Now;
                    d.CreateID       = d.UpdateID = HozestERPContext.Current.User.CustomerID;
                    d.IsEnable       = false;
                    d.IsAudit        = true;
                    d.IsStoraged     = false;

                    base.XMPurchaseRejectedService.InsertXMPurchaseRejected(d);

                    //生成采购退货单明细表
                    foreach (XMPurchaseRejectedProductDetails p in PurchaseRejectedList)
                    {
                        p.PrId = d.Id;
                        base.XMPurchaseRejectedProductDetailsService.InsertXMPurchaseRejectedProductDetails(p);
                    }
                }
            }
        }
示例#2
0
        protected void btnSave_Click(object sender, EventArgs e)
        {
            decimal value = 0;

            if (this.type == 0)                        //新增
            {
                bool   isEmpty = false;                //判断厂家编码是否填写(厂家编码必填)
                bool   isFlase = false;                //判断入库数量值是否正确
                string rf      = AutoRejectedNumber(); //自动生成退货单号

                var InventoryInfo = base.XMInventoryInfoService.GetXMInventoryInfoById(this.ID);
                int storageID     = -1;
                if (InventoryInfo != null)
                {
                    storageID = InventoryInfo.WfId;
                }
                int      supplierId         = ddlSuppliers.SelectedValue == "" ? -1 : int.Parse(ddlSuppliers.SelectedValue);
                int      BizUserId          = HozestERPContext.Current.User.CustomerID;                                                                                 // 退货人
                DateTime BizDt              = txtStorageDate.Value == "" ? DateTime.Parse(DateTime.Now.ToShortDateString()) : Convert.ToDateTime(txtStorageDate.Value); //退货时间
                int      paymentType        = int.Parse(ddlPayment.SelectedValue);
                string   note               = txtNote.Text.Trim();
                decimal  totalRejectedMoney = 0;
                string   hiddjsonContent    = hdfJsonContent.Value;
                if (hiddjsonContent != "")
                {
                    JArray ja_goods = (JArray)JsonConvert.DeserializeObject(hiddjsonContent);
                    if (ja_goods.Count == 0)
                    {
                        isEmpty = true;
                    }
                    for (int i = 0; i < ja_goods.Count; i++)
                    {
                        int  rejecedCount = ja_goods[i]["Count"].ToString().Replace('\"', ' ').Trim() == "" ? 0 : int.Parse(ja_goods[i]["Count"].ToString().Replace('\"', ' ').Trim());     //可退货数量
                        bool t            = IsNumeric(ja_goods[i]["ProductCount"].ToString().Replace('\"', ' ').Trim() == "" ? "0" : ja_goods[i]["ProductCount"].ToString().Replace('\"', ' ').Trim());
                        if (!t)
                        {
                            base.ShowMessage("商品退货数量格式不正确!");
                            BindGrid(hiddjsonContent);
                            return;
                        }
                        int productCount = ja_goods[i]["ProductCount"].ToString().Replace('\"', ' ').Trim() == "" ? 0 : int.Parse(ja_goods[i]["ProductCount"].ToString().Replace('\"', ' ').Trim());      //退货数量
                        if (productCount == 0 || productCount > rejecedCount)
                        {
                            isFlase = true;
                        }
                    }
                }
                if (isFlase)
                {
                    base.ShowMessage("商品退货数量不能为0 或 大于可退货数量!");
                    BindGrid(hiddjsonContent);
                    return;
                }
                if (isEmpty)
                {
                    base.ShowMessage("厂家编码不能为空,请输入厂家编码 或商品信息不存在!");
                    BindGrid(hiddjsonContent);
                    return;
                }
                XMPurchaseRejected rejected = new XMPurchaseRejected();
                rejected.Ref            = rf;
                rejected.SupplierId     = supplierId;
                rejected.BizUserId      = BizUserId;
                rejected.BizDt          = BizDt;
                rejected.BillStatus     = 0; //待退货
                rejected.RejectionMoney = totalRejectedMoney;
                rejected.ReceivingType  = paymentType;
                rejected.BillMemo       = note;
                rejected.CreateID       = HozestERPContext.Current.User.CustomerID;
                rejected.CreateDate     = DateTime.Now;
                rejected.UpdateID       = HozestERPContext.Current.User.CustomerID;
                rejected.UpdateDate     = DateTime.Now;
                rejected.IsEnable       = false;
                rejected.IsAudit        = false;
                rejected.IsStoraged     = true; //已经入库
                base.XMPurchaseRejectedService.InsertXMPurchaseRejected(rejected);
                int rejectedID = rejected.Id;
                if (hiddjsonContent != "")
                {
                    JArray ja_goods = (JArray)JsonConvert.DeserializeObject(hiddjsonContent);
                    for (int i = 0; i < ja_goods.Count; i++)
                    {
                        string productCode  = ja_goods[i]["PlatformMerchantCode"].ToString().Replace('\"', ' ').Trim();                                                                                 //厂家编码
                        int    productCount = ja_goods[i]["ProductCount"].ToString().Replace('\"', ' ').Trim() == "" ? 0 : int.Parse(ja_goods[i]["ProductCount"].ToString().Replace('\"', ' ').Trim()); //退货数量
                        XMPurchaseRejectedProductDetails details = new XMPurchaseRejectedProductDetails();
                        details.PrId = rejectedID;
                        var product = base.XMProductService.getXMProductByManufacturersCode(productCode);
                        if (product != null)
                        {
                            details.ProductId = product.Id;
                        }
                        details.InventoryInfoID      = this.ID;      //库存ID
                        details.PlatformMerchantCode = productCode;
                        details.RejectionCount       = productCount; // 退货数量
                        details.CreateDate           = DateTime.Now;
                        details.CreateID             = HozestERPContext.Current.User.CustomerID;
                        details.UpdateDate           = DateTime.Now;
                        details.UpdateID             = HozestERPContext.Current.User.CustomerID;
                        details.IsEnable             = false;
                        base.XMPurchaseRejectedProductDetailsService.InsertXMPurchaseRejectedProductDetails(details);
                    }
                }

                XMPaymentApply xmPaymentApply = new XMPaymentApply();
                //xmPaymentApply.PurchaseID = this.PurchaseID;
                xmPaymentApply.PayAmounts       = 0 - totalRejectedMoney;
                xmPaymentApply.PayMode          = paymentType;
                xmPaymentApply.SupplierID       = supplierId;
                xmPaymentApply.RequstDate       = DateTime.Now;
                xmPaymentApply.UserDate         = DateTime.Now;
                xmPaymentApply.IsAudit          = false;
                xmPaymentApply.FinancialStatus  = false;
                xmPaymentApply.ApplicantID      = HozestERPContext.Current.User.CustomerID;
                xmPaymentApply.UpdateDate       = DateTime.Now;
                xmPaymentApply.UpdateID         = HozestERPContext.Current.User.CustomerID;
                xmPaymentApply.IsEnable         = false;
                xmPaymentApply.FinancialConfirm = false;
                XMPaymentApplyService.InsertXMPaymentApply(xmPaymentApply);

                base.ShowMessage("操作成功!");
                BindGrid(rejected.Id);
            }
            else                            //编辑
            {
                bool    isEmpty    = false; //判断厂家编码是否填写(厂家编码必填)
                bool    isFlase    = false; //判断入库数量值是否正确
                int     id         = this.RejectedID;
                decimal totalMoney = 0;     //总价
                var     rejected   = base.XMPurchaseRejectedService.GetXMPurchaseRejectedById(id);
                if (rejected != null)
                {
                    var rejectedDetails = base.XMPurchaseRejectedProductDetailsService.GetXMPurchaseRejectedProductDetailsByRejectedID(rejected.Id);
                    rejected.SupplierId = ddlSuppliers.SelectedValue == "" ? -1 : int.Parse(ddlSuppliers.SelectedValue);
                    rejected.BizUserId  = HozestERPContext.Current.User.CustomerID;
                    rejected.BizDt      = txtStorageDate.Value == "" ? DateTime.Parse(DateTime.Now.ToShortDateString()) : Convert.ToDateTime(txtStorageDate.Value); //业务时间
                    string hiddjsonContent = hdfJsonContent.Value;
                    if (hiddjsonContent != "")
                    {
                        JArray ja_goods = (JArray)JsonConvert.DeserializeObject(hiddjsonContent);
                        if (ja_goods.Count == 0)
                        {
                            isEmpty = true;
                        }
                        for (int i = 0; i < ja_goods.Count; i++)
                        {
                            int  rejecedCount = ja_goods[i]["Count"].ToString().Replace('\"', ' ').Trim() == "" ? 0 : int.Parse(ja_goods[i]["Count"].ToString().Replace('\"', ' ').Trim());     //可退货数量
                            bool t            = IsNumeric(ja_goods[i]["ProductCount"].ToString().Replace('\"', ' ').Trim() == "" ? "0" : ja_goods[i]["ProductCount"].ToString().Replace('\"', ' ').Trim());
                            if (!t)
                            {
                                base.ShowMessage("商品采购数量数量格式不正确!");
                                BindGrid(hiddjsonContent);
                                return;
                            }
                            int productCount = ja_goods[i]["ProductCount"].ToString().Replace('\"', ' ').Trim() == "" ? 0 : int.Parse(ja_goods[i]["ProductCount"].ToString().Replace('\"', ' ').Trim());      //退货数量
                            if (productCount == 0 || productCount > rejecedCount)
                            {
                                isFlase = true;
                            }
                        }
                    }
                    if (isFlase)
                    {
                        base.ShowMessage("商品退货数量不能为0 或 大于可退货数量!");
                        BindGrid(hiddjsonContent);
                        return;
                    }
                    if (isEmpty)
                    {
                        base.ShowMessage("厂家编码不能为空,请输入厂家编码或 商品信息不存在");
                        BindGrid(hiddjsonContent);
                        return;
                    }
                    rejected.RejectionMoney = totalMoney;
                    rejected.ReceivingType  = int.Parse(ddlPayment.SelectedValue);
                    rejected.BillMemo       = txtNote.Text.Trim();
                    rejected.UpdateDate     = DateTime.Now;
                    rejected.UpdateID       = HozestERPContext.Current.User.CustomerID;
                    base.XMPurchaseRejectedService.UpdateXMPurchaseRejected(rejected);
                    if (rejectedDetails != null && rejectedDetails.Count() > 0)
                    {
                        if (hiddjsonContent != "")
                        {
                            JArray ja_goods = (JArray)JsonConvert.DeserializeObject(hiddjsonContent);
                            for (int i = 0; i < ja_goods.Count; i++)
                            {
                                string productCode  = ja_goods[i]["PlatformMerchantCode"].ToString().Replace('\"', ' ').Trim();                                                                                 //厂家编码
                                int    productCount = ja_goods[i]["ProductCount"].ToString().Replace('\"', ' ').Trim() == "" ? 0 : int.Parse(ja_goods[i]["ProductCount"].ToString().Replace('\"', ' ').Trim()); //退货数量
                                foreach (XMPurchaseRejectedProductDetails info in rejectedDetails)
                                {
                                    if (productCode == info.PlatformMerchantCode)
                                    {
                                        info.InventoryInfoID = this.ID;//库存ID
                                        info.RejectionCount  = productCount;
                                        info.UpdateID        = HozestERPContext.Current.User.CustomerID;
                                        info.UpdateDate      = DateTime.Now;
                                        base.XMPurchaseRejectedProductDetailsService.UpdateXMPurchaseRejectedProductDetails(info);
                                    }
                                }
                            }
                        }
                    }
                }
                base.ShowMessage("操作成功!");
                BindGrid(rejected.Id);
            }
        }