KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > print > MPrintFormat


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2002 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.print;
15
16 import java.util.*;
17 import java.sql.*;
18
19 import org.apache.log4j.Logger;
20
21 import org.compiere.model.*;
22 import org.compiere.util.DB;
23 import org.compiere.util.Env;
24 import org.compiere.util.Msg;
25 import org.compiere.util.Util;
26 import org.compiere.util.CCache;
27 import org.compiere.util.Language;
28
29 /**
30  * AD_PrintFormat - Print Format Model
31  *
32  * @author Jorg Janke
33  * @version $Id: MPrintFormat.java,v 1.34 2003/11/06 07:10:20 jjanke Exp $
34  */

35 public class MPrintFormat extends X_AD_PrintFormat
36 {
37     /**
38      * Private Constructor.
39      * Use static get methods
40      * @param ctx context
41      * @param AD_PrintFormat_ID AD_PrintFormat_ID
42      */

43     private MPrintFormat (Properties ctx, int AD_PrintFormat_ID)
44     {
45         super (ctx, AD_PrintFormat_ID);
46         m_language = Env.getLanguage(ctx);
47         if (AD_PrintFormat_ID == 0)
48         {
49             setStandardHeaderFooter(true);
50             setIsTableBased(true);
51             setIsForm(false);
52             setIsDefault(false);
53         }
54         m_items = getItems();
55     } // MPrintFormat
56

57     /** Items */
58     private MPrintFormatItem[] m_items = null;
59     /** Translation View Language */
60     private String JavaDoc m_translationViewLanguage = null;
61     /** Language of Report */
62     private Language m_language;
63     /** Table Format */
64     private MPrintTableFormat m_tFormat;
65
66     private static Logger s_log = Logger.getLogger (PO.class);
67
68     /**
69      * Get Language
70      * @return language
71      */

72     public Language getLanguage()
73     {
74         return m_language;
75     } // getLanguage
76

77     /**
78      * Set Language
79      * @param language language
80      */

81     public void setLanguage(Language language)
82     {
83         if (language != null)
84             m_language = language;
85         m_translationViewLanguage = null;
86     } // getLanguage
87

88     /**
89      * Get AD_Column_ID of Order Columns
90      * @return Array of AD_Column_IDs in Sort Order
91      */

92     public int[] getOrderAD_Column_IDs()
93     {
94         HashMap map = new HashMap(); // SortNo - AD_Column_ID
95
for (int i = 0; i < m_items.length; i++)
96         {
97             // Sort Order and Column must be > 0
98
if (m_items[i].getSortNo() != 0 && m_items[i].getAD_Column_ID() != 0)
99                 map.put(new Integer JavaDoc(m_items[i].getSortNo()), new Integer JavaDoc(m_items[i].getAD_Column_ID()));
100         }
101         // Get SortNo and Sort them
102
Integer JavaDoc[] keys = new Integer JavaDoc[map.keySet().size()];
103         map.keySet().toArray(keys);
104         Arrays.sort(keys);
105
106         // Create AD_Column_ID array
107
int[] retValue = new int[keys.length];
108         for (int i = 0; i < keys.length; i++)
109         {
110             Integer JavaDoc value = (Integer JavaDoc)map.get(keys[i]);
111             retValue[i] = value.intValue();
112         }
113         return retValue;
114     } // getOrderAD_Column_IDs
115

116     /**
117      * Get AD_Column_IDs of columns in Report
118      * @return Array of AD_Column_ID
119      */

120     public int[] getAD_Column_IDs()
121     {
122         ArrayList list = new ArrayList();
123         for (int i = 0; i < m_items.length; i++)
124         {
125             if (m_items[i].getAD_Column_ID() != 0 && m_items[i].isPrinted())
126                 list.add(new Integer JavaDoc(m_items[i].getAD_Column_ID()));
127         }
128         // Convert
129
int[] retValue = new int[list.size()];
130         for (int i = 0; i < list.size(); i++)
131             retValue[i] = ((Integer JavaDoc)list.get(i)).intValue();
132         return retValue;
133     } // getAD_Column_IDs
134

135     /**
136      * Set Items
137      * @param items items
138      */

139     private void setItems (MPrintFormatItem[] items)
140     {
141         if (items != null)
142             m_items = items;
143     } // setItems
144

145     /**
146      * Get active Items
147      * @return items
148      */

149     private MPrintFormatItem[] getItems()
150     {
151         ArrayList list = new ArrayList();
152         String JavaDoc sql = "SELECT * FROM AD_PrintFormatItem pfi "
153             + "WHERE pfi.AD_PrintFormat_ID=? AND pfi.IsActive='Y'"
154             + " AND NOT EXISTS (SELECT * FROM AD_Column c WHERE pfi.AD_Column_ID=c.AD_Column_ID AND c.ColumnName='Password') "
155             + "ORDER BY SeqNo";
156         MRole role = MRole.getDefault(getCtx(), false);
157         try
158         {
159             PreparedStatement pstmt = DB.prepareStatement(sql);
160             pstmt.setInt(1, getID());
161             ResultSet rs = pstmt.executeQuery();
162             while (rs.next())
163             {
164                 MPrintFormatItem pfi = new MPrintFormatItem(p_ctx, rs);
165                 if (role.isColumnAccess(getAD_Table_ID(), pfi.getAD_Column_ID(), true))
166                     list.add (pfi);
167             }
168             rs.close();
169             pstmt.close();
170         }
171         catch (SQLException e)
172         {
173             log.error("getItems", e);
174         }
175         //
176
MPrintFormatItem[] retValue = new MPrintFormatItem[list.size()];
177         list.toArray(retValue);
178         return retValue;
179     } // getItems
180

181     /**
182      * Get Item Count
183      * @return number of items
184      */

185     public int getItemCount()
186     {
187         return m_items.length;
188     } // getItemCount
189

190     /**
191      * Get Print Format Item
192      * @param index index
193      * @return Print Format Item
194      */

195     public MPrintFormatItem getItem (int index)
196     {
197         if (index < 0 || index >= m_items.length)
198             throw new ArrayIndexOutOfBoundsException JavaDoc("Index=" + index + " - Length=" + m_items.length);
199         return m_items[index];
200     } // getItem
201

202     /**
203      * Set the translation of the Format Items to the original
204      */

205     public void setTranslation()
206     {
207         StringBuffer JavaDoc sb = new StringBuffer JavaDoc ("UPDATE AD_PrintFormatItem_Trl t"
208             + " SET (PrintName, PrintNameSuffix)="
209             + " (SELECT PrintName, PrintNameSuffix FROM AD_PrintFormatItem i WHERE i.AD_PrintFormatItem_ID=t.AD_PrintFormatItem_ID) "
210             + "WHERE AD_PrintFormatItem_ID IN"
211             + " (SELECT AD_PrintFormatItem_ID FROM AD_PrintFormatItem WHERE AD_PrintFormat_ID=").append(getID()).append(")");
212         int no = DB.executeUpdate(sb.toString());
213         log.debug("setTranslation #" + no);
214     } // setTranslation
215

216     /*************************************************************************/
217
218     /**
219      * Set Standard Header
220      * @param standardHeaderFooter true if std header
221      */

222     public void setStandardHeaderFooter (boolean standardHeaderFooter)
223     {
224         super.setIsStandardHeaderFooter(standardHeaderFooter);
225         if (standardHeaderFooter)
226         {
227             setFooterMargin(0);
228             setHeaderMargin(0);
229         }
230     } // setSatndardHeaderFooter
231

232     /**
233      * Set Table based.
234      * Reset Form
235      * @param tableBased true if table based
236      */

237     protected void setIsTableBased (boolean tableBased)
238     {
239         setValueNoCheck("IsTableBased", new Boolean JavaDoc(tableBased));
240         if (tableBased)
241             setIsForm(false);
242     } // setIsTableBased
243

244     /*************************************************************************/
245
246     /**
247      * Set Translation View Language.
248      * @param language language (checked for base language)
249      */

250     public void setTranslationLanguage (Language language)
251     {
252         if (language == null || language.isBaseLanguage())
253         {
254             log.info("setTranslationLanguage - ignored - " + language);
255             m_translationViewLanguage = null;
256         }
257         else
258         {
259             log.info("setTranslationLanguage - " + language.getAD_Language());
260             m_translationViewLanguage = language.getAD_Language();
261             m_language = language;
262         }
263     } // setTranslationLanguage
264

265     /**
266      * Get Translation View use
267      * @return true if a translation view is used
268      */

269     public boolean isTranslationView()
270     {
271         return m_translationViewLanguage != null;
272     } // isTranslationView
273

274     /**
275      * Update the Query to access the Translation View.
276      * Can be called multiple times, adds only if not set already
277      * @param query query to be updated
278      */

279     public void setTranslationViewQuery (MQuery query)
280     {
281         // Set Table Name and add add restriction, if a view and language set
282
if (m_translationViewLanguage != null && query != null && query.getTableName().toUpperCase().endsWith("_V"))
283         {
284             query.setTableName(query.getTableName() + "t");
285             query.addRestriction("AD_Language", MQuery.EQUAL, m_translationViewLanguage);
286         }
287     } // setTranslationViewQuery
288

289     /*************************************************************************/
290
291     /**
292      * Get Optional TableFormat
293      * @param AD_PrintTableFormat_ID table format
294      */

295     public void setAD_PrintTableFormat_ID (int AD_PrintTableFormat_ID)
296     {
297         super.setAD_PrintTableFormat_ID(AD_PrintTableFormat_ID);
298         m_tFormat = MPrintTableFormat.get (AD_PrintTableFormat_ID, getAD_PrintFont_ID());
299     } // getAD_PrintTableFormat_ID
300

301     /**
302      * Get Table Format
303      * @return Table Format
304      */

305     public MPrintTableFormat getTableFormat()
306     {
307         if (m_tFormat == null)
308             m_tFormat = MPrintTableFormat.get(getAD_PrintTableFormat_ID(), getAD_PrintFont_ID());
309         return m_tFormat;
310     } // getTableFormat
311

312     /**
313      * Sting Representation
314      * @return info
315      */

316     public String JavaDoc toString()
317     {
318         StringBuffer JavaDoc sb = new StringBuffer JavaDoc ("MPrintFormat[").append(getID())
319             .append(",").append(getName())
320             .append("]");
321         return sb.toString();
322     } // toString
323

324     /*************************************************************************/
325
326     /**
327      * Load Special data (images, ..).
328      * To be extended by sub-classes
329      * @param rs result set
330      * @param index zero based index
331      * @return value value
332      * @throws SQLException
333      */

334     protected Object JavaDoc loadSpecial (ResultSet rs, int index) throws SQLException
335     {
336         // CreateCopy
337
// Log.trace(Log.l4_Data, "MPrintFormat.loadSpecial", p_info.getColumnName(index));
338
return null;
339     } // loadSpecial
340

341     /**
342      * Save Special Data.
343      * To be extended by sub-classes
344      * @param value value
345      * @param index index
346      * @return SQL code for INSERT VALUES clause
347      */

348     protected String JavaDoc saveNewSpecial (Object JavaDoc value, int index)
349     {
350         // CreateCopy
351
// String colName = p_info.getColumnName(index);
352
// String colClass = p_info.getColumnClass(index).toString();
353
// String colValue = value == null ? "null" : value.getClass().toString();
354
// Log.error("PO.saveNewSpecial - Unknown class for column " + colName + " (" + colClass + ") - Value=" + colValue);
355
if (value == null)
356             return "NULL";
357         return value.toString();
358     } // saveNewSpecial
359

360
361     /*************************************************************************/
362
363     /**
364      * Create MPrintFormat for Table
365      * @param ctx context
366      * @param AD_Table_ID table
367      * @return print format
368      */

369     static public MPrintFormat createFromTable (Properties ctx, int AD_Table_ID)
370     {
371         return createFromTable(ctx, AD_Table_ID, 0);
372     } // createFromTable
373

374     /**
375      * Create MPrintFormat for Table
376      * @param ctx context
377      * @param AD_Table_ID table
378      * @param AD_PrintFormat_ID 0 or existing PrintFormat
379      * @return print format
380      */

381     static public MPrintFormat createFromTable (Properties ctx, int AD_Table_ID, int AD_PrintFormat_ID)
382     {
383         int AD_Client_ID = Env.getContextAsInt (ctx, "#AD_Client_ID");
384         s_log.info ("createFromTable - AD_Table_ID=" + AD_Table_ID + " - AD_Client_ID=" + AD_Client_ID);
385
386         MPrintFormat pf = new MPrintFormat(ctx, AD_PrintFormat_ID);
387         pf.setValueNoCheck("AD_Table_ID", new Integer JavaDoc(AD_Table_ID));
388
389         // Get Info
390
String JavaDoc sql = "SELECT TableName," // 1
391
+ " (SELECT COUNT(*) FROM AD_PrintFormat x WHERE x.AD_Table_ID=t.AD_Table_ID AND x.AD_Client_ID=c.AD_Client_ID) AS Count,"
392             + " COALESCE (cpc.AD_PrintColor_ID, pc.AD_PrintColor_ID) AS AD_PrintColor_ID," // 3
393
+ " COALESCE (cpf.AD_PrintFont_ID, pf.AD_PrintFont_ID) AS AD_PrintFont_ID,"
394             + " COALESCE (cpp.AD_PrintPaper_ID, pp.AD_PrintPaper_ID) AS AD_PrintPaper_ID "
395             + "FROM AD_Table t, AD_Client c"
396             + " LEFT OUTER JOIN AD_PrintColor cpc ON (cpc.AD_Client_ID=c.AD_Client_ID AND cpc.IsDefault='Y')"
397             + " LEFT OUTER JOIN AD_PrintFont cpf ON (cpf.AD_Client_ID=c.AD_Client_ID AND cpf.IsDefault='Y')"
398             + " LEFT OUTER JOIN AD_PrintPaper cpp ON (cpp.AD_Client_ID=c.AD_Client_ID AND cpp.IsDefault='Y'),"
399             + " AD_PrintColor pc, AD_PrintFont pf, AD_PrintPaper pp "
400             + "WHERE t.AD_Table_ID=? AND c.AD_Client_ID=?" // #1/2
401
+ " AND pc.IsDefault='Y' AND pf.IsDefault='Y' AND pp.IsDefault='Y'";
402         boolean error = true;
403         try
404         {
405             PreparedStatement pstmt = DB.prepareStatement(sql);
406             pstmt.setInt(1, AD_Table_ID);
407             pstmt.setInt(2, AD_Client_ID);
408             ResultSet rs = pstmt.executeQuery();
409             if (rs.next())
410             {
411                 // Name
412
String JavaDoc TableName = rs.getString(1);
413                 String JavaDoc ColumnName = TableName + "_ID";
414                 String JavaDoc s = ColumnName;
415                 if (!ColumnName.equals("T_Report_ID"))
416                 {
417                     s = Msg.translate (ctx, ColumnName);
418                     if (ColumnName.equals (s)) // not found
419
s = Msg.translate (ctx, TableName);
420                 }
421                 int count = rs.getInt(2);
422                 if (count > 0)
423                     s += " " + count;
424                 pf.setName(s);
425                 //
426
pf.setAD_PrintColor_ID(rs.getInt(3));
427                 pf.setAD_PrintFont_ID(rs.getInt(4));
428                 pf.setAD_PrintPaper_ID(rs.getInt(5));
429                 //
430
error = false;
431             }
432             else
433                 s_log.error("createFromTable - no info found " + AD_Table_ID);
434             rs.close();
435             pstmt.close();
436         }
437         catch (SQLException e)
438         {
439             s_log.error("createFromTable", e);
440         }
441         if (error)
442             return null;
443
444         // Save & complete
445
if (!pf.save())
446             return null;
447     // pf.dump();
448
pf.setItems (createItems(ctx, pf));
449         //
450
return pf;
451     } // createFromTable
452

453     /**
454      * Create MPrintFormat for ReportView
455      * @param ctx context
456      * @param AD_ReportView_ID ReportView
457      * @param ReportName - optional Report Name
458      * @return print format
459      */

460     static public MPrintFormat createFromReportView (Properties ctx, int AD_ReportView_ID, String JavaDoc ReportName)
461     {
462         int AD_Client_ID = Env.getContextAsInt (ctx, "#AD_Client_ID");
463         s_log.info ("createFromReportView - AD_ReportView_ID=" + AD_ReportView_ID + " - AD_Client_ID=" + AD_Client_ID + " - " + ReportName);
464
465         MPrintFormat pf = new MPrintFormat(ctx, 0);
466         pf.setValueNoCheck("AD_ReportView_ID", new Integer JavaDoc(AD_ReportView_ID));
467
468         // Get Info
469
String JavaDoc sql = "SELECT t.TableName,"
470             + " (SELECT COUNT(*) FROM AD_PrintFormat x WHERE x.AD_ReportView_ID=rv.AD_ReportView_ID AND x.AD_Client_ID=c.AD_Client_ID) AS Count,"
471             + " COALESCE (cpc.AD_PrintColor_ID, pc.AD_PrintColor_ID) AS AD_PrintColor_ID,"
472             + " COALESCE (cpf.AD_PrintFont_ID, pf.AD_PrintFont_ID) AS AD_PrintFont_ID,"
473             + " COALESCE (cpp.AD_PrintPaper_ID, pp.AD_PrintPaper_ID) AS AD_PrintPaper_ID,"
474             + " t.AD_Table_ID "
475             + "FROM AD_ReportView rv"
476             + " INNER JOIN AD_Table t ON (rv.AD_Table_ID=t.AD_Table_ID),"
477             + " AD_Client c"
478             + " LEFT OUTER JOIN AD_PrintColor cpc ON (cpc.AD_Client_ID=c.AD_Client_ID AND cpc.IsDefault='Y')"
479             + " LEFT OUTER JOIN AD_PrintFont cpf ON (cpf.AD_Client_ID=c.AD_Client_ID AND cpf.IsDefault='Y')"
480             + " LEFT OUTER JOIN AD_PrintPaper cpp ON (cpp.AD_Client_ID=c.AD_Client_ID AND cpp.IsDefault='Y'),"
481             + " AD_PrintColor pc, AD_PrintFont pf, AD_PrintPaper pp "
482             + "WHERE rv.AD_ReportView_ID=? AND c.AD_Client_ID=?"
483             + " AND pc.IsDefault='Y' AND pf.IsDefault='Y' AND pp.IsDefault='Y'";
484         boolean error = true;
485         try
486         {
487             PreparedStatement pstmt = DB.prepareStatement(sql);
488             pstmt.setInt(1, AD_ReportView_ID);
489             pstmt.setInt(2, AD_Client_ID);
490             ResultSet rs = pstmt.executeQuery();
491             if (rs.next())
492             {
493                 // Name
494
String JavaDoc name = ReportName;
495             // String TableName = rs.getString(1);
496
int count = rs.getInt(2);
497                 if (count > 0)
498                     name += " " + count;
499                 pf.setName(name);
500                 //
501
pf.setAD_PrintColor_ID(rs.getInt(3));
502                 pf.setAD_PrintFont_ID(rs.getInt(4));
503                 pf.setAD_PrintPaper_ID(rs.getInt(5));
504                 //
505
pf.setValueNoCheck("AD_Table_ID", new Integer JavaDoc(rs.getInt(6)));
506                 error = false;
507             }
508             else
509                 s_log.error("createFromReportView - no info found " + AD_ReportView_ID);
510             rs.close();
511             pstmt.close();
512         }
513         catch (SQLException e)
514         {
515             s_log.error("createFromReportView", e);
516         }
517         if (error)
518             return null;
519
520         // Save & complete
521
if (!pf.save())
522             return null;
523     // pf.dump();
524
pf.setItems (createItems(ctx, pf));
525         //
526
return pf;
527     } // createFromReportView
528

529
530     /**
531      * Create Items.
532      * Using the display order of Fields in some Tab
533      * @param ctx context
534      * @param format print format
535      * @return items
536      */

537     static private MPrintFormatItem[] createItems (Properties ctx, MPrintFormat format)
538     {
539         s_log.info ("createItems");
540         ArrayList list = new ArrayList();
541         String JavaDoc sql = "SELECT c.AD_Column_ID "
542             + "FROM AD_Column c"
543             + " LEFT OUTER JOIN AD_Tab tab ON (c.AD_Table_ID=tab.AD_Table_ID AND tab.AD_Tab_ID=(SELECT AD_Tab_ID FROM AD_Tab tt WHERE tt.AD_Table_ID=c.AD_Table_ID AND ROWNUM=1))"
544             + " LEFT OUTER JOIN AD_Field f ON (tab.AD_Tab_ID=f.AD_Tab_ID AND c.AD_Column_ID=f.AD_Column_ID) "
545             + "WHERE c.AD_Table_ID=?"
546             + " AND c.ColumnName<>'Password' "
547             + "ORDER BY f.SeqNo, c.Name";
548         try
549         {
550             PreparedStatement pstmt = DB.prepareStatement(sql);
551             pstmt.setInt(1, format.getAD_Table_ID());
552             ResultSet rs = pstmt.executeQuery();
553             int seqNo = 1;
554             while (rs.next())
555             {
556                 MPrintFormatItem pfi = MPrintFormatItem.createFromColumn (ctx, rs.getInt(1), format, seqNo++);
557                 if (pfi != null)
558                     list.add (pfi);
559             }
560             rs.close();
561             pstmt.close();
562         }
563         catch (SQLException e)
564         {
565             s_log.error("getItems", e);
566         }
567         //
568
MPrintFormatItem[] retValue = new MPrintFormatItem[list.size()];
569         list.toArray(retValue);
570         return retValue;
571     } // createItems
572

573     /**
574      * Copy Items
575      * @param fromFormat from print format
576      * @param toFormat to print format (client, id)
577      * @return items
578      */

579     static private MPrintFormatItem[] copyItems (MPrintFormat fromFormat, MPrintFormat toFormat)
580     {
581         s_log.info("copyItems - from " + fromFormat);
582         ArrayList list = new ArrayList();
583
584         MPrintFormatItem[] items = fromFormat.getItems();
585         for (int i = 0; i < items.length; i++)
586         {
587             MPrintFormatItem pfi = items[i].copyToClient (toFormat.getAD_Client_ID(), toFormat.getID());
588             if (pfi != null)
589                 list.add (pfi);
590         }
591         //
592
MPrintFormatItem[] retValue = new MPrintFormatItem[list.size()];
593         list.toArray(retValue);
594         return retValue;
595     } // copyItems
596

597     /*************************************************************************/
598
599     /**
600      * Copy existing Definition To Client
601      * @param ctx context
602      * @param from_AD_PrintFormat_ID format
603      * @param to_AD_PrintFormat_ID format
604      * @return print format
605      */

606     public static MPrintFormat copy (Properties ctx, int from_AD_PrintFormat_ID, int to_AD_PrintFormat_ID)
607     {
608         return copy (ctx, from_AD_PrintFormat_ID, to_AD_PrintFormat_ID, -1);
609     }
610
611     /**
612      * Copy existing Definition To Client
613      * @param ctx context
614      * @param AD_PrintFormat_ID format
615      * @param To_Client_ID to client
616      * @return print format
617      */

618     public static MPrintFormat copyToClient (Properties ctx, int AD_PrintFormat_ID, int To_Client_ID)
619     {
620         return copy (ctx, AD_PrintFormat_ID, 0, To_Client_ID);
621     }
622
623     /**
624      * Copy existing Definition To Client
625      * @param ctx context
626      * @param from_AD_PrintFormat_ID format
627      * @param to_AD_PrintFormat_ID to format
628      * @param to_Client_ID to client (ignored, if to_AD_PrintFormat_ID <> 0)
629      * @return print format
630      */

631     private static MPrintFormat copy (Properties ctx, int from_AD_PrintFormat_ID,
632         int to_AD_PrintFormat_ID, int to_Client_ID)
633     {
634         s_log.info ("copyToClient - From_AD_PrintFormat_ID=" + from_AD_PrintFormat_ID
635             + ", To_AD_PrintFormat_ID=" + to_AD_PrintFormat_ID + ", To_Client_ID=" + to_Client_ID);
636         if (from_AD_PrintFormat_ID == 0)
637             throw new IllegalArgumentException JavaDoc ("MPrintFormat.copyToClient - from_AD_PrintFormat_ID is 0");
638         //
639
MPrintFormat from = new MPrintFormat(ctx, from_AD_PrintFormat_ID);
640         MPrintFormat to = new MPrintFormat (ctx, to_AD_PrintFormat_ID); // could be 0
641
MPrintFormat.copyValues (from, to);
642         // New
643
if (to_AD_PrintFormat_ID == 0)
644         {
645             to.setValueNoCheck ("AD_Client_ID", new Integer JavaDoc(to_Client_ID));
646             to.setValueNoCheck ("AD_Org_ID", new Integer JavaDoc(0));
647         }
648         // Remove TEMPLATE - add copy
649
to.setName(Util.replace(to.getName(), "TEMPLATE", String.valueOf(to_Client_ID)));
650         to.setName(to.getName() + " " + Msg.getMsg(ctx, "Copy"));
651         //
652
to.save();
653
654         // Copy Items
655
to.setItems(copyItems(from,to));
656         return to;
657     } // copyToClient
658

659     /*************************************************************************/
660
661     /** Cached Formats */
662     static private CCache s_formats = new CCache("printFormat", 30);
663
664     /**
665      * Get Format from disk
666      * @param AD_PrintFormat_ID id
667      * @return Format
668      */

669     static public MPrintFormat get (int AD_PrintFormat_ID)
670     {
671         return new MPrintFormat (Env.getCtx(), AD_PrintFormat_ID);
672     } // get
673

674     /**
675      * Get Format
676      * @param AD_PrintFormat_ID id
677      * @param readFromDisk refresh from disk
678      * @return Format
679      */

680     static public MPrintFormat get (int AD_PrintFormat_ID, boolean readFromDisk)
681     {
682         Integer JavaDoc key = new Integer JavaDoc(AD_PrintFormat_ID);
683         MPrintFormat pf = null;
684         if (!readFromDisk)
685             pf = (MPrintFormat)s_formats.get(key);
686         if (pf == null)
687         {
688             pf = new MPrintFormat (Env.getCtx(), AD_PrintFormat_ID);
689             s_formats.put(key, pf);
690         }
691         return pf;
692     } // get
693

694     /**
695      * Delete Format from Cache
696      * @param AD_PrintFormat_ID id
697      */

698     static public void deleteFromCache (int AD_PrintFormat_ID)
699     {
700         Integer JavaDoc key = new Integer JavaDoc(AD_PrintFormat_ID);
701         s_formats.put(key, null);
702     } // get
703

704     /*************************************************************************/
705
706     /**
707      * Test
708      * @param args arga
709      */

710     static public void main (String JavaDoc[] args)
711     {
712         org.compiere.Compiere.startupClient();
713         /**
714         MPrintFormat.createFromTable(Env.getCtx(), 496); // Order
715         MPrintFormat.createFromTable(Env.getCtx(), 497);
716         MPrintFormat.createFromTable(Env.getCtx(), 516); // Invoice
717         MPrintFormat.createFromTable(Env.getCtx(), 495);
718         MPrintFormat.createFromTable(Env.getCtx(), 500); // Shipment
719         MPrintFormat.createFromTable(Env.getCtx(), 501);
720
721         MPrintFormat.createFromTable(Env.getCtx(), 498); // Check
722         MPrintFormat.createFromTable(Env.getCtx(), 499);
723         MPrintFormat.createFromTable(Env.getCtx(), 498); // Remittance
724         **/

725     } // main
726

727
728 } // MPrintFormat
729
Popular Tags