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'); }
$koncetrats = explode(",", trim($_REQUEST['konc'])); foreach ($koncetrats as $value) { $tovar_konc = new KoncentrTovarishestvo(); $tovar_konc->id_tovar = $tovar->id; $tovar_konc->name_konc = $value; $tovar_konc->save(); } Flight::redirect("/admin/associations?success=3"); } else { $tovar = Tovarishestva::find_by_id($_REQUEST['id']); $tovar->name = trim(strip_tags($_REQUEST['name'])); $tovar->save(); KoncentrTovarishestvo::table()->delete(array('id_tovar' => $tovar->id)); $koncetrats = explode(",", trim($_REQUEST['konc'])); foreach ($koncetrats as $value) { $tovar_konc = new KoncentrTovarishestvo(); $tovar_konc->id_tovar = $tovar->id; $tovar_konc->name_konc = trim($value); $tovar_konc->save(); } Flight::redirect("/admin/associations?success=2"); } } ?> <!-- line modal --> <div class="modal fade" id="squarespaceModal" tabindex="-1" role="dialog" aria-labelledby="modalLabel" aria-hidden="true"> <div class="modal-dialog"> <div class="modal-content"> <div class="modal-header"> <button type="button" class="close" data-dismiss="modal"><span aria-hidden="true">x</span><span class="sr-only">Close</span></button> <h3 class="modal-title" id="lineModalLabel">Добавление пользователя</h3>