Overview
Comment:Modernisation : comptes bancaires
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: ddb9d065194b62cd31c50fb767e9802631edea30
User & Date: bohwaz on 2017-08-17 01:34:58
Other Links: branch diff | manifest | tags
Context
2017-08-17
04:45
Correction bugs CSS et date check-in: 021d913259 user: bohwaz tags: dev
01:34
Modernisation : comptes bancaires check-in: ddb9d06519 user: bohwaz tags: dev
00:49
Modernisation catégories compta check-in: ba738d8d9a user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Compta/Rapprochement.php from [dde3f8b132] to [0ca57367ca].

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
            'debut'     =>  $debut,
            'fin'       =>  $fin,
            'exercice'  =>  $exercice
        ]);

        foreach ($result as &$row)
        {
            $solde += $row['solde'];
            $row['solde'] = $solde;
        }

        $solde_final = $solde;

        return $result;
    }








|
|







41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
            'debut'     =>  $debut,
            'fin'       =>  $fin,
            'exercice'  =>  $exercice
        ]);

        foreach ($result as &$row)
        {
            $solde += $row->solde;
            $row->solde = $solde;
        }

        $solde_final = $solde;

        return $result;
    }

72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
        // Synchro des trucs cochés
        $st = $db->prepare('INSERT OR REPLACE INTO compta_rapprochement (id_operation, id_auteur) 
            VALUES (:operation, :auteur);');
        $st->bindValue(':auteur', (int)$auteur, \SQLITE3_INTEGER);

        foreach ($journal as $row)
        {
            if (!array_key_exists($row['id'], $cases))
                continue;

            $st->bindValue(':operation', (int)$row['id'], \SQLITE3_INTEGER);
            $st->execute();
        }

        // Synchro des trucs NON cochés
        $st = $db->prepare('DELETE FROM compta_rapprochement WHERE id_operation = :id;');

        foreach ($journal as $row)
        {
            if (array_key_exists($row['id'], $cases))
                continue;

            $st->bindValue(':id', (int)$row['id'], \SQLITE3_INTEGER);
            $st->execute();
        }

        $db->commit();
        return true;
    }
}







|


|








|


|







72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
        // Synchro des trucs cochés
        $st = $db->prepare('INSERT OR REPLACE INTO compta_rapprochement (id_operation, id_auteur) 
            VALUES (:operation, :auteur);');
        $st->bindValue(':auteur', (int)$auteur, \SQLITE3_INTEGER);

        foreach ($journal as $row)
        {
            if (!array_key_exists($row->id, $cases))
                continue;

            $st->bindValue(':operation', (int)$row->id, \SQLITE3_INTEGER);
            $st->execute();
        }

        // Synchro des trucs NON cochés
        $st = $db->prepare('DELETE FROM compta_rapprochement WHERE id_operation = :id;');

        foreach ($journal as $row)
        {
            if (array_key_exists($row->id, $cases))
                continue;

            $st->bindValue(':id', (int)$row->id, \SQLITE3_INTEGER);
            $st->execute();
        }

        $db->commit();
        return true;
    }
}

Modified src/include/lib/Garradin/Utils.php from [07575ef06e] to [38a24e8737].

507
508
509
510
511
512
513
514
515


516




517



518
519
520
521
522
523
524
525
    }

    static public function suggestPassword()
    {
        return Security::getRandomPassphrase(ROOT . '/include/data/dictionary.fr');
    }

    static public function checkIBAN($iban)
    {


        $iban = substr($iban, 4) . substr($iban, 0, 4);




        $iban = str_replace(range('A', 'Z'), range(10, 35), $iban);



        return (bcmod($iban, 97) == 1);
    }
    
    static public function checkBIC($bic)
    {
        return preg_match('!^[A-Z]{4}[A-Z]{2}[1-9A-Z]{2}(?:[A-Z\d]{3})?$!', $bic);
    }








|

>
>
|
>
>
>
>
|
>
>
>
|







507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
    }

    static public function suggestPassword()
    {
        return Security::getRandomPassphrase(ROOT . '/include/data/dictionary.fr');
    }

    static public function checkIBAN($value)
    {
        // Enlever les caractères indésirables (espaces, tirets),
        $value = preg_replace('/[^A-Z0-9]/', '', strtoupper($value));
        
        // Supprimer les 4 premiers caractères et les replacer à la fin du compte
        $value = substr($value, 4) . substr($value, 0, 4);

        // Remplacer les lettres par des chiffres au moyen d'une table de conversion (A=10, B=11, C=12 etc.)
        $value = str_replace(range('A', 'Z'), range(10, 35), $value);

        // Diviser le nombre ainsi obtenu par 97
        // Si le reste n'est pas égal à 1 l'IBAN est incorrect : Modulo de 97 égal à 1.
        return (bcmod($value, 97) == 1);
    }
    
    static public function checkBIC($bic)
    {
        return preg_match('!^[A-Z]{4}[A-Z]{2}[1-9A-Z]{2}(?:[A-Z\d]{3})?$!', $bic);
    }

Modified src/templates/admin/compta/banques/modifier.tpl from [9e2a94ee6b] to [46b56f033b].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{include file="admin/_head.tpl" title="Modifier un compte" current="compta/banques"}

{if $error}
    <p class="error">
        {$error}
    </p>
{/if}

<form method="post" action="{$self_url}">

    <fieldset>
        <legend>Modifier un compte bancaire</legend>
        <dl>
            <dt><label for="f_libelle">Libellé</label> <b title="(Champ obligatoire)">obligatoire</b></dt>


<
<
|
<
<







1
2


3


4
5
6
7
8
9
10
{include file="admin/_head.tpl" title="Modifier un compte" current="compta/banques"}



{form_errors}



<form method="post" action="{$self_url}">

    <fieldset>
        <legend>Modifier un compte bancaire</legend>
        <dl>
            <dt><label for="f_libelle">Libellé</label> <b title="(Champ obligatoire)">obligatoire</b></dt>

Modified src/templates/admin/compta/banques/rapprocher.tpl from [c0b0802567] to [a6ece77d56].

27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
            <input type="date" name="fin" id="f_fin" value="{form_field name='fin' default=$fin}" />
            <input type="hidden" name="id" value="{$compte.id}" />
            <input type="submit" value="Afficher" />
        </p>
    </fieldset>
</form>

{if $error}
    <p class="error">{$error}</p>
{/if}

<form method="post" action="{$self_url}">
    <table class="list">
        <colgroup>
            <col width="3%" />
            <col width="3%" />
            <col width="3%" />







|
<
<







27
28
29
30
31
32
33
34


35
36
37
38
39
40
41
            <input type="date" name="fin" id="f_fin" value="{form_field name='fin' default=$fin}" />
            <input type="hidden" name="id" value="{$compte.id}" />
            <input type="submit" value="Afficher" />
        </p>
    </fieldset>
</form>

{form_errors}



<form method="post" action="{$self_url}">
    <table class="list">
        <colgroup>
            <col width="3%" />
            <col width="3%" />
            <col width="3%" />

Modified src/templates/admin/compta/banques/supprimer.tpl from [aca4962b79] to [f2f4e5378b].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
{include file="admin/_head.tpl" title="Supprimer un compte" current="compta/banques"}

{if $error}
    <p class="error">
        {$error}
    </p>
{/if}

<form method="post" action="{$self_url}">

    <fieldset>
        <legend>Supprimer le compte ?</legend>
        <h3 class="warning">
            Êtes-vous sûr de vouloir supprimer le compte «&nbsp;{$compte.id} - {$compte.libelle}&nbsp;» ?


<
<
|
<
<







1
2


3


4
5
6
7
8
9
10
{include file="admin/_head.tpl" title="Supprimer un compte" current="compta/banques"}



{form_errors}



<form method="post" action="{$self_url}">

    <fieldset>
        <legend>Supprimer le compte ?</legend>
        <h3 class="warning">
            Êtes-vous sûr de vouloir supprimer le compte «&nbsp;{$compte.id} - {$compte.libelle}&nbsp;» ?

Modified src/www/admin/compta/banques/index.php from [ebe60d3b59] to [eb4af51836].

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
<?php
namespace Garradin;

require_once __DIR__ . '/../_inc.php';

$banques = new Compta\Comptes_Bancaires;
$journal = new Compta\Journal;

$error = false;

if (Utils::post('add'))
{
	$session->requireAccess('compta', Membres::DROIT_ADMIN);

    if (!Utils::CSRF_check('compta_ajout_banque'))
    {
        $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
    }
    else
    {
        try
        {
            $id = $banques->add([
                'libelle'       =>  Utils::post('libelle'),
                'banque'        =>  Utils::post('banque'),
                'iban'          =>  Utils::post('iban'),
                'bic'           =>  Utils::post('bic'),
            ]);

            if (Utils::post('solde') > 0)
            {
            	$exercices = new Compta\Exercices;
            	$exercice = $exercices->getCurrent();
            	$solde = Utils::post('solde');

            	$journal->add([
                    'libelle'       =>  'Solde initial',
                    'montant'       =>  abs($solde),
                    'date'          =>  gmdate('Y-m-d', $exercice->debut),
                    'compte_credit' =>  $solde > 0 ? null : $id,
                    'compte_debit'  =>  $solde < 0 ? null : $id,
                    'numero_piece'  =>  null,
                    'remarques'     =>  'Opération automatique à l\'ajout du compte dans la liste des comptes bancaires',
                    'id_auteur'     =>  $user->id,
                ]);
            }

            Utils::redirect('/admin/compta/banques/');
        }
        catch (UserException $e)
        {
            $error = $e->getMessage();
        }
	}
}

$liste = $banques->getList();

foreach ($liste as &$banque)
{
    $banque->solde = $journal->getSolde($banque->id);
}

$tpl->assign('liste', $liste);

function tpl_format_iban($iban)
{
    return implode(' ', str_split($iban, 4));
}

$tpl->register_modifier('format_iban', 'Garradin\tpl_format_iban');
$tpl->assign('error', $error);

$tpl->display('admin/compta/banques/index.tpl');








<
|
<



<
<
<
<
<
<
|
|
|
|
|
|
|
|

|
|
|
|
|

|
|
|
|
|
|
|
|
|
|
|

|
|
|
|
|
|
<











|
<

|

<
<
<

1
2
3
4
5
6
7
8

9

10
11
12






13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45

46
47
48
49
50
51
52
53
54
55
56
57

58
59
60



61
<?php
namespace Garradin;

require_once __DIR__ . '/../_inc.php';

$banques = new Compta\Comptes_Bancaires;
$journal = new Compta\Journal;


if (f('add') && $form->check('compta_ajout_banque'))

{
	$session->requireAccess('compta', Membres::DROIT_ADMIN);







    try
    {
        $id = $banques->add([
            'libelle' => f('libelle'),
            'banque'  => f('banque'),
            'iban'    => f('iban'),
            'bic'     => f('bic'),
        ]);

        if (f('solde') > 0)
        {
        	$exercices = new Compta\Exercices;
        	$exercice = $exercices->getCurrent();
        	$solde = f('solde');

        	$journal->add([
                'libelle'       =>  'Solde initial',
                'montant'       =>  abs($solde),
                'date'          =>  gmdate('Y-m-d', $exercice->debut),
                'compte_credit' =>  $solde > 0 ? null : $id,
                'compte_debit'  =>  $solde < 0 ? null : $id,
                'numero_piece'  =>  null,
                'remarques'     =>  'Opération automatique à l\'ajout du compte dans la liste des comptes bancaires',
                'id_auteur'     =>  $user->id,
            ]);
        }

        Utils::redirect('/admin/compta/banques/');
    }
    catch (UserException $e)
    {
        $form->addError($e->getMessage());
    }

}

$liste = $banques->getList();

foreach ($liste as &$banque)
{
    $banque->solde = $journal->getSolde($banque->id);
}

$tpl->assign('liste', $liste);

$tpl->register_modifier('format_iban', function ($iban) {

    return implode(' ', str_split($iban, 4));
});




$tpl->display('admin/compta/banques/index.tpl');

Modified src/www/admin/compta/banques/modifier.php from [b80a5da1e9] to [9a9183f85e].

10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
$compte = $banque->get(qg('id'));

if (!$compte)
{
    throw new UserException('Le compte demandé n\'existe pas.');
}

$error = false;

if (!empty($_POST['save']))
{
    if (!Utils::CSRF_check('compta_edit_banque_'.$compte['id']))
    {
        $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
    }
    else
    {
        try
        {
            $id = $banque->edit($compte['id'], [
                'libelle'       =>  Utils::post('libelle'),
                'banque'        =>  Utils::post('banque'),
                'iban'          =>  Utils::post('iban'),
                'bic'           =>  Utils::post('bic'),
            ]);

            Utils::redirect('/admin/compta/banques/');
        }
        catch (UserException $e)
        {
            $error = $e->getMessage();
        }
    }
}

$tpl->assign('error', $error);

$tpl->assign('compte', $compte);

$tpl->display('admin/compta/banques/modifier.tpl');







<
<
<
<
|
|
<
<
<
<
|
|
|
|
|
|
|
|

|
|
|
|
|
|
|
|
<
<
<



10
11
12
13
14
15
16




17
18




19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35



36
37
38
$compte = $banque->get(qg('id'));

if (!$compte)
{
    throw new UserException('Le compte demandé n\'existe pas.');
}





if (f('save') && $form->check('compta_edit_banque_' . $compte->id))
{




    try
    {
        $id = $banque->edit($compte->id, [
            'libelle' => f('libelle'),
            'banque'  => f('banque'),
            'iban'    => f('iban'),
            'bic'     =>  f('bic'),
        ]);

        Utils::redirect('/admin/compta/banques/');
    }
    catch (UserException $e)
    {
        $form->addError($e->getMessage());
    }
}




$tpl->assign('compte', $compte);

$tpl->display('admin/compta/banques/modifier.tpl');

Modified src/www/admin/compta/banques/rapprocher.php from [697914e32f] to [143cff1a1c].

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
$compte = $banques->get(qg('id'));

if (!$compte)
{
    throw new UserException("Le compte demandé n'existe pas.");
}

$error = false;

$solde_initial = $solde_final = 0;

$debut = qg('debut');
$fin = qg('fin');

if ($debut && $fin)
{
    if (!Utils::checkDate($debut) || !Utils::checkDate($fin))
    {
        $error = 'La date donnée est invalide.';
        $debut = $fin = false;
    }
    else if (strtotime($debut) < $exercice['debut'])
    {
        $debut = date('Y-m-d', $exercice['debut']);
    }
    else if (strtotime($fin) > $exercice['fin'])
    {
        $fin = date('Y-m-d', $exercice['fin']);
    }
}

if (!$debut || !$fin)
{
    $date = $exercice['fin'];
    $debut = date('Y-m-01', $date);
    $fin = date('Y-m-t', $date);
}

$journal = $rapprochement->getJournal($compte['id'], $debut, $fin, $solde_initial, $solde_final);

// Enregistrement des cases cochées
if (Utils::post('save'))
{
    if (!Utils::CSRF_check('compta_rapprocher_' . $compte['id']))
    {
        $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
    }
    else
    {
        try
        {
            $rapprochement->record($compte['id'], $journal, Utils::post('rapprocher'), $user['id']);
            Utils::redirect(Utils::getSelfURL());
        }
        catch (UserException $e)
        {
            $error = $e->getMessage();
        }
	}
}

if (substr($debut, 0, 7) == substr($fin, 0, 7))
{
    $tpl->assign('prev', Utils::modifyDate($debut, '-1 month', true));
    $tpl->assign('next', Utils::modifyDate($fin, '+1 month', true));
}

$tpl->assign('compte', $compte);
$tpl->assign('debut', $debut);
$tpl->assign('fin', $fin);

$tpl->assign('journal', $journal);

$tpl->assign('solde_initial', $solde_initial);
$tpl->assign('solde_final', $solde_final);

$tpl->assign('error', $error);

$tpl->display('admin/compta/banques/rapprocher.tpl');







<
<









|


|

|

|

|





|




|


<
<
|
|
<
<
<
<
|
|
|
|
|
|
|
|
|
<

















<
<

13
14
15
16
17
18
19


20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51


52
53




54
55
56
57
58
59
60
61
62

63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79


80
$compte = $banques->get(qg('id'));

if (!$compte)
{
    throw new UserException("Le compte demandé n'existe pas.");
}



$solde_initial = $solde_final = 0;

$debut = qg('debut');
$fin = qg('fin');

if ($debut && $fin)
{
    if (!Utils::checkDate($debut) || !Utils::checkDate($fin))
    {
        $form->addError('La date donnée est invalide.');
        $debut = $fin = false;
    }
    else if (strtotime($debut) < $exercice->debut)
    {
        $debut = date('Y-m-d', $exercice->debut);
    }
    else if (strtotime($fin) > $exercice->fin)
    {
        $fin = date('Y-m-d', $exercice->fin);
    }
}

if (!$debut || !$fin)
{
    $date = $exercice->fin;
    $debut = date('Y-m-01', $date);
    $fin = date('Y-m-t', $date);
}

$journal = $rapprochement->getJournal($compte->id, $debut, $fin, $solde_initial, $solde_final);

// Enregistrement des cases cochées


if (f('save') && $form->check('compta_rapprocher_' . $compte->id))
{




    try
    {
        $rapprochement->record($compte->id, $journal, f('rapprocher'), $user->id);
        Utils::redirect(Utils::getSelfURL());
    }
    catch (UserException $e)
    {
        $form->addError($e->getMessage());
    }

}

if (substr($debut, 0, 7) == substr($fin, 0, 7))
{
    $tpl->assign('prev', Utils::modifyDate($debut, '-1 month', true));
    $tpl->assign('next', Utils::modifyDate($fin, '+1 month', true));
}

$tpl->assign('compte', $compte);
$tpl->assign('debut', $debut);
$tpl->assign('fin', $fin);

$tpl->assign('journal', $journal);

$tpl->assign('solde_initial', $solde_initial);
$tpl->assign('solde_final', $solde_final);



$tpl->display('admin/compta/banques/rapprocher.tpl');

Modified src/www/admin/compta/banques/supprimer.php from [7a7915257e] to [c38863ebf9].

1

2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
<?php

namespace Garradin;

require_once __DIR__ . '/../_inc.php';

$session->requireAccess('compta', Membres::DROIT_ADMIN);

$banque = new Compta\Comptes_Bancaires;

$compte = $banque->get(qg('id'));

if (!$compte)
{
    throw new UserException('Le compte demandé n\'existe pas.');
}

$error = false;

if (!empty($_POST['delete']))
{
    if (!Utils::CSRF_check('compta_delete_banque_'.$compte['id']))
    {
        $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
    }
    else
    {
        try
        {
            $banque->delete($compte['id']);
            Utils::redirect('/admin/compta/banques/');
        }
        catch (UserException $e)
        {
            $error = $e->getMessage();
        }
    }
}

$tpl->assign('error', $error);

$tpl->assign('compte', $compte);

$tpl->display('admin/compta/banques/supprimer.tpl');

>












|


<
<
<
<
|
|
<
<
<
<
|
|
|
|
|
|
|
|
|
|
|
<
<
<



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17




18
19




20
21
22
23
24
25
26
27
28
29
30



31
32
33
<?php

namespace Garradin;

require_once __DIR__ . '/../_inc.php';

$session->requireAccess('compta', Membres::DROIT_ADMIN);

$banque = new Compta\Comptes_Bancaires;

$compte = $banque->get(qg('id'));

if (!$compte)
{
	throw new UserException('Le compte demandé n\'existe pas.');
}





if (f('delete') && $form->check('compta_delete_banque_' . $compte->id))
{




	try
	{
		$banque->delete($compte->id);
		Utils::redirect('/admin/compta/banques/');
	}
	catch (UserException $e)
	{
		$form->addError($e->getMessage());
	}
}




$tpl->assign('compte', $compte);

$tpl->display('admin/compta/banques/supprimer.tpl');