diff --git a/htdocs/api/class/api.class.php b/htdocs/api/class/api.class.php
index 00621fdeb59..550fd790d5e 100644
--- a/htdocs/api/class/api.class.php
+++ b/htdocs/api/class/api.class.php
@@ -86,8 +86,11 @@ class DolibarrApi
function _cleanObjectDatas($object) {
// Remove $db object property for object
- unset($object->db);
-
+ unset($object->db);
+
+ // Remove linkedObjects. We should already have linkedObjectIds that avoid huge responses
+ unset($object->linkedObjects);
+
// Remove the $oldcopy property because it is not supported by the JSON
// encoder. The following error is generated when trying to serialize
// it: "Error encoding/decoding JSON: Type is not supported"
@@ -109,13 +112,15 @@ class DolibarrApi
}
// If object has linked objects, remove $db property
+ /*
if(isset($object->linkedObjects) && count($object->linkedObjects) > 0) {
foreach($object->linkedObjects as $type_object => $linked_object) {
foreach($linked_object as $object2clean) {
$this->_cleanObjectDatas($object2clean);
}
}
- }
+ }*/
+
return $object;
}
diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php
index 1f560775b7b..b4c540d6c57 100644
--- a/htdocs/commande/class/api_orders.class.php
+++ b/htdocs/commande/class/api_orders.class.php
@@ -156,7 +156,7 @@ class Orders extends DolibarrApi
throw new RestException(503, 'Error when retrieve commande list');
}
if( ! count($obj_ret)) {
- throw new RestException(404, 'No commande found');
+ throw new RestException(404, 'No order found');
}
return $obj_ret;
}
@@ -178,15 +178,16 @@ class Orders extends DolibarrApi
foreach($request_data as $field => $value) {
$this->commande->$field = $value;
}
- if (isset($request_data["lines"])) {
+ /*if (isset($request_data["lines"])) {
$lines = array();
foreach ($request_data["lines"] as $line) {
array_push($lines, (object) $line);
}
$this->commande->lines = $lines;
- }
- if(! $this->commande->create(DolibarrApiAccess::$user) ) {
- throw new RestException(500, "Error while creating order");
+ }*/
+ if ($this->commande->create(DolibarrApiAccess::$user) <= 0) {
+ $errormsg = $this->commande->error;
+ throw new RestException(500, $errormsg ? $errormsg : "Error while creating order");
}
return $this->commande->id;
@@ -208,7 +209,7 @@ class Orders extends DolibarrApi
$result = $this->commande->fetch($id);
if( ! $result ) {
- throw new RestException(404, 'Commande not found');
+ throw new RestException(404, 'Order not found');
}
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
@@ -239,7 +240,7 @@ class Orders extends DolibarrApi
$result = $this->commande->fetch($id);
if( ! $result ) {
- throw new RestException(404, 'Commande not found');
+ throw new RestException(404, 'Order not found');
}
if( ! DolibarrApi::_checkAccessToResource('commande',$this->commande->id)) {
diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php
index dbb815bb663..5396625fcb5 100644
--- a/htdocs/commande/class/commande.class.php
+++ b/htdocs/commande/class/commande.class.php
@@ -693,8 +693,8 @@ class Commande extends CommonOrder
* Note that this->ref can be set or empty. If empty, we will use "(PROV)"
*
* @param User $user Objet user that make creation
- * @param int $notrigger Disable all triggers
- * @return int <0 if KO, >0 if OK
+ * @param int $notrigger Disable all triggers
+ * @return int <0 if KO, >0 if OK
*/
function create($user, $notrigger=0)
{
@@ -808,37 +808,43 @@ class Commande extends CommonOrder
*/
for ($i=0;$i<$num;$i++)
{
+ $line = $this->lines[$i];
+
+ // Test and convert into object this->lines[$i]. When coming from REST API, we may still have an array
+ //if (! is_object($line)) $line=json_decode(json_encode($line), FALSE); // convert recursively array into object.
+ if (! is_object($line)) $line = (object) $line;
+
// Reset fk_parent_line for no child products and special product
- if (($this->lines[$i]->product_type != 9 && empty($this->lines[$i]->fk_parent_line)) || $this->lines[$i]->product_type == 9) {
+ if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
$fk_parent_line = 0;
}
$result = $this->addline(
- $this->lines[$i]->desc,
- $this->lines[$i]->subprice,
- $this->lines[$i]->qty,
- $this->lines[$i]->tva_tx,
- $this->lines[$i]->localtax1_tx,
- $this->lines[$i]->localtax2_tx,
- $this->lines[$i]->fk_product,
- $this->lines[$i]->remise_percent,
- $this->lines[$i]->info_bits,
- $this->lines[$i]->fk_remise_except,
+ $line->desc,
+ $line->subprice,
+ $line->qty,
+ $line->tva_tx,
+ $line->localtax1_tx,
+ $line->localtax2_tx,
+ $line->fk_product,
+ $line->remise_percent,
+ $line->info_bits,
+ $line->fk_remise_except,
'HT',
0,
- $this->lines[$i]->date_start,
- $this->lines[$i]->date_end,
- $this->lines[$i]->product_type,
- $this->lines[$i]->rang,
- $this->lines[$i]->special_code,
+ $line->date_start,
+ $line->date_end,
+ $line->product_type,
+ $line->rang,
+ $line->special_code,
$fk_parent_line,
- $this->lines[$i]->fk_fournprice,
- $this->lines[$i]->pa_ht,
- $this->lines[$i]->label,
- $this->lines[$i]->array_options,
- $this->lines[$i]->fk_unit,
+ $line->fk_fournprice,
+ $line->pa_ht,
+ $line->label,
+ $line->array_options,
+ $line->fk_unit,
$this->element,
- $this->lines[$i]->id
+ $line->id
);
if ($result < 0)
{
@@ -851,7 +857,7 @@ class Commande extends CommonOrder
return -1;
}
// Defined the new fk_parent_line
- if ($result > 0 && $this->lines[$i]->product_type == 9) {
+ if ($result > 0 && $line->product_type == 9) {
$fk_parent_line = $result;
}
}
diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php
index 68d0d1b5567..ce07251aa95 100644
--- a/htdocs/compta/facture.php
+++ b/htdocs/compta/facture.php
@@ -2520,58 +2520,6 @@ if ($action == 'create')
print '
| ' . $langs->trans('MulticurrencyTotalTTC') . ' | ' . price($objectsrc->multicurrency_total_ttc) . " |
";
}
}
- else
- {
- // Show deprecated optional form to add product line here
- if (! empty($conf->global->PRODUCT_SHOW_WHEN_CREATE)) {
- print '';
-
- // Zone de choix des produits predefinis a la creation
- print '';
- print '';
- print '| ' . $langs->trans('ProductsAndServices') . ' | ';
- print '' . $langs->trans('Qty') . ' | ';
- print '' . $langs->trans('ReductionShort') . ' | ';
- print ' | ';
- if (! empty($conf->service->enabled)) {
- print '' . $langs->trans('ServiceLimitedDuration') . ' | ';
- }
- print ' ';
- for($i = 1; $i <= $NBLINES; $i ++) {
- print '';
- print '| ';
- // multiprix
- if (! empty($conf->global->PRODUIT_MULTIPRICES))
- $form->select_produits('', 'idprod' . $i, '', $conf->product->limit_size, $soc->price_level);
- else
- $form->select_produits('', 'idprod' . $i, '', $conf->product->limit_size);
- print ' | ';
- print ' | ';
- print '% | ';
- print ' | ';
- // Si le module service est actif, on propose des dates de debut et fin a la ligne
- if (! empty($conf->service->enabled)) {
- print '';
- print '';
- print '| ';
- print $langs->trans('From') . ' ';
- print ' | ';
- print $form->select_date('', 'date_start' . $i, $usehm, $usehm, 1, "add", 1, 0, 1);
- print ' | ';
- print '';
- print $langs->trans('to') . ' ';
- print ' | ';
- print $form->select_date('', 'date_end' . $i, $usehm, $usehm, 1, "add", 1, 0, 1);
- print ' | ';
- print ' | ';
- }
- print " \n";
- }
-
- print ' ';
- print ' |
';
- }
- }
print "\n";
diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php
index 8fc6274b1a6..e14ed12dce3 100644
--- a/htdocs/compta/facture/class/api_invoices.class.php
+++ b/htdocs/compta/facture/class/api_invoices.class.php
@@ -68,7 +68,7 @@ class Invoices extends DolibarrApi
$result = $this->invoice->fetch($id);
if( ! $result ) {
- throw new RestException(404, 'Facture not found');
+ throw new RestException(404, 'Invoice not found');
}
if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
@@ -128,6 +128,7 @@ class Invoices extends DolibarrApi
$sql .= " AND sc.fk_user = ".$search_sale;
}
+ // TODO remove this, useless for WS
$nbtotalofrecords = 0;
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
{
@@ -178,7 +179,7 @@ class Invoices extends DolibarrApi
function post($request_data = NULL)
{
if(! DolibarrApiAccess::$user->rights->facture->creer) {
- throw new RestException(401);
+ throw new RestException(401, "Insuffisant rights");
}
// Check mandatory fields
$result = $this->_validate($request_data);
@@ -189,8 +190,18 @@ class Invoices extends DolibarrApi
if(! array_keys($request_data,'date')) {
$this->invoice->date = dol_now();
}
- if( ! $this->invoice->create(DolibarrApiAccess::$user)) {
- throw new RestException(500);
+ /* We keep lines as an array
+ if (isset($request_data["lines"])) {
+ $lines = array();
+ foreach ($request_data["lines"] as $line) {
+ array_push($lines, (object) $line);
+ }
+ $this->invoice->lines = $lines;
+ }*/
+
+ if ($this->invoice->create(DolibarrApiAccess::$user) <= 0) {
+ $errormsg = $this->invoice->error;
+ throw new RestException(500, $errormsg ? $errormsg : "Error while creating order");
}
return $this->invoice->id;
}
@@ -210,7 +221,7 @@ class Invoices extends DolibarrApi
$result = $this->invoice->fetch($id);
if( ! $result ) {
- throw new RestException(404, 'Facture not found');
+ throw new RestException(404, 'Invoice not found');
}
if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) {
@@ -240,7 +251,7 @@ class Invoices extends DolibarrApi
}
$result = $this->invoice->fetch($id);
if( ! $result ) {
- throw new RestException(404, 'Facture not found');
+ throw new RestException(404, 'Invoice not found');
}
if( ! DolibarrApi::_checkAccessToResource('facture',$this->facture->id)) {
diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php
index 1cc4abce751..d8f290e82a1 100644
--- a/htdocs/compta/facture/class/facture.class.php
+++ b/htdocs/compta/facture/class/facture.class.php
@@ -449,7 +449,7 @@ class Facture extends CommonInvoice
/*
* Insert lines of invoices into database
*/
- if (count($this->lines) && is_object($this->lines[0])) // If this->lines is array on InvoiceLines (preferred mode)
+ if (count($this->lines) && is_object($this->lines[0])) // If this->lines is array of InvoiceLines (preferred mode)
{
$fk_parent_line = 0;
@@ -483,49 +483,56 @@ class Facture extends CommonInvoice
}
}
}
- else // If this->lines is not object of invoice lines
+ else // If this->lines is an array of invoice line arrays
{
$fk_parent_line = 0;
dol_syslog("There is ".count($this->lines)." lines that are array lines");
+
foreach ($this->lines as $i => $val)
{
- if (($this->lines[$i]->info_bits & 0x01) == 0) // We keep only lines with first bit = 0
+ $line = $this->lines[$i];
+
+ // Test and convert into object this->lines[$i]. When coming from REST API, we may still have an array
+ //if (! is_object($line)) $line=json_decode(json_encode($line), FALSE); // convert recursively array into object.
+ if (! is_object($line)) $line = (object) $line;
+
+ if (($line->info_bits & 0x01) == 0) // We keep only lines with first bit = 0
{
// Reset fk_parent_line for no child products and special product
- if (($this->lines[$i]->product_type != 9 && empty($this->lines[$i]->fk_parent_line)) || $this->lines[$i]->product_type == 9) {
+ if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
$fk_parent_line = 0;
}
$result = $this->addline(
- $this->lines[$i]->desc,
- $this->lines[$i]->subprice,
- $this->lines[$i]->qty,
- $this->lines[$i]->tva_tx,
- $this->lines[$i]->localtax1_tx,
- $this->lines[$i]->localtax2_tx,
- $this->lines[$i]->fk_product,
- $this->lines[$i]->remise_percent,
- $this->lines[$i]->date_start,
- $this->lines[$i]->date_end,
- $this->lines[$i]->fk_code_ventilation,
- $this->lines[$i]->info_bits,
- $this->lines[$i]->fk_remise_except,
+ $line->desc,
+ $line->subprice,
+ $line->qty,
+ $line->tva_tx,
+ $line->localtax1_tx,
+ $line->localtax2_tx,
+ $line->fk_product,
+ $line->remise_percent,
+ $line->date_start,
+ $line->date_end,
+ $line->fk_code_ventilation,
+ $line->info_bits,
+ $line->fk_remise_except,
'HT',
0,
- $this->lines[$i]->product_type,
- $this->lines[$i]->rang,
- $this->lines[$i]->special_code,
+ $line->product_type,
+ $line->rang,
+ $line->special_code,
$this->element,
- $this->lines[$i]->id,
+ $line->id,
$fk_parent_line,
- $this->lines[$i]->fk_fournprice,
- $this->lines[$i]->pa_ht,
- $this->lines[$i]->label,
- $this->lines[$i]->array_options,
- $this->lines[$i]->situation_percent,
- $this->lines[$i]->fk_prev_id,
- $this->lines[$i]->fk_unit
+ $line->fk_fournprice,
+ $line->pa_ht,
+ $line->label,
+ $line->array_options,
+ $line->situation_percent,
+ $line->fk_prev_id,
+ $line->fk_unit
);
if ($result < 0)
{
@@ -536,7 +543,7 @@ class Facture extends CommonInvoice
}
// Defined the new fk_parent_line
- if ($result > 0 && $this->lines[$i]->product_type == 9) {
+ if ($result > 0 && $line->product_type == 9) {
$fk_parent_line = $result;
}
}