/**
  * {@inheritdoc}
  */
 public function buildLines()
 {
     $transmitters = $this->attribution->getTransmitters();
     $models = array();
     foreach ($transmitters as $transmitter) {
         $key = $transmitter->getModel()->getId();
         if (!isset($models[$key])) {
             $models[$key] = array('quantity' => 0, 'product' => $transmitter->getModel()->getProduct(), 'numbers' => array());
         }
         $models[$key]['quantity']++;
         $models[$key]['numbers'][] = $transmitter->getNumber();
     }
     //$position = 0;
     // Description des numéros d'émetteurs
     foreach ($models as $key => $values) {
         asort($values['numbers']);
         $description = '';
         $n1 = $temp = $values['numbers'][0];
         $i = 1;
         $size = sizeof($values['numbers']);
         if ($size > 1) {
             do {
                 if ($values['numbers'][$i] != $temp + 1) {
                     $add = $n1 == $temp ? 'n°' . $n1 : 'du n°' . $n1 . ' au n°' . $temp;
                     $description .= $add . chr(10);
                     $n1 = $models[$key]['numbers'][$i];
                 }
                 $temp = $values['numbers'][$i];
                 $i++;
             } while ($i < $size);
             $add = $n1 == $temp ? 'n°' . $n1 : 'du n°' . $n1 . ' au n°' . $temp;
             $description .= $add;
         } else {
             $description .= 'n°' . $n1;
         }
         $line = BillLineFactory::create(new ProductBillLineBuilder($values['product'], $this->vat, $values['quantity'], array('description' => $description)));
         $this->getBill()->addLine($line);
     }
     if (null !== $this->getOption('port')) {
         $line = BillLineFactory::create(new ProductBillLineBuilder($this->getOption('port'), $this->vat, sizeof($transmitters)));
         $line->setQuantity(1);
         $this->getBill()->addLine($line);
     }
 }
 /**
  * @dataProvider builders
  */
 public function testBuilders($method)
 {
     $this->builder->expects($this->once())->method($method);
     $this->line = BillLineFactory::create($this->builder);
 }
 /**
  * {@inheritdoc}
  */
 public function buildLines()
 {
     $periods = array('1' => 'P1Y', '2' => 'P6M', '4' => 'P3M');
     foreach ($this->fee->getContracts() as $key => $contract) {
         $begin = clone $this->follower->getActivation();
         $endContract = $contract->getEnd();
         $end = clone $this->follower->getActivation();
         $end->add(new \DateInterval($periods[$this->fee->getFrequence()]));
         $frequenceString = ' ' . $this->fee->getFrequenceString();
         if ($endContract !== null) {
             if ($endContract < $end) {
                 $end = $endContract;
                 $frequenceString = '';
             }
         }
         $product = $this->getOption('product');
         $diff = $end->diff($begin);
         $rapport = ($diff->format('%m') + 12 * $diff->format('%y')) / 12;
         $fee = $contract->getFee() * $rapport;
         $end->sub(new \DateInterval('P1D'));
         $line = BillLineFactory::create(new ProductBillLineBuilder($product, $this->fee->getVat()->getRate(), 1, array('price' => $fee, 'designation' => $product->getDesignation() . $frequenceString . ' du ' . $begin->format('d/m/Y') . ' au ' . $end->format('d/m/Y'), 'description' => $contract->getDoor()->getType() . ' / ' . $contract->getDoor()->getLocation())));
         $line->setPosition($key);
         $line->setBill($this->getBill());
         $this->getBill()->addLine($line);
     }
 }