<?php
        
  function index(){
    

        $pf = 'nc';
        $consecutive = null;
        
        $user = null;
        // $invoice = $note->nulled_invoice;

        $companyNIT = null;
        $companyNITDV = null;
        $SoftwareID = null;
        $pin = null;
        $AuthorizationProviderID = null;

        // 13.1.5.2. Documento CreditNote – Nota Crédito
        // 20 Nota Crédito que NO referencia una factura electrónica
        $CustomizationID = '22';
        $ProfileExecutionID = '1';
        $ID = $pf.$note->id;

        $SoftwareSecurityCode = hash('sha384',$SoftwareID.$pin.$ID);
        
        $IssueDate = substr($note->created_at,0,10);
        $IssueTime = substr($note->created_at,11,16)."-05:00";

        $CreditNoteTypeCode = "91";
        $invoiceNumber = $invoice->code.$invoice->invoice_number;
        
        $noteCode = $type;

        $cancelReason = null;
        $invoiceCufe = $invoice->cufe;
        $invoiceIssueDate = $invoice->created_at->format('Y-m-d');

        $CompanyName = null;
        $CompanyAddress = null;
        $CompanyCity = null;
        $CompanyDepto = null;
        $CompanyDeptoCode = null;
        $companyEmail = null;
        $TaxLevelCode = 'O-23';
        $TLClistName = '48';
        $cityCode = '11001';
        $TaxSchemeId = '01';
        $TaxSchemeName = 'IVA';

        $CustomerName = htmlspecialchars($user->name);
        $CustomerCityCode = '05042';
        $CustomerCity = htmlspecialchars($user->city);
        $CustomerDepto = htmlspecialchars($user->depto);
        $CustomerDeptoCode = '05';
        $CustomerAddress = htmlspecialchars($user->address);
        $CustomerNit = $user->personal_id;
        $CustomerEmail = $user->email;
        $CustomerIdCode = $user->type_of_id;
        $AdditionalAccountID = '2';
        
        $CustomerDV = null;
        if ($CustomerIdCode == '31') {
            $CustomerDV = $this->getDV($CustomerNit);
            $AdditionalAccountID = '1';
        };
      
        $TaxableAmount = $note->taxable_base;
        $TaxAmount = $note->iva;
        $Percent = '19';
        $LineExtensionAmount = $note->subtotal;
        $TaxExclusiveAmount = $note->taxable_base;
        $TaxInclusiveAmount = $note->subtotal+$note->iva;
        $ChargeTotalAmount = $note->other_charges;
        $PayableAmount = $note->total;

        
        $items = $invoice->items;
        $LineCountNumeric = $items->count();
        $xmlLines = $this->formLinesXMl($items);
        

        $codImp1 = '01';
        $ValImp1 =  $TaxAmount;

        $codImp2 = '04';
        $ValImp2 =  '0.00';

        $codImp3 = '03';
        $ValImp3 =  '0.00';

        $cufe = $ID.$IssueDate.$IssueTime.$LineExtensionAmount.$codImp1.$ValImp1.$codImp2.$ValImp2.$codImp3.$ValImp3.$PayableAmount.$companyNIT.$CustomerNit.$pin.$ProfileExecutionID;

        $UUID = hash('sha384',$cufe);

        $QRCode = "NroFactura=$ID NitFacturador=$companyNIT NitAdquiriente=$CustomerNit FechaFactura=$IssueDate ValorTotalFactura=$PayableAmount CUFE=$UUID URL=https://catalogo-vpfe-hab.dian.gov.co/document/searchqr?documentkey=$UUID";

        $xmlHead = $this->formHeadXMl();

        $xmlExtensions = $this->formExtensionXMl($companyNIT,$SoftwareID,$AuthorizationProviderID,$QRCode,$companyNITDV,$SoftwareSecurityCode);

        $xmlVersion = $this->formVersionXMl($CustomizationID,$ProfileExecutionID,$ID,$UUID,$IssueDate,$IssueTime,$CreditNoteTypeCode,$LineCountNumeric,$invoiceNumber,$noteCode,$cancelReason,$invoiceCufe,$invoiceIssueDate);

        $xmlCompany = $this->formCompanyXMl($CompanyName,$CompanyCity,$CompanyDepto,$CompanyDeptoCode,$CompanyAddress,$companyNIT,$TaxLevelCode,$cityCode,$TaxSchemeId,$TaxSchemeName,$companyNITDV,$TLClistName,$companyEmail);

        $xmlCustomer = $this->formCustomerXMl($AdditionalAccountID,$CustomerName,$CustomerCityCode,$CustomerCity,$CustomerDepto,$CustomerDeptoCode,$CustomerAddress,$CustomerNit,$CustomerIdCode,$CustomerDV,$CustomerEmail);

        $xmlTotal = $this->formTotalsXMl($TaxableAmount,$Percent,$TaxAmount,$LineExtensionAmount,$TaxExclusiveAmount,$TaxInclusiveAmount,$PayableAmount,$ChargeTotalAmount);


        $xml = $xmlHead.$xmlExtensions.$xmlVersion.$xmlCompany.$xmlCustomer.$xmlTotal.$xmlLines;


        $firmado = new FirmadorV2();
      
        $certificadop12 = '../../path/cert.p12';
        $clavecertificado = 'password';
        
        $signed = $firmado->firmar($certificadop12, $clavecertificado, $xml, $UUID, $pf);
       
        $nit = '0'.$companyNIT;
        $ppp = '000';
        $aa = '20';
        $a = str_pad($consecutive, 8, '0', STR_PAD_LEFT);
        $xml_name = $pf.$nit.$ppp.$aa.$a.'.xml';
        $z = 'z';
        $fileName = $z.$nit.$ppp.$aa.$a.'.zip';
        $zip_name = '../../zip/location/xmls/credit_notes/'.$fileName;
        $zip = new ZipArchive;
        $zip->open($zip_name, ZipArchive::CREATE); 
        $zip->addFromString($xml_name, $signed);
        $zip->close();
        
        $document = file_get_contents($zip_name);
        $contentFile =  base64_encode($document);


  }
  function formLinesFromReturnXMl($items){

    $string = "";

    foreach ($items as $key => $value) {

      $LineID = $key+1;
      $LineQty = $value['units'];
      $AllowanceChargeID = 1;
      $line_total = $value['net_price'] * $LineQty;
      $LineBaseAmount = $line_total;
      $AllowancePercentage = 0;
      $LineAllowanceAmount = 0;
      $LineTotal = $line_total;
      $LineTax = $value['iva_per_item'] * $LineQty;
      $LineTaxPercentage = $value['iva'];
      $LineItemName =  htmlspecialchars($value['name']);
      if ($LineTax > 0) {
        $TaxableAmount = $LineTotal;
      }else{
        $TaxableAmount = 0;
      }

      $string .= 
        "<cac:CreditNoteLine> 
          <cbc:ID>$LineID</cbc:ID> 
          <cbc:CreditedQuantity unitCode='EA'>$LineQty</cbc:CreditedQuantity> 
          <cbc:LineExtensionAmount currencyID='COP'>$LineTotal</cbc:LineExtensionAmount>";
          
      if ($LineTotal == 0) {
        
        $total_list_price = $LineBaseAmount*$LineQty;
        $string .=  
        "<cac:PricingReference>
          <cac:AlternativeConditionPrice>
            <cbc:PriceAmount currencyID='COP'>$total_list_price</cbc:PriceAmount>
            <cbc:PriceTypeCode>01</cbc:PriceTypeCode>
          </cac:AlternativeConditionPrice>
        </cac:PricingReference>";
      }

      $string .= 
        "<cac:TaxTotal>
            <cbc:TaxAmount currencyID='COP'>$LineTax</cbc:TaxAmount> 
            <cac:TaxSubtotal> 
              <cbc:TaxableAmount currencyID='COP'>$TaxableAmount</cbc:TaxableAmount> 
              <cbc:TaxAmount currencyID='COP'>$LineTax</cbc:TaxAmount> 
              <cac:TaxCategory> 
                <cbc:Percent>$LineTaxPercentage</cbc:Percent> 
                <cac:TaxScheme> 
                  <cbc:ID>01</cbc:ID> 
                  <cbc:Name>IVA</cbc:Name> 
                </cac:TaxScheme> 
              </cac:TaxCategory> 
            </cac:TaxSubtotal> 
          </cac:TaxTotal> 
          <cac:AllowanceCharge> 
            <cbc:ID>$AllowanceChargeID</cbc:ID> 
            <cbc:ChargeIndicator>false</cbc:ChargeIndicator> 
            <cbc:MultiplierFactorNumeric>$AllowancePercentage</cbc:MultiplierFactorNumeric> 
            <cbc:Amount currencyID='COP'>$LineAllowanceAmount</cbc:Amount> 
            <cbc:BaseAmount currencyID='COP'>$LineBaseAmount</cbc:BaseAmount> 
          </cac:AllowanceCharge> 
          <cac:Item> 
            <cbc:Description>$LineItemName</cbc:Description> 
          </cac:Item> 
          <cac:Price> 
            <cbc:PriceAmount currencyID='COP'>$LineTotal</cbc:PriceAmount> 
            <cbc:BaseQuantity unitCode='EA'>$LineQty</cbc:BaseQuantity> 
          </cac:Price> 
        </cac:CreditNoteLine>";

    }
  
    return $string."</CreditNote>";

  }
  
  function formLinesXMl($items){

    $string = "";

    foreach ($items as $key => $value) {

      $LineID = $key+1;
      $LineQty = $value->qty;
      $AllowanceChargeID = 1;
      $LineBaseAmount = $value->list_price;
      $AllowancePercentage = $value->discount;
      $LineAllowanceAmount = $value->discount_total;
      $LineTotal = $value->net_price_total;
      $LineTax = $value->iva_total;
      $LineTaxPercentage = $value->iva;
      $LineItemName =  htmlspecialchars($value->name);
      if ($LineTax > 0) {
        $TaxableAmount = $LineTotal;
      }else{
        $TaxableAmount = 0;
      }


      $string .= 
        "<cac:CreditNoteLine> 
          <cbc:ID>$LineID</cbc:ID> 
          <cbc:CreditedQuantity unitCode='EA'>$LineQty</cbc:CreditedQuantity> 
          <cbc:LineExtensionAmount currencyID='COP'>$LineTotal</cbc:LineExtensionAmount>";
          
      if ($LineTotal == 0) {
        
        $total_list_price = $LineBaseAmount*$LineQty;
        $string .=  
        "<cac:PricingReference>
          <cac:AlternativeConditionPrice>
            <cbc:PriceAmount currencyID='COP'>$total_list_price</cbc:PriceAmount>
            <cbc:PriceTypeCode>01</cbc:PriceTypeCode>
          </cac:AlternativeConditionPrice>
        </cac:PricingReference>";
      }

      $string .= 
        "<cac:TaxTotal>
            <cbc:TaxAmount currencyID='COP'>$LineTax</cbc:TaxAmount> 
            <cac:TaxSubtotal> 
              <cbc:TaxableAmount currencyID='COP'>$TaxableAmount</cbc:TaxableAmount> 
              <cbc:TaxAmount currencyID='COP'>$LineTax</cbc:TaxAmount> 
              <cac:TaxCategory> 
                <cbc:Percent>$LineTaxPercentage</cbc:Percent> 
                <cac:TaxScheme> 
                  <cbc:ID>01</cbc:ID> 
                  <cbc:Name>IVA</cbc:Name> 
                </cac:TaxScheme> 
              </cac:TaxCategory> 
            </cac:TaxSubtotal> 
          </cac:TaxTotal> 
          <cac:AllowanceCharge> 
            <cbc:ID>$AllowanceChargeID</cbc:ID> 
            <cbc:ChargeIndicator>false</cbc:ChargeIndicator> 
            <cbc:MultiplierFactorNumeric>$AllowancePercentage</cbc:MultiplierFactorNumeric> 
            <cbc:Amount currencyID='COP'>$LineAllowanceAmount</cbc:Amount> 
            <cbc:BaseAmount currencyID='COP'>$LineBaseAmount</cbc:BaseAmount> 
          </cac:AllowanceCharge> 
          <cac:Item> 
            <cbc:Description>$LineItemName</cbc:Description> 
          </cac:Item> 
          <cac:Price> 
            <cbc:PriceAmount currencyID='COP'>$LineTotal</cbc:PriceAmount> 
            <cbc:BaseQuantity unitCode='EA'>$LineQty</cbc:BaseQuantity> 
          </cac:Price> 
        </cac:CreditNoteLine>";

    }
   

    return $string."</CreditNote>";

  }

  function formTotalsXMl($TaxableAmount,$Percent,$TaxAmount,$LineExtensionAmount,$TaxExclusiveAmount,$TaxInclusiveAmount,$PayableAmount,$ChargeTotalAmount){

    $string = '';

    if ($ChargeTotalAmount > 0 ){
      $string .=   
        "<cac:AllowanceCharge>
          <cbc:ID>1</cbc:ID>
          <cbc:ChargeIndicator>true</cbc:ChargeIndicator>  
          <cbc:AllowanceChargeReason>ENVIO - PROCESAMIENTO</cbc:AllowanceChargeReason>  
          <cbc:Amount currencyID='COP'>$ChargeTotalAmount</cbc:Amount> 
        </cac:AllowanceCharge>";
    }

    $string .=
        "<cac:TaxTotal> 
          <cbc:TaxAmount currencyID='COP'>$TaxAmount</cbc:TaxAmount> 
          <cac:TaxSubtotal> 
            <cbc:TaxableAmount currencyID='COP'>$TaxableAmount</cbc:TaxableAmount> 
            <cbc:TaxAmount currencyID='COP'>$TaxAmount</cbc:TaxAmount> 
            <cac:TaxCategory> 
              <cbc:Percent>$Percent</cbc:Percent> 
              <cac:TaxScheme> 
                <cbc:ID>01</cbc:ID> 
                <cbc:Name>IVA</cbc:Name> 
              </cac:TaxScheme> 
            </cac:TaxCategory> 
          </cac:TaxSubtotal> 
        </cac:TaxTotal> 
        <cac:LegalMonetaryTotal>
          <cbc:LineExtensionAmount currencyID='COP'>$LineExtensionAmount</cbc:LineExtensionAmount> 
          <cbc:TaxExclusiveAmount currencyID='COP'>$TaxExclusiveAmount</cbc:TaxExclusiveAmount> 
          <cbc:TaxInclusiveAmount currencyID='COP'>$TaxInclusiveAmount</cbc:TaxInclusiveAmount> 
          <cbc:ChargeTotalAmount currencyID='COP'>$ChargeTotalAmount</cbc:ChargeTotalAmount> 
          <cbc:PayableAmount currencyID='COP'>$PayableAmount</cbc:PayableAmount> 
        </cac:LegalMonetaryTotal>";

    return $string;
  }

  function formCustomerXMl($AdditionalAccountID,$CustomerName,$CustomerCityCode,$CustomerCity,$CustomerDepto,$CustomerDeptoCode,$CustomerAddress,$CustomerNit,$customerIdCode,$CustomerDV,$CustomerEmail){
      return   
      "<cac:AccountingCustomerParty>
        <cbc:AdditionalAccountID>$AdditionalAccountID</cbc:AdditionalAccountID>
            <cac:Party> 
                <cac:PartyName> 
                    <cbc:Name>$CustomerName</cbc:Name>
                </cac:PartyName> 
                <cac:PhysicalLocation> 
                    <cac:Address> 
                        <cbc:ID>$CustomerCityCode</cbc:ID> 
                        <cbc:CityName>$CustomerCity</cbc:CityName> 
                        <cbc:CountrySubentity>$CustomerDepto</cbc:CountrySubentity> 
                        <cbc:CountrySubentityCode>$CustomerDeptoCode</cbc:CountrySubentityCode> 
                        <cac:AddressLine> 
                            <cbc:Line>$CustomerAddress</cbc:Line> 
                        </cac:AddressLine> 
                        <cac:Country> 
                            <cbc:IdentificationCode>CO</cbc:IdentificationCode> 
                            <cbc:Name languageID='es'>Colombia</cbc:Name> 
                        </cac:Country> 
                    </cac:Address> 
                </cac:PhysicalLocation> 
                <cac:PartyTaxScheme> 
                    <cbc:RegistrationName>$CustomerName</cbc:RegistrationName> 
                    <cbc:CompanyID schemeAgencyID='195' schemeAgencyName='CO, DIAN (Dirección de Impuestos y Aduanas Nacionales)' schemeName='$customerIdCode' schemeID='$CustomerDV'>$CustomerNit</cbc:CompanyID> 
                    <cac:TaxScheme> 
                        <cbc:ID>ZY</cbc:ID> 
                        <cbc:Name>No Causa</cbc:Name> 
                    </cac:TaxScheme> 
                </cac:PartyTaxScheme> 
                <cac:PartyLegalEntity> 
                    <cbc:RegistrationName>$CustomerName</cbc:RegistrationName> 
                    <cbc:CompanyID schemeAgencyID='195' schemeAgencyName='CO, DIAN (Dirección de Impuestos y Aduanas Nacionales)' schemeID='$CustomerDV' schemeName='$customerIdCode'>$CustomerNit</cbc:CompanyID>
                </cac:PartyLegalEntity> 
                <cac:Contact>
                    <cbc:ElectronicMail>
                        $CustomerEmail
                    </cbc:ElectronicMail>
                </cac:Contact>
            </cac:Party> 
        </cac:AccountingCustomerParty>";

  }
  function formCompanyXMl($CompanyName,$CompanyCity,$CompanyDepto,$CompanyDeptoCode,$CompanyAddress,$companyNIT,$TaxLevelCode,$cityCode,$TaxSchemeId,$TaxSchemeName,$companyNITDV,$TLClistName,$companyEmail){

     $string = 
     "<cac:AccountingSupplierParty> 
        <cbc:AdditionalAccountID>1</cbc:AdditionalAccountID> 
        <cac:Party> 
            <cac:PartyName> 
                <cbc:Name>$CompanyName</cbc:Name> 
            </cac:PartyName>
            <cac:PhysicalLocation>
                <cac:Address>
                    <cbc:ID>$cityCode</cbc:ID>
                    <cbc:CityName>$CompanyCity</cbc:CityName>
                    <cbc:CountrySubentity>$CompanyDepto</cbc:CountrySubentity>
                    <cbc:CountrySubentityCode>$CompanyDeptoCode</cbc:CountrySubentityCode>
                    <cac:AddressLine>
                        <cbc:Line>$CompanyAddress</cbc:Line>
                    </cac:AddressLine>
                    <cac:Country>
                        <cbc:IdentificationCode>CO</cbc:IdentificationCode>
                        <cbc:Name languageID='es'>Colombia</cbc:Name>
                    </cac:Country>
                </cac:Address>
            </cac:PhysicalLocation> 
            <cac:PartyTaxScheme> 
                <cbc:RegistrationName>$CompanyName</cbc:RegistrationName> 
                <cbc:CompanyID schemeAgencyID='195' schemeAgencyName='CO, DIAN (Dirección de Impuestos y Aduanas Nacionales)' schemeID='$companyNITDV' schemeName='31'>$companyNIT</cbc:CompanyID> 
                <cbc:TaxLevelCode listName='$TLClistName'>$TaxLevelCode</cbc:TaxLevelCode> 
                <cac:RegistrationAddress> 
                    <cbc:ID>$cityCode</cbc:ID> 
                    <cbc:CityName>$CompanyCity</cbc:CityName> 
                    <cbc:CountrySubentity>$CompanyDepto</cbc:CountrySubentity> 
                    <cbc:CountrySubentityCode>$CompanyDeptoCode</cbc:CountrySubentityCode> 
                    <cac:AddressLine> 
                        <cbc:Line>$CompanyAddress</cbc:Line> 
                    </cac:AddressLine> 
                    <cac:Country> 
                        <cbc:IdentificationCode>CO</cbc:IdentificationCode> 
                        <cbc:Name languageID='es'>Colombia</cbc:Name> 
                    </cac:Country> 
                </cac:RegistrationAddress> 
                <cac:TaxScheme> 
                    <cbc:ID>$TaxSchemeId</cbc:ID> 
                    <cbc:Name>$TaxSchemeName</cbc:Name> 
                </cac:TaxScheme> 
            </cac:PartyTaxScheme> 
            <cac:PartyLegalEntity> 
                <cbc:RegistrationName>$CompanyName</cbc:RegistrationName> 
                <cbc:CompanyID schemeAgencyID='195' schemeAgencyName='CO, DIAN (Dirección de Impuestos y Aduanas Nacionales)' schemeID='$companyNITDV' schemeName='31'>$companyNIT</cbc:CompanyID> 
            </cac:PartyLegalEntity> 
            <cac:Contact>
                <cbc:ElectronicMail>$companyEmail</cbc:ElectronicMail>
            </cac:Contact>
        </cac:Party> 
    </cac:AccountingSupplierParty>";
     return $string;
  }

  function formVersionXMl($CustomizationID,$ProfileExecutionID,$ID,$UUID,$IssueDate,$IssueTime,$CreditNoteTypeCode,$LineCountNumeric,$invoiceNumber,$noteCode,$cancelReason,$invoiceCufe,$invoiceIssueDate){
     return 
    "<cbc:UBLVersionID>UBL 2.1</cbc:UBLVersionID>
    <cbc:CustomizationID>$CustomizationID</cbc:CustomizationID> 
    <cbc:ProfileID>DIAN 2.1</cbc:ProfileID> 
    <cbc:ProfileExecutionID>$ProfileExecutionID</cbc:ProfileExecutionID> 
    <cbc:ID>$ID</cbc:ID> 
    <cbc:UUID schemeID='$ProfileExecutionID' schemeName='CUDE-SHA384'>$UUID</cbc:UUID> 
    <cbc:IssueDate>$IssueDate</cbc:IssueDate> 
    <cbc:IssueTime>$IssueTime</cbc:IssueTime> 
    <cbc:CreditNoteTypeCode>$CreditNoteTypeCode</cbc:CreditNoteTypeCode> 
    <cbc:DocumentCurrencyCode listAgencyID='6' listAgencyName='United Nations Economic Commission for Europe' listID='ISO 4217 Alpha'>COP</cbc:DocumentCurrencyCode> 
    <cbc:LineCountNumeric>$LineCountNumeric</cbc:LineCountNumeric>
    <cac:DiscrepancyResponse>
      <cbc:ReferenceID>$invoiceNumber</cbc:ReferenceID>
      <cbc:ResponseCode>$noteCode</cbc:ResponseCode>
      <cbc:Description>$cancelReason</cbc:Description>
    </cac:DiscrepancyResponse>
    <cac:BillingReference>
      <cac:InvoiceDocumentReference>
        <cbc:ID>$invoiceNumber</cbc:ID>
        <cbc:UUID schemeName='CUFE-SHA384'>$invoiceCufe</cbc:UUID>
        <cbc:IssueDate>$invoiceIssueDate</cbc:IssueDate>
      </cac:InvoiceDocumentReference>
    </cac:BillingReference>";
  }

  function formExtensionXMl($companyNIT,$SoftwareID,$AuthorizationProviderID,$QRCode,$companyNITDV,$SoftwareSecurityCode){
    return 
    "<ext:UBLExtensions> 
        <ext:UBLExtension> 
            <ext:ExtensionContent> 
                <sts:DianExtensions> 
                    <sts:InvoiceSource> 
                        <cbc:IdentificationCode listAgencyID='6' listAgencyName='United Nations Economic Commission for Europe' listSchemeURI='urn:oasis:names:specification:ubl:codelist:gc:CountryIdentificationCode-2.1'>CO</cbc:IdentificationCode> 
                    </sts:InvoiceSource> 
                    <sts:SoftwareProvider> 
                        <sts:ProviderID schemeAgencyID='195' schemeAgencyName='CO, DIAN (Dirección de Impuestos y Aduanas Nacionales)' schemeID='$companyNITDV' schemeName='31'>$companyNIT</sts:ProviderID> 
                        <sts:SoftwareID schemeAgencyID='195' schemeAgencyName='CO, DIAN (Dirección de Impuestos y Aduanas Nacionales)'>$SoftwareID</sts:SoftwareID> 
                    </sts:SoftwareProvider> 
                    <sts:SoftwareSecurityCode schemeAgencyID='195' schemeAgencyName='CO, DIAN (Dirección de Impuestos y Aduanas Nacionales)'>$SoftwareSecurityCode</sts:SoftwareSecurityCode> 
                    <sts:AuthorizationProvider> 
                        <sts:AuthorizationProviderID schemeAgencyID='195' schemeAgencyName='CO, DIAN (Dirección de Impuestos y Aduanas Nacionales)' schemeID='4' schemeName='31'>$AuthorizationProviderID</sts:AuthorizationProviderID> 
                        </sts:AuthorizationProvider> 
                        <sts:QRCode> $QRCode </sts:QRCode> 
                </sts:DianExtensions> 
            </ext:ExtensionContent> 
        </ext:UBLExtension> 
        <ext:UBLExtension><ext:ExtensionContent></ext:ExtensionContent></ext:UBLExtension></ext:UBLExtensions>";
  }

  function formHeadXMl(){
    $string = "<?xml version='1.0' encoding='UTF-8' standalone='no'?><CreditNote xmlns='urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2' xmlns:cac='urn:oasis:names:specification:ubl:schema:xsd:CommonAggregateComponents-2' xmlns:cbc='urn:oasis:names:specification:ubl:schema:xsd:CommonBasicComponents-2' xmlns:ds='http://www.w3.org/2000/09/xmldsig#' xmlns:ext='urn:oasis:names:specification:ubl:schema:xsd:CommonExtensionComponents-2' xmlns:sts='http://www.dian.gov.co/contratos/facturaelectronica/v1/Structures' xmlns:xades='http://uri.etsi.org/01903/v1.3.2#' xmlns:xades141='http://uri.etsi.org/01903/v1.4.1#' xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' xsi:schemaLocation='urn:oasis:names:specification:ubl:schema:xsd:CreditNote-2 http://docs.oasis-open.org/ubl/os-UBL-2.1/xsd/maindoc/UBL-CreditNote-2.1.xsd'>";
    return $string;
  }

} 