<input type="hidden" name="percentageDiscount" id="percentageDiscount" value="{$Usergroupdata->percentageDiscount}"/>
<input type="hidden" name="stopDiscountOfTotalControl" id="stopDiscountOfTotalControl" value="{$Usergroupdata->stopDiscountOfTotalControl}"/>
<input type="hidden" name="discountOfTotalControlEditable" id="discountOfTotalControlEditable" value="{$Usergroupdata->discountOfTotalControlEditable}"/>
<input type="hidden" name="discountOfTotalControlMTGDA" id="discountOfTotalControlMTGDA" value="{$Usergroupdata->discountOfTotalControlMTGDA}"/>
<input type="hidden" name="psid" id="psid" value="{$restaurantPlaystationPlay->playstationid}"/>
<input type="hidden" name="deviceIdentification" id="deviceIdentification" value="{$restaurantPlaystationPlay->deviceIdentification}"/>
<input type="hidden" name="subDeviceIdentification" id="subDeviceIdentification" value="{$restaurantPlaystationPlay->subDeviceIdentification}"/>
<input type="hidden" name="useSubIdentification" id="psid" value="{$restaurantPlaystationPlay->useSubIdentification}"/>
<input type="hidden" name="printBill" id="printBill" value="0"/>
<input type="hidden" name="endRestaurantTable" id="endRestaurantTable" value="0"/>
<input type="hidden" name="playstationTableId" id="playstationTableId" value="{$restaurantPlaystationPlay->tableId}"/>
<div class="main-menu orderDetails">
    <div id="deliveryPart">
        <div class="form-group col-md-12">
            <label class="col-lg-3 control-label">العميل </label>
            <div class="col-lg-6" id="clientDiv">
                <input type="hidden" id="client" name="client"  class="wdt100"  data-placeholder="اختر عميل " />
            </div>

            <label class="col-lg-1 control-label">الدين</label>
            <div class="col-lg-2" id="activeUserDebt">

            </div>
        </div>

        <div class="form-group col-md-12">
            <label class="col-lg-3 control-label">الوقت </label>
            <div class="col-lg-6">
                <input type="text" id="startTime" name="startTime" readonly class="form-control" value="{$restaurantPlaystationPlay->startTime} - {$restaurantPlaystationPlay->endTime}"/>
            </div>

            {$restaurantPlaystationPlay->durationInText}

        </div>
        <div class="form-group col-md-12">
            <label class="col-lg-3 control-label">سعر الساعة </label>
            <div class="col-lg-6">
                <input type="text" id="hourPrice" name="hourPrice" readonly class="form-control" value="{if $restaurantPlaystationPlay->priceIs == 0}{$restaurantPlaystationPlay->hourPrice}{else}{$restaurantPlaystationPlay->hourPriceMulti}{/if}"/>
            </div>
        </div>
        <div class="form-group col-md-12">
            <label class="col-lg-3 control-label">الاجمالى</label>
            <div class="col-lg-6">
                <input type="text" readonly id="totalPrice" name="totalPrice" class="form-control positivefloat calcNet" value="{$restaurantPlaystationPlay->totalPrice}"/>
            </div>
        </div>
        <div class="form-group col-md-12">
            <label class="col-lg-3 control-label">الخصم</label>
            <div class="col-lg-6">
                <input type="text" id="discount" name="discount" class="form-control positivefloat calcNet" value="0"/>
            </div>
        </div>

        <!--        {if $Programsettingdata->thereIsRestTax == 1}
                show and hide it
                {if $Programsettingdata->taxNameFlag == 1}خدمة{else}الضريبة{/if}
                <input type="text" name="billTax" id="billTax" value=""/>

                {/if}
                <input type="hidden" name="thereIsRestTax" id="thereIsRestTax" value="{$Programsettingdata->thereIsRestTax}"/>-->
        <div class="form-group col-md-12">
            <label class="col-lg-3 control-label">الصافى</label>
            <div class="col-lg-6">
                <input type="text" readonly id="netPrice" name="netPrice" class="form-control positivefloat" value="{$restaurantPlaystationPlay->totalPrice}"/>
            </div>
        </div>
        <div class="form-group col-md-12">
            <label class="col-lg-3 control-label">المدفوع</label>
            <div class="col-lg-6">
                <input type="text" readonly id="payed" name="payed" class="form-control positivefloat" value="{$restaurantPlaystationPlay->totalPrice}"/>
            </div>
        </div>
        <div class="form-group col-md-12">
            <label class="col-lg-3 control-label">تعليق</label>
            <div class="col-lg-6">
                <textarea class="form-control" id="billComment" name="billComment"></textarea>
            </div>
        </div>

    </div>

</div>
{literal}
<script>
    var psid = $('#psid').val();
    $('#endPlayModalTitle').html("تفاصيل " + $('li[data-id="' + psid + '"]').first().data('name'));
    $(".positivefloat").forcepositivefloat();
    var stopDiscountOfTotalControl = $('#stopDiscountOfTotalControl').val();
    var discountOfTotalControlMTGDA = $('#discountOfTotalControlMTGDA').val();
    $("#client").select2({
        dropdownParent: $('#endPlayModal'), //to avoid hiding options behind modal//not working
        placeholder: "اختر عميل ",
        minimumInputLength: 0,
        //  minimumInputLength: 3,
        multiple: false,
        quietMillis: 100,
        ajax: {
            url: "billsajax.php?do=getclients",
            dataType: 'json',
            data: function (term, page) {
                //  alert(term);
                return {
                    term: term, //search term
                    page_limit: 10, // page size
                };
            },
            results: function (data) {
                // alert(term);
                return {results: data};
            }
        },
        formatResult: function (data) {
            return  data.text;
        },
        initSelection: function (element, callback) {
            var item = element.val().split(':');
            var data = {id: item[0], text: item[1]};
            callback(data);
        }
    });
    $("#client").live('change', function (e) {
        $('#activeUserDebt').html($("#client").select2('data').clientdebt);
    });
    $(".calcNet").live('keyup', function (e) {

        var generaldiscount = Number($('#discount').val());
        var genetalprice = Number($('#totalPrice').val());

        var percentageDiscount = document.getElementById("percentageDiscount").value;
        var directDiscount = ((Number(percentageDiscount) / 100) * genetalprice).toFixed(2);

        //يوجد خصم للمجموعة ومسموح بتخطى الخصم اذن نجعل الخصم يصل ل 100%
        if (stopDiscountOfTotalControl == 1 && discountOfTotalControlMTGDA == 0) {
            percentageDiscount = 100;//make max discount 100% of bill value not more
            directDiscount = (Number(percentageDiscount) / 100) * genetalprice;

        }
        //لو الخصم اكبر من المسموح بيه
        if (generaldiscount >= genetalprice || generaldiscount >= directDiscount)
        {
            if (directDiscount >= genetalprice)
            {
                $('#discount').val(genetalprice);
            } else
            {
                $('#discount').val(directDiscount);
            }
        } else
        {
            $('#discount').val(generaldiscount);
        }
        var generaldiscount = $('#discount').val();

        var net = (genetalprice - generaldiscount).toFixed(1);
        $('#netPrice').val(net);
    });
</script>
{/literal}