Skip to content

Commit

Permalink
Common checkbox to also export these items
Browse files Browse the repository at this point in the history
  • Loading branch information
pedrodevog committed Oct 28, 2023
1 parent 3e3a947 commit 55e26cb
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 11 deletions.
33 changes: 27 additions & 6 deletions module/CudiBundle/Component/Document/Generator/SaleArticles.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ class SaleArticles extends \CommonBundle\Component\Document\Generator\Csv
* @param AcademicYear $academicYear The academic year
* @param integer $semester The semester
*/
public function __construct(EntityManager $entityManager, AcademicYear $academicYear, $semester)
public function __construct(EntityManager $entityManager, AcademicYear $academicYear, int $semester, bool $common)
{
$headers = array(
'Title',
Expand All @@ -40,7 +40,7 @@ public function __construct(EntityManager $entityManager, AcademicYear $academic

parent::__construct(
$headers,
$this->getData($entityManager, $academicYear, $semester)
$this->getData($entityManager, $academicYear, $semester, $common)
);
}

Expand All @@ -49,7 +49,7 @@ public function __construct(EntityManager $entityManager, AcademicYear $academic
* @param AcademicYear $academicYear
* @param integer $semester
*/
private function getData(EntityManager $entityManager, AcademicYear $academicYear, $semester)
private function getData(EntityManager $entityManager, AcademicYear $academicYear, int $semester, bool $common)
{
$articles = $entityManager
->getRepository('CudiBundle\Entity\Sale\Article')
Expand All @@ -58,14 +58,34 @@ private function getData(EntityManager $entityManager, AcademicYear $academicYea
$data = array();
foreach ($articles as $article) {
$codes = $this->getSubjectCode($entityManager, $academicYear, $article);
foreach ($codes as $code) {
if ($codes) {
foreach ($codes as $code) {
$articleData = array(
$article->getMainArticle()->getTitle(),
$article->getBarcode(),
$article->getSupplier()->getName(),
$article->getMainArticle()->getAuthors(),
$code->getSubject()->getCode(),
$code->getSubject()->getName(),
$this->getNbSold($entityManager, $article, $academicYear),
$article->getStockValue(),
$this->getPagesBW($entityManager, $article),
$this->getPagesColored($entityManager, $article),
$this->getRectoVerso($entityManager, $article),
number_format($article->getPurchasePrice() / 100, 2),
number_format($article->getSellPrice() / 100, 2),
$article->getMainArticle()->getNameContact(),
$article->getMainArticle()->getEmailContact()
);
}
} elseif ($common) {
$articleData = array(
$article->getMainArticle()->getTitle(),
$article->getBarcode(),
$article->getSupplier()->getName(),
$article->getMainArticle()->getAuthors(),
$code->getSubject()->getCode(),
$code->getSubject()->getName(),
'',
'',
$this->getNbSold($entityManager, $article, $academicYear),
$article->getStockValue(),
$this->getPagesBW($entityManager, $article),
Expand All @@ -77,6 +97,7 @@ private function getData(EntityManager $entityManager, AcademicYear $academicYea
$article->getMainArticle()->getEmailContact()
);
}

if (!in_array($articleData, $data)) {
$data[] = $articleData;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,10 @@ public function downloadAction()
->findOneById($formData['academic_year']);

$semester = $formData['semester'];
$common = $formData['common'];

$file = new CsvFile();
$document = new SaleArticlesGenerator($this->getEntityManager(), $academicYear, $formData['semester']);
$document = new SaleArticlesGenerator($this->getEntityManager(), $academicYear, $formData['semester'], $common);
$document->generateDocument($file);

$this->getResponse()->getHeaders()
Expand Down
9 changes: 9 additions & 0 deletions module/CudiBundle/Form/Admin/Sale/Article/Export.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@ public function init()
)
);

$this->add(
array(
'type' => 'checkbox',
'name' => 'common',
'label' => 'Common items',
'required' => true,
)
);

$this->addSubmit('Download', 'download');
}

Expand Down
5 changes: 3 additions & 2 deletions module/CudiBundle/Resources/translations/site.en.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'Actions' => 'Actions',
'Mandatory' => 'Mandatory',
'Booked' => 'Booked',
'Bought' => 'Bought',
'Assigned' => 'Assigned',
'Remarks' => 'Remarks',
'Remark' => 'Remark',
Expand Down Expand Up @@ -95,6 +96,6 @@
'You currently have no personal retails!' => 'You currently have no personal retails!',
'You successfully deleted the retail!' => 'You successfully deleted the retail!',

'To edit subjects here, go to' => 'To edit subject here, go to',
'Profile' => 'Profile',
'To edit subjects visible here, go to' => 'To edit subject visible here, go to',
'profile' => 'profile',
);
5 changes: 3 additions & 2 deletions module/CudiBundle/Resources/translations/site.nl.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
'Actions' => 'Acties',
'Mandatory' => 'Verplicht',
'Booked' => 'Gereserveerd',
'Bought' => 'Gekocht',
'Assigned' => 'Toegewezen',
'Remarks' => 'Opmerkingen',
'Remark' => 'Opmerking',
Expand Down Expand Up @@ -95,6 +96,6 @@
'You currently have no personal retails!' => 'Je hebt momenteel geen persoonlijke aanbiedingen!',
'You successfully deleted the retail!' => 'De aanbieding is succesvol verwijderd!',

'To edit subjects here, go to' => 'Om je vakken aan te passen, ga naar',
'Profile' => 'Profiel',
'To edit subjects visible here, go to' => 'Om je vakken aan te passen, ga naar',
'profile' => 'profiel',
);

0 comments on commit 55e26cb

Please sign in to comment.