-
Notifications
You must be signed in to change notification settings - Fork 0
/
functions_group_barcode.php
265 lines (165 loc) · 7.12 KB
/
functions_group_barcode.php
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
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
$PREFIX_GROUP_STICKER="GRP"; //prefix that is used to detect group barcode
function detect_group_barcode($barcode,$PREFIX_GROUP_STICKER) //first compares barcode if this is a group prefix
{
echo "detecting group0";
echo $group=strtoupper(substr($barcode,0,3));
if(strcmp($PREFIX_GROUP_STICKER,$group)==0){
echo "detected group sticker ".$group;
return 1;}
else
return 0;
}
//if group detected check if is in the system
function check_group_barcode($barcode)
{
echo $sql="SELECT * FROM group_barcode WHERE group_barcode='$barcode'";
$result=query_select($sql);
if(mysql_num_rows($result)>0)
{
echo "Group barcode in the system";
return 1;
}
else 0;
}
function check_if_sold_group($barcode)
{
echo $sql="SELECT * FROM group_barcode WHERE group_barcode='$barcode' AND details=1";
$result=query_select($sql);
if(mysql_num_rows($result)>0)
{
echo "Not yet sold";
return 1;
}
}
function if_valid_barcode($barcode)
{
$barcode2=substr($barcode,0,3);
$barcode2=strtoupper($barcode2);
if(strcmp($barcode2,'UNQ')==0 OR strcmp($barcode2,'DBS')==0 OR strcmp($barcode2,'FAU')==0)
return $barcode;
else {
return 1;
}
}
function extract_list($list)
{
//this function will clear the list a bit and organise an output format lets strip in ;
$replace=array();
$replace[0]=" ";
$replace[1]="\n";
//$list=str_replace($replace[0], ";", $list);
return $list;
}
function proccess_string_barcode() //takes list of barcodes as a string and formats, removing white spacves. Giving as result number of barcodes recognised
{
}
function initialize_group_barcode()
{
//connect_dbi();
$group_barcode=$_POST['group_sticker'];
$details='1';
$reserved=$l_klient;
echo $sql="INSERT INTO group_barcode(group_barcode,details,reserved) VALUES('$group_barcode','$details','$reserved')";//initialised by 1-ones
$result=query_select($sql);
if($result)
{
echo "Group barcode initialised";
echo var_dump($result);
echo $group_barcode_id=mysql_insert_id();
return $group_barcode_id; //after initialising we sent back only once a group barcode
}
echo var_dump($result);
}
function get_list($list)
{
$list=extract_list($list);
//return as array
$list_returned=array();
$number_of_barcodes=100;
//$list_returned=$list;
//$list_returned=implode(' ', array_slice(explode(' ', $list), 0, 1));
///$list_returned=getNWordsFromString($list);
$barcodes = explode(" ", $list);
//echo $barcodes[0];
//echo $barcodes[1];
//return the barcodes
// $list_returned=$list;
return $barcodes;
}
function set_individual_barcode($barcode,$group)
{
$barcode_individual=$barcode;
echo $group_barcode=$group;
echo $SQL="INSERT INTO barcode_individual(barcode_individual,group_barcode_idgroup_barcode) VALUES('$barcode_individual','$group_barcode')";
$result=query_select($SQL);
if($result)
{
$individual_id=mysql_insert_id(); //get last individual inser id for barcode
echo "Genereted group for barcode :".$individual_id;
}
}
function extract_group($barcode)
{
//we extract as particular group of items
$item_type=$_POST['item_type']; //take weee_extension id, means particular item
//we add here a query that will conver conversion item_type into weee cat
$sql_cnv="SELECT * FROM weee_extension WHERE idweee_extension='$item_type'";
$result_cnv=mysql_query($sql_cnv) or die(mysql_error());
$rek=mysql_fetch_array($result_cnv);
$item_type_cnv=$rek['weee_extension']; //this is id_item_cat connected to particular weee id_extension
$name_ext=$rek['name_ext']; //name_ext is a name of particular group shall be counted and also shown on invoice
//geting barcode details
$check_item_cat="SELECT * FROM item_has_cat WHERE id_item_cat='$item_type_cnv'"; //we compare weee extension with a item cat id
$result_check=mysql_query($check_item_cat)or die(mysql_error());
$rek_check=mysql_fetch_array($result_check);
$cat=$rek_check['cat']; //we pick up weight and category
$weight=$rek_check['weight'];
//end
echo $sql="SELECT * FROM group_barcode INNER JOIN barcode_individual ON group_barcode.idgroup_barcode=barcode_individual.group_barcode_idgroup_barcode WHERE group_barcode='$barcode' AND details='1' ";
$result=query_select($sql);
while($rek=mysql_fetch_array($result,MYSQL_BOTH))
{
//here a check if is already sold
if(check_if_barcode_individual_sold($rek['barcode_individual'])==0)
{
echo $rek['barcode_individual'];
//get a first barcode from barcode individual
$barcode=$rek['barcode_individual'];
//insert waste barcode
echo "</BR></BR>";
echo $insert="INSERT into waste_barcode(Barcode_waste,category,weight,type_item,stock_out,type_item_cnv,site) VALUES('$barcode','$cat','$weight','$item_type_cnv',1,'$item_type','0')";
$result1=query_select($insert);
$last_barcode=mysql_insert_id();
//transaction details
$invoice_id=$_SESSION['inv_id_generated'];
$ref_sell=$_SESSION['ref_sell_number'];
$buyer_id=$_SESSION['site_id_s_s'];
//insert transaction
$batch_date=$_SESSION['batch_date1'];
echo $transaction="INSERT INTO transaction_waste(ref_sell_number,buyer_id,finished,invoice_waste_idinvoice_waste,waste_barcode_idwaste_barcode,date_sold) VALUES('$ref_sell','$buyer_id','1','$invoice_id','$last_barcode','$batch_date')";
$result2=query_select($transaction);
echo "DONE ".$rek['barcode_individual'];
}
}
//here close status of barcode group. Set it sold 2
}
function check_if_barcode_individual_sold($barcode_individual)
{
$sql="SELECT * FROM waste_barcode WHERE Barcode_waste='$barcode_individual'";
$result=query_select($sql);
if(mysql_num_rows($result)>0)
return 1;
else return 0;
//mysql_fetch_array($result);
}
function update_group_sold($barcode)
{
$sql="UPDATE group_barcode SET details=2 WHERE group_barcode='$barcode'";
query_select($sql);
}