</a> | </a> | ||||
{% endif %} | {% endif %} | ||||
{% if _entity_config['list']['btn_download_purchase_order_archive'] is defined %} | |||||
<a class="float-right btn-sm btn-success" | |||||
href="{{ path('easyadmin', { entity: 'Supplier', action: 'exportOrderPurchasesAsArchive' }) }}"> | |||||
<i class="fa fa-download"></i> Télécharger tous les bons de commande | |||||
</a> | |||||
{% endif %} | |||||
{% if _entity_config['list']['edit_position'] is defined %} | {% if _entity_config['list']['edit_position'] is defined %} | ||||
<a class="float-right btn-sm btn-success action-sort" | <a class="float-right btn-sm btn-success action-sort" | ||||
href="{{ path('easyadmin', _request_parameters|merge({ action: 'sort' })) }}"> | href="{{ path('easyadmin', _request_parameters|merge({ action: 'sort' })) }}"> |
protected $columns; | protected $columns; | ||||
protected $titleDocument; | protected $titleDocument; | ||||
protected $convertEncoding ; | |||||
protected $fromEncoding ; | |||||
protected $toEncoding ; | |||||
public function __construct() | public function __construct() | ||||
{ | { | ||||
$this->arrayToExport = array(); | $this->arrayToExport = array(); | ||||
$this->titleDocument = 'csv_file'; | $this->titleDocument = 'csv_file'; | ||||
$this->convertEncoding = false ; | |||||
$this->fromEncoding = 'UTF-8' ; | |||||
$this->toEncoding = 'ISO-8859-1' ; | |||||
} | |||||
public function enableConvertEncoding($toEncoding, $fromEncoding = null) | |||||
{ | |||||
$this->convertEncoding = true ; | |||||
$this->toEncoding = $toEncoding ; | |||||
if(!is_null($fromEncoding)) { | |||||
$this->fromEncoding = $fromEncoding ; | |||||
} | |||||
} | |||||
public function encode($value) | |||||
{ | |||||
if($this->convertEncoding) { | |||||
return mb_convert_encoding($value, $this->toEncoding, $this->fromEncoding) ; | |||||
} | |||||
return $value ; | |||||
} | |||||
public function encodeArray($array) | |||||
{ | |||||
return array_map(function($value) { | |||||
return $this->encode($value) ; | |||||
}, $array) ; | |||||
} | } | ||||
public function setTitle($title, $displayHeader = false){ | public function setTitle($title, $displayHeader = false){ | ||||
$this->titleDocument = $this->formatTitle($title); | $this->titleDocument = $this->formatTitle($title); | ||||
if($displayHeader){ | |||||
if($displayHeader) { | |||||
array_unshift($this->arrayToExport, array('')); | array_unshift($this->arrayToExport, array('')); | ||||
array_unshift($this->arrayToExport, array($title)); | array_unshift($this->arrayToExport, array($title)); | ||||
} | } | ||||
} | } | ||||
public function setColumns($columns, $displayLegend = true){ | |||||
$this->columns =array_fill_keys(array_keys($columns), null);; | |||||
if($displayLegend)$this->arrayToExport[] = $columns; | |||||
public function setColumns($columns, $displayLegend = true) { | |||||
$this->columns = array_fill_keys(array_keys($columns), null); | |||||
if($displayLegend) $this->row($columns); | |||||
} | } | ||||
public function cell($column, $value){ | public function cell($column, $value){ | ||||
$this->arrayToExport[] = array_merge($this->columns, array($column =>$value)); | |||||
$this->arrayToExport[] = array_merge( | |||||
$this->columns, | |||||
array($column => $this->encode($value)) | |||||
); | |||||
} | } | ||||
public function row($values = null, $row = false){ | public function row($values = null, $row = false){ | ||||
$values = $this->encodeArray($values) ; | |||||
if(!$row){ | if(!$row){ | ||||
if($values)$this->arrayToExport[] = array_merge($this->columns, $values); | if($values)$this->arrayToExport[] = array_merge($this->columns, $values); | ||||
else $this->arrayToExport[] = array(); | else $this->arrayToExport[] = array(); | ||||
if($values)$this->arrayToExport[$row] = array_merge($this->columns, $values); | if($values)$this->arrayToExport[$row] = array_merge($this->columns, $values); | ||||
else $this->arrayToExport[$row] = array(); | else $this->arrayToExport[$row] = array(); | ||||
} | } | ||||
} | |||||
public function emptyRow() | |||||
{ | |||||
$this->row([]) ; | |||||
} | } | ||||
public function dump(){ | public function dump(){ | ||||
dump($this->arrayToExport); | dump($this->arrayToExport); | ||||
} | } | ||||
public function createCsv($path) | |||||
{ | |||||
$handle = fopen($path, 'w+'); | |||||
foreach ($this->arrayToExport as $line) { | |||||
fputcsv($handle, $line, ';', ' '); | |||||
} | |||||
fclose($handle); | |||||
} | |||||
public function getReponse(){ | public function getReponse(){ | ||||
$response = new StreamedResponse(function () { | $response = new StreamedResponse(function () { | ||||
$handle = fopen('php://output', 'r+'); | |||||
foreach ($this->arrayToExport as $line) { | |||||
fputcsv($handle, $line, ';', ' '); | |||||
} | |||||
fclose($handle); | |||||
$this->createCsv('php://output'); | |||||
}); | }); | ||||
$response->headers->set('Content-Type', 'application/force-download'); | $response->headers->set('Content-Type', 'application/force-download'); |
return $orderProduct->getQuantityOrder() * $this->getPrice($orderProduct); | return $orderProduct->getQuantityOrder() * $this->getPrice($orderProduct); | ||||
} | } | ||||
public function getTotalBuyingPrice(OrderProductInterface $orderProduct) | |||||
{ | |||||
return $orderProduct->getQuantityOrder() * $this->getBuyingPrice($orderProduct); | |||||
} | |||||
public function getMargin(OrderProductInterface $orderProduct) | public function getMargin(OrderProductInterface $orderProduct) | ||||
{ | { | ||||
); | ); | ||||
} | } | ||||
public function getTotalBuyingPriceWithTax(OrderProductInterface $orderProduct) | |||||
{ | |||||
return $this->applyTax( | |||||
$this->getTotalBuyingPrice($orderProduct), | |||||
$orderProduct->getTaxRateInherited()->getValue() | |||||
); | |||||
} | |||||
//inclus toujours les réductions catalogues | //inclus toujours les réductions catalogues | ||||
public function getTotalTaxes(OrderProductInterface $orderProduct){ | public function getTotalTaxes(OrderProductInterface $orderProduct){ | ||||
return $this->getTotalWithTaxAndReduction($orderProduct) - $this->getTotalWithReduction($orderProduct); | return $this->getTotalWithTaxAndReduction($orderProduct) - $this->getTotalWithReduction($orderProduct); |
return $this->getTotalOrderProductsWithTaxByOrderProducts($orderShop->getOrderProducts()) ; | return $this->getTotalOrderProductsWithTaxByOrderProducts($orderShop->getOrderProducts()) ; | ||||
} | } | ||||
public function getTotalBuyingPriceOrderProductsWithTax($orderProducts):float | |||||
{ | |||||
$total = 0; | |||||
foreach ($orderProducts as $orderProduct) { | |||||
$total += $this->orderProductPriceUtils->getTotalBuyingPriceWithTax($orderProduct); | |||||
} | |||||
return $total; | |||||
} | |||||
public function getTotalOrderProductsWithTaxByOrderProducts($orderProducts):float | public function getTotalOrderProductsWithTaxByOrderProducts($orderProducts):float | ||||
{ | { |
} | } | ||||
return $reminders; | return $reminders; | ||||
} | } | ||||
public function removeDir($dir) { | |||||
$files = array_diff(scandir($dir), array('.','..')); | |||||
foreach ($files as $file) { | |||||
(is_dir("$dir/$file")) ? $this->removeDir("$dir/$file") : unlink("$dir/$file"); | |||||
} | |||||
return rmdir($dir); | |||||
} | |||||
function folderToZip($folder, &$zipFile, $subfolder = null) { | |||||
if ($zipFile == null) { | |||||
// no resource given, exit | |||||
return false; | |||||
} | |||||
// we check if $folder has a slash at its end, if not, we append one | |||||
$tabFolder = str_split($folder) ; | |||||
$tabSubFolder = str_split($subfolder) ; | |||||
$folder .= end($tabFolder) == "/" ? "" : "/"; | |||||
$subfolder .= end($tabSubFolder) == "/" ? "" : "/"; | |||||
// we start by going through all files in $folder | |||||
$handle = opendir($folder); | |||||
while ($f = readdir($handle)) { | |||||
if ($f != "." && $f != "..") { | |||||
if (is_file($folder . $f)) { | |||||
// if we find a file, store it | |||||
// if we have a subfolder, store it there | |||||
if ($subfolder != null) | |||||
$zipFile->addFile($folder . $f, $subfolder . $f); | |||||
else | |||||
$zipFile->addFile($folder . $f); | |||||
} elseif (is_dir($folder . $f)) { | |||||
// if we find a folder, create a folder in the zip | |||||
$zipFile->addEmptyDir($f); | |||||
// and call the function again | |||||
folderToZip($folder . $f, $zipFile, $f); | |||||
} | |||||
} | |||||
} | |||||
} | |||||
} | } |