Commit 0b8c62c6 authored by Laurent Lecluse's avatar Laurent Lecluse
Browse files

wip repartiteur

parent 7b68045d
Loading
Loading
Loading
Loading
−177
Changes for code/test9.php: 0 added lines, 177 removed lines.
Original line number Diff line number Diff line
@@ -7,180 +7,3 @@
 * @var $viewName   string
 * @var $viewFile   string
 */

$data = [
    1 => [ // mep = lap
        'lap' => [
            ['aa' => 5, 'ac' => 4],
        ],
        'mep' => [
            ['h' => 9],
        ],
    ],
    2 => [ // mep < lap
        'lap' => [
            ['aa' => 5, 'ac' => 4],
        ],
        'mep' => [
            ['h' => 6],
        ],
    ],
    3 => [ // 3 mep
        'lap' => [
            ['aa' => 5, 'ac' => 4],
        ],
        'mep' => [
            ['h' => 2],
            ['h' => 3],
            ['h' => 1],
        ],
    ],
    4 => [ // n mep, = lap
        'lap' => [
            ['aa' => 5, 'ac' => 4],
            ['aa' => 3, 'ac' => 21],
        ],
        'mep' => [
            ['h' => 33],
        ],
    ],
    5 => [ // n mep, =  2 lap
        'lap' => [
            ['aa' => 5, 'ac' => 4],
            ['aa' => 3, 'ac' => 21],
        ],
        'mep' => [
            ['h' => 18],
            ['h' => 15],
        ],
    ],
    6 => [ // n mep, <  2 lap
        'lap' => [
            ['aa' => 5, 'ac' => 4],
            ['aa' => 3, 'ac' => 21],
        ],
        'mep' => [
            ['h' => 3],
            ['h' => 10],
            ['h' => 31],
        ],
    ],
];

//unset($data[1]);
//unset($data[2]);
//unset($data[3]);
//unset($data[4]);
//unset($data[5]);
//unset($data[6]);


function traitementProrata(array &$d)
{
    $laps = &$d['lap'];
    $meps = &$d['mep'];

    foreach ($laps as $lid => $null) {
        $lap = &$laps[$lid];
        $lap['mep'] = [];

        /* ALGO */
        $npAA = $lap['aa'];
        $npAC = $lap['ac'];
        /* FIN ALGO */

        foreach ($meps as $mid => $null) {
            $mep = &$meps[$mid];

            if ($npAA + $npAC == 0) break;

            /* ALGO */
            $nmep = ['aa' => 0, 'ac' => 0];

            $heures = min($mep['h'], $npAA+$npAC);

            $aaHeures = min((int)round($heures * $npAA / ($npAA+$npAC)), $npAA);
            if ($aaHeures > 0) {
                $nmep['aa'] += $aaHeures;
                $mep['h'] -= $aaHeures;
                $npAA -= $aaHeures;
            }

            $acHeures = $heures - $aaHeures;
            if ($acHeures > 0) {
                $nmep['ac'] += $acHeures;
                $mep['h'] -= $acHeures;
                $npAC -= $acHeures;
            }

            if ($nmep['aa'] + $nmep['ac'] > 0) {
                $lap['mep'][$mid] = $nmep;
                if ($mep['h'] == 0){
                    unset($meps[$mid]);
                }
            }
            /* FIN ALGO */
        }
    }

}


function traitementOrdre(array &$d)
{
    $laps = &$d['lap'];
    $meps = &$d['mep'];

    foreach ($laps as $lid => $null) {
        $lap = &$laps[$lid];
        $lap['mep'] = [];

        /* ALGO */
        $npAA = $lap['aa'];
        $npAC = $lap['ac'];
        /* FIN ALGO */

        foreach ($meps as $mid => $null) {
            $mep = &$meps[$mid];

            /* ALGO */
            $nmep = ['aa' => 0, 'ac' => 0];

            $heures = min($mep['h'], $npAA);
            if ($heures > 0) {
                $nmep['aa'] += $heures;
                $mep['h'] -= $heures;
                $npAA -= $heures;
            }

            $heures = min($mep['h'], $npAC);
            if ($heures > 0) {
                $nmep['ac'] += $heures;
                $mep['h'] -= $heures;
                $npAC -= $heures;
            }

            if ($nmep['aa'] + $nmep['ac'] > 0) {
                $lap['mep'][$mid] = $nmep;
                if ($mep['h'] == 0){
                    unset($meps[$mid]);
                }
            }
            /* FIN ALGO */
        }
    }

}


foreach ($data as $index => $d) {
    echo "================== Cas " . $index . " ==================\n";
    echo "----- Avant ----------\n";
    arrayDump($d);
    echo "----- Traitement -----\n";
    //traitementOrdre($d);
    traitementProrata($d);
    echo "----- Après ----------\n";
    arrayDump($d);
    echo "\n";
}
 No newline at end of file
+61
Changes for tests/TblPaiement/RepartiteurTest.php: 61 added lines, 0 removed lines.
Original line number Diff line number Diff line
<?php declare(strict_types=1);

namespace TblPaiement;

use Paiement\Tbl\Process\Sub\Repartiteur;
use Paiement\Tbl\Process\Sub\ServiceAPayer;
use tests\OseTestCase;

final class RepartiteurTest extends OseTestCase
{
    protected Repartiteur $repartiteur;



    protected function setUp(): void
    {
        $this->repartiteur = new Repartiteur();
    }



    protected function process(array $data)
    {


        $this->assertArrayEquals($calc, $await);
    }



    public function testAll()
    {
        $tests = [
            [
                'reglePaiementAnneeCiv'  => ,
                'pourcS1PourAnneeCivile' => ,
                'semestriel'             => ,
                'periodeCode'            => ,
                'anneeId'                => ,
                'horaireDebut'           => ,
                'horaireFin'             => ,
                'await'                  => ,
            ],
        ];

        foreach ($tests as $test) {

            $this->repartiteur->setPourcS1PourAnneeCivile($test['reglePaiementAnneeCiv']);
            $this->repartiteur->setPourcS1PourAnneeCivile($test['pourcS1PourAnneeCivile']);
            $calc = $this->repartiteur->calculPourcAA(
                semestriel: $test['semestriel'],
                periodeCode: $test['periodeCode'],
                anneeId: $test['anneeId'],
                horaireDebut: $test['horaireDebut'],
                horaireFin: $test['horaireFin']
            );

            $this->assertEquals($test['await'], $calc);
        }
    }
}