<?php
/* @var $model InventoryProducts */

$form = $this->beginWidget('CActiveForm', [
    'id' => 'inventory-products-form',
    'enableAjaxValidation' => false,
    'enableClientValidation' => false,
    'htmlOptions' => ['enctype' => 'multipart/form-data'],
]);
?>

<?php echo $form->hiddenField($model, 'id'); ?>

<div class="tab-content">
    <div class="tab-pane active">
        <ul class="clearfix form-ul material">

            <!-- Part Number -->
            <li class="col-sm-4">
                <?php echo $form->labelEx($model, 'sku', ['label' => 'Part Number ']); ?>
                <?php echo $form->textField($model, 'sku', [
                    'data-validation'=>'required',
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'sku'); ?>
            </li>

            <!-- Product Name -->
            <li class="col-sm-4">
                <?php echo $form->labelEx($model, 'product_name', ['label' => 'Name ']); ?>
                <?php echo $form->textField($model, 'product_name', [
                    'data-validation'=>'required',
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'product_name'); ?>
            </li>

            <!-- Alias -->
            <li class="col-sm-4">
                <?php echo $form->label($model, 'alias', ['label' => 'Alias']); ?>
                <?php echo $form->textField($model, 'alias', [
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'alias'); ?>
            </li>

            <!-- Brand -->
            <li class="col-sm-4">
                <?php echo $form->labelEx($model, 'brand', ['label' => 'Brand ']); ?>
                <?php echo $form->textField($model, 'brand', [
                    'data-validation'=>'required',
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'brand'); ?>
            </li>

            <!-- Category -->
            <li class="col-sm-4">
                <?php echo $form->label($model, 'category', ['label' => 'Category']); ?>
                <?php echo $form->textField($model, 'category', [
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'category'); ?>
            </li>

            <!-- Unit -->
            <li class="col-sm-4">
                <?php echo $form->labelEx($model, 'unit', ['label' => 'Unit ']); ?>
                <?php echo $form->textField($model, 'unit', [
                    'data-validation'=>'required',
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'unit'); ?>
            </li>

            <!-- Warehouse -->
            <li class="col-sm-4">
                <?php echo $form->labelEx($model, 'warehouse', ['label' => 'Warehouse ']); ?>
                <?php echo $form->textField($model, 'warehouse', [
                    'data-validation'=>'required',
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'warehouse'); ?>
            </li>

            <!-- Rack -->
            <li class="col-sm-4">
                <?php echo $form->labelEx($model, 'rack', ['label' => 'Rack ']); ?>
                <?php echo $form->textField($model, 'rack', [
                    'data-validation'=>'required',
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'rack'); ?>
            </li>

            <!-- Bin -->
            <li class="col-sm-4">
                <?php echo $form->label($model, 'bin', ['label' => 'Bin']); ?>
                <?php echo $form->textField($model, 'bin', [
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'bin'); ?>
            </li>

            <!-- Quantity -->
            <li class="col-sm-4">
                <?php echo $form->label($model, 'quantity', ['label' => 'Total Quantity']); ?>
                <?php echo $form->textField($model, 'quantity', [
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'quantity'); ?>
            </li>

            <!-- Price -->
            <li class="col-sm-4">
                <?php echo $form->label($model, 'price', ['label' => 'Rate']); ?>
                <?php echo $form->textField($model, 'price', [
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'price'); ?>
            </li>

            <!-- Total Value -->
            <li class="col-sm-4">
                <?php echo $form->label($model, 'total_value', ['label' => 'Total Value']); ?>
                <?php echo $form->textField($model, 'total_value', [
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'total_value'); ?>
            </li>

            <!-- Length -->
            <li class="col-sm-4">
                <?php echo $form->label($model, 'length_cm', ['label' => 'Length (CM)']); ?>
                <?php echo $form->textField($model, 'length_cm', [
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'length_cm'); ?>
            </li>

            <!-- Width -->
            <li class="col-sm-4">
                <?php echo $form->label($model, 'width_cm', ['label' => 'Width (CM)']); ?>
                <?php echo $form->textField($model, 'width_cm', [
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'width_cm'); ?>
            </li>

            <!-- Height -->
            <li class="col-sm-4">
                <?php echo $form->label($model, 'height_cm', ['label' => 'Height (CM)']); ?>
                <?php echo $form->textField($model, 'height_cm', [
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'height_cm'); ?>
            </li>

            <!-- Have Expiry Date -->
            <li class="col-sm-4">
                <?php echo $form->label($model, 'have_expiry_date', ['label' => 'Have Expiry Date']); ?>
                <?php echo $form->dropDownList($model, 'have_expiry_date', [
                    'Y'=>'Yes',
                    'N'=>'No'
                ], ['class'=>'form-control']); ?>
                <?php echo $form->error($model,'have_expiry_date'); ?>
            </li>

            <!-- Have Serial Number -->
            <li class="col-sm-4">
                <?php echo $form->label($model, 'have_serial_no', ['label' => 'Have Serial Number']); ?>
                <?php echo $form->dropDownList($model, 'have_serial_no', [
                    'Y'=>'Yes',
                    'N'=>'No'
                ], ['class'=>'form-control']); ?>
                <?php echo $form->error($model,'have_serial_no'); ?>
            </li>

            <!-- Image -->
            <li class="col-sm-4">
                <?php echo $form->label($model, 'image', ['label' => 'Image']); ?>
                <?php echo $form->fileField($model, 'image', [
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'image'); ?>
            </li>
            <!-- Tax Code -->
            <li class="col-sm-4">
                <?php echo $form->labelEx($model, 'tax_code', ['label' => 'Tax Code ']); ?>
                <?php echo $form->textField($model, 'tax_code', [
                    'data-validation'=>'required',
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'tax_code'); ?>
            </li>

            <!-- Machine/Spare -->
            <li class="col-sm-4">
                <?php echo $form->labelEx($model, 'machine_spare', ['label' => 'Machine/Spare ']); ?>
                <?php echo $form->textField($model, 'machine_spare', [
                    'data-validation'=>'required',
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'machine_spare'); ?>
            </li>

            <!-- Machine/Spare Remarks -->
            <li class="col-sm-4">
                <?php echo $form->label($model, 'machine_spare_remarks', ['label' => 'Machine/Spare Remarks']); ?>
                <?php echo $form->textField($model, 'machine_spare_remarks', [
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'machine_spare_remarks'); ?>
            </li>


            <!-- Thickness -->
            <li class="col-sm-4">
                <?php echo $form->label($model, 'thickness', ['label' => 'Thickness']); ?>
                <?php echo $form->textField($model, 'thickness', [
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'thickness'); ?>
            </li>

            <!-- Finish -->
            <li class="col-sm-4">
                <?php echo $form->label($model, 'finish', ['label' => 'Finish']); ?>
                <?php echo $form->textField($model, 'finish', [
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'finish'); ?>
            </li>

            <!-- HS Code -->
            <li class="col-sm-4">
                <?php echo $form->label($model, 'hs_code', ['label' => 'HS Code']); ?>
                <?php echo $form->textField($model, 'hs_code', [
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'hs_code'); ?>
            </li>

            <!-- Bar Code -->
            <li class="col-sm-4">
                <?php echo $form->label($model, 'bar_code', ['label' => 'Bar Code']); ?>
                <?php echo $form->textField($model, 'bar_code', [
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'bar_code'); ?>
            </li>

            <!-- Item Type -->
            <li class="col-sm-4">
                <?php echo $form->label($model, 'item_type', ['label' => 'Item Type']); ?>
                <?php echo $form->textField($model, 'item_type', [
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'item_type'); ?>
            </li>

            <!-- Volume -->
            <li class="col-sm-4">
                <?php echo $form->label($model, 'volume_l', ['label' => 'Volume (L)']); ?>
                <?php echo $form->textField($model, 'volume_l', [
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'volume_l'); ?>
            </li>

            <!-- Weight -->
            <li class="col-sm-4">
                <?php echo $form->label($model, 'weight', ['label' => 'Weight']); ?>
                <?php echo $form->textField($model, 'weight', [
                    'class'=>'form-control'
                ]); ?>
                <?php echo $form->error($model,'weight'); ?>
            </li>
        </ul>
    </div>
</div>

<?php $this->endWidget(); ?> <!-- Single endWidget for this form -->

<div class="modal-footer">
    <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
    <button type="button" class="inventory-save-btn btn btn-theme">Save</button>
</div>

<script>
$(document).ready(function(){

    $('.inventory-save-btn').on('click', function() {
        var btn = $(this);
        btn.prop('disabled', true).addClass('btn_loding').removeClass('btn-theme');
        $("#loader").show();

        var form = document.getElementById('inventory-products-form');
        var formData = new FormData(form);

        $.ajax({
            url: '<?php echo Yii::app()->createUrl("/inventoryProducts/save"); ?>',
            type: 'POST',
            data: formData,
            dataType: 'json',
            contentType: false,
            processData: false,
           success: function(data){

    $("#loader").hide();
    btn.prop('disabled', false)
       .removeClass('btn_loding')
       .addClass('btn-theme');

    if(data.status === "success"){
        t8.success("Saved Successfully!");
        $(".x.close").click();
        reloadTable("#tbl_inventory_products");
    }
    else{
        $.each(data.message, function(k, v){
            t8.error(v);
        });
    }
},
            error: function(){
                $("#loader").hide();
                btn.prop('disabled', false).removeClass('btn_loding').addClass('btn-theme');
                t8.error("Something went wrong.");
            }
        });
    });

});
</script>