合并PHP

时间:2015-05-04 15:24:09

标签: php xml

我根据XML文件创建发票。在XML中,我有相同的电话号码。这个电话号码会刮不同的子节点。 (一个是数据,另一个是短信等) 我想组合电话号码相同的节点。 结果现在是:

Beschrijving                Prijs excl.BT1W Aantal  BTW Subtotaal
telnr..818              
Nationaal data 725.48 MB    45,20           1       21  45,2

telnr..884              
Nationaal SMS 22            0               1       21  0

telnr..249  
Internationaal Europa 
EU 24.92 minuten            1,41            1       21  1,41     

telnr..818              
Nationaal SMS2              0               1       21  0
Servicenummers BTW 
hoog tarief 21.8 minuten    0               1       21  0

telnr..249              
Nationaal vast 6.77 minuten 0,21            1       21  0,21

我想要的是什么:

Beschrijving                Prijs excl.BTW  Aantal  BTW Subtotaal
telnr..818              
Nationaal data 725.48 MB    45,20           1       21  45,2
Nationaal SMS2              0               1       21  0
Servicenummers BTW 
hoog tarief 21.8 minuten    0               1       21  0

telnr..884              
Nationaal SMS 22            0               1       21  0           

telnr..249              
Nationaal vast 6.77 minuten 0,21            1       21  0,21
Internationaal Europa 
EU 24.92 minuten            1,41            1       21  1,41

XML

<?xml version="1.0" encoding="utf-8"?>
<!--Aanmaakdatum: 16-04-2015 10:07:00 (CustomerId=35023)-->
<Facturen>
  <Factuur>
    <Specificaties>
    ----
    </Specificaties>
    <DetailSpecificaties>
      <DetailSpecificatie>
        <Nummer>+31527682617</Nummer>
        <SimNummer></SimNummer>
        <Categorie>Nationaal vast</Categorie>
        <Bedrag>6,11</Bedrag>
        <ProductType>Telefonie</ProductType>
        <GebruiksType>Gesprekken</GebruiksType>
        <GebruiksEenheid>Seconden</GebruiksEenheid>
        <Aantal>56</Aantal>
        <Volume>4844</Volume>
        <StartDatum>2-3-2015 8:51:53</StartDatum>
        <EindDatum>27-3-2015 13:48:27</EindDatum>
      </DetailSpecificatie>
      <DetailSpecificatie>
        <Nummer>+31527682617</Nummer>
        <SimNummer></SimNummer>
        <Categorie>Nationaal mobiel</Categorie>
        <Bedrag>11,15</Bedrag>
        <ProductType>Telefonie</ProductType>
        <GebruiksType>Gesprekken</GebruiksType>
        <GebruiksEenheid>Seconden</GebruiksEenheid>
        <Aantal>77</Aantal>
        <Volume>4240</Volume>
        <StartDatum>2-3-2015 10:14:45</StartDatum>
        <EindDatum>31-3-2015 10:32:39</EindDatum>
      </DetailSpecificatie>
      <DetailSpecificatie>
        <Nummer>+31527682617</Nummer>
        <SimNummer></SimNummer>
        <Categorie>On-net</Categorie>
        <Bedrag>0,00</Bedrag>
        <ProductType>Telefonie</ProductType>
        <GebruiksType>Gesprekken</GebruiksType>
        <GebruiksEenheid>Seconden</GebruiksEenheid>
        <Aantal>254</Aantal>
        <Volume>19456</Volume>
        <StartDatum>2-3-2015 9:18:28</StartDatum>
        <EindDatum>31-3-2015 16:58:26</EindDatum>
      </DetailSpecificatie>
    </DetailSpecificaties>
  </Factuur>
</Facturen>

PHP

    <?php
    foreach($xml->children() as $Factuur) { 

        $tellen='1';
        $TelNummer = NULL;
        foreach($Factuur->DetailSpecificaties->children() as $Specificatie) {

            if($TelNummer != trim((string)$Specificatie->Nummer)) {

                $TelNummer = trim((string)$Specificatie->Nummer);
                $fields["subtitle_$tellen"] .= $TelNummer;

            }


                $fields["payment_term"] = "0D";

                if(trim((string)$Specificatie->Categorie) != ""){
                    //$fields["description_$tellen"] = "Specificatie:";
                    $fields["description_$tellen"] .= trim((string)$Specificatie->Categorie);  
                }


                if(trim((string)$Specificatie->GebruiksType) != "" && trim((string)$Specificatie->GebruiksType) == "Gesprekken"){
                    $Gesprekken = round((float)$Specificatie->Volume / 60, 2);
                    $fields["description_$tellen"] .= " ".$Gesprekken. " minuten"; 
                }

                if(trim((string)$Specificatie->GebruiksType) != "" && trim((string)$Specificatie->GebruiksType) == "Data"){
                    $Data = round(((float)$Specificatie->Volume / 1024 / 1024), 2);
                    $fields["description_$tellen"] .= " ".$Data. " MB"; 
                }


                if(trim((string)$Specificatie->GebruiksType) != "" && trim((string)$Specificatie->GebruiksType) == "SMS"){
                    $SMS = (float)$Specificatie->Volume;
                    $fields["description_$tellen"] .= " ".$SMS; 
                }


                if(trim((string)$Specificatie->GebruiksType) != "" && trim((string)$Specificatie->GebruiksType) == "Abonnement"){
                    $Abonnement = (float)$Specificatie->Abonnement;
                    $fields["description_$tellen"] .= " Abonnement"; 
                }


                if(trim($Specificatie->Bedrag) != ""){
                    $fields["price_$tellen"] = (string)$Specificatie->Bedrag;
                }


                $fields["amount_$tellen"] = "1";



                $fields["vat_$tellen"] = "21";

                $tellen++;


        }
}
?>

0 个答案:

没有答案
相关问题