Overview
Comment:Création des écritures comptables liées à l'enregistrement d'un paiement
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: 2dfd20ead779c4d8b8f83effe9ab49d159834fd2
User & Date: bohwaz on 2014-02-06 17:39:24
Other Links: manifest | tags
Context
2014-02-06
17:40
Utilisation de global.js pour détecter les fallback de input type=date plutôt que d'inclure directement datepickr check-in: ba9341763c user: bohwaz tags: trunk
17:39
Création des écritures comptables liées à l'enregistrement d'un paiement check-in: 2dfd20ead7 user: bohwaz tags: trunk
17:38
détection de fallback plus simple et rapide et fonctionnant avec chrome, pour input type="date" check-in: 8e270b999e user: bohwaz tags: trunk
Changes

Modified src/include/class.membres_transactions.php from [c1c0b2f33f] to [a28a264d2d].

65
66
67
68
69
70
71


72








73
74


75






















































76
77
78
79
80
81
82
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
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
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146







+
+
-
+
+
+
+
+
+
+
+


+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







		$this->_checkFields($data);

		if (empty($data['id_membre']))
		{
			throw new UserException('Membre inconnu ou invalide.');
		}

		$db->exec('BEGIN;');

		$db->simpleInsert('membres_transactions', $data);
		$db->simpleInsert('membres_transactions', [
			'date'				=>	$data['date'],
			'id_transaction'	=>	$data['id_transaction'],
			'montant'			=>	$data['montant'],
			'libelle'			=>	$data['libelle'],
			'id_membre'			=>	$data['id_membre'],
			]);
		
		$id = $db->lastInsertRowId();

		$id_cat = $db->simpleQuerySingle('SELECT id_categorie_compta FROM transactions WHERE id = ?;', 
			false, (int)$data['id_transaction']);
		// FIXME création écriture comptable

		if ($id_cat)
		{
			$journal = new Compta_Journal;

			try {
              	if ($data['moyen_paiement'] != 'ES')
                {
                    if (trim($data['banque']) == '')
                    {
                        throw new UserException('Le compte bancaire choisi est invalide.');
                    }

                    if (!$db->simpleQuerySingle('SELECT 1 FROM compta_comptes_bancaires WHERE id = ?;',
                    	false, $data['banque']))
                    {
                        throw new UserException('Le compte bancaire choisi n\'existe pas.');
                    }

                    $debit = $data['banque'];
                }
                else
                {
                	$debit = Compta_Comptes::CAISSE;
                }

                $credit = $db->simpleQuerySingle('SELECT compte FROM compta_categories WHERE id = ?;', 
                	false, $id_cat);

	            $id_operation = $journal->add([
	                'libelle'       =>  $data['libelle'],
	                'montant'       =>  $data['montant'],
	                'date'          =>  $data['date'],
	                'moyen_paiement'=>  $data['moyen_paiement'],
	                'numero_cheque' =>  $data['numero_cheque'],
	                'compte_debit'  =>  $debit,
	                'compte_credit' =>  $credit,
	                'id_categorie'  =>  (int)$id_cat,
	                'id_auteur'     =>  $data['id_auteur'],
	            ]);

	            $db->simpleInsert('membres_transactions_operations', [
	            	'id_operation' => $id_operation,
	            	'id_membre_transaction' => $id,
	            ]);
	        }
	        catch (\Exception $e)
	        {
	        	$db->exec('ROLLBACK;');
	        	throw $e;
	        }
		}

		$db->exec('END;');

		return $id;
	}

	/**
	 * Modifier une transaction
	 * @param  integer $id  ID de la transaction à modifier

Modified src/templates/admin/membres/transactions/ajout.tpl from [0270e23c5b] to [3abf379283].

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







-
+















+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+







        <legend>Enregistrer un paiement</legend>
        <dl>
            <dt><label for="f_id_transaction">Cotisation ou activité liée</label></dt>
            <dd>
                <select id="f_id_transaction" name="id_transaction">
                    <option value="0" {form_field name="id_transaction" selected=0}>-- Aucune, paiement non lié</option>
                    {foreach from=$transactions item="tr"}
                    <option value="{$tr.id|escape}" {form_field name="id_transaction" selected=$tr.id default=$default_tr}>
                    <option value="{$tr.id|escape}" {form_field name="id_transaction" selected=$tr.id default=$default_tr} data-compta="{$tr.id_categorie_compta|escape}">
                        {$tr.intitule|escape}
                        — {$tr.montant|html_money} {$config.monnaie|escape}
                        — {if $tr.duree}pour {$tr.duree|escape} jours
                        {elseif $tr.debut}
                            du {$tr.debut|format_sqlite_date_to_french} au {$tr.fin|format_sqlite_date_to_french}
                        {else}
                            ponctuelle
                        {/if}
                    </option>
                    {/foreach}
                </select>
            </dd>
            <dd class="help">
                Un paiement non relié à une activité ou cotisation peut être
                par exemple un don ponctuel.
            </dd>
            <dt class="f_compta"><label for="f_moyen_paiement">Moyen de paiement</label> <b title="(Champ obligatoire)">obligatoire</b></dt>
            <dd class="f_compta">
                <select name="moyen_paiement" id="f_moyen_paiement">
                {foreach from=$moyens_paiement item="moyen"}
                    <option value="{$moyen.code|escape}"{if $moyen.code == $moyen_paiement} selected="selected"{/if}>{$moyen.nom|escape}</option>
                {/foreach}
                </select>
            </dd>
            <dt class="f_cheque"><label for="f_numero_cheque">Numéro de chèque</label></dt>
            <dd class="f_cheque"><input type="text" name="numero_cheque" id="f_numero_cheque" value="{form_field name=numero_cheque}" /></dd>
            <dt class="f_banque"><label for="f_banque">Compte bancaire</label> <b title="(Champ obligatoire)">obligatoire</b></dt>
            <dd class="f_banque">
                <select name="banque" id="f_banque">
                {foreach from=$comptes_bancaires item="compte"}
                    <option value="{$compte.id|escape}"{if $compte.id == $banque} selected="selected"{/if}>{$compte.libelle|escape} - {$compte.banque|escape}</option>
                {/foreach}
                </select>
            </dd>
            <dt><label for="f_montant">Montant</label></dt>
            <dd><input type="number" size="5" name="montant" id="f_montant" value="{form_field name=montant default=$default_amount}" min="0.00" step="0.01" /> {$config.monnaie|escape}</dd>
            <dt><label for="f_libelle">Libellé</label></dt>
            <dd><input type="text" name="libelle" id="f_libelle" value="{form_field name=libelle}" /></dd>
            <dt><label for="f_date">Date</label></dt>
            <dd><input type="date" name="date" id="f_date" value="{form_field name=date}" /></dd>
70
71
72
73
74
75
76




77



























78
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
125
126







+
+
+
+
-
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+

    <p class="submit">
        {csrf_field key="add_transaction"}
        {if $membre}<input type="hidden" name="id_membre" value="{$membre.id|escape}" />{/if}
        <input type="submit" name="add" value="Enregistrer ce paiement &rarr;" />
    </p>
</form>

<script type="text/javascript">
{literal}
(function () {
    window.changeMoyenPaiement = function()

    {
        var elm = $('#f_moyen_paiement');
        toggleElementVisibility('.f_cheque', elm.value == 'CH');
        toggleElementVisibility('.f_banque', elm.value != 'ES');
    };

    changeMoyenPaiement();
    toggleElementVisibility('.f_compta', false);

    $('#f_moyen_paiement').onchange = changeMoyenPaiement;

    $('#f_id_transaction').onchange = function () {
        if (this.options[this.selectedIndex].getAttribute('data-compta'))
        {
            toggleElementVisibility('.f_compta', true);
            changeMoyenPaiement();
        }
        else
        {
            toggleElementVisibility('.f_compta', false);
            changeMoyenPaiement();
        }
    };
} ());
{/literal}
</script>

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

Modified src/www/admin/membres/transactions/ajout.php from [e2c59b063f] to [1d8a763b77].

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







+
+
+











-
+





+
-
+
+
+
+
+
+
+
+
+
+

















+
+
+
+
+
+







        throw new UserException("Ce membre n'existe pas.");
    }
}

$transactions = new Transactions;
$m_transactions = new Membres_Transactions;

$cats = new Compta_Categories;
$banques = new Compta_Comptes_Bancaires;

$error = false;

if (!empty($_POST['add']))
{
    if (!utils::CSRF_check('add_transaction'))
    {
        $error = 'Une erreur est survenue, merci de renvoyer le formulaire.';
    }
    else
    {
        try {
            $m_transactions->add(array(
            $data = [
                'libelle'           =>  utils::post('libelle'),
                'date'              =>  utils::post('date'),
                'id_transaction'    =>  utils::post('id_transaction'),
                'montant'           =>  (float) utils::post('montant'),
                'id_membre'         =>  utils::post('id_membre'),
            ];
            ));

            if (!empty($data['id_transaction']))
            {
                $data['id_auteur'] = $user['id'];
                $data['moyen_paiement'] = utils::post('moyen_paiement');
                $data['numero_cheque'] = utils::post('numero_cheque');
                $data['banque'] = utils::post('banque');
            }

            $m_transactions->add($data);

            utils::redirect('/admin/membres/transactions.php?id=' . (int)utils::post('id_membre'));
        }
        catch (UserException $e)
        {
            $error = $e->getMessage();
        }
    }
}

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

$tpl->assign('transactions', $transactions->listCurrent());

$tpl->assign('default_tr', null);
$tpl->assign('default_amount', 0.00);

$tpl->assign('moyens_paiement', $cats->listMoyensPaiement());
$tpl->assign('moyen_paiement', utils::post('moyen_paiement') ?: 'ES');
$tpl->assign('comptes_bancaires', $banques->getList());
$tpl->assign('banque', utils::post('banque'));


if ($membre)
{
    $cats = new Membres_Categories;
    $categorie = $cats->get($membre['id_categorie']);

    if (!empty($categorie['id_transaction_obligatoire']))