147 lines
4.5 KiB
PHP

<?php
declare(strict_types=1);
/**
* Calendar App
*
* @copyright 2021 Anna Larch <anna.larch@gmx.net>
*
* @author Anna Larch <anna.larch@gmx.net>
* @author Richard Steinmetz <richard@steinmetz.cloud>
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU AFFERO GENERAL PUBLIC LICENSE
* License as published by the Free Software Foundation; either
* version 3 of the License, or any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU AFFERO GENERAL PUBLIC LICENSE for more details.
*
* You should have received a copy of the GNU Affero General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*
*/
namespace OCA\Gestion\Service\Order;
use DateTime;
use OCA\Gestion\Constants\BddConstant;
use OCA\Gestion\Constants\OrderTypeConstant;
use OCA\Gestion\Db\Bdd;
use OCA\Gestion\Db\OrderBdd;
use OCA\Gestion\Helpers\FileExportHelpers;
use Psr\Log\LoggerInterface;
class OrderService {
/** @var \OCA\Gestion\Db\OrderBdd */
private $orderBdd;
private $gestionBdd;
/** @var LoggerInterface */
private $logger;
public function __construct(
OrderBdd $orderBdd,
LoggerInterface $logger,
Bdd $gestionBdd) {
$this->logger = $logger;
$this->orderBdd = $orderBdd;
$this->gestionBdd = $gestionBdd;
}
public function getOrdersWithDetailsAsArray(){
$orders = $this->orderBdd->getOrdersWithDetails();
foreach($orders as &$order){
$currentOrderProductsReferenceAsString = "";
if($order["fk_order_type_key"] == OrderTypeConstant::ORDER_TYPE_DEVIS){
if($order["fk_devis_id"] != null){
$produitReferences = $this->gestionBdd->getDevisProduitsReferences($order["fk_devis_id"]);
}
if(!empty($produitReferences)){
$currentOrderProductsReferenceAsString = implode('-',$produitReferences);
}
$order["product_references"] = $currentOrderProductsReferenceAsString;
}
else{
$orderItemReferences = $this->orderBdd->getOrderItemsReferenceByOrderId($order['id']);
if(!empty($orderItemReferences)){
$currentOrderProductsReferenceAsString = implode('-',$orderItemReferences);
}
$order["product_references"] = $currentOrderProductsReferenceAsString;
}
}
return $orders;
}
public function createDefaultOrder($idNextcloud){
$this->orderBdd->createDefaultOrder($idNextcloud);
}
public function updateOrderDate($orderId,$date){
$this->orderBdd->updateOrderDateAndSetNewOrderNumber($orderId,$date);
}
public function getThanatoProductsFees(){
return $this->orderBdd->getThanatoProductDiscountList();
}
public function createDefaultThanatoProductFee(){
$this->orderBdd->createDefaultThanatoProductFee();
}
public function getOrderCount(){
return $this->orderBdd->getOrderCount();
}
public function getThanatoProductFeeCount(){
return $this->orderBdd->getThanatoProductFeeCount();
}
public function getOrderByIdWithDetails($orderId){
return $this->orderBdd->getOrderByIdWithDetails($orderId);
}
public function getOrderProductsById($orderId){
return $this->orderBdd->getOrderProductsByOrderId($orderId);
}
public function getOrderItemsByOrderId($orderId){
return $this->orderBdd->getOrderItemsByOrderId($orderId);
}
public function getOrderTotalAmount($orderId,$tva){
return $this->orderBdd->getOrderTotalAmount($orderId,$tva);
}
public function getOrderPdfData($orderId){
$orderDetails = $this->orderBdd->getOrderByIdWithDetails($orderId);
if($orderDetails == null){
return null;
}
$orderProducts = $this->orderBdd->getOrderProductsByOrderId($orderId);
$orderDetails["products"] = $orderProducts;
$clientAdresses = FileExportHelpers::GetAddressAndCityFromAddress($orderDetails["client_adresse"]);
$orderDetails["client_real_adress"] = $clientAdresses["address"];
$orderDetails["client_adress_city"] = $clientAdresses["city"];
return $orderDetails;
}
public function createOrderFromDevisIdAndDate(int $devisId,Datetime $devisDate,string $idNextCloud = BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD ){
$this->orderBdd->createOrderFromDevisIdAndDate($devisId,$devisDate,$idNextCloud);
}
public function getOrderProducts(){
return $this->orderBdd->getOrderProducts();
}
public function createDefaultOrderProduct($idNextCloud){
$this->orderBdd->createDefaultOrderProduct($idNextCloud);
}
public function addDefaultOrderItem($orderId){
$this->orderBdd->addDefaultOrderItem($orderId);
}
}