Search in sources :

Example 11 with MBankAccount

use of org.compiere.model.MBankAccount in project lar_361 by comitsrl.

the class MLARRetiroCaja method completeIt.

// rejectIt
@Override
public String completeIt() {
    for (X_LAR_RetiroCajaLine linea : obtenerLineas()) {
        // Verifico que el importe ingresado, sea mayor a 0.
        if (linea.getMonto().compareTo(Env.ZERO) <= 0) {
            m_processMsg = "Por favor, ingrese un importe.";
            return STATUS_Drafted;
        }
        // Pago que debita los valores transferidos de la cuenta.
        final MPayment paymentBankFrom = new MPayment(getCtx(), 0, get_TrxName());
        final MPayment cobro = new MPayment(getCtx(), linea.getCobro_ID(), get_TrxName());
        // Si se trata de una Extaccion Bancaria, tomo la cuenta bancaria origen.
        if (get_ValueAsBoolean("ExtraccionBancaria") || get_ValueAsBoolean("TransferenciaBancaria"))
            paymentBankFrom.setC_BankAccount_ID(get_ValueAsInt("CuentaOrigen_ID"));
        else
            paymentBankFrom.setC_BankAccount_ID(getC_BankAccountFrom_ID());
        paymentBankFrom.setDateAcct(new Timestamp(System.currentTimeMillis()));
        paymentBankFrom.setDateTrx(new Timestamp(System.currentTimeMillis()));
        paymentBankFrom.setDescription(getDescription());
        paymentBankFrom.setC_BPartner_ID(MSysConfig.getIntValue("LAR_SdN_MovimientosDeCaja", 0, Env.getAD_Client_ID(getCtx())));
        paymentBankFrom.setC_Currency_ID(getC_Currency_ID());
        paymentBankFrom.setPayAmt(linea.getMonto());
        paymentBankFrom.setOverUnderAmt(Env.ZERO);
        paymentBankFrom.setPosted(true);
        paymentBankFrom.setLAR_C_DoctType_ID(false, ((MBankAccount) paymentBankFrom.getC_BankAccount()).get_ValueAsBoolean("IsDrawer") ? paymentBankFrom.getC_BankAccount().getAD_Org_ID() : Env.getAD_Org_ID(p_ctx));
        // Si el TenderType es cheque, cambio la marca IsOnDrawer a false.
        if (linea.getTenderType().equals("Z")) {
            paymentBankFrom.setTenderType(cobro.getTenderType());
            paymentBankFrom.setRoutingNo(cobro.getRoutingNo());
            paymentBankFrom.setCheckNo(cobro.getCheckNo());
            paymentBankFrom.setAccountNo(cobro.getAccountNo());
            paymentBankFrom.setA_Name(cobro.getA_Name());
            paymentBankFrom.set_ValueOfColumn("LAR_PaymentSource_ID", cobro.getC_Payment_ID());
            final String sql = "UPDATE C_Payment" + "   SET IsOnDrawer='N'" + " WHERE C_Payment_ID='" + cobro.getC_Payment_ID() + "'";
            DB.executeUpdate(sql, get_TrxName());
        } else {
            paymentBankFrom.setTenderType(MPayment.TENDERTYPE_Cash);
            paymentBankFrom.set_ValueOfColumn("IsOnDrawer", false);
        }
        paymentBankFrom.saveEx();
        if (paymentBankFrom.processIt(MPayment.DOCACTION_Complete)) {
            paymentBankFrom.saveEx();
            linea.setPago_ID(paymentBankFrom.getC_Payment_ID());
            linea.saveEx();
        } else {
            m_processMsg = "No se ha podido procesar el pago correspondiente al retiro de efectivo.";
            return STATUS_Drafted;
        }
        if (isTransferencia() || get_ValueAsBoolean("Deposito") || get_ValueAsBoolean("ExtraccionBancaria") || get_ValueAsBoolean("TransferenciaBancaria")) {
            final MPayment paymentBankTo = new MPayment(getCtx(), 0, get_TrxName());
            // Si el tenderType es cheque, copio los campos pertinentes al mismo.
            if (linea.getTenderType().equals("Z")) {
                paymentBankTo.setTenderType(linea.getTenderType());
                paymentBankTo.setRoutingNo(cobro.getRoutingNo());
                paymentBankTo.setCheckNo(cobro.getCheckNo());
                paymentBankTo.setAccountNo(cobro.getAccountNo());
                paymentBankTo.setA_Name(cobro.getA_Name());
                paymentBankTo.set_ValueOfColumn("LAR_PaymentSource_ID", cobro.getC_Payment_ID());
                if (isTransferencia())
                    paymentBankTo.set_ValueOfColumn("IsOnDrawer", true);
                else {
                    paymentBankTo.set_ValueOfColumn("IsOnDrawer", false);
                    cobro.set_ValueOfColumn("IsDeposited", true);
                    cobro.saveEx();
                }
            } else {
                paymentBankTo.setTenderType(MPayment.TENDERTYPE_Cash);
                paymentBankTo.set_ValueOfColumn("IsOnDrawer", false);
            }
            // Si es una trasferencia o una extraccion bancaria, seteo la caja destino. Si no, seteo la cuenta bancaria destino.
            MBankAccount destino = null;
            if (isTransferencia() || get_ValueAsBoolean("ExtraccionBancaria"))
                destino = (MBankAccount) getC_BankAccountTo();
            else
                destino = new MBankAccount(p_ctx, get_ValueAsInt("CuentaDestino_ID"), get_TrxName());
            paymentBankTo.setPosted(true);
            paymentBankTo.setC_BankAccount_ID(destino.getC_BankAccount_ID());
            paymentBankTo.setDateAcct(new Timestamp(System.currentTimeMillis()));
            paymentBankTo.setDateTrx(new Timestamp(System.currentTimeMillis()));
            paymentBankTo.setDescription(getDescription());
            paymentBankTo.setC_BPartner_ID(MSysConfig.getIntValue("LAR_SdN_MovimientosDeCaja", 0, Env.getAD_Client_ID(getCtx())));
            paymentBankTo.setC_Currency_ID(getC_Currency_ID());
            paymentBankTo.setPayAmt(linea.getMonto());
            paymentBankTo.setOverUnderAmt(Env.ZERO);
            paymentBankTo.setLAR_C_DoctType_ID(true, destino.get_ValueAsBoolean("IsDrawer") ? destino.getAD_Org_ID() : Env.getAD_Org_ID(p_ctx));
            paymentBankTo.setIsReceipt(true);
            paymentBankTo.saveEx();
            if (paymentBankTo.processIt(MPayment.DOCACTION_Complete)) {
                paymentBankTo.saveEx();
                linea.setCobro_ID(paymentBankTo.getC_Payment_ID());
                linea.saveEx();
            } else {
                m_processMsg = "No se ha podido efectuar la transferencia de efectivo. Error al crear el cobro en la cuenta Destino.";
                return STATUS_Drafted;
            }
        }
    }
    setProcessed(true);
    setDocAction(DOCACTION_Void);
    if (!save())
        return STATUS_Drafted;
    return STATUS_Completed;
}
Also used : MPayment(org.compiere.model.MPayment) Timestamp(java.sql.Timestamp) MBankAccount(org.compiere.model.MBankAccount)

Example 12 with MBankAccount

use of org.compiere.model.MBankAccount in project lar_361 by comitsrl.

the class DrawerTransfer method doIt.

// prepare
/**
 * Perform process.
 *
 * @return Message (translated text)
 * @throws Exception
 *             if not successful
 */
protected String doIt() throws Exception {
    String msg = String.format("From Bank=%d - To Bank=%d - DocumentNo=%s - Description=%s - Statement Date=%s - Date Account=%s", p_From_C_BankAccount_ID, p_To_C_BankAccount_ID, p_DocumentNo, p_Description, p_StatementDate, p_DateAcct);
    log.info(msg);
    if (p_From_C_BankAccount_ID == 0)
        throw new IllegalArgumentException("Número de Caja Requerido");
    // if (p_DocumentNo == null || p_DocumentNo.length() == 0)
    // throw new IllegalArgumentException("Document No required");
    // if (p_To_C_BankAccount_ID == p_From_C_BankAccount_ID)
    // throw new AdempiereUserError("Accounts From and To must be different");
    p_C_BPartner_ID = new MUser(getCtx(), Env.getAD_User_ID(getCtx()), get_TrxName()).getC_BPartner_ID();
    if (p_C_BPartner_ID == 0)
        throw new AdempiereUserError("Socio de Negocio requerido");
    // Login Date
    if (p_StatementDate == null)
        p_StatementDate = Env.getContextAsDate(getCtx(), "#Date");
    if (p_StatementDate == null)
        p_StatementDate = new Timestamp(System.currentTimeMillis());
    if (p_DateAcct == null)
        p_DateAcct = p_StatementDate;
    if (p_BankStatement_ID == 0)
        throw new AdempiereUserError("Por favor, seleccione un cierre de caja a transferir.");
    // Si la cuenta, es una caja principal, se transfieren los valores segun
    // la forma de pago.
    final MBankAccount cuenta = new MBankAccount(getCtx(), p_From_C_BankAccount_ID, get_TrxName());
    return "@Se transfirieron@ " + m_transferred + " líneas.";
}
Also used : AdempiereUserError(org.compiere.util.AdempiereUserError) MUser(org.compiere.model.MUser) Timestamp(java.sql.Timestamp) MBankAccount(org.compiere.model.MBankAccount)

Aggregations

MBankAccount (org.compiere.model.MBankAccount)12 MPayment (org.compiere.model.MPayment)7 BigDecimal (java.math.BigDecimal)5 MBankStatement (org.compiere.model.MBankStatement)5 Timestamp (java.sql.Timestamp)4 MBankStatementLine (org.compiere.model.MBankStatementLine)4 PreparedStatement (java.sql.PreparedStatement)2 ResultSet (java.sql.ResultSet)2 AdempiereUserError (org.compiere.util.AdempiereUserError)2 Insets (java.awt.Insets)1 ArrayList (java.util.ArrayList)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 AdempiereException (org.adempiere.exceptions.AdempiereException)1 VLookup (org.compiere.grid.ed.VLookup)1 VString (org.compiere.grid.ed.VString)1 MCashBook (org.compiere.model.MCashBook)1 MLookup (org.compiere.model.MLookup)1 MUser (org.compiere.model.MUser)1 X_I_BankStatement (org.compiere.model.X_I_BankStatement)1