salix/db/.archive/232801/00-client_create.sql

90 lines
2.2 KiB
MySQL
Raw Normal View History

2023-07-06 09:51:04 +00:00
DROP PROCEDURE IF EXISTS `vn`.`clientCreate`;
2023-06-20 15:01:06 +00:00
DELIMITER $$
CREATE OR REPLACE DEFINER=`root`@`localhost` PROCEDURE `vn`.`client_create`(
vFirstname VARCHAR(50),
2023-07-06 09:51:04 +00:00
vSurnames VARCHAR(50),
vFi VARCHAR(9),
vAddress TEXT,
2023-06-20 15:01:06 +00:00
vPostcode CHAR(5),
vCity VARCHAR(25),
vProvinceFk SMALLINT(5),
vCompanyFk SMALLINT(5),
vPhone VARCHAR(11),
vEmail VARCHAR(255),
2023-06-22 15:56:45 +00:00
vUserFk INT
)
2023-06-20 15:01:06 +00:00
BEGIN
/**
* Create new client
*
* @params vFirstname firstName
* @params vSurnames surnames
* @params vFi company code from accounting transactions
* @params vAddress address
* @params vPostcode postCode
* @params vCity city
* @params vProvinceFk province
* @params vCompanyFk company in which he has become a client
* @params vPhone telephone number
* @params vEmail email address
* @params vUserFk user id
*/
DECLARE vPayMethodFk INT;
DECLARE vDueDay INT;
DECLARE vDefaultCredit DECIMAL(10, 2);
DECLARE vIsTaxDataChecked TINYINT(1);
DECLARE vHasCoreVnl BOOLEAN;
DECLARE vMandateTypeFk INT;
2023-06-28 12:07:37 +00:00
SELECT defaultPayMethodFk,
2023-06-22 13:00:15 +00:00
defaultDueDay,
defaultCredit,
defaultIsTaxDataChecked,
defaultHasCoreVnl,
defaultMandateTypeFk
2023-06-22 14:23:36 +00:00
INTO vPayMethodFk,
2023-06-28 12:07:37 +00:00
vDueDay,
vDefaultCredit,
vIsTaxDataChecked,
vHasCoreVnl,
vMandateTypeFk
2023-06-22 13:00:15 +00:00
FROM clientConfig;
2023-06-20 15:01:06 +00:00
INSERT INTO `client`
SET id = vUserFk,
name = CONCAT(vFirstname, ' ', vSurnames),
street = vAddress,
fi = TRIM(vFi),
phone = vPhone,
email = vEmail,
provinceFk = vProvinceFk,
city = vCity,
postcode = vPostcode,
2023-07-06 09:51:04 +00:00
socialName = CONCAT(vSurnames, ' ', vFirstname),
2023-06-20 15:01:06 +00:00
payMethodFk = vPayMethodFk,
dueDay = vDueDay,
credit = vDefaultCredit,
isTaxDataChecked = vIsTaxDataChecked,
hasCoreVnl = vHasCoreVnl,
isEqualizated = FALSE
ON duplicate KEY UPDATE
payMethodFk = vPayMethodFk,
dueDay = vDueDay,
credit = vDefaultCredit,
isTaxDataChecked = vIsTaxDataChecked,
hasCoreVnl = vHasCoreVnl,
isActive = TRUE;
2023-07-06 09:51:04 +00:00
2023-07-03 12:08:50 +00:00
INSERT INTO mandate (clientFk, companyFk, mandateTypeFk)
SELECT vUserFk, vCompanyFk, vMandateTypeFk
WHERE NOT EXISTS (
2023-07-06 09:51:04 +00:00
SELECT id
FROM mandate
WHERE clientFk = vUserFk
AND companyFk = vCompanyFk
2023-07-03 12:08:50 +00:00
AND mandateTypeFk = vMandateTypeFk
);
2023-06-20 15:01:06 +00:00
END$$
DELIMITER ;