public DanishFormatFieldBase SecondaryCreateDomesticFormatField(CreditorTransPayment tran,
                                                                        CreditorPaymentFormat paymentFormat, BankStatement bankAccount, Company company, bool glJournalGenerated = false)
        {
            var danishFields = new BankDataFormatFields();

            SharedCodeForCreateBankFormatFields(company, tran, paymentFormat, bankAccount, danishFields);
            DomesticPaymentType(danishFields, tran);

            danishFields.TransTypeCommand = BankDataPayFormat.TRANSTYPE_IB030202000005;
            danishFields.Index            = BankDataPayFormat.INDEX02;
            danishFields.SenderName       = NETSNorge.processString(company._Name, 35, false);
            danishFields.SenderAddress1   = NETSNorge.processString(company._Address1, 35, false);
            danishFields.SenderAddress2   = NETSNorge.processString(company._Address2, 35, false);
            danishFields.SenderAddress3   = NETSNorge.processString(company._Address3, 35, false);

            danishFields.ReservetForXML = new List <string>
            {
                NETSNorge.processString(string.Empty, 35, false),
                NETSNorge.processString(string.Empty, 35, false),
                NETSNorge.processString(string.Empty, 35, false),
                NETSNorge.processString(string.Empty, 35, false),

                NETSNorge.processString(string.Empty, 48, false),
                NETSNorge.processString(string.Empty, 255, false),
                NETSNorge.processString(string.Empty, 255, false)
            };

            return(danishFields);
        }
        public static void CreateStartAndEnd(List <DanishFormatFieldBase> listofBankProperties, StreamWriter sw, bool isStartOrEnd)
        {
            var endObject = new BankDataFormatFields();

            endObject.TransferDate = BasePage.GetSystemDefaultDate().Date;

            var listOfBankData = listofBankProperties.OfType <BankDataFormatFields>().Where(bankData => bankData.Index == INDEX01).ToList();

            endObject.TotalPayments = listOfBankData.Count;

            var totalAmount   = listofBankProperties.OfType <BankDataFormatFields>().Aggregate(0.0, (current, bp) => current + bp.AmountLong);
            var lineamountint = NumberConvert.ToLong(totalAmount);

            endObject.TotalAmount = lineamountint;

            string stringWithEmpty;

            if (isStartOrEnd)
            {
                endObject.TransTypeCommand = TRANSTYPE_IB000000000000;
                stringWithEmpty            = new string(' ', 90);
            }
            else
            {
                endObject.TransTypeCommand = TRANSTYPE_IB999999999999;
                stringWithEmpty            = new string(' ', 64);
            }

            endObject.OtherTransfers = new List <string>()
            {
                stringWithEmpty,
                new string(' ', 255),
                new string(' ', 255),
                new string(' ', 255)
            };

            const char seperator = ',';

            sw.Write("\"{0}\",", endObject.TransTypeCommand);
            sw.Write("\"{0:yyyyMMdd}\"", endObject.TransferDate);
            if (!isStartOrEnd)
            {
                sw.Write(seperator);
                sw.Write("\"{0:D6}\",", endObject.TotalPayments);
                sw.Write("\"{0:D13}+\"", endObject.TotalAmount);
            }
            foreach (var oT in endObject.OtherTransfers)
            {
                sw.Write(seperator);
                sw.Write('"');
                sw.Write(oT);
                sw.Write('"');
            }
            sw.WriteLine();
        }
        public DanishFormatFieldBase CreateIndbetalingskortFormatField(CreditorTransPayment tran,
                                                                       CreditorPaymentFormat paymentFormat,
                                                                       BankStatement bankAccount,
                                                                       Uniconta.DataModel.Creditor creditor,
                                                                       Company company,
                                                                       bool glJournalGenerated = false)
        {
            var danishFields = new BankDataFormatFields();

            SharedCodeForCreateBankFormatFields(company, tran, paymentFormat, bankAccount, danishFields);
            SharedFIKPayment(danishFields, tran);

            danishFields.TransTypeCommand = BankDataPayFormat.TRANSTYPE_IB030207000002;
            danishFields.Index            = BankDataPayFormat.INDEX01;

            var lineamountint = NumberConvert.ToLong(tran.PaymentAmount * 100d);

            danishFields.AmountLong = lineamountint;

            danishFields.FromAccountType = 2;
            danishFields.GiroReg         = NETSNorge.processString(string.Empty, 4, false);

            if (danishFields.FormType == BankFormatBase.FIK04)
            {
                danishFields.ToAccountGiro     = NETSNorge.processString(danishFields.ToAccountNumber, 10, false);
                danishFields.ToAccountCreditor = NETSNorge.processString(string.Empty, 8, false);
            }
            else
            {
                danishFields.ToAccountGiro     = NETSNorge.processString(string.Empty, 10, false);
                danishFields.ToAccountCreditor = NETSNorge.processString(danishFields.ToAccountNumber, 8, false);
            }
            string credName = glJournalGenerated ? string.Empty : tran.Creditor.Name;

            danishFields.NameOfReceiver   = NETSNorge.processString(credName, 32, false);
            danishFields.AlternativSender = NETSNorge.processString(string.Empty, 32, false);

            var internalAdvText = StandardPaymentFunctions.InternalMessage(paymentFormat._OurMessage, tran, company, creditor);

            danishFields.OwnVoucherNumber = NETSNorge.processString(internalAdvText, 35, false);

            danishFields.SenderName     = NETSNorge.processString(company._Name, 35, false);
            danishFields.SenderAddress1 = NETSNorge.processString(company._Address1, 35, false);
            danishFields.SenderAddress2 = NETSNorge.processString(company._Address2, 35, false);
            danishFields.SenderAddress3 = NETSNorge.processString(company._Address3, 35, false);
            danishFields.Blanks         = NETSNorge.processString(string.Empty, 35, false);

            if (danishFields.FormType == BankFormatBase.FIK73 || danishFields.FormType == BankFormatBase.FIK75)
            {
                var externalAdvText = StandardPaymentFunctions.ExternalMessage(paymentFormat._Message, tran, company, creditor);
                var message         = externalAdvText;

                message = NETSNorge.processString(message, 210, false);

                int maxStrLen = 35;
                int maxLines  = 6;

                List <string> messageList = new List <string>();

                if (message != string.Empty)
                {
                    if (message.Length > maxLines * maxStrLen)
                    {
                        message = message.Substring(0, maxLines * maxStrLen);
                    }

                    messageList = message.Select((x, i) => i)
                                  .Where(i => i % maxStrLen == 0)
                                  .Select(i => message.Substring(i, message.Length - i >= maxStrLen ? maxStrLen : message.Length - i)).ToList <string>();
                }

                danishFields.ReceiverAccountInfo = messageList;
            }
            else
            {
                danishFields.ReceiverAccountInfo = new List <string>()
                {
                    NETSNorge.processString(string.Empty, 35, false),
                    NETSNorge.processString(string.Empty, 35, false),
                    NETSNorge.processString(string.Empty, 35, false),
                    NETSNorge.processString(string.Empty, 35, false),
                    NETSNorge.processString(string.Empty, 35, false),
                    NETSNorge.processString(string.Empty, 35, false),
                };
            }

            danishFields.Blanks2  = NETSNorge.processString(string.Empty, 16, false);
            danishFields.Reserved = NETSNorge.processString(string.Empty, 215, false);

            danishFields.UniquePaymRef = tran.PaymentEndToEndId.ToString();

            return(danishFields);
        }
        public DanishFormatFieldBase CreateForeignFormatField(CreditorTransPayment tran,
                                                              CreditorPaymentFormat paymentFormat,
                                                              BankStatement bankAccount,
                                                              Uniconta.DataModel.Creditor creditor,
                                                              Company company,
                                                              bool glJournalGenerated = false)
        {
            var danishFields = new BankDataFormatFields();

            SharedCodeForCreateBankFormatFields(company, tran, paymentFormat, bankAccount, danishFields);
            SharedForeignReceiverBankInfo(danishFields, tran);

            var externalAdvText = StandardPaymentFunctions.ExternalMessage(paymentFormat._Message, tran, company, creditor);
            var message         = externalAdvText;

            message = NETSNorge.processString(message, 140, false);

            int maxStrLen = 35;
            int maxLines  = 4;

            List <string> messageList = new List <string>();

            if (message != string.Empty)
            {
                if (message.Length > maxLines * maxStrLen)
                {
                    message = message.Substring(0, maxLines * maxStrLen);
                }

                messageList = message.Select((x, i) => i)
                              .Where(i => i % maxStrLen == 0)
                              .Select(i => message.Substring(i, message.Length - i >= maxStrLen ? maxStrLen : message.Length - i)).ToList <string>();
            }

            danishFields.DescriptionOfPayment = messageList;

            danishFields.TransTypeCommand = BankDataPayFormat.TRANSTYPE_IB030204000003;
            danishFields.Index            = BankDataPayFormat.INDEX01;

            var lineamountint = NumberConvert.ToLong(tran.PaymentAmount * 100d);

            danishFields.AmountLong = lineamountint;

            danishFields.FromAccountType = 2;

            danishFields.TransferCoin = new string(' ', 3);

            var paymentType = ISOPaymentType(tran.CurrencyLocalStr, bankAccount, danishFields.ReceiverIBAN, company);

            danishFields.TransferType = paymentType == UnicontaISO20022CreditTransfer.ISO20022PaymentTypes.SEPA ? BankDataPayFormat.FOREIGN_SEPATRANSFER : BankDataPayFormat.FOREIGN_STANDARDTRANSFER;

            if (glJournalGenerated)
            {
                danishFields.NameOfReceiver     = NETSNorge.processString(string.Empty, 35, false);
                danishFields.AddressOfReceiver  = NETSNorge.processString(string.Empty, 35, false);
                danishFields.AddressOfReceiver2 = NETSNorge.processString(string.Empty, 35, false);
            }
            else
            {
                danishFields.NameOfReceiver     = NETSNorge.processString(tran.Creditor.Name, 35, false);
                danishFields.AddressOfReceiver  = NETSNorge.processString(tran.Creditor.Address1 + ", " + tran.Creditor.ZipCode + " " + tran.Creditor.City, 35, false);
                danishFields.AddressOfReceiver2 = NETSNorge.processString(tran.Creditor.Address2, 35, false);
            }

            danishFields.OtherTransfers = new List <string>()
            {
                NETSNorge.processString(string.Empty, 35, false),
                NETSNorge.processString(string.Empty, 4, false),
                NETSNorge.processString(string.Empty, 6, false),
                NETSNorge.processString(string.Empty, 2, false),
                NETSNorge.processString(string.Empty, 75, false),
                NETSNorge.processString(string.Empty, 75, false),
                NETSNorge.processString(string.Empty, 75, false),
                NETSNorge.processString(string.Empty, 24, false),
                NETSNorge.processString(string.Empty, 215, false)
            };

            danishFields.UniquePaymRef = tran.PaymentEndToEndId.ToString();

            return(danishFields);
        }
        public DanishFormatFieldBase SecondaryCreateForeignFormatField(CreditorTransPayment tran,
                                                                       CreditorPaymentFormat paymentFormat,
                                                                       BankStatement bankAccount,
                                                                       Uniconta.DataModel.Creditor creditor,
                                                                       Company company,
                                                                       bool glJournalGenerated = false
                                                                       )
        {
            var danishFields = new BankDataFormatFields();

            SharedCodeForCreateBankFormatFields(company, tran, paymentFormat, bankAccount, danishFields);
            SharedForeignReceiverBankInfo(danishFields, tran);

            danishFields.TransTypeCommand = BankDataPayFormat.TRANSTYPE_IB030204000003;
            danishFields.Index            = BankDataPayFormat.INDEX02;


            danishFields.Blanks       = NETSNorge.processString(string.Empty, 1, false);
            danishFields.SwiftAddress = NETSNorge.processString(danishFields.SwiftAddress, 11, false);

            danishFields.ReceiverBankInfo = new List <string>()
            {
                NETSNorge.processString("Bank", 35, false),    //Dummy text - ask bank if correct Bank name is needed
                NETSNorge.processString("Address", 35, false), //Dummy text - ask bank if correct Bank address is needed
                NETSNorge.processString(string.Empty, 35, false),
                NETSNorge.processString(danishFields.CountryCode, 35, false),
                NETSNorge.processString(string.Empty, 33, false) //BankCode
            };


            danishFields.ToAccountNumber = NETSNorge.processString(danishFields.ToAccountNumber, 34, false);
            danishFields.ReceiverIBAN    = NETSNorge.processString(danishFields.ReceiverIBAN, 35, false);

            var paymentType = ISOPaymentType(tran.CurrencyLocalStr, bankAccount, danishFields.ReceiverIBAN, company);

            danishFields.TransferType        = paymentType == UnicontaISO20022CreditTransfer.ISO20022PaymentTypes.SEPA ? 1 : 0;;
            danishFields.TransferTypeForeign = 1; //Cross border payments always paid by receiver
            danishFields.Blanks2             = NETSNorge.processString(string.Empty, 15, false);

            danishFields.Messages = new List <string>()
            {
                NETSNorge.processString(string.Empty, 35, false),
                NETSNorge.processString(string.Empty, 35, false),
                NETSNorge.processString(string.Empty, 35, false)
            };

            var internalAdvText = StandardPaymentFunctions.InternalMessage(paymentFormat._OurMessage, tran, company, creditor);

            danishFields.OwnVoucherNumber = NETSNorge.processString(internalAdvText, 35, false);

            danishFields.SenderInformation = new List <string>()
            {
                NETSNorge.processString(string.Empty, 15, false),
                NETSNorge.processString(string.Empty, 13, false),
                NETSNorge.processString(string.Empty, 1, false),
                NETSNorge.processString(string.Empty, 7, false),
                NETSNorge.processString(string.Empty, 15, false),
                NETSNorge.processString(string.Empty, 13, false),
                NETSNorge.processString(string.Empty, 1, false),
                NETSNorge.processString(string.Empty, 7, false),
                NETSNorge.processString(string.Empty, 15, false),
                NETSNorge.processString(string.Empty, 13, false),
                NETSNorge.processString(string.Empty, 1, false),
                NETSNorge.processString(string.Empty, 7, false),
                NETSNorge.processString(string.Empty, 15, false),
                NETSNorge.processString(string.Empty, 13, false),
                NETSNorge.processString(string.Empty, 1, false),
                NETSNorge.processString(string.Empty, 7, false),
                NETSNorge.processString(string.Empty, 15, false),
                NETSNorge.processString(string.Empty, 13, false),
                NETSNorge.processString(string.Empty, 1, false),
                NETSNorge.processString(string.Empty, 7, false),
                NETSNorge.processString(string.Empty, 169, false),
            };


            danishFields.UniquePaymRef = tran.PaymentEndToEndId.ToString();

            return(danishFields);
        }
        public DanishFormatFieldBase CreateDomesticFormatField(CreditorTransPayment tran, CreditorPaymentFormat paymentFormat,
                                                               BankStatement bankAccount, Uniconta.DataModel.Creditor creditor, Company company, bool glJournalGenerated = false)
        {
            var danishFields = new BankDataFormatFields();

            SharedCodeForCreateBankFormatFields(company, tran, paymentFormat, bankAccount, danishFields);
            DomesticPaymentType(danishFields, tran);

            danishFields.TransTypeCommand = BankDataPayFormat.TRANSTYPE_IB030202000005;
            danishFields.Index            = BankDataPayFormat.INDEX01;

            var lineamountint = NumberConvert.ToLong(tran.PaymentAmount * 100d);

            danishFields.AmountLong = lineamountint;

            danishFields.FromAccountType     = 2;
            danishFields.TransferType        = 2;
            danishFields.ClearingTypeChannel = "0";

            if (glJournalGenerated)
            {
                danishFields.NameOfReceiver     = NETSNorge.processString(string.Empty, 32, false);
                danishFields.AddressOfReceiver  = NETSNorge.processString(string.Empty, 32, false);
                danishFields.AddressOfReceiver2 = NETSNorge.processString(string.Empty, 32, false);
                danishFields.ZipCodeOfReceiver  = NETSNorge.processString(string.Empty, 4, false);
                danishFields.CityOfReceiver     = NETSNorge.processString(string.Empty, 32, false);
            }
            else
            {
                danishFields.NameOfReceiver     = NETSNorge.processString(tran.Creditor.Name, 32, false);
                danishFields.AddressOfReceiver  = NETSNorge.processString(tran.Creditor.Address1, 32, false);
                danishFields.AddressOfReceiver2 = NETSNorge.processString(tran.Creditor.Address2, 32, false);
                danishFields.ZipCodeOfReceiver  = NETSNorge.processString(tran.Creditor.ZipCode, 4, false);
                danishFields.CityOfReceiver     = NETSNorge.processString(tran.Creditor.City, 32, false);
            }

            var internalAdvText = StandardPaymentFunctions.InternalMessage(paymentFormat._OurMessage, tran, company, creditor);

            danishFields.OwnVoucherNumber = NETSNorge.processString(internalAdvText, 35, false);

            //Message to Beneficiary >>
            var externalAdvText = StandardPaymentFunctions.ExternalMessage(paymentFormat._Message, tran, company, creditor);
            var message         = externalAdvText;

            danishFields.ReceiverAccountStatement = NETSNorge.processString(externalAdvText, 35, false);

            //Extended notification
            if (paymentFormat._ExtendedText)
            {
                if (message == null || message.Length <= 35)
                {
                    message = string.Empty;
                }
            }
            else
            {
                message = string.Empty;
            }

            message = NETSNorge.processString(message, 315, false);

            int maxStrLen = 35;
            int maxLines  = 9;

            List <string> messageList = new List <string>();

            if (message != string.Empty)
            {
                if (message.Length > maxLines * maxStrLen)
                {
                    message = message.Substring(0, maxLines * maxStrLen);
                }

                messageList = message.Select((x, i) => i)
                              .Where(i => i % maxStrLen == 0)
                              .Select(i => message.Substring(i, message.Length - i >= maxStrLen ? maxStrLen : message.Length - i)).ToList <string>();
            }

            //danishFields.ReceiverAccountStatement = NETSNorge.processString(message, 35, false);
            danishFields.AdviceText = messageList;
            //Message to Beneficiary <<

            danishFields.Blanks  = NETSNorge.processString(string.Empty, 1, false);
            danishFields.Blanks2 = NETSNorge.processString(string.Empty, 215, false);

            danishFields.UniquePaymRef = tran.PaymentEndToEndId.ToString();

            return(danishFields);
        }