Search in sources :

Example 1 with PaymentExport

use of org.compiere.util.PaymentExport in project adempiere by adempiere.

the class VPayPrint method cmd_export.

//  loadPaymentRuleInfo
/**************************************************************************
	 *  Export payments to file
	 */
private void cmd_export() {
    ValueNamePair pp = (ValueNamePair) fPaymentRule.getSelectedItem();
    if (pp == null)
        return;
    String paymentRule = pp.getValue();
    log.info(paymentRule);
    if (!getChecks(paymentRule))
        return;
    //  Get File Info
    JFileChooser fc = new JFileChooser();
    fc.setDialogTitle(Msg.getMsg(Env.getCtx(), "Export"));
    fc.setFileSelectionMode(JFileChooser.FILES_ONLY);
    fc.setMultiSelectionEnabled(false);
    fc.setSelectedFile(new java.io.File("paymentExport.txt"));
    if (fc.showSaveDialog(panel) != JFileChooser.APPROVE_OPTION)
        return;
    //  Create File
    int no = 0;
    StringBuffer error = new StringBuffer("");
    if (paymentExportClass == null || paymentExportClass.trim().length() == 0) {
        paymentExportClass = "org.compiere.util.GenericPaymentExport";
    }
    try {
        Class<?> clazz = Class.forName(paymentExportClass);
        if (clazz.isInstance(PaymentExportList.class)) {
            PaymentExportList custom = (PaymentExportList) clazz.newInstance();
            no = custom.exportToFile(paySelectionChecks, fc.getSelectedFile(), error);
        } else if (clazz.isInstance(PaymentExport.class)) {
            PaymentExport custom = (PaymentExport) clazz.newInstance();
            no = custom.exportToFile(paySelectionChecks.toArray(new MPaySelectionCheck[paySelectionChecks.size()]), fc.getSelectedFile(), error);
        }
    } catch (ClassNotFoundException e) {
        no = -1;
        error.append("No custom PaymentExport class " + paymentExportClass + " - " + e.toString());
        log.log(Level.SEVERE, error.toString(), e);
    } catch (Exception e) {
        no = -1;
        error.append("Error in " + paymentExportClass + " check log, " + e.toString());
        log.log(Level.SEVERE, error.toString(), e);
    }
    if (no >= 0) {
        ADialog.info(windowNo, panel, "Saved", fc.getSelectedFile().getAbsolutePath() + "\n" + Msg.getMsg(Env.getCtx(), "NoOfLines") + "=" + no);
        if (ADialog.ask(windowNo, panel, "VPayPrintSuccess?")) {
            //	int lastDocumentNo = 
            MPaySelectionCheck.confirmPrint(paySelectionChecks, paymentBatch);
        //	document No not updated
        }
    } else {
        ADialog.error(windowNo, panel, "Error", error.toString());
    }
    dispose();
}
Also used : PropertyVetoException(java.beans.PropertyVetoException) MPaySelectionCheck(org.compiere.model.MPaySelectionCheck) JFileChooser(javax.swing.JFileChooser) PaymentExportList(org.compiere.util.PaymentExportList) ValueNamePair(org.compiere.util.ValueNamePair) PaymentExport(org.compiere.util.PaymentExport)

Example 2 with PaymentExport

use of org.compiere.util.PaymentExport in project adempiere by adempiere.

the class WPayPrint method cmd_export.

//  loadPaymentRuleInfo
/**************************************************************************
	 *  Export payments to file
	 */
private void cmd_export() {
    if (fPaymentRule.getSelectedItem() == null)
        return;
    String paymentRule = fPaymentRule.getSelectedItem().toValueNamePair().getValue();
    log.info(paymentRule);
    if (!getChecks(paymentRule))
        return;
    try {
        //  Get File Info
        File tempFile = File.createTempFile("paymentExport", ".txt");
        //  Create File
        int no = 0;
        StringBuffer error = new StringBuffer("");
        if (paymentExportClass == null || paymentExportClass.trim().length() == 0) {
            paymentExportClass = "org.compiere.util.GenericPaymentExport";
        }
        //	Get Payment Export Class
        try {
            Class<?> clazz = Class.forName(paymentExportClass);
            if (clazz.isInstance(PaymentExportList.class)) {
                PaymentExportList custom = (PaymentExportList) clazz.newInstance();
                no = custom.exportToFile(paySelectionChecks, tempFile, error);
            } else if (clazz.isInstance(PaymentExport.class)) {
                PaymentExport custom = (PaymentExport) clazz.newInstance();
                no = custom.exportToFile(paySelectionChecks.toArray(new MPaySelectionCheck[paySelectionChecks.size()]), tempFile, error);
            }
        } catch (ClassNotFoundException e) {
            no = -1;
            error.append("No custom PaymentExport class " + paymentExportClass + " - " + e.toString());
            log.log(Level.SEVERE, error.toString(), e);
        } catch (Exception e) {
            no = -1;
            error.append("Error in " + paymentExportClass + " check log, " + e.toString());
            log.log(Level.SEVERE, error.toString(), e);
        }
        if (no >= 0) {
            Filedownload.save(new FileInputStream(tempFile), "plain/text", "paymentExport.txt");
            FDialog.info(windowNo, form, "Saved", Msg.getMsg(Env.getCtx(), "NoOfLines") + "=" + no);
            if (FDialog.ask(windowNo, form, "VPayPrintSuccess?")) {
                //	int lastDocumentNo = 
                MPaySelectionCheck.confirmPrint(paySelectionChecks, paymentBatch);
            //	document No not updated
            }
        } else {
            FDialog.error(windowNo, form, "Error", error.toString());
        }
        dispose();
    } catch (Exception e) {
        log.log(Level.SEVERE, e.getLocalizedMessage(), e);
    }
}
Also used : MPaySelectionCheck(org.compiere.model.MPaySelectionCheck) PaymentExportList(org.compiere.util.PaymentExportList) PaymentExport(org.compiere.util.PaymentExport) File(java.io.File) PayPrint(org.compiere.apps.form.PayPrint) FileInputStream(java.io.FileInputStream)

Aggregations

MPaySelectionCheck (org.compiere.model.MPaySelectionCheck)2 PaymentExport (org.compiere.util.PaymentExport)2 PaymentExportList (org.compiere.util.PaymentExportList)2 PropertyVetoException (java.beans.PropertyVetoException)1 File (java.io.File)1 FileInputStream (java.io.FileInputStream)1 JFileChooser (javax.swing.JFileChooser)1 PayPrint (org.compiere.apps.form.PayPrint)1 ValueNamePair (org.compiere.util.ValueNamePair)1