public async Task <IActionResult> OnGet(string reqNo)
        {
            Suppliers = _context.Suppliers.AsNoTracking().Select(n => new SelectListItem
            {
                Value = n.Id.ToString(),
                Text  = n.Name
            }).ToList();
            WarehouseStock = _context.WarehouseStock.AsNoTracking().Select(n => new SelectListItem
            {
                Value = n.Id.ToString(),
                Text  = n.StockName
            }).ToList();
            AllSuppliers      = _context.Suppliers.AsNoTracking().ToList();
            AllWarehouseStock = _context.WarehouseStock.AsNoTracking().ToList();
            ApplicationUser   = await _userManager.GetUserAsync(User);

            Requisitions     = _context.Requisitions.AsNoTracking().Where(r => r.ReqNo == reqNo).ToList();
            Supplier         = AllSuppliers.FirstOrDefault(s => s.Id == Requisitions.FirstOrDefault().SupplierId);
            SelectedSupplier = Supplier.Name;
            List <Warehouse> wStock = new List <Warehouse>();

            foreach (var req in Requisitions)
            {
                wStock.Add(AllWarehouseStock.FirstOrDefault(w => w.Id == req.StockId));
            }
            WStock = wStock;
            ReqNo  = reqNo;
            return(Page());
        }
Esempio n. 2
0
        public async Task <IActionResult> OnGetAsync()
        {
            var username = HttpContext.Session.GetString("_username");
            var usertype = HttpContext.Session.GetString("_usertype");
            var access   = new Access(username, "Supervisor");

            if (access.IsLogin())
            {
                if (access.IsAuthorize(usertype))
                {
                    Requisitions = await _context.Requisition
                                   .Where(i => i.DateDeleted == null)
                                   .Where(i => i.RequisitionStatus == "New")
                                   .Where(s => s.Receiver == username)
                                   .Include(p => p.Project)
                                   .OrderBy(p => p.RequisitionStatus)
                                   .ToListAsync();

                    RequisitionCount = Requisitions.Count();

                    return(Page());
                }
                else
                {
                    ErrorMessage = "Access Denied";
                    return(RedirectToPage($"/{usertype}/Index"));
                }
            }
            else
            {
                ErrorMessage = "Login Required";
                return(RedirectToPage("/Account/Login"));
            }
        }
        public async Task <IActionResult> OnPostEditReq()
        {
            Suppliers = _context.Suppliers.AsNoTracking().Select(n => new SelectListItem
            {
                Value = n.Id.ToString(),
                Text  = n.Name
            }).ToList();
            WarehouseStock = _context.WarehouseStock.AsNoTracking().Select(n => new SelectListItem
            {
                Value = n.Id.ToString(),
                Text  = n.StockName
            }).ToList();
            AllSuppliers      = _context.Suppliers.AsNoTracking().ToList();
            AllWarehouseStock = _context.WarehouseStock.AsNoTracking().ToList();
            ApplicationUser   = await _userManager.GetUserAsync(User);

            Supplier         = AllSuppliers.FirstOrDefault(s => s.Id == Requisitions.FirstOrDefault().SupplierId);
            SelectedSupplier = Supplier.Name;
            List <Warehouse> wStock = new List <Warehouse>();

            foreach (var req in Requisitions)
            {
                wStock.Add(AllWarehouseStock.FirstOrDefault(w => w.Id == req.StockId));
            }
            WStock = wStock;
            if (await _userManager.IsInRoleAsync(ApplicationUser, "Admin"))
            {
                try
                {
                    CreatePDF(AllSuppliers.FirstOrDefault(s => s.Id == Convert.ToInt32(SelectedSupplier)).Email, ReqNo);
                }
                catch (Exception)
                {
                    _logger.LogError("Error in creating PDF");
                }
                Requisitions = _context.Requisitions.AsNoTracking().Where(r => r.ReqNo == ReqNo).ToList();
                foreach (var req in Requisitions)
                {
                    req.Approved     = "Approved";
                    req.ApprovedDate = DateTime.Now;
                    req.Approver     = ApplicationUser.UserName;

                    _context.Requisitions.Update(req);
                }
                _context.SaveChanges();
                TempData["StatusMessage"] = "Requisition created, approved and sent to supplier.";
            }
            else
            {
                TempData["StatusMessage"] = "Requisition created and waiting approval.";
            }
            return(Redirect("~/WarehousePages/RequisitionIndex"));
        }
        public async Task <IActionResult> OnPostAddItems()
        {
            Suppliers = _context.Suppliers.AsNoTracking().Select(n => new SelectListItem
            {
                Value = n.Id.ToString(),
                Text  = n.Name
            }).ToList();
            WarehouseStock = _context.WarehouseStock.AsNoTracking().Select(n => new SelectListItem
            {
                Value = n.Id.ToString(),
                Text  = n.StockName
            }).ToList();
            AllSuppliers      = _context.Suppliers.AsNoTracking().ToList();
            AllWarehouseStock = _context.WarehouseStock.AsNoTracking().ToList();
            Supplier          = AllSuppliers.FirstOrDefault(s => s.Id == Requisitions.FirstOrDefault().SupplierId);
            SelectedSupplier  = Supplier.Name;
            List <Warehouse> wStock = new List <Warehouse>();

            foreach (var req in Requisitions)
            {
                wStock.Add(AllWarehouseStock.FirstOrDefault(w => w.Id == req.StockId));
            }
            WStock = wStock;
            Warehouse warehouseStock = new Warehouse();

            warehouseStock = _context.WarehouseStock.AsNoTracking().AsNoTracking().FirstOrDefault(s => s.Id == Convert.ToInt32(SelectedStock));

            ApplicationUser = await _userManager.GetUserAsync(User);

            Requisition requisition = new Requisition
            {
                StockId      = warehouseStock.Id,
                Quantity     = Quantity,
                Price        = warehouseStock.Price,
                Total        = warehouseStock.Price * Quantity,
                Requester    = ApplicationUser.UserName,
                ReqDate      = DateTime.Now,
                SupplierId   = Convert.ToInt32(SelectedSupplier),
                ReqNo        = ReqNo,
                Approved     = "Waiting Approval",
                ApprovedDate = DateTime.Now
            };
            await _context.Requisitions.AddAsync(requisition);

            await _context.SaveChangesAsync();

            Requisitions = _context.Requisitions.AsNoTracking().Where(r => r.ReqNo == ReqNo).ToList();
            return(Page());
        }
        public async Task <string> CreateRequisition(string location, string user)
        {
            var newId       = Guid.NewGuid().ToString();
            var scheduleFor = this.context.NextProductsSchedule.FirstOrDefault();
            var requisition = new Requisitions()
            {
                Id          = newId,
                Date        = DateTime.UtcNow,
                Location    = location,
                Status      = 0,
                ScheduleFor = scheduleFor.NextSchedule,
                AddedBy     = user,
                Total       = 0
            };

            await this.context.Requisitions.AddAsync(requisition);

            await this.context.SaveChangesAsync();

            return(newId);
        }
Esempio n. 6
0
        //End of background jobs

        //Check for maintenance history and create requisitioin
        public void CheckForMaintenanceHistoryAndCreateRequisition(int?VehicleId, CheckUpCard CheckUp, JobCards jobCard)
        {
            //Check for maintenance
            MaintenanceHistory maintenanceHistory = db.MaintenanceHistory.FirstOrDefault(m => m.MaintenanceStatus == null && m.JobCardId == null && m.InitialControlSchedule.VehicleId == VehicleId);

            if (maintenanceHistory != null)
            {
                CheckUp.MaintenanceTypeId = maintenanceHistory.MaintenanceId;
                jobCard.IsMaintenance     = true;

                //Updating Maintenance history
                MaintenanceHistory newMaintenanceHistory = db.MaintenanceHistory.Find(maintenanceHistory.Id);
                newMaintenanceHistory.JobCardId = jobCard.Id;
                if (ModelState.IsValid)
                {
                    db.Entry(newMaintenanceHistory).State = EntityState.Modified;
                }

                //Create Requisition
                int?brandId = db.Vehicles.Find(VehicleId).BrandId;
                List <WarehouseToMaintenance> warehouseToMaintenances = db.WarehouseToMaintenance.Where(w => w.MaintenanceTypeId == maintenanceHistory.MaintenanceId && w.TempWarehouse.VehicleId == brandId).ToList();

                foreach (var item in warehouseToMaintenances)
                {
                    //If it is includes to the range(if true) must not erquire SP else require
                    if (!CheckForSparePartIfMustAdd(VehicleId, item.NotRequireSPLimit, item.WarehouseId))
                    {
                        Requisitions requisition = new Requisitions();
                        requisition.IsOpen           = true;
                        requisition.JobCardId        = jobCard.Id;
                        requisition.TempWarehouseId  = item.WarehouseId;
                        requisition.RequiredQuantity = item.Quantity;
                        requisition.AddedDate        = DateTime.Now;

                        db.Requisitions.Add(requisition);
                        db.SaveChanges();
                    }
                }
            }
        }
Esempio n. 7
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            var username = HttpContext.Session.GetString("_username");
            var usertype = HttpContext.Session.GetString("_usertype");
            var access   = new Access(username, "Student");

            if (access.IsLogin())
            {
                if (access.IsAuthorize(usertype))
                {
                    if (id == null)
                    {
                        return(NotFound());
                    }

                    Project = await _context.Project.Where(s => s.DateDeleted == null).FirstOrDefaultAsync(m => m.ProjectId == id);

                    if (Project == null)
                    {
                        return(NotFound());
                    }

                    ProjectSpecialization = await _context.ProjectSpecialization.FirstOrDefaultAsync(ps => ps.ProjectId == Project.ProjectId);

                    Specialization = await _context.Specialization.Where(s => s.DateDeleted == null).FirstOrDefaultAsync(s => s.SpecializationId == ProjectSpecialization.SpecializationId);

                    Supervisor = await _context.Supervisor.Where(s => s.DateDeleted == null).FirstOrDefaultAsync(s => s.AssignedId == Project.SupervisorId);

                    CoSupervisor = await _context.Supervisor.Where(s => s.DateDeleted == null).FirstOrDefaultAsync(s => s.AssignedId == Project.CoSupervisorId);

                    Requisitions = await _context.Requisition.Where(s => s.DateDeleted == null).Where(i => i.Sender == username).ToListAsync();

                    if (Requisitions.Count() == 0)
                    {
                        CanRequisition = true;
                    }
                    else
                    {
                        CanRequisition = true;

                        foreach (var Requisition in Requisitions)
                        {
                            if (Requisition.RequisitionStatus != "Rejected")
                            {
                                CanRequisition = false;
                                break;
                            }
                        }
                    }

                    var proposal = await _context.Proposal.Where(p => p.DateDeleted == null).Where(p => p.ProposalStatus == "New").FirstOrDefaultAsync(p => p.Sender == username);

                    if (proposal != null)
                    {
                        CanRequisition = false;
                    }

                    var student = await _context.Student.Where(s => s.DateDeleted == null).FirstOrDefaultAsync(s => s.AssignedId == username);

                    if (student.ProjectId != null)
                    {
                        CanRequisition = false;
                    }

                    return(Page());
                }
                else
                {
                    ErrorMessage = "Access Denied";
                    return(RedirectToPage($"/{usertype}/Index"));
                }
            }
            else
            {
                ErrorMessage = "Login Required";
                return(RedirectToPage("/Account/Login"));
            }
        }
Esempio n. 8
0
        public INVStoreTrans GetTransactionDetailsAfterSearch(long _TransactionID)
        {
            var model = new INVStoreTrans();


            using (_context)
            {
                var RequisitionID = (from r in _context.INV_StoreTransRequest
                                     where r.TransactionID == _TransactionID
                                     select r.RequisitionID
                                     ).FirstOrDefault();

                if (RequisitionID != null)
                {
                    var TransactionInfo = (from t in _context.INV_StoreTrans.AsEnumerable()
                                           where t.TransactionID == _TransactionID

                                           join req in _context.INV_StoreTransRequest on t.TransactionID equals req.TransactionID into Requests
                                           from req in Requests.DefaultIfEmpty()

                                           //from req in _context.INV_StoreTransRequest.Where(x => x.TransactionID == _TransactionID).DefaultIfEmpty()

                                           join r in _context.PRD_ChemProdReq on RequisitionID equals r.RequisitionID into Requisitions
                                           from r in Requisitions.DefaultIfEmpty()

                                           //from r in _context.PRD_ChemProdReq.Where(x => x.RequisitionID == RequisitionID).DefaultIfEmpty()

                                           join u in _context.Users on(r == null ? null : r.ReqRaisedBy) equals u.UserID into UserInfo
                                           from u in UserInfo.DefaultIfEmpty()

                                           //from u in _context.Users.Where(x => x.UserID == r.ReqRaisedBy).DefaultIfEmpty()
                                           select new INVStoreTrans
                    {
                        TransactionID = t.TransactionID,
                        TransactionNo = t.TransactionNo,
                        IssueFrom = t.TransactionFrom,
                        IssueTo = t.TransactionTo,
                        TransactionDate = (Convert.ToDateTime(t.TransactionDate)).ToString("dd'/'MM'/'yyyy"),
                        RecordStatus = t.RecordStatus,
                        RequisitionID = (r == null ? 0 : r.RequisitionID),
                        RequisitionNo = (r == null ? null : r.RequisitionNo),
                        RequisitionCategory = (r == null ? null : DalCommon.ReturnRequisitionCategory(r.RequisitionCategory)),
                        RequisitionType = (r == null ? null : DalCommon.ReturnOrderType(r.RequisitionType)),
                        RequiredByTime = (r == null ? null : (r.RequiredByTime).ToString()),
                        ReqRaisedOn = (r == null ? null : (Convert.ToDateTime(r.ReqRaisedOn)).ToString("dd'/'MM'/'yyyy")),
                        ReqRaisedByName = (u == null ? null : (u.FirstName + " " + u.MiddleName + " " + u.LastName)),
                        JobOrderNo = (r == null ? null : r.JobOrderNo),
                        Remark = (req == null ? null : req.Remark),
                        TransactionType = t.TransactionType
                    }).FirstOrDefault();


                    model.TransactionInfo = TransactionInfo;

                    var TransactionItemList = GetTransactionItemList(_TransactionID, TransactionInfo.IssueFrom);

                    model.TransactionItemList = TransactionItemList;

                    return(model);
                }

                else
                {
                    var TransactionInfo = (from t in _context.INV_StoreTrans.AsEnumerable()
                                           where t.TransactionID == _TransactionID

                                           join req in _context.INV_StoreTransRequest on t.TransactionID equals req.TransactionID into Requests
                                           from req in Requests.DefaultIfEmpty()

                                           //from req in _context.INV_StoreTransRequest.Where(x => x.TransactionID == _TransactionID).DefaultIfEmpty()

                                           select new INVStoreTrans
                    {
                        TransactionID = t.TransactionID,
                        TransactionNo = t.TransactionNo,
                        IssueFrom = t.TransactionFrom,
                        IssueTo = t.TransactionTo,
                        TransactionDate = (Convert.ToDateTime(t.TransactionDate)).ToString("dd'/'MM'/'yyyy"),
                        RecordStatus = t.RecordStatus,
                        Remark = (req == null ? null : req.Remark),
                        ReqToDate = (Convert.ToDateTime(req.ReqToDate)).ToString("dd'/'MM'/'yyyy"),
                        ReqFromDate = (Convert.ToDateTime(req.ReqFromDate)).ToString("dd'/'MM'/'yyyy"),
                        TransactionType = t.TransactionType
                    }).FirstOrDefault();


                    model.TransactionInfo = TransactionInfo;

                    if (TransactionInfo.TransactionType == "ADI")
                    {
                        var TransactionItemList = GetTransactionItemListForStockAdjust(_TransactionID, TransactionInfo.IssueFrom);
                        model.TransactionItemList = TransactionItemList;
                    }
                    else
                    {
                        var TransactionItemList = GetTransactionItemList(_TransactionID, TransactionInfo.IssueFrom);
                        model.TransactionItemList = TransactionItemList;
                    }



                    return(model);
                }
            }
        }