migrations/Idempiere/Version20221116031506.php line 1

Open in your IDE?
  1. <?php
  2. declare(strict_types=1);
  3. namespace IdempiereMigrations;
  4. use Doctrine\DBAL\Schema\Schema;
  5. use Doctrine\Migrations\AbstractMigration;
  6. /**
  7.  * Auto-generated Migration: Please modify to your needs!
  8.  */
  9. final class Version20221116031506 extends AbstractMigration
  10. {
  11.     public function getDescription(): string
  12.     {
  13.         return '';
  14.     }
  15.     public function up(Schema $schema): void
  16.     {
  17.         // this up() migration is auto-generated, please modify it to your needs
  18.         $function '$function$';
  19.         $this->addSql(
  20.             "CREATE OR REPLACE FUNCTION adempiere.productexclude(product_id numeric, role_id numeric, user_id numeric)
  21.                 RETURNS boolean
  22.                 LANGUAGE plpgsql
  23.                 STABLE
  24.             AS {$function}
  25.             DECLARE
  26.                 IsExclude CHAR(1);
  27.             BEGIN
  28.                 --
  29.                 SELECT    supa.IsExclude
  30.                 INTO    IsExclude
  31.                 FROM M_Product mp
  32.                 JOIN SM_User_ProductAccess supa ON supa.M_Product_ID = mp.M_Product_ID
  33.                 WHERE supa.M_Product_ID=Product_ID AND supa.ResponsibleType = 'R' AND supa.AD_Role_ID = Role_ID AND supa.IsActive = 'Y';
  34.                 
  35.                 IF (IsExclude IS NOT NULL) THEN
  36.                     IF (IsExclude = 'Y') THEN 
  37.                         RETURN TRUE;
  38.                     ELSE
  39.                         RETURN FALSE;
  40.                     END IF;
  41.                 END IF;
  42.                 
  43.                 --
  44.                 SELECT    supa.IsExclude
  45.                 INTO    IsExclude
  46.                 FROM M_Product mp
  47.                 JOIN SM_User_ProductAccess supa ON supa.M_Product_ID = mp.M_Product_ID
  48.                 WHERE supa.M_Product_ID=Product_ID AND supa.ResponsibleType = 'H' AND supa.AD_User_ID = User_ID AND supa.IsActive = 'Y';
  49.                 IF (IsExclude IS NOT NULL) THEN
  50.                     IF (IsExclude = 'Y') THEN 
  51.                         RETURN TRUE;
  52.                     ELSE
  53.                         RETURN FALSE;
  54.                     END IF;
  55.                 END IF;
  56.                 IF (IsExclude IS NULL) THEN
  57.                     RETURN FALSE;
  58.                 END IF;
  59.             END;
  60.             $function$
  61.             ;"
  62.         );
  63.     }
  64.     public function down(Schema $schema): void
  65.     {
  66.         // this down() migration is auto-generated, please modify it to your needs
  67.         $this->addSql('DELETE FUNCTION TABLE adempiere.productexclude()');
  68.     }
  69. }