-- Copyright (c) 1997-now, NeoNova BV, The Netherlands. All rights Reserved.
--
-- This software is the copyrighted work of NeoNova BV.
-- Use of the software is subject to the general business terms and conditions of NeoNova BV
-- and its related transaction documents like license sheets or other written notices.#
-- Any reproduction or redistribution of the software not in accordance with the license terms
-- is expressly prohibited by law, and may result in severe civil and criminally penalties.
-- Violators will be prosecuted to the maximum extent possible.

BEGIN;

CREATE TABLE ringgroup (
 id serial,

 created timestamp with time zone not null default CURRENT_TIMESTAMP,
--HELP_EN_INFO:Creation Date
--HELP_EN_LONG:The date and time this record was created.
--HELP_NL_INFO:Datum aanmaak
--HELP_NL_LONG:De tijd en datum waarop dit is aangemaakt.

 lastupdate timestamp with time zone not null default CURRENT_TIMESTAMP,
--HELP_EN_INFO:Last Update
--HELP_EN_LONG:The date and time this record was updated.
--HELP_NL_INFO:Laatste wijziging
--HELP_NL_LONG:De tijd en datum van laatste wijziging.

 company integer NOT NULL default '1',
--HELP_EN_INFO:company
--HELP_EN_LONG:The company this Ring Group belongs to.
--HELP_NL_INFO:bedrijf
--HELP_NL_LONG:Het bedrijf waar deze gegevens bij horen.

  department integer NOT NULL default '1',
--HELP_EN_INFO:department
--HELP_EN_LONG:The department this Ring Group belongs to. 
--HELP_EN_LONG:The department manager can manage this Ring Group.
--HELP_NL_INFO:afdeling
--HELP_NL_LONG:De afdeling waar deze belgroep bij hoort. 
--HELP_NL_LONG:De afdelingsmanager mag deze belgroep beheren.

  department_only varchar(3) NOT NULL default 'no'
   CHECK (department_only IN ('yes', 'no')),
--HELP_EN_INFO:department members only
--HELP_EN_LONG:If set to "yes", only members of the department this Ring Group belongs to, 
--HELP_EN_LONG:are allowed to login to this Ring Group.
--HELP_NL_INFO:alleen afdelingsleden
--HELP_NL_INFO:Als dit op 'ja' staat, kunnen alleen leden van de afdeling waartoe 
--HELP_NL_INFO:waartoe deze belgroep behoort zich aanmelden voor deze belgroep.

 status varchar(8) NOT NULL default 'active'
   CHECK (status IN ('active', 'deleted')),
--HELP_EN_INFO:state
--HELP_EN_LONG:Ring Group status.
--HELP_NL_INFO:status
--HELP_NL_LONG:De status van deze belgroep. 

 name varchar(32) NOT NULL default '',
--HELP_EN_INFO:Ring Group name
--HELP_EN_LONG:The name for this Ring Group.
--HELP_NL_INFO:naam belgroep
--HELP_NL_LONG:De naam van deze belgroep.

 phoneline integer NOT NULL default '1',
--HELP_EN_INFO:Ring Group extension
--HELP_EN_LONG:The extension that connects to this Ring Group.
--HELP_NL_INFO:intern nummer
--HELP_NL_LONG:De extensie voor deze belgroep. 

 music varchar(64) NOT NULL default 'default',
--HELP_EN_INFO:music on hold
--HELP_EN_LONG:<p>Music on Hold for this Ring Group. Choose from the available categories. 'Default' (easy listening), 
--HELP_EN_LONG:'Ringing' (the tone you hear you are trying to call someone) and 'Beepbeep' 
--HELP_EN_LONG:are default Music on Hold types.</p>
--HELP_EN_LONG:<p>You can also upload your own MP3 files or streams.</p>
--HELP_NL_INFO:wachtmuziek
--HELP_NL_LONG:<p>Wachtmuziek voor deze belgroep. Kies uit de standaard categorieen 'Standaard' (easy listening), 
--HELP_NL_LONG:'Ringing' (dezelfde toon die je hoort als de telefoon aan de andere kant overgaat) of 'Beepbeep'.</p>
--HELP_NL_LONG:<p>U kunt ook uw eigen MP3-bestanden of MP3-streams uploaden. </p>

 showdisplay varchar(3) NOT NULL default 'no',
--HELP_EN_INFO:show on display
--HELP_EN_LONG:Show the name of the Ring Group on the phone display. Note that not all phone types support this feature. 
--HELP_NL_INFO:Toon op toestel
--HELP_NL_LONG:Toon de naam van de belgroep op de display van het telefoontoestel. Niet alle telefoontypes ondersteunen 
--HELP_NL_LONG:deze optie. Neem contact met uw telefoonleverancier voor meer informatie.

 strategy varchar(16) NOT NULL default 'ringall',
--HELP_EN_INFO:Ring Group calling strategy
--HELP_EN_LONG:Ringing strategy for distributing calls over agents. Default is set to 'Ring all available phones 
--HELP_EN_LONG:until one answers'.
--HELP_NL_INFO:strategie
--HELP_NL_LONG:De wijze waarop inkomende gesprekken worden verdeeld over de agenten. Standaard is dit 'laat alle 
--HELP_NL_LONG:toestellen overgaan tot iemand opneemt'.

 timeout integer default '45',
--HELP_EN_INFO:ringing timeout
--HELP_EN_LONG:The time in seconds of a ringing round.
--HELP_NL_INFO:rinkeltijd
--HELP_NL_LONG:De tijd dat de telefoons overgaan.

 completecaller integer NOT NULL default '0',
--HELP_EN_INFO:Completed by caller
--HELP_EN_LONG:Amount of calls hungup by the caller.
--HELP_NL_INFO:Beeindigd door beller
--HELP_NL_LONG:Aantal gesprekken beeindigd door de beller.

 completeagent integer NOT NULL default '0',
--HELP_EN_INFO:Completed by agent
--HELP_EN_LONG:Amount of calls hungup by the agent.
--HELP_NL_INFO:Beeindigd door agent
--HELP_NL_LONG:Aantal gesprekken beeindigd door de agent.

 agentdump integer NOT NULL default '0',
--HELP_EN_INFO:Dumped by agent
--HELP_EN_LONG:Amount of calls prematurely hungup by the agent.
--HELP_NL_INFO:Beeindigd door agent
--HELP_NL_LONG:Aantal gesprekken voortijdig beeindigd door de agent.

 agentconnect integer NOT NULL default '0',
--HELP_EN_INFO:Connected to agent
--HELP_EN_LONG:Amount of calls connected to an Ring Group agent.
--HELP_NL_INFO:Verbonden met agent
--HELP_NL_LONG:Aantal gesprekken dat is verbonden met een agent.

 abandoned integer NOT NULL default '0',
--HELP_EN_INFO:Abandoned
--HELP_EN_LONG:Amount of calls abandoned by callers.
--HELP_NL_INFO:Opgehangen
--HELP_NL_LONG:Aantal gesprekken dat is opgehangen tijdens het wachten.

 rejected integer NOT NULL default '0',
--HELP_EN_INFO:Rejected
--HELP_EN_LONG:Amount of calls rejected by Ring Group, for example maximum callers waiting reached.
--HELP_NL_INFO:Geweigerd
--HELP_NL_LONG:Aantal gesprekken dat is geweigerd door de belgroep, bijvoorbeeld door maximaal aantal wachtenden.

 PRIMARY KEY  (id)
);

CREATE INDEX ringgroup_name_index ON ringgroup (name);

GRANT UPDATE, SELECT, INSERT, DELETE ON ringgroup TO astium;
GRANT UPDATE, SELECT, INSERT, DELETE ON ringgroup_id_seq TO astium;
INSERT INTO ringgroup (name, company, phoneline) VALUES ('empty', '1', '1');
-- Copyright (c) 1997-now, NeoNova BV, The Netherlands. All rights Reserved.
--
-- This software is the copyrighted work of NeoNova BV.
-- Use of the software is subject to the general business terms and conditions of NeoNova BV
-- and its related transaction documents like license sheets or other written notices.#
-- Any reproduction or redistribution of the software not in accordance with the license terms
-- is expressly prohibited by law, and may result in severe civil and criminally penalties.
-- Violators will be prosecuted to the maximum extent possible.

CREATE TABLE ringgroup_contact (
 id serial,

 created timestamp with time zone not null default CURRENT_TIMESTAMP,
--HELP_EN_INFO:Creation Date
--HELP_EN_LONG:The date and time this record was created.
--HELP_NL_INFO:Datum aanmaak
--HELP_NL_LONG:De tijd en datum waarop dit is aangemaakt.

 lastupdate timestamp with time zone not null default CURRENT_TIMESTAMP,
--HELP_EN_INFO:Last Update
--HELP_EN_LONG:The date and time this record was updated.
--HELP_NL_INFO:Laatste wijziging
--HELP_NL_LONG:De tijd en datum van laatste wijziging.

 ringgroup integer NOT NULL default '1',
--HELP_EN_INFO:Ring Group
--HELP_EN_LONG:The Ring Group this contact is connected to.
--HELP_NL_INFO:belgroep
--HELP_NL_LONG:De belgroep waar deze persoon zich in bevindt.

 contact integer NOT NULL default '1',
--HELP_EN_INFO:contact
--HELP_EN_LONG:The agent for this Ring Group.
--HELP_NL_INFO:persoon
--HELP_NL_LONG:De medewerker voor deze belgroep.

 forwarding varchar(3) NOT NULL default 'no'
   CHECK (forwarding IN ('yes', 'no')),
--HELP_EN_INFO:honour forwarding/voicemail
--HELP_EN_LONG:<p>This enables forwarding settings on the extension of the Ring Group agent. </p> 
--HELP_EN_LONG:<p>Forwarding options are even active if an agent is logged out of his phone.</p> 
--HELP_EN_LONG:<p><b>WARNING</b>: Enabling this feature may cause undesired results. See the manual for more 
--HELP_EN_LONG:information and examples.</p>
--HELP_NL_INFO:doorschakelen/voicemail volgen
--HELP_NL_LONG:<p>Deze optie volgt doorschakelopties die zijn ingesteld bij de extensie van de belgroep agent.</p>
--HELP_NL_LONG:<p>Wanneer deze optie aanstaat, blijven doorschakelingen nog steeds actief, zelfs wanneer een agent  
--HELP_NL_LONG:is uitgelogd op zijn toestel.</p>
--HELP_NL_LONG:<p><b>WAARSCHUWING</b>: Deze optie kan ongewenste resultaten opleveren. Zie de manual voor meer  
--HELP_NL_LONG:informatie.</p>

 penalty integer NOT NULL default '1',
--HELP_EN_INFO:The priority group of a Ring Group agent
--HELP_EN_LONG:<p>The priority group of a Ring Group agent. Agents can be put in a group with a priority number. The group  
--HELP_EN_LONG:with highest priority (=1) gets calls first. When all agents of this group are busy at the same time 
--HELP_EN_LONG:or none of them are logged in, the next group of agents will be called.  
--HELP_EN_LONG:Highest priority = 1, lowest priority = 99. </p>
--HELP_NL_INFO:Prioriteit groep van belgroep agent
--HELP_NL_LONG:<p>De prioriteit groep van de agent. Agenten kunnen gegroepeerd worden met een prioriteitsnummer. De 
--HELP_NL_LONG:groep agenten met de hoogste prioriteit (=1) krijgen als eerste gesprekken 
--HELP_NL_LONG:te verwerken. Wanneer deze groep agenten allemaal tegelijkertijd bezet is of niet is ingelogd, worden   
--HELP_NL_LONG:agenten uit de volgende groep met een lagere prioriteit gebeld. Hoogste prioriteit = 1, 
--HELP_NL_LONG:laagste prioriteit = 99. </p>

 phoneline integer NOT NULL default '1',
--HELP_EN_INFO:extension
--HELP_EN_LONG:Extension of the user that is connected to this Ring Group.
--HELP_NL_INFO:intern nummer
--HELP_NL_LONG:De extensie van de medewerker die in deze belgroep zit.

 callstaken integer NOT NULL default '0',
--HELP_EN_INFO:Call Taken
--HELP_EN_LONG:The number of calls taken since the last Ring Group statistics reset.
--HELP_NL_INFO:Aantal gesprekken
--HELP_NL_LONG:Het aantal gevoerde gesprekken sinds de laatste reset. 

 lastcall timestamp with time zone NOT NULL default CURRENT_TIMESTAMP,
--HELP_EN_INFO:Last Call
--HELP_EN_LONG:The time of the last call made from this Ring Group.
--HELP_NL_INFO:Laatste gesprek
--HELP_NL_LONG:Datum/Tijd van het laatste gesprek uit deze belgroep.

 PRIMARY KEY  (id)
);

CREATE INDEX ringgroup_contact_ringgroup_index ON ringgroup_contact (ringgroup);
CREATE INDEX ringgroup_contact_contact_index ON ringgroup_contact (contact);

GRANT UPDATE, SELECT, INSERT, DELETE ON ringgroup_contact TO astium;
GRANT UPDATE, SELECT, INSERT, DELETE ON ringgroup_contact_id_seq TO astium;
INSERT INTO ringgroup_contact (ringgroup, contact) VALUES ('1', '1');

-- ringgroup_contact
ALTER TABLE ringgroup_contact ADD CONSTRAINT ringgroup_contact_ringgroup_constraint FOREIGN KEY (ringgroup) REFERENCES ringgroup (id);
ALTER TABLE ringgroup_contact ADD CONSTRAINT ringgroup_contact_phoneline_constraint FOREIGN KEY (phoneline) REFERENCES phoneline (id);
ALTER TABLE ringgroup_contact ADD CONSTRAINT ringgroup_contact_contact_constraint FOREIGN KEY (contact) REFERENCES contact (id);

-- ringgroup
ALTER TABLE ringgroup ADD CONSTRAINT ringgroup_company_constraint FOREIGN KEY (company) REFERENCES company (id);
ALTER TABLE ringgroup ADD CONSTRAINT ringgroup_phoneline_constraint FOREIGN KEY (phoneline) REFERENCES phoneline (id);

COMMIT;

