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

BbcMonthlyFlightsBillCron   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 66
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
dl 0
loc 66
rs 10
c 0
b 0
f 0
wmc 4
lcom 1
cbo 2

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
A run() 0 23 3
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
}