public ActionResult CustomerListUpdate(int custid, string custName, string ComName, string Address, string State, string Postal, string City, string Email, string Jobs, string Calls, decimal CreditLimit, string Scheduled, string Type, string Visits, string MExp, string CCExp, string AgeRecords, string House, string WHeater, string AC, string GenNotes)
        {
            var custdata = (from p in db.tbl_Customer where p.CustomerID == custid select p).FirstOrDefault();

            custdata.CustomerName = custName;
            custdata.CompanyName  = ComName;
            custdata.EMail        = Email;

            var custLoc = (from l in db.tbl_Locations where l.BilltoCustomerID == custdata.CustomerID select l).FirstOrDefault();

            custLoc.Address    = Address;
            custLoc.State      = State;
            custLoc.City       = City;
            custLoc.PostalCode = Postal;

            var custinfo = (from l in db.tbl_Customer_Info where l.CustomerID == custdata.CustomerID select l).FirstOrDefault();

            custinfo.CreditLimit = CreditLimit;

            db.SaveChanges();

            var test = "";

            return(Json(test));
        }
Exemplo n.º 2
0
        private int CreateConfigIfNotExist(int franchiseID)
        {
            var context = new EightHundredEntities();

            if (context.tbl_HVAC_ConfigFranchise.Any(item => item.FranchiseID == franchiseID))
            {
                return(context.tbl_HVAC_ConfigFranchise.First(item => item.FranchiseID == franchiseID).ConfigID);
            }
            var config = new tbl_HVAC_ConfigsApp {
                ConfigName = "Config for Franchise " + franchiseID.ToString()
            };

            context.tbl_HVAC_ConfigsApp.AddObject(config);
            context.SaveChanges();
            var configFranchise = new tbl_HVAC_ConfigFranchise {
                ConfigID = config.ConfigID, FranchiseID = franchiseID
            };

            context.tbl_HVAC_ConfigFranchise.AddObject(configFranchise);

            SetQuestionsForNewConfig(context, config);

            context.SaveChanges();
            return(config.ConfigID);
        }
        public ActionResult GetXmlList(bool editing)
        {
            var userId = GetUserID();

            if (editing)
            {
                var jobId   = GetJobCode();
                var context = new EightHundredEntities();//new HVAC_appContext();//
                var xml     = "";
                if (context.tbl_HVAC_CustomersAnswers.Any(item => item.JobID == jobId && item.UserID == userId))
                {
                    var customerAnswer =
                        context.tbl_HVAC_CustomersAnswers.First(item => item.JobID == jobId && item.UserID == userId);
                    xml = SetAnswers(context, customerAnswer);
                }
                else
                {
                    var customerAnswer = new tbl_HVAC_CustomersAnswers {
                        JobID = jobId, UserID = userId
                    };
                    context.tbl_HVAC_CustomersAnswers.AddObject(customerAnswer);
                    context.SaveChanges();
                    xml = SetAnswers(context, customerAnswer);
                }
                context.SaveChanges();
                return(new XmlResult(xml));
            }
            return(Json(new { result = 0 }));
        }
Exemplo n.º 4
0
        public int CreateEmailDestination(int ownerAlertId, int communicationTypeId, string emailName, string emailAddress, string destinationAdditionalText)
        {
            if (db.tbl_OwnerAlertDestinations.Any(q => (q.OwnerAlertId == ownerAlertId) &&
                                                  (q.OwnerAlertDestinationName == emailName || q.OwnerAlertDestinationText == emailAddress)))
            {
                return(-1);
            }

            // Initialise the Owner Alert Destination
            tbl_OwnerAlertDestinations model = new tbl_OwnerAlertDestinations()
            {
                OwnerAlertId = ownerAlertId,
                OwnerAlertCommunicationTypeID       = communicationTypeId,
                OwnerAlertDestinationName           = emailName,
                OwnerAlertDestinationText           = emailAddress,
                OwnerAlertDestinationAdditionalText = destinationAdditionalText,
                OwneralertEnabledYN = true
            };

            try
            {
                // Insert the object into the database
                db.tbl_OwnerAlertDestinations.AddObject(model);
                db.SaveChanges();

                return(model.DestinationID);
            }
            catch (Exception ex)
            {
                var message = ex.Message;
                return(0);
            }
        }
        public ActionResult UpdatePart(PartAdjust partdata, int pbid)
        {
            using (var db = new EightHundredEntities())
            {
                var part = db.tbl_PB_Parts.Single(q => q.PartID == partdata.PartID);

                part.PartCost             = partdata.PartCost.Value;
                part.PartStdPrice         = partdata.PartStdPrice.Value;
                part.PartMemberPrice      = partdata.PartMemberPrice.Value;
                part.PartAddonStdPrice    = partdata.PartAddonStdPrice.Value;
                part.PartAddonMemberPrice = partdata.PartAddonMemberPrice.Value;

                var masterpart = db.tbl_PB_MasterParts.Single(q => q.MasterPartID == partdata.MasterPartID);

                masterpart.PartCode = partdata.PartCode;
                masterpart.PartName = partdata.PartDescription;

                db.SaveChanges();

                var taskdetail = db.tbl_PB_JobCodes_Details.Where(q => q.PartID == partdata.PartID).ToList();

                taskdetail.ForEach(q => q.PartCost             = partdata.PartCost.Value);
                taskdetail.ForEach(q => q.PartStdPrice         = partdata.PartStdPrice.Value);
                taskdetail.ForEach(q => q.PartMemberPrice      = partdata.PartMemberPrice.Value);
                taskdetail.ForEach(q => q.PartAddonStdPrice    = partdata.PartAddonStdPrice.Value);
                taskdetail.ForEach(q => q.PartAddonMemberPrice = partdata.PartAddonMemberPrice.Value);

                db.SaveChanges();

                //Recalcuate Task
                this.treeview.RecalculatePrices(0, pbid);

                return(Json("success"));
            }
        }
Exemplo n.º 6
0
        public OperationResult <PayrollSetup> SavePayrollSetup(int franchiseID, decimal overtimeStarts, int overtimeMethod, decimal overtimeMultiplier)
        {
            // Step 0: Business Validations
            StringBuilder sbExceptions = new StringBuilder();

            if (overtimeStarts < 0)
            {
                sbExceptions.AppendLine("Overtime Start cannot be negative: " + overtimeStarts.ToString());
            }
            if (overtimeMultiplier < 0)
            {
                sbExceptions.AppendLine("Overtime Multiplier cannot be negative: " + overtimeMultiplier.ToString());
            }
            if (sbExceptions.Length > 0)
            {
                throw new ArgumentException(sbExceptions.ToString());
            }

            // Step 1: inflate a POCO object with our parameters and do any validation
            PayrollSetup payrollSetupToReturn = new PayrollSetup()
            {
                FranchiseID      = franchiseID,
                OvertimeStarts   = overtimeStarts,
                OvertimeMethodID = overtimeMethod,
                OTMultiplier     = overtimeMultiplier
            };

            // Step 2: Database Persistance
            // If there is already a Payroll Setup for the franchise, do UPDATE
            var existingPayroll = (from tbl_HR_PayrollSetup payrollSetup in db.tbl_HR_PayrollSetup
                                   where payrollSetup.FranchiseID == franchiseID
                                   select payrollSetup).FirstOrDefault <tbl_HR_PayrollSetup>();

            if (existingPayroll != null)
            {
                // do an update
                existingPayroll.OvertimeStarts = (float)overtimeStarts;
                existingPayroll.OvertimeMethod = overtimeMethod;
                existingPayroll.OTMultiplier   = (float)overtimeMultiplier;
            }
            else
            {
                // Otherwise, do an INSERT
                tbl_HR_PayrollSetup newPayrollSetup = new tbl_HR_PayrollSetup()
                {
                    FranchiseID    = franchiseID,
                    OvertimeStarts = (float)overtimeStarts,
                    OvertimeMethod = overtimeMethod,
                    OTMultiplier   = (float)overtimeMultiplier
                };
                db.tbl_HR_PayrollSetup.AddObject(newPayrollSetup);
            }
            db.SaveChanges();

            return(new OperationResult <PayrollSetup>()
            {
                Success = true, ResultData = payrollSetupToReturn
            });
        }
        public ActionResult Create(Site site)
        {
            if (ModelState.IsValid)
            {
                db.Sites.AddObject(site);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(site));
        }
        public ActionResult SaveGuarantee()
        {
            var configId    = GetConfigID();
            var context     = new EightHundredEntities();
            var guaranteeId = int.Parse(Request.Form["Id"]);

            if (context.tbl_HVAC_ConfigsApp.First(item => item.ConfigID == configId).tbl_HVAC_ConfigGuaranteeTexts.Any(item => item.GuaranteeID == guaranteeId))
            {
                var code =
                    context.tbl_HVAC_ConfigsApp.First(item => item.ConfigID == configId).tbl_HVAC_ConfigGuaranteeTexts.First(
                        item => item.GuaranteeID == guaranteeId);
                code.GuaranteeText = Request.Form["GuaranteeText"];
            }
            else
            {
                context.tbl_HVAC_ConfigGuaranteeTexts.AddObject(new tbl_HVAC_ConfigGuaranteeTexts
                {
                    ConfigID      = configId,
                    GuaranteeID   = guaranteeId,
                    GuaranteeText = Request.Form["GuaranteeText"]
                });
            }
            context.SaveChanges();
            return(Json(new { result = true }));
        }
        public ActionResult ClearAnswers()
        {
            //TODO Verify security
            //var user = membershipService.GetUser(User.Identity.Name);
            //if (user.ProviderUserKey != null)
            //{
            //var userID = (Guid) user.ProviderUserKey;
            var userId     = GetUserID();
            var httpCookie = Request.Cookies["id_job"];

            if (httpCookie != null)
            {
                var jobID          = int.Parse(httpCookie.Value.Replace("\"", ""));
                var context        = new EightHundredEntities();
                var customerAnswer = context.tbl_HVAC_CustomersAnswers.First(item => item.JobID == jobID && item.UserID == userId);
                foreach (var source in customerAnswer.tbl_HVAC_Answers.ToArray())
                {
                    context.tbl_HVAC_Answers.DeleteObject(source);
                }
                context.tbl_HVAC_CustomersAnswers.DeleteObject(customerAnswer);
                context.SaveChanges();
            }
            //}
            return(Json(new { result = "success" }));
        }
        private void UpdatePaymentsInJob(EightHundredEntities context, int jobId)
        {
            var payments     = context.tbl_Payments.Where(item => item.JobID == jobId).ToList();
            var hvacPayments = GetValue(context, jobId);

            foreach (var payment in payments)
            {
                if (hvacPayments.payments.All(i => i.id != payment.PaymentID))
                {
                    context.tbl_Payments.DeleteObject(payment);
                }
            }
            foreach (var paymentItem in hvacPayments.payments)
            {
                if (payments.All(i => i.PaymentID != paymentItem.id))
                {
                    context.tbl_Payments.AddObject(new tbl_Payments
                    {
                        CheckNumber       = paymentItem.code, CreateDate = DateTime.Now,
                        DepositID         = 0, DepositStatus = false, DriversLicNUm = null, ErrorFlag = false,
                        ExceptionComments = null, FranchiseID = GetFranchiseID(), JobID = jobId,
                        PaymentAmount     = decimal.Parse(paymentItem.payment, NumberStyles.Any),
                        PaymentDate       = DateTime.Now, PaymentTypeID = paymentItem.typeId
                    });
                }
            }

            context.SaveChanges();

            //{"email":"","payments":[{"id":2,"type":"AmEx","payment":"$2,042.93","code":""}],"total_amount":12736.06}
        }
        public ActionResult DeleteTraining(int id)
        {
            var training = db.Trainings.First(t => t.TrainingId == id);

            db.Trainings.DeleteObject(training);
            db.SaveChanges();
            return(RedirectToAction("Training"));
        }
Exemplo n.º 12
0
        public ActionResult PayrollExceptionDataAdd(int partcode, string partdesc, int servicepro, int paytype, float rate, bool addon, DateTime dateexpires, bool active, string comments, int fid)
        {
            tbl_HR_PartsExceptions partException = new tbl_HR_PartsExceptions();

            partException.PartID       = partcode;
            partException.ServiceProID = servicepro;
            partException.PayType      = paytype;
            partException.Rate         = rate;
            partException.AddonYN      = addon;
            partException.DateExpires  = dateexpires;
            partException.ActiveYN     = active;
            partException.Comments     = comments;
            partException.FranchiseID  = fid;
            db.tbl_HR_PartsExceptions.AddObject(partException);
            db.SaveChanges();
            var test = "";

            return(Json(test));
        }
        private bool GenerateInvoice(EightHundredEntities context, tbl_Job job, Guid userId)
        {
            ClearJobTasks(context, job.JobID);
            UpdatePaymentsInJob(context, job.JobID);
            var jsonData =
                context.tbl_HVAC_Answers.Single(
                    item =>
                    item.tbl_HVAC_CustomersAnswers.JobID == job.JobID && item.tbl_HVAC_CustomersAnswers.UserID == userId &&
                    item.QuestionID == 35).Data;

            /*{"Jobs":
             * [            [
             * {"Count":"1","JobCode":"LE-HPAH136","Description":"asd","ResAccountCode":"41000","Price":7380,"TotalPrice":"$7,380.00",
             * "Parts":
             * [
             * {"PartCost":3690,"PartCode":"LE-HPAH136","PartName":"LE-3 Ton Air Handler Electric Heat - 10KW","PartStdPrice":7380,"PartID":503085,"Qty":1}
             * ],"id":1337316467855},
             * {"Count":"1","JobCode":"LE-HPAH136","Description":"asd3","ResAccountCode":"41000","Price":7380,"TotalPrice":"$7,380.00",
             * "Parts":
             * [
             * {"PartCost":3690,"PartCode":"LE-HPAH136","PartName":"LE-3 Ton Air Handler Electric Heat - 10KW","PartStdPrice":7380,"PartID":503085,"Qty":2,"TotalPrice":"$14,760.00"}
             * ],"id":1337316467857},
             * {"id":"ACC-CMF001","isAccessory":true,"Code":"ACC-CMF001","JobCode":"ACC-CMF001","Description":"1\" Charged Media Filter, 20 x 25","ResAccountCode":"41000","Count":1,"Price":895,"TotalPrice":"$895.00"},
             * {"id":"ACC-HUM001","isAccessory":true,"Code":"ACC-HUM001","JobCode":"ACC-HUM001","Description":"Humidifier","ResAccountCode":"41000","Count":3,"Price":595,"TotalPrice":"$1,785.00"}
             * ],
             * "MainSystem":{"Parts":[{"PartCost":3690,"PartCode":"LE-HPAH136","PartName":"LE-3 Ton Air Handler Electric Heat - 10KW","PartStdPrice":7380,"PartID":503085,"Qty":1}],"TotalPrice":7380,"id":"LE","AFUE":"80","SEER":"12","JobCodeId":0,"JobCode":"LE-HPAH136","ResAccountCode":"41000","Description":"SEER Rating 12, AFUE 80, LE-3 Ton Air Handler Electric Heat - 10KW","Count":1,"Price":7380},"TotalAmount":24820,"Tax":0,"GrandTotal":24820,"TaxRate":0} */
            //{"Jobs":[{"Count":"1","Description":"SEER Rating 16, AFUE 29, SE-2.5 Ton Gas Furnace Vertical","Price":12488,"TotalPrice":"$12,488.00","Parts":[{"PartCost":6244,"PartCode":"SE-HPGFV30","PartName":"SE-2.5 Ton Gas Furnace Vertical","PartStdPrice":12488,"PartID":503287,"Qty":1}],"id":1331745863188},{"id":"ACC-CMF001","isAccessory":true,"Code":"ACC-CMF001","Description":"1\" Charged Media Filter, 20 x 25","Count":1,"Price":895,"TotalPrice":"$895.00"},{"Count":"1","Description":"SEER Rating 16, AFUE 29, SE-2.5 Ton Gas Furnace Vertical","Price":12488,"TotalPrice":"$12,488.00","Parts":[{"PartCost":6244,"PartCode":"SE-HPGFV30","PartName":"SE-2.5 Ton Gas Furnace Vertical","PartStdPrice":12488,"PartID":503287,"Qty":1}],"id":1331745863190}],"MainSystem":{"Parts":[{"PartCost":6244,"PartCode":"SE-HPGFV30","PartName":"SE-2.5 Ton Gas Furnace Vertical","PartStdPrice":12488,"PartID":503287,"Qty":1}],"TotalPrice":12488,"id":"SE","AFUE":"29","SEER":"16","JobCodeId":0,"JobCode":"SE-HPGFV30","Description":"SEER Rating 16, AFUE 29, SE-2.5 Ton Gas Furnace Vertical","Count":1,"Price":12488},"TotalAmount":25871,"Tax":0,"GrandTotal":25871,"TaxRate":0}
            //var jsonData = "{\"Jobs\":[" +
            //            "{\"JobCode\":\"SE-HPGFV30\",\"Count\":\"1\",\"Description\":\"SEER Rating 16, AFUE 29, SE-2.5 Ton Gas Furnace Vertical\",\"Price\":12488,\"TotalPrice\":\"$12,488.00\",\"Parts\":[{\"PartCost\":6244,\"PartCode\":\"SE-HPGFV30\",\"PartName\":\"SE-2.5 Ton Gas Furnace Vertical\",\"PartStdPrice\":12488,\"PartID\":503287,\"Qty\":1}],\"id\":1331745863188}," +
            //            "{\"id\":\"ACC-CMF001\",\"isAccessory\":true,\"Code\":\"ACC-CMF001\",\"JobCode\":\"ACC-CMF001\",,\"Description\":\"1\\\" Charged Media Filter, 20 x 25\",\"Count\":1,\"Price\":895,\"TotalPrice\":\"$895.00\"}," +
            //            "{\"JobCode\":\"SE-HPGFV30\",\"Count\":\"1\",\"Description\":\"SEER Rating 16, AFUE 29, SE-2.5 Ton Gas Furnace Vertical\",\"Price\":12488,\"TotalPrice\":\"$12,488.00\",\"Parts\":[{\"PartCost\":6244,\"PartCode\":\"SE-HPGFV30\",\"PartName\":\"SE-2.5 Ton Gas Furnace Vertical\",\"PartStdPrice\":12488,\"PartID\":503287,\"Qty\":1}],\"id\":1331745863190}]," +
            //        "\"MainSystem\":{\"Parts\":[{\"PartCost\":6244,\"PartCode\":\"SE-HPGFV30\",\"PartName\":\"SE-2.5 Ton Gas Furnace Vertical\",\"PartStdPrice\":12488,\"PartID\":503287,\"Qty\":1}],\"TotalPrice\":12488,\"id\":\"SE\",\"AFUE\":\"29\",\"SEER\":\"16\",\"JobCodeId\":0,\"JobCode\":\"SE-HPGFV30\",\"Description\":\"SEER Rating 16, AFUE 29, SE-2.5 Ton Gas Furnace Vertical\",\"Count\":1,\"Price\":12488}," +
            //        "\"TotalAmount\":25871," +
            //        "\"Tax\":0," +
            //        "\"GrandTotal\":25871," +
            //        "\"TaxRate\":0}";
            //var jsonData33 = context.tbl_HVAC_Answers.Single(
            //        item =>
            //        item.tbl_HVAC_CustomersAnswers.JobID == jobId && item.tbl_HVAC_CustomersAnswers.UserID == userId &&
            //        item.QuestionID == 33).Data;

            var prMainJobs    = DeserialiseMainJobs(jsonData);
            var prAccessories = DeserialiseAccessoriesJobs(jsonData);

            SetJobTasks(context, prMainJobs, prAccessories);

            var pr = JSONHelper.Deserialise <PriceListModel <SystemInfoModelWithParts> >(jsonData);

            job.SubTotal   = decimal.Parse(pr.TotalAmount);
            job.TaxAmount  = decimal.Parse(pr.Tax);
            job.TotalSales = decimal.Parse(pr.GrandTotal);

            context.SaveChanges();
            return(true);
        }
        // Will add OR update a timesheet for the employee
        public static void SaveTimeSheet(int employeeID
                                         , DateTime datetimeWeekOf
                                         , decimal sundayHours
                                         , decimal mondayHours
                                         , decimal tuesdayHours
                                         , decimal wednesdayHours
                                         , decimal thursdayHours
                                         , decimal fridayHours
                                         , decimal saturdayHours
                                         )
        {
            // TODO: Validat the input

            EightHundredEntities db   = new EightHundredEntities();
            var existingTimeSheetList = (from timeSheet in db.tbl_HR_TimeSheet
                                         where timeSheet.EmployeeID == employeeID &&
                                         timeSheet.WeekEndingDateOn == datetimeWeekOf
                                         select timeSheet)
                                        .ToList();

            if (existingTimeSheetList.Count > 0)
            {
                // update the existing timesheet
                var existingTimeSheet = existingTimeSheetList.First();

                existingTimeSheet.SundayHours    = sundayHours;
                existingTimeSheet.MondayHours    = mondayHours;
                existingTimeSheet.TuesdayHours   = tuesdayHours;
                existingTimeSheet.WednesdayHours = wednesdayHours;
                existingTimeSheet.ThursdayHours  = thursdayHours;
                existingTimeSheet.FridayHours    = fridayHours;
                existingTimeSheet.SaturdayHours  = saturdayHours;
            }
            else
            {
                // save a new timesheet
                tbl_HR_TimeSheet newTimeSheet = new tbl_HR_TimeSheet()
                {
                    EmployeeID       = employeeID,
                    WeekEndingDateOn = datetimeWeekOf,
                    SundayHours      = sundayHours,
                    MondayHours      = mondayHours,
                    TuesdayHours     = tuesdayHours,
                    WednesdayHours   = wednesdayHours,
                    ThursdayHours    = thursdayHours,
                    FridayHours      = fridayHours,
                    SaturdayHours    = saturdayHours
                };

                db.tbl_HR_TimeSheet.AddObject(newTimeSheet);
            }

            db.SaveChanges();
        }
Exemplo n.º 15
0
        public ActionResult Create(TrainingType trainingtype, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    if (file.ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(file.FileName);
                        var path     = Path.Combine(Server.MapPath("~/Content/Uploads"), fileName);
                        file.SaveAs(path);
                        trainingtype.Icon = string.Format("~/Content/Uploads/{0}", fileName);
                    }
                }
                db.TrainingTypes.AddObject(trainingtype);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(trainingtype));
        }
Exemplo n.º 16
0
        public ActionResult SaveReferralCode(tbl_Referral[] datas)
        {
            int frid = datas[0].FranchiseID;

            for (int i = 0; i < datas.Count(); i++)
            {
                if (datas[i].referralID == 0)
                {
                    dbeight.tbl_Referral.AddObject(datas[i]);
                    dbeight.SaveChanges();
                }
                else
                {
                    int refid = datas[i].referralID;
                    var data  = dbeight.tbl_Referral.First(q => q.referralID == refid);

                    data.ReferralType = datas[i].ReferralType;
                    data.activeYN     = datas[i].activeYN;

                    dbeight.SaveChanges();
                }
            }

            var referral_list = (from t in dbeight.tbl_Referral
                                 where t.FranchiseID == frid
                                 select new
            {
                ReferralType = t.ReferralType,
                ActiveYN = t.activeYN,
                ReferralID = t.referralID
            }).ToList();

            return(Json(referral_list));
        }
        private void MarkInvoiced(int id, DateTime invoiceDate)
        {
            var job = new tbl_Job {
                JobID = id
            };

            using (var ctx = new EightHundredEntities(UserKey))
            {
                ctx.tbl_Job.Attach(job);
                job.InvoicedDate = invoiceDate;
                ctx.SaveChanges();
            }
        }
Exemplo n.º 18
0
        public ActionResult Save_DBA(int?franchiseID, string OwnersNotes, string CallAnsweringScript)
        {
            var test = "Already exists in the list..";

            try
            {
                var data = from R in db.tbl_Dispatch_OwnerNotes where R.FranchiseID == franchiseID select R;
                if (data.Count() == 0)
                {
                    // Add new.
                    tbl_Dispatch_OwnerNotes Dispatch_DBA = new tbl_Dispatch_OwnerNotes();
                    Dispatch_DBA.FranchiseID      = franchiseID.Value;
                    Dispatch_DBA.DispatchComments = OwnersNotes;
                    Dispatch_DBA.DispatchNotes    = OwnersNotes;
                    Dispatch_DBA.DispatchSpecials = CallAnsweringScript;
                    System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
                    Byte[] timestamp = encoding.GetBytes(DateTime.Now.ToString());
                    Dispatch_DBA.timestamp = timestamp;
                    db.tbl_Dispatch_OwnerNotes.AddObject(Dispatch_DBA);
                    db.SaveChanges();
                    test = "Save Data....";
                }
                else
                {
                    // Update existing.
                    var DispatchOwnerNote = (from p in db.tbl_Dispatch_OwnerNotes where p.FranchiseID == franchiseID select p).Single();
                    DispatchOwnerNote.DispatchNotes    = OwnersNotes;
                    DispatchOwnerNote.DispatchSpecials = CallAnsweringScript;
                    db.SaveChanges();
                    test = "Update Data....";
                }
            }
            catch (Exception e)
            {
                test = e.Message;
            }

            return(Json(test));
        }
        public ActionResult Create(Training training, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                if (file != null)
                {
                    if (file.ContentLength > 0)
                    {
                        var fileName = Path.GetFileName(file.FileName);
                        var path     = Path.Combine(Server.MapPath("~/Content/Uploads"), fileName);
                        file.SaveAs(path);
                        training.NavigateUrl = string.Format("~/Content/Uploads/{0}", fileName);
                    }
                }
                db.Trainings.AddObject(training);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.SiteId         = new SelectList(db.Sites, "SiteId", "SiteName", training.SiteId);
            ViewBag.TrainingTypeId = new SelectList(db.TrainingTypes, "TrainingTypeId", "TrainingTypeName", training.TrainingTypeId);
            return(View(training));
        }
        public ActionResult SaveGPSPoint()
        {
            var context     = new EightHundredEntities();
            var franchiseId = GetFranchiseID();
            var userId      = GetUserID();

            context.AddTotbl_GPS_Tracks(new tbl_GPS_Tracks
            {
                FranchiseId = franchiseId,
                Lat         = float.Parse(Request.Form["Lat"].Replace('.', ',')),
                Lng         = float.Parse(Request.Form["Lng"].Replace('.', ',')),
                UserId      = userId,
                TimeRecord  = DateTime.Parse(Request.Form["TimeRecord"])
            });
            context.SaveChanges();
            return(Json(new { result = true }));
        }
        private void ClearJobTasks(EightHundredEntities context, int jobId)
        {
            var listofMainTask   = context.tbl_Job_Tasks.Where(item => item.JobID == jobId).ToList();
            var listOfMainTaskId = listofMainTask.Select(i => i.JobTaskID);
            var listofPart       =
                context.tbl_Job_Task_Parts.Where(item => listOfMainTaskId.Contains(item.JobTaskID)).ToList();

            foreach (var jobTaskPart in listofPart)
            {
                context.tbl_Job_Task_Parts.DeleteObject(jobTaskPart);
            }
            foreach (var tblJobTask in listofMainTask)
            {
                context.tbl_Job_Tasks.DeleteObject(tblJobTask);
            }
            context.SaveChanges();
        }
        public ActionResult SetQuestions()
        {
            var context  = new EightHundredEntities();
            var configId = GetConfigID();

            foreach (var question in context.tbl_HVAC_ConfigQuestions.Where(item => item.ConfigID == configId))
            {
                context.tbl_HVAC_ConfigQuestions.DeleteObject(question);
            }
            foreach (var key in Request.Form.AllKeys)
            {
                context.tbl_HVAC_ConfigQuestions.AddObject(new tbl_HVAC_ConfigQuestions {
                    ConfigID = configId, OrderNum = int.Parse(key), QuestionID = int.Parse(Request.Form[key])
                });
            }
            context.SaveChanges();
            return(Json(new { result = true }));
        }
        public OperationResult <bool> SendMessage(int inResponseTo, string message, bool markProcessed)
        {
            var result = new OperationResult <bool>();

            using (var db = new EightHundredEntities(UserKey))
            {
                var om      = db.tbl_Dispatch_Message_History.Single(m => m.MessageHistoryID == inResponseTo);
                var techTab =
                    db.tbl_Franchise_Tablets.SingleOrDefault(
                        t => t.FranchiseID == om.FranchiseID && t.EmployeeID == om.TechID);

                if (techTab == null)
                {
                    result.Message = "No tablet could be found for the technician you replied to.";
                    return(result);
                }

                var fileName = techTab.TabletNumber.Split('-').Last() + "_tbl_DispatchMessage.xml";

                string xml;
                if (!GetMsgXml(om.FranchiseID, fileName, message, out xml))
                {
                    result.Message = xml;
                    return(result);
                }

                string msg;
                if (!SendMessageToTablet(db, xml, techTab.TabletNumber, fileName, out msg))
                {
                    result.Message = msg;
                    return(result);
                }

                if (markProcessed && !om.ProcessedYN)
                {
                    om.ProcessedYN = true;
                    db.SaveChanges();
                }
            }
            result.ResultData = true;
            return(result);
        }
Exemplo n.º 24
0
        //[AcceptVerbs(HttpVerbs.Post)]
        public ActionResult SaveMyCompanyInfo(CompanyInfoViewModel model, FormCollection collection)
        {
            //var franchiseID = Convert.ToInt32(collection["FranchiseID"]);
            var franchiseID = model.FranchiseID;

            var companyInfo = (from e in DB.tbl_Franchise
                               join o in DB.tbl_Franchise_Owner on e.OwnerID equals o.OwnerID
                               where e.FranchiseID == franchiseID
                               select e).FirstOrDefault();

            var ownerInfo = (from e in DB.tbl_Franchise_Owner where e.OwnerID == companyInfo.OwnerID select e).FirstOrDefault();

            ownerInfo.OwnerName        = model.OwnerName;
            companyInfo.LegalName      = model.LegalName;
            companyInfo.LegalAddress   = model.LegalAddress;
            companyInfo.LegalCity      = model.LegalCity;
            companyInfo.LegalState     = model.LegalState;
            companyInfo.LegalPostal    = model.LegalPostal;
            companyInfo.LegalCountryID = model.LegalCountryID;

            companyInfo.ShipName      = model.ShipName;
            companyInfo.ShipCompany   = model.ShipCompany;
            companyInfo.ShipAddress   = model.ShipAddress;
            companyInfo.ShipCity      = model.ShipCity;
            companyInfo.ShipState     = model.ShipState;
            companyInfo.ShipPostal    = model.ShipPostal;
            companyInfo.ShipCountryID = model.ShipCountryID;

            companyInfo.MailName      = model.MailName;
            companyInfo.MailCompany   = model.MailCompany;
            companyInfo.MailAddress   = model.MailAddress;
            companyInfo.MailCity      = model.MailCity;
            companyInfo.MailState     = model.MailState;
            companyInfo.MailPostal    = model.MailPostal;
            companyInfo.MailCountryID = model.MailCountryID;

            companyInfo.OfficeName      = model.OfficeName;
            companyInfo.OfficeCompany   = model.OfficeCompany;
            companyInfo.OfficeAddress   = model.OfficeAddress;
            companyInfo.OfficeCity      = model.OfficeCity;
            companyInfo.OfficeState     = model.OfficeState;
            companyInfo.OfficePostal    = model.OfficePostal;
            companyInfo.OfficeCountryID = model.OfficeCountryID;

            DB.SaveChanges();

            return(RedirectToAction("MyCompanyInfo"));
        }
        public ActionResult SaveHowWeAre()
        {
            var context  = new EightHundredEntities();
            var configId = GetConfigID();
            var list     =
                context.tbl_HVAC_ConfigWhoWeAreTexts.Where(item => item.ConfigID == configId).ToArray();

            if (list.Length > 0)
            {
                list[0].Text = Request.Form["GuaranteeText"];
            }
            else
            {
                var url = new tbl_HVAC_ConfigWhoWeAreTexts
                {
                    ConfigID = configId,
                    Text     = Request.Form["GuaranteeText"]
                };
                context.tbl_HVAC_ConfigWhoWeAreTexts.AddObject(url);
            }
            context.SaveChanges();
            return(Json(new { result = true }));
        }
        public ActionResult SaveReliableInstallations()
        {
            var context  = new EightHundredEntities();
            var configId = GetConfigID();
            var list     =
                context.tbl_HVAC_ConfigReliableInstallationsUrl.Where(item => item.ConfigID == configId).ToArray();

            if (list.Length > 0)
            {
                list[0].UrlText = Request.Form[Request.Form.AllKeys.First(i => i.StartsWith("cd"))];
            }
            else
            {
                var url = new tbl_HVAC_ConfigReliableInstallationsUrl
                {
                    ConfigID = configId,
                    UrlText  = Request.Form[Request.Form.AllKeys.First(i => i.StartsWith("cd"))]
                };
                context.tbl_HVAC_ConfigReliableInstallationsUrl.AddObject(url);
            }
            context.SaveChanges();
            return(Json(new { result = true }));
        }
        public void ApplyAdjustment(string franchiseid, string invoiceid, string amount, string accountid, string comments)
        {
            if (gbZeeAcctType == "QB")
            {
                Apply_Adjustment_ForQB(franchiseid, invoiceid, amount, accountid, comments);
            }
            else if (gbZeeAcctType == "PV")
            {
                //do nothing
            }
            else
            {
                //MSA system

                //adjust job payments
                try {
                    SBASuccess = false;
                    //SBAAppLoader.Main();

                    // set sbaObjects

                    // Initialize form
                    //adjust msa accounting
                    InitializeSBA_Adjustments(franchiseid, invoiceid, amount, accountid, comments);


                    if (SBASuccess == true)
                    {
                        tbl_Payments newpayment = new tbl_Payments();

                        newpayment.FranchiseID   = Convert.ToInt32(franchiseid);
                        newpayment.JobID         = Convert.ToInt32(invoiceid);
                        newpayment.PaymentAmount = Convert.ToDecimal(amount);
                        newpayment.PaymentDate   = DateTime.Now;
                        newpayment.DepositStatus = true;
                        newpayment.CreateDate    = DateTime.Now;
                        //posted
                        if (accountid == "65900 WriteOff")
                        {
                            newpayment.PaymentTypeID = -1;
                            //writeoff
                            newpayment.DepositID = -1;
                        }
                        else
                        {
                            newpayment.PaymentTypeID = -2;
                            //discount
                            newpayment.DepositID = -2;
                        }
                        DB.tbl_Payments.AddObject(newpayment);
                        DB.SaveChanges();

                        try {
                            int ijobid = Convert.ToInt32(invoiceid);

                            var Jobrec = (from J in DB.tbl_Job where J.JobID == ijobid select J).Single();
                            Jobrec.Balance = Jobrec.Balance - Convert.ToInt32(amount);
                            DB.SaveChanges();
                        } catch (Exception ex) {
                            ViewBag.lblmessage = "Unable to update job balance, but we will post the adjustment for you!  Error message is:" + ex.Message;
                        }
                    }
                } catch (Exception ex) {
                    ViewBag.lblmessage = "Adjustment was NOT posted since we are Unable to update job payments due to:" + ex.Message;
                }
            }
        }
 private bool WaitEstimateJob(EightHundredEntities contex, tbl_Job job)
 {
     job.StatusID = 13;
     contex.SaveChanges();
     return(true);
 }
 private bool CompleteJob(EightHundredEntities context, tbl_Job job)
 {
     job.StatusID = 6;
     context.SaveChanges();
     return(true);
 }
        private void SetJobTasks(EightHundredEntities context, IEnumerable <SystemInfoModelWithParts> prMainJobs, IEnumerable <AccessoryModel> prAccessories)
        {
            var frId        = GetFranchiseID();
            var priceBookId = GetPriceBookId(context, frId);
            var jobId       = GetJobCode();

            foreach (var jobtask in prMainJobs)
            {
                var qty = 1;
                //var jobDesription = context.View_HVAC_APP.First(i => i.JobCode == jobtask.JobCode).JobCodeDescription;
                var jobTask = new tbl_Job_Tasks
                {
                    JobID = jobId,
                    JobCodeDescription = jobtask.Description,
                    JobCode            = jobtask.JobCode,
                    AccountCode        = jobtask.ResAccountCode,
                    AddOnYN            = false,
                    AuthorizedYN       = true,
                    MemberYN           = false,
                    Cost      = jobtask.Parts.Sum(item => item.PartStdPrice * item.Qty),
                    Quantity  = qty,
                    JobCodeID = jobtask.JobCodeId,
                    Price     = jobtask.Parts.Sum(item => item.PartStdPrice * item.Qty), AdjustedPrice = 0, ErrorFlag = false, HomeGuardLink = 0, HomeGuardPrice = 0, LinePrice = 0, TabletTaskID = 0, UnitPrice = 0
                };
                context.tbl_Job_Tasks.AddObject(jobTask);
                context.SaveChanges();
                foreach (var listpart in jobtask.Parts.Where(listpart => listpart.Qty != 0))
                {
                    context.tbl_Job_Task_Parts.AddObject(new tbl_Job_Task_Parts
                    {
                        Cost     = listpart.PartCost,
                        PartCode = listpart.PartCode,
                        PartName = listpart.PartName,
                        Price    = listpart.PartStdPrice,
                        PartsID  = listpart.PartID,
                        Quantity = listpart.Qty,
                    });
                }
                context.SaveChanges();
            }

            var codes = prAccessories.Select(i => new KeyValuePair <string, AccessoryModel>(i.JobCode, i));

            var jobcodes = codes.Select(item => item.Key);
            //var list = context.View_HVAC_APP.Where(item => item.PriceBookID == priceBookId).Where(
            //    i => jobcodes.Contains(i.JobCode)).ToList();
            var listparts =
                context.View_HVAC_APP_Parts.Where(item => item.PriceBookID == priceBookId).Where(
                    i => jobcodes.Contains(i.JobCode)).ToList();

            foreach (var jobtask in codes.Select(i => i.Value))
            {
                var job_task = new tbl_Job_Tasks
                {
                    JobID = jobId,
                    JobCodeDescription = jobtask.Description,
                    JobCode            = jobtask.JobCode,
                    AccountCode        = jobtask.ResAccountCode,
                    AddOnYN            = false,
                    AuthorizedYN       = true,
                    MemberYN           = false,
                    Cost      = jobtask.Price,
                    Quantity  = jobtask.Count,
                    JobCodeID = jobtask.JobCodeId,
                    Price     = jobtask.Price, AdjustedPrice = 0, ErrorFlag = false, HomeGuardLink = 0, HomeGuardPrice = 0, LinePrice = 0, TabletTaskID = 0, UnitPrice = 0
                };
                context.tbl_Job_Tasks.AddObject(job_task);
                context.SaveChanges();
                foreach (var listpart in listparts.Where(i => i.JobCode == job_task.JobCode))
                {
                    context.tbl_Job_Task_Parts.AddObject(new tbl_Job_Task_Parts
                    {
                        Cost      = listpart.PartCost,
                        PartCode  = listpart.PartCode,
                        PartName  = listpart.PartName,
                        Price     = listpart.PartStdPrice,
                        JobTaskID = job_task.JobTaskID,
                        PartsID   = listpart.PartID,
                        Quantity  = listpart.Qty * job_task.Quantity,
                    });
                }
                context.SaveChanges();
            }
        }