<?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');
}
</script>
<?php
//Mercados
$o_ClienteSystemClass = new ClienteSystemClass(new TipoNegocioBean());
$a_Mercado = $o_ClienteSystemClass->LoadMercadoXRol();
?>
<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="35%" 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>