|
Nom du patient RDV |
Nom du patient Facturation |
10000, "sortfield" => "rowid"];
$listProduitsResult = CallAPI("GET", $apiKey, $apiUrl."products", $produitParam);
$listProduitsResult = json_decode($listProduitsResult, true);
if (isset($listProduitsResult["error"]) && $listProduitsResult["error"]["code"] >= "300") {
} else {
foreach ($listProduitsResult as $produit) {
//Afficher les produits et services
//echo html_entity_decode($produit["ref"], ENT_QUOTES);
}
}
} else {
}
//On récupère les ID dstincts des rdv pour un certain staff_id pour un certain mois de l'année
$nbre_clients =mysqli_query ($base,"SELECT DISTINCT(`customer_id`) FROM `wp_bookly_appointments`,`wp_bookly_customer_appointments`,`wp_bookly_customers`,`wp_bookly_services` WHERE `wp_bookly_customer_appointments`.`appointment_id`=`wp_bookly_appointments`.`id` AND `wp_bookly_customers`.`id`=`wp_bookly_customer_appointments`.`customer_id` AND `wp_bookly_services`.`id`=`wp_bookly_appointments`.`service_id` AND staff_id=".$_POST["staffid"]." AND MONTH(start_date) = ".$_POST["month"]." and YEAR(end_date) = ".$_POST["year"]."") or die('erreur de sql'.$sql.'
'.mysqli_error());
//On crée le tableau qui sera posté
$newInvoice = [];
$nbre_facture=0; //= nombre client aussi
$nbre_ligne=0;
// On crée la variable pour les lignes de factures
$newInvoiceLine = [];
//if (isset($_POST["skip"]["0"])) {echo ("Set : ".$_POST["skip"]["0"]);} else {echo ("Not Set");}
//if (isset($_POST["skip"]["1"])) {echo ("Set : ".$_POST["skip"]["1"]);} else {echo ("Not Set");}
//On récupère les rdv pour un certain staff_id pour un certain mois de l'année
$all_appointment = mysqli_query ($base,"SELECT * FROM (SELECT `wp_bookly_appointments`.`id`, `wp_bookly_appointments`.`staff_id`, `wp_bookly_appointments`.`service_id`,`wp_bookly_services`.`title`, `start_date`, `customer_id` , `full_name`,`first_name`,`last_name` FROM `wp_bookly_appointments`,`wp_bookly_customer_appointments`,`wp_bookly_customers`,`wp_bookly_services` WHERE `wp_bookly_customer_appointments`.`appointment_id`=`wp_bookly_appointments`.`id` AND `wp_bookly_customers`.`id`=`wp_bookly_customer_appointments`.`customer_id` AND `wp_bookly_services`.`id`=`wp_bookly_appointments`.`service_id` AND staff_id=".$_POST["staffid"]." AND MONTH(start_date) = ".$_POST["month"]." and YEAR(end_date) = ".$_POST["year"].") A
INNER JOIN
(SELECT `customer_id`, count(*) as nbrerdv FROM `wp_bookly_appointments`,`wp_bookly_customer_appointments`,`wp_bookly_customers`,`wp_bookly_services` WHERE `wp_bookly_customer_appointments`.`appointment_id`=`wp_bookly_appointments`.`id` AND `wp_bookly_customers`.`id`=`wp_bookly_customer_appointments`.`customer_id` AND `wp_bookly_services`.`id`=`wp_bookly_appointments`.`service_id` AND staff_id=".$_POST["staffid"]." AND MONTH(start_date) = ".$_POST["month"]." and YEAR(end_date) = ".$_POST["year"]." GROUP BY `customer_id` ORDER BY `wp_bookly_customers`.`full_name` ASC) B
ON A.`customer_id` = B.`customer_id` ORDER BY `full_name` ASC, `start_date`") or die('erreur de sql'.$sql.'
'.mysqli_error());
$row_cnt = mysqli_num_rows($all_appointment);
while ($all_appointment_fetch = mysqli_fetch_array($all_appointment)) // On boucle pour afficher toutes les données et on met toutes données dans un tableau
{
if ($clientprecedentid != $all_appointment_fetch['customer_id']) {
$i=0;
$searchClientResult = CallAPI("GET", $apiKey, $apiUrl."thirdparties?", array(
"sortfield" => "t.rowid",
"sortorder" => "ASC",
"limit" => "1",
"mode" => "1",
"sqlfilters" => "(t.nom:like:'%".utf8_encode($all_appointment_fetch['full_name'])."%')"
));
$searchClientResult = json_decode($searchClientResult, true);
if (isset($_POST["skip"][$nbre_facture]) && $_POST["skip"][$nbre_facture]=="1") {$checked="disabled";}
else if (isset($_POST["skip"][$nbre_facture]) && $_POST["skip"][$nbre_facture]=="0") {$checked="checked disabled";} else {$checked="checked";}
echo ("
|
".utf8_encode($all_appointment_fetch['full_name'])." |
");
if (isset($searchClientResult["error"]) && $searchClientResult["error"]["code"] = "404") {
// il y a eu une erreur
echo "Patient introuvable";
$socid = NULL;
$stop=1;
$ConsrecuResult["array_options"]["options_consrecu"] = NULL;
$client_agenda =mysqli_query ($base,"SELECT * FROM `wp_bookly_customers` WHERE `id`=\"".$all_appointment_fetch['customer_id']."\"") or die('erreur de sql'.$sql.' '.mysqli_error());
$client_agenda = mysqli_fetch_assoc($client_agenda);
$newClient = [
"name" => utf8_encode($client_agenda["full_name"]),
"email" => utf8_encode($client_agenda["email"]),
"address" => utf8_encode($client_agenda["street"])." ".utf8_encode($client_agenda["street_number"]),
"town" => utf8_encode($client_agenda["city"]),
"zip" => utf8_encode($client_agenda["postcode"]),
"client" => "1",
"code_client" => "-1"
];
//$newClientResult = CallAPI("POST", $apiKey, $apiUrl."thirdparties", json_encode($newClient));
//$newClientResult = json_decode($newClientResult, true);
//$clientDoliId = $newClientResult;
//On affiche le tableau avec la requête de creation de client
//echo ''; print_r($newClient); echo ' ';
//On fait passer le PHP array via le form dans un input hidden
$clientArray = base64_encode(serialize($newClient));
echo ("");
echo ('');
echo ('
');
} else {
foreach ($searchClientResult as $clients) {
echo( html_entity_decode($clients["name"], ENT_QUOTES));
$socid = html_entity_decode($clients["ref"], ENT_QUOTES);
// On récupère la consultation récurrente accordée
$ConsrecuResult = CallAPI("GET", $apiKey, $apiUrl."thirdparties/".$socid, array());
$ConsrecuResult = json_decode($ConsrecuResult, true);
}
}
echo (" |
");
if (isset($_POST["skip"][$nbre_facture])) {$skip=$_POST["skip"][$nbre_facture];} else {$skip="0";}
$newInvoice[] = [
"socid" => $socid,
"lines" => NULL,
"note_private" => "Facture importée depuis l'agenda Libellules",
"model_pdf" => "generic_invoice_odt:/home/libellules/public_html/gestion/valentine/documents/doctemplates/invoices/modele_libellules_2019.odt",
"mode_reglement_code" => "VIR",
"fk_account" => $_POST["bank"],
"skip" => "$skip"
];
}
if (isset($_POST["skip"][$nbre_facture]) && $_POST["skip"][$nbre_facture]=="1") {echo(""); } else {
echo("
");
}
echo("| ".utf8_encode($all_appointment_fetch['title'])." le ".utf8_encode($all_appointment_fetch['start_date'])." | ");
if (!isset($_POST['product'])) {
echo ("");
echo ("Quantité : "false", "includeparentid" => "false"];
$listProduitsResult = CallAPI("GET", $apiKey, $apiUrl."products/".$product[$nbre_ligne], $produitParam);
// On réutilise la variable $produit pour que la suite fonctionne
$produit = json_decode($listProduitsResult, true);
if (isset($produit["error"]) && $produit["error"]["code"] >= "300") {
//Imprimer les Array créés
echo ''; print_r($produit); echo ' ';
} else {
//Afficher les produits et services
//echo html_entity_decode($produit["ref"], ENT_QUOTES);
//On affiche le JSON de la ligne
//echo ''; print_r($produit); echo ' ';
}
echo (html_entity_decode($produit["ref"], ENT_QUOTES)." - ".html_entity_decode($produit["label"], ENT_QUOTES)." - ".number_format(html_entity_decode($produit["price"], ENT_QUOTES),2)." € X ".$qty[$nbre_ligne]);
}
echo (" |
");
$i++;
$newInvoice[$nbre_facture]["lines"][] = [
"fk_product" => html_entity_decode($produit["id"], ENT_QUOTES),
"subprice" => number_format(html_entity_decode($produit["price"], ENT_QUOTES),2),
"qty" => $qty[$nbre_ligne],
"tva_tx" => "0",
"array_options" => [
"options_dateconsul" => strtotime(utf8_encode($all_appointment_fetch['start_date']))
]
];
if ($i == $all_appointment_fetch['nbrerdv'] ) {
//if (isset($_POST['product'])) {
//echo(" |
");
//}
//Imprimer les Array créés pour chaque ligne
//echo ''; print_r($newInvoice); echo '
';
// On réinitialise les lignes de facture pour la prochaine facture
//$newInvoiceLine = [];
//On augmente le nbre de facture de +1
$nbre_facture++;
}
$clientprecedentid = $all_appointment_fetch['customer_id'];
$nbre_ligne++;
// Calcul de l'état d'avancement du chargement
$nbre_boucle++;
$progress = $nbre_boucle / $row_cnt * 100;
// Affichage du loader avec suivi de chargement
echo '';
}
//On affiche le PHP Array final contenant toutes les factures
//echo ''; print_r($newInvoice); echo '
';
echo ("
");
//echo ($nbre_facture);
//echo ($nbre_ligne);
if (!isset($_POST['product'])) {
if (isset($stop)) {
echo ('