Created
April 13, 2016 20:20
-
-
Save igoralves1/30a2bc9e3c793d6e2e080fda8a596baf to your computer and use it in GitHub Desktop.
PHP - Generate a XML.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public function genetare_XML_string(array $arrSetOrder) { | |
//Values by default | |
$arrIni["Object"]=17; | |
$arrIni["Version"]=2; | |
$arrIni["Company"]="US";//Default is not demo Company | |
//Setting user's parameters | |
$arrOrder = array_merge($arrIni,$arrSetOrder); | |
#Doc Header | |
//Statics variables | |
$Object=$arrOrder["Object"]; | |
$Version=$arrOrder["Version"]; | |
$Company=$arrOrder["Company"]; | |
$OrderNum=$arrOrder["OrderNum"]; | |
$CompanyID=$arrOrder["CompanyID"]; | |
$PostDate=$arrOrder["PostDate"]; | |
$DocDueDate=$arrOrder["DocDueDate"]; | |
$CancelDate=$arrOrder["CancelDate"]; | |
$ShipToCode=$arrOrder["ShipToCode"]; | |
$BillToCode=$arrOrder["BillToCode"]; | |
$CntcCode=$arrOrder["CntcCode"]; | |
$CntcEmail=$arrOrder["CntcEmail"]; | |
#Doc contents | |
//Loop trough items to creating rows | |
$LineNum=1; | |
foreach ($arrOrder["arrItens"] as $value) { | |
$rowItens.="<row>"; | |
$rowItens.="<LineNum>".$LineNum++."</LineNum>"; | |
$rowItens.="<ItemCode>{$value["ItemCode"]}</ItemCode>"; | |
$rowItens.="<Quantity>{$value["Quantity"]}</Quantity>"; | |
$rowItens.="<DiscountPercent>{$value["DiscountPercent"]}</DiscountPercent>"; | |
$rowItens.="</row>"; | |
} | |
$str="<?xml version=\"1.0\" encoding=\"utf-8\"?>"; | |
$str.="<ORDR>"; | |
$str.="<BOM>"; | |
$str.="<BO>"; | |
$str.="<AdmInfo>"; | |
$str.="<Object>$Object</Object>"; | |
$str.="<Version>$Version</Version>"; | |
$str.="</AdmInfo>"; | |
$str.="<Documents>"; | |
$str.="<row>"; | |
$str.="<OrderNum>$OrderNum</OrderNum>"; | |
$str.="<CompanyID>$CompanyID</CompanyID>"; | |
$str.="<Company>$Company</Company>"; | |
$str.="<PostDate>$PostDate</PostDate>"; | |
$str.="<DocDueDate>$DocDueDate</DocDueDate>"; | |
$str.="<CancelDate>$CancelDate</CancelDate>"; | |
$str.="<ShipToCode>$ShipToCode</ShipToCode>"; | |
$str.="<BillToCode>$BillToCode</BillToCode>"; | |
$str.="<CntcCode>$CntcCode</CntcCode>"; | |
$str.="<CntcEmail>$CntcEmail</CntcEmail>"; | |
$str.="</row>"; | |
$str.="</Documents>"; | |
$str.="<Document_Lines>"; | |
$str.=$rowItens; | |
$str.="</Document_Lines>"; | |
$str.="</BO>"; | |
$str.="</BOM>"; | |
$str.="</ORDR>"; | |
return $str; | |
}//End of genetare_XML_file |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment