|
@@ -64,6 +64,102 @@ class B3CprService
|
|
|
}
|
|
}
|
|
|
public function mapToB3(array $cpr): array
|
|
public function mapToB3(array $cpr): array
|
|
|
{
|
|
{
|
|
|
|
|
+ $collateralTypeCodes = $this->splitSemicolonList($cpr['cpr_collateral_type_code'] ?? null);
|
|
|
|
|
+ $collateralTypeNames = $this->splitSemicolonList($cpr['cpr_collateral_type_name'] ?? null);
|
|
|
|
|
+ $constitutionProcessIndicators = $this->splitSemicolonList($cpr['cpr_constitution_process_indicator'] ?? null);
|
|
|
|
|
+ $otcBondsmanAccountCodes = $this->splitSemicolonList($cpr['cpr_otc_bondsman_account_code'] ?? null);
|
|
|
|
|
+
|
|
|
|
|
+ $collateralsCount = max(
|
|
|
|
|
+ count($collateralTypeCodes),
|
|
|
|
|
+ count($collateralTypeNames),
|
|
|
|
|
+ count($constitutionProcessIndicators),
|
|
|
|
|
+ count($otcBondsmanAccountCodes)
|
|
|
|
|
+ );
|
|
|
|
|
+ if ($collateralsCount <= 0) {
|
|
|
|
|
+ $collateralsCount = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $collaterals = [];
|
|
|
|
|
+ for ($i = 0; $i < $collateralsCount; $i++) {
|
|
|
|
|
+ $collaterals[] = [
|
|
|
|
|
+ 'collateralTypeCode' => $collateralTypeCodes[$i] ?? null,
|
|
|
|
|
+ 'collateralTypeName' => $collateralTypeNames[$i] ?? null,
|
|
|
|
|
+ 'constitutionProcessIndicator' => $this->mapIndicator($constitutionProcessIndicators[$i] ?? null),
|
|
|
|
|
+ 'otcBondsmanAccountCode' => $otcBondsmanAccountCodes[$i] ?? null,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $issuerNames = $this->splitSemicolonList($cpr['cpr_issuer_name'] ?? null);
|
|
|
|
|
+ $issuerDocumentNumbers = $this->splitSemicolonList($cpr['cpr_issuers_document_number'] ?? null);
|
|
|
|
|
+ $issuerPersonTypes = $this->splitSemicolonList($cpr['cpr_issuers_person_type_acronym'] ?? null);
|
|
|
|
|
+ $issuerLegalNatures = $this->splitSemicolonList($cpr['cpr_issuer_legal_nature_code'] ?? null);
|
|
|
|
|
+ $issuerStates = $this->splitSemicolonList($cpr['cpr_issuers_state_acronym'] ?? null);
|
|
|
|
|
+ $issuerCities = $this->splitSemicolonList($cpr['cpr_issuers_city_name'] ?? null);
|
|
|
|
|
+
|
|
|
|
|
+ $issuersCount = max(
|
|
|
|
|
+ count($issuerNames),
|
|
|
|
|
+ count($issuerDocumentNumbers),
|
|
|
|
|
+ count($issuerPersonTypes),
|
|
|
|
|
+ count($issuerLegalNatures),
|
|
|
|
|
+ count($issuerStates),
|
|
|
|
|
+ count($issuerCities)
|
|
|
|
|
+ );
|
|
|
|
|
+ if ($issuersCount <= 0) {
|
|
|
|
|
+ $issuersCount = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $issuers = [];
|
|
|
|
|
+ for ($i = 0; $i < $issuersCount; $i++) {
|
|
|
|
|
+ $issuers[] = [
|
|
|
|
|
+ 'cprIssuerName' => $issuerNames[$i] ?? null,
|
|
|
|
|
+ 'documentNumber' => $issuerDocumentNumbers[$i] ?? null,
|
|
|
|
|
+ 'personTypeAcronym' => $issuerPersonTypes[$i] ?? null,
|
|
|
|
|
+ 'issuerLegalNatureCode' => $issuerLegalNatures[$i] ?? null,
|
|
|
|
|
+ 'stateAcronym' => $issuerStates[$i] ?? null,
|
|
|
|
|
+ 'cityName' => $issuerCities[$i] ?? null,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $productionPlaceNames = $this->splitSemicolonList($cpr['cpr_production_place_name'] ?? null);
|
|
|
|
|
+ $propertyRegistrationNumbers = $this->splitSemicolonList($cpr['cpr_property_registration_number'] ?? null);
|
|
|
|
|
+ $notaryNames = $this->splitSemicolonList($cpr['cpr_notary_name'] ?? null);
|
|
|
|
|
+ $totalProductionAreas = $this->splitSemicolonList($cpr['cpr_total_production_area_in_hectares_number'] ?? null);
|
|
|
|
|
+ $totalAreas = $this->splitSemicolonList($cpr['cpr_total_area_in_hectares_number'] ?? null);
|
|
|
|
|
+ $carCodes = $this->splitSemicolonList($cpr['cpr_car_code'] ?? null);
|
|
|
|
|
+ $latitudeCodes = $this->splitSemicolonList($cpr['cpr_latitude_code'] ?? null);
|
|
|
|
|
+ $longitudeCodes = $this->splitSemicolonList($cpr['cpr_longitude_code'] ?? null);
|
|
|
|
|
+ $zipCodes = $this->splitSemicolonList($cpr['cpr_zip_code'] ?? null);
|
|
|
|
|
+
|
|
|
|
|
+ $productionPlacesCount = max(
|
|
|
|
|
+ count($productionPlaceNames),
|
|
|
|
|
+ count($propertyRegistrationNumbers),
|
|
|
|
|
+ count($notaryNames),
|
|
|
|
|
+ count($totalProductionAreas),
|
|
|
|
|
+ count($totalAreas),
|
|
|
|
|
+ count($carCodes),
|
|
|
|
|
+ count($latitudeCodes),
|
|
|
|
|
+ count($longitudeCodes),
|
|
|
|
|
+ count($zipCodes)
|
|
|
|
|
+ );
|
|
|
|
|
+ if ($productionPlacesCount <= 0) {
|
|
|
|
|
+ $productionPlacesCount = 1;
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $productionPlaces = [];
|
|
|
|
|
+ for ($i = 0; $i < $productionPlacesCount; $i++) {
|
|
|
|
|
+ $productionPlaces[] = [
|
|
|
|
|
+ 'productionPlaceName' => $productionPlaceNames[$i] ?? null,
|
|
|
|
|
+ 'propertyRegistrationNumber' => $propertyRegistrationNumbers[$i] ?? null,
|
|
|
|
|
+ 'notaryName' => $notaryNames[$i] ?? null,
|
|
|
|
|
+ 'totalProductionAreaInHectaresNumber' => $totalProductionAreas[$i] ?? null,
|
|
|
|
|
+ 'totalAreaInHectaresNumber' => $totalAreas[$i] ?? null,
|
|
|
|
|
+ 'carCode' => $carCodes[$i] ?? null,
|
|
|
|
|
+ 'latitudeCode' => $latitudeCodes[$i] ?? null,
|
|
|
|
|
+ 'longitudeCode' => $longitudeCodes[$i] ?? null,
|
|
|
|
|
+ 'zipCode' => $zipCodes[$i] ?? null,
|
|
|
|
|
+ ];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
$instrument = [
|
|
$instrument = [
|
|
|
'cprTypeCode' => $cpr['cpr_type_code'] ?? null,
|
|
'cprTypeCode' => $cpr['cpr_type_code'] ?? null,
|
|
|
'otcRegisterAccountCode' => $cpr['cpr_otc_register_account_code'] ?? null,
|
|
'otcRegisterAccountCode' => $cpr['cpr_otc_register_account_code'] ?? null,
|
|
@@ -76,12 +172,7 @@ class B3CprService
|
|
|
'issueFinancialValue' => $cpr['cpr_issue_financial_value'] ?? null,
|
|
'issueFinancialValue' => $cpr['cpr_issue_financial_value'] ?? null,
|
|
|
'profitabilityStartDate' => $this->convertDate($cpr['cpr_profitability_start_date'] ?? null),
|
|
'profitabilityStartDate' => $this->convertDate($cpr['cpr_profitability_start_date'] ?? null),
|
|
|
'automaticExpirationIndicator' => $this->mapIndicator($cpr['cpr_automatic_expiration_indicator'] ?? null),
|
|
'automaticExpirationIndicator' => $this->mapIndicator($cpr['cpr_automatic_expiration_indicator'] ?? null),
|
|
|
- 'collaterals' => [[
|
|
|
|
|
- 'collateralTypeCode' => $cpr['cpr_collateral_type_code'] ?? null,
|
|
|
|
|
- 'collateralTypeName' => $cpr['cpr_collateral_type_name'] ?? null,
|
|
|
|
|
- 'constitutionProcessIndicator' => $this->mapIndicator($cpr['cpr_constitution_process_indicator'] ?? null),
|
|
|
|
|
- 'otcBondsmanAccountCode' => $cpr['cpr_otc_bondsman_account_code'] ?? null,
|
|
|
|
|
- ]],
|
|
|
|
|
|
|
+ 'collaterals' => $collaterals,
|
|
|
'products' => [[
|
|
'products' => [[
|
|
|
'cprProductName' => $cpr['cpr_product_name'] ?? null,
|
|
'cprProductName' => $cpr['cpr_product_name'] ?? null,
|
|
|
'cprProductClassName' => $cpr['cpr_product_class_name'] ?? null,
|
|
'cprProductClassName' => $cpr['cpr_product_class_name'] ?? null,
|
|
@@ -99,14 +190,7 @@ class B3CprService
|
|
|
'stateAcronym' => $cpr['cpr_deliveryPlace_state_acronym'] ?? null,
|
|
'stateAcronym' => $cpr['cpr_deliveryPlace_state_acronym'] ?? null,
|
|
|
'cityName' => $cpr['cpr_deliveryPlace_city_name'] ?? null,
|
|
'cityName' => $cpr['cpr_deliveryPlace_city_name'] ?? null,
|
|
|
],
|
|
],
|
|
|
- 'issuers' => [[
|
|
|
|
|
- 'cprIssuerName' => $cpr['cpr_issuer_name'] ?? null,
|
|
|
|
|
- 'documentNumber' => $cpr['cpr_issuers_document_number'] ?? null,
|
|
|
|
|
- 'personTypeAcronym' => $cpr['cpr_issuers_person_type_acronym'] ?? null,
|
|
|
|
|
- 'issuerLegalNatureCode' => $cpr['cpr_issuer_legal_nature_code'] ?? null,
|
|
|
|
|
- 'stateAcronym' => $cpr['cpr_issuers_state_acronym'] ?? null,
|
|
|
|
|
- 'cityName' => $cpr['cpr_issuers_city_name'] ?? null,
|
|
|
|
|
- ]],
|
|
|
|
|
|
|
+ 'issuers' => $issuers,
|
|
|
'scr' => [
|
|
'scr' => [
|
|
|
'scrTypeCode' => $cpr['cpr_scr_type_code'] ?? null,
|
|
'scrTypeCode' => $cpr['cpr_scr_type_code'] ?? null,
|
|
|
'finalityCode' => $cpr['cpr_finality_code'] ?? null,
|
|
'finalityCode' => $cpr['cpr_finality_code'] ?? null,
|
|
@@ -116,22 +200,33 @@ class B3CprService
|
|
|
'creditorName' => $cpr['cpr_creditor_name'] ?? null,
|
|
'creditorName' => $cpr['cpr_creditor_name'] ?? null,
|
|
|
'documentNumber' => $cpr['cpr_creditor_document_number'] ?? null,
|
|
'documentNumber' => $cpr['cpr_creditor_document_number'] ?? null,
|
|
|
],
|
|
],
|
|
|
- 'productionPlaces' => [[
|
|
|
|
|
- 'productionPlaceName' => $cpr['cpr_production_place_name'] ?? null,
|
|
|
|
|
- 'propertyRegistrationNumber' => $cpr['cpr_property_registration_number'] ?? null,
|
|
|
|
|
- 'notaryName' => $cpr['cpr_notary_name'] ?? null,
|
|
|
|
|
- 'totalProductionAreaInHectaresNumber' => $cpr['cpr_total_production_area_in_hectares_number'] ?? null,
|
|
|
|
|
- 'totalAreaInHectaresNumber' => $cpr['cpr_total_area_in_hectares_number'] ?? null,
|
|
|
|
|
- 'carCode' => $cpr['cpr_car_code'] ?? null,
|
|
|
|
|
- 'latitudeCode' => $cpr['cpr_latitude_code'] ?? null,
|
|
|
|
|
- 'longitudeCode' => $cpr['cpr_longitude_code'] ?? null,
|
|
|
|
|
- 'zipCode' => $cpr['cpr_zip_code'] ?? null,
|
|
|
|
|
- ]],
|
|
|
|
|
|
|
+ 'productionPlaces' => $productionPlaces,
|
|
|
];
|
|
];
|
|
|
|
|
|
|
|
return ['data' => ['instrument' => $instrument]];
|
|
return ['data' => ['instrument' => $instrument]];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private function splitSemicolonList($value): array
|
|
|
|
|
+ {
|
|
|
|
|
+ if (is_array($value)) {
|
|
|
|
|
+ $items = array_map(static fn($v) => trim((string)$v), array_values($value));
|
|
|
|
|
+ return array_values(array_filter($items, static fn($v) => $v !== ''));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ if (!is_string($value)) {
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $trimmed = trim($value);
|
|
|
|
|
+ if ($trimmed === '') {
|
|
|
|
|
+ return [];
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ $parts = preg_split('/\s*;\s*/', $trimmed) ?: [];
|
|
|
|
|
+ $parts = array_map(static fn($v) => trim((string)$v), $parts);
|
|
|
|
|
+ return array_values(array_filter($parts, static fn($v) => $v !== ''));
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
private function convertDate(?string $date): ?string
|
|
private function convertDate(?string $date): ?string
|
|
|
{
|
|
{
|
|
|
if (!is_string($date) || trim($date) === '') {
|
|
if (!is_string($date) || trim($date) === '') {
|