-- https://www.phpmyadmin.net/
--

START TRANSACTION;



--
-- Database: `paymentpack`
--

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

--
-- Table structure for table `receipts`
--

CREATE TABLE `receipts` (
  `id` int(11) NOT NULL,
  `DemanderCode_str` varchar(50) DEFAULT NULL,
  `Demander` varchar(255) DEFAULT NULL,
  `OrderNo_str` varchar(100) DEFAULT NULL,
  `InvoiceNo_str` varchar(100) NOT NULL,
  `ReceiptNo_str` varchar(100) DEFAULT NULL,
  `OrderActivatedDate` date DEFAULT NULL,
  `ReceivedDate` date DEFAULT NULL,
  `NSN_str` varchar(50) DEFAULT NULL,
  `ICN_str` varchar(50) DEFAULT NULL,
  `packDescription_Str` text DEFAULT NULL,
  `QtyOrdered_int` int(11) DEFAULT 0,
  `QtyReceived_int` int(11) DEFAULT 0,
  `BatchNumber_str` varchar(50) DEFAULT NULL,
  `Expiry_dat` date DEFAULT NULL,
  `PackCost_mon` decimal(10,2) DEFAULT 0.00,
  `TotalCost_mon` decimal(10,2) DEFAULT 0.00,
  `Supplier_str` varchar(255) DEFAULT NULL,
  `OrderType` varchar(50) DEFAULT NULL,
  `Complete` varchar(10) DEFAULT NULL,
  `facility` varchar(255) DEFAULT NULL,
  `district` varchar(255) DEFAULT NULL,
  `uploaded_by` varchar(255) DEFAULT NULL,
  `del_point` varchar(7) DEFAULT NULL,
  `upload_month` varchar(7) DEFAULT NULL,
  `upload_date` timestamp NOT NULL DEFAULT current_timestamp()
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--- Triggers `receipts`
--
DELIMITER $$
CREATE TRIGGER `before_insert_receipts_paymentpack` BEFORE INSERT ON `receipts` FOR EACH ROW BEGIN
    IF NEW.upload_month IS NULL THEN
        SET NEW.upload_month = DATE_FORMAT(NEW.upload_date, '%Y-%m');
    END IF;
END
$$
DELIMITER ;

--
-- Indexes for dumped tables
--

--
-- Indexes for table `receipts`
--
ALTER TABLE `receipts`
  ADD PRIMARY KEY (`id`),
  ADD KEY `idx_invoice` (`InvoiceNo_str`),
  ADD KEY `idx_facility_month` (`facility`,`upload_month`),
  ADD KEY `idx_del_point` (`del_point`);

--
-- AUTO_INCREMENT for dumped tables
--

--
-- AUTO_INCREMENT for table `receipts`
--
ALTER TABLE `receipts`
  MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=4170;
COMMIT;

