Advertisement
AmourSpirit

Joomla PhpExcel layout working example

Jul 31st, 2015
415
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 24.21 KB | None | 0 0
  1. <?php defined('_JEXEC') or die(); ?>
  2. <?php
  3. JHtml::addIncludePath(JPATH_COMPONENT.'/helpers/html');
  4. //
  5. // see also http://pastebin.com/71iRCXB1 (Joomla PhpExcel working example first report)
  6. // see also http://pastebin.com/TfKq8NZ4 (xlsx.php for joomla and PhpExcel)
  7. // see also http://pastebin.com/kM9wtd1c (xls.php for joomla and PhpExcel)
  8.  
  9. $params = JComponentHelper::getParams('com_cn_reports');
  10. $cartTz = null;
  11. $useTz = filter_var($params->get('use_opencart_timezone',false), FILTER_VALIDATE_BOOLEAN);
  12. if ($useTz == true) {
  13.     $cartTz = $params->get('opencart_timezone','America/Toronto');
  14. }
  15.  
  16. $objPhpExcel = $this->phpexcel;
  17. $rowOffset = 7; // athe amount of rows to leave above the sheet data rows.
  18. $col_count = 11; // the number of colums in the commissions data
  19. $data_row_offset = 3; // the number of rows to increas by before writing data into the table. Makes room for header rows
  20.  
  21. // rowRptDisplayTitle is the row to set the title for the report on.
  22. // set rowRptDisplayTitle to 0 (zero) to hide the row
  23. $rowRptDisplayTitle = 4;
  24. if (filter_var($this->showTitle, FILTER_VALIDATE_BOOLEAN) == false) {
  25.     $rowRptDisplayTitle = 0;
  26. }
  27. // rowHeaderText is the row to display the header text on for the report
  28. // set rowHeaderText to 0 (zero) to hide the row.
  29. $rowHeaderText = 6;
  30. if (filter_var($this->showHeader, FILTER_VALIDATE_BOOLEAN) == false) {
  31.     $rowHeaderText = 0;
  32. }
  33. // overrideOffset: set this value to the number of rows below the commissions that
  34. // you want the overrides to be in . Later the rowOffset and the number of rows in
  35. // the commissions will be added to this value.
  36. $overrideOffset = 2;
  37. // rowFooterText is the offset to display the footer text below the last row of
  38. // the report data. If 0 (zero) will not be displayed
  39. $rowFooterText = 2;
  40. if (filter_var($this->showFooter, FILTER_VALIDATE_BOOLEAN) == false) {
  41.     $rowFooterText = 0;
  42. }
  43.  
  44. // set up font for report title on top of page below logo
  45. $rowRptTitleFontStyle = array(
  46.         'font'  => array(
  47.                 'bold'  => true,
  48.                 'color' => array('rgb' => $this->rowRptTitleFontcolor),
  49.                 'size'  => 13,
  50.                 'name'  => 'Verdana'
  51.         ));
  52. // set up font for The merger title above each table
  53. $rowColumnTitleFontStyle = array(
  54.         'font'  => array(
  55.                 'bold'  => true,
  56.                 'color' => array('rgb' => $this->rowColumnTitleFontColor),
  57.                 'size'  => 11,
  58.                 'name'  => 'Verdana'
  59.         ));
  60. // set up font for the column headers for each table
  61. $rowColumnHeaderFontStyle = array(
  62.         'font'  => array(
  63.                 'bold'  => false,
  64.                 'color' => array('rgb' => $this->rowColumnHeaderFontColor),
  65.                 'size'  => 10,
  66.                 'name'  => 'Verdana'
  67.         ));
  68. // set up font for the column footer for each table
  69. $rowColumnFooterFontStyle = array(
  70.         'font'  => array(
  71.                 'bold'  => false,
  72.                 'color' => array('rgb' => $this->rowcolumnfooterfontcolor),
  73.                 'size'  => 10,
  74.                 'name'  => 'Verdana'
  75.         ));
  76. // set up font for the alternate rows for each table
  77. $rowAltRowFontStyle = array(
  78.         'font'  => array(
  79.                 'bold'  => false,
  80.                 'color' => array('rgb' => $this->rowAltFontColor),
  81.                 'size'  => 11,
  82.                 'name'  => 'Calibri'
  83.         ));
  84. // set up array to place borders around sections
  85. $styleOutline = array(
  86.         'borders' => array(
  87.                 'outline' => array(
  88.                         'style' => PHPExcel_Style_Border::BORDER_THICK,
  89.                         'color' => array('rgb' => '000000'),
  90.                 ),
  91.         ),
  92. );
  93.  
  94. // add commissions
  95. //Setup header row
  96. $column_index = 0;
  97. $row_index = $rowOffset + 1;
  98. $as = $objPhpExcel->getActiveSheet();
  99. // an array of all the column widths. Later this will be applied to the columns
  100. $cwidth = array(8.0,6.2,12.0,15.0,8.0,8.0,10.0,10.0,12.9,11.0,5.0,13.0);
  101. // grab the header row for the commissions section here because we want to add the columns and do
  102. // an auto resize on the columns. with a merged cell the columns will not rezize automatically
  103.  
  104. $row_commission_header = $row_index;
  105. $row_index++;
  106.  
  107. $as->setCellValueByColumnAndRow($column_index++, $row_index, JText::_('COM_CN_REPORTS_FORM_LBL_ORDERID'));
  108. $as->setCellValueByColumnAndRow($column_index++, $row_index, JText::_('COM_CN_REPORTS_FORM_LBL_COUNT'));
  109. $as->setCellValueByColumnAndRow($column_index++, $row_index, JText::_('COM_CN_REPORTS_FORM_LBL_OT_TOTAL'));
  110. $as->setCellValueByColumnAndRow($column_index++, $row_index, JText::_('COM_CN_REPORTS_FORM_LBL_WHOLESALE'));
  111. $as->setCellValueByColumnAndRow($column_index++, $row_index, JText::_('COM_CN_REPORTS_FORM_LBL_VOUCHER'));
  112. $as->setCellValueByColumnAndRow($column_index++, $row_index, JText::_('COM_CN_REPORTS_FORM_LBL_COUPON'));
  113. $as->setCellValueByColumnAndRow($column_index++, $row_index, JText::_('COM_CN_REPORTS_FORM_LBL_SHIPPING'));
  114. $as->setCellValueByColumnAndRow($column_index++, $row_index, JText::_('COM_CN_REPORTS_FORM_LBL_TAX'));
  115. $as->setCellValueByColumnAndRow($column_index++, $row_index, JText::_('COM_CN_REPORTS_FORM_LBL_APM'));
  116. $as->setCellValueByColumnAndRow($column_index++, $row_index, JText::_('COM_CN_REPORTS_FORM_LBL_DATE_ADDED'));
  117. $as->getStyle("J$row_index")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  118. $as->setCellValueByColumnAndRow($column_index++, $row_index, JText::_('COM_CN_REPORTS_FORM_LBL_COMMISSION_PERCENT'));
  119. $as->setCellValueByColumnAndRow($column_index++, $row_index, JText::_('COM_CN_REPORTS_FORM_LBL_COMMISSION'));
  120.  
  121.  
  122.  
  123. // Array that contains all the colums that require right alignment
  124. $rArray = array('A','B','C','D','E','F','G','H','I','K','L');
  125. // loop the array and set all the cells to right alignment
  126. for ($i = 0; $i < count($rArray); $i++) {
  127.     $as->getStyle($rArray[$i] . $row_index)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
  128. }
  129. //   $as->setCellValueByColumnAndRow($column_index++, 1, 'Time Zone');
  130. //   $as->setCellValueByColumnAndRow($column_index, 2, $cartTz);
  131.  
  132. $as->getStyle("A$row_index:L$row_index")->getFill()
  133.     ->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
  134.     ->getStartColor()->setRGB($this->rowColumnHeaderBgColor);
  135. $as->getStyle("A$row_index:L$row_index")->applyFromArray($rowColumnHeaderFontStyle);
  136. ?>
  137. <?php
  138.   // Set autosizes on the columns
  139. // for($i = 0; $i < $col_count; $i++)
  140. // {
  141. //  $as->getColumnDimensionByColumn($i)->setAutoSize(true);
  142. //   //Calulate the column widths to attempt to autosize them
  143.  
  144. // }
  145.     $as->calculateColumnWidths();
  146. for ($i = 0; $i < count($cwidth); $i++)
  147. {
  148.     $as->getColumnDimensionByColumn($i)->setWidth($cwidth[$i]);
  149. }
  150. ?>
  151. <?php
  152. // set the column header row
  153. $row_commissions_start = $row_commission_header;
  154. $as->mergeCells("A$row_commission_header:L$row_commission_header");
  155. $as->getStyle("A$row_commission_header")->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
  156. $as->getStyle("A$row_commission_header")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  157.  
  158. $as->setCellValue("A$row_commission_header",
  159.         JText::sprintf('COM_CN_REPORTS_FORM_TITLE_COMISSIONS',
  160.                 $this->reportStart->format('Y-m-d'), $this->reportEnd->format('Y-m-d'),$this->partnerName));
  161. $as->getStyle("A$row_commission_header")->getFill()
  162. ->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
  163. ->getStartColor()->setRGB($this->rowColumnTitleBgColor);
  164. $as->getStyle("A$row_commission_header")->applyFromArray($rowColumnTitleFontStyle);
  165. ?>
  166.  
  167. <?php
  168.  
  169. for ($i = 0, $n = count($this->rows[0]); $i < $n; $i++)
  170. {
  171.     $row = &$this->rows[0][$i];
  172.     //$as->getColumnDimensionByColumn($i)->setAutoSize(true);
  173.  
  174.     //Write out data rows
  175.     // convert the order date to unix time including cart timezone
  176.     // this seems to convert better to excel date time
  177.     $time = JFactory::getDate($row->OrderDate, $cartTz)->toUnix();
  178.     $column_index = 0;
  179.  
  180.     $row_index = $i + $data_row_offset + $rowOffset;
  181.     $as->setCellValueByColumnAndRow($column_index++, $row_index, $row->OrderID);            // A
  182.     $as->setCellValueByColumnAndRow($column_index++, $row_index, $row->Count);              // B
  183.     $as->setCellValueByColumnAndRow($column_index++, $row_index, $row->otTotal);            // C
  184.     $as->setCellValueByColumnAndRow($column_index++, $row_index, $row->Wholesale);          // D
  185.     $as->setCellValueByColumnAndRow($column_index++, $row_index, $row->Voucher);            // E
  186.     $as->setCellValueByColumnAndRow($column_index++, $row_index, $row->Coupon);             // F
  187.     $as->setCellValueByColumnAndRow($column_index++, $row_index, $row->Shipping);           // G
  188.     $as->setCellValueByColumnAndRow($column_index++, $row_index, $row->Tax);                // H
  189.     $as->setCellValueByColumnAndRow($column_index++, $row_index, $row->ActualProfitMargin); // I
  190.  
  191.     // Set the order date column to excel time from unix. This seems to convert better.
  192.     $as->setCellValueByColumnAndRow($column_index++, $row_index,
  193.             PHPExcel_Shared_Date::PHPToExcel($time));   // J
  194.  
  195.     // set the date formate on the order date cell for the current row
  196.     $as
  197.         ->getStyle("J$row_index")
  198.         ->getNumberFormat()
  199.         ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDDSLASH);
  200.     // set the alignment to left for the date
  201.     $as->getStyle("J$row_index")
  202.         ->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  203.  
  204.     $as->setCellValueByColumnAndRow($column_index++, $row_index, $row->commissionpercent);  // K
  205.     $as->setCellValueByColumnAndRow($column_index++, $row_index, $row->Commission);         // L
  206.     // set up alternate row formating for even rows
  207.     if (($i % 2) == 0) {
  208.         $as->getStyle("A$row_index:L$row_index")->getFill()
  209.             ->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
  210.             ->getStartColor()->setRGB($this->altRowaltBgColor);
  211.         $as->getStyle("A$row_index:L$row_index")->applyFromArray($rowAltRowFontStyle);
  212.     }
  213.  }
  214.  ?>
  215. <?php
  216.     // write formulas
  217.     $startRow = $rowOffset + $data_row_offset;
  218.     $finalRow = $row_index;
  219.     //$finalRow = count($this->rows[0]) + 1 + $rowOffset;
  220.     $totalRow = $finalRow + 1;
  221.     // set the row for the overrides sections to start
  222.     // add the current value + the rows
  223.     $overrideOffset = $overrideOffset + $totalRow;
  224.  
  225.     $as
  226.         ->setCellValue("A$totalRow",JText::_('COM_CN_REPORTS_TOTAL'))
  227.         ->setCellValue("B$totalRow","=SUM(B$startRow:B$finalRow)") // COUNT
  228.         ->setCellValue("C$totalRow","=SUM(C$startRow:C$finalRow)") // ocTotal
  229.         ->setCellValue("D$totalRow","=SUM(D$startRow:D$finalRow)") // Wholesale
  230.         ->setCellValue("E$totalRow","=SUM(E$startRow:E$finalRow)") // Voucher
  231.         ->setCellValue("F$totalRow","=SUM(F$startRow:F$finalRow)") // coupon
  232.         ->setCellValue("G$totalRow","=SUM(G$startRow:G$finalRow)") // Shipping
  233.         ->setCellValue("H$totalRow","=SUM(H$startRow:H$finalRow)") // Tax
  234.         ->setCellValue("I$totalRow","=SUM(I$startRow:I$finalRow)") // ActualProfitMargin
  235.         ->setCellValue("L$totalRow","=SUM(L$startRow:L$finalRow)"); // Commission
  236.  
  237.     // format teh footer background color
  238.     $as->getStyle("A$totalRow:L$totalRow")->getFill()
  239.     ->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
  240.     ->getStartColor()->setRGB($this->rowcolumnfooterbgcolor);
  241.     $as->getStyle("A$totalRow:L$totalRow")->applyFromArray($rowColumnFooterFontStyle);
  242.  
  243.     $cArray = array('C','D','E','F','G','H','I','L'); // array of columns that are to be formated as currency
  244.  
  245.     // loop the arrray and format the columns as currency
  246.     for ($i = 0; $i < count($cArray); $i++) {
  247.         $currentCol = $cArray[$i];
  248.         $range = $currentCol . $startRow . ':' . $currentCol . $totalRow;
  249.         $as->getStyle($range)->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
  250.     }
  251.     // format the commission percent column to percentage
  252.     $as->getStyle("K$startRow:K$totalRow")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_PERCENTAGE);
  253.     $row_commissions_totals = $totalRow;
  254.     $row_commissions_end = $totalRow;
  255.     $row_final = $totalRow;
  256.  
  257. ?>
  258. <?php
  259. // set a border around the commisssions section
  260. $as->getStyle("A$row_commissions_start:L$row_commissions_end")->applyFromArray($styleOutline);
  261. ?>
  262. <?php
  263. $overridesCount = count($this->rows[1]);
  264. // add overrides
  265. // only add overrides if there are some to add
  266. if ($overridesCount > 0)
  267. {
  268.     // $objPhpExcel->setActiveSheetIndex(1);
  269.     // $as = $objPhpExcel->getActiveSheet();
  270.     //Setup header row
  271.     $row_overrides_title = $overrideOffset + 1;
  272.     $row_index = $row_overrides_title + 1;
  273.     $data_row_offset = 3;
  274.  
  275.     //$as->setCellValueByColumnAndRow($column_index++, 1, JText::_('USERS.USERNAME'));
  276.     $as->mergeCells("E$row_index:H$row_index");
  277.     $as->getStyle("E$row_index")->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
  278.     $as->getStyle("E$row_index")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  279.     $as->setCellValue("E$row_index", JText::_('COM_CN_REPORTS_FORM_LBL_OVERRIDES_SHORT_DESC'));
  280.  
  281.     $as->setCellValue("I$row_index", JText::_('COM_CN_REPORTS_FORM_LBL_ORDERID'));
  282.  
  283.     $as->mergeCells("J$row_index:K$row_index");
  284.     $as->getStyle("J$row_index")->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
  285.     $as->getStyle("J$row_index")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  286.     $as->setCellValue("J$row_index", JText::_('COM_CN_REPORTS_FORM_LBL_OVERRIDES_CREATED_TIME'));
  287.  
  288.     $as->setCellValue("L$row_index", JText::_('COM_CN_REPORTS_FORM_LBL_OVERRIDES_AMOUNT'));
  289.     $as->getStyle("E$row_index:L$row_index")->getFill()
  290.         ->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
  291.         ->getStartColor()->setRGB($this->rowColumnHeaderBgColor);
  292.     $as->getStyle("E$row_index:L$row_index")->applyFromArray($rowColumnHeaderFontStyle);
  293.  
  294.     // Array that contains all the colums that require right alignment
  295.     $rArray = array('I','L');
  296.     // loop the array and set all the cells to right alignment
  297.     for ($i = 0; $i < count($rArray); $i++) {
  298.         $as->getStyle($rArray[$i] . $row_index)->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_RIGHT);
  299.     }
  300.     $row_final = $row_index;
  301. }
  302. ?>
  303. <?php
  304. // only add overrides if we have some
  305. if ($overridesCount > 0)
  306. {
  307.     for ($i = 0, $n = $overridesCount; $i < $n; $i++)
  308.     {
  309.         $row = &$this->rows[1][$i];
  310.  
  311.       //Write out data rows
  312.  
  313.         // convert the order date to unix time including cart timezone
  314.         // this seems to convert better to excel date time
  315.         $time = JFactory::getDate($row->created_time, $cartTz)->toUnix();
  316.         $column_index = 0;
  317.         $row_index = $i + $data_row_offset + $overrideOffset;
  318.         $as->mergeCells("E$row_index:H$row_index");
  319.         $as->getStyle("E$row_index")->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
  320.         $as->getStyle("E$row_index")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  321.         $as->getStyle("E$row_index")->getAlignment()->setWrapText(true);
  322.         $as->setCellValue("E$row_index", $row->override_short_desc);
  323.  
  324.         // only add the order_id if it is greater than zero. Less than 1 is a null
  325.         if(isset($row->order_id) && ((int)$row->order_id > 0))
  326.         {
  327.             $as->setCellValue("I$row_index", $row->order_id);
  328.         }
  329.  
  330.         $as->mergeCells("J$row_index:K$row_index"); // merge the date columns
  331.         // set the date formate on the order date cell for the current row
  332.         // Set the order date column to excel time from unix. This seems to convert better.
  333.         $as->setCellValue("J$row_index", PHPExcel_Shared_Date::PHPToExcel($time));
  334.         $as
  335.         ->getStyle("J$row_index")
  336.         ->getNumberFormat()
  337.         ->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_DATE_YYYYMMDDSLASH);
  338.  
  339.  
  340.         // set the alignment to left for the date
  341.         $as->getStyle("J$row_index")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  342.  
  343.         $as->getStyle("L$row_index")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
  344.         $as->setCellValue("L$row_index", $row->amount);
  345.         // set up alternate row formating for even rows
  346.         if (($i % 2) == 0) {
  347.             $as->getStyle("E$row_index:L$row_index")->getFill()
  348.             ->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
  349.             ->getStartColor()->setRGB($this->altRowaltBgColor);
  350.             $as->getStyle("E$row_index:L$row_index")->applyFromArray($rowAltRowFontStyle);
  351.         }
  352.         $row_final = $row_index;
  353.     }
  354. }
  355. ?>
  356. <?php
  357. // only add overrides if we have some
  358. if ($overridesCount > 0)
  359. {
  360.     // write the totals row for commission overrides
  361.     $finalRow = $row_index;
  362.     $startRow = $data_row_offset + $overrideOffset;
  363.     // $finalRow = count($this->rows[1]) + 1 + $overrideOffset;
  364.     $totalRow = $finalRow + 1;
  365.  
  366.     $as->setCellValue("E$totalRow",JText::_('COM_CN_REPORTS_TOTAL'));
  367.     $as->setCellValue("L$totalRow","=SUM(L$startRow:L$finalRow)"); // amount
  368.     // format teh footer background color
  369.     $as->getStyle("E$totalRow:L$totalRow")->getFill()
  370.             ->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
  371.             ->getStartColor()->setRGB($this->rowcolumnfooterbgcolor);
  372.  
  373.     $as->getStyle("L$totalRow")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
  374.     $as->getStyle("E$totalRow:L$totalRow")->applyFromArray($rowColumnFooterFontStyle);
  375.     $row_overrides_final = $totalRow;
  376.     $row_final = $totalRow;
  377. }
  378. ?>
  379. <?php
  380. // only add overrides if we have some
  381. if ($overridesCount > 0)
  382. {
  383.     $row_overrides_start = $row_overrides_title;
  384.     // set the column header title row for commissios
  385.     $as->mergeCells("E$row_overrides_title:L$row_overrides_title");
  386.     $as->getStyle("E$row_overrides_title")->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
  387.     $as->getStyle("E$row_overrides_title")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  388.  
  389.     $as->setCellValue("E$row_overrides_title",JText::_('COM_CN_REPORTS_FORM_TITLE_COMMISSIONS_OVERRIDES'));
  390.     $as->getStyle("E$row_overrides_title")->getFill()
  391.     ->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
  392.     ->getStartColor()->setRGB($this->rowColumnTitleBgColor);
  393.     $as->getStyle("E$row_overrides_title")->applyFromArray($rowColumnTitleFontStyle);
  394. }
  395. ?>
  396. <?php
  397. // set a border around the overrides section
  398. if ($overridesCount > 0)
  399. {
  400.     $as->getStyle("E$row_overrides_start:L$row_overrides_final")->applyFromArray($styleOutline);
  401. }
  402. ?>
  403. <?php
  404. // set the grand total sections
  405. // we will not need a grand total section if we have not overrides in this report
  406. if ($overridesCount > 0)
  407. {
  408.  
  409.     //Setup header row
  410.     $row_index = $row_overrides_final + 3;
  411.     $row_total_start = $row_index;
  412.     $as->mergeCells("E$row_index:L$row_index");
  413.     $as->getStyle("E$row_index")->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
  414.     $as->getStyle("E$row_index")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  415.     $as->setCellValue("E$row_index", JText::_('COM_CN_REPORTS_FORM_TITLE_GRAND_TOTAL'));
  416.  
  417.     $as->getStyle("E$row_index")->getFill()
  418.         ->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
  419.         ->getStartColor()->setRGB($this->rowColumnTitleBgColor);
  420.     $as->getStyle("E$row_index")->applyFromArray($rowColumnTitleFontStyle);
  421.  
  422.     // set up the commissions totals
  423.     $row_index++;
  424.     $row_total_total_overrides = $row_index;
  425.     $as->mergeCells("E$row_index:K$row_index");
  426.     $as->getStyle("E$row_index")->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
  427.     $as->getStyle("E$row_index")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  428.     $as->setCellValue("E$row_index",JText::_('COM_CN_REPORTS_FORM_LBL_COMMISSION_TOTAL'));
  429.     $as->setCellValue("L$row_index","=L$row_overrides_final");
  430.     $as->getStyle("L$row_index")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
  431.     // set the alternative style on the commission row
  432.     $as->getStyle("E$row_index:L$row_index")->getFill()
  433.     ->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
  434.     ->getStartColor()->setRGB($this->altRowaltBgColor);
  435.     $as->getStyle("E$row_index:L$row_index")->applyFromArray($rowAltRowFontStyle);
  436.  
  437.     // set up the overrides total row
  438.     $row_index++;
  439.     $row_total_total_commissions = $row_index;
  440.     $as->mergeCells("E$row_index:K$row_index");
  441.     $as->getStyle("E$row_index")->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
  442.     $as->getStyle("E$row_index")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  443.     $as->setCellValue("E$row_index",JText::_('COM_CN_REPORTS_FORM_LBL_OVERRIDES_TOTALS'));
  444.     $as->setCellValue("L$row_index","=L$row_commissions_totals");
  445.     $as->getStyle("L$row_index")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
  446.  
  447.     // set up the total of totals row
  448.     $row_index++;
  449.     $as->mergeCells("E$row_index:K$row_index");
  450.     $as->getStyle("E$row_index")->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
  451.     $as->getStyle("E$row_index")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  452.     $as->setCellValue("E$row_index",JText::_('COM_CN_REPORTS_FORM_LBL_GRAND_TOTAL'));
  453.     $as->setCellValue("L$row_index","=(L$row_total_total_commissions - L$row_total_total_overrides)");
  454.     $as->getStyle("L$row_index")->getNumberFormat()->setFormatCode(PHPExcel_Style_NumberFormat::FORMAT_CURRENCY_USD_SIMPLE);
  455.  
  456.     $as->getStyle("E$row_index:L$row_index")->getFill()
  457.     ->setFillType(PHPExcel_Style_Fill::FILL_SOLID)
  458.     ->getStartColor()->setRGB($this->rowcolumnfooterbgcolor);
  459.     $as->getStyle("E$row_index:L$row_index")->applyFromArray($rowColumnFooterFontStyle);
  460.  
  461.     $row_final = $row_index;
  462.     $row_total_end = $row_final;
  463. }
  464. ?>
  465. <?php
  466. // set a border around the totals section
  467. if ($overridesCount > 0)
  468. {
  469.     $as->getStyle("E$row_total_start:L$row_total_end")->applyFromArray($styleOutline);
  470. }
  471. ?>
  472. <?php
  473. // display the logo on the excel page for the compnent
  474. if (filter_var($this->showLogo, FILTER_VALIDATE_BOOLEAN) == true) {
  475.     $company_logo = $params->get('company_logo','');
  476.  
  477.     if ($company_logo !== "") {
  478.         // wrap in try block just incase the image fails
  479.         try {
  480.             $objDrawing = new PHPExcel_Worksheet_Drawing();
  481.             $objDrawing->setName('Logo');
  482.             $objDrawing->setDescription('Logo');
  483.             // setPath expects a filepath instead of a url
  484.             // Using forward slash to ensure php compatibality on other servers.
  485.             $objDrawing->setPath(JPATH_ROOT . '/' . $company_logo);
  486.             $objDrawing->setCoordinates('A1');
  487.             $objDrawing->setWorksheet($as);
  488.         } catch (Exception $e) {
  489.         }
  490.  
  491.     }
  492. }
  493.  
  494. ?>
  495. <?php
  496. // display the title text just under the logo
  497. // only display the title if the $rowRptDisplayTitle is greater than zero
  498. if ($rowRptDisplayTitle > 0)
  499. {
  500.     $as->mergeCells(cellsToMergeByColsRow(0,$col_count,$rowRptDisplayTitle));
  501.     $as->getStyle("A$rowRptDisplayTitle")->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_CENTER);
  502.     $as->getStyle("A$rowRptDisplayTitle")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
  503.     $as->getStyle("A$rowRptDisplayTitle")->applyFromArray($rowRptTitleFontStyle);
  504.     $as->getRowDimension($rowRptDisplayTitle)->setRowHeight(20);
  505.     $as->setCellValue("A$rowRptDisplayTitle",JText::sprintf('COM_CN_REPORTS_FORM_TITLE_COMISSIONS',
  506.                     $this->reportStart->format('Y-m-d'), $this->reportEnd->format('Y-m-d'),$this->partnerName));
  507. }
  508. ?>
  509. <?php
  510. // $rowHeaderText
  511. // display the report header
  512. $headerText = JHtml::_('contentadministrator.reportHeader');
  513. if (($rowHeaderText > 0) && ($headerText !== '')) {
  514.     $headerText = strip_tags($headerText);
  515.     $as->mergeCells(cellsToMergeByColsRow(0,$col_count,$rowHeaderText));
  516.     $as->getStyle("A$rowHeaderText")->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
  517.     $as->getStyle("A$rowHeaderText")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  518.     $as->getRowDimension($rowHeaderText)->setRowHeight(40);
  519.     $as->getStyle("A$rowHeaderText")->getAlignment()->setWrapText(true);
  520.     $as->setCellValue("A$rowHeaderText",$headerText);
  521. }
  522. ?>
  523. <?php
  524. // $rowHeaderText
  525. // display the report footer
  526. $footerText = JHtml::_('contentadministrator.reportFooter');
  527. if (($rowFooterText > 0) && ($footerText !== '')) {
  528.     $footerText = strip_tags($footerText);
  529.     $row_index = $rowFooterText + $row_final;
  530.     $as->mergeCells(cellsToMergeByColsRow(0,$col_count,$row_index));
  531.     $as->getStyle("A$row_index")->getAlignment()->setVertical(PHPExcel_Style_Alignment::VERTICAL_TOP);
  532.     $as->getStyle("A$row_index")->getAlignment()->setHorizontal(PHPExcel_Style_Alignment::HORIZONTAL_LEFT);
  533.     $as->getRowDimension($row_index)->setRowHeight(40);
  534.     $as->getStyle("A$row_index")->getAlignment()->setWrapText(true);
  535.     $as->setCellValue("A$row_index",$footerText);
  536.     $row_final = $row_index;
  537. }
  538. ?>
  539. <?php
  540. // set the print area
  541. $as->getPageSetup()->setPrintArea("A1:L$row_final");
  542. $as->setShowGridlines(filter_var($this->showGrid, FILTER_VALIDATE_BOOLEAN));
  543. ?>
  544. <?php
  545. function cellsToMergeByColsRow($start = -1, $end = -1, $row = -1){
  546.     $merge = 'A1:A1';
  547.     if($start>=0 && $end>=0 && $row>=0){
  548.         $start = PHPExcel_Cell::stringFromColumnIndex($start);
  549.         $end = PHPExcel_Cell::stringFromColumnIndex($end);
  550.         $merge = "$start{$row}:$end{$row}";
  551.     }
  552.     return $merge;
  553. }
  554. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement