1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
require_once __DIR__ . '/../class/bbcvols.class.php'; |
4
|
|
|
require_once __DIR__ . '/CreateReceiverMonthBillCommand.php'; |
5
|
|
|
require_once __DIR__ . '/../../product/class/product.class.php'; |
6
|
|
|
require_once __DIR__ . '/../../compta/facture/class/facture.class.php'; |
7
|
|
|
require_once __DIR__ . '/../../user/class/user.class.php'; |
8
|
|
|
require_once __DIR__ . '/../../adherents/class/adherent.class.php'; |
9
|
|
|
require_once __DIR__ . '/AbstractBillCommandHandler.php'; |
10
|
|
|
require_once __DIR__ . '/CommandInterface.php'; |
11
|
|
|
|
12
|
|
|
/** |
13
|
|
|
* @author Laurent De Coninck <[email protected]> |
14
|
|
|
*/ |
15
|
|
|
class CreateReceiverMonthBillCommandHandler extends AbstractBillCommandHandler |
16
|
|
|
{ |
17
|
|
|
|
18
|
|
|
/** |
19
|
|
|
* @param CreateReceiverMonthBillCommand|CommandInterface $command |
20
|
|
|
*/ |
21
|
|
View Code Duplication |
public function handle(CommandInterface $command) |
|
|
|
|
22
|
|
|
{ |
23
|
|
|
$object = new Facture($this->db); |
24
|
|
|
$object->fetch_thirdparty(); |
25
|
|
|
|
26
|
|
|
$object->socid = $this->getCustomer($command->getReceiverId())->id; |
|
|
|
|
27
|
|
|
$object->type = $command->getBillingType(); |
28
|
|
|
$object->number = "provisoire"; |
29
|
|
|
$object->date = $this->generateBillDate($command->getYear(), $command->getMonth()); |
30
|
|
|
$object->date_pointoftax = ""; |
31
|
|
|
$object->note_public = $command->getPublicNote(); |
32
|
|
|
$object->note_private = $command->getPrivateNote(); |
33
|
|
|
$object->ref_client = ""; |
34
|
|
|
$object->ref_int = ""; |
35
|
|
|
$object->modelpdf = $command->getModelDocument(); |
36
|
|
|
$object->cond_reglement_id = $command->getBillingCondition(); |
37
|
|
|
$object->mode_reglement_id = $command->getBillType(); |
38
|
|
|
$object->fk_account = $this->getBankAccount(); |
39
|
|
|
|
40
|
|
|
$id = $object->create($this->user); |
41
|
|
|
|
42
|
|
|
if ($id <= 0) { |
43
|
|
|
throw new \InvalidArgumentException('Error during bill creation'); |
44
|
|
|
} |
45
|
|
|
|
46
|
|
|
$flightProduct = $this->getProduct(); |
47
|
|
|
foreach ($command->getFlights() as $flight) { |
|
|
|
|
48
|
|
|
$this->addOrderLine($object, $flightProduct, $flight); |
49
|
|
|
$this->addLinks($object, $flight); |
50
|
|
|
$this->flagFlightAsBilled($flight); |
51
|
|
|
} |
52
|
|
|
|
53
|
|
|
$this->generateBillDocument($command, $object, $id); |
|
|
|
|
54
|
|
|
|
55
|
|
|
$this->validates($object, $id); |
56
|
|
|
|
57
|
|
|
$this->generateBillDocument($command, $object, $id); |
|
|
|
|
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @return int |
63
|
|
|
*/ |
64
|
|
|
private function getBankAccount() |
65
|
|
|
{ |
66
|
|
|
return $this->conf->BBC_DEFAULT_BANK_ACCOUNT; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* @param int $year |
71
|
|
|
* @param int $month |
72
|
|
|
* |
73
|
|
|
* @return int |
74
|
|
|
*/ |
75
|
|
|
private function generateBillDate($year, $month) |
76
|
|
|
{ |
77
|
|
|
$day = cal_days_in_month(CAL_GREGORIAN, $month, $year); |
78
|
|
|
$date = (new DateTime())->setDate($year, $month, $day); |
79
|
|
|
return $date->getTimestamp(); |
80
|
|
|
} |
81
|
|
|
} |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.