Commit a130007d authored by Antony Le Courtes's avatar Antony Le Courtes
Browse files

Correction des demandes de mise en paiement pour pouvoir gérer la notion de...

Correction des demandes de mise en paiement pour pouvoir gérer la notion de budget sur des types de ressources autres que de la paie état ou des ressources propres (#61953)
parent a082fa1d
Loading
Loading
Loading
Loading
+52 −104
Original line number Diff line number Diff line
@@ -14,61 +14,44 @@
        <div :id="'dmep-collapse-' + datas.code" :aria-labelledby="'dmep-heading-' + datas.code"
             class="accordion-collapse collapse show">
            <div class="accordion-body">
                <div v-if="this.dotationPaieEtat + dotationRessourcesPropres > 0">
                <div v-if="this.datas.budget.dotation.total > 0">
                    <!--Budget-->
                    <div class="cartridge gray bordered" style="padding-bottom: 5px;margin-bottom:20px;">
                        <span>Budget</span>
                    </div>
                    <div class="container">
                        <table class="table table-bordered caption-top">
                        <table class="table table-bordered caption-top" style="table-layout: fixed;width:100%">
                            <thead class="table-light">
                            <tr>
                                <th class="fw-bold" scope="col">Paie état</th>
                                <th class="fw-bold" scope="col">Ressources propres</th>

                                <th v-for="(value, index) in datasBudget"
                                    :key="index"
                                    class="fw-bold"
                                    scope="col">{{ value.libelle }}
                                </th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr>

                                <td style="width:50%;">
                                    <div v-if="this.dotationPaieEtat > 0"
                                <td v-for="(value, index) in datasBudget">
                                    <div v-if="value.dotation > 0"
                                         class="text-center progress position-relative bg-secondary"
                                         style="height: 30px;">
                                        <span class="position-absolute top-50 start-50 translate-middle"
                                              style="color:white;">{{
                                                this.consommationPaieEtat + ' sur ' + this.dotationPaieEtat
                                                value.consommation + ' sur ' + value.dotation
                                            }} HETD</span>
                                        <div :aria-valuemax="this.dotationPaieEtat"
                                             :aria-valuenow="this.consommationPaieEtat"
                                             :class="'progress-bar progress-bar-striped '+ this.bgPaieEtat"
                                             :style="'width:' + this.pourcentagePaieEtat + '%;'"
                                             :title="this.pourcentagePaieEtat + '%'"
                                        <div :aria-valuemax="value.dotation"
                                             :aria-valuenow="value.consommation"
                                             :class="'progress-bar progress-bar-striped '+ bgBudget(value)"
                                             :style="'width:' + pourcentageBudget(value) + '%;'"
                                             :title="this.pourcentageBudget(value) + '%'"
                                             aria-valuemin="0"
                                             role="progressbar">
                                        </div>
                                    </div>
                                    <div v-if="this.dotationPaieEtat == 0" class="text-center">
                                        Aucune dotation paie état
                                    </div>
                                </td>
                                <td style="width:50%;">
                                    <div v-if="this.dotationRessourcesPropres > 0"
                                         class="progress position-relative bg-secondary" style="height: 30px;">
                                        <span class="position-absolute top-50 start-50 translate-middle"
                                              style="color:white;">{{
                                                this.consommationRessourcesPropres + ' sur ' + this.dotationRessourcesPropres
                                            }} HETD</span>
                                        <div :aria-valuemax="this.dotationRessourcesPropres"
                                             :aria-valuenow="this.consommationRessourcesPropres"
                                             :class="'progress-bar progress-bar-striped '+ this.bgRessourcesPropres"
                                             :style="'width:' + this.pourcentageRessourcePropre + '%;'"
                                             :title="this.pourcentageRessourcePropre + '%'"
                                             aria-valuemin="0"
                                             role="progressbar">
                                        </div>
                                    </div>
                                    <div v-if="this.dotationRessourcesPropres == 0" class="text-center">
                                        Aucune dotation ressources propres
                                    <div v-if="value.dotation == 0" class="text-center">
                                        Aucune dotation {{ value.libelle }}
                                    </div>
                                </td>
                            </tr>
@@ -159,8 +142,6 @@
                                                                        <option
                                                                            v-for="item in group.child"
                                                                            :key="item.value"
                                                                            :data-paie-etat="item.paieEtat"
                                                                            :data-ressources-propres="item.ressourcesPropres"
                                                                            :selected="item.centreCoutId==value.centreCout.centreCoutId"
                                                                            :value="item.centreCoutId">
                                                                            {{
@@ -303,8 +284,6 @@
                                                                :label="group.group">
                                                                <option v-for="item in group.child"
                                                                        :key="item.value"
                                                                        :data-paie-etat="item.paieEtat"
                                                                        :data-ressources-propres="item.ressourcesPropres"
                                                                        :selected="item.centreCoutId == value.centreCout.centreCoutId"
                                                                        :value="item.centreCoutId">
                                                                    {{
@@ -463,8 +442,6 @@
                                                                :label="group.group">
                                                                <option v-for="item in group.child"
                                                                        :key="item.value"
                                                                        :data-paie-etat="item.paieEtat"
                                                                        :data-ressources-propres="item.ressourcesPropres"
                                                                        :selected="item.centreCoutId == value.centreCout.centreCoutId"
                                                                        :value="item.centreCoutId"
                                                                >
@@ -570,59 +547,39 @@

export default {


    name: "DemandeMiseEnPaiementStructure",
    props: {
        datas: {required: true},
        intervenant: {required: true},
    },
    data()
    {

        return {
            dotationPaieEtat: this.datas.budget.dotation.paieEtat,
            dotationRessourcesPropres: this.datas.budget.dotation.ressourcePropre,
            consommationPaieEtat: this.datas.budget.liquidation.paieEtat,
            consommationRessourcesPropres: this.datas.budget.liquidation.ressourcePropre,

        }
    },
    watch: {
        datas: function () {
            this.dotationPaieEtat = this.datas.budget.dotation.paieEtat;
            this.dotationRessourcesPropres = this.datas.budget.dotation.ressourcePropre;
            this.consommationPaieEtat = this.datas.budget.liquidation.paieEtat;
            this.consommationRessourcesPropres = this.datas.budget.liquidation.ressourcePropre;
        },

    },
    computed:
        {
            pourcentagePaieEtat()
            {
                return Math.round((this.consommationPaieEtat / this.dotationPaieEtat) * 100);
            },
            pourcentageRessourcePropre()
            {
                return Math.round((this.consommationRessourcesPropres / this.dotationRessourcesPropres) * 100);
            },
            bgPaieEtat()
            datasBudget()
            {
                if (Math.round((this.consommationPaieEtat / this.dotationPaieEtat) * 100) > 100) {
                    return 'bg-warning';
                } else {
                    return 'bg-success';
                let datasBudget = {};
                Object.entries(this.datas.budget.dotation).forEach(([key, value]) => {
                    if (key != 'total') {
                        datasBudget[key] = {};
                        datasBudget[key]['libelle'] = value.libelle;
                        datasBudget[key]['dotation'] = value.heures;
                        datasBudget[key]['consommation'] = 1001;
                    }
            },
            bgRessourcesPropres()
            {
                if (Math.round((this.consommationRessourcesPropres / this.dotationRessourcesPropres) * 100) > 100) {
                    return 'bg-warning';
                } else {
                    return 'bg-success';
                });

                Object.entries(this.datas.budget.consommation).forEach(([key, value]) => {
                    if (key != 'total') {
                        if (key in datasBudget) {
                            datasBudget[key]['consommation'] = value.heures;
                        }

                    }
                });
                return datasBudget;
            }

        },

    methods: {
        heuresStatutToString(value)
        {
@@ -707,8 +664,6 @@ export default {
            let missionId = (inputHeure.hasAttribute('data-mission-id') ? inputHeure.getAttribute('data-mission-id') : '');

            let centreCoutId = inputCentreCout.value;
            let ressourcesPropres = inputCentreCout.options[inputCentreCout.selectedIndex].getAttribute('data-ressources-propres');
            let paieEtat = inputCentreCout.options[inputCentreCout.selectedIndex].getAttribute('data-paie-etat');
            //Si centre de cout non sélectionné
            if (centreCoutId == '') {
                unicaenVue.flashMessenger.toast("Vous devez sélectionner un centre de coût pour demander la mise en paiement de ces heures", 'error', options)
@@ -721,25 +676,6 @@ export default {
                this.$emit('refresh-btn-state');;
                return false;
            }
            //Si je suis sur une demande de mise en paiement avec des fonds paie etat
            if (paieEtat == 1 && this.dotationPaieEtat > 0) {
                let solde = this.dotationPaieEtat - (this.consommationPaieEtat + heureADemander);
                if (solde <= 0) {
                    unicaenVue.flashMessenger.toast("Demande de mise en paiement impossible manque de dotation 'paie etat' pour ces heures", 'error', options)
                    this.$emit('refresh-btn-state');
                    return false;
                }
            }
            //Si je suis sur une demande de mise en paiement avec des fonds ressources propres
            if (ressourcesPropres == 1 && this.dotationRessourcesPropres > 0) {
                let solde = this.dotationRessourcesPropres - (this.consommationRessourcesPropres + heureADemander);
                if (solde <= 0) {
                    unicaenVue.flashMessenger.toast("Demande de mise en paiement impossible manque de dotation 'ressources propres' pour ces heures", 'error', options)
                    this.$emit('refresh-btn-state');
                    return false;
                }
            }


            var datas = [];
            let demande = {
@@ -893,6 +829,18 @@ export default {
        {
            return Util.dateToString(val);

        },
        pourcentageBudget(value)
        {
            return Math.round((value.consommation / value.dotation) * 100);
        },
        bgBudget(value)
        {
            if (Math.round((value.consommation / value.dotation) * 100) > 100) {
                return 'bg-danger';
            } else {
                return 'bg-success';
            }
        }


+2 −1
Original line number Diff line number Diff line
@@ -64,7 +64,8 @@ class DemandesController extends AbstractController
            $demandes                         = $this->axios()->fromPost();
            $demandesApprouveesBudgetairement = $this->getServiceDemandes()->verifierBudgetDemandeMiseEnPaiement($demandes);
            $error                            = 0;
            $errorBudget                      = count($demandes) - count($demandesApprouveesBudgetairement);
            $errorBudget = round(count($demandes) - count($demandesApprouveesBudgetairement));

            $success                          = 0;
            foreach ($demandesApprouveesBudgetairement as $demande) {
                try {
+20 −14
Original line number Diff line number Diff line
@@ -14,6 +14,7 @@ use Lieu\Entity\Db\Structure;
class BudgetService extends AbstractService
{
    use DotationServiceAwareTrait;
    use TypeRessourceServiceAwareTrait;


    /**
@@ -102,32 +103,37 @@ class BudgetService extends AbstractService
    {
        $budget = [
            'dotation'    => [
                'paieEtat'        => 0,
                'ressourcePropre' => 0,
                'total'           => 0,
            ],
            'liquidation' => [
                'paieEtat'        => 0,
                'ressourcePropre' => 0,
            'consommation' => [
                'total'           => 0,
            ],

        ];
        if ($structure instanceof Structure) {
        $dotation = $this->getServiceDotation()->getTableauBord([$structure->getId()]);
        $liquidation = $this->getTblLiquidation($structure);
            foreach ($dotation as $key => $value) {

        if (!empty($dotation)) {
            $dotation    = $this->getServiceDotation()->getTableauBord([$structure->getId()]);
            $liquidation = $this->getTblLiquidation($structure);
            foreach ($dotation as $key => $values) {
                if ($key == $structure->getId()) {
                    $budget['dotation']['paieEtat']        = (key_exists(1, $value)) ? $value['1'] : 0;
                    $budget['dotation']['ressourcePropre'] = (key_exists(2, $value)) ? $value['2'] : 0;
                    $budget['dotation']['total']           = $value['total'];
                    foreach ($values as $k => $v) {
                        if ($k != 'total') {
                            $typeRessources                                                = $this->getServiceTypeRessource()->get($k);
                            $budget['dotation'][$typeRessources->getCode()]['heures']      = $v;
                            $budget['dotation'][$typeRessources->getCode()]['libelle']     = $typeRessources->getLibelle();
                            $budget['consommation'][$typeRessources->getCode()]['heures']  = (key_exists($k, $liquidation)) ? $liquidation[$k] : 0;
                            $budget['consommation'][$typeRessources->getCode()]['libelle'] = $typeRessources->getLibelle();
                        } else {
                            $budget['dotation']['total'] = $values['total'];
                        }
                    }
                    break;
                }
            }
            //liquidation
            $budget['liquidation']['paieEtat']        = (key_exists('1', $liquidation)) ? $liquidation['1'] : 0;
            $budget['liquidation']['ressourcePropre'] = (key_exists('2', $liquidation)) ? $liquidation['2'] : 0;
            $budget['liquidation']['total']           = $liquidation['total'];
            $budget['consommation']['total'] = $liquidation['total'];

        }

        return $budget;
+12 −19
Original line number Diff line number Diff line
@@ -597,8 +597,7 @@ class DemandesService extends AbstractService
    public function verifierBudgetDemandeMiseEnPaiement(array $demandes): array
    {
        $demandesApprouvees                      = [];
        $totalHeuresDemandees['ressourcePropre'] = 0;
        $totalHeuresDemandees['paieEtat']        = 0;
        $totalHeuresDemandees = [];

        //1 - On récupère le budget de la structure pour laquelle on a des heures à demander
        foreach ($demandes as $demande) {
@@ -607,36 +606,30 @@ class DemandesService extends AbstractService
            if ($structure instanceof Structure) {

                $budget = $this->getServiceBudget()->getBudgetPaiement($structure);

                //2 - On récupère le centre de cout que nous souhaitons utiliser pour la demande de mise en paiement

                $centreCout = $this->getEntityManager()->getRepository(CentreCout::class)->find($demande['centreCoutId']);
                $centreCout = $this->getServiceCentreCout()->get($demande['centreCoutId']);
                if ($centreCout instanceof CentreCout) {
                    //3 - on vérifier si il y a du budget dans le type de ressource auquel est rattaché ce centre de cout
                    if ($centreCout->getTypeRessource()->getCode() == 'ressources-propres') {
                        if ($budget['dotation']['ressourcePropre'] > 0) {
                    if (array_key_exists($centreCout->getTypeRessource()->getCode(), $budget['dotation'])) {
                        if (!array_key_exists($centreCout->getTypeRessource()->getCode(), $totalHeuresDemandees)) {
                            $totalHeuresDemandees[$centreCout->getTypeRessource()->getCode()] = 0;
                        }
                        if ($budget['dotation'][$centreCout->getTypeRessource()->getCode()]['heures'] > 0) {

                            //4 - on regarde si il y a encore assez de budget pour demander les heures en paiement
                            $total = round($budget['liquidation']['ressourcePropre'] + $demande['heures'] + $totalHeuresDemandees['ressourcePropre'],2);
                            if ($total <= $budget['dotation']['ressourcePropre']) {
                                $totalHeuresDemandees['ressourcePropre'] += $demande['heures'];
                            $total = round($budget['consommation'][$centreCout->getTypeRessource()->getCode()]['heures'] + $demande['heures'] + $totalHeuresDemandees[$centreCout->getTypeRessource()->getCode()], 2);
                            if ($total <= $budget['dotation'][$centreCout->getTypeRessource()->getCode()]['heures']) {
                                $totalHeuresDemandees[$centreCout->getTypeRessource()->getCode()] += $demande['heures'];
                            } else {
                                continue;
                            }
                        }
                        $demandesApprouvees[] = $demande;
                    }
                    if ($centreCout->getTypeRessource()->getCode() == 'paie-etat') {
                        //Si la dotation est supérieur à 0, alors on vérifie s'il reste du budget disponible
                        if ($budget['dotation']['paieEtat'] > 0) {
                            //4bis - on regarde s'il y a encore assez de budget pour demander les heures en paiement
                            $total = round($budget['liquidation']['paieEtat'] + $demande['heures'] + $totalHeuresDemandees['paieEtat'],2);
                            if ($total <= $budget['dotation']['paieEtat']) {
                                $totalHeuresDemandees['paieEtat'] += $demande['heures'];
                    } else {
                                continue;
                            }
                        }
                        //Si pas de dotation dans ce type de ressources alors on autorise obligatoirement la demande
                        $demandesApprouvees[] = $demande;
                    }
                } else {
+5 −1
Original line number Diff line number Diff line
@@ -49,7 +49,7 @@ class DotationService extends AbstractEntityService
    /**
     * Retourne, dans un tableau, le nombre d'heures abondées budgétairement par structure et par type de ressource
     */
    public function getTableauBord( array $structures = [] )
    public function getTableauBord(array $structures = []): array
    {
        $sql = "
        SELECT
@@ -80,6 +80,10 @@ class DotationService extends AbstractEntityService
            $res['total'] += $heures;
        }

        if ($res['total'] == 0) {
            return [];
        }

        return $res;
    }