<?php
//This file is part of NOALYSS and is under GPL 
//see licence.txt
?><TABLE style="width: auto" class="nowrap">
<TR>
<TD><?php echo _('Type de journal')?> </TD>
<TD>
<?php echo $type;?>
</TD>
</TR>

<TR>

		<TD><?php echo _('Nom journal')?> </TD>
		<TD> <INPUT TYPE="text" class="input_text" NAME="p_jrn_name" VALUE="<?php	echo $name;	?>"></TD>
                <td></td>
</TR>
<?php
//---------------------------------------------------------------------------------------------------------------
//ODS
//---------------------------------------------------------------------------------------------------------------
if ( $new || $type=='ODS' ):
?>
<TR id="type_ods">
<td style="white-space: nowrap"><?php echo _('Postes utilisables journal (débit/crédit) ')?>
</TD>
<td>
<?php echo $search;?>
</TD>
<TD CLASS="notice">
<?php echo _("Uniquement pour les journaux d'Opérations Diverses, les valeurs sont séparées par des espaces, on peut aussi
	utiliser le * pour indiquer 'tous les postes qui en dépendent' exemple: 4*")?>
</TD>
</TR>
<?php
endif;
?>
<?php
//---------------------------------------------------------------------------------------------------------------
//FIN
//---------------------------------------------------------------------------------------------------------------
if ( $new|| $type=='FIN') :
?>
    <tr id="type_fin">
    <td style="white-space: nowrap">
        <?php echo _('Numérotation de chaque opération')?>
    </td>
    <td>
        <?php echo $num_op->input();?>
    </td>
    </tr>
    <tr id="type_fin2">
    <TD style="white-space: nowrap">
    <?php echo _('Compte en banque')?>
    </td>
    <TD>
    <?php
    $card=new ICard();
    $card->name='bank';
    // clean only the INPUT no javascript
    $card->setAfter_clean("");
    $card->extra=$cn->make_list('select fd_id from fiche_def where frd_id=4');
    $card->set_dblclick("fill_ipopcard(this);");
    $card->set_function('fill_data');
    $card->set_attribute('ipopup','ipop_card');
    $list=$cn->make_list('select fd_id from fiche_def where frd_id=4');
    $card->set_attribute('typecard',$list);

    $card->value=$qcode_bank;
    echo $card->search();
    echo $card->input();
    echo $str_add_button;

    ?>
    </td>
    <td class="notice" style="white-space: nowrap">
    <?php echo _("Obligatoire pour les journaux FIN : donner ici la fiche du compte en banque utilisée")?>
    </td>
    </tr>
    <?php
endif;
?>
        
<?php
//---------------------------------------------------------------------------------------------------------------
//ACH / VEN
//---------------------------------------------------------------------------------------------------------------
if ( $type == 'ACH' || $type == 'VEN'||$new):
    // Display the warning : always used negative amounts
    ?>
    
    <tr id="neg_amount">
        <td style="white-space: nowrap">
            
            <?php 
            echo _("Uniquement note de débit ou crédit");
            echo Icon_Action::warnbulle(73);
            ?>
        </td>
        <td>
           <?php
                $negative->javascript="toggle_row_warning_enable('negative_amount','row_warning')";
                echo $negative->input();
            ?>
        </td>


    </tr>
    <tr id="row_warning">
        <td style="white-space: nowrap">
            <?php echo _("Avertissement montant positif"); ?>
        </td>
        <td>
            <?php echo $negative_warning->input();?>
        </td>
    </tr>
    <tr>
        <td>
            <?php echo _('Utilisation des quantités')?>
        </td>
        <td>

        <?php
            echo $quantity->input();
        ?>
        </td>
    </tr>
<?php
endif;
?>
    
    
    
<tr>
	<td style="white-space: nowrap"><?php echo _("Minimum de lignes à afficher")?></td>
<td><?php echo $min_row->input()?></td>
</tr>
<tr>
<td><INPUT TYPE="hidden" id="p_jrn_deb_max_line" NAME="p_jrn_deb_max_line" VALUE="10"></td>
</tr>
<tr><td><INPUT TYPE="hidden" id="p_ech_lib" NAME="p_ech_lib" VALUE="echeance"></td>
</tr>
<tr>
    <td style="width: 200px">
    <?php echo _('Description') ?>
    </TD>
    <td style="width: 500px">
     <?php echo $str_description; ?>   
    </td>
</tr>    

<TR>
<TD><?php echo _('Préfixe code interne')?> </TD><TD>
<?php echo $code?> </TD>
</TR>
<TR>
<TD><?php echo _('Préfixe pièce justificative')?>
    <?php echo Icon_Action::infobulle(39);?>
</TD>
<TD>
<?php echo $pj_pref; ?>
</TD>
</TR>
    <tr>
    <td>
        <?=_("Nombre de chiffres du numéro de pièce, remplissage avec des 0 ")?>
    </td>
        <td>
            <?=$padding->input()?>
        </td>
    </tr>

</TR>
<?php if ( $new == 0 ) : ?>
    <TR>
    <TD>
      <?php echo _('Dernière pièce numérotée')?>
      <?php echo Icon_Action::infobulle(40);?>
    </TD>
    <TD>

    <?php echo str_pad($last_seq,$this->jrn_def_pj_padding??0,'0',STR_PAD_LEFT)?>
    </TD>
    </TR>

    <tr>
    <TD><?php echo _('N° pièce justificative')?>
        <?php echo Icon_Action::infobulle(38);?>
    </TD>
    <TD>
        <?php echo $pj_seq; ?>

    </TD>
    </tr>
    <tr>
        <td>
            <?=_("Journal actif")?>
        </td>
        <td>
            <?=$actif->input()?>
        </td>
    </TR>
<?php endif; ?>
<?php

    // if the ledger is financial and has no operation let choose the currency
 if ( $new == 1 || $type == 'FIN'):
?>
<tr id="type_fin3">
    <td>
        <?php echo _("Devise")?>
    </td>
    <td>
        <?php echo $default_currency->input();?>
    </td>
</tr>
<?php
endif;
?>
</TABLE>
<hr>
    <?php
    /////////////////// ACH //////////////////////////////////
    if ( $new ==1 || $type=='ACH' ) : 
        ?>
    <div id='ACH_div' >
    <h2 class="h-section" > Fiches </h2>
    <TABLE class="result" style="width:80%;margin-left:10%;">
        <tr>
            <th>
                <?php echo _("Services, fournitures ou biens  achetés (D)");?>
            </th>
            <th>
                <?php echo _("Fournisseurs (C)"); ?>
            </th>
        </tr>
    
        
    <?php
    // Show the fiche in deb section
    $Res=$cn->exec_sql("select fd_id,fd_label from fiche_def order by fd_label");
    $num=$cn->size();
    // default card for ACH
    if ($new == 1)
    {
        $rdeb=$default_deb_purchase;
        $rcred=$default_cred_purchase;
    }
    
    for ($i=0;$i<$num;$i++) {
      $res=$cn->fetch($i);
      $CHECKED=" unchecked";
       foreach ( $rdeb as $element) {
        if ( $element == $res['fd_id'] ) {
          $CHECKED="CHECKED";
          break;
        }
      }
            echo '<tr>';
      printf ('<TD> <INPUT TYPE="CHECKBOX" VALUE="%s" NAME="ACH_FICHEDEB[]" class="ach_fichedeb" %s>%s</TD>',
              $res['fd_id'],$CHECKED,$res['fd_label']);
      $CHECKED=" unchecked";
      foreach ( $rcred as $element) {
        if ( $element == $res['fd_id'] ) {
          $CHECKED="CHECKED";
          break;
        }
      }
      printf ('<TD> <INPUT TYPE="CHECKBOX" VALUE="%s" NAME="ACH_FICHECRED[]" class="ach_fichecred" %s>%s</TD>',
              $res['fd_id'],$CHECKED,$res['fd_label']);
      echo '</TR>';
    }
    ?>
    </TABLE>
</div>
<?php /////////////////// ACH //////////////////////////////////
 endif; 
 ?>
<?php
    /////////////////// VEN //////////////////////////////////
    if ( $new ==1  || $type=='VEN' ) : 
        ?>
    <div id='VEN_div' >
    <h2 class="h-section"> Fiches </h2>
    <TABLE class="result" style="width:80%;margin-left:10%;">
        
        <tr>
            <th>
                <?php echo _("Clients (D)");?>
            </th>
            <th>
                <?php echo _("Services, fournitures ou biens  vendus (C)");?>
            </th>
        </tr>
    
        
    <?php
    // Show the fiche in deb section
    $Res=$cn->exec_sql("select fd_id,fd_label from fiche_def order by fd_label");
    $num=$cn->size();
    // default card for VEN
    if ($new == 1)
    {
        $rdeb=$default_deb_sale;
        $rcred=$default_cred_sale;
    }

    for ($i=0;$i<$num;$i++) {
      $res=$cn->fetch($i);
      $CHECKED=" unchecked";
      foreach ( $rdeb as $element) {
        if ( $element == $res['fd_id'] ) {
          $CHECKED="CHECKED";
          break;
        }
      }
            echo '<tr>';
      printf ('<TD> <INPUT TYPE="CHECKBOX" VALUE="%s" NAME="VEN_FICHEDEB[]" class="ven_fichedeb" %s>%s</TD>',
              $res['fd_id'],$CHECKED,$res['fd_label']);
      $CHECKED=" unchecked";
      foreach ( $rcred as $element) {
        if ( $element == $res['fd_id'] ) {
          $CHECKED="CHECKED";
          break;
        }
      }
      printf ('<TD> <INPUT TYPE="CHECKBOX" VALUE="%s" NAME="VEN_FICHECRED[]" class="ven_fichecred" %s>%s</TD>',
              $res['fd_id'],$CHECKED,$res['fd_label']);
      echo '</TR>';
    }
    ?>
    </TABLE>
</div>
<?php /////////////////// VEN //////////////////////////////////
 endif; 
 ?>
   <?php
    /////////////////// ODS //////////////////////////////////
    if ( $new ==1 || $type=='ODS' ) : 
        ?>
    <div id='ODS_div' >
    <h2 class="h-section"> Fiches </h2>
   <TABLE class="result" style="width:60%;margin-left:20%;">
        <tr>
            <th>
                <?php echo _("Fiches utilisables (D/C)"); ?>
            </th>
           
        </tr>
    
        
    <?php
    // Show the fiche in deb section
    $Res=$cn->exec_sql("select fd_id,fd_label from fiche_def order by fd_label");
    $num=$cn->size();
    // default card for ODS
    if ($new == 1)
    {
        $rdeb=$default_ods;
    }
    for ($i=0;$i<$num;$i++) {
      $res=$cn->fetch($i);
      $CHECKED=" unchecked";
     if (!empty($rdeb)) foreach ( $rdeb as $element) {
        if ( $element == $res['fd_id'] ) {
          $CHECKED="CHECKED";
          break;
        }
      }
            echo '<tr>';
      printf ('<TD> <INPUT TYPE="CHECKBOX" VALUE="%s" NAME="ODS_FICHEDEB[]" class="ods_fichedeb" %s>%s</TD>',
              $res['fd_id'],$CHECKED,$res['fd_label']);
      $CHECKED=" unchecked";

      echo '</TR>';
    }
    ?>
    </TABLE>
</div>
<?php /////////////////// ODS //////////////////////////////////
 endif; 
 ?>
   <?php
    /////////////////// FIN //////////////////////////////////
    if ( $new ==1 || $type=='FIN' ) : 
        ?>
    <div id='FIN_div' >
    <h2 class="h-section"> Fiches </h2>
     <TABLE class="result" style="width:60%;margin-left:20%;">
        <tr>
            <th>
                Tiers (D/C)
            </th>
           
        </tr>
    
        
    <?php
    // Show the fiche in deb section
    $Res=$cn->exec_sql("select fd_id,fd_label from fiche_def order by fd_label");
    $num=$cn->size();
    // default card for ACH
    if ($new == 1)
    {
        $rdeb=$default_fin;
    }
    for ($i=0;$i<$num;$i++) {
      $res=$cn->fetch($i);
      $CHECKED=" unchecked";
      foreach ( $rdeb as $element) {
        if ( $element == $res['fd_id'] ) {
          $CHECKED="CHECKED";
          break;
        }
      }
            echo '<tr>';
      printf ('<TD> <INPUT TYPE="CHECKBOX" VALUE="%s" NAME="FIN_FICHEDEB[]" class="fin_fichedeb" %s>%s</TD>',
              $res['fd_id'],$CHECKED,$res['fd_label']);
      $CHECKED=" unchecked";

      echo '</TR>';
    }
    ?>
    </TABLE>
</div>
<?php /////////////////// FIN //////////////////////////////////
 endif; 
 ?>
<?php if ( $new == 1 ) : ?>
<script>
    var a_div=Array('VEN_div','ODS_div','ACH_div','FIN_div');
    function hide_ledger()
    {
        for (var i=0;i<a_div.length;i++)
        {
            $(a_div[i]).style.display='none';
        }
    }
    function hide_row()
    {
        $('type_ods').style.display='none';
        $('type_fin').style.display='none';
        $('type_fin2').style.display='none';
        $('type_fin3').style.display='none';
        $('neg_amount').style.display='none';
        $('row_warning').style.display='none';
    }
   function show_ledger_div()
   {
       hide_ledger();
       var ch=$('p_jrn_type_select_id').options[$('p_jrn_type_select_id').selectedIndex].value;
      if ( ch != -1 ) {  $(ch+'_div').style.display='block';}
       switch (ch) {
           case 'FIN':
             hide_row();
             $('type_fin').style.display='table-row';
             $('type_fin2').style.display='table-row';         
             $('type_fin3').style.display='table-row';         
             break;
           case 'ODS':
               hide_row();
               $('type_ods').style.display='table-row';
               break;
           case 'ACH':
            hide_row();
               $('neg_amount').style.display='table-row';
               toggle_row_warning_enable('negative_amount','row_warning');

               break;
           case 'VEN':
               hide_row();
               $('neg_amount').style.display='table-row';
               toggle_row_warning_enable('negative_amount','row_warning');

               break;

           default:
               hide_row();
       }
   }
    hide_ledger();
    hide_row();
    <?php
    if (isset ($previous_p_jrn_type)  ):
    ?>
      show_ledger_div();              
    <?php
    endif;
    ?>


</script>
<?php endif; ?>
<?php if ( $type=="ACH" || $type=="VEN") :?>
<script>
toggle_row_warning_enable('negative_amount','row_warning');
</script>
<?php
endif;
?>
<script>
/** activate checkbox */
(function () {var a_checkbox=['ach_fichecred','ach_fichedeb','ven_fichecred','ven_fichedeb','ods_fichedeb','fin_fichedeb'];
    a_checkbox.forEach(element => activate_checkbox_range(element));})()
</script>