📄 morder.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.model;
import java.io.*;
import java.math.*;
import java.sql.*;
import java.util.*;
import java.util.logging.*;
import org.compiere.print.*;
import org.compiere.process.*;
import org.compiere.util.*;
/**
* Order Model.
* Please do not set DocStatus and C_DocType_ID directly.
* They are set in the process() method.
* Use DocAction and C_DocTypeTarget_ID instead.
*
* @author Jorg Janke
* @version $Id: MOrder.java,v 1.105 2006/01/28 01:28:28 jjanke Exp $
*/
public class MOrder extends X_C_Order implements DocAction
{
/**
* Create new Order by copying
* @param from order
* @param dateDoc date of the document date
* @param C_DocTypeTarget_ID target document type
* @param isSOTrx sales order
* @param counter create counter links
* @param copyASI copy line attributes Attribute Set Instance, Resaouce Assignment
* @param trxName trx
* @return Order
*/
public static MOrder copyFrom (MOrder from, Timestamp dateDoc,
int C_DocTypeTarget_ID, boolean isSOTrx, boolean counter, boolean copyASI,
String trxName)
{
MOrder to = new MOrder (from.getCtx(), 0, trxName);
to.set_TrxName(trxName);
PO.copyValues(from, to, from.getAD_Client_ID(), from.getAD_Org_ID());
to.set_ValueNoCheck ("C_Order_ID", I_ZERO);
to.set_ValueNoCheck ("DocumentNo", null);
//
to.setDocStatus (DOCSTATUS_Drafted); // Draft
to.setDocAction(DOCACTION_Complete);
//
to.setC_DocType_ID(0);
to.setC_DocTypeTarget_ID (C_DocTypeTarget_ID);
to.setIsSOTrx(isSOTrx);
//
to.setIsSelected (false);
to.setDateOrdered (dateDoc);
to.setDateAcct (dateDoc);
to.setDatePromised (dateDoc); // assumption
to.setDatePrinted(null);
to.setIsPrinted (false);
//
to.setIsApproved (false);
to.setIsCreditApproved(false);
to.setC_Payment_ID(0);
to.setC_CashLine_ID(0);
// Amounts are updated when adding lines
to.setGrandTotal(Env.ZERO);
to.setTotalLines(Env.ZERO);
//
to.setIsDelivered(false);
to.setIsInvoiced(false);
to.setIsSelfService(false);
to.setIsTransferred (false);
to.setPosted (false);
to.setProcessed (false);
if (counter)
to.setRef_Order_ID(from.getC_Order_ID());
else
to.setRef_Order_ID(0);
//
if (!to.save(trxName))
throw new IllegalStateException("Could not create Order");
if (counter)
from.setRef_Order_ID(to.getC_Order_ID());
if (to.copyLinesFrom(from, counter, copyASI) == 0)
throw new IllegalStateException("Could not create Order Lines");
return to;
} // copyFrom
/**************************************************************************
* Default Constructor
* @param ctx context
* @param C_Order_ID order to load, (0 create new order)
* @param trxName trx name
*/
public MOrder(Properties ctx, int C_Order_ID, String trxName)
{
super (ctx, C_Order_ID, trxName);
// New
if (C_Order_ID == 0)
{
setDocStatus(DOCSTATUS_Drafted);
setDocAction (DOCACTION_Prepare);
//
setDeliveryRule (DELIVERYRULE_Availability);
setFreightCostRule (FREIGHTCOSTRULE_FreightIncluded);
setInvoiceRule (INVOICERULE_Immediate);
setPaymentRule(PAYMENTRULE_OnCredit);
setPriorityRule (PRIORITYRULE_Medium);
setDeliveryViaRule (DELIVERYVIARULE_Pickup);
//
setIsDiscountPrinted (false);
setIsSelected (false);
setIsTaxIncluded (false);
setIsSOTrx (true);
setIsDropShip(false);
setSendEMail (false);
//
setIsApproved(false);
setIsPrinted(false);
setIsCreditApproved(false);
setIsDelivered(false);
setIsInvoiced(false);
setIsTransferred(false);
setIsSelfService(false);
//
super.setProcessed(false);
setProcessing(false);
setPosted(false);
setDateAcct (new Timestamp(System.currentTimeMillis()));
setDatePromised (new Timestamp(System.currentTimeMillis()));
setDateOrdered (new Timestamp(System.currentTimeMillis()));
setFreightAmt (Env.ZERO);
setChargeAmt (Env.ZERO);
setTotalLines (Env.ZERO);
setGrandTotal (Env.ZERO);
}
} // MOrder
/**************************************************************************
* Project Constructor
* @param project Project to create Order from
* @param DocSubTypeSO if SO DocType Target (default DocSubTypeSO_OnCredit)
*/
public MOrder (MProject project, boolean IsSOTrx, String DocSubTypeSO)
{
this (project.getCtx(), 0, project.get_TrxName());
setAD_Client_ID(project.getAD_Client_ID());
setAD_Org_ID(project.getAD_Org_ID());
setC_Campaign_ID(project.getC_Campaign_ID());
setSalesRep_ID(project.getSalesRep_ID());
//
setC_Project_ID(project.getC_Project_ID());
setDescription(project.getName());
Timestamp ts = project.getDateContract();
if (ts != null)
setDateOrdered (ts);
ts = project.getDateFinish();
if (ts != null)
setDatePromised (ts);
//
setC_BPartner_ID(project.getC_BPartner_ID());
setC_BPartner_Location_ID(project.getC_BPartner_Location_ID());
setAD_User_ID(project.getAD_User_ID());
//
setM_Warehouse_ID(project.getM_Warehouse_ID());
setM_PriceList_ID(project.getM_PriceList_ID());
setC_PaymentTerm_ID(project.getC_PaymentTerm_ID());
//
setIsSOTrx(IsSOTrx);
if (IsSOTrx)
{
if (DocSubTypeSO == null || DocSubTypeSO.length() == 0)
setC_DocTypeTarget_ID(DocSubTypeSO_OnCredit);
else
setC_DocTypeTarget_ID(DocSubTypeSO);
}
else
setC_DocTypeTarget_ID();
} // MOrder
/**
* Load Constructor
* @param ctx context
* @param rs result set record
*/
public MOrder (Properties ctx, ResultSet rs, String trxName)
{
super(ctx, rs, trxName);
} // MOrder
/** Order Lines */
private MOrderLine[] m_lines = null;
/** Tax Lines */
private MOrderTax[] m_taxes = null;
/** Force Creation of order */
private boolean m_forceCreation = false;
/**
* Overwrite Client/Org if required
* @param AD_Client_ID client
* @param AD_Org_ID org
*/
public void setClientOrg (int AD_Client_ID, int AD_Org_ID)
{
super.setClientOrg(AD_Client_ID, AD_Org_ID);
} // setClientOrg
/**
* Add to Description
* @param description text
*/
public void addDescription (String description)
{
String desc = getDescription();
if (desc == null)
setDescription(description);
else
setDescription(desc + " | " + description);
} // addDescription
/**
* Set Business Partner (Ship+Bill)
* @param C_BPartner_ID bpartner
*/
public void setC_BPartner_ID (int C_BPartner_ID)
{
super.setC_BPartner_ID (C_BPartner_ID);
super.setBill_BPartner_ID (C_BPartner_ID);
} // setC_BPartner_ID
/**
* Set Business Partner Location (Ship+Bill)
* @param C_BPartner_Location_ID bp location
*/
public void setC_BPartner_Location_ID (int C_BPartner_Location_ID)
{
super.setC_BPartner_Location_ID (C_BPartner_Location_ID);
super.setBill_Location_ID(C_BPartner_Location_ID);
} // setC_BPartner_Location_ID
/**
* Set Business Partner Contact (Ship+Bill)
* @param AD_User_ID user
*/
public void setAD_User_ID (int AD_User_ID)
{
super.setAD_User_ID (AD_User_ID);
super.setBill_User_ID (AD_User_ID);
} // setAD_User_ID
/**
* Set Ship Business Partner
* @param C_BPartner_ID bpartner
*/
public void setShip_BPartner_ID (int C_BPartner_ID)
{
super.setC_BPartner_ID (C_BPartner_ID);
} // setShip_BPartner_ID
/**
* Set Ship Business Partner Location
* @param C_BPartner_Location_ID bp location
*/
public void setShip_Location_ID (int C_BPartner_Location_ID)
{
super.setC_BPartner_Location_ID (C_BPartner_Location_ID);
} // setShip_Location_ID
/**
* Set Ship Business Partner Contact
* @param AD_User_ID user
*/
public void setShip_User_ID (int AD_User_ID)
{
super.setAD_User_ID (AD_User_ID);
} // setShip_User_ID
/**
* Set Warehouse
* @param M_Warehouse_ID warehouse
*/
public void setM_Warehouse_ID (int M_Warehouse_ID)
{
super.setM_Warehouse_ID (M_Warehouse_ID);
} // setM_Warehouse_ID
/**
* Set Drop Ship
* @param IsDropShip drop ship
*/
public void setIsDropShip (boolean IsDropShip)
{
super.setIsDropShip (IsDropShip);
} // setIsDropShip
/*************************************************************************/
public static final String DocSubTypeSO_Standard = "SO";
public static final String DocSubTypeSO_Quotation = "OB";
public static final String DocSubTypeSO_Proposal = "ON";
public static final String DocSubTypeSO_Prepay = "PR";
public static final String DocSubTypeSO_POS = "WR";
public static final String DocSubTypeSO_Warehouse = "WP";
public static final String DocSubTypeSO_OnCredit = "WI";
public static final String DocSubTypeSO_RMA = "RM";
/**
* Set Target Sales Document Type
* @param DocSubTypeSO_x SO sub type - see DocSubTypeSO_*
*/
public void setC_DocTypeTarget_ID (String DocSubTypeSO_x)
{
String sql = "SELECT C_DocType_ID FROM C_DocType "
+ "WHERE AD_Client_ID=? AND AD_Org_ID IN (0," + getAD_Org_ID()
+ ") AND DocSubTypeSO=? "
+ "ORDER BY AD_Org_ID DESC, IsDefault DESC";
int C_DocType_ID = DB.getSQLValue(null, sql, getAD_Client_ID(), DocSubTypeSO_x);
if (C_DocType_ID <= 0)
log.severe ("Not found for AD_Client_ID=" + getAD_Client_ID () + ", SubType=" + DocSubTypeSO_x);
else
{
log.fine("(SO) - " + DocSubTypeSO_x);
setC_DocTypeTarget_ID (C_DocType_ID);
setIsSOTrx(true);
}
} // setC_DocTypeTarget_ID
/**
* Set Target Document Type.
* Standard Order or PO
*/
public void setC_DocTypeTarget_ID ()
{
if (isSOTrx()) // SO = Std Order
{
setC_DocTypeTarget_ID(DocSubTypeSO_Standard);
return;
}
// PO
String sql = "SELECT C_DocType_ID FROM C_DocType "
+ "WHERE AD_Client_ID=? AND AD_Org_ID IN (0," + getAD_Org_ID()
+ ") AND DocBaseType='POO' "
+ "ORDER BY AD_Org_ID DESC, IsDefault DESC";
int C_DocType_ID = DB.getSQLValue(null, sql, getAD_Client_ID());
if (C_DocType_ID <= 0)
log.severe ("No POO found for AD_Client_ID=" + getAD_Client_ID ());
else
{
log.fine("(PO) - " + C_DocType_ID);
setC_DocTypeTarget_ID (C_DocType_ID);
}
} // setC_DocTypeTarget_ID
/**
* Set Business Partner Defaults & Details.
* SOTrx should be set.
* @param bp business partner
*/
public void setBPartner (MBPartner bp)
{
if (bp == null)
return;
setC_BPartner_ID(bp.getC_BPartner_ID());
// Defaults Payment Term
int ii = 0;
if (isSOTrx())
ii = bp.getC_PaymentTerm_ID();
else
ii = bp.getPO_PaymentTerm_ID();
if (ii != 0)
setC_PaymentTerm_ID(ii);
// Default Price List
if (isSOTrx())
ii = bp.getM_PriceList_ID();
else
ii = bp.getPO_PriceList_ID();
if (ii != 0)
setM_PriceList_ID(ii);
// Default Delivery/Via Rule
String ss = bp.getDeliveryRule();
if (ss != null)
setDeliveryRule(ss);
ss = bp.getDeliveryViaRule();
if (ss != null)
setDeliveryViaRule(ss);
// Default Invoice/Payment Rule
ss = bp.getInvoiceRule();
if (ss != null)
setInvoiceRule(ss);
ss = bp.getPaymentRule();
if (ss != null)
setPaymentRule(ss);
// Sales Rep
ii = bp.getSalesRep_ID();
if (ii != 0)
setSalesRep_ID(ii);
// Set Locations
MBPartnerLocation[] locs = bp.getLocations(false);
if (locs != null)
{
for (int i = 0; i < locs.length; i++)
{
if (locs[i].isShipTo())
super.setC_BPartner_Location_ID(locs[i].getC_BPartner_Location_ID());
if (locs[i].isBillTo())
setBill_Location_ID(locs[i].getC_BPartner_Location_ID());
}
// set to first
if (getC_BPartner_Location_ID() == 0 && locs.length > 0)
super.setC_BPartner_Location_ID(locs[0].getC_BPartner_Location_ID());
if (getBill_Location_ID() == 0 && locs.length > 0)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -