Esempio n. 1
0
 public function generateReport()
 {
     require_once PATH_LIBS . 'phpexcel/PHPExcel.php';
     require_once PATH_LIBS . 'phpexcel/PHPExcel/Writer/Excel2007.php';
     $xls = PHPExcel_IOFactory::load($_SERVER['DOCUMENT_ROOT'] . '/../reports/report.xls');
     $xls->setActiveSheetIndex(0);
     $sheet = $xls->getActiveSheet();
     $KoncentrTovarishestvo = KoncentrTovarishestvo::find_by_sql('SELECT * FROM `counter` inner join `koncentrator_tovarishestvo` on `koncentrator_tovarishestvo`.`name_konc` = `counter`.`concetrator` WHERE `id_tovar` = ' . $_REQUEST['tovarishestvo']);
     $date_start = explode('.', $_REQUEST[Report::DATE_START]);
     $date_start_string = $date_start[2] . '.' . $date_start[1] . '.' . $date_start[0];
     $date_end = explode('.', $_REQUEST[Report::DATE_END]);
     $date_end_string = $date_end[2] . '.' . $date_end[1] . '.' . $date_end[0];
     $i = 10;
     $j = 1;
     foreach ($KoncentrTovarishestvo as $counter) {
         $user = User::find('all', ['conditions' => ['counter = ? and concetrator =?', $counter->counter, $counter->concetrator]]);
         if ($user != null) {
             $sheet->setCellValue('A' . $i, $j);
             $sheet->setCellValue('B' . $i, 'ТП-Рында');
             $sheet->setCellValue('C' . $i, $user[0]->fio);
             $sheet->setCellValue('E' . $i, $user[0]->address);
             $sheet->setCellValue('F' . $i, $user[0]->n_scet);
             $sheet->setCellValue('M' . $i, $counter->date);
             $sheet->setCellValue('N' . $i, (int) $counter->reading);
             $i++;
             $j++;
         }
     }
     $i += 3;
     $sheet->setCellValue('M' . $i, 'От Исполнителя: ______________________________________');
     $i++;
     $sheet->setCellValue('M' . $i, '(должность, подпись, ФИО)');
     $objWriter = new PHPExcel_Writer_Excel5($xls);
     $Tovarishestvo = Tovarishestva::find('all', ['conditions' => ['id = ?', $_REQUEST['tovarishestvo']]]);
     header("Content-type: application/vnd.ms-excel");
     header("Content-Disposition: attachment; filename=" . $Tovarishestvo[0]->name . " " . $_REQUEST[Report::DATE_START] . "-" . $_REQUEST[Report::DATE_END] . ".xls");
     $objWriter->save('php://output');
 }