-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathboms_save.php
More file actions
23 lines (20 loc) · 912 Bytes
/
Copy pathboms_save.php
File metadata and controls
23 lines (20 loc) · 912 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
<?php
require_once 'includes/auth.php';
require_login();
require_csrf();
require_once 'includes/db.php';
$product_id = (int)$_POST['product_id'];
$material_id = (int)$_POST['material_id'];
$quantity = (float)$_POST['quantity'];
$unit = trim($_POST['unit'] ?? '');
$version = $_POST['version'] ?? 'standard';
// There can be no duplicate rows: same product_id, material_id, version!
$stmt = $pdo->prepare("SELECT id FROM boms WHERE product_id=? AND material_id=? AND version=?");
$stmt->execute([$product_id, $material_id, $version]);
if ($stmt->fetch()) {
echo json_encode(['success'=>false, 'message'=>'This material is already in the bill of materials!']);
exit;
}
$stmt = $pdo->prepare("INSERT INTO boms (product_id, material_id, quantity, unit, version) VALUES (?, ?, ?, ?, ?)");
$res = $stmt->execute([$product_id, $material_id, $quantity, $unit, $version]);
echo json_encode(['success'=>$res]);