PageRenderTime 45ms CodeModel.GetById 11ms RepoModel.GetById 0ms app.codeStats 0ms

/db_vistaReservesSZ.php

https://gitlab.com/vado/scadi
PHP | 1058 lines | 939 code | 69 blank | 50 comment | 87 complexity | 71defa482ca68d91602c6f6c47410126 MD5 | raw file
  1. <?php
  2. //------------------------------------------------------------------------------
  3. function db_getReservesZona($zona,$db)
  4. {
  5. global $mPars,
  6. $mProductes,
  7. $mRebostsRef,
  8. $mReservesComandes,
  9. $jaEntregatTkg,
  10. $jaEntregatTuts,
  11. $mRecepcions,
  12. $sz,
  13. $mParametres,
  14. $mPerfilsRef,
  15. $mGrupsZones,
  16. $mProductesJaEntregats;
  17. $mReservesProductes=array();
  18. $puntsEntregaZona='';
  19. $grupsPuntsEntregaZona='';
  20. if($zona!='')
  21. {
  22. //get grups dins zona
  23. if(!$result=mysql_query("select ref from rebosts_".$mPars['selRutaSufix']." WHERE LOCATE('".$zona.",',categoria)>0",$db))
  24. {
  25. //echo "<br> 17 db_vistaReserves.php ".mysql_errno() . ": " . mysql_error(). "\n";
  26. //err__('DB/*19.1*/',mysql_errno().'--'.mysql_error(),'102','db.php');
  27. }
  28. else
  29. {
  30. $i=0;
  31. while($mRow=mysql_fetch_array($result,MYSQL_ASSOC))
  32. {
  33. $puntsEntregaZona.=','.$mRow['ref'].',';
  34. }
  35. }
  36. }
  37. else
  38. {
  39. $zona='totes';
  40. //get grups dins zona
  41. if(!$result=mysql_query("select ref from rebosts_".$mPars['selRutaSufix'],$db))
  42. {
  43. //echo "<br> 34 db_vistaReserves.php ".mysql_errno() . ": " . mysql_error(). "\n";
  44. //err__('DB/*19.1*/',mysql_errno().'--'.mysql_error(),'102','db.php');
  45. }
  46. else
  47. {
  48. $i=0;
  49. while($mRow=mysql_fetch_array($result,MYSQL_ASSOC))
  50. {
  51. $puntsEntregaZona.=','.$mRow['ref'].',';
  52. }
  53. }
  54. }
  55. $puntsEntregaZona=str_replace(',,',',',$puntsEntregaZona);
  56. //get grups amb punts entrega en els grups anteriors
  57. if(!$result=mysql_query("select rebost,punt_entrega from comandes_".$mPars['selRutaSufix']." where LOCATE(CONCAT(',',punt_entrega,','),CONCAT(' ','".$puntsEntregaZona."'))>0",$db))
  58. {
  59. //echo "<br> 54 db_vistaReserves.php ".mysql_errno() . ": " . mysql_error(). "\n";
  60. //err__('DB/*19.1*/',mysql_errno().'--'.mysql_error(),'102','db.php');
  61. }
  62. else
  63. {
  64. $i=0;
  65. while($mRow=mysql_fetch_array($result,MYSQL_ASSOC))
  66. {
  67. $grupId=substr($mRow['rebost'],0,strpos($mRow['rebost'],'-'));
  68. $grupsPuntsEntregaZona.=','.$grupId.',';
  69. $mComandesGrups[$grupId]['punt_entrega']=$mRow['punt_entrega'];
  70. }
  71. }
  72. $grupsPuntsEntregaZona=str_replace(',,',',',$grupsPuntsEntregaZona);
  73. //getComandes dels usuaris dels grups dels puntsentrega dins zona
  74. $do=true;
  75. if(!$result=mysql_query("select * from comandes_".$mPars['selRutaSufix']." where LOCATE(CONCAT(',',SUBSTRING_INDEX(rebost,'-',1),','),CONCAT(' ','".$grupsPuntsEntregaZona."'))>0 AND usuari_id!=0",$db))
  76. {
  77. //echo "<br> 70 db_vistaReserves.php ".mysql_errno() . ": " . mysql_error(). "\n";
  78. //err__('DB/*19.1*/',mysql_errno().'--'.mysql_error(),'102','db.php');
  79. }
  80. else
  81. {
  82. $i=0;
  83. while($mRow=mysql_fetch_array($result,MYSQL_ASSOC))
  84. {
  85. $grupId=substr($mRow['rebost'],0,strpos($mRow['rebost'],'-'));
  86. $do=true;
  87. if(!isset($mReservesComandes[$zona]))
  88. {
  89. $mReservesComandes[$zona]=array();
  90. }
  91. if(!isset($mReservesComandes[$zona][$mComandesGrups[$grupId]['punt_entrega']]))
  92. {
  93. $mReservesComandes[$zona][$mComandesGrups[$grupId]['punt_entrega']]=array();
  94. }
  95. if(!isset($mReservesComandes[$zona][$mComandesGrups[$grupId]['punt_entrega']][$grupId][$mRow['usuari_id']]))
  96. {
  97. $mReservesComandes[$zona][$mComandesGrups[$grupId]['punt_entrega']][$grupId][$mRow['usuari_id']]=array();
  98. }
  99. $mReservesComandes[$zona][$mComandesGrups[$grupId]['punt_entrega']][$grupId][$mRow['usuari_id']]['resum']=$mRow['resum'];
  100. if($do)
  101. {
  102. $mComanda=explode(';',$mRow['resum']);
  103. while(list($key,$mVal)=each($mComanda))
  104. {
  105. $mIndexQuantitat=explode(':',$mVal);
  106. $index=str_replace('producte_','',$mIndexQuantitat[0]);
  107. $do2=true;
  108. if($sz!='')
  109. {
  110. if($index!='')
  111. {
  112. $productorId=substr($mProductes[$index]['productor'],0,strpos($mProductes[$index]['productor'],'-'));
  113. $superZonaProductor=getSuperZona($mPerfilsRef[$productorId]['zona']);
  114. if($superZonaProductor==$sz)
  115. {
  116. $do2=true;
  117. }
  118. else
  119. {
  120. $do2=false;
  121. }
  122. }
  123. else
  124. {
  125. $do2=false;
  126. }
  127. }
  128. else
  129. {
  130. $do2=true;
  131. }
  132. if($do2)
  133. {
  134. $quantitat=@$mIndexQuantitat[1];
  135. if($index!='')
  136. {
  137. if(array_key_exists($index,$mReservesProductes))
  138. {
  139. $mReservesProductes[$index]+=$quantitat;
  140. }
  141. else
  142. {
  143. $mReservesProductes[$index]=$quantitat;
  144. }
  145. }
  146. }
  147. }
  148. }
  149. }
  150. }
  151. if($mPars['excloureProductesJaEntregats']=='1')
  152. {
  153. while(list($index,$mVal)=each($mProductesJaEntregats))
  154. {
  155. while(list($grupId,$mVal2)=each($mVal))
  156. {
  157. //echo "<br>".$mRebostsRef[$grupId]['nom']." (".$mRebostsRef[$grupId]['categoria'].") ".$mProductes[$index]['producte']."-".$mVal2['rebut'];
  158. if(substr_count($grupsPuntsEntregaZona,','.$grupId.',')>0)
  159. {
  160. if($index!='' && isset($mReservesProductes[$index]))
  161. {
  162. $mReservesProductes[$index]-=$mVal2['rebut'];
  163. $jaEntregatTkg+=$mVal2['rebut']*$mProductes[$index]['pes'];
  164. $jaEntregatTuts+=$mVal2['rebut'];
  165. }
  166. }
  167. }
  168. }
  169. reset($mProductesJaEntregats);
  170. }
  171. //vd($jaEntregatTkg);
  172. //incorporar reserves a productes
  173. while(list($index,$mProducte)=each($mProductes))
  174. {
  175. if(isset($mReservesProductes[$index]))
  176. {
  177. $mProductes[$index]['quantitat']=$mReservesProductes[$index];
  178. }
  179. else
  180. {
  181. $mProductes[$index]['quantitat']=0;
  182. }
  183. }
  184. reset($mProductes);
  185. return;
  186. }
  187. //------------------------------------------------------------------------------
  188. function db_getComandesDesti($db)
  189. {
  190. global $mPars,
  191. $mProductes,
  192. $mRebostsRef,
  193. $mReservesComandesDesti,
  194. $jaEntregatTkg,
  195. $jaEntregatTuts,
  196. $mRecepcions,
  197. $mParametres,
  198. $mPerfilsRef,
  199. $mGrupsZones,
  200. $mPuntsEntrega;
  201. $where=' WHERE ';
  202. $mysqlChain="";
  203. $zona='';
  204. $superZona='';
  205. if(isset($mPars['szDesti']) && $mPars['szDesti']!='')
  206. {
  207. $superZona=$mPars['szDesti'];
  208. $mysqlChain.=' (';
  209. while(list($key,$zona)=each($mGrupsZones[$mPars['szDesti']]))
  210. {
  211. $mysqlChain.=" LOCATE('".$zona.",',categoria)>0 OR ";
  212. }
  213. reset($mGrupsZones[$mPars['szDesti']]);
  214. $mysqlChain=substr($mysqlChain,0,strlen($mysqlChain)-3).')';
  215. }
  216. else if(isset($mPars['zDesti']) && $mPars['zDesti']!='')
  217. {
  218. $superZona=getSuperZona($mPars['zDesti']);
  219. $zona=$mPars['zDesti'];
  220. $mysqlChain.=' ';
  221. while(list($key,$zona_)=each($mGrupsZones[$superZona]))
  222. {
  223. if($zona_==$mPars['zDesti'])
  224. {
  225. $mysqlChain.=" LOCATE('".$zona_.",',categoria)>0 ";
  226. }
  227. }
  228. reset($mGrupsZones[$superZona]);
  229. }
  230. else if(isset($mPars['grupDesti']) && $mPars['grupDesti']!='')
  231. {
  232. $zona=db_getZonaGrup($mPars['grupDesti'],$db);
  233. $superZona=getSuperZona($zona);
  234. $mysqlChain.=' ';
  235. while(list($pe,$mPuntEntrega)=each($mPuntsEntrega))
  236. {
  237. if($pe==$mPars['grupDesti'])
  238. {
  239. $mysqlChain.=" id='".$pe."' ";
  240. }
  241. }
  242. reset($mPuntsEntrega);
  243. }
  244. else
  245. {
  246. $where='';
  247. $mysqlChain.="";
  248. }
  249. $mReservesProductes=array();
  250. $puntsEntrega='';
  251. $grupsPuntsEntrega='';
  252. //get punts entrega
  253. //echo "<br>"."select DISTINCT(ref) from rebosts_".$mPars['selRutaSufix']." ".$where." ".$mysqlChain."";
  254. if(!$result=mysql_query("select DISTINCT(id) from rebosts_".$mPars['selRutaSufix']." ".$where." ".$mysqlChain."",$db))
  255. {
  256. //echo "<br> 17 db_vistaReserves.php ".mysql_errno() . ": " . mysql_error(). "\n";
  257. //err__('DB/*19.1*/',mysql_errno().'--'.mysql_error(),'102','db.php');
  258. }
  259. else
  260. {
  261. while($mRow=mysql_fetch_array($result,MYSQL_NUM))
  262. {
  263. $puntsEntrega.=','.$mRow['0'].',';
  264. }
  265. }
  266. //get comandes dels grups amb punt d'entrega seleccionats amb punts entrega en els grups anteriors
  267. //echo "<br>select rebost,punt_entrega ".$mPars['taulaComandes']." where LOCATE(CONCAT(',',punt_entrega,','),CONCAT(' ','".$puntsEntrega."'))>0";
  268. if(!$result=mysql_query("select rebost,punt_entrega from ".$mPars['taulaComandes']." where LOCATE(CONCAT(',',punt_entrega,','),CONCAT(' ','".$puntsEntrega."'))>0",$db))
  269. {
  270. //echo "<br> 54 db_vistaReserves.php ".mysql_errno() . ": " . mysql_error(). "\n";
  271. //err__('DB/*19.1*/',mysql_errno().'--'.mysql_error(),'102','db.php');
  272. }
  273. else
  274. {
  275. $i=0;
  276. while($mRow=mysql_fetch_array($result,MYSQL_ASSOC))
  277. {
  278. $grupId=substr($mRow['rebost'],0,strpos($mRow['rebost'],'-'));
  279. $grupsPuntsEntrega.=','.$grupId.',';
  280. $mComandesGrups[$grupId]['punt_entrega']=$mRow['punt_entrega'];
  281. }
  282. }
  283. $grupsPuntsEntrega=str_replace(',,',',',$grupsPuntsEntrega);
  284. //getComandes dels usuaris dels grups dels puntsentrega dins zona
  285. //echo "select * from comandes_".$mPars['selRutaSufix']." where LOCATE(CONCAT(',',SUBSTRING_INDEX(rebost,'-',1),','),CONCAT(' ','".$grupsPuntsEntrega."'))>0 AND usuari_id!=0";
  286. if(!$result=mysql_query("select * from ".$mPars['taulaComandes']." where LOCATE(CONCAT(',',SUBSTRING_INDEX(rebost,'-',1),','),CONCAT(' ','".$grupsPuntsEntrega."'))>0 AND usuari_id!=0",$db))
  287. {
  288. //echo "<br> 70 db_vistaReserves.php ".mysql_errno() . ": " . mysql_error(). "\n";
  289. //err__('DB/*19.1*/',mysql_errno().'--'.mysql_error(),'102','db.php');
  290. }
  291. else
  292. {
  293. $i=0;
  294. while($mRow=mysql_fetch_array($result,MYSQL_ASSOC))
  295. {
  296. $grupId=substr($mRow['rebost'],0,strpos($mRow['rebost'],'-'));
  297. $puntEntregaId=db_getPuntEntrega($grupId,$db);
  298. $zona_=db_getZonaGrup($grupId,$db);
  299. $superZona_=getSuperZona($zona_);
  300. if
  301. (
  302. (
  303. (
  304. (
  305. $mPars['rc']=='1'
  306. &&
  307. $mRecepcions[$grupId]['acceptada']=='1'
  308. )
  309. ||
  310. $mPars['rc']=='-1'
  311. )
  312. &&
  313. $grupId!='62'
  314. &&
  315. $grupId!='0' && $grupId!=0
  316. &&
  317. (
  318. (
  319. @$mPars['szDesti']==''
  320. &&
  321. @$mPars['zDesti']==''
  322. &&
  323. @$mPars['grupDesti']==''
  324. )
  325. ||
  326. (
  327. @$mPars['szDesti']!=''
  328. &&
  329. @$mPars['szDesti']==$superZona_
  330. )
  331. ||
  332. (
  333. @$mPars['zDesti']!=''
  334. &&
  335. @$mPars['zDesti']==$zona_
  336. )
  337. ||
  338. (
  339. @$mPars['grupDesti']!=''
  340. &&
  341. @$mPars['grupDesti']==$puntEntregaId
  342. )
  343. )
  344. )
  345. )
  346. {
  347. $mComandesGrups[$grupId]['punt_entrega']==$puntEntregaId;
  348. if($superZona_!='' && !isset($mReservesComandesDesti[$superZona_]))
  349. {
  350. $mReservesComandesDesti[$superZona_]=array();
  351. }
  352. if($zona_!='' && !isset($mReservesComandesDesti[$superZona_][$zona_]))
  353. {
  354. $mReservesComandesDesti[$superZona_][$zona_]=array();
  355. }
  356. if($mComandesGrups[$grupId]['punt_entrega']!='' && !isset($mReservesComandesDesti[$superZona_][$zona_][$puntEntregaId]))
  357. {
  358. $mReservesComandesDesti[$superZona_][$zona_][$puntEntregaId]=array();
  359. }
  360. if($grupId!='' && !isset($mReservesComandesDesti[$superZona_][$zona_][$puntEntregaId][$grupId]))
  361. {
  362. $mReservesComandesDesti[$superZona_][$zona_][$puntEntregaId][$grupId]=array();
  363. }
  364. if($mRow['usuari_id']!='' && !isset($mReservesComandesDesti[$superZona_][$zona_][$puntEntregaId][$grupId][$mRow['usuari_id']]))
  365. {
  366. $mReservesComandesDesti[$superZona_][$zona_][$puntEntregaId][$grupId][$mRow['usuari_id']]=array();
  367. }
  368. $mReservesComandesDesti[$superZona_][$zona_][$puntEntregaId][$grupId][$mRow['usuari_id']]=$mRow;
  369. $mComanda=explode(';',$mRow['resum']);
  370. while(list($key,$mVal)=each($mComanda))
  371. {
  372. $mIndexQuantitat=explode(':',$mVal);
  373. $index=str_replace('producte_','',$mIndexQuantitat[0]);
  374. $quantitat=@$mIndexQuantitat[1];
  375. if
  376. (
  377. $index!=''
  378. )
  379. {
  380. if(array_key_exists($index,$mReservesProductes))
  381. {
  382. $mReservesProductes[$index]+=$quantitat;
  383. }
  384. else
  385. {
  386. $mReservesProductes[$index]=$quantitat;
  387. }
  388. if(!isset($mReservesComandesDesti[$superZona_][$zona_][$puntEntregaId][$grupId][$mRow['usuari_id']]['pesC']))
  389. {
  390. $mReservesComandesDesti[$superZona_][$zona_][$puntEntregaId][$grupId][$mRow['usuari_id']]['pesC']=0;
  391. }
  392. @$mReservesComandesDesti[$superZona_][$zona_][$puntEntregaId][$grupId][$mRow['usuari_id']]['pesC']+=$quantitat*$mProductes[$index]['pes'];
  393. }
  394. }
  395. reset($mComanda);
  396. }
  397. }
  398. }
  399. ksort($mReservesComandesDesti);
  400. if($mPars['excloureProductesJaEntregats']=='1')
  401. {
  402. $mProductesJaEntregats=db_getProductesJaEntregats2($db);
  403. while(list($index,$mProductesJaEntregatsPEs)=each($mProductesJaEntregats))
  404. {
  405. while(list($puntEntrega,$mProductesJaEntregatsPE)=each($mProductesJaEntregatsPEs))
  406. {
  407. while(list($grupId,$mProductesJaEntregatsGrup)=each($mProductesJaEntregatsPE))
  408. {
  409. while(list($incId,$mVal3)=each($mProductesJaEntregatsGrup))
  410. {
  411. //echo "<br>".$mRebostsRef[$grupId]['nom']." (".$mRebostsRef[$grupId]['categoria'].") ".$mProductes[$index]['producte']."-".$mVal2['rebut'];
  412. $zona_=db_getZonaGrup($puntEntrega,$db);
  413. $superZona_=getSuperZona($zona_);
  414. if(substr_count($grupsPuntsEntrega,','.$puntEntrega.',')>0)
  415. {
  416. if
  417. (
  418. $index!=''
  419. &&
  420. isset($mReservesProductes[$index])
  421. &&
  422. (
  423. (
  424. (!isset($mPars['szDesti']) || @$mPars['szDesti']=='')
  425. &&
  426. (!isset($mPars['zDesti']) || @$mPars['zDesti']=='')
  427. &&
  428. (!isset($mPars['grupDesti']) || @$mPars['grupDesti']=='')
  429. )
  430. ||
  431. (
  432. @$mPars['szDesti']!=''
  433. &&
  434. @$mPars['szDesti']==$superZona_
  435. )
  436. ||
  437. (
  438. @$mPars['zDesti']!=''
  439. &&
  440. @$mPars['zDesti']==$zona_
  441. )
  442. ||
  443. (
  444. @$mPars['grupDesti']!=''
  445. &&
  446. @$mPars['grupDesti']==$grupId
  447. )
  448. )
  449. )
  450. {
  451. if(isset($mProductes[$index]))
  452. {
  453. //$mReservesProductes[$index]-=$mVal3['rebut'];
  454. $jaEntregatTkg+=$mVal3['rebut']*$mProductes[$index]['pes'];
  455. $jaEntregatTuts+=$mVal3['rebut'];
  456. }
  457. }
  458. }
  459. }
  460. reset($mProductesJaEntregatsGrup);
  461. }
  462. reset($mProductesJaEntregatsPE);
  463. }
  464. reset($mProductesJaEntregatsPEs);
  465. }
  466. reset($mProductesJaEntregats);
  467. }
  468. //incorporar reserves a productes
  469. while(list($index,$mProducte)=each($mProductes))
  470. {
  471. if(isset($mReservesProductes[$index]))
  472. {
  473. $mProductes[$index]['quantitat']=$mReservesProductes[$index];
  474. }
  475. else
  476. {
  477. $mProductes[$index]['quantitat']=0;
  478. }
  479. }
  480. reset($mProductes);
  481. return;
  482. }
  483. //------------------------------------------------------------------------------
  484. function db_getComandesOrigen($db)
  485. {
  486. global $mPars,
  487. $mProductesOrigen,
  488. $mRebostsRef,
  489. $mReservesComandesOrigen,
  490. $jaEntregatTkg,
  491. $jaEntregatTuts,
  492. $mRecepcions,
  493. $mParametres,
  494. $mPerfilsRef,
  495. $mGrupsZones,
  496. $mPuntsEntrega,
  497. $mProductesJaEntregats;
  498. $where=' WHERE ';
  499. $mysqlChain="";
  500. $zona='';
  501. $superZona='';
  502. if(isset($mPars['szOrigen']) && $mPars['szOrigen']!='')
  503. {
  504. $superZona=$mPars['szOrigen'];
  505. $mysqlChain.=' (';
  506. while(list($key,$zona)=each($mGrupsZones[$mPars['szOrigen']]))
  507. {
  508. $mysqlChain.=" LOCATE('".$zona.",',categoria)>0 OR ";
  509. }
  510. reset($mGrupsZones[$mPars['szOrigen']]);
  511. $mysqlChain=substr($mysqlChain,0,strlen($mysqlChain)-3).')';
  512. }
  513. else if(isset($mPars['zOrigen']) && $mPars['zOrigen']!='')
  514. {
  515. $superZona=getSuperZona($mPars['zOrigen']);
  516. $zona=$mPars['zOrigen'];
  517. $mysqlChain.=' ';
  518. while(list($key,$zona_)=each($mGrupsZones[$superZona]))
  519. {
  520. if($zona_==$mPars['zOrigen'])
  521. {
  522. $mysqlChain.=" LOCATE('".$zona_.",',categoria)>0 ";
  523. }
  524. }
  525. reset($mGrupsZones[$superZona]);
  526. }
  527. else if(isset($mPars['grupOrigen']) && $mPars['grupOrigen']!='')
  528. {
  529. $zona=db_getZonaGrup($mPars['grupOrigen'],$db);
  530. $superZona=getSuperZona($zona);
  531. $mysqlChain.=' ';
  532. while(list($pe,$mPuntEntrega)=each($mPuntsEntrega))
  533. {
  534. if($pe==$mPars['grupOrigen'])
  535. {
  536. $mysqlChain.=" id='".$pe."' ";
  537. }
  538. }
  539. reset($mPuntsEntrega);
  540. }
  541. else
  542. {
  543. $where='';
  544. $mysqlChain.="";
  545. }
  546. $mReservesProductes=array();
  547. $puntsEntrega='';
  548. $grupsPuntsEntrega='';
  549. //get punts entrega
  550. //echo "<br>"."select DISTINCT(ref) from rebosts_".$mPars['selRutaSufix']." ".$where." ".$mysqlChain."";
  551. if(!$result=mysql_query("select DISTINCT(ref) from rebosts_".$mPars['selRutaSufix']." ".$where." ".$mysqlChain."",$db))
  552. {
  553. //echo "<br> 17 db_vistaReserves.php ".mysql_errno() . ": " . mysql_error(). "\n";
  554. //err__('DB/*19.1*/',mysql_errno().'--'.mysql_error(),'102','db.php');
  555. }
  556. else
  557. {
  558. while($mRow=mysql_fetch_array($result,MYSQL_NUM))
  559. {
  560. $puntsEntrega.=','.$mRow[0].',';
  561. }
  562. }
  563. //get comandes dels grups amb punt d'entrega seleccionats amb punts entrega en els grups anteriors
  564. if(!$result=mysql_query("select rebost,punt_entrega from ".$mPars['taulaComandes']." where LOCATE(CONCAT(',',punt_entrega,','),CONCAT(' ','".$puntsEntrega."'))>0",$db))
  565. {
  566. //echo "<br> 54 db_vistaReserves.php ".mysql_errno() . ": " . mysql_error(). "\n";
  567. //err__('DB/*19.1*/',mysql_errno().'--'.mysql_error(),'102','db.php');
  568. }
  569. else
  570. {
  571. $i=0;
  572. while($mRow=mysql_fetch_array($result,MYSQL_ASSOC))
  573. {
  574. $grupId=substr($mRow['rebost'],0,strpos($mRow['rebost'],'-'));
  575. $grupsPuntsEntrega.=','.$grupId.',';
  576. $mComandesGrups[$grupId]['punt_entrega']=$mRow['punt_entrega'];
  577. }
  578. }
  579. $grupsPuntsEntrega=str_replace(',,',',',$grupsPuntsEntrega);
  580. //getComandes dels usuaris dels grups dels puntsentrega dins zona
  581. $do=true;
  582. if(!$result=mysql_query("select * from ".$mPars['taulaComandes']." where LOCATE(CONCAT(',',SUBSTRING_INDEX(rebost,'-',1),','),CONCAT(' ','".$grupsPuntsEntrega."'))>0 AND usuari_id!=0",$db))
  583. {
  584. //echo "<br> 70 db_vistaReserves.php ".mysql_errno() . ": " . mysql_error(). "\n";
  585. //err__('DB/*19.1*/',mysql_errno().'--'.mysql_error(),'102','db.php');
  586. }
  587. else
  588. {
  589. $i=0;
  590. while($mRow=mysql_fetch_array($result,MYSQL_ASSOC))
  591. {
  592. $grupId=substr($mRow['rebost'],0,strpos($mRow['rebost'],'-'));
  593. $puntEntregaId=db_getPuntEntrega($grupId,$db);
  594. $zona_=db_getZonaGrup($grupId,$db);
  595. $superZona_=getSuperZona($zona_);
  596. if
  597. (
  598. (
  599. $grupId!='62'
  600. &&
  601. (
  602. (
  603. $mPars['szOrigen']==''
  604. &&
  605. $mPars['zOrigen']==''
  606. &&
  607. $mPars['grupOrigen']==''
  608. )
  609. ||
  610. (
  611. $mPars['szOrigen']!=''
  612. &&
  613. $mPars['szOrigen']==$superZona_
  614. )
  615. ||
  616. (
  617. $mPars['zOrigen']!=''
  618. &&
  619. $mPars['zOrigen']==$zona_
  620. )
  621. ||
  622. (
  623. $mPars['grupOrigen']!=''
  624. &&
  625. $mPars['grupOrigen']==$puntEntregaId
  626. )
  627. )
  628. )
  629. )
  630. {
  631. $do=true;
  632. $mComandesGrups[$grupId]['punt_entrega']==$puntEntregaId;
  633. if($superZona_!='' && !isset($mReservesComandesOrigen[$superZona_]))
  634. {
  635. $mReservesComandesOrigen[$superZona_]=array();
  636. }
  637. if($zona_!='' && !isset($mReservesComandesOrigen[$superZona_][$zona_]))
  638. {
  639. $mReservesComandesOrigen[$superZona_][$zona_]=array();
  640. }
  641. if($mComandesGrups[$grupId]['punt_entrega']!='' && !isset($mReservesComandesOrigen[$superZona_][$zona_][$puntEntregaId]))
  642. {
  643. $mReservesComandesOrigen[$superZona_][$zona_][$puntEntregaId]=array();
  644. }
  645. if($grupId!='' && !isset($mReservesComandesOrigen[$superZona_][$zona_][$puntEntregaId][$grupId]))
  646. {
  647. $mReservesComandesOrigen[$superZona_][$zona_][$puntEntregaId][$grupId]=array();
  648. }
  649. if($mRow['usuari_id']!='' && !isset($mReservesComandesOrigen[$superZona_][$zona_][$puntEntregaId][$grupId][$mRow['usuari_id']]))
  650. {
  651. $mReservesComandesOrigen[$superZona_][$zona_][$puntEntregaId][$grupId][$mRow['usuari_id']]=array();
  652. }
  653. $mReservesComandesOrigen[$superZona_][$zona_][$puntEntregaId][$grupId][$mRow['usuari_id']]=$mRow;
  654. if($do)
  655. {
  656. $mComanda=explode(';',$mRow['resum']);
  657. while(list($key,$mVal)=each($mComanda))
  658. {
  659. $mIndexQuantitat=explode(':',$mVal);
  660. $index=str_replace('producte_','',$mIndexQuantitat[0]);
  661. $quantitat=@$mIndexQuantitat[1];
  662. if
  663. (
  664. $index!=''
  665. )
  666. {
  667. if(array_key_exists($index,$mReservesProductes))
  668. {
  669. $mReservesProductes[$index]+=$quantitat;
  670. }
  671. else
  672. {
  673. $mReservesProductes[$index]=$quantitat;
  674. }
  675. if(!isset($mReservesComandesOrigen[$superZona_][$zona_][$puntEntregaId][$grupId][$mRow['usuari_id']]['pesC']))
  676. {
  677. $mReservesComandesOrigen[$superZona_][$zona_][$puntEntregaId][$grupId][$mRow['usuari_id']]['pesC']=0;
  678. }
  679. @$mReservesComandesOrigen[$superZona_][$zona_][$puntEntregaId][$grupId][$mRow['usuari_id']]['pesC']+=$quantitat*$mProductesOrigen[$index]['pes'];
  680. }
  681. }
  682. }
  683. reset($mComanda);
  684. }
  685. }
  686. }
  687. ksort($mReservesComandesOrigen);
  688. if($mPars['excloureProductesJaEntregats']=='1')
  689. {
  690. $mProductesJaEntregats=db_getProductesJaEntregats2($db);
  691. while(list($index,$mProductesJaEntregatsPEs)=each($mProductesJaEntregats))
  692. {
  693. while(list($puntEntrega,$mProductesJaEntregatsPE)=each($mProductesJaEntregatsPEs))
  694. {
  695. while(list($grupId,$mProductesJaEntregatsGrup)=each($mProductesJaEntregatsPE))
  696. {
  697. while(list($incId,$mVal3)=each($mProductesJaEntregatsGrup))
  698. {
  699. //echo "<br>".$mRebostsRef[$grupId]['nom']." (".$mRebostsRef[$grupId]['categoria'].") ".$mProductes[$index]['producte']."-".$mVal2['rebut'];
  700. $zona_=db_getZonaGrup($puntEntrega,$db);
  701. $superZona_=getSuperZona($zona_);
  702. if(substr_count($grupsPuntsEntrega,','.$puntEntrega.',')>0)
  703. {
  704. if
  705. (
  706. $index!=''
  707. &&
  708. isset($mReservesProductes[$index])
  709. &&
  710. (
  711. (
  712. $mPars['szOrigen']==''
  713. &&
  714. $mPars['zOrigen']==''
  715. &&
  716. $mPars['grupOrigen']==''
  717. )
  718. ||
  719. (
  720. $mPars['szOrigen']!=''
  721. &&
  722. $mPars['szOrigen']==$superZona_
  723. )
  724. ||
  725. (
  726. $mPars['zOrigen']!=''
  727. &&
  728. $mPars['zOrigen']==$zona_
  729. )
  730. ||
  731. (
  732. $mPars['grupOrigen']!=''
  733. &&
  734. $mPars['grupOrigen']==$grupId
  735. )
  736. )
  737. )
  738. {
  739. //$mReservesProductes[$index]-=$mVal3['rebut'];
  740. @$jaEntregatTkg+=$mVal3['rebut']*$mProductesOrigen[$index]['pes'];
  741. $jaEntregatTuts+=$mVal3['rebut'];
  742. }
  743. }
  744. }
  745. reset($mProductesJaEntregatsGrup);
  746. }
  747. reset($mProductesJaEntregatsPE);
  748. }
  749. reset($mProductesJaEntregatsPEs);
  750. }
  751. reset($mProductesJaEntregats);
  752. }
  753. //incorporar reserves a productes
  754. while(list($index,$mProducte)=each($mProductesOrigen))
  755. {
  756. if(isset($mReservesProductes[$index]))
  757. {
  758. $mProductesOrigen[$index]['quantitat']=$mReservesProductes[$index];
  759. }
  760. else
  761. {
  762. $mProductesOrigen[$index]['quantitat']=0;
  763. }
  764. }
  765. reset($mProductesOrigen);
  766. return;
  767. }
  768. //------------------------------------------------------------------------------
  769. function confirmarRecepcions($cadenaRecepcionsAConfirmar,$grupId,$db)
  770. {
  771. global $mPars,$mMissatgeAlerta;
  772. //echo "<br>"."update rebosts_".$mPars['selRutaSufix']." set recepcions=CONCAT(recepcions,',".$cadenaRecepcionsAConfirmar."') where id='".$grupId."'";
  773. if(!$result=mysql_query("update rebosts_".$mPars['selRutaSufix']." set recepcions=CONCAT(recepcions,',".$cadenaRecepcionsAConfirmar."') where id='".$grupId."'",$db))
  774. {
  775. //echo "<br> 154 db_vistaReserves.php ".mysql_errno() . ": " . mysql_error(). "\n";
  776. //err__('DB/*19.1*/',mysql_errno().'--'.mysql_error(),'102','db.php');
  777. $mMissatgeAlerta['missatge1'].="<p class='pAlertaNo4'>Atenció, no s'ha pogut acceptar la recepció del grup seleccionat. Posa't en contacte amb l'administrador</p>";
  778. $mMissatgeAlerta['result1']=false;
  779. }
  780. else
  781. {
  782. mail_recepcioAcceptada($cadenaRecepcionsAConfirmar,$grupId,$db);
  783. }
  784. return $mMissatgeAlerta;
  785. }
  786. //------------------------------------------------------------------------------
  787. function db_getReservesCSV($db)
  788. {
  789. global $mPars,$mGrupsRef,$mReservesCsv,$mReservesComandesDesti,$jaEntregatTkg,$destiText,$origenText;
  790. $dir0=getcwd();
  791. $dir="docs".$mPars['selRutaSufix'];
  792. if(!@chdir($dir))
  793. {
  794. mkdir($dir);
  795. }
  796. else
  797. {
  798. if(!chdir('reserves')){mkdir('reserves');}
  799. chdir($dir0);
  800. }
  801. @unlink("docs".$mPars['selRutaSufix']."/reserves/reserves_".$mPars['usuari_id'].".csv");
  802. if(!$fp=fopen("docs".$mPars['selRutaSufix']."/reserves/reserves_".$mPars['usuari_id'].".csv",'a'))
  803. {
  804. return false;
  805. }
  806. if($origenText=='')
  807. {
  808. $mH1=array('vista reserves de : '.$destiText);
  809. fputcsv($fp, $mH1,',','"');
  810. $mH1=array('');
  811. fputcsv($fp, $mH1,',','"');
  812. }
  813. else
  814. {
  815. $mH1=array('llista de productes que cal portar de '.(strtoupper($origenText)).' a '.(strtoupper($destiText)));
  816. fputcsv($fp, $mH1,',','"');
  817. $mH1=array('');
  818. fputcsv($fp, $mH1,',','"');
  819. }
  820. $mH1=array(date('d-m-Y H:i'));
  821. fputcsv($fp, $mH1,',','"');
  822. $mH1=array('');
  823. fputcsv($fp, $mH1,',','"');
  824. //info comandes incloses en aquesta entrega
  825. $mH1=array('COMANDES INCLOSES:');
  826. fputcsv($fp, $mH1,',','"');
  827. $mH1=array('Superzona','Zona','Punt Entrega','GRUP','Kg comanda');
  828. fputcsv($fp, $mH1,',','"');
  829. while(list($sz,$mSz)=each($mReservesComandesDesti))
  830. {
  831. while(list($z,$mZ)=each($mSz))
  832. {
  833. while(list($pe,$mPe)=each($mZ))
  834. {
  835. while(list($grupId,$mG)=each($mPe))
  836. {
  837. $pesC=0;
  838. while(list($usuariId,$mU)=each($mG))
  839. {
  840. $pesC+=@$mU['pesC'];
  841. }
  842. reset($mG);
  843. $mH1=array($sz,$z,urldecode($mGrupsRef[$pe]['nom']),urldecode($mGrupsRef[$grupId]['nom']),number_format($pesC,2,',',''));
  844. fputcsv($fp, $mH1,',','"');
  845. }
  846. reset($mPe);
  847. }
  848. reset($mZ);
  849. }
  850. reset($mSz);
  851. }
  852. reset($mReservesComandesDesti);
  853. $mH1=array('');
  854. fputcsv($fp, $mH1,',','"');
  855. if($mPars['excloureProductesJaEntregats']==1)
  856. {
  857. $mH1=array("* Mostrar els productes ja entregats a ".$destiText." (".$jaEntregatTkg." kg): NO");
  858. fputcsv($fp, $mH1,',','"');
  859. }
  860. else
  861. {
  862. $mH1=array("* Mostrar els productes ja entregats a ".$destiText." (".$jaEntregatTkg." kg): SI");
  863. fputcsv($fp, $mH1,',','"');
  864. }
  865. if($mPars['elp']==1)
  866. {
  867. $mH1=array("* Mostrar els productes que no cal portar perquè en algun magatzem de ".$destiText." hi ha estoc positiu suficient: NO");
  868. fputcsv($fp, $mH1,',','"');
  869. }
  870. else
  871. {
  872. $mH1=array("* Mostrar els productes que no cal portar perquè en algun magatzem de ".$destiText."l hi ha estoc positiu suficient: SI");
  873. fputcsv($fp, $mH1,',','"');
  874. }
  875. /*
  876. if($sz==''){$sz='(cap superZona seleccionada)';}
  877. $mH1=array("* Mostrar només els productes dels productors gestionats desde la superzona seleccionada: ".$sz);
  878. fputcsv($fp, $mH1,',','"');
  879. */
  880. $mH1=array('');
  881. fputcsv($fp, $mH1,',','"');
  882. while(list($key,$mReservaCsv)=each($mReservesCsv))
  883. {
  884. if(!fputcsv($fp, $mReservaCsv,',','"'))
  885. {
  886. return false;
  887. }
  888. }
  889. reset($mReservesCsv);
  890. fclose($fp);
  891. return;
  892. }
  893. //*v36-28-11-15 funcio
  894. //------------------------------------------------------------------------------
  895. function db_infoFullRutaDistribucioCSV($db)
  896. {
  897. global $mPars,$mInfoRutaDistribCsv,$destiText,$jaEntregatTkg;
  898. $dir0=getcwd();
  899. $dir="docs".$mPars['selRutaSufix'];
  900. if(!@chdir($dir))
  901. {
  902. mkdir($dir);
  903. }
  904. else
  905. {
  906. if(!chdir('reserves')){mkdir('reserves');}
  907. chdir($dir0);
  908. }
  909. @unlink("docs".$mPars['selRutaSufix']."/reserves/infoFullRutaDistribucio_".$mPars['usuari_id'].".csv");
  910. if(!$fp=fopen("docs".$mPars['selRutaSufix']."/reserves/infoFullRutaDistribucio_".$mPars['usuari_id'].".csv",'a'))
  911. {
  912. return false;
  913. }
  914. $mH1=array((date('d-m-Y H:i')));
  915. fputcsv($fp, $mH1,',','"');
  916. $mH1=array('');
  917. fputcsv($fp, $mH1,',','"');
  918. //info comandes incloses en aquesta entrega
  919. $mH1=array($mPars['selRutaSufix'].' INFO FULL RUTA DISTRIBUCIO:');
  920. fputcsv($fp, $mH1,',','"');
  921. $mH1=array('');
  922. fputcsv($fp, $mH1,',','"');
  923. while(list($key,$mInfoRutaDistribCsv_)=each($mInfoRutaDistribCsv))
  924. {
  925. fputcsv($fp,$mInfoRutaDistribCsv_,',','"');
  926. }
  927. reset($mInfoRutaDistribCsv);
  928. $mH1=array('');
  929. fputcsv($fp, $mH1,',','"');
  930. if($mPars['excloureProductesJaEntregats']==1)
  931. {
  932. $mH1=array("* Mostrar els productes ja entregats a ".$destiText." (".$jaEntregatTkg." kg): NO");
  933. fputcsv($fp, $mH1,',','"');
  934. }
  935. else
  936. {
  937. $mH1=array("* Mostrar els productes ja entregats a ".$destiText." (".$jaEntregatTkg." kg): SI");
  938. fputcsv($fp, $mH1,',','"');
  939. }
  940. if($mPars['elp']==1)
  941. {
  942. $mH1=array("* Mostrar els productes que no cal portar perquè en algun magatzem de ".$destiText." hi ha estoc positiu suficient: NO");
  943. fputcsv($fp, $mH1,',','"');
  944. }
  945. else
  946. {
  947. $mH1=array("* Mostrar els productes que no cal portar perquè en algun magatzem de ".$destiText."l hi ha estoc positiu suficient: SI");
  948. fputcsv($fp, $mH1,',','"');
  949. }
  950. /*
  951. if($sz==''){$sz='(cap superZona seleccionada)';}
  952. $mH1=array("* Mostrar només els productes dels productors gestionats desde la superzona seleccionada: ".$sz);
  953. fputcsv($fp, $mH1,',','"');
  954. */
  955. fclose($fp);
  956. return;
  957. }
  958. ?>