/** * Finds the TrMatOsmotr model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param string $id * @return TrMatOsmotr the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = TrMatOsmotr::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionDelete($id) { if (Yii::$app->request->isAjax) { $transaction = Yii::$app->db->beginTransaction(); try { TrMatOsmotr::deleteAll(['id_osmotraktmat' => $id]); echo $this->findModel($id)->delete(); $transaction->commit(); } catch (Exception $e) { $transaction->rollBack(); throw new Exception($e->getMessage() . ' Удаление невозможно.'); } } }
protected function Body() { $ID = $this->getDopparamID(); $this->setReportName('Акт осмотра материалов №' . $ID); $Osmotraktmat = Osmotraktmat::findOne($ID); $TrMatOsmotr = TrMatOsmotr::findAll(['id_osmotraktmat' => $ID]); $Mols = TrMatOsmotr::getMolsByTrMatOsmotr($ID); $objPHPExcel = $this->getObjPHPExcel(); $objPHPExcel->getActiveSheet()->setCellValue('A3', 'материалов № ' . $Osmotraktmat->osmotraktmat_id . ' от ' . Yii::$app->formatter->asDate($Osmotraktmat->osmotraktmat_date)); $num = 7; foreach ($TrMatOsmotr as $ar) { $objPHPExcel->getActiveSheet()->insertNewRowBefore($num); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $num, $num - 6); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $num, $ar->idTrMat->idMattraffic->idMaterial->idMatv->matvid_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, $num, $ar->idTrMat->idMattraffic->idMaterial->material_name); $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow(3, $num, $ar->idTrMat->idMattraffic->idMaterial->material_inv, \PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(4, $num, !empty($ar->idTrMat->idParent) ? 'Инв. номер: ' . $ar->idTrMat->idParent->idMaterial->material_inv . ', ' . $ar->idTrMat->idParent->idMaterial->material_name : ''); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5, $num, $ar->tr_mat_osmotr_number); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6, $num, $ar->idTrMat->idMattraffic->idMaterial->idIzmer->izmer_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, $num, $ar->idReason->reason_text . (empty($ar->idReason->reason_text) ? '' : '. ') . $ar->tr_mat_osmotr_comment); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8, $num, $ar->idTrMat->idMattraffic->idMol->idperson->auth_user_fullname . ', ' . $ar->idTrMat->idMattraffic->idMol->iddolzh->dolzh_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(9, $num, TrMatOsmotr::getBuildandKabByTrMatOsmotr($ar->primaryKey)); $objPHPExcel->getActiveSheet()->getStyle('A' . $num . ':J' . $num)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT); $num++; } $objPHPExcel->getActiveSheet()->removeRow($num); $crows = count($TrMatOsmotr); $num = 8; foreach ($Mols as $ar) { $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $num + $crows, 'Материально ответственное лицо'); $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(0, $num + $crows, 1, $num + $crows); $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(3, $num + $crows, 6, $num + $crows); $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(7, $num + $crows, 9, $num + $crows); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, $num + $crows, $ar['dolzh_name']); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, $num + $crows, $ar['auth_user_fullname']); $objPHPExcel->getActiveSheet()->insertNewRowBefore($num + $crows + 1); $num++; } $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, $num + $crows + 1, $Osmotraktmat->idMaster->idperson->auth_user_fullname); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, $num + $crows + 1, $Osmotraktmat->idMaster->iddolzh->dolzh_name); $objPHPExcel->getActiveSheet()->removeRow($num + $crows); }
/** * @param $objPHPExcel * @param null $ID */ protected function Body() { $ID = $this->getDopparamID(); $this->setReportName('Акт передачи материалов сторонней организации №' . $ID); $Recoverysendakt = Recoverysendakt::findOne($ID); $Recoveryrecieveaktmat = Recoveryrecieveaktmat::findAll(['id_recoverysendakt' => $ID]); $Mols = Recoveryrecieveaktmat::getMolsByRecoverysendakt($ID); $objPHPExcel = $this->getObjPHPExcel(); $objPHPExcel->getActiveSheet()->setCellValue('A3', 'сторонней организации № ' . $Recoverysendakt->recoverysendakt_id . ' от ' . Yii::$app->formatter->asDate($Recoverysendakt->recoverysendakt_date)); $objPHPExcel->getActiveSheet()->setCellValue('C4', $Recoverysendakt->idOrgan->organ_name); $material_tip = Material::VariablesValues('material_tip'); $num = 9; foreach ($Recoveryrecieveaktmat as $ar) { $objPHPExcel->getActiveSheet()->insertNewRowBefore($num); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $num, $num - 8); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $num, $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->idMatv->matvid_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, $num, $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->material_name); $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow(3, $num, $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->material_inv, \PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(4, $num, $material_tip[$ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->material_tip]); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5, $num, $ar->idTrMatOsmotr->tr_mat_osmotr_number); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6, $num, $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->idIzmer->izmer_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, $num, $ar->idTrMatOsmotr->idReason->reason_text . (empty($ar->idTrMatOsmotr->idReason->reason_text) ? '' : '. ') . $ar->idTrMatOsmotr->tr_mat_osmotr_comment); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8, $num, $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMol->idperson->auth_user_fullname . ', ' . $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMol->iddolzh->dolzh_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(9, $num, TrMatOsmotr::getBuildandKabByTrMatOsmotr($ar->idTrMatOsmotr->tr_mat_osmotr_id)); $objPHPExcel->getActiveSheet()->getStyle('A' . $num . ':J' . $num)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT); $num++; } $objPHPExcel->getActiveSheet()->removeRow($num); $crows = count($Recoveryrecieveaktmat); $num = 10; foreach ($Mols as $ar) { $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $num + $crows, 'Материально ответственное лицо'); $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(0, $num + $crows, 1, $num + $crows); $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(3, $num + $crows, 6, $num + $crows); $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(7, $num + $crows, 9, $num + $crows); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, $num + $crows, $ar['dolzh_name']); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, $num + $crows, $ar['auth_user_fullname']); $objPHPExcel->getActiveSheet()->insertNewRowBefore($num + $crows + 1); $num++; } $objPHPExcel->getActiveSheet()->removeRow($num + $crows); }
/** * @return \yii\db\ActiveQuery */ public function getTrMatOsmotrs() { return $this->hasMany(TrMatOsmotr::className(), ['id_tr_mat' => 'tr_mat_id'])->from(['trMatOsmotrs' => TrMatOsmotr::tableName()]); }
public static function Recoverysendakt_ExportExcel() { $objPHPExcel = new \PHPExcel(); $reportName = 'Выгрузка'; /* Границы таблицы */ $ramka = array('borders' => array('allborders' => ['style' => \PHPExcel_Style_Border::BORDER_THIN])); /* Жирный шрифт для шапки таблицы */ $font = array('font' => array('bold' => true), 'alignment' => array('horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_CENTER)); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, 1, $reportName); $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(0, 1)->applyFromArray(['font' => ['bold' => true, 'size' => 14]]); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, 2, 'Дата: ' . date('d.m.Y')); $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(0, 2)->applyFromArray(['font' => ['italic' => true]]); $params = Yii::$app->request->queryParams; $inputdata = json_decode($params['inputdata']); // $fields = Proc::GetArrayValuesByKeyName($modelName, $inputdata); // $selectvalues = (array) $selectvalues; $filter = 'Фильтр:'; /* foreach ($fields[$modelName] as $attr => $value) { $val_result = $value; if (!empty($value)) { if (isset($selectvalues[$modelName . '[' . $attr . ']'])) $val_result = $selectvalues[$modelName . '[' . $attr . ']'][$fields[$modelName][$attr]]; $filter .= ' ' . $labels[$attr] . ': "' . $val_result . '";'; } } */ /* if ($ModelFilter instanceof Model) { $dopfilter = self::ConstructFilterOutput($ModelFilter); if (!empty($dopfilter)) $filter .= ' ' . $dopfilter; } */ $num = 5; // $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(0, 1, 10, 1); self::SetTitlebyArray($objPHPExcel, ['№', 'Тип материальной ценности', 'Вид материальной ценности', 'Наименование', 'Инвентарный номер', 'Серийный номер', 'Дата выпуска', 'Стоимость', 'Списание', 'Количество', 'Единица измерения', 'Материально-ответственное лицо', 'Здание', 'Кабинет', 'Укомплектовано в', 'Инвентарный номер мат-ой цен-ти в которую укомплектовано', 'Номер акта осмотра', 'Дата акта осмотра', 'Вид акта осмотра', 'Мастер', 'Причина неисправности', 'Пользователь', 'Организация', 'Дата отправки', 'Дата получения', 'Результат', 'Подлежит восстановлению'], $num); for ($i = 0; $i <= 26; $i++) { $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow($i, $num)->applyFromArray($font); } $num++; $Recoveryrecieveakt = Recoveryrecieveakt::find()->joinWith(['idRecoverysendakt.idOrgan', 'idOsmotrakt.idReason', 'idOsmotrakt.idUser idUser', 'idOsmotrakt.idMaster idMaster', 'idOsmotrakt.idUser.idperson idpersonuser', 'idOsmotrakt.idUser.iddolzh iddolzhuser', 'idOsmotrakt.idMaster.idperson idpersonmaster', 'idOsmotrakt.idMaster.iddolzh iddolzhmaster', 'idOsmotrakt.idTrosnov.idMattraffic.idMaterial.idMatv', 'idOsmotrakt.idTrosnov.idMattraffic.idMaterial.idIzmer', 'idOsmotrakt.idTrosnov.idMattraffic.idMol.idperson', 'idOsmotrakt.idTrosnov.idMattraffic.idMol.iddolzh', 'idOsmotrakt.idTrosnov.idMattraffic.idMol.idbuild'])->orderBy(['idOsmotrakt.osmotrakt_date' => SORT_ASC])->all(); $material_tip = Material::VariablesValues('material_tip'); $material_writeoff = Material::VariablesValues('material_writeoff'); $recoveryrecieveakt_repaired = Recoveryrecieveakt::VariablesValues('recoveryrecieveakt_repaired'); foreach ($Recoveryrecieveakt as $ar) { $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $num, $num - 5); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $num, $material_tip[$ar->idOsmotrakt->idTrosnov->idMattraffic->idMaterial->material_tip]); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, $num, $ar->idOsmotrakt->idTrosnov->idMattraffic->idMaterial->idMatv->matvid_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, $num, $ar->idOsmotrakt->idTrosnov->idMattraffic->idMaterial->material_name); $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow(4, $num, $ar->idOsmotrakt->idTrosnov->idMattraffic->idMaterial->material_inv, \PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow(5, $num, $ar->idOsmotrakt->idTrosnov->idMattraffic->idMaterial->material_serial, \PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6, $num, Yii::$app->formatter->asDate($ar->idOsmotrakt->idTrosnov->idMattraffic->idMaterial->material_release)); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, $num, $ar->idOsmotrakt->idTrosnov->idMattraffic->idMaterial->material_price); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8, $num, $material_writeoff[$ar->idOsmotrakt->idTrosnov->idMattraffic->idMaterial->material_writeoff]); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(9, $num, 1); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(10, $num, $ar->idOsmotrakt->idTrosnov->idMattraffic->idMaterial->idIzmer->izmer_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(11, $num, $ar->idOsmotrakt->idTrosnov->idMattraffic->idMol->idperson->auth_user_fullname . ', ' . $ar->idOsmotrakt->idTrosnov->idMattraffic->idMol->iddolzh->dolzh_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(12, $num, empty($ar->idOsmotrakt->idTrosnov->idMattraffic->idMol->idbuild->build_name) ? '' : $ar->idOsmotrakt->idTrosnov->idMattraffic->idMol->idbuild->build_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(13, $num, $ar->idOsmotrakt->idTrosnov->tr_osnov_kab); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(14, $num, ''); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(15, $num, ''); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(16, $num, $ar->idOsmotrakt->osmotrakt_id); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(17, $num, Yii::$app->formatter->asDate($ar->idOsmotrakt->osmotrakt_date)); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(18, $num, 'Материальная ценность'); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(19, $num, $ar->idOsmotrakt->idMaster->idperson->auth_user_fullname . ', ' . $ar->idOsmotrakt->idMaster->iddolzh->dolzh_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(20, $num, (empty($ar->idOsmotrakt->idReason->reason_text) ? '' : $ar->idOsmotrakt->idReason->reason_text . ', ') . $ar->idOsmotrakt->osmotrakt_comment); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(21, $num, $ar->idOsmotrakt->idUser->idperson->auth_user_fullname . ', ' . $ar->idOsmotrakt->idUser->iddolzh->dolzh_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(22, $num, $ar->idRecoverysendakt->idOrgan->organ_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(23, $num, Yii::$app->formatter->asDate($ar->idRecoverysendakt->recoverysendakt_date)); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(24, $num, Yii::$app->formatter->asDate($ar->recoveryrecieveakt_date)); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(25, $num, $ar->recoveryrecieveakt_result); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(26, $num, empty($ar->recoveryrecieveakt_repaired) ? '' : $recoveryrecieveakt_repaired[$ar->recoveryrecieveakt_repaired]); $num++; } $Recoveryrecieveaktmat = Recoveryrecieveaktmat::find()->joinWith(['idRecoverysendakt.idOrgan', 'idTrMatOsmotr.idReason', 'idTrMatOsmotr.idOsmotraktmat.idMaster idMaster', 'idTrMatOsmotr.idOsmotraktmat.idMaster.idperson idpersonmaster', 'idTrMatOsmotr.idOsmotraktmat.idMaster.iddolzh iddolzhmaster', 'idTrMatOsmotr.idTrMat.idMattraffic.idMaterial.idMatv', 'idTrMatOsmotr.idTrMat.idMattraffic.idMaterial.idIzmer', 'idTrMatOsmotr.idTrMat.idMattraffic.idMol.idperson', 'idTrMatOsmotr.idTrMat.idMattraffic.idMol.iddolzh', 'idTrMatOsmotr.idTrMat.idMattraffic.idMol.idbuild', 'idTrMatOsmotr.idTrMat.idParent idParent'])->orderBy(['idOsmotraktmat.osmotraktmat_date' => SORT_ASC])->all(); $recoveryrecieveaktmat_repaired = Recoveryrecieveaktmat::VariablesValues('recoveryrecieveaktmat_repaired'); foreach ($Recoveryrecieveaktmat as $ar) { $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $num, $num - 5); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $num, $material_tip[$ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->material_tip]); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, $num, $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->idMatv->matvid_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, $num, $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->material_name); $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow(4, $num, $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->material_inv, \PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow(5, $num, $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->material_serial, \PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6, $num, Yii::$app->formatter->asDate($ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->material_release)); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, $num, $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->material_price); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8, $num, $material_writeoff[$ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->material_writeoff]); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(9, $num, $ar->idTrMatOsmotr->tr_mat_osmotr_number); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(10, $num, $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->idIzmer->izmer_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(11, $num, $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMol->idperson->auth_user_fullname . ', ' . $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMol->iddolzh->dolzh_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(12, $num, empty($ar->idTrMatOsmotr->idTrMat->idMattraffic->idMol->idbuild->build_name) ? '' : $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMol->idbuild->build_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(13, $num, TrMatOsmotr::getBuildandKabByTrMatOsmotr($ar->id_tr_mat_osmotr)); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(14, $num, $ar->idTrMatOsmotr->idTrMat->idParent->material_name); $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow(15, $num, $ar->idTrMatOsmotr->idTrMat->idParent->material_inv, \PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(16, $num, $ar->idTrMatOsmotr->idOsmotraktmat->osmotraktmat_id); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(17, $num, Yii::$app->formatter->asDate($ar->idTrMatOsmotr->idOsmotraktmat->osmotraktmat_date)); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(18, $num, 'Материал'); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(19, $num, $ar->idTrMatOsmotr->idOsmotraktmat->idMaster->idperson->auth_user_fullname . ', ' . $ar->idTrMatOsmotr->idOsmotraktmat->idMaster->iddolzh->dolzh_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(20, $num, (empty($ar->idTrMatOsmotr->idReason->reason_text) ? '' : $ar->idTrMatOsmotr->idReason->reason_text . ', ') . $ar->idTrMatOsmotr->tr_mat_osmotr_comment); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(21, $num, ''); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(22, $num, $ar->idRecoverysendakt->idOrgan->organ_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(23, $num, Yii::$app->formatter->asDate($ar->idRecoverysendakt->recoverysendakt_date)); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(24, $num, Yii::$app->formatter->asDate($ar->recoveryrecieveaktmat_date)); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(25, $num, $ar->recoveryrecieveaktmat_result); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(26, $num, empty($ar->recoveryrecieveaktmat_repaired) ? '' : $recoveryrecieveaktmat_repaired[$ar->recoveryrecieveaktmat_repaired]); $num++; } /* Авторазмер колонок Excel */ $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn(0)->setWidth(6); $objPHPExcel->getActiveSheet()->getStyle('A5:AA' . ($num - 1))->applyFromArray($ramka); for ($i = 1; $i <= 26; $i++) { $objPHPExcel->getActiveSheet()->getColumnDimensionByColumn($i)->setAutoSize(true); } /* if ($filter !== 'Фильтр:') { $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, 3, $filter); $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(0, 3, $i, 3); $objPHPExcel->getActiveSheet()->getStyleByColumnAndRow(0, 3)->applyFromArray([ 'font' => [ 'italic' => true ] ]); } */ // присваиваем имя файла от имени модели $FileName = $reportName; // Устанавливаем имя листа $objPHPExcel->getActiveSheet()->setTitle($FileName); // Выбираем первый лист $objPHPExcel->setActiveSheetIndex(0); // Формируем файл Excel $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $FileName = DIRECTORY_SEPARATOR === '/' ? $FileName : mb_convert_encoding($FileName, 'Windows-1251', 'UTF-8'); // Proc::SaveFileIfExists() - Функция выводит подходящее имя файла, которое еще не существует. mb_convert_encoding() - Изменяем кодировку на кодировку Windows $fileroot = Proc::SaveFileIfExists('files/' . $FileName . '.xlsx'); // Сохраняем файл в папку "files" $objWriter->save('files/' . $fileroot); // Возвращаем имя файла Excel if (DIRECTORY_SEPARATOR === '/') { echo $fileroot; } else { echo mb_convert_encoding($fileroot, 'UTF-8', 'Windows-1251'); } }
/** * @return \yii\db\ActiveQuery */ public function getIdTrMatOsmotr() { return $this->hasOne(TrMatOsmotr::className(), ['tr_mat_osmotr_id' => 'id_tr_mat_osmotr'])->from(['idTrMatOsmotr' => TrMatOsmotr::tableName()]); }
protected function Body() { $ID = $this->getDopparamID(); $this->setReportName('Акт получения материалов у сторонней организации №' . $ID); $Recoverysendakt = Recoverysendakt::findOne($ID); $Recoveryrecieveaktmat_ok = Recoveryrecieveaktmat::find()->andWhere(['id_recoverysendakt' => $ID, 'recoveryrecieveaktmat_repaired' => 2])->all(); $Recoveryrecieveaktmat_fail = Recoveryrecieveaktmat::find()->andWhere(['and', ['id_recoverysendakt' => $ID], ['or', ['recoveryrecieveaktmat_repaired' => 1], ['recoveryrecieveaktmat_repaired' => NULL]]])->all(); $Mols = Recoveryrecieveaktmat::getMolsByRecoverysendakt($ID); $objPHPExcel = $this->getObjPHPExcel(); $objPHPExcel->getActiveSheet()->setCellValue('F4', $Recoverysendakt->idOrgan->organ_name); $objPHPExcel->getActiveSheet()->setCellValue('F5', $Recoverysendakt->recoverysendakt_id . ' от ' . Yii::$app->formatter->asDate($Recoverysendakt->recoverysendakt_date)); $objPHPExcel->getActiveSheet()->setCellValue('F6', Yii::$app->formatter->asDate(date('Y-m-d'))); $material_tip = Material::VariablesValues('material_tip'); $num = 11; foreach ($Recoveryrecieveaktmat_ok as $ar) { $objPHPExcel->getActiveSheet()->insertNewRowBefore($num); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $num, $num - 10); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $num, $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->idMatv->matvid_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, $num, $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->material_name); $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow(3, $num, $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->material_inv, \PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(4, $num, $material_tip[$ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->material_tip]); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5, $num, $ar->idTrMatOsmotr->tr_mat_osmotr_number); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6, $num, $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->idIzmer->izmer_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, $num, $ar->recoveryrecieveaktmat_result); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8, $num, $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMol->idperson->auth_user_fullname . ', ' . $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMol->iddolzh->dolzh_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(9, $num, TrMatOsmotr::getBuildandKabByTrMatOsmotr($ar->id_tr_mat_osmotr)); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(10, $num, Yii::$app->formatter->asDate($ar->recoveryrecieveaktmat_date)); $objPHPExcel->getActiveSheet()->getStyle('A' . $num . ':K' . $num)->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT); $num++; } $objPHPExcel->getActiveSheet()->removeRow($num); $crows = count($Recoveryrecieveaktmat_ok); $num = 15; foreach ($Recoveryrecieveaktmat_fail as $ar) { $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $num + $crows, $num + $crows - 15); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(1, $num + $crows, $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->idMatv->matvid_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(2, $num + $crows, $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->material_name); $objPHPExcel->getActiveSheet()->setCellValueExplicitByColumnAndRow(3, $num + $crows, $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->material_inv, \PHPExcel_Cell_DataType::TYPE_STRING); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(4, $num + $crows, $material_tip[$ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->material_tip]); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(5, $num + $crows, $ar->idTrMatOsmotr->tr_mat_osmotr_number); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(6, $num + $crows, $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMaterial->idIzmer->izmer_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, $num + $crows, $ar->recoveryrecieveaktmat_result); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(8, $num + $crows, $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMol->idperson->auth_user_fullname . ', ' . $ar->idTrMatOsmotr->idTrMat->idMattraffic->idMol->iddolzh->dolzh_name); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(9, $num + $crows, TrMatOsmotr::getBuildandKabByTrMatOsmotr($ar->id_tr_mat_osmotr)); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(10, $num + $crows, Yii::$app->formatter->asDate($ar->recoveryrecieveaktmat_date)); $objPHPExcel->getActiveSheet()->getStyle('A' . ($num + $crows) . ':K' . ($num + $crows))->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_LEFT); $objPHPExcel->getActiveSheet()->insertNewRowBefore($num + $crows + 1); $num++; } $objPHPExcel->getActiveSheet()->removeRow($num + $crows); $crows = count($Recoveryrecieveaktmat_ok) + count($Recoveryrecieveaktmat_fail); $num = 17; foreach ($Mols as $ar) { $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(0, $num + $crows, 'Материально ответственное лицо'); $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(0, $num + $crows, 1, $num + $crows); $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(3, $num + $crows, 6, $num + $crows); $objPHPExcel->getActiveSheet()->mergeCellsByColumnAndRow(7, $num + $crows, 10, $num + $crows); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(3, $num + $crows, $ar['dolzh_name']); $objPHPExcel->getActiveSheet()->setCellValueByColumnAndRow(7, $num + $crows, $ar['auth_user_fullname']); $objPHPExcel->getActiveSheet()->insertNewRowBefore($num + $crows + 1); $num++; } $objPHPExcel->getActiveSheet()->removeRow($num + $crows); }
public function searchformaterialkarta($params) { $query = TrMatOsmotr::find(); $query->joinWith(['idTrMat.idMattraffic', 'idOsmotraktmat.idMaster.idperson', 'idOsmotraktmat.idMaster.iddolzh', 'idReason']); $dataProvider = new ActiveDataProvider(['query' => $query, 'sort' => ['defaultOrder' => ['idOsmotraktmat.osmotraktmat_id' => SORT_DESC]]]); $this->load($params); if (!$this->validate()) { // uncomment the following line if you do not want to return any records when validation fails // $query->where('0=1'); return $dataProvider; } $query->andWhere(['idMattraffic.id_material' => $params['id']]); $query->andFilterWhere(Proc::WhereConstruct($this, 'idOsmotraktmat.osmotraktmat_id')); $query->andFilterWhere(Proc::WhereConstruct($this, 'idOsmotraktmat.osmotraktmat_date', Proc::Date)); $query->andFilterWhere(Proc::WhereConstruct($this, 'tr_mat_osmotr_number')); $query->andFilterWhere(['LIKE', 'idReason.reason_text', $this->getAttribute('idReason.reason_text')]); $query->andFilterWhere(['LIKE', 'tr_mat_osmotr_comment', $this->getAttribute('tr_mat_osmotr_comment')]); $query->andFilterWhere(['LIKE', 'idperson.auth_user_fullname', $this->getAttribute('idOsmotraktmat.idMaster.idperson.auth_user_fullname')]); $query->andFilterWhere(['LIKE', 'iddolzh.dolzh_name', $this->getAttribute('idOsmotraktmat.idMaster.iddolzh.dolzh_name')]); Proc::AssignRelatedAttributes($dataProvider, ['idOsmotraktmat.osmotraktmat_id', 'idOsmotraktmat.osmotraktmat_date', 'idReason.reason_text', 'idOsmotraktmat.idMaster.idperson.auth_user_fullname', 'idOsmotraktmat.idMaster.iddolzh.dolzh_name']); return $dataProvider; }