throw new Exception(res.getErrorMessage());
}
String roundingAccountCode = ((VOResponse)res).getVo().toString();
// create ALWAYS expirations in DOC19...
PaymentInstalmentVO inVO = null;
pstmt = conn.prepareStatement(
"insert into DOC19_EXPIRATIONS(COMPANY_CODE_SYS01,DOC_TYPE,DOC_YEAR,DOC_NUMBER,DOC_SEQUENCE,PROGRESSIVE,"+
"DOC_DATE,EXPIRATION_DATE,NAME_1,NAME_2,VALUE,DESCRIPTION,CUSTOMER_SUPPLIER_CODE,PROGRESSIVE_REG04,"+
"CURRENCY_CODE_REG03,PAYMENT_TYPE_CODE_REG11,PAYED,REAL_PAYMENT_TYPE_CODE_REG11,PAYED_DATE,PAYED_VALUE,"+
"REAL_ACCOUNT_CODE_ACC02,ROUNDING_ACCOUNT_CODE_ACC02,ALREADY_PAYED,CREATE_USER,CREATE_DATE) "+
"values(?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)"
);
long startTime = docVO.getDocDateDOC01().getTime(); // invoice date...
if (payVO.getStartDayREG10().equals(ApplicationConsts.START_DAY_END_MONTH)) {
Calendar cal = Calendar.getInstance();
cal.setTimeInMillis(startTime);
if (cal.get(cal.MONTH)==10 || cal.get(cal.MONTH)==3 || cal.get(cal.MONTH)==5 || cal.get(cal.MONTH)==8)
cal.set(cal.DAY_OF_MONTH,30);
else if (cal.get(cal.MONTH)==1) {
if (cal.get(cal.YEAR)%4==0)
cal.set(cal.DAY_OF_MONTH,29);
else
cal.set(cal.DAY_OF_MONTH,28);
} else
cal.set(cal.DAY_OF_MONTH,31);
startTime = cal.getTime().getTime();
}
BigDecimal amount = null;
BigDecimal progressiveDOC19 = null;
pstmt3 = conn.prepareStatement(
"INSERT INTO DOC27_PAYMENTS(COMPANY_CODE_SYS01,PROGRESSIVE,PAYMENT_DATE,PAYMENT_VALUE,CUSTOMER_SUPPLIER_CODE,"+
"ACCOUNT_CODE_ACC02,PAYMENT_TYPE_CODE_REG11,CURRENCY_CODE_REG03,PROGRESSIVE_REG04,CREATE_USER,CREATE_DATE) "+
"VALUES (?,?,?,?,?,?,?,?,?,?,?)"
);
pstmt2 = conn.prepareStatement(
"INSERT INTO DOC28_PAYMENT_DISTRIBUTION(COMPANY_CODE_SYS01,PROGRESSIVE_DOC27,PROGRESSIVE_DOC19,"+
"PAYMENT_VALUE,PAYED,CREATE_USER,CREATE_DATE) VALUES (?,?,?,?,?,?,?)"
);
for(int i=0;i<paymentInstallments.size();i++) {
progressiveDOC19 = CompanyProgressiveUtils.getInternalProgressive(docVO.getCompanyCodeSys01DOC01(),"DOC19_EXPIRATIONS","PROGRESSIVE",conn);
inVO = (PaymentInstalmentVO)paymentInstallments.get(i);
pstmt.setString(1,docVO.getCompanyCodeSys01DOC01());
pstmt.setString(2,docVO.getDocTypeDOC01());
pstmt.setBigDecimal(3,docVO.getDocYearDOC01());
pstmt.setBigDecimal(4,docVO.getDocNumberDOC01());
pstmt.setBigDecimal(5,docVO.getDocSequenceDOC01());
pstmt.setBigDecimal(6,progressiveDOC19);
pstmt.setDate(7,docVO.getDocDateDOC01());
pstmt.setDate(8,new java.sql.Date(startTime + inVO.getInstalmentDaysREG17().longValue()*86400*1000)); // expiration date
pstmt.setString(9,docVO.getName_1REG04());
pstmt.setString(10,docVO.getName_2REG04());
if (docVO.getDocTypeDOC01().equals(ApplicationConsts.SALE_CREDIT_NOTE_DOC_TYPE))
amount = docVO.getTotalDOC01().multiply(inVO.getPercentageREG17()).divide(new BigDecimal(-100),BigDecimal.ROUND_HALF_UP).setScale(docVO.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP); // value
else
amount = docVO.getTotalDOC01().multiply(inVO.getPercentageREG17()).divide(new BigDecimal(100),BigDecimal.ROUND_HALF_UP).setScale(docVO.getDecimalsREG03().intValue(),BigDecimal.ROUND_HALF_UP); // value
pstmt.setBigDecimal(11,CurrencyConversionUtils.convertCurrencyToCurrency(amount,conv));
if (docVO.getDocTypeDOC01().equals(ApplicationConsts.SALE_DESK_DOC_TYPE))
pstmt.setString(12,t3+" "+docVO.getDocSequenceDOC01()+"/"+docVO.getDocYearDOC01()+" - "+t8+" "+t9+" "+(i+1)+" - "+inVO.getPaymentTypeDescriptionSYS10()); // description
else if (docVO.getDocTypeDOC01().equals(ApplicationConsts.SALE_CREDIT_NOTE_DOC_TYPE))
pstmt.setString(12,t7+" "+docVO.getDocSequenceDOC01()+"/"+docVO.getDocYearDOC01()+" - "+t8+" "+t9+" "+(i+1)+" - "+inVO.getPaymentTypeDescriptionSYS10()); // description
else
pstmt.setString(12,t10+" "+docVO.getDocSequenceDOC01()+"/"+docVO.getDocYearDOC01()+" - "+t8+" "+t9+" "+(i+1)+" - "+inVO.getPaymentTypeDescriptionSYS10()); // description
pstmt.setString(13,docVO.getCustomerCodeSAL07());
pstmt.setBigDecimal(14,docVO.getProgressiveReg04DOC01());
pstmt.setString(15,companyCurrencyCode);
pstmt.setString(16,payVO.getPaymentTypeCodeReg11REG10());
if (pk.getDocTypeDOC01().equals(ApplicationConsts.SALE_DESK_DOC_TYPE)) {
pstmt.setString(17,"Y");
pstmt.setString(18,payVO.getPaymentTypeCodeReg11REG10());
pstmt.setDate(19,new java.sql.Date(startTime + inVO.getInstalmentDaysREG17().longValue()*86400*1000));
pstmt.setBigDecimal(20,CurrencyConversionUtils.convertCurrencyToCurrency(amount,conv));
pstmt.setString(21,payVO.getAccountCodeAcc02REG11());
pstmt.setString(22,roundingAccountCode);
pstmt.setBigDecimal(23,CurrencyConversionUtils.convertCurrencyToCurrency(amount,conv));
pstmt.setString(24,username);