<?php
/****************************************************************************************
 * SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV
 *
 * Version 1.0.4
 *
 * Copyright (C) 2006-2016  Sylvain FATOME
 * This program is free software; you can redistribute it and/or modify it under the terms
 * of the GNU General Public License as published by the Free Software Foundation;
 * either version 2 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with this program
 * (in the directory docs);
 * if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
 * Boston, MA  02110-1301, USA.
 *
 * Contact : galawa@free.fr
 *
 * Web : http://smi.no-ip.org
 ****************************************************************************************/

// vérification des tentatives de hack
$pos = strpos($_SERVER['PHP_SELF'], 'inc.php');
if ($pos !== FALSE) {
    header('Location: ../index.php');
}

include_once('../inc/fic_droits.inc.php');
include_once('../inc/fic_taxes.inc.php');
include_once('../inc/func.inc.php');
include_once('../inc/func_geo.inc.php');
include_once('../inc/func_txt.inc.php');
include_once('../classes/ezSQL/shared/ez_sql_core.php');
include_once('../classes/ezSQL/mysqli/ez_sql_mysqli.php');
include_once('../inc/func_sql.inc.php');
Archivelog(valsession('code_log'));
// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);

$td = $_GET['td'];
$coderech = $_GET['code'];

$pbm_tva = FALSE;
$tvamod = TRUE;
$tvadesact = TRUE;

if ($coderech <> '') {
    $row = lit_enr_tva($coderech, TRUE);
    if (is_array($row)) {
        $row = encode_str($row);
        extract($row);
        $tvamod = tva_modifiable($coderech, TRUE);
        $tvadesact = tva_desactivable($coderech, TRUE);
    } else {
        $pbm_tva = TRUE;
    }
} else {
    if ($td <> 'add') {
        $pbm_tva = TRUE;
    }
}

$titre = '';
if ($pbm_tva == FALSE) {
    switch ($td) {
        case 'add' :
            $titre = _('CREATION TVA');
            $tva_actif = TRUE;
            break;
        case 'edit' :
            $titre = _('MODIFICATION TVA');
            break;
        case 'del' :
            $titre = _('SUPPRESSION TVA');
            break;
        default :
            $pbm_tva = TRUE;
            break;
    }
}
?>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-type=" content="text/html; charset=utf-8">
    <title>SMI - <?php echo _('ESPACE PRIVE'); ?> : <?php echo _('Fiche TVA'); ?></title>

    <?php include_once('../inc/header.inc.php'); ?>

    <script language="javascript">
        <!--
        var tab_champ = ["nom:code ; format:alphanum ; req:Y ; txt:<?php echo _('Code'); ?> ; lmn:1 ; lmx:10; stok:frmok ; stbad:frmbad",
            "nom:desc ; format:txt ; req:Y ; txt:<?php echo _('Libellé'); ?>; lmn:1 ; lmx:40; stok:frmok ; stbad:frmbad",
            "nom:taux ; format:reel_ns ; req:Y ; txt:<?php echo _('Taux'); ?>; lmn:1 ; lmx:10; stok:frmok ; stbad:frmbad"];
        //-->
    </script>

    <?php if ($pbm_tva == FALSE) { ?>
        <script type="text/javascript">
            <!--
            $(function () {
                $("#code").Setcase({caseValue: 'upper', changeonFocusout: true});
                $("#desc").Setcase({caseValue: 'upper', changeonFocusout: true});
            });

            function init_all() {
                init_Body();
                init_fdeci('taux', 2, '');
                <?php
                 switch ($td)
                 {
                    case 'add':
                        echo "init_valid_form('enr','tva_maj','".valsession('date_fmtshort')."',tab_champ,'','');";
                        break;
                    case 'edit':
                        echo "readonly_id('code',false);";
                        if ($tvamod == FALSE)
                            {echo "readonly_id('taux',false);";}
                        if ($tvadesact == FALSE)
                            {echo "readonly_id('actif',false);";}
                        echo "init_valid_form('enr','tva_maj','".valsession('date_fmtshort')."',tab_champ,'','');";
                        break;
                    case 'del':
                        echo "init_valid_form('del','tva_maj','".valsession('date_fmtshort')."',tab_champ,'','');";
                        echo 'readonly_all();';
                        echo "warn_del('');";
                        break;
                    case 'view':
                        echo 'readonly_all();';
                        break;

                 }
                ?>
                Focus_first();
            }

            $(document).ready(function () {
                init_all();
            });
            //-->
        </script>

    <?php } ?>
</head>

<body>
<?php
include_once('../inc/entete.inc.php');
if ($pbm_tva == FALSE) {
    cre_ent_form($titre, 'tva_lst.php', $_SERVER['HTTP_REFERER'], '');
    ?>
    <form name="tva_maj" id="tva_maj" method="post" action="tva_enr.php">
        <input name="titre" type="hidden" id="titre" value="<?php echo $titre ?>">
        <input name="td" type="hidden" id="td" value="<?php echo $td ?>">
        <input name="nbutton" type="hidden" id="nbutton" value="">
        <table width="100%" border="0">
            <tr>
                <td width="10%" class="rubfrm" id="f_code" align="right"><?php echo _('Code'); ?></td>
                <td width="47%">
                    <input name="code" type="text" id="code" value="<?php echo $tva_code ?>" size="10">
                    <img src="../img/oblig.png" align="absmiddle" alt="<?php echo _('Champ obligatoire'); ?>">
                </td>
            </tr>
            <tr>
                <td class="rubfrm" id="f_desc" align="right"><?php echo _('Libellé'); ?></td>
                <td><input name="desc" type="text" id="desc" value="<?php echo $tva_desc; ?>" size="50">
                    <img src="../img/oblig.png" align="absmiddle" alt="<?php echo _('Champ obligatoire'); ?>"></td>
            </tr>
            <tr>
                <td class="rubfrm" id="f_taux" align="right"><?php echo _('Taux'); ?></td>
                <td>
                    <input name="taux" type="text" id="taux" style="text-align:right" value="<?php echo $tva_tx; ?>"
                           size="10">%
                    <?php
                    if ($tvamod == TRUE) {
                        echo ' <img src="../img/oblig.png" align="absmiddle" alt="' . _('Champ obligatoire') . '">';
                    }
                    echo '<div class="annot_petit_it">';
                    echo _("Vous ne pouvez pas modifier le taux d'une TVA déjà utilisée dans une intervention ou un contrat signé");
                    echo '<br />';
                    echo _("Il vaux mieux utiliser l'option 'Réaffecter'");
                    echo '</div>';
                    ?>
                </td>
            </tr>
            <tr>
                <td class="rubfrm" id="f_actif" align="right"><?php echo _('TVA par défaut'); ?></td>
                <td>
                    <?php
                    cre_select('default', 'default', $non_oui, (int)$tva_default);
                    echo '<div class="annot_petit_it">';
                    echo _('La TVA par défaut sera celle reprise en création de contrat, articles, etc... et pour les renouvellements, notamment de contrats');
                    echo '</div>';
                    ?>
                </td>
            </tr>
            <tr>
                <td class="rubfrm" id="f_actif" align="right"><?php echo _('Actif'); ?></td>
                <td>
                    <?php
                    cre_select('actif', 'actif', $non_oui, (int)$tva_actif);
                    echo '<div class="annot_petit_it">';
                    echo _('Vous ne pouvez pas désactiver une TVA déjà utilisée dans une intervention ou un contrat non clôt');
                    echo '</div>';
                    ?>
                </td>
            </tr>
        </table>
        <p align="center">
            <?php
            switch ($td) {
                case 'add' :
                case 'edit' :
                    echo '<input name="enr" type="button" class="bton_std" id="enr" value="' . _('Valider') . '">';
                    break;
                case 'del' :
                    echo '<input name="del" type="button" class="bton_std" id="del" value="' . _('Supprimer') . '">';
                    break;
            }
            echo '<input name="RAZ" type="reset" class="bton_std" id="RAZ" value="' . _('Réinitialiser') . '">';
            ?>
        </p>
    </form>
    <?php
} else {
    pop_ret_auto(_('Problème de paramètres'), 'warn', 'tva_lst.php');
}
include_once('pied.php');
?>
</body>
</html>