Arjuna Aircraft Ident.: F-MBSD | Pour résumer le bordel :
Code :
- CREATE procedure icsd_ARTAssetList
- (
- @orgid int,
- @userid int,
- @date1 datetime,
- @date2 datetime,
- @invdate1 datetime,
- @invdate2 datetime,
- @leasescheduleid int = 0,
- @leasecontractid int = 0,
- @duration int = 0,
- @brand varchar(255) = '%',
- @lineOfProduct varchar(255) = '%',
- @manufacturerRef varchar(255) = '',
- @description varchar(255) = '%',
- @category varchar(255) = '',
- @cat1 varchar(255) = '',
- @cat2 varchar(255) = '',
- @cat3 varchar(255) = '',
- @serialnumber varchar(255) = '%',
- @supplier varchar(255) = '%',
- @invoice varchar(255) = '%',
- @ref1 varchar(255) = '%',
- @ref2 varchar(255) = '%',
- @ref3 varchar(255) = '%',
- @ref4 varchar(255) = '%',
- @ref5 varchar(255) = '%',
- @assetid int = 0,
- @orderby varchar(255) = 'org'
- )
- AS
- BEGIN
- select orgid,
- name,
- leasescheduleid,
- schedule,
- -- inventory row
- -- inventory autoincrement
- manufacturerRef,
- SerialNumber,
- description,
- brand,
- lineOfProduct,
- category,
- cat1,
- cat2,
- cat3,
- supplier,
- invoice,
- invcreation,
- ref1,
- ref2,
- ref3,
- ref4,
- ref5,
- leasecontractid,
- contract,
- assetid
- from (
- select o.orgid,
- o.name,
- ls.leasescheduleid,
- ls.schedule,
- -- inventory row
- -- inventory autoincrement
- a.ProductCode manufacturerRef,
- a.SerialNumber,
- a.description,
- a.manufacture brand,
- a.brand lineOfProduct,
- zg.category,
- a.catalogType cat1,
- at1.value cat2,
- at2.value cat3,
- v.name supplier,
- zf.numero invoice,
- zf.datecreation invcreation,
- a.reference1 ref1,
- a.reference2 ref2,
- a.reference3 ref3,
- a.reference4 ref4,
- a.reference5 ref5,
- lc.leasecontractid,
- lc.contract,
- a.assetid
- from organization v, zfactures zf, zfactureasset zfa, sdViewAttributesValues at2, sdViewAttributesValues at1, zCatalogTypeGenre zg, asset a, zloyer zl, contractline cl, leasecontract lc, leaseschedule ls, zUserContractPerimeter zu, organization o, UserOrg uo
- where (uo.orgid = @orgid or @orgid = 0)
- and uo.userid = @userid
- and o.type = 'C'
- and o.active = 'A'
- and o.orgid = uo.orgid
- and zu.userid = uo.userid
- and zu.orgid = uo.orgid
- and (zu.scheduleid = @leasescheduleid or @leasescheduleid = 0)
- and ls.orgid = o.orgid
- and ls.leasescheduleid = zu.scheduleid
- and ls.active = 'A'
- and ls.userights = 1
- and lc.orgid = ls.orgid
- and lc.leasescheduleid = ls.leasescheduleid
- and (lc.leasecontractid = @leasecontractid or @leasecontractid = 0)
- and (lc.leasecontractid = zu.contractid or zu.contractid = -1)
- and lc.active = 'A'
- and (lc.leasestopdate between @date1 and @date2 or @date1 > @date2 or @date1 is null or @date2 is null)
- and (datediff(m, lc.leasestartdate, lc.leasestopdate) = @duration or @duration = 0)
- and cl.contractlineid = (select max(cl2.contractlineid)
- from contractline cl2
- where cl2.leasecontractid = lc.leasecontractid
- and cl2.active = 'A')
- and cl.active = 'A'
- and zl.leasecontractid = cl.leasecontractid
- and zl.contractlineid = cl.ContractLineID
- and a.orgid = o.orgid
- and (a.assetid = @assetid or @assetid = 0)
- and a.linetype in ('B', 'S')
- and a.assetid = zl.assetid
- and a.manufacture like '%' + @brand + '%'
- and a.brand like '%' + @lineOfProduct + '%'
- and a.description like '%' + @description + '%'
- and (a.catalogtype = @cat1 or @cat1 = '')
- and (a.productCode = @manufacturerRef or @manufacturerRef = '')
- and zg.catalogType = a.catalogType
- and zg.orgid = a.orgid
- and (zg.category = @category or @category = '')
- and at1.assetid =* a.assetid
- and at1.attributename =* zg.subcat1
- and (at1.value = @cat2 or @cat2 = '')
- and at2.assetid =* a.assetid
- and at2.attributename =* zg.subcat2
- and (at2.value = @cat3 or @cat3 = '')
- and zfa.assetid = a.assetid
- and zfa.leasescheduleid = ls.leasescheduleid
- and zfa.leasecontractid = lc.leasecontractid
- and zfa.contractlineid = cl.contractlineid
- and zf.factureid = zfa.factureid
- and zf.type = 'F'
- and a.serialNumber like '%' + @serialNumber + '%'
- and v.orgid = a.VendorOrgID
- and v.type = 'V'
- and zf.numero like '%' + @invoice + '%'
- and (zf.datecreation between @invdate1 and @invdate2 or @invdate1 > @invdate2 or @invdate1 is null or @invdate2 is null)
- and a.reference1 like '%' + @ref1 + '%'
- and a.reference2 like '%' + @ref2 + '%'
- and a.reference3 like '%' + @ref3 + '%'
- and a.reference4 like '%' + @ref4 + '%'
- and a.reference5 like '%' + @ref5 + '%'
- union all
- select o.orgid,
- o.name,
- ls.leasescheduleid,
- ls.schedule,
- -- inventory row
- -- inventory autoincrement
- a.ProductCode manufacturerRef,
- a.SerialNumber,
- a.description,
- a.manufacture brand,
- a.brand lineOfProduct,
- zg.category,
- a.catalogType cat1,
- at1.value cat2,
- at2.value cat3,
- v.name supplier,
- zf.numero invoice,
- zf.datecreation invcreation,
- a.reference1 ref1,
- a.reference2 ref2,
- a.reference3 ref3,
- a.reference4 ref4,
- a.reference5 ref5,
- lc.leasecontractid,
- lc.contract,
- a.assetid
- from organization v, zfactures zf, zfactureasset zfa, sdViewAttributesValues at2, sdViewAttributesValues at1, zCatalogTypeGenre zg, asset a, zloyer zl, contractline cl, leasecontract lc, leaseschedule ls, organization o, UserOrg uo
- where (uo.orgid = @orgid or @orgid = 0)
- and uo.userid = @userid
- and o.type = 'C'
- and o.active = 'A'
- and o.orgid = uo.orgid
- and ls.orgid = o.orgid
- and (ls.leasescheduleid = @leasescheduleid or @leasescheduleid = 0)
- and ls.active = 'A'
- and ls.userights = 0
- and lc.orgid = ls.orgid
- and lc.leasescheduleid = ls.leasescheduleid
- and lc.active = 'A'
- and (lc.leasecontractid = @leasecontractid or @leasecontractid = 0)
- and (lc.leasestopdate between @date1 and @date2 or @date1 is null or @date2 is null or @date1 > @date2)
- and (datediff(m, lc.leasestartdate, lc.leasestopdate) = @duration or @duration = 0)
- and cl.contractlineid = (select max(cl2.contractlineid)
- from contractline cl2
- where cl2.leasecontractid = lc.leasecontractid
- and cl2.active = 'A')
- and cl.active = 'A'
- and zl.leasecontractid = cl.leasecontractid
- and zl.contractlineid = cl.ContractLineID
- and a.orgid = o.orgid
- and (a.assetid = @assetid or @assetid = 0)
- and a.linetype in ('B', 'S')
- and a.assetid = zl.assetid
- and a.manufacture like '%' + @brand + '%'
- and a.brand like '%' + @lineOfProduct + '%'
- and a.description like '%' + @description + '%'
- and (a.catalogtype = @cat1 or @cat1 = '')
- and (a.productCode = @manufacturerRef or @manufacturerRef = '')
- and zg.catalogType = a.catalogType
- and zg.orgid = a.orgid
- and (zg.category = @category or @category = '')
- and at1.assetid =* a.assetid
- and at1.attributename =* zg.subcat1
- and (at1.value = @cat2 or @cat2 = '')
- and at2.assetid =* a.assetid
- and at2.attributename =* zg.subcat2
- and (at2.value = @cat3 or @cat3 = '')
- and zfa.assetid = a.assetid
- and zfa.leasescheduleid = ls.leasescheduleid
- and zfa.leasecontractid = lc.leasecontractid
- and zfa.contractlineid = cl.contractlineid
- and zf.factureid = zfa.factureid
- and zf.type = 'F'
- and a.serialNumber like '%' + @serialNumber + '%'
- and v.orgid = a.VendorOrgID
- and v.type = 'V'
- and zf.numero like '%' + @invoice + '%'
- and (zf.datecreation between @invdate1 and @invdate2 or @invdate1 > @invdate2 or @invdate1 is null or @invdate2 is null)
- and a.reference1 like '%' + @ref1 + '%'
- and a.reference2 like '%' + @ref2 + '%'
- and a.reference3 like '%' + @ref3 + '%'
- and a.reference4 like '%' + @ref4 + '%'
- and a.reference5 like '%' + @ref5 + '%'
- ) tmp
- order by case @orderby
- when 'org' then name
- when 'manufacturerRef' then manufacturerRef
- when 'SerialNumber' then SerialNumber
- when 'description' then description
- when 'brand' then brand
- when 'lineOfProduct' then lineOfProduct
- when 'category' then category
- when 'cat1' then cat1
- when 'cat2' then cat2
- when 'cat3' then cat3
- when 'supplier' then supplier
- when 'numero' then invoice
- when 'datecreation' then convert(varchar(8), invcreation, 112)
- when 'reference1' then ref1
- when 'reference2' then ref2
- when 'reference3' then ref3
- when 'reference4' then ref4
- when 'reference5' then ref5
- end, case @orderby
- when 'org' then schedule
- when 'manufacturerRef' then manufacturerRef
- when 'SerialNumber' then SerialNumber
- when 'description' then description
- when 'brand' then brand
- when 'lineOfProduct' then lineOfProduct
- when 'category' then category
- when 'cat1' then cat1
- when 'cat2' then cat2
- when 'cat3' then cat3
- when 'supplier' then supplier
- when 'numero' then invoice
- when 'datecreation' then convert(varchar(8), invcreation, 112)
- when 'reference1' then ref1
- when 'reference2' then ref2
- when 'reference3' then ref3
- when 'reference4' then ref4
- when 'reference5' then ref5
- end
- END
- GO
- -- 19 SECONDES
- NEW
- CREATE procedure icsd_ARTAssetList
- (
- @orgid int,
- @userid int,
- @date1 datetime,
- @date2 datetime,
- @invdate1 datetime,
- @invdate2 datetime,
- @leasescheduleid int = 0,
- @leasecontractid int = 0,
- @duration int = 0,
- @brand varchar(255) = '%',
- @lineOfProduct varchar(255) = '%',
- @manufacturerRef varchar(255) = '',
- @description varchar(255) = '%',
- @category varchar(255) = '',
- @cat1 varchar(255) = '',
- @cat2 varchar(255) = '',
- @cat3 varchar(255) = '',
- @serialnumber varchar(255) = '%',
- @supplier varchar(255) = '%',
- @invoice varchar(255) = '%',
- @ref1 varchar(255) = '%',
- @ref2 varchar(255) = '%',
- @ref3 varchar(255) = '%',
- @ref4 varchar(255) = '%',
- @ref5 varchar(255) = '%',
- @assetid int = 0,
- @orderby varchar(255) = 'org'
- )
- AS
- BEGIN
- select orgid,
- name,
- leasescheduleid,
- schedule,
- -- inventory row
- -- inventory autoincrement
- manufacturerRef,
- SerialNumber,
- description,
- brand,
- lineOfProduct,
- category,
- cat1,
- cat2,
- cat3,
- supplier,
- invoice,
- invcreation,
- ref1,
- ref2,
- ref3,
- ref4,
- ref5,
- leasecontractid,
- contract,
- assetid
- from (
- select o.orgid,
- o.name,
- ls.leasescheduleid,
- ls.schedule,
- -- inventory row
- -- inventory autoincrement
- a.ProductCode manufacturerRef,
- a.SerialNumber,
- a.description,
- a.manufacture brand,
- a.brand lineOfProduct,
- zg.category,
- a.catalogType cat1,
- at1.value cat2,
- at2.value cat3,
- v.name supplier,
- zf.numero invoice,
- zf.datecreation invcreation,
- a.reference1 ref1,
- a.reference2 ref2,
- a.reference3 ref3,
- a.reference4 ref4,
- a.reference5 ref5,
- lc.leasecontractid,
- lc.contract,
- a.assetid
- from organization v, zfactures zf, zfactureasset zfa, sdViewAttributesValues at2, sdViewAttributesValues at1, zCatalogTypeGenre zg, zUserContractPerimeter zu, organization o, UserOrg uo, leaseschedule ls, leasecontract lc, contractline cl, zloyer zl, asset a
- where 1 = 1
- and (a.orgid = @orgid or @orgid = 0)
- and (a.assetid = @assetid or @assetid = 0)
- and a.linetype in ('B', 'S')
- and a.manufacture like '%' + @brand + '%'
- and a.brand like '%' + @lineOfProduct + '%'
- and a.description like '%' + @description + '%'
- and (a.catalogtype = @cat1 or @cat1 = '')
- and (a.productCode = @manufacturerRef or @manufacturerRef = '')
- and a.serialNumber like '%' + @serialNumber + '%'
- and a.reference1 like '%' + @ref1 + '%'
- and a.reference2 like '%' + @ref2 + '%'
- and a.reference3 like '%' + @ref3 + '%'
- and a.reference4 like '%' + @ref4 + '%'
- and a.reference5 like '%' + @ref5 + '%'
- and (a.leasescheduleid = @leasescheduleid or @leasescheduleid = 0)
- and (a.leasecontractid = @leasecontractid or @leasecontractid = 0)
- and a.contractlineid = (select max(cl2.contractlineid)
- from contractline cl2
- where cl2.leasecontractid = a.leasecontractid
- and cl2.active = 'A')
- and zl.leasecontractid = a.leasecontractid
- and zl.contractlineid = a.ContractLineID
- and zl.assetid = a.assetid
- and cl.contractlineid = zl.contractlineid
- and cl.leasecontractid = zl.leasecontractid
- and cl.active = 'A'
- and lc.orgid = a.orgid
- and lc.leasescheduleid = a.leasescheduleid
- and lc.leasecontractid = zl.leasecontractid
- and lc.active = 'A'
- and (lc.leasestopdate between @date1 and @date2 or @date1 > @date2 or @date1 is null or @date2 is null)
- and (datediff(m, lc.leasestartdate, lc.leasestopdate) = @duration or @duration = 0)
- and ls.orgid = lc.orgid
- and ls.leasescheduleid = lc.leasescheduleid
- and ls.active = 'A'
- and ls.userights = 1
- and uo.orgid = ls.orgid
- and uo.userid = @userid
- and o.type = 'C'
- and o.active = 'A'
- and o.orgid = uo.orgid
- and zu.userid = uo.userid
- and zu.orgid = uo.orgid
- and zu.scheduleid = ls.leasescheduleid
- and (zu.contractid = lc.leasecontractid or zu.contractid = -1)
- and zg.catalogType = a.catalogType
- and zg.orgid = a.orgid
- and (zg.category = @category or @category = '')
- and at1.assetid =* a.assetid
- and at1.attributename =* zg.subcat1
- and (at1.value = @cat2 or @cat2 = '')
- and at2.assetid =* a.assetid
- and at2.attributename =* zg.subcat2
- and (at2.value = @cat3 or @cat3 = '')
- and zfa.assetid = a.assetid
- and zfa.leasescheduleid = ls.leasescheduleid
- and zfa.leasecontractid = lc.leasecontractid
- and zfa.contractlineid = cl.contractlineid
- and zf.factureid = zfa.factureid
- and zf.type = 'F'
- and v.orgid = a.VendorOrgID
- and v.type = 'V'
- and zf.numero like '%' + @invoice + '%'
- and (zf.datecreation between @invdate1 and @invdate2 or @invdate1 > @invdate2 or @invdate1 is null or @invdate2 is null)
- union all
- select o.orgid,
- o.name,
- ls.leasescheduleid,
- ls.schedule,
- -- inventory row
- -- inventory autoincrement
- a.ProductCode manufacturerRef,
- a.SerialNumber,
- a.description,
- a.manufacture brand,
- a.brand lineOfProduct,
- zg.category,
- a.catalogType cat1,
- at1.value cat2,
- at2.value cat3,
- v.name supplier,
- zf.numero invoice,
- zf.datecreation invcreation,
- a.reference1 ref1,
- a.reference2 ref2,
- a.reference3 ref3,
- a.reference4 ref4,
- a.reference5 ref5,
- lc.leasecontractid,
- lc.contract,
- a.assetid
- from organization v, zfactures zf, zfactureasset zfa, sdViewAttributesValues at2, sdViewAttributesValues at1, zCatalogTypeGenre zg, organization o, UserOrg uo, leaseschedule ls, leasecontract lc, contractline cl, zloyer zl, asset a
- where 1 = 1
- and (a.orgid = @orgid or @orgid = 0)
- and (a.assetid = @assetid or @assetid = 0)
- and a.linetype in ('B', 'S')
- and a.manufacture like '%' + @brand + '%'
- and a.brand like '%' + @lineOfProduct + '%'
- and a.description like '%' + @description + '%'
- and (a.catalogtype = @cat1 or @cat1 = '')
- and (a.productCode = @manufacturerRef or @manufacturerRef = '')
- and a.serialNumber like '%' + @serialNumber + '%'
- and a.reference1 like '%' + @ref1 + '%'
- and a.reference2 like '%' + @ref2 + '%'
- and a.reference3 like '%' + @ref3 + '%'
- and a.reference4 like '%' + @ref4 + '%'
- and a.reference5 like '%' + @ref5 + '%'
- and (a.leasescheduleid = @leasescheduleid or @leasescheduleid = 0)
- and (a.leasecontractid = @leasecontractid or @leasecontractid = 0)
- and a.contractlineid = (select max(cl2.contractlineid)
- from contractline cl2
- where cl2.leasecontractid = a.leasecontractid
- and cl2.active = 'A')
- and zl.leasecontractid = a.leasecontractid
- and zl.contractlineid = a.ContractLineID
- and zl.assetid = a.assetid
- and cl.contractlineid = zl.contractlineid
- and cl.leasecontractid = zl.leasecontractid
- and cl.active = 'A'
- and lc.orgid = a.orgid
- and lc.leasescheduleid = a.leasescheduleid
- and lc.leasecontractid = zl.leasecontractid
- and lc.active = 'A'
- and (lc.leasestopdate between @date1 and @date2 or @date1 > @date2 or @date1 is null or @date2 is null)
- and (datediff(m, lc.leasestartdate, lc.leasestopdate) = @duration or @duration = 0)
- and ls.orgid = lc.orgid
- and ls.leasescheduleid = lc.leasescheduleid
- and ls.active = 'A'
- and ls.userights = 0
- and uo.orgid = ls.orgid
- and uo.userid = @userid
- and o.type = 'C'
- and o.active = 'A'
- and o.orgid = uo.orgid
- and zg.catalogType = a.catalogType
- and zg.orgid = a.orgid
- and (zg.category = @category or @category = '')
- and at1.assetid =* a.assetid
- and at1.attributename =* zg.subcat1
- and (at1.value = @cat2 or @cat2 = '')
- and at2.assetid =* a.assetid
- and at2.attributename =* zg.subcat2
- and (at2.value = @cat3 or @cat3 = '')
- and zfa.assetid = a.assetid
- and zfa.leasescheduleid = ls.leasescheduleid
- and zfa.leasecontractid = lc.leasecontractid
- and zfa.contractlineid = cl.contractlineid
- and zf.factureid = zfa.factureid
- and zf.type = 'F'
- and v.orgid = a.VendorOrgID
- and v.type = 'V'
- and zf.numero like '%' + @invoice + '%'
- and (zf.datecreation between @invdate1 and @invdate2 or @invdate1 > @invdate2 or @invdate1 is null or @invdate2 is null)
- ) tmp
- order by case @orderby
- when 'org' then name
- when 'manufacturerRef' then manufacturerRef
- when 'SerialNumber' then SerialNumber
- when 'description' then description
- when 'brand' then brand
- when 'lineOfProduct' then lineOfProduct
- when 'category' then category
- when 'cat1' then cat1
- when 'cat2' then cat2
- when 'cat3' then cat3
- when 'supplier' then supplier
- when 'numero' then invoice
- when 'datecreation' then convert(varchar(8), invcreation, 112)
- when 'reference1' then ref1
- when 'reference2' then ref2
- when 'reference3' then ref3
- when 'reference4' then ref4
- when 'reference5' then ref5
- end, case @orderby
- when 'org' then schedule
- when 'manufacturerRef' then manufacturerRef
- when 'SerialNumber' then SerialNumber
- when 'description' then description
- when 'brand' then brand
- when 'lineOfProduct' then lineOfProduct
- when 'category' then category
- when 'cat1' then cat1
- when 'cat2' then cat2
- when 'cat3' then cat3
- when 'supplier' then supplier
- when 'numero' then invoice
- when 'datecreation' then convert(varchar(8), invcreation, 112)
- when 'reference1' then ref1
- when 'reference2' then ref2
- when 'reference3' then ref3
- when 'reference4' then ref4
- when 'reference5' then ref5
- end
- END
- GO
- -- 2 SECONDES !!!
|
|