Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/export excel #125

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/Siwapp/CoreBundle/DataFixtures/ORM/LoadItemData.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,11 @@ public function load(ObjectManager $manager)
// TODO: find a way of obtainin Bundle's path with the help of $this->container
$bpath = $this->container->get('kernel')->getBundle('SiwappCoreBundle')->getPath();
$value = $yaml->parse(file_get_contents($bpath.'/DataFixtures/items.yml'));


foreach ($value['Item'] as $ref => $values) {
$item = new Item();

foreach ($values as $fname => $fvalue) {
if (in_array($fname, ['Product'])) {
$fvalue = $manager->merge($this->getReference($fvalue));
Expand All @@ -52,6 +55,7 @@ public function load(ObjectManager $manager)
$manager->flush();
}


}

public function getOrder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
use Doctrine\Common\Util\Inflector;
use Doctrine\Common\Persistence\ObjectManager;

class LoadEstimateData extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
class LoadEstimate extends AbstractFixture implements OrderedFixtureInterface, ContainerAwareInterface
{
private $container;

Expand Down
53 changes: 48 additions & 5 deletions src/Siwapp/InvoiceBundle/Controller/InvoiceController.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Symfony\Component\HttpFoundation\JsonResponse;
use Symfony\Component\HttpFoundation\Request;
use Symfony\Component\HttpFoundation\Response;
use Symfony\Component\HttpFoundation\StreamedResponse;
use Symfony\Component\HttpKernel\Exception\NotFoundHttpException;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Route;
use Sensio\Bundle\FrameworkExtraBundle\Configuration\Method;
Expand Down Expand Up @@ -56,8 +57,7 @@ public function indexAction(Request $request)
$data = $listForm->getData();
if (empty($data['invoices'])) {
$this->addTranslatedMessage('flash.nothing_selected', 'warning');
}
else {
} else {
if ($request->request->has('delete')) {
return $this->bulkDelete($data['invoices']);
} elseif ($request->request->has('pdf')) {
Expand All @@ -66,7 +66,10 @@ public function indexAction(Request $request)
return $this->bulkPrint($data['invoices']);
} elseif ($request->request->has('email')) {
return $this->bulkEmail($data['invoices']);
} elseif ($request->request->has('excel')) {
return $this->bulkExcel($data['invoices']);
}

}
}

Expand Down Expand Up @@ -379,7 +382,7 @@ protected function getInvoicePrintPdfHtml(Invoice $invoice, $print = false)
->getAll();

return $this->renderView('SiwappInvoiceBundle:Invoice:print.html.twig', [
'invoice' => $invoice,
'invoice' => $invoice,
'settings' => $settings,
'print' => $print,
]);
Expand Down Expand Up @@ -442,17 +445,57 @@ protected function bulkEmail(array $invoices)
return $this->redirect($this->generateUrl('invoice_index'));
}

protected function bulkExcel(array $invoices)
{
$translator = $this->get('translator.default');

$file = fopen('export-invoice.csv', 'w+');
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where is this file supposed to exist?
When i try it, i get

Warning: fopen(export-invoice.csv): failed to open stream: Permission denied

fputcsv($file, [
$translator->trans('list.number',[], 'SiwappInvoiceBundle'),
$translator->trans('list.customer',[], 'SiwappInvoiceBundle'),
$translator->trans('list.issue_date',[], 'SiwappInvoiceBundle'),
$translator->trans('list.sub_total',[], 'SiwappInvoiceBundle'),
$translator->trans('list.taxes',[], 'SiwappInvoiceBundle'),
$translator->trans('list.gross_amount',[], 'SiwappInvoiceBundle'),
$translator->trans('list.status',[], 'SiwappInvoiceBundle')
],
';');

/**
* @var Invoice $invoice
*/
foreach ($invoices as $invoice) {
fputcsv(
$file,
[
$invoice->label(),
$invoice->getCustomerName(),
$invoice->getCreatedAt()->format('Y-m-d'),
$invoice->getBaseAmount(),
$invoice->getTaxAmount(),
$invoice->getGrossAmount(),
$invoice->getStatusString()
], ';'
);
}
$response = new Response(file_get_contents("export-invoice.csv"));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lets delete the file after we create the response

$response->headers->set('Content-type', 'application/csv');
$response->headers->set('Content-Disposition', 'attachment; filename="export-invoice.csv"');

return $response;
}

protected function getEmailMessage($invoice)
{
$em = $this->getDoctrine()->getManager();
$configRepo = $em->getRepository('SiwappConfigBundle:Property');

$html = $this->renderView('SiwappInvoiceBundle:Invoice:email.html.twig', array(
'invoice' => $invoice,
'invoice' => $invoice,
'settings' => $em->getRepository('SiwappConfigBundle:Property')->getAll(),
));
$pdf = $this->getPdf($html);
$attachment = new \Swift_Attachment($pdf, $invoice->getId().'.pdf', 'application/pdf');
$attachment = new \Swift_Attachment($pdf, $invoice->getId() . '.pdf', 'application/pdf');
$subject = '[' . $this->get('translator')->trans('invoice.invoice', [], 'SiwappInvoiceBundle') . ': ' . $invoice->label() . ']';
$message = \Swift_Message::newInstance()
->setSubject($subject)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,16 @@ list:
bulk_delete: 'Διαγραφή επιλεγμένων'
bulk_email: 'Τα e-mail έχουν επιλεγεί'
bulk_pdf: 'Μεταμόρφωση επιλεγμένων ως PDF'
bulk_excel: 'Excel'
bulk_print: 'Εκτύπωση επιλεγμένων'
number: 'Αριθμός'
customer: 'Πελάτης'
issue_date: 'Ημερομηνία'
due_date: 'Από'
status: 'Κατάσταση'
due_amount: 'Από'
taxes: 'Taxes'
sub_total: 'Subtotal'
gross_amount: 'Σύνολο'
payments: 'Πληρωμές'
no_results: 'Δεν βρέθηκαν τιμολόγια.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,13 +93,16 @@ list:
bulk_delete_confirm: 'Are you sure you want to remove selected invoices?'
bulk_email: 'E-mail selected'
bulk_pdf: 'Download selected as PDF'
bulk_excel: 'Download selected as Excel'
bulk_print: 'Print selected'
number: 'Number'
customer: 'Customer'
issue_date: 'Date'
due_date: 'Due Date'
status: 'Status'
due_amount: 'Due'
taxes: 'Taxes'
sub_total: 'Subtotal'
gross_amount: 'Total'
payments: 'Payments'
no_results: 'No invoices found.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ list:
bulk_delete: 'Borrar seleccionadas'
bulk_delete_confirm: '¿Estás seguro de querer eliminar las facturas seleccionadas?'
bulk_email: 'Enviar por email seleccionadas'
bulk_excel: 'Excel'
bulk_pdf: 'Descargar seleccionadas como PDF'
bulk_print: 'Imprimir seleccionadas'
number: 'Número'
Expand All @@ -100,6 +101,8 @@ list:
due_date: 'Fecha de vencimiento'
status: 'Estado'
due_amount: 'Debido'
taxes: 'Taxes'
sub_total: 'Subtotal'
gross_amount: 'Total'
payments: 'Pagos'
no_results: 'No se han encontrado facturas.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,16 @@ list:
bulk_delete: 'Șterge selecția'
bulk_email: 'E-mail selectat'
bulk_pdf: 'Descărc selectate ca PDF'
bulk_excel: 'Excel'
bulk_print: 'Imprimare selecția'
number: 'Număr'
customer: 'Client'
issue_date: 'Data'
due_date: 'Data scadenta'
status: 'Status'
due_amount: 'Suma datorata'
taxes: 'Taxes'
sub_total: 'Subtotal'
gross_amount: 'Total'
payments: 'Plați'
no_results: 'Nu s-au găsit facturi.'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@
<li>
<button type="submit" name="pdf" class="btn btn-default" title="{% trans %}list.bulk_pdf{% endtrans %}"><span class="glyphicon glyphicon-download-alt"></span></button>
</li>
<li>
<button type="submit" name="excel" class="btn btn-default" title="{% trans %}list.bulk_excel{% endtrans %}"><span class="glyphicon glyphicon-save-file"></span></button>
</li>
<li>
<button type="submit" name="email" class="btn btn-default" title="{% trans %}list.bulk_email{% endtrans %}"><span class="glyphicon glyphicon-envelope"></span></button>
</li>
Expand Down
4 changes: 2 additions & 2 deletions var/SymfonyRequirements.php
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -420,7 +420,7 @@ public function __construct()
is_dir(__DIR__.'/../vendor/composer'),
'Vendor libraries must be installed',
'Vendor libraries are missing. Install composer following instructions from <a href="http://getcomposer.org/">http://getcomposer.org/</a>. '.
'Then run "<strong>php composer.phar install</strong>" to install them.'
'Then run "<strong>php composer.phar install</strong>" to install them.'
);

$cacheDir = is_dir(__DIR__.'/../var/cache') ? __DIR__.'/../var/cache' : __DIR__.'/cache';
Expand Down Expand Up @@ -816,4 +816,4 @@ protected function getPhpRequiredVersion()

return false;
}
}
}
Empty file modified var/logs/.gitkeep
100755 → 100644
Empty file.
Empty file modified var/sessions/.gitkeep
100755 → 100644
Empty file.