HOTFIX facture group and simple
This commit is contained in:
parent
25b27a7f32
commit
a0d17190bf
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace OCA\Gestion\Controller;
|
namespace OCA\Gestion\Controller;
|
||||||
|
|
||||||
use OCA\Gestion\Constants\BddConstant;
|
use OCA\Gestion\Constants\BddConstant;
|
||||||
@ -16,7 +17,7 @@ use OCA\Gestion\Service\InvoicePdfService;
|
|||||||
use OCP\IUserSession;
|
use OCP\IUserSession;
|
||||||
|
|
||||||
date_default_timezone_set('Europe/Paris');
|
date_default_timezone_set('Europe/Paris');
|
||||||
class InvoiceController extends Controller
|
class InvoiceController extends Controller
|
||||||
{
|
{
|
||||||
private Bdd $gestionRepository;
|
private Bdd $gestionRepository;
|
||||||
private InvoicePdfService $invoicePdfService;
|
private InvoicePdfService $invoicePdfService;
|
||||||
@ -31,11 +32,11 @@ class InvoiceController extends Controller
|
|||||||
private $user;
|
private $user;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
$UserId,
|
$UserId,
|
||||||
$AppName,
|
$AppName,
|
||||||
IRequest $request,
|
IRequest $request,
|
||||||
IConfig $config,
|
IConfig $config,
|
||||||
Bdd $bdd,
|
Bdd $bdd,
|
||||||
InvoicePdfService $invoicePdfService,
|
InvoicePdfService $invoicePdfService,
|
||||||
@ -43,9 +44,7 @@ class InvoiceController extends Controller
|
|||||||
IMailer $mailer,
|
IMailer $mailer,
|
||||||
MailerService $mailerService,
|
MailerService $mailerService,
|
||||||
IUserSession $userSession
|
IUserSession $userSession
|
||||||
|
) {
|
||||||
)
|
|
||||||
{
|
|
||||||
$this->currentUserIdNextcloud = $UserId;
|
$this->currentUserIdNextcloud = $UserId;
|
||||||
$this->invoicePdfService = $invoicePdfService;
|
$this->invoicePdfService = $invoicePdfService;
|
||||||
$this->rootFolder = $rootFolder;
|
$this->rootFolder = $rootFolder;
|
||||||
@ -54,65 +53,65 @@ class InvoiceController extends Controller
|
|||||||
$this->mailerService = $mailerService;
|
$this->mailerService = $mailerService;
|
||||||
$this->config = $config;
|
$this->config = $config;
|
||||||
$this->user = $userSession->getUser();
|
$this->user = $userSession->getUser();
|
||||||
|
|
||||||
try{
|
|
||||||
$this->storage = $rootFolder->getUserFolder($this->currentUserIdNextcloud);
|
|
||||||
}catch(\OC\User\NoUserException $e){
|
|
||||||
|
|
||||||
}
|
try {
|
||||||
|
$this->storage = $rootFolder->getUserFolder($this->currentUserIdNextcloud);
|
||||||
|
} catch(\OC\User\NoUserException $e) {
|
||||||
|
|
||||||
|
}
|
||||||
parent::__construct($AppName, request: $request);
|
parent::__construct($AppName, request: $request);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
*/
|
*/
|
||||||
|
|
||||||
public function getInvoicePdfContent($factureId){
|
public function getInvoicePdfContent($factureId)
|
||||||
|
{
|
||||||
$facture = $this->gestionRepository->getFactureByFactureId($factureId);
|
$facture = $this->gestionRepository->getFactureByFactureId($factureId);
|
||||||
if($facture == null)
|
if($facture == null) {
|
||||||
{
|
|
||||||
return new DataResponse("La facture n'existe pas", 404, ['Content-Type' => 'application/json']);
|
return new DataResponse("La facture n'existe pas", 404, ['Content-Type' => 'application/json']);
|
||||||
}
|
}
|
||||||
$factureGeneratedResponse = $this->invoicePdfService->generateFacturePdfByFactureId($factureId,$this->currentUserIdNextcloud);
|
$factureGeneratedResponse = $this->invoicePdfService->generateFacturePdfByFactureId($factureId, $this->currentUserIdNextcloud);
|
||||||
if($factureGeneratedResponse == null){
|
if($factureGeneratedResponse == null) {
|
||||||
return new DataResponse("La facture n'a pas été générée correctement", 404, ['Content-Type' => 'application/json']);
|
return new DataResponse("La facture n'a pas été générée correctement", 404, ['Content-Type' => 'application/json']);
|
||||||
}
|
}
|
||||||
$factureContent = base64_encode($factureGeneratedResponse['content']);
|
$factureContent = base64_encode($factureGeneratedResponse['content']);
|
||||||
return new DataResponse([
|
return new DataResponse([
|
||||||
"content" => $factureContent
|
"content" => $factureContent
|
||||||
], 200, ['Content-Type' => 'application/json']);
|
], 200, ['Content-Type' => 'application/json']);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @NoAdminRequired
|
* @NoAdminRequired
|
||||||
* @NoCSRFRequired
|
* @NoCSRFRequired
|
||||||
*/
|
*/
|
||||||
public function sendInvoicePdfViaMail($factureId, $email = '')
|
public function sendInvoicePdfViaMail($factureId, $email = '')
|
||||||
{
|
{
|
||||||
$facture = $this->gestionRepository->getFactureByFactureId($factureId);
|
$facture = $this->gestionRepository->getFactureByFactureId($factureId);
|
||||||
if($facture == null)
|
if($facture == null) {
|
||||||
{
|
|
||||||
return new DataResponse("La facture n'existe pas", 404, ['Content-Type' => 'application/json']);
|
return new DataResponse("La facture n'existe pas", 404, ['Content-Type' => 'application/json']);
|
||||||
}
|
}
|
||||||
$factureGeneratedResponse = $this->invoicePdfService->generateFacturePdfByFactureId($factureId,$this->currentUserIdNextcloud);
|
$factureGeneratedResponse = $this->invoicePdfService->generateFacturePdfByFactureId($factureId, $this->currentUserIdNextcloud);
|
||||||
if($factureGeneratedResponse == null){
|
if($factureGeneratedResponse == null) {
|
||||||
return new DataResponse("La facture n'a pas été générée correctement", 404, ['Content-Type' => 'application/json']);
|
return new DataResponse("La facture n'a pas été générée correctement", 404, ['Content-Type' => 'application/json']);
|
||||||
}
|
}
|
||||||
$factureContent = $factureGeneratedResponse["content"];
|
$factureContent = $factureGeneratedResponse["content"];
|
||||||
$factureDate = DateHelpers::convertInvoiceDateToMonthAndYearOnly($facture['date_paiement']);
|
$factureDate = DateHelpers::convertInvoiceDateToMonthAndYearOnly($facture['date_paiement']);
|
||||||
try {
|
try {
|
||||||
|
|
||||||
$message = $this->mailer->createMessage();
|
$message = $this->mailer->createMessage();
|
||||||
$message->setTo(recipients: [$email => "Facture"]);
|
$message->setTo(recipients: [$email => "Facture"]);
|
||||||
$content = $this->mailer->createAttachment($factureContent, "Facture.pdf", "application/pdf");
|
$content = $this->mailer->createAttachment($factureContent, "Facture.pdf", "application/pdf");
|
||||||
$message->attach($content);
|
$message->attach($content);
|
||||||
$message->setSubject("Facture");
|
$message->setSubject("Facture");
|
||||||
|
|
||||||
$signature = $this->mailerService->getFooterContent();
|
$signature = $this->mailerService->getFooterContent($this->getUserNameForEmailSignature());
|
||||||
|
|
||||||
|
|
||||||
$message->setHtmlBody(
|
$message->setHtmlBody(
|
||||||
"<p>Bonjour.</p>".
|
"<p>Bonjour.</p>".
|
||||||
"<p> Vous trouverez en pièce jointe la facture des soins de " . $factureDate . ".</p>".
|
"<p> Vous trouverez en pièce jointe la facture des soins de " . $factureDate . ".</p>".
|
||||||
$signature
|
$signature
|
||||||
);
|
);
|
||||||
@ -120,7 +119,7 @@ class InvoiceController extends Controller
|
|||||||
if ($appAdminEmail) {
|
if ($appAdminEmail) {
|
||||||
$message->setCc([$appAdminEmail]);
|
$message->setCc([$appAdminEmail]);
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->mailer->send($message);
|
$this->mailer->send($message);
|
||||||
$this->gestionRepository->setFactureSentDate($factureId);
|
$this->gestionRepository->setFactureSentDate($factureId);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
@ -128,4 +127,11 @@ class InvoiceController extends Controller
|
|||||||
}
|
}
|
||||||
return new DataResponse("E-mail envoyé avec succès à ".$email.".", 200, ['Content-Type' => 'application/json']);
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@ -3352,6 +3352,7 @@ class Bdd
|
|||||||
if($factureData == null) {
|
if($factureData == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
$products = $this->getDevisProduits($factureData["devis_id"]);
|
$products = $this->getDevisProduits($factureData["devis_id"]);
|
||||||
$isDevisNegative = $this->isDevisNegative($factureData['devis_id'], $factureData['client_id']);
|
$isDevisNegative = $this->isDevisNegative($factureData['devis_id'], $factureData['client_id']);
|
||||||
$factureData = $this->setDevisStartAndEndTime($factureData);
|
$factureData = $this->setDevisStartAndEndTime($factureData);
|
||||||
@ -3359,6 +3360,11 @@ class Bdd
|
|||||||
$factureData["products"] = $products;
|
$factureData["products"] = $products;
|
||||||
$factureData["configuration"] = $configuration;
|
$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;
|
$isClientInsideGroup = $factureData["group_id"] != null;
|
||||||
if($isClientInsideGroup) {
|
if($isClientInsideGroup) {
|
||||||
$factureData["client_real_adress"] = $factureData["group_address"];
|
$factureData["client_real_adress"] = $factureData["group_address"];
|
||||||
@ -3371,11 +3377,15 @@ class Bdd
|
|||||||
$factureData["client_real_adress"] = $clientAdresses["address"];
|
$factureData["client_real_adress"] = $clientAdresses["address"];
|
||||||
$factureData["client_adress_city"] = $clientAdresses["city"];
|
$factureData["client_adress_city"] = $clientAdresses["city"];
|
||||||
}
|
}
|
||||||
|
|
||||||
$factureData['is_negative'] = $isDevisNegative;
|
$factureData['is_negative'] = $isDevisNegative;
|
||||||
|
$factureData["is_tva"] = $hasTva;
|
||||||
|
$factureData["client_tva_intracommu"] = $groupClient["tva_intracommu"];
|
||||||
|
|
||||||
$configurationAdresses = FileExportHelpers::GetAddressAndCityFromAddress($configuration->adresse);
|
$configurationAdresses = FileExportHelpers::GetAddressAndCityFromAddress($configuration->adresse);
|
||||||
$factureData["configuration_adresse"] = $configurationAdresses["address"];
|
$factureData["configuration_adresse"] = $configurationAdresses["address"];
|
||||||
$factureData["configuration_adresse_city"] = $configurationAdresses["city"];
|
$factureData["configuration_adresse_city"] = $configurationAdresses["city"];
|
||||||
|
|
||||||
return $factureData;
|
return $factureData;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -29,40 +29,44 @@ namespace OCA\Gestion\Service;
|
|||||||
use OCA\Gestion\Constants\BddConstant;
|
use OCA\Gestion\Constants\BddConstant;
|
||||||
use OCP\Files\IRootFolder;
|
use OCP\Files\IRootFolder;
|
||||||
|
|
||||||
class MailerService {
|
class MailerService
|
||||||
|
{
|
||||||
private $adminStorage;
|
private $adminStorage;
|
||||||
|
|
||||||
public function __construct(
|
public function __construct(
|
||||||
IRootFolder $rootFolder,
|
IRootFolder $rootFolder,
|
||||||
){
|
) {
|
||||||
$this->adminStorage = $rootFolder->getUserFolder(BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD);
|
$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>";
|
{
|
||||||
|
$wish = "<p>Vous en souhaitant bonne réception. </p>";
|
||||||
$cordialement = "<p> Cordialement,</p>";
|
$cordialement = "<p> Cordialement,</p>";
|
||||||
$userName = "<p> {$userName} </p>" ;
|
$userName = "<p> {$userName} </p>" ;
|
||||||
$signatureImage = $this->getSignatureHtmlEmailContent();
|
// $signatureImage = $this->getSignatureHtmlEmailContent();
|
||||||
return $wish . $cordialement .$userName . $signatureImage ;
|
// return $wish . $cordialement .$userName . $signatureImage ;
|
||||||
}
|
return $wish . $cordialement .$userName ;
|
||||||
|
}
|
||||||
private function getSignatureHtmlEmailContent (){
|
|
||||||
$signatureImage = $this->getSignatureContent();
|
private function getSignatureHtmlEmailContent()
|
||||||
if (!$signatureImage) {
|
{
|
||||||
return "";
|
$signatureImage = $this->getSignatureContent();
|
||||||
}
|
if (!$signatureImage) {
|
||||||
return "<img width='170' height='80' style= 'width: 170;height: 80px;display:block;' src='data:image/jpeg;base64,".base64_encode($signatureImage)."'>" ;
|
return "";
|
||||||
}
|
}
|
||||||
|
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()
|
||||||
$file = $this->adminStorage->get('/.gestion/sign.jpg');
|
{
|
||||||
return $file->getContent();
|
try {
|
||||||
}
|
if(isset($this->adminStorage)) {
|
||||||
}
|
$file = $this->adminStorage->get('/.gestion/sign.jpg');
|
||||||
catch(\OCP\Files\NotFoundException $e) {}
|
return $file->getContent();
|
||||||
|
}
|
||||||
return false;
|
} catch(\OCP\Files\NotFoundException $e) {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user