Search in sources :

Example 1 with MLARPaymentHeader

use of ar.com.ergio.model.MLARPaymentHeader in project lar_361 by comitsrl.

the class LAR_ProcessPaymentHeader method doIt.

protected String doIt() throws Exception {
    String result = "Documento procesado con éxito";
    MLARPaymentHeader header = new MLARPaymentHeader(getCtx(), paymentHeader_ID, get_TrxName());
    if (!header.processIt(accion))
        result = "No se pudo procesar el documento";
    return result;
}
Also used : MLARPaymentHeader(ar.com.ergio.model.MLARPaymentHeader)

Example 2 with MLARPaymentHeader

use of ar.com.ergio.model.MLARPaymentHeader in project lar_361 by comitsrl.

the class PosOrderGlobalVoiding method doIt.

// prepare
@Override
protected String doIt() throws Exception {
    log.info("C_Order_ID=" + p_C_Order_ID);
    m_processMsg = new StringBuilder();
    final MOrder order = new MOrder(getCtx(), p_C_Order_ID, get_TrxName());
    int count = 0;
    // Primero recupera las facturas asociadas a la orden
    // (previo a anulación de orden, porque sino se recuperarían también las anuladas)
    final MInvoice[] invoices = order.getInvoices();
    for (int i = 0; i < invoices.length; i++) {
        count++;
        int c_Invoice_ID = invoices[i].getC_Invoice_ID();
        // Recupera y anula la cabecera de cobros/pagos asociada a la factura
        // en caso de tratarse de una factura de venta al contado (cabecera no nula)
        final MLARPaymentHeader header = MLARPaymentHeader.getFromInvoice(getCtx(), c_Invoice_ID, get_TrxName());
        if (header == null)
            continue;
        if (header.processIt(MLARPaymentHeader.ACTION_Void)) {
            header.save(get_TrxName());
            m_processMsg.append("Cabecera de cobros anulada correctamente");
        } else
            m_processMsg.append("Cabecera de corbos: ").append(order.getProcessMsg());
    }
    // e imputaciones de pago.
    if (order.processIt(MOrder.ACTION_Void)) {
        order.save(get_TrxName());
        m_processMsg.append(", @C_Order_ID@ anulada correctamente");
    } else
        m_processMsg.append(", @C_Order_ID@: ").append(order.getProcessMsg());
    // Retrocede la secuencia asociada al tipo de documento de la factura
    for (int i = 0; i < invoices.length; i++) {
        int AD_Sequence_ID = invoices[i].getC_DocType().getDefiniteSequence_ID();
        final MSequence seq = new MSequence(getCtx(), AD_Sequence_ID, invoices[i].get_TrxName());
        seq.setCurrentNext(seq.getCurrentNext() - count);
        if (!seq.save())
            m_processMsg.append(", @AD_Sequence_ID@: Error al guardar");
    }
    return m_processMsg.toString();
}
Also used : MLARPaymentHeader(ar.com.ergio.model.MLARPaymentHeader) MOrder(org.compiere.model.MOrder) MInvoice(org.compiere.model.MInvoice) MSequence(org.compiere.model.MSequence)

Example 3 with MLARPaymentHeader

use of ar.com.ergio.model.MLARPaymentHeader in project lar_361 by comitsrl.

the class PosOrderModel method createPayment.

// payCheck
private MPayment createPayment(String tenderType) {
    if (paymentHeader == null) {
        paymentHeader = new MLARPaymentHeader(getCtx(), 0, get_TrxName());
        paymentHeader.setAD_Org_ID(m_pos.getAD_Org_ID());
        paymentHeader.setC_DocType_ID(m_pos.get_ValueAsInt("C_Payment_DocType_ID"));
        paymentHeader.setC_BPartner_ID(getC_BPartner_ID());
        paymentHeader.setDateTrx(Env.getContextAsDate(getCtx(), "#Date"));
        paymentHeader.setDocStatus(DocAction.STATUS_Drafted);
        paymentHeader.setIsReceipt(true);
        paymentHeader.saveEx();
    }
    MPayment payment = new MPayment(getCtx(), 0, get_TrxName());
    payment.setAD_Org_ID(m_pos.getAD_Org_ID());
    payment.setTenderType(tenderType);
    payment.setC_Order_ID(getC_Order_ID());
    payment.setIsReceipt(true);
    payment.setC_BPartner_ID(getC_BPartner_ID());
    payment.set_ValueOfColumn("LAR_PaymentHeader_ID", paymentHeader.getLAR_PaymentHeader_ID());
    // Si tiene descuento asignado, lo registra como un writeOffAmt
    if (discount.compareTo(Env.ZERO) > 0)
        payment.setWriteOffAmt(discount);
    return payment;
}
Also used : MLARPaymentHeader(ar.com.ergio.model.MLARPaymentHeader) MPayment(org.compiere.model.MPayment)

Example 4 with MLARPaymentHeader

use of ar.com.ergio.model.MLARPaymentHeader in project lar_361 by comitsrl.

the class MPayment method anularCopias.

// getApprovalAmt
/**
 * Anular copias de cobro, creadas por transferencia.
 * @author fchiappano
 * @return
 */
private boolean anularCopias() {
    String sql = "SELECT C_Payment_ID" + "  FROM C_Payment" + " WHERE LAR_PaymentSource_ID=?";
    PreparedStatement pstmt = null;
    ResultSet rs = null;
    try {
        pstmt = DB.prepareStatement(sql, get_TrxName());
        pstmt.setInt(1, getC_Payment_ID());
        rs = pstmt.executeQuery();
        while (rs.next()) {
            MPayment paymentCopia = new MPayment(p_ctx, rs.getInt("C_Payment_ID"), get_TrxName());
            // @fchiappano si el cobro/pago copia, ya fue conciliado en
            // cuenta bancaria, no se puede anular.
            final int C_BankStatementLine_ID = paymentCopia.getC_BankStatementLine_ID();
            if (C_BankStatementLine_ID > 0) {
                MBankStatementLine stmtLine = new MBankStatementLine(p_ctx, C_BankStatementLine_ID, get_TrxName());
                if (!((MBankStatement) stmtLine.getC_BankStatement()).get_ValueAsBoolean("EsCierreCaja")) {
                    m_processMsg = "No se puede anular el cobro, ya que el mismo ya fue conciliado en una cuenta bancaria.";
                    return false;
                }
            }
            // pago, no se puede anular.
            if (!paymentCopia.isReceipt() && !paymentCopia.getDocStatus().equals(DOCSTATUS_Voided) && !paymentCopia.getDocStatus().equals(DOCSTATUS_Reversed)) {
                int LAR_PaymentHeader_ID = paymentCopia.get_ValueAsInt("LAR_PaymentHeader_ID");
                if (LAR_PaymentHeader_ID > 0) {
                    MLARPaymentHeader header = new MLARPaymentHeader(p_ctx, LAR_PaymentHeader_ID, get_TrxName());
                    m_processMsg = "No se puede anular el cobro seleccionado. El mismo está siendo utilizado en la Orden de Pago Nro: " + header.getDocumentNo();
                    return false;
                }
            }
            // Anulo la copia del cobro/pago.
            if (!paymentCopia.voidIt()) {
                m_processMsg = paymentCopia.getProcessMsg();
                return false;
            }
            // @fchiappano Marco el cobro reverso, como conciliado.
            MPayment reverso = (MPayment) paymentCopia.getReversal();
            reverso.setIsReconciled(true);
            reverso.saveEx();
            paymentCopia.saveEx();
        }
    } catch (SQLException e) {
        log.log(Level.SEVERE, sql, e);
    } finally {
        DB.close(rs, pstmt);
        rs = null;
        pstmt = null;
    }
    return true;
}
Also used : MLARPaymentHeader(ar.com.ergio.model.MLARPaymentHeader) SQLException(java.sql.SQLException) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement)

Example 5 with MLARPaymentHeader

use of ar.com.ergio.model.MLARPaymentHeader in project lar_361 by comitsrl.

the class LAR_OnDrawerChecksSelection method doIt.

protected String doIt() throws Exception {
    String result = "No se seleccionaron documentos";
    MLARPaymentHeader header = new MLARPaymentHeader(getCtx(), paymentHeader_ID, get_TrxName());
    Frame frame = new Frame();
    String usedDocs = // Consulta que devuelve el ID de los documentos (recibos) que ya
    "" + // fueron transferidos en algún pago, siempre y cuando ese pago no haya sido cancelado
    "SELECT " + "		distinct(REC.c_payment_id) " + "FROM c_payment PAY " + "		INNER JOIN c_payment REC " + "		ON REC.c_payment_id = PAY.lar_paymentsource_id " + "		AND REC.Processed='Y' " + "		AND REC.isReceipt='Y' " + "		AND PAY.docstatus NOT IN('IN', 'RE', 'VO')  ";
    // Marcos Zúñiga add IsOnDrawer='Y' condition
    String ondrawer = "" + "SELECT " + "      C_Payment_ID " + "FROM C_Payment pt " + "WHERE " + "      pt.IsOnDrawer='Y'" + "      AND pt.C_BankAccount_ID=" + header.getC_BankAccount_ID();
    ;
    String whereSQL = "isReceipt='Y' AND Docstatus IN ('CO','CL') AND TenderType IN ('K') AND C_Payment_ID NOT IN (" + usedDocs + ") AND C_Payment_ID IN (" + ondrawer + ")";
    Info inf = InfoOnDrawerChecks.create(frame, true, 0, "C_Payment", "C_Payment_ID", "", true, whereSQL);
    AEnv.showCenterWindow(frame, inf);
    Object[] pays = inf.getSelectedKeys();
    if (pays == null)
        return result;
    for (int i = 0; i < pays.length; i++) {
        MPayment receipt = new MPayment(Env.getCtx(), (Integer) pays[i], get_TrxName());
        MPayment pay = new MPayment(Env.getCtx(), 0, get_TrxName());
        PO.copyValues(receipt, pay);
        pay.set_CustomColumn("LAR_PaymentHeader_ID", header.getLAR_PaymentHeader_ID());
        pay.set_CustomColumn("LAR_PaymentSource_ID", receipt.getC_Payment_ID());
        pay.setC_DocType_ID(header.getC_DocType_ID());
        pay.setDocumentNo(header.getDocumentNo());
        pay.setDocStatus(header.getDocStatus());
        pay.setDateTrx(header.getDateTrx());
        pay.setDateAcct(header.getDateTrx());
        pay.setErrorMessage("");
        pay.setC_BPartner_ID(header.getC_BPartner_ID());
        pay.setC_BankAccount_ID(header.getC_BankAccount_ID());
        pay.setIsReceipt(header.isReceipt());
        // pay.setProcessed(header.isProcessed());
        pay.setProcessed(false);
        pay.setIsActive(header.isActive());
        pay.setPosted(false);
        // Marcos Zúñiga
        pay.setC_Invoice_ID(header.getC_Invoice_ID());
        // Marcos Zúñiga
        pay.setC_Order_ID(0);
        pay.setIsApproved(false);
        pay.setIsAllocated(false);
        pay.setIsDelayedCapture(false);
        pay.setIsOnline(false);
        pay.setIsPrepayment(false);
        pay.setIsReconciled(false);
        pay.setOProcessing("N");
        pay.setOrig_TrxID("");
        pay.setPONum("");
        pay.setRef_Payment_ID(0);
        pay.setReversal_ID(0);
        pay.setReplication(false);
        pay.setTrxType(MPayment.TRXTYPE_Sales);
        pay.setUser1_ID(0);
        pay.setUser2_ID(0);
        pay.setVoiceAuthCode("");
        pay.setOverUnderAmt(Env.ZERO);
        pay.setWriteOffAmt(Env.ZERO);
        pay.setIsOverUnderPayment(false);
        // Cheque de Terceros
        pay.setTenderType("Z");
        receipt.setIsReconciled(false);
        if (!pay.save(get_TrxName())) {
            rollback();
            throw new AdempiereSystemError("Error al seleccionar documentos");
        }
        if (!receipt.save(get_TrxName())) {
            rollback();
            throw new AdempiereSystemError("Error al seleccionar documentos");
        }
    }
    result = pays.length + " Documentos seleccionados";
    return result;
}
Also used : MLARPaymentHeader(ar.com.ergio.model.MLARPaymentHeader) Frame(java.awt.Frame) AdempiereSystemError(org.compiere.util.AdempiereSystemError) MPayment(org.compiere.model.MPayment) Info(org.compiere.apps.search.Info)

Aggregations

MLARPaymentHeader (ar.com.ergio.model.MLARPaymentHeader)5 MPayment (org.compiere.model.MPayment)2 Frame (java.awt.Frame)1 PreparedStatement (java.sql.PreparedStatement)1 ResultSet (java.sql.ResultSet)1 SQLException (java.sql.SQLException)1 Info (org.compiere.apps.search.Info)1 MInvoice (org.compiere.model.MInvoice)1 MOrder (org.compiere.model.MOrder)1 MSequence (org.compiere.model.MSequence)1 AdempiereSystemError (org.compiere.util.AdempiereSystemError)1