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 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);
        }
Exemple #3
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 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);
        }
        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();
        }
        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"));
            }
        }