59 lines
1.9 KiB
PHP
59 lines
1.9 KiB
PHP
<?php
|
|
/* Copyright (C) 2026 Eduard Wisch <data@data-it-solution.de>
|
|
*
|
|
* AJAX: Produktmenge aktualisieren
|
|
*/
|
|
|
|
if (!defined('NOTOKENRENEWAL')) define('NOTOKENRENEWAL', '1');
|
|
if (!defined('NOREQUIREMENU')) define('NOREQUIREMENU', '1');
|
|
if (!defined('NOREQUIREHTML')) define('NOREQUIREHTML', '1');
|
|
if (!defined('NOREQUIREAJAX')) define('NOREQUIREAJAX', '1');
|
|
|
|
// Load Dolibarr environment
|
|
$res = 0;
|
|
if (!$res && file_exists("../../main.inc.php")) $res = @include "../../main.inc.php";
|
|
if (!$res && file_exists("../../../main.inc.php")) $res = @include "../../../main.inc.php";
|
|
if (!$res && file_exists("../../../../main.inc.php")) $res = @include "../../../../main.inc.php";
|
|
if (!$res) die("Include of main fails");
|
|
|
|
dol_include_once('/stundenzettel/class/stundenzettel.class.php');
|
|
|
|
header('Content-Type: application/json');
|
|
|
|
// Security check
|
|
if (!$user->hasRight('stundenzettel', 'write')) {
|
|
echo json_encode(array('success' => false, 'error' => 'Permission denied'));
|
|
exit;
|
|
}
|
|
|
|
$stundenzettel_id = GETPOST('stundenzettel_id', 'int');
|
|
$line_id = GETPOST('line_id', 'int');
|
|
$qty_done = GETPOST('qty_done', 'int');
|
|
|
|
if (empty($stundenzettel_id) || empty($line_id)) {
|
|
echo json_encode(array('success' => false, 'error' => 'Missing parameters'));
|
|
exit;
|
|
}
|
|
|
|
$stundenzettel = new Stundenzettel($db);
|
|
if ($stundenzettel->fetch($stundenzettel_id) <= 0) {
|
|
echo json_encode(array('success' => false, 'error' => 'Stundenzettel not found'));
|
|
exit;
|
|
}
|
|
|
|
// Nur im Entwurf bearbeitbar
|
|
if ($stundenzettel->status != Stundenzettel::STATUS_DRAFT) {
|
|
echo json_encode(array('success' => false, 'error' => 'Stundenzettel is not in draft status'));
|
|
exit;
|
|
}
|
|
|
|
$result = $stundenzettel->updateProductQty($line_id, $qty_done);
|
|
|
|
if ($result > 0) {
|
|
echo json_encode(array(
|
|
'success' => true,
|
|
'qty_done' => $qty_done
|
|
));
|
|
} else {
|
|
echo json_encode(array('success' => false, 'error' => 'Failed to update qty'));
|
|
}
|