<?php
declare(strict_types=1);
namespace IdempiereMigrations;
use Doctrine\DBAL\Schema\Schema;
use Doctrine\Migrations\AbstractMigration;
/**
* Auto-generated Migration: Please modify to your needs!
*/
final class Version20221116031506 extends AbstractMigration
{
public function getDescription(): string
{
return '';
}
public function up(Schema $schema): void
{
// this up() migration is auto-generated, please modify it to your needs
$function = '$function$';
$this->addSql(
"CREATE OR REPLACE FUNCTION adempiere.productexclude(product_id numeric, role_id numeric, user_id numeric)
RETURNS boolean
LANGUAGE plpgsql
STABLE
AS {$function}
DECLARE
IsExclude CHAR(1);
BEGIN
--
SELECT supa.IsExclude
INTO IsExclude
FROM M_Product mp
JOIN SM_User_ProductAccess supa ON supa.M_Product_ID = mp.M_Product_ID
WHERE supa.M_Product_ID=Product_ID AND supa.ResponsibleType = 'R' AND supa.AD_Role_ID = Role_ID AND supa.IsActive = 'Y';
IF (IsExclude IS NOT NULL) THEN
IF (IsExclude = 'Y') THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
END IF;
--
SELECT supa.IsExclude
INTO IsExclude
FROM M_Product mp
JOIN SM_User_ProductAccess supa ON supa.M_Product_ID = mp.M_Product_ID
WHERE supa.M_Product_ID=Product_ID AND supa.ResponsibleType = 'H' AND supa.AD_User_ID = User_ID AND supa.IsActive = 'Y';
IF (IsExclude IS NOT NULL) THEN
IF (IsExclude = 'Y') THEN
RETURN TRUE;
ELSE
RETURN FALSE;
END IF;
END IF;
IF (IsExclude IS NULL) THEN
RETURN FALSE;
END IF;
END;
$function$
;"
);
}
public function down(Schema $schema): void
{
// this down() migration is auto-generated, please modify it to your needs
$this->addSql('DELETE FUNCTION TABLE adempiere.productexclude()');
}
}