public function actionExportar() { // get your HTML raw content without any layouts or scripts if (isset($_COOKIE['pcbuilder_cart'])) { $total = 0; $pcbuilder_cart = unserialize($_COOKIE['pcbuilder_cart']); if (count($pcbuilder_cart) > 0) { $pcbuilder_cart = Yii::$app->PCBuilder->array_sort($pcbuilder_cart, 'categoria', 'SORT_ASC'); foreach ($pcbuilder_cart as $i => $peca) { $modelPeca = Pecas::findOne($peca['peca']); $pecas[] = ['id' => $modelPeca['id'], 'cookieID' => $i, 'nome' => $modelPeca['nome'], 'loja' => $modelPeca['loja'], 'link_externo' => $modelPeca['link_externo'], 'preco' => $modelPeca['preco'][0]['preco']]; $total = $total + $modelPeca['preco'][0]['preco']; } } } else { echo "Nada para salvar!"; exit; } if (count($pecas) > 0) { $content = $this->renderPartial('_pdf', ['pecas' => $pecas, 'total' => $total]); $date = new \Datetime(null); $hoje = $date->getTimestamp() + $date->getOffset(); // setup kartik\mpdf\Pdf component $pdf = new Pdf(['mode' => Pdf::MODE_BLANK, 'format' => Pdf::FORMAT_A4, 'orientation' => Pdf::ORIENT_PORTRAIT, 'destination' => Pdf::DEST_DOWNLOAD, 'content' => $content, 'filename' => 'PC Builder - Lista de Peças - ' . date("d.m.Y H.i.s", $hoje) . '.pdf', 'options' => ['title' => 'PC Builder - Lista de Peças - ' . date("d/m/Y H:i:s", $hoje), 'defaultheaderline' => 0, 'setAutoTopMargin' => 'stretch'], 'methods' => ['SetHeader' => ['' . '<table width="100%">' . '<tr>' . '<td width="75%"><a target="_blank" href="http://www.brunodeoliveira.com"><img width="100px" src="imgs/logo.png"></a></td>' . '<td width="25%" valign="bottom" style="text-align: right">Salvo em<br /><small>' . date("d/m/Y H:i:s") . '</small></td>' . '<tr/>' . '</table>' . ''], 'SetFooter' => ['Obrigado por utilizar o PC Builder - Desenvolvido por Bruno de Oliveira - Página {PAGENO}']]]); return $pdf->render(); } }
public function diffDias($data) { $date = new \Datetime(null); $hoje = $date->getTimestamp() + $date->getOffset(); $diff = strtotime($data) - $hoje; return floor($diff / (24 * 60 * 60)); }
public function actionEventos($from, $to) { $date = new \Datetime(null); $hoje = $date->getTimestamp() + $date->getOffset(); $de = date("Y-m-d", $from / 1000); $para = date("Y-m-d", $to / 1000); $model = Eventos::find()->joinWith('atividade')->where(['>=', 'd_ini', $de])->orWhere(['<=', 'd_ter', $de])->orWhere(['<=', 'd_ter', $para])->andWhere(['atividades.empresa_id' => Yii::$app->session->get('empresa')])->all(); $d = ['success' => 1]; foreach ($model as $dados) { $d['result'][] = ['id' => $dados['id'], 'title' => $dados['atividade']['atividade'], 'url' => Url::to(['evento/visualizar', 'id' => $dados['id']]), 'class' => Yii::$app->AgobUtils->cssStatus($dados['status'], $dados['d_ter']), 'start' => strtotime($dados['d_ini']) . '000', 'end' => strtotime($dados['d_ter']) . '000', 'dias' => Yii::$app->AgobUtils->diffDias($dados['d_ter']), 'status' => $dados['status']]; } echo json_encode($d); }