use of org.adempiere.pos.AdempierePOSException in project adempiere by adempiere.
the class CPOS method configureBPartner.
/**
* Set BPartner, update price list and locations
* Configuration of Business Partner has priority over POS configuration
* @param p_C_BPartner_ID id
*/
/**
* set BPartner and save
*/
public void configureBPartner(int partnerId) {
// Valid if has a Order
if (isCompleted() || isVoided())
return;
log.fine("CPOS.setC_BPartner_ID=" + partnerId);
boolean isSamePOSPartner = false;
// Validate BPartner
if (partnerId == 0) {
isSamePOSPartner = true;
partnerId = entityPOS.getC_BPartnerCashTrx_ID();
}
// Get BPartner
partner = MBPartner.get(ctx, partnerId);
if (partner == null || partner.get_ID() == 0) {
throw new AdempierePOSException("POS.NoBPartnerForOrder");
} else {
log.info("CPOS.SetC_BPartner_ID -" + partner);
currentOrder.setBPartner(partner);
//
MBPartnerLocation[] partnerLocations = partner.getLocations(true);
if (partnerLocations.length > 0) {
for (MBPartnerLocation partnerLocation : partnerLocations) {
if (partnerLocation.isBillTo())
currentOrder.setBill_Location_ID(partnerLocation.getC_BPartner_Location_ID());
if (partnerLocation.isShipTo())
currentOrder.setShip_Location_ID(partnerLocation.getC_BPartner_Location_ID());
}
}
// Validate Same BPartner
if (isSamePOSPartner) {
if (currentOrder.getPaymentRule() == null)
currentOrder.setPaymentRule(MOrder.PAYMENTRULE_Cash);
}
// Set Sales Representative
currentOrder.setSalesRep_ID(entityPOS.getSalesRep_ID());
// Save Header
currentOrder.saveEx();
// Load Price List Version
MPriceListVersion priceListVersion = loadPriceListVersion(currentOrder.getM_PriceList_ID());
MProductPrice[] productPrices = priceListVersion.getProductPrice("AND EXISTS(" + "SELECT 1 " + "FROM C_OrderLine ol " + "WHERE ol.C_Order_ID = " + currentOrder.getC_Order_ID() + " " + "AND ol.M_Product_ID = M_ProductPrice.M_Product_ID)");
// Update Lines
MOrderLine[] lines = currentOrder.getLines();
// Delete if not exist in price list
for (MOrderLine line : lines) {
// Verify if exist
if (existInPriceList(line.getM_Product_ID(), productPrices)) {
line.setC_BPartner_ID(partner.getC_BPartner_ID());
line.setC_BPartner_Location_ID(currentOrder.getC_BPartner_Location_ID());
line.setPrice();
line.setTax();
line.saveEx();
} else {
line.deleteEx(true);
}
}
}
}
use of org.adempiere.pos.AdempierePOSException in project adempiere by adempiere.
the class POSGenericTicketHandler method printTicket.
@Override
public void printTicket() {
try {
ProcessInfo info = new ProcessInfo(null, 0);
info.setTransactionName(getPOS().get_TrxName());
if (!getPOS().isInvoiced()) {
ReportCtl.startDocumentPrint(ReportEngine.ORDER, null, getPOS().getC_Order_ID(), null, getPOS().getWindowNo(), false, null, info);
} else {
for (MInvoice invoice : getPOS().getOrder().getInvoices()) {
ReportCtl.startDocumentPrint(ReportEngine.INVOICE, null, invoice.getC_Invoice_ID(), null, getPOS().getWindowNo(), false, null, info);
}
}
} catch (Exception e) {
throw new AdempierePOSException("PrintTicket - Error Printing Ticket");
}
}
use of org.adempiere.pos.AdempierePOSException in project adempiere by adempiere.
the class POSScalesDriver method getMeasure.
public BigDecimal getMeasure() {
if (loadLibrary()) {
if (!openPort(getElectronicScales()))
throw new AdempierePOSException("@NotFound@ @Port@ @ElectronicScales@");
String measure = this.getMeasureMessage().trim();
String[] tokens;
if (measure != null && !measure.equals("NEG")) {
tokens = measure.split(" ");
if (tokens != null && tokens.length > 0) {
try {
BigDecimal measureQuantity = new BigDecimal(tokens[0].trim());
if (measureQuantity != null && measureQuantity.signum() > 0) {
closePort();
return measureQuantity;
}
return BigDecimal.ONE;
} catch (Exception e) {
throw new org.adempiere.pos.AdempierePOSException("@Error@ @From@ @ElectronicScales@ : " + measure);
}
}
}
}
return BigDecimal.ONE;
}
use of org.adempiere.pos.AdempierePOSException in project adempiere by adempiere.
the class ReverseTheSalesTransaction method cancelInvoices.
private void cancelInvoices() {
for (MInOut customerReturn : customerReturns) {
ProcessInfo processInfo = ProcessBuilder.create(getCtx()).process(// AD_Process_ID = 154
"M_InOut_CreateInvoice").withTitle("Generate Invoice from Receipt").withRecordId(MInOut.Table_ID, customerReturn.getM_InOut_ID()).withoutTransactionClose().execute(get_TrxName());
if (processInfo.isError()) {
String errorMessage = Msg.parseTranslation(getCtx(), processInfo.getTitle() + " @ProcessRunError@ " + processInfo.getSummary() + " " + processInfo.getLogInfo());
throw new AdempierePOSException(errorMessage);
}
addLog(processInfo.getLogInfo());
for (MInvoice creditNote : getCreditNotes(customerReturn.getM_RMA_ID())) {
if (creditNote != null && creditNote.getC_Invoice_ID() > 0) {
creditNote.setDateInvoiced(today);
creditNote.setDateAcct(today);
creditNote.processIt(DocAction.ACTION_Complete);
creditNote.saveEx();
addLog(creditNote.getDocumentInfo());
}
}
}
}
use of org.adempiere.pos.AdempierePOSException in project adempiere by adempiere.
the class CPOS method isValidUserPin.
/**
* Validate User PIN
* @param userPin
*/
public boolean isValidUserPin(char[] userPin) {
if (userPin == null || userPin.length == 0)
return false;
MUser user = MUser.get(getCtx(), getAD_User_ID());
Optional<I_AD_User> optionalSuperVisor = Optional.of(user.getSupervisor());
I_AD_User superVisor = optionalSuperVisor.orElseThrow(() -> new AdempierePOSException("@Supervisor@ @NotFound@"));
Optional<String> superVisorName = Optional.ofNullable(superVisor.getName());
if (superVisor.getUserPIN() == null || superVisor.getUserPIN().isEmpty())
throw new AdempierePOSException("@Supervisor@ \"" + superVisorName.orElse("") + "\": @UserPIN@ @NotFound@");
char[] correctPassword = superVisor.getUserPIN().toCharArray();
boolean isCorrect = true;
if (userPin.length != correctPassword.length) {
isCorrect = false;
} else {
for (int i = 0; i < userPin.length; i++) {
if (userPin[i] != correctPassword[i]) {
isCorrect = false;
}
}
}
//Zero out the password.
for (int i = 0; i < correctPassword.length; i++) {
correctPassword[i] = 0;
}
return isCorrect;
}
Aggregations