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
| <?php
fortiz@lacorona.com.mx
function satxwalm($nufa, $data) {
require_once("dbi/clfactur.class.php");
require_once("dbi/clflinea.class.php");
require_once("dbi/clbodega.class.php");
require_once("dbi/clclient.class.php");
require_once("dbi/clproduc.class.php");
require_once "lib/numealet.php";
require_once "lib/getfolio.php";
global $conn;
error_reporting(E_ALL);
$edidata = "";
$dc1 = "'";
$dc2 = "'";
$fact = new Clfactur($conn,$nufa);
$clie = new Clclient($conn,(int)$fact->row["factnucl"],"renglon");
$nuca = $clie->row["clienuca"];
if ($nuca==18 || $nuca==33 || $nuca==35 || $nuca==36 || $nuca==37) $ok=true;
else die ("NO es factura de walmart!");
$bode = new Clbodega($conn,(int)$fact->row["factnubo"],'renglon');
$g_auto = $data['noAprobacion'];
$g_c_prod = 0; $g_t_seg = 0;
$g_ref_num = $conn->getOne("select fedifoli from cfdwalmart where fedinufa = '$nufa'");
if (!$g_ref_num) $g_ref_num = getfolio("cte",6,"SATXINVO",11);
$edidata .= "UNA:+.?".$dc1;
$fech = date("ymd");
$hora = date("Hi");
$edidata .= "UNB+UNOB:1+JABON-CORONA:ZZ+925485MX00:8+$fech:$hora+".$g_ref_num.$dc2;
$edidata .= "UNG+INVOIC+JABON-CORONA:ZZ+925485MX00:8+$fech:$hora+".$g_ref_num."+UN+D:01B:AMC002".$dc2;
$edidata .= "UNH+".$g_ref_num."+INVOIC:D:01B:UN:AMC002".$dc2;
$edidata .= "BGM+380+".trim(substr($fact->row["factnufa"],4))."+9".$dc2;
$edidata .= "DTM+137:".iso_fech($fact->row["factfdoc"]). ":204".$dc2;
$edidata .= "FTX+ZZZ+++".satxwalm_fix(numealet($fact->row["factimto"]),512).$dc2;
$npec = trim($fact->row["factnpec"]);
if (strlen($npec)>10) {
$npec = str_replace(array('*','"',"'","=",'-'),"",$npec);
echo "replace=$npec ";
if (strlen($npec)>10) $npec = substr($npec,1);
echo "sin=$npec ";
if (strlen($npec)>10) $npec = substr(0,10);
echo "sale=$npec ";
}
$cant = $conn->getOne("select count(*) from clflinea, clproduc where faliprod = prodprod and falinufa = '$nufa' and prodtico = 0");
if ($cant == 0) {
$edidata .= "RFF+ON:".$npec.$dc2;
$edidata .= "DTM+171:".edi_fech($fact->row["factfpec"]).":102".$dc2;
} else {
$folio_numero = $fact->row['factreci'];
$folio_fecha = $fact->row['factrfec'];
$edidata .= "RFF+DQ:".$folio_numero.$dc2;
$edidata .= "DTM+171:".edi_fech($folio_fecha).":102".$dc2;
}
$edidata .= "RFF+BT:".trim(substr($fact->row["factnufa"],0,4)).$dc2;
$edidata .= "RFF+ATZ:".$g_auto.$dc2;
$edidata .= "NAD+BY+7507003100001::9++NUEVA WAL MART DE MEXICO S DE RL DE:CV+".
"NEXTENGO NO 78:SANTA CRUZ ACAYUCAN+AZCAPOTZALCO+DF+02770".$dc2;
$edidata .= "RFF+GN:NWM9709244W4".$dc2;
$edidata .= "NAD+SU+7504000065005::9++FABRICA DE JABON LA CORONA,SA DE CV+".
"CARLOS B ZETINA NO 80+FRACC IND XALOSTOC+MC+55348".$dc2;
$edidata .= "RFF+GN:FJC780315E91".$dc2;
$eancode = "";
$prov = "";
$ordc = $conn->getRow("select * from ediordcom where ordcnpec matches '*".$npec."*'");
if (isset($ordc["ordcnpec"])) {
$prov = $ordc["ordcprov"];
$eancode = $ordc["ordcgln"];
} else {
echo "sin ediordcom";
$obs4 = $fact->row["factobs4"];
$eancode = substr($obs4,20);
$prov = (substr($obs4,0,10)=="PROVEEDOR:") ? substr($obs4,10,9) : "";
if (!$prov) $prov = ($clie->row["clienuca"] == 33) ? "227412640" : "172042132";
}
if ($eancode=="") $eancode = "7507003163884";
if ($prov=="") $prov = "000";
$edidata .= "RFF+IA:".$prov.$dc2;
if ($fact->row['factcoim']==3) {
$dire = trim($bode->row["bodedirf"]);
$colo = trim($bode->row["bodecolf"]);
$pobl = trim(substr($bode->row["bodepobf"],6));
$codp = (int)substr($bode->row["bodepobf"],0,5);
} else {
$dire = trim($bode->row["bodedire"]);
$colo = trim($bode->row["bodecolo"]);
$pobl = trim(substr($bode->row["bodepobl"],6));
$codp = (int)substr($bode->row["bodepobl"],0,5);
}
$edo = edi_estado($pobl);
$edidata .= "NAD+II+7504000065005::9++FABRICA DE JABON LA CORONA,SA DE CV+".
satxwalm_fix($dire,35).":".
satxwalm_fix($colo,35)."+".
satxwalm_fix($pobl,35)."+".
satxwalm_fix($edo,3)."+".
satxwalm_fix($codp,17).$dc2;
$edidata .= "NAD+ST+".$eancode."::9++".satxwalm_fix($clie->row["clienone"]).":".
satxwalm_fix($clie->row["clienopr"],35)."+".
satxwalm_fix($clie->row["cliedire"],35).":".
satxwalm_fix($clie->row["cliecolo"],35)."+".
satxwalm_fix($clie->getPueb("cliecoes","cliemuni","cliepueb"),35)."+".
satxwalm_fix($clie->getrefe("cte",6,"FACTCOES","cliecoes",49,2),3)."+".
satxwalm_fix($clie->row["cliecodp"],17).$dc2;
$edidata .= "CUX+2:MXN:4++1".$dc2;
$edidata .= "PAT+1++5:3:D:30".$dc2;
$edidata .= "PCD+12:0".$dc2;
$g_t_seg += 18;
$fali = new Clflinea($conn, $nufa);
for ($i=0; $i<sizeof($fali->faliprod); $i++) {
$nupr = (int)$fali->faliprod[$i];
$prod = new Clproduc($conn, $nupr,'renglon');
$g_c_prod++;
$upc = "";
if (isset($ordc['ordcnpec'])) {
$upc = $conn->getOne("select ordcupc from ediordcom where ordcprod = $nupr and ordcnpec = '".$ordc["ordcnpec"]."'");
if ($upc=="") {
$upc = $conn->getOne("select ordcupc
from clproduc a, clproduc b, ediordcom
where a.prodprod = $nupr
and a.prodagru = b.prodagru
and b.prodprod = ordcprod
and ordcnpec = '".$ordc["ordcnpec"]."'");
}
}
if ($upc=="") $upc = $prod->row["prodea13"];
$edidata .= "LIN+".$g_c_prod."++".trim($upc).":SRV::9".$dc2;
$edidata .= "PIA+1+".$prod->row["prodprod"].":SA".$dc2;
$edidata .= "IMD+F++:::".trim($prod->row["proddeco"]).$dc2;
$unif = (float)$fali->faliunif[$i]; if ($unif==0) $unif=1;
$edidata .= "QTY+47:".$unif.":CA".$dc2;
$edidata .= "QTY+59:".$prod->row["produnca"].":EA".$dc2;
$edidata .= "MOA+203:".$fali->falineto[$i].$dc2;
$prun = (double)$fali->falineto[$i] / $unif;
$edidata .= "PRI+AAA:".$prun."::::CA".$dc2;
$edidata .= "TAX+7+VAT+++:::".$fali->falipoim[$i].$dc2;
$edidata .= "MOA+124:".$fali->faliimpu[$i].$dc2;
$g_t_seg += 9;
}
$edidata .= "UNS+S".$dc2;
$edidata .= "CNT+11:".$fact->row["facttoun"].$dc2;
$edidata .= "CNT+2:".$g_c_prod.$dc2;
$edidata .= "MOA+9:".$fact->row["factimto"].$dc2;
$edidata .= "MOA+79:".($fact->row["factneto"]+$fact->row["factnet2"]).$dc2;
$edidata .= "MOA+125:".($fact->row["factneto"]+$fact->row["factnet2"]).$dc2;
$edidata .= "TAX+7+VAT+++:::".$fact->row["factpoim"].$dc2;
$edidata .= "MOA+124:".$fact->row["factimpu"].$dc2;
$g_t_seg += 9;
$edidata .= "UNT+".$g_t_seg."+".$g_ref_num.$dc2;
$edidata .= "UNE+4+".$g_ref_num.$dc2;
$edidata .= "UNZ+1+".$g_ref_num.$dc2;
$ret=$conn->replace("cfdwalmart",array("fedinufa"=>$nufa,"fedifoli"=>$g_ref_num,"fediaper"=>null,"fedicont"=>null),
"fedinufa",true);
return($edidata);
}
function edi_fech($fech) {
return ("20".substr($fech,6,2).substr($fech,3,2).substr($fech,0,2));
}
function iso_fech($fech) {
return (str_replace(array(":","-"," "),"",$fech));
}
function edi_estado($esta) {
$coes="XX";
if (stristr($esta,"AGUAS")) $coes="AS";
if (stristr($esta,"MEXICALI")) $coes="BC";
if (stristr($esta,"B.C.S.")) $coes="BS";
if (stristr($esta,"CAMPE")) $coes="CC";
if (stristr($esta,"TUXTLA")) $coes="CS";
if (stristr($esta,"TAPACHULA")) $coes="CS";
if (stristr($esta,"CHIHUHUA")) $coes="CH";
if (stristr($esta,"COAH")) $coes="CL";
if (stristr($esta,"COLIMA")) $coes="CM";
if (stristr($esta,"D.F.")) $coes="DF";
if (stristr($esta,"DURANGO")) $coes="DG";
if (stristr($esta,"IRAPUATO")) $coes="GT";
if (stristr($esta,"ACAPULCO")) $coes="GR";
if (stristr($esta,"HIDALGO")) $coes="HG";
if (stristr($esta,"GUADALAJARA")) $coes="JC";
if (stristr($esta,"XALOSTOC")) $coes="MC";
if (stristr($esta,"MORELIA")) $coes="MN";
if (stristr($esta,"MORELOS")) $coes="MS";
if (stristr($esta,"NAYARIT")) $coes="NT";
if (stristr($esta,"GARZA")) $coes="NL";
if (stristr($esta,"OAX")) $coes="OC";
if (stristr($esta,"PUEBLA")) $coes="PL";
if (stristr($esta,"QUERETARO")) $coes="QT";
if (stristr($esta,"QUINTANA")) $coes="QR";
if (stristr($esta,"SAN LUIS")) $coes="SP";
if (stristr($esta,"CULIACAN")) $coes="SL";
if (stristr($esta,"HERMOSILLO")) $coes="SR";
if (stristr($esta,"VILLAHERMOSA")) $coes="TC";
if (stristr($esta,"ALTAMIRA")) $coes="TS";
if (stristr($esta,"TLAXCALA")) $coes="TL";
if (stristr($esta,"CORDOBA")) $coes="VZ";
if (stristr($esta,"UMAN")) $coes="YN";
if (stristr($esta,"ZACATECAS")) $coes="ZS";
return ($coes);
}
function satxwalm_fix($str,$largo=-1) {
$tmp = trim($str);
for ($i=0;$i<strlen($tmp);$i++) {
$a = ord($tmp{$i});
if ($a < 32 || $a > 127) $tmp{$i} = "?";
}
$tmp = str_replace(array(":","+","|","'")," ",$tmp);
if ($largo>0) $tmp = substr($tmp,0,$largo-1);
return ($tmp);
}
?> |