Overview
Comment:Ajout / liste des comptes bancaires + vérifs IBAN/BIC et conversion vers RIB
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 12601a6400407a6df592b427cc5dbfbb5fa4b933
User & Date: bohwaz on 2012-07-24 05:46:16
Other Links: manifest | tags
Context
2012-07-24
17:57
ajout saisie simplifiée avec catégories check-in: edd91dda26 user: bohwaz tags: trunk
05:46
Ajout / liste des comptes bancaires + vérifs IBAN/BIC et conversion vers RIB check-in: 12601a6400 user: bohwaz tags: trunk
04:20
  • Mise à jour plan comptable (peaufinage)
  • Possibilité de compléter le plan comptable abrégé pour en faire un plan comptable exhaustif
  • Du coup numérotation possible à la main
  • On met le plan comptable dans la page catégories pour simplifier
check-in: 62c2fe36fd user: bohwaz tags: trunk
Changes

Modified DB_SCHEMA from [bd978d8707] to [f413614f6a].

194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
CREATE TABLE compta_comptes_bancaires
-- Comptes bancaires
(
    id TEXT PRIMARY KEY,

    banque TEXT NOT NULL,

    rib TEXT,
    iban TEXT,
    bic TEXT,

    FOREIGN KEY(id) REFERENCES compta_comptes(id)
);

CREATE TABLE compta_journal







<







194
195
196
197
198
199
200

201
202
203
204
205
206
207
CREATE TABLE compta_comptes_bancaires
-- Comptes bancaires
(
    id TEXT PRIMARY KEY,

    banque TEXT NOT NULL,


    iban TEXT,
    bic TEXT,

    FOREIGN KEY(id) REFERENCES compta_comptes(id)
);

CREATE TABLE compta_journal

Modified include/class.compta_comptes_bancaires.php from [20d2e75506] to [2cd63c2373].

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
<?php

require_once GARRADIN_ROOT . '/include/class.compta_comptes.php';

class Garradin_Compta_Comptes_Bancaires extends Garradin_Compta_Comptes
{
    const NUMERO_PARENT_COMPTES = 512;

    public function add($data)
    {
        $db = Garradin_DB::getInstance();

        $data['parent'] = self::NUMERO_PARENT_COMPTES;
        $data['id'] = false;

        $new_id = parent::add($data);

        $db = Garradin_DB::getInstance();
        $db->simpleInsert('compta_comptes_bancaires', array(
            'id'        =>  $new_id,
            'banque'    =>  $data['banque'],
            'rib'       =>  $data['rib'],
            'iban'      =>  $data['iban'],
            'bic'       =>  $data['bic'],
        ));

        return $new_id;
    }














|







<







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
<?php

require_once GARRADIN_ROOT . '/include/class.compta_comptes.php';

class Garradin_Compta_Comptes_Bancaires extends Garradin_Compta_Comptes
{
    const NUMERO_PARENT_COMPTES = 512;

    public function add($data)
    {
        $db = Garradin_DB::getInstance();

        $data['parent'] = self::NUMERO_PARENT_COMPTES;
        $data['id'] = null;

        $new_id = parent::add($data);

        $db = Garradin_DB::getInstance();
        $db->simpleInsert('compta_comptes_bancaires', array(
            'id'        =>  $new_id,
            'banque'    =>  $data['banque'],

            'iban'      =>  $data['iban'],
            'bic'       =>  $data['bic'],
        ));

        return $new_id;
    }

41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
        if (!$result)
        {
            return $result;
        }

        $db->simpleUpdate('compta_comptes_bancaires', array(
            'banque'    =>  $data['banque'],
            'rib'       =>  $data['rib'],
            'iban'      =>  $data['iban'],
            'bic'       =>  $data['bic'],
        ), 'id = \''.$db->escapeString(trim($id)).'\'');

        return true;
    }








<







40
41
42
43
44
45
46

47
48
49
50
51
52
53
        if (!$result)
        {
            return $result;
        }

        $db->simpleUpdate('compta_comptes_bancaires', array(
            'banque'    =>  $data['banque'],

            'iban'      =>  $data['iban'],
            'bic'       =>  $data['bic'],
        ), 'id = \''.$db->escapeString(trim($id)).'\'');

        return true;
    }

68
69
70
71
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


102
103
104
105
106
107
108
109
        $db = Garradin_DB::getInstance();
        return $db->simpleQuerySingle('SELECT * FROM compta_comptes AS c
            INNER JOIN compta_comptes_bancaires AS cc
            ON c.id = cc.id
            WHERE c.id = ?;', true, $id);
    }

    public function getList()
    {
        $db = Garradin_DB::getInstance();
        return $db->simpleStatementFetch('SELECT * FROM compta_comptes AS c
            INNER JOIN compta_comptes_bancaires AS cc ON c.id = cc.id
            WHERE c.parent = '.self::NUMERO_PARENT_COMPTES.' ORDER BY c.id;');
    }

    protected function _checkFields(&$data)
    {
        parent::_checkFields($data);

        if (empty($data['banque']) || !trim($data['banque']))
        {
            throw new UserException('Le libellé ne peut rester vide.');
        }









        foreach (array('iban', 'bic', 'rib') as $champ)

        {



            if (!array_key_exists($champ, $data))


                $data[$champ] = '';

            else
            {
                $data[$champ] = trim($data[$champ]);
                $data[$champ] = preg_replace('![^\d]!', ' ', $data[$champ]);
                $data[$champ] = preg_replace('!\s{2,}!', ' ', $data[$champ]);
                $data[$champ] = trim($data[$champ]);


            }
        }

        return true;
    }
}

?>







|







|





|


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








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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
        $db = Garradin_DB::getInstance();
        return $db->simpleQuerySingle('SELECT * FROM compta_comptes AS c
            INNER JOIN compta_comptes_bancaires AS cc
            ON c.id = cc.id
            WHERE c.id = ?;', true, $id);
    }

    public function getList($parent = false)
    {
        $db = Garradin_DB::getInstance();
        return $db->simpleStatementFetch('SELECT * FROM compta_comptes AS c
            INNER JOIN compta_comptes_bancaires AS cc ON c.id = cc.id
            WHERE c.parent = '.self::NUMERO_PARENT_COMPTES.' ORDER BY c.id;');
    }

    protected function _checkFields(&$data, $ignored = null)
    {
        parent::_checkFields($data);

        if (empty($data['banque']) || !trim($data['banque']))
        {
            throw new UserException('Le nom de la banque ne peut rester vide.');
        }

        if (empty($data['bic']))
        {
            $data['bic'] = '';
        }
        else
        {
            $data['bic'] = trim(strtoupper($data['bic']));
            $data['bic'] = preg_replace('![^\dA-Z]!', '', $data['bic']);

            if (!utils::checkBIC($data['bic']))
            {
                throw new UserException('Code BIC/SWIFT invalide.');
            }
        }

        if (empty($data['iban']))
        {
            $data['iban'] = '';
        }
        else
        {
            $data['iban'] = trim(strtoupper($data['iban']));
            $data['iban'] = preg_replace('![^\dA-Z]!', '', $data['iban']);

            if (!utils::checkIBAN($data['iban']))
            {
                throw new UserException('Code IBAN invalide.');
            }
        }

        return true;
    }
}

?>

Modified include/lib.utils.php from [f83ff2f520] to [8f26d20129].

417
418
419
420
421
422
423





424
425



















426

    static public function suggestPassword()
    {
        require_once GARRADIN_ROOT . '/include/libs/passphrase/lib.passphrase.french.php';
        return Passphrase::generate();
    }






}




















?>







>
>
>
>
>
|

>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>

417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450

    static public function suggestPassword()
    {
        require_once GARRADIN_ROOT . '/include/libs/passphrase/lib.passphrase.french.php';
        return Passphrase::generate();
    }

    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 IBAN_RIB($iban)
    {
        if (substr($iban, 0, 2) != 'FR')
        {
            return '';
        }

        return substr($iban, 4, 5) // Code banque
            . ' ' . substr($iban, 4+5, 5) // Code guichet
            . ' ' . substr($iban, 4+5+5, -2) // Numéro de compte
            . ' ' . substr($iban, -2); // Clé RIB
    }

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

?>

Modified templates/admin/_head.tpl from [2e51a9e8d8] to [604dd8c802].

35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
        {if $user.droits.compta >= Garradin_Membres::DROIT_ACCES}
            <li class="compta{if $current == 'compta'} current{/if}"><a href="{$www_url}admin/compta/">Comptabilité</a>
            {if $user.droits.compta >= Garradin_Membres::DROIT_ECRITURE}
            <ul>
                <li class="compta_saisie{if $current == 'compta/saisie'} current{/if}"><a href="{$www_url}admin/compta/saisie.php">Saisie</a></li>
                {if $user.droits.compta >= Garradin_Membres::DROIT_ADMIN}
                <li class="compta_gestion{if $current == 'compta/gestion'} current{/if}"><a href="{$www_url}admin/compta/gestion.php">Suivi des opérations</a></li>
                <li class="compta_banque{if $current == 'compta/banque'} current{/if}"><a href="{$www_url}admin/compta/banque.php">Banques &amp; caisse</a></li>
                <li class="compta_cats{if $current == 'compta/categories'} current{/if}"><a href="{$www_url}admin/compta/categories.php">Catégories &amp; comptes</a></li>
                {/if}
            </ul>
            {/if}
            </li>
        {/if}
        {if $user.droits.wiki >= Garradin_Membres::DROIT_ACCES}







|







35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
        {if $user.droits.compta >= Garradin_Membres::DROIT_ACCES}
            <li class="compta{if $current == 'compta'} current{/if}"><a href="{$www_url}admin/compta/">Comptabilité</a>
            {if $user.droits.compta >= Garradin_Membres::DROIT_ECRITURE}
            <ul>
                <li class="compta_saisie{if $current == 'compta/saisie'} current{/if}"><a href="{$www_url}admin/compta/saisie.php">Saisie</a></li>
                {if $user.droits.compta >= Garradin_Membres::DROIT_ADMIN}
                <li class="compta_gestion{if $current == 'compta/gestion'} current{/if}"><a href="{$www_url}admin/compta/gestion.php">Suivi des opérations</a></li>
                <li class="compta_banque{if $current == 'compta/banque'} current{/if}"><a href="{$www_url}admin/compta/banques.php">Banques &amp; caisse</a></li>
                <li class="compta_cats{if $current == 'compta/categories'} current{/if}"><a href="{$www_url}admin/compta/categories.php">Catégories &amp; comptes</a></li>
                {/if}
            </ul>
            {/if}
            </li>
        {/if}
        {if $user.droits.wiki >= Garradin_Membres::DROIT_ACCES}

Added templates/admin/compta/banque_ajouter.tpl version [61aef76692].

































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
{include file="admin/_head.tpl" title="Ajouter un compte" current="compta/categories"}

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

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

    <fieldset>
        <legend>Ajouter un compte bancaire</legend>
        <dl>
            <dt><label for="f_libelle">Libellé</label> <b title="(Champ obligatoire)">obligatoire</b></dt>
            <dd><input type="text" name="libelle" id="f_libelle" value="{form_field name=libelle}" /></dd>
            <dt><label for="f_banque">Nom de la banque</label> <b title="(Champ obligatoire)">obligatoire</b></dt>
            <dd><input type="text" name="banque" id="f_banque" value="{form_field name=banque}" /></dd>
            <dt><label for="f_bic">Code BIC/SWIFT de la banque</label></dt>
            <dd><input type="text" size="10" name="bic" id="f_bic" value="{form_field name=bic}" /></dd>
            <dt><label for="f_iban">Numéro IBAN</label></dt>
            <dd><input type="text" size="10" name="iban" id="f_iban" value="{form_field name=iban}" /></dd>
        </dl>
    </fieldset>

    <p class="submit">
        {csrf_field key="compta_ajout_banque"}
        <input type="submit" name="add" value="Enregistrer &rarr;" />
    </p>

</form>

{include file="admin/_foot.tpl"}

Added templates/admin/compta/banques.tpl version [d268d3353e].



















































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
{include file="admin/_head.tpl" title="Comptes bancaires" current="compta/banques"}

<ul class="actions">
    <li class="current"><a href="{$www_url}admin/compta/banques.php">Comptes bancaires</a></li>
    <li><a href="{$www_url}admin/compta/caisse.php">Caisse</a></li>
    <li><strong><a href="{$www_url}admin/compta/banque_ajouter.php">Ajouter un compte bancaires</a></strong></li>
</ul>

    {if !empty($liste)}
        <dl class="catList">
        {foreach from=$liste item="compte"}
            <dt>{$compte.libelle|escape}</dt>
            <dd class="actions">
                <a href="{$www_url}admin/compta/banque_modifier.php?id={$compte.id|escape}">Modifier</a>
                | <a href="{$www_url}admin/compta/banque_supprimer.php?id={$compte.id|escape}">Supprimer</a>
            </dd>
        {/foreach}
        </dl>
    {else}
        <p class="alert">
            Aucun compte bancaire trouvé.
        </p>
    {/if}

{include file="admin/_foot.tpl"}

Added www/admin/compta/banque_ajouter.php version [4696d58f5a].



























































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
<?php

require_once __DIR__ . '/_inc.php';

if ($user['droits']['compta'] < Garradin_Membres::DROIT_ADMIN)
{
    throw new UserException("Vous n'avez pas le droit d'accéder à cette page.");
}

require_once GARRADIN_ROOT . '/include/class.compta_comptes_bancaires.php';
$banque = new Garradin_Compta_Comptes_Bancaires;

$error = false;

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

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

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

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

?>

Added www/admin/compta/banques.php version [95c4b33651].



































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

require_once __DIR__ . '/_inc.php';

if ($user['droits']['compta'] < Garradin_Membres::DROIT_ADMIN)
{
    throw new UserException("Vous n'avez pas le droit d'accéder à cette page.");
}

require_once GARRADIN_ROOT . '/include/class.compta_comptes_bancaires.php';
$banque = new Garradin_Compta_Comptes_Bancaires;

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

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

?>