Buggy code:
} else { buffer += ( ( ( ( ( "EJERCICIO:<seq2seq4repair_space>" + ( moIntPeriodYear . getValue ( ) ) ) + "<seq2seq4repair_space>PERÍODO<seq2seq4repair_space>DEL<seq2seq4repair_space>" ) + ( moIntPeriodStart . getValue ( ) ) ) + "<seq2seq4repair_space>AL<seq2seq4repair_space>" ) + ( moIntPeriodEnd . getValue ( ) ) ) + "\n" ; } buffer += ( "PERÍODO<seq2seq4repair_space>DE<seq2seq4repair_space>PAGO:<seq2seq4repair_space>" + ( ( moKeyPaymentType . getSelectedIndex ( ) ) > 0 ? moKeyPaymentType . getSelectedItem ( ) : "(TODOS)" ) ) + "\n\n" ; buffer += ( "Usuario:<seq2seq4repair_space>" + ( ( ( erp . client . SClientInterface ) ( miClient ) ) . getSessionXXX ( ) . getUser ( ) . getUser ( ) ) ) + "\n" ; buffer += ( "Emisión:<seq2seq4repair_space>" + ( ( ( erp . client . SClientInterface ) ( miClient ) ) . getSessionXXX ( ) . getFormatters ( ) . getDatetimeFormat ( ) . format ( new Date ( ) ) ) ) + "\n" ; bw . write ( SLibUtilities . textToAscii ( buffer ) ) ; bw . write ( "\n\n" ) ; buffer = sEarningHeader ; bw . write ( SLibUtilities . textToAscii ( buffer ) ) ; bw . write ( "\n" ) ; buffer = ( ( "EMPLEADO_ID\",\"EMPLEADO\",\"DEPARTAMENTO_ID\",\"DEPARTAMENTO\"," + sTaxExentHeader ) + "" ) + "\"SUBTOTAL<seq2seq4repair_space>GRAVADO\",\"SUBTOTAL<seq2seq4repair_space>EXCENTO\",\"TOTAL<seq2seq4repair_space>ENTREGADO\",\"DEDUCCIONES<seq2seq4repair_space>DE<seq2seq4repair_space>LEY\",\"TODAS<seq2seq4repair_space>LAS<seq2seq4repair_space>DEDUCCIONES\",\"SALDO<seq2seq4repair_space>BRUTO\",\"SALDO<seq2seq4repair_space>NETO\"" ; bw . write ( SLibUtilities . textToAscii ( buffer ) ) ; sql = ( ( "SELECT<seq2seq4repair_space>DISTINCT<seq2seq4repair_space>pre.id_emp,<seq2seq4repair_space>e.num,<seq2seq4repair_space>b.bp,<seq2seq4repair_space>d.code,<seq2seq4repair_space>d.name<seq2seq4repair_space>" + ( ( ( ( ( ( "FROM<seq2seq4repair_space>hrs_pay<seq2seq4repair_space>AS<seq2seq4repair_space>p<seq2seq4repair_space>" + "INNER<seq2seq4repair_space>JOIN<seq2seq4repair_space>hrs_pay_rcp<seq2seq4repair_space>AS<seq2seq4repair_space>pr<seq2seq4repair_space>ON<seq2seq4repair_space>pr.id_pay<seq2seq4repair_space>=<seq2seq4repair_space>p.id_pay<seq2seq4repair_space>" ) + "INNER<seq2seq4repair_space>JOIN<seq2seq4repair_space>hrs_pay_rcp_ear<seq2seq4repair_space>AS<seq2seq4repair_space>pre<seq2seq4repair_space>ON<seq2seq4repair_space>pre.id_pay<seq2seq4repair_space>=<seq2seq4repair_space>pr.id_pay<seq2seq4repair_space>AND<seq2seq4repair_space>pre.id_emp<seq2seq4repair_space>=<seq2seq4repair_space>pr.id_emp<seq2seq4repair_space>" ) + "INNER<seq2seq4repair_space>JOIN<seq2seq4repair_space>erp.hrsu_emp<seq2seq4repair_space>AS<seq2seq4repair_space>e<seq2seq4repair_space>ON<seq2seq4repair_space>e.id_emp<seq2seq4repair_space>=<seq2seq4repair_space>pre.id_emp<seq2seq4repair_space>" ) + "INNER<seq2seq4repair_space>JOIN<seq2seq4repair_space>erp.bpsu_bp<seq2seq4repair_space>AS<seq2seq4repair_space>b<seq2seq4repair_space>ON<seq2seq4repair_space>b.id_bp<seq2seq4repair_space>=<seq2seq4repair_space>pre.id_emp<seq2seq4repair_space>" ) + "INNER<seq2seq4repair_space>JOIN<seq2seq4repair_space>erp.hrsu_dep<seq2seq4repair_space>AS<seq2seq4repair_space>d<seq2seq4repair_space>ON<seq2seq4repair_space>d.id_dep<seq2seq4repair_space>=<seq2seq4repair_space>e.fk_dep<seq2seq4repair_space>" ) + "WHERE<seq2seq4repair_space>p.b_del<seq2seq4repair_space>=<seq2seq4repair_space>0<seq2seq4repair_space>AND<seq2seq4repair_space>pr.b_del<seq2seq4repair_space>=<seq2seq4repair_space>0<seq2seq4repair_space>AND<seq2seq4repair_space>pre.b_del<seq2seq4repair_space>=<seq2seq4repair_space>0<seq2seq4repair_space>" ) ) + ( ( moKeyPaymentType . getSelectedIndex ( ) ) > 0 ? "<seq2seq4repair_space>AND<seq2seq4repair_space>p.fk_tp_pay<seq2seq4repair_space>=<seq2seq4repair_space>" + ( moKeyPaymentType . getValue ( ) [ 0 ] ) : "" ) ) + "<seq2seq4repair_space>" ; if ( moRadFilterTypeDate . isSelected ( ) ) { sql += ( ( ( ( "<seq2seq4repair_space>AND<seq2seq4repair_space>p.dt_sta<seq2seq4repair_space>>=<seq2seq4repair_space>'" + ( DbmsDateFormatDate . format ( moDateDateStart . getValue ( ) ) ) ) + "'<seq2seq4repair_space>AND<seq2seq4repair_space>p.dt_end<seq2seq4repair_space><=<seq2seq4repair_space>'" ) + ( DbmsDateFormatDate . format ( moDateDateEnd . getValue ( ) ) ) ) + "'<seq2seq4repair_space>" ) + ( getOrderBy ( ) ) ; } else { sql += ( ( ( ( ( ( ( "<seq2seq4repair_space>AND<seq2seq4repair_space>p.per_year<seq2seq4repair_space>=<seq2seq4repair_space>" + ( moIntPeriodYear . getValue ( ) ) ) + "<seq2seq4repair_space>" ) + "AND<seq2seq4repair_space>p.per<seq2seq4repair_space>BETWEEN<seq2seq4repair_space>" ) + ( moIntPeriodStart . getValue ( ) ) ) + "<seq2seq4repair_space>AND<seq2seq4repair_space>" ) + ( moIntPeriodEnd . getValue ( ) ) ) + "<seq2seq4repair_space>" ) + ( getOrderBy ( ) ) ; } resulSetEmployee = miClient . getSession ( ) . getStatement ( ) . getConnection ( ) . createStatement ( ) . executeQuery ( sql ) ; while ( resulSetEmployee . next ( ) ) { dTotalAmountTax = 0 ; dTotalAmountExem = 0 ; dTotalAmountDelivered = 0 ; dPayrollTax = 0 ; dEmployersImss = 0 ; dTotalCost = 0 ; dDeduction = 0 ; dDeductionAll = 0 ; dTotalAmountGross = 0 ; dTotalAmountNet = 0 ; buffer = "" ; nEmployeeId = resulSetEmployee . getInt ( "pre.id_emp" ) ; buffer += ( "\"" + ( resulSetEmployee . getString ( "e.num" ) . replace ( "\"" , "'" ) ) ) + "\"," ; buffer += ( "\"" + ( resulSetEmployee . getString ( "b.bp" ) . replace ( "\"" , "'" ) ) ) + "\"," ; buffer += ( "\"" + ( resulSetEmployee . getString ( "d.code" ) . replace ( "\"" , "'" ) ) ) + "\"," ; buffer += ( "\"" + ( resulSetEmployee . getString ( "d.name" ) . replace ( "\"" , "'" ) ) ) + "\"," ; for ( SDbEarning earning : aEarnings ) { sql = ( ( ( ( ( ( "SELECT<seq2seq4repair_space>SUM(pre.amt_exem)<seq2seq4repair_space>AS<seq2seq4repair_space>f_exem,<seq2seq4repair_space>SUM(pre.amt_taxa)<seq2seq4repair_space>AS<seq2seq4repair_space>f_tax<seq2seq4repair_space>" + ( ( ( "FROM<seq2seq4repair_space>hrs_pay<seq2seq4repair_space>AS<seq2seq4repair_space>p<seq2seq4repair_space>" + "INNER<seq2seq4repair_space>JOIN<seq2seq4repair_space>hrs_pay_rcp<seq2seq4repair_space>AS<seq2seq4repair_space>pr<seq2seq4repair_space>ON<seq2seq4repair_space>pr.id_pay<seq2seq4repair_space>=<seq2seq4repair_space>p.id_pay<seq2seq4repair_space>" ) + "INNER<seq2seq4repair_space>JOIN<seq2seq4repair_space>hrs_pay_rcp_ear<seq2seq4repair_space>AS<seq2seq4repair_space>pre<seq2seq4repair_space>ON<seq2seq4repair_space>pre.id_pay<seq2seq4repair_space>=<seq2seq4repair_space>pr.id_pay<seq2seq4repair_space>AND<seq2seq4repair_space>pre.id_emp<seq2seq4repair_space>=<seq2seq4repair_space>pr.id_emp<seq2seq4repair_space>" ) + "WHERE<seq2seq4repair_space>p.b_del<seq2seq4repair_space>=<seq2seq4repair_space>0<seq2seq4repair_space>AND<seq2seq4repair_space>pr.b_del<seq2seq4repair_space>=<seq2seq4repair_space>0<seq2seq4repair_space>AND<seq2seq4repair_space>pre.b_del<seq2seq4repair_space>=<seq2seq4repair_space>0<seq2seq4repair_space>" ) ) + ( ( moKeyPaymentType . getSelectedIndex ( ) ) > 0 ? "<seq2seq4repair_space>AND<seq2seq4repair_space>p.fk_tp_pay<seq2seq4repair_space>=<seq2seq4repair_space>" + ( moKeyPaymentType . getValue ( ) [ 0 ] ) : "" ) ) + "<seq2seq4repair_space>AND<seq2seq4repair_space>pre.id_emp<seq2seq4repair_space>=<seq2seq4repair_space>" ) + nEmployeeId ) + "<seq2seq4repair_space>" ) + "AND<seq2seq4repair_space>pre.fk_ear<seq2seq4repair_space>=<seq2seq4repair_space>" ) + ( earning . getPkEarningId ( ) ) ; if ( moRadFilterTypeDate . isSelected ( ) ) { <START_BUG> sql += ( ( ( "<seq2seq4repair_space>AND<seq2seq4repair_space>p.dt_sta<seq2seq4repair_space>=<seq2seq4repair_space>'" + ( DbmsDateFormatDate . format ( moDateDateStart . getValue ( ) ) ) ) + "'<seq2seq4repair_space>AND<seq2seq4repair_space>p.dt_end<seq2seq4repair_space><=<seq2seq4repair_space>'" ) + ( DbmsDateFormatDate . format ( moDateDateEnd . getValue ( ) ) ) ) + "'<seq2seq4repair_space>" ; <END_BUG> } else { sql += ( ( ( ( ( ( "<seq2seq4repair_space>AND<seq2seq4repair_space>p.per_year<seq2seq4repair_space>=<seq2seq4repair_space>" + ( moIntPeriodYear . getValue ( ) ) ) + "<seq2seq4repair_space>" ) + "AND<seq2seq4repair_space>p.per<seq2seq4repair_space>BETWEEN<seq2seq4repair_space>" ) + ( moIntPeriodStart . getValue ( ) ) ) + "<seq2seq4repair_space>AND<seq2seq4repair_space>" ) + ( moIntPeriodEnd . getValue ( ) ) ) + "<seq2seq4repair_space>" ; } resulSet = miClient . getSession ( ) . getStatement ( ) . executeQuery ( sql ) ; while ( resulSet . next ( ) ) { dAmountTax = resulSet . getDouble ( "f_tax" ) ; dAmountExem = resulSet . getDouble ( "f_exem" ) ; buffer += ( SLibUtils . round ( dAmountTax , SLibUtils . getDecimalFormatAmount ( ) . getMaximumFractionDigits ( ) ) ) + "," ; buffer += ( SLibUtils . round ( dAmountExem , SLibUtils . getDecimalFormatAmount ( ) . getMaximumFractionDigits ( ) ) ) + "," ; dTotalAmountTax += dAmountTax ; dTotalAmountExem += dAmountExem ; } } dTotalAmountDelivered = SLibUtils . round ( ( dTotalAmountTax + dTotalAmountExem ) , SLibUtils . getDecimalFormatAmount ( ) . getMaximumFractionDigits ( ) ) ; dTotalCost = SLibUtils . round ( ( ( dTotalAmountDelivered + dPayrollTax ) + dEmployersImss ) , SLibUtils . getDecimalFormatAmount ( ) . getMaximumFractionDigits ( ) ) ; adAmountDeductions = getAmountDeductions ( nEmployeeId ) ; if ( adAmountDeductions != null ) { dDeduction = SLibUtils . round ( adAmountDeductions [ 0 ] , SLibUtils . getDecimalFormatAmount ( ) . getMaximumFractionDigits ( ) ) ; dDeductionAll = SLibUtils . round ( adAmountDeductions [ 1 ] , SLibUtils . getDecimalFormatAmount ( ) . getMaximumFractionDigits ( ) ) ; }

Fix:
sql += ( ( ( "<seq2seq4repair_space>AND<seq2seq4repair_space>p.dt_sta<seq2seq4repair_space>>=<seq2seq4repair_space>'" + ( DbmsDateFormatDate . format ( moDateDateStart . getValue ( ) ) ) ) + "'<seq2seq4repair_space>AND<seq2seq4repair_space>p.dt_end<seq2seq4repair_space><=<seq2seq4repair_space>'" ) + ( DbmsDateFormatDate . format ( moDateDateEnd . getValue ( ) ) ) ) + "'<seq2seq4repair_space>" ;