Exemplo n.º 1
0
 public ActionResult Delete(string docid, string seqno)
 {
     try
     {
         RepairCostModel repairCost = _context.BMEDRepairCosts.Find(docid, Convert.ToInt32(seqno));
         _context.BMEDRepairCosts.Remove(repairCost);
         _context.SaveChanges();
         //
         RepairDtlModel dtl = _context.BMEDRepairDtls.Where(d => d.DocId == repairCost.DocId)
                              .FirstOrDefault();
         if (dtl != null)
         {
             dtl.Cost = _context.BMEDRepairCosts.Where(k => k.DocId == repairCost.DocId)
                        .Select(k => k.TotalCost)
                        .DefaultIfEmpty(0).Sum();
             _context.Entry(dtl).State = EntityState.Modified;
             _context.SaveChanges();
         }
         return(new JsonResult(repairCost)
         {
             Value = new { success = true, error = "" }
         });
     }
     catch (Exception e)
     {
         throw new Exception(e.Message);
     }
 }
Exemplo n.º 2
0
        public async Task <IViewComponentResult> InvokeAsync(string id)
        {
            RepairCostModel cost = new RepairCostModel();
            var             ur   = _userRepo.Find(u => u.UserName == this.User.Identity.Name).FirstOrDefault();

            /* Check the device's contract. */
            var repairDtl = _context.BMEDRepairDtls.Find(id);

            if (repairDtl.NotInExceptDevice == "Y") //該案件為統包
            {
                ViewData["HideCost"] = "Y";
            }
            else
            {
                ViewData["HideCost"] = "N";
            }

            int seqno = _context.BMEDRepairCosts.Where(c => c.DocId == id)
                        .Select(c => c.SeqNo).DefaultIfEmpty().Max();

            cost.DocId = id;
            cost.Qty   = 1; //Default value.
            cost.SeqNo = seqno + 1;
            RepairFlowModel rf = _context.BMEDRepairFlows.Where(f => f.DocId == id)
                                 .Where(f => f.Status == "?").FirstOrDefault();
            var isEngineer = false;

            if (ur.DptId == "8420" || ur.DptId == "7084")
            {
                isEngineer = true;
            }
            if (!(rf.Cls.Contains("工程師") && rf.UserId == ur.Id))    /* 流程 => 其他 */
            {
                if (rf.Cls.Contains("工程師") && isEngineer == true)   /* 流程 => 工程師,Login User => 非負責之工程師 */
                {
                    return(View(cost));
                }
                if (rf.Cls.Contains("醫工主管") || rf.Cls.Contains("賀康主管")) /* 流程 => 醫工、賀康主管 */
                {
                    if (rf.UserId == ur.Id)
                    {
                        return(View(cost));
                    }
                }
                List <RepairCostModel> t = _context.BMEDRepairCosts.Include(r => r.TicketDtl).Where(c => c.DocId == id).ToList();
                return(View("List", t));
            }
            /* 流程 => 工程師,Login User => 負責之工程師 */
            return(View(cost));
        }
Exemplo n.º 3
0
        public IActionResult RepCostEdit(RepairCostModel repairCost)
        {
            var ur = _userRepo.Find(u => u.UserName == this.User.Identity.Name).FirstOrDefault();

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

                RepairDtlModel dtl = _context.RepairDtls.Where(d => d.DocId == repairCost.DocId)
                                     .FirstOrDefault();
                if (dtl != null)
                {
                    dtl.Cost = _context.RepairCosts.Where(k => k.DocId == repairCost.DocId)
                               .Select(k => k.TotalCost)
                               .DefaultIfEmpty(0).Sum();
                    _context.Entry(dtl).State = EntityState.Modified;
                    _context.SaveChanges();
                }

                return(new JsonResult(repairCost)
                {
                    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.º 4
0
        // GET: RepairCost/Edit2
        public IActionResult Edit2(string docid, string seqno)
        {
            RepairCostModel repairCost = _context.RepairCosts.Include(rc => rc.TicketDtl)
                                         .SingleOrDefault(rc => rc.DocId == docid && rc.SeqNo == Convert.ToInt32(seqno));

            if (repairCost.StockType == "0")
            {
                ViewData["StockType"] = "庫存";
            }
            else if (repairCost.StockType == "2")
            {
                ViewData["StockType"] = "發票(含收據)";
            }
            else if (repairCost.StockType == "4")
            {
                ViewData["StockType"] = "零用金";
            }
            else
            {
                ViewData["StockType"] = "簽單";
            }

            return(View(repairCost));
        }
Exemplo n.º 5
0
        public IActionResult Edit(RepairCostModel repairCost)
        {
            var ur = _userRepo.Find(u => u.UserName == this.User.Identity.Name).FirstOrDefault();

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

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

                    int seqno = _context.BMEDRepairCosts.Where(c => c.DocId == repairCost.DocId)
                                .Select(c => c.SeqNo).DefaultIfEmpty().Max();
                    repairCost.SeqNo = seqno + 1;
                    if (repairCost.StockType == "2")
                    {
                        if (string.IsNullOrEmpty(repairCost.TicketDtl.TicketDtlNo))
                        {
                            //throw new Exception("發票號碼不可空白!!");
                            string msg = "發票號碼不可空白!!";
                            return(BadRequest(msg));
                        }
                        if (repairCost.AccountDate == null)
                        {
                            //throw new Exception("發票日期不可空白!!");
                            string msg = "發票日期不可空白!!";
                            return(BadRequest(msg));
                        }
                        int i = _context.BMEDTicketDtls.Where(d => d.TicketDtlNo == repairCost.TicketDtl.TicketDtlNo)
                                .Select(d => d.SeqNo).DefaultIfEmpty().Max();
                        repairCost.TicketDtl.SeqNo   = i + 1;
                        repairCost.TicketDtl.ObjName = repairCost.PartName;
                        repairCost.TicketDtl.Qty     = repairCost.Qty;
                        repairCost.TicketDtl.Unite   = repairCost.Unite;
                        repairCost.TicketDtl.Price   = repairCost.Price;
                        repairCost.TicketDtl.Cost    = repairCost.TotalCost;
                        TicketModel t = _context.BMEDTickets.Find(repairCost.TicketDtl.TicketDtlNo);
                        if (t == null)
                        {
                            t            = new TicketModel();
                            t.TicketNo   = repairCost.TicketDtl.TicketDtlNo;
                            t.TicDate    = repairCost.AccountDate;
                            t.ApplyDate  = null;
                            t.CancelDate = null;
                            t.VendorId   = repairCost.VendorId;
                            t.VendorName = repairCost.VendorName;
                            repairCost.TicketDtl.Ticket = t;
                            _context.BMEDTickets.Add(t);
                        }
                        _context.BMEDTicketDtls.Add(repairCost.TicketDtl);
                    }
                    else
                    {
                        repairCost.AccountDate = repairCost.AccountDate == null ? DateTime.Now.Date : repairCost.AccountDate;
                        repairCost.TicketDtl   = null;
                    }
                    repairCost.Rtp = ur.Id;
                    repairCost.Rtt = DateTime.Now;
                    if (repairCost.StockType != "0")
                    {
                        repairCost.PartNo = "";
                    }

                    _context.BMEDRepairCosts.Add(repairCost);
                    _context.SaveChanges();
                    //
                    RepairDtlModel dtl = _context.BMEDRepairDtls.Where(d => d.DocId == repairCost.DocId)
                                         .FirstOrDefault();
                    if (dtl != null)
                    {
                        dtl.Cost = _context.BMEDRepairCosts.Where(k => k.DocId == repairCost.DocId)
                                   .Select(k => k.TotalCost)
                                   .DefaultIfEmpty(0).Sum();
                        _context.Entry(dtl).State = EntityState.Modified;
                        _context.SaveChanges();
                    }

                    return(ViewComponent("BMEDRepCostList", new { id = repairCost.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);
            }
        }
        public async Task <IViewComponentResult> InvokeAsync(string id)
        {
            RepairCostModel cost = new RepairCostModel();
            var             ur   = _userRepo.Find(u => u.UserName == this.User.Identity.Name).FirstOrDefault();

            int seqno = _context.RepairCosts.Where(c => c.DocId == id)
                        .Select(c => c.SeqNo).DefaultIfEmpty().Max();

            cost.DocId = id;
            cost.SeqNo = seqno + 1;
            RepairFlowModel rf = _context.RepairFlows.Where(f => f.DocId == id)
                                 .Where(f => f.Status == "?").FirstOrDefault();
            var isEngineer = _context.UsersInRoles.Where(u => u.AppRoles.RoleName == "RepEngineer" &&
                                                         u.UserId == ur.Id).FirstOrDefault();

            /* 查無處理中流程 => 已結案 或 已廢除 */
            if (rf == null)
            {
                /* Role => 工務經辦 or Admin */
                if (userManager.IsInRole(this.UserClaimsPrincipal, "RepToDo") == true ||
                    userManager.IsInRole(this.UserClaimsPrincipal, "Admin") == true ||
                    userManager.IsInRole(this.UserClaimsPrincipal, "RepAdmin"))
                {
                    return(View(cost));
                }
            }
            if (!(rf.Cls.Contains("工程師") && rf.UserId == ur.Id))    /* 流程 => 其他 */
            {
                if (rf.Cls.Contains("工程師") && isEngineer != null)   /* 流程 => 工程師,Login User => 非負責之工程師 */
                {
                    return(View(cost));
                }
                if (userManager.IsInRole(this.UserClaimsPrincipal, "RepToDo") == true ||
                    userManager.IsInRole(this.UserClaimsPrincipal, "Admin") == true ||
                    userManager.IsInRole(this.UserClaimsPrincipal, "RepAdmin")) /* 腳色 => 工務經辦 or Admin */
                {
                    return(View(cost));
                }
                List <RepairCostModel> t = _context.RepairCosts.Include(r => r.TicketDtl)
                                           .Where(c => c.DocId == id).ToList();
                t.ForEach(r => {
                    if (r.StockType == "0")
                    {
                        r.StockType = "庫存";
                    }
                    else if (r.StockType == "2")
                    {
                        r.StockType = "發票(含收據)";
                    }
                    else if (r.StockType == "4")
                    {
                        r.StockType = "零用金";
                    }
                    else
                    {
                        r.StockType = "簽單";
                    }
                });
                return(View("Print", t));
            }
            /* 流程 => 工程師,Login User => 負責之工程師 */
            return(View(cost));
        }
Exemplo n.º 7
0
        public IActionResult Edit2(RepairCostModel repairCost)
        {
            var ur = _userRepo.Find(u => u.UserName == this.User.Identity.Name).FirstOrDefault();

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

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

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

                RepairDtlModel dtl = _context.RepairDtls.Where(d => d.DocId == repairCost.DocId)
                                     .FirstOrDefault();
                if (dtl != null)
                {
                    dtl.Cost = _context.RepairCosts.Where(k => k.DocId == repairCost.DocId)
                               .Select(k => k.TotalCost)
                               .DefaultIfEmpty(0).Sum();
                    _context.Entry(dtl).State = EntityState.Modified;
                    _context.SaveChanges();
                }

                return(RedirectToAction("Edit", "Repair", new { Area = "", id = repairCost.DocId, page = 4 }));
            }
            if (repairCost.StockType == "0")
            {
                ViewData["StockType"] = "庫存";
            }
            else if (repairCost.StockType == "2")
            {
                ViewData["StockType"] = "發票(含收據)";
            }
            else if (repairCost.StockType == "4")
            {
                ViewData["StockType"] = "零用金";
            }
            else
            {
                ViewData["StockType"] = "簽單";
            }
            return(View(repairCost));
        }