<?php if(!class_exists('raintpl')){exit;}?><div class="modal fade" id="modal_imprimir_pedido">
   <div class="modal-dialog">
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title">Imprimir <?php  echo FS_PEDIDO;?></h4>
            <?php if( mt_rand(0,1)==0 ){ ?>

            <p class="help-block">
               Más formatos disponibles <a href="https://www.facturascripts.com/buscar?query=imprimir" target="_blank">en la web</a>.
            </p>
            <?php }else{ ?>

            <p class="help-block">
               Más formatos disponibles en el plugin <a href="https://www.facturascripts.com/plugin/plantillas_pdf" target="_blank">Plantillas PDF</a>.
            </p>
            <?php } ?>

         </div>
         <div class="modal-body">
         <?php $loop_var1=$fsc->extensions; $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

            <?php if( $value1->type=='pdf' ){ ?>

            <a href="index.php?page=<?php echo $value1->from;?><?php echo $value1->params;?>&id=<?php echo $fsc->pedido->idpedido;?>" target="_blank" class="btn btn-block btn-default">
               <?php echo $value1->text;?>

            </a>
            <?php } ?>

         <?php } ?>

         </div>
         <div class="modal-footer">
            <a href="index.php?page=admin_empresa#impresion" target="_blank">
               <span class="glyphicon glyphicon-wrench"></span>&nbsp; Opciones de impresión
            </a>
         </div>
      </div>
   </div>
</div>

<?php if( $fsc->empresa->can_send_mail() ){ ?>

<form class="form" role="form" name="f_enviar_email" action="<?php echo $fsc->url();?>" method="post" enctype="multipart/form-data">
   <input type="hidden" name="codcliente" value="<?php echo $fsc->pedido->codcliente;?>"/>
   <div class="modal" id="modal_enviar">
      <div class="modal-dialog">
         <div class="modal-content">
            <div class="modal-header">
               <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
               <h4 class="modal-title">
                  <span class="glyphicon glyphicon-envelope"></span>&nbsp;
                  Enviar <?php  echo FS_PEDIDO;?>

               </h4>
               <?php if( $fsc->pedido->femail ){ ?>

               <p class="help-block">
                  <span class="glyphicon glyphicon-send"></span> &nbsp;
                  Este <?php  echo FS_PEDIDO;?> fue enviado el <?php echo $fsc->pedido->femail;?>.
               </p>
               <?php }elseif( !in_array('CRM',$GLOBALS['plugins']) ){ ?>

               <p class="help-block">
                  Gestiona los contactos del cliente y comunícate con ellos con el
                  <a href="https://www.facturascripts.com/plugin/CRM" target="_blank">plugin CRM</a>.
               </p>
               <?php } ?>

            </div>
            <div class="modal-body">
               <div class="form-group">
                  <div class="input-group">
                     <span class="input-group-addon">De</span>
                     <select name="de" class="form-control">
                        <?php if( $fsc->user->email ){ ?>

                        <option><?php echo $fsc->user->email;?></option>
                        <?php } ?>

                        <option><?php echo $fsc->empresa->email;?></option>
                     </select>
                  </div>
               </div>
               <div class="form-group">
                  <div class="input-group">
                     <span class="input-group-addon">Para</span>
                     <?php if( $fsc->cliente_s ){ ?>

                     <input id="ac_email" class="form-control" type="text" name="email" value="<?php echo $fsc->cliente_s->email;?>" autocomplete="off"/>
                     <span class="input-group-addon" title="Asignar email al cliente">
                        <input type="checkbox" name="guardar" value="TRUE"/>
                        <span class="glyphicon glyphicon-floppy-disk"></span>
                     </span>
                     <?php }else{ ?>

                     <input id="ac_email" class="form-control" type="text" name="email" autocomplete="off"/>
                     <?php } ?>

                  </div>
               </div>
               <div class="form-group">
                  <div class="input-group">
                     <span class="input-group-addon">Copia</span>
                     <input id="ac_email2" class="form-control" type="text" name="email_copia" autocomplete="off"/>
                     <span class="input-group-addon" title="Copia de carbón oculta">
                        <input type="checkbox" name="cco" value="TRUE"/>
                        <span class="glyphicon glyphicon-eye-close"></span>
                     </span>
                  </div>
               </div>
               <div class="form-group">
                  <textarea class="form-control" name="mensaje" rows="6"><?php echo plantilla_email('pedido',$fsc->pedido->codigo,$fsc->empresa->email_config['mail_firma']); ?></textarea>
                  <p class="help-block">
                     <a href="index.php?page=admin_empresa#email">Editar la firma</a>
                  </p>
               </div>
               <div class="form-group">
                  <input name="adjunto" type="file"/>
                  <p class="help-block">
                     Se va a adjuntar el <?php  echo FS_PEDIDO;?>, pero si lo deseas
                     puedes añadir otro archivo de hasta <?php echo $fsc->get_max_file_upload();?> MB
                  </p>
               </div>
               <div class="btn-group">
                  <button type="button" class="btn btn-sm btn-primary dropdown-toggle" data-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
                     <span class="glyphicon glyphicon-send"></span>&nbsp; Enviar <span class="caret"></span>
                  </button>
                  <ul class="dropdown-menu">
                  <?php $loop_var1=$fsc->extensions; $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

                     <?php if( $value1->type=='email' ){ ?>

                     <li>
                        <a href="#" onclick="this.disabled=true;enviar_email('index.php?page=<?php echo $value1->from;?><?php echo $value1->params;?>&id=<?php echo $fsc->pedido->idpedido;?>');"><?php echo $value1->text;?></a>
                     </li>
                     <?php } ?>

                  <?php } ?>

                  </ul>
               </div>
            </div>
         </div>
      </div>
   </div>
</form>
<?php }else{ ?>

<div class="modal" id="modal_enviar">
   <div class="modal-dialog">
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title">
               <span class="glyphicon glyphicon-envelope"></span>&nbsp; Enviar por email
            </h4>
         </div>
         <div class="modal-body">
            <a href='index.php?page=admin_empresa#email' class="btn btn-sm btn-warning">
               <span class="glyphicon glyphicon-wrench"></span>&nbsp; Configurar
            </a>
         </div>
      </div>
   </div>
</div>
<?php } ?>


<form class="form" role="form" action="<?php echo $fsc->url();?>&status=1" method="post">
   <div class="modal" id="modal_aprobar">
      <div class="modal-dialog modal-sm">
         <div class="modal-content">
            <div class="modal-header">
               <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
               <h4 class="modal-title">Aprobar <?php  echo FS_PEDIDO;?> y facturar</h4>
            </div>
            <div class="modal-body">
               <div class="form-group">
                  Fecha de la <?php  echo FS_FACTURA;?>:
                  <input class="form-control datepicker" type="text" name="facturar" value="<?php echo $fsc->today();?>" autocomplete="off"/>
                  <p class="help-block">Se generará una <?php  echo FS_FACTURA;?>.</p>
               </div>
               <div class="text-right">
                  <button class="btn btn-sm btn-primary" onclick="this.disabled=true;this.form.submit();">
                     <span class="glyphicon glyphicon-paperclip"></span>&nbsp; Aprobar
                  </button>
                   <?php echo $fsc->url();?>&status=1
               </div>
            </div>
         </div>
      </div>
   </div>
</form>

<form action="<?php echo $fsc->ppage->url();?>" method="post">
   <input type="hidden" name="delete" value="<?php echo $fsc->pedido->idpedido;?>"/>
   <div class="modal fade" id="modal_eliminar">
      <div class="modal-dialog">
         <div class="modal-content">
            <div class="modal-header">
               <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
               <h4 class="modal-title">¿Realmente desea eliminar este <?php  echo FS_PEDIDO;?>?</h4>
            </div>
            <?php if( $fsc->pedido->idalbaran ){ ?>

            <div class="modal-body bg-warning">
               Hay un <?php  echo FS_ALBARAN;?> asociado, pero no será eliminado.
            </div>
            <?php } ?>

            <div class="modal-footer">
               <button class="btn btn-sm btn-danger" onclick="this.disabled = true;this.form.submit();">
                  <span class="glyphicon glyphicon-trash"></span>&nbsp; Eliminar
               </button>
            </div>
         </div>
      </div>
   </div>
</form>

<div class="modal fade" id="modal_versionesp" tabindex="-1" role="dialog">
   <div class="modal-dialog modal-lg" role="document">
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
               <span aria-hidden="true">&times;</span>
            </button>
            <h4 class="modal-title">
               <i class="fa fa-retweet" aria-hidden="true"></i> Versiones del <?php  echo FS_PEDIDO;?>

            </h4>
            <p class="help-block">Estas son todas las versiones de <?php  echo FS_PEDIDO;?> actual.</p>
         </div>
         <div class="table-responsive">
            <table class="table table-hover">
               <thead>
                  <tr>
                     <th></th>
                     <th class="text-left">Código + <?php  echo FS_NUMERO2;?></th>
                     <th class="text-left">Cliente</th>
                     <th class="hidden-sm"></th>
                     <th class="text-left">Observaciones</th>
                     <th class="text-right">Total</th>
                     <th class="text-right">Fecha</th>
                  </tr>
               </thead>
               <?php $loop_var1=$fsc->versiones; $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

               <tr class='clickableRow<?php if( $value1->status==1 ){ ?> success<?php }elseif( $value1->status==2 ){ ?> danger<?php }elseif( $value1->total<=0 ){ ?> warning<?php } ?>' href="<?php echo $value1->url();?>">
                  <td class="text-center">
                     <?php if( $value1->idalbaran ){ ?>

                     <span class="glyphicon glyphicon-paperclip" title="El <?php  echo FS_PEDIDO;?> tiene vinculado un <?php  echo FS_ALBARAN;?>"></span>
                     <?php } ?>

                     <?php if( $value1->status==2 ){ ?>

                     <span class="glyphicon glyphicon-remove" title="El <?php  echo FS_PEDIDO;?> ha sido rechazado"></span>
                     <?php } ?>

                     <?php if( $value1->femail ){ ?>

                     <span class="glyphicon glyphicon-send" title="El <?php  echo FS_PEDIDO;?> fue enviado por email el <?php echo $value1->femail;?>"></span>
                     <?php } ?>

                  </td>
                  <td>
                     <?php if( $value1->idpedido==$fsc->pedido->idpedido ){ ?>

                     <b class="text-capitalize"><?php  echo FS_PEDIDO;?> actual</b>
                     <?php }else{ ?>

                     <a href="<?php echo $value1->url();?>"><?php echo $value1->codigo;?></a> <?php echo $value1->numero2;?>

                     <?php } ?>

                     <?php if( $value1->totaliva==0 ){ ?><span class="label label-warning">Sin <?php  echo FS_IVA;?></span><?php } ?>

                     <?php if( $value1->totalrecargo!=0 ){ ?><span class="label label-default">RE</span><?php } ?>

                     <?php if( $value1->totalirpf!=0 ){ ?><span class="label label-default"><?php  echo FS_IRPF;?></span><?php } ?>

                  </td>
                  <td><?php echo $value1->nombrecliente;?></td>
                  <td class="text-right hidden-sm">
                     <span title="<?php echo $value1->numdocs;?> documentos adjuntos">
                     <?php if( $value1->numdocs==1 ){ ?>

                     <i class="fa fa-file" aria-hidden="true"></i>
                     <?php }elseif( $value1->numdocs>1 ){ ?>

                     <?php echo $value1->numdocs;?> <i class="fa fa-file" aria-hidden="true"></i>
                     <?php } ?>

                     </span>
                  </td>
                  <td><?php echo $value1->observaciones_resume();?></td>
                  <td class="text-right" title="<?php echo $fsc->show_precio($fsc->euro_convert($value1->totaleuros, $value1->coddivisa, $value1->tasaconv));?>">
                     <?php echo $fsc->show_precio($value1->total, $value1->coddivisa);?>

                  </td>
                  <td class="text-right" title="Hora <?php echo $value1->hora;?>">
                     <?php if( $value1->fecha==$fsc->today() ){ ?><b><?php echo $value1->fecha;?></b><?php }else{ ?><?php echo $value1->fecha;?><?php } ?>

                  </td>
               </tr>
               <?php }else{ ?>

               <tr class="warning">
                  <td></td>
                  <td colspan="7">Ninguna versión encontrada.</td>
               </tr>
               <?php } ?>

            </table>
         </div>
         <div class="modal-footer">
            <a class="btn btn-sm btn-success" href="<?php echo $fsc->url();?>&nversion=TRUE" title="Nueva versión del <?php  echo FS_PEDIDO;?>">
               <i class="fa fa-retweet" aria-hidden="true"></i>
               <span class="hidden-xs">&nbsp; Nueva versión</span>
            </a>
         </div>
      </div>
   </div>
</div>

<div class="modal" id="modal_historico">
   <div class="modal-dialog modal-lg">
      <div class="modal-content">
         <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-label="Close">
               <span aria-hidden="true">&times;</span>
            </button>
            <h4 class="modal-title">
               <i class="fa fa-book" aria-hidden="true"></i>
               Histórico del <?php  echo FS_PEDIDO;?> <?php echo $fsc->pedido->codigo;?>

            </h4>
         </div>
         <div class="table-responsive">
            <table class="table table-hover">
               <thead>
                  <tr>
                     <th>Tipo</th>
                     <th>Documento</th>
                     <th class="text-right">Importe</th>
                     <th class="text-right">Fecha</th>
                  </tr>
               </thead>
               <tbody>
                  <tr class="warning">
                     <td class="text-capitalize"><?php  echo FS_PEDIDO;?></td>
                     <td><b>Este <?php  echo FS_PEDIDO;?></b></td>
                     <td class="text-right"><?php echo $fsc->show_precio($fsc->pedido->total, $fsc->pedido->coddivisa);?></td>
                     <td class="text-right"><?php echo $fsc->pedido->fecha;?></td>
                  </tr>
                  <?php $loop_var1=$fsc->historico; $counter1=-1; if($loop_var1) foreach( $loop_var1 as $key1 => $value1 ){ $counter1++; ?>

                  <tr>
                     <td class="text-capitalize"><?php echo $value1['documento'];?></td>
                     <td>
                        <a href="<?php echo $value1['modelo']->url();?>" target="_blank"><?php echo $value1['modelo']->codigo;?></a>
                        <?php if( $value1['modelo']->numero2 ){ ?><?php echo $value1['modelo']->numero2;?><?php } ?>

                     </td>
                     <td class="text-right"><?php echo $fsc->show_precio($value1['modelo']->total, $value1['modelo']->coddivisa);?></td>
                     <td class="text-right"><?php echo $value1['modelo']->fecha;?></td>
                  </tr>
                  <?php } ?>

               </tbody>
            </table>
         </div>
      </div>
   </div>
</div>