On peaufine la page d'affichage des achats à faire

This commit is contained in:
2021-03-18 18:22:05 +01:00
parent 6ad1277b24
commit 2665548d93
7 changed files with 100 additions and 30 deletions

View File

@@ -6,6 +6,7 @@ use DateInterval;
use DateTime;
use Exception;
use PlanificationLivraison\Form\ProductsListForm;
use PlanificationLivraison\Model\OrderDeliveryScheduleQuery;
use PlanificationLivraison\PlanificationLivraison;
use Propel\Runtime\Exception\PropelException;
use Propel\Runtime\Propel;
@@ -24,6 +25,7 @@ class ProductsList extends BaseAdminController
public function viewAction(Request $request)
{
$productsList = [];
$myOrders = [];
$con = Propel::getConnection();
$error = "";
$startDate = new DateTime();
@@ -41,29 +43,67 @@ class ProductsList extends BaseAdminController
if (null !== $startDate && null !== $endDate) {
$sql = "select op.product_sale_elements_ref as `name`, aa.title as `packaging`, sum(op.quantity) as `quantity` " .
$sqlMyOrders = "select ods.order_id from order_delivery_schedule ods " .
"where ods.due_delivery_time_start >= '" . $startDate->format(PlanificationLivraison::FORMAT_DATE_COMPLETE) . "' " .
" and ods.due_delivery_time_start <= '" . $endDate->format(PlanificationLivraison::FORMAT_DATE_COMPLETE) . "' ".
" and ods.order_id not in (select o.id from `order` o where o.status_id = (select os.id from order_status os where os.code='canceled'))";
try {
$stmt = $con->prepare($sqlMyOrders);
$stmt->execute();
} catch (Exception $e) {
Propel::log($e->getMessage(), Propel::LOG_ERR);
throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sqlMyOrders), 0, $e);
}
$myOrders = $stmt->fetchAll(\PDO::FETCH_COLUMN);
// Récupération de la liste des produits commandés, regroupés par type de produit pour obtenir la quantité totale
$sqlProducts = "select op.product_sale_elements_id as `id`, op.product_sale_elements_ref as `name`, aa.title as `packaging`, sum(op.quantity) as `quantity`, '' as `repartition` " .
"from order_product op, product_sale_elements ps, attribute_combination ac, attribute_av_i18n aa " .
"where ps.id = op.product_sale_elements_id" .
" and ac.product_sale_elements_id = ps.id" .
" and aa.id = ac.attribute_av_id" .
" and op.order_id in (" .
" select ods.order_id from order_delivery_schedule ods " .
" where ods.due_delivery_time_start >= '" . $startDate->format(PlanificationLivraison::FORMAT_DATE_COMPLETE) . "'" .
" and ods.due_delivery_time_start <= '" . $endDate->format(PlanificationLivraison::FORMAT_DATE_COMPLETE) . "'" .
" ) " .
" and op.order_id not in (select o.id from `order` o " .
" where o.status_id = (select os.id from order_status os where os.code='canceled')) " .
" and op.order_id in (" . implode(',', $myOrders) . ")" .
"group by op.product_sale_elements_id " .
"order by op.product_ref, op.product_sale_elements_id";
try {
$stmt = $con->prepare($sql);
$stmt = $con->prepare($sqlProducts);
$stmt->execute();
} catch (Exception $e) {
Propel::log($e->getMessage(), Propel::LOG_ERR);
throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sql), 0, $e);
throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sqlProducts), 0, $e);
}
$productsList = $stmt->fetchAll(\PDO::FETCH_ASSOC);
// Récupération de la répartition des commande,s pour chaque produit
$sqlRepartition = "select op.product_sale_elements_id as `id`, sum(op.quantity) as `quantity`, DATE_FORMAT(ods.due_delivery_time_start, '%d/%m/%Y') as `day` " .
"from order_delivery_schedule ods, order_product op " .
"where ods.order_id in (" . implode(',', $myOrders) . ") " .
" and ods.order_id = op.order_id " .
"group by op.product_sale_elements_id, DATE_FORMAT(ods.due_delivery_time_start, '%d %m %y') " .
"order by op.product_sale_elements_id, ods.due_delivery_time_start";
try {
$stmt = $con->prepare($sqlRepartition);
$stmt->execute();
} catch (Exception $e) {
Propel::log($e->getMessage(), Propel::LOG_ERR);
throw new PropelException(sprintf('Unable to execute SELECT statement [%s]', $sqlRepartition), 0, $e);
}
$repartition = $stmt->fetchAll(\PDO::FETCH_ASSOC);
foreach ($productsList as $key => $produit) {
$texte = "";
foreach ($repartition as $item) {
if ($item['id'] === $produit['id']) {
$texte .= $item['quantity'] . " unité(s) pour le " . $item['day'] . "<br>";
}
}
$productsList[$key]['repartition'] = $texte;
}
}
} catch (\Exception $e) {
$error = $e->getMessage();