Overview
Comment:Account selection is functional
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: 0df14a7dd92f928a3bf802e4cc88f277e612a32f
User & Date: bohwaz on 2020-09-10 17:08:25
Other Links: branch diff | manifest | tags
Context
2020-09-10
23:22
Fix new transaction keeping submitted values check-in: 0e4d9c752d user: bohwaz tags: dev
17:08
Account selection is functional check-in: 0df14a7dd9 user: bohwaz tags: dev
15:36
Sélecteur de compte fonctionnel check-in: b7d307b8a5 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Template.php from [f5047d25e3] to [982598300f].

70
71
72
73
74
75
76
77

78
79
80
81
82
83
84
		$this->register_function('format_droits', [$this, 'formatDroits']);

		$this->register_function('csrf_field', function ($params) {
			return Form::tokenHTML($params['key']);
		});

		$this->register_function('icon', [$this, 'widgetIcon']);
		$this->register_function('button', [$this, 'widgetLinkButton']);


		$this->register_modifier('strlen', 'strlen');
		$this->register_modifier('dump', ['KD2\ErrorManager', 'dump']);
		$this->register_modifier('get_country_name', ['Garradin\Utils', 'getCountryName']);
		$this->register_modifier('format_sqlite_date_to_french', ['Garradin\Utils', 'sqliteDateToFrench']);
		$this->register_modifier('format_bytes', ['Garradin\Utils', 'format_bytes']);
		$this->register_modifier('format_tel', [$this, 'formatPhoneNumber']);







|
>







70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
		$this->register_function('format_droits', [$this, 'formatDroits']);

		$this->register_function('csrf_field', function ($params) {
			return Form::tokenHTML($params['key']);
		});

		$this->register_function('icon', [$this, 'widgetIcon']);
		$this->register_function('button', [$this, 'widgetButton']);
		$this->register_function('linkbutton', [$this, 'widgetLinkButton']);

		$this->register_modifier('strlen', 'strlen');
		$this->register_modifier('dump', ['KD2\ErrorManager', 'dump']);
		$this->register_modifier('get_country_name', ['Garradin\Utils', 'getCountryName']);
		$this->register_modifier('format_sqlite_date_to_french', ['Garradin\Utils', 'sqliteDateToFrench']);
		$this->register_modifier('format_bytes', ['Garradin\Utils', 'format_bytes']);
		$this->register_modifier('format_tel', [$this, 'formatPhoneNumber']);
168
169
170
171
172
173
174















175
176
177
178
179
180
181
	{
		if (empty($params['href'])) {
			return sprintf('<b class="icn">%s</b>', Utils::iconUnicode($params['shape']));
		}

		return sprintf('<a href="%s" class="icn" title="%s">%s</a>', $this->escape(ADMIN_URL . $params['href']), $this->escape($params['label']), Utils::iconUnicode($params['shape']));
	}
















	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)







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







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
	{
		if (empty($params['href'])) {
			return sprintf('<b class="icn">%s</b>', Utils::iconUnicode($params['shape']));
		}

		return sprintf('<a href="%s" class="icn" title="%s">%s</a>', $this->escape(ADMIN_URL . $params['href']), $this->escape($params['label']), Utils::iconUnicode($params['shape']));
	}

	protected function widgetButton(array $params): string
	{
		$icon = Utils::iconUnicode($params['shape']);
		$label = $this->escape($params['label']);
		unset($params['label'], $params['shape']);

		array_walk($params, function (&$v, $k) {
			$v = sprintf('%s="%s"', $k, $this->escape($v));
		});

		$params = implode(' ', $params);

		return sprintf('<button %s class="icn-btn" data-icon="%s" type="button">%s</button>', $params, $icon, $label);
	}

	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)

Modified src/templates/acc/accounts/selector.tpl from [d6563ce158] to [90b2aab47f].

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
52
53
					</td>
				</tr>
			{/foreach}
			</tbody>
		</table>
	{/foreach}



















{/if}

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









var buttons = document.querySelectorAll('button');

buttons.forEach((e) => {
	e.onclick = () => {
		window.parent.inputListSelected(e.value, e.getAttribute('data-label'));
	};
});

buttons[0].focus();

var rows = document.querySelectorAll('table tr');

rows.forEach((e) => {
	e.className = 'clickable';



	e.onclick = (evt) => {
		if (evt.target.tagName && evt.target.tagName == 'BUTTON') {
			return;
		}

		e.querySelector('button').click();
	};
});



















</script>
{/literal}

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







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




>
>
>
>
>
>
>
>
>













|
>
>
>








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




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
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
					</td>
				</tr>
			{/foreach}
			</tbody>
		</table>
	{/foreach}

{else}

	<h2 class="ruler"><input type="text" placeholder="Recherche rapide" id="lookup" /></h2>

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

{/if}

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

RegExp.escape = function(string) {
  return string.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&')
};

function normalizeString(str) {
	return str.normalize('NFD').replace(/[\u0300-\u036f]/g, "")
}

var buttons = document.querySelectorAll('button');

buttons.forEach((e) => {
	e.onclick = () => {
		window.parent.inputListSelected(e.value, e.getAttribute('data-label'));
	};
});

buttons[0].focus();

var rows = document.querySelectorAll('table tr');

rows.forEach((e) => {
	e.classList.add('clickable');
	var l = e.querySelector('td').innerText + ' ' + e.querySelector('th').innerText;
	e.setAttribute('data-search-label', normalizeString(l));

	e.onclick = (evt) => {
		if (evt.target.tagName && evt.target.tagName == 'BUTTON') {
			return;
		}

		e.querySelector('button').click();
	};
});

var q = document.getElementById('lookup');

q.onkeyup = (e) => {
	var query = new RegExp(RegExp.escape(normalizeString(q.value)), 'i');

	rows.forEach((elm) => {
		if (elm.getAttribute('data-search-label').match(query)) {
			elm.style.display = null;
		}
		else {
			elm.style.display = 'none';
		}
	});

};

q.focus();

</script>
{/literal}

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

Modified src/templates/acc/transactions/new.tpl from [e8a2cd2bf5] to [2b0fe5bbad].

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
		</dl>
	</fieldset>



	{* Saisie avancée *}
	<fieldset data-types="advanced">
		<table class="list">
			<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 key="line_number" item="line"}
				<tr>
					<th>{input type="list" target="%sacc/accounts/selector.php?target=all"|args:$admin_url name="lines[%d][account]"|args:$line_number value=$line.id_account required=1}</th>
					<td>{input type="number" name="lines[%d][debit]"|args:$line_number min="0.00" step="0.01" value=$line.debit required=1}</td>
					<td>{input type="number" name="lines[%d][credit]"|args:$line_number min="0.00" step="0.01" value=$line.credit required=1}</td>
					<td>{input type="text" name="lines[%d][reference]" size=8}</td>
					<td>{input type="text" name="lines[%d][label]"}</td>
					<td></td>
				</tr>
			{/foreach}
			</tbody>
			<tfoot>
				<tr>
					<th></th>
					<td id="lines_debit_total"></td>
					<td id="lines_credit_total"></td>
					<td colspan="2"></td>
					<td></td>
				</tr>
			</tfoot>
		</table>
	</fieldset>

	<fieldset>
		<legend>Détails</legend>







|














|
|
|

|






|
|

|







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
		</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 key="line_number" item="line"}
				<tr>
					<th>{input type="list" target="%sacc/accounts/selector.php?target=all"|args:$admin_url name="lines[%d][account]"|args:$line_number value=$line.id_account required=1}</th>
					<td>{input type="number" name="lines[%d][debit]"|args:$line_number min="0.00" step="0.01" value=$line.debit required=1 size=5}</td>
					<td>{input type="number" name="lines[%d][credit]"|args:$line_number min="0.00" step="0.01" value=$line.credit required=1 size=5}</td>
					<td>{input type="text" name="lines[%d][reference]" size=10}</td>
					<td>{input type="text" name="lines[%d][label]"}</td>
					<td>{button label="Enlever la ligne" shape="minus"}</td>
				</tr>
			{/foreach}
			</tbody>
			<tfoot>
				<tr>
					<th></th>
					<td><input type="number" id="lines_debit_total" readonly="readonly" size="5" tabindex="-1" /></td>
					<td><input type="number" id="lines_credit_total" readonly="readonly" size="5" tabindex="-1" /></td>
					<td colspan="2"></td>
					<td>{button label="Ajouter une ligne" shape="plus"}</td>
				</tr>
			</tfoot>
		</table>
	</fieldset>

	<fieldset>
		<legend>Détails</legend>
152
153
154
155
156
157
158




































159
160
161
162
163
164
165
			hideAll();
			$('[data-types=' + e.value + ']')[0].style.display = 'block';
			$('[data-types=all-but-advanced]')[0].style.display = e.value == 'advanced' ? 'none' : 'block';
		};
	});

	hideAll();




































}

function inputListSelected(value, label) {
	var i = g.current_list_input;
	i.parentNode.querySelector('input[type=hidden]').value = value;
	i.parentNode.querySelector('span.label').innerHTML = label;
	g.closeDialog();







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







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
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
			hideAll();
			$('[data-types=' + e.value + ']')[0].style.display = 'block';
			$('[data-types=all-but-advanced]')[0].style.display = e.value == 'advanced' ? 'none' : 'block';
		};
	});

	hideAll();

	var lines = $('.transaction-lines tbody tr');

	function initLine(e) {
		e.querySelector('button:nth-child(1)').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;
			}

			e.parentNode.removeChild(e);
		};
	}

	lines.forEach((e) => {
		initLine(e);
	});

	$('.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);
	};
}

function inputListSelected(value, label) {
	var i = g.current_list_input;
	i.parentNode.querySelector('input[type=hidden]').value = value;
	i.parentNode.querySelector('span.label').innerHTML = label;
	g.closeDialog();

Modified src/www/admin/acc/transactions/new.php from [cdd41db12e] to [5705618f16].

11
12
13
14
15
16
17
18
19
20
21
$accounts = $chart->accounts();

$transaction = new Transaction;

$tpl->assign('date', $session->get('context_compta_date') ?: false);
$tpl->assign('ok', (int) qg('ok'));

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

$tpl->assign('analytical_accounts', $accounts->listAnalytical());
$tpl->display('acc/transactions/new.tpl');







|



11
12
13
14
15
16
17
18
19
20
21
$accounts = $chart->accounts();

$transaction = new Transaction;

$tpl->assign('date', $session->get('context_compta_date') ?: false);
$tpl->assign('ok', (int) qg('ok'));

$tpl->assign('lines', $transaction->getLines() ?: [[]]);

$tpl->assign('analytical_accounts', $accounts->listAnalytical());
$tpl->display('acc/transactions/new.tpl');

Modified src/www/admin/static/admin.css from [1039b12155] to [6429107812].

270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
}

label:hover {
    cursor: pointer;
    border-bottom: 1px dotted #900;
}

table.list tr.clickable:hover {
    cursor: pointer;
    color: #633;
    background: #ffc;

}

dl dt label {







|







270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
}

label:hover {
    cursor: pointer;
    border-bottom: 1px dotted #900;
}

table tr.clickable:hover {
    cursor: pointer;
    color: #633;
    background: #ffc;

}

dl dt label {
319
320
321
322
323
324
325

326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
    min-width: 20em;
    max-width: 100%;
    border: 1px solid #999;
    font-size: inherit;
    background: #fff;
    border-radius: .25rem;
    transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;

}

input:not([type=checkbox]):not([type=radio]):focus, button:focus, select:focus, textarea:focus {
    border-color: #009;
    box-shadow: 0 0 0 0.2rem rgb(var(--gSecondColor));
    outline: 0;
}

input:not(:placeholder-shown):focus:invalid {
    border-color: #f33;
}

input[type=password], input.clearTextPassword {
    font-family: monospace;
}

select, input[size] {
    min-width: 0;
}

input.time {
    text-align: center;
    padding: .2em 0;
}

input[type=number], input[type=date] {
    padding: 0.2em 0.4em;
    font-family: Sans-serif;
    min-width: 2em;
}

input[type=submit], input[type=button], input[type=checkbox], button {
    padding: 0.3em;
    cursor: pointer;
    transition: opacity .5s ease;
}

input.resetButton {







>
















<
<
<
<





<
<
<
<
<
<







319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342




343
344
345
346
347






348
349
350
351
352
353
354
    min-width: 20em;
    max-width: 100%;
    border: 1px solid #999;
    font-size: inherit;
    background: #fff;
    border-radius: .25rem;
    transition: border-color .15s ease-in-out,box-shadow .15s ease-in-out;
    line-height: 1.5rem;
}

input:not([type=checkbox]):not([type=radio]):focus, button:focus, select:focus, textarea:focus {
    border-color: #009;
    box-shadow: 0 0 0 0.2rem rgb(var(--gSecondColor));
    outline: 0;
}

input:not(:placeholder-shown):focus:invalid {
    border-color: #f33;
}

input[type=password], input.clearTextPassword {
    font-family: monospace;
}





input.time {
    text-align: center;
    padding: .2em 0;
}







input[type=submit], input[type=button], input[type=checkbox], button {
    padding: 0.3em;
    cursor: pointer;
    transition: opacity .5s ease;
}

input.resetButton {
372
373
374
375
376
377
378




379
380
381
382
383
384
385
    background: none;
    margin-top: .1em;
}

input[type=button].showPassword:hover {
    background: none;
}





form .input-list {
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: start;
    flex-direction: row-reverse;







>
>
>
>







363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
    background: none;
    margin-top: .1em;
}

input[type=button].showPassword:hover {
    background: none;
}

select, input[size] {
    min-width: 0;
}

form .input-list {
    padding: 0;
    display: inline-flex;
    align-items: center;
    justify-content: start;
    flex-direction: row-reverse;
1127
1128
1129
1130
1131
1132
1133


1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
}

dl.list dt em {
    color: #9c4f15;
    color: rgb(var(--gMainColor));
}



table.accounts tbody tr td:first-child { font-family: monospace; }
table.accounts th { font-weight: normal; }
table.accounts .account-level-1 th { font-size: 1.6em; }
table.accounts .account-level-2 > th { padding-left: 1em; font-size: 1.3em; }
table.accounts .account-level-3 > th { padding-left: 2em; }
table.accounts .account-level-4 > th { padding-left: 3em; }
table.accounts .account-level-5 > th { padding-left: 4em; }
table.accounts .account-level-6 > th { padding-left: 5em; }

dl.describe {
    margin-bottom: 1em;
}

dl.describe > dt {
    font-weight: bold;







>
>



|
|
|
|
|







1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
}

dl.list dt em {
    color: #9c4f15;
    color: rgb(var(--gMainColor));
}

table.accounts { width: 100%; }
table.accounts .actions { text-align: right; }
table.accounts tbody tr td:first-child { font-family: monospace; }
table.accounts th { font-weight: normal; }
table.accounts .account-level-1 th { font-size: 1.6em; }
table.accounts .account-level-2 th { padding-left: 1em; font-size: 1.3em; }
table.accounts .account-level-3 th { padding-left: 2em; }
table.accounts .account-level-4 th { padding-left: 3em; }
table.accounts .account-level-5 th { padding-left: 4em; }
table.accounts .account-level-6 th { padding-left: 5em; }

dl.describe {
    margin-bottom: 1em;
}

dl.describe > dt {
    font-weight: bold;

Modified src/www/admin/static/scripts/global.js from [72cac74200] to [24c23639ba].

215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
		}*/
	};

	g.current_list_input = null;

		// Sélecteurs de listes
	g.onload(() => {
		var inputs = $(' form .input-list button');

		inputs.forEach((i) => {
			i.onclick = () => {
				g.current_list_input = i.parentNode;
				g.openFrameDialog(i.value);
				return false;
			};







|







215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
		}*/
	};

	g.current_list_input = null;

		// Sélecteurs de listes
	g.onload(() => {
		var inputs = $('form .input-list button');

		inputs.forEach((i) => {
			i.onclick = () => {
				g.current_list_input = i.parentNode;
				g.openFrameDialog(i.value);
				return false;
			};