Overview
Comment:Fix issue with single cents
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: 447fa418e527ab44bd8bae250bd2f1ac9742c814
User & Date: bohwaz on 2020-11-09 22:40:31
Other Links: branch diff | manifest | tags
Context
2020-11-09
22:41
Add more test case check-in: 7fc961ba15 user: bohwaz tags: dev
22:40
Fix issue with single cents check-in: 447fa418e5 user: bohwaz tags: dev
22:24
Implement simple tracking of revenue/expense/others check-in: a7bb0c41f4 user: bohwaz tags: dev
Changes

Modified src/include/lib/Garradin/Utils.php from [a268cc4010] to [bc8274f2ad].

120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
            return 0;
        }

        if (!preg_match('/^(\d+)(?:[,.](\d{1,2}))?$/', $value, $match)) {
            throw new UserException('Le format du montant est invalide. Format accepté, exemple : 142,02');
        }

        $value = $match[1] . str_pad((int)@$match[2], 2, '0', STR_PAD_RIGHT);
        $value = (int) $value;
        return $value;
    }

    static public function money_format($number, string $dec_point = ',', string $thousands_sep = ' ', $zero_if_empty = true): string {
        if ($number == 0) {
            return $zero_if_empty ? '0' : '0,00';







|







120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
            return 0;
        }

        if (!preg_match('/^(\d+)(?:[,.](\d{1,2}))?$/', $value, $match)) {
            throw new UserException('Le format du montant est invalide. Format accepté, exemple : 142,02');
        }

        $value = $match[1] . str_pad(@$match[2], 2, '0', STR_PAD_RIGHT);
        $value = (int) $value;
        return $value;
    }

    static public function money_format($number, string $dec_point = ',', string $thousands_sep = ' ', $zero_if_empty = true): string {
        if ($number == 0) {
            return $zero_if_empty ? '0' : '0,00';

Modified tests/run.php from [e0e24bf932] to [9eeba6e792].

1
2



3
4
5
6
7
8
9
10
<?php




require __DIR__ . '/../src/include/init.php';

if (!empty($_SERVER['argv'][1]))
{
	require $_SERVER['argv'][1];
	exit;
}
else


>
>
>
|







1
2
3
4
5
6
7
8
9
10
11
12
13
<?php


define('Garradin\WWW_URI', '/');

const INIT = __DIR__ . '/../src/include/init.php';

if (!empty($_SERVER['argv'][1]))
{
	require $_SERVER['argv'][1];
	exit;
}
else

tests/run.sh became executable with contents [476c017c61].

whitespace changes only

Modified tests/unit_tests/01_basic/db.php from [88dbf0c61d] to [829b0c0b3e].

1
2
3
4
5
6
7

8
9
10
11
12
13
14
15
16
<?php

namespace Garradin;

use KD2\Test;

const DB_FILE = ':memory:';


require __DIR__ . '/../init.php';

$db = DB::getInstance();

// test exec
Test::assert($db->exec('CREATE TABLE test (a, b);'));

// test insert







>

|







1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
<?php

namespace Garradin;

use KD2\Test;

const DB_FILE = ':memory:';
const INSTALL_PROCESS = true;

require INIT;

$db = DB::getInstance();

// test exec
Test::assert($db->exec('CREATE TABLE test (a, b);'));

// test insert

Added tests/unit_tests/02_accounting/money.php version [48f882c475].



























>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
<?php

namespace Garradin;
use KD2\Test;

require INIT;

Test::strictlyEquals(500, Utils::moneyToInteger('5'));
Test::strictlyEquals(442, Utils::moneyToInteger('4,42'));
Test::strictlyEquals(442, Utils::moneyToInteger('4.42'));
Test::strictlyEquals(4, Utils::moneyToInteger('0,04'));
Test::strictlyEquals(30, Utils::moneyToInteger('0,3'));
Test::strictlyEquals(202034, Utils::moneyToInteger('2020,34'));