コード例 #1
0
ファイル: AddressTools.cs プロジェクト: simhaonline/openpetra
        /// <summary>
        /// Adds The best address to a table of partners
        /// </summary>
        /// <param name="APartners"></param>
        /// <param name="APartnerKeyColumn"></param>
        /// <param name="ATransaction"></param>
        /// <param name="APartnerDetails"></param>
        /// <param name="ABuildAddressBlock"></param>
        public static void AddBestAddressForPartner(ref DataTable APartners,
            int APartnerKeyColumn,
            TDBTransaction ATransaction,
            Boolean APartnerDetails = false,
            Boolean ABuildAddressBlock = false)
        {
            APartners = GetBestAddressForPartnersAsJoinedTable(APartners, APartnerKeyColumn, ATransaction, APartnerDetails);

            if (ABuildAddressBlock)
            {
                DataTable TempTable = APartners.Copy();
                TempTable.Columns.Add("Full_Address");

                foreach (DataRow dr in TempTable.Rows)
                {
                    TFormDataPartner FormData = new TFormDataPartner();
                    FormData.Address1 = dr["addr_p_locality_c"].ToString();
                    FormData.Address3 = dr["addr_p_address_3_c"].ToString();
                    FormData.AddressStreet2 = dr["addr_p_street_name_c"].ToString();
                    FormData.City = dr["addr_p_city_c"].ToString();
                    FormData.CountryCode = dr["addr_p_country_code_c"].ToString();
                    FormData.PostalCode = dr["addr_p_postal_code_c"].ToString();

                    dr["Full_Address"] =
                        TFormLetterTools.BuildAddressBlock(FormData, "ONE_LINE",
                            Shared.SharedTypes.PartnerClassStringToEnum(dr["p_partner_class_c"].ToString()), ATransaction);
                }

                APartners = TempTable.Copy();
            }
        }
コード例 #2
0
        private static int CompareUsingPostalCode(TFormData A, TFormData B)
        {
            TFormDataPartner P1 = A as TFormDataPartner;
            TFormDataPartner P2 = B as TFormDataPartner;

            if ((P1 == null) || (P2 == null))
            {
                throw new ArgumentException("Cannot sort the form data because it is not related to Partner details.");
            }

            string code1 = P1.PostalCode;
            string code2 = P2.PostalCode;

            // Remove any spaces in the code (eg GB codes can have a space)
            code1 = code1.Replace(" ", "");
            code2 = code2.Replace(" ", "");

            // Special cases:
            // Switzerland uses CH- prefix sometimes
            if (code1.StartsWith("CH-"))
            {
                code1 = code1.Substring(3);
            }

            if (code2.StartsWith("CH-"))
            {
                code2 = code2.Substring(3);
            }

            return(CompareInternal(code1, code2));
        }
コード例 #3
0
        private static int CompareUsingCountryName(TFormData A, TFormData B)
        {
            TFormDataPartner P1 = A as TFormDataPartner;
            TFormDataPartner P2 = B as TFormDataPartner;

            if ((P1 == null) || (P2 == null))
            {
                throw new ArgumentException("Cannot sort the form data because it is not related to Partner details.");
            }

            return(CompareInternal(P1.CountryName, P2.CountryName));
        }
コード例 #4
0
        private static int CompareUsingPostCodeRegion(TFormData A, TFormData B)
        {
            TFormDataPartner P1 = A as TFormDataPartner;
            TFormDataPartner P2 = B as TFormDataPartner;

            if ((P1 == null) || (P2 == null))
            {
                throw new ArgumentException("Cannot sort the form data because it is not related to Partner details.");
            }

            // At the moment TFormDataPartner does not have a PostcodeRegion property
            throw new NotImplementedException();
        }
コード例 #5
0
        public static String BuildAddressBlock(TFormDataPartner AFormData,
                                               String AAddressLayoutCode,
                                               TPartnerClass APartnerClass,
                                               TDBTransaction ATransaction)
        {
            PAddressBlockTable AddressBlockTable;
            String             AddressLayoutBlock = "";

            if ((AAddressLayoutCode == null) ||
                (AAddressLayoutCode == ""))
            {
                // this should not happen but just in case we use SMLLABEL as default layout code
                AddressBlockTable = PAddressBlockAccess.LoadByPrimaryKey(AFormData.CountryCode, "SMLLABEL", ATransaction);

                if (AddressBlockTable.Count == 0)
                {
                    // if no address block layout could be found for given country then try to retrieve for default "99"
                    AddressBlockTable = PAddressBlockAccess.LoadByPrimaryKey("99", "SMLLABEL", ATransaction);
                }
            }
            else
            {
                AddressBlockTable = PAddressBlockAccess.LoadByPrimaryKey(AFormData.CountryCode, AAddressLayoutCode, ATransaction);

                if (AddressBlockTable.Count == 0)
                {
                    // if no address block layout could be found for given country then try to retrieve for default "99"
                    AddressBlockTable = PAddressBlockAccess.LoadByPrimaryKey("99", AAddressLayoutCode, ATransaction);
                }
            }

            if (AddressBlockTable.Count == 0)
            {
                return("");
            }
            else
            {
                PAddressBlockRow AddressBlockRow = (PAddressBlockRow)AddressBlockTable.Rows[0];
                AddressLayoutBlock = AddressBlockRow.AddressBlockText;
            }

            return(BuildAddressBlock(AddressLayoutBlock, AFormData, APartnerClass, ATransaction));
        }
コード例 #6
0
        private static int CompareUsingFirstNameLastName(TFormData A, TFormData B)
        {
            TFormDataPartner P1 = A as TFormDataPartner;
            TFormDataPartner P2 = B as TFormDataPartner;

            if ((P1 == null) || (P2 == null))
            {
                throw new ArgumentException("Cannot sort the form data because it is not related to Partner details.");
            }

            int byFirstName = CompareInternal(P1.FirstName, P2.FirstName);

            if (byFirstName != 0)
            {
                return(byFirstName);
            }

            return(CompareInternal(P1.LastName, P2.LastName));
        }
コード例 #7
0
        public static String BuildAddressBlock(String AAddressLayoutBlock,
                                               TFormDataPartner AFormData,
                                               TPartnerClass APartnerClass,
                                               TDBTransaction ATransaction)
        {
            String AddressBlock = "";

            List <String> AddressTokenList     = new List <String>();
            String        AddressLineText      = "";
            String        AddressLineTokenText = "";
            Boolean       PrintAnyway          = false;
            Boolean       CapsOn           = false;
            Boolean       UseContact       = false;
            String        SpacePlaceholder = "";

            PPersonTable PersonTable;
            PPersonRow   PersonRow = null;
            PFamilyTable FamilyTable;
            PFamilyRow   FamilyRow         = null;
            Int64        ContactPartnerKey = 0;

            AddressTokenList = BuildTokenListFromAddressLayoutBlock(AAddressLayoutBlock);

            // initialize values
            AddressLineText = "";
            PrintAnyway     = false;

            foreach (String AddressLineToken in AddressTokenList)
            {
                switch (AddressLineToken)
                {
                case "[[TitleAndSpace]]":
                case "[[FirstNameAndSpace]]":
                case "[[FirstInitialAndSpace]]":
                case "[[LastNameAndSpace]]":

                    SpacePlaceholder = " ";
                    break;

                default:

                    SpacePlaceholder = "";
                    break;
                }

                switch (AddressLineToken)
                {
                case "[[AcademicTitle]]":

                    if (UseContact)
                    {
                        if (PersonRow != null)
                        {
                            AddressLineText += ConvertIfUpperCase(PersonRow.AcademicTitle, CapsOn);
                        }
                    }
                    else
                    {
                        if (AFormData.GetType() == typeof(TFormDataPerson))
                        {
                            AddressLineText += ConvertIfUpperCase(((TFormDataPerson)AFormData).AcademicTitle, CapsOn);
                        }
                    }

                    break;

                case "[[AddresseeType]]":
                    AddressLineText += ConvertIfUpperCase(AFormData.AddresseeType, CapsOn);
                    break;

                case "[[Address3]]":
                    AddressLineText += ConvertIfUpperCase(AFormData.Address3, CapsOn);
                    break;

                case "[[CapsOn]]":
                    CapsOn = true;
                    break;

                case "[[CapsOff]]":
                    CapsOn = false;
                    break;

                case "[[City]]":
                    AddressLineText += ConvertIfUpperCase(AFormData.City, CapsOn);
                    break;

                case "[[CountryName]]":
                    AddressLineText += ConvertIfUpperCase(AFormData.CountryName, CapsOn);
                    break;

                case "[[CountryInLocalLanguage]]":
                    AddressLineText += ConvertIfUpperCase(AFormData.CountryInLocalLanguage, CapsOn);
                    break;

                case "[[County]]":
                    AddressLineText += ConvertIfUpperCase(AFormData.County, CapsOn);
                    break;

                case "[[UseContact]]":

                    /* Get the person or family record that is acting as the contact
                     *  only applicable to churches and organisations. */
                    switch (APartnerClass)
                    {
                    case TPartnerClass.CHURCH:
                        PChurchTable ChurchTable;
                        PChurchRow   ChurchRow;
                        ChurchTable = PChurchAccess.LoadByPrimaryKey(Convert.ToInt64(AFormData.PartnerKey), ATransaction);

                        if (ChurchTable.Count > 0)
                        {
                            ChurchRow = (PChurchRow)ChurchTable.Rows[0];

                            if (!ChurchRow.IsContactPartnerKeyNull())
                            {
                                ContactPartnerKey = ChurchRow.ContactPartnerKey;
                            }
                        }

                        break;

                    case TPartnerClass.ORGANISATION:
                        POrganisationTable OrganisationTable;
                        POrganisationRow   OrganisationRow;
                        OrganisationTable = POrganisationAccess.LoadByPrimaryKey(Convert.ToInt64(AFormData.PartnerKey), ATransaction);

                        if (OrganisationTable.Count > 0)
                        {
                            OrganisationRow = (POrganisationRow)OrganisationTable.Rows[0];

                            if (!OrganisationRow.IsContactPartnerKeyNull())
                            {
                                ContactPartnerKey = OrganisationRow.ContactPartnerKey;
                            }
                        }

                        break;

                    default:
                        ContactPartnerKey = 0;
                        break;
                    }

                    if (ContactPartnerKey > 0)
                    {
                        PersonTable = PPersonAccess.LoadByPrimaryKey(ContactPartnerKey, ATransaction);

                        if (PersonTable.Count > 0)
                        {
                            PersonRow = (PPersonRow)PersonTable.Rows[0];
                        }
                        else
                        {
                            FamilyTable = PFamilyAccess.LoadByPrimaryKey(ContactPartnerKey, ATransaction);

                            if (FamilyTable.Count > 0)
                            {
                                FamilyRow = (PFamilyRow)FamilyTable.Rows[0];
                            }
                        }
                    }

                    UseContact = true;
                    break;

                case "[[CountryCode]]":
                    AddressLineText += ConvertIfUpperCase(AFormData.CountryCode, CapsOn);
                    break;

                case "[[Decorations]]":

                    if (UseContact)
                    {
                        if (PersonRow != null)
                        {
                            AddressLineText += ConvertIfUpperCase(PersonRow.Decorations, CapsOn);
                        }
                    }
                    else
                    {
                        if (AFormData.GetType() == typeof(TFormDataPerson))
                        {
                            AddressLineText += ConvertIfUpperCase(((TFormDataPerson)AFormData).Decorations, CapsOn);
                        }
                    }

                    break;

                case "[[FirstName]]":
                case "[[FirstNameAndSpace]]":

                    AddressLineTokenText = "";

                    if (UseContact)
                    {
                        if (PersonRow != null)
                        {
                            AddressLineTokenText = ConvertIfUpperCase(PersonRow.FirstName, CapsOn);
                        }
                        else if (FamilyRow != null)
                        {
                            AddressLineTokenText = ConvertIfUpperCase(FamilyRow.FirstName, CapsOn);
                        }
                    }
                    else
                    {
                        AddressLineTokenText = ConvertIfUpperCase(AFormData.FirstName, CapsOn);
                    }

                    if ((AddressLineTokenText != null) &&
                        (AddressLineTokenText.Length > 0))
                    {
                        AddressLineText += AddressLineTokenText + SpacePlaceholder;
                    }

                    break;

                case "[[FirstInitial]]":
                case "[[FirstInitialAndSpace]]":

                    AddressLineTokenText = "";

                    if (UseContact)
                    {
                        if (PersonRow != null)
                        {
                            if (PersonRow.FirstName.Length > 0)
                            {
                                AddressLineTokenText = ConvertIfUpperCase(PersonRow.FirstName.Substring(0, 1), CapsOn);
                            }
                        }
                        else if (FamilyRow != null)
                        {
                            if (PersonRow.FirstName.Length > 0)
                            {
                                AddressLineTokenText = ConvertIfUpperCase(FamilyRow.FirstName.Substring(0, 1), CapsOn);
                            }
                        }
                    }
                    else
                    {
                        if (AFormData.FirstName.Length > 0)
                        {
                            AddressLineTokenText = ConvertIfUpperCase(AFormData.FirstName.Substring(0, 1), CapsOn);
                        }
                    }

                    if ((AddressLineTokenText != null) &&
                        (AddressLineTokenText.Length > 0))
                    {
                        AddressLineText += AddressLineTokenText + SpacePlaceholder;
                    }

                    break;

                case "[[LastName]]":
                case "[[LastNameAndSpace]]":

                    AddressLineTokenText = "";

                    if (UseContact)
                    {
                        if (PersonRow != null)
                        {
                            AddressLineTokenText = ConvertIfUpperCase(PersonRow.FamilyName, CapsOn);
                        }
                        else if (FamilyRow != null)
                        {
                            AddressLineTokenText = ConvertIfUpperCase(FamilyRow.FamilyName, CapsOn);
                        }
                    }
                    else
                    {
                        AddressLineTokenText = ConvertIfUpperCase(AFormData.LastName, CapsOn);
                    }

                    if ((AddressLineTokenText != null) &&
                        (AddressLineTokenText.Length > 0))
                    {
                        AddressLineText += AddressLineTokenText + SpacePlaceholder;
                    }

                    break;

                case "[[Address1]]":
                    AddressLineText += ConvertIfUpperCase(AFormData.Address1, CapsOn);
                    break;

                case "[[MiddleName]]":

                    if (UseContact)
                    {
                        if (PersonRow != null)
                        {
                            AddressLineText += ConvertIfUpperCase(PersonRow.MiddleName1, CapsOn);
                        }
                    }
                    else
                    {
                        if (AFormData.GetType() == typeof(TFormDataPerson))
                        {
                            AddressLineText += ConvertIfUpperCase(((TFormDataPerson)AFormData).MiddleName, CapsOn);
                        }
                    }

                    break;

                case "[[Org/Church]]":

                    /* if the contact person is being printed then might still want the
                     *  Organisation or Church name printed.  This does it but only if there
                     *  is a valid contact. */
                    if (UseContact)
                    {
                        AddressLineText += ConvertIfUpperCase(AFormData.ShortName, CapsOn);
                    }

                    break;

                case "[[PartnerKey]]":
                    AddressLineText += ConvertIfUpperCase(AFormData.PartnerKey, CapsOn);
                    break;

                case "[[ShortName]]":
                    AddressLineText += ConvertIfUpperCase(AFormData.ShortName, CapsOn);
                    break;

                case "[[LocalName]]":

                    if (AFormData.LocalName != "")
                    {
                        AddressLineText += ConvertIfUpperCase(AFormData.LocalName, CapsOn);
                    }
                    else
                    {
                        AddressLineText += ConvertIfUpperCase(AFormData.ShortName, CapsOn);
                    }

                    break;

                case "[[PostalCode]]":
                    AddressLineText += ConvertIfUpperCase(AFormData.PostalCode, CapsOn);
                    break;

                case "[[Enclosures]]":
                    AddressLineText += AFormData.Enclosures;
                    break;

                case "[[MailingCode]]":
                    AddressLineText += AFormData.MailingCode;
                    break;

                case "[[Tab]]":
                    AddressLineText += "\t";
                    break;

                case "[[Space]]":
                    AddressLineText += " ";
                    break;

                case "[[AddressStreet2]]":
                    AddressLineText += ConvertIfUpperCase(AFormData.AddressStreet2, CapsOn);
                    break;

                case "[[Title]]":
                case "[[TitleAndSpace]]":
                    AddressLineTokenText = ConvertIfUpperCase(AFormData.Title, CapsOn);

                    if ((AddressLineTokenText != null) &&
                        (AddressLineTokenText.Length > 0))
                    {
                        AddressLineText += AddressLineTokenText + SpacePlaceholder;
                    }

                    break;

                case "[[NoSuppress]]":
                    PrintAnyway = true;
                    break;

                case "[[LocationKey]]":
                    AddressLineText += AFormData.LocationKey;
                    break;

                case "[[LineFeed]]":

                    // only add line if not empty and not suppressed
                    if (PrintAnyway ||
                        (!PrintAnyway &&
                         (AddressLineText.Trim() != "")))
                    {
                        AddressBlock += AddressLineText + "\r\n";
                    }

                    // reset values
                    AddressLineText = "";
                    PrintAnyway     = false;
                    break;

                default:
                    AddressLineText += ConvertIfUpperCase(AddressLineToken, CapsOn);
                    break;
                }
            }

            // this is only for last line if there was no line feed:
            // only add line if not empty and not suppressed
            if (PrintAnyway ||
                (!PrintAnyway &&
                 (AddressLineText.Trim() != "")))
            {
                AddressBlock += AddressLineText + "\r\n";
            }

            // or just get the element list from cached table (since we need to get different ones depending on country)

            return(AddressBlock);
        }
コード例 #8
0
ファイル: AP.Remittance.cs プロジェクト: weiplanet/openpetra
        private static void CreateFormDataInternal(Int32 ALedgerNumber, int APaymentNumber,
                                                   TFormLetterFinanceInfo AFormLetterFinanceInfo, List <TFormData> AFormDataList, bool AIncludeChequeFormData,
                                                   int AChequeNumber = 0, string AChequeAmountInWords = "")
        {
            // Get all the details for this payment.  This creates a transaction.
            AccountsPayableTDS paymentDetails = TAPTransactionWebConnector.LoadAPPayment(ALedgerNumber, APaymentNumber);

            if (paymentDetails.PPartner.Rows.Count == 0) // unable to load this partner..
            {
                return;
            }

            if (paymentDetails.AApPayment.Rows.Count == 0) // unable to load this payment..
            {
                return;
            }

            if (AIncludeChequeFormData && paymentDetails.AApPayment[0].PrintCheque && (paymentDetails.AApPayment[0].Amount <= 0.0m))
            {
                // Cannot print cheques unless they are for a positive amount
                return;
            }

            TFormDataPartner formData = new TFormDataPartner();

            // Deal with the supplier part
            Int64 supplierKey = paymentDetails.PPartner[0].PartnerKey;

            TFormLettersWebConnector.FillFormDataFromPartner(supplierKey, formData, AFormLetterFinanceInfo);

            // Deal with the top-level details of the Payment in the ApPayment table.  This will only have one row
            //  but may contain information about multiple invoices (documents)
            formData.PaymentNumber = paymentDetails.AApPayment[0].PaymentNumber;

            formData.PaymentDate = paymentDetails.AApPayment[0].PaymentDate.HasValue ?
                                   paymentDetails.AApPayment[0].PaymentDate.Value.ToString("dd MMMM yyyy") : string.Empty;
            formData.TotalPayment = paymentDetails.AApPayment[0].Amount.ToString(
                "N2");

            formData.OurReference =
                (paymentDetails.AApSupplier.Rows.Count > 0) ? paymentDetails.AApSupplier[0].OurReference : string.Empty;

            string currencyCode = string.Empty;

            // A payment may be made up of multiple invoices
            foreach (AApDocumentRow documentRow in paymentDetails.AApDocument.Rows)
            {
                TFormDataAPPayment invoiceDetails = new TFormDataAPPayment();
                invoiceDetails.InvoiceNumber = documentRow.DocumentCode;
                invoiceDetails.InvoiceDate   = documentRow.DateIssued.ToString("dd MMMM yyyy");
                invoiceDetails.InvoiceAmount = documentRow.TotalAmount.ToString(
                    "N2");
                invoiceDetails.InvoiceCurrencyCode =
                    (paymentDetails.AApSupplier.Rows.Count > 0) ? paymentDetails.AApSupplier[0].CurrencyCode : string.Empty;
                currencyCode = invoiceDetails.InvoiceCurrencyCode;

                invoiceDetails.PaymentAmount = string.Empty;

                // An invoice in this payment may only be part-paid, so how much of the invoice amount was paid in this payment??
                foreach (AApDocumentPaymentRow documentPayment in paymentDetails.AApDocumentPayment.Rows)
                {
                    if ((documentPayment.ApDocumentId == documentRow.ApDocumentId) &&
                        (documentPayment.PaymentNumber == paymentDetails.AApPayment[0].PaymentNumber))
                    {
                        invoiceDetails.PaymentAmount = documentPayment.Amount.ToString("N2");
                    }
                }

                formData.AddPayment(invoiceDetails);
            }

            formData.CurrencyCode = currencyCode;

            if (AIncludeChequeFormData && paymentDetails.AApPayment[0].PrintCheque)
            {
                formData.ChequeDate          = DateTime.Today.ToString("dd MMM yyyy");
                formData.ChequeAmountToPay   = paymentDetails.AApPayment[0].Amount.ToString("n2");
                formData.ChequeAmountInWords = AChequeAmountInWords;
                formData.ChequeNumber        = AChequeNumber.ToString("D6");
            }

            AFormDataList.Add(formData);
        }