

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

        <ol class="breadcrumb">
            <li><a href="#">خصائص عامة</a></li>
            <li><a href="clientController.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 nameToBeChecked" role="form" action="clientController.php?do=add" method="post" id="spform">

                    {/literal}

                    <div class="form-group">
                        <span style="   font-size: 17px; color: red;text-align: center;margin-right: 211px;">  {if !empty($msg)}{$msg}{/if}</span>
                    </div>


                    <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">اسم العميل</label>
                        <div class="col-lg-4">

                            <span id="sprytextfield1">

                                <input type="text" name="txtName" id="txtName" class="form-control" placeholder="اسم العميل"/>
                                <span class="textfieldRequiredMsg">ادخل اسم العميل</span></span>



                            <div id="nameError" class="alert alert-block alert-danger fade in" style="display:none">
                                <button type="button" class="close pull-left" data-dismiss="alert" aria-hidden="true">&times;</button>
                                <h4>رسالة خطا</h4>
                                <p>هذا الاسم مستخدم من قبل</p>

                                <div class="clearfix"></div>
                            </div>


                        </div>
                    </div>


                    {if $Programsettingdata->clientcode eq 1}

                    <div class="form-group">
                        
                        <label for="txtName" class="col-lg-2 control-label">{$Programsettingdata->clientcodname}</label>
                        <div class="col-lg-4">
                            <input type="text" name="clientcode" id="clientcode" class="form-control" placeholder="{$Programsettingdata->clientcodname}"/>
                            <div id="clientcodeError" class="alert alert-block alert-danger fade in" style="display:none">
                                <button type="button" class="close pull-left" data-dismiss="alert" aria-hidden="true">&times;</button>
                                <h4>رسالة خطا</h4>
                                <p>هذا الكود مستخدم من قبل</p>

                                <div class="clearfix"></div>
                            </div>
                            <div class="clearfix"></div>
                        </div>
                    </div>

                    {/if}

                    {if $Programsettingdata->clientserial eq 1}
                    <!-- =================================================   -->
                    <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">الرقم التسلسلي</label>
                        <div class="col-lg-4">

                            <input type="text" name="clientid" disabled id="clientid" class="form-control" value="{$nextId}"/>

                            <div class="clearfix"></div>
                        </div>


                    </div>
                    <!-- =================================================   -->
                    {/if}

                    <!-- =================================================   -->
                    <!--                    <div class="form-group">
                                            <label for="txtAddress" class="col-lg-2 control-label">المحافظة </label>
                                            <div class="col-lg-4">
                                                <span id="spryselect1">
                                                    <select name="clientgovernmentid" id="clientgovernmentid"  data-placeholder="اختر " class="select2 wdt100">


                                                        <option value="0">اختر المحافظة </option>
                                                        {foreach $allGovernment as $government}
                                                        <option value="{$government->governmentid}">{$government->governmentname} </option>
                                                        {/foreach}
                                                    </select>
                                                    <span class="selectInvalidMsg">اختر المحافظة</span></span>

                                            </div>
                                        </div>-->
                    <!-- =================================================   -->


                    <div class="form-group">
                        <label for="txtDebt" class="col-lg-2 control-label">أصل المديونية</label>
                        <div class="col-lg-4">

                            <div class="input-group"> <span id="sprytextfield4">
                                    <input type="text" name="txtDebt" id="txtDebt"  class="form-control positivefloat" placeholder="اصل المديونية" />
                                    <span class="textfieldRequiredMsg">ادخل اصل المديونية</span><span class="textfieldInvalidFormatMsg">ادخل رقم </span></span><span class="input-group-addon">{$currency}</span>
                            </div>

                        </div>
                        <!--span style="   font-size: 17px; color: red;text-align: center;">  {if !empty($checkNo)}{$checkNo}{/if}</span-->
                    </div>

                    <!-- =================================================   -->
                    <div class="form-group">
                        <label for="txtAddress" class="col-lg-2 control-label">العنوان</label>
                        <div class="col-lg-4">
                            <input type="text" name="txtAddress" required="required" id="txtAddress" class="form-control" placeholder="العنوان"/>
                        </div>
                    </div>

                    <!-- =================================================   -->
                    <div class="form-group">
                        <label for="txtName" class="col-lg-2 control-label">رقم التليفون</label>
                        <div class="col-lg-4">
                            <input type="text" value="" name="txtPhone" id="txtPhone" required class="form-control  " />
                        </div>
                    </div>
                    <!-- =================================================   -->
                    <div class="form-group">
                        <label for="txtMobile" class="col-lg-2 control-label">رقم الموبايل</label>
                        <div class="col-lg-4">
                            <input type="text" name="txtMobile" id="txtMobile" class="form-control positiveNo" placeholder="رقم الموبايل"/>
                        </div>
                    </div>

                    <!-- =================================================   -->
                    <div class="form-group">
                        <label for="txtAddress" class="col-lg-2 control-label">الشركة - المنطقة</label>
                        <div class="col-lg-4">
                            <span id="spryselect1">
                                <input type="hidden" name="clientareaid" value="" id="clientareaid"/>
                                <span class="selectInvalidMsg">اختر الشركة - المنطقة</span></span>

                        </div>
                    </div>

                    <!-- =================================================   -->

                    <div class="form-group">
                        <label for="textDetails" class="col-lg-2 control-label">التعليق</label>
                        <div class="col-lg-4">

                            <textarea  class="form-control" rows="3" name="textDetails" id="textDetails"></textarea>

                        </div>
                    </div>

                    <!-- =================================================   -->
                    <div class="form-group">
                        <label for="textDetails" class="col-lg-2 control-label">المخزن</label>
                        <div class="col-lg-3">
                            <label>
                                <input type="checkbox" class="ckstore" name="store_all" id="store_all" checked="checked" value="1" />
                                كل المخازن
                            </label>
                        </div>
                        {foreach $stores as $data}
                        <div class="col-lg-3">
                            <label>
                                <input type="checkbox" class="clientStore ckstore" name="store{$data->storeId}" id="store{$data->storeId}" checked="checked" value="1" />
                                {$data->storeName}
                            </label>
                        </div>
                        {/foreach}
                    </div>
                    <!-- =================================================   -->
                    <div class="form-group">
                        <label for="textDetails" class="col-lg-2 control-label">نوع العميل</label>
                        <div class="col-lg-3">
                            <label>
                                <input type="checkbox" class="cktype" name="typeClient_all" id="typeClient_all" checked="checked" value="1" />
                                كل انوع العملاء
                            </label>
                        </div>
                        {foreach $typeClient as $data}
                        <div class="col-lg-3">
                            <label>
                                <input type="checkbox" class="typeClient cktype" name="type{$data->typeId}" id="type{$data->typeId}" checked="checked" value="1" />
                                {$data->typeName}
                            </label>
                        </div>
                        {/foreach}
                    </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">
    $('#store_all').live('click', function () {
        if ($(this).attr('checked') == 'checked') {
            $('.clientStore').attr('checked', 'checked');
            $('.clientStore').attr('disabled', 'disabled');
        }
        else
        {
            $('.clientStore').removeAttr('checked');
            $('.clientStore').removeAttr('disabled');
        }
    });
    $('#spbutton').live('click', function (e) {
        //ckeck name
        var tableName = 'client';
        var inputName = 'txtName';
        var name = $("#" + inputName).val();
        $.ajax({
            url: 'checkRedundantNames.php?name=' + name + '&tablename=' + tableName,
            success: function (data) {
                //alert(data);
                if (data == '0')
                {
                    $("#nameError").css("display", "none");
                    //return true;
                    //check code
                    /*----------------------------------------------------*/
                    var tableName = 'clientcode';
                    var inputName = 'clientcode';
                    var name = $("#" + inputName).val();
                    $.ajax({
                        url: 'checkRedundantNames.php?name=' + name + '&tablename=' + tableName,
                        success: function (data) {
                            //alert(data);
                            if (data == '0')
                            {
                                $("#clientcodeError").css("display", "none");
                                //return true;


                                var myForm = document.getElementById("spform");
                                var SS = Spry.Widget.Form.validate(myForm);
                                if (SS == true) {
                                    var aStoreIsSelected = 0;
                                    $('.ckstore').each(function () {
                                        if ($(this).attr('checked') == 'checked') {
                                            aStoreIsSelected = 1;
                                            return;
                                        }
                                    });
                                    if (aStoreIsSelected == 1) {
                                        if (!$('#spbutton').hasClass("processing"))
                                        {
                                            $('#spbutton').addClass("processing");
                                            myForm.submit();
                                            //$('#spbutton').unbind('click');
                                        }
                                    } else {
                                        alert('عفوا لابد من اختيار مخزن على الاقل');
                                    }
                                }


                            } else if (data == '1')
                            {
                                $("#" + inputName).val("");
                                $("#" + inputName).focus();
                                $("#clientcodeError").css("display", "block");
                                return false;
                            }
                        }});

                    /*----------------------------------------------------*/

                } else if (data == '1')
                {
                    $("#" + inputName).val("");
                    $("#" + inputName).focus();
                    $("#nameError").css("display", "block");
                    return false;
                }
            }});

    });
</script>

{/literal}

{literal}
<script type="text/javascript">
$("#spbutton").click(function(e) {

    alert(222);
     if ($('#spform').validate().form()) {
			alert('valid');
                    }
                    
   $("#spform").validate();
    
    alert(111);

   
    }

    );
</script>
{/literal}
