*** empty log message ***
[fa-stable.git] / includes / data_checks.inc
1 <?php
2
3 function db_has_customers()
4 {
5         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."debtors_master");
6 }
7
8 function check_db_has_customers($msg)
9 {
10         global $path_to_root;
11     if (!db_has_customers()) 
12     {
13         display_error($msg, true);
14         end_page();
15         exit;   
16     }   
17 }
18
19 function db_has_currencies()
20 {
21         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."currencies");
22 }
23
24 function check_db_has_currencies($msg)
25 {
26         global $path_to_root;
27     if (!db_has_currencies()) 
28     {
29         display_error($msg, true);
30         end_page();
31         exit;   
32     }   
33 }
34
35 function db_has_sales_types()
36 {
37         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."sales_types");
38 }
39
40 function check_db_has_sales_types($msg)
41 {
42         global $path_to_root;
43     if (!db_has_sales_types()) 
44     {
45         display_error($msg, true);
46         end_page();
47         exit;   
48     }   
49 }
50
51 function db_has_item_tax_types()
52 {
53         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."item_tax_types");
54 }
55
56 function check_db_has_item_tax_types($msg)
57 {
58         global $path_to_root;
59     if (!db_has_item_tax_types()) 
60     {
61         display_error($msg, true);
62         end_page();
63         exit;   
64     }   
65 }
66
67 function db_has_tax_types()
68 {
69         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."tax_types");
70 }
71
72 function check_db_has_tax_types($msg)
73 {
74         global $path_to_root;
75     if (!db_has_tax_types()) 
76     {
77         display_error($msg, true);
78         end_page();
79         exit;   
80     }   
81 }
82
83 function db_has_tax_groups()
84 {
85         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."tax_groups");
86 }
87
88 function check_db_has_tax_groups($msg)
89 {
90         global $path_to_root;
91     if (!db_has_tax_groups()) 
92     {
93         display_error($msg, true);
94         end_page();
95         exit;   
96     }   
97 }
98
99 function db_has_movement_types()
100 {
101         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."movement_types");
102 }
103
104 function check_db_has_movement_types($msg)
105 {
106         global $path_to_root;
107     if (!db_has_movement_types()) 
108     {
109         display_error($msg, true);
110         end_page();
111         exit;   
112     }   
113 }
114
115 function db_has_bank_trans_types()
116 {
117         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."bank_trans_types");
118 }
119
120 function check_db_has_bank_trans_types($msg)
121 {
122         global $path_to_root;
123     if (!db_has_bank_trans_types()) 
124     {
125         display_error($msg, true);
126         end_page();
127         exit;   
128     }   
129 }
130
131 function db_customer_has_branches($customer_id)
132 {
133         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."cust_branch WHERE debtor_no=$customer_id");
134 }
135
136 function db_has_customer_branches()
137 {
138         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."cust_branch");
139 }
140
141 function check_db_has_customer_branches($msg)
142 {
143         global $path_to_root;
144     if (!db_has_customer_branches()) 
145     {
146         display_error($msg, true);
147         end_page();
148         exit;   
149     }   
150 }
151
152 function db_has_sales_people()
153 {
154         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."salesman");
155 }
156
157 function check_db_has_sales_people($msg)
158 {
159         global $path_to_root;
160     if (!db_has_sales_people()) 
161     {
162         display_error($msg, true);
163         end_page();
164         exit;   
165     }   
166 }
167
168 function db_has_sales_areas()
169 {
170         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."areas");
171 }
172
173 function check_db_has_sales_areas($msg)
174 {
175         global $path_to_root;
176     if (!db_has_sales_areas()) 
177     {
178         display_error($msg, true);
179         end_page();
180         exit;   
181     }   
182 }
183
184 function db_has_shippers()
185 {
186         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."shippers");
187 }
188
189 function check_db_has_shippers($msg)
190 {
191         global $path_to_root;
192     if (!db_has_shippers()) 
193     {
194         display_error($msg, true);
195         end_page();
196         exit;   
197     }   
198 }
199
200 function db_has_open_workorders()
201 {
202         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."workorders WHERE closed=0");
203 }
204
205 function db_has_workorders()
206 {
207         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."workorders");
208 }
209
210 function check_db_has_workorders($msg)
211 {
212         global $path_to_root;
213     if (!db_has_workorders()) 
214     {
215         display_error($msg, true);
216         end_page();
217         exit;   
218     }   
219 }
220
221 function db_has_open_dimensions()
222 {
223         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."dimensions WHERE closed=0");
224 }
225
226 function db_has_dimensions()
227 {
228         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."dimensions");
229 }
230
231 function check_db_has_dimensions($msg)
232 {
233         global $path_to_root;
234     if (!db_has_dimensions()) 
235     {
236         display_error($msg, true);
237         end_page();
238         exit;   
239     }   
240 }
241
242
243 function db_has_suppliers()
244 {
245         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."suppliers");
246 }
247
248 function check_db_has_suppliers($msg)
249 {
250         global $path_to_root;
251     if (!db_has_suppliers()) 
252     {
253         display_error($msg, true);
254         end_page();
255         exit;   
256     }   
257 }
258
259 function db_has_stock_items()
260 {
261         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master");
262 }
263
264 function check_db_has_stock_items($msg)
265 {
266         global $path_to_root;
267     if (!db_has_stock_items()) 
268     {
269         display_error($msg, true);
270         end_page();
271         exit;   
272     }   
273 }
274
275 function db_has_bom_stock_items()
276 {
277         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE (mb_flag='M' OR mb_flag='K')");
278 }
279
280 function check_db_has_bom_stock_items($msg)
281 {
282         global $path_to_root;
283     if (!db_has_bom_stock_items()) 
284     {
285         display_error($msg, true);
286         end_page();
287         exit;   
288     }   
289 }
290
291 function db_has_manufacturable_items()
292 {
293         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE (mb_flag='M')");
294 }
295
296 function check_db_has_manufacturable_items($msg)
297 {
298         global $path_to_root;
299     if (!db_has_manufacturable_items()) 
300     {
301         display_error($msg, true);
302         end_page();
303         exit;   
304     }   
305 }
306
307 function db_has_purchasable_items()
308 {
309         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE (mb_flag!='M' AND mb_flag!='K')");
310 }
311
312 function check_db_has_purchasable_items($msg)
313 {
314         global $path_to_root;
315     if (!db_has_purchasable_items()) 
316     {
317         display_error($msg, true);
318         end_page();
319         exit;   
320     }   
321 }
322
323 function db_has_costable_items()
324 {
325         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_master WHERE (mb_flag!='D' AND mb_flag!='K')");
326 }
327
328 function check_db_has_costable_items($msg)
329 {
330         global $path_to_root;
331     if (!db_has_costable_items()) 
332     {
333         display_error($msg, true);
334         end_page();
335         exit;   
336     }   
337 }
338
339 function db_has_stock_categories()
340 {
341         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."stock_category");
342 }
343
344 function check_db_has_stock_categories($msg)
345 {
346         global $path_to_root;
347     if (!db_has_stock_categories()) 
348     {
349         display_error($msg, true);
350         end_page();
351         exit;   
352     }   
353 }
354
355 function db_has_workcentres()
356 {
357         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."workcentres");
358 }
359
360 function check_db_has_workcentres($msg)
361 {
362         global $path_to_root;
363     if (!db_has_workcentres()) 
364     {
365         display_error($msg, true);
366         end_page();
367         exit;   
368     }   
369 }
370
371 function db_has_locations()
372 {
373         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."locations");
374 }
375
376 function check_db_has_locations($msg)
377 {
378         global $path_to_root;
379     if (!db_has_locations()) 
380     {
381         display_error($msg, true);
382         end_page();
383         exit;   
384     }   
385 }
386
387 function db_has_bank_accounts()
388 {
389         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."bank_accounts");
390 }
391
392 function check_db_has_bank_accounts($msg)
393 {
394         global $path_to_root;
395     if (!db_has_bank_accounts()) 
396     {
397         display_error($msg, true);
398         end_page();
399         exit;   
400     }   
401 }
402
403 function db_has_gl_accounts()
404 {
405         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."chart_master");
406 }
407
408 function db_has_gl_account_groups()
409 {
410         return check_empty_result("SELECT COUNT(*) FROM ".TB_PREF."chart_types");
411 }
412
413 function check_db_has_gl_account_groups($msg)
414 {
415         global $path_to_root;
416     if (!db_has_gl_account_groups()) 
417     {
418         display_error($msg, true);
419         end_page();
420         exit;   
421     }   
422 }
423
424 function check_empty_result($sql)
425 {
426         $result = db_query($sql, "could not do check empty query");     
427         
428         $myrow = db_fetch_row($result);
429         return $myrow[0] > 0;           
430 }
431
432 ?>