<?php
$form = $this->distanceform;
$form->prepare();
$form->setAttribute('action', $this->url('cabfare', ['action' => 'add-price-distance']));
$form->setAttribute('method', 'post');
echo $this->form()->openTag($form);

if(isset($VndViewFare)){
    
    foreach ($form->getElements() as $element) {
    $element->setAttribute('disabled', true);
    $element->setAttribute('readonly',true);
    }
}

$bookingMode    = $this->bookingMode;
$bookingType    = $this->bookingType;
$masterlocalpkg = $this->masterLocalPkg;
$kmRateString="";
$package_fare_data="";

$rate_upto_distance = isset($fareDetails['rate_upto_distance'])?$fareDetails['rate_upto_distance']:'';
if($rate_upto_distance!=''){
   $kmRateString = '';
   foreach($rate_upto_distance as $key=>$value){
        $counter = $key;
        $kmRateString  .='<div class="row form-group"><div class="col-sm-2"><input type="text" class="form-control" id="kms_'.$counter.'" name="package_km_upto_to[]" value="'.$value['km_upto'].'"></div><div class="col-sm-2" ><div class="input-group"><span class="input-group-addon">Rs</span><input type="text" class="form-control" id="rs_'.$counter.'" value="'.$value['rate_per_km'].'" name="package_rate_per_km[]" ></div></div><div class="col-sm-1 removeDistanceFields"  id="removeDistanceFields_"'.$counter.'><a href="#"><i class="fa fa-trash-o fa-2x"></i></a></div><div class="col-sm-2">&nbsp;</div></div>';
   }
}


$local_package_fare = isset($fareDetails['local_package_fare'])?$fareDetails['local_package_fare']:'';
if(!empty($local_package_fare)){
    $package_fare_data = array_column($local_package_fare, 'local_pkg_fare','local_pkg_id');
}
$distance_fare = isset($fareDetails['booking_mode_fare_data'])?$fareDetails['booking_mode_fare_data']:'';
//$rate_upto_distance = isset($distance_fare['rate_upto_distance'])?$distance_fare['rate_upto_distance']:'';

$roundUpKm=0;
$accumulated_instance=0;
if(isset($distance_fare['round_up_km'])=='on'){
    $roundUpKm = 1;
}
if(isset($distance_fare['accumulated_instance'])=='on'){
  $accumulated_instance=1;
}
/*if($rate_upto_distance!=''){
   $rateUptoDistanceArr  = json_decode($rate_upto_distance);
   $kmRateSting = '';

   foreach($rateUptoDistanceArr as $key=>$value){
        $counter = $key;
        $kmRate  = explode('_',$value);
        $kmRateString  .='<div class="row form-group"><div class="col-sm-2"><input type="text" class="form-control" id="kms_'.$counter.'" name="package_km_upto_to[]" value="'.$kmRate[0].'"></div><div class="col-sm-2" ><div class="input-group"><span class="input-group-addon">Rs</span><input type="text" class="form-control" id="rs_'.$counter.'" value="'.$kmRate[1].'" name="package_rate_per_km[]" ></div></div><div class="col-sm-1 removeDistanceFields"  id="removeDistanceFields_"'.$counter.'><a href="#"><i class="fa fa-trash-o fa-2x"></i></a></div><div class="col-sm-2">&nbsp;</div></div>';

   }
}*/

echo $this->formElement($form->get('distance_fare_id')->setValue(isset($distance_fare['id'])?$distance_fare['id']:''));
?>
<div class="row">
    <div class="col-sm-12 col-md-12 mrgin20auto5">
        <div class="portlet-body padding10px">
            <h4 class="distanceRates_distance">Distance Rates</h4>
            <div class="form-group clearfix">
                <div class="col-sm-2 margin-r-5">
                    <label class="ratePerKm_distance"><?php echo $this->translate($form->get('rate_per_km')->getLabel()); ?></label>
                    <div class="input-group margin-l-5"> <span class="input-group-addon ratePerKmRupees_distance">Rs</span>
                       <?php echo $this->formElement($form->get('rate_per_km')->setValue(isset($distance_fare['per_km_charge'])?$distance_fare['per_km_charge']:'')); ?>
                    </div>
                </div>
                
                <?php if(isset($bookingType) && $bookingType!=1){ ?>

                <div class="col-sm-3">
                    <label class="firstKmRate_distance"><?php echo $this->translate($form->get('ignore_first_km_rate')->getLabel()); ?></label>
                    <div class="input-group"> <span class="input-group-addon">Km</span>
                        <?php echo $this->formElement($form->get('ignore_first_km_rate')->setValue(isset($distance_fare['minimum_distance'])?$distance_fare['minimum_distance']:'')); ?>
                        
                    </div>
                    <span class="errmsg alert-danger"></span>
                </div>
                <div class="col-sm-2 margin-l-5">
                    <label class="minimumCharge_distance"><?php echo $this->translate($form->get('minimum_fare')->getLabel()); ?></label>
                    <div class="input-group"> <span class="input-group-addon minimumChargeRupees_distance">Rs</span>
                       <?php echo $this->formElement($form->get('minimum_fare')->setValue(isset($distance_fare['minimum_charge'])?$distance_fare['minimum_charge']:'')); ?>
                    </div>
                </div>
                <?php }?>
            </div>
            <div class="col-sm-12">
                <form class="form-inline" role="form">
                    <div class="row no-margin">
                        <div class="col-sm-2 no-padding">
                          <label class="booking-check"><?php echo $this->translate($form->get('round_per_kms')->getLabel()); ?>
                                <?php echo $this->formElement($form->get('round_per_kms')->setValue($roundUpKm)); ?>
                                <span class="checkmark"></span>
                            </label>
                        </div>

                    </div>
                    <hr>

                    <h4 class="accumulated_distance">Distances</h4>
                    <p class="accumulated_distance_detail">You May Wish To Charge Different Rate Per Km Depending On The Length Of The Journey</p>
                    <div class="row" style="margin:0">
                        <div class="col-sm-3 no-padding">
                            <label class="booking-check"><?php echo $this->translate($form->get('accumulated_instances')->getLabel()); ?>
                                 <?php echo $this->formElement($form->get('accumulated_instances')->setValue($accumulated_instance)); ?>
                                <span class="checkmark"></span>
                            </label>
                        </div>

                    </div>
                </form>
                <hr>



                <div class="row">
                    <div class="col-sm-2">
                        <label class="km_upto_accumulated"><?php echo $this->translate($form->get('package_km_upto_to[]')->getLabel()); ?>  </label>
                    </div>
                    <div class="col-sm-2">
                        <label class="rate_per_km_accumulated"><?php echo $this->translate($form->get('package_rate_per_km[]')->getLabel()); ?></label>
                    </div>

                    <div class="col-sm-2 margin-left15"></div>
                    <div class="col-sm-3">&nbsp;</div>
                </div>

                <?php echo $kmRateString;?>

                <div id="mainDistanceDiv">
                    <div class="row form-group">
                        <div class="col-sm-2 margin-left0 margin-r-5">
                            <?php echo $this->formElement($form->get('package_km_upto_to[]')); ?>
                        </div>

                        <div class="col-sm-2">
                            <div class="input-group"><span class="input-group-addon">Rs</span>
                                <?php echo $this->formElement($form->get('package_rate_per_km[]')); ?>
                            </div>
                        </div>
                     <?php if(!isset($VndViewFare)){ ?>
                        <div class="col-sm-4">
                            <div class="col-sm-4 addButton no-padding" id="add_2">
                                <a href="#" class="btn btn-info form-control">Add More</a>
                            </div>
                     </div><?php }?>

                    <div class="col-sm-3">&nbsp;</div>
                     </div>
                </div>

                <div id="appended_text_form"></div>


<!--                <div class="row">
                    <div class="col-sm-3 ">
                        <label class="booking-check"><?php //echo $this->translate($form->get('update_all_rows')->getLabel()); ?>
                             <?php //echo $this->formElement($form->get('update_all_rows')); ?>
                            <span class="checkmark"></span>
                        </label>
                    </div>
                </div>-->

                <hr>
                <?php
                        if(!empty($masterlocalpkg) && $bookingMode==1){
                 ?>                       
                <div class="row">
                    <div class="col-sm-2">
                        <label><?php echo $this->translate($form->get('distance_package_name[]')->getLabel()); ?></label>
                    </div>
                    <div class="col-sm-2">
                        <label><?php echo $this->translate($form->get('distance_ignore_km[]')->getLabel()); ?></label>
                    </div>
                    <div class="col-sm-2">
                        <label><?php echo $this->translate($form->get('distance_amount[]')->getLabel()); ?></label>
                    </div>
                    <div class="col-sm-2 margin-left15"></div>
                    <div class="col-sm-3">&nbsp;</div>
                </div>
                        <?php }?>
                <!-- Add more package comment by mohitv
                <div id="DistanceDiv_package">
                    <div class="row margin-bttom10px" >
                        <div class="col-sm-2"><?php //echo $this->formElement($form->get('distance_package_name[]')); ?></div>
                        <div class="col-sm-2"><?php //echo $this->formElement($form->get('distance_ignore_km[]')); ?></div>
                        <div class="col-sm-2"><?php //echo $this->formElement($form->get('distance_amount[]')); ?></div>

                      <div class="col-sm-2 addpkg_on_plus" id="addpkgdis_1">
                           <a href="#" class="btn btn-info form-control">Add More</a>
                      </div>
                    </div>
                </div>
                <div id="appended_Dis_package"></div>-->

                 <?php
                        if(!empty($masterlocalpkg) && $bookingMode==1){
                            foreach($masterlocalpkg as $val){
                                $localId = $val['id'];
                               $fare_value =  isset($package_fare_data[$localId])?$package_fare_data[$localId]:'';
                                ?>
                   <div class="col-sm-12 no-padding margin-bttom10px">
                            <div class="col-sm-2"><?php echo $val['name']; ?></div>
                            <div class="col-sm-2"><?php echo $val['km']; ?></div>
                            <div class="col-sm-2"><?php echo $this->formElement($form->get('distance_amount[]')->setValue($fare_value)); ?></div>
                            <input type="hidden" name="localpkgid[]" value="<?php echo $localId;?>"/>
                    </div>
                <?php }} ?>


                <div class="row ">
                    <div class="col-sm-3"></div>
                    <div class="col-sm-3"></div>
                    <div class="col-sm-2 pull-right margin-r-10">
                           <?php // echo $this->formElement($form->get('next')); ?>
                    </div>
                    <?php if(!isset($VndViewFare)){ ?>
                    <div class="col-sm-2 pull-right margin-bttom10px" id="distance_fair_manage_cab_save">
                            <?php echo $this->formElement($form->get('submit_distance')); ?>
                    </div>
                    <?php } ?>
                    <div class="col-sm-2 pull-right margin-bttom10px display-none" id="distance_fair_manage_vehicle">
                        <a href="#" data-toggle="tab">
                            <button class="btn btn-info form-control">Save</button>
                        </a>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

  <?php echo $this->form()->closeTag(); ?>