refs #5366 refactor(invoiceIn_toBook): use invoiceIn_booking #1599
|
@ -782,6 +782,38 @@ USE `sage`;
|
||||||
-- Dumping data for table `TiposIva`
|
-- Dumping data for table `TiposIva`
|
||||||
--
|
--
|
||||||
|
|
||||||
|
LOCK TABLES `taxType` WRITE;
|
||||||
|
/*!40000 ALTER TABLE `taxType` DISABLE KEYS */;
|
||||||
|
INSERT INTO `sage`.`taxType` (id, code, isIntracommunity) VALUES
|
||||||
|
(2, NULL, 0),
|
||||||
|
(4, 'national4', 0),
|
||||||
|
(5, NULL, 0),
|
||||||
|
(6, NULL, 1),
|
||||||
|
(7, NULL, 1),
|
||||||
|
(8, NULL, 1),
|
||||||
|
(10, 'national10', 0),
|
||||||
|
(11, NULL, 0),
|
||||||
|
(16, 'CEEServices21', 1),
|
||||||
|
(18, NULL, 0),
|
||||||
|
(20, 'national0', 0),
|
||||||
|
(21, 'national21', 0),
|
||||||
|
(22, 'import10', 0),
|
||||||
|
(26, NULL, 0),
|
||||||
|
(90, 'import21', 0),
|
||||||
|
(91, NULL, 0),
|
||||||
|
(92, NULL, 0),
|
||||||
|
(93, NULL, 0),
|
||||||
|
(94, NULL, 0),
|
||||||
|
(100, NULL, 0),
|
||||||
|
(108, NULL, 0),
|
||||||
|
(109, NULL, 0),
|
||||||
|
(110, NULL, 1),
|
||||||
|
(111, NULL, 0),
|
||||||
|
(112, NULL, 0),
|
||||||
|
(113, 'ISP21', 0),
|
||||||
|
(114, NULL, 0),
|
||||||
|
(115, 'import4', 0);
|
||||||
|
|
||||||
LOCK TABLES `TiposIva` WRITE;
|
LOCK TABLES `TiposIva` WRITE;
|
||||||
/*!40000 ALTER TABLE `TiposIva` DISABLE KEYS */;
|
/*!40000 ALTER TABLE `TiposIva` DISABLE KEYS */;
|
||||||
INSERT INTO `TiposIva` VALUES (2,0,'Operaciones no sujetas',0.0000000000,0.0000000000,0.0000000000,'','4770000020','','','','','','','95B21A93-5910-489D-83BB-C32788C9B19D','','','','','','','','','',0,0),(4,0,'I.V.A. 4%',0.0000000000,4.0000000000,0.0000000000,'4720000004','4770000004','','6310000000','','','','','9E6160D5-984E-4643-ACBC-1EBC3BF73360','','','','','','','','','',0,0),(5,0,'I.V.A. 4% y R.E. 0.5%',0.0000000000,4.0000000000,0.5000000000,'','4770000504','4770000405','','','','','','DBEFA562-63FB-4FFC-8171-64F0C6F065FF','','','','','','','','','',0,0),(6,0,'H.P. IVA 4% CEE',0.0000000000,4.0000000000,0.0000000000,'4721000004','4771000004','','','','','','','DD0ECBA8-2EF5-425E-911B-623580BADA77','','','','','','','','','',0,1),(7,0,'H.P. IVA 10% CEE',0.0000000000,10.0000000000,0.0000000000,'4721000011','4771000010','','','','','','','593208CD-6F28-4489-B6EC-907AD689EAC9','','','','','','','','','',0,1),(8,0,'H.P. IVA 21% CEE',0.0000000000,21.0000000000,0.0000000000,'4721000021','4771000021','','','','','','','27061852-9BC1-4C4F-9B6E-69970E208F23','','','','','','','','','',0,1),(10,0,'I.V.A. 10% Nacional',0.0000000000,10.0000000000,0.0000000000,'4720000011','4770000010','','6290000553','','','','','828A9D6F-5C01-4C3A-918A-B2E4482830D3','','','','','','','','','',0,0),(11,0,'I.V.A. 10% y R.E. 1,4%',0.0000000000,10.0000000000,1.4000000000,'','4770000101','4770000110','','','','','','C1F2D910-83A1-4191-A76C-8B3D7AB98348','','','','','','','','','',0,0),(16,0,'I.V.A. Adqui. servicios CEE',0.0000000000,21.0000000000,0.0000000000,'4721000015','4771000016','','','','','','','E3EDE961-CE8F-41D4-9E6C-D8BCD32275A1','','','','','','','','','',0,1),(18,0,'H.P. Iva Importación 0% ISP',0.0000000000,0.0000000000,0.0000000000,'4720000005','4770000005','','','','','','','27AD4158-2349-49C2-B53A-A4E0EFAC5D09','','','','','','','','','',0,0),(20,0,'I.V.A 0% Nacional',0.0000000000,0.0000000000,0.0000000000,'4720000000','','','','','','','','B90B0FBD-E513-4F04-9721-C873504E08DF','','','','','','','','','',0,0),(21,0,'I.V.A. 21%',0.0000000000,21.0000000000,0.0000000000,'4720000021','4770000021','4770000000','','','','','','BA8C4E28-DCFA-4F7B-AE4F-CA044626B55E','','','','','','','','','',0,0),(22,0,'IVA 10% importaciones',0.0000000000,10.0000000000,0.0000000000,'4722000010','','','','','','','','540450A8-4B41-4607-96D1-E7F296FB6933','','','','','','','','','',0,0),(26,0,'I.V.A. 21% y R.E. 5,2%',0.0000000000,21.0000000000,5.2000000000,'4720000021','4770000215','4770000521','631000000','','','','','2BC0765F-7739-49AE-A5F0-28B648B81677','','','','','','','','','',0,0),(90,0,'IVA 21% importaciones',0.0000000000,21.0000000000,0.0000000000,'4722000021','','','','','','','','EB675F91-5FF2-4E26-A31E-EEB674125945','','','','','','','','','',0,0),(91,0,'IVA 0% importaciones',0.0000000000,0.0000000000,0.0000000000,'4723000000','','','','','','','','5E5EFA56-2A99-4D54-A16B-5D818274CA18','','','','','','','','','',0,0),(92,0,'8.5% comp. ganadera o pesquera',0.0000000000,8.5000000000,0.0000000000,'4720000000','4770000000','477000000','631000000','','','','','','','','','','','','','','',0,0),(93,0,'12% com. agrícola o forestal',0.0000000000,12.0000000000,0.0000000000,'4720000012','','','','','','','','267B1DDB-247F-4A71-AB95-3349FEFC5F92','','','','','','','','','',0,0),(94,0,'10,5% com. ganadera o pesquera',0.0000000000,10.5000000000,0.0000000000,'4770000000','4720000000','631000000','477000000','','','','','','','','','','','','','','',0,0),(100,0,'HP IVA SOPORTADO 5%',0.0000000000,5.0000000000,0.0000000000,'4720000055','','','','','','','','3AD36CB2-4172-4CC9-9F87-2BF2B56AAC80','','','','','','','','','',0,0),(108,0,'I.V.A. 8%',0.0000000000,8.0000000000,0.0000000000,'4720000000','4770000000','477000000','631000000','','','','','','','','','','','','','','',0,0),(109,0,'I.V.A. 8% y R.E. 1%',0.0000000000,8.0000000000,1.0000000000,'4720000000','4770000000','477000000','631000000','','','','','','','','','','','','','','',0,0),(110,0,'HP IVA Devengado Exento CEE',0.0000000000,0.0000000000,0.0000000000,'','4771000000','','','','','','','C605BC32-E161-42FD-83F3-3A66B1FBE399','','','','','','','','','',0,1),(111,0,'H.P. Iva Devengado Exento Ser',0.0000000000,0.0000000000,0.0000000000,'','4771000001','','','','','','','F1AEC4DC-AFE5-498E-A713-2648FFB6DA32','','','','','','','','','',0,0),(112,0,'H.P. IVA Devengado en exportac',0.0000000000,0.0000000000,0.0000000000,'','4770000002','','','','','','','F980AE74-BF75-4F4C-927F-0CCCE0DB8D15','','','','','','','','','',0,0),(113,0,'HP DEVENGADO 21 ISP ',0.0000000000,21.0000000000,0.0000000000,'4720000006','4770000006','','','','','','','728D7A76-E936-438C-AF05-3CA38FE16EA5','','','','','','','','','',0,0),(114,0,'HP.IVA NO DEDUCIBLE 10%',0.0000000000,0.0000000000,0.0000000000,'4720000026','','','','','','','','','','','','','','','','','',0,0),(115,0,'H.P. IVA Soportado Impor 4% ',0.0000000000,4.0000000000,0.0000000000,'4722000004','','','','','','','','','','','','','','','','','',0,0);
|
INSERT INTO `TiposIva` VALUES (2,0,'Operaciones no sujetas',0.0000000000,0.0000000000,0.0000000000,'','4770000020','','','','','','','95B21A93-5910-489D-83BB-C32788C9B19D','','','','','','','','','',0,0),(4,0,'I.V.A. 4%',0.0000000000,4.0000000000,0.0000000000,'4720000004','4770000004','','6310000000','','','','','9E6160D5-984E-4643-ACBC-1EBC3BF73360','','','','','','','','','',0,0),(5,0,'I.V.A. 4% y R.E. 0.5%',0.0000000000,4.0000000000,0.5000000000,'','4770000504','4770000405','','','','','','DBEFA562-63FB-4FFC-8171-64F0C6F065FF','','','','','','','','','',0,0),(6,0,'H.P. IVA 4% CEE',0.0000000000,4.0000000000,0.0000000000,'4721000004','4771000004','','','','','','','DD0ECBA8-2EF5-425E-911B-623580BADA77','','','','','','','','','',0,1),(7,0,'H.P. IVA 10% CEE',0.0000000000,10.0000000000,0.0000000000,'4721000011','4771000010','','','','','','','593208CD-6F28-4489-B6EC-907AD689EAC9','','','','','','','','','',0,1),(8,0,'H.P. IVA 21% CEE',0.0000000000,21.0000000000,0.0000000000,'4721000021','4771000021','','','','','','','27061852-9BC1-4C4F-9B6E-69970E208F23','','','','','','','','','',0,1),(10,0,'I.V.A. 10% Nacional',0.0000000000,10.0000000000,0.0000000000,'4720000011','4770000010','','6290000553','','','','','828A9D6F-5C01-4C3A-918A-B2E4482830D3','','','','','','','','','',0,0),(11,0,'I.V.A. 10% y R.E. 1,4%',0.0000000000,10.0000000000,1.4000000000,'','4770000101','4770000110','','','','','','C1F2D910-83A1-4191-A76C-8B3D7AB98348','','','','','','','','','',0,0),(16,0,'I.V.A. Adqui. servicios CEE',0.0000000000,21.0000000000,0.0000000000,'4721000015','4771000016','','','','','','','E3EDE961-CE8F-41D4-9E6C-D8BCD32275A1','','','','','','','','','',0,1),(18,0,'H.P. Iva Importación 0% ISP',0.0000000000,0.0000000000,0.0000000000,'4720000005','4770000005','','','','','','','27AD4158-2349-49C2-B53A-A4E0EFAC5D09','','','','','','','','','',0,0),(20,0,'I.V.A 0% Nacional',0.0000000000,0.0000000000,0.0000000000,'4720000000','','','','','','','','B90B0FBD-E513-4F04-9721-C873504E08DF','','','','','','','','','',0,0),(21,0,'I.V.A. 21%',0.0000000000,21.0000000000,0.0000000000,'4720000021','4770000021','4770000000','','','','','','BA8C4E28-DCFA-4F7B-AE4F-CA044626B55E','','','','','','','','','',0,0),(22,0,'IVA 10% importaciones',0.0000000000,10.0000000000,0.0000000000,'4722000010','','','','','','','','540450A8-4B41-4607-96D1-E7F296FB6933','','','','','','','','','',0,0),(26,0,'I.V.A. 21% y R.E. 5,2%',0.0000000000,21.0000000000,5.2000000000,'4720000021','4770000215','4770000521','631000000','','','','','2BC0765F-7739-49AE-A5F0-28B648B81677','','','','','','','','','',0,0),(90,0,'IVA 21% importaciones',0.0000000000,21.0000000000,0.0000000000,'4722000021','','','','','','','','EB675F91-5FF2-4E26-A31E-EEB674125945','','','','','','','','','',0,0),(91,0,'IVA 0% importaciones',0.0000000000,0.0000000000,0.0000000000,'4723000000','','','','','','','','5E5EFA56-2A99-4D54-A16B-5D818274CA18','','','','','','','','','',0,0),(92,0,'8.5% comp. ganadera o pesquera',0.0000000000,8.5000000000,0.0000000000,'4720000000','4770000000','477000000','631000000','','','','','','','','','','','','','','',0,0),(93,0,'12% com. agrícola o forestal',0.0000000000,12.0000000000,0.0000000000,'4720000012','','','','','','','','267B1DDB-247F-4A71-AB95-3349FEFC5F92','','','','','','','','','',0,0),(94,0,'10,5% com. ganadera o pesquera',0.0000000000,10.5000000000,0.0000000000,'4770000000','4720000000','631000000','477000000','','','','','','','','','','','','','','',0,0),(100,0,'HP IVA SOPORTADO 5%',0.0000000000,5.0000000000,0.0000000000,'4720000055','','','','','','','','3AD36CB2-4172-4CC9-9F87-2BF2B56AAC80','','','','','','','','','',0,0),(108,0,'I.V.A. 8%',0.0000000000,8.0000000000,0.0000000000,'4720000000','4770000000','477000000','631000000','','','','','','','','','','','','','','',0,0),(109,0,'I.V.A. 8% y R.E. 1%',0.0000000000,8.0000000000,1.0000000000,'4720000000','4770000000','477000000','631000000','','','','','','','','','','','','','','',0,0),(110,0,'HP IVA Devengado Exento CEE',0.0000000000,0.0000000000,0.0000000000,'','4771000000','','','','','','','C605BC32-E161-42FD-83F3-3A66B1FBE399','','','','','','','','','',0,1),(111,0,'H.P. Iva Devengado Exento Ser',0.0000000000,0.0000000000,0.0000000000,'','4771000001','','','','','','','F1AEC4DC-AFE5-498E-A713-2648FFB6DA32','','','','','','','','','',0,0),(112,0,'H.P. IVA Devengado en exportac',0.0000000000,0.0000000000,0.0000000000,'','4770000002','','','','','','','F980AE74-BF75-4F4C-927F-0CCCE0DB8D15','','','','','','','','','',0,0),(113,0,'HP DEVENGADO 21 ISP ',0.0000000000,21.0000000000,0.0000000000,'4720000006','4770000006','','','','','','','728D7A76-E936-438C-AF05-3CA38FE16EA5','','','','','','','','','',0,0),(114,0,'HP.IVA NO DEDUCIBLE 10%',0.0000000000,0.0000000000,0.0000000000,'4720000026','','','','','','','','','','','','','','','','','',0,0),(115,0,'H.P. IVA Soportado Impor 4% ',0.0000000000,4.0000000000,0.0000000000,'4722000004','','','','','','','','','','','','','','','','','',0,0);
|
||||||
|
|
|
@ -2896,3 +2896,10 @@ INSERT INTO `vn`.`travelConfig` (`id`, `warehouseInFk`, `warehouseOutFk`, `agenc
|
||||||
INSERT INTO `vn`.`buyConfig` (`id`, `monthsAgo`)
|
INSERT INTO `vn`.`buyConfig` (`id`, `monthsAgo`)
|
||||||
VALUES
|
VALUES
|
||||||
(1, 6);
|
(1, 6);
|
||||||
|
|
||||||
|
INSERT INTO `vn`.`invoiceInSerial` (`code`, `description`, `cplusTerIdNifFk`, `taxAreaFk`)
|
||||||
|
VALUES
|
||||||
|
('C', 'Asgard', 1, 'WORLD'),
|
||||||
|
('E', 'Midgard', 1, 'CEE'),
|
||||||
|
('R', 'Jotunheim', 1, 'NATIONAL'),
|
||||||
|
('W', 'Vanaheim', 1, 'WORLD');
|
||||||
|
|
|
@ -15620,6 +15620,18 @@ CREATE TABLE `ClavesOperacion` (
|
||||||
--
|
--
|
||||||
-- Table structure for table `Municipios`
|
-- Table structure for table `Municipios`
|
||||||
--
|
--
|
||||||
|
DROP TABLE IF EXISTS `taxType`;
|
||||||
|
|
||||||
|
CREATE TABLE `taxType` (
|
||||||
|
id INT(11) NOT NULL,
|
||||||
|
code VARCHAR(25) DEFAULT NULL NULL,
|
||||||
|
isIntracommunity TINYINT(1) DEFAULT FALSE NOT NULL,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
UNIQUE KEY `taxType_UN` (`code`)
|
||||||
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci COMMENT='Coincidencia del id con Sage.TiposIVA.CodigoIva(propia de Sage), en ningún caso vincular mediate FK';
|
||||||
|
|
||||||
|
ALTER TABLE `sage`.`taxType` ADD CONSTRAINT taxType_PK PRIMARY KEY IF NOT EXISTS (id);
|
||||||
|
ALTER TABLE `sage`.`taxType` ADD CONSTRAINT taxType_UN UNIQUE KEY IF NOT EXISTS (code);
|
||||||
|
|
||||||
DROP TABLE IF EXISTS `Municipios`;
|
DROP TABLE IF EXISTS `Municipios`;
|
||||||
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
/*!40101 SET @saved_cs_client = @@character_set_client */;
|
||||||
|
@ -22074,12 +22086,14 @@ CREATE TABLE `autonomy` (
|
||||||
`name` varchar(100) NOT NULL,
|
`name` varchar(100) NOT NULL,
|
||||||
`countryFk` mediumint(8) unsigned NOT NULL,
|
`countryFk` mediumint(8) unsigned NOT NULL,
|
||||||
`geoFk` int(11) DEFAULT NULL,
|
`geoFk` int(11) DEFAULT NULL,
|
||||||
|
`isUeeMember` tinyint(1) DEFAULT NULL,
|
||||||
|
`hasDailyInvoice` tinyint(4) DEFAULT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY (`id`),
|
||||||
KEY `autonomy_FK` (`countryFk`),
|
KEY `autonomy_FK` (`countryFk`),
|
||||||
KEY `autonomy_FK_1` (`geoFk`),
|
KEY `autonomy_FK_1` (`geoFk`),
|
||||||
CONSTRAINT `autonomy_FK` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
CONSTRAINT `autonomy_FK` FOREIGN KEY (`countryFk`) REFERENCES `country` (`id`) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
CONSTRAINT `autonomy_FK_1` FOREIGN KEY (`geoFk`) REFERENCES `zoneGeo` (`id`) ON UPDATE CASCADE
|
CONSTRAINT `autonomy_FK_1` FOREIGN KEY (`geoFk`) REFERENCES `zoneGeo` (`id`) ON UPDATE CASCADE
|
||||||
) ENGINE=InnoDBDEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Comunidades autónomas o su equivalente en otros paises. Agrupación de provincias, en una categoria inferior a country.';
|
) ENGINE=InnoDB AUTO_INCREMENT=109 DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_unicode_ci COMMENT='Comunidades autónomas o su equivalente en otros paises. Agrupación de provincias, en una categoria inferior a country.';
|
||||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||||
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
||||||
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
||||||
|
@ -28805,7 +28819,10 @@ CREATE TABLE `expence` (
|
||||||
PRIMARY KEY (`id`)
|
PRIMARY KEY (`id`)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb3 COLLATE=utf8mb3_general_ci;
|
||||||
/*!40101 SET character_set_client = @saved_cs_client */;
|
/*!40101 SET character_set_client = @saved_cs_client */;
|
||||||
|
ALTER TABLE `vn`.`expence`
|
||||||
|
ADD code VARCHAR(25) DEFAULT NULL NULL;
|
||||||
|
ALTER TABLE `vn`.`expence`
|
||||||
|
ADD CONSTRAINT expence_UN UNIQUE KEY IF NOT EXISTS (code);
|
||||||
--
|
--
|
||||||
-- Table structure for table `farming`
|
-- Table structure for table `farming`
|
||||||
--
|
--
|
||||||
|
@ -57317,7 +57334,7 @@ DELIMITER ;
|
||||||
/*!50003 SET character_set_client = @saved_cs_client */ ;
|
/*!50003 SET character_set_client = @saved_cs_client */ ;
|
||||||
/*!50003 SET character_set_results = @saved_cs_results */ ;
|
/*!50003 SET character_set_results = @saved_cs_results */ ;
|
||||||
/*!50003 SET collation_connection = @saved_col_connection */ ;
|
/*!50003 SET collation_connection = @saved_col_connection */ ;
|
||||||
/*!50003 DROP PROCEDURE IF EXISTS `invoiceInBookingMain` */;
|
/*!50003 DROP PROCEDURE IF EXISTS `invoiceIn_booking` */;
|
||||||
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
/*!50003 SET @saved_cs_client = @@character_set_client */ ;
|
||||||
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
/*!50003 SET @saved_cs_results = @@character_set_results */ ;
|
||||||
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
/*!50003 SET @saved_col_connection = @@collation_connection */ ;
|
||||||
|
@ -57326,28 +57343,71 @@ DELIMITER ;
|
||||||
/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
|
/*!50003 SET collation_connection = utf8mb4_general_ci */ ;
|
||||||
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
/*!50003 SET @saved_sql_mode = @@sql_mode */ ;
|
||||||
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
|
/*!50003 SET sql_mode = 'NO_ENGINE_SUBSTITUTION' */ ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
DELIMITER ;;
|
DELIMITER ;;
|
||||||
CREATE DEFINER=`root`@`localhost` PROCEDURE `invoiceInBookingMain`(vInvoiceInId INT)
|
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`invoiceIn_booking`(vSelf INT)
|
||||||
BEGIN
|
BEGIN
|
||||||
DECLARE vTotalAmount,vTotalAmountDivisa DECIMAL(10,2);
|
DECLARE vBookNumber INT;
|
||||||
DECLARE vBookNumber,vSerialNumber INT;
|
|
||||||
DECLARE vRate DECIMAL(10,4);
|
|
||||||
|
|
||||||
CALL invoiceInBookingCommon(vInvoiceInId,vSerialNumber);
|
DROP TEMPORARY TABLE IF EXISTS tInvoiceIn;
|
||||||
|
CREATE TEMPORARY TABLE tInvoiceIn
|
||||||
SELECT SUM(iit.taxableBase * IF( i.serial= 'R' AND ti.Iva <> 'HP DEVENGADO 21 ISP', 1 +(ti.PorcentajeIva/100),1)),
|
ENGINE = MEMORY
|
||||||
SUM(iit.foreignValue * IF( i.serial= 'R', 1 + (ti.PorcentajeIva/100),1)),
|
SELECT ii.bookEntried,
|
||||||
iit.taxableBase/iit.foreignValue
|
iit.foreignValue,
|
||||||
INTO vTotalAmount, vTotalAmountDivisa, vRate
|
ii.companyFk,
|
||||||
FROM newInvoiceIn i
|
ii.expenceFkDeductible,
|
||||||
JOIN invoiceInTax iit ON iit.invoiceInFk = i.id
|
iit.taxableBase,
|
||||||
LEFT JOIN sage.TiposIva ti ON ti.CodigoIva = iit.taxTypeSageFk;
|
ii.serial,
|
||||||
|
ii.issued,
|
||||||
|
ii.operated,
|
||||||
|
ii.supplierRef,
|
||||||
|
ii.cplusTrascendency472Fk,
|
||||||
|
ii.cplusTaxBreakFk,
|
||||||
|
ii.cplusSubjectOpFk,
|
||||||
|
ii.cplusInvoiceType472Fk,
|
||||||
|
ii.cplusRectificationTypeFk,
|
||||||
|
ii.booked,
|
||||||
|
IFNULL(a.isUeeMember, c.isUeeMember) isUeeMember,
|
||||||
|
(c.id = cc.id) isSameCountry,
|
||||||
|
s.account supplierAccount,
|
||||||
|
s.name supplierName,
|
||||||
|
s.nif,
|
||||||
|
iit.taxTypeSageFk,
|
||||||
|
tt.code taxCode,
|
||||||
|
ti.Iva,
|
||||||
|
ti.CuentaIvaSoportado,
|
||||||
|
ti.PorcentajeIva,
|
||||||
|
ti.CuentaIvaRepercutido,
|
||||||
|
ttr.ClaveOperacionDefecto,
|
||||||
|
iis.cplusTerIdNifFk,
|
||||||
|
cit.id invoicesCount,
|
||||||
|
e.code,
|
||||||
|
e.isWithheld,
|
||||||
|
e.id expenceFk,
|
||||||
|
e.name expenceName
|
||||||
|
FROM invoiceIn ii
|
||||||
|
JOIN supplier s ON s.id = ii.supplierFk
|
||||||
|
LEFT JOIN province p ON p.id = s.provinceFk
|
||||||
|
LEFT JOIN autonomy a ON a.id = p.autonomyFk
|
||||||
|
JOIN country c ON c.id = s.countryFk
|
||||||
|
JOIN supplier sc ON sc.id = ii.companyFk
|
||||||
|
JOIN country cc ON cc.id = sc.countryFk
|
||||||
|
JOIN invoiceInSerial iis ON iis.code = ii.serial
|
||||||
|
JOIN cplusInvoiceType472 cit ON cit.id = ii.cplusInvoiceType472Fk
|
||||||
|
LEFT JOIN invoiceInTax iit ON iit.invoiceInFk = ii.id
|
||||||
|
LEFT JOIN sage.TiposTransacciones ttr ON ttr.CodigoTransaccion = iit.transactionTypeSageFk
|
||||||
|
LEFT JOIN expence e ON e.id = iit.expenceFk
|
||||||
|
LEFT JOIN sage.TiposIva ti ON ti.CodigoIva = iit.taxTypeSageFk
|
||||||
|
LEFT JOIN sage.taxType tt ON tt.id = ti.CodigoIva
|
||||||
|
WHERE ii.id = vSelf;
|
||||||
|
|
||||||
CALL vn.ledger_next(vBookNumber);
|
CALL vn.ledger_next(vBookNumber);
|
||||||
|
|
||||||
-- Apunte del proveedor
|
-- Apunte del proveedor
|
||||||
|
INSERT INTO XDiario(
|
||||||
INSERT INTO XDiario(ASIEN,
|
ASIEN,
|
||||||
FECHA,
|
FECHA,
|
||||||
SUBCTA,
|
SUBCTA,
|
||||||
EUROHABER,
|
EUROHABER,
|
||||||
|
@ -57356,24 +57416,30 @@ BEGIN
|
||||||
HABERME,
|
HABERME,
|
||||||
NFACTICK,
|
NFACTICK,
|
||||||
CLAVE,
|
CLAVE,
|
||||||
empresa_id
|
empresa_id)
|
||||||
)
|
|
||||||
SELECT
|
SELECT
|
||||||
vBookNumber,
|
vBookNumber ASIEN,
|
||||||
n.bookEntried,
|
tii.bookEntried FECHA,
|
||||||
s.supplierAccount,
|
tii.supplierAccount SUBCTA,
|
||||||
vTotalAmount EUROHABER,
|
SUM(tii.taxableBase *
|
||||||
n.conceptWithSupplier,
|
IF(tii.serial= 'R' AND ((tii.taxCode IS NULL OR tii.taxCode <> 'ISP21')
|
||||||
vRate,
|
AND tii.taxTypeSageFk IS NOT NULL),
|
||||||
vTotalAmountDivisa,
|
1 + (tii.PorcentajeIva / 100),
|
||||||
n.invoicesCount,
|
1)) EUROHABER,
|
||||||
vInvoiceInId,
|
CONCAT('s/fra',
|
||||||
n.companyFk
|
RIGHT(tii.supplierRef, 8),
|
||||||
FROM newInvoiceIn n
|
':',
|
||||||
JOIN newSupplier s;
|
LEFT(tii.supplierName, 10)) CONCEPTO,
|
||||||
|
CAST(tii.taxableBase / tii.foreignValue AS DECIMAL (10,4)) CAMBIO,
|
||||||
|
SUM(tii.foreignValue * IF(tii.serial = 'R', 1 + (tii.PorcentajeIva / 100), 1)) HABERME,
|
||||||
|
tii.invoicesCount NFACTICK,
|
||||||
|
vSelf CLAVE,
|
||||||
|
tii.companyFk empresa_id
|
||||||
|
FROM tInvoiceIn tii;
|
||||||
|
|
||||||
-- Línea de Gastos
|
-- Línea de Gastos
|
||||||
INSERT INTO XDiario ( ASIEN,
|
INSERT INTO XDiario(
|
||||||
|
ASIEN,
|
||||||
FECHA,
|
FECHA,
|
||||||
SUBCTA,
|
SUBCTA,
|
||||||
CONTRA,
|
CONTRA,
|
||||||
|
@ -57384,30 +57450,29 @@ BEGIN
|
||||||
DEBEME,
|
DEBEME,
|
||||||
HABERME,
|
HABERME,
|
||||||
NFACTICK,
|
NFACTICK,
|
||||||
empresa_id
|
empresa_id)
|
||||||
)
|
|
||||||
SELECT vBookNumber ASIEN,
|
SELECT vBookNumber ASIEN,
|
||||||
n.bookEntried FECHA,
|
tii.bookEntried FECHA,
|
||||||
IF(e.isWithheld , LPAD(RIGHT(s.supplierAccount,5),10,iit.expenceFk),iit.expenceFk) SUBCTA,
|
IF(tii.isWithheld, LPAD(RIGHT(tii.supplierAccount, 5), 10, tii.expenceFk),tii.expenceFk) SUBCTA,
|
||||||
s.supplierAccount CONTRA,
|
tii.supplierAccount CONTRA,
|
||||||
IF(e.isWithheld AND iit.taxableBase < 0, NULL, ROUND(SUM(iit.taxableBase),2)) EURODEBE,
|
IF(tii.isWithheld AND tii.taxableBase < 0, NULL, ROUND(SUM(tii.taxableBase),2)) EURODEBE,
|
||||||
IF(e.isWithheld AND iit.taxableBase < 0,ROUND(SUM(-iit.taxableBase),2),NULL) EUROHABER,
|
IF(tii.isWithheld AND tii.taxableBase < 0, ROUND(SUM(-tii.taxableBase), 2), NULL) EUROHABER,
|
||||||
n.conceptWithSupplier CONCEPTO,
|
CONCAT('s/fra',
|
||||||
vRate,
|
RIGHT(tii.supplierRef, 8),
|
||||||
IF(e.isWithheld,NULL,ABS(ROUND(SUM(iit.foreignValue),2))) DEBEME,
|
':',
|
||||||
IF(e.isWithheld,ABS(ROUND(SUM(iit.foreignValue),2)),NULL) HABERME,
|
LEFT(tii.supplierName, 10)) CONCEPTO,
|
||||||
n.invoicesCount NFACTICK,
|
CAST(tii.taxableBase / tii.foreignValue AS DECIMAL (10, 4)) CAMBIO,
|
||||||
n.companyFk empresa_id
|
IF(tii.isWithheld, NULL,ABS(ROUND(SUM(tii.foreignValue), 2))) DEBEME,
|
||||||
FROM newInvoiceIn n
|
IF(tii.isWithheld, ABS(ROUND(SUM(tii.foreignValue), 2)) ,NULL) HABERME,
|
||||||
JOIN newSupplier s
|
tii.invoicesCount NFACTICK,
|
||||||
JOIN invoiceInTax iit ON iit.invoiceInFk = n.id
|
tii.companyFk empresa_id
|
||||||
JOIN (SELECT * FROM expence e GROUP BY e.id)e ON e.id = iit.expenceFk
|
FROM tInvoiceIn tii
|
||||||
WHERE e.name != 'Suplidos Transitarios nacionales'
|
WHERE tii.code IS NULL OR tii.code <> 'suplido'
|
||||||
GROUP BY iit.expenceFk;
|
GROUP BY tii.expenceFk;
|
||||||
|
|
||||||
-- Líneas de IVA
|
-- Líneas de IVA
|
||||||
|
INSERT INTO XDiario(
|
||||||
INSERT INTO XDiario( ASIEN,
|
ASIEN,
|
||||||
FECHA,
|
FECHA,
|
||||||
SUBCTA,
|
SUBCTA,
|
||||||
CONTRA,
|
CONTRA,
|
||||||
|
@ -57434,56 +57499,50 @@ BEGIN
|
||||||
TERNIF,
|
TERNIF,
|
||||||
TERNOM,
|
TERNOM,
|
||||||
FECREGCON,
|
FECREGCON,
|
||||||
empresa_id
|
empresa_id)
|
||||||
)
|
|
||||||
SELECT vBookNumber ASIEN,
|
SELECT vBookNumber ASIEN,
|
||||||
n.bookEntried FECHA,
|
tii.bookEntried FECHA,
|
||||||
IF(n.expenceFkDeductible>0, n.expenceFkDeductible, ti.CuentaIvaSoportado) SUBCTA,
|
IF(tii.expenceFkDeductible>0, tii.expenceFkDeductible, tii.CuentaIvaSoportado) SUBCTA,
|
||||||
s.supplierAccount CONTRA,
|
tii.supplierAccount CONTRA,
|
||||||
SUM(ROUND(ti.PorcentajeIva * it.taxableBase / 100 /* + 0.0001*/ , 2)) EURODEBE,
|
SUM(ROUND(tii.PorcentajeIva * tii.taxableBase / 100, 2)) EURODEBE,
|
||||||
SUM(it.taxableBase) BASEEURO,
|
SUM(tii.taxableBase) BASEEURO,
|
||||||
GROUP_CONCAT(DISTINCT e.`name` SEPARATOR ', ') CONCEPTO,
|
GROUP_CONCAT(DISTINCT tii.expenceName SEPARATOR ', ') CONCEPTO,
|
||||||
vSerialNumber FACTURA,
|
vSelf FACTURA,
|
||||||
ti.PorcentajeIva IVA,
|
tii.PorcentajeIva IVA,
|
||||||
IF(isUeeMember AND eWithheld.id IS NULL,'','*') AUXILIAR,
|
IF(tii.isUeeMember AND eWithheld.id IS NULL, '', '*') AUXILIAR,
|
||||||
n.serial SERIE,
|
tii.serial SERIE,
|
||||||
ttr.ClaveOperacionDefecto,
|
tii.ClaveOperacionDefecto,
|
||||||
n.issued FECHA_EX,
|
tii.issued FECHA_EX,
|
||||||
n.operated FECHA_OP,
|
tii.operated FECHA_OP,
|
||||||
n.invoicesCount NFACTICK,
|
tii.invoicesCount NFACTICK,
|
||||||
n.supplierRef FACTURAEX,
|
tii.supplierRef FACTURAEX,
|
||||||
TRUE L340,
|
TRUE L340,
|
||||||
(isSameCountry OR NOT isUeeMember) LRECT349,
|
(tii.isSameCountry OR NOT tii.isUeeMember) LRECT349,
|
||||||
n.cplusTrascendency472Fk TIPOCLAVE,
|
tii.cplusTrascendency472Fk TIPOCLAVE,
|
||||||
n.cplusTaxBreakFk TIPOEXENCI,
|
tii.cplusTaxBreakFk TIPOEXENCI,
|
||||||
n.cplusSubjectOpFk TIPONOSUJE,
|
tii.cplusSubjectOpFk TIPONOSUJE,
|
||||||
n.cplusInvoiceType472Fk TIPOFACT,
|
tii.cplusInvoiceType472Fk TIPOFACT,
|
||||||
n.cplusRectificationTypeFk TIPORECTIF,
|
tii.cplusRectificationTypeFk TIPORECTIF,
|
||||||
iis.cplusTerIdNifFk TERIDNIF,
|
tii.cplusTerIdNifFk TERIDNIF,
|
||||||
s.nif AS TERNIF,
|
tii.nif TERNIF,
|
||||||
s.name AS TERNOM,
|
tii.supplierName TERNOM,
|
||||||
n.booked FECREGCON,
|
tii.booked FECREGCON,
|
||||||
n.companyFk
|
tii.companyFk
|
||||||
FROM newInvoiceIn n
|
FROM tInvoiceIn tii
|
||||||
JOIN newSupplier s
|
|
||||||
JOIN invoiceInTax it ON n.id = it.invoiceInFk
|
|
||||||
JOIN sage.TiposIva ti ON ti.CodigoIva = it.taxTypeSageFk
|
|
||||||
JOIN sage.TiposTransacciones ttr ON ttr.CodigoTransaccion = it.transactionTypeSageFk
|
|
||||||
JOIN invoiceInSerial iis ON iis.code = n.serial
|
|
||||||
JOIN (SELECT * FROM expence e GROUP BY e.id)e ON e.id = it.expenceFk
|
|
||||||
LEFT JOIN (
|
LEFT JOIN (
|
||||||
SELECT eWithheld.id
|
SELECT e.id
|
||||||
FROM invoiceInTax hold
|
FROM tInvoiceIn tii
|
||||||
JOIN expence eWithheld ON eWithheld.id = hold.expenceFk AND eWithheld.isWithheld
|
JOIN expence e ON e.id = tii.expenceFk
|
||||||
WHERE hold.invoiceInFk = vInvoiceInId LIMIT 1
|
WHERE e.isWithheld
|
||||||
|
LIMIT 1
|
||||||
) eWithheld ON TRUE
|
) eWithheld ON TRUE
|
||||||
WHERE it.taxTypeSageFk IS NOT NULL
|
WHERE tii.taxTypeSageFk IS NOT NULL
|
||||||
AND it.taxTypeSageFk NOT IN (22, 90)
|
AND (tii.taxCode IS NULL OR tii.taxCode NOT IN ('import10', 'import21'))
|
||||||
GROUP BY ti.PorcentajeIva, e.id;
|
GROUP BY tii.PorcentajeIva, tii.expenceFk;
|
||||||
|
|
||||||
-- Línea iva inversor sujeto pasivo
|
-- Línea iva inversor sujeto pasivo
|
||||||
|
INSERT INTO XDiario(
|
||||||
INSERT INTO XDiario( ASIEN,
|
ASIEN,
|
||||||
FECHA,
|
FECHA,
|
||||||
SUBCTA,
|
SUBCTA,
|
||||||
CONTRA,
|
CONTRA,
|
||||||
|
@ -57509,50 +57568,43 @@ BEGIN
|
||||||
TERIDNIF,
|
TERIDNIF,
|
||||||
TERNIF,
|
TERNIF,
|
||||||
TERNOM,
|
TERNOM,
|
||||||
empresa_id
|
empresa_id)
|
||||||
)
|
|
||||||
SELECT vBookNumber ASIEN,
|
SELECT vBookNumber ASIEN,
|
||||||
n.bookEntried FECHA,
|
tii.bookEntried FECHA,
|
||||||
ti.CuentaIvaRepercutido SUBCTA,
|
tii.CuentaIvaRepercutido SUBCTA,
|
||||||
s.supplierAccount CONTRA,
|
tii.supplierAccount CONTRA,
|
||||||
SUM(ROUND(ti.PorcentajeIva * it.taxableBase / 100,2)) EUROHABER,
|
SUM(ROUND(tii.PorcentajeIva * tii.taxableBase / 100,2)) EUROHABER,
|
||||||
ROUND(SUM(it.taxableBase),2) BASEEURO,
|
ROUND(SUM(tii.taxableBase),2) BASEEURO,
|
||||||
GROUP_CONCAT(DISTINCT e.`name` SEPARATOR ', ') CONCEPTO,
|
GROUP_CONCAT(DISTINCT tii.expenceName SEPARATOR ', ') CONCEPTO,
|
||||||
vSerialNumber FACTURA,
|
vSelf FACTURA,
|
||||||
ti.PorcentajeIva IVA,
|
tii.PorcentajeIva IVA,
|
||||||
'*' AUXILIAR,
|
'*' AUXILIAR,
|
||||||
n.serial SERIE,
|
tii.serial SERIE,
|
||||||
ttr.ClaveOperacionDefecto,
|
tii.ClaveOperacionDefecto,
|
||||||
n.issued FECHA_EX,
|
tii.issued FECHA_EX,
|
||||||
n.operated FECHA_OP,
|
tii.operated FECHA_OP,
|
||||||
n.invoicesCount NFACTICK,
|
tii.invoicesCount NFACTICK,
|
||||||
n.supplierRef FACTURAEX,
|
tii.supplierRef FACTURAEX,
|
||||||
FALSE L340,
|
FALSE L340,
|
||||||
(isSameCountry OR NOT isUeeMember) LRECT349,
|
(tii.isSameCountry OR NOT tii.isUeeMember) LRECT349,
|
||||||
1 TIPOCLAVE,
|
1 TIPOCLAVE,
|
||||||
n.cplusTaxBreakFk TIPOEXENCI,
|
tii.cplusTaxBreakFk TIPOEXENCI,
|
||||||
n.cplusSubjectOpFk TIPONOSUJE,
|
tii.cplusSubjectOpFk TIPONOSUJE,
|
||||||
n.cplusInvoiceType472Fk TIPOFACT,
|
tii.cplusInvoiceType472Fk TIPOFACT,
|
||||||
n.cplusRectificationTypeFk TIPORECTIF,
|
tii.cplusRectificationTypeFk TIPORECTIF,
|
||||||
iis.cplusTerIdNifFk TERIDNIF,
|
tii.cplusTerIdNifFk TERIDNIF,
|
||||||
s.nif AS TERNIF,
|
tii.nif TERNIF,
|
||||||
s.name AS TERNOM,
|
tii.supplierName TERNOM,
|
||||||
n.companyFk
|
tii.companyFk
|
||||||
FROM newInvoiceIn n
|
FROM tInvoiceIn tii
|
||||||
JOIN newSupplier s
|
WHERE tii.taxCode = 'ISP21' OR MID(tii.supplierAccount, 4, 1) = '1'
|
||||||
JOIN invoiceInTax it ON n.id = it.invoiceInFk
|
AND tii.taxTypeSageFk IS NOT NULL
|
||||||
JOIN sage.TiposIva ti ON ti.CodigoIva = it.taxTypeSageFk
|
GROUP BY tii.PorcentajeIva, tii.expenceFk;
|
||||||
JOIN sage.TiposTransacciones ttr ON ttr.CodigoTransaccion = it.transactionTypeSageFk
|
|
||||||
JOIN invoiceInSerial iis ON iis.code = n.serial
|
|
||||||
JOIN (SELECT * FROM expence e GROUP BY e.id)e ON e.id = it.expenceFk
|
|
||||||
WHERE ti.Iva = 'HP DEVENGADO 21 ISP' OR MID(s.account, 4, 1) = '1'
|
|
||||||
GROUP BY ti.PorcentajeIva, e.id;
|
|
||||||
|
|
||||||
-- Actualización del registro original
|
-- Actualización del registro original
|
||||||
UPDATE invoiceIn ii
|
UPDATE invoiceIn ii
|
||||||
JOIN newInvoiceIn ni ON ii.id = ni.id
|
SET ii.isBooked = TRUE
|
||||||
SET ii.serialNumber = vSerialNumber,
|
WHERE ii.id = vSelf;
|
||||||
ii.isBooked = TRUE;
|
|
||||||
|
|
||||||
-- Problemas derivados de la precisión en los decimales al calcular los impuestos
|
-- Problemas derivados de la precisión en los decimales al calcular los impuestos
|
||||||
UPDATE XDiario
|
UPDATE XDiario
|
||||||
|
@ -57569,8 +57621,12 @@ BEGIN
|
||||||
ORDER BY id DESC
|
ORDER BY id DESC
|
||||||
LIMIT 1;
|
LIMIT 1;
|
||||||
|
|
||||||
|
DROP TEMPORARY TABLE tInvoiceIn;
|
||||||
END ;;
|
END ;;
|
||||||
DELIMITER ;
|
DELIMITER ;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
/*!50003 SET sql_mode = @saved_sql_mode */ ;
|
||||||
/*!50003 SET character_set_client = @saved_cs_client */ ;
|
/*!50003 SET character_set_client = @saved_cs_client */ ;
|
||||||
/*!50003 SET character_set_results = @saved_cs_results */ ;
|
/*!50003 SET character_set_results = @saved_cs_results */ ;
|
||||||
|
|
|
@ -110,5 +110,6 @@ TABLES=(
|
||||||
TiposIva
|
TiposIva
|
||||||
TiposTransacciones
|
TiposTransacciones
|
||||||
TiposRetencion
|
TiposRetencion
|
||||||
|
taxType
|
||||||
)
|
)
|
||||||
dump_tables ${TABLES[@]}
|
dump_tables ${TABLES[@]}
|
||||||
|
|
|
@ -32,7 +32,7 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await Self.rawSql(`CALL vn.invoiceInBookingMain(?)`, [id], myOptions);
|
await Self.rawSql(`CALL vn.invoiceIn_booking(?)`, [id], myOptions);
|
||||||
if (tx) await tx.commit();
|
if (tx) await tx.commit();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
if (tx) await tx.rollback();
|
if (tx) await tx.rollback();
|
||||||
|
|
Loading…
Reference in New Issue