martes, 25 de julio de 2017

Do not allow reverse paid invoice in iDempiere





/***
  @author: José Francisco Rodríguez Chávez
  @email: jfrodriguez.idempiere@gmail.com
  @created: 25/07/2017 11:25 am
  @lastupdated: 25/07/2017 11:25 am
  @version: 1.0
  @description:Do not allow reverse paid invoice
  @name: beanshell:DontAllowReversePaidInvoice
***/

import org.compiere.util.DB;
import org.compiere.util.Env;
import org.adempiere.webui.window.FDialog;

id_factura = A_PO.get_Value("C_Invoice_ID");
id_usuario =  Env.getAD_User_ID(Env.getCtx());

String resultado = "";

pcheck = (id_factura == null || id_factura == VOID);

if(!pcheck)
{
    String consulta = "SELECT count(al.*) " +
                      "FROM c_invoice i " +
                      "INNER JOIN c_allocationline al ON i.c_invoice_id = al.c_invoice_id " +
                      "INNER JOIN c_payment p ON al.c_payment_id = p.c_payment_id " +
                      "WHERE i.c_invoice_id = ? " +
                      "AND i.docstatus in ('CO', 'CL') " +
                      "AND p.docstatus not in ('RE', 'VO');";

    Object[] parametro = new Object[]{id_factura};

    int valorRetornado = DB.getSQLValue(null, consulta, parametro);

    if(valorRetornado > 0) {
        resultado = "Error: Can not revert invoice that has an assigned payment. Please check.";
    }
}

return resultado;

No hay comentarios:

Publicar un comentario