From dac99c774515f76b9e422dc54d1dc964d0df1ad5 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Mon, 16 Oct 2017 20:16:30 +0200 Subject: [PATCH 01/13] Missing menus in links on index stats --- htdocs/index.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/htdocs/index.php b/htdocs/index.php index 007145083cf..ea5d097e2c3 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -285,21 +285,21 @@ if (empty($user->societe_id)) // Dashboard Link lines $links=array( DOL_URL_ROOT.'/user/index.php', - DOL_URL_ROOT.'/societe/list.php?type=c', - DOL_URL_ROOT.'/societe/list.php?type=p', - DOL_URL_ROOT.'/societe/list.php?type=f', - DOL_URL_ROOT.'/contact/list.php', + DOL_URL_ROOT.'/societe/list.php?type=c&mainmenu=companies', + DOL_URL_ROOT.'/societe/list.php?type=p&mainmenu=companies', + DOL_URL_ROOT.'/societe/list.php?type=f&mainmenu=companies', + DOL_URL_ROOT.'/contact/list.php?mainmenu=companies', DOL_URL_ROOT.'/adherents/list.php?statut=1&mainmenu=members', DOL_URL_ROOT.'/product/list.php?type=0&mainmenu=products', DOL_URL_ROOT.'/product/list.php?type=1&mainmenu=products', DOL_URL_ROOT.'/comm/propal/list.php?mainmenu=commercial', DOL_URL_ROOT.'/commande/list.php?mainmenu=commercial', DOL_URL_ROOT.'/compta/facture/list.php?mainmenu=accountancy', - DOL_URL_ROOT.'/contrat/list.php', - DOL_URL_ROOT.'/fichinter/list.php', - DOL_URL_ROOT.'/fourn/commande/list.php', - DOL_URL_ROOT.'/fourn/facture/list.php', - DOL_URL_ROOT.'/supplier_proposal/list.php', + DOL_URL_ROOT.'/contrat/list.php?mainmenu=commercial', + DOL_URL_ROOT.'/fichinter/list.php?mainmenu=commercial', + DOL_URL_ROOT.'/fourn/commande/list.php?mainmenu=commercial', + DOL_URL_ROOT.'/fourn/facture/list.php?mainmenu=accountancy', + DOL_URL_ROOT.'/supplier_proposal/list.php?mainmenu=commercial', DOL_URL_ROOT.'/projet/list.php?mainmenu=project', DOL_URL_ROOT.'/expensereport/list.php?mainmenu=hrm' ); From b3f17dc614c2e356c2ea856d5255ffa12da47a9f Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Mon, 16 Oct 2017 20:20:55 +0200 Subject: [PATCH 02/13] Better with leftmenu --- htdocs/index.php | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/htdocs/index.php b/htdocs/index.php index ea5d097e2c3..e6fb102fb80 100644 --- a/htdocs/index.php +++ b/htdocs/index.php @@ -292,16 +292,16 @@ if (empty($user->societe_id)) DOL_URL_ROOT.'/adherents/list.php?statut=1&mainmenu=members', DOL_URL_ROOT.'/product/list.php?type=0&mainmenu=products', DOL_URL_ROOT.'/product/list.php?type=1&mainmenu=products', - DOL_URL_ROOT.'/comm/propal/list.php?mainmenu=commercial', - DOL_URL_ROOT.'/commande/list.php?mainmenu=commercial', - DOL_URL_ROOT.'/compta/facture/list.php?mainmenu=accountancy', - DOL_URL_ROOT.'/contrat/list.php?mainmenu=commercial', - DOL_URL_ROOT.'/fichinter/list.php?mainmenu=commercial', - DOL_URL_ROOT.'/fourn/commande/list.php?mainmenu=commercial', - DOL_URL_ROOT.'/fourn/facture/list.php?mainmenu=accountancy', - DOL_URL_ROOT.'/supplier_proposal/list.php?mainmenu=commercial', + DOL_URL_ROOT.'/comm/propal/list.php?mainmenu=commercial&leftmenu=propals', + DOL_URL_ROOT.'/commande/list.php?mainmenu=commercial&leftmenu=orders', + DOL_URL_ROOT.'/compta/facture/list.php?mainmenu=accountancy&leftmenu=customers_bills', + DOL_URL_ROOT.'/contrat/list.php?mainmenu=commercial&leftmenu=contracts', + DOL_URL_ROOT.'/fichinter/list.php?mainmenu=commercial&leftmenu=ficheinter', + DOL_URL_ROOT.'/fourn/commande/list.php?mainmenu=commercial&leftmenu=orders_suppliers', + DOL_URL_ROOT.'/fourn/facture/list.php?mainmenu=accountancy&leftmenu=suppliers_bills', + DOL_URL_ROOT.'/supplier_proposal/list.php?mainmenu=commercial&leftmenu=', DOL_URL_ROOT.'/projet/list.php?mainmenu=project', - DOL_URL_ROOT.'/expensereport/list.php?mainmenu=hrm' + DOL_URL_ROOT.'/expensereport/list.php?mainmenu=hrm&leftmenu=expensereport' ); // Translation lang files $langfile=array("users", From 50cacfee3d5884ef4d5b1f77be6f9a2182be72ac Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Tue, 17 Oct 2017 13:24:38 +0200 Subject: [PATCH 03/13] lighter icon --- htdocs/theme/eldy/img/statut9.png | Bin 502 -> 428 bytes htdocs/theme/eldy/img/statut9_40x40.png | Bin 754 -> 644 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/htdocs/theme/eldy/img/statut9.png b/htdocs/theme/eldy/img/statut9.png index e5304dd791bba49d3c56b11e2298b65f669e3dd5..49397d25520ca96de60b385586961d55ac51c203 100644 GIT binary patch delta 356 zcmV-q0h|8z1FQp(QGekI5epX(r?@fC0003wNkly?W8nvv8wYH`eCw|`q$-`v~-Up=P@iuS^l$nnauwRR!jt;V{ z2(%UmllQg;Syq(iEL#z9B2rvn0A@Bdh*f5@okha{B2tvuY)5?vO_n5t&{Y127E~XW z4y!)=!x3R3B3dw)@jq7Hzj z&b_;kBq)Qnw#0LoYDn`f~q)9F00Te{bbYZcQpezo{LaK$yE?WikdhWFdk*#D$ zzxMF|oO6DD2Qa$6rnk8X!1wXEh%vqlW`|z&IY2P`=vCjV$bY+XYpYq*xJlEnQ52+< z^lM%3#~9!K4B-(#N(lhx900lZGZA_9q%1!<=WNn6+)aRQb^ZEB2*+l|-%wQ^cz^u3 zEZ+ck249B5XJ+;x#<<23h{#k`U+h%XK!&4{k1-xCD+Y)$uEiLShNF>ppRcYSW~z;u zd0L>V;g?w<>wn$uZd);cnfdi@cUMwMd-vaNLrMwf+@A2Ch;#1ZKIb+#=SV4C$jy9y zsj8u^fvSd^`TSB=JDpqL>>sv2TkUjirRw#9h@6Yabm_ZArkTij)$0WT*r}?)N}ivp z>N2adlIN#St7-rslcoV+yWcy{D4^000SaNLh0L01m_e01m_fl`9S#00007bV*G` z2jL143l<+P933A300I$7L_t(o!`+!ta+@#^hJP&sVr(-R7dxG%Z#_fL)ZQ(*O3%=@ zBx7UBWC#vmOWT*g00rAPHfZ`ki_ynQEB(6?d!=x$lv0S3fbuz3KF~Wm#v>A^HL;r4UBZAChw3=R2Kckw2e*>I-`^pw=2e7_#NM_=r@RV(I&W zh%N^hCkZmG85fi!65e!rbllP3SOo!J8V&$5t$7s$d^R96<7u<`@RA;q<+^y{wD z1jmBwn!5)062}-@O@6o1T<5aKjHIJO7?ECa!cZAaB` z8Wp+snuP$sw(Xy$0TxVRuhgg>@R&Cw0FVP%``%UGJ5!m(>2_-jT$QB+yqV36$&@Nf z33y5oJ=p%Mu+$D}8yG!`O@mrKR}24*xh0wRGMDZHQy~3 z;*eP}zJd9Fw18_9nA$||f~`J7H1_aCo+17MUC$%a38Tm300000NkvXXu0mjffk6>B delta 724 zcmV;_0xSK51@Z-uDu2oV(E!mWdG=bVH9E8h<~C8o|Iq55JeG)XtRMBL!nSW-L_G$)fne|e?U)4{ONXS8(11tE0u6@e$Gt8*d6#X z7*PN9H4{ceD}Sds3)(t6L$h9ITLFm(onDXLhQpn+whVb%t>UWPW?6rdXW^dueG;yF zFkC#2a9uq0`;;|KD$o()-Vx$pu*GaSLckH?eyu4Ef&jlBA1OZ5juo79++1HXP1BZV zu+!@u9Ty*ConDWYPOj&&vkB3 zhQr*mmu5)aGmYq(`r>2VA7HVGKGNb6VNmaoKz~g<4!6SBn$evgL+jF zeT-N%%mFRagrV!X;Y`DTWtz*Yx~q13?Z(c&59W(zldUY=HBCdi(ResEu-#}pR8sap zYHucPeH^m8kc^sb Date: Wed, 18 Oct 2017 12:10:00 +0200 Subject: [PATCH 04/13] FIX: Bad localtax apply --- htdocs/expedition/class/expedition.class.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 9e057106dd8..7cfd19e6f1f 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -3,7 +3,7 @@ * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2007 Franky Van Liedekerke * Copyright (C) 2006-2012 Laurent Destailleur - * Copyright (C) 2011-2016 Juanjo Menent + * Copyright (C) 2011-2017 Juanjo Menent * Copyright (C) 2013 Florian Henry * Copyright (C) 2014 Cedric GROSS * Copyright (C) 2014-2015 Marcos GarcĂ­a @@ -1400,7 +1400,10 @@ class Expedition extends CommonObject $line->pa_ht = $obj->pa_ht; + // Local taxes $localtax_array=array(0=>$obj->localtax1_type, 1=>$obj->localtax1_tx, 2=>$obj->localtax2_type, 3=>$obj->localtax2_tx); + $localtax1_tx = get_localtax($obj->tva_tx, 1, $this->thirdparty); + $localtax2_tx = get_localtax($obj->tva_tx, 2, $this->thirdparty); // For invoicing $tabprice = calcul_price_total($obj->qty_shipped, $obj->subprice, $obj->remise_percent, $obj->tva_tx, $obj->localtax1_tx, $obj->localtax2_tx, 0, 'HT', $obj->info_bits, $obj->fk_product_type, $mysoc, $localtax_array); // We force type to 0 From df53870c01db2cb2d72b7c2faf86e4670c0ccf39 Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Wed, 18 Oct 2017 12:13:32 +0200 Subject: [PATCH 05/13] FIX: Bad localtax apply --- htdocs/expedition/class/expedition.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 7cfd19e6f1f..879b5745db4 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -1406,7 +1406,7 @@ class Expedition extends CommonObject $localtax2_tx = get_localtax($obj->tva_tx, 2, $this->thirdparty); // For invoicing - $tabprice = calcul_price_total($obj->qty_shipped, $obj->subprice, $obj->remise_percent, $obj->tva_tx, $obj->localtax1_tx, $obj->localtax2_tx, 0, 'HT', $obj->info_bits, $obj->fk_product_type, $mysoc, $localtax_array); // We force type to 0 + $tabprice = calcul_price_total($obj->qty_shipped, $obj->subprice, $obj->remise_percent, $obj->tva_tx, $localtax1_tx, $localtax2_tx, 0, 'HT', $obj->info_bits, $obj->fk_product_type, $mysoc, $localtax_array); // We force type to 0 $line->desc = $obj->description; // We need ->desc because some code into CommonObject use desc (property defined for other elements) $line->qty = $line->qty_shipped; $line->total_ht = $tabprice[0]; From 93d16bf4d705c3de8f932d18f7ec5cde959e1321 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 19 Oct 2017 12:30:36 +0200 Subject: [PATCH 06/13] Fix several fixes in APIs --- .../comm/propal/class/api_proposals.class.php | 6 +- htdocs/comm/propal/class/propal.class.php | 5 + htdocs/commande/class/api_orders.class.php | 28 +-- htdocs/commande/class/commande.class.php | 6 +- .../facture/class/api_invoices.class.php | 184 ++++++++++++++++++ htdocs/compta/facture/class/facture.class.php | 5 + 6 files changed, 215 insertions(+), 19 deletions(-) diff --git a/htdocs/comm/propal/class/api_proposals.class.php b/htdocs/comm/propal/class/api_proposals.class.php index f719dbf7ea8..2c3afba030f 100644 --- a/htdocs/comm/propal/class/api_proposals.class.php +++ b/htdocs/comm/propal/class/api_proposals.class.php @@ -280,14 +280,14 @@ class Proposals extends DolibarrApi $request_data->date_end, $request_data->array_options, $request_data->fk_unit, - $this->element, - $request_data->id, + $request_data->origin, + $request_data->origin_id, $request_data->multicurrency_subprice, $request_data->fk_remise_except ); if ($updateRes > 0) { - return $this->get($id)->line->rowid; + return $updateRes; } return false; diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index a2af740793e..e7eeaab0c7e 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -590,6 +590,11 @@ class Propal extends CommonObject return -2; } } + else + { + dol_syslog(get_class($this)."::addline status of order must be Draft to allow use of ->addline()", LOG_ERR); + return -3; + } } diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index d4b4502d4ed..9acfd6cc245 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -52,9 +52,9 @@ class Orders extends DolibarrApi } /** - * Get properties of a commande object + * Get properties of an order object * - * Return an array with commande informations + * Return an array with order informations * * @param int $id ID of order * @return array|mixed data without useless information @@ -176,7 +176,7 @@ class Orders extends DolibarrApi * Create order object * * @param array $request_data Request data - * @return int ID of commande + * @return int ID of order */ function post($request_data = NULL) { @@ -236,8 +236,8 @@ class Orders extends DolibarrApi /** * Add a line to given order * - * @param int $id Id of commande to update - * @param array $request_data Orderline data + * @param int $id Id of order to update + * @param array $request_data OrderLine data * * @url POST {id}/lines * @@ -281,12 +281,13 @@ class Orders extends DolibarrApi $request_data->label, $request_data->array_options, $request_data->fk_unit, - $this->element, - $request_data->id + $request_data->origin, + $request_data->origin_id, + $request_data->multicurrency_subprice ); if ($updateRes > 0) { - return $this->get($id)->line->rowid; + return $updateRes; } return false; @@ -295,9 +296,9 @@ class Orders extends DolibarrApi /** * Update a line to given order * - * @param int $id Id of commande to update + * @param int $id Id of order to update * @param int $lineid Id of line to update - * @param array $request_data Orderline data + * @param array $request_data OrderLine data * * @url PUT {id}/lines/{lineid} * @@ -310,7 +311,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)) { @@ -338,7 +339,8 @@ class Orders extends DolibarrApi $request_data->label, $request_data->special_code, $request_data->array_options, - $request_data->fk_unit + $request_data->fk_unit, + $request_data->multicurrency_subprice ); if ($updateRes > 0) { @@ -353,7 +355,7 @@ class Orders extends DolibarrApi * Delete a line to given order * * - * @param int $id Id of commande to update + * @param int $id Id of order to update * @param int $lineid Id of line to delete * * @url DELETE {id}/lines/{lineid} diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 9ed198eefa3..1eec56fdbab 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1431,10 +1431,10 @@ class Commande extends CommonOrder return -2; } } - else - { + else + { dol_syslog(get_class($this)."::addline status of order must be Draft to allow use of ->addline()", LOG_ERR); - return -3; + return -3; } } diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index f841fc80050..c5c14da9a8f 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -210,6 +210,190 @@ class Invoices extends DolibarrApi return $this->invoice->id; } + /** + * Get lines of an invoice + * + * @param int $id Id of invoice + * + * @url GET {id}/lines + * + * @return int + */ + function getLines($id) { + if(! DolibarrApiAccess::$user->rights->facture->lire) { + throw new RestException(401); + } + + $result = $this->invoice->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Invoice not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + $this->invoice->getLinesArray(); + $result = array(); + foreach ($this->invoice->lines as $line) { + array_push($result,$this->_cleanObjectDatas($line)); + } + return $result; + } + + /** + * Add a line to given order + * + * @param int $id Id of invoice to update + * @param array $request_data Orderline data + * + * @url POST {id}/lines + * + * @return int + */ + function postLine($id, $request_data = NULL) { + if(! DolibarrApiAccess::$user->rights->facture->creer) { + throw new RestException(401); + } + + $result = $this->invoice->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Invoice not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + $request_data = (object) $request_data; + $updateRes = $this->invoice->addline( + $request_data->desc, + $request_data->subprice, + $request_data->qty, + $request_data->tva_tx, + $request_data->localtax1_tx, + $request_data->localtax2_tx, + $request_data->fk_product, + $request_data->remise_percent, + $request_data->date_start, + $request_data->date_end, + 0, + $request_data->info_bits, + $request_data->fk_remise_except, + 'HT', + 0, + $request_data->product_type, + $request_data->rang, + $request_data->special_code, + $request_data->origin, + $request_data->origin_id, + $fk_parent_line, + $request_data->fk_fournprice, + $request_data->pa_ht, + $request_data->label, + $request_data->array_options, + $request_data->situation_percent, + $request_data->prev_id, + $request_data->fk_unit, + $request_data->multicurrency_subprice + ); + + if ($updateRes > 0) { + return $updateRes; + + } + return false; + } + + /** + * Update a line to given order + * + * @param int $id Id of invoice to update + * @param int $lineid Id of line to update + * @param array $request_data InvoiceLine data + * + * @url PUT {id}/lines/{lineid} + * + * @return object + */ + function putLine($id, $lineid, $request_data = NULL) { + if(! DolibarrApiAccess::$user->rights->facture->creer) { + throw new RestException(401); + } + + $result = $this->invoice->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Invoice not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + $request_data = (object) $request_data; + $updateRes = $this->invoice->updateline( + $lineid, + $request_data->desc, + $request_data->subprice, + $request_data->qty, + $request_data->remise_percent, + $request_data->date_start, + $request_data->date_end, + $request_data->tva_tx, + $request_data->localtax1_tx, + $request_data->localtax2_tx, + 'HT', + $request_data->info_bits, + $request_data->product_type, + $request_data->fk_parent_line, + 0, + $request_data->fk_fournprice, + $request_data->pa_ht, + $request_data->label, + $request_data->special_code, + $request_data->array_options, + $request_data->situation_percent, + $request_data->fk_unit, + $request_data->multicurrency_subprice + ); + + if ($updateRes > 0) { + $result = $this->get($id); + unset($result->line); + return $this->_cleanObjectDatas($result); + } + return false; + } + + /** + * Delete a line to given order + * + * + * @param int $id Id of invoice to update + * @param int $lineid Id of line to delete + * + * @url DELETE {id}/lines/{lineid} + * + * @return int + */ + function delLine($id, $lineid) { + if(! DolibarrApiAccess::$user->rights->facture->creer) { + throw new RestException(401); + } + + $result = $this->invoice->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Invoice not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('facture',$this->invoice->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + $request_data = (object) $request_data; + $updateRes = $this->invoice->deleteline($lineid); + if ($updateRes > 0) { + return $this->get($id); + } + return false; + } + /** * Update invoice * diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index fc019d92eea..37f5166bc53 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2638,6 +2638,11 @@ class Facture extends CommonInvoice return -2; } } + else + { + dol_syslog(get_class($this)."::addline status of order must be Draft to allow use of ->addline()", LOG_ERR); + return -3; + } } /** From cb089987ee24ee9d67b9778458cc1715e7131299 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 19 Oct 2017 12:35:15 +0200 Subject: [PATCH 07/13] Fix code comment --- .../compta/facture/class/api_invoices.class.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index c5c14da9a8f..aac7330711f 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -15,9 +15,9 @@ * along with this program. If not, see . */ - use Luracast\Restler\RestException; +use Luracast\Restler\RestException; - require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; +require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; /** * API class for invoices @@ -241,10 +241,10 @@ class Invoices extends DolibarrApi } /** - * Add a line to given order + * Add a line to a given invoice * * @param int $id Id of invoice to update - * @param array $request_data Orderline data + * @param array $request_data InvoiceLine data * * @url POST {id}/lines * @@ -304,7 +304,7 @@ class Invoices extends DolibarrApi } /** - * Update a line to given order + * Update a line to a given invoice * * @param int $id Id of invoice to update * @param int $lineid Id of line to update @@ -363,7 +363,7 @@ class Invoices extends DolibarrApi } /** - * Delete a line to given order + * Delete a line to a given invoice * * * @param int $id Id of invoice to update @@ -461,9 +461,9 @@ class Invoices extends DolibarrApi } /** - * Validate an order + * Validate an invoice * - * @param int $id Order ID + * @param int $id Invoice ID * @param int $idwarehouse Warehouse ID * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * From 83440f5bbcb902fa3ff5c0d14df424b701167a87 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 19 Oct 2017 13:07:33 +0200 Subject: [PATCH 08/13] FIX #7626 --- htdocs/core/actions_massactions.inc.php | 16 ++++++++-------- htdocs/core/actions_sendmails.inc.php | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/htdocs/core/actions_massactions.inc.php b/htdocs/core/actions_massactions.inc.php index 6dc6fed25f1..32d80bef672 100644 --- a/htdocs/core/actions_massactions.inc.php +++ b/htdocs/core/actions_massactions.inc.php @@ -265,14 +265,14 @@ if (! $error && $massaction == 'confirm_presend') $replyto = $from; $subject = GETPOST('subject'); $message = GETPOST('message'); - $sendtocc = GETPOST('sentocc'); - $sendtobcc = ''; - if ($objectclass == 'Propale') $sendtocc = (empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO)?'':$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO); - if ($objectclass == 'Commande') $sendtocc = (empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO)?'':$conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO); - if ($objectclass == 'Facture') $sendtocc = (empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO)?'':$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO); - if ($objectclass == 'Supplier_Proposal') $sendtocc = (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO)?'':$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO); - if ($objectclass == 'CommandeFournisseur') $sendtocc = (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO)?'':$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO); - if ($objectclass == 'FactureFournisseur') $sendtocc = (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO)?'':$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO); + + $sendtobcc = GETPOST('sendtoccc'); + if ($objectclass == 'Propale') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO)); + if ($objectclass == 'Commande') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO)); + if ($objectclass == 'Facture') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO)); + if ($objectclass == 'Supplier_Proposal') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO)); + if ($objectclass == 'CommandeFournisseur') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO)); + if ($objectclass == 'FactureFournisseur') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO)); $substitutionarray=array( diff --git a/htdocs/core/actions_sendmails.inc.php b/htdocs/core/actions_sendmails.inc.php index 2b6cbb22e92..fca8ac511da 100644 --- a/htdocs/core/actions_sendmails.inc.php +++ b/htdocs/core/actions_sendmails.inc.php @@ -266,7 +266,7 @@ if (($action == 'send' || $action == 'relance') && ! $_POST['addfile'] && ! $_PO // $message=preg_replace('/()/', '\1'.$urlwithroot.'/viewimage.php\2modulepart=medias\3file=\4\5', $message); - $sendtobcc= GETPOST('sendtoccc'); + $sendtobcc = GETPOST('sendtoccc'); if ($mode == 'emailfromproposal') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO)); if ($mode == 'emailfromorder') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO)); if ($mode == 'emailfrominvoice') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) ? '' : (($sendtobcc?", ":"").$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO)); From 8da7f789d831f33b0dbaca3ac0cc4e72f6241568 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 19 Oct 2017 17:30:08 +0200 Subject: [PATCH 09/13] Fix init of environment for a dedicated entity in API --- htdocs/api/class/api_access.class.php | 7 +++++-- htdocs/api/index.php | 4 ++++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/htdocs/api/class/api_access.class.php b/htdocs/api/class/api_access.class.php index 92a13c26c62..5c6acfb9a84 100644 --- a/htdocs/api/class/api_access.class.php +++ b/htdocs/api/class/api_access.class.php @@ -107,7 +107,7 @@ class DolibarrApiAccess implements iAuthenticate $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; $sql.= " WHERE u.api_key = '".$db->escape($api_key)."'"; // TODO Check if 2 users has same API key. - + $result = $db->query($sql); if ($result) { @@ -118,9 +118,12 @@ class DolibarrApiAccess implements iAuthenticate $stored_key = $obj->api_key; $userentity = $obj->entity; - if (! defined("DOLENTITY")) // If API was not forced with HTTP_DOLENTITY, we set entity to entity of user + if (! defined("DOLENTITY") && $conf->entity != $obj->entity) // If API was not forced with HTTP_DOLENTITY, and user is on another entity, so we reset entity to entity of user { $conf->entity = ($obj->entity?$obj->entity:1); + // We must also reload global conf to get params from the entity + dol_syslog("Entity was not set on http header with HTTP_DOLAPIENTITY (recommanded for performance purpose), so we switch now on entity of user (".$conf->entity .") and we have to reload configuration.", LOG_WARNING); + $conf->setValues($db); } } } diff --git a/htdocs/api/index.php b/htdocs/api/index.php index 9f734c9e24d..d34a97ed298 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -37,6 +37,10 @@ if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); // Do not lo if (! defined("NOLOGIN")) define("NOLOGIN",'1'); // If this page is public (can be called outside logged session) +// Force entity if a value is provided into HTTP header. Otherwise, will use the entity of user of token used. +if (! empty($_SERVER['HTTP_DOLAPIENTITY'])) define("DOLENTITY", (int) $_SERVER['HTTP_DOLAPIENTITY']); + + $res=0; if (! $res && file_exists("../main.inc.php")) $res=include '../main.inc.php'; if (! $res) die("Include of main fails"); From d7113a3602f3abdd4947ac6ad8eec83dcfe7e283 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 19 Oct 2017 17:32:23 +0200 Subject: [PATCH 10/13] Fix init of environment for a dedicated entity in API --- htdocs/api/class/api_access.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/api/class/api_access.class.php b/htdocs/api/class/api_access.class.php index 5c6acfb9a84..41ff488136d 100644 --- a/htdocs/api/class/api_access.class.php +++ b/htdocs/api/class/api_access.class.php @@ -118,7 +118,7 @@ class DolibarrApiAccess implements iAuthenticate $stored_key = $obj->api_key; $userentity = $obj->entity; - if (! defined("DOLENTITY") && $conf->entity != $obj->entity) // If API was not forced with HTTP_DOLENTITY, and user is on another entity, so we reset entity to entity of user + if (! defined("DOLENTITY") && $conf->entity != ($obj->entity?$obj->entity:1)) // If API was not forced with HTTP_DOLENTITY, and user is on another entity, so we reset entity to entity of user { $conf->entity = ($obj->entity?$obj->entity:1); // We must also reload global conf to get params from the entity From d4ade7b935b8d8ab07bfda9c68d6749d9e1ecc4d Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 19 Oct 2017 17:57:16 +0200 Subject: [PATCH 11/13] FIX API to get object does not return data o flinked objects --- htdocs/compta/facture/class/api_invoices.class.php | 1 + htdocs/fourn/class/api_supplier_invoices.class.php | 1 + htdocs/fourn/class/api_supplier_orders.class.php | 1 + 3 files changed, 3 insertions(+) diff --git a/htdocs/compta/facture/class/api_invoices.class.php b/htdocs/compta/facture/class/api_invoices.class.php index aac7330711f..6c55e24f788 100644 --- a/htdocs/compta/facture/class/api_invoices.class.php +++ b/htdocs/compta/facture/class/api_invoices.class.php @@ -75,6 +75,7 @@ class Invoices extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } + $this->invoice->fetchObjectLinked(); return $this->_cleanObjectDatas($this->invoice); } diff --git a/htdocs/fourn/class/api_supplier_invoices.class.php b/htdocs/fourn/class/api_supplier_invoices.class.php index 26ae936d5a0..a833546f83d 100644 --- a/htdocs/fourn/class/api_supplier_invoices.class.php +++ b/htdocs/fourn/class/api_supplier_invoices.class.php @@ -76,6 +76,7 @@ class SupplierInvoices extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } + $this->invoice->fetchObjectLinked(); return $this->_cleanObjectDatas($this->invoice); } diff --git a/htdocs/fourn/class/api_supplier_orders.class.php b/htdocs/fourn/class/api_supplier_orders.class.php index 2695727c3ee..91eab23e3a8 100644 --- a/htdocs/fourn/class/api_supplier_orders.class.php +++ b/htdocs/fourn/class/api_supplier_orders.class.php @@ -76,6 +76,7 @@ class SupplierOrders extends DolibarrApi throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } + $this->order->fetchObjectLinked(); return $this->_cleanObjectDatas($this->order); } From f7556e7ad22779c0db2e24ee50744b9504e58f02 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 19 Oct 2017 19:06:48 +0200 Subject: [PATCH 12/13] FIX make of link to other object during creation --- htdocs/comm/propal/class/propal.class.php | 51 +++++++++++++++--- htdocs/commande/class/api_orders.class.php | 5 +- htdocs/commande/class/commande.class.php | 9 +++- .../facture/class/facture-rec.class.php | 47 +++++++++++----- htdocs/compta/facture/class/facture.class.php | 9 +++- htdocs/contrat/class/contrat.class.php | 11 ++-- .../class/fournisseur.commande.class.php | 53 +++++++++++++------ .../fourn/class/fournisseur.facture.class.php | 37 ++++++++++++- .../class/supplier_proposal.class.php | 41 +++++++++++--- 9 files changed, 208 insertions(+), 55 deletions(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index e7eeaab0c7e..25d488e7316 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -960,9 +960,51 @@ class Propal extends CommonObject $resql=$this->db->query($sql); if (! $resql) $error++; + if (! empty($this->linkedObjectsIds) && empty($this->linked_objects)) // To use new linkedObjectsIds instead of old linked_objects + { + $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds + } + + // Add object linked + if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects)) + { + foreach($this->linked_objects as $origin => $tmp_origin_id) + { + if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...)) + { + foreach($tmp_origin_id as $origin_id) + { + $ret = $this->add_object_linked($origin, $origin_id); + if (! $ret) + { + $this->error=$this->db->lasterror(); + $error++; + } + } + } + else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1)) + { + $origin_id = $tmp_origin_id; + $ret = $this->add_object_linked($origin, $origin_id); + if (! $ret) + { + $this->error=$this->db->lasterror(); + $error++; + } + } + } + } + + // Add linked object (deprecated, use ->linkedObjectsIds instead) + if (! $error && $this->origin && $this->origin_id) + { + $ret = $this->add_object_linked(); + if (! $ret) dol_print_error($this->db); + } + /* * Insertion du detail des produits dans la base - */ + */ if (! $error) { $fk_parent_line=0; @@ -1016,13 +1058,6 @@ class Propal extends CommonObject } } - // Add linked object - if (! $error && $this->origin && $this->origin_id) - { - $ret = $this->add_object_linked(); - if (! $ret) dol_print_error($this->db); - } - // Set delivery address if (! $error && $this->fk_delivery_address) { diff --git a/htdocs/commande/class/api_orders.class.php b/htdocs/commande/class/api_orders.class.php index 9acfd6cc245..f2c8de6da5b 100644 --- a/htdocs/commande/class/api_orders.class.php +++ b/htdocs/commande/class/api_orders.class.php @@ -196,6 +196,7 @@ class Orders extends DolibarrApi } $this->commande->lines = $lines; }*/ + if ($this->commande->create(DolibarrApiAccess::$user) < 0) { throw new RestException(500, "Error creating order", array_merge(array($this->commande->error), $this->commande->errors)); } @@ -386,7 +387,7 @@ class Orders extends DolibarrApi /** * Update order general fields (won't touch lines of order) * - * @param int $id Id of commande to update + * @param int $id Id of order to update * @param array $request_data Datas * * @return int @@ -398,7 +399,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 1eec56fdbab..c5271c34744 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -875,6 +875,11 @@ class Commande extends CommonOrder { $this->ref = $initialref; + if (! empty($this->linkedObjectsIds) && empty($this->linked_objects)) // To use new linkedObjectsIds instead of old linked_objects + { + $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds + } + // Add object linked if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects)) { @@ -887,7 +892,7 @@ class Commande extends CommonOrder $ret = $this->add_object_linked($origin, $origin_id); if (! $ret) { - dol_print_error($this->db); + $this->error=$this->db->lasterror(); $error++; } } @@ -898,7 +903,7 @@ class Commande extends CommonOrder $ret = $this->add_object_linked($origin, $origin_id); if (! $ret) { - dol_print_error($this->db); + $this->error=$this->db->lasterror(); $error++; } } diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index cbeba2828e7..779f4545f77 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -201,19 +201,40 @@ class FactureRec extends CommonInvoice } } - // Add object linked - if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects)) - { - foreach($this->linked_objects as $origin => $origin_id) - { - $ret = $this->add_object_linked($origin, $origin_id); - if (! $ret) - { - $this->error=$this->db->lasterror(); - $error++; - } - } - } + if (! empty($this->linkedObjectsIds) && empty($this->linked_objects)) // To use new linkedObjectsIds instead of old linked_objects + { + $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds + } + + // Add object linked + if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects)) + { + foreach($this->linked_objects as $origin => $tmp_origin_id) + { + if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...)) + { + foreach($tmp_origin_id as $origin_id) + { + $ret = $this->add_object_linked($origin, $origin_id); + if (! $ret) + { + $this->error=$this->db->lasterror(); + $error++; + } + } + } + else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1)) + { + $origin_id = $tmp_origin_id; + $ret = $this->add_object_linked($origin, $origin_id); + if (! $ret) + { + $this->error=$this->db->lasterror(); + $error++; + } + } + } + } if ($error) { diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 37f5166bc53..c0be06da6bd 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -442,6 +442,11 @@ class Facture extends CommonInvoice $resql=$this->db->query($sql); if (! $resql) $error++; + if (! empty($this->linkedObjectsIds) && empty($this->linked_objects)) // To use new linkedObjectsIds instead of old linked_objects + { + $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds + } + // Add object linked if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects)) { @@ -454,7 +459,7 @@ class Facture extends CommonInvoice $ret = $this->add_object_linked($origin, $origin_id); if (! $ret) { - dol_print_error($this->db); + $this->error=$this->db->lasterror(); $error++; } } @@ -465,7 +470,7 @@ class Facture extends CommonInvoice $ret = $this->add_object_linked($origin, $origin_id); if (! $ret) { - dol_print_error($this->db); + $this->error=$this->db->lasterror(); $error++; } } diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 937cce82474..ca8d6fc9ddb 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -946,7 +946,12 @@ class Contrat extends CommonObject if (! $error) { - // Add object linked + if (! empty($this->linkedObjectsIds) && empty($this->linked_objects)) // To use new linkedObjectsIds instead of old linked_objects + { + $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds + } + + // Add object linked if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects)) { foreach($this->linked_objects as $origin => $tmp_origin_id) @@ -958,7 +963,7 @@ class Contrat extends CommonObject $ret = $this->add_object_linked($origin, $origin_id); if (! $ret) { - dol_print_error($this->db); + $this->error=$this->db->lasterror(); $error++; } } @@ -969,7 +974,7 @@ class Contrat extends CommonObject $ret = $this->add_object_linked($origin, $origin_id); if (! $ret) { - dol_print_error($this->db); + $this->error=$this->db->lasterror(); $error++; } } diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index eb872e17270..50e805f1089 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -1197,23 +1197,44 @@ class CommandeFournisseur extends CommonOrder { // Add link with price request and supplier order if ($this->id) - { - $this->ref="(PROV".$this->id.")"; + { + $this->ref="(PROV".$this->id.")"; - // Add object linked - if (is_array($this->linked_objects) && ! empty($this->linked_objects)) - { - foreach($this->linked_objects as $origin => $origin_id) - { - $ret = $this->add_object_linked($origin, $origin_id); - if (! $ret) - { - dol_print_error($this->db); - $error++; - } - } - } - } + if (! empty($this->linkedObjectsIds) && empty($this->linked_objects)) // To use new linkedObjectsIds instead of old linked_objects + { + $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds + } + + // Add object linked + if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects)) + { + foreach($this->linked_objects as $origin => $tmp_origin_id) + { + if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...)) + { + foreach($tmp_origin_id as $origin_id) + { + $ret = $this->add_object_linked($origin, $origin_id); + if (! $ret) + { + dol_print_error($this->db); + $error++; + } + } + } + else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1)) + { + $origin_id = $tmp_origin_id; + $ret = $this->add_object_linked($origin, $origin_id); + if (! $ret) + { + dol_print_error($this->db); + $error++; + } + } + } + } + } if (! $error) { diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index d4edc4a01cd..9a9702ab718 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -306,7 +306,42 @@ class FactureFournisseur extends CommonInvoice $resql=$this->db->query($sql); if (! $resql) $error++; - // Add object linked + if (! empty($this->linkedObjectsIds) && empty($this->linked_objects)) // To use new linkedObjectsIds instead of old linked_objects + { + $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds + } + + // Add object linked + if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects)) + { + foreach($this->linked_objects as $origin => $tmp_origin_id) + { + if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...)) + { + foreach($tmp_origin_id as $origin_id) + { + $ret = $this->add_object_linked($origin, $origin_id); + if (! $ret) + { + dol_print_error($this->db); + $error++; + } + } + } + else // Old behaviour, if linked_object has only one link per type, so is something like array('contract'=>id1)) + { + $origin_id = $tmp_origin_id; + $ret = $this->add_object_linked($origin, $origin_id); + if (! $ret) + { + dol_print_error($this->db); + $error++; + } + } + } + } + + // Add linked object (deprecated, use ->linkedObjectsIds instead) if (! $error && $this->id && ! empty($this->origin) && ! empty($this->origin_id)) { $ret = $this->add_object_linked(); diff --git a/htdocs/supplier_proposal/class/supplier_proposal.class.php b/htdocs/supplier_proposal/class/supplier_proposal.class.php index c37555efdb7..2751e89763c 100644 --- a/htdocs/supplier_proposal/class/supplier_proposal.class.php +++ b/htdocs/supplier_proposal/class/supplier_proposal.class.php @@ -848,9 +848,41 @@ class SupplierProposal extends CommonObject $resql=$this->db->query($sql); if (! $resql) $error++; + if (! empty($this->linkedObjectsIds) && empty($this->linked_objects)) // To use new linkedObjectsIds instead of old linked_objects + { + $this->linked_objects = $this->linkedObjectsIds; // TODO Replace linked_objects with linkedObjectsIds + } + + // Add object linked + if (! $error && $this->id && is_array($this->linked_objects) && ! empty($this->linked_objects)) + { + foreach($this->linked_objects as $origin => $tmp_origin_id) + { + if (is_array($tmp_origin_id)) // New behaviour, if linked_object can have several links per type, so is something like array('contract'=>array(id1, id2, ...)) + { + foreach($tmp_origin_id as $origin_id) + { + $ret = $this->add_object_linked($origin, $origin_id); + if (! $ret) + { + dol_print_error($this->db); + $error++; + } + } + } + } + } + + // Add linked object (deprecated, use ->linkedObjectsIds instead) + if (! $error && $this->origin && $this->origin_id) + { + $ret = $this->add_object_linked(); + if (! $ret) dol_print_error($this->db); + } + /* * Insertion du detail des produits dans la base - */ + */ if (! $error) { $fk_parent_line=0; @@ -903,13 +935,6 @@ class SupplierProposal extends CommonObject } } - // Add linked object - if (! $error && $this->origin && $this->origin_id) - { - $ret = $this->add_object_linked(); - if (! $ret) dol_print_error($this->db); - } - if (! $error) { // Mise a jour infos denormalisees From cad44ee68afe1b2b24a1b3020cb0eb2ff475970e Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 22 Oct 2017 01:25:59 +0200 Subject: [PATCH 13/13] FIX substitution in ODT of thirdparties documents --- .../societe/doc/doc_generic_odt.modules.php | 68 ++++--------------- 1 file changed, 13 insertions(+), 55 deletions(-) diff --git a/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php b/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php index edee43b274c..13595108140 100644 --- a/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php +++ b/htdocs/core/modules/societe/doc/doc_generic_odt.modules.php @@ -150,7 +150,7 @@ class doc_generic_odt extends ModeleThirdPartyDoc } $texte.='
'; } - + $texte.= ''; $texte.= ''; @@ -272,53 +272,6 @@ class doc_generic_odt extends ModeleThirdPartyDoc } //print $odfHandler->__toString()."\n"; - // Make substitutions into odt of user info - $tmparray=$this->get_substitutionarray_user($user,$outputlangs); - //var_dump($tmparray); exit; - foreach($tmparray as $key=>$value) - { - try { - if (preg_match('/logo$/',$key)) // Image - { - //var_dump($value);exit; - if (file_exists($value)) $odfHandler->setImage($key, $value); - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); - } - else // Text - { - //print $key.' '.$value;exit; - $odfHandler->setVars($key, $value, true, 'UTF-8'); - } - } - catch(OdfException $e) - { - // setVars failed, probably because key not found - } - } - // Make substitutions into odt of mysoc info - $tmparray=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); - //var_dump($tmparray); exit; - foreach($tmparray as $key=>$value) - { - try { - if (preg_match('/logo$/',$key)) // Image - { - //var_dump($value);exit; - if (file_exists($value)) $odfHandler->setImage($key, $value); - else $odfHandler->setVars($key, 'ErrorFileNotFound', true, 'UTF-8'); - } - else // Text - { - $odfHandler->setVars($key, $value, true, 'UTF-8'); - } - } - catch(OdfException $e) - { - // setVars failed, probably because key not found - } - } - - // Replace tags of lines for contacts $contact_arrray=array(); @@ -333,7 +286,7 @@ class doc_generic_odt extends ModeleThirdPartyDoc if ($num) { require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; - + $i=0; $contactstatic = new Contact($this->db); @@ -380,13 +333,18 @@ class doc_generic_odt extends ModeleThirdPartyDoc } } - // Make substitutions into odt of thirdparty + external modules - $tmparray=$this->get_substitutionarray_thirdparty($object,$outputlangs); + // Make substitutions into odt + $array_user=$this->get_substitutionarray_user($user,$outputlangs); + $array_soc=$this->get_substitutionarray_mysoc($mysoc,$outputlangs); + $array_thirdparty=$this->get_substitutionarray_thirdparty($object,$outputlangs); + $array_other=$this->get_substitutionarray_other($outputlangs); + + $tmparray = array_merge($array_user,$array_soc,$array_thirdparty,$array_other); complete_substitutions_array($tmparray, $outputlangs, $object); // Call the ODTSubstitution hook $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); - $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + $reshook=$hookmanager->executeHooks('ODTSubstitution',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks // Replace variables into document foreach($tmparray as $key=>$value) @@ -438,13 +396,13 @@ class doc_generic_odt extends ModeleThirdPartyDoc $odfHandler->creator = $user->getFullName($outputlangs); $odfHandler->title = $object->builddoc_filename; $odfHandler->subject = $object->builddoc_filename; - + if (! empty($conf->global->ODT_ADD_DOLIBARR_ID)) { $odfHandler->userdefined['dol_id'] = $object->id; $odfHandler->userdefined['dol_element'] = $object->element; } - + $odfHandler->saveToDisk($file); }catch (Exception $e){ $this->error=$e->getMessage(); @@ -453,7 +411,7 @@ class doc_generic_odt extends ModeleThirdPartyDoc } $parameters=array('odfHandler'=>&$odfHandler,'file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs,'substitutionarray'=>&$tmparray); $reshook=$hookmanager->executeHooks('afterODTCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks - + if (! empty($conf->global->MAIN_UMASK)) @chmod($file, octdec($conf->global->MAIN_UMASK));