Overview
Comment:Ajout numéro pièce comptable et remarques dans le formulaire d'enregistrement d'une cotisation
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: f6fc2d8cbda936ab9c9ad6474b5dd2adef0e31ce
User & Date: bohwaz on 2017-09-01 07:30:40
Other Links: branch diff | manifest | tags
Context
2017-09-03
00:17
Ne pas prendre en compte LOCAL_LOGIN s'il est positionné sur false/null/0 check-in: 2b5e5aed0c user: bohwaz tags: dev
2017-09-01
07:30
Ajout numéro pièce comptable et remarques dans le formulaire d'enregistrement d'une cotisation check-in: f6fc2d8cbd user: bohwaz tags: dev
03:44
Refonte formulaire saisie compta pour pouvoir changer d'un type à l'autre sans recharger la page (et donc vider les champs) check-in: 563749cf65 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Membres/Cotisations.php from [e3d6aba6dc] to [96cbb779cb].

13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
	const ITEMS_PER_PAGE = 100;

	/**
	 * Vérification des champs fournis pour la modification de donnée
	 * @param  array $data Tableau contenant les champs à ajouter/modifier
	 * @return void
	 */
	protected function _checkFields(&$data, $compta = false)
	{
		$db = DB::getInstance();

        if (empty($data['date']) || !Utils::checkDate($data['date']))
        {
            throw new UserException('Date vide ou invalide.');
        }







|







13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
	const ITEMS_PER_PAGE = 100;

	/**
	 * Vérification des champs fournis pour la modification de donnée
	 * @param  array $data Tableau contenant les champs à ajouter/modifier
	 * @return void
	 */
	protected function _checkFields(&$data)
	{
		$db = DB::getInstance();

        if (empty($data['date']) || !Utils::checkDate($data['date']))
        {
            throw new UserException('Date vide ou invalide.');
        }
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
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
		if (empty($data['id_membre']) 
			|| !$db->firstColumn('SELECT 1 FROM membres WHERE id = ?;', (int) $data['id_membre']))
		{
			throw new UserException('Membre inconnu ou invalide.');
		}

		$data['id_membre'] = (int) $data['id_membre'];

		if ($compta)
		{
	        if (!isset($data['moyen_paiement']) || trim($data['moyen_paiement']) === '')
	        {
	        	throw new UserException('Moyen de paiement inconnu ou invalide.');
	        }

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

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

	        if (!isset($data['montant']) || !is_numeric($data['montant']) || $data['montant'] < 0)
	        {
	        	throw new UserException('Le montant indiqué n\'est pas un nombre valide : doit être supérieur ou égal à zéro.');
	        }
	    }
	}

	/**
	 * Enregistrer un événement de cotisation
	 * @param array $data Tableau des champs à insérer
	 * @return integer ID de l'événement créé
	 */
	public function add($data)
	{
		$db = DB::getInstance();

		$co = $db->first('SELECT * FROM cotisations WHERE id = ?;', (int)$data['id_cotisation']);

		$this->_checkFields($data, !empty($co->id_categorie_compta));

		$check = $db->firstColumn('SELECT 1 FROM cotisations_membres 
			WHERE id_cotisation = ? AND id_membre = ? AND date = ?;', 
			(int)$data['id_cotisation'], (int)$data['id_membre'], $data['date']);

		if ($check)
		{
			throw new UserException('Cette cotisation a déjà été enregistrée pour ce jour-ci et ce membre-ci.');
		}

		$db->begin();

		$db->insert('cotisations_membres', [
			'date'				=>	$data['date'],
			'id_cotisation'		=>	$data['id_cotisation'],
			'id_membre'			=>	$data['id_membre'],
			]);

		$id = $db->lastInsertRowId();

		if ($co->id_categorie_compta && $data['montant'] > 0)
		{
			try {
		        $id_operation = $this->addOperationCompta($id, [
		        	'id_categorie'	=>	$co->id_categorie_compta,
		            'libelle'       =>  'Cotisation (automatique)',
		            'montant'       =>  $data['montant'],
		            'date'          =>  $data['date'],
		            'moyen_paiement'=>  $data['moyen_paiement'],
		            'numero_cheque' =>  isset($data['numero_cheque']) ? $data['numero_cheque'] : null,
		            'id_auteur'     =>  $data['id_auteur'],
		            'banque'		=>	isset($data['banque']) ? $data['banque'] : null,
		            'id_membre'		=>	$data['id_membre'],
		        ]);


	        }
	        catch (\Exception $e)
	        {
	        	$db->rollback();
	        	throw $e;
	        }
		}







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<







|





|




















|


|


<

<
<

<


>
>







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
92
93
94
95
96
		if (empty($data['id_membre']) 
			|| !$db->firstColumn('SELECT 1 FROM membres WHERE id = ?;', (int) $data['id_membre']))
		{
			throw new UserException('Membre inconnu ou invalide.');
		}

		$data['id_membre'] = (int) $data['id_membre'];


























	}

	/**
	 * Enregistrer un événement de cotisation
	 * @param array $data Tableau des champs à insérer
	 * @return integer ID de l'événement créé
	 */
	public function add($data, array $data_compta)
	{
		$db = DB::getInstance();

		$co = $db->first('SELECT * FROM cotisations WHERE id = ?;', (int)$data['id_cotisation']);

		$this->_checkFields($data);

		$check = $db->firstColumn('SELECT 1 FROM cotisations_membres 
			WHERE id_cotisation = ? AND id_membre = ? AND date = ?;', 
			(int)$data['id_cotisation'], (int)$data['id_membre'], $data['date']);

		if ($check)
		{
			throw new UserException('Cette cotisation a déjà été enregistrée pour ce jour-ci et ce membre-ci.');
		}

		$db->begin();

		$db->insert('cotisations_membres', [
			'date'				=>	$data['date'],
			'id_cotisation'		=>	$data['id_cotisation'],
			'id_membre'			=>	$data['id_membre'],
			]);

		$id = $db->lastInsertRowId();

		if ($co->id_categorie_compta)
		{
			try {
				$data_compta = array_merge($data_compta, [
		        	'id_categorie'	=>	$co->id_categorie_compta,
		            'libelle'       =>  'Cotisation (automatique)',

		            'date'          =>  $data['date'],


		            'id_auteur'     =>  $data['id_auteur'],

		            'id_membre'		=>	$data['id_membre'],
		        ]);

				$id_operation = $this->addOperationCompta($id, $data_compta);
	        }
	        catch (\Exception $e)
	        {
	        	$db->rollback();
	        	throw $e;
	        }
		}
171
172
173
174
175
176
177























178
179
180
181
182
183
184
	 * @param int $id Numéro de la cotisation membre
	 * @param array $data Données
	 */
	public function addOperationCompta($id, $data)
	{
		$journal = new \Garradin\Compta\Journal;
		$db = DB::getInstance();
























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

		$data['libelle'] = trim($data['libelle']);







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







143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
	 * @param int $id Numéro de la cotisation membre
	 * @param array $data Données
	 */
	public function addOperationCompta($id, $data)
	{
		$journal = new \Garradin\Compta\Journal;
		$db = DB::getInstance();

		if (!isset($data['moyen_paiement']) || trim($data['moyen_paiement']) === '')
		{
			throw new UserException('Moyen de paiement inconnu ou invalide.');
		}

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

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

		if (!isset($data['montant']) || !is_numeric($data['montant']) || $data['montant'] < 0)
		{
			throw new UserException('Le montant indiqué n\'est pas un nombre valide : doit être supérieur ou égal à zéro.');
		}

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

		$data['libelle'] = trim($data['libelle']);
208
209
210
211
212
213
214


215
216
217
218
219
220
221
            'date'          =>  $data['date'],
            'moyen_paiement'=>  $data['moyen_paiement'],
            'numero_cheque' =>  isset($data['numero_cheque']) ? $data['numero_cheque'] : null,
            'compte_debit'  =>  $debit,
            'compte_credit' =>  $credit,
            'id_categorie'  =>  (int)$data['id_categorie'],
            'id_auteur'     =>  (int)$data['id_auteur'],


        ]);

        $db->insert('membres_operations', [
			'id_operation'  => $id_operation,
			'id_membre'     => $data['id_membre'],
			'id_cotisation' => (int)$id,
        ]);







>
>







203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
            'date'          =>  $data['date'],
            'moyen_paiement'=>  $data['moyen_paiement'],
            'numero_cheque' =>  isset($data['numero_cheque']) ? $data['numero_cheque'] : null,
            'compte_debit'  =>  $debit,
            'compte_credit' =>  $credit,
            'id_categorie'  =>  (int)$data['id_categorie'],
            'id_auteur'     =>  (int)$data['id_auteur'],
			'remarques'      => isset($data['remarques']) ? $data['remarques'] : null,
			'numero_piece'   => isset($data['numero_piece']) ? $data['numero_piece'] : null,
        ]);

        $db->insert('membres_operations', [
			'id_operation'  => $id_operation,
			'id_membre'     => $data['id_membre'],
			'id_cotisation' => (int)$id,
        ]);

Modified src/templates/admin/config/membres.tpl from [731fd23cc8] to [166866b141].

119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
    <div id="orderFields">
        {foreach from=$champs item="champ" key="nom"}
        {if $nom == 'passe'}{continue}{/if}
        <fieldset id="f_{$nom}">
            <legend>{$nom}</legend>
            <dl>
                <dt><label>Type</label></dt>
                <dd>{$champ.type|get_type}</dd>
                <dt><label for="f_{$nom}_title">Titre</label> <b title="(Champ obligatoire)">obligatoire</b></dt>
                <dd><input type="text" name="champs[{$nom}][title]" id="f_{$nom}_title" value="{form_field data=$champs->$nom name=title}" size="60" required="required" /></dd>
                <dt><label for="f_{$nom}_help">Aide</label></dt>
                <dd><input type="text" name="champs[{$nom}][help]" id="f_{$nom}_help" value="{form_field data=$champs->$nom name=help}" size="100" /></dd>
                <dt><label><input type="checkbox" name="champs[{$nom}][editable]" value="1" {form_field data=$champs->$nom name=editable checked="1"} /> Modifiable par les membres</label></dt>
                <dd class="help">Si coché, les membres pourront changer cette information depuis leur espace personnel.</dd>
                <dt><label><input type="checkbox" name="champs[{$nom}][mandatory]" value="1" {form_field data=$champs->$nom name=mandatory checked="1"} /> Champ obligatoire</label></dt>







|







119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
    <div id="orderFields">
        {foreach from=$champs item="champ" key="nom"}
        {if $nom == 'passe'}{continue}{/if}
        <fieldset id="f_{$nom}">
            <legend>{$nom}</legend>
            <dl>
                <dt><label>Type</label></dt>
                <dd><input type="hidden" name="champs[{$nom}][type]" value="{$champ.type}" />{$champ.type|get_type}</dd>
                <dt><label for="f_{$nom}_title">Titre</label> <b title="(Champ obligatoire)">obligatoire</b></dt>
                <dd><input type="text" name="champs[{$nom}][title]" id="f_{$nom}_title" value="{form_field data=$champs->$nom name=title}" size="60" required="required" /></dd>
                <dt><label for="f_{$nom}_help">Aide</label></dt>
                <dd><input type="text" name="champs[{$nom}][help]" id="f_{$nom}_help" value="{form_field data=$champs->$nom name=help}" size="100" /></dd>
                <dt><label><input type="checkbox" name="champs[{$nom}][editable]" value="1" {form_field data=$champs->$nom name=editable checked="1"} /> Modifiable par les membres</label></dt>
                <dd class="help">Si coché, les membres pourront changer cette information depuis leur espace personnel.</dd>
                <dt><label><input type="checkbox" name="champs[{$nom}][mandatory]" value="1" {form_field data=$champs->$nom name=mandatory checked="1"} /> Champ obligatoire</label></dt>

Modified src/templates/admin/membres/cotisations/ajout.tpl from [aaf9e77610] to [be4a739974].

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
                        {else}
                            ponctuelle
                        {/if}
                    </option>
                    {/foreach}
                </select>
            </dd>






            <dt class="f_compta"><label for="f_montant">Montant</label> <b title="(Champ obligatoire)">obligatoire</b></dt>
            <dd class="f_compta"><input type="number" name="montant" step="0.01" min="0.00" id="f_montant" value="{form_field name=montant default=$default_amount}" /></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}"{if $moyen.code == $moyen_paiement} selected="selected"{/if}>{$moyen.nom}</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}"{if $compte.id == $banque} selected="selected"{/if}>{$compte.libelle} - {$compte.banque}</option>
                {/foreach}
                </select>
            </dd>
            <dt><label for="f_date">Date</label> <b title="(Champ obligatoire)">obligatoire</b></dt>
            <dd><input type="date" name="date" id="f_date" value="{form_field name=date default=$default_date}" required="required" /></dd>
            {if !$membre}
            <dt><label for="f_numero_membre">Numéro de membre</label> <b title="(Champ obligatoire)">obligatoire</b></dt>
            <dd><input type="number" name="numero_membre" id="f_numero_membre" value="{form_field name=numero_membre}" step="1" min="1" required="required" /></dd>
            {/if}
        </dl>
    </fieldset>

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







>
>
>
>
>
>




















|
|
<
|
|
<







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
                        {else}
                            ponctuelle
                        {/if}
                    </option>
                    {/foreach}
                </select>
            </dd>
            <dt><label for="f_date">Date</label> <b title="(Champ obligatoire)">obligatoire</b></dt>
            <dd><input type="date" name="date" id="f_date" value="{form_field name=date default=$default_date}" required="required" /></dd>
            {if !$membre}
            <dt><label for="f_numero_membre">Numéro de membre</label> <b title="(Champ obligatoire)">obligatoire</b></dt>
            <dd><input type="number" name="numero_membre" id="f_numero_membre" value="{form_field name=numero_membre}" step="1" min="1" required="required" /></dd>
            {/if}
            <dt class="f_compta"><label for="f_montant">Montant</label> <b title="(Champ obligatoire)">obligatoire</b></dt>
            <dd class="f_compta"><input type="number" name="montant" step="0.01" min="0.00" id="f_montant" value="{form_field name=montant default=$default_amount}" /></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}"{if $moyen.code == $moyen_paiement} selected="selected"{/if}>{$moyen.nom}</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}"{if $compte.id == $banque} selected="selected"{/if}>{$compte.libelle} - {$compte.banque}</option>
                {/foreach}
                </select>
            </dd>
            <dt class="f_compta"><label for="f_numero_piece">Numéro de pièce comptable</label></dt>
            <dd class="f_compta"><input type="text" name="numero_piece" id="f_numero_piece" value="{form_field name=numero_piece}" /></dd>

            <dt class="f_compta"><label for="f_remarques">Remarques</label></dt>
            <dd class="f_compta"><textarea name="remarques" id="f_remarques" rows="4" cols="30">{form_field name=remarques}</textarea></dd>

        </dl>
    </fieldset>

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

Modified src/www/admin/membres/cotisations/ajout.php from [c2c1d14ae5] to [f07e5f3c25].

49
50
51
52
53
54
55



56
57
58
59


60
61
62
63
64
65
66
67
68
69
            }

            $data = [
                'date'           =>  f('date'),
                'id_cotisation'  =>  f('id_cotisation'),
                'id_membre'      =>  $id_membre,
                'id_auteur'      =>  $user->id,



                'montant'        =>  f('montant'),
                'moyen_paiement' =>  f('moyen_paiement'),
                'numero_cheque'  =>  f('numero_cheque'),
                'banque'         =>  f('banque'),


            ];

            $m_cotisations->add($data);

            Utils::redirect('/admin/membres/cotisations.php?id=' . $id_membre);
        }
        catch (UserException $e)
        {
            $form->addError($e->getMessage());
        }







>
>
>




>
>


|







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
            }

            $data = [
                'date'           =>  f('date'),
                'id_cotisation'  =>  f('id_cotisation'),
                'id_membre'      =>  $id_membre,
                'id_auteur'      =>  $user->id,
            ];

            $compta = [
                'montant'        =>  f('montant'),
                'moyen_paiement' =>  f('moyen_paiement'),
                'numero_cheque'  =>  f('numero_cheque'),
                'banque'         =>  f('banque'),
                'numero_piece'   =>  f('numero_piece'),
                'remarques'      =>  f('remarques'),
            ];

            $m_cotisations->add($data, $compta);

            Utils::redirect('/admin/membres/cotisations.php?id=' . $id_membre);
        }
        catch (UserException $e)
        {
            $form->addError($e->getMessage());
        }