use of org.compiere.model.X_I_InOutLineConfirm in project adempiere by adempiere.
the class ImportInOutConfirm method doIt.
// prepare
/**
* doIt
* @return info
*/
protected String doIt() throws Exception {
log.info("I_InOutLineConfirm_ID=" + p_I_InOutLineConfirm_ID);
StringBuffer sql = null;
int no = 0;
String clientCheck = " AND AD_Client_ID=" + p_AD_Client_ID;
// Delete Old Imported
if (p_DeleteOldImported) {
sql = new StringBuffer("DELETE I_InOutLineConfirm " + "WHERE I_IsImported='Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Delete Old Impored =" + no);
}
// Set IsActive, Created/Updated
sql = new StringBuffer("UPDATE I_InOutLineConfirm " + "SET IsActive = COALESCE (IsActive, 'Y')," + " Created = COALESCE (Created, SysDate)," + " CreatedBy = COALESCE (CreatedBy, 0)," + " Updated = COALESCE (Updated, SysDate)," + " UpdatedBy = COALESCE (UpdatedBy, 0)," + " I_ErrorMsg = ' '," + " I_IsImported = 'N' " + "WHERE I_IsImported<>'Y' OR I_IsImported IS NULL");
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.info("Reset=" + no);
// Set Client from Name
sql = new StringBuffer("UPDATE I_InOutLineConfirm i " + "SET AD_Client_ID=COALESCE (AD_Client_ID,").append(p_AD_Client_ID).append(") " + "WHERE (AD_Client_ID IS NULL OR AD_Client_ID=0)" + " AND I_IsImported<>'Y'");
no = DB.executeUpdate(sql.toString(), get_TrxName());
log.fine("Set Client from Value=" + no);
// Error Confirmation Line
sql = new StringBuffer("UPDATE I_InOutLineConfirm i " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Invalid Confirmation Line, '" + "WHERE (M_InOutLineConfirm_ID IS NULL OR M_InOutLineConfirm_ID=0" + " OR NOT EXISTS (SELECT * FROM M_InOutLineConfirm c WHERE i.M_InOutLineConfirm_ID=c.M_InOutLineConfirm_ID))" + " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.warning("Invalid InOutLineConfirm=" + no);
// Error Confirmation No
sql = new StringBuffer("UPDATE I_InOutLineConfirm i " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Missing Confirmation No, '" + "WHERE (ConfirmationNo IS NULL OR ConfirmationNo='')" + " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.warning("Invalid ConfirmationNo=" + no);
// Qty
sql = new StringBuffer("UPDATE I_InOutLineConfirm i " + "SET I_IsImported='E', I_ErrorMsg=I_ErrorMsg||'ERR=Target<>(Confirmed+Difference+Scrapped), ' " + "WHERE EXISTS (SELECT * FROM M_InOutLineConfirm c " + "WHERE i.M_InOutLineConfirm_ID=c.M_InOutLineConfirm_ID" + " AND c.TargetQty<>(i.ConfirmedQty+i.ScrappedQty+i.DifferenceQty))" + " AND I_IsImported<>'Y'").append(clientCheck);
no = DB.executeUpdate(sql.toString(), get_TrxName());
if (no != 0)
log.warning("Invalid Qty=" + no);
commitEx();
/*********************************************************************/
PreparedStatement pstmt = null;
sql = new StringBuffer("SELECT * FROM I_InOutLineConfirm " + "WHERE I_IsImported='N'").append(clientCheck).append(" ORDER BY I_InOutLineConfirm_ID");
no = 0;
try {
pstmt = DB.prepareStatement(sql.toString(), get_TrxName());
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
X_I_InOutLineConfirm importLine = new X_I_InOutLineConfirm(getCtx(), rs, get_TrxName());
MInOutLineConfirm confirmLine = new MInOutLineConfirm(getCtx(), importLine.getM_InOutLineConfirm_ID(), get_TrxName());
if (confirmLine.get_ID() == 0 || confirmLine.get_ID() != importLine.getM_InOutLineConfirm_ID()) {
importLine.setI_IsImported(false);
importLine.setI_ErrorMsg("ID Not Found");
importLine.saveEx();
} else {
confirmLine.setConfirmationNo(importLine.getConfirmationNo());
confirmLine.setConfirmedQty(importLine.getConfirmedQty());
confirmLine.setDifferenceQty(importLine.getDifferenceQty());
confirmLine.setScrappedQty(importLine.getScrappedQty());
confirmLine.setDescription(importLine.getDescription());
if (confirmLine.save()) {
// Import
importLine.setI_IsImported(true);
importLine.setProcessed(true);
if (importLine.save())
no++;
}
}
}
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.log(Level.SEVERE, sql.toString(), e);
}
try {
if (pstmt != null)
pstmt.close();
pstmt = null;
} catch (Exception e) {
pstmt = null;
}
return "@Updated@ #" + no;
}
Aggregations