Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Using the standard 'create invoice from salesorder' in workflows
#18
I don't fully understand this code:

PHP Code:
$focus CRMEntity::getInstance('Invoice');

list(
$so_wsid,$soid) = explode('x',$entity->getId());
$so_focus CRMEntity::getInstance('SalesOrder');
$so_focus->id $soid;
$so_focus->retrieve_entity_info($soid"SalesOrder");
$focus getConvertSoToInvoice($focus$so_focus$soid);  // this will do the Mapping for the duedate and others SalesOrder2Invoice

 // we do this to get the pdoInformation array
$wsso vtws_retrieve($entity->getId(), $current_user);
$focus->column_fields['pdoInformation'] = $wsso['pdoInformation'];

$invoice vtws_create('Invoice'$focus->column_fields$current_user); 

First, we create an invoice instance. Then we get the SO's CRM id. We also create a Salesorder instance. Both instances are empty, they still have to be filled with specific data. We do that by calling 'retrieve_entity_info' which we feed the CRM id but still, one line before that we have to manually set the SO's instance with the SO ID? Then, after we've told so_focus which ID it needs to base itself on, we have to feed the soid yet again to the 'getConvertSoToInvoice' function?


I am testing the instance of invoice now, after I call the getConvertSoToInvoice. It seems now I know why the native Account number and salesorder ID were never filled out on creating an invoice ffrom a sales order: this function does not fill them.

I now have the following code in a test file:


PHP Code:
<?php

error_reporting
(E_ERROR);
ini_set("display_errors""on");

include_once 
'include/Webservices/Retrieve.php';
include_once 
'include/Webservices/Create.php';
include_once 
'modules/Users/Users.php';

$user = new Users();
$current_user $user->retrieveCurrentUserInfoFromFile(Users::getActiveAdminId());

/*=========== Retrieve SO =============*/
// Retrieve SO crmid
global $adb;
$query 'SELECT salesorderid FROM vtiger_salesorder WHERE salesorder_no=?';
$params = array('ORD160935');
$result $adb->pquery($query$params);
$so_crmid $adb->query_result($result0'salesorderid');

// Get the SO
$so_focus CRMEntity::getInstance('SalesOrder');
$so_focus->id $so_crmid;
$so_focus->retrieve_entity_info($so_crmid"SalesOrder");

// Create invoice instance
$focus CRMEntity::getInstance('Invoice');
$focus getConvertSoToInvoice($focus$so_focus$so_crmid);

$invoice vtws_create('Invoice'$focus->column_fields$current_user);

echo 
"<pre>";
var_dump($focus->column_fields);
echo 
"</pre>"

The first lines are only for testing of course (the lines that get the SO crm id from the DB). It gives me:

Code:
Fatal error: Uncaught exception 'WebServiceException' with message 'Permission to perform the operation is denied for id' in /

Wait, again the WEBSERVICE ID of course.... stupid of me.
Reply


Messages In This Thread
RE: Using the standard 'create invoice from salesorder' in workflows - Guido1982 - 08-08-2016, 07:34 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)