function afficheSousRubriques($bud, $id_rub, &$form, $indent = 0) { global $dbh, $charset; global $view_lig_rub_form, $lig_rub_img, $lig_indent; global $acquisition_gestion_tva; switch ($acquisition_gestion_tva) { case '0': case '2': $htttc = htmlentities($msg['acquisition_ttc'], ENT_QUOTES, $charset); $k_htttc = 'ttc'; $k_htttc_autre = 'ht'; break; default: $htttc = htmlentities($msg['acquisition_ht'], ENT_QUOTES, $charset); $k_htttc = 'ht'; $k_htttc_autre = 'ttc'; break; } $id_bud = $bud->id_budget; $q = budgets::listRubriques($id_bud, $id_rub); $list_n = pmb_mysql_query($q, $dbh); while ($row = pmb_mysql_fetch_object($list_n)) { $form = str_replace('<!-- sous_rub' . $id_rub . ' -->', $view_lig_rub_form . '<!-- sous_rub' . $id_rub . ' -->', $form); $marge = ''; for ($i = 0; $i < $indent; $i++) { $marge .= $lig_indent; } $form = str_replace('<!-- marge -->', $marge, $form); $nb_sr = rubriques::countChilds($row->id_rubrique); if ($nb_sr) { $form = str_replace('<!-- img_plus -->', $lig_rub_img, $form); } else { $form = str_replace('<!-- img_plus -->', '', $form); } $form = str_replace('<!-- sous_rub -->', '<!-- sous_rub' . $row->id_rubrique . ' -->', $form); $form = str_replace('!!id_rub!!', $row->id_rubrique, $form); $form = str_replace('!!id_parent!!', $row->num_parent, $form); $libelle = htmlentities($row->libelle, ENT_QUOTES, $charset); $form = str_replace('!!lib_rub!!', $libelle, $form); //montant total $mnt['tot'][$k_htttc] = $row->montant; //montant a valider $mnt['ava'] = rubriques::calcAValider($row->id_rubrique); //montant engage $mnt['eng'] = rubriques::calcEngage($row->id_rubrique); //montant facture $mnt['fac'] = rubriques::calcFacture($row->id_rubrique); //montant paye $mnt['pay'] = rubriques::calcPaye($row->id_rubrique); //solde $mnt['sol'][$k_htttc] = $mnt['tot'][$k_htttc] - $mnt['eng'][$k_htttc]; $lib_mnt = array(); foreach ($mnt as $k => $v) { $lib_mnt[$k] = number_format($mnt[$k][$k_htttc], 2, '.', ' '); if ($acquisition_gestion_tva && $k != "tot" && $k != "sol") { $lib_mnt_autre[$k] = number_format($mnt[$k][$k_htttc_autre], 2, '.', ' '); } } if ($bud->type_budget == TYP_BUD_GLO) { $lib_mnt['tot'] = ' '; $lib_mnt['sol'] = ' '; } foreach ($lib_mnt as $k => $v) { if (!$acquisition_gestion_tva || !$lib_mnt_autre[$k]) { $form = str_replace('!!mnt_' . $k . '!!', $lib_mnt[$k], $form); } elseif ($acquisition_gestion_tva) { $form = str_replace('!!mnt_' . $k . '!!', $lib_mnt[$k] . "<br />" . $lib_mnt_autre[$k], $form); } } if ($nb_sr) { afficheSousRubriques($bud, $row->id_rubrique, $form, $indent + 1); } } }
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; } } } } }
static function delete($id_exercice = 0) { global $dbh; if (!$id_exercice) { return; } //Suppression des actes //TODO Voir suppression du lien entre actes et exercices $res_actes = actes::listByExercice($id_exercice); while ($row = mysql_fetch_object($res_actes)) { actes::delete($row->id_acte); } //Suppression des budgets $res_budgets = budgets::listByExercice($id_exercice); while ($row = mysql_fetch_object($res_budgets)) { budgets::delete($row->id_budget); } //Suppression de l'exercice $q = "delete from exercices where id_exercice = '" . $id_exercice . "' "; mysql_query($q, $dbh); }
function afficheSousRubriques($id_bud, $id_rub, &$form, $indent = 0) { global $dbh, $msg, $charset; global $lig_rub, $lig_rub_img, $lig_indent; $bud = new budgets($id_bud); $q = budgets::listRubriques($id_bud, $id_rub); $list_n = mysql_query($q, $dbh); while ($row = mysql_fetch_object($list_n)) { $form = str_replace('<!-- sous_rub' . $id_rub . ' -->', $lig_rub[0] . '<!-- sous_rub' . $id_rub . ' -->', $form); $marge = ''; for ($i = 0; $i < $indent; $i++) { $marge .= $lig_indent; } $form = str_replace('<!-- marge -->', $marge, $form); if (rubriques::countChilds($row->id_rubrique)) { $form = str_replace('<!-- img_plus -->', $lig_rub_img, $form); } else { $form = str_replace('<!-- img_plus -->', '', $form); } $form = str_replace('<!-- sous_rub -->', '<!-- sous_rub' . $row->id_rubrique . ' -->', $form); $form = str_replace('!!id_rub!!', $row->id_rubrique, $form); $form = str_replace('!!id_parent!!', $row->num_parent, $form); $form = str_replace('!!lib_rub!!', $row->libelle, $form); if ($bud->type_budget == TYP_BUD_RUB) { $form = str_replace('!!mnt!!', $row->montant, $form); } else { $form = str_replace('!!mnt!!', ' ', $form); } $form = str_replace('!!ncp!!', $row->num_cp_compta, $form); afficheSousRubriques($id_bud, $row->id_rubrique, $form, $indent + 1); } }
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>"; } }
static function calcMontant($id_budget = 0) { global $dbh; if ($id_budget) { $q = "select sum(montant) from rubriques where num_budget = '" . $id_budget . "' and num_parent = '0' "; $r = mysql_query($q, $dbh); $total = mysql_result($r, 0, 0); $budget = new budgets($id_budget); $budget->montant_global = $total; $budget->save(); } }