-- Name: employee_banking_employee_banking_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE employee_banking_employee_banking_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.employee_banking_employee_banking_id_seq OWNER TO postgres;

--
-- Name: employee_banking_employee_banking_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE employee_banking_employee_banking_id_seq OWNED BY employee_banking.employee_banking_id;


--
-- Name: employee_cases; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE employee_cases (
    employee_case_id integer NOT NULL,
    case_type_id integer,
    entity_id integer,
    org_id integer,
    narrative character varying(240),
    case_date date,
    complaint text,
    case_action text,
    completed boolean DEFAULT false NOT NULL,
    details text
);


ALTER TABLE public.employee_cases OWNER TO postgres;

--
-- Name: employee_cases_employee_case_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE employee_cases_employee_case_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.employee_cases_employee_case_id_seq OWNER TO postgres;

--
-- Name: employee_cases_employee_case_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE employee_cases_employee_case_id_seq OWNED BY employee_cases.employee_case_id;


--
-- Name: employee_leave; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE employee_leave (
    employee_leave_id integer NOT NULL,
    entity_id integer,
    contact_entity_id integer,
    leave_type_id integer,
    org_id integer,
    leave_from date NOT NULL,
    leave_to date NOT NULL,
    leave_days real NOT NULL,
    start_half_day boolean DEFAULT false NOT NULL,
    end_half_day boolean DEFAULT false NOT NULL,
    special_request boolean DEFAULT false NOT NULL,
    application_date timestamp without time zone DEFAULT now(),
    approve_status character varying(16) DEFAULT 'Draft'::character varying NOT NULL,
    workflow_table_id integer,
    action_date timestamp without time zone,
    completed boolean DEFAULT false NOT NULL,
    narrative character varying(240),
    details text
);


ALTER TABLE public.employee_leave OWNER TO postgres;

--
-- Name: employee_leave_employee_leave_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE employee_leave_employee_leave_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.employee_leave_employee_leave_id_seq OWNER TO postgres;

--
-- Name: employee_leave_employee_leave_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE employee_leave_employee_leave_id_seq OWNED BY employee_leave.employee_leave_id;


--
-- Name: employee_leave_types; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE employee_leave_types (
    employee_leave_type_id integer NOT NULL,
    entity_id integer,
    leave_type_id integer,
    org_id integer,
    leave_balance real DEFAULT 0 NOT NULL,
    leave_starting date DEFAULT ('now'::text)::date NOT NULL,
    details text
);


ALTER TABLE public.employee_leave_types OWNER TO postgres;

--
-- Name: employee_leave_types_employee_leave_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE employee_leave_types_employee_leave_type_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.employee_leave_types_employee_leave_type_id_seq OWNER TO postgres;

--
-- Name: employee_leave_types_employee_leave_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE employee_leave_types_employee_leave_type_id_seq OWNED BY employee_leave_types.employee_leave_type_id;


--
-- Name: employee_month; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE employee_month (
    employee_month_id integer NOT NULL,
    entity_id integer NOT NULL,
    period_id integer NOT NULL,
    bank_branch_id integer NOT NULL,
    pay_group_id integer NOT NULL,
    department_role_id integer NOT NULL,
    currency_id integer,
    org_id integer,
    exchange_rate real DEFAULT 1 NOT NULL,
    bank_account character varying(32),
    basic_pay double precision DEFAULT 0 NOT NULL,
    details text
);


ALTER TABLE public.employee_month OWNER TO postgres;

--
-- Name: employee_month_employee_month_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE employee_month_employee_month_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.employee_month_employee_month_id_seq OWNER TO postgres;

--
-- Name: employee_month_employee_month_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE employee_month_employee_month_id_seq OWNED BY employee_month.employee_month_id;


--
-- Name: employee_objectives; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE employee_objectives (
    employee_objective_id integer NOT NULL,
    entity_id integer,
    org_id integer,
    employee_objective_name character varying(320) NOT NULL,
    objective_date date NOT NULL,
    approve_status character varying(16) DEFAULT 'Draft'::character varying NOT NULL,
    workflow_table_id integer,
    application_date timestamp without time zone DEFAULT now(),
    action_date timestamp without time zone,
    supervisor_comments text,
    details text
);


ALTER TABLE public.employee_objectives OWNER TO postgres;

--
-- Name: employee_objectives_employee_objective_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE employee_objectives_employee_objective_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.employee_objectives_employee_objective_id_seq OWNER TO postgres;

--
-- Name: employee_objectives_employee_objective_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE employee_objectives_employee_objective_id_seq OWNED BY employee_objectives.employee_objective_id;


--
-- Name: employee_overtime; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE employee_overtime (
    employee_overtime_id integer NOT NULL,
    employee_month_id integer NOT NULL,
    org_id integer,
    overtime_date date NOT NULL,
    overtime double precision NOT NULL,
    overtime_rate double precision NOT NULL,
    application_date timestamp without time zone DEFAULT now(),
    approve_status character varying(16) DEFAULT 'draft'::character varying NOT NULL,
    workflow_table_id integer,
    action_date timestamp without time zone,
    narrative character varying(240),
    details text
);


ALTER TABLE public.employee_overtime OWNER TO postgres;

--
-- Name: employee_overtime_employee_overtime_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE employee_overtime_employee_overtime_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.employee_overtime_employee_overtime_id_seq OWNER TO postgres;

--
-- Name: employee_overtime_employee_overtime_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE employee_overtime_employee_overtime_id_seq OWNED BY employee_overtime.employee_overtime_id;


--
-- Name: employee_per_diem; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE employee_per_diem (
    employee_per_diem_id integer NOT NULL,
    employee_month_id integer NOT NULL,
    currency_id integer,
    org_id integer,
    travel_date date NOT NULL,
    return_date date NOT NULL,
    days_travelled integer NOT NULL,
    per_diem double precision DEFAULT 0 NOT NULL,
    cash_paid double precision DEFAULT 0 NOT NULL,
    tax_amount double precision DEFAULT 0 NOT NULL,
    full_amount double precision DEFAULT 0 NOT NULL,
    exchange_rate real DEFAULT 1 NOT NULL,
    travel_to character varying(240),
    post_account character varying(32),
    application_date timestamp without time zone DEFAULT now(),
    approve_status character varying(16) DEFAULT 'draft'::character varying NOT NULL,
    workflow_table_id integer,
    action_date timestamp without time zone,
    completed boolean DEFAULT false NOT NULL,
    details text
);


ALTER TABLE public.employee_per_diem OWNER TO postgres;

--
-- Name: employee_per_diem_employee_per_diem_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE employee_per_diem_employee_per_diem_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.employee_per_diem_employee_per_diem_id_seq OWNER TO postgres;

--
-- Name: employee_per_diem_employee_per_diem_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE employee_per_diem_employee_per_diem_id_seq OWNED BY employee_per_diem.employee_per_diem_id;


--
-- Name: employee_tax_types; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE employee_tax_types (
    employee_tax_type_id integer NOT NULL,
    employee_month_id integer NOT NULL,
    tax_type_id integer NOT NULL,
    org_id integer,
    tax_identification character varying(50),
    in_tax boolean DEFAULT false NOT NULL,
    amount double precision DEFAULT 0 NOT NULL,
    additional double precision DEFAULT 0 NOT NULL,
    employer double precision DEFAULT 0 NOT NULL,
    exchange_rate real DEFAULT 1 NOT NULL,
    narrative character varying(240)
);


ALTER TABLE public.employee_tax_types OWNER TO postgres;

--
-- Name: employee_tax_types_employee_tax_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE employee_tax_types_employee_tax_type_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.employee_tax_types_employee_tax_type_id_seq OWNER TO postgres;

--
-- Name: employee_tax_types_employee_tax_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE employee_tax_types_employee_tax_type_id_seq OWNED BY employee_tax_types.employee_tax_type_id;


--
-- Name: employee_trainings; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE employee_trainings (
    employee_training_id integer NOT NULL,
    training_id integer,
    entity_id integer,
    org_id integer,
    narrative character varying(240),
    completed boolean DEFAULT false NOT NULL,
    application_date timestamp without time zone DEFAULT now(),
    approve_status character varying(16) DEFAULT 'Draft'::character varying NOT NULL,
    workflow_table_id integer,
    action_date timestamp without time zone,
    details text
);


ALTER TABLE public.employee_trainings OWNER TO postgres;

--
-- Name: employee_trainings_employee_training_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE employee_trainings_employee_training_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.employee_trainings_employee_training_id_seq OWNER TO postgres;

--
-- Name: employee_trainings_employee_training_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE employee_trainings_employee_training_id_seq OWNED BY employee_trainings.employee_training_id;


--
-- Name: employees; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE employees (
    entity_id integer NOT NULL,
    department_role_id integer NOT NULL,
    bank_branch_id integer NOT NULL,
    disability_id integer,
    employee_id character varying(12) NOT NULL,
    pay_scale_id integer NOT NULL,
    pay_scale_step_id integer,
    pay_group_id integer NOT NULL,
    location_id integer NOT NULL,
    currency_id integer NOT NULL,
    org_id integer NOT NULL,
    person_title character varying(7),
    surname character varying(50) NOT NULL,
    first_name character varying(50) NOT NULL,
    middle_name character varying(50),
    date_of_birth date,
    dob_email date DEFAULT '2016-01-01'::date,
    gender character varying(1),
    phone character varying(120),
    nationality character(2) NOT NULL,
    nation_of_birth character(2),
    place_of_birth character varying(50),
    marital_status character varying(2),
    appointment_date date,
    current_appointment date,
    exit_date date,
    contract boolean DEFAULT false NOT NULL,
    contract_period integer NOT NULL,
    employment_terms character varying(320),
    identity_card character varying(50),
    basic_salary real NOT NULL,
    bank_account character varying(32),
    picture_file character varying(32),
    active boolean DEFAULT true NOT NULL,
    language character varying(320),
    desg_code character varying(16),
    inc_mth character varying(16),
    previous_sal_point character varying(16),
    current_sal_point character varying(16),
    halt_point character varying(16),
    bio_metric_number character varying(32),
    height real,
    weight real,
    blood_group character varying(3),
    allergies character varying(320),
    field_of_study text,
    interests text,
    objective text,
    details text
);


ALTER TABLE public.employees OWNER TO postgres;

--
-- Name: employment; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE employment (
    employment_id integer NOT NULL,
    entity_id integer,
    org_id integer,
    date_from date NOT NULL,
    date_to date,
    employers_name character varying(240),
    position_held character varying(240),
    details text
);


ALTER TABLE public.employment OWNER TO postgres;

--
-- Name: employment_employment_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE employment_employment_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.employment_employment_id_seq OWNER TO postgres;

--
-- Name: employment_employment_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE employment_employment_id_seq OWNED BY employment.employment_id;


--
-- Name: entity_subscriptions; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE entity_subscriptions (
    entity_subscription_id integer NOT NULL,
    entity_type_id integer NOT NULL,
    entity_id integer NOT NULL,
    subscription_level_id integer NOT NULL,
    org_id integer,
    details text
);


ALTER TABLE public.entity_subscriptions OWNER TO postgres;

--
-- Name: entity_subscriptions_entity_subscription_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE entity_subscriptions_entity_subscription_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.entity_subscriptions_entity_subscription_id_seq OWNER TO postgres;

--
-- Name: entity_subscriptions_entity_subscription_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE entity_subscriptions_entity_subscription_id_seq OWNED BY entity_subscriptions.entity_subscription_id;


--
-- Name: entity_types; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE entity_types (
    entity_type_id integer NOT NULL,
    use_key_id integer NOT NULL,
    org_id integer,
    entity_type_name character varying(50) NOT NULL,
    entity_role character varying(240),
    start_view character varying(120),
    group_email character varying(120),
    description text,
    details text
);


ALTER TABLE public.entity_types OWNER TO postgres;

--
-- Name: entity_types_entity_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE entity_types_entity_type_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.entity_types_entity_type_id_seq OWNER TO postgres;

--
-- Name: entity_types_entity_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE entity_types_entity_type_id_seq OWNED BY entity_types.entity_type_id;


--
-- Name: entitys; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE entitys (
    entity_id integer NOT NULL,
    entity_type_id integer NOT NULL,
    use_key_id integer NOT NULL,
    org_id integer NOT NULL,
    entity_name character varying(120) NOT NULL,
    user_name character varying(120) NOT NULL,
    primary_email character varying(120),
    primary_telephone character varying(50),
    super_user boolean DEFAULT false NOT NULL,
    entity_leader boolean DEFAULT false NOT NULL,
    no_org boolean DEFAULT false NOT NULL,
    function_role character varying(240),
    date_enroled timestamp without time zone DEFAULT now(),
    is_active boolean DEFAULT true,
    entity_password character varying(64) NOT NULL,
    first_password character varying(64) NOT NULL,
    new_password character varying(64),
    start_url character varying(64),
    is_picked boolean DEFAULT false NOT NULL,
    details text,
    attention character varying(50),
    credit_limit real DEFAULT 0,
    account_id integer,
    bio_code character varying(50)
);


ALTER TABLE public.entitys OWNER TO postgres;

--
-- Name: entitys_entity_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE entitys_entity_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.entitys_entity_id_seq OWNER TO postgres;

--
-- Name: entitys_entity_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE entitys_entity_id_seq OWNED BY entitys.entity_id;


--
-- Name: entry_forms; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE entry_forms (
    entry_form_id integer NOT NULL,
    org_id integer,
    entity_id integer,
    form_id integer,
    entered_by_id integer,
    application_date timestamp without time zone DEFAULT now() NOT NULL,
    completion_date timestamp without time zone,
    approve_status character varying(16) DEFAULT 'Draft'::character varying NOT NULL,
    workflow_table_id integer,
    action_date timestamp without time zone,
    narrative character varying(240),
    answer text,
    sub_answer text,
    details text
);


ALTER TABLE public.entry_forms OWNER TO postgres;

--
-- Name: entry_forms_entry_form_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE entry_forms_entry_form_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.entry_forms_entry_form_id_seq OWNER TO postgres;

--
-- Name: entry_forms_entry_form_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE entry_forms_entry_form_id_seq OWNED BY entry_forms.entry_form_id;


--
-- Name: evaluation_points; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE evaluation_points (
    evaluation_point_id integer NOT NULL,
    job_review_id integer,
    review_point_id integer,
    objective_id integer,
    career_development_id integer,
    org_id integer,
    points integer DEFAULT 1 NOT NULL,
    grade character varying(2),
    narrative text,
    reviewer_points integer DEFAULT 1 NOT NULL,
    reviewer_grade character varying(2),
    reviewer_narrative text,
    details text
);


ALTER TABLE public.evaluation_points OWNER TO postgres;

--
-- Name: evaluation_points_evaluation_point_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE evaluation_points_evaluation_point_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.evaluation_points_evaluation_point_id_seq OWNER TO postgres;

--
-- Name: evaluation_points_evaluation_point_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE evaluation_points_evaluation_point_id_seq OWNED BY evaluation_points.evaluation_point_id;


--
-- Name: farm_fields; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE farm_fields (
    farm_field_id integer NOT NULL,
    org_id integer,
    farm_field_name character varying(50),
    details text
);


ALTER TABLE public.farm_fields OWNER TO postgres;

--
-- Name: farm_fields_farm_field_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE farm_fields_farm_field_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.farm_fields_farm_field_id_seq OWNER TO postgres;

--
-- Name: farm_fields_farm_field_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE farm_fields_farm_field_id_seq OWNED BY farm_fields.farm_field_id;


--
-- Name: fields; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE fields (
    field_id integer NOT NULL,
    org_id integer,
    form_id integer,
    field_name character varying(50),
    question text,
    field_lookup text,
    field_type character varying(25) NOT NULL,
    field_class character varying(25),
    field_bold character(1) DEFAULT '0'::bpchar NOT NULL,
    field_italics character(1) DEFAULT '0'::bpchar NOT NULL,
    field_order integer NOT NULL,
    share_line integer,
    field_size integer DEFAULT 25 NOT NULL,
    label_position character(1) DEFAULT 'L'::bpchar,
    field_fnct character varying(120),
    manditory character(1) DEFAULT '0'::bpchar NOT NULL,
    show character(1) DEFAULT '1'::bpchar,
    tab character varying(25),
    details text
);


ALTER TABLE public.fields OWNER TO postgres;

--
-- Name: fields_field_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE fields_field_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.fields_field_id_seq OWNER TO postgres;

--
-- Name: fields_field_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE fields_field_id_seq OWNED BY fields.field_id;


--
-- Name: fiscal_years; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE fiscal_years (
    fiscal_year_id integer NOT NULL,
    fiscal_year character varying(9) NOT NULL,
    org_id integer,
    fiscal_year_start date NOT NULL,
    fiscal_year_end date NOT NULL,
    year_opened boolean DEFAULT true NOT NULL,
    year_closed boolean DEFAULT false NOT NULL,
    details text
);


ALTER TABLE public.fiscal_years OWNER TO postgres;

--
-- Name: fiscal_years_fiscal_year_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE fiscal_years_fiscal_year_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.fiscal_years_fiscal_year_id_seq OWNER TO postgres;

--
-- Name: fiscal_years_fiscal_year_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE fiscal_years_fiscal_year_id_seq OWNED BY fiscal_years.fiscal_year_id;


--
-- Name: follow_up; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE follow_up (
    follow_up_id integer NOT NULL,
    lead_item_id integer,
    entity_id integer,
    org_id integer,
    create_time timestamp without time zone DEFAULT now() NOT NULL,
    follow_date date DEFAULT ('now'::text)::date NOT NULL,
    follow_time time without time zone DEFAULT ('now'::text)::time with time zone NOT NULL,
    done boolean DEFAULT false NOT NULL,
    narrative character varying(240),
    details text
);


ALTER TABLE public.follow_up OWNER TO postgres;

--
-- Name: follow_up_follow_up_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE follow_up_follow_up_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.follow_up_follow_up_id_seq OWNER TO postgres;

--
-- Name: follow_up_follow_up_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE follow_up_follow_up_id_seq OWNED BY follow_up.follow_up_id;


--
-- Name: forms; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE forms (
    form_id integer NOT NULL,
    org_id integer,
    form_name character varying(240) NOT NULL,
    form_number character varying(50),
    table_name character varying(50),
    version character varying(25),
    completed character(1) DEFAULT '0'::bpchar NOT NULL,
    is_active character(1) DEFAULT '0'::bpchar NOT NULL,
    use_key integer DEFAULT 0,
    form_header text,
    form_footer text,
    default_values text,
    details text
);


ALTER TABLE public.forms OWNER TO postgres;

--
-- Name: forms_form_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE forms_form_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.forms_form_id_seq OWNER TO postgres;

--
-- Name: forms_form_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE forms_form_id_seq OWNED BY forms.form_id;


--
-- Name: gls; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE gls (
    gl_id integer NOT NULL,
    journal_id integer NOT NULL,
    account_id integer NOT NULL,
    org_id integer,
    debit real DEFAULT 0 NOT NULL,
    credit real DEFAULT 0 NOT NULL,
    gl_narrative character varying(240)
);


ALTER TABLE public.gls OWNER TO postgres;

--
-- Name: gls_gl_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE gls_gl_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.gls_gl_id_seq OWNER TO postgres;

--
-- Name: gls_gl_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE gls_gl_id_seq OWNED BY gls.gl_id;


--
-- Name: helpdesk; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE helpdesk (
    helpdesk_id integer NOT NULL,
    pdefinition_id integer,
    plevel_id integer,
    client_id integer,
    recorded_by integer,
    closed_by integer,
    org_id integer,
    description character varying(120) NOT NULL,
    reported_by character varying(50) NOT NULL,
    recoded_time timestamp without time zone DEFAULT now() NOT NULL,
    solved_time timestamp without time zone,
    is_solved boolean DEFAULT false NOT NULL,
    curr_action character varying(50),
    curr_status character varying(50),
    problem text,
    solution text
);


ALTER TABLE public.helpdesk OWNER TO postgres;

--
-- Name: helpdesk_helpdesk_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE helpdesk_helpdesk_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.helpdesk_helpdesk_id_seq OWNER TO postgres;

--
-- Name: helpdesk_helpdesk_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE helpdesk_helpdesk_id_seq OWNED BY helpdesk.helpdesk_id;


--
-- Name: holidays; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE holidays (
    holiday_id integer NOT NULL,
    org_id integer,
    holiday_name character varying(50) NOT NULL,
    holiday_date date,
    details text
);


ALTER TABLE public.holidays OWNER TO postgres;

--
-- Name: holidays_holiday_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE holidays_holiday_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.holidays_holiday_id_seq OWNER TO postgres;

--
-- Name: holidays_holiday_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE holidays_holiday_id_seq OWNED BY holidays.holiday_id;


--
-- Name: identification_types; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE identification_types (
    identification_type_id integer NOT NULL,
    org_id integer,
    identification_type_name character varying(50),
    details text
);


ALTER TABLE public.identification_types OWNER TO postgres;

--
-- Name: identification_types_identification_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE identification_types_identification_type_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.identification_types_identification_type_id_seq OWNER TO postgres;

--
-- Name: identification_types_identification_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE identification_types_identification_type_id_seq OWNED BY identification_types.identification_type_id;


--
-- Name: identifications; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE identifications (
    identification_id integer NOT NULL,
    entity_id integer,
    identification_type_id integer,
    nationality character(2) NOT NULL,
    org_id integer,
    identification character varying(64),
    is_active boolean DEFAULT true NOT NULL,
    starting_from date,
    expiring_at date,
    place_of_issue character varying(50),
    details text
);


ALTER TABLE public.identifications OWNER TO postgres;

--
-- Name: identifications_identification_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE identifications_identification_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.identifications_identification_id_seq OWNER TO postgres;

--
-- Name: identifications_identification_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE identifications_identification_id_seq OWNED BY identifications.identification_id;


--
-- Name: industry; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE industry (
    industry_id integer NOT NULL,
    org_id integer,
    industry_name character varying(50) NOT NULL,
    details text
);


ALTER TABLE public.industry OWNER TO postgres;

--
-- Name: industry_industry_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE industry_industry_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.industry_industry_id_seq OWNER TO postgres;

--
-- Name: industry_industry_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE industry_industry_id_seq OWNED BY industry.industry_id;


--
-- Name: intake; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE intake (
    intake_id integer NOT NULL,
    department_role_id integer,
    pay_scale_id integer,
    pay_group_id integer,
    location_id integer,
    org_id integer,
    opening_date date NOT NULL,
    closing_date date NOT NULL,
    positions integer,
    contract boolean DEFAULT false NOT NULL,
    contract_period integer NOT NULL,
    details text
);


ALTER TABLE public.intake OWNER TO postgres;

--
-- Name: intake_intake_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE intake_intake_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.intake_intake_id_seq OWNER TO postgres;

--
-- Name: intake_intake_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE intake_intake_id_seq OWNED BY intake.intake_id;


--
-- Name: interns; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE interns (
    intern_id integer NOT NULL,
    internship_id integer,
    entity_id integer,
    org_id integer,
    payment_amount real,
    start_date date,
    end_date date,
    phone_mobile character varying(50),
    application_date timestamp without time zone DEFAULT now(),
    approve_status character varying(16) DEFAULT 'Draft'::character varying NOT NULL,
    workflow_table_id integer,
    action_date timestamp without time zone,
    applicant_comments text,
    review text
);


ALTER TABLE public.interns OWNER TO postgres;

--
-- Name: interns_intern_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE interns_intern_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.interns_intern_id_seq OWNER TO postgres;

--
-- Name: interns_intern_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE interns_intern_id_seq OWNED BY interns.intern_id;


--
-- Name: internships; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE internships (
    internship_id integer NOT NULL,
    department_id integer,
    org_id integer,
    opening_date date NOT NULL,
    closing_date date NOT NULL,
    positions integer,
    location character varying(50),
    details text
);


ALTER TABLE public.internships OWNER TO postgres;

--
-- Name: internships_internship_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE internships_internship_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.internships_internship_id_seq OWNER TO postgres;

--
-- Name: internships_internship_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE internships_internship_id_seq OWNED BY internships.internship_id;


--
-- Name: item_category; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE item_category (
    item_category_id integer NOT NULL,
    org_id integer,
    item_category_name character varying(120) NOT NULL,
    details text
);


ALTER TABLE public.item_category OWNER TO postgres;

--
-- Name: item_category_item_category_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE item_category_item_category_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.item_category_item_category_id_seq OWNER TO postgres;

--
-- Name: item_category_item_category_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE item_category_item_category_id_seq OWNED BY item_category.item_category_id;


--
-- Name: item_units; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE item_units (
    item_unit_id integer NOT NULL,
    org_id integer,
    item_unit_name character varying(50) NOT NULL,
    details text
);


ALTER TABLE public.item_units OWNER TO postgres;

--
-- Name: item_units_item_unit_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE item_units_item_unit_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.item_units_item_unit_id_seq OWNER TO postgres;

--
-- Name: item_units_item_unit_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE item_units_item_unit_id_seq OWNED BY item_units.item_unit_id;


--
-- Name: items; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE items (
    item_id integer NOT NULL,
    org_id integer,
    item_category_id integer,
    tax_type_id integer,
    item_unit_id integer,
    sales_account_id integer,
    purchase_account_id integer,
    item_name character varying(120),
    bar_code character varying(32),
    inventory boolean DEFAULT false NOT NULL,
    for_sale boolean DEFAULT true NOT NULL,
    for_purchase boolean DEFAULT true NOT NULL,
    sales_price real,
    purchase_price real,
    reorder_level integer,
    lead_time integer,
    is_active boolean DEFAULT true NOT NULL,
    details text
);


ALTER TABLE public.items OWNER TO postgres;

--
-- Name: items_item_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE items_item_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.items_item_id_seq OWNER TO postgres;

--
-- Name: items_item_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE items_item_id_seq OWNED BY items.item_id;


--
-- Name: job_reviews; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE job_reviews (
    job_review_id integer NOT NULL,
    entity_id integer,
    review_category_id integer,
    org_id integer,
    total_points integer,
    self_rating integer,
    supervisor_rating integer,
    review_date date NOT NULL,
    review_done boolean DEFAULT false NOT NULL,
    approve_status character varying(16) DEFAULT 'Draft'::character varying NOT NULL,
    workflow_table_id integer,
    application_date timestamp without time zone DEFAULT now(),
    action_date timestamp without time zone,
    recomendation text,
    staff_comments text,
    reviewer_comments text,
    pl_comments text,
    details text
);


ALTER TABLE public.job_reviews OWNER TO postgres;

--
-- Name: job_reviews_job_review_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE job_reviews_job_review_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.job_reviews_job_review_id_seq OWNER TO postgres;

--
-- Name: job_reviews_job_review_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE job_reviews_job_review_id_seq OWNED BY job_reviews.job_review_id;


--
-- Name: jobs_category; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE jobs_category (
    jobs_category_id integer NOT NULL,
    org_id integer,
    jobs_category character varying(50),
    details text
);


ALTER TABLE public.jobs_category OWNER TO postgres;

--
-- Name: jobs_category_jobs_category_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE jobs_category_jobs_category_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.jobs_category_jobs_category_id_seq OWNER TO postgres;

--
-- Name: jobs_category_jobs_category_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE jobs_category_jobs_category_id_seq OWNED BY jobs_category.jobs_category_id;


--
-- Name: journals; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE journals (
    journal_id integer NOT NULL,
    period_id integer NOT NULL,
    currency_id integer,
    department_id integer,
    org_id integer,
    exchange_rate real DEFAULT 1 NOT NULL,
    journal_date date NOT NULL,
    posted boolean DEFAULT false NOT NULL,
    year_closing boolean DEFAULT false NOT NULL,
    narrative character varying(240),
    details text
);


ALTER TABLE public.journals OWNER TO postgres;

--
-- Name: journals_journal_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE journals_journal_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.journals_journal_id_seq OWNER TO postgres;

--
-- Name: journals_journal_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE journals_journal_id_seq OWNED BY journals.journal_id;


--
-- Name: kin_types; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE kin_types (
    kin_type_id integer NOT NULL,
    org_id integer,
    kin_type_name character varying(50),
    details text
);


ALTER TABLE public.kin_types OWNER TO postgres;

--
-- Name: kin_types_kin_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE kin_types_kin_type_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.kin_types_kin_type_id_seq OWNER TO postgres;

--
-- Name: kin_types_kin_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE kin_types_kin_type_id_seq OWNED BY kin_types.kin_type_id;


--
-- Name: kins; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE kins (
    kin_id integer NOT NULL,
    entity_id integer,
    kin_type_id integer,
    org_id integer,
    full_names character varying(120),
    date_of_birth date,
    identification character varying(50),
    relation character varying(50),
    emergency_contact boolean DEFAULT false NOT NULL,
    beneficiary boolean DEFAULT false NOT NULL,
    beneficiary_ps real,
    details text
);


ALTER TABLE public.kins OWNER TO postgres;

--
-- Name: kins_kin_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE kins_kin_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.kins_kin_id_seq OWNER TO postgres;

--
-- Name: kins_kin_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE kins_kin_id_seq OWNED BY kins.kin_id;


--
-- Name: lead_items; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE lead_items (
    lead_item_id integer NOT NULL,
    lead_id integer,
    entity_id integer,
    item_id integer,
    org_id integer,
    pitch_date date DEFAULT ('now'::text)::date NOT NULL,
    units integer DEFAULT 1 NOT NULL,
    price real DEFAULT 0 NOT NULL,
    lead_level integer DEFAULT 1 NOT NULL,
    narrative character varying(320),
    details text
);


ALTER TABLE public.lead_items OWNER TO postgres;

--
-- Name: lead_items_lead_item_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE lead_items_lead_item_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.lead_items_lead_item_id_seq OWNER TO postgres;

--
-- Name: lead_items_lead_item_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE lead_items_lead_item_id_seq OWNED BY lead_items.lead_item_id;


--
-- Name: leads; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE leads (
    lead_id integer NOT NULL,
    industry_id integer,
    entity_id integer,
    org_id integer,
    business_id integer,
    business_name character varying(50) NOT NULL,
    business_address character varying(100),
    city character varying(30),
    state character varying(50),
    country_id character(2),
    number_of_employees integer,
    telephone character varying(50),
    website character varying(120),
    primary_contact character varying(120),
    job_title character varying(120),
    primary_email character varying(120),
    prospect_level integer DEFAULT 1 NOT NULL,
    contact_date date DEFAULT ('now'::text)::date NOT NULL,
    details text
);


ALTER TABLE public.leads OWNER TO postgres;

--
-- Name: leads_lead_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE leads_lead_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.leads_lead_id_seq OWNER TO postgres;

--
-- Name: leads_lead_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE leads_lead_id_seq OWNED BY leads.lead_id;


--
-- Name: leave_types; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE leave_types (
    leave_type_id integer NOT NULL,
    org_id integer,
    leave_type_name character varying(50) NOT NULL,
    allowed_leave_days integer DEFAULT 1 NOT NULL,
    leave_days_span integer DEFAULT 1 NOT NULL,
    use_type integer DEFAULT 0 NOT NULL,
    month_quota real DEFAULT 0 NOT NULL,
    initial_days real DEFAULT 0 NOT NULL,
    maximum_carry real DEFAULT 0 NOT NULL,
    include_holiday boolean DEFAULT false NOT NULL,
    include_mon boolean DEFAULT true NOT NULL,
    include_tue boolean DEFAULT true NOT NULL,
    include_wed boolean DEFAULT true NOT NULL,
    include_thu boolean DEFAULT true NOT NULL,
    include_fri boolean DEFAULT true NOT NULL,
    include_sat boolean DEFAULT false NOT NULL,
    include_sun boolean DEFAULT false NOT NULL,
    details text
);


ALTER TABLE public.leave_types OWNER TO postgres;

--
-- Name: leave_types_leave_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE leave_types_leave_type_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.leave_types_leave_type_id_seq OWNER TO postgres;

--
-- Name: leave_types_leave_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE leave_types_leave_type_id_seq OWNED BY leave_types.leave_type_id;


--
-- Name: leave_work_days; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE leave_work_days (
    leave_work_day_id integer NOT NULL,
    employee_leave_id integer,
    entity_id integer,
    org_id integer,
    work_date date NOT NULL,
    half_day boolean DEFAULT false NOT NULL,
    approve_status character varying(16) DEFAULT 'Draft'::character varying NOT NULL,
    workflow_table_id integer,
    application_date timestamp without time zone DEFAULT now(),
    action_date timestamp without time zone,
    details text
);


ALTER TABLE public.leave_work_days OWNER TO postgres;

--
-- Name: leave_work_days_leave_work_day_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE leave_work_days_leave_work_day_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.leave_work_days_leave_work_day_id_seq OWNER TO postgres;

--
-- Name: leave_work_days_leave_work_day_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE leave_work_days_leave_work_day_id_seq OWNED BY leave_work_days.leave_work_day_id;


--
-- Name: ledger_links; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE ledger_links (
    ledger_link_id integer NOT NULL,
    ledger_type_id integer,
    org_id integer,
    link_type integer,
    link_id integer
);


ALTER TABLE public.ledger_links OWNER TO postgres;

--
-- Name: ledger_links_ledger_link_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE ledger_links_ledger_link_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.ledger_links_ledger_link_id_seq OWNER TO postgres;

--
-- Name: ledger_links_ledger_link_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE ledger_links_ledger_link_id_seq OWNED BY ledger_links.ledger_link_id;


--
-- Name: ledger_types; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE ledger_types (
    ledger_type_id integer NOT NULL,
    account_id integer,
    tax_account_id integer,
    org_id integer,
    ledger_type_name character varying(120) NOT NULL,
    ledger_posting boolean DEFAULT true NOT NULL,
    income_ledger boolean DEFAULT true NOT NULL,
    expense_ledger boolean DEFAULT true NOT NULL,
    details text
);


ALTER TABLE public.ledger_types OWNER TO postgres;

--
-- Name: ledger_types_ledger_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE ledger_types_ledger_type_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.ledger_types_ledger_type_id_seq OWNER TO postgres;

--
-- Name: ledger_types_ledger_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE ledger_types_ledger_type_id_seq OWNED BY ledger_types.ledger_type_id;


--
-- Name: loan_monthly; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE loan_monthly (
    loan_month_id integer NOT NULL,
    loan_id integer,
    period_id integer,
    employee_adjustment_id integer,
    org_id integer,
    interest_amount real DEFAULT 0 NOT NULL,
    repayment real DEFAULT 0 NOT NULL,
    interest_paid real DEFAULT 0 NOT NULL,
    penalty real DEFAULT 0 NOT NULL,
    penalty_paid real DEFAULT 0 NOT NULL,
    extra_payment real DEFAULT 0 NOT NULL,
    details text
);


ALTER TABLE public.loan_monthly OWNER TO postgres;

--
-- Name: loan_monthly_loan_month_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE loan_monthly_loan_month_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.loan_monthly_loan_month_id_seq OWNER TO postgres;

--
-- Name: loan_monthly_loan_month_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE loan_monthly_loan_month_id_seq OWNED BY loan_monthly.loan_month_id;


--
-- Name: loan_types; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE loan_types (
    loan_type_id integer NOT NULL,
    adjustment_id integer,
    org_id integer,
    loan_type_name character varying(50) NOT NULL,
    default_interest real,
    reducing_balance boolean DEFAULT true NOT NULL,
    details text
);


ALTER TABLE public.loan_types OWNER TO postgres;

--
-- Name: loan_types_loan_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE loan_types_loan_type_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.loan_types_loan_type_id_seq OWNER TO postgres;

--
-- Name: loan_types_loan_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE loan_types_loan_type_id_seq OWNED BY loan_types.loan_type_id;


--
-- Name: loans; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE loans (
    loan_id integer NOT NULL,
    loan_type_id integer NOT NULL,
    entity_id integer NOT NULL,
    org_id integer,
    principle real NOT NULL,
    interest real NOT NULL,
    monthly_repayment real NOT NULL,
    loan_date date,
    initial_payment real DEFAULT 0 NOT NULL,
    reducing_balance boolean DEFAULT true NOT NULL,
    repayment_period integer NOT NULL,
    application_date timestamp without time zone DEFAULT now(),
    approve_status character varying(16) DEFAULT 'Draft'::character varying NOT NULL,
    workflow_table_id integer,
    action_date timestamp without time zone,
    details text,
    CONSTRAINT loans_repayment_period_check CHECK ((repayment_period > 0))
);


ALTER TABLE public.loans OWNER TO postgres;

--
-- Name: loans_loan_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE loans_loan_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.loans_loan_id_seq OWNER TO postgres;

--
-- Name: loans_loan_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE loans_loan_id_seq OWNED BY loans.loan_id;


--
-- Name: locations; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE locations (
    location_id integer NOT NULL,
    org_id integer,
    location_name character varying(50),
    details text
);


ALTER TABLE public.locations OWNER TO postgres;

--
-- Name: locations_location_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE locations_location_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.locations_location_id_seq OWNER TO postgres;

--
-- Name: locations_location_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE locations_location_id_seq OWNED BY locations.location_id;


--
-- Name: objective_details; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE objective_details (
    objective_detail_id integer NOT NULL,
    objective_id integer,
    ln_objective_detail_id integer,
    org_id integer,
    objective_detail_name character varying(320) NOT NULL,
    success_indicator text NOT NULL,
    achievements text,
    resources_required text,
    ods_ps real,
    ods_points integer DEFAULT 1 NOT NULL,
    ods_reviewer_points integer DEFAULT 1 NOT NULL,
    target_date date,
    completed boolean DEFAULT false NOT NULL,
    completion_date date,
    target_changes text,
    supervisor_comments text,
    details text
);


ALTER TABLE public.objective_details OWNER TO postgres;

--
-- Name: objective_details_objective_detail_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE objective_details_objective_detail_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.objective_details_objective_detail_id_seq OWNER TO postgres;

--
-- Name: objective_details_objective_detail_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE objective_details_objective_detail_id_seq OWNED BY objective_details.objective_detail_id;


--
-- Name: objective_types; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE objective_types (
    objective_type_id integer NOT NULL,
    org_id integer,
    objective_type_name character varying(320) NOT NULL,
    details text
);


ALTER TABLE public.objective_types OWNER TO postgres;

--
-- Name: objective_types_objective_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE objective_types_objective_type_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.objective_types_objective_type_id_seq OWNER TO postgres;

--
-- Name: objective_types_objective_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE objective_types_objective_type_id_seq OWNED BY objective_types.objective_type_id;


--
-- Name: objectives; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE objectives (
    objective_id integer NOT NULL,
    employee_objective_id integer,
    objective_type_id integer,
    org_id integer,
    date_set date NOT NULL,
    objective_ps real,
    objective_name character varying(320) NOT NULL,
    objective_completed boolean DEFAULT false NOT NULL,
    objective_maditory boolean DEFAULT false NOT NULL,
    supervisor_comments text,
    details text
);


ALTER TABLE public.objectives OWNER TO postgres;

--
-- Name: objectives_objective_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE objectives_objective_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.objectives_objective_id_seq OWNER TO postgres;

--
-- Name: objectives_objective_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE objectives_objective_id_seq OWNED BY objectives.objective_id;


--
-- Name: org_events; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE org_events (
    org_event_id integer NOT NULL,
    org_id integer,
    org_event_name character varying(50) NOT NULL,
    start_date date,
    end_date date,
    details text
);


ALTER TABLE public.org_events OWNER TO postgres;

--
-- Name: org_events_org_event_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE org_events_org_event_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.org_events_org_event_id_seq OWNER TO postgres;

--
-- Name: org_events_org_event_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE org_events_org_event_id_seq OWNED BY org_events.org_event_id;


--
-- Name: orgs; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE orgs (
    org_id integer NOT NULL,
    currency_id integer,
    default_country_id character(2),
    parent_org_id integer,
    org_name character varying(50) NOT NULL,
    org_full_name character varying(120),
    org_sufix character varying(4) NOT NULL,
    is_default boolean DEFAULT true NOT NULL,
    is_active boolean DEFAULT true NOT NULL,
    logo character varying(50),
    pin character varying(50),
    pcc character varying(12),
    system_key character varying(64),
    system_identifier character varying(64),
    mac_address character varying(64),
    public_key bytea,
    license bytea,
    details text,
    org_client_id integer,
    payroll_payable boolean DEFAULT true NOT NULL,
    cert_number character varying(50),
    vat_number character varying(50),
    enforce_budget boolean DEFAULT true NOT NULL,
    invoice_footer text,
    employee_limit integer DEFAULT 5 NOT NULL,
    transaction_limit integer DEFAULT 100 NOT NULL,
    expiry_date date
);


ALTER TABLE public.orgs OWNER TO postgres;

--
-- Name: orgs_org_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE orgs_org_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.orgs_org_id_seq OWNER TO postgres;

--
-- Name: orgs_org_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE orgs_org_id_seq OWNED BY orgs.org_id;


--
-- Name: pay_groups; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE pay_groups (
    pay_group_id integer NOT NULL,
    org_id integer,
    pay_group_name character varying(50),
    gl_payment_account character varying(16),
    bank_header text,
    bank_address text,
    details text
);


ALTER TABLE public.pay_groups OWNER TO postgres;

--
-- Name: pay_groups_pay_group_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE pay_groups_pay_group_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.pay_groups_pay_group_id_seq OWNER TO postgres;

--
-- Name: pay_groups_pay_group_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE pay_groups_pay_group_id_seq OWNED BY pay_groups.pay_group_id;


--
-- Name: pay_scale_steps; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE pay_scale_steps (
    pay_scale_step_id integer NOT NULL,
    pay_scale_id integer,
    org_id integer,
    pay_step integer NOT NULL,
    pay_amount real NOT NULL
);


ALTER TABLE public.pay_scale_steps OWNER TO postgres;

--
-- Name: pay_scale_steps_pay_scale_step_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE pay_scale_steps_pay_scale_step_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.pay_scale_steps_pay_scale_step_id_seq OWNER TO postgres;

--
-- Name: pay_scale_steps_pay_scale_step_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE pay_scale_steps_pay_scale_step_id_seq OWNED BY pay_scale_steps.pay_scale_step_id;


--
-- Name: pay_scale_years; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE pay_scale_years (
    pay_scale_year_id integer NOT NULL,
    pay_scale_id integer,
    org_id integer,
    pay_year integer NOT NULL,
    pay_amount real NOT NULL
);


ALTER TABLE public.pay_scale_years OWNER TO postgres;

--
-- Name: pay_scale_years_pay_scale_year_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE pay_scale_years_pay_scale_year_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.pay_scale_years_pay_scale_year_id_seq OWNER TO postgres;

--
-- Name: pay_scale_years_pay_scale_year_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE pay_scale_years_pay_scale_year_id_seq OWNED BY pay_scale_years.pay_scale_year_id;


--
-- Name: pay_scales; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE pay_scales (
    pay_scale_id integer NOT NULL,
    currency_id integer,
    org_id integer,
    pay_scale_name character varying(32) NOT NULL,
    min_pay real,
    max_pay real,
    details text
);


ALTER TABLE public.pay_scales OWNER TO postgres;

--
-- Name: pay_scales_pay_scale_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE pay_scales_pay_scale_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.pay_scales_pay_scale_id_seq OWNER TO postgres;

--
-- Name: pay_scales_pay_scale_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE pay_scales_pay_scale_id_seq OWNED BY pay_scales.pay_scale_id;


--
-- Name: pc_allocations; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE pc_allocations (
    pc_allocation_id integer NOT NULL,
    period_id integer,
    department_id integer,
    entity_id integer,
    org_id integer,
    narrative character varying(320),
    application_date timestamp without time zone DEFAULT now(),
    approve_status character varying(16) DEFAULT 'Draft'::character varying NOT NULL,
    workflow_table_id integer,
    action_date timestamp without time zone,
    details text
);


ALTER TABLE public.pc_allocations OWNER TO postgres;

--
-- Name: pc_allocations_pc_allocation_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE pc_allocations_pc_allocation_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.pc_allocations_pc_allocation_id_seq OWNER TO postgres;

--
-- Name: pc_allocations_pc_allocation_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE pc_allocations_pc_allocation_id_seq OWNED BY pc_allocations.pc_allocation_id;


--
-- Name: pc_banking; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE pc_banking (
    pc_banking_id integer NOT NULL,
    pc_allocation_id integer,
    org_id integer,
    banking_date date NOT NULL,
    amount double precision NOT NULL,
    narrative character varying(320) NOT NULL,
    details text
);


ALTER TABLE public.pc_banking OWNER TO postgres;

--
-- Name: pc_banking_pc_banking_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE pc_banking_pc_banking_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.pc_banking_pc_banking_id_seq OWNER TO postgres;

--
-- Name: pc_banking_pc_banking_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE pc_banking_pc_banking_id_seq OWNED BY pc_banking.pc_banking_id;


--
-- Name: pc_budget; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE pc_budget (
    pc_budget_id integer NOT NULL,
    pc_allocation_id integer,
    pc_item_id integer,
    org_id integer,
    budget_units integer NOT NULL,
    budget_price double precision NOT NULL,
    details text
);


ALTER TABLE public.pc_budget OWNER TO postgres;

--
-- Name: pc_budget_pc_budget_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE pc_budget_pc_budget_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.pc_budget_pc_budget_id_seq OWNER TO postgres;

--
-- Name: pc_budget_pc_budget_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE pc_budget_pc_budget_id_seq OWNED BY pc_budget.pc_budget_id;


--
-- Name: pc_category; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE pc_category (
    pc_category_id integer NOT NULL,
    org_id integer,
    pc_category_name character varying(50) NOT NULL,
    details text
);


ALTER TABLE public.pc_category OWNER TO postgres;

--
-- Name: pc_category_pc_category_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE pc_category_pc_category_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.pc_category_pc_category_id_seq OWNER TO postgres;

--
-- Name: pc_category_pc_category_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE pc_category_pc_category_id_seq OWNED BY pc_category.pc_category_id;


--
-- Name: pc_expenditure; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE pc_expenditure (
    pc_expenditure_id integer NOT NULL,
    pc_allocation_id integer,
    pc_item_id integer,
    pc_type_id integer,
    entity_id integer,
    org_id integer,
    is_request boolean DEFAULT true NOT NULL,
    request_date timestamp without time zone DEFAULT now(),
    application_date timestamp without time zone DEFAULT now(),
    approve_status character varying(16) DEFAULT 'Draft'::character varying NOT NULL,
    workflow_table_id integer,
    action_date timestamp without time zone,
    units integer NOT NULL,
    unit_price double precision NOT NULL,
    receipt_number character varying(50),
    exp_date date,
    details text
);


ALTER TABLE public.pc_expenditure OWNER TO postgres;

--
-- Name: pc_expenditure_pc_expenditure_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE pc_expenditure_pc_expenditure_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.pc_expenditure_pc_expenditure_id_seq OWNER TO postgres;

--
-- Name: pc_expenditure_pc_expenditure_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE pc_expenditure_pc_expenditure_id_seq OWNED BY pc_expenditure.pc_expenditure_id;


--
-- Name: pc_items; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE pc_items (
    pc_item_id integer NOT NULL,
    pc_category_id integer,
    org_id integer,
    pc_item_name character varying(50) NOT NULL,
    default_price double precision NOT NULL,
    default_units integer NOT NULL,
    details text
);


ALTER TABLE public.pc_items OWNER TO postgres;

--
-- Name: pc_items_pc_item_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE pc_items_pc_item_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.pc_items_pc_item_id_seq OWNER TO postgres;

--
-- Name: pc_items_pc_item_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE pc_items_pc_item_id_seq OWNED BY pc_items.pc_item_id;


--
-- Name: pc_types; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE pc_types (
    pc_type_id integer NOT NULL,
    org_id integer,
    pc_type_name character varying(50) NOT NULL,
    details text
);


ALTER TABLE public.pc_types OWNER TO postgres;

--
-- Name: pc_types_pc_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE pc_types_pc_type_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.pc_types_pc_type_id_seq OWNER TO postgres;

--
-- Name: pc_types_pc_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE pc_types_pc_type_id_seq OWNED BY pc_types.pc_type_id;


--
-- Name: pdefinitions; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE pdefinitions (
    pdefinition_id integer NOT NULL,
    ptype_id integer,
    org_id integer,
    pdefinition_name character varying(50) NOT NULL,
    description text,
    solution text
);


ALTER TABLE public.pdefinitions OWNER TO postgres;

--
-- Name: pdefinitions_pdefinition_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE pdefinitions_pdefinition_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.pdefinitions_pdefinition_id_seq OWNER TO postgres;

--
-- Name: pdefinitions_pdefinition_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE pdefinitions_pdefinition_id_seq OWNED BY pdefinitions.pdefinition_id;


--
-- Name: pensions; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE pensions (
    pension_id integer NOT NULL,
    entity_id integer,
    adjustment_id integer,
    contribution_id integer,
    org_id integer,
    pension_company character varying(50) NOT NULL,
    pension_number character varying(50),
    active boolean DEFAULT true,
    amount double precision DEFAULT 0 NOT NULL,
    use_formura boolean DEFAULT false NOT NULL,
    employer_ps double precision DEFAULT 0 NOT NULL,
    employer_amount double precision DEFAULT 0 NOT NULL,
    employer_formural boolean DEFAULT false NOT NULL,
    details text
);


ALTER TABLE public.pensions OWNER TO postgres;

--
-- Name: pensions_pension_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE pensions_pension_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.pensions_pension_id_seq OWNER TO postgres;

--
-- Name: pensions_pension_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE pensions_pension_id_seq OWNED BY pensions.pension_id;


--
-- Name: period_tax_rates; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE period_tax_rates (
    period_tax_rate_id integer NOT NULL,
    period_tax_type_id integer,
    tax_rate_id integer,
    org_id integer,
    tax_range double precision NOT NULL,
    tax_rate double precision NOT NULL,
    narrative character varying(240)
);


ALTER TABLE public.period_tax_rates OWNER TO postgres;

--
-- Name: period_tax_rates_period_tax_rate_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE period_tax_rates_period_tax_rate_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.period_tax_rates_period_tax_rate_id_seq OWNER TO postgres;

--
-- Name: period_tax_rates_period_tax_rate_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE period_tax_rates_period_tax_rate_id_seq OWNED BY period_tax_rates.period_tax_rate_id;


--
-- Name: period_tax_types; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE period_tax_types (
    period_tax_type_id integer NOT NULL,
    period_id integer,
    tax_type_id integer,
    account_id integer,
    org_id integer,
    period_tax_type_name character varying(50) NOT NULL,
    pay_date date DEFAULT ('now'::text)::date NOT NULL,
    formural character varying(320),
    tax_relief real DEFAULT 0 NOT NULL,
    percentage boolean DEFAULT true NOT NULL,
    linear boolean DEFAULT true NOT NULL,
    tax_type_order integer DEFAULT 0 NOT NULL,
    in_tax boolean DEFAULT false NOT NULL,
    employer double precision NOT NULL,
    employer_ps double precision NOT NULL,
    account_number character varying(32),
    details text
);


ALTER TABLE public.period_tax_types OWNER TO postgres;

--
-- Name: period_tax_types_period_tax_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE period_tax_types_period_tax_type_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.period_tax_types_period_tax_type_id_seq OWNER TO postgres;

--
-- Name: period_tax_types_period_tax_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE period_tax_types_period_tax_type_id_seq OWNED BY period_tax_types.period_tax_type_id;


--
-- Name: periods; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE periods (
    period_id integer NOT NULL,
    fiscal_year_id integer,
    org_id integer,
    start_date date NOT NULL,
    end_date date NOT NULL,
    opened boolean DEFAULT false NOT NULL,
    activated boolean DEFAULT false NOT NULL,
    closed boolean DEFAULT false NOT NULL,
    overtime_rate double precision DEFAULT 1 NOT NULL,
    per_diem_tax_limit double precision DEFAULT 2000 NOT NULL,
    is_posted boolean DEFAULT false NOT NULL,
    loan_approval boolean DEFAULT false NOT NULL,
    gl_payroll_account character varying(32),
    gl_advance_account character varying(32),
    entity_id integer,
    application_date timestamp without time zone DEFAULT now(),
    approve_status character varying(16) DEFAULT 'Draft'::character varying NOT NULL,
    workflow_table_id integer,
    action_date timestamp without time zone,
    details text
);


ALTER TABLE public.periods OWNER TO postgres;

--
-- Name: periods_period_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE periods_period_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.periods_period_id_seq OWNER TO postgres;

--
-- Name: periods_period_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE periods_period_id_seq OWNED BY periods.period_id;


--
-- Name: phases; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE phases (
    phase_id integer NOT NULL,
    project_id integer,
    org_id integer,
    phase_name character varying(240),
    start_date date NOT NULL,
    end_date date,
    completed boolean DEFAULT false NOT NULL,
    phase_cost real DEFAULT 0 NOT NULL,
    details text
);


ALTER TABLE public.phases OWNER TO postgres;

--
-- Name: phases_phase_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE phases_phase_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.phases_phase_id_seq OWNER TO postgres;

--
-- Name: phases_phase_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE phases_phase_id_seq OWNED BY phases.phase_id;


--
-- Name: picture_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE picture_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.picture_id_seq OWNER TO postgres;

--
-- Name: plevels; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE plevels (
    plevel_id integer NOT NULL,
    org_id integer,
    plevel_name character varying(50) NOT NULL,
    details text
);


ALTER TABLE public.plevels OWNER TO postgres;

--
-- Name: plevels_plevel_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE plevels_plevel_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.plevels_plevel_id_seq OWNER TO postgres;

--
-- Name: plevels_plevel_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE plevels_plevel_id_seq OWNED BY plevels.plevel_id;


--
-- Name: product_receipts; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE product_receipts (
    product_receipt_id integer NOT NULL,
    receipt_source_id integer,
    org_id integer,
    is_paid boolean DEFAULT false NOT NULL,
    receipt_amount real NOT NULL,
    receipt_date date NOT NULL,
    receipt_time timestamp without time zone DEFAULT now() NOT NULL,
    receipt_reference character varying(32),
    narrative character varying(320)
);


ALTER TABLE public.product_receipts OWNER TO postgres;

--
-- Name: product_receipts_product_receipt_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE product_receipts_product_receipt_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.product_receipts_product_receipt_id_seq OWNER TO postgres;

--
-- Name: product_receipts_product_receipt_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE product_receipts_product_receipt_id_seq OWNED BY product_receipts.product_receipt_id;


--
-- Name: productions; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE productions (
    production_id integer NOT NULL,
    product_id integer,
    entity_id integer,
    org_id integer,
    quantity integer NOT NULL,
    price real NOT NULL,
    transaction_time timestamp without time zone DEFAULT now() NOT NULL,
    expiry_date date NOT NULL,
    montly_billing boolean DEFAULT false NOT NULL,
    is_renewed boolean DEFAULT false NOT NULL,
    auto_renew boolean DEFAULT false NOT NULL,
    details text
);


ALTER TABLE public.productions OWNER TO postgres;

--
-- Name: productions_production_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE productions_production_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.productions_production_id_seq OWNER TO postgres;

--
-- Name: productions_production_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE productions_production_id_seq OWNED BY productions.production_id;


--
-- Name: products; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE products (
    product_id integer NOT NULL,
    org_id integer,
    product_name character varying(50),
    is_singular boolean DEFAULT true NOT NULL,
    align_expiry boolean DEFAULT true NOT NULL,
    is_montly_bill boolean DEFAULT false NOT NULL,
    montly_cost real DEFAULT 0 NOT NULL,
    is_annual_bill boolean DEFAULT true NOT NULL,
    annual_cost real DEFAULT 0 NOT NULL,
    details text NOT NULL
);


ALTER TABLE public.products OWNER TO postgres;

--
-- Name: products_product_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE products_product_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.products_product_id_seq OWNER TO postgres;

--
-- Name: products_product_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE products_product_id_seq OWNED BY products.product_id;


--
-- Name: project_cost; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE project_cost (
    project_cost_id integer NOT NULL,
    phase_id integer,
    org_id integer,
    project_cost_name character varying(240),
    amount real DEFAULT 0 NOT NULL,
    cost_date date NOT NULL,
    cost_approved boolean DEFAULT false,
    details text
);


ALTER TABLE public.project_cost OWNER TO postgres;

--
-- Name: project_cost_project_cost_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE project_cost_project_cost_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.project_cost_project_cost_id_seq OWNER TO postgres;

--
-- Name: project_cost_project_cost_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE project_cost_project_cost_id_seq OWNED BY project_cost.project_cost_id;


--
-- Name: project_staff; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE project_staff (
    project_staff_id integer NOT NULL,
    project_id integer,
    entity_id integer,
    org_id integer,
    project_role character varying(240),
    monthly_cost boolean DEFAULT true NOT NULL,
    is_active boolean DEFAULT true NOT NULL,
    payroll_ps real DEFAULT 0 NOT NULL,
    staff_cost real DEFAULT 0 NOT NULL,
    tax_cost real DEFAULT 0 NOT NULL,
    details text
);


ALTER TABLE public.project_staff OWNER TO postgres;

--
-- Name: project_staff_costs; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE project_staff_costs (
    project_staff_cost_id integer NOT NULL,
    project_id integer NOT NULL,
    employee_month_id integer NOT NULL,
    org_id integer,
    project_role character varying(240),
    payroll_ps real DEFAULT 0 NOT NULL,
    staff_cost real DEFAULT 0 NOT NULL,
    tax_cost real DEFAULT 0 NOT NULL,
    details text
);


ALTER TABLE public.project_staff_costs OWNER TO postgres;

--
-- Name: project_staff_costs_project_staff_cost_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE project_staff_costs_project_staff_cost_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.project_staff_costs_project_staff_cost_id_seq OWNER TO postgres;

--
-- Name: project_staff_costs_project_staff_cost_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE project_staff_costs_project_staff_cost_id_seq OWNED BY project_staff_costs.project_staff_cost_id;


--
-- Name: project_staff_project_staff_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE project_staff_project_staff_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.project_staff_project_staff_id_seq OWNER TO postgres;

--
-- Name: project_staff_project_staff_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE project_staff_project_staff_id_seq OWNED BY project_staff.project_staff_id;


--
-- Name: project_types; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE project_types (
    project_type_id integer NOT NULL,
    org_id integer,
    project_type_name character varying(50) NOT NULL,
    details text
);


ALTER TABLE public.project_types OWNER TO postgres;

--
-- Name: project_types_project_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE project_types_project_type_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.project_types_project_type_id_seq OWNER TO postgres;

--
-- Name: project_types_project_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE project_types_project_type_id_seq OWNED BY project_types.project_type_id;


--
-- Name: projects; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE projects (
    project_id integer NOT NULL,
    project_type_id integer,
    entity_id integer,
    org_id integer,
    project_name character varying(240) NOT NULL,
    signed boolean DEFAULT false NOT NULL,
    contract_ref character varying(120),
    monthly_amount real,
    full_amount real,
    project_cost real,
    narrative character varying(120),
    project_account character varying(32),
    start_date date NOT NULL,
    ending_date date,
    details text
);


ALTER TABLE public.projects OWNER TO postgres;

--
-- Name: projects_project_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE projects_project_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.projects_project_id_seq OWNER TO postgres;

--
-- Name: projects_project_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE projects_project_id_seq OWNED BY projects.project_id;


--
-- Name: ptypes; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE ptypes (
    ptype_id integer NOT NULL,
    org_id integer,
    ptype_name character varying(50) NOT NULL,
    details text
);


ALTER TABLE public.ptypes OWNER TO postgres;

--
-- Name: ptypes_ptype_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE ptypes_ptype_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.ptypes_ptype_id_seq OWNER TO postgres;

--
-- Name: ptypes_ptype_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE ptypes_ptype_id_seq OWNED BY ptypes.ptype_id;


--
-- Name: quotations; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE quotations (
    quotation_id integer NOT NULL,
    org_id integer,
    item_id integer,
    entity_id integer,
    active boolean DEFAULT false NOT NULL,
    amount real,
    valid_from date,
    valid_to date,
    lead_time integer,
    details text
);


ALTER TABLE public.quotations OWNER TO postgres;

--
-- Name: quotations_quotation_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE quotations_quotation_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.quotations_quotation_id_seq OWNER TO postgres;

--
-- Name: quotations_quotation_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE quotations_quotation_id_seq OWNED BY quotations.quotation_id;


--
-- Name: receipt_sources; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE receipt_sources (
    receipt_source_id integer NOT NULL,
    org_id integer,
    receipt_source_name character varying(50) NOT NULL,
    details text
);


ALTER TABLE public.receipt_sources OWNER TO postgres;

--
-- Name: receipt_sources_receipt_source_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE receipt_sources_receipt_source_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.receipt_sources_receipt_source_id_seq OWNER TO postgres;

--
-- Name: receipt_sources_receipt_source_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE receipt_sources_receipt_source_id_seq OWNED BY receipt_sources.receipt_source_id;


--
-- Name: reporting; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE reporting (
    reporting_id integer NOT NULL,
    entity_id integer,
    report_to_id integer,
    org_id integer,
    date_from date,
    date_to date,
    reporting_level integer DEFAULT 1 NOT NULL,
    primary_report boolean DEFAULT true NOT NULL,
    is_active boolean DEFAULT true NOT NULL,
    ps_reporting real,
    details text
);


ALTER TABLE public.reporting OWNER TO postgres;

--
-- Name: reporting_reporting_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE reporting_reporting_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.reporting_reporting_id_seq OWNER TO postgres;

--
-- Name: reporting_reporting_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE reporting_reporting_id_seq OWNED BY reporting.reporting_id;


--
-- Name: review_category; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE review_category (
    review_category_id integer NOT NULL,
    org_id integer,
    review_category_name character varying(320),
    rate_objectives boolean DEFAULT true NOT NULL,
    details text
);


ALTER TABLE public.review_category OWNER TO postgres;

--
-- Name: review_category_review_category_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE review_category_review_category_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.review_category_review_category_id_seq OWNER TO postgres;

--
-- Name: review_category_review_category_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE review_category_review_category_id_seq OWNED BY review_category.review_category_id;


--
-- Name: review_points; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE review_points (
    review_point_id integer NOT NULL,
    review_category_id integer,
    org_id integer,
    review_point_name character varying(50),
    review_points integer DEFAULT 1 NOT NULL,
    details text
);


ALTER TABLE public.review_points OWNER TO postgres;

--
-- Name: review_points_review_point_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE review_points_review_point_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.review_points_review_point_id_seq OWNER TO postgres;

--
-- Name: review_points_review_point_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE review_points_review_point_id_seq OWNED BY review_points.review_point_id;


--
-- Name: shift_schedule; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE shift_schedule (
    shift_schedule_id integer NOT NULL,
    shift_id integer,
    entity_id integer,
    org_id integer,
    is_active boolean DEFAULT true NOT NULL,
    details text
);


ALTER TABLE public.shift_schedule OWNER TO postgres;

--
-- Name: shift_schedule_shift_schedule_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE shift_schedule_shift_schedule_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.shift_schedule_shift_schedule_id_seq OWNER TO postgres;

--
-- Name: shift_schedule_shift_schedule_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE shift_schedule_shift_schedule_id_seq OWNED BY shift_schedule.shift_schedule_id;


--
-- Name: shifts; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE shifts (
    shift_id integer NOT NULL,
    project_id integer,
    org_id integer,
    shift_name character varying(50),
    shift_hours integer DEFAULT 8 NOT NULL,
    include_holiday boolean DEFAULT false NOT NULL,
    include_mon boolean DEFAULT true NOT NULL,
    include_tue boolean DEFAULT true NOT NULL,
    include_wed boolean DEFAULT true NOT NULL,
    include_thu boolean DEFAULT true NOT NULL,
    include_fri boolean DEFAULT true NOT NULL,
    include_sat boolean DEFAULT false NOT NULL,
    include_sun boolean DEFAULT false NOT NULL,
    time_in time without time zone NOT NULL,
    time_out time without time zone NOT NULL,
    details text
);


ALTER TABLE public.shifts OWNER TO postgres;

--
-- Name: shifts_shift_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE shifts_shift_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.shifts_shift_id_seq OWNER TO postgres;

--
-- Name: shifts_shift_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE shifts_shift_id_seq OWNED BY shifts.shift_id;


--
-- Name: skill_category; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE skill_category (
    skill_category_id integer NOT NULL,
    org_id integer,
    skill_category_name character varying(50) NOT NULL,
    details text
);


ALTER TABLE public.skill_category OWNER TO postgres;

--
-- Name: skill_category_skill_category_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE skill_category_skill_category_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.skill_category_skill_category_id_seq OWNER TO postgres;

--
-- Name: skill_category_skill_category_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE skill_category_skill_category_id_seq OWNED BY skill_category.skill_category_id;


--
-- Name: skill_types; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE skill_types (
    skill_type_id integer NOT NULL,
    skill_category_id integer,
    org_id integer,
    skill_type_name character varying(50) NOT NULL,
    basic character varying(50),
    intermediate character varying(50),
    advanced character varying(50),
    details text
);


ALTER TABLE public.skill_types OWNER TO postgres;

--
-- Name: skill_types_skill_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE skill_types_skill_type_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.skill_types_skill_type_id_seq OWNER TO postgres;

--
-- Name: skill_types_skill_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE skill_types_skill_type_id_seq OWNED BY skill_types.skill_type_id;


--
-- Name: skills; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE skills (
    skill_id integer NOT NULL,
    entity_id integer,
    skill_type_id integer,
    org_id integer,
    state_skill character varying(50),
    skill_level integer DEFAULT 1 NOT NULL,
    aquired boolean DEFAULT false NOT NULL,
    training_date date,
    trained boolean DEFAULT false NOT NULL,
    training_institution character varying(240),
    training_cost real,
    details text
);


ALTER TABLE public.skills OWNER TO postgres;

--
-- Name: skills_skill_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE skills_skill_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.skills_skill_id_seq OWNER TO postgres;

--
-- Name: skills_skill_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE skills_skill_id_seq OWNED BY skills.skill_id;


--
-- Name: stock_lines; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE stock_lines (
    stock_line_id integer NOT NULL,
    org_id integer,
    stock_id integer,
    item_id integer,
    quantity integer,
    narrative character varying(240)
);


ALTER TABLE public.stock_lines OWNER TO postgres;

--
-- Name: stock_lines_stock_line_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE stock_lines_stock_line_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.stock_lines_stock_line_id_seq OWNER TO postgres;

--
-- Name: stock_lines_stock_line_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE stock_lines_stock_line_id_seq OWNED BY stock_lines.stock_line_id;


--
-- Name: stocks; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE stocks (
    stock_id integer NOT NULL,
    org_id integer,
    store_id integer,
    stock_name character varying(50),
    stock_take_date date,
    details text
);


ALTER TABLE public.stocks OWNER TO postgres;

--
-- Name: stocks_stock_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE stocks_stock_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.stocks_stock_id_seq OWNER TO postgres;

--
-- Name: stocks_stock_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE stocks_stock_id_seq OWNED BY stocks.stock_id;


--
-- Name: stores; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE stores (
    store_id integer NOT NULL,
    org_id integer,
    store_name character varying(120),
    details text
);


ALTER TABLE public.stores OWNER TO postgres;

--
-- Name: stores_store_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE stores_store_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.stores_store_id_seq OWNER TO postgres;

--
-- Name: stores_store_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE stores_store_id_seq OWNED BY stores.store_id;


--
-- Name: sub_fields; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE sub_fields (
    sub_field_id integer NOT NULL,
    org_id integer,
    field_id integer,
    sub_field_order integer NOT NULL,
    sub_title_share character varying(120),
    sub_field_type character varying(25),
    sub_field_lookup text,
    sub_field_size integer NOT NULL,
    sub_col_spans integer DEFAULT 1 NOT NULL,
    manditory character(1) DEFAULT '0'::bpchar NOT NULL,
    show character(1) DEFAULT '1'::bpchar,
    question text
);


ALTER TABLE public.sub_fields OWNER TO postgres;

--
-- Name: sub_fields_sub_field_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE sub_fields_sub_field_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.sub_fields_sub_field_id_seq OWNER TO postgres;

--
-- Name: sub_fields_sub_field_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE sub_fields_sub_field_id_seq OWNED BY sub_fields.sub_field_id;


--
-- Name: subscription_levels; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE subscription_levels (
    subscription_level_id integer NOT NULL,
    org_id integer,
    subscription_level_name character varying(50),
    details text
);


ALTER TABLE public.subscription_levels OWNER TO postgres;

--
-- Name: subscription_levels_subscription_level_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE subscription_levels_subscription_level_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.subscription_levels_subscription_level_id_seq OWNER TO postgres;

--
-- Name: subscription_levels_subscription_level_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE subscription_levels_subscription_level_id_seq OWNED BY subscription_levels.subscription_level_id;


--
-- Name: subscriptions; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE subscriptions (
    subscription_id integer NOT NULL,
    industry_id integer,
    entity_id integer,
    account_manager_id integer,
    org_id integer,
    business_name character varying(50),
    business_address character varying(100),
    city character varying(30),
    state character varying(50),
    country_id character(2),
    number_of_employees integer,
    telephone character varying(50),
    website character varying(120),
    primary_contact character varying(120),
    job_title character varying(120),
    primary_email character varying(120),
    confirm_email character varying(120),
    system_key character varying(64),
    subscribed boolean,
    subscribed_date timestamp without time zone,
    approve_status character varying(16) DEFAULT 'Draft'::character varying NOT NULL,
    workflow_table_id integer,
    application_date timestamp without time zone DEFAULT now(),
    action_date timestamp without time zone,
    details text
);


ALTER TABLE public.subscriptions OWNER TO postgres;

--
-- Name: subscriptions_subscription_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE subscriptions_subscription_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.subscriptions_subscription_id_seq OWNER TO postgres;

--
-- Name: subscriptions_subscription_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE subscriptions_subscription_id_seq OWNED BY subscriptions.subscription_id;


--
-- Name: sys_audit_details; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE sys_audit_details (
    sys_audit_trail_id integer NOT NULL,
    old_value text
);


ALTER TABLE public.sys_audit_details OWNER TO postgres;

--
-- Name: sys_audit_trail; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE sys_audit_trail (
    sys_audit_trail_id integer NOT NULL,
    user_id character varying(50) NOT NULL,
    user_ip character varying(50),
    change_date timestamp without time zone DEFAULT now() NOT NULL,
    table_name character varying(50) NOT NULL,
    record_id character varying(50) NOT NULL,
    change_type character varying(50) NOT NULL,
    narrative character varying(240)
);


ALTER TABLE public.sys_audit_trail OWNER TO postgres;

--
-- Name: sys_audit_trail_sys_audit_trail_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE sys_audit_trail_sys_audit_trail_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.sys_audit_trail_sys_audit_trail_id_seq OWNER TO postgres;

--
-- Name: sys_audit_trail_sys_audit_trail_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE sys_audit_trail_sys_audit_trail_id_seq OWNED BY sys_audit_trail.sys_audit_trail_id;


--
-- Name: sys_continents; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE sys_continents (
    sys_continent_id character(2) NOT NULL,
    sys_continent_name character varying(120)
);


ALTER TABLE public.sys_continents OWNER TO postgres;

--
-- Name: sys_countrys; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE sys_countrys (
    sys_country_id character(2) NOT NULL,
    sys_continent_id character(2),
    sys_country_code character varying(3),
    sys_country_number character varying(3),
    sys_phone_code character varying(3),
    sys_country_name character varying(120),
    sys_currency_name character varying(50),
    sys_currency_cents character varying(50),
    sys_currency_code character varying(3),
    sys_currency_exchange real
);


ALTER TABLE public.sys_countrys OWNER TO postgres;

--
-- Name: sys_dashboard; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE sys_dashboard (
    sys_dashboard_id integer NOT NULL,
    entity_id integer,
    org_id integer,
    narrative character varying(240),
    details text
);


ALTER TABLE public.sys_dashboard OWNER TO postgres;

--
-- Name: sys_dashboard_sys_dashboard_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE sys_dashboard_sys_dashboard_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.sys_dashboard_sys_dashboard_id_seq OWNER TO postgres;

--
-- Name: sys_dashboard_sys_dashboard_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE sys_dashboard_sys_dashboard_id_seq OWNED BY sys_dashboard.sys_dashboard_id;


--
-- Name: sys_emailed; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE sys_emailed (
    sys_emailed_id integer NOT NULL,
    sys_email_id integer,
    org_id integer,
    table_id integer,
    table_name character varying(50),
    email_type integer DEFAULT 1 NOT NULL,
    emailed boolean DEFAULT false NOT NULL,
    created timestamp without time zone DEFAULT now(),
    narrative character varying(240),
    mail_body text
);


ALTER TABLE public.sys_emailed OWNER TO postgres;

--
-- Name: sys_emailed_sys_emailed_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE sys_emailed_sys_emailed_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.sys_emailed_sys_emailed_id_seq OWNER TO postgres;

--
-- Name: sys_emailed_sys_emailed_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE sys_emailed_sys_emailed_id_seq OWNED BY sys_emailed.sys_emailed_id;


--
-- Name: sys_emails; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE sys_emails (
    sys_email_id integer NOT NULL,
    org_id integer,
    use_type integer DEFAULT 1 NOT NULL,
    sys_email_name character varying(50),
    default_email character varying(320),
    title character varying(240) NOT NULL,
    details text
);


ALTER TABLE public.sys_emails OWNER TO postgres;

--
-- Name: sys_emails_sys_email_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE sys_emails_sys_email_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.sys_emails_sys_email_id_seq OWNER TO postgres;

--
-- Name: sys_emails_sys_email_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE sys_emails_sys_email_id_seq OWNED BY sys_emails.sys_email_id;


--
-- Name: sys_errors; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE sys_errors (
    sys_error_id integer NOT NULL,
    sys_error character varying(240) NOT NULL,
    error_message text NOT NULL
);


ALTER TABLE public.sys_errors OWNER TO postgres;

--
-- Name: sys_errors_sys_error_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE sys_errors_sys_error_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.sys_errors_sys_error_id_seq OWNER TO postgres;

--
-- Name: sys_errors_sys_error_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE sys_errors_sys_error_id_seq OWNED BY sys_errors.sys_error_id;


--
-- Name: sys_files; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE sys_files (
    sys_file_id integer NOT NULL,
    org_id integer,
    table_id integer,
    table_name character varying(50),
    file_name character varying(320),
    file_type character varying(320),
    file_size integer,
    narrative character varying(320),
    details text
);


ALTER TABLE public.sys_files OWNER TO postgres;

--
-- Name: sys_files_sys_file_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE sys_files_sys_file_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.sys_files_sys_file_id_seq OWNER TO postgres;

--
-- Name: sys_files_sys_file_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE sys_files_sys_file_id_seq OWNED BY sys_files.sys_file_id;


--
-- Name: sys_logins; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE sys_logins (
    sys_login_id integer NOT NULL,
    entity_id integer,
    login_time timestamp without time zone DEFAULT now(),
    login_ip character varying(64),
    narrative character varying(240)
);


ALTER TABLE public.sys_logins OWNER TO postgres;

--
-- Name: sys_logins_sys_login_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE sys_logins_sys_login_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.sys_logins_sys_login_id_seq OWNER TO postgres;

--
-- Name: sys_logins_sys_login_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE sys_logins_sys_login_id_seq OWNED BY sys_logins.sys_login_id;


--
-- Name: sys_menu_msg; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE sys_menu_msg (
    sys_menu_msg_id integer NOT NULL,
    menu_id character varying(16) NOT NULL,
    menu_name character varying(50) NOT NULL,
    xml_file character varying(50) NOT NULL,
    msg text
);


ALTER TABLE public.sys_menu_msg OWNER TO postgres;

--
-- Name: sys_menu_msg_sys_menu_msg_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE sys_menu_msg_sys_menu_msg_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.sys_menu_msg_sys_menu_msg_id_seq OWNER TO postgres;

--
-- Name: sys_menu_msg_sys_menu_msg_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE sys_menu_msg_sys_menu_msg_id_seq OWNED BY sys_menu_msg.sys_menu_msg_id;


--
-- Name: sys_news; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE sys_news (
    sys_news_id integer NOT NULL,
    org_id integer,
    sys_news_group integer,
    sys_news_title character varying(240) NOT NULL,
    publish boolean DEFAULT false NOT NULL,
    details text
);


ALTER TABLE public.sys_news OWNER TO postgres;

--
-- Name: sys_news_sys_news_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE sys_news_sys_news_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.sys_news_sys_news_id_seq OWNER TO postgres;

--
-- Name: sys_news_sys_news_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE sys_news_sys_news_id_seq OWNED BY sys_news.sys_news_id;


--
-- Name: sys_queries; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE sys_queries (
    sys_queries_id integer NOT NULL,
    org_id integer,
    sys_query_name character varying(50),
    query_date timestamp without time zone DEFAULT now() NOT NULL,
    query_text text,
    query_params text
);


ALTER TABLE public.sys_queries OWNER TO postgres;

--
-- Name: sys_queries_sys_queries_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE sys_queries_sys_queries_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.sys_queries_sys_queries_id_seq OWNER TO postgres;

--
-- Name: sys_queries_sys_queries_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE sys_queries_sys_queries_id_seq OWNED BY sys_queries.sys_queries_id;


--
-- Name: sys_reset; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE sys_reset (
    sys_reset_id integer NOT NULL,
    entity_id integer,
    org_id integer,
    request_email character varying(320),
    request_time timestamp without time zone DEFAULT now(),
    login_ip character varying(64),
    narrative character varying(240)
);


ALTER TABLE public.sys_reset OWNER TO postgres;

--
-- Name: sys_reset_sys_reset_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE sys_reset_sys_reset_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.sys_reset_sys_reset_id_seq OWNER TO postgres;

--
-- Name: sys_reset_sys_reset_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE sys_reset_sys_reset_id_seq OWNED BY sys_reset.sys_reset_id;


--
-- Name: tasks; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE tasks (
    task_id integer NOT NULL,
    phase_id integer,
    entity_id integer,
    org_id integer,
    task_name character varying(320) NOT NULL,
    start_date date NOT NULL,
    dead_line date,
    end_date date,
    hours_taken integer DEFAULT 7 NOT NULL,
    completed boolean DEFAULT false NOT NULL,
    details text
);


ALTER TABLE public.tasks OWNER TO postgres;

--
-- Name: tasks_task_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE tasks_task_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tasks_task_id_seq OWNER TO postgres;

--
-- Name: tasks_task_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE tasks_task_id_seq OWNED BY tasks.task_id;


--
-- Name: tax_rates; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE tax_rates (
    tax_rate_id integer NOT NULL,
    tax_type_id integer,
    org_id integer,
    tax_range double precision NOT NULL,
    tax_rate double precision NOT NULL,
    narrative character varying(240)
);


ALTER TABLE public.tax_rates OWNER TO postgres;

--
-- Name: tax_rates_tax_rate_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE tax_rates_tax_rate_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tax_rates_tax_rate_id_seq OWNER TO postgres;

--
-- Name: tax_rates_tax_rate_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE tax_rates_tax_rate_id_seq OWNED BY tax_rates.tax_rate_id;


--
-- Name: tax_types; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE tax_types (
    tax_type_id integer NOT NULL,
    account_id integer,
    currency_id integer,
    use_key_id integer NOT NULL,
    sys_country_id character(2),
    org_id integer,
    tax_type_name character varying(50) NOT NULL,
    tax_type_number character varying(50),
    formural character varying(320),
    tax_relief real DEFAULT 0 NOT NULL,
    tax_type_order integer DEFAULT 0 NOT NULL,
    in_tax boolean DEFAULT false NOT NULL,
    tax_rate real DEFAULT 0 NOT NULL,
    tax_inclusive boolean DEFAULT false NOT NULL,
    linear boolean DEFAULT true,
    percentage boolean DEFAULT true,
    employer double precision DEFAULT 0 NOT NULL,
    employer_ps double precision DEFAULT 0 NOT NULL,
    account_number character varying(32),
    employer_account character varying(32),
    active boolean DEFAULT true,
    details text
);


ALTER TABLE public.tax_types OWNER TO postgres;

--
-- Name: tax_types_tax_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE tax_types_tax_type_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tax_types_tax_type_id_seq OWNER TO postgres;

--
-- Name: tax_types_tax_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE tax_types_tax_type_id_seq OWNED BY tax_types.tax_type_id;


--
-- Name: tender_items; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE tender_items (
    tender_item_id integer NOT NULL,
    org_id integer,
    bidder_id integer,
    tender_item_name character varying(320) NOT NULL,
    quantity integer,
    item_amount real,
    item_tax real,
    details text
);


ALTER TABLE public.tender_items OWNER TO postgres;

--
-- Name: tender_items_tender_item_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE tender_items_tender_item_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tender_items_tender_item_id_seq OWNER TO postgres;

--
-- Name: tender_items_tender_item_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE tender_items_tender_item_id_seq OWNED BY tender_items.tender_item_id;


--
-- Name: tender_types; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE tender_types (
    tender_type_id integer NOT NULL,
    org_id integer,
    tender_type_name character varying(50),
    details text
);


ALTER TABLE public.tender_types OWNER TO postgres;

--
-- Name: tender_types_tender_type_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE tender_types_tender_type_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tender_types_tender_type_id_seq OWNER TO postgres;

--
-- Name: tender_types_tender_type_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE tender_types_tender_type_id_seq OWNED BY tender_types.tender_type_id;


--
-- Name: tenders; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE tenders (
    tender_id integer NOT NULL,
    org_id integer,
    tender_type_id integer,
    tender_name character varying(320),
    tender_number character varying(64),
    tender_date date NOT NULL,
    tender_end_date date,
    is_completed boolean DEFAULT false NOT NULL,
    details text
);


ALTER TABLE public.tenders OWNER TO postgres;

--
-- Name: tenders_tender_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE tenders_tender_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.tenders_tender_id_seq OWNER TO postgres;

--
-- Name: tenders_tender_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE tenders_tender_id_seq OWNED BY tenders.tender_id;


--
-- Name: timesheet; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE timesheet (
    timesheet_id integer NOT NULL,
    task_id integer,
    org_id integer,
    ts_date date NOT NULL,
    ts_start_time time without time zone NOT NULL,
    ts_end_time time without time zone NOT NULL,
    ts_narrative character varying(320),
    details text
);


ALTER TABLE public.timesheet OWNER TO postgres;

--
-- Name: timesheet_timesheet_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE timesheet_timesheet_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.timesheet_timesheet_id_seq OWNER TO postgres;

--
-- Name: timesheet_timesheet_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE timesheet_timesheet_id_seq OWNED BY timesheet.timesheet_id;


--
-- Name: tomcat_users; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW tomcat_users AS
 SELECT entitys.user_name,
    entitys.entity_password,
    entity_types.entity_role
   FROM ((entity_subscriptions
     JOIN entitys ON ((entity_subscriptions.entity_id = entitys.entity_id)))
     JOIN entity_types ON ((entity_subscriptions.entity_type_id = entity_types.entity_type_id)))
  WHERE (entitys.is_active = true);


ALTER TABLE public.tomcat_users OWNER TO postgres;

--
-- Name: trainings; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE trainings (
    training_id integer NOT NULL,
    org_id integer,
    training_name character varying(50),
    start_date date,
    end_date date,
    training_cost real,
    completed boolean DEFAULT false NOT NULL,
    application_date timestamp without time zone DEFAULT now(),
    approve_status character varying(16) DEFAULT 'Draft'::character varying NOT NULL,
    workflow_table_id integer,
    action_date timestamp without time zone,
    details text
);


ALTER TABLE public.trainings OWNER TO postgres;

--
-- Name: trainings_training_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE trainings_training_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.trainings_training_id_seq OWNER TO postgres;

--
-- Name: trainings_training_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE trainings_training_id_seq OWNED BY trainings.training_id;


--
-- Name: transaction_counters; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE transaction_counters (
    transaction_counter_id integer NOT NULL,
    transaction_type_id integer,
    org_id integer,
    document_number integer DEFAULT 1 NOT NULL
);


ALTER TABLE public.transaction_counters OWNER TO postgres;

--
-- Name: transaction_counters_transaction_counter_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE transaction_counters_transaction_counter_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.transaction_counters_transaction_counter_id_seq OWNER TO postgres;

--
-- Name: transaction_counters_transaction_counter_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE transaction_counters_transaction_counter_id_seq OWNED BY transaction_counters.transaction_counter_id;


--
-- Name: transaction_details; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE transaction_details (
    transaction_detail_id integer NOT NULL,
    transaction_id integer,
    account_id integer,
    item_id integer,
    store_id integer,
    org_id integer,
    quantity integer NOT NULL,
    amount real DEFAULT 0 NOT NULL,
    tax_amount real DEFAULT 0 NOT NULL,
    narrative character varying(240),
    purpose character varying(320),
    details text
);


ALTER TABLE public.transaction_details OWNER TO postgres;

--
-- Name: transaction_details_transaction_detail_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE transaction_details_transaction_detail_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.transaction_details_transaction_detail_id_seq OWNER TO postgres;

--
-- Name: transaction_details_transaction_detail_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE transaction_details_transaction_detail_id_seq OWNED BY transaction_details.transaction_detail_id;


--
-- Name: transaction_links; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE transaction_links (
    transaction_link_id integer NOT NULL,
    org_id integer,
    transaction_id integer,
    transaction_to integer,
    transaction_detail_id integer,
    transaction_detail_to integer,
    amount real DEFAULT 0 NOT NULL,
    quantity integer DEFAULT 0 NOT NULL,
    narrative character varying(240)
);


ALTER TABLE public.transaction_links OWNER TO postgres;

--
-- Name: transaction_links_transaction_link_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE transaction_links_transaction_link_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.transaction_links_transaction_link_id_seq OWNER TO postgres;

--
-- Name: transaction_links_transaction_link_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE transaction_links_transaction_link_id_seq OWNED BY transaction_links.transaction_link_id;


--
-- Name: transaction_status; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE transaction_status (
    transaction_status_id integer NOT NULL,
    transaction_status_name character varying(50) NOT NULL
);


ALTER TABLE public.transaction_status OWNER TO postgres;

--
-- Name: transaction_types; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE transaction_types (
    transaction_type_id integer NOT NULL,
    transaction_type_name character varying(50) NOT NULL,
    document_prefix character varying(16) DEFAULT 'D'::character varying NOT NULL,
    for_sales boolean DEFAULT true NOT NULL,
    for_posting boolean DEFAULT true NOT NULL
);


ALTER TABLE public.transaction_types OWNER TO postgres;

--
-- Name: transactions; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE transactions (
    transaction_id integer NOT NULL,
    entity_id integer,
    transaction_type_id integer,
    ledger_type_id integer,
    transaction_status_id integer DEFAULT 1,
    bank_account_id integer,
    journal_id integer,
    currency_id integer,
    department_id integer,
    entered_by integer,
    org_id integer,
    exchange_rate real DEFAULT 1 NOT NULL,
    transaction_date date NOT NULL,
    payment_date date NOT NULL,
    transaction_amount real DEFAULT 0 NOT NULL,
    transaction_tax_amount real DEFAULT 0 NOT NULL,
    document_number integer DEFAULT 1 NOT NULL,
    tx_type integer,
    for_processing boolean DEFAULT false NOT NULL,
    is_cleared boolean DEFAULT false NOT NULL,
    completed boolean DEFAULT false NOT NULL,
    reference_number character varying(50),
    payment_number character varying(50),
    order_number character varying(50),
    payment_terms character varying(50),
    job character varying(240),
    point_of_use character varying(240),
    application_date timestamp without time zone DEFAULT now(),
    approve_status character varying(16) DEFAULT 'Draft'::character varying NOT NULL,
    workflow_table_id integer,
    action_date timestamp without time zone,
    narrative character varying(120),
    details text
);


ALTER TABLE public.transactions OWNER TO postgres;

--
-- Name: transactions_transaction_id_seq; Type: SEQUENCE; Schema: public; Owner: postgres
--

CREATE SEQUENCE transactions_transaction_id_seq
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.transactions_transaction_id_seq OWNER TO postgres;

--
-- Name: transactions_transaction_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: postgres
--

ALTER SEQUENCE transactions_transaction_id_seq OWNED BY transactions.transaction_id;


--
-- Name: use_keys; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE use_keys (
    use_key_id integer NOT NULL,
    use_key_name character varying(32) NOT NULL,
    use_function integer
);


ALTER TABLE public.use_keys OWNER TO postgres;

--
-- Name: vw_account_types; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_account_types AS
 SELECT account_class.account_class_id,
    account_class.account_class_no,
    account_class.account_class_name,
    account_class.chat_type_id,
    account_class.chat_type_name,
    account_types.account_type_id,
    account_types.account_type_no,
    account_types.org_id,
    account_types.account_type_name,
    account_types.details
   FROM (account_types
     JOIN account_class ON ((account_types.account_class_id = account_class.account_class_id)));


ALTER TABLE public.vw_account_types OWNER TO postgres;

--
-- Name: vw_accounts; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_accounts AS
 SELECT vw_account_types.chat_type_id,
    vw_account_types.chat_type_name,
    vw_account_types.account_class_id,
    vw_account_types.account_class_no,
    vw_account_types.account_class_name,
    vw_account_types.account_type_id,
    vw_account_types.account_type_no,
    vw_account_types.account_type_name,
    accounts.account_id,
    accounts.account_no,
    accounts.org_id,
    accounts.account_name,
    accounts.is_header,
    accounts.is_active,
    accounts.details,
    ((((((accounts.account_no || ' : '::text) || (vw_account_types.account_class_name)::text) || ' : '::text) || (vw_account_types.account_type_name)::text) || ' : '::text) || (accounts.account_name)::text) AS account_description
   FROM (accounts
     JOIN vw_account_types ON ((accounts.account_type_id = vw_account_types.account_type_id)));


ALTER TABLE public.vw_accounts OWNER TO postgres;

--
-- Name: vw_address; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_address AS
 SELECT sys_countrys.sys_country_id,
    sys_countrys.sys_country_name,
    address.address_id,
    address.org_id,
    address.address_name,
    address.table_name,
    address.table_id,
    address.post_office_box,
    address.postal_code,
    address.premises,
    address.street,
    address.town,
    address.phone_number,
    address.extension,
    address.mobile,
    address.fax,
    address.email,
    address.is_default,
    address.website,
    address.details,
    address_types.address_type_id,
    address_types.address_type_name
   FROM ((address
     JOIN sys_countrys ON ((address.sys_country_id = sys_countrys.sys_country_id)))
     LEFT JOIN address_types ON ((address.address_type_id = address_types.address_type_id)));


ALTER TABLE public.vw_address OWNER TO postgres;

--
-- Name: vw_address_entitys; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_address_entitys AS
 SELECT vw_address.address_id,
    vw_address.address_name,
    vw_address.table_id,
    vw_address.table_name,
    vw_address.sys_country_id,
    vw_address.sys_country_name,
    vw_address.is_default,
    vw_address.post_office_box,
    vw_address.postal_code,
    vw_address.premises,
    vw_address.street,
    vw_address.town,
    vw_address.phone_number,
    vw_address.extension,
    vw_address.mobile,
    vw_address.fax,
    vw_address.email,
    vw_address.website
   FROM vw_address
  WHERE (((vw_address.table_name)::text = 'entitys'::text) AND (vw_address.is_default = true));


ALTER TABLE public.vw_address_entitys OWNER TO postgres;

--
-- Name: vw_adjustments; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_adjustments AS
 SELECT currency.currency_id,
    currency.currency_name,
    currency.currency_symbol,
    adjustments.org_id,
    adjustments.adjustment_id,
    adjustments.adjustment_name,
    adjustments.adjustment_type,
    adjustments.adjustment_order,
    adjustments.earning_code,
    adjustments.formural,
    adjustments.monthly_update,
    adjustments.in_payroll,
    adjustments.in_tax,
    adjustments.visible,
    adjustments.running_balance,
    adjustments.reduce_balance,
    adjustments.tax_reduction_ps,
    adjustments.tax_relief_ps,
    adjustments.tax_max_allowed,
    adjustments.account_number,
    adjustments.details
   FROM (adjustments
     JOIN currency ON ((adjustments.currency_id = currency.currency_id)));


ALTER TABLE public.vw_adjustments OWNER TO postgres;

--
-- Name: vw_periods; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_periods AS
 SELECT fiscal_years.fiscal_year_id,
    fiscal_years.fiscal_year,
    fiscal_years.fiscal_year_start,
    fiscal_years.fiscal_year_end,
    fiscal_years.year_opened,
    fiscal_years.year_closed,
    periods.period_id,
    periods.org_id,
    periods.start_date,
    periods.end_date,
    periods.opened,
    periods.activated,
    periods.closed,
    periods.overtime_rate,
    periods.per_diem_tax_limit,
    periods.is_posted,
    periods.gl_payroll_account,
    periods.gl_advance_account,
    periods.details,
    date_part('month'::text, periods.start_date) AS month_id,
    to_char((periods.start_date)::timestamp with time zone, 'YYYY'::text) AS period_year,
    to_char((periods.start_date)::timestamp with time zone, 'Month'::text) AS period_month,
    to_char((periods.start_date)::timestamp with time zone, 'YYYY, Month'::text) AS period_disp,
    (trunc(((date_part('month'::text, periods.start_date) - (1)::double precision) / (3)::double precision)) + (1)::double precision) AS quarter,
    (trunc(((date_part('month'::text, periods.start_date) - (1)::double precision) / (6)::double precision)) + (1)::double precision) AS semister,
    to_char((periods.start_date)::timestamp with time zone, 'YYYYMM'::text) AS period_code
   FROM (periods
     LEFT JOIN fiscal_years ON ((periods.fiscal_year_id = fiscal_years.fiscal_year_id)))
  ORDER BY periods.start_date;


ALTER TABLE public.vw_periods OWNER TO postgres;

--
-- Name: vw_employee_month_list; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_employee_month_list AS
 SELECT vw_periods.period_id,
    vw_periods.start_date,
    vw_periods.end_date,
    vw_periods.overtime_rate,
    vw_periods.activated,
    vw_periods.closed,
    vw_periods.month_id,
    vw_periods.period_year,
    vw_periods.period_month,
    vw_periods.quarter,
    vw_periods.semister,
    vw_periods.gl_payroll_account,
    vw_periods.is_posted,
    entitys.entity_id,
    entitys.entity_name,
    pay_groups.pay_group_id,
    pay_groups.pay_group_name,
    pay_groups.gl_payment_account,
    pay_groups.bank_header,
    pay_groups.bank_address,
    employees.employee_id,
    employees.surname,
    employees.first_name,
    employees.middle_name,
    employees.date_of_birth,
    employees.gender,
    employees.nationality,
    employees.marital_status,
    employees.appointment_date,
    employees.exit_date,
    employees.contract,
    employees.contract_period,
    employees.employment_terms,
    employees.identity_card,
    (((((employees.surname)::text || ' '::text) || (employees.first_name)::text) || ' '::text) || (COALESCE(employees.middle_name, ''::character varying))::text) AS employee_name,
    departments.department_id,
    departments.department_name,
    departments.department_account,
    departments.function_code,
    department_roles.department_role_id,
    department_roles.department_role_name,
    employee_month.org_id,
    employee_month.employee_month_id,
    employee_month.bank_account,
    employee_month.basic_pay,
    employee_month.currency_id,
    employee_month.exchange_rate
   FROM ((((((employee_month
     JOIN vw_periods ON ((employee_month.period_id = vw_periods.period_id)))
     JOIN pay_groups ON ((employee_month.pay_group_id = pay_groups.pay_group_id)))
     JOIN entitys ON ((employee_month.entity_id = entitys.entity_id)))
     JOIN employees ON ((employee_month.entity_id = employees.entity_id)))
     JOIN department_roles ON ((employee_month.department_role_id = department_roles.department_role_id)))
     JOIN departments ON ((department_roles.department_id = departments.department_id)));


ALTER TABLE public.vw_employee_month_list OWNER TO postgres;

--
-- Name: vw_advance_deductions; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_advance_deductions AS
 SELECT eml.employee_month_id,
    eml.period_id,
    eml.start_date,
    eml.end_date,
    eml.month_id,
    eml.period_year,
    eml.period_month,
    eml.gl_payroll_account,
    eml.entity_id,
    eml.entity_name,
    eml.employee_id,
    advance_deductions.org_id,
    advance_deductions.advance_deduction_id,
    advance_deductions.pay_date,
    advance_deductions.amount,
    advance_deductions.in_payroll,
    advance_deductions.narrative,
    (advance_deductions.amount * eml.exchange_rate) AS b_advance_deduction
   FROM (advance_deductions
     JOIN vw_employee_month_list eml ON ((advance_deductions.employee_month_id = eml.employee_month_id)));


ALTER TABLE public.vw_advance_deductions OWNER TO postgres;

--
-- Name: vw_advance_statement; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_advance_statement AS
 SELECT eml.employee_month_id,
    eml.period_id,
    eml.start_date,
    eml.month_id,
    eml.period_year,
    eml.period_month,
    eml.entity_id,
    eml.entity_name,
    eml.employee_id,
    employee_advances.org_id,
    employee_advances.pay_date,
    employee_advances.in_payroll,
    employee_advances.narrative,
    employee_advances.amount,
    (0)::real AS recovery
   FROM (employee_advances
     JOIN vw_employee_month_list eml ON ((employee_advances.employee_month_id = eml.employee_month_id)))
  WHERE ((employee_advances.approve_status)::text = 'Approved'::text)
UNION
 SELECT eml.employee_month_id,
    eml.period_id,
    eml.start_date,
    eml.month_id,
    eml.period_year,
    eml.period_month,
    eml.entity_id,
    eml.entity_name,
    eml.employee_id,
    advance_deductions.org_id,
    advance_deductions.pay_date,
    advance_deductions.in_payroll,
    advance_deductions.narrative,
    (0)::real AS amount,
    advance_deductions.amount AS recovery
   FROM (advance_deductions
     JOIN vw_employee_month_list eml ON ((advance_deductions.employee_month_id = eml.employee_month_id)));


ALTER TABLE public.vw_advance_statement OWNER TO postgres;

--
-- Name: vw_job_reviews; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_job_reviews AS
 SELECT entitys.entity_id,
    entitys.entity_name,
    review_category.review_category_id,
    review_category.review_category_name,
    review_category.rate_objectives,
    job_reviews.org_id,
    job_reviews.job_review_id,
    job_reviews.total_points,
    job_reviews.review_date,
    job_reviews.review_done,
    job_reviews.approve_status,
    job_reviews.workflow_table_id,
    job_reviews.application_date,
    job_reviews.action_date,
    job_reviews.recomendation,
    job_reviews.reviewer_comments,
    job_reviews.pl_comments,
    job_reviews.details,
    date_part('year'::text, job_reviews.review_date) AS review_year
   FROM ((job_reviews
     JOIN entitys ON ((job_reviews.entity_id = entitys.entity_id)))
     JOIN review_category ON ((job_reviews.review_category_id = review_category.review_category_id)));


ALTER TABLE public.vw_job_reviews OWNER TO postgres;

--
-- Name: vw_review_year; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_review_year AS
 SELECT vw_job_reviews.org_id,
    vw_job_reviews.review_year
   FROM vw_job_reviews
  WHERE (vw_job_reviews.review_year IS NOT NULL)
  GROUP BY vw_job_reviews.org_id, vw_job_reviews.review_year;


ALTER TABLE public.vw_review_year OWNER TO postgres;

--
-- Name: vw_all_job_reviews; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_all_job_reviews AS
 SELECT a.org_id,
    a.review_year,
    a.entity_id,
    a.employee_id,
    a.employee_name,
    b.job_review_id,
    b.total_points,
    b.approve_status
   FROM (( SELECT vw_review_year.review_year,
            employees.org_id,
            employees.entity_id,
            employees.employee_id,
            (((((employees.surname)::text || ' '::text) || (employees.first_name)::text) || ' '::text) || (COALESCE(employees.middle_name, ''::character varying))::text) AS employee_name
           FROM (vw_review_year
             JOIN employees ON ((vw_review_year.org_id = employees.org_id)))
          WHERE (employees.active = true)) a
     LEFT JOIN ( SELECT vw_job_reviews.job_review_id,
            vw_job_reviews.total_points,
            vw_job_reviews.approve_status,
            vw_job_reviews.entity_id,
            vw_job_reviews.review_year
           FROM vw_job_reviews) b ON (((a.entity_id = b.entity_id) AND (a.review_year = b.review_year))));


ALTER TABLE public.vw_all_job_reviews OWNER TO postgres;

--
-- Name: vw_education_max; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_education_max AS
 SELECT education_class.education_class_id,
    education_class.education_class_name,
    education.org_id,
    education.education_id,
    education.entity_id,
    education.date_from,
    education.date_to,
    education.name_of_school,
    education.examination_taken,
    education.grades_obtained,
    education.certificate_number
   FROM ((education_class
     JOIN education ON ((education_class.education_class_id = education.education_class_id)))
     JOIN ( SELECT education_1.entity_id,
            max(education_1.education_id) AS max_education_id
           FROM (education education_1
             JOIN ( SELECT education_2.entity_id,
                    max(education_2.education_class_id) AS max_education_class_id
                   FROM education education_2
                  GROUP BY education_2.entity_id) a ON (((education_1.entity_id = a.entity_id) AND (education_1.education_class_id = a.max_education_class_id))))
          GROUP BY education_1.entity_id) b ON ((education.education_id = b.max_education_id)));


ALTER TABLE public.vw_education_max OWNER TO postgres;

--
-- Name: vw_employment_max; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_employment_max AS
 SELECT employment.employment_id,
    employment.entity_id,
    employment.date_from,
    employment.date_to,
    employment.org_id,
    employment.employers_name,
    employment.position_held,
    age((COALESCE(employment.date_to, ('now'::text)::date))::timestamp with time zone, (employment.date_from)::timestamp with time zone) AS employment_duration,
    c.employment_experince
   FROM ((employment
     JOIN ( SELECT max(employment_1.employment_id) AS max_employment_id
           FROM (employment employment_1
             JOIN ( SELECT employment_2.entity_id,
                    max(employment_2.date_from) AS max_date_from
                   FROM employment employment_2
                  GROUP BY employment_2.entity_id) a ON (((employment_1.entity_id = a.entity_id) AND (employment_1.date_from = a.max_date_from))))
          GROUP BY employment_1.entity_id) b ON ((employment.employment_id = b.max_employment_id)))
     JOIN ( SELECT employment_1.entity_id,
            sum(age((COALESCE(employment_1.date_to, ('now'::text)::date))::timestamp with time zone, (employment_1.date_from)::timestamp with time zone)) AS employment_experince
           FROM employment employment_1
          GROUP BY employment_1.entity_id) c ON ((employment.entity_id = c.entity_id)));


ALTER TABLE public.vw_employment_max OWNER TO postgres;

--
-- Name: vw_applicants; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_applicants AS
 SELECT sys_countrys.sys_country_id,
    sys_countrys.sys_country_name,
    currency.currency_id,
    currency.currency_name,
    currency.currency_symbol,
    applicants.org_id,
    applicants.entity_id,
    applicants.surname,
    applicants.first_name,
    applicants.middle_name,
    applicants.date_of_birth,
    applicants.nationality,
    applicants.identity_card,
    applicants.language,
    applicants.objective,
    applicants.interests,
    applicants.picture_file,
    applicants.details,
    applicants.person_title,
    applicants.field_of_study,
    applicants.applicant_email,
    applicants.applicant_phone,
    applicants.previous_salary,
    applicants.expected_salary,
    (((((applicants.surname)::text || ' '::text) || (applicants.first_name)::text) || ' '::text) || (COALESCE(applicants.middle_name, ''::character varying))::text) AS applicant_name,
    to_char(age((applicants.date_of_birth)::timestamp with time zone), 'YY'::text) AS applicant_age,
        CASE
            WHEN ((applicants.gender)::text = 'M'::text) THEN 'Male'::text
            ELSE 'Female'::text
        END AS gender_name,
        CASE
            WHEN ((applicants.marital_status)::text = 'M'::text) THEN 'Married'::text
            ELSE 'Single'::text
        END AS marital_status_name,
    vw_education_max.education_class_id,
    vw_education_max.education_class_name,
    vw_education_max.education_id,
    vw_education_max.date_from,
    vw_education_max.date_to,
    vw_education_max.name_of_school,
    vw_education_max.examination_taken,
    vw_education_max.grades_obtained,
    vw_education_max.certificate_number,
    vw_employment_max.employers_name,
    vw_employment_max.position_held,
    vw_employment_max.date_from AS emp_date_from,
    vw_employment_max.date_to AS emp_date_to,
    vw_employment_max.employment_duration,
    vw_employment_max.employment_experince,
    round(((date_part('year'::text, vw_employment_max.employment_duration) + (date_part('month'::text, vw_employment_max.employment_duration) / (12)::double precision)))::numeric, 1) AS emp_duration,
    round(((date_part('year'::text, vw_employment_max.employment_experince) + (date_part('month'::text, vw_employment_max.employment_experince) / (12)::double precision)))::numeric, 1) AS emp_experince
   FROM ((((applicants
     JOIN sys_countrys ON ((applicants.nationality = sys_countrys.sys_country_id)))
     LEFT JOIN vw_education_max ON ((applicants.entity_id = vw_education_max.entity_id)))
     LEFT JOIN vw_employment_max ON ((applicants.entity_id = vw_employment_max.entity_id)))
     LEFT JOIN currency ON ((applicants.currency_id = currency.currency_id)));


ALTER TABLE public.vw_applicants OWNER TO postgres;

--
-- Name: vw_department_roles; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_department_roles AS
 SELECT departments.department_id,
    departments.department_name,
    departments.description AS department_description,
    departments.duties AS department_duties,
    ln_department_roles.department_role_name AS parent_role_name,
    jobs_category.jobs_category_id,
    jobs_category.jobs_category,
    department_roles.org_id,
    department_roles.department_role_id,
    department_roles.ln_department_role_id,
    department_roles.department_role_name,
    department_roles.job_description,
    department_roles.job_requirements,
    department_roles.duties,
    department_roles.performance_measures,
    department_roles.active,
    department_roles.details
   FROM (((department_roles
     JOIN departments ON ((department_roles.department_id = departments.department_id)))
     LEFT JOIN department_roles ln_department_roles ON ((department_roles.ln_department_role_id = ln_department_roles.department_role_id)))
     LEFT JOIN jobs_category ON ((jobs_category.jobs_category_id = department_roles.jobs_category_id)));


ALTER TABLE public.vw_department_roles OWNER TO postgres;

--
-- Name: vw_intake; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_intake AS
 SELECT vw_department_roles.department_id,
    vw_department_roles.department_name,
    vw_department_roles.department_description,
    vw_department_roles.department_duties,
    vw_department_roles.department_role_id,
    vw_department_roles.department_role_name,
    vw_department_roles.parent_role_name,
    vw_department_roles.jobs_category_id,
    vw_department_roles.jobs_category,
    vw_department_roles.job_description,
    vw_department_roles.job_requirements,
    vw_department_roles.duties,
    vw_department_roles.performance_measures,
    locations.location_id,
    locations.location_name,
    pay_groups.pay_group_id,
    pay_groups.pay_group_name,
    pay_scales.pay_scale_id,
    pay_scales.pay_scale_name,
    orgs.org_name,
    orgs.details AS org_detail,
    intake.org_id,
    intake.intake_id,
    intake.opening_date,
    intake.closing_date,
    intake.positions,
    intake.contract,
    intake.contract_period,
    intake.details,
    (((((vw_department_roles.department_name)::text || ', '::text) || (vw_department_roles.department_role_name)::text) || ', '::text) || to_char((intake.opening_date)::timestamp with time zone, 'YYYY, Mon'::text)) AS intake_disp
   FROM (((((intake
     JOIN vw_department_roles ON ((intake.department_role_id = vw_department_roles.department_role_id)))
     JOIN locations ON ((intake.location_id = locations.location_id)))
     JOIN pay_groups ON ((intake.pay_group_id = pay_groups.pay_group_id)))
     JOIN pay_scales ON ((intake.pay_scale_id = pay_scales.pay_scale_id)))
     JOIN orgs ON ((intake.org_id = orgs.org_id)));


ALTER TABLE public.vw_intake OWNER TO postgres;

--
-- Name: vw_applications; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_applications AS
 SELECT vw_intake.department_id,
    vw_intake.department_name,
    vw_intake.department_description,
    vw_intake.department_duties,
    vw_intake.department_role_id,
    vw_intake.department_role_name,
    vw_intake.parent_role_name,
    vw_intake.job_description,
    vw_intake.job_requirements,
    vw_intake.duties,
    vw_intake.performance_measures,
    vw_intake.intake_id,
    vw_intake.opening_date,
    vw_intake.closing_date,
    vw_intake.positions,
    vw_intake.org_name,
    vw_intake.org_detail,
    entitys.entity_id,
    entitys.entity_name,
    entitys.primary_email,
    currency.currency_id,
    currency.currency_name,
    currency.currency_symbol,
    applications.org_id,
    applications.application_id,
    applications.employee_id,
    applications.contract_date,
    applications.contract_close,
    applications.contract_start,
    applications.contract_period,
    applications.contract_terms,
    applications.initial_salary,
    applications.application_date,
    applications.approve_status,
    applications.workflow_table_id,
    applications.action_date,
    applications.applicant_comments,
    applications.review,
    applications.short_listed,
    applications.previous_salary,
    applications.expected_salary,
    applications.exchange_rate,
    applications.review_rating,
    vw_education_max.education_class_name,
    vw_education_max.date_from,
    vw_education_max.date_to,
    vw_education_max.name_of_school,
    vw_education_max.examination_taken,
    vw_education_max.grades_obtained,
    vw_education_max.certificate_number,
    vw_employment_max.employment_id,
    vw_employment_max.employers_name,
    vw_employment_max.position_held,
    vw_employment_max.date_from AS emp_date_from,
    vw_employment_max.date_to AS emp_date_to,
    vw_employment_max.employment_duration,
    vw_employment_max.employment_experince,
    round(((date_part('year'::text, vw_employment_max.employment_duration) + (date_part('month'::text, vw_employment_max.employment_duration) / (12)::double precision)))::numeric, 1) AS emp_duration,
    round(((date_part('year'::text, vw_employment_max.employment_experince) + (date_part('month'::text, vw_employment_max.employment_experince) / (12)::double precision)))::numeric, 1) AS emp_experince
   FROM (((((applications
     JOIN entitys ON ((applications.entity_id = entitys.entity_id)))
     JOIN vw_intake ON ((applications.intake_id = vw_intake.intake_id)))
     LEFT JOIN vw_education_max ON ((entitys.entity_id = vw_education_max.entity_id)))
     LEFT JOIN vw_employment_max ON ((entitys.entity_id = vw_employment_max.entity_id)))
     LEFT JOIN currency ON ((applications.currency_id = currency.currency_id)));


ALTER TABLE public.vw_applications OWNER TO postgres;

--
-- Name: workflows; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE workflows (
    workflow_id integer NOT NULL,
    source_entity_id integer NOT NULL,
    org_id integer,
    workflow_name character varying(240) NOT NULL,
    table_name character varying(64),
    table_link_field character varying(64),
    table_link_id integer,
    approve_email text NOT NULL,
    reject_email text NOT NULL,
    approve_file character varying(320),
    reject_file character varying(320),
    link_copy integer,
    details text
);


ALTER TABLE public.workflows OWNER TO postgres;

--
-- Name: vw_workflows; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_workflows AS
 SELECT entity_types.entity_type_id AS source_entity_id,
    entity_types.entity_type_name AS source_entity_name,
    workflows.workflow_id,
    workflows.org_id,
    workflows.workflow_name,
    workflows.table_name,
    workflows.table_link_field,
    workflows.table_link_id,
    workflows.approve_email,
    workflows.reject_email,
    workflows.approve_file,
    workflows.reject_file,
    workflows.details
   FROM (workflows
     JOIN entity_types ON ((workflows.source_entity_id = entity_types.entity_type_id)));


ALTER TABLE public.vw_workflows OWNER TO postgres;

--
-- Name: workflow_phases; Type: TABLE; Schema: public; Owner: postgres; Tablespace: 
--

CREATE TABLE workflow_phases (
    workflow_phase_id integer NOT NULL,
    workflow_id integer NOT NULL,
    approval_entity_id integer NOT NULL,
    org_id integer,
    approval_level integer DEFAULT 1 NOT NULL,
    return_level integer DEFAULT 1 NOT NULL,
    escalation_days integer DEFAULT 0 NOT NULL,
    escalation_hours integer DEFAULT 3 NOT NULL,
    required_approvals integer DEFAULT 1 NOT NULL,
    reporting_level integer DEFAULT 1 NOT NULL,
    use_reporting boolean DEFAULT false NOT NULL,
    advice boolean DEFAULT false NOT NULL,
    notice boolean DEFAULT false NOT NULL,
    phase_narrative character varying(240) NOT NULL,
    advice_email text,
    notice_email text,
    advice_file character varying(320),
    notice_file character varying(320),
    details text
);


ALTER TABLE public.workflow_phases OWNER TO postgres;

--
-- Name: vw_workflow_phases; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_workflow_phases AS
 SELECT vw_workflows.source_entity_id,
    vw_workflows.source_entity_name,
    vw_workflows.workflow_id,
    vw_workflows.workflow_name,
    vw_workflows.table_name,
    vw_workflows.table_link_field,
    vw_workflows.table_link_id,
    vw_workflows.approve_email,
    vw_workflows.reject_email,
    vw_workflows.approve_file,
    vw_workflows.reject_file,
    entity_types.entity_type_id AS approval_entity_id,
    entity_types.entity_type_name AS approval_entity_name,
    workflow_phases.workflow_phase_id,
    workflow_phases.org_id,
    workflow_phases.approval_level,
    workflow_phases.return_level,
    workflow_phases.escalation_days,
    workflow_phases.escalation_hours,
    workflow_phases.notice,
    workflow_phases.notice_email,
    workflow_phases.notice_file,
    workflow_phases.advice,
    workflow_phases.advice_email,
    workflow_phases.advice_file,
    workflow_phases.required_approvals,
    workflow_phases.use_reporting,
    workflow_phases.reporting_level,
    workflow_phases.phase_narrative,
    workflow_phases.details
   FROM ((workflow_phases
     JOIN vw_workflows ON ((workflow_phases.workflow_id = vw_workflows.workflow_id)))
     JOIN entity_types ON ((workflow_phases.approval_entity_id = entity_types.entity_type_id)));


ALTER TABLE public.vw_workflow_phases OWNER TO postgres;

--
-- Name: vw_approvals; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_approvals AS
 SELECT vw_workflow_phases.workflow_id,
    vw_workflow_phases.workflow_name,
    vw_workflow_phases.approve_email,
    vw_workflow_phases.reject_email,
    vw_workflow_phases.source_entity_id,
    vw_workflow_phases.source_entity_name,
    vw_workflow_phases.approval_entity_id,
    vw_workflow_phases.approval_entity_name,
    vw_workflow_phases.workflow_phase_id,
    vw_workflow_phases.approval_level,
    vw_workflow_phases.phase_narrative,
    vw_workflow_phases.return_level,
    vw_workflow_phases.required_approvals,
    vw_workflow_phases.notice,
    vw_workflow_phases.notice_email,
    vw_workflow_phases.notice_file,
    vw_workflow_phases.advice,
    vw_workflow_phases.advice_email,
    vw_workflow_phases.advice_file,
    vw_workflow_phases.use_reporting,
    approvals.approval_id,
    approvals.org_id,
    approvals.forward_id,
    approvals.table_name,
    approvals.table_id,
    approvals.completion_date,
    approvals.escalation_days,
    approvals.escalation_hours,
    approvals.escalation_time,
    approvals.application_date,
    approvals.approve_status,
    approvals.action_date,
    approvals.approval_narrative,
    approvals.to_be_done,
    approvals.what_is_done,
    approvals.review_advice,
    approvals.details,
    oe.entity_id AS org_entity_id,
    oe.entity_name AS org_entity_name,
    oe.user_name AS org_user_name,
    oe.primary_email AS org_primary_email,
    ae.entity_id AS app_entity_id,
    ae.entity_name AS app_entity_name,
    ae.user_name AS app_user_name,
    ae.primary_email AS app_primary_email
   FROM (((vw_workflow_phases
     JOIN approvals ON ((vw_workflow_phases.workflow_phase_id = approvals.workflow_phase_id)))
     JOIN entitys oe ON ((approvals.org_entity_id = oe.entity_id)))
     LEFT JOIN entitys ae ON ((approvals.app_entity_id = ae.entity_id)));


ALTER TABLE public.vw_approvals OWNER TO postgres;

--
-- Name: vw_approvals_entitys; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_approvals_entitys AS
 SELECT vw_workflow_phases.workflow_id,
    vw_workflow_phases.workflow_name,
    vw_workflow_phases.source_entity_id,
    vw_workflow_phases.source_entity_name,
    vw_workflow_phases.approval_entity_id,
    vw_workflow_phases.approval_entity_name,
    vw_workflow_phases.workflow_phase_id,
    vw_workflow_phases.approval_level,
    vw_workflow_phases.notice,
    vw_workflow_phases.notice_email,
    vw_workflow_phases.notice_file,
    vw_workflow_phases.advice,
    vw_workflow_phases.advice_email,
    vw_workflow_phases.advice_file,
    vw_workflow_phases.return_level,
    vw_workflow_phases.required_approvals,
    vw_workflow_phases.phase_narrative,
    vw_workflow_phases.use_reporting,
    approvals.approval_id,
    approvals.org_id,
    approvals.forward_id,
    approvals.table_name,
    approvals.table_id,
    approvals.completion_date,
    approvals.escalation_days,
    approvals.escalation_hours,
    approvals.escalation_time,
    approvals.application_date,
    approvals.approve_status,
    approvals.action_date,
    approvals.approval_narrative,
    approvals.to_be_done,
    approvals.what_is_done,
    approvals.review_advice,
    approvals.details,
    oe.entity_id AS org_entity_id,
    oe.entity_name AS org_entity_name,
    oe.user_name AS org_user_name,
    oe.primary_email AS org_primary_email,
    entitys.entity_id,
    entitys.entity_name,
    entitys.user_name,
    entitys.primary_email
   FROM ((((vw_workflow_phases
     JOIN approvals ON ((vw_workflow_phases.workflow_phase_id = approvals.workflow_phase_id)))
     JOIN entitys oe ON ((approvals.org_entity_id = oe.entity_id)))
     JOIN entity_subscriptions ON ((vw_workflow_phases.approval_entity_id = entity_subscriptions.entity_type_id)))
     JOIN entitys ON ((entity_subscriptions.entity_id = entitys.entity_id)))
  WHERE ((approvals.forward_id IS NULL) AND (vw_workflow_phases.use_reporting = false))
UNION
 SELECT vw_workflow_phases.workflow_id,
    vw_workflow_phases.workflow_name,
    vw_workflow_phases.source_entity_id,
    vw_workflow_phases.source_entity_name,
    vw_workflow_phases.approval_entity_id,
    vw_workflow_phases.approval_entity_name,
    vw_workflow_phases.workflow_phase_id,
    vw_workflow_phases.approval_level,
    vw_workflow_phases.notice,
    vw_workflow_phases.notice_email,
    vw_workflow_phases.notice_file,
    vw_workflow_phases.advice,
    vw_workflow_phases.advice_email,
    vw_workflow_phases.advice_file,
    vw_workflow_phases.return_level,
    vw_workflow_phases.required_approvals,
    vw_workflow_phases.phase_narrative,
    vw_workflow_phases.use_reporting,
    approvals.approval_id,
    approvals.org_id,
    approvals.forward_id,
    approvals.table_name,
    approvals.table_id,
    approvals.completion_date,
    approvals.escalation_days,
    approvals.escalation_hours,
    approvals.escalation_time,
    approvals.application_date,
    approvals.approve_status,
    approvals.action_date,
    approvals.approval_narrative,
    approvals.to_be_done,
    approvals.what_is_done,
    approvals.review_advice,
    approvals.details,
    oe.entity_id AS org_entity_id,
    oe.entity_name AS org_entity_name,
    oe.user_name AS org_user_name,
    oe.primary_email AS org_primary_email,
    entitys.entity_id,
    entitys.entity_name,
    entitys.user_name,
    entitys.primary_email
   FROM ((((vw_workflow_phases
     JOIN approvals ON ((vw_workflow_phases.workflow_phase_id = approvals.workflow_phase_id)))
     JOIN entitys oe ON ((approvals.org_entity_id = oe.entity_id)))
     JOIN reporting ON (((approvals.org_entity_id = reporting.entity_id) AND (vw_workflow_phases.reporting_level = reporting.reporting_level))))
     JOIN entitys ON ((reporting.report_to_id = entitys.entity_id)))
  WHERE ((((approvals.forward_id IS NULL) AND (reporting.primary_report = true)) AND (reporting.is_active = true)) AND (vw_workflow_phases.use_reporting = true));


ALTER TABLE public.vw_approvals_entitys OWNER TO postgres;

--
-- Name: vw_aptitude_grades; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_aptitude_grades AS
 SELECT aptitude_tests.aptitude_test_id,
    aptitude_tests.aptitude_test_name,
    aptitude_tests.pass_mark,
    aptitude_grades.user_id,
    entitys.user_name,
    entitys.entity_name,
    aptitude_grades.graded_by,
    grader_entity.entity_name AS graded_by_name,
    aptitude_grades.aptitude_grade_id,
    aptitude_grades.grade,
    aptitude_grades.date_taken,
    aptitude_grades.date_graded,
    aptitude_grades.org_id
   FROM (((aptitude_grades
     JOIN aptitude_tests ON ((aptitude_grades.aptitude_test_id = aptitude_tests.aptitude_test_id)))
     JOIN entitys ON ((entitys.entity_id = aptitude_grades.user_id)))
     LEFT JOIN entitys grader_entity ON ((grader_entity.entity_id = aptitude_grades.user_id)));


ALTER TABLE public.vw_aptitude_grades OWNER TO postgres;

--
-- Name: vw_aptitude_ongoing; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_aptitude_ongoing AS
 SELECT aptitude_ongoing.aptitude_ongoing_id,
    aptitude_tests.aptitude_test_name AS aptitude_test_id,
    entitys.entity_name AS user_id
   FROM ((aptitude_ongoing
     JOIN entitys ON (((entitys.user_name)::bpchar = aptitude_ongoing.user_id)))
     JOIN aptitude_tests ON ((aptitude_tests.aptitude_test_id = aptitude_ongoing.aptitude_test_id)));


ALTER TABLE public.vw_aptitude_ongoing OWNER TO postgres;

--
-- Name: vw_asset_movement; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_asset_movement AS
 SELECT departments.department_id,
    departments.department_name,
    asset_movement.asset_movement_id,
    asset_movement.asset_id,
    asset_movement.org_id,
    asset_movement.date_aquired,
    asset_movement.date_left,
    asset_movement.details
   FROM (asset_movement
     JOIN departments ON ((asset_movement.department_id = departments.department_id)));


ALTER TABLE public.vw_asset_movement OWNER TO postgres;

--
-- Name: vw_assets; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_assets AS
 SELECT asset_types.asset_type_id,
    asset_types.asset_type_name,
    items.item_id,
    items.item_name,
    assets.asset_id,
    assets.org_id,
    assets.asset_name,
    assets.asset_serial,
    assets.purchase_date,
    assets.purchase_value,
    assets.disposal_amount,
    assets.disposal_date,
    assets.disposal_posting,
    assets.lost,
    assets.stolen,
    assets.tag_number,
    assets.asset_location,
    assets.asset_condition,
    assets.asset_acquisition,
    assets.details
   FROM ((assets
     JOIN asset_types ON ((assets.asset_type_id = asset_types.asset_type_id)))
     JOIN items ON ((assets.item_id = items.item_id)));


ALTER TABLE public.vw_assets OWNER TO postgres;

--
-- Name: vw_attendance; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_attendance AS
 SELECT entitys.entity_id,
    entitys.entity_name,
    attendance.attendance_id,
    attendance.attendance_date,
    attendance.org_id,
    attendance.time_in,
    attendance.time_out,
    attendance.details,
    to_char((attendance.attendance_date)::timestamp with time zone, 'YYYYMM'::text) AS a_month,
    date_part('week'::text, attendance.attendance_date) AS a_week,
    date_part('dow'::text, attendance.attendance_date) AS a_dow
   FROM (attendance
     JOIN entitys ON ((attendance.entity_id = entitys.entity_id)));


ALTER TABLE public.vw_attendance OWNER TO postgres;

--
-- Name: vw_bank_branch; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_bank_branch AS
 SELECT sys_countrys.sys_country_id,
    sys_countrys.sys_country_code,
    sys_countrys.sys_country_name,
    banks.bank_id,
    banks.bank_name,
    banks.bank_code,
    banks.swift_code,
    banks.sort_code,
    bank_branch.bank_branch_id,
    bank_branch.org_id,
    bank_branch.bank_branch_name,
    bank_branch.bank_branch_code,
    bank_branch.narrative
   FROM ((bank_branch
     JOIN banks ON ((bank_branch.bank_id = banks.bank_id)))
     LEFT JOIN sys_countrys ON ((banks.sys_country_id = sys_countrys.sys_country_id)));


ALTER TABLE public.vw_bank_branch OWNER TO postgres;

--
-- Name: vw_bank_accounts; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_bank_accounts AS
 SELECT vw_bank_branch.bank_id,
    vw_bank_branch.bank_name,
    vw_bank_branch.bank_branch_id,
    vw_bank_branch.bank_branch_name,
    vw_accounts.account_type_id,
    vw_accounts.account_type_name,
    vw_accounts.account_id,
    vw_accounts.account_name,
    currency.currency_id,
    currency.currency_name,
    currency.currency_symbol,
    bank_accounts.bank_account_id,
    bank_accounts.org_id,
    bank_accounts.bank_account_name,
    bank_accounts.bank_account_number,
    bank_accounts.narrative,
    bank_accounts.is_active,
    bank_accounts.details
   FROM (((bank_accounts
     JOIN vw_bank_branch ON ((bank_accounts.bank_branch_id = vw_bank_branch.bank_branch_id)))
     JOIN vw_accounts ON ((bank_accounts.account_id = vw_accounts.account_id)))
     JOIN currency ON ((bank_accounts.currency_id = currency.currency_id)));


ALTER TABLE public.vw_bank_accounts OWNER TO postgres;

--
-- Name: vw_budgets; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_budgets AS
 SELECT departments.department_id,
    departments.department_name,
    fiscal_years.fiscal_year_id,
    fiscal_years.fiscal_year_start,
    fiscal_years.fiscal_year,
    fiscal_years.fiscal_year_end,
    fiscal_years.year_opened,
    fiscal_years.year_closed,
    budgets.budget_id,
    budgets.org_id,
    budgets.budget_type,
    budgets.budget_name,
    budgets.application_date,
    budgets.approve_status,
    budgets.workflow_table_id,
    budgets.action_date,
    budgets.details
   FROM ((budgets
     JOIN departments ON ((budgets.department_id = departments.department_id)))
     JOIN fiscal_years ON ((budgets.fiscal_year_id = fiscal_years.fiscal_year_id)));


ALTER TABLE public.vw_budgets OWNER TO postgres;

--
-- Name: vw_items; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_items AS
 SELECT sales_account.account_id AS sales_account_id,
    sales_account.account_name AS sales_account_name,
    purchase_account.account_id AS purchase_account_id,
    purchase_account.account_name AS purchase_account_name,
    item_category.item_category_id,
    item_category.item_category_name,
    item_units.item_unit_id,
    item_units.item_unit_name,
    tax_types.tax_type_id,
    tax_types.tax_type_name,
    tax_types.account_id AS tax_account_id,
    tax_types.tax_rate,
    tax_types.tax_inclusive,
    items.item_id,
    items.org_id,
    items.item_name,
    items.inventory,
    items.bar_code,
    items.for_sale,
    items.for_purchase,
    items.sales_price,
    items.purchase_price,
    items.reorder_level,
    items.lead_time,
    items.is_active,
    items.details
   FROM (((((items
     JOIN accounts sales_account ON ((items.sales_account_id = sales_account.account_id)))
     JOIN accounts purchase_account ON ((items.purchase_account_id = purchase_account.account_id)))
     JOIN item_category ON ((items.item_category_id = item_category.item_category_id)))
     JOIN item_units ON ((items.item_unit_id = item_units.item_unit_id)))
     JOIN tax_types ON ((items.tax_type_id = tax_types.tax_type_id)));


ALTER TABLE public.vw_items OWNER TO postgres;

--
-- Name: vw_budget_lines; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_budget_lines AS
 SELECT vw_budgets.department_id,
    vw_budgets.department_name,
    vw_budgets.fiscal_year_id,
    vw_budgets.fiscal_year,
    vw_budgets.fiscal_year_start,
    vw_budgets.fiscal_year_end,
    vw_budgets.year_opened,
    vw_budgets.year_closed,
    vw_budgets.budget_id,
    vw_budgets.budget_name,
    vw_budgets.budget_type,
    vw_budgets.approve_status,
    periods.period_id,
    periods.start_date,
    periods.end_date,
    periods.opened,
    periods.activated,
    periods.closed,
    periods.overtime_rate,
    periods.per_diem_tax_limit,
    periods.is_posted,
    date_part('month'::text, periods.start_date) AS month_id,
    to_char((periods.start_date)::timestamp with time zone, 'YYYY'::text) AS period_year,
    to_char((periods.start_date)::timestamp with time zone, 'Month'::text) AS period_month,
    (trunc(((date_part('month'::text, periods.start_date) - (1)::double precision) / (3)::double precision)) + (1)::double precision) AS quarter,
    (trunc(((date_part('month'::text, periods.start_date) - (1)::double precision) / (6)::double precision)) + (1)::double precision) AS semister,
    vw_accounts.account_class_id,
    vw_accounts.chat_type_id,
    vw_accounts.chat_type_name,
    vw_accounts.account_class_name,
    vw_accounts.account_type_id,
    vw_accounts.account_type_name,
    vw_accounts.account_id,
    vw_accounts.account_name,
    vw_accounts.is_header,
    vw_accounts.is_active,
    vw_items.item_id,
    vw_items.item_name,
    vw_items.tax_type_id,
    vw_items.tax_account_id,
    vw_items.tax_type_name,
    vw_items.tax_rate,
    vw_items.tax_inclusive,
    vw_items.sales_account_id,
    vw_items.purchase_account_id,
    budget_lines.budget_line_id,
    budget_lines.org_id,
    budget_lines.transaction_id,
    budget_lines.spend_type,
    budget_lines.quantity,
    budget_lines.amount,
    budget_lines.tax_amount,
    budget_lines.narrative,
    budget_lines.details,
        CASE
            WHEN (budget_lines.spend_type = 1) THEN 'Monthly'::text
            WHEN (budget_lines.spend_type = 2) THEN 'Quaterly'::text
            ELSE 'Once'::text
        END AS spend_type_name,
    budget_lines.income_budget,
        CASE
            WHEN (budget_lines.income_budget = true) THEN 'Income Budget'::text
            ELSE 'Expenditure Budget'::text
        END AS income_expense,
        CASE
            WHEN (budget_lines.income_budget = true) THEN budget_lines.amount
            ELSE (0)::real
        END AS dr_budget,
        CASE
            WHEN (budget_lines.income_budget = false) THEN budget_lines.amount
            ELSE (0)::real
        END AS cr_budget
   FROM ((((budget_lines
     JOIN vw_budgets ON ((budget_lines.budget_id = vw_budgets.budget_id)))
     JOIN periods ON ((budget_lines.period_id = periods.period_id)))
     JOIN vw_accounts ON ((budget_lines.account_id = vw_accounts.account_id)))
     LEFT JOIN vw_items ON ((budget_lines.item_id = vw_items.item_id)));


ALTER TABLE public.vw_budget_lines OWNER TO postgres;

--
-- Name: vw_budget_ads; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_budget_ads AS
 SELECT vw_budget_lines.department_id,
    vw_budget_lines.department_name,
    vw_budget_lines.fiscal_year_id,
    vw_budget_lines.fiscal_year,
    vw_budget_lines.fiscal_year_start,
    vw_budget_lines.fiscal_year_end,
    vw_budget_lines.year_opened,
    vw_budget_lines.year_closed,
    vw_budget_lines.budget_type,
    vw_budget_lines.account_class_id,
    vw_budget_lines.chat_type_id,
    vw_budget_lines.chat_type_name,
    vw_budget_lines.account_class_name,
    vw_budget_lines.account_type_id,
    vw_budget_lines.account_type_name,
    vw_budget_lines.account_id,
    vw_budget_lines.account_name,
    vw_budget_lines.is_header,
    vw_budget_lines.is_active,
    vw_budget_lines.item_id,
    vw_budget_lines.item_name,
    vw_budget_lines.tax_type_id,
    vw_budget_lines.tax_account_id,
    vw_budget_lines.org_id,
    vw_budget_lines.spend_type,
    vw_budget_lines.spend_type_name,
    vw_budget_lines.income_budget,
    vw_budget_lines.income_expense,
    sum(vw_budget_lines.quantity) AS s_quantity,
    sum(vw_budget_lines.amount) AS s_amount,
    sum(vw_budget_lines.tax_amount) AS s_tax_amount,
    sum(vw_budget_lines.dr_budget) AS s_dr_budget,
    sum(vw_budget_lines.cr_budget) AS s_cr_budget,
    sum((vw_budget_lines.dr_budget - vw_budget_lines.cr_budget)) AS budget_diff
   FROM vw_budget_lines
  WHERE ((vw_budget_lines.approve_status)::text = 'Approved'::text)
  GROUP BY vw_budget_lines.department_id, vw_budget_lines.department_name, vw_budget_lines.fiscal_year_id, vw_budget_lines.fiscal_year, vw_budget_lines.fiscal_year_start, vw_budget_lines.fiscal_year_end, vw_budget_lines.year_opened, vw_budget_lines.year_closed, vw_budget_lines.budget_type, vw_budget_lines.account_class_id, vw_budget_lines.chat_type_id, vw_budget_lines.chat_type_name, vw_budget_lines.account_class_name, vw_budget_lines.account_type_id, vw_budget_lines.account_type_name, vw_budget_lines.account_id, vw_budget_lines.account_name, vw_budget_lines.is_header, vw_budget_lines.is_active, vw_budget_lines.item_id, vw_budget_lines.item_name, vw_budget_lines.tax_type_id, vw_budget_lines.tax_account_id, vw_budget_lines.org_id, vw_budget_lines.spend_type, vw_budget_lines.spend_type_name, vw_budget_lines.income_budget, vw_budget_lines.income_expense;


ALTER TABLE public.vw_budget_ads OWNER TO postgres;

--
-- Name: vw_budget_ledger; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_budget_ledger AS
 SELECT journals.org_id,
    periods.fiscal_year_id,
    journals.department_id,
    accounts.account_id,
    accounts.account_no,
    accounts.account_type_id,
    accounts.account_name,
    sum((journals.exchange_rate * gls.debit)) AS bl_debit,
    sum((journals.exchange_rate * gls.credit)) AS bl_credit,
    sum((journals.exchange_rate * (gls.debit - gls.credit))) AS bl_diff
   FROM (((journals
     JOIN gls ON ((journals.journal_id = gls.journal_id)))
     JOIN accounts ON ((gls.account_id = accounts.account_id)))
     JOIN periods ON ((journals.period_id = periods.period_id)))
  WHERE (journals.posted = true)
  GROUP BY journals.org_id, periods.fiscal_year_id, journals.department_id, accounts.account_id, accounts.account_no, accounts.account_type_id, accounts.account_name;


ALTER TABLE public.vw_budget_ledger OWNER TO postgres;

--
-- Name: vw_budget_pdc; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_budget_pdc AS
 SELECT vw_budget_ads.department_id,
    vw_budget_ads.department_name,
    vw_budget_ads.fiscal_year_id,
    vw_budget_ads.fiscal_year,
    vw_budget_ads.fiscal_year_start,
    vw_budget_ads.fiscal_year_end,
    vw_budget_ads.year_opened,
    vw_budget_ads.year_closed,
    vw_budget_ads.budget_type,
    vw_budget_ads.account_class_id,
    vw_budget_ads.chat_type_id,
    vw_budget_ads.chat_type_name,
    vw_budget_ads.account_class_name,
    vw_budget_ads.account_type_id,
    vw_budget_ads.account_type_name,
    vw_budget_ads.account_id,
    vw_budget_ads.account_name,
    vw_budget_ads.is_header,
    vw_budget_ads.is_active,
    vw_budget_ads.item_id,
    vw_budget_ads.item_name,
    vw_budget_ads.tax_type_id,
    vw_budget_ads.tax_account_id,
    vw_budget_ads.org_id,
    vw_budget_ads.spend_type,
    vw_budget_ads.spend_type_name,
    vw_budget_ads.income_budget,
    vw_budget_ads.income_expense,
    vw_budget_ads.s_quantity,
    vw_budget_ads.s_amount,
    vw_budget_ads.s_tax_amount,
    vw_budget_ads.s_dr_budget,
    vw_budget_ads.s_cr_budget,
    vw_budget_ledger.bl_debit,
    vw_budget_ledger.bl_credit,
        CASE
            WHEN (vw_budget_ads.income_budget = true) THEN COALESCE((((-1))::double precision * vw_budget_ledger.bl_diff), (0)::double precision)
            ELSE (COALESCE(vw_budget_ledger.bl_diff, (0)::real))::double precision
        END AS amount_used,
        CASE
            WHEN (vw_budget_ads.income_budget = true) THEN (vw_budget_ads.s_amount + COALESCE(vw_budget_ledger.bl_diff, (0)::real))
            ELSE (vw_budget_ads.s_amount - COALESCE(vw_budget_ledger.bl_diff, (0)::real))
        END AS budget_balance
   FROM (vw_budget_ads
     LEFT JOIN vw_budget_ledger ON ((((vw_budget_ads.department_id = vw_budget_ledger.department_id) AND (vw_budget_ads.account_id = vw_budget_ledger.account_id)) AND (vw_budget_ads.fiscal_year_id = vw_budget_ledger.fiscal_year_id))));


ALTER TABLE public.vw_budget_pdc OWNER TO postgres;

--
-- Name: vw_budget_pds; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_budget_pds AS
 SELECT vw_budget_lines.department_id,
    vw_budget_lines.department_name,
    vw_budget_lines.fiscal_year_id,
    vw_budget_lines.fiscal_year,
    vw_budget_lines.fiscal_year_start,
    vw_budget_lines.fiscal_year_end,
    vw_budget_lines.year_opened,
    vw_budget_lines.year_closed,
    vw_budget_lines.period_id,
    vw_budget_lines.start_date,
    vw_budget_lines.end_date,
    vw_budget_lines.opened,
    vw_budget_lines.closed,
    vw_budget_lines.month_id,
    vw_budget_lines.period_year,
    vw_budget_lines.period_month,
    vw_budget_lines.quarter,
    vw_budget_lines.semister,
    vw_budget_lines.budget_type,
    vw_budget_lines.account_class_id,
    vw_budget_lines.chat_type_id,
    vw_budget_lines.chat_type_name,
    vw_budget_lines.account_class_name,
    vw_budget_lines.account_type_id,
    vw_budget_lines.account_type_name,
    vw_budget_lines.account_id,
    vw_budget_lines.account_name,
    vw_budget_lines.is_header,
    vw_budget_lines.is_active,
    vw_budget_lines.item_id,
    vw_budget_lines.item_name,
    vw_budget_lines.tax_type_id,
    vw_budget_lines.tax_account_id,
    vw_budget_lines.tax_type_name,
    vw_budget_lines.tax_rate,
    vw_budget_lines.tax_inclusive,
    vw_budget_lines.sales_account_id,
    vw_budget_lines.purchase_account_id,
    vw_budget_lines.budget_line_id,
    vw_budget_lines.org_id,
    vw_budget_lines.transaction_id,
    vw_budget_lines.spend_type,
    vw_budget_lines.spend_type_name,
    vw_budget_lines.income_budget,
    vw_budget_lines.income_expense,
    sum(vw_budget_lines.quantity) AS s_quantity,
    sum(vw_budget_lines.amount) AS s_amount,
    sum(vw_budget_lines.tax_amount) AS s_tax_amount,
    sum(vw_budget_lines.dr_budget) AS s_dr_budget,
    sum(vw_budget_lines.cr_budget) AS s_cr_budget,
    sum((vw_budget_lines.dr_budget - vw_budget_lines.cr_budget)) AS budget_diff
   FROM vw_budget_lines
  WHERE ((vw_budget_lines.approve_status)::text = 'Approved'::text)
  GROUP BY vw_budget_lines.department_id, vw_budget_lines.department_name, vw_budget_lines.fiscal_year_id, vw_budget_lines.fiscal_year, vw_budget_lines.fiscal_year_start, vw_budget_lines.fiscal_year_end, vw_budget_lines.year_opened, vw_budget_lines.year_closed, vw_budget_lines.period_id, vw_budget_lines.start_date, vw_budget_lines.end_date, vw_budget_lines.opened, vw_budget_lines.closed, vw_budget_lines.month_id, vw_budget_lines.period_year, vw_budget_lines.period_month, vw_budget_lines.quarter, vw_budget_lines.semister, vw_budget_lines.budget_type, vw_budget_lines.account_class_id, vw_budget_lines.chat_type_id, vw_budget_lines.chat_type_name, vw_budget_lines.account_class_name, vw_budget_lines.account_type_id, vw_budget_lines.account_type_name, vw_budget_lines.account_id, vw_budget_lines.account_name, vw_budget_lines.is_header, vw_budget_lines.is_active, vw_budget_lines.item_id, vw_budget_lines.item_name, vw_budget_lines.tax_type_id, vw_budget_lines.tax_account_id, vw_budget_lines.tax_type_name, vw_budget_lines.tax_rate, vw_budget_lines.tax_inclusive, vw_budget_lines.sales_account_id, vw_budget_lines.purchase_account_id, vw_budget_lines.budget_line_id, vw_budget_lines.org_id, vw_budget_lines.transaction_id, vw_budget_lines.spend_type, vw_budget_lines.spend_type_name, vw_budget_lines.income_budget, vw_budget_lines.income_expense;


ALTER TABLE public.vw_budget_pds OWNER TO postgres;

--
-- Name: vw_career_development; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_career_development AS
 SELECT vw_job_reviews.entity_id,
    vw_job_reviews.entity_name,
    vw_job_reviews.job_review_id,
    vw_job_reviews.total_points,
    vw_job_reviews.review_date,
    vw_job_reviews.review_done,
    vw_job_reviews.recomendation,
    vw_job_reviews.reviewer_comments,
    vw_job_reviews.pl_comments,
    vw_job_reviews.approve_status,
    vw_job_reviews.workflow_table_id,
    vw_job_reviews.application_date,
    vw_job_reviews.action_date,
    career_development.career_development_id,
    career_development.career_development_name,
    career_development.details AS career_development_details,
    evaluation_points.org_id,
    evaluation_points.evaluation_point_id,
    evaluation_points.points,
    evaluation_points.reviewer_points,
    evaluation_points.reviewer_narrative,
    evaluation_points.narrative,
    evaluation_points.details
   FROM ((evaluation_points
     JOIN vw_job_reviews ON ((evaluation_points.job_review_id = vw_job_reviews.job_review_id)))
     JOIN career_development ON ((evaluation_points.career_development_id = career_development.career_development_id)));


ALTER TABLE public.vw_career_development OWNER TO postgres;

--
-- Name: vw_casual_application; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_casual_application AS
 SELECT casual_category.casual_category_id,
    casual_category.casual_category_name,
    departments.department_id,
    departments.department_name,
    casual_application.casual_application_id,
    casual_application."position",
    casual_application.org_id,
    casual_application.application_date,
    casual_application.approved_pay_rate,
    casual_application.approve_status,
    casual_application.action_date,
    casual_application.work_duration,
    casual_application.details
   FROM ((casual_application
     JOIN casual_category ON ((casual_application.casual_category_id = casual_category.casual_category_id)))
     JOIN departments ON ((casual_application.department_id = departments.department_id)));


ALTER TABLE public.vw_casual_application OWNER TO postgres;

--
-- Name: vw_casuals; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_casuals AS
 SELECT vw_casual_application.casual_category_id,
    vw_casual_application.casual_category_name,
    vw_casual_application.department_id,
    vw_casual_application.department_name,
    vw_casual_application.casual_application_id,
    vw_casual_application."position",
    vw_casual_application.application_date,
    vw_casual_application.approved_pay_rate,
    vw_casual_application.approve_status AS application_approve_status,
    vw_casual_application.action_date AS application_action_date,
    vw_casual_application.work_duration,
    entitys.entity_id,
    entitys.entity_name,
    casuals.org_id,
    casuals.casual_id,
    casuals.start_date,
    casuals.end_date,
    casuals.duration,
    casuals.pay_rate,
    casuals.amount_paid,
    casuals.approve_status,
    casuals.action_date,
    casuals.paid,
    casuals.details
   FROM ((casuals
     JOIN vw_casual_application ON ((casuals.casual_application_id = vw_casual_application.casual_application_id)))
     JOIN entitys ON ((casuals.entity_id = entitys.entity_id)));


ALTER TABLE public.vw_casuals OWNER TO postgres;

--
-- Name: vw_claims; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_claims AS
 SELECT claim_types.claim_type_id,
    claim_types.claim_type_name,
    entitys.entity_id,
    entitys.entity_name,
    claims.org_id,
    claims.claim_id,
    claims.claim_date,
    claims.narrative,
    claims.in_payroll,
    claims.process_claim,
    claims.process_date,
    claims.application_date,
    claims.approve_status,
    claims.workflow_table_id,
    claims.action_date,
    claims.details
   FROM ((claims
     JOIN claim_types ON ((claims.claim_type_id = claim_types.claim_type_id)))
     JOIN entitys ON ((claims.entity_id = entitys.entity_id)));


ALTER TABLE public.vw_claims OWNER TO postgres;

--
-- Name: vw_claim_details; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_claim_details AS
 SELECT vw_claims.claim_type_id,
    vw_claims.claim_type_name,
    vw_claims.entity_id,
    vw_claims.entity_name,
    vw_claims.claim_id,
    vw_claims.claim_date,
    vw_claims.narrative,
    vw_claims.application_date,
    vw_claims.approve_status,
    vw_claims.workflow_table_id,
    vw_claims.action_date,
    currency.currency_id,
    currency.currency_name,
    currency.currency_symbol,
    claim_details.org_id,
    claim_details.claim_detail_id,
    claim_details.nature_of_expence,
    claim_details.receipt_number,
    claim_details.amount,
    claim_details.exchange_rate,
    claim_details.expense_code,
    claim_details.details
   FROM ((claim_details
     JOIN vw_claims ON ((claim_details.claim_id = vw_claims.claim_id)))
     JOIN currency ON ((claim_details.currency_id = currency.currency_id)));


ALTER TABLE public.vw_claim_details OWNER TO postgres;

--
-- Name: vw_claim_types; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_claim_types AS
 SELECT adjustments.adjustment_id,
    adjustments.adjustment_name,
    claim_types.org_id,
    claim_types.claim_type_id,
    claim_types.claim_type_name,
    claim_types.details
   FROM (claim_types
     JOIN adjustments ON ((claim_types.adjustment_id = adjustments.adjustment_id)));


ALTER TABLE public.vw_claim_types OWNER TO postgres;

--
-- Name: vw_contracting; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_contracting AS
 SELECT vw_intake.department_id,
    vw_intake.department_name,
    vw_intake.department_description,
    vw_intake.department_duties,
    vw_intake.department_role_id,
    vw_intake.department_role_name,
    vw_intake.job_description,
    vw_intake.parent_role_name,
    vw_intake.job_requirements,
    vw_intake.duties,
    vw_intake.performance_measures,
    vw_intake.intake_id,
    vw_intake.opening_date,
    vw_intake.closing_date,
    vw_intake.positions,
    entitys.entity_id,
    entitys.entity_name,
    orgs.org_id,
    orgs.org_name,
    contract_types.contract_type_id,
    contract_types.contract_type_name,
    contract_types.notice_period,
    contract_types.contract_text,
    contract_status.contract_status_id,
    contract_status.contract_status_name,
    applications.application_id,
    applications.employee_id,
    applications.contract_date,
    applications.contract_close,
    applications.contract_start,
    applications.contract_period,
    applications.contract_terms,
    applications.initial_salary,
    applications.application_date,
    applications.approve_status,
    applications.workflow_table_id,
    applications.action_date,
    applications.applicant_comments,
    applications.review,
    applications.notice_email,
    (('now'::text)::date - applications.contract_close) AS days_end_contract,
    vw_education_max.education_class_name,
    vw_education_max.date_from,
    vw_education_max.date_to,
    vw_education_max.name_of_school,
    vw_education_max.examination_taken,
    vw_education_max.grades_obtained,
    vw_education_max.certificate_number,
    vw_employment_max.employment_id,
    vw_employment_max.employers_name,
    vw_employment_max.position_held,
    vw_employment_max.date_from AS emp_date_from,
    vw_employment_max.date_to AS emp_date_to,
    vw_employment_max.employment_duration,
    vw_employment_max.employment_experince,
    round(((date_part('year'::text, vw_employment_max.employment_duration) + (date_part('month'::text, vw_employment_max.employment_duration) / (12)::double precision)))::numeric, 1) AS emp_duration,
    round(((date_part('year'::text, vw_employment_max.employment_experince) + (date_part('month'::text, vw_employment_max.employment_experince) / (12)::double precision)))::numeric, 1) AS emp_experince
   FROM (((((((applications
     JOIN entitys ON ((applications.employee_id = entitys.entity_id)))
     JOIN orgs ON ((applications.org_id = orgs.org_id)))
     LEFT JOIN vw_intake ON ((applications.intake_id = vw_intake.intake_id)))
     LEFT JOIN contract_types ON ((applications.contract_type_id = contract_types.contract_type_id)))
     LEFT JOIN contract_status ON ((applications.contract_status_id = contract_status.contract_status_id)))
     LEFT JOIN vw_education_max ON ((entitys.entity_id = vw_education_max.entity_id)))
     LEFT JOIN vw_employment_max ON ((entitys.entity_id = vw_employment_max.entity_id)));


ALTER TABLE public.vw_contracting OWNER TO postgres;

--
-- Name: vw_curr_orgs; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_curr_orgs AS
 SELECT currency.currency_id AS base_currency_id,
    currency.currency_name AS base_currency_name,
    currency.currency_symbol AS base_currency_symbol,
    orgs.org_id,
    orgs.org_name,
    orgs.is_default,
    orgs.is_active,
    orgs.logo,
    orgs.cert_number,
    orgs.pin,
    orgs.vat_number,
    orgs.invoice_footer,
    orgs.details
   FROM (orgs
     JOIN currency ON ((orgs.currency_id = currency.currency_id)));


ALTER TABLE public.vw_curr_orgs OWNER TO postgres;

--
-- Name: vw_cv_projects; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_cv_projects AS
 SELECT entitys.entity_id,
    entitys.entity_name,
    cv_projects.cv_projectid,
    cv_projects.cv_project_name,
    cv_projects.org_id,
    cv_projects.cv_project_date,
    cv_projects.details
   FROM (cv_projects
     JOIN entitys ON ((cv_projects.entity_id = entitys.entity_id)));


ALTER TABLE public.vw_cv_projects OWNER TO postgres;

--
-- Name: vw_cv_seminars; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_cv_seminars AS
 SELECT entitys.entity_id,
    entitys.entity_name,
    cv_seminars.cv_seminar_id,
    cv_seminars.cv_seminar_name,
    cv_seminars.org_id,
    cv_seminars.cv_seminar_date,
    cv_seminars.details
   FROM (cv_seminars
     JOIN entitys ON ((cv_seminars.entity_id = entitys.entity_id)));


ALTER TABLE public.vw_cv_seminars OWNER TO postgres;

--
-- Name: vw_day_works; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_day_works AS
 SELECT entitys.entity_id AS supervisor_id,
    entitys.entity_name AS supervisor_name,
    farm_fields.farm_field_id,
    farm_fields.farm_field_name,
    vw_periods.period_id,
    vw_periods.start_date,
    vw_periods.end_date,
    vw_periods.activated,
    vw_periods.closed,
    vw_periods.month_id,
    vw_periods.period_year,
    vw_periods.period_month,
    vw_periods.quarter,
    vw_periods.semister,
    day_works.org_id,
    day_works.day_work_id,
    day_works.batch_ref,
    day_works.work_date,
    day_works.work_start,
    day_works.work_end,
    day_works.farm_weight,
    day_works.factory_weight,
    day_works.details
   FROM (((day_works
     JOIN entitys ON ((day_works.entity_id = entitys.entity_id)))
     JOIN farm_fields ON ((day_works.farm_field_id = farm_fields.farm_field_id)))
     JOIN vw_periods ON ((day_works.period_id = vw_periods.period_id)));


ALTER TABLE public.vw_day_works OWNER TO postgres;

--
-- Name: vw_default_accounts; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_default_accounts AS
 SELECT vw_accounts.account_class_id,
    vw_accounts.chat_type_id,
    vw_accounts.chat_type_name,
    vw_accounts.account_class_name,
    vw_accounts.account_type_id,
    vw_accounts.account_type_name,
    vw_accounts.account_id,
    vw_accounts.account_no,
    vw_accounts.account_name,
    vw_accounts.is_header,
    vw_accounts.is_active,
    use_keys.use_key_id,
    use_keys.use_key_name,
    use_keys.use_function,
    default_accounts.default_account_id,
    default_accounts.org_id,
    default_accounts.narrative
   FROM ((vw_accounts
     JOIN default_accounts ON ((vw_accounts.account_id = default_accounts.account_id)))
     JOIN use_keys ON ((default_accounts.use_key_id = use_keys.use_key_id)));


ALTER TABLE public.vw_default_accounts OWNER TO postgres;

--
-- Name: vw_default_adjustments; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_default_adjustments AS
 SELECT vw_adjustments.adjustment_id,
    vw_adjustments.adjustment_name,
    vw_adjustments.adjustment_type,
    vw_adjustments.currency_id,
    vw_adjustments.currency_name,
    vw_adjustments.currency_symbol,
    entitys.entity_id,
    entitys.entity_name,
    default_adjustments.org_id,
    default_adjustments.default_adjustment_id,
    default_adjustments.amount,
    default_adjustments.active,
    default_adjustments.final_date,
    default_adjustments.narrative
   FROM ((default_adjustments
     JOIN vw_adjustments ON ((default_adjustments.adjustment_id = vw_adjustments.adjustment_id)))
     JOIN entitys ON ((default_adjustments.entity_id = entitys.entity_id)));


ALTER TABLE public.vw_default_adjustments OWNER TO postgres;

--
-- Name: vw_default_banking; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_default_banking AS
 SELECT entitys.entity_id,
    entitys.entity_name,
    vw_bank_branch.bank_id,
    vw_bank_branch.bank_name,
    vw_bank_branch.bank_branch_id,
    vw_bank_branch.bank_branch_name,
    vw_bank_branch.bank_branch_code,
    currency.currency_id,
    currency.currency_name,
    currency.currency_symbol,
    default_banking.org_id,
    default_banking.default_banking_id,
    default_banking.amount,
    default_banking.ps_amount,
    default_banking.final_date,
    default_banking.active,
    default_banking.bank_account,
    default_banking.narrative
   FROM (((default_banking
     JOIN entitys ON ((default_banking.entity_id = entitys.entity_id)))
     JOIN vw_bank_branch ON ((default_banking.bank_branch_id = vw_bank_branch.bank_branch_id)))
     JOIN currency ON ((default_banking.currency_id = currency.currency_id)));


ALTER TABLE public.vw_default_banking OWNER TO postgres;

--
-- Name: vw_tax_types; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_tax_types AS
 SELECT vw_accounts.account_type_id,
    vw_accounts.account_type_name,
    vw_accounts.account_id,
    vw_accounts.account_name,
    currency.currency_id,
    currency.currency_name,
    currency.currency_symbol,
    use_keys.use_key_id,
    use_keys.use_key_name,
    use_keys.use_function,
    tax_types.org_id,
    tax_types.tax_type_id,
    tax_types.tax_type_name,
    tax_types.formural,
    tax_types.tax_relief,
    tax_types.tax_type_order,
    tax_types.in_tax,
    tax_types.tax_rate,
    tax_types.tax_inclusive,
    tax_types.linear,
    tax_types.percentage,
    tax_types.employer,
    tax_types.employer_ps,
    tax_types.account_number,
    tax_types.employer_account,
    tax_types.active,
    tax_types.tax_type_number,
    tax_types.details
   FROM (((tax_types
     JOIN currency ON ((tax_types.currency_id = currency.currency_id)))
     JOIN use_keys ON ((tax_types.use_key_id = use_keys.use_key_id)))
     LEFT JOIN vw_accounts ON ((tax_types.account_id = vw_accounts.account_id)));


ALTER TABLE public.vw_tax_types OWNER TO postgres;

--
-- Name: vw_default_tax_types; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_default_tax_types AS
 SELECT entitys.entity_id,
    entitys.entity_name,
    vw_tax_types.tax_type_id,
    vw_tax_types.tax_type_name,
    vw_tax_types.tax_type_number,
    vw_tax_types.currency_id,
    vw_tax_types.currency_name,
    vw_tax_types.currency_symbol,
    default_tax_types.default_tax_type_id,
    default_tax_types.org_id,
    default_tax_types.tax_identification,
    default_tax_types.active,
    default_tax_types.narrative
   FROM ((default_tax_types
     JOIN entitys ON ((default_tax_types.entity_id = entitys.entity_id)))
     JOIN vw_tax_types ON ((default_tax_types.tax_type_id = vw_tax_types.tax_type_id)));


ALTER TABLE public.vw_default_tax_types OWNER TO postgres;

--
-- Name: vw_define_phases; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_define_phases AS
 SELECT entity_types.entity_type_id,
    entity_types.entity_type_name,
    project_types.project_type_id,
    project_types.project_type_name,
    define_phases.define_phase_id,
    define_phases.define_phase_name,
    define_phases.org_id,
    define_phases.define_phase_time,
    define_phases.define_phase_cost,
    define_phases.phase_order,
    define_phases.details
   FROM ((define_phases
     JOIN entity_types ON ((define_phases.entity_type_id = entity_types.entity_type_id)))
     JOIN project_types ON ((define_phases.project_type_id = project_types.project_type_id)));


ALTER TABLE public.vw_define_phases OWNER TO postgres;

--
-- Name: vw_define_tasks; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_define_tasks AS
 SELECT vw_define_phases.entity_type_id,
    vw_define_phases.entity_type_name,
    vw_define_phases.project_type_id,
    vw_define_phases.project_type_name,
    vw_define_phases.define_phase_id,
    vw_define_phases.define_phase_name,
    vw_define_phases.define_phase_time,
    vw_define_phases.define_phase_cost,
    define_tasks.org_id,
    define_tasks.define_task_id,
    define_tasks.define_task_name,
    define_tasks.narrative,
    define_tasks.details
   FROM (define_tasks
     JOIN vw_define_phases ON ((define_tasks.define_phase_id = vw_define_phases.define_phase_id)));


ALTER TABLE public.vw_define_tasks OWNER TO postgres;

--
-- Name: vw_departments; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_departments AS
 SELECT departments.ln_department_id,
    p_departments.department_name AS ln_department_name,
    departments.department_id,
    departments.org_id,
    departments.department_name,
    departments.active,
    departments.function_code,
    departments.petty_cash,
    departments.cost_center,
    departments.revenue_center,
    departments.description,
    departments.duties,
    departments.reports,
    departments.details
   FROM (departments
     LEFT JOIN departments p_departments ON ((departments.ln_department_id = p_departments.department_id)));


ALTER TABLE public.vw_departments OWNER TO postgres;

--
-- Name: vw_education; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_education AS
 SELECT education_class.education_class_id,
    education_class.education_class_name,
    entitys.entity_id,
    entitys.entity_name,
    education.org_id,
    education.education_id,
    education.date_from,
    education.date_to,
    education.name_of_school,
    education.examination_taken,
    education.grades_obtained,
    education.certificate_number,
    education.details
   FROM ((education
     JOIN education_class ON ((education.education_class_id = education_class.education_class_id)))
     JOIN entitys ON ((education.entity_id = entitys.entity_id)));


ALTER TABLE public.vw_education OWNER TO postgres;

--
-- Name: vw_employee_adjustments; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_employee_adjustments AS
 SELECT eml.employee_month_id,
    eml.period_id,
    eml.start_date,
    eml.month_id,
    eml.period_year,
    eml.period_month,
    eml.end_date,
    eml.entity_id,
    eml.entity_name,
    eml.employee_id,
    eml.identity_card,
    eml.department_id,
    eml.department_name,
    eml.department_account,
    eml.function_code,
    eml.department_role_id,
    eml.department_role_name,
    adjustments.adjustment_id,
    adjustments.adjustment_name,
    adjustments.adjustment_type,
    adjustments.account_number,
    adjustments.earning_code,
    currency.currency_id,
    currency.currency_name,
    currency.currency_symbol,
    employee_adjustments.org_id,
    employee_adjustments.employee_adjustment_id,
    employee_adjustments.pay_date,
    employee_adjustments.amount,
    employee_adjustments.in_payroll,
    employee_adjustments.in_tax,
    employee_adjustments.visible,
    employee_adjustments.exchange_rate,
    employee_adjustments.paid_amount,
    employee_adjustments.balance,
    employee_adjustments.narrative,
    employee_adjustments.tax_relief_amount,
    (employee_adjustments.exchange_rate * employee_adjustments.amount) AS base_amount,
    ((employee_adjustments.exchange_rate * eml.exchange_rate) * employee_adjustments.amount) AS b_amount,
    ((employee_adjustments.exchange_rate * eml.exchange_rate) * employee_adjustments.paid_amount) AS b_paid_amount
   FROM (((employee_adjustments
     JOIN adjustments ON ((employee_adjustments.adjustment_id = adjustments.adjustment_id)))
     JOIN vw_employee_month_list eml ON ((employee_adjustments.employee_month_id = eml.employee_month_id)))
     JOIN currency ON ((adjustments.currency_id = currency.currency_id)));


ALTER TABLE public.vw_employee_adjustments OWNER TO postgres;

--
-- Name: vw_employee_advances; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_employee_advances AS
 SELECT eml.employee_month_id,
    eml.period_id,
    eml.start_date,
    eml.end_date,
    eml.month_id,
    eml.period_year,
    eml.period_month,
    eml.gl_payroll_account,
    eml.entity_id,
    eml.entity_name,
    eml.employee_id,
    employee_advances.org_id,
    employee_advances.employee_advance_id,
    employee_advances.pay_date,
    employee_advances.pay_period,
    employee_advances.pay_upto,
    employee_advances.amount,
    employee_advances.in_payroll,
    employee_advances.completed,
    employee_advances.approve_status,
    employee_advances.action_date,
    employee_advances.narrative,
    (employee_advances.amount * eml.exchange_rate) AS b_advance_amount
   FROM (employee_advances
     JOIN vw_employee_month_list eml ON ((employee_advances.employee_month_id = eml.employee_month_id)));


ALTER TABLE public.vw_employee_advances OWNER TO postgres;

--
-- Name: vw_employee_banking; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_employee_banking AS
 SELECT eml.employee_month_id,
    eml.period_id,
    eml.start_date,
    eml.month_id,
    eml.period_year,
    eml.period_month,
    eml.entity_id,
    eml.entity_name,
    eml.employee_id,
    eml.pay_group_id,
    eml.bank_header,
    eml.bank_address,
    vw_bank_branch.bank_id,
    vw_bank_branch.bank_name,
    vw_bank_branch.bank_branch_id,
    vw_bank_branch.bank_branch_name,
    vw_bank_branch.bank_branch_code,
    currency.currency_id,
    currency.currency_name,
    currency.currency_symbol,
    employee_banking.org_id,
    employee_banking.employee_banking_id,
    employee_banking.amount,
    employee_banking.exchange_rate,
    employee_banking.active,
    employee_banking.bank_account,
    employee_banking.narrative,
    (employee_banking.exchange_rate * employee_banking.amount) AS base_amount,
    ((employee_banking.exchange_rate * eml.exchange_rate) * employee_banking.amount) AS b_amount
   FROM (((employee_banking
     JOIN vw_employee_month_list eml ON ((employee_banking.employee_month_id = eml.employee_month_id)))
     JOIN vw_bank_branch ON ((employee_banking.bank_branch_id = vw_bank_branch.bank_branch_id)))
     JOIN currency ON ((employee_banking.currency_id = currency.currency_id)));


ALTER TABLE public.vw_employee_banking OWNER TO postgres;

--
-- Name: vw_employee_cases; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_employee_cases AS
 SELECT case_types.case_type_id,
    case_types.case_type_name,
    entitys.entity_id,
    entitys.entity_name,
    employee_cases.org_id,
    employee_cases.employee_case_id,
    employee_cases.narrative,
    employee_cases.case_date,
    employee_cases.complaint,
    employee_cases.case_action,
    employee_cases.completed,
    employee_cases.details
   FROM ((employee_cases
     JOIN case_types ON ((employee_cases.case_type_id = case_types.case_type_id)))
     JOIN entitys ON ((employee_cases.entity_id = entitys.entity_id)));


ALTER TABLE public.vw_employee_cases OWNER TO postgres;

--
-- Name: vw_employee_leave; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_employee_leave AS
 SELECT entitys.entity_id,
    entitys.entity_name,
    leave_types.leave_type_id,
    leave_types.leave_type_name,
    contact_entity.entity_name AS contact_name,
    employee_leave.org_id,
    employee_leave.employee_leave_id,
    employee_leave.leave_from,
    employee_leave.leave_to,
    employee_leave.start_half_day,
    employee_leave.end_half_day,
    employee_leave.approve_status,
    employee_leave.action_date,
    employee_leave.workflow_table_id,
    employee_leave.completed,
    employee_leave.leave_days,
    employee_leave.narrative,
    employee_leave.details,
    employee_leave.special_request,
        CASE
            WHEN (employee_leave.start_half_day = true) THEN '14:00:00'::time without time zone
            ELSE '08:00:00'::time without time zone
        END AS activity_time,
        CASE
            WHEN (employee_leave.end_half_day = true) THEN '14:00:00'::time without time zone
            ELSE '17:00:00'::time without time zone
        END AS finish_time,
    date_part('month'::text, employee_leave.leave_from) AS leave_month,
    to_char((employee_leave.leave_from)::timestamp with time zone, 'YYYY'::text) AS leave_year
   FROM (((employee_leave
     JOIN entitys ON ((employee_leave.entity_id = entitys.entity_id)))
     JOIN leave_types ON ((employee_leave.leave_type_id = leave_types.leave_type_id)))
     LEFT JOIN entitys contact_entity ON ((employee_leave.contact_entity_id = contact_entity.entity_id)));


ALTER TABLE public.vw_employee_leave OWNER TO postgres;

--
-- Name: vw_employee_leave_types; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_employee_leave_types AS
 SELECT entitys.entity_id,
    entitys.entity_name,
    leave_types.leave_type_id,
    leave_types.leave_type_name,
    leave_types.allowed_leave_days,
    leave_types.leave_days_span,
    leave_types.use_type,
    leave_types.month_quota,
    leave_types.initial_days,
    leave_types.maximum_carry,
    leave_types.include_holiday,
    employee_leave_types.org_id,
    employee_leave_types.employee_leave_type_id,
    employee_leave_types.leave_balance,
    employee_leave_types.leave_starting,
    employee_leave_types.details
   FROM ((employee_leave_types
     JOIN entitys ON ((employee_leave_types.entity_id = entitys.entity_id)))
     JOIN leave_types ON ((employee_leave_types.leave_type_id = leave_types.leave_type_id)));


ALTER TABLE public.vw_employee_leave_types OWNER TO postgres;

--
-- Name: vw_employee_month; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_employee_month AS
 SELECT vw_periods.period_id,
    vw_periods.start_date,
    vw_periods.end_date,
    vw_periods.overtime_rate,
    vw_periods.activated,
    vw_periods.closed,
    vw_periods.month_id,
    vw_periods.period_year,
    vw_periods.period_month,
    vw_periods.quarter,
    vw_periods.semister,
    vw_periods.gl_payroll_account,
    vw_periods.is_posted,
    vw_bank_branch.bank_id,
    vw_bank_branch.bank_name,
    vw_bank_branch.bank_branch_id,
    vw_bank_branch.bank_branch_name,
    vw_bank_branch.bank_branch_code,
    pay_groups.pay_group_id,
    pay_groups.pay_group_name,
    pay_groups.gl_payment_account,
    pay_groups.bank_header,
    pay_groups.bank_address,
    vw_department_roles.department_id,
    vw_department_roles.department_name,
    vw_department_roles.department_role_id,
    vw_department_roles.department_role_name,
    entitys.entity_id,
    entitys.entity_name,
    employees.employee_id,
    employees.surname,
    employees.first_name,
    employees.middle_name,
    employees.date_of_birth,
    employees.gender,
    employees.nationality,
    employees.marital_status,
    employees.appointment_date,
    employees.exit_date,
    employees.contract,
    employees.contract_period,
    employees.employment_terms,
    employees.identity_card,
    (((((employees.surname)::text || ' '::text) || (employees.first_name)::text) || ' '::text) || (COALESCE(employees.middle_name, ''::character varying))::text) AS employee_name,
    currency.currency_id,
    currency.currency_name,
    currency.currency_symbol,
    employee_month.exchange_rate,
    employee_month.org_id,
    employee_month.employee_month_id,
    employee_month.bank_account,
    employee_month.basic_pay,
    employee_month.details,
    getadjustment(employee_month.employee_month_id, 4, 31) AS overtime,
    getadjustment(employee_month.employee_month_id, 1, 1) AS full_allowance,
    getadjustment(employee_month.employee_month_id, 1, 2) AS payroll_allowance,
    getadjustment(employee_month.employee_month_id, 1, 3) AS tax_allowance,
    getadjustment(employee_month.employee_month_id, 2, 1) AS full_deduction,
    getadjustment(employee_month.employee_month_id, 2, 2) AS payroll_deduction,
    getadjustment(employee_month.employee_month_id, 2, 3) AS tax_deduction,
    getadjustment(employee_month.employee_month_id, 3, 1) AS full_expense,
    getadjustment(employee_month.employee_month_id, 3, 2) AS payroll_expense,
    getadjustment(employee_month.employee_month_id, 3, 3) AS tax_expense,
    getadjustment(employee_month.employee_month_id, 4, 11) AS payroll_tax,
    getadjustment(employee_month.employee_month_id, 4, 12) AS tax_tax,
    getadjustment(employee_month.employee_month_id, 4, 22) AS net_adjustment,
    getadjustment(employee_month.employee_month_id, 4, 33) AS per_diem,
    getadjustment(employee_month.employee_month_id, 4, 34) AS advance,
    getadjustment(employee_month.employee_month_id, 4, 35) AS advance_deduction,
    getadjustment(employee_month.employee_month_id, 4, 41) AS other_banks,
    ((((employee_month.basic_pay + getadjustment(employee_month.employee_month_id, 4, 31)) + getadjustment(employee_month.employee_month_id, 4, 22)) + getadjustment(employee_month.employee_month_id, 4, 33)) - getadjustment(employee_month.employee_month_id, 4, 11)) AS net_pay,
    ((((((((employee_month.basic_pay + getadjustment(employee_month.employee_month_id, 4, 31)) + getadjustment(employee_month.employee_month_id, 4, 22)) + getadjustment(employee_month.employee_month_id, 4, 33)) + getadjustment(employee_month.employee_month_id, 4, 34)) - getadjustment(employee_month.employee_month_id, 4, 11)) - getadjustment(employee_month.employee_month_id, 4, 35)) - getadjustment(employee_month.employee_month_id, 4, 36)) - getadjustment(employee_month.employee_month_id, 4, 41)) AS banked,
    ((((employee_month.basic_pay + getadjustment(employee_month.employee_month_id, 4, 31)) + getadjustment(employee_month.employee_month_id, 1, 1)) + getadjustment(employee_month.employee_month_id, 3, 1)) + getadjustment(employee_month.employee_month_id, 4, 33)) AS cost
   FROM (((((((employee_month
     JOIN vw_bank_branch ON ((employee_month.bank_branch_id = vw_bank_branch.bank_branch_id)))
     JOIN vw_periods ON ((employee_month.period_id = vw_periods.period_id)))
     JOIN pay_groups ON ((employee_month.pay_group_id = pay_groups.pay_group_id)))
     JOIN entitys ON ((employee_month.entity_id = entitys.entity_id)))
     JOIN vw_department_roles ON ((employee_month.department_role_id = vw_department_roles.department_role_id)))
     JOIN employees ON ((employee_month.entity_id = employees.entity_id)))
     JOIN currency ON ((employee_month.currency_id = currency.currency_id)));


ALTER TABLE public.vw_employee_month OWNER TO postgres;

--
-- Name: vw_employee_objectives; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_employee_objectives AS
 SELECT entitys.entity_id,
    entitys.entity_name,
    employee_objectives.org_id,
    employee_objectives.employee_objective_id,
    employee_objectives.employee_objective_name,
    employee_objectives.objective_date,
    employee_objectives.approve_status,
    employee_objectives.workflow_table_id,
    employee_objectives.application_date,
    employee_objectives.action_date,
    employee_objectives.supervisor_comments,
    employee_objectives.details,
    date_part('year'::text, employee_objectives.objective_date) AS objective_year
   FROM (employee_objectives
     JOIN entitys ON ((employee_objectives.entity_id = entitys.entity_id)));


ALTER TABLE public.vw_employee_objectives OWNER TO postgres;

--
-- Name: vw_employee_overtime; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_employee_overtime AS
 SELECT eml.employee_month_id,
    eml.period_id,
    eml.start_date,
    eml.month_id,
    eml.period_year,
    eml.period_month,
    eml.entity_id,
    eml.entity_name,
    eml.employee_id,
    employee_overtime.org_id,
    employee_overtime.employee_overtime_id,
    employee_overtime.overtime_date,
    employee_overtime.overtime,
    employee_overtime.overtime_rate,
    employee_overtime.narrative,
    employee_overtime.approve_status,
    employee_overtime.action_date,
    employee_overtime.details
   FROM (employee_overtime
     JOIN vw_employee_month_list eml ON ((employee_overtime.employee_month_id = eml.employee_month_id)));


ALTER TABLE public.vw_employee_overtime OWNER TO postgres;

--
-- Name: vw_pension_adjustments; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_pension_adjustments AS
 SELECT c.period_id,
    c.start_date,
    a.employee_adjustment_id,
    a.employee_month_id,
    a.adjustment_id,
    a.pension_id,
    a.org_id,
    a.adjustment_type,
    a.adjustment_factor,
    a.pay_date,
    a.amount,
    a.exchange_rate,
    a.in_payroll,
    a.in_tax,
    a.visible,
    (a.amount * a.exchange_rate) AS base_amount
   FROM ((employee_adjustments a
     JOIN employee_month b ON ((a.employee_month_id = b.employee_month_id)))
     JOIN periods c ON ((b.period_id = c.period_id)))
  WHERE (a.pension_id IS NOT NULL);


ALTER TABLE public.vw_pension_adjustments OWNER TO postgres;

--
-- Name: vw_pensions; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_pensions AS
 SELECT entitys.entity_id,
    entitys.entity_name,
    adjustments.adjustment_id,
    adjustments.adjustment_name,
    currency.currency_id,
    currency.currency_name,
    currency.currency_symbol,
    pensions.contribution_id,
    contributions.adjustment_name AS contribution_name,
    pensions.org_id,
    pensions.pension_id,
    pensions.pension_company,
    pensions.pension_number,
    pensions.amount,
    pensions.use_formura,
    pensions.employer_ps,
    pensions.employer_amount,
    pensions.employer_formural,
    pensions.active,
    pensions.details
   FROM ((((pensions
     JOIN entitys ON ((pensions.entity_id = entitys.entity_id)))
     JOIN adjustments ON ((pensions.adjustment_id = adjustments.adjustment_id)))
     JOIN adjustments contributions ON ((pensions.contribution_id = contributions.adjustment_id)))
     JOIN currency ON ((adjustments.currency_id = currency.currency_id)));


ALTER TABLE public.vw_pensions OWNER TO postgres;

--
-- Name: vw_employee_pensions; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_employee_pensions AS
 SELECT a.entity_id,
    a.entity_name,
    a.adjustment_id,
    a.adjustment_name,
    a.contribution_id,
    a.contribution_name,
    a.org_id,
    a.pension_id,
    a.pension_company,
    a.pension_number,
    a.active,
    a.currency_id,
    a.currency_name,
    a.currency_symbol,
    b.period_id,
    b.start_date,
    b.employee_month_id,
    COALESCE(b.amount, (0)::double precision) AS amount,
    COALESCE(b.base_amount, (0)::double precision) AS base_amount,
    COALESCE(c.amount, (0)::double precision) AS employer_amount,
    COALESCE(c.base_amount, (0)::double precision) AS employer_base_amount,
    (b.amount + COALESCE(c.amount, (0)::double precision)) AS pension_amount,
    (b.base_amount + COALESCE(c.base_amount, (0)::double precision)) AS pension_base_amount
   FROM ((vw_pensions a
     JOIN vw_pension_adjustments b ON (((a.pension_id = b.pension_id) AND (a.adjustment_id = b.adjustment_id))))
     LEFT JOIN vw_pension_adjustments c ON ((((a.pension_id = c.pension_id) AND (a.contribution_id = c.adjustment_id)) AND (b.employee_month_id = c.employee_month_id))));


ALTER TABLE public.vw_employee_pensions OWNER TO postgres;

--
-- Name: vw_employee_per_diem; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_employee_per_diem AS
 SELECT eml.employee_month_id,
    eml.period_id,
    eml.start_date,
    eml.month_id,
    eml.period_year,
    eml.period_month,
    eml.entity_id,
    eml.entity_name,
    eml.employee_id,
    employee_per_diem.org_id,
    employee_per_diem.employee_per_diem_id,
    employee_per_diem.travel_date,
    employee_per_diem.return_date,
    employee_per_diem.days_travelled,
    employee_per_diem.per_diem,
    employee_per_diem.cash_paid,
    employee_per_diem.tax_amount,
    employee_per_diem.full_amount,
    employee_per_diem.travel_to,
    employee_per_diem.approve_status,
    employee_per_diem.action_date,
    employee_per_diem.completed,
    employee_per_diem.post_account,
    employee_per_diem.details,
    (employee_per_diem.exchange_rate * employee_per_diem.tax_amount) AS base_tax_amount,
    (employee_per_diem.exchange_rate * employee_per_diem.full_amount) AS base_full_amount,
    ((employee_per_diem.exchange_rate * eml.exchange_rate) * employee_per_diem.full_amount) AS b_full_amount,
    ((employee_per_diem.exchange_rate * eml.exchange_rate) * employee_per_diem.cash_paid) AS b_cash_paid
   FROM (employee_per_diem
     JOIN vw_employee_month_list eml ON ((employee_per_diem.employee_month_id = eml.employee_month_id)));


ALTER TABLE public.vw_employee_per_diem OWNER TO postgres;

--
-- Name: vw_employee_per_diem_ledger; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_employee_per_diem_ledger AS
 SELECT a.org_id,
    a.period_id,
    a.travel_date,
    'Travel Cost'::text AS description,
    a.post_account,
    a.entity_name,
    a.b_full_amount AS dr_amt,
    0.0 AS cr_amt
   FROM vw_employee_per_diem a
  WHERE ((a.approve_status)::text = 'Approved'::text)
UNION
 SELECT a.org_id,
    a.period_id,
    a.travel_date,
    'Travel Payment'::text AS description,
    (get_default_account(24, a.org_id))::character varying(32) AS post_account,
    a.entity_name,
    0.0 AS dr_amt,
    a.cash_paid AS cr_amt
   FROM vw_employee_per_diem a
  WHERE ((a.approve_status)::text = 'Approved'::text)
UNION
 SELECT a.org_id,
    a.period_id,
    a.travel_date,
    'Travel PAYE'::text AS description,
    (get_default_account(25, a.org_id))::character varying(32) AS post_account,
    a.entity_name,
    0.0 AS dr_amt,
    (a.b_full_amount - a.b_cash_paid) AS cr_amt
   FROM vw_employee_per_diem a
  WHERE ((a.approve_status)::text = 'Approved'::text);


ALTER TABLE public.vw_employee_per_diem_ledger OWNER TO postgres;

--
-- Name: vw_employee_periods; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_employee_periods AS
 SELECT aa.period_id,
    aa.start_date,
    aa.period_year,
    aa.period_month,
    aa.period_code,
    aa.week_start,
    date_part('week'::text, aa.week_start) AS p_week,
    b.org_id,
    b.entity_id,
    b.employee_id,
    b.active,
    (((((b.surname)::text || ' '::text) || (b.first_name)::text) || ' '::text) || (COALESCE(b.middle_name, ''::character varying))::text) AS employee_name
   FROM (( SELECT a.org_id,
            a.period_id,
            a.start_date,
            a.end_date,
            to_char((a.start_date)::timestamp with time zone, 'YYYY'::text) AS period_year,
            to_char((a.start_date)::timestamp with time zone, 'Month'::text) AS period_month,
            to_char((a.start_date)::timestamp with time zone, 'YYYYMM'::text) AS period_code,
            generate_series((a.start_date)::timestamp with time zone, (a.end_date)::timestamp with time zone, '7 days'::interval) AS week_start
           FROM periods a) aa
     JOIN employees b ON ((aa.org_id = b.org_id)));


ALTER TABLE public.vw_employee_periods OWNER TO postgres;

--
-- Name: vw_employee_tax_month; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_employee_tax_month AS
 SELECT emp.period_id,
    emp.start_date,
    emp.end_date,
    emp.overtime_rate,
    emp.activated,
    emp.closed,
    emp.month_id,
    emp.period_year,
    emp.period_month,
    emp.quarter,
    emp.semister,
    emp.bank_header,
    emp.bank_address,
    emp.gl_payroll_account,
    emp.is_posted,
    emp.bank_id,
    emp.bank_name,
    emp.bank_branch_id,
    emp.bank_branch_name,
    emp.bank_branch_code,
    emp.pay_group_id,
    emp.pay_group_name,
    emp.department_id,
    emp.department_name,
    emp.department_role_id,
    emp.department_role_name,
    emp.entity_id,
    emp.entity_name,
    emp.employee_id,
    emp.surname,
    emp.first_name,
    emp.middle_name,
    emp.date_of_birth,
    emp.gender,
    emp.nationality,
    emp.marital_status,
    emp.appointment_date,
    emp.exit_date,
    emp.contract,
    emp.contract_period,
    emp.employment_terms,
    emp.identity_card,
    emp.employee_name,
    emp.currency_id,
    emp.currency_name,
    emp.currency_symbol,
    emp.exchange_rate,
    emp.org_id,
    emp.employee_month_id,
    emp.bank_account,
    emp.basic_pay,
    emp.details,
    emp.overtime,
    emp.full_allowance,
    emp.payroll_allowance,
    emp.tax_allowance,
    emp.full_deduction,
    emp.payroll_deduction,
    emp.tax_deduction,
    emp.full_expense,
    emp.payroll_expense,
    emp.tax_expense,
    emp.payroll_tax,
    emp.tax_tax,
    emp.net_adjustment,
    emp.per_diem,
    emp.advance,
    emp.advance_deduction,
    emp.net_pay,
    emp.banked,
    emp.cost,
    tax_types.tax_type_id,
    tax_types.tax_type_name,
    tax_types.account_id,
    tax_types.use_key_id,
    employee_tax_types.employee_tax_type_id,
    employee_tax_types.tax_identification,
    employee_tax_types.amount,
    employee_tax_types.exchange_rate AS tax_exchange_rate,
    employee_tax_types.additional,
    employee_tax_types.employer,
    employee_tax_types.narrative,
    (employee_tax_types.amount * employee_tax_types.exchange_rate) AS tax_base_amount,
    ((employee_tax_types.amount * employee_tax_types.exchange_rate) * emp.exchange_rate) AS b_tax_amount
   FROM ((vw_employee_month emp
     JOIN employee_tax_types ON ((emp.employee_month_id = employee_tax_types.employee_month_id)))
     JOIN tax_types ON ((employee_tax_types.tax_type_id = tax_types.tax_type_id)));


ALTER TABLE public.vw_employee_tax_month OWNER TO postgres;

--
-- Name: vw_employee_tax_types; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_employee_tax_types AS
 SELECT eml.employee_month_id,
    eml.period_id,
    eml.start_date,
    eml.month_id,
    eml.period_year,
    eml.period_month,
    eml.end_date,
    eml.gl_payroll_account,
    eml.entity_id,
    eml.entity_name,
    eml.employee_id,
    eml.identity_card,
    eml.surname,
    eml.first_name,
    eml.middle_name,
    eml.date_of_birth,
    eml.department_id,
    eml.department_name,
    eml.department_account,
    eml.function_code,
    eml.department_role_id,
    eml.department_role_name,
    tax_types.tax_type_id,
    tax_types.tax_type_name,
    tax_types.account_id,
    tax_types.tax_type_number,
    tax_types.account_number,
    tax_types.employer_account,
    employee_tax_types.org_id,
    employee_tax_types.employee_tax_type_id,
    employee_tax_types.tax_identification,
    employee_tax_types.amount,
    employee_tax_types.additional,
    employee_tax_types.employer,
    employee_tax_types.narrative,
    currency.currency_id,
    currency.currency_name,
    currency.currency_symbol,
    employee_tax_types.exchange_rate,
    (employee_tax_types.exchange_rate * employee_tax_types.amount) AS base_amount,
    (employee_tax_types.exchange_rate * employee_tax_types.employer) AS base_employer,
    (employee_tax_types.exchange_rate * employee_tax_types.additional) AS base_additional,
    ((employee_tax_types.exchange_rate * eml.exchange_rate) * employee_tax_types.amount) AS b_amount,
    ((employee_tax_types.exchange_rate * eml.exchange_rate) * employee_tax_types.employer) AS b_employer,
    ((employee_tax_types.exchange_rate * eml.exchange_rate) * employee_tax_types.additional) AS b_additional
   FROM (((employee_tax_types
     JOIN vw_employee_month_list eml ON ((employee_tax_types.employee_month_id = eml.employee_month_id)))
     JOIN tax_types ON ((employee_tax_types.tax_type_id = tax_types.tax_type_id)))
     JOIN currency ON ((tax_types.currency_id = currency.currency_id)));


ALTER TABLE public.vw_employee_tax_types OWNER TO postgres;

--
-- Name: vw_employee_trainings; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_employee_trainings AS
 SELECT entitys.entity_id,
    entitys.entity_name,
    trainings.training_id,
    trainings.training_name,
    trainings.training_cost,
    employee_trainings.org_id,
    employee_trainings.employee_training_id,
    employee_trainings.narrative,
    employee_trainings.completed,
    employee_trainings.application_date,
    employee_trainings.approve_status,
    employee_trainings.action_date,
    employee_trainings.details
   FROM ((employee_trainings
     JOIN entitys ON ((employee_trainings.entity_id = entitys.entity_id)))
     JOIN trainings ON ((employee_trainings.training_id = trainings.training_id)));


ALTER TABLE public.vw_employee_trainings OWNER TO postgres;

--
-- Name: vw_employees; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_employees AS
 SELECT vw_bank_branch.bank_id,
    vw_bank_branch.bank_name,
    vw_bank_branch.bank_branch_id,
    vw_bank_branch.bank_branch_name,
    vw_bank_branch.bank_branch_code,
    vw_department_roles.department_id,
    vw_department_roles.department_name,
    vw_department_roles.department_role_id,
    vw_department_roles.department_role_name,
    locations.location_id,
    locations.location_name,
    currency.currency_id,
    currency.currency_name,
    currency.currency_symbol,
    sys_countrys.sys_country_name,
    nob.sys_country_name AS birth_nation_name,
    disability.disability_id,
    disability.disability_name,
    employees.org_id,
    employees.entity_id,
    employees.employee_id,
    employees.surname,
    employees.first_name,
    employees.middle_name,
    employees.person_title,
    employees.field_of_study,
    (((((employees.surname)::text || ' '::text) || (employees.first_name)::text) || ' '::text) || (COALESCE(employees.middle_name, ''::character varying))::text) AS employee_name,
    employees.date_of_birth,
    employees.dob_email,
    employees.place_of_birth,
    employees.gender,
    employees.nationality,
    employees.nation_of_birth,
    employees.marital_status,
    employees.appointment_date,
    employees.exit_date,
    employees.contract,
    employees.contract_period,
    employees.employment_terms,
    employees.identity_card,
    employees.basic_salary,
    employees.bank_account,
    employees.language,
    employees.picture_file,
    employees.active,
    employees.height,
    employees.weight,
    employees.blood_group,
    employees.allergies,
    employees.phone,
    employees.objective,
    employees.interests,
    employees.details,
    to_char(age((employees.date_of_birth)::timestamp with time zone), 'YY'::text) AS employee_age,
        CASE
            WHEN ((employees.gender)::text = 'M'::text) THEN 'Male'::text
            ELSE 'Female'::text
        END AS gender_name,
        CASE
            WHEN ((employees.marital_status)::text = 'M'::text) THEN 'Married'::text
            ELSE 'Single'::text
        END AS marital_status_name,
    vw_education_max.education_class_name,
    vw_education_max.date_from,
    vw_education_max.date_to,
    vw_education_max.name_of_school,
    vw_education_max.examination_taken,
    vw_education_max.grades_obtained,
    vw_education_max.certificate_number
   FROM ((((((((employees
     JOIN vw_bank_branch ON ((employees.bank_branch_id = vw_bank_branch.bank_branch_id)))
     JOIN vw_department_roles ON ((employees.department_role_id = vw_department_roles.department_role_id)))
     JOIN locations ON ((employees.location_id = locations.location_id)))
     JOIN currency ON ((employees.currency_id = currency.currency_id)))
     JOIN sys_countrys ON ((employees.nationality = sys_countrys.sys_country_id)))
     LEFT JOIN sys_countrys nob ON ((employees.nation_of_birth = nob.sys_country_id)))
     LEFT JOIN disability ON ((employees.disability_id = disability.disability_id)))
     LEFT JOIN vw_education_max ON ((employees.entity_id = vw_education_max.entity_id)));


ALTER TABLE public.vw_employees OWNER TO postgres;

--
-- Name: vw_employment; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_employment AS
 SELECT entitys.entity_id,
    entitys.entity_name,
    employment.employment_id,
    employment.date_from,
    employment.date_to,
    employment.org_id,
    employment.employers_name,
    employment.position_held,
    employment.details,
    age((COALESCE(employment.date_to, ('now'::text)::date))::timestamp with time zone, (employment.date_from)::timestamp with time zone) AS employment_duration
   FROM (employment
     JOIN entitys ON ((employment.entity_id = entitys.entity_id)));


ALTER TABLE public.vw_employment OWNER TO postgres;

--
-- Name: vw_ems; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_ems AS
 SELECT em.org_id,
    em.period_id,
    em.start_date,
    em.end_date,
    em.overtime_rate,
    em.activated,
    em.closed,
    em.month_id,
    em.period_year,
    em.period_month,
    em.quarter,
    em.semister,
    em.bank_header,
    em.bank_address,
    em.gl_payroll_account,
    em.is_posted,
    em.bank_id,
    em.bank_name,
    em.bank_branch_id,
    em.bank_branch_name,
    em.bank_branch_code,
    em.pay_group_id,
    em.pay_group_name,
    em.gl_payment_account,
    em.department_id,
    em.department_name,
    em.department_role_id,
    em.department_role_name,
    em.entity_id,
    em.entity_name,
    em.employee_id,
    em.surname,
    em.first_name,
    em.middle_name,
    em.date_of_birth,
    em.gender,
    em.nationality,
    em.marital_status,
    em.appointment_date,
    em.exit_date,
    em.contract,
    em.contract_period,
    em.employment_terms,
    em.identity_card,
    em.employee_name,
    em.currency_id,
    em.currency_name,
    em.currency_symbol,
    em.exchange_rate,
    em.employee_month_id,
    em.bank_account,
    em.basic_pay,
    em.details,
    em.overtime,
    em.full_allowance,
    em.payroll_allowance,
    em.tax_allowance,
    em.full_deduction,
    em.payroll_deduction,
    em.tax_deduction,
    em.full_expense,
    em.payroll_expense,
    em.tax_expense,
    em.payroll_tax,
    em.tax_tax,
    em.net_adjustment,
    em.per_diem,
    em.advance,
    em.advance_deduction,
    em.other_banks,
    em.net_pay,
    em.banked,
    em.cost,
    (em.basic_pay * em.exchange_rate) AS b_basic_pay,
    ((em.banked + em.other_banks) * em.exchange_rate) AS b_banked
   FROM vw_employee_month em;


ALTER TABLE public.vw_ems OWNER TO postgres;

--
-- Name: vw_entity_address; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_entity_address AS
 SELECT vw_address.address_id,
    vw_address.address_name,
    vw_address.sys_country_id,
    vw_address.sys_country_name,
    vw_address.table_id,
    vw_address.table_name,
    vw_address.is_default,
    vw_address.post_office_box,
    vw_address.postal_code,
    vw_address.premises,
    vw_address.street,
    vw_address.town,
    vw_address.phone_number,
    vw_address.extension,
    vw_address.mobile,
    vw_address.fax,
    vw_address.email,
    vw_address.website
   FROM vw_address
  WHERE (((vw_address.table_name)::text = 'entitys'::text) AND (vw_address.is_default = true));


ALTER TABLE public.vw_entity_address OWNER TO postgres;

--
-- Name: vw_entity_employees; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_entity_employees AS
 SELECT entitys.entity_id,
    entitys.org_id,
    entitys.entity_type_id,
    entitys.entity_name,
    entitys.user_name,
    entitys.primary_email,
    entitys.super_user,
    entitys.entity_leader,
    entitys.function_role,
    entitys.date_enroled,
    entitys.is_active,
    entitys.entity_password,
    entitys.first_password,
    entitys.is_picked,
    employees.employee_id,
    employees.surname,
    employees.first_name,
    employees.middle_name,
    employees.date_of_birth,
    employees.dob_email,
    employees.gender,
    employees.nationality,
    employees.marital_status,
    employees.appointment_date,
    employees.exit_date,
    employees.contract,
    employees.contract_period,
    employees.employment_terms,
    employees.identity_card,
    employees.basic_salary,
    employees.bank_account,
    employees.language,
    employees.objective,
    employees.active
   FROM (entitys
     JOIN employees ON ((entitys.entity_id = employees.entity_id)));


ALTER TABLE public.vw_entity_employees OWNER TO postgres;

--
-- Name: vw_entity_subscriptions; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_entity_subscriptions AS
 SELECT entity_types.entity_type_id,
    entity_types.entity_type_name,
    entitys.entity_id,
    entitys.entity_name,
    subscription_levels.subscription_level_id,
    subscription_levels.subscription_level_name,
    entity_subscriptions.entity_subscription_id,
    entity_subscriptions.org_id,
    entity_subscriptions.details
   FROM (((entity_subscriptions
     JOIN entity_types ON ((entity_subscriptions.entity_type_id = entity_types.entity_type_id)))
     JOIN entitys ON ((entity_subscriptions.entity_id = entitys.entity_id)))
     JOIN subscription_levels ON ((entity_subscriptions.subscription_level_id = subscription_levels.subscription_level_id)));


ALTER TABLE public.vw_entity_subscriptions OWNER TO postgres;

--
-- Name: vw_entity_types; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_entity_types AS
 SELECT use_keys.use_key_id,
    use_keys.use_key_name,
    use_keys.use_function,
    entity_types.entity_type_id,
    entity_types.org_id,
    entity_types.entity_type_name,
    entity_types.entity_role,
    entity_types.start_view,
    entity_types.group_email,
    entity_types.description,
    entity_types.details
   FROM (use_keys
     JOIN entity_types ON ((use_keys.use_key_id = entity_types.use_key_id)));


ALTER TABLE public.vw_entity_types OWNER TO postgres;

--
-- Name: vw_org_address; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_org_address AS
 SELECT vw_address.sys_country_id AS org_sys_country_id,
    vw_address.sys_country_name AS org_sys_country_name,
    vw_address.address_id AS org_address_id,
    vw_address.table_id AS org_table_id,
    vw_address.table_name AS org_table_name,
    vw_address.post_office_box AS org_post_office_box,
    vw_address.postal_code AS org_postal_code,
    vw_address.premises AS org_premises,
    vw_address.street AS org_street,
    vw_address.town AS org_town,
    vw_address.phone_number AS org_phone_number,
    vw_address.extension AS org_extension,
    vw_address.mobile AS org_mobile,
    vw_address.fax AS org_fax,
    vw_address.email AS org_email,
    vw_address.website AS org_website
   FROM vw_address
  WHERE (((vw_address.table_name)::text = 'orgs'::text) AND (vw_address.is_default = true));


ALTER TABLE public.vw_org_address OWNER TO postgres;

--
-- Name: vw_orgs; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_orgs AS
 SELECT orgs.org_id,
    orgs.org_name,
    orgs.is_default,
    orgs.is_active,
    orgs.logo,
    orgs.org_full_name,
    orgs.pin,
    orgs.pcc,
    orgs.details,
    orgs.cert_number,
    orgs.vat_number,
    orgs.invoice_footer,
    currency.currency_id,
    currency.currency_name,
    currency.currency_symbol,
    vw_org_address.org_sys_country_id,
    vw_org_address.org_sys_country_name,
    vw_org_address.org_address_id,
    vw_org_address.org_table_name,
    vw_org_address.org_post_office_box,
    vw_org_address.org_postal_code,
    vw_org_address.org_premises,
    vw_org_address.org_street,
    vw_org_address.org_town,
    vw_org_address.org_phone_number,
    vw_org_address.org_extension,
    vw_org_address.org_mobile,
    vw_org_address.org_fax,
    vw_org_address.org_email,
    vw_org_address.org_website
   FROM ((orgs
     JOIN currency ON ((orgs.currency_id = currency.currency_id)))
     LEFT JOIN vw_org_address ON ((orgs.org_id = vw_org_address.org_table_id)));


ALTER TABLE public.vw_orgs OWNER TO postgres;

--
-- Name: vw_entitys; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_entitys AS
 SELECT vw_orgs.org_id,
    vw_orgs.org_name,
    vw_orgs.is_default AS org_is_default,
    vw_orgs.is_active AS org_is_active,
    vw_orgs.logo AS org_logo,
    vw_orgs.cert_number AS org_cert_number,
    vw_orgs.pin AS org_pin,
    vw_orgs.vat_number AS org_vat_number,
    vw_orgs.invoice_footer AS org_invoice_footer,
    vw_orgs.org_sys_country_id,
    vw_orgs.org_sys_country_name,
    vw_orgs.org_address_id,
    vw_orgs.org_table_name,
    vw_orgs.org_post_office_box,
    vw_orgs.org_postal_code,
    vw_orgs.org_premises,
    vw_orgs.org_street,
    vw_orgs.org_town,
    vw_orgs.org_phone_number,
    vw_orgs.org_extension,
    vw_orgs.org_mobile,
    vw_orgs.org_fax,
    vw_orgs.org_email,
    vw_orgs.org_website,
    addr.address_id,
    addr.address_name,
    addr.sys_country_id,
    addr.sys_country_name,
    addr.table_name,
    addr.is_default,
    addr.post_office_box,
    addr.postal_code,
    addr.premises,
    addr.street,
    addr.town,
    addr.phone_number,
    addr.extension,
    addr.mobile,
    addr.fax,
    addr.email,
    addr.website,
    entity_types.entity_type_id,
    entity_types.entity_type_name,
    entity_types.entity_role,
    entitys.entity_id,
    entitys.use_key_id,
    entitys.entity_name,
    entitys.user_name,
    entitys.super_user,
    entitys.entity_leader,
    entitys.date_enroled,
    entitys.is_active,
    entitys.entity_password,
    entitys.first_password,
    entitys.function_role,
    entitys.attention,
    entitys.primary_email,
    entitys.primary_telephone,
    entitys.credit_limit
   FROM (((entitys
     LEFT JOIN vw_address_entitys addr ON ((entitys.entity_id = addr.table_id)))
     JOIN vw_orgs ON ((entitys.org_id = vw_orgs.org_id)))
     JOIN entity_types ON ((entitys.entity_type_id = entity_types.entity_type_id)));


ALTER TABLE public.vw_entitys OWNER TO postgres;

--
-- Name: vw_entry_forms; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_entry_forms AS
 SELECT entitys.entity_id,
    entitys.entity_name,
    forms.form_id,
    forms.form_name,
    forms.form_number,
    forms.completed,
    forms.is_active,
    forms.use_key,
    entry_forms.org_id,
    entry_forms.entry_form_id,
    entry_forms.approve_status,
    entry_forms.application_date,
    entry_forms.completion_date,
    entry_forms.action_date,
    entry_forms.narrative,
    entry_forms.answer,
    entry_forms.workflow_table_id,
    entry_forms.details
   FROM ((entry_forms
     JOIN entitys ON ((entry_forms.entity_id = entitys.entity_id)))
     JOIN forms ON ((entry_forms.form_id = forms.form_id)));


ALTER TABLE public.vw_entry_forms OWNER TO postgres;

--
-- Name: vw_objectives; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_objectives AS
 SELECT vw_employee_objectives.entity_id,
    vw_employee_objectives.entity_name,
    vw_employee_objectives.employee_objective_id,
    vw_employee_objectives.employee_objective_name,
    vw_employee_objectives.objective_date,
    vw_employee_objectives.approve_status,
    vw_employee_objectives.workflow_table_id,
    vw_employee_objectives.application_date,
    vw_employee_objectives.action_date,
    vw_employee_objectives.supervisor_comments,
    objective_types.objective_type_id,
    objective_types.objective_type_name,
    objectives.org_id,
    objectives.objective_id,
    objectives.date_set,
    objectives.objective_ps,
    objectives.objective_name,
    objectives.objective_completed,
    objectives.details
   FROM ((objectives
     JOIN vw_employee_objectives ON ((objectives.employee_objective_id = vw_employee_objectives.employee_objective_id)))
     JOIN objective_types ON ((objectives.objective_type_id = objective_types.objective_type_id)));


ALTER TABLE public.vw_objectives OWNER TO postgres;

--
-- Name: vw_evaluation_objectives; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_evaluation_objectives AS
 SELECT vw_job_reviews.entity_id,
    vw_job_reviews.entity_name,
    vw_job_reviews.review_category_id,
    vw_job_reviews.review_category_name,
    vw_job_reviews.rate_objectives,
    vw_job_reviews.job_review_id,
    vw_job_reviews.total_points,
    vw_job_reviews.review_date,
    vw_job_reviews.review_done,
    vw_job_reviews.recomendation,
    vw_job_reviews.reviewer_comments,
    vw_job_reviews.pl_comments,
    vw_job_reviews.approve_status,
    vw_job_reviews.workflow_table_id,
    vw_job_reviews.application_date,
    vw_job_reviews.action_date,
    vw_objectives.objective_type_id,
    vw_objectives.objective_type_name,
    vw_objectives.objective_id,
    vw_objectives.date_set,
    vw_objectives.objective_ps,
    vw_objectives.objective_name,
    vw_objectives.objective_completed,
    vw_objectives.details AS objective_details,
    evaluation_points.org_id,
    evaluation_points.evaluation_point_id,
    evaluation_points.points,
    evaluation_points.reviewer_points,
    evaluation_points.reviewer_narrative,
    evaluation_points.narrative,
    evaluation_points.details
   FROM ((evaluation_points
     JOIN vw_job_reviews ON ((evaluation_points.job_review_id = vw_job_reviews.job_review_id)))
     JOIN vw_objectives ON ((evaluation_points.objective_id = vw_objectives.objective_id)));


ALTER TABLE public.vw_evaluation_objectives OWNER TO postgres;

--
-- Name: vw_review_points; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_review_points AS
 SELECT review_category.review_category_id,
    review_category.review_category_name,
    review_category.details AS review_category_details,
    review_points.org_id,
    review_points.review_point_id,
    review_points.review_point_name,
    review_points.review_points,
    review_points.details
   FROM (review_points
     JOIN review_category ON ((review_points.review_category_id = review_category.review_category_id)));


ALTER TABLE public.vw_review_points OWNER TO postgres;

--
-- Name: vw_evaluation_points; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_evaluation_points AS
 SELECT vw_job_reviews.entity_id,
    vw_job_reviews.entity_name,
    vw_job_reviews.review_category_id,
    vw_job_reviews.review_category_name,
    vw_job_reviews.rate_objectives,
    vw_job_reviews.job_review_id,
    vw_job_reviews.total_points,
    vw_job_reviews.review_date,
    vw_job_reviews.review_done,
    vw_job_reviews.recomendation,
    vw_job_reviews.reviewer_comments,
    vw_job_reviews.pl_comments,
    vw_job_reviews.approve_status,
    vw_job_reviews.workflow_table_id,
    vw_job_reviews.application_date,
    vw_job_reviews.action_date,
    vw_review_points.review_point_id,
    vw_review_points.review_point_name,
    vw_review_points.review_points,
    evaluation_points.org_id,
    evaluation_points.evaluation_point_id,
    evaluation_points.points,
    evaluation_points.grade,
    evaluation_points.reviewer_points,
    evaluation_points.reviewer_grade,
    evaluation_points.reviewer_narrative,
    evaluation_points.narrative,
    evaluation_points.details
   FROM ((evaluation_points
     JOIN vw_job_reviews ON ((evaluation_points.job_review_id = vw_job_reviews.job_review_id)))
     JOIN vw_review_points ON ((evaluation_points.review_point_id = vw_review_points.review_point_id)));


ALTER TABLE public.vw_evaluation_points OWNER TO postgres;

--
-- Name: vw_fields; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_fields AS
 SELECT forms.form_id,
    forms.form_name,
    fields.field_id,
    fields.org_id,
    fields.question,
    fields.field_lookup,
    fields.field_type,
    fields.field_order,
    fields.share_line,
    fields.field_size,
    fields.field_fnct,
    fields.manditory,
    fields.field_bold,
    fields.field_italics
   FROM (fields
     JOIN forms ON ((fields.form_id = forms.form_id)));


ALTER TABLE public.vw_fields OWNER TO postgres;

--
-- Name: vw_leads; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_leads AS
 SELECT entitys.entity_id,
    entitys.entity_name,
    industry.industry_id,
    industry.industry_name,
    sys_countrys.sys_country_id,
    sys_countrys.sys_country_name,
    leads.org_id,
    leads.lead_id,
    leads.business_name,
    leads.business_address,
    leads.city,
    leads.state,
    leads.country_id,
    leads.number_of_employees,
    leads.telephone,
    leads.website,
    leads.primary_contact,
    leads.job_title,
    leads.primary_email,
    leads.prospect_level,
    leads.contact_date,
    leads.details
   FROM (((leads
     JOIN entitys ON ((leads.entity_id = entitys.entity_id)))
     JOIN industry ON ((leads.industry_id = industry.industry_id)))
     JOIN sys_countrys ON ((leads.country_id = sys_countrys.sys_country_id)));


ALTER TABLE public.vw_leads OWNER TO postgres;

--
-- Name: vw_lead_items; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_lead_items AS
 SELECT entitys.entity_id,
    entitys.entity_name,
    items.item_id,
    items.item_name,
    vw_leads.industry_id,
    vw_leads.industry_name,
    vw_leads.sys_country_id,
    vw_leads.sys_country_name,
    vw_leads.lead_id,
    vw_leads.business_name,
    vw_leads.business_address,
    vw_leads.city,
    vw_leads.state,
    vw_leads.country_id,
    vw_leads.number_of_employees,
    vw_leads.telephone,
    vw_leads.website,
    vw_leads.primary_contact,
    vw_leads.job_title,
    vw_leads.primary_email,
    vw_leads.prospect_level,
    vw_leads.contact_date,
    lead_items.org_id,
    lead_items.lead_item_id,
    lead_items.pitch_date,
    lead_items.units,
    lead_items.price,
    lead_items.lead_level,
    lead_items.narrative,
    lead_items.details,
    ((lead_items.units)::double precision * lead_items.price) AS lead_value
   FROM (((lead_items
     JOIN vw_leads ON ((lead_items.lead_id = vw_leads.lead_id)))
     JOIN entitys ON ((lead_items.entity_id = entitys.entity_id)))
     JOIN items ON ((lead_items.item_id = items.item_id)));


ALTER TABLE public.vw_lead_items OWNER TO postgres;

--
-- Name: vw_follow_up; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_follow_up AS
 SELECT vw_lead_items.item_id,
    vw_lead_items.item_name,
    vw_lead_items.industry_id,
    vw_lead_items.industry_name,
    vw_lead_items.sys_country_id,
    vw_lead_items.sys_country_name,
    vw_lead_items.lead_id,
    vw_lead_items.business_name,
    vw_lead_items.business_address,
    vw_lead_items.city,
    vw_lead_items.state,
    vw_lead_items.country_id,
    vw_lead_items.number_of_employees,
    vw_lead_items.telephone,
    vw_lead_items.website,
    vw_lead_items.primary_contact,
    vw_lead_items.job_title,
    vw_lead_items.primary_email,
    vw_lead_items.prospect_level,
    vw_lead_items.contact_date,
    vw_lead_items.lead_item_id,
    vw_lead_items.pitch_date,
    vw_lead_items.units,
    vw_lead_items.price,
    vw_lead_items.lead_value,
    vw_lead_items.lead_level,
    entitys.entity_id,
    entitys.entity_name,
    follow_up.org_id,
    follow_up.follow_up_id,
    follow_up.create_time,
    follow_up.follow_date,
    follow_up.follow_time,
    follow_up.done,
    follow_up.narrative,
    follow_up.details
   FROM ((follow_up
     JOIN vw_lead_items ON ((follow_up.lead_item_id = vw_lead_items.lead_item_id)))
     JOIN entitys ON ((follow_up.entity_id = entitys.entity_id)));


ALTER TABLE public.vw_follow_up OWNER TO postgres;

--
-- Name: vw_journals; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_journals AS
 SELECT vw_periods.fiscal_year_id,
    vw_periods.fiscal_year_start,
    vw_periods.fiscal_year_end,
    vw_periods.year_opened,
    vw_periods.year_closed,
    vw_periods.period_id,
    vw_periods.start_date,
    vw_periods.end_date,
    vw_periods.opened,
    vw_periods.closed,
    vw_periods.month_id,
    vw_periods.period_year,
    vw_periods.period_month,
    vw_periods.quarter,
    vw_periods.semister,
    currency.currency_id,
    currency.currency_name,
    currency.currency_symbol,
    departments.department_id,
    departments.department_name,
    journals.journal_id,
    journals.org_id,
    journals.journal_date,
    journals.posted,
    journals.year_closing,
    journals.narrative,
    journals.exchange_rate,
    journals.details
   FROM (((journals
     JOIN vw_periods ON ((journals.period_id = vw_periods.period_id)))
     JOIN currency ON ((journals.currency_id = currency.currency_id)))
     LEFT JOIN departments ON ((journals.department_id = departments.department_id)));


ALTER TABLE public.vw_journals OWNER TO postgres;

--
-- Name: vw_gls; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_gls AS
 SELECT vw_accounts.account_class_id,
    vw_accounts.account_class_no,
    vw_accounts.account_class_name,
    vw_accounts.chat_type_id,
    vw_accounts.chat_type_name,
    vw_accounts.account_type_id,
    vw_accounts.account_type_no,
    vw_accounts.account_type_name,
    vw_accounts.account_id,
    vw_accounts.account_no,
    vw_accounts.account_name,
    vw_accounts.is_header,
    vw_accounts.is_active,
    vw_journals.fiscal_year_id,
    vw_journals.fiscal_year_start,
    vw_journals.fiscal_year_end,
    vw_journals.year_opened,
    vw_journals.year_closed,
    vw_journals.period_id,
    vw_journals.start_date,
    vw_journals.end_date,
    vw_journals.opened,
    vw_journals.closed,
    vw_journals.month_id,
    vw_journals.period_year,
    vw_journals.period_month,
    vw_journals.quarter,
    vw_journals.semister,
    vw_journals.currency_id,
    vw_journals.currency_name,
    vw_journals.currency_symbol,
    vw_journals.exchange_rate,
    vw_journals.journal_id,
    vw_journals.journal_date,
    vw_journals.posted,
    vw_journals.year_closing,
    vw_journals.narrative,
    gls.gl_id,
    gls.org_id,
    gls.debit,
    gls.credit,
    gls.gl_narrative,
    (gls.debit * vw_journals.exchange_rate) AS base_debit,
    (gls.credit * vw_journals.exchange_rate) AS base_credit
   FROM ((gls
     JOIN vw_accounts ON ((gls.account_id = vw_accounts.account_id)))
     JOIN vw_journals ON ((gls.journal_id = vw_journals.journal_id)));


ALTER TABLE public.vw_gls OWNER TO postgres;

--
-- Name: vw_pdefinitions; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_pdefinitions AS
 SELECT ptypes.ptype_id,
    ptypes.ptype_name,
    pdefinitions.org_id,
    pdefinitions.pdefinition_id,
    pdefinitions.pdefinition_name,
    pdefinitions.description,
    pdefinitions.solution
   FROM (pdefinitions
     JOIN ptypes ON ((pdefinitions.ptype_id = ptypes.ptype_id)));


ALTER TABLE public.vw_pdefinitions OWNER TO postgres;

--
-- Name: vw_helpdesk; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_helpdesk AS
 SELECT vw_pdefinitions.ptype_id,
    vw_pdefinitions.ptype_name,
    vw_pdefinitions.pdefinition_id,
    vw_pdefinitions.pdefinition_name,
    plevels.plevel_id,
    plevels.plevel_name,
    helpdesk.client_id,
    clients.entity_name AS client_name,
    helpdesk.recorded_by,
    recorder.entity_name AS recorder_name,
    helpdesk.closed_by,
    closer.entity_name AS closer_name,
    helpdesk.org_id,
    helpdesk.helpdesk_id,
    helpdesk.description,
    helpdesk.reported_by,
    helpdesk.recoded_time,
    helpdesk.solved_time,
    helpdesk.is_solved,
    helpdesk.curr_action,
    helpdesk.curr_status,
    helpdesk.problem,
    helpdesk.solution
   FROM (((((helpdesk
     JOIN vw_pdefinitions ON ((helpdesk.pdefinition_id = vw_pdefinitions.pdefinition_id)))
     JOIN plevels ON ((helpdesk.plevel_id = plevels.plevel_id)))
     JOIN entitys clients ON ((helpdesk.client_id = clients.entity_id)))
     JOIN entitys recorder ON ((helpdesk.recorded_by = recorder.entity_id)))
     LEFT JOIN entitys closer ON ((helpdesk.closed_by = closer.entity_id)));


ALTER TABLE public.vw_helpdesk OWNER TO postgres;

--
-- Name: vw_identifications; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_identifications AS
 SELECT entitys.entity_id,
    entitys.entity_name,
    identification_types.identification_type_id,
    identification_types.identification_type_name,
    identifications.org_id,
    identifications.identification_id,
    identifications.identification,
    identifications.is_active,
    identifications.starting_from,
    identifications.expiring_at,
    identifications.place_of_issue,
    identifications.details
   FROM ((identifications
     JOIN entitys ON ((identifications.entity_id = entitys.entity_id)))
     JOIN identification_types ON ((identifications.identification_type_id = identification_types.identification_type_id)));


ALTER TABLE public.vw_identifications OWNER TO postgres;

--
-- Name: vw_internships; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_internships AS
 SELECT departments.department_id,
    departments.department_name,
    internships.internship_id,
    internships.opening_date,
    orgs.org_id,
    orgs.org_name,
    orgs.details AS org_details,
    internships.closing_date,
    internships.positions,
    internships.location,
    internships.details
   FROM ((internships
     JOIN departments ON ((internships.department_id = departments.department_id)))
     JOIN orgs ON ((internships.org_id = orgs.org_id)));


ALTER TABLE public.vw_internships OWNER TO postgres;

--
-- Name: vw_intern_evaluations; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_intern_evaluations AS
 SELECT vw_applicants.entity_id,
    vw_applicants.sys_country_name,
    vw_applicants.applicant_name,
    vw_applicants.applicant_age,
    vw_applicants.gender_name,
    vw_applicants.marital_status_name,
    vw_applicants.language,
    vw_applicants.objective,
    vw_applicants.interests,
    education.date_from,
    education.date_to,
    education.name_of_school,
    education.examination_taken,
    vw_internships.department_id,
    vw_internships.department_name,
    vw_internships.internship_id,
    vw_internships.positions,
    vw_internships.opening_date,
    vw_internships.closing_date,
    interns.intern_id,
    interns.payment_amount,
    interns.start_date,
    interns.end_date,
    interns.application_date,
    interns.approve_status,
    interns.action_date,
    interns.workflow_table_id,
    interns.applicant_comments,
    interns.review
   FROM ((((vw_applicants
     JOIN education ON ((vw_applicants.entity_id = education.entity_id)))
     JOIN interns ON ((interns.entity_id = vw_applicants.entity_id)))
     JOIN vw_internships ON ((interns.internship_id = vw_internships.internship_id)))
     JOIN ( SELECT education_1.entity_id,
            max(education_1.education_class_id) AS mx_class_id
           FROM education education_1
          WHERE (education_1.entity_id IS NOT NULL)
          GROUP BY education_1.entity_id) a ON (((education.entity_id = a.entity_id) AND (education.education_class_id = a.mx_class_id))))
  WHERE (education.education_class_id > 6)
  ORDER BY vw_applicants.entity_id;


ALTER TABLE public.vw_intern_evaluations OWNER TO postgres;

--
-- Name: vw_interns; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_interns AS
 SELECT entitys.entity_id,
    entitys.entity_name,
    entitys.primary_email,
    entitys.primary_telephone,
    vw_internships.department_id,
    vw_internships.department_name,
    vw_internships.org_name,
    vw_internships.org_details,
    vw_internships.internship_id,
    vw_internships.positions,
    vw_internships.opening_date,
    vw_internships.closing_date,
    interns.org_id,
    interns.intern_id,
    interns.payment_amount,
    interns.start_date,
    interns.end_date,
    interns.application_date,
    interns.approve_status,
    interns.action_date,
    interns.workflow_table_id,
    interns.phone_mobile,
    interns.applicant_comments,
    interns.review,
    vw_education_max.education_class_name,
    vw_education_max.date_from,
    vw_education_max.date_to,
    vw_education_max.name_of_school,
    vw_education_max.examination_taken,
    vw_education_max.grades_obtained,
    vw_education_max.certificate_number
   FROM (((interns
     JOIN entitys ON ((interns.entity_id = entitys.entity_id)))
     JOIN vw_internships ON ((interns.internship_id = vw_internships.internship_id)))
     LEFT JOIN vw_education_max ON ((entitys.entity_id = vw_education_max.entity_id)));


ALTER TABLE public.vw_interns OWNER TO postgres;

--
-- Name: vw_kins; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_kins AS
 SELECT entitys.entity_id,
    entitys.entity_name,
    kin_types.kin_type_id,
    kin_types.kin_type_name,
    kins.org_id,
    kins.kin_id,
    kins.full_names,
    kins.date_of_birth,
    kins.identification,
    kins.relation,
    kins.emergency_contact,
    kins.beneficiary,
    kins.beneficiary_ps,
    kins.details
   FROM ((kins
     JOIN entitys ON ((kins.entity_id = entitys.entity_id)))
     JOIN kin_types ON ((kins.kin_type_id = kin_types.kin_type_id)));


ALTER TABLE public.vw_kins OWNER TO postgres;

--
-- Name: vw_leave_work_days; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_leave_work_days AS
 SELECT vw_employee_leave.entity_id,
    vw_employee_leave.entity_name,
    vw_employee_leave.leave_type_id,
    vw_employee_leave.leave_type_name,
    vw_employee_leave.employee_leave_id,
    vw_employee_leave.leave_from,
    vw_employee_leave.leave_to,
    vw_employee_leave.start_half_day,
    vw_employee_leave.end_half_day,
    leave_work_days.org_id,
    leave_work_days.leave_work_day_id,
    leave_work_days.work_date,
    leave_work_days.half_day,
    leave_work_days.application_date,
    leave_work_days.approve_status,
    leave_work_days.workflow_table_id,
    leave_work_days.action_date,
    leave_work_days.details
   FROM (leave_work_days
     JOIN vw_employee_leave ON ((leave_work_days.employee_leave_id = vw_employee_leave.employee_leave_id)));


ALTER TABLE public.vw_leave_work_days OWNER TO postgres;

--
-- Name: vw_sm_gls; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_sm_gls AS
 SELECT vw_gls.org_id,
    vw_gls.account_class_id,
    vw_gls.account_class_no,
    vw_gls.account_class_name,
    vw_gls.chat_type_id,
    vw_gls.chat_type_name,
    vw_gls.account_type_id,
    vw_gls.account_type_no,
    vw_gls.account_type_name,
    vw_gls.account_id,
    vw_gls.account_no,
    vw_gls.account_name,
    vw_gls.is_header,
    vw_gls.is_active,
    vw_gls.fiscal_year_id,
    vw_gls.fiscal_year_start,
    vw_gls.fiscal_year_end,
    vw_gls.year_opened,
    vw_gls.year_closed,
    vw_gls.period_id,
    vw_gls.start_date,
    vw_gls.end_date,
    vw_gls.opened,
    vw_gls.closed,
    vw_gls.month_id,
    vw_gls.period_year,
    vw_gls.period_month,
    vw_gls.quarter,
    vw_gls.semister,
    sum(vw_gls.debit) AS acc_debit,
    sum(vw_gls.credit) AS acc_credit,
    sum(vw_gls.base_debit) AS acc_base_debit,
    sum(vw_gls.base_credit) AS acc_base_credit
   FROM vw_gls
  WHERE (vw_gls.posted = true)
  GROUP BY vw_gls.org_id, vw_gls.account_class_id, vw_gls.account_class_no, vw_gls.account_class_name, vw_gls.chat_type_id, vw_gls.chat_type_name, vw_gls.account_type_id, vw_gls.account_type_no, vw_gls.account_type_name, vw_gls.account_id, vw_gls.account_no, vw_gls.account_name, vw_gls.is_header, vw_gls.is_active, vw_gls.fiscal_year_id, vw_gls.fiscal_year_start, vw_gls.fiscal_year_end, vw_gls.year_opened, vw_gls.year_closed, vw_gls.period_id, vw_gls.start_date, vw_gls.end_date, vw_gls.opened, vw_gls.closed, vw_gls.month_id, vw_gls.period_year, vw_gls.period_month, vw_gls.quarter, vw_gls.semister
  ORDER BY vw_gls.account_id;


ALTER TABLE public.vw_sm_gls OWNER TO postgres;

--
-- Name: vw_ledger; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_ledger AS
 SELECT vw_sm_gls.org_id,
    vw_sm_gls.account_class_id,
    vw_sm_gls.account_class_no,
    vw_sm_gls.account_class_name,
    vw_sm_gls.chat_type_id,
    vw_sm_gls.chat_type_name,
    vw_sm_gls.account_type_id,
    vw_sm_gls.account_type_no,
    vw_sm_gls.account_type_name,
    vw_sm_gls.account_id,
    vw_sm_gls.account_no,
    vw_sm_gls.account_name,
    vw_sm_gls.is_header,
    vw_sm_gls.is_active,
    vw_sm_gls.fiscal_year_id,
    vw_sm_gls.fiscal_year_start,
    vw_sm_gls.fiscal_year_end,
    vw_sm_gls.year_opened,
    vw_sm_gls.year_closed,
    vw_sm_gls.period_id,
    vw_sm_gls.start_date,
    vw_sm_gls.end_date,
    vw_sm_gls.opened,
    vw_sm_gls.closed,
    vw_sm_gls.month_id,
    vw_sm_gls.period_year,
    vw_sm_gls.period_month,
    vw_sm_gls.quarter,
    vw_sm_gls.semister,
    vw_sm_gls.acc_debit,
    vw_sm_gls.acc_credit,
    (vw_sm_gls.acc_debit - vw_sm_gls.acc_credit) AS acc_balance,
    COALESCE(
        CASE
            WHEN (vw_sm_gls.acc_debit > vw_sm_gls.acc_credit) THEN (vw_sm_gls.acc_debit - vw_sm_gls.acc_credit)
            ELSE (0)::real
        END, (0)::real) AS bal_debit,
    COALESCE(
        CASE
            WHEN (vw_sm_gls.acc_debit < vw_sm_gls.acc_credit) THEN (vw_sm_gls.acc_credit - vw_sm_gls.acc_debit)
            ELSE (0)::real
        END, (0)::real) AS bal_credit,
    vw_sm_gls.acc_base_debit,
    vw_sm_gls.acc_base_credit,
    (vw_sm_gls.acc_base_debit - vw_sm_gls.acc_base_credit) AS acc_base_balance,
    COALESCE(
        CASE
            WHEN (vw_sm_gls.acc_base_debit > vw_sm_gls.acc_base_credit) THEN (vw_sm_gls.acc_base_debit - vw_sm_gls.acc_base_credit)
            ELSE (0)::real
        END, (0)::real) AS bal_base_debit,
    COALESCE(
        CASE
            WHEN (vw_sm_gls.acc_base_debit < vw_sm_gls.acc_base_credit) THEN (vw_sm_gls.acc_base_credit - vw_sm_gls.acc_base_debit)
            ELSE (0)::real
        END, (0)::real) AS bal_base_credit
   FROM vw_sm_gls;


ALTER TABLE public.vw_ledger OWNER TO postgres;

--
-- Name: vw_ledger_types; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_ledger_types AS
 SELECT vw_accounts.account_class_id,
    vw_accounts.chat_type_id,
    vw_accounts.chat_type_name,
    vw_accounts.account_class_name,
    vw_accounts.account_type_id,
    vw_accounts.account_type_name,
    vw_accounts.account_id,
    vw_accounts.account_no,
    vw_accounts.account_name,
    vw_accounts.is_header,
    vw_accounts.is_active,
    ta.account_class_id AS t_account_class_id,
    ta.chat_type_id AS t_chat_type_id,
    ta.chat_type_name AS t_chat_type_name,
    ta.account_class_name AS t_account_class_name,
    ta.account_type_id AS t_account_type_id,
    ta.account_type_name AS t_account_type_name,
    ta.account_id AS t_account_id,
    ta.account_no AS t_account_no,
    ta.account_name AS t_account_name,
    ledger_types.org_id,
    ledger_types.ledger_type_id,
    ledger_types.ledger_type_name,
    ledger_types.ledger_posting,
    ledger_types.income_ledger,
    ledger_types.expense_ledger,
    ledger_types.details
   FROM ((ledger_types
     JOIN vw_accounts ON ((ledger_types.account_id = vw_accounts.account_id)))
     JOIN vw_accounts ta ON ((ledger_types.tax_account_id = ta.account_id)));


ALTER TABLE public.vw_ledger_types OWNER TO postgres;

--
-- Name: vw_loan_types; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_loan_types AS
 SELECT adjustments.adjustment_id,
    adjustments.adjustment_name,
    adjustments.account_number,
    currency.currency_id,
    currency.currency_name,
    currency.currency_symbol,
    loan_types.org_id,
    loan_types.loan_type_id,
    loan_types.loan_type_name,
    loan_types.default_interest,
    loan_types.reducing_balance,
    loan_types.details
   FROM ((loan_types
     JOIN adjustments ON ((loan_types.adjustment_id = adjustments.adjustment_id)))
     JOIN currency ON ((adjustments.currency_id = currency.currency_id)));


ALTER TABLE public.vw_loan_types OWNER TO postgres;

--
-- Name: vw_loans; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_loans AS
 SELECT vw_loan_types.adjustment_id,
    vw_loan_types.adjustment_name,
    vw_loan_types.account_number,
    vw_loan_types.currency_id,
    vw_loan_types.currency_name,
    vw_loan_types.currency_symbol,
    vw_loan_types.loan_type_id,
    vw_loan_types.loan_type_name,
    entitys.entity_id,
    entitys.entity_name,
    employees.employee_id,
    loans.org_id,
    loans.loan_id,
    loans.principle,
    loans.interest,
    loans.monthly_repayment,
    loans.reducing_balance,
    loans.repayment_period,
    loans.initial_payment,
    loans.loan_date,
    loans.application_date,
    loans.approve_status,
    loans.workflow_table_id,
    loans.action_date,
    loans.details,
    get_repayment(loans.principle, loans.interest, loans.repayment_period) AS repayment_amount,
    (loans.initial_payment + get_total_repayment(loans.loan_id)) AS total_repayment,
    get_total_interest(loans.loan_id) AS total_interest,
    (((loans.principle + get_total_interest(loans.loan_id)) - loans.initial_payment) - get_total_repayment(loans.loan_id)) AS loan_balance,
    get_payment_period(loans.principle, loans.monthly_repayment, loans.interest) AS calc_repayment_period
   FROM (((loans
     JOIN entitys ON ((loans.entity_id = entitys.entity_id)))
     JOIN employees ON ((loans.entity_id = employees.entity_id)))
     JOIN vw_loan_types ON ((loans.loan_type_id = vw_loan_types.loan_type_id)));


ALTER TABLE public.vw_loans OWNER TO postgres;

--
-- Name: vw_loan_monthly; Type: VIEW; Schema: public; Owner: postgres
--

CREATE VIEW vw_loan_monthly AS
 SELECT vw_loans.adjustment_id,
    vw_loans.adjustment_name,
    vw_loans.account_number,
    vw_loans.currency_id,
    vw_loans.currency_name,
    vw_loans.currency_symbol,
    vw_loans.loan_type_id,
    vw_loans.loan_type_name,
    vw_loans.entity_id,
    vw_loans.entity_name,
    vw_loans.employee_id,
    vw_loans.loan_date,
    vw_loans.loan_id,
    vw_loans.principle,
    vw_loans.interest,
    vw_loans.monthly_repayment,
    vw_loans.reducing_balance,
    vw_loans.repayment_period,
    vw_periods.period_id,
    vw_periods.start_date,
    vw_periods.end_date,
    vw_periods.activated,
    vw_periods.closed,
    loan_monthly.org_id,
    loan_monthly.loan_month_id,
    loan_monthly.interest_amount,
    loan_monthly.repayment,
    loan_monthly.interest_paid,
    loan_monthly.employee_adjustment_id,
    loan_monthly.penalty,
    loan_monthly.penalty_paid,
    loan_monthly.extra_payment,
    loan_monthly.details,
    get_total_interest(vw_loans.loan_id, vw_periods.start_date) AS total_interest,
    get_total_repayment(vw_loans.loan_id, vw_periods.start_date) AS total_repayment,
    ((((vw_loans.principle + get_total_interest(vw_loans.loan_id, (vw_periods.start_date + 1))) + get_penalty(vw_loans.loan_id, (vw_periods.start_date + 1))) - vw_loans.initial_payment) - get_total_repayment(vw_loans.loan_id, (vw_periods.start_date + 1))) AS loan_balance
   FROM ((loan_monthly
     JOIN vw_loans ON ((loan_monthly.loan_id = vw_loans.loan_id)))
     JOIN vw_periods ON ((loan_monthly.period_id = vw_periods.period_id)));


ALTER TABLE public.vw_loan_monthly OWNER TO postgres;

--
