//สรุปรายการซ่อมประจำวัน
        public ActionResult ReportDay()
        {
            ViewBag.ReportList = "first active";

            ReportDayViewModel model = new ReportDayViewModel();
            model.Report = new ReportDay();

            DateTime start = DateTime.Today;
            model.DateStart = start.AddYears(543);

            DateTime end = DateTime.Today.AddDays(1);
            model.DateEnd = Convert.ToDateTime(end.AddYears(543).ToString("MM/dd/yyyy"));


            model.Report.Repairs = ReportManager.ReportRepairDay(start);
            model.Report.Claims = ReportManager.ReportClaimDay(start);
            
            var workingstatus = WorkingStatusManager.GetAll().Where(m => m.iDefault>=5 && m.iDefault<=7);
            model.Report.WorkingStatuies = workingstatus.OrderBy(m => m.iDefault).ToList();
            model.Report.Insurances = InsuranceManager.GetAll().OrderBy(m => m.sInsuranceName).ToList();
            model.Report.TCStaffs = StaffManager.GetAll().Where(m => m.StaffPosition.sDescription == "ช่าง").OrderBy(m => m.sStaffName).ToList();
            model.Report.STCStaffs = StaffManager.GetAll().Where(m => m.StaffPosition.sDescription == "หัวหน้าช่าง").OrderBy(m => m.sStaffName).ToList();
            model.Report.QCStaffs = StaffManager.GetAll().Where(m => m.StaffPosition.sDescription == "ฝ่ายตรวจสอบคุณภาพ").OrderBy(m => m.sStaffName).ToList();

            ViewBag.ReportHeader = String.Format("รายงานบริการประจำวันที่ {0}", DateExtension.DateThaiFormat(start));
            return View(model);
        }
Example #2
0
        public JsonResult EditStatus(RepairStatus model)
        {
            try
            {
                WorkingStatusManager.EditRepairStatus(model);


                //re-initial data
                Repair model2 = RepairManager.GetById(model.kRepairId);


                //Inform all connected clients
                var clientName = User.Identity.Name;
                Task.Factory.StartNew(() =>
                {
                    var clients = Hub.GetClients <RealTimeJTableDemoHub>();
                    clients.RecordUpdated(clientName, model2);
                });


                return(Json(new { Result = "OK" }));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }
Example #3
0
        public JsonResult GetAll()
        {
            try
            {
                var items = WorkingStatusManager.GetAll();

                return(Json(new { Result = "OK", Options = items.Select(m => new { DisplayText = m.sDescription, Value = m.kWorkingStatusId }) }));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }
Example #4
0
 public JsonResult Delete(Guid kWorkingStatusId)
 {
     try
     {
         //Thread.Sleep(50);
         WorkingStatusManager.Delete(kWorkingStatusId);
         return(Json(new { Result = "OK" }));
     }
     catch (Exception ex)
     {
         return(Json(new { Result = "ERROR", Message = "Cann't Delete" }));
     }
 }
Example #5
0
        public JsonResult Search(string term)
        {
            try
            {
                var items = WorkingStatusManager.GetBySearch(term);

                return(Json(items.Select(m => m.sDescription), JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }
Example #6
0
        public JsonResult GetClaimWorkingStatusByPosition()
        {
            try
            {
                var items = WorkingStatusManager.GetAll()
                            .Where(m => m.iDefault == (int)Working.Claim || m.iDefault == (int)Working.Claiming || m.iDefault == (int)Working.ConfirmRepair)
                            .ToList().OrderBy(m => m.sDescription);

                return(Json(new { Result = "OK", Options = items.Select(m => new { DisplayText = m.sDescription, Value = m.kWorkingStatusId }) }));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }
Example #7
0
        public JsonResult Create(WorkingStatus model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Json(new { Result = "ERROR", Message = "Form is not valid! Please correct it and try again." }));
                }
                model.kWorkingStatusId = Guid.NewGuid();

                WorkingStatusManager.Create(model);
                return(Json(new { Result = "OK", Record = model }));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }
Example #8
0
        public JsonResult GetWorkingStatusByPosition()
        {
            try
            {
                var id    = (Guid)Membership.GetUser().ProviderUserKey;
                var staff = StaffManager.GetById(id);
                var items = WorkingStatusManager
                            .GetByPosition(staff.StaffPosition.sDescription)
                            .Where(m => m.iDefault != (int)Working.Claiming)
                            .OrderBy(m => m.iDefault);



                return(Json(new { Result = "OK", Options = items.Select(m => new { DisplayText = m.sDescription, Value = m.kWorkingStatusId }) }));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }
Example #9
0
        public JsonResult Lists(string jtSearching = null, int jtStartIndex = 0, int jtPageSize = 0, string jtSorting = null)
        {
            try
            {
                //Thread.Sleep(200);
                var itemCount = WorkingStatusManager.GetCountByFiltering(jtSearching);
                var items     = WorkingStatusManager.GetByFilterings(jtSearching, jtStartIndex, jtPageSize, jtSorting).ToList();

                return(Json(new
                {
                    Result = "OK",
                    Records = items,
                    TotalRecordCount = itemCount
                }, JsonRequestBehavior.AllowGet));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }
Example #10
0
        public JsonResult Edit(WorkingStatus model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Json(new { Result = "ERROR", Message = "Form is not valid! Please correct it and try again." }));
                }

                WorkingStatus itemFound = WorkingStatusManager.GetById(model.kWorkingStatusId);
                if (itemFound == null)
                {
                    return(Json(new { Result = "ERROR", Message = "Item Not Found" }));
                }

                WorkingStatusManager.Edit(model);
                return(Json(new { Result = "OK" }));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }
Example #11
0
        public JsonResult GetWorkingStatusByStep(int step)
        {
            try
            {
                var items = WorkingStatusManager.GetAll();

                //ªèÒ§
                if (step == 1)
                {
                    items = items.Where(m => m.iDefault == (int)Working.Claim || m.iDefault == (int)Working.QC || m.iDefault == (int)Working.Repair).ToList();
                }
                //
                else if (step == 2)
                {
                    items = items.Where(m => m.iDefault == (int)Working.Claim || m.iDefault == (int)Working.QC || m.iDefault == (int)Working.Repair).ToList();
                }

                return(Json(new { Result = "OK", Options = items.Select(m => new { DisplayText = m.sDescription, Value = m.kWorkingStatusId }) }));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }
Example #12
0
        public ActionResult Index()
        {
            ViewBag.ClientName = User.Identity.Name;
            ViewBag.ClaimList  = "first active";

            BookingClaimViewModel model = new BookingClaimViewModel();

            ViewBag.WorkingStatus = new SelectList(WorkingStatusManager.GetAll().Where(m => m.iDefault > 0), "kWorkingStatusId", "sDescription");


            if (!User.IsInRole("Admin"))
            {
                if (Staff.vStaffPositionDescription == "ฝ่ายเครม")
                {
                    return(View("ListsCR", model));
                }
                else
                {
                    return(View("ListsUser", model));
                }
            }

            return(View(model));
        }
Example #13
0
        public ActionResult Create(BookingClaimViewModel model, FormCollection collection)
        {
            try
            {
                //initial working status
                var workingStatusId = WorkingStatusManager.GetAll().Where(m => m.iDefault == (int)Working.Claiming).SingleOrDefault();

                if (model.Product != null)
                {
                    model.Product.Brand = BrandManager.GetById(model.Product.kBrandId);
                }
                model.Product.ProductType = ProductTypeManager.GetById(model.Product.kProductTypeId);

                #region SAVE CUSTOMER
                var insCount = InsuranceManager.GetCountDuplicate(model.Insurance.sInsuranceName.Trim());
                if (insCount.Count <= 0)
                {
                    Insurance insurance = new Insurance
                    {
                        kInsuranceId   = Guid.NewGuid(),
                        sInsuranceName = model.Insurance.sInsuranceName,
                        sAddress1      = model.Insurance.sAddress1,
                        sCity          = model.Insurance.sCity,
                        sZip           = model.Insurance.sZip,
                        sPhone         = model.Insurance.sPhone,
                        sMobile        = model.Insurance.sMobile,
                        sFax           = model.Insurance.sFax,
                        sEmailAddress  = model.Insurance.sEmailAddress
                    };
                    InsuranceManager.Create(insurance);
                    model.Claim.Insurance = insurance;
                }
                else
                {
                    model.Claim.Insurance = insCount[0];
                }
                #endregion

                #region SAVE Brand
                var brandCount = BrandManager.GetCountDuplicate(model.Product.Brand.sBrandName.Trim());
                if (brandCount.Count <= 0)
                {
                    Brand brand = new Brand
                    {
                        kBrandId   = Guid.NewGuid(),
                        sBrandName = model.Product.Brand.sBrandName
                    };
                    BrandManager.Create(brand);
                    model.Product.Brand = brand;
                }
                else
                {
                    model.Product.Brand = brandCount[0];
                }
                #endregion

                #region SAVE Product Type
                var productTypeCount = ProductTypeManager.GetCountDuplicate(model.Product.ProductType.sDescription.Trim());
                if (productTypeCount.Count <= 0)
                {
                    ProductType productType = new ProductType
                    {
                        kProductTypeId = Guid.NewGuid(),
                        sDescription   = model.Product.ProductType.sDescription
                    };
                    ProductTypeManager.Create(productType);
                    model.Product.ProductType = productType;
                }
                else
                {
                    model.Product.ProductType = productTypeCount[0];
                }
                #endregion

                #region SAVE PRODUCT
                var productCount = ProductManager.GetCountDuplicate(
                    model.Product.sProductName.Trim()
                    //, model.Product.Brand.sBrandName.Trim()
                    //, model.Product.ProductType.sDescription.Trim()
                    );
                if (productCount.Count <= 0)
                {
                    Product product = new Product
                    {
                        kProductId     = Guid.NewGuid(),
                        kProductTypeId = productTypeCount.SingleOrDefault().kProductTypeId,
                        kBrandId       = brandCount.SingleOrDefault().kBrandId,
                        sProductName   = model.Product.sProductName,
                        sProductModel  = model.Product.sProductModel
                    };
                    ProductManager.Create(product);
                    model.Product = product;
                }
                else
                {
                    model.Product = productCount[0];
                }
                #endregion

                #region SAVE CLAIM BOOKING
                var repair = RepairManager.GetByRepairNo(model.Claim.sRepairNo ?? "");

                //initial booking first character
                string char_number = CharBooking.C.ToString();

                Claim claim = new Claim();
                claim.dtDateUpdate = DateTime.Now;
                claim.kClaimId     = Guid.NewGuid();
                claim.kStaffId     = (Guid)Membership.GetUser().ProviderUserKey;
                claim.kOwnerId     = repair.kOwnerId ?? (Guid)Membership.GetUser().ProviderUserKey;
                claim.kInsuranceId = model.Claim.Insurance.kInsuranceId;
                claim.kProductId   = model.Product.kProductId;
                claim.sRepairNo    = model.Claim.sRepairNo;
                claim.sClaimNo     = String.Format("{0}{1}", char_number, ClaimNextItemNoManager.GetNextItemNo());
                claim.sSerial      = model.Claim.sSerial;
                if (model.Claim.dtInsuranceExpire != null)
                {
                    claim.dtInsuranceExpire = model.Claim.dtInsuranceExpire.Value.AddYears(-543);
                }


                model.Claim = claim;
                ClaimManager.Create(model.Claim);
                ClaimNextItemNoManager.IncreaseNextItemNo();

                #region also pdate repair side

                repair.dtDateUpdate = DateTime.Now;
                repair.kStaffId     = (Guid)Membership.GetUser().ProviderUserKey;
                RepairManager.Edit(repair);

                #endregion

                #endregion

                #region SAVE REPAIR WORKING STATUS

                ClaimStatus claimStatus = new ClaimStatus
                {
                    kClaimStatusId   = Guid.NewGuid(),
                    kWorkingStatusId = workingStatusId.kWorkingStatusId,
                    kStaffId         = (Guid)Membership.GetUser().ProviderUserKey,
                    kClaimId         = model.Claim.kClaimId
                };
                ClaimStatusManager.Create(claimStatus);

                #endregion

                #region UPDATE REPAIR WORKING STATUS
                if (!String.IsNullOrEmpty(model.Claim.sRepairNo))
                {
                    repair = RepairManager.GetByRepairNo(model.Claim.sRepairNo);

                    RepairStatus repairStatus = new RepairStatus
                    {
                        kRepairStatusId  = Guid.NewGuid(),
                        kWorkingStatusId = workingStatusId.kWorkingStatusId,
                        kStaffId         = (Guid)Membership.GetUser().ProviderUserKey,
                        kRepairId        = repair.kRepairId
                    };
                    RepairStatusManager.Create(repairStatus);
                }
                #endregion



                #region SAVE CAUSE OF CLAIM

                //initial cause
                string keyname;
                string keyvalue;
                int    countvalue = 0;
                for (int i = 0; i <= collection.Count - 1; i++)
                {
                    keyname  = collection.AllKeys[i];
                    keyvalue = collection[i];

                    if (keyname.Contains("cause"))
                    {
                        countvalue++;
                    }
                }

                if (countvalue > 1)
                {
                    model.ClaimCauses = new List <ClaimCause>();
                    for (int i = 1; i <= countvalue / 4; i++)
                    {
                        ClaimCause claimCause = new ClaimCause();
                        claimCause.kClaimCauseId = Guid.NewGuid();
                        claimCause.kClaimId      = model.Claim.kClaimId;
                        claimCause.kStaffId      = (Guid)Membership.GetUser().ProviderUserKey;
                        claimCause.sDescription  = collection[String.Format("cause_description_{0}", i)];
                        claimCause.sNote         = collection[String.Format("cause_note_{0}", i)];

                        if (!String.IsNullOrEmpty(claimCause.sDescription))
                        {
                            int qty = 0;
                            if (int.TryParse(collection[String.Format("cause_qty_{0}", i)], out qty))
                            {
                                claimCause.iQty = qty;
                            }

                            Decimal price = 0;
                            if (Decimal.TryParse(collection[String.Format("cause_price_{0}", i)], out price))
                            {
                                claimCause.dPrice = price;
                            }

                            model.ClaimCauses.Add(claimCause);
                            ClaimCourseManager.Create(claimCause);
                        }
                    }
                }

                if (model.ClaimCauses != null)
                {
                    foreach (var item in model.ClaimCauses)
                    {
                        var causeCount = CauseManager.GetCountDuplicate(item.sDescription.Trim());
                        if (causeCount <= 0)
                        {
                            Cause cause = new Cause
                            {
                                kCauseId     = Guid.NewGuid(),
                                sDescription = item.sDescription.Trim()
                            };
                            CauseManager.Create(cause);
                        }
                    }
                }
                #endregion
            }
            catch (Exception ex)
            {
                return(RedirectToAction("Error", "Home"));
            }

            Claim model2 = ClaimManager.GetById(model.Claim.kClaimId);

            //create remind for history
            RemindHistory remind = new RemindHistory
            {
                sRemind  = model2.vMessage,
                kStaffId = model2.kStaffId
            };
            RemindHistoryManager.Create(remind);

            var clientName = User.Identity.Name;
            Task.Factory.StartNew(() =>
            {
                var clients = Hub.GetClients <RealTimeJTableDemoHub>();
                clients.RecordCreated(clientName, model2);
            });

            return(RedirectToAction("Index"));
        }
Example #14
0
        public JsonResult EditClaim(Claim claim_sending, ClaimStatus status_sending)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    return(Json(new { Result = "ERROR", Message = "Form is not valid! Please correct it and try again." }));
                }

                Repair repair    = null;
                Claim  itemFound = ClaimManager.GetById(claim_sending.kClaimId);
                if (itemFound == null)
                {
                    return(Json(new { Result = "ERROR", Message = "Item Not Found" }));
                }
                if (itemFound.IsComplete == true)
                {
                    return(Json(new { Result = "ERROR", Message = "ปิด job!" }));
                }

                var status = WorkingStatusManager.GetById(status_sending.kWorkingStatusId);
                if (status.iDefault == (int)Working.ConfirmRepair && claim_sending.IsRecieved != true)
                {
                    return(Json(new { Result = "ERROR", Message = "ตรวจรับสินค้า!" }));
                }


                bool isStatusChange = false;
                if (status_sending.kWorkingStatusId != itemFound.kWorkingStatusId)
                {
                    #region update claim status side
                    if (status.iDefault == (int)Working.ConfirmRepair)
                    {
                        status_sending.kStaffId = itemFound.kOwnerId.Value;
                    }
                    else
                    {
                        status_sending.kStaffId = (Guid)Membership.GetUser().ProviderUserKey;
                    }
                    status_sending.dtDateAdd      = DateTime.Now;
                    status_sending.kClaimStatusId = Guid.NewGuid();
                    ClaimStatusManager.Create(status_sending);

                    #endregion

                    #region also update repair status side
                    if (!String.IsNullOrEmpty(itemFound.sRepairNo))
                    {
                        repair = RepairManager.GetByRepairNo(itemFound.sRepairNo);
                        RepairStatus repairStatus = new RepairStatus
                        {
                            kStaffId         = itemFound.kOwnerId.Value,
                            kRepairId        = repair.kRepairId,
                            kWorkingStatusId = status_sending.kWorkingStatusId,
                            kRepairStatusId  = Guid.NewGuid()
                        };
                        RepairStatusManager.Create(repairStatus);
                    }
                    #endregion

                    isStatusChange = true;
                }


                #region update claim
                //assign claim
                itemFound.dtDateUpdate = DateTime.Now;
                itemFound.IsRecieved   = claim_sending.IsRecieved;
                itemFound.IsNoCredit   = claim_sending.IsNoCredit;
                if (isStatusChange)
                {
                    itemFound.kStaffId = itemFound.kOwnerId.Value;
                }
                ClaimManager.Edit(itemFound);
                #endregion

                #region update repair
                if (isStatusChange)
                {
                    if (repair != null)
                    {
                        repair.kStaffId = status_sending.kStaffId;
                    }
                    RepairManager.Edit(repair);
                }
                #endregion

                if (isStatusChange)
                {
                    //create remind for history
                    RemindHistory remind = new RemindHistory
                    {
                        sRemind  = itemFound.vMessage,
                        kStaffId = itemFound.kOwnerId.Value
                    };
                    RemindHistoryManager.Create(remind);

                    var clientName = User.Identity.Name;
                    Task.Factory.StartNew(() =>
                    {
                        var clients = Hub.GetClients <RealTimeJTableDemoHub>();
                        clients.RecordUpdated(clientName, itemFound);
                    });
                }

                return(Json(new { Result = "OK", Records = itemFound }));
            }
            catch (Exception ex)
            {
                return(Json(new { Result = "ERROR", Message = ex.Message }));
            }
        }