use of org.compiere.model.MTaxDeclaration in project adempiere by adempiere.
the class TaxDeclarationCreate method doIt.
// prepare
/**
* Process
* @return info
* @throws Exception
*/
protected String doIt() throws Exception {
log.info("C_TaxDeclaration_ID=" + p_C_TaxDeclaration_ID);
m_td = new MTaxDeclaration(getCtx(), p_C_TaxDeclaration_ID, get_TrxName());
if (m_td.get_ID() == 0)
throw new AdempiereSystemError("@NotFound@ @C_TaxDeclaration_ID@ = " + p_C_TaxDeclaration_ID);
if (p_DeleteOld) {
// Delete old
String sql = "DELETE C_TaxDeclarationLine WHERE C_TaxDeclaration_ID=?";
int no = DB.executeUpdate(sql, p_C_TaxDeclaration_ID, false, get_TrxName());
if (no != 0)
log.config("Delete Line #" + no);
sql = "DELETE C_TaxDeclarationAcct WHERE C_TaxDeclaration_ID=?";
no = DB.executeUpdate(sql, p_C_TaxDeclaration_ID, false, get_TrxName());
if (no != 0)
log.config("Delete Acct #" + no);
}
// Get Invoices
String sql = "SELECT * FROM C_Invoice i " + "WHERE TRUNC(i.DateInvoiced, 'DD') >= ? AND TRUNC(i.DateInvoiced, 'DD') <= ? " + " AND Processed='Y'" + " AND NOT EXISTS (SELECT * FROM C_TaxDeclarationLine tdl " + "WHERE i.C_Invoice_ID=tdl.C_Invoice_ID)";
PreparedStatement pstmt = null;
ResultSet rs = null;
int noInvoices = 0;
try {
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setTimestamp(1, m_td.getDateFrom());
pstmt.setTimestamp(2, m_td.getDateTo());
rs = pstmt.executeQuery();
while (rs.next()) {
// no lock
create(new MInvoice(getCtx(), rs, null));
noInvoices++;
}
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
return "@C_Invoice_ID@ #" + noInvoices + " (" + m_noLines + ", " + m_noAccts + ")";
}
Aggregations