Skip to content

Commit 797d1a2

Browse files
committed
Fix issue #78
1 parent 8d51279 commit 797d1a2

File tree

4 files changed

+116
-2
lines changed

4 files changed

+116
-2
lines changed

src/Facades/FacadeClassMapper.php

+6-2
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,9 @@ public static function EnumTypeMatch(){
138138
'Gender' => 'gender',
139139
'UseTimeEntry' => 'TimeEntryUsedForPaychecksEnum',
140140
'SpecialItemType' => 'SpecialItemTypeEnum',
141-
'TaxTypeApplicable' => 'TaxTypeApplicablityEnum'
141+
'TaxTypeApplicable' => 'TaxTypeApplicablityEnum',
142+
'PostingType' => 'PostingTypeEnum',
143+
'JournalEntryType' => 'EntityTypeEnum'
142144
];
143145
}
144146

@@ -179,7 +181,9 @@ public static function OtherAntiPatternNameEntity(){
179181
'ItemAssemblyLine' => 'ItemComponentLine',
180182
'SalesTaxRateList' => 'TaxRateList',
181183
'PurchaseTaxRateList' => 'TaxRateList',
182-
'AdjustmentTaxRateList' => 'TaxRateList'
184+
'AdjustmentTaxRateList' => 'TaxRateList',
185+
//Use JournalEntryEntity to replace Entity
186+
'JournalEntryEntity' => 'EntityTypeRef'
183187
];
184188
}
185189

src/Facades/FacadeHelper.php

+5
Original file line numberDiff line numberDiff line change
@@ -431,6 +431,11 @@ public static function simpleAppendClassNameSpace($key){
431431
private static function assignValue($targetObject, $key, $value){
432432
//Reflection Class
433433
$reflectionClassOfTargetObject = new \ReflectionClass($targetObject);
434+
if(strcasecmp($key, "JournalEntryEntity") == 0){
435+
$key = "Entity";
436+
}else if(strcasecmp($key, "JournalEntryType") == 0){
437+
$key = "Type";
438+
}
434439
$property = $reflectionClassOfTargetObject->getProperty($key);
435440
if($property instanceof \ReflectionProperty){
436441
$value = FacadeHelper::convertValueTypeToAppropriateString($value);

src/Facades/JournalEntry.php

+27
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
class JournalEntry{
55

66
public static function create(array $data, $throwException = TRUE){
7+
$data = JournalEntry::changeArrayName($data);
78
if(!isset($data) || empty($data)) throw new \Exception("Passed array for creating JournalEntry is Empty");
9+
//QBO should not call the Entity as DataEnityt
810
$JournalEntryObject = FacadeHelper::reflectArrayToObject("JournalEntry", $data, $throwException );
911
return $JournalEntryObject;
1012
}
@@ -13,6 +15,7 @@ public static function create(array $data, $throwException = TRUE){
1315
* This is an immutable function
1416
*/
1517
public static function update($objToUpdate, array $data){
18+
$data = JournalEntry::changeArrayName($data);
1619
$classOfObj = get_class($objToUpdate);
1720
if(strcmp($classOfObj, FacadeHelper::simpleAppendClassNameSpace("JournalEntry")) != 0){
1821
throw new \Exception("Target object class:{" . $classOfObj . "} is not an instance of JournalEntry.");
@@ -23,4 +26,28 @@ public static function update($objToUpdate, array $data){
2326
return $clonedOfObj;
2427
}
2528

29+
30+
private static function changeArrayName(&$array){
31+
if(is_array($array)){
32+
foreach($array as $key => &$value){
33+
if(is_array($value)){
34+
JournalEntry::changeArrayName($value);
35+
}
36+
37+
if(strcmp($key, "Entity") == 0){
38+
$array["JournalEntryEntity"] = $array["Entity"];
39+
unset($array["Entity"]);
40+
}
41+
42+
if(strcmp($key, "Type") == 0){
43+
$array["JournalEntryType"] = $array["Type"];
44+
unset($array["Type"]);
45+
}
46+
47+
}
48+
}
49+
50+
return $array;
51+
}
52+
2653
}

src/_Samples/JournalEntryCreate.php

+78
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
<?php
2+
//Replace the line with require "vendor/autoload.php" if you are using the Samples from outside of _Samples folder
3+
include('../config.php');
4+
5+
6+
use QuickBooksOnline\API\DataService\DataService;
7+
use QuickBooksOnline\API\Core\Http\Serialization\XmlObjectSerializer;
8+
use QuickBooksOnline\API\Facades\JournalEntry;
9+
// Prep Data Services
10+
$dataService = DataService::Configure(array(
11+
'auth_mode' => 'oauth2',
12+
'ClientID' => "Q0fXL014zAv3wzmlhwXMEHTrKepfAshCRjztEu58ZokzCD5T7D",
13+
'ClientSecret' => "stfnZfuSZUDay6cJSWtvQ9HkWiKFbcI9YuBTET5P",
14+
'accessTokenKey' =>
15+
'eyJlbmMiOiJBMTI4Q0JDLUhTMjU2IiwiYWxnIjoiZGlyIn0..qMhDp-FoKX9dtjmkN62gpQ.VmnY8diZN3FNxI5Wz1axd70pkexOZU9vrimA8PvGDdshOP9OmpA6TsqhxggYf631Q_77zGKDQW2-feNZFKan7jDakTsCUoZCYn9N3RRGy8CI4NVeGfgMJokqhK6rxxcajdjBqQ5EDS_uJKEAPUEfJ1JzEcEHF7Yyp0e6Mj13pkNtvFNTmyvmIoLOU9dfwWbDlvPxJFm_bpjPXM8m4-3wzIr0AXMDqjNlmCZpht9-W5r_UtkkZ66O4Ob06gFGt2t2NYU7jCrW_hOhQwM1urtRjusb9aTh7jElohX7yIipfWyU4nLUIC4QeZOOuKgphuYyej3PgbuoQQCgf0rEvyZ_gkpfmITB684m596RUhiVMvZYPPGd578qcMMwTawpf1fl9bh5p7uvS0izIoGAWWh-l16Gm8al2nJ9_iMIsnNpCPTFuVglu5fckCciByjlOz60OMJHWI0M3uhHu6-22VpUzNpOp3rZ6DDkeVLPWh6KVYDc2JeDJMHkt4TaDK0yb9Xu4qDY-ZPKXAY4eZocdZSTelmldTqXC1oq2E2-HmuGQRuMWdlMzM1UyF8GPlOztTwpuP9GSsfWZJ-TY85Hhv623zcmNYbk21c1YpGryJ-PN4KCRnjaLahlj2pBiPn4_HpYC9z_FrR2G1tzIR-RgZTq2qx47Ppuv5iAPWwQR222aKqVg2XruBsjusU7Ks0wLWp3.VzeZzhi19SkswkLvuXmw9g',
16+
'refreshTokenKey' => "L011530994357pUIdF4rZSpMC5XCZ2TV4ypu4pOpfen4VRvYzl",
17+
'QBORealmID' => "193514611894164",
18+
'baseUrl' => "Development"
19+
));
20+
$dataService->setLogLocation("/Users/hlu2/Desktop/newFolderForLog");
21+
$dataService->throwExceptionOnError(true);
22+
$theResourceObj = JournalEntry::create([
23+
"Line" => [
24+
[
25+
"Id" => "0",
26+
"Description" => "nov portion of rider insurance",
27+
"Amount" => 100.0,
28+
"DetailType" => "JournalEntryLineDetail",
29+
"JournalEntryLineDetail" => [
30+
"PostingType" => "Debit",
31+
"Entity" => [
32+
"Type" => "Vendor",
33+
"EntityRef" => [
34+
"value" => "something",
35+
"name" => "somethingelse"
36+
]
37+
],
38+
"AccountRef" => [
39+
"value" => "39",
40+
"name" => "Opening Bal Equity"
41+
]
42+
]
43+
],
44+
[
45+
"Description" => "nov portion of rider insurance",
46+
"Amount" => 100.0,
47+
"DetailType" => "JournalEntryLineDetail",
48+
"JournalEntryLineDetail" => [
49+
"PostingType" => "Credit",
50+
"Entity" => [
51+
"Type" => "Vendor",
52+
"EntityRef" => [
53+
"value" => "something",
54+
"name" => "somethingelse"
55+
]
56+
],
57+
"AccountRef" => [
58+
"value" => "44",
59+
"name" => "Notes Payable"
60+
]
61+
]
62+
]
63+
]
64+
]);
65+
66+
var_dump($theResourceObj);
67+
$resultingObj = $dataService->Add($theResourceObj);
68+
$error = $dataService->getLastError();
69+
if ($error) {
70+
echo "The Status code is: " . $error->getHttpStatusCode() . "\n";
71+
echo "The Helper message is: " . $error->getOAuthHelperError() . "\n";
72+
echo "The Response message is: " . $error->getResponseBody() . "\n";
73+
}
74+
else {
75+
echo "Created Id={$resultingObj->Id}. Reconstructed response body:\n\n";
76+
$xmlBody = XmlObjectSerializer::getPostXmlFromArbitraryEntity($resultingObj, $urlResource);
77+
echo $xmlBody . "\n";
78+
}

0 commit comments

Comments
 (0)