Warning: chmod(): Operation not permitted in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [0] in function chmod in /var/www/hopeinstoughton_www/wp-content/plugins/simple-universal-google-analytics/main.php on line 8 [1] in function include_once in /var/www/hopeinstoughton_www/wp-settings.php on line 560 [2] in function require_once in /var/www/hopeinstoughton_www/wp-config.php on line 85 [3] in function require_once in /var/www/hopeinstoughton_www/wp-load.php on line 50 [4] in function require_once in /var/www/hopeinstoughton_www/wp-blog-header.php on line 13 [5] in function require in /var/www/hopeinstoughton_www/index.php on line 17
| Server IP : 94.177.8.99 / Your IP : 216.73.217.165 Web Server : Apache/2.4.58 (Ubuntu) System : Linux aries 6.8.0-134-generic #134-Ubuntu SMP PREEMPT_DYNAMIC Fri Jun 26 18:43:11 UTC 2026 x86_64 User : www-data ( 33) PHP Version : 8.1.34 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/hopeinstoughton_books/core/models/ |
Upload File : |
<?php
class Stocktake_Model extends Model {
function __loclist(&$ITEM, &$param) {
$param[$ITEM['dl_id']] = $ITEM['dl_desc'];
return 0;
}
function __selectitem(&$ITEM, &$param) {
$name = ip_asTitle($ITEM);
$barcode = $ITEM['ds_barcode'];
$param[$barcode] = substr($barcode, 6, 5) . '. ' . $name;
}
public function GenerateBarcodeList() {
global $DATABASE;
$sql = <<<BLOCK
select a1.ba_name as ba_name1,a2.ba_name as ba_name2,ds_barcode,bt_title
from dt_stock
left outer join dt_title on ds_title=bt_id
left outer join dt_author as a1 on a1.ba_id=bt_author1
left outer join dt_author as a2 on a2.ba_id=bt_author2
where ds_out < '1991-01-01'
order by ds_barcode
BLOCK;
$result = $DATABASE->Query($sql, NULL, array($this, '__selectitem'), array());
DbErr($DATABASE);
return $result;
}
function LookupTitle($bkid) {
global $DATABASE;
$sql = <<<BLOCK
select a1.ba_name as ba_name1,a2.ba_name as ba_name2,bt_title
from dt_title
left outer join dt_author as a1 on a1.ba_id=bt_author1
left outer join dt_author as a2 on a2.ba_id=bt_author2
where bt_id=%d
BLOCK;
$ITEM = $DATABASE->Lookup($sql, $bkid);
return $ITEM['__existing'] ? ip_AsTitle($ITEM) : '(missing)';
}
function GenerateLocationList($full = 1) {
global $DATABASE;
$sql = 'select dl_id,dl_desc from dt_location order by dl_desc';
if ($full) {
$res = array('' => 'please select the location');
} else {
$res = array();
}
$res = $DATABASE->Query($sql, '', array($this, '__loclist'), $res);
DBerr($DATABASE);
return $res;
}
public function GetTransactionHistory($barcode, $DATA, &$flags) {
global $DATABASE;
// get first added date, and last stocktake date
$dadded = gmdate('Y.m.d', strtotime($DATA['ds_in'] . 'Z'));
$dstock = gmdate('Y.m.d', strtotime($DATA['ds_stocktake'] . 'Z'));
$sql = <<<BLOCK
select *
from dt_trant
left outer join dt_tranh on dt_tran=bh_id
left outer join dt_member on bh_member=bm_id
where dt_stockcode=%s
order by dt_timestamp desc
BLOCK;
// where dt_stockcode=$dbarcode and bh_type<>'0'
$result = $DATABASE->Query($sql, $barcode, array($this, '__history'),
array('out' => '', 'full' => date('Y.m.d H:i:s', strtotime($DATA['ds_stocktake'] . 'Z')),
'stocktake' => $dstock, 'in' => $dadded, 'flags' => 0, 'count' => 0));
DbErr($DATABASE);
$flags = $result['flags'];
$result['out'] .= $this->_checkDate('1900-01-01', $result['stocktake'], 'stocktake', $result['full']);
$result['out'] .= $this->_checkDate('1900-01-01', $result['in'], 'added to library');
return $result['out'];
}
function _checkDate($itemdate, &$actiondate, $status, $fullactiondate = '') {
if ($actiondate < '2000-01-01') $actiondate = '';
if ($actiondate != '') {
if ($actiondate > $itemdate) {
if ($fullactiondate != '') $actiondate = "<span title=\"$fullactiondate\">$actiondate</span>";
$line = "<td>$actiondate</td><td>$status</td>";
$actiondate = '';
return "<tR>$line</tr>\n";
}
}
return '';
}
function __history(&$ITEM, &$param) {
// date, status (added, borrowed, stocktake, sold, writeoff), customer
$surname = ip_AsMember($ITEM);
$param['count']++;
$status = $ITEM['bh_type'];
$purchase = intval($ITEM['dt_purchase']);
if ($status == 'X') {
$desc = 'stock write-off';
if ($param['count'] == 1) $param['flags'] |= 1;
} elseif ($purchase) {
$desc = 'sold';
if ($param['count'] == 1) $param['flags'] |= 2;
} else {
$desc = 'borrowed';
}
$date = strtotime($ITEM['bh_datetime'] . ' Z');
$date = date('Y.m.d', $date);
$stocktake = $this->_checkDate($date, $param['stocktake'], 'stocktake', $param['full']);
if ($stocktake != '') $param['flags'] &= ~2; // still present - so not sold
$param['out'] .= $stocktake;
$line = "<td>$date</td><td>$desc</td><td>$surname</td>";
$param['out'] .= "<tr>$line</tR>\n";
return 0;
}
public function webform_Stocktake() {
$webform = new webform('');
$f = $webform->AddField_Hidden('barcode');
$f = $webform->AddField_List('location', '&Location', 1);
$f->SetList($this->GenerateLocationList());
return $webform;
}
public function Stocktake_ProcessBarcode($barcode, $location) {
global $DATABASE;
$dt = gmdate('Y-m-d H:i:s');
if ($location) {
$DATABASE->Query("update dt_stock set ds_member=0,ds_stocktake=%s,ds_location=%d where ds_barcode=%s",
array($dt, $location, $barcode), '', 0);
} else {
$DATABASE->Query("update dt_stock set ds_member=0,ds_stocktake=%s where ds_barcode=%s", // leave location unchanged
array($dt, $barcode), '', 0);
}
// If we have found the book during a stocktake, assume that it has been returned
$DATABASE->Query("update dt_trant set dt_returned=1 where dt_stockcode=%s and dt_returned=0", $barcode, '', 0);
}
}