Tul xxx Tul
User / IP
:
216.73.216.183
Host / Server
:
45.84.207.204 / aircan.me
System
:
Linux lt-bnk-web1726.main-hosting.eu 5.14.0-611.36.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Mar 3 11:23:52 EST 2026 x86_64
Command
|
Upload
|
Create
Mass Deface
|
Jumping
|
Symlink
|
Reverse Shell
Ping
|
Port Scan
|
DNS Lookup
|
Whois
|
Header
|
cURL
:
/
home
/
u931257429
/
domains
/
aircan.me
/
public_html
/
siscapslaurel
/
models
/
Viewing: InventoryTransaction.php
<?php class InventoryTransaction { public static function recentForItem(int $itemId, int $limit = 20): array { $pdo = (new Database())->getConnection(); $stmt = $pdo->prepare("SELECT t.*, CONCAT(u.first_name, ' ', u.last_name) AS user_name FROM inventory_transactions t LEFT JOIN users u ON u.id = t.created_by_user_id WHERE t.item_id = :item_id ORDER BY t.transacted_at DESC, t.id DESC LIMIT :limit"); $stmt->bindValue(':item_id', $itemId, PDO::PARAM_INT); $stmt->bindValue(':limit', $limit, PDO::PARAM_INT); $stmt->execute(); return $stmt->fetchAll(PDO::FETCH_ASSOC) ?: []; } public static function record( int $itemId, string $type, float $quantity, ?float $unitCost, ?string $reference, ?string $notes, ?int $userId, ?string $transactedAt = null ): void { $allowedTypes = ['Ingreso','Reposicion','Consumo','Baja','Ajuste']; if (!in_array($type, $allowedTypes, true)) { throw new InvalidArgumentException('Tipo de transacción inválido.'); } $pdo = (new Database())->getConnection(); $pdo->beginTransaction(); try { $itemStmt = $pdo->prepare('SELECT current_quantity, unit_cost FROM inventory_items WHERE id = :id LIMIT 1 FOR UPDATE'); $itemStmt->execute([':id' => $itemId]); $item = $itemStmt->fetch(PDO::FETCH_ASSOC); if (!$item) { throw new RuntimeException('Artículo de inventario no encontrado.'); } $currentQty = (float)$item['current_quantity']; $sign = in_array($type, ['Consumo','Baja'], true) ? -1 : 1; $delta = $sign * abs($quantity); $newQty = $currentQty + $delta; if ($newQty < 0) { throw new RuntimeException('La transacción dejaría la cantidad en negativo.'); } $effectiveUnitCost = $unitCost !== null ? (float)$unitCost : (float)$item['unit_cost']; if ($type === 'Ingreso' || $type === 'Reposicion') { // Promedio ponderado simple $totalValue = ($currentQty * (float)$item['unit_cost']) + (abs($quantity) * $effectiveUnitCost); $totalQty = $currentQty + abs($quantity); $averageCost = $totalQty > 0 ? $totalValue / $totalQty : $effectiveUnitCost; $effectiveUnitCost = $averageCost; } $transactedAt = $transactedAt ?: date('Y-m-d H:i:s'); $insert = $pdo->prepare("INSERT INTO inventory_transactions (item_id, transaction_type, reference, quantity, unit_cost, balance_after, notes, transacted_at, created_by_user_id) VALUES (:item_id, :transaction_type, :reference, :quantity, :unit_cost, :balance_after, :notes, :transacted_at, :created_by_user_id)"); $insert->execute([ ':item_id' => $itemId, ':transaction_type' => $type, ':reference' => $reference, ':quantity' => $delta, ':unit_cost' => $effectiveUnitCost, ':balance_after' => $newQty, ':notes' => $notes, ':transacted_at' => $transactedAt, ':created_by_user_id' => $userId ?: null, ]); $updateSql = "UPDATE inventory_items SET current_quantity = :current_quantity"; $updateParams = [ ':current_quantity' => $newQty, ':id' => $itemId, ]; if ($type === 'Ingreso' || $type === 'Reposicion') { $updateSql .= ", unit_cost = :unit_cost"; $updateParams[':unit_cost'] = $effectiveUnitCost; } $updateSql .= " WHERE id = :id"; $upd = $pdo->prepare($updateSql); $upd->execute($updateParams); $pdo->commit(); } catch (Throwable $e) { if ($pdo->inTransaction()) { $pdo->rollBack(); } throw $e; } } }
Coded With 💗 by
0x6ick