Files
Nuvolar/Nuvolar.Scanner.Module.CSharp/StoredProcedures.sql
T
2017-03-08 11:21:27 +01:00

678 lines
20 KiB
Transact-SQL

CREATE procedure [dbo].[DX_DeleteStorageOutRows_dxDataGrid]
@StorageOutRows uniqueidentifier
as
begin
set nocount on
set xact_abort on
declare @Ok int
declare @ErrorNumber int
exec [dbo].[sp_AddToTableD_StorageOut] @StorageOutRows=@StorageOutRows, @User=null, @Ok=@Ok output, @ErrorNumber=@ErrorNumber
end
GO
/****** Object: StoredProcedure [dbo].[DX_DeleteStoragePDACollectionRows_dxDataGrid] Script Date: 2015.11.18. 20:24:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author : Ivan.Szabo
-- Create date: 2015-09-10
-- Modified on: 2015-09-10
-- Version : 1.0.1001
-- Description: PDA kollekció sort töröl
-- =============================================
CREATE procedure [dbo].[DX_DeleteStoragePDACollectionRows_dxDataGrid]
@StoragePDACollectionRows uniqueidentifier
as
begin
set nocount on
set xact_abort on
delete from [dbo].[StoragePDACollectionRows] where Oid=@StoragePDACollectionRows
end
GO
/****** Object: StoredProcedure [dbo].[DX_GetDiscountInfo_dxDatagrid] Script Date: 2015.11.18. 20:24:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Ivan.Szabo
-- Create date: 2015-09-10
-- Modified on: 2015-09-23
-- Description: Visszatér az érvényes leértékelési sorokkal
-- =============================================
CREATE procedure [dbo].[DX_GetDiscountInfo_dxDatagrid]
@Barcode nvarchar(50),
@Result nvarchar(max) output
as
begin
declare @ResultLocal nvarchar(max)
declare @Products uniqueidentifier
declare @Oid nvarchar(50)
declare @PriceBruttoHUF nvarchar(50)
declare @ExpirationDate nvarchar(50)
select @Products=Products from pcs_whs.dbo.ProductsBarcodes where Barcode=@Barcode
if @Products is not null
begin
set @ResultLocal='['
declare CCF cursor local fast_forward for
select convert(nvarchar(50),Oid),
Barcode,
convert(nvarchar(50),round(PriceBruttoHUF,0)),
convert(nvarchar(50),ExpirationDate,111)
from PricingProductsBarcodeCustomers t1
where t1.Products=@Products and t1.Barcode like '99%' and t1.ExpirationDate>getdate()
order by t1.ActualDate desc
open CCF
fetch next from CCF into @Oid,@Barcode,@PriceBruttoHUF,@ExpirationDate
while @@FETCH_STATUS=0
begin
if @ResultLocal='['
begin
set @ResultLocal = @ResultLocal+'{ "Oid": "'+@Oid+'", "Barcode": "'+@Barcode+'", "PriceBruttoHUF": "'+@PriceBruttoHUF+'", "ExpirationDate": "'+@ExpirationDate+'" }'
end
else
begin
set @ResultLocal = @ResultLocal+',{ "Oid": "'+@Oid+'", "Barcode": "'+@Barcode+'", "PriceBruttoHUF": "'+@PriceBruttoHUF+'", "ExpirationDate": "'+@ExpirationDate+'" }'
end
fetch next from CCF into @Oid,@Barcode,@PriceBruttoHUF,@ExpirationDate
end
close CCF
deallocate CCF
set @ResultLocal = @ResultLocal+']'
end
set @Result=@ResultLocal
end
GO
/****** Object: StoredProcedure [dbo].[DX_GetProductsInfo_dxDatagrid] Script Date: 2015.11.18. 20:24:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author : Ivan.Szabo
-- Create date: 2015-09-10
-- Modified on: 2015-09-10
-- Version : 1.0.1001
-- Description: Termék információ
-- =============================================
CREATE procedure [dbo].[DX_GetProductsInfo_dxDatagrid]
@Barcode nvarchar(50),
@Result nvarchar(max) output
as
begin
set nocount on
declare @ResultLocal nvarchar(max)
declare @ProductNumber nvarchar(50)
declare @ShortName nvarchar(255)
declare @PriceBruttoHUF nvarchar(50)
declare @UnitName nvarchar(50)
declare @ActualDate nvarchar(50)
declare @ExpirationDate nvarchar(50)
declare @IsAction nvarchar(50)
declare @PricingCodeDescription nvarchar(255)
declare @QTTFree nvarchar(50)
declare @Products uniqueidentifier
set @ResultLocal='['
select top 1 @ProductNumber=t2.ProductNumber,
@Products=t2.Oid,
@ShortName=t2.ShortName,
@PriceBruttoHUF=convert(nvarchar(50),round(t1.[PriceBruttoHUF],0)),
@UnitName=t3.ShortName,
@ActualDate=replace(convert(nvarchar(10),t1.ActualDate,111),'/','-'),
@ExpirationDate=replace(convert(nvarchar(10),t1.ExpirationDate,111),'/','-'),
@IsAction=case when t1.IsAction=1 then 'Igen' else 'Nem' end,
@PricingCodeDescription=t1.PricingCodeDescription
from [dbo].[PricingProductsBarcodeCustomers] t1 join pcs_whs.dbo.Products t2 on
t1.Products=t2.Oid left join pcs_whs.dbo.Units t3 on
t2.Units=t3.Oid
where t1.Barcode=@Barcode and t1.ExpirationDate>getdate() and t1.ActualDate<getdate()
order by t1.IsAction desc,t1.ActualDate desc
if @ProductNumber is not null
begin
set @ResultLocal = @ResultLocal+'{ "Oid": "'+convert(nvarchar(50),NEWID())+'", "ShortName": "Cikkszám", "Value": "'+@ProductNumber+'" },'
set @ResultLocal = @ResultLocal+'{ "Oid": "'+convert(nvarchar(50),NEWID())+'", "ShortName": "Megnevezés", "Value": "'+@ShortName+'" },'
set @ResultLocal = @ResultLocal+'{ "Oid": "'+convert(nvarchar(50),NEWID())+'", "ShortName": "Ár", "Value": "'+@PriceBruttoHUF+'" },'
set @ResultLocal = @ResultLocal+'{ "Oid": "'+convert(nvarchar(50),NEWID())+'", "ShortName": "Érvényes (tól)", "Value": "'+@ActualDate+'" },'
set @ResultLocal = @ResultLocal+'{ "Oid": "'+convert(nvarchar(50),NEWID())+'", "ShortName": "Érvényes (ig)", "Value": "'+@ExpirationDate+'" },'
set @ResultLocal = @ResultLocal+'{ "Oid": "'+convert(nvarchar(50),NEWID())+'", "ShortName": "Akciós?", "Value": "'+@IsAction+'" },'
set @ResultLocal = @ResultLocal+'{ "Oid": "'+convert(nvarchar(50),NEWID())+'", "ShortName": "Árutasítás", "Value": "'+@PricingCodeDescription+'" },'
set @QTTFree='0.00'
select @QTTFree=convert(nvarchar(50),round(QTTFree,2))
from StorageComputed
where Products=@Products
set @ResultLocal = @ResultLocal+'{ "Oid": "'+convert(nvarchar(50),NEWID())+'", "ShortName": "Készlet", "Value": "'+@QTTFree+' / '+@UnitName+'" }'
end
else
begin
set @ResultLocal = @ResultLocal+'{ "Oid": "'+convert(nvarchar(50),NEWID())+'", "ShortName": "<NINCS>", "Value": "<NINCS>" }'
end
set @ResultLocal = @ResultLocal+']'
set @Result=@ResultLocal
end
GO
/****** Object: StoredProcedure [dbo].[DX_GetStorageInHeader_dxList] Script Date: 2015.11.18. 20:24:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Ivan.Szabo
-- Create date: 2015-09-10
-- Modified on: 2015-09-10
-- Description: Adott adatbázisban a nyitott betárolásokat hozza fel
-- =============================================
create procedure [dbo].[DX_GetStorageInHeader_dxList]
@Result nvarchar(max) output
AS
Begin
set nocount on
declare @ResultLocal nvarchar(max)
declare @DocumentNumber nvarchar(50)
declare @Oid nvarchar(50)
set @ResultLocal='['
declare CCF cursor local fast_forward for
select convert(nvarchar(50),t1.Oid),t1.DocumentNumber
from StorageInHeader t1
where t1.IsEditable=1 and t1.GCRecord is null and ltrim(rtrim(isnull(t1.DocumentNumber,'')))<>''
order by t1.DocumentNumber
open CCF
fetch next from CCF into @Oid,@DocumentNumber
while @@FETCH_STATUS=0
begin
if @ResultLocal='['
begin
set @ResultLocal = @ResultLocal+'{"key":"'+@Oid+'", "title" : "'+@DocumentNumber+'"}'
end
else
begin
set @ResultLocal = @ResultLocal+',{"key":"'+@Oid+'", "title" : "'+@DocumentNumber+'"}'
end
fetch next from CCF into @Oid,@DocumentNumber
end
close CCF
deallocate CCF
set @ResultLocal = @ResultLocal+']'
set @Result=@ResultLocal
end
GO
/****** Object: StoredProcedure [dbo].[DX_GetStorageOutHeader_dxList] Script Date: 2015.11.18. 20:24:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author : Ivan.Szabo
-- Create date: 2015-09-10
-- Modified on: 2015-09-23
-- Description: Adott adatbázisban a nyitott kitárolásokat hozza fel
-- Version : 1.0.1002
-- =============================================
CREATE procedure [dbo].[DX_GetStorageOutHeader_dxList]
@Result nvarchar(max) output
AS
Begin
set nocount on
declare @ResultLocal nvarchar(max)
declare @DocumentNumber nvarchar(50)
declare @GroupName nvarchar(50)
declare @Oid nvarchar(50)
declare @CustomerName nvarchar(50)
set @ResultLocal='['
declare CCF cursor local fast_forward for
select convert(nvarchar(50),t1.Oid),t1.DocumentNumber,
case when t2.MoveType=0 then 'É'
when t2.MoveType=3 then 'L'
when t2.MoveType=4 then 'S'
when t2.MoveType=10 then 'B'
when t2.MoveType=9 then 'V'
end,
isnull(t3.FullName,'')
from StorageOutHeader t1 join [dbo].[StorageMoveType] t2 on
t1.StorageMoveType=t2.Oid left join Organization t3 on
t1.Customers=t3.Oid
where t1.IsEditable=1 and t1.GCRecord is null and ltrim(rtrim(isnull(t1.DocumentNumber,'')))<>'' and t2.MoveType in (0,3,4,10,9)
order by t1.DocumentNumber
open CCF
fetch next from CCF into @Oid,@DocumentNumber,@GroupName,@CustomerName
while @@FETCH_STATUS=0
begin
if @ResultLocal='['
begin
set @ResultLocal = @ResultLocal+'{"key":"'+@Oid+'", "title" : "'+@DocumentNumber+'","group" : "'+@GroupName+'","customername" : "'+@CustomerName+'"}'
end
else
begin
set @ResultLocal = @ResultLocal+',{"key":"'+@Oid+'", "title" : "'+@DocumentNumber+'","group" : "'+@GroupName+'","customername" : "'+@CustomerName+'"}'
end
fetch next from CCF into @Oid,@DocumentNumber,@GroupName,@CustomerName
end
close CCF
deallocate CCF
set @ResultLocal = @ResultLocal+']'
set @Result=@ResultLocal
end
GO
/****** Object: StoredProcedure [dbo].[DX_GetStorageOutRows_dxDataGrid] Script Date: 2015.11.18. 20:24:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [dbo].[DX_GetStorageOutRows_dxDataGrid]
@StorageOutHeader uniqueidentifier,
@Result nvarchar(max) output
as
begin
set nocount on
declare @ResultLocal nvarchar(max)
declare @ShortName nvarchar(50)
declare @Oid nvarchar(50)
declare @ProductNumber nvarchar(50)
declare @QTT nvarchar(50)
declare @RowIndex nvarchar(50)
set @ResultLocal='['
declare CCF cursor local fast_forward for
select convert(nvarchar(50),t2.Oid),t3.ProductNumber,replace(t3.ShortName,'"',''''),convert(nvarchar(50),round(t2.QTT_Will,4)),convert(nvarchar(20),isnull(t2.RowIndex,-1))
from StorageOutHeader t1 right join StorageOutRows t2 on
t1.Oid=t2.StorageOutHeader left join pcs_whs.dbo.Products t3 on
t2.Products=t3.Oid
where t1.Oid=@StorageOutHeader and t2.GCRecord is null and t1.GCRecord is null
order by t2.RowIndex desc
open CCF
fetch next from CCF into @Oid,@ProductNumber,@ShortName,@QTT,@RowIndex
while @@FETCH_STATUS=0
begin
if @ResultLocal='['
begin
set @ResultLocal = @ResultLocal+'{ "Oid": "'+@Oid+'", "ProductNumber": "'+@ProductNumber+'", "ShortName": "'+@ShortName+'", "QTT": '+@QTT+',"RowIndex":'+@RowIndex+' }'
end
else
begin
set @ResultLocal = @ResultLocal+','+'{ "Oid": "'+@Oid+'", "ProductNumber": "'+@ProductNumber+'", "ShortName": "'+@ShortName+'", "QTT": '+@QTT+',"RowIndex":'+@RowIndex+' }'
end
fetch next from CCF into @Oid,@ProductNumber,@ShortName,@QTT,@RowIndex
end
close CCF
deallocate CCF
set @ResultLocal = @ResultLocal+']'
set @Result=@ResultLocal
end
GO
/****** Object: StoredProcedure [dbo].[DX_GetStoragePDACollectionHeader_dxList] Script Date: 2015.11.18. 20:24:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author : Ivan.Szabo
-- Create date: 2015-09-10
-- Modified on: 2015-09-24
-- Version : 1.0.1002
-- Description: Adott adatbázisban a nyitott PDA kollekciókat hozza fel
-- =============================================
CREATE procedure [dbo].[DX_GetStoragePDACollectionHeader_dxList]
@Result nvarchar(max) output
AS
Begin
set nocount on
declare @ResultLocal nvarchar(max)
declare @DocumentNumber nvarchar(50)
declare @Oid nvarchar(50)
set @ResultLocal='['
declare CCF cursor local fast_forward for
select convert(nvarchar(50),t1.Oid),isnull(t1.DocumentNumber,'')
from StoragePDACollectionHeader t1
where ltrim(rtrim(isnull(t1.DocumentNumber,'')))<>'' and isnull(t1.StoragePDACollectionHeaderStatus,0)=0
order by t1.DocumentNumber
open CCF
fetch next from CCF into @Oid,@DocumentNumber
while @@FETCH_STATUS=0
begin
if @ResultLocal='['
begin
set @ResultLocal = @ResultLocal+'{"key":"'+@Oid+'", "title" : "'+@DocumentNumber+'"}'
end
else
begin
set @ResultLocal = @ResultLocal+',{"key":"'+@Oid+'", "title" : "'+@DocumentNumber+'"}'
end
fetch next from CCF into @Oid,@DocumentNumber
end
close CCF
deallocate CCF
set @ResultLocal = @ResultLocal+']'
set @Result=@ResultLocal
end
GO
/****** Object: StoredProcedure [dbo].[DX_GetStoragePDACollectionRows_dxDataGrid] Script Date: 2015.11.18. 20:24:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author : Ivan.Szabo
-- Create date: 2015-09-10
-- Modified on: 2015-09-24
-- Version : 1.0.1002
-- Description: Adott adatbázisban a nyitott PDA kollekciók sorait hozza fel
-- =============================================
CREATE procedure [dbo].[DX_GetStoragePDACollectionRows_dxDataGrid]
@StoragePDACollectionHeader uniqueidentifier,
@Result nvarchar(max) output
as
begin
set nocount on
declare @ResultLocal nvarchar(max)
declare @ShortName nvarchar(50)
declare @Oid nvarchar(50)
declare @Barcode nvarchar(50)
declare @QTT nvarchar(50)
declare @RowIndex nvarchar(50)
set @ResultLocal='['
declare CCF cursor local fast_forward for
select convert(nvarchar(50),t2.Oid),isnull(t2.Barcode,''),
replace(t3.ShortName,'"',''''),
convert(nvarchar(50),round(t2.QTT,4)),
convert(nvarchar(20),isnull(t2.RowIndex,-1))
from StoragePDACollectionHeader t1 right join [StoragePDACollectionRows] t2 on
t1.Oid=t2.StoragePDACollectionHeader left join pcs_whs.dbo.Products t3 on
t2.Products=t3.Oid
where t1.Oid=@StoragePDACollectionHeader
order by t2.RowIndex desc
open CCF
fetch next from CCF into @Oid,@Barcode,@ShortName,@QTT,@RowIndex
while @@FETCH_STATUS=0
begin
if @ResultLocal='['
begin
set @ResultLocal = @ResultLocal+'{ "Oid": "'+@Oid+'", "Barcode": "'+@Barcode+'", "ShortName": "'+@ShortName+'", "QTT": '+@QTT+',"RowIndex":'+@RowIndex+' }'
end
else
begin
set @ResultLocal = @ResultLocal+','+char(13)+char(10)+'{ "Oid": "'+@Oid+'", "Barcode": "'+@Barcode+'", "ShortName": "'+@ShortName+'", "QTT": '+@QTT+',"RowIndex":'+@RowIndex+' }'
end
fetch next from CCF into @Oid,@Barcode,@ShortName,@QTT,@RowIndex
end
close CCF
deallocate CCF
set @ResultLocal = @ResultLocal+']'
set @Result=@ResultLocal
end
GO
/****** Object: StoredProcedure [dbo].[DX_InsertDiscount_dxDataGrid] Script Date: 2015.11.18. 20:24:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
CREATE procedure [dbo].[DX_InsertDiscount_dxDataGrid]
@Barcode nvarchar(50),
@PriceBruttoHUF float,
@ActualDate date,
@Expirationdate date
as
begin
set nocount on
declare @Products uniqueidentifier
declare @DiscountedBarcode nvarchar(50)
declare @NumberGenerator uniqueidentifier
declare @CustomersFrom uniqueidentifier
declare @CustomerNumber nvarchar(50)
select @Products=Products
from PricingProductsBarcodeCustomers
where Barcode=@Barcode
if @Products is not null
begin
begin tran
select top 1 @CustomerNumber=t2.CustomerNumber,@CustomersFrom=t1.Oid
from CustomersFrom t1 join Customers t2 on
t1.Oid=t2.Oid
select @NumberGenerator=Oid
from NumberGenerator
where ShortName='DISCOUNT'
exec sp_GetNewNumber @NumberGenerator=@NumberGenerator,
@YearString= null,
@MonthString= null,
@NewNumber=@DiscountedBarcode output
set @DiscountedBarcode='99'+convert(nvarchar(10),@CustomerNumber)+ Replace(@DiscountedBarcode, 'Y', '')
select @DiscountedBarcode=pcs_whs.dbo.EAN13CodeGenerator(@DiscountedBarcode)
insert PricingProductsBarcodeCustomers (Oid, Products, Barcode, Customers, PriceBruttoHUF, ExpirationDate, ActualDate, PricingCode, PricingCodeDescription,
IsAction, BarcodeType)
select NEWID(),@Products,@DiscountedBarcode,@CustomersFrom,@PriceBruttoHUF,@ExpirationDate,@ActualDate,'','DISCOUNT',
0,'AIR'
commit
end
end
GO
/****** Object: StoredProcedure [dbo].[DX_InsertStorageOutRows_dxDataGrid] Script Date: 2015.11.18. 20:24:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Ivan.Szabo
-- Create date: 2015-09-10
-- Modified on: 2015-09-21
-- Description: Kitárol egy ételt PDA-n keresztül
-- =============================================
CREATE procedure [dbo].[DX_InsertStorageOutRows_dxDataGrid]
@StorageOutHeader uniqueidentifier,
@Barcode nvarchar(50),
@QTT float,
@Result nvarchar(max) output
as
begin
set nocount on
set xact_abort on
declare @RowIndex int
declare @Products uniqueidentifier
declare @Storage uniqueidentifier
declare @Ok int
declare @ErrorNumber int
select @Storage=Storage from StorageOutHeader where Oid=@StorageOutHeader
select @Products=Products from pcs_whs.dbo.ProductsBarcodes where Barcode=@Barcode
if @Products is not null
begin
begin tran
exec [dbo].[sp_AddToTable_StorageOut] @StorageOutHeader=@StorageOutHeader,
@Storage=@Storage,
@Barcode=@Barcode,
@Products=@Products,
@QTT=@QTT, @User=null,
@Ok=@Ok output,
@ErrorNumber=@ErrorNumber output
commit
end
end
GO
/****** Object: StoredProcedure [dbo].[DX_InsertStoragePDACollectionRows_dxDataGrid] Script Date: 2015.11.18. 20:24:07 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author: Ivan.Szabo
-- Create date: 2015-09-10
-- Modified on: 2015-09-21
-- Description: PDA kollekció sorba beszúr
-- =============================================
CREATE procedure [dbo].[DX_InsertStoragePDACollectionRows_dxDataGrid]
@StoragePDACollectionHeader uniqueidentifier,
@Barcode nvarchar(50),
@QTT float,
@Result nvarchar(max) output
as
begin
set nocount on
set xact_abort on
declare @RowIndex int
if exists(select Oid from pcs_whs.[dbo].[ProductsBarcodes] where [Barcode]=@Barcode)
begin
begin tran
select @RowIndex=max(RowIndex)+1 from [StoragePDACollectionRows] where StoragePDACollectionHeader=@StoragePDACollectionHeader
if @RowIndex is null set @RowIndex=1
insert [dbo].[StoragePDACollectionRows](Oid, StoragePDACollectionHeader, Products, QTT, QTT_Processed, RowIndex, Barcode )
select NEWID(),@StoragePDACollectionHeader,t1.Products,@QTT,0,@RowIndex,@Barcode
from pcs_whs.dbo.[ProductsBarcodes] t1
where t1.Barcode=@Barcode
commit
end
end
/****** Object: StoredProcedure [dbo].[DX_GetCustomersFrom_dxSelectBox] Script Date: 2015.11.17. 23:29:22 ******/
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
-- =============================================
-- Author : Ivan.Szabo
-- Create date : 2015-09-10
-- Modified on : 2015-09-10
-- Description : pcs ... adatbázisok listája
-- =============================================
CREATE PROCEDURE [dbo].[DX_GetCustomersFrom_dxSelectBox]
@Result nvarchar(max) output
AS
begin
set nocount on
declare @SQLDatabase nvarchar(10)
declare @ResultLocal nvarchar(max)
set @ResultLocal='['
declare CCF cursor local fast_forward for
select t1.SQLDatabase
from pcs_whs.dbo.CustomersFrom t1
where t1.Active=1 and t1.IsMobile=1
order by t1.SQLDatabase
open CCF
fetch next from CCF into @SQLDatabase
while @@FETCH_STATUS=0
begin
if @ResultLocal='['
begin
set @ResultLocal = @ResultLocal+'"'+@SQLDatabase+'"'
end
else
begin
set @ResultLocal = @ResultLocal+',"'+@SQLDatabase+'"'
end
fetch next from CCF into @SQLDatabase
end
close CCF
deallocate CCF
set @ResultLocal = @ResultLocal+']'
set @Result=@ResultLocal
end