}
}
// after rows insertion, total doc has been updated, without considering total discount:
// sale doc header will be reloaded, in order to apply header discount and update total amount...
SaleDocPK pk = new SaleDocPK(detailSaleDocVO.getCompanyCodeSys01DOC01(),detailSaleDocVO.getDocTypeDOC01(),detailSaleDocVO.getDocYearDOC01(),detailSaleDocVO.getDocNumberDOC01());
res = ClientUtils.getData("loadSaleDoc",pk);
if (res.isError()) {
Logger.error(
this.getClass().getName(),
"buttonClose_actionPerformed",
"Error on creating document: "+res.getErrorMessage(),
null
);
return;
}
DetailSaleDocVO oldDetailSaleDocVO = (DetailSaleDocVO)((VOResponse)res).getVo();
res = ClientUtils.getData("updateSaleDoc",new ValueObject[]{oldDetailSaleDocVO,detailSaleDocVO});
if (res.isError()) {
Logger.error(
this.getClass().getName(),
"buttonClose_actionPerformed",
"Error on creating document: "+res.getErrorMessage(),
null
);
return;
}
res = ClientUtils.getData("closeSaleDoc",new SaleDocPK(
detailSaleDocVO.getCompanyCodeSys01DOC01(),
detailSaleDocVO.getDocTypeDOC01(),
detailSaleDocVO.getDocYearDOC01(),
detailSaleDocVO.getDocNumberDOC01()
));
if (!res.isError()) {
// prompt user if a sale invoice must be created...
if (JOptionPane.showConfirmDialog(
this,
ClientSettings.getInstance().getResources().getResource("create sale invoice?"),
ClientSettings.getInstance().getResources().getResource("desk selling invoice"),
JOptionPane.YES_NO_OPTION)==JOptionPane.YES_OPTION
) {
DetailSaleDocVO invoiceVO = null;
try {
invoiceVO = (DetailSaleDocVO) detailSaleDocVO.clone();
}
catch (CloneNotSupportedException ex) {
ex.printStackTrace();
}
Calendar cal = Calendar.getInstance();
invoiceVO.setCompanyCodeSys01Doc01DOC01(detailSaleDocVO.getCompanyCodeSys01DOC01());
invoiceVO.setDocTypeDoc01DOC01(detailSaleDocVO.getDocTypeDOC01());
invoiceVO.setDocYearDoc01DOC01(detailSaleDocVO.getDocYearDOC01());
invoiceVO.setDocNumberDoc01DOC01(detailSaleDocVO.getDocNumberDOC01());
invoiceVO.setDocSequenceDoc01DOC01(((BigDecimal)((VOResponse)res).getVo()));
invoiceVO.setDocYearDOC01(new BigDecimal(cal.get(cal.YEAR)));
invoiceVO.setDocDateDOC01(new java.sql.Date(System.currentTimeMillis()));
invoiceVO.setDocTypeDOC01(ApplicationConsts.SALE_INVOICE_FROM_SD_DOC_TYPE);
invoiceVO.setDocStateDOC01(ApplicationConsts.OPENED);
invoiceVO.setDocNumberDOC01(null);
invoiceVO.setDocSequenceDOC01(null);
res = ClientUtils.getData("createInvoiceFromSaleDoc",invoiceVO);
if (!res.isError()) {
invoiceVO = (DetailSaleDocVO)((VOResponse)res).getVo();
new SaleInvoiceDocFromSaleDocController(null,new SaleDocPK(
invoiceVO.getCompanyCodeSys01DOC01(),
invoiceVO.getDocTypeDOC01(),
invoiceVO.getDocYearDOC01(),
invoiceVO.getDocNumberDOC01()
));