-
Notifications
You must be signed in to change notification settings - Fork 10
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from siwapp/master
update to latest codebase
- Loading branch information
Showing
64 changed files
with
611 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,7 +6,6 @@ cache: | |
- $HOME/.composer/cache | ||
|
||
php: | ||
- '5.6' | ||
- '7.0' | ||
- '7.1' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 65 additions & 0 deletions
65
src/Siwapp/CoreBundle/Controller/AbstractInvoiceController.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
<?php | ||
|
||
namespace Siwapp\CoreBundle\Controller; | ||
|
||
use Siwapp\CoreBundle\Entity\AbstractInvoice; | ||
use Siwapp\CoreBundle\Entity\Item; | ||
use Symfony\Bundle\FrameworkBundle\Controller\Controller; | ||
|
||
abstract class AbstractInvoiceController extends Controller | ||
{ | ||
|
||
protected function getPdf(string $html): string | ||
{ | ||
$config = $this->getDoctrine()->getRepository('SiwappConfigBundle:Property'); | ||
$pdfSize = $config->get('pdf_size'); | ||
$pdfOrientation = $config->get('pdf_orientation'); | ||
$config = []; | ||
if ($pdfSize) { | ||
$config['page-size'] = $pdfSize; | ||
} | ||
if ($pdfOrientation) { | ||
$config['orientation'] = $pdfOrientation; | ||
} | ||
|
||
return $this->get('knp_snappy.pdf')->getOutputFromHtml($html, $config); | ||
} | ||
|
||
protected function getInvoiceTotalsFromPost(array $post, AbstractInvoice $invoice, string $locale): array | ||
{ | ||
$em = $this->getDoctrine()->getManager(); | ||
$taxRepo = $em->getRepository('SiwappCoreBundle:Tax'); | ||
$currency = $em->getRepository('SiwappConfigBundle:Property')->get('currency'); | ||
$formatter = new \NumberFormatter($locale, \NumberFormatter::CURRENCY); | ||
|
||
$totals = []; | ||
foreach ($post['items'] as $index => $postItem) { | ||
$item = new Item; | ||
$item->setUnitaryCost($postItem['unitary_cost']); | ||
$item->setQuantity($postItem['quantity']); | ||
$item->setDiscount($postItem['discount_percent']); | ||
if (isset($postItem['taxes'])) { | ||
foreach($postItem['taxes'] as $taxId) { | ||
$tax = $taxRepo->find($taxId); | ||
if (!$tax) { | ||
continue; | ||
} | ||
$item->addTax($tax); | ||
} | ||
} | ||
$totals['items'][$index] = [ | ||
'gross_amount' => $formatter->formatCurrency($item->getGrossAmount(), $currency), | ||
]; | ||
$invoice->addItem($item); | ||
} | ||
$invoice->checkAmounts(); | ||
|
||
$totals += [ | ||
'invoice_base_amount' => $formatter->formatCurrency($invoice->getBaseAmount(), $currency), | ||
'invoice_tax_amount' => $formatter->formatCurrency($invoice->getTaxAmount(), $currency), | ||
'invoice_gross_amount' => $formatter->formatCurrency($invoice->getGrossAmount(), $currency), | ||
]; | ||
|
||
return $totals; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.