<?php
/**
 * Fine search form
 *
 * @author Moises Heberle [moises@solis.coop.br]
 *
 * @version $Id$
 *
 * \b Maintainers \n
 * Eduardo Bonfandini [eduardo@solis.coop.br]
 * Jamiel Spezia [jamiel@solis.coop.br]
 * Luiz Gregory Filho [luiz@solis.coop.br]
 * Moises Heberle [moises@solis.coop.br]
 * Sandro Roberto Weisheimer [sandrow@solis.coop.br]
 *
 * @since
 * Class created on 28/07/2008
 *
 * \b Organization: \n
 * SOLIS - Cooperativa de Solucoes Livres \n
 * The Gnuteca3 Development Team
 *
 * \b CopyLeft: \n
 * CopyLeft (L) 2008 SOLIS - Cooperativa de Solucoes Livres \n
 *
 * \b License: \n
 * Licensed under GPL (for further details read the COPYING file or http://www.gnu.org/copyleft/gpl.html )
 *
 * \b History: \n
 * See history in SVN repository: http://gnuteca.solis.coop.br
 */
class FrmFineSearch extends GnutecaForm
{
    public $busFineStatus;
    public $busLibraryUnit;


    public function __construct()
    {
        $MIOLO  = MIOLO::getInstance();
        $module = MIOLO::getCurrentModule();
        $this->busFineStatus  = $MIOLO->getBusiness($module, 'BusFineStatus');
        $this->busLibraryUnit = $MIOLO->getBusiness($module, 'BusLibraryUnit');
        $this->setAllFunctions('Fine', array('loanIdS'));
        parent::__construct();
        if ( $this->primeiroAcessoAoForm() && strlen(MIOLO::_REQUEST('event')) == 0 )
        {
            $this->setFocus('fineIdS');
        }
    }


    public function createFields()
    {
    	//Set location
    	$this->business->isFormSearch = TRUE;

        $fineIdS = new MTextField('fineIdS', null, _M('Code', $this->module), FIELD_ID_SIZE);
        $validators[] = new MIntegerValidator('fineIdS');
        $fields[] = $fineIdS;

        $loanIdLabelS = new MLabel(_M('Loan code', $this->module) . ':');
        $loanIdLabelS->setWidth(FIELD_LABEL_SIZE);
        $loanIdS = new MLookupTextField('loanIdS', '', '', FIELD_LOOKUPFIELD_SIZE);
        $loanIdS->setContext($this->module, $this->module, 'Loan', 'filler', 'loanIdS,loanIdDescriptionS');
        $loanIdDescriptionS = new MTextField('loanIdDescriptionS', null, NULL, FIELD_DESCRIPTION_LOOKUP_SIZE);
        $loanIdDescriptionS->setReadOnly(true);
        $fields[] = new MHcontainer('loanIdContainerS', array($loanIdLabelS, $loanIdS, $loanIdDescriptionS));

        $lblPerson = new MLabel(_M('Person code', $this->module) . ':');
        $lblPerson->setWidth(FIELD_LABEL_SIZE);
        $personId = new MLookupTextField('personIdS', '', '', FIELD_LOOKUPFIELD_SIZE);
        $personId->setContext($this->module, $this->module, 'Person', 'filler', 'personIdS,personIdDescription');
        $description = new MTextField('personIdDescription', null, null, FIELD_DESCRIPTION_LOOKUP_SIZE);
        $description->setReadOnly(true);
        $fields[] = new MHcontainer('hctPerson', array($lblPerson, $personId, $description));

        $lblDate             = new MLabel(_M('Begin date', $this->module) . ':');
        $lblDate->setWidth(FIELD_LABEL_SIZE);
        $beginBeginDateS     = new MCalendarField('beginBeginDateS', $this->beginBeginDateS->value, null, FIELD_DATE_SIZE, null, 'calendar-win2k-1');
        $endBeginDateS       = new MCalendarField('endBeginDateS', $this->endBeginDateS->value, null, FIELD_DATE_SIZE, null, 'calendar-win2k-1');
        $fields[] = new MHContainer('hctDates', array($lblDate, $beginBeginDateS, $endBeginDateS));

        $valueS = new MTextField('valueS', null, _M('Value', $this->module), FIELD_ID_SIZE);
        $validators[] = new MRegExpValidator('valueS', _M('Value', $this->module), '^([0-9]?[0-9])(\.[0-9][0-9]?)?$');
        $fields[] = $valueS;

        $fields[] = new GnutecaSelection('fineStatusIdS', null, _M('Fine status', $this->module), $this->busFineStatus->listFineStatus());

        $lblDate             = new MLabel(_M('End date', $this->module) . ':');
        $lblDate->setWidth(FIELD_LABEL_SIZE);
        $beginEndDateS     = new MCalendarField('beginEndDateS', $this->beginEndDateS->value, null, FIELD_DATE_SIZE, null, 'calendar-win2k-1');
        $endEndDateS       = new MCalendarField('endEndDateS', $this->endEndDateS->value, null, FIELD_DATE_SIZE, null, 'calendar-win2k-1');
        $fields[] = new MHContainer('hctDates', array($lblDate, $beginEndDateS, $endEndDateS));

        $fields[] = new MTextField('itemNumberS', NULL, _M('Item number',$this->module));

        $this->busLibraryUnit->filterOperator = TRUE;
        $this->busLibraryUnit->labelAllLibrary = TRUE;
        $fields[] = new GnutecaSelection('libraryUnitIdS',   $this->libraryUnitId->value, _M('Library unit', $this->module), $this->busLibraryUnit->listLibraryUnit(), null, null, null, TRUE);

        $this->setFields( $fields );
        $this->setValidators( $validators );
    }


    public function getGrid()
    {
        $data = $this->getData();
        if ($data->valueS)
        {
            $data->valueS = str_replace(',', '.', $data->valueS);
        }
        return parent::getGrid($data);
    }


    public function showDetail()
    {
        $frm = $this->MIOLO->getUI()->getForm($this->module, 'FrmFineStatusHistory');
        parent::_showDetail($frm);
    }



}
?>
