From 80082c312590b976d979be065fa6d791ff65c599 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Mon, 14 Jan 2013 16:19:22 +0000 Subject: [PATCH] --- inc/commons/class.common.tools.php | 85 +++++++++++++++++++++++++++++- 1 file changed, 83 insertions(+), 2 deletions(-) diff --git a/inc/commons/class.common.tools.php b/inc/commons/class.common.tools.php index 73aad5499..f7082beb9 100644 --- a/inc/commons/class.common.tools.php +++ b/inc/commons/class.common.tools.php @@ -190,7 +190,6 @@ class commonTools { $res.=''; $res.=''; $res.=''; - $res.=''; $res.=''; $res.='
' . __('Exporter la base clients') . '
' . __('Type de client') . '' . form::combo('type', $types) . '
' . __('Type d\'export') . '' . form::combo('typeexp', $typeexp) . '
' . $core->typo->BoutonOK(__('Exporter')) . '
'; $res.=''; @@ -222,7 +221,89 @@ class commonTools { foreach ($rows as $r) { $entreprises[$r['entreprise']]['utilisateurs'][$r['utilisateur_id']] = $r; } - fb($entreprises); + + $xls = new PHPExcel(); + $s1 = $xls->getActiveSheet(); + $s1->setTitle('Entreprises'); + self::exportClientsXLSEntreprises($s1, $entreprises); + + $s2 = $xls->createSheet(); + $s2->setTitle('Utilisateurs'); + self::exportClientsXLSUsers($s2, $entreprises); + + ob_end_clean(); + files::$mimeType['xlsx'] = 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'; + cubeHTTP::forceDownload('clients.xlsx', false); + + $xls->setActiveSheetIndex(0); + $writer = new PHPExcel_Writer_Excel2007($xls); + $writer->save('php://output'); + exit; + } + + /** + * + * @param PHPExcel_Worksheet $s + * @param type $e + */ + public static function exportClientsXLSEntreprises(&$s, $e) { + $j = 2; + $w = 3; + foreach ($e as $id => $datas) { + $mainAddress = self::_address($datas['nom'], $datas['adresse'], $datas['code_postal'], $datas['ville'], $datas['pays']); + $otherAddress = array(); + foreach ($datas['utilisateurs'] as $u) { + $a = self::_address($datas['nom'], $u['adresse'], $u['code_postal'], $u['ville'], $u['pays']); + if ($a != $mainAddress && !in_array($a, $otherAddress)) { + $otherAddress[] = $a; + } + } + + $s->getCellByColumnAndRow(0, $j)->setValue($id); + $s->getCellByColumnAndRow(1, $j)->setValue($datas['nom']); + $s->getCellByColumnAndRow(2, $j)->setValue($mainAddress); + $i = 3; + foreach ($otherAddress as $o) { + $s->getCellByColumnAndRow($i, $j)->setValue($o); + $i++; + } + $j++; + $w = max($w, $i); + } + + $h = $j; + + $s->getCellByColumnAndRow(0, 1)->setValue('#'); + $s->getCellByColumnAndRow(1, 1)->setValue('Raison sociale'); + $s->getCellByColumnAndRow(2, 1)->setValue('Adresse principale'); + $s->getCellByColumnAndRow(3, 1)->setValue('Autres adresses'); + + for ($i = 0; $i <= $w; $i++) { + for ($j = 0; $j <= $h; $j++) { + $style = $s->getStyleByColumnAndRow($i, $j); + $style->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER)->setWrapText(true); + } + if ($i == 0) { + $s->getColumnDimensionByColumn($i)->setAutoSize(); + } elseif ($i == 1) { + $s->getColumnDimensionByColumn($i)->setWidth(20); + } else { + $s->getColumnDimensionByColumn($i)->setWidth(30); + } + } + } + + protected static function _address($nom, $adresse, $code_postal, $ville, $pays) { + return trim(trim($nom) . "\r\n" . trim($adresse) . "\r\n" . trim($code_postal . " " . $ville) . "\r\n" . cubeCountry::getCountryName($pays, 'fr_FR')); + } + + /** + * + * @param PHPExcel_Worksheet $s + * @param type $e + */ + public static function exportClientsXLSUsers(&$s, $e) { + } public static function favicon($args) { -- 2.39.5