Procházet zdrojové kódy

Adapter la génération du récapitulatif de commande en PDF

master
keun před 8 roky
rodič
revize
8b5fe3f4cc
3 změnil soubory, kde provedl 63 přidání a 64 odebrání
  1. +54
    -57
      backend/controllers/CommandeController.php
  2. +1
    -1
      backend/views/commande/index.php
  3. +8
    -6
      backend/views/commande/report.php

+ 54
- 57
backend/controllers/CommandeController.php Zobrazit soubor

@@ -51,65 +51,62 @@ class CommandeController extends \yii\web\Controller {
foreach ($commandes as $c)
$c->init();
$production = Production::find()->where('date LIKE \'' . $date . '\'')->one();
$produits_selec = ProductionProduit::findProduits($production->id);
$points_vente = PointVente::find()->all();
foreach ($points_vente as $pv)
$pv->initCommandes($commandes);
// produits
$produits = Produit::find()
->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement])
->orderBy('order ASC')
->all();
/*return [
'data' => $data,
'filename' => $filename
];*/
// get your HTML raw content without any layouts or scripts
$content = $this->renderPartial('report',[
'production' => $production,
'produits_selec' => $produits_selec,
'points_vente' => $points_vente,
'date' => $date,
'produits' => $produits
]);
$production = Production::find()
->where('date LIKE \'' . $date . '\'')
->one();
if($production)
{
$produits_selec = ProductionProduit::findProduits($production->id);
$points_vente = PointVente::find()->all();
foreach ($points_vente as $pv)
$pv->initCommandes($commandes);

/*$pdf = Yii::$app->pdf;
$pdf->content = $content;
$pdf->orientation = Pdf::ORIENT_LANDSCAPE ;
return $pdf->render();*/
// produits
$produits = Produit::find()
->where(['id_etablissement' => Yii::$app->user->identity->id_etablissement])
->orderBy('order ASC')
->all();

// get your HTML raw content without any layouts or scripts
$content = $this->renderPartial('report',[
'production' => $production,
'produits_selec' => $produits_selec,
'points_vente' => $points_vente,
'date' => $date,
'produits' => $produits
]);

$date_str = date('d/m/Y',strtotime($date)) ;

$pdf = new Pdf([
// set to use core fonts only
'mode' => Pdf::MODE_UTF8,
// A4 paper format
'format' => Pdf::FORMAT_A4,
// portrait orientation
'orientation' => Pdf::ORIENT_LANDSCAPE,
// stream to browser inline
'destination' => Pdf::DEST_BROWSER,
// your html content input
'content' => $content,
// format content from your own css file if needed or use the
// enhanced bootstrap css built by Krajee for mPDF formatting
//'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
// any css to be embedded if required
//'cssInline' => '.kv-heading-1{font-size:18px}',
// set mPDF properties on the fly
//'options' => ['title' => 'Krajee Report Title'],
// call mPDF methods on the fly
'methods' => [
'SetHeader'=>['Commandes du '.$date_str],
'SetFooter'=>['{PAGENO}'],
]
]);

// return the pdf output as per the destination setting
return $pdf->render();
}
// setup kartik\mpdf\Pdf component
$pdf = new Pdf([
// set to use core fonts only
'mode' => Pdf::MODE_UTF8,
// A4 paper format
'format' => Pdf::FORMAT_A4,
// portrait orientation
'orientation' => Pdf::ORIENT_LANDSCAPE,
// stream to browser inline
'destination' => Pdf::DEST_BROWSER,
// your html content input
'content' => $content,
// format content from your own css file if needed or use the
// enhanced bootstrap css built by Krajee for mPDF formatting
//'cssFile' => '@vendor/kartik-v/yii2-mpdf/assets/kv-mpdf-bootstrap.min.css',
// any css to be embedded if required
//'cssInline' => '.kv-heading-1{font-size:18px}',
// set mPDF properties on the fly
//'options' => ['title' => 'Krajee Report Title'],
// call mPDF methods on the fly
'methods' => [
'SetHeader'=>['Commandes'],
'SetFooter'=>['{PAGENO}'],
]
]);

// return the pdf output as per the destination setting
return $pdf->render();
}

public function actionDeleteCommande($date, $id_commande) {

+ 1
- 1
backend/views/commande/index.php Zobrazit soubor

@@ -59,7 +59,7 @@ foreach ($produits as $p) {
<div class="alert alert-info">Aucune commande passée pour cette date</div>
<?php else: ?>
<strong><?= count($commandes) ?> commande<?php if(count($commandes)> 1): ?>s<?php endif; ?></strong><br />
<a class="btn btn-primary" href="<?php echo Yii::$app->urlManager->createUrl(['commande/download', 'date' => $date, 'id_point_vente' => 0, 'global' => 1]); ?>"><span class="glyphicon glyphicon-download-alt"></span> Récapitulatif global</a>
<a class="btn btn-primary" href="<?php echo Yii::$app->urlManager->createUrl(['commande/report', 'date' => $date, 'id_point_vente' => 0, 'global' => 1]); ?>"><span class="glyphicon glyphicon-download-alt"></span> Récapitulatif global</a>
<br />
<br />
<?php endif; ?>

+ 8
- 6
backend/views/commande/report.php Zobrazit soubor

@@ -1,6 +1,4 @@

<h1>Commandes <?php echo $date ; ?></h1>

<?php

$num_jour_semaine = date('w', strtotime($date));
@@ -12,6 +10,7 @@ $html = '' ;
// par point de vente
foreach ($points_vente as $pv) {
if (count($pv->commandes) && strlen($pv->$champs_horaires_point_vente)) {
$html .= '<h3>'.$pv->nom.'</h3>' ;

$html .= '<table class="table table-bordered">'
@@ -34,10 +33,10 @@ foreach ($points_vente as $pv) {
} else {
$str_user = $c->username; //.' - '.date('d/m', strtotime($c->date)) ;
}
// téléphone
if (isset($c->user) && strlen($c->user->telephone)) {
$str_user .= ' (' . $c->user->telephone . ')';
$str_user .= '<br />' . $c->user->telephone . '';
}

$html .= '<td>'.$str_user.'</td>';
@@ -49,7 +48,7 @@ foreach ($points_vente as $pv) {
$add = false;
foreach ($c->commandeProduits as $cp) {
if ($p->id == $cp->id_produit) {
$str_produits .= $cp->quantite . '' . $p->diminutif . ', ';
$str_produits .= $cp->quantite . ' x ' . $p->nom . '<br /> ';
$add = true;
}
}
@@ -64,10 +63,13 @@ foreach ($points_vente as $pv) {
}
$html .= '</tbody></table>' ;
$html .= '</tbody></table><pagebreak>' ;
}
}

// on enlève le dernier "pagebreak"
$html = substr($html, 0, strlen($html) - 11) ;

echo $html ;

?>

Načítá se…
Zrušit
Uložit