/// <summary> /// Tạo xml mẫu 03 bán lẻ xăng dầu /// </summary> /// <param name="numTotal"></param> /// <returns></returns> private StringBuilder Genarate03(PVOILInvoice objInv) { StringBuilder strbd = new StringBuilder(); #region Thông tin điểm bán hàng strbd.AppendFormat("<BranchName>{0}</BranchName>", objInv.BranchName); strbd.AppendFormat("<BranchAddress>{0}</BranchAddress>", objInv.BranchAddress); strbd.AppendFormat("<BranchPhone>{0}</BranchPhone>", objInv.BranchPhone); #endregion return(strbd); }
/// <summary> /// Tạo xml mẫu 04 song ngữ hàng hóa dịch vụ /// </summary> /// <returns></returns> private StringBuilder Genarate04(PVOILInvoice objInv) { StringBuilder strbd = new StringBuilder(); #region Thông tin hóa đơn strbd.AppendFormat("<ContractNo>{0}</ContractNo>", objInv.ContractNo); strbd.AppendFormat("<ContractDate>{0}</ContractDate>", objInv.ContractDate); strbd.AppendFormat("<RefNo>{0}</RefNo>", objInv.RefNo); strbd.AppendFormat("<AmountInWordsEnglish>{0}</AmountInWordsEnglish>", (!string.IsNullOrEmpty(objInv.AmountInWords) && objInv.AmountInWords.Split(';').Count() == 2) ? objInv.AmountInWords.Split(';')[1] : ""); #endregion return(strbd); }
/// <summary> /// Tạo xml mẫu 01 bán buôn không thực xuất /// </summary> /// <param name="numTotal"></param> /// <returns></returns> private StringBuilder Genarate01(PVOILInvoice objInv) { StringBuilder strbd = new StringBuilder(); #region Thông tin hóa đơn strbd.AppendFormat("<ContractNo>{0}</ContractNo>", objInv.ContractNo); strbd.AppendFormat("<ContractDate>{0}</ContractDate>", objInv.ContractDate); strbd.AppendFormat("<RefNo>{0}</RefNo>", objInv.RefNo); strbd.AppendFormat("<StoreAddress>{0}</StoreAddress>", objInv.COutputWarehouse); #endregion return(strbd); }
public static ValidationResult checkExistInvoice(String fkey) { PVOILInvoiceDA pvOil = new PVOILInvoiceDA(); PVOILInvoice objInv = pvOil.checkExistInvoice(fkey); if (objInv != null) { return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_Invoice_Exist), fkey))); } else { return(null); } }
public static ValidationResult checkExistNoInvoice(String fkey, out PVOILInvoice objOut) { PVOILInvoiceDA pvOil = new PVOILInvoiceDA(); PVOILInvoice objInv = pvOil.checkExistInvoice(fkey); if (objInv == null) { objOut = null; return(new ValidationResult(ConfigMultiLanguage.getMess(ConstantsMultiLanguageKey.E_InvoiceDelete_NotExist))); } else { objOut = objInv; return(null); } }
private StringBuilder GenarateXMLbyViewer(string viewer, PVOILInvoice objInv) { switch (viewer) { case "SONGNGU": return(Genarate04(objInv)); case "BANLEXD": return(Genarate03(objInv)); case "BANBUONKTHUCXUAT": return(Genarate01(objInv)); default: return(null); } }
/// <summary> /// service export pdf dự thảo hóa đơn /// </summary> /// <param name="exportObj"></param> /// <returns></returns> public byte[] exportPDF(ExportInvoiceRequest exportObj) { try { SearchInvoiceDA da = new SearchInvoiceDA(); GenerateXMLInvoice xMLInvoice = new GenerateXMLInvoice(); searchInvoiceResponse response = new searchInvoiceResponse(); //lay hoa don PVOILInvoice invoice = da.selectItemInvoiceByFKey(exportObj.FKey); InvoicesModel invoiceModel = ModelBase.mapperStatic <PVOILInvoice, InvoicesModel>().Map <PVOILInvoice, InvoicesModel>(invoice); searchInvoiceModel tmp = new searchInvoiceModel(); //tmp.invoice = invoiceModel; ////lay san pham //tmp.invoice.products = da.selectProductByInvoice(invoiceModel.id); //InvTemplate_GetTemplateInvoice_Result template = da.InvTemplate_GetTemplateInvoice(invoice.Pattern, invoice.ComTaxCode); ////Tạo data XML từ invoice và product //String xml = xMLInvoice.GetXMLData(tmp.invoice, tmp.invoice.products, template.TemplateName); //Tạo data html từ xml //String html = xMLInvoice.GetHtml(xMLInvoice.GetData(xml), template); //Tạo pdf html từ html var htmlToPdf = new NReco.PdfGenerator.HtmlToPdfConverter(); htmlToPdf.Zoom = 1.6f; htmlToPdf.Size = NReco.PdfGenerator.PageSize.A4; htmlToPdf.Margins = new PageMargins { Left = 20 }; //byte[] pdfBytes = htmlToPdf.GeneratePdf(html); //return pdfBytes; return(null); } catch (Exception ex) { throw ex; } }
/// <summary> /// service insert hóa đơn /// </summary> /// <param name="createInvoiceModel"></param> /// <returns></returns> public createInvoiceResponse createInvoice(CreateInvoiceRequest createInvoiceModel) { try { createInvoiceResponse returnObj = new createInvoiceResponse(); //Gán key của FAST vào FKey createInvoiceModel.invoice.Fkey = createInvoiceModel.key; CRUDInvoices cRUD = new CRUDInvoices(); PVOILInvoice invoice = ModelBase.mapperStatic <InvoicesModel, PVOILInvoice>().Map <InvoicesModel, PVOILInvoice>(createInvoiceModel.invoice); List <ProductInv> lstProduct = ModelBase.mapperStatic <ProductModel, ProductInv>().Map <List <ProductModel>, List <ProductInv> >(createInvoiceModel.invoice.products); invoice.InvCateID = 1; invoice.SysSource = "Auto"; int idInvoice = cRUD.insertInvoiceProduct(invoice, lstProduct, createInvoiceModel.invoice.originalKey); returnObj.taxCode = createInvoiceModel.invoice.ComTaxCode; returnObj.key = createInvoiceModel.invoice.Fkey; returnObj.SoDuThao = idInvoice; returnObj.result = true; return(returnObj); } catch (Exception ex) { throw ex; } }
/// <summary> /// ham validate model /// </summary> /// <param name="validationContext"></param> /// <returns></returns> public IEnumerable <ValidationResult> Validate(System.ComponentModel.DataAnnotations.ValidationContext validationContext) { AdjustInvDH ctlAdj = new AdjustInvDH(); Boolean draftCancel = invoice.DraftCancel ?? false; //check hoa đơn hủy if ((invoice.Type == InvoiceType.Nomal || invoice.Type == InvoiceType.ForReplace || invoice.Type == InvoiceType.ForAdjustAccrete || invoice.Type == InvoiceType.ForAdjustReduce || invoice.Type == InvoiceType.ForAdjustInfo) && draftCancel) { List <String> validateRequestHuy = ModelBase.validateRequiredObject(new string[] { "key" , "invoice.Type", "invoice.Status", "invoice.DraftCancel", "invoice.ComtaxCode" }, new object[] { key, invoice.Type, invoice.Status, invoice.DraftCancel, invoice.ComTaxCode }); foreach (String item in validateRequestHuy) { yield return(new ValidationResult(item)); } //check invoice co ton tai hay ko PVOILInvoice objOut; yield return(ModelValidate.checkExistNoInvoice(key, out objOut)); //type=0,1,2,3,4 and status=0 and draftcancel=1 check key họ truyền lên với fkey trong bảng pvoilinvie là status=3 hoặc 5 thì k nhận báo lỗi if (objOut != null) { if (objOut.Status == Untilities.Common.Constants.InvoiceStatus.Bi_Thay_The || objOut.Status == Untilities.Common.Constants.InvoiceStatus.Xoa_Bo) { yield return(new ValidationResult(ConstantsMultiLanguageKey.E_Invoice_Status_3_5)); } // Check trong bảng [AdjustInv] nếu đã tồn tại invid của key truyền lên thì báo lỗi AdjustInv objAdj = ctlAdj.CheckExists(objOut.id); if (objAdj != null) { yield return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_AdjustInv_Exist), key))); } } //if (invoice.Status != 1) //{ // yield return new ValidationResult(ConstantsMultiLanguageKey.E_Invoice_Status_Delete); //} } else { List <String> validateRequest = ModelBase.validateRequiredObject(new string[] { "key" , "invoice.ComtaxCode", "invoice.BusinessDepartmentID", "invoice.Type", "invoice.Status" , "invoice.PaymentMethod", "invoice.PaymentStatus", "invoice.CreateDate", "invoice.CreateBy" , "invoice.Total" , "invoice.VATRate", "invoice.VATAmount", "invoice.Amount" , "invoice.AmountInWords" , "invoice.Otherfees" , "invoice.Currency" , "invoice.ExchangeRate" }, new object[] { key , invoice.ComTaxCode, invoice.BusinessDepartmentID, invoice.Type, invoice.Status , invoice.PaymentMethod, invoice.PaymentStatus, invoice.CreateDate, invoice.CreateBy , invoice.Total , invoice.VATRate, invoice.VATAmount, invoice.Amount , invoice.AmountInWords , invoice.OtherFees , invoice.Currency , invoice.ExchangeRate }); foreach (String item in validateRequest) { yield return(new ValidationResult(item)); } //ton tai du lieu 1 trong 3 column sau CusTaxCode,CusName,CusAddress thì ca 3 column này phải có data if (String.IsNullOrEmpty(invoice.Buyer)) { List <String> validateRequestCus = ModelBase.validateRequiredObject(new string[] { "invoice.CusTaxCode", "invoice.CusName", "invoice.CusAddress" }, new object[] { invoice.CusTaxCode, invoice.CusName, invoice.CusAddress }); foreach (String item in validateRequestCus) { yield return(new ValidationResult(item)); } } if (invoice.Status != 0) { new ValidationResult(ConstantsMultiLanguageKey.E_Invoice_Status_Create); } else { if ((invoice.Type == InvoiceType.Nomal || invoice.Type == InvoiceType.ForReplace || invoice.Type == InvoiceType.ForAdjustAccrete || invoice.Type == InvoiceType.ForAdjustReduce || invoice.Type == InvoiceType.ForAdjustInfo) && invoice.DraftCancel != null) { if (!(invoice.Type == InvoiceType.Nomal && !draftCancel)) { String noCheckOk = HttpContext.Current.Request.QueryString["NoCheckOK"]; if ((!((invoice.Type == InvoiceType.ForAdjustReduce || invoice.Type == InvoiceType.ForAdjustAccrete) && !draftCancel)) || noCheckOk == null) { List <String> validateRequestCus = ModelBase.validateRequiredObject(new string[] { "invoice.originalKey" }, new object[] { invoice.originalKey }); foreach (String item in validateRequestCus) { yield return(new ValidationResult(item)); } } } //hoa don ko phai huy if (!draftCancel) { //check invoice co ton tai hay ko yield return(ModelValidate.checkExistInvoice(key)); if (invoice.Status != 0) { new ValidationResult(ConstantsMultiLanguageKey.E_Invoice_Status_Create); } PVOILInvoiceDA pvOil = new PVOILInvoiceDA(); //originalKey trong bảng pvoilinvie là status=3 hoặc 5 thì k nhận báo lỗi PVOILInvoice objInvoice = pvOil.checkExistInvoice(invoice.originalKey); if (objInvoice != null) { if (objInvoice.Status == Untilities.Common.Constants.InvoiceStatus.Bi_Thay_The || objInvoice.Status == Untilities.Common.Constants.InvoiceStatus.Xoa_Bo) { yield return(new ValidationResult(ConstantsMultiLanguageKey.E_Invoice_Status_3_5)); } } // type=1,2,3,4 check id của originalKey có trong bảng [AdjustInv] chưa?. nếu có status khác 0,1,2 báo lỗi if ((invoice.Type == InvoiceType.ForReplace || invoice.Type == InvoiceType.ForAdjustAccrete || invoice.Type == InvoiceType.ForAdjustReduce || invoice.Type == InvoiceType.ForAdjustInfo) && objInvoice != null) { AdjustInv objAdj = ctlAdj.CheckExistsAdj(Convert.ToInt64(objInvoice.id)); if (objAdj != null && (objAdj.Status != Untilities.Common.Constants.StatusAdj.Adj_0 && objAdj.Status != Untilities.Common.Constants.StatusAdj.Adj_1 && objAdj.Status != Untilities.Common.Constants.StatusAdj.Adj_2)) { yield return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_AdjustInv_ThayThe), invoice.originalKey))); } } // type=1,2,3,4 thì bắt truyền trường ProcessInvNote => "bắt buộc nhập ProcessInvNote" if (invoice.Type == InvoiceType.ForReplace || invoice.Type == InvoiceType.ForAdjustAccrete || invoice.Type == InvoiceType.ForAdjustReduce || invoice.Type == InvoiceType.ForAdjustInfo) { List <String> validateRequestProcessInvNote = ModelBase.validateRequiredObject(new string[] { "invoice.ProcessInvNote" }, new object[] { invoice.ProcessInvNote }); foreach (String item in validateRequestProcessInvNote) { yield return(new ValidationResult(item)); } } // type=4 : check originalKey nếu tồn tại type=4 thì sẽ chỉ nhận type=4 k nhận type=1,2,3 của fkey mới if (invoice.Type == InvoiceType.ForAdjustInfo) { if (objInvoice.Type == InvoiceType.ForAdjustInfo) { yield return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_Invoice_DaDieuChinhThongTin), invoice.originalKey))); } } } //else if (draftCancel) //{ // if (invoice.Status != 1) // { // new ValidationResult(ConstantsMultiLanguageKey.E_Invoice_Status_Delete); // } //} //check mau hoa don khong được điều chỉnh thay thế if ((invoice.Type == InvoiceType.ForReplace || invoice.Type == InvoiceType.ForAdjustAccrete || invoice.Type == InvoiceType.ForAdjustReduce || invoice.Type == InvoiceType.ForAdjustInfo) && invoice.DraftCancel != null) { yield return(ModelValidate.checkExistInvoiceTemplateTypeView(invoice.Type ?? 8)); } } else { //check invoice co ton tai hay ko yield return(ModelValidate.checkExistInvoice(key)); } } CustomerDA ctlCustomer = new CustomerDA(); Customer objCus = ctlCustomer.checkExistCustaxcode(invoice.CusTaxCode); if (objCus != null) { invoice.CusAddress = objCus.Address; invoice.CusName = objCus.Name; } WareHouseDA ctlWareHouse = new WareHouseDA(); Warehouse objWareHouse = ctlWareHouse.checkExistWarehouse(invoice.COutputWarehouseID ?? 0); if (objWareHouse != null) { invoice.COutputWarehouseCode = objWareHouse.Code; invoice.COutputWarehouse = objWareHouse.Name; } //check hàng hóa List <String> validateRequestProduct = ModelBase.validateRequiredList <ProductModel>(invoice.products, new string[] { "VATRate", "VATAmount" }); foreach (String item in validateRequestProduct) { yield return(new ValidationResult(item)); } int ComID = invoice.ComID ?? default(int); //Check company //yield return ModelValidate.checkComID(ComID); //Check buyer //yield return ModelValidate.checkExistBuyer(invoice.Buyer); yield return(ModelValidate.checkValueInArrayValue <InvoiceType>(invoice.Type, "Type", ConstantsMultiLanguageKey.E_InValid_Value)); yield return(ModelValidate.checkValueInArrayValue <PaymentMethod>(invoice.PaymentMethod, "PaymentMethod", ConstantsMultiLanguageKey.E_InValid_Value)); yield return(ModelValidate.checkValueInArrayValue <InvoiceStatus>(invoice.Status, "Status", ConstantsMultiLanguageKey.E_InValid_Value)); yield return(ModelValidate.checkValueInArrayValue <PaymentStatus>(invoice.PaymentStatus, "PaymentStatus", ConstantsMultiLanguageKey.E_InValid_Value)); yield return(ModelValidate.checkValueInArrayValue <VATRate>(invoice.VATRate, "VATRate", ConstantsMultiLanguageKey.E_InValid_Value)); yield return(ModelValidate.checkDoDaiSo(invoice.Total.ToString(), LengthNumber.DO_DAI_19, "Total", ConstantsMultiLanguageKey.E_String_Length)); yield return(ModelValidate.checkSoAm(invoice.Total, "Total", ConstantsMultiLanguageKey.E_Number_Value)); yield return(ModelValidate.checkDoDaiSo(invoice.VATAmount.ToString(), LengthNumber.DO_DAI_19, "VATAmount", ConstantsMultiLanguageKey.E_String_Length)); yield return(ModelValidate.checkSoAm(invoice.VATAmount, "VATAmount", ConstantsMultiLanguageKey.E_Number_Value)); yield return(ModelValidate.checkDoDaiSo(invoice.Amount.ToString(), LengthNumber.DO_DAI_19, "Amount", ConstantsMultiLanguageKey.E_String_Length)); yield return(ModelValidate.checkSoAm(invoice.Amount, "Amount", ConstantsMultiLanguageKey.E_Number_Value)); yield return(ModelValidate.checkDoDaiSo(invoice.AmountInWords, LengthNumber.DO_DAI_255, "AmountInWords", ConstantsMultiLanguageKey.E_String_Length)); yield return(ModelValidate.checkDoDaiSo(invoice.OtherFees.ToString(), LengthNumber.DO_DAI_19, "Otherfees", ConstantsMultiLanguageKey.E_String_Length)); yield return(ModelValidate.checkSoAm(invoice.OtherFees, "Otherfees", ConstantsMultiLanguageKey.E_Number_Value)); yield return(ModelValidate.checkDoDaiSo(invoice.ExchangeRate.ToString(), LengthNumber.DO_DAI_19, "ExchangeRate", ConstantsMultiLanguageKey.E_String_Length)); yield return(ModelValidate.checkSoAm(invoice.ExchangeRate, "ExchangeRate", ConstantsMultiLanguageKey.E_Number_Value)); yield return(ModelValidate.checkDoDaiSo(invoice.Currency, LengthNumber.DO_DAI_3, "Currency", ConstantsMultiLanguageKey.E_String_Length)); //yield return ModelValidate.checkCurrency(invoice.Currency); ///Check BusinessDepartment ID BusinessDepartment objBD = null; Business objB = null; PublishInvoice objPInvoice = null; Department objDepartment = null; userdata objuser = null; //Lấy BusinessID yield return(ModelValidate.checkExistBussinessDepartment(invoice.BusinessDepartmentID, out objBD)); if (objBD != null) { //Lấy thông tin Business yield return(ModelValidate.checkExistBussiness(objBD.BusinessID, out objB)); if (invoice.ModifiedDate == null) { invoice.ModifiedDate = DateTime.Now; } if (invoice.PublishDate == null) { invoice.PublishDate = DateTime.Now; } //check khac nhau giua tax code dang nhap va bussinessDepartment if (!invoice.ComTaxCode.Equals(objB.TaxCode)) { yield return(new ValidationResult(ConstantsMultiLanguageKey.E_TAXCODEDANGNHAP_TAXCODEBUSINESSDEPARTMENT)); } //lay tax code invoice.ComTaxCode = objB.TaxCode; if (objB != null) { invoice.Serial = objB.InvSerial; invoice.Pattern = objB.InvPattern; invoice.BusinessID = objBD.BusinessID; //lấy thông tin company CompanyDA ctlCompany = new CompanyDA(); Company company = ctlCompany.checkExistByID(objB.ComID); if (company != null) { invoice.ComName = company.Name; invoice.ComAddress = company.Address; } //Lấy thông tin Publish Invoice yield return(ModelValidate.checkExistPublishInvoice(objB.InvSerial, objB.InvPattern, objB.ComID, out objPInvoice)); if (objPInvoice != null) { invoice.Name = objPInvoice.InvCateName; } //Lấy thông tin Publish Invoice yield return(ModelValidate.checkExistDepartment(objBD.DepartmentID, out objDepartment)); if (objDepartment != null) { invoice.DepartmentID = objBD.DepartmentID; invoice.BranchCode = objDepartment.Code; invoice.BranchName = objDepartment.Name; invoice.BranchAddress = objDepartment.Address; invoice.BranchPhone = objDepartment.Phone; invoice.ComID = objDepartment.ComID; } //Lấy thông tin User yield return(ModelValidate.checkUsersByID(objBD.UserID, out objuser)); if (objuser != null) { if (HttpContext.Current.Request.Headers["Authentication"] != null) { String[] authentication = Untility.decodeBase64(HttpContext.Current.Request.Headers["Authentication"]).Split(':'); String userNameLogin = authentication[0]; //check khac nhau giua username dang nhap va bussinessDepartment if (!objuser.username.Equals(userNameLogin)) { yield return(new ValidationResult(ConstantsMultiLanguageKey.E_USERNAMEDANGNHAP_USERNAMEBUSINESSDEPARTMENT)); } } if (!objuser.IsApproved ?? !eInvoice.Untilities.Common.Constants.ActiveUser.INACTIVE) { yield return(new ValidationResult(String.Format(ConfigMultiLanguage.getMessWithKey(ConstantsMultiLanguageKey.E_User_Active), objuser.username))); } } } } } }
/// <summary> /// Thêm invoice kèm product /// </summary> /// <param name="invoiceObj"></param> /// <param name="lstProductObj"></param> /// <returns></returns> public int insertInvoiceProduct(PVOILInvoice invoiceObj, List <ProductInv> lstProductObj, String originKey) { ProductInvDA cPro = new ProductInvDA(); PVOILInvoiceDA ctlPvoil = new PVOILInvoiceDA(); AdjustInvDH cAdj = new AdjustInvDH(); AdjustInv objAdj = new AdjustInv(); int idInvoice = 0; Boolean draftCancel = invoiceObj.DraftCancel ?? false; PVOILInvoice objInv = ctlPvoil.checkExistInvoice(originKey, invoiceObj.ComTaxCode); PVOILInvoice objAdjInv = ctlPvoil.checkExistInvoice(invoiceObj.Fkey, invoiceObj.ComTaxCode); int adjustInvId = objAdjInv != null ? objAdjInv.id : 0; //Set status cho table AdjustInv if (draftCancel) { if (invoiceObj.Type == InvoiceType.Nomal || invoiceObj.Type == InvoiceType.ForReplace || invoiceObj.Type == InvoiceType.ForAdjustAccrete || invoiceObj.Type == InvoiceType.ForAdjustReduce || invoiceObj.Type == InvoiceType.ForAdjustInfo) { objAdj.Status = StatusAdj.Du_Thao_Huy; } } else { if (invoiceObj.Type == InvoiceType.ForReplace) { objAdj.Status = StatusAdj.Du_Thao_Thay_The; } else if (invoiceObj.Type == InvoiceType.ForAdjustAccrete || invoiceObj.Type == InvoiceType.ForAdjustReduce || invoiceObj.Type == InvoiceType.ForAdjustInfo) { objAdj.Status = StatusAdj.Du_Thao_Dieu_Chinh; } else { objAdj.Status = 0; } } using (DbContextTransaction transaction = dbInvoice.db.Database.BeginTransaction()) { try { if (draftCancel && ((invoiceObj.Type == InvoiceType.Nomal || invoiceObj.Type == InvoiceType.ForReplace || invoiceObj.Type == InvoiceType.ForAdjustAccrete || invoiceObj.Type == InvoiceType.ForAdjustReduce || invoiceObj.Type == InvoiceType.ForAdjustInfo))) { objAdjInv.Type = invoiceObj.Type; objAdjInv.Status = invoiceObj.Status; objAdjInv.DraftCancel = invoiceObj.DraftCancel; updateInvoices(objAdjInv); objAdj.AdjustInvId = adjustInvId; if (objInv == null) { invoiceObj = objAdjInv; objAdj.InvId = invoiceObj.id; } else { objAdj.InvId = objInv.id; } objAdj.Description = invoiceObj.Name; objAdj.Pattern = invoiceObj.Pattern; objAdj.ProcessDate = DateTime.Now; objAdj.ComID = invoiceObj.ComID; } else { idInvoice = insertInvoices(invoiceObj); adjustInvId = objAdjInv != null ? objAdjInv.id : idInvoice; int invID = objInv != null ? objInv.id : 0; objAdj.InvId = invID; objAdj.AdjustInvId = adjustInvId; objAdj.Description = invoiceObj.Name; objAdj.Pattern = invoiceObj.Pattern; objAdj.ProcessDate = DateTime.Now; objAdj.ComID = invoiceObj.ComID; //Type =4 khoong nhan product if (invoiceObj.Type != InvoiceType.ForAdjustInfo) { foreach (ProductInv item in lstProductObj) { item.id = Guid.NewGuid(); item.InvID = idInvoice; } cPro.insertProduct(lstProductObj); } } //check insert table AdjustInv type=0 and status=0 and daftcancel=0 thì ko insert if (invoiceObj.Type == InvoiceType.Nomal) { if (draftCancel) { cAdj.insertAdjustInv(objAdj); } } else { cAdj.insertAdjustInv(objAdj); } transaction.Commit(); return(idInvoice); } catch (Exception ex) { transaction.Rollback(); throw ex; } } }
public int updateInvoices(PVOILInvoice invoiceObj) { dbInvoice.Update <PVOILInvoice>(invoiceObj); return(invoiceObj.id); }
/// <summary> /// them invoice /// </summary> /// <param name="invoiceObj"></param> /// <returns></returns> public int insertInvoices(PVOILInvoice invoiceObj) { dbInvoice.Insert <PVOILInvoice>(invoiceObj); return(invoiceObj.id); }
public string GetXMLData(PVOILInvoice objInv, List <ProductInv> lstProducts, String tempName) { int ComID = objInv.ComID ?? 0; String Fkey = objInv.Fkey; StringBuilder strbd = new StringBuilder(); strbd.AppendFormat("<?xml-stylesheet type='text/xsl' href='{0}' ?>", ""); strbd.Append("<Invoice><Content Id=\"SigningData\">"); int NumTotal = objInv.Currency.ToUpper().Trim() == "VND" ? 0 : 2; #region Thông tin cơ bản hóa đơn strbd.AppendFormat("<InvoiceName>{0}</InvoiceName>", objInv.Name); strbd.AppendFormat("<InvoicePattern>{0}</InvoicePattern>", objInv.Pattern); strbd.AppendFormat("<SerialNo>{0}</SerialNo>", objInv.Serial); strbd.AppendFormat("<InvoiceNo>{0}</InvoiceNo>", objInv.No); DateTime ArisingDate = objInv.ArisingDate ?? DateTime.MinValue; strbd.AppendFormat("<ArisingDate>{0}</ArisingDate>", objInv.ArisingDate == DateTime.MinValue ? string.Empty : ArisingDate.ToString("dd/MM/yyyy")); strbd.AppendFormat("<SearchKey>{0}</SearchKey>", objInv.SearchKey); strbd.AppendFormat("<Fkey>{0}</Fkey>", Fkey); strbd.AppendFormat("<Note>{0}</Note>", objInv.Note); strbd.AppendFormat("<PaymentMethod>{0}</PaymentMethod>", objInv.PaymentMethod); #endregion #region Thông tin đơn vị strbd.AppendFormat("<ComName>{0}</ComName>", objInv.ComName); strbd.AppendFormat("<ComTaxCode>{0}</ComTaxCode>", objInv.ComTaxCode); strbd.AppendFormat("<ComAddress>{0}</ComAddress>", objInv.ComAddress); strbd.AppendFormat("<ComPhone>{0}</ComPhone>", objInv.ComPhone); strbd.AppendFormat("<ComFax>{0}</ComFax>", objInv.ComFax); strbd.AppendFormat("<ComBankNo>{0}</ComBankNo>", objInv.ComBankNo); strbd.AppendFormat("<ComBankName>{0}</ComBankName>", objInv.ComBankName); #endregion #region Thông tin khách hàng strbd.AppendFormat("<Buyer>{0}</Buyer>", objInv.Buyer); strbd.AppendFormat("<CusName>{0}</CusName>", objInv.CusName); strbd.AppendFormat("<CusTaxCode>{0}</CusTaxCode>", objInv.CusTaxCode); strbd.AppendFormat("<CusPhone>{0}</CusPhone>", objInv.CusPhone); strbd.AppendFormat("<CusEmail>{0}</CusEmail>", objInv.CusEmail); strbd.AppendFormat("<CusAddress>{0}</CusAddress>", objInv.CusAddress); strbd.AppendFormat("<CusBankName>{0}</CusBankName>", objInv.CusBankName); strbd.AppendFormat("<CusBankNo>{0}</CusBankNo>", objInv.CusBankNo); #endregion #region Tạo xml theo từng mẫu //tao xml view cho cac kieu ban xang dau var strXML = GenarateXMLbyViewer(tempName, objInv); strbd.Append(strXML); #endregion if (objInv.FormatNumber ?? false) { strbd.AppendFormat("<FormatNumber>{0}</FormatNumber>", objInv.FormatNumber); } #region Thông tin hàng hóa strbd.Append("<Products>"); var i = 1; foreach (ProductInv product in lstProducts) { strbd.Append("<Product>"); strbd.AppendFormat("<Order>{0}</Order>", i); strbd.AppendFormat("<Extra>{0}</Extra>", Format.ParseChar(product.Extra)); strbd.AppendFormat("<ProdName>{0}</ProdName>", product.Name); int type = objInv.Type ?? 0; strbd.AppendFormat("<ProdPrice>{0}</ProdPrice>", (type != (int)InvoiceType.ForAdjustInfo && product.Price > 0) ? Format.NumberVi(product.Price ?? 0, objInv.NumPrice) : ""); strbd.AppendFormat("<ProdQuantity>{0}</ProdQuantity>", (type != (int)InvoiceType.ForAdjustInfo && product.Quantity > 0) ? Format.NumberVi(product.Quantity ?? 0, objInv.NumQuantity) : ""); strbd.AppendFormat("<ProdType>{0}</ProdType>", product.ProdType); strbd.AppendFormat("<ProdUnit>{0}</ProdUnit>", product.Unit); strbd.AppendFormat("<Total>{0}</Total>", product.Total); strbd.AppendFormat("<VATAmount>{0}</VATAmount>", product.VATAmount); strbd.AppendFormat("<Discount>{0}</Discount>", product.Discount); strbd.AppendFormat("<IsSum>{0}</IsSum>", product.IsSum); strbd.AppendFormat("<Amount>{0}</Amount>", (objInv.Type != (int)InvoiceType.ForAdjustInfo && product.Amount > 0) ? Format.NumberVi(product.Amount ?? 0, objInv.NumAmount) : ""); strbd.Append("</Product>"); i++; } strbd.Append("</Products>"); #endregion #region Thông tin tổng tiền, tiền thuế strbd.AppendFormat("<Total>{0}</Total>", (objInv.Type != (int)InvoiceType.ForAdjustInfo && objInv.Total > 0) ? Format.NumberVi(objInv.Total ?? 0, objInv.NumAmount) : ""); strbd.AppendFormat("<Otherfees>{0}</Otherfees>", objInv.OtherFees); strbd.AppendFormat("<VATRate>{0}</VATRate>", objInv.VATRate); strbd.AppendFormat("<VATAmount>{0}</VATAmount>", (objInv.Type != (int)InvoiceType.ForAdjustInfo && objInv.VATAmount > 0) ? Format.NumberVi(objInv.VATAmount ?? 0, objInv.NumAmount) : ""); strbd.AppendFormat("<Amount>{0}</Amount>", (objInv.Type != (int)InvoiceType.ForAdjustInfo && objInv.Amount > 0) ? Format.NumberVi(objInv.Amount ?? 0, NumTotal) : ""); strbd.AppendFormat("<AmountInWords>{0}</AmountInWords>", (!string.IsNullOrEmpty(objInv.AmountInWords) && objInv.Amount > 0) ? objInv.AmountInWords.Split(';')[0] : ""); #endregion strbd.Append("</Content></Invoice>"); XmlDocument xdoc = new XmlDocument(); xdoc.PreserveWhitespace = true; xdoc.LoadXml(strbd.ToString()); //XmlNode xnd = xdoc.GetElementsByTagName("Invoice")[0].AppendChild(xdoc.CreateElement("qrCodeData")); //var qrCodeData = string.Format("{0}|{1};{2};{3};{4};{5};{6};{7};{8};{9}", this.Fkey, this.Pattern, this.Serial, this.No, this.ComTaxCode, this.CusTaxCode, this.Amount, this.VATAmount, this.ArisingDate, this.ComID); //xnd.InnerText = qrCodeData; return(xdoc.OuterXml); }