-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLibrary.sql
More file actions
320 lines (252 loc) · 8.34 KB
/
Library.sql
File metadata and controls
320 lines (252 loc) · 8.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
create database Library_db
drop database Library_db
use Library_db
update produit set qte =1000
create table produit(
id int primary key identity,
nom nvarchar(200),
categorie varchar(200),
prix float,
matiere nvarchar(200),
Nscolaire nvarchar(200),
qte int,
valeur int,
emplacement varchar(50),
imagedata image,
description varchar(300),
codebar varchar(50) unique,
remise float,
codebarStatus varchar(10) check (codebarStatus in ('scanned','generated')))
create table Fournisseur (id int primary key identity,
nom varchar(50),
email varchar(50),
adresse varchar(150),
tel varchar(15))
create table Bon_Livraison(
Nentre int primary key identity,
NBon int,
fournisseur int foreign key references fournisseur(id) ,
dateentre date,
Montant_Ht float,
montant_Tva float,
montant_TTC float,
Verification varchar(15),
CommandeId varchar(20) default 'NULL')
create Trigger trg1 on Bon_Livraison for insert as
begin
select Nentre from inserted
end
create table produit_Bon_Livraison(
facture_id int foreign key references Bon_Livraison(Nentre) not null,
produit_id int foreign key references produit(id) not null,
Unite Varchar(20),
QteEntre int,
prixunitaire float,
remise float,
tva float)
alter table produit_Bon_Livraison
add constraint pk1 primary key(facture_id,produit_id)
create table client(CIN varchar(15) primary key not null,
nom varchar(20),
prenom varchar(20),
tel varchar(12),
email varchar(50),
adresse varchar(50))
insert into Client Values('1','Normal Client','','','','')
Select cin as 'C.I.N',(nom+' '+prenom) as 'Nom',tel as 'Tel',email as 'Email',adresse as 'Adresse' from client
create table Bill(id int primary key identity not null,
client_CIN varchar(15) foreign key references client(CIN),
datesortie date,
montant float,
Status varchar(50),
montantRest float)
create Trigger trg2 on Bill for insert
as
begin
select id from inserted
end
create table Bill_products(
product_id int foreign key references produit(id) not null,
Bill_id int foreign key references Bill(id) not null,
Unite varchar(20),
quantite int,
remise int)
alter table Bill_products
add constraint pk2 primary key(product_id,Bill_id)
insert into Fournisseur values
('DAR SOULAMIAL HADITA','','',''),
('DAR IHYA EL OULOUM','','',''),
('DAR AL MASSAR','','',''),
('MEDIPAF','','',''),
('STAR SCHOOL','','',''),
('BOUBKAR','','',''),
('EDISOFT','','',''),
('ETABLISSEMENT ARRISSALA','','',''),
('FOX DISTRY','','',''),
('MAISON INTERNATIONAL DU LIVRE','','',''),
('IMARSI','','',''),
('LIBRAIRIE PAPETERIE NATIONALE','','',''),
('EDITION EL ATLASSI','','',''),
('EDITION MOUAD','','',''),
('DEVINK','','',''),
('NRG','','',''),
('LIBRAIRIE ESSALAM AL JADIDA','','',''),
('O.M.A.B','','',''),
('SICLA','','',''),
('GSB GROUPE SALHI BUSINESS','','',''),
('Ets LA RENAISSANCE SARL EDITION ET DISTRIBUTION','','',''),
('TOP BLEU BLEU','','',''),
('DAR AL OUMA SARL EDITION ET DIFFUSION','','',''),
('PAPETERIE LALLA GHITA','','',''),
('MARACI','','',''),
('TOVEL SARL','','',''),
('LIB DAR CHOUROUK','','','')
create table commande(id int identity primary key not null,
Fournisseur_id int foreign key references fournisseur(id),
datecommande date,
status varchar(25))
create Trigger trg3 on commande for insert
as
begin
select id from inserted
end
create table produit_commande(
product_id int foreign key references produit(id) not null,
commande_id int foreign key references commande(id) not null,
unite varchar(20),
quantiteDemande int,
quantiteLivrée int,
quantiteReste int)
alter table produit_commande
add constraint pk3 primary key(product_id,commande_id)
Create table Users(id int identity ,
username Varchar(50),
password Varchar(50),
nom_complet varchar(50),
email varchar(50),
account_Type varchar(50))
insert into Users values('kin1','0123','hatim rachid','hat-124@hotmail.fr','ADMIN')
create table marche(Nmarche varchar(60) primary key,
nomMarch varchar(50),
Dudate date,
addDate date,
client varchar(50),
adresse varchar(50),
objet varchar(1500))
create table marcheProduit(id int identity primary key,
Nmarche varchar(60) foreign key references marche(Nmarche),
designation nvarchar(150),
unite varchar(20),
quantite int,
prix float,
tva int)
--archive
delete from produit_Bon_LivraisonAR
delete from Bon_LivraisonAR
delete from Bill_productsAR
delete from BillAR
delete from produit_commandeAR
delete from commandeAR
select * from BillAR
drop table commandeAR
--archive Query -----------------------------------------------------
insert into Bon_LivraisonAR select Nentre,NBon,fournisseur,dateentre,Montant_Ht,montant_Tva,montant_TTC,Verification,CommandeId from Bon_Livraison where Verification like 'Verifié'
insert into produit_Bon_LivraisonAR select * from produit_Bon_Livraison where produit_Bon_Livraison.facture_id in (select facture_id from Bon_Livraison where Verification like 'Verifié')
insert into BillAR select id,client_CIN,datesortie,montant,Status,montantRest from Bill where Bill.Status='Payé'
insert into Bill_productsAR select * from Bill_products where Bill_id in (select Bill_id from Bill where Bill.Status='Payé')
insert into commandeAR select id,Fournisseur_id,datecommande,status from commande where status='Livré'
insert into produit_commandeAR select * from produit_commande where produit_commande.commande_id in (select id from commande where status='Livré')
DBCC CHECKIDENT ('Bon_Livraison', RESEED, 1)
delete from Bill_products
delete from Bill
DBCC CHECKIDENT ('Bill', RESEED, 1)
delete from produit_commande
delete from commande
DBCC CHECKIDENT ('commande', RESEED, 1)
--------------------------------------------------------------------
update produit set prix=1 where prix is null
drop table commandeAR
create table Bon_LivraisonAR(
Nentre int primary key,
NBon int,
fournisseur int foreign key references fournisseur(id) ,
dateentre date,
Montant_Ht float,
montant_Tva float,
montant_TTC float,
Verification varchar(15),
CommandeId varchar(20) default 'NULL')
create Trigger trg4 on Bon_LivraisonAR for insert as
begin
select Nentre from inserted
end
create table produit_Bon_LivraisonAR(
facture_id int foreign key references Bon_LivraisonAR(Nentre) not null,
produit_id int foreign key references produit(id) not null,
Unite Varchar(20),
QteEntre int,
prixunitaire float,
remise float,
tva float)
alter table produit_Bon_LivraisonAR
add constraint pk4 primary key(facture_id,produit_id)
create table BillAR(id int primary key not null,
client_CIN varchar(15) foreign key references client(CIN),
datesortie date,
montant float,
Status varchar(50),
montantRest float)
create Trigger trg5 on BillAR for insert
as
begin
select id from inserted
end
create table Bill_productsAR(
product_id int foreign key references produit(id) not null,
Bill_id int foreign key references BillAR(id) not null,
Unite varchar(20),
quantite int,
remise int)
alter table Bill_productsAR
add constraint pk5 primary key(product_id,Bill_id)
create table commandeAR(id int primary key not null,
Fournisseur_id int foreign key references fournisseur(id),
datecommande date,
status varchar(25))
create Trigger trg6 on commandeAR for insert
as
begin
select id from inserted
end
create table produit_commandeAR(
product_id int foreign key references produit(id) not null,
commande_id int foreign key references commandeAR(id) not null,
unite varchar(20),
quantiteDemande int,
quantiteLivrée int,
quantiteReste int)
alter table produit_commandeAR
add constraint pk6 primary key(product_id,commande_id)
----------------------------------------------------------log----------------------------------------------
create table DB_LOG(
log_id int,
log_description varchar(50),
log_type varchar(30),
log_date date,
log_time varchar(10),
log_reference_id varchar(15))
drop table DB_LOG
select * from BillAR
delete from Bon_LivraisonAR
select top 1 Nscolaire from produit
inner join Bill_products on product_id = id
group by Nscolaire
order by count(*) desc
select id,nom,categorie,matiere,Nscolaire,prix,qte,valeur from produit+
select COUNT(*) from Bill where datesortie=CONVERT(date, getdate());
select CONVERT(date, getdate()),* from Bill
select sum(Bill.montant) from Bill where Bill.datesortie=CONVERT(date, getdate())
insert into produit select Désignation,Catégorie,Prix,Matiére,Niveau_Scolaire,qte,valuer,eplacement,NULL,description,codebar,10,'generated' from ImportedProducts
select * from ImportedProducts
select * from produit
update produit set prix=50 where prix is null