//Remove FileSource public static DeleteFileList RemoveFileSource(string source, bool IsMapPath = true, string extension = ".bak", List <string> exception = null) { var rs = new DeleteFileList(); try { var fileList = TM.IO.FileDirectory.FilesToList(source, IsMapPath); if (exception == null) { foreach (var item in fileList) { if (item.ToExtension().ToLower() == extension) { FileManagerController.DeleteDirFile(source + item, IsMapPath); rs.CountDelete++; } } } else { foreach (var item in fileList) { if (!exception.Contains(item.ToLower())) { FileManagerController.DeleteDirFile(TM.OleDBF.DataSource + item, IsMapPath); rs.CountDelete++; } else { rs.CountException++; } } } } catch (Exception) { } return(rs); }
public JsonResult XuLyHD(Common.DefaultObj obj, bool?ckhExcept) { var ok = new System.Text.StringBuilder(); var err = new System.Text.StringBuilder(); var index = 0; obj.DataSource = Common.Directories.HDData; obj = getDefaultObj(obj); var hddttime = obj.datetime.ToString("MMyyyy"); var FoxPro = new TM.Connection.OleDBF(obj.DataSource); var indexError = ""; // Loại bỏ obj.data_value = string.IsNullOrEmpty(obj.data_value) ? null : $",{obj.data_value.Trim(',')},"; try { var hdall = "hdall" + obj.time; var hdallhddt = "hdall_hddt" + obj.time; TM.OleDBF.DataSource = TM.Common.Directories.HDData + obj.time + "\\"; //Khai báo biến var listKey = new List <string>(); var NumberToLeter = new TM.Helper.NumberToLeter(); var hasError = false; string fileName = "hoadon"; string fileNameDBFHDDT = TM.OleDBF.DataSource + hdallhddt + ".dbf"; string fileNameXMLFull = TM.OleDBF.DataSource + fileName + ".xml"; string fileNameZIPFull = TM.OleDBF.DataSource + fileName + ".zip"; string fileNameXMLError = TM.OleDBF.DataSource + fileName + "_Error.xml"; //Xóa file HDDT cũ FileManagerController.DeleteDirFile(fileNameDBFHDDT); FileManagerController.DeleteDirFile(fileNameZIPFull); FileManagerController.DeleteDirFile(fileNameXMLError); // TM.IO.FileDirectory.Copy(TM.OleDBF.DataSource + hdall + ".dbf", fileNameDBFHDDT); //Xử lý trùng mã thanh toán khác đơn vị RemoveDuplicate(TM.OleDBF.DataSource, hdallhddt, new string[] { "tong_cd", "tong_dd", "tong_net", "tong_tv", "vat", "tong", "kthue", "giam_tru", "tongcong" }, new string[] { "acc_net", "acc_tv", "so_dd", "so_cd", "diachi_tt", "ma_tuyen", "ms_thue", "ma_dt", "ma_cbt", "banknumber" }, "Remove Duplicate hoadon", null); //Get data from HDDT var data = FoxPro.Connection.Query <Models.HD_DT>($"SELECT * FROM {hdallhddt}").ToList().Trim(); //TM.OleDBF.ToDataTable("SELECT * FROM " + hdallhddt); //HDDT Hoa don using (System.IO.Stream outfile = new System.IO.FileStream(TM.IO.FileDirectory.MapPath(fileNameXMLFull), System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite)) { ok.Append($"<Invoices><BillTime>{obj.time}</BillTime>").AppendLine(); err.Append($"<Invoices><BillTime>{obj.time}</BillTime>").AppendLine(); foreach (var i in data) { index++; indexError = $"Index: {index}, APP_ID: {i.APP_ID}"; #region List Product //<Product> //<ProdName>Dịch vụ Internet</ProdName> //<ProdUnit></ProdUnit> //<ProdQuantity></ProdQuantity> //<ProdPrice></ProdPrice> //<Amount>1</Amount> //</Product> //<Product> //<ProdName>Dịch vụ MyTv</ProdName> //<ProdUnit></ProdUnit> //<ProdQuantity></ProdQuantity> //<ProdPrice></ProdPrice> //<Amount>0</Amount> //</Product> //<Product> //<ProdName>Dịch vụ Cố định</ProdName> //<ProdUnit></ProdUnit> //<ProdQuantity></ProdQuantity> //<ProdPrice></ProdPrice> //<Amount>20000</Amount> //</Product> //<Product> //<ProdName>Dịch vụ Di động</ProdName> //<ProdUnit></ProdUnit> //<ProdQuantity></ProdQuantity> //<ProdPrice></ProdPrice> //<Amount>0</Amount> //</Product> //<Product> //<ProdName>Khuyến mại, giảm trừ</ProdName> //<ProdUnit></ProdUnit> //<ProdQuantity></ProdQuantity> //<ProdPrice></ProdPrice> //<Amount>0</Amount> //</Product> #endregion var check = true; var MA_TT = i.MA_TT.Replace("-", ""); //Check EzPay if (i.KIEU_TT == 1) { err.Append($"<Inv><app_id>{i.APP_ID}</app_id><key>{MA_TT}</key><error>Is Ezpay</error></Inv>").AppendLine(); check = false; hasError = true; } //Check Error if (string.IsNullOrEmpty(MA_TT)) { err.Append($"<Inv><app_id>{i.APP_ID}</app_id><key>{MA_TT}</key><error>Null Or Empty</error></Inv>").AppendLine(); check = false; hasError = true; } else { if (listKey.Contains(MA_TT)) { err.Append($"<Inv><app_id>{i.APP_ID}</app_id><key>{MA_TT}</key><error>Trùng mã thanh toán</error></Inv>").AppendLine(); check = false; hasError = true; } } if (ckhExcept.HasValue) { if (!string.IsNullOrEmpty(obj.data_value) && obj.data_value.IndexOf($",{MA_TT},") < 0) { err.Append($"<Inv><app_id>{i.APP_ID}</app_id><key>{MA_TT}</key><error>Loại bỏ</error></Inv>").AppendLine(); check = false; hasError = true; } } else { if (!string.IsNullOrEmpty(obj.data_value) && obj.data_value.IndexOf($",{MA_TT},") < 0) { err.Append($"<Inv><app_id>{i.APP_ID}</app_id><key>{MA_TT}</key><error>Loại bỏ</error></Inv>").AppendLine(); check = false; hasError = true; } } //Run if (check) { var Products = $"{getProduct("Dịch vụ Internet", i.TONG_NET)}" + $"{getProduct("Dịch vụ MyTv", i.TONG_TV)}" + $"{getProduct("Dịch vụ Cố định", i.TONG_CD)}" + $"{getProduct("Dịch vụ Di động", i.TONG_DD)}" + $"{getProduct("Khuyến mại, giảm trừ", i.GIAM_TRU)}"; //var so_cd = string.IsNullOrEmpty(dt.Rows[i]["so_cd"].ToString().Trim()); //var so_dd = string.IsNullOrEmpty(dt.Rows[i]["so_dd"].ToString().Trim()); //var acc_net = string.IsNullOrEmpty(dt.Rows[i]["acc_net"].ToString().Trim()); //var acc_tv = string.IsNullOrEmpty(dt.Rows[i]["acc_tv"].ToString().Trim()); //var ma_in = dt.Rows[i]["ma_in"].ToString().Trim(); var Invoice = "<Invoice>" + $"<MaThanhToan><![CDATA[{getMaThanhToanHD(hddttime, MA_TT, i.MA_IN == 2 ? Common.HDDT.DetailDiDong : Common.HDDT.DetailCoDinh)}]]></MaThanhToan>" + $"<CusCode><![CDATA[{MA_TT}]]></CusCode>" + $"<CusName><![CDATA[{(obj.ckhTCVN3 ? i.TEN_TT.TCVN3ToUnicode() : i.TEN_TT)}]]></CusName>" + $"<CusAddress><![CDATA[{(obj.ckhTCVN3 ? i.DIACHI_TT.TCVN3ToUnicode() : i.DIACHI_TT)}]]></CusAddress>" + $"<CusPhone><![CDATA[{getCusPhone(i.ACC_NET, i.ACC_TV, i.SO_CD, i.SO_DD)}]]></CusPhone>" + $"<CusTaxCode>{i.MS_THUE}</CusTaxCode>" + $"<PaymentMethod>{"TM/CK"}</PaymentMethod>" + $"<KindOfService>Cước Tháng {obj.month_year_time}</KindOfService>" + $"<Products>{Products}</Products>" + $"<Total>{i.TONG}</Total>" + $"<DiscountAmount>{i.GIAM_TRU}</DiscountAmount>" + "<VATRate>10</VATRate>" + $"<VATAmount>{i.VAT}</VATAmount>" + $"<Amount>{i.TONGCONG}</Amount>" + $"<AmountInWords><![CDATA[{NumberToLeter.DocTienBangChu(i.TONGCONG, "")}]]></AmountInWords>" + $"<PaymentStatus>0</PaymentStatus>" + $"<Extra>{i.MA_CBT};0;0</Extra>" + $"<ResourceCode>{i.MA_CBT}</ResourceCode>" + "</Invoice>"; Invoice = $"<Inv><key>{MA_TT}{hddttime}</key>{Invoice}</Inv>"; ok.Append(Invoice).AppendLine(); listKey.Add(MA_TT); } if (index % 100 == 0) { outfile.Write(System.Text.Encoding.UTF8.GetBytes(ok.ToString()), 0, System.Text.Encoding.UTF8.GetByteCount(ok.ToString())); ok = new System.Text.StringBuilder(); } } ok.Append("</Invoices>"); outfile.Write(System.Text.Encoding.UTF8.GetBytes(ok.ToString()), 0, System.Text.Encoding.UTF8.GetByteCount(ok.ToString())); // outfile.Close(); } if (hasError) { using (System.IO.Stream outfile = new System.IO.FileStream(TM.IO.FileDirectory.MapPath(fileNameXMLError), System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite)) { err.Append("</Invoices>"); outfile.Write(System.Text.Encoding.UTF8.GetBytes(err.ToString()), 0, System.Text.Encoding.UTF8.GetByteCount(err.ToString())); outfile.Close(); } //this.danger("Có lỗi xảy ra Truy cập File Manager \"~\\" + TM.OleDBF.DataSource.Replace("Uploads\\", "") + "\" để tải file"); } //ZipFile if (obj.ckhZipFile) { TM.IO.Zip.ZipFile(new List <string>() { fileNameXMLFull }, fileNameZIPFull, 9); } //Insert To File Manager FileManagerController.DeleteDirFile(fileNameXMLFull); FileManagerController.InsertFile(fileNameZIPFull); FileManagerController.InsertFile(fileNameXMLError); return(Json(new { success = $"Tạo hóa đơn điện tử thành công! Truy cập File Manager \"~\\{TM.OleDBF.DataSource.Replace("Uploads\\", "")}\" để tải file" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { danger = $"{ex.Message} - Index: {index}" }, JsonRequestBehavior.AllowGet)); } finally { FoxPro.Close(); } }
public JsonResult XuLyKH(Common.DefaultObj obj) { var ok = new System.Text.StringBuilder(); var err = new System.Text.StringBuilder(); var index = 0; obj.DataSource = Common.Directories.HDData; obj = getDefaultObj(obj); var FoxPro = new TM.Connection.OleDBF(obj.DataSource); var hddttime = obj.datetime.ToString("MMyyyy"); // Loại bỏ obj.data_value = string.IsNullOrEmpty(obj.data_value) ? null : $",{obj.data_value.Trim(',')},"; try { var listKey = new List <string>(); var hasError = false; var fileName = "cus"; var hdallhddt = "hdall_hddt" + obj.time; var fileNameDBFHDDT = TM.OleDBF.DataSource + hdallhddt + ".dbf"; var fileNameXMLFull = TM.OleDBF.DataSource + fileName + ".xml"; var fileNameZIPFull = TM.OleDBF.DataSource + fileName + ".zip"; var fileNameXMLError = TM.OleDBF.DataSource + fileName + "_Error.xml"; //Xóa file HDDT cũ FileManagerController.DeleteDirFile(fileNameZIPFull); FileManagerController.DeleteDirFile(fileNameXMLError); //Get data from HDDT var data = FoxPro.Connection.Query <Models.HD_DT>($"SELECT * FROM {hdallhddt}").ToList().Trim(); //TM.OleDBF.ToDataTable("SELECT * FROM " + hdallhddt); using (System.IO.Stream outfile = new System.IO.FileStream(TM.IO.FileDirectory.MapPath(fileNameXMLFull), System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite)) { ok.Append("<Customers>").AppendLine(); err.Append("<Customers>").AppendLine(); foreach (var i in data) { index++; var MA_TT = i.MA_TT.Replace("-", ""); #region List Product //<Product> //<ProdName>Dịch vụ Internet</ProdName> //<ProdUnit></ProdUnit> //<ProdQuantity></ProdQuantity> //<ProdPrice></ProdPrice> //<Amount>1</Amount> //</Product> //<Product> //<ProdName>Dịch vụ MyTv</ProdName> //<ProdUnit></ProdUnit> //<ProdQuantity></ProdQuantity> //<ProdPrice></ProdPrice> //<Amount>0</Amount> //</Product> //<Product> //<ProdName>Dịch vụ Cố định</ProdName> //<ProdUnit></ProdUnit> //<ProdQuantity></ProdQuantity> //<ProdPrice></ProdPrice> //<Amount>20000</Amount> //</Product> //<Product> //<ProdName>Dịch vụ Di động</ProdName> //<ProdUnit></ProdUnit> //<ProdQuantity></ProdQuantity> //<ProdPrice></ProdPrice> //<Amount>0</Amount> //</Product> //<Product> //<ProdName>Khuyến mại, giảm trừ</ProdName> //<ProdUnit></ProdUnit> //<ProdQuantity></ProdQuantity> //<ProdPrice></ProdPrice> //<Amount>0</Amount> //</Product> #endregion //Check EzPay var check = true; if (i.KIEU_TT == 1) { err.Append($"<Inv><app_id>{i.APP_ID}</app_id><key>{MA_TT}</key><error>Is Ezpay</error></Inv>").AppendLine(); check = false; hasError = true; } //Check Error if (string.IsNullOrEmpty(MA_TT)) { err.Append($"<Customer><app_id>{i.APP_ID}</app_id><key>{MA_TT}</key><error>Null Or Empty HDDT Khách hàng</error></Customer>").AppendLine(); check = false; hasError = true; } else { if (listKey.Contains(MA_TT)) { err.Append($"<Customer><app_id>{i.APP_ID}</app_id><key>{MA_TT}</key><error>Trùng mã thanh toán Khách hàng</error></Customer>").AppendLine(); check = false; hasError = true; } } if (!string.IsNullOrEmpty(obj.data_value) && obj.data_value.IndexOf($",{MA_TT}{hddttime},") < 0) { err.Append($"<Inv><app_id>{i.APP_ID}</app_id><key>{MA_TT}</key><error>Loại bỏ</error></Inv>").AppendLine(); check = false; hasError = true; } //Run if (check) { var customer = "<Customer>" + $"<Name><![CDATA[{(obj.ckhTCVN3 ? i.TEN_TT.TCVN3ToUnicode() : i.TEN_TT)}]]></Name>" + $"<Code>{MA_TT}</Code>" + $"<TaxCode>{i.MS_THUE}</TaxCode>" + $"<Address><![CDATA[{(obj.ckhTCVN3 ? i.DIACHI_TT.TCVN3ToUnicode() : i.TEN_TT)}]]></Address>" + "<BankAccountName></BankAccountName>" + "<BankName></BankName>" + $"<BankNumber>{i.BANKNUMBER}</BankNumber>" + "<Email></Email>" + "<Fax></Fax>" + $"<Phone>{getCusPhone(i.ACC_NET, i.ACC_TV, i.SO_DD, i.SO_CD)}</Phone>" + "<ContactPerson></ContactPerson>" + "<RepresentPerson></RepresentPerson>" + "<CusType>0</CusType>" + $"<MaThanhToan><![CDATA[{getMaThanhToanKH(obj.month_year_time, MA_TT, i.MA_IN == 2 ? Common.HDDT.DetailDiDong : Common.HDDT.DetailCoDinh)}]]></MaThanhToan>" + "</Customer>"; ok.Append(customer).AppendLine(); listKey.Add(MA_TT); } if (index % 100 == 0) { outfile.Write(System.Text.Encoding.UTF8.GetBytes(ok.ToString()), 0, System.Text.Encoding.UTF8.GetByteCount(ok.ToString())); ok = new System.Text.StringBuilder(); } } ok.Append("</Customers>"); outfile.Write(System.Text.Encoding.UTF8.GetBytes(ok.ToString()), 0, System.Text.Encoding.UTF8.GetByteCount(ok.ToString())); // outfile.Close(); } if (hasError) { using (System.IO.Stream outfile = new System.IO.FileStream(TM.IO.FileDirectory.MapPath(fileNameXMLError), System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite)) { err.Append("</Customers>"); outfile.Write(System.Text.Encoding.UTF8.GetBytes(err.ToString()), 0, System.Text.Encoding.UTF8.GetByteCount(err.ToString())); outfile.Close(); } //this.danger("Có lỗi xảy ra Truy cập File Manager \"~\\" + TM.OleDBF.DataSource.Replace("Uploads\\", "") + "\" để tải file"); } //ZipFile if (obj.ckhZipFile) { TM.IO.Zip.ZipFile(new List <string>() { fileNameXMLFull }, fileNameZIPFull, 9); } //Insert To File Manager FileManagerController.DeleteDirFile(fileNameXMLFull); FileManagerController.InsertFile(fileNameZIPFull); FileManagerController.InsertFile(fileNameXMLError); //Insert To File Manager hdallhddt FileManagerController.InsertFile(fileNameDBFHDDT); //Delete .BAK FileManagerController.RemoveFileSource(obj.DataSource, false); return(Json(new { success = $"Tạo hóa đơn điện tử thành công! Truy cập File Manager \"~\\{TM.OleDBF.DataSource.Replace("Uploads\\", "")}\" để tải file" }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { danger = $"{ex.Message} - Index: {index}" }, JsonRequestBehavior.AllowGet)); } finally { FoxPro.Close(); } }
public JsonResult XuLyHuyHDTheoMATT(Common.DefaultObj obj) { var index = 0; try { obj.DataSource = Common.Directories.HDData; obj = getDefaultObj(obj); var source = Common.Directories.HDData + obj.time; var hddttime = obj.datetime.ToString("MMyyyy"); string strUpload = "Cập nhật thành công "; // var file = obj.DataSource + "hoadon.zip"; // // TM.IO.Zip.ExtractZipFile(file, null, obj.DataSource); // FileManagerController.DeleteDirFile(file); var ok = new System.Text.StringBuilder(); // var doc = new System.Xml.XmlDocument(); // file = file.Replace(".zip", ".xml"); // doc.Load(file); var file_hoadonhuy = "hoadonhuy.xml"; var file_hoadonhuy_zip = "hoadonhuy.zip"; // Loại bỏ obj.data_value = string.IsNullOrEmpty(obj.data_value) ? null : $",{obj.data_value.Trim(',')},"; using (System.IO.Stream outfile = new System.IO.FileStream(obj.DataSource + file_hoadonhuy, System.IO.FileMode.Create, System.IO.FileAccess.ReadWrite)) { ok.Append("<Inv>"); var tthuy = obj.data_value.Trim().Trim(',').Split(','); foreach (var item in tthuy) { ok.Append($"<key>{item}{hddttime}</key>").AppendLine(); } ok.Append("</Inv>").AppendLine(); outfile.Write(System.Text.Encoding.UTF8.GetBytes(ok.ToString()), 0, System.Text.Encoding.UTF8.GetByteCount(ok.ToString())); // outfile.Close(); } //ZipFile if (obj.ckhZipFile) { TM.IO.Zip.ZipFile(new List <string>() { obj.DataSource + file_hoadonhuy }, obj.DataSource + file_hoadonhuy_zip, 9, false); } //Insert To File Manager FileManagerController.InsertFile(obj.DataSource + file_hoadonhuy); FileManagerController.InsertFile(obj.DataSource + file_hoadonhuy_zip); FileManagerController.DeleteDirFile(file_hoadonhuy); return(Json(new { success = $"Tạo hóa đơn hủy thành công! Truy cập File Manager \"~\\{source.Replace("Uploads\\", "")}\" để tải file", url = UrlDownloadFiles($"{source}\\{file_hoadonhuy_zip}") }, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { danger = $"{ex.Message} - Index: {index}" }, JsonRequestBehavior.AllowGet)); } finally { } }
public ActionResult Mergin(string time, bool ckhMerginMonth) { try { //Declare var hdall = "hdall" + time; string hdcd = "hdcd" + time; string hddd = "hddd" + time; string hdnet = "hdnet" + time; string hdtv = "hdtv" + time; //Kiểm tra tháng đầu vào if (ckhMerginMonth) { time = DateTime.Now.AddMonths(-1).ToString("yyyyMM"); } //Source var fileNameSource = new List <string>(); var dtMergin = new System.Data.DataTable(); var check_file = 0; fileNameSource.Add(hdcd + ".dbf"); fileNameSource.Add(hddd + ".dbf"); fileNameSource.Add(hdnet + ".dbf"); fileNameSource.Add(hdtv + ".dbf"); //Datasource TM.OleDBF.DataSource = TM.Common.Directories.HDData + time + "\\"; var fileList = TM.IO.FileDirectory.FilesToList(TM.OleDBF.DataSource); foreach (var item in fileList) { if (fileNameSource.Contains(item)) { check_file++; } } if (check_file < 4) { this.danger("Chưa tải đủ tệp!"); return(RedirectToAction("Index")); } //Xóa file hdall cũ FileManagerController.DeleteDirFile(TM.OleDBF.DataSource + hdall + ".dbf"); //Tạo bảng hóa đơn ghép //Mã in //- gộp = 1 //- net = 2 //- tv = 3 //- cd = 4 //- dd = 5 TM.OleDBF.CreateTable(hdall, new Dictionary <string, string>() { { "ma_dvi", "n(10)" }, { "ma_tt", "c(20)" }, { "acc_net", "c(20)" }, { "acc_tv", "c(20)" }, { "so_dd", "c(20)" }, { "so_cd", "c(20)" }, { "ten_tt", "c(100)" }, { "diachi_tt", "c(150)" }, { "dienthoai", "c(20)" }, { "ma_tuyen", "c(10)" }, { "ms_thue", "c(15)" }, { "banknumber", "c(16)" }, { "ma_dt", "n(10)" }, { "ma_cbt", "n(15)" }, { "tong_cd", "n(15)" }, { "tong_dd", "n(15)" }, { "tong_net", "n(15)" }, { "tong_tv", "n(15)" }, { "vat", "n(15,2)" }, { "tong", "n(15)" }, { "kthue", "n(15)" }, { "giam_tru", "n(15)" }, { "tongcong", "n(15)" }, { "stk", "c(100)" }, { "ezpay", "n(1)" }, { "kieu", "c(10)" }, { "ghep", "n(1)" }, { "ma_in", "n(1)" }, { "kieu_tt", "n(1)" }, { "flag", "n(1)" }, { "app_id", "n(10)" }, }); #region old //TM.OleDBF.Execute( // "CREATE TABLE " + hdall + @"( // [Ma_dvi] n(2), // [ma_cq] c(50), // [acc_net] c(50), // [acc_tv] c(50), // [so_dd] c(50), // [so_cd] c(50), // [ten_tb] c(100), // [dia_chi] c(100), // [ma_tuyen] c(50), // [ma_st] c(15), // [banknumber] c(16), // [ma_dt] n(1), // [ma_cbt] n(15), // [tong_cd] n(12), // [tong_dd] n(12), // [tong_net] n(12), // [tong_tv] n(12), // [vat] n(12, 2), // [tong] n(12), // [kthue] n(12), // [giam_tru] n(12), // [tongcong] n(12), // [ezpay] n(1), // [Kieu] c(10), // [ghep] n(1), // [ma_in] n(1), // [flag] n(1), // [app_id] n(10))", hdall); #endregion //insert_hdall //Nhập hóa đơn cố định vào hóa đơn ghép TM.OleDBF.Execute(InsertString(hdall, hdcd, new Dictionary <string, string>() { { "ma_dvi", "dvql_id" }, { "ma_tt", "Ma_kh1" }, { "so_cd", "so_tb" }, { "ten_tt", "ten_cq" }, { "diachi_tt", "dia_chi" }, { "ma_tuyen", "ma_tuyen" }, { "ms_thue", "ma_st" }, { "ma_dt", "ma_dt" }, { "ma_cbt", "ma_cbt" }, { "tong_cd", "tong" }, { "vat", "vat" }, { "tong", "tong" }, { "tongcong", "tong_cuoc" }, { "ezpay", "0" }, { "kieu", "1" }, { "ghep", "0" }, { "ma_in", "4" }, { "flag", "1" }, }), "Insert " + hdcd); //Nhập hóa đơn net vào hóa đơn ghép TM.OleDBF.Execute(InsertString(hdall, hdnet, new Dictionary <string, string>() { { "ma_dvi", "ma_dvi" }, { "ma_tt", "ma_tt" }, { "acc_net", "ma_tb" }, { "ten_tt", "ten_tt" }, { "diachi_tt", "diachi_tt" }, { "dienthoai", "dienthoai" }, { "ma_tuyen", "ma_tuyen" }, { "ms_thue", "ms_thue" }, { "ma_dt", "ma_dt" }, { "ma_cbt", "ma_cbt" }, { "tong_net", "Tong" }, { "vat", "vat" }, { "tong", "tong" }, { "tongcong", "tongcong" }, { "ezpay", "0" }, { "kieu", "1" }, { "ghep", "0" }, { "ma_in", "2" }, { "flag", "1" }, }), "Insert " + hdnet); //Nhập hóa đơn tv vào hóa đơn ghép TM.OleDBF.Execute(InsertString(hdall, hdtv, new Dictionary <string, string>() { { "ma_dvi", "ma_dvi" }, { "ma_tt", "ma_tt" }, { "acc_tv", "ma_tb" }, { "ten_tt", "ten_tt" }, { "diachi_tt", "diachi_tt" }, { "dienthoai", "dienthoai" }, { "ma_tuyen", "ma_tuyen" }, { "ms_thue", "ms_thue" }, { "ma_dt", "ma_dt" }, { "ma_cbt", "ma_cbt" }, { "tong_tv", "Tong" }, { "vat", "vat" }, { "tong", "tong" }, { "tongcong", "tongcong" }, { "ezpay", "0" }, { "kieu", "1" }, { "ghep", "0" }, { "ma_in", "3" }, { "flag", "1" }, }), "Insert " + hdtv); //Nhập hóa đơn di động vào hóa đơn ghép TM.OleDBF.Execute(InsertString(hdall, hddd, new Dictionary <string, string>() { { "ma_dvi", "ma_dvi" }, { "ma_tt", "ma_cq" }, { "so_dd", "so_tb" }, { "ten_tt", "ten_tt" }, { "diachi_tt", "diachi_tt" }, { "ma_tuyen", "ma_tuyen" }, { "ms_thue", "ms_thue" }, { "banknumber", "taikhoan" }, { "ma_dt", "ma_dt" }, { "ma_cbt", "ma_cbt" }, { "tong_dd", "cuoc_cthue" }, { "vat", "thue" }, { "tong", "cuoc_cthue+cuoc_kthue" }, { "kthue", "cuoc_kthue" }, { "giam_tru", "giamtru" }, { "tongcong", "tongcong" }, { "ezpay", "ezpay" }, { "kieu", "1" }, { "ghep", "0" }, { "ma_in", "5" }, { "flag", "1" }, }), "Insert " + hddd); //Update Ma_dt 0 -> 1 TM.OleDBF.Execute($"UPDATE {hdall} SET ma_dt=1 WHERE ma_dt=0", hdall); //Remove tongcong<=1000 TM.OleDBF.Execute($"UPDATE {hdall} SET flag=0 WHERE tongcong<=1000", hdall); //Tạo thêm cột app_id //try //{ // TM.OleDBF.Execute(string.Format("ALTER TABLE {0} ADD COLUMN {1} n(10)", file, app_id), "Tạo cột app_id - " + extraEX); //} //catch (Exception) { } //Cập nhật app_id = Auto Increment //TM.OleDBF.Execute(string.Format("UPDATE {0} SET {1}=RECNO()", hdall, app_id), "Cập nhật app_id = Auto Increment "); //Remove Duplicate hdall //Xử lý trùng mã thanh toán khác đơn vị RemoveDuplicate(TM.OleDBF.DataSource, hdall, new string[] { "tong_cd", "tong_dd", "tong_net", "tong_tv", "vat", "tong", "kthue", "giam_tru", "tongcong" }, new string[] { "acc_net", "acc_tv", "so_dd", "so_cd", "diachi_tt", "ma_tuyen", "ms_thue", "ma_dt", "ma_cbt" }, "Remove Duplicate hoadon", "ma_dvi", "ma_tt", "ma_in=1"); //Cập nhật STK UpdateSTK_MA_DVI(Common.Objects.stk_ma_dvi, hdall); //Update NULL TM.OleDBF.Execute($"UPDATE {hdall} SET ezpay=0 WHERE ezpay is null", hdall); TM.OleDBF.Execute($"UPDATE {hdall} SET tong_cd=0 WHERE tong_cd is null", hdall); TM.OleDBF.Execute($"UPDATE {hdall} SET tong_dd=0 WHERE tong_dd is null", hdall); TM.OleDBF.Execute($"UPDATE {hdall} SET tong_net=0 WHERE tong_net is null", hdall); TM.OleDBF.Execute($"UPDATE {hdall} SET tong_tv=0 WHERE tong_tv is null", hdall); TM.OleDBF.Execute($"UPDATE {hdall} SET kthue=0 WHERE kthue is null", hdall); TM.OleDBF.Execute($"UPDATE {hdall} SET giam_tru=0 WHERE giam_tru is null", hdall); //Remove Bak file var deleteFile = FileManagerController.RemoveFileSource(TM.OleDBF.DataSource); //Add hdall to FileManager FileManagerController.InsertFile(TM.OleDBF.DataSource + hdall + ".dbf"); //Return Download File //return RedirectToAction("DownloadFiles"); this.success("Ghép hóa đơn thành công"); } catch (Exception ex) { this.danger(ex.Message); } return(RedirectToAction("Index")); }