<?php use_helper( 'UrlFunctions' ); ?>
<?php
//error_reporting(E_ALL);
//ini_set('display_errors','On'); //PARA PRODUCCION "Off"
$s_User = myUser::getUser()->getUserId();
if( isset( $i_IdDel ) && $i_IdDel != "" && myUser::getUser()->getRoleId() == 'sys.gen')
{
    $o_Cr_pedido_prestamoDP = new Cr_pedido_prestamoDP();
    $o_Cr_pedido_prestamoDP->setIdpedido( ( int ) $i_IdDel );
    $o_Cr_pedido_prestamoDP->setEliminado( 1 );
    $o_Cr_pedido_prestamoDP->setUsuarioEliminado( $s_User );
    $o_Cr_pedido_prestamoDP->setFechaEliminado( date( "Y-m-d H:i:s" ) );
    $b_Result = $o_Cr_pedido_prestamoDP->update();
    if( $b_Result )
    {
        ?>
        <script>
        location.href = "<?php echo buildUrl( 'ped/his', "block={$block}" ) ?>";
        </script>
        <?php
    }
}elseif(isset( $i_IdDel )&& myUser::getUser()->getRoleId() != 'sys.gen'){
	?>
	<script>
		alert('No se permite eliminar!!');
	</script>
	<?php
}
?>
<script>
findControl = function()
{
    concatValueStr();
}
concatValueStr = function(){
    strFormSerialize = $('form1').serialize();
    if( arguments[0] )
    {
        strFormSerialize += '&'+arguments[0];
    }
    executeFind( strFormSerialize );
}
executeFind = function( str )
{ 
    url = "<?=buildUrl('ped/hisgrid', "block=001")?>";
    var myAjax  = new Ajax.Updater(
                                    "resultGrtid",
                                    url,
                                    {
                                        asynchronous:    true,
                                        method            : 'get',
                                        parameters    : str,
                                        evalScripts    : true,
                                        onLoading   : cargandoImagenSerch(),
                                        onComplete    : function(){
                                            //objMainTab.showMenu();
                                        }
                                    });
}
function cargandoImagenSerch(){
	//disabledWin.setPathImage('/images/common/progress.gif');
	disabledWin.show(true,true,'resultGrtid');
}


acutalizarMercado = function(destino,elm){
  $(destino).options.length = 1;
  var url = '<?=buildUrlComplet('mnt.php/ajax/request')?>';
  var pars = 'type=getMercado&nombreElm='+destino+'&value='+elm.value;
  
	var myAjax = new Ajax.Request(
                            		url, 
                            		{
                            			method: 'get', 
                            			parameters: pars, 
                            			onComplete: actualizaJSON
                            		});
}

actualizaJSON = function(request, json){
  var numeroElementos = json.length;
  for (var i = 0; i < numeroElementos; i++){
    if($(json[i][0])){
  	  switch ($(json[i][0]).tagName){
  	    case 'TD'      : Element.update(json[i][0], json[i][1]); break;
  	    case 'INPUT'   : $(json[i][0]).value=json[i][1]; break;
  	    case 'SELECT'  : 
  	      var objDDL = $(json[i][0]);
  	      if(typeof(cont) == 'undefined'){
  	        var cont = 0;
  	        objDDL.options.length = 1;
  	      }
  	      var a_contentValues = json[i][1].split("_;_");
      		var value	= a_contentValues[0];
      		var text	= a_contentValues[1];
  	      var option	= new Option(text,value);
      		try{
      			objDDL.add(option,null);
      		}catch (e){
      			objDDL.add(option,-1);
      		}
  	      cont++;
  	    break;
  	  }
    }else{
      if(json[i][0].indexOf("function") > -1){
        eval("scriptEval = "+json[i][0]);
        scriptEval();
      }
    }
  }
}
</script>
<?php
//Mercados
$o_ClienteSystemClass = new ClienteSystemClass(new TipoNegocioBean());
$a_Mercado = $o_ClienteSystemClass->LoadMercadoXRol();

$o_SucursalBean = new SucursalBean();
$o_SucursalBL = new SucursalBL();
$a_Sucursal = $o_SucursalBL->busquedaSucursal($o_SucursalBean);

?>
<fieldset>
    <div class="titleBody descripProy">
        <li>
            Historial de Pedidos
            <!--<input type="button" title="Registrar" onclick="objMainTab.modalDialog( '<?php echo buildUrl('cus/addedit', 'block=001&i_Id=' ) ?>',{'width':900})" value="Registrar" class="button">-->
        </li>
    </div>
    <div class="block">
        <form action="" method="post" name="form1" id="form1">
            <table width="100%" cellspacing="0" cellpadding="0" border="0">
                <tr>
                    <td>
                
                        <table width="100%" cellspacing="0" cellpadding="0" border="0">
                        
                            <tr>
                                <td width="25%" nowrap="nowrap">
                                    <table width="100%" cellspacing="1" cellpadding="0" border="0" class="SubCabecera">
                                        <tr>
                                        	<td width="14%" height="26" nowrap="nowrap" class="cabecera"><label class="label" for="txtNombre">Sucursal</label></td>
					                        <td width="25%" nowrap="nowrap">
				    		                      	 <select name="cboSucursal" id="cboSucursal" type="text" class="combo" onchange="acutalizarMercado('cboMercado',this);"/> 
										 	            <option value="" > - Seleccionar - </option>
								                        <?php foreach ($a_Sucursal as $iKey => $o_SucursalBean){ ?>
								                        <option value="<?=$o_SucursalBean->getIdSucursal()?>">
								                          <?=$o_SucursalBean->getDescripcion()?>
								                        </option>
								                        <?php } ?> 
									              </select>
		                       				</td>
                                            <td nowrap="nowrap">
                                                <div class="field-label">
                                                    <label for="Nombre" class="label">Mercado :</label>
                                                </div>
                                            </td>
                                            <td nowrap="nowrap">
                                                <select name="cboMercado" id="cboMercado" type="text" class="combo"/> 
                                                    <option value="" > - Seleccionar - </option>
                                                    <?php foreach ($a_Mercado as $iKey => $o_MercadoBean){ ?>
                                                    <option value="<?=$o_MercadoBean->getIdMercado()?>">
                                                    <?=$o_MercadoBean->getDescripcion()?>
                                                    </option>
                                                    <?php } ?> 
                                                </select>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                                <td width="25%" nowrap="nowrap">
                                    <table width="100%" cellspacing="1" cellpadding="0" border="0" class="SubCabecera">
                                        <tr>
                                            <td width="35%" nowrap="nowrap">
                                                <div class="field-label">
                                                    <label for="Estado" class="label">Nro Cliente :</label>
                                                </div>
                                            </td>
                                            <td nowrap="nowrap"><input type="text" class="text" name="IdCliente" id="IdCliente" /></td>
                                        </tr>
                                    </table>
                                </td>
                                <td width="20%" nowrap="nowrap">
                                    <table width="100%" cellspacing="1" cellpadding="0" border="0" class="SubCabecera">
                                        <tr>
                                            <td width="35%" nowrap="nowrap">
                                                <div class="field-label">
                                                    <label for="estado" class="label">Nro Pedido :</label>
                                                </div>
                                            </td>
                                            <td nowrap="nowrap"><input type="text" class="text" name="IdPedido" id="IdPedido" /></td>
                                        </tr>

                                    </table>
                                    
                                </td>
                            </tr>
                            
                            <tr>
                                <td width="25%" nowrap="nowrap">
                                    <table width="100%" cellspacing="1" cellpadding="0" border="0" class="SubCabecera">
                                        <tr>
                                            <td width="35%" nowrap="nowrap">
                                                <div class="field-label">
                                                    <label for="txtFechaIni" class="label">Fecha Inicio :</label>
                                                </div>
                                            </td>
                                            <td nowrap="nowrap">
                                                <input class="text" type="text" ondblclick="this.value=''" size="8" maxlength="10" name="txtFechaIni" id="txtFechaIni" value='' /><button type="button" onclick="return false" id="btnFechaIni">...</button></td>
                		                         <script type="text/javascript">
                		                            document.getElementById("txtFechaIni").disabled = false;
                		                            Calendar.setup({
                		                              inputField : "txtFechaIni",
                		                              ifFormat : "%Y-%m-%d",
                		                              daFormat : "%Y-%m-%d",
                		                              button   : "btnFechaIni"
                		                            });
                		                         </script>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                                <td width="25%" nowrap="nowrap">
                                    <table width="100%" cellspacing="1" cellpadding="0" border="0" class="SubCabecera">
                                        <tr>
                                            <td width="35%" nowrap="nowrap">
                                                <div class="field-label">
                                                    <label for="txtFechaFin" class="label">Fecha Final :</label>
                                                </div>
                                            </td>
                                            <td nowrap="nowrap">
                                                <input class="text" type="text" ondblclick="this.value=''" size="8" maxlength="10" name="txtFechaFin" id="txtFechaFin" value='' /><button type="button" onclick="return false" id="btnFechaFin">...</button></td>
                		                         <script type="text/javascript">
                		                            document.getElementById("txtFechaFin").disabled = false;
                		                            Calendar.setup({
                		                              inputField : "txtFechaFin",
                		                              ifFormat : "%Y-%m-%d",
                		                              daFormat : "%Y-%m-%d",
                		                              button   : "btnFechaFin"
                		                            });
                		                         </script>
                                            </td>
                                        </tr>
                                    </table>
                                </td>
                                <td width="20%" nowrap="nowrap">
                                	 <table width="100%" cellspacing="1" cellpadding="0" border="0" class="SubCabecera">
                                        <tr>
                                            <td width="35%" nowrap="nowrap">
                                               <label for="txtFechaFin" class="label"> Estado</label>
			                                </td>
			                                <td  nowrap="nowrap">
			                                   <select name="cboEstado" id="cboEstado" type="text" class="combo"> 
			  								   <option value="" > -Seleccione - </option>
			  								  <option value="P" selected="selected"> - Pediente - </option>
			  								  <option value="A" > - Aprobado - </option>
			  								  <option value="R" > - Rechazado - </option>
			  								  </select>
			                                </td>
                                        </tr>
                                    </table>
                                   
                            </tr>
                            
                        </table>
                    
                    </td>
                    
                    <td>
                        <input type="button" onclick="findControl();" value="Buscar" id="btn_frmFindFeaturesTpl" class="button">
                    </td>
                </tr>
            </table>
            
    
        </form>
    </div>
</fieldset>
<div id="resultGrtid" style=""></div>
<div id="resultContent" style=""></div>
<script>
findControl();
</script>
<script>
eliminarCabecera = function( i_Id )
{
    var x = confirm( "Esta seguro de eliminar el registro?" );
    if( x )
    {
        location.href = "<?php echo buildUrl( 'ped/his', "block=001&i_IdDel=" ) ?>" + i_Id;
    }
}
</script>