--- /dev/null
+/*******************************************************************************
+ * Copyright � Igor Barma, Alexandre Desoubeaux, Christian Martel, Eric Brun, Mathieu Amblard, Gwenael Gevet, Pierre Guillot, 2012
+ * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Alexandre Lefevre, Marc Salvat 2014-2016
+ * Copyright Alexandre Desoubeaux, Christian Martel, Cedric Lecarpentier, Marc Salvat, Marc Suarez, Harifetra Ramamonjy 2017
+ *
+ * This file is part of the work and learning management system Pentila Nero.
+ *
+ * Pentila Nero is free software. You can redistribute it and/or modify since
+ * you respect the terms of either (at least one of the both license) :
+ * - under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ * - the CeCILL-C as published by CeCILL-C; either version 1 of the
+ * License, or any later version
+ * - the GNU Lesser General Public License as published by the
+ * Free Software Foundation, either version 3 of the license,
+ * or (at your option) any later version.
+ *
+ * There are special exceptions to the terms and conditions of the
+ * licenses as they are applied to this software. View the full text of
+ * the exception in file LICENSE-PROJECT.txt in the directory of this software
+ * distribution.
+ *
+ * Pentila Nero 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
+ * Licenses for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * and the CeCILL-C and the GNU Lesser General Public License along with
+ * Pentila Nero. If not, see :
+ * <http://www.gnu.org/licenses/> and
+ * <http://www.cecill.info/licences.fr.html>.
+ ******************************************************************************/
+package com.pentila.entSavoie.portlets.cantine.util;
+
+import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.StringReader;
+import java.net.URL;
+import java.text.ParseException;
+import java.text.SimpleDateFormat;
+import java.util.ArrayList;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.GregorianCalendar;
+import java.util.List;
+import java.util.Locale;
+
+import javax.naming.NamingException;
+
+import jxl.CellView;
+import jxl.Workbook;
+import jxl.WorkbookSettings;
+import jxl.format.Alignment;
+import jxl.format.Border;
+import jxl.format.BorderLineStyle;
+import jxl.format.Colour;
+import jxl.format.ScriptStyle;
+import jxl.format.UnderlineStyle;
+import jxl.format.VerticalAlignment;
+import jxl.write.Label;
+import jxl.write.WritableCellFormat;
+import jxl.write.WritableFont;
+import jxl.write.WritableSheet;
+import jxl.write.WritableWorkbook;
+
+import com.itextpdf.text.BaseColor;
+import com.itextpdf.text.Document;
+import com.itextpdf.text.Element;
+import com.itextpdf.text.Font;
+import com.itextpdf.text.FontFactory;
+import com.itextpdf.text.PageSize;
+import com.itextpdf.text.Paragraph;
+import com.itextpdf.text.Phrase;
+import com.itextpdf.text.html.simpleparser.HTMLWorker;
+import com.itextpdf.text.html.simpleparser.StyleSheet;
+import com.itextpdf.text.pdf.BaseFont;
+import com.itextpdf.text.pdf.PdfPCell;
+import com.itextpdf.text.pdf.PdfPTable;
+import com.itextpdf.text.pdf.PdfWriter;
+import com.liferay.portal.kernel.json.JSONArray;
+import com.liferay.portal.kernel.json.JSONObject;
+import com.liferay.portal.kernel.util.FileUtil;
+import com.liferay.portal.kernel.util.HtmlUtil;
+import com.liferay.portal.model.Organization;
+import com.liferay.portal.model.User;
+import com.liferay.portal.theme.ThemeDisplay;
+import com.pentila.entSavoie.ENTDisplayUtil;
+import com.pentila.entSavoie.cantine.model.CantineCategorieRecette;
+import com.pentila.entSavoie.cantine.model.CantineDatePlanAlimentaire;
+import com.pentila.entSavoie.cantine.model.CantineMenu;
+import com.pentila.entSavoie.cantine.model.CantinePlanAlimentaire;
+import com.pentila.entSavoie.cantine.model.CantinePlanAlimentaireConfiguration;
+import com.pentila.entSavoie.cantine.model.CantineRecette;
+import com.pentila.entSavoie.cantine.service.CantineCategorieRecetteLocalServiceUtil;
+import com.pentila.entSavoie.cantine.service.CantineDatePlanAlimentaireLocalServiceUtil;
+import com.pentila.entSavoie.cantine.service.CantineMenuLocalServiceUtil;
+import com.pentila.entSavoie.cantine.service.CantinePlanAlimentaireConfigurationLocalServiceUtil;
+import com.pentila.entSavoie.cantine.service.CantinePlanAlimentaireLocalServiceUtil;
+import com.pentila.entSavoie.cantine.service.CantineRecetteLocalServiceUtil;
+import com.pentila.entSavoie.directory.OrganizationFinderServiceUtil;
+
+public class ExportUtil {
+
+ static SimpleDateFormat classicDateFormat = new SimpleDateFormat("yyyy-MM-dd");
+ static SimpleDateFormat frenchDateFormat = new SimpleDateFormat("dd/MM/yyyy");
+ static SimpleDateFormat frenchDateFormatString = new SimpleDateFormat("EEEE dd MMM yyyy", Locale.FRENCH);
+
+ //Export de la feuille de controle au format XLS
+ public static byte[] exportFeuilleControleXLS(long planAlimentaireId, String fileName, JSONArray contraintes, User user) throws NamingException, Exception {
+
+ Organization etab = OrganizationFinderServiceUtil.getEtabRatachement(user);
+
+ String dateIntervalle = " du ";
+
+ CantinePlanAlimentaire cpa = CantinePlanAlimentaireLocalServiceUtil.getCantinePlanAlimentaire(planAlimentaireId);
+ List<CantineDatePlanAlimentaire> lcdpa = CantineDatePlanAlimentaireLocalServiceUtil.getCantineDatePlanAlimentaireByPlanAlimentaireId(planAlimentaireId);
+ dateIntervalle += frenchDateFormat.format(lcdpa.get(0).getDate()) + " au ";
+ dateIntervalle += frenchDateFormat.format(lcdpa.get(lcdpa.size() - 1).getDate());
+
+ File file = FileUtil.createTempFile("xls");
+
+ WorkbookSettings wbSettings = new WorkbookSettings();
+ wbSettings.setLocale(new Locale("en", "EN"));
+
+ WritableWorkbook workbook = Workbook.createWorkbook(file, wbSettings);
+ workbook.createSheet("Feuille de contr\u00f4le", 0);
+ workbook.createSheet("Configuration des cat\u00e9gories", 1);
+ workbook.createSheet("Liste des menus", 2);
+ workbook.setColourRGB(Colour.RED, 244, 78, 78);
+ workbook.setColourRGB(Colour.LIGHT_GREEN, 117, 226, 80);
+ workbook.setColourRGB(Colour.GREY_50_PERCENT, 151, 151, 151);
+
+ WritableSheet excelSheet = workbook.getSheet(0);
+
+ WritableFont times14ptHeaderPrincipal = new WritableFont(WritableFont.TIMES, 14, WritableFont.BOLD);
+ WritableCellFormat times14HeaderPrincipal = new WritableCellFormat(times14ptHeaderPrincipal);
+ times14HeaderPrincipal.setBorder(Border.ALL, BorderLineStyle.NONE);
+ times14HeaderPrincipal.setAlignment(Alignment.LEFT);
+ times14HeaderPrincipal.setVerticalAlignment(VerticalAlignment.CENTRE);
+
+ // Ajout du titre principal --> merge de toutes les colonnes
+ excelSheet.addCell(new Label(0, 0, cpa.getNomPlan() + dateIntervalle, times14HeaderPrincipal));
+ excelSheet.mergeCells(0, 0, 7, 0);
+
+ excelSheet.addCell(new Label(0, 1, ENTDisplayUtil.formatSCONETName(user, etab.getName()), times14HeaderPrincipal));
+ excelSheet.mergeCells(0, 1, 7, 1);
+
+ excelSheet.addCell(new Label(0, 2, "Feuille de contr\u00f4le", times14HeaderPrincipal));
+ excelSheet.mergeCells(0, 2, 7, 2);
+
+ WritableFont times13pt = new WritableFont(WritableFont.TIMES, 13, WritableFont.BOLD);
+
+ WritableCellFormat times13 = new WritableCellFormat(times13pt);
+ times13.setBorder(Border.ALL, BorderLineStyle.HAIR);
+ times13.setAlignment(Alignment.CENTRE);
+ times13.setVerticalAlignment(VerticalAlignment.CENTRE);
+ times13.setBackground(Colour.PALE_BLUE);
+ times13.setWrap(true);
+
+ WritableFont times12pt = new WritableFont(WritableFont.TIMES, 12);
+
+ WritableCellFormat times12Left = new WritableCellFormat(times12pt);
+ times12Left.setBorder(Border.ALL, BorderLineStyle.HAIR);
+ times12Left.setVerticalAlignment(VerticalAlignment.TOP);
+ times12Left.setWrap(true);
+
+ WritableCellFormat times12 = new WritableCellFormat(times12pt);
+ times12.setBorder(Border.ALL, BorderLineStyle.HAIR);
+ times12.setAlignment(Alignment.CENTRE);
+ times12.setVerticalAlignment(VerticalAlignment.TOP);
+ times12Left.setWrap(true);
+
+ WritableCellFormat times12Grey = new WritableCellFormat(times12pt);
+ times12Grey.setBorder(Border.ALL, BorderLineStyle.HAIR);
+ times12Grey.setAlignment(Alignment.CENTRE);
+ times12Grey.setVerticalAlignment(VerticalAlignment.TOP);
+ times12Grey.setBackground(Colour.GREY_25_PERCENT);
+ times12Grey.setWrap(true);
+
+ WritableCellFormat times12Green = new WritableCellFormat(times12pt);
+ times12Green.setBorder(Border.ALL, BorderLineStyle.HAIR);
+ times12Green.setAlignment(Alignment.CENTRE);
+ times12Green.setVerticalAlignment(VerticalAlignment.TOP);
+ times12Green.setBackground(Colour.LIGHT_GREEN);
+ times12Green.setWrap(true);
+
+ WritableCellFormat times12Red = new WritableCellFormat(times12pt);
+ times12Red.setBorder(Border.ALL, BorderLineStyle.HAIR);
+ times12Red.setAlignment(Alignment.CENTRE);
+ times12Red.setVerticalAlignment(VerticalAlignment.TOP);
+ times12Red.setBackground(Colour.RED);
+ times12Red.setWrap(true);
+
+ CellView cv = new CellView();
+ cv.setSize(150000);
+ excelSheet.setColumnView(0, cv);
+
+ //On passe les colonnes en autoResize
+ CellView cv2 = new CellView();
+ cv2.setSize(3800);
+ for(int i=1;i<=7;i++){
+ excelSheet.setColumnView(i, cv2);
+ }
+
+ //On ajoute les headers bien formatés correctement
+ excelSheet.addCell(new Label(0, 4, "Contrainte", times13));
+ excelSheet.addCell(new Label(1, 4, "Entr\u00e9e", times13));
+ excelSheet.addCell(new Label(2, 4, "Plat protidique", times13));
+ excelSheet.addCell(new Label(3, 4, "Garniture", times13));
+ excelSheet.addCell(new Label(4, 4, "Produit Laitier", times13));
+ excelSheet.addCell(new Label(5, 4, "Dessert", times13));
+ excelSheet.addCell(new Label(6, 4, "Fr\u00e9quence recommand\u00e9e", times13));
+ excelSheet.addCell(new Label(7, 4, "Contr\u00f4le", times13));
+
+
+ int row = 5;
+ for(int i=0; i<contraintes.length(); i++){
+ JSONObject contrainte = contraintes.getJSONObject(i);
+
+ //On rempli le fichier avec les infos
+ excelSheet.addCell(new Label(0, row, contrainte.getString("libelleGemrcn"), times12Left));
+ excelSheet.addCell(new Label(1, row, HtmlUtil.extractText(contrainte.getString("nbEntree")), contrainte.getString("nbEntree").isEmpty()?times12Grey:times12));
+ excelSheet.addCell(new Label(2, row, HtmlUtil.extractText(contrainte.getString("nbPlat")), contrainte.getString("nbPlat").isEmpty()?times12Grey:times12));
+ excelSheet.addCell(new Label(3, row, HtmlUtil.extractText(contrainte.getString("nbGarniture")), contrainte.getString("nbGarniture").isEmpty()?times12Grey:times12));
+ excelSheet.addCell(new Label(4, row, HtmlUtil.extractText(contrainte.getString("nbLait")), contrainte.getString("nbLait").isEmpty()?times12Grey:times12));
+ excelSheet.addCell(new Label(5, row, HtmlUtil.extractText(contrainte.getString("nbDessert")), contrainte.getString("nbDessert").isEmpty()?times12Grey:times12));
+ excelSheet.addCell(new Label(6, row, HtmlUtil.extractText(contrainte.getString("frequence")), times12));
+ excelSheet.addCell(new Label(7, row, HtmlUtil.extractText(contrainte.getString("freqGlobal")), contrainte.getBoolean("controle")?times12Green:times12Red));
+
+ row++;
+ }
+
+ /*
+ * Definition des nouvelles couleurs
+ */
+ workbook.setColourRGB(Colour.DARK_RED, 255, 51, 0); // FF3300
+ workbook.setColourRGB(Colour.DARK_BLUE, 0, 123, 184); // 007BB8
+ workbook.setColourRGB(Colour.BROWN, 102, 0, 0); // 660000
+ workbook.setColourRGB(Colour.DARK_GREEN, 51, 153, 102); // 339966
+ workbook.setColourRGB(Colour.GREEN, 102, 204, 0); // 66CC00
+
+
+ /*
+ * Definition des nouvelles font
+ */
+ WritableFont times13ptNoBold = new WritableFont(WritableFont.TIMES, 13, WritableFont.NO_BOLD);
+ WritableCellFormat times13Header = new WritableCellFormat(times13ptNoBold);
+ times13Header.setBorder(Border.ALL, BorderLineStyle.HAIR);
+ times13Header.setAlignment(Alignment.CENTRE);
+ times13Header.setVerticalAlignment(VerticalAlignment.CENTRE);
+ times13Header.setWrap(true);
+
+ WritableCellFormat times13HeaderGRAY = new WritableCellFormat(times13pt);
+ times13HeaderGRAY.setBorder(Border.ALL, BorderLineStyle.HAIR);
+ times13HeaderGRAY.setAlignment(Alignment.CENTRE);
+ times13HeaderGRAY.setVerticalAlignment(VerticalAlignment.CENTRE);
+ times13HeaderGRAY.setWrap(true);
+ times13HeaderGRAY.setBackground(Colour.GREY_50_PERCENT);
+
+ WritableFont times12ptBLACK = new WritableFont(WritableFont.TIMES, 13, WritableFont.BOLD);
+ WritableCellFormat times12BLACK = new WritableCellFormat(times12ptBLACK);
+ times12BLACK.setBorder(Border.ALL, BorderLineStyle.HAIR);
+ times12BLACK.setAlignment(Alignment.CENTRE);
+ times12BLACK.setVerticalAlignment(VerticalAlignment.TOP);
+ times12BLACK.setWrap(true);
+
+ WritableFont times12ptDARK_RED = new WritableFont(WritableFont.TIMES, 13, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.DARK_RED, ScriptStyle.NORMAL_SCRIPT);
+ WritableCellFormat times12DARK_RED = new WritableCellFormat(times12ptDARK_RED);
+ times12DARK_RED.setBorder(Border.ALL, BorderLineStyle.HAIR);
+ times12DARK_RED.setAlignment(Alignment.CENTRE);
+ times12DARK_RED.setVerticalAlignment(VerticalAlignment.TOP);
+ times12DARK_RED.setWrap(true);
+
+ WritableFont times12ptDARK_BLUE = new WritableFont(WritableFont.TIMES, 13, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.DARK_BLUE, ScriptStyle.NORMAL_SCRIPT);
+ WritableCellFormat times12DARK_BLUE = new WritableCellFormat(times12ptDARK_BLUE);
+ times12DARK_BLUE.setBorder(Border.ALL, BorderLineStyle.HAIR);
+ times12DARK_BLUE.setAlignment(Alignment.CENTRE);
+ times12DARK_BLUE.setVerticalAlignment(VerticalAlignment.TOP);
+ times12DARK_BLUE.setWrap(true);
+
+ WritableFont times12ptBROWN = new WritableFont(WritableFont.TIMES, 13, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.BROWN, ScriptStyle.NORMAL_SCRIPT);
+ WritableCellFormat times12BROWN = new WritableCellFormat(times12ptBROWN);
+ times12BROWN.setBorder(Border.ALL, BorderLineStyle.HAIR);
+ times12BROWN.setAlignment(Alignment.CENTRE);
+ times12BROWN.setVerticalAlignment(VerticalAlignment.TOP);
+ times12BROWN.setWrap(true);
+
+ WritableFont times12ptDARK_GREEN = new WritableFont(WritableFont.TIMES, 13, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.DARK_GREEN, ScriptStyle.NORMAL_SCRIPT);
+ WritableCellFormat times12DARK_GREEN = new WritableCellFormat(times12ptDARK_GREEN);
+ times12DARK_GREEN.setBorder(Border.ALL, BorderLineStyle.HAIR);
+ times12DARK_GREEN.setAlignment(Alignment.CENTRE);
+ times12DARK_GREEN.setVerticalAlignment(VerticalAlignment.TOP);
+ times12DARK_GREEN.setWrap(true);
+
+ WritableFont times12ptGREEN = new WritableFont(WritableFont.TIMES, 13, WritableFont.BOLD, false, UnderlineStyle.NO_UNDERLINE, Colour.GREEN, ScriptStyle.NORMAL_SCRIPT);
+ WritableCellFormat times12GREEN = new WritableCellFormat(times12ptGREEN);
+ times12GREEN.setBorder(Border.ALL, BorderLineStyle.HAIR);
+ times12GREEN.setAlignment(Alignment.CENTRE);
+ times12GREEN.setVerticalAlignment(VerticalAlignment.TOP);
+ times12GREEN.setWrap(true);
+
+ /*
+ * Configuration du plan alimentaire
+ */
+ WritableSheet excelSheet1 = workbook.getSheet(1);
+
+ // Ajout du titre principal --> merge de toutes les colonnes
+ excelSheet1.addCell(new Label(0, 0, cpa.getNomPlan() + dateIntervalle, times14HeaderPrincipal));
+ excelSheet1.mergeCells(0, 0, 5, 0);
+
+ excelSheet1.addCell(new Label(0, 1, ENTDisplayUtil.formatSCONETName(user, etab.getName()), times14HeaderPrincipal));
+ excelSheet1.mergeCells(0, 1, 5, 1);
+
+ excelSheet1.addCell(new Label(0, 2, "Configuration des cat\u00e9gories", times14HeaderPrincipal));
+ excelSheet1.mergeCells(0, 2, 5, 2);
+
+ //On passe les colonnes en autoResize
+ CellView cv3 = new CellView();
+ cv3.setAutosize(true);
+ for(int i=0;i<=5;i++){
+ excelSheet1.setColumnView(i, cv3);
+ }
+
+ int colDate = 1;
+ int rowToStart = 4;
+ excelSheet1.addCell(new Label(0, rowToStart, "", times13HeaderGRAY));
+ for(CantineDatePlanAlimentaire cdpa: lcdpa){
+
+ if(colDate>5){
+ colDate = 1;
+ rowToStart = row;
+ excelSheet1.addCell(new Label(0, rowToStart, "", times13HeaderGRAY));
+ }
+
+ row = rowToStart;
+ excelSheet1.addCell(new Label(colDate, row, frenchDateFormat.format(cdpa.getDate()), times13Header));
+ row++;
+
+ for(int i=0; i<CantineUtil.steps.size(); i++){
+
+ excelSheet1.addCell(new Label(0, row, (CantineUtil.getTypeLibelle(CantineUtil.steps.get(i+1)).replace("é", "\u00e9")), times13Header));
+
+ List<CantinePlanAlimentaireConfiguration> lcpac = CantinePlanAlimentaireConfigurationLocalServiceUtil.getCantinePlanAlimentaireConfigurationByCantineDatePlanAlimentaireId_TypeRecette(cdpa.getCantineDatePlanAlimentaireId(), CantineUtil.steps.get(i+1));
+ if(lcpac.size() == 0){
+ excelSheet1.addCell(new Label(colDate, row, "", times12));
+ } else if(lcpac.size() == 1){
+ for(CantinePlanAlimentaireConfiguration cpac: lcpac){
+ CantineCategorieRecette ccr = CantineCategorieRecetteLocalServiceUtil.getCantineCategorieRecette(cpac.getCategorieRecetteId());
+ String color = ccr.getCouleurCategorie();
+ if(color.equals("FF3300")){
+ excelSheet1.addCell(new Label(colDate, row, ccr.getNomCategorie(), times12DARK_RED));
+ } else if(color.equals("007BB8")){
+ excelSheet1.addCell(new Label(colDate, row, ccr.getNomCategorie(), times12DARK_BLUE));
+ } else if(color.equals("660000")){
+ excelSheet1.addCell(new Label(colDate, row, ccr.getNomCategorie(), times12BROWN));
+ } else if(color.equals("339966")){
+ excelSheet1.addCell(new Label(colDate, row, ccr.getNomCategorie(), times12DARK_GREEN));
+ } else if(color.equals("66CC00")){
+ excelSheet1.addCell(new Label(colDate, row, ccr.getNomCategorie(), times12GREEN));
+ } else {
+ excelSheet1.addCell(new Label(colDate, row, ccr.getNomCategorie(), times12BLACK));
+ }
+ }
+ }
+ // Pas plus d'une couleur par cellule
+ else {
+ String categs = "";
+ for(CantinePlanAlimentaireConfiguration cpac: lcpac){
+ CantineCategorieRecette ccr = CantineCategorieRecetteLocalServiceUtil.getCantineCategorieRecette(cpac.getCategorieRecetteId());
+ categs += ccr.getNomCategorie();
+
+ String color = ccr.getCouleurCategorie();
+ if(color.equals("FF3300")){
+ categs += " (ROUGE)";
+ } else if(color.equals("007BB8")){
+ categs += " (BLEU)";
+ } else if(color.equals("660000")){
+ categs += " (MARRON)";
+ } else if(color.equals("339966")){
+ categs += " (VERT FONCE)";
+ } else if(color.equals("66CC00")){
+ categs += " (VERT)";
+ }
+
+ categs += "\n";
+ }
+
+ categs = categs.substring(0, categs.lastIndexOf("\n"));
+ excelSheet1.addCell(new Label(colDate, row, categs, times12BLACK));
+ }
+
+ row++;
+ }
+
+ colDate++;
+ }
+
+ /*
+ * Ajout des Menus
+ */
+ WritableSheet excelSheet2 = workbook.getSheet(2);
+
+ // Ajout du titre principal --> merge de toutes les colonnes
+ excelSheet2.addCell(new Label(0, 0, cpa.getNomPlan() + dateIntervalle, times14HeaderPrincipal));
+ excelSheet2.mergeCells(0, 0, 5, 0);
+
+ excelSheet2.addCell(new Label(0, 1, ENTDisplayUtil.formatSCONETName(user, etab.getName()), times14HeaderPrincipal));
+ excelSheet2.mergeCells(0, 1, 5, 1);
+
+ excelSheet2.addCell(new Label(0, 2, "Liste des menus", times14HeaderPrincipal));
+ excelSheet2.mergeCells(0, 2, 5, 2);
+
+ //On passe les colonnes en autoResize
+ CellView cv4 = new CellView();
+ cv4.setAutosize(true);
+ for(int i=0;i<=5;i++){
+ excelSheet2.setColumnView(i, cv4);
+ }
+
+ colDate = 1;
+ rowToStart = 4;
+ excelSheet2.addCell(new Label(0, rowToStart, "", times13HeaderGRAY));
+ for(CantineDatePlanAlimentaire cdpa: lcdpa){
+
+ if(colDate>5){
+ colDate = 1;
+ rowToStart = row;
+ excelSheet2.addCell(new Label(0, rowToStart, "", times13HeaderGRAY));
+ }
+
+ row = rowToStart;
+ excelSheet2.addCell(new Label(colDate, row, frenchDateFormat.format(cdpa.getDate()), times13Header));
+ row++;
+
+ for(int i=0; i<CantineUtil.steps.size(); i++){
+
+ excelSheet2.addCell(new Label(0, row, (CantineUtil.getTypeLibelle(CantineUtil.steps.get(i+1)).replace("é", "\u00e9")), times13Header));
+
+ List<CantineMenu> lcm = CantineMenuLocalServiceUtil.getCantineMenuByCantineDatePlanAlimentaireId_TypeRecette(cdpa.getCantineDatePlanAlimentaireId(), CantineUtil.steps.get(i+1));
+ if(lcm.size() == 0){
+ excelSheet2.addCell(new Label(colDate, row, "", times12));
+ } else if(lcm.size() == 1){
+ for(CantineMenu cm: lcm){
+ CantineRecette cr = CantineRecetteLocalServiceUtil.getCantineRecette(cm.getRecetteId());
+ CantineCategorieRecette ccr = CantineCategorieRecetteLocalServiceUtil.getCantineCategorieRecette(cr.getCategorieRecetteId());
+ String color = ccr.getCouleurCategorie();
+ if(color.equals("FF3300")){
+ excelSheet2.addCell(new Label(colDate, row, cr.getTitreRecette(), times12DARK_RED));
+ } else if(color.equals("007BB8")){
+ excelSheet2.addCell(new Label(colDate, row, cr.getTitreRecette(), times12DARK_BLUE));
+ } else if(color.equals("660000")){
+ excelSheet2.addCell(new Label(colDate, row, cr.getTitreRecette(), times12BROWN));
+ } else if(color.equals("339966")){
+ excelSheet2.addCell(new Label(colDate, row, cr.getTitreRecette(), times12DARK_GREEN));
+ } else if(color.equals("66CC00")){
+ excelSheet2.addCell(new Label(colDate, row, cr.getTitreRecette(), times12GREEN));
+ } else {
+ excelSheet2.addCell(new Label(colDate, row, cr.getTitreRecette(), times12BLACK));
+ }
+ }
+ }
+ // Pas plus d'une couleur par cellule
+ else {
+ String menus = "";
+ for(CantineMenu cm: lcm){
+
+ CantineRecette cr = CantineRecetteLocalServiceUtil.getCantineRecette(cm.getRecetteId());
+ CantineCategorieRecette ccr = CantineCategorieRecetteLocalServiceUtil.getCantineCategorieRecette(cr.getCategorieRecetteId());
+
+ menus += cr.getTitreRecette();
+
+ String color = ccr.getCouleurCategorie();
+ if(color.equals("FF3300")){
+ menus += " (ROUGE)";
+ } else if(color.equals("007BB8")){
+ menus += " (BLEU)";
+ } else if(color.equals("660000")){
+ menus += " (MARRON)";
+ } else if(color.equals("339966")){
+ menus += " (VERT FONCE)";
+ } else if(color.equals("66CC00")){
+ menus += " (VERT)";
+ }
+
+ menus += "\n";
+ }
+
+ menus = menus.substring(0, menus.lastIndexOf("\n"));
+ excelSheet2.addCell(new Label(colDate, row, menus, times12BLACK));
+ }
+
+
+
+ row++;
+ }
+
+ colDate++;
+ }
+
+ workbook.write();
+ workbook.close();
+
+ return FileUtil.getBytes(file);
+
+ }
+
+ //Export de la feuille de controle au format PDF
+ public static byte[] exportFeuilleControlePDF(long planAlimentaireId, String fileName, JSONArray contraintes, User user) throws NamingException, Exception {
+
+ Organization etab = OrganizationFinderServiceUtil.getEtabRatachement(user);
+
+ String dateIntervalle = " du ";
+
+ CantinePlanAlimentaire cpa = CantinePlanAlimentaireLocalServiceUtil.getCantinePlanAlimentaire(planAlimentaireId);
+ List<CantineDatePlanAlimentaire> lcdpa = CantineDatePlanAlimentaireLocalServiceUtil.getCantineDatePlanAlimentaireByPlanAlimentaireId(planAlimentaireId);
+ dateIntervalle += frenchDateFormat.format(lcdpa.get(0).getDate()) + " au ";
+ dateIntervalle += frenchDateFormat.format(lcdpa.get(lcdpa.size() - 1).getDate());
+
+ FontFactory.register("com/pentila/entSavoie/portlets/cantine/util/LiberationMono-Regular.ttf", "exportFont");
+ Document document = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);
+ ByteArrayOutputStream b = new ByteArrayOutputStream();
+ PdfWriter.getInstance(document, b);
+
+ document.addAuthor(user.getFullName());
+ document.addTitle(fileName);
+ document.addSubject(fileName);
+ document.addCreationDate();
+ document.setMargins(5, 5, 5, 5);
+
+ //styleSheets
+ StyleSheet mystyle = new StyleSheet();
+
+ // Ouverture du document
+ document.open();
+
+ String planTitle = "<div align='center' style='font-size:16px;'><b><u>Feuille de contr\u00f4le</u></b></div><br /><br />";
+ planTitle += "<div style='font-size:14px;'><b> Plan : </b>" + cpa.getNomPlan() + dateIntervalle + "</div>";
+ planTitle += "<div style='font-size:14px;'><b> Etablissement : </b>" + ENTDisplayUtil.formatSCONETName(user, etab.getName()) + "</div><br />";
+
+ Paragraph plan = new Paragraph();
+ StringReader planSR = new StringReader(planTitle);
+ ArrayList planList = HTMLWorker.parseToList(planSR, mystyle);
+ for (int k = 0; k < planList.size(); ++k){
+ plan.add((Element)planList.get(k));
+ }
+ planSR.close();
+ document.add(plan);
+
+ float[] colsWidth = {7f, 1f, 1f, 1f, 1f, 1f, 1f, 1f}; // Code 1
+ PdfPTable table = new PdfPTable(colsWidth);
+ table.setWidthPercentage(95);
+
+ Font font = FontFactory.getFont("Arial", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10, Font.NORMAL);
+ font.setStyle(Font.BOLD);
+
+ PdfPCell cell = new PdfPCell(new Phrase("Contraintes", font));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ table.addCell(cell);
+
+ cell = new PdfPCell(new Phrase("Entr\u00e9e", font));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ table.addCell(cell);
+
+ cell = new PdfPCell(new Phrase("Plat Protidique", font));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ table.addCell(cell);
+
+ cell = new PdfPCell(new Phrase("Garniture", font));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ table.addCell(cell);
+
+ cell = new PdfPCell(new Phrase("Produit Laitier", font));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ table.addCell(cell);
+
+ cell = new PdfPCell(new Phrase("Dessert", font));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ table.addCell(cell);
+
+ cell = new PdfPCell(new Phrase("Fr\u00e9quence recommand\u00e9e", font));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ table.addCell(cell);
+
+ cell = new PdfPCell(new Phrase("Contr\u00f4le", font));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ table.addCell(cell);
+
+ Font font10 = FontFactory.getFont("Arial", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10, Font.NORMAL);
+
+ for(int i=0; i<contraintes.length(); i++){
+ JSONObject contrainte = contraintes.getJSONObject(i);
+
+ cell = new PdfPCell(new Phrase(contrainte.getString("libelleGemrcn"),font10));
+ cell.setHorizontalAlignment(Element.ALIGN_LEFT);
+ table.addCell(cell);
+
+ cell = new PdfPCell(new Phrase(HtmlUtil.extractText(contrainte.getString("nbEntree")), font10));
+ if(contrainte.getString("nbEntree").isEmpty()){
+ cell.setBackgroundColor(BaseColor.GRAY);
+ }
+ cell.setHorizontalAlignment(Element.ALIGN_LEFT);
+ table.addCell(cell);
+
+ cell = new PdfPCell(new Phrase(HtmlUtil.extractText(contrainte.getString("nbPlat")), font10));
+ if(contrainte.getString("nbPlat").isEmpty()){
+ cell.setBackgroundColor(BaseColor.GRAY);
+ }
+ cell.setHorizontalAlignment(Element.ALIGN_LEFT);
+ table.addCell(cell);
+
+ cell = new PdfPCell(new Phrase(HtmlUtil.extractText(contrainte.getString("nbGarniture")), font10));
+ if(contrainte.getString("nbGarniture").isEmpty()){
+ cell.setBackgroundColor(BaseColor.GRAY);
+ }
+ cell.setHorizontalAlignment(Element.ALIGN_LEFT);
+ table.addCell(cell);
+
+ cell = new PdfPCell(new Phrase(HtmlUtil.extractText(contrainte.getString("nbLait")), font10));
+ if(contrainte.getString("nbLait").isEmpty()){
+ cell.setBackgroundColor(BaseColor.GRAY);
+ }
+ cell.setHorizontalAlignment(Element.ALIGN_LEFT);
+ table.addCell(cell);
+
+ cell = new PdfPCell(new Phrase(HtmlUtil.extractText(contrainte.getString("nbDessert")), font10));
+ if(contrainte.getString("nbDessert").isEmpty()){
+ cell.setBackgroundColor(BaseColor.GRAY);
+ }
+ cell.setHorizontalAlignment(Element.ALIGN_LEFT);
+ table.addCell(cell);
+
+ cell = new PdfPCell(new Phrase(contrainte.getString("frequence"), font10));
+ cell.setHorizontalAlignment(Element.ALIGN_LEFT);
+ table.addCell(cell);
+
+ Paragraph freq = new Paragraph();
+ StringReader freqSR = new StringReader(contrainte.getString("freqGlobal"));
+ ArrayList freqList = HTMLWorker.parseToList(freqSR, mystyle);
+ for (int k = 0; k < freqList.size(); ++k){
+ freq.add((Element)freqList.get(k));
+ }
+ freqSR.close();
+ cell = new PdfPCell(new Phrase(freq));
+ if(contrainte.getBoolean("controle")){
+ cell.setBackgroundColor(BaseColor.GREEN);
+ } else {
+ cell.setBackgroundColor(BaseColor.RED);
+ } cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ table.addCell(cell);
+
+ }
+
+ document.add(table);
+
+ // Fermeture le document
+ document.close();
+
+ byte[] result = b.toByteArray();
+ b.close();
+
+ return result;
+ }
+
+ //Methodes d'export des menus
+ //Export au format semaine
+ public static byte[] exportMenuWeek(String fileName, Date date, User user, boolean isMidi, boolean isSoir, boolean isAll, ThemeDisplay themeDisplay) throws NamingException, Exception {
+
+ String year = classicDateFormat.format(date).substring(0, 4);
+ String month = classicDateFormat.format(date).substring(5, 7);
+ String day = classicDateFormat.format(date).substring(8, 10);
+
+ Calendar fistDayCalendar = GregorianCalendar.getInstance();
+ fistDayCalendar.set(Integer.parseInt(year), Integer.parseInt(month)-1, Integer.parseInt(day));
+ //On se place sur le premier jour de la semaine
+ while(fistDayCalendar.get(Calendar.DAY_OF_WEEK) != Calendar.MONDAY){
+ fistDayCalendar.add(Calendar.DATE, -1);
+ }
+
+ Calendar lastDayCalendar = GregorianCalendar.getInstance();
+ lastDayCalendar.set(Integer.parseInt(year), Integer.parseInt(month)-1, Integer.parseInt(day));
+ //On se place sur le dernier jour de la semaine
+ while(lastDayCalendar.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY){
+ lastDayCalendar.add(Calendar.DATE, 1);
+ }
+
+ FontFactory.register("com/pentila/entSavoie/portlets/cantine/util/LiberationMono-Regular.ttf", "exportFont");
+ Document document = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);
+ ByteArrayOutputStream b = new ByteArrayOutputStream();
+ PdfWriter.getInstance(document, b);
+
+ document.addAuthor(user.getFullName());
+ document.addTitle(fileName);
+ document.addSubject(fileName);
+ document.addCreationDate();
+ document.setMargins(25, 25, 25, 25);
+
+ //styleSheets
+ StyleSheet mystyle = new StyleSheet();
+
+ // Ouverture du document
+ document.open();
+
+ //Midi
+ if(isMidi){
+
+ String menuTitle = "<div align='center' style='font-size:16px;'><b><u>MENU du MIDI du " + frenchDateFormat.format(fistDayCalendar.getTime()) + " au " + frenchDateFormat.format(lastDayCalendar.getTime()) + "</u></b></div><br /><br />";
+
+ Paragraph title = new Paragraph();
+ StringReader titleMenu = new StringReader(menuTitle);
+ ArrayList titleList = HTMLWorker.parseToList(titleMenu, mystyle);
+ for (int k = 0; k < titleList.size(); ++k){
+ title.add((Element)titleList.get(k));
+ }
+ titleMenu.close();
+ document.add(title);
+ PdfPTable table = createMenuForWeek(PortletPropsValues.ENT_CANTINE_PLAN_TYPE_MIDI, fistDayCalendar, user, themeDisplay);
+ document.add(table);
+
+ }
+ //Soir
+ else if(isSoir){
+
+ String menuTitle = "<div align='center' style='font-size:16px;'><b><u>MENU du SOIR du " + frenchDateFormat.format(fistDayCalendar.getTime()) + " au " + frenchDateFormat.format(lastDayCalendar.getTime()) + "</u></b></div><br /><br />";
+
+ Paragraph title = new Paragraph();
+ StringReader titleMenu = new StringReader(menuTitle);
+ ArrayList titleList = HTMLWorker.parseToList(titleMenu, mystyle);
+ for (int k = 0; k < titleList.size(); ++k){
+ title.add((Element)titleList.get(k));
+ }
+ titleMenu.close();
+ document.add(title);
+ PdfPTable table = createMenuForWeek(PortletPropsValues.ENT_CANTINE_PLAN_TYPE_SOIR, fistDayCalendar, user, themeDisplay);
+ document.add(table);
+ }
+ //Les 2
+ else if(isAll){
+
+ //Midi
+ String menuTitle = "<div align='center' style='font-size:16px;'><b><u>MENU du MIDI du " + frenchDateFormat.format(fistDayCalendar.getTime()) + " au " + frenchDateFormat.format(lastDayCalendar.getTime()) + "</u></b></div><br /><br />";
+ Paragraph title = new Paragraph();
+ StringReader titleMenu = new StringReader(menuTitle);
+ ArrayList titleList = HTMLWorker.parseToList(titleMenu, mystyle);
+ for (int k = 0; k < titleList.size(); ++k){
+ title.add((Element)titleList.get(k));
+ }
+ titleMenu.close();
+ document.add(title);
+
+ PdfPTable tableMidi = createMenuForWeek(PortletPropsValues.ENT_CANTINE_PLAN_TYPE_MIDI, fistDayCalendar, user, themeDisplay);
+ document.add(tableMidi);
+ document.newPage();
+
+ //On se replace sur le premier jour
+ fistDayCalendar.add(Calendar.DATE, -6);
+
+ //Soir
+ String menuTitleSoir = "<div align='center' style='font-size:16px;'><b><u>MENU du SOIR du " + frenchDateFormat.format(fistDayCalendar.getTime()) + " au " + frenchDateFormat.format(lastDayCalendar.getTime()) + "</u></b></div><br /><br />";
+ Paragraph titleSoir = new Paragraph();
+ StringReader titleMenuSoir = new StringReader(menuTitleSoir);
+ ArrayList titleSoirList = HTMLWorker.parseToList(titleMenuSoir, mystyle);
+ for (int k = 0; k < titleSoirList.size(); ++k){
+ titleSoir.add((Element)titleSoirList.get(k));
+ }
+ titleMenuSoir.close();
+ document.add(titleSoir);
+ PdfPTable tableSoir = createMenuForWeek(PortletPropsValues.ENT_CANTINE_PLAN_TYPE_SOIR, fistDayCalendar, user, themeDisplay);
+ document.add(tableSoir);
+ }
+
+ // Fermeture le document
+ document.close();
+
+ byte[] result = b.toByteArray();
+ b.close();
+
+ return result;
+ }
+
+ public static PdfPTable createMenuForWeek(int type, Calendar fistDayCalendar, User user, ThemeDisplay themeDisplay) throws NamingException, Exception{
+
+
+ List<String> entrees = new ArrayList<String>();
+ List<String> plats = new ArrayList<String>();
+ List<String> garnitures = new ArrayList<String>();
+ List<String> fromages = new ArrayList<String>();
+ List<String> desserts = new ArrayList<String>();
+
+ boolean incrementDay = false;
+
+ boolean hasLundi = false;
+ boolean hasMardi = false;
+ boolean hasMercredi = false;
+ boolean hasJeudi = false;
+ boolean hasVendredi = false;
+ boolean hasSamedi = false;
+ boolean hasDimanche = false;
+
+ int nbDay = 0;
+
+ //Recuperation des menus
+ do{
+ if (incrementDay){
+ fistDayCalendar.add(Calendar.DATE, 1);
+ }
+
+ Date date = fistDayCalendar.getTime();
+ String dateFormat = classicDateFormat.format(date);
+ Date d = new Date();
+ try {
+ d = classicDateFormat.parse(dateFormat);
+ } catch (ParseException e) {
+ System.out.println("ParseException createMenuForWeek l.1877");
+ }
+
+ List<CantineDatePlanAlimentaire> lCantineDatePlanAlimentaires = CantineDatePlanAlimentaireLocalServiceUtil.getCantineDatePlanAlimentaireByEtabId_Date(OrganizationFinderServiceUtil.getEtabRatachement(user).getOrganizationId(), d);
+ String menuEntree = "";
+ String menuPlat = "";
+ String menuGarniture = "";
+ String menuLait = "";
+ String menuDessert = "";
+
+ if(lCantineDatePlanAlimentaires.size()>0){
+
+ //Pour savoir s'il y a des menus du type courant
+ boolean hasMenu = false;
+
+ //Formater les menus correctements
+ for(CantineDatePlanAlimentaire cdpa: lCantineDatePlanAlimentaires){
+ CantinePlanAlimentaire cpa = CantinePlanAlimentaireLocalServiceUtil.getCantinePlanAlimentaire(cdpa.getPlanAlimentaireId());
+ if(cpa.getType() == type){
+ hasMenu = true;
+
+ //On recupere les entrees
+ List<CantineMenu> lcmEntree = CantineMenuLocalServiceUtil.getCantineMenuByCantineDatePlanAlimentaireId_TypeRecette(cdpa.getCantineDatePlanAlimentaireId(), PortletPropsValues.ENT_CANTINE_BANQUE_ENTREE);
+ for(CantineMenu cm: lcmEntree){
+ CantineRecette cr = CantineRecetteLocalServiceUtil.getCantineRecette(cm.getRecetteId());
+ menuEntree += cr.getTitreRecette() + "<br />";
+ }
+
+ //On recupere les plats
+ List<CantineMenu> lcmPlat = CantineMenuLocalServiceUtil.getCantineMenuByCantineDatePlanAlimentaireId_TypeRecette(cdpa.getCantineDatePlanAlimentaireId(), PortletPropsValues.ENT_CANTINE_BANQUE_PLAT);
+ for(CantineMenu cm: lcmPlat){
+ CantineRecette cr = CantineRecetteLocalServiceUtil.getCantineRecette(cm.getRecetteId());
+ menuPlat += cr.getTitreRecette() + "<br />";
+ }
+
+ //On recupere les garnitures
+ List<CantineMenu> lcmGarniture = CantineMenuLocalServiceUtil.getCantineMenuByCantineDatePlanAlimentaireId_TypeRecette(cdpa.getCantineDatePlanAlimentaireId(), PortletPropsValues.ENT_CANTINE_BANQUE_GARNITURE);
+ for(CantineMenu cm: lcmGarniture){
+ CantineRecette cr = CantineRecetteLocalServiceUtil.getCantineRecette(cm.getRecetteId());
+ menuGarniture += cr.getTitreRecette() + "<br />";
+ }
+
+ //On recupere les fromages
+ List<CantineMenu> lcmFromage = CantineMenuLocalServiceUtil.getCantineMenuByCantineDatePlanAlimentaireId_TypeRecette(cdpa.getCantineDatePlanAlimentaireId(), PortletPropsValues.ENT_CANTINE_BANQUE_LAIT);
+ for(CantineMenu cm: lcmFromage){
+ CantineRecette cr = CantineRecetteLocalServiceUtil.getCantineRecette(cm.getRecetteId());
+ menuLait += cr.getTitreRecette() + "<br />";
+ }
+
+ //On recupere les desserts
+ List<CantineMenu> lcmDessert = CantineMenuLocalServiceUtil.getCantineMenuByCantineDatePlanAlimentaireId_TypeRecette(cdpa.getCantineDatePlanAlimentaireId(), PortletPropsValues.ENT_CANTINE_BANQUE_DESSERT);
+ for(CantineMenu cm: lcmDessert){
+ CantineRecette cr = CantineRecetteLocalServiceUtil.getCantineRecette(cm.getRecetteId());
+ menuDessert += cr.getTitreRecette() + "<br />";
+ }
+ }
+ }
+
+ if(menuEntree.contains("<br />")){
+ menuEntree = menuEntree.substring(0, menuEntree.lastIndexOf("<br />"));
+ }
+ entrees.add(menuEntree);
+
+ if(menuPlat.contains("<br />")){
+ menuPlat = menuPlat.substring(0, menuPlat.lastIndexOf("<br />"));
+ }
+ plats.add(menuPlat);
+
+ if(menuGarniture.contains("<br />")){
+ menuGarniture = menuGarniture.substring(0, menuGarniture.lastIndexOf("<br />"));
+ }
+ garnitures.add(menuGarniture);
+
+ if(menuLait.contains("<br />")){
+ menuLait = menuLait.substring(0, menuLait.lastIndexOf("<br />"));
+ }
+ fromages.add(menuLait);
+
+ if(menuDessert.contains("<br />")){
+ menuDessert = menuDessert.substring(0, menuDessert.lastIndexOf("<br />"));
+ }
+ desserts.add(menuDessert);
+
+ if(hasMenu){
+ if (fistDayCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.MONDAY){
+ hasLundi = true;
+ } else if(fistDayCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.TUESDAY){
+ hasMardi = true;
+ } else if(fistDayCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.WEDNESDAY){
+ hasMercredi = true;
+ } else if(fistDayCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.THURSDAY){
+ hasJeudi = true;
+ } else if(fistDayCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.FRIDAY){
+ hasVendredi = true;
+ } else if(fistDayCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.SATURDAY){
+ hasSamedi = true;
+ } else if(fistDayCalendar.get(Calendar.DAY_OF_WEEK) == Calendar.SUNDAY){
+ hasDimanche = true;
+ }
+ }
+ nbDay++;
+ }
+
+ incrementDay = true;
+
+ } while(fistDayCalendar.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY);
+
+
+ //styleSheets
+ StyleSheet mystyle = new StyleSheet();
+
+ PdfPTable table = new PdfPTable(nbDay + 1);
+
+ Font font = FontFactory.getFont("Arial", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12, Font.NORMAL);
+ font.setStyle(Font.BOLD);
+
+ PdfPCell cell = new PdfPCell(new Phrase(""));
+ cell.setBackgroundColor(BaseColor.GRAY);
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ table.addCell(cell);
+
+ if(hasLundi){
+ cell = new PdfPCell(new Phrase("LUNDI", font));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ table.addCell(cell);
+ }
+
+ if(hasMardi){
+ cell = new PdfPCell(new Phrase("MARDI", font));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ table.addCell(cell);
+ }
+
+ if(hasMercredi){
+ cell = new PdfPCell(new Phrase("MERCREDI", font));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ table.addCell(cell);
+ }
+
+ if(hasJeudi){
+ cell = new PdfPCell(new Phrase("JEUDI", font));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ table.addCell(cell);
+ }
+
+ if(hasVendredi){
+ cell = new PdfPCell(new Phrase("VENDREDI", font));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ table.addCell(cell);
+ }
+
+ if(hasSamedi){
+ cell = new PdfPCell(new Phrase("SAMEDI", font));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ table.addCell(cell);
+ }
+
+ if(hasDimanche){
+ cell = new PdfPCell(new Phrase("DIMANCHE", font));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ table.addCell(cell);
+ }
+
+ //On cree le menu
+ //Les Entrees
+ String imageEntreeUrl = themeDisplay.getURLPortal() + "/html/js/extjs/pentila/img/cantine/entree.png";
+ com.itextpdf.text.Image imageEntree = com.itextpdf.text.Image.getInstance(new URL(imageEntreeUrl));
+ PdfPTable entreeTable = new PdfPTable(1);
+ PdfPCell entreeCell = new PdfPCell(new Phrase("ENTREE", font));
+ entreeCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ entreeCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ entreeCell.setBorder(0);
+ entreeTable.addCell(entreeCell);
+ entreeCell = new PdfPCell(imageEntree);
+ entreeCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ entreeCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ entreeCell.setBorder(0);
+ entreeTable.addCell(entreeCell);
+ cell = new PdfPCell(entreeTable);
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ table.addCell(cell);
+ for(String entree: entrees){
+ Paragraph entreePara = new Paragraph();
+ StringReader entreeReader = new StringReader(entree);
+ ArrayList entreeList = HTMLWorker.parseToList(entreeReader, mystyle);
+ for (int k = 0; k < entreeList.size(); ++k){
+ entreePara.add((Element)entreeList.get(k));
+ }
+ entreeReader.close();
+
+ cell = new PdfPCell(new Phrase(entreePara));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ table.addCell(cell);
+ }
+
+ //Les Plats
+ String imagePlatUrl = themeDisplay.getURLPortal() + "/html/js/extjs/pentila/img/cantine/plat.png";
+ com.itextpdf.text.Image imagePlat = com.itextpdf.text.Image.getInstance(new URL(imagePlatUrl));
+ PdfPTable platTable = new PdfPTable(1);
+ PdfPCell platCell = new PdfPCell(new Phrase("PLAT", font));
+ platCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ platCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ platCell.setBorder(0);
+ platTable.addCell(platCell);
+ platCell = new PdfPCell(imagePlat);
+ platCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ platCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ platCell.setBorder(0);
+ platTable.addCell(platCell);
+ cell = new PdfPCell(platTable);
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ table.addCell(cell);
+ for(String plat: plats){
+ Paragraph platPara = new Paragraph();
+ StringReader platReader = new StringReader(plat);
+ ArrayList platList = HTMLWorker.parseToList(platReader, mystyle);
+ for (int k = 0; k < platList.size(); ++k){
+ platPara.add((Element)platList.get(k));
+ }
+ platReader.close();
+
+ cell = new PdfPCell(new Phrase(platPara));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);cell.setVerticalAlignment(Element.ALIGN_CENTER);
+ cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ table.addCell(cell);
+ }
+
+ //Les Garniture
+ String imageGarnitureUrl = themeDisplay.getURLPortal() + "/html/js/extjs/pentila/img/cantine/garniture.png";
+ com.itextpdf.text.Image imageGarniture = com.itextpdf.text.Image.getInstance(new URL(imageGarnitureUrl));
+ PdfPTable garnitureTable = new PdfPTable(1);
+ PdfPCell garnitureCell = new PdfPCell(new Phrase("GARNITURE", font));
+ garnitureCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ garnitureCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ garnitureCell.setBorder(0);
+ garnitureTable.addCell(garnitureCell);
+ garnitureCell = new PdfPCell(imageGarniture);
+ garnitureCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ garnitureCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ garnitureCell.setBorder(0);
+ garnitureTable.addCell(garnitureCell);
+ cell = new PdfPCell(garnitureTable);
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ table.addCell(cell);
+ for(String garniture: garnitures){
+ Paragraph garniturePara = new Paragraph();
+ StringReader garnitureReader = new StringReader(garniture);
+ ArrayList garnitureList = HTMLWorker.parseToList(garnitureReader, mystyle);
+ for (int k = 0; k < garnitureList.size(); ++k){
+ garniturePara.add((Element)garnitureList.get(k));
+ }
+ garnitureReader.close();
+
+ cell = new PdfPCell(new Phrase(garniturePara));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ table.addCell(cell);
+ }
+
+ //Les Fromages
+ String imageFromageUrl = themeDisplay.getURLPortal() + "/html/js/extjs/pentila/img/cantine/fromage.png";
+ com.itextpdf.text.Image imageFromage = com.itextpdf.text.Image.getInstance(new URL(imageFromageUrl));
+ PdfPTable fromageTable = new PdfPTable(1);
+ PdfPCell fromageCell = new PdfPCell(new Phrase("FROMAGE", font));
+ fromageCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ fromageCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ fromageCell.setBorder(0);
+ fromageTable.addCell(fromageCell);
+ fromageCell = new PdfPCell(imageFromage);
+ fromageCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ fromageCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ fromageCell.setBorder(0);
+ fromageTable.addCell(fromageCell);
+ cell = new PdfPCell(fromageTable);
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ table.addCell(cell);
+ for(String fromage: fromages){
+ Paragraph fromagePara = new Paragraph();
+ StringReader fromageReader = new StringReader(fromage);
+ ArrayList fromageList = HTMLWorker.parseToList(fromageReader, mystyle);
+ for (int k = 0; k < fromageList.size(); ++k){
+ fromagePara.add((Element)fromageList.get(k));
+ }
+ fromageReader.close();
+
+ cell = new PdfPCell(new Phrase(fromagePara));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ table.addCell(cell);
+ }
+
+ //Les Desserts
+ String imageDessertUrl = themeDisplay.getURLPortal() + "/html/js/extjs/pentila/img/cantine/dessert.png";
+ com.itextpdf.text.Image imageDessert = com.itextpdf.text.Image.getInstance(new URL(imageDessertUrl));
+ PdfPTable dessertTable = new PdfPTable(1);
+ PdfPCell dessertCell = new PdfPCell(new Phrase("DESSERT", font));
+ dessertCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ dessertCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ dessertCell.setBorder(0);
+ dessertTable.addCell(dessertCell);
+ dessertCell = new PdfPCell(imageDessert);
+ dessertCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ dessertCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ dessertCell.setBorder(0);
+ dessertTable.addCell(dessertCell);
+ cell = new PdfPCell(dessertTable);
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ table.addCell(cell);
+ for(String dessert: desserts){
+ Paragraph dessertPara = new Paragraph();
+ StringReader dessertReader = new StringReader(dessert);
+ ArrayList dessertList = HTMLWorker.parseToList(dessertReader, mystyle);
+ for (int k = 0; k < dessertList.size(); ++k){
+ dessertPara.add((Element)dessertList.get(k));
+ }
+ dessertReader.close();
+
+ cell = new PdfPCell(new Phrase(dessertPara));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ table.addCell(cell);
+ }
+
+ return table;
+ }
+
+ //Export au format jour
+ public static byte[] exportMenuDay(String fileName, Date date, User user, boolean isMidi, boolean isSoir, boolean isAll, ThemeDisplay themeDisplay) throws NamingException, Exception {
+
+ FontFactory.register("com/pentila/entSavoie/portlets/cantine/util/LiberationMono-Regular.ttf", "exportFont");
+ Document document = new Document(PageSize.A4, 0, 0, 0, 0);
+ ByteArrayOutputStream b = new ByteArrayOutputStream();
+ PdfWriter.getInstance(document, b);
+
+ document.addAuthor(user.getFullName());
+ document.addTitle(fileName);
+ document.addSubject(fileName);
+ document.addCreationDate();
+ document.setMargins(50, 50, 50, 50);
+
+ //styleSheets
+ StyleSheet mystyle = new StyleSheet();
+
+ // Ouverture du document
+ document.open();
+
+ //Midi
+ if(isMidi){
+
+ String menuTitle = "<div align='center' style='font-size:16px;'><b><u>MENU du MIDI du " + frenchDateFormat.format(date) + "</u></b></div><br /><br />";
+
+ Paragraph title = new Paragraph();
+ StringReader titleMenu = new StringReader(menuTitle);
+ ArrayList titleList = HTMLWorker.parseToList(titleMenu, mystyle);
+ for (int k = 0; k < titleList.size(); ++k){
+ title.add((Element)titleList.get(k));
+ }
+ titleMenu.close();
+ document.add(title);
+ PdfPTable table = createMenuForDay(PortletPropsValues.ENT_CANTINE_PLAN_TYPE_MIDI, date, user, themeDisplay);
+ document.add(table);
+
+ }
+ //Soir
+ else if(isSoir){
+
+ String menuTitle = "<div align='center' style='font-size:16px;'><b><u>MENU du SOIR du " + frenchDateFormat.format(date) + "</u></b></div><br /><br />";
+
+ Paragraph title = new Paragraph();
+ StringReader titleMenu = new StringReader(menuTitle);
+ ArrayList titleList = HTMLWorker.parseToList(titleMenu, mystyle);
+ for (int k = 0; k < titleList.size(); ++k){
+ title.add((Element)titleList.get(k));
+ }
+ titleMenu.close();
+ document.add(title);
+ PdfPTable table = createMenuForDay(PortletPropsValues.ENT_CANTINE_PLAN_TYPE_SOIR, date, user, themeDisplay);
+ document.add(table);
+ }
+ //Les 2
+ else if(isAll){
+
+ //Midi
+ String menuTitle = "<div align='center' style='font-size:16px;'><b><u>MENU du MIDI du " + frenchDateFormat.format(date) + "</u></b></div><br /><br />";
+ Paragraph title = new Paragraph();
+ StringReader titleMenu = new StringReader(menuTitle);
+ ArrayList titleList = HTMLWorker.parseToList(titleMenu, mystyle);
+ for (int k = 0; k < titleList.size(); ++k){
+ title.add((Element)titleList.get(k));
+ }
+ titleMenu.close();
+ document.add(title);
+
+ PdfPTable tableMidi = createMenuForDay(PortletPropsValues.ENT_CANTINE_PLAN_TYPE_MIDI, date, user, themeDisplay);
+ document.add(tableMidi);
+ document.newPage();
+
+
+ //Soir
+ String menuTitleSoir = "<div align='center' style='font-size:16px;'><b><u>MENU du SOIR du " + frenchDateFormat.format(date) + "</u></b></div><br /><br />";
+ Paragraph titleSoir = new Paragraph();
+ StringReader titleMenuSoir = new StringReader(menuTitleSoir);
+ ArrayList titleSoirList = HTMLWorker.parseToList(titleMenuSoir, mystyle);
+ for (int k = 0; k < titleSoirList.size(); ++k){
+ titleSoir.add((Element)titleSoirList.get(k));
+ }
+ titleMenuSoir.close();
+ document.add(titleSoir);
+ PdfPTable tableSoir = createMenuForDay(PortletPropsValues.ENT_CANTINE_PLAN_TYPE_SOIR, date, user, themeDisplay);
+ document.add(tableSoir);
+ }
+
+ // Fermeture le document
+ document.close();
+
+ byte[] result = b.toByteArray();
+ b.close();
+
+ return result;
+ }
+
+ public static PdfPTable createMenuForDay(int type, Date date, User user, ThemeDisplay themeDisplay) throws NamingException, Exception {
+ //styleSheets
+ StyleSheet mystyle = new StyleSheet();
+
+ PdfPTable table = new PdfPTable(2);
+
+ Font font = FontFactory.getFont("Arial", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 12, Font.NORMAL);
+ font.setStyle(Font.BOLD);
+
+ PdfPCell cell = new PdfPCell(new Phrase(""));
+ cell.setBackgroundColor(BaseColor.GRAY);
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ table.addCell(cell);
+
+ cell = new PdfPCell(new Phrase(frenchDateFormatString.format(date), font));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ table.addCell(cell);
+
+ List<CantineDatePlanAlimentaire> lCantineDatePlanAlimentaires = CantineDatePlanAlimentaireLocalServiceUtil.getCantineDatePlanAlimentaireByEtabId_Date(OrganizationFinderServiceUtil.getEtabRatachement(user).getOrganizationId(), date);
+ String menuEntree = "";
+ String menuPlat = "";
+ String menuGarniture = "";
+ String menuLait = "";
+ String menuDessert = "";
+ //Formater les menus correctements
+ for(CantineDatePlanAlimentaire cdpa: lCantineDatePlanAlimentaires){
+ CantinePlanAlimentaire cpa = CantinePlanAlimentaireLocalServiceUtil.getCantinePlanAlimentaire(cdpa.getPlanAlimentaireId());
+ if(cpa.getType() == type){
+ //On recupere les entrees
+ List<CantineMenu> lcmEntree = CantineMenuLocalServiceUtil.getCantineMenuByCantineDatePlanAlimentaireId_TypeRecette(cdpa.getCantineDatePlanAlimentaireId(), PortletPropsValues.ENT_CANTINE_BANQUE_ENTREE);
+ for(CantineMenu cm: lcmEntree){
+ CantineRecette cr = CantineRecetteLocalServiceUtil.getCantineRecette(cm.getRecetteId());
+ menuEntree += cr.getTitreRecette() + "<br />";
+ }
+
+ //On recupere les plats
+ List<CantineMenu> lcmPlat = CantineMenuLocalServiceUtil.getCantineMenuByCantineDatePlanAlimentaireId_TypeRecette(cdpa.getCantineDatePlanAlimentaireId(), PortletPropsValues.ENT_CANTINE_BANQUE_PLAT);
+ for(CantineMenu cm: lcmPlat){
+ CantineRecette cr = CantineRecetteLocalServiceUtil.getCantineRecette(cm.getRecetteId());
+ menuPlat += cr.getTitreRecette() + "<br />";
+ }
+
+ //On recupere les garnitures
+ List<CantineMenu> lcmGarniture = CantineMenuLocalServiceUtil.getCantineMenuByCantineDatePlanAlimentaireId_TypeRecette(cdpa.getCantineDatePlanAlimentaireId(), PortletPropsValues.ENT_CANTINE_BANQUE_GARNITURE);
+ for(CantineMenu cm: lcmGarniture){
+ CantineRecette cr = CantineRecetteLocalServiceUtil.getCantineRecette(cm.getRecetteId());
+ menuGarniture += cr.getTitreRecette() + "<br />";
+ }
+
+ //On recupere les fromages
+ List<CantineMenu> lcmFromage = CantineMenuLocalServiceUtil.getCantineMenuByCantineDatePlanAlimentaireId_TypeRecette(cdpa.getCantineDatePlanAlimentaireId(), PortletPropsValues.ENT_CANTINE_BANQUE_LAIT);
+ for(CantineMenu cm: lcmFromage){
+ CantineRecette cr = CantineRecetteLocalServiceUtil.getCantineRecette(cm.getRecetteId());
+ menuLait += cr.getTitreRecette() + "<br />";
+ }
+
+ //On recupere les desserts
+ List<CantineMenu> lcmDessert = CantineMenuLocalServiceUtil.getCantineMenuByCantineDatePlanAlimentaireId_TypeRecette(cdpa.getCantineDatePlanAlimentaireId(), PortletPropsValues.ENT_CANTINE_BANQUE_DESSERT);
+ for(CantineMenu cm: lcmDessert){
+ CantineRecette cr = CantineRecetteLocalServiceUtil.getCantineRecette(cm.getRecetteId());
+ menuDessert += cr.getTitreRecette() + "<br />";
+ }
+ }
+ }
+
+ //On cree le menu
+ //Les Entrees
+ if(menuEntree.contains("<br />")){
+ menuEntree = menuEntree.substring(0, menuEntree.lastIndexOf("<br />"));
+ }
+ String imageEntreeUrl = themeDisplay.getURLPortal() + "/html/js/extjs/pentila/img/cantine/entree.png";
+ com.itextpdf.text.Image imageEntree = com.itextpdf.text.Image.getInstance(new URL(imageEntreeUrl));
+ PdfPTable entreeTable = new PdfPTable(1);
+ PdfPCell entreeCell = new PdfPCell(new Phrase("ENTREE", font));
+ entreeCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ entreeCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ entreeCell.setBorder(0);
+ entreeTable.addCell(entreeCell);
+ entreeCell = new PdfPCell(imageEntree);
+ entreeCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ entreeCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ entreeCell.setBorder(0);
+ entreeTable.addCell(entreeCell);
+ cell = new PdfPCell(entreeTable);
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ table.addCell(cell);
+ Paragraph entreePara = new Paragraph();
+ StringReader entreeReader = new StringReader(menuEntree);
+ ArrayList entreeList = HTMLWorker.parseToList(entreeReader, mystyle);
+ for (int k = 0; k < entreeList.size(); ++k){
+ entreePara.add((Element)entreeList.get(k));
+ }
+ entreeReader.close();
+
+ cell = new PdfPCell(new Phrase(entreePara));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ table.addCell(cell);
+
+ //Les Plats
+ if(menuPlat.contains("<br />")){
+ menuPlat = menuPlat.substring(0, menuPlat.lastIndexOf("<br />"));
+ }
+ String imagePlatUrl = themeDisplay.getURLPortal() + "/html/js/extjs/pentila/img/cantine/plat.png";
+ com.itextpdf.text.Image imagePlat = com.itextpdf.text.Image.getInstance(new URL(imagePlatUrl));
+ PdfPTable platTable = new PdfPTable(1);
+ PdfPCell platCell = new PdfPCell(new Phrase("PLAT", font));
+ platCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ platCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ platCell.setBorder(0);
+ platTable.addCell(platCell);
+ platCell = new PdfPCell(imagePlat);
+ platCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ platCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ platCell.setBorder(0);
+ platTable.addCell(platCell);
+ cell = new PdfPCell(platTable);
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ table.addCell(cell);
+ Paragraph platPara = new Paragraph();
+ StringReader platReader = new StringReader(menuPlat);
+ ArrayList platList = HTMLWorker.parseToList(platReader, mystyle);
+ for (int k = 0; k < platList.size(); ++k){
+ platPara.add((Element)platList.get(k));
+ }
+ platReader.close();
+
+ cell = new PdfPCell(new Phrase(platPara));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ table.addCell(cell);
+
+ //Les Garniture
+ if(menuGarniture.contains("<br />")){
+ menuGarniture = menuGarniture.substring(0, menuGarniture.lastIndexOf("<br />"));
+ }
+ String imageGarnitureUrl = themeDisplay.getURLPortal() + "/html/js/extjs/pentila/img/cantine/garniture.png";
+ com.itextpdf.text.Image imageGarniture = com.itextpdf.text.Image.getInstance(new URL(imageGarnitureUrl));
+ PdfPTable garnitureTable = new PdfPTable(1);
+ PdfPCell garnitureCell = new PdfPCell(new Phrase("GARNITURE", font));
+ garnitureCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ garnitureCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ garnitureCell.setBorder(0);
+ garnitureTable.addCell(garnitureCell);
+ garnitureCell = new PdfPCell(imageGarniture);
+ garnitureCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ garnitureCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ garnitureCell.setBorder(0);
+ garnitureTable.addCell(garnitureCell);
+ cell = new PdfPCell(garnitureTable);
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ table.addCell(cell);
+ Paragraph garniturePara = new Paragraph();
+ StringReader garnitureReader = new StringReader(menuGarniture);
+ ArrayList garnitureList = HTMLWorker.parseToList(garnitureReader, mystyle);
+ for (int k = 0; k < garnitureList.size(); ++k){
+ garniturePara.add((Element)garnitureList.get(k));
+ }
+ garnitureReader.close();
+
+ cell = new PdfPCell(new Phrase(garniturePara));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ table.addCell(cell);
+
+ //Les Fromages
+ if(menuLait.contains("<br />")){
+ menuLait = menuLait.substring(0, menuLait.lastIndexOf("<br />"));
+ }
+ String imageFromageUrl = themeDisplay.getURLPortal() + "/html/js/extjs/pentila/img/cantine/fromage.png";
+ com.itextpdf.text.Image imageFromage = com.itextpdf.text.Image.getInstance(new URL(imageFromageUrl));
+ PdfPTable fromageTable = new PdfPTable(1);
+ PdfPCell fromageCell = new PdfPCell(new Phrase("FROMAGE", font));
+ fromageCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ fromageCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ fromageCell.setBorder(0);
+ fromageTable.addCell(fromageCell);
+ fromageCell = new PdfPCell(imageFromage);
+ fromageCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ fromageCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ fromageCell.setBorder(0);
+ fromageTable.addCell(fromageCell);
+ cell = new PdfPCell(fromageTable);
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ table.addCell(cell);
+ Paragraph fromagePara = new Paragraph();
+ StringReader fromageReader = new StringReader(menuLait);
+ ArrayList fromageList = HTMLWorker.parseToList(fromageReader, mystyle);
+ for (int k = 0; k < fromageList.size(); ++k){
+ fromagePara.add((Element)fromageList.get(k));
+ }
+ fromageReader.close();
+
+ cell = new PdfPCell(new Phrase(fromagePara));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ table.addCell(cell);
+
+ //Les Desserts
+ if(menuDessert.contains("<br />")){
+ menuDessert = menuDessert.substring(0, menuDessert.lastIndexOf("<br />"));
+ }
+ String imageDessertUrl = themeDisplay.getURLPortal() + "/html/js/extjs/pentila/img/cantine/dessert.png";
+ com.itextpdf.text.Image imageDessert = com.itextpdf.text.Image.getInstance(new URL(imageDessertUrl));
+ PdfPTable dessertTable = new PdfPTable(1);
+ PdfPCell dessertCell = new PdfPCell(new Phrase("DESSERT", font));
+ dessertCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ dessertCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ dessertCell.setBorder(0);
+ dessertTable.addCell(dessertCell);
+ dessertCell = new PdfPCell(imageDessert);
+ dessertCell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ dessertCell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ dessertCell.setBorder(0);
+ dessertTable.addCell(dessertCell);
+ cell = new PdfPCell(dessertTable);
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ table.addCell(cell);
+ Paragraph dessertPara = new Paragraph();
+ StringReader dessertReader = new StringReader(menuDessert);
+ ArrayList dessertList = HTMLWorker.parseToList(dessertReader, mystyle);
+ for (int k = 0; k < dessertList.size(); ++k){
+ dessertPara.add((Element)dessertList.get(k));
+ }
+ dessertReader.close();
+
+ cell = new PdfPCell(new Phrase(dessertPara));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ cell.setVerticalAlignment(Element.ALIGN_MIDDLE);
+ table.addCell(cell);
+
+ return table;
+ }
+
+ /*
+ * Export de la configuration du plan alimentaire
+ */
+ public static byte[] exportPlanConfiguration(String fileName, User user,
+ ThemeDisplay themeDisplay, long planAlimentaireId) throws NamingException, Exception {
+
+ Organization etab = OrganizationFinderServiceUtil.getEtabRatachement(user);
+
+ String dateIntervalle = " du ";
+
+ CantinePlanAlimentaire cpa = CantinePlanAlimentaireLocalServiceUtil.getCantinePlanAlimentaire(planAlimentaireId);
+ List<CantineDatePlanAlimentaire> lcdpa = CantineDatePlanAlimentaireLocalServiceUtil.getCantineDatePlanAlimentaireByPlanAlimentaireId(planAlimentaireId);
+ dateIntervalle += frenchDateFormat.format(lcdpa.get(0).getDate()) + " au ";
+ dateIntervalle += frenchDateFormat.format(lcdpa.get(lcdpa.size() - 1).getDate());
+
+ FontFactory.register("com/pentila/entSavoie/portlets/cantine/util/LiberationMono-Regular.ttf", "exportFont");
+ Document document = new Document(PageSize.A4.rotate(), 0, 0, 0, 0);
+ ByteArrayOutputStream b = new ByteArrayOutputStream();
+ PdfWriter.getInstance(document, b);
+
+ document.addAuthor(user.getFullName());
+ document.addTitle(fileName);
+ document.addSubject(fileName);
+ document.addCreationDate();
+ document.setMargins(5, 5, 5, 5);
+
+ //styleSheets
+ StyleSheet mystyle = new StyleSheet();
+
+ // Ouverture du document
+ document.open();
+
+ String planTitle = "<div align='center' style='font-size:16px;'><b><u>Configuration du plan alimentaire</u></b></div><br /><br />";
+ planTitle += "<div style='font-size:14px;'><b> Plan : </b>" + cpa.getNomPlan() + dateIntervalle + "</div>";
+ planTitle += "<div style='font-size:14px;'><b> Etablissement : </b>" + ENTDisplayUtil.formatSCONETName(user, etab.getName()) + "</div><br />";
+
+ Paragraph plan = new Paragraph();
+ StringReader planSR = new StringReader(planTitle);
+ ArrayList planList = HTMLWorker.parseToList(planSR, mystyle);
+ for (int k = 0; k < planList.size(); ++k){
+ plan.add((Element)planList.get(k));
+ }
+ planSR.close();
+ document.add(plan);
+
+ float[] colsWidth = {1f, 1f, 1f, 1f, 1f, 1f}; // Code 1
+ PdfPTable table = new PdfPTable(colsWidth);
+ table.setWidthPercentage(95);
+
+ Font font = FontFactory.getFont("Arial", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10, Font.NORMAL);
+ font.setStyle(Font.BOLD);
+
+ Font font10 = FontFactory.getFont("Arial", BaseFont.IDENTITY_H, BaseFont.EMBEDDED, 10, Font.NORMAL);
+
+ PdfPCell cell;
+
+ int colDate = 1;
+ for(CantineDatePlanAlimentaire cdpa: lcdpa){
+
+ if(colDate>5){
+ colDate = 1;
+ cell = new PdfPCell(new Phrase(""));
+ table.addCell(cell);
+ }
+
+ cell = new PdfPCell(new Phrase(frenchDateFormat.format(cdpa.getDate()), font));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ table.addCell(cell);
+
+ for(int i=0; i<CantineUtil.steps.size(); i++){
+
+ cell = new PdfPCell(new Phrase(CantineUtil.getTypeLibelle(CantineUtil.steps.get(i+1)).replace("é", "\u00e9"), font));
+ cell.setHorizontalAlignment(Element.ALIGN_CENTER);
+ table.addCell(cell);
+ // TODO
+// List<CantinePlanAlimentaireConfiguration> lcpac = CantinePlanAlimentaireConfigurationLocalServiceUtil.getCantinePlanAlimentaireConfigurationByCantineDatePlanAlimentaireId_TypeRecette(cdpa.getCantineDatePlanAlimentaireId(), CantineUtil.steps.get(i+1));
+// if(lcpac.size() == 0){
+// excelSheet1.addCell(new Label(colDate, row, "", times12));
+// } else if(lcpac.size() == 1){
+// for(CantinePlanAlimentaireConfiguration cpac: lcpac){
+// CantineCategorieRecette ccr = CantineCategorieRecetteLocalServiceUtil.getCantineCategorieRecette(cpac.getCategorieRecetteId());
+// String color = ccr.getCouleurCategorie();
+// if(color.equals("FF3300")){
+// excelSheet1.addCell(new Label(colDate, row, ccr.getNomCategorie(), times12DARK_RED));
+// } else if(color.equals("007BB8")){
+// excelSheet1.addCell(new Label(colDate, row, ccr.getNomCategorie(), times12DARK_BLUE));
+// } else if(color.equals("660000")){
+// excelSheet1.addCell(new Label(colDate, row, ccr.getNomCategorie(), times12BROWN));
+// } else if(color.equals("339966")){
+// excelSheet1.addCell(new Label(colDate, row, ccr.getNomCategorie(), times12DARK_GREEN));
+// } else if(color.equals("66CC00")){
+// excelSheet1.addCell(new Label(colDate, row, ccr.getNomCategorie(), times12GREEN));
+// } else {
+// excelSheet1.addCell(new Label(colDate, row, ccr.getNomCategorie(), times12BLACK));
+// }
+// }
+// }
+// // Pas plus d'une couleur par cellule
+// else {
+// String categs = "";
+// for(CantinePlanAlimentaireConfiguration cpac: lcpac){
+// CantineCategorieRecette ccr = CantineCategorieRecetteLocalServiceUtil.getCantineCategorieRecette(cpac.getCategorieRecetteId());
+// categs += ccr.getNomCategorie();
+//
+// String color = ccr.getCouleurCategorie();
+// if(color.equals("FF3300")){
+// categs += " (ROUGE)";
+// } else if(color.equals("007BB8")){
+// categs += " (BLEU)";
+// } else if(color.equals("660000")){
+// categs += " (MARRON)";
+// } else if(color.equals("339966")){
+// categs += " (VERT FONCE)";
+// } else if(color.equals("66CC00")){
+// categs += " (VERT)";
+// }
+//
+// categs += "\n";
+// }
+//
+// categs = categs.substring(0, categs.lastIndexOf("\n"));
+// excelSheet1.addCell(new Label(colDate, row, categs, times12BLACK));
+// }
+//
+// row++;
+ }
+
+ colDate++;
+ }
+
+ return null;
+ }
+
+}