Overview
Comment:Refactor transaction form, add transaction editing
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: f2c1ee8e780cd9e935c2e350df052a11aa3810ac
User & Date: bohwaz on 2020-10-01 14:04:11
Other Links: branch diff | manifest | tags
Context
2020-10-02
23:37
Transaction editing is working now check-in: 27f81b8455 user: bohwaz tags: dev
2020-10-01
14:04
Refactor transaction form, add transaction editing check-in: f2c1ee8e78 user: bohwaz tags: dev
11:21
Display list of users linked to a transaction check-in: a0fe66f766 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Entities/Accounting/Transaction.php from [1161b019a8] to [14ee05e6ca].

227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
...
268
269
270
271
272
273
274
275








			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));
				}

				// FIXME: allow one different analytical account per line
				$line['id_analytical'] = !empty($source['id_analytical']) ? $source['id_analytical'] : null;

				$line = (new Line)->import($line);
				$this->add($line);
			}
		}
	}

	public function year()
................................................................................
	public function listLinkedUsers()
	{
		$db = EntityManager::getInstance(self::class)->DB();
		$identity_column = Config::getInstance()->get('champ_identite');
		$sql = sprintf('SELECT m.id, m.%s AS identity FROM membres m INNER JOIN acc_transactions_users l ON l.id_user = m.id WHERE l.id_transaction = ?;', $identity_column);
		return $db->get($sql, $this->id());
	}
}















<
<
<







 







|
>
>
>
>
>
>
>
>
227
228
229
230
231
232
233



234
235
236
237
238
239
240
...
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
			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);
			}
		}
	}

	public function year()
................................................................................
	public function listLinkedUsers()
	{
		$db = EntityManager::getInstance(self::class)->DB();
		$identity_column = Config::getInstance()->get('champ_identite');
		$sql = sprintf('SELECT m.id, m.%s AS identity FROM membres m INNER JOIN acc_transactions_users l ON l.id_user = m.id WHERE l.id_transaction = ?;', $identity_column);
		return $db->get($sql, $this->id());
	}

	public function listLinkedUsersAssoc()
	{
		$db = EntityManager::getInstance(self::class)->DB();
		$identity_column = Config::getInstance()->get('champ_identite');
		$sql = sprintf('SELECT m.id, m.%s AS identity FROM membres m INNER JOIN acc_transactions_users l ON l.id_user = m.id WHERE l.id_transaction = ?;', $identity_column);
		return $db->getAssoc($sql, $this->id());
	}
}

Modified src/include/lib/Garradin/Form.php from [0c8efc77a0] to [b88e77b07b].

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
	protected $errors = [];

	public function __construct()
	{
		// Valide un montant de monnaie valide (deux décimales, ne peut être négatif)
		\KD2\Form::registerValidationRule('money', function ($name, $params, $value) {
			return preg_match('/^\d+(?:\.\d{1,2})?$/', $value) && $value >= 0;
		});

		// Test si la valeur existe dans cette table
		// in_table:compta_categories,id
		\KD2\Form::registerValidationRule('in_table', function ($name, $params, $value) {
			$db = DB::getInstance();
			return $db->test($params[0], $db->where($params[1], $value));







|







6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
{
	protected $errors = [];

	public function __construct()
	{
		// Valide un montant de monnaie valide (deux décimales, ne peut être négatif)
		\KD2\Form::registerValidationRule('money', function ($name, $params, $value) {
			return preg_match('/^\d+(?:[.,]\d{1,2})?$/', $value) && $value >= 0;
		});

		// Test si la valeur existe dans cette table
		// in_table:compta_categories,id
		\KD2\Form::registerValidationRule('in_table', function ($name, $params, $value) {
			$db = DB::getInstance();
			return $db->test($params[0], $db->where($params[1], $value));

Modified src/include/lib/Garradin/Template.php from [678031083a] to [cb36a70b55].

192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
...
213
214
215
216
217
218
219










220
221
222
223
224
225
226
...
282
283
284
285
286
287
288
289
290
291
292
293
294

295
296
297
298
299
300
301
...
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
	protected function widgetLinkButton(array $params): string
	{
		return sprintf('<a class="icn-btn" data-icon="%s" href="%s">%s</a>', Utils::iconUnicode($params['shape']), $this->escape(ADMIN_URL . $params['href']), $this->escape($params['label']));
	}

	protected function formInput(array $params)
	{
		static $params_list = ['value', 'default', 'type', 'help', 'label', 'name', 'options'];

		// Extract params and keep attributes separated
		$attributes = array_diff_key($params, array_flip($params_list));
		$params = array_intersect_key($params, array_flip($params_list));
		extract($params, \EXTR_SKIP);

		if (!isset($name, $type)) {
................................................................................
			$current_value = $value;
		}
		elseif (isset($_POST[$name])) {
			$current_value = $_POST[$name];
		}
		elseif (isset($default)) {
			$current_value = $default;










		}

		$attributes['id'] = 'f_' . $name;
		$attributes['name'] = $name;

		if ($type == 'radio' || $type == 'checkbox') {
			$attributes['id'] .= '_' . $value;
................................................................................
			$input = sprintf('<textarea %s>%s</textarea>', $attributes_string, $this->escape($current_value));
		}
		elseif ($type == 'list') {
			$multiple = !empty($attributes['multiple']);
			$values = '';
			$delete_btn = $this->widgetButton(['shape' => 'delete']);

			if (!is_array($current_value)) {
				$current_value = [];
			}

			foreach ($current_value as $v => $l) {
				$values .= sprintf('<span class="label"><input type="hidden" name="%s[%s]" value="%s" /> %3$s %s</span>', $this->escape($name), $this->escape($v), $this->escape($l), $multiple ? $delete_btn : '');

			}

			$button = $this->widgetButton([
				'shape' => $multiple ? 'plus' : 'menu',
				'value' => $attributes['target'],
				'label' => $multiple ? 'Ajouter' : 'Sélectionner',
				'data-multiple' => $multiple ? '1' : '0',
................................................................................
				'data-name' => $name,
			]);

			$input = sprintf('<span id="%s_container" class="input-list">%s%s</span>', $this->escape($attributes['id']), $button, $values);
		}
		elseif ($type == 'money') {
			$currency = Config::getInstance()->get('monnaie');
			$input = sprintf('<input type="text" pattern="[0-9.,]*" inputmode="decimal" size="8" class="money" %s value="%s" /><b>%s</b>', $attributes_string, $this->escape($current_value), $currency);
		}
		else {
			$input = sprintf('<input type="%s" %s value="%s" />', $type, $attributes_string, $this->escape($current_value));
		}

		// No label? then we only want the input without the widget
		if (empty($label)) {







|







 







>
>
>
>
>
>
>
>
>
>







 







<
|
<
<
|
|
>







 







|







192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
...
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
...
292
293
294
295
296
297
298

299


300
301
302
303
304
305
306
307
308
309
...
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
	protected function widgetLinkButton(array $params): string
	{
		return sprintf('<a class="icn-btn" data-icon="%s" href="%s">%s</a>', Utils::iconUnicode($params['shape']), $this->escape(ADMIN_URL . $params['href']), $this->escape($params['label']));
	}

	protected function formInput(array $params)
	{
		static $params_list = ['value', 'default', 'type', 'help', 'label', 'name', 'options', 'source'];

		// Extract params and keep attributes separated
		$attributes = array_diff_key($params, array_flip($params_list));
		$params = array_intersect_key($params, array_flip($params_list));
		extract($params, \EXTR_SKIP);

		if (!isset($name, $type)) {
................................................................................
			$current_value = $value;
		}
		elseif (isset($_POST[$name])) {
			$current_value = $_POST[$name];
		}
		elseif (isset($default)) {
			$current_value = $default;
		}
		elseif (isset($source) && is_object($source) && isset($source->$name)) {
			$current_value = $source->$name;
		}
		elseif (isset($source) && is_array($source) && isset($source[$name])) {
			$current_value = $source[$name];
		}

		if ($type == 'date' && is_object($current_value) && $current_value instanceof \DateTimeInterface) {
			$current_value = $current_value->format('d/m/Y');
		}

		$attributes['id'] = 'f_' . $name;
		$attributes['name'] = $name;

		if ($type == 'radio' || $type == 'checkbox') {
			$attributes['id'] .= '_' . $value;
................................................................................
			$input = sprintf('<textarea %s>%s</textarea>', $attributes_string, $this->escape($current_value));
		}
		elseif ($type == 'list') {
			$multiple = !empty($attributes['multiple']);
			$values = '';
			$delete_btn = $this->widgetButton(['shape' => 'delete']);


			if (null !== $current_value) {


				foreach ($current_value as $v => $l) {
					$values .= sprintf('<span class="label"><input type="hidden" name="%s[%s]" value="%s" /> %3$s %s</span>', $this->escape($name), $this->escape($v), $this->escape($l), $multiple ? $delete_btn : '');
				}
			}

			$button = $this->widgetButton([
				'shape' => $multiple ? 'plus' : 'menu',
				'value' => $attributes['target'],
				'label' => $multiple ? 'Ajouter' : 'Sélectionner',
				'data-multiple' => $multiple ? '1' : '0',
................................................................................
				'data-name' => $name,
			]);

			$input = sprintf('<span id="%s_container" class="input-list">%s%s</span>', $this->escape($attributes['id']), $button, $values);
		}
		elseif ($type == 'money') {
			$currency = Config::getInstance()->get('monnaie');
			$input = sprintf('<input type="text" pattern="[0-9]*([.,][0-9]{1,2})?" inputmode="decimal" size="8" class="money" %s value="%s" /><b>%s</b>', $attributes_string, $this->escape($current_value), $currency);
		}
		else {
			$input = sprintf('<input type="%s" %s value="%s" />', $type, $attributes_string, $this->escape($current_value));
		}

		// No label? then we only want the input without the widget
		if (empty($label)) {

Added src/templates/acc/transactions/_lines_form.tpl version [95d838e536].







































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
46
47
48
49
50
51
<?php
assert(is_array($lines));
assert(is_array($analytical_accounts));
assert(!isset($lines_accounts) || is_array($lines_accounts));
?>

<table class="list transaction-lines">
	<thead>
		<tr>
			<th>Compte</th>
			<td>Débit</td>
			<td>Crédit</td>
			<td>Réf. pièce</td>
			<td>Libellé ligne</td>
			{if count($analytical_accounts) > 0}
				<td>Analytique</td>
			{/if}
			<td></td>
		</tr>
	</thead>
	<tbody>
	{foreach from=$lines key="k" item="line"}
		<tr>
			<th>
				{if isset($lines_accounts)}
					{input type="list" target="%sacc/accounts/selector.php?target=all"|args:$admin_url name="lines[account][]" value=$lines_accounts[$k]}
				{else}
					{input type="list" target="%sacc/accounts/selector.php?target=all"|args:$admin_url name="lines[account][]"}
				{/if}
			</th>
			<td>{input type="money" name="lines[debit][]" value=$line.debit size=5}</td>
			<td>{input type="money" name="lines[credit][]" value=$line.credit size=5}</td>
			<td>{input type="text" name="lines[reference][]" value=$line.reference size=10}</td>
			<td>{input type="text" name="lines[label][]" value=$line.label}</td>
			{if count($analytical_accounts) > 0}
				<td>{input value=$line.id_analytical type="select" name="lines[id_analytical][]" options=$analytical_accounts}</td>
			{/if}
			<td>{button label="Enlever la ligne" shape="minus" name="remove_line"}</td>
		</tr>
	{/foreach}
	</tbody>
	<tfoot>
		<tr>
			<th></th>
			<td>{input type="money" name="debit_total" readonly="readonly" tabindex="-1" }</td>
			<td>{input type="money" name="credit_total" readonly="readonly" tabindex="-1" }</td>
			<td colspan="3" id="lines_message"></td>
			<td>{button label="Ajouter une ligne" shape="plus"}</td>
		</tr>
	</tfoot>
</table>

Modified src/templates/acc/transactions/details.tpl from [d1e9164567] to [6ca0ac5041].

11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
..
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

<dl class="describe">
	<dt>Libellé</dt>
	<dd><h2>{$transaction.label}</h2></dd>
	<dt>Date</dt>
	<dd>{$transaction.date|date_fr:'l j F Y (d/m/Y)'}</dd>
	<dt>Numéro pièce comptable</dt>
	<dd>{if trim($transaction.numero_piece)}{$transaction.numero_piece}{else}-{/if}</dd>

	<dt>Exercice</dt>
	<dd>
		<a href="{$admin_url}acc/years/year.php?id={$transaction.id_year}">{$tr_year.label}</a>
		| Du {$tr_year.start_date|date_fr:'d/m/Y'} au {$tr_year.end_date|date_fr:'d/m/Y'}
		| <strong>{if $tr_year.closed}Clôturé{else}En cours{/if}</strong>
	</dd>
................................................................................
	{else}
		{foreach from=$related_users item="u"}
			<dd><a href="{$admin_url}membres/fiche.php?id={$u.id}">{$u.identity}</a></dd>
		{/foreach}
	{/if}

	<dt>Remarques</dt>
	<dd>{if trim($transaction.notes)}{$transaction.notes}{else}-{/if}</dd>

	<dt>Fichiers joints</dt>
	{foreach from=$files item="file"}
	<dd>
		<aside class="file">
			<a href="{$file.url}">{$file.nom}</a>
			<small>({$file.type}, {$file.taille|format_bytes})</small>







|







 







|







11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
..
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64

<dl class="describe">
	<dt>Libellé</dt>
	<dd><h2>{$transaction.label}</h2></dd>
	<dt>Date</dt>
	<dd>{$transaction.date|date_fr:'l j F Y (d/m/Y)'}</dd>
	<dt>Numéro pièce comptable</dt>
	<dd>{if trim($transaction.reference)}{$transaction.reference}{else}-{/if}</dd>

	<dt>Exercice</dt>
	<dd>
		<a href="{$admin_url}acc/years/year.php?id={$transaction.id_year}">{$tr_year.label}</a>
		| Du {$tr_year.start_date|date_fr:'d/m/Y'} au {$tr_year.end_date|date_fr:'d/m/Y'}
		| <strong>{if $tr_year.closed}Clôturé{else}En cours{/if}</strong>
	</dd>
................................................................................
	{else}
		{foreach from=$related_users item="u"}
			<dd><a href="{$admin_url}membres/fiche.php?id={$u.id}">{$u.identity}</a></dd>
		{/foreach}
	{/if}

	<dt>Remarques</dt>
	<dd>{if trim($transaction.notes)}{$transaction.notes|escape|nl2br}{else}-{/if}</dd>

	<dt>Fichiers joints</dt>
	{foreach from=$files item="file"}
	<dd>
		<aside class="file">
			<a href="{$file.url}">{$file.nom}</a>
			<small>({$file.type}, {$file.taille|format_bytes})</small>

Added src/templates/acc/transactions/edit.tpl version [22f7776fc7].























































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
{include file="admin/_head.tpl" title="Saisie d'une écriture" current="acc/new" js=1}

<form method="post" action="{$self_url}" enctype="multipart/form-data">
	{form_errors}

	<fieldset>
		<legend>Informations</legend>
		<dl>
			{input source=$transaction type="text" name="label" label="Libellé général" required=1}
			{input source=$transaction type="date" name="date" label="Date" required=1}
		</dl>
	</fieldset>

	{* Saisie avancée *}
	<fieldset data-types="advanced">
		{include file="acc/transactions/_lines_form.tpl"}
	</fieldset>

	<fieldset>
		<legend>Détails</legend>
		<dl>
			{input value=$linked_users type="list" multiple=true name="users" label="Membres associés" target="%smembres/selector.php"|args:$admin_url}
			{input source=$transaction type="text" name="reference" label="Numéro de pièce comptable"}
			{input source=$transaction type="textarea" name="notes" label="Remarques" rows=4 cols=30}

			{input source=$transaction type="file" name="file" label="Ajouter un fichier joint"}
		</dl>
	</fieldset>

	<p class="submit">
		{csrf_field key="acc_edit_%d"|args:$transaction.id}
		<input type="submit" name="save" value="Enregistrer &rarr;" />
	</p>

</form>

{literal}
<script type="text/javascript" defer="defer" async="async">
g.script('scripts/accounting.js', () => { initTransactionForm(); });
</script>
{/literal}

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

Modified src/templates/acc/transactions/new.tpl from [26d128618b] to [c01a249a64].

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
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
...
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
259
260
261
262
263
264
265
266
267

268
269
270
271
		</dl>
		<dl data-types="all-but-advanced">
			{input type="money" name="amount" label="Montant" required=1}
			{input type="text" name="payment_reference" label="Référence de paiement" help="Numéro de chèque, numéro de transaction CB, etc."}
		</dl>
	</fieldset>



	{* Saisie avancée *}
	<fieldset data-types="advanced">
		<table class="list transaction-lines">
			<thead>
				<tr>
					<th>Compte</th>
					<td>Débit</td>
					<td>Crédit</td>
					<td>Réf. pièce</td>
					<td>Libellé ligne</td>
					<td></td>
				</tr>
			</thead>
			<tbody>
			{foreach from=$lines item="line"}
				<tr>
					<th>{input type="list" target="%sacc/accounts/selector.php?target=all"|args:$admin_url name="lines[account][]" value=$line.account}</th>
					<td>{input type="money" name="lines[debit][]" value=$line.debit size=5}</td>
					<td>{input type="money" name="lines[credit][]" value=$line.credit size=5}</td>
					<td>{input type="text" name="lines[reference][]" value=$line.label size=10}</td>
					<td>{input type="text" name="lines[label][]"}</td>
					<td>{button label="Enlever la ligne" shape="minus" name="remove_line"}</td>
				</tr>
			{/foreach}
			</tbody>
			<tfoot>
				<tr>
					<th></th>
					<td>{input type="money" name="debit_total" readonly="readonly" tabindex="-1" }</td>
					<td>{input type="money" name="credit_total" readonly="readonly" tabindex="-1" }</td>
					<td colspan="2" id="lines_message"></td>
					<td>{button label="Ajouter une ligne" shape="plus"}</td>
				</tr>
			</tfoot>
		</table>

	</fieldset>

	<fieldset>
		<legend>Détails</legend>
		<dl>
			{input type="list" multiple=true name="users" label="Membres associés" target="%smembres/selector.php"|args:$admin_url}
			{input type="text" name="reference" label="Numéro de pièce comptable"}
			{input type="textarea" name="notes" label="Remarques" rows=4 cols=30}

			{input type="file" name="file" label="Fichier joint"}


			{if count($analytical_accounts) > 0}
				{input type="select" name="id_analytical" label="Compte analytique (projet)" options=$analytical_accounts}
			{/if}
		</dl>
	</fieldset>

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

</form>

{literal}
<script type="text/javascript">

function initForm() {
	// Hide type specific parts of the form
	function hideAllTypes() {
		var sections = $('fieldset[data-types]');

		sections.forEach((e) => {
			e.style.display = 'none';
		});
	}

	// Toggle parts of the form when a type is selected
	function selectType(v) {
		hideAllTypes();
		$('[data-types=' + v + ']')[0].style.display = 'block';
		$('[data-types=all-but-advanced]')[0].style.display = v == 'advanced' ? 'none' : 'block';
		// Disable required form elements, or the form won't be able to be submitted
		$('[data-types=all-but-advanced] input[required]').forEach((e) => {
			e.disabled = v == 'advanced' ? true : false;
		});

	}

................................................................................
	hideAllTypes();

	// In case of a pre-filled form: show the correct part of the form
	var current = document.querySelector('input[name=type]:checked');
	if (current) {
		selectType(current.value);
	}

	// Advanced transaction: line management
	var lines = $('.transaction-lines tbody tr');

	function initLine(row) {
		row.querySelector('button[name="remove_line"]').onclick = () => {
			var count = $('.transaction-lines tbody tr').length;

			if (count <= 2) {
				alert("Il n'est pas possible d'avoir moins de deux lignes dans une écriture.");
				return false;
			}

			row.parentNode.removeChild(row);
			updateTotals();
		};

		// Update totals and disable other amount input
		var money_inputs = row.querySelectorAll('input.money');

		money_inputs.forEach((i) => {
			i.onkeyup = (e) => {
				if (!e.key.match(/^([0-9,.]|Separator|Backspace)$/i)) {
					return true;
				}

				var v = i.value.replace(/[^0-9.,]/);
				var ro = (v.length == 0 || v == 0) ? false : true;

				money_inputs.forEach((i2) => {
					i2.readOnly = i2 === i ? false : ro;
					if (i2 !== i) { i2.value = ''; }
				});

				updateTotals();
			};
		});
	}

	lines.forEach(initLine);

	function updateTotals() {
		var amounts = $('.transaction-lines tbody input.money');
		var debit = credit = 0;

		amounts.forEach((i) => {
			var v = i.value.replace(/[^0-9.,]/, '');
			if (v.length == 0) return;

			v = v.split(/[,.]/);
			var d = v.length == 2 ? v[1] : '0';
			v = v[0] + (d + '00').substr(0, 2);
			v = parseInt(v, 10);

			if (i.name.match(/debit/)) {
				debit += v;
			}
			else {
				credit += v;
			}
		});

		$('#lines_message').innerHTML = (debit === credit) ? '' : '<span class="alert">Écriture non équilibrée</span>';

		debit = debit ? debit + '' : '000';
		credit = credit ? credit + '' : '000';
		$('#f_debit_total').value = debit.substr(0, debit.length-2) + ',' + debit.substr(-2);
		$('#f_credit_total').value = credit.substr(0, credit.length-2) + ',' + credit.substr(-2);
	}

	// Add row button
	$('.transaction-lines tfoot button')[0].onclick = () => {
		var line = $('.transaction-lines tbody tr')[0];
		var n = line.cloneNode(true);
		n.querySelectorAll('input').forEach((e) => {
			e.value = '';
		});
		n.querySelector('.input-list .label').innerHTML = '';
		var b = n.querySelector('.input-list button');
		b.onclick = () => {
			g.current_list_input = b.parentNode;
			g.openFrameDialog(b.value);
			return false;
		};
		initLine(n);
		line.parentNode.appendChild(n);
	};
}

initForm();

</script>
{/literal}

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







<
<


<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
<
>










|
>







 







|
<



|
<
<
<
<





|
|







 







|
<
<

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




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
...
133
134
135
136
137
138
139
140


141
















































































142


143


144
145
146
147
148
		</dl>
		<dl data-types="all-but-advanced">
			{input type="money" name="amount" label="Montant" required=1}
			{input type="text" name="payment_reference" label="Référence de paiement" help="Numéro de chèque, numéro de transaction CB, etc."}
		</dl>
	</fieldset>



	{* Saisie avancée *}
	<fieldset data-types="advanced">

































		{include file="acc/transactions/_lines_form.tpl"}
	</fieldset>

	<fieldset>
		<legend>Détails</legend>
		<dl>
			{input type="list" multiple=true name="users" label="Membres associés" target="%smembres/selector.php"|args:$admin_url}
			{input type="text" name="reference" label="Numéro de pièce comptable"}
			{input type="textarea" name="notes" label="Remarques" rows=4 cols=30}

			{input type="file" name="file" label="Fichier joint"}
		</dl>
		<dl data-types="all-but-advanced">
			{if count($analytical_accounts) > 0}
				{input type="select" name="id_analytical" label="Compte analytique (projet)" options=$analytical_accounts}
			{/if}
		</dl>
	</fieldset>

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

</form>

{literal}
<script type="text/javascript" defer="defer" async="async">

function initForm() {
	// Hide type specific parts of the form
	function hideAllTypes() {
		g.toggle('fieldset[data-types]', false);




	}

	// Toggle parts of the form when a type is selected
	function selectType(v) {
		hideAllTypes();
		g.toggle('[data-types=' + v + ']', true);
		g.toggle('[data-types=all-but-advanced]', v != 'advanced');
		// Disable required form elements, or the form won't be able to be submitted
		$('[data-types=all-but-advanced] input[required]').forEach((e) => {
			e.disabled = v == 'advanced' ? true : false;
		});

	}

................................................................................
	hideAllTypes();

	// In case of a pre-filled form: show the correct part of the form
	var current = document.querySelector('input[name=type]:checked');
	if (current) {
		selectType(current.value);
	}
}



















































































initForm();





g.script('scripts/accounting.js', () => { initTransactionForm(); });
</script>
{/literal}

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

Added src/www/admin/acc/transactions/edit.php version [0cc65f8dd2].







































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
46
47
48
49
50
51
<?php

namespace Garradin;

use Garradin\Accounting\Transactions;

require_once __DIR__ . '/../_inc.php';

$session->requireAccess('compta', Membres::DROIT_ADMIN);

$transaction = Transactions::get((int) qg('id'));

if (!$transaction) {
    throw new UserException('Cette écriture n\'existe pas');
}

$chart = $year->chart();
$accounts = $chart->accounts();


if (f('delete'))
{
    if ($form->check('acc_edit_' . $transaction->id))
    {
        try
        {
            $transaction->delete();
            Utils::redirect(ADMIN_URL . 'acc/');
        }
        catch (UserException $e)
        {
            $form->addError($e->getMessage());
        }
    }
}

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

$lines = $transaction->getLinesWithAccounts();
$lines_accounts = [];

foreach ($lines as $k => $line) {
    $lines_accounts[$k] = [$line->id_account => sprintf('%s - %s', $line->account_code, $line->account_name)];
}

$tpl->assign('lines', $lines);
$tpl->assign('lines_accounts', $lines_accounts);
$tpl->assign('analytical_accounts', ['' => '-- Aucun'] + $accounts->listAnalytical());
$tpl->assign('linked_users', $transaction->listLinkedUsersAssoc());

$tpl->display('acc/transactions/edit.tpl');

Modified src/www/admin/acc/transactions/new.php from [d477ceee4e] to [14490d4037].

34
35
36
37
38
39
40

41
42
43
44
45
46
47
            for ($i = 0; $i < $max; $i++) {
                $out[] = [
                    'debit'      => $lines['debit'][$i],
                    'credit'     => $lines['credit'][$i],
                    'reference'  => $lines['reference'][$i],
                    'label'      => $lines['label'][$i],
                    'account'    => $lines['account'][$i],

                ];
            }

            $_POST['lines'] = $lines = $out;
        }

        $transaction->id_year = $year->id();







>







34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
            for ($i = 0; $i < $max; $i++) {
                $out[] = [
                    'debit'      => $lines['debit'][$i],
                    'credit'     => $lines['credit'][$i],
                    'reference'  => $lines['reference'][$i],
                    'label'      => $lines['label'][$i],
                    'account'    => $lines['account'][$i],
                    'id_analytical' => isset($lines['id_analytical'][$i]) ? $lines['id_analytical'][$i] : null,
                ];
            }

            $_POST['lines'] = $lines = $out;
        }

        $transaction->id_year = $year->id();