Exemplo n.º 1
0
        public JsonResult PostRDwithstatus(int Docno, int vendor, string Grno, string reasonofr, DateTime dateofdev, int prref, List <ProcureVM> rdlists)
        {
            NumberSequence seq = new NumberSequence();

            if (rdlists == null)
            {
                rdlists = new List <ProcureVM>();
                return(Json(new { code = 0, message = "Please add Rejected Quantity before Submitting" }, JsonRequestBehavior.AllowGet));
            }

            if (rdlists == null)
            {
                rdlists = new List <ProcureVM>();
            }
            var check = obj.GetDoc().Where(x => x.DocumentNo == Docno && x.DocStatus == "Open").FirstOrDefault();

            if (check == null)
            {
                var add = obj.Addrd(vendor, Docno, reasonofr, dateofdev, prref);
                obj.addgr(add);
                obj.Save();
                string no = seq.GenerateNo("Return", add.DocumentNo);
                obj.upatedocdetail(add.DocumentNo, no);
                obj.Save();
                obj.updategrstatustoopen(Docno);
                obj.Save();

                foreach (ProcureVM rd in rdlists)
                {
                    if (rd.RejectedQuantity > 0)
                    {
                        var addetails = obj.Addreturn(add.DocumentNo, Docno, vendor, db.getItemid(rd.ItemName), rd.DeliveredQuantity, rd.RejectedQuantity, rd.ApprovedQuantity);
                        obj.addr(addetails);
                        obj.Save();
                        obj.minusslstock(db.getSlid(rd.ItemName), rd.RejectedQuantity);
                        obj.Save();
                        obj.minusitemsfromqualitystock(db.getItemid(rd.ItemName), rd.RejectedQuantity);
                        obj.Save();
                        if (rd.ApprovedQuantity == 0)
                        {
                            obj.updatestatusdoctorejected(Docno);
                            obj.Save();
                        }
                    }
                }
                return(Json(new { Returnno = add.DocumentNo, message = "Return Delivery created with " + add.Docno + " and " + Grno + " Status changed to Open" }, JsonRequestBehavior.AllowGet));
            }
            else
            {
                return(Json(new { message = "Return Delivery already created for " + Grno + "" }, JsonRequestBehavior.AllowGet));
            }
        }