/***************************************************************************
 *   Copyright (C) 2008 by S. MANKOWSKI / G. DE BURE support@mankowski.fr  *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>  *
 ***************************************************************************/
#ifndef SKGREPORT_H
#define SKGREPORT_H
/** @file
 * A report class for document
 *
 * @author Stephane MANKOWSKI
 */
#include <QObject>
#include <QVariant>

#include "skgerror.h"
#include "skgbasemodeler_export.h"

class SKGDocument;
/**
 * A report class for document
 */
class SKGBASEMODELER_EXPORT SKGReport : public QObject
{
    Q_OBJECT
    /**
     * The period
     */
    Q_PROPERTY(QString period READ getPeriod)

    /**
     * The month (for compatibility in templates)
     */
    Q_PROPERTY(QString month READ getPeriod)

    /**
     * The previous period
     */
    Q_PROPERTY(QString previous_period READ getPreviousPeriod)

    /**
     * The previous month (for compatibility in templates)
     */
    Q_PROPERTY(QString previous_month READ getPreviousPeriod)

public:
    /**
     * Default Constructor
     */
    explicit SKGReport(SKGDocument* iDocument);

    /**
     * Default Destructor
     */
    virtual ~SKGReport();

    /**
     * Set the current period
     * @param iPeriod the period
     */
    virtual void setPeriod(const QString& iPeriod);

    /**
     * Get the current period
     * @return the current period
     */
    virtual QString getPeriod();

    /**
     * Get the previous period
     * @return the previous period
     */
    virtual QString getPreviousPeriod();

    /**
     * Get report
     * @param iReport the report
     * @param iFile the tremplate file name
     * @param oHtml the html report
     * @return an object managing the error
     *   @see SKGError
     */
    static SKGError getReportFromTemplate(SKGReport* iReport, const QString& iFile, QString& oHtml);

protected:
    /**
     * Enrich the grantlee mapping
     * @param iMapping the mapping
     */
    virtual void addItemsInMapping(QVariantHash& iMapping);

    SKGDocument* m_document;
    QHash<QString, QVariant> m_cache;

private:
    Q_DISABLE_COPY(SKGReport)
};

#endif  // SKGREPORT_H
