use of org.compiere.util.AdempiereUserError in project lar_361 by comitsrl.
the class LCO_DianGenerateXML method doIt.
// prepare
/**
* Process
* @return message
* @throws Exception
*/
protected String doIt() throws Exception {
/**
*Genera Envios XML
* Para Schedule
* Para LCO_SendScheduleLine Order by ID
* Idx = Idx + 1
* Si Idx MOD Max_Records = 1
* Asigne CumulatedAmt(Posicion=1), RecordsQty del XML Header anterior
* Cree nuevo LCO_DIAN_XML_Header
* Asigne CurrentNext --Secuencia env�o por a�o
* Fin Si
* Asigne LCO_SendScheduleLine.LCO_DIAN_XML_Header_ID
* Sume CumulatedAmt
* Cuente RecordsQty
* Fin LCO_SendScheduleLine
* Asigne CumulatedAmt, RecordsQty del ultimo XML Header
* Fin Schedule
* LCO_SendSchedule.processed = Y --Content ReadOnly
*/
X_LCO_DIAN_SendSchedule sendScheduleProcess = new X_LCO_DIAN_SendSchedule(getCtx(), p_LCO_DIAN_SendSchedule_ID, get_TrxName());
if (!sendScheduleProcess.isGenerated()) {
throw new AdempiereUserError("SendSchedule has not been generated before");
}
if (sendScheduleProcess.isProcessed()) {
throw new AdempiereUserError("SendSchedule has been processed before");
}
MLCODIANFormat format = new MLCODIANFormat(getCtx(), sendScheduleProcess.getLCO_DIAN_Format_ID(), get_TrxName());
MSequence seqxml = new MSequence(getCtx(), format.getAD_Sequence_ID(), get_TrxName());
log.info("LCO_DIAN_SendSchedule_ID = " + p_LCO_DIAN_SendSchedule_ID);
if (sendScheduleProcess.getLCO_DIAN_SendSchedule_ID() == 0)
throw new AdempiereUserError("@No@ @LCO_DIAN_SendSchedule@");
String sql = "SELECT * FROM LCO_DIAN_SendScheduleLine " + "WHERE LCO_DIAN_SendSchedule_ID = ? AND (lco_dian_xml_header_id = 0 or lco_dian_xml_header_id IS NULL) AND IsActive='Y' " + "ORDER BY LCO_DIAN_SendScheduleLine_ID";
PreparedStatement pstmt = null;
ResultSet rs = null;
X_LCO_DIAN_XML_Header xmlh = null;
BigDecimal cumulatedAmt = Env.ZERO;
int cnt = 0;
int cntmedia = 0;
try {
pstmt = DB.prepareStatement(sql, get_TrxName());
pstmt.setInt(1, p_LCO_DIAN_SendSchedule_ID);
rs = pstmt.executeQuery();
// para ScheduleLine
while (rs.next()) {
X_LCO_DIAN_SendScheduleLine dssl = new X_LCO_DIAN_SendScheduleLine(getCtx(), rs, get_TrxName());
if (xmlh == null) {
xmlh = new X_LCO_DIAN_XML_Header(getCtx(), 0, get_TrxName());
cntmedia++;
xmlh.setLCO_DIAN_SendSchedule_ID(sendScheduleProcess.getLCO_DIAN_SendSchedule_ID());
int p_seqEnvio = seqxml.getNextID();
seqxml.saveEx();
xmlh.setSequence(p_seqEnvio);
xmlh.saveEx();
}
cnt++;
cumulatedAmt = cumulatedAmt.add(dssl.getFieldAmt1());
// Asigne LCO_SendScheduleLine.LCO_DIAN_XML_Header_ID
dssl.setLCO_DIAN_XML_Header_ID(xmlh.getLCO_DIAN_XML_Header_ID());
dssl.saveEx();
if (cnt == format.getMaxXMLRecords()) {
// Asigne CumulatedAmt, RecordsQty del ultimo XML Header
xmlh.setCumulatedAmt(cumulatedAmt);
xmlh.setRecordsQty(new BigDecimal(cnt));
xmlh.saveEx();
xmlh = null;
cnt = 0;
}
}
// Fin LCO_SendScheduleLine
} catch (SQLException e) {
log.log(Level.SEVERE, sql, e);
throw e;
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
// last header not saved
if (xmlh != null) {
// Asigne CumulatedAmt, RecordsQty del ultimo XML Header
xmlh.setCumulatedAmt(cumulatedAmt);
xmlh.setRecordsQty(new BigDecimal(cnt));
xmlh.saveEx();
xmlh = null;
}
// LCO_SendSchedule.processed = Y --Content ReadOnly
sendScheduleProcess.setProcessed(true);
sendScheduleProcess.saveEx();
return "@LCO_MediaInserted@=" + cntmedia;
}
use of org.compiere.util.AdempiereUserError in project lar_361 by comitsrl.
the class LCO_DianProcessContent method doIt.
// prepare
/**
* Process
* @return message
* @throws Exception
*/
protected String doIt() throws Exception {
// Fill details for the format
log.info("LCO_DIAN_SendSchedule_ID = " + p_LCO_DIAN_SendSchedule_ID);
X_LCO_DIAN_SendSchedule sendScheduleProcess = new X_LCO_DIAN_SendSchedule(getCtx(), p_LCO_DIAN_SendSchedule_ID, get_TrxName());
if (sendScheduleProcess.isGenerated()) {
throw new AdempiereUserError("SendSchedule has been generated before");
}
if (sendScheduleProcess.getLCO_DIAN_SendSchedule_ID() == 0)
throw new AdempiereUserError("@No@ @LCO_DIAN_SendSchedule@");
MLCODIANFormat format = new MLCODIANFormat(getCtx(), sendScheduleProcess.getLCO_DIAN_Format_ID(), get_TrxName());
int cnt = 0;
if (format.isBPartnerDetailed()) {
// bring BPartners from selected year and dates
String sqlBp = "SELECT DISTINCT fa.C_BPartner_ID AS C_BPartner_ID, bp.TaxID AS TaxId " + "FROM Fact_Acct fa " + " JOIN C_BPartner bp ON fa.C_BPartner_ID = bp.C_BPartner_ID " + " INNER JOIN C_Period p ON fa.C_Period_ID = p.C_Period_ID " + "WHERE fa.C_BPartner_ID <> 0 AND fa.C_Bpartner_ID IS NOT NULL " + " AND fa.AD_Client_ID = ? " + " AND p.C_Year_ID = ? AND fa.DateAcct BETWEEN ? AND ? " + " AND fa.PostingType = 'A' /* Actual Hardcoded */ " + "ORDER BY fa.C_BPartner_ID";
PreparedStatement pstmtbp = null;
ResultSet rsbp = null;
try {
pstmtbp = DB.prepareStatement(sqlBp, get_TrxName());
pstmtbp.setInt(1, sendScheduleProcess.getAD_Client_ID());
pstmtbp.setInt(2, sendScheduleProcess.getC_Year_ID());
pstmtbp.setTimestamp(3, sendScheduleProcess.getStartDate());
pstmtbp.setTimestamp(4, sendScheduleProcess.getEndDate());
rsbp = pstmtbp.executeQuery();
// for each bpartner
while (rsbp.next()) {
// bp was found in fact acct
int bpID = rsbp.getInt(1);
// for each concept related to this format
for (MLCODIANConcept concept : format.getConcepts()) {
int cntsrc = concept.calculateSources(sendScheduleProcess, bpID);
cnt = cnt + cntsrc;
}
}
} catch (Exception e) {
log.log(Level.SEVERE, "", e);
throw e;
} finally {
DB.close(rsbp, pstmtbp);
rsbp = null;
pstmtbp = null;
}
} else {
int bpID = -1;
// for each concept related to this format
for (MLCODIANConcept concept : format.getConcepts()) {
int cntsrc = concept.calculateSources(sendScheduleProcess, bpID);
cnt = cnt + cntsrc;
}
}
// TODO: Implement post-process
sendScheduleProcess.setIsGenerated(true);
sendScheduleProcess.saveEx();
return "@LCO_LinesInserted@=" + cnt;
}
use of org.compiere.util.AdempiereUserError in project lar_361 by comitsrl.
the class LCO_GenerateWithholding method doIt.
// prepare
/**
* Process
* @return message
* @throws Exception
*/
protected String doIt() throws Exception {
int cnt = 0;
LCO_MInvoice inv = new LCO_MInvoice(getCtx(), p_Record_ID, get_TrxName());
if (inv.getC_Invoice_ID() == 0)
throw new AdempiereUserError("@No@ @Invoice@");
cnt = inv.recalcWithholdings();
if (cnt == -1)
throw new AdempiereUserError("Error calculating withholding, please check log");
return "@Inserted@=" + cnt;
}
use of org.compiere.util.AdempiereUserError in project lar_361 by comitsrl.
the class DrawerTransfer method doIt.
// prepare
/**
* Perform process.
*
* @return Message (translated text)
* @throws Exception
* if not successful
*/
protected String doIt() throws Exception {
String msg = String.format("From Bank=%d - To Bank=%d - DocumentNo=%s - Description=%s - Statement Date=%s - Date Account=%s", p_From_C_BankAccount_ID, p_To_C_BankAccount_ID, p_DocumentNo, p_Description, p_StatementDate, p_DateAcct);
log.info(msg);
if (p_From_C_BankAccount_ID == 0)
throw new IllegalArgumentException("Número de Caja Requerido");
// if (p_DocumentNo == null || p_DocumentNo.length() == 0)
// throw new IllegalArgumentException("Document No required");
// if (p_To_C_BankAccount_ID == p_From_C_BankAccount_ID)
// throw new AdempiereUserError("Accounts From and To must be different");
p_C_BPartner_ID = new MUser(getCtx(), Env.getAD_User_ID(getCtx()), get_TrxName()).getC_BPartner_ID();
if (p_C_BPartner_ID == 0)
throw new AdempiereUserError("Socio de Negocio requerido");
// Login Date
if (p_StatementDate == null)
p_StatementDate = Env.getContextAsDate(getCtx(), "#Date");
if (p_StatementDate == null)
p_StatementDate = new Timestamp(System.currentTimeMillis());
if (p_DateAcct == null)
p_DateAcct = p_StatementDate;
if (p_BankStatement_ID == 0)
throw new AdempiereUserError("Por favor, seleccione un cierre de caja a transferir.");
// Si la cuenta, es una caja principal, se transfieren los valores segun
// la forma de pago.
final MBankAccount cuenta = new MBankAccount(getCtx(), p_From_C_BankAccount_ID, get_TrxName());
return "@Se transfirieron@ " + m_transferred + " líneas.";
}
Aggregations