PHP: Group timestamps in days, weeks, months, years - php

In my application I am using RRD, but in several specific scenarios I want to fetch and group data (by days, weeks, months, years based on timestamps).
Here is an example to understand me better:
We have array with two data sources (all, active). In each data source, keys are timestamps and interval between timestamps is 86400 sec.
$arr = [
"all" => [
"1664236800" => 0,
"1664323200" => 0,
"1664409600" => 0,
"1664496000" => 0,
"1664582400" => 0,
"1664668800" => 0,
"1664755200" => 0,
"1664841600" => 0,
"1664928000" => 0,
"1665014400" => 0,
"1665100800" => 0,
"1665187200" => 0,
"1665273600" => 0,
"1665360000" => 0,
"1665446400" => 0,
"1665532800" => 0,
"1665619200" => 0,
"1665705600" => 0,
"1665792000" => 0,
"1665878400" => 0,
"1665964800" => 0,
"1666051200" => 0,
"1666137600" => 0,
"1666224000" => 0,
"1666310400" => 0,
"1666396800" => 0,
"1666483200" => 0,
"1666569600" => 0,
"1666656000" => 0,
"1666742400" => 0,
"1666828800" => 0,
"1666915200" => 0,
"1667001600" => 0,
"1667088000" => 0,
"1667174400" => 0,
"1667260800" => 0,
"1667347200" => 0,
"1667433600" => 0,
"1667520000" => 0,
"1667606400" => 0,
"1667692800" => 0,
"1667779200" => 0,
"1667865600" => 0,
"1667952000" => 0,
"1668038400" => 0,
"1668124800" => 0,
"1668211200" => 0,
"1668297600" => 0,
"1668384000" => 0,
"1668470400" => 0,
"1668556800" => 0,
"1668643200" => 0,
"1668729600" => 0,
"1668816000" => 0,
"1668902400" => 0,
"1668988800" => 0,
"1669075200" => 0,
"1669161600" => 0,
"1669248000" => 0,
"1669334400" => 0,
"1669420800" => 0,
"1669507200" => 0,
"1669593600" => 0,
"1669680000" => 0,
"1669766400" => 0,
"1669852800" => 0,
"1669939200" => 0,
"1670025600" => 0,
"1670112000" => 0,
"1670198400" => 0,
"1670284800" => 0,
"1670371200" => 0,
"1670457600" => 0,
"1670544000" => 0,
"1670630400" => 0,
"1670716800" => 0,
"1670803200" => 0,
"1670889600" => 0,
"1670976000" => 0,
"1671062400" => 0,
"1671148800" => 0,
"1671235200" => 0,
"1671321600" => 0,
"1671408000" => 0,
"1671494400" => 0,
"1671580800" => 0,
"1671667200" => 0,
"1671753600" => 0,
"1671840000" => 0,
"1671926400" => 0,
"1672012800" => 0,
"1672099200" => 0,
"1672185600" => 0,
"1672272000" => 0,
],
"active" => [
"1664236800" => 0,
"1664323200" => 0,
"1664409600" => 0,
"1664496000" => 0,
"1664582400" => 0,
"1664668800" => 0,
"1664755200" => 0,
"1664841600" => 0,
"1664928000" => 0,
"1665014400" => 0,
"1665100800" => 0,
"1665187200" => 0,
"1665273600" => 0,
"1665360000" => 0,
"1665446400" => 0,
"1665532800" => 0,
"1665619200" => 0,
"1665705600" => 0,
"1665792000" => 0,
"1665878400" => 0,
"1665964800" => 0,
"1666051200" => 0,
"1666137600" => 0,
"1666224000" => 0,
"1666310400" => 0,
"1666396800" => 0,
"1666483200" => 0,
"1666569600" => 0,
"1666656000" => 0,
"1666742400" => 0,
"1666828800" => 0,
"1666915200" => 0,
"1667001600" => 0,
"1667088000" => 0,
"1667174400" => 0,
"1667260800" => 0,
"1667347200" => 0,
"1667433600" => 0,
"1667520000" => 0,
"1667606400" => 0,
"1667692800" => 0,
"1667779200" => 0,
"1667865600" => 0,
"1667952000" => 0,
"1668038400" => 0,
"1668124800" => 0,
"1668211200" => 0,
"1668297600" => 0,
"1668384000" => 0,
"1668470400" => 0,
"1668556800" => 0,
"1668643200" => 0,
"1668729600" => 0,
"1668816000" => 0,
"1668902400" => 0,
"1668988800" => 0,
"1669075200" => 0,
"1669161600" => 0,
"1669248000" => 0,
"1669334400" => 0,
"1669420800" => 0,
"1669507200" => 0,
"1669593600" => 0,
"1669680000" => 0,
"1669766400" => 0,
"1669852800" => 0,
"1669939200" => 0,
"1670025600" => 0,
"1670112000" => 0,
"1670198400" => 0,
"1670284800" => 0,
"1670371200" => 0,
"1670457600" => 0,
"1670544000" => 0,
"1670630400" => 0,
"1670716800" => 0,
"1670803200" => 0,
"1670889600" => 0,
"1670976000" => 0,
"1671062400" => 0,
"1671148800" => 0,
"1671235200" => 0,
"1671321600" => 0,
"1671408000" => 0,
"1671494400" => 0,
"1671580800" => 0,
"1671667200" => 0,
"1671753600" => 0,
"1671840000" => 0,
"1671926400" => 0,
"1672012800" => 0,
"1672099200" => 0,
"1672185600" => 0,
"1672272000" => 0,
]
];
I want to group this data in months.
The example response:
$arr = [
"1664236800" => [ // 27 September ( this is first value from fetch array)
"all" => [
"1664236800" => 0,
"1664323200" => 0,
"1664409600" => 0,
"1664496000" => 0,
],
"active" => [
"1664236800" => 0,
"1664323200" => 0,
"1664409600" => 0,
"1664496000" => 0,
],
],
"1664582400" => [ // 1st October
"all" => [
"1664582400" => 0,
"1664668800" => 0,
"1664755200" => 0,
"1664841600" => 0,
"1664928000" => 0,
"1665014400" => 0,
"1665100800" => 0,
"1665187200" => 0,
"1665273600" => 0,
"1665360000" => 0,
"1665446400" => 0,
"1665532800" => 0,
"1665619200" => 0,
"1665705600" => 0,
"1665792000" => 0,
"1665878400" => 0,
"1665964800" => 0,
"1666051200" => 0,
"1666137600" => 0,
"1666224000" => 0,
"1666310400" => 0,
"1666396800" => 0,
"1666483200" => 0,
"1666569600" => 0,
"1666656000" => 0,
"1666742400" => 0,
"1666828800" => 0,
"1666915200" => 0,
"1667001600" => 0,
"1667088000" => 0,
"1667174400" => 0,
],
"active" => [
"1664582400" => 0,
"1664668800" => 0,
"1664755200" => 0,
"1664841600" => 0,
"1664928000" => 0,
"1665014400" => 0,
"1665100800" => 0,
"1665187200" => 0,
"1665273600" => 0,
"1665360000" => 0,
"1665446400" => 0,
"1665532800" => 0,
"1665619200" => 0,
"1665705600" => 0,
"1665792000" => 0,
"1665878400" => 0,
"1665964800" => 0,
"1666051200" => 0,
"1666137600" => 0,
"1666224000" => 0,
"1666310400" => 0,
"1666396800" => 0,
"1666483200" => 0,
"1666569600" => 0,
"1666656000" => 0,
"1666742400" => 0,
"1666828800" => 0,
"1666915200" => 0,
"1667001600" => 0,
"1667088000" => 0,
"1667174400" => 0,
],
],
"1667260800" => [ // 1st November
"all" => [
"1667260800" => 0,
"1667347200" => 0,
"1667433600" => 0,
"1667520000" => 0,
"1667606400" => 0,
"1667692800" => 0,
"1667779200" => 0,
"1667865600" => 0,
"1667952000" => 0,
"1668038400" => 0,
"1668124800" => 0,
"1668211200" => 0,
"1668297600" => 0,
"1668384000" => 0,
"1668470400" => 0,
"1668556800" => 0,
"1668643200" => 0,
"1668729600" => 0,
"1668816000" => 0,
"1668902400" => 0,
"1668988800" => 0,
"1669075200" => 0,
"1669161600" => 0,
"1669248000" => 0,
"1669334400" => 0,
"1669420800" => 0,
"1669507200" => 0,
"1669593600" => 0,
"1669680000" => 0,
"1669766400" => 0,
],
"active" => [
"1667260800" => 0,
"1667347200" => 0,
"1667433600" => 0,
"1667520000" => 0,
"1667606400" => 0,
"1667692800" => 0,
"1667779200" => 0,
"1667865600" => 0,
"1667952000" => 0,
"1668038400" => 0,
"1668124800" => 0,
"1668211200" => 0,
"1668297600" => 0,
"1668384000" => 0,
"1668470400" => 0,
"1668556800" => 0,
"1668643200" => 0,
"1668729600" => 0,
"1668816000" => 0,
"1668902400" => 0,
"1668988800" => 0,
"1669075200" => 0,
"1669161600" => 0,
"1669248000" => 0,
"1669334400" => 0,
"1669420800" => 0,
"1669507200" => 0,
"1669593600" => 0,
"1669680000" => 0,
"1669766400" => 0,
],
],
"1669852800" => [ // 1st December
"all" => [
"1669852800" => 0,
"1669939200" => 0,
"1670025600" => 0,
"1670112000" => 0,
"1670198400" => 0,
"1670284800" => 0,
"1670371200" => 0,
"1670457600" => 0,
"1670544000" => 0,
"1670630400" => 0,
"1670716800" => 0,
"1670803200" => 0,
"1670889600" => 0,
"1670976000" => 0,
"1671062400" => 0,
"1671148800" => 0,
"1671235200" => 0,
"1671321600" => 0,
"1671408000" => 0,
"1671494400" => 0,
"1671580800" => 0,
"1671667200" => 0,
"1671753600" => 0,
"1671840000" => 0,
"1671926400" => 0,
"1672012800" => 0,
"1672099200" => 0,
"1672185600" => 0,
"1672272000" => 0,
],
"active" => [
"1669852800" => 0,
"1669939200" => 0,
"1670025600" => 0,
"1670112000" => 0,
"1670198400" => 0,
"1670284800" => 0,
"1670371200" => 0,
"1670457600" => 0,
"1670544000" => 0,
"1670630400" => 0,
"1670716800" => 0,
"1670803200" => 0,
"1670889600" => 0,
"1670976000" => 0,
"1671062400" => 0,
"1671148800" => 0,
"1671235200" => 0,
"1671321600" => 0,
"1671408000" => 0,
"1671494400" => 0,
"1671580800" => 0,
"1671667200" => 0,
"1671753600" => 0,
"1671840000" => 0,
"1671926400" => 0,
"1672012800" => 0,
"1672099200" => 0,
"1672185600" => 0,
"1672272000" => 0,
],
]
];
Which is the best way I can do this?
My way is to convert each timestamp in date("Y-d", $timestamp) and group by response. (don't know how effective is)

The simplest approach is to loop over your original array, and compute the correct monthly slot for each timestamp :
$result = array();
foreach($arr as $type => $items)
{
foreach($items as $timestamp => $value)
{
// compute first day of month
$d = new DateTime();
$d->setTimestamp(intval($timestamp)); // load timestamp into a DateTime object
$d->setTimeZone(new DateTimeZone('UTC'));
$d->setTime(0, 0, 0); // remove hours, minutes and seconds parts (if needed)
$d->modify('first day of this month');
$firstMonthTimestamp = strval($d->getTimestamp());
// create result array structure the first time
if(!array_key_exists($firstMonthTimestamp, $result)) $result[$firstMonthTimestamp] = array();
if(!array_key_exists($type, $result[$firstMonthTimestamp])) $result[$firstMonthTimestamp][$type] = array();
// append element to the month list
$result[$firstMonthTimestamp][$type][$timestamp] = $value ;
}
}
print_r($result);

As often happens, after you ask a question an answer pops into your head.
The above solution is good, but I need to be able to group this data by hours, days, weeks, months and years
This is my solution after several days of reflection.
$groupData = (new Grouper())->group(new GroupByMonth(), $arr);
Grouper.php
class Grouper
{
public function group(GrouperInterface $service, $data)
{
$dataSources = array_keys($data);
$timestamps = array_keys($data[$dataSources[0]]);
$groupData = [];
$lastKey = null;
foreach ($timestamps as $timestamp) {
if ($service->isNewGroup($timestamp)) {
$groupData[$timestamp] = array_fill_keys($dataSources, []);
$lastKey = $timestamp;
}
foreach ($dataSources as $ds) {
$groupData[$lastKey][$ds][$timestamp] = $data[$ds][$timestamp];
}
}
return $groupData;
}
}
GroupByMonth.php
class GroupByMonth implements GrouperInterface
{
private int $endTimestamp = -1;
public function isNewGroup(int $timestamp): bool
{
if ($this->endTimestamp >= $timestamp) {
return false;
}
$this->endTimestamp = $this->calculateEndTimestamp($timestamp);
return true;
}
private function calculateEndTimestamp(int $timestamp): int
{
list($year, $month) = explode('-', date('Y-n', $timestamp));
$daysInMonth = cal_days_in_month(CAL_GREGORIAN, $month, $year);
$date = \DateTime::createFromFormat("Y-n-d H:i:s", "{$year}-{$month}-{$daysInMonth} 23:59:59");
return $date->getTimestamp();
}
}
This is a better solution for me because it allows me to write more grouping functionality

Related

Is there a chance that array_slice is bugged - returning wrong

Is there a chance to array_slice is bugged (using PHP 8.0.12)
I were looking for best way to get few elements(limited) of array with possible offset so tried to array_slice but its keep return me wrong index then i expect
I have array with objects from database and they looks like(ill write only id)
$questions simplified to only id
$limit = 1;
$questions = array(
array(
'id' => 2,
'stage' => 1,
'question_order' => 0,
'many_answers' => 0,
'points' => 5.5,
'spread_points_in_time' => 0,
'question' => "Czy Johnny Deep grał Jack'a Sparow'a?",
'time' => "00:00:10"
),
array(
'id' => 3,
'stage' => 1,
'question_order' => 0,
'many_answers' => 0,
'points' => 4.5,
'spread_points_in_time' =>0,
'question' => "Producent laptopa Darka",
'time' => "00:00:00"
),
array(
'id' => 1,
'stage' => 1,
'question_order' => 0,
'many_answers' => 0,
'points' => 10,
'spread_points_in_time' => 0,
'question' => "Która klawiatura jest mechniczna",
'time' => "00:00:10"
),
array(
'id' => 8,
'stage' => 2,
'question_order' => 0,
'many_answers' => 0,
'points' => 30,
'spread_points_in_time' => 1,
'question' => "2*2",
'time' => "00:00:30"
),
array(
'id' => 4,
'stage' => 2,
'question_order' => 0,
'many_answers' => 0,
'points' => 30,
'spread_points_in_time' => 0,
'question' => "Który język programowania ma dostęp do komórek pamięci komputera?",
'time' => "00:00:30"
),
array(
'id' => 7,
'stage' => 2,
'question_order' => 0,
'many_answers' => 0,
'points' => 30,
'spread_points_in_time' => 0,
'question' => "2+2",
'time' => "00:00:30"
),
array(
'id' => 10,
'stage' => 3,
'question_order' => 1,
'many_answers' => 1,
'points' => 5,
'spread_points_in_time' => 0,
'question' => "Jaki jest symbol chemiczny srebra?",
'time' => "00:00:00"
),
array(
'id' => 11,
'stage' => 3,
'question_order' => 0,
'many_answers' => 1,
'points' => 5,
'spread_points_in_time' => 0,
'question' => "Jaka jest żywotność ważki?",
'time' => "00:00:00"
),
array(
'id' => 9,
'stage' => 3,
'question_order' => 0,
'many_answers' => 0,
'points' => 5,
'spread_points_in_time' => 0,
'question' => "W którym roku Titanic zatonął na Oceanie Atlantyckim 15 kwietnia podczas dziewiczej podróży z Southampton?",
'time' => "00:00:00"
)
);
echo json_encode(
array(
'all' => $questions,
'limit' => $limit,
'sliced' => array_slice($questions, 0, $limit),
)
);
so when i try array_splice(array, 0, 1) i would expect 1 so id should be 2 but instead i get object which have id 1
i also tried with flag to keep indexed but then i end up same but with true index of object with id 1 (then key is 2)
If i put limit as 2 then i get object with id 1 and also object with id 2 (flag to keep indexed also return me properly to objects 2 and 0)
Also tried to remove id from every object by
foreach($questions as $key => $question)
{
unset($questions[$key]['id'];
}
But this didnt changed anything
$questions source https://pastebin.com/wDfJdm9Z
After plenty of combinations i figured it out
I were sorting this array before everything with forcing keys
So in sorting it looked like
foreach($toSort as $key => $item)
{
foreach($ids as $idKey => $id)
{
if($item['id'] == $id)
{
$sorted[$idKey] = $item;
break;
}
}
}
So for example array could end up with wrong order of keys like:
array(
[1] => item2,
[0] => item1,
[2] => item3
);
I were expecting array gona shove key 0 to be index 0 but don't looks like
Setting something to exact key isn't same as set something to set at exact index
SOLUTION WAS add ksort($sorted) before return $sorted

SOAP-ERROR: Encoding: object has no 'verify_bool' property

After updating my SSL certificate Letsencrypt on server (Linux Ubuntu), I am getting error "SOAP-ERROR: Encoding: object has no 'verify_bool' property" when sending SOAP request. I am using SoapClient.php in Laravel application. Before updating the certificate it worked fine.
My code is here:
$soap_client = new \SoapClient("https://.....?WSDL", array(
'local_cert' => app_path('Services/my.pem'),
'passphrase' => 'mypasphrase')
);
$auth = $soap_client->AuthenticateUser(array(
'aName' => '777.SSL.888',
'aPassword' => 'password'
));
$session_id = $auth->AuthenticateUserResult->SessionID;
$data = $soap_client->getClientsByKeyFields(array(
'aSessionID' => $session_id,
'aClient' => array(
'ID' => 0,
'Natural_Person_Bool' => 1,
'Class_ID' => 10,
'Sex_ID' => 0,
'SETTLEMENT_ID' => 0,
'DOCUMENT_TYPE_ID' => 0,
'ACTIVITY_KIND_ID' => 0,
'RESIDENT_BOOL' => 1,
'ECONOMICS_SECTOR_ID' => 0,
'COUNTRY_ID' => 0,
'IIN' => $iin)
));
Solution was simple. I just needed to add "verify_bool" item to the array for 'aClient' in "getClientsByKeyFields()" function with default value, so my edited code for $data is
$data = $soap_client->getClientsByKeyFields(array(
'aSessionID' => $session_id,
'aClient' => array(
'ID' => 0,
'Natural_Person_Bool' => 1,
'Class_ID' => 10,
'Sex_ID' => 0,
'SETTLEMENT_ID' => 0,
'DOCUMENT_TYPE_ID' => 0,
'ACTIVITY_KIND_ID' => 0,
'RESIDENT_BOOL' => 1,
'ECONOMICS_SECTOR_ID' => 0,
'COUNTRY_ID' => 0,
'IIN' => $iin,
'verify_bool' => 1)
));

Assign an array in an array variable in PHP

I want to assign an array as an value of another variable in PHP. First array is
<?php
$jsonData = array(
'EndUserIp' => $ipAddress,
'TokenId' => 'a58c1052-c08f-4f40-9a9c-8841de585a14',
'AdultCount' => 1,
'ChildCount' => 0,
'InfantCount' => 0,
'DirectFlight' => 1,
'OneStopFlight' => 0,
'JourneyType' => 1,
'Segments'
);
?>
The second array is:
<?php
$segmentVal = array(
'Origin' => 'DEL',
'Destination' => 'CCU',
'FlightCabinClass' => 2,
'PreferredDepartureTime' => '2017-10-13T00:00:00',
'PreferredArrivalTime' => '2017-10-13T00:00:00'
);
?>
I want to assign the second array as the value of Segment variable in the first array.
try $jsonData['Segments'] = $segmentVal;
Following way to do array combine.
1)
<?php
$segmentVal = array(
'Origin' => 'DEL',
'Destination' => 'CCU',
'FlightCabinClass' => 2,
'PreferredDepartureTime' => '2017-10-13T00:00:00',
'PreferredArrivalTime' => '2017-10-13T00:00:00'
);
$jsonData = array(
'EndUserIp' => $ipAddress,
'TokenId' => 'a58c1052-c08f-4f40-9a9c-8841de585a14',
'AdultCount' => 1,
'ChildCount' => 0,
'InfantCount' => 0,
'DirectFlight' => 1,
'OneStopFlight' => 0,
'JourneyType' => 1,
'Segments' => $segmentVal
);
?>
2)
<?php
$jsonData = array(
'EndUserIp' => $ipAddress,
'TokenId' => 'a58c1052-c08f-4f40-9a9c-8841de585a14',
'AdultCount' => 1,
'ChildCount' => 0,
'InfantCount' => 0,
'DirectFlight' => 1,
'OneStopFlight' => 0,
'JourneyType' => 1,
'Segments' => array(
'Origin' => 'DEL',
'Destination' => 'CCU',
'FlightCabinClass' => 2,
'PreferredDepartureTime' => '2017-10-13T00:00:00',
'PreferredArrivalTime' => '2017-10-13T00:00:00'
)
);
?>
I came up with two possible ways to do so
First one is passing encoding the second array with json as below
$jsonData = array(
'EndUserIp' => "192.168.0.10",
'TokenId' => 'a58c1052-c08f-4f40-9a9c-8841de585a14',
'AdultCount' => 1,
'ChildCount' => 0,
'InfantCount' => 0,
'DirectFlight' => 1,
'OneStopFlight' => 0,
'JourneyType' => 1,
'Segments' => json_encode($segmentVal),
);
The second one is similar
You can serialize the $segmentVal as below
$jsonData = array(
'EndUserIp' => "192.168.0.10",
'TokenId' => 'a58c1052-c08f-4f40-9a9c-8841de585a14',
'AdultCount' => 1,
'ChildCount' => 0,
'InfantCount' => 0,
'DirectFlight' => 1,
'OneStopFlight' => 0,
'JourneyType' => 1,
'Segments' => serialize($segmentVal),
);

kashflow api script keeps failing to connect

The problem I have is with the script that connects to kashflow from our website, when a customer enters their order and finalises the checkout the site is supposed to connect to kashflow but instead gives the following error.
Notice: Undefined index: $Name in
/home/expressn/public_html/ajax/kashflow/includes/kashflow.inc.php on
line 73
Unhandled exception: Customer name cannot be empty
It's been narrowed down to the following code we hope as Customer Name is apparently a blank string?
Would anyone be kind enough to tell me what needs to be done to solve this problem?
public function insertCustomer($customer){
$parameters['custr'] = array(
"CustomerID" => 0,
"Code" => '',
"Name" => $customer['Name'],
"Contact" => '',
"Telephone" => $customer['Telephone'],
"Mobile" => '',
"Fax" => '',
"Email" => $customer['Email'],
"Address1" => $customer['Address1'],
"Address2" => $customer['Address2'],
"Address3" => $customer['Address3'],
"Address4" => $customer['Address4'],
"Postcode" => $customer['Postcode'],
"Website" => '',
"EC" => 0,
"OutsideEC" => 0,
"Notes" => '',
"Source" => $this->m_source,
"Discount" => 0,
"ShowDiscount" => 0,
"PaymentTerms" => 0,
"ExtraText1" => '',
"ExtraText2" => '',
"ExtraText3" => '',
"ExtraText4" => '',
"ExtraText5" => '',
"ExtraText6" => '',
"ExtraText7" => '',
"ExtraText8" => '',
"ExtraText9" => '',
"ExtraText10" => '',
"ExtraText11" => '',
"ExtraText12" => '',
"ExtraText13" => '',
"ExtraText14" => '',
"ExtraText15" => '',
"ExtraText16" => '',
"ExtraText17" => '',
"ExtraText18" => '',
"ExtraText19" => '',
"ExtraText20" => '',
"CheckBox1" => 0,
"CheckBox2" => 0,
"CheckBox3" => 0,
"CheckBox4" => 0,
"CheckBox5" => 0,
"CheckBox6" => 0,
"CheckBox7" => 0,
"CheckBox8" => 0,
"CheckBox9" => 0,
"CheckBox10" => 0,
"CheckBox11" => 0,
"CheckBox12" => 0,
"CheckBox13" => 0,
"CheckBox14" => 0,
"CheckBox15" => 0,
"CheckBox16" => 0,
"CheckBox17" => 0,
"CheckBox18" => 0,
"CheckBox19" => 0,
"CheckBox20" => 0,
"Created" => date( "Y-m-d\TH:i:s"),
"Updated" => date( "Y-m-d\TH:i:s"),
"CurrencyID" => 0,
"ContactTitle" => '',
"ContactFirstName" => '',
"ContactLastName" => '',
"CustHasDeliveryAddress" => 1,
"DeliveryAddress1" => $customer['delAddress1'],
"DeliveryAddress2" => $customer['delAddress2'],
"DeliveryAddress3" => $customer['delAddress3'],
"DeliveryAddress4" => $customer['delAddress4'],
"DeliveryPostcode" => $customer['delPostcode'],
"VATNumber" => ''
);
return $this->makeRequest("InsertCustomer",$parameters);
}
Hello I know it has been a while now but I also ran into this problem.
From my experience the mandatory params are:
'CustomerID'=>0,
'EC'=>0,
'OutsideEC'=>0,
'Source'=>0,
'Discount'=>0,
'ShowDiscount'=>0,
'PaymentTerms'=>0,
'CheckBox1'=>0,
'CheckBox2'=>0,
'CheckBox3'=>0,
'CheckBox4'=>0,
'CheckBox5'=>0,
'CheckBox6'=>0,
'CheckBox7'=>0,
'CheckBox8'=>0,
'CheckBox9'=>0,
'CheckBox10'=>0,
'CheckBox11'=>0,
'CheckBox12'=>0,
'CheckBox13'=>0,
'CheckBox14'=>0,
'CheckBox15'=>0,
'CheckBox16'=>0,
'CheckBox17'=>0,
'CheckBox18'=>0,
'CheckBox19'=>0,
'CheckBox20'=>0,
'Created'=> '',
'Updated'=>'',
'CurrencyID'=>0,
'Name'=>''
The case that you use for the keys is also important so "EC" is not the same as "ec". The api also returns a blank object if you are not authenticated, this can make it seem as if it is working when it is not.
So one thing to check is that you are giving 'UserName' & 'Password' not 'username' & 'password' just another thing is that I found https://securedwebapp.com/api/service.asmx << this doc is much better than http://www.kashflow.com/developers/soap-api/ << this doc for detailing how to call the APIs.

pChart don't draw texts

I'm trying to drawn a chart with php and the pChart framework. The issue is that the texts of charts are not being drawn.
include "pChart2.1.1/class/pData.class.php";
include "pChart2.1.1/class/pDraw.class.php";
include "pChart2.1.1/class/pImage.class.php";
$myData = new pData();
## DEFINITION OF SERIES AND X AXIS... ##
$myData->setAbscissa("Absissa");
$myData->setAxisPosition(0, AXIS_POSITION_LEFT);
$myData->setAxisName(0, "1st axis");
$myData->setAxisUnit(0, "");
$myPicture = new pImage(1024, 600, $myData);
$Settings = array("R" => 255, "G" => 255, "B" => 255, "Dash" => 1, "DashR" => 275, "DashG" => 275, "DashB" => 275);
$myPicture->drawFilledRectangle(0, 0, 1024, 600, $Settings);
$myPicture->drawRectangle(0, 0, 1023, 599, array("R" => 0, "G" => 0, "B" => 0));
$myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 50, "G" => 50, "B" => 50, "Alpha" => 20));
$myPicture->setFontProperties(array("FontName" => "fonts/Bedizen.ttf", "FontSize" => 40));
$TextSettings = array("Align" => TEXT_ALIGN_TOPMIDDLE, "R" => 255, "G" => 255, "B" => 255);
$myPicture->drawText(512, 25, "Abertura Geral", $TextSettings);
$myPicture->setShadow(TRUE);
$myPicture->setGraphArea(50, 50, 999, 560);
$myPicture->setFontProperties(array("R" => 0, "G" => 0, "B" => 0, "FontName" => "fonts/pf_arma_five.ttf", "FontSize" => 6));
$Settings = array("Pos" => SCALE_POS_LEFTRIGHT
, "Mode" => SCALE_MODE_FLOATING
, "LabelingMethod" => LABELING_ALL
, "GridR" => 255, "GridG" => 255, "GridB" => 255, "GridAlpha" => 50, "TickR" => 0, "TickG" => 0, "TickB" => 0, "TickAlpha" => 50, "LabelRotation" => 0, "CycleBackground" => 1, "DrawXLines" => 1, "DrawSubTicks" => 1, "SubTickR" => 255, "SubTickG" => 0, "SubTickB" => 0, "SubTickAlpha" => 50, "DrawYLines" => ALL);
$myPicture->drawScale($Settings);
$myPicture->setShadow(TRUE, array("X" => 1, "Y" => 1, "R" => 50, "G" => 50, "B" => 50, "Alpha" => 10));
$Config = "";
$myPicture->drawLineChart($Config);
$Config = array("FontR" => 0, "FontG" => 0, "FontB" => 0, "FontName" => "fonts/pf_arma_five.ttf", "FontSize" => 6, "Margin" => 6, "Alpha" => 30, "BoxSize" => 5, "Style" => LEGEND_NOBORDER,
"Mode" => LEGEND_HORIZONTAL);
$myPicture->drawLegend(938, 16, $Config);
$myPicture->render("/tmp/t2.png");
And the result is a chart without any text.
Thank you for the help.
I think this is your problem
$TextSettings = array("Align" => TEXT_ALIGN_TOPMIDDLE, "R" => 255, "G" => 255, "B" => 255);
The text is white, same as the background you should change this line for this:
$TextSettings = array("Align" => TEXT_ALIGN_TOPMIDDLE, "R" => 0, "G" => 0, "B" => 0);
I hope that is all. Good luck

Categories