-- phpMyAdmin SQL Dump
-- version 5.2.1
-- https://www.phpmyadmin.net/
--
-- Host: 127.0.0.1
-- Generation Time: Feb 19, 2026 at 10:22 AM
-- Server version: 10.4.32-MariaDB
-- PHP Version: 8.2.12

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Database: `newgst`
--

-- --------------------------------------------------------

--
-- Table structure for table `backups`
--

CREATE TABLE `backups` (
  `id` int(11) NOT NULL,
  `filename` varchar(255) NOT NULL,
  `filepath` text DEFAULT NULL,
  `file_size` bigint(20) DEFAULT NULL,
  `created_at` datetime DEFAULT NULL,
  `created_by` varchar(100) DEFAULT NULL,
  `remarks` text DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

-- --------------------------------------------------------

--
-- Table structure for table `company`
--

CREATE TABLE `company` (
  `id` int(11) NOT NULL,
  `name` varchar(300) NOT NULL,
  `email` varchar(300) NOT NULL,
  `phone` varchar(255) NOT NULL,
  `mobile` varchar(300) NOT NULL,
  `address` text NOT NULL,
  `city` varchar(255) NOT NULL,
  `state_name` varchar(255) NOT NULL,
  `state_code` varchar(10) NOT NULL,
  `zipcode` varchar(10) NOT NULL,
  `gstin` varchar(255) NOT NULL,
  `pan` varchar(255) NOT NULL,
  `logo` varchar(255) NOT NULL,
  `bank_details` text NOT NULL,
  `terms_conditions` text NOT NULL,
  `website` varchar(255) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

--
-- Dumping data for table `company`
--

INSERT INTO `company` (`id`, `name`, `email`, `phone`, `mobile`, `address`, `city`, `state_name`, `state_code`, `zipcode`, `gstin`, `pan`, `logo`, `bank_details`, `terms_conditions`, `website`) VALUES
(1, 'Indrani', 'admin@example.com', '1234567890', '1234567890', 'Address', 'City', 'State', '27', '123456', 'GSTIN', 'PAN', 'uploads/logo/logo_1771059841.png', '', '', '');

-- --------------------------------------------------------

--
-- Table structure for table `credit_notes`
--

CREATE TABLE `credit_notes` (
  `id` bigint(20) NOT NULL,
  `credit_note_no` varchar(50) NOT NULL,
  `credit_note_date` date NOT NULL,
  `party_id` bigint(20) NOT NULL,
  `billing_address_id` int(11) DEFAULT NULL,
  `original_invoice_id` bigint(20) DEFAULT NULL,
  `original_invoice_no` varchar(50) DEFAULT NULL,
  `credit_note_type` enum('sales_return','rate_difference','discount','others') NOT NULL,
  `gst_treatment` enum('tax_invoice','bill_of_supply') DEFAULT 'tax_invoice',
  `reverse_charge` tinyint(1) DEFAULT 0,
  `taxable_amount` decimal(15,2) DEFAULT 0.00,
  `total_tax` decimal(15,2) DEFAULT 0.00,
  `freight_charge` decimal(15,2) DEFAULT 0.00,
  `packing_charge` decimal(15,2) DEFAULT 0.00,
  `discount_amount` decimal(15,2) DEFAULT 0.00,
  `round_off` decimal(10,2) DEFAULT 0.00,
  `net_amount` decimal(15,2) DEFAULT 0.00,
  `adjustment_type` enum('refund','adjust_invoice','adjust_future') DEFAULT 'adjust_invoice',
  `refund_amount` decimal(15,2) DEFAULT 0.00,
  `adjusted_amount` decimal(15,2) DEFAULT 0.00,
  `balance_amount` decimal(15,2) DEFAULT 0.00,
  `is_gst_adjusted` tinyint(1) DEFAULT 0,
  `gst_return_period` varchar(10) DEFAULT NULL,
  `reason` text DEFAULT NULL,
  `remarks` text DEFAULT NULL,
  `status` enum('draft','posted','cancelled','adjusted') DEFAULT 'draft',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

--
-- Dumping data for table `credit_notes`
--

INSERT INTO `credit_notes` (`id`, `credit_note_no`, `credit_note_date`, `party_id`, `billing_address_id`, `original_invoice_id`, `original_invoice_no`, `credit_note_type`, `gst_treatment`, `reverse_charge`, `taxable_amount`, `total_tax`, `freight_charge`, `packing_charge`, `discount_amount`, `round_off`, `net_amount`, `adjustment_type`, `refund_amount`, `adjusted_amount`, `balance_amount`, `is_gst_adjusted`, `gst_return_period`, `reason`, `remarks`, `status`, `created_at`, `updated_at`) VALUES
(3, 'CN2026020001', '2026-02-17', 16, 17, NULL, NULL, 'others', 'tax_invoice', 0, 1400.00, 71.40, 0.00, 0.00, 0.00, 0.00, 1471.40, 'refund', 1471.00, 0.40, 0.40, 0, NULL, '', '', 'posted', '2026-02-17 14:41:14', '2026-02-17 14:41:14');

-- --------------------------------------------------------

--
-- Table structure for table `debit_notes`
--

CREATE TABLE `debit_notes` (
  `id` bigint(20) NOT NULL,
  `debit_note_no` varchar(50) NOT NULL,
  `debit_note_date` date NOT NULL,
  `party_id` bigint(20) NOT NULL,
  `billing_address_id` int(11) DEFAULT NULL,
  `original_bill_id` bigint(20) DEFAULT NULL,
  `original_bill_no` varchar(50) DEFAULT NULL,
  `debit_note_type` enum('purchase_return','rate_difference','damage_claim','shortage','others') NOT NULL,
  `gst_treatment` enum('tax_invoice','bill_of_supply') DEFAULT 'tax_invoice',
  `reverse_charge` tinyint(1) DEFAULT 0,
  `taxable_amount` decimal(15,2) DEFAULT 0.00,
  `total_tax` decimal(15,2) DEFAULT 0.00,
  `freight_charge` decimal(15,2) DEFAULT 0.00,
  `packing_charge` decimal(15,2) DEFAULT 0.00,
  `discount_amount` decimal(15,2) DEFAULT 0.00,
  `round_off` decimal(10,2) DEFAULT 0.00,
  `net_amount` decimal(15,2) DEFAULT 0.00,
  `adjustment_type` enum('refund','adjust_bill','adjust_future') DEFAULT 'adjust_bill',
  `refund_amount` decimal(15,2) DEFAULT 0.00,
  `adjusted_amount` decimal(15,2) DEFAULT 0.00,
  `balance_amount` decimal(15,2) DEFAULT 0.00,
  `is_gst_adjusted` tinyint(1) DEFAULT 0,
  `gst_return_period` varchar(10) DEFAULT NULL,
  `reason` text DEFAULT NULL,
  `remarks` text DEFAULT NULL,
  `status` enum('draft','posted','cancelled','adjusted') DEFAULT 'draft',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

-- --------------------------------------------------------

--
-- Table structure for table `document_items`
--

CREATE TABLE `document_items` (
  `id` bigint(20) NOT NULL,
  `doc_type` enum('quotation','proforma','sales_challan','sales_invoice','credit_note','purchase_order','purchase_challan','purchase_bill','debit_note') NOT NULL,
  `doc_id` bigint(20) NOT NULL,
  `product_id` bigint(20) NOT NULL,
  `product_name` varchar(255) DEFAULT NULL,
  `description` text DEFAULT NULL,
  `hsn_code` varchar(20) DEFAULT NULL,
  `quantity` decimal(15,2) NOT NULL,
  `unit` varchar(50) DEFAULT NULL,
  `unit_price` decimal(15,2) NOT NULL,
  `discount_percent` decimal(5,2) DEFAULT 0.00,
  `discount_amount` decimal(15,2) DEFAULT 0.00,
  `taxable_value` decimal(15,2) DEFAULT 0.00,
  `tax_rate` decimal(5,2) DEFAULT 0.00,
  `cgst_percent` decimal(5,2) DEFAULT 0.00,
  `sgst_percent` decimal(5,2) DEFAULT 0.00,
  `igst_percent` decimal(5,2) DEFAULT 0.00,
  `cgst_amount` decimal(15,2) DEFAULT 0.00,
  `sgst_amount` decimal(15,2) DEFAULT 0.00,
  `igst_amount` decimal(15,2) DEFAULT 0.00,
  `cess_percent` decimal(5,2) DEFAULT 0.00,
  `cess_amount` decimal(15,2) DEFAULT 0.00,
  `total_tax` decimal(15,2) DEFAULT 0.00,
  `total_amount` decimal(15,2) DEFAULT 0.00,
  `original_item_id` bigint(20) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

--
-- Dumping data for table `document_items`
--

INSERT INTO `document_items` (`id`, `doc_type`, `doc_id`, `product_id`, `product_name`, `description`, `hsn_code`, `quantity`, `unit`, `unit_price`, `discount_percent`, `discount_amount`, `taxable_value`, `tax_rate`, `cgst_percent`, `sgst_percent`, `igst_percent`, `cgst_amount`, `sgst_amount`, `igst_amount`, `cess_percent`, `cess_amount`, `total_tax`, `total_amount`, `original_item_id`) VALUES
(10, 'quotation', 10, 1, 'test name', NULL, '84008600', 2.00, 'pcs', 200.00, 20.00, 80.00, 320.00, 5.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 16.00, 336.00, NULL),
(12, 'quotation', 12, 3, 'test', NULL, '', 4.00, 'pcs', 6000.00, 50.00, 12000.00, 12000.00, 5.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 600.00, 12600.00, NULL),
(21, 'proforma', 2, 3, 'test', NULL, '', 1.00, 'pcs', 6000.00, 0.00, 0.00, 6000.00, 5.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 300.00, 6300.00, NULL),
(22, 'proforma', 2, 1, 'test name', NULL, '84008600', 3.00, 'pcs', 200.00, 0.00, 0.00, 600.00, 5.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 30.00, 630.00, NULL),
(24, 'sales_challan', 1, 1, 'test name', NULL, '84008600', 2.00, 'pcs', 200.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 400.00, NULL),
(28, 'sales_challan', 3, 1, 'test name', NULL, '84008600', 4.00, 'pcs', 200.00, 10.00, 80.00, 720.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 720.00, NULL),
(31, 'sales_invoice', 1, 1, 'test name', NULL, '84008600', 3.00, 'pcs', 200.00, 10.00, 60.00, 540.00, 0.00, 2.50, 2.50, 0.00, 13.50, 13.50, 0.00, 0.10, 0.54, 27.54, 567.54, NULL),
(34, 'credit_note', 1, 1, 'test name', NULL, '84008600', 2.00, 'pcs', 200.00, 7.00, 28.00, 372.00, 0.00, 2.50, 2.50, 0.00, 9.30, 9.30, 0.00, 0.10, 0.37, 18.97, 390.97, NULL),
(38, 'quotation', 18, 1, 'test name', NULL, '84008600', 2.00, 'pcs', 200.00, 0.00, 0.00, 400.00, 5.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 20.00, 420.00, NULL),
(41, 'proforma', 1, 1, 'test name', NULL, '84008600', 3.00, 'pcs', 200.00, 0.00, 0.00, 600.00, 5.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 30.00, 630.00, NULL),
(42, 'credit_note', 2, 1, 'test name', NULL, '84008600', 1.00, 'pcs', 200.00, 0.00, 0.00, 200.00, 0.00, 2.50, 2.50, 0.00, 5.00, 5.00, 0.00, 0.10, 0.20, 10.20, 210.20, NULL),
(47, 'sales_invoice', 3, 5, 'test', NULL, '', 2.00, 'pcs', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, NULL),
(49, 'quotation', 19, 1, 'test name', NULL, '84008600', 2.00, 'pcs', 200.00, 0.00, 0.00, 400.00, 5.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 20.00, 420.00, NULL),
(50, 'proforma', 5, 1, 'test name', NULL, '84008600', 2.00, 'pcs', 200.00, 0.00, 0.00, 400.00, 5.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 20.00, 420.00, NULL),
(51, 'sales_challan', 4, 1, 'test name', NULL, '84008600', 2.00, 'pcs', 200.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 400.00, NULL),
(54, 'sales_invoice', 5, 1, 'test name', NULL, '84008600', 2.00, 'pcs', 200.00, 0.00, 0.00, 400.00, 0.00, 2.50, 2.50, 0.00, 10.00, 10.00, 0.00, 0.10, 0.40, 20.40, 420.40, NULL),
(55, 'sales_invoice', 6, 1, 'test name', NULL, '84008600', 3.00, 'pcs', 200.00, 0.00, 0.00, 600.00, 0.00, 2.50, 2.50, 0.00, 15.00, 15.00, 0.00, 0.10, 0.60, 30.60, 630.60, NULL),
(56, 'sales_invoice', 7, 1, 'test name', NULL, '84008600', 1.00, 'pcs', 200.00, 0.00, 0.00, 200.00, 0.00, 2.50, 2.50, 0.00, 5.00, 5.00, 0.00, 0.10, 0.20, 10.20, 210.20, NULL),
(58, 'quotation', 20, 1, 'test name', NULL, '84008600', 4.00, 'pcs', 200.00, 20.00, 160.00, 640.00, 5.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 32.00, 672.00, NULL),
(59, 'proforma', 6, 1, 'test name', NULL, '84008600', 4.00, 'pcs', 200.00, 0.00, 0.00, 800.00, 5.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 40.00, 840.00, NULL),
(60, 'sales_challan', 5, 1, 'test name', NULL, '84008600', 4.00, 'pcs', 200.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 800.00, NULL),
(62, 'proforma', 7, 1, 'test name', NULL, '84008600', 2.00, 'pcs', 200.00, 0.00, 0.00, 400.00, 5.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 20.00, 420.00, NULL),
(63, 'sales_invoice', 8, 1, 'test name', NULL, '84008600', 2.00, 'pcs', 200.00, 0.00, 0.00, 400.00, 0.00, 2.50, 2.50, 0.00, 10.00, 10.00, 0.00, 0.10, 0.40, 20.40, 420.40, NULL),
(64, 'sales_invoice', 9, 1, 'test name', NULL, '84008600', 1.00, 'pcs', 200.00, 0.00, 0.00, 200.00, 0.00, 2.50, 2.50, 0.00, 5.00, 5.00, 0.00, 0.10, 0.20, 10.20, 210.20, NULL),
(65, 'sales_challan', 7, 1, 'test name', NULL, '84008600', 3.00, 'pcs', 200.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 600.00, NULL),
(66, 'sales_challan', 6, 1, 'test name', NULL, '84008600', 2.00, 'pcs', 200.00, 0.00, 0.00, 400.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 400.00, NULL),
(68, 'sales_invoice', 10, 1, 'test name', NULL, '84008600', 7.00, 'pcs', 200.00, 0.00, 0.00, 1400.00, 0.00, 2.50, 2.50, 0.00, 35.00, 35.00, 0.00, 0.10, 1.40, 71.40, 1471.40, NULL),
(69, 'credit_note', 3, 1, 'test name', NULL, '84008600', 7.00, 'pcs', 200.00, 0.00, 0.00, 1400.00, 0.00, 2.50, 2.50, 0.00, 35.00, 35.00, 0.00, 0.10, 1.40, 71.40, 1471.40, NULL),
(70, 'purchase_order', 1, 1, 'test name', NULL, '84008600', 5.00, 'pcs', 150.00, 10.00, 75.00, 675.00, 5.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 33.75, 708.75, NULL),
(72, 'purchase_order', 2, 2, 'test name', NULL, '84008600', 3.00, 'pcs', 200.00, 0.00, 0.00, 600.00, 10.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 60.00, 660.00, NULL),
(73, 'purchase_challan', 1, 1, 'test name', NULL, '84008600', 4.00, 'pcs', 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, NULL),
(75, 'purchase_challan', 2, 1, 'test name', NULL, '84008600', 3.00, 'pcs', 150.00, 0.00, 0.00, 450.00, 5.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 22.50, 472.50, NULL),
(80, 'purchase_bill', 1, 1, 'test name', NULL, '84008600', 3.00, 'pcs', 150.00, 0.00, 0.00, 450.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.00, 0.10, 0.45, 0.45, 450.45, NULL);

-- --------------------------------------------------------

--
-- Table structure for table `gst_returns`
--

CREATE TABLE `gst_returns` (
  `id` bigint(20) NOT NULL,
  `return_type` enum('GSTR1','GSTR3B','GSTR9') NOT NULL,
  `return_period` varchar(10) DEFAULT NULL,
  `filing_date` date DEFAULT NULL,
  `total_taxable_value` decimal(15,2) DEFAULT 0.00,
  `total_cgst` decimal(15,2) DEFAULT 0.00,
  `total_sgst` decimal(15,2) DEFAULT 0.00,
  `total_igst` decimal(15,2) DEFAULT 0.00,
  `total_cess` decimal(15,2) DEFAULT 0.00,
  `status` enum('pending','filed','verified') DEFAULT 'pending',
  `filed_date` date DEFAULT NULL,
  `acknowledgment_no` varchar(100) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

-- --------------------------------------------------------

--
-- Table structure for table `gst_return_details`
--

CREATE TABLE `gst_return_details` (
  `id` bigint(20) NOT NULL,
  `gst_return_id` bigint(20) NOT NULL,
  `document_type` enum('sales_invoice','purchase_bill','credit_note','debit_note') NOT NULL,
  `document_id` bigint(20) NOT NULL,
  `taxable_value` decimal(15,2) DEFAULT 0.00,
  `cgst_amount` decimal(15,2) DEFAULT 0.00,
  `sgst_amount` decimal(15,2) DEFAULT 0.00,
  `igst_amount` decimal(15,2) DEFAULT 0.00,
  `cess_amount` decimal(15,2) DEFAULT 0.00
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

-- --------------------------------------------------------

--
-- Table structure for table `parties`
--

CREATE TABLE `parties` (
  `id` bigint(20) NOT NULL,
  `party_type` enum('customer','supplier','both') NOT NULL,
  `party_name` varchar(255) NOT NULL,
  `contact_person` varchar(255) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `mobile` varchar(255) DEFAULT NULL,
  `phone` varchar(255) DEFAULT NULL,
  `address` text DEFAULT NULL,
  `city` varchar(255) DEFAULT NULL,
  `pincode` varchar(10) DEFAULT NULL,
  `state_name` varchar(255) DEFAULT NULL,
  `state_code` varchar(10) DEFAULT NULL,
  `gstin` varchar(255) DEFAULT NULL,
  `pan` varchar(255) DEFAULT NULL,
  `opening_balance` decimal(15,2) DEFAULT 0.00,
  `credit_limit` decimal(15,2) DEFAULT 0.00,
  `outstanding_amt` decimal(15,2) DEFAULT 0.00,
  `status` tinyint(1) DEFAULT 1,
  `created_at` date DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

--
-- Dumping data for table `parties`
--

INSERT INTO `parties` (`id`, `party_type`, `party_name`, `contact_person`, `email`, `mobile`, `phone`, `address`, `city`, `pincode`, `state_name`, `state_code`, `gstin`, `pan`, `opening_balance`, `credit_limit`, `outstanding_amt`, `status`, `created_at`, `updated_at`) VALUES
(13, 'customer', 'Party', 'test person', 'mail@mail.com', '2020202020', '2020202020', 'Karond Chouraha', 'Bhopal', '462001', 'Madhya Pradesh', 'MP', '202020W', '202020', 200000.00, 2000.00, 40.00, 1, '2026-02-14', '2026-02-18 07:10:54'),
(14, 'customer', 'Atharv', 'Party', '', '3030303030', '3030303030', 'Nishatpura', 'Bhopal', '462001', 'Madhya Pradesh', 'MP', '', '', 200.00, 0.00, 0.00, 1, '2026-02-17', '2026-02-17 14:10:08'),
(15, 'customer', 'Anant', 'Atharv', '', '', '', 'Nishatpura', 'Bhopal', '462001', 'Madhya Pradesh', 'MP', '', '', 0.00, 0.00, 0.00, 1, '2026-02-17', '2026-02-17 14:26:10'),
(16, 'customer', 'Dhruv', 'Anant', 'testmail@mail.com', '5050505050', '5050505050', 'Nishatpura', 'Bhopal', '462001', 'Madhya Pradesh', 'MP', '', '', 200.00, 0.00, 0.00, 1, '2026-02-17', '2026-02-17 14:45:06'),
(17, 'supplier', 'Abhi Infra', 'Kailash', 'testmail@mail.com', '7525265354', '52653652352', 'Piplani', 'Bhopal', '462001', 'Madhya Pradesh', 'MP', '78087889989', 'JKK5426132', 100000.00, 50000.00, 450.45, 1, '2026-02-18', '2026-02-18 12:15:06'),
(19, 'both', 'Garud', 'Anant', 'testmail@mail.com', '2020202020', '2020202020', 'Indrapuri', 'Bhopal', '462001', 'Madhya Pradesh', 'MP', '78087889989', '789GY123', 100000.00, 10000.00, 0.00, 1, '2026-02-18', '2026-02-18 07:57:23'),
(20, 'supplier', 'Dev', 'Anant', 'testmail@mail.com', '7894564552', '4568795564', 'Shyamla Hills', 'Bhopal', '462001', 'Madhya Pradesh', 'MP', '4578942562', '444GG5545', 20000.00, 5000.00, 0.00, 1, '2026-02-18', '2026-02-18 10:51:45');

-- --------------------------------------------------------

--
-- Table structure for table `party_addresses`
--

CREATE TABLE `party_addresses` (
  `id` int(11) NOT NULL,
  `party_id` bigint(20) DEFAULT NULL,
  `address_type` enum('billing','shipping','both') DEFAULT 'both',
  `address` text DEFAULT NULL,
  `city` varchar(255) DEFAULT NULL,
  `pincode` varchar(10) DEFAULT NULL,
  `state_name` varchar(255) DEFAULT NULL,
  `state_code` varchar(10) DEFAULT NULL,
  `is_default` tinyint(1) DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

--
-- Dumping data for table `party_addresses`
--

INSERT INTO `party_addresses` (`id`, `party_id`, `address_type`, `address`, `city`, `pincode`, `state_name`, `state_code`, `is_default`) VALUES
(14, 13, 'both', 'Karond Chouraha', 'Bhopal', '462001', 'Madhya Pradesh', 'MP', 1),
(15, 14, 'both', 'Nishatpura', 'Bhopal', '462001', 'Madhya Pradesh', 'MP', 1),
(16, 15, 'both', 'Nishatpura', 'Bhopal', '462001', 'Madhya Pradesh', 'MP', 1),
(17, 16, 'both', 'Nishatpura', 'Bhopal', '462001', 'Madhya Pradesh', 'MP', 1),
(18, 17, 'both', 'Piplani', 'Bhopal', '462001', 'Madhya Pradesh', 'MP', 1),
(20, 19, 'both', 'Indrapuri', 'Bhopal', '462001', 'Madhya Pradesh', 'MP', 1),
(21, 20, 'both', 'Shyamla Hills', 'Bhopal', '462001', 'Madhya Pradesh', 'MP', 1);

-- --------------------------------------------------------

--
-- Table structure for table `party_contacts`
--

CREATE TABLE `party_contacts` (
  `id` bigint(20) NOT NULL,
  `party_id` bigint(20) DEFAULT NULL,
  `contact_name` varchar(255) NOT NULL,
  `phone` varchar(255) DEFAULT NULL,
  `designation` varchar(100) DEFAULT NULL,
  `is_primary` tinyint(1) DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

--
-- Dumping data for table `party_contacts`
--

INSERT INTO `party_contacts` (`id`, `party_id`, `contact_name`, `phone`, `designation`, `is_primary`) VALUES
(10, 13, 'test person', '2020202020', NULL, 1),
(11, 14, 'Party', '3030303030', '', 1),
(12, 15, 'Atharv', '', '', 1),
(13, 16, 'Anant', '5050505050', '', 1),
(14, 17, 'Kailash', '7525265354', 'Proprietor', 1),
(16, 19, 'Anant', '2020202020', 'Proprietor', 1),
(17, 20, 'Anant', '7894564552', 'Proprietor', 1);

-- --------------------------------------------------------

--
-- Table structure for table `payments`
--

CREATE TABLE `payments` (
  `id` bigint(20) NOT NULL,
  `payment_type` enum('receipt','payment') NOT NULL,
  `party_id` bigint(20) NOT NULL,
  `payment_date` date NOT NULL,
  `payment_mode` enum('cash','bank','cheque','online','card') NOT NULL,
  `amount` decimal(15,2) NOT NULL,
  `reference_no` varchar(100) DEFAULT NULL,
  `bank_name` varchar(255) DEFAULT NULL,
  `remarks` text DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

--
-- Dumping data for table `payments`
--

INSERT INTO `payments` (`id`, `payment_type`, `party_id`, `payment_date`, `payment_mode`, `amount`, `reference_no`, `bank_name`, `remarks`, `created_at`) VALUES
(3, 'receipt', 15, '2026-02-17', 'cash', 400.40, '', '', '', '2026-02-17 14:23:52'),
(4, 'receipt', 15, '2026-02-17', 'cash', 230.20, '', '', '', '2026-02-17 14:26:10'),
(5, 'receipt', 16, '2026-02-17', 'cash', 1400.40, '', '', '', '2026-02-17 14:37:39'),
(6, 'receipt', 16, '2026-02-17', 'cash', 71.00, '', '', '', '2026-02-17 14:45:06'),
(7, 'receipt', 13, '2026-02-18', 'cash', 800.80, '', '', '', '2026-02-18 07:10:54'),
(8, 'payment', 17, '2026-02-18', 'cash', 100.00, '', '', '', '2026-02-18 12:15:06');

-- --------------------------------------------------------

--
-- Table structure for table `payment_allocations`
--

CREATE TABLE `payment_allocations` (
  `id` bigint(20) NOT NULL,
  `payment_id` bigint(20) NOT NULL,
  `document_type` enum('sales_invoice','purchase_bill','credit_note','debit_note') NOT NULL,
  `document_id` bigint(20) NOT NULL,
  `allocated_amount` decimal(15,2) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

--
-- Dumping data for table `payment_allocations`
--

INSERT INTO `payment_allocations` (`id`, `payment_id`, `document_type`, `document_id`, `allocated_amount`) VALUES
(1, 3, 'sales_invoice', 8, 400.40),
(2, 4, 'sales_invoice', 8, 20.00),
(3, 4, 'sales_invoice', 9, 210.20),
(4, 5, 'sales_invoice', 10, 1400.40),
(5, 6, 'sales_invoice', 10, 71.00),
(6, 7, 'sales_invoice', 6, 630.60),
(7, 7, 'sales_invoice', 7, 170.20),
(8, 8, 'purchase_bill', 1, 100.00);

-- --------------------------------------------------------

--
-- Table structure for table `products`
--

CREATE TABLE `products` (
  `id` bigint(20) NOT NULL,
  `product_code` varchar(50) DEFAULT NULL,
  `product_name` varchar(255) NOT NULL,
  `product_type` varchar(100) DEFAULT NULL,
  `hsn_code` varchar(20) DEFAULT NULL,
  `unit_of_measure` varchar(50) DEFAULT NULL,
  `selling_price` decimal(15,2) DEFAULT 0.00,
  `purchase_price` decimal(15,2) DEFAULT 0.00,
  `gst_rate` decimal(5,2) DEFAULT 0.00,
  `cess_percent` decimal(5,2) DEFAULT 0.00,
  `status` tinyint(1) DEFAULT 1,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

--
-- Dumping data for table `products`
--

INSERT INTO `products` (`id`, `product_code`, `product_name`, `product_type`, `hsn_code`, `unit_of_measure`, `selling_price`, `purchase_price`, `gst_rate`, `cess_percent`, `status`, `created_at`, `updated_at`) VALUES
(1, '7471', 'test name', 'Electrical', '84008600', 'pcs', 200.00, 150.00, 5.00, 0.10, 1, '2026-02-14 07:35:03', '2026-02-14 07:35:03'),
(2, '1', 'test name', 'Salesforce', '84008600', 'pcs', 400.00, 200.00, 10.00, 3.00, 1, '2026-02-14 08:34:40', '2026-02-14 08:34:40'),
(3, '', 'test', '', '', 'pcs', 6000.00, 3630.00, 5.00, 3.00, 1, '2026-02-14 10:28:36', '2026-02-14 10:43:18'),
(5, '2', 'test', '', '', 'pcs', 0.00, 6.00, 0.00, 0.00, 1, '2026-02-14 10:45:59', '2026-02-14 10:45:59');

-- --------------------------------------------------------

--
-- Table structure for table `proforma_invoices`
--

CREATE TABLE `proforma_invoices` (
  `id` bigint(20) NOT NULL,
  `proforma_no` varchar(50) NOT NULL,
  `proforma_date` date NOT NULL,
  `party_id` bigint(20) NOT NULL,
  `billing_address_id` int(11) DEFAULT NULL,
  `shipping_address_id` int(11) DEFAULT NULL,
  `shipping_address_custom` text DEFAULT NULL,
  `po_number` varchar(255) DEFAULT NULL,
  `po_date` date DEFAULT NULL,
  `destination_port` varchar(300) DEFAULT NULL,
  `loading_port` varchar(300) DEFAULT NULL,
  `payment_terms_ex` varchar(300) DEFAULT NULL,
  `incoterms` varchar(300) DEFAULT NULL,
  `custom_point` varchar(300) DEFAULT NULL,
  `pkgs_no` varchar(300) DEFAULT NULL,
  `origin` varchar(300) DEFAULT NULL,
  `taxable_amount` decimal(15,2) DEFAULT 0.00,
  `total_tax` decimal(15,2) DEFAULT 0.00,
  `freight_charge` decimal(15,2) DEFAULT 0.00,
  `packing_charge` decimal(15,2) DEFAULT 0.00,
  `discount_amount` decimal(15,2) DEFAULT 0.00,
  `round_off` decimal(10,2) DEFAULT 0.00,
  `net_amount` decimal(15,2) DEFAULT 0.00,
  `remarks` text DEFAULT NULL,
  `status` enum('draft','sent','accepted','converted') DEFAULT 'draft',
  `converted_to_invoice_id` bigint(20) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

--
-- Dumping data for table `proforma_invoices`
--

INSERT INTO `proforma_invoices` (`id`, `proforma_no`, `proforma_date`, `party_id`, `billing_address_id`, `shipping_address_id`, `shipping_address_custom`, `po_number`, `po_date`, `destination_port`, `loading_port`, `payment_terms_ex`, `incoterms`, `custom_point`, `pkgs_no`, `origin`, `taxable_amount`, `total_tax`, `freight_charge`, `packing_charge`, `discount_amount`, `round_off`, `net_amount`, `remarks`, `status`, `converted_to_invoice_id`, `created_at`, `updated_at`) VALUES
(5, 'PF2026020001', '2026-02-17', 13, 14, 14, NULL, '', NULL, '', '', '', '', '', '', '', 420.00, 0.00, 0.00, 0.00, 0.00, 0.00, 420.00, '', 'draft', NULL, '2026-02-17 12:02:35', '2026-02-17 12:02:35'),
(6, 'PF2026020002', '2026-02-17', 14, 15, 15, NULL, '', NULL, '', '', '', '', '', '', '', 840.00, 0.00, 0.00, 0.00, 0.00, 0.00, 840.00, '', 'sent', NULL, '2026-02-17 14:01:32', '2026-02-17 14:01:32'),
(7, 'PF2026020003', '2026-02-17', 15, 16, 16, NULL, '', NULL, '', '', '', '', '', '', '', 420.00, 0.00, 0.00, 0.00, 0.00, 0.00, 420.00, '', 'draft', NULL, '2026-02-17 14:15:48', '2026-02-17 14:15:48');

-- --------------------------------------------------------

--
-- Table structure for table `purchase_bills`
--

CREATE TABLE `purchase_bills` (
  `id` bigint(20) NOT NULL,
  `bill_no` varchar(50) NOT NULL,
  `bill_date` date NOT NULL,
  `party_id` bigint(20) NOT NULL,
  `billing_address_id` int(11) DEFAULT NULL,
  `shipping_address_id` int(11) DEFAULT NULL,
  `shipping_address_custom` text DEFAULT NULL,
  `po_id` bigint(20) DEFAULT NULL,
  `challan_id` bigint(20) DEFAULT NULL,
  `supplier_invoice_no` varchar(255) DEFAULT NULL,
  `supplier_invoice_date` date DEFAULT NULL,
  `place_of_supply` varchar(255) DEFAULT NULL,
  `state_code` varchar(10) DEFAULT NULL,
  `taxable_amount` decimal(15,2) DEFAULT 0.00,
  `total_tax` decimal(15,2) DEFAULT 0.00,
  `freight_charge` decimal(15,2) DEFAULT 0.00,
  `packing_charge` decimal(15,2) DEFAULT 0.00,
  `other_charges` decimal(15,2) DEFAULT 0.00,
  `discount_amount` decimal(15,2) DEFAULT 0.00,
  `round_off` decimal(10,2) DEFAULT 0.00,
  `net_amount` decimal(15,2) DEFAULT 0.00,
  `paid_amount` decimal(15,2) DEFAULT 0.00,
  `balance_amount` decimal(15,2) DEFAULT 0.00,
  `payment_status` enum('paid','partial','unpaid') DEFAULT 'unpaid',
  `transport_name` varchar(255) DEFAULT NULL,
  `transport_mode` varchar(50) DEFAULT NULL,
  `vehicle_no` varchar(50) DEFAULT NULL,
  `tracking_no` varchar(255) DEFAULT NULL,
  `is_reverse_charge` tinyint(1) DEFAULT 0,
  `eway_bill_no` varchar(50) DEFAULT NULL,
  `remarks` text DEFAULT NULL,
  `status` enum('draft','posted','cancelled') DEFAULT 'draft',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

--
-- Dumping data for table `purchase_bills`
--

INSERT INTO `purchase_bills` (`id`, `bill_no`, `bill_date`, `party_id`, `billing_address_id`, `shipping_address_id`, `shipping_address_custom`, `po_id`, `challan_id`, `supplier_invoice_no`, `supplier_invoice_date`, `place_of_supply`, `state_code`, `taxable_amount`, `total_tax`, `freight_charge`, `packing_charge`, `other_charges`, `discount_amount`, `round_off`, `net_amount`, `paid_amount`, `balance_amount`, `payment_status`, `transport_name`, `transport_mode`, `vehicle_no`, `tracking_no`, `is_reverse_charge`, `eway_bill_no`, `remarks`, `status`, `created_at`, `updated_at`) VALUES
(1, 'PBILL2026020001', '2026-02-18', 17, 18, 18, NULL, NULL, 1, '', '2026-02-18', 'Bhopal', '', 450.00, 0.45, 100.00, 0.00, 0.00, 0.00, 0.00, 550.45, 100.00, 450.45, 'partial', '', 'Road', '', '', 0, '', '', 'posted', '2026-02-18 11:33:53', '2026-02-18 12:15:06');

-- --------------------------------------------------------

--
-- Table structure for table `purchase_challans`
--

CREATE TABLE `purchase_challans` (
  `id` bigint(20) NOT NULL,
  `challan_no` varchar(50) NOT NULL,
  `challan_date` date NOT NULL,
  `party_id` bigint(20) NOT NULL,
  `billing_address_id` int(11) DEFAULT NULL,
  `shipping_address_id` int(11) DEFAULT NULL,
  `shipping_address_custom` text DEFAULT NULL,
  `po_id` bigint(20) DEFAULT NULL,
  `transport_name` varchar(255) DEFAULT NULL,
  `transport_mode` varchar(50) DEFAULT NULL,
  `vehicle_no` varchar(50) DEFAULT NULL,
  `tracking_no` varchar(255) DEFAULT NULL,
  `total_amount` decimal(15,2) DEFAULT 0.00,
  `remarks` text DEFAULT NULL,
  `status` enum('draft','received','billed') DEFAULT 'draft',
  `converted_to_bill_id` bigint(20) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

--
-- Dumping data for table `purchase_challans`
--

INSERT INTO `purchase_challans` (`id`, `challan_no`, `challan_date`, `party_id`, `billing_address_id`, `shipping_address_id`, `shipping_address_custom`, `po_id`, `transport_name`, `transport_mode`, `vehicle_no`, `tracking_no`, `total_amount`, `remarks`, `status`, `converted_to_bill_id`, `created_at`, `updated_at`) VALUES
(1, 'PC2026020001', '2026-02-18', 19, 20, NULL, 'hello', 2, '', '', '', '', 0.00, '', 'billed', 1, '2026-02-18 10:12:10', '2026-02-18 11:33:53');

-- --------------------------------------------------------

--
-- Table structure for table `purchase_orders`
--

CREATE TABLE `purchase_orders` (
  `id` bigint(20) NOT NULL,
  `po_no` varchar(50) NOT NULL,
  `po_date` date NOT NULL,
  `party_id` bigint(20) NOT NULL,
  `billing_address_id` int(11) DEFAULT NULL,
  `shipping_address_id` int(11) DEFAULT NULL,
  `shipping_address_custom` text DEFAULT NULL,
  `expected_delivery_date` date DEFAULT NULL,
  `taxable_amount` decimal(15,2) DEFAULT 0.00,
  `total_tax` decimal(15,2) DEFAULT 0.00,
  `freight_charge` decimal(15,2) DEFAULT 0.00,
  `packing_charge` decimal(15,2) DEFAULT 0.00,
  `discount_amount` decimal(15,2) DEFAULT 0.00,
  `net_amount` decimal(15,2) DEFAULT 0.00,
  `terms_conditions` text DEFAULT NULL,
  `remarks` text DEFAULT NULL,
  `status` enum('draft','sent','confirmed','received','cancelled') DEFAULT 'draft',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

--
-- Dumping data for table `purchase_orders`
--

INSERT INTO `purchase_orders` (`id`, `po_no`, `po_date`, `party_id`, `billing_address_id`, `shipping_address_id`, `shipping_address_custom`, `expected_delivery_date`, `taxable_amount`, `total_tax`, `freight_charge`, `packing_charge`, `discount_amount`, `net_amount`, `terms_conditions`, `remarks`, `status`, `created_at`, `updated_at`) VALUES
(2, 'PO2026020001', '2026-02-18', 17, 18, NULL, 'Panchvati, Lalghati, Bairagarh', NULL, 660.00, 0.00, 200.00, 0.00, 0.00, 860.00, '', '', '', '2026-02-18 09:12:47', '2026-02-18 11:33:53');

-- --------------------------------------------------------

--
-- Table structure for table `purchase_returns`
--

CREATE TABLE `purchase_returns` (
  `id` bigint(20) NOT NULL,
  `return_no` varchar(50) NOT NULL,
  `return_date` date NOT NULL,
  `debit_note_id` bigint(20) NOT NULL,
  `original_bill_id` bigint(20) NOT NULL,
  `party_id` bigint(20) NOT NULL,
  `total_amount` decimal(15,2) DEFAULT 0.00,
  `tax_amount` decimal(15,2) DEFAULT 0.00,
  `reason` text DEFAULT NULL,
  `status` enum('initiated','approved','completed') DEFAULT 'initiated',
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

-- --------------------------------------------------------

--
-- Table structure for table `quotations`
--

CREATE TABLE `quotations` (
  `id` bigint(20) NOT NULL,
  `quotation_no` varchar(50) NOT NULL,
  `quotation_date` date NOT NULL,
  `party_id` bigint(20) NOT NULL,
  `billing_address_id` int(11) DEFAULT NULL,
  `shipping_address_id` int(11) DEFAULT NULL,
  `shipping_address_custom` text DEFAULT NULL,
  `valid_until` date DEFAULT NULL,
  `taxable_amount` decimal(15,2) DEFAULT 0.00,
  `total_tax` decimal(15,2) DEFAULT 0.00,
  `freight_charge` decimal(15,2) DEFAULT 0.00,
  `packing_charge` decimal(15,2) DEFAULT 0.00,
  `discount_amount` decimal(15,2) DEFAULT 0.00,
  `round_off` decimal(10,2) DEFAULT 0.00,
  `net_amount` decimal(15,2) DEFAULT 0.00,
  `terms_conditions` text DEFAULT NULL,
  `remarks` text DEFAULT NULL,
  `status` enum('draft','sent','accepted','rejected','converted') DEFAULT 'draft',
  `converted_to_invoice_id` bigint(20) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

--
-- Dumping data for table `quotations`
--

INSERT INTO `quotations` (`id`, `quotation_no`, `quotation_date`, `party_id`, `billing_address_id`, `shipping_address_id`, `shipping_address_custom`, `valid_until`, `taxable_amount`, `total_tax`, `freight_charge`, `packing_charge`, `discount_amount`, `round_off`, `net_amount`, `terms_conditions`, `remarks`, `status`, `converted_to_invoice_id`, `created_at`, `updated_at`) VALUES
(19, 'Q2026020001', '2026-02-17', 13, 14, 14, NULL, '2026-02-17', 420.00, 0.00, 0.00, 0.00, 0.00, 0.00, 420.00, '', '', 'sent', NULL, '2026-02-17 12:01:50', '2026-02-17 12:01:59'),
(20, 'Q2026020002', '2026-02-17', 14, 15, 15, NULL, NULL, 672.00, 0.00, 0.00, 0.00, 0.00, 0.00, 672.00, '', '', 'sent', NULL, '2026-02-17 14:00:51', '2026-02-17 14:01:04');

-- --------------------------------------------------------

--
-- Table structure for table `sales_challans`
--

CREATE TABLE `sales_challans` (
  `id` bigint(20) NOT NULL,
  `challan_no` varchar(50) NOT NULL,
  `challan_date` date NOT NULL,
  `party_id` bigint(20) NOT NULL,
  `billing_address_id` int(11) DEFAULT NULL,
  `shipping_address_id` int(11) DEFAULT NULL,
  `shipping_address_custom` text DEFAULT NULL,
  `po_number` varchar(255) DEFAULT NULL,
  `po_date` date DEFAULT NULL,
  `transport_name` varchar(255) DEFAULT NULL,
  `transport_mode` varchar(50) DEFAULT NULL,
  `vehicle_no` varchar(50) DEFAULT NULL,
  `tracking_no` varchar(255) DEFAULT NULL,
  `total_amount` decimal(15,2) DEFAULT 0.00,
  `remarks` text DEFAULT NULL,
  `status` enum('draft','dispatched','delivered','invoiced') DEFAULT 'draft',
  `converted_to_invoice_id` bigint(20) DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

--
-- Dumping data for table `sales_challans`
--

INSERT INTO `sales_challans` (`id`, `challan_no`, `challan_date`, `party_id`, `billing_address_id`, `shipping_address_id`, `shipping_address_custom`, `po_number`, `po_date`, `transport_name`, `transport_mode`, `vehicle_no`, `tracking_no`, `total_amount`, `remarks`, `status`, `converted_to_invoice_id`, `created_at`, `updated_at`) VALUES
(4, 'CH2026020001', '2026-02-17', 13, 14, 14, NULL, '', NULL, '', '', '', '', 400.00, '', 'draft', NULL, '2026-02-17 12:03:24', '2026-02-17 12:03:24'),
(5, 'CH2026020002', '2026-02-17', 14, 15, 15, NULL, '', NULL, '', 'Road', '', '', 800.00, '', 'draft', NULL, '2026-02-17 14:02:17', '2026-02-17 14:02:17'),
(6, 'CH2026020003', '2026-02-17', 15, 16, 16, NULL, '', NULL, '', 'Road', '', '', 400.00, '', 'dispatched', NULL, '2026-02-17 14:15:10', '2026-02-17 14:28:09'),
(7, 'CH2026020004', '2026-02-17', 15, 16, 16, NULL, '', NULL, '', '', '', '', 600.00, '', 'draft', NULL, '2026-02-17 14:27:53', '2026-02-17 14:27:53');

-- --------------------------------------------------------

--
-- Table structure for table `sales_invoices`
--

CREATE TABLE `sales_invoices` (
  `id` bigint(20) NOT NULL,
  `invoice_no` varchar(50) NOT NULL,
  `invoice_date` date NOT NULL,
  `party_id` bigint(20) NOT NULL,
  `billing_address_id` int(11) DEFAULT NULL,
  `shipping_address_id` int(11) DEFAULT NULL,
  `shipping_address_custom` text DEFAULT NULL,
  `quotation_id` bigint(20) DEFAULT NULL,
  `proforma_id` bigint(20) DEFAULT NULL,
  `challan_id` bigint(20) DEFAULT NULL,
  `po_number` varchar(255) DEFAULT NULL,
  `po_date` date DEFAULT NULL,
  `place_of_supply` varchar(255) DEFAULT NULL,
  `state_code` varchar(10) DEFAULT NULL,
  `taxable_amount` decimal(15,2) DEFAULT 0.00,
  `total_tax` decimal(15,2) DEFAULT 0.00,
  `freight_charge` decimal(15,2) DEFAULT 0.00,
  `packing_charge` decimal(15,2) DEFAULT 0.00,
  `discount_amount` decimal(15,2) DEFAULT 0.00,
  `round_off` decimal(10,2) DEFAULT 0.00,
  `net_amount` decimal(15,2) DEFAULT 0.00,
  `paid_amount` decimal(15,2) DEFAULT 0.00,
  `balance_amount` decimal(15,2) DEFAULT 0.00,
  `payment_status` enum('paid','partial','unpaid') DEFAULT 'unpaid',
  `transport_name` varchar(255) DEFAULT NULL,
  `transport_mode` varchar(50) DEFAULT NULL,
  `vehicle_no` varchar(50) DEFAULT NULL,
  `tracking_no` varchar(255) DEFAULT NULL,
  `is_reverse_charge` tinyint(1) DEFAULT 0,
  `eway_bill_no` varchar(50) DEFAULT NULL,
  `irn_no` varchar(100) DEFAULT NULL,
  `remarks` text DEFAULT NULL,
  `status` enum('draft','posted','cancelled') DEFAULT 'draft',
  `created_at` timestamp NULL DEFAULT current_timestamp(),
  `updated_at` timestamp NULL DEFAULT current_timestamp() ON UPDATE current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

--
-- Dumping data for table `sales_invoices`
--

INSERT INTO `sales_invoices` (`id`, `invoice_no`, `invoice_date`, `party_id`, `billing_address_id`, `shipping_address_id`, `shipping_address_custom`, `quotation_id`, `proforma_id`, `challan_id`, `po_number`, `po_date`, `place_of_supply`, `state_code`, `taxable_amount`, `total_tax`, `freight_charge`, `packing_charge`, `discount_amount`, `round_off`, `net_amount`, `paid_amount`, `balance_amount`, `payment_status`, `transport_name`, `transport_mode`, `vehicle_no`, `tracking_no`, `is_reverse_charge`, `eway_bill_no`, `irn_no`, `remarks`, `status`, `created_at`, `updated_at`) VALUES
(6, 'INV2026020001', '2026-02-17', 13, 14, 14, NULL, 19, 5, 4, '', NULL, '', '', 600.00, 30.60, 0.00, 0.00, 0.00, 0.00, 630.60, 630.60, 0.00, 'paid', '', '', '', '', 0, '', '', '', 'draft', '2026-02-17 13:31:14', '2026-02-18 07:10:54'),
(7, 'INV2026020002', '2026-02-17', 13, 14, 14, NULL, NULL, NULL, NULL, '', NULL, '', '', 200.00, 10.20, 0.00, 0.00, 0.00, 0.00, 210.20, 170.20, 40.00, 'paid', '', '', '', '', 0, '', '', '', 'draft', '2026-02-17 13:33:12', '2026-02-18 07:10:54'),
(8, 'INV2026020003', '2026-02-17', 15, 16, 16, NULL, NULL, NULL, NULL, '', NULL, '', '', 400.00, 20.40, 0.00, 0.00, 0.00, 0.00, 420.40, 420.40, 0.00, 'paid', '', '', '', '', 0, '', '', '', 'posted', '2026-02-17 14:17:09', '2026-02-17 14:26:10'),
(9, 'INV2026020004', '2026-02-17', 15, 16, 16, NULL, NULL, NULL, NULL, '', NULL, '', '', 200.00, 10.20, 0.00, 0.00, 0.00, 0.00, 210.20, 210.20, 0.00, 'paid', '', '', '', '', 0, '', '', '', 'draft', '2026-02-17 14:25:05', '2026-02-17 14:26:10'),
(10, 'INV2026020005', '2026-02-17', 16, 17, 17, NULL, NULL, NULL, NULL, '', NULL, '', '', 1400.00, 71.40, 0.00, 0.00, 0.00, 0.00, 1471.40, 1471.40, 0.00, 'paid', '', 'Road', '', '', 0, '', '', '', 'draft', '2026-02-17 14:36:23', '2026-02-17 14:45:06');

-- --------------------------------------------------------

--
-- Table structure for table `sales_returns`
--

CREATE TABLE `sales_returns` (
  `id` bigint(20) NOT NULL,
  `return_no` varchar(50) NOT NULL,
  `return_date` date NOT NULL,
  `credit_note_id` bigint(20) NOT NULL,
  `original_invoice_id` bigint(20) NOT NULL,
  `party_id` bigint(20) NOT NULL,
  `total_amount` decimal(15,2) DEFAULT 0.00,
  `tax_amount` decimal(15,2) DEFAULT 0.00,
  `reason` text DEFAULT NULL,
  `status` enum('initiated','approved','completed') DEFAULT 'initiated',
  `created_at` timestamp NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=latin1 COLLATE=latin1_swedish_ci;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `backups`
--
ALTER TABLE `backups`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `company`
--
ALTER TABLE `company`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `credit_notes`
--
ALTER TABLE `credit_notes`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `credit_note_no` (`credit_note_no`),
  ADD KEY `party_id` (`party_id`),
  ADD KEY `billing_address_id` (`billing_address_id`),
  ADD KEY `original_invoice_id` (`original_invoice_id`);

--
-- Indexes for table `debit_notes`
--
ALTER TABLE `debit_notes`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `debit_note_no` (`debit_note_no`),
  ADD KEY `party_id` (`party_id`),
  ADD KEY `billing_address_id` (`billing_address_id`),
  ADD KEY `original_bill_id` (`original_bill_id`);

--
-- Indexes for table `document_items`
--
ALTER TABLE `document_items`
  ADD PRIMARY KEY (`id`),
  ADD KEY `product_id` (`product_id`),
  ADD KEY `doc_type` (`doc_type`,`doc_id`),
  ADD KEY `original_item_id` (`original_item_id`),
  ADD KEY `hsn_code` (`hsn_code`);

--
-- Indexes for table `gst_returns`
--
ALTER TABLE `gst_returns`
  ADD PRIMARY KEY (`id`);

--
-- Indexes for table `gst_return_details`
--
ALTER TABLE `gst_return_details`
  ADD PRIMARY KEY (`id`),
  ADD KEY `gst_return_id` (`gst_return_id`),
  ADD KEY `document_type` (`document_type`,`document_id`);

--
-- Indexes for table `parties`
--
ALTER TABLE `parties`
  ADD PRIMARY KEY (`id`),
  ADD KEY `party_type` (`party_type`),
  ADD KEY `gstin` (`gstin`);

--
-- Indexes for table `party_addresses`
--
ALTER TABLE `party_addresses`
  ADD PRIMARY KEY (`id`),
  ADD KEY `party_id` (`party_id`);

--
-- Indexes for table `party_contacts`
--
ALTER TABLE `party_contacts`
  ADD PRIMARY KEY (`id`),
  ADD KEY `party_id` (`party_id`);

--
-- Indexes for table `payments`
--
ALTER TABLE `payments`
  ADD PRIMARY KEY (`id`),
  ADD KEY `party_id` (`party_id`);

--
-- Indexes for table `payment_allocations`
--
ALTER TABLE `payment_allocations`
  ADD PRIMARY KEY (`id`),
  ADD KEY `payment_id` (`payment_id`),
  ADD KEY `document_type` (`document_type`,`document_id`);

--
-- Indexes for table `products`
--
ALTER TABLE `products`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `product_code` (`product_code`),
  ADD KEY `hsn_code` (`hsn_code`);

--
-- Indexes for table `proforma_invoices`
--
ALTER TABLE `proforma_invoices`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `proforma_no` (`proforma_no`),
  ADD KEY `party_id` (`party_id`),
  ADD KEY `billing_address_id` (`billing_address_id`),
  ADD KEY `shipping_address_id` (`shipping_address_id`);

--
-- Indexes for table `purchase_bills`
--
ALTER TABLE `purchase_bills`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `bill_no` (`bill_no`),
  ADD KEY `party_id` (`party_id`),
  ADD KEY `billing_address_id` (`billing_address_id`),
  ADD KEY `shipping_address_id` (`shipping_address_id`),
  ADD KEY `po_id` (`po_id`),
  ADD KEY `challan_id` (`challan_id`);

--
-- Indexes for table `purchase_challans`
--
ALTER TABLE `purchase_challans`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `challan_no` (`challan_no`),
  ADD KEY `party_id` (`party_id`),
  ADD KEY `billing_address_id` (`billing_address_id`),
  ADD KEY `shipping_address_id` (`shipping_address_id`),
  ADD KEY `po_id` (`po_id`);

--
-- Indexes for table `purchase_orders`
--
ALTER TABLE `purchase_orders`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `po_no` (`po_no`),
  ADD KEY `party_id` (`party_id`),
  ADD KEY `billing_address_id` (`billing_address_id`),
  ADD KEY `shipping_address_id` (`shipping_address_id`);

--
-- Indexes for table `purchase_returns`
--
ALTER TABLE `purchase_returns`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `return_no` (`return_no`),
  ADD KEY `debit_note_id` (`debit_note_id`),
  ADD KEY `original_bill_id` (`original_bill_id`),
  ADD KEY `party_id` (`party_id`);

--
-- Indexes for table `quotations`
--
ALTER TABLE `quotations`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `quotation_no` (`quotation_no`),
  ADD KEY `party_id` (`party_id`),
  ADD KEY `billing_address_id` (`billing_address_id`),
  ADD KEY `shipping_address_id` (`shipping_address_id`);

--
-- Indexes for table `sales_challans`
--
ALTER TABLE `sales_challans`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `challan_no` (`challan_no`),
  ADD KEY `party_id` (`party_id`),
  ADD KEY `billing_address_id` (`billing_address_id`),
  ADD KEY `shipping_address_id` (`shipping_address_id`);

--
-- Indexes for table `sales_invoices`
--
ALTER TABLE `sales_invoices`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `invoice_no` (`invoice_no`),
  ADD KEY `party_id` (`party_id`),
  ADD KEY `billing_address_id` (`billing_address_id`),
  ADD KEY `shipping_address_id` (`shipping_address_id`),
  ADD KEY `quotation_id` (`quotation_id`),
  ADD KEY `proforma_id` (`proforma_id`),
  ADD KEY `challan_id` (`challan_id`);

--
-- Indexes for table `sales_returns`
--
ALTER TABLE `sales_returns`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `return_no` (`return_no`),
  ADD KEY `credit_note_id` (`credit_note_id`),
  ADD KEY `original_invoice_id` (`original_invoice_id`),
  ADD KEY `party_id` (`party_id`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `backups`
--
ALTER TABLE `backups`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `company`
--
ALTER TABLE `company`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `credit_notes`
--
ALTER TABLE `credit_notes`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4;

--
-- AUTO_INCREMENT for table `debit_notes`
--
ALTER TABLE `debit_notes`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `document_items`
--
ALTER TABLE `document_items`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=81;

--
-- AUTO_INCREMENT for table `gst_returns`
--
ALTER TABLE `gst_returns`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `gst_return_details`
--
ALTER TABLE `gst_return_details`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `parties`
--
ALTER TABLE `parties`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=21;

--
-- AUTO_INCREMENT for table `party_addresses`
--
ALTER TABLE `party_addresses`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=22;

--
-- AUTO_INCREMENT for table `party_contacts`
--
ALTER TABLE `party_contacts`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=18;

--
-- AUTO_INCREMENT for table `payments`
--
ALTER TABLE `payments`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;

--
-- AUTO_INCREMENT for table `payment_allocations`
--
ALTER TABLE `payment_allocations`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=9;

--
-- AUTO_INCREMENT for table `products`
--
ALTER TABLE `products`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;

--
-- AUTO_INCREMENT for table `proforma_invoices`
--
ALTER TABLE `proforma_invoices`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;

--
-- AUTO_INCREMENT for table `purchase_bills`
--
ALTER TABLE `purchase_bills`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;

--
-- AUTO_INCREMENT for table `purchase_challans`
--
ALTER TABLE `purchase_challans`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT for table `purchase_orders`
--
ALTER TABLE `purchase_orders`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=3;

--
-- AUTO_INCREMENT for table `purchase_returns`
--
ALTER TABLE `purchase_returns`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

--
-- AUTO_INCREMENT for table `quotations`
--
ALTER TABLE `quotations`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=21;

--
-- AUTO_INCREMENT for table `sales_challans`
--
ALTER TABLE `sales_challans`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=8;

--
-- AUTO_INCREMENT for table `sales_invoices`
--
ALTER TABLE `sales_invoices`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=11;

--
-- AUTO_INCREMENT for table `sales_returns`
--
ALTER TABLE `sales_returns`
  MODIFY `id` bigint(20) NOT NULL AUTO_INCREMENT;

--
-- Constraints for dumped tables
--

--
-- Constraints for table `credit_notes`
--
ALTER TABLE `credit_notes`
  ADD CONSTRAINT `credit_notes_ibfk_1` FOREIGN KEY (`party_id`) REFERENCES `parties` (`id`),
  ADD CONSTRAINT `credit_notes_ibfk_2` FOREIGN KEY (`billing_address_id`) REFERENCES `party_addresses` (`id`),
  ADD CONSTRAINT `credit_notes_ibfk_3` FOREIGN KEY (`original_invoice_id`) REFERENCES `sales_invoices` (`id`);

--
-- Constraints for table `debit_notes`
--
ALTER TABLE `debit_notes`
  ADD CONSTRAINT `debit_notes_ibfk_1` FOREIGN KEY (`party_id`) REFERENCES `parties` (`id`),
  ADD CONSTRAINT `debit_notes_ibfk_2` FOREIGN KEY (`billing_address_id`) REFERENCES `party_addresses` (`id`),
  ADD CONSTRAINT `debit_notes_ibfk_3` FOREIGN KEY (`original_bill_id`) REFERENCES `purchase_bills` (`id`);

--
-- Constraints for table `document_items`
--
ALTER TABLE `document_items`
  ADD CONSTRAINT `document_items_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `products` (`id`);

--
-- Constraints for table `gst_return_details`
--
ALTER TABLE `gst_return_details`
  ADD CONSTRAINT `gst_return_details_ibfk_1` FOREIGN KEY (`gst_return_id`) REFERENCES `gst_returns` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `party_addresses`
--
ALTER TABLE `party_addresses`
  ADD CONSTRAINT `party_addresses_ibfk_1` FOREIGN KEY (`party_id`) REFERENCES `parties` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `party_contacts`
--
ALTER TABLE `party_contacts`
  ADD CONSTRAINT `party_contacts_ibfk_1` FOREIGN KEY (`party_id`) REFERENCES `parties` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `payments`
--
ALTER TABLE `payments`
  ADD CONSTRAINT `payments_ibfk_1` FOREIGN KEY (`party_id`) REFERENCES `parties` (`id`);

--
-- Constraints for table `payment_allocations`
--
ALTER TABLE `payment_allocations`
  ADD CONSTRAINT `payment_allocations_ibfk_1` FOREIGN KEY (`payment_id`) REFERENCES `payments` (`id`) ON DELETE CASCADE;

--
-- Constraints for table `proforma_invoices`
--
ALTER TABLE `proforma_invoices`
  ADD CONSTRAINT `proforma_invoices_ibfk_1` FOREIGN KEY (`party_id`) REFERENCES `parties` (`id`),
  ADD CONSTRAINT `proforma_invoices_ibfk_2` FOREIGN KEY (`billing_address_id`) REFERENCES `party_addresses` (`id`),
  ADD CONSTRAINT `proforma_invoices_ibfk_3` FOREIGN KEY (`shipping_address_id`) REFERENCES `party_addresses` (`id`);

--
-- Constraints for table `purchase_bills`
--
ALTER TABLE `purchase_bills`
  ADD CONSTRAINT `purchase_bills_ibfk_1` FOREIGN KEY (`party_id`) REFERENCES `parties` (`id`),
  ADD CONSTRAINT `purchase_bills_ibfk_2` FOREIGN KEY (`billing_address_id`) REFERENCES `party_addresses` (`id`),
  ADD CONSTRAINT `purchase_bills_ibfk_3` FOREIGN KEY (`shipping_address_id`) REFERENCES `party_addresses` (`id`),
  ADD CONSTRAINT `purchase_bills_ibfk_4` FOREIGN KEY (`po_id`) REFERENCES `purchase_orders` (`id`),
  ADD CONSTRAINT `purchase_bills_ibfk_5` FOREIGN KEY (`challan_id`) REFERENCES `purchase_challans` (`id`);

--
-- Constraints for table `purchase_challans`
--
ALTER TABLE `purchase_challans`
  ADD CONSTRAINT `purchase_challans_ibfk_1` FOREIGN KEY (`party_id`) REFERENCES `parties` (`id`),
  ADD CONSTRAINT `purchase_challans_ibfk_2` FOREIGN KEY (`billing_address_id`) REFERENCES `party_addresses` (`id`),
  ADD CONSTRAINT `purchase_challans_ibfk_3` FOREIGN KEY (`shipping_address_id`) REFERENCES `party_addresses` (`id`),
  ADD CONSTRAINT `purchase_challans_ibfk_4` FOREIGN KEY (`po_id`) REFERENCES `purchase_orders` (`id`);

--
-- Constraints for table `purchase_orders`
--
ALTER TABLE `purchase_orders`
  ADD CONSTRAINT `purchase_orders_ibfk_1` FOREIGN KEY (`party_id`) REFERENCES `parties` (`id`),
  ADD CONSTRAINT `purchase_orders_ibfk_2` FOREIGN KEY (`billing_address_id`) REFERENCES `party_addresses` (`id`),
  ADD CONSTRAINT `purchase_orders_ibfk_3` FOREIGN KEY (`shipping_address_id`) REFERENCES `party_addresses` (`id`);

--
-- Constraints for table `purchase_returns`
--
ALTER TABLE `purchase_returns`
  ADD CONSTRAINT `purchase_returns_ibfk_1` FOREIGN KEY (`debit_note_id`) REFERENCES `debit_notes` (`id`),
  ADD CONSTRAINT `purchase_returns_ibfk_2` FOREIGN KEY (`original_bill_id`) REFERENCES `purchase_bills` (`id`),
  ADD CONSTRAINT `purchase_returns_ibfk_3` FOREIGN KEY (`party_id`) REFERENCES `parties` (`id`);

--
-- Constraints for table `quotations`
--
ALTER TABLE `quotations`
  ADD CONSTRAINT `quotations_ibfk_1` FOREIGN KEY (`party_id`) REFERENCES `parties` (`id`),
  ADD CONSTRAINT `quotations_ibfk_2` FOREIGN KEY (`billing_address_id`) REFERENCES `party_addresses` (`id`),
  ADD CONSTRAINT `quotations_ibfk_3` FOREIGN KEY (`shipping_address_id`) REFERENCES `party_addresses` (`id`);

--
-- Constraints for table `sales_challans`
--
ALTER TABLE `sales_challans`
  ADD CONSTRAINT `sales_challans_ibfk_1` FOREIGN KEY (`party_id`) REFERENCES `parties` (`id`),
  ADD CONSTRAINT `sales_challans_ibfk_2` FOREIGN KEY (`billing_address_id`) REFERENCES `party_addresses` (`id`),
  ADD CONSTRAINT `sales_challans_ibfk_3` FOREIGN KEY (`shipping_address_id`) REFERENCES `party_addresses` (`id`);

--
-- Constraints for table `sales_invoices`
--
ALTER TABLE `sales_invoices`
  ADD CONSTRAINT `sales_invoices_ibfk_1` FOREIGN KEY (`party_id`) REFERENCES `parties` (`id`),
  ADD CONSTRAINT `sales_invoices_ibfk_2` FOREIGN KEY (`billing_address_id`) REFERENCES `party_addresses` (`id`),
  ADD CONSTRAINT `sales_invoices_ibfk_3` FOREIGN KEY (`shipping_address_id`) REFERENCES `party_addresses` (`id`),
  ADD CONSTRAINT `sales_invoices_ibfk_4` FOREIGN KEY (`quotation_id`) REFERENCES `quotations` (`id`),
  ADD CONSTRAINT `sales_invoices_ibfk_5` FOREIGN KEY (`proforma_id`) REFERENCES `proforma_invoices` (`id`),
  ADD CONSTRAINT `sales_invoices_ibfk_6` FOREIGN KEY (`challan_id`) REFERENCES `sales_challans` (`id`);

--
-- Constraints for table `sales_returns`
--
ALTER TABLE `sales_returns`
  ADD CONSTRAINT `sales_returns_ibfk_1` FOREIGN KEY (`credit_note_id`) REFERENCES `credit_notes` (`id`),
  ADD CONSTRAINT `sales_returns_ibfk_2` FOREIGN KEY (`original_invoice_id`) REFERENCES `sales_invoices` (`id`),
  ADD CONSTRAINT `sales_returns_ibfk_3` FOREIGN KEY (`party_id`) REFERENCES `parties` (`id`);
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
