BbcMonthlyFlightsBillCron::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
nc 1
nop 1
dl 0
loc 10
rs 9.9332
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
     * @throws Exception
51
     */
52
    public function run()
53
    {
54
        dol_syslog('Monthly bill generation : Start');
55
56
        try {
57
58
            if(date('d')>=15){
59
                dol_syslog('Monthly bill generation : date over');
60
                return -2;
61
            }
62
63
            $command = new CreateMonthBillCommand(0, '', '', date('Y'), (date('m') - 1));
64
            $this->handler->handle($command);
65
66
            dol_syslog('Monthly bill generation : OK');
67
            return 0;
68
69
        } catch (Exception $e) {
70
            dol_syslog($e->getMessage(), LOG_ERR);
71
            dol_syslog('Monthly bill generation : NOK');
72
            return -1;
73
        }
74
    }
75
76
}