use of org.compiere.model.MInvoiceSchedule in project adempiere by adempiere.
the class SB_InvoiceGenerateFromOrderLine method generate.
// doIt
/**
* Generate Shipments
* @param pstmt order query
* @return info
*/
private String generate(MOrder order) {
try {
{
// New Invoice Location
if (!p_ConsolidateDocument || (m_invoice != null && m_invoice.getC_BPartner_Location_ID() != order.getBill_Location_ID()))
completeInvoice();
boolean completeOrder = MOrder.INVOICERULE_AfterOrderDelivered.equals(order.getInvoiceRule());
// Schedule After Delivery
boolean doInvoice = false;
if (MOrder.INVOICERULE_CustomerScheduleAfterDelivery.equals(order.getInvoiceRule())) {
m_bp = new MBPartner(getCtx(), order.getBill_BPartner_ID(), null);
if (m_bp.getC_InvoiceSchedule_ID() == 0) {
log.warning("BPartner has no Schedule - set to After Delivery");
order.setInvoiceRule(MOrder.INVOICERULE_AfterDelivery);
order.saveEx();
} else {
MInvoiceSchedule is = MInvoiceSchedule.get(getCtx(), m_bp.getC_InvoiceSchedule_ID(), get_TrxName());
if (is.canInvoice(order.getDateOrdered(), order.getGrandTotal()))
doInvoice = true;
else
return "";
}
}
// After Delivery
if (doInvoice || MOrder.INVOICERULE_AfterDelivery.equals(order.getInvoiceRule())) {
MInOut[] shipments = order.getShipments();
for (int i = 0; i < shipments.length; i++) {
MInOut ship = shipments[i];
if (// ignore incomplete or reversals
!ship.isComplete() || ship.getDocStatus().equals(MInOut.DOCSTATUS_Reversed))
continue;
MInOutLine[] shipLines = ship.getLines(false);
for (int j = 0; j < shipLines.length; j++) {
MInOutLine shipLine = shipLines[j];
if (!order.isOrderLine(shipLine.getC_OrderLine_ID()))
continue;
if (!getSelectionKeys().contains(shipLine.getC_OrderLine_ID()))
continue;
if (!shipLine.isInvoiced())
createLine(order, ship, shipLine);
}
m_line += 1000;
}
} else // After Order Delivered, Immediate
{
MOrderLine[] oLines = order.getLines(true, null);
for (int i = 0; i < oLines.length; i++) {
MOrderLine oLine = oLines[i];
if (!getSelectionKeys().contains(oLine.getC_OrderLine_ID()))
continue;
BigDecimal toInvoice = oLine.getQtyOrdered().subtract(oLine.getQtyInvoiced());
if (toInvoice.compareTo(Env.ZERO) == 0 && oLine.getM_Product_ID() != 0)
continue;
BigDecimal notInvoicedShipment = oLine.getQtyDelivered().subtract(oLine.getQtyInvoiced());
//
boolean fullyDelivered = oLine.getQtyOrdered().compareTo(oLine.getQtyDelivered()) == 0;
// Complete Order
if (completeOrder && !fullyDelivered) {
log.fine("Failed CompleteOrder - " + oLine);
// Elaine 2008/11/25
addLog("Failed CompleteOrder - " + oLine);
completeOrder = false;
break;
} else // Immediate
if (MOrder.INVOICERULE_Immediate.equals(order.getInvoiceRule())) {
log.fine("Immediate - ToInvoice=" + toInvoice + " - " + oLine);
BigDecimal qtyEntered = toInvoice;
if (oLine.getQtyEntered().compareTo(oLine.getQtyOrdered()) != 0)
qtyEntered = toInvoice.multiply(oLine.getQtyEntered()).divide(oLine.getQtyOrdered(), 12, BigDecimal.ROUND_HALF_UP);
createLine(order, oLine, toInvoice, qtyEntered);
} else {
log.fine("Failed: " + order.getInvoiceRule() + " - ToInvoice=" + toInvoice + " - " + oLine);
addLog("Failed: " + order.getInvoiceRule() + " - ToInvoice=" + toInvoice + " - " + oLine);
}
}
// for all order lines
if (MOrder.INVOICERULE_Immediate.equals(order.getInvoiceRule()))
m_line += 1000;
}
// Complete Order successful
if (completeOrder && MOrder.INVOICERULE_AfterOrderDelivered.equals(order.getInvoiceRule())) {
MInOut[] shipments = order.getShipments();
for (int i = 0; i < shipments.length; i++) {
MInOut ship = shipments[i];
if (// ignore incomplete or reversals
!ship.isComplete() || ship.getDocStatus().equals(MInOut.DOCSTATUS_Reversed))
continue;
MInOutLine[] shipLines = ship.getLines(false);
for (int j = 0; j < shipLines.length; j++) {
MInOutLine shipLine = shipLines[j];
if (!order.isOrderLine(shipLine.getC_OrderLine_ID()))
continue;
if (!shipLine.isInvoiced())
createLine(order, ship, shipLine);
}
m_line += 1000;
}
}
// complete Order
}
// for all orders
} catch (Exception e) {
log.log(Level.SEVERE, "", e);
}
completeInvoice();
return "@Created@ = " + m_created;
}
use of org.compiere.model.MInvoiceSchedule in project adempiere by adempiere.
the class InvoiceGenerate method generate.
// doIt
/**
* Generate Shipments
* @param pstmt order query
* @return info
*/
private String generate(PreparedStatement pstmt) {
try {
ResultSet rs = pstmt.executeQuery();
while (rs.next()) {
MOrder order = new MOrder(getCtx(), rs, get_TrxName());
// New Invoice Location
if (!p_ConsolidateDocument || (m_invoice != null && m_invoice.getC_BPartner_Location_ID() != order.getBill_Location_ID()))
completeInvoice();
boolean completeOrder = MOrder.INVOICERULE_AfterOrderDelivered.equals(order.getInvoiceRule());
// Schedule After Delivery
boolean doInvoice = false;
if (MOrder.INVOICERULE_CustomerScheduleAfterDelivery.equals(order.getInvoiceRule())) {
m_bp = new MBPartner(getCtx(), order.getBill_BPartner_ID(), null);
if (m_bp.getC_InvoiceSchedule_ID() == 0) {
log.warning("BPartner has no Schedule - set to After Delivery");
order.setInvoiceRule(MOrder.INVOICERULE_AfterDelivery);
order.saveEx();
} else {
MInvoiceSchedule is = MInvoiceSchedule.get(getCtx(), m_bp.getC_InvoiceSchedule_ID(), get_TrxName());
if (is.canInvoice(order.getDateOrdered(), order.getGrandTotal()))
doInvoice = true;
else
continue;
}
}
// After Delivery
if (doInvoice || MOrder.INVOICERULE_AfterDelivery.equals(order.getInvoiceRule())) {
MInOut[] shipments = order.getShipments();
for (int i = 0; i < shipments.length; i++) {
MInOut ship = shipments[i];
if (// ignore incomplete or reversals
!ship.isComplete() || ship.getDocStatus().equals(MInOut.DOCSTATUS_Reversed))
continue;
MInOutLine[] shipLines = ship.getLines(false);
for (int j = 0; j < shipLines.length; j++) {
MInOutLine shipLine = shipLines[j];
if (!order.isOrderLine(shipLine.getC_OrderLine_ID()))
continue;
if (!shipLine.isInvoiced())
createLine(order, ship, shipLine);
}
m_line += 1000;
}
} else // After Order Delivered, Immediate
{
MOrderLine[] oLines = order.getLines(true, null);
for (int i = 0; i < oLines.length; i++) {
MOrderLine oLine = oLines[i];
BigDecimal toInvoice = oLine.getQtyOrdered().subtract(oLine.getQtyInvoiced());
if (toInvoice.compareTo(Env.ZERO) == 0 && oLine.getM_Product_ID() != 0)
continue;
BigDecimal notInvoicedShipment = oLine.getQtyDelivered().subtract(oLine.getQtyInvoiced());
//
boolean fullyDelivered = oLine.getQtyOrdered().compareTo(oLine.getQtyDelivered()) == 0;
// Complete Order
if (completeOrder && !fullyDelivered) {
log.fine("Failed CompleteOrder - " + oLine);
// Elaine 2008/11/25
addLog("Failed CompleteOrder - " + oLine);
completeOrder = false;
break;
} else // Immediate
if (MOrder.INVOICERULE_Immediate.equals(order.getInvoiceRule())) {
log.fine("Immediate - ToInvoice=" + toInvoice + " - " + oLine);
BigDecimal qtyEntered = toInvoice;
// Correct UOM for QtyEntered
if (oLine.getQtyEntered().compareTo(oLine.getQtyOrdered()) != 0)
qtyEntered = toInvoice.multiply(oLine.getQtyEntered()).divide(oLine.getQtyOrdered(), 12, BigDecimal.ROUND_HALF_UP);
createLine(order, oLine, toInvoice, qtyEntered);
} else {
log.fine("Failed: " + order.getInvoiceRule() + " - ToInvoice=" + toInvoice + " - " + oLine);
addLog("Failed: " + order.getInvoiceRule() + " - ToInvoice=" + toInvoice + " - " + oLine);
}
}
// for all order lines
if (MOrder.INVOICERULE_Immediate.equals(order.getInvoiceRule()))
m_line += 1000;
}
// Complete Order successful
if (completeOrder && MOrder.INVOICERULE_AfterOrderDelivered.equals(order.getInvoiceRule())) {
MInOut[] shipments = order.getShipments();
for (int i = 0; i < shipments.length; i++) {
MInOut ship = shipments[i];
if (// ignore incomplete or reversals
!ship.isComplete() || ship.getDocStatus().equals(MInOut.DOCSTATUS_Reversed))
continue;
MInOutLine[] shipLines = ship.getLines(false);
for (int j = 0; j < shipLines.length; j++) {
MInOutLine shipLine = shipLines[j];
if (!order.isOrderLine(shipLine.getC_OrderLine_ID()))
continue;
if (!shipLine.isInvoiced())
createLine(order, ship, shipLine);
}
m_line += 1000;
}
}
// complete Order
}
// for all orders
rs.close();
pstmt.close();
pstmt = null;
} catch (Exception e) {
log.log(Level.SEVERE, "", e);
}
try {
if (pstmt != null)
pstmt.close();
pstmt = null;
} catch (Exception e) {
pstmt = null;
}
completeInvoice();
return "@Created@ = " + m_created;
}
use of org.compiere.model.MInvoiceSchedule in project adempiere by adempiere.
the class InvoiceGenerateFromShipment method generate.
//@Trifon
private String generate(PreparedStatement pstmt) {
ResultSet rs = null;
MInvoice invoice = null;
try {
rs = pstmt.executeQuery();
while (rs.next()) {
MInOut inOut = new MInOut(getCtx(), rs, get_TrxName());
if (// ignore incomplete or reversals
!inOut.isComplete() || inOut.getDocStatus().equals(MInOut.DOCSTATUS_Reversed)) {
continue;
}
MOrder order = new MOrder(getCtx(), inOut.getC_Order_ID(), get_TrxName());
// New Invoice Location
if (!p_ConsolidateDocument || (invoice != null && invoice.getC_BPartner_Location_ID() != order.getBill_Location_ID())) {
invoice = completeInvoice(invoice);
}
// boolean completeOrder = MOrder.INVOICERULE_AfterOrderDelivered.equals(order.getInvoiceRule());
// Schedule After Delivery
boolean doInvoice = false;
if (MOrder.INVOICERULE_CustomerScheduleAfterDelivery.equals(order.getInvoiceRule())) {
m_bp = new MBPartner(getCtx(), order.getBill_BPartner_ID(), null);
if (m_bp.getC_InvoiceSchedule_ID() == 0) {
log.warning("BPartner has no Schedule - set to After Delivery");
order.setInvoiceRule(MOrder.INVOICERULE_AfterDelivery);
order.save();
} else {
MInvoiceSchedule is = MInvoiceSchedule.get(getCtx(), m_bp.getC_InvoiceSchedule_ID(), get_TrxName());
if (is.canInvoice(order.getDateOrdered(), order.getGrandTotal()))
doInvoice = true;
else
continue;
}
}
// After Delivery - Invoice per Delivery
if (doInvoice || MOrder.INVOICERULE_AfterDelivery.equals(order.getInvoiceRule())) {
MInOutLine[] shipLines = inOut.getLines(false);
for (int j = 0; j < shipLines.length; j++) {
MInOutLine inOutLine = shipLines[j];
if (!inOutLine.isInvoiced()) {
invoice = createInvoiceLineFromShipmentLine(invoice, order, inOut, inOutLine);
}
}
m_line += 1000;
} else // After Order Delivered, Immediate
{
throw new AdempiereException("Not supported Invoice Rules[Immediate, AfterOrderDelivered]");
}
}
// for all Shipments
} catch (Exception e) {
log.log(Level.SEVERE, "", e);
} finally {
DB.close(rs, pstmt);
pstmt = null;
}
completeInvoice(invoice);
return "@Created@ = " + m_created;
}
Aggregations