Overview
Comment:Débuts classe de gestion des mouvements
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | dev
Files: files | file ages | folders
SHA1: dd86c3907f963d4da6c7a62cae7f69ab90dafad2
User & Date: bohwaz on 2019-02-15 16:32:53
Other Links: branch diff | manifest | tags
Context
2019-02-15
16:33
Débuts de manuel check-in: 82f49f41ab user: bohwaz tags: dev
16:32
Débuts classe de gestion des mouvements check-in: dd86c3907f user: bohwaz tags: dev
16:32
Renommer journal en mouvements check-in: 35af07a502 user: bohwaz tags: dev
Changes

Added src/include/lib/Garradin/Compta/Mouvement.php version [0ef83a74a5].



























































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
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
103
104
105
106
107
108
109
<?php

namespace Garradin\Compta;

use Garradin\Entity;

class Mouvement extends Entity
{
	protected $table = 'compta_mouvements';

	protected $id;
	protected $libelle;
	protected $remarques;
	protected $numero_piece;

	protected $date;
	protected $moyen_paiement;
	protected $numero_cheque;

	protected $validation;

	protected $hash;
	protected $prev_hash;

	protected $id_exercice;
	protected $id_auteur;
	protected $id_categorie;
	protected $id_projet;

	protected $lignes = [];

	public function getLignes()
	{
		$db = DB::getInstance();
		return $db->toObject($db->get('SELECT * FROM compta_mouvements_lignes WHERE id_mouvement = ? ORDER BY id;', $this->id), Ligne::class);
	}

	public function add(Ligne $ligne)
	{
		$this->lignes[] = $ligne;
	}

	public function save()
	{
		if (!parent::save())
		{
			return false;
		}

		foreach ($this->lignes as $ligne)
		{
			$ligne->id_mouvement = $this->id;
			$ligne->save();
		}
	}

	public function validate($key, $value)
	{
		switch ($key)
		{
			case 'date':
				if (!($value instanceof \DateTime))
				{
					throw new ValidationException('La date est invalide.');
				}
				break;
			case 'moyen_paiement':
				if (!$db->test('compta_moyens_paiement', 'code', $value))
				{
					throw new ValidationException('Moyen de paiement inconnu.');
				}
				break;
			case 'id_exercice':
				if (null !== $value && !$db->test('compta_exercices', 'id', $value))
				{
					throw new ValidationException('Numéro d\'exercice invalide.');
				}
				break;
			default:
				break;
		}

		return true;
	}

	public function selfCheck()
	{
		if (trim($this->libelle) === '')
		{
			throw new ValidationException('Le libellé ne peut rester vide.');
		}

		if (null === $this->date)
		{
			throw new ValidationException('Le date ne peut rester vide.');
		}

		if (null === $this->id_exercice && $config->get('compta_expert'))
		{
			throw new ValidationException('Aucun exercice spécifié.');
		}

		if (null !== $this->id_exercice 
			&& !$db->test('compta_exercices', 'id = ? AND debut <= ? AND fin >= ?;', $this->id_exercice, $this->date, $this->date))
		{
			throw new ValidationException('La date ne correspond pas à l\'exercice sélectionné.');
		}
	}
}

Added src/include/lib/Garradin/Entity.php version [885673b2ef].







































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
50
51
<?php

namespace Garradin;

class Entity
{
	protected $id;
	protected $table;

	public function save()
	{
		$db = DB::getInstance();

		if (null === $this->id)
		{
			if ($return = $db->insert($this->table, $this->toArray()))
			{
				$this->id = $db->lastInsertId();
			}
		}
		else
		{
			$return = $db->update($this->table, $this->toArray(), 'id = :id', ['id' => $this->id]);
		}

		return $return;
	}

	public function set($key, $value = null)
	{
		if (is_array($key))
		{
			foreach ($key as $_key => $_value)
			{
				if (!$this->set($_key, $value))
				{
					return false;
				}
			}

			return true;
		}

		$this->$key = $value;
	}

	public function filterUserEntry($key, $value)
	{
		return trim($value);
	}
}