Esempio n. 1
0
        public ActionResult InsertPayment(tbl_Payments paymentdata)
        {
            using (var ctx = new AuditedJobContext(UserInfo.UserKey, UserInfo.User.UserName, false))
            {
                try
                {
                    var job = (from j in ctx.tbl_Job
                               where j.JobID == paymentdata.JobID
                               select new
                    {
                        j.FranchiseID,
                        j.CustomerID
                    })
                              .First();

                    paymentdata.FranchiseID   = job.FranchiseID;
                    paymentdata.DepositStatus = false;
                    paymentdata.CreateDate    = DateTime.Now;
                    ctx.tbl_Payments.AddObject(paymentdata);
                    ctx.SaveChanges();

                    InvoiceFinancialDetail finance = RecalcJobData(paymentdata.JobID, job.CustomerID);

                    return(Json(finance));
                }
                catch (Exception)
                {
                }

                return(Json("fail"));
            }
        }
Esempio n. 2
0
        public ActionResult DeleteJobTask(int jobid, int taskid, int partid)
        {
            using (var ctx = new AuditedJobContext(UserInfo.UserKey, UserInfo.User.UserName, false))
            {
                using (var scope = new TransactionScope())
                {
                    var part = ctx.tbl_Job_Task_Parts.SingleOrDefault(q => q.JobTaskPartsID == partid);

                    if (part != null)
                    {
                        ctx.tbl_Job_Task_Parts.DeleteObject(part);
                        ctx.SaveChanges();
                    }

                    if (!ctx.tbl_Job_Task_Parts.Any(q => q.JobTaskID == taskid))
                    {
                        var task = ctx.tbl_Job_Tasks.Single(q => q.JobTaskID == taskid);
                        ctx.tbl_Job_Tasks.DeleteObject(task);
                        ctx.SaveChanges();
                    }

                    scope.Complete();
                }

                var customerid = ctx.tbl_Job.FirstOrDefault(q => q.JobID == jobid).CustomerID;
                InvoiceFinancialDetail finance = RecalcJobData(jobid, customerid);

                return(Json(finance));
            }
        }
Esempio n. 3
0
        public ActionResult SearchCode(int jobid, string searchstr, int pbid)
        {
            using (var ctx = new AuditedJobContext(UserInfo.UserKey, UserInfo.User.UserName, false))
            {
                var frid = (from j in ctx.tbl_Job
                            where j.JobID == jobid
                            select j.FranchiseID)
                           .Single();

                var codelist = (from b in ctx.tbl_PB_JobCodes
                                join c in ctx.tbl_PB_SubSection on b.SubSectionID equals c.SubsectionID
                                join d in ctx.tbl_PB_Section on c.SectionID equals d.SectionID
                                join e in ctx.tbl_PriceBook on d.PriceBookID equals e.PriceBookID
                                where e.FranchiseID == frid && e.ActiveBookYN && e.PriceBookID == pbid
                                orderby b.JobCode
                                select new
                {
                    b.JobCodeID,
                    Code = b.JobCode + " - " + b.JobCodeDescription
                });

                codelist = codelist.Where(q => q.Code.Contains(searchstr));

                return(Json(codelist.ToList()));
            }
        }
Esempio n. 4
0
        public ActionResult UpdatePayment(tbl_Payments paymentdata)
        {
            using (var ctx = new AuditedJobContext(UserInfo.UserKey, UserInfo.User.UserName, false))
            {
                try
                {
                    var payment = (from p in ctx.tbl_Payments where p.PaymentID == paymentdata.PaymentID select p).Single();

                    if (payment.DepositStatus == true)
                    {
                        return(Json("posted"));
                    }

                    payment.DepositStatus = false;
                    payment.PaymentAmount = paymentdata.PaymentAmount;
                    payment.PaymentDate   = paymentdata.PaymentDate;
                    payment.PaymentTypeID = paymentdata.PaymentTypeID;
                    payment.CheckNumber   = paymentdata.CheckNumber;
                    payment.DriversLicNUm = paymentdata.DriversLicNUm;
                    ctx.SaveChanges();

                    var CustomerID = ctx.tbl_Job.First(q => q.JobID == paymentdata.JobID).CustomerID;

                    InvoiceFinancialDetail finance = RecalcJobData(paymentdata.JobID, CustomerID);

                    return(Json(finance));
                }
                catch (Exception)
                {
                }

                return(Json("fail"));
            }
        }
Esempio n. 5
0
        public ActionResult SearchPart(int jobid, string searchstr, int pbid)
        {
            using (var ctx = new AuditedJobContext(UserInfo.UserKey, UserInfo.User.UserName, false))
            {
                var frid = (from j in ctx.tbl_Job
                            where j.JobID == jobid
                            select j.FranchiseID)
                           .Single();

                var partlist = (from s in ctx.tbl_PB_Parts
                                join t in ctx.tbl_PriceBook on s.PriceBookID equals t.PriceBookID
                                join m in ctx.tbl_PB_MasterParts on s.MasterPartID equals m.MasterPartID
                                where m.FranchiseID == frid && t.ActiveBookYN && t.PriceBookID == pbid
                                orderby m.PartCode
                                select new
                {
                    s.PartID,
                    Code = m.PartCode + " - " + m.PartName
                });

                partlist = partlist.Where(q => q.Code.Contains(searchstr));

                return(Json(partlist.ToList()));
            }
        }
Esempio n. 6
0
        public ActionResult AddPart(int partid, int jobid, int taskid)
        {
            var objmodcommon = new mod_common(UserInfo.UserKey);

            using (var ctx = new AuditedJobContext(UserInfo.UserKey, UserInfo.User.UserName, false))
            {
                try
                {
                    var part = (from p in ctx.tbl_PB_Parts
                                where p.PartID == partid
                                select p)
                               .Single();

                    var task = (from t in ctx.tbl_Job_Tasks
                                where t.JobTaskID == taskid
                                select t)
                               .Single();

                    var newpart = new tbl_Job_Task_Parts
                    {
                        JobTaskID = taskid,
                        PartCode  = objmodcommon.GetPartCode(partid).Trim(),
                        PartName  = objmodcommon.GetPartName(partid).Trim(),
                        PartsID   = part.PartID,
                        Quantity  = 1
                    };

                    if (task.MemberYN)
                    {
                        newpart.Price = task.AddOnYN ? part.PartAddonMemberPrice : part.PartMemberPrice;
                    }
                    else
                    {
                        newpart.Price = task.AddOnYN ? part.PartAddonStdPrice : part.PartStdPrice;
                    }

                    ctx.tbl_Job_Task_Parts.AddObject(newpart);
                    ctx.SaveChanges();

                    var customerid = ctx.tbl_Job.FirstOrDefault(q => q.JobID == jobid).CustomerID;

                    InvoiceFinancialDetail finance = RecalcJobData(jobid, customerid);

                    return(Json(finance));
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName,
                                                   validationError.ErrorMessage);
                        }
                    }
                }

                return(Json("fail"));
            }
        }
Esempio n. 7
0
        public InvoiceFinancialDetail RecalcJobData(int jobid, int customerid)
        {
            using (var ctx = new AuditedJobContext(UserInfo.UserKey, UserInfo.User.UserName, false))
            {
                try
                {
                    var total = (from j in ctx.tbl_Job
                                 join t in ctx.tbl_Job_Tasks on j.JobID equals t.JobID
                                 where j.JobID == jobid
                                 select new { t.Price, t.Quantity }).ToArray().Sum(x => x.Price * x.Quantity);

                    var totalpayment = (from p in ctx.tbl_Payments
                                        where p.JobID == jobid
                                        select p.PaymentAmount).Sum() ?? 0;

                    var objjob = (from j in ctx.tbl_Job
                                  where j.JobID == jobid
                                  select j)
                                 .FirstOrDefault();

                    objjob.SubTotal   = total;
                    objjob.TotalSales = total + objjob.TaxAmount;
                    objjob.Balance    = objjob.TotalSales - totalpayment;

                    ctx.SaveChanges();

                    var finance = new InvoiceFinancialDetail()
                    {
                        SubTotal  = String.Format("{0:C}", objjob.SubTotal).Replace("$", ""),
                        Total     = String.Format("{0:C}", objjob.TotalSales).Replace("$", ""),
                        Balance   = String.Format("{0:C}", objjob.Balance).Replace("$", ""),
                        TotalPaid = String.Format("{0:C}", totalpayment).Replace("$", "")
                    };

                    var customerbalance = (from h in ctx.tbl_Job
                                           where h.CustomerID == customerid
                                           group h by h.CustomerID into g
                                           select new
                    {
                        TotalBalance = g.Sum(x => x.Balance)
                    })
                                          .Single();

                    finance.CustomerBalance = String.Format("{0:C}", customerbalance.TotalBalance).Replace("$", "");

                    return(finance);
                }
                catch (Exception)
                {
                }

                return(null);
            }
        }
Esempio n. 8
0
        public ActionResult UpdateJobTask(int jobid, tbl_Job_Tasks taskdata, tbl_Job_Task_Parts partdata)
        {
            using (var ctx = new AuditedJobContext(UserInfo.UserKey, UserInfo.User.UserName, false))
            {
                try
                {
                    var task = ctx.tbl_Job_Tasks.FirstOrDefault(t => t.JobID == jobid && t.JobTaskID == taskdata.JobTaskID);

                    if (task != null)
                    {
                        task.MemberYN           = taskdata.MemberYN;
                        task.AddOnYN            = taskdata.AddOnYN;
                        task.Quantity           = taskdata.Quantity;
                        task.Price              = taskdata.Price;
                        task.JobCodeDescription = taskdata.JobCodeDescription;
                        task.JobCode            = taskdata.JobCode;
                        task.JobCodeID          = taskdata.JobCodeID;
                    }

                    var part = ctx.tbl_Job_Task_Parts.FirstOrDefault(q => q.JobTaskPartsID == partdata.JobTaskPartsID && q.JobTaskID == taskdata.JobTaskID);

                    if (part != null)
                    {
                        part.PartsID  = partdata.PartsID;
                        part.Quantity = partdata.Quantity;
                        part.Price    = partdata.Price;
                        part.PartCode = partdata.PartCode;
                        part.PartName = partdata.PartName;
                    }

                    ctx.SaveChanges();

                    var customerid = ctx.tbl_Job.FirstOrDefault(q => q.JobID == jobid).CustomerID;
                    InvoiceFinancialDetail finance = RecalcJobData(jobid, customerid);

                    return(Json(finance));
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName,
                                                   validationError.ErrorMessage);
                        }
                    }
                }

                return(Json("fail"));
            }
        }
Esempio n. 9
0
        public ActionResult UpdateAccountCode(int taskid, string accode)
        {
            using (var ctx = new AuditedJobContext(UserInfo.UserKey, UserInfo.User.UserName, false))
            {
                var task = ctx.tbl_Job_Tasks.Single(q => q.JobTaskID == taskid);

                task.AccountCode = accode;

                ctx.SaveChanges();

                return(Json("success"));
            }
        }
        public ActionResult GenerateInvoice()
        {
            var jobId   = GetJobCode();
            var userId  = GetUserID();
            var context = new AuditedJobContext(userId, "From HVAC app user", false);

            var job = context.tbl_Job.First(item => item.JobID == jobId);

            GenerateInvoice(context, job, userId);

            context.SaveChanges();
            return(Json(new { result = true }, JsonRequestBehavior.AllowGet));
        }
Esempio n. 11
0
        public ActionResult GetJobCodeData(int jobcodeid)
        {
            using (var ctx = new AuditedJobContext(UserInfo.UserKey, UserInfo.User.UserName, false))
            {
                var codedata = ctx.tbl_PB_JobCodes.Select(b => new
                {
                    b.JobCodeID,
                    b.JobCode,
                    b.JobCodeDescription,
                    b.JobAddonMemberPrice
                })
                               .FirstOrDefault(b => b.JobCodeID == jobcodeid);

                return(Json(codedata));
            }
        }
Esempio n. 12
0
        public ActionResult JobTaskList(int jobid, int?actype)
        {
            using (var ctx = new AuditedJobContext(UserInfo.UserKey, UserInfo.User.UserName, false))
            {
                var jobtaskdata = (from jobtask in ctx.tbl_Job_Tasks
                                   join jobtaskparts in ctx.tbl_Job_Task_Parts on jobtask.JobTaskID equals jobtaskparts.JobTaskID into parts
                                   from p in parts.DefaultIfEmpty()
                                   where jobtask.JobID == jobid
                                   select new
                {
                    JobTaskPartsID = ((int?)p.JobTaskPartsID) ?? 0,
                    jobtask.AccountCode,
                    jobtask.JobTaskID,
                    jobtask.Quantity,
                    jobtask.JobCode,
                    jobtask.JobCodeDescription,
                    jobtask.Price,
                    p.PartName,
                    PartQuantity = ((decimal?)p.Quantity) ?? 0,
                    PartPrice = ((decimal?)p.Price) ?? 0,
                    p.PartCode,
                    jobtask.AddOnYN,
                    jobtask.MemberYN
                }).ToList();

                var jobtasklist = (from t in jobtaskdata
                                   select new
                {
                    t.JobTaskPartsID,
                    t.JobTaskID,
                    t.Quantity,
                    t.AddOnYN,
                    t.MemberYN,
                    t.PartQuantity,
                    PartPrice = string.Format("{0:C}", t.PartPrice),
                    Code = t.JobCode,
                    TaskDesc = t.JobCodeDescription,
                    Unit = string.Format("{0:C}", t.Price),
                    Line = string.Format("{0:C}", t.Price * t.Quantity),
                    Part = (t.AddOnYN) ? t.PartCode ?? "" : t.PartCode,
                    PartDesc = (t.AccountCode == "0" || t.AccountCode == "" || t.AccountCode == "00000") ? t.PartName + " NoAcct!" : t.PartName ?? "",
                    t.AccountCode
                });

                return(Json(jobtasklist));
            }
        }
Esempio n. 13
0
        public ActionResult GetJobPartData(int partid)
        {
            using (var ctx = new AuditedJobContext(UserInfo.UserKey, UserInfo.User.UserName, false))
            {
                var partdata = (from s in ctx.tbl_PB_Parts
                                join m in ctx.tbl_PB_MasterParts on s.MasterPartID equals m.MasterPartID
                                where s.PartID == partid
                                orderby m.PartCode
                                select new
                {
                    m.PartCode,
                    m.PartName,
                    s.PartAddonMemberPrice
                })
                               .FirstOrDefault();

                return(Json(partdata));
            }
        }
        public ActionResult EstimateJob()
        {
            try
            {
                var jobId   = GetJobCode();
                var userId  = GetUserID();
                var context = new AuditedJobContext(userId, userId.ToString(), false);

                var job = context.tbl_Job.First(item => item.JobID == jobId);

                GenerateInvoice(context, job, userId);
                WaitEstimateJob(context, job);

                context.SaveChanges();
                return(Json(new { result = true }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { result = false, message = ex.Message + "\n" + (ex.InnerException != null ? ex.InnerException.Message : "") }, JsonRequestBehavior.AllowGet));
            }
        }
Esempio n. 15
0
        public ActionResult DeletePayment(tbl_Payments paymentdata)
        {
            using (var ctx = new AuditedJobContext(UserInfo.UserKey, UserInfo.User.UserName, false))
            {
                var payment = (from p in ctx.tbl_Payments where p.PaymentID == paymentdata.PaymentID select p).Single();

                if (payment.DepositStatus == true)
                {
                    return(Json("posted"));
                }

                ctx.tbl_Payments.DeleteObject(payment);
                ctx.SaveChanges();

                var CustomerID = ctx.tbl_Job.First(q => q.JobID == paymentdata.JobID).CustomerID;

                InvoiceFinancialDetail finance = RecalcJobData(paymentdata.JobID, CustomerID);

                return(Json(finance));
            }
        }
Esempio n. 16
0
 public JsonResult UpdateSchedule(int scheduleId, string monStartTime, string monEndTime, string tueStartTime, string tueEndTime, string wedStartTime, string wedEndTime,
                                  string thruStartTime, string thruEndTime, string friStartTime, string friEndTime, string satStartTime, string satEndTime, string sunStartTime, string sunEndTime)
 {
     using (var context = new AuditedJobContext(UserInfo.UserKey, UserInfo.User.UserName, false))
     {
         var Schedule = (from p in context.tbl_Dispatch_Schedule where p.ScheduleID == scheduleId select p).Single();
         if (Schedule != null)
         {
             if (!string.IsNullOrWhiteSpace(sunStartTime))
             {
                 Schedule.SunStart = sunStartTime;
             }
             else
             {
                 Schedule.SunStart = "Off";
             }
             if (!string.IsNullOrWhiteSpace(sunEndTime))
             {
                 Schedule.SunEnd = sunEndTime;
             }
             else
             {
                 Schedule.SunEnd = "Off";
             }
             if (!string.IsNullOrWhiteSpace(monStartTime))
             {
                 Schedule.MonStart = monStartTime;
             }
             else
             {
                 Schedule.MonStart = "Off";
             }
             if (!string.IsNullOrWhiteSpace(monEndTime))
             {
                 Schedule.MonEnd = monEndTime;
             }
             else
             {
                 Schedule.MonEnd = "Off";
             }
             if (!string.IsNullOrWhiteSpace(tueStartTime))
             {
                 Schedule.TueStart = tueStartTime;
             }
             else
             {
                 Schedule.TueStart = "Off";
             }
             if (!string.IsNullOrWhiteSpace(tueEndTime))
             {
                 Schedule.TueEnd = tueEndTime;
             }
             else
             {
                 Schedule.TueEnd = "Off";
             }
             if (!string.IsNullOrWhiteSpace(wedStartTime))
             {
                 Schedule.WedStart = wedStartTime;
             }
             else
             {
                 Schedule.WedStart = "Off";
             }
             if (!string.IsNullOrWhiteSpace(wedEndTime))
             {
                 Schedule.WedEnd = wedEndTime;
             }
             else
             {
                 Schedule.WedEnd = "Off";
             }
             if (!string.IsNullOrWhiteSpace(thruStartTime))
             {
                 Schedule.ThuStart = thruStartTime;
             }
             else
             {
                 Schedule.ThuStart = "Off";
             }
             if (!string.IsNullOrWhiteSpace(thruEndTime))
             {
                 Schedule.ThuEnd = thruEndTime;
             }
             else
             {
                 Schedule.ThuEnd = "Off";
             }
             if (!string.IsNullOrWhiteSpace(friStartTime))
             {
                 Schedule.FriStart = friStartTime;
             }
             else
             {
                 Schedule.FriStart = "Off";
             }
             if (!string.IsNullOrWhiteSpace(friEndTime))
             {
                 Schedule.FriEnd = friEndTime;
             }
             else
             {
                 Schedule.FriEnd = "Off";
             }
             if (!string.IsNullOrWhiteSpace(satStartTime))
             {
                 Schedule.SatStart = satStartTime;
             }
             else
             {
                 Schedule.SatStart = "Off";
             }
             if (!string.IsNullOrWhiteSpace(satEndTime))
             {
                 Schedule.SatEnd = satEndTime;
             }
             else
             {
                 Schedule.SatEnd = "Off";
             }
             context.SaveChanges();
             return(Json(new
             {
                 Message = "Record Updated Successfully.",
                 ResultData = "",
                 Success = true
             }));
         }
         else
         {
             return(Json(new
             {
                 Message = string.Format("There is no schedule exists for ID: {0}.", scheduleId),
                 ResultData = "",
                 Success = false
             }));
         }
     }
 }
Esempio n. 17
0
        public ActionResult InsertMultiplePayment(tbl_Payments[] paymentdata, DateTime PaymentDate)
        {
            using (var ctx = new AuditedJobContext(UserInfo.UserKey, UserInfo.User.UserName, false))
            {
                var     overpayments    = 0;
                var     underpayments   = 0;
                var     finance         = new InvoiceFinancialDetail();
                decimal amountRemaining = 0;

                paymentdata = paymentdata.OrderBy(x => x.PaymentDate).ToArray();

                for (var i = 0; i < paymentdata.Length; i++)
                {
                    var jobId = paymentdata[i].JobID;

                    if (overpayments > 0)
                    {
                        paymentdata[i].PaymentAmount = amountRemaining;
                    }

                    var paymentAmount = Convert.ToDecimal(paymentdata[i].PaymentAmount);

                    var job = (from j in ctx.tbl_Job
                               where j.JobID == jobId
                               select new
                    {
                        j.CustomerID,
                        j.Balance
                    })
                              .First();

                    var currentBalance = job.Balance;

                    if (paymentAmount > currentBalance)
                    {
                        paymentdata[i].PaymentAmount = currentBalance;

                        amountRemaining = paymentAmount - currentBalance;
                        if (i == paymentdata.Length - 1)
                        {
                            paymentdata[i].PaymentAmount += amountRemaining;
                        }

                        overpayments++;
                    }

                    if (paymentAmount < currentBalance)
                    {
                        underpayments++;

                        paymentdata[i].PaymentAmount = amountRemaining == 0 ? 0 : amountRemaining;

                        if (i == paymentdata.Length - 1)
                        {
                            paymentdata[i].PaymentAmount = amountRemaining == 0 ? 0 : amountRemaining;
                        }
                    }

                    if (paymentAmount == currentBalance)
                    {
                        paymentdata[i].PaymentAmount = paymentAmount;
                    }

                    if (underpayments > 1)
                    {
                        paymentdata[i].PaymentAmount = 0;
                    }

                    paymentdata[i].PaymentDate = PaymentDate;
                    paymentdata[i].CreateDate  = DateTime.Now;
                    ctx.tbl_Payments.AddObject(paymentdata[i]);
                    ctx.SaveChanges();
                    finance = RecalcMultipleJobData(paymentdata[i].JobID, job.CustomerID);
                    i++;
                }

                return(Json(finance));
            }
        }
Esempio n. 18
0
        public ActionResult AddCode(int jobcodeid, int jobid)
        {
            var objmodcommon = new mod_common(UserInfo.UserKey);

            using (var ctx = new AuditedJobContext(UserInfo.UserKey, UserInfo.User.UserName, false))
            {
                try
                {
                    //task
                    var task = (from jc in ctx.tbl_PB_JobCodes
                                where jc.JobCodeID == jobcodeid
                                select new
                    {
                        jc.JobAddonMemberPrice,
                        jc.JobAddonStdPrice,
                        jc.JobCost,
                        jc.JobCode,
                        jc.JobCodeID,
                        jc.JobCodeDescription
                    }).Single();

                    var job = (from j in ctx.tbl_Job
                               where j.JobID == jobid
                               select new
                    {
                        j.CustomerID,
                        j.BusinessTypeID
                    }).Single();

                    var newtask = new tbl_Job_Tasks()
                    {
                        Cost               = task.JobCost,
                        JobCodeID          = task.JobCodeID,
                        JobCode            = task.JobCode,
                        JobCodeDescription = task.JobCodeDescription,
                        JobID              = jobid,
                        AuthorizedYN       = true,
                        AddOnYN            = true,
                        Quantity           = 1
                    };

                    if (ctx.tbl_Customer_Members.Any(q => q.CustomerID == job.CustomerID))
                    {
                        newtask.Price = task.JobAddonMemberPrice;
                    }
                    else
                    {
                        newtask.Price = task.JobAddonStdPrice;
                    }

                    newtask.AccountCode = objmodcommon.Get_Account_Code(task.JobCodeID, job.BusinessTypeID);

                    ctx.tbl_Job_Tasks.AddObject(newtask);
                    ctx.SaveChanges();

                    //part
                    var partlist = (from p in ctx.tbl_PB_JobCodes_Details
                                    where p.JobCodeID == newtask.JobCodeID
                                    select p);

                    bool addflag = false;
                    foreach (var part in partlist)
                    {
                        var newpart = new tbl_Job_Task_Parts()
                        {
                            JobTaskID = newtask.JobTaskID,
                            PartCode  = objmodcommon.GetPartCode(part.PartID).Trim(),
                            PartName  = objmodcommon.GetPartName(part.PartID),
                            PartsID   = part.PartID,
                            Quantity  = newtask.Quantity * part.Qty
                        };

                        if (newtask.AddOnYN)
                        {
                            newpart.Price = newtask.MemberYN ? part.PartAddonMemberPrice : part.PartAddonStdPrice;
                        }
                        else
                        {
                            newpart.Price = newtask.MemberYN ? part.PartMemberPrice : part.PartStdPrice;
                        }

                        ctx.tbl_Job_Task_Parts.AddObject(newpart);

                        addflag = true;
                    }

                    if (addflag)
                    {
                        ctx.SaveChanges();
                    }

                    InvoiceFinancialDetail finance = RecalcJobData(jobid, job.CustomerID);

                    return(Json(finance));
                }
                catch (DbEntityValidationException dbEx)
                {
                    foreach (var validationErrors in dbEx.EntityValidationErrors)
                    {
                        foreach (var validationError in validationErrors.ValidationErrors)
                        {
                            Trace.TraceInformation("Property: {0} Error: {1}", validationError.PropertyName,
                                                   validationError.ErrorMessage);
                        }
                    }
                }

                return(Json("fail"));
            }
        }
        public JsonResult CustomerHistoryList(string customerID)
        {
            using (var context = new AuditedJobContext(UserInfo.UserKey, UserInfo.User.UserName, false))
            {
                var cid = int.Parse(customerID);;

                var customerHistoryData = (from log in context.AuditLogs
                                           join ac in context.Audit_Customer on log.AuditID equals ac.AuditID
                                           where log.EntityID == customerID && log.EntityType == "tbl_Customer"
                                           select new
                {
                    log.UserKey,
                    log.AuditDate,
                    log.Type,
                    log.EntityType,
                    ac.Attribute,
                    ac.NewValue,
                    ac.OldValue
                }).Concat(
                    from log in context.AuditLogs
                    join ac in context.Audit_Contact on log.AuditID equals ac.AuditID
                    join c in context.tbl_Contacts on log.EntityID equals SqlFunctions.StringConvert((double)c.ContactID).Trim()
                    where c.CustomerID == cid && log.EntityType == "tbl_Contacts"
                    select new
                {
                    log.UserKey,
                    log.AuditDate,
                    log.Type,
                    log.EntityType,
                    ac.Attribute,
                    ac.NewValue,
                    ac.OldValue
                }).Concat(
                    from log in context.AuditLogs
                    join al in context.Audit_Location on log.AuditID equals al.AuditID
                    join l in context.tbl_Locations on log.EntityID equals SqlFunctions.StringConvert((double)l.LocationID).Trim()
                    where (l.ActvieCustomerID == cid || l.BilltoCustomerID == cid) && log.EntityType == "tbl_Locations"
                    select new
                {
                    log.UserKey,
                    log.AuditDate,
                    log.Type,
                    log.EntityType,
                    al.Attribute,
                    al.NewValue,
                    al.OldValue
                }).Concat(
                    from log in context.AuditLogs
                    join am in context.Audit_Membership on log.AuditID equals am.AuditID
                    join cm in context.tbl_Customer_Members on log.EntityID equals SqlFunctions.StringConvert((double)cm.MemberID).Trim()
                    where cm.CustomerID == cid && log.EntityType == "tbl_Customer_Members"
                    select new
                {
                    log.UserKey,
                    log.AuditDate,
                    log.Type,
                    log.EntityType,
                    am.Attribute,
                    am.NewValue,
                    am.OldValue
                }).OrderBy(o => o.AuditDate).ToList();

                var customerHistoryList = new List <CustomerHistoryInfo>();

                for (var i = 0; i < customerHistoryData.Count; i++)
                {
                    var from = customerHistoryData[i].OldValue;
                    var to   = customerHistoryData[i].NewValue;

                    var changedby = "";
                    try
                    {
                        changedby = Membership.GetUser(new Guid(customerHistoryData[i].UserKey)).UserName;
                    }
                    catch (Exception)
                    {
                        changedby = "N/A";
                    }

                    customerHistoryList.Add(new CustomerHistoryInfo
                    {
                        FieldName  = customerHistoryData[i].Attribute,
                        TableName  = customerHistoryData[i].EntityType,
                        ChangeType = customerHistoryData[i].Type,
                        Date       = customerHistoryData[i].AuditDate.ToShortDateString(),
                        Time       = customerHistoryData[i].AuditDate.ToShortTimeString(),
                        isTablet   = "No",
                        ChangedBy  = changedby,
                        From       = from,
                        To         = to
                    });
                }

                return(Json(customerHistoryList));
            }
        }