<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">شئون العاملين</a></li>
            <li><a href="Rewards.php?do=show">مرتبات بعد سن المعاش </a></li>
            <li class="active">اضافة</li>
        </ol>
        <div class="panel panel-default panel-m">
            <div class="panel-heading">
                <h3 class="panel-title">اضافة</h3>
            </div>
            <div class="panel-body"> {literal}
                <form class="nameToBeChecked form-horizontal" role="form" action="Rewards.php?do=add"
                      method="post" enctype="multipart/form-data" id="spform">
                    {/literal}

                    <!-- =================================================   -->
                   <div class="form-group">
                        <label class="col-lg-2 control-label">الموظف</label>
                         <div class="col-lg-4">
                            <span>
                        <select name="name" class=" select2" required data-placeholder="اختر الموظف" class="select2 wdt100" >
                             <option value="-1">اختر الموظف</option>
                            {foreach $showData as $data}
                                <option value="{$data.id}">{$data.name}</option>
                            {/foreach}
                        </select>
                        </span>
                        </div>
                    </div>
                    <div class="form-group">
                   <label class="col-lg-2 control-label">عن شهر :</label>
                   <div class="col-lg-4">
                            <select name="month" id="month" class="form-control">
                                <option value="-1">-- اختر الشهر --</option>
                                <option value="1">يناير</option>
                                <option value="2">فبراير</option>
                                <option value="3">مارس</option>
                                <option value="4">أبريل</option>
                                <option value="5">مايو</option>
                                <option value="6">يونيو</option>
                                <option value="7">يوليو</option>
                                <option value="8">أغسطس</option>
                                <option value="9">سبتمبر</option>
                                <option value="10">أكتوبر</option>
                                <option value="11">نوفمبر</option>
                                <option value="12">ديسمبر</option>
                            </select>
                        </div>
                    </div>
                    
                     <label >الاستحقاقات :</label>
                    
                         
                        <div class="form-group">
                            <label class="col-lg-2 control-label">اساسي</label>
                            <div class="col-lg-4">
                                <span id="sprytextfield2">
                                    <input name="salary" id="salary" type="number" class="calc-input form-control " />
                                   
                            </div>
                        </div>
                        <div class="form-group">
                      <label class="col-lg-2 control-label">بدل انتقال</label>
                        <div class="col-lg-4">
                            <input name="move_val" id="move_val" type="number" class="calc-input form-control" placeholder="0" />
                        </div>
                        </div>
                        <div class="form-group">
                      <label class="col-lg-2 control-label">بدل جهود</label>
                        <div class="col-lg-4">
                            <input name="efforts_val" id="efforts_val" type="number" class="calc-input form-control" placeholder="0" />
                        </div>
                    </div>
                        <div class="form-group">
                      <label class="col-lg-2 control-label">بدل طبيعة العمل</label>
                        <div class="col-lg-4">
                            <input name="nature_val" id="nature_val" type="number" class="calc-input form-control" placeholder="0" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-2 control-label" style="font-weight: bold;">إجمالي الاستحقاقات</label>
                        <div class="col-lg-4">
                            <input name="total_earn" id="total_earn" type="number" readonly class="form-control" style="background: #e9ecef; font-weight: bold;" />
                        </div>
                    </div>
                     <label >الاستقطاعات :</label>
                       <div class="form-group">
                           <label class="col-lg-2 control-label">سلفة الجمعية</label>
                        <div class="col-lg-4">
                            <input name="advance" id="advance" type="number" class="calc-input form-control" placeholder="0" />
                        </div>
                    </div>
                      <div class="form-group">
                           <label class="col-lg-2 control-label">ص.خ</label>
                        <div class="col-lg-4">
                            <input name="skh" id="skh" type="number" class="calc-input form-control" placeholder="0" />
                        </div>
                    </div>
                         <div class="form-group">
                           <label class="col-lg-2 control-label">كسب</label>
                        <div class="col-lg-4">
                            <input name="earn" id="earn" type="number" class="calc-input form-control" placeholder="0" />
                        </div>
                    </div>
                         <div class="form-group">
                           <label class="col-lg-2 control-label">دمغة</label>
                        <div class="col-lg-4">
                            <input name="stamp" id="stamp" type="number" class="calc-input form-control" placeholder="0" />
                        </div>
                    </div>
                         <div class="form-group">
                           <label class="col-lg-2 control-label">الجزاءات</label>
                        <div class="col-lg-4">
                            <input name="penalties" id="penalties" type="number" class="calc-input form-control" placeholder="0" />
                        </div>
                    </div>
                         <div class="form-group">
                           <label class="col-lg-2 control-label">ض.سنوات سابقة</label>
                        <div class="col-lg-4">
                            <input name="tax" id="tax" type="number" class="calc-input form-control" placeholder="0" />
                        </div>
                    </div>
                    <div class="form-group">
                        <label class="col-lg-2 control-label" style="font-weight: bold;">إجمالي الاستقطاعات</label>
                        <div class="col-lg-4">
                            <input name="deductions" id="deductions" type="number" readonly class="form-control" style="background: #e9ecef; font-weight: bold;" />
                        </div>
                    </div>
                    
                    <div class="form-group">
                        <label class="col-lg-2 control-label" style="font-weight: bold;">صافي المستحق</label>
                        <div class="col-lg-4">
                            <input name="net" id="net" type="number" readonly class="form-control" style="background: #e9ecef; font-weight: bold;" />
                        </div>
                    </div>
                    
                       <div class="form-group">
                            <label class="col-lg-2 control-label">ملاحظات</label>
                            <div class="col-lg-4">
                                <span id="sprytextfield2">
                                    <input name="comment" type="text" class="form-control " />
                                   
                            </div>
                        </div>


                       
                    
                    <!-- =================================================   -->
                    <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-4">
                            <button type="button" class="btn btn-primary pull-left" id="spbutton">حفظ</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>

{literal}
<script type="text/javascript">
    var sprytextfield1 = new Spry.Widget.ValidationTextField("sprytextfield1");
    var sprytextfield2 = new Spry.Widget.ValidationTextField("sprytextfield2");
    $('#spbutton').live('click', function (e) {
        if (!$('#spbutton').hasClass("processing")) {
            $('#spbutton').addClass("processing");
            var myForm = document.getElementById("spform");
            var SS = Spry.Widget.Form.validate(myForm);
            if (SS == true) {
                myForm.submit();
            } else {
                $('#spbutton').removeClass("processing");
            }
        }
    });
$(document).ready(function() {
    $('#nature').on('change', function() {
        if ($(this).val() === 'other') {
            $('#other_input_container').show();
        } else {
            $('#other_input_container').hide(); 
            $('#other_nature').val(''); 
        }
    });
});
$(document).ready(function(){
    $('#name').on('change', function() {
        let sideValue = $(this).find(':selected').data('side');
        if (sideValue) {
                $('#side').val(sideValue);
            } else {
                $('#side').val(''); 
            }
        });
});

function doCalculation() {
    let salary = parseFloat($('#salary').val()) || 0;
    let move_val    = parseFloat($('#move_val').val()) || 0;
    let efforts_val = parseFloat($('#efforts_val').val()) || 0;
    let nature_val  = parseFloat($('#nature_val').val()) || 0;
    let advance   = parseFloat($('#advance').val()) || 0;
    let skh       = parseFloat($('#skh').val()) || 0;
    let earn      = parseFloat($('#earn').val()) || 0;
    let stamp     = parseFloat($('#stamp').val()) || 0;
    let penalties = parseFloat($('#penalties').val()) || 0;
    let tax       = parseFloat($('#tax').val()) || 0;
    let totalEarn = salary + move_val + efforts_val + nature_val;
    $('#total_earn').val(totalEarn.toFixed(2));
   let totalDeductions = advance + skh + earn + stamp + penalties + tax;
    $('#deductions').val(totalDeductions.toFixed(2));
  
    
   let netTotal = totalEarn - totalDeductions;
    $('#net').val(netTotal.toFixed(2));
}

$(document).on('input', '.calc-input', function() {
    doCalculation();
});

</script>
{/literal}
 