ParserDatabaseBruto.php 12KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285
  1. <?php
  2. defined('BASEPATH') or exit('No direct script access allowed');
  3. class ParserDatabaseBruto
  4. {
  5. protected $idLicitacion = 0;
  6. protected $fechaInicioParser = "";
  7. protected $CI;
  8. protected $nombreLog = "";
  9. public function __construct()
  10. {
  11. $this->CI = &get_instance();
  12. $this->CI->load->model("Parser_model");
  13. }
  14. public function setDatosParser($arrayDatosSucios, $fecha, $datosPerfil)
  15. {
  16. $this->fechaInicioParser = $fecha;
  17. $this->nombreLog = "setLicitacion__" . $datosPerfil->prefijos_tablas . "__" . $this->fechaInicioParser;
  18. if (!empty($arrayDatosSucios)) {
  19. foreach ($arrayDatosSucios as $nombreArchivo => $datosArchivo) {
  20. guardar_log($this->nombreLog, "ARCHIVO ---" . $nombreArchivo, false);
  21. foreach ($datosArchivo as $row) {
  22. $idLicitacion = $this->setInicioLicitacion($row['general']);
  23. if ($idLicitacion['result']) {
  24. $this->idLicitacion = $idLicitacion['id'];
  25. $this->setDatosSingular($row, "contractInfo", "BRUTO_contract_folder", $this->idLicitacion, "ContractInfo", "id_ajena_licitacion");
  26. $this->setDatosSingular($row, "tenderingProcess", "BRUTO_tendering_process", $this->idLicitacion, "TenderingProcess", "id_ajena_licitacion");
  27. $this->setProcurementProject($row['procurementProject']);
  28. $this->setProcurementProjectLot($row['procurementProjectLot']);
  29. $this->setTenderingTerms($row['tenderingTerms']);
  30. $this->setLocatedContractingParty($row['locatedContractingParty']);
  31. $this->setParty($row['party']);
  32. $this->setValidNoticeInfo($row['validNoticeInfo']);
  33. $this->setDatosMultiples($row, "tenderingResult", "BRUTO_tender_result", $this->idLicitacion, "TenderResult", "id_ajena_licitacion");
  34. $this->setDatosMultiples($row, "legalDocs", "BRUTO_legal_documents", $this->idLicitacion, "LegalDocs", 'id_ajena_licitacion');
  35. $this->setDatosMultiples($row, "technicalDocs", "BRUTO_technical_documents", $this->idLicitacion, "TechnicalDocs", "id_ajena_licitacion");
  36. $this->setDatosMultiples($row, "generalDocs", "BRUTO_general_documents", $this->idLicitacion, "GeneralDocs", "id_ajena_licitacion");
  37. $this->setDatosMultiples($row, "additionalDocs", "BRUTO_additional_documents", $this->idLicitacion, "AdditionalDocs", "id_ajena_licitacion");
  38. }
  39. }
  40. }
  41. }
  42. return;
  43. }
  44. private function setInicioLicitacion($datosInicioLicitacion): array
  45. {
  46. $result = array("result" => false, "id" => 0);
  47. $datosInicioLicitacion['fecha_creacion_log'] = $this->fechaInicioParser;
  48. $insertLicitacion = $this->CI->Parser_model->setInicioLicitacion($datosInicioLicitacion);
  49. if ($insertLicitacion) {
  50. $result = array("result" => true, "id" => $insertLicitacion);
  51. guardar_log($this->nombreLog, "Licitacion ID " . $datosInicioLicitacion['id_licitacion'] . " - BBDD Licitación ID " . $insertLicitacion, "false");
  52. } else {
  53. $result = array("result" => true, "id" => 0);
  54. guardar_log($this->nombreLog, "Licitacion ID " . $datosInicioLicitacion['id_licitacion'], "false", 2);
  55. }
  56. return $result;
  57. }
  58. private function setLocatedContractingParty($contractInfo): void
  59. {
  60. $locatedContractingPartyId = $this->setDatosSingular($contractInfo, "locatedContractingParty", "BRUTO_located_contracting_party", $this->idLicitacion, "locatedContractingParty", "id_ajena_licitacion");
  61. $this->setDatosMultiples($contractInfo, "activity", "BRUTO_located_contracting_party_activity", $locatedContractingPartyId, "locatedContractingParty_Activity", "id_ajena_lcp");
  62. }
  63. private function setParty($partyInfo): void
  64. {
  65. $partyId = $this->setDatosSingular($partyInfo, "party", "BRUTO_party", $this->idLicitacion, "PartyInfo", "id_ajena_licitacion");
  66. $this->setDatosMultiples($partyInfo, "partyIdentification", "BRUTO_party_party_idenfitication", $partyId, "PartyInfo_PartyIdentification", "id_ajena_party");
  67. }
  68. private function setProcurementProject($procurementInfo): void
  69. {
  70. $procurementProjectId = $this->setDatosSingular($procurementInfo, "budget", "BRUTO_procurement_project", $this->idLicitacion, "ProcurementProject", "id_ajena_licitacion");
  71. $this->setDatosMultiples($procurementInfo, "itemClass", "BRUTO_procurement_project_itemClass", $procurementProjectId, "ProcurementProject_ItemClass", "id_ajena_pp");
  72. }
  73. private function setProcurementProjectLot($procurementLotInfo): void
  74. {
  75. $resultInsert = 0;
  76. if (!empty($procurementLotInfo)) {
  77. $aux = 0;
  78. foreach ($procurementLotInfo as $row) {
  79. $setInsert = array();
  80. $setInsert[$aux] = $row;
  81. $setInsert[$aux]['id_ajena_licitacion'] = $this->idLicitacion;
  82. $setInsert[$aux]["fecha_creacion_log"] = $this->fechaInicioParser;
  83. unset($setInsert[$aux]['itemClassification']);
  84. if (!empty($setInsert)) {
  85. $resultInsert = insertBucle($setInsert, "BRUTO_procurement_project_lot", $this->nombreLog);
  86. if (array_key_exists('itemClassification', $row)) {
  87. $this->setDatosMultiples($row, "itemClassification", "BRUTO_procurement_project_lot_item", $resultInsert, "ProcurementLotItem", "id_ajena_ppl");
  88. }
  89. }
  90. $aux++;
  91. }
  92. if ($resultInsert) {
  93. $result = array("result" => true);
  94. guardar_log($this->nombreLog, "ProcurementLot Finalizada Inserción", "false");
  95. } else {
  96. $result = array("result" => true, "id" => 0);
  97. guardar_log($this->nombreLog, "ProcurementLot Fallida", "false", 2);
  98. }
  99. } else {
  100. guardar_log($this->nombreLog, "ProcurementLot vacio", "false");
  101. }
  102. }
  103. private function setTenderingTerms($tenderingTermsInfo): void
  104. {
  105. $resultInsert = 0;
  106. if (!empty($tenderingTermsInfo)) {
  107. $setInsert = array();
  108. $setInsert['tenderingTerms'][0] = $tenderingTermsInfo[0];
  109. $setInsert['tenderingTerms'][0]['id_ajena_licitacion'] = $this->idLicitacion;
  110. if (!empty($setInsert)) {
  111. $resultInsert = insertBucle($setInsert['tenderingTerms'], "BRUTO_tendering_terms", $this->nombreLog);
  112. if ($resultInsert > 0) {
  113. $this->setDatosMultiples($tenderingTermsInfo, 1, "BRUTO_tendering_terms_awarding_terms", $resultInsert, "TenderingTermsAwardingTerms", "id_ajena_tt");
  114. $this->setDatosMultiples($tenderingTermsInfo, 2, "BRUTO_tendering_terms_qualification_request", $resultInsert, "TenderingTermsQualificationRequest", "id_ajena_tt");
  115. $this->setDatosMultiples($tenderingTermsInfo, 3, "BRUTO_tendering_terms_financial_evaluation", $resultInsert, "TenderingTermsFinancialEvaluation", "id_ajena_ttfe");
  116. $this->setDatosMultiples($tenderingTermsInfo, 4, "BRUTO_tendering_terms_specific_terms", $resultInsert, "TenderingTermsSpecificRequirement", "id_ajena_tt");
  117. }
  118. }
  119. if ($resultInsert) {
  120. $result = array("result" => true);
  121. guardar_log($this->nombreLog, "TenderingTerms Finalizada Inserción", "false");
  122. } else {
  123. $result = array("result" => true, "id" => 0);
  124. guardar_log($this->nombreLog, "TenderingTerms Fallida", "false", 2);
  125. }
  126. } else {
  127. guardar_log($this->nombreLog, "TenderingTerms vacio", "false");
  128. }
  129. }
  130. private function setValidNoticeInfo($validNoticeInfo): void
  131. {
  132. $resultInsert = 0;
  133. if (!empty($validNoticeInfo)) {
  134. $aux = 0;
  135. foreach ($validNoticeInfo as $row) {
  136. $setInsert = array();
  137. $setInsert[$aux] = $row;
  138. $setInsert[$aux]['id_ajena_licitacion'] = $this->idLicitacion;
  139. unset($setInsert[$aux]['documento']);
  140. unset($setInsert[$aux]['fechas']);
  141. if (!empty($setInsert)) {
  142. $resultInsert = insertBucle($setInsert, "BRUTO_valid_notice_info", $this->nombreLog);
  143. if ($resultInsert > 0) {
  144. $this->setDatosMultiples($row, "documento", "BRUTO_valid_notice_info_documento", $resultInsert, "validNoticeInfoFechas", "id_ajena_vni");
  145. $this->setDatosMultiples($row, "fechas", "BRUTO_valid_notice_info_fecha", $resultInsert, "validNoticeInfoDocumento", "id_ajena_vni");
  146. }
  147. }
  148. $aux++;
  149. }
  150. if ($resultInsert) {
  151. $result = array("result" => true);
  152. guardar_log($this->nombreLog, "validNoticeInfo Finalizada Inserción", "false");
  153. } else {
  154. $result = array("result" => true, "id" => 0);
  155. guardar_log($this->nombreLog, "validNoticeInfo Fallida", "false", 2);
  156. }
  157. } else {
  158. guardar_log($this->nombreLog, "validNoticeInfo vacio", "false");
  159. }
  160. }
  161. private function setDatosSingular($arrayDatos, $arrayKey, $tabla, $idAjena = 0, $nodoLog, $txtIdAjena): int
  162. {
  163. $insertedId = 0;
  164. if (!empty($arrayDatos) && array_key_exists($arrayKey, $arrayDatos)) {
  165. $arrayInsertar = array();
  166. $arrayInsertar[0] = $arrayDatos[$arrayKey];
  167. if ($idAjena > 0) {
  168. $arrayInsertar[0][$txtIdAjena] = $idAjena;
  169. $arrayInsertar[0]["fecha_creacion_log"] = $this->fechaInicioParser;
  170. }
  171. $insertedId = insertBucle($arrayInsertar, $tabla, $this->nombreLog);
  172. if ($insertedId == 0) {
  173. guardar_log($this->nombreLog, $nodoLog . " Fallido", "false");
  174. } else {
  175. guardar_log($this->nombreLog, $nodoLog . " Finalizada Inserción", "false");
  176. }
  177. } else {
  178. guardar_log($this->nombreLog, $nodoLog . " vacio", "false");
  179. }
  180. return $insertedId;
  181. }
  182. private function setDatosMultiples($arrayDatos, $arrayKey, $tabla, $idAjena = 0, $nodoLog, $txtIdAjena): void
  183. {
  184. $setInsert = array();
  185. $resultInsert = 0;
  186. if (array_key_exists($arrayKey, $arrayDatos)) {
  187. if (!empty($arrayDatos[$arrayKey])) {
  188. $aux = 0;
  189. foreach ($arrayDatos[$arrayKey] as $row) {
  190. $setInsert[$aux] = $row;
  191. if ($idAjena > 0) {
  192. $setInsert[$aux][$txtIdAjena] = $idAjena;
  193. $setInsert[$aux]["fecha_creacion_log"] = $this->fechaInicioParser;
  194. }
  195. $aux++;
  196. }
  197. if (!empty($setInsert)) {
  198. $resultInsert = insertBucle($setInsert, $tabla, $this->nombreLog);
  199. }
  200. if ($resultInsert) {
  201. $result = array("result" => true);
  202. guardar_log($this->nombreLog, $nodoLog . " Finalizada Inserción", "false");
  203. } else {
  204. $result = array("result" => true, "id" => 0);
  205. guardar_log($this->nombreLog, $nodoLog . " Fallida", "false", 2);
  206. }
  207. } else {
  208. guardar_log($this->nombreLog, $nodoLog . " vacio", "false");
  209. }
  210. } else {
  211. guardar_log($this->nombreLog, $nodoLog . " vacio", "false");
  212. }
  213. }
  214. }
  215. /* End of file ParserSetDatabase.php */
  216. /* Location: ./application/libraries/ParserSetDatabase.php */