public ActionResult GetView2Insert()
        {
            try
            {
                Billing_BL          _obj_bl              = new Billing_BL();
                string              _caseCode            = _obj_bl.Billing_GenCaseCode();
                Billing_Header_Info _Billing_Header_Info = new Billing_Header_Info();
                _Billing_Header_Info.Case_Code = _caseCode;
                return(View("~/Areas/Manager/Views/Billing_Search/_PartialInsert.cshtml", _Billing_Header_Info));
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);

                Billing_Header_Info _Billing_Header_Info = new Billing_Header_Info();
                return(PartialView("~/Areas/Manager/Views/Billing_Search/_PartialInsert.cshtml", new Billing_Header_Info()));
            }
        }
Exemple #2
0
        public ActionResult DoSearchResult(SearchObject_Question_Info p_SearchObject_Header_Info, Billing_Header_Info p_Billing_Header_Info)
        {
            try
            {
                List <Billing_Detail_Info> _lst_billing_detail = AppsCommon.Get_LstFee_Detail(p_SearchObject_Header_Info.CASE_CODE);
                decimal _ck         = 0;
                decimal _billing_id = 0;
                using (var scope = new TransactionScope())
                {
                    p_SearchObject_Header_Info.LANGUAGE_CODE = AppsCommon.GetCurrentLang();
                    p_SearchObject_Header_Info.MODIFIED_BY   = SessionData.CurrentUser.Username;
                    p_SearchObject_Header_Info.MODIFIED_DATE = DateTime.Now;

                    p_SearchObject_Header_Info.FILE_URL   = AppLoadHelpers.PushFileToServer(p_SearchObject_Header_Info.FileBase_File_Url, AppUpload.Search);
                    p_SearchObject_Header_Info.FILE_URL02 = AppLoadHelpers.PushFileToServer(p_SearchObject_Header_Info.FileBase_File_Url02, AppUpload.Search);

                    SearchObject_BL _con = new SearchObject_BL();
                    _ck = _con.SEARCH_RESULT_SEARCH(p_SearchObject_Header_Info);

                    if (_ck < 0)
                    {
                        goto Commit_Transaction;
                    }

                    // insert billing
                    // lấy thông tin cũ
                    if (_lst_billing_detail.Count == 0)
                    {
                        goto Commit_Transaction;
                    }

                    SearchObject_BL            _SearchObject_BL     = new SearchObject_BL();
                    List <Billing_Detail_Info> _lst_detail          = new List <Billing_Detail_Info>();
                    SearchObject_Header_Info   objSearch_HeaderInfo = _SearchObject_BL.GetBilling_By_Case_Code(p_SearchObject_Header_Info.CASE_CODE, SessionData.CurrentUser.Username,
                                                                                                               AppsCommon.GetCurrentLang(), ref _lst_detail);

                    Billing_BL _obj_bl = new Billing_BL();
                    p_Billing_Header_Info.Created_By    = SessionData.CurrentUser.Username;
                    p_Billing_Header_Info.Created_Date  = DateTime.Now;
                    p_Billing_Header_Info.Language_Code = AppsCommon.GetCurrentLang();
                    p_Billing_Header_Info.Status        = (decimal)CommonEnums.Billing_Status.New_Wait_Approve;
                    p_Billing_Header_Info.Billing_Type  = (decimal)CommonEnums.Billing_Type.Search;
                    p_Billing_Header_Info.Notes         = "Billing for case code " + p_SearchObject_Header_Info.CASE_CODE; // + " - " + p_SearchObject_Header_Info.NOTE;

                    p_Billing_Header_Info.Case_Code     = _obj_bl.Billing_GenCaseCode();
                    p_Billing_Header_Info.App_Case_Code = p_SearchObject_Header_Info.CASE_CODE;

                    p_Billing_Header_Info.Billing_Date = DateTime.Now;
                    p_Billing_Header_Info.Deadline     = DateTime.Now.AddDays(30);

                    p_Billing_Header_Info.Request_By = SessionData.CurrentUser.Username;
                    p_Billing_Header_Info.Approve_By = "";


                    decimal _Total_Amount_Represent = 0;
                    decimal _Total_Amount_Temp      = 0;

                    decimal            _Percent_discount = 0;
                    List <AllCodeInfo> _lstDiscount      = WebApps.CommonFunction.AppsCommon.AllCode_GetBy_CdTypeCdName("DISCOUNT", "SERVICE");
                    if (_lstDiscount.Count > 0)
                    {
                        _Percent_discount = Convert.ToDecimal(_lstDiscount[0].CdVal);
                    }

                    foreach (Billing_Detail_Info item in _lst_billing_detail)
                    {
                        _Total_Amount_Represent = _Total_Amount_Represent + item.Represent_Fee;
                        _Total_Amount_Temp      = _Total_Amount_Temp + item.Total_Fee;
                    }

                    decimal _discount = Math.Round(_Total_Amount_Represent * _Percent_discount / 100);
                    p_Billing_Header_Info.Total_Pre_Tex = _Total_Amount_Temp - _discount;

                    p_Billing_Header_Info.Tex_Fee      = Math.Round(p_Billing_Header_Info.Total_Pre_Tex / 100 * Common.Common.Tax);
                    p_Billing_Header_Info.Total_Amount = p_Billing_Header_Info.Total_Pre_Tex + p_Billing_Header_Info.Tex_Fee;

                    p_Billing_Header_Info.Currency      = objSearch_HeaderInfo.Currency_Type;
                    p_Billing_Header_Info.Currency_Rate = AppsCommon.Get_Currentcy_VCB();

                    p_Billing_Header_Info.Insert_Type = (decimal)Common.CommonData.CommonEnums.Billing_Insert_Type.Search;

                    p_Billing_Header_Info.Discount_Fee_Service = _discount;
                    p_Billing_Header_Info.Percent_Discount     = _Percent_discount;
                    p_Billing_Header_Info.Currency_Rate        = AppsCommon.Get_Currentcy_VCB();

                    _billing_id = _obj_bl.Billing_Insert(p_Billing_Header_Info);

                    if (_billing_id > 0 && _lst_billing_detail.Count > 0)
                    {
                        _ck = _obj_bl.Billing_Detail_InsertBatch(_lst_billing_detail, _billing_id);
                    }

                    if (_ck > 0 && p_Billing_Header_Info.Insert_Type == (decimal)Common.CommonData.CommonEnums.Billing_Insert_Type.Search)
                    {
                        //string _fileExport = AppsCommon.Export_Billing(p_Billing_Header_Info.Case_Code);

                        string _mapPath_Report = Server.MapPath("~/Report/");
                        string _mapPath        = Server.MapPath("~/");

                        string _fileExport = AppsCommon.Export_Billing_Crytal(p_Billing_Header_Info.Case_Code, _mapPath_Report, _mapPath, objSearch_HeaderInfo.CREATED_BY, p_Billing_Header_Info, _lst_billing_detail);
                        if (_fileExport == "")
                        {
                            goto Commit_Transaction;
                        }

                        SearchObject_BL _bl = new SearchObject_BL();
                        _ck = _bl.Update_Url_Billing(p_Billing_Header_Info.App_Case_Code, _billing_id, _fileExport);

                        // insert vào docking
                        AppsCommon.Insert_Docketing(p_Billing_Header_Info.Case_Code, "Report Billing", _fileExport, true);
                    }

                    //end
Commit_Transaction:
                    if (_ck < 0)
                    {
                        Transaction.Current.Rollback();
                    }
                    else
                    {
                        SessionData.RemoveDataSession(p_SearchObject_Header_Info.CASE_CODE);
                        scope.Complete();
                    }
                }
                return(Json(new { success = _ck }));
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
                return(Json(new { success = "-1" }));
            }
        }
Exemple #3
0
        public ActionResult DoAdminConfirm(string p_case_code, decimal p_status, string p_note)
        {
            try
            {
                SearchObject_BL _con = new SearchObject_BL();

                decimal _ck = _con.Admin_Update(p_case_code, p_status, p_note, AppsCommon.GetCurrentLang(), SessionData.CurrentUser.Username);

                // nếu thành công thì gửi email cho khách hàng
                if (_ck != -1 && p_status == (decimal)CommonSearch.Stt_DaPhanHoi)
                {
                    // lấy thông tin search
                    SearchObject_BL _searchBL = new SearchObject_BL();
                    List <SearchObject_Detail_Info> _ListDetail        = new List <SearchObject_Detail_Info>();
                    SearchObject_Question_Info      _QuestionInfo      = new SearchObject_Question_Info();
                    List <AppClassDetailInfo>       search_Class_Infos = new List <AppClassDetailInfo>();
                    SearchObject_Header_Info        _HeaderInfo        = _searchBL.SEARCH_HEADER_GETBY_CASECODE(p_case_code, ref _ListDetail, ref _QuestionInfo, ref search_Class_Infos);

                    // lấy thông tin người dùng
                    UserBL   _UserBL  = new UserBL();
                    UserInfo userInfo = _UserBL.GetUserByUsername(_HeaderInfo.CREATED_BY.Trim());

                    #region Bỏ đi vì đã có trong email

                    //string _fileTemp = System.Web.HttpContext.Current.Server.MapPath("/Content/Report/Search Report.doc");
                    //if (_HeaderInfo.Customer_Country != Common.Common.Country_VietNam_Id)
                    //    _fileTemp = System.Web.HttpContext.Current.Server.MapPath("/Content/Report/Search Report_En.doc");
                    //DocumentModel document = DocumentModel.Load(_fileTemp);

                    //// Fill export_header
                    //string fileName = System.Web.HttpContext.Current.Server.MapPath("/Content/Export/" + "Search_report" + p_case_code.ToString() + ".pdf");
                    //document.MailMerge.FieldMerging += (sender, e) =>
                    //{
                    //    if (e.IsValueFound)
                    //    {
                    //        if (e.FieldName == "Text")
                    //            ((Run)e.Inline).Text = e.Value.ToString();
                    //    }
                    //};

                    //string _search_type = "";
                    //if (_ListDetail.Count > 0)
                    //{
                    //    _search_type = _ListDetail[0].SEARCH_TYPE_NAME;
                    //}

                    //document.MailMerge.Execute(new { DateNo = DateTime.Now.ToString("dd-MM-yyyy") });
                    //document.MailMerge.Execute(new { Case_Name = _HeaderInfo.CASE_NAME });
                    //document.MailMerge.Execute(new { Client_Reference = _HeaderInfo.CLIENT_REFERENCE });
                    //document.MailMerge.Execute(new { Case_Code = _HeaderInfo.CASE_CODE });
                    //document.MailMerge.Execute(new { Applicant_Name = _HeaderInfo.Customer_Name });
                    //document.MailMerge.Execute(new { Customer_Country_Name = _HeaderInfo.Customer_Country_Name });
                    //document.MailMerge.Execute(new { Object = _HeaderInfo.Object_Search_Name });
                    //document.MailMerge.Execute(new { Result = _QuestionInfo.RESULT });
                    //document.MailMerge.Execute(new { Search_Type = _search_type });

                    //if (userInfo != null)
                    //{
                    //    document.MailMerge.Execute(new { Contact_Person = userInfo.Contact_Person });
                    //    document.MailMerge.Execute(new { Address = userInfo.Address });
                    //    document.MailMerge.Execute(new { FullName = userInfo.FullName });
                    //}
                    //else
                    //{
                    //    document.MailMerge.Execute(new { Contact_Person = "" });
                    //    document.MailMerge.Execute(new { Address = "" });
                    //    document.MailMerge.Execute(new { FullName = "" });
                    //}

                    //document.Save(fileName, SaveOptions.PdfDefault);
                    //byte[] fileContents;
                    //var options = SaveOptions.PdfDefault;
                    //// Save document to DOCX format in byte array.
                    //using (var stream = new MemoryStream())
                    //{
                    //    document.Save(stream, options);
                    //    fileContents = stream.ToArray();
                    //}
                    //Convert.ToBase64String(fileContents);
                    #endregion

                    string _emailTo = userInfo.Email;
                    string _emailCC = "";
                    //string _emailCC = userInfo.Copyto;
                    List <string> _LstAttachment = new List <string>();

                    //20190812 bỏ đi vì đã gửi trong email rồi
                    //_LstAttachment.Add(fileName);

                    if (_QuestionInfo.FILE_URL != null && _QuestionInfo.FILE_URL != "")
                    {
                        _LstAttachment.Add(System.Web.HttpContext.Current.Server.MapPath(_QuestionInfo.FILE_URL));
                    }

                    if (_QuestionInfo.FILE_URL02 != null && _QuestionInfo.FILE_URL02 != "")
                    {
                        _LstAttachment.Add(System.Web.HttpContext.Current.Server.MapPath(_QuestionInfo.FILE_URL02));
                    }

                    if (_HeaderInfo.Billing_Id > 0)
                    {
                        // lấy thông tin billing
                        Billing_BL          _Billing_BL          = new Billing_BL();
                        Billing_Header_Info _Billing_Header_Info = _Billing_BL.Billing_GetBy_Id(_HeaderInfo.Billing_Id, AppsCommon.GetCurrentLang());
                        if (_Billing_Header_Info.Billing_Id > 0 && _Billing_Header_Info.Status == (decimal)CommonEnums.Billing_Status.Approved)
                        {
                            //_LstAttachment.Add(System.Web.HttpContext.Current.Server.MapPath(_HeaderInfo.Url_Billing));

                            // kết xuất thông tin
                            string _mapPath_Report = Server.MapPath("~/Report/");
                            string _mapPath        = Server.MapPath("~/");

                            string _fileName = AppsCommon.Export_Billing_Crytal_View(_Billing_Header_Info.Case_Code, _mapPath_Report, _mapPath);
                            _LstAttachment.Add(System.Web.HttpContext.Current.Server.MapPath(_fileName));
                        }
                    }

                    string _content = _QuestionInfo.RESULT.Replace("\n", "<br><br>");
                    _content = AppsCommon.SetContentMailTemplate(_content, yourref: _QuestionInfo.CLIENT_REFERENCE, outref: p_case_code, dearname: userInfo.Username);

                    Email_Info _Email_Info = new Email_Info
                    {
                        EmailFrom     = EmailHelper.EmailOriginal.EMailFrom_Business,
                        Pass          = EmailHelper.EmailOriginal.PassWord_Business,
                        Display_Name  = EmailHelper.EmailOriginal.DisplayName_Business,
                        EmailTo       = _emailTo,
                        EmailCC       = _emailCC,
                        Subject       = "Search Report",
                        Content       = _content,
                        LstAttachment = _LstAttachment,
                    };

                    CommonFunction.AppsCommon.EnqueueSendEmail(_Email_Info);
                }

                return(Json(new { success = _ck }));
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
                return(Json(new { success = "-1" }));
            }
        }
        string Export_Billing(string p_case_code)
        {
            try
            {
                Billing_BL _obj_bl = new Billing_BL();
                SearchObject_Header_Info   SearchObject_Header_Info = new SearchObject_Header_Info();
                List <Billing_Detail_Info> _lst_billing_detail      = new List <Billing_Detail_Info>();
                Billing_Header_Info        _Billing_Header_Info     = _obj_bl.Billing_Search_GetBy_Code(p_case_code, AppsCommon.GetCurrentLang(), ref SearchObject_Header_Info, ref _lst_billing_detail);
                foreach (Billing_Detail_Info item in _lst_billing_detail)
                {
                    item.Total_Fee = item.Nation_Fee + item.Represent_Fee + item.Service_Fee;
                }

                string _fileTemp = System.Web.HttpContext.Current.Server.MapPath("/Content/Report/Biling_Search_Report.doc");
                //if (_ApplicationHeaderInfo.Customer_Country != Common.Common.Country_VietNam_Id)
                //    _fileTemp = System.Web.HttpContext.Current.Server.MapPath("/Content/Report/Biling_Report_EN.doc");
                DocumentModel document = DocumentModel.Load(_fileTemp);

                // Fill export_header
                string fileName_exp     = "/Content/Export/" + "Biling_Search_Report" + p_case_code + DateTime.Now.ToString("yyyyMMddHHmmss") + ".pdf";
                string fileName_exp_doc = "/Content/Export/" + "Biling_Search_Report" + p_case_code + DateTime.Now.ToString("yyyyMMddHHmmss") + ".doc";

                string fileName     = System.Web.HttpContext.Current.Server.MapPath(fileName_exp);
                string fileName_doc = System.Web.HttpContext.Current.Server.MapPath(fileName_exp_doc);

                document.MailMerge.FieldMerging += (sender, e) =>
                {
                    if (e.IsValueFound)
                    {
                        if (e.FieldName == "Text")
                        {
                            ((Run)e.Inline).Text = e.Value.ToString();
                        }
                    }
                };

                document.MailMerge.Execute(new { DateNo = DateTime.Now.ToString("dd-MM-yyyy") });
                document.MailMerge.Execute(new { Case_Name = SearchObject_Header_Info.CASE_NAME });
                document.MailMerge.Execute(new { Client_Reference = SearchObject_Header_Info.CLIENT_REFERENCE });
                document.MailMerge.Execute(new { Case_Code = SearchObject_Header_Info.CASE_CODE });
                document.MailMerge.Execute(new { Master_Name = SearchObject_Header_Info.Customer_Name });
                //document.MailMerge.Execute(new { App_No = SearchObject_Header_Info.App_No });
                document.MailMerge.Execute(new { Customer_Country_Name = SearchObject_Header_Info.Customer_Country_Name });
                document.MailMerge.Execute(new { Bill_Code = _Billing_Header_Info.Case_Code });

                document.MailMerge.Execute(new { Total_Amount = _Billing_Header_Info.Total_Amount.ToString("#,##0.##") });
                document.MailMerge.Execute(new { Total_Pre_Tex = _Billing_Header_Info.Total_Pre_Tex.ToString("#,##0.##") });
                document.MailMerge.Execute(new { Tex_Fee = _Billing_Header_Info.Tex_Fee.ToString("#,##0.##") });
                document.MailMerge.Execute(new { Currency = _Billing_Header_Info.Currency });

                document.MailMerge.Execute(new { Deadline = _Billing_Header_Info.Deadline.ToString("dd/MM/yyyy") });
                document.MailMerge.Execute(new { Billing_Date = _Billing_Header_Info.Billing_Date.ToString("dd/MM/yyyy") });

                // lấy thông tin người dùng
                UserBL   _UserBL  = new UserBL();
                UserInfo userInfo = _UserBL.GetUserByUsername(SearchObject_Header_Info.CREATED_BY);
                if (userInfo != null)
                {
                    document.MailMerge.Execute(new { Contact_Person = userInfo.Contact_Person + " " + userInfo.FullName });
                    document.MailMerge.Execute(new { Address = userInfo.Address });
                    document.MailMerge.Execute(new { FullName = userInfo.FullName });
                }
                else
                {
                    document.MailMerge.Execute(new { Contact_Person = "" });
                    document.MailMerge.Execute(new { Address = "" });
                    document.MailMerge.Execute(new { FullName = "" });
                }

                DataTable dtDetail = new DataTable();
                dtDetail = ConvertData.ConvertToDatatable <Billing_Detail_Info>(_lst_billing_detail);
                document.MailMerge.Execute(dtDetail, "TEMP");

                document.Save(fileName, SaveOptions.PdfDefault);
                //document.Save(fileName_doc, SaveOptions.DocxDefault);

                byte[] fileContents;
                var    options = SaveOptions.PdfDefault;
                // Save document to DOCX format in byte array.
                using (var stream = new MemoryStream())
                {
                    document.Save(stream, options);
                    fileContents = stream.ToArray();
                }
                Convert.ToBase64String(fileContents);

                return(fileName_exp);
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
                return("");
            }
        }
        public ActionResult DoInsert(Billing_Header_Info p_Billing_Header_Info)
        {
            try
            {
                List <Billing_Detail_Info> _lst_billing_detail = Get_LstFee_Detail(p_Billing_Header_Info.App_Case_Code);

                if (p_Billing_Header_Info.Total_Amount == 0)
                {
                    return(Json(new { success = "-2" }));
                }

                Billing_BL _obj_bl = new Billing_BL();
                p_Billing_Header_Info.Created_By    = SessionData.CurrentUser.Username;
                p_Billing_Header_Info.Created_Date  = DateTime.Now;
                p_Billing_Header_Info.Language_Code = AppsCommon.GetCurrentLang();
                p_Billing_Header_Info.Status        = (decimal)CommonEnums.Billing_Status.New_Wait_Approve;
                p_Billing_Header_Info.Billing_Type  = (decimal)CommonEnums.Billing_Type.Search;
                p_Billing_Header_Info.Currency_Rate = AppsCommon.Get_Currentcy_VCB();
                decimal _ck         = 0;
                decimal _billing_id = 0;
                using (var scope = new TransactionScope())
                {
                    _billing_id = _obj_bl.Billing_Insert(p_Billing_Header_Info);

                    if (_billing_id > 0 && _lst_billing_detail.Count > 0)
                    {
                        _ck = _obj_bl.Billing_Detail_InsertBatch(_lst_billing_detail, _billing_id);
                    }

                    if (_ck > 0 && p_Billing_Header_Info.Insert_Type == (decimal)Common.CommonData.CommonEnums.Billing_Insert_Type.Search)
                    {
                        //string _fileExport = Export_Billing(p_Billing_Header_Info.Case_Code);

                        string _mapPath_Report = Server.MapPath("~/Report/");
                        string _mapPath        = Server.MapPath("~/");

                        // bỏ đi để lúc nào gửi email thì lấy ra
                        //string _fileExport = AppsCommon.Export_Billing_Crytal_View(p_Billing_Header_Info.Case_Code, _mapPath_Report, _mapPath);

                        string          _fileExport = "";
                        SearchObject_BL _bl         = new SearchObject_BL();
                        _ck = _bl.Update_Url_Billing(p_Billing_Header_Info.App_Case_Code, _billing_id, _fileExport);

                        // insert vào docking
                        AppsCommon.Insert_Docketing(p_Billing_Header_Info.Case_Code, "Report Billing", _fileExport, true);
                    }

                    //end
                    if (_ck < 0)
                    {
                        Transaction.Current.Rollback();
                    }
                    else
                    {
                        SessionData.RemoveDataSession(p_Billing_Header_Info.App_Case_Code);
                        scope.Complete();
                    }
                }
                return(Json(new { success = _ck }));
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
                return(Json(new { success = "-1" }));
            }
        }