Skip to content

Commit

Permalink
Merge pull request #179 from globaldyne/v10.8
Browse files Browse the repository at this point in the history
V10.8
  • Loading branch information
globaldyne authored Aug 9, 2024
2 parents 9f32d63 + 9205560 commit 155185a
Show file tree
Hide file tree
Showing 89 changed files with 3,608 additions and 3,324 deletions.
19 changes: 19 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,23 @@
# CHANGELOG
### Version 10.8
- Fix API key update not returning error in correct format
- Rewrite API page
- Rewrite About page
- Try to get measurement unit from ingredient supplier first for ingredient search in formulation
- Table border removed from tables
- Added support for a dark theme
- Complete rewrite for Finished Product page
- Various minor improvements for Formula view
- Rewrite Sell Formula for BS5
- Added a font size when exporting a PDF in Sell Formula
- Added brand logo when exporting a PDF in Sell Formula
- Added opacity for watermak in Sell Formula page
- Replaced PDF export in Sell Formula with the native DataTables function
- Removed the space from ml2L function when appending the measurement unit
- Default PV Logo update
- Refactor of validateFormula() function
- Renamed clone formula to duplicate

### Version 10.7
- Removed ingredient purity and dilutant from Finished Product page for cleaner view
- Moved IFRA doc to a modal window
Expand Down
2 changes: 1 addition & 1 deletion VERSION.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
10.7
10.8
216 changes: 216 additions & 0 deletions core/finished_formula_data.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,216 @@
<?php

define('__ROOT__', dirname(dirname(__FILE__)));

require_once(__ROOT__.'/inc/sec.php');
require_once(__ROOT__.'/inc/opendb.php');
require_once(__ROOT__.'/inc/settings.php');

require_once(__ROOT__.'/libs/fpdf.php');
require_once(__ROOT__.'/func/genBatchID.php');
require_once(__ROOT__.'/func/genBatchPDF.php');
require_once(__ROOT__.'/func/calcCosts.php');
require_once(__ROOT__.'/func/calcPerc.php');
require_once(__ROOT__.'/func/searchIFRA.php');
require_once(__ROOT__.'/func/getIngSupplier.php');
require_once(__ROOT__.'/func/validateFormula.php');

if(!$_POST['id']){
$response['data'] = [];
header('Content-Type: application/json; charset=utf-8');
echo json_encode($response);
return;
}


$defPercentage = $settings['defPercentage'];

$defCatClass = $_POST['defCatClass'] ?: $settings['defCatClass'];
$id = mysqli_real_escape_string($conn, $_POST['id']);

$meta = mysqli_fetch_array(mysqli_query($conn, "SELECT name,fid,catClass,finalType,defView,isProtected,notes,product_name FROM formulasMetaData WHERE id = '$id'"));

if(!$meta['fid']){
$response['Error'] = (string)'Requested id is not valid.';
header('Content-Type: application/json; charset=utf-8');
echo json_encode($response);
return;
}


$mg = mysqli_fetch_assoc(mysqli_query($conn, "SELECT SUM(quantity) AS total_mg FROM formulas WHERE fid = '".$meta['fid']."'"));

$bottle_id = $_POST['bottle_id'];
$concentration = $_POST['concentration'];
$carrier_id = $_POST['carrier_id'];
$lid_id = $_POST['lid_id'];

$bottle = mysqli_fetch_array(mysqli_query($conn, "SELECT price,ml,name FROM bottles WHERE id = '$bottle_id' AND price != 0 "));

$carrier_cost = mysqli_fetch_array(mysqli_query($conn, "SELECT price,size FROM suppliers WHERE ingID = '$carrier_id'"));

if($_POST['lid_id']){
$lid = mysqli_fetch_array(mysqli_query($conn, "SELECT price,style FROM lids WHERE id = '$lid_id'"));
}else{
$lid['price'] = 0;
$lid['style'] = 'none';
}

$new_conc = $bottle['ml'] / 100 * $concentration;
$carrier = $bottle['ml'] - $new_conc;


if($_POST['supplier_id']){
$sid = $_POST['supplier_id'];
}

if($_POST['batch_id'] == '1'){

define('FPDF_FONTPATH',__ROOT__.'/fonts');
$batchID = genBatchID();

genBatchPDF($meta['fid'],$batchID,$bottle['ml'],$new_conc,$mg['total_mg'],$defCatClass,$settings['qStep'], $defPercentage);


}


$formula_q = mysqli_query($conn, "SELECT id,ingredient,concentration,quantity FROM formulas WHERE fid = '".$meta['fid']."' ORDER BY ingredient ASC");
while ($formula = mysqli_fetch_array($formula_q)){
$form[] = $formula;
}

foreach ($form as $formula){

$ing_q = mysqli_fetch_array(mysqli_query($conn, "SELECT id, name, cas, $defCatClass, profile, odor, category, physical_state,usage_type AS classification, type, byPassIFRA FROM ingredients WHERE name = '".$formula['ingredient']."'"));

$new_quantity = $formula['quantity'] / $mg['total_mg'] * $new_conc;

$conc = $formula['concentration'] / 100 * $formula['quantity']/$mg['total_mg'] * 100;
$conc_final = $formula['concentration'] / 100 * $formula['quantity']/$mg['total_mg'] * $concentration;

if($settings['multi_dim_perc'] == '1'){
$compos = mysqli_query($conn, "SELECT name,$defPercentage,cas FROM ingredient_compounds WHERE ing = '".$formula['ingredient']."'");

while($compo = mysqli_fetch_array($compos)){
$cmp[] = $compo;
}

foreach ($cmp as $a){
$arrayLength = count($a);
$i = 0;
while ($i < $arrayLength){
$c = multi_dim_search($a, 'cas', $ing_q['cas']?:'N/A')[$i];
$conc_a[$a['cas']] += $c['percentage']/100 * $formula['quantity'] * $formula['concentration'] / 100;
$conc_b[$a['cas']] += $c['percentage']/100 * $formula['quantity'] * $formula['concentration'] / $mg['total_mg']* $concentration / 100 ;
$i++;
}
}
$conc+=$conc_a[$a['cas']];
$conc_final+=$conc_b[$a['cas']];

}

$r['formula_ingredient_id'] = (int)$formula['id'];
$r['formula_name'] = (string)$meta['name'];
$r['fid'] = (string)$meta['fid'];

$r['ingredient']['name'] = (string)$ingName ?: $formula['ingredient'];
$r['ingredient']['cas'] = (string)$ing_q['cas'] ?: 'N/A';
$r['quantity'] = number_format((float)$new_quantity, $settings['qStep'],'.', '') ?: 0;
$r['final_concentration'] = number_format((float)$conc_final, $settings['qStep']) ?: 0;

if($sid){
$r['cost'] = (float)calcCosts(getSingleSupplier($sid,$ing_q['id'],$conn)['price'],$new_quantity, $formula['concentration'], getPrefSupplier($ing_q['id'],$conn)['size']);
}else{
$r['cost'] = (float)calcCosts(getPrefSupplier($ing_q['id'],$conn)['price'],$new_quantity, $formula['concentration'], getPrefSupplier($ing_q['id'],$conn)['size']);
}

$u = explode(' - ',searchIFRA($ing_q['cas'],$formula['ingredient'],null,$defCatClass));

if(($u['0'] && $ing_q['byPassIFRA'] == 0)){
$r['usage_limit'] = number_format((float)$u['0']?:100, $settings['qStep']);
$r['usage_restriction'] = (string)$u['1'] ?: 'N/A';
$r['usage_regulator'] = (string)"IFRA";
}else{
$r['usage_limit'] = number_format((float)$ing_q["$defCatClass"], $settings['qStep']) ?: 100;
$r['usage_restriction'] = (int)$ing_q['classification'];
$r['usage_regulator'] = (string)"PV";
$r['ingredient']['classification'] = (int)$ing_q['classification'] ?: 1;
}


$response['data'][] = $r;

$conc_tot[] = $conc_final;
$new_tot[] = $new_quantity;

if($sid){
$tot[] = calcCosts(getSingleSupplier($sid,$ing_q['id'],$conn)['price'],$new_quantity, $formula['concentration'], getPrefSupplier($ing_q['id'],$conn)['size']);
}else{
$tot[] = calcCosts(getPrefSupplier($ing_q['id'],$conn)['price'],$new_quantity, $formula['concentration'], getPrefSupplier($ing_q['id'],$conn)['size']);
}

}

if(empty($r)){
$response['data'] = [];
}
$carrier_sub_cost = number_format($carrier_cost['price'] / $carrier_cost['size'] * $carrier, $settings['qStep']);

$m['sub_total_quantity'] = number_format(array_sum($new_tot), $settings['qStep']);
$m['carrier_quantity'] = number_format($carrier, $settings['qStep']);
$m['carrier_quantity'] = number_format($carrier, $settings['qStep']);
$m['carrier_cost'] = (float)$carrier_sub_cost;
$m['bottle_quantity'] = (float)$bottle['ml'];
$m['lid_cost'] = (float)$lid['price'];
$m['lid_style'] = (string)$lid['style'];
$m['batchNo'] = $batchID;
$m['total_quantity'] = (float)number_format( array_sum($new_tot) + $carrier,$settings['qStep']);
$m['quantity_unit'] = (string)$settings['mUnit'];
$m['sub_concentration'] = (float)number_format(array_sum($conc_tot),$settings['qStep']);
$m['carrier_concentration'] = (float)number_format($carrier * 100 / $bottle['ml'],$settings['qStep']);
$m['sub_cost'] = (float)number_format(array_sum($tot),$settings['qStep']);
$m['bottle_cost'] = (float)number_format($bottle['price'],$settings['qStep']);
$m['total_cost'] = (float)number_format(array_sum($tot) + $lid['price'] + $carrier_sub_cost + $bottle['price'], $settings['qStep']);


$m['cat_class'] = (string)$defCatClass;
$m['currency'] = (string)utf8_encode($settings['currency']);
$m['product_concentration'] = (int)$concentration;
$m['formula_name'] = (string)$meta['name'];
$m['product_name'] = (string)$meta['product_name'] ?: '-';
$m['fid'] = (string)$meta['fid'];



if($m['sub_total_quantity'] != 0){
$rs = validateFormula($meta['fid'], $bottle['ml'], $new_conc, $mg['total_mg'], $defCatClass, $settings['qStep']);
if($rs !== 0){
foreach ($rs as $error) {
$inval_materials[] = $error;
}
$val_status = 1;
$val_slug = "danger";
$val_msg .= "Your formula contains materials not compatible with IFRA standards";
}
}

$compliance['checked_for'] = $defCatClass;
$compliance['final_total_ml'] = (float)$mg['total_mg'];
$compliance['final_type_conc'] = (int)$concentration;
$compliance['carrier'] = (float)$carrier;
$compliance['status'] = (int)$val_status ?: 0;
$compliance['slug'] = (string)$val_slug ?: "success";
$compliance['message'] = (string)$val_msg ?: 'Formula is IFRA compliant';

$compliance['inval_materials'] = array( "data" => $inval_materials );

$response['compliance'] = $compliance;
$response['meta'] = $m;


header('Content-Type: application/json; charset=utf-8');
echo json_encode($response);
return;
?>
7 changes: 4 additions & 3 deletions core/full_formula_data.php
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,9 @@
$chName = mysqli_fetch_array(mysqli_query($conn,"SELECT chemical_name FROM ingredients WHERE name = '".$formula['ingredient']."'"));
$ingName = $chName['chemical_name'];
}
$r['formula_ingredient_id'] = (int)$formula['id'];
$r['fid'] = (string)$meta['name']; //TODO
$r['formula_ingredient_id'] = (int)$formula['id'];
$r['formula_name'] = (string)$meta['name'];
$r['fid'] = (string)$meta['fid']; //TODO

if($settings['grp_formula'] == '1'){
$r['ingredient']['profile'] = (string)$ing_q['profile'] ?: 'Unknown';
Expand Down Expand Up @@ -277,7 +278,7 @@


if($m['total_ingredients'] != 0 && !$_POST['search']){
if( validateFormula($meta['fid'], $_GET['final_total_ml'] ?: 100, $new_conc, $mg['total_mg'], $_GET['val_cat']?: $defCatClass, $settings['qStep'], $conn) == TRUE){
if( validateFormula($meta['fid'], $_GET['final_total_ml'] ?: 100, $new_conc, $mg['total_mg'], $_GET['val_cat']?: $defCatClass, $settings['qStep']) == TRUE){
$val_status = 1;
$val_msg = 'Your formula contains materials, exceeding and/or missing IFRA standards. Please alter your formula.';
}
Expand Down
5 changes: 3 additions & 2 deletions core/list_ingredients_simple.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
$i = 0;
foreach ($ingredients as $ingredient) {


$supp = getIngSupplier($ingredient['id'],1,$conn);
$r['id'] = (int)$ingredient['id'];
$r['name'] = (string)$ingredient['name'];
$r['IUPAC'] = (string)$ingredient['INCI']?: 'N/A';
Expand All @@ -45,7 +45,8 @@
$r['description'] = (string)$ingredient['odor'] ?: 'N/A';
$r['physical_state'] = (int)$ingredient['physical_state'] ?: 1;
$r['profile'] = (string)$ingredient['profile'] ?: 'Uknwown';
$r['stock'] = (float)number_format(getIngSupplier($ingredient['id'],1,$conn)['stock'], $settings['qStep']) ?: 0;
$r['stock'] = (float)number_format($supp['stock'], $settings['qStep']) ?: 0;
$r['mUnit'] = (string)$supp['mUnit'];

$rx[]=$r;
$i++;
Expand Down
4 changes: 2 additions & 2 deletions css/bootstrap-tagsinput.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
*/

.bootstrap-tagsinput {
background-color: #fff;
background-color: var( --bs-body-bg);
border: 1px solid #ccc;
box-shadow: inset 0 1px 1px rgba(0, 0, 0, 0.075);
display: inline-block;
Expand Down Expand Up @@ -42,7 +42,7 @@
}
.bootstrap-tagsinput .tag {
margin-right: 2px;
color: white;
color: var( --bs-light );
}
.bootstrap-tagsinput .tag [data-role="remove"] {
margin-left: 8px;
Expand Down
Loading

0 comments on commit 155185a

Please sign in to comment.