HOTFIX facture group and simple

This commit is contained in:
Tolotsoa 2025-09-05 01:21:33 +03:00
parent 25b27a7f32
commit a0d17190bf
3 changed files with 80 additions and 60 deletions

View File

@ -1,4 +1,5 @@
<?php
namespace OCA\Gestion\Controller;
use OCA\Gestion\Constants\BddConstant;
@ -43,9 +44,7 @@ class InvoiceController extends Controller
IMailer $mailer,
MailerService $mailerService,
IUserSession $userSession
)
{
) {
$this->currentUserIdNextcloud = $UserId;
$this->invoicePdfService = $invoicePdfService;
$this->rootFolder = $rootFolder;
@ -55,9 +54,9 @@ class InvoiceController extends Controller
$this->config = $config;
$this->user = $userSession->getUser();
try{
try {
$this->storage = $rootFolder->getUserFolder($this->currentUserIdNextcloud);
}catch(\OC\User\NoUserException $e){
} catch(\OC\User\NoUserException $e) {
}
parent::__construct($AppName, request: $request);
@ -68,14 +67,14 @@ class InvoiceController extends Controller
* @NoCSRFRequired
*/
public function getInvoicePdfContent($factureId){
$facture = $this->gestionRepository->getFactureByFactureId($factureId);
if($facture == null)
public function getInvoicePdfContent($factureId)
{
$facture = $this->gestionRepository->getFactureByFactureId($factureId);
if($facture == null) {
return new DataResponse("La facture n'existe pas", 404, ['Content-Type' => 'application/json']);
}
$factureGeneratedResponse = $this->invoicePdfService->generateFacturePdfByFactureId($factureId,$this->currentUserIdNextcloud);
if($factureGeneratedResponse == null){
$factureGeneratedResponse = $this->invoicePdfService->generateFacturePdfByFactureId($factureId, $this->currentUserIdNextcloud);
if($factureGeneratedResponse == null) {
return new DataResponse("La facture n'a pas été générée correctement", 404, ['Content-Type' => 'application/json']);
}
$factureContent = base64_encode($factureGeneratedResponse['content']);
@ -91,12 +90,11 @@ class InvoiceController extends Controller
public function sendInvoicePdfViaMail($factureId, $email = '')
{
$facture = $this->gestionRepository->getFactureByFactureId($factureId);
if($facture == null)
{
if($facture == null) {
return new DataResponse("La facture n'existe pas", 404, ['Content-Type' => 'application/json']);
}
$factureGeneratedResponse = $this->invoicePdfService->generateFacturePdfByFactureId($factureId,$this->currentUserIdNextcloud);
if($factureGeneratedResponse == null){
$factureGeneratedResponse = $this->invoicePdfService->generateFacturePdfByFactureId($factureId, $this->currentUserIdNextcloud);
if($factureGeneratedResponse == null) {
return new DataResponse("La facture n'a pas été générée correctement", 404, ['Content-Type' => 'application/json']);
}
$factureContent = $factureGeneratedResponse["content"];
@ -109,7 +107,8 @@ class InvoiceController extends Controller
$message->attach($content);
$message->setSubject("Facture");
$signature = $this->mailerService->getFooterContent();
$signature = $this->mailerService->getFooterContent($this->getUserNameForEmailSignature());
$message->setHtmlBody(
"<p>Bonjour.</p>".
@ -128,4 +127,11 @@ class InvoiceController extends Controller
}
return new DataResponse("E-mail envoyé avec succès à ".$email.".", 200, ['Content-Type' => 'application/json']);
}
public function getUserNameForEmailSignature()
{
$configs = json_decode($this->gestionRepository->getConfiguration(BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD));
$currentConfig = $configs[0];
return $currentConfig->nom . " " . $currentConfig->prenom;
}
}

View File

@ -3352,6 +3352,7 @@ class Bdd
if($factureData == null) {
return null;
}
$products = $this->getDevisProduits($factureData["devis_id"]);
$isDevisNegative = $this->isDevisNegative($factureData['devis_id'], $factureData['client_id']);
$factureData = $this->setDevisStartAndEndTime($factureData);
@ -3359,6 +3360,11 @@ class Bdd
$factureData["products"] = $products;
$factureData["configuration"] = $configuration;
// Récupération des informations client et gestion TVA
$client = $this->getClientById($factureData['client_id']);
$hasTva = ($client && isset($client['tva'])) ? ($client['tva'] == 1) : true;
$groupClient = $this->getTvaItracomuIdClient($factureData['client_id']);
$isClientInsideGroup = $factureData["group_id"] != null;
if($isClientInsideGroup) {
$factureData["client_real_adress"] = $factureData["group_address"];
@ -3371,11 +3377,15 @@ class Bdd
$factureData["client_real_adress"] = $clientAdresses["address"];
$factureData["client_adress_city"] = $clientAdresses["city"];
}
$factureData['is_negative'] = $isDevisNegative;
$factureData["is_tva"] = $hasTva;
$factureData["client_tva_intracommu"] = $groupClient["tva_intracommu"];
$configurationAdresses = FileExportHelpers::GetAddressAndCityFromAddress($configuration->adresse);
$factureData["configuration_adresse"] = $configurationAdresses["address"];
$factureData["configuration_adresse_city"] = $configurationAdresses["city"];
return $factureData;
}

View File

@ -29,24 +29,27 @@ namespace OCA\Gestion\Service;
use OCA\Gestion\Constants\BddConstant;
use OCP\Files\IRootFolder;
class MailerService {
class MailerService
{
private $adminStorage;
public function __construct(
IRootFolder $rootFolder,
){
) {
$this->adminStorage = $rootFolder->getUserFolder(BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD);
}
public function getFooterContent ($userName = "Johann"){
public function getFooterContent($userName = "DEKINDT Vanessa")
{
$wish = "<p>Vous en souhaitant bonne réception. </p>";
$cordialement = "<p> Cordialement,</p>";
$userName = "<p> {$userName} </p>" ;
$signatureImage = $this->getSignatureHtmlEmailContent();
return $wish . $cordialement .$userName . $signatureImage ;
// $signatureImage = $this->getSignatureHtmlEmailContent();
// return $wish . $cordialement .$userName . $signatureImage ;
return $wish . $cordialement .$userName ;
}
private function getSignatureHtmlEmailContent (){
private function getSignatureHtmlEmailContent()
{
$signatureImage = $this->getSignatureContent();
if (!$signatureImage) {
return "";
@ -54,14 +57,15 @@ class MailerService {
return "<img width='170' height='80' style= 'width: 170;height: 80px;display:block;' src='data:image/jpeg;base64,".base64_encode($signatureImage)."'>" ;
}
private function getSignatureContent(){
try{
if(isset($this->adminStorage)){
private function getSignatureContent()
{
try {
if(isset($this->adminStorage)) {
$file = $this->adminStorage->get('/.gestion/sign.jpg');
return $file->getContent();
}
} catch(\OCP\Files\NotFoundException $e) {
}
catch(\OCP\Files\NotFoundException $e) {}
return false;
}