use of org.compiere.model.MClient in project adempiere by adempiere.
the class SB_InvoiceGenerateFromOrderLine method createLine.
// createLine
/**
* Create Invoice Line from Shipment
* @param order order
* @param ship shipment header
* @param sLine shipment line
*/
private void createLine(MOrder order, MInOut ship, MInOutLine sLine) {
if (m_invoice == null) {
m_invoice = new MInvoice(order, 0, p_DateInvoiced);
if (!m_invoice.save())
throw new IllegalStateException("Could not create Invoice (s)");
}
// Create Shipment Comment Line
if (m_ship == null || m_ship.getM_InOut_ID() != ship.getM_InOut_ID()) {
MDocType dt = MDocType.get(getCtx(), ship.getC_DocType_ID());
if (m_bp == null || m_bp.getC_BPartner_ID() != ship.getC_BPartner_ID())
m_bp = new MBPartner(getCtx(), ship.getC_BPartner_ID(), get_TrxName());
// Reference: Delivery: 12345 - 12.12.12
MClient client = MClient.get(getCtx(), order.getAD_Client_ID());
String AD_Language = client.getAD_Language();
if (client.isMultiLingualDocument() && m_bp.getAD_Language() != null)
AD_Language = m_bp.getAD_Language();
if (AD_Language == null)
AD_Language = Language.getBaseAD_Language();
java.text.SimpleDateFormat format = DisplayType.getDateFormat(DisplayType.Date, Language.getLanguage(AD_Language));
String reference = dt.getPrintName(m_bp.getAD_Language()) + ": " + ship.getDocumentNo() + " - " + format.format(ship.getMovementDate());
m_ship = ship;
//
MInvoiceLine line = new MInvoiceLine(m_invoice);
line.setIsDescription(true);
line.setDescription(reference);
line.setLine(m_line + sLine.getLine() - 2);
if (!line.save())
throw new IllegalStateException("Could not create Invoice Comment Line (sh)");
// Optional Ship Address if not Bill Address
if (order.getBill_Location_ID() != ship.getC_BPartner_Location_ID()) {
MLocation addr = MLocation.getBPLocation(getCtx(), ship.getC_BPartner_Location_ID(), null);
line = new MInvoiceLine(m_invoice);
line.setIsDescription(true);
line.setDescription(addr.toString());
line.setLine(m_line + sLine.getLine() - 1);
if (!line.save())
throw new IllegalStateException("Could not create Invoice Comment Line 2 (sh)");
}
}
//
MInvoiceLine line = new MInvoiceLine(m_invoice);
line.setShipLine(sLine);
if (sLine.sameOrderLineUOM())
line.setQtyEntered(sLine.getQtyEntered());
else
line.setQtyEntered(sLine.getMovementQty());
line.setQtyInvoiced(sLine.getMovementQty());
line.setLine(m_line + sLine.getLine());
//@Trifon - special handling when ShipLine.ToBeInvoiced='N'
String toBeInvoiced = sLine.get_ValueAsString("ToBeInvoiced");
if ("N".equals(toBeInvoiced)) {
line.setPriceEntered(Env.ZERO);
line.setPriceActual(Env.ZERO);
line.setPriceLimit(Env.ZERO);
line.setPriceList(Env.ZERO);
//setC_Tax_ID(oLine.getC_Tax_ID());
line.setLineNetAmt(Env.ZERO);
line.setIsDescription(true);
}
if (!line.save())
throw new IllegalStateException("Could not create Invoice Line (s)");
// Link
sLine.setIsInvoiced(true);
if (!sLine.save())
throw new IllegalStateException("Could not update Shipment Line");
log.fine(line.toString());
}
use of org.compiere.model.MClient in project adempiere by adempiere.
the class ReplenishReport method createDO.
// Create Inventory Movements
/**
* Create Distribution Order
*/
private void createDO() throws Exception {
int noMoves = 0;
String info = "";
//
MClient client = null;
MDDOrder order = null;
int M_Warehouse_ID = 0;
int M_WarehouseSource_ID = 0;
MWarehouse whSource = null;
MWarehouse wh = null;
X_T_Replenish[] replenishs = getReplenishDO("M_WarehouseSource_ID IS NOT NULL");
for (X_T_Replenish replenish : replenishs) {
if (whSource == null || whSource.getM_WarehouseSource_ID() != replenish.getM_WarehouseSource_ID())
whSource = MWarehouse.get(getCtx(), replenish.getM_WarehouseSource_ID());
if (wh == null || wh.getM_Warehouse_ID() != replenish.getM_Warehouse_ID())
wh = MWarehouse.get(getCtx(), replenish.getM_Warehouse_ID());
if (client == null || client.getAD_Client_ID() != whSource.getAD_Client_ID())
client = MClient.get(getCtx(), whSource.getAD_Client_ID());
//
if (order == null || M_WarehouseSource_ID != replenish.getM_WarehouseSource_ID() || M_Warehouse_ID != replenish.getM_Warehouse_ID()) {
M_WarehouseSource_ID = replenish.getM_WarehouseSource_ID();
M_Warehouse_ID = replenish.getM_Warehouse_ID();
order = new MDDOrder(getCtx(), 0, get_TrxName());
order.setC_DocType_ID(p_C_DocType_ID);
order.setDescription(Msg.getMsg(getCtx(), "Replenishment") + ": " + whSource.getName() + "->" + wh.getName());
// Set Org
order.setAD_Org_ID(whSource.getAD_Org_ID());
// Set Org Trx
MOrg orgTrx = MOrg.get(getCtx(), wh.getAD_Org_ID());
order.setAD_OrgTrx_ID(orgTrx.getAD_Org_ID());
int C_BPartner_ID = orgTrx.getLinkedC_BPartner_ID(get_TrxName());
if (C_BPartner_ID == 0)
throw new AdempiereUserError(Msg.translate(getCtx(), "C_BPartner_ID") + " @FillMandatory@ ");
MBPartner bp = new MBPartner(getCtx(), C_BPartner_ID, get_TrxName());
// Set BPartner Link to Org
order.setBPartner(bp);
order.setDateOrdered(new Timestamp(System.currentTimeMillis()));
//order.setDatePromised(DatePromised);
order.setDeliveryRule(MDDOrder.DELIVERYRULE_Availability);
order.setDeliveryViaRule(MDDOrder.DELIVERYVIARULE_Delivery);
order.setPriorityRule(MDDOrder.PRIORITYRULE_Medium);
order.setIsInDispute(false);
order.setIsApproved(false);
order.setIsDropShip(false);
order.setIsDelivered(false);
order.setIsInTransit(false);
order.setIsPrinted(false);
order.setIsSelected(false);
order.setIsSOTrx(false);
// Warehouse in Transit
MWarehouse[] whsInTransit = MWarehouse.getForOrg(getCtx(), whSource.getAD_Org_ID());
for (MWarehouse whInTransit : whsInTransit) {
if (whInTransit.isInTransit())
order.setM_Warehouse_ID(whInTransit.getM_Warehouse_ID());
}
if (order.getM_Warehouse_ID() == 0)
throw new AdempiereUserError("Warehouse inTransit is @FillMandatory@ ");
if (!order.save())
return;
log.fine(order.toString());
noMoves++;
info += " - " + order.getDocumentNo();
}
// To
int M_LocatorTo_ID = wh.getDefaultLocator().getM_Locator_ID();
int M_Locator_ID = whSource.getDefaultLocator().getM_Locator_ID();
if (M_LocatorTo_ID == 0 || M_Locator_ID == 0)
throw new AdempiereUserError(Msg.translate(getCtx(), "M_Locator_ID") + " @FillMandatory@ ");
// From: Look-up Storage
/*MProduct product = MProduct.get(getCtx(), replenish.getM_Product_ID());
MProductCategory pc = MProductCategory.get(getCtx(), product.getM_Product_Category_ID());
String MMPolicy = pc.getMMPolicy();
if (MMPolicy == null || MMPolicy.length() == 0)
MMPolicy = client.getMMPolicy();
//
MStorage[] storages = MStorage.getWarehouse(getCtx(),
whSource.getM_Warehouse_ID(), replenish.getM_Product_ID(), 0, 0,
true, null,
MClient.MMPOLICY_FiFo.equals(MMPolicy), get_TrxName());
BigDecimal target = replenish.getQtyToOrder();
for (int j = 0; j < storages.length; j++)
{
MStorage storage = storages[j];
if (storage.getQtyOnHand().signum() <= 0)
continue;
BigDecimal moveQty = target;
if (storage.getQtyOnHand().compareTo(moveQty) < 0)
moveQty = storage.getQtyOnHand();
//
MDDOrderLine line = new MDDOrderLine(order);
line.setM_Product_ID(replenish.getM_Product_ID());
line.setQtyEntered(moveQty);
if (replenish.getQtyToOrder().compareTo(moveQty) != 0)
line.setDescription("Total: " + replenish.getQtyToOrder());
line.setM_Locator_ID(storage.getM_Locator_ID()); // from
line.setM_AttributeSetInstance_ID(storage.getM_AttributeSetInstance_ID());
line.setM_LocatorTo_ID(M_LocatorTo_ID); // to
line.setM_AttributeSetInstanceTo_ID(storage.getM_AttributeSetInstance_ID());
line.setIsInvoiced(false);
line.saveEx();
//
target = target.subtract(moveQty);
if (target.signum() == 0)
break;
}*/
MDDOrderLine line = new MDDOrderLine(order);
line.setM_Product_ID(replenish.getM_Product_ID());
line.setQty(replenish.getQtyToOrder());
if (replenish.getQtyToOrder().compareTo(replenish.getQtyToOrder()) != 0)
line.setDescription("Total: " + replenish.getQtyToOrder());
// from
line.setM_Locator_ID(M_Locator_ID);
line.setM_AttributeSetInstance_ID(0);
// to
line.setM_LocatorTo_ID(M_LocatorTo_ID);
line.setM_AttributeSetInstanceTo_ID(0);
line.setIsInvoiced(false);
line.saveEx();
}
if (replenishs.length == 0) {
m_info = "No Source Warehouse";
log.warning(m_info);
} else {
m_info = "#" + noMoves + info;
log.info(m_info);
}
}
use of org.compiere.model.MClient in project adempiere by adempiere.
the class EMail method setEMailParameters.
/**
* Set EMail Parameters (Host / Port / Encryption)
*/
private void setEMailParameters(int p_AD_EMailConfig_ID) {
//
if (p_AD_EMailConfig_ID != 0)
m_AD_EMailConfig_ID = p_AD_EMailConfig_ID;
// Validate Config
if (m_AD_EMailConfig_ID == 0) {
MClient client = MClient.get(m_ctx);
m_AD_EMailConfig_ID = client.getAD_EMailConfig_ID();
}
MEMailConfig eMailConfig = MEMailConfig.get(m_ctx, m_AD_EMailConfig_ID);
// Valid null
if (eMailConfig != null) {
m_Host = eMailConfig.getSMTPHost();
//
m_Port = eMailConfig.getPort();
m_Timeout = eMailConfig.getTimeout();
m_ConnectionTimeout = eMailConfig.getConnectionTimeout();
m_Protocol = eMailConfig.getProtocol();
m_EncryptionType = eMailConfig.getEncryptionType();
m_AuthMechanism = eMailConfig.getAuthMechanism();
m_IsSmtpAuthorization = eMailConfig.isSmtpAuthorization();
m_Domain = eMailConfig.getLDAPDomain();
} else {
getPort();
getProtocol();
getEncryptionType();
getAuthMechanism();
m_IsSmtpAuthorization = false;
}
}
use of org.compiere.model.MClient in project adempiere by adempiere.
the class CompiereUtil method initWeb.
public static boolean initWeb() {
if (s_initOK) {
//log.info(context.getServletContextName());
return true;
}
try {
//CLogMgt.setLevel(Level.OFF);
/* ADEMPIERE/COMPIERE */
//s_initOK = Compiere.startup(false);
s_initOK = Adempiere.startup(false);
} catch (Exception ex) {
log.log(Level.SEVERE, "startup", ex);
}
if (!s_initOK)
return false;
// Logging now initiated
//log.info(info.toString());
//
Properties ctx = new Properties();
MClient client = MClient.get(ctx, 0);
MSystem system = MSystem.get(ctx);
return s_initOK;
}
use of org.compiere.model.MClient in project adempiere by adempiere.
the class WebSessionCtx method getDefaults.
// setWStore
/**
* Get Web Store Defaults
* @return context
*/
private Properties getDefaults() {
// No Web Store
if (wstore == null)
return new Properties();
//
Integer key = new Integer(wstore.getW_Store_ID());
Properties newCtx = (Properties) s_cacheCtx.get(key);
/** Create New Context */
if (newCtx == null) {
log.info(wstore.getWebContext());
newCtx = new Properties();
// copy explicitly
Enumeration e = ctx.keys();
while (e.hasMoreElements()) {
String pKey = (String) e.nextElement();
newCtx.setProperty(pKey, ctx.getProperty(pKey));
}
Env.setContext(newCtx, "#AD_Client_ID", wstore.getAD_Client_ID());
Env.setContext(newCtx, "#AD_Org_ID", wstore.getAD_Org_ID());
//
Env.setContext(newCtx, "#SalesRep_ID", wstore.getSalesRep_ID());
Env.setContext(newCtx, "#M_PriceList_ID", wstore.getM_PriceList_ID());
Env.setContext(newCtx, "#M_Warehouse_ID", wstore.getM_Warehouse_ID());
//
String s = wstore.getWebParam1();
Env.setContext(newCtx, "webParam1", s == null ? "" : s);
s = wstore.getWebParam2();
Env.setContext(newCtx, "webParam2", s == null ? "" : s);
s = wstore.getWebParam3();
Env.setContext(newCtx, "webParam3", s == null ? "" : s);
s = wstore.getWebParam4();
Env.setContext(newCtx, "webParam4", s == null ? "" : s);
s = wstore.getWebParam5();
Env.setContext(newCtx, "webParam5", s == null ? "" : s);
s = wstore.getWebParam6();
Env.setContext(newCtx, "webParam6", s == null ? "" : s);
s = wstore.getStylesheet();
if (s == null)
s = "standard";
else {
int index = s.lastIndexOf('.');
if (index != -1)
s = s.substring(0, index);
}
Env.setContext(newCtx, "Stylesheet", s);
//
s = wstore.getWebInfo();
if (s != null && s.length() > 0)
Env.setContext(newCtx, HDR_INFO, s);
// Payment Term
Env.setContext(newCtx, "#M_PriceList_ID", wstore.getM_PriceList_ID());
// Default User - SalesRep
if (Env.getContextAsInt(newCtx, "#AD_User_ID") == 0)
Env.setContext(newCtx, "#AD_User_ID", wstore.getSalesRep_ID());
// Default Role for access
if (Env.getContextAsInt(newCtx, "#AD_Role_ID") == 0) {
// HARDCODED - System
int AD_Role_ID = 0;
Env.setContext(newCtx, "#AD_Role_ID", AD_Role_ID);
}
// Client
MClient client = MClient.get(newCtx, wstore.getAD_Client_ID());
// Name,Description, SMTPHost,RequestEMail,RequestUser, RequestUserPw
Env.setContext(newCtx, "name", client.getName());
Env.setContext(newCtx, "description", client.getDescription());
// AD_Language
if (newCtx.getProperty("#AD_Language") == null && client.getAD_Language() != null)
Env.setContext(newCtx, "#AD_Language", client.getAD_Language());
// DocumentDir
String docDir = client.getDocumentDir();
Env.setContext(newCtx, CTX_DOCUMENT_DIR, docDir == null ? "" : docDir);
// Default Language
if (newCtx.getProperty("#AD_Language") == null)
Env.setContext(newCtx, "#AD_Language", "en_US");
// Save Context - Key is AD_Client_ID
s_cacheCtx.put(key, newCtx);
}
// return new Properties (pp); seems not to work with JSP
Enumeration e = newCtx.keys();
while (e.hasMoreElements()) {
String pKey = (String) e.nextElement();
ctx.setProperty(pKey, newCtx.getProperty(pKey));
}
return ctx;
}
Aggregations