Garradin Plugins

Check-in [de92b13f21]
Login

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix + détails
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA1: de92b13f21eb938a5e4bda125a7931cd2af5bb6d
User & Date: bohwaz 2020-05-22 21:59:18
Context
2020-05-22
22:39
Numéro de note et liste multi-ligne check-in: 8de2d829b4 user: bohwaz tags: trunk
21:59
Fix + détails check-in: de92b13f21 user: bohwaz tags: trunk
01:04
Ajout catégorie check-in: 1038686ea1 user: bohwaz tags: trunk
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to caisse/lib/Session.php.

86
87
88
89
90
91
92


















93
94
95
96
97
98
99

	public function listTabsTotals()
	{
		return DB::getInstance()->get(POS::sql('SELECT *,
			(SELECT SUM(qty * price) FROM @PREFIX_tabs_items WHERE tab = t.id) AS total
			FROM @PREFIX_tabs t WHERE session = ? ORDER BY opened;'), $this->id);
	}



















	public function listTotalsByCategory()
	{
		return DB::getInstance()->get(POS::sql('SELECT
			SUM(ti.qty * ti.price) AS total,
			c.name
			FROM @PREFIX_tabs_items ti







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







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

	public function listTabsTotals()
	{
		return DB::getInstance()->get(POS::sql('SELECT *,
			(SELECT SUM(qty * price) FROM @PREFIX_tabs_items WHERE tab = t.id) AS total
			FROM @PREFIX_tabs t WHERE session = ? ORDER BY opened;'), $this->id);
	}

	public function listTabsWithItems()
	{
		$db = DB::getInstance();
		$tabs = $db->get(POS::sql('SELECT *, total - paid AS remainder
			FROM (SELECT *,
				(SELECT SUM(qty * price) FROM @PREFIX_tabs_items WHERE tab = t.id) AS total,
				(SELECT SUM(amount) FROM @PREFIX_tabs_payments WHERE tab = t.id) AS paid
				FROM @PREFIX_tabs t WHERE session = ? ORDER BY opened
			);'), $this->id);

		foreach ($tabs as &$tab) {
			$t = new Tab($tab->id);
			$tab->items = $t->listItems();
		}

		return $tabs;
	}

	public function listTotalsByCategory()
	{
		return DB::getInstance()->get(POS::sql('SELECT
			SUM(ti.qty * ti.price) AS total,
			c.name
			FROM @PREFIX_tabs_items ti

Changes to caisse/lib/Tab.php.

5
6
7
8
9
10
11
12
13
14
15

16
17
18
19
20
21

22
23
24
25
26
27
28
use Garradin\DB;
use Garradin\UserException;

class Tab
{
	public $id;

	public function __construct(int $id)
	{
		$this->id = $id;


		$sql = POS::sql('SELECT *,
			COALESCE((SELECT SUM(qty*price) FROM @PREFIX_tabs_items WHERE tab = @PREFIX_tabs.id), 0) AS total
			FROM @PREFIX_tabs WHERE id = ?;');

		foreach (DB::getInstance()->first($sql, $id) as $key => $value) {
			$this->$key = $value;

		}
	}

	public function getRemainder(): int
	{
		return (int) DB::getInstance()->firstColumn(POS::sql('SELECT
			(SELECT SUM(price * qty) FROM @PREFIX_tabs_items WHERE tab = ?)







|



>
|
|
|

|
|
>







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
use Garradin\DB;
use Garradin\UserException;

class Tab
{
	public $id;

	public function __construct(int $id, bool $fetch = true)
	{
		$this->id = $id;

		if ($fetch) {
			$sql = POS::sql('SELECT *,
				COALESCE((SELECT SUM(qty*price) FROM @PREFIX_tabs_items WHERE tab = @PREFIX_tabs.id), 0) AS total
				FROM @PREFIX_tabs WHERE id = ?;');

			foreach (DB::getInstance()->first($sql, $id) as $key => $value) {
				$this->$key = $value;
			}
		}
	}

	public function getRemainder(): int
	{
		return (int) DB::getInstance()->firstColumn(POS::sql('SELECT
			(SELECT SUM(price * qty) FROM @PREFIX_tabs_items WHERE tab = ?)

Changes to caisse/templates/session.tpl.

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
...
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
{include file="admin/_head.tpl" current="plugin_%s"|args:$plugin.id}

<h3>{$title}</h3>

<h2 class="ruler">Notes</h2>


<table class="list">
	<thead>
		<tr>
			<td>N°</td>
			<th>Note</th>
			<td>Total</td>
			<td></td>
		</tr>
	</thead>
	<tbody>
		{foreach from=$tabs item="tab"}
		<tr>
			<td>{$tab.id}</td>
			<th>
				{$tab.opened|date_format:"%H:%M"}
				{if $tab.closed}
				&rarr; {$tab.closed|date_format:"%H:%M"}
				{/if}
				— {$tab.name}
			</th>
			<td>

				{$tab.total|raw|pos_money}


			</td>
			<td class="actions"><span class="noprint"><a href="tab.php?id={$tab.id}" class="icn" title="Détails">𝍢</a></span></td>


		</tr>

		{/foreach}
	</tbody>
	<tfoot>
		<tr>
			<td></td>
			<th>Total</th>
			<td>{$total|raw|pos_money}</td>
			<td></td>
		</tr>
	</tfoot>
</table>


<h2 class="ruler">Règlements</h2>

<table class="list">
	<thead>
		<tr>
			<td>Note n°</td>
................................................................................
			</td>
			<td></td>
		</tr>
		{/foreach}
	</tbody>
</table>

{if $pos_session.opened && !$pos_session.closed}

<form method="post" action="">
<fieldset>

	<legend>Clôturer la caisse</legend>
	<dl>
		<dt>Ouverture</dt>











		<dd>{$pos_session.opened|date_format:"%d/%m/%Y à %H:%M"}</dd>
		<dt>Solde à l'ouverture</dt>






		<dd>{$pos_session.open_amount|raw|pos_money}</dd>
		<dt>Solde de la caisse à la clôture</dt>
		<dd><input type="text" pattern="\d+(,\d+)?" name="amount" id="f_amount" size="5" placeholder="42,32" />&nbsp;€</dd>
	</dl>
	<p class="submit">
		<input type="submit" name="close" value="Clôturer la caisse" />

	</p>
</fieldset>
</form>

















{/if}


































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




<

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







 







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

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

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
..
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
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
{include file="admin/_head.tpl" current="plugin_%s"|args:$plugin.id}

<h3>{$title}</h3>



{if $pos_session.opened && !$pos_session.closed}
<form method="post" action="" class="noprint">
<fieldset>
	<legend>Clôturer la caisse</legend>
	<dl>
		<dt>Ouverture</dt>









		<dd>{$pos_session.opened|date_format:"%d/%m/%Y à %H:%M"}</dd>






		<dt>Solde à l'ouverture</dt>
		<dd>{$pos_session.open_amount|raw|pos_money}</dd>
		<dt>Solde de la caisse à la clôture</dt>
		<dd><input type="text" pattern="\d+(,\d+)?" name="amount" id="f_amount" size="5" placeholder="42,32" />&nbsp;€</dd>
	</dl>

	<p class="submit">
		<input type="submit" name="close" value="Clôturer la caisse" />
	</p>
</fieldset>
</form>










{/if}

<h2 class="ruler">Règlements</h2>

<table class="list">
	<thead>
		<tr>
			<td>Note n°</td>
................................................................................
			</td>
			<td></td>
		</tr>
		{/foreach}
	</tbody>
</table>



<h2 class="ruler">Notes</h2>


<table class="list">
	<thead>
		<tr>
			<td>N°</td>
			<th>Note</th>
			<td>Total</td>
			<td></td>
		</tr>
	</thead>
	<tbody>
		{foreach from=$tabs item="tab"}
		<tr>
			<td>{$tab.id}</td>
			<th>
				{$tab.opened|date_format:"%H:%M"}

				{if $tab.closed}
				&rarr; {$tab.closed|date_format:"%H:%M"}
				{/if}
				— {$tab.name}
			</th>
			<td>
				{$tab.total|raw|pos_money}


			</td>


			<td class="actions"><span class="noprint"><a href="tab.php?id={$tab.id}" class="icn" title="Détails">𝍢</a></span></td>
		</tr>

		{/foreach}
	</tbody>
	<tfoot>
		<tr>
			<td></td>
			<th>Total</th>
			<td>{$total|raw|pos_money}</td>
			<td></td>
		</tr>
	</tfoot>
</table>

{foreach from=$tabs item="tab"}

	<h2 class="ruler">Note n°{$tab.id}&nbsp;:
		{$tab.opened|date_format:"%H:%M"}
		{if $tab.closed}
		&rarr; {$tab.closed|date_format:"%H:%M"}
		{/if}
		— {$tab.name}
	</h2>

	<section class="items">
		<table class="list">
			<thead>
				<th></th>
				<td>Qté</td>
				<td>Prix</td>
				<td>Total</td>
			</thead>
			<tbody>
			{foreach from=$tab.items item="item"}
			<tr>
				<th><small class="cat">{$item.category}</small> {$item.name}</th>
				<td>{$item.qty}</td>
				<td>{$item.price|raw|pos_money}</td>
				<td>{$item.total|raw|pos_money}</td>
			</tr>
			{/foreach}
			</tbody>
			<tfoot>
				<tr>
					<th>Total</th>
					<td></td>
					<td></td>
					<td colspan="2">{$tab.total|raw|pos_money}</td>
				</tr>
			</tfoot>
		</table>
	</section>

{/foreach}

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

Changes to caisse/www/admin/_inc.php.

6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

function reload() {
	Utils::redirect(Utils::getSelfURL(true));
}

function get_amount(string $amount): int {
	$a = preg_replace('/[^\d,]/', '', $amount);
	$a = explode('.', $a);
	$a = sprintf('%d%02d', $a[0], @$a[1]);
	return $a;
}

function pos_amount(int $a): string {
	return sprintf("%d,%02d", (int) ($a/100), (int) ($a%100));
}







|







6
7
8
9
10
11
12
13
14
15
16
17
18
19
20

function reload() {
	Utils::redirect(Utils::getSelfURL(true));
}

function get_amount(string $amount): int {
	$a = preg_replace('/[^\d,]/', '', $amount);
	$a = explode(',', $a);
	$a = sprintf('%d%02d', $a[0], @$a[1]);
	return $a;
}

function pos_amount(int $a): string {
	return sprintf("%d,%02d", (int) ($a/100), (int) ($a%100));
}

Changes to caisse/www/admin/session.php.

26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
}

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

if ($pos_session) {
	$tpl->assign('payments', $pos_session->listPayments());
	$tpl->assign('payments_totals', $pos_session->listPaymentTotals());
	$tpl->assign('tabs', $pos_session->listTabsTotals());
	$tpl->assign('totals_categories', $pos_session->listTotalsByCategory());
	$tpl->assign('total', $pos_session->getTotal());

	$tpl->assign('title', 'Session de caisse du ' . Utils::sqliteDateToFrench($pos_session->opened));
	$tpl->display(PLUGIN_ROOT . '/templates/session.tpl');
}
else {
	$tpl->display(PLUGIN_ROOT . '/templates/session_open.tpl');
}







|









26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
}

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

if ($pos_session) {
	$tpl->assign('payments', $pos_session->listPayments());
	$tpl->assign('payments_totals', $pos_session->listPaymentTotals());
	$tpl->assign('tabs', $pos_session->listTabsWithItems());
	$tpl->assign('totals_categories', $pos_session->listTotalsByCategory());
	$tpl->assign('total', $pos_session->getTotal());

	$tpl->assign('title', 'Session de caisse du ' . Utils::sqliteDateToFrench($pos_session->opened));
	$tpl->display(PLUGIN_ROOT . '/templates/session.tpl');
}
else {
	$tpl->display(PLUGIN_ROOT . '/templates/session_open.tpl');
}