<?php
/* @var $this TicketController */
/* @var $model Ticket */
/* @var $form CActiveForm */
?>

<?php
$form = $this->beginWidget('bootstrap.widgets.TbActiveForm', array(
            'id' => 'ticket-form',
            'enableAjaxValidation' => false,
        ));
$this->widget('bootstrap.widgets.TbAlert');


if (Yii::app()->user->checkAccess('Food Manager'))
{
    echo $form->textFieldRow($model, 'department_id', array('disabled' => 'disabled'));
}
else
{
    echo "<br />";
    echo Yii::t('default', 'Location');
    echo "<br />";

    $state = $this->createWidget('application.extensions.jquery-cascade.jQueryCascade');
    echo $state->dropDownList('Location',
            $model->location,
            User::model()->getLocationsInGeomarket(),
            array('name'=>''),
            CController::createUrl('ticket/getDepartments'),
            'Ticket_department_id'
    );

    $location = $model->location;
    $departments = array();
    $departments[''] = yii::t('default', 'Select Department');
    if ($location != '')
    {
        $selected_location = Location::model()->findByPk($location);

        if (isset($selected_location->departments) && ($selected_location->departments != null))
        {
            foreach ($selected_location->departments as $department)
            {
                $departments[$department->id] = $department->name;
            }
        }
    }
    echo $form->dropDownListRow($model, 'department_id', $departments);
}

echo CHtml::label('Date', 'Ticket_date_time');

$this->widget('application.extensions.timepicker.timepicker', array(
    'model' => $model,
    'name' => 'date_time',
    'select' => 'date',
    'options' => array(
        'timeFormat' => 'hh:mm',
        'showOn' => 'focus',
        'showSecond' => false,
        'changeMonth' => false,
        'changeYear' => false,
        'tabularLevel' => null,
        'regional' => 'nl',
    ),
));





echo "<br />";
echo Yii::t('default', 'POS');
echo "<br />";

$state = $this->createWidget('application.extensions.jquery-cascade.jQueryCascade');
echo $state->dropDownList('POS',
        $model->pos_id,
        Pos::getAllAsArray(),
        array('name'=>''),
        CController::createUrl('ticket/getSchedules'),
        'Ticket_schedule_id'
);

$pos = $model->pos_id;
$schedules = array();
$schedules[''] = yii::t('default', 'Select Schedule');
if ($pos != '')
{
    $selected_pos = Pos::model()->findByPk($pos);

    if (isset($selected_pos->posSchedules) && ($selected_pos->posSchedules != null))
    {
        foreach ($selected_pos->posSchedules as $posSchedules)
        {
            $schedules[$posSchedules->schedule->id] = $posSchedules->schedule->name;
        }
    }
}
echo $form->dropDownListRow($model, 'schedule_id', $schedules);

echo $form->textFieldRow($model, 'quantity');

echo $form->dropDownListRow($model, 'issuing_reason_id', CHtml::listData(IssuingReason::getAll("Active"), 'id', 'reason'), array('empty' => Yii::t('default', 'Select Reason')));
?>
<div class="actions">
    <?php
    if (Yii::app()->user->checkAccess('Food Manager'))
    {
        echo CHtml::submitButton(Yii::t('default', 'Issue'),
                array('class' => 'btn primary',
                    "onClick" => "
                        // The confirmation message of the
                       if (confirm('" . Yii::t('default', 'Are you sure you want to issue the ticket?') . "')){
                           return confirm('Please note that you will charge the department ('+$('#Ticket_department_id').val()+') for ('+$('#Ticket_quantity').val()+') meal(s), press “Ok” to continue or “cancel” to revert') ;
                           }else{
                           return false;
                           }"
                )
        );
    }
    else
    {
        echo CHtml::submitButton(Yii::t('default', 'Issue'),
                array('class' => 'btn primary',
                    "onClick" => "
                        // The confirmation message of the
                       if (confirm('" . Yii::t('default', 'Are you sure you want to issue the ticket?') . "')){
                           return confirm('Please note that you will charge the department ('+$('#Ticket_department_id :selected').text()+') for ('+$('#Ticket_quantity').val()+') meal(s), press “Ok” to continue or “cancel” to revert') ;
                           }else{
                           return false;
                           }"
                )
        );
    }
    ?>
    &ensp;
    <?php echo CHtml::link(Yii::t('default', 'Cancel'), array('index'), array('class' => 'btn primary')); ?>
</div>

<?php $this->endWidget(); ?>
