public ActionResult TextMessage(int?id)
        {
            string sData = "Pickup Details";

            Models.JobServicePickup svcpu;
            Models.JobServices      svc = db.JobServices.Find(id);
            if (svc.JobServicePickups.FirstOrDefault() == null)
            {
                sData += "\nPickup: undefined ";
            }
            else
            {
                Decimal quote = (svc.QuotedAmt == null ? 0 : (decimal)svc.QuotedAmt);

                svcpu  = svc.JobServicePickups.FirstOrDefault();
                sData += "\nDate:" + ((DateTime)svc.DtStart).ToString("dd MMM yyyy (ddd)");
                sData += "\nTime&Location:" + svcpu.JsTime + " " + svcpu.JsLocation;
                sData += "\nGuest:" + svcpu.ClientName + " #" + svcpu.ClientContact;
                sData += "\nDriver:" + svcpu.ProviderName + " #" + svcpu.ProviderContact;
                sData += "\nUnit:" + svc.SupplierItem.Description + " " + svc.SupplierItem.Remarks;
                sData += "\nRate:P" + quote.ToString("##,###.00");
                sData += "\nParticulars:" + svc.Particulars;
                sData += "\n  " + svc.Remarks;
                sData += "\n\nHave a safe trip,\nAJ88 Car Rental";
            }

            ViewBag.StrData = sData;
            return(View());
        }
        public ActionResult InitServicePickup(int?id)
        {
            Models.JobServicePickup svcpu;

            Models.JobServices svc = db.JobServices.Find(id);
            if (svc.JobServicePickups.FirstOrDefault() == null)
            {
                svcpu = new JobServicePickup();
                svcpu.JobServicesId   = svc.Id;
                svcpu.JsDate          = svc.JobMain.JobDate;
                svcpu.JsTime          = svc.JobMain.JobDate.ToString("hh:mm:00");
                svcpu.ClientName      = svc.JobMain.Description;
                svcpu.ClientContact   = svc.JobMain.CustContactNumber;
                svcpu.ProviderName    = svc.SupplierItem.InCharge;
                svcpu.ProviderContact = svc.SupplierItem.Tel1
                                        + (svc.SupplierItem.Tel2 == null ? "" : "/" + svc.SupplierItem.Tel2)
                                        + (svc.SupplierItem.Tel3 == null ? "" : "/" + svc.SupplierItem.Tel3);

                db.JobServicePickups.Add(svcpu);
                db.SaveChanges();
            }
            else
            {
                svcpu = svc.JobServicePickups.FirstOrDefault();
            }

            return(RedirectToAction("ServicePickup", new { id = svcpu.Id }));
        }
        public ActionResult ResetServicePickup(int?id)
        {
            Models.JobServicePickup svcpu = db.JobServicePickups.Find(id);
            Models.JobServices      svc   = db.JobServices.Find(svcpu.JobServicesId);

            svcpu.ClientName = (svcpu.ClientName == null || svcpu.ClientName.Trim() == ""?svc.JobMain.Customer.Name: svcpu.ClientName);

            string sClientContact =
                (svc.JobMain.Customer.Contact1 == null ? "" : svc.JobMain.Customer.Contact1) +
                (svc.JobMain.Customer.Contact2 == null ? "" : "/" + svc.JobMain.Customer.Contact2);

            svcpu.ClientContact = (svcpu.ClientContact == null || svcpu.ClientContact.Trim() == "" ? sClientContact:svcpu.ClientContact);

            svcpu.ProviderName    = svc.SupplierItem.InCharge;
            svcpu.ProviderContact = svc.SupplierItem.Tel1
                                    + (svc.SupplierItem.Tel2 == null ? "" : "/" + svc.SupplierItem.Tel2)
                                    + (svc.SupplierItem.Tel3 == null ? "" : "/" + svc.SupplierItem.Tel3);

            db.Entry(svcpu).State = EntityState.Modified;
            db.SaveChanges();

            return(RedirectToAction("ServicePickup", new { id = svcpu.Id }));
        }
        public ActionResult AddTemplate(int JobId)
        {
            int iTemplate = (int)TempData["SELECTEDTEMPLATE"];
            int TempId    = (int)TempData["TEMPLATEID"];

            var template = db.Products.Find(TempId);
            var price    = db.ProductPrices.Where(d => d.ProductId == template.Id).OrderBy(s => new { s.Uom, s.Qty });

            // copy job services
            var     jobTemplate  = db.JobMains.Find(iTemplate);
            var     jobRef       = db.JobMains.Find(JobId);
            var     srcJobSvcs   = db.JobServices.Where(d => d.JobMainId == iTemplate);
            var     srcJobIti    = db.JobItineraries.Where(d => d.JobMainId == iTemplate);
            decimal dQuoteAmt    = 0;
            decimal dSupplierAmt = 0;

            DateTime dtJobTemplate  = (DateTime)jobTemplate.JobDate;
            DateTime dtJobDateStart = (DateTime)jobTemplate.JobDate;
            int      irow           = 0;

            #region add new service
            foreach (var src in srcJobSvcs)
            {
                irow++;

                Models.JobServices newJobSrv = new JobServices()
                {
                    JobMainId      = jobRef.Id,
                    ServicesId     = src.ServicesId,
                    DtStart        = jobRef.JobDate,
                    DtEnd          = jobRef.JobDate,
                    Particulars    = src.Particulars,
                    Remarks        = src.Remarks,
                    QuotedAmt      = dQuoteAmt,
                    SupplierAmt    = dSupplierAmt,
                    ActualAmt      = 0,
                    SupplierId     = src.SupplierId,
                    SupplierItemId = src.SupplierItemId
                };

                if (src.DtStart != null)
                {
                    DateTime dtSrc = (DateTime)src.DtStart;
                    TimeSpan tsSrc = dtSrc - dtJobTemplate;
                    if (jobRef.JobDate != null)
                    {
                        newJobSrv.DtStart = jobRef.JobDate.Add(tsSrc);
                        dtJobDateStart    = jobRef.JobDate.Add(tsSrc);
                    }
                }
                if (src.DtEnd != null)
                {
                    DateTime dtSrc = (DateTime)src.DtEnd;
                    TimeSpan tsSrc = dtSrc - dtJobTemplate;
                    if (jobRef.JobDate != null)
                    {
                        newJobSrv.DtEnd = jobRef.JobDate.Add(tsSrc);
                    }
                }

                if (jobRef.NoOfPax > 0 && irow == 1)
                {
                    decimal pPrice = 0;
                    foreach (var p in price)
                    {
                        if (p.Uom == "PAX")
                        {
                            if (p.Qty <= jobRef.NoOfPax)
                            {
                                pPrice = p.Rate * jobRef.NoOfPax;
                            }
                        }
                        if (p.Uom == "UNIT")
                        {
                            pPrice = p.Rate;
                        }
                    }

                    newJobSrv.QuotedAmt = pPrice;
                }


                db.JobServices.Add(newJobSrv);
            }
            #endregion

            #region Copy/Add Itinerary
            foreach (var src in srcJobIti)
            {
                Models.JobItinerary newJobIti = new JobItinerary()
                {
                    JobMainId     = jobRef.Id,
                    DestinationId = src.DestinationId,
                    Remarks       = src.Remarks
                };
                if (src.ItiDate != null)
                {
                    DateTime dtSrc = (DateTime)src.ItiDate;
                    TimeSpan tsSrc = dtSrc - dtJobTemplate;
                    if (jobRef.JobDate != null)
                    {
                        newJobIti.ItiDate = jobRef.JobDate.Add(tsSrc);
                    }
                }
                else
                {
                    newJobIti.ItiDate = dtJobDateStart;
                }


                db.JobItineraries.Add(newJobIti);
            }
            #endregion

            db.SaveChanges();

            #region set svc id to iti
            Models.JobServices jtmp = db.JobServices.Where(d => d.JobMainId == JobId).OrderByDescending(o => o.Id).FirstOrDefault();
            int iAddedSvc           = jtmp.Id;

            IList <Models.JobItinerary> jIti = db.JobItineraries.Where(d => d.JobMainId == JobId && d.SvcId == null).ToList();
            foreach (var tmp in jIti)
            {
                tmp.SvcId           = iAddedSvc;
                db.Entry(tmp).State = EntityState.Modified;
            }
            db.SaveChanges();

            #endregion


            return(RedirectToAction("Services", new { id = JobId }));
        }