/**
  * This function generates and return the rotation by family
  * (This function generate the math of Claculo ABC x Sfam in new_rotation workset Excel Document)
  *
  * @author Erick Guevara Mart�nez
  * @param InventoryRotationCollection $inventory
  * @param ProductCollection $products
  */
 public function generateRotationByFamily(InventoryRotationCollection $inventory, ProductCollection $products)
 {
     // Init a new stock
     $stockByFamily = new FamilyStock();
     // Read all inventory lines to get the family stock rotation
     $inventory->rewind();
     while ($inventory->valid()) {
         $productInventory = $inventory->read();
         $product = $products->getByPK($productInventory->getItemCode());
         // If the product exist in own catalog then constinue
         if ($product instanceof Product && $product->isLine()) {
             // If the family product exist in the stock then get the family line and increment the total sale
             if ($stockByFamily->existIndex(substr($product->getItemCode(), 0, 3))) {
                 $familyLine = $stockByFamily->getByIndex(substr($product->getItemCode(), 0, 3));
                 $familyLine->setTotalSale($familyLine->getTotalSale() + $productInventory->getTVTA());
                 // If the family product not exist in the stock, then create it
             } else {
                 $familyLine = new FamilyLine();
                 $familyLine->setIdFamily(substr($product->getItemCode(), 0, 3))->setTotalSale($productInventory->getTVTA());
             }
             // Add the family line into stock
             $stockByFamily->addStockable($familyLine);
         }
     }
     // Create a ABC classification by sale and return the stock
     return $stockByFamily->ABCClassmentBySale();
 }