Is there a way to remove lines from an invoice using the Consolibyte quickbooks toolkit?
I can send invoices with lines but I would also like to update an invoice and I think the best way would be to remove each line and then send up the lines as they are currently. i.e: To update an invoice I would first get the invoice from quickbooks using the ref I store locally, remove the lines, then update the fields on the invoice object, then add the new lines and then send the invoice using the update method.
I have seen this example:
https://github.com/consolibyte/quickbooks-php/blob/master/docs/partner_platform/example_app_ipp_v3/example_invoice_update.php
But I am unsure how I could update individual lines as I have no reference to them stored locally, hence trying to remove them and then re-create.
Found the answer here:
How to access Quickbooks Invoice Line Items using php api
My solution looks like this, using Laravel:
public function qbUpdateInvoice(Invoice $invoice)
{
if ($invoice->qb_ref == null) {
throw new \Exception('Invoice Quickbooks ref not available.');
}
$qbInvoice = $this->findInvoiceByRef($invoice);
$count = $qbInvoice->countLine();
for ($i = 0; $i < $count; $i++) {
$qbInvoice->unsetLine($i);
}
$qbInvoice = $this->setInvoiceDetails($invoice, $qbInvoice);
$qbInvoice = $this->setInvoiceLines($invoice, $qbInvoice);
$response = $this->qbInvoiceService->update($this->context, $this->realm, $qbInvoice->getId(), $qbInvoice);
if (!$response) {
throw new \Exception($this->qbInvoiceService->lastError());
}
return $response;
}
Related
I am importing google contacts from a csv file in a specific manner, in the file I have 2 custom fields that need to be added to every contact when they are imported. I have added the first custom field but have no idea how to add a second one programatically. It seems possible as you can add a second custom field from the contact page. Here is the code to add one custom field to the contact:
$opened_file=fopen("export_test.csv", "r");
while(($data = fgetcsv($opened_file, 1000,",")) !== FALSE)
{
$contacts[] = $data;
}
$person = new Google_Service_PeopleService_Person();
$custom_field = new Google_Service_PeopleService_UserDefined();
for($i = 1; $i < count($contacts); $i++)
{
$custom_field->setKey($contacts[$i][50]);
$custom_field->setValue($contacts[$i][51]);
$person->setUserDefined($custom_field);
}
I have tried making a new user defined object, setting the key and value and attaching it to the person but this just overwrites the first custom field. I have also looked this issue up but turned up with nothing. Is it possible to add a second custom field programatically?
UserDefined is a list in the documentation https://developers.google.com/people/api/rest/v1/people#resource:-person.
I'm unsure about the PHP syntax, but based on examples in https://github.com/googleapis/google-api-php-client, try doing
$custom_field_array = array();
...
$person->setUserDefined($custom_field_array);
Good Day!
I am currently working on a QUICKBOOKS API payment and is using their DevKit https://github.com/consolibyte/quickbooks-php its working just fine, I can retrieve invoices and pay them individually. Now, I want to create a functionality that can pay multiple invoices in 1 payment. What I could think right now is doing a loop until all selected invoices gets paid individually but I guess its not the correct approach..
this is the code I got from the DevKit
$PaymentService = new QuickBooks_IPP_Service_Payment();
// Create payment object
$Payment = new QuickBooks_IPP_Object_Payment();
$Payment->setPaymentRefNum('WEB123');
$Payment->setTxnDate('2014-02-11');
$Payment->setTotalAmt(10);
// Create line for payment (this details what it's applied to)
$Line = new QuickBooks_IPP_Object_Line();
$Line->setAmount(10);
// The line has a LinkedTxn node which links to the actual invoice
$LinkedTxn = new QuickBooks_IPP_Object_LinkedTxn();
$LinkedTxn->setTxnId('{-84}');
$LinkedTxn->setTxnType('Invoice');
$Line->setLinkedTxn($LinkedTxn);
$Payment->addLine($Line);
$Payment->setCustomerRef('{-67}');
// Send payment to QBO
if ($resp = $PaymentService->add($Context, $realm, $Payment))
{
print('Our new Payment ID is: [' . $resp . ']');
}
else
{
print($PaymentService->lastError());
}
If I put them inside a loop, I am sure they will all get paid and also it will create multiple payments as well.
Is there any other much better ways to do this? please help. Thanks!
Just do this stuff more than one time:
// The line has a LinkedTxn node which links to the actual invoice
$LinkedTxn = new QuickBooks_IPP_Object_LinkedTxn();
$LinkedTxn->setTxnId('{-84}');
$LinkedTxn->setTxnType('Invoice');
$Line->setLinkedTxn($LinkedTxn);
$Payment->addLine($Line);
For example:
foreach ($invoices as $invoice_id)
{
// The line has a LinkedTxn node which links to the actual invoice
$LinkedTxn = new QuickBooks_IPP_Object_LinkedTxn();
$LinkedTxn->setTxnId($invoice_id);
$LinkedTxn->setTxnType('Invoice');
$Line->setLinkedTxn($LinkedTxn);
$Payment->addLine($Line);
}
I made it work with this code
$c = 0;
foreach ($invoice_ids as $i) {
$Line = new QuickBooks_IPP_Object_Line();
$Line->setAmount($i_line_amount[$c]); //amount per line
$LinkedTxn = new QuickBooks_IPP_Object_LinkedTxn();
$LinkedTxn->setTxnId($i);
$LinkedTxn->setTxnType('Invoice');
$Line->setLinkedTxn($LinkedTxn);
$Payment->addLine($Line);
$c++;
}
How can i Export only first 100 products from magento using magento inbuilt data flow profile functionality. i want to export first products but there are 20000 products there on my store so i want to export products in bunch of 1000.Waiting for suggestion.
You can do it by rewrite the core function getIdCollection() inside Mage_Dataflow_Model_Batch_Abstract class.
There is return all id collections, you can customize code there as you need it.
Currently return code as per following:
return $this->getResource()->getIdCollection($this), you can replace code as per following
//return $this->getResource()->getIdCollection($this);
$idArray = array();
foreach($this->getResource()->getIdCollection($this) as $key => $val){
if($key < 100){
$idArray[] = $val;
}
}
return $idArray;
After Please check downloaded csv, don't see loaded records on popup window Hope this would help you!..
We have been trying to modify the Customer.php file ( import/export ) to get it to send out the new account details automatically as it imports the customers from a CSV file.
We are working in the right area as we dropped a simple mail() call which was called (we received the emails) for every new row. The problem arises when trying to get it to generate a new random password and send out the new account details - it never sends any mail and we cannot figure out why! Code follows ( Edited from app/code/local/Mage/ImportExport/Model/Import/Entity/Customer.php )
/**
* Update and insert data in entity table.
*
* #param array $entityRowsIn Row for insert
* #param array $entityRowsUp Row for update
* #return Mage_ImportExport_Model_Import_Entity_Customer
*/
protected function _saveCustomerEntity(array $entityRowsIn, array $entityRowsUp)
{
if ($entityRowsIn) {
$this->_connection->insertMultiple($this->_entityTable, $entityRowsIn);
// BEGIN: Send New Account Email
$cust = Mage::getModel('customer/customer');
$cust->setWebsiteId(Mage::app()->getWebsite()->getId());
foreach($entityRowsIn as $idx => $u){
// Failed
$cust->loadByEmail($u['email']);
$cust->setConfirmation(NULL);
$cust->setPassword($cust->generatePassword(8));
$cust->save();
$cust->sendNewAccountEmail();
//$cust->sendPasswordReminderEmail(); // this call doesnt work either
}
// END: Send New Account Email
}
if ($entityRowsUp) {
$this->_connection->insertOnDuplicate(
$this->_entityTable,
$entityRowsUp,
array('group_id', 'store_id', 'updated_at', 'created_at')
);
}
return $this;
}
Inorder to improve performance magento 'caches' object, so when trying to load an object in a loop you either need to load a new instance or call it reset() method
$website_id = Mage::app()->getWebsite()->getId();
foreach($entityRowsIn as $idx => $u){
$cust = Mage::getModel('customer/customer');
$cust->setWebsiteId($website_id);
$cust->loadByEmail($u['email']);
$cust->setPassword($cust->generatePassword(8));
$cust->save();
$cust->sendNewAccountEmail(); // if you are getting 2 email then remove this line
}
If you are load a large number of customers then you may run in to memory issues and my need to look a other technique using reset()
If this code is being run from the Administration section of Magento then you will need to make sure that you set the correct Website ID ( Mage::app()->getWebsite()->getId() will return the incorrect one ).
From the front end this code will work fine but for Admin work you should use '1' or whatever your Front end websites ID is as the getId() method was returning '0' in the Admin area! Small gotcha but had me going for hours!
I had found this script on how to Auto generate password for existing customers
$passwordLength = 10;
$customers = Mage::getModel('customer/customer')->getCollection();
foreach ($customers as $customer){
$customer->setPassword($customer->generatePassword($passwordLength))->save();
$customer->sendNewAccountEmail();
}
I'm trying to display the subscriber count from a MailChimp mailing list using their API, and I've got it partially working, except the code below is currently spitting out the subscriber count for all lists, rather than for one specific list. I've specified the list id in the line $listId ='XXX'; but that doesn't seem to be working. Because I have five lists in total, the output from the PHP below shows this:
10 0 0 1 9
What do I need to do in my code below to get the subscriber count from a specific list id?
<?php
/**
This Example shows how to pull the Members of a List using the MCAPI.php
class and do some basic error checking.
**/
require_once 'inc/MCAPI.class.php';
$apikey = 'XXX';
$listId = 'XXX';
$api = new MCAPI($apikey);
$retval = $api->lists();
if ($api->errorCode){
echo "Unable to load lists()!";
echo "\n\tCode=".$api->errorCode;
echo "\n\tMsg=".$api->errorMessage."\n";
} else {
foreach ($retval['data'] as $list){
echo "\t ".$list['stats']['member_count'];
}
}
?>
I just came across this function (see below) that let's me return a single list using a known list_id. The problem is, I'm not sure how to add the list_id in the function.
I'm assuming I need to define it in this line? $params["filters"] = $filters;
The MailChimp lists() method documentation can be referred to here: http://apidocs.mailchimp.com/rtfm/lists.func.php
function lists($filters=array (
), $start=0, $limit=25) {
$params = array();
$params["filters"] = $filters;
$params["start"] = $start;
$params["limit"] = $limit;
return $this->callServer("lists", $params);
}
I'd strongly recommend not mucking with the internals of the wrapper as it's not going to be nearly as helpful as the online documentation and the examples included with the wrapper. Using the wrapper means the line you tracked down will effectively be filled when make the proper call.
Anywho, this is what you want:
$filters = array('list_id'=>'XXXX');
$lists = $api->lists($filters);
Mailchimp provides a pre-built php wrapper around their api at http://apidocs.mailchimp.com/downloads/#php. This api includes a function lists() which, according to its documentation, returns among other things:
int member_count The number of active members in the given list.
It looks like this is the function which you are referring to above. All you should have to do is iterate through the lists that are returned to find the one with the proper id. From there you should be able to query the subscriber count along with a number of other statistics about the list.