
<section class="content">
    <div class="row">
        <div class="col-sm-12">
            <div class="box" style="border-top: 2.5px solid #9fc10b;">
                <div class="box-body">
                    <?php echo (isset($trader['id']))?form_open("traders/edit/".$trader['id']):form_open("traders/add");?>
                    <fieldset class="warehouse-border">
                        <legend class="warehouse-border">
                            <h4><?=lang("personal_information")?></h4>
                        </legend>
                        <div class="row">
                            <div class="col-md-2">
                                <div class="form-group">
                                    <label for="traderCode"><?=lang("trader_code")?> *</label>
                                    <input id="traderCode" class="form-control" type="text" name="traderCode" value="<?=isset($trader['cod_vend'])?$trader['cod_vend']:set_value('traderCode')?>">
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label for="documentType"><?=lang("document_type")?> *</label>
                                    <select id="documentType" class="form-control" name="documentType" id="documentType">
                                    <option value=""><?=lang("select")?></option>
                                       <?php
                                        foreach($documents_type as $document) { ?>
                                            <option value="<?=$document['code']?>" <?=(isset($trader['type_document']) && $trader['type_document'] == $document['code'])?'selected':((set_value('documentType')==$document['code'])?"selected":"")?> ><?=$document['description']?></option>
                                        <?php }?>
                                    </select>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label for="my-input"><?=lang("document_number")?> *</label>
                                    <div class="input-group">
                                        <input id="documentNumber" class="form-control" type="text" name="documentNumber" value="<?=isset($trader['document'])?$trader['document']:set_value('documentNumber')?>">
                                        <span class="input-group-btn">
                                            <button id="search-doc" class="btn btn-primary" type="button"><i class="fa fa-search" aria-hidden="true"></i></button>
                                        </span>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label for=""><?=lang("name")?> *</label>
                                    <input type="text" name="name" id="name" class="form-control" placeholder="" value="<?=isset($trader['name'])?$trader['name']:set_value('name')?>">
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label for=""><?=lang("fathers_lastname")?> *</label>
                                    <input type="text" name="fathersLastName" id="fathersLastName" class="form-control" placeholder="" value="<?=isset($trader['last_name_1'])?$trader['last_name_1']:set_value('fathersLastName')?>">
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label for="MotherLastName"><?=lang("mothers_lastname")?> *</label>
                                    <input type="text" name="MotherLastName" id="MotherLastName" class="form-control" placeholder="" value="<?=isset($trader['last_name_2'])?$trader['last_name_2']:set_value('MotherLastName')?>">
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label for="birthDate"><?=lang("birth_date")?> * </label>
                                    <input type="date" class="form-control" name="birthDate" id="birthDate"  max="<?= date("Y-m-d",strtotime(date('Y-m-d')."- 17 year")); ?>" value="<?=isset($trader['birth_date'])?$trader['birth_date']:set_value('birthDate')?>">
                                </div>
                            </div>
                            <div class="col-md-2">
                                <div class="form-group">
                                    <label for="Gender"><?=lang("gender")?> *</label>
                                    <select class="form-control form-control-sm" name="gender" id="Gender">
                                        <option value = ""><?=lang('select')?></option>
                                        <option value="M" <?=(isset($trader['gender']) && $trader['gender']== "M")?'selected':((set_value('gender')=== "M")?"selected":"")?>><?=lang("male")?></option>
                                        <option value="F" <?=(isset($trader['gender']) && $trader['gender']== "F")?'selected':((set_value('gender')=== "F")?"selected":"")?>><?=lang("female")?></option>
                                        <option value="O" <?=(isset($trader['gender']) && $trader['gender']== "O")?'selected':((set_value('gender')=== "O")?"selected":"")?>><?=lang("other")?></option>
                                    </select>
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-6">
                                <div class="form-group">
                                    <label for="address"><?=lang("address")?></label>
                                    <input type="text" name="address" id="address" class="form-control" placeholder="" value="<?=isset($trader['address'])?$trader['address']:set_value('address')?>">
                                </div>
                            </div>
                        </div>
                        <div class="row">
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label for="departament"><?=lang("departament")?></label>
                                    <select class="form-control form-control-sm" name="departament" id="departament">
                                    <option value="0"><?=lang("select")?></option>
                                       <?php
                                        foreach($departamentList as $departament) { ?>
                                            <option value="<?=$departament['id']?>" <?=(isset($trader['codDepa']) && $trader['codDepa'] == $departament['id'])?'selected':((set_value('departament')==$departament['id'])?"selected":"")?>><?=$departament['description']?></option>
                                        <?php }?>
                                    </select>
                                </select>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label for="province"><?=lang("province")?></label>
                                    <select class="form-control form-control-sm" name="province" id="province">
                                    <option value="0"><?=lang("select")?></option>
                                </select>
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label for="district"><?=lang("district")?></label>
                                    <select class="form-control form-control-sm" name="district" id="district">
                                    <option value="0"><?=lang("select")?></option>
                                </select>
                                </div>
                            </div>
                        </div>
                    </fieldset>
                    <fieldset class="warehouse-border">
                        <legend class="warehouse-border">
                            <h4><?=lang("contact_information")?></h4>
                        </legend>
                        <div class="row">
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label for="phone"><?=lang("phone")?> 1</label>
                                    <input type="phone1" class="form-control" name="phone1" id="phone1" placeholder=""  value="<?=isset($trader['movil'])?$trader['movil']:set_value('phone1')?>">
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label for="phone2"><?=lang("phone")?> 2</label>
                                    <input type="text" class="form-control" name="phone2" id="phone2" placeholder=""  value="<?=isset($trader['movil_2'])?$trader['movil_2']:set_value('phone2')?>">
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <label for="email"><?=lang("email")?></label>
                                    <input type="mail" class="form-control" name="email" id="email" placeholder=""  value="<?=isset($trader['email'])?$trader['email']:set_value('email')?>">
                                </div>
                            </div>
                        </div>
                    </fieldset>
                    <!--<fieldset>
                        <legend>Datos de usuario
                            <input type="text" name="" id="">
                        </legend>
                        <div class="row">
                            <div class="col-md-3">
                               <div class="form-group">
                                 <label for="">Usuario</label>
                                 <select class="form-control" name="" id="">
                                   <option></option>
                                   <option></option>
                                   <option></option>
                                 </select>
                               </div>
                            </div>
                        </div>
                    </fieldset>-->
                    <fieldset>
                        <legend></legend>
                        <div class="row">
                            <div class="col-md-12 text-right">
                                <button type="submit" class="btn btn-primary"><?=lang("accept")?></button>
                                <a id = "btn-cancel" class="btn btn-danger"><?=lang("cancel")?></a>
                            </div>
                        </div>
                    </fieldset>
                    <?php echo form_close();?>
                </div>
            </div>
        </div>
    </div>
</section>

<script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>
<script src="<?= $assets ?>dist/js/pages/traders.js" type="text/javascript"></script>
<?php if(isset($trader['ubigeo']) && !empty($trader['ubigeo'])){ ?>
 <script>
   $(document).ready(function() {
    $('#departament').trigger('change');
    $('#province > option[value="<?=$trader['codProv']?>"]').attr('selected', 'selected');
    $('#province').trigger('change');
    $('#district > option[value="<?=$trader['ubigeo']?>"]').attr('selected', 'selected');
   
});
 </script>
<?php }?>