<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">شئون العاملين</a></li>
            <li><a href="engineerallowance.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="engineerallowance.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="value" id="value" type="number" class="calc-input form-control"  />
                        </div>
                    </div>
                    
                    <label>استقطاعات :</label>
                     <div class="form-group">
                      <label class="col-lg-2 control-label">صندوق خدمة</label>
                        <div class="col-lg-4">
                            <input name="service_box" id="service_box" 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="earn" id="earn" 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="stamp" id="stamp" 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="total_deductions" id="total_deductions" 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="total_earns" id="total_earns" 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="notes" id="notes" type="text" 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="other_additions" id="other_additions" 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="other_discounts" id="other_discounts" type="number" class="calc-input 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 value    = parseFloat($('#value').val()) || 0;
    let service_box = parseFloat($('#service_box').val()) || 0;
   
    let earn       = parseFloat($('#earn').val()) || 0;
    let stamp     = parseFloat($('#stamp').val()) || 0;
   let totalDeductions = service_box + earn + stamp ;
    $('#total_deductions').val(totalDeductions.toFixed(2));
      let totalEarn = value - totalDeductions;
    $('#total_earns').val(totalEarn.toFixed(2));
}

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

</script>
{/literal}
 