HashMap params = new HashMap();
params.put(ApplicationConsts.COMPANY_CODE_SYS01,pk.getCompanyCodeSys01DOC01());
params.put(ApplicationConsts.PARAM_CODE,ApplicationConsts.RECEIPT_PATH);
Response userParRes = userParAction.loadUserParam(params,serverLanguageId,username);
if (userParRes.isError()){
VOResponse res = new VOResponse();
res.setErrorMessage(userParRes.getErrorMessage());
return res;
}
String programPath = (String)((VOResponse)userParRes).getVo();
if (programPath==null) {
throw new Exception(t1);
}
// for demo only...
if (programPath.equals("NOPRINT")) {
return new VOResponse(Boolean.TRUE);
}
programPath = programPath.replace('\\','/');
String path = programPath.substring(0,programPath.lastIndexOf("/"));
// retrieve progressiveREG04 of current company...
pstmt = conn.prepareStatement(
"select PROGRESSIVE from REG04_SUBJECTS where COMPANY_CODE_SYS01=? and SUBJECT_TYPE=?"
);
pstmt.setString(1,pk.getCompanyCodeSys01DOC01());
pstmt.setString(2,ApplicationConsts.SUBJECT_MY_COMPANY);
ResultSet rset = pstmt.executeQuery();
BigDecimal progressiveREG04 = null;
if(rset.next()) {
progressiveREG04 = rset.getBigDecimal(1);
}
rset.close();
if (progressiveREG04==null) {
throw new Exception(t2);
}
// retrieve company data...
//SubjectPK subjectPK = new SubjectPK(pk.getCompanyCodeSys01DOC01(),progressiveREG04);
Response companyRes = companyAction.loadCompany(pk.getCompanyCodeSys01DOC01(),serverLanguageId,username);
if (companyRes.isError())
throw new Exception(companyRes.getErrorMessage());
OrganizationVO companyVO = (OrganizationVO)((VOResponse)companyRes).getVo();
// prepare text file...
GridSaleDocRowVO docRowVO = null;
String tmpFile = path+"/receipt_"+docVO.getDocYearDOC01()+"_"+docVO.getDocSequenceDOC01()+".tmp";
PrintWriter pw = new PrintWriter(new FileOutputStream(tmpFile));
pw.println(companyVO.getName_1REG04());
pw.println(companyVO.getAddressREG04()==null?"":companyVO.getAddressREG04());
pw.println(companyVO.getCityREG04()==null?"":companyVO.getCityREG04());
pw.println(companyVO.getProvinceREG04()==null?"":companyVO.getProvinceREG04());
pw.println(companyVO.getTaxCodeREG04()==null?"":companyVO.getTaxCodeREG04());
pw.println();
for(int i=0;i<rows.size();i++) {
docRowVO = (GridSaleDocRowVO)rows.get(i);
pw.println(
docRowVO.getItemCodeItm01DOC02()+"\t"+
docRowVO.getDescriptionSYS10()+"\t"+
docVO.getCurrencyCodeReg03DOC01()+"\t"+
docRowVO.getValueDOC02()
);
}
pw.println();
if (docVO.getDiscountPercDOC01()!=null)
pw.println(
"%"+"\t"+
docVO.getDiscountPercDOC01()
);
if (docVO.getDiscountValueDOC01()!=null)
pw.println(
docVO.getCurrencyCodeReg03DOC01()+"\t"+
docVO.getDiscountValueDOC01()
);
pw.println();
pw.println(
docVO.getCurrencyCodeReg03DOC01()+"\t"+
docVO.getTotalDOC01()
);
pw.println();
SimpleDateFormat sdf = new SimpleDateFormat(t3);
pw.println(sdf.format(new java.util.Date()));
pw.println();
pw.println(docVO.getDocSequenceDOC01());
pw.close();
// "commit" file...
String file = path+"/receipt_"+docVO.getDocYearDOC01()+"_"+docVO.getDocSequenceDOC01()+".txt";
new File(tmpFile).renameTo(new File(file));
// call external application that manages this text file...
Process p = Runtime.getRuntime().exec(programPath+" "+file);
LogProcessMessage log = new LogProcessMessage(username,p.getInputStream());
LogErrorProcessMessage errorLog = new LogErrorProcessMessage(username,p.getErrorStream());
int returnCode = p.waitFor();
if (returnCode!=0) {
throw new Exception(t4+" "+returnCode);
}
return new VOResponse(Boolean.TRUE);
}
catch (Throwable ex) {
Logger.error(username,this.getClass().getName(),"executeCommand","Error while exporting a retail sale to file",ex);
throw new Exception(ex.getMessage());
}