



--
-- Name: companies; Type: TABLE; Schema: public; Owner: ramimmah
--

CREATE TABLE public.companies (
    id integer NOT NULL,
    company_name character varying(255),
    contact_person character varying(150),
    phone character varying(50),
    email character varying(150),
    address text,
    created_at timestamp without time zone DEFAULT now(),
    advance_payment numeric(10,2) DEFAULT 0
);


ALTER TABLE public.companies OWNER TO ramimmah;

--
-- Name: companies_id_seq; Type: SEQUENCE; Schema: public; Owner: ramimmah
--

CREATE SEQUENCE public.companies_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.companies_id_seq OWNER TO ramimmah;

--
-- Name: companies_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: ramimmah
--

ALTER SEQUENCE public.companies_id_seq OWNED BY public.companies.id;


--
-- Name: company_payments; Type: TABLE; Schema: public; Owner: ramimmah
--

CREATE TABLE public.company_payments (
    id integer NOT NULL,
    receipt_number character varying(150),
    company_id integer,
    amount numeric(10,2),
    payment_method character varying(50),
    created_at timestamp without time zone DEFAULT now()
);


ALTER TABLE public.company_payments OWNER TO ramimmah;

--
-- Name: company_payments_id_seq; Type: SEQUENCE; Schema: public; Owner: ramimmah
--

CREATE SEQUENCE public.company_payments_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.company_payments_id_seq OWNER TO ramimmah;

--
-- Name: company_payments_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: ramimmah
--

ALTER SEQUENCE public.company_payments_id_seq OWNED BY public.company_payments.id;


--
-- Name: expenses; Type: TABLE; Schema: public; Owner: ramimmah
--

CREATE TABLE public.expenses (
    id integer NOT NULL,
    expenses_name character varying(255),
    category character varying(150),
    amount numeric(10,2),
    expense_date date,
    note text,
    created_at timestamp without time zone DEFAULT now()
);


ALTER TABLE public.expenses OWNER TO ramimmah;

--
-- Name: expenses_id_seq; Type: SEQUENCE; Schema: public; Owner: ramimmah
--

CREATE SEQUENCE public.expenses_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.expenses_id_seq OWNER TO ramimmah;

--
-- Name: expenses_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: ramimmah
--

ALTER SEQUENCE public.expenses_id_seq OWNED BY public.expenses.id;


--
-- Name: product_images; Type: TABLE; Schema: public; Owner: ramimmah
--

CREATE TABLE public.product_images (
    id integer NOT NULL,
    variant_id integer,
    image_path text,
    is_primary boolean DEFAULT false,
    created_at timestamp without time zone DEFAULT now()
);


ALTER TABLE public.product_images OWNER TO ramimmah;

--
-- Name: product_images_id_seq; Type: SEQUENCE; Schema: public; Owner: ramimmah
--

CREATE SEQUENCE public.product_images_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.product_images_id_seq OWNER TO ramimmah;

--
-- Name: product_images_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: ramimmah
--

ALTER SEQUENCE public.product_images_id_seq OWNED BY public.product_images.id;


--
-- Name: product_variants; Type: TABLE; Schema: public; Owner: ramimmah
--

CREATE TABLE public.product_variants (
    id integer NOT NULL,
    product_id integer,
    size character varying(50),
    quantity integer DEFAULT 0,
    buying_price numeric(10,2),
    selling_price numeric(10,2),
    image_path text,
    created_at timestamp without time zone DEFAULT now()
);


ALTER TABLE public.product_variants OWNER TO ramimmah;

--
-- Name: product_variants_id_seq; Type: SEQUENCE; Schema: public; Owner: ramimmah
--

CREATE SEQUENCE public.product_variants_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.product_variants_id_seq OWNER TO ramimmah;

--
-- Name: product_variants_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: ramimmah
--

ALTER SEQUENCE public.product_variants_id_seq OWNED BY public.product_variants.id;


--
-- Name: products; Type: TABLE; Schema: public; Owner: ramimmah
--

CREATE TABLE public.products (
    id integer NOT NULL,
    product_name character varying(255),
    lot_details character varying(255),
    description text,
    category character varying(100),
    is_deleted boolean DEFAULT false,
    is_visible boolean DEFAULT true,
    created_at timestamp without time zone DEFAULT now()
);


ALTER TABLE public.products OWNER TO ramimmah;

--
-- Name: products_id_seq; Type: SEQUENCE; Schema: public; Owner: ramimmah
--

CREATE SEQUENCE public.products_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.products_id_seq OWNER TO ramimmah;

--
-- Name: products_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: ramimmah
--

ALTER SEQUENCE public.products_id_seq OWNED BY public.products.id;


--
-- Name: sales; Type: TABLE; Schema: public; Owner: ramimmah
--

CREATE TABLE public.sales (
    id integer NOT NULL,
    product_variant_id integer,
    buyer_name character varying(255),
    quantity integer,
    unit_price numeric(10,2),
    total_price numeric(10,2),
    sale_date date,
    payment_method character varying(50),
    note text,
    buying_price numeric(10,2),
    phone_number character varying(30),
    profit numeric(10,2),
    receipt_number character varying(150),
    paid_amount numeric(10,2),
    due_amount numeric(10,2),
    created_at timestamp without time zone DEFAULT now()
);


ALTER TABLE public.sales OWNER TO ramimmah;

--
-- Name: sales_id_seq; Type: SEQUENCE; Schema: public; Owner: ramimmah
--

CREATE SEQUENCE public.sales_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.sales_id_seq OWNER TO ramimmah;

--
-- Name: sales_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: ramimmah
--

ALTER SEQUENCE public.sales_id_seq OWNED BY public.sales.id;


--
-- Name: shipment_items; Type: TABLE; Schema: public; Owner: ramimmah
--

CREATE TABLE public.shipment_items (
    id integer NOT NULL,
    shipment_id integer,
    product_name character varying(255),
    quantity integer,
    unit_price numeric(10,2),
    cost_price numeric(10,2),
    created_at timestamp without time zone DEFAULT now()
);


ALTER TABLE public.shipment_items OWNER TO ramimmah;

--
-- Name: shipment_items_id_seq; Type: SEQUENCE; Schema: public; Owner: ramimmah
--

CREATE SEQUENCE public.shipment_items_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.shipment_items_id_seq OWNER TO ramimmah;

--
-- Name: shipment_items_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: ramimmah
--

ALTER SEQUENCE public.shipment_items_id_seq OWNED BY public.shipment_items.id;


--
-- Name: shipments; Type: TABLE; Schema: public; Owner: ramimmah
--

CREATE TABLE public.shipments (
    id integer NOT NULL,
    shipment_number character varying(150),
    company_id integer,
    shipping_cost numeric(10,2),
    order_date date,
    paid_amount numeric(10,2),
    due_amount numeric(10,2),
    shipment_date date,
    arrival_date date,
    created_at timestamp without time zone DEFAULT now(),
    shipping_date date,
    tracking_code character varying(255)
);


ALTER TABLE public.shipments OWNER TO ramimmah;

--
-- Name: shipments_id_seq; Type: SEQUENCE; Schema: public; Owner: ramimmah
--

CREATE SEQUENCE public.shipments_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.shipments_id_seq OWNER TO ramimmah;

--
-- Name: shipments_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: ramimmah
--

ALTER SEQUENCE public.shipments_id_seq OWNED BY public.shipments.id;

--
-- Name: users_id_seq; Type: SEQUENCE; Schema: public; Owner: ramimmah
--

CREATE SEQUENCE public.users_id_seq
    AS integer
    START WITH 1
    INCREMENT BY 1
    NO MINVALUE
    NO MAXVALUE
    CACHE 1;


ALTER TABLE public.users_id_seq OWNER TO ramimmah;

--
-- Name: users_id_seq; Type: SEQUENCE OWNED BY; Schema: public; Owner: ramimmah
--

ALTER SEQUENCE public.users_id_seq OWNED BY public.users.id;


--
-- Name: companies id; Type: DEFAULT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.companies ALTER COLUMN id SET DEFAULT nextval('public.companies_id_seq'::regclass);


--
-- Name: company_payments id; Type: DEFAULT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.company_payments ALTER COLUMN id SET DEFAULT nextval('public.company_payments_id_seq'::regclass);


--
-- Name: expenses id; Type: DEFAULT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.expenses ALTER COLUMN id SET DEFAULT nextval('public.expenses_id_seq'::regclass);


--
-- Name: product_images id; Type: DEFAULT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.product_images ALTER COLUMN id SET DEFAULT nextval('public.product_images_id_seq'::regclass);


--
-- Name: product_variants id; Type: DEFAULT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.product_variants ALTER COLUMN id SET DEFAULT nextval('public.product_variants_id_seq'::regclass);


--
-- Name: products id; Type: DEFAULT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.products ALTER COLUMN id SET DEFAULT nextval('public.products_id_seq'::regclass);


--
-- Name: sales id; Type: DEFAULT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.sales ALTER COLUMN id SET DEFAULT nextval('public.sales_id_seq'::regclass);


--
-- Name: shipment_items id; Type: DEFAULT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.shipment_items ALTER COLUMN id SET DEFAULT nextval('public.shipment_items_id_seq'::regclass);


--
-- Name: shipments id; Type: DEFAULT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.shipments ALTER COLUMN id SET DEFAULT nextval('public.shipments_id_seq'::regclass);


--
-- Name: companies companies_pkey; Type: CONSTRAINT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.companies
    ADD CONSTRAINT companies_pkey PRIMARY KEY (id);


--
-- Name: company_payments company_payments_pkey; Type: CONSTRAINT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.company_payments
    ADD CONSTRAINT company_payments_pkey PRIMARY KEY (id);


--
-- Name: expenses expenses_pkey; Type: CONSTRAINT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.expenses
    ADD CONSTRAINT expenses_pkey PRIMARY KEY (id);


--
-- Name: product_images product_images_pkey; Type: CONSTRAINT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.product_images
    ADD CONSTRAINT product_images_pkey PRIMARY KEY (id);


--
-- Name: product_variants product_variants_pkey; Type: CONSTRAINT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.product_variants
    ADD CONSTRAINT product_variants_pkey PRIMARY KEY (id);


--
-- Name: products products_pkey; Type: CONSTRAINT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.products
    ADD CONSTRAINT products_pkey PRIMARY KEY (id);


--
-- Name: sales sales_pkey; Type: CONSTRAINT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.sales
    ADD CONSTRAINT sales_pkey PRIMARY KEY (id);


--
-- Name: shipment_items shipment_items_pkey; Type: CONSTRAINT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.shipment_items
    ADD CONSTRAINT shipment_items_pkey PRIMARY KEY (id);


--
-- Name: shipments shipments_pkey; Type: CONSTRAINT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.shipments
    ADD CONSTRAINT shipments_pkey PRIMARY KEY (id);


--
-- Name: company_payments company_payments_company_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.company_payments
    ADD CONSTRAINT company_payments_company_id_fkey FOREIGN KEY (company_id) REFERENCES public.companies(id);


--
-- Name: product_images product_images_variant_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.product_images
    ADD CONSTRAINT product_images_variant_id_fkey FOREIGN KEY (variant_id) REFERENCES public.product_variants(id);


--
-- Name: product_variants product_variants_product_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.product_variants
    ADD CONSTRAINT product_variants_product_id_fkey FOREIGN KEY (product_id) REFERENCES public.products(id);


--
-- Name: sales sales_product_variant_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.sales
    ADD CONSTRAINT sales_product_variant_id_fkey FOREIGN KEY (product_variant_id) REFERENCES public.product_variants(id);


--
-- Name: shipment_items shipment_items_shipment_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.shipment_items
    ADD CONSTRAINT shipment_items_shipment_id_fkey FOREIGN KEY (shipment_id) REFERENCES public.shipments(id);


--
-- Name: shipments shipments_company_id_fkey; Type: FK CONSTRAINT; Schema: public; Owner: ramimmah
--

ALTER TABLE ONLY public.shipments
    ADD CONSTRAINT shipments_company_id_fkey FOREIGN KEY (company_id) REFERENCES public.companies(id);


--
-- Name: TABLE companies; Type: ACL; Schema: public; Owner: ramimmah
--

GRANT ALL ON TABLE public.companies TO ramimmah_shtrading;


--
-- Name: TABLE company_payments; Type: ACL; Schema: public; Owner: ramimmah
--

GRANT ALL ON TABLE public.company_payments TO ramimmah_shtrading;


--
-- Name: TABLE expenses; Type: ACL; Schema: public; Owner: ramimmah
--

GRANT ALL ON TABLE public.expenses TO ramimmah_shtrading;


--
-- Name: TABLE product_images; Type: ACL; Schema: public; Owner: ramimmah
--

GRANT ALL ON TABLE public.product_images TO ramimmah_shtrading;


--
-- Name: TABLE product_variants; Type: ACL; Schema: public; Owner: ramimmah
--

GRANT ALL ON TABLE public.product_variants TO ramimmah_shtrading;


--
-- Name: TABLE products; Type: ACL; Schema: public; Owner: ramimmah
--

GRANT ALL ON TABLE public.products TO ramimmah_shtrading;


--
-- Name: TABLE sales; Type: ACL; Schema: public; Owner: ramimmah
--

GRANT ALL ON TABLE public.sales TO ramimmah_shtrading;


--
-- Name: TABLE shipment_items; Type: ACL; Schema: public; Owner: ramimmah
--

GRANT ALL ON TABLE public.shipment_items TO ramimmah_shtrading;


--
-- Name: TABLE shipments; Type: ACL; Schema: public; Owner: ramimmah
--

GRANT ALL ON TABLE public.shipments TO ramimmah_shtrading;


--
-- Name: TABLE users; Type: ACL; Schema: public; Owner: ramimmah
--

GRANT ALL ON TABLE public.users TO ramimmah_shtrading;