PreparedStatement stmtDeletePrice = c.prepareStatement("delete from precio where codigo_de_articulo = ? and fecha = curdate() ");
PreparedStatement stmtInsertPrice = c.prepareStatement("insert into precio ( codigo_de_articulo , monto , fecha ) values ( ? , ? , curdate() ) ");
for (Object x : xml.getChildren()) {
XMLElement xmlI = (XMLElement)x;
stmtUpdateItem.setString(1, xmlI.getAttribute("MAKTG",""));
stmtUpdateItem.setString(2, xmlI.getAttribute("EAN11",""));
stmtUpdateItem.setString(3, xmlI.getAttribute("MATKL",""));
stmtUpdateItem.setString(4, xmlI.getAttribute("MSEH3",""));
stmtUpdateItem.setString(5, xmlI.getAttribute("DISC",""));
stmtUpdateItem.setString(6, xmlI.getAttribute("MATNR",""));
int ans = stmtUpdateItem.executeUpdate();
if ( ans == 0 ){
stmtItem.setString(1, xmlI.getAttribute("MATNR",""));
stmtItem.setString(2, xmlI.getAttribute("MAKTG",""));
stmtItem.setString(3, xmlI.getAttribute("EAN11",""));
stmtItem.setString(4, xmlI.getAttribute("MATKL",""));
stmtItem.setString(5, xmlI.getAttribute("MSEH3",""));
stmtItem.setString(6, Shared.getConfig("photoDir") + xmlI.getAttribute("MATNR","") + ".JPG");
stmtItem.setString(7, xmlI.getAttribute("DISC",""));
stmtItem.executeUpdate();
}
stmtBarcode.setString(1, xmlI.getAttribute("MATNR",""));
stmtBarcode.setString(2, xmlI.getAttribute("EAN11",""));
stmtBarcode.executeUpdate();
stmtDeletePrice.setString(1, xmlI.getAttribute("MATNR",""));
stmtDeletePrice.executeUpdate();
stmtInsertPrice.setString(1, xmlI.getAttribute("MATNR",""));
stmtInsertPrice.setString(2, xmlI.getAttribute("PRICE",""));
stmtInsertPrice.executeUpdate();
lastMovement = xmlI.getAttribute("MBLNR");
// TODO QUITAR
/*if ( !xmlI.getAttribute("MBLNR").equals("4900458135") && !xmlI.getAttribute("MBLNR").equals("4900458134")
&& !xmlI.getAttribute("MBLNR").equals("4900458133") && !xmlI.getAttribute("MBLNR").equals("4900458130") && !xmlI.getAttribute("MBLNR").equals("4900458129")){
continue;
}*/
/*if (
!xmlI.getAttribute("MBLNR").equals("4900447579")&& !xmlI.getAttribute("MBLNR").equals("4900447580")
&& !xmlI.getAttribute("MBLNR").equals("4900447581")){
continue;
}*/
int reason = Shared.calculateReason(xmlI.getAttribute("BWART",""), xmlI.getAttribute("SHKZG",""));
// TODO QUITAR
//reason *= -1;
System.out.println("MBLNR = " + xmlI.getAttribute("MBLNR","") + " reason = " + reason + " codigo_articulo = " + xmlI.getAttribute("MATNR",""));
stmtDetailsMovements.setString(1, xmlI.getAttribute("MATNR",""));
stmtDetailsMovements.setInt(2, reason * Integer.parseInt(xmlI.getAttribute("MENGE","").split("\\.")[0]));
stmtDetailsMovements.setString(3, xmlI.getAttribute("BWART",""));
stmtDetailsMovements.executeUpdate();
System.out.println("Movimiento " + reason + " articulo " + xmlI.getAttribute("MATNR",""));
}
stmtMI.setString(1, "lastSAPcodeAtInitialStock");
stmtMI.setString(2, lastMovement);
stmtMI.setString(3, "Ultimo Movimiento Para Inventario Inicial");