Esempio n. 1
0
        /**
         *  Export to File
         *  @param checks array of checks
         *  @param file file to export checks
         *  @return number of lines
         */
        public static int ExportToFile(MPaySelectionCheck[] checks, File file)
        {
            if (checks == null || checks.Length == 0)
            {
                return(0);
            }
            //  Must be a file
            if (file.isDirectory())
            {
                _log.Log(Level.WARNING, "File is directory - " + file.getAbsolutePath());
                return(0);
            }
            //  delete if exists
            try
            {
                if (file.exists())
                {
                    file.delete();
                }
            }
            catch (Exception e)
            {
                _log.Log(Level.WARNING, "Could not delete - " + file.getAbsolutePath(), e);
            }

            char          x       = '"'; //  ease
            int           noLines = 0;
            StringBuilder line    = null;

            try
            {
                FileWriter fw = new FileWriter(file);

                //  write header
                line = new StringBuilder();
                line.Append(x).Append("Value").Append(x).Append(",")
                .Append(x).Append("Name").Append(x).Append(",")
                .Append(x).Append("Contact").Append(x).Append(",")
                .Append(x).Append("Addr1").Append(x).Append(",")
                .Append(x).Append("Addr2").Append(x).Append(",")
                .Append(x).Append("City").Append(x).Append(",")
                .Append(x).Append("State").Append(x).Append(",")
                .Append(x).Append("ZIP").Append(x).Append(",")
                .Append(x).Append("Country").Append(x).Append(",")
                .Append(x).Append("ReferenceNo").Append(x).Append(",")
                .Append(x).Append("BPRoutingNo").Append(x).Append(",")
                .Append(x).Append("BPAccountNo").Append(x).Append(",")
                .Append(x).Append("BPAName").Append(x).Append(",")
                .Append(x).Append("BPACity").Append(x).Append(",")
                .Append(x).Append("BPBBAN").Append(x).Append(",")
                .Append(x).Append("BPIBAN").Append(x).Append(",")
                .Append(x).Append("BAName").Append(x).Append(",")
                .Append(x).Append("BARoutingNo").Append(x).Append(",")
                .Append(x).Append("BASwiftCode").Append(x).Append(",")
                .Append(x).Append("DocumentNo").Append(x).Append(",")
                .Append(x).Append("PayDate").Append(x).Append(",")
                .Append(x).Append("Currency").Append(x).Append(",")
                .Append(x).Append("PayAmount").Append(x).Append(",")
                .Append(x).Append("Comment").Append(x)
                .Append(Env.NL);
                fw.write(line.ToString());
                noLines++;

                //  write lines
                for (int i = 0; i < checks.Length; i++)
                {
                    MPaySelectionCheck mpp = checks[i];
                    if (mpp == null)
                    {
                        continue;
                    }
                    //  BPartner Info
                    String[] bp = GetBPartnerInfo(mpp.GetC_BPartner_ID());
                    //  TarGet BankAccount Info
                    String[] bpba = GetBPBankAccountInfo(mpp.GetC_BP_BankAccount_ID());

                    //  Comment - list of invoice document no
                    StringBuilder       comment = new StringBuilder();
                    MPaySelectionLine[] psls    = mpp.GetPaySelectionLines(false);
                    for (int l = 0; l < psls.Length; l++)
                    {
                        if (l > 0)
                        {
                            comment.Append(", ");
                        }
                        comment.Append(psls[l].GetInvoice().GetDocumentNo());
                    }
                    line = new StringBuilder();
                    line.Append(x).Append(bp[BP_VALUE]).Append(x).Append(",")                                                            // Value
                    .Append(x).Append(bp[BP_NAME]).Append(x).Append(",")                                                                 // Name
                    .Append(x).Append(bp[BP_CONTACT]).Append(x).Append(",")                                                              // Contact
                    .Append(x).Append(bp[BP_ADDR1]).Append(x).Append(",")                                                                // Addr1
                    .Append(x).Append(bp[BP_ADDR2]).Append(x).Append(",")                                                                // Addr2
                    .Append(x).Append(bp[BP_CITY]).Append(x).Append(",")                                                                 // City
                    .Append(x).Append(bp[BP_REGION]).Append(x).Append(",")                                                               // State
                    .Append(x).Append(bp[BP_POSTAL]).Append(x).Append(",")                                                               // ZIP
                    .Append(x).Append(bp[BP_COUNTRY]).Append(x).Append(",")                                                              // Country
                    .Append(x).Append(bp[BP_REFNO]).Append(x).Append(",")                                                                // ReferenceNo
                    .Append(x).Append(bpba[BPBA_RoutingNo]).Append(x).Append(",")                                                        // Routing No (as of BPBankAccount
                    .Append(x).Append(bpba[BPBA_AccountNo]).Append(x).Append(",")                                                        // AccountNo
                    .Append(x).Append(bpba[BPBA_AName]).Append(x).Append(",")                                                            // Account Name
                    .Append(x).Append(bpba[BPBA_ACity]).Append(x).Append(",")                                                            // Account City
                    .Append(x).Append(bpba[BPBA_BBAN]).Append(x).Append(",")                                                             // BBAN
                    .Append(x).Append(bpba[BPBA_IBAN]).Append(x).Append(",")                                                             // IBAN
                    .Append(x).Append(bpba[BA_Name]).Append(x).Append(",")                                                               // Bank Name
                    .Append(x).Append(bpba[BA_RoutingNo]).Append(x).Append(",")                                                          // Bank RoutingNo
                    .Append(x).Append(bpba[BA_SwitftCode]).Append(x).Append(",")                                                         // SwiftCode
                    //  Payment Info
                    .Append(x).Append(mpp.GetDocumentNo()).Append(x).Append(",")                                                         // DocumentNo
                    .Append(mpp.GetParent().GetPayDate()).Append(",")                                                                    // PayDate
                    .Append(x).Append(MCurrency.GetISO_Code(Env.GetContext(), mpp.GetParent().GetC_Currency_ID())).Append(x).Append(",") // Currency
                    .Append(mpp.GetPayAmt()).Append(",")                                                                                 // PayAmount
                    .Append(x).Append(comment.ToString()).Append(x)                                                                      // Comment
                    .Append(Env.NL);
                    fw.write(line.ToString());
                    noLines++;
                }   //  write line

                fw.flush();
                fw.close();
            }
            catch (Exception e)
            {
                _log.Log(Level.SEVERE, "", e);
            }

            return(noLines);
        }