Skip to content
This repository has been archived by the owner on Mar 26, 2023. It is now read-only.

Version 0.07 #55

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions DataTables/lang/FR.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"emptyTable": "Aucune donnée disponible dans le tableau",
"emptyTable": "Aucune donnée disponible pour ce rapport",
"lengthMenu": "Afficher _MENU_ éléments",
"loadingRecords": "Chargement...",
"processing": "Traitement...",
Expand All @@ -8,7 +8,7 @@
"first": "Premier",
"last": "Dernier",
"previous": "Précédent",
"next": "Suiv"
"next": "Suivant"
},
"aria": {
"sortAscending": ": activer pour trier la colonne par ordre croissant",
Expand Down
162 changes: 128 additions & 34 deletions js/glutax.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
var modalPurchReceipt;
var temporaryObjectStore;

$(document).ready(function(){
modalPurchReceipt = new bootstrap.Modal(document.getElementById('purchaseReceipt'), {
Expand All @@ -7,7 +8,6 @@ $(document).ready(function(){
loadPage();
});


// Click on the Website title in the Top NavBar
$("#glutaxTitle").on("click", function(){
loadPage();
Expand Down Expand Up @@ -203,6 +203,68 @@ function wrapForm(formID){
}
}

/**
* Send a GET request to the server
* @param {String} queryType Type of query: SKU.
* @param {String} queryData
*/
function queryDB(queryType, queryData, queryCallback){
var engineURL = "php/gtQuery.php";

var url = engineURL + "?type=" + queryType + "&" + queryData;
console.log("Query to: " + url);

var http = new XMLHttpRequest();
http.open("GET", url, true);

http.onreadystatechange = function(){
if( http.readyState === 4 && http.status === 200){
window[queryCallback](http.responseText);
}
}
http.send();
}

/**
*
* @param {String} sku SKU to validate
* @returns SKU if it can be used, or empty if SKU is already used.
*/
function validateSKU(obj){
var wip = '';
temporaryObjectStore = obj;
var sku = obj.value + '';

if( sku == '' ){
temporaryObjectStore.classList.remove("is-invalid");
document.getElementById(temporaryObjectStore.id + "-invalid").innerHTML = "";
return false;
}

wip = sku.split(' ').join('');
wip = wip.toUpperCase();

var db = "";
var queryString = "sku=" + wip + "&p=" + $("#id").val();
db = queryDB('SKU', queryString, 'validateSKU_cb');
}


function validateSKU_cb(data){
console.log('My response = ' + data);
var resp = JSON.parse(data);

if( resp.result != 'ok' ){
temporaryObjectStore.classList.add("is-invalid");
document.getElementById(temporaryObjectStore.id + "-invalid").innerHTML = resp.msg;
$("#Save").addClass("disabled");
} else {
temporaryObjectStore.classList.remove("is-invalid");
document.getElementById(temporaryObjectStore.id + "-invalid").innerHTML = "";
$("#Save").removeClass("disabled");
}
}

/**
* Display a message as a toast.
* @param {String} message Message to show in the Toast.
Expand All @@ -218,6 +280,10 @@ function toast(message){
toastList.forEach(toast => toast.show());
}

/**
* Display a message in a modal, the user will have to click OK.
* @param {String} message Message to show in the Modal.
*/
function tell(message){

document.getElementById('tellModalText').innerHTML = message;
Expand All @@ -227,43 +293,71 @@ function tell(message){
}


function loadReport(report){
$("#myBox").load('php/rpt-frame.php?r=' + report, function(){
function loadReport(report, defn = ''){
$("#myBox").load('php/rpt-frame.php?r=' + report + defn, function(){

var langPack = ""
$('#glutaxReport').DataTable({
"processing": true,
"language":{
"url": "DataTables/lang/" + myLang + ".json"
// Basic set of options
var dataOptions = {
"processing": true,
"language":{
"url": "DataTables/lang/" + myLang + ".json"
},
"responsive": true,
"pageLength": myReportLines,
"sAjaxSource":"php/rpt-data.php?r=" + report + defn,
"dom":"Bfrtip",
"buttons":[
{
extend: 'collection',
text: 'Options',
buttons: [
'colvis',
'colvisRestore',
'pageLength'
]
},
"pageLength": myReportLines,
"sAjaxSource":"php/rpt-data.php?r=" + report,
"dom":"Bfrtip",
"buttons":[
{
extend: 'collection',
text: 'Options',
buttons: [
'colvis',
'colvisRestore',
'pageLength'
]
},
{
extend: 'collection',
text: 'Exporter',
buttons: [
'copy',
'excel',
'csv',
'pdf',
'print'
]
}
]
});
{
extend: 'collection',
text: 'Exporter',
buttons: [
'copy',
'excel',
'csv',
'pdf',
'print'
]
}
]
};

// Create the column Indices to hide according to the Report Type.
var myCols;
if( defn.search("summ=y") > 0 || report.search("summary") > 0 ){
// Summary
myCols = [
{"visible": false, "targets": [0], "searchable": false}
];
}else{
// Details
myCols = [
{"visible": false, "targets": [2,6,7,8]},
{"visible": false, "targets": [0], "searchable": false}
];
}

// Inject "columnDefs" option
if( myCols !== '' ){
dataOptions.columnDefs = myCols;
}

// Send Options
var myTable = $('#glutaxReport').DataTable(dataOptions);

// Add On Click
myTable.on('click', 'tr', function(){
var pID = myTable.row( this ).data()[0];
purchReceipt( pID );
});

});
}
18 changes: 17 additions & 1 deletion page.php
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@
<?= _NAVBAR_REPORT ?>
</a>
<div class="dropdown-menu dropdown-menu-right animate slideIn" aria-labelledby="navbarReports">
<a class="dropdown-item" href="#" onclick="loadPage('browser', '');"><?= _REPORT_BROWSER ?></a>
<div class="dropdown-divider"></div>
<a class="dropdown-item navReport" href="#" data-report="purch-all-summary"><?= _REPORT_PURCH_ALL_SUMMARY ?></a>
<a class="dropdown-item navReport" href="#" data-report="purch-all-details"><?= _REPORT_PURCH_ALL_DETAILS ?></a>
</div>
Expand Down Expand Up @@ -121,10 +123,24 @@
</a>
<div class="dropdown-menu dropdown-menu-right animate slideIn" aria-labelledby="navbarOptions">
<a class="dropdown-item" href="#" onclick="loadPage('settings','');"><?= _OPTION_SETTING ?></a>
<?php
if( $_SESSION['accountID'] == 1 ){
echo '<a class="dropdown-item" href="#" onclick="loadPage(\'system\',\'\');">' . _OPTION_SYSTEM . '</a>';
}
?>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#"><?= _OPTION_LOGOUT ?></a>
</div>
</li>
<!-- Help Menu -->
<li class="nav-item dropdown">
<a class="nav-link dropdown-toggle" href="#" id="navbarHelp" role="button" data-bs-toggle="dropdown" aria-haspopup="true" aria-expanded="false">
<?= _NAVBAR_HELP ?>
</a>
<div class="dropdown-menu dropdown-menu-right animate slideIn" aria-labelledby="navbarHelp">
<a class="dropdown-item" href="#" onclick="loadPage('help-calc','');"><?= _HELP_CALC ?></a>
</div>
</li>
</ul>
</div>
</div>
Expand Down Expand Up @@ -174,7 +190,7 @@
<div class="modal-content p-3" id="purchaseReceiptBody">
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" onclick="loadPage('purch', 'p=' + myPurchaseID);"><?= _BUTTON_UPDATE ?></button>
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal" onclick="loadPage('purch', 'p=' + myPurchaseID);"><?= _BUTTON_EXPAND ?></button>
<button type="button" class="btn btn-primary" data-bs-dismiss="modal"><?= _BUTTON_CLOSE ?></button>
</div>
</div>
Expand Down
11 changes: 11 additions & 0 deletions pages/_base
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
# Global Include.
include('../php/gtInclude.php');
?>
<!-- Header -->
<h1 class="mt-5 text-white font-weight-light"><?php echo $pageHeader; ?> </h1>
<p class="lead text-white-50"><?php echo $pageSubHeader; ?></p>
<hr>
<div class="bg-light p-3 rounded shadow-sm">

</div>
46 changes: 46 additions & 0 deletions pages/browser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php
# Global Include.
include('../php/gtInclude.php');
?>
<!-- Header -->
<h1 class="mt-5 text-white font-weight-light"><?= _REPORT_BROWSER ?> </h1>
<p class="lead text-white-50"><?= _REPORT_BROWSER_SEL_HELP ?></p>
<hr>
<div class="bg-light p-3 rounded shadow-sm">
<h3><?= _REPORT_BROWSER_SEL_TITLE ?></h3>
<div class="row justify-content-around">
<div class="col-md-4">
<label for="txtStartDate" class="form-label text-start"><?= _REPORT_BROWSER_SEL_START ?></label>
<input type="date" class="form-control" id="txtStartDate" value="<?php echo date('Y-m-01'); ?>">
<label for="txtEndDate" class="form-label text-start"><?= _REPORT_BROWSER_SEL_END ?></label>
<input type="date" class="form-control" id="txtEndDate" value="<?php echo date('Y-m-t'); ?>">
</div>
<div class="col-md-3">
<div class="form-check form-switch">
<input class="form-check-input" type="checkbox" id="chkSummarize">
<label class="form-check-label" for="chkSummarize">Purchase Summary</label>
</div>
</div>
</div>

<button type="button" class="btn btn-primary" onclick="buildQueryString();"><?= _REPORT_BROWSER_SEL_GO ?></button>

</div>

<script>

function buildQueryString(){
var startDate = $("#txtStartDate").val();
var endDate = $("#txtEndDate").val();
var summary = "n";
if( document.getElementById("chkSummarize").checked == true ){
summary = "y";
}

var defn = "&start=" + startDate + "&end=" + endDate + "&summ=" + summary;

var rpt = "custom";
loadReport(rpt, defn);
}

</script>
35 changes: 35 additions & 0 deletions pages/help-calc.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
<?php
# Global Include.
include('../php/gtInclude.php');
?>
<!-- Header -->
<h1 class="mt-5 text-white font-weight-light"><?php echo _HELP_CALC; ?> </h1>
<p class="lead text-white-50"><?php echo _HELP_CALC_HELP; ?></p>
<hr>
<div class="bg-light p-3 rounded shadow-sm text-start">
<?php
if( $_LANG == "FR" ){
echo "<p>Chaque produit sans gluten est compar&eacute; &agrave; un &eacute;quivalent avec gluten. Chacun des produits est ramen&eacute; &agrave; un prix par unit&eacute;, ";
echo "par exemple, un prix par gramme. Ce premier calcul permet d'obtenir un prix pour une m&ecirc;me quantit&eacute;.</p><p>La ";
echo "diff&eacute;rence entre les deux prix normalis&eacute;s est calcul&eacute;e, puis, multipli&eacute;e par la quantit&eacute; du produit sans gluten.</p>";
echo "<p>Cette m&eacute;thode permet de calculer la diff&eacute;rence pay&eacute;e pour le produit sans gluten, &agrave; quantit&eacute; et poids &eacute;gal.</p>";
echo "<h3>Exemple</h3>";
echo "<dl class='row'><dt class='col-sm-2'>Sans gluten</dt><dd class='col-sm-10'>Biscuits sandwichs &agrave; l'&eacute;rable Great Value sans gluten<br>3,97 $<br>325 g<br><strong>3,97 $ &divide; (325 g. &divide; 100 g.) = <u>1,22 $</u> par 100 grammes</strong>.</dd></dt>";
echo "<dt class='col-sm-2'>Avec gluten</dt><dd class='col-sm-10'>Biscuits Tradition de Leclerc en forme de feuille d'&eacute;rable<br>2,67 $<br>350 g<br><strong>2,67 $ &divide; (350 g. &divide; 100 g.) = <u>0,76 $</u> par 100 grammes</strong>.</dd></dt></dl>";
echo "Mon produit co&ucirc;te 0,46$ de plus par 100 grammes (1,22$ - 0,76$ = 0,46$).<br>";
echo "Mon produit est un format de 325 grammes: 325 g. &divide; 100 g. = 3,25 &times; 0,46$ = 1,495 $ &asymp; <u>1,49$</u> pay&eacute; en extra.";
}else{
echo "<p>Each gluten-free product is compared with a with-gluten product. Each product is reduced to a common unit price, e.g. a price per gram. ";
echo "This first step allow us to get the price of each products on a same basis.</p><p>The ";
echo "discrepancy between both normalized prices is calculated, and then, extended to the gluten-free product quantity.</p>";
echo "<p>This method return the accurate amount paid in extra for the gluten-free alternative, for the same quantity and weigth.</p>";
echo "<h3>Example</h3>";
echo "<dl class='row'><dt class='col-sm-2'>Gluten-free</dt><dd class='col-sm-10'>Great Value Gluten Free Maple Cream Sandwich Cookies<br>$3.97<br>325 g<br><strong>$3.97 &divide; (325 g. &divide; 100 g.) = <u>$1.22</u> per 100 grams</strong>.</dd></dt>";
echo "<dt class='col-sm-2'>With gluten</dt><dd class='col-sm-10'>Tradition Maple Leaf Cookies<br>$2.67<br>350 g<br><strong>$2.67 &divide; (350 g. &divide; 100 g.) = <u>$0.76</u> per 100 grams</strong>.</dd></dt></dl>";
echo "My product cost $0.46 more per 100 grams ($1.22 - $0.76 = $0.46).<br>";
echo "My product is a format of 325 grams: 325 g. &divide; 100 g. = 3.25 &times; $0.46 = $1.495 &asymp; <u>$1.49</u> paid in extra.";
}


?>
</div>
Loading