Skip to content

Commit

Permalink
Merge pull request #166 from globaldyne/v9.9
Browse files Browse the repository at this point in the history
V9.9
  • Loading branch information
globaldyne authored Apr 13, 2024
2 parents 297c704 + bd452e5 commit af7e343
Show file tree
Hide file tree
Showing 19 changed files with 721 additions and 165 deletions.
17 changes: 17 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,21 @@
# CHANGELOG
### Version 9.9
- Record replaced ingredients when finalising a formula in the generated PDF
- Increase toast duration for formula making to 10 seconds
- Make sure the correct ingredient's quantity is reset when reseting an ingredient in Formula make which is replaced
- Update bottle add modal
- Prevent illegal characters from a bottle name
- Fix json import for ingredients if values contains illegal chars
- Implement signaling for formula reload when its updated via the API
- Prevent negative value when updating Make Formula data via the API
- Add odor to the data sent to PV Scale
- Increase update interval check from PV Scale to 5s
- Added separate notes field for Formula Make
- When a formula is marked as completed it generates a document in formula attachments
- Added API key to the data sent to PV Scale
- Add material skip when making a formula
- Add advanced material replacement when making a formula

### Version 9.8
- Added phpMyAdmin definition in the docker compose
- Update general settings to use toast messages
Expand Down
2 changes: 1 addition & 1 deletion VERSION.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9.8
9.9
60 changes: 48 additions & 12 deletions api.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
if(apiCheckAuth($key, $conn) == true){
$response['status'] = "Success";
}else{
$response['status'] = "Failed";
$response['status'] = "Auth failed";
}
header('Content-Type: application/json; charset=utf-8');
echo json_encode($response);
Expand All @@ -44,7 +44,7 @@
$_REQUEST['do'] = strtolower(mysqli_real_escape_string($conn, $_REQUEST['do']));

if(apiCheckAuth($key, $conn) == false){
$response['status'] = "Failed";
$response['status'] = "Auth failed";
header('Content-Type: application/json; charset=utf-8');
echo json_encode($response);
return;
Expand Down Expand Up @@ -291,6 +291,26 @@

//CALLBACKS
if($_REQUEST['do'] == 'callback'){
//SKIP MATERIAL FROM MAKE FORMULA
if($_REQUEST['action'] == 'skipMaterial'){
$fid = mysqli_real_escape_string($conn, $_REQUEST['fid']);
$id = mysqli_real_escape_string($conn, $_REQUEST['id']);
$ingID = mysqli_real_escape_string($conn, $_REQUEST['ingId']);
$notes = mysqli_real_escape_string($conn, $_REQUEST['notes']) ?: "-";

if(mysqli_query($conn, "UPDATE makeFormula SET skip = '1', notes = '$notes' WHERE fid = '$fid' AND id = '$id'")){
$response['success'] = true;
$response['message'] = $_REQUEST['ing'].' skipped from the formulation';
file_put_contents($tmp_path.'reload_signal.txt', 'reload');
} else {
$response['success'] = false;
$response['message'] = 'Error skipping the ingredient';
}
header('Content-Type: application/json;');
echo json_encode($response);
return;
}

if( $_REQUEST['action'] == 'makeFormula'){

$fid = mysqli_real_escape_string($conn, $_REQUEST['fid']);
Expand All @@ -299,17 +319,26 @@
$qr = trim($_REQUEST['qr']);

if (empty($fid) || empty($id) || empty($ingID) || empty($qr)) {
$response['error'] = 'Missing required params';
$response['success'] = false;
$response['message'] = 'Missing required params';
echo json_encode($response);
return;
}

if(!is_numeric($_REQUEST['q'])){
$response['error'] = 'Invalid quantity value';
$response['success'] = false;
$response['message'] = 'Invalid quantity value';
echo json_encode($response);
return;
}


if((double)$_REQUEST['q'] == 0.00){
$response['success'] = false;
$response['message'] = 'Please add quantity';
echo json_encode($response);
return;
}

$q = trim($_REQUEST['q']);
$notes = mysqli_real_escape_string($conn, $_REQUEST['notes']);

Expand All @@ -322,18 +351,22 @@
$q = $getStock['stock'];
}
mysqli_query($conn, "UPDATE suppliers SET stock = stock - $q WHERE ingID = '$ingID' AND preferred = '1'");
$response['success'] .= "Stock deducted by ".$q.$settings['mUnit'];
$response['success'] = true;
$response['message'] = "Stock deducted by ".$q.$settings['mUnit'];
}

$q = trim($_REQUEST['q']);
if($qr == $q){
if(mysqli_query($conn, "UPDATE makeFormula SET toAdd = '0' WHERE fid = '$fid' AND id = '$id'")){
$response['success'] = $_REQUEST['ing'].' added';
$response = array("success" => true, "message" => "Ingredient added");
}
}else{
$sub_tot = $qr - $q;
//if ($sub_tot < 0) {
// $sub_tot += abs($sub_tot);
//}
if(mysqli_query($conn, "UPDATE makeFormula SET quantity='$sub_tot' WHERE fid = '$fid' AND id = '$id'")){
$response['success'] = 'Formula updated';
$response = array("success" => true, "message" => "Quantity updated ($q)");
}
}

Expand All @@ -344,16 +377,19 @@

if($qr < $q){
if(mysqli_query($conn, "UPDATE makeFormula SET overdose = '$q' WHERE fid = '$fid' AND id = '$id'")){
$response['success'] = $_REQUEST['ing'].' is overdosed, '.$q.' added';
$response['success'] = true;
$response['message'] = $_REQUEST['ing'].' is overdosed, '.$q.' added';
}
}

if(!mysqli_num_rows(mysqli_query($conn, "SELECT id FROM makeFormula WHERE fid = '$fid' AND toAdd = '1'"))){
$response['success'] = 'All materials added. You should mark formula as complete now';
$response['success'] = true;
$response['message'] = 'All materials added. You should mark formula as complete now';
}


echo json_encode($response);
file_put_contents($tmp_path.'reload_signal.txt', 'reload');
header('Content-Type: application/json;');
echo json_encode($response);
return;

}
Expand Down
6 changes: 5 additions & 1 deletion core/pending_formulas_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,12 @@
foreach ($rs as $rq) {
$gING = mysqli_fetch_array(mysqli_query($conn, "SELECT cas,odor FROM ingredients WHERE name = '".$rq['ingredient']."'"));
$inventory = mysqli_fetch_array(mysqli_query($conn, "SELECT stock,mUnit FROM suppliers WHERE ingID = '".$rq['ingredient_id']."' AND preferred = '1'"));
$repq = mysqli_fetch_array(mysqli_query($conn, "SELECT name FROM ingredients WHERE id = '".$rq['replacement_id']."'"));

$r['id'] = (int)$rq['id'];
$r['fid'] = (string)$rq['fid'];
$r['repID'] = (string)$rq['replacement_id'];
$r['repName'] = (string)$repq['name'];
$r['name'] = (string)$rq['name'];
$r['ingredient'] = (string)$rq['ingredient'];
$r['ingID'] = (int)$rq['ingredient_id'];
Expand All @@ -63,7 +66,8 @@
$r['inventory']['mUnit'] = (string)$inventory['mUnit'] ?: $settings['mUnit'];

$r['toAdd'] = (int)$rq['toAdd'];

$r['toSkip'] = (int)$rq['skip'];



$rx[]=$r;
Expand Down
5 changes: 5 additions & 0 deletions css/vault.css
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,11 @@ tr.strikeout td:before {
text-decoration: line-through solid red 3px;
}

.skipped {
font-style: italic;
text-decoration: line-through solid yellow 3px;
}

#formula td,
table.table th {
white-space: nowrap;
Expand Down
3 changes: 3 additions & 0 deletions db/pvault.sql
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,14 @@ CREATE TABLE `makeFormula` (
`name` varchar(255) COLLATE utf8_general_ci NOT NULL,
`ingredient` varchar(255) COLLATE utf8_general_ci DEFAULT NULL,
`ingredient_id` INT NOT NULL,
`replacement_id` INT NOT NULL DEFAULT '0',
`concentration` decimal(5,2) DEFAULT 100.00,
`dilutant` varchar(255) COLLATE utf8_general_ci DEFAULT NULL,
`quantity` decimal(8,4) DEFAULT NULL,
`overdose` double(8,4) NOT NULL DEFAULT 0.0000,
`originalQuantity` double(8,4) DEFAULT NULL,
`notes` MEDIUMTEXT NULL,
`skip` INT NOT NULL DEFAULT '0',
`toAdd` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_general_ci;
Expand Down
2 changes: 1 addition & 1 deletion db/schema.ver
Original file line number Diff line number Diff line change
@@ -1 +1 @@
9.8
9.9
3 changes: 3 additions & 0 deletions db/updates/update_9.8-9.9.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
ALTER TABLE `makeFormula` ADD `notes` MEDIUMTEXT NULL AFTER `originalQuantity`;
ALTER TABLE `makeFormula` ADD `skip` INT NOT NULL DEFAULT '0' AFTER `notes`;
ALTER TABLE `makeFormula` ADD `replacement_id` INT NOT NULL DEFAULT '0' AFTER `ingredient_id`;
72 changes: 68 additions & 4 deletions func/genBatchPDF.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,9 +117,11 @@ function Code39($xpos, $ypos, $code, $baseline=0.5, $height=5){

$display_heading = array('name'=> 'Product', 'ingredient'=> 'Ingredient','concentration'=> 'Concentration',);
$formula_q = mysqli_query($conn, "SELECT * FROM formulas WHERE fid = '$fid' ORDER BY ingredient ASC");

$header = array('Ingredient', 'CAS#', 'Purity %', 'Dilutant', 'Quantity', 'Concentration %');
$hd_blends = array('Ingredient', 'Contains','CAS#', 'Concentration %');
$hd_extras = array('Ingredient', 'Notes');
$hd_replacements = array('Ingredient', 'Replacement');

$meta = mysqli_fetch_array(mysqli_query($conn, "SELECT * FROM formulasMetaData WHERE fid = '$fid'"));

Expand Down Expand Up @@ -202,11 +204,17 @@ function Code39($xpos, $ypos, $code, $baseline=0.5, $height=5){
$pdf->SetFont('Arial','BU',10);
$pdf->MultiCell(250,10,"Also contains \n");



foreach($hd_blends as $heading) {
$pdf->Cell(68,12,$heading,1,0,'C');
}
if($formulaTable == "makeFormula"){
$qAllIng = mysqli_query($conn, "SELECT ingredient,quantity,concentration,notes,replacement_id FROM makeFormula WHERE fid = '$fid'");
} else {
$qAllIng = mysqli_query($conn, "SELECT ingredient,quantity,concentration FROM $formulaTable WHERE fid = '$fid'");

$qAllIng = mysqli_query($conn, "SELECT ingredient,quantity,concentration FROM $formulaTable WHERE fid = '$fid'");
}
while ($res_all_ing = mysqli_fetch_array($qAllIng)) {

$bldQ = mysqli_query($conn, "SELECT ing,name,cas,percentage FROM allergens WHERE ing = '".$res_all_ing['ingredient']."'");
Expand All @@ -222,10 +230,66 @@ function Code39($xpos, $ypos, $code, $baseline=0.5, $height=5){
}
}

//Extras table
$pdf->AddPage();
$pdf->AliasNbPages();
$pdf->SetFont('Arial','BU',10);
$pdf->MultiCell(250,10,"Additional information \n");

//ADD INFO
foreach($hd_extras as $heading) {
$pdf->Cell(140,12,$heading,1,0,'C');
}
if($formulaTable == "makeFormula"){
$qExtras = mysqli_query($conn, "SELECT DISTINCT A.ingredient, B.notes FROM formulas A JOIN makeFormula B ON A.ingredient = B.ingredient WHERE A.fid = '$fid' ORDER BY ingredient ASC");
} else {
$qExtras = mysqli_query($conn, "SELECT ingredient,notes FROM formulas WHERE fid = '$fid'");

}
while ($res_extras = mysqli_fetch_array($qExtras)) {
$pdf->Ln();
$pdf->SetFont('Arial','',8);
$pdf->Cell(140,8,$res_extras['ingredient'],1,0,'C');
$pdf->Cell(140,8,$res_extras['notes'] ?: "-",1,0,'C');
}
if($formulaTable == "makeFormula"){
//Replacements table
$pdf->AddPage();
$pdf->AliasNbPages();
$pdf->SetFont('Arial','BU',10);
$pdf->MultiCell(250,10,"Replacements \n");


foreach($hd_replacements as $heading) {
$pdf->Cell(140,12,$heading,1,0,'C');
}

$qRepl = mysqli_query($conn, "SELECT DISTINCT A.ingredient, B.replacement_id FROM formulas A JOIN makeFormula B ON A.ingredient = B.ingredient WHERE A.fid = '$fid' ORDER BY ingredient ASC");

while ($res_repl = mysqli_fetch_array($qRepl)) {
$repInfo = mysqli_fetch_array(mysqli_query($conn, "SELECT name FROM ingredients WHERE id = '".$res_repl['replacement_id']."'"));

$pdf->Ln();
$pdf->SetFont('Arial','',8);
$pdf->Cell(140,8,$res_repl['ingredient'],1,0,'C');
$pdf->Cell(140,8,$repInfo['name'] ?: "-",1,0,'C');
}
}




//GEN PDF
$pdf = base64_encode($pdf->Output('S'));
$docData = 'data:application/pdf;base64,' .$pdf;

mysqli_query($conn, "INSERT INTO batchIDHistory (id,fid,pdf,product_name) VALUES ('$batchID','$fid','$pdf','".$meta['product_name']."')");
if($formulaTable == "makeFormula"){

mysqli_query($conn, "INSERT INTO documents (ownerID,type,name,notes,docData) VALUES (".$meta['id'].",'5','$batchID','Auto generated by Formula Make','$docData')");


}else{
mysqli_query($conn, "INSERT INTO batchIDHistory (id,fid,pdf,product_name) VALUES ('$batchID','$fid','$pdf','".$meta['product_name']."')");
}

}

Expand Down
Loading

0 comments on commit af7e343

Please sign in to comment.