-- -------------------------------------------------------------
-- TablePlus 6.7.0(634)
--
-- https://tableplus.com/
--
-- Database: sx_db_1751480457
-- Generation Time: 2025-09-12 12:22:42.6040
-- -------------------------------------------------------------


/*!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 */;
/*!40014 SET @OLD_UNIQUE_CHECKS=@@UNIQUE_CHECKS, UNIQUE_CHECKS=0 */;
/*!40014 SET @OLD_FOREIGN_KEY_CHECKS=@@FOREIGN_KEY_CHECKS, FOREIGN_KEY_CHECKS=0 */;
/*!40101 SET @OLD_SQL_MODE=@@SQL_MODE, SQL_MODE='NO_AUTO_VALUE_ON_ZERO' */;
/*!40111 SET @OLD_SQL_NOTES=@@SQL_NOTES, SQL_NOTES=0 */;


CREATE TABLE `invoices` (
  `id` bigint(20) unsigned NOT NULL AUTO_INCREMENT,
  `refid` bigint(20) unsigned DEFAULT NULL,
  `external_id` varchar(255) DEFAULT NULL,
  `synced` tinyint(1) NOT NULL DEFAULT 0,
  `title` varchar(255) DEFAULT NULL,
  `fields` longtext CHARACTER SET utf8mb4 COLLATE utf8mb4_bin DEFAULT NULL CHECK (json_valid(`fields`)),
  `billingaddress` varchar(255) DEFAULT NULL,
  `billcity` varchar(255) DEFAULT NULL,
  `billphone` varchar(255) DEFAULT NULL,
  `billstate` varchar(255) DEFAULT NULL,
  `billzip` varchar(255) DEFAULT NULL,
  `created_by` bigint(20) DEFAULT NULL,
  `department` int(11) DEFAULT NULL,
  `discountamount` varchar(10) DEFAULT NULL,
  `discountdate` varchar(25) DEFAULT NULL,
  `discountitem` int(11) DEFAULT NULL,
  `discountrate` varchar(10) DEFAULT NULL,
  `discounttotal` varchar(10) DEFAULT NULL,
  `duedate` varchar(25) DEFAULT NULL,
  `email` varchar(255) DEFAULT NULL,
  `estimate` int(11) DEFAULT NULL,
  `estgrossprofit` decimal(10,2) DEFAULT NULL,
  `estgrossprofitpercent` decimal(5,2) DEFAULT NULL,
  `exchangerate` decimal(10,4) DEFAULT NULL,
  `enddate` varchar(25) DEFAULT NULL,
  `formid` bigint(20) DEFAULT NULL,
  `leadsource` varchar(255) DEFAULT NULL,
  `location` int(11) DEFAULT NULL,
  `memo` text DEFAULT NULL,
  `message` text DEFAULT NULL,
  `nexus` tinyint(1) NOT NULL DEFAULT 0,
  `nextbill` varchar(25) DEFAULT NULL,
  `orderstatus` int(11) DEFAULT NULL,
  `opportunity` varchar(255) DEFAULT NULL,
  `ordpicked` tinyint(1) NOT NULL DEFAULT 0,
  `paymentoption` int(11) DEFAULT NULL,
  `paymenthold` tinyint(1) NOT NULL DEFAULT 0,
  `posting` tinyint(1) NOT NULL DEFAULT 0,
  `postingperiod` varchar(255) DEFAULT NULL,
  `prevdate` varchar(25) DEFAULT NULL,
  `promocode` varchar(255) DEFAULT NULL,
  `salesrep` int(11) DEFAULT NULL,
  `salesteam` int(11) DEFAULT NULL,
  `shipcarrier` varchar(255) DEFAULT NULL,
  `shipcomplete` tinyint(1) NOT NULL DEFAULT 0,
  `shipdate` varchar(25) DEFAULT NULL,
  `shipisresidential` tinyint(1) NOT NULL DEFAULT 0,
  `shipmethod` int(11) DEFAULT NULL,
  `shipoverride` tinyint(1) NOT NULL DEFAULT 0,
  `shippingaddress` int(11) DEFAULT NULL,
  `shippingcost` decimal(10,2) DEFAULT NULL,
  `shippingcostoverridden` tinyint(1) NOT NULL DEFAULT 0,
  `source` varchar(255) DEFAULT NULL,
  `sourcewebsite` varchar(50) DEFAULT NULL,
  `startdate` varchar(25) DEFAULT NULL,
  `status` varchar(255) DEFAULT NULL,
  `subsidiary` varchar(255) DEFAULT NULL,
  `subtotal` decimal(8,2) DEFAULT NULL,
  `tag` varchar(255) DEFAULT NULL,
  `terms` varchar(255) DEFAULT NULL,
  `tobeprinted` tinyint(1) NOT NULL DEFAULT 0,
  `total` decimal(10,2) DEFAULT NULL,
  `totalcostestimate` decimal(10,2) DEFAULT NULL,
  `trandate` varchar(25) DEFAULT NULL,
  `tranid` varchar(255) DEFAULT NULL,
  `transactionnumber` varchar(255) DEFAULT NULL,
  `userevenuearrangement` tinyint(1) NOT NULL DEFAULT 1,
  `visibletocustomer` tinyint(1) NOT NULL DEFAULT 1,
  `void` tinyint(1) NOT NULL DEFAULT 0,
  `voided` tinyint(1) NOT NULL DEFAULT 0,
  `website` varchar(255) DEFAULT NULL,
  `deleted_at` timestamp NULL DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL,
  `class` bigint(20) DEFAULT NULL,
  `entity` int(11) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `invoices_external_id_unique` (`external_id`),
  KEY `invoices_created_by_foreign` (`created_by`),
  KEY `invoices_formid_foreign` (`formid`),
  KEY `invoices_refid_index` (`refid`),
  CONSTRAINT `invoices_created_by_foreign` FOREIGN KEY (`created_by`) REFERENCES `users` (`id`) ON DELETE SET NULL,
  CONSTRAINT `invoices_formid_foreign` FOREIGN KEY (`formid`) REFERENCES `entry_forms` (`id`) ON DELETE SET NULL
) ENGINE=InnoDB AUTO_INCREMENT=93105 DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;



/*!40101 SET SQL_MODE=@OLD_SQL_MODE */;
/*!40014 SET FOREIGN_KEY_CHECKS=@OLD_FOREIGN_KEY_CHECKS */;
/*!40014 SET UNIQUE_CHECKS=@OLD_UNIQUE_CHECKS */;
/*!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 */;
/*!40111 SET SQL_NOTES=@OLD_SQL_NOTES */;