<commit_before><?php require 'header.php'; enableToERP($userID); ?>
<script src="../plugins/jQuery/jquery-ui/jquery-ui.min.js"></script>
<?php
$meta_curDate = $meta_deliveryDate = getCurrentTimestamp();
$meta_porto = $meta_porto_percentage = 0;
$meta_paymentMethod = $meta_shipmentType = $meta_representative = $meta_header = '';

if(!empty($_GET['val'])){
  $historyID = intval($_GET['val']);
} else {
  redirect('view?err=1');
}

$result = $conn->query("SELECT proposals.*, companyID, id_number FROM proposals, processHistory, clientData
WHERE proposals.clientID = clientData.id AND proposals.id = processHistory.processID AND processHistory.id = $historyID");
if($result && $result->num_rows > 0){
  $proposal_row = $result->fetch_assoc();
} else {
  redirect('view?err=2'); //STRIKE
}
if(!in_array($proposal_row['companyID'], $available_companies)){
  redirect('view?err=2'); //STRIKE
}

if($_SERVER['REQUEST_METHOD'] == 'POST'){
  if(isset($_POST['meta_curDate']) && test_Date($_POST['meta_curDate'].' 12:00:00')){
    $meta_curDate = test_input($_POST['meta_curDate'].' 12:00:00');
    $proposal_row['curDate'] = $meta_curDate;
  }
  if(isset($_POST['meta_deliveryDate']) && test_Date($_POST['meta_deliveryDate'].' 12:00:00')){
    $meta_deliveryDate = test_input($_POST['meta_deliveryDate'].' 12:00:00');
    $proposal_row['deliveryDate'] =  $meta_deliveryDate;
  }
  if(isset($_POST['meta_paymentMethod'])){
    $meta_paymentMethod = test_input($_POST['meta_paymentMethod']);
    $proposal_row['paymentMethod'] =  $meta_paymentMethod;
  }
  if(isset($_POST['meta_shipmentType'])){
    $meta_shipmentType = test_input($_POST['meta_shipmentType']);
    $proposal_row['shipmentType'] =  $meta_shipmentType;
  }
  if(isset($_POST['meta_representative'])){
    $meta_representative = test_input($_POST['meta_representative']);
    $proposal_row['representative'] =  $meta_representative;
  }
  if(isset($_POST['meta_porto'])){
    $meta_porto = floatval($_POST['meta_porto']);
    $proposal_row['porto'] =  $meta_porto;
  }
  if(isset($_POST['meta_header'])){
    $meta_header = test_input($_POST['meta_header']);
    $proposal_row['header'] =  $meta_header;
  }
  if(isset($_POST['meta_porto_percentage'])){
    $meta_porto_percentage = intval($_POST['meta_porto_percentage']);
    $proposal_row['portoRate'] =  $meta_porto_percentage;
  }

  if(isset($_POST['translate'])){
    if(!empty($_POST['copy_transition'])){
      $transit = $_POST['copy_transition'];
      $prod_list = array();
      //step1 - get all products (id quantity and origin) from current history
      $res = $conn->query("SELECT * FROM products WHERE historyID = $historyID");
      while($row = $res->fetch_assoc()){
        if($row['origin']){
          $prod_list[$row['origin']] = $row;
        } else {  //origins can be empty... what to do then?
          $prod_list[$row['id']] = $row;
        }
      }
      //step2 - reduce by all products which are same as transit
      $res = $conn->query("SELECT quantity, origin FROM products INNER JOIN processHistory ON products.historyID = processHistory.id
      WHERE processHistory.processID = ".$proposal_row['id']." AND id_number LIKE '$transit%'"); echo $conn->error;
      while($row = $res->fetch_assoc()){
        if(isset($prod_list[$row['origin']])){
          $prod_list[$row['origin']]['quantity'] -= $row['quantity'];
        }
      }
      $res->free();
      //step3 - create new history and enter products with quantities
      $num = getNextERP($transit, $proposal_row['companyID']);
      $conn->query("INSERT INTO processHistory (id_number, processID) VALUES('$num', ".$proposal_row['id'].")"); echo $conn->error;
      $historyID = $conn->insert_id;
      $stmt = $conn->prepare("INSERT INTO products (historyID, origin, position, name, price, quantity, description, taxID, cash, unit, purchase, iv, iv2)
      VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); echo $conn->error;
      $stmt->bind_param("isisddsidsdss", $historyID, $origin, $pos, $name, $price, $quantity, $desc, $taxID, $cash, $unit, $purchase, $iv, $iv2);
      foreach($prod_list as $p){
        if($p['quantity'] > 0 || !$p['origin']){
          $origin = $p['origin'];
          $pos = $p['position'];
          $name = $p['name'];
          $price = $p['price'];
          $quantity = $p['quantity'];
          $desc = $p['description'];
          $taxID = $p['taxID'];
          $cash = $p['cash'];
          $unit = $p['unit'];
          $purchase = $p['purchase'];
          $iv = $p['iv'];
          $iv2 = $p['iv2'];
          $stmt->execute();
        }
        if($stmt->error) echo $stmt->error;
      }
      echo $stmt->error;
      $stmt->close();
      redirect("edit?val=$historyID");<commit_msg>Fixed: Char enum as decimal<commit_after><?php require 'header.php'; enableToERP($userID); ?>
<script src="../plugins/jQuery/jquery-ui/jquery-ui.min.js"></script>
<?php
$meta_curDate = $meta_deliveryDate = getCurrentTimestamp();
$meta_porto = $meta_porto_percentage = 0;
$meta_paymentMethod = $meta_shipmentType = $meta_representative = $meta_header = '';

if(!empty($_GET['val'])){
  $historyID = intval($_GET['val']);
} else {
  redirect('view?err=1');
}

$result = $conn->query("SELECT proposals.*, companyID, id_number FROM proposals, processHistory, clientData
WHERE proposals.clientID = clientData.id AND proposals.id = processHistory.processID AND processHistory.id = $historyID");
if($result && $result->num_rows > 0){
  $proposal_row = $result->fetch_assoc();
} else {
  redirect('view?err=2'); //STRIKE
}
if(!in_array($proposal_row['companyID'], $available_companies)){
  redirect('view?err=2'); //STRIKE
}

if($_SERVER['REQUEST_METHOD'] == 'POST'){
  if(isset($_POST['meta_curDate']) && test_Date($_POST['meta_curDate'].' 12:00:00')){
    $meta_curDate = test_input($_POST['meta_curDate'].' 12:00:00');
    $proposal_row['curDate'] = $meta_curDate;
  }
  if(isset($_POST['meta_deliveryDate']) && test_Date($_POST['meta_deliveryDate'].' 12:00:00')){
    $meta_deliveryDate = test_input($_POST['meta_deliveryDate'].' 12:00:00');
    $proposal_row['deliveryDate'] =  $meta_deliveryDate;
  }
  if(isset($_POST['meta_paymentMethod'])){
    $meta_paymentMethod = test_input($_POST['meta_paymentMethod']);
    $proposal_row['paymentMethod'] =  $meta_paymentMethod;
  }
  if(isset($_POST['meta_shipmentType'])){
    $meta_shipmentType = test_input($_POST['meta_shipmentType']);
    $proposal_row['shipmentType'] =  $meta_shipmentType;
  }
  if(isset($_POST['meta_representative'])){
    $meta_representative = test_input($_POST['meta_representative']);
    $proposal_row['representative'] =  $meta_representative;
  }
  if(isset($_POST['meta_porto'])){
    $meta_porto = floatval($_POST['meta_porto']);
    $proposal_row['porto'] =  $meta_porto;
  }
  if(isset($_POST['meta_header'])){
    $meta_header = test_input($_POST['meta_header']);
    $proposal_row['header'] =  $meta_header;
  }
  if(isset($_POST['meta_porto_percentage'])){
    $meta_porto_percentage = intval($_POST['meta_porto_percentage']);
    $proposal_row['portoRate'] =  $meta_porto_percentage;
  }

  if(isset($_POST['translate'])){
    if(!empty($_POST['copy_transition'])){
      $transit = $_POST['copy_transition'];
      $prod_list = array();
      //step1 - get all products (id quantity and origin) from current history
      $res = $conn->query("SELECT * FROM products WHERE historyID = $historyID");
      while($row = $res->fetch_assoc()){
        if($row['origin']){
          $prod_list[$row['origin']] = $row;
        } else {  //origins can be empty... what to do then?
          $prod_list[$row['id']] = $row;
        }
      }
      //step2 - reduce by all products which are same as transit
      $res = $conn->query("SELECT quantity, origin FROM products INNER JOIN processHistory ON products.historyID = processHistory.id
      WHERE processHistory.processID = ".$proposal_row['id']." AND id_number LIKE '$transit%'"); echo $conn->error;
      while($row = $res->fetch_assoc()){
        if(isset($prod_list[$row['origin']])){
          $prod_list[$row['origin']]['quantity'] -= $row['quantity'];
        }
      }
      $res->free();
      //step3 - create new history and enter products with quantities
      $num = getNextERP($transit, $proposal_row['companyID']);
      $conn->query("INSERT INTO processHistory (id_number, processID) VALUES('$num', ".$proposal_row['id'].")"); echo $conn->error;
      $historyID = $conn->insert_id;
      $stmt = $conn->prepare("INSERT INTO products (historyID, origin, position, name, price, quantity, description, taxID, cash, unit, purchase, iv, iv2)
      VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"); echo $conn->error;
      $stmt->bind_param("isisddsissdss", $historyID, $origin, $pos, $name, $price, $quantity, $desc, $taxID, $cash, $unit, $purchase, $iv, $iv2);
      foreach($prod_list as $p){
        if($p['quantity'] > 0 || !$p['origin']){
          $origin = $p['origin'];
          $pos = $p['position'];
          $name = $p['name'];
          $price = $p['price'];
          $quantity = $p['quantity'];
          $desc = $p['description'];
          $taxID = $p['taxID'];
          $cash = $p['cash'];
          $unit = $p['unit'];
          $purchase = $p['purchase'];
          $iv = $p['iv'];
          $iv2 = $p['iv2'];
          $stmt->execute();
        }
        if($stmt->error) echo $stmt->error;
      }
      echo $stmt->error;
      $stmt->close();
      redirect("edit?val=$historyID");
{'fraction_non_alphanumeric': 0.19651898734177214, 'fraction_numerical': 0.007805907172995781, 'mean_word_length': 4.051145444858817, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 53, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '191640', 'n_tokens_mistral': 3230, 'n_tokens_neox': 3145, 'n_words': 547}