/** * Возвращает модель по указанному идентификатору * Если модель не будет найдена - возникнет HTTP-исключение. * * @param integer идентификатор нужной модели * * @return void */ public function loadModel($id) { $model = Cost::model()->findByPk($id); if ($model === null) { throw new CHttpException(404, Yii::t('BalanceModule.balance', 'Запрошенная страница не найдена.')); } return $model; }
* @license https://github.com/yupe/yupe/blob/master/LICENSE BSD * @link http://yupe.ru **/ $form = $this->beginWidget('bootstrap.widgets.TbActiveForm', ['action' => Yii::app()->createUrl($this->route), 'method' => 'get', 'type' => 'vertical', 'htmlOptions' => ['class' => 'well']]); ?> <fieldset> <div class="row"> <div class="col-sm-3"> <?php echo $form->textFieldGroup($model, 'id', ['widgetOptions' => ['htmlOptions' => ['class' => 'popover-help', 'data-original-title' => $model->getAttributeLabel('id'), 'data-content' => $model->getAttributeDescription('id')]]]); ?> </div> <div class="col-sm-3"> <?php echo $form->dropDownListGroup($model, 'cost_id', ['widgetOptions' => ['data' => CHtml::listData(Cost::model()->findAll(), 'id', 'name')]]); ?> </div> <div class="col-sm-3"> <?php echo $form->textFieldGroup($model, 'receiver', ['widgetOptions' => ['htmlOptions' => ['class' => 'popover-help', 'data-original-title' => $model->getAttributeLabel('receiver'), 'data-content' => $model->getAttributeDescription('receiver')]]]); ?> </div> <div class="col-sm-3"> <?php echo $form->textFieldGroup($model, 'date', ['widgetOptions' => ['htmlOptions' => ['class' => 'popover-help', 'data-original-title' => $model->getAttributeLabel('date'), 'data-content' => $model->getAttributeDescription('date')]]]); ?> </div> <div class="col-sm-3"> <?php echo $form->textFieldGroup($model, 'price', ['widgetOptions' => ['htmlOptions' => ['class' => 'popover-help', 'data-original-title' => $model->getAttributeLabel('price'), 'data-content' => $model->getAttributeDescription('price')]]]);
public function actionPrint($inflow, $outflow, $totalArr, $in, $out) { $costArr = Cost::model()->findAll(); $codeArr = Subject::model()->findAll(); ////////////////////////////////////////////////////////////////////// //Формирование файла exel $phpExcelPath = Yii::getPathOfAlias('application.components.phpexel'); include $phpExcelPath . DIRECTORY_SEPARATOR . 'PHPExcel.php'; $objPHPExcel = new PHPExcel(); $objPHPExcel->getProperties()->setCreator("Спасибоку")->setLastModifiedBy("system")->setTitle("Балансовая ведомость")->setSubject("Спасибоку")->setDescription("Балансовая ведомость, отражающая приход и расход")->setKeywords("Приход,Расход,Итог")->setCategory("Отчет"); //Создание вкладок $sheet1 = $objPHPExcel->createSheet(0); $sheet2 = $objPHPExcel->createSheet(1); $sheet3 = $objPHPExcel->createSheet(2); $sheet1->setTitle("Приход"); $sheet2->setTitle("Расход"); $sheet3->setTitle("Итог"); //Создание заголовков $sheet1->setCellValue("A1", "Дата")->setCellValue("B1", "Шифр")->setCellValue("C1", "Основание")->setCellValue("D1", "Исполнитель")->setCellValue("E1", "Оплата")->setCellValue("F1", "Другая информация")->setCellValue("H1", "Наименование услуги")->setCellValue("I1", "Шифр"); $sheet2->setCellValue("A1", "Дата")->setCellValue("B1", "Шифр")->setCellValue("C1", "Получатель")->setCellValue("D1", "Сумма")->setCellValue("E1", "Основание")->setCellValue("F1", "Комментарий")->setCellValue("H1", "Наименование")->setCellValue("I1", "Шифр"); $sheet3->setCellValue("A1", "Дата")->setCellValue("B1", "Приход")->setCellValue("C1", "Расход"); $sheet1->getStyle('A1:F1')->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'dbd8e9')))); $sheet1->getStyle('H1:I1')->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'dbd8e9')))); $sheet2->getStyle('A1:F1')->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'dbd8e9')))); $sheet2->getStyle('H1:I1')->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'dbd8e9')))); $sheet3->getStyle('A1:C1')->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'dbd8e9')))); //Inflow $i = 2; foreach ($codeArr as $value) { if ($i % 2 != 0) { $sheet1->getStyle('H' . $i . ':I' . $i)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'B8CCE4')))); } $sheet1->setCellValue("H" . $i, $value->name)->setCellValue("I" . $i, $value->code); $i++; } $i = 2; foreach ($inflow as $value) { if ($i % 2 != 0) { $sheet1->getStyle('A' . $i . ':F' . $i)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'B8CCE4')))); } $sheet1->setCellValue("A" . $i, $value->date)->setCellValue("B" . $i, $value->subject->code)->setCellValue("C" . $i, $value->based)->setCellValue("D" . $i, $value->receiver)->setCellValue("E" . $i, $value->form->price)->setCellValue("F" . $i, $value->comment); $i++; } $sheet1->setCellValue('A' . $i, "Итог:"); $sheet1->setCellValue('B' . $i, $in); //Outflow $i = 2; foreach ($costArr as $value) { if ($i % 2 != 0) { $sheet2->getStyle('H' . $i . ':I' . $i)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'B8CCE4')))); } $sheet2->setCellValue("H" . $i, $value->name)->setCellValue("I" . $i, $value->code); $i++; } $i = 2; foreach ($outflow as $value) { if ($i % 2 != 0) { $sheet2->getStyle('A' . $i . ':F' . $i)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'B8CCE4')))); } $sheet2->setCellValue("A" . $i, $value->date)->setCellValue("B" . $i, $value->cost->name)->setCellValue("C" . $i, $value->receiver)->setCellValue("D" . $i, $value->price)->setCellValue("E" . $i, $value->based)->setCellValue("F" . $i, $value->note); $i++; } $sheet2->setCellValue('A' . $i, "Итог:"); $sheet2->setCellValue('B' . $i, $out); //Total $i = 2; foreach ($totalArr as $value) { if ($i % 2 != 0) { $sheet3->getStyle('A' . $i . ':C' . $i)->applyFromArray(array('fill' => array('type' => PHPExcel_Style_Fill::FILL_SOLID, 'color' => array('rgb' => 'B8CCE4')))); } $sheet3->setCellValue("A" . $i, $value['date'])->setCellValue("B" . $i, $value['inflow'])->setCellValue("C" . $i, $value['outflow']); $i++; } $x = array_pop($totalArr); $sheet3->setCellValue("A" . $i, "Итог"); $sheet3->setCellValue("C" . $i, $x['total']); ////////////////////////////////////////////////////////////// // Автоматическое скачивание файла header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); header('Content-Disposition: attachment;filename="Отчет.xlsx"'); header('Cache-Control: max-age=0'); $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save('php://output'); //////////////////// }