use of org.compiere.model.MRfQ in project adempiere by adempiere.
the class RfQServlet method streamAttachment.
// doGet
/**
* Stream Attachment
* @param request request
* @param response response
* @return "" or error message
*/
private String streamAttachment(HttpServletRequest request, HttpServletResponse response) {
// Get Note ID
int C_RfQ_ID = WebUtil.getParameterAsInt(request, "C_RfQ_ID");
if (C_RfQ_ID == 0) {
log.fine("streamAttachment - no ID)");
return "No RfQ ID";
}
// Get Note
Properties ctx = JSPEnv.getCtx(request);
MRfQ doc = new MRfQ(ctx, C_RfQ_ID, null);
if (doc.getC_RfQ_ID() != C_RfQ_ID) {
log.fine("streamAttachment - RfQ not found - ID=" + C_RfQ_ID);
return "RfQ not found";
}
if (!doc.isPdfAttachment())
return "No PDF Attachment found";
byte[] data = doc.getPdfAttachment();
if (data == null)
return "No PDF Attachment";
// Send PDF
try {
// 2k Buffer
int bufferSize = 2048;
int fileLength = data.length;
//
response.setContentType("application/pdf");
response.setBufferSize(bufferSize);
response.setContentLength(fileLength);
//
log.fine("streamAttachment - length=" + fileLength);
// timer start
long time = System.currentTimeMillis();
//
ServletOutputStream out = response.getOutputStream();
out.write(data);
out.flush();
out.close();
//
time = System.currentTimeMillis() - time;
double speed = (fileLength / 1024) / ((double) time / 1000);
log.fine("streamInvoice - length=" + fileLength + " - " + time + " ms - " + speed + " kB/sec");
} catch (IOException ex) {
log.log(Level.SEVERE, "streamAttachment - " + ex);
return "Streaming error";
}
return null;
}
use of org.compiere.model.MRfQ in project adempiere by adempiere.
the class RfQCreate method doIt.
// prepare
/**
* Perform process.
* @return Message (translated text)
* @throws Exception if not successful
*/
protected String doIt() throws Exception {
MRfQ rfq = new MRfQ(getCtx(), p_C_RfQ_ID, get_TrxName());
log.info("doIt - " + rfq + ", Send=" + p_IsSendRfQ);
String error = rfq.checkQuoteTotalAmtOnly();
if (error != null && error.length() > 0)
throw new Exception(error);
int counter = 0;
int sent = 0;
int notSent = 0;
// Get all existing responses
MRfQResponse[] responses = rfq.getResponses(false, false);
// Topic
MRfQTopic topic = new MRfQTopic(getCtx(), rfq.getC_RfQ_Topic_ID(), get_TrxName());
MRfQTopicSubscriber[] subscribers = topic.getSubscribers();
for (int i = 0; i < subscribers.length; i++) {
MRfQTopicSubscriber subscriber = subscribers[i];
boolean skip = false;
// existing response
for (int r = 0; r < responses.length; r++) {
if (subscriber.getC_BPartner_ID() == responses[r].getC_BPartner_ID() && subscriber.getC_BPartner_Location_ID() == responses[r].getC_BPartner_Location_ID()) {
skip = true;
break;
}
}
if (skip)
continue;
// Create Response
MRfQResponse response = new MRfQResponse(rfq, subscriber);
if (// no lines
response.get_ID() == 0)
continue;
counter++;
if (p_IsSendRfQ) {
commitEx();
if (response.sendRfQ())
sent++;
else
notSent++;
}
}
// for all subscribers
String retValue = "@Created@ " + counter;
if (p_IsSendRfQ)
retValue += " - @IsSendRfQ@=" + sent + " - @Error@=" + notSent;
return retValue;
}
use of org.compiere.model.MRfQ in project adempiere by adempiere.
the class RfQCreatePO method doIt.
// prepare
/**
* Process.
* Create purchase order(s) for the resonse(s) and lines marked as
* Selected Winner using the selected Purchase Quantity (in RfQ Line Quantity) .
* If a Response is marked as Selected Winner, all lines are created
* (and Selected Winner of other responses ignored).
* If there is no response marked as Selected Winner, the lines are used.
* @return message
*/
protected String doIt() throws Exception {
MRfQ rfq = new MRfQ(getCtx(), p_C_RfQ_ID, get_TrxName());
if (rfq.get_ID() == 0)
throw new IllegalArgumentException("No RfQ found");
log.info(rfq.toString());
// Complete
MRfQResponse[] responses = rfq.getResponses(true, true);
log.config("#Responses=" + responses.length);
if (responses.length == 0)
throw new IllegalArgumentException("No completed RfQ Responses found");
// Winner for entire RfQ
for (int i = 0; i < responses.length; i++) {
MRfQResponse response = responses[i];
if (!response.isSelectedWinner())
continue;
//
MBPartner bp = new MBPartner(getCtx(), response.getC_BPartner_ID(), get_TrxName());
log.config("Winner=" + bp);
MOrder order = new MOrder(getCtx(), 0, get_TrxName());
order.setIsSOTrx(false);
if (p_C_DocType_ID != 0)
order.setC_DocTypeTarget_ID(p_C_DocType_ID);
else
order.setC_DocTypeTarget_ID();
order.setBPartner(bp);
order.setC_BPartner_Location_ID(response.getC_BPartner_Location_ID());
order.setSalesRep_ID(rfq.getSalesRep_ID());
if (response.getDateWorkComplete() != null)
order.setDatePromised(response.getDateWorkComplete());
else if (rfq.getDateWorkComplete() != null)
order.setDatePromised(rfq.getDateWorkComplete());
order.saveEx();
//
MRfQResponseLine[] lines = response.getLines(false);
for (int j = 0; j < lines.length; j++) {
// Respones Line
MRfQResponseLine line = lines[j];
if (!line.isActive())
continue;
MRfQResponseLineQty[] qtys = line.getQtys(false);
// Response Line Qty
for (int k = 0; k < qtys.length; k++) {
MRfQResponseLineQty qty = qtys[k];
// Create PO Lline for all Purchase Line Qtys
if (qty.getRfQLineQty().isActive() && qty.getRfQLineQty().isPurchaseQty()) {
MOrderLine ol = new MOrderLine(order);
ol.setM_Product_ID(line.getRfQLine().getM_Product_ID(), qty.getRfQLineQty().getC_UOM_ID());
ol.setDescription(line.getDescription());
ol.setQty(qty.getRfQLineQty().getQty());
BigDecimal price = qty.getNetAmt();
ol.setPrice();
ol.setPrice(price);
ol.saveEx();
}
}
}
response.setC_Order_ID(order.getC_Order_ID());
response.saveEx();
return order.getDocumentNo();
}
// Selected Winner on Line Level
int noOrders = 0;
for (int i = 0; i < responses.length; i++) {
MRfQResponse response = responses[i];
MBPartner bp = null;
MOrder order = null;
// For all Response Lines
MRfQResponseLine[] lines = response.getLines(false);
for (int j = 0; j < lines.length; j++) {
MRfQResponseLine line = lines[j];
if (!line.isActive() || !line.isSelectedWinner())
continue;
// New/different BP
if (bp == null || bp.getC_BPartner_ID() != response.getC_BPartner_ID()) {
bp = new MBPartner(getCtx(), response.getC_BPartner_ID(), get_TrxName());
order = null;
}
log.config("Line=" + line + ", Winner=" + bp);
// New Order
if (order == null) {
order = new MOrder(getCtx(), 0, get_TrxName());
order.setIsSOTrx(false);
order.setC_DocTypeTarget_ID();
order.setBPartner(bp);
order.setC_BPartner_Location_ID(response.getC_BPartner_Location_ID());
order.setSalesRep_ID(rfq.getSalesRep_ID());
order.saveEx();
noOrders++;
addLog(0, null, null, order.getDocumentNo());
}
// For all Qtys
MRfQResponseLineQty[] qtys = line.getQtys(false);
for (int k = 0; k < qtys.length; k++) {
MRfQResponseLineQty qty = qtys[k];
if (qty.getRfQLineQty().isActive() && qty.getRfQLineQty().isPurchaseQty()) {
MOrderLine ol = new MOrderLine(order);
ol.setM_Product_ID(line.getRfQLine().getM_Product_ID(), qty.getRfQLineQty().getC_UOM_ID());
ol.setDescription(line.getDescription());
ol.setQty(qty.getRfQLineQty().getQty());
BigDecimal price = qty.getNetAmt();
ol.setPrice();
ol.setPrice(price);
ol.saveEx();
}
}
// for all Qtys
}
// for all Response Lines
if (order != null) {
response.setC_Order_ID(order.getC_Order_ID());
response.saveEx();
}
}
return "#" + noOrders;
}
use of org.compiere.model.MRfQ in project adempiere by adempiere.
the class RfQResponseRank method doIt.
// prepare
/**
* Process.
* <pre>
* - ignore 0 or invalid responses
* - rank among qty
* - for selected PO qty select winner
* - if all lines are winner - select that
* </pre>
* @return message
*/
protected String doIt() throws Exception {
MRfQ rfq = new MRfQ(getCtx(), p_C_RfQ_ID, get_TrxName());
if (rfq.get_ID() == 0)
throw new IllegalArgumentException("No RfQ found");
log.info(rfq.toString());
String error = rfq.checkQuoteTotalAmtOnly();
if (error != null && error.length() > 0)
throw new Exception(error);
// Get Completed, Active Responses
MRfQResponse[] responses = rfq.getResponses(true, true);
log.fine("doIt - #Responses=" + responses.length);
if (responses.length == 0)
throw new IllegalArgumentException("No completed RfQ Responses found");
if (responses.length == 1) {
responses[0].setIsSelectedWinner(true);
responses[0].saveEx();
return "Only one completed RfQ Response found";
}
// Rank
if (rfq.isQuoteTotalAmtOnly())
rankResponses(rfq, responses);
else
rankLines(rfq, responses);
return "# " + responses.length;
}
use of org.compiere.model.MRfQ in project adempiere by adempiere.
the class WebInfo method getRfQs.
// getRegistration
/**
* Get RfQs.
* Where Response is Accepted, Self Service and either
* all vendors or this vendor is selected.
* @return request for quotations
*/
public ArrayList<MRfQ> getRfQs() {
m_infoMessage = null;
ArrayList<MRfQ> list = new ArrayList<MRfQ>();
String sql = "SELECT * " + "FROM C_RfQ r " + "WHERE r.IsRfQResponseAccepted='Y'" + " AND r.IsSelfService='Y' AND r.IsActive='Y' AND r.Processed='N'" + " AND (r.IsInvitedVendorsOnly='N'" + " OR EXISTS (SELECT * FROM C_RfQResponse rr " + " WHERE r.C_RfQ_ID=rr.C_RfQ_ID AND rr.C_BPartner_ID=?)) " + "ORDER BY r.Name";
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
pstmt = DB.prepareStatement(sql, null);
pstmt.setInt(1, getC_BPartner_ID());
rs = pstmt.executeQuery();
while (rs.next()) list.add(new MRfQ(m_ctx, rs, null));
} catch (Exception e) {
log.log(Level.SEVERE, sql, e);
} finally {
DB.close(rs, pstmt);
rs = null;
pstmt = null;
}
log.fine("#" + list.size());
return list;
}
Aggregations