|
|
@@ -33,7 +33,7 @@ class ApiInvoiceHelper
|
|
|
$invoice['array_options_sales_group'] = $this->getGroupId();
|
|
|
$this->apiInvoice = new ApiInvoice;
|
|
|
$this->apiInvoice->loadData($invoice);
|
|
|
- $this->apiInvoice->prepareData();
|
|
|
+ $this->apiInvoice->prepareData($invoice['fk_multicurrency']);
|
|
|
$this->apiInvoice->validate();
|
|
|
ApiBbusLog::appLog("{$sendId} - createInvoice_________END - " . microtime(true));
|
|
|
return $this->apiInvoice->create($company_invoice);
|
|
|
@@ -75,7 +75,7 @@ class ApiInvoiceHelper
|
|
|
$invoice['array_options_sales_group'] = $this->getGroupId();
|
|
|
//print_r($invoice);exit;
|
|
|
$this->apiInvoice->loadData($invoice);
|
|
|
- $this->apiInvoice->prepareData();
|
|
|
+ $this->apiInvoice->prepareData($invoice['fk_multicurrency']);
|
|
|
$this->apiInvoice->validate();
|
|
|
return $this->apiInvoice->create();
|
|
|
}
|
|
|
@@ -223,7 +223,7 @@ class ApiInvoiceHelper
|
|
|
interface ApiInvoiceData
|
|
|
{
|
|
|
public function loadData(array $data): void;
|
|
|
- public function prepareData(): void;
|
|
|
+ public function prepareData($currency): void;
|
|
|
public function validate(): void;
|
|
|
public function create(); // missing return type because of the different result objects
|
|
|
}
|
|
|
@@ -252,7 +252,7 @@ class ApiInvoiceLine implements ApiInvoiceData
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
- public function prepareData(): void
|
|
|
+ public function prepareData($currency = null): void
|
|
|
{
|
|
|
$this->data->desc = sanitizeVal($this->data->desc, 'restricthtml');
|
|
|
$this->data->label = sanitizeVal($this->data->label);
|
|
|
@@ -322,7 +322,7 @@ class ApiInvoiceLine implements ApiInvoiceData
|
|
|
*/
|
|
|
class ApiInvoice implements ApiInvoiceData
|
|
|
{
|
|
|
- const SOCID = 1;
|
|
|
+ //const SOCID = 1;
|
|
|
|
|
|
public $data;
|
|
|
public $invoice;
|
|
|
@@ -337,11 +337,22 @@ class ApiInvoice implements ApiInvoiceData
|
|
|
/**
|
|
|
*
|
|
|
*/
|
|
|
- public function prepareData(): void
|
|
|
+ public function prepareData($currency): void
|
|
|
{
|
|
|
- global $user;
|
|
|
-
|
|
|
- $this->data['socid'] = self::SOCID;
|
|
|
+ global $user, $db;
|
|
|
+ $socid = 0;
|
|
|
+ $sql = "SELECT s.rowid FROM llx_societe as s
|
|
|
+ INNER JOIN llx_societe_extrafields as se ON se.fk_object = s.rowid
|
|
|
+ WHERE s.fk_multicurrency = {$currency} AND se.is_general_customer = 1";
|
|
|
+ $result = $db->query($sql);
|
|
|
+ if($db->num_rows($result) > 0){
|
|
|
+ while($row = $db->fetch_object($result)){
|
|
|
+ $socid = $row->rowid;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ throw new RestException(400, 'There is no General Customer');
|
|
|
+ }
|
|
|
+ $this->data['socid'] = $socid;
|
|
|
$this->data['entity'] = $user->entity;
|
|
|
}
|
|
|
/**
|