/// <summary> /// /// </summary> /// <param name="APaymentNum"></param> /// <param name="ALedgerNumber"></param> public void PrintRemittanceAdvice(Int32 APaymentNum, Int32 ALedgerNumber) { FLedgerNumber = ALedgerNumber; txtPaymentNum.NumberValueInt = APaymentNum; AccountsPayableTDS PaymentDetails = TRemote.MFinance.AP.WebConnectors.LoadAPPayment(ALedgerNumber, APaymentNum); if (PaymentDetails.AApPayment.Rows.Count == 0) // unable to load this payment.. { lblLoadStatus.Text = String.Format(Catalog.GetString("Error - can't load Payment number {0}."), APaymentNum); return; } SortedList <string, List <string> > FormValues = new SortedList <string, List <string> >(); // // load my own country code, so I don't print it on letters to my own country. // string LocalCountryCode = TRemote.MPartner.Partner.ServerLookups.WebConnectors.GetCountryCodeFromSiteLedger(); // // These are the fields that I will pull out of the TDS... // FormValues.Add("SupplierName", new List <string>()); FormValues.Add("SupplierAddress", new List <string>()); FormValues.Add("PaymentDate", new List <string>()); FormValues.Add("OurReference", new List <string>()); FormValues.Add("InvoiceDate", new List <string>()); FormValues.Add("InvoiceNumber", new List <string>()); FormValues.Add("InvoiceAmount", new List <string>()); FormValues.Add("TotalPayment", new List <string>()); FormValues["SupplierName"].Add(PaymentDetails.PPartner[0].PartnerShortName); if (PaymentDetails.PLocation[0].CountryCode == LocalCountryCode) { PaymentDetails.PLocation[0].CountryCode = ""; // Don't print country code it it's the same as my own. } FormValues["SupplierAddress"].Add(Calculations.DetermineLocationString(PaymentDetails.PLocation[0], Calculations.TPartnerLocationFormatEnum.plfHtmlLineBreak)); String DatePattern = Thread.CurrentThread.CurrentCulture.DateTimeFormat.LongDatePattern; DatePattern = "dd MMMM yyyy"; // The long pattern above is no good in UK, although it might be OK in other cultures... FormValues["PaymentDate"].Add(PaymentDetails.AApPayment[0].PaymentDate.Value.ToString(DatePattern)); FormValues["OurReference"].Add(PaymentDetails.AApSupplier[0].OurReference); foreach (AApDocumentRow Row in PaymentDetails.AApDocument.Rows) { FormValues["InvoiceDate"].Add(Row.DateIssued.ToString(DatePattern)); FormValues["InvoiceNumber"].Add(Row.DocumentCode); FormValues["InvoiceAmount"].Add(Row.TotalAmount.ToString("n2") + " " + PaymentDetails.AApSupplier[0].CurrencyCode); } FormValues["TotalPayment"].Add(PaymentDetails.AApPayment[0].Amount.ToString("n2") + " " + PaymentDetails.AApSupplier[0].CurrencyCode); String TemplateFilename = TAppSettingsManager.GetValue("Formletters.Path") + "\\ApRemittanceAdvice.html"; if (!File.Exists(TemplateFilename)) { lblLoadStatus.Text = String.Format(Catalog.GetString("Error - unable to load HTML template from {0}"), TemplateFilename); return; } FHtmlDoc = TFormLettersTools.PrintSimpleHTMLLetter(TemplateFilename, FormValues); System.Drawing.Printing.PrintDocument printDocument = new System.Drawing.Printing.PrintDocument(); bool printerInstalled = printDocument.PrinterSettings.IsValid; if (!printerInstalled) { lblLoadStatus.Text = Catalog.GetString("There is no printer, so printing is not possible"); return; } FGfxPrinter = new TGfxPrinter(printDocument, TGfxPrinter.ePrinterBehaviour.eFormLetter); try { TPrinterHtml htmlPrinter = new TPrinterHtml(FHtmlDoc, TAppSettingsManager.GetValue("Formletters.Path"), FGfxPrinter); FGfxPrinter.Init(eOrientation.ePortrait, htmlPrinter, eMarginType.ePrintableArea); this.ppvLetters.InvalidatePreview(); this.ppvLetters.Document = FGfxPrinter.Document; this.ppvLetters.Zoom = 1; // GfxPrinter.Document.EndPrint += new PrintEventHandler(this.EndPrint); } catch (Exception ex) { MessageBox.Show(ex.Message); } btnPDF.Visible = true; btnCopy.Visible = true; lblLoadStatus.Text = ""; }
public static string FormatHtmlReceipt( String ADonorShortName, Int64 ADonorKey, TPartnerClass ADonorClass, String AGiftCurrency, string ALocalCountryCode, AGiftTable AGiftsThisDonor, string AHTMLTemplateFilename, TDBTransaction ATransaction) { SortedList <string, List <string> > FormValues = new SortedList <string, List <string> >(); // These are the fields that can be printed in the letter: FormValues.Add("AdresseeShortName", new List <string>()); FormValues.Add("AdresseeTitle", new List <string>()); FormValues.Add("AdresseeFirstName", new List <string>()); FormValues.Add("AdresseeFamilyName", new List <string>()); FormValues.Add("AdresseeStreetAddress", new List <string>()); FormValues.Add("AdresseeAddress3", new List <string>()); FormValues.Add("AdresseeCity", new List <string>()); FormValues.Add("AdresseePostCode", new List <string>()); FormValues.Add("AdresseeCountry", new List <string>()); FormValues.Add("FormattedAddress", new List <string>()); FormValues.Add("DateToday", new List <string>()); FormValues.Add("DateEntered", new List <string>()); FormValues.Add("GiftAmount", new List <string>()); FormValues.Add("GiftCurrency", new List <string>()); FormValues.Add("GiftTxd", new List <string>()); FormValues.Add("RecipientShortName", new List <string>()); FormValues.Add("MotivationDetail", new List <string>()); FormValues.Add("Reference", new List <string>()); FormValues.Add("DonorComment", new List <string>()); FormValues.Add("GiftTotalAmount", new List <string>()); FormValues.Add("GiftTotalCurrency", new List <string>()); FormValues.Add("TxdTotal", new List <string>()); FormValues.Add("NonTxdTotal", new List <string>()); // Donor Name: FormValues["AdresseeShortName"].Add(ADonorShortName); if (ADonorClass == TPartnerClass.PERSON) { PPersonTable Tbl = PPersonAccess.LoadByPrimaryKey(ADonorKey, ATransaction); if (Tbl.Rows.Count > 0) { FormValues["AdresseeTitle"].Add(Tbl[0].Title); FormValues["AdresseeFirstName"].Add(Tbl[0].FirstName); FormValues["AdresseeFamilyName"].Add(Tbl[0].FamilyName); } } else if (ADonorClass == TPartnerClass.FAMILY) { PFamilyTable Tbl = PFamilyAccess.LoadByPrimaryKey(ADonorKey, ATransaction); if (Tbl.Rows.Count > 0) { FormValues["AdresseeTitle"].Add(Tbl[0].Title); FormValues["AdresseeFirstName"].Add(Tbl[0].FirstName); FormValues["AdresseeFamilyName"].Add(Tbl[0].FamilyName); } } else { FormValues["AdresseeFamilyName"].Add(ADonorShortName); } FormValues["DateToday"].Add(DateTime.Now.ToString("dd MMMM yyyy")); // Donor Adress: PLocationTable Location; PPartnerLocationTable PartnerLocation; string CountryName; string EmailAddress; if (TAddressTools.GetBestAddress(ADonorKey, out Location, out PartnerLocation, out CountryName, out EmailAddress, ATransaction)) { PLocationRow LocRow = Location[0]; FormValues["AdresseeStreetAddress"].Add(LocRow.StreetName); FormValues["AdresseeAddress3"].Add(LocRow.Address3); FormValues["AdresseeCity"].Add(LocRow.City); FormValues["AdresseePostCode"].Add(LocRow.PostalCode); if (LocRow.CountryCode != ALocalCountryCode) // Don't add the Donor's country if it's also my country: { FormValues["AdresseeCountry"].Add(CountryName); } else { LocRow.CountryCode = ""; } FormValues["FormattedAddress"].Add(Calculations.DetermineLocationString(LocRow, Calculations.TPartnerLocationFormatEnum.plfHtmlLineBreak)); } decimal GiftTotal = 0; decimal TxdTotal = 0; decimal NonTxdTotal = 0; // Details per gift: foreach (AGiftRow GiftRow in AGiftsThisDonor.Rows) { String DateEntered = GiftRow.DateEntered.ToString("dd MMM yyyy"); String GiftReference = GiftRow.Reference; AGiftDetailTable DetailTbl = AGiftDetailAccess.LoadViaAGift( GiftRow.LedgerNumber, GiftRow.BatchNumber, GiftRow.GiftTransactionNumber, ATransaction); foreach (AGiftDetailRow DetailRow in DetailTbl.Rows) { FormValues["Reference"].Add(GiftReference); FormValues["DateEntered"].Add(DateEntered); GiftReference = ""; // Date and Reference are one-per-gift, not per detail DateEntered = ""; // so if this gift has several details, I'll blank the subsequent lines. string DonorComment = ""; FormValues["GiftAmount"].Add(StringHelper.FormatUsingCurrencyCode(DetailRow.GiftTransactionAmount, AGiftCurrency)); FormValues["GiftCurrency"].Add(AGiftCurrency); FormValues["MotivationDetail"].Add(DetailRow.MotivationDetailCode); GiftTotal += DetailRow.GiftTransactionAmount; if (DetailRow.TaxDeductible) { FormValues["GiftTxd"].Add("Y"); TxdTotal += DetailRow.GiftTransactionAmount; } else { FormValues["GiftTxd"].Add(" "); NonTxdTotal += DetailRow.GiftTransactionAmount; } // Recipient Short Name: PPartnerTable RecipientTbl = PPartnerAccess.LoadByPrimaryKey(DetailRow.RecipientKey, ATransaction); if (RecipientTbl.Rows.Count > 0) { String ShortName = Calculations.FormatShortName(RecipientTbl[0].PartnerShortName, eShortNameFormat.eReverseShortname); FormValues["RecipientShortName"].Add(ShortName); } if (DetailRow.CommentOneType == "Donor") { DonorComment += DetailRow.GiftCommentOne; } if (DetailRow.CommentTwoType == "Donor") { if (DonorComment != "") { DonorComment += "\r\n"; } DonorComment += DetailRow.GiftCommentTwo; } if (DetailRow.CommentThreeType == "Donor") { if (DonorComment != "") { DonorComment += "\r\n"; } DonorComment += DetailRow.GiftCommentThree; } if (DonorComment != "") { DonorComment = "Comment: " + DonorComment; } FormValues["DonorComment"].Add(DonorComment); } // foreach GiftDetail } // foreach Gift FormValues["GiftTotalAmount"].Add(StringHelper.FormatUsingCurrencyCode(GiftTotal, AGiftCurrency)); FormValues["GiftTotalCurrency"].Add(AGiftCurrency); FormValues["TxdTotal"].Add(StringHelper.FormatUsingCurrencyCode(TxdTotal, AGiftCurrency)); FormValues["NonTxdTotal"].Add(StringHelper.FormatUsingCurrencyCode(NonTxdTotal, AGiftCurrency)); return(TFormLettersTools.PrintSimpleHTMLLetter(AHTMLTemplateFilename, FormValues)); }