Ejemplo n.º 1
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" }));
            }
        }