FR [ 1895317 ] InvoiceCreateInOut: you can create many receipts
This commit is contained in:
parent
c78bc26b10
commit
4ed7def01a
|
@ -0,0 +1,30 @@
|
||||||
|
/******************************************************************************
|
||||||
|
* Product: Adempiere ERP & CRM Smart Business Solution *
|
||||||
|
* Copyright (C) 2008 SC ARHIPAC SERVICE SRL. All Rights Reserved. *
|
||||||
|
* This program is free software; you can redistribute it and/or modify it *
|
||||||
|
* under the terms version 2 of the GNU General Public License as published *
|
||||||
|
* by the Free Software Foundation. This program is distributed in the hope *
|
||||||
|
* that it will be useful, but WITHOUT ANY WARRANTY; without even the implied *
|
||||||
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. *
|
||||||
|
* See the GNU General Public License for more details. *
|
||||||
|
* You should have received a copy of the GNU General Public License along *
|
||||||
|
* with this program; if not, write to the Free Software Foundation, Inc., *
|
||||||
|
* 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. *
|
||||||
|
*****************************************************************************/
|
||||||
|
package org.adempiere.exceptions;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Throwed when an invoice is fully matched so no more receipts can be generated.
|
||||||
|
* @author Teo Sarca, www.arhipac.ro
|
||||||
|
*/
|
||||||
|
public class InvoiceFullyMatchedException extends AdempiereException
|
||||||
|
{
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
public static final String AD_Message = "InvoiceFullyMatched";
|
||||||
|
|
||||||
|
public InvoiceFullyMatchedException()
|
||||||
|
{
|
||||||
|
super("@"+AD_Message+"@");
|
||||||
|
}
|
||||||
|
}
|
|
@ -1196,4 +1196,17 @@ public class MInvoiceLine extends X_C_InvoiceLine
|
||||||
setC_Activity_ID(rmaLine.getC_Activity_ID());
|
setC_Activity_ID(rmaLine.getC_Activity_ID());
|
||||||
setC_Campaign_ID(rmaLine.getC_Campaign_ID());
|
setC_Campaign_ID(rmaLine.getC_Campaign_ID());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return matched qty
|
||||||
|
*/
|
||||||
|
public BigDecimal getMatchedQty()
|
||||||
|
{
|
||||||
|
String sql = "SELECT COALESCE(SUM("+MMatchInv.COLUMNNAME_Qty+"),0)"
|
||||||
|
+" FROM "+MMatchInv.Table_Name
|
||||||
|
+" WHERE "+MMatchInv.COLUMNNAME_C_InvoiceLine_ID+"=?"
|
||||||
|
+" AND "+MMatchInv.COLUMNNAME_Processed+"=?";
|
||||||
|
return DB.getSQLValueBDEx(get_TrxName(), sql, getC_InvoiceLine_ID(), true);
|
||||||
|
}
|
||||||
|
|
||||||
} // MInvoiceLine
|
} // MInvoiceLine
|
||||||
|
|
|
@ -16,37 +16,50 @@
|
||||||
*****************************************************************************/
|
*****************************************************************************/
|
||||||
package org.compiere.process;
|
package org.compiere.process;
|
||||||
|
|
||||||
import java.util.logging.*;
|
import java.math.BigDecimal;
|
||||||
|
import java.util.logging.Level;
|
||||||
|
|
||||||
import org.compiere.util.*;
|
import org.adempiere.exceptions.AdempiereException;
|
||||||
import org.compiere.model.*;
|
import org.adempiere.exceptions.FillMandatoryException;
|
||||||
|
import org.adempiere.exceptions.InvoiceFullyMatchedException;
|
||||||
|
import org.compiere.model.MInOut;
|
||||||
|
import org.compiere.model.MInOutLine;
|
||||||
|
import org.compiere.model.MInvoice;
|
||||||
|
import org.compiere.model.MInvoiceLine;
|
||||||
|
import org.compiere.util.Env;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create (Generate) Shipment from Invoice
|
* Create (Generate) Shipment from Invoice
|
||||||
*
|
*
|
||||||
* @author Jorg Janke
|
* @author Jorg Janke
|
||||||
* @version $Id: InvoiceCreateInOut.java,v 1.2 2006/07/30 00:51:02 jjanke Exp $
|
* @version $Id: InvoiceCreateInOut.java,v 1.2 2006/07/30 00:51:02 jjanke Exp $
|
||||||
|
*
|
||||||
|
* @author Teo Sarca, www.arhipac.ro
|
||||||
|
* <li>FR [ 1895317 ] InvoiceCreateInOut: you can create many receipts
|
||||||
*/
|
*/
|
||||||
public class InvoiceCreateInOut extends SvrProcess
|
public class InvoiceCreateInOut extends SvrProcess
|
||||||
{
|
{
|
||||||
|
public static final String PARAM_M_Warehouse_ID = MInOut.COLUMNNAME_M_Warehouse_ID;
|
||||||
|
|
||||||
/** Warehouse */
|
/** Warehouse */
|
||||||
private int p_M_Warehouse_ID = 0;
|
private int p_M_Warehouse_ID = 0;
|
||||||
/** Invoice */
|
/** Invoice */
|
||||||
private int p_C_Invoice_ID = 0;
|
private int p_C_Invoice_ID = 0;
|
||||||
|
/** Receipt */
|
||||||
|
private MInOut m_inout = null;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Prepare - e.g., get Parameters.
|
* Prepare - e.g., get Parameters.
|
||||||
*/
|
*/
|
||||||
protected void prepare()
|
protected void prepare()
|
||||||
{
|
{
|
||||||
ProcessInfoParameter[] para = getParameter();
|
for (ProcessInfoParameter para : getParameter())
|
||||||
for (int i = 0; i < para.length; i++)
|
|
||||||
{
|
{
|
||||||
String name = para[i].getParameterName();
|
String name = para.getParameterName();
|
||||||
if (para[i].getParameter() == null)
|
if (para.getParameter() == null)
|
||||||
;
|
;
|
||||||
else if (name.equals("M_Warehouse_ID"))
|
else if (name.equals(PARAM_M_Warehouse_ID))
|
||||||
p_M_Warehouse_ID = para[i].getParameterAsInt();
|
p_M_Warehouse_ID = para.getParameterAsInt();
|
||||||
else
|
else
|
||||||
log.log(Level.SEVERE, "Unknown Parameter: " + name);
|
log.log(Level.SEVERE, "Unknown Parameter: " + name);
|
||||||
}
|
}
|
||||||
|
@ -61,46 +74,74 @@ public class InvoiceCreateInOut extends SvrProcess
|
||||||
*/
|
*/
|
||||||
protected String doIt () throws Exception
|
protected String doIt () throws Exception
|
||||||
{
|
{
|
||||||
log.info("C_Invoice_ID=" + p_C_Invoice_ID
|
log.info("C_Invoice_ID=" + p_C_Invoice_ID + ", M_Warehouse_ID=" + p_M_Warehouse_ID);
|
||||||
+ ", M_Warehouse_ID=" + p_M_Warehouse_ID);
|
if (p_C_Invoice_ID <= 0)
|
||||||
if (p_C_Invoice_ID == 0)
|
throw new FillMandatoryException("C_Invoice_ID");
|
||||||
throw new IllegalArgumentException("@NotFound@ @C_Invoice_ID@");
|
|
||||||
if (p_M_Warehouse_ID == 0)
|
if (p_M_Warehouse_ID == 0)
|
||||||
throw new IllegalArgumentException("@NotFound@ @M_Warehouse_ID@");
|
throw new FillMandatoryException(PARAM_M_Warehouse_ID);
|
||||||
//
|
//
|
||||||
MInvoice invoice = new MInvoice (getCtx(), p_C_Invoice_ID, null);
|
MInvoice invoice = new MInvoice (getCtx(), p_C_Invoice_ID, null);
|
||||||
if (invoice.get_ID() == 0)
|
if (invoice.get_ID() <= 0)
|
||||||
throw new IllegalArgumentException("@NotFound@ @C_Invoice_ID@");
|
throw new AdempiereException("@NotFound@ @C_Invoice_ID@");
|
||||||
if (!MInvoice.DOCSTATUS_Completed.equals(invoice.getDocStatus()))
|
if (!MInvoice.DOCSTATUS_Completed.equals(invoice.getDocStatus()))
|
||||||
throw new IllegalArgumentException("@InvoiceCreateDocNotCompleted@");
|
throw new AdempiereException("@InvoiceCreateDocNotCompleted@");
|
||||||
//
|
//
|
||||||
MInOut ship = new MInOut (invoice, 0, null, p_M_Warehouse_ID);
|
for (MInvoiceLine invoiceLine : invoice.getLines(false))
|
||||||
if (!ship.save())
|
|
||||||
throw new IllegalArgumentException("@SaveError@ Receipt");
|
|
||||||
//
|
|
||||||
MInvoiceLine[] invoiceLines = invoice.getLines(false);
|
|
||||||
for (int i = 0; i < invoiceLines.length; i++)
|
|
||||||
{
|
{
|
||||||
MInvoiceLine invoiceLine = invoiceLines[i];
|
createLine(invoice, invoiceLine);
|
||||||
MInOutLine sLine = new MInOutLine(ship);
|
|
||||||
sLine.setInvoiceLine(invoiceLine, 0, // Locator
|
|
||||||
invoice.isSOTrx() ? invoiceLine.getQtyInvoiced() : Env.ZERO);
|
|
||||||
sLine.setQtyEntered(invoiceLine.getQtyEntered());
|
|
||||||
sLine.setMovementQty(invoiceLine.getQtyInvoiced());
|
|
||||||
if (invoice.isCreditMemo())
|
|
||||||
{
|
|
||||||
sLine.setQtyEntered(sLine.getQtyEntered().negate());
|
|
||||||
sLine.setMovementQty(sLine.getMovementQty().negate());
|
|
||||||
}
|
|
||||||
if (!sLine.save())
|
|
||||||
throw new IllegalArgumentException("@SaveError@ @M_InOutLine_ID@");
|
|
||||||
//
|
|
||||||
invoiceLine.setM_InOutLine_ID(sLine.getM_InOutLine_ID());
|
|
||||||
if (!invoiceLine.save())
|
|
||||||
throw new IllegalArgumentException("@SaveError@ @C_InvoiceLine_ID@");
|
|
||||||
}
|
}
|
||||||
|
if (m_inout == null)
|
||||||
return ship.getDocumentNo();
|
throw new InvoiceFullyMatchedException();
|
||||||
|
//
|
||||||
|
return m_inout.getDocumentNo();
|
||||||
} // doIt
|
} // doIt
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create Shipment/Receipt header
|
||||||
|
* @param invoice
|
||||||
|
* @return Shipment/Receipt header
|
||||||
|
*/
|
||||||
|
private MInOut getCreateHeader(MInvoice invoice)
|
||||||
|
{
|
||||||
|
if (m_inout != null)
|
||||||
|
return m_inout;
|
||||||
|
m_inout = new MInOut (invoice, 0, null, p_M_Warehouse_ID);
|
||||||
|
m_inout.saveEx();
|
||||||
|
return m_inout;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create shipment/receipt line
|
||||||
|
* @param invoice
|
||||||
|
* @param invoiceLine
|
||||||
|
* @return shipment/receipt line
|
||||||
|
*/
|
||||||
|
private MInOutLine createLine(MInvoice invoice, MInvoiceLine invoiceLine)
|
||||||
|
{
|
||||||
|
BigDecimal qtyMatched = invoiceLine.getMatchedQty();
|
||||||
|
BigDecimal qtyInvoiced = invoiceLine.getQtyInvoiced();
|
||||||
|
BigDecimal qtyNotMatched = qtyInvoiced.subtract(qtyMatched);
|
||||||
|
// If is fully matched don't create anything
|
||||||
|
if (qtyNotMatched.signum() == 0)
|
||||||
|
{
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
MInOut inout = getCreateHeader(invoice);
|
||||||
|
MInOutLine sLine = new MInOutLine(inout);
|
||||||
|
sLine.setInvoiceLine(invoiceLine, 0, // Locator
|
||||||
|
invoice.isSOTrx() ? qtyNotMatched : Env.ZERO);
|
||||||
|
sLine.setQtyEntered(qtyNotMatched);
|
||||||
|
sLine.setMovementQty(qtyNotMatched);
|
||||||
|
if (invoice.isCreditMemo())
|
||||||
|
{
|
||||||
|
sLine.setQtyEntered(sLine.getQtyEntered().negate());
|
||||||
|
sLine.setMovementQty(sLine.getMovementQty().negate());
|
||||||
|
}
|
||||||
|
sLine.saveEx();
|
||||||
|
//
|
||||||
|
invoiceLine.setM_InOutLine_ID(sLine.getM_InOutLine_ID());
|
||||||
|
invoiceLine.saveEx();
|
||||||
|
//
|
||||||
|
return sLine;
|
||||||
|
}
|
||||||
} // InvoiceCreateInOut
|
} // InvoiceCreateInOut
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
-- 08.12.2008 11:38:06 EET
|
||||||
|
-- BF [ 1895317 ] InvoiceCreateInOut: you can create many receipts
|
||||||
|
INSERT INTO AD_Message (AD_Client_ID,AD_Message_ID,AD_Org_ID,Created,CreatedBy,EntityType,IsActive,MsgText,MsgType,Updated,UpdatedBy,Value) VALUES (0,53047,0,TO_DATE('2008-12-08 11:37:49','YYYY-MM-DD HH24:MI:SS'),0,'D','Y','Invoice is fully matched.','E',TO_DATE('2008-12-08 11:37:49','YYYY-MM-DD HH24:MI:SS'),0,'InvoiceFullyMatched')
|
||||||
|
;
|
||||||
|
|
||||||
|
-- 08.12.2008 11:38:07 EET
|
||||||
|
-- BF [ 1895317 ] InvoiceCreateInOut: you can create many receipts
|
||||||
|
INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=53047 AND EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language!=l.AD_Language OR tt.AD_Message_ID!=t.AD_Message_ID)
|
||||||
|
;
|
||||||
|
|
||||||
|
-- 08.12.2008 11:39:11 EET
|
||||||
|
-- BF [ 1895317 ] InvoiceCreateInOut: you can create many receipts
|
||||||
|
UPDATE AD_Message_Trl SET IsTranslated='Y',MsgText='Factura este integral receptionata.',Updated=TO_DATE('2008-12-08 11:39:11','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Message_ID=53047 AND AD_Language='ro_RO'
|
||||||
|
;
|
||||||
|
|
|
@ -0,0 +1,15 @@
|
||||||
|
-- 08.12.2008 11:38:06 EET
|
||||||
|
-- BF [ 1895317 ] InvoiceCreateInOut: you can create many receipts
|
||||||
|
INSERT INTO AD_Message (AD_Client_ID,AD_Message_ID,AD_Org_ID,Created,CreatedBy,EntityType,IsActive,MsgText,MsgType,Updated,UpdatedBy,Value) VALUES (0,53047,0,TO_TIMESTAMP('2008-12-08 11:37:49','YYYY-MM-DD HH24:MI:SS'),0,'D','Y','Invoice is fully matched.','E',TO_TIMESTAMP('2008-12-08 11:37:49','YYYY-MM-DD HH24:MI:SS'),0,'InvoiceFullyMatched')
|
||||||
|
;
|
||||||
|
|
||||||
|
-- 08.12.2008 11:38:07 EET
|
||||||
|
-- BF [ 1895317 ] InvoiceCreateInOut: you can create many receipts
|
||||||
|
INSERT INTO AD_Message_Trl (AD_Language,AD_Message_ID, MsgText,MsgTip, IsTranslated,AD_Client_ID,AD_Org_ID,Created,Createdby,Updated,UpdatedBy) SELECT l.AD_Language,t.AD_Message_ID, t.MsgText,t.MsgTip, 'N',t.AD_Client_ID,t.AD_Org_ID,t.Created,t.Createdby,t.Updated,t.UpdatedBy FROM AD_Language l, AD_Message t WHERE l.IsActive='Y' AND l.IsSystemLanguage='Y' AND l.IsBaseLanguage='N' AND t.AD_Message_ID=53047 AND EXISTS (SELECT * FROM AD_Message_Trl tt WHERE tt.AD_Language!=l.AD_Language OR tt.AD_Message_ID!=t.AD_Message_ID)
|
||||||
|
;
|
||||||
|
|
||||||
|
-- 08.12.2008 11:39:11 EET
|
||||||
|
-- BF [ 1895317 ] InvoiceCreateInOut: you can create many receipts
|
||||||
|
UPDATE AD_Message_Trl SET IsTranslated='Y',MsgText='Factura este integral receptionata.',Updated=TO_TIMESTAMP('2008-12-08 11:39:11','YYYY-MM-DD HH24:MI:SS'),UpdatedBy=0 WHERE AD_Message_ID=53047 AND AD_Language='ro_RO'
|
||||||
|
;
|
||||||
|
|
Loading…
Reference in New Issue