|
|
@@ -332,7 +332,7 @@ class DistributionController extends BackendController |
|
|
|
* @param integer $idProducer |
|
|
|
* @return PDF|null |
|
|
|
*/ |
|
|
|
public function actionReport($date = '', $save = false, $idProducer = 0) |
|
|
|
public function actionReport($date = '', $save = false, $idProducer = 0, $type = "pdf") |
|
|
|
{ |
|
|
|
if (!Yii::$app->user->isGuest) { |
|
|
|
$idProducer = Producer::getId() ; |
|
|
@@ -360,59 +360,151 @@ class DistributionController extends BackendController |
|
|
|
} |
|
|
|
|
|
|
|
// produits |
|
|
|
$productsArray = Product::searchAll() ; |
|
|
|
$productsArray = Product::find() |
|
|
|
->joinWith(['productDistribution' => function($q) use ($distribution) { |
|
|
|
$q->where(['id_distribution' => $distribution->id]); |
|
|
|
}]) |
|
|
|
->where([ |
|
|
|
'id_producer' => Producer::getId(), |
|
|
|
]) |
|
|
|
->orderBy('order ASC') |
|
|
|
->all(); |
|
|
|
|
|
|
|
if($type == 'pdf') { |
|
|
|
// get your HTML raw content without any layouts or scripts |
|
|
|
$content = $this->renderPartial('report', [ |
|
|
|
'date' => $date, |
|
|
|
'distribution' => $distribution, |
|
|
|
'selectedProductsArray' => $selectedProductsArray, |
|
|
|
'pointsSaleArray' => $pointsSaleArray, |
|
|
|
'productsArray' => $productsArray, |
|
|
|
'ordersArray' => $ordersArray |
|
|
|
]); |
|
|
|
|
|
|
|
// get your HTML raw content without any layouts or scripts |
|
|
|
$content = $this->renderPartial('report', [ |
|
|
|
'date' => $date, |
|
|
|
'distribution' => $distribution, |
|
|
|
'selectedProductsArray' => $selectedProductsArray, |
|
|
|
'pointsSaleArray' => $pointsSaleArray, |
|
|
|
'productsArray' => $productsArray, |
|
|
|
'ordersArray' => $ordersArray |
|
|
|
]); |
|
|
|
$dateStr = date('d/m/Y', strtotime($date)); |
|
|
|
|
|
|
|
$dateStr = date('d/m/Y', strtotime($date)); |
|
|
|
if ($save) { |
|
|
|
$destination = Pdf::DEST_FILE; |
|
|
|
} else { |
|
|
|
$destination = Pdf::DEST_BROWSER; |
|
|
|
} |
|
|
|
|
|
|
|
if ($save) { |
|
|
|
$destination = Pdf::DEST_FILE; |
|
|
|
} else { |
|
|
|
$destination = Pdf::DEST_BROWSER; |
|
|
|
} |
|
|
|
$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_PORTRAIT, |
|
|
|
// stream to browser inline |
|
|
|
'destination' => $destination, |
|
|
|
'filename' => Yii::getAlias('@app/web/pdf/Commandes-' . $date . '-' . $idProducer . '.pdf'), |
|
|
|
// 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 ' . $dateStr], |
|
|
|
'SetFooter' => ['{PAGENO}'], |
|
|
|
] |
|
|
|
]); |
|
|
|
|
|
|
|
$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_PORTRAIT, |
|
|
|
// stream to browser inline |
|
|
|
'destination' => $destination, |
|
|
|
'filename' => Yii::getAlias('@app/web/pdf/Commandes-' . $date . '-' . $idProducer . '.pdf'), |
|
|
|
// 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 ' . $dateStr], |
|
|
|
'SetFooter' => ['{PAGENO}'], |
|
|
|
] |
|
|
|
]); |
|
|
|
// return the pdf output as per the destination setting |
|
|
|
return $pdf->render(); |
|
|
|
} |
|
|
|
|
|
|
|
elseif($type == 'csv') { |
|
|
|
$datas = []; |
|
|
|
|
|
|
|
// produits en colonne |
|
|
|
$productsNameArray = [''] ; |
|
|
|
$productsIndexArray = [] ; |
|
|
|
$cpt = 1 ; |
|
|
|
foreach ($productsArray as $product) { |
|
|
|
$quantity = Order::getProductQuantity($product->id, $ordersArray); |
|
|
|
if($quantity) { |
|
|
|
$productsNameArray[] = $product->name ; |
|
|
|
$productsIndexArray[$product->id] = $cpt ++ ; |
|
|
|
} |
|
|
|
} |
|
|
|
$datas[] = $productsNameArray ; |
|
|
|
|
|
|
|
// points de vente |
|
|
|
foreach ($pointsSaleArray as $pointSale) { |
|
|
|
if (count($pointSale->orders)) { |
|
|
|
// listing commandes |
|
|
|
$datas[] = ['> '.$pointSale->name] ; |
|
|
|
foreach($pointSale->orders as $order) { |
|
|
|
$orderLine = [$order->getStrUser()] ; |
|
|
|
foreach($order->productOrder as $productOrder) { |
|
|
|
$orderLine[$productsIndexArray[$productOrder->id_product]] = $productOrder->quantity ; |
|
|
|
} |
|
|
|
$datas[] = $this->_lineOrderReportCSV($orderLine, $cpt) ; |
|
|
|
} |
|
|
|
|
|
|
|
// total point de vente |
|
|
|
$totalsPointSaleArray = ['Total'] ; |
|
|
|
foreach ($productsArray as $product) { |
|
|
|
$quantity = Order::getProductQuantity($product->id, $pointSale->orders); |
|
|
|
if($quantity) { |
|
|
|
$index = $productsIndexArray[$product->id] ; |
|
|
|
if(!isset($totalsPointSaleArray[$index])) { |
|
|
|
$totalsPointSaleArray[$index] = 0 ; |
|
|
|
} |
|
|
|
$totalsPointSaleArray[$index] += $quantity ; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
$datas[] = $this->_lineOrderReportCSV($totalsPointSaleArray, $cpt) ; |
|
|
|
$datas[] = [] ; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// global |
|
|
|
$totalsGlobalArray = ['> Totaux'] ; |
|
|
|
foreach ($productsArray as $product) { |
|
|
|
$quantity = Order::getProductQuantity($product->id, $ordersArray); |
|
|
|
if($quantity) { |
|
|
|
$index = $productsIndexArray[$product->id] ; |
|
|
|
if(!isset($totalsGlobalArray[$index])) { |
|
|
|
$totalsGlobalArray[$index] = 0 ; |
|
|
|
} |
|
|
|
$totalsGlobalArray[$index] += $quantity ; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// return the pdf output as per the destination setting |
|
|
|
return $pdf->render(); |
|
|
|
$datas[] = $this->_lineOrderReportCSV($totalsGlobalArray, $cpt) ; |
|
|
|
|
|
|
|
CSV::downloadSendHeaders('Commandes_'.$date.'.csv'); |
|
|
|
echo CSV::array2csv($datas); |
|
|
|
die(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return null ; |
|
|
|
} |
|
|
|
|
|
|
|
public function _lineOrderReportCSV($orderLine, $cptMax) |
|
|
|
{ |
|
|
|
$line = [] ; |
|
|
|
for($i = 0; $i <= $cptMax ; $i++) { |
|
|
|
if(isset($orderLine[$i]) && $orderLine[$i]) { |
|
|
|
$line[] = $orderLine[$i] ; |
|
|
|
} |
|
|
|
else { |
|
|
|
$line[] = '' ; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
return $line ; |
|
|
|
} |
|
|
|
|
|
|
|
public function actionAjaxProcessProductQuantityMax($idDistribution, $idProduct, $quantityMax) |
|
|
|
{ |
|
|
|
\Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; |