Overview
Comment:Déporter l'ajout d'écriture comptable
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: f57802b44838b210d9227297cc0c178355696575
User & Date: bohwaz on 2014-02-06 18:09:23
Other Links: manifest | tags
Context
2014-02-06
18:36
Page de liste des écritures comptables liées à un paiement check-in: 864f64380c user: bohwaz tags: trunk
18:09
Déporter l'ajout d'écriture comptable check-in: f57802b448 user: bohwaz tags: trunk
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
Changes

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

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
...
188
189
190
191
192
193
194


195



196
197



































































198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
...
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
		$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']);

		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;
	        }
		}
................................................................................
	/**
	 * Ajouter une écriture comptable pour un paiemement membre
	 * @param int $id Numéro de la transaction
	 * @param array $data Données
	 */
	public function addOperationCompta($id, $data)
	{






	}




































































	public function get($id)
	{
		$db = DB::getInstance();
		return $db->simpleQuerySingle('SELECT * FROM membres_transactions WHERE id = ?;', true, (int) $id);
	}

	public function listForMember($id)
	{
		$db = DB::getInstance();
		return $db->simpleStatementFetch('SELECT mtr.*, 
				tr.intitule, tr.duree, tr.debut, tr.fin
			FROM membres_transactions AS mtr 
				LEFT JOIN transactions AS tr ON tr.id = mtr.id_transaction
			WHERE mtr.id_membre = ? ORDER BY mtr.date DESC;', \SQLITE3_ASSOC, (int)$id);
	}

	public function listCurrentSubscriptionsForMember($id)
	{
................................................................................
			GROUP BY mtr.id_transaction
			ORDER BY tr.intitule;', \SQLITE3_ASSOC, (int)$id);
	}

	public function isMemberUpToDate($id, $id_transaction)
	{
		$db = DB::getInstance();
		return $db->simpleQuerySingle('
			SELECT
				SUM(mtr.montant) AS total, tr.montant,
				tr.montant - SUM(mtr.montant) AS a_payer, tr.intitule, tr.duree, tr.debut, tr.fin,
				CASE WHEN tr.duree IS NOT NULL THEN date(mtr.date, \'+\'||tr.duree||\' days\')
				WHEN tr.fin IS NOT NULL THEN tr.fin ELSE NULL END AS expiration
			FROM transactions AS tr
				LEFT JOIN membres_transactions AS mtr
				ON (tr.id = mtr.id_transaction AND id_membre = ? 







|







<
<

<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
>
>
|
|
|
|
|
<
<
<
|
>
>
>
|
<
<
<
<
<







 







>
>

>
>
>
|

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









|
|







 







|
<







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
...
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
...
271
272
273
274
275
276
277
278

279
280
281
282
283
284
285
		$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']);

		if ($id_cat)
		{


			try {
























		        $this->addOperationCompta($id, [
		        	'id_categorie'	=>	$id_cat,
		            'libelle'       =>  $data['libelle'],
		            'montant'       =>  $data['montant'],
		            'date'          =>  $data['date'],
		            'moyen_paiement'=>  $data['moyen_paiement'],
		            'numero_cheque' =>  $data['numero_cheque'],



		            'id_auteur'     =>  $data['id_auteur'],
		            'moyen_paiement'=>	$data['moyen_paiement'],
		            'numero_cheque'	=>	$data['numero_cheque'],
		            'banque'		=>	$data['banque'],
		        ]);





	        }
	        catch (\Exception $e)
	        {
	        	$db->exec('ROLLBACK;');
	        	throw $e;
	        }
		}
................................................................................
	/**
	 * Ajouter une écriture comptable pour un paiemement membre
	 * @param int $id Numéro de la transaction
	 * @param array $data Données
	 */
	public function addOperationCompta($id, $data)
	{
		$journal = new 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']);

		if (!isset($data['montant']) || !is_numeric($data['montant']) || (float)$data['montant'] < 0)
		{
			throw new UserException('Le montant doit être un nombre positif et valide.');
		}

		$data['montant'] = (float) $data['montant'];

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

        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->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, $data['id_categorie']);

        $id_operation = $journal->add([
            'libelle'       =>  $data['libelle'],
            'montant'       =>  $data['montant'],
            '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->simpleInsert('membres_transactions_operations', [
        	'id_operation' => $id_operation,
        	'id_membre_transaction' => $id,
        ]);

        return $id_operation;
	}

	/**
	 * Renvoie un paiement membre
	 * @param  integer $id Numéro du paiement
	 * @return array Données du paiement
	 */
	public function get($id)
	{
		$db = DB::getInstance();
		return $db->simpleQuerySingle('SELECT * FROM membres_transactions WHERE id = ?;', true, (int) $id);
	}

	public function listForMember($id)
	{
		$db = DB::getInstance();
		return $db->simpleStatementFetch('SELECT mtr.*, tr.intitule, tr.duree, tr.debut, tr.fin,
				(SELECT COUNT(*) FROM membres_transactions_operations WHERE id_membre_transaction = mtr.id) AS nb_operations
			FROM membres_transactions AS mtr 
				LEFT JOIN transactions AS tr ON tr.id = mtr.id_transaction
			WHERE mtr.id_membre = ? ORDER BY mtr.date DESC;', \SQLITE3_ASSOC, (int)$id);
	}

	public function listCurrentSubscriptionsForMember($id)
	{
................................................................................
			GROUP BY mtr.id_transaction
			ORDER BY tr.intitule;', \SQLITE3_ASSOC, (int)$id);
	}

	public function isMemberUpToDate($id, $id_transaction)
	{
		$db = DB::getInstance();
		return $db->simpleQuerySingle('SELECT

				SUM(mtr.montant) AS total, tr.montant,
				tr.montant - SUM(mtr.montant) AS a_payer, tr.intitule, tr.duree, tr.debut, tr.fin,
				CASE WHEN tr.duree IS NOT NULL THEN date(mtr.date, \'+\'||tr.duree||\' days\')
				WHEN tr.fin IS NOT NULL THEN tr.fin ELSE NULL END AS expiration
			FROM transactions AS tr
				LEFT JOIN membres_transactions AS mtr
				ON (tr.id = mtr.id_transaction AND id_membre = ? 

Modified src/templates/admin/membres/transactions.tpl from [aea94f1339] to [14fa5c2cc6].

62
63
64
65
66
67
68
69
70
71

72
73
74
75
76
77
78
..
85
86
87
88
89
90
91







92
93
94
95
96
97
98
99
100
101
102
103
104
{/if}
</dl>

{if !empty($paiements)}
<table class="list">
    <thead>
        <th>Date</th>
        <td width="40%">Intitulé</td>
        <td>Montant</td>
        <td>Activité ou cotisation liée</td>

        <td class="actions"></td>
    </thead>
    <tbody>
        {foreach from=$paiements item="p"}
            <tr>
                <td>{$p.date|format_sqlite_date_to_french}</td>
                <td>{$p.libelle|escape}</td>
................................................................................
                        {elseif $p.debut}
                            du {$p.debut|format_sqlite_date_to_french} au {$p.fin|format_sqlite_date_to_french}
                        {else}
                            ponctuelle
                        {/if}
                    {else}
                        <em>Aucune</em>







                    {/if}
                </td>
                <td class="actions">
                    <a class="icn" href="{$admin_url}membres/transactions/modifier.php?id={$p.id|escape}" title="Modifier">✎</a>
                    <a class="icn" href="{$admin_url}membres/transactions/supprimer.php?id={$p.id|escape}" title="Supprimer">✘</a>
                </td>
            </tr>
        {/foreach}
    </tbody>
</table>
{/if}

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







|


>







 







>
>
>
>
>
>
>













62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
..
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
{/if}
</dl>

{if !empty($paiements)}
<table class="list">
    <thead>
        <th>Date</th>
        <td>Intitulé</td>
        <td>Montant</td>
        <td>Activité ou cotisation liée</td>
        <td>Écritures liées</td>
        <td class="actions"></td>
    </thead>
    <tbody>
        {foreach from=$paiements item="p"}
            <tr>
                <td>{$p.date|format_sqlite_date_to_french}</td>
                <td>{$p.libelle|escape}</td>
................................................................................
                        {elseif $p.debut}
                            du {$p.debut|format_sqlite_date_to_french} au {$p.fin|format_sqlite_date_to_french}
                        {else}
                            ponctuelle
                        {/if}
                    {else}
                        <em>Aucune</em>
                    {/if}
                </td>
                <td class="num">
                    {if $p.nb_operations > 0}
                    <a href="{$admin_url}membres/transactions/ecritures.php?id={$p.id|escape}">{$p.nb_operations|escape}</a>
                    {else}
                    0
                    {/if}
                </td>
                <td class="actions">
                    <a class="icn" href="{$admin_url}membres/transactions/modifier.php?id={$p.id|escape}" title="Modifier">✎</a>
                    <a class="icn" href="{$admin_url}membres/transactions/supprimer.php?id={$p.id|escape}" title="Supprimer">✘</a>
                </td>
            </tr>
        {/foreach}
    </tbody>
</table>
{/if}

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