<div class="row">
    <div class="container">
        <ol class="breadcrumb">
            <li><a href="#">شئون العاملين</a></li>
            <li><a href="Salaries.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="Salaries.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="form-control 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-2">
                            <input type="number" name="due_q" id="due_q" class="calc-input form-control" placeholder="ق" min="0" max="99" />
                        </div>
                        <div class="col-lg-2">
                            <input type="number" name="due_j" id="due_j" class="calc-input form-control" placeholder="جنيه" />
                        </div>
                    </div>
                     <label >الاستقطاعات :</label>
                       <div class="form-group">
                            <label class="col-lg-2 control-label">كسب</label>
                            <div class="col-lg-2">
                                <input type="number" name="earn_q" id="earn_q" class="calc-input form-control" placeholder="ق" min="0" max="99" />
                            </div>
                            <div class="col-lg-2">
                                <input type="number" name="earn_j" id="earn_j" class="calc-input form-control" placeholder="جنيه" />
                            </div>
                        </div>
                      <div class="form-group">
                        <label class="col-lg-2 control-label">دمغة</label>
                        <div class="col-lg-2">
                            <input type="number" name="stamp_q" id="stamp_q" class="calc-input form-control" placeholder="ق" min="0" max="99" />
                        </div>
                        <div class="col-lg-2">
                            <input type="number" name="stamp_j" id="stamp_j" class="calc-input form-control" placeholder="جنيه" />
                        </div>
                    </div>
                     <div class="form-group">
                        <label class="col-lg-2 control-label">ص.خ</label>
                        <div class="col-lg-2">
                            <input type="number" name="s_q" id="s_q" class="calc-input form-control" placeholder="ق" min="0" max="99" />
                        </div>
                        <div class="col-lg-2">
                            <input type="number" name="s_j" id="s_j" class="calc-input form-control" placeholder="جنيه" />
                        </div>
                    </div>
                       <div class="form-group">
                            <label class="col-lg-2 control-label">جملة المستقطع</label>
                            <div class="col-lg-4">
                                <span id="sprytextfield2">
                                    <input name="totaldeductions" type="number" step="0.01" readonly class="form-control " />
                                   
                            </div>
                        </div>
                     <div class="form-group">
                        <label class="col-lg-2 control-label" style="font-weight: bold;">صافي المستحق</label>
                        <div class="col-lg-2">
                            <input type="number" name="net_q" id="net_q" readonly class="form-control" placeholder="ق" style="background: #d4edda;" />
                        </div>
                        <div class="col-lg-2">
                            <input type="number" name="net_j" id="net_j" readonly class="form-control" placeholder="جنيه" style="background: #d4edda; 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 due_q = parseInt($('input[name="due_q"]').val()) || 0;
    let due_j = parseInt($('input[name="due_j"]').val()) || 0;
    
   let earn_q = parseInt($('#earn_q').val()) || 0;
    let earn_j = parseInt($('#earn_j').val()) || 0;
    let stamp_q = parseInt($('input[name="stamp_q"]').val()) || 0;
    let stamp_j = parseInt($('input[name="stamp_j"]').val()) || 0;
    let s_q = parseInt($('input[name="s_q"]').val()) || 0;
    let s_j = parseInt($('input[name="s_j"]').val()) || 0;

    let totalEarn = earn_j + (earn_q / 100);
    let totalDue = salary + due_j + (due_q / 100);
   let totalDeductions = totalEarn + (stamp_j + stamp_q/100) + (s_j + s_q/100);
    
    $('input[name="totaldeductions"]').val(totalDeductions.toFixed(2));

    
    let netTotal = totalDue - totalDeductions;
    let net_j = Math.floor(netTotal);
    let net_q = Math.round((netTotal - net_j) * 100);

    $('input[name="net_j"]').val(net_j);
    $('input[name="net_q"]').val(net_q);
}

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

</script>
{/literal}
 