www/includes/db_product.php

changeset 768
ae1195153fa2
parent 763
12a795e8b568
child 773
f4161330ed01
equal deleted inserted replaced
767:08c0343b622b 768:ae1195153fa2
278 $sql .= "', divide_type='" . $_POST['divide_type']; 278 $sql .= "', divide_type='" . $_POST['divide_type'];
279 $sql .= "', divide_size='" . floatval($_POST['divide_size']); 279 $sql .= "', divide_size='" . floatval($_POST['divide_size']);
280 $sql .= "', divide_factor='" . floatval($_POST['divide_factor']); 280 $sql .= "', divide_factor='" . floatval($_POST['divide_factor']);
281 $sql .= "', divide_parts='" . $_POST['divide_parts']; 281 $sql .= "', divide_parts='" . $_POST['divide_parts'];
282 $sql .= "', divide_part='" . $_POST['divide_part']; 282 $sql .= "', divide_part='" . $_POST['divide_part'];
283 //syslog(LOG_NOTICE, $sql);
284 283
285 $fermentables = '['; 284 $fermentables = '[';
286 $comma = FALSE; 285 $comma = FALSE;
287 if (isset($_POST['fermentables'])) { 286 if (isset($_POST['fermentables'])) {
288 $array = $_POST['fermentables']; 287 $array = $_POST['fermentables'];
329 //syslog(LOG_NOTICE, $fermentable); 328 //syslog(LOG_NOTICE, $fermentable);
330 $fermentables .= $fermentable; 329 $fermentables .= $fermentable;
331 } 330 }
332 } 331 }
333 $fermentables .= ']'; 332 $fermentables .= ']';
334 //syslog(LOG_NOTICE, $fermentables);
335 $sql .= "', json_fermentables='" . $fermentables; 333 $sql .= "', json_fermentables='" . $fermentables;
336 334
337 $hops = '['; 335 $hops = '[';
338 $comma = FALSE; 336 $comma = FALSE;
339 if (isset($_POST['hops'])) { 337 if (isset($_POST['hops'])) {
375 //syslog(LOG_NOTICE, $hop); 373 //syslog(LOG_NOTICE, $hop);
376 $hops .= $hop; 374 $hops .= $hop;
377 } 375 }
378 } 376 }
379 $hops .= ']'; 377 $hops .= ']';
380 //syslog(LOG_NOTICE, 'hops: ' . $hops);
381 $sql .= "', json_hops='" . $hops; 378 $sql .= "', json_hops='" . $hops;
382 379
383 $miscs = '['; 380 $miscs = '[';
384 $comma = FALSE; 381 $comma = FALSE;
385 if (isset($_POST['miscs'])) { 382 if (isset($_POST['miscs'])) {
412 //syslog(LOG_NOTICE, $misc); 409 //syslog(LOG_NOTICE, $misc);
413 $miscs .= $misc; 410 $miscs .= $misc;
414 } 411 }
415 } 412 }
416 $miscs .= ']'; 413 $miscs .= ']';
417 //syslog(LOG_NOTICE, 'miscs: ' . $miscs);
418 $sql .= "', json_miscs='" . $miscs; 414 $sql .= "', json_miscs='" . $miscs;
419 415
420 $yeasts = '['; 416 $yeasts = '[';
421 $comma = FALSE; 417 $comma = FALSE;
422 if (isset($_POST['yeasts'])) { 418 if (isset($_POST['yeasts'])) {
465 //syslog(LOG_NOTICE, $yeast); 461 //syslog(LOG_NOTICE, $yeast);
466 $yeasts .= $yeast; 462 $yeasts .= $yeast;
467 } 463 }
468 } 464 }
469 $yeasts .= ']'; 465 $yeasts .= ']';
470 //syslog(LOG_NOTICE, $yeasts);
471 $sql .= "', json_yeasts='" . $yeasts; 466 $sql .= "', json_yeasts='" . $yeasts;
472 467
473 $mashs = '['; 468 $mashs = '[';
474 $comma = FALSE; 469 $comma = FALSE;
475 if (isset($_POST['mashs'])) { 470 if (isset($_POST['mashs'])) {
513 //syslog(LOG_NOTICE, $mash); 508 //syslog(LOG_NOTICE, $mash);
514 $mashs .= $mash; 509 $mashs .= $mash;
515 } 510 }
516 } 511 }
517 $mashs .= ']'; 512 $mashs .= ']';
518 //syslog(LOG_NOTICE, $mashs);
519 $sql .= "', json_mashs='" . $mashs; 513 $sql .= "', json_mashs='" . $mashs;
520 514
521 if (isset($_POST['insert'])) { 515 if (isset($_POST['insert'])) {
522 $sql .= "';"; 516 $sql .= "';";
523 } 517 }
527 521
528 $result = mysqli_query($connect, $sql); 522 $result = mysqli_query($connect, $sql);
529 if (! $result) { 523 if (! $result) {
530 syslog(LOG_NOTICE, "db_product: result: ".mysqli_error($connect)); 524 syslog(LOG_NOTICE, "db_product: result: ".mysqli_error($connect));
531 $response['error'] = true; 525 $response['error'] = true;
532 $response['msg'] = "SQL fout: ".mysqli_error($link); 526 $response['msg'] = "SQL fout: ".mysqli_error($connect);
533 } else { 527 } else {
534 if (isset($_POST['update'])) { 528 if (isset($_POST['update'])) {
535 //syslog(LOG_NOTICE, "db_product: updated record ".$_POST['record']); 529 //syslog(LOG_NOTICE, "db_product: updated record ".$_POST['record']);
536 inventory_reduce(); 530 inventory_reduce();
537 } else { 531 } else {
538 $lastid = mysqli_insert_id($connect); 532 $lastid = mysqli_insert_id($connect);
539 //syslog(LOG_NOTICE, "db_product: inserted record ".$lastid);
540 } 533 }
541 } 534 }
542 echo json_encode($response); 535 echo json_encode($response);
543 536
544 } else if (isset($_POST['splitit'])) { 537 } else if (isset($_POST['splitit'])) {
554 547
555 $result = mysqli_query($connect, $sql); 548 $result = mysqli_query($connect, $sql);
556 if (! $result) { 549 if (! $result) {
557 syslog(LOG_NOTICE, "db_product: result: ".mysqli_error($connect)); 550 syslog(LOG_NOTICE, "db_product: result: ".mysqli_error($connect));
558 $response['error'] = true; 551 $response['error'] = true;
559 $response['msg'] = "SQL update fout: ".mysqli_error($link); 552 $response['msg'] = "SQL update fout: ".mysqli_error($connect);
560 } else { 553 } else {
561 syslog(LOG_NOTICE, "db_product: updated (divide) record ".$_POST['record']); 554 syslog(LOG_NOTICE, "db_product: updated (divide) record ".$_POST['record']);
562 } 555 }
563 echo json_encode($response); 556 echo json_encode($response);
564 557
569 $sql = "DELETE FROM `products` WHERE uuid='".$_POST['uuid']."';"; 562 $sql = "DELETE FROM `products` WHERE uuid='".$_POST['uuid']."';";
570 $result = mysqli_query($connect, $sql); 563 $result = mysqli_query($connect, $sql);
571 if (! $result) { 564 if (! $result) {
572 syslog(LOG_NOTICE, "db_product: ".$sql." result: ".mysqli_error($connect)); 565 syslog(LOG_NOTICE, "db_product: ".$sql." result: ".mysqli_error($connect));
573 $response['error'] = true; 566 $response['error'] = true;
574 $response['msg'] = "SQL delete fout: ".mysqli_error($link); 567 $response['msg'] = "SQL delete fout: ".mysqli_error($connect);
575 } else { 568 } else {
576 syslog(LOG_NOTICE, "db_product: deleted product uuid ".$_POST['uuid']); 569 syslog(LOG_NOTICE, "db_product: deleted product uuid ".$_POST['uuid']);
577 } 570 }
578 echo json_encode($response); 571 echo json_encode($response);
579 572
594 'brew_date' => substr($row['brew_date_start'], 0, 10), 587 'brew_date' => substr($row['brew_date_start'], 0, 10),
595 'package_date' => $row['package_date'] 588 'package_date' => $row['package_date']
596 ); 589 );
597 } 590 }
598 header("Content-type: application/json"); 591 header("Content-type: application/json");
599 echo json_encode($brews, JSON_UNESCAPED_UNICODE); 592 exit(json_encode($brews, JSON_UNESCAPED_UNICODE));
600 return;
601 } 593 }
602 594
603 if (isset($_GET['select']) && ($_GET['select'] == "archname")) { 595 if (isset($_GET['select']) && ($_GET['select'] == "archname")) {
604 $query = "SELECT record,name,code,brew_date_start,st_name,brew_fermenter_sg,fg,batch_size FROM products WHERE stage = '11' ORDER BY name,brew_date_start;"; 596 $query = "SELECT record,name,code,brew_date_start,st_name,brew_fermenter_sg,fg,batch_size FROM products WHERE stage = '11' ORDER BY name,brew_date_start;";
605 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); 597 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
614 'fg' => $row['fg'], 606 'fg' => $row['fg'],
615 'batch_size' => $row['batch_size'] 607 'batch_size' => $row['batch_size']
616 ); 608 );
617 } 609 }
618 header("Content-type: application/json"); 610 header("Content-type: application/json");
619 echo json_encode($brews, JSON_UNESCAPED_UNICODE); 611 exit(json_encode($brews, JSON_UNESCAPED_UNICODE));
620 return;
621 } 612 }
622 613
623 if (isset($_GET['select']) && ($_GET['select'] == "archcode")) { 614 if (isset($_GET['select']) && ($_GET['select'] == "archcode")) {
624 $query = "SELECT record,name,code,brew_date_start,st_name,brew_fermenter_sg,fg,batch_size FROM products WHERE stage = '11' ORDER BY code;"; 615 $query = "SELECT record,name,code,brew_date_start,st_name,brew_fermenter_sg,fg,batch_size FROM products WHERE stage = '11' ORDER BY code;";
625 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); 616 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
634 'fg' => $row['fg'], 625 'fg' => $row['fg'],
635 'batch_size' => $row['batch_size'] 626 'batch_size' => $row['batch_size']
636 ); 627 );
637 } 628 }
638 header("Content-type: application/json"); 629 header("Content-type: application/json");
639 echo json_encode($brews, JSON_UNESCAPED_UNICODE); 630 exit(json_encode($brews, JSON_UNESCAPED_UNICODE));
640 return;
641 } 631 }
642 632
643 if (isset($_GET['select']) && ($_GET['select'] == "archdate")) { 633 if (isset($_GET['select']) && ($_GET['select'] == "archdate")) {
644 $query = "SELECT record,name,code,brew_date_start,st_name,brew_fermenter_sg,fg,batch_size FROM products WHERE stage = '11' ORDER BY brew_date_start;"; 634 $query = "SELECT record,name,code,brew_date_start,st_name,brew_fermenter_sg,fg,batch_size FROM products WHERE stage = '11' ORDER BY brew_date_start;";
645 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect)); 635 $result = mysqli_query($connect, $query) or die("SQL Error 1: " . mysqli_error($connect));
655 'fg' => $row['fg'], 645 'fg' => $row['fg'],
656 'batch_size' => $row['batch_size'] 646 'batch_size' => $row['batch_size']
657 ); 647 );
658 } 648 }
659 header("Content-type: application/json"); 649 header("Content-type: application/json");
660 echo json_encode($brews, JSON_UNESCAPED_UNICODE); 650 exit(json_encode($brews, JSON_UNESCAPED_UNICODE));
661 return;
662 } 651 }
663 652
664 /* 653 /*
665 * SELECT, produce a list of products that can be fermented. 654 * SELECT, produce a list of products that can be fermented.
666 */ 655 */
688 'yeast_lo' => $yl, 677 'yeast_lo' => $yl,
689 'yeast_hi' => $yh 678 'yeast_hi' => $yh
690 ); 679 );
691 } 680 }
692 header("Content-type: application/json"); 681 header("Content-type: application/json");
693 echo json_encode($brews, JSON_UNESCAPED_UNICODE); 682 exit(json_encode($brews, JSON_UNESCAPED_UNICODE));
694 return;
695 } 683 }
696 684
697 /* 685 /*
698 * Default, select all or a given record. 686 * Default, select all or a given record.
699 */ 687 */
1081 $brew .= ',"yeasts":' . $row['json_yeasts']; 1069 $brew .= ',"yeasts":' . $row['json_yeasts'];
1082 $brew .= ',"mashs":' . $row['json_mashs']; 1070 $brew .= ',"mashs":' . $row['json_mashs'];
1083 } 1071 }
1084 1072
1085 $brew .= '}'; 1073 $brew .= '}';
1086 // syslog(LOG_NOTICE, $brew);
1087 $brews .= $brew; 1074 $brews .= $brew;
1088 } 1075 }
1089 $brews .= ']'; 1076 $brews .= ']';
1090 header("Content-type: application/json"); 1077 header("Content-type: application/json");
1091 echo $brews; 1078 exit($brews);
1092 } 1079 }
1093 1080
1094 1081
1095 1082
1096 function reduce_fermentables($item) { 1083 function reduce_fermentables($item) {

mercurial