예제 #1
0
        public ActionResult DownloadJobInformationExcel(bool bMaxLimitExceeded, DateTime from, DateTime to, string timeperiod)
        {
            var generator = new ExcelWriter();

            var xml = string.Empty;

            if (bMaxLimitExceeded == false)
            {
                xml = this.Request.Form["grid_xml"];
                xml = this.Server.UrlDecode(xml);

                var stream = generator.Generate(xml);
                return(File(stream.ToArray(), generator.ContentType, "MyJobInformationReport.xlsx"));
            }
            else
            {
                var HeaderXml = this.Request.Form["grid_xml"];
                HeaderXml = this.Server.UrlDecode(HeaderXml);

                switch (timeperiod)
                {
                case "0":
                    from = DateTime.Now.AddDays(-(DateTime.Now.DayOfWeek - DayOfWeek.Sunday));
                    to   = DateTime.Now;
                    break;

                case "1":
                    from = DateTime.Now.AddDays(-(DateTime.Now.DayOfWeek - DayOfWeek.Sunday + 7));
                    to   = from.AddDays(6);
                    break;

                case "2":
                    from = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
                    to   = DateTime.Now;
                    break;

                case "3":
                    from = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1).AddMonths(-1);
                    to   = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1).AddDays(-1);
                    break;

                case "4":
                    from = new DateTime(DateTime.Today.Year, 1, 1);
                    to   = DateTime.Now;
                    break;

                case "5":
                    from = new DateTime(DateTime.Today.Year - 10, 1, 1);
                    to   = DateTime.Now;
                    break;
                }

                var result = AbstractBusinessService.Create <ReportingService>(UserInfo.UserKey).GetCallStateReport(from, to);

                xml = GetJobInformationXML(result, includeLinks: false).ToString();

                var stream = generator.Generate(AddHeaderToRowsInXML(HeaderXml, xml));
                return(File(stream.ToArray(), generator.ContentType, "MyDetailedCallStats.xlsx"));
            }
        }
        private KeyPerformanceIndicator GetKpiData(int franchiseId, string strStartDate, string strEndDate, bool force)
        {
            if (UserInfo.CurrentFranchise == null || UserInfo.CurrentFranchise.FranchiseID != franchiseId)
            {
                SetCurrentFranchise(franchiseId, UserInfo.ShowInactiveFranchises);
            }

            const string            key = "KPI_DATA";
            KeyPerformanceIndicator kpi = null;

            if (HttpContext.Session != null && HttpContext.Session[key] != null)
            {
                kpi = HttpContext.Session[key] as KeyPerformanceIndicator;
            }

            var startDate = DateTime.Parse(strStartDate).Date;
            var endDate   = DateTime.Parse(strEndDate).Date.AddDays(1);

            if (kpi == null || force)
            {
                kpi = AbstractBusinessService.Create <ReportingService>(UserInfo.UserKey).GetKeyPerformanceIndicators(
                    franchiseId, startDate, endDate);
                Session[key] = kpi;
            }

            return(kpi);
        }
예제 #3
0
        public JsonResult GetCallStateInformation(DateTime from, DateTime to, string timeperiod)
        {
            switch (timeperiod)
            {
            case "0":
                from = DateTime.Now.AddDays(-(DateTime.Now.DayOfWeek - DayOfWeek.Sunday));
                to   = DateTime.Now;
                break;

            case "1":
                from = DateTime.Now.AddDays(-(DateTime.Now.DayOfWeek - DayOfWeek.Sunday + 7));
                to   = from.AddDays(6);
                break;

            case "2":
                from = new DateTime(DateTime.Now.Year, DateTime.Now.Month, 1);
                to   = DateTime.Now;
                break;

            case "3":
                from = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1).AddMonths(-1);
                to   = new DateTime(DateTime.Today.Year, DateTime.Today.Month, 1).AddDays(-1);
                break;

            case "4":
                from = new DateTime(DateTime.Today.Year, 1, 1);
                to   = DateTime.Now;
                break;

            case "5":
                from = new DateTime(DateTime.Today.Year - 10, 1, 1);
                to   = DateTime.Now;
                break;
            }

            var result = AbstractBusinessService.Create <ReportingService>(UserInfo.UserKey).GetCallStateReport(from, to);

            var sb = new StringBuilder();

            sb = GetJobInformationXML(result);

            var serializer = new System.Web.Script.Serialization.JavaScriptSerializer();

            try
            {
                var test = serializer.Serialize(sb.ToString());
                return(Json(new { data = sb.ToString(), maxLimitExceeded = false }));
            }
            catch (Exception)
            {
                sb = GetJobInformationXML(result, 1000);
                return(Json(new { data = sb.ToString(), maxLimitExceeded = true }));
            }
        }
 public JsonResult Approve(int id)
 {
     try
     {
         AbstractBusinessService.Create <EmployeeService>(UserInfo.UserKey).PublishBio(id);
         return(Json(new { Success = true, Message = "Your new bio is now live!" }));
     }
     catch (Exception ex)
     {
         return(Json(new { Success = false, Message = ex.Message }));
     }
 }
        public JsonResult RespondToTechMessage(int id, string msg, bool markProcessed)
        {
            OperationResult <bool> result;

            try
            {
                result = AbstractBusinessService.Create <MessagingService>(UserInfo.UserKey).SendMessage(id, msg, markProcessed);
            }
            catch (Exception ex)
            {
                return(Json(new { Success = false, Message = ex.Message }));
            }

            return(Json(new { Success = result.ResultData, Message = result.Message }));
        }
예제 #6
0
        public ViewResult DailyBudget(int?frid, FormCollection formcollection)
        {
            var franchiseId = frid ?? UserInfo.CurrentFranchise.FranchiseID;

            DateTime todaydate;

            if (!DateTime.TryParse(formcollection["txtDate"], out todaydate))
            {
                todaydate = DateTime.Today;
            }

            var m = AbstractBusinessService.Create <ReportingService>(UserInfo.UserKey).GetBudget(franchiseId, todaydate);

            return(View(m));
        }
        public JsonResult SaveStatus(int id, int statusId, int?reason)
        {
            int franchiseId;

            try
            {
                using (var db = GetAuditedContext())
                {
                    var job = db.tbl_Job.Single(j => j.JobID == id);
                    franchiseId = job.FranchiseID;

                    job.StatusID       = statusId;
                    job.CancelReasonID = reason.GetValueOrDefault();
                    db.SaveChanges();
                }
            }
            catch (Exception ex)
            {
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }

                return(Json(new { Success = false, msg = "Error saving status: " + ex.Message }));
            }

            AlertType?type = null;

            switch (statusId)
            {
            case 10:
                type = AlertType.CallRescheduled;
                break;

            case 12:
                type = AlertType.CustomerCancellation;
                break;
            }

            if (type.HasValue)
            {
                AbstractBusinessService.Create <AlertEngine>(UserInfo.UserKey).SendAlert(type.Value, franchiseId);
            }

            return(Json(new { Success = true, msg = "Success" }));
        }
예제 #8
0
        public JsonResult UpdateCustomerInformation(int franchiseId, tbl_Customer customer, tbl_Locations location, tbl_Contacts primaryContact, tbl_Contacts secondaryContact, bool isBillTo)
        {
            var result = AbstractBusinessService.Create <CustomerService>(UserInfo.UserKey).SaveCustomer(franchiseId, customer, location, primaryContact, secondaryContact, isBillTo);

            if (!result.Success)
            {
                return(Json(new { Success = false, Message = "Could not save customer information: " + result.Message }));
            }

            return(Json(new
            {
                Success = true,
                CustomerId = customer.CustomerID,
                LocationId = location.LocationID,
                PrimaryContactId = primaryContact.ContactID,
                SecondaryContactId = secondaryContact.ContactID
            }));
        }
        public ActionResult PrintInvoice(int id)
        {
            var contentType = "application/pdf";
            var result      = AbstractBusinessService.Create <InvoiceService>(UserInfo.UserKey).GetInvoicePdf(id, true);
            var fileName    = result.ResultData.Key;
            var data        = result.ResultData.Value;

            if (!result.Success)
            {
                contentType = "text/plain";
                fileName    = "error.txt";
                data        = Encoding.Unicode.GetBytes(result.Message);
            }

            return(new FileStreamResult(new MemoryStream(data), contentType)
            {
                FileDownloadName = fileName
            });
        }
        private FileResult GetBioInternal(int id, bool preview)
        {
            var contentType = "application/pdf";
            var result      = preview
                        ? AbstractBusinessService.Create <EmployeeService>(UserInfo.UserKey).PreviewBio(id)
                        : AbstractBusinessService.Create <EmployeeService>(UserInfo.UserKey).GetBio(id);
            var fileName = result.ResultData.Key;
            var data     = result.ResultData.Value;

            if (!result.Success)
            {
                contentType = "text/plain";
                fileName    = "error.txt";
                data        = Encoding.Unicode.GetBytes(result.Message);
            }

            return(new FileStreamResult(new MemoryStream(data), contentType)
            {
                FileDownloadName = fileName
            });
        }
        public JsonResult SendTechBio(int id)
        {
            using (var db = GetAuditedContext())
            {
                var qryResult = (from j in db.tbl_Job
                                 join c in db.tbl_Customer
                                 on j.CustomerID equals c.CustomerID
                                 where j.JobID == id
                                 select new { j.ServiceProID, c.EMail }).SingleOrDefault();

                if (qryResult == null || string.IsNullOrWhiteSpace(qryResult.EMail))
                {
                    return(Json(new { Success = false, Message = "Could not find email address for customer or no email is specified." }));
                }

                var result = AbstractBusinessService.Create <EmployeeService>(UserInfo.UserKey).SendTechnicianBio(qryResult.ServiceProID, qryResult.EMail);

                return(Json(result.Success
                            ? new { Success = true, Message = "Technician bio sent to customer." }
                            : new { Success = false, Message = result.Message }));
            }
        }
        public JsonResult getlivecheck(int franchiseId)
        {
            using (var db = new EightHundredEntities())
            {
                var result = AbstractBusinessService.Create <ReportingService>(UserInfo.UserKey).getOnlineCheck(franchiseId);
                int uid    = 0;
                var sb     = new StringBuilder();
                sb.Append("<rows>");
                foreach (var rec in result)
                {
                    sb.AppendFormat("<row id='{0}'>", uid++);
                    sb.AppendFormat(formatStr, rec.TestDescription);
                    sb.AppendFormat(formatStr, rec.PassFail);
                    sb.AppendFormat(dateFormat, rec.Comments);
                    sb.AppendFormat(formatStr, rec.resolution);
                    sb.Append("</row>");
                    uid++;
                }
                sb.Append("</rows>");

                return(Json(new { data = sb.ToString() }));
            }
        }
 private OperationResult <bool> SendInvoiceByEmail(EmailClass em, Guid userId, int jobId)
 {
     return(AbstractBusinessService.Create <InvoiceService>(userId).SendToCustomer(jobId, em.email));
 }
예제 #14
0
        public OperationResult <Payroll> ProcessPayrollForWeek(DateTime date, int payrollidNotUsed, string FranchiseId, bool persistToDataBase, Guid userKey)
        {
            // The date is not getting the end date for the week right now, but we can change that
            while (date.DayOfWeek != DayOfWeek.Saturday)
            {
                date = date.AddDays(1.0);
            }

            // NOTE doesn't make sense to put in a payrollidNotUsed if we have the week, so ignore the variable for now.  Kept there to maintain the parameter signature
            var result = new OperationResult <Payroll>();

            int      franchiseid = Convert.ToInt32(FranchiseId);
            DateTime startDate   = date.AddDays(-7);
            DateTime holddate    = date.AddDays(1);

            // Forget about what's in the database, just perform the function to generate a payroll for this week since we re-process it anyways
            // [Step 1] - Get everything we should need so we don't have to make anymore database calls
            List <tbl_Employee>     employeelist  = (from e in db.tbl_Employee where e.ActiveYN == true && e.FranchiseID == franchiseid select e).ToList <tbl_Employee>();
            List <tbl_HR_TimeSheet> timeSheetList = (from ts in db.tbl_HR_TimeSheet
                                                     join e in db.tbl_Employee on ts.EmployeeID equals e.EmployeeID
                                                     where
                                                     e.FranchiseID == franchiseid &&
                                                     ts.WeekEndingDateOn == date
                                                     select ts).ToList <tbl_HR_TimeSheet>();

            var reportingService = AbstractBusinessService.Create <ReportingService>(userKey);
            // Query Jobs within dates from our reporting layer
            KeyPerformanceIndicator kpiAllFranchise = reportingService.GetKeyPerformanceIndicators(
                franchiseid, startDate, holddate);
            List <Reporting.Job>          jobList          = kpiAllFranchise.AllJobs.ToList <Reporting.Job>();
            List <Reporting.JobTask>      taskList         = kpiAllFranchise.AllTasks.ToList();
            List <Reporting.PayrollSetup> payrollsetuplist = reportingService.GetPayrollSetupData(franchiseid).ToList <Reporting.PayrollSetup>();

            // Existing Payroll
            List <tbl_Payroll>        existingPayrollList = (from p in db.tbl_Payroll where p.PayrollDate == date select p).ToList <tbl_Payroll>();
            tbl_Payroll               existingPayroll     = (existingPayrollList.Count == 0) ? null : existingPayrollList[0];
            List <tbl_Job_Payroll>    jobPayrollListForExistingPayroll = new List <tbl_Job_Payroll>();
            List <tbl_PayrollDetails> payrollDetailsForExistingPayroll = new List <tbl_PayrollDetails>();

            if (existingPayroll != null)
            {
                jobPayrollListForExistingPayroll = (from j in db.tbl_Job_Payroll where j.PayrollID == existingPayroll.PayrollID select j).ToList <tbl_Job_Payroll>();
                payrollDetailsForExistingPayroll = (from pd in db.tbl_PayrollDetails where pd.PayrollID == existingPayroll.PayrollID select pd).ToList <tbl_PayrollDetails>();
            }

            // [Step 2] - Process a new Payroll
            Payroll payrollResult = new Payroll(date, franchiseid);

            ProcessEmployeesForWeek(payrollResult, employeelist, timeSheetList, jobList, taskList, payrollsetuplist);


            // [Step 3] - Now do the database stuff
            tbl_Payroll payrollToUse = null;

            if (existingPayroll != null)                // There IS an existing payroll
            {
                payrollToUse = existingPayroll;

                // blow away any existing JobPayrolls
                foreach (tbl_Job_Payroll existingJobPayroll in jobPayrollListForExistingPayroll)
                {
                    db.DeleteObject(existingJobPayroll);
                }

                // Blow away any existing PayrollDetails
                foreach (tbl_PayrollDetails existingPayrollDetail in payrollDetailsForExistingPayroll)
                {
                    db.DeleteObject(existingPayrollDetail);
                }
            }
            else
            {
                // Create a new payroll
                payrollToUse             = new tbl_Payroll();
                payrollToUse.LockDate    = null;
                payrollToUse.PayrollDate = date;
                payrollToUse.FranchiseID = franchiseid;
                db.tbl_Payroll.AddObject(payrollToUse);
            }

            // add all the payroll details
            foreach (PayrollDetail pd in payrollResult.PayrollDetails)
            {
                tbl_PayrollDetails newPayrollDetail = new tbl_PayrollDetails()
                {
                    PayrollID = payrollToUse.PayrollID,

                    EmployeeID = pd.EmployeeID,

                    SundayHours    = (float)pd.SundayHours,
                    MondayHours    = (float)pd.MondayHours,
                    TuesdayHours   = (float)pd.TuesdayHours,
                    WednesdayHours = (float)pd.WednesdayHours,
                    ThursdayHours  = (float)pd.ThursdayHours,
                    FridayHours    = (float)pd.FridayHours,
                    SaturdayHours  = (float)pd.SaturdayHours,

                    OTHours      = (float)pd.OTHours,
                    OTPay        = (float)pd.OTPay,
                    OTRate       = (float)pd.OTRate,
                    RegularHours = (float)pd.RegularHours,
                    RegularPay   = (float)pd.RegularPay,
                    RegularRate  = (float)pd.RegularRate,
                    WeeklySalary = (float)pd.WeeklySalary
                };
                db.tbl_PayrollDetails.AddObject(newPayrollDetail);

                // now add the job_payroll records
                foreach (JobPayroll jobPayroll in pd.JobPayrolls)
                {
                    tbl_Job_Payroll newJobPayroll = new tbl_Job_Payroll()
                    {
                        JobID          = jobPayroll.JobID
                        , ServiceProID = pd.EmployeeID   // TODO: Get rid of this after we add the foreign key to Payroll Detail
                        ,
                        JobSubTotal = (float)jobPayroll.JobSubTotal
                        ,
                        TotalCommissionPartsAndLabor = jobPayroll.TotalCommissionPartsAndLabor
                        ,
                        TotalCommissionSpifs = (float)jobPayroll.TotalCommissionSpifs
                        ,
                        PayrollID = payrollToUse.PayrollID
                    };
                    db.tbl_Job_Payroll.AddObject(newJobPayroll);
                }
            }

            db.SaveChanges();

            //[Step 4] - Communicate results
            payrollResult.PayrollID = payrollToUse.PayrollID;   // Doesn't make perfect sense but the UI needs this
            result.ResultData       = payrollResult;
            result.Success          = true;
            if (!result.Success)
            {
                result.Message = "Run Payroll Failed";
            }

            return(result);
        }
예제 #15
0
        public JsonResult SaveJob(tbl_Job job, string trackId)
        {
            var messages = new List <string>();
            var result   = new SaveResult();

            result.Success = false;

            try
            {
                job.ScheduleStart = GetJobStartDate(job.ServiceWindowID, job.ServiceDate.GetValueOrDefault());
                job.ScheduleEnd   = job.ScheduleStart.GetValueOrDefault().AddHours(job.ServiceLength.GetValueOrDefault());
                job.ServiceProID  = 127; // default to N/A

                if (job.CustomerID == 0)
                {
                    messages.Add("No customer selected for this job.");
                }

                if (job.LocationID == 0)
                {
                    messages.Add("No job location selected for this job.");
                }

                if (job.ServiceDate.GetValueOrDefault() == default(DateTime))
                {
                    messages.Add("Please select a Service Date for the job.");
                }

                if (job.ExpectedPayTypeID == 7 && !CheckCreditTermsInternal(job.FranchiseID, job.CustomerID))
                {
                    messages.Add("The customer has no credit terms set up with this franchise.  Please select a different payment type.");
                }

                if (job.ScheduleStart < DateTime.Now)
                {
                    messages.Add("The Service Date for this job occurs in the past.");
                }

                using (var jobContext = GetContext())
                {
                    if (job.AreaID != 0)
                    {
                        var dba = jobContext.tbl_Dispatch_DBA.Select(d => new { d.DBAID, d.DBAName, d.FranchiseID }).FirstOrDefault(d => d.DBAID == job.AreaID);
                        if (dba == null)
                        {
                            messages.Add("The specified DBA cannot be found.");
                        }
                        else
                        {
                            if (dba.FranchiseID != job.FranchiseID)
                            {
                                messages.Add(string.Format("The specified DBA ({0}) is not valid for the selected franchise.", dba.DBAName));
                            }
                        }
                    }

                    if (messages.Count != 0)
                    {
                        result.Messages = messages.ToArray();
                    }
                    else
                    {
                        var hasInfoRecord = jobContext.tbl_Customer_Info.Any(c => c.CustomerID == job.CustomerID);

                        if (!hasInfoRecord)
                        {
                            var newInfo = tbl_Customer_Info.Createtbl_Customer_Info(default(int), job.FranchiseID,
                                                                                    job.CustomerID, 2, 0, 2, 0, 0);
                            jobContext.AddTotbl_Customer_Info(newInfo);
                        }

                        job.CallTaker = UserInfo.UserKey.ToString();
                        jobContext.AddTotbl_Job(job);
                        jobContext.SaveChanges();

                        try
                        {
                            int trackNum;
                            if (int.TryParse(trackId, out trackNum))
                            {
                                var stat = db.StatisticTracks.SingleOrDefault(s => s.TrackId == trackNum);
                                if (stat != null)
                                {
                                    stat.Duration = DateTime.Now - stat.StartDate;
                                    stat.OptionId = 1;
                                    stat.Jobid    = job.JobID;
                                    db.SaveChanges();
                                }
                            }
                        }catch (Exception ex)
                        {
                            Logger.Log("Could not track call statistic", ex, LogLevel.Error);
                        }

                        result.Success  = true;
                        result.SavedId  = job.JobID;
                        result.Messages = new[] { "Job saved successfully." };
                    }
                }
            }
            catch (Exception ex)
            {
                while (ex.InnerException != null)
                {
                    ex = ex.InnerException;
                }

                result.Messages = new[] { ex.Message };
            }

            if (result.Success)
            {
                var type = job.JobPriorityID == 4
                            ? AlertType.RecallBooked
                            : (job.ServiceID == 10 ? AlertType.HvacSalesAlert : AlertType.AppointmentBooked);

                AbstractBusinessService.Create <AlertEngine>(UserInfo.UserKey).SendAlert(type, job.FranchiseID);
            }

            return(Json(result));
        }