<commit_before>module FEC
  module Exporter
    class XML < FEC::Exporter::Base
      private

      def build(journals)
        builder = Nokogiri::XML::Builder.new(encoding: 'ISO-8859-15') do |xml|
          xml.comptabilite do
            xml.exercice do
              xml.DateCloture @financial_year.stopped_on.strftime('%Y-%m-%d')
              journals.each do |journal|
                entries = journal.entries.between(@financial_year.started_on, @financial_year.stopped_on)
                next unless entries.any?
                xml.journal do
                  xml.JournalCode journal.code
                  xml.JournalLib journal.name
                  entries.includes(items: :account).references(items: :account).find_each do |entry|
                    next if entry.items.empty?
                    resource = Maybe(entry.resource)
                    xml.ecriture do
                      xml.EcritureNum (entry.continuous_number? ? entry.continuous_number : '')
                      xml.EcritureDate entry.printed_on.strftime('%Y-%m-%d')
                      xml.EcritureLib entry.items.first.name
                      xml.PieceRef entry.number
                      xml.PieceDate entry.created_at.strftime('%Y-%m-%d') # bug with resource.created_at.strftime('%Y-%m-%d')
                      xml.EcritureLet entry.letter if entry.letter
                      # xml.DateLet
                      xml.ValidDate (entry.validated_at? ? entry.validated_at.strftime('%Y-%m-%d') : '')
                      xml.DateRglt entry.first_payment.paid_at if entry.first_payment && fiscal_position == :ba_ir_cash_accountancy
                      xml.ModeRglt entry.first_payment.mode.name if entry.first_payment && fiscal_position == :ba_ir_cash_accountancy
                      xml.NatOp '' if fiscal_position == :ba_ir_cash_accountancy
                      xml.IdClient (resource.client? ? resource.client.number : (resource.supplier? ? resource.supplier.full_name : '')) if resource && fiscal_position == :bnc_ir_cash_accountancy<commit_msg>Fixed FEC export<commit_after>module FEC
  module Exporter
    class XML < FEC::Exporter::Base
      private

      def build(journals)
        validators = {
                       "all" => "formatA47A-I-VII-1.xsd",
                       "ba_bnc_ir_commercial_accountancy" => "formatA47A-I-VIII-3.xsd",
                       "ba_ir_cash_accountancy" => "formatA47A-I-VIII-5.xsd",
                       "bnc_ir_cash_accountancy" => "formatA47A-I-VIII-7.xsd"
                     }

        builder = Nokogiri::XML::Builder.new(encoding: 'ISO-8859-15') do |xml|
          xml.comptabilite('xmlns:xsi' => 'http://www.w3.org/2001/XMLSchema-instance', 'xsi:noNamespaceSchemaLocation' => validators[fiscal_position]) do
            xml.exercice do
              xml.DateCloture @financial_year.stopped_on.strftime('%Y-%m-%d')
              journals.each do |journal|
                entries = journal.entries.between(@financial_year.started_on, @financial_year.stopped_on)
                next unless entries.any?
                xml.journal do
                  xml.JournalCode journal.code
                  xml.JournalLib journal.name
                  entries.includes(:incoming_payments, :purchase_payments, items: :account).references(items: :account).find_each do |entry|
                    next if entry.items.empty? || ((fiscal_position == 'ba_ir_cash_accountancy' || fiscal_position == 'bnc_ir_cash_accountancy') && !entry.first_payment)
                    resource = Maybe(entry.resource)
                    xml.ecriture do
                      xml.EcritureNum (entry.continuous_number? ? entry.continuous_number : '')
                      xml.EcritureDate entry.printed_on.strftime('%Y-%m-%d')
                      xml.EcritureLib entry.items.first.name
                      xml.PieceRef entry.number
                      xml.PieceDate entry.created_at.strftime('%Y-%m-%d') # bug with resource.created_at.strftime('%Y-%m-%d')
                      xml.EcritureLet entry.letter if entry.letter
                      # xml.DateLet
                      xml.ValidDate (entry.validated_at? ? entry.validated_at.strftime('%Y-%m-%d') : '')
                      xml.DateRglt entry.first_payment.paid_at.strftime('%Y-%m-%d') if entry.first_payment && fiscal_position == 'ba_ir_cash_accountancy'
                      xml.ModeRglt entry.first_payment.mode.name if entry.first_payment && fiscal_position == 'ba_ir_cash_accountancy'
                      xml.NatOp '' if fiscal_position == 'ba_ir_cash_accountancy'
                      xml.IdClient (resource.has_attribute?(:client_id).get && resource.client.get ? resource.client.get.number : (resource.has_attribute?(:supplier_id).get && resource.supplier.get ? resource.supplier.get.full_name : '')) if resource.is_some? && fiscal_position == 'bnc_ir_cash_accountancy'
{'fraction_non_alphanumeric': 0.11115660184237462, 'fraction_numerical': 0.00593654042988741, 'mean_word_length': 2.057571964956195, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, 'xml': 41}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7127378', 'n_tokens_mistral': 1491, 'n_tokens_neox': 1382, 'n_words': 212}