#Can't check to see if array key has any value, anyone that can help?
1 messages · Page 1 of 1 (latest)
Oke, momento please
// Sets al the invoices (drafts) in the database.
$invoices = $this->GetInvoicesFromAPI();
$count = 0;
foreach ($invoices as $invoice) {
if(!empty($invoices['details']) && !empty($invoices['contact']) ) {
$count++;
foreach ($invoice['details'] as $detail) {
$toevoeging = new Invoice();
$toevoeging->id = strval($invoice['id']);
$toevoeging->administration_id = strval($invoice['administration_id']);
$toevoeging->company_name = strval($invoice['contact']['company_name']);
$toevoeging->customer_id = strval($invoice['contact']['customer_id']);
$toevoeging->invoice_workflow_id = strval($invoice['contact']['invoice_workflow_id']);
$toevoeging->price = strval($detail['price']);
$toevoeging->amount = strval($detail['amount']);
$toevoeging->tax_rate_id = strval($detail['tax_rate_id']);
$toevoeging->description = strval($detail['description']);
$toevoeging->save();
}
echo "Factuur in database gezet uit moneybird, klantennummer: <b>" . $invoice['contact']['customer_id'] . "</b> ✅ ".$count."</br>";
}
}```
details: [
{
id: "377308226859829057",
administration_id: "342225896400225467",
tax_rate_id: "342225897800074538",
ledger_account_id: "342225896712701148",
project_id: null,
product_id: null,
amount: null,
amount_decimal: "1.0",
description: "*Hardware*",
price: "0.0",
period: null,
row_order: 0,
total_price_excl_tax_with_discount: "0.0",
total_price_excl_tax_with_discount_base: "0.0",
tax_report_reference: [
"NL/1a"
],
mandatory_tax_text: "",
created_at: "2023-01-18T13:39:47.045Z",
updated_at: "2023-01-18T13:39:47.045Z"
},
{
id: "377308226870314818",
administration_id: "342225896400225467",
tax_rate_id: "342225897800074538",
ledger_account_id: "342408295609271670",
project_id: null,
product_id: null,
amount: "1",
amount_decimal: "1.0",
description: "HP EliteDesk 800 G4 Mini
- Intel Core i5-8500
- 16GB DDR4-SDRAM
- 512GB NVMe SSD
- Intel® UHD Graphics 630
- Windows 10 Pro
_Refurbished_",
price: "439.0",
period: null,
row_order: 1,
total_price_excl_tax_with_discount: "439.0",
total_price_excl_tax_with_discount_base: "439.0",
tax_report_reference: [
"NL/1a"
],
mandatory_tax_text: null,
created_at: "2023-01-18T13:39:47.055Z",
updated_at: "2023-01-18T13:39:47.055Z"
},```
Possible output for details.
Thats why i'd prefer hastebin
What exactly are you looking to do then?
To check if $invoice['details'] is not details: [ ]
Like checking if its empty
Since array_key_exists can't be done because there are more then 1 keys under details
Maybe convert json to array and check if the details is_null?
You can just check if its empty or even do a count and check if its zero.
How do you suggest doing that?
Empty doesn't work
if(!empty($invoices['details']) && !empty($invoices['contact']) ) {```
What does work about it? It reports false positive?
doesnt*
Try count then.
if(count($invoices['details']) && count($invoices['contact'])) {
What's the output when you do dd($invoice);
Moneybird tends to mix objects and arrays together, been there and it was a struggle
It ain't pretty but I did it like this:
$details = $invoice->details;
//Kijken of er een referentie is meegegeven
if (substr($details, 0, 1) == "["){
}```
Or you could just do substr($invoice->details, 0, 1) == "["
https://hastebin.com/orelezukuc.php
Can't put in chat because to long
Hastebin is a free web-based pastebin service for storing and sharing text and code snippets with anyone. Get started now.
Oke oke, thank you i'll try that
alright you're referencing to $invoices instead of $invoice
count($invoice['details']) should work
within the foreach loop that is
@gray sparrow Je gebruikt de verkeerde variabele bij de if- statement. Je moet $invoice['details'] hebben in plaats van $invoices['details']
Ik zie het inderdaad..😂
Ook dat werkt alsnog niet met de code die ik had gestuurd of die werd verstuurd door het persoon hierin
Ik zou dat van jou maar eens moeten proberen denk ik
Hmm weird
Oh nee werkt nu!
🙂
Super
@fringe thorn @novel pagoda Thank u guys for the help, it works now!
Glad one of the solutions worked for oyu.
@gray sparrow Why have you deleted the original post?
I think because it contained specific private date