Overview
Comment:Saving a service for a user is working \o/
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: c4ed8acc1dbb2e561c6d6c819299fcc9e20b0173
User & Date: bohwaz on 2020-11-07 17:01:56
Other Links: branch diff | manifest | tags
Context
2020-11-07
20:19
Fix user details page, display number of services check-in: e9afce499d user: bohwaz tags: dev
17:01
Saving a service for a user is working \o/ check-in: c4ed8acc1d user: bohwaz tags: dev
16:48
Make sure either both id_year and id_account are null, or both of them are filled check-in: 5ffcc01335 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Entities/Services/Service_User.php from [acc90e2331] to [01f53898cb].

114
115
116
117
118
119
120
121

122


			$transaction->importFromNewForm($source);
			$transaction->save();
			$transaction->linkToUser($su->id_user, $su->id());
		}

		$db->commit();
	}

}








|
>
|
>
114
115
116
117
118
119
120
121
122
123
124

			$transaction->importFromNewForm($source);
			$transaction->save();
			$transaction->linkToUser($su->id_user, $su->id());
		}

		$db->commit();

		return $su;
	}
}

Modified src/templates/services/save.tpl from [bf6b80053a] to [972b3293ea].

5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
..
90
91
92
93
94
95
96

97



98
99
100
101
102
103
104
{form_errors}

<form method="post" action="{$self_url}" data-focus="1">

	<fieldset>
		<legend>Enregistrer une activité</legend>

{if !$selected_user}
		<dl>
			{input type="list" name="user" required=1 label="Sélectionner un membre" default=$selected_user target="membres/selector.php"}
		</dl>
{else}
		<dl>
			<dt>Membre sélectionné</dt>
			<dd><h3>{$user_name}</h3><input type="hidden" name="id_user" value="{$user_id}" /></dd>
................................................................................
			{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>
{/if}
	</fieldset>

	<p class="submit">
		{csrf_field key=$csrf_key}

		<input type="submit" name="save" value="Enregistrer &rarr;" />



	</p>

</form>

{literal}
<script type="text/javascript">
function selectService(elm) {







|







 







>
|
>
>
>







5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
..
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
{form_errors}

<form method="post" action="{$self_url}" data-focus="1">

	<fieldset>
		<legend>Enregistrer une activité</legend>

{if !$user_id}
		<dl>
			{input type="list" name="user" required=1 label="Sélectionner un membre" default=$selected_user target="membres/selector.php"}
		</dl>
{else}
		<dl>
			<dt>Membre sélectionné</dt>
			<dd><h3>{$user_name}</h3><input type="hidden" name="id_user" value="{$user_id}" /></dd>
................................................................................
			{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>
{/if}
	</fieldset>

	<p class="submit">
		{csrf_field key=$csrf_key}
		{if $user_id}
			<input type="submit" name="save" value="Enregistrer &rarr;" />
		{else}
			<input type="submit" name="next" value="Continuer &rarr;" />
		{/if}
	</p>

</form>

{literal}
<script type="text/javascript">
function selectService(elm) {

Modified src/www/admin/services/save.php from [58f5e92f69] to [31cc1e68ef].

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
use Garradin\Entities\Accounting\Account;
use Garradin\Entities\Accounting\Transaction;

require_once __DIR__ . '/_inc.php';

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











$user_id = (int) qg('user') ?: null;
$user_name = $user_id ? (new Membres)->getNom($user_id) : null;

$grouped_services = Services::listGroupedWithFees($user_id);

if (!count($grouped_services)) {
	Utils::redirect(ADMIN_URL . 'services/?CREATE');
}

$csrf_key = 'service_save';

$form->runIf('save', function () use ($session) {
	$su = new Service_User;
	$su->saveFromForm($session->getUser()->id);

	Utils::redirect(ADMIN_URL . 'services/user.php?id=' . $su->id_user);
}, $csrf_key);

$selected_user = $user_id ? [$user_id => $user_name] : null;

$types_details = Transaction::getTypesDetails();
$account_targets = $types_details[Transaction::TYPE_REVENUE]->accounts[1]->targets_string;

$tpl->assign(compact('grouped_services', 'csrf_key', 'selected_user', 'account_targets', 'user_name', 'user_id'));

$tpl->display('services/save.tpl');







>
>
>
>
>
>
>
>
>
>
|











<
|




|







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
use Garradin\Entities\Accounting\Account;
use Garradin\Entities\Accounting\Transaction;

require_once __DIR__ . '/_inc.php';

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

$user_id = qg('user');

if (!$user_id && ($user_id = f('user'))) {
	$user_id = @key($user_id);
}

if (!$user_id) {
	$user_id = f('id_user');
}

$user_id = (int) $user_id ?: null;
$user_name = $user_id ? (new Membres)->getNom($user_id) : null;

$grouped_services = Services::listGroupedWithFees($user_id);

if (!count($grouped_services)) {
	Utils::redirect(ADMIN_URL . 'services/?CREATE');
}

$csrf_key = 'service_save';

$form->runIf('save', function () use ($session) {

	$su = Service_User::saveFromForm($session->getUser()->id);

	Utils::redirect(ADMIN_URL . 'services/user.php?id=' . $su->id_user);
}, $csrf_key);

$selected_user = $user_name ? [$user_id => $user_name] : null;

$types_details = Transaction::getTypesDetails();
$account_targets = $types_details[Transaction::TYPE_REVENUE]->accounts[1]->targets_string;

$tpl->assign(compact('grouped_services', 'csrf_key', 'selected_user', 'account_targets', 'user_name', 'user_id'));

$tpl->display('services/save.tpl');