Example #1
0
function verif_bud()
{
    global $msg, $charset;
    global $max_lig;
    global $prix, $rem, $rub, $fac;
    global $error, $error_msg;
    global $acquisition_budget;
    if ($acquisition_budget) {
        $tot_rub = array();
        $tot_bud = array();
        for ($i = 1; $i <= $max_lig; $i++) {
            if ($fac[$i]) {
                $tot_rub[$rub[$i]] = 0;
            }
        }
        //récupère le total facturé par rubrique
        for ($i = 1; $i <= $max_lig; $i++) {
            if ($fac[$i]) {
                $tot_rub[$rub[$i]] = $tot_rub[$rub[$i]] + $fac[$i] * $prix[$i] * (1 - $rem[$i] / 100);
            }
        }
        //récupère le total facturé par budget
        foreach ($tot_rub as $key => $value) {
            $r = new rubriques($key);
            if (!array_key_exists($r->num_budget, $tot_bud)) {
                $tot_bud[$r->num_budget] = 0;
            }
            $tot_bud[$r->num_budget] = $tot_bud[$r->num_budget] + $value;
        }
        //Vérifie que les budgets affectés par rubrique ne sont pas dépassés
        foreach ($tot_rub as $key => $value) {
            $r = new rubriques($key);
            $b = new budgets($r->num_budget);
            if ($b->type_budget == TYP_BUD_RUB) {
                //Budget affecté par rubrique
                $mnt_rub = $r->montant;
                $eng_rub = rubriques::calcEngagement($key) + $value;
                //Budget rubrique dépassé ?
                if ($eng_rub > $mnt_rub) {
                    $error = true;
                    $tab_rub = rubriques::listAncetres($key, true);
                    $lib_rub = $b->libelle . ":";
                    foreach ($tab_rub as $value) {
                        $lib_rub .= $value[1];
                        if ($value[0] != $key) {
                            $lib_rub .= ":";
                        }
                    }
                    $error_msg = $msg['acquisition_rub'] . " :\\n\\n" . $lib_rub . "\\n\\n" . $msg['acquisition_act_bud_dep'];
                    break;
                }
            }
        }
        //Vérifie que les budgets affectés globalement ne sont pas dépassés
        foreach ($tot_bud as $key => $value) {
            $b = new budgets($key);
            if ($b->type_budget == TYP_BUD_GLO) {
                $mnt_bud = $b->montant_global;
                $eng_bud = budgets::calcEngagement($b->id_budget) + $value;
                //Budget dépassé ?
                if ($eng_bud > $mnt_bud) {
                    $error = true;
                    $error_msg = $msg['acquisition_act_tab_bud'] . " : " . $b->libelle . "\\n\\n" . $msg['acquisition_act_bud_dep'];
                    break;
                }
            }
        }
    }
}
Example #2
0
function show_results($dbh, $nbr_lignes = 0, $page = 0)
{
    global $nb_per_page;
    global $base_url;
    global $caller;
    global $charset;
    global $msg;
    global $id_bibli, $id_exer;
    global $acquisition_budget_show_all;
    global $elt_query;
    // on récupére le nombre de lignes qui vont bien
    $nbr_lignes = entites::countRubriquesFinales($id_bibli, $id_exer, true, $elt_query);
    if (!$page) {
        $page = 1;
    }
    $debut = ($page - 1) * $nb_per_page;
    if ($nbr_lignes) {
        // on lance la vraie requête
        if (!$acquisition_budget_show_all) {
            $res = entites::listRubriquesFinales($id_bibli, $id_exer, true, $debut, $nb_per_page, $elt_query);
        } else {
            $res = entites::listRubriquesFinales($id_bibli, $id_exer, true, 0, 0, $elt_query);
        }
        $id_bud = 0;
        print "<div class=\"row\"><table><tr><th>" . htmlentities($msg['acquisition_rub'], ENT_QUOTES, $charset) . "</th><th>" . htmlentities($msg['acquisition_rub_sol'], ENT_QUOTES, $charset) . "</th></tr>";
        while ($row = mysql_fetch_object($res)) {
            $new_id_bud = $row->num_budget;
            if ($new_id_bud != $id_bud) {
                $id_bud = $new_id_bud;
                print pmb_bidi("<tr><td>" . htmlentities($row->lib_bud, ENT_QUOTES, $charset) . "</td>");
                if ($row->type_budget) {
                    $aff_glo = true;
                    $mnt = $row->montant_global;
                    $cal = budgets::calcEngagement($id_bud);
                    if ($cal > $mnt) {
                        $sol = 0;
                    } else {
                        $sol = $mnt - $cal;
                    }
                    $sol = number_format($sol, 2, '.', '');
                    if ($cal > $mnt * ($row->seuil_alerte / 100)) {
                        $alert = true;
                    } else {
                        $alert = false;
                    }
                } else {
                    $aff_glo = false;
                }
                print "<td></td></tr>";
            }
            $tab_rub = rubriques::listAncetres($row->id_rubrique, true);
            $lib_rub = '';
            $lib_rub_no_html = "";
            foreach ($tab_rub as $dummykey => $value) {
                $lib_rub .= htmlentities($value[1], ENT_QUOTES, $charset);
                $lib_rub_no_html .= $value[1];
                if ($value[0] != $row->id_rubrique) {
                    $lib_rub .= ":";
                }
            }
            if (!$aff_glo) {
                $mnt = $row->montant;
                $cal = rubriques::calcEngagement($row->id_rubrique);
                if ($cal > $mnt) {
                    $sol = 0;
                } else {
                    $sol = $mnt - $cal;
                }
                $sol = number_format($sol, 2, '.', '');
                if ($cal >= $mnt * ($row->seuil_alerte / 100)) {
                    $alert = true;
                } else {
                    $alert = false;
                }
            }
            if ($alert) {
                $cl = "class='erreur' ";
            } else {
                $cl = '';
            }
            print "<tr><td><div class='child_tab'>";
            print pmb_bidi("\n\t\t\t<a href='#' onclick=\"set_parent('{$caller}', '{$row->id_rubrique}', '" . htmlentities(addslashes($row->lib_bud . ":" . $lib_rub_no_html), ENT_QUOTES, $charset) . "' )\" ><span " . $cl . ">" . $lib_rub . "</span></a>\n\t\t\t</div></td><td style='text-align:right;'><span " . $cl . ">" . $sol . "</span></td></tr>");
        }
        print "</table>";
        mysql_free_result($res);
        // affichage pagination
        print "<hr /><div align='center'>";
        if (!$acquisition_budget_show_all) {
            $base_url .= "&elt_query=" . $elt_query;
            $nav_bar = aff_pagination($base_url, $nbr_lignes, $nb_per_page, $page, 10, true, true);
            print $nav_bar;
        }
        print "</div></div>";
    }
}