From 0a5ded20a34f8d88769f9ae1f88d191e5f17b66a Mon Sep 17 00:00:00 2001 From: "geoffrey.girard" Date: Fri, 24 Jun 2016 15:27:47 +0200 Subject: [PATCH 01/31] FIX extrafield cloned on project clone --- htdocs/projet/class/project.class.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/projet/class/project.class.php b/htdocs/projet/class/project.class.php index 7f8aa6252e8..91a75f80ce1 100644 --- a/htdocs/projet/class/project.class.php +++ b/htdocs/projet/class/project.class.php @@ -1121,6 +1121,7 @@ class Project extends CommonObject // Load source object $clone_project->fetch($fromid); + $clone_project->fetch_optionals(); $clone_project->fetch_thirdparty(); $orign_dt_start=$clone_project->date_start; From 321ccce438c25c3fe55969a310cd5699053b5233 Mon Sep 17 00:00:00 2001 From: "geoffrey.girard" Date: Fri, 24 Jun 2016 15:57:08 +0200 Subject: [PATCH 02/31] Fix PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS on project edit view --- htdocs/projet/card.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/htdocs/projet/card.php b/htdocs/projet/card.php index af4a4c7299f..5dc8d8e03b4 100644 --- a/htdocs/projet/card.php +++ b/htdocs/projet/card.php @@ -635,8 +635,12 @@ else $filteronlist=''; if (! empty($conf->global->PROJECT_FILTER_FOR_THIRDPARTY_LIST)) $filteronlist=$conf->global->PROJECT_FILTER_FOR_THIRDPARTY_LIST; $text=$form->select_thirdparty_list($object->thirdparty->id, 'socid', $filteronlist, 1, 1); - $texthelp=$langs->trans("IfNeedToUseOhterObjectKeepEmpty"); - print $form->textwithtooltip($text.' '.img_help(), $texthelp, 1, 0, '', '', 2); + if (empty($conf->global->PROJECT_CAN_ALWAYS_LINK_TO_ALL_SUPPLIERS) && empty($conf->dol_use_jmobile)) + { + $texthelp=$langs->trans("IfNeedToUseOhterObjectKeepEmpty"); + print $form->textwithtooltip($text.' '.img_help(),$texthelp,1); + } + else print $text; print ''; // Visibility From 1368e6d462c7191a79977cb88effb22541ae72e5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 24 Jun 2016 17:04:59 +0200 Subject: [PATCH 03/31] Fix: error message was not enough to understand Conflicts: htdocs/langs/en_US/errors.lang --- htdocs/comm/propal/class/propal.class.php | 3 ++- htdocs/commande/class/commande.class.php | 6 ++++-- htdocs/compta/facture/class/facture.class.php | 6 ++++-- htdocs/expedition/class/expedition.class.php | 6 ++++-- htdocs/langs/en_US/errors.lang | 7 +++++++ 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 112dbf792ff..463c81266f8 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -429,7 +429,8 @@ class Propal extends CommonObject $product_type=$product->type; if (! empty($conf->global->STOCK_MUST_BE_ENOUGH_FOR_PROPOSAL) && $product_type == 0 && $product->stock_reel < $qty) { - $this->error=$langs->trans('ErrorStockIsNotEnough'); + $langs->load("errors"); + $this->error=$langs->trans('ErrorStockIsNotEnoughToAddProductOnProposal', $product->ref); $this->db->rollback(); return -3; } diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 30d22e7588e..9eb67cecc56 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1242,7 +1242,8 @@ class Commande extends CommonOrder if (! empty($conf->global->STOCK_MUST_BE_ENOUGH_FOR_ORDER) && $product_type == 0 && $product->stock_reel < $qty) { - $this->error=$langs->trans('ErrorStockIsNotEnough'); + $langs->load("errors"); + $this->error=$langs->trans('ErrorStockIsNotEnoughToAddProductOnOrder', $product->ref); dol_syslog(get_class($this)."::addline error=Product ".$product->ref.": ".$this->error, LOG_ERR); $this->db->rollback(); return self::STOCK_NOT_ENOUGH_FOR_ORDER; @@ -2563,7 +2564,8 @@ class Commande extends CommonOrder if (! empty($conf->global->STOCK_MUST_BE_ENOUGH_FOR_ORDER) && $product_type == 0 && $product->stock_reel < $qty) { - $this->error=$langs->trans('ErrorStockIsNotEnough'); + $langs->load("errors"); + $this->error=$langs->trans('ErrorStockIsNotEnoughToAddProductOnOrder', $product->ref); dol_syslog(get_class($this)."::addline error=Product ".$product->ref.": ".$this->error, LOG_ERR); $this->db->rollback(); unset($_POST['productid']); diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 0bb1a4cf189..27432d7c399 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -2138,7 +2138,8 @@ class Facture extends CommonInvoice $product_type=$product->type; if (! empty($conf->global->STOCK_MUST_BE_ENOUGH_FOR_INVOICE) && $product_type == 0 && $product->stock_reel < $qty) { - $this->error=$langs->trans('ErrorStockIsNotEnough'); + $langs->load("errors"); + $this->error=$langs->trans('ErrorStockIsNotEnoughToAddProductOnInvoice', $product->ref); $this->db->rollback(); return -3; } @@ -2348,7 +2349,8 @@ class Facture extends CommonInvoice $product_type=$product->type; if (! empty($conf->global->STOCK_MUST_BE_ENOUGH_FOR_INVOICE) && $product_type == 0 && $product->stock_reel < $qty) { - $this->error=$langs->trans('ErrorStockIsNotEnough'); + $langs->load("errors"); + $this->error=$langs->trans('ErrorStockIsNotEnoughToAddProductOnInvoice', $product->ref); $this->db->rollback(); return -3; } diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 143e86330ee..1b7fbefb8a6 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -874,7 +874,8 @@ class Expedition extends CommonObject $product_type=$product->type; if ($product_type == 0 && $product_stock < $qty) { - $this->error=$langs->trans('ErrorStockIsNotEnough'); + $langs->load("errors"); + $this->error=$langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $product->ref); $this->db->rollback(); return -3; } @@ -930,7 +931,8 @@ class Expedition extends CommonObject if ($prod_batch->qty < $linebatch->dluo_qty) { - $this->errors[] = $langs->trans('ErrorStockIsNotEnough'); + $langs->load("errors"); + $this->errors[]=$langs->trans('ErrorStockIsNotEnoughToAddProductOnShipment', $prod_batch->fk_product); dol_syslog(get_class($this)."::addline_batch error=Product ".$prod_batch->batch.": ".$this->errorsToString(), LOG_ERR); $this->db->rollback(); return -1; diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index 50fd77a85e7..dc3502e027a 100755 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -173,6 +173,13 @@ ErrorOppStatusRequiredIfAmount=You set an estimated amount for this opportunity/ ErrorBadDefinitionOfMenuArrayInModuleDescriptor=Bad Definition Of Menu Array In Module Descriptor (bad value for key fk_menu) ErrorSavingChanges=An error has ocurred when saving the changes ErrorWarehouseRequiredIntoShipmentLine=Warehouse is required on the line to ship +ErrorFileMustHaveFormat=File must have format %s +ErrorSupplierCountryIsNotDefined=Country for this supplier is not defined. Correct this first. +ErrorsThirdpartyMerge=Failed to merge the two records. Request canceled. +ErrorStockIsNotEnoughToAddProductOnOrder=Stock is not enougth for product %s to add it into a new order. +ErrorStockIsNotEnoughToAddProductOnInvoice=Stock is not enougth for product %s to add it into a new invoice. +ErrorStockIsNotEnoughToAddProductOnShipment=Stock is not enougth for product %s to add it into a new shipment. +ErrorStockIsNotEnoughToAddProductOnProposal=Stock is not enougth for product %s to add it into a new proposal. # Warnings WarningPasswordSetWithNoAccount=A password was set for this member. However, no user account was created. So this password is stored but can't be used to login to Dolibarr. It may be used by an external module/interface but if you don't need to define any login nor password for a member, you can disable option "Manage a login for each member" from Member module setup. If you need to manage a login but don't need any password, you can keep this field empty to avoid this warning. Note: Email can also be used as a login if the member is linked to a user. From eb9d26a9e0fa38673db05beced0b1485875067cb Mon Sep 17 00:00:00 2001 From: Alexis Algoud Date: Mon, 27 Jun 2016 11:36:13 +0200 Subject: [PATCH 04/31] FIX #5383 bad object id on don delete --- htdocs/don/card.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/don/card.php b/htdocs/don/card.php index b56171b8796..cc27b1bcfd1 100644 --- a/htdocs/don/card.php +++ b/htdocs/don/card.php @@ -740,9 +740,9 @@ if (! empty($id) && $action != 'edit') // Delete if ($user->rights->don->supprimer) { - if ($don->statut == -1 || $don->statut == 0) + if ($object->statut == -1 || $object->statut == 0) { - print '"; + print '"; } else { From d0be7877d376841141f759bcd6789d46c3f73ed1 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Mon, 27 Jun 2016 13:57:10 +0200 Subject: [PATCH 05/31] Fix box PHP strict warning --- htdocs/core/boxes/box_actions.php | 57 +++++++++++-------- htdocs/core/boxes/box_activity.php | 7 ++- htdocs/core/boxes/box_bookmarks.php | 7 ++- htdocs/core/boxes/box_clients.php | 7 ++- htdocs/core/boxes/box_commandes.php | 5 +- htdocs/core/boxes/box_comptes.php | 7 ++- htdocs/core/boxes/box_contacts.php | 15 ++--- htdocs/core/boxes/box_contracts.php | 15 ++--- htdocs/core/boxes/box_external_rss.php | 5 +- htdocs/core/boxes/box_factures.php | 9 +-- htdocs/core/boxes/box_factures_fourn.php | 7 ++- htdocs/core/boxes/box_factures_fourn_imp.php | 7 ++- htdocs/core/boxes/box_factures_imp.php | 7 ++- htdocs/core/boxes/box_ficheinter.php | 7 ++- htdocs/core/boxes/box_fournisseurs.php | 5 +- htdocs/core/boxes/box_goodcustomers.php | 11 ++-- .../boxes/box_graph_invoices_permonth.php | 9 +-- .../box_graph_invoices_supplier_permonth.php | 9 +-- .../core/boxes/box_graph_orders_permonth.php | 9 +-- .../box_graph_orders_supplier_permonth.php | 9 +-- .../boxes/box_graph_product_distribution.php | 7 ++- .../boxes/box_graph_propales_permonth.php | 7 ++- htdocs/core/boxes/box_members.php | 7 ++- htdocs/core/boxes/box_produits.php | 7 ++- .../core/boxes/box_produits_alerte_stock.php | 7 ++- htdocs/core/boxes/box_project.php | 7 ++- htdocs/core/boxes/box_propales.php | 5 +- htdocs/core/boxes/box_prospect.php | 7 ++- htdocs/core/boxes/box_services_contracts.php | 17 +++--- htdocs/core/boxes/box_services_expired.php | 8 ++- htdocs/core/boxes/box_supplier_orders.php | 10 ++-- htdocs/core/boxes/box_task.php | 9 +-- 32 files changed, 176 insertions(+), 136 deletions(-) diff --git a/htdocs/core/boxes/box_actions.php b/htdocs/core/boxes/box_actions.php index 1f5e8493d7b..82aacf2d8a0 100644 --- a/htdocs/core/boxes/box_actions.php +++ b/htdocs/core/boxes/box_actions.php @@ -167,13 +167,15 @@ class box_actions extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { + function showBox($head = null, $contents = null, $nooutput=0) + { global $langs, $conf; parent::showBox($this->info_box_head, $this->info_box_contents); - if (! empty($conf->global->SHOW_DIALOG_HOMEPAGE)) + $out=''; + if (! empty($conf->global->SHOW_DIALOG_HOMEPAGE)) { $actioncejour=false; $contents=$this->info_box_contents; @@ -183,8 +185,8 @@ class box_actions extends ModeleBoxes $bcx[1] = 'class="box_impair"'; if ($contents[0][0]['text'] != $langs->trans("NoActionsToDo")) { - print '
trans("ActionsToDo").'">'; - print ''; + $out.= '
trans("ActionsToDo").'">'; + $out.= '
'; for ($line=0, $n=$nblines; $line < $n; $line++) { if (isset($contents[$line])) @@ -202,40 +204,45 @@ class box_actions extends ModeleBoxes $urlsoc=$contents[$line][3]['url']; $dateligne=$contents[$line][4]['text']; $percentage=$contents[$line][5]['text']; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; + $out.= ''; + $out.= ''; + $out.= ''; + $out.= ''; + $out.= ''; + $out.= ''; + $out.= ''; } } - print '
'; - print img_object("",$logo); - print ''.$label.''.img_object("",$logosoc)." ".$nomsoc.''.$dateligne.''.$percentage.'
'; + $out.= img_object("",$logo); + $out.= ''.$label.''.img_object("",$logosoc)." ".$nomsoc.''.$dateligne.''.$percentage.'
'; + $out.= ''; } - print '
'; + $out.= ''; if ($actioncejour) { - print ''; + $out.= ''; } else { - print ''; + $out.= ''; } } + + if ($nooutput) return $out; + else print $out; + + return ''; } } diff --git a/htdocs/core/boxes/box_activity.php b/htdocs/core/boxes/box_activity.php index f7e09d33583..34666507488 100644 --- a/htdocs/core/boxes/box_activity.php +++ b/htdocs/core/boxes/box_activity.php @@ -455,10 +455,11 @@ class box_activity extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_bookmarks.php b/htdocs/core/boxes/box_bookmarks.php index 88adb744ceb..e99a0b30387 100644 --- a/htdocs/core/boxes/box_bookmarks.php +++ b/htdocs/core/boxes/box_bookmarks.php @@ -135,11 +135,12 @@ class box_bookmarks extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_clients.php b/htdocs/core/boxes/box_clients.php index 24c940fb9ea..307dcc7cbfd 100644 --- a/htdocs/core/boxes/box_clients.php +++ b/htdocs/core/boxes/box_clients.php @@ -157,11 +157,12 @@ class box_clients extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_commandes.php b/htdocs/core/boxes/box_commandes.php index 6eb5006182c..7653206333d 100644 --- a/htdocs/core/boxes/box_commandes.php +++ b/htdocs/core/boxes/box_commandes.php @@ -176,11 +176,12 @@ class box_commandes extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) + function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents); + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_comptes.php b/htdocs/core/boxes/box_comptes.php index 178851466be..a6b8e2744a6 100644 --- a/htdocs/core/boxes/box_comptes.php +++ b/htdocs/core/boxes/box_comptes.php @@ -169,11 +169,12 @@ class box_comptes extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_contacts.php b/htdocs/core/boxes/box_contacts.php index a1fc2768ba1..45963af9bb1 100644 --- a/htdocs/core/boxes/box_contacts.php +++ b/htdocs/core/boxes/box_contacts.php @@ -83,7 +83,7 @@ class box_contacts extends ModeleBoxes $societestatic=new Societe($db); $line = 0; - while ($line < $num) + while ($line < $num) { $objp = $db->fetch_object($result); $datec=$db->jdate($objp->datec); @@ -100,7 +100,7 @@ class box_contacts extends ModeleBoxes $contactstatic->address = $objp->address; $contactstatic->zip = $objp->zip; $contactstatic->town = $objp->town; - + $societestatic->id = $objp->fk_soc; $societestatic->name = $objp->socname; $societestatic->name_alias = $objp->name_alias; @@ -108,7 +108,7 @@ class box_contacts extends ModeleBoxes $societestatic->code_fournisseur = $objp->code_fournisseur; $societestatic->client = $objp->client; $societestatic->fournisseur = $objp->fournisseur; - + $this->info_box_contents[$line][] = array( 'td' => 'align="left"', 'text' => $contactstatic->getNomUrl(1), @@ -131,7 +131,7 @@ class box_contacts extends ModeleBoxes 'text' => $contactstatic->getLibStatut(3), 'asis'=>1, ); - + $line++; } @@ -163,11 +163,12 @@ class box_contacts extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_contracts.php b/htdocs/core/boxes/box_contracts.php index 665bff4c6da..40cc8885f90 100644 --- a/htdocs/core/boxes/box_contracts.php +++ b/htdocs/core/boxes/box_contracts.php @@ -55,14 +55,14 @@ class box_contracts extends ModeleBoxes $this->max=$max; include_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; - + $this->info_box_head = array('text' => $langs->trans("BoxTitleLastContracts",$max)); if ($user->rights->contrat->lire) { $contractstatic=new Contrat($db); $thirdpartytmp=new Societe($db); - + $sql = "SELECT s.nom as name, s.rowid as socid,"; $sql.= " c.rowid, c.ref, c.statut as fk_statut, c.date_contrat, c.datec, c.fin_validite, c.date_cloture"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."contrat as c"; @@ -83,8 +83,8 @@ class box_contracts extends ModeleBoxes $line = 0; $langs->load("contracts"); - - while ($line < $num) + + while ($line < $num) { $objp = $db->fetch_object($resql); $datec=$db->jdate($objp->datec); @@ -99,7 +99,7 @@ class box_contracts extends ModeleBoxes $thirdpartytmp->name = $objp->name; $thirdpartytmp->id = $objp->socid; - + // fin_validite is no more on contract but on services // if ($objp->fk_statut == 1 && $dateterm < ($now - $conf->contrat->cloture->warning_delay)) { $late = img_warning($langs->trans("Late")); } @@ -157,11 +157,12 @@ class box_contracts extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) + function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents); + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_external_rss.php b/htdocs/core/boxes/box_external_rss.php index f1db35e1614..dbe71a6ca41 100644 --- a/htdocs/core/boxes/box_external_rss.php +++ b/htdocs/core/boxes/box_external_rss.php @@ -184,11 +184,12 @@ class box_external_rss extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) + function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents); + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_factures.php b/htdocs/core/boxes/box_factures.php index 7b5a01d6bca..22a90929a0b 100644 --- a/htdocs/core/boxes/box_factures.php +++ b/htdocs/core/boxes/box_factures.php @@ -180,11 +180,12 @@ class box_factures extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines - * @return void + * @param int $nooutput No print, only return string + * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_factures_fourn.php b/htdocs/core/boxes/box_factures_fourn.php index 88b64947f05..b43d9cfc47b 100644 --- a/htdocs/core/boxes/box_factures_fourn.php +++ b/htdocs/core/boxes/box_factures_fourn.php @@ -189,11 +189,12 @@ class box_factures_fourn extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_factures_fourn_imp.php b/htdocs/core/boxes/box_factures_fourn_imp.php index 27441f22ea5..b3ca0fec031 100644 --- a/htdocs/core/boxes/box_factures_fourn_imp.php +++ b/htdocs/core/boxes/box_factures_fourn_imp.php @@ -186,11 +186,12 @@ class box_factures_fourn_imp extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_factures_imp.php b/htdocs/core/boxes/box_factures_imp.php index bcc26f60e4c..67c4d4dbfcc 100644 --- a/htdocs/core/boxes/box_factures_imp.php +++ b/htdocs/core/boxes/box_factures_imp.php @@ -182,11 +182,12 @@ class box_factures_imp extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_ficheinter.php b/htdocs/core/boxes/box_ficheinter.php index decf5e564f0..d57a2a991df 100644 --- a/htdocs/core/boxes/box_ficheinter.php +++ b/htdocs/core/boxes/box_ficheinter.php @@ -144,11 +144,12 @@ class box_ficheinter extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_fournisseurs.php b/htdocs/core/boxes/box_fournisseurs.php index e3e6061d803..ed3680af455 100644 --- a/htdocs/core/boxes/box_fournisseurs.php +++ b/htdocs/core/boxes/box_fournisseurs.php @@ -139,11 +139,12 @@ class box_fournisseurs extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) + function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents); + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_goodcustomers.php b/htdocs/core/boxes/box_goodcustomers.php index 579df4762a0..56aa9097ac2 100644 --- a/htdocs/core/boxes/box_goodcustomers.php +++ b/htdocs/core/boxes/box_goodcustomers.php @@ -81,7 +81,7 @@ class box_goodcustomers extends ModeleBoxes if ($user->rights->societe->lire) { - + $sql = "SELECT s.rowid, s.nom as name, s.logo, s.code_client, s.code_fournisseur, s.client, s.fournisseur, s.tms as datem, s.status as status,"; $sql.= " count(*) as nbfact, sum(". $db->ifsql('f.paye=1','1','0').") as nbfactpaye"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture as f"; @@ -127,7 +127,7 @@ class box_goodcustomers extends ModeleBoxes 'td' => 'align="right"', 'text' => $nbfact.( $nbimpaye != 0 ? ' ('.$nbimpaye.')':'') ); - + $this->info_box_contents[$line][] = array( 'td' => 'align="right" width="18"', 'text' => $thirdpartystatic->LibStatut($objp->status,3) @@ -158,11 +158,12 @@ class box_goodcustomers extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_graph_invoices_permonth.php b/htdocs/core/boxes/box_graph_invoices_permonth.php index 3848960e5e9..1b54d917d05 100644 --- a/htdocs/core/boxes/box_graph_invoices_permonth.php +++ b/htdocs/core/boxes/box_graph_invoices_permonth.php @@ -171,7 +171,7 @@ class box_graph_invoices_permonth extends ModeleBoxes if (! $mesg) { $langs->load("bills"); - + $px2->SetData($data2); unset($data2); $px2->SetPrecisionY(0); @@ -263,11 +263,12 @@ class box_graph_invoices_permonth extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php b/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php index 0931d2d05df..c7856d619f6 100644 --- a/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php +++ b/htdocs/core/boxes/box_graph_invoices_supplier_permonth.php @@ -170,7 +170,7 @@ class box_graph_invoices_supplier_permonth extends ModeleBoxes if (! $mesg) { $langs->load("bills"); - + $px2->SetData($data2); unset($data2); $px2->SetPrecisionY(0); @@ -262,11 +262,12 @@ class box_graph_invoices_supplier_permonth extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_graph_orders_permonth.php b/htdocs/core/boxes/box_graph_orders_permonth.php index 4f86dcd0b8b..4a0f0a7d5b1 100644 --- a/htdocs/core/boxes/box_graph_orders_permonth.php +++ b/htdocs/core/boxes/box_graph_orders_permonth.php @@ -90,7 +90,7 @@ class box_graph_orders_permonth extends ModeleBoxes if ($user->rights->commande->lire) { $langs->load("orders"); - + $param_year='DOLUSERCOOKIE_box_'.$this->boxcode.'_year'; $param_shownb='DOLUSERCOOKIE_box_'.$this->boxcode.'_shownb'; $param_showtot='DOLUSERCOOKIE_box_'.$this->boxcode.'_showtot'; @@ -263,11 +263,12 @@ class box_graph_orders_permonth extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_graph_orders_supplier_permonth.php b/htdocs/core/boxes/box_graph_orders_supplier_permonth.php index 6df7d81766c..2ab14bb4502 100644 --- a/htdocs/core/boxes/box_graph_orders_supplier_permonth.php +++ b/htdocs/core/boxes/box_graph_orders_supplier_permonth.php @@ -89,7 +89,7 @@ class box_graph_orders_supplier_permonth extends ModeleBoxes if ($user->rights->fournisseur->commande->lire) { $langs->load("orders"); - + $param_year='DOLUSERCOOKIE_box_'.$this->boxcode.'_year'; $param_shownb='DOLUSERCOOKIE_box_'.$this->boxcode.'_shownb'; $param_showtot='DOLUSERCOOKIE_box_'.$this->boxcode.'_showtot'; @@ -262,11 +262,12 @@ class box_graph_orders_supplier_permonth extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_graph_product_distribution.php b/htdocs/core/boxes/box_graph_product_distribution.php index 46ddccc2a1d..48168eadb53 100644 --- a/htdocs/core/boxes/box_graph_product_distribution.php +++ b/htdocs/core/boxes/box_graph_product_distribution.php @@ -390,11 +390,12 @@ class box_graph_product_distribution extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_graph_propales_permonth.php b/htdocs/core/boxes/box_graph_propales_permonth.php index 8ef7b25969f..0ae61938ce7 100644 --- a/htdocs/core/boxes/box_graph_propales_permonth.php +++ b/htdocs/core/boxes/box_graph_propales_permonth.php @@ -264,11 +264,12 @@ class box_graph_propales_permonth extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_members.php b/htdocs/core/boxes/box_members.php index 9c166aac866..d5d8f1243f5 100644 --- a/htdocs/core/boxes/box_members.php +++ b/htdocs/core/boxes/box_members.php @@ -169,11 +169,12 @@ class box_members extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_produits.php b/htdocs/core/boxes/box_produits.php index c8ef1b5f558..5cce3254bfb 100644 --- a/htdocs/core/boxes/box_produits.php +++ b/htdocs/core/boxes/box_produits.php @@ -192,11 +192,12 @@ class box_produits extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_produits_alerte_stock.php b/htdocs/core/boxes/box_produits_alerte_stock.php index 5a718b79696..4d79abd156b 100644 --- a/htdocs/core/boxes/box_produits_alerte_stock.php +++ b/htdocs/core/boxes/box_produits_alerte_stock.php @@ -199,11 +199,12 @@ class box_produits_alerte_stock extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_project.php b/htdocs/core/boxes/box_project.php index 7d819ec0d2b..8733f3ed8ce 100644 --- a/htdocs/core/boxes/box_project.php +++ b/htdocs/core/boxes/box_project.php @@ -173,11 +173,12 @@ class box_project extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_propales.php b/htdocs/core/boxes/box_propales.php index c14cf07a51c..b0a1e4a3798 100644 --- a/htdocs/core/boxes/box_propales.php +++ b/htdocs/core/boxes/box_propales.php @@ -166,11 +166,12 @@ class box_propales extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) + function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents); + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_prospect.php b/htdocs/core/boxes/box_prospect.php index 3895a27a9f1..40adb98b405 100644 --- a/htdocs/core/boxes/box_prospect.php +++ b/htdocs/core/boxes/box_prospect.php @@ -167,11 +167,12 @@ class box_prospect extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_services_contracts.php b/htdocs/core/boxes/box_services_contracts.php index 802dee8474f..b45bde124a3 100644 --- a/htdocs/core/boxes/box_services_contracts.php +++ b/htdocs/core/boxes/box_services_contracts.php @@ -64,7 +64,7 @@ class box_services_contracts extends ModeleBoxes $contractstatic=new Contrat($db); $contratlignestatic=new ContratLigne($db); $thirdpartytmp = new Societe($db); - + $sql = "SELECT s.nom as name, s.rowid as socid,"; $sql.= " c.rowid, c.ref, c.statut as contract_status,"; $sql.= " cd.rowid as cdid, cd.tms as datem, cd.statut, cd.label, cd.description, cd.product_type as type,"; @@ -103,14 +103,14 @@ class box_services_contracts extends ModeleBoxes $contratlignestatic->type=$objp->type; $contratlignestatic->product_id=$objp->product_id; $contratlignestatic->product_ref=$objp->product_ref; - + $contractstatic->statut=$objp->contract_status; $contractstatic->id=$objp->rowid; $contractstatic->ref=$objp->ref; - + $thirdpartytmp->name = $objp->name; $thirdpartytmp->id = $objp->socid; - + // Multilangs if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active { @@ -132,7 +132,7 @@ class box_services_contracts extends ModeleBoxes 'text' => $contratlignestatic->getNomUrl(1), 'asis' => 1 ); - + $this->info_box_contents[$i][] = array('td' => 'align="left"', 'text' => $contractstatic->getNomUrl(1), 'asis' => 1 @@ -175,11 +175,12 @@ class box_services_contracts extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) - { - parent::showBox($this->info_box_head, $this->info_box_contents); + function showBox($head = null, $contents = null, $nooutput=0) + { + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_services_expired.php b/htdocs/core/boxes/box_services_expired.php index 296ef56af8a..1e39b286ee9 100644 --- a/htdocs/core/boxes/box_services_expired.php +++ b/htdocs/core/boxes/box_services_expired.php @@ -118,7 +118,7 @@ class box_services_expired extends ModeleBoxes $i++; } - if ($num==0) + if ($num==0) { $langs->load("contracts"); $this->info_box_contents[$i][0] = array('td' => 'align="center"','text'=>$langs->trans("NoExpiredServices")); @@ -147,11 +147,13 @@ class box_services_expired extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) + function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents); + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_supplier_orders.php b/htdocs/core/boxes/box_supplier_orders.php index 84521bf4ee0..26061de5bf8 100644 --- a/htdocs/core/boxes/box_supplier_orders.php +++ b/htdocs/core/boxes/box_supplier_orders.php @@ -171,11 +171,13 @@ class box_supplier_orders extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines - * @return void - */ - function showBox($head = null, $contents = null) + * @param int $nooutput No print, only return string + * @param int $nooutput No print, only return string + * @return void + */ + function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents); + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } diff --git a/htdocs/core/boxes/box_task.php b/htdocs/core/boxes/box_task.php index d314af73cd1..29dd9390597 100644 --- a/htdocs/core/boxes/box_task.php +++ b/htdocs/core/boxes/box_task.php @@ -91,11 +91,11 @@ class box_task extends ModeleBoxes $sql.= $db->plimit($max, 0); $result = $db->query($sql); - if ($result) + if ($result) { $num = $db->num_rows($result); $i = 0; - while ($i < $num) + while ($i < $num) { $objp = $db->fetch_object($result); $this->info_box_contents[$i][] = array( @@ -137,10 +137,11 @@ class box_task extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines + * @param int $nooutput No print, only return string * @return void */ - function showBox($head = null, $contents = null) + function showBox($head = null, $contents = null, $nooutput=0) { - parent::showBox($this->info_box_head, $this->info_box_contents); + parent::showBox($this->info_box_head, $this->info_box_contents, $nooutput); } } From 1fdd43452828b81978807187f8ced2698ee58892 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Tue, 28 Jun 2016 09:52:27 +0200 Subject: [PATCH 06/31] fix travis --- htdocs/core/boxes/box_services_expired.php | 1 - htdocs/core/boxes/box_supplier_orders.php | 1 - 2 files changed, 2 deletions(-) diff --git a/htdocs/core/boxes/box_services_expired.php b/htdocs/core/boxes/box_services_expired.php index 1e39b286ee9..29db63054e5 100644 --- a/htdocs/core/boxes/box_services_expired.php +++ b/htdocs/core/boxes/box_services_expired.php @@ -148,7 +148,6 @@ class box_services_expired extends ModeleBoxes * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines * @param int $nooutput No print, only return string - * @param int $nooutput No print, only return string * @return void */ function showBox($head = null, $contents = null, $nooutput=0) diff --git a/htdocs/core/boxes/box_supplier_orders.php b/htdocs/core/boxes/box_supplier_orders.php index 26061de5bf8..1f0e1ece2ef 100644 --- a/htdocs/core/boxes/box_supplier_orders.php +++ b/htdocs/core/boxes/box_supplier_orders.php @@ -171,7 +171,6 @@ class box_supplier_orders extends ModeleBoxes * * @param array $head Array with properties of box title * @param array $contents Array with properties of box lines - * @param int $nooutput No print, only return string * @param int $nooutput No print, only return string * @return void */ From d9035e53089f4cc2599f54a7852daf3c657d67dd Mon Sep 17 00:00:00 2001 From: gauthier Date: Tue, 28 Jun 2016 11:41:23 +0200 Subject: [PATCH 07/31] FIX : receiving link never works --- htdocs/core/lib/sendings.lib.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/core/lib/sendings.lib.php b/htdocs/core/lib/sendings.lib.php index 1c0c589870e..f95fd5dbe76 100644 --- a/htdocs/core/lib/sendings.lib.php +++ b/htdocs/core/lib/sendings.lib.php @@ -302,7 +302,9 @@ function show_list_sending_receive($origin,$origin_id,$filter='') $expedition->id=$objp->sendingid; $expedition->fetchObjectLinked($expedition->id,$expedition->element); //var_dump($expedition->linkedObjects); - $receiving=(! empty($expedition->linkedObjects['delivery'][0])?$expedition->linkedObjects['delivery'][0]:''); + reset($expedition->linkedObjects['delivery']); + $first = key($expedition->linkedObjects['delivery']); + $receiving=(! empty($expedition->linkedObjects['delivery'][$first])?$expedition->linkedObjects['delivery'][$first]:''); if (! empty($receiving)) { From 7e8506e25ff3579cd54bb360ff52114a1726899e Mon Sep 17 00:00:00 2001 From: Alexis Algoud Date: Tue, 28 Jun 2016 13:25:47 +0200 Subject: [PATCH 08/31] FIX #5338 use of not initialized var $aphour, $apmin, etc --- htdocs/comm/action/card.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 5b013e7a57c..e54fd788a92 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -61,8 +61,14 @@ $originid=GETPOST('originid','int'); $confirm = GETPOST('confirm', 'alpha'); $fulldayevent=GETPOST('fullday'); -$datep=dol_mktime($fulldayevent?'00':GETPOST("aphour"), $fulldayevent?'00':GETPOST("apmin"), 0, GETPOST("apmonth"), GETPOST("apday"), GETPOST("apyear")); -$datef=dol_mktime($fulldayevent?'23':GETPOST("p2hour"), $fulldayevent?'59':GETPOST("p2min"), $fulldayevent?'59':'0', GETPOST("p2month"), GETPOST("p2day"), GETPOST("p2year")); + +$aphour = GETPOST('aphour'); +$apmin = GETPOST('apmin'); +$p2hour = GETPOST('p2hour'); +$p2min = GETPOST('p2min'); + +$datep=dol_mktime($fulldayevent?'00':$aphour, $fulldayevent?'00':$apmin, 0, GETPOST("apmonth"), GETPOST("apday"), GETPOST("apyear")); +$datef=dol_mktime($fulldayevent?'23':$p2hour, $fulldayevent?'59':$p2min, $fulldayevent?'59':'0', GETPOST("p2month"), GETPOST("p2day"), GETPOST("p2year")); // Security check $socid = GETPOST('socid','int'); @@ -92,7 +98,6 @@ $extralabels=$extrafields->fetch_name_optionals_label($object->table_element); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('actioncard','globalcard')); - /* * Actions */ From dfc4f3e7fe8bd3b503402d6fc71e10de329c65d7 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Wed, 29 Jun 2016 11:06:02 +0200 Subject: [PATCH 09/31] on going accountacy working --- htdocs/accountancy/bookkeeping/card.php | 122 +++-- htdocs/accountancy/bookkeeping/list.php | 25 +- .../accountancy/class/bookkeeping.class.php | 432 ++++++++++-------- .../class/html.formventilation.class.php | 72 ++- .../accountancy/journal/purchasesjournal.php | 23 +- htdocs/accountancy/journal/sellsjournal.php | 33 +- htdocs/langs/en_US/accountancy.lang | 6 + 7 files changed, 405 insertions(+), 308 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/card.php b/htdocs/accountancy/bookkeeping/card.php index 7293797ecc6..ba3c37f1997 100644 --- a/htdocs/accountancy/bookkeeping/card.php +++ b/htdocs/accountancy/bookkeeping/card.php @@ -18,9 +18,9 @@ */ /** - * \file htdocs/accountancy/bookkeeping/card.php - * \ingroup Advanced accountancy - * \brief Page to show book-entry + * \file htdocs/accountancy/bookkeeping/card.php + * \ingroup Advanced accountancy + * \brief Page to show book-entry */ require '../../main.inc.php'; @@ -62,17 +62,17 @@ if (! empty($update)) { } if ($action == "confirm_update") { - + $error = 0; - + if ((floatval($debit) != 0.0) && (floatval($credit) != 0.0)) { setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors'); $error ++; } - + if (empty($error)) { $book = new BookKeeping($db); - + $result = $book->fetch($id); if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); @@ -82,7 +82,7 @@ if ($action == "confirm_update") { $book->label_compte = $label_compte; $book->debit = $debit; $book->credit = $credit; - + if (floatval($debit) != 0.0) { $book->montant = $debit; $book->sens = 'D'; @@ -91,7 +91,7 @@ if ($action == "confirm_update") { $book->montant = $credit; $book->sens = 'C'; } - + $result = $book->update($user); if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); @@ -101,19 +101,19 @@ if ($action == "confirm_update") { } } } -} +} else if ($action == "add") { $error = 0; - + if ((floatval($debit) != 0.0) && (floatval($credit) != 0.0)) { setEventMessages($langs->trans('ErrorDebitCredit'), null, 'errors'); $error ++; } - + if (empty($error)) { $book = new BookKeeping($db); - + $book->numero_compte = $account_number; $book->code_tiers = $code_tiers; $book->label_compte = $label_compte; @@ -126,17 +126,17 @@ else if ($action == "add") { $book->code_journal = GETPOST('code_journal'); $book->fk_doc = GETPOST('fk_doc'); $book->fk_docdet = GETPOST('fk_docdet'); - + if (floatval($debit) != 0.0) { $book->montant = $debit; $book->sens = 'D'; } - + if (floatval($credit) != 0.0) { $book->montant = $credit; $book->sens = 'C'; } - + $result = $book->createStd($user); if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); @@ -145,15 +145,15 @@ else if ($action == "add") { $action = ''; } } -} +} else if ($action == "confirm_delete") { $book = new BookKeeping($db); - + $result = $book->fetch($id); - + $piece_num = $book->piece_num; - + if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); } else { @@ -163,11 +163,11 @@ else if ($action == "confirm_delete") { } } $action = ''; -} +} else if ($action == "confirm_create") { $book = new BookKeeping($db); - + $book->label_compte = ''; $book->debit = 0; $book->credit = 0; @@ -178,9 +178,9 @@ else if ($action == "confirm_create") { $book->code_journal = GETPOST('code_journal'); $book->fk_doc = 0; $book->fk_docdet = 0; - + $book->montant = 0; - + $result = $book->createStd($user); if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); @@ -209,15 +209,15 @@ if ($action == 'delete') { if ($action == 'create') { print load_fiche_titre($langs->trans("CreateMvts")); - + $code_journal_array = array ( $conf->global->ACCOUNTING_SELL_JOURNAL => $conf->global->ACCOUNTING_SELL_JOURNAL, $conf->global->ACCOUNTING_PURCHASE_JOURNAL => $conf->global->ACCOUNTING_PURCHASE_JOURNAL, $conf->global->ACCOUNTING_SOCIAL_JOURNAL => $conf->global->ACCOUNTING_SOCIAL_JOURNAL, $conf->global->ACCOUNTING_MISCELLANEOUS_JOURNAL => $conf->global->ACCOUNTING_MISCELLANEOUS_JOURNAL, - $conf->global->ACCOUNTING_EXPENSEREPORT_JOURNAL => $conf->global->ACCOUNTING_EXPENSEREPORT_JOURNAL + $conf->global->ACCOUNTING_EXPENSEREPORT_JOURNAL => $conf->global->ACCOUNTING_EXPENSEREPORT_JOURNAL ); - + $sql = 'SELECT DISTINCT accountancy_journal FROM ' . MAIN_DB_PREFIX . 'bank_account WHERE clos=0'; $resql = $db->query($sql); if (! $resql) { @@ -229,52 +229,52 @@ if ($action == 'create') { } } } - + $book = new BookKeeping($db); $next_num_mvt = $book->getNextNumMvt(); - + print '
'; print '' . "\n"; print '' . "\n"; - + dol_fiche_head(); - + print ''; print ''; print ''; print ''; print ''; - + print ''; print ''; print ''; print ''; - + print ''; print ''; print ''; print ''; - + print ''; print ''; print ''; print ''; - + print ''; print ''; print ''; print ''; - + print '
' . $langs->trans("NumMvts") . '' . $next_num_mvt . '
' . $langs->trans("Docdate") . ''; print $html->select_date('', 'doc_date', '', '', '', "create_mvt", 1, 1); print '
' . $langs->trans("Codejournal") . '' . $html->selectarray('code_journal', $code_journal_array) . '
' . $langs->trans("Docref") . '
' . $langs->trans("Doctype") . '
'; - + dol_fiche_end(); - + print '
'; print '     '; print '
'; - + print '
'; } else { $book = new BookKeeping($db); @@ -283,9 +283,9 @@ if ($action == 'create') { setEventMessages($book->error, $book->errors, 'errors'); } if (! empty($book->piece_num)) { - + print load_fiche_titre($langs->trans("UpdateMvts"), '' . $langs->trans('BackToList') . ''); - + print ''; print ''; print ''; @@ -309,14 +309,14 @@ if ($action == 'create') { print ''; print '
' . $langs->trans("NumMvts") . '
'; print '
'; - + $result = $book->fetch_all_per_mvt($piece_num); if ($result < 0) { setEventMessages($book->error, $book->errors, 'errors'); } else { - + print load_fiche_titre($langs->trans("ListeMvts")); - + print '
'; print '' . "\n"; print '' . "\n"; @@ -324,15 +324,15 @@ if ($action == 'create') { print '' . "\n"; print '' . "\n"; print '' . "\n"; - + print ""; if (count($book->linesmvt) > 0) { - + $total_debit = 0; $total_credit = 0; - + print ''; - + print_liste_field_titre($langs->trans("AccountAccountingShort")); print_liste_field_titre($langs->trans("Code_tiers")); print_liste_field_titre($langs->trans("Labelcompte")); @@ -341,18 +341,18 @@ if ($action == 'create') { print_liste_field_titre($langs->trans("Amount"), "", "", "", "", 'align="center"'); print_liste_field_titre($langs->trans("Sens"), "", "", "", "", 'align="center"'); print_liste_field_titre($langs->trans("Action"), "", "", "", "", 'width="60" align="center"'); - + print "\n"; - + foreach ( $book->linesmvt as $line ) { $var = ! $var; - print ''; - + print ''; + $total_debit += $line->debit; $total_credit += $line->credit; - + if ($action == 'update' && $line->id == $id) { - + print ''; @@ -376,7 +376,7 @@ if ($action == 'create') { print ''; print ''; print ''; - + print ''; } print "\n"; } - + if ($total_debit != $total_credit) { setEventMessages(null, array ( - 'MvtNotCorrectlyBalanced', - $total_credit, - $total_debit + $langs->trans('MvtNotCorrectlyBalanced', $total_credit, $total_debit) ), 'errors'); } - + if ($action == "" || $action == 'add') { $var = ! $var; - print ''; + print ''; print ''; diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index cb5d7caf006..23148213aa0 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -202,14 +202,22 @@ if ($action == 'delbookkeeping') { if ($action == 'delbookkeepingyearconfirm') { $delyear = GETPOST('delyear', 'int'); + if ($delyear==-1) { + $delyear=0; + } + $deljournal = GETPOST('deljournal','alpha'); + if ($deljournal==-1) { + $deljournal=0; + } - if (! empty($delyear)) { - $result = $object->deleteByYear($delyear); + + if (! empty($delyear) || ! empty($deljournal)) { + $result = $object->deleteByYearAndJournal($delyear,$deljournal); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } Header("Location: list.php"); - exit(); + exit; } } if ($action == 'delmouvconfirm') { @@ -222,7 +230,7 @@ if ($action == 'delmouvconfirm') { setEventMessages($object->error, $object->errors, 'errors'); } Header("Location: list.php"); - exit(); + exit; } } if ($action == 'export_csv') { @@ -276,11 +284,13 @@ if ($action == 'delbookkeepingyear') { $form_question = array (); $delyear = GETPOST('delyear'); + $deljournal = GETPOST('deljournal'); if (empty($delyear)) { $delyear = dol_print_date(dol_now(), '%Y'); } $year_array = $formventilation->selectyear_accountancy_bookkepping($delyear, 'delyear', 0, 'array'); + $journal_array = $formventilation->selectjournal_accountancy_bookkepping($deljournal, 'deljournal', 0, 'array'); $form_question['delyear'] = array ( 'name' => 'delyear', @@ -289,6 +299,13 @@ if ($action == 'delbookkeepingyear') { 'values' => $year_array, 'default' => $delyear ); + $form_question['deljournal'] = array ( + 'name' => 'deljournal', + 'type' => 'select', + 'label' => $langs->trans('DelJournal'), + 'values' => $journal_array, + 'default' => $deljournal + ); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans('DeleteMvt'), $langs->trans('ConfirmDeleteMvt'), 'delbookkeepingyearconfirm', $form_question, 0, 1); print $formconfirm; diff --git a/htdocs/accountancy/class/bookkeeping.class.php b/htdocs/accountancy/class/bookkeeping.class.php index 6f4698413dc..79e66ab7cce 100644 --- a/htdocs/accountancy/class/bookkeeping.class.php +++ b/htdocs/accountancy/class/bookkeeping.class.php @@ -54,13 +54,13 @@ class BookKeeping extends CommonObject * @var string Name of table without prefix where object is stored */ public $table_element = 'accounting_bookkeeping'; - + /** * * @var BookKeepingLine[] Lines */ public $lines = array (); - + /** * * @var int ID @@ -84,10 +84,10 @@ class BookKeeping extends CommonObject public $import_key; public $code_journal; public $piece_num; - + /** */ - + /** * Constructor * @@ -97,22 +97,24 @@ class BookKeeping extends CommonObject $this->db = $db; return 1; } - + /** * Create object into database * * @param User $user User that creates * @param bool $notrigger false=launch triggers after, true=disable triggers - * + * * @return int <0 if KO, Id of created object if OK */ public function create(User $user, $notrigger = false) { dol_syslog(__METHOD__, LOG_DEBUG); - + + global $langs; + $error = 0; - + // Clean parameters - + if (isset($this->doc_type)) { $this->doc_type = trim($this->doc_type); } @@ -158,32 +160,32 @@ class BookKeeping extends CommonObject if (isset($this->piece_num)) { $this->piece_num = trim($this->piece_num); } - + $this->db->begin(); - + $this->piece_num = 0; - + // first check if line not yet in bookkeeping $sql = "SELECT count(*) as nb"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; - $sql .= " WHERE doc_type = '" . $this->doc_type . "'"; + $sql .= " WHERE doc_type = '" . $this->db->escape($this->doc_type) . "'"; $sql .= " AND fk_docdet = " . $this->fk_docdet; - $sql .= " AND numero_compte = '" . $this->numero_compte . "'"; - - dol_syslog(get_class($this) . ":: create sql=" . $sql, LOG_DEBUG); + $sql .= " AND numero_compte = '" . $this->db->escape($this->numero_compte) . "'"; + + dol_syslog(get_class($this) . ":: create ", LOG_DEBUG); $resql = $this->db->query($sql); - + if ($resql) { $row = $this->db->fetch_object($resql); if ($row->nb == 0) { - + // Determine piece_num $sqlnum = "SELECT piece_num"; $sqlnum .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sqlnum .= " WHERE doc_type = '" . $this->doc_type . "'"; $sqlnum .= " AND fk_docdet = '" . $this->fk_docdet . "'"; $sqlnum .= " AND doc_ref = '" . $this->doc_ref . "'"; - + dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG); $resqlnum = $this->db->query($sqlnum); if ($resqlnum) { @@ -194,7 +196,7 @@ class BookKeeping extends CommonObject if (empty($this->piece_num)) { $sqlnum = "SELECT MAX(piece_num)+1 as maxpiecenum"; $sqlnum .= " FROM " . MAIN_DB_PREFIX . $this->table_element; - + dol_syslog(get_class($this) . ":: create sqlnum=" . $sqlnum, LOG_DEBUG); $resqlnum = $this->db->query($sqlnum); if ($resqlnum) { @@ -202,18 +204,19 @@ class BookKeeping extends CommonObject $this->piece_num = $objnum->maxpiecenum; } } - dol_syslog(get_class($this) . ":: create this->piece_num=" . $this->piece_num, LOG_DEBUG); if (empty($this->piece_num)) { $this->piece_num = 1; } - + + dol_syslog(get_class($this) . ":: create this->piece_num=" . $this->piece_num, LOG_DEBUG); + $now = dol_now(); if (empty($this->date_create)) { $this->date_create = $now; } - + $sql = "INSERT INTO " . MAIN_DB_PREFIX . $this->table_element . " ("; - + $sql .= "doc_date"; $sql .= ", doc_type"; $sql .= ", doc_ref"; @@ -230,33 +233,33 @@ class BookKeeping extends CommonObject $sql .= ", import_key"; $sql .= ", code_journal"; $sql .= ", piece_num"; - + $sql .= ") VALUES ("; - - $sql .= "'" . $this->doc_date . "'"; - $sql .= ",'" . $this->doc_type . "'"; - $sql .= ",'" . $this->doc_ref . "'"; + + $sql .= "'" . $this->db->idate($this->doc_date) . "'"; + $sql .= ",'" . $this->db->escape($this->doc_type) . "'"; + $sql .= ",'" . $this->db->escape($this->doc_ref) . "'"; $sql .= "," . $this->fk_doc; $sql .= "," . $this->fk_docdet; - $sql .= ",'" . $this->code_tiers . "'"; - $sql .= ",'" . $this->numero_compte . "'"; + $sql .= ",'" . $this->db->escape($this->code_tiers) . "'"; + $sql .= ",'" . $this->db->escape($this->numero_compte) . "'"; $sql .= ",'" . $this->db->escape($this->label_compte) . "'"; $sql .= "," . $this->debit; $sql .= "," . $this->credit; $sql .= "," . $this->montant; - $sql .= ",'" . $this->sens . "'"; + $sql .= ",'" . $this->db->escape($this->sens) . "'"; $sql .= ",'" . $this->fk_user_author . "'"; $sql .= ",'" . $this->date_create . "'"; - $sql .= ",'" . $this->code_journal . "'"; + $sql .= ",'" . $this->db->escape($this->code_journal) . "'"; $sql .= "," . $this->piece_num; - + $sql .= ")"; - - dol_syslog(get_class($this) . ":: create sql=" . $sql, LOG_DEBUG); + + dol_syslog(get_class($this) . ":: create", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); - + if ($id > 0) { $this->id = $id; $result = 0; @@ -264,67 +267,67 @@ class BookKeeping extends CommonObject $result = - 2; $error ++; $this->errors[] = 'Error Create Error ' . $result . ' lecture ID'; - dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + dol_syslog(__METHOD__ . ' $result='.$result.' ' . implode(',', $this->errors), LOG_ERR); } } else { $result = - 1; $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + dol_syslog(__METHOD__ . ' $result='.$result.' ' . implode(',', $this->errors), LOG_ERR); } } else { $result = - 3; $error ++; - $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + $this->errors[] = $langs->trans('BookeppingLineAlreayExists'); + dol_syslog(__METHOD__ . ' $result='.$result.' ' . implode(',', $this->errors), LOG_ERR); } } else { $result = - 5; $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); - dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); + dol_syslog(__METHOD__ . ' $result='.$result.' '. implode(',', $this->errors), LOG_ERR); } - + if (! $error) { - + if (! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action to call a trigger. - + // // Call triggers // $result=$this->call_trigger('MYOBJECT_CREATE',$user); // if ($result < 0) $error++; // // End call triggers } } - + // Commit or rollback if ($error) { $this->db->rollback(); - + return - 1 * $error; } else { $this->db->commit(); - + return $result; } } - + /** * Create object into database * * @param User $user User that creates * @param bool $notrigger false=launch triggers after, true=disable triggers - * + * * @return int <0 if KO, Id of created object if OK */ public function createStd(User $user, $notrigger = false) { dol_syslog(__METHOD__, LOG_DEBUG); - + $error = 0; - + // Clean parameters - + if (isset($this->doc_type)) { $this->doc_type = trim($this->doc_type); } @@ -370,13 +373,13 @@ class BookKeeping extends CommonObject if (isset($this->piece_num)) { $this->piece_num = trim($this->piece_num); } - + // Check parameters // Put here code to add control on parameters values - + // Insert request $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . $this->table_element . '('; - + $sql .= 'doc_date,'; $sql .= 'doc_type,'; $sql .= 'doc_ref,'; @@ -393,9 +396,9 @@ class BookKeeping extends CommonObject $sql .= 'import_key,'; $sql .= 'code_journal,'; $sql .= 'piece_num'; - + $sql .= ') VALUES ('; - + $sql .= ' ' . (! isset($this->doc_date) || dol_strlen($this->doc_date) == 0 ? 'NULL' : "'" . $this->db->idate($this->doc_date) . "'") . ','; $sql .= ' ' . (! isset($this->doc_type) ? 'NULL' : "'" . $this->db->escape($this->doc_type) . "'") . ','; $sql .= ' ' . (! isset($this->doc_ref) ? 'NULL' : "'" . $this->db->escape($this->doc_ref) . "'") . ','; @@ -412,58 +415,58 @@ class BookKeeping extends CommonObject $sql .= ' ' . (! isset($this->import_key) ? 'NULL' : "'" . $this->db->escape($this->import_key) . "'") . ','; $sql .= ' ' . (! isset($this->code_journal) ? 'NULL' : "'" . $this->db->escape($this->code_journal) . "'") . ','; $sql .= ' ' . (! isset($this->piece_num) ? 'NULL' : $this->piece_num); - + $sql .= ')'; - + $this->db->begin(); - + $resql = $this->db->query($sql); if (! $resql) { $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } - + if (! $error) { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX . $this->table_element); - + if (! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action to call a trigger. - + // // Call triggers // $result=$this->call_trigger('MYOBJECT_CREATE',$user); // if ($result < 0) $error++; // // End call triggers } } - + // Commit or rollback if ($error) { $this->db->rollback(); - + return - 1 * $error; } else { $this->db->commit(); - + return $this->id; } } - + /** * Load object in memory from the database * * @param int $id Id object * @param string $ref Ref - * + * * @return int <0 if KO, 0 if not found, >0 if OK */ public function fetch($id, $ref = null) { dol_syslog(__METHOD__, LOG_DEBUG); - + $sql = 'SELECT'; $sql .= ' t.rowid,'; - + $sql .= " t.doc_date,"; $sql .= " t.doc_type,"; $sql .= " t.doc_ref,"; @@ -480,22 +483,22 @@ class BookKeeping extends CommonObject $sql .= " t.import_key,"; $sql .= " t.code_journal,"; $sql .= " t.piece_num"; - + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; if (null !== $ref) { $sql .= ' WHERE t.ref = ' . '\'' . $ref . '\''; } else { $sql .= ' WHERE t.rowid = ' . $id; } - + $resql = $this->db->query($sql); if ($resql) { $numrows = $this->db->num_rows($resql); if ($numrows) { $obj = $this->db->fetch_object($resql); - + $this->id = $obj->rowid; - + $this->doc_date = $this->db->jdate($obj->doc_date); $this->doc_type = $obj->doc_type; $this->doc_ref = $obj->doc_ref; @@ -514,7 +517,7 @@ class BookKeeping extends CommonObject $this->piece_num = $obj->piece_num; } $this->db->free($resql); - + if ($numrows) { return 1; } else { @@ -523,11 +526,11 @@ class BookKeeping extends CommonObject } else { $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); - + return - 1; } } - + /** * Load object in memory from the database * @@ -537,15 +540,15 @@ class BookKeeping extends CommonObject * @param int $offset offset limit * @param array $filter filter array * @param string $filtermode filter mode (AND or OR) - * + * * @return int <0 if KO, >0 if OK */ public function fetchAll($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); - + $sql = 'SELECT'; $sql .= ' t.rowid,'; - + $sql .= " t.doc_date,"; $sql .= " t.doc_type,"; $sql .= " t.doc_ref,"; @@ -562,9 +565,9 @@ class BookKeeping extends CommonObject $sql .= " t.import_key,"; $sql .= " t.code_journal,"; $sql .= " t.piece_num"; - + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; - + // Manage filter $sqlwhere = array (); if (count($filter) > 0) { @@ -584,11 +587,11 @@ class BookKeeping extends CommonObject } } } - + if (count($sqlwhere) > 0) { $sql .= ' WHERE ' . implode(' ' . $filtermode . ' ', $sqlwhere); } - + if (! empty($sortfield)) { $sql .= $this->db->order($sortfield, $sortorder); } @@ -596,16 +599,16 @@ class BookKeeping extends CommonObject $sql .= ' ' . $this->db->plimit($limit + 1, $offset); } $this->lines = array (); - + $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); - + while ( $obj = $this->db->fetch_object($resql) ) { $line = new BookKeepingLine(); - + $line->id = $obj->rowid; - + $line->doc_date = $this->db->jdate($obj->doc_date); $line->doc_type = $obj->doc_type; $line->doc_ref = $obj->doc_ref; @@ -622,20 +625,20 @@ class BookKeeping extends CommonObject $line->import_key = $obj->import_key; $line->code_journal = $obj->code_journal; $line->piece_num = $obj->piece_num; - + $this->lines[] = $line; } $this->db->free($resql); - + return $num; } else { $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); - + return - 1; } } - + /** * Load object in memory from the database * @@ -650,15 +653,15 @@ class BookKeeping extends CommonObject */ public function fetchAllBalance($sortorder = '', $sortfield = '', $limit = 0, $offset = 0, array $filter = array(), $filtermode = 'AND') { dol_syslog(__METHOD__, LOG_DEBUG); - + $sql = 'SELECT'; $sql .= " t.numero_compte,"; $sql .= " SUM(t.debit) as debit,"; $sql .= " SUM(t.credit) as credit"; - - + + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; - + // Manage filter $sqlwhere = array (); if (count($filter) > 0) { @@ -678,13 +681,13 @@ class BookKeeping extends CommonObject } } } - + if (count($sqlwhere) > 0) { $sql .= ' WHERE ' . implode(' ' . $filtermode . ' ', $sqlwhere); } - + $sql .= ' GROUP BY t.numero_compte'; - + if (! empty($sortfield)) { $sql .= $this->db->order($sortfield, $sortorder); } @@ -692,45 +695,45 @@ class BookKeeping extends CommonObject $sql .= ' ' . $this->db->plimit($limit + 1, $offset); } $this->lines = array (); - + $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); - + while ( $obj = $this->db->fetch_object($resql) ) { $line = new BookKeepingLine(); - + $line->numero_compte = $obj->numero_compte; $line->debit = $obj->debit; $line->credit = $obj->credit; $this->lines[] = $line; } $this->db->free($resql); - + return $num; } else { $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); - + return - 1; } } - + /** * Update object into database * * @param User $user User that modifies * @param bool $notrigger false=launch triggers after, true=disable triggers - * + * * @return int <0 if KO, >0 if OK */ public function update(User $user, $notrigger = false) { $error = 0; - + dol_syslog(__METHOD__, LOG_DEBUG); - + // Clean parameters - + if (isset($this->doc_type)) { $this->doc_type = trim($this->doc_type); } @@ -776,13 +779,13 @@ class BookKeeping extends CommonObject if (isset($this->piece_num)) { $this->piece_num = trim($this->piece_num); } - + // Check parameters // Put here code to add a control on parameters values - + // Update request $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; - + $sql .= ' doc_date = ' . (! isset($this->doc_date) || dol_strlen($this->doc_date) != 0 ? "'" . $this->db->idate($this->doc_date) . "'" : 'null') . ','; $sql .= ' doc_type = ' . (isset($this->doc_type) ? "'" . $this->db->escape($this->doc_type) . "'" : "null") . ','; $sql .= ' doc_ref = ' . (isset($this->doc_ref) ? "'" . $this->db->escape($this->doc_ref) . "'" : "null") . ','; @@ -799,71 +802,71 @@ class BookKeeping extends CommonObject $sql .= ' import_key = ' . (isset($this->import_key) ? "'" . $this->db->escape($this->import_key) . "'" : "null") . ','; $sql .= ' code_journal = ' . (isset($this->code_journal) ? "'" . $this->db->escape($this->code_journal) . "'" : "null") . ','; $sql .= ' piece_num = ' . (isset($this->piece_num) ? $this->piece_num : "null"); - + $sql .= ' WHERE rowid=' . $this->id; - + $this->db->begin(); - + $resql = $this->db->query($sql); if (! $resql) { $error ++; $this->errors[] = 'Error ' . $this->db->lasterror(); dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } - + if (! $error && ! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action calls a trigger. - + // // Call triggers // $result=$this->call_trigger('MYOBJECT_MODIFY',$user); // if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} // // End call triggers } - + // Commit or rollback if ($error) { $this->db->rollback(); - + return - 1 * $error; } else { $this->db->commit(); - + return 1; } } - + /** * Delete object in database * * @param User $user User that deletes * @param bool $notrigger false=launch triggers after, true=disable triggers - * + * * @return int <0 if KO, >0 if OK */ public function delete(User $user, $notrigger = false) { dol_syslog(__METHOD__, LOG_DEBUG); - + $error = 0; - + $this->db->begin(); - + if (! $error) { if (! $notrigger) { // Uncomment this and change MYOBJECT to your own tag if you // want this action calls a trigger. - + // // Call triggers // $result=$this->call_trigger('MYOBJECT_DELETE',$user); // if ($result < 0) { $error++; //Do also what you must do to rollback action if trigger fail} // // End call triggers } } - + if (! $error) { $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element; $sql .= ' WHERE rowid=' . $this->id; - + $resql = $this->db->query($sql); if (! $resql) { $error ++; @@ -871,19 +874,19 @@ class BookKeeping extends CommonObject dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } } - + // Commit or rollback if ($error) { $this->db->rollback(); - + return - 1 * $error; } else { $this->db->commit(); - + return 1; } } - + /** * Delete bookkepping by importkey * @@ -892,14 +895,14 @@ class BookKeeping extends CommonObject */ function deleteByImportkey($importkey) { $this->db->begin(); - + // first check if line not yet in bookkeeping $sql = "DELETE"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE import_key = '" . $importkey . "'"; - + $resql = $this->db->query($sql); - + if (! $resql) { $this->errors[] = "Error " . $this->db->lasterror(); foreach ( $this->errors as $errmsg ) { @@ -909,11 +912,11 @@ class BookKeeping extends CommonObject $this->db->rollback(); return - 1; } - + $this->db->commit(); return 1; } - + /** * Delete bookkepping by year * @@ -922,14 +925,14 @@ class BookKeeping extends CommonObject */ function deleteByYear($delyear) { $this->db->begin(); - + // first check if line not yet in bookkeeping $sql = "DELETE"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE YEAR(doc_date) = " . $delyear; - + $resql = $this->db->query($sql); - + if (! $resql) { $this->errors[] = "Error " . $this->db->lasterror(); foreach ( $this->errors as $errmsg ) { @@ -939,11 +942,54 @@ class BookKeeping extends CommonObject $this->db->rollback(); return - 1; } - + $this->db->commit(); return 1; } - + + /** + * Delete bookkepping by year + * + * @param string $delyear year to delete + * @param string $deljournal journal to delete + * @return int Result + */ + function deleteByYearAndJournal($delyear,$deljournal) { + $this->db->begin(); + + $sqlwhere=array(); + + // first check if line not yet in bookkeeping + $sql = "DELETE"; + $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; + if (!empty($delyear)) { + $sqlwhere[] .= " YEAR(doc_date) = " . $delyear; + } + if (!empty($deljournal)) { + $sqlwhere[] .= " code_journal = '" . $this->db->escape($deljournal)."'"; + } + + if (count($sqlwhere)>0) { + $sql.=" WHERE ".implode(' AND ', $sqlwhere); + + $resql = $this->db->query($sql); + + if (! $resql) { + $this->errors[] = "Error " . $this->db->lasterror(); + foreach ( $this->errors as $errmsg ) { + dol_syslog(get_class($this) . "::delete " . $errmsg, LOG_ERR); + $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); + } + $this->db->rollback(); + return - 1; + } + + $this->db->commit(); + + } + return 1; + } + /** * Delete bookkepping by piece number * @@ -952,14 +998,14 @@ class BookKeeping extends CommonObject */ function deleteMvtNum($piecenum) { $this->db->begin(); - + // first check if line not yet in bookkeeping $sql = "DELETE"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE piece_num = " . $piecenum; - + $resql = $this->db->query($sql); - + if (! $resql) { $this->errors[] = "Error " . $this->db->lasterror(); foreach ( $this->errors as $errmsg ) { @@ -969,57 +1015,57 @@ class BookKeeping extends CommonObject $this->db->rollback(); return - 1; } - + $this->db->commit(); return 1; } - + /** * Load an object from its id and create a new one in database * * @param int $fromid Id of object to clone - * + * * @return int New id of clone */ public function createFromClone($fromid) { dol_syslog(__METHOD__, LOG_DEBUG); - + global $user; $error = 0; $object = new Accountingbookkeeping($this->db); - + $this->db->begin(); - + // Load source object $object->fetch($fromid); // Reset object $object->id = 0; - + // Clear fields // ... - + // Create clone $result = $object->create($user); - + // Other options if ($result < 0) { $error ++; $this->errors = $object->errors; dol_syslog(__METHOD__ . ' ' . join(',', $this->errors), LOG_ERR); } - + // End if (! $error) { $this->db->commit(); - + return $object->id; } else { $this->db->rollback(); - + return - 1; } } - + /** * Initialise object with example values * Id must be 0 if object instance is a specimen @@ -1028,7 +1074,7 @@ class BookKeeping extends CommonObject */ public function initAsSpecimen() { $this->id = 0; - + $this->doc_date = ''; $this->doc_type = ''; $this->doc_ref = ''; @@ -1046,7 +1092,7 @@ class BookKeeping extends CommonObject $this->code_journal = ''; $this->piece_num = ''; } - + /** * Load an accounting document into memory from database * @@ -1057,12 +1103,12 @@ class BookKeeping extends CommonObject $sql = "SELECT piece_num,doc_date,code_journal,doc_ref,doc_type"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE piece_num = " . $piecenum; - + dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { $obj = $this->db->fetch_object($result); - + $this->piece_num = $obj->piece_num; $this->code_journal = $obj->code_journal; $this->doc_date = $this->db->jdate($obj->doc_date); @@ -1073,10 +1119,10 @@ class BookKeeping extends CommonObject dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR); return - 1; } - + return 1; } - + /** * Return next number movement * @@ -1084,13 +1130,13 @@ class BookKeeping extends CommonObject */ public function getNextNumMvt() { $sql = "SELECT MAX(piece_num)+1 as max FROM " . MAIN_DB_PREFIX . $this->table_element; - + dol_syslog(get_class($this) . "getNextNumMvt sql=" . $sql, LOG_DEBUG); $result = $this->db->query($sql); - + if ($result) { $obj = $this->db->fetch_object($result); - + return $obj->max; } else { $this->error = "Error " . $this->db->lasterror(); @@ -1098,7 +1144,7 @@ class BookKeeping extends CommonObject return - 1; } } - + /** * Load all informations of accountancy document * @@ -1112,17 +1158,17 @@ class BookKeeping extends CommonObject $sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; $sql .= " WHERE piece_num = " . $piecenum; - + dol_syslog(get_class($this) . "::" . __METHOD__, LOG_DEBUG); $result = $this->db->query($sql); if ($result) { - + while ( $obj = $this->db->fetch_object($result) ) { - + $line = new BookKeepingLine(); - + $line->id = $obj->rowid; - + $line->doc_date = $this->db->jdate($obj->doc_date); $line->doc_type = $obj->doc_type; $line->doc_ref = $obj->doc_ref; @@ -1137,7 +1183,7 @@ class BookKeeping extends CommonObject $line->sens = $obj->sens; $line->code_journal = $obj->code_journal; $line->piece_num = $obj->piece_num; - + $this->linesmvt[] = $line; } } else { @@ -1145,10 +1191,10 @@ class BookKeeping extends CommonObject dol_syslog(get_class($this) . "::" . __METHOD__ . $this->error, LOG_ERR); return - 1; } - + return 1; } - + /** * Export bookkeping * @@ -1161,20 +1207,20 @@ class BookKeeping extends CommonObject $sql .= " numero_compte, label_compte, debit, credit,"; $sql .= " montant, sens, fk_user_author, import_key, code_journal, piece_num"; $sql .= " FROM " . MAIN_DB_PREFIX . $this->table_element; - + dol_syslog(get_class($this) . "::export_bookkeping", LOG_DEBUG); - + $resql = $this->db->query($sql); - + if ($resql) { $this->linesexport = array (); - + $num = $this->db->num_rows($resql); while ( $obj = $this->db->fetch_object($resql) ) { $line = new BookKeepingLine(); - + $line->id = $obj->rowid; - + $line->doc_date = $this->db->jdate($obj->doc_date); $line->doc_type = $obj->doc_type; $line->doc_ref = $obj->doc_ref; @@ -1189,11 +1235,11 @@ class BookKeeping extends CommonObject $line->sens = $obj->sens; $line->code_journal = $obj->code_journal; $line->piece_num = $obj->piece_num; - + $this->linesexport[] = $line; } $this->db->free($resql); - + return $num; } else { $this->error = "Error " . $this->db->lasterror(); @@ -1201,15 +1247,15 @@ class BookKeeping extends CommonObject return - 1; } } - + /** * Description of accounting account * * @param string $account Accounting account - * @return string + * @return string */ function get_compte_desc($account = null) - { + { global $conf; $pcgver = $conf->global->CHARTOFACCOUNTS; @@ -1226,14 +1272,14 @@ class BookKeeping extends CommonObject if ($resql) { $obj = ''; if ($this->db->num_rows($resql)) { - $obj = $this->db->fetch_object($resql); + $obj = $this->db->fetch_object($resql); } - - if(empty($obj->category)){ + + if(empty($obj->category)){ return $obj->label; }else{ return $obj->label.' ('.$obj->category.')'; - + } } else { $this->error = "Error " . $this->db->lasterror(); @@ -1242,7 +1288,7 @@ class BookKeeping extends CommonObject return -1; } } - + } /** diff --git a/htdocs/accountancy/class/html.formventilation.class.php b/htdocs/accountancy/class/html.formventilation.class.php index e3ae592a47f..9294cf7f6a8 100644 --- a/htdocs/accountancy/class/html.formventilation.class.php +++ b/htdocs/accountancy/class/html.formventilation.class.php @@ -58,7 +58,7 @@ class FormVentilation extends Form return Form::selectarray($htmlname, $options, $selectedkey); } - + /** * Return list of accounts with label by chart of accounts * @@ -69,23 +69,23 @@ class FormVentilation extends Form * @param int $select_in $selectid value is a aa.rowid (0 default) or aa.account_number (1) * @param int $select_out set value returned by select 0=rowid (default), 1=account_number * @param int $aabase set accounting_account base class to display empty=all or from 1 to 8 will display only account beginning by this number - * + * * @return string String with HTML select */ function select_account($selectid, $htmlname = 'account', $showempty = 0, $event = array(), $select_in = 0, $select_out = 0, $aabase = '') { global $conf; - + require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; $trunclength = defined('ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT') ? $conf->global->ACCOUNTING_LENGTH_DESCRIPTION_ACCOUNT : 50; - + $sql = "SELECT DISTINCT aa.account_number, aa.label, aa.rowid, aa.fk_pcg_version"; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS; $sql .= " AND aa.active = 1"; $sql .= " ORDER BY aa.account_number"; - + dol_syslog(get_class($this) . "::select_account", LOG_DEBUG); $resql = $this->db->query($sql); @@ -127,7 +127,7 @@ class FormVentilation extends Form $this->db->free($resql); return $out; } - + /** * Return list of accounts with label by class of accounts * @@ -135,18 +135,18 @@ class FormVentilation extends Form * @param string $htmlname Name of field in html form * @param int $showempty Add an empty field * @param array $event Event options - * + * * @return string String with HTML select */ function select_pcgtype($selectid, $htmlname = 'pcg_type', $showempty = 0, $event = array()) { global $conf; - + $sql = "SELECT DISTINCT pcg_type "; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS; $sql .= " ORDER BY pcg_type"; - + dol_syslog(get_class($this) . "::select_pcgtype", LOG_DEBUG); $resql = $this->db->query($sql); @@ -168,7 +168,7 @@ class FormVentilation extends Form $this->db->free($resql); return $out; } - + /** * Return list of accounts with label by sub_class of accounts * @@ -176,18 +176,18 @@ class FormVentilation extends Form * @param string $htmlname Name of field in html form * @param int $showempty Add an empty field * @param array $event Event options - * + * * @return string String with HTML select */ function select_pcgsubtype($selectid, $htmlname = 'pcg_subtype', $showempty = 0, $event = array()) { global $conf; - + $sql = "SELECT DISTINCT pcg_subtype "; $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa"; $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS; $sql .= " ORDER BY pcg_subtype"; - + dol_syslog(get_class($this) . "::select_pcgsubtype", LOG_DEBUG); $resql = $this->db->query($sql); @@ -209,7 +209,7 @@ class FormVentilation extends Form $this->db->free($resql); return $out; } - + /** * Return list of auxilary thirdparty accounts * @@ -217,7 +217,7 @@ class FormVentilation extends Form * @param string $htmlname Name of field in html form * @param int $showempty Add an empty field * @param array $event Event options - * + * * @return string String with HTML select */ function select_auxaccount($selectid, $htmlname = 'account_num_aux', $showempty = 0, $event = array()) { @@ -246,7 +246,7 @@ class FormVentilation extends Form // Auxiliary supplier account $sql = "SELECT DISTINCT code_compta_fournisseur, nom "; $sql .= " FROM ".MAIN_DB_PREFIX."societe"; - $sql .= " ORDER BY code_compta"; + $sql .= " ORDER BY code_compta_fournisseur"; dol_syslog(get_class($this)."::select_auxaccount", LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { @@ -268,7 +268,7 @@ class FormVentilation extends Form return $out; } - + /** * Return HTML combo list of years existing into book keepping * @@ -284,7 +284,7 @@ class FormVentilation extends Form $sql = "SELECT DISTINCT date_format(doc_date,'%Y') as dtyear"; $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping"; - $sql .= " ORDER BY doc_date"; + $sql .= " ORDER BY date_format(doc_date,'%Y')"; dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); $resql = $this->db->query($sql); @@ -304,4 +304,40 @@ class FormVentilation extends Form return $out_array; } } + + /** + * Return HTML combo list of years existing into book keepping + * + * @param string $selected Preselected value + * @param string $htmlname Name of HTML select object + * @param int $useempty Affiche valeur vide dans liste + * @param string $output_format (html/opton (for option html only)/array (to return options arrays + * @return string/array + */ + function selectjournal_accountancy_bookkepping($selected = '', $htmlname = 'journalid', $useempty = 0, $output_format = 'html') + { + $out_array = array(); + + $sql = "SELECT DISTINCT code_journal"; + $sql .= " FROM ".MAIN_DB_PREFIX."accounting_bookkeeping"; + $sql .= " ORDER BY code_journal"; + dol_syslog(get_class($this)."::".__METHOD__, LOG_DEBUG); + $resql = $this->db->query($sql); + + if (!$resql) { + $this->error = "Error ".$this->db->lasterror(); + dol_syslog(get_class($this)."::".__METHOD__.$this->error, LOG_ERR); + return -1; + } + while ($obj = $this->db->fetch_object($resql)) { + $out_array[$obj->code_journal] = $obj->code_journal; + } + $this->db->free($resql); + + if ($output_format == 'html') { + return Form::selectarray($htmlname, $out_array, $selected, $useempty, 0, 0, 'placeholder="aa"'); + } else { + return $out_array; + } + } } diff --git a/htdocs/accountancy/journal/purchasesjournal.php b/htdocs/accountancy/journal/purchasesjournal.php index 5ca1197b3e2..f66293b6185 100644 --- a/htdocs/accountancy/journal/purchasesjournal.php +++ b/htdocs/accountancy/journal/purchasesjournal.php @@ -138,7 +138,7 @@ if ($result) { //Define array for display vat tx $def_tva[$obj->rowid]=price($obj->tva_tx); - $tabfac[$obj->rowid]["date"] = $obj->df; + $tabfac[$obj->rowid]["date"] = $db->jdate($obj->df); $tabfac[$obj->rowid]["ref"] = $obj->ref_supplier . ' (' . $obj->ref . ')'; $tabfac[$obj->rowid]["refsologest"] = $obj->ref; $tabfac[$obj->rowid]["refsuppliersologest"] = $obj->ref_supplier; @@ -193,7 +193,7 @@ if ($action == 'writebookkeeping') { $bookkeeping->fk_doc = $key; $bookkeeping->fk_docdet = $val["fk_facturefourndet"]; $bookkeeping->code_tiers = $tabcompany[$key]['code_fournisseur']; - $bookkeeping->label_compte = utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("Code_tiers"); + $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("Code_tiers"); $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_SUPPLIER; $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt >= 0) ? 'C' : 'D'; @@ -225,7 +225,7 @@ if ($action == 'writebookkeeping') { $bookkeeping->fk_doc = $key; $bookkeeping->fk_docdet = $val["fk_facturefourndet"]; $bookkeeping->code_tiers = ''; - $bookkeeping->label_compte = utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->refsupplier . ' - ' . utf8_decode($accountingaccount->label); + $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $accountingaccount->label; $bookkeeping->numero_compte = $k; $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt < 0) ? 'C' : 'D'; @@ -256,7 +256,7 @@ if ($action == 'writebookkeeping') { $bookkeeping->fk_doc = $key; $bookkeeping->fk_docdet = $val["fk_facturefourndet"]; $bookkeeping->code_tiers = ''; - $bookkeeping->label_compte = utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("VAT"). ' '.$def_tva[$key]; + $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->refsupplier . ' - ' . $langs->trans("VAT"). ' '.$def_tva[$key]; $bookkeeping->numero_compte = $k; $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt < 0) ? 'C' : 'D'; @@ -297,7 +297,7 @@ if ($action == 'export_csv') { $sep = ";"; foreach ( $tabfac as $key => $val ) { - $date = dol_print_date($db->jdate($val["date"]), '%d%m%Y'); + $date = dol_print_date($val["date"], '%d%m%Y'); // Product / Service foreach ( $tabht[$key] as $k => $mt ) { @@ -340,7 +340,7 @@ if ($action == 'export_csv') { print length_accounta(html_entity_decode($k)) . $sep; print ($mt < 0 ? 'D' : 'C') . $sep; print ($mt <= 0 ? price(- $mt) : $mt) . $sep; - print utf8_decode($companystatic->name) . $sep; + print $companystatic->name . $sep; print $val["ref"]; print "\n"; } @@ -356,7 +356,7 @@ if ($action == 'export_csv') { $invoicestatic->type = $val["type"]; $invoicestatic->description = html_entity_decode(dol_trunc($val["description"], 32)); - $date = dol_print_date($db->jdate($val["date"]), 'day'); + $date = dol_print_date($val["date"], 'day'); $companystatic->id = $tabcompany[$key]['id']; $companystatic->name = $tabcompany[$key]['name']; @@ -370,7 +370,7 @@ if ($action == 'export_csv') { print '"' . $date . '"' . $sep; print '"' . $val["ref"] . '"' . $sep; print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; - print '"' . utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $val["refsuppliersologest"] . ' - ' . utf8_decode(dol_trunc($accountingaccount->label, 32)) . '"' . $sep; + print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $val["refsuppliersologest"] . ' - ' . dol_trunc($accountingaccount->label, 32) . '"' . $sep; // print '"' . dol_trunc($accountingaccount->label, 32) . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"'; @@ -384,7 +384,7 @@ if ($action == 'export_csv') { print '"' . $val["ref"] . '"' . $sep; print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; // print '"' . $langs->trans("VAT") . '"' . $sep; - print '"' . utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("VAT") . '"' . $sep; + print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("VAT") . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"'; print "\n"; @@ -396,8 +396,7 @@ if ($action == 'export_csv') { print '"' . $date . '"' . $sep; print '"' . $val["ref"] . '"' . $sep; print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; - // print '"' . utf8_decode($companystatic->name) . '"' . $sep; - print '"' . utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("Code_tiers") . '"' . $sep; + print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $val["refsuppliersologest"] . ' - ' . $langs->trans("Code_tiers") . '"' . $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"'; } @@ -479,7 +478,7 @@ if ($action == 'export_csv') { $invoicestatic->type = $val["type"]; $invoicestatic->description = html_entity_decode(dol_trunc($val["description"], 32)); - $date = dol_print_date($db->jdate($val["date"]), 'day'); + $date = dol_print_date($val["date"], 'day'); // Product / Service foreach ( $tabht[$key] as $k => $mt ) { diff --git a/htdocs/accountancy/journal/sellsjournal.php b/htdocs/accountancy/journal/sellsjournal.php index 5da210ca09a..1f21788bc30 100644 --- a/htdocs/accountancy/journal/sellsjournal.php +++ b/htdocs/accountancy/journal/sellsjournal.php @@ -161,7 +161,7 @@ if ($result) { } // Invoice lines - $tabfac[$obj->rowid]["date"] = $obj->df; + $tabfac[$obj->rowid]["date"] = $db->jdate($obj->df); $tabfac[$obj->rowid]["ref"] = $obj->facnumber; $tabfac[$obj->rowid]["type"] = $obj->type; $tabfac[$obj->rowid]["description"] = $obj->label_compte; @@ -220,7 +220,7 @@ if ($action == 'writebookkeeping') { $bookkeeping->code_tiers = $tabcompany[$key]['code_client']; $bookkeeping->numero_compte = $conf->global->ACCOUNTING_ACCOUNT_CUSTOMER; // $bookkeeping->label_compte = $tabcompany[$key]['name']; - $bookkeeping->label_compte = utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers"); + $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers"); $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt >= 0) ? 'D' : 'C'; $bookkeeping->debit = ($mt >= 0) ? $mt : 0; @@ -250,7 +250,7 @@ if ($action == 'writebookkeeping') { $bookkeeping->fk_docdet = $val["fk_facturedet"]; $bookkeeping->code_tiers = ''; $bookkeeping->numero_compte = $k; - $bookkeeping->label_compte = utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->ref . ' - ' . utf8_decode($accountingaccount->label); + $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $accountingaccount->label; $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt < 0) ? 'D' : 'C'; $bookkeeping->debit = ($mt < 0) ? $mt : 0; @@ -280,7 +280,7 @@ if ($action == 'writebookkeeping') { $bookkeeping->fk_docdet = $val["fk_facturedet"]; $bookkeeping->code_tiers = ''; $bookkeeping->numero_compte = $k; - $bookkeeping->label_compte = utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT").' '.$def_tva[$key]; + $bookkeeping->label_compte = dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT").' '.$def_tva[$key]; $bookkeeping->montant = $mt; $bookkeeping->sens = ($mt < 0) ? 'D' : 'C'; $bookkeeping->debit = ($mt < 0) ? $mt : 0; @@ -324,7 +324,7 @@ if ($action == 'export_csv') { $invoicestatic->id = $key; $invoicestatic->ref = $val["ref"]; - $date = dol_print_date($db->jdate($val["date"]), '%d%m%Y'); + $date = dol_print_date($val["date"], '%d%m%Y'); foreach ( $tabttc[$key] as $k => $mt ) { print $date . $sep; @@ -333,8 +333,7 @@ if ($action == 'export_csv') { print length_accounta(html_entity_decode($k)) . $sep; print ($mt < 0 ? 'C' : 'D') . $sep; print ($mt <= 0 ? price(- $mt) : $mt) . $sep; - print utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . $sep; - // print utf8_decode($companystatic->name) . $sep; + print dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . $sep; print $val["ref"]; print "\n"; } @@ -349,8 +348,7 @@ if ($action == 'export_csv') { print $sep; print ($mt < 0 ? 'D' : 'C') . $sep; print ($mt <= 0 ? price(- $mt) : $mt) . $sep; - print utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->ref . ' - ' . utf8_decode(utf8_decode($accountingaccount_static->label)) . $sep; - // print dol_trunc($accountingaccount_static->label, 32) . $sep; + print dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $accountingaccount_static->label . $sep; print $val["ref"]; print "\n"; } @@ -365,7 +363,7 @@ if ($action == 'export_csv') { print $sep; print ($mt < 0 ? 'D' : 'C') . $sep; print ($mt <= 0 ? price(- $mt) : $mt) . $sep; - print utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . $sep; + print dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . $sep; // print $langs->trans("VAT") . $sep; print $val["ref"]; print "\n"; @@ -382,14 +380,13 @@ if ($action == 'export_csv') { $invoicestatic->id = $key; $invoicestatic->ref = $val["ref"]; - $date = dol_print_date($db->jdate($val["date"]), 'day'); + $date = dol_print_date($val["date"], 'day'); foreach ( $tabttc[$key] as $k => $mt ) { print '"' . $date . '"' . $sep; print '"' . $val["ref"] . '"' . $sep; print '"' . length_accounta(html_entity_decode($k)) . '"' . $sep; - print '"' . utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . '"' . $sep; - // print '"' . utf8_decode($companystatic->name) . '"' . $sep; + print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("Code_tiers") . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"' . $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"'; print "\n"; @@ -404,8 +401,7 @@ if ($action == 'export_csv') { print '"' . $date . '"' . $sep; print '"' . $val["ref"] . '"' . $sep; print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; - print '"' . utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . utf8_decode(dol_trunc($accountingaccount->label, 32)) . '"' . $sep; - // print '"' . dol_trunc($accountingaccount->label, 32) . '"' . $sep; + print '"' . dol_trunc($companystatic->name, 16) . ' - ' . dol_trunc($accountingaccount->label, 32) . '"' . $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"'; print "\n"; @@ -418,8 +414,7 @@ if ($action == 'export_csv') { print '"' . $date . '"' . $sep; print '"' . $val["ref"] . '"' . $sep; print '"' . length_accountg(html_entity_decode($k)) . '"' . $sep; - print '"' . utf8_decode(dol_trunc($companystatic->name, 16)) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . '"' . $sep; - // print '"' . $langs->trans("VAT") . '"' . $sep; + print '"' . dol_trunc($companystatic->name, 16) . ' - ' . $invoicestatic->ref . ' - ' . $langs->trans("VAT") . '"' . $sep; print '"' . ($mt < 0 ? price(- $mt) : '') . '"' . $sep; print '"' . ($mt >= 0 ? price($mt) : '') . '"'; print "\n"; @@ -497,7 +492,7 @@ if ($action == 'export_csv') { $invoicestatic->ref = $val["ref"]; $invoicestatic->type = $val["type"]; - $date = dol_print_date($db->jdate($val["date"]), 'day'); + $date = dol_print_date($val["date"], 'day'); // Third party foreach ( $tabttc[$key] as $k => $mt ) { @@ -527,7 +522,7 @@ if ($action == 'export_csv') { print ""; print ""; // print ""; - print ""; + print ""; print ""; print ""; print ""; diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index 18742ba0ed7..433d5a0178d 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -84,6 +84,11 @@ AccountingCategory=Accounting category NotMatch=Not Set +DeleteMvt=Delete general ledger lines +DelYear=Year to delete +DelJournal=Journal to delete +ConfirmDeleteMvt=This will delete all line of of the general ledger for year and/or from a specifics journal + DelBookKeeping=Delete the records of the general ledger DescSellsJournal=Sales journal @@ -160,3 +165,4 @@ Formula=Formula ## Error ErrorNoAccountingCategoryForThisCountry=No accounting category are available for this country ExportNotSupported=The export format setuped is not supported into this page +BookeppingLineAlreayExists=Lines already existing into bookeeping From 76a113257e965d154da458444ead0a4c5c3490ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Wed, 29 Jun 2016 16:16:56 +0200 Subject: [PATCH 10/31] Update index.php --- htdocs/comm/index.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/comm/index.php b/htdocs/comm/index.php index 93f9b243624..eef29d2edc3 100644 --- a/htdocs/comm/index.php +++ b/htdocs/comm/index.php @@ -341,7 +341,7 @@ if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->commande $companystatic->code_client = $obj->code_client; $companystatic->code_fournisseur = $obj->code_fournisseur; $companystatic->canvas=$obj->canvas; - print $companystatic->getNomUrl(1,'customer',16); + print $companystatic->getNomUrl(1,'supplier',16); print ''; print ''; $i++; @@ -647,7 +647,7 @@ if (! empty($conf->propal->enabled) && $user->rights->propal->lire) $companystatic->code_client = $obj->code_client; $companystatic->code_fournisseur = $obj->code_fournisseur; $companystatic->canvas=$obj->canvas; - print $companystatic->getNomUrl(1, 'company', 44); + print $companystatic->getNomUrl(1, 'customer', 44); print ''; print ''."\n"; @@ -746,7 +746,7 @@ if (! empty($conf->commande->enabled) && $user->rights->commande->lire) $companystatic->code_client = $obj->code_client; $companystatic->code_fournisseur = $obj->code_fournisseur; $companystatic->canvas=$obj->canvas; - print $companystatic->getNomUrl(1, 'company', 44); + print $companystatic->getNomUrl(1, 'customer', 44); print ''; print ''."\n"; From a55a166df3e3069edaa0bf4afc3969ba185a8a14 Mon Sep 17 00:00:00 2001 From: Alexis Algoud Date: Wed, 29 Jun 2016 16:30:47 +0200 Subject: [PATCH 11/31] FIX old method add have to return create method result for backward compatibility --- htdocs/comm/action/class/actioncomm.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index 6b77e2414da..e759e93a635 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -406,7 +406,7 @@ class ActionComm extends CommonObject */ public function add(User $user, $notrigger = 0) { - $this->create($user, $notrigger); + return $this->create($user, $notrigger); } /** From ea3e851ec05b101817ff0c9d1a11c51bbe491864 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Wed, 29 Jun 2016 16:54:37 +0200 Subject: [PATCH 12/31] Fix stuff in accoutancy --- htdocs/accountancy/admin/categories.php | 129 +++---- .../class/accountancycategory.class.php | 342 +++++++++--------- htdocs/accountancy/report/result.php | 73 ++-- htdocs/core/modules/modAccounting.class.php | 10 +- 4 files changed, 290 insertions(+), 264 deletions(-) diff --git a/htdocs/accountancy/admin/categories.php b/htdocs/accountancy/admin/categories.php index b1836836e84..e1a0e3fe052 100644 --- a/htdocs/accountancy/admin/categories.php +++ b/htdocs/accountancy/admin/categories.php @@ -16,9 +16,9 @@ */ /** - * \file htdocs/accountancy/admin/categories.php - * \ingroup Advanced accountancy - * \brief Page to assign mass categories to accounts + * \file htdocs/accountancy/admin/categories.php + * \ingroup Advanced accountancy + * \brief Page to assign mass categories to accounts */ require '../../main.inc.php'; @@ -36,11 +36,11 @@ $langs->load("accountancy"); $mesg = ''; $action = GETPOST('action'); $cat_id = GETPOST('account_category'); -$selectcpt = GETPOST('cpt_bk'); +$selectcpt = GETPOST('cpt_bk', 'array'); $cpt_id = GETPOST('cptid'); -if($cat_id == 0){ - $cat_id = null; +if ($cat_id == 0) { + $cat_id = null; } $id = GETPOST('id', 'int'); @@ -54,31 +54,30 @@ if (! $user->admin) $AccCat = new AccountancyCategory($db); // si ajout de comptes -if(!empty($selectcpt)){ - $cpts = array(); - $i = 0; - foreach ($selectcpt as $selectedOption){ - $cpts[$i] = "'".$selectedOption."'"; - $i++; +if (! empty($selectcpt)) { + $cpts = array (); + foreach ( $selectcpt as $selectedOption ) { + if (! array_key_exists($selectedOption, $cpts)) + $cpts[$selectedOption] = "'" . $selectedOption . "'"; } - - if($AccCat->updateAccAcc($cat_id, $cpts)){ + + $return= $AccCat->updateAccAcc($cat_id, $cpts); + + if ($return<0) { + setEventMessages($langs->trans('errors'), $AccCat->errors, 'errors'); + } else { setEventMessages($langs->trans('Saved'), null, 'mesgs'); - }else{ - setEventMessages($langs->trans('errors'), null, 'errors'); } - - } if ($action == 'delete') { - if($cpt_id){ - if($AccCat->deleteCptCat($cpt_id)){ + if ($cpt_id) { + if ($AccCat->deleteCptCat($cpt_id)) { setEventMessages($langs->trans('Deleted'), null, 'mesgs'); - }else{ + } else { setEventMessages($langs->trans('errors'), null, 'errors'); } } -} +} /* * View @@ -88,65 +87,69 @@ llxheader('', $langs->trans('AccountAccounting')); $formaccounting = new FormAccounting($db); $form = new Form($db); - print load_fiche_titre($langs->trans('Categories')); +print load_fiche_titre($langs->trans('Categories')); - print '' . "\n"; - print ''; - print ''; +print '' . "\n"; +print ''; +print ''; - dol_fiche_head(); +dol_fiche_head(); - print '
'; print $formventilation->select_account($line->numero_compte, 'account_number', 0, array (), 1, 1, ''); print '' . price($line->credit) . '' . price($line->montant) . '' . $line->sens . ''; print ''; print img_edit(); @@ -384,23 +384,21 @@ if ($action == 'create') { print ''; print img_delete(); print ''; - + print '
'; print $formventilation->select_account($account_number, 'account_number', 0, array (), 1, 1, ''); print '" . $invoicestatic->getNomUrl(1) . "" . length_accountg($k) . "" . $accountingaccount->label . "" . $companystatic->getNomUrl(0, 'customer', 16) . ' - ' . $invoicestatic->ref . ' - ' . utf8_decode(utf8_decode($accountingaccount->label)) . "" . $companystatic->getNomUrl(0, 'customer', 16) . ' - ' . $invoicestatic->ref . ' - ' . $accountingaccount->label . "" . ($mt < 0 ? price(- $mt) : '') . "" . ($mt >= 0 ? price($mt) : '') . "
'.price($obj->total_ttc).'
'; print dol_print_date($db->jdate($obj->dp),'day').''; print dol_print_date($db->jdate($obj->dp),'day').'
'; - // Category - print ''; - print ''; +print '
' . $langs->trans("AccountingCategory") . ''; - $formaccounting->select_accounting_category($cat_id, 'account_category', 1); - print ''; - print '
'; +// Category +print ''; +print ''; - - if(!empty($cat_id)){ - $obj = $AccCat->getCptBK($cat_id); - print ''; - print ''; +if (! empty($cat_id)) { + $return = $AccCat->getCptBK($cat_id); + if ($return < 0) { + setEventMessages(null, $AccCat->errors, 'errors'); } - - print '
' . $langs->trans("AccountingCategory") . ''; +$formaccounting->select_accounting_category($cat_id, 'account_category', 1); +print ''; +print '
' . $langs->trans("AddCompteFromBK") . ''; - if(!empty($obj)){ - print ' - '; - } - print '
'; + print '' . $langs->trans("AddCompteFromBK") . ''; + print ''; + if (is_array($AccCat->lines_cptbk) && count($AccCat->lines_cptbk) > 0) { + print ' - '; + } + print ''; +} - dol_fiche_end(); +print ''; - print '
'; +dol_fiche_end(); + +print ''; if ($action == 'display' || $action == 'delete') { print ''; - print ''; + print ''; - if(!empty($cat_id)){ - $obj = $AccCat->display($cat_id); - $j=1; - if(!empty($obj)){ - foreach ( $obj as $cpt ) { + if (! empty($cat_id)) { + $return = $AccCat->display($cat_id); + if ($return < 0) { + setEventMessages(null, $AccCat->errors, 'errors'); + } + $j = 1; + if (is_array($AccCat->lines_display) && count($AccCat->lines_display) > 0) { + foreach ( $AccCat->lines_display as $cpt ) { $var = ! $var; - print ''; + print ''; print ''; print ''; - print $form->formconfirm($_SERVER["PHP_SELF"]."?account_category=$cat_id&cptid=".$cpt->rowid, $langs->trans("DeleteCptCategory"), $langs->trans("ConfirmDeleteCptCategory"), "delete", '', 0, "action-delete".$j); - print ''; + print $form->formconfirm($_SERVER["PHP_SELF"] . "?account_category=$cat_id&cptid=" . $cpt->rowid, $langs->trans("DeleteCptCategory"), $langs->trans("ConfirmDeleteCptCategory"), "delete", '', 0, "action-delete" . $j); + print ''; print "\n"; - $j++; + $j ++; } - } + } } print "
'.$langs->trans("Numerocompte").''.$langs->trans("Description").'Action
' . $langs->trans("Numerocompte") . '' . $langs->trans("Description") . 'Action
' . length_accountg($cpt->account_number) . '' . $cpt->label . '
"; diff --git a/htdocs/accountancy/class/accountancycategory.class.php b/htdocs/accountancy/class/accountancycategory.class.php index ef880aa8113..43b9816c5ed 100644 --- a/htdocs/accountancy/class/accountancycategory.class.php +++ b/htdocs/accountancy/class/accountancycategory.class.php @@ -17,9 +17,9 @@ */ /** - * \file htdocs/accountancy/class/accountancycategory.class.php - * \ingroup Advanced accountancy - * \brief File of class to manage categories of an accounting category_type + * \file htdocs/accountancy/class/accountancycategory.class.php + * \ingroup Advanced accountancy + * \brief File of class to manage categories of an accounting category_type */ // Class @@ -32,18 +32,20 @@ class AccountancyCategory { private $db; public $error; - public $errors = array(); - //public $element='accounting_category'; - //public $table_element='c_accounting_category'; + public $errors = array (); + public $element = 'accounting_category'; + public $table_element = 'c_accounting_category'; public $id; + public $lines_cptbk; + public $lines_display; + public $sdc; /** - * Constructor + * Constructor * - * @param DoliDB $db Database handler + * @param DoliDB $db Database handler */ - public function __construct($db) - { + public function __construct($db) { $this->db = $db; return 1; @@ -52,122 +54,136 @@ class AccountancyCategory /** * Function to select all accounting accounts from an accounting category * - * @param int $id Id + * @param int $id Id * * @return int <0 if KO, 0 if not found, >0 if OK - */ - public function display($id) - { + */ + public function display($id) { $sql = "SELECT t.rowid, t.account_number, t.label"; - $sql.= " FROM " . MAIN_DB_PREFIX . "accounting_account as t"; - $sql.= " WHERE t.fk_accounting_category = " . $id; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as t"; + $sql .= " WHERE t.fk_accounting_category = " . $id; + + $this->lines_display = array (); dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - $i = 0; - $obj = ''; $num = $this->db->num_rows($resql); if ($num) { - while ( $i < $num ) { - $obj[$i] = $this->db->fetch_object($resql); - $i ++; + while ( $obj = $this->db->fetch_object($resql) ) { + $this->lines_display[] = $obj; } } - return $obj; + return $num; } else { $this->error = "Error " . $this->db->lasterror(); - dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR); + $this->errors[] = $this->error; + dol_syslog(__METHOD__ . " " . implode(',' . $this->errors), LOG_ERR); - return -1; + return - 1; } } /** * Function to select accountiing category of an accounting account present in chart of accounts * - * @param int $id Id category + * @param int $id Id category * * @return int <0 if KO, 0 if not found, >0 if OK */ - public function getCptBK($id) - { + public function getCptBK($id) { global $conf; $sql = "SELECT t.numero_compte, t.label_compte, t.doc_ref"; - $sql.= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as t"; - $sql.= " WHERE t.numero_compte NOT IN ("; - $sql.= " SELECT t.account_number"; - $sql.= " FROM " . MAIN_DB_PREFIX . "accounting_account as t"; - $sql.= " WHERE t.fk_accounting_category = " . $id .")"; - $sql.= " AND t.numero_compte IN ("; - $sql.= " SELECT DISTINCT aa.account_number"; - $sql.= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa"; - $sql.= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; - $sql.= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS; - $sql.= " AND aa.active = 1)"; - $sql.= " GROUP BY t.numero_compte"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as t"; + $sql .= " WHERE t.numero_compte NOT IN ("; + $sql .= " SELECT t.account_number"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as t"; + $sql .= " WHERE t.fk_accounting_category = " . $id . ")"; + $sql .= " AND t.numero_compte IN ("; + $sql .= " SELECT DISTINCT aa.account_number"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa"; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; + $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS; + $sql .= " AND aa.active = 1)"; + $sql .= " GROUP BY t.numero_compte, t.label_compte, t.doc_ref"; + $sql .= " ORDER BY t.numero_compte"; - dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG); + $this->lines_CptBk = array (); + + dol_syslog(__METHOD__, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { - $i = 0; - $obj = ''; $num = $this->db->num_rows($resql); if ($num) { - while ( $i < $num ) { - $obj[$i] = $this->db->fetch_object($resql); - $i ++; + while ( $obj = $this->db->fetch_object($resql) ) { + $this->lines_cptbk[] = $obj; } } - return $obj; + return $num; } else { $this->error = "Error " . $this->db->lasterror(); - dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR); + $this->errors[] = $this->error; + dol_syslog(__METHOD__ . " " . implode(',' . $this->errors), LOG_ERR); - return -1; + return - 1; } } - + /** * Function to add an accounting account in an accounting category * - * @param int $id_cat Id category - * @param array $cpts list of accounts array + * @param int $id_cat Id category + * @param array $cpts list of accounts array * * @return int <0 if KO, >0 if OK */ - public function updateAccAcc($id_cat, $cpts = array()) - { + public function updateAccAcc($id_cat, $cpts = array()) { global $conf; $error = 0; - $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account as aa"; - $sql.= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; - $sql.= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS; - $sql.= " AND aa.active = 1"; - $sql.= " SET fk_accounting_category=" . $id_cat; - $sql.= " WHERE aa.account_number IN (" . join(',',$cpts) .")"; - $this->db->begin(); + require_once DOL_DOCUMENT_ROOT.'/core/lib/accounting.lib.php'; - dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG); + $sql = "SELECT aa.rowid,aa.account_number "; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as aa"; + $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "accounting_system as asy ON aa.fk_pcg_version = asy.pcg_version"; + $sql .= " AND asy.rowid = " . $conf->global->CHARTOFACCOUNTS; + $sql .= " AND aa.active = 1"; + + dol_syslog(__METHOD__, LOG_DEBUG); $resql = $this->db->query($sql); if (! $resql) { $error ++; $this->errors[] = "Error " . $this->db->lasterror(); + return -1; + } + + $this->db->begin(); + while ( $obj = $this->db->fetch_object($resql)) { + if (array_key_exists(length_accountg($obj->account_number), $cpts)) { + $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account"; + $sql .= " SET fk_accounting_category=" . $id_cat; + $sql .= " WHERE rowid=".$obj->rowid; + dol_syslog(__METHOD__, LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { + $error ++; + $this->errors[] = "Error " . $this->db->lasterror(); + } + } } // Commit or rollback if ($error) { - foreach ($this->errors as $errmsg) { + foreach ( $this->errors as $errmsg ) { dol_syslog(__METHOD__ . " " . $errmsg, LOG_ERR); - $this->error.=($this->error ? ', ' . $errmsg : $errmsg); + $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); } $this->db->rollback(); - return -1 * $error; + return - 1 * $error; } else { $this->db->commit(); @@ -178,17 +194,16 @@ class AccountancyCategory /** * Function to delete an accounting account from an accounting category * - * @param int $cpt_id Id of accounting account + * @param int $cpt_id Id of accounting account * * @return int <0 if KO, >0 if OK */ - public function deleteCptCat($cpt_id) - { + public function deleteCptCat($cpt_id) { $error = 0; $sql = "UPDATE " . MAIN_DB_PREFIX . "accounting_account as aa"; - $sql.= " SET fk_accounting_category= 0"; - $sql.= " WHERE aa.rowid= " . $cpt_id; + $sql .= " SET fk_accounting_category= 0"; + $sql .= " WHERE aa.rowid= " . $cpt_id; $this->db->begin(); dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG); @@ -200,13 +215,13 @@ class AccountancyCategory // Commit or rollback if ($error) { - foreach ($this->errors as $errmsg) { + foreach ( $this->errors as $errmsg ) { dol_syslog(__METHOD__ . " " . $errmsg, LOG_ERR); - $this->error.=($this->error ? ', ' . $errmsg : $errmsg); + $this->error .= ($this->error ? ', ' . $errmsg : $errmsg); } $this->db->rollback(); - return -1 * $error; + return - 1 * $error; } else { $this->db->commit(); @@ -217,57 +232,51 @@ class AccountancyCategory /** * Function to know all category from accounting account * - * @return array Result in table + * @return array Result in table */ - public function getCatsCpts() - { + public function getCatsCpts() { global $mysoc; $sql = ""; - if (empty($mysoc->country_id) && empty($mysoc->country_code)) - { - dol_print_error('','Call to select_accounting_account with mysoc country not yet defined'); - exit; - } + if (empty($mysoc->country_id) && empty($mysoc->country_code)) { + dol_print_error('', 'Call to select_accounting_account with mysoc country not yet defined'); + exit(); + } - if (! empty($mysoc->country_id)) - { - $sql = "SELECT t.rowid, t.account_number, t.label as name_cpt, cat.code, cat.position, cat.label as name_cat, cat.sens "; - $sql.= " FROM " . MAIN_DB_PREFIX . "accounting_account as t, ".MAIN_DB_PREFIX."c_accounting_category as cat"; - $sql.= " WHERE t.fk_accounting_category IN ( SELECT c.rowid "; - $sql.= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c"; - $sql.= " WHERE c.active = 1"; - $sql.= " AND c.fk_country = ".$mysoc->country_id.")"; - $sql.= " AND cat.rowid = t.fk_accounting_category"; - $sql.= " ORDER BY cat.position ASC"; - } - else - { - $sql = "SELECT c.rowid, c.code, c.label, c.category_type "; - $sql.= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c, ".MAIN_DB_PREFIX."c_country as co"; - $sql.= " WHERE c.active = 1 AND c.fk_country = co.rowid"; - $sql.= " AND co.code = '".$mysoc->country_code."'"; - $sql.= " ORDER BY c.position ASC"; - } - - $resql = $this->db->query($sql); + if (! empty($mysoc->country_id)) { + $sql = "SELECT t.rowid, t.account_number, t.label as name_cpt, cat.code, cat.position, cat.label as name_cat, cat.sens "; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_account as t, " . MAIN_DB_PREFIX . "c_accounting_category as cat"; + $sql .= " WHERE t.fk_accounting_category IN ( SELECT c.rowid "; + $sql .= " FROM " . MAIN_DB_PREFIX . "c_accounting_category as c"; + $sql .= " WHERE c.active = 1"; + $sql .= " AND c.fk_country = " . $mysoc->country_id . ")"; + $sql .= " AND cat.rowid = t.fk_accounting_category"; + $sql .= " ORDER BY cat.position ASC"; + } else { + $sql = "SELECT c.rowid, c.code, c.label, c.category_type "; + $sql .= " FROM " . MAIN_DB_PREFIX . "c_accounting_category as c, " . MAIN_DB_PREFIX . "c_country as co"; + $sql .= " WHERE c.active = 1 AND c.fk_country = co.rowid"; + $sql .= " AND co.code = '" . $mysoc->country_code . "'"; + $sql .= " ORDER BY c.position ASC"; + } + + $resql = $this->db->query($sql); if ($resql) { $i = 0; $obj = ''; $num = $this->db->num_rows($resql); - $data = array(); + $data = array (); if ($num) { - while ( $i < $num ) { - $obj = $this->db->fetch_object($resql); + while ( $obj = $this->db->fetch_object($resql) ) { $name_cat = $obj->name_cat; - $data[$name_cat][$i] = array( - 'id' => $obj->rowid, - 'code' => $obj->code, - 'position' => $obj->position, - 'account_number' => $obj->account_number, - 'name_cpt' => $obj->name_cpt, - 'sens' => $obj->sens, - ); + $data[$name_cat][$i] = array ( + 'id' => $obj->rowid, + 'code' => $obj->code, + 'position' => $obj->position, + 'account_number' => $obj->account_number, + 'name_cpt' => $obj->name_cpt, + 'sens' => $obj->sens + ); $i ++; } } @@ -276,29 +285,28 @@ class AccountancyCategory $this->error = "Error " . $this->db->lasterror(); dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR); - return -1; + return - 1; } - } + } /** * Function to show result of an accounting account from the general ledger with a sens and a period - * - * @param int $cpt Id accounting account - * @param string $month Specifig month - Can be empty - * @param string $year Specific year - * @param int $sens Sens of the account 0: credit - debit 1: debit - credit * - * @return array Result in table + * @param int $cpt Id accounting account + * @param string $month Specifig month - Can be empty + * @param string $year Specific year + * @param int $sens Sens of the account 0: credit - debit 1: debit - credit + * + * @return array Result in table */ - public function getResult($cpt, $month, $year, $sens) - { - $sql = "SELECT SUM(t.debit) as debit, SUM(t.credit) as credit"; - $sql.= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as t"; - $sql.= " WHERE t.numero_compte = " . $cpt; - $sql.= " AND YEAR(t.doc_date) = " . $year; + public function getResult($cpt, $month, $year, $sens) { + $sql = "SELECT SUM(t.debit) as debit, SUM(t.credit) as credit"; + $sql .= " FROM " . MAIN_DB_PREFIX . "accounting_bookkeeping as t"; + $sql .= " WHERE t.numero_compte = '" . $cpt."'"; + $sql .= " AND YEAR(t.doc_date) = " . $year; - if(! empty($month)){ - $sql.= " AND MONTH(t.doc_date) = " . $month; + if (! empty($month)) { + $sql .= " AND MONTH(t.doc_date) = " . $month; } dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG); @@ -306,81 +314,77 @@ class AccountancyCategory if ($resql) { $num = $this->db->num_rows($resql); - $sdc = 0; + $this->sdc = 0; if ($num) { $obj = $this->db->fetch_object($resql); - if($sens == 1){ - $sdc = $obj->debit - $obj->credit; - }else{ - $sdc = $obj->credit - $obj->debit; + if ($sens == 1) { + $this->sdc = $obj->debit - $obj->credit; + } else { + $this->sdc = $obj->credit - $obj->debit; } } - return $sdc; + return $num; } else { $this->error = "Error " . $this->db->lasterror(); dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR); - return -1; + return - 1; } } /** * Function to call category from a specific country * - * @return array Result in table + * @return array Result in table */ - public function getCatsCal() - { - global $db,$langs,$user,$mysoc; + public function getCatsCal() { + global $db, $langs, $user, $mysoc; - if (empty($mysoc->country_id) && empty($mysoc->country_code)) - { - dol_print_error('','Call to select_accounting_account with mysoc country not yet defined'); - exit; - } + if (empty($mysoc->country_id) && empty($mysoc->country_code)) { + dol_print_error('', 'Call to select_accounting_account with mysoc country not yet defined'); + exit(); + } - if (! empty($mysoc->country_id)) - { - $sql = "SELECT c.rowid, c.code, c.label, c.formula, c.position"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c"; - $sql.= " WHERE c.active = 1 AND c.category_type = 1 "; - $sql.= " AND c.fk_country = ".$mysoc->country_id; - $sql.= " ORDER BY c.position ASC"; - } - else - { - $sql = "SELECT c.rowid, c.code, c.label, c.formula, c.position"; - $sql.= " FROM ".MAIN_DB_PREFIX."c_accounting_category as c, ".MAIN_DB_PREFIX."c_country as co"; - $sql.= " WHERE c.active = 1 AND c.category_type = 1 AND c.fk_country = co.rowid"; - $sql.= " AND co.code = '".$mysoc->country_code."'"; - $sql.= " ORDER BY c.position ASC"; - } + if (! empty($mysoc->country_id)) { + $sql = "SELECT c.rowid, c.code, c.label, c.formula, c.position"; + $sql .= " FROM " . MAIN_DB_PREFIX . "c_accounting_category as c"; + $sql .= " WHERE c.active = 1 AND c.category_type = 1 "; + $sql .= " AND c.fk_country = " . $mysoc->country_id; + $sql .= " ORDER BY c.position ASC"; + } else { + $sql = "SELECT c.rowid, c.code, c.label, c.formula, c.position"; + $sql .= " FROM " . MAIN_DB_PREFIX . "c_accounting_category as c, " . MAIN_DB_PREFIX . "c_country as co"; + $sql .= " WHERE c.active = 1 AND c.category_type = 1 AND c.fk_country = co.rowid"; + $sql .= " AND co.code = '" . $mysoc->country_code . "'"; + $sql .= " ORDER BY c.position ASC"; + } - dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG); + dol_syslog(__METHOD__ . " sql=" . $sql, LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $i = 0; $obj = ''; $num = $this->db->num_rows($resql); - $data = array(); + $data = array (); if ($num) { while ( $i < $num ) { $obj = $this->db->fetch_object($resql); $position = $obj->position; - $data[$position] = array( - 'code' => $obj->code, - 'label' => $obj->label, - 'formula' => $obj->formula - ); + $data[$position] = array ( + 'code' => $obj->code, + 'label' => $obj->label, + 'formula' => $obj->formula + ); $i ++; } } return $data; } else { $this->error = "Error " . $this->db->lasterror(); - dol_syslog(__METHOD__ . " " . $this->error, LOG_ERR); + $this->errors[] = $this->error; + dol_syslog(__METHOD__ . " " . implode(',' . $this->errors), LOG_ERR); - return -1; + return - 1; } } } diff --git a/htdocs/accountancy/report/result.php b/htdocs/accountancy/report/result.php index 72a4d6e96b2..c9c1a13fd14 100644 --- a/htdocs/accountancy/report/result.php +++ b/htdocs/accountancy/report/result.php @@ -53,7 +53,7 @@ if ($year == 0) { } if($cat_id == 0){ - $cat_id = null; + $cat_id = null; } // Security check @@ -76,31 +76,31 @@ $textprevyear = '' . img_next() . ''; print load_fiche_titre($langs->trans('ReportInOut') . " " . $textprevyear . " " . $langs->trans("Year") . " " . $year_start . " " . $textnextyear); - + print ''; - -$months = array( $langs->trans("JanuaryMin"), - $langs->trans("FebruaryMin"), - $langs->trans("MarchMin"), - $langs->trans("AprilMin"), - $langs->trans("MayMin"), - $langs->trans("JuneMin"), - $langs->trans("JulyMin"), - $langs->trans("AugustMin"), - $langs->trans("SeptemberMin"), - $langs->trans("OctoberMin"), - $langs->trans("NovemberMin"), + +$months = array( $langs->trans("JanuaryMin"), + $langs->trans("FebruaryMin"), + $langs->trans("MarchMin"), + $langs->trans("AprilMin"), + $langs->trans("MayMin"), + $langs->trans("JuneMin"), + $langs->trans("JulyMin"), + $langs->trans("AugustMin"), + $langs->trans("SeptemberMin"), + $langs->trans("OctoberMin"), + $langs->trans("NovemberMin"), $langs->trans("DecemberMin"), ); print ''; print ''; -print ''; +print ''; print ''; foreach($months as $k => $v){ print ''; } -print ''; +print ''; $cats = $AccCat->getCatsCpts(); $catsCalcule = $AccCat->getCatsCal(); @@ -123,22 +123,41 @@ if(!empty($cats)) $position = $cpt['position']; $code = $cpt['code']; - $resultNP = $AccCat->getResult($cpt['account_number'], 0, $year_current -1, $cpt['dc']); - $resultN = $AccCat->getResult($cpt['account_number'], 0, $year_current, $cpt['dc']); + $return = $AccCat->getResult($cpt['account_number'], 0, $year_current -1, $cpt['dc']); + if ($return < 0) { + setEventMessages(null, $AccCat->errors, 'errors'); + $resultNP=0; + } else { + $resultNP=$AccCat->sdc; + } + + $return = $AccCat->getResult($cpt['account_number'], 0, $year_current, $cpt['dc']); + if ($return < 0) { + setEventMessages(null, $AccCat->errors, 'errors'); + $resultN=0; + } else { + $resultN=$AccCat->sdc; + } $sommes[$code]['NP'] += $resultNP; - $sommes[$code]['N'] += $resultN; + $sommes[$code]['N'] += $resultN; print ''; print ''; print ''; print ''; print ''; - + foreach($months as $k => $v){ - $resultM = $AccCat->getResult($cpt['account_number'], $k+1, $year_current, $cpt['dc']); + $return = $AccCat->getResult($cpt['account_number'], $k+1, $year_current, $cpt['dc']); + if ($return < 0) { + setEventMessages(null, $AccCat->errors, 'errors'); + $resultM=0; + } else { + $resultM=$AccCat->sdc; + } $sommes[$code]['M'][$k] += $resultM; print ''; } - + print "\n"; } @@ -168,9 +187,9 @@ if(!empty($cats)) } $result = strtr($formula, $vars); eval( '$result = (' . $result . ');' ); - print ''; + print ''; $sommes[$code]['N'] += $result; - + // Detail by month foreach($months as $k => $v){ foreach($sommes as $code => $det){ @@ -181,14 +200,14 @@ if(!empty($cats)) print ''; $sommes[$code]['M'][$k] += $result; } - + //print ''; print "\n"; unset($catsCalcule[$p]); // j'élimine la catégorie calculée après affichage } $j++; } - + // Others calculed category foreach($catsCalcule as $p => $catc) { @@ -215,7 +234,7 @@ if(!empty($cats)) } $result = strtr($formula, $vars); eval( '$result = (' . $result . ');' ); - print ''; + print ''; $sommes[$code]['N'] += $result; // Detail by month diff --git a/htdocs/core/modules/modAccounting.class.php b/htdocs/core/modules/modAccounting.class.php index 03b450aa275..af51e01c576 100644 --- a/htdocs/core/modules/modAccounting.class.php +++ b/htdocs/core/modules/modAccounting.class.php @@ -71,7 +71,7 @@ class modAccounting extends DolibarrModules $this->requiredby = array(); // List of modules id to disable if this one is disabled $this->conflictwith = array("modComptabilite"); // List of modules are in conflict with this module $this->phpmin = array(5, 3); // Minimum version of PHP required by module - $this->need_dolibarr_version = array(3, 7); // Minimum version of Dolibarr required by module + $this->need_dolibarr_version = array(3, 9); // Minimum version of Dolibarr required by module $this->langfiles = array("accountancy"); // Constants @@ -179,7 +179,7 @@ class modAccounting extends DolibarrModules $this->const[18] = array ( "ACCOUNTING_EXPORT_GLOBAL_ACCOUNT", "yesno", - "1" + "1" ); $this->const[19] = array ( "ACCOUNTING_EXPORT_LABEL", @@ -189,12 +189,12 @@ class modAccounting extends DolibarrModules $this->const[20] = array ( "ACCOUNTING_EXPORT_AMOUNT", "yesno", - "1" + "1" ); $this->const[21] = array ( "ACCOUNTING_EXPORT_DEVISE", "yesno", - "1" + "1" ); */ $this->const[22] = array( @@ -270,7 +270,7 @@ class modAccounting extends DolibarrModules $this->rights[$r][4] = 'fiscalyear'; $this->rights[$r][5] = ''; $r++; - + $this->rights[$r][0] = 50440; $this->rights[$r][1] = 'Manage chart of accounts'; $this->rights[$r][2] = 'r'; From 34fddbf3bcc33a764f606228a47994b25b522982 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Wed, 29 Jun 2016 17:30:47 +0200 Subject: [PATCH 13/31] addd export cogilog --- .../class/accountancyexport.class.php | 36 +++++++++++++++++++ htdocs/langs/en_US/accountancy.lang | 1 + 2 files changed, 37 insertions(+) diff --git a/htdocs/accountancy/class/accountancyexport.class.php b/htdocs/accountancy/class/accountancyexport.class.php index c7920577adc..04f66a47026 100644 --- a/htdocs/accountancy/class/accountancyexport.class.php +++ b/htdocs/accountancy/class/accountancyexport.class.php @@ -43,6 +43,7 @@ class AccountancyExport public static $EXPORT_TYPE_CIEL = 5; public static $EXPORT_TYPE_QUADRATUS = 6; public static $EXPORT_TYPE_EBP = 7; + public static $EXPORT_TYPE_COGILOG = 8; /** * @@ -91,6 +92,7 @@ class AccountancyExport self::$EXPORT_TYPE_CIEL => $langs->trans('Modelcsv_ciel'), self::$EXPORT_TYPE_QUADRATUS => $langs->trans('Modelcsv_quadratus'), self::$EXPORT_TYPE_EBP => $langs->trans('Modelcsv_ebp'), + self::$EXPORT_TYPE_COGILOG => $langs->trans('Modelcsv_cogilog'), ); } @@ -137,6 +139,9 @@ class AccountancyExport case self::$EXPORT_TYPE_EBP : $this->exportEbp($TData); break; + case self::$EXPORT_TYPE_COGILOG : + $this->exportCogilog($TData); + break; default : $this->errors[] = $langs->trans('accountancy_error_modelnotfound'); break; @@ -188,6 +193,37 @@ class AccountancyExport } } + /** + * Export format : COGILOG + * + * @param array $objectLines data + * + * @return void + */ + public function exportCogilog($objectLines) { + foreach ( $objectLines as $line ) { + $date = dol_print_date($line->doc_date, '%d%m%Y'); + + print $line->code_journal . $this->separator; + print $date . $this->separator; + print $line->piece_num . $this->separator; + print length_accountg($line->numero_compte) . $this->separator; + print '' . $this->separator; + print $line->label_compte . $this->separator; + print $date . $this->separator; + if ($line->sens=='D') { + print price($line->montant) . $this->separator; + print '' . $this->separator; + }elseif ($line->sens=='C') { + print '' . $this->separator; + print price($line->montant) . $this->separator; + } + print $line->doc_ref . $this->separator; + print $line->label_compte . $this->separator; + print $this->end_line; + } + } + /** * Export format : COALA * diff --git a/htdocs/langs/en_US/accountancy.lang b/htdocs/langs/en_US/accountancy.lang index 433d5a0178d..9a12afd3953 100644 --- a/htdocs/langs/en_US/accountancy.lang +++ b/htdocs/langs/en_US/accountancy.lang @@ -147,6 +147,7 @@ Modelcsv_bob50=Export towards Sage BOB 50 Modelcsv_ciel=Export towards Sage Ciel Compta or Compta Evolution Modelcsv_quadratus=Export towards Quadratus QuadraCompta Modelcsv_ebp=Export towards EBP +Modelcsv_cogilog=Export towards Cogilog ## Tools - Init accounting account on product / service InitAccountancy=Init accountancy From e4a2b5abb372eeb43a7d46d507344fdd6cea7a5f Mon Sep 17 00:00:00 2001 From: fmarcet Date: Thu, 30 Jun 2016 11:27:29 +0200 Subject: [PATCH 14/31] Fix: Incorrect document link on supplier invoices's list --- htdocs/core/class/html.formfile.class.php | 4 +--- htdocs/fourn/facture/list.php | 3 ++- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 48dc7a3ebf2..3faedf4b601 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -6,6 +6,7 @@ * Copyright (C) 2013 Cédric Salvador * Copyright (C) 2014 Marcos García * Copyright (C) 2015 Bahfir Abbes + * Copyright (C) 2016 Ferran Marcet * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -716,9 +717,6 @@ class FormFile if ($modulepart == 'export') { $relativepath = $file["name"]; } - if ($modulepart == 'facture_fournisseur' || $modulepart == 'invoice_fournisseur') { - $relativepath = get_exdir($modulesubdir, 2,0,0,null,'invoice_supplier'). $modulesubdir. "/" . $file["name"]; - } // Show file name with link to download $out.= 'getNomUrl(1); $filename=dol_sanitizeFileName($obj->ref); $filedir=$conf->fournisseur->facture->dir_output.'/'.get_exdir($obj->facid,2,0,0,$facturestatic,'invoice_supplier').dol_sanitizeFileName($obj->ref); - print $formfile->getDocumentsLink('facture_fournisseur', $filename, $filedir); + $subdir = get_exdir($obj->facid,2,0,0,$facturestatic,'invoice_supplier').dol_sanitizeFileName($obj->ref); + print $formfile->getDocumentsLink('facture_fournisseur', $subdir, $filedir); print "\n"; // Ref supplier From 1740166d287aa4704f04fbde1f731dee9973c0a6 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Thu, 30 Jun 2016 14:16:41 +0200 Subject: [PATCH 15/31] FIX :#5416 --- htdocs/multicurrency/class/multicurrency.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/multicurrency/class/multicurrency.class.php b/htdocs/multicurrency/class/multicurrency.class.php index 9b203ea0424..6bfa3502149 100644 --- a/htdocs/multicurrency/class/multicurrency.class.php +++ b/htdocs/multicurrency/class/multicurrency.class.php @@ -493,7 +493,7 @@ class MultiCurrency extends CommonObject */ public static function getIdFromCode(&$db, $code) { - $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'multicurrency WHERE code = "'.$db->escape($code).'"'; + $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'multicurrency WHERE code = \''.$db->escape($code).'\''; $resql = $db->query($sql); if ($resql && $obj = $db->fetch_object($resql)) return $obj->rowid; else return 0; From c73c1a577adb9d8c6614dc21def9992c0954a72f Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Thu, 30 Jun 2016 14:24:03 +0200 Subject: [PATCH 16/31] Time spent can be saved with project read right --- htdocs/projet/tasks/time.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/projet/tasks/time.php b/htdocs/projet/tasks/time.php index 02fa370fc13..7fc6be32725 100644 --- a/htdocs/projet/tasks/time.php +++ b/htdocs/projet/tasks/time.php @@ -53,7 +53,7 @@ $projectstatic = new Project($db); * Actions */ -if ($action == 'addtimespent' && $user->rights->projet->creer) +if ($action == 'addtimespent' && $user->rights->projet->lire) { $error=0; From 542be965b3ca853f8f4d1a2a7641d9f25021ef89 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Thu, 30 Jun 2016 14:24:55 +0200 Subject: [PATCH 17/31] add log and toher multicurrency bug fix for PgSQL --- .../class/multicurrency.class.php | 29 ++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/htdocs/multicurrency/class/multicurrency.class.php b/htdocs/multicurrency/class/multicurrency.class.php index 6bfa3502149..c2c6ba1bc99 100644 --- a/htdocs/multicurrency/class/multicurrency.class.php +++ b/htdocs/multicurrency/class/multicurrency.class.php @@ -140,6 +140,7 @@ class MultiCurrency extends CommonObject $this->db->begin(); + dol_syslog(__METHOD__,LOG_DEBUG); $resql = $this->db->query($sql); if (!$resql) { $error ++; @@ -184,9 +185,10 @@ class MultiCurrency extends CommonObject $sql = 'SELECT'; $sql .= ' c.rowid, c.name, c.code, c.entity, c.date_create, c.fk_user'; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' AS c'; - if (!empty($code)) $sql .= ' WHERE c.code = "'.$this->db->escape($code).'"'; + if (!empty($code)) $sql .= ' WHERE c.code = \''.$this->db->escape($code).'\''; else $sql .= ' WHERE c.rowid = ' . $id; + dol_syslog(__METHOD__,LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { @@ -226,8 +228,6 @@ class MultiCurrency extends CommonObject */ public function fetchAllCurrencyRate() { - dol_syslog('Currency::fetchAllCurrencyRate', LOG_DEBUG); - $sql = 'SELECT cr.rowid'; $sql.= ' FROM ' . MAIN_DB_PREFIX . $this->table_element_line. ' as cr'; $sql.= ' WHERE cr.fk_multicurrency = '.$this->id; @@ -235,6 +235,7 @@ class MultiCurrency extends CommonObject $this->rates = array(); + dol_syslog(__METHOD__,LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $num = $this->db->num_rows($resql); @@ -284,10 +285,11 @@ class MultiCurrency extends CommonObject // Update request $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; - $sql .= ' name="'.$this->db->escape($this->name).'"'; - $sql .= ' code="'.$this->db->escape($this->code).'"'; + $sql .= ' name=\''.$this->db->escape($this->name).'\''; + $sql .= ' code=\''.$this->db->escape($this->code).'\''; $sql .= ' WHERE rowid=' . $this->id; + dol_syslog(__METHOD__,LOG_DEBUG); $this->db->begin(); $resql = $this->db->query($sql); @@ -347,6 +349,7 @@ class MultiCurrency extends CommonObject $sql = 'DELETE FROM ' . MAIN_DB_PREFIX . $this->table_element; $sql .= ' WHERE rowid=' . $this->id; + dol_syslog(__METHOD__,LOG_DEBUG); $resql = $this->db->query($sql); if (!$resql) { $error ++; @@ -425,7 +428,9 @@ class MultiCurrency extends CommonObject $currency->code = $code; $currency->name = $code; - $sql = 'SELECT label FROM '.MAIN_DB_PREFIX.'c_currencies WHERE code_iso = "'.$db->escape($code).'"'; + $sql = 'SELECT label FROM '.MAIN_DB_PREFIX.'c_currencies WHERE code_iso = \''.$db->escape($code).'\''; + + dol_syslog(__METHOD__,LOG_DEBUG); $resql = $db->query($sql); if ($resql && ($line = $db->fetch_object($resql))) { @@ -475,6 +480,7 @@ class MultiCurrency extends CommonObject $sql.= ' WHERE cr.fk_multicurrency = '.$this->id; $sql.= ' AND cr.date_sync >= ALL (SELECT cr2.date_sync FROM '.MAIN_DB_PREFIX.$this->table_element_line.' AS cr2 WHERE cr.rowid = cr2.rowid)'; + dol_syslog(__METHOD__,LOG_DEBUG); $resql = $this->db->query($sql); if ($resql && ($obj = $this->db->fetch_object($resql))) { $this->rate = new CurrencyRate($this->db); @@ -494,6 +500,8 @@ class MultiCurrency extends CommonObject public static function getIdFromCode(&$db, $code) { $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'multicurrency WHERE code = \''.$db->escape($code).'\''; + + dol_syslog(__METHOD__,LOG_DEBUG); $resql = $db->query($sql); if ($resql && $obj = $db->fetch_object($resql)) return $obj->rowid; else return 0; @@ -512,10 +520,11 @@ class MultiCurrency extends CommonObject { $sql = 'SELECT m.rowid, mc.rate FROM '.MAIN_DB_PREFIX.'multicurrency m'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'multicurrency_rate mc ON (m.rowid = mc.fk_multicurrency)'; - $sql.= ' WHERE m.code = "'.$db->escape($code).'"'; + $sql.= ' WHERE m.code = \''.$db->escape($code).'\''; $sql.= " AND m.entity IN (".getEntity('multicurrency', 1).")"; $sql.= ' ORDER BY mc.date_sync DESC LIMIT 1'; + dol_syslog(__METHOD__,LOG_DEBUG); $resql = $db->query($sql); if ($resql && $obj = $db->fetch_object($resql)) return array($obj->rowid, $obj->rate); else return array(0, 1); @@ -556,6 +565,8 @@ class MultiCurrency extends CommonObject global $db; $sql = 'SELECT multicurrency_tx FROM '.MAIN_DB_PREFIX.$table.' WHERE rowid = '.$fk_facture; + + dol_syslog(__METHOD__,LOG_DEBUG); $resql = $db->query($sql); if ($resql && ($line = $db->fetch_object($resql))) { @@ -721,6 +732,7 @@ class CurrencyRate extends CommonObjectLine $this->db->begin(); + dol_syslog(__METHOD__,LOG_DEBUG); $resql = $this->db->query($sql); if (!$resql) { $error ++; @@ -765,6 +777,7 @@ class CurrencyRate extends CommonObjectLine $sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' AS cr'; $sql .= ' WHERE cr.rowid = ' . $id; + dol_syslog(__METHOD__,LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) { $numrows = $this->db->num_rows($resql); @@ -816,6 +829,7 @@ class CurrencyRate extends CommonObjectLine $this->db->begin(); + dol_syslog(__METHOD__,LOG_DEBUG); $resql = $this->db->query($sql); if (!$resql) { $error ++; @@ -866,6 +880,7 @@ class CurrencyRate extends CommonObjectLine $sql = 'DELETE FROM '.MAIN_DB_PREFIX.$this->table_element; $sql .= ' WHERE rowid='.$this->id; + dol_syslog(__METHOD__,LOG_DEBUG); $resql = $this->db->query($sql); if (!$resql) { $error ++; From 22bc44620b8f2733009867e6a6ca6c9065b5dbc6 Mon Sep 17 00:00:00 2001 From: Alexis Algoud Date: Thu, 30 Jun 2016 14:27:58 +0200 Subject: [PATCH 18/31] FIX #5170 tva sign with INVOICE_POSITIVE_CREDIT_NOTE option --- htdocs/core/lib/pdf.lib.php | 14 ++++++++++---- .../core/modules/facture/doc/pdf_crabe.modules.php | 7 +++++-- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/htdocs/core/lib/pdf.lib.php b/htdocs/core/lib/pdf.lib.php index 6389c71b06c..9fe2bbb1b40 100644 --- a/htdocs/core/lib/pdf.lib.php +++ b/htdocs/core/lib/pdf.lib.php @@ -1342,7 +1342,10 @@ function pdf_getlineupexcltax($object,$i,$outputlangs,$hidedetails=0) */ function pdf_getlineupwithtax($object,$i,$outputlangs,$hidedetails=0) { - global $hookmanager; + global $hookmanager,$conf; + + $sign=1; + if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1; if (is_object($hookmanager) && (($object->lines[$i]->product_type == 9 && !empty($object->lines[$i]->special_code)) || ! empty($object->lines[$i]->fk_parent_line))) { @@ -1355,7 +1358,7 @@ function pdf_getlineupwithtax($object,$i,$outputlangs,$hidedetails=0) } else { - if (empty($hidedetails) || $hidedetails > 1) return price(($object->lines[$i]->subprice) + ($object->lines[$i]->subprice)*($object->lines[$i]->tva_tx)/100, 0, $outputlangs); + if (empty($hidedetails) || $hidedetails > 1) return price($sign * (($object->lines[$i]->subprice) + ($object->lines[$i]->subprice)*($object->lines[$i]->tva_tx)/100), 0, $outputlangs); } } @@ -1629,7 +1632,10 @@ function pdf_getlinetotalexcltax($object,$i,$outputlangs,$hidedetails=0) */ function pdf_getlinetotalwithtax($object,$i,$outputlangs,$hidedetails=0) { - global $hookmanager; + global $hookmanager,$conf; + + $sign=1; + if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1; if ($object->lines[$i]->special_code == 3) { @@ -1648,7 +1654,7 @@ function pdf_getlinetotalwithtax($object,$i,$outputlangs,$hidedetails=0) } else { - if (empty($hidedetails) || $hidedetails > 1) return price(($object->lines[$i]->total_ht) + ($object->lines[$i]->total_ht)*($object->lines[$i]->tva_tx)/100, 0, $outputlangs); + if (empty($hidedetails) || $hidedetails > 1) return price($sign * (($object->lines[$i]->total_ht) + ($object->lines[$i]->total_ht)*($object->lines[$i]->tva_tx)/100), 0, $outputlangs); } } return ''; diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index 719449bcbd4..33febb9028b 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -539,13 +539,16 @@ class pdf_crabe extends ModelePDFFactures $pdf->SetXY($this->postotalht, $curY); $pdf->MultiCell($this->page_largeur-$this->marge_droite-$this->postotalht, 3, $total_excl_tax, 0, 'R', 0); + + $sign=1; + if (isset($object->type) && $object->type == 2 && ! empty($conf->global->INVOICE_POSITIVE_CREDIT_NOTE)) $sign=-1; // Collecte des totaux par valeur de tva dans $this->tva["taux"]=total_tva $prev_progress = $object->lines[$i]->get_prev_progress(); if ($prev_progress > 0) // Compute progress from previous situation { - $tvaligne = $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent; + $tvaligne = $sign * $object->lines[$i]->total_tva * ($object->lines[$i]->situation_percent - $prev_progress) / $object->lines[$i]->situation_percent; } else { - $tvaligne = $object->lines[$i]->total_tva; + $tvaligne = $sign * $object->lines[$i]->total_tva; } $localtax1ligne=$object->lines[$i]->total_localtax1; $localtax2ligne=$object->lines[$i]->total_localtax2; From 97fe75f198de42b116db78a0ecb21f281eca7bfc Mon Sep 17 00:00:00 2001 From: arnaud Date: Thu, 30 Jun 2016 14:57:23 +0200 Subject: [PATCH 19/31] FIX #5004 --- htdocs/societe/consumption.php | 70 +++++++++++++++++----------------- 1 file changed, 36 insertions(+), 34 deletions(-) diff --git a/htdocs/societe/consumption.php b/htdocs/societe/consumption.php index e07e13ef751..ea2cb899893 100644 --- a/htdocs/societe/consumption.php +++ b/htdocs/societe/consumption.php @@ -280,43 +280,45 @@ if ($type_element == 'contract') $thirdTypeSelect='customer'; } -$sql = $sql_select; -$sql.= ' d.description as description,'; -if ($type_element != 'fichinter' && $type_element != 'contract') $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_start, d.date_end, d.qty, d.qty as prod_qty,'; -if ($type_element == 'contract') $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_ouverture as date_start, d.date_cloture as date_end, d.qty, d.qty as prod_qty,'; -if ($type_element != 'fichinter') $sql.= ' p.ref as ref, p.rowid as prod_id, p.rowid as fk_product, p.fk_product_type as prod_type, p.fk_product_type as fk_product_type, p.entity as pentity,'; -$sql.= " s.rowid as socid "; -if ($type_element != 'fichinter') $sql.= ", p.ref as prod_ref, p.label as product_label"; -$sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".$tables_from; -if ($type_element != 'fichinter') $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON d.fk_product = p.rowid '; -$sql.= $where; -if ($month > 0) { - if ($year > 0) { - $start = dol_mktime(0, 0, 0, $month, 1, $year); - $end = dol_time_plus_duree($start,1,'m') - 1; +if(!empty($sql_select)) { + $sql = $sql_select; + $sql.= ' d.description as description,'; + if ($type_element != 'fichinter' && $type_element != 'contract') $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_start, d.date_end, d.qty, d.qty as prod_qty,'; + if ($type_element == 'contract') $sql.= ' d.label, d.fk_product as product_id, d.fk_product as fk_product, d.info_bits, d.date_ouverture as date_start, d.date_cloture as date_end, d.qty, d.qty as prod_qty,'; + if ($type_element != 'fichinter') $sql.= ' p.ref as ref, p.rowid as prod_id, p.rowid as fk_product, p.fk_product_type as prod_type, p.fk_product_type as fk_product_type, p.entity as pentity,'; + $sql.= " s.rowid as socid "; + if ($type_element != 'fichinter') $sql.= ", p.ref as prod_ref, p.label as product_label"; + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".$tables_from; + if ($type_element != 'fichinter') $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON d.fk_product = p.rowid '; + $sql.= $where; + if ($month > 0) { + if ($year > 0) { + $start = dol_mktime(0, 0, 0, $month, 1, $year); + $end = dol_time_plus_duree($start,1,'m') - 1; + $sql.= " AND ".$dateprint." BETWEEN '".$db->idate($start)."' AND '".$db->idate($end)."'"; + } else { + $sql.= " AND date_format(".$dateprint.", '%m') = '".sprintf('%02d',$month)."'"; + } + } else if ($year > 0) { + $start = dol_mktime(0, 0, 0, 1, 1, $year); + $end = dol_time_plus_duree($start,1,'y') - 1; $sql.= " AND ".$dateprint." BETWEEN '".$db->idate($start)."' AND '".$db->idate($end)."'"; - } else { - $sql.= " AND date_format(".$dateprint.", '%m') = '".sprintf('%02d',$month)."'"; } -} else if ($year > 0) { - $start = dol_mktime(0, 0, 0, 1, 1, $year); - $end = dol_time_plus_duree($start,1,'y') - 1; - $sql.= " AND ".$dateprint." BETWEEN '".$db->idate($start)."' AND '".$db->idate($end)."'"; + if ($sref) $sql.= " AND ".$doc_number." LIKE '%".$sref."%'"; + if ($sprod_fulldescr) + { + $sql.= " AND (d.description LIKE '%".$db->escape($sprod_fulldescr)."%'"; + if (GETPOST('type_element') != 'fichinter') $sql.= " OR p.ref LIKE '%".$db->escape($sprod_fulldescr)."%'"; + if (GETPOST('type_element') != 'fichinter') $sql.= " OR p.label LIKE '%".$db->escape($sprod_fulldescr)."%'"; + $sql.=")"; + } + $sql.= $db->order($sortfield,$sortorder); + + $resql=$db->query($sql); + $totalnboflines = $db->num_rows($resql); + + $sql.= $db->plimit($limit + 1, $offset); } -if ($sref) $sql.= " AND ".$doc_number." LIKE '%".$sref."%'"; -if ($sprod_fulldescr) -{ - $sql.= " AND (d.description LIKE '%".$db->escape($sprod_fulldescr)."%'"; - if (GETPOST('type_element') != 'fichinter') $sql.= " OR p.ref LIKE '%".$db->escape($sprod_fulldescr)."%'"; - if (GETPOST('type_element') != 'fichinter') $sql.= " OR p.label LIKE '%".$db->escape($sprod_fulldescr)."%'"; - $sql.=")"; -} -$sql.= $db->order($sortfield,$sortorder); - -$resql=$db->query($sql); -$totalnboflines = $db->num_rows($resql); - -$sql.= $db->plimit($limit + 1, $offset); //print $sql; // Define type of elements From 02169478d03e86ae3b8ec1c57373b30376cb5d37 Mon Sep 17 00:00:00 2001 From: Alexis Algoud Date: Thu, 30 Jun 2016 15:30:07 +0200 Subject: [PATCH 20/31] FIX #4964 buyprice in customer from shipping buyprice wasn't load in expedition::fetch_lines --- htdocs/expedition/class/expedition.class.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 1b7fbefb8a6..a15c3b53b83 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -1266,7 +1266,7 @@ class Expedition extends CommonObject $sql = "SELECT cd.rowid, cd.fk_product, cd.label as custom_label, cd.description, cd.qty as qty_asked"; $sql.= ", cd.total_ht, cd.total_localtax1, cd.total_localtax2, cd.total_ttc, cd.total_tva"; - $sql.= ", cd.tva_tx, cd.localtax1_tx, cd.localtax2_tx, cd.price, cd.subprice, cd.remise_percent"; + $sql.= ", cd.tva_tx, cd.localtax1_tx, cd.localtax2_tx, cd.price, cd.subprice, cd.remise_percent,cd.buy_price_ht as pa_ht"; $sql.= ", ed.rowid as line_id, ed.qty as qty_shipped, ed.fk_origin_line, ed.fk_entrepot"; $sql.= ", p.ref as product_ref, p.label as product_label, p.fk_product_type"; $sql.= ", p.weight, p.weight_units, p.length, p.length_units, p.surface, p.surface_units, p.volume, p.volume_units, p.tobatch as product_tobatch"; @@ -1336,6 +1336,8 @@ class Expedition extends CommonObject $line->volume = $obj->volume; $line->volume_units = $obj->volume_units; + $line->pa_ht = $obj->pa_ht; + // 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); // We force type to 0 $line->desc = $obj->description; // We need ->desc because some code into CommonObject use desc (property defined for other elements) From 0ffe106e2cdb7cfa5213a93a12baf3fc89026267 Mon Sep 17 00:00:00 2001 From: arnaud Date: Thu, 30 Jun 2016 16:03:48 +0200 Subject: [PATCH 21/31] FIX #4749 --- htdocs/compta/bank/annuel.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/bank/annuel.php b/htdocs/compta/bank/annuel.php index 68ef0a42e32..61941a4cefb 100644 --- a/htdocs/compta/bank/annuel.php +++ b/htdocs/compta/bank/annuel.php @@ -36,10 +36,10 @@ $id=GETPOST('account'); $ref=GETPOST('ref'); // Security check -$fieldid = (! empty($ref)?$ref:$id); -$fieldname = isset($ref)?'ref':'rowid'; +$fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref :'')); +$fieldtype = (! empty($ref) ? 'ref' :'rowid'); if ($user->societe_id) $socid=$user->societe_id; -$result=restrictedArea($user,'banque',$fieldid,'bank_account','','',$fieldname); +$result=restrictedArea($user,'banque',$fieldvalue,'bank_account&bank_account','','',$fieldtype); $year_start=GETPOST('year_start'); $year_current = strftime("%Y",time()); @@ -146,7 +146,7 @@ $linkback = ''.$langs->trans("B // Ref print ''; print ''; - + if ($inputalsopricewithtax) print ''; // Qty @@ -3430,7 +3430,7 @@ abstract class CommonObject $text.= ' - '.(! empty($line->label)?$line->label:$label); $description.=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($line->description)); // Description is what to show on popup. We shown nothing if already into desc. } - + $line->pu_ttc = price2num($line->subprice * (1 + ($line->tva_tx/100)), 'MU'); // Output template part (modules that overwrite templates must declare this into descriptor) @@ -3871,7 +3871,7 @@ abstract class CommonObject return -1; } } - + // We save charset_output to restore it because write_file can change it if needed for // output format that does not support UTF8. $sav_charset_output=$outputlangs->charset_output; @@ -3935,13 +3935,13 @@ abstract class CommonObject /* For default values */ /** - * Return the default value to use for a field when showing the create form of object. + * Return the default value to use for a field when showing the create form of object. * Return values in this order: * 1) If parameter is available into POST, we return it first. * 2) If not but an alternate value was provided as parameter of function, we return it. - * 3) If not but a constant $conf->global->OBJECTELEMENT_FIELDNAME is set, we return it (It is better to use the dedicated table). + * 3) If not but a constant $conf->global->OBJECTELEMENT_FIELDNAME is set, we return it (It is better to use the dedicated table). * 4) Return value found into database (TODO No yet implemented) - * + * * @param string $fieldname Name of field * @param string $alternatevalue Alternate value to use * @return string|string[] Default value (can be an array if the GETPOST return an array) @@ -3952,27 +3952,27 @@ abstract class CommonObject // If param here has been posted, we use this value first. if (isset($_POST[$fieldname])) return GETPOST($fieldname, 2); - + if (isset($alternatevalue)) return $alternatevalue; - + $newelement=$this->element; if ($newelement == 'facture') $newelement='invoice'; if ($newelement == 'commande') $newelement='order'; - if (empty($newelement)) + if (empty($newelement)) { dol_syslog("Ask a default value using common method getDefaultCreateValueForField on an object with no property ->element defined. Return empty string.", LOG_WARNING); return ''; } - + $keyforfieldname=strtoupper($newelement.'_DEFAULT_'.$fieldname); //var_dump($keyforfieldname); if (isset($conf->global->$keyforfieldname)) return $conf->global->$keyforfieldname; - - // TODO Ad here a scan into table llx_overwrite_default with a filter on $this->element and $fieldname - + + // TODO Ad here a scan into table llx_overwrite_default with a filter on $this->element and $fieldname + } - - + + /* For triggers */ @@ -3989,7 +3989,7 @@ abstract class CommonObject function call_trigger($trigger_name, $user) { global $langs,$conf; - + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; $interface=new Interfaces($this->db); $result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf); @@ -4171,7 +4171,7 @@ abstract class CommonObject { $res=$object->fetch(0,$value); if ($res > 0) $this->array_options[$key]=$object->id; - else + else { $this->error="Ref '".$value."' for object '".$object->element."' not found"; $this->db->rollback(); @@ -4235,7 +4235,7 @@ abstract class CommonObject } else return 0; } - + /** * Update an exta field value for the current object. * Data to describe values to insert/update are stored into $this->array_options=array('options_codeforfield1'=>'valueforfield1', 'options_codeforfield2'=>'valueforfield2', ...) @@ -4300,7 +4300,7 @@ abstract class CommonObject } break; } - + $this->db->begin(); $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element."_extrafields SET ".$key."='".$this->db->escape($this->array_options["options_".$key])."'"; $sql .= " WHERE fk_object = ".$this->id; @@ -4478,7 +4478,7 @@ abstract class CommonObject * @param int $origin_id Old thirdparty id (the thirdparty to delete) * @param int $dest_id New thirdparty id (the thirdparty that will received element of the other) * @param string[] $tables Tables that need to be changed - * @param int $ignoreerrors Ignore errors. Return true even if errors. We need this when replacement can fails like for categories (categorie of old thirdparty may already exists on new one) + * @param int $ignoreerrors Ignore errors. Return true even if errors. We need this when replacement can fails like for categories (categorie of old thirdparty may already exists on new one) * @return bool */ public static function commonReplaceThirdparty(DoliDB $db, $origin_id, $dest_id, array $tables, $ignoreerrors=0) @@ -4487,7 +4487,7 @@ abstract class CommonObject { $sql = 'UPDATE '.MAIN_DB_PREFIX.$table.' SET fk_soc = '.$dest_id.' WHERE fk_soc = '.$origin_id; - if (! $db->query($sql)) + if (! $db->query($sql)) { if ($ignoreerrors) return true; //$this->errors = $db->lasterror(); @@ -4497,26 +4497,26 @@ abstract class CommonObject return true; } - + /** * Get buy price to use for margin calculation. This function is called when buy price is unknown. * set buy price = sell price if ForceBuyingPriceIfNull configured, * else if calculation MARGIN_TYPE = 'costprice' and costprice is defined, use costprice as buyprice * else if calculation MARGIN_TYPE = 'pmp' and pmp is calculated, use pmp as buyprice * else set min buy price as buy price - * + * * @param float $unitPrice product unit price * @param float $discountPercent line discount percent * @param int $fk_product product id * * @return float <0 if ko, buyprice if ok */ - public function defineBuyPrice($unitPrice = 0, $discountPercent = 0, $fk_product = 0) + public function defineBuyPrice($unitPrice = 0, $discountPercent = 0, $fk_product = 0) { global $conf; - + $buyPrice = 0; - + if (($unitPrice > 0) && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) // In most cases, test here is false { $buyPrice = $unitPrice * (1 - $discountPercent / 100); @@ -4560,7 +4560,7 @@ abstract class CommonObject $buyPrice = $product->pmp; } } - + if (empty($buyPrice) && isset($conf->global->MARGIN_TYPE) && in_array($conf->global->MARGIN_TYPE, array('1','pmp','costprice'))) { require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; diff --git a/htdocs/install/mysql/data/llx_accounting_category.sql b/htdocs/install/mysql/data/llx_accounting_category.sql index 5769d291563..8e69ca6331e 100644 --- a/htdocs/install/mysql/data/llx_accounting_category.sql +++ b/htdocs/install/mysql/data/llx_accounting_category.sql @@ -25,5 +25,5 @@ -- INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 1,'VTE','Ventes de marchandises', '707xxx', 0, 0, '', '10', 1, 1); -INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 2,'MAR','Coût d\'achats marchandises vendues', '603xxx | 607xxx | 609xxx', 0, 0, '', '20', 1, 1); +INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 2,'MAR','Coût d achats marchandises vendues', '603xxx | 607xxx | 609xxx', 0, 0, '', '20', 1, 1); INSERT INTO llx_c_accounting_category (rowid, code, label, range_account, sens, category_type, formula, position, fk_country, active) VALUES ( 3,'MARGE','Marge commerciale', '', 0, 1, '1 + 2', '30', 1, 1); \ No newline at end of file diff --git a/htdocs/install/pgsql/functions/functions.sql b/htdocs/install/pgsql/functions/functions.sql index 307c88c3007..df0c64855b1 100644 --- a/htdocs/install/pgsql/functions/functions.sql +++ b/htdocs/install/pgsql/functions/functions.sql @@ -56,16 +56,12 @@ CREATE OR REPLACE FUNCTION dol_util_triggerall(DoEnable boolean) RETURNS integer CREATE OR REPLACE FUNCTION update_modified_column_tms() RETURNS TRIGGER AS $$ BEGIN NEW.tms = now(); RETURN NEW; END; $$ LANGUAGE plpgsql; CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_accounting_account FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms(); CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_accounting_fiscalyear FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms(); -CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_accountingtransaction FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms(); CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_actioncomm FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms(); CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_actioncomm_extrafields FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms(); CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_adherent FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms(); CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_adherent_extrafields FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms(); CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_adherent_type FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms(); CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_adherent_type_extrafields FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms(); -CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_askpricesupplier FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms(); -CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_askpricesupplier_extrafields FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms(); -CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_askpricesupplierdet_extrafields FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms(); CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_bank FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms(); CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_bank_account FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms(); CREATE TRIGGER update_customer_modtime BEFORE UPDATE ON llx_bank_account_extrafields FOR EACH ROW EXECUTE PROCEDURE update_modified_column_tms(); From 3611161b67353c96ac0ffbc9491c544deb48b19c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 30 Jun 2016 19:35:11 +0200 Subject: [PATCH 28/31] Fix custom code should not appears on services --- dev/translation/sanity_check_en_langfiles.php | 3 ++- htdocs/langs/en_US/products.lang | 2 ++ htdocs/product/card.php | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/dev/translation/sanity_check_en_langfiles.php b/dev/translation/sanity_check_en_langfiles.php index f64798d72ff..6d63c415981 100755 --- a/dev/translation/sanity_check_en_langfiles.php +++ b/dev/translation/sanity_check_en_langfiles.php @@ -324,7 +324,8 @@ if ((! empty($_REQUEST['unused']) && $_REQUEST['unused'] == 'true') || (isset($a if (preg_match('/GlobalVariableUpdaterHelp$/', $value)) $qualifiedforclean=0; if (preg_match('/OppStatus/', $value)) $qualifiedforclean=0; if (preg_match('/AvailabilityType/', $value)) $qualifiedforclean=0; - + if (preg_match('/CardProduct/', $value)) $qualifiedforclean=0; + if (preg_match('/sms/i', $value)) $qualifiedforclean=0; if (preg_match('/TF_/i', $value)) $qualifiedforclean=0; if (preg_match('/WithBankUsing/i', $value)) $qualifiedforclean=0; diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index b1b8d601430..e9142d463ff 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -32,6 +32,8 @@ ServicesOnSellAndOnBuy=Services for sale and for purchase LastModifiedProductsAndServices=Latest %s modified products/services LastRecordedProducts=Latest %s recorded products LastRecordedServices=Latest %s recorded services +CardProduct0=Product card +CardProduct1=Service card Stock=Stock Stocks=Stocks Movements=Movements diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 330e712cf1b..e524b8f8303 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -1314,7 +1314,7 @@ else } // Custom code - if (empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO)) + if (! $object->isService() && empty($conf->global->PRODUCT_DISABLE_CUSTOM_INFO)) { print ''; // Origin country From 102179028c6db5db2ee3277ad6e04e0954389e1c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 1 Jul 2016 03:11:41 +0200 Subject: [PATCH 29/31] FIX #5414 --- htdocs/langs/en_US/admin.lang | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index af3373bf4aa..d5086ca1343 100755 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -564,6 +564,8 @@ Module59000Name=Margins Module59000Desc=Module to manage margins Module60000Name=Commissions Module60000Desc=Module to manage commissions +Module63000Name=Resources +Module63000Desc=Manage resources (printers, cars, room, ...) you can then share into events Permission11=Read customer invoices Permission12=Create/modify customer invoices Permission13=Unvalidate customer invoices From 62d7303d8fecd59dcaec7c4eb7da43b9e62c80cd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 1 Jul 2016 03:40:48 +0200 Subject: [PATCH 30/31] Add comment --- htdocs/core/class/commonobject.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index aa36fa74624..71540cf16d7 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -4489,7 +4489,7 @@ abstract class CommonObject if (! $db->query($sql)) { - if ($ignoreerrors) return true; + if ($ignoreerrors) return true; // TODO Not enough. If there is A-B on kept thirdarty and B-C on old one, we must get A-B-C after merge. Not A-B. //$this->errors = $db->lasterror(); return false; } From 2c5e1c17fe4407cb2abae27fcc68900368569614 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 1 Jul 2016 03:42:19 +0200 Subject: [PATCH 31/31] Fix hard coded table prefix --- htdocs/societe/class/societe.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 0e7e375ac2f..e9b77836d3c 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -3483,17 +3483,17 @@ class Societe extends CommonObject * Because this function is meant to be executed within a transaction, we won't take care of it. */ $sql = 'SELECT rowid -FROM llx_societe_commerciaux +FROM '.MAIN_DB_PREFIX.'societe_commerciaux WHERE fk_soc = '.(int) $dest_id.' AND fk_user IN ( SELECT fk_user - FROM llx_societe_commerciaux + FROM '.MAIN_DB_PREFIX.'societe_commerciaux WHERE fk_soc = '.(int) $origin_id.' );'; $query = $db->query($sql); while ($result = $db->fetch_object($query)) { - $db->query('DELETE FROM llx_societe_commerciaux WHERE rowid = '.$result->rowid); + $db->query('DELETE FROM '.MAIN_DB_PREFIX.'societe_commerciaux WHERE rowid = '.$result->rowid); } /**
'.$langs->trans("Account").''.$langs->trans("Description").'N-1N-1'.$langs->trans("NReal").''.$langs->trans($v).'
' . $cpt['account_number'] . '' . $cpt['name_cpt'] . '' . price($resultNP) . '' . price($resultN) . '' . price($resultM) . '
' . price($result) . '' . price($result) . '' . price($result) . '' . $catsCalcule[$p]['formula'] . '
' . price($result) . '' . price($result) . '
'.$langs->trans("Ref").''; -if ($_GET["account"]) +if (!empty($id)) { if (! preg_match('/,/', $id)) { From 75bb16193089d141c71a96d0db24fb95364545ec Mon Sep 17 00:00:00 2001 From: atm-geoffrey Date: Thu, 30 Jun 2016 16:20:53 +0200 Subject: [PATCH 22/31] FIX #4828 --- htdocs/comm/action/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 123189bdc87..a78eac54695 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -781,7 +781,7 @@ if ($action == 'create') print '
'.$langs->trans("Project").''; - $numproject=$formproject->select_projects((! empty($societe->id)?$societe->id:0),GETPOST("projectid")?GETPOST("projectid"):'','projectid'); + $numproject=$formproject->select_projects((! empty($societe->id)?$societe->id:-1),GETPOST("projectid")?GETPOST("projectid"):'','projectid'); if ($numproject==0) { print '   '.$langs->trans("AddProject").''; From aa67a29115817036fcc9016b0641f7f984e82202 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Thu, 30 Jun 2016 16:40:38 +0200 Subject: [PATCH 23/31] FIX #4383 $userid not defined --- htdocs/user/class/userbankaccount.class.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/htdocs/user/class/userbankaccount.class.php b/htdocs/user/class/userbankaccount.class.php index 30c795bbd72..437be45c7b2 100644 --- a/htdocs/user/class/userbankaccount.class.php +++ b/htdocs/user/class/userbankaccount.class.php @@ -142,8 +142,7 @@ class UserBankAccount extends Account $sql = "SELECT rowid, fk_user, entity, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,"; $sql.= " owner_address, label, datec, tms as datem"; $sql.= " FROM ".MAIN_DB_PREFIX."user_rib"; - if ($id) $sql.= " WHERE rowid = ".$id; - if ($socid) $sql.= " WHERE fk_user = ".$userid; + $sql.= " WHERE rowid = ".$id; $resql = $this->db->query($sql); if ($resql) From 38dcb0de4988a9a632db69b1f96278983615f042 Mon Sep 17 00:00:00 2001 From: arnaud Date: Thu, 30 Jun 2016 16:53:24 +0200 Subject: [PATCH 24/31] FIX #4455 --- htdocs/fourn/card.php | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php index 5188003c115..956d4b52452 100644 --- a/htdocs/fourn/card.php +++ b/htdocs/fourn/card.php @@ -407,6 +407,18 @@ if ($object->id > 0) } // TODO move to DAO class + $sql = "SELECT count(p.rowid) as total"; + $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as p "; + $sql.= " WHERE p.fk_soc =".$object->id; + $sql.= " AND p.entity =".$conf->entity; + $sql.= " ORDER BY p.date_commande DESC"; + $resql=$db->query($sql); + if ($resql) + { + $object_count = $db->fetch_object($resql); + $num = $object_count->total; + } + $sql = "SELECT p.rowid,p.ref, p.date_commande as dc, p.fk_statut, p.total_ht, p.tva as total_tva, p.total_ttc"; $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as p "; $sql.= " WHERE p.fk_soc =".$object->id; @@ -417,7 +429,6 @@ if ($object->id > 0) if ($resql) { $i = 0 ; - $num = $db->num_rows($resql); if ($num > 0) { @@ -433,7 +444,7 @@ if ($object->id > 0) } $var = True; - while ($i < $num && $i <= $MAXLIST) + while ($i < $num && $i < $MAXLIST) { $obj = $db->fetch_object($resql); $var=!$var; From d004f3a538c6a0907ea75cb2e07671f47a775bc9 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Thu, 30 Jun 2016 17:03:56 +0200 Subject: [PATCH 25/31] FIX #4448 $filebonprev is not used, $this->filename now --- .../compta/prelevement/class/bonprelevement.class.php | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/htdocs/compta/prelevement/class/bonprelevement.class.php b/htdocs/compta/prelevement/class/bonprelevement.class.php index 610fe257732..8fd5450d66a 100644 --- a/htdocs/compta/prelevement/class/bonprelevement.class.php +++ b/htdocs/compta/prelevement/class/bonprelevement.class.php @@ -918,7 +918,10 @@ class BonPrelevement extends CommonObject $row = $this->db->fetch_row($resql); $ref = "T".$ref.str_pad(dol_substr("00".intval($row[0])+1,0,2),2,"0",STR_PAD_LEFT); - $this->filename = $conf->prelevement->dir_output.'/receipts/'.$ref.'.xml'; + $dir=$conf->prelevement->dir_output.'/receipts'; + if (! is_dir($dir)) dol_mkdir($dir); + + $this->filename = $dir.'/receipts/'.$ref.'.xml'; // Create withdraw receipt in database $sql = "INSERT INTO ".MAIN_DB_PREFIX."prelevement_bons ("; @@ -934,10 +937,6 @@ class BonPrelevement extends CommonObject { $prev_id = $this->db->last_insert_id(MAIN_DB_PREFIX."prelevement_bons"); $this->id = $prev_id; - - $dir=$conf->prelevement->dir_output.'/receipts'; - $file=$filebonprev; - if (! is_dir($dir)) dol_mkdir($dir); } else { @@ -1033,7 +1032,7 @@ class BonPrelevement extends CommonObject // Generation of SEPA file $this->generate(); } - dol_syslog(__METHOD__."::End withdraw receipt, file ".$filebonprev, LOG_DEBUG); + dol_syslog(__METHOD__."::End withdraw receipt, file ".$this->filename, LOG_DEBUG); } /* From 37ee64ae9ba24a70ef2def4e2168e0d7db363c0e Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Thu, 30 Jun 2016 17:10:06 +0200 Subject: [PATCH 26/31] fix 4672 --- htdocs/comm/mailing/advtargetemailing.php | 8 +++---- htdocs/core/lib/emailing.lib.php | 8 +++---- .../mailings/advthirdparties.modules.php | 22 +++++++++---------- 3 files changed, 19 insertions(+), 19 deletions(-) diff --git a/htdocs/comm/mailing/advtargetemailing.php b/htdocs/comm/mailing/advtargetemailing.php index be8a63225fe..9cd40a55b8b 100644 --- a/htdocs/comm/mailing/advtargetemailing.php +++ b/htdocs/comm/mailing/advtargetemailing.php @@ -221,7 +221,7 @@ if ($action == 'add') { if ((count($advTarget->thirdparty_lines) > 0) || (count($advTarget->contact_lines) > 0)) { // Add targets into database $obj = new mailing_advthirdparties($db); - $result = $obj->add_to_target($id, $advTarget->thirdparty_lines, $array_query['type_of_target'], $advTarget->contact_lines); + $result = $obj->add_to_target_spec($id, $advTarget->thirdparty_lines, $array_query['type_of_target'], $advTarget->contact_lines); } else { $result = 0; } @@ -967,11 +967,11 @@ if ($object->fetch($id) >= 0) { print ''; print '
'; } - - if (empty($conf->mailchimp->enabled) || (! empty($conf->mailchimp->enabled) && $object->statut != 3)) + + if (empty($conf->mailchimp->enabled) || (! empty($conf->mailchimp->enabled) && $object->statut != 3)) { - // List of recipients (TODO Move code of page cibles.php into a .tpl.php file and make an include here to avoid duplicate content) + // List of recipients (TODO Move code of page cibles.php into a .tpl.php file and make an include here to avoid duplicate content) } } diff --git a/htdocs/core/lib/emailing.lib.php b/htdocs/core/lib/emailing.lib.php index 443b9b6156a..9ddd05f7faa 100644 --- a/htdocs/core/lib/emailing.lib.php +++ b/htdocs/core/lib/emailing.lib.php @@ -39,14 +39,14 @@ function emailing_prepare_head(Mailing $object) $head[$h][2] = 'card'; $h++; - if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->mailing->mailing_advance->recipient)) + if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->mailing->mailing_advance->recipient)) { $head[$h][0] = DOL_URL_ROOT."/comm/mailing/cibles.php?id=".$object->id; $head[$h][1] = $langs->trans("MailRecipients"); $head[$h][2] = 'targets'; $h++; - - if (! empty($conf->global->EMAILING_USE_ADVANCED_SELECTOR)) // Still need debug + + if (! empty($conf->global->EMAILING_USE_ADVANCED_SELECTOR)) { $head[$h][0] = DOL_URL_ROOT."/comm/mailing/advtargetemailing.php?id=".$object->id; $head[$h][1] = $langs->trans("MailAdvTargetRecipients"); @@ -54,7 +54,7 @@ function emailing_prepare_head(Mailing $object) $h++; } } - + $head[$h][0] = DOL_URL_ROOT."/comm/mailing/info.php?id=".$object->id; $head[$h][1] = $langs->trans("Info"); $head[$h][2] = 'info'; diff --git a/htdocs/core/modules/mailings/advthirdparties.modules.php b/htdocs/core/modules/mailings/advthirdparties.modules.php index cba8af72295..1e04fe5459d 100644 --- a/htdocs/core/modules/mailings/advthirdparties.modules.php +++ b/htdocs/core/modules/mailings/advthirdparties.modules.php @@ -56,7 +56,7 @@ class mailing_advthirdparties extends MailingTargets * @param array $contactid Array of contact id to add * @return int <0 if error, number of emails added if ok */ - function add_to_target($mailing_id,$socid,$type_of_target, $contactid) + function add_to_target_spec($mailing_id,$socid,$type_of_target, $contactid) { global $conf, $langs; @@ -80,14 +80,14 @@ class mailing_advthirdparties extends MailingTargets { $num = $this->db->num_rows($result); $i = 0; - + dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found", LOG_DEBUG); - + $old = ''; while ($i < $num) { $obj = $this->db->fetch_object($result); - + if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) { if (!array_key_exists($obj->email, $cibles)) { $cibles[$obj->email] = array( @@ -102,7 +102,7 @@ class mailing_advthirdparties extends MailingTargets ); } } - + $i++; } } @@ -129,21 +129,21 @@ class mailing_advthirdparties extends MailingTargets $sql.= " AND socp.fk_soc IN (".implode(',',$socid).")"; } $sql.= " ORDER BY email"; - + // Stock recipients emails into targets table $result=$this->db->query($sql); if ($result) { $num = $this->db->num_rows($result); $i = 0; - + dol_syslog(get_class($this)."::add_to_target mailing ".$num." targets found"); - + $old = ''; while ($i < $num) { $obj = $this->db->fetch_object($result); - + if (!empty($obj->email) && filter_var($obj->email, FILTER_VALIDATE_EMAIL)) { if (!array_key_exists($obj->email, $cibles)) { $cibles[$obj->email] = array( @@ -158,7 +158,7 @@ class mailing_advthirdparties extends MailingTargets ); } } - + $i++; } } @@ -202,7 +202,7 @@ class mailing_advthirdparties extends MailingTargets * * @return int Nb of recipients */ - function getNbOfRecipients() + function getNbOfRecipients($sql) { global $conf; From 215f397f33a6e279e0f6d8dc39ab80d5eff74e64 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Thu, 30 Jun 2016 17:28:13 +0200 Subject: [PATCH 27/31] Cannot reproduce 4793 still fix other bug on PgSQL --- htdocs/compta/facture/class/facture.class.php | 140 +++++++++-------- htdocs/core/class/commonobject.class.php | 146 +++++++++--------- .../mysql/data/llx_accounting_category.sql | 2 +- htdocs/install/pgsql/functions/functions.sql | 4 - 4 files changed, 146 insertions(+), 146 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index aa51c63374d..73127f9a1f2 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -108,7 +108,7 @@ class Facture extends CommonInvoice var $specimen; var $fac_rec; - + // Multicurrency var $fk_multicurrency; var $multicurrency_code; @@ -136,7 +136,7 @@ class Facture extends CommonInvoice * @var array Table of previous situations */ public $tab_previous_situation_invoice=array(); - + /** * @var array Table of next situations */ @@ -249,7 +249,7 @@ class Facture extends CommonInvoice $this->fk_multicurrency = 0; $this->multicurrency_tx = 1; } - + dol_syslog(get_class($this)."::create user=".$user->id); // Check parameters @@ -280,7 +280,7 @@ class Facture extends CommonInvoice $result=$_facrec->fetch($this->fac_rec); $this->socid = $_facrec->socid; - + // Fields coming from GUI (priority on template). TODO Value of template should be used as default value on GUI so we can use here always value from GUI $this->fk_project = GETPOST('projectid','int') > 0 ? GETPOST('projectid','int') : $_facrec->fk_project; $this->note_public = GETPOST('note_public') ? GETPOST('note_public') : $_facrec->note_public; @@ -289,7 +289,7 @@ class Facture extends CommonInvoice $this->cond_reglement_id = GETPOST('cond_reglement_id') > 0 ? GETPOST('cond_reglement_id') : $_facrec->cond_reglement_id; $this->mode_reglement_id = GETPOST('mode_reglement_id') > 0 ? GETPOST('mode_reglement_id') : $_facrec->mode_reglement_id; $this->fk_account = GETPOST('fk_account') > 0 ? GETPOST('fk_account') : $_facrec->fk_account; - + // Fields always coming from template $this->remise_absolue = $_facrec->remise_absolue; $this->remise_percent = $_facrec->remise_percent; @@ -302,13 +302,13 @@ class Facture extends CommonInvoice $this->note_public=trim($this->note_public); $this->note_private=trim($this->note_private); $this->note_private=dol_concatdesc($this->note_private, $langs->trans("GeneratedFromRecurringInvoice", $_facrec->ref)); - + //if (! $this->remise) $this->remise = 0; if (! $this->mode_reglement_id) $this->mode_reglement_id = 0; $this->brouillon = 1; - + $forceduedate = $this->calculate_date_lim_reglement(); - + // For recurrn invoices, update date and number of last generation of recurring template invoice, before inserting new invoice if ($_facrec->frequency > 0) { @@ -658,7 +658,7 @@ class Facture extends CommonInvoice function createFromCurrent($user,$invertdetail=0) { global $conf; - + // Charge facture source $facture=new Facture($this->db); @@ -712,15 +712,15 @@ class Facture extends CommonInvoice elseif ($this->type == self::TYPE_SITUATION && !empty($conf->global->INVOICE_USE_SITUATION)) { $this->fetchObjectLinked('', '', $object->id, 'facture'); - - foreach ($this->linkedObjectsIds as $typeObject => $Tfk_object) + + foreach ($this->linkedObjectsIds as $typeObject => $Tfk_object) { - foreach ($Tfk_object as $fk_object) + foreach ($Tfk_object as $fk_object) { $facture->add_object_linked($typeObject, $fk_object); } } - + $facture->add_object_linked('facture', $this->fk_facture_source); } @@ -1107,7 +1107,7 @@ class Facture extends CommonInvoice $this->multicurrency_total_ht = $obj->multicurrency_total_ht; $this->multicurrency_total_tva = $obj->multicurrency_total_tva; $this->multicurrency_total_ttc = $obj->multicurrency_total_ttc; - + if ($this->type == self::TYPE_SITUATION && $fetch_situation) { $this->fetchPreviousNextSituationInvoice(); @@ -1229,7 +1229,7 @@ class Facture extends CommonInvoice $line->situation_percent= $objp->situation_percent; $line->fk_prev_id = $objp->fk_prev_id; $line->fk_unit = $objp->fk_unit; - + // Multicurrency $line->fk_multicurrency = $objp->fk_multicurrency; $line->multicurrency_code = $objp->multicurrency_code; @@ -1237,7 +1237,7 @@ class Facture extends CommonInvoice $line->multicurrency_total_ht = $objp->multicurrency_total_ht; $line->multicurrency_total_tva = $objp->multicurrency_total_tva; $line->multicurrency_total_ttc = $objp->multicurrency_total_ttc; - + $this->lines[$i] = $line; $i++; @@ -1255,17 +1255,17 @@ class Facture extends CommonInvoice /** * Fetch previous and next situations invoices * - * @return void + * @return void */ function fetchPreviousNextSituationInvoice() { global $conf; - + $this->tab_previous_situation_invoice = array(); $this->tab_next_situation_invoice = array(); - + $sql = 'SELECT rowid, situation_counter FROM '.MAIN_DB_PREFIX.'facture WHERE rowid <> '.$this->id.' AND entity = '.$conf->entity.' AND situation_cycle_ref = '.(int) $this->situation_cycle_ref.' ORDER BY situation_counter ASC'; - + dol_syslog(get_class($this).'::fetchPreviousNextSituationInvoice ', LOG_DEBUG); $result = $this->db->query($sql); if ($result && $this->db->num_rows($result) > 0) @@ -1274,13 +1274,13 @@ class Facture extends CommonInvoice { $invoice = new Facture($this->db); if ($invoice->fetch($objp->rowid) > 0) - { + { if ($objp->situation_counter < $this->situation_counter) $this->tab_previous_situation_invoice[] = $invoice; else $this->tab_next_situation_invoice[] = $invoice; } } } - + } /** @@ -2061,7 +2061,7 @@ class Facture extends CommonInvoice $this->brouillon=0; $this->date_validation=$now; $i = 0; - + if (!empty($conf->global->INVOICE_USE_SITUATION)) { $final = True; @@ -2094,7 +2094,7 @@ class Facture extends CommonInvoice /** * Update price of next invoice - * + * * @param Translate $langs Translate object * @return bool false if KO, true if OK */ @@ -2103,13 +2103,13 @@ class Facture extends CommonInvoice foreach ($this->tab_next_situation_invoice as $next_invoice) { $is_last = $next_invoice->is_last_in_cycle(); - - if ($next_invoice->brouillon && $is_last != 1) + + if ($next_invoice->brouillon && $is_last != 1) { $this->error = $langs->trans('updatePriceNextInvoiceErrorUpdateline', $next_invoice->ref); return false; } - + $next_invoice->brouillon = 1; foreach ($next_invoice->lines as $line) { @@ -2117,17 +2117,17 @@ class Facture extends CommonInvoice $line->date_start, $line->date_end, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, 'HT', $line->info_bits, $line->product_type, $line->fk_parent_line, 0, $line->fk_fournprice, $line->pa_ht, $line->label, $line->special_code, $line->array_options, $line->situation_percent, $line->fk_unit); - - if ($result < 0) + + if ($result < 0) { $this->error = $langs->trans('updatePriceNextInvoiceErrorUpdateline', $next_invoice->ref); return false; } } - + break; // Only the next invoice and not each next invoice } - + return true; } @@ -2280,7 +2280,7 @@ class Facture extends CommonInvoice if (empty($fk_parent_line) || $fk_parent_line < 0) $fk_parent_line=0; if (empty($fk_prev_id)) $fk_prev_id = 'null'; if (! isset($situation_percent) || $situation_percent > 100 || (string) $situation_percent == '') $situation_percent = 100; - + $remise_percent=price2num($remise_percent); $qty=price2num($qty); $pu_ht=price2num($pu_ht); @@ -2342,7 +2342,7 @@ class Facture extends CommonInvoice $multicurrency_total_ht = $tabprice[16]; $multicurrency_total_tva = $tabprice[17]; $multicurrency_total_ttc = $tabprice[18]; - + // Rank to use $rangtouse = $rang; if ($rangtouse == -1) @@ -2355,14 +2355,14 @@ class Facture extends CommonInvoice $this->line=new FactureLigne($this->db); $this->line->context = $this->context; - + $this->line->fk_facture=$this->id; $this->line->label=$label; // deprecated $this->line->desc=$desc; - + $this->line->qty= ($this->type==self::TYPE_CREDIT_NOTE?abs($qty):$qty); // For credit note, quantity is always positive and unit price negative $this->line->subprice= ($this->type==self::TYPE_CREDIT_NOTE?-abs($pu_ht):$pu_ht); // For credit note, unit price always negative, always positive otherwise - + $this->line->tva_tx=$txtva; $this->line->localtax1_tx=$txlocaltax1; $this->line->localtax2_tx=$txlocaltax2; @@ -2374,7 +2374,7 @@ class Facture extends CommonInvoice $this->line->total_tva= (($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_tva):$total_tva); // For credit note and if qty is negative, total is negative $this->line->total_localtax1=(($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_localtax1):$total_localtax1); // For credit note and if qty is negative, total is negative $this->line->total_localtax2=(($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_localtax2):$total_localtax2); // For credit note and if qty is negative, total is negative - + $this->line->fk_product=$fk_product; $this->line->product_type=$product_type; $this->line->remise_percent=$remise_percent; @@ -2384,7 +2384,7 @@ class Facture extends CommonInvoice $this->line->rang=$rangtouse; $this->line->info_bits=$info_bits; $this->line->fk_remise_except=$fk_remise_except; - + $this->line->special_code=$special_code; $this->line->fk_parent_line=$fk_parent_line; $this->line->origin=$origin; @@ -2396,7 +2396,7 @@ class Facture extends CommonInvoice // infos marge $this->line->fk_fournprice = $fk_fournprice; $this->line->pa_ht = $pa_ht; - + // Multicurrency $this->line->fk_multicurrency = $this->fk_multicurrency; $this->line->multicurrency_code = $this->multicurrency_code; @@ -2404,7 +2404,7 @@ class Facture extends CommonInvoice $this->line->multicurrency_total_ht = $multicurrency_total_ht; $this->line->multicurrency_total_tva = $multicurrency_total_tva; $this->line->multicurrency_total_ttc = $multicurrency_total_ttc; - + if (is_array($array_options) && count($array_options)>0) { $this->line->array_options=$array_options; } @@ -2489,7 +2489,7 @@ class Facture extends CommonInvoice return -3; } } - + $this->db->begin(); // Clean parameters @@ -2515,7 +2515,7 @@ class Facture extends CommonInvoice $localtaxes_type=getLocalTaxesFromRate($txtva,0,$this->thirdparty, $mysoc); $txtva = preg_replace('/\s*\(.*\)/','',$txtva); // Remove code into vatrate. - + $tabprice=calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, $situation_percent, $this->multicurrency_tx); $total_ht = $tabprice[0]; @@ -2531,7 +2531,7 @@ class Facture extends CommonInvoice $multicurrency_total_ht = $tabprice[16]; $multicurrency_total_tva = $tabprice[17]; $multicurrency_total_ttc = $tabprice[18]; - + // Old properties: $price, $remise (deprecated) $price = $pu; $remise = 0; @@ -2607,7 +2607,7 @@ class Facture extends CommonInvoice $this->line->multicurrency_total_ht = $multicurrency_total_ht; $this->line->multicurrency_total_tva = $multicurrency_total_tva; $this->line->multicurrency_total_ttc = $multicurrency_total_ttc; - + if (is_array($array_options) && count($array_options)>0) { $this->line->array_options=$array_options; } @@ -2638,28 +2638,28 @@ class Facture extends CommonInvoice } /** - * Check if the percent edited is lower of next invoice line - * + * Check if the percent edited is lower of next invoice line + * * @param int $idline id of line to check * @param float $situation_percent progress percentage need to be test * @return false if KO, true if OK */ function checkProgressLine($idline, $situation_percent) { - $sql = 'SELECT fd.situation_percent FROM '.MAIN_DB_PREFIX.'facturedet fd - INNER JOIN '.MAIN_DB_PREFIX.'facture f ON (fd.fk_facture = f.rowid) - WHERE fd.fk_prev_id = '.$idline.' + $sql = 'SELECT fd.situation_percent FROM '.MAIN_DB_PREFIX.'facturedet fd + INNER JOIN '.MAIN_DB_PREFIX.'facture f ON (fd.fk_facture = f.rowid) + WHERE fd.fk_prev_id = '.$idline.' AND f.fk_statut <> 0'; - + $result = $this->db->query($sql); if (! $result) { $this->error=$this->db->error(); return false; } - + $obj = $this->db->fetch_object($result); - + if ($obj === null) return true; else return $situation_percent < $obj->situation_percent; } @@ -2674,7 +2674,7 @@ class Facture extends CommonInvoice function update_percent($line, $percent) { global $mysoc,$user; - + include_once(DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php'); // Cap percentages to 100 @@ -3555,6 +3555,10 @@ class Facture extends CommonInvoice $prodids[$i] = $row[0]; } } + //Avoid php warning Warning: mt_rand(): max(0) is smaller than min(1) when no product exists + if (empty($num_prods)) { + $num_prods=1; + } // Initialize parameters $this->id=0; @@ -3788,7 +3792,7 @@ class Facture extends CommonInvoice function get_prev_sits() { global $conf; - + $sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . 'facture'; $sql .= ' where situation_cycle_ref = ' . $this->situation_cycle_ref; $sql .= ' and situation_counter < ' . $this->situation_counter; @@ -3818,9 +3822,9 @@ class Facture extends CommonInvoice */ function setFinal() { - + $this->db->begin(); - + $this->situation_final = 1; $sql = 'update ' . MAIN_DB_PREFIX . 'facture set situation_final = ' . $this->situation_final . ' where rowid = ' . $this->id; $resql = $this->db->query($sql); @@ -3845,12 +3849,12 @@ class Facture extends CommonInvoice function is_last_in_cycle() { global $conf; - + if (!empty($this->situation_cycle_ref)) { // No point in testing anything if we're not inside a cycle $sql = 'SELECT max(situation_counter) FROM ' . MAIN_DB_PREFIX . 'facture WHERE situation_cycle_ref = ' . $this->situation_cycle_ref . ' AND entity = ' . ($this->entity > 0 ? $this->entity : $conf->entity); $resql = $this->db->query($sql); - + if ($resql && $resql->num_rows > 0) { $res = $this->db->fetch_array($resql); $last = $res['max(situation_counter)']; @@ -3895,7 +3899,7 @@ class Facture extends CommonInvoice // Paid invoices have status STATUS_CLOSED if ($this->statut != Facture::STATUS_VALIDATED) return false; - + return $this->date_lim_reglement < ($now - $conf->facture->client->warning_delay); } } @@ -3984,7 +3988,7 @@ class FactureLigne extends CommonInvoiceLine var $multicurrency_total_ht; var $multicurrency_total_tva; var $multicurrency_total_ttc; - + /** * Load invoice line from database * @@ -4074,7 +4078,7 @@ class FactureLigne extends CommonInvoiceLine $error=0; $pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'. - + dol_syslog(get_class($this)."::insert rang=".$this->rang, LOG_DEBUG); // Clean parameters @@ -4100,9 +4104,9 @@ class FactureLigne extends CommonInvoiceLine if (empty($this->multicurrency_total_ht)) $this->multicurrency_total_ht=0; if (empty($this->multicurrency_total_tva)) $this->multicurrency_total_tva=0; if (empty($this->multicurrency_total_ttc)) $this->multicurrency_total_ttc=0; - + // if buy price not defined, define buyprice as configured in margin admin - if ($this->pa_ht == 0 && $pa_ht_isemptystring) + if ($this->pa_ht == 0 && $pa_ht_isemptystring) { if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) { @@ -4286,7 +4290,7 @@ class FactureLigne extends CommonInvoiceLine $error=0; $pa_ht_isemptystring = (empty($this->pa_ht) && $this->pa_ht == ''); // If true, we can use a default value. If this->pa_ht = '0', we must use '0'. - + // Clean parameters $this->desc=trim($this->desc); if (empty($this->tva_tx)) $this->tva_tx=0; @@ -4308,7 +4312,7 @@ class FactureLigne extends CommonInvoiceLine if ($this->product_type < 0) return -1; // if buy price not defined, define buyprice as configured in margin admin - if ($this->pa_ht == 0 && $pa_ht_isemptystring) + if ($this->pa_ht == 0 && $pa_ht_isemptystring) { if (($result = $this->defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) { @@ -4355,13 +4359,13 @@ class FactureLigne extends CommonInvoiceLine if (! empty($this->rang)) $sql.= ", rang=".$this->rang; $sql .= ", situation_percent=" . $this->situation_percent; $sql .= ", fk_unit=".(!$this->fk_unit ? 'NULL' : $this->fk_unit); - + // Multicurrency $sql.= " , multicurrency_subprice=".price2num($this->multicurrency_subprice).""; $sql.= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht).""; $sql.= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva).""; $sql.= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc).""; - + $sql.= " WHERE rowid = ".$this->rowid; dol_syslog(get_class($this)."::update", LOG_DEBUG); @@ -4477,7 +4481,7 @@ class FactureLigne extends CommonInvoiceLine /** * Returns situation_percent of the previous line. - * Warning: If invoice is a replacement invoice, this->fk_prev_id is id of the replaced line. + * Warning: If invoice is a replacement invoice, this->fk_prev_id is id of the replaced line. * * @param int $invoiceid Invoice id * @return int >= 0 diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 620047014d4..aa36fa74624 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -444,7 +444,7 @@ abstract class CommonObject global $conf, $langs; $countriesusingstate=array('AU','US','IN','GB','ES','UK','TR'); // See also option MAIN_FORCE_STATE_INTO_ADDRESS - + $contactid=0; $thirdpartyid=0; if ($this->element == 'societe') @@ -461,12 +461,12 @@ abstract class CommonObject $contactid=$this->contact_id; $thirdpartyid=$object->fk_soc; } - + $out=''; - + $outdone=0; $coords = $this->getFullAddress(1,', '); - if ($coords) + if ($coords) { if (! empty($conf->use_javascript_ajax)) { @@ -481,7 +481,7 @@ abstract class CommonObject } if (! in_array($this->country_code,$countriesusingstate) && empty($conf->global->MAIN_FORCE_STATE_INTO_ADDRESS) // If MAIN_FORCE_STATE_INTO_ADDRESS is on, state is already returned previously with getFullAddress - && empty($conf->global->SOCIETE_DISABLE_STATE) && $this->state) + && empty($conf->global->SOCIETE_DISABLE_STATE) && $this->state) { $out.=($outdone?' - ':'').$this->state; $outdone++; @@ -512,15 +512,15 @@ abstract class CommonObject if (! empty($this->office_fax)) { $out.=dol_print_phone($this->fax,$this->country_code,$contactid,$thirdpartyid,'AC_FAX',' ','fax',$langs->trans("Fax")); $outdone++; } - + $out.='
'; $outdone=0; - if (! empty($this->email)) + if (! empty($this->email)) { $out.=dol_print_email($this->email,$this->id,$object->id,'AC_EMAIL',0,0,1); $outdone++; } - if (! empty($this->url)) + if (! empty($this->url)) { $out.=dol_print_url($this->url,'',0,1); $outdone++; @@ -531,12 +531,12 @@ abstract class CommonObject if ($this->skype) $out.=dol_print_skype($this->skype,$this->id,$object->id,'AC_SKYPE'); $outdone++; } - + $out.=''; - + return $out; } - + /** * Add a link between element $this->element and a contact * @@ -592,7 +592,7 @@ abstract class CommonObject } $datecreate = dol_now(); - + $this->db->begin(); // Insertion dans la base @@ -610,9 +610,9 @@ abstract class CommonObject if (! $notrigger) { $result=$this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); - if ($result < 0) - { - $this->db->rollback(); + if ($result < 0) + { + $this->db->rollback(); return -1; } } @@ -883,9 +883,9 @@ abstract class CommonObject if (empty($order)) $order='position'; if ($order == 'position') $order.=',code'; - + $tab = array(); - $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle"; + $sql = "SELECT DISTINCT tc.rowid, tc.code, tc.libelle, tc.position"; $sql.= " FROM ".MAIN_DB_PREFIX."c_type_contact as tc"; $sql.= " WHERE tc.element='".$this->element."'"; if ($activeonly == 1) $sql.= " AND tc.active=1"; // only the active types @@ -1196,7 +1196,7 @@ abstract class CommonObject if (!empty($id) && !empty($field) && !empty($table)) { $sql = "SELECT ".$field." FROM ".MAIN_DB_PREFIX.$table; $sql.= " WHERE rowid = ".$id; - + dol_syslog(get_class($this).'::getValueFrom', LOG_DEBUG); $resql = $this->db->query($sql); if ($resql) @@ -1428,7 +1428,7 @@ abstract class CommonObject if ($this->statut >= 0 || $this->element == 'societe') { $fieldname = 'multicurrency_code'; - + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql .= ' SET '.$fieldname.' = "'.$this->db->escape($code).'"'; $sql .= ' WHERE rowid='.$this->id; @@ -1436,10 +1436,10 @@ abstract class CommonObject if ($this->db->query($sql)) { $this->multicurrency_code = $code; - + list($fk_multicurrency, $rate) = MultiCurrency::getIdAndTxFromCode($this->db, $code); if ($rate) $this->setMulticurrencyRate($rate); - + return 1; } else @@ -1456,7 +1456,7 @@ abstract class CommonObject return -2; } } - + /** * Change the multicurrency rate * @@ -1469,7 +1469,7 @@ abstract class CommonObject if ($this->statut >= 0 || $this->element == 'societe') { $fieldname = 'multicurrency_tx'; - + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; $sql .= ' SET '.$fieldname.' = '.$rate; $sql .= ' WHERE rowid='.$this->id; @@ -1477,11 +1477,11 @@ abstract class CommonObject if ($this->db->query($sql)) { $this->multicurrency_tx = $rate; - + // Update line price if (!empty($this->lines)) { - foreach ($this->lines as &$line) + foreach ($this->lines as &$line) { switch ($this->element) { case 'propal': @@ -1503,10 +1503,10 @@ abstract class CommonObject dol_syslog(get_class($this).'::setMulticurrencyRate no updateline defined', LOG_DEBUG); break; } - + } } - + return 1; } else @@ -2244,7 +2244,7 @@ abstract class CommonObject $this->total_localtax1 += $obj->total_localtax1; $this->total_localtax2 += $obj->total_localtax2; $this->total_ttc += $obj->total_ttc; - + if (! isset($total_ht_by_vats[$obj->vatrate])) $total_ht_by_vats[$obj->vatrate]=0; if (! isset($total_tva_by_vats[$obj->vatrate])) $total_tva_by_vats[$obj->vatrate]=0; if (! isset($total_ttc_by_vats[$obj->vatrate])) $total_ttc_by_vats[$obj->vatrate]=0; @@ -2290,12 +2290,12 @@ abstract class CommonObject $this->total_ttc -= $sit->total_ttc; } } - + // Multicurrency $this->multicurrency_total_ht += $this->total_ht * $multicurrency_tx; $this->multicurrency_total_tva += $this->total_tva * $multicurrency_tx; $this->multicurrency_total_ttc += $this->total_ttc * $multicurrency_tx; - + $this->db->free($resql); // Now update global field total_ht, total_ttc and tva @@ -2398,8 +2398,8 @@ abstract class CommonObject * - all parameters empty -> we look all link to current object (current object can be source or target) * - one couple id+type is provided -> this will set $justsource or $justtarget * - one couple id+type is provided and other type is provided -> this will set $justsource or $justtarget + criteria on other type - * - * + * + * * @param int $sourceid Object source id (if not defined, id of object) * @param string $sourcetype Object source type (if not defined, element name of object) * @param int $targetid Object target id (if not defined, id of object) @@ -2508,7 +2508,7 @@ abstract class CommonObject { // Parse element/subelement (ex: project_task) $module = $element = $subelement = $objecttype; - if ($objecttype != 'supplier_proposal' && $objecttype != 'order_supplier' && $objecttype != 'invoice_supplier' + if ($objecttype != 'supplier_proposal' && $objecttype != 'order_supplier' && $objecttype != 'invoice_supplier' && preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs)) { $module = $element = $regs[1]; @@ -2544,10 +2544,10 @@ abstract class CommonObject else if ($objecttype == 'subscription') { $classpath = 'adherents/class'; $module = 'adherent'; } - + // Set classfile $classfile = strtolower($subelement); $classname = ucfirst($subelement); - + if ($objecttype == 'invoice_supplier') { $classfile = 'fournisseur.facture'; $classname = 'FactureFournisseur'; } @@ -2563,7 +2563,7 @@ abstract class CommonObject else if ($objecttype == 'subscription') { $classfile = 'cotisation'; $classname = 'Cotisation'; } - + // Here $module, $classfile and $classname are set if ($conf->$module->enabled && (($element != $this->element) || $alsosametype)) { @@ -2936,7 +2936,7 @@ abstract class CommonObject return price2num($total_discount); } - + /** * Return into unit=0, the calculated total of weight and volume of all lines * qty * Calculate by adding weight and volume of each product line, so properties ->volume/volume_units/weight/weight_units must be loaded on line. @@ -2951,13 +2951,13 @@ abstract class CommonObject $totalVolume = ''; $totalOrdered = ''; // defined for shipment only $totalToShip = ''; // defined for shipment only - + foreach ($this->lines as $line) { - + $totalOrdered+=$line->qty_asked; // defined for shipment only $totalToShip+=$line->qty_shipped; // defined for shipment only - + // Define qty, weight, volume, weight_units, volume_units if ($this->element == 'shipping') $qty=$line->qty_shipped; // for shipments else $qty=$line->qty; @@ -2965,12 +2965,12 @@ abstract class CommonObject $volume=$line->volume; $weight_units=$line->weight_units; $volume_units=$line->volume_units; - + $weightUnit=0; $volumeUnit=0; if (! empty($weight_units)) $weightUnit = $weight_units; if (! empty($volume_units)) $volumeUnit = $volume_units; - + //var_dump($line->volume_units); if ($weight_units < 50) // >50 means a standard unit (power of 10 of official unit) > 50 means an exotic unit (like inch) { @@ -2993,11 +2993,11 @@ abstract class CommonObject $totalVolume += $volume * $qty; // This may be wrong if we mix different units } } - + return array('weight'=>$totalWeight, 'volume'=>$totalVolume, 'ordered'=>$totalOrdered, 'toship'=>$totalToShip); - } - - + } + + /** * Set extra parameters * @@ -3267,7 +3267,7 @@ abstract class CommonObject // Multicurrency if (!empty($conf->multicurrency->enabled)) print '
'.$langs->trans('PriceUHTCurrency').''.$langs->trans('PriceUTTC').'
'.$langs->trans("CustomCode").'