Skip to content

Helper scripts

Ważne skrypty

  • [document].[documentOUT_conditionalyDelete] - Usuwanie zatwierdzonego dokumentu rozchodowego - jest zabezpieczony na to, żeby nie usunąć korygowaneg

Pomocne skrypty SQL

Podstawowe złaczenie - dokumenty magazynowe

SQL
select
    d.documentdate,
    d.documentFullNR,
  w.locationCode warehouseCode,
    l.locationCode,
    c.commisionFullNR,
    dl.itemQuantity,
    dl.itemQuantityLeft,
    dl.itemPrice,
  dl.sysItemPrice,
    dl.itemValue,
    dl.itemValueLeft,
    dl.sysItemValue,
    dl.sysItemValueLeft,
    d.warehouseID,
    d.documentID, -- w systemie  http://lisicki.platformacrm.pl/sales-met/documentIn/86bb2f0f-50f9-e911-8424-7ed30a52f64f
    dl.documentLineID, -- id pozycji
    dl.initialsourcedocumentLineID, -- zrodlowy documentLineID (czyli z ktorej partii pochodzi wydanie)
    i.itemName,
  dt.documentCategory --warehouse, warehouseC, warehouseH
from
    document.documentLine dl
    inner join document.document d on d.documentID =dl.documentID
  inner join wms.location w on d.warehouseID = w.locationID   --magazyn
  left join wms.location l on l.locationID  = dl.locationid   --lokacja
    inner join wms.item i on dl.itemID =i.itemID
  inner join document.documenttype dt on dt.documentType = d.documentType
    left join wms.commisionLine cl on dl.commisionLineID = cl.commisionLineID
    left join wms.commision c on c.commisionID =cl.commisionID
where
    dl.itemID  ='29994D4D-509A-EA11-80E1-9C8E994DC647'
  --and dt.baseDocumentType = 'wmm'     --typ zrodlowy pz,pzi
    and dl.status >0  -- tylko zatwierdzone pozycje
    and d.status >0   -- tylko zatwierdzone dokumenty
  and d.documentDate >= '2023-11-01'
    and d.documentDate <= '2023-11-30'
ORDER BY 
  documentDate ,   dl.signvalue * -1  ,d.documentNR 

Sortowanie

Opcja nr 1: ORDER BY documentDate , dl.signvalue * -1 ,d.documentNR Wady - nie posortuje dobrze dokumentow WM- i WM+ w tym samym dniu

Opcja nr 2: order by d.documentDate ,d.fulltextid (chyba najlepsza opcja na razie ??)

Ostatnia data i numer dokumentu wydania

  • update: 20240605
SQL
select * from (
    select
        row_number() OVER(PARTITION BY i.itemid ORDER BY d.documentdate DESC) row,
        dl.itemid,
      d.documentdate,
        d.documentFullNR
    from
        document.document d
        inner join document.documenttype dt on dt.documentType = d.documentType
      inner join document.documentline dl on d.documentid=dl.documentid
        inner join wms.item i on dl.itemid = i.itemid
    where
        dl.status >=0
      and d.status>=0
        and dt.basedocumenttype in ('rw','wz','RWCO','rwp') --wydania bez korekt,wm,mm itp
      --and d.warehouseid =@warehouseID
) x where row=1

Pierwsza cena

SQL
--pierwsza cena
select itemid,sysItemPrice from (
select
    row_number() OVER(PARTITION BY i.itemid ORDER BY d.documentdate DESC) row,
            i.itemID,
            dl.sysItemPrice
        from document.document d
            inner join document.documenttype dt on dt.documentType = d.documentType
            inner join document.documentline dl on d.documentid=dl.documentid
            inner join wms.item i on dl.itemid = i.itemid
        where
            dl.status >=0
            and d.status>=0
            and dt.baseDocumentType = 'pz' --ex. tylko pz, pzi
            and d.documentDate >=@date
) x where row=1) pierwszacena  on datasummary.itemID = pierwszacena.itemid