Browse Source

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

master
keun 8 years ago
parent
commit
ce066fd9b9
2 changed files with 106 additions and 17 deletions
  1. +37
    -4
      backend/controllers/CommandeController.php
  2. +69
    -13
      backend/views/commande/report.php

+ 37
- 4
backend/controllers/CommandeController.php View File

@@ -39,10 +39,43 @@ class CommandeController extends \yii\web\Controller {
];
}
public function actionReport() {
public function actionReport($date = '') {

$commandes = Commande::find()
->with('commandeProduits', 'user')
->joinWith('production')
->where(['production.date' => $date])
->orderBy('date ASC')
->all();

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');
$content = $this->renderPartial('report',[
'production' => $production,
'produits_selec' => $produits_selec,
'points_vente' => $points_vente,
'date' => $date,
'produits' => $produits
]);

/*$pdf = Yii::$app->pdf;
$pdf->content = $content;
@@ -70,7 +103,7 @@ class CommandeController extends \yii\web\Controller {
//'options' => ['title' => 'Krajee Report Title'],
// call mPDF methods on the fly
'methods' => [
'SetHeader'=>['Krajee Report Header'],
'SetHeader'=>['Commandes'],
'SetFooter'=>['{PAGENO}'],
]
]);
@@ -659,7 +692,7 @@ class CommandeController extends \yii\web\Controller {
}

// téléphone
if (strlen($c->user->telephone)) {
if (isset($c->user) && strlen($c->user->telephone)) {
$str_user .= ' (' . $c->user->telephone . ')';
}


+ 69
- 13
backend/views/commande/report.php View File

@@ -1,17 +1,73 @@
<?php

/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
<h1>Commandes <?php echo $date ; ?></h1>

?>
<?php

$num_jour_semaine = date('w', strtotime($date));
$arr_jour_semaine = [0 => 'dimanche', 1 => 'lundi', 2 => 'mardi', 3 => 'mercredi', 4 => 'jeudi', 5 => 'vendredi', 6 => 'samedi'];
$champs_horaires_point_vente = 'horaires_' . $arr_jour_semaine[$num_jour_semaine];

$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">'
. '<thead>'
. '<tr>'
. '<th>Client</th>'
. '<th>Produits</th>'
. '<th>Commentaire</th>'
. '<th>Montant</th>'
. '</tr>'
. '<tbody>';
foreach ($pv->commandes as $c) {
$html .= '<tr>' ;
$str_user = '';

// username
if ($c->user) {
$str_user = $c->user->prenom . " " . $c->user->nom; //.' - '.date('d/m', strtotime($c->date)) ;
} else {
$str_user = $c->username; //.' - '.date('d/m', strtotime($c->date)) ;
}

<h1>Commandes</h1>
// téléphone
if (isset($c->user) && strlen($c->user->telephone)) {
$str_user .= ' (' . $c->user->telephone . ')';
}

<p>Aliquam laoreet venenatis ligula, vitae porttitor ante molestie id. Praesent
eleifend placerat diam. Nullam vel finibus velit. Integer vitae enim vel
nunc eleifend condimentum. Morbi eu eros efficitur, gravida nibh eu, iaculis
tortor. Nam venenatis congue lacus, eget posuere mauris ultrices quis. Integer
tempus est ut felis elementum tincidunt. </p>
$html .= '<td>'.$str_user.'</td>';
// produits
$str_produits = '';
foreach ($produits as $p) {
if (isset($produits_selec[$p->id]['actif']) && $produits_selec[$p->id]['actif']) {
$add = false;
foreach ($c->commandeProduits as $cp) {
if ($p->id == $cp->id_produit) {
$str_produits .= $cp->quantite . '' . $p->diminutif . ', ';
$add = true;
}
}
}
}

$html .= '<td>'.substr($str_produits, 0, strlen($str_produits) - 2).'</td>';
$html .= '<td>'.$c->commentaire.'</td>';
$html .= '<td>'.number_format($c->montant, 2) . ' €'.'</td>';

$html .= '</tr>' ;
}
$html .= '</tbody></table>' ;
}
}

echo $html ;

?>

Loading…
Cancel
Save