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();
     }
 }
Esempio n. 2
0
 /**
  * Creates data provider instance with search query applied
  *
  * @param array $params
  *
  * @return ActiveDataProvider
  */
 public function search($params)
 {
     $query = Pecas::find();
     $query->joinWith('preco');
     $dataProvider = new ActiveDataProvider(['query' => $query]);
     $dataProvider->sort->attributes['preco.preco'] = ['asc' => ['precos.preco' => SORT_ASC], 'desc' => ['precos.preco' => 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->andFilterWhere(['id' => $this->id]);
     $query->andFilterWhere(['categoria_id' => $this->categoria_id]);
     $query->andFilterWhere(['like', 'nome', $this->nome]);
     return $dataProvider;
 }
Esempio n. 3
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPeca()
 {
     return $this->hasOne(Pecas::className(), ['id' => 'peca_id']);
 }
Esempio n. 4
0
 private function salvaPeca($peca, $loja, $imagem, $link, $preco, $categoria_id)
 {
     $peca = $this->converte($peca);
     $loja = $this->converte($loja);
     $imagem = $this->converte($imagem);
     $link = $this->converte($link);
     $novaPeca = new Pecas();
     $novaPeca->nome = $peca;
     $novaPeca->categoria_id = $categoria_id;
     $novaPeca->loja = $loja;
     $novaPeca->link_externo = $link;
     $novaPeca->disponivel = '1';
     if (!$novaPeca->save()) {
         print_r($novaPeca->getErrors());
         exit;
     }
     $novoPreco = new Precos();
     $novoPreco->peca_id = $novaPeca->id;
     $novoPreco->preco = $preco;
     if (!$novoPreco->save()) {
         print_r($novoPreco->getErrors());
         exit;
     }
     if (!@copy($imagem, 'imgs/pecas/' . $novaPeca->id . '.jpg')) {
         copy('imgs/semimagem.jpg', 'imgs/pecas/' . $novaPeca->id . '.jpg');
     }
 }
Esempio n. 5
0
 /**
  * @return \yii\db\ActiveQuery
  */
 public function getPecas()
 {
     return $this->hasMany(Pecas::className(), ['categoria_id' => 'id']);
 }