Search in sources :

Example 1 with MPaySelectionCheck

use of org.compiere.model.MPaySelectionCheck 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 MPaySelectionCheck

use of org.compiere.model.MPaySelectionCheck in project adempiere by adempiere.

the class Process method startCheckPrint.

//	startStandardReport
/**
	 * 	Start Check Print.
	 * 	Find/Create
	 *	@param C_Payment_ID Payment
	 * 	@param IsDirectPrint if true, prints directly - otherwise View
	 * 	@return true if success
	 */
public static ReportEngine startCheckPrint(int C_Payment_ID) {
    int C_PaySelectionCheck_ID = 0;
    MPaySelectionCheck psc = MPaySelectionCheck.getOfPayment(Env.getCtx(), C_Payment_ID, null);
    if (psc != null)
        C_PaySelectionCheck_ID = psc.getC_PaySelectionCheck_ID();
    else {
        psc = MPaySelectionCheck.createForPayment(Env.getCtx(), C_Payment_ID, null);
        if (psc != null)
            C_PaySelectionCheck_ID = psc.getC_PaySelectionCheck_ID();
    }
    return startDocumentPrint(ReportEngine.CHECK, C_PaySelectionCheck_ID);
}
Also used : MPaySelectionCheck(org.compiere.model.MPaySelectionCheck) JasperPrint(net.sf.jasperreports.engine.JasperPrint)

Example 3 with MPaySelectionCheck

use of org.compiere.model.MPaySelectionCheck in project adempiere by adempiere.

the class PaySelectionCreateCheck method createCheck.

//	doIt
/**
	 * 	Create Check from line
	 *	@param line
	 *	@throws Exception for invalid bank accounts
	 */
private void createCheck(MPaySelectionLine line) throws Exception {
    //	Try to find one
    for (int i = 0; i < paySelectionChecks.size(); i++) {
        MPaySelectionCheck check = (MPaySelectionCheck) paySelectionChecks.get(i);
        //	Add to existing
        if (check.getC_BPartner_ID() == line.getInvoice().getC_BPartner_ID()) {
            check.addLine(line);
            if (!check.save())
                throw new IllegalStateException("Cannot save MPaySelectionCheck");
            line.setC_PaySelectionCheck_ID(check.getC_PaySelectionCheck_ID());
            line.setProcessed(true);
            if (!line.save())
                throw new IllegalStateException("Cannot save MPaySelectionLine");
            return;
        }
    }
    //	Create new
    String PaymentRule = line.getPaymentRule();
    if (p_PaymentRule != null) {
        if (!X_C_Order.PAYMENTRULE_DirectDebit.equals(PaymentRule))
            PaymentRule = p_PaymentRule;
    }
    MPaySelectionCheck check = new MPaySelectionCheck(line, PaymentRule);
    if (!check.isValid()) {
        int C_BPartner_ID = check.getC_BPartner_ID();
        MBPartner bp = MBPartner.get(getCtx(), C_BPartner_ID);
        String msg = "@NotFound@ @C_BP_BankAccount@: " + bp.getName();
        throw new AdempiereUserError(msg);
    }
    if (!check.save())
        throw new IllegalStateException("Cannot save MPaySelectionCheck");
    line.setC_PaySelectionCheck_ID(check.getC_PaySelectionCheck_ID());
    line.setProcessed(true);
    if (!line.save())
        throw new IllegalStateException("Cannot save MPaySelectionLine");
    paySelectionChecks.add(check);
}
Also used : MPaySelectionCheck(org.compiere.model.MPaySelectionCheck) AdempiereUserError(org.compiere.util.AdempiereUserError) MBPartner(org.compiere.model.MBPartner)

Example 4 with MPaySelectionCheck

use of org.compiere.model.MPaySelectionCheck in project adempiere by adempiere.

the class GenericPaymentExport method exportToFile.

/**************************************************************************
	 *  Export to File
	 *  @param paySelectionChecks array of checks
	 *  @param file file to export checks
	 *  @return number of lines
	 */
public int exportToFile(List<MPaySelectionCheck> paySelectionChecks, File file, StringBuffer error) {
    if (paySelectionChecks == null || paySelectionChecks.size() == 0)
        return 0;
    //  Must be a file
    if (file.isDirectory()) {
        error.append("No se puede escribir, el archivo seleccionado es un directorio - " + file.getAbsolutePath());
        s_log.log(Level.SEVERE, error.toString());
        return -1;
    }
    //  delete if exists
    try {
        if (file.exists())
            file.delete();
    } catch (Exception e) {
        s_log.log(Level.WARNING, "Could not delete - " + file.getAbsolutePath(), e);
    }
    //  ease
    char x = '"';
    int noLines = 0;
    StringBuffer line = null;
    try {
        FileWriter fw = new FileWriter(file);
        //  write header
        line = new StringBuffer();
        line.append(x).append("Value").append(x).append(",").append(x).append("Name").append(x).append(",").append(x).append("Contact").append(x).append(",").append(x).append("Addr1").append(x).append(",").append(x).append("Addr2").append(x).append(",").append(x).append("City").append(x).append(",").append(x).append("State").append(x).append(",").append(x).append("ZIP").append(x).append(",").append(x).append("Country").append(x).append(",").append(x).append("ReferenceNo").append(x).append(",").append(x).append("DocumentNo").append(x).append(",").append(x).append("PayDate").append(x).append(",").append(x).append("Currency").append(x).append(",").append(x).append("PayAmount").append(x).append(",").append(x).append("Comment").append(x).append(Env.NL);
        fw.write(line.toString());
        noLines++;
        //  write lines
        for (MPaySelectionCheck paySelectionCheck : paySelectionChecks) {
            if (paySelectionCheck == null)
                continue;
            //  BPartner Info
            String[] bp = getBPartnerInfo(paySelectionCheck.getC_BPartner_ID());
            //  Comment - list of invoice document no
            StringBuffer comment = new StringBuffer();
            List<MPaySelectionLine> paySelectionLines = paySelectionCheck.getPaySelectionLinesAsList(false);
            for (MPaySelectionLine paySelectionLine : paySelectionLines) {
                if (paySelectionLine.get_ID() == paySelectionLines.get(0).get_ID())
                    comment.append(", ");
                comment.append(paySelectionLine.getInvoice().getDocumentNo());
            }
            line = new StringBuffer();
            // Value
            line.append(x).append(bp[BP_VALUE]).append(x).append(",").append(x).append(bp[BP_NAME]).append(x).append(// Name
            ",").append(x).append(bp[BP_CONTACT]).append(x).append(// Contact
            ",").append(x).append(bp[BP_ADDR1]).append(x).append(// Addr1
            ",").append(x).append(bp[BP_ADDR2]).append(x).append(// Addr2
            ",").append(x).append(bp[BP_CITY]).append(x).append(// City
            ",").append(x).append(bp[BP_REGION]).append(x).append(// State
            ",").append(x).append(bp[BP_POSTAL]).append(x).append(// ZIP
            ",").append(x).append(bp[BP_COUNTRY]).append(x).append(// Country
            ",").append(x).append(bp[BP_REFNO]).append(x).append(// ReferenceNo
            ",").append(x).append(paySelectionCheck.getDocumentNo()).append(x).append(// DocumentNo
            ",").append(paySelectionCheck.getParent().getPayDate()).append(// PayDate
            ",").append(x).append(MCurrency.getISO_Code(Env.getCtx(), paySelectionCheck.getParent().getC_Currency_ID())).append(x).append(// Currency
            ",").append(paySelectionCheck.getPayAmt()).append(// PayAmount
            ",").append(x).append(comment.toString()).append(// Comment
            x).append(Env.NL);
            fw.write(line.toString());
            noLines++;
        }
        //  write line
        fw.flush();
        fw.close();
    } catch (Exception e) {
        error.append(e.toString());
        s_log.log(Level.SEVERE, "", e);
        return -1;
    }
    return noLines;
}
Also used : MPaySelectionLine(org.compiere.model.MPaySelectionLine) MPaySelectionCheck(org.compiere.model.MPaySelectionCheck) FileWriter(java.io.FileWriter) SQLException(java.sql.SQLException)

Example 5 with MPaySelectionCheck

use of org.compiere.model.MPaySelectionCheck 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)7 MPaySelectionLine (org.compiere.model.MPaySelectionLine)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 FileWriter (java.io.FileWriter)1 BigDecimal (java.math.BigDecimal)1 SQLException (java.sql.SQLException)1 JFileChooser (javax.swing.JFileChooser)1 JasperPrint (net.sf.jasperreports.engine.JasperPrint)1 PayPrint (org.compiere.apps.form.PayPrint)1 MBPartner (org.compiere.model.MBPartner)1 MInvoice (org.compiere.model.MInvoice)1 MPayment (org.compiere.model.MPayment)1 AdempiereUserError (org.compiere.util.AdempiereUserError)1 ValueNamePair (org.compiere.util.ValueNamePair)1