Merge branch 'staging' into features/feature-send-defunt-certificate-to-client

This commit is contained in:
Tiavina 2025-03-07 17:35:52 +03:00
commit b57b8d63fc
38 changed files with 488 additions and 69 deletions

View File

@ -177,5 +177,9 @@ return [
// API
['name' => 'api#getDefundIdByCalendarUuid', 'url' => '/api/getDefundIdByCalendarUuid/{uuid}', 'verb' => 'GET'],
//invoice controller
['name' => 'invoice#sendInvoicePdfViaMail', 'url' => '/invoice/{factureId}/sendInvoicePdfViaMail', 'verb' => 'POST'],
['name' => 'invoice#getInvoicePdfContent', 'url' => '/invoice/{factureId}/getInvoicePdfContent', 'verb' => 'GET'],
]
];

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -0,0 +1,99 @@
<?php
namespace OCA\Gestion\Controller;
use OCA\Gestion\Db\Bdd;
use OCA\Gestion\Service\InvoicePdfService;
use OCP\AppFramework\Controller;
use OCP\AppFramework\Http\DataResponse;
use OCP\DB\Exception;
use OCP\Files\IRootFolder;
use OCP\IRequest;
use OCP\Mail\IMailer;
class InvoiceController extends Controller
{
private Bdd $gestionRepository;
private InvoicePdfService $invoicePdfService;
private $rootFolder;
private $mailer;
private $currentUserIdNextcloud;
private $storage;
public function __construct(
$UserId,
$AppName,
IRequest $request,
Bdd $bdd,
InvoicePdfService $invoicePdfService,
IRootFolder $rootFolder,
IMailer $mailer
)
{
$this->currentUserIdNextcloud = $UserId;
$this->invoicePdfService = $invoicePdfService;
$this->rootFolder = $rootFolder;
$this->mailer = $mailer;
$this->gestionRepository = $bdd;
try{
$this->storage = $rootFolder->getUserFolder($this->currentUserIdNextcloud);
}catch(\OC\User\NoUserException $e){
}
parent::__construct($AppName, request: $request);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
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){
return new DataResponse("La facture n'a pas été générée correctement", 404, ['Content-Type' => 'application/json']);
}
$factureContent = base64_encode($factureGeneratedResponse['content']);
return new DataResponse([
"content" => $factureContent
], 200, ['Content-Type' => 'application/json']);
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*/
public function sendInvoicePdfViaMail($factureId)
{
$facture = $this->gestionRepository->getFactureByFactureId($factureId);
if($facture == null)
{
return new DataResponse("La facture n'existe pas", 404, ['Content-Type' => 'application/json']);
}
$factureClientMail = $this->gestionRepository->getFactureClientMailByFactureId($factureId);
if($factureClientMail == null){
return new DataResponse("Le mail de la facture n'existe pas", 404, ['Content-Type' => 'application/json']);
}
$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"];
try {
$message = $this->mailer->createMessage();
$message->setTo(recipients: [$factureClientMail => "Facture"]);
$content = $this->mailer->createAttachment($factureContent, "Facture.pdf", "application/pdf");
$message->attach($content);
$message->setSubject("Facture");
$message->setPlainBody("Veuiller trouver ci-joint votre facture");
$this->mailer->send($message);
$this->gestionRepository->setFactureSentDate($factureId);
} catch (Exception $e) {
return new DataResponse("Veuillez configurer le mail sur nextcloud ?", 500, ['Content-Type' => 'application/json']);
}
return new DataResponse("Mail envoyé avec succès", 200, ['Content-Type' => 'application/json']);
}
}

View File

@ -1129,7 +1129,7 @@ class PageController extends Controller {
* @NoCSRFRequired
*/
public function getFacturesWithProduits() {
$result = $this->myDb->getFacturesWithProduits($this->idNextcloud);
$result = $this->myDb->getFacturesWithProduits();
$this->refreshFEC();
return $result;
}
@ -2537,8 +2537,8 @@ class PageController extends Controller {
public function exportFactureToPdf($factureId){
try{
$factureFilenames = $this->invoicePdfService->generateFacturePdfByFactureId($factureId,$this->idNextcloud);
return json_encode($factureFilenames);
$factureGeneratedResponse = $this->invoicePdfService->generateFacturePdfByFactureId($factureId,$this->idNextcloud);
return json_encode($factureGeneratedResponse["filenames"]);
}
catch(\OCP\Files\NotFoundException $e) { }
@ -3025,6 +3025,11 @@ class PageController extends Controller {
public function factureGroupDetails($numfacture){
$this->denyIfNotAdmin();
$facture = $this->myDb->getFactureGroupByFactureIdWithDetails($numfacture);
$facture["path_to_file"] = $this->idNextcloud.'/'.FileExportHelpers::GetFactureGroupFileFullPath(
clientName:$facture['group_name'],
factureNum: $facture['num'],
facturationDate: $facture['date_paiement']
);
return new TemplateResponse('gestion', 'factureGroupDetails', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud,
'configuration'=> $this->getConfiguration(),
'facture'=>json_decode(json_encode($facture)),

View File

@ -264,6 +264,7 @@ class Bdd {
.$this->tableprefix."client.fk_client_group_facturation_id as fk_client_group_facturation_id,"
.$this->tableprefix."thanato.nom as nom_thanato, ".$this->tableprefix."thanato.prenom as prenom_thanato, ".$this->tableprefix."thanato.id as tid, "
.$this->tableprefix."devis.num, ".$this->tableprefix."devis.date, ".$this->tableprefix."devis.version, ".$this->tableprefix."devis.mentions, "
.$this->tableprefix."devis.order_number, ".$this->tableprefix."devis.case_number, "
.$this->tableprefix."lieu.id as lid, ".$this->tableprefix."lieu.nom as lieu,".$this->tableprefix."lieu.adresse as adresse_soin,".$this->tableprefix."devis.id_lieu, "
.$this->tableprefix."defunt.id as id_defunt, ".$this->tableprefix."defunt.nom as nom_defunt, "
.$this->tableprefix."devis.devis_full_number as devis_full_number
@ -348,6 +349,57 @@ class Bdd {
return json_encode($result);
}
public function getFacturesListWithDependencies(){
$sql = "SELECT
facture.id,
facture.user_id,
facture.num,
facture.date,
facture.fk_facture_status_key,
facture.fk_facture_payment_type_id,
facture.payment_date,
facture_payment_type.facture_payment_type_label,
facture_status.facture_status_label,
facture.facture_type,
facture.fk_client_id as facture_client_id,
facture.fk_client_group_facturation_id as facture_client_group_facturation_id,
facture.date_paiement,
facture.type_paiement,
facture.id_devis,
facture.version,
facture.status_paiement,
facture_client.nom as facture_client_name,
facture_client_group_facturation.group_facturation_name as facture_group_name,
devis.num as dnum,
devis.comment as dcomment,
client.entreprise,
client.nom,
client.prenom,
client.id as id_cli,
client.entreprise as client_entreprise,
client.fk_client_group_facturation_id as fk_client_group_facturation_id,
client.adresse as adresse_cli,client.mail as mail_cli,
client.telephone as telephone_cli,client.legal_one as legalone_cli,
client.fk_client_group_id as fk_client_group_id,
defunt.id as id_defunt,
defunt.nom as nom_defunt,
lieu.id as lid,
lieu.nom as lieu,
lieu.adresse as adresse_soin,devis.id_lieu
FROM ".$this->tableprefix."facture as facture
LEFT JOIN ".$this->tableprefix."devis as devis on facture.id_devis = devis.id
LEFT JOIN ".$this->tableprefix."lieu as lieu on devis.id_lieu = lieu.id
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
LEFT JOIN ".$this->tableprefix."defunt as defunt on devis.id_defunt = defunt.id
LEFT JOIN ".$this->tableprefix."facture_payment_type as facture_payment_type on facture.fk_facture_payment_type_id = facture_payment_type.id
LEFT JOIN ".$this->tableprefix."facture_status as facture_status on facture.fk_facture_status_key = facture_status.facture_status_key
LEFT JOIN ".$this->tableprefix."client as facture_client on facture.fk_client_id = facture_client.id
LEFT JOIN ".$this->tableprefix."client_group_facturation as facture_client_group_facturation on facture.fk_client_group_facturation_id = facture_client_group_facturation.id
ORDER BY facture.id DESC, facture.date_paiement DESC";
$result = $this->execSQL($sql, array());
return $result;
}
public function getFactures($idNextcloud){
$sql = "SELECT ".$this->tableprefix."facture.id, ".$this->tableprefix."facture.user_id, ".$this->tableprefix."facture.num, ".$this->tableprefix."facture.date, "
.$this->tableprefix."facture.fk_facture_status_key, ".$this->tableprefix."facture.fk_facture_payment_type_id, ".$this->tableprefix."facture.payment_date, "
@ -356,6 +408,8 @@ class Bdd {
.$this->tableprefix."facture.facture_type, "
.$this->tableprefix."facture.fk_client_id as facture_client_id, "
.$this->tableprefix."facture.fk_client_group_facturation_id as facture_client_group_facturation_id, "
.$this->tableprefix."facture.document_generated_date as facture_document_generated_date, "
.$this->tableprefix."facture.document_sent_date as facture_document_sent_date, "
.$this->tableprefix."devis.num as dnum, ".$this->tableprefix."devis.comment as dcomment, date_paiement, type_paiement, id_devis, entreprise, "
.$this->tableprefix."facture.version, status_paiement,"
.$this->tableprefix."client.nom, ".$this->tableprefix."client.prenom, "
@ -377,8 +431,8 @@ class Bdd {
return $result;
}
public function getFacturesWithProduits($idNextCloud){
$factures = $this->getFactures($idNextCloud);
public function getFacturesWithProduits(){
$factures = $this->getFacturesListWithDependencies();
$facturesList = json_decode($factures);
foreach($facturesList as $currentFacture){
$produits = $this->getProduitsDevisByDevisId($currentFacture->id_devis);
@ -545,18 +599,22 @@ class Bdd {
}
public function getOneFacture($numfacture, $idNextcloud){
// $sql = "SELECT ".$this->tableprefix."facture.id," . $this->tableprefix . "facture.version," . $this->tableprefix . "facture.num, ".$this->tableprefix."facture.date, ".$this->tableprefix."devis.num as dnum, comment, date_paiement, type_paiement, id_devis, nom, prenom, entreprise FROM (".$this->tableprefix."facture LEFT JOIN ".$this->tableprefix."devis on ".$this->tableprefix."facture.id_devis = ".$this->tableprefix."devis.id AND ".$this->tableprefix."facture.id_nextcloud = ".$this->tableprefix."devis.id_nextcloud) LEFT JOIN ".$this->tableprefix."client on ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id AND ".$this->tableprefix."devis.id_nextcloud = ".$this->tableprefix."client.id_nextcloud WHERE ".$this->tableprefix."facture.id = ? AND ".$this->tableprefix."facture.id_nextcloud = ?";
$sql = "SELECT ".$this->tableprefix."facture.id," . $this->tableprefix . "facture.version," . $this->tableprefix . "facture.num, "
.$this->tableprefix."facture.date, ".$this->tableprefix."devis.num as dnum, comment, date_paiement, type_paiement, id_devis, ".$this->tableprefix."client.nom, prenom, entreprise,"
.$this->tableprefix."devis.comment as dcomment,".$this->tableprefix."lieu.nom as lieu, ".$this->tableprefix."lieu.adresse as adresse_soin,"
.$this->tableprefix."defunt.nom as nom_defunt, "
.$this->tableprefix."devis.order_number as order_number, "
.$this->tableprefix."devis.case_number as case_number, "
.$this->tableprefix."client.id as client_id, "
.$this->tableprefix."client.mail as client_mail, "
.$this->tableprefix."client_group_facturation.id as group_client_id, "
.$this->tableprefix."client_group_facturation.email as group_client_mail, "
.$this->tableprefix."facture_payment_type.facture_payment_type_label as facture_payment_type_label
FROM (".$this->tableprefix."facture
LEFT JOIN ".$this->tableprefix."devis on ".$this->tableprefix."facture.id_devis = ".$this->tableprefix."devis.id
LEFT JOIN ".$this->tableprefix."lieu on ".$this->tableprefix."devis.id_lieu = ".$this->tableprefix."lieu.id)
LEFT JOIN ".$this->tableprefix."client on ".$this->tableprefix."devis.id_client = ".$this->tableprefix."client.id
LEFT JOIN ".$this->tableprefix."client_group_facturation on ".$this->tableprefix."client.fk_client_group_facturation_id = ".$this->tableprefix."client_group_facturation.id
LEFT JOIN ".$this->tableprefix."defunt on ".$this->tableprefix."devis.id_defunt = ".$this->tableprefix."defunt.id
LEFT JOIN ".$this->tableprefix."facture_payment_type on ".$this->tableprefix."facture.fk_facture_payment_type_id = ".$this->tableprefix."facture_payment_type.id
WHERE ".$this->tableprefix."facture.id = ?";
@ -4424,7 +4482,9 @@ class Bdd {
facture.fk_client_id,
facture.fk_client_group_facturation_id,
facture.month,
facture.year
facture.year,
facture.facture_case_number,
facture.facture_order_number
FROM ".$this->tableprefix."facture as facture
WHERE facture.id = ? AND
facture.facture_type = ?
@ -4509,4 +4569,71 @@ class Bdd {
$facture["isFactureClientGroup"] = !$isFactureSingleClient;
return $facture;
}
public function setFactureGeneratedDate($factureId){
$datetimeNow = new Datetime();
$dateNow = $datetimeNow->format("Y-m-d");
$sql = "UPDATE ".$this->tableprefix."facture set document_generated_date = ? WHERE id = ?";
$this->execSQLNoData($sql,[
$dateNow,
$factureId
]);
}
public function setFactureSentDate($factureId){
$datetimeNow = new Datetime();
$dateNow = $datetimeNow->format("Y-m-d");
$sql = "UPDATE ".$this->tableprefix."facture set document_sent_date = ? WHERE id = ?";
$this->execSQLNoData($sql,[
$dateNow,
$factureId
]);
}
public function getFactureClientMailByFactureId($factureId){
$sql = "SELECT
facture.id,
facture.facture_type,
facture_client.mail as facture_client_mail,
facture_client_group_facturation.email as facture_client_group_mail,
facture.fk_client_id as facture_client_id,
facture.fk_client_group_facturation_id as facture_client_group_facturation_id,
client.id as client_id,
client.fk_client_group_facturation_id as devis_client_group_facturation_id,
client.mail as devis_client_mail,
client_group_facturation.email as devis_client_group_mail
FROM ".$this->tableprefix."facture as facture
LEFT JOIN ".$this->tableprefix."devis as devis
on facture.id_devis = devis.id
LEFT JOIN ".$this->tableprefix."client as client
on devis.id_client = client.id
LEFT JOIN ".$this->tableprefix."client_group_facturation as client_group_facturation
on client.fk_client_group_facturation_id = client_group_facturation.id
LEFT JOIN ".$this->tableprefix."client as facture_client
on facture.fk_client_id = facture_client.id
LEFT JOIN ".$this->tableprefix."client_group_facturation as facture_client_group_facturation
on facture.fk_client_group_facturation_id = client_group_facturation.id
WHERE facture.id = ?
LIMIT 1;";
$mail = null;
$result = $this->execSQLNoJsonReturn($sql,[$factureId]);
if(!empty($result)){
$facture = $result[0];
$factureIsSingle = $facture["facture_type"] == FactureTypeConstant::TYPE_SINGLE;
if($factureIsSingle){
$mail = $facture["fk_client_group_facturation_id"] != null ?
$facture["devis_client_group_mail"] :
$facture["devis_client_mail"];
}
else{
$factureIsClientWithoutGroup = $facture["facture_client_id"] != null && $facture["facture_client_id"] != 0;
$mail = $factureIsClientWithoutGroup ?
$facture["facture_client_mail"] :
$facture["facture_client_group_mail"];
}
}
return $mail;
}
}

View File

@ -2,6 +2,8 @@
namespace OCA\Gestion\Helpers;
use DateTime;
class FileExportHelpers
{
@ -53,6 +55,27 @@ class FileExportHelpers
return $racinePath.'CLIENTS/'.mb_strtoupper($clientName,'UTF-8').'/';
}
public static function GetFactureGroupFilename($factureNum,$clientName){
$factureNum = str_replace('/','-',$factureNum);
$clientName = str_replace('&nbsp;',' ',$clientName ?? '');
return 'FACTURE'.'_'.$factureNum.'_'.mb_strtoupper($clientName,'UTF-8').'.pdf';
}
public static function GetFactureGroupFolder($clientName,$facturationDate){
$clientRacineFolder = 'CLIENTS/'.mb_strtoupper($clientName,'UTF-8').'/';
$factureDatetime = new DateTime($facturationDate);
$factureDateYear = $factureDatetime->format('Y');
$factureMonth = DateHelpers::GetDateWithFormatDayAndMonthPlainString($facturationDate);
$factureByYearFolder = $clientRacineFolder."$factureDateYear".'/'.$factureMonth.'/'.'FACTURES'.'/';
return $factureByYearFolder;
}
public static function GetFactureGroupFileFullPath($clientName,$factureNum,$facturationDate){
$factureFolder = self::GetFactureGroupFolder($clientName,$facturationDate);
$factureFilename = self::GetFactureGroupFilename($factureNum,$clientName);
return $factureFolder.$factureFilename;
}
public static function GetDefuntsFolder($clientName,$defuntName,$racinePath){
$clientsFolder = self::GetClientsFolder($clientName,$racinePath);
return $clientsFolder.'DEFUNTS/'.mb_strtoupper($defuntName,'UTF-8').'/';

View File

@ -91,7 +91,7 @@ class InvoiceGroupPdfHandler extends FPDF {
$factureNum = $this->factureData['num'];
$factureNum = str_replace('/','-',$factureNum);
$clientName = str_replace('&nbsp;',' ',$this->factureData['group_name'] ?? '');
return $this->factureData['configuration']->facture_prefixe.'_'.$factureNum.'_'.mb_strtoupper($clientName,'UTF-8');
return 'FACTURE'.'_'.$factureNum.'_'.mb_strtoupper($clientName,'UTF-8');
}
public function DrawPageNumbersText($pageNumber,$pageCount){

View File

@ -88,7 +88,7 @@ class InvoicePdfService {
$logo = $this->getLogo();
$invoicePdfData = $this->gestionBdd->getInvoicePdfData($factureId,$currentConfig);
if($invoicePdfData == null){
return "";
return null;
}
$clean_folder = html_entity_decode(string: $currentConfig->path).'/';
$factureFolders = $this->getFacturesFolder($invoicePdfData,$clean_folder);
@ -112,7 +112,11 @@ class InvoicePdfService {
$file_pdf->putContent($pdfContent);
$filenames[] = $ff_pdf;
}
return $filenames;
$this->gestionBdd->setFactureGeneratedDate($factureId);
return [
"content" => $pdfContent,
"filenames" => $filenames
];
}
public function generateFacturePdfByFactureId($factureId,$idNextCloud){
@ -195,7 +199,11 @@ class InvoicePdfService {
$file_pdf->putContent($pdfContent);
$filenames[] = $ff_pdf;
}
return $filenames;
$this->gestionBdd->setFactureGeneratedDate($factureId);
return [
"content" => $pdfContent,
"filenames" => $filenames
];
}
public function generateFacturePdfByFactureIds(array $factureIds,$idNextCloud){
@ -279,8 +287,8 @@ class InvoicePdfService {
}
$this->gestionBdd->invoiceListOfDevisIds($devisIds);
$filenames = $this->generateFactureGroupPdfByFactureId($factureId,$idNextcloud);
return $filenames;
$factureGeneratedResponse = $this->generateFactureGroupPdfByFactureId($factureId,$idNextcloud);
return $factureGeneratedResponse["filenames"];
}
catch(Exception){
return null;

View File

@ -4,9 +4,9 @@ import "../css/mycss.css";
import { globalConfiguration } from "./modules/mainFunction.mjs";
import "./listener/main_listener";
import "./listener/invoiceListener";
import "./listener/factureSendMailListener";
import { generateUrl } from "@nextcloud/router";
window.addEventListener("DOMContentLoaded", function () {
globalConfiguration();
});

View File

@ -5,6 +5,7 @@ import "../css/mycss.css";
import { getArticlesById, getMailServerFrom, getProduitsById, saveNextcloud, savePdfToNextcloud} from "./modules/ajaxRequest.mjs";
import { globalConfiguration } from "./modules/mainFunction.mjs";
import "./listener/main_listener";
import "./listener/factureSendMailListener";
import { Client } from "./objects/client.mjs";
import { capture, captureDevisFacture, sendMail } from "./pdf";

View File

@ -0,0 +1,69 @@
import {showError, showSuccess } from "@nextcloud/dialogs";
import {baseUrl, hideLoader, showLoader} from "../modules/mainFunction.mjs";
import { Facture } from "../objects/facture.mjs";
import DataTable from "datatables.net";
import { generateUrl } from "@nextcloud/router";
$('body').on('click', '#showSendFacturePdfMailModal', function () {
$('#sendFacturePdfMail').show();
});
$('body').on('click', '#closeSendFacturePdfMail', function () {
$('#sendFacturePdfMail').hide();
});
$('body').on('click', '#showPdfPreview', function () {
const factureId = $('#factureIdentifier').data('id');
if(factureId){
showLoader();
$.ajax({
url: baseUrl + '/invoice/'+factureId+'/getInvoicePdfContent',
type: 'GET',
contentType: 'application/json'
}).done(function (response, textStatus, xhr) {
if (xhr.status === 200) {
var base64PDF = response.content;
var byteCharacters = atob(base64PDF);
var byteNumbers = new Array(byteCharacters.length);
for (var i = 0; i < byteCharacters.length; i++) {
byteNumbers[i] = byteCharacters.charCodeAt(i);
}
var byteArray = new Uint8Array(byteNumbers);
var fileBlob = new Blob([byteArray], { type: "application/pdf" });
var fileURL = URL.createObjectURL(fileBlob);
window.open(fileURL, "_blank");
} else {
showError(t('gestion', "Erreur dans la récupération du document de la facture"));
}
}).fail(function (response, code) {
showError(response);
}).always(function () {
hideLoader();
});
}
});
$('body').on('click','#sendFacturePdf',function(){
const factureId = $('#factureIdentifier').data('id');
if(factureId){
showLoader();
$.ajax({
url: baseUrl + '/invoice/'+factureId+'/sendInvoicePdfViaMail',
type: 'POST',
contentType: 'application/json'
}).done(function (response, textStatus, xhr) {
if (xhr.status === 200) {
showSuccess(response);
} else {
showError(t('gestion', "Erreur dans l'envoi du mail chez le client"));
}
$('#sendFacturePdfMail').hide();
}).fail(function (response, code) {
$('#sendFacturePdfMail').hide();
showError(response);
}).always(function () {
hideLoader();
});
}
})

View File

@ -34,12 +34,38 @@ export class Facture {
}
this.payment_date = paymentDate;
this.factureType = myresp.facture_type;
if(this.factureType == FactureTypeSingle){
const isFactureSingle = this.factureType == FactureTypeSingle;
if(isFactureSingle){
this.baseUrl = generateUrl(`/apps/gestion/facture/${this.id}/show`);
}
else{
this.baseUrl = generateUrl(`/apps/gestion/facture/${this.id}/groupDetails`);
}
const isDocumentAlreadyGenerated = myresp.facture_document_generated_date != null;
const isDocumentAlreadySent = myresp.facture_document_sent_date != null;
this.isDocumentAlreadyGeneratedLabel = this.getDocumentStateLabel(isDocumentAlreadyGenerated);
this.isDocumentAlreadySentLabel = this.getDocumentStateLabel(isDocumentAlreadySent);
this.isDocumentAlreadyGeneratedClass = this.getDocumentStateClass(isDocumentAlreadyGenerated);
this.isDocumentAlreadySentClass = this.getDocumentStateClass(isDocumentAlreadySent);
this.clientName = this.nom;
if(isFactureSingle == false){
const isFactureClientWithoutGroup = myresp.facture_client_id != null && myresp.facture_client_id != 0;
if(isFactureClientWithoutGroup){
this.clientName = ((myresp.facture_client_name == null || myresp.facture_client_name.length == 0) ? '-' : myresp.facture_client_name);
}
else{
this.clientName = ((myresp.facture_group_name == null || myresp.facture_group_name.length == 0) ? '-' : myresp.facture_group_name);
}
}
}
getDocumentStateLabel(documentState){
return documentState ? "Oui" : "Non";
}
getDocumentStateClass(documentState){
return documentState ? "text-bg-success" : "text-bg-warning";
}
/**
@ -54,10 +80,12 @@ export class Facture {
'<input style="margin:0;padding:0;" class="inputDate devisOrFactureInputDate" type="date" value=' + this.date_paiement + ' data-table="facture" data-column="date_paiement" data-id="' + this.id + '"/>',
'<div>' + this.type_paiement + '</div>',
'<div class="selectAvailableDevis" data-table="facture" data-column="id_devis" data-id="' + this.id + '" data-current="' + this.id_devis + '">' + this.nom_defunt + ' | <span style="font-size: 0.7rem">' + this.prenom + ' ' + this.nom + '</span></div>',
'<div>' + this.nom + '</div>',
'<div>' + this.clientName + '</div>',
'<div>' + this.factureProduits + '</div>',
'<div>' + this.status_paiement + '</div>',
'<div>' + this.payment_date + '</div>',
'<div><span class="badge '+this.isDocumentAlreadyGeneratedClass+'">' + this.isDocumentAlreadyGeneratedLabel + '</span></div>',
'<div><span class="badge '+this.isDocumentAlreadySentClass+'">' + this.isDocumentAlreadySentLabel + '</span></div>',
'<div style="display:inline-block;margin-right:0px;width:80%;"><a href="' + this.baseUrl +'"><button>' + t('gestion', 'Open') + '</button></a></div><div data-modifier="facture" data-id=' + this.id + ' data-table="facture" style="display:inline-block;margin-right:0px;" class="deleteItem icon-delete"></div>',
];
return myrow;

View File

@ -115,16 +115,16 @@
}
;
foreach ($devis as $key => $d) {
foreach ($devis as $key => $currentDevis) {
?>
<div class="bootstrap-iso d-flex flex-column justify-content-between">
<div class="d-flex flex-column w-100">
<h2 class="mt-3 mb-3 text-center"> <?php p($l->t('Quote')); ?>
<div id="devisid" style="display:inline" data-table="devis" data-column="num"
data-id="<?php echo $d->id; ?>">sur le defunt <?php echo $d->nom_defunt; ?></div>
data-id="<?php echo $currentDevis->id; ?>">sur le defunt <?php echo $currentDevis->nom_defunt; ?></div>
<span data-html2canvas-ignore>(</span>
<div data-html2canvas-ignore id="devisversion" style="display:inline" data-table="devis"
data-column="version" data-id="<?php echo $d->id; ?>"><?php echo $d->lieu; ?>)</div>
data-column="version" data-id="<?php echo $currentDevis->id; ?>"><?php echo $currentDevis->lieu; ?>)</div>
</h2>
<hr />
<div class="row">
@ -152,21 +152,21 @@
</div>
<div class="col-5 h-100 m-0" style="min-height:250px;">
<h5 class="p-3 m-0 text-dark text-center border border-2 border-dark"><?php p($l->t('TO')); ?>
<span id="entreprise"><?php echo $d->entreprise ?></span></h6>
<span id="entreprise"><?php echo $currentDevis->entreprise ?></span></h6>
<p
class="p-3 m-0 h-auto text-center text-dark text-center border border-top-0 border-2 border-dark">
<span id="nomprenom" data-id="0" data-table="devis"
data-column="id_client"><?php echo $d->prenom . ' ' . $d->nom ?></span><br />
<span id="adresse"><?php echo $d->adresse_cli ?></span><br />
<span id="mail"><?php echo $d->mail_cli ?></span><br />
<span id="telephone"><?php echo $d->telephone_cli ?></span><br />
<span id="legal_one"><?php echo $d->legalone_cli ?></span><br />
data-column="id_client"><?php echo $currentDevis->prenom . ' ' . $currentDevis->nom ?></span><br />
<span id="adresse"><?php echo $currentDevis->adresse_cli ?></span><br />
<span id="mail"><?php echo $currentDevis->mail_cli ?></span><br />
<span id="telephone"><?php echo $currentDevis->telephone_cli ?></span><br />
<span id="legal_one"><?php echo $currentDevis->legalone_cli ?></span><br />
<span id="dateContext" style="display: none"><?php echo $facture->date ?></span>
<span id="nomcli" style="display: none"><?php echo $d->prenom . ' ' . $d->nom ?></span>
<span id="idcli" style="display: none"><?php echo $d->id_cli ?></span>
<span id="etp" style="display: none"><?php echo $d->entreprise ?></span>
<span id="nomcli" style="display: none"><?php echo $currentDevis->prenom . ' ' . $currentDevis->nom ?></span>
<span id="idcli" style="display: none"><?php echo $currentDevis->id_cli ?></span>
<span id="etp" style="display: none"><?php echo $currentDevis->entreprise ?></span>
<span class="pdf"
style="display: none"><?php echo $d->entreprise . "_" . $d->id . "_v" . $d->version ?></span>
style="display: none"><?php echo $currentDevis->entreprise . "_" . $currentDevis->id . "_v" . $currentDevis->version ?></span>
</p>
</div>
</div>
@ -175,7 +175,7 @@
<hr />
<div class="col col-xl mb-3 text-center">
<b><span><?php p($l->t('Offer valid for 1 month from')); ?> :
</span><span><?php echo (new DateTime($d->date))->format('d-m-Y'); ?></span></b></div>
</span><span><?php echo (new DateTime($currentDevis->date))->format('d-m-Y'); ?></span></b></div>
<hr />
</div>
</div>
@ -183,21 +183,36 @@
<div class="col col-md">
<div class="col col-xl text-center">
<span>Date de soin :
<b><?php echo (new DateTime($d->date))->format('d-m-Y'); ?></b>,</span>&nbsp;<span
id="devisid" data-id=<?php echo $d->id; ?>>Defunt associé :
<b><?php echo $d->num; ?></b></span><br />
<span>Lieu : <b><?php echo $d->lieu; ?> (<?php echo $d->adresse_soin; ?>)</b>
<b><?php echo (new DateTime($currentDevis->date))->format('d-m-Y'); ?></b>,</span>&nbsp;<span
id="devisid" data-id=<?php echo $currentDevis->id; ?>>Defunt associé :
<b><?php echo $currentDevis->nom_defunt; ?></b></span><br />
<span>Lieu : <b><?php echo $currentDevis->lieu; ?> (<?php echo $currentDevis->adresse_soin; ?>)</b>
</div>
</div>
</div>
<div class="row">
<div class="col col-md">
<hr />
<div class="col col-xl mb-3 text-center editable" id="deviscomment" style="display:inline"
data-table="devis" data-column="comment" data-id="<?php echo $d->id; ?>">
<?php echo ($d->comment == "") ? "-" : $d->comment; ?></div>
<hr />
<label class="fw-bold">Commande :</label>
<div class="col col-xl mb-3 text-center editable"
style="display:inline"
data-table="devis" data-column="order_number"
data-id="<?php echo $currentDevis->id;?>">
<?php echo ($currentDevis->order_number == "" ) ? "-" : $currentDevis->order_number ; ?>
</div>
</div>
<hr />
</div>
<div class="row">
<div class="col col-md">
<label class="fw-bold">Numéro de dossier :</label>
<div class="col col-xl mb-3 text-center editable"
style="display:inline"
data-table="devis" data-column="case_number"
data-id="<?php echo $currentDevis->id;?>">
<?php echo ($currentDevis->case_number == "" ) ? "-" : $currentDevis->case_number ; ?>
</div>
</div>
<hr />
</div>
<div class="table-responsive">
<table id="produits" data-type="facture" class="table table-striped">
@ -212,7 +227,7 @@
</tr>
</thead>
<tbody>
<?php foreach ($d->dproduits as $key => $produit) { ?>
<?php foreach ($currentDevis->dproduits as $key => $produit) { ?>
<tr>
<td><?php echo $produit->reference ?></td>
<td><?php echo $produit->description ?></td>
@ -242,7 +257,7 @@
$tva = json_decode($_['configuration'])[0]->tva_default;
$totalttc = 0;
$totalprice = 0;
foreach ($d->dproduits as $key => $produit) {
foreach ($currentDevis->dproduits as $key => $produit) {
$totalhtc = $totalhtc + ($produit->quantite * $produit->prix_unitaire);
}
$totalttc = ($totalhtc * $tva) / 100;

View File

@ -37,6 +37,8 @@
<th><?php p($l->t('Articles'));?></th>
<th><?php p($l->t('Status'));?></th>
<th><?php p($l->t('Date de paiement'));?></th>
<th><?php p($l->t('Généré'));?></th>
<th><?php p($l->t('Envoyé au client'));?></th>
<th><?php p($l->t('Actions'));?></th>
</tr>
</thead>

View File

@ -108,7 +108,10 @@ $currentConfig = json_decode($_['configuration'])[0];
</div>
<div>
<button id="exportFactureToPdf" type="button" class="mb-2 btn btn-outline-success" data-html2canvas-ignore data-name=""><?php p($l->t('Save in Nextcloud'));?></button>
<button id="mailGestion" type="button" class="mb-2 btn btn-outline-success sendmail" data-html2canvas-ignore data-name=""><?php p($l->t('Send by email'));?></button>
<button id="showSendFacturePdfMailModal"
type="button"
class="mb-2 btn btn-outline-success sendmail"
><?php p($l->t('Send by email'));?></button>
</div>
<div class="mt-0 table-responsive">
<table id="totalFactureGroupPrice" class="table table-striped table-xl">
@ -138,4 +141,18 @@ $currentConfig = json_decode($_['configuration'])[0];
<p><?php echo $currentConfig->entreprise; ?><br /><?php echo $currentConfig->adresse; ?><br /><?php echo $currentConfig->legal_one; ?><br /><?php echo $currentConfig->legal_two; ?>
</p>
</div>
<div class="modal" id="sendFacturePdfMail" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Envoyer la facture par email à <?= $facture->mail; ?></h5>
</div>
<div class="modal-footer">
<button id="showPdfPreview" type="button" class="btn btn-secondary">Voir l'aperçu</button>
<button id="closeSendFacturePdfMail" type="button" class="btn btn-secondary">Annuler</button>
<button id="sendFacturePdf" type="button" class="btn btn-primary">Envoyer</button>
</div>
</div>
</div>
</div>
</div>

View File

@ -1,3 +1,7 @@
<?php
$facture = $_['facture'][0];
$clientMail = $facture->client_id != null ? $facture->client_mail : $facture->group_client_mail;
?>
<div class="bootstrap-iso d-flex flex-column justify-content-between">
<div class="d-flex flex-column w-100">
<h2 class="mt-3 mb-3 text-center"><?php p($l->t('Invoice #'));?>
@ -123,7 +127,10 @@
<hr>
<div>
<button id="exportFactureToPdf" type="button" class="mb-2 btn btn-outline-success" data-html2canvas-ignore data-name=""><?php p($l->t('Save in Nextcloud'));?></button>
<button id="mailGestion" type="button" class="mb-2 btn btn-outline-success sendmail" data-html2canvas-ignore data-name=""><?php p($l->t('Send by email'));?></button>
<button id="showSendFacturePdfMailModal"
type="button"
class="mb-2 btn btn-outline-success sendmail"
><?php p($l->t('Send by email'));?></button>
</div>
<div class="mt-0 table-responsive">
<table id="totaldevis" class="table table-striped table-xl">
@ -149,5 +156,19 @@
<p><?php echo $res->entreprise; ?><br /><?php echo $res->adresse; ?><br /><?php echo $res->legal_one; ?><br/><?php echo $res->legal_two; ?></p>
</div>
</div>
<div class="modal" id="sendFacturePdfMail" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title">Envoyer la facture par email à <?= $clientMail; ?></h5>
</div>
<div class="modal-footer">
<button id="showPdfPreview" type="button" class="btn btn-secondary">Voir l'aperçu</button>
<button id="closeSendFacturePdfMail" type="button" class="btn btn-secondary">Annuler</button>
<button id="sendFacturePdf" type="button" class="btn btn-primary">Envoyer</button>
</div>
</div>
</div>
</div>
</div>