<input type="hidden" name="hid_file_id" id="hid_file_id" value="<?php echo $file_id; ?>">

<?php echo $form->hiddenField($model, 'id'); ?>
<?php echo $form->hiddenField($model, 'enquiry_id'); ?>
<ul class="clearfix form-ul material">

    <li class="col-sm-4">
        <?php echo $form->textField($model, 'title', array('title' => 'File Title ', 'data-label' => 'File Title <span style="color:red;">*</span>', 'readonly' => 'readonly')); ?>
        <?php echo $form->error($model, 'title'); ?>
    </li>
    <!-- 'multiple'=>true,-->
    <li class="col-sm-4">
        <?php
        if ($enq_id > 0) {
            $arr_vendor = Vendor::getVendorsEnquiry($enq_id);
            $model->vendor_id = $vendor_id;
        } else {
            $arr_vendor = Vendor::getVendors();
        }
        echo $form->dropDownList($model, 'vendor_id', $arr_vendor, array('class' => '', 'prompt' => 'Select', 'title' => 'Select Supplier *', 'data-label' => 'Supplier <span style="color:red;">*</span>', 'onChange' => 'getCurrency(this.value)', 'disabled' => true)); ?>
        <?php echo $form->error($model, 'vendor_id'); ?>
    </li>
    <!--                <li class="col-sm-4">   
                      
                    <?php //echo $form->textField($model, 'connected_file_id', array('class'=>'','title' => 'Connected File ','data-label'=>'Connected File')); 
                    ?>
                </li> -->

    <li class="col-sm-4">
        <?php echo $form->textField($model, 'order_date', array('class' => 'datepicker', 'title' => 'Order Date ', 'data-label' => 'Order Date', 'readonly' => 'readonly')); ?>
        <?php echo $form->error($model, 'order_date'); ?>
    </li>
    <li class="col-sm-4">
        <?php echo $form->textField($model, 'required_date', array('class' => 'datepicker', 'title' => 'Required Date ', 'data-label' => 'Required Date <span style="color:red;">*</span>', 'data-search' => 'true', 'value' => $required_date, 'readonly' => 'readonly')); ?>
        <?php echo $form->error($model, 'required_date'); ?>
    </li>

    <li class="col-sm-4">
        <?php echo $form->textField($model, 'expected_delivery_date', array('class' => 'datepicker', 'title' => 'Expected Delivery Date ', 'data-label' => 'Expected Delivery Date', 'onclick' => 'putDateVal(this.value)', 'readonly' => 'readonly')); ?>
        <?php echo $form->error($model, 'expected_delivery_date'); ?>
    </li>

    <li class="col-sm-3" id="c_div">
        <?php
        if ($model->id == 0) {
            if ($model->vendor_id > 0) {
                $model->currency  = $model->vendor_details->vendor_currency_id;
            }
        }
        ?>
        <?php echo $form->dropDownList($model, 'currency', MasCurrency::getCurrency(), array('onChange' => 'getExchangeRate(this.id)', 'class' => 'tooltipster', 'title' => 'Currency', 'data-label' => 'Currency', 'disabled' => true, 'prompt' => '--Select--')); ?>

        <?php echo $form->error($model, 'currency'); ?>

    </li>
    <li class="col-sm-3">
        <?php
        if ($model->id == 0) {
            if ($model->vendor_id > 0) {
                $model->exchange_rate  = $model->vendor_details->currency_detail->exchange_rate;
            }
        } ?>

        <?php echo $form->textField($model, 'exchange_rate', array('class' => 'tooltipster', 'title' => 'Exchange Rate', 'data-label' => 'Exchange Rate', 'value' => $exchange_rate, 'readonly' => 'readonly')); ?>
        <?php echo $form->error($model, 'exchange_rate'); ?>

    </li>
    <?php if(isset(Yii::app()->user->fm_module) && Yii::app()->user->fm_module=='Y'){?>
    <li class="col-sm-3">
        <?php echo $form->dropDownList($model, 'ticket_id', TicketHeader::GetJoblist(), array('class' => '', 'title' => 'Select Payment Terms', 'data-label' => 'Payment Terms <span style="color:red;">*</span> ', 'disabled' => true)); ?>
        <?php echo $form->error($model, 'ticket_id'); ?>
    </li>
    <?php }?>

    <li class="col-sm-3" id="p_div">
        <?php echo $form->dropDownList($model, 'payment_terms', MasPaymentTerm::getPaymentTerms(), array('class' => '', 'title' => 'Select Payment Terms', 'data-label' => 'Payment Terms <span style="color:red;">*</span> ', 'disabled' => true)); ?>
        <?php echo $form->error($model, 'payment_terms'); ?>
    </li>
    <li class="col-sm-3">
        <?php echo $form->dropDownList($model, 'shipping_by', MasShipping::getShipping(), array('title' => 'Shipping By', 'data-label' => 'Mode of Transport', 'disabled' => true)); ?>
        <?php echo $form->error($model, 'shipping_by'); ?>
    </li>
    <li class="col-sm-4">

        <?php
        if ($model->shipping_address == '') {
            $masCompanyAddress  = $masCompanyAddress;
        } else {
            $masCompanyAddress = $model->shipping_address;
        }

        ?>
        <?php echo $form->textArea($model, 'shipping_address', array('title' => 'Shipping Address', 'data-label' => 'Shipping Address <span style="color:red;">*</span> ', 'data-search' => 'true', 'value' => $masCompanyAddress, 'readonly' => 'readonly')); ?>

        <?php echo $form->error($model, 'shipping_address'); ?>

    </li>
    <li class="col-sm-4">

        <?php echo $form->textArea($model, 'pricing_conditions', array('title' => 'Pricing Conditions', 'data-label' => 'Pricing Conditions', 'data-search' => 'true', 'readonly' => 'readonly')); ?>

        <?php echo $form->error($model, 'pricing_conditions'); ?>

    </li>
    <li class="col-sm-4">

        <?php echo $form->textArea($model, 'start_text', array('title' => 'Start Text', 'data-label' => 'Start Text', 'readonly' => 'readonly')); ?>

        <?php echo $form->error($model, 'start_text'); ?>

    </li>


</ul>
<?php
$cs = Yii::app()->getClientScript();
$cs->registerScript("getCurrency", " function getCurrency(vendor_id) {
                                jQuery.ajax({
                                        'dataType':'json', 
                                        'type': 'post',
                                        'url': '" . Yii::app()->createUrl('vendor/getCurrency') . "',
                                        'data': {'vendor_id':vendor_id},
                                        'cache': false,
                                        'success': function(data) {
                                           $('#c_div').html(data.currency);
                                           $('#p_div').html(data.payterm);
                                           $('#PurchasingOrder_exchange_rate').val(data.exchange_rate).addClass('filled');
                                           $('#PurchasingOrder_shipping_address').val(data.shipaddress).addClass('filled');
                                        }
                                });

        }", CClientScript::POS_HEAD);
$cs->registerScript("getExchangeRate", " function getExchangeRate(currency) {
            var currency_id = $('#'+currency).val();
                                jQuery.ajax({
                                        'type': 'post',
                                        'url': '" . Yii::app()->createUrl('lead/getExchangeRate') . "',
                                        'data': {'currency_id':currency_id},
                                        'cache': false,
                                        'success': function(data) {
                                           $('#PurchasingOrder_exchange_rate').val(data);
                                        }
                                });

        }", CClientScript::POS_HEAD);
$cs->registerScript("putDateVal", " function putDateVal(date) {
                var i=0;
                for(i=0;i<50;i++){
                try{
                    $('#PurchasingOrderStockItem_'+i+'_expected_delivery_date').val(date);
                }catch(e){}
                }
        }", CClientScript::POS_HEAD);
?>
<script>
    $(function() {
        var date_value = $("#PurchasingOrder_order_date").val().split("/");
        var current = new Date(date_value[2], date_value[1] - 1, date_value[0]);
        $('#PurchasingOrder_required_date').datetimepicker({
            minDate: current,
            format: 'DD/MM/YYYY'
        });
        var exp_date = $("#PurchasingOrder_required_date").val().split("/");
        var current_2 = new Date(exp_date[2], exp_date[1] - 1, exp_date[0]);
        $('#PurchasingOrder_expected_delivery_date').datetimepicker({
            minDate: current,
            maxDate: current_2,
            format: 'DD/MM/YYYY'
        });
        $("#PurchasingOrder_expected_delivery_date").on("dp.change", function(e) {
            var d = new Date(e.date);
            var duedate = new Date(d);
            duedate.setDate(d.getDate() + 0);
            var month = String(duedate.getMonth() + 1);
            var day = String(duedate.getDate());
            const year = String(duedate.getFullYear());

            if (month.length < 2) month = '0' + month;
            if (day.length < 2) day = '0' + day;

            var final = `${day}/${month}/${year}`;
            //$('#Contract_contract_date_to').val(final);
            var i = 0;
            for (i = 0; i < 50; i++) {
                try {
                    $('#PurchasingOrderStockItem_' + i + '_expected_delivery_date').val(final);
                } catch (e) {}
            }

        });

    });
</script>