private function saveSales($jsonSales, $repository)
 {
     $newCnt = 0;
     foreach ($jsonSales as $jsonSale) {
         if ($repository->findIfSaleIsNew($jsonSale['invoice'], $jsonSale['licenseId'], $jsonSale['pluginKey'])) {
             $newCnt++;
             $sale = new Sale();
             $sale->setFromJSON($jsonSale);
             $this->em->persist($sale);
             if (true == $this->input->getOption('new-sale-notification')) {
                 $this->saleMailer->sendEmail($sale);
             }
         }
     }
     return $newCnt;
 }
 private function saveSales($jsonSales, $existingInvoices)
 {
     foreach ($jsonSales as $jsonSale) {
         $exists = false;
         foreach ($existingInvoices as $existing) {
             if ($existing['invoice'] == $jsonSale['invoice'] && $existing['licenseId'] == $jsonSale['licenseId']) {
                 $exists = true;
             }
         }
         if (!$exists) {
             $sale = new Sale();
             $sale->setFromJSON($jsonSale);
             $this->em->persist($sale);
             if (true == $this->getContainer()->getParameter('new_sale_notification')) {
                 $this->saleMailer->sendEmail($sale);
             }
         }
     }
 }