Overview
Comment:Link users to transactions
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: 1ba94977997fe5deae81b433eb1127a724bd7708
User & Date: bohwaz on 2020-09-29 17:25:13
Other Links: branch diff | manifest | tags
Context
2020-09-29
18:47
Fix small issues on transaction adding check-in: e57d8c495d user: bohwaz tags: dev
17:25
Link users to transactions check-in: 1ba9497799 user: bohwaz tags: dev
17:24
Allow d/m/Y date format check-in: e4d78127c5 user: bohwaz tags: dev
Changes

Modified src/include/data/1.0.0_schema.sql from [442e7113d3] to [74342d58e2].

65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
...
266
267
268
269
270
271
272










273
274
275
276
277
278
279
    id_cotisation INTEGER NOT NULL REFERENCES cotisations (id) ON DELETE CASCADE,

    date TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(date) IS NOT NULL AND date(date) = date)
);

CREATE UNIQUE INDEX IF NOT EXISTS cm_unique ON cotisations_membres (id_membre, id_cotisation, date);

CREATE TABLE IF NOT EXISTS membres_mouvements
-- Liaison des enregistrement des paiements en compta
(
    id_membre INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
    id_transaction INTEGER NOT NULL REFERENCES acc_transactions (id) ON DELETE CASCADE,
    id_cotisation INTEGER NULL REFERENCES cotisations_membres (id) ON DELETE SET NULL,

    PRIMARY KEY (id_membre, id_transaction)
);

CREATE TABLE IF NOT EXISTS rappels
-- Rappels de devoir renouveller une cotisation
(
    id INTEGER NOT NULL PRIMARY KEY,
    id_cotisation INTEGER NOT NULL REFERENCES cotisations (id) ON DELETE CASCADE,

    delai INTEGER NOT NULL, -- Délai en jours pour envoyer le rappel
................................................................................
    id_analytical INTEGER NULL REFERENCES acc_accounts(id) ON DELETE SET NULL,

    CONSTRAINT line_check1 CHECK ((credit * debit) = 0),
    CONSTRAINT line_check2 CHECK ((credit + debit) > 0)
);

CREATE INDEX IF NOT EXISTS acc_transactions_lines_account ON acc_transactions_lines (id_account);











CREATE TABLE IF NOT EXISTS plugins
(
    id TEXT NOT NULL PRIMARY KEY,
    officiel INTEGER NOT NULL DEFAULT 0,
    nom TEXT NOT NULL,
    description TEXT NULL,







<
<
<
<
<
<
<
<
<
<







 







>
>
>
>
>
>
>
>
>
>







65
66
67
68
69
70
71










72
73
74
75
76
77
78
...
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
    id_cotisation INTEGER NOT NULL REFERENCES cotisations (id) ON DELETE CASCADE,

    date TEXT NOT NULL DEFAULT CURRENT_DATE CHECK (date(date) IS NOT NULL AND date(date) = date)
);

CREATE UNIQUE INDEX IF NOT EXISTS cm_unique ON cotisations_membres (id_membre, id_cotisation, date);











CREATE TABLE IF NOT EXISTS rappels
-- Rappels de devoir renouveller une cotisation
(
    id INTEGER NOT NULL PRIMARY KEY,
    id_cotisation INTEGER NOT NULL REFERENCES cotisations (id) ON DELETE CASCADE,

    delai INTEGER NOT NULL, -- Délai en jours pour envoyer le rappel
................................................................................
    id_analytical INTEGER NULL REFERENCES acc_accounts(id) ON DELETE SET NULL,

    CONSTRAINT line_check1 CHECK ((credit * debit) = 0),
    CONSTRAINT line_check2 CHECK ((credit + debit) > 0)
);

CREATE INDEX IF NOT EXISTS acc_transactions_lines_account ON acc_transactions_lines (id_account);

CREATE TABLE IF NOT EXISTS acc_transactions_users
-- Liaison des écritures et des membres
(
    id_user INTEGER NOT NULL REFERENCES membres (id) ON DELETE CASCADE,
    id_transaction INTEGER NOT NULL REFERENCES acc_transactions (id) ON DELETE CASCADE,
    id_service INTEGER NULL REFERENCES cotisations_membres (id) ON DELETE SET NULL,

    PRIMARY KEY (id_user, id_transaction)
);

CREATE TABLE IF NOT EXISTS plugins
(
    id TEXT NOT NULL PRIMARY KEY,
    officiel INTEGER NOT NULL DEFAULT 0,
    nom TEXT NOT NULL,
    description TEXT NULL,

Modified src/include/lib/Garradin/Entities/Accounting/Transaction.php from [162732cfbf] to [057c49d87b].

42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
...
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
...
244
245
246
247
248
249
250
251















		'id_creator' => '?int',
	];

	protected $_form_rules = [
		'label'     => 'required|string|max:200',
		'notes'     => 'string|max:20000',
		'reference' => 'string|max:200',
		'date'      => 'required|date_format:Y-m-d',
	];

	protected $_lines;

	public function getLinesWithAccounts()
	{
		$em = EntityManager::getInstance(Line::class);
................................................................................
			throw new ValidationException('Type d\'écriture inconnu');
		}

		$type = $source['type'];

		$this->importForm();

		$accounts = new Accounts($chart_id);

		if ($type !== 'advanced') {
			$from = $accounts->getIdFromCode($source[$type . '_from']);
			$to = $accounts->getIdFromCode($source[$type . '_to']);
			$amount = $source['amount'];

			$line = new Line;
			$line->importForm([
				'reference'  => $source['payment_reference'],
				'credit' => '0',
				'debit'      => $amount,
				'id_account' => $from,
				'id_analytical' => $source['id_analytical'] ?? null,
			]);
			$this->add($line);

			$line = new Line;
			$line->importForm([
				'reference'  => $source['payment_reference'],
				'credit'     => $amount,
				'debit' => '0',
				'id_account' => $to,
				'id_analytical' => $source['id_analytical'] ?? null,
			]);
			$this->add($line);
		}
		else {
			foreach ($source['lines'] as $i => $line) {
				$line['id_account'] = $accounts->getIdFromCode($line['account']);

				if (!$line['id_account']) {
					throw new ValidationException('Numéro de compte invalide sur la ligne ' . ($i+1));
				}

				$line = (new Line)->import($line);
				$this->add($line);
................................................................................
		return EntityManager::findOneById(Year::class, $this->id_year);
	}

	public function listFiles()
	{
		return Fichiers::listLinkedFiles(Fichiers::LIEN_COMPTA, $this->id());
	}
}






















|







 







<
<

|
|




|
|
|
|






|
|
|
|






|







 







|
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
...
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
...
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
		'id_creator' => '?int',
	];

	protected $_form_rules = [
		'label'     => 'required|string|max:200',
		'notes'     => 'string|max:20000',
		'reference' => 'string|max:200',
		'date'      => 'required|date_format:d/m/Y',
	];

	protected $_lines;

	public function getLinesWithAccounts()
	{
		$em = EntityManager::getInstance(Line::class);
................................................................................
			throw new ValidationException('Type d\'écriture inconnu');
		}

		$type = $source['type'];

		$this->importForm();



		if ($type !== 'advanced') {
			$from = @count($source[$type . '_from']) ? key($source[$type . '_from']) : null;
			$to = @count($source[$type . '_to']) ? key($source[$type . '_to']) : null;
			$amount = $source['amount'];

			$line = new Line;
			$line->importForm([
				'reference'     => $source['payment_reference'],
				'credit'        => '0',
				'debit'         => $amount,
				'id_account'    => $from,
				'id_analytical' => $source['id_analytical'] ?? null,
			]);
			$this->add($line);

			$line = new Line;
			$line->importForm([
				'reference'     => $source['payment_reference'],
				'credit'        => $amount,
				'debit'         => '0',
				'id_account'    => $to,
				'id_analytical' => $source['id_analytical'] ?? null,
			]);
			$this->add($line);
		}
		else {
			foreach ($source['lines'] as $i => $line) {
				$line['id_account'] = @count($line['id_account']) ? key($line['id_account']) : null;

				if (!$line['id_account']) {
					throw new ValidationException('Numéro de compte invalide sur la ligne ' . ($i+1));
				}

				$line = (new Line)->import($line);
				$this->add($line);
................................................................................
		return EntityManager::findOneById(Year::class, $this->id_year);
	}

	public function listFiles()
	{
		return Fichiers::listLinkedFiles(Fichiers::LIEN_COMPTA, $this->id());
	}

	public function linkTo(int $user_id, ?int $contribution_id = null)
	{
		if (!$this->id()) {
			throw new \LogicException('Cannot link a non-saved transaction');
		}

		$db = EntityManager::getInstance(self::class)->DB();

		return $db->insert('acc_transactions_users', [
			'id_transaction' => $this->id(),
			'id_user'        => $user_id,
			'id_service'     => $service_id,
		]);
	}
}

Modified src/templates/acc/accounts/selector.tpl from [4c975a28aa] to [bbba4e74fd].

9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
..
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
			<tbody>
			{foreach from=$accounts item="account"}
				<tr>
					<td>{$account.code}</td>
					<th>{$account.label}</th>
					<td class="desc">{$account.description}</td>
					<td class="actions">
						<button class="icn-btn" value="{$account.code}" data-label="&lt;b&gt;{$account.code}&lt;/b&gt; — {$account.label}" data-icon="&rarr;">Sélectionner</button>
					</td>
				</tr>
			{/foreach}
			</tbody>
		</table>
	{/foreach}

................................................................................
	<table class="accounts">
		<tbody>
		{foreach from=$accounts item="account"}
			<tr class="account-level-{$account.code|strlen}">
				<td>{$account.code}</td>
				<th>{$account.label}</th>
				<td class="actions">
					<button class="icn-btn" value="{$account.code}" data-label="{$account.code}" data-icon="&rarr;">Sélectionner</button>
					}
				</td>
			</tr>
		{/foreach}
		</tbody>
	</table>








|







 







|







9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
..
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
			<tbody>
			{foreach from=$accounts item="account"}
				<tr>
					<td>{$account.code}</td>
					<th>{$account.label}</th>
					<td class="desc">{$account.description}</td>
					<td class="actions">
						<button class="icn-btn" value="{$account.id}" data-label="{$account.code} — {$account.label}" data-icon="&rarr;">Sélectionner</button>
					</td>
				</tr>
			{/foreach}
			</tbody>
		</table>
	{/foreach}

................................................................................
	<table class="accounts">
		<tbody>
		{foreach from=$accounts item="account"}
			<tr class="account-level-{$account.code|strlen}">
				<td>{$account.code}</td>
				<th>{$account.label}</th>
				<td class="actions">
					<button class="icn-btn" value="{$account.id}" data-label="{$account.code}" data-icon="&rarr;">Sélectionner</button>
					}
				</td>
			</tr>
		{/foreach}
		</tbody>
	</table>

Modified src/templates/acc/transactions/new.tpl from [ce2915f3db] to [92c72d5670].

263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
		line.parentNode.appendChild(n);
	};
}

function inputListSelected(value, label) {
	var i = g.current_list_input;
	var multiple = i.firstChild.getAttribute('data-multiple');
	var name = i.getAttribute('data-name');

	var span = document.createElement('span');
	span.className = 'label';
	span.innerHTML = '<input type="hidden" name="' + name + '[' + value + ']" value="' + label + '" />' + label;
	if (parseInt(multiple, 10) == 1) {
		var btn = document.createElement('button');
		btn.className = 'icn-btn';







|







263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
		line.parentNode.appendChild(n);
	};
}

function inputListSelected(value, label) {
	var i = g.current_list_input;
	var multiple = i.firstChild.getAttribute('data-multiple');
	var name = i.firstChild.getAttribute('data-name');

	var span = document.createElement('span');
	span.className = 'label';
	span.innerHTML = '<input type="hidden" name="' + name + '[' + value + ']" value="' + label + '" />' + label;
	if (parseInt(multiple, 10) == 1) {
		var btn = document.createElement('button');
		btn.className = 'icn-btn';

Modified src/www/admin/acc/transactions/new.php from [4f163a9108] to [d477ceee4e].

50
51
52
53
54
55
56







57
58
59
60
61
62
63
        $transaction->save();

        // Append file
        if (!empty($_FILES['file']['name'])) {
            $file = Fichiers::upload($_FILES['file']);
            $file->linkTo(Fichiers::LIEN_COMPTA, $transaction->id());
        }








        Utils::redirect(Utils::getSelfURL(false) . '?ok=' . $transaction->id());
    }
    catch (UserException $e) {
        $form->addError($e->getMessage());
    }
}







>
>
>
>
>
>
>







50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
        $transaction->save();

        // Append file
        if (!empty($_FILES['file']['name'])) {
            $file = Fichiers::upload($_FILES['file']);
            $file->linkTo(Fichiers::LIEN_COMPTA, $transaction->id());
        }

        // Link members
        if (!empty($_POST['users']) && is_array($_POST['users'])) {
            foreach ($_POST['users'] as $id => $label) {
                $transaction->linkToUser((int) $id);
            }
        }

        Utils::redirect(Utils::getSelfURL(false) . '?ok=' . $transaction->id());
    }
    catch (UserException $e) {
        $form->addError($e->getMessage());
    }
}