'.__('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) {
echo '
'.__('NO stock taking proccess running!').'
';
die();
}
if (isset($_POST['confirmFinish'])) {
set_time_limit(0);
// get currently active stock take name
$stk_take_q = $dbs->query('SELECT stock_take_name, stock_take_id FROM stock_take WHERE is_active=1');
$stk_take_d = $stk_take_q->fetch_row();
// update stock take finish time
$finish_time_q = $dbs->query('UPDATE stock_take SET end_date=NOW() WHERE is_active=1');
$stk_take_report_filename = strtolower(str_replace(' ', '_', trim($stk_take_d[0]))).'_report.html';
if ($dbs->affected_rows) {
// purge item data
if (isset($_POST['purge']) AND !empty($_POST['purge'])) {
// purge data in item table
$purge_item_q = $dbs->query('DELETE FROM item WHERE item_id IN (SELECT item_id FROM stock_take_item WHERE status=\'m\')');
// purge data in loan table
$purge_loan_q = $dbs->query('DELETE FROM loan WHERE item_code IN (SELECT item_code FROM stock_take_item WHERE status=\'m\')');
}
$update_item_status_to_missing = $dbs->query('UPDATE item SET item_status_id=\'MIS\' WHERE item_code IN (SELECT item_code FROM stock_take_item WHERE status=\'m\')');
// start output buffering content for report generation
ob_start();
echo ''.$stk_take_d[0].' Report';
echo ''."\n";
echo ''."\n";
echo ''."\n";
echo '';
echo ''."\n";
define('REPECT_INCLUDE', true);
// stock take general report
echo ''.$stk_take_d[0].' - Stock Take Report
';
include MDLBS.'stock_take/st_report.php';
// cell row class
$cellClass = 'alterCell';
// stock take lost item list
$lost_item_q = $dbs->query('SELECT item_code, title, classification, coll_type_name, call_number FROM stock_take_item WHERE status=\'m\'');
if ($lost_item_q->num_rows > 0) {
echo '
';
echo 'LOST Item list
';
echo '';
echo '';
echo '
';
echo '
'."\n";
while ($lost_item_d = $lost_item_q->fetch_row()) {
$cellClass = ($cellClass == 'alterCell')?'alterCell2':'alterCell';
echo ''.$lost_item_d[0].' |
'.$lost_item_d[1].' |
'.$lost_item_d[2].' | ';
echo '
'."\n";
}
echo '
'."\n";
unset($lost_item_q);
}
// stock take error logs
$error_log_q = $dbs->query('SELECT log_date, log_msg FROM system_log WHERE log_location=\'stock_take\' AND log_msg LIKE \'Stock Take ERROR%\'');
if ($error_log_q->num_rows > 0) {
echo '
';
echo 'Stock Take Error Logs
';
echo '';
echo '';
echo '
';
echo '
';
while ($error_log_d = $error_log_q->fetch_row()) {
$cellClass = ($cellClass == 'alterCell')?'alterCell2':'alterCell';
echo '';
echo ''.$error_log_d[0].' | '.$error_log_d[1].' | ';
echo '
';
}
echo '
';
unset($error_log_q);
}
echo '';
$html_str = ob_get_clean();
// put html to file
$file_write = @file_put_contents(REPBS.$stk_take_report_filename, $html_str);
if ($file_write) {
// open result in new window
echo '';
} else { utility::jsAlert('ERROR! Stock take report failed to generate, possibly because '.REPBS.' directory is not writable'); }
// update
$update_st_q = $dbs->query("UPDATE stock_take SET report_file='$stk_take_report_filename' WHERE is_active=1");
// set currently active stock take process to unactive
$inactive_q = $dbs->query('UPDATE stock_take SET is_active=0');
// clean all current stock take error log
$error_log_q = $dbs->query('DELETE FROM system_log WHERE log_location=\'stock_take\' AND log_msg LIKE \'Stock Take ERROR%\'');
// write log
utility::writeLogs($dbs, 'staff', $_SESSION['uid'], 'stock_take', $_SESSION['realname'].' finish stock take ('.$stk_take_d[0].') from address '.$_SERVER['REMOTE_ADDR']);
// send an alert
echo '';
}
exit();
} else {
?>
submit_button_attr = 'value="'.__('Finish Stock Take').'" class="button btn btn-delete btn-danger"';
// form table attributes
$form->table_attr = 'align="center" id="dataList" cellpadding="5" cellspacing="0"';
$form->table_header_attr = 'class="alterCell" style="font-weight: bold;"';
$form->table_content_attr = 'class="alterCell2"';
/* Form Element(s) */
// purge lost item
$purge_options[] = array('1', __('Yes'));
$form->addCheckBox('purge', __('Purge Lost Item'), $purge_options);
// hidden item
$form->addHidden('confirmFinish', 'true');
// print out the object
echo $form->printOut();
}