I am trying to find a flag to determine whether a QuickBooks Customer has new invoices. I am syncing the invoices, and next time when I try to sync I want to check whether there are any new Invoices OR updated once.
There is a syncToken in Customer record but it only shows the updates for the Customer object.
Is there a way to check for the updated Invoices OR New onces, other than syncing all?
The way we handled this is by storing the last sync time. Add the last sync time as a filter to the QuickBooks SDK query object. First time, ALL invoices are synced. During the next sync, the ones that have been created or modified after the last sync time are synced. Here's a C# code sample from a Windows service that we are using:
using QBXMLRP2Lib;
using Interop.QBFC13;
public void SyncTransactions(QBSessionManager sessionMgr, DateTime? fromModifiedDate)
{
IMsgSetRequest msgset = sessionMgr.CreateMsgSetRequest("US", 13, 0);
IInvoiceQuery invoiceQuery = msgset.AppendInvoiceQueryRq();
invoiceQuery.IncludeLineItems.SetValue(true); // true if line items from a transaction have to included in the result set
if (fromModifiedDate != null)
{
invoiceQuery.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.ModifiedDateRangeFilter.FromModifiedDate.SetValue(fromModifiedDate.Value, false);
invoiceQuery.ORInvoiceQuery.InvoiceFilter.ORDateRangeFilter.ModifiedDateRangeFilter.FromModifiedDate.SetTimeZone(0, 0); // UTC, since we keep the last sync time in UTC
IMsgSetResponse msgRes = sessionMgr.DoRequests(msgset);
IResponseList responseList = msgRes.ResponseList;
if (responseList.Count > 0)
{
// process the results here
}
}
}
Hope this helps.
I figure it out after #Naveen's Answer.
Basically the syncToken is good to use when we deal with single record at a time. We can keep syncToken in our database and check it against QuickBooks next time.
But when it comes to bulk record fetching its good to use LastUpdatedTime.
To filter invoices what I did was query QuickBooks as below,
$InvoiceService = new QuickBooks_IPP_Service_Invoice();
$invoices = $InvoiceService->query($Context, $realm, "SELECT * FROM Invoice where MetaData.LastUpdatedTime > <date>";
Note: <date> should be in long date format. Ex: 2004-02-12T15:19:21+00:00. We can get this date format by date('c', mySql date);
Cheers..!!! Thanks again #Naveen for your tip
Related
Task:
I am creating a way that a frontend user can send a message and schedule a time for it to be delivered. To accomplish this, I am storing the message info in database tables and then Setting a queue to fire a send function at the appropriate time.
Question:
If the user changes their mind about the time to send the message after this code is executed, is there a way to remove this from the queue and then re add it to fire at a different time?
Example
$data = ['message_id' => $this->messageModel->id];
$queue = Queue::later($this->send_at, 'KurtJensen\Twilio\Classes\SendQueue', $data);
// ==== Everything works great up to this point =======
// Don't know if this will work
// Can I get a queue identifier here?
$this->messageModel->queue_id = $queue->id;
$this->messageModel->save();
Then later to change time:
$this->messageModel= Message::find($id);
$q_id = $this->messageModel->queue_id;
// ==== I doubt this would work or if canceling a queue is possible =======
Queue::cancel($q_id);
$queue = Queue::later($new_time, 'KurtJensen\Twilio\Classes\SendQueue', $data);
$this->messageModel->queue_id = $queue->id;
$this->messageModel->save();
I would like to limit the access of a function i've created to once every 24 hour based on the users IP address. I would also like the PHP script to delete the MySQL record if it's older than 24 hours.
If the user already has used the function within 24 hours, show them a message and prevent the script from continue running.
If the user already has used the function but 24 hours has passed since he used the function, delete the MySQL record and let the script continue running.
I'm lost and as you can see i am also missing some statements for deleting old records (-24 hours)..
Could anyone provide me with an example of how to do this? Thanks
Get client's IP address and store it with current date and time if the record doesn't exist.
Fetch the record and add 24 hours to its date and time value and check it with the current date and time every time the script is executed.
You need if else conditional statements to check if the 24 hours time is over or not. Based on that, you will control the execution of the function you want to.
I think I don't want to write much of theory. Here, I've written the pattern what the code looks like:
if(!$record_in_db) {
// create record with the client's ip address and the current date and time
// invoke the function you want - This is the code to trigger the function first time for the new IP address
} else {
// fetch_record_from_db
// add 24 hours to its date and time value
// check it with current date and time
$record_date_time = new DateTime('22-12-2016 22:45:20'); // this value should be fetched from database
$record_date_time_by_24_hours = $record_date_time->modify('+1 day');
$current_date_time = new DateTime(date('d-m-Y H:i:s', strtotime('now')));
$date_time_diff = $current_date_time->diff($record_date_time_by_24_hours);
if($date_time_diff->invert == 0) {
// Do something
} else {
// update the date and time of the record to NOW which is current date and time
// invoke the function you want
}
}
I can't write you the whole code. I could only give you some hints. You need to build the code from it. Hope I've given you right hints that could help you.
So I'm creating an application that allows users to record a message through Twilio and I'm attempting to store the RecordingSID, the date it was created, and the duration of the recording in a MySQLi database right after the recording has been made. I've managed to get the RecordingSID by taking the last 34 digits off the RecordingURL using the substr() function and am simply getting whatever today's date is for the date created field in my database table. However, seemingly regardless of how long the actual recording is, I'm continually getting a value of 8 when attempting to get the recording duration. Here's what I've got right now (with database inserts omitted since they work):
<?php
$recordingURL = $_REQUEST['RecordingUrl'];
$recordingSID = substr($recordingURL, -34);
date_default_timezone_set('EST');
$dateCreated = date("Y-m-d");
$duration = $_REQUEST['RecordingDuration'];
?>
Any help with this matter would be fantastic! Thanks!
Edit: I've also tried the following solution in place of the last line in my previous code snippet:
<?php
$recordings = $client->account->recordings->getIterator(0, 50, array('Sid' => $recordingSID,));
foreach ($recordings as $recording)
{
$duration = $recording->duration;
}
?>
Based on that code sample you've pasted in, you could be doing a couple of things incorrectly. Correct me if I'm wrong, but I believe you are trying to request a Recording resource back from the Twilio API after you've submitted one with the Twilio js and their TwiML?
If so, twilio actually has a nice little demo of exactly your use case.
You shouldn't see anything in the $_REQUEST['RecordingDuration'], I'm not sure why you are even getting a value of 8 returned. Basically what you want to do is find the users recordings by using the Twilio REST API.
here is an example snippet:
<?php
// Get the PHP helper library from twilio.com/docs/php/install
require_once('/path/to/twilio-php/Services/Twilio.php'); // Loads the library
// Your Account Sid and Auth Token from twilio.com/user/account
$sid = "ACda6f132a3c49700934481addd5ce1659";
$token = "{{ auth_token }}";
$client = new Services_Twilio($sid, $token);
// Loop over the list of recordings and echo a property for each one
foreach ($client->account->recordings as $recording) {
echo $recording->duration;
}
The response from the API call will return a Recording resource.
Here is some more examples from their docs
I have around 10000 records in a mysql table which has id, info and ip columns. ip columns are empty. I want to display one row at a time whenever the page refreshes. For every row displayed i want to store the IP of the client refreshing the page. So whenever the page is refreshed from that IP it displays same info.
I hope i explained it well. How can I make sure that it displays correct row everytime page is refreshed and i don't make extra mysql queries.
Currently I am fetching up all the rows every time person opens the page and then filtering it but I know this is not efficient. Please help
I hope understand you. So, you want show the same row to a IP that it already saved:
// Controller...
$ip = $container->get('request')->getClientIp(); // The ip
$em = $this->getDoctrine()->getManager(); // Get the Entity Manager
// First check if the ip has assigned a record
$record = $em->getRepository('AcmeStoreBundle:Records')
->findOneByIp( $ip );
if( !$record ){ // There isn't a IP assigned
$record = $em->getRepository('AcmeStoreBundle:Records')
->findOneBy( array('ip' => null) ); // Get other record to assign
$record->setIp( $ip );
$em->flush(); // Save the ip
}
return new Response('Record info: ' . $record->getInfo() );
The first time you get a record doesn't used, after you get the same record for your IP.
Use the iterate() method together with batch processing.
http://docs.doctrine-project.org/en/2.0.x/reference/batch-processing.html
If you need only a subset of the records, you can use setFirstResult($num) and setMaxResults($num).
How Can I find whether the transaction made by user is settled or Unsettled in the authorize.net.I am using AIM.
I want to get through coding.When the transaction is completed and I cant find transaction status.But I want to get whether it goes for settled or unsettled transaction.
Thanks in advance.
You cannot get this information through coding as no API Authorize.Net offers allows for this. It can only be done through the control panel. When you process a transaction and it is approved you can assume the transaction is unsettled. Transactions are settled once per day usually around midnight Pacific Time. After that you can assume a transaction is settled.
As of 03-16-2011 authorize.net has released two new calls to the Transaction Details API, getUnsettledTransactionList and getBatchStatistics.
getUnsettledTransactionList returns up to 1,000 unsettled transactions per call, returning the most recent transactions. The information returned in the response will be the same as what's returned in getTransactionList call.
getBatchStatistics returns the batch stats for a single batch like settlement state and time, charge count, decline count, etc.
For more info, check out the XML guide and the SOAP guide.
At the time of writing the PHP SDK is at version 1.1.6 and does not have this function built into the TD api, however if you look at the documentation provided above, as well as this example page, you will see that getting a list of unsettled transactions is in fact possible.
from this page
I've followed this link http://developer.authorize.net/api/transaction_details/ and get this code from there,
<?php
require_once "anet_php_sdk/AuthorizeNet.php";
define("AUTHORIZENET_API_LOGIN_ID", "YOURLOGIN");
define("AUTHORIZENET_TRANSACTION_KEY", "YOURKEY");
// Get Settled Batch List
$request = new AuthorizeNetTD;
$response = $request->getSettledBatchList();
echo count($response->xml->batchList->batch) . " batches\n";
foreach ($response->xml->batchList->batch as $batch) {
echo "Batch ID: " . $batch->batchId . "\n";
}
// Get Transaction Details
$transactionId = "12345";
$response = $request->getTransactionDetails($transactionId);
echo $response->xml->transaction->transactionStatus;
but I m getting this error message.
User authentication failed due to invalid authentication values.
As suggested in #cwd's answer, the most reliable way to know if a transaction is settled is to call getUnsettledTransactionList or getBatchStatistics, but you can also just check what your Transaction Cut-off Time is set to.
Log in to your Authorize.net admin, click Account > Transaction Cut-Off Time
My account is set to 4:00 PM PDT so you can just compare your transaction time to the cut off time. Something like:
$createdTime = new DateTime($charge['createdTime']);
// starting point for settle time
$settleTime = new DateTime($createdTime->format('Y-m-d') . ' 16:00:00');
$now = new DateTime();
// if card was charged after settle time for
// that day, move settle time to the next day
if ($createdTime > $settleTime) {
$settleTime->add(new DateInterval('P1D'));
}
if ($now > $settleTime) $settled = true;
http://developer.authorize.net/api/transaction_details/ is the API you are looking for.