| 1 |  |  | <?php | 
            
                                                                                                            
                            
            
                                    
            
            
                | 2 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 3 |  |  | require_once __DIR__ . '/CommandHandlerInterface.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 4 |  |  | require_once __DIR__ . '/CommandInterface.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 5 |  |  | require_once __DIR__ . '/CreateOrderCommand.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 6 |  |  | require_once __DIR__ . '/../../societe/class/societe.class.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 7 |  |  | require_once __DIR__ . '/../../commande/class/commande.class.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 8 |  |  | require_once __DIR__ . '/../../product/class/product.class.php'; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 9 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 10 |  |  | /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 11 |  |  |  * CreateOrderCommandHandler class | 
            
                                                                                                            
                            
            
                                    
            
            
                | 12 |  |  |  * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 13 |  |  |  * @author Laurent De Coninck <[email protected]> | 
            
                                                                                                            
                            
            
                                    
            
            
                | 14 |  |  |  */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 15 |  |  | class CreateOrderCommandHandler implements CommandHandlerInterface | 
            
                                                                                                            
                            
            
                                    
            
            
                | 16 |  |  | { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 17 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 18 |  |  |      * @var DoliDB | 
            
                                                                                                            
                            
            
                                    
            
            
                | 19 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 20 |  |  |     private $db; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 21 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 22 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 23 |  |  |      * @var stdClass | 
            
                                                                                                            
                            
            
                                    
            
            
                | 24 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 25 |  |  |     private $conf; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 26 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 27 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 28 |  |  |      * @var User | 
            
                                                                                                            
                            
            
                                    
            
            
                | 29 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 30 |  |  |     private $user; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 31 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 32 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 33 |  |  |      * @var Translate | 
            
                                                                                                            
                            
            
                                    
            
            
                | 34 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 35 |  |  |     private $langs; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 36 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 37 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 38 |  |  |      * @var ModeleThirdPartyCode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 39 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 40 |  |  |     private $codeFournisseurGenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 41 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 42 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 43 |  |  |      * @var ModeleThirdPartyCode | 
            
                                                                                                            
                            
            
                                    
            
            
                | 44 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 45 |  |  |     private $codeClientGenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 46 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 47 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 48 |  |  |      * @var Societe | 
            
                                                                                                            
                            
            
                                    
            
            
                | 49 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 50 |  |  |     private $societe; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 51 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 52 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 53 |  |  |      * @var Commande | 
            
                                                                                                            
                            
            
                                    
            
            
                | 54 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 55 |  |  |     private $order; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 56 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 57 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 58 |  |  |      * @param DoliDB $db | 
            
                                                                                                            
                            
            
                                    
            
            
                | 59 |  |  |      * @param stdClass $conf | 
            
                                                                                                            
                            
            
                                    
            
            
                | 60 |  |  |      * @param User $user | 
            
                                                                                                            
                            
            
                                    
            
            
                | 61 |  |  |      * @param Translate $langs | 
            
                                                                                                            
                            
            
                                    
            
            
                | 62 |  |  |      * @param ModeleThirdPartyCode $codeClientGenerator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 63 |  |  |      * @param ModeleThirdPartyCode $codeFounrisseurGenerator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 64 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 65 |  |  |     public function __construct( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 66 |  |  |         $db, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 67 |  |  |         $conf, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 68 |  |  |         $user, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 69 |  |  |         $langs, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 70 |  |  |         ModeleThirdPartyCode $codeClientGenerator, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 71 |  |  |         ModeleThirdPartyCode $codeFounrisseurGenerator | 
            
                                                                                                            
                            
            
                                    
            
            
                | 72 |  |  |     ) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 73 |  |  |         $this->db = $db; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 74 |  |  |         $this->conf = $conf->global; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 75 |  |  |         $this->user = $user; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 76 |  |  |         $this->langs = $langs; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 77 |  |  |         $this->codeClientGenerator = $codeClientGenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 78 |  |  |         $this->codeFournisseurGenerator = $codeFounrisseurGenerator; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 79 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 80 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 81 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 82 |  |  |      * @param CreateOrderCommand|CommandInterface $command | 
            
                                                                                                            
                            
            
                                    
            
            
                | 83 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 84 |  |  |      * @throws Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 85 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 86 |  |  |     public function handle(CommandInterface $command) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 87 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 88 |  |  |         $customerId = $this->createCustomer($command)->id; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 89 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 90 |  |  |         $this->createOrder($command, $customerId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 91 |  |  |             ->addLine($command) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 92 |  |  |             ->addContacts() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 93 |  |  |             ->validateOrder(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 94 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 95 |  |  |         $this->order->generateDocument('einstein', $this->langs); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 96 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 97 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 98 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 99 |  |  |      * @return Product | 
            
                                                                                                            
                            
            
                                    
            
            
                | 100 |  |  |      */ | 
            
                                                                                                            
                            
            
                                                                    
                                                                                                        
            
            
                | 101 |  | View Code Duplication |     private function getProduct() | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 102 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 103 |  |  |         $flightProduct = new Product($this->db); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 104 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 105 |  |  |         if ($flightProduct->fetch($this->conf->BBC_FLIGHT_TYPE_CUSTOMER) <= 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 106 |  |  |             throw new \InvalidArgumentException('Default product not configured'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 107 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 108 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 109 |  |  |         return $flightProduct; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 110 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 111 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 112 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 113 |  |  |      * @param Product $flightProduct | 
            
                                                                                                            
                            
            
                                    
            
            
                | 114 |  |  |      * @param float|int $pricePerPax | 
            
                                                                                                            
                            
            
                                    
            
            
                | 115 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 116 |  |  |      * @return float|int | 
            
                                                                                                            
                            
            
                                    
            
            
                | 117 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 118 |  |  |     private function computeDiscounts($flightProduct, $pricePerPax = 0) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 119 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 120 |  |  |         return ($flightProduct->price_ttc - ($pricePerPax)) * 100 / $flightProduct->price_ttc; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 121 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 122 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 123 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 124 |  |  |      * @param CommandInterface|CreateOrderCommand $command | 
            
                                                                                                            
                            
            
                                    
            
            
                | 125 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 126 |  |  |      * @return Societe | 
            
                                                                                                            
                            
            
                                    
            
            
                | 127 |  |  |      * @throws Exception | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 128 |  |  |      */ | 
            
                                                                        
                            
            
                                    
            
            
                | 129 |  |  |     private function createCustomer(CommandInterface $command) | 
            
                                                                        
                            
            
                                    
            
            
                | 130 |  |  |     { | 
            
                                                                        
                            
            
                                    
            
            
                | 131 |  |  |         $this->societe = new Societe($this->db); | 
            
                                                                        
                            
            
                                    
            
            
                | 132 |  |  |         if ($command->hasSocId()) { | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 133 |  |  |             $this->societe->fetch($command->getSocid()); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 134 |  |  |             return $this->societe; | 
            
                                                                        
                            
            
                                    
            
            
                | 135 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 136 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 137 |  |  |         $name = $command->getName() . ' ' . $command->getFirstname(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 138 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 139 |  |  |         $existingCustomers = $this->societe->fetch(null, $name); | 
            
                                                                        
                            
            
                                    
            
            
                | 140 |  |  |         if ($existingCustomers > 0) { | 
            
                                                                        
                            
            
                                    
            
            
                | 141 |  |  |             $this->societe = $existingCustomers[0]; | 
            
                                                                        
                            
            
                                    
            
            
                | 142 |  |  |             return $this->societe; | 
            
                                                                        
                            
            
                                    
            
            
                | 143 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 144 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 145 |  |  |         $this->societe->particulier = 1; | 
            
                                                                        
                            
            
                                    
            
            
                | 146 |  |  |         $this->societe->name = $name; | 
            
                                                                        
                            
            
                                    
            
            
                | 147 |  |  |         $this->societe->civility_id = $command->getCivilityId(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 148 |  |  |         $this->societe->name_bis = $command->getName(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 149 |  |  |         $this->societe->firstname = $command->getFirstname(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 150 |  |  |         $this->societe->entity = $this->conf->entity; | 
            
                                                                        
                            
            
                                    
            
            
                | 151 |  |  |         $this->societe->name_alias = ''; | 
            
                                                                        
                            
            
                                    
            
            
                | 152 |  |  |         $this->societe->address = GETPOST('address'); | 
            
                                                                        
                            
            
                                    
            
            
                | 153 |  |  |         $this->societe->zip = $command->getZip(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 154 |  |  |         $this->societe->town = $command->getTown(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 155 |  |  |         $this->societe->country_id = 2; | 
            
                                                                        
                            
            
                                    
            
            
                | 156 |  |  |         $this->societe->state_id = $command->getState(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 157 |  |  |         $this->societe->phone = $command->getPhone(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 158 |  |  |         $this->societe->email = $command->getEmail(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 159 |  |  |         $this->societe->code_client = $this->codeClientGenerator->getNextValue($this->societe, 0); | 
            
                                                                        
                            
            
                                    
            
            
                | 160 |  |  |         $this->societe->code_fournisseur = $this->codeFournisseurGenerator->getNextValue($this->societe, 1); | 
            
                                                                        
                            
            
                                    
            
            
                | 161 |  |  |         $this->societe->tva_intra = $command->getTva(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 162 |  |  |         $this->societe->tva_assuj = empty($command->getTva()) ? 0 : 1; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 163 |  |  |         $this->societe->status = 1; | 
            
                                                                        
                            
            
                                    
            
            
                | 164 |  |  |         $this->societe->client = 3; //prospect + customer | 
            
                                                                        
                            
            
                                    
            
            
                | 165 |  |  |         $this->societe->fournisseur = 0; | 
            
                                                                        
                            
            
                                    
            
            
                | 166 |  |  |         $this->societe->commercial_id = $this->user->id; | 
            
                                                                        
                            
            
                                    
            
            
                | 167 |  |  |         $this->societe->default_lang = $command->getLanguage(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                        
                            
            
                                    
            
            
                | 168 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 169 |  |  |         $customerId = $this->societe->create($this->user); | 
            
                                                                        
                            
            
                                    
            
            
                | 170 |  |  |         if ($customerId < 0) { | 
            
                                                                        
                            
            
                                    
            
            
                | 171 |  |  |             throw new Exception($this->societe->errorsToString(), $customerId); | 
            
                                                                        
                            
            
                                    
            
            
                | 172 |  |  |         } | 
            
                                                                        
                            
            
                                    
            
            
                | 173 |  |  |  | 
            
                                                                        
                            
            
                                    
            
            
                | 174 |  |  |         return $this->societe; | 
            
                                                                        
                            
            
                                    
            
            
                | 175 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 176 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 177 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 178 |  |  |      * @param CommandInterface|CreateOrderCommand $command | 
            
                                                                                                            
                            
            
                                    
            
            
                | 179 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 180 |  |  |      * @return CreateOrderCommandHandler | 
            
                                                                                                            
                            
            
                                    
            
            
                | 181 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 182 |  |  |     private function addLine(CommandInterface $command) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 183 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 184 |  |  |         $product = $this->getProduct(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 185 |  |  |         $pu_ht = price2num($product->price, 'MU'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 186 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 187 |  |  |         $this->order->addline( | 
            
                                                                                                            
                            
            
                                    
            
            
                | 188 |  |  |             '', | 
            
                                                                                                            
                            
            
                                    
            
            
                | 189 |  |  |             $pu_ht, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 190 |  |  |             $command->getNbrPax(), | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 191 |  |  |             $product->tva_tx, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 192 |  |  |             0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 193 |  |  |             0, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 194 |  |  |             $product->id, | 
            
                                                                                                            
                            
            
                                    
            
            
                | 195 |  |  |             $this->computeDiscounts($product, ($command->getCost() / $command->getNbrPax())) | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 196 |  |  |         ); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 197 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 198 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 199 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 200 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 201 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 202 |  |  |      * @param CommandInterface|CreateOrderCommand $command | 
            
                                                                                                            
                            
            
                                    
            
            
                | 203 |  |  |      * @param int $customerId | 
            
                                                                                                            
                            
            
                                    
            
            
                | 204 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 205 |  |  |      * @return $this | 
            
                                                                                                            
                            
            
                                    
            
            
                | 206 |  |  |      * @throws Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 207 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 208 |  |  |     private function createOrder(CommandInterface $command, $customerId) | 
            
                                                                                                            
                            
            
                                    
            
            
                | 209 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 210 |  |  |         $this->order = new Commande($this->db); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 211 |  |  |         $this->order->note_public = $command->isCommentPublic() ? $command->getComment() : ''; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 212 |  |  |         $this->order->note_private = $command->isCommentPublic() ? $command->getComment() : ''; | 
                            
                    |  |  |  | 
                                                                                        
                                                                                            
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 213 |  |  |         $this->order->socid = $customerId; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 214 |  |  |         $this->order->cond_reglement_id = 1; // reception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 215 |  |  |         $this->order->mode_reglement_id = 2; //virement | 
            
                                                                                                            
                            
            
                                    
            
            
                | 216 |  |  |         $this->order->demand_reason_id = $command->getOrigine(); | 
                            
                    |  |  |  | 
                                                                                        
                                                                                     | 
            
                                                                                                            
                            
            
                                    
            
            
                | 217 |  |  |         $this->order->date = time(); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 218 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 219 |  |  |         $orderId = $this->order->create($this->user); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 220 |  |  |         if ($orderId <= 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 221 |  |  |             throw new Exception('Exception during the order creation'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 222 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 223 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 224 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 225 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 226 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 227 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 228 |  |  |      * Validate the order | 
            
                                                                                                            
                            
            
                                    
            
            
                | 229 |  |  |      * | 
            
                                                                                                            
                            
            
                                    
            
            
                | 230 |  |  |      * @throws Exception | 
            
                                                                                                            
                            
            
                                    
            
            
                | 231 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 232 |  |  |     private function validateOrder() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 233 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 234 |  |  |         if ($this->order->valid($this->user) < 0) { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 235 |  |  |             throw new Exception('Validation of order failed'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 236 |  |  |         } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 237 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 238 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 239 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 240 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 241 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 242 |  |  |      * Add sales contact | 
            
                                                                                                            
                            
            
                                    
            
            
                | 243 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 244 |  |  |     private function addContacts() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 245 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 246 |  |  |         $this->order->add_contact($this->user->id, 91, 'internal'); | 
            
                                                                                                            
                            
            
                                    
            
            
                | 247 |  |  |         return $this; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 248 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 249 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 250 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 251 |  |  |      * @return Societe | 
            
                                                                                                            
                            
            
                                    
            
            
                | 252 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 253 |  |  |     public function getCustomer() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 254 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 255 |  |  |         return $this->societe; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 256 |  |  |     } | 
            
                                                                                                            
                            
            
                                    
            
            
                | 257 |  |  |  | 
            
                                                                                                            
                            
            
                                    
            
            
                | 258 |  |  |     /** | 
            
                                                                                                            
                            
            
                                    
            
            
                | 259 |  |  |      * @return Commande | 
            
                                                                                                            
                            
            
                                    
            
            
                | 260 |  |  |      */ | 
            
                                                                                                            
                            
            
                                    
            
            
                | 261 |  |  |     public function getOrder() | 
            
                                                                                                            
                            
            
                                    
            
            
                | 262 |  |  |     { | 
            
                                                                                                            
                            
            
                                    
            
            
                | 263 |  |  |         return $this->order; | 
            
                                                                                                            
                            
            
                                    
            
            
                | 264 |  |  |     } | 
            
                                                                                                            
                                                                
            
                                    
            
            
                | 265 |  |  |  | 
            
                                                        
            
                                    
            
            
                | 266 |  |  | } | 
            
                        
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.