-- ----------------------------
-- 发票表 for accounting_invoices
-- ----------------------------
DROP TABLE IF EXISTS `accounting_invoices`;
CREATE TABLE `accounting_invoices`  (
                                        `id` bigint(20) NOT NULL AUTO_INCREMENT COMMENT '发票id',
                                        `voucher_id` bigint(20) NULL DEFAULT NULL COMMENT '凭证id，一个凭证对应多个电子发票',
                                        `invoice_code` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '发票代码',
                                        `invoice_num` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NOT NULL COMMENT '发票号码',
                                        `amountIn_words` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '大写金额',
                                        `price` varchar(55) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '单价',
                                        `total_tax` varchar(55) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '合计税额',
                                        `tax_rate` varchar(55) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '税率',
                                        `total_amount` varchar(55) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '金额',
                                        `commodity_tax` varchar(55) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '税额',
                                        `commodity_amount` varchar(55) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '价税合计',
                                        `amountIn_figuers` varchar(55) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '小写价税合计',
                                        `fote_drawer` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '开票人',
                                        `seller_address` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '销方地址电话',
                                        `commodity_num` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '服务条数',
                                        `seller_register_num` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '销方纳税识别号',
                                        `machine_code` varchar(10) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '报送状态',
                                        `remarks` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '备注',
                                        `seller_bank` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '销方开户行及账号',
                                        `check_code` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '校验码',
                                        `invoice_date` datetime(0) NULL DEFAULT NULL COMMENT '开票日期',
                                        `purchaser_register_num` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '购方税号',
                                        `invoice_type_org` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '清单标志',
                                        `PASSWORD` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '密码区',
                                        `agent` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '打印标志',
                                        `purchaser_bank` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '购方开户行及账号',
                                        `checker` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '复核人',
                                        `city` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '城市',
                                        `purchaser_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '购方公司名',
                                        `commodity_type` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '规格型号',
                                        `province` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '报送日志',
                                        `invoice_type` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '发票种类',
                                        `sheet_num` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '发票联',
                                        `purchaser_address` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '购方地址电话',
                                        `commodity_unit` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '部门',
                                        `payee` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '收款人',
                                        `commodity_name` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '主要商品名称',
                                        `seller_name` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '销方名称',
                                        `invoice_check` tinyint(10) NULL DEFAULT NULL COMMENT '审核状态0待审核1已审核2审核退回3未提交',
                                        `invoice_seal` tinyint(10) NULL DEFAULT NULL COMMENT '是否印章0，1',
                                        `invoice_qrcode` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '发票综合代码',
                                        `invoice_qrnum` varchar(100) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '发票综合号码',
                                        `qr_check_code` tinyint(10) NULL DEFAULT NULL COMMENT '二维码查验（1查询相符,0查验不符）',
                                        `invoice_state` tinyint(10) NULL DEFAULT NULL COMMENT '发票状态1正常0作废',
                                        `print_num` datetime(0) NULL DEFAULT NULL COMMENT '作废日期',
                                        `inout_mark` tinyint(10) NULL DEFAULT NULL COMMENT '进销项标识0进项1销项',
                                        `invalid_mark` varchar(50) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '作废标志0作废1启用',
                                        `duplicate_mark` tinyint(10) NULL DEFAULT NULL COMMENT '重复标识0已查重1有重复',
                                        `check_true` tinyint(10) NULL DEFAULT NULL COMMENT '验真0未验真1已验证',
                                        `encrypt` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '加密',
                                        `create_by` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '制单人',
                                        `creator` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '创建者',
                                        `create_time` datetime(0) NULL DEFAULT NULL COMMENT '创建时间',
                                        `update_time` datetime(0) NULL DEFAULT NULL COMMENT '更新时间',
                                        `record_id` bigint(20) NULL DEFAULT NULL COMMENT '归档id，一个归档id对应多个发票',
                                        `company_id` bigint(20) NULL DEFAULT NULL COMMENT '业务实体id',
                                        `company` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '业务实体',
                                        `dept_id` bigint(20) NULL DEFAULT NULL COMMENT '所属部门id',
                                        `dept_name` varchar(30) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '所属部门',
                                        `user_id` bigint(20) NULL DEFAULT NULL COMMENT '用户id',
                                        `deleted` bit(1) NULL DEFAULT b'0' COMMENT '是否删除',
                                        `updater` varchar(20) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '更新者',
                                        `remark` varchar(500) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '备注',
                                        `attr1` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '预留字段1',
                                        `attr2` varchar(255) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '预留字段2',
                                        `attr3` int(11) NULL DEFAULT NULL COMMENT '预留字段3',
                                        `attr4` int(11) NULL DEFAULT NULL COMMENT '预留字段4',
                                        `archive_state` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '归档状态',
                                        `tenant_id` bigint(20) NULL DEFAULT NULL COMMENT '租户编号，一个集团/总公司对应一个租户',
                                        `file_url` varchar(64) CHARACTER SET utf8mb4 COLLATE utf8mb4_general_ci NULL DEFAULT NULL COMMENT '发票地址',
                                        PRIMARY KEY (`id`) USING BTREE
) ENGINE = InnoDB AUTO_INCREMENT = 16 CHARACTER SET = utf8mb4 COLLATE = utf8mb4_general_ci COMMENT = '发票表' ROW_FORMAT = Dynamic;

SET FOREIGN_KEY_CHECKS = 1;

-- 插入发票菜单
SELECT * FROM `system_menu` WHERE `name`='会计档案';
SET @menuId = LAST_INSERT_ID();
INSERT INTO `lyr-one`.`system_menu`(`name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES ('发票管理', '', 2, 0, @menuId, 'invoices', '', 'accounting/invoices/index', 'Invoices', 0, b'1', b'1', b'1', '', '2023-09-20 14:03:48', '', '2023-09-20 14:03:48', b'0');
SET @menuId2 = LAST_INSERT_ID();
INSERT INTO `lyr-one`.`system_menu`(`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (NULL, '发票查询', 'accounting:invoices:query', 3, 1, @menuId2, '', '', '', NULL, 0, b'1', b'1', b'1', '', '2023-09-20 14:03:48', '', '2023-09-20 14:03:48', b'0');
INSERT INTO `lyr-one`.`system_menu`(`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (NULL, '发票创建', 'accounting:invoices:create', 3, 2, @menuId2, '', '', '', NULL, 0, b'1', b'1', b'1', '', '2023-09-20 14:03:48', '', '2023-09-20 14:03:48', b'0');
INSERT INTO `lyr-one`.`system_menu`(`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (NULL, '发票更新', 'accounting:invoices:update', 3, 3, @menuId2, '', '', '', NULL, 0, b'1', b'1', b'1', '', '2023-09-20 14:03:48', '', '2023-09-20 14:03:48', b'0');
INSERT INTO `lyr-one`.`system_menu`(`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (NULL, '发票删除', 'accounting:invoices:delete', 3, 4, @menuId2, '', '', '', NULL, 0, b'1', b'1', b'1', '', '2023-09-20 14:03:48', '', '2023-09-20 14:03:48', b'0');
INSERT INTO `lyr-one`.`system_menu`(`id`, `name`, `permission`, `type`, `sort`, `parent_id`, `path`, `icon`, `component`, `component_name`, `status`, `visible`, `keep_alive`, `always_show`, `creator`, `create_time`, `updater`, `update_time`, `deleted`) VALUES (NULL, '发票导出', 'accounting:invoices:export', 3, 5, @menuId2, '', '', '', NULL, 0, b'1', b'1', b'1', '', '2023-09-20 14:03:48', '', '2023-09-20 14:03:48', b'0');


-- 插入发票字典
INSERT INTO `lyr-one`.`system_dict_type`(`id`, `name`, `type`, `status`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `deleted_time`) VALUES (190, '会计发票查验', 'accounting_invoices_check', 0, NULL, '', '2023-09-21 14:15:03', '', '2023-09-21 14:15:03', b'0', '1970-01-01 00:00:00');
INSERT INTO `lyr-one`.`system_dict_type`(`id`, `name`, `type`, `status`, `remark`, `creator`, `create_time`, `updater`, `update_time`, `deleted`, `deleted_time`) VALUES (191, '会计发票查重', 'accounting_invoices_duplicate', 0, NULL, '', '2023-09-21 14:16:49', '', '2023-09-21 14:17:27', b'0', '1970-01-01 00:00:00');

