<?php
/****************************************************************************************
 * SMI (Services Maintenance Interventions) est une gestion libre de maintenance et de SAV
 *
 * Version 1.0.0
 *
 * Copyright (C) 2006-2014  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)
    $ok_inc = TRUE;
else
    $ok_inc = FALSE;
if ($ok_inc == FALSE) header("Location: ../index.php");


include_once("../inc/config.inc.php");
include_once("../inc/fic_age.inc.php");
include_once("../inc/fic_cli.inc.php");
include_once("../inc/fic_droits.inc.php");
include_once("../inc/fic_loc.inc.php");
include_once("../inc/fic_pdt.inc.php");
include_once("../inc/fic_st.inc.php");
include_once("../inc/fic_taxes.inc.php");
include_once("../inc/func.inc.php");
include_once("../inc/func_date.inc.php");
include_once("../inc/func_log.inc.php");
include_once("../inc/func_geo.inc.php");
include_once("../inc/func_time.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(@$_SESSION["code_log"]);
// Variables Formulaire
fix_magic_quotes();
$_GET = clean_str($_GET);
$_POST = clean_str($_POST);

$pbm_pdt = FALSE;
$dureemini = 0;
$nbs_couv = 0;
$nbsc_barloc = 0;

if (isset($_GET['td']))
    $td = @$_GET['td'];
else {
    if (isset($_POST['td']))
        $td = @$_POST['td'];
    else
        $pbm_pdt = TRUE;
}
if (isset($_GET['cl']))
    $codecoloc = @$_GET['cl'];
else {
    if (isset($_POST['cl']))
        $codecoloc = @$_POST['cl'];
    else
        $pbm_pdt = TRUE;
}
if (isset($_GET['ca']))
    $codeart = @$_GET['ca'];
else {
    if (isset($_POST['ca']))
        $codeart = @$_POST['ca'];
    else
        $pbm_pdt = TRUE;
}
$dd = "";
if (isset($_GET["dd"]))
    $dd = @$_GET["dd"];
else {
    if (isset($_POST['dd']))
        $dd = @$_POST['dd'];
    else
        $pbm_pdt = TRUE;
}
$hd = "";
if (isset($_GET["hd"]))
    $hd = @$_GET["hd"];
else {
    if (isset($_POST['hd']))
        $hd = @$_POST['hd'];
    else
        $pbm_pdt = TRUE;
}
$df = "";
if (isset($_GET["df"]))
    $df = @$_GET["df"];
else {
    if (isset($_POST['df']))
        $df = @$_POST['df'];
    else
        $pbm_pdt = TRUE;
}
$hf = "";
if (isset($_GET["hf"]))
    $hf = @$_GET["hf"];
else {
    if (isset($_POST['hf']))
        $hf = @$_POST['hf'];
    else
        $pbm_pdt = TRUE;
}
if (isset($_GET["ibl"])) {
    $ibl = intval(@$_GET["ibl"]);
    if (($ibl == 0) OR ($ibl < -1))
        $pbm_pdt = TRUE;
} else {
    if (isset($_POST['ibl']))
        $ibl = intval(@$_POST['ibl']);
    else
        $ibl = -2;
}
if ((chkdate($dd) == FALSE) OR (chkdate($df) == FALSE))
    $pbm_pdt = TRUE;

if ((heurecorrecte($hd . ':00') == FALSE) OR (heurecorrecte($hf . ':00') == FALSE))
    $pbm_pdt = TRUE;

if ($pbm_pdt == FALSE) {
    $njour = njour_semaine(datetomysql($dd));

    $nbjours = diff_date_jours(datetomysql($dd), datetomysql($df), FALSE);
    $dureemini = diff_dateheure_sec($dd . ' ' . $hd . ':00', $df . ' ' . $hf . ':00');

    if ($codecoloc <> "") {
        // Récupération des données du contrat de location
        $row = lit_enr_coloc($codecoloc);
        if (is_array($row)) {
            extract($row);

            if ($td <> "add") {
                // Contrôle qu'un client n'essaye pas de "hacker" un contrat
                if ((@$_SESSION["niv_log"] == 1) AND ($coloc_codecli <> @$_SESSION["code_log"]))
                    $pbm_pdt = TRUE;

                // Contrôle qu'une agence n'essaye pas de "hacker" un contrat
                if (((@$_SESSION["niv_log"] == 4) OR (@$_SESSION["niv_log"] == 3)) AND ($coloc_codeage <> @$_SESSION["code_age"]))
                    $pbm_pdt = TRUE;
            }

            if ($pbm_pdt == FALSE) {
                switch ($coloc_typcli) {
                    case 0 :
                        $row = lit_enr_cli($coloc_codecli, TRUE);
                        break;
                    case 1 :
                        $row = lit_enr_age($coloc_codecli, TRUE);
                        break;
                    case 3 :
                        $row = lit_enr_st($coloc_codecli, TRUE);
                        break;
                }
                if (is_array($row)) {
                    extract($row);

                    switch ($coloc_typcli) {
                        case 0 :
                            // Contrôle qu'une agence n'essaye pas de "hacker" un contrat
                            switch (@$_SESSION["niv_log"]) {
                                case 3 :
                                case 4 :
                                    if (client_age_ok($cli_code, @$_SESSION["code_age"], TRUE) == FALSE)
                                        $pbm_pdt = TRUE;
                                    break;
                                default :
                                    break;
                            }
                            break;
                    }

                    if ($pbm_pdt == FALSE) {
                        $udesc1 = "";
                        $udesc2 = "";

                        $codeadev = give_dev_codea_defaut_pdtloc($codeart, $_SESSION["lng"], TRUE);

                        if ($td == "add") {
                            // Récupération des données de la fiche article
                            $row = lit_enr_pdtloc($codeart);
                            if (is_array($row)) {
                                extract($row);

                                // Récupération des informations unité consommable
                                $pdtlbl_pdtuconsi1 = $pdtloc_pdtucons1;
                                $pdtlbl_pdtuconsi2 = $pdtloc_pdtucons2;
                                $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                                $rech = "SELECT pdtu_abr FROM `" . TBPDTU . "` WHERE pdtu_code='" . $pdtloc_pdtucons1 . "'";
                                $row = $db->get_row($rech, ARRAY_A);
                                if ($row) {
                                    extract($row);
                                    $udesc1 = $pdtu_abr;
                                }
                                $rech = "SELECT pdtu_abr FROM `" . TBPDTU . "` WHERE pdtu_code='" . $pdtloc_pdtucons2 . "'";
                                $row = $db->get_row($rech, ARRAY_A);
                                if ($row) {
                                    extract($row);
                                    $udesc2 = $pdtu_abr;
                                }
                                $db->disconnect();

                                // Initialisation caution
                                $pdtlbl_caution = $pdtloc_caution;
                                // Initialisation code TVA
                                if ($cli_modfact == 2)
                                    $pdtlbl_tvacaut = "TVA0";
                                else
                                    $pdtlbl_tvacaut = $pdtloc_tvacaut;
                                // Récupération des informations TVA caution
                                $row = lit_enr_tva($pdtlbl_tvacaut, TRUE);
                                if (is_array($row))
                                    extract($row);
                                $txtvacaut = $tva_tx / 100;
                                $cautionttc = round(($pdtlbl_caution * (1 + $txtvacaut)) * 100) / 100;

                                $puht = 0;
                                $pdtlbl_codetva = "TVA0";

                                if ($ibl > 0) {
                                    $row = lit_enr_barloc_id($ibl, TRUE);
                                    if (is_array($row)) {
                                        extract($row);
                                        if ($barloc_actif == 1) {
                                            // Initialisation tarif de vente
                                            $pdtlbl_pvht = $barloc_pvht;
                                            $pdtlbl_puconsi1 = $barloc_puconsi1;
                                            $pdtlbl_puconsi2 = $barloc_puconsi2;
                                            // Initialisation code TVA
                                            if ($cli_modfact == 2)
                                                $pdtlbl_codetva = "TVA0";
                                            else
                                                $pdtlbl_codetva = $barloc_codetva;
                                            // Récupération des informations TVA tarif
                                            $row = lit_enr_tva($pdtlbl_codetva, TRUE);
                                            if (is_array($row))
                                                extract($row);
                                            $txtva = $tva_tx / 100;

                                            $pvttc = round(($pdtlbl_pvht * (1 + $txtva)) * 100) / 100;
                                            $pvttcconsi1 = round(($barloc_puconsi1 * (1 + $txtva)) * 100) / 100;
                                            $pvttcconsi2 = round(($barloc_puconsi2 * (1 + $txtva)) * 100) / 100;

                                            // Initialisation tarif assurance
                                            $pdtlbl_mtass = $barloc_mtass;
                                            // Initialisation code TVA
                                            if ($cli_modfact == 2)
                                                $pdtlbl_codetva = "TVA0";
                                            else
                                                $pdtlbl_codetvaass = $barloc_codetvaass;
                                            // Récupération des informations TVA assurance
                                            $row = lit_enr_tva($pdtlbl_codetvaass, TRUE);
                                            if (is_array($row))
                                                extract($row);
                                            $txtvaass = $tva_tx / 100;
                                            $pvttcass = round(($pdtlbl_mtass * (1 + $txtvaass)) * 100) / 100;

                                            // Durée (secondes) couverte par ce barème pour une unité
                                            $nbsc_barloc = nbsc_in_barloc_barloc($ibl, TRUE);
                                        } else
                                            $pbm_pdt = TRUE;
                                    } else
                                        $pbm_pdt = TRUE;
                                } else {
                                    if ($ibl == -1)
                                        $nbsc_barloc = $dureemini;
                                }
                            } else
                                $pbm_pdt = TRUE;
                        } else {
                            $ibl = $_SESSION["pdtlbl"][0]["idbarloc"];
                            $pdtlbl_qte = $_SESSION["pdtlbl"][0]["qte"];
                            $pdtlbl_pvht = $_SESSION["pdtlbl"][0]["pvht"];
                            $pdtlbl_codetva = $_SESSION["pdtlbl"][0]["codetva"];
                            $pdtlbl_caution = $_SESSION["pdtlbl"][0]["caution"];
                            $pdtlbl_tvacaut = $_SESSION["pdtlbl"][0]["tvacaut"];
                            $pdtlbl_avecass = $_SESSION["pdtlbl"][0]["avecass"];
                            $pdtlbl_mtass = $_SESSION["pdtlbl"][0]["mtass"];
                            $pdtlbl_tvaass = $_SESSION["pdtlbl"][0]["tvaass"];
                            $pdtlbl_codetvaass = $_SESSION["pdtlbl"][0]["codetvaass"];
                            $pdtlbl_qconsi1 = $_SESSION["pdtlbl"][0]["qconsi1"];
                            $pdtlbl_pdtuconsi1 = $_SESSION["pdtlbl"][0]["pdtuconsi1"];
                            $pdtlbl_puconsi1 = $_SESSION["pdtlbl"][0]["puconsi1"];
                            $pdtlbl_qconsi2 = $_SESSION["pdtlbl"][0]["qconsi2"];
                            $pdtlbl_pdtuconsi2 = $_SESSION["pdtlbl"][0]["pdtuconsi2"];
                            $pdtlbl_puconsi2 = $_SESSION["pdtlbl"][0]["puconsi2"];

                            // Récupération des informations TVA caution
                            $row = lit_enr_tva($pdtlbl_tvacaut, TRUE);
                            if (is_array($row))
                                extract($row);
                            $txtvacaut = $tva_tx / 100;
                            $cautionttc = round(($pdtlbl_caution * (1 + $txtvacaut)) * 100) / 100;

                            // Récupération des informations TVA tarif
                            $row = lit_enr_tva($pdtlbl_codetva, TRUE);
                            if (is_array($row))
                                extract($row);
                            $txtva = $tva_tx / 100;
                            $pvttc = round(($pdtlbl_pvht * (1 + $txtva)) * 100) / 100;
                            $pvttcconsi1 = round(($pdtlbl_puconsi1 * (1 + $txtva)) * 100) / 100;
                            $pvttcconsi2 = round(($pdtlbl_puconsi2 * (1 + $txtva)) * 100) / 100;

                            // Récupération des informations TVA assurance
                            $row = lit_enr_tva($pdtlbl_codetvaass, TRUE);
                            if (is_array($row))
                                extract($row);
                            $txtvaass = $tva_tx / 100;
                            $pvttcass = round(($pdtlbl_mtass * (1 + $txtvaass)) * 100) / 100;

                            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
                            $rech = "SELECT pdtu_abr FROM `" . TBPDTU . "` WHERE pdtu_code='" . $pdtlbl_pdtuconsi1 . "'";
                            $row = $db->get_row($rech, ARRAY_A);
                            if ($row) {
                                extract($row);
                                $udesc1 = $pdtu_abr;
                            }
                            $rech = "SELECT pdtu_abr FROM `" . TBPDTU . "` WHERE pdtu_code='" . $pdtlbl_pdtuconsi2 . "'";
                            $row = $db->get_row($rech, ARRAY_A);
                            if ($row) {
                                extract($row);
                                $udesc2 = $pdtu_abr;
                            }
                            $db->disconnect();
                        }
                    }
                }
            } else
                $pbm_pdt = TRUE;
        } else
            $pbm_pdt = TRUE;
    } else
        $pbm_pdt = TRUE;
}

switch ($td) {
    case "add" :
        $titre = _("CHOIX BAREME");
        if (($ibl <> -2) && ($ibl <> 0))
            $pdtlbl_qte = ($dureemini / $nbsc_barloc);
        if ($ibl == 0)
            $pdtlbl_qte = $nbjours;
        switch ($barloc_typarr) {
            case 1 :
                $pdtlbl_qte = floor($pdtlbl_qte);
                break;
            case 2 :
                $pdtlbl_qte = ceil($pdtlbl_qte);
                break;
            default :
                $pdtlbl_qte = round($pdtlbl_qte, 2);
                break;
        }
        $pdtlbl_avecass = 1;
        break;
    case "edit" :
        $titre = _("EDITION BAREME");
        if (isset($_SESSION["pdtlbl"])) {
            if (count($_SESSION["pdtlbl"]) == 0)
                $pbm_pdt = TRUE;
        }
        break;
    case "del" :
        $titre = _("SUPPRESSION BAREME");
        if (isset($_SESSION["pdtlbl"])) {
            if (count($_SESSION["pdtlbl"]) == 0)
                $pbm_pdt = TRUE;
        }
        break;
    default :
        $pbm_pdt = 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 _("Article (Barême Location)"); ?></title>

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

    <script language="javascript">
        <!--
        var tab1_champ = [];
        //-->
    </script>

    <script type="text/javascript">
        <!--
        function init_all() {
            init_Body();
            add_func_click('annul', 'sclose', '');
            <?PHP
            if ($ibl<>-2)
                echo "readonly_id('ibl',false);";
            if ($barloc_assobl == TRUE)
                echo "readonly_id('assobl',false);";
            ?>
            init_chk_calc_location('assobl','<?PHP echo $cli_modfact; ?>',<?PHP echo intval($_SESSION['num_nbdec']); ?>,'<?PHP echo $_SESSION['num_cardec']; ?>','<?PHP echo $_SESSION['num_carsep']; ?>');
            init_valid_form('enr','pdtlbl_maj','<?PHP echo $_SESSION['date_fmtshort']; ?>',tab1_champ,'','');
            Focus_first();
        }

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

</head>

<body>
<?PHP
if ($pbm_pdt == FALSE) {
    ?>
    <p align="center"><span class="titrepage"><?PHP echo $titre ?></span></p>
    <p align="center"><span class="titre_gras"><?PHP echo _("Pour la location du produit").' '.$pdtloc_des; ?></span><br />
        <span class="annot_petit_gras"><?PHP echo __("Du").' '.$dd . ' ' . $hd.' '._("au").' '.$df . ' ' . $hf; ?></span></p>

    <form name="pdtlbl_maj" id="pdtlbl_maj" method="post" action="<?PHP if ($ibl == -2) echo "pdtlbl_maj.php"; else echo "pdtlbl_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="cl" type="hidden" id="cl" value="<?PHP echo $codecoloc ?>">
    <input name="ca" type="hidden" id="ca" value="<?PHP echo $codeart ?>">
    <input name="dd" type="hidden" id="dd" value="<?PHP echo $dd ?>">
    <input name="hd" type="hidden" id="dd" value="<?PHP echo $hd ?>">
    <input name="df" type="hidden" id="df" value="<?PHP echo $df ?>">
    <input name="hf" type="hidden" id="df" value="<?PHP echo $hf ?>">
    <input name="dmini" type="hidden" id="dmini" value="<?PHP echo $dureemini; ?>">
    <input name="nbsc" type="hidden" id="nbsc" value="<?PHP echo $nbs_couv; ?>">
    <input name="nbscbl" type="hidden" id="nbscbl" value="<?PHP echo $nbsc_barloc; ?>">
    <input name="cpen" type="hidden" id="cpen" value="<?PHP echo $barloc_codepen; ?>">
    <input name="nbutton" type="hidden" id="nbutton" value="">
    <table width="100%" border="0">
    <tr>
        <td width="160" class="rubfrm" id="f_ibl" align="right">
            <?PHP if ($ibl == -2) echo _("Barêmes possibles"); else echo _("Barême"); ?>
        </td>
        <td>
            <?PHP
            $tab_bar = [];
            $tab_bar["0"] = _("Prêt de matériel (Gratuit)");
            // création de la liste des barèmes actifs et pouvant être choisis
            $db = open_database(DBUSER, DBPASS, DBNAME, DBHOST);
            // Filtre sur barèmes actifs
            $rech = "SELECT * FROM `" . TBBARLOC . "`, `" . TBPERLOC . "` WHERE " . TBBARLOC . ".barloc_actif = '1'";
            $rech .= " AND " . TBBARLOC . ".barloc_codepdtloc = '" . $codeart . "'";
            $rech .= " AND (" . TBBARLOC . ".barloc_dateval1 <= '" . datetomysql($dd) . "' AND (" . TBBARLOC . ".barloc_dateval2 >= '" . datetomysql($dd) . "' OR " . TBBARLOC . ".barloc_dateval2 = '0000-00-00')";
            $rech .= " AND (" . TBBARLOC . ".barloc_dateval2 >= '" . datetomysql($df) . "' OR " . TBBARLOC . ".barloc_dateval2 = '0000-00-00'))";
            $rech .= " AND ((" . TBPERLOC . ".perloc_jourd1 <= '" . $njour . "' AND " . TBPERLOC . ".perloc_jourd2 >= '" . $njour . "') OR " . TBPERLOC . ".perloc_jourd1 = '-1')";
            $rech .= " AND ((" . TBPERLOC . ".perloc_nduree * " . TBPERLOC . ".perloc_tduree) <= " . $dureemini . ")";
            $rech .= " AND " . TBBARLOC . ".barloc_codeperloc = " . TBPERLOC . ".perloc_code";
            $rech .= " ORDER BY " . TBBARLOC . ".barloc_des";
            $rows = $db->get_results($rech, ARRAY_A);

            if ($rows) {
                foreach ($rows as $row) {
                    extract($row);
                    $dureebl = $perloc_nduree * $perloc_tduree;
                    $affopt = TRUE;

                    // On vérifie dans le cas où "multiple" est à non
                    if ($barloc_mult == 0) {
                        if ($dureebl <> $dureemini)
                            $affopt = FALSE;
                    }
                    if ($affopt == TRUE)
                        $tab_bar[$barloc_id] = $barloc_des . ' (' . $perloc_nduree . ' ' . $lng_tduree[$perloc_tduree] . ')';
                }
            }
            $db->disconnect();

            cre_select('ibl', 'ibl', $tab_bar, $ibl, '', _("-- Faites votre choix --"));
            ?>
        </td>
    </tr>
    <?PHP
    if ($ibl <> -2) {
        ?>
        <tr>
            <td class="rubfrm" id="f_qte"
                align="right"><?PHP echo _("Quantité"); ?><?PHP if ($ibl == -1) echo " (jours)"; ?></td>
            <td>
                <?PHP
                cre_input_num('qte', $pdtlbl_qte, FALSE, TRUE, FALSE, FALSE);
                ?>
            </td>
        </tr>
        <tr>
            <td class="rubfrm" id="f_assobl" align="right"><?PHP echo _("Assurance"); ?></td>
            <td>
                <?PHP
                if ($ibl <> 0) {
                   cre_select('assobl', 'assobl', $non_oui, (int)$pdtlbl_avecass);
                } else
                    echo '<span class="annot_gras_it">'._("Sans assurance (prêt)").'</span>';
                ?>
            </td>
        </tr>
        <tr>
            <td class="annot_gras_it" align="center" colspan="2"><?PHP echo _("Détail montant :"); ?></td>
        </tr>
        <tr>
        <td colspan="2">
        <table width="100%" border="0" class="MtableD">
        <th>
            <?PHP echo _("Type"); ?>
        </th>
        <th>
            <?PHP echo _("Quantité"); ?>
        </th>
        <th>
            <?PHP echo _("PU"); if ($cli_modfact == 1) echo ' '._("TTC"); else echo ' '._("HT"); ?>
        </th>
        <th>
            <?PHP echo _("Total"); if ($cli_modfact == 1) echo ' '._("TTC"); else echo ' '._("HT"); ?>
        </th>
        <th>
            <?PHP echo _("TVA"); ?>
        </th>
        <tr>
            <td>
                <span class="annot_petit_gras"><?PHP echo _("Coût de location"); ?></span>
            </td>
            <td class="TDnumberD">
                <?PHP echo full_num_format($pdtlbl_qte,'span','affqteloc');?>
            </td>
            <td class="TDnumberD">
                <input name="pvht" type="hidden" id="pvht" value="<?PHP echo $pdtlbl_pvht; ?>" readonly>
                <input name="pvttc" type="hidden" id="pvttc" value="<?PHP echo $pvttc; ?>" readonly>
                <?PHP
                switch ($cli_modfact)
                {
                    case 1 :
                        echo full_num_format($pvttc, '', '', TRUE);
                        break;
                    default :
                        echo full_num_format($pdtlbl_pvht, '', '', TRUE);
                        break;
                }
                ?>
            </td>
            <td class="TDnumberD">
			<?PHP
            $totlocht = round($pdtlbl_pvht * $pdtlbl_qte * 100) / 100;
            $totlocttc = round($pvttc * $pdtlbl_qte * 100) / 100;
            $totloctva = $totlocttc - $totlocht;
            switch ($cli_modfact)
            {
                case 1 :
                    echo full_num_format($totlocttc, 'span', 'afftotloc', TRUE);
                    break;
                default :
                    echo full_num_format($totlocht, 'span', 'afftotloc', TRUE);
                    break;
            }
            ?>
            </td>
            <td class="TDnumberD">
                <input name="tva" type="hidden" id="tva" value="<?PHP echo $pdtlbl_codetva; ?>">
                <input name="txtva" type="hidden" id="txtva" value="<?PHP echo $txtva; ?>" readonly>
                <?PHP echo full_num_format($txtva * 100) . "%"; ?>
            </td>
        </tr>
        <tr>
            <td>
                <span class="annot_petit_gras"><?PHP echo _("Caution"); ?></span>
            </td>
            <td class="TDnumberD"><?PHP echo full_num_format(1);?></td>
            <td class="TDnumberD">
                <input name="caution" type="hidden" id="caution" value="<?PHP echo $pdtlbl_caution; ?>" readonly>
                <input name="cautionttc" type="hidden" id="cautionttc" value="<?PHP echo $cautionttc; ?>" readonly>
                <?PHP
                switch ($cli_modfact)
                {
                    case 1 :
                        echo full_num_format($cautionttc, '', '', TRUE);
                        break;
                    default :
                        echo full_num_format($caution, '', '', TRUE);
                        break;
                }
                ?>
            </td>
            <td class="TDnumberD">
			<?PHP
            $totcautht = round($pdtlbl_caution * 100) / 100;
            $totcautttc = round($cautionttc * 100) / 100;
            $totcauttva = $totcautttc - $totcautht;
            switch ($cli_modfact)
            {
                case 1 :
                    echo full_num_format($totcautttc, 'span', 'afftotcaut', TRUE);
                    break;
                default :
                    echo full_num_format($totcautionht, 'span', 'afftotcaut', TRUE);
                    break;
            }
            ?>
            </td>
            <td class="TDnumberD">
                <input name="tvacaut" type="hidden" id="tvacaut" value="<?PHP echo $pdtlbl_tvacaut; ?>">
                <input name="txtvacaut" type="hidden" id="txtvacaut" value="<?PHP echo $txtvacaut; ?>" readonly>
                <?PHP echo full_num_format($txtvacaut * 100) . "%"; ?>
            </td>
        </tr>
        <tr>
            <td>
                <span class="annot_petit_gras"><?PHP echo _("Assurance"); ?></span>
            </td>
            <td class="TDnumberD">
                <span id="affqteass"><?PHP echo full_num_format($pdtlbl_qte);?></span>
            </td>
            <td class="TDnumberD">
                <input name="mtass" type="hidden" id="mtass" value="<?PHP echo $pdtlbl_mtass; ?>" readonly>
                <input name="mtassttc" type="hidden" id="mtassttc" value="<?PHP echo $pvttcass; ?>" readonly>
			<?PHP
            if ($pdtlbl_avecass == 1) {
                switch ($cli_modfact)
                {
                    case 1 :
                        echo full_num_format($pvttcass, 'span', 'affpuass', TRUE);
                        break;
                    default :
                        echo full_num_format($pdtlbl_mtass, 'span', 'affpuass', TRUE);
                        break;
                }
            } else echo "-"; ?>
            </td>
            <td class="TDnumberD">
			<?PHP
            $totassht = 0;
            $totassttc = 0;
            $totasstva = 0;
            if ($pdtlbl_avecass == 1) {
                $totassht = round($pdtlbl_mtass * $pdtlbl_qte * 100) / 100;
                $totassttc = round($pvttcass * $pdtlbl_qte * 100) / 100;
                $totasstva = $totassttc - $totassht;
                switch ($cli_modfact)
                {
                    case 1 :
                        echo full_num_format($totassttc, 'span', 'afftotass', TRUE);
                        break;
                    default :
                        echo full_num_format($totassht, 'span', 'afftotass', TRUE);
                        break;
                }
            } else
                echo full_num_format($totassht, 'span', 'afftotass', TRUE);
            ?>
            </td>
            <td class="TDnumberD">
                <input name="tvaass" type="hidden" id="tvaass" value="<?PHP echo $pdtlbl_codetvaass; ?>">
                <input name="txtvaass" type="hidden" id="txtvaass" value="<?PHP echo $txtvaass; ?>" readonly>
                <span id="afftvaass"><?PHP if ($pdtlbl_avecass == 1) echo full_num_format($txtvaass * 100) . "%"; else echo "-"; ?></span>
            </td>
        </tr>
        <?PHP if (trim($udesc1) <> "") { ?>
            <tr>
                <td>
                    <span
                        class="annot_petit_gras"><?PHP echo _("Forfait"). ' '.full_num_format($barloc_qconsi1) . ' ' . strtolower($udesc1); ?></span>
                </td>
                <td class="TDnumberD">
                    <?PHP echo full_num_format($pdtlbl_qte,'span','affqtecons1');?>
                </td>
                <td class="TDnumberD">
                    <input name="qcons1" type="hidden" id="qcons1" value="<?PHP echo $barloc_qconsi1; ?>" readonly>
                    <input name="pdtucons1" type="hidden" id="pdtucons1" value="<?PHP echo $pdtlbl_pdtuconsi1; ?>"
                           readonly>
                    <input name="mtcons1" type="hidden" id="mtcons1" value="<?PHP echo $pdtlbl_puconsi1; ?>" readonly>
                    <input name="mtconsttc1" type="hidden" id="mtconsttc1" value="<?PHP echo $pvttcconsi1; ?>" readonly>
			<?PHP
            switch ($cli_modfact)
            {
                case 1 :
                    echo full_num_format($pvttcconsi1, 'span', 'affpuconsi1', TRUE);
                    break;
                default :
                    echo full_num_format($pdtlbl_puconsi1, 'span', 'affpuconsi1', TRUE);
                    break;
            }
            ?>
                </td>
                <td class="TDnumberD">
			<?PHP
            $totcons1ht = round($pdtlbl_puconsi1 * $pdtlbl_qte * 100) / 100;
            $totcons1ttc = round($pvttcconsi1 * $pdtlbl_qte * 100) / 100;
            $totcons1tva = $totcons1ttc - $totcons1ht;
            switch ($cli_modfact)
            {
                case 1 :
                    echo full_num_format($totcons1ttc, 'span', 'afftotconsi1', TRUE);
                    break;
                default :
                    echo full_num_format($totcons1ht, 'span', 'afftotconsi1', TRUE);
                    break;
            }
            ?>
                </td>
                <td class="TDnumberD">
                    <?PHP echo full_num_format($txtva * 100) . "%"; ?>
                </td>
            </tr>
        <?PHP
        }
        if (trim($udesc2) <> "") {
            ?>
            <tr>
                <td>
                    <span
                        class="annot_petit_gras"><?PHP echo _("Forfait").' '. full_num_format($barloc_qconsi2) . ' ' . strtolower($udesc2); ?></span>
                </td>
                <td class="TDnumberD">
                    <span id="affqtecons2"><?PHP echo full_num_format($pdtlbl_qte);?></span>
                </td>
                <td class="TDnumberD">
                    <input name="qcons2" type="hidden" id="qcons2" value="<?PHP echo $barloc_qconsi2; ?>" readonly>
                    <input name="pdtucons2" type="hidden" id="pdtucons2" value="<?PHP echo $pdtlbl_pdtuconsi2; ?>"
                           readonly>
                    <input name="mtcons2" type="hidden" id="mtcons2" value="<?PHP echo $pdtlbl_puconsi2; ?>" readonly>
                    <input name="mtconsttc2" type="hidden" id="mtconsttc2" value="<?PHP echo $pvttcconsi2; ?>" readonly>
			<?PHP
            switch ($cli_modfact)
            {
                case 1 :
                    echo full_num_format($pvttcconsi2, 'span', 'affpuconsi2', TRUE);
                    break;
                default :
                    echo full_num_format($pdtlbl_puconsi2, 'span', 'affpuconsi2', TRUE);
                    break;
            }
            ?>
                </td>
                <td class="TDnumberD">
			<?PHP
            $totcons2ht = round($pdtlbl_puconsi2 * $pdtlbl_qte * 100) / 100;
            $totcons2ttc = round($pvttcconsi2 * $pdtlbl_qte * 100) / 100;
            $totcons2tva = $totcons2ttc - $totcons2ht;
            switch ($cli_modfact)
            {
                case 1 :
                    echo full_num_format($totcons2ttc, 'span', 'afftotconsi2', TRUE);
                    break;
                default :
                    echo full_num_format($totcons2ht, 'span', 'afftotconsi2', TRUE);
                    break;
            }
            ?>
                </td>
                <td class="TDnumberD">
                    <?PHP echo full_num_format($txtva * 100) . "%"; ?>
                </td>
            </tr>
        <?PHP } ?>
        <tr>
            <td colspan="5">&nbsp;</td>
        </tr>
        <tr>
            <td colspan="3" align="right">
                <?PHP echo _("Total HT"); ?>
            </td>
            <td class="TDnumberD">
                <?PHP
                $totalgenHT = $totlocht + $totcautht + $totassht + $totcons1ht + $totcons2ht;
                $totalgenTTC = $totlocttc + $totcautttc + $totassttc + $totcons1ttc + $totcons2ttc;
                $totalgenTVA = $totloctva + $totcauttva + $totasstva + $totcons1tva + $totcons2tva;
                echo full_num_format($totalgenHT, 'span', 'afftotalgenht', TRUE);
                ?>
            </td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td colspan="3" align="right">
                <?PHP echo _("Total TVA"); ?>
            </td>
            <td class="TDnumberD">
			<?PHP echo full_num_format($totalgenTVA, 'span', 'afftotalgentva', TRUE); ?>
            </td>
            <td>&nbsp;</td>
        </tr>
        <tr>
            <td colspan="3" class="annot_petit_gras" align="right">
                <?PHP echo _("Total TTC"); ?>
            </td>
            <td class="TDnumberD">
			<span class="annot_petit_gras">
                <?PHP echo full_num_format($totalgenTTC, 'span', 'afftotalgenttc', TRUE); ?>
            </span>
            </td>
            <td>&nbsp;</td>
        </tr>
        </table>
        </td>
        </tr>
    <?PHP
    }
    ?>
    </table>
    <?PHP if ($cli_modfact == 2) echo '<span class="annot_petit_it">'._("NOTA : Client exonéré de TVA").'</span>'; ?>
    <p align="center">
    <?PHP
    switch ($td)
    {
        case "add" :
            echo '<input name="RAZ" type="button" class="bton_std" id="RAZ" value="'. _("Réinitialiser").'">';
            echo '<input name="enr" type="button" class="bton_std" id="enr" value="'._("Valider").'">';
            break;
        case "edit" :
            echo '<input name="enr" type="button" class="bton_std" id="enr" value="'._("Valider").'">';
            break;
        case "del" :
            echo '<input name="enr" type="button" class="bton_std" id="enr" value="'._("Supprimer").'">';
            break;
    }
    echo '<input name="annul" type="button" class="bton_std" id="annul" value="'._("Annuler").'">';
    ?>
    </p>
    </form>
<?PHP
} else
    close_fen_auto('', 'fscomp');
?>
</body>
</html>