use of org.compiere.model.MPOS in project adempiere-gRPC-Server by adempiere.
the class PointOfSalesServiceImplementation method reverseSalesTransaction.
/**
* Process a Shipment
* @param request
* @return
* @return Shipment.Builder
*/
private Order.Builder reverseSalesTransaction(ReverseSalesRequest request) {
if (Util.isEmpty(request.getOrderUuid())) {
throw new AdempiereException("@C_Order_ID@ @NotFound@");
}
MPOS pointOfSales = getPOSFromUuid(request.getPosUuid(), true);
if (pointOfSales.get_ValueAsInt("C_DocTypeRMA_ID") <= 0) {
throw new AdempiereException("@C_DocTypeRMA_ID@ @NotFound@");
}
AtomicReference<MOrder> returnOrderReference = new AtomicReference<MOrder>();
Trx.run(transactionName -> {
int orderId = RecordUtil.getIdFromUuid(I_C_Order.Table_Name, request.getOrderUuid(), transactionName);
MOrder order = new MOrder(Env.getCtx(), orderId, transactionName);
ProcessInfo infoProcess = ProcessBuilder.create(Env.getCtx()).process(ReverseTheSalesTransaction.getProcessId()).withoutTransactionClose().withRecordId(MOrder.Table_ID, orderId).withParameter("C_Order_ID", orderId).withParameter("Bill_BPartner_ID", order.getC_BPartner_ID()).withParameter("IsCancelled", true).withParameter("C_DocTypeRMA_ID", pointOfSales.get_ValueAsInt("C_DocTypeRMA_ID")).execute(transactionName);
MOrder returnOrder = new MOrder(Env.getCtx(), infoProcess.getRecord_ID(), transactionName);
if (!Util.isEmpty(request.getDescription())) {
returnOrder.setDescription(request.getDescription());
returnOrder.saveEx();
}
returnOrderReference.set(returnOrder);
});
// Default
return ConvertUtil.convertOrder(returnOrderReference.get());
}
use of org.compiere.model.MPOS in project adempiere-gRPC-Server by adempiere.
the class PointOfSalesServiceImplementation method getProductPrice.
/**
* Get Product Price Method
* @param request
* @return
*/
private ProductPrice.Builder getProductPrice(GetProductPriceRequest request) {
// Get Product
MProduct product = null;
String key = Env.getAD_Client_ID(Env.getCtx()) + "|";
if (!Util.isEmpty(request.getSearchValue())) {
key = key + "SearchValue|" + request.getSearchValue();
product = productCache.get(key);
if (product == null) {
product = new Query(Env.getCtx(), I_M_Product.Table_Name, "(" + "UPPER(Value) = UPPER(?)" + "OR UPPER(Name) = UPPER(?)" + "OR UPPER(UPC) = UPPER(?)" + "OR UPPER(SKU) = UPPER(?)" + ")", null).setParameters(request.getSearchValue(), request.getSearchValue(), request.getSearchValue(), request.getSearchValue()).setClient_ID().setOnlyActiveRecords(true).first();
}
} else if (!Util.isEmpty(request.getUpc())) {
key = key + "Upc|" + request.getUpc();
product = productCache.get(key);
if (product == null) {
Optional<MProduct> optionalProduct = MProduct.getByUPC(Env.getCtx(), request.getUpc(), null).stream().findAny();
if (optionalProduct.isPresent()) {
product = optionalProduct.get();
}
}
} else if (!Util.isEmpty(request.getValue())) {
key = key + "Value|" + request.getValue();
product = productCache.get(key);
if (product == null) {
product = new Query(Env.getCtx(), I_M_Product.Table_Name, "UPPER(Value) = UPPER(?)", null).setParameters(request.getValue()).setClient_ID().setOnlyActiveRecords(true).first();
}
} else if (!Util.isEmpty(request.getName())) {
key = key + "Name|" + request.getName();
product = productCache.get(key);
if (product == null) {
product = new Query(Env.getCtx(), I_M_Product.Table_Name, "UPPER(Name) LIKE UPPER(?)", null).setParameters(request.getName()).setClient_ID().setOnlyActiveRecords(true).first();
}
}
// Validate product
if (product == null) {
throw new AdempiereException("@M_Product_ID@ @NotFound@");
} else {
productCache.put(key, product);
}
MPOS pos = getPOSFromUuid(request.getPosUuid(), true);
// Validate Price List
int priceListId = pos.getM_PriceList_ID();
if (!Util.isEmpty(request.getPriceListUuid())) {
priceListId = RecordUtil.getIdFromUuid(I_M_PriceList.Table_Name, request.getPriceListUuid(), null);
}
MPriceList priceList = MPriceList.get(Env.getCtx(), priceListId, null);
AtomicInteger warehouseId = new AtomicInteger(pos.getM_Warehouse_ID());
if (!Util.isEmpty(request.getWarehouseUuid())) {
warehouseId.set(RecordUtil.getIdFromUuid(I_M_Warehouse.Table_Name, request.getWarehouseUuid(), null));
}
// Get Valid From
AtomicReference<Timestamp> validFrom = new AtomicReference<>();
if (!Util.isEmpty(request.getValidFrom())) {
validFrom.set(ValueUtil.convertStringToDate(request.getValidFrom()));
} else {
validFrom.set(TimeUtil.getDay(System.currentTimeMillis()));
}
int businessPartnerId = RecordUtil.getIdFromUuid(I_C_BPartner.Table_Name, request.getBusinessPartnerUuid(), null);
int displayCurrencyId = pos.get_ValueAsInt("DisplayCurrency_ID");
int conversionTypeId = pos.get_ValueAsInt("C_ConversionType_ID");
return convertProductPrice(product, businessPartnerId, priceList, warehouseId.get(), validFrom.get(), displayCurrencyId, conversionTypeId, Env.ONE);
}
use of org.compiere.model.MPOS in project lar_361 by comitsrl.
the class ProcesadorWSFE method getPuntoVenta.
// agregarDocAsociado
/**
* Obtener nro de Punto de Venta.
* @author fchiappano
* @param invoice
* @return nroPdv.
*/
private int getPuntoVenta(final MInvoice invoice) {
int c_Pos_ID = invoice.get_ValueAsInt("C_Pos_ID");
if (c_Pos_ID <= 0) {
msgError = "Es obligatorio, el ingreso de un punto de venta valido, para el documento.";
return 0;
}
MPOS pdv = new MPOS(ctx, c_Pos_ID, invoice.get_TrxName());
int nroPdv = pdv.get_ValueAsInt("PosNumber");
if (nroPdv <= 0) {
msgError = "Número de PDV invalido.";
return 0;
}
return nroPdv;
}
use of org.compiere.model.MPOS in project lar_361 by comitsrl.
the class WsfeV1 method createInputFile.
/**
* @author: Horacio Alvarez
* @descripcion: Crea el archivo de entrada para el WSFE.PY.
* Setea los valores necesarios con el objeto MInvoice.
*/
@Override
protected void createInputFile() {
try {
StringBuffer line = new StringBuffer();
// *****NRO. COMPROBANTE
if (this.getInvoice().getNumeroComprobante() == 0) {
this.setMessageError(Msg.translate(this.getM_ctx(), "CaeNoNumeroComprobante"));
return;
}
line.append(this.getInvoice().getNumeroComprobante() + "\n");
// *****PUNTO DE VENTA
final MPOS pos = new MPOS(getM_ctx(), this.getInvoice().get_ValueAsInt("C_Pos_ID"), getTrxName());
if (pos.get_ValueAsInt("PosNumber") == 0) {
this.setMessageError(Msg.translate(this.getM_ctx(), "CaeNoPuntoDeVenta"));
return;
}
line.append(pos.get_ValueAsInt("PosNumber") + "\n");
// *****TIPO DE COMPROBANTE
MDocType docType = new MDocType(Env.getCtx(), this.getInvoice().getC_DocTypeTarget_ID(), getTrxName());
line.append(docType.getdocsubtypecae() + "\n");
// *****TIPO DOC: 80 CUIT / 96 DNI
MBPartner partner = new MBPartner(this.getM_ctx(), this.getInvoice().getC_BPartner_ID(), getTrxName());
// @fchiappano Recuperar el tipo de identificación, desde el Socio del Negocio.
final X_LCO_TaxIdType tipoIdentificacion = new X_LCO_TaxIdType(getM_ctx(), partner.get_ValueAsInt("LCO_TaxIdType_ID"), getTrxName());
line.append(tipoIdentificacion.getLCO_TaxCodeDian() + "\n");
if (partner.getTaxID() == null || partner.getTaxID().equals("")) {
this.setMessageError(Msg.translate(this.getM_ctx(), "CaeNoCUIT"));
return;
}
line.append(partner.getTaxID().replaceAll("-", "") + "\n");
// *****IMPORTE TOTAL
// line.append(this.getInvoice().getGrandTotal().toString().replace(".", "")+"\n");
line.append(this.getInvoice().getGrandTotal().setScale(2, BigDecimal.ROUND_HALF_UP) + "\n");
// *****IMPORTE NETO
// line.append(this.getInvoice().getTotalLines().toString().replace(".", "")+"\n");
line.append(this.getInvoice().getTotalLines().setScale(2, BigDecimal.ROUND_HALF_UP) + "\n");
// *****FECHA
if (this.getInvoice().getDateAcct() == null) {
this.setMessageError(Msg.translate(this.getM_ctx(), "CaeNoDateAcct"));
return;
}
line.append(formatTime(this.getInvoice().getDateAcct(), "yyyyMMdd") + "\n");
// *****PRESTA SERVICIOS 0-->NO 1-->SI
line.append(MSysConfig.getValue("LAR_PrestaServicios_FE", Env.getAD_Client_ID(Env.getCtx())) + "\n");
// *****MONEDA
MCurrency currency = new MCurrency(this.getM_ctx(), this.getInvoice().getC_Currency_ID(), getTrxName());
line.append(currency.get_ValueAsString("WSFECode") + "\n");
// *****CONVERSION
// Se debe convertir a la moneda del comprobante desde la moneda de la compañía
BigDecimal cotizacion;
if (currency.getC_Currency_ID() != LAR_Utils.getMonedaPredeterminada(getM_ctx(), getInvoice().getAD_Client_ID(), getTrxName()))
cotizacion = (BigDecimal) getInvoice().get_Value("TasaDeCambio");
else
cotizacion = MCurrency.currencyConvert(Env.ONE, Env.getContextAsInt(this.getM_ctx(), "$C_Currency_ID"), this.getInvoice().getC_Currency_ID(), this.getInvoice().getDateInvoiced(), 0, this.getM_ctx());
line.append(cotizacion + "\n");
// *****IMPUESTO
BigDecimal total_Impuesto = BigDecimal.ZERO;
MInvoiceTax[] taxes = this.getInvoice().getTaxes(false);
MTax tax = null;
int size = taxes.length;
boolean firstLineAppended = false;
for (int i = 0; i < size; i++) {
tax = MTax.get(this.getM_ctx(), taxes[i].getC_Tax_ID());
if (!tax.get_ValueAsBoolean("IsPerception")) {
total_Impuesto = total_Impuesto.add(taxes[i].getTaxAmt().setScale(2, BigDecimal.ROUND_HALF_UP));
taxes[i].getTaxAmt();
taxes[i].getTaxBaseAmt();
tax.get_ValueAsString("WSFECode");
if (firstLineAppended) {
line.append(";");
}
line.append(tax.get_ValueAsString("WSFECode") + ":" + (getTaxBaseAmt(taxes[i].getTaxBaseAmt(), this.getInvoice().getGrandTotal(), getTaxesAmt(this.getInvoice()))).setScale(2, BigDecimal.ROUND_HALF_UP) + ":" + taxes[i].getTaxAmt().setScale(2, BigDecimal.ROUND_HALF_UP));
firstLineAppended = true;
}
}
line.append("\n");
// *****MONTO TOTAL DE IMPUESTOS
// line.append(total_Impuesto + "\n");
// *****IMPUESTOS PERCEPCIONES
BigDecimal total_Perception = BigDecimal.ZERO;
MInvoiceTax[] taxesPerc = this.getInvoice().getTaxes(true);
MTax taxPerc = null;
int sizePerc = taxesPerc.length;
boolean firstLineAppended2 = false;
for (int i = 0; i < sizePerc; i++) {
taxPerc = MTax.get(this.getM_ctx(), taxesPerc[i].getC_Tax_ID());
if (taxPerc.get_ValueAsBoolean("IsPerception")) {
total_Perception = total_Perception.add(taxesPerc[i].getTaxAmt().setScale(2, BigDecimal.ROUND_HALF_UP));
taxesPerc[i].getTaxAmt();
taxesPerc[i].getTaxBaseAmt();
taxPerc.get_ValueAsInt("WSFECode");
if (firstLineAppended2) {
line.append(";");
}
BigDecimal alic = (taxPerc.getRate().setScale(2, BigDecimal.ROUND_HALF_UP)).negate();
line.append(taxPerc.get_ValueAsInt("WSFECode") + ":" + (getTaxBaseAmt(taxesPerc[i].getTaxBaseAmt(), this.getInvoice().getGrandTotal(), getTaxesAmt(this.getInvoice()))).setScale(2, BigDecimal.ROUND_HALF_UP) + ":" + taxesPerc[i].getTaxAmt().setScale(2, BigDecimal.ROUND_HALF_UP) + ":" + alic);
firstLineAppended2 = true;
}
}
if (total_Perception.equals(Env.ZERO))
line.append("0");
line.append("\n");
// *****MONTO TOTAL DE PERCEPCIONES
line.append(total_Perception + "\n");
// *****C_INVOICE_ID para seguimiento
line.append(this.getInvoice().getC_Invoice_ID() + "\n");
// @fchiappano Agregar Fecha de Vencimiento de Pago.
Timestamp fechaPago = (Timestamp) this.getInvoice().get_Value("FechaPago");
if (fechaPago != null)
line.append(formatTime(fechaPago, "yyyyMMdd") + "\n");
else
line.append(formatTime(new Timestamp(System.currentTimeMillis()), "yyyyMMdd") + "\n");
// @fchiappano Agregar datos opcionales (CBU y Alias).
int c_BankAccount_ID = MOrgInfo.get(this.getM_ctx(), this.getInvoice().getAD_Org_ID()).get_ValueAsInt("C_BankAccount_ID");
MBankAccount cuentaBancaria = new MBankAccount(getM_ctx(), c_BankAccount_ID, getTrxName());
// ****** CBU
line.append(cuentaBancaria.get_Value("CBU") + "\n");
// ****** ALIAS
line.append(cuentaBancaria.get_Value("Alias") + "\n");
// @fchiappano se agregan datos para NC y ND (FCE).
if (getInvoice().get_ValueAsInt("Source_Invoice_ID") > 0) {
MInvoice facturaOrigen = new MInvoice(getM_ctx(), getInvoice().get_ValueAsInt("Source_Invoice_ID"), getTrxName());
// ****** Tipo de Doc. Factura Origen.
MDocType tipoDoc = (MDocType) facturaOrigen.getC_DocTypeTarget();
line.append(tipoDoc.getdocsubtypecae() + "\n");
// ****** Punto de Venta Factura Origen.
MPOS pdv = new MPOS(getM_ctx(), facturaOrigen.get_ValueAsInt("C_Pos_ID"), getTrxName());
line.append(pdv.get_ValueAsInt("PosNumber") + "\n");
// ****** Nro. Doc. Factura Origen.
line.append(facturaOrigen.getNumeroComprobante() + "\n");
// ****** Fecha Facturación Factura Origen
Date fecha = new Date(facturaOrigen.getDateInvoiced().getTime());
line.append(fecha.toString().replace("-", "") + "\n");
// ****** Codigo de Cancelación
boolean cancelado = getInvoice().get_ValueAsBoolean("Cancelacion");
if (cancelado)
line.append("S" + "\n");
else
line.append("N" + "\n");
}
File textFile = new File(getPath() + "entrada.txt");
FileWriter textOut;
textOut = new FileWriter(textFile);
textOut.write(line.toString());
textOut.close();
} catch (Exception ex) {
this.setMessageError(Msg.translate(this.getM_ctx(), "caeErrorCreateInputFile"));
log.log(Level.SEVERE, this.getMessageError(), ex);
}
}
use of org.compiere.model.MPOS in project lar_361 by comitsrl.
the class PosBasePanel method getPOSs.
// setMPOS
/**
* Get POSs for specific Sales Rep and Org
* @param SalesRep_ID
* @return array of POS
*/
private MPOS[] getPOSs(int SalesRep_ID) {
String whereClause = "AD_Org_ID=?";
Object[] params = new Object[] { Env.getAD_Org_ID(m_ctx) };
List<MPOS> list = new Query(m_ctx, MPOS.Table_Name, whereClause, null).setParameters(params).setOnlyActiveRecords(true).list();
return list.toArray(new MPOS[list.size()]);
}
Aggregations