Files
crm.e5.pl/modules/EcmProducts/checkCode.php

45 lines
894 B
PHP
Raw Permalink Normal View History

2024-04-27 09:23:34 +02:00
<?php
$code = trim($_REQUEST['code']);
$db = $GLOBALS['db'];
if (strlen($code)<7) {
echo '0';
return;
}
$res = $db->fetchByAssoc($db->query("SELECT count(id) as c FROM ecmproducts WHERE UPPER(code)='".strtoupper($code)."'"));
if (intval($res['c'])!=0) {
echo '0';
return;
}
//pod podobny
$res = $db->fetchByAssoc($db->query("SELECT count(id) as c FROM ecmproducts WHERE UPPER(code) LIKE '".strtoupper($code)."%'"));
if (intval($res['c'])!=0) {
echo '2';
return;
}
$type = substr($code,0,2);
$res = $db->fetchByAssoc($db->query("
select code_number from ecmproducts where code like '$type%'
and deleted='0'
and product_active = '1'
order by code_number desc limit 0,1;
"));
$number = intval($res['code_number'])+1;
$c_number = intval(substr($code, -5));
if ($c_number > $number) {
echo '0';
return;
}
echo '1';
return;
?>