Merge branch 'features/feature-facture-per-client-or-client-group' into staging

This commit is contained in:
Tiavina 2025-03-02 12:10:08 +03:00
commit 907653bed0
32 changed files with 595 additions and 153 deletions

View File

@ -169,5 +169,8 @@ return [
['name' => 'page#payInvoices','url' => '/facture/payInvoices', 'verb' => 'POST'],
//relation of user and thanato
['name' => 'page#getUsersNotLinkedToThanato','url' => '/user/getUsersNotLinkedToThanato', 'verb' => 'PROPFIND'],
//group of devis and facture
['name' => 'page#exportGroupOfDevisIntoFacture','url' => '/devis/exportGroupOfDevisIntoFacture', 'verb' => 'POST'],
]
];

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

@ -348,7 +348,7 @@ class PageController extends Controller {
$produits = json_decode($this->myDb->getListProduit($d->id, $this->idNextcloud));
$d->dproduits = $produits;
}
$clients = json_decode($this->myDb->getClients($this->idNextcloud));
$clients = json_decode($this->myDb->getClientsAndClientGroupFacturations(includeClientInsideGroup:false));
return new TemplateResponse('gestion', 'apercustousdevis', array('groups' => $this->groups, 'user' => $this->user, 'path' => $this->idNextcloud,
'configuration'=> $this->getConfiguration(),
'devis'=> $devis,
@ -2926,4 +2926,26 @@ class PageController extends Controller {
return json_encode([]);
}
}
/**
* @NoAdminRequired
* @NoCSRFRequired
*
*/
public function exportGroupOfDevisIntoFacture($clientId,$clientType,$month,$year,$facturationDate){
try{
$result = $this->invoicePdfService->exportGroupOfDevisIntoFacture(
$clientId,
$clientType,
$month,
$year,
$facturationDate,
$this->idNextcloud
);
return json_encode($result);
}
catch(Exception $e) {
return json_encode([]);
}
}
}

View File

@ -259,6 +259,7 @@ class Bdd {
$sql = "SELECT ".$this->tableprefix."devis.id, ".$this->tableprefix."devis.id as devisid, ".$this->tableprefix."devis.user_id,".$this->tableprefix."devis.id_nextcloud ,".$this->tableprefix."devis.comment ,"
.$this->tableprefix."client.nom, ".$this->tableprefix."client.prenom, ".$this->tableprefix."client.id as cid, ".$this->tableprefix."client.id as id_client, "
.$this->tableprefix."client.adresse as adresse_cli,".$this->tableprefix."client.mail as mail_cli,".$this->tableprefix."client.telephone as telephone_cli,".$this->tableprefix."client.legal_one as legalone_cli,"
.$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."lieu.id as lid, ".$this->tableprefix."lieu.nom as lieu,".$this->tableprefix."lieu.adresse as adresse_soin,".$this->tableprefix."devis.id_lieu, "
@ -328,14 +329,18 @@ class Bdd {
return $this->execSQL($sql, array());
}
private function getClientsWithClientType(){
$sql = "SELECT client.*,'client' as client_type FROM ".$this->tableprefix."client as client;";
private function getClientsWithClientType(bool $includeClientInsideGroup = true){
$sql = "SELECT client.*,'client' as client_type FROM ".$this->tableprefix."client as client";
if($includeClientInsideGroup == false){
$sql .= " WHERE client.fk_client_group_facturation_id IS NULL";
}
$sql .= ";";
$clientsWithClientType = $this->execSQLNoJsonReturn($sql,[]);
return $clientsWithClientType;
}
public function getClientsAndClientGroupFacturations(){
$clients = $this->getClientsWithClientType();
public function getClientsAndClientGroupFacturations(bool $includeClientInsideGroup = true){
$clients = $this->getClientsWithClientType($includeClientInsideGroup);
$clientGroupFacturations = $this->getClientGroupFacturationsWithType();
$result = [...$clientGroupFacturations,...$clients];
return json_encode($result);
@ -2793,8 +2798,19 @@ class Bdd {
public function getInvoiceGroupPdfData($factureId,$configuration){
$tvaValue = $configuration->tva_default;
$factureData = $this->getFactureByFactureId($factureId);
$factureDevisList = $this->getInvoiceGroupDevisDatasByFactureId($factureId);
$factureData["group_name"] = "";
$isFactureForSingleClient = $factureData['fk_client_id'] != null && $factureData['fk_client_id'] != 0;
if($isFactureForSingleClient){
$factureDevisList = $this->getDevisDataByClientIdAndMonthYear(
$factureData['fk_client_id'],
$factureData['month'],
$factureData['year']);
}
else{
$factureDevisList = $this->getDevisDataByClientGroupFacturationIdAndMonthYear(
$factureData['fk_client_group_facturation_id'],
$factureData['month'],
$factureData['year']);
}
$factureIncrement = 0;
$productsCount = 0;
$totalHt = 0;
@ -2804,11 +2820,21 @@ class Bdd {
$orderNumber = "";
foreach($factureDevisList as &$devis){
if($factureIncrement == 0){
$factureData["client_real_adress"] = $devis["group_address"] ?? "";
$factureData["client_adress_city"] = $devis["group_postal_code"]." ".$devis["group_city"];
$factureData["client_mail"] = $devis["group_email"];
$factureData["siret"] = $devis["group_siret_number"];
$factureData["group_name"] = $devis["group_name"] ?? "";
if($isFactureForSingleClient){
$clientAddresses = FileExportHelpers::GetAddressAndCityFromAddress($devis['client_adresse']);
$factureData["client_real_adress"] = $clientAddresses['address'];
$factureData["client_adress_city"] = $clientAddresses['city'];
$factureData["client_mail"] = $devis["client_mail"];
$factureData["siret"] = $devis["client_legal_one"];
$factureData["group_name"] = $devis["client_nom"] ?? "";
}
else{
$factureData["client_real_adress"] = $devis["group_address"] ?? "";
$factureData["client_adress_city"] = $devis["group_postal_code"]." ".$devis["group_city"];
$factureData["client_mail"] = $devis["group_email"];
$factureData["siret"] = $devis["group_siret_number"];
$factureData["group_name"] = $devis["group_name"] ?? "";
}
}
$caseNumber = empty($devis["case_number"]) ? $caseNumber : $devis["case_number"];
$orderNumber = empty($devis["order_number"]) ? $orderNumber : $devis["order_number"];
@ -4071,8 +4097,10 @@ class Bdd {
return null;
}
private function createFactureAndReturnFactureId($facturationDate,$type){
public function createFactureAndReturnFactureId($facturationDate,$type,$month = null,$year = null,$fkClientId = null,$fkClientGroupFacturationId = null){
$datetimeNow = new Datetime();
$month = $month ?? $datetimeNow->format('m');
$year = $year ?? $datetimeNow->format('Y');
if($facturationDate == null || $facturationDate == ""){
$facturationDate = DateHelpers::GetLastDayOfTheMonthOfADate($datetimeNow);
$facturationDate = $facturationDate->format('Y-m-d');
@ -4087,7 +4115,7 @@ class Bdd {
$fullFactureNumber = DateHelpers::GetFullFactureOrDevisNumberByDate($datetimeNow,$factureNumber,"FAC");
$last = 0;
$last = $this->lastNumFacture(BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD);
$sql = "INSERT INTO `".$this->tableprefix."facture` (`date`,`id_nextcloud`,`num`,`date_paiement`,`type_paiement`,`id_devis`,`user_id`, `version`,`facture_number`,`facture_type`) VALUES (?,?,?,?,?,?,?,?,?,?);";
$sql = "INSERT INTO `".$this->tableprefix."facture` (`date`,`id_nextcloud`,`num`,`date_paiement`,`type_paiement`,`id_devis`,`user_id`, `version`,`facture_number`,`facture_type`,`month`,`year`,`fk_client_id`,`fk_client_group_facturation_id`) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?);";
$this->execSQLNoData($sql, array(
$factureDate ,
BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD,
@ -4098,7 +4126,11 @@ class Bdd {
$last+1,
"",
$factureNumber,
$type)
$type,
$month,
$year,
$fkClientId,
$fkClientGroupFacturationId)
);
return $this->getFactureIdByFactureNumber($fullFactureNumber);
@ -4128,4 +4160,202 @@ class Bdd {
}
return FactureTypeConstant::TYPE_SINGLE;
}
public function getDevisIdsByClientGroupFacturationIdAndMonthYear($clientGroupFacturationId,$month,$year){
$sql = "SELECT devis.id
FROM ".$this->tableprefix."devis as devis
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
WHERE
client.fk_client_group_facturation_id = ? AND
YEAR(devis.date) = ? AND
MONTH(devis.date) = ?
";
$result = $this->execSQLNoJsonReturn($sql,[$clientGroupFacturationId,$year,$month]);
$devisIds = [];
foreach($result as $currentResult){
$devisIds[] = $currentResult['id'];
}
return $devisIds;
}
public function getDevisIdsByClientIdAndMonthYear($clientId,$month,$year){
$sql = "SELECT devis.id
FROM ".$this->tableprefix."devis as devis
LEFT JOIN ".$this->tableprefix."client as client on devis.id_client = client.id
WHERE
client.id = ? AND
YEAR(devis.date) = ? AND
MONTH(devis.date) = ?
";
$result = $this->execSQLNoJsonReturn($sql,[$clientId,$year,$month]);
$devisIds = [];
foreach($result as $currentResult){
$devisIds[] = $currentResult['id'];
}
return $devisIds;
}
public function getFactureIdByClientIdAndMonthYear($clientId,$month,$year){
$sql = "SELECT
facture.id as facture_id
FROM ".$this->tableprefix."facture as facture
WHERE
facture.fk_client_id = ? AND
facture.year = ? AND
facture.month = ? AND
facture.facture_type = ?";
$result = $this->execSQLNoJsonReturn($sql,[
$clientId,
$year,
$month,
FactureTypeConstant::TYPE_GROUP
]);
if(!empty($result)){
return $result[0]['facture_id'];
}
return null;
}
public function getFactureIdByClientGroupFacturationIdAndMonthYear($clientId,$month,$year){
$sql = "SELECT
facture.id as facture_id
FROM ".$this->tableprefix."facture as facture
WHERE
facture.fk_client_group_facturation_id = ? AND
facture.year = ? AND
facture.month = ? AND
facture.facture_type = ?";
$result = $this->execSQLNoJsonReturn($sql,[
$clientId,
$year,
$month,
FactureTypeConstant::TYPE_GROUP
]);
if(!empty($result)){
return $result[0]['facture_id'];
}
return null;
}
public function invoiceListOfDevisIds($devisIds){
$sqlConditionsPlaceholder = implode(',', array_fill(0, count($devisIds), '?'));
$sql = "UPDATE ".$this->tableprefix."devis as devis
SET devis.mentions = ?
WHERE devis.id IN ($sqlConditionsPlaceholder);";
$conditions = array_merge(
[DevisMentionConstant::FACTURED_FORMATTED],
$devisIds
);
$this->execSQLNoData($sql,$conditions);
}
private function getDevisDataByClientGroupFacturationIdAndMonthYear($clientGroupFacturationId,$month,$year){
$sql = "SELECT
devis.id as devis_id,
devis.date as devis_date,
devis.num as calendar_uuid,
devis.comment as devis_comment,
devis.order_number as order_number,
devis.case_number as case_number,
client.nom as client_nom,
client.entreprise as client_entreprise,
client.adresse as client_adresse,
client.mail as client_mail,
client.legal_one as client_legal_one,
defunt.nom as defunt_nom,
defunt.sexe as defunt_sexe,
lieu.nom as lieu_nom,
lieu.adresse as lieu_adresse,
thanato.nom as thanato_nom,
thanato.prenom as thanato_prenom,
client_group_facturation.id as group_id,
client_group_facturation.group_facturation_name as group_name,
client_group_facturation.phone_number as group_phone_number,
client_group_facturation.address as group_address,
client_group_facturation.postal_code as group_postal_code,
client_group_facturation.city as group_city,
client_group_facturation.email as group_email,
client_group_facturation.siret_number as group_siret_number,
client_group_facturation.tva_intracommu as group_tva_intracommu
FROM ".$this->tableprefix."devis as devis
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."lieu as lieu on devis.id_lieu = lieu.id
LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id
LEFT JOIN ".$this->tableprefix."client_group_facturation as client_group_facturation on client.fk_client_group_facturation_id = client_group_facturation.id
WHERE
client.fk_client_group_facturation_id = ? AND
YEAR(devis.date) = ? AND
MONTH(devis.date) = ?
ORDER BY devis.date ASC;";
$devisList = $this->execSQLNoJsonReturn($sql,[
$clientGroupFacturationId,
$year,
$month
]);
return $devisList;
}
private function getDevisDataByClientIdAndMonthYear($clientId,$month,$year){
$sql = "SELECT
devis.id as devis_id,
devis.date as devis_date,
devis.num as calendar_uuid,
devis.comment as devis_comment,
devis.order_number as order_number,
devis.case_number as case_number,
client.nom as client_nom,
client.entreprise as client_entreprise,
client.adresse as client_adresse,
client.mail as client_mail,
client.legal_one as client_legal_one,
defunt.nom as defunt_nom,
defunt.sexe as defunt_sexe,
lieu.nom as lieu_nom,
lieu.adresse as lieu_adresse,
thanato.nom as thanato_nom,
thanato.prenom as thanato_prenom,
client_group_facturation.id as group_id,
client_group_facturation.group_facturation_name as group_name,
client_group_facturation.phone_number as group_phone_number,
client_group_facturation.address as group_address,
client_group_facturation.postal_code as group_postal_code,
client_group_facturation.city as group_city,
client_group_facturation.email as group_email,
client_group_facturation.siret_number as group_siret_number,
client_group_facturation.tva_intracommu as group_tva_intracommu
FROM ".$this->tableprefix."devis as devis
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."lieu as lieu on devis.id_lieu = lieu.id
LEFT JOIN ".$this->tableprefix."thanato as thanato on devis.id_thanato = thanato.id
LEFT JOIN ".$this->tableprefix."client_group_facturation as client_group_facturation on client.fk_client_group_facturation_id = client_group_facturation.id
WHERE
client.id = ? AND
YEAR(devis.date) = ? AND
MONTH(devis.date) = ?
ORDER BY devis.date ASC;";
$devisList = $this->execSQLNoJsonReturn($sql,[
$clientId,
$year,
$month
]);
return $devisList;
}
}

View File

@ -28,8 +28,6 @@ namespace OCA\Gestion\Service\InvoiceGroupPdfHandler;
use DateTime;
use \FPDF;
use OCA\Gestion\Constants\MultipleFactureTypeConstant;
use OCA\Gestion\Helpers\DateHelpers;
use OCA\Gestion\Helpers\FileExportHelpers;
use OCA\Gestion\Helpers\PriceHelpers;

View File

@ -27,12 +27,14 @@ declare(strict_types=1);
namespace OCA\Gestion\Service;
use DateTime;
use OCA\Gestion\Constants\BddConstant;
use OCA\Gestion\Constants\FactureTypeConstant;
use OCA\Gestion\Constants\MultipleFactureTypeConstant;
use OCA\Gestion\Db\Bdd;
use OCA\Gestion\Helpers\DateHelpers;
use OCA\Gestion\Service\InvoiceGroupPdfHandler\InvoiceGroupPdfHandler;
use OCA\Gestion\Service\InvoiceRecap\InvoiceRecapService;
use OCP\DB\Exception;
use OCP\Files\IRootFolder;
class InvoicePdfService {
@ -224,4 +226,44 @@ class InvoicePdfService {
public function generateInvoiceRecap($filter,$filterType,$date,$idNextCloud){
$this->invoiceRecapService->generateInvoiceRecap($filter,$filterType,$date,$idNextCloud);
}
public function exportGroupOfDevisIntoFacture($clientId,$clientType,$month,$year,$facturationDate,$idNextcloud = BddConstant::DEFAULT_ADMIN_ID_NEXTCLOUD){
try{
$datetime = new Datetime();
$month = $month ?? $datetime->format('m');
$year = $year ?? $datetime->format('Y');
$factureId = null;
$fkClientId = null;
$fkClientGroupFacturationId = null;
if($clientType == MultipleFactureTypeConstant::CLIENT_FILTER_TYPE){
$factureId = $this->gestionBdd->getFactureIdByClientIdAndMonthYear($clientId,$month,$year);
$devisIds = $this->gestionBdd->getDevisIdsByClientIdAndMonthYear($clientId,$month,$year);
$fkClientId = $clientId;
}
else{
$factureId = $this->gestionBdd->getFactureIdByClientGroupFacturationIdAndMonthYear($clientId,$month,$year);
$devisIds = $this->gestionBdd->getDevisIdsByClientGroupFacturationIdAndMonthYear($clientId,$month,$year);
$fkClientGroupFacturationId = $clientId;
}
$clientIsAlreadyFacturedForThisMonthAndYear = $factureId != null && $factureId != 0;
if($clientIsAlreadyFacturedForThisMonthAndYear == false){
$factureId = $this->gestionBdd->createFactureAndReturnFactureId(
$facturationDate,
FactureTypeConstant::TYPE_GROUP,
$month,
$year,
$fkClientId,
$fkClientGroupFacturationId);
}
$this->gestionBdd->invoiceListOfDevisIds($devisIds);
$filenames = $this->generateFactureGroupPdfByFactureId($factureId,$idNextcloud);
return $filenames;
}
catch(Exception){
return null;
}
}
}

View File

@ -0,0 +1,5 @@
alter table oc_gestion_facture
add column fk_client_id INT DEFAULT NULL,
add column fk_client_group_facturation_id INT DEFAULT NULL,
add column month int DEFAULT NULL,
add column year int DEFAULT NULL;

View File

@ -4,6 +4,7 @@ import "../css/mycss.css";
import { globalConfiguration } from "./modules/mainFunction.mjs";
import "./listener/main_listener";
import "./listener/devisListener";
import { exportClientDevisByMonthAndYearToPdf } from "./modules/ajaxRequest.mjs";
import 'select2/dist/css/select2.css';
import 'select2';

View File

@ -130,3 +130,70 @@ $('body').on('click', '#cocher', function () {
$('#cocherparmois').hide();
});
document.onchange = function(event) {
if (event.target && event.target.id === 'clientselector') {
let selectedOption = event.target.options[event.target.selectedIndex];
let filterType = selectedOption.getAttribute('data-type');
let filterTypeInput = document.getElementById('filterType');
if (filterTypeInput) {
filterTypeInput.value = filterType;
}
}
};
$('body').on('click', '#showGroupDevisFacturationModal', function () {
console.log("sdsfs");
$('#groupDevisFacturationModal').show();
});
$('body').on('click', '#closeGroupDevisModal', function () {
$('#groupDevisFacturationModal').hide();
});
$('body').on('click', '#invoiceGroupQuote', function () {
var dateValue = document.getElementById("facturationDate").value;
const urlParams = new URLSearchParams(window.location.search);
const filter = urlParams.get('cli');
const year = urlParams.get('annee');
const month = urlParams.get('mois');
const filterType = urlParams.get('filterType');
var invoiceGroupQuotePayload = {
clientId : filter,
month : month,
year : year,
clientType : filterType,
facturationDate : dateValue
};
showLoader();
$.ajax({
url: baseUrl + '/devis/exportGroupOfDevisIntoFacture',
type: 'POST',
contentType: 'application/json',
data: JSON.stringify(invoiceGroupQuotePayload)
}).done(function (response) {
var fileNames = response;
if(fileNames != null){
let fileNamesArray = JSON.parse(fileNames);
if(fileNamesArray.length > 0){
fileNamesArray.forEach((filename) => {
showSuccess('Sauvegardé dans' + filename);
})
$('#groupDevisFacturationModal').hide();
}
else{
showError(t('gestion', "Les données pour sauvegarde sont vides"));
}
}
else{
showError(t('gestion', "Les données pour sauvegarde sont vides"));
}
}).fail(function (response, code) {
showError(t('gestion', "Erreur dans la génération de facture multiple"));
}).always(function () {
hideLoader();
});
});

View File

@ -126,7 +126,7 @@ document.body.addEventListener('click', e => {
console.log(url);
window.location.replace(url);
} else if("apercusDevis" === e.target.id) {
window.location.replace(generateUrl(`/apps/gestion/devis/apercus?cli=&annee=${(new Date()).getFullYear()}&mois=${(new Date()).getMonth()}`));
window.location.replace(generateUrl(`/apps/gestion/devis/apercus?cli=&annee=${(new Date()).getFullYear()}&mois=${(new Date()).getMonth()}&filterType=group`));
} else if("newArticle" === e.target.id) {
Article.newArticle(new DataTable('.tabledt'));
} else if("newDefunt" == e.target.id) {

View File

@ -3,143 +3,199 @@
<form method="get" class="d-flex flex-row align-items-center">
<select name="cli" id="clientselector">
<?php
foreach ($_['clients'] as $key => $client) {
?>
<option <?php if(strcmp($_GET['cli'],$client->id)==0) echo 'selected' ?> value='<?php echo $client->id; ?>'><?php echo html_entity_decode($client->prenom).' '.html_entity_decode($client->nom); ?></option>
<?php
foreach ($_['clients'] as $key => $client) {
?>
<option <?php
if ($_GET['cli'] == $client->id && $_GET['filterType'] == $client->client_type) {
echo 'selected';
}
?> value='<?php echo $client->id; ?>' data-type='<?php echo $client->client_type ?>'>
<?php echo strtoupper(html_entity_decode($client->nom)); ?>
</option>
<?php
}
?>
</select>&nbsp;&nbsp;
<select name="annee" id="yearselector">
<option value="-1" <?php if ((int)$_GET['annee'] == -1) echo 'selected' ?>>Toutes les années</option>
<?php
$currentYear = date('Y');
for ($year = $currentYear; $year >= $currentYear - 10; $year--) {
echo '<option value="' . $year . '"';
if ((int)$_GET['annee'] == $year) echo ' selected';
echo '>' . $year . '</option>';
}
<option value="-1" <?php if ((int) $_GET['annee'] == -1)
echo 'selected' ?>>Toutes les années</option>
<?php
$currentYear = date('Y');
for ($year = $currentYear; $year >= $currentYear - 10; $year--) {
echo '<option value="' . $year . '" ' . ((int) $_GET['annee'] == $year ? 'selected' : '') . '>' . $year . '</option>';
}
?>
</select>&nbsp;&nbsp;
<select name="mois" id="monthselector">
<option value="0" <?php if((int) $_GET['mois'] == 0) echo 'selected' ?>>Tous les mois</option>
<option value="1" <?php if((int) $_GET['mois'] == 1) echo 'selected' ?>>Janvier</option>
<option value="2" <?php if((int) $_GET['mois'] == 2) echo 'selected' ?>>Fevrier</option>
<option value="3" <?php if((int) $_GET['mois'] == 3) echo 'selected' ?>>Mars</option>
<option value="4" <?php if((int) $_GET['mois'] == 4) echo 'selected' ?>>Avril</option>
<option value="5" <?php if((int) $_GET['mois'] == 5) echo 'selected' ?>>Mai</option>
<option value="6" <?php if((int) $_GET['mois'] == 6) echo 'selected' ?>>Juin</option>
<option value="7" <?php if((int) $_GET['mois'] == 7) echo 'selected' ?>>Juillet</option>
<option value="8" <?php if((int) $_GET['mois'] == 8) echo 'selected' ?>>Août</option>
<option value="9" <?php if((int) $_GET['mois'] == 9) echo 'selected' ?>>Septembre</option>
<option value="10" <?php if((int) $_GET['mois'] == 10) echo 'selected' ?>>Octobre</option>
<option value="11" <?php if((int) $_GET['mois'] == 11) echo 'selected' ?>>Novembre</option>
<option value="12" <?php if((int) $_GET['mois'] == 12) echo 'selected' ?>>Decembre</option>
</select>&nbsp;&nbsp;
<input type="submit" value="Filtrer"/>
<option value="0" <?php if ((int) $_GET['mois'] == 0)
echo 'selected' ?>>Tous les mois</option>
<option value="1" <?php if ((int) $_GET['mois'] == 1)
echo 'selected' ?>>Janvier</option>
<option value="2" <?php if ((int) $_GET['mois'] == 2)
echo 'selected' ?>>Fevrier</option>
<option value="3" <?php if ((int) $_GET['mois'] == 3)
echo 'selected' ?>>Mars</option>
<option value="4" <?php if ((int) $_GET['mois'] == 4)
echo 'selected' ?>>Avril</option>
<option value="5" <?php if ((int) $_GET['mois'] == 5)
echo 'selected' ?>>Mai</option>
<option value="6" <?php if ((int) $_GET['mois'] == 6)
echo 'selected' ?>>Juin</option>
<option value="7" <?php if ((int) $_GET['mois'] == 7)
echo 'selected' ?>>Juillet</option>
<option value="8" <?php if ((int) $_GET['mois'] == 8)
echo 'selected' ?>>Août</option>
<option value="9" <?php if ((int) $_GET['mois'] == 9)
echo 'selected' ?>>Septembre</option>
<option value="10" <?php if ((int) $_GET['mois'] == 10)
echo 'selected' ?>>Octobre</option>
<option value="11" <?php if ((int) $_GET['mois'] == 11)
echo 'selected' ?>>Novembre</option>
<option value="12" <?php if ((int) $_GET['mois'] == 12)
echo 'selected' ?>>Decembre</option>
</select>&nbsp;&nbsp;
<input type="hidden" name="filterType" id="filterType"
value="<?php echo ($_GET['filterType'] ?? 'group'); ?>">
<input type="submit" value="Filtrer" />
</form>
<div class="d-flex flex-row">
<?php
$clients = $_['clients'];
if($_SERVER['REQUEST_METHOD'] == 'GET') {
$devis = array_filter($_['devis'], function($d) {
if($d->cid){
$datesplit = explode("-", $d->date);
$year = (int) $datesplit[0];
$month = (int) $datesplit[1];
$checkClient = false;
if(strcmp($_GET['cli'], '')==0){
$checkClient = $_['clients'][0]->id == $d->cid;
} else {
$checkClient = ((int) $_GET['cli']) == $d->cid;
}
$checkYear = ((int) ($_GET['annee']) == -1)?(true):($year==((int) $_GET['annee']));
$checkMounth = (((int) $_GET['mois']) == 0)? (true): ($month==((int) $_GET['mois']));
return $checkClient && $checkYear && $checkMounth;
$clients = $_['clients'];
if ($_SERVER['REQUEST_METHOD'] == 'GET') {
$devis = array_filter($_['devis'], function ($currentDevis) {
if ($currentDevis->cid) {
$datesplit = explode("-", $currentDevis->date);
$year = (int) $datesplit[0];
$month = (int) $datesplit[1];
$checkClient = false;
$filterType = "group";
if (array_key_exists('filterType', $_GET) && $_GET['filterType'] == 'client') {
$filterType = "client";
}
return false;
});
if(strcmp($_GET['cli'], '')!=0 && sizeof($devis)>0) {
?>
<button class="btn btn-secondary" type="button" id="exportMultipleDevisToPdf"><?php p($l->t('Save in Nextcloud'));?></button>
<?php
$clientIsNotSelected = strcmp($_GET['cli'], '') == 0;
if ($clientIsNotSelected) {
if ($filterType == "group") {
$checkClient = $_['clients'][0]->fk_client_group_facturation_id == $currentDevis->cid;
} else {
$checkClient = $_['clients'][0]->id == $currentDevis->cid;
}
} else {
if ($filterType == "group") {
$checkClient = $currentDevis->fk_client_group_facturation_id == $_GET['cli'];
} else {
$checkClient = $currentDevis->cid == $_GET['cli'];
}
}
$checkYear = ((int) ($_GET['annee']) == -1) ? (true) : ($year == ((int) $_GET['annee']));
$checkMounth = (((int) $_GET['mois']) == 0) ? (true) : ($month == ((int) $_GET['mois']));
return $checkClient && $checkYear && $checkMounth;
}
return false;
});
if (strcmp($_GET['cli'], '') != 0 && sizeof($devis) > 0) {
?>
<button class="btn btn-secondary" type="button"
id="exportMultipleDevisToPdf"><?php p($l->t('Save in Nextcloud')); ?></button>
<button class="btn btn-secondary" type="button" id="showGroupDevisFacturationModal" data-toggle="modal"
data-target="#groupDevisFacturationModal">
Facturer
</button>
<?php
}
}
?>
</div>
</div>
<hr>
<div id="gestion-canvas" class="canvas_div_pdf">
<?php
if($_SERVER['REQUEST_METHOD'] == 'GET' && strcmp($_GET['cli'], '')!=0) {
if(sizeof($devis)==0) echo "Aucun devis trouvé.";
};
foreach ($devis as $key => $d) {
?>
if ($_SERVER['REQUEST_METHOD'] == 'GET' && strcmp($_GET['cli'], '') != 0) {
if (sizeof($devis) == 0)
echo "Aucun devis trouvé.";
}
;
foreach ($devis as $key => $d) {
?>
<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>
<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>
</h2>
<hr/>
<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>
<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>
</h2>
<hr />
<div class="row">
<div class="col-5 h-100 m-0" style="min-height:250px;">
<?php $res = json_decode($_['configuration'])[0]; ?>
<h5 class="p-3 m-0 text-dark text-center border border-2 border-dark"><?php p($l->t('FROM'));?> <?php echo $res->entreprise; ?></h5>
<p class="p-3 m-0 h-auto text-center text-dark text-center border border-top-0 border-2 border-dark">
<h5 class="p-3 m-0 text-dark text-center border border-2 border-dark"><?php p($l->t('FROM')); ?>
<?php echo $res->entreprise; ?></h5>
<p
class="p-3 m-0 h-auto text-center text-dark text-center border border-top-0 border-2 border-dark">
<?php echo $res->prenom . " " . $res->nom; ?><br />
<?php echo $res->adresse; ?><br />
<?php echo $res->mail; ?><br />
<?php echo $res->telephone; ?><br/>
<?php echo $res->telephone; ?><br />
<span id="nothing"></span><br />
</p>
</div>
<div class="col-2 h-100 m-0" style="min-height:250px;">
<?php
if(isset($_['logo']) && $_['logo'] !== "nothing"){
echo "<center><a><img alt='".$l->t('Company logo')."' class=\"img-fluid\" src=\"data:image/png;base64, ".$_['logo']."\"/></a></center>";
}else{
echo "<span style='font-size:12px' id='Company-logo' data-html2canvas-ignore><b><center>".$l->t('You can add your company logo here.')."</center></b><br/><i>".$l->t('To add a logo, drop the logo.png file in ".gestion" folder at the root of your Nextcloud Files app. Remember to set "Show hidden files".')."</i><br/><br/><center>".$l->t('This message will not appear on generated PDF.')."</center></span>";
}
if (isset($_['logo']) && $_['logo'] !== "nothing") {
echo "<center><a><img alt='" . $l->t('Company logo') . "' class=\"img-fluid\" src=\"data:image/png;base64, " . $_['logo'] . "\"/></a></center>";
} else {
echo "<span style='font-size:12px' id='Company-logo' data-html2canvas-ignore><b><center>" . $l->t('You can add your company logo here.') . "</center></b><br/><i>" . $l->t('To add a logo, drop the logo.png file in ".gestion" folder at the root of your Nextcloud Files app. Remember to set "Show hidden files".') . "</i><br/><br/><center>" . $l->t('This message will not appear on generated PDF.') . "</center></span>";
}
?>
</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>
<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 />
<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 class="pdf" style="display: none"><?php echo $d->entreprise."_".$d->id."_v".$d->version?></span>
</p>
<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>
<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 />
<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 class="pdf"
style="display: none"><?php echo $d->entreprise . "_" . $d->id . "_v" . $d->version ?></span>
</p>
</div>
</div>
<div class="row">
<div class="col col-md">
<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>
<hr/>
<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>
<hr />
</div>
</div>
<div class="row">
<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>
<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>
</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>
<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 />
</div>
</div>
@ -147,12 +203,12 @@
<table id="produits" data-type="facture" class="table table-striped">
<thead>
<tr>
<th><?php p($l->t('Reference'));?></th>
<th><?php p($l->t('Designation'));?></th>
<th><?php p($l->t('Comment'));?></th>
<th><?php p($l->t('Quantity'));?></th>
<th><?php p($l->t('Unit price without VAT'));?></th>
<th><?php p($l->t('Total without VAT'));?></th>
<th><?php p($l->t('Reference')); ?></th>
<th><?php p($l->t('Designation')); ?></th>
<th><?php p($l->t('Comment')); ?></th>
<th><?php p($l->t('Quantity')); ?></th>
<th><?php p($l->t('Unit price without VAT')); ?></th>
<th><?php p($l->t('Total without VAT')); ?></th>
</tr>
</thead>
<tbody>
@ -162,8 +218,9 @@
<td><?php echo $produit->description ?></td>
<td><?php echo $produit->comment ?></td>
<td><?php echo $produit->quantite ?></td>
<td>&euro;<?php echo number_format($produit->prix_unitaire, 2) ?></td>
<td>&euro;<?php echo number_format($produit->prix_unitaire*$produit->quantite, 2) ?></td>
<td>&euro;<?php echo number_format($produit->prix_unitaire, 2) ?></td>
<td>&euro;<?php echo number_format($produit->prix_unitaire * $produit->quantite, 2) ?>
</td>
</tr>
<?php } ?>
</tbody>
@ -173,23 +230,23 @@
<table id="totaldevis" class="table table-striped table-xl">
<thead class="bg-dark text-white">
<tr>
<th class="text-center"><?php p($l->t('Total without VAT'));?></th>
<th class="text-center"><?php p($l->t('VAT Rate'));?></th>
<th class="text-center"><?php p($l->t('Total VAT'));?></th>
<th class="text-center"><?php p($l->t('Total Price'));?></th>
<th class="text-center"><?php p($l->t('Total without VAT')); ?></th>
<th class="text-center"><?php p($l->t('VAT Rate')); ?></th>
<th class="text-center"><?php p($l->t('Total VAT')); ?></th>
<th class="text-center"><?php p($l->t('Total Price')); ?></th>
</tr>
</thead>
<tbody>
<?php
$totalhtc = 0;
$tva = json_decode($_['configuration'])[0]->tva_default;
$totalttc = 0;
$totalprice = 0;
foreach ($d->dproduits as $key => $produit) {
$totalhtc = $totalhtc + ($produit->quantite*$produit->prix_unitaire);
}
$totalttc = ($totalhtc * $tva)/100;
$totalprice = $totalhtc + $totalttc;
<?php
$totalhtc = 0;
$tva = json_decode($_['configuration'])[0]->tva_default;
$totalttc = 0;
$totalprice = 0;
foreach ($d->dproduits as $key => $produit) {
$totalhtc = $totalhtc + ($produit->quantite * $produit->prix_unitaire);
}
$totalttc = ($totalhtc * $tva) / 100;
$totalprice = $totalhtc + $totalttc;
?>
<tr>
<td>&euro;<?php echo number_format($totalhtc, 2) ?></td>
@ -203,19 +260,36 @@
</div>
<div class="d-flex flex-column w-100">
<div class="col m-0 pb-0 alert alert-info text-center">
<p><span id="mentions_default"><?php p($l->t('Please set in global configuration'));?></span></p>
<p><span id="mentions_default"><?php p($l->t('Please set in global configuration')); ?></span></p>
</div>
<hr />
<div class="col m-0 pb-0 alert alert-info text-center">
<p><?php echo $res->entreprise; ?><br /><?php echo $res->adresse; ?><br /><?php echo $res->legal_one; ?><br/><?php echo $res->legal_two; ?></p>
<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>
<hr data-html2canvas-ignore>
<hr data-html2canvas-ignore>
<hr data-html2canvas-ignore>
<?php
}
<?php
}
?>
</div>
<div class="modal" id="groupDevisFacturationModal" tabindex="-1">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalLabel">Choisir la date de facturation souhaitée</h5>
</div>
<div class="modal-body">
<input type="date" id="facturationDate">
</div>
<div class="modal-footer">
<button id="closeGroupDevisModal" type="button" class="btn btn-secondary">Annuler</button>
<button id="invoiceGroupQuote" type="button" class="btn btn-primary">Facturer</button>
</div>
</div>
</div>
</div>
</div>