PlanificaitionLivraison : bien avancé sur le reporting des achats à faire, manque plus que le détail des commandes pour chaque produit
This commit is contained in:
80
local/modules/PlanificationLivraison/Controller/ProductsList.php
Executable file
80
local/modules/PlanificationLivraison/Controller/ProductsList.php
Executable file
@@ -0,0 +1,80 @@
|
||||
<?php
|
||||
|
||||
namespace PlanificationLivraison\Controller;
|
||||
|
||||
use DateInterval;
|
||||
use DateTime;
|
||||
use Exception;
|
||||
use PlanificationLivraison\Form\ProductsListForm;
|
||||
use PlanificationLivraison\PlanificationLivraison;
|
||||
use Propel\Runtime\Exception\PropelException;
|
||||
use Propel\Runtime\Propel;
|
||||
use Thelia\Controller\Admin\BaseAdminController;
|
||||
use Thelia\Core\HttpFoundation\Request;
|
||||
|
||||
|
||||
/**
|
||||
* Class ProductsList
|
||||
* @package PlanificationLivraison\Controller
|
||||
*/
|
||||
class ProductsList extends BaseAdminController
|
||||
{
|
||||
const FORMAT_DATES_HTML = 'd/m/Y';
|
||||
|
||||
public function viewAction(Request $request)
|
||||
{
|
||||
$productsList = [];
|
||||
$con = Propel::getConnection();
|
||||
$error = "";
|
||||
$startDate = new DateTime();
|
||||
$endDate = new DateTime();
|
||||
|
||||
$form = new ProductsListForm($request);
|
||||
try {
|
||||
$formValidate = $this->validateForm($form);
|
||||
$data = $formValidate->getData();
|
||||
|
||||
$start = $data['date-picker-start'];
|
||||
$startDate = DateTime::createFromFormat(self::FORMAT_DATES_HTML, $start)->setTime(0,0,0,0);
|
||||
$end = $data['date-picker-end'];
|
||||
$endDate = DateTime::createFromFormat(self::FORMAT_DATES_HTML, $end)->setTime(23,59,59,0);
|
||||
|
||||
if (null !== $startDate && null !== $endDate) {
|
||||
|
||||
$sql = "select op.product_sale_elements_ref as `name`, aa.title as `packaging`, sum(op.quantity) as `quantity` " .
|
||||
"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')) " .
|
||||
"group by op.product_sale_elements_id " .
|
||||
"order by op.product_ref, op.product_sale_elements_id";
|
||||
|
||||
try {
|
||||
$stmt = $con->prepare($sql);
|
||||
$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);
|
||||
}
|
||||
$productsList = $stmt->fetchAll(\PDO::FETCH_ASSOC);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$error = $e->getMessage();
|
||||
}
|
||||
|
||||
return $this->render("liste-achats",
|
||||
[
|
||||
'productsList' => $productsList,
|
||||
'startDate' => $startDate->format(PlanificationLivraison::FORMAT_DATES),
|
||||
'endDate' => $endDate->format(PlanificationLivraison::FORMAT_DATES),
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user