Completed
Pull Request — master (#6)
by Laurent
03:31 queued 01:45
created

BbcMonthlyFlightsBillCron::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 7
nc 1
nop 1
dl 0
loc 10
rs 9.4285
c 0
b 0
f 0
1
<?php
2
3
require_once __DIR__ . '/../../command/CreateMonthBillCommandHandler.php';
4
require_once __DIR__ . '/../../command/CreateMonthBillCommand.php';
5
6
/**
7
 * @author Laurent De Coninck <[email protected]>
8
 */
9
class BbcMonthlyFlightsBillCron
10
{
11
12
    /**
13
     * @var DoliDB
14
     */
15
    private $db;
16
17
    /**
18
     * @var stdClass
19
     */
20
    private $conf;
21
22
    private $langs;
23
24
    private $user;
25
26
    /**
27
     * @var CreateMonthBillCommandHandler
28
     */
29
    private $handler;
30
31
    /**
32
     * @param DoliDB $db
33
     */
34
    public function __construct($db)
35
    {
36
        global $conf, $langs, $user;
37
38
        $this->db = $db;
39
        $this->conf = $conf->global;
40
        $this->langs = $langs;
41
        $this->user = $user;
42
        $this->handler = new CreateMonthBillCommandHandler($this->db, $this->conf, $this->user, $this->langs);
43
    }
44
45
    /**
46
     * Run the cron job.
47
     *
48
     * @return int <0 if error
49
     */
50
    public function run()
51
    {
52
        dol_syslog('Monthly bill generation : Start');
53
54
        try {
55
56
            if(date('d')>=15){
57
                dol_syslog('Monthly bill generation : date over');
58
                return -2;
59
            }
60
61
            $command = new CreateMonthBillCommand(0, '', '', date('Y'), (date('m') - 1));
62
            $this->handler->handle($command);
63
64
            dol_syslog('Monthly bill generation : OK');
65
            return 0;
66
67
        } catch (Exception $e) {
68
            dol_syslog($e->getMessage(), LOG_ERR);
69
            dol_syslog('Monthly bill generation : NOK');
70
            return -1;
71
        }
72
    }
73
74
}