public ViewResult Index()
        {
            var model = new List <Tuple <Car, Client, Rent> >();

            foreach (var item in _rentsRepository.GetAllRents())
            {
                Tuple <Car, Client, Rent> t1 = Tuple.Create(_carsRepository.GetCar(item.CarId), _clientsRepository.GetClient(item.ClientId), item);
                model.Add(t1);
            }
            return(View(model));
        }
        public ViewResult Index()
        {
            List <Service> services = _sevicesRepository.GetAll().ToList();

            foreach (var item in services)
            {
                item.Car     = _carsrepository.GetCar(item.CarId);
                item.Client  = _clientsRepository.GetClient(item.ClientId);
                item.Invoice = _invoicesRepository.GetInvoice(item.InvoiceId);
            }
            return(View(services));
        }
        public ActionResult Edit(Guid?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }

            ClientW client = _rep.GetClient(id.Value);

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

            return(View(client));
        }
Exemple #4
0
        public ViewResult Details(Guid id)
        {
            Client client = _clientsRepository.GetClient(id);
            List <Tuple <Car, Rent> > activerents   = new List <Tuple <Car, Rent> >();
            List <Tuple <Car, Rent> > finishedrents = new List <Tuple <Car, Rent> >();

            foreach (var rent in _rentsRepository.GetAllRentsByClient(id))
            {
                if (rent.IsFinished == true)
                {
                    Tuple <Car, Rent> tuple = Tuple.Create(_carsRepository.GetCar(rent.CarId), rent);
                    finishedrents.Add(tuple);
                }
                if (rent.IsActive == true && rent.IsFinished == false)
                {
                    Tuple <Car, Rent> tuple = Tuple.Create(_carsRepository.GetCar(rent.CarId), rent);
                    activerents.Add(tuple);
                }
            }
            List <Income>  incomes  = new List <Income>();
            List <Invoice> expenses = new List <Invoice>();

            foreach (var item in _incomesRepository.GetAllByClient(id))
            {
                Income temp = item;
                temp.Invoice = _invoicesRepository.GetInvoice(temp.InvoiceId);
                if (temp.CarId != null)
                {
                    temp.Car = _carsRepository.GetCar(temp.CarId.GetValueOrDefault());
                }
                incomes.Add(temp);
            }
            foreach (var item in _invoicesRepository.GetAllCostByClient(id))
            {
                expenses.Add(item);
            }
            ClientDetailsViewModel model = new ClientDetailsViewModel
            {
                Client        = client,
                ActiveRents   = activerents,
                FinishedRents = finishedrents,
                Incomes       = incomes,
                Expenses      = expenses
            };

            return(View(model));
        }
Exemple #5
0
        public async Task <ActionResult> EditClient(int clientId)
        {
            var client = await _clientRepository.GetClient(clientId);

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

            return(View("EditClient", _mapper.Map <ClientModel>(client)));
        }
        public async Task GetById_Should_Return_Null_Client()
        {
            // Arrange
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            _clientService            = new BankApplication.Service.Service.ClientService(dbContext, _mapper);
            var clientId = 6;

            // Act
            var actual = await _clientService.GetClient(clientId);

            // Assert
            Assert.IsNull(actual);
        }
        public async Task GetById_Should_Return_Correct_Client()
        {
            // Arrange
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            _service = new Service.Service.ClientService(dbContext, _mapper);
            var clientId = 1;

            // Act
            var actual = await _service.GetClient(clientId);

            // Assert
            Assert.AreEqual(clientId, actual.Id);
        }
Exemple #8
0
        public async Task GetClient_ShouldReturnNull()
        {
            using var factory         = new SQLiteDbContextFactory();
            await using var dbContext = factory.CreateContext();
            clientsRepository         = new ClientService(dbContext, mapper);

            //Arrange
            var clientId = 22;

            //Actual
            var actual = await clientsRepository.GetClient(clientId);

            //Assert
            Assert.Null(actual);
        }
Exemple #9
0
        private async void buttonChangeClient_Click(object sender, System.EventArgs e)
        {
            if (!VerifyClintsValues(out var fio, out var telephone, out var address, await _clientsRepository.GetClients()))
            {
                return;
            }

            var client = await _clientsRepository.GetClient(Convert.ToInt32(textBoxIdClient.Text));

            client.FIO           = fio;
            client.ContactNumber = telephone;
            client.Address       = address;
            NormalizeTables();
            await _clientsRepository.UpdateClient(client);

            await UpdateDataGridViewClients();
        }
Exemple #10
0
        public ClientModel GetClient(int id)
        {
            var client = _clientsRepository.GetClient(id);

            return(_mapper.Map <ClientModel>(client));
        }
Exemple #11
0
 public async Task <ClientDTO> GetClient([FromRoute] int id)
 {
     return(await _service.GetClient(id));
 }
        public ViewResult Details(Guid id)
        {
            //Task<IActionResult> task = Task.Run(async () => await PDFAsync());

            Car car = _carsrepository.GetCar(id);
            //FileDescription file1 = new FileDescription
            //{
            //    Id = Guid.NewGuid(),
            //    Ext = ".jpg",
            //    Description = "test1",
            //    Enabled = true
            //};
            //FileDescription file2 = new FileDescription
            //{
            //    Id = Guid.NewGuid(),
            //    Ext = ".jpg",
            //    Description = "test2",
            //    Enabled = true
            //};
            //var file1car1 = new CarFile();
            //var file2car1 = new CarFile();
            //file1car1.Car = car;
            //file1car1.CarId = car.Id;
            //file1car1.FileDescription = file1;
            //file1car1.FileDescriptionId = file1.Id;

            //file2car1.Car = car;
            //file2car1.CarId = car.Id;
            //file2car1.FileDescription = file2;
            //file2car1.FileDescriptionId = file2.Id;
            //_fileDescriptionsRepository.Create(file1);
            //_fileDescriptionsRepository.Create(file2);
            //_carFilesRepository.Add(file1car1);
            //_carFilesRepository.Add(file2car1);


            //dane dla skończonych wynajmów - id klienta,nazwa klienta, użytkownik,tel,mail, od, do, przebieg start, przebieg koniec, id wynajmu
            List <Rent> rents         = _rentsRepository.GetAllRentsByCar(id).ToList();
            Rent        currentRent   = null;
            var         finishedRents = new List <Tuple <Guid, string, string, string, string, DateTime, DateTime, Tuple <int, int, Guid> > >();
            string      clientName    = "";

            if (rents != null)
            {
                foreach (var rent in rents)
                {
                    if (rent.IsFinished)
                    {
                        HandoverDocument document = _handoverDocumentsRepository.GetHandoverByRent(rent.Id);
                        var milage       = Tuple.Create(document.StartMilage, document.EndMilage, rent.Id);
                        var finishedrent = new Tuple <Guid, string, string, string, string, DateTime, DateTime, Tuple <int, int, Guid> >
                                               (rent.ClientId, _clientsRepository.GetClient(rent.ClientId).Name, rent.UserName, rent.UserPhone, rent.UserMail, rent.StartDate, rent.EndDate, milage);
                        finishedRents.Add(finishedrent);
                    }
                    else
                    {
                        if (rent.IsActive)
                        {
                            currentRent = rent;
                            clientName  = _clientsRepository.GetClient(rent.ClientId).Name;
                        }
                    }
                }
            }
            Service lastService            = null;
            IEnumerable <Service> services = _sevicesRepository.GetAllbyCar(car.Id);

            if (services.Count() > 0)
            {
                lastService = services.First();
                foreach (var item in services)
                {
                    item.Client = _clientsRepository.GetClient(item.ClientId);
                    if (item.Date > lastService.Date)
                    {
                        lastService = item;
                    }
                }
            }
            DateTime nextServiceDate   = car.RegistrationDate.AddYears(car.YearsServiceInterval);
            int      daysToNextService = (nextServiceDate - DateTime.Now.Date).Days;

            if (lastService != null)
            {
                nextServiceDate   = lastService.Date.AddYears(car.YearsServiceInterval);
                daysToNextService = (DateTime.Now.Date - nextServiceDate).Days;
            }
            int milageToNextService = car.NextServiceMilage - car.Milage;

            IEnumerable <TyreInfo> tyres = _tyreInfosRepository.GetAllByCar(car.Id);

            foreach (var item in tyres)
            {
                if (item.TyreShopId != Guid.Empty)
                {
                    item.TyreShop = _tyreShopsRepository.GetTyreShop(item.TyreShopId);
                }
                else
                {
                    item.TyreShop = null;
                }
            }
            FinancialInfo financial                     = _financialInfosRepository.GetCarFinancialInfo(car.Id);
            IEnumerable <MilageRecord> records          = _milageRecordsRepository.GetMilageRecordsByCar(car.Id);
            InsurancePolicy            policy           = _insurancePoliciesRepository.GetActiveCarPolicy(car.Id);
            List <InsurancePolicy>     previousPolicies = new List <InsurancePolicy>();

            foreach (var item in _insurancePoliciesRepository.GetAllCarPolicies(car.Id))
            {
                if (!item.IsActive)
                {
                    previousPolicies.Add(item);
                }
            }
            CarDetailsViewModel carDetailsViewModel = new CarDetailsViewModel()
            {
                DaysToNextService   = daysToNextService,
                NextServiceDate     = nextServiceDate,
                MilageToNextService = milageToNextService,
                FinancialInfo       = financial,
                Car                       = car,
                Services                  = services,
                TyreInfos                 = tyres,
                MilageHistory             = records,
                PageTitle                 = "Szczegóły " + car.RegistrationNumber,
                IsCurrentlyRented         = !car.IsAvailable,
                PreviousRents             = finishedRents,
                CurrentRent               = currentRent,
                CurrentRentClientName     = clientName,
                InsurancePolicy           = policy,
                PreviousInsurancePolicies = previousPolicies
            };

            return(View(carDetailsViewModel));
        }
        public async Task <ReportDTO <QuickJobTimeReportDTO> > RunAsync(QuickJobTimeReportCriteria criteria)
        {
            DateTime start = criteria.PeriodSettings.Start;
            DateTime end   = criteria.PeriodSettings.End;
            int      jobId = int.Parse(criteria.SelectedJobId);

            int?limitToEmployeeId = await _sessionAdapter.EmployeeIdAsync();

            if (criteria.ShowAllEmployeesForJob)
            {
                limitToEmployeeId = null;
            }

            using (var conn = new SqlConnection(configuration.GetConnectionString("SiteConnection")))
                using (var cmd = conn.CreateCommand())
                {
                    conn.Open();


                    cmd.CommandText = @"

Select " +

                                      $"	min(Convert(varchar(10),Isnull(te.Date,@WeekStart), 101)) as  {nameof(QuickJobTimeReportDTO.PeriodStart)}, "
                                      + $"	max(Convert(varchar(10),isnull( te.Date,@WeekEnd),101)) as {nameof(QuickJobTimeReportDTO.PeriodEnd)},    "
                                      + $"	COALESCE(e.Last,'') + ', ' + COALESCE(e.First,'')  as  {nameof(QuickJobEmployees.EmployeeName)}, "
                                      + $"	j.JobCode  as  {nameof(QuickJobTimeReportDTO.JobCode)}, "
                                      + $"	j.JobName as  {nameof(QuickJobTimeReportDTO.JobName)},"
                                      + $"	c.ClientName as  {nameof(QuickJobTimeReportDTO.ClientName)}, "
                                      + $"    s.SiteName as  {nameof(QuickJobTimeReportDTO.SiteName)}, "
                                      + $"	jt.LegacyCode + ' - ' + jt.[Name] as {nameof(QuickJobEmployees.TaskName)}, "
                                      + $"	tc.Name as {nameof(QuickJobEmployees.TaskCategory)}, "
                                      + $"	isnull(sum(te.hours),0) as {nameof(QuickJobEmployees.Regular)}, "
                                      + $"    isnull(sum(te.overtimehours),0) as {nameof(QuickJobEmployees.Overtime)}, "
                                      + $"	isnull(sum(te.hours),0) + isnull(sum(te.overtimehours),0) as  {nameof(QuickJobEmployees.Combined)}"
                                      +

                                      @"
from 
    dbo.Jobs j
    inner join dbo.Clients c
        on c.ClientId = j.ClientId
	left outer join [dbo].TimeEntries te
		on j.JobId = te.JobId
    left outer join [dbo].Employees e
		on e.EmployeeId = te.EmployeeId
    inner join dbo.[Sites] s
	    on j.SiteId = s.SiteID
	left outer join dbo.JobTasks jt
		on jt.JobTaskId = te.TaskId
    inner join dbo.TaskCategories tc
	    on tc.TaskCategoryId = jt.TaskCategoryId
where 
	(@JobId is null Or te.JobId = @JobId) and
	te.Date >= @WeekStart and te.Date <= @WeekEnd and
    ISNULL(e.[UserName],'') != '*****@*****.**' "
                                      + (limitToEmployeeId.HasValue ? $" and te.EmployeeId = { limitToEmployeeId.Value}" : string.Empty)
                                      + @"  group by tc.Name,s.SiteName, 
j.JobCode, 
COALESCE(e.Last,'') + ', ' + COALESCE(e.First,'') , 
j.JobName, c.ClientName , 
jt.LegacyCode + ' - ' + jt.[Name], 
j.JobId




Select 
    'Time And Expense Expenditures' as [name]
    ,SUM(ISNULL(e.Amount,0)) as amount
    from dbo.Jobs j
inner join dbo.TimeAndExpenceExpenditures e
on e.JobId = j.JobId
where WeekId BETWEEN @WeekIdStartInclusive AND @WeekIdEndInclusive
AND (@LimitToEmployeeId is null OR @LimitToEmployeeId = e.EmployeeId)
AND (@JobId is null Or j.JobId = @JobId)    
HAVING SUM(ISNULL(e.Amount,0)) > 0

UNION ALL

select 
    'Company Vehicle Expense' as [name]
    ,SUM(ISNULL((ve.TotalNumberOfDaysUsed * 125)
        + CASE WHEN ve.TotalMiles > 250 
            THEN (ve.TotalMiles * .50) - (250 * .50)
            ELSE 0
            END,0)) as amount
from dbo.Jobs j       
inner join dbo.CompanyVehicleExpenditures ve
on ve.JobId = j.JobId
where WeekId BETWEEN @WeekIdStartInclusive AND @WeekIdEndInclusive
AND (@LimitToEmployeeId is null OR @LimitToEmployeeId = ve.EmployeeId)
AND (@JobId is null Or j.JobId = @JobId)    
HAVING SUM(ISNULL((ve.TotalNumberOfDaysUsed * 125)
        + CASE WHEN ve.TotalMiles > 250 
            THEN (ve.TotalMiles * .50) - (250 * .50)
            ELSE 0
            END,0)) > 0

UNION ALL 

select 
    'Contractor/PO Expense' as [name]
    ,SUM(ISNULL(ce.TotalPOContractAmount,0)) as amount
from dbo.Jobs j       
inner join dbo.ContractorExpenditures ce
on j.JobId = ce.JobId
where WeekId BETWEEN @WeekIdStartInclusive AND @WeekIdEndInclusive
AND (@LimitToEmployeeId is null OR @LimitToEmployeeId = ce.EmployeeId)
AND (@JobId is null Or j.JobId = @JobId)   
HAVING SUM(ISNULL(ce.TotalPOContractAmount,0)) > 0

UNION ALL    

select 
    'Arc Flash Labels Expense' as [name]
    ,SUM(ISNULL(e.TotalLabelsCost,0) + ISNULL(e.TotalPostageCost,0)) as amount
FROM dbo.Jobs j
inner join  dbo.ArcFlashlabelExpenditures e
on j.jobId = e.jobId
where WeekId BETWEEN @WeekIdStartInclusive AND @WeekIdEndInclusive
AND (@LimitToEmployeeId is null OR @LimitToEmployeeId = e.EmployeeId)
AND (@JobId is null Or j.JobId = @JobId)   
HAVING SUM(ISNULL(e.TotalLabelsCost,0) + ISNULL(e.TotalPostageCost,0)) > 0

UNION ALL

select 
    'Miscellaneous Expense' as [name]
    ,SUM(ISNULL(e.Amount,0)) as amount
from dbo.Jobs j
inner join dbo.MiscExpenditures e
on j.JobId = e.JobId
where WeekId BETWEEN @WeekIdStartInclusive AND @WeekIdEndInclusive
AND (@LimitToEmployeeId is null OR @LimitToEmployeeId = e.EmployeeId)
AND (@JobId is null Or j.JobId = @JobId)   
HAVING SUM(ISNULL(e.Amount,0)) > 0 ";



                    cmd.Parameters.Add(new SqlParameter("JobId", jobId));
                    cmd.Parameters.Add(new SqlParameter("LimitToEmployeeId", limitToEmployeeId.HasValue ? limitToEmployeeId : DBNull.Value));
                    cmd.Parameters.Add(new SqlParameter("WeekIdStartInclusive", WeekDTO.CreateWithWeekContaining(start).WeekId.Value));
                    cmd.Parameters.Add(new SqlParameter("WeekIdEndInclusive", WeekDTO.CreateWithWeekContaining(end).WeekId.Value));
                    cmd.Parameters.Add(new SqlParameter("WeekStart", start));
                    cmd.Parameters.Add(new SqlParameter("WeekEnd", end));

                    var rdr = cmd.ExecuteReader();

                    var map = GetColumnMap(rdr.GetColumnSchema());
                    var rpt = new QuickJobTimeReportDTO()
                    {
                        PeriodEnd   = end,
                        PeriodStart = start,
                        Expenses    = new Dictionary <string, decimal>()
                    };

                    var employeeRows = new List <QuickJobEmployees>();

                    var job = (await _jobsRepository.GetAsync()).SingleOrDefault(x => x.JobId == jobId);
                    rpt.JobCode    = job.JobCode;
                    rpt.JobName    = job.JobName;
                    rpt.SiteName   = (await _sitesRepository.GetAll()).SingleOrDefault(x => x.SiteID == job.SiteId)?.SiteName;
                    rpt.ClientName = (await _clientsRepository.GetClient(job.ClientId))?.ClientName;

                    while (await rdr.ReadAsync())
                    {
                        if (rdr.HasRows)
                        {
                            employeeRows.Add(new QuickJobEmployees()
                            {
                                Combined     = rdr.GetDecimal(map[nameof(QuickJobEmployees.Combined)]),
                                Regular      = rdr.GetDecimal(map[nameof(QuickJobEmployees.Regular)]),
                                Overtime     = rdr.GetDecimal(map[nameof(QuickJobEmployees.Overtime)]),
                                EmployeeName = rdr.GetSqlString(map[nameof(QuickJobEmployees.EmployeeName)]).Value,
                                TaskCategory = rdr.GetSqlString(map[nameof(QuickJobEmployees.TaskCategory)]).Value,
                                TaskName     = rdr.GetSqlString(map[nameof(QuickJobEmployees.TaskName)]).Value,
                            });
                        }
                    }
                    rpt.Employees = employeeRows;

                    await rdr.NextResultAsync();

                    while (await rdr.ReadAsync())
                    {
                        rpt.Expenses.Add(rdr.GetString(0), rdr.GetDecimal(1));
                    }

                    return(new ReportDTO <QuickJobTimeReportDTO>()
                    {
                        Data = rpt,
                        ReportName = QuickJobTimeReport.QuickJobTimeReportCriteria.QUICK_JOB_TIME_REPORT_NAME,
                        RunSettings =
                            new Dictionary <string, string>()
                        {
                            { "Generated", $"{DateTimeWithZone.EasternStandardTime.ToShortDateString()} at {DateTimeWithZone.EasternStandardTime.ToShortTimeString()}" },
                            { "Company", $"Orion Engineering Co., Inc." },
                            { "Showing Time From", criteria.ShowAllEmployeesForJob ? "All Employees" : "Self" },
                        }
                    });
                }
        }
        private async void addButton_Click(object sender, EventArgs e)
        {
            if (!VerifyDocumentsValues(out var name))
            {
                return;
            }

            var document = new Models.Documents()
            {
                FileName = name
            };
            var folder   = localFileManager.CreateFileFolder("Document_" + document.Id.ToString());
            var format   = ".pdf";
            var trueName = SearchNames(folder, name);

            folder = folder + @"\" + trueName + format;
            //folder = $@"{folder}\{name}" + ".pdf";
            document.FileName = trueName;
            Document doc = new Document();

            PdfWriter.GetInstance(doc, new FileStream(folder, FileMode.Create));
            doc.Open();

            string   ttf      = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Fonts), "ARIAL.TTF");
            BaseFont baseFont = BaseFont.CreateFont(ttf, BaseFont.IDENTITY_H, BaseFont.NOT_EMBEDDED);
            Font     font     = new Font(baseFont, iTextSharp.text.Font.DEFAULTSIZE, iTextSharp.text.Font.NORMAL);

            var dateFrom = dateTimePickerFrom.Value;
            var dateTo   = dateTimePickerTo.Value;

            var currentOrders = await _ordersRepository.GetOrdersinDates(dateFrom, dateTo);

            for (int i = 0; i < currentOrders.Count; i++)
            {
                if (currentOrders[i].TimeCompleted != DateTime.MinValue)
                {
                    var currentuser = await _clientsRepository.GetClient(currentOrders[i].ClientId);

                    var currentworker = await _workerRepository.GetWorker(currentOrders[i].WorkerId);

                    PdfPTable table = new PdfPTable(2);

                    PdfPCell cell = new PdfPCell(new Phrase("Заказ " + $"{currentOrders[i].Id}", font));

                    cell.Colspan             = 2;
                    cell.HorizontalAlignment = 1;
                    cell.Border = 0;
                    table.AddCell(cell);
                    table.AddCell(new Phrase("ID", font));
                    table.AddCell(new Phrase(currentOrders[i].Id.ToString(), font));
                    table.AddCell(new Phrase("ФИО заказчика", font));
                    table.AddCell(new Phrase(currentuser.FIO, font));
                    table.AddCell(new Phrase("телефон заказчика", font));
                    table.AddCell(new Phrase(currentuser.ContactNumber, font));
                    table.AddCell(new Phrase("ФИО исполнителя", font));
                    table.AddCell(new Phrase(currentworker.FIO, font));

                    var col  = new PdfPCell(new Phrase(currentOrders[i].Payment.ToString(), font));
                    var col2 = new PdfPCell(new Phrase(currentOrders[i].PaymentIsDone.ToString(), font));
                    if (currentOrders[i].Payment > currentOrders[i].PaymentIsDone)
                    {
                        col.BackgroundColor  = BaseColor.RED;
                        col2.BackgroundColor = BaseColor.RED;
                    }
                    else
                    {
                        col.BackgroundColor  = BaseColor.WHITE;
                        col2.BackgroundColor = BaseColor.WHITE;
                    }
                    table.AddCell(new Phrase("Сумма к оплате", font));
                    table.AddCell(col);
                    table.AddCell(new Phrase("Оплачено", font));
                    table.AddCell(col2);


                    table.AddCell(new Phrase("Дата завершения", font));
                    table.AddCell(new Phrase(currentOrders[i].TimeCompleted.ToString(), font));

                    doc.Add(table);
                }
            }
            doc.Close();

            document.FileLink    = folder;
            document.TimeCreated = DateTime.Now;
            refreshGridWidth();
            await _documentsRepository.CreateDocuments(document);

            await UpdateDataGridViewDocuments(dateTimePickerFrom.Value, dateTimePickerTo.Value);
            await UpdateDataGridViewOrders(dateTimePickerFrom.Value, dateTimePickerTo.Value);
        }