Overview
Comment:Fix new transaction keeping submitted values
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: 0e4d9c752d7dfca00bb377a09d903701823b8500
User & Date: bohwaz on 2020-09-10 23:22:09
Other Links: branch diff | manifest | tags
Context
2020-09-14
00:24
Transaction and line saving works now check-in: 68ac12741f user: bohwaz tags: dev
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
Changes

Modified src/include/lib/Garradin/Entities/Accounting/Transaction.php from [9f05a3c6b2] to [8f5af7c0b9].

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
	protected $id_year;
	protected $id_analytical;

	protected $_types = [
		'label'             => 'string',
		'notes'             => '?string',
		'reference'         => '?string',
		'date'              => 'date',
		'validated'         => 'bool',
		'hash'              => '?string',
		'prev_hash'         => '?string',
		'id_year'           => 'int',
		'id_analytical'     => '?int',
	];








|







26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
	protected $id_year;
	protected $id_analytical;

	protected $_types = [
		'label'             => 'string',
		'notes'             => '?string',
		'reference'         => '?string',
		'date'              => 'DateTime',
		'validated'         => 'bool',
		'hash'              => '?string',
		'prev_hash'         => '?string',
		'id_year'           => 'int',
		'id_analytical'     => '?int',
	];

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

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
...
267
268
269
270
271
272
273
274








275
276
277
278
279
280
281
		}

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

		if ($type == 'radio' || $type == 'checkbox') {
			$attributes['id'] .= '_' . $value;




		}

		// Create attributes string
		if (array_key_exists('required', $attributes)) {
			$attributes['required'] = 'required';
		}

		$attributes_string = $attributes;

		if ($type == 'list') {
			unset($attributes_string['target']);
		}

		array_walk($attributes_string, function (&$v, $k) {
			$v = sprintf('%s="%s"', $k, $v);
		});

		$attributes_string = implode(' ', $attributes_string);
................................................................................

			$input .= '</select>';
		}
		elseif ($type == 'textarea') {
			$input = sprintf('<textarea %s>%s</textarea>', $attributes_string, $this->escape($current_value));
		}
		elseif ($type == 'list') {
			$input = sprintf('<span id="%s_container" class="input-list"><input type="hidden" value="%s" %s /><span class="label">%2$s</span><button type="button" data-icon="%s" name="list_selector[%2$s]" class="icn-btn" value="%s">%s</button></span>', $this->escape($attributes['id']), $this->escape($current_value), $attributes_string, Utils::iconUnicode('menu'), $this->escape($attributes['target']), 'Sélectionner');








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







>
>
>
>










|







 







|
>
>
>
>
>
>
>
>







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
...
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
		}

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

		if ($type == 'radio' || $type == 'checkbox') {
			$attributes['id'] .= '_' . $value;

			if (isset($_POST[$name]) && $_POST[$name] == $value) {
				$attributes['checked'] = 'checked';
			}
		}

		// Create attributes string
		if (array_key_exists('required', $attributes)) {
			$attributes['required'] = 'required';
		}

		$attributes_string = $attributes;

		if ($type == 'list') {
			unset($attributes_string['target'], $attributes_string['multiple']);
		}

		array_walk($attributes_string, function (&$v, $k) {
			$v = sprintf('%s="%s"', $k, $v);
		});

		$attributes_string = implode(' ', $attributes_string);
................................................................................

			$input .= '</select>';
		}
		elseif ($type == 'textarea') {
			$input = sprintf('<textarea %s>%s</textarea>', $attributes_string, $this->escape($current_value));
		}
		elseif ($type == 'list') {
			$multiple = !empty($attributes['multiple']);

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

			$input = sprintf('<span id="%s_container" class="input-list">%s<input type="hidden" value="%s" %s /><span class="label">%3$s</span></span>', $this->escape($attributes['id']), $button, $this->escape($current_value), $attributes_string);
		}
		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)) {

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

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

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







>
|
|

|
|
|
|
|
|
|
|

|

|
|




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

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

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

if (q) {
	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 [2b0fe5bbad] to [ea399dd132].

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
..
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
...
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
...
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
163
164
165
			{input type="list" target="%sacc/accounts/selector.php?target=common"|args:$admin_url name="to" label="Vers" required=1}
		</dl>
	</fieldset>

	<fieldset data-types="revenue">
		<legend>Recette</legend>
		<dl>
			{input type="list" target="%sacc/accounts/selector.php?target=revenue"|args:$admin_url name="from" label="Type de recette" required=1}
			{input type="list" target="%sacc/accounts/selector.php?target=common"|args:$admin_url name="to" label="Compte d'encaissement" required=1}
		</dl>
	</fieldset>

	<fieldset data-types="expense">
		<legend>Dépense</legend>
		<dl>
			{input type="list" target="%sacc/accounts/selector.php?target=expense"|args:$admin_url name="to" label="Type de dépense" required=1}
			{input type="list" target="%sacc/accounts/selector.php?target=common"|args:$admin_url name="from" label="Compte de décaissement" required=1}
		</dl>
	</fieldset>

	<fieldset data-types="debt">
		<legend>Dette</legend>
		<dl>
			{input type="list" target="%sacc/accounts/selector.php?target=thirdparty"|args:$admin_url name="to" label="Compte de tiers" required=1}
			{input type="list" target="%sacc/accounts/selector.php?target=expense"|args:$admin_url name="from" label="Type de dette (dépense)" required=1}
		</dl>
	</fieldset>

	<fieldset data-types="credit">
		<legend>Créance</legend>
		<dl>
			{input type="list" target="%sacc/accounts/selector.php?target=thirdparty"|args:$admin_url name="to" label="Compte de tiers" required=1}
			{input type="list" target="%sacc/accounts/selector.php?target=revenue"|args:$admin_url name="from" label="Type de créance (recette)" required=1}
		</dl>
	</fieldset>

	<fieldset>
		<legend>Informations</legend>
		<dl>
			{input type="text" name="label" label="Libellé" required=1}
			{input type="date" name="date" value=$date label="Date" required=1}
		</dl>
		<dl data-types="all-but-advanced">
			{input type="number" name="amount" label="Montant (%s)"|args:$config.monnaie min="0.00" step="0.01" value="0.00" required=1}
			{input type="text" name="reference_paiement" label="Référence de paiement" help="Numéro de chèque, numéro de transaction CB, etc."}
		</dl>
	</fieldset>



	{* Saisie avancée *}
................................................................................
					<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>
................................................................................
			</tfoot>
		</table>
	</fieldset>

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

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

</form>

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

function initForm() {
	function hideAll() {
		var sections = $('fieldset[data-types]');

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







	var radios = $('fieldset input[type=radio][name=type]');

	radios.forEach((e) => {
		e.onchange = (evt) => {
			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;








|
|






|
|






|
|






|
|







|


|







 







|
|
|
|
|







 







|







 







|






>
>
>
>
>
>




|
|
<
<



|
>
>
>
>
>
>







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
..
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
...
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
...
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
163
164
165
166
167
168
169
170
171
172
173
174
175
			{input type="list" target="%sacc/accounts/selector.php?target=common"|args:$admin_url name="to" label="Vers" required=1}
		</dl>
	</fieldset>

	<fieldset data-types="revenue">
		<legend>Recette</legend>
		<dl>
			{input type="list" target="%sacc/accounts/selector.php?target=revenue"|args:$admin_url name="revenue_from" label="Type de recette" required=1}
			{input type="list" target="%sacc/accounts/selector.php?target=common"|args:$admin_url name="revenue_to" label="Compte d'encaissement" required=1}
		</dl>
	</fieldset>

	<fieldset data-types="expense">
		<legend>Dépense</legend>
		<dl>
			{input type="list" target="%sacc/accounts/selector.php?target=expense"|args:$admin_url name="expense_to" label="Type de dépense" required=1}
			{input type="list" target="%sacc/accounts/selector.php?target=common"|args:$admin_url name="expense_from" label="Compte de décaissement" required=1}
		</dl>
	</fieldset>

	<fieldset data-types="debt">
		<legend>Dette</legend>
		<dl>
			{input type="list" target="%sacc/accounts/selector.php?target=thirdparty"|args:$admin_url name="debt_to" label="Compte de tiers" required=1}
			{input type="list" target="%sacc/accounts/selector.php?target=expense"|args:$admin_url name="debt_from" label="Type de dette (dépense)" required=1}
		</dl>
	</fieldset>

	<fieldset data-types="credit">
		<legend>Créance</legend>
		<dl>
			{input type="list" target="%sacc/accounts/selector.php?target=thirdparty"|args:$admin_url name="credit_to" label="Compte de tiers" required=1}
			{input type="list" target="%sacc/accounts/selector.php?target=revenue"|args:$admin_url name="credit_from" label="Type de créance (recette)" required=1}
		</dl>
	</fieldset>

	<fieldset>
		<legend>Informations</legend>
		<dl>
			{input type="text" name="label" label="Libellé" required=1}
			{input type="date" name="date" default=$date label="Date" required=1}
		</dl>
		<dl data-types="all-but-advanced">
			{input type="number" name="amount" label="Montant (%s)"|args:$config.monnaie min="0.00" step="0.01" default="0" required=1}
			{input type="text" name="reference_paiement" label="Référence de paiement" help="Numéro de chèque, numéro de transaction CB, etc."}
		</dl>
	</fieldset>



	{* Saisie avancée *}
................................................................................
					<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}</th>
					<td>{input type="number" name="lines[%d][debit]"|args:$line_number min="0.00" step="0.01" value=$line.debit size=5}</td>
					<td>{input type="number" name="lines[%d][credit]"|args:$line_number min="0.00" step="0.01" value=$line.credit size=5}</td>
					<td>{input type="text" name="lines[%d][reference]"|args:$line_number size=10}</td>
					<td>{input type="text" name="lines[%d][label]"|args:$line_number}</td>
					<td>{button label="Enlever la ligne" shape="minus"}</td>
				</tr>
			{/foreach}
			</tbody>
			<tfoot>
				<tr>
					<th></th>
................................................................................
			</tfoot>
		</table>
	</fieldset>

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

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

</form>

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

function initForm() {
	function hideAllTypes() {
		var sections = $('fieldset[data-types]');

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

	function selectType(v) {
		hideAllTypes();
		$('[data-types=' + v + ']')[0].style.display = 'block';
		$('[data-types=all-but-advanced]')[0].style.display = v == 'advanced' ? 'none' : 'block';
	}

	var radios = $('fieldset input[type=radio][name=type]');

	radios.forEach((e) => {
		e.onchange = () => {
			selectType(e.value);


		};
	});

	hideAllTypes();

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

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

	function initLine(e) {
		e.querySelector('button:nth-child(1)').onclick = () => {
			var count = $('.transaction-lines tbody tr').length;

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

7
8
9
10
11
12
13




14
15
16
17
18
19
20
21

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

$chart = $year->chart();
$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');







>
>
>
>






|

7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25

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

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

$transaction = new Transaction;

if (f('save')) {
    $transaction->import();
}

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

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

$tpl->assign('analytical_accounts', ['label' => '-- Aucun'] + $accounts->listAnalytical());
$tpl->display('acc/transactions/new.tpl');

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

373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
...
872
873
874
875
876
877
878
879

880
881
882
883
884
885
886
}

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

form .input-list span.label {
    padding: .4rem .6rem;
}

................................................................................

h2.ruler:after {
    left: 0.5em;
    margin-right: -50%;
}

.icn-btn {
    border: 1px solid #fff;

    font-size: inherit;
    border-radius: .2em;
    padding: .2em .4em;
    margin: .2em .5em;
    display: inline-block;
    background-color: rgba(var(--gSecondColor), 0.1);
    text-shadow: none;







<







 







|
>







373
374
375
376
377
378
379

380
381
382
383
384
385
386
...
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
}

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

    min-width: 0;
}

form .input-list span.label {
    padding: .4rem .6rem;
}

................................................................................

h2.ruler:after {
    left: 0.5em;
    margin-right: -50%;
}

.icn-btn {
    border: 1px solid #9c4f15;
    border-color: rgba(var(--gSecondColor), 0.5);
    font-size: inherit;
    border-radius: .2em;
    padding: .2em .4em;
    margin: .2em .5em;
    display: inline-block;
    background-color: rgba(var(--gSecondColor), 0.1);
    text-shadow: none;