1 14 package org.compiere.model; 15 16 import java.util.*; 17 import java.sql.*; 18 import java.math.*; 19 import java.io.Serializable ; 20 import org.compiere.util.*; 21 22 23 29 public class MInvoiceLine extends X_C_InvoiceLine 30 { 31 36 public MInvoiceLine (Properties ctx, int C_InvoiceLine_ID) 37 { 38 super (ctx, C_InvoiceLine_ID); 39 if (C_InvoiceLine_ID == 0) 40 { 41 setIsDescription(false); 42 setIsPrinted (true); 43 setLineNetAmt (Env.ZERO); 44 setChargeAmt (Env.ZERO); 45 setPriceActual (Env.ZERO); 46 setQtyInvoiced (Env.ZERO); 47 setPriceLimit (Env.ZERO); 48 setPriceList (Env.ZERO); 49 } 50 } 52 58 public MInvoiceLine (MInvoice invoice) 59 { 60 this (invoice.getCtx(), 0); 61 setC_Invoice_ID (invoice.getC_Invoice_ID()); 62 setInvoice(invoice); 63 } 65 66 71 public MInvoiceLine (Properties ctx, ResultSet rs) 72 { 73 super (ctx, rs); 74 } 76 private int m_M_PriceList_ID = 0; 77 private Timestamp m_DateInvoiced = null; 78 private int m_C_BPartner_Location_ID = 0; 79 private boolean m_IsSOTrx = true; 80 private boolean m_priceSet = false; 81 82 83 private String m_name; 84 85 90 public void setInvoice (MInvoice invoice) 91 { 92 setClientOrg(invoice.getAD_Client_ID(), invoice.getAD_Org_ID()); 93 m_M_PriceList_ID = invoice.getM_PriceList_ID(); 94 m_DateInvoiced = invoice.getDateInvoiced(); 95 m_C_BPartner_Location_ID = invoice.getC_BPartner_Location_ID(); 96 m_IsSOTrx = invoice.isSOTrx(); 97 } 99 102 public void setPrice() 103 { 104 if (getM_Product_ID() == 0) 105 return; 106 Log.trace(Log.l4_Data, "MOrderLine.setPrice - M_PriceList_ID=" + m_M_PriceList_ID); 108 MProductPricing pp = new MProductPricing (getM_Product_ID()); 109 pp.setM_PriceList_ID(m_M_PriceList_ID); 110 setPriceActual (pp.getPriceStd()); 111 setPriceList (pp.getPriceList()); 112 setPriceLimit (pp.getPriceLimit()); 113 if (getC_UOM_ID() == 0) 114 setC_UOM_ID(pp.getC_UOM_ID()); 115 m_priceSet = true; 117 } 119 122 public void setTax() 123 { 124 int M_Warehouse_ID = Env.getContextAsInt(getCtx(), "#M_Warehouse_ID"); 125 int ii = Tax.get(getCtx(), getM_Product_ID(), getC_Charge_ID() , m_DateInvoiced, m_DateInvoiced, 126 getAD_Org_ID(), M_Warehouse_ID, 127 m_C_BPartner_Location_ID, m_C_BPartner_Location_ID, m_IsSOTrx); 129 if (ii != 0) 130 setC_Tax_ID (ii); 131 else 132 Log.error("MOrderLine.setTax - No Tax found"); 133 } 135 138 private void setDefaults() 139 { 140 if (!m_priceSet && getPriceActual().intValue() == 0) 142 setPrice(); 143 144 if (getC_Tax_ID() == 0) 146 setTax(); 147 148 if (getLine() == 0) 150 { 151 String sql = "SELECT COALESCE(MAX(Line),0)+10 FROM C_InvoiceLine WHERE C_Invoice_ID=?"; 152 int ii = DB.getSQLValue (sql, getC_Invoice_ID()); 153 setLine (ii); 154 } 155 if (getC_UOM_ID() == 0) 157 setC_UOM_ID (Env.getContextAsInt(getCtx(), "#C_UOM_ID")); 158 159 setLineNetAmt(getPriceActual().multiply(getQtyInvoiced())); 161 } 163 167 public boolean save () 168 { 169 Log.trace (Log.l4_Data, "MInvoiceLine.save"); 170 setDefaults(); 171 return super.save (); 172 } 173 174 public String toString () 175 { 176 StringBuffer sb = new StringBuffer ("MInvoiceLine[") 177 .append(getID()) 178 .append ("]"); 179 return sb.toString (); 180 } 181 182 186 public String getName () 187 { 188 if (m_name == null) 189 { 190 String sql = "SELECT COALESCE (p.Name, c.Name) " 191 + "FROM C_InvoiceLine il" 192 + " LEFT OUTER JOIN M_Product p ON (il.M_Product_ID=p.M_Product_ID)" 193 + " LEFT OUTER JOIN C_Charge C ON (il.C_Charge_ID=c.C_Charge_ID) " 194 + "WHERE C_InvoiceLine_ID=?"; 195 PreparedStatement pstmt = null; 196 try 197 { 198 pstmt = DB.prepareStatement(sql); 199 pstmt.setInt(1, getC_InvoiceLine_ID()); 200 ResultSet rs = pstmt.executeQuery(); 201 if (rs.next()) 202 m_name = rs.getString(1); 203 rs.close(); 204 pstmt.close(); 205 pstmt = null; 206 if (m_name == null) 207 m_name = "??"; 208 } 209 catch (Exception e) 210 { 211 log.error("getName", e); 212 } 213 finally 214 { 215 try 216 { 217 if (pstmt != null) 218 pstmt.close (); 219 } 220 catch (Exception e) 221 {} 222 pstmt = null; 223 } 224 } 225 return m_name; 226 } 228 232 public void setName (String tempName) 233 { 234 m_name = tempName; 235 } 237 } | Popular Tags |