public EmployeeVacation GetEmployeeVacations(string employeeID)
        {
            EmployeeVacation result = new EmployeeVacation();

            var employee = this._nomipaqEmployee.SearhItemsFor(g => g.codigoempleado.Equals(employeeID));

            if (employee.Any())
            {
                var emp       = employee.FirstOrDefault();
                var vacations = this._nomipaqVacations.SearhItemsFor(j => j.idempleado.Equals(emp.idempleado));
                if (vacations.Any())
                {
                    var totaltomadas = vacations.Sum(t => t.diasvacaciones);
                    var antiguedad   = Math.Abs(Math.Round((emp.fechaalta.Value - DateTime.Today).TotalDays / 365.0, 0));

                    var totalantiguedad   = this._antiguedad.Where(s => s.Antiguedad.Equals(int.Parse(antiguedad.ToString())) || s.Antiguedad < int.Parse(antiguedad.ToString()));
                    var diasporantiguedad = this._antiguedad.Where(s => s.Antiguedad.Equals(int.Parse(antiguedad.ToString()))).FirstOrDefault();
                    if (totalantiguedad.Any())
                    {
                        var days = totalantiguedad.Sum(v => v.Dias);
                        result.Employee        = employeeID;
                        result.Antiguedad      = int.Parse(antiguedad.ToString());
                        result.DiasTomados     = totaltomadas.Value;
                        result.TotalDias       = days;
                        result.DiasDisponibles = days - totaltomadas.Value;
                        result.DiasPorAño      = diasporantiguedad != null ? diasporantiguedad.Dias : 0;
                    }
                }
            }

            return(result);
        }
 public static void InsertNewEmployeeVacation(EmployeeVacation employeeVacation)
 {
     using (ManagementSystemEntities db = new ManagementSystemEntities())
     {
         db.EmployeeVacations.Add(employeeVacation);
         db.SaveChanges();
     }
 }
Ejemplo n.º 3
0
        public ActionResult DeleteConfirmed(int id)
        {
            EmployeeVacation employeeVacation = db.Vacations.Find(id);

            db.Vacations.Remove(employeeVacation);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 4
0
 public ActionResult Edit([Bind(Include = "Id,VacationFrom,VacationTo,StatusVacation,VacationYearTaken,VacationNote,UserID,TypeId")] EmployeeVacation employeeVacation)
 {
     if (ModelState.IsValid)
     {
         db.Entry(employeeVacation).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     return(View(employeeVacation));
 }
Ejemplo n.º 5
0
        public ActionResult Create([Bind(Include = "Id,VacationFrom,VacationTo,StatusVacation,VacationYearTaken,VacationNote,UserID,TypeId")] EmployeeVacation employeeVacation)
        {
            if (ModelState.IsValid)
            {
                db.Vacations.Add(employeeVacation);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(employeeVacation));
        }
Ejemplo n.º 6
0
        public JsonResult GetFormatData(int id,
                                        [FromServices] IRepository <EmployeeFormat> formatRepository,
                                        [FromServices] IOrganigramaModelFactory _organigramaModelFactory,
                                        [FromServices] IRepository <PermissionType> _permissionTypeRepository)
        {
            StringBuilder sb = new StringBuilder();

            var    result = formatRepository.GetElement(id);
            string type   = _permissionTypeRepository.GetElement(result.PermissionType).Description;

            string name = "";

            if (result.EmployeeSubstitute != "0")
            {
                var employee = _organigramaModelFactory.GetEmployeeData(result.EmployeeSubstitute.TrimStart(new Char[] { '0' }));
                name = $"{employee.GeneralInfo.FirstName} {employee.GeneralInfo.LastName}";
            }

            if (type.ToLower().Contains("permiso") || type.ToLower().Contains("pase"))
            {
                sb.Append($"Hora inicial : {result.StartTime}{Environment.NewLine}");
                sb.Append($"Hora final : {result.EndTime}{Environment.NewLine}");
                if (result.WithPay)
                {
                    sb.Append($"Con goze de sueldo : Si{Environment.NewLine}");
                }
                else
                {
                    sb.Append($"Con goze de sueldo : No{Environment.NewLine}");
                }
            }
            else if (type.ToLower().Contains("vacacion"))
            {
                if (!string.IsNullOrEmpty(result.NomipaqVacations))
                {
                    EmployeeVacation empvac = JsonConvert.DeserializeObject <EmployeeVacation>(result.NomipaqVacations);
                    sb.Append($"Total de días : {empvac.TotalDias}{Environment.NewLine}");
                    sb.Append($"Total de días gozados : {empvac.DiasTomados}{Environment.NewLine}");
                    sb.Append($"Total de días disponibles : {empvac.DiasDisponibles}{Environment.NewLine}");
                }
            }

            return(Json(new
            {
                type = type,
                comment = result.Comments,
                dateini = result.StartDate.ToShortDateString(),
                datefin = result.EndDate.ToShortDateString(),
                sustitute = name,
                config = sb.ToString()
            }));
        }
Ejemplo n.º 7
0
        // GET: EmployeeVacations/Delete/5
        public ActionResult Delete(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            EmployeeVacation employeeVacation = db.Vacations.Find(id);

            if (employeeVacation == null)
            {
                return(HttpNotFound());
            }
            return(View(employeeVacation));
        }
Ejemplo n.º 8
0
        public void UpdateRelatedOperations_ChangeVacationRecalculateOperations()
        {
            var uow = Substitute.For <IUnitOfWork>();

            var employee = new EmployeeCard();

            var vacationType = Substitute.For <VacationType>();

            vacationType.ExcludeFromWearing.Returns(true);

            var vacation = new EmployeeVacation();

            vacation.Employee     = employee;
            vacation.BeginDate    = new DateTime(2019, 3, 1);
            vacation.EndDate      = new DateTime(2019, 3, 10);
            vacation.VacationType = vacationType;

            employee.Vacations.Add(vacation);

            var norm = new NormItem();

            norm.Amount      = 1;
            norm.PeriodCount = 3;
            norm.NormPeriod  = NormPeriodType.Month;

            var nomenclatureType = Substitute.For <ItemsType>();
            var protectionTools  = Substitute.For <ProtectionTools>();

            var nomenclature = Substitute.For <Nomenclature>();

            nomenclature.TypeName.Returns("fake");
            nomenclature.Type.Returns(nomenclatureType);

            var issue = new EmployeeIssueOperation();

            issue.UseAutoWriteoff = true;
            issue.Employee        = employee;
            issue.Nomenclature    = nomenclature;
            issue.ProtectionTools = protectionTools;
            issue.NormItem        = norm;
            issue.OperationTime   = new DateTime(2019, 2, 10);
            issue.StartOfUse      = new DateTime(2019, 2, 10);
            issue.ExpiryByNorm    = new DateTime(2019, 5, 10);
            issue.Issued          = 1;

            var operations = new List <EmployeeIssueOperation>()
            {
                issue
            };

            IssueGraph.MakeIssueGraphTestGap = (e, t) => new IssueGraph(operations);

            var employeeIssueRepository = Substitute.For <EmployeeIssueRepository>(uow);

            employeeIssueRepository.GetOperationsTouchDates(Arg.Any <IUnitOfWork>(), Arg.Any <EmployeeCard[]>(), Arg.Any <DateTime>(), Arg.Any <DateTime>(), Arg.Any <Action <IQueryOver <EmployeeIssueOperation, EmployeeIssueOperation> > >())
            .Returns(operations);

            var ask = Substitute.For <IInteractiveQuestion>();

            ask.Question(string.Empty).ReturnsForAnyArgs(false);

            var baseParameters = Substitute.For <BaseParameters>();

            baseParameters.ColDayAheadOfShedule.Returns(0);

            vacation.UpdateRelatedOperations(uow, employeeIssueRepository, baseParameters, ask);

            Assert.That(issue.ExpiryByNorm, Is.EqualTo(new DateTime(2019, 5, 20)));
            Assert.That(issue.AutoWriteoffDate, Is.EqualTo(new DateTime(2019, 5, 20)));
        }
Ejemplo n.º 9
0
 public FormatRequestModel()
 {
     EmployeeFormats   = new List <EmployeeFormatItem>();
     EmployeeVacations = new EmployeeVacation();
 }
Ejemplo n.º 10
0
        public void HandleDeleteEmployeeVacation_RecalculateDatesAndNextIssueTest()
        {
            var ask = Substitute.For <IInteractiveQuestion>();

            ask.Question(string.Empty).ReturnsForAnyArgs(true);

            using (var uow = UnitOfWorkFactory.CreateWithoutRoot("Тест на обработку события удаления")) {
                BuisnessLogicGlobalEventHandler.Init(ask, UnitOfWorkFactory);

                var nomenclatureType = new ItemsType();
                nomenclatureType.Name = "Тестовый тип номенклатуры";
                uow.Save(nomenclatureType);

                var nomenclature = new Nomenclature();
                nomenclature.Type = nomenclatureType;
                uow.Save(nomenclature);

                var protectionTools = new ProtectionTools();
                protectionTools.Name = "СИЗ для тестирования";
                protectionTools.AddNomeclature(nomenclature);
                uow.Save(protectionTools);

                var norm     = new Norm();
                var normItem = norm.AddItem(protectionTools);
                normItem.Amount      = 1;
                normItem.NormPeriod  = NormPeriodType.Month;
                normItem.PeriodCount = 2;
                uow.Save(norm);

                var employee = new EmployeeCard();

                var vacationType = new VacationType();
                vacationType.Name = "Тестовый отпуск";
                vacationType.ExcludeFromWearing = true;

                var vacation = new EmployeeVacation();
                vacation.BeginDate    = new DateTime(2019, 2, 1);
                vacation.EndDate      = new DateTime(2019, 3, 1);
                vacation.VacationType = vacationType;
                employee.AddVacation(vacation);
                uow.Save(vacationType);
                uow.Save(vacation);
                uow.Save(employee);

                var warehouseOperation = new WarehouseOperation();
                warehouseOperation.Nomenclature = nomenclature;
                uow.Save(warehouseOperation);

                var expenseOp = new EmployeeIssueOperation();
                expenseOp.OperationTime      = new DateTime(2019, 1, 1);
                expenseOp.ExpiryByNorm       = new DateTime(2019, 4, 1);
                expenseOp.Employee           = employee;
                expenseOp.Nomenclature       = nomenclature;
                expenseOp.ProtectionTools    = protectionTools;
                expenseOp.NormItem           = normItem;
                expenseOp.Issued             = 1;
                expenseOp.WarehouseOperation = warehouseOperation;
                uow.Save(expenseOp);
                uow.Commit();

                //Выполняем удаление
                employee.Vacations.Remove(vacation);
                uow.Delete(vacation);
                uow.Commit();

                //проверяем данные
                using (var uow2 = UnitOfWorkFactory.CreateWithoutRoot("Тест на обработку события удаления uow2")) {
                    var resultOp = uow2.GetById <EmployeeIssueOperation>(expenseOp.Id);
                    Assert.That(resultOp.ExpiryByNorm, Is.EqualTo(new DateTime(2019, 3, 1)));
                }
            }
        }
Ejemplo n.º 11
0
        public void HandleDeleteEmployeeVacation_RecalculateWithTwoIssuePerDayTest()
        {
            var ask = Substitute.For <IInteractiveQuestion>();

            ask.Question(string.Empty).ReturnsForAnyArgs(true);
            var baseParameters = Substitute.For <BaseParameters>();

            baseParameters.ColDayAheadOfShedule.Returns(0);

            using (var uow = UnitOfWorkFactory.CreateWithoutRoot("Тест на обработку события удаления")) {
                BuisnessLogicGlobalEventHandler.Init(ask, UnitOfWorkFactory);

                var nomenclatureType = new ItemsType();
                nomenclatureType.Name = "Тестовый тип номенклатуры";
                uow.Save(nomenclatureType);

                var nomenclature = new Nomenclature();
                nomenclature.Type = nomenclatureType;
                uow.Save(nomenclature);

                var protectionTools = new ProtectionTools();
                protectionTools.Name = "СИЗ для тестирования";
                protectionTools.AddNomeclature(nomenclature);
                uow.Save(protectionTools);

                var norm     = new Norm();
                var normItem = norm.AddItem(protectionTools);
                normItem.Amount      = 1;
                normItem.NormPeriod  = NormPeriodType.Year;
                normItem.PeriodCount = 1;
                uow.Save(norm);

                var employee = new EmployeeCard();
                employee.AddUsedNorm(norm);

                var vacationType = new VacationType();
                vacationType.Name = "Тестовый отпуск";
                vacationType.ExcludeFromWearing = true;

                var vacation = new EmployeeVacation();
                vacation.BeginDate    = new DateTime(2019, 2, 1);
                vacation.EndDate      = new DateTime(2019, 2, 10);
                vacation.VacationType = vacationType;
                employee.AddVacation(vacation);
                uow.Save(vacationType);
                uow.Save(vacation);
                uow.Save(employee);
                uow.Commit();

                var warehouseOperation = new WarehouseOperation();
                warehouseOperation.Nomenclature = nomenclature;
                uow.Save(warehouseOperation);

                var expenseOp = new EmployeeIssueOperation();
                expenseOp.OperationTime      = new DateTime(2019, 1, 1, 14, 0, 0);
                expenseOp.AutoWriteoffDate   = new DateTime(2020, 1, 1);
                expenseOp.Employee           = employee;
                expenseOp.Nomenclature       = nomenclature;
                expenseOp.ProtectionTools    = protectionTools;
                expenseOp.NormItem           = normItem;
                expenseOp.Issued             = 1;
                expenseOp.WarehouseOperation = warehouseOperation;
                var graph = IssueGraph.MakeIssueGraph(uow, employee, protectionTools);
                expenseOp.RecalculateDatesOfIssueOperation(graph, baseParameters, ask);
                uow.Save(expenseOp);

                var warehouseOperation2 = new WarehouseOperation();
                warehouseOperation2.Nomenclature = nomenclature;
                uow.Save(warehouseOperation2);

                var expenseOp2 = new EmployeeIssueOperation();
                expenseOp2.OperationTime      = new DateTime(2019, 1, 1, 13, 0, 0);
                expenseOp2.AutoWriteoffDate   = new DateTime(2020, 1, 1);
                expenseOp2.Employee           = employee;
                expenseOp2.Nomenclature       = nomenclature;
                expenseOp2.ProtectionTools    = protectionTools;
                expenseOp2.NormItem           = normItem;
                expenseOp2.Issued             = 1;
                expenseOp2.WarehouseOperation = warehouseOperation2;
                graph = IssueGraph.MakeIssueGraph(uow, employee, protectionTools);
                expenseOp2.RecalculateDatesOfIssueOperation(graph, baseParameters, ask);
                uow.Save(expenseOp2);
                uow.Commit();

                vacation.UpdateRelatedOperations(uow, new EmployeeIssueRepository(), baseParameters, ask);
                uow.Commit();

                Assert.That(employee.WorkwearItems[0].NextIssue, Is.EqualTo(new DateTime(2021, 1, 11)));

                //Выполняем удаление
                employee.Vacations.Remove(vacation);
                uow.Delete(vacation);
                uow.Commit();

                //проверяем данные
                using (var uow2 = UnitOfWorkFactory.CreateWithoutRoot("Тест на обработку события удаления uow2")) {
                    var resultEmployee = uow2.GetById <EmployeeCard>(employee.Id);
                    Assert.That(resultEmployee.WorkwearItems[0].NextIssue, Is.EqualTo(new DateTime(2021, 1, 1)));
                }
            }
        }
Ejemplo n.º 12
0
        public JsonResult GetFormatData(int id,
                                        [FromServices] IRepository <EmployeeFormat> formatRepository,
                                        [FromServices] IOrganigramaModelFactory _organigramaModelFactory,
                                        [FromServices] IRepository <PermissionType> _permissionTypeRepository)
        {
            StringBuilder sb = new StringBuilder();

            var    result = formatRepository.GetElement(id);
            string type   = _permissionTypeRepository.GetElement(result.PermissionType).Description;

            var allPermission  = formatRepository.SearhItemsFor(y => y.EmployeeId.Equals(result.EmployeeId));
            int totpermissions = 0;

            if (allPermission.Any())
            {
                var d = formatRepository.SearhItemsFor(y => y.EmployeeId.Equals(result.EmployeeId)).Select(r => new EmployeeFormatItem()
                {
                    Id             = r.Id,
                    EmployeeId     = r.EmployeeId,
                    ApprovalDate   = r.ApprovalDate.HasValue ? r.ApprovalDate.Value.ToShortDateString() : "",
                    Comments       = r.Comments,
                    CreateDate     = r.CreateDate.ToShortDateString(),
                    EndDate        = r.EndDate.ToShortDateString(),
                    PermissionType = _permissionTypeRepository.GetElement(r.PermissionType).Description,
                    StartDate      = $"({r.StartDate.ToShortDateString()})-({r.EndDate.ToShortDateString()})"
                });

                totpermissions = d.Where(t => t.PermissionType.ToLower().Contains("permiso")).Count();
            }

            string name = "";

            if (result.EmployeeSubstitute != "0")
            {
                var employee = _organigramaModelFactory.GetEmployeeData(result.EmployeeSubstitute.TrimStart(new Char[] { '0' }));
                name = $"{employee.GeneralInfo.FirstName} {employee.GeneralInfo.LastName}";
            }

            if (type.ToLower().Contains("permiso") || type.ToLower().Contains("pase"))
            {
                sb.Append($"Hora inicial : {result.StartTime}{Environment.NewLine}");
                sb.Append($"Hora final : {result.EndTime}{Environment.NewLine}");
                if (result.WithPay)
                {
                    sb.Append($"Con goze de sueldo : Si{Environment.NewLine}");
                }
                else
                {
                    sb.Append($"Con goze de sueldo : No{Environment.NewLine}");
                }
                if (totpermissions > 0)
                {
                    sb.Append($"Permisos registrados : {totpermissions}");
                }
            }
            else if (type.ToLower().Contains("vacacion"))
            {
                if (!string.IsNullOrEmpty(result.NomipaqVacations))
                {
                    EmployeeVacation empvac = JsonConvert.DeserializeObject <EmployeeVacation>(result.NomipaqVacations);
                    sb.Append($"Total de días : {empvac.TotalDias}{Environment.NewLine}");
                    sb.Append($"Total de días gozados : {empvac.DiasTomados}{Environment.NewLine}");
                    sb.Append($"Total de días disponibles : {empvac.DiasDisponibles}{Environment.NewLine}");
                }
            }

            return(Json(new
            {
                type = type,
                comment = result.Comments,
                dateini = result.StartDate.ToShortDateString(),
                datefin = result.EndDate.ToShortDateString(),
                sustitute = name,
                config = sb.ToString()
            }));
        }
        public void UpdateOperations_RecalculeteDatesAfterCreateVacation()
        {
            var ask = Substitute.For <IInteractiveQuestion>();

            ask.Question(string.Empty).ReturnsForAnyArgs(true);
            var baseParameters = Substitute.For <BaseParameters>();

            baseParameters.ColDayAheadOfShedule.Returns(0);

            using (var uow = UnitOfWorkFactory.CreateWithoutRoot()) {
                var warehouse = new Warehouse();
                uow.Save(warehouse);

                var nomenclatureType = new ItemsType();
                nomenclatureType.Name = "Тестовый тип номенклатуры";
                uow.Save(nomenclatureType);

                var nomenclature = new Nomenclature();
                nomenclature.Type = nomenclatureType;
                uow.Save(nomenclature);

                var position1 = new StockPosition(nomenclature, 0, null, null);

                var nomenclature2 = new Nomenclature();
                nomenclature2.Type = nomenclatureType;
                uow.Save(nomenclature2);

                var protectionTools = new ProtectionTools();
                protectionTools.AddNomeclature(nomenclature);
                protectionTools.AddNomeclature(nomenclature2);
                protectionTools.Name = "СИЗ для тестирования";
                uow.Save(protectionTools);

                var position2 = new StockPosition(nomenclature2, 0, null, null);

                var norm     = new Norm();
                var normItem = norm.AddItem(protectionTools);
                normItem.Amount      = 1;
                normItem.NormPeriod  = NormPeriodType.Year;
                normItem.PeriodCount = 1;
                uow.Save(norm);

                var employee = new EmployeeCard();
                employee.AddUsedNorm(norm);
                uow.Save(employee);
                uow.Commit();

                var income = new Income();
                income.Warehouse = warehouse;
                income.Date      = new DateTime(2017, 1, 1);
                income.Operation = IncomeOperations.Enter;
                var incomeItem1 = income.AddItem(nomenclature);
                incomeItem1.Amount = 10;
                var incomeItem2 = income.AddItem(nomenclature2);
                incomeItem2.Amount = 5;
                income.UpdateOperations(uow, ask);
                uow.Save(income);

                var expense = new Expense();
                expense.Warehouse = warehouse;
                expense.Employee  = employee;
                expense.Date      = new DateTime(2018, 5, 10);
                expense.Operation = ExpenseOperations.Employee;
                expense.AddItem(position1, 1);
                expense.AddItem(position2, 1);

                //Обновление операций
                expense.UpdateOperations(uow, baseParameters, ask);
                uow.Save(expense);
                uow.Commit();

                expense.UpdateEmployeeWearItems();
                uow.Commit();

                Assert.That(employee.WorkwearItems[0].NextIssue,
                            Is.EqualTo(new DateTime(2020, 5, 10))
                            );

                //Добавляем новый отпуск на 10 дней.
                var vacationType = new VacationType();
                vacationType.Name = "Тестовый отпуск";
                vacationType.ExcludeFromWearing = true;

                var vacation = new EmployeeVacation();
                vacation.BeginDate    = new DateTime(2019, 2, 1);
                vacation.EndDate      = new DateTime(2019, 2, 10);
                vacation.VacationType = vacationType;
                employee.AddVacation(vacation);
                vacation.UpdateRelatedOperations(uow, new workwear.Repository.Operations.EmployeeIssueRepository(), baseParameters, ask);
                uow.Save(vacationType);
                uow.Save(vacation);
                uow.Save(employee);

                Assert.That(employee.WorkwearItems[0].NextIssue,
                            Is.EqualTo(new DateTime(2020, 5, 20))
                            );
            }
        }