2_verify_kontrahenci.php 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. #!/usr/bin/env php
  2. <?php
  3. //$_SERVER['SERVER_NAME'] = "biuro.biall-net.pl";
  4. //require("/Library/Server/Web/Data/Sites/Default/dev-bzyk/se-lib/bootstrap.php");
  5. require("config_inc.php"); //generated by build_BI_audit.xml
  6. #require("/Library/Server/Web/Data/Sites/SE-producition-git/SE/se-lib/bootstrap.php");
  7. date_default_timezone_set('Europe/Warsaw');// PHP 5 >= 5.1.0 required by date functions
  8. $query = "select ID, NIP, REGON, KRS from BI_audit_ENERGA_RUM_KONTRAHENCI where (NIP is null or REGON is null or KRS is null) and not (NIP is null and REGON is null and KRS is null)";
  9. $result = DB::query($query);
  10. while ($row = DB::fetch($result)) {
  11. $query = "select nip, regon, krs from BI_audit_KRS where nip = '{$row->NIP}' or regon = '{$row->REGON}' or krs = '{$row->KRS}'";
  12. if ($items = DB::getPDO()->fetchAll($query)) {
  13. list($nip, $regon, $krs) = [$items[0]["nip"], $items[0]["regon"], $items[0]["krs"]];
  14. if (count($items) > 1) {
  15. for ($i = 1; $i < count($items); $i++) {
  16. if ($nip != $items[$i]["nip"]) $nip = null;
  17. if ($regon != $items[$i]["regon"]) $regon = null;
  18. if ($krs != $items[$i]["krs"]) $krs = null;
  19. }
  20. }
  21. if (!($nip || $regon || $krs)) {
  22. echo "ERROR!\n";
  23. echo $query . "\n";
  24. } else {
  25. $set = [];
  26. if ($nip && $nip != $row->NIP) $set[] = "NIP = '{$nip}'";
  27. if ($regon && $regon != $row->REGON) $set[] = "REGON = '{$regon}'";
  28. if ($krs && $krs != $row->KRS) $set[] = "KRS = '{$krs}'";
  29. if ($set) {
  30. $query = "update BI_audit_ENERGA_RUM_KONTRAHENCI set " . implode(', ', $set) . " where ID = '{$row->ID}'";
  31. DB::query($query);
  32. echo $query . "\n";
  33. }
  34. }
  35. }
  36. }
  37. $query = "select ID, NIP, REGON from BI_audit_ENERGA_RUM_KONTRAHENCI where (NIP is null or REGON is null) and not (NIP is null and REGON is null)";
  38. $result = DB::query($query);
  39. while ($row = DB::fetch($result)) {
  40. $query = "select nip, regon from BI_audit_CEIDG where nip = '{$row->NIP}' or regon = '{$row->REGON}'";
  41. if ($items = DB::getPDO()->fetchAll($query)) {
  42. list($nip, $regon) = [$items[0]["nip"], $items[0]["regon"]];
  43. if (count($items) > 1) {
  44. for ($i = 1; $i < count($items); $i++) {
  45. if ($nip != $items[$i]["nip"]) $nip = null;
  46. if ($regon != $items[$i]["regon"]) $regon = null;
  47. }
  48. }
  49. if (!($nip || $regon)) {
  50. echo "ERROR!\n";
  51. echo $query . "\n";
  52. } else {
  53. $set = [];
  54. if ($nip && $nip != $row->NIP) $set[] = "NIP = '{$nip}'";
  55. if ($regon && $regon != $row->REGON) $set[] = "REGON = '{$regon}'";
  56. if ($set) {
  57. $query = "update BI_audit_ENERGA_RUM_KONTRAHENCI set " . implode(', ', $set) . " where ID = '{$row->ID}'";
  58. DB::query($query);
  59. echo $query . "\n";
  60. }
  61. }
  62. }
  63. }