Browse Source

[backend] Distributions : correctif export grille (pdf)

dev
Guillaume 3 years ago
parent
commit
00c3611be1
2 changed files with 95 additions and 81 deletions
  1. +37
    -29
      backend/controllers/DistributionController.php
  2. +58
    -52
      backend/views/distribution/report-grid.php

+ 37
- 29
backend/controllers/DistributionController.php View File

$idProducer = GlobalParam::getCurrentProducerId(); $idProducer = GlobalParam::getCurrentProducerId();
} }


$ordersArray = Order::searchAll([
'distribution.date' => $date,
'distribution.id_producer' => $idProducer
],
[
'orderby' => 'user.lastname ASC, user.name ASC, comment_point_sale ASC',
'conditions' => 'date_delete IS NULL'
]);

$ordersByPage = 12 ;
$nbPages = ceil(count($ordersArray) / $ordersByPage) ;
$ordersArrayPaged = [] ;
$index = 0 ;
$indexPage = 0 ;

foreach($ordersArray as $order) {
if(!isset($ordersArrayPaged[$indexPage])) {
$ordersArrayPaged[$indexPage] = [] ;
}
$ordersArrayPaged[$indexPage][] = $order ;

$index ++ ;

if($index == $ordersByPage - 1) {
$index = 0 ;
$indexPage ++ ;
}
}

$distribution = Distribution::searchOne([ $distribution = Distribution::searchOne([
'id_producer' => $idProducer 'id_producer' => $idProducer
], [ ], [
]); ]);


if ($distribution) { if ($distribution) {

$ordersArray = Order::searchAll([
'distribution.date' => $date,
'distribution.id_producer' => $idProducer
],
[
'orderby' => 'user.lastname ASC, user.name ASC, comment_point_sale ASC',
'conditions' => 'date_delete IS NULL'
]);

$selectedProductsArray = ProductDistribution::searchByDistribution($distribution->id); $selectedProductsArray = ProductDistribution::searchByDistribution($distribution->id);
$pointsSaleArray = PointSale::searchAll([ $pointsSaleArray = PointSale::searchAll([
'point_sale.id_producer' => $idProducer 'point_sale.id_producer' => $idProducer
$pointSale->initOrders($ordersArray); $pointSale->initOrders($ordersArray);
} }


$ordersByPage = 12 ;
$nbPages = ceil(count($ordersArray) / $ordersByPage) ;
$ordersArrayPaged = [] ;

foreach($pointsSaleArray as $pointSale) {

$index = 0 ;
$indexPage = 0 ;

foreach($pointSale->orders as $order) {
if(!isset($ordersArrayPaged[$pointSale->id])) {
$ordersArrayPaged[$pointSale->id] = [] ;
}
if(!isset($ordersArrayPaged[$pointSale->id][$indexPage])) {
$ordersArrayPaged[$pointSale->id][$indexPage] = [] ;
}
$ordersArrayPaged[$pointSale->id][$indexPage][] = $order ;

$index ++ ;

if($index == $ordersByPage - 1) {
$index = 0 ;
$indexPage ++ ;
}
}
}

// catégories // catégories
$categoriesArray = ProductCategory::searchAll(['id_producer' => $idProducer], ['orderby' => 'product_category.position ASC']) ; $categoriesArray = ProductCategory::searchAll(['id_producer' => $idProducer], ['orderby' => 'product_category.position ASC']) ;
array_unshift($categoriesArray, null) ; array_unshift($categoriesArray, null) ;

+ 58
- 52
backend/views/distribution/report-grid.php View File



$html = '' ; $html = '' ;


foreach($ordersArray as $indexPage => $orders) {
$html .= '<table class="">'
. '<thead>'
. '<tr>'
. '<th></th>' ;
foreach($pointsSaleArray as $pointSale) {


foreach($orders as $order) {
$html .= '<th class="th-user" text-rotate="90">'
.'<div class="user">'.$order->getStrUser().'</div>'
//.'<div class="amount">'.number_format($order->amount_with_tax, 2) .' € </div>'
.'</th>' ;
}
$html .= '<h1>'.$pointSale->name.'</h1>' ;


$html .= '</tr>'
. '<thead>'
. '<tbody>';
foreach ($ordersArray[$pointSale->id] as $indexPage => $orders) {


$html .= '<table class="">'
. '<thead>'
. '<tr>'
. '<th></th>';


foreach($categoriesArray as $category) {
if($category) {
$html .= '<tr><td class="category-name">'.$category->name.'</td><td colspan="'.(count($orders)).'"></td></tr>' ;
}

foreach($productsArray as $product) {
if(($category && $product->id_product_category == $category->id) || (!$category && !$product->id_product_category)) {
$html .= line_product($product, $orders) ;
}
foreach ($orders as $order) {
$html .= '<th class="th-user" text-rotate="90">'
. '<div class="user">' . $order->getStrUser() . '</div>'
//.'<div class="amount">'.number_format($order->amount_with_tax, 2) .' € </div>'
. '</th>';
} }
}


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




$html .= '<table class="">'
. '<thead>'
. '<tr>'
. '<th>Client</th>'
. '<th>Contact</th>'
. '<th>Commentaire</th>'
. '<th>Montant</th>'
. '</thead>'
. '<tbody>';
foreach ($categoriesArray as $category) {
if ($category) {
$html .= '<tr><td class="category-name">' . $category->name . '</td><td colspan="' . (count($orders)) . '"></td></tr>';
}


foreach($orders as $order) {
$html .= '<tr>' ;
$strUser = $order->getStrUser() ;
if($producer->option_order_reference_type == Producer::ORDER_REFERENCE_TYPE_YEARLY && $order->reference && strlen($order->reference) > 0) {
$strUser .= '<br />'.$order->reference ;
foreach ($productsArray as $product) {
if (($category && $product->id_product_category == $category->id) || (!$category && !$product->id_product_category)) {
$html .= line_product($product, $orders);
}
}
} }


$html .= '<td>'.$strUser.'</td>' ;
$contactUser = '' ;
if($order->user) {
$contactUser .= $order->user->phone.'<br />'.$order->user->email ;
$html .= '</tbody>'
. '</table>';
$html .= '<pagebreak>';


$html .= '<table class="">'
. '<thead>'
. '<tr>'
. '<th>Client</th>'
. '<th>Contact</th>'
. '<th>Commentaire</th>'
. '<th>Montant</th>'
. '</thead>'
. '<tbody>';

foreach ($orders as $order) {
$html .= '<tr>';
$strUser = $order->getStrUser();
if ($producer->option_order_reference_type == Producer::ORDER_REFERENCE_TYPE_YEARLY && $order->reference && strlen($order->reference) > 0) {
$strUser .= '<br />' . $order->reference;
}

$html .= '<td>' . $strUser . '</td>';
$contactUser = '';
if ($order->user) {
$contactUser .= $order->user->phone . '<br />' . $order->user->email;
}
$html .= '<td>' . $contactUser . '</td>';
$html .= '<td>' . nl2br($order->comment) . '</td>';
$html .= '<td>' . number_format($order->amount_with_tax, 2) . ' € </td>';
$html .= '</tr>';
} }
$html .= '<td>'.$contactUser.'</td>' ;
$html .= '<td>'.nl2br($order->comment).'</td>' ;
$html .= '<td>'.number_format($order->amount_with_tax, 2) .' € </td>' ;
$html .= '</tr>' ;
}


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


$html .= '<pagebreak>' ;
$html .= '<pagebreak>';
}
} }


echo($html) ; echo($html) ;

Loading…
Cancel
Save