<?php
$form = $this->beginWidget('CActiveForm', array(
    'id' => 'order_edit-form',
    'enableAjaxValidation' => false,
    'enableClientValidation' => false,
));
?>
<div class="tab-content">
    <div class="tab-pane active">
        <ul class="clearfix form-ul material">
            <?php echo $form->hiddenField($model, 'id'); ?>
            <?php echo $form->hiddenField($model, 'distributer_id'); ?>
            <?php echo $form->hiddenField($model, 'month'); ?>
            <li class="col-sm-4">
                <?php 
                $arr_months=Order::getmonths();
                $dis_name = Distributers::model()->findByPk($model->distributer_id)->distributer_name;
                echo CHtml::textField('distributer_id',$dis_name, array('data-label' => 'Distributor <span style="color:red">*</span>','readonly'=>'true')); ?>
            </li>
            <li class="col-sm-4">
                <?php echo $form->textField($model, 'year', array('data-label' => 'Year <span style="color:red">*</span>','readonly'=>'true')); ?>
            </li>
            <li class="col-sm-4">
                <?php echo CHtml::textField('month', $arr_months[(int)$model->month], array('data-label' => 'Month <span style="color:red">*</span>','readonly'=>'true')); ?>
            </li>
            
        </ul>
    </div>
    <table class="table table-theme">
        <thead>
            <tr>
                <th width="5%">No</th>
                <th width="15%">Category</th>
                <th width="10%">GMC Code</th>
                <th width="10%">Model</th>
                <th width="10%">Base Code</th>
                <th width="10%">Quantity Ordered</th>
        
            </tr>
        </thead>
        <tbody>
           <?php
            $m=1;
            foreach ($modelItems as $i => $each){?>
            
                <tr>                
                    <td><label><?php echo $m;?></label>
                        <?php echo $form->hiddenField($each, "[" . $i . "]id"); ?>
                        <?php echo $form->hiddenField($each, "[" . $i . "]category_id"); ?>
                        <?php echo $form->hiddenField($each,  "[" . $i . "]product_id"); ?>
                    </td>
                    <td>
                        <?php echo $each->category_det->product_category; ?> 
                    </td>
                    <td>
                        <?php echo $each->product_det->gmc_code; ?>
                    </td>
                    <td>
                        <?php echo $form->textField($each,  "[" . $i . "]model", array('class'=>'go','readonly'=>'true')); ?>
                    </td>
                    <td>
                        <?php echo $form->textField($each,  "[" . $i . "]base_code", array('class'=>'go','readonly'=>'true')); ?>
                    </td>
                   <td style>
                        <?php echo $form->textField($each,  "[" . $i . "]quantity_ordered", array('class' => 'qty go cell-center text-right')); ?>
                    </td>
                </tr>        
            <?php 
            $m++;
                    
               
            } ?>     
        </tbody>
        </table>
</div>
<div class="modal-footer">
    <button type="button" class="btn btn-default" id="order_edit_close" data-dismiss="modal">Close</button>
    <?php
    $url = Yii::app()->createUrl('order/SaveEdittedOrder');
    echo CHtml::ajaxSubmitButton('Save', $url, array(
        'dataType' => 'json',
        'type' => 'post',
        'success' => 'function(data) {
            $("#loader").hide();
                if(data.status=="success"){  
                    t8.success("Order Saved Successfully!");
                    $("#order_edit_close").click();
                    reloadTable("#tbl_order_details");
                } else { 
                    $("#order_edit-form .order_edit-save-btn").prop("disabled", false);                      
                    $("#order_edit-form .order_edit-save-btn").addClass("btn-theme").removeClass("btn_loading"); 
                    $.each(data, function(key, val) {
                        t8.error(""+val+""); 
                    }); 
                } 
        }',
        'beforeSend' => 'function(){ 
            $("#loader").show();
            $(".toast8-error").hide();
            $("#order_edit-form .order_edit-save-btn").prop("disabled", true);                      
            $("#order_edit-form .order_edit-save-btn").addClass("btn_loading").removeClass("btn-theme"); 

        }'
    ), array('id' => 'mybtn' . rand(), 'class' => 'order_edit-save-btn btn btn-theme'));
    ?>
</div>
<?php $this->endWidget(); ?>