Beispiel #1
0
        public JsonResult GetPId(int ProjectId)
        {
            List <SelectListItem> siteList = new List <SelectListItem>();

            var projects = db.Project.SingleOrDefault(x => x.Id == ProjectId);
            var sDate    = NullHelper.DateToString(projects.StartDate);
            var eDate    = NullHelper.DateToString(projects.EndDate);

            var sites            = db.ProjectSite.Where(x => x.ProjectId == ProjectId).ToList();
            var projectResources = db.ProjectResource.SingleOrDefault(x => x.ProjectId == ProjectId);
            var projectManager   = projectResources.CompanyResource.Name;


            foreach (var x in sites)
            {
                siteList.Add(new SelectListItem {
                    Text = x.Name, Value = x.Id.ToString()
                });
            }

            var result = new
            {
                start   = sDate,
                end     = eDate,
                manager = projectManager,
                Sites   = siteList
            };

            return(Json(result, JsonRequestBehavior.AllowGet));
        }
        public ActionResult Details(int purchaseOrderId, int tenderMasId)
        {
            var procPurchaseMasterId = db.Proc_PurchaseOrderMas.FirstOrDefault(x => x.Id == purchaseOrderId && x.Proc_TenderMasId == tenderMasId);

            ViewBag.ProcPurchaseMasterId = procPurchaseMasterId.Id;
            var procPurchaseDetId = db.Proc_PurchaseOrderDet.FirstOrDefault(x => x.Proc_PurchaseOrderMasId == purchaseOrderId);

            ViewBag.ProcPurchaseDetId = procPurchaseDetId.Id;
            ViewBag.PurchaseMasId     = purchaseOrderId;
            ViewBag.TenderMasId       = tenderMasId;

            var purchaseItemDet = (from purchaseDet in db.Proc_PurchaseOrderDet
                                   join purchaseMas in db.Proc_PurchaseOrderMas on purchaseDet.Proc_PurchaseOrderMasId equals purchaseMas.Id
                                   join tenderMas in db.Proc_TenderMas on purchaseMas.Proc_TenderMasId equals tenderMas.Id
                                   join reqDet in db.Proc_RequisitionDet on purchaseDet.ItemId equals reqDet.ItemId
                                   join reqMas in db.Proc_RequisitionMas on reqDet.Proc_RequisitionMasId equals reqMas.Id
                                   join procItem in db.ProcProjectItem on reqMas.ProcProjectId equals procItem.ProcProjectId
                                   join procProj in db.ProcProject on procItem.ProcProjectId equals procProj.Id
                                   join projSite in db.ProjectSite on procProj.ProjectSiteId equals projSite.Id
                                   join proj in db.Project on projSite.ProjectId equals proj.Id
                                   where purchaseMas.Id == purchaseOrderId
                                   select reqMas).FirstOrDefault();

            if (purchaseItemDet != null)
            {
                ViewBag.ProjectName = purchaseItemDet.ProcProject.ProjectSite.Project.Name;
                ViewBag.SiteName    = purchaseItemDet.ProcProject.ProjectSite.Name;
            }
            //ViewBag.ProjectId = new SelectList(db.Project, "Id", "Name");
            ViewBag.SiteId = new SelectList(db.ProjectSite, "Id", "Name");

            var vendorAndTenderId = (from purchaseOrderMas in db.Proc_PurchaseOrderMas
                                     join vendors in db.Vendor on purchaseOrderMas.VendorId equals vendors.Id
                                     where purchaseOrderMas.Id == purchaseOrderId
                                     select purchaseOrderMas).FirstOrDefault();

            ViewBag.VendorId        = new SelectList(db.Vendor, "Id", "Name", vendorAndTenderId.VendorId);
            ViewBag.TenderId        = new SelectList(db.Proc_TenderMas.Where(x => x.Id == tenderMasId), "Id", "TNo", vendorAndTenderId.Proc_TenderMasId);
            ViewBag.PurchaseAddress = purchaseItemDet.ProcProject.ProjectSite.Location;
            ViewBag.ItemName        = new SelectList(db.Item, "Id", "Name");
            ViewBag.UnitName        = new SelectList(db.Unit, "Id", "Name");
            var puchaseOrders = db.Proc_PurchaseOrderMas.FirstOrDefault(x => x.Id == purchaseOrderId);

            if (puchaseOrders != null)
            {
                ViewBag.PONo                 = NullHelper.ObjectToString(puchaseOrders.PONo);
                ViewBag.PODate               = NullHelper.DateToString(puchaseOrders.PODate);
                ViewBag.VendorAttention      = NullHelper.ObjectToString(puchaseOrders.Attention);
                ViewBag.AttnManager          = NullHelper.ObjectToString(puchaseOrders.OrderTo);
                ViewBag.AttnCell             = NullHelper.ObjectToString(puchaseOrders.AttnCell);
                ViewBag.Email                = NullHelper.ObjectToString(puchaseOrders.AttnEmail);
                ViewBag.Subject              = NullHelper.ObjectToString(puchaseOrders.Subject);
                ViewBag.LeadTime             = NullHelper.ObjectToString(puchaseOrders.LeadTime);
                ViewBag.Content              = NullHelper.ObjectToString(puchaseOrders.Content);
                ViewBag.RcvConcernPerson     = NullHelper.ObjectToString(puchaseOrders.RecvConcernPerson);
                ViewBag.RcvConcernPersonCell = NullHelper.ObjectToString(puchaseOrders.RecvConcernPersonCell);
            }
            return(View());
        }
Beispiel #3
0
        // GET: Projects/Details/5
        public ActionResult Details(int?id)
        {
            var pId = db.Project.FirstOrDefault(x => x.Id == id);

            ViewBag.Proj = pId.Id;



            ViewBag.PId = id;
            var projectData = db.Project.Where(x => x.Id == id).FirstOrDefault();

            ViewBag.ProjectName = projectData.Name;


            var prMan = (from projRes in db.ProjectResource
                         join comRes in db.CompanyResource on projRes.CompanyResourceId equals comRes.Id
                         where projRes.ProjectId == id
                         select comRes).FirstOrDefault();

            ViewBag.ProjectManager = new SelectList(db.CompanyResource, "Id", "Name", prMan.Id);

            var startDate = NullHelper.DateToString(projectData.StartDate);

            ViewBag.StartDate = startDate;

            var endDate = NullHelper.DateToString(projectData.EndDate);

            ViewBag.EndDate = endDate;

            var remarks = projectData.Remarks;

            ViewBag.ProjectRemarks = NullHelper.ObjectToString(remarks);



            var status = new SelectList(new List <SelectListItem> {
                new SelectListItem {
                    Text = "Active", Value = "A"
                }, new SelectListItem {
                    Text = "Inactive", Value = "I"
                },
            }, "Value", "Text");

            ViewBag.Statuses = status;
            ViewBag.RName    = new SelectList(db.CompanyResource, "Id", "Name");

            return(View());
        }
Beispiel #4
0
        public JsonResult getEditMaterialEntry(int MaterialEntryMasId)
        {
            bool flag = false;

            var check = db.Proc_MaterialEntryDet.Where(x => x.Proc_MaterialEntryMasId == MaterialEntryMasId).Count();

            if (check > 0)
            {
                flag = true;
                var data = db.Proc_MaterialEntryDet.Where(x => x.Proc_MaterialEntryMasId == MaterialEntryMasId).ToList();

                List <VMEditMaterialsEntryItem> detailsList = new List <VMEditMaterialsEntryItem>();
                foreach (var i in data)
                {
                    VMEditMaterialsEntryItem vm = new VMEditMaterialsEntryItem();

                    vm.Proc_MaterialEntryDetId = i.Id;
                    //var projectId = (from tenderDet in db.Proc_TenderDet
                    //                 join requisitionDet in db.Proc_RequisitionDet on tenderDet.Proc_RequisitionDetId equals requisitionDet.Id
                    //                 join requisitionMas in db.Proc_RequisitionMas on requisitionDet.Proc_RequisitionMasId equals requisitionMas.Id
                    //                 join procProject in db.ProcProject on requisitionMas.ProcProjectId equals procProject.Id
                    //                 join site in db.ProjectSite on procProject.ProjectSiteId equals site.Id
                    //                 join project in db.Project on site.ProjectId equals project.Id
                    //                 where tenderDet.Proc_TenderMasId == i.Proc_TenderMasId
                    //                 select project).FirstOrDefault();
                    //vm.ProjectId = projectId.Id;
                    //vm.ProjectName = projectId.Name;

                    //var siteId = (from tenderDet in db.Proc_TenderDet
                    //              join requisitionDet in db.Proc_RequisitionDet on tenderDet.Proc_RequisitionDetId equals requisitionDet.Id
                    //              join requisitionMas in db.Proc_RequisitionMas on requisitionDet.Proc_RequisitionMasId equals requisitionMas.Id
                    //              join procProject in db.ProcProject on requisitionMas.ProcProjectId equals procProject.Id
                    //              join site in db.ProjectSite on procProject.ProjectSiteId equals site.Id
                    //              where tenderDet.Proc_TenderMasId == TenderId
                    //              select site).FirstOrDefault();
                    //vm.SiteId = siteId.Id;
                    //vm.SitetName = siteId.Name;

                    vm.ChallanNo = i.ChallanNo;

                    //var date = NullHelper.DateToString(i.ChallanDate);
                    if (i.ChallanDate == null)
                    {
                        vm.ChallanDate = "";
                    }
                    else
                    {
                        vm.ChallanDate = NullHelper.DateToString(i.ChallanDate);
                    }
                    //vm.ChallanDate = i.ChallanDate;
                    vm.EntryQty = i.EntryQty;
                    vm.Status   = i.Status;

                    var ItemId = (from entryDet in db.Proc_MaterialEntryDet
                                  join entryMas in db.Proc_MaterialEntryMas on entryDet.Proc_MaterialEntryMasId equals entryMas.Id
                                  join procProject in db.ProcProject on entryMas.ProcProjectId equals procProject.Id
                                  join procProjectItem in db.ProcProjectItem on procProject.Id equals procProjectItem.ProcProjectId
                                  join items in db.Item on procProjectItem.ItemId equals items.Id
                                  where entryDet.Proc_MaterialEntryMasId == MaterialEntryMasId
                                  select items).FirstOrDefault();
                    vm.ItemId   = ItemId.Id;
                    vm.ItemName = ItemId.Name;

                    var requisitionId = (from entryDet in db.Proc_MaterialEntryDet
                                         join entryMas in db.Proc_MaterialEntryMas on entryDet.Proc_MaterialEntryMasId equals entryMas.Id
                                         join procProject in db.ProcProject on entryMas.ProcProjectId equals procProject.Id
                                         join procProjectItem in db.ProcProjectItem on procProject.Id equals procProjectItem.ProcProjectId
                                         join requisitionMas in db.Proc_RequisitionMas on procProject.Id equals requisitionMas.ProcProjectId
                                         where entryDet.Proc_MaterialEntryMasId == MaterialEntryMasId && procProjectItem.ItemId == ItemId.Id
                                         select requisitionMas).FirstOrDefault();

                    vm.RCode = requisitionId.Rcode;

                    var PONo = (from purchaseOrderMas in db.Proc_PurchaseOrderMas
                                join purchaseOrderDet in db.Proc_PurchaseOrderDet on purchaseOrderMas.Id equals purchaseOrderDet.Proc_PurchaseOrderMasId
                                join entryDet in db.Proc_MaterialEntryDet on purchaseOrderDet.Id equals entryDet.Proc_PurchaseOrderDetId
                                where entryDet.Proc_MaterialEntryMas.Id == MaterialEntryMasId
                                select purchaseOrderMas).FirstOrDefault();

                    vm.PONo = PONo.PONo;
                    vm.PurchaseOrderDetId = db.Proc_PurchaseOrderDet.FirstOrDefault(x => x.Proc_PurchaseOrderMasId == PONo.Id).Id;


                    //var unit = db.Unit.FirstOrDefault(x => x.Id == ItemId.Id);
                    var unit = (from procProjectItem in db.ProcProjectItem
                                join units in db.Unit on procProjectItem.UnitId equals units.Id
                                where procProjectItem.ItemId == ItemId.Id
                                select units).FirstOrDefault();
                    vm.UnitId   = unit.Id;
                    vm.UnitName = unit.Name;

                    var vendors = (from purchaseDet in db.Proc_PurchaseOrderDet
                                   join purchaseMas in db.Proc_PurchaseOrderMas on purchaseDet.Proc_PurchaseOrderMasId equals purchaseMas.Id
                                   //join entryDet in db.Proc_MaterialEntryDet on purchaseDet.Id equals entryDet.Proc_PurchaseOrderDetId
                                   join vendor in db.Vendor on purchaseMas.VendorId equals vendor.Id
                                   where purchaseMas.PONo == PONo.PONo
                                   select vendor).Distinct().FirstOrDefault();

                    //var vendor = (from requisitionDet in db.Proc_RequisitionDet
                    //              join requisitionMas in db.Proc_RequisitionMas on requisitionDet.Proc_RequisitionMasId equals requisitionMas.Id
                    //              join tenderDet in db.Proc_TenderDet on requisitionDet.Id equals tenderDet.Proc_RequisitionDetId
                    //              where requisitionMas.Rcode == requisitionId.Rcode && requisitionDet.ItemId == ItemId.Id
                    //              select tenderDet).FirstOrDefault();

                    vm.VendorId   = vendors.Id;
                    vm.VendorName = db.Vendor.SingleOrDefault(x => x.Id == vendors.Id).Name;
                    var totalMaterial = (from total in db.ProcProjectItem
                                         join procProject in db.ProcProject on total.ProcProjectId equals procProject.Id
                                         where  total.ItemId == ItemId.Id
                                         select total).FirstOrDefault();

                    var requiredQty = (from requisitionDet in db.Proc_RequisitionDet
                                       join requisitionMas in db.Proc_RequisitionMas on requisitionDet.Proc_RequisitionMasId equals requisitionMas.Id
                                       where requisitionMas.Rcode == requisitionId.Rcode && requisitionDet.ItemId == ItemId.Id
                                       select requisitionDet).FirstOrDefault();

                    var unitPrice = (from tenderDet in db.Proc_TenderDet
                                     join requisitionDet in db.Proc_RequisitionDet on tenderDet.Proc_RequisitionDetId equals requisitionDet.Id
                                     join requisitionMas in db.Proc_RequisitionMas on requisitionDet.Proc_RequisitionMasId equals requisitionMas.Id
                                     where requisitionMas.Rcode == requisitionId.Rcode && requisitionDet.ItemId == ItemId.Id

                                     select tenderDet).FirstOrDefault();
                    vm.TotalMaterial = totalMaterial.PQuantity;
                    vm.RemainingQty  = requiredQty.ReqQty;
                    vm.UnitPrice     = unitPrice.TQPrice;
                    vm.Status        = i.Status;
                    detailsList.Add(vm);
                }

                var result = new
                {
                    flag = flag,
                    List = detailsList
                };

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var result = new
                {
                    flag = flag
                };

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }
Beispiel #5
0
        public ActionResult Edit(int?projectId, int?siteId)
        {
            ViewBag.PId = projectId;
            ViewBag.SId = siteId;

            var procProjectId = db.ProcProject.FirstOrDefault(x => x.Id == projectId && x.ProjectSiteId == siteId);

            ViewBag.ProcProjectId = procProjectId.Id;

            ViewBag.ProcProjectIdEditForm = procProjectId.ProjectSite.Project.Name;



            ViewBag.ProjectId = new SelectList(db.Project, "Id", "Name");
            ViewBag.SiteId    = new SelectList(db.ProjectSite, "Id", "Name");



            ViewBag.ItemName = new SelectList(db.Item, "Id", "Name");
            ViewBag.Unit     = new SelectList(db.Unit, "Id", "Name");

            var projectTypeStatus = new SelectList(new List <SelectListItem> {
                new SelectListItem {
                    Text = "Government", Value = "Government"
                }, new SelectListItem {
                    Text = "Non-Government", Value = "Non-Government"
                },
            }, "Value", "Text");

            ViewBag.ProjectType = projectTypeStatus;

            ViewBag.PrManId = new SelectList(db.CompanyResource, "Id", "Name");
            ViewBag.StEngId = new SelectList(db.CompanyResource, "Id", "Name");

            var projectIdFinder = db.ProjectSite.SingleOrDefault(x => x.Id == siteId);

            var projects = db.Project.SingleOrDefault(x => x.Id == projectIdFinder.ProjectId);

            ViewBag.StartDate = NullHelper.DateToString(projects.StartDate);
            ViewBag.EndDate   = NullHelper.DateToString(projects.EndDate);

            var procProjects = db.ProcProject.SingleOrDefault(x => x.Id == projectId && x.ProjectSiteId == siteId);

            ViewBag.BOQDate = NullHelper.DateToString(procProjects.BOQDate);
            ViewBag.NOADate = NullHelper.DateToString(procProjects.NOADate);
            ViewBag.BOQNo   = NullHelper.ObjectToString(procProjects.BOQNo);
            ViewBag.NOANo   = NullHelper.ObjectToString(procProjects.NOANo);
            //ViewBag.PType = NullHelper.ObjectToString(procProjects.ProjectType);
            var projectType = new SelectList(new List <SelectListItem> {
                new SelectListItem {
                    Text = "Government", Value = "Government"
                },
                new SelectListItem {
                    Text = "Non-Government", Value = "Non-Government"
                },
            }, "Value", "Text", procProjects.ProjectType);

            ViewBag.ProjectType = projectType;
            ViewBag.PStatus     = NullHelper.ObjectToString(procProjects.Status);
            ViewBag.PRemarks    = NullHelper.ObjectToString(procProjects.Remarks);



            var projectRes = db.ProjectResource.SingleOrDefault(x => x.ProjectId == projectIdFinder.ProjectId);

            ViewBag.PrMan = NullHelper.ObjectToString(projectRes.CompanyResource.Name);

            var projectSiteRes = db.ProjectSiteResource.SingleOrDefault(x => x.ProjectSiteId == siteId);

            ViewBag.StEng = NullHelper.ObjectToString(projectSiteRes.CompanyResource.Name);

            VMProjectItem vmProjectItem = new VMProjectItem();

            vmProjectItem.ProcProjectItem = db.ProcProjectItem.Where(x => x.ProcProjectId == projectId /*&& x.ProjectSiteId == siteId*/).ToList();


            if (projectId == null || siteId == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ProcProject     procProject     = db.ProcProject.Where(x => x.Id == projectId && x.ProjectSiteId == siteId).FirstOrDefault();
            Project         project         = db.Project.Where(x => x.Id == projectId).FirstOrDefault();
            ProcProjectItem procProjectItem = db.ProcProjectItem.Where(x => x.ProcProjectId == projectId /*&& x.ProjectSiteId == siteId*/).FirstOrDefault();


            if (procProject == null)
            {
                return(HttpNotFound());
            }

            return(View(vmProjectItem));
        }
        public JsonResult getEditTender(int TenderId)
        {
            bool flag = false;

            var check = db.Proc_TenderDet.Where(x => x.Proc_TenderMasId == TenderId).Count();

            if (check > 0)
            {
                flag = true;
                var data = db.Proc_TenderDet.Where(x => x.Proc_TenderMasId == TenderId).ToList();

                List <VMEditTenderItem> detailsList = new List <VMEditTenderItem>();
                foreach (var i in data)
                {
                    VMEditTenderItem vm = new VMEditTenderItem();
                    vm.TenderDetailId = i.Id;

                    var projectId = (from tenderDet in db.Proc_TenderDet
                                     join requisitionDet in db.Proc_RequisitionDet on tenderDet.Proc_RequisitionDetId equals requisitionDet.Id
                                     join requisitionMas in db.Proc_RequisitionMas on requisitionDet.Proc_RequisitionMasId equals requisitionMas.Id
                                     join procProject in db.ProcProject on requisitionMas.ProcProjectId equals procProject.Id
                                     join site in db.ProjectSite on procProject.ProjectSiteId equals site.Id
                                     join project in db.Project on site.ProjectId equals project.Id
                                     where tenderDet.Proc_TenderMasId == i.Proc_TenderMasId
                                     select project).FirstOrDefault();
                    vm.ProjectId   = projectId.Id;
                    vm.ProjectName = projectId.Name;

                    var siteId = (from tenderDet in db.Proc_TenderDet
                                  join requisitionDet in db.Proc_RequisitionDet on tenderDet.Proc_RequisitionDetId equals requisitionDet.Id
                                  join requisitionMas in db.Proc_RequisitionMas on requisitionDet.Proc_RequisitionMasId equals requisitionMas.Id
                                  join procProject in db.ProcProject on requisitionMas.ProcProjectId equals procProject.Id
                                  join site in db.ProjectSite on procProject.ProjectSiteId equals site.Id
                                  where tenderDet.Proc_TenderMasId == TenderId
                                  select site).FirstOrDefault();
                    vm.SiteId    = siteId.Id;
                    vm.SitetName = siteId.Name;

                    var requisitionId = (from tenderDet in db.Proc_TenderDet
                                         join requisitionDet in db.Proc_RequisitionDet on tenderDet.Proc_RequisitionDetId equals requisitionDet.Id
                                         join requisitionMas in db.Proc_RequisitionMas on requisitionDet.Proc_RequisitionMasId equals requisitionMas.Id
                                         where tenderDet.Proc_TenderMasId == TenderId
                                         select requisitionMas).FirstOrDefault();

                    vm.RCode = requisitionId.Rcode;

                    var ItemId = (from tenderDet in db.Proc_TenderDet
                                  join requisitionDet in db.Proc_RequisitionDet on tenderDet.Proc_RequisitionDetId equals requisitionDet.Id
                                  join requisitionMas in db.Proc_RequisitionMas on requisitionDet.Proc_RequisitionMasId equals requisitionMas.Id
                                  join procProject in db.ProcProject on requisitionMas.ProcProjectId equals procProject.Id
                                  join procProjectItem in db.ProcProjectItem on procProject.Id equals procProjectItem.ProcProjectId
                                  join items in db.Item on procProjectItem.ItemId equals items.Id
                                  where tenderDet.Proc_TenderMasId == TenderId && requisitionDet.Id == i.Proc_RequisitionDetId && items.Id == requisitionDet.ItemId
                                  select items).FirstOrDefault();
                    vm.ItemId   = ItemId.Id;
                    vm.ItemName = ItemId.Name;


                    var quantity = db.Proc_RequisitionDet.FirstOrDefault(x => x.ItemId == ItemId.Id).ReqQty;
                    vm.Qty = quantity;

                    //var unit = db.Unit.FirstOrDefault(x => x.Id == ItemId.Id);
                    var unit = (from procProjectItem in db.ProcProjectItem
                                join units in db.Unit on procProjectItem.UnitId equals units.Id
                                where procProjectItem.ItemId == ItemId.Id
                                select units).FirstOrDefault();

                    vm.UnitId   = unit.Id;
                    vm.UnitName = unit.Name;
                    vm.Proc_RequisitionDetId = i.Proc_RequisitionDetId;
                    vm.VendorId   = i.VendorId;
                    vm.VendorName = db.Vendor.SingleOrDefault(x => x.Id == i.VendorId).Name;
                    vm.TQNo       = i.TQNo;

                    if (i.TQDate == null)
                    {
                        vm.TQDate = "";
                    }
                    else
                    {
                        vm.TQDate = NullHelper.DateToString(i.TQDate);
                    }
                    //vm.TQDate = i.TQDate;
                    vm.TQPrice = i.TQPrice;
                    vm.Status  = i.Status;

                    detailsList.Add(vm);
                }

                var result = new
                {
                    flag = flag,
                    List = detailsList
                };

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
            else
            {
                var result = new
                {
                    flag = flag
                };

                return(Json(result, JsonRequestBehavior.AllowGet));
            }
        }
        public ActionResult Edit(int purchaseOrderId, int tenderMasId)
        {
            //var procPurchaseMasterId = db.Proc_PurchaseOrderMas.FirstOrDefault(x => x.Id == purchaseOrderId && x.Proc_TenderMasId == tenderMasId);
            var procPurchaseMasterId = db.Proc_PurchaseOrderMas.FirstOrDefault(x => x.Id == purchaseOrderId);

            ViewBag.ProcPurchaseMasterId = procPurchaseMasterId.Id;
            //   var procPurchaseDetId = db.Proc_PurchaseOrderDet.FirstOrDefault(x => x.Proc_PurchaseOrderMasId == purchaseOrderId);
            //   ViewBag.ProcPurchaseDetId = procPurchaseDetId.Id;
            ViewBag.PurchaseMasId = purchaseOrderId;
            ViewBag.TenderMasId   = tenderMasId;
            var purchaseItemDet = (from purchaseDet in db.Proc_PurchaseOrderDet
                                   join purchaseMas in db.Proc_PurchaseOrderMas on purchaseDet.Proc_PurchaseOrderMasId equals purchaseMas.Id
                                   join tenderMas in db.Proc_TenderMas on purchaseMas.Proc_TenderMasId equals tenderMas.Id
                                   join reqDet in db.Proc_RequisitionDet on purchaseDet.ItemId equals reqDet.ItemId
                                   join reqMas in db.Proc_RequisitionMas on reqDet.Proc_RequisitionMasId equals reqMas.Id
                                   join procItem in db.ProcProjectItem on reqMas.ProcProjectId equals procItem.ProcProjectId
                                   join procProj in db.ProcProject on procItem.ProcProjectId equals procProj.Id
                                   join projSite in db.ProjectSite on procProj.ProjectSiteId equals projSite.Id
                                   join proj in db.Project on projSite.ProjectId equals proj.Id
                                   where purchaseMas.Id == purchaseOrderId
                                   select reqMas).FirstOrDefault();

            var vendorAndTenderId = (from purchaseOrderMas in db.Proc_PurchaseOrderMas
                                     join vendors in db.Vendor on purchaseOrderMas.VendorId equals vendors.Id
                                     where purchaseOrderMas.Id == purchaseOrderId
                                     select purchaseOrderMas).FirstOrDefault();

            //   if (purchaseItemDet != null)
            // {
            ViewBag.ProjectName = purchaseItemDet.ProcProject.ProjectSite.Project.Name;
            ViewBag.SiteName    = purchaseItemDet.ProcProject.ProjectSite.Name;
            ViewBag.PONoId      = purchaseOrderId;
            ViewBag.ProjectId   = purchaseItemDet.ProcProject.ProjectSite.ProjectId;
            ViewBag.SiteId      = purchaseItemDet.ProcProject.ProjectSiteId;
            //ViewBag.VendorId = vendorAndTenderId.VendorId;
            //  ViewBag.VendorId = new SelectList(db.Vendor, "Id", "Name", vendorAndTenderId.VendorId);

            //  }

            //ViewBag.ProjectId = new SelectList(db.Project, "Id", "Name");
            //      ViewBag.SiteId = new SelectList(db.ProjectSite, "Id", "Name");


            //var vendorAndTenderId = (from purchaseOrderMas in db.Proc_PurchaseOrderMas
            //                         join vendors in db.Vendor on purchaseOrderMas.VendorId equals vendors.Id
            //                         where purchaseOrderMas.Id == purchaseOrderId
            //                         select purchaseOrderMas).FirstOrDefault();
            ViewBag.VendorId        = new SelectList(db.Vendor, "Id", "Name", vendorAndTenderId.VendorId);
            ViewBag.TenderId        = new SelectList(db.Proc_TenderMas.Where(x => x.Id == tenderMasId), "Id", "TNo", vendorAndTenderId.Proc_TenderMasId);
            ViewBag.PurchaseAddress = purchaseItemDet.ProcProject.ProjectSite.Location;

            var items = (from tenderMas in db.Proc_TenderMas
                         join tenderDet in db.Proc_TenderDet on tenderMas.Id equals tenderDet.Proc_TenderMasId
                         join requisitionDet in db.Proc_RequisitionDet on tenderDet.Proc_RequisitionDetId equals requisitionDet.Id
                         join requisitionMas in db.Proc_RequisitionMas on requisitionDet.Proc_RequisitionMasId equals requisitionMas.Id
                         join procProject in db.ProcProject on requisitionMas.ProcProjectId equals procProject.Id
                         join procProjectItem in db.ProcProjectItem on procProject.Id equals procProjectItem.ProcProjectId
                         join item in db.Item on procProjectItem.ItemId equals item.Id
                         where tenderDet.VendorId == vendorAndTenderId.VendorId && requisitionDet.ItemId == item.Id
                         select item).Distinct().ToList();

            List <SelectListItem> itemList = new List <SelectListItem>();

            foreach (var x in items)
            {
                //var itemName = db.Proc_TenderMas.SingleOrDefault(m => m.Id == x.Id);
                itemList.Add(new SelectListItem {
                    Text = x.Name, Value = x.Id.ToString()
                });
            }

            //ViewBag.ItemName = new SelectList(db.Item, "Id", "Name");
            ViewBag.ItemName = itemList.Distinct();
            ViewBag.UnitName = new SelectList(db.Unit, "Id", "Name");

            var puchaseOrders = db.Proc_PurchaseOrderMas.FirstOrDefault(x => x.Id == purchaseOrderId);

            if (puchaseOrders != null)
            {
                ViewBag.PONo                 = NullHelper.ObjectToString(puchaseOrders.PONo);
                ViewBag.PODate               = NullHelper.DateToString(puchaseOrders.PODate);
                ViewBag.VendorAttention      = NullHelper.ObjectToString(puchaseOrders.Attention);
                ViewBag.AttnManager          = NullHelper.ObjectToString(puchaseOrders.OrderTo);
                ViewBag.AttnCell             = NullHelper.ObjectToString(puchaseOrders.AttnCell);
                ViewBag.Email                = NullHelper.ObjectToString(puchaseOrders.AttnEmail);
                ViewBag.Subject              = NullHelper.ObjectToString(puchaseOrders.Subject);
                ViewBag.LeadTime             = NullHelper.ObjectToString(puchaseOrders.LeadTime);
                ViewBag.Content              = NullHelper.ObjectToString(puchaseOrders.Content);
                ViewBag.RcvConcernPerson     = NullHelper.ObjectToString(puchaseOrders.RecvConcernPerson);
                ViewBag.RcvConcernPersonCell = NullHelper.ObjectToString(puchaseOrders.RecvConcernPersonCell);
            }



            //new 7feb 18


            return(View());
        }