1 17 package org.openbravo.erpCommon.ad_background; 18 import java.util.*; 19 import javax.servlet.*; 20 import java.io.*; 21 import org.openbravo.erpCommon.ad_forms.AcctServer; 22 import org.openbravo.base.secureApp.VariablesSecureApp; 23 24 25 public class PeriodicAcctServer implements BackgroundProcess { 26 public String batchSize="50"; 27 private String [] TableIds = null; 29 30 public void processPL(PeriodicBackground periodicBG, boolean directProcess) throws Exception { 31 String adNoteId = ""; 32 periodicBG.addLog("Iniciando proceso contable background."); 33 if (periodicBG.vars==null || periodicBG.adClientId.equals("")) { 34 try { 35 PeriodicAcctServerData[] dataOrg = PeriodicAcctServerData.selectUserOrg(periodicBG.conn, periodicBG.adProcessId); 36 if (dataOrg==null || dataOrg.length==0) { 37 periodicBG.addLog("La carga de organizaciĆ³n y usuario a fallado."); 38 periodicBG.setProcessing(false); 39 return; 40 } 41 periodicBG.vars = new VariablesSecureApp(dataOrg[0].adUserId, periodicBG.adClientId,dataOrg[0].adOrgId); 42 } catch (ServletException ex) { 43 ex.printStackTrace(); 44 return; 45 } 46 } 47 48 try { 49 PeriodicAcctServerData [] data = PeriodicAcctServerData.selectAcctTable(periodicBG.conn); 50 ArrayList<Object > vTableIds = new ArrayList<Object >(); 51 for (int i=0;i<data.length;i++){ 52 vTableIds.add(data[i].adTableId); 53 } 54 TableIds = new String [vTableIds.size()]; 55 vTableIds.toArray(TableIds); 56 } catch (ServletException ex) { 57 ex.printStackTrace(); 58 return; 59 } 60 adNoteId = periodicBG.saveLog(adNoteId, periodicBG.adClientId); 61 String [] tables=null; 62 String strTable = ""; 63 if (directProcess) { 64 strTable = PeriodicAcctServerData.selectTable(periodicBG.conn, periodicBG.adPinstanceId); 65 } 66 if (!strTable.equals("")) { 67 tables = new String [1]; 68 tables[0] = new String (strTable); 69 } else tables = TableIds; 70 for (int i=0;i<tables.length;i++){ 71 periodicBG.doPause(); 72 AcctServer acct = AcctServer.get(tables[i], periodicBG.adClientId); 73 acct.setBatchSize(batchSize); 74 int total = 0; 75 while (acct.checkDocuments()) { 76 periodicBG.doPause(); 77 if (total==0) periodicBG.addLog("Contabilizando - " + acct.tableName, false); 78 else periodicBG.addLog("Contabilizados " + total + " - " + acct.tableName, false); 79 try { 80 acct.run(periodicBG.vars); 81 periodicBG.doPause(); 82 } catch(IOException ex) { 83 ex.printStackTrace(); 84 return; 85 } catch(InterruptedException e) { 86 return; 87 } 88 if (!periodicBG.canContinue(directProcess, periodicBG.adClientId)) { 89 periodicBG.addLog("Table=" + acct.tableName + " - " +acct.getInfo(periodicBG.vars)); 90 adNoteId = periodicBG.saveLog(adNoteId, periodicBG.adClientId); 91 return; 92 } 93 total += Integer.valueOf(batchSize).intValue(); 94 } 95 periodicBG.addLog("Table=" + acct.tableName + " - " + acct.getInfo(periodicBG.vars)); 96 adNoteId = periodicBG.saveLog(adNoteId, periodicBG.adClientId); 97 } 98 } 99 } 100 | Popular Tags |