<div class="row">
    <div class="container">

        <ol class="breadcrumb">
            <li><a href="#">نظام المطالبة</a></li>
            <li><a href="claimdebtController.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="form-horizontal" action="claimdebtController.php" id="claimformajax" method="post"
                    enctype="multipart/form-data" data-dosave="?do=savedata" data-direction="">
                    {/literal}

                    <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">المطالبات </label>
                        <div class="col-lg-4">
                            <input id="claimid" type="text"  name="claimid" class="getselectjoin claimid"  data-placeholder=" اختر     "   data-table="claims" data-tableid="id"  
                            data-join="  "  data-filter=" and claims.del < 2 and claims.stoptrue = 1 and claims.debttrue = 0 "
                            data-parent="" data-itr=""  data-search="id,'/',claim_number,'/',claim_value"/>  
                            <input type="hidden" class="selectedit" data-id="{$claim->id}" data-text="{$claim->id}/{$claim->claim_number}/{$claim->claim_value}"  data-table="claimid" />
                          
                        </div>
                    </div>


                    <div class="form-group">
                        <label class="col-lg-2 control-label">طريقة الدفع</label>
                        <div class="col-lg-4">
                            <div class="radio-inline">
                                <label>
                                    <input value="0"  name="paymethod" id="pmsave" class="pmethod" checked="checked"   type="radio" />خزنة </label>
                            </div>
                            <div class="radio-inline">
                                <label>
                                    <input value="1" name="paymethod" id="pmbank" class="pmethod" type="radio" />بنك</label>
                            </div>
                        </div>
                    </div>


                    <div id="save-div">
                        {if $searchinonesave == 1}
                        <input type="hidden" name="saveid" id="saveid" value="{$allSave}" />
                        {else}
                        <div class="form-group">
                            <label class="col-lg-2 control-label">خزنة</label>
                            <div class="col-lg-4">
                                <select name="saveid" id="saveid" class="select2">
                                    <option value="-1">اختر</option>
                                    {foreach $allSave as $data}
                                    <option value="{$data.saveid}" {if $saveid == $data.saveid}selected{/if}>{$data.savename}</option>
                                    {/foreach}
                                </select>
                            </div>
                        </div>
                        {/if}
                    </div>  

                    <div id="bank-div" style="display: none">
                        <div class="form-group">
                            <label class="col-lg-2 control-label">بنك</label>
                            <div class="col-lg-4">
                                <span id="spryselect4">
                                    <select name="bankid"  id="bankid" class="select2" data-placeholder="اختر البنك">
                                        <option value="-1">اختر</option>
                                        {foreach $banks as $data}
                                        <option value="{$data.bankid}">{$data.bankname}</option>
                                        {/foreach}
                                    </select>
                                    <span class="selectInvalidMsg">{$smarty.const.EXPENSES_CHOOSE_ELBANK}</span></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <label class="col-lg-2 control-label">الحساب</label>
                            <div class="col-lg-4">
                                <span id="spryselect5">

                                    <input id="bankaccountid" type="text"  name="bankaccountid" class="getselectjoin bankaccountid"  data-placeholder=" اختر الحساب     "   data-table=" bankaccount" data-tableid="accountid"  data-join=""  data-filter=" and bankaccount.conditions = 0 "  data-parent="bankid" data-itr=""  data-search="accountname,'/',accountnumber"/>  
                                   
                                    <span class="selectInvalidMsg">{$smarty.const.EXPENSES_CHOOSE_ACCOUNT}</span></span>
                            </div>
                        </div>
                    </div>




                    <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">قيمة المطالبة    </label>
                        <div class="col-lg-4"> <span id="sprydate">
                                <input required="required" type="text" name="claim_value" 
                                class="form-control  nummbers" placeholder="" readonly 
                                data-table="claims" id="claim_value" data-tableid="" data-parentid=""
                                data-parentcol="" value="{$claim->claim_value}" />
                                <span class="textfieldRequiredMsg">*</span></span>
                        </div>
                    </div>


                    <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">رقم المعملة     </label>
                        <div class="col-lg-4"> <span id="sprydate">
                                <input required="required" type="text" name="transaction_number" 
                                class="form-control checkcolumn  nummbers" placeholder=""  data-tablecol="transaction_number"
                                data-table="claimdebts" id="transaction_number" data-tableid="" data-parentid=""
                                data-parentcol=""  />
                                <span class="textfieldRequiredMsg">*</span></span>
                        </div>
                    </div>


                    <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">الخصم    </label>
                        <div class="col-lg-4"> <span id="sprydate">
                                <input required="required" type="text" name="direct_debit" 
                                class="form-control  nummbers" placeholder=""  
                                data-table="claims" id="direct_debit" data-tableid="" data-parentid=""
                                data-parentcol="" value="" />
                                <span class="textfieldRequiredMsg">*</span></span>
                        </div>
                    </div>

                     <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">نسبة الضريبه    </label>
                        <div class="col-lg-4"> <span id="sprydate">
                                <input required="required" type="text" name="tax_rate" 
                                class="form-control  nummbers" placeholder=""  
                                data-table="claims" id="tax_rate" data-tableid="" data-parentid=""
                                data-parentcol="" value="" />
                                <span class="textfieldRequiredMsg">*</span></span>
                        </div>
                    </div>

                     <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">الضريبة    </label>
                        <div class="col-lg-4"> <span id="sprydate">
                                <input required="required" type="text" name="direct_tax" 
                                class="form-control  nummbers" placeholder=""   readonly="" 
                                data-table="claims" id="direct_tax" data-tableid="" data-parentid=""
                                data-parentcol="" value="" />
                                <span class="textfieldRequiredMsg">*</span></span>
                        </div>
                    </div>

                    <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">التعليق</label>
                        <div class="col-lg-4">
                            <textarea class="form-control" name="claim_debtcomment" rows="2" placeholder=""></textarea>
                        </div>
                    </div>

                    <div class="form-group">
                        <div class="col-lg-offset-2 col-lg-4">
                            <button type="button" class="btn btn-primary pull-left saveformajax" data-form="claimformajax" data-action="0">حفظ الامر</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script type="text/javascript">
    $(document).ready(function () {
        selectedit2();

        $('.pmethod').live('change', function () {
            if ($(this).val() == 0) {
                $('#save-div').show();
                 $('#bank-div').hide();
            } else {
                $('#save-div').hide();
                 $('#bank-div').show();
            }
        });


        $('#claimid').live('change', function () {
            window.location.href = "claimdebtController.php?do=&id="+$(this).val();
        });


        $('#tax_rate').live('change', function () {
            var claim_value = Number($('#claim_value').val());
            var direct_debit = Number($('#direct_debit').val());
            var tax_rate = Number($(this).val());
            $('#direct_tax').val(((claim_value - direct_debit) * tax_rate) / 100);
        });
    });
</script>