'.__('You don\'t have enough privileges to access this area!').'');
}
// check if there is any active stock take proccess
$stk_query = $dbs->query('SELECT * FROM stock_take WHERE is_active=1');
if ($stk_query->num_rows < 1) {
echo '
'.__('NO stock taking proccess initialized yet!').'
';
die();
}
// file upload
if (isset($_POST['stUpload']) && isset($_FILES['stFile'])) {
require SIMBIO.'simbio_FILE/simbio_file_upload.inc.php';
// create upload object
$upload = new simbio_file_upload();
$upload->setAllowableFormat(array('.txt'));
$upload->setMaxSize($sysconf['max_upload']*1024);
$upload->setUploadDir(UPLOAD);
// upload the file and change all space characters to underscore
$upload_status = $upload->doUpload('stFile');
if ($upload_status == UPLOAD_SUCCESS) {
// write log
utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'stock_take', $_SESSION['realname'].' upload stock take file '.$upload->new_filename);
// open file
$stfile = @fopen(UPLOAD.$upload->new_filename, 'r');
if (!$stfile) {
echo '';
exit();
}
// start loop
$i = 0;
while (!feof($stfile)) {
$curr_time = date('Y-m-d H:i:s');
$item_code = fgetss($stfile, 512);
$item_code = trim($item_code);
if (!$item_code) {
continue;
}
// check item status first
$item_check = $dbs->query("SELECT * FROM stock_take_item WHERE item_code='$item_code'");
$item_check_d = $item_check->fetch_assoc();
if ($item_check->num_rows > 0) {
if ($item_check_d['status'] == 'l') {
// record to log
utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'stock_take', 'Stock Take ERROR : Item '.$item_check_d['title'].' ('.$item_check_d['item_code'].') is currently ON LOAN (from uploaded file '.$upload->new_filename.')');
continue;
} else if ($item_check_d['status'] == 'e') {
continue;
} else {
$update = @$dbs->query("UPDATE LOW_PRIORITY stock_take_item SET status='e', checked_by='".$_SESSION['realname']."', last_update='".$curr_time."' WHERE item_code='$item_code'");
$update = @$dbs->query("UPDATE LOW_PRIORITY stock_take SET total_item_lost=total_item_lost-1 WHERE is_active=1");
$i++;
}
} else {
// record to log
utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'stock_take', 'Stock Take ERROR : Item Code '.$item_code.' doesnt exists in stock take data. Invalid Item Code OR Maybe out of Stock Take range (from uploaded file '.$upload->new_filename.')');
}
}
fclose($stfile);
// message
echo '';
} else {
// write log
utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'stock_take', 'ERROR : '.$_SESSION['realname'].' FAILED TO upload stock take file '.$upload->new_filename.', with error ('.$upload->error.')');
echo '';
}
exit();
}
?>