-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaterials_update.php
More file actions
35 lines (32 loc) · 1.57 KB
/
Copy pathmaterials_update.php
File metadata and controls
35 lines (32 loc) · 1.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
<?php
require_once 'includes/auth.php';
require_login();
require_csrf();
require_once 'includes/db.php';
$id = (int)$_POST['id'];
$product_code = trim($_POST['product_code'] ?? '');
$product_name = trim($_POST['product_name'] ?? '');
$description = trim($_POST['description'] ?? '');
$stock = floatval($_POST['stock'] ?? 0);
$warehouse_location = trim($_POST['warehouse_location'] ?? '');
$unit = trim($_POST['unit'] ?? '');
$unit_value = trim($_POST['unit_value'] ?? '');
$qr_unit_pack = trim($_POST['qr_unit_pack'] ?? '');
$product_group = trim($_POST['product_group'] ?? '');
$purchase_price = floatval($_POST['purchase_price'] ?? 0);
$purchase_time = (int)($_POST['purchase_time'] ?? 0);
$supplier = trim($_POST['supplier'] ?? '');
$is_active = isset($_POST['is_active']) ? (int)$_POST['is_active'] : 1;
// Duplicate check only if code has changed
$stmt = $pdo->prepare("SELECT id FROM materials WHERE product_code=? AND id<>?");
$stmt->execute([$product_code, $id]);
if ($stmt->fetch()) {
echo json_encode(['success'=>false, 'message'=>'The product code already exists!']);
exit;
}
$stmt = $pdo->prepare("UPDATE materials SET product_code=?, product_name=?, description=?, stock=?, warehouse_location=?, unit=?, unit_value=?, qr_unit_pack=?, product_group=?, purchase_price=?, purchase_time=?, supplier=?, is_active=? WHERE id=?");
$res = $stmt->execute([
$product_code, $product_name, $description, $stock, $warehouse_location, $unit, $unit_value, $qr_unit_pack, $product_group,
$purchase_price, $purchase_time, $supplier, $is_active, $id
]);
echo json_encode(['success'=>$res]);