Exemplo n.º 1
0
        public ActionResult Delete(string id, string uName)
        {
            var uid = _context.AppUsers.Where(u => u.UserName == uName).FirstOrDefault().Id;

            try
            {
                KeepEmpModel keepEmp = _context.BMEDKeepEmps.Find(id, uid);
                _context.BMEDKeepEmps.Remove(keepEmp);
                _context.SaveChanges();

                // Recount the all keep time, and set value to KeepDtl.
                KeepDtlModel dtl = _context.BMEDKeepDtls.Where(d => d.DocId == keepEmp.DocId)
                                   .FirstOrDefault();
                if (dtl != null)
                {
                    int hr = _context.BMEDKeepEmps.Where(p => p.DocId == keepEmp.DocId)
                             .Select(p => p.Hour)
                             .DefaultIfEmpty(0).Sum();
                    decimal min = _context.BMEDKeepEmps.Where(p => p.DocId == keepEmp.DocId)
                                  .Select(p => p.Minute)
                                  .DefaultIfEmpty(0).Sum();
                    dtl.Hours = hr + Decimal.Round(min / 60m, 2);
                    _context.Entry(dtl).State = EntityState.Modified;
                    _context.SaveChanges();
                }
                return(new JsonResult(keepEmp)
                {
                    Value = new { success = true, error = "" }
                });
            }
            catch (Exception e)
            {
                throw new Exception(e.Message);
            }
        }
Exemplo n.º 2
0
 public IActionResult Delete(string docid, string seqno)
 {
     try
     {
         KeepCostModel keepCost = _context.BMEDKeepCosts.Find(docid, Convert.ToInt32(seqno));
         _context.BMEDKeepCosts.Remove(keepCost);
         _context.SaveChanges();
         //
         KeepDtlModel dtl = _context.BMEDKeepDtls.Where(d => d.DocId == keepCost.DocId)
                            .FirstOrDefault();
         if (dtl != null)
         {
             dtl.Cost = _context.BMEDKeepCosts.Where(k => k.DocId == keepCost.DocId)
                        .Select(k => k.TotalCost)
                        .DefaultIfEmpty(0).Sum();
             _context.Entry(dtl).State = EntityState.Modified;
             _context.SaveChanges();
         }
         return(new JsonResult(keepCost)
         {
             Value = new { success = true, error = "" }
         });
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Exemplo n.º 3
0
 public async Task <IActionResult> Edit(KeepDtlModel keepDtlModel)
 {
     if (ModelState.IsValid)
     {
         try
         {
             if (keepDtlModel.IsCharged == "N")
             {
                 var keepCost = _context.BMEDKeepCosts.Where(c => c.DocId == keepDtlModel.DocId).ToList();
                 if (keepCost.Count() > 0)
                 {
                     throw new Exception("點選無費用時,請先刪除所有費用明細!!");
                 }
                 //_context.BMEDKeepCosts.RemoveRange(_context.BMEDKeepCosts.Where(c => c.DocId == keepDtlModel.DocId));
                 keepDtlModel.Cost = 0;
             }
             else
             {
                 keepDtlModel.Cost = _context.BMEDKeepCosts.Where(k => k.DocId == keepDtlModel.DocId)
                                     .Select(k => k.TotalCost)
                                     .DefaultIfEmpty(0).Sum();
                 int hr = _context.BMEDKeepEmps.Where(p => p.DocId == keepDtlModel.DocId)
                          .Select(p => p.Hour)
                          .DefaultIfEmpty(0).Sum();
                 decimal min = _context.BMEDKeepEmps.Where(p => p.DocId == keepDtlModel.DocId)
                               .Select(p => p.Minute)
                               .DefaultIfEmpty(0).Sum();
                 keepDtlModel.Hours = hr + Decimal.Round(min / 60m, 2);
             }
             _context.Entry(keepDtlModel).State = EntityState.Modified;
             _context.SaveChanges();
             return(new JsonResult(keepDtlModel)
             {
                 Value = new { success = true, error = "" }
             });
         }
         catch (Exception e)
         {
             throw new Exception(e.Message);
         }
     }
     else
     {
         string msg = "";
         foreach (var error in ViewData.ModelState.Values.SelectMany(modelState => modelState.Errors))
         {
             msg += error.ErrorMessage + Environment.NewLine;
         }
         throw new Exception(msg);
     }
 }
Exemplo n.º 4
0
        public ActionResult Edit(KeepEmpModel keepEmp)
        {
            if (ModelState.IsValid)
            {
                var ExistKeepEmp = _context.BMEDKeepEmps.Find(keepEmp.DocId, keepEmp.UserId);
                if (ExistKeepEmp != null)
                {
                    return(new JsonResult(keepEmp)
                    {
                        Value = new { isExist = true, error = "資料已存在!" }
                    });
                }
                else
                {
                    _context.BMEDKeepEmps.Add(keepEmp);
                    _context.SaveChanges();
                }

                // Recount the all keep time, and set value to KeepDtl.
                KeepDtlModel dtl = _context.BMEDKeepDtls.Where(d => d.DocId == keepEmp.DocId)
                                   .FirstOrDefault();
                if (dtl != null)
                {
                    int hr = _context.BMEDKeepEmps.Where(p => p.DocId == keepEmp.DocId)
                             .Select(p => p.Hour)
                             .DefaultIfEmpty(0).Sum();
                    decimal min = _context.BMEDKeepEmps.Where(p => p.DocId == keepEmp.DocId)
                                  .Select(p => p.Minute)
                                  .DefaultIfEmpty(0).Sum();
                    dtl.Hours = hr + Decimal.Round(min / 60m, 2);
                    _context.Entry(dtl).State = EntityState.Modified;
                    _context.SaveChanges();
                }

                // Return ViewComponent for ajax request.
                return(ViewComponent("BMEDKeepEmpList", new { id = keepEmp.DocId, viewType = "Edit" }));
            }
            else
            {
                string msg = "";
                foreach (var error in ViewData.ModelState.Values.SelectMany(modelState => modelState.Errors))
                {
                    msg += error.ErrorMessage + Environment.NewLine;
                }
                throw new Exception(msg);
            }
        }
Exemplo n.º 5
0
        public IActionResult KeepCostEdit(KeepCostModel keepCost)
        {
            var ur = _userRepo.Find(u => u.UserName == this.User.Identity.Name).FirstOrDefault();

            if (keepCost.SignNo != null)
            {
                keepCost.SignNo = keepCost.SignNo.ToUpper();
            }
            if (keepCost.StockType == "3")
            {
                ModelState.Remove("TicketDtl.SeqNo");
            }
            if (ModelState.IsValid)
            {
                keepCost.Rtp = ur.Id;
                keepCost.Rtt = DateTime.Now;
                _context.Entry(keepCost).State = EntityState.Modified;
                _context.SaveChanges();

                KeepDtlModel dtl = _context.KeepDtls.Where(d => d.DocId == keepCost.DocId)
                                   .FirstOrDefault();
                if (dtl != null)
                {
                    dtl.Cost = _context.KeepCosts.Where(k => k.DocId == keepCost.DocId)
                               .Select(k => k.TotalCost)
                               .DefaultIfEmpty(0).Sum();
                    _context.Entry(dtl).State = EntityState.Modified;
                    _context.SaveChanges();
                }

                return(new JsonResult(keepCost)
                {
                    Value = new { success = true, error = "" }
                });
            }
            else
            {
                string msg = "";
                foreach (var error in ViewData.ModelState.Values.SelectMany(modelState => modelState.Errors))
                {
                    msg += error.ErrorMessage + Environment.NewLine;
                }
                throw new Exception(msg);
            }
        }
Exemplo n.º 6
0
        public async Task <IViewComponentResult> InvokeAsync(string id)
        {
            KeepDtlModel keepDtl = _context.KeepDtls.Find(id);

            if (keepDtl == null)
            {
                return(Content("Page not found!"));  //ViewComponent can't return HTTP response (like as StatusCode() or BasRequest())
            }
            else
            {
                switch (keepDtl.InOut)
                {
                case "0":
                    keepDtl.InOut = "自行";
                    break;

                case "1":
                    keepDtl.InOut = "委外";
                    break;

                case "2":
                    keepDtl.InOut = "租賃";
                    break;

                case "3":
                    keepDtl.InOut = "保固";
                    break;
                }
                if (keepDtl.Result != null)
                {
                    keepDtl.ResultTitle = _context.KeepResults.Find(keepDtl.Result).Title;
                }
            }
            /* Get CheckerName from Keep table. */
            var checkerId = _context.Keeps.Find(id).CheckerId;

            keepDtl.CheckerName = checkerId == 0 ? "" : _context.AppUsers.Find(checkerId).FullName;

            return(View(keepDtl));
        }
Exemplo n.º 7
0
        // GET: Keep/PrintKeepDoc/5
        public IActionResult PrintKeepDoc(string DocId, int printType)
        {
            /* Get all print details according to the DocId. */
            KeepModel    keep = _context.Keeps.Find(DocId);
            KeepDtlModel dtl  = _context.KeepDtls.Find(DocId);
            KeepEmpModel emp  = _context.KeepEmps.Where(ep => ep.DocId == DocId).FirstOrDefault();

            /* Get the last flow. */
            string[]      s    = new string[] { "?", "2" };
            KeepFlowModel flow = _context.KeepFlows.Where(f => f.DocId == DocId)
                                 .Where(f => s.Contains(f.Status)).FirstOrDefault();
            KeepPrintVModel vm = new KeepPrintVModel();

            if (keep == null)
            {
                return(StatusCode(404));
            }
            else
            {
                vm.Docid       = DocId;
                vm.UserId      = keep.UserId;
                vm.UserName    = keep.UserName;
                vm.UserAccount = _context.AppUsers.Find(keep.UserId).UserName;
                vm.AccDpt      = keep.AccDpt;
                vm.SentDate    = keep.SentDate;
                vm.AssetNo     = keep.AssetNo;
                vm.AssetNam    = keep.AssetName;
                vm.Company     = _context.Departments.Find(keep.DptId).Name_C;
                vm.Amt         = 1;
                vm.Cycle       = keep.Cycle;
                vm.Contact     = keep.Ext;
                vm.PlaceLoc    = keep.PlaceLoc;

                if (dtl != null)
                {
                    vm.Result  = dtl.Result == null ? "" : _context.KeepResults.Find(dtl.Result).Title;
                    vm.Memo    = dtl.Memo;
                    vm.EndDate = dtl.EndDate;
                }
                //
                vm.AccDptNam = _context.Departments.Find(keep.AccDpt).Name_C;
                vm.Hour      = dtl.Hours == null ? 0 : dtl.Hours.Value;
                vm.InOut     = dtl.InOut == "0" ? "自行" :
                               dtl.InOut == "1" ? "委外" :
                               dtl.InOut == "2" ? "租賃" :
                               dtl.InOut == "3" ? "保固" : "";
                //vm.EngName = emp == null ? "" : _context.AppUsers.Find(emp.UserId).FullName;
                var lastFlowEng = _context.KeepFlows.Where(rf => rf.DocId == DocId)
                                  .Where(rf => rf.Cls.Contains("工程師"))
                                  .OrderByDescending(rf => rf.StepId).FirstOrDefault();
                AppUserModel EngTemp = _context.AppUsers.Find(lastFlowEng.UserId);
                if (EngTemp != null)
                {
                    vm.EngName = EngTemp.FullName + " (" + EngTemp.UserName + ")";
                }
                else
                {
                    vm.EngName = "";
                }

                var engMgr = _context.KeepFlows.Where(r => r.DocId == DocId)
                             .Where(r => r.Cls.Contains("工務主管") || r.Cls.Contains("營建主管"))
                             .Where(r => r.Opinions.Contains("[同意]")).ToList();
                if (engMgr.Count() != 0)
                {
                    engMgr = engMgr.GroupBy(e => e.UserId).Select(group => group.FirstOrDefault()).ToList();
                    foreach (var item in engMgr)
                    {
                        vm.EngMgr += item == null ? "" : _context.AppUsers.Find(item.UserId).FullName + "  ";
                    }
                }

                var engDirector = _context.KeepFlows.Where(r => r.DocId == DocId)
                                  .Where(r => r.Cls.Contains("工務主任") || r.Cls.Contains("營建主任"))
                                  .Where(r => r.Opinions.Contains("[同意]")).LastOrDefault();
                string firstString = "";
                if (engDirector != null)
                {
                    if (engDirector.Opinions != null)
                    {
                        var firstBracketIndex = engDirector.Opinions.IndexOf("]");
                        firstString = engDirector.Opinions.Substring(0, firstBracketIndex);
                    }
                }
                vm.EngDirector = engDirector == null ? "" : firstString + "]" + _context.AppUsers.Find(engDirector.UserId).FullName;

                var delivMgr = _context.RepairFlows.Where(r => r.DocId == DocId)
                               .Where(r => r.Cls.Contains("單位主管"))
                               .Where(r => r.Opinions.Contains("[同意]")).ToList();
                if (delivMgr.Count() != 0)
                {
                    delivMgr = delivMgr.GroupBy(e => e.UserId).Select(group => group.FirstOrDefault()).ToList();
                    foreach (var item in delivMgr)
                    {
                        vm.DelivMgr += item == null ? "" : _context.AppUsers.Find(item.UserId).FullName + "  ";
                    }
                }

                var delivDirector = _context.RepairFlows.Where(r => r.DocId == DocId)
                                    .Where(r => r.Cls.Contains("單位主任"))
                                    .Where(r => r.Opinions.Contains("[同意]")).LastOrDefault();
                vm.DelivDirector = delivDirector == null ? "" : _context.AppUsers.Find(delivDirector.UserId).FullName;

                var ViceSI = _context.RepairFlows.Where(r => r.DocId == DocId)
                             .Where(r => r.Cls.Contains("院長室主管") || r.Cls.Contains("副院長"))
                             .Where(r => r.Opinions.Contains("[同意]")).LastOrDefault();
                vm.ViceSuperintendent = ViceSI == null ? "" : _context.AppUsers.Find(ViceSI.UserId).FullName;

                if (flow != null)
                {
                    if (flow.Status == "2")
                    {
                        vm.CloseDate = flow.Rtt;
                        AppUserModel u = _context.AppUsers.Find(flow.UserId);
                        if (u != null)
                        {
                            vm.DelivEmp     = u.UserName;
                            vm.DelivEmpName = u.FullName;
                        }
                    }
                }
            }
            //if (printType != 0)
            //{
            //    return View("PrintRepairDoc2", vm);
            //}
            return(View(vm));
        }
Exemplo n.º 8
0
        public IActionResult Create(KeepModel keep)
        {
            AppUserModel ur = _context.AppUsers.Where(u => u.UserName == this.User.Identity.Name).FirstOrDefault();

            //if (string.IsNullOrEmpty(keep.AssetNo))
            //{
            //    throw new Exception("財產編號不可空白!!");
            //}
            string msg = "";

            try
            {
                if (ModelState.IsValid)
                {
                    //更新申請人的Email
                    if (string.IsNullOrEmpty(keep.Email))
                    {
                        throw new Exception("電子信箱不可空白!!");
                    }
                    AppUserModel a = _context.AppUsers.Find(keep.UserId);
                    a.Email = keep.Email;
                    _context.Entry(a).State = EntityState.Modified;
                    _context.SaveChanges();
                    //
                    AssetKeepModel kp = _context.AssetKeeps.Find(keep.DeviceNo);
                    AssetModel     at = _context.Assets.Find(keep.DeviceNo);
                    //
                    keep.AssetNo   = _context.Assets.Find(keep.DeviceNo).AssetNo;
                    keep.AssetName = _context.Assets.Find(keep.DeviceNo).Cname;
                    keep.EngId     = kp.KeepEngId;
                    //keep.AccDpt = at.AccDpt;
                    keep.SentDate = DateTime.Now;
                    keep.Cycle    = "手動出單";
                    keep.Src      = "M";
                    _context.Entry(keep).State = EntityState.Modified;

                    //
                    KeepDtlModel dl = new KeepDtlModel();
                    //var notInExceptDevice = _context.ExceptDevice.Find(keep.AssetNo);

                    /* If can find data in ExceptDevice table, the device is "not" 統包.
                     * It means if value is "Y", the device is 統包
                     */
                    //if (notInExceptDevice == null)
                    //{
                    //    dl.NotInExceptDevice = "Y";
                    //}
                    //else
                    //{
                    //    dl.NotInExceptDevice = "N";
                    //}
                    dl.DocId = keep.DocId;
                    switch (kp == null ? "自行" : kp.InOut)
                    {
                    case "自行":
                        dl.InOut = "0";
                        break;

                    case "委外":
                        dl.InOut = "1";
                        break;

                    case "租賃":
                        dl.InOut = "2";
                        break;

                    case "保固":
                        dl.InOut = "3";
                        break;

                    default:
                        dl.InOut = "0";
                        break;
                    }
                    _context.KeepDtls.Add(dl);
                    _context.SaveChanges();
                    //
                    KeepFlowModel kf = new KeepFlowModel();
                    kf.DocId  = keep.DocId;
                    kf.StepId = 1;
                    kf.UserId = ur.Id;
                    kf.Status = "1";
                    //rf.Role = Roles.GetRolesForUser().FirstOrDefault();
                    kf.Rtp = ur.Id;
                    kf.Rdt = null;
                    kf.Rtt = DateTime.Now;
                    kf.Cls = "申請者";
                    _context.KeepFlows.Add(kf);
                    //
                    kf        = new KeepFlowModel();
                    kf.DocId  = keep.DocId;
                    kf.StepId = 2;
                    kf.UserId = kp == null ? ur.Id : kp.KeepEngId;
                    kf.Status = "?";
                    AppUserModel u = _context.AppUsers.Find(kf.UserId);
                    if (u == null)
                    {
                        throw new Exception("無工程師資料!!");
                    }
                    //rf.Role = Roles.GetRolesForUser(u.UserName).FirstOrDefault();
                    kf.Rtp = null;
                    kf.Rdt = null;
                    kf.Rtt = DateTime.Now;
                    kf.Cls = "設備工程師";
                    _context.KeepFlows.Add(kf);
                    _context.SaveChanges();
                    //send mail
                    Tmail  mail = new Tmail();
                    string body = "";
                    u         = _context.AppUsers.Find(ur.Id);
                    mail.from = new System.Net.Mail.MailAddress(u.Email); //u.Email
                    //u = _context.AppUsers.Find(kp.KeepEngId);
                    mail.to = new System.Net.Mail.MailAddress(u.Email);   //u.Email
                    mail.message.Subject = "醫工工務智能保修系統[醫工保養案]:設備名稱: " + keep.AssetName;
                    body += "<p>表單編號:" + keep.DocId + "</p>";
                    body += "<p>送單日期:" + keep.SentDate.Value.ToString("yyyy/MM/dd") + "</p>";
                    body += "<p>申請人:" + keep.UserName + "</p>";
                    body += "<p>財產編號:" + keep.AssetNo + "</p>";
                    body += "<p>設備名稱:" + keep.AssetName + "</p>";
                    body += "<p>放置地點:" + keep.PlaceLoc + "</p>";
                    body += "<p><a href='http://dms.cch.org.tw/EDIS/Account/Login'" + "?docId=" + keep.DocId + "&dealType=KeepEdit" + ">處理案件</a></p>";
                    body += "<br/>";
                    body += "<h3>此封信件為系統通知郵件,請勿回覆。</h3>";
                    body += "<br/>";
                    body += "<h3 style='color:red'>如有任何疑問請聯絡工務部,分機3033或7033。<h3>";
                    mail.message.Body       = body;
                    mail.message.IsBodyHtml = true;
                    //mail.SendMail();

                    return(Ok(keep));
                }
                else
                {
                    msg = "";
                    foreach (var error in ViewData.ModelState.Values.SelectMany(modelState => modelState.Errors))
                    {
                        msg += error.ErrorMessage + Environment.NewLine;
                    }
                    throw new Exception(msg);
                }
            }
            catch (Exception ex)
            {
                msg = ex.Message;
            }
            return(BadRequest(msg));
        }
Exemplo n.º 9
0
        public async Task <IActionResult> Edit(KeepCostModel keepCost)
        {
            var ur   = _userRepo.Find(u => u.UserName == this.User.Identity.Name).FirstOrDefault();
            var kdtl = _context.BMEDKeepDtls.Find(keepCost.DocId);

            /* Change to UpperCase.*/
            if (keepCost.TicketDtl.TicketDtlNo != null)
            {
                keepCost.TicketDtl.TicketDtlNo = keepCost.TicketDtl.TicketDtlNo.ToUpper();
            }
            if (keepCost.SignNo != null)
            {
                keepCost.SignNo = keepCost.SignNo.ToUpper();
            }

            if (ModelState.IsValid)
            {
                try
                {
                    if (keepCost.StockType == "2")
                    {
                        var dupData = _context.BMEDKeepCosts.Include(c => c.TicketDtl)
                                      .Where(c => c.DocId == keepCost.DocId &&
                                             c.PartName == keepCost.PartName &&
                                             c.Standard == keepCost.Standard &&
                                             c.TicketDtl.TicketDtlNo == keepCost.TicketDtl.TicketDtlNo).FirstOrDefault();
                        if (dupData != null)
                        {
                            string msg = "資料重複儲存!!";
                            return(BadRequest(msg));
                        }
                    }
                    else
                    {
                        var dupData = _context.BMEDKeepCosts.Include(c => c.TicketDtl)
                                      .Where(c => c.DocId == keepCost.DocId &&
                                             c.PartName == keepCost.PartName &&
                                             c.Standard == keepCost.Standard &&
                                             c.SignNo == keepCost.SignNo).FirstOrDefault();
                        if (dupData != null)
                        {
                            string msg = "資料重複儲存!!";
                            return(BadRequest(msg));
                        }
                    }

                    int seqno = _context.BMEDKeepCosts.Where(c => c.DocId == keepCost.DocId)
                                .Select(c => c.SeqNo).DefaultIfEmpty().Max();
                    keepCost.SeqNo = seqno + 1;
                    if (keepCost.StockType == "2")
                    {
                        if (string.IsNullOrEmpty(keepCost.TicketDtl.TicketDtlNo))
                        {
                            //throw new Exception("發票號碼不可空白!!");
                            string msg = "發票號碼不可空白!!";
                            return(BadRequest(msg));
                        }
                        if (keepCost.AccountDate == null)
                        {
                            //throw new Exception("發票日期不可空白!!");
                            string msg = "發票日期不可空白!!";
                            return(BadRequest(msg));
                        }
                        // check vendor from ERP
                        if (keepCost.VendorId == null)
                        {
                            string msg = "廠商尚未選擇!!";
                            return(BadRequest(msg));
                        }
                        else
                        {
                            if (kdtl != null)
                            {
                                if (kdtl.NotInExceptDevice == "N")  //非統包
                                {
                                    // Do nothing.
                                }
                                else
                                {
                                    var vendor      = _context.BMEDVendors.Find(keepCost.VendorId);
                                    var checkResult = await new ERPVendors().CheckERPVendorAsync(vendor.UniteNo, vendor.VendorName);
                                    if (checkResult != null)
                                    {
                                        keepCost.ERPVendorId = checkResult;
                                    }
                                    else
                                    {
                                        string msg = "於ERP系統查無此廠商!!";
                                        return(BadRequest(msg));
                                    }
                                }
                            }
                            else
                            {
                                var vendor      = _context.BMEDVendors.Find(keepCost.VendorId);
                                var checkResult = await new ERPVendors().CheckERPVendorAsync(vendor.UniteNo, vendor.VendorName);
                                if (checkResult != null)
                                {
                                    keepCost.ERPVendorId = checkResult;
                                }
                                else
                                {
                                    string msg = "於ERP系統查無此廠商!!";
                                    return(BadRequest(msg));
                                }
                            }
                        }
                        int i = _context.BMEDTicketDtls.Where(d => d.TicketDtlNo == keepCost.TicketDtl.TicketDtlNo)
                                .Select(d => d.SeqNo).DefaultIfEmpty().Max();
                        keepCost.TicketDtl.SeqNo   = i + 1;
                        keepCost.TicketDtl.ObjName = keepCost.PartName;
                        keepCost.TicketDtl.Qty     = keepCost.Qty;
                        keepCost.TicketDtl.Unite   = keepCost.Unite;
                        keepCost.TicketDtl.Price   = keepCost.Price;
                        keepCost.TicketDtl.Cost    = keepCost.TotalCost;
                        TicketModel t = _context.BMEDTickets.Find(keepCost.TicketDtl.TicketDtlNo);
                        if (t == null)
                        {
                            t            = new TicketModel();
                            t.TicketNo   = keepCost.TicketDtl.TicketDtlNo;
                            t.TicDate    = keepCost.AccountDate;
                            t.ApplyDate  = null;
                            t.CancelDate = null;
                            t.VendorId   = keepCost.VendorId;
                            t.VendorName = keepCost.VendorName;
                            keepCost.TicketDtl.Ticket = t;
                            _context.BMEDTickets.Add(t);
                        }
                        _context.BMEDTicketDtls.Add(keepCost.TicketDtl);
                    }
                    else
                    {
                        keepCost.AccountDate = keepCost.AccountDate == null ? DateTime.Now.Date : keepCost.AccountDate;
                        keepCost.TicketDtl   = null;
                    }
                    keepCost.Rtp = ur.Id;
                    keepCost.Rtt = DateTime.Now;
                    if (keepCost.StockType != "0")
                    {
                        if (kdtl.NotInExceptDevice == "N") //非統包
                        {
                            keepCost.PartNo = "";
                        }
                    }

                    _context.BMEDKeepCosts.Add(keepCost);
                    _context.SaveChanges();
                    //
                    KeepDtlModel dtl = _context.BMEDKeepDtls.Where(d => d.DocId == keepCost.DocId)
                                       .FirstOrDefault();
                    if (dtl != null)
                    {
                        dtl.Cost = _context.BMEDKeepCosts.Where(k => k.DocId == keepCost.DocId)
                                   .Select(k => k.TotalCost)
                                   .DefaultIfEmpty(0).Sum();
                        _context.Entry(dtl).State = EntityState.Modified;
                        _context.SaveChanges();
                    }

                    return(ViewComponent("BMEDKeepCostList", new { id = keepCost.DocId, viewType = "Edit" }));
                }
                catch (Exception e)
                {
                    throw new Exception(e.Message);
                }
            }
            else
            {
                string msg = "";
                foreach (var error in ViewData.ModelState.Values.SelectMany(modelState => modelState.Errors))
                {
                    msg += error.ErrorMessage + Environment.NewLine;
                }
                throw new Exception(msg);
            }
        }
Exemplo n.º 10
0
        public async Task <IActionResult> NextFlow(AssignModel assign)
        {
            var ur = _userRepo.Find(u => u.UserName == this.User.Identity.Name).FirstOrDefault();

            /* 工程師的流程控管 */
            if (assign.Cls == "設備工程師")
            {
                /* 如點選有費用、卻無輸入費用明細 */
                var isCharged = _context.BMEDKeepDtls.Where(d => d.DocId == assign.DocId).FirstOrDefault().IsCharged;
                if (isCharged == "Y")
                {
                    var CheckRepairCost = _context.BMEDKeepCosts.Where(c => c.DocId == assign.DocId).FirstOrDefault();
                    if (CheckRepairCost == null)
                    {
                        throw new Exception("尚未輸入費用明細!!");
                    }
                }
            }

            if (assign.FlowCls == "結案" || assign.FlowCls == "廢除")
            {
                assign.FlowUid = ur.Id;
            }
            if (ModelState.IsValid)
            {
                KeepFlowModel kf = _context.BMEDKeepFlows.Where(f => f.DocId == assign.DocId && f.Status == "?").FirstOrDefault();
                if (assign.FlowCls == "驗收人")
                {
                    if (_context.BMEDKeepEmps.Where(emp => emp.DocId == assign.DocId).Count() <= 0)
                    {
                        throw new Exception("沒有維修工程師紀錄!!");
                    }
                    else if (_context.BMEDKeepDtls.Find(assign.DocId).EndDate == null)
                    {
                        throw new Exception("沒有完工日!!");
                    }
                    if (_context.BMEDKeepDtls.Find(assign.DocId).Result == null)
                    {
                        throw new Exception("保養結果不可空白!!");
                    }
                    if (string.IsNullOrEmpty(_context.BMEDKeepDtls.Find(assign.DocId).InOut))
                    {
                        throw new Exception("保養方式不可空白!!");
                    }
                }
                if (assign.FlowCls == "結案")
                {
                    KeepDtlModel kd = _context.BMEDKeepDtls.Find(assign.DocId);
                    kd.CloseDate             = DateTime.Now;
                    kf.Opinions              = "[" + assign.AssignCls + "]" + Environment.NewLine + assign.AssignOpn;
                    kf.Status                = "2";
                    kf.UserId                = ur.Id;
                    kf.UserName              = _context.AppUsers.Find(ur.Id).FullName;
                    kf.Rtt                   = DateTime.Now;
                    kf.Rtp                   = ur.Id;
                    _context.Entry(kf).State = EntityState.Modified;
                    _context.Entry(kd).State = EntityState.Modified;

                    _context.SaveChanges();
                    // Save stock to ERP system.
                    //var ERPreponse = await SaveToERPAsync(assign.DocId);

                    //Send Mail
                    //To all users in this keep's flow.
                    Tmail        mail = new Tmail();
                    string       body = "";
                    string       sto  = "";
                    AppUserModel u;
                    KeepModel    keep = _context.BMEDKeeps.Find(assign.DocId);
                    mail.from = new System.Net.Mail.MailAddress(ur.Email); //u.Email
                    _context.BMEDKeepFlows.Where(f => f.DocId == assign.DocId)
                    .ToList()
                    .ForEach(f =>
                    {
                        u    = _context.AppUsers.Find(f.UserId);
                        sto += u.Email + ",";
                    });
                    mail.sto = sto.TrimEnd(new char[] { ',' });

                    mail.message.Subject = "醫工工務智能保修系統[醫工保養案-結案通知]:設備名稱: " + keep.AssetName;
                    body += "<p>表單編號:" + keep.DocId + "</p>";
                    body += "<p>送單日期:" + keep.SentDate.Value.ToString("yyyy/MM/dd") + "</p>";
                    body += "<p>申請人:" + keep.UserName + "</p>";
                    body += "<p>財產編號:" + keep.AssetNo + "</p>";
                    body += "<p>設備名稱:" + keep.AssetName + "</p>";
                    body += "<p>放置地點:" + keep.PlaceLoc + "</p>";
                    body += "<p>保養結果:" + kd.Result + "</p>";
                    body += "<p>保養描述:" + kd.Memo + "</p>";
                    body += "<p><a href='http://dms.cch.org.tw/EDIS/Account/Login'" + "?DocId=" + keep.DocId + "&dealType=BMEDKeepViews" + ">檢視案件</a></p>";
                    body += "<br/>";
                    body += "<h3>此封信件為系統通知郵件,請勿回覆。</h3>";
                    body += "<br/>";
                    //body += "<h3 style='color:red'>如有任何疑問請聯絡工務部,分機3033或7033。<h3>";
                    mail.message.Body       = body;
                    mail.message.IsBodyHtml = true;
                    mail.SendMail();
                }
                else if (assign.FlowCls == "廢除")
                {
                    kf.Opinions = "[廢除]" + Environment.NewLine + assign.AssignOpn;
                    kf.Status   = "3";
                    kf.Rtt      = DateTime.Now;
                    kf.Rtp      = ur.Id;
                    _context.Entry(kf).State = EntityState.Modified;
                    _context.SaveChanges();
                }
                else
                {
                    //轉送下一關卡
                    kf.Opinions = "[" + assign.AssignCls + "]" + Environment.NewLine + assign.AssignOpn;
                    kf.Status   = "1";
                    kf.Rtt      = DateTime.Now;
                    kf.Rtp      = ur.Id;
                    _context.Entry(kf).State = EntityState.Modified;
                    _context.SaveChanges();
                    //
                    KeepFlowModel flow = new KeepFlowModel();
                    flow.DocId    = assign.DocId;
                    flow.StepId   = kf.StepId + 1;
                    flow.UserId   = assign.FlowUid.Value;
                    flow.UserName = _context.AppUsers.Find(assign.FlowUid.Value).FullName;
                    flow.Status   = "?";
                    flow.Cls      = assign.FlowCls;
                    flow.Rtt      = DateTime.Now;
                    _context.BMEDKeepFlows.Add(flow);
                    _context.SaveChanges();

                    //Send Mail
                    //To user and the next flow user.
                    Tmail        mail = new Tmail();
                    string       body = "";
                    AppUserModel u;
                    KeepModel    keep = _context.BMEDKeeps.Find(assign.DocId);
                    mail.from = new System.Net.Mail.MailAddress(ur.Email); //ur.Email
                    u         = _context.AppUsers.Find(flow.UserId);
                    mail.to   = new System.Net.Mail.MailAddress(u.Email);  //u.Email
                                                                           //mail.cc = new System.Net.Mail.MailAddress("*****@*****.**");
                    mail.message.Subject = "醫工工務智能保修系統[醫工保養案]:設備名稱: " + keep.AssetName;
                    body += "<p>表單編號:" + keep.DocId + "</p>";
                    body += "<p>送單日期:" + keep.SentDate.Value.ToString("yyyy/MM/dd") + "</p>";
                    body += "<p>申請人:" + keep.UserName + "</p>";
                    body += "<p>財產編號:" + keep.AssetNo + "</p>";
                    body += "<p>設備名稱:" + keep.AssetName + "</p>";
                    body += "<p>放置地點:" + keep.PlaceLoc + "</p>";
                    body += "<p><a href='http://dms.cch.org.tw/EDIS/Account/Login'" + "?docId=" + keep.DocId + "&dealType=BMEDKeepEdit" + ">處理案件</a></p>";
                    body += "<br/>";
                    body += "<h3>此封信件為系統通知郵件,請勿回覆。</h3>";
                    body += "<br/>";
                    //body += "<h3 style='color:red'>如有任何疑問請聯絡工務部,分機3033或7033。<h3>";
                    mail.message.Body       = body;
                    mail.message.IsBodyHtml = true;
                    mail.SendMail();
                }

                return(new JsonResult(assign)
                {
                    Value = new { success = true, error = "" }
                });
            }
            else
            {
                string msg = "";
                foreach (var error in ViewData.ModelState.Values.SelectMany(modelState => modelState.Errors))
                {
                    msg += error.ErrorMessage + Environment.NewLine;
                }
                throw new Exception(msg);
            }
        }
Exemplo n.º 11
0
        public async Task <IViewComponentResult> InvokeAsync(string id)
        {
            var ur = _userRepo.Find(us => us.UserName == this.User.Identity.Name).FirstOrDefault();

            // InOut dropdown list's items.
            List <SelectListItem> listItem1 = new List <SelectListItem>();

            listItem1.Add(new SelectListItem {
                Text = "自行", Value = "0"
            });
            listItem1.Add(new SelectListItem {
                Text = "委外", Value = "1"
            });
            listItem1.Add(new SelectListItem {
                Text = "租賃", Value = "2"
            });
            listItem1.Add(new SelectListItem {
                Text = "保固", Value = "3"
            });
            ViewData["InOut"] = new SelectList(listItem1, "Value", "Text", "");

            // Result dropdown list's items.
            List <SelectListItem> listItem2 = new List <SelectListItem>();

            _context.BMEDKeepResults.Where(d => d.Flg == "Y")
            .ToList()
            .ForEach(d => {
                listItem2.Add(new SelectListItem {
                    Text = d.Title, Value = d.Id.ToString()
                });
            });
            ViewData["Result"] = new SelectList(listItem2, "Value", "Text", "");

            if (id == null)
            {
                KeepDtlModel dtl = new KeepDtlModel();
                dtl.IsCharged = "N";
                return(View(dtl));
            }

            KeepDtlModel  keepDtl = _context.BMEDKeepDtls.Find(id);
            KeepFlowModel kf      = _context.BMEDKeepFlows.Where(f => f.DocId == id)
                                    .Where(f => f.Status == "?").FirstOrDefault();

            /* Get CheckerName from Repair table. */
            var checkerId = _context.BMEDKeeps.Find(id).CheckerId;

            keepDtl.CheckerName = checkerId == 0 ? "" : _context.AppUsers.Find(checkerId).FullName;

            var isEngineer = _context.UsersInRoles.Where(u => u.AppRoles.RoleName == "MedEngineer" &&
                                                         u.UserId == ur.Id).FirstOrDefault();

            if (kf.Cls.Contains("工程師") && kf.UserId == ur.Id)  /* 流程 => 工程師,Login User => 負責之工程師 */
            {
                return(View(keepDtl));
            }
            else if (kf.Cls.Contains("工程師") && isEngineer != null)  /* 流程 => 工程師,Login User => 非負責之工程師 */
            {
                return(View(keepDtl));
            }
            else  /* 流程 => 其他 */
            {
                switch (keepDtl.InOut)
                {
                case "0":
                    keepDtl.InOut = "自行";
                    break;

                case "1":
                    keepDtl.InOut = "委外";
                    break;

                case "2":
                    keepDtl.InOut = "租賃";
                    break;

                case "3":
                    keepDtl.InOut = "保固";
                    break;
                }
                keepDtl.ResultTitle = keepDtl.Result == null ? "" : _context.BMEDKeepResults.Find(keepDtl.Result).Title;
                return(View("Details", keepDtl));
            }
        }
Exemplo n.º 12
0
        public IActionResult Edit2(KeepCostModel keepCost)
        {
            var ur = _userRepo.Find(u => u.UserName == this.User.Identity.Name).FirstOrDefault();

            if (keepCost.StockType == "3")
            {
                ModelState.Remove("TicketDtl.SeqNo");
            }
            if (ModelState.IsValid)
            {
                if (keepCost.StockType != "3")
                {
                    TicketModel t = _context.Tickets.Find(keepCost.TicketDtl.TicketDtlNo);
                    if (t == null)
                    {
                        t            = new TicketModel();
                        t.TicketNo   = keepCost.TicketDtl.TicketDtlNo;
                        t.TicDate    = keepCost.AccountDate;
                        t.ApplyDate  = null;
                        t.CancelDate = null;
                        t.VendorId   = keepCost.VendorId;
                        t.VendorName = keepCost.VendorName;
                        keepCost.TicketDtl.Ticket = t;
                        _context.Tickets.Add(t);
                    }

                    TicketDtlModel ticketDtl = _context.TicketDtls.Find(keepCost.TicketDtl.TicketDtlNo, keepCost.TicketDtl.SeqNo);
                    if (ticketDtl == null)
                    {
                        int i = _context.TicketDtls.Where(d => d.TicketDtlNo == keepCost.TicketDtl.TicketDtlNo)
                                .Select(d => d.SeqNo).DefaultIfEmpty().Max();
                        keepCost.TicketDtl.SeqNo   = i + 1;
                        keepCost.TicketDtl.ObjName = keepCost.PartName;
                        keepCost.TicketDtl.Qty     = keepCost.Qty;
                        keepCost.TicketDtl.Unite   = keepCost.Unite;
                        keepCost.TicketDtl.Price   = keepCost.Price;
                        keepCost.TicketDtl.Cost    = keepCost.TotalCost;
                        _context.TicketDtls.Add(keepCost.TicketDtl);
                    }
                    else
                    {
                        ticketDtl.ObjName = keepCost.PartName;
                        ticketDtl.Qty     = keepCost.Qty;
                        ticketDtl.Unite   = keepCost.Unite;
                        ticketDtl.Price   = keepCost.Price;
                        ticketDtl.Cost    = keepCost.TotalCost;
                        _context.Entry(ticketDtl).State = EntityState.Modified;
                    }
                }

                keepCost.Rtp = ur.Id;
                keepCost.Rtt = DateTime.Now;
                _context.Entry(keepCost).State = EntityState.Modified;
                _context.SaveChanges();

                KeepDtlModel dtl = _context.KeepDtls.Where(d => d.DocId == keepCost.DocId)
                                   .FirstOrDefault();
                if (dtl != null)
                {
                    dtl.Cost = _context.KeepCosts.Where(k => k.DocId == keepCost.DocId)
                               .Select(k => k.TotalCost)
                               .DefaultIfEmpty(0).Sum();
                    _context.Entry(dtl).State = EntityState.Modified;
                    _context.SaveChanges();
                }

                return(RedirectToAction("Edit", "Keep", new { Area = "", id = keepCost.DocId, page = 5 }));
            }
            if (keepCost.StockType == "0")
            {
                ViewData["StockType"] = "庫存";
            }
            else if (keepCost.StockType == "2")
            {
                ViewData["StockType"] = "發票(含收據)";
            }
            else if (keepCost.StockType == "4")
            {
                ViewData["StockType"] = "零用金";
            }
            else
            {
                ViewData["StockType"] = "簽單";
            }
            return(View(keepCost));
        }
Exemplo n.º 13
0
        public async Task <IViewComponentResult> InvokeAsync(string id)
        {
            /* Get repair and flow details. */
            KeepModel     keep     = _context.BMEDKeeps.Find(id);
            KeepDtlModel  keepDtl  = _context.BMEDKeepDtls.Find(id);
            KeepFlowModel keepFlow = _context.BMEDKeepFlows.Where(f => f.DocId == id && f.Status == "?")
                                     .FirstOrDefault();

            List <SelectListItem> listItem = new List <SelectListItem>();

            listItem.Add(new SelectListItem {
                Text = "申請人", Value = "申請人"
            });
            listItem.Add(new SelectListItem {
                Text = "驗收人", Value = "驗收人"
            });
            listItem.Add(new SelectListItem {
                Text = "單位主管", Value = "單位主管"
            });
            //listItem.Add(new SelectListItem { Text = "維修工程師", Value = "維修工程師" });
            listItem.Add(new SelectListItem {
                Text = "設備工程師", Value = "設備工程師"
            });
            listItem.Add(new SelectListItem {
                Text = "賀康主管", Value = "賀康主管"
            });
            //總、分院不同關卡
            if (keep.Loc == "總院")
            {
                listItem.Add(new SelectListItem {
                    Text = "醫工主管", Value = "醫工主管"
                });
            }
            else
            {
                listItem.Add(new SelectListItem {
                    Text = "醫工分院主管", Value = "醫工分院主管"
                });
                listItem.Add(new SelectListItem {
                    Text = "設備主管", Value = "設備主管"
                });
            }
            listItem.Add(new SelectListItem {
                Text = "其他", Value = "其他"
            });

            //額外流程控管 04/16
            //if (keepDtl.IsCharged == "Y" && keepDtl.NotInExceptDevice == "N")   //有費用 & 非統包
            //{
            //    var itemToRemove = listItem.SingleOrDefault(r => r.Value == "驗收人");  //移除驗收人關卡,只醫工主管可結案
            //    if (itemToRemove != null)
            //    {
            //        listItem.Remove(itemToRemove);
            //    }
            //}
            if (keepDtl.NotInExceptDevice == "N")                                    //非統包
            {
                var itemToRemove = listItem.SingleOrDefault(r => r.Value == "賀康主管"); //移除賀康主管關卡
                if (itemToRemove != null)
                {
                    listItem.Remove(itemToRemove);
                }
            }
            if (keepFlow.Cls == "驗收人" && keepDtl.IsCharged == "Y")  //有費用 & 關卡於驗收人,下一關只可給工程師
            {
                var itemToRemove = listItem.SingleOrDefault(r => r.Value == "醫工主管");
                if (itemToRemove != null)
                {
                    listItem.Remove(itemToRemove);
                }
                itemToRemove = listItem.SingleOrDefault(r => r.Value == "賀康主管");
                if (itemToRemove != null)
                {
                    listItem.Remove(itemToRemove);
                }
            }

            //Add New
            //有統包 有費用 關卡工程師
            //if (keepDtl.NotInExceptDevice == "Y" && keepFlow.Cls.Contains("工程師") && keepDtl.IsCharged == "Y")
            //{
            //    listItem.Add(new SelectListItem { Text = "賀康經辦", Value = "賀康經辦" });
            //    var itemToRemove = listItem.SingleOrDefault(r => r.Value == "賀康主管");  //移除賀康主管關卡
            //    if (itemToRemove != null)
            //    {
            //        listItem.Remove(itemToRemove);
            //    }
            //}

            /* Insert values. */
            AssignModel assign = new AssignModel();

            assign.DocId = id;

            /* 根據當下流程的人員做額外的流程控管 */
            if (keepFlow != null)
            {
                assign.Cls = keepFlow.Cls;

                if (keepFlow.Cls == "驗收人" || keepFlow.Cls == "醫工主管" ||
                    keepFlow.Cls == "賀康主管" || keepFlow.Cls == "設備主管")  //可結案人員
                {
                    listItem.Add(new SelectListItem {
                        Text = "結案", Value = "結案"
                    });
                }
                if (keepFlow.Cls == "驗收人" && keepDtl.IsCharged == "Y")  //有費用 & 關卡於驗收人,下一關只可給工程師
                {
                    var itemToRemove = listItem.SingleOrDefault(r => r.Value == "結案");
                    if (itemToRemove != null)
                    {
                        listItem.Remove(itemToRemove);
                    }
                }
                if (keepFlow.Cls == "驗收人")
                {
                    //2021/04/28 去除申請人
                    var itemToRemove = listItem.SingleOrDefault(r => r.Value == "申請人");
                    if (itemToRemove != null)
                    {
                        listItem.Remove(itemToRemove);
                    }
                }
                //無費用時單位主管可結案
                if (keepFlow.Cls == "單位主管")
                {
                    if (keepDtl != null)
                    {
                        if (keepDtl.IsCharged == "N")
                        {
                            listItem.Add(new SelectListItem {
                                Text = "結案", Value = "結案"
                            });
                        }
                    }
                }
            }
            ViewData["FlowCls"] = new SelectList(listItem, "Value", "Text", "");

            List <SelectListItem> listItem3 = new List <SelectListItem>();

            listItem3.Add(new SelectListItem {
                Text = "", Value = ""
            });
            ViewData["FlowUid"] = new SelectList(listItem3, "Value", "Text", "");

            assign.Hint = "申請者→負責工程師→使用單位→(若有費用)負責工程師→[醫工部主管、賀康主管]→結案";

            return(View(assign));
        }