Created
July 21, 2016 10:11
-
-
Save gautiermichelin/8e445f0865722310b5a86f72bee805df to your computer and use it in GitHub Desktop.
Marketcircle Billings Pro : convert BEX file to TSV (tabulated CSV)
This file contains 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
{ | |
"require": { | |
"rodneyrehm/plist": "^2.0" | |
} | |
} |
This file contains 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
<?php | |
/** | |
* Examples for how to use CFPropertyList | |
* Read an XML PropertyList | |
* @package plist | |
* @subpackage plist.examples | |
*/ | |
namespace CFPropertyList; | |
require __DIR__ . '/vendor/autoload.php'; | |
error_reporting(E_ALL); | |
ini_set("display_errors",1); | |
/** | |
* Require CFPropertyList | |
*/ | |
//require_once(__DIR__.'/../classes/CFPropertyList/CFPropertyList.php'); | |
/* | |
* create a new CFPropertyList instance which loads the sample.plist on construct. | |
* since we know it's an XML file, we can skip format-determination | |
*/ | |
$plist = new CFPropertyList( "07-21-2016-08-57-EstimateSlips.bex", CFPropertyList::FORMAT_XML ); | |
/* | |
* retrieve the array structure of sample.plist and dump to stdout | |
*/ | |
//echo '<pre>'; | |
$slips = $plist->toArray(); | |
$resp = array(); | |
//echo '</pre>'; | |
$filename = $slips["entityName"].".tsv"; | |
$objects = $slips["objects"]; | |
$csv_file = new \SplFileObject($filename, 'w'); | |
$csv_file->fwrite("category.name comment createDate discount distance duration foreignAppEntityName foreignAppImportID foreignAppName markup mileageType name nature owner.name rate roundTime type.typeCode units\n"); | |
foreach ($objects as $object) { | |
//$csv_file->fwrite($object); | |
$object["comment"] = str_replace("\n","§" ,$object["comment"]); | |
$csv_file->fwrite($object["category.name"]."\t"); | |
$csv_file->fwrite($object["comment"]."\t"); | |
$csv_file->fwrite($object["createDate"]."\t"); | |
$csv_file->fwrite($object["discount"]."\t"); | |
$csv_file->fwrite($object["distance"]."\t"); | |
$csv_file->fwrite($object["duration"]."\t"); | |
$csv_file->fwrite($object["foreignAppEntityName"]."\t"); | |
$csv_file->fwrite($object["foreignAppImportID"]."\t"); | |
$csv_file->fwrite($object["foreignAppName"]."\t"); | |
$csv_file->fwrite($object["markup"]."\t"); | |
$csv_file->fwrite($object["mileageType"]."\t"); | |
$csv_file->fwrite($object["name"]."\t"); | |
$csv_file->fwrite($object["nature"]."\t"); | |
$csv_file->fwrite($object["owner.name"]."\t"); | |
$csv_file->fwrite($object["rate"]."\t"); | |
$csv_file->fwrite($object["roundTime"]."\t"); | |
$csv_file->fwrite($object["type.typeCode"]."\t"); | |
$csv_file->fwrite($object["units"]."\n"); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment