use of org.compiere.model.MBankStatement in project lar_361 by comitsrl.
the class CreateFromStatement method save.
/**
* Save Statement - Insert Data
* @return true if saved
*/
public boolean save(IMiniTable miniTable, String trxName) {
// fixed values
int C_BankStatement_ID = ((Integer) getGridTab().getValue("C_BankStatement_ID")).intValue();
MBankStatement bs = new MBankStatement(Env.getCtx(), C_BankStatement_ID, trxName);
log.config(bs.toString());
// Lines
for (int i = 0; i < miniTable.getRowCount(); i++) {
if (((Boolean) miniTable.getValueAt(i, 0)).booleanValue()) {
// 1-DateTrx
Timestamp trxDate = (Timestamp) miniTable.getValueAt(i, 1);
// 2-C_Payment_ID
KeyNamePair pp = (KeyNamePair) miniTable.getValueAt(i, 2);
int C_Payment_ID = pp.getKey();
// 3-Currency
pp = (KeyNamePair) miniTable.getValueAt(i, 3);
int C_Currency_ID = pp.getKey();
// 5- Conv Amt
BigDecimal TrxAmt = (BigDecimal) miniTable.getValueAt(i, 5);
log.fine("Line Date=" + trxDate + ", Payment=" + C_Payment_ID + ", Currency=" + C_Currency_ID + ", Amt=" + TrxAmt);
//
MBankStatementLine bsl = new MBankStatementLine(bs);
bsl.setStatementLineDate(trxDate);
bsl.setPayment(new MPayment(Env.getCtx(), C_Payment_ID, trxName));
bsl.setTrxAmt(TrxAmt);
bsl.setStmtAmt(TrxAmt);
bsl.setC_Currency_ID(bankAccount.getC_Currency_ID());
if (!bsl.save())
log.log(Level.SEVERE, "Line not created #" + i);
}
// if selected
}
// for all rows
return true;
}
use of org.compiere.model.MBankStatement in project lar_361 by comitsrl.
the class TransaccionCuentaBancaria method transferirValoresPorFormaPago.
// transferirMovimientosEntreCuentas
/**
* Transferir Valores a las Cuentas Bancarias correspondientes, segĂșn la forma de pago utilizada.
* @param C_BankStatement_ID
* @param ctx
* @param trxName
* @return
*/
public static KeyNamePair[] transferirValoresPorFormaPago(final int p_BankStatement_ID, final String p_Description, final int p_C_BPartner_ID, final Timestamp p_StatementDate, final Timestamp p_DateAcct, final Properties ctx, final String trxName) {
List<KeyNamePair> m_informe = new ArrayList<KeyNamePair>();
int m_efectivoTransferido = 0;
int m_chequeTransferido = 0;
int m_debitoTransferido = 0;
int m_creditoTransferido = 0;
int m_depositoTransferido = 0;
int m_chequeEmitido = 0;
int tipoPago = 0;
// Chequeo si hay tarjetas de Debito y si las mismas tienen una cuenta bancaria configurada.
tipoPago = comprobarCuentasPorFormaPago(p_BankStatement_ID, "LAR_Tarjeta_Debito_ID");
if (tipoPago > 0) {
final MLARTarjetaCredito debito = new MLARTarjetaCredito(ctx, tipoPago, trxName);
setError(m_informe, "La tarjeta de debito " + debito.getDescription() + ", no posee una cuenta bancaria configurada.");
return m_informe.toArray(new KeyNamePair[m_informe.size()]);
}
// Chequeo si hay tarjetas de Credito y si las mismas tienen una cuenta bancaria configurada.
tipoPago = comprobarCuentasPorFormaPago(p_BankStatement_ID, "LAR_Tarjeta_Credito_ID");
if (tipoPago > 0) {
final MLARTarjetaCredito credito = new MLARTarjetaCredito(ctx, tipoPago, trxName);
setError(m_informe, "La tarjeta de credito " + credito.getDescription() + ", no posee una cuenta bancaria configurada.");
return m_informe.toArray(new KeyNamePair[m_informe.size()]);
}
// Chequeo si hay Tipos de Deposito y si los mismos tienen una cuenta bancaria configurada.
tipoPago = comprobarCuentasPorFormaPago(p_BankStatement_ID, "LAR_Deposito_Directo_ID");
if (tipoPago > 0) {
final MLARTarjetaCredito deposito = new MLARTarjetaCredito(ctx, tipoPago, trxName);
setError(m_informe, "El tipo de deposito directo " + deposito.getName() + ", no posee una cuenta bancaria configurada.");
return m_informe.toArray(new KeyNamePair[m_informe.size()]);
}
final MBankStatement statement = new MBankStatement(ctx, p_BankStatement_ID, trxName);
// Valido que si es una caja de tipo VENTAS, tenga si o si una caja PRINCIPAL asignada.
if (!statement.getBankAccount().get_ValueAsBoolean("EsCajaPrincipal") && statement.getBankAccount().get_ValueAsInt("CajaPrincipal_ID") == 0) {
setError(m_informe, "La caja de Ventas seleccionada, no posee una caja del tipo Principal/General asignada.");
return m_informe.toArray(new KeyNamePair[m_informe.size()]);
}
BigDecimal totalAmt = Env.ZERO;
BigDecimal cashAmt = BigDecimal.ZERO;
int p_C_Currency_ID = 0;
// Creo un nuevo Statement, para conciliar los pagos que debitan los valores de la caja.
final MBankStatement newStmt = new MBankStatement(ctx, 0, trxName);
newStmt.setC_BankAccount_ID(statement.getC_BankAccount_ID());
newStmt.setName("Compensacion Transferencia");
newStmt.setDocStatus(MBankStatement.DOCSTATUS_Drafted);
// marco el nuevo Statement como cierre de caja tambien.
if (statement.get_ValueAsBoolean("EsCierreCaja")) {
newStmt.set_ValueOfColumn("EsCierreCaja", true);
// Seteo el Saldo inicial en 0, para que no genere errores en
// futuros calculos.
newStmt.set_ValueOfColumn("SaldoInicial", Env.ZERO);
newStmt.set_ValueOfColumn("ScrutinizedCheckAmt", Env.ZERO);
newStmt.set_ValueOfColumn("ScrutinizedCashAmt", Env.ZERO);
newStmt.set_ValueOfColumn("ScrutinizedCreditCardAmt", Env.ZERO);
newStmt.set_ValueOfColumn("ScrutinizedDirectDebitAmt", Env.ZERO);
}
// @fchiappano Marco el nuevo Statement como transferido.
newStmt.set_ValueOfColumn("Transferido", true);
newStmt.set_ValueOfColumn("LAR_CierreCaja_Origen_ID", statement.getC_BankStatement_ID());
newStmt.setStatementDate(p_StatementDate);
newStmt.saveEx();
// Reccorro todas las lineas del statement para transferir a una nueva cuenta segun corresponda.
for (MBankStatementLine linea : statement.getLines(true)) {
// Si la linea ya fue transferida, paso a la siguiente.
if (linea.get_ValueAsBoolean("IsTransferred"))
continue;
// De la linea obtengo el pago
final MPayment pago = (MPayment) linea.getC_Payment();
// completo o cerrado (por anulacion), se continua con la siguiente linea.
if (!pago.getDocStatus().equals(MPayment.DOCSTATUS_Completed) && !pago.getDocStatus().equals(MPayment.DOCSTATUS_Closed))
continue;
MPayment paymentBankTo = null;
// Tomo y guardo, la moneda utilizada en el pago para utilizarla posteriormente.
p_C_Currency_ID = pago.getC_Currency_ID();
final MBankAccount cuentaBancaria = new MBankAccount(ctx, statement.getC_BankAccount_ID(), trxName);
if (cuentaBancaria.get_ValueAsInt("CajaPrincipal_ID") > 0) {
if (pago.getTenderType().equals(MPayment.TENDERTYPE_Cash) && MSysConfig.getValue("LAR_TransfiereEfectivo_En_CierreDeCajas", Env.getAD_Client_ID(ctx)).equals("Y")) {
cashAmt = pago.get_ValueAsBoolean("IsReceipt") ? cashAmt.add(pago.getPayAmt()) : cashAmt.add(pago.getPayAmt().negate());
linea.set_ValueOfColumn("IsTransferred", true);
linea.saveEx();
m_efectivoTransferido++;
continue;
} else if (pago.getTenderType().equals(MPayment.TENDERTYPE_Check) | pago.getTenderType().equals("Z") && pago.get_ValueAsBoolean("IsReceipt") && pago.get_ValueAsBoolean("IsOnDrawer")) {
paymentBankTo = crearPago(p_DateAcct, p_StatementDate, cuentaBancaria.get_ValueAsInt("CajaPrincipal_ID"), pago, p_C_BPartner_ID, p_Description, ctx, trxName);
// Desmarco el pago como en cartera.
pago.set_ValueOfColumn("IsOnDrawer", false);
pago.saveEx();
// Copio los datos propios del cheque en el cobro destino.
paymentBankTo.setTenderType(pago.getTenderType());
paymentBankTo.setRoutingNo(pago.getRoutingNo());
paymentBankTo.setCheckNo(pago.getCheckNo());
paymentBankTo.setAccountNo(pago.getAccountNo());
paymentBankTo.setA_Name(pago.getA_Name());
final int lar_Plan_Pago_ID = pago.get_ValueAsInt("LAR_Plan_Pago_ID");
paymentBankTo.set_ValueOfColumn("LAR_Plan_Pago_ID", lar_Plan_Pago_ID > 0 ? lar_Plan_Pago_ID : null);
// Creo el pago que debita el cheque.
debitarValores(statement, p_C_BPartner_ID, ctx, trxName, pago, newStmt);
m_chequeTransferido++;
}
}
if (pago.getTenderType().equals(MPayment.TENDERTYPE_CreditCard)) {
totalAmt = totalAmt.add(pago.getPayAmt());
paymentBankTo = crearPago(p_DateAcct, p_StatementDate, getCuentaPorFormaPago("LAR_Tarjeta_Credito_ID", pago.get_ValueAsInt("LAR_Tarjeta_Credito_ID")), pago, p_C_BPartner_ID, p_Description, ctx, trxName);
paymentBankTo.set_ValueOfColumn("LAR_Tarjeta_Credito_ID", pago.get_ValueAsInt("LAR_Tarjeta_Credito_ID"));
paymentBankTo.setA_Name(pago.getA_Name());
paymentBankTo.setCreditCardNumber(pago.getCreditCardNumber());
paymentBankTo.setCreditCardExpMM(pago.getCreditCardExpMM());
paymentBankTo.setCreditCardExpYY(pago.getCreditCardExpYY());
final int lar_Plan_Pago_ID = pago.get_ValueAsInt("LAR_Plan_Pago_ID");
paymentBankTo.set_ValueOfColumn("LAR_Plan_Pago_ID", lar_Plan_Pago_ID > 0 ? lar_Plan_Pago_ID : null);
// Creo el pago que debita el cupon de tarjeta de credito.
debitarValores(statement, p_C_BPartner_ID, ctx, trxName, pago, newStmt);
m_creditoTransferido++;
} else if (pago.getTenderType().equals(MPayment.TENDERTYPE_DirectDebit)) {
totalAmt = totalAmt.add(pago.getPayAmt());
paymentBankTo = crearPago(p_DateAcct, p_StatementDate, getCuentaPorFormaPago("LAR_Tarjeta_Debito_ID", pago.get_ValueAsInt("LAR_Tarjeta_Debito_ID")), pago, p_C_BPartner_ID, p_Description, ctx, trxName);
paymentBankTo.set_ValueOfColumn("LAR_Tarjeta_Debito_ID", pago.get_ValueAsInt("LAR_Tarjeta_Debito_ID"));
final int lar_Plan_Pago_ID = pago.get_ValueAsInt("LAR_Plan_Pago_ID");
paymentBankTo.set_ValueOfColumn("LAR_Plan_Pago_ID", lar_Plan_Pago_ID > 0 ? lar_Plan_Pago_ID : null);
// Creo el pago que debita el cupon de tarjeta de debito.
debitarValores(statement, p_C_BPartner_ID, ctx, trxName, pago, newStmt);
m_debitoTransferido++;
} else if (pago.getTenderType().equals(MPayment.TENDERTYPE_DirectDeposit)) {
totalAmt = totalAmt.add(pago.getPayAmt());
paymentBankTo = crearPago(p_DateAcct, p_StatementDate, getCuentaPorFormaPago("LAR_Deposito_Directo_ID", pago.get_ValueAsInt("LAR_Deposito_Directo_ID")), pago, p_C_BPartner_ID, p_Description, ctx, trxName);
paymentBankTo.set_ValueOfColumn("LAR_Deposito_Directo_ID", pago.get_ValueAsInt("LAR_Deposito_Directo_ID"));
// Creo el pago que debita el deposito directo.
debitarValores(statement, p_C_BPartner_ID, ctx, trxName, pago, newStmt);
m_depositoTransferido++;
} else if (pago.getTenderType().equals(MPayment.TENDERTYPE_Check) && !pago.isReceipt() && pago.get_ValueAsInt("LAR_Cheque_Emitido_ID") > 0) {
totalAmt = totalAmt.add(pago.getPayAmt());
paymentBankTo = crearPago(p_DateAcct, p_StatementDate, getCuentaPorFormaPago("LAR_Cheque_Emitido_ID", pago.get_ValueAsInt("LAR_Cheque_Emitido_ID")), pago, p_C_BPartner_ID, p_Description, ctx, trxName);
paymentBankTo.set_ValueOfColumn("LAR_Cheque_Emitido_ID", pago.get_ValueAsInt("LAR_Cheque_Emitido_ID"));
// Creo el pago en negativo, que debita el cheque emitido.
debitarValores(statement, p_C_BPartner_ID, ctx, trxName, pago, newStmt);
m_chequeEmitido++;
}
// Guardo y completo el cobro en la caja destino.
if (paymentBankTo != null) {
paymentBankTo.saveEx();
paymentBankTo.processIt(MPayment.DOCACTION_Complete);
paymentBankTo.saveEx();
}
}
if (cashAmt.compareTo(BigDecimal.ZERO) > 0) {
final MPayment cashBankTo = new MPayment(ctx, 0, trxName);
final MBankAccount cuentaBancaria = new MBankAccount(ctx, statement.getC_BankAccount_ID(), trxName);
cashBankTo.setC_BankAccount_ID(cuentaBancaria.get_ValueAsInt("CajaPrincipal_ID"));
cashBankTo.setDateAcct(p_DateAcct);
cashBankTo.setDateTrx(p_StatementDate);
cashBankTo.setTenderType(MPayment.TENDERTYPE_Cash);
cashBankTo.setDescription(p_Description);
cashBankTo.setC_BPartner_ID(p_C_BPartner_ID);
cashBankTo.setC_Currency_ID(p_C_Currency_ID);
cashBankTo.setPayAmt(cashAmt);
cashBankTo.setPosted(true);
cashBankTo.setOverUnderAmt(Env.ZERO);
cashBankTo.setLAR_C_DoctType_ID(true, cuentaBancaria.getAD_Org_ID());
cashBankTo.setIsReceipt(true);
cashBankTo.saveEx();
cashBankTo.processIt(MPayment.DOCACTION_Complete);
cashBankTo.saveEx();
// Creo el pago, que debita todo el efectivo transferido.
debitarValores(statement, p_C_BPartner_ID, ctx, trxName, cashBankTo, newStmt);
// Sumo el cashAmt al totalAmt para debitar el total de los valores posteriormente.
// totalAmt = totalAmt.add(cashAmt);
}
if (m_chequeTransferido > 0 || m_creditoTransferido > 0 || m_debitoTransferido > 0 || m_depositoTransferido > 0 || m_efectivoTransferido > 0) {
statement.set_ValueOfColumn("Transferido", true);
statement.saveEx();
// process new statement
newStmt.processIt(MBankStatement.DOCACTION_Complete);
newStmt.saveEx();
}
m_informe.add(new KeyNamePair(m_chequeTransferido + m_creditoTransferido + m_debitoTransferido + m_depositoTransferido + m_efectivoTransferido, "Total"));
m_informe.add(new KeyNamePair(m_efectivoTransferido, "Efectivo"));
m_informe.add(new KeyNamePair(m_chequeTransferido, "Cheques"));
m_informe.add(new KeyNamePair(m_creditoTransferido, "Tarjetas de Credito"));
m_informe.add(new KeyNamePair(m_debitoTransferido, "Tarjetas de Debito"));
m_informe.add(new KeyNamePair(m_depositoTransferido, "Depositos Directos"));
m_informe.add(new KeyNamePair(m_chequeEmitido, "Cheques Emitidos"));
return m_informe.toArray(new KeyNamePair[m_informe.size()]);
}
use of org.compiere.model.MBankStatement in project lar_361 by comitsrl.
the class TransaccionCuentaBancaria method transferirMovimientosEntreCuentas.
/**
* Transferir todos los valores contemplados dentro de un Statement bancario,
* de una cuenta origen a una cuenta destino.
*
* @param p_BankStatement_ID
* @param p_From_C_BankAccount_ID
* @param p_To_C_BankAccount_ID
* @param p_Description
* @param p_C_BPartner_ID
* @param p_C_Currency_ID
* @param p_StatementDate
* @param p_DateAcct
* @param ctx
* @param trxName
* @return Cantidad de lineas transferidas.
*/
public static int transferirMovimientosEntreCuentas(final int p_BankStatement_ID, final int p_From_C_BankAccount_ID, final String p_Description, final int p_C_BPartner_ID, final Timestamp p_StatementDate, final Timestamp p_DateAcct, final Properties ctx, final String trxName) {
// Contador de lineas tranferidas.
int m_transferred = 0;
final MBankStatement statement = new MBankStatement(ctx, p_BankStatement_ID, trxName);
final MBankAccount mBankTo = new MBankAccount(ctx, statement.getBankAccount().get_ValueAsInt("CajaPrincipal_ID"), trxName);
BigDecimal cashAmt = BigDecimal.ZERO;
BigDecimal totalAmt = BigDecimal.ZERO;
int p_C_Currency_ID = 0;
int cash_transferred = 0;
// Iterates over conciliated payments
for (final MBankStatementLine line : statement.getLines(true)) {
// siguiente.
if (line.get_ValueAsBoolean("IsTransferred"))
continue;
final MPayment paymentFrom = new MPayment(ctx, line.getC_Payment_ID(), trxName);
totalAmt = totalAmt.add(paymentFrom.getPayAmt());
// @fchiappano Tomo la moneda utilizada en el pago.
p_C_Currency_ID = paymentFrom.getC_Currency_ID();
// Accumulates cash amounts
if (paymentFrom.getTenderType().equals(MPayment.TENDERTYPE_Cash)) {
cashAmt = cashAmt.add(paymentFrom.getPayAmt());
line.set_ValueOfColumn("IsTransferred", true);
line.saveEx();
cash_transferred++;
continue;
}
// Transfer other payments
crearPago(p_DateAcct, p_StatementDate, mBankTo.getC_BankAccount_ID(), paymentFrom, p_C_BPartner_ID, p_Description, ctx, trxName);
// Mark bank statement line as transferred
line.set_ValueOfColumn("IsTransferred", true);
line.saveEx();
m_transferred++;
}
// Transfer an accumulated cash amount
if (cashAmt.compareTo(BigDecimal.ZERO) > 0) {
final MPayment cashBankTo = new MPayment(ctx, 0, trxName);
cashBankTo.setC_BankAccount_ID(mBankTo.getC_BankAccount_ID());
cashBankTo.setDateAcct(p_DateAcct);
cashBankTo.setDateTrx(p_StatementDate);
cashBankTo.setTenderType(MPayment.TENDERTYPE_Cash);
cashBankTo.setDescription(p_Description);
cashBankTo.setC_BPartner_ID(p_C_BPartner_ID);
cashBankTo.setC_Currency_ID(p_C_Currency_ID);
cashBankTo.setPayAmt(cashAmt);
cashBankTo.setOverUnderAmt(Env.ZERO);
cashBankTo.setLAR_C_DoctType_ID(true, mBankTo.getAD_Org_ID());
cashBankTo.saveEx();
cashBankTo.processIt(MPayment.DOCACTION_Complete);
cashBankTo.saveEx();
}
// debitarValores(statement, p_C_Currency_ID, p_C_BPartner_ID, totalAmt, ctx, trxName);
// @fchiappano Marco el Statement original como transferido.
statement.set_ValueOfColumn("Transferido", true);
statement.saveEx();
return m_transferred + cash_transferred;
}
use of org.compiere.model.MBankStatement in project adempiere by adempiere.
the class BankStatementPayment method createPayment.
// createPayment - Import
/**
* Create Payment for BankStatement
* @param bsl bank statement Line
* @return Message
* @throws Exception if not successful
*/
private String createPayment(MBankStatementLine bsl) throws Exception {
if (bsl == null || bsl.getC_Payment_ID() != 0)
return "--";
log.fine(bsl.toString());
if (bsl.getC_Invoice_ID() == 0 && bsl.getC_BPartner_ID() == 0)
throw new AdempiereUserError("@NotFound@ @C_Invoice_ID@ / @C_BPartner_ID@");
//
MBankStatement bs = new MBankStatement(getCtx(), bsl.getC_BankStatement_ID(), get_TrxName());
//
MPayment payment = createPayment(bsl.getC_Invoice_ID(), bsl.getC_BPartner_ID(), bsl.getC_Currency_ID(), bsl.getStmtAmt(), bsl.getTrxAmt(), bs.getC_BankAccount_ID(), bsl.getStatementLineDate(), bsl.getDateAcct(), bsl.getDescription(), bsl.getAD_Org_ID());
if (payment == null)
throw new AdempiereSystemError("Could not create Payment");
// update statement
bsl.setPayment(payment);
bsl.saveEx();
//
String retString = "@C_Payment_ID@ = " + payment.getDocumentNo();
if (payment.getOverUnderAmt().signum() != 0)
retString += " - @OverUnderAmt@=" + payment.getOverUnderAmt();
return retString;
}
use of org.compiere.model.MBankStatement in project adempiere by adempiere.
the class StatementCreateFrom method doIt.
@Override
protected String doIt() throws Exception {
// fixed values
if (getRecord_ID() <= 0)
throw new AdempiereException("@C_BankStatement_ID@ @NotFound@");
MBankStatement bankStatement = new MBankStatement(Env.getCtx(), getRecord_ID(), get_TrxName());
// Get Bank Account
MBankAccount bankAccount = bankStatement.getBankAccount();
// Created
AtomicInteger created = new AtomicInteger(0);
// Total Amount
AtomicReference<BigDecimal> totalAmt = new AtomicReference<>(BigDecimal.ZERO);
log.config(bankStatement.toString());
// Lines
getSelectionKeys().stream().forEach(key -> {
Timestamp dateTransaction = getSelectionAsTimestamp(key, "P_DateTrx");
int paymentId = getSelectionAsInt(key, "P_C_Payment_ID");
int currencyId = getSelectionAsInt(key, "P_C_Currency_ID");
BigDecimal transactionAmount = getSelectionAsBigDecimal(key, "P_ConvertedAmount");
log.fine("Line Date=" + dateTransaction + ", Payment=" + paymentId + ", Currency=" + currencyId + ", Amt=" + transactionAmount);
MBankStatementLine bankStatementLine = new MBankStatementLine(bankStatement);
bankStatementLine.setDateAcct(bankStatement.getStatementDate());
bankStatementLine.setStatementLineDate(bankStatement.getStatementDate());
bankStatementLine.setValutaDate(dateTransaction);
MPayment payment = new MPayment(Env.getCtx(), paymentId, get_TrxName());
bankStatementLine.setPayment(payment);
bankStatementLine.setTrxAmt(transactionAmount);
bankStatementLine.setStmtAmt(transactionAmount);
bankStatementLine.setC_Currency_ID(bankAccount.getC_Currency_ID());
bankStatementLine.saveEx();
created.updateAndGet(createNo -> createNo + 1);
totalAmt.updateAndGet(amt -> amt.add(payment.isReceipt() ? payment.getPayAmt() : payment.getPayAmt().negate()));
});
// Return Created
return "@Created@ = " + created.get() + " - @PayAmt@ = " + DisplayType.getNumberFormat(DisplayType.Amount).format(totalAmt.get());
}
Aggregations