Пример #1
0
        public JsonResult DeleteContent(int id)
        {
            BaseJsonData json = new BaseJsonData();

            if (!User.Identity.IsAuthenticated)
            {
                json.msg_code = "nologin";
                goto next;
            }
            Reimbursement_Content content = db.Reimbursement_Content.Find(id);

            if (content == null)
            {
                json.msg_code = "nodate";
                json.msg_text = "报销内容不存在或被删除。";
                goto next;
            }
            Reimbursement bill = db.Reimbursement.Find(content.c_reimbursement_code);

            if (bill != null)
            {
                int user = Common.PageValidate.FilterParam(User.Identity.Name);
                if (user != bill.r_add_user_id)
                {
                    json.msg_code = "forbidden";
                    json.msg_text = "没有权限操作他人申请的报销单。";
                    goto next;
                }
                if (bill.r_bill_state == 1)
                {
                    json.msg_code = "forbidden";
                    json.msg_text = "已批复同意的报销单不允许删除。";
                    goto next;
                }
            }
            var details = db.Reimbursement_Detail.Where(x => x.detail_content_id == content.content_id);

            foreach (var detail in details)
            {
                db.Reimbursement_Detail.Remove(detail);
            }
            db.Reimbursement_Content.Remove(content);
            try
            {
                db.SaveChanges();
            }
            catch (Exception e)
            {
                ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().Name);
                json.msg_code = "error";
                json.msg_text = "报销单删除失败。";
                goto next;
            }
            json.state    = 1;
            json.msg_code = "success";
next:
            return(Json(json, JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        public JsonResult Create(ApplyListModel _sbill)
        {
            BaseJsonData json = new BaseJsonData();

            if (!User.Identity.IsAuthenticated)
            {
                json.msg_code = "nologin";
                goto next;
            }
            int user = Common.PageValidate.FilterParam(User.Identity.Name);

            SetSelect(0);
            if (ModelState.IsValid)
            {
                Reimbursement bill = new Reimbursement();
                bill.r_bill_amount      = _sbill.amount;
                bill.r_bill_state       = 0;
                bill.r_add_date         = DateTime.Now;
                bill.r_add_user_id      = user;
                bill.reimbursement_info = _sbill.info;
                var maxfa = db.Reimbursement.OrderByDescending(x => x.reimbursement_code).FirstOrDefault();
                //apply_number:年份+10001自增
                if (maxfa == null)
                {
                    bill.reimbursement_code = DateTime.Now.Year.ToString() + "10001";
                }
                else
                {
                    bill.reimbursement_code = DateTime.Now.Year.ToString() + (int.Parse(maxfa.reimbursement_code.Substring(4)) + 1);
                }
                db.Reimbursement.Add(bill);
                try
                {
                    db.SaveChanges();
                }
                catch (Exception e)
                {
                    ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                    json.msg_code = "error";
                    json.msg_text = "报销单提交失败。";
                    goto next;
                }

                StringBuilder sbErr = new StringBuilder();
                //添加报销内容
                foreach (ViewContentModel citem in _sbill.contents)
                {
                    Reimbursement_Content content = new Reimbursement_Content();
                    content.c_reimbursement_code = bill.reimbursement_code;
                    content.c_amount             = citem.amount;
                    content.c_dic_id             = citem.selectId;
                    db.Reimbursement_Content.Add(content);
                    try
                    {
                        //必需先提交更改,因为下面添加明细需要用到自动生成的ID。
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                        Delete(bill.reimbursement_code);
                        json.msg_code = "error";
                        json.msg_text = "报销单提交失败。";
                        goto next;
                    }
                    //添加明细
                    if (citem.details != null && citem.details.Count() > 0)
                    {
                        foreach (ViewDetailContent viewDetail in citem.details)
                        {
                            Reimbursement_Detail detail = new Reimbursement_Detail()
                            {
                                detail_amount     = viewDetail.amount,
                                detail_content_id = content.content_id,
                                detail_date       = DateTime.Parse(viewDetail.strDate + " 00:00"),
                                detail_info       = viewDetail.detailInfo
                            };
                            db.Reimbursement_Detail.Add(detail);
                        }
                    }
                    //添加附件
                    if (citem.attachments != null && citem.attachments.Count() > 0)
                    {
                        string attachment_path      = string.Format("{0}\\{1}\\{2}\\", MyConfiguration.GetAttachmentPath(), bill.reimbursement_code, DateTime.Now.ToString("yyyyMMdd"));
                        string attachment_temp_path = MyConfiguration.GetAttachmentTempPath();;
                        if (!Directory.Exists(attachment_path))
                        {
                            Directory.CreateDirectory(attachment_path);
                        }
                        string filePath, tempFile, saveFileName = "", storeFileName;
                        foreach (ViewAttachment item in citem.attachments)
                        {
                            try
                            {
                                saveFileName  = Path.GetFileName(item.fileName);
                                storeFileName = string.Format("{0}/{1}", DateTime.Now.ToString("yyyyMMdd"), saveFileName);
                                tempFile      = attachment_temp_path + item.fileName;
                                filePath      = string.Format("{0}{1}", attachment_path, saveFileName);
                                if (System.IO.File.Exists(filePath))
                                {
                                    System.IO.File.Delete(filePath);
                                }
                                System.IO.File.Move(tempFile, filePath);
                            }
                            catch (Exception e)
                            {
                                ErrorUnit.WriteErrorLog(e.ToString(), GetType().ToString());
                                sbErr.Append("文件【").Append(saveFileName).Append("】保存失败,请重新上传。\r\n");
                                continue;
                            }
                            Reimbursement_Attachment attachment = new Reimbursement_Attachment
                            {
                                attachment_path         = storeFileName,
                                atta_detail_id          = content.content_id,
                                atta_reimbursement_code = bill.reimbursement_code
                            };
                            db.Reimbursement_Attachment.Add(attachment);
                        }
                    }
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                        Delete(bill.reimbursement_code);
                        json.msg_code = "error";
                        json.msg_text = "报销单提交失败。";
                        goto next;
                    }
                }

                //添加其他附件
                if (_sbill.attachments != null && _sbill.attachments.Count() > 0)
                {
                    string attachment_path      = string.Format("{0}\\{1}\\{2}\\", MyConfiguration.GetAttachmentPath(), bill.reimbursement_code, DateTime.Now.ToString("yyyyMMdd"));
                    string attachment_temp_path = MyConfiguration.GetAttachmentTempPath();;
                    if (!Directory.Exists(attachment_path))
                    {
                        Directory.CreateDirectory(attachment_path);
                    }
                    string filePath, tempFile, saveFileName = "", storeFileName;
                    foreach (ViewAttachment item in _sbill.attachments)
                    {
                        try
                        {
                            saveFileName  = Path.GetFileName(item.fileName);
                            storeFileName = string.Format("{0}/{1}", DateTime.Now.ToString("yyyyMMdd"), saveFileName);
                            tempFile      = attachment_temp_path + item.fileName;
                            filePath      = string.Format("{0}{1}", attachment_path, saveFileName);
                            if (System.IO.File.Exists(filePath))
                            {
                                System.IO.File.Delete(filePath);
                            }
                            System.IO.File.Move(tempFile, filePath);
                        }
                        catch (Exception e)
                        {
                            ErrorUnit.WriteErrorLog(e.ToString(), GetType().ToString());
                            sbErr.Append("文件【").Append(saveFileName).Append("】保存失败,请重新上传。\r\n");
                            continue;
                        }
                        Reimbursement_Attachment attachment = new Reimbursement_Attachment
                        {
                            attachment_path         = storeFileName,
                            atta_detail_id          = 0,
                            atta_reimbursement_code = bill.reimbursement_code
                        };
                        db.Reimbursement_Attachment.Add(attachment);
                    }
                    try
                    {
                        db.SaveChanges();
                    }
                    catch (Exception e)
                    {
                        ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                        Delete(bill.reimbursement_code);
                        json.msg_code = "error";
                        json.msg_text = "报销单提交失败。";
                        goto next;
                    }
                }
                //添加批复人
                Process_Respond pr = new Process_Respond();
                pr.pr_reimbursement_code = bill.reimbursement_code;
                pr.pr_user_id            = _sbill.next;
                pr.pr_number             = 1;
                db.Process_Respond.Add(pr);
                try
                {
                    db.SaveChanges();
                    SysLog.WriteLog(user, string.Format("添加报帐单[{0}]", bill.reimbursement_code), IpHelper.GetIP(), bill.reimbursement_code, 4, "", db);
                }
                catch (Exception e)
                {
                    ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                    Delete(bill.reimbursement_code);
                    json.msg_code = "error";
                    json.msg_text = "报销单提交失败。";
                    goto next;
                }
                json.state    = 1;
                json.msg_code = bill.reimbursement_code;
                json.msg_text = sbErr.ToString();
            }
next:
            return(Json(json, JsonRequestBehavior.AllowGet));
        }
Пример #3
0
        public JsonResult Edit(ApplyListModel viewBill)
        {
            BaseJsonData json = new BaseJsonData();

            if (!User.Identity.IsAuthenticated)
            {
                json.msg_code = "nologin";
                goto next;
            }
            int user = Common.PageValidate.FilterParam(User.Identity.Name);

            SetSelect(0);
            if (ModelState.IsValid)
            {
                Reimbursement bill = db.Reimbursement.Find(viewBill.reimbursementCode);
                if (bill == null)
                {
                    json.msg_code = "error";
                    json.msg_text = "没有主申请单,更新失败。";
                    goto next;
                }
                if (viewBill.next == 0)
                {
                    json.msg_code = "error";
                    json.msg_text = "必需选择审核用户。";
                    goto next;
                }
                StringBuilder sbmsg = new StringBuilder();
                if (bill.r_bill_state == 1)
                {
                    json.msg_code = "error";
                    json.msg_text = "该报销单已经批复完成,不允许修改。";
                    goto next;
                }
                else
                {
                    bill.r_bill_amount      = viewBill.amount;
                    bill.r_fact_amount      = viewBill.amount;
                    bill.r_bill_state       = 0;
                    bill.r_add_date         = DateTime.Now;
                    bill.reimbursement_info = viewBill.info;
                    db.Entry(bill).State    = EntityState.Modified;
                    //录入报销事由
                    Reimbursement_Content content = null;

                    foreach (ViewContentModel citem in viewBill.contents)
                    {
                        if (citem.contentId != null && citem.contentId != 0)
                        {
                            content = db.Reimbursement_Content.Find(citem.contentId);
                            if (content != null)
                            {
                                content.c_amount        = citem.amount;
                                db.Entry(content).State = EntityState.Modified;
                            }
                        }
                        else
                        {
                            content = new Reimbursement_Content();
                            content.c_reimbursement_code = bill.reimbursement_code;
                            content.c_dic_id             = citem.selectId;
                            content.c_amount             = citem.amount;
                            db.Reimbursement_Content.Add(content);
                        }

                        try
                        {
                            db.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                            sbmsg.Append("报销内容录入失败<br />");
                            continue;
                        }

                        //录入明细
                        if (citem.details != null && citem.details.Count() > 0)
                        {
                            Reimbursement_Detail detail = null;
                            foreach (ViewDetailContent item in citem.details)
                            {
                                if (item.detailId != null && item.detailId != 0)
                                {
                                    detail = db.Reimbursement_Detail.Find(item.detailId);
                                }
                                else
                                {
                                    detail = new Reimbursement_Detail();
                                    detail.detail_content_id = content.content_id;
                                }
                                detail.detail_amount     = item.amount;
                                detail.detail_date       = DateTime.Parse(item.strDate + " 00:00");
                                detail.detail_info       = item.detailInfo;
                                detail.detail_content_id = content.content_id;
                                if (item.detailId != null && item.detailId != 0)
                                {
                                    db.Entry(detail).State = EntityState.Modified;
                                }
                                else
                                {
                                    db.Reimbursement_Detail.Add(detail);
                                }
                            }
                        }
                        //录入附件
                        if (citem.attachments != null && citem.attachments.Count() > 0)
                        {
                            string attachment_path      = string.Format("{0}\\{1}\\{2}\\", MyConfiguration.GetAttachmentPath(), bill.reimbursement_code, DateTime.Now.ToString("yyyyMMdd"));
                            string attachment_temp_path = MyConfiguration.GetAttachmentTempPath();;
                            if (!Directory.Exists(attachment_path))
                            {
                                Directory.CreateDirectory(attachment_path);
                            }
                            string filePath, tempFile, saveFileName = "", storeFileName;
                            foreach (ViewAttachment item in citem.attachments)
                            {
                                if (item.id > 0)
                                {
                                    continue;
                                }
                                try
                                {
                                    saveFileName  = Path.GetFileName(item.fileName);
                                    storeFileName = string.Format("{0}/{1}", DateTime.Now.ToString("yyyyMMdd"), saveFileName);
                                    tempFile      = attachment_temp_path + item.fileName;
                                    filePath      = string.Format("{0}{1}", attachment_path, saveFileName);
                                    if (System.IO.File.Exists(filePath))
                                    {
                                        System.IO.File.Delete(filePath);
                                    }
                                    System.IO.File.Move(tempFile, filePath);
                                }
                                catch (Exception e)
                                {
                                    ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                                    sbmsg.Append("文件【").Append(item.fileName).Append("】保存失败,请重新上传");
                                    continue;
                                }
                                Reimbursement_Attachment attachment = new Reimbursement_Attachment
                                {
                                    attachment_path         = storeFileName,
                                    atta_detail_id          = (int)citem.contentId,
                                    atta_reimbursement_code = bill.reimbursement_code
                                };
                                db.Reimbursement_Attachment.Add(attachment);
                            }
                        }

                        try
                        {
                            db.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                            sbmsg.Append("报销明细录入失败<br />");
                            continue;
                        }
                    }
                    //录入附件
                    if (viewBill.attachments != null && viewBill.attachments.Count() > 0)
                    {
                        string attachment_path      = string.Format("{0}\\{1}\\{2}\\", MyConfiguration.GetAttachmentPath(), bill.reimbursement_code, DateTime.Now.ToString("yyyyMMdd"));
                        string attachment_temp_path = MyConfiguration.GetAttachmentTempPath();;
                        if (!Directory.Exists(attachment_path))
                        {
                            Directory.CreateDirectory(attachment_path);
                        }
                        string filePath, tempFile, saveFileName = "", storeFileName;
                        foreach (ViewAttachment item in viewBill.attachments)
                        {
                            if (item.id > 0)
                            {
                                continue;
                            }
                            try
                            {
                                saveFileName  = Path.GetFileName(item.fileName);
                                storeFileName = string.Format("{0}/{1}", DateTime.Now.ToString("yyyyMMdd"), saveFileName);
                                tempFile      = attachment_temp_path + item.fileName;
                                filePath      = string.Format("{0}{1}", attachment_path, saveFileName);
                                if (System.IO.File.Exists(filePath))
                                {
                                    System.IO.File.Delete(filePath);
                                }
                                System.IO.File.Move(tempFile, filePath);
                            }
                            catch (Exception e)
                            {
                                ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                                sbmsg.Append("文件【").Append(item.fileName).Append("】保存失败,请重新上传");
                                continue;
                            }
                            Reimbursement_Attachment attachment = new Reimbursement_Attachment
                            {
                                attachment_path         = storeFileName,
                                atta_detail_id          = 0,
                                atta_reimbursement_code = bill.reimbursement_code
                            };
                            db.Reimbursement_Attachment.Add(attachment);
                        }
                        try
                        {
                            //干脆都先提交得了
                            db.SaveChanges();
                        }
                        catch (Exception e)
                        {
                            ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                            Delete(bill.reimbursement_code);
                            json.msg_code = "error";
                            json.msg_text = "报销单附件提交失败。";
                            goto next;
                        }
                    }
                    //录入批复流程
                    db.Process_Respond.RemoveRange(db.Process_Respond.Where(x => x.pr_reimbursement_code == bill.reimbursement_code));
                    //添加批复人
                    Process_Respond pr = new Process_Respond();
                    pr.pr_reimbursement_code = bill.reimbursement_code;
                    pr.pr_user_id            = viewBill.next;
                    pr.pr_number             = 1;
                    db.Process_Respond.Add(pr);
                    try
                    {
                        db.SaveChanges();
                        SysLog.WriteLog(user, string.Format("修改报帐单[{0}]", bill.reimbursement_code), IpHelper.GetIP(), bill.reimbursement_code, 4, "", db);
                    }
                    catch (Exception e)
                    {
                        ErrorUnit.WriteErrorLog(e.ToString(), this.GetType().ToString());
                        Delete(bill.reimbursement_code);
                        json.msg_code = "error";
                        json.msg_text = "报销单提交失败。";
                        goto next;
                    }
                }
                json.state    = 1;
                json.msg_code = bill.reimbursement_code;
                json.msg_text = sbmsg.ToString();
            }
next:
            return(Json(json, JsonRequestBehavior.AllowGet));
        }