« Back to History
kasab_entry_save_batch.php
|
20260722_120325.php
Initial Domain Snapshot
Copy Code
<?php require_once __DIR__ . '/modules/auth/page_acl.php'; $ctx = page_require_access('kasab_entry_add'); $pdo = $ctx['pdo']; $company_id = (int)$ctx['company_id']; $data = json_decode(file_get_contents('php://input'), true); /* ================= ORIGINAL INSERT (UNCHANGED) ================= */ $stmt = $pdo->prepare(" INSERT INTO kasab_entry (company_id, roll_type, entry_date, color, employee_id, rolls_json, weight_json) VALUES (:cid, :rt, :dt, :clr, :eid, :rj, :wj) "); $stmt->execute([ ':cid' => $company_id, ':rt' => $data['roll_type'], ':dt' => $data['entry_date'], ':clr' => $data['color'], ':eid' => (int)$data['contractor'], ':rj' => json_encode(['rolls'=>(int)$data['rolls']]), ':wj' => json_encode(['weights'=>$data['weights']]) ]); $entry_id = $pdo->lastInsertId(); // --- Activity Log --- require_once __DIR__ . '/helpers/activity_helper.php'; if (function_exists('log_activity')) { $u = $ctx['user'] ?? null; log_activity([ 'activity_type' => 'entry', 'module_name' => 'kasab_entry', 'action_name' => 'save', 'activity_note' => 'Kasab entry saved | Roll Type: ' . ($data['roll_type'] ?? '') . ', Color: ' . ($data['color'] ?? '') . ', Contractor: ' . ($data['contractor'] ?? '') . ', Rolls: ' . ($data['rolls'] ?? '') . ', Total Weight: ' . (isset($total_weight) ? $total_weight : '') . ', Entry Date: ' . ($data['entry_date'] ?? ''), 'reference_id' => $entry_id, ]); } /* ================= STOCK TABLE INSERT (NEW) ================= */ $rolls = (int)$data['rolls']; $weights = $data['weights']; $total_weight = array_sum($weights); $raw_count = count($weights); $total_rolls = $rolls * $raw_count; $stock = $pdo->prepare(" INSERT INTO kasab_stock_txn (company_id, txn_type, roll_type, color, rolls, weight, entry_date, employee_id, ref_entry_id) VALUES (:cid,'IN',:rt,:clr,:rolls,:weight,:dt,:eid,:ref) "); $stock->execute([ ':cid'=>$company_id, ':rt'=>$data['roll_type'], ':clr'=>$data['color'], ':rolls'=>$total_rolls, ':weight'=>$total_weight, ':dt'=>$data['entry_date'], ':eid'=>(int)$data['contractor'], ':ref'=>$entry_id ]); echo json_encode(['success'=>true]);