<section class="content">
    <div class="row">
        <div class="col-sm-12">
            <div class="tabbable">
                <div class="tab-content no-border padding-24">
                    <div class="tab-pane fade in active" id="faq-tab-1">
                        <div class="space-8"></div>
                        <div class="panel-group accordion-style1 accordion-style2" id="faq-list-1">
                            <div class="panel panel-default">
                                <div class="panel-headingnew"><?php echo $this->translate('Fees'); ?> </div>
                                <div class="left_panel col-sm-12 padding_margin0 pull-left bgwhite">
                                    <?php echo $this->partial('menu-sidebar.phtml'); ?>
                                    <div class="tab-content tab_editprofile col-sm-10 padding-left0 marginbott10px margintop10px">
                                        <div id="common-tab" class="tab-pane fade in tab_editprofile tab_editprofile1 active">
                                            <div class="col-sm-col-sm-offset-1 margin-10auto0 paddingRL10px">
                                                <?php
                                                $form = $this->form;
                                                $form->prepare();
                                                $form->setAttribute('action', $this->url('setting', ['action' => 'add-waiting-fees-fare']));
                                                $form->setAttribute('method', 'post');
                                                echo $this->form()->openTag($form);


                                    $waiting_fee_upto = isset($fareDetails['waiting_fare']) ? $fareDetails['waiting_fare'] : '';
//echo '<pre>';print_r($waiting_fee_upto);die();

                                                $kmRateString = "";
                                                if ($waiting_fee_upto != '') {
                                                    //$waiting_fareArr  = json_decode($waiting_fee_upto);
                                                    $kmRateSting = '';
                                                    foreach ($waiting_fee_upto 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="waiting_time_minutes_upto[]" value="' . $value['waiting_minute_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['waiting_fees'] . '" name="waiting_time_fees[]" ></div></div><div class="col-sm-1 removeWaitingFeeFieldsUser"  id="removeDistanceFields_"' . $counter . '><a href="#"><i class="fa fa-trash-o fa-2x"></i></a></div><div class="col-sm-2">&nbsp;</div></div>';
                                                    }
                                                }
                                                ?>

                                                <div class="row">
                                                    <div class="col-sm-12">
                                                        <div class="col-sm-12 col-md-12">
                                                            <div class="portlet-body">
                                                                <h4 class="cancellationFees_distance">Waiting Fees</h4>
                                                                <div class="row form-group">
                                                                    <div class="col-sm-3 form-group">                   
                                                                        <h4>Booking Type</h4>
<?php echo $this->FormElement($form->get('booking_type')->setValue(isset($waiting_fee_upto[0]['booking_type']) ? $waiting_fee_upto[0]['booking_type'] : '')); ?>
                                                                    </div>
                                                                </div>
                                                                <h4 class="waitingTime_hour">Waiting Time Fees</h4>
                                                                <p class="waitingTimeDetail_hour">You Can Charge An Additional Fee For Waiting Time Upto 10 Minutes, Another From 11- 20 Minutes, And So On</p>

            <div class="col-sm-12">
        <div class="col-sm-2">
            <label class="waitingMinutesUpTo_hour">
                <?php echo $this->translate($form->get('waiting_time_minutes_upto[]')->getLabel()); ?>
            </label>
        </div>

        <div class="col-sm-2">
            <label class="waitingFee_hour"><?php echo $this->translate($form->get('waiting_time_fees[]')->getLabel()); ?></label>
        </div>
            <div class="col-sm-3"></div>
            </div>

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

                <div class="col-sm-2">
                    <div class="input-group"><span class="input-group-addon">Rs</span><?php echo $this->formElement($form->get('waiting_time_fees[]')->setValue('')); ?>
                    </div>
                </div>

                <div class="col-sm-4"><div class="col-sm-4 addWaitingFeeUser no-padding" id="addWaitingFee_3 ">
                        <a href="#" class="btn btn-info form-control">Add More</a></div>
                    <div class="col-sm-2">&nbsp;</div>
                </div>
            </div>
        </div>

                                                                <div id="append_waiting_fee"></div>
<?php echo $kmRateString; ?>

                                                                <hr>





                                                                <div class="row ">
                                                                    <div class="col-sm-3"></div>
                                                                    <div class="col-sm-3"></div>
                                                                    <div class="col-sm-2 pull-right margin-bttom10px">
<?php echo $this->formElement($form->get('save')); ?>
                                                                    </div>
                                                                </div>
                                                            </div>
                                                        </div>
                                                        <div class="col-sm-4 col-md-4"></div>
                                                    </div>
                                                </div>

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

                                                <span class="checkbox_error"></span>                                                
                                                <div class="panel panel-default">
                                                    <div class="panel-headingnew"> View/Update Records </div>
                                                    <div id="faq-1-3" class="panel-collapse collapse in" aria-expanded="false">
                                                        <div class="box">
                                                            <!-- /.box-header -->
                                                            <div class="box-body table-responsive listing-data">
<?php echo $this->partial('waiting-fees-listing.phtml'); ?>
                                                            </div>
                                                            <!-- /.box-body -->
                                                        </div>
                                                    </div>
                                                </div>

                                            </div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
        <br>
        <!-- /.widget-box -->
    </div>
    <!-- /.col -->
</section>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script type="text/javascript">
    $(document).on('click', '.addWaitingFeeUser', function () {
        var addButtonId = $(this).attr('id');
        var counterArr = addButtonId.split("_");
        var counter = counterArr[1];
        counter++;
        var detailsdiv = "";
        detailsdiv += '<div class="row form-group"><div class="col-sm-2"><input type="text" name="waiting_time_minutes_upto[]" id="fair_waiting_minutes_' + counter + '" class="form-control" ></div><div class="col-sm-2"><div class="input-group"><span class="input-group-addon">Rs</span><input type="text" name="waiting_time_fees[]" id="fair_waiting_fees_' + counter + '" class="form-control" ></div></div><div class="col-sm-1 removeWaitingFeeFieldsUser"  id="removeDistanceFields_"' + counter + '><a href="#"><i class="fa fa-trash-o fa-2x"></i></a></div><div class="col-sm-3">&nbsp;</div></div>';
        appendedWaitingLength++;
        $("#append_waiting_fee").append(detailsdiv);
        return false;

    });

    $(document).on('click', '.removeWaitingFeeFieldsUser', function () {
        var addId = $(".addWaitingFeeUser").attr('id');
        var addIdArr = addId.split("_");
        var counter = addIdArr[1];
        counter--;
        $(this).closest('.row').remove();
        return false;

    });
</script>

