nikolasd
10/26/2018 - 1:37 PM

SQL Scripts to Repair Customer Balance

Για διόρθωση καρτελών πελατών

--Hotel Transcations στο Εμπορικό - Εισπράξεις
SELECT
  A.HECSTMID,
  hr.heresnum,
  doc.hedoccode,
  hb.herefnumber billno,
  a.hedentid,
  a.hefindentid,
  a.hedepositdentid,
  a.hedepositref,
  a.heparenttransid,
  a.heid,
  a.hetranstype,
  a.hestatus,
  a.*
FROM hehoteltransactions a
INNER JOIN hehotelbills hb
  ON hb.heid = a.hehlblid
LEFT JOIN hereservations hr
  ON hr.heid = a.hersrvid
LEFT JOIN hedocentries doc
  ON doc.heid = a.HEFINDENTID
WHERE a.hecstmid IN (SELECT
  heid
FROM hecustomers
WHERE hecode IN ('CH-005161'))
AND YEAR(a.hetransdate) = 2017

--Hotel Transcations στο Εμπορικό - Πωλήσεις
SELECT
  A.HECSTMID,
  hr.heresnum,
  doc.hedoccode,
  hb.herefnumber billno,
  a.hedentid,
  a.hefindentid,
  a.hedepositdentid,
  a.hedepositref,
  a.heparenttransid,
  a.heid,
  a.hetranstype,
  a.hestatus,
  a.*
FROM hehoteltransactions a
INNER JOIN hehotelbills hb
  ON hb.heid = a.hehlblid
LEFT JOIN hereservations hr
  ON hr.heid = a.hersrvid
LEFT JOIN hedocentries doc
  ON doc.heid = a.hedentid
WHERE a.hecstmid IN (SELECT
  heid
FROM hecustomers
WHERE hecode IN ('CU-016800'))
AND YEAR(a.hetransdate) = 2017

--Hotel Transcations στο Εμπορικό - Προκαταβολές
SELECT
  A.HECSTMID,
  hr.heresnum,
  doc.hedoccode,
  hb.herefnumber billno,
  a.hedentid,
  a.hefindentid,
  a.hedepositdentid,
  a.hedepositref,
  a.heparenttransid,
  a.heid,
  a.hetranstype,
  a.hestatus,
  a.*
FROM hehoteltransactions a
INNER JOIN hehotelbills hb
  ON hb.heid = a.hehlblid
LEFT JOIN hereservations hr
  ON hr.heid = a.hersrvid
LEFT JOIN hedocentries doc
  ON doc.heid = a.HEDEPOSITDENTID
WHERE a.hecstmid IN (SELECT
  heid
FROM hecustomers
WHERE hecode IN ('CU-016800'))
AND YEAR(a.hetransdate) = 2017

-- Εύρεση HotelTransaction συγκεκριμένης είσπραξης ή προκαταβολής
SELECT
  A.HEID,
  b.hecode,
  b.HENAME,
  a.*
FROM HEHOTELTRANSACTIONS a
INNER JOIN hecustomers b
  ON b.heid = a.HECSTMID
WHERE a.HEDEPOSITDENTID IN (SELECT
  HEID,
  *
FROM HEDOCENTRIES
WHERE HEDOCCODE IN ('Xenia-ΑΕν-0000000031'))
OR a.HEFINDENTID IN (SELECT
  HEID,
  *
FROM HEDOCENTRIES
WHERE HEDOCCODE IN ('Xenia-ΑΕν-0000000031'))



-- Allow modification and/or deletion of DocEntry
UPDATE HEDOCENTRIES
SET HEALLOWMODIFICATION = 1
--,HEALLOWDELETION =1
WHERE HEDOCCODE IN (
'Xenia-Απ-0000000014'
)

-- Εύρεση transperdoc συγκεκριμένου πελάτη και για συγκεκριμένο παραστατικό
-- Για όταν θέλουμε να διαγράψουμε κάποιο παραστατικό
SELECT
  B.HETRANSTYPE,
  A.HEID,
  C.HEDOCCODE,
  B.HEAMOUNT,
  A.*
FROM HETRANSPERDOC A
INNER JOIN HEHOTELTRANSACTIONS B
  ON B.HEID = A.HEHLTRID
INNER JOIN HEDOCENTRIES C
  ON C.HEID = A.HEDENTID
WHERE B.HECSTMID IN (SELECT
  HEID
FROM HECUSTOMERS
WHERE HECODE IN ('CU-012179'))
AND C.HEDOCCODE NOT LIKE 'AL%'
AND YEAR(B.HETRANSDATE) = 2017

-- Εύρεση συγκεκριμένου παραστατικού
SELECT
  HEID,
  *
FROM HEDOCENTRIES
WHERE HEDOCCODE IN (
'Astori-ΕΠρ-0000001369'
)

-- Εύρεση συγκεκριμένου HotelTransaction για συγκεκριμένη προκαταβολή ή είσπραξη
SELECT
  b.hecode,
  b.HENAME,
  a.*
FROM HEHOTELTRANSACTIONS a
INNER JOIN hecustomers b
  ON b.heid = a.HECSTMID
WHERE a.HEDEPOSITDENTID =
'791E9109-3247-E711-97CD-10604B869FF9'
OR a.HEFINDENTID =
'791E9109-3247-E711-97CD-10604B869FF9'