Exemplo n.º 1
0
        public void saveRequisitionsAsDisbursement(string userId, Dictionary <Departments, List <RequisitionDetail> > requisitionsForDepartment)
        {
            Employee employee = deptService.findEmployeeById(userId);

            foreach (var dept in requisitionsForDepartment)
            {
                //Create new disbursement
                Disbursement d = new Disbursement();
                d.Id             = Guid.NewGuid().ToString();
                d.GeneratedDate  = DateTime.Now;
                d.CollectionDate = DateTime.Now.AddDays(1);
                d.Departments    = dept.Key;
                d.storeClerk     = employee;
                d.DepartmentsId  = dept.Key.Id;
                d.status         = DisbusementStatus.PENDING;
                dbcontext.Add(d);
                dbcontext.SaveChanges();

                //In each new disbursement, create new disbursement
                foreach (var req in dept.Value)
                {
                    DisbursementDetail ddetail = new DisbursementDetail();
                    ddetail.Id                = Guid.NewGuid().ToString();
                    ddetail.DisbursementId    = d.Id;
                    ddetail.Disbursement      = d;
                    ddetail.RequisitionDetail = req;
                    ddetail.disbursedQty      = req.DistributedQty;
                    dbcontext.Add(ddetail);
                    dbcontext.SaveChanges();
                }
            }
        }
        public void CreatePurchaseOrder(string userId, string supplierId)
        {
            List <PurchaseCart> cartList         = dbcontext.purchaseCarts.Where(x => x.EmployeeId == userId).ToList();
            Employee            emp              = deptService.findEmployeeById(userId);
            PurchaseOrder       newPurchaseOrder = new PurchaseOrder();

            newPurchaseOrder.Id         = Guid.NewGuid().ToString();
            newPurchaseOrder.EmployeeId = emp.Id;
            newPurchaseOrder.Employee   = emp;
            newPurchaseOrder.status     = POStatus.PENDING;
            newPurchaseOrder.date       = DateTime.Now;
            newPurchaseOrder.SupplierId = supplierId;
            foreach (var i in cartList)
            {
                Inventory            inv = dbcontext.inventories.Where(x => x.Id == i.Id).FirstOrDefault();
                PurchaseOrderDetails purchaseOrderDetail = new PurchaseOrderDetails();
                purchaseOrderDetail.Id = Guid.NewGuid().ToString();
                purchaseOrderDetail.PurchaseOrderId = newPurchaseOrder.Id;
                purchaseOrderDetail.Inventory       = i.Inventory;
                purchaseOrderDetail.InventoryId     = i.InventoryId;
                purchaseOrderDetail.quantity        = i.Qty;
                dbcontext.Add(purchaseOrderDetail);
            }
            dbcontext.Add(newPurchaseOrder);
            dbcontext.purchaseCarts.RemoveRange(cartList);
            dbcontext.SaveChanges();
        }
        public void AddItem(string userid, string itemid, int qty)
        {
            var oldcartItem = dbcontext.employeeCarts
                              .Where(x => x.EmployeeId == userid && x.InventoryId == itemid)
                              .FirstOrDefault();

            if (oldcartItem == null)
            {
                var cartItem = new EmployeeCart()
                {
                    Id          = Guid.NewGuid().ToString(),
                    EmployeeId  = userid,
                    InventoryId = itemid,
                    Qty         = qty,
                    Inventory   = dbcontext.inventories.SingleOrDefault(p => p.Id == itemid)
                };
                dbcontext.employeeCarts.Add(cartItem);
                dbcontext.SaveChanges();
            }
            else
            {
                oldcartItem.Qty = qty;
                dbcontext.Update(oldcartItem);
                dbcontext.SaveChanges();
            }
        }
        public void updateRequisition(string?userId, string requisitionId, ReqStatus?status, string?remarks)
        {
            Requisition requisition = findRequisition(requisitionId);

            // When authorization period expired, the default approver will be dept head.
            requisition.ApprovedEmployeeId = userId;
            requisition.Remarks            = remarks;
            requisition.status             = (ReqStatus)status;
            dbcontext.Update(requisition);
            dbcontext.SaveChanges();
        }
        public IActionResult updateRetrievalQty(string rqId, string itemId, string newQty, List <string> requi)
        {
            RequisitionDetail rd = (from r in dbcontext.requisitionDetails
                                    where r.Inventory.description == itemId &&
                                    r.Requisition.Id == rqId
                                    select r).FirstOrDefault();

            rd.DistributedQty = int.Parse(newQty);
            dbcontext.SaveChanges();
            System.Diagnostics.Debug.WriteLine("updateRetrievalQty reqlist: " + requi.Count);
            return(RedirectToAction("viewRetrieval", new { req = requi }));
        }
        public void Handle(PersistEmployeeCommand command)
        {
            var employee = _context.Users.FirstOrDefault(x => string.Concat(x.FirstName, " ", x.LastName).ToUpper().Contains(command.FullName.ToUpper()));

            if (employee == null)
            {
                User newEmp = new User();
                newEmp.Set(command.Persist.FirstName,
                           command.Persist.LastName,
                           command.Persist.JobId,
                           command.Persist.UnitId);

                _context.Add(newEmp);
            }
            else
            {
                employee.Set(command.Persist.FirstName,
                             command.Persist.LastName,
                             command.Persist.JobId,
                             command.Persist.UnitId);

                _context.Update(employee);
            }
            _context.SaveChanges();
        }
Exemplo n.º 7
0
        public IActionResult AddRequest(UserProductRequest upr)
        {
            if (ModelState.IsValid)
            {
                _db.UserProductRequest.Add(upr);

                _db.SaveChanges();

                var request = from
                              r in _db.UserProductRequest
                              join u in _db.SprUser on r.UserId equals u.Id
                              join p in _db.SprProduct on r.ProductId equals p.Id
                              select
                              new { r.Id, u.FirstName, u.LastName, p.ProductName, r.ProductAmount };
                request = request.Where(r => r.Id == upr.Id);

                upr.setProductName(request.First().ProductName);
                upr.setUserName(request.First().FirstName + " " + request.First().LastName);

                return(View(upr));
            }
            else
            {
                var users    = from i in _db.SprUser select i;
                var products = from i in _db.SprProduct select i;

                ViewBag.usersCol    = users;
                ViewBag.productsCol = products;

                return(View("Index"));
            }
        }   //  AddRequest()
Exemplo n.º 8
0
        public void CreateRequisition(string userId)
        {
            List <EmployeeCart> cartList       = dbcontext.employeeCarts.Where(x => x.EmployeeId == userId).ToList();
            Employee            emp            = deptService.findEmployeeById(userId);
            Requisition         newRequisition = new Requisition(emp.Departments.DeptCode);

            newRequisition.status = ReqStatus.AWAITING_APPROVAL;
            Employee approver = deptService.setApprover(userId);

            newRequisition.ApprovedEmployee   = approver;
            newRequisition.ApprovedEmployeeId = approver.Id;
            newRequisition.Employee           = emp;
            newRequisition.EmployeeId         = emp.Id;
            newRequisition.DepartmentId       = emp.Departments.Id;
            foreach (var i in cartList)
            {
                Inventory         inv = dbcontext.inventories.Where(x => x.Id == i.Id).FirstOrDefault();
                RequisitionDetail requisitionDetail = new RequisitionDetail();
                requisitionDetail.Id            = Guid.NewGuid().ToString();
                requisitionDetail.RequisitionId = newRequisition.Id;
                requisitionDetail.Inventory     = i.Inventory;
                requisitionDetail.RequestedQty  = i.Qty;
                dbcontext.Add(requisitionDetail);
            }
            dbcontext.Add(newRequisition);
            dbcontext.employeeCarts.RemoveRange(cartList);
            dbcontext.SaveChanges();

            notificationService.sendNotification(NotificationType.REQUISITION, newRequisition, null, null);
        }
        public void recommendQty(Dictionary <string, List <RequisitionDetail> > reqPerIt)
        {
            int itemQty;
            int itemNeeded;

            foreach (var r in reqPerIt)
            {
                Inventory item = (from i in dbcontext.inventories
                                  where i.description == r.Key
                                  select i).FirstOrDefault();
                itemQty = item.stock;
                foreach (var rd in r.Value)
                {
                    itemNeeded = rd.RequestedQty;
                    if (itemQty >= itemNeeded)
                    {
                        rd.DistributedQty = itemNeeded;
                    }
                    else if (itemQty < itemNeeded)
                    {
                        rd.DistributedQty = itemQty;
                    }
                    dbcontext.SaveChanges();
                }
            }
            ;
        }
Exemplo n.º 10
0
        public IActionResult submit(Employee e1)
        {
            Employee e       = new Employee();
            var      regex   = @"\A(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-z0-9](?:[a-z0-9-]*[a-z0-9])?\.)+[a-z0-9](?:[a-z0-9-]*[a-z0-9])?)\Z";
            bool     isValid = Regex.IsMatch(e1.Email, regex, RegexOptions.IgnoreCase);


            string   dateInput  = e1.DateReg.ToString();
            var      parsedDate = DateTime.Parse(dateInput);
            DateTime from       = new DateTime(2019, 1, 1);
            DateTime to         = new DateTime(2019, 6, 30);

            if (parsedDate >= from && parsedDate < to && isValid == true)
            {
                e.Name    = e1.Name.ToString();
                e.Email   = e1.Email.ToString();
                e.Gender  = e1.Gender.ToString();
                e.DateReg = parsedDate.ToString("d", CultureInfo.CreateSpecificCulture("en-US"));

                if (e1.Day1 == true && e1.Day2 == true && e1.Day3 == true)
                {
                    e.SelectedDays = "Day1,Day2,Day3";
                }
                else if (e1.Day1 == true && e1.Day2 == true)
                {
                    e.SelectedDays = "Day1,Day2";
                }
                else if (e1.Day1 == true && e1.Day3 == true)
                {
                    e.SelectedDays = "Day1,Day3";
                }
                else if (e1.Day2 == true && e1.Day3 == true)
                {
                    e.SelectedDays = "Day2,Day3";
                }
                else if (e1.Day1 == true)
                {
                    e.SelectedDays = "Day1";
                }
                else if (e1.Day2 == true)
                {
                    e.SelectedDays = "Day2";
                }
                else if (e1.Day3 == true)
                {
                    e.SelectedDays = "Day3";
                }
                e.AdditionalRequest = e1.AdditionalRequest.ToString();
                dbcontext.Add(e);
                dbcontext.SaveChanges();
                return(RedirectToAction("viewUsers"));
            }
            else
            {
                ViewData["error"] = "Date is wrong";
                return(RedirectToAction("addUser"));
            }
        }
Exemplo n.º 11
0
        public void Handle(SetProductCommand command)
        {
            OrderDetails product = _context.OrderDetails.Where(x => x.OrderId == command.Product.orderId && x.ProductId == command.Product.productId).FirstOrDefault();

            product.SetProduct(command.Product.statusId, command.Product.comment, command.Product.productsCount, command.Id);
            _context.OrderDetails.Update(product);

            _context.SaveChanges();
        }
Exemplo n.º 12
0
        public void Handle(SetOrderCommand command)
        {
            var order = _context.Orders.Find(command.Order.OrderId);

            order.OrderStatusId = command.Order.StatusId;
            //order.IsEnded = true; тука не трябва да се сетва, тъй като в този случай на истина ще бъде видим за следващото ниво (Офис кординатор)

            _context.Orders.Update(order);
            _context.SaveChanges();
        }
        public void Handle(AddToLinkCommand command)
        {
            var lastLink = _context.LinkedOrders.Where(x => x.UserId == command.Id).FirstOrDefault();

            // case 1: no links created
            // case 2:
            // case 3: count of orders smaller than current linked ordrs,
            // Add new link
            if (lastLink == null)
            {
                _context.LinkedOrders.Add(new LinkedOrder {
                    UserId = command.Id, DateCreated = DateTime.Now
                });
                lastLink = _context.LinkedOrders.OrderByDescending(x => x.DateCreated).FirstOrDefault();
            }

            //var orders = _context.Orders.Where(x => x.LinkId == lastLink.LinkId);

            // if (!orders.Any())
            // {
            foreach (int order in command.Orders)
            {
                var currentOrder = _context.Orders.Find(order);
                // currentOrder.IsLinked = true;
                //currentOrder.LinkId = lastLink.LinkId;

                _context.Orders.Update(currentOrder);
            }
            //}
            // add order to link
            //else if (command.Orders.Count() > orders.Count())
            //{

            //}
            // remove order from link
            //else if (command.Orders.Count() < orders.Count())
            //{
            //foreach (var orderItem in orders)
            // {
            // int? currentOrder = command.Orders.Where(m => m == orderItem.OrderId).Select(m => m).FirstOrDefault();
            // if (currentOrder == null)
            // {
            //    var toUnLink = _context.Orders.Find(orderItem);
            // toUnLink.IsLinked = false;
            //toUnLink.LinkId = null;

            //    _context.Orders.Update(toUnLink);
            // }
            // }
            //}

            _context.SaveChanges();
        }
Exemplo n.º 14
0
        public void Handle(CompleteOrderCommand command)
        {
            var order = _context.Orders.FirstOrDefault(x => x.OrderId == command.OrderId);

            if (order == null)
            {
                throw new AppException("Order not found!");
            }
            order.IsCompletedRm = true;

            _context.Orders.Update(order);
            _context.SaveChanges();
        }
        public void Handle(UpdateUserCommand command)
        {
            User user = _context.Users.Find(command.Id);

            user.Set(command.Value.FirstName,
                     command.Value.LastName,
                     command.Value.UserName,
                     command.Value.JobId,
                     command.Value.UnitId);

            _context.Users.Update(user);
            _context.SaveChanges();
        }
        public void sendNotification(NotificationType notificationType, Requisition?requisition, Disbursement?disbursement, AdjustmentVoucher?adjustment)
        {
            Employee sender       = new Employee();
            Employee reciever     = new Employee();
            string   subjectEmail = "";

            switch (notificationType)
            {
            case NotificationType.REQUISITION:
                RequisitionNotif requisitionNotif = new RequisitionNotif();
                subjectEmail = "New Requisition: " + requisition.Id;
                requisitionNotif.Requisition = requisition;
                requisitionNotif.Sender      = requisition.Employee;
                requisitionNotif.ReceiverId  = requisition.ApprovedEmployeeId;
                requisitionNotif.SenderId    = requisition.EmployeeId;
                sender   = requisition.Employee;
                reciever = requisition.ApprovedEmployee;
                dbcontext.Add(requisitionNotif);
                break;

            case NotificationType.DISBURSEMENT:
                DisbursementNotif disbursementNotif = new DisbursementNotif();
                subjectEmail = "New Disbursement: " + disbursement.Id;
                disbursementNotif.Disbursement = disbursement;
                reciever = disbursement.Departments.Employees.Where(x => x.Role == Role.DEPT_REP).FirstOrDefault();
                sender   = disbursement.storeClerk;
                disbursementNotif.Receiver   = reciever;
                disbursementNotif.ReceiverId = reciever.Id;
                disbursementNotif.Sender     = sender;
                disbursementNotif.SenderId   = sender.Id;
                dbcontext.Add(disbursementNotif);
                break;

            case NotificationType.ADJUSTMENTVOUCHER:
                AdjustmentVoucherNotif adjustmentVoucherNotif = new AdjustmentVoucherNotif();
                subjectEmail = "New AdjustmentVoucher: " + adjustment.Id;
                adjustmentVoucherNotif.AdjustmentVoucher = adjustment;
                sender   = adjustment.EmEmployee;
                reciever = adjustment.appEmEmployee;
                adjustmentVoucherNotif.ReceiverId = reciever.Id;
                adjustmentVoucherNotif.SenderId   = sender.Id;
                adjustmentVoucherNotif.Receiver   = reciever;
                adjustmentVoucherNotif.Sender     = sender;
                dbcontext.Add(adjustmentVoucherNotif);
                break;
            }

            dbcontext.SaveChanges();
            SendEmail(sender, reciever, subjectEmail);
        }
Exemplo n.º 17
0
        public User Create(User user, string password)
        {
            // validation
            if (string.IsNullOrWhiteSpace(password))
            {
                throw new AppException("Password is required");
            }
            if (_context.Users.Any(x => x.UserName == user.UserName))
            {
                throw new AppException("Username " + user.UserName + " is already taken");
            }

            byte[] passwordHash, passwordSalt;
            CreatePasswordHash(password, out passwordHash, out passwordSalt);

            user.PasswordHash = passwordHash;
            user.PasswordSalt = passwordSalt;

            _context.Users.Add(user);
            _context.SaveChanges();

            return(user);
        }
        public void Handle(CreateOrderCommand command)
        {
            var unitId = _context.Users.Where(u => u.UserId == command.UserId).Select(u => u.UnitId).FirstOrDefault();

            Order order = new Order();

            order.Create(1, command.Order.TotalAmount, unitId, command.UserId);
            _context.Orders.Add(order);

            var products = CreateProducts(command.Order.Products, order.OrderId);

            _context.OrderDetails.AddRange(products);

            _context.SaveChanges();
        }
        public void createEmployeeAuthorization(string employeeName, string SD, string ED)
        {
            DateTime startDate = DateTime.Parse(SD);
            DateTime endDate   = DateTime.Parse(ED);
            Employee employee  = dbcontext.employees.Where(x => x.Name == employeeName).FirstOrDefault();
            //To extract authorization that is from the dept and have overlapping dates
            List <EmployeeAuthorize> existEmpAuthorize = dbcontext.employeeAuthorizes.Where(x => x.DepartmentsId == employee.DepartmentsId && x.startDate <= endDate && x.endDate >= startDate).ToList();

            if (existEmpAuthorize.Count > 0)
            {
                dbcontext.employeeAuthorizes.RemoveRange(existEmpAuthorize);                              //Remove any authorization that have overlaps in dates
            }
            EmployeeAuthorize newAuthorize = new EmployeeAuthorize();

            newAuthorize.Id            = Guid.NewGuid().ToString();
            newAuthorize.EmployeeId    = employee.Id;
            newAuthorize.startDate     = startDate;
            newAuthorize.endDate       = endDate;
            newAuthorize.DepartmentsId = employee.DepartmentsId;
            dbcontext.employeeAuthorizes.Add(newAuthorize);
            dbcontext.SaveChanges();
        }