From 7f1adc6a6ab53fce7e3a5d7f910cd90109ffc27e Mon Sep 17 00:00:00 2001 From: Ferran Marcet Date: Tue, 7 Nov 2017 09:46:39 +0100 Subject: [PATCH 001/177] FIX: Saving wrong localtax on order addline --- htdocs/commande/class/commande.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index c326efa7e49..0ea9302b221 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -1360,8 +1360,8 @@ class Commande extends CommonOrder $this->line->vat_src_code=$vat_src_code; $this->line->tva_tx=$txtva; - $this->line->localtax1_tx=$localtaxes_type[1]; - $this->line->localtax2_tx=$localtaxes_type[3]; + $this->line->localtax1_tx=$txlocaltax1; + $this->line->localtax2_tx=$txlocaltax2; $this->line->localtax1_type=$localtaxes_type[0]; $this->line->localtax2_type=$localtaxes_type[2]; $this->line->fk_product=$fk_product; From 4874d08062ed78dc66ea3bb6e24e5431b5644f05 Mon Sep 17 00:00:00 2001 From: De Coninck Laurent Date: Fri, 19 Jan 2018 08:59:04 +0100 Subject: [PATCH 002/177] fix the bill replacement with discounts #8028 --- htdocs/compta/facture/class/facture.class.php | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 3c35a03f218..748f83f5a53 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -539,6 +539,15 @@ class Facture extends CommonInvoice } $newinvoiceline->fk_parent_line=$fk_parent_line; + + if($newinvoiceline->fk_remise_except){ + $discount = new DiscountAbsolute($this->db); + $discount->fetch($newinvoiceline->fk_remise_except); + + $discountId = $soc->set_remise_except($discount->amount_ht, $user, $discount->description, $discount->tva_tx); + $newinvoiceline->fk_remise_except = $discountId; + } + $result=$newinvoiceline->insert(); // Defined the new fk_parent_line From 53ac13c792dddc0cbd073ea25657900a323d6dc6 Mon Sep 17 00:00:00 2001 From: De Coninck Laurent Date: Tue, 23 Jan 2018 18:03:29 +0100 Subject: [PATCH 003/177] check on type replacement #8028 --- htdocs/compta/facture/class/facture.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 748f83f5a53..72285e87808 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -540,7 +540,7 @@ class Facture extends CommonInvoice $newinvoiceline->fk_parent_line=$fk_parent_line; - if($newinvoiceline->fk_remise_except){ + if($this->type === Facture::TYPE_REPLACEMENT && $newinvoiceline->fk_remise_except){ $discount = new DiscountAbsolute($this->db); $discount->fetch($newinvoiceline->fk_remise_except); From 2147bd23e64da09d96fc2a44395aa4293a2ab427 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 2 Feb 2018 10:22:47 +0100 Subject: [PATCH 004/177] Fix: remove lines with special code when convert to reduc --- htdocs/compta/facture.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index b5b200aa540..5fcd2d05aee 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -611,7 +611,7 @@ if (empty($reshook)) $i = 0; foreach ($object->lines as $line) { - if ($line->total_ht!=0) + if (empty($line->special_code) && $line->total_ht != 0) // Remove lines with special code { // no need to create discount if amount is null $amount_ht[$line->tva_tx] += $line->total_ht; $amount_tva[$line->tva_tx] += $line->total_tva; From a161ca37ffe23e530870f5fb83522910d075fff6 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sun, 4 Feb 2018 08:58:31 +0100 Subject: [PATCH 005/177] Fix: use product_type instead special_code --- htdocs/compta/facture.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 5fcd2d05aee..63b8f2a102b 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -611,7 +611,7 @@ if (empty($reshook)) $i = 0; foreach ($object->lines as $line) { - if (empty($line->special_code) && $line->total_ht != 0) // Remove lines with special code + if (empty($line->product_type >= 9) && $line->total_ht != 0) // Remove lines with product_type greater than or equal to 9 { // no need to create discount if amount is null $amount_ht[$line->tva_tx] += $line->total_ht; $amount_tva[$line->tva_tx] += $line->total_tva; From d5b7184c8d501e6d4e8b83afeed36027eed9a2c6 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sun, 4 Feb 2018 09:04:15 +0100 Subject: [PATCH 006/177] Fix: wrong test --- htdocs/compta/facture.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 63b8f2a102b..39d603a6c5e 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -611,7 +611,7 @@ if (empty($reshook)) $i = 0; foreach ($object->lines as $line) { - if (empty($line->product_type >= 9) && $line->total_ht != 0) // Remove lines with product_type greater than or equal to 9 + if ($line->product_type < 9 && $line->total_ht != 0) // Remove lines with product_type greater than or equal to 9 { // no need to create discount if amount is null $amount_ht[$line->tva_tx] += $line->total_ht; $amount_tva[$line->tva_tx] += $line->total_tva; From ae9c7ad6b6b9668dddf46e9692053049735dd3b5 Mon Sep 17 00:00:00 2001 From: atm-quentin Date: Mon, 5 Feb 2018 10:40:52 +0100 Subject: [PATCH 007/177] FIX unset categorie --- htdocs/societe/card.php | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 4807591b9f3..a5ad6f2e270 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -519,15 +519,15 @@ if (empty($reshook)) $error=$object->error; $errors=$object->errors; } } + if(!empty($user->rights->categorie->creer)){ + // Customer categories association + $custcats = GETPOST( 'custcats', 'array' ); + $object->setCategories($custcats, 'customer'); - // Customer categories association - $custcats = GETPOST( 'custcats', 'array' ); - $object->setCategories($custcats, 'customer'); - - // Supplier categories association - $suppcats = GETPOST('suppcats', 'array'); - $object->setCategories($suppcats, 'supplier'); - + // Supplier categories association + $suppcats = GETPOST('suppcats', 'array'); + $object->setCategories($suppcats, 'supplier'); + } // Logo/Photo save $dir = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos/"; $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']); From 839de650121b330daed69476aec3baae58b2a68f Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 5 Feb 2018 11:30:31 +0100 Subject: [PATCH 008/177] Fix: avoid error -1 --- htdocs/core/class/commonobject.class.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index fa59659ab31..e9498d52d7d 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -1210,7 +1210,10 @@ abstract class CommonObject if ($resql) { $row = $this->db->fetch_row($resql); - $result = $this->fetch($row[0]); + // Test for avoid error -1 + if ($row[0] > 0) { + $result = $this->fetch($row[0]); + } } return $result; From bb93b98260dc2de3a82f37df1b424866877849c7 Mon Sep 17 00:00:00 2001 From: atm-quentin Date: Mon, 5 Feb 2018 15:25:49 +0100 Subject: [PATCH 009/177] NEW field commerciaux and categ export CustomersInvoicesAndPayments --- htdocs/core/modules/modFacture.class.php | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/htdocs/core/modules/modFacture.class.php b/htdocs/core/modules/modFacture.class.php index 40e2a03d161..9c71ddea1d1 100644 --- a/htdocs/core/modules/modFacture.class.php +++ b/htdocs/core/modules/modFacture.class.php @@ -248,16 +248,19 @@ class modFacture extends DolibarrModules $this->export_label[$r]='CustomersInvoicesAndPayments'; // Translation key (used only if key ExportDataset_xxx_z not found) $this->export_icon[$r]='invoice'; $this->export_permission[$r]=array(array("facture","facture","export")); - $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','c.code'=>'CountryCode','s.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode','s.code_compta_fournisseur'=>'SupplierAccountancyCode','s.tva_intra'=>'VATIntra','f.rowid'=>"InvoiceId",'f.facnumber'=>"InvoiceRef",'f.type'=>"Type",'f.datec'=>"InvoiceDateCreation",'f.datef'=>"DateInvoice",'f.date_lim_reglement'=>"DateDue",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'none.rest'=>'Rest','f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus','f.note_private'=>"NotePrivate",'f.note_public'=>"NotePublic",'f.fk_user_author'=>'CreatedById','uc.login'=>'CreatedByLogin','f.fk_user_valid'=>'ValidatedById','uv.login'=>'ValidatedByLogin','pj.ref'=>'ProjectRef','p.rowid'=>'PaymentId','p.ref'=>'PaymentRef','p.amount'=>'AmountPayment','pf.amount'=>'AmountPaymentDistributedOnInvoice','p.datep'=>'DatePayment','p.num_paiement'=>'PaymentNumber','pt.code'=>'CodePaymentMode','pt.libelle'=>'LabelPaymentMode','p.note'=>'PaymentNote','p.fk_bank'=>'IdTransaction','ba.ref'=>'AccountRef'); - $this->export_TypeFields_array[$r]=array('s.rowid'=>'Numeric','s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','c.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.code_compta'=>'Text','s.code_compta_fournisseur'=>'Text','s.tva_intra'=>'Text','f.rowid'=>"Numeric",'f.facnumber'=>"Text",'f.type'=>"Numeric",'f.datec'=>"Date",'f.datef'=>"Date",'f.date_lim_reglement'=>"Date",'f.total'=>"Numeric",'f.total_ttc'=>"Numeric",'f.tva'=>"Numeric",'none.rest'=>'NumericCompute','f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_private'=>"Text",'f.note_public'=>"Text",'f.fk_user_author'=>'Numeric','uc.login'=>'Text','f.fk_user_valid'=>'Numeric','uv.login'=>'Text','pj.ref'=>'Text','p.amount'=>'Numeric','pf.amount'=>'Numeric','p.rowid'=>'Numeric','p.ref'=>'Text','p.datep'=>'Date','p.num_paiement'=>'Numeric','p.fk_bank'=>'Numeric','p.note'=>'Text','pt.code'=>'Text','pt.libelle'=>'text','ba.ref'=>'Text'); - $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','c.code'=>'company','s.phone'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company','s.tva_intra'=>'company','pj.ref'=>'project','p.rowid'=>'payment','p.ref'=>'payment','p.amount'=>'payment','pf.amount'=>'payment','p.datep'=>'payment','p.num_paiement'=>'payment','pt.code'=>'payment','pt.libelle'=>'payment','p.note'=>'payment','f.fk_user_author'=>'user','uc.login'=>'user','f.fk_user_valid'=>'user','uv.login'=>'user','p.fk_bank'=>'account','ba.ref'=>'account'); + $this->export_fields_array[$r]=array('s.rowid'=>"IdCompany",'s.nom'=>'CompanyName','s.address'=>'Address','s.zip'=>'Zip','s.town'=>'Town','ucomm.lastname'=>'SalesRepresentatives','cat.label'=>'Category','c.code'=>'CountryCode','s.phone'=>'Phone','s.siren'=>'ProfId1','s.siret'=>'ProfId2','s.ape'=>'ProfId3','s.idprof4'=>'ProfId4','s.code_compta'=>'CustomerAccountancyCode','s.code_compta_fournisseur'=>'SupplierAccountancyCode','s.tva_intra'=>'VATIntra','f.rowid'=>"InvoiceId",'f.facnumber'=>"InvoiceRef",'f.type'=>"Type",'f.datec'=>"InvoiceDateCreation",'f.datef'=>"DateInvoice",'f.date_lim_reglement'=>"DateDue",'f.total'=>"TotalHT",'f.total_ttc'=>"TotalTTC",'f.tva'=>"TotalVAT",'none.rest'=>'Rest','f.paye'=>"InvoicePaid",'f.fk_statut'=>'InvoiceStatus','f.note_private'=>"NotePrivate",'f.note_public'=>"NotePublic",'f.fk_user_author'=>'CreatedById','uc.login'=>'CreatedByLogin','f.fk_user_valid'=>'ValidatedById','uv.login'=>'ValidatedByLogin','pj.ref'=>'ProjectRef','p.rowid'=>'PaymentId','p.ref'=>'PaymentRef','p.amount'=>'AmountPayment','pf.amount'=>'AmountPaymentDistributedOnInvoice','p.datep'=>'DatePayment','p.num_paiement'=>'PaymentNumber','pt.code'=>'CodePaymentMode','pt.libelle'=>'LabelPaymentMode','p.note'=>'PaymentNote','p.fk_bank'=>'IdTransaction','ba.ref'=>'AccountRef'); + $this->export_TypeFields_array[$r]=array('s.rowid'=>'Numeric','s.nom'=>'Text','s.address'=>'Text','s.zip'=>'Text','s.town'=>'Text','ucomm.lastname'=>'Text','cat.label'=>'Text','c.code'=>'Text','s.phone'=>'Text','s.siren'=>'Text','s.siret'=>'Text','s.ape'=>'Text','s.idprof4'=>'Text','s.code_compta'=>'Text','s.code_compta_fournisseur'=>'Text','s.tva_intra'=>'Text','f.rowid'=>"Numeric",'f.facnumber'=>"Text",'f.type'=>"Numeric",'f.datec'=>"Date",'f.datef'=>"Date",'f.date_lim_reglement'=>"Date",'f.total'=>"Numeric",'f.total_ttc'=>"Numeric",'f.tva'=>"Numeric",'none.rest'=>'NumericCompute','f.paye'=>"Boolean",'f.fk_statut'=>'Status','f.note_private'=>"Text",'f.note_public'=>"Text",'f.fk_user_author'=>'Numeric','uc.login'=>'Text','f.fk_user_valid'=>'Numeric','uv.login'=>'Text','pj.ref'=>'Text','p.amount'=>'Numeric','pf.amount'=>'Numeric','p.rowid'=>'Numeric','p.ref'=>'Text','p.datep'=>'Date','p.num_paiement'=>'Numeric','p.fk_bank'=>'Numeric','p.note'=>'Text','pt.code'=>'Text','pt.libelle'=>'text','ba.ref'=>'Text'); + $this->export_entities_array[$r]=array('s.rowid'=>"company",'s.nom'=>'company','s.address'=>'company','s.zip'=>'company','s.town'=>'company','ucomm.lastname'=>'company','cat.label'=>'company','c.code'=>'company','s.phone'=>'company','s.siren'=>'company','s.siret'=>'company','s.ape'=>'company','s.idprof4'=>'company','s.code_compta'=>'company','s.code_compta_fournisseur'=>'company','s.tva_intra'=>'company','pj.ref'=>'project','p.rowid'=>'payment','p.ref'=>'payment','p.amount'=>'payment','pf.amount'=>'payment','p.datep'=>'payment','p.num_paiement'=>'payment','pt.code'=>'payment','pt.libelle'=>'payment','p.note'=>'payment','f.fk_user_author'=>'user','uc.login'=>'user','f.fk_user_valid'=>'user','uv.login'=>'user','p.fk_bank'=>'account','ba.ref'=>'account'); $this->export_special_array[$r]=array('none.rest'=>'getRemainToPay'); $this->export_dependencies_array[$r]=array('payment'=>'p.rowid', 'none.rest'=>array('f.rowid','f.total_ttc')); // To add unique key if we ask a field of a child to avoid the DISTINCT to discard them $keyforselect='facture'; $keyforelement='invoice'; $keyforaliasextra='extra'; include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; - if (empty($user->rights->societe->client->voir)) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'user as ucomm ON sc.fk_user = ucomm.rowid'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_societe as cs ON cs.fk_soc = s.rowid'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'categorie as cat ON cs.fk_categorie = cat.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture as f'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid'; From 2081aefc84cf1156527c09b7e827b500423a4f00 Mon Sep 17 00:00:00 2001 From: atm-quentin Date: Mon, 5 Feb 2018 16:07:08 +0100 Subject: [PATCH 010/177] FIX creer into lire --- htdocs/societe/card.php | 34 ++++++++++++++++++---------------- 1 file changed, 18 insertions(+), 16 deletions(-) diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index a5ad6f2e270..611abc9b704 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -519,15 +519,16 @@ if (empty($reshook)) $error=$object->error; $errors=$object->errors; } } - if(!empty($user->rights->categorie->creer)){ - // Customer categories association - $custcats = GETPOST( 'custcats', 'array' ); - $object->setCategories($custcats, 'customer'); + + + // Customer categories association + $custcats = GETPOST( 'custcats', 'array' ); + $object->setCategories($custcats, 'customer'); - // Supplier categories association - $suppcats = GETPOST('suppcats', 'array'); - $object->setCategories($suppcats, 'supplier'); - } + // Supplier categories association + $suppcats = GETPOST('suppcats', 'array'); + $object->setCategories($suppcats, 'supplier'); + // Logo/Photo save $dir = $conf->societe->multidir_output[$conf->entity]."/".$object->id."/logos/"; $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']); @@ -634,15 +635,16 @@ if (empty($reshook)) { $error = $object->error; $errors = $object->errors; } + //Prevent thirdparty's emptying if a user hasn't rights $user->rights->categorie->lire + if(!empty($user->rights->categorie->lire)){ + // Customer categories association + $categories = GETPOST( 'custcats', 'array' ); + $object->setCategories($categories, 'customer'); - // Customer categories association - $categories = GETPOST( 'custcats', 'array' ); - $object->setCategories($categories, 'customer'); - - // Supplier categories association - $categories = GETPOST('suppcats', 'array'); - $object->setCategories($categories, 'supplier'); - + // Supplier categories association + $categories = GETPOST('suppcats', 'array'); + $object->setCategories($categories, 'supplier'); + } // Logo/Photo save $dir = $conf->societe->multidir_output[$object->entity]."/".$object->id."/logos"; $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']); From 9b5655596249c3e0367f63d44e4d9f8e59da95ca Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Tue, 6 Feb 2018 18:49:29 +0100 Subject: [PATCH 011/177] FIX: Withdrawals lines not filter by company name and not respect dropdown limit lines by page --- htdocs/compta/prelevement/list.php | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/htdocs/compta/prelevement/list.php b/htdocs/compta/prelevement/list.php index 245903101cf..ff6fe4e109c 100644 --- a/htdocs/compta/prelevement/list.php +++ b/htdocs/compta/prelevement/list.php @@ -2,7 +2,7 @@ /* Copyright (C) 2005 Rodolphe Quiedeville * Copyright (C) 2005-2016 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin - * Copyright (C) 2010-2012 Juanjo Menent + * Copyright (C) 2010-2018 Juanjo Menent * * 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 @@ -101,7 +101,7 @@ if ($socid) $sql.= " AND s.rowid = ".$socid; if ($search_line) $sql.= " AND pl.rowid = '".$db->escape($search_line)."'"; if ($search_bon) $sql.= natural_search("p.ref", $search_bon); if ($search_code) $sql.= natural_search("s.code_client", $search_code); -if ($search_company) natural_search("s.nom", $search_company); +if ($search_company) $sql.= natural_search("s.nom", $search_company); $sql.= $db->order($sortfield,$sortorder); @@ -123,13 +123,14 @@ if ($result) $urladd = "&statut=".$statut; $urladd .= "&search_bon=".$search_bon; - - print_barre_liste($langs->trans("WithdrawalsLines"), $page, $_SERVER["PHP_SELF"], $urladd, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_generic', 0, '', '', $limit); + if ($limit > 0 && $limit != $conf->liste_limit) $urladd.='&limit='.urlencode($limit); print"\n\n"; print '
'; - $moreforfilter=''; + print_barre_liste($langs->trans("WithdrawalsLines"), $page, $_SERVER["PHP_SELF"], $urladd, $sortfield, $sortorder, '', $num, $nbtotalofrecords, 'title_generic', 0, '', '', $limit); + + $moreforfilter=''; print '
'; print ''."\n"; From 8b7f40e15bb64ad97d78c75142acc339ccdd0540 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 6 Feb 2018 19:29:16 +0100 Subject: [PATCH 012/177] Fix: wrong id name --- htdocs/user/class/usergroup.class.php | 12 ++++++------ htdocs/user/group/index.php | 10 +++++----- htdocs/user/home.php | 6 +++--- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/htdocs/user/class/usergroup.class.php b/htdocs/user/class/usergroup.class.php index 1c9ede28d94..efb0beceafd 100644 --- a/htdocs/user/class/usergroup.class.php +++ b/htdocs/user/class/usergroup.class.php @@ -1,10 +1,10 @@ - * Copyright (c) 2005-2013 Laurent Destailleur - * Copyright (c) 2005-2012 Regis Houssin - * Copyright (C) 2012 Florian Henry - * Copyright (C) 2014 Juanjo Menent - * Copyright (C) 2014 Alexis Algoud +/* Copyright (c) 2005 Rodolphe Quiedeville + * Copyright (c) 2005-2018 Laurent Destailleur + * Copyright (c) 2005-2018 Regis Houssin + * Copyright (C) 2012 Florian Henry + * Copyright (C) 2014 Juanjo Menent + * Copyright (C) 2014 Alexis Algoud * * 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 diff --git a/htdocs/user/group/index.php b/htdocs/user/group/index.php index 0fcd2af98f2..284a7fb289a 100644 --- a/htdocs/user/group/index.php +++ b/htdocs/user/group/index.php @@ -1,8 +1,8 @@ - * Copyright (C) 2004-2011 Laurent Destailleur - * Copyright (C) 2005-2017 Regis Houssin - * Copyright (C) 2011 Herve Prot +/* Copyright (C) 2002-2003 Rodolphe Quiedeville + * Copyright (C) 2004-2018 Laurent Destailleur + * Copyright (C) 2005-2018 Regis Houssin + * Copyright (C) 2011 Herve Prot * * 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 @@ -181,7 +181,7 @@ if ($resql) { $obj = $db->fetch_object($resql); - $grouptemp->id = $obj->id; + $grouptemp->id = $obj->rowid; $grouptemp->name = $obj->name; $grouptemp->note = $obj->note; diff --git a/htdocs/user/home.php b/htdocs/user/home.php index 620954553fb..6600d262002 100644 --- a/htdocs/user/home.php +++ b/htdocs/user/home.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005-2015 Regis Houssin +/* Copyright (C) 2005-2018 Laurent Destailleur + * Copyright (C) 2005-2018 Regis Houssin * * 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 @@ -240,7 +240,7 @@ if ($canreadperms) { $obj = $db->fetch_object($resql); - $grouptemp->id = $obj->id; + $grouptemp->id = $obj->rowid; $grouptemp->name = $obj->name; $grouptemp->note = $obj->note; From 6254e20c676319e0b29dc2bd5262644270af32dd Mon Sep 17 00:00:00 2001 From: atm-ph Date: Wed, 7 Feb 2018 15:33:40 +0100 Subject: [PATCH 013/177] Fix position if module use pdf hook "linkedobjects" --- .../commande/doc/pdf_einstein.modules.php | 22 +++++++++++++------ .../modules/facture/doc/pdf_crabe.modules.php | 20 ++++++++++++----- .../modules/propale/doc/pdf_azur.modules.php | 22 +++++++++++++------ 3 files changed, 45 insertions(+), 19 deletions(-) diff --git a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php index 7e9535fb48c..5d07085378b 100644 --- a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php @@ -293,16 +293,17 @@ class pdf_einstein extends ModelePDFCommandes $pdf->AddPage(); if (! empty($tplidx)) $pdf->useTemplate($tplidx); $pagenb++; - $this->_pagehead($pdf, $object, 1, $outputlangs); + $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs); $pdf->SetFont('','', $default_font_size - 1); $pdf->MultiCell(0, 3, ''); // Set interline to 3 $pdf->SetTextColor(0,0,0); - $tab_top = 90; - $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10); - $tab_height = 130; + $tab_top = 90+$top_shift; + $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42+$top_shift:10); + $tab_height = 130-$top_shift; $tab_height_newpage = 150; + if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $tab_height_newpage -= $top_shift; // Incoterm $height_incoterms = 0; @@ -1298,16 +1299,22 @@ class pdf_einstein extends ModelePDFCommandes $posy+=2; + $top_shift = 0; // Show list of linked objects + $current_y = $pdf->getY(); $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size); - + if ($current_y < $pdf->getY()) + { + $top_shift = $pdf->getY() - $current_y; + } + if ($showaddress) { // Sender properties $carac_emetteur = pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty); // Show sender - $posy=42; + $posy=42+$top_shift; $posx=$this->marge_gauche; if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80; $hautcadre=40; @@ -1359,7 +1366,7 @@ class pdf_einstein extends ModelePDFCommandes // Show recipient $widthrecbox=100; if ($this->page_largeur < 210) $widthrecbox=84; // To work with US executive format - $posy=42; + $posy=42+$top_shift; $posx=$this->page_largeur-$this->marge_droite-$widthrecbox; if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche; @@ -1384,6 +1391,7 @@ class pdf_einstein extends ModelePDFCommandes } $pdf->SetTextColor(0,0,0); + return $top_shift; } /** diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index d4872b000de..de0b126b059 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -331,15 +331,16 @@ class pdf_crabe extends ModelePDFFactures if (! empty($tplidx)) $pdf->useTemplate($tplidx); $pagenb++; - $this->_pagehead($pdf, $object, 1, $outputlangs); + $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs); $pdf->SetFont('','', $default_font_size - 1); $pdf->MultiCell(0, 3, ''); // Set interline to 3 $pdf->SetTextColor(0,0,0); - $tab_top = 90; - $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10); - $tab_height = 130; + $tab_top = 90+$top_shift; + $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42+$top_shift:10); + $tab_height = 130-$top_shift; $tab_height_newpage = 150; + if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $tab_height_newpage -= $top_shift; // Incoterm $height_incoterms = 0; @@ -1670,9 +1671,15 @@ class pdf_crabe extends ModelePDFFactures $posy+=1; + $top_shift = 0; // Show list of linked objects + $current_y = $pdf->getY(); $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, $w, 3, 'R', $default_font_size); - + if ($current_y < $pdf->getY()) + { + $top_shift = $pdf->getY() - $current_y; + } + if ($showaddress) { // Sender properties @@ -1680,6 +1687,7 @@ class pdf_crabe extends ModelePDFFactures // Show sender $posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42; + $posy+=$top_shift; $posx=$this->marge_gauche; if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80; @@ -1735,6 +1743,7 @@ class pdf_crabe extends ModelePDFFactures $widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100; if ($this->page_largeur < 210) $widthrecbox=84; // To work with US executive format $posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42; + $posy+=$top_shift; $posx=$this->page_largeur-$this->marge_droite-$widthrecbox; if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche; @@ -1759,6 +1768,7 @@ class pdf_crabe extends ModelePDFFactures } $pdf->SetTextColor(0,0,0); + return $top_shift; } /** diff --git a/htdocs/core/modules/propale/doc/pdf_azur.modules.php b/htdocs/core/modules/propale/doc/pdf_azur.modules.php index 604940b017e..b2a0a522cc9 100644 --- a/htdocs/core/modules/propale/doc/pdf_azur.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_azur.modules.php @@ -329,16 +329,17 @@ class pdf_azur extends ModelePDFPropales $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) //print $heightforinfotot + $heightforsignature + $heightforfreetext + $heightforfooter;exit; - $this->_pagehead($pdf, $object, 1, $outputlangs); + $top_shift = $this->_pagehead($pdf, $object, 1, $outputlangs); $pdf->SetFont('','', $default_font_size - 1); $pdf->MultiCell(0, 3, ''); // Set interline to 3 $pdf->SetTextColor(0,0,0); - $tab_top = 90; - $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10); - $tab_height = 130; + $tab_top = 90+$top_shift; + $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42+$top_shift:10); + $tab_height = 130-$top_shift; $tab_height_newpage = 150; + if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $tab_height_newpage -= $top_shift; // Incoterm $height_incoterms = 0; @@ -1484,9 +1485,15 @@ class pdf_azur extends ModelePDFPropales $posy+=2; + $top_shift = 0; // Show list of linked objects + $current_y = $pdf->getY(); $posy = pdf_writeLinkedObjects($pdf, $object, $outputlangs, $posx, $posy, 100, 3, 'R', $default_font_size); - + if ($current_y < $pdf->getY()) + { + $top_shift = $pdf->getY() - $current_y; + } + if ($showaddress) { // Sender properties @@ -1503,7 +1510,7 @@ class pdf_azur extends ModelePDFPropales $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty); // Show sender - $posy=42; + $posy=42+$top_shift; $posx=$this->marge_gauche; if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80; $hautcadre=40; @@ -1554,7 +1561,7 @@ class pdf_azur extends ModelePDFPropales // Show recipient $widthrecbox=100; if ($this->page_largeur < 210) $widthrecbox=84; // To work with US executive format - $posy=42; + $posy=42+$top_shift; $posx=$this->page_largeur-$this->marge_droite-$widthrecbox; if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche; @@ -1579,6 +1586,7 @@ class pdf_azur extends ModelePDFPropales } $pdf->SetTextColor(0,0,0); + return $top_shift; } /** From 879308e0ef5e986e9f7d60c0c12a7f8780c90d53 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 8 Feb 2018 10:15:53 +0100 Subject: [PATCH 014/177] Fix responsive --- htdocs/core/tpl/login.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/tpl/login.tpl.php b/htdocs/core/tpl/login.tpl.php index 0deca9be98d..e3dc94cd30e 100644 --- a/htdocs/core/tpl/login.tpl.php +++ b/htdocs/core/tpl/login.tpl.php @@ -270,7 +270,7 @@ if (!empty($conf->global->MAIN_EASTER_EGG_COMMITSTRIP)) { { $xml = simplexml_load_string($resgetcommitstrip['content']); $little = $xml->channel->item[0]->children('content',true); - print $little->encoded; + print preg_replace('/width="650" height="658"/', '', $little->encoded); } } From a26bb2d884220a0093f82f1f7155771bdc89a252 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 8 Feb 2018 12:41:31 +0100 Subject: [PATCH 015/177] FIX #8151 --- htdocs/fichinter/class/fichinter.class.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index fb2359092a0..13eb2e74d7d 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -1169,6 +1169,8 @@ class Fichinter extends CommonObject */ function fetch_lines() { + $this->lines = array(); + $sql = 'SELECT rowid, description, duree, date, rang'; $sql.= ' FROM '.MAIN_DB_PREFIX.'fichinterdet'; $sql.=' WHERE fk_fichinter = '.$this->id .' ORDER BY rang ASC, date ASC' ; From 3f17c92aa3550b1131205e15b8c519c444821d17 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 8 Feb 2018 13:09:21 +0100 Subject: [PATCH 016/177] Update card.php --- htdocs/societe/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/card.php b/htdocs/societe/card.php index 611abc9b704..d3f629952b1 100644 --- a/htdocs/societe/card.php +++ b/htdocs/societe/card.php @@ -635,7 +635,7 @@ if (empty($reshook)) { $error = $object->error; $errors = $object->errors; } - //Prevent thirdparty's emptying if a user hasn't rights $user->rights->categorie->lire + // Prevent thirdparty's emptying if a user hasn't rights $user->rights->categorie->lire (in such a case, post of 'custcats' is not defined) if(!empty($user->rights->categorie->lire)){ // Customer categories association $categories = GETPOST( 'custcats', 'array' ); From 03b10041db412ef53c57a80af61cfd95e68601d8 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 8 Feb 2018 13:27:43 +0100 Subject: [PATCH 017/177] Fix missing contextpage --- htdocs/product/fournisseurs.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index f70dd2b78d9..21d29a8ce89 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -76,6 +76,8 @@ $pagenext = $page + 1; if (! $sortfield) $sortfield="s.nom"; if (! $sortorder) $sortorder="ASC"; +$contextpage='pricesuppliercard'; + // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('pricesuppliercard','globalcard')); From cc20a9d1d580a8b18bd23f631719ab2bce27df48 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 8 Feb 2018 16:13:12 +0100 Subject: [PATCH 018/177] FIX #8079 --- htdocs/compta/bank/bankentries_list.php | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/htdocs/compta/bank/bankentries_list.php b/htdocs/compta/bank/bankentries_list.php index 380392c6805..78e95180dc5 100644 --- a/htdocs/compta/bank/bankentries_list.php +++ b/htdocs/compta/bank/bankentries_list.php @@ -924,6 +924,7 @@ if ($resql) $balance = 0; // For balance $balancecalculated = false; + $posconciliatecol = 0; // Loop on each record $sign = 1; @@ -1347,7 +1348,11 @@ if ($resql) } } print ''; - if (! $i) $totalarray['nbfield']++; + if (! $i) + { + $totalarray['nbfield']++; + $posconciliatecol = $totalarray['nbfield']; + } } if (! empty($arrayfields['b.conciliated']['checked'])) @@ -1430,6 +1435,12 @@ if ($resql) } elseif ($totalarray['totaldebfield'] == $i) print ''; elseif ($totalarray['totalcredfield'] == $i) print ''; + elseif ($i == $posconciliatecol) + { + print ''; + } else print ''; } print ''; From a200a7f149d733a8ab7e0e9062fa2f1854ea59cb Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 8 Feb 2018 16:41:50 +0100 Subject: [PATCH 019/177] Fix look and feel v7 --- htdocs/compta/bank/bankentries_list.php | 56 +++++++++++++++---------- 1 file changed, 33 insertions(+), 23 deletions(-) diff --git a/htdocs/compta/bank/bankentries_list.php b/htdocs/compta/bank/bankentries_list.php index 78e95180dc5..c6baf1c47f1 100644 --- a/htdocs/compta/bank/bankentries_list.php +++ b/htdocs/compta/bank/bankentries_list.php @@ -383,12 +383,14 @@ if (dol_strlen($search_dv_start) > 0) $param .= '&search_start_dvmonth=' . GETPO if (dol_strlen($search_dv_end) > 0) $param .= '&search_end_dvmonth=' . GETPOST('search_end_dvmonth', 'int') . '&search_end_dvday=' . GETPOST('search_end_dvday', 'int') . '&search_end_dvyear=' . GETPOST('search_end_dvyear', 'int'); if ($search_req_nb) $param.='&req_nb='.urlencode($search_req_nb); if (GETPOST("thirdparty")) $param.='&thirdparty='.urlencode(GETPOST("thirdparty")); -if ($optioncss != '') $param.='&optioncss='.$optioncss; +if ($optioncss != '') $param.='&optioncss='.$optioncss; // Add $param from extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php'; $options = array(); +$buttonreconcile = ''; + if ($id > 0 || ! empty($ref)) { $title = $langs->trans("FinancialAccount").' - '.$langs->trans("Transactions"); @@ -420,18 +422,19 @@ if ($id > 0 || ! empty($ref)) if ($action != 'reconcile') { - print '
'; + //print '
'; - if ($object->canBeConciliated() > 0) { + if ($object->canBeConciliated() > 0) + { // If not cash account and can be reconciliate if ($user->rights->banque->consolidate) { - print ''.$langs->trans("Conciliate").''; + $buttonreconcile = ''.$langs->trans("Conciliate").''; } else { - print ''.$langs->trans("Conciliate").''; + $buttonreconcile = ''.$langs->trans("Conciliate").''; } } - print '
'; + //print '
'; } } else @@ -585,7 +588,7 @@ if ($resql) $nbmax=15; // We accept to show last 15 receipts (so we can have more than one year) $liste=""; $sql = "SELECT DISTINCT num_releve FROM ".MAIN_DB_PREFIX."bank"; - $sql.= " WHERE fk_account=".$id." AND num_releve IS NOT NULL"; + $sql.= " WHERE fk_account=".$object->id." AND num_releve IS NOT NULL"; $sql.= $db->order("num_releve","DESC"); $sql.= $db->plimit($nbmax+1); print '

'; @@ -614,17 +617,17 @@ if ($resql) { dol_print_error($db); } - /** - * Using BANK_REPORT_LAST_NUM_RELEVE to automatically report last num (or not) - */ - if ($conf->global->BANK_REPORT_LAST_NUM_RELEVE == 1) { - print ' - - '; - } - print '

'; + + // Using BANK_REPORT_LAST_NUM_RELEVE to automatically report last num (or not) + if ($conf->global->BANK_REPORT_LAST_NUM_RELEVE == 1) + { + print ' + + '; + } + print '

'; } // Form to add a transaction with no invoice @@ -721,11 +724,6 @@ if ($resql) // Title $bankcateg=new BankCateg($db); - $morehtml='
'; - $morehtml.= ' "; // ' Page '; - $morehtml.=''; - $morehtml.='/'.$nbtotalofpages.' '; - $morehtml.='
'; $addbutton = ''; if ($action != 'addline' && $action != 'reconcile') @@ -754,6 +752,18 @@ if ($resql) $addbutton = ''.$langs->trans("AddBankRecord").''; } } + + $morehtml='
'; + $morehtml.= ' "; // ' Page '; + $morehtml.=''; + $morehtml.='/'.$nbtotalofpages.' '; + $morehtml.='
'; + + if ($action != 'addline' && $action != 'reconcile') + { + $morehtml.=$buttonreconcile; + } + $morehtml.=$addbutton; $picto='title_bank'; From 19a0f552c9c944355f78c1f49ee86fe61e98e023 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 8 Feb 2018 16:49:28 +0100 Subject: [PATCH 020/177] Fix td balance --- htdocs/compta/bank/bankentries_list.php | 2 +- htdocs/langs/en_US/errors.lang | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/bank/bankentries_list.php b/htdocs/compta/bank/bankentries_list.php index c6baf1c47f1..692df2fcb22 100644 --- a/htdocs/compta/bank/bankentries_list.php +++ b/htdocs/compta/bank/bankentries_list.php @@ -1022,7 +1022,7 @@ if ($resql) print '
'; - print ''; print ''; } diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index e51bdfc1be0..e4ecb9f5af8 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -73,7 +73,7 @@ ErrorLDAPSetupNotComplete=Dolibarr-LDAP matching is not complete. ErrorLDAPMakeManualTest=A .ldif file has been generated in directory %s. Try to load it manually from command line to have more information on errors. ErrorCantSaveADoneUserWithZeroPercentage=Can't save an action with "statut not started" if field "done by" is also filled. ErrorRefAlreadyExists=Ref used for creation already exists. -ErrorPleaseTypeBankTransactionReportName=Please type bank statement name where entry is reported (Format YYYYMM or YYYYMMDD) +ErrorPleaseTypeBankTransactionReportName=Please ennter the bank statement name where the entry has to be reported (Format YYYYMM or YYYYMMDD) ErrorRecordHasChildren=Failed to delete record since it has some childs. ErrorRecordHasAtLeastOneChildOfType=Object has at least one child of type %s ErrorRecordIsUsedCantDelete=Can't delete record. It is already used or included into other object. From b5c12b346c7ee21a840fc7d5a8956dd1088af1a1 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 8 Feb 2018 16:50:43 +0100 Subject: [PATCH 021/177] Fix typo --- htdocs/langs/en_US/errors.lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/errors.lang b/htdocs/langs/en_US/errors.lang index e4ecb9f5af8..4ed104af7df 100644 --- a/htdocs/langs/en_US/errors.lang +++ b/htdocs/langs/en_US/errors.lang @@ -73,7 +73,7 @@ ErrorLDAPSetupNotComplete=Dolibarr-LDAP matching is not complete. ErrorLDAPMakeManualTest=A .ldif file has been generated in directory %s. Try to load it manually from command line to have more information on errors. ErrorCantSaveADoneUserWithZeroPercentage=Can't save an action with "statut not started" if field "done by" is also filled. ErrorRefAlreadyExists=Ref used for creation already exists. -ErrorPleaseTypeBankTransactionReportName=Please ennter the bank statement name where the entry has to be reported (Format YYYYMM or YYYYMMDD) +ErrorPleaseTypeBankTransactionReportName=Please enter the bank statement name where the entry has to be reported (Format YYYYMM or YYYYMMDD) ErrorRecordHasChildren=Failed to delete record since it has some childs. ErrorRecordHasAtLeastOneChildOfType=Object has at least one child of type %s ErrorRecordIsUsedCantDelete=Can't delete record. It is already used or included into other object. From b074f580db12bfa24279e3b71e1b764c6a267ff1 Mon Sep 17 00:00:00 2001 From: atm-ph Date: Thu, 8 Feb 2018 16:59:17 +0100 Subject: [PATCH 022/177] Fix can't update $nblignes on beforePDFCreation if we update $object->lines --- htdocs/core/modules/commande/doc/pdf_einstein.modules.php | 2 +- htdocs/core/modules/facture/doc/pdf_crabe.modules.php | 2 +- htdocs/core/modules/propale/doc/pdf_azur.modules.php | 2 +- .../core/modules/supplier_invoice/pdf/pdf_canelle.modules.php | 2 +- htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php | 2 +- .../core/modules/supplier_proposal/doc/pdf_aurore.modules.php | 2 +- 6 files changed, 6 insertions(+), 6 deletions(-) diff --git a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php index 5d07085378b..d8bfff2e528 100644 --- a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php @@ -179,7 +179,7 @@ class pdf_einstein extends ModelePDFCommandes */ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0) { - global $user,$langs,$conf,$mysoc,$db,$hookmanager; + global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes; if (! is_object($outputlangs)) $outputlangs=$langs; // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index de0b126b059..88a47095b8c 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -168,7 +168,7 @@ class pdf_crabe extends ModelePDFFactures */ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0) { - global $user,$langs,$conf,$mysoc,$db,$hookmanager; + global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes; if (! is_object($outputlangs)) $outputlangs=$langs; // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO diff --git a/htdocs/core/modules/propale/doc/pdf_azur.modules.php b/htdocs/core/modules/propale/doc/pdf_azur.modules.php index b2a0a522cc9..03d0db86d8f 100644 --- a/htdocs/core/modules/propale/doc/pdf_azur.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_azur.modules.php @@ -153,7 +153,7 @@ class pdf_azur extends ModelePDFPropales */ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0) { - global $user,$langs,$conf,$mysoc,$db,$hookmanager; + global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes; if (! is_object($outputlangs)) $outputlangs=$langs; // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO diff --git a/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php b/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php index b488252f77c..85b3f7bd045 100644 --- a/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php +++ b/htdocs/core/modules/supplier_invoice/pdf/pdf_canelle.modules.php @@ -139,7 +139,7 @@ class pdf_canelle extends ModelePDFSuppliersInvoices */ function write_file($object, $outputlangs='', $srctemplatepath='', $hidedetails=0, $hidedesc=0, $hideref=0) { - global $user,$langs,$conf,$mysoc,$hookmanager; + global $user,$langs,$conf,$mysoc,$hookmanager,$nblignes; // Get source company if (! is_object($object->thirdparty)) $object->fetch_thirdparty(); diff --git a/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php b/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php index 78ecb9d52c2..9d0a76eb2b6 100644 --- a/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php +++ b/htdocs/core/modules/supplier_order/pdf/pdf_muscadet.modules.php @@ -154,7 +154,7 @@ class pdf_muscadet extends ModelePDFSuppliersOrders */ function write_file($object,$outputlangs='',$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0) { - global $user,$langs,$conf,$hookmanager,$mysoc; + global $user,$langs,$conf,$hookmanager,$mysoc,$nblignes; if (! is_object($outputlangs)) $outputlangs=$langs; // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO diff --git a/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php b/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php index 0982a18f3d0..a6457dd7a2e 100644 --- a/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php +++ b/htdocs/core/modules/supplier_proposal/doc/pdf_aurore.modules.php @@ -141,7 +141,7 @@ class pdf_aurore extends ModelePDFSupplierProposal */ function write_file($object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0) { - global $user,$langs,$conf,$mysoc,$db,$hookmanager; + global $user,$langs,$conf,$mysoc,$db,$hookmanager,$nblignes; if (! is_object($outputlangs)) $outputlangs=$langs; // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO From d10d9f0fb24f0fe8a5f1710252229c6ea07d86e0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 8 Feb 2018 17:22:07 +0100 Subject: [PATCH 023/177] Fix scrutinizer --- htdocs/compta/paiement/class/paiement.class.php | 2 +- htdocs/compta/tva/class/tva.class.php | 3 ++- htdocs/contrat/class/contrat.class.php | 2 +- htdocs/fichinter/class/api_interventions.class.php | 1 + htdocs/societe/class/api_thirdparties.class.php | 2 ++ htdocs/societe/class/societe.class.php | 2 +- 6 files changed, 8 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/paiement/class/paiement.class.php b/htdocs/compta/paiement/class/paiement.class.php index fdcfc89c4e0..95c366dff0d 100644 --- a/htdocs/compta/paiement/class/paiement.class.php +++ b/htdocs/compta/paiement/class/paiement.class.php @@ -1047,7 +1047,7 @@ class Paiement extends CommonObject */ function getNomUrl($withpicto=0, $option='', $mode='withlistofinvoices', $notooltip=0) { - global $langs; + global $conf, $langs; if (! empty($conf->dol_no_mouse_hover)) $notooltip=1; // Force disable tooltips diff --git a/htdocs/compta/tva/class/tva.class.php b/htdocs/compta/tva/class/tva.class.php index 689e5d8fed3..187d21cb0a6 100644 --- a/htdocs/compta/tva/class/tva.class.php +++ b/htdocs/compta/tva/class/tva.class.php @@ -652,9 +652,10 @@ class Tva extends CommonObject * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto * @param string $option link option * @param int $notooltip 1=Disable tooltip + * @param string $morecss More CSS * @return string Chaine with URL */ - function getNomUrl($withpicto=0, $option='', $notooltip=0) + function getNomUrl($withpicto=0, $option='', $notooltip=0, morecss='') { global $langs, $conf; diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index e3900d2d89e..9e6b5e4aeb1 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -1205,7 +1205,7 @@ class Contrat extends CommonObject * @param int $notrigger 0=launch triggers after, 1=disable triggers * @return int <0 if KO, >0 if OK */ - function update($user=null, $notrigger=0) + function update($user, $notrigger=0) { global $conf, $langs; $error=0; diff --git a/htdocs/fichinter/class/api_interventions.class.php b/htdocs/fichinter/class/api_interventions.class.php index 23073737d7e..2cfe14c7197 100644 --- a/htdocs/fichinter/class/api_interventions.class.php +++ b/htdocs/fichinter/class/api_interventions.class.php @@ -162,6 +162,7 @@ class Interventions extends DolibarrApi { $num = $db->num_rows($result); $min = min($num, ($limit <= 0 ? $num : $limit)); + $i = 0; while ($i < $min) { $obj = $db->fetch_object($result); diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index 35301b06a07..7326d99e2b7 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -261,6 +261,8 @@ class Thirdparties extends DolibarrApi { global $db, $hookmanager; + $error = 0; + if ($id == $idtodelete) { throw new RestException(400, 'Try to merge a thirdparty into itself'); diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 44e95f4159b..381f50ae218 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -3780,7 +3780,7 @@ class Societe extends CommonObject */ public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id) { - if ($origin_id == $id) + if ($origin_id == $dest_id) { dol_syslog('Error: Try to merge a thirdparty into itself'); return false; From a5814ce77907f7a2c7b874b493324596a64796b0 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 9 Feb 2018 11:00:43 +0100 Subject: [PATCH 024/177] Fix: nocheck for "fournisseur", already check with "societe" --- htdocs/core/lib/security.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index e84eef83924..f8753193888 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -382,7 +382,7 @@ function checkUserAccessToObject($user, $featuresarray, $objectid=0, $tableandsh $checkother = array('contact','agenda'); // Test on entity and link to third party. Allowed if link is empty (Ex: contacts...). $checkproject = array('projet','project'); // Test for project object $checktask = array('projet_task'); - $nocheck = array('barcode','stock'); // No test + $nocheck = array('barcode','stock','fournisseur'); // No test $checkdefault = 'all other not already defined'; // Test on entity and link to third party. Not allowed if link is empty (Ex: invoice, orders...). // If dbtablename not defined, we use same name for table than module name From 2817ace0d2e9a23de261202dc4a6a1d8e5acf3ce Mon Sep 17 00:00:00 2001 From: John Date: Fri, 9 Feb 2018 15:47:18 +0100 Subject: [PATCH 025/177] Fix contract line extrafields save on add line --- htdocs/contrat/class/contrat.class.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 470d86d6c7c..78071fe0242 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -2987,7 +2987,16 @@ class ContratLigne extends CommonObjectLine { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX.'contratdet'); - // FIXME Missing insert of extrafields + // Insert of extrafields + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && is_array($this->array_options) && count($this->array_options)>0) // For avoid conflicts if trigger used + { + $result = $this->insertExtraFields(); + if ($result < 0) + { + $this->db->rollback(); + return -1; + } + } if (!$notrigger) { From 84fd67c407915450a7a66633111214d01c81a597 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 9 Feb 2018 15:49:49 +0100 Subject: [PATCH 026/177] CSS --- htdocs/theme/eldy/style.css.php | 2 +- htdocs/theme/md/style.css.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index 0b905a0e22b..385863de840 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -277,7 +277,7 @@ input.select2-input { .liste_titre input[name=month_date_when], .liste_titre input[name=monthvalid], .liste_titre input[name=search_ordermonth], .liste_titre input[name=search_deliverymonth], .liste_titre input[name=search_smonth], .liste_titre input[name=search_month], .liste_titre input[name=search_emonth], .liste_titre input[name=smonth], .liste_titre input[name=month], .liste_titre select[name=month], -.liste_titre input[name=month_lim], .liste_titre input[name=month_create] { +.liste_titre input[name=month_lim], .liste_titre input[name=month_start], .liste_titre input[name=month_end], .liste_titre input[name=month_create] { margin-right: 4px; } input[type=submit] { diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index 02c9cd9ee74..e54da2bdc92 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -290,7 +290,7 @@ textarea.cke_source:focus .liste_titre input[name=month_date_when], .liste_titre input[name=monthvalid], .liste_titre input[name=search_ordermonth], .liste_titre input[name=search_deliverymonth], .liste_titre input[name=search_smonth], .liste_titre input[name=search_month], .liste_titre input[name=search_emonth], .liste_titre input[name=smonth], .liste_titre input[name=month], -.liste_titre input[name=month_lim], .liste_titre input[name=month_create] { +.liste_titre input[name=month_lim], .liste_titre input[name=month_start], .liste_titre input[name=month_end], .liste_titre input[name=month_create] { margin-right: 4px; } input, input.flat, textarea, textarea.flat, form.flat select, select, select.flat, .dataTables_length label select { From 71c968b0b10b2b9e002b98f8caf3c10b44cc14f0 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 9 Feb 2018 16:06:23 +0100 Subject: [PATCH 027/177] Fix lose validator user in edit --- htdocs/holiday/card.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/holiday/card.php b/htdocs/holiday/card.php index e3009c975bc..e626f950a2b 100644 --- a/htdocs/holiday/card.php +++ b/htdocs/holiday/card.php @@ -1180,6 +1180,7 @@ else print ''; } + // Validator if (!$edit) { print ''; print ''; @@ -1189,7 +1190,7 @@ else print ''; print ''; print ''; print ''; } From 67ce71bc487feba279c83c57cfb287a6bea08f52 Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Fri, 9 Feb 2018 18:23:11 +0100 Subject: [PATCH 028/177] Fix: Contracts not show price --- htdocs/contrat/tpl/linkedobjectblock.tpl.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/htdocs/contrat/tpl/linkedobjectblock.tpl.php b/htdocs/contrat/tpl/linkedobjectblock.tpl.php index eae46dad772..68d7a8462f2 100644 --- a/htdocs/contrat/tpl/linkedobjectblock.tpl.php +++ b/htdocs/contrat/tpl/linkedobjectblock.tpl.php @@ -1,5 +1,6 @@ + * Copyright (C) 2018 Juanjo Menent * * 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 @@ -50,7 +51,15 @@ foreach($linkedObjectBlock as $key => $objectlink) - + From 01b3b8e09e6f97b65d605393117f73347885ae69 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sun, 11 Feb 2018 12:09:12 +0100 Subject: [PATCH 029/177] Fix: check perms by type of product --- htdocs/product/card.php | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 861c46328df..9ab1632439d 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -1588,15 +1588,16 @@ else print '
'; print '
'.price(-1 * $totalarray['totaldeb']).''.price($totalarray['totalcred']).''; + if ($user->rights->banque->consolidate && $action == 'reconcile') print ''; + print '
'; print price(price2num($balance, 'MT'), 1, $langs); print ''; + print ''; print '
'.$langs->trans('ReviewedByCP').'
'.$langs->trans('ReviewedByCP').''; - print $form->select_dolusers($object->fk_user, "valideur", 1, ($user->admin ? '' : array($user->id))); // By default, hierarchical parent + print $form->select_dolusers($object->fk_validator, "valideur", 1, ($user->admin ? '' : array($user->id))); // By default, hierarchical parent print '
getNomUrl(1); ?> date_contrat,'day'); ?> rights->contrat->lire) { + $totalcontrat = 0; + foreach ($objectlink->lines as $linecontrat) { + $totalcontrat = $totalcontrat + $linecontrat->total_ht; + $total = $total + $linecontrat->total_ht; + } + echo price($totalcontrat); + } ?> getLibStatut(7); ?> ">transnoentitiesnoconv("RemoveLink")); ?>
'; - // Type - if (! empty($conf->produit->enabled) && ! empty($conf->service->enabled)) - { - // TODO change for compatibility with edit in place - $typeformat='select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service"); - print ''; - } + // Type + if (! empty($conf->produit->enabled) && ! empty($conf->service->enabled)) + { + // TODO change for compatibility with edit in place + $typeformat='select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service"); + $perm = ($object->type==Product::TYPE_PRODUCT && $user->rights->produit->creer) || ($object->type==Product::TYPE_SERVICE && $user->rights->service->creer); + print ''; + } if ($showbarcode) { From 2b7693c5826bca85c3efdd68fe7531f2ece552f9 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sun, 11 Feb 2018 12:14:23 +0100 Subject: [PATCH 030/177] Fix: wrong param name (Travis error !) --- htdocs/compta/tva/class/tva.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/tva/class/tva.class.php b/htdocs/compta/tva/class/tva.class.php index 187d21cb0a6..0008c1232d2 100644 --- a/htdocs/compta/tva/class/tva.class.php +++ b/htdocs/compta/tva/class/tva.class.php @@ -652,10 +652,10 @@ class Tva extends CommonObject * @param int $withpicto 0=No picto, 1=Include picto into link, 2=Only picto * @param string $option link option * @param int $notooltip 1=Disable tooltip - * @param string $morecss More CSS + * @param string $morecss More CSS * @return string Chaine with URL */ - function getNomUrl($withpicto=0, $option='', $notooltip=0, morecss='') + function getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='') { global $langs, $conf; From 86df1ddd0a3ce89470af4afca54b648c38904ee6 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sun, 11 Feb 2018 13:27:02 +0100 Subject: [PATCH 031/177] Fix: uniformize user rights check --- htdocs/product/card.php | 47 +++++++++++++++++++---------------------- 1 file changed, 22 insertions(+), 25 deletions(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 9ab1632439d..80366d7fde8 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -124,6 +124,9 @@ $hookmanager->initHooks(array('productcard','globalcard')); if ($cancel) $action = ''; +$usercanread = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->lire) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->lire)); +$usercancreate = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->creer) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->creer)); +$usercandelete = (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->supprimer) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->supprimer)); $createbarcode=empty($conf->barcode->enabled)?0:1; if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->barcode->creer_advance)) $createbarcode=0; @@ -134,7 +137,7 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e if (empty($reshook)) { // Type - if ($action == 'setfk_product_type' && $user->rights->produit->creer) + if ($action == 'setfk_product_type' && $usercancreate) { $result = $object->setValueFrom('fk_product_type', GETPOST('fk_product_type'), '', null, 'text', '', $user, 'PRODUCT_MODIFY'); header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); @@ -143,7 +146,7 @@ if (empty($reshook)) // Actions to build doc $upload_dir = $conf->produit->dir_output; - $permissioncreate = $user->rights->produit->creer; + $permissioncreate = $usercancreate; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; @@ -181,7 +184,7 @@ if (empty($reshook)) } // Add a product or service - if ($action == 'add' && ($user->rights->produit->creer || $user->rights->service->creer)) + if ($action == 'add' && $usercancreate) { $error=0; @@ -360,7 +363,7 @@ if (empty($reshook)) } // Update a product or service - if ($action == 'update' && ($user->rights->produit->creer || $user->rights->service->creer)) + if ($action == 'update' && $usercancreate) { if (GETPOST('cancel','alpha')) { @@ -477,7 +480,7 @@ if (empty($reshook)) // Action clone object if ($action == 'confirm_clone' && $confirm != 'yes') { $action=''; } - if ($action == 'confirm_clone' && $confirm == 'yes' && ($user->rights->produit->creer || $user->rights->service->creer)) + if ($action == 'confirm_clone' && $confirm == 'yes' && $usercancreate) { if (! GETPOST('clone_content') && ! GETPOST('clone_prices') ) { @@ -565,12 +568,9 @@ if (empty($reshook)) // Delete a product if ($action == 'confirm_delete' && $confirm != 'yes') { $action=''; } - if ($action == 'confirm_delete' && $confirm == 'yes') - { - if (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->supprimer) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->supprimer)) - { - $result = $object->delete($user); - } + if ($action == 'confirm_delete' && $confirm == 'yes' && $usercandelete) + { + $result = $object->delete($user); if ($result > 0) { @@ -887,7 +887,7 @@ else // ----------------------------------------- // When used in standard mode // ----------------------------------------- - if ($action == 'create' && ($user->rights->produit->creer || $user->rights->service->creer)) + if ($action == 'create' && $usercancreate) { //WYSIWYG Editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; @@ -1240,7 +1240,7 @@ else else if ($object->id > 0) { // Fiche en mode edition - if ($action == 'edit' && ((($object->type == Product::TYPE_PRODUCT && $user->rights->produit->creer) || ($object->type == Product::TYPE_SERVICE && $user->rights->service->creer)))) + if ($action == 'edit' && $usercancreate) { //WYSIWYG Editor require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; @@ -1593,8 +1593,7 @@ else { // TODO change for compatibility with edit in place $typeformat='select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service"); - $perm = ($object->type==Product::TYPE_PRODUCT && $user->rights->produit->creer) || ($object->type==Product::TYPE_SERVICE && $user->rights->service->creer); - print ''; } @@ -1606,7 +1605,7 @@ else print '
'.$form->editfieldkey("Type",'fk_product_type',$object->type,$object,$user->rights->produit->creer||$user->rights->service->creer,$typeformat).''; - print $form->editfieldval("Type",'fk_product_type',$object->type,$object,$user->rights->produit->creer||$user->rights->service->creer,$typeformat); - print '
'.$form->editfieldkey("Type", 'fk_product_type', $object->type, $object, $perm, $typeformat).''; + print $form->editfieldval("Type", 'fk_product_type', $object->type, $object, $perm, $typeformat); + print '
'.$form->editfieldkey("Type", 'fk_product_type', $object->type, $object, $perm, $typeformat).''; + print '
'.$form->editfieldkey("Type", 'fk_product_type', $object->type, $object, $usercancreate, $typeformat).''; print $form->editfieldval("Type", 'fk_product_type', $object->type, $object, $perm, $typeformat); print '
'; - if (($action != 'editbarcodetype') && ! empty($user->rights->produit->creer) && $createbarcode) print ''; + if (($action != 'editbarcodetype') && $usercancreate && $createbarcode) print ''; print '
'; print $langs->trans("BarcodeType"); print 'id.'">'.img_edit($langs->trans('Edit'),1).'id.'">'.img_edit($langs->trans('Edit'),1).'
'; print ''; if ($action == 'editbarcodetype' || $action == 'editbarcode') @@ -1630,7 +1629,7 @@ else print ''; - if (($action != 'editbarcode') && ! empty($user->rights->produit->creer) && $createbarcode) print ''; + if (($action != 'editbarcode') && $usercancreate && $createbarcode) print ''; print '
'; print $langs->trans("BarcodeValue"); print 'id.'">'.img_edit($langs->trans('Edit'),1).'id.'">'.img_edit($langs->trans('Edit'),1).'
'; print ''; if ($action == 'editbarcode') @@ -1742,7 +1741,7 @@ else // Batch number management (to batch) if (! empty($conf->productbatch->enabled)) { print ''.$langs->trans("ManageLotSerial").''; - if (! empty($conf->use_javascript_ajax) && $user->rights->produit->creer && ! empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) { + if (! empty($conf->use_javascript_ajax) && $usercancreate && ! empty($conf->global->MAIN_DIRECT_STATUS_UPDATE)) { print ajax_object_onoff($object, 'status_batch', 'tobatch', 'ProductStatusOnBatch', 'ProductStatusNotOnBatch'); } else { print $object->getLibStatut(0,2); @@ -1975,9 +1974,8 @@ if ($action != 'create' && $action != 'edit') $parameters=array(); $reshook=$hookmanager->executeHooks('addMoreActionsButtons',$parameters,$object,$action); // Note that $action and $object may have been modified by hook if (empty($reshook)) - { - if (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->creer ) || - ($object->type == Product::TYPE_SERVICE && $user->rights->service->creer)) + { + if ($usercancreate) { if (! isset($object->no_button_edit) || $object->no_button_edit <> 1) print ''; @@ -1995,8 +1993,7 @@ if ($action != 'create' && $action != 'edit') } $object_is_used = $object->isObjectUsed($object->id); - if (($object->type == Product::TYPE_PRODUCT && $user->rights->produit->supprimer) - || ($object->type == Product::TYPE_SERVICE && $user->rights->service->supprimer)) + if ($usercandelete) { if (empty($object_is_used) && (! isset($object->no_button_delete) || $object->no_button_delete <> 1)) { @@ -2152,8 +2149,8 @@ if ($action != 'create' && $action != 'edit' && $action != 'delete') $relativepath = $comref . '/' . $objectref . '.pdf'; $filedir = $conf->produit->dir_output . '/' . $objectref; $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id; - $genallowed=$user->rights->produit->lire; - $delallowed=$user->rights->produit->creer; + $genallowed=$usercanread; + $delallowed=$usercandelete; $var=true; From 3525306cc44ae5795b9dc2728915cd6d1ec9606a Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sun, 11 Feb 2018 13:29:37 +0100 Subject: [PATCH 032/177] Fix: wrong var name --- htdocs/product/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 80366d7fde8..93f45317661 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -1594,7 +1594,7 @@ else // TODO change for compatibility with edit in place $typeformat='select;0:'.$langs->trans("Product").',1:'.$langs->trans("Service"); print ''.$form->editfieldkey("Type", 'fk_product_type', $object->type, $object, $usercancreate, $typeformat).''; - print $form->editfieldval("Type", 'fk_product_type', $object->type, $object, $perm, $typeformat); + print $form->editfieldval("Type", 'fk_product_type', $object->type, $object, $usercancreate, $typeformat); print ''; } From b7b496132b9e775b24485af3aee8d9d23c3ba4c3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 12 Feb 2018 01:27:54 +0100 Subject: [PATCH 033/177] Fix syntax error --- htdocs/compta/tva/class/tva.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/tva/class/tva.class.php b/htdocs/compta/tva/class/tva.class.php index 187d21cb0a6..f50e13e02d6 100644 --- a/htdocs/compta/tva/class/tva.class.php +++ b/htdocs/compta/tva/class/tva.class.php @@ -655,7 +655,7 @@ class Tva extends CommonObject * @param string $morecss More CSS * @return string Chaine with URL */ - function getNomUrl($withpicto=0, $option='', $notooltip=0, morecss='') + function getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='') { global $langs, $conf; From fa3b1c74a901072f0a96c2028482837bde4f3b37 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 12 Feb 2018 02:25:34 +0100 Subject: [PATCH 034/177] Fix bad link --- htdocs/compta/bank/transfer.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/bank/transfer.php b/htdocs/compta/bank/transfer.php index 3819e2acccb..61a4f524a1a 100644 --- a/htdocs/compta/bank/transfer.php +++ b/htdocs/compta/bank/transfer.php @@ -125,7 +125,7 @@ if ($action == 'add') if (! $error) { - $mesgs = $langs->trans("TransferFromToDone",''.$accountfrom->label."",''.$accountto->label."",$amount,$langs->transnoentities("Currency".$conf->currency)); + $mesgs = $langs->trans("TransferFromToDone",''.$accountfrom->label."",''.$accountto->label."",$amount,$langs->transnoentities("Currency".$conf->currency)); setEventMessages($mesgs, null, 'mesgs'); $db->commit(); } From 37ff46b05ad687c51b6672537e7f5bb82bfafd79 Mon Sep 17 00:00:00 2001 From: Romain DESCHAMPS Date: Fri, 9 Feb 2018 09:11:47 +0100 Subject: [PATCH 035/177] add missing links in supplier card boxes --- htdocs/fourn/card.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php index 724f90af228..5a47ce17089 100644 --- a/htdocs/fourn/card.php +++ b/htdocs/fourn/card.php @@ -305,7 +305,7 @@ if ($object->id > 0) $outstandingTotal=$tmp['total_ht']; $outstandingTotalIncTax=$tmp['total_ttc']; $text=$langs->trans("OverAllSupplierProposals"); - $link=''; + $link=DOL_URL_ROOT.'/supplier_proposal/list.php?socid='.$object->id; $icon='bill'; if ($link) $boxstat.=''; $boxstat.='
'; @@ -323,7 +323,7 @@ if ($object->id > 0) $outstandingTotal=$tmp['total_ht']; $outstandingTotalIncTax=$tmp['total_ttc']; $text=$langs->trans("OverAllOrders"); - $link=''; + $link=DOL_URL_ROOT.'/fourn/commande/list.php?socid='.$object->id; $icon='bill'; if ($link) $boxstat.=''; $boxstat.='
'; @@ -341,7 +341,7 @@ if ($object->id > 0) $outstandingTotalIncTax=$tmp['total_ttc']; $text=$langs->trans("OverAllInvoices"); - $link=''; + $link=DOL_URL_ROOT.'/fourn/facture/list.php?socid='.$object->id; $icon='bill'; if ($link) $boxstat.=''; $boxstat.='
'; From 8e42ed5824f24e6165c96791a0d3bc893472035b Mon Sep 17 00:00:00 2001 From: Romain DESCHAMPS Date: Fri, 9 Feb 2018 09:14:34 +0100 Subject: [PATCH 036/177] add missing links in cust. card boxes --- htdocs/comm/card.php | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index 7e81d88adc1..2495d512c55 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -549,7 +549,7 @@ if ($id > 0) $outstandingTotal=$tmp['total_ht']; $outstandingTotalIncTax=$tmp['total_ttc']; $text=$langs->trans("OverAllProposals"); - $link=''; + $link=DOL_URL_ROOT.'/comm/propal/list.php?socid='.$object->id; $icon='bill'; if ($link) $boxstat.=''; $boxstat.='
'; @@ -561,13 +561,13 @@ if ($id > 0) if (! empty($conf->commande->enabled)) { - // Box proposals + // Box commandes $tmp = $object->getOutstandingOrders(); $outstandingOpened=$tmp['opened']; $outstandingTotal=$tmp['total_ht']; $outstandingTotalIncTax=$tmp['total_ttc']; $text=$langs->trans("OverAllOrders"); - $link=''; + $link=DOL_URL_ROOT.'/commande/list.php?socid='.$object->id; $icon='bill'; if ($link) $boxstat.=''; $boxstat.='
'; @@ -579,12 +579,13 @@ if ($id > 0) if (! empty($conf->facture->enabled)) { + // Box factures $tmp = $object->getOutstandingBills(); $outstandingOpened=$tmp['opened']; $outstandingTotal=$tmp['total_ht']; $outstandingTotalIncTax=$tmp['total_ttc']; $text=$langs->trans("OverAllInvoices"); - $link=''; + $link=DOL_URL_ROOT.'/compta/facture/list.php?socid='.$object->id; $icon='bill'; if ($link) $boxstat.=''; $boxstat.='
'; From f88874c1f7fafe9aa3ee49aa0ab829cbc45be387 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 12 Feb 2018 02:53:08 +0100 Subject: [PATCH 037/177] Code comment --- htdocs/core/lib/security.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index e84eef83924..c204809e9a1 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -104,7 +104,7 @@ function dol_hash($chain,$type=0) * @param string $features Features to check (it must be module name. Examples: 'societe', 'contact', 'produit&service', 'produit|service', ...) * @param int $objectid Object ID if we want to check a particular record (optional) is linked to a owned thirdparty (optional). * @param string $tableandshare 'TableName&SharedElement' with Tablename is table where object is stored. SharedElement is an optional key to define where to check entity for multicompany modume. Param not used if objectid is null (optional). - * @param string $feature2 Feature to check, second level of permission (optional). Can be or check with 'level1|level2'. + * @param string $feature2 Feature to check, second level of permission (optional). Can be a 'or' check with 'level1|level2'. * @param string $dbt_keyfield Field name for socid foreign key if not fk_soc. Not used if objectid is null (optional) * @param string $dbt_select Field name for select if not rowid. Not used if objectid is null (optional) * @param Canvas $objcanvas Object canvas From 671fbd3d55b1bcd9f339c021c6cd81e5a5682f43 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 12 Feb 2018 02:59:18 +0100 Subject: [PATCH 038/177] Code comment --- htdocs/contrat/class/contrat.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/contrat/class/contrat.class.php b/htdocs/contrat/class/contrat.class.php index 5165d1cdcb6..23ae71cb6f3 100644 --- a/htdocs/contrat/class/contrat.class.php +++ b/htdocs/contrat/class/contrat.class.php @@ -881,7 +881,6 @@ class Contrat extends CommonObject $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."contrat"); - // Load object modContract $module=(! empty($conf->global->CONTRACT_ADDON)?$conf->global->CONTRACT_ADDON:'mod_contract_serpis'); if (substr($module, 0, 13) == 'mod_contract_' && substr($module, -3) == 'php') From d731857fd0dfaa0ac22ee8db3d8aa1ce29f5d4f5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 12 Feb 2018 03:13:12 +0100 Subject: [PATCH 039/177] Update linkedobjectblock.tpl.php --- htdocs/contrat/tpl/linkedobjectblock.tpl.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/htdocs/contrat/tpl/linkedobjectblock.tpl.php b/htdocs/contrat/tpl/linkedobjectblock.tpl.php index 68d7a8462f2..a44f20679b8 100644 --- a/htdocs/contrat/tpl/linkedobjectblock.tpl.php +++ b/htdocs/contrat/tpl/linkedobjectblock.tpl.php @@ -52,7 +52,11 @@ foreach($linkedObjectBlock as $key => $objectlink) date_contrat,'day'); ?> rights->contrat->lire) { + // Price of contract is not shown by default because a contract is a list of service with + // start and end date that change with time andd that may be different that the period of reference for price. + // So price of a contract does often means nothing. Prices is on the different invoices done on same contract. + if ($user->rights->contrat->lire && empty($conf->global->CONTRACT_SHOW_TOTAL_OF_PRODUCT_AS_PRICE)) + { $totalcontrat = 0; foreach ($objectlink->lines as $linecontrat) { $totalcontrat = $totalcontrat + $linecontrat->total_ht; @@ -65,4 +69,4 @@ foreach($linkedObjectBlock as $key => $objectlink) - \ No newline at end of file + From 975608b9d3f0812b6961fa230d371cdb93dfd5f5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 12 Feb 2018 03:21:04 +0100 Subject: [PATCH 040/177] FIX #8174 --- htdocs/compta/facture/list.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index 84898930ed9..0ff463f9ca5 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -152,7 +152,7 @@ $arrayfields=array( 'f.type'=>array('label'=>$langs->trans("Type"), 'checked'=>0), 'f.date'=>array('label'=>$langs->trans("DateInvoice"), 'checked'=>1), 'f.date_lim_reglement'=>array('label'=>$langs->trans("DateDue"), 'checked'=>1), - 'p.ref'=>array('label'=>$langs->trans("ProjectRef"), 'checked'=>0), + 'p.ref'=>array('label'=>$langs->trans("ProjectRef"), 'checked'=>0, 'enabled'=>(empty($conf->projet->enabled)?0:1)), 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1), 's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1), 's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1), @@ -162,8 +162,8 @@ $arrayfields=array( 'f.fk_mode_reglement'=>array('label'=>$langs->trans("PaymentMode"), 'checked'=>1), 'f.total_ht'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1), 'f.total_vat'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>0), - 'f.total_localtax1'=>array('label'=>$langs->transcountry("AmountLT1", $mysoc->country_code), 'checked'=>0, 'enabled'=>$mysoc->localtax1_assuj=="1"), - 'f.total_localtax2'=>array('label'=>$langs->transcountry("AmountLT2", $mysoc->country_code), 'checked'=>0, 'enabled'=>$mysoc->localtax2_assuj=="1"), + 'f.total_localtax1'=>array('label'=>$langs->transcountry("AmountLT1", $mysoc->country_code), 'checked'=>0, 'enabled'=>($mysoc->localtax1_assuj=="1")), + 'f.total_localtax2'=>array('label'=>$langs->transcountry("AmountLT2", $mysoc->country_code), 'checked'=>0, 'enabled'=>($mysoc->localtax2_assuj=="1")), 'f.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>0), 'dynamount_payed'=>array('label'=>$langs->trans("Received"), 'checked'=>0), 'rtp'=>array('label'=>$langs->trans("Rest"), 'checked'=>0), From 7f4adb7f97ae51bb6799a59178f9108256a5d247 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 12 Feb 2018 03:23:57 +0100 Subject: [PATCH 041/177] Update card.php --- htdocs/product/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 93f45317661..f65898bda68 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -2150,7 +2150,7 @@ if ($action != 'create' && $action != 'edit' && $action != 'delete') $filedir = $conf->produit->dir_output . '/' . $objectref; $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id; $genallowed=$usercanread; - $delallowed=$usercandelete; + $delallowed=$usercancreate; $var=true; From 55779e3b5543b2ac7f5d171c773240fbd78713ed Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 12 Feb 2018 04:07:45 +0100 Subject: [PATCH 042/177] Fix confusion between supplier and customer categories --- .../societe/class/api_thirdparties.class.php | 1551 +++++++++-------- 1 file changed, 856 insertions(+), 695 deletions(-) diff --git a/htdocs/societe/class/api_thirdparties.class.php b/htdocs/societe/class/api_thirdparties.class.php index 7326d99e2b7..fa52c73f597 100644 --- a/htdocs/societe/class/api_thirdparties.class.php +++ b/htdocs/societe/class/api_thirdparties.class.php @@ -15,7 +15,7 @@ * along with this program. If not, see . */ - use Luracast\Restler\RestException; +use Luracast\Restler\RestException; /** @@ -27,567 +27,728 @@ */ class Thirdparties extends DolibarrApi { - /** - * - * @var array $FIELDS Mandatory fields, checked when create and update object - */ - static $FIELDS = array( - 'name' - ); + /** + * + * @var array $FIELDS Mandatory fields, checked when create and update object + */ + static $FIELDS = array( + 'name' + ); - /** - * @var Societe $company {@type Societe} - */ - public $company; + /** + * @var Societe $company {@type Societe} + */ + public $company; - /** - * Constructor - */ - function __construct() - { + /** + * Constructor + */ + function __construct() + { global $db, $conf; $this->db = $db; require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; - $this->company = new Societe($this->db); + $this->company = new Societe($this->db); - if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY)) { - static::$FIELDS[] = 'email'; - } - } + if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY)) { + static::$FIELDS[] = 'email'; + } + } - /** - * Get properties of a thirdparty object - * - * Return an array with thirdparty informations - * - * @param int $id ID of thirdparty - * @return array|mixed data without useless information + /** + * Get properties of a thirdparty object * - * @throws RestException - */ - function get($id) - { - if(! DolibarrApiAccess::$user->rights->societe->lire) { - throw new RestException(401); - } - - $result = $this->company->fetch($id); - if( ! $result ) { - throw new RestException(404, 'Thirdparty not found'); - } - - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - $filterabsolutediscount = "fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%'))"; - $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')"; - $absolute_discount = $this->company->getAvailableDiscounts('', $filterabsolutediscount); - $absolute_creditnote = $this->company->getAvailableDiscounts('', $filtercreditnote); - $this->company->absolute_discount = price2num($absolute_discount, 'MT'); - $this->company->absolute_creditnote = price2num($absolute_creditnote, 'MT'); - - return $this->_cleanObjectDatas($this->company); - } - - /** - * List thirdparties - * - * Get a list of thirdparties - * - * @param string $sortfield Sort field - * @param string $sortorder Sort order - * @param int $limit Limit for list - * @param int $page Page number - * @param int $mode Set to 1 to show only customers - * Set to 2 to show only prospects - * Set to 3 to show only those are not customer neither prospect - * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.nom:like:'TheCompany%') and (t.date_creation:<:'20160101')" - * @return array Array of thirdparty objects - */ - function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $mode=0, $sqlfilters = '') { - global $db, $conf; - - $obj_ret = array(); - - // case of external user, we force socids - $socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : ''; - - // If the internal user must only see his customers, force searching by him - $search_sale = 0; - if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id; - - $sql = "SELECT t.rowid"; - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) - $sql.= " FROM ".MAIN_DB_PREFIX."societe as t"; - - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale - $sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st"; - $sql.= " WHERE t.fk_stcomm = st.id"; - if ($mode == 1) $sql.= " AND t.client IN (1, 3)"; - if ($mode == 2) $sql.= " AND t.client IN (2, 3)"; - if ($mode == 3) $sql.= " AND t.client IN (0)"; - $sql.= ' AND t.entity IN ('.getEntity('societe').')'; - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; - //if ($email != NULL) $sql.= " AND s.email = \"".$email."\""; - if ($socid) $sql.= " AND t.rowid IN (".$socids.")"; - if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale - // Insert sale filter - if ($search_sale > 0) - { - $sql .= " AND sc.fk_user = ".$search_sale; - } - // Add sql filters - if ($sqlfilters) - { - if (! DolibarrApi::_checkFilters($sqlfilters)) - { - throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); - } - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; - $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; - } - - $sql.= $db->order($sortfield, $sortorder); - - if ($limit) { - if ($page < 0) - { - $page = 0; - } - $offset = $limit * $page; - - $sql.= $db->plimit($limit + 1, $offset); - } - - $result = $db->query($sql); - if ($result) - { - $num = $db->num_rows($result); - $min = min($num, ($limit <= 0 ? $num : $limit)); - while ($i < $min) - { - $obj = $db->fetch_object($result); - $soc_static = new Societe($db); - if($soc_static->fetch($obj->rowid)) { - $obj_ret[] = $this->_cleanObjectDatas($soc_static); - } - $i++; - } - } - else { - throw new RestException(503, 'Error when retrieve thirdparties : '.$db->lasterror()); - } - if( ! count($obj_ret)) { - throw new RestException(404, 'Thirdparties not found'); - } - return $obj_ret; - } - - /** - * Create thirdparty object - * - * @param array $request_data Request datas - * @return int ID of thirdparty - */ - function post($request_data = NULL) - { - if(! DolibarrApiAccess::$user->rights->societe->creer) { - throw new RestException(401); - } - // Check mandatory fields - $result = $this->_validate($request_data); - - foreach($request_data as $field => $value) { - $this->company->$field = $value; - } - if ($this->company->create(DolibarrApiAccess::$user) < 0) - throw new RestException(500, 'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors)); - - return $this->company->id; - } - - /** - * Update thirdparty - * - * @param int $id Id of thirdparty to update - * @param array $request_data Datas - * @return int - */ - function put($id, $request_data = NULL) - { - if(! DolibarrApiAccess::$user->rights->societe->creer) { + * Return an array with thirdparty informations + * + * @param int $id ID of thirdparty + * @return array|mixed data without useless information + * + * @throws RestException + */ + function get($id) + { + if(! DolibarrApiAccess::$user->rights->societe->lire) { throw new RestException(401); } - $result = $this->company->fetch($id); - if( ! $result ) { - throw new RestException(404, 'Thirdparty not found'); - } + $result = $this->company->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + } if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); } - foreach($request_data as $field => $value) { - if ($field == 'id') continue; - $this->company->$field = $value; - } + $filterabsolutediscount = "fk_facture_source IS NULL OR (fk_facture_source IS NOT NULL AND (description LIKE '(DEPOSIT)%' AND description NOT LIKE '(EXCESS RECEIVED)%'))"; + $filtercreditnote = "fk_facture_source IS NOT NULL AND (description NOT LIKE '(DEPOSIT)%' OR description LIKE '(EXCESS RECEIVED)%')"; + $absolute_discount = $this->company->getAvailableDiscounts('', $filterabsolutediscount); + $absolute_creditnote = $this->company->getAvailableDiscounts('', $filtercreditnote); + $this->company->absolute_discount = price2num($absolute_discount, 'MT'); + $this->company->absolute_creditnote = price2num($absolute_creditnote, 'MT'); - if($this->company->update($id, DolibarrApiAccess::$user,1,'','','update')) - return $this->get ($id); + return $this->_cleanObjectDatas($this->company); + } - return false; - } + /** + * List thirdparties + * + * Get a list of thirdparties + * + * @param string $sortfield Sort field + * @param string $sortorder Sort order + * @param int $limit Limit for list + * @param int $page Page number + * @param int $mode Set to 1 to show only customers + * Set to 2 to show only prospects + * Set to 3 to show only those are not customer neither prospect + * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.nom:like:'TheCompany%') and (t.date_creation:<:'20160101')" + * @return array Array of thirdparty objects + */ + function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $mode=0, $sqlfilters = '') { + global $db, $conf; - /** - * Merge a thirdparty into another one. - * - * Merge content (properties, notes) and objects (like invoices, events, orders, proposals, ...) of a thirdparty into a target thirdparty, - * then delete the merged thirdparty. - * If a property has a defined value both in thirdparty to delete and thirdparty to keep, the value into the thirdparty to - * delete will be ignored, the value of target thirdparty will remain, except for notes (content is concatenated). - * - * @param int $id ID of thirdparty to keep (the target thirdparty) - * @param int $idtodelete ID of thirdparty to remove (the thirdparty to delete), once data has been merged into the target thirdparty. - * @return int - * - * @url PUT {id}/merge/{idtodelete} - */ - function merge($id, $idtodelete) - { - global $db, $hookmanager; + $obj_ret = array(); - $error = 0; + // case of external user, we force socids + $socids = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : ''; - if ($id == $idtodelete) - { - throw new RestException(400, 'Try to merge a thirdparty into itself'); - } + // If the internal user must only see his customers, force searching by him + $search_sale = 0; + if (! DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) $search_sale = DolibarrApiAccess::$user->id; - if(! DolibarrApiAccess::$user->rights->societe->creer) { - throw new RestException(401); - } + $sql = "SELECT t.rowid"; + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql .= ", sc.fk_soc, sc.fk_user"; // We need these fields in order to filter by sale (including the case where the user can only see his prospects) + $sql.= " FROM ".MAIN_DB_PREFIX."societe as t"; - $result = $this->company->fetch($id); // include the fetch of extra fields - if( ! $result ) { - throw new RestException(404, 'Thirdparty not found'); - } + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; // We need this table joined to the select in order to filter by sale + $sql.= ", ".MAIN_DB_PREFIX."c_stcomm as st"; + $sql.= " WHERE t.fk_stcomm = st.id"; + if ($mode == 1) $sql.= " AND t.client IN (1, 3)"; + if ($mode == 2) $sql.= " AND t.client IN (2, 3)"; + if ($mode == 3) $sql.= " AND t.client IN (0)"; + $sql.= ' AND t.entity IN ('.getEntity('societe').')'; + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; + //if ($email != NULL) $sql.= " AND s.email = \"".$email."\""; + if ($socid) $sql.= " AND t.rowid IN (".$socids.")"; + if ($search_sale > 0) $sql.= " AND t.rowid = sc.fk_soc"; // Join for the needed table to filter by sale + // Insert sale filter + if ($search_sale > 0) + { + $sql .= " AND sc.fk_user = ".$search_sale; + } + // Add sql filters + if ($sqlfilters) + { + if (! DolibarrApi::_checkFilters($sqlfilters)) + { + throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); + } + $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; + $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; + } - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } + $sql.= $db->order($sortfield, $sortorder); - $this->companytoremove = new Societe($db); + if ($limit) { + if ($page < 0) + { + $page = 0; + } + $offset = $limit * $page; - $result = $this->companytoremove->fetch($idtodelete); // include the fetch of extra fields - if( ! $result ) { - throw new RestException(404, 'Thirdparty not found'); - } + $sql.= $db->plimit($limit + 1, $offset); + } - if( ! DolibarrApi::_checkAccessToResource('societe',$this->companytoremove->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + $min = min($num, ($limit <= 0 ? $num : $limit)); + while ($i < $min) + { + $obj = $db->fetch_object($result); + $soc_static = new Societe($db); + if($soc_static->fetch($obj->rowid)) { + $obj_ret[] = $this->_cleanObjectDatas($soc_static); + } + $i++; + } + } + else { + throw new RestException(503, 'Error when retrieve thirdparties : '.$db->lasterror()); + } + if( ! count($obj_ret)) { + throw new RestException(404, 'Thirdparties not found'); + } + return $obj_ret; + } - $soc_origin = $this->companytoremove; - $object = $this->company; - $user = DolibarrApiAccess::$user; + /** + * Create thirdparty object + * + * @param array $request_data Request datas + * @return int ID of thirdparty + */ + function post($request_data = NULL) + { + if(! DolibarrApiAccess::$user->rights->societe->creer) { + throw new RestException(401); + } + // Check mandatory fields + $result = $this->_validate($request_data); + + foreach($request_data as $field => $value) { + $this->company->$field = $value; + } + if ($this->company->create(DolibarrApiAccess::$user) < 0) + throw new RestException(500, 'Error creating thirdparty', array_merge(array($this->company->error), $this->company->errors)); + + return $this->company->id; + } + + /** + * Update thirdparty + * + * @param int $id Id of thirdparty to update + * @param array $request_data Datas + * @return int + */ + function put($id, $request_data = NULL) + { + if(! DolibarrApiAccess::$user->rights->societe->creer) { + throw new RestException(401); + } + + $result = $this->company->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + foreach($request_data as $field => $value) { + if ($field == 'id') continue; + $this->company->$field = $value; + } + + if($this->company->update($id, DolibarrApiAccess::$user,1,'','','update')) + return $this->get($id); + + return false; + } + + /** + * Merge a thirdparty into another one. + * + * Merge content (properties, notes) and objects (like invoices, events, orders, proposals, ...) of a thirdparty into a target thirdparty, + * then delete the merged thirdparty. + * If a property has a defined value both in thirdparty to delete and thirdparty to keep, the value into the thirdparty to + * delete will be ignored, the value of target thirdparty will remain, except for notes (content is concatenated). + * + * @param int $id ID of thirdparty to keep (the target thirdparty) + * @param int $idtodelete ID of thirdparty to remove (the thirdparty to delete), once data has been merged into the target thirdparty. + * @return int + * + * @url PUT {id}/merge/{idtodelete} + */ + function merge($id, $idtodelete) + { + global $db, $hookmanager; + + $error = 0; + + if ($id == $idtodelete) + { + throw new RestException(400, 'Try to merge a thirdparty into itself'); + } + + if(! DolibarrApiAccess::$user->rights->societe->creer) { + throw new RestException(401); + } + + $result = $this->company->fetch($id); // include the fetch of extra fields + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $this->companytoremove = new Societe($db); + + $result = $this->companytoremove->fetch($idtodelete); // include the fetch of extra fields + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('societe',$this->companytoremove->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $soc_origin = $this->companytoremove; + $object = $this->company; + $user = DolibarrApiAccess::$user; - // Call same code than into action 'confirm_merge' + // Call same code than into action 'confirm_merge' - $db->begin(); + $db->begin(); - // Recopy some data - $object->client = $object->client | $soc_origin->client; - $object->fournisseur = $object->fournisseur | $soc_origin->fournisseur; - $listofproperties=array( - 'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'skype', 'url', 'barcode', - 'idprof1', 'idprof2', 'idprof3', 'idprof4', 'idprof5', 'idprof6', - 'tva_intra', 'effectif_id', 'forme_juridique', 'remise_percent', 'mode_reglement_supplier_id', 'cond_reglement_supplier_id', 'name_bis', - 'stcomm_id', 'outstanding_limit', 'price_level', 'parent', 'default_lang', 'ref', 'ref_ext', 'import_key', 'fk_incoterms', 'fk_multicurrency', - 'code_client', 'code_fournisseur', 'code_compta', 'code_compta_fournisseur', - 'model_pdf', 'fk_projet' - ); - foreach ($listofproperties as $property) - { - if (empty($object->$property)) $object->$property = $soc_origin->$property; - } + // Recopy some data + $object->client = $object->client | $soc_origin->client; + $object->fournisseur = $object->fournisseur | $soc_origin->fournisseur; + $listofproperties=array( + 'address', 'zip', 'town', 'state_id', 'country_id', 'phone', 'phone_pro', 'fax', 'email', 'skype', 'url', 'barcode', + 'idprof1', 'idprof2', 'idprof3', 'idprof4', 'idprof5', 'idprof6', + 'tva_intra', 'effectif_id', 'forme_juridique', 'remise_percent', 'mode_reglement_supplier_id', 'cond_reglement_supplier_id', 'name_bis', + 'stcomm_id', 'outstanding_limit', 'price_level', 'parent', 'default_lang', 'ref', 'ref_ext', 'import_key', 'fk_incoterms', 'fk_multicurrency', + 'code_client', 'code_fournisseur', 'code_compta', 'code_compta_fournisseur', + 'model_pdf', 'fk_projet' + ); + foreach ($listofproperties as $property) + { + if (empty($object->$property)) $object->$property = $soc_origin->$property; + } - // Concat some data - $listofproperties=array( - 'note_public', 'note_private' - ); - foreach ($listofproperties as $property) - { - $object->$property = dol_concatdesc($object->$property, $soc_origin->$property); - } + // Concat some data + $listofproperties=array( + 'note_public', 'note_private' + ); + foreach ($listofproperties as $property) + { + $object->$property = dol_concatdesc($object->$property, $soc_origin->$property); + } - // Merge extrafields - if (is_array($soc_origin->array_options)) - { - foreach ($soc_origin->array_options as $key => $val) - { - if (empty($object->array_options[$key])) $object->array_options[$key] = $val; - } - } + // Merge extrafields + if (is_array($soc_origin->array_options)) + { + foreach ($soc_origin->array_options as $key => $val) + { + if (empty($object->array_options[$key])) $object->array_options[$key] = $val; + } + } - // Merge categories - $static_cat = new Categorie($db); - $custcats = $static_cat->containing($soc_origin->id, 'customer', 'id'); - $object->setCategories($custcats, 'customer'); - $suppcats = $static_cat->containing($soc_origin->id, 'supplier', 'id'); - $object->setCategories($suppcats, 'supplier'); + // Merge categories + $static_cat = new Categorie($db); + $custcats = $static_cat->containing($soc_origin->id, 'customer', 'id'); + $object->setCategories($custcats, 'customer'); + $suppcats = $static_cat->containing($soc_origin->id, 'supplier', 'id'); + $object->setCategories($suppcats, 'supplier'); - // If thirdparty has a new code that is same than origin, we clean origin code to avoid duplicate key from database unique keys. - if ($soc_origin->code_client == $object->code_client - || $soc_origin->code_fournisseur == $object->code_fournisseur - || $soc_origin->barcode == $object->barcode) - { - dol_syslog("We clean customer and supplier code so we will be able to make the update of target"); - $soc_origin->code_client = ''; - $soc_origin->code_fournisseur = ''; - $soc_origin->barcode = ''; - $soc_origin->update($soc_origin->id, $user, 0, 1, 1, 'merge'); - } + // If thirdparty has a new code that is same than origin, we clean origin code to avoid duplicate key from database unique keys. + if ($soc_origin->code_client == $object->code_client + || $soc_origin->code_fournisseur == $object->code_fournisseur + || $soc_origin->barcode == $object->barcode) + { + dol_syslog("We clean customer and supplier code so we will be able to make the update of target"); + $soc_origin->code_client = ''; + $soc_origin->code_fournisseur = ''; + $soc_origin->barcode = ''; + $soc_origin->update($soc_origin->id, $user, 0, 1, 1, 'merge'); + } - // Update - $result = $object->update($object->id, $user, 0, 1, 1, 'merge'); - if ($result < 0) - { - $error++; - } + // Update + $result = $object->update($object->id, $user, 0, 1, 1, 'merge'); + if ($result < 0) + { + $error++; + } - // Move links - if (! $error) - { - $objects = array( - 'Adherent' => '/adherents/class/adherent.class.php', - 'Societe' => '/societe/class/societe.class.php', - 'Categorie' => '/categories/class/categorie.class.php', - 'ActionComm' => '/comm/action/class/actioncomm.class.php', - 'Propal' => '/comm/propal/class/propal.class.php', - 'Commande' => '/commande/class/commande.class.php', - 'Facture' => '/compta/facture/class/facture.class.php', - 'FactureRec' => '/compta/facture/class/facture-rec.class.php', - 'LignePrelevement' => '/compta/prelevement/class/ligneprelevement.class.php', - 'Contact' => '/contact/class/contact.class.php', - 'Contrat' => '/contrat/class/contrat.class.php', - 'Expedition' => '/expedition/class/expedition.class.php', - 'Fichinter' => '/fichinter/class/fichinter.class.php', - 'CommandeFournisseur' => '/fourn/class/fournisseur.commande.class.php', - 'FactureFournisseur' => '/fourn/class/fournisseur.facture.class.php', - 'SupplierProposal' => '/supplier_proposal/class/supplier_proposal.class.php', - 'ProductFournisseur' => '/fourn/class/fournisseur.product.class.php', - 'Livraison' => '/livraison/class/livraison.class.php', - 'Product' => '/product/class/product.class.php', - 'Project' => '/projet/class/project.class.php', - 'User' => '/user/class/user.class.php', - ); + // Move links + if (! $error) + { + $objects = array( + 'Adherent' => '/adherents/class/adherent.class.php', + 'Societe' => '/societe/class/societe.class.php', + 'Categorie' => '/categories/class/categorie.class.php', + 'ActionComm' => '/comm/action/class/actioncomm.class.php', + 'Propal' => '/comm/propal/class/propal.class.php', + 'Commande' => '/commande/class/commande.class.php', + 'Facture' => '/compta/facture/class/facture.class.php', + 'FactureRec' => '/compta/facture/class/facture-rec.class.php', + 'LignePrelevement' => '/compta/prelevement/class/ligneprelevement.class.php', + 'Contact' => '/contact/class/contact.class.php', + 'Contrat' => '/contrat/class/contrat.class.php', + 'Expedition' => '/expedition/class/expedition.class.php', + 'Fichinter' => '/fichinter/class/fichinter.class.php', + 'CommandeFournisseur' => '/fourn/class/fournisseur.commande.class.php', + 'FactureFournisseur' => '/fourn/class/fournisseur.facture.class.php', + 'SupplierProposal' => '/supplier_proposal/class/supplier_proposal.class.php', + 'ProductFournisseur' => '/fourn/class/fournisseur.product.class.php', + 'Livraison' => '/livraison/class/livraison.class.php', + 'Product' => '/product/class/product.class.php', + 'Project' => '/projet/class/project.class.php', + 'User' => '/user/class/user.class.php', + ); - //First, all core objects must update their tables - foreach ($objects as $object_name => $object_file) - { - require_once DOL_DOCUMENT_ROOT.$object_file; + //First, all core objects must update their tables + foreach ($objects as $object_name => $object_file) + { + require_once DOL_DOCUMENT_ROOT.$object_file; - if (!$errors && !$object_name::replaceThirdparty($db, $soc_origin->id, $object->id)) - { - $errors++; - //setEventMessages($db->lasterror(), null, 'errors'); - } - } - } + if (!$errors && !$object_name::replaceThirdparty($db, $soc_origin->id, $object->id)) + { + $errors++; + //setEventMessages($db->lasterror(), null, 'errors'); + } + } + } - // External modules should update their ones too - if (!$errors) - { - $reshook = $hookmanager->executeHooks('replaceThirdparty', array( - 'soc_origin' => $soc_origin->id, - 'soc_dest' => $object->id - ), $soc_dest, $action); + // External modules should update their ones too + if (!$errors) + { + $reshook = $hookmanager->executeHooks('replaceThirdparty', array( + 'soc_origin' => $soc_origin->id, + 'soc_dest' => $object->id + ), $soc_dest, $action); - if ($reshook < 0) - { - //setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - $errors++; - } - } + if ($reshook < 0) + { + //setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); + $errors++; + } + } - if (! $error) - { - $object->context=array('merge'=>1, 'mergefromid'=>$soc_origin->id); + if (! $error) + { + $object->context=array('merge'=>1, 'mergefromid'=>$soc_origin->id); - // Call trigger - $result=$object->call_trigger('COMPANY_MODIFY',$user); - if ($result < 0) - { - //setEventMessages($object->error, $object->errors, 'errors'); - $error++; - } - // End call triggers - } + // Call trigger + $result=$object->call_trigger('COMPANY_MODIFY',$user); + if ($result < 0) + { + //setEventMessages($object->error, $object->errors, 'errors'); + $error++; + } + // End call triggers + } - if (! $error) - { - //We finally remove the old thirdparty - if ($soc_origin->delete($soc_origin->id, $user) < 1) - { - $errors++; - } - } + if (! $error) + { + //We finally remove the old thirdparty + if ($soc_origin->delete($soc_origin->id, $user) < 1) + { + $errors++; + } + } - // End of merge + // End of merge - if ($error) - { - $db->rollback(); + if ($error) + { + $db->rollback(); - throw new RestException(500, 'Error failed to merged thirdparty '.$this->companytoremove->id.' into '.$id.'. Enable and read log file for more information.'); - } + throw new RestException(500, 'Error failed to merged thirdparty '.$this->companytoremove->id.' into '.$id.'. Enable and read log file for more information.'); + } else { $db->commit(); } - return $this->get($id); - } + return $this->get($id); + } - /** - * Delete thirdparty - * - * @param int $id Thirparty ID - * @return integer - */ - function delete($id) - { - if(! DolibarrApiAccess::$user->rights->societe->supprimer) { - throw new RestException(401); - } - $result = $this->company->fetch($id); - if( ! $result ) { - throw new RestException(404, 'Thirdparty not found'); - } - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - return $this->company->delete($id); - } + /** + * Delete thirdparty + * + * @param int $id Thirparty ID + * @return integer + */ + function delete($id) + { + if(! DolibarrApiAccess::$user->rights->societe->supprimer) { + throw new RestException(401); + } + $result = $this->company->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + } + if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + return $this->company->delete($id); + } - /** - * Get categories for a thirdparty - * - * @param int $id ID of thirdparty - * @param string $sortfield Sort field - * @param string $sortorder Sort order - * @param int $limit Limit for list - * @param int $page Page number - * - * @return mixed - * - * @url GET {id}/categories - */ + /** + * Get customer categories for a thirdparty + * + * @param int $id ID of thirdparty + * @param string $sortfield Sort field + * @param string $sortorder Sort order + * @param int $limit Limit for list + * @param int $page Page number + * + * @return mixed + * + * @url GET {id}/categories + */ function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) { if (! DolibarrApiAccess::$user->rights->categorie->lire) { throw new RestException(401); } + $result = $this->company->fetch($id); + if( ! $result ) + { + throw new RestException(404, 'Thirdparty not found'); + } + $categories = new Categorie($this->db); $result = $categories->getListForItem($id, 'customer', $sortfield, $sortorder, $limit, $page); - if (empty($result)) { - throw new RestException(404, 'No category found'); - } - - if ($result < 0) { + if (is_numeric($result) && $result < 0) + { throw new RestException(503, 'Error when retrieve category list : '.$categories->error); } + if (is_numeric($result) && $result == 0) // To fix a return of 0 instead of empty array of method getListForItem + { + return array(); + } + return $result; - } + } - /** - * Add category to a thirdparty - * - * @param int $id Id of thirdparty - * @param array $request_data Request datas - * - * @return mixed - * - * @url POST {id}/addCategory - */ - function addCategory($id, $request_data = NULL) { - if (!isset($request_data["category_id"])) - throw new RestException(400, "category_id field missing"); - $category_id = $request_data["category_id"]; + /** + * Add a customer category to a thirdparty + * + * @param int $id Id of thirdparty + * @param int $category_id Id of category + * + * @return mixed + * + * @url POST {id}/categories/{category_id} + */ + function addCategory($id, $category_id) + { + if(! DolibarrApiAccess::$user->rights->societe->creer) { + throw new RestException(401); + } - if(! DolibarrApiAccess::$user->rights->societe->creer) { - throw new RestException(401); - } + $result = $this->company->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + } + $category = new Categorie($this->db); + $result = $category->fetch($category_id); + if( ! $result ) { + throw new RestException(404, 'category not found'); + } - $result = $this->company->fetch($id); - if( ! $result ) { - throw new RestException(404, 'Thirdparty not found'); - } - $category = new Categorie($this->db); - $result = $category->fetch($category_id); - if( ! $result ) { - throw new RestException(404, 'category not found'); - } + if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } - if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } + $category->add_type($this->company,'customer'); - $category->add_type($this->company,'customer'); - return $this->company; - } + return $this->_cleanObjectDatas($this->company); + } + + /** + * Remove the link between a customer category and the thirdparty + * + * @param int $id Id of thirdparty + * @param int $category_id Id of category + * + * @return mixed + * + * @url DELETE {id}/categories/{category_id} + */ + function deleteCategory($id, $category_id) + { + if(! DolibarrApiAccess::$user->rights->societe->creer) { + throw new RestException(401); + } + + $result = $this->company->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + } + $category = new Categorie($this->db); + $result = $category->fetch($category_id); + if( ! $result ) { + throw new RestException(404, 'category not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $category->del_type($this->company,'customer'); + + return $this->_cleanObjectDatas($this->company); + } + + /** + * Get supplier categories for a thirdparty + * + * @param int $id ID of thirdparty + * @param string $sortfield Sort field + * @param string $sortorder Sort order + * @param int $limit Limit for list + * @param int $page Page number + * + * @return mixed + * + * @url GET {id}/supplier_categories + */ + function getSupplierCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) + { + if (! DolibarrApiAccess::$user->rights->categorie->lire) { + throw new RestException(401); + } + + $result = $this->company->fetch($id); + if( ! $result ) + { + throw new RestException(404, 'Thirdparty not found'); + } + + $categories = new Categorie($this->db); + + $result = $categories->getListForItem($id, 'supplier', $sortfield, $sortorder, $limit, $page); + + if (is_numeric($result) && $result < 0) + { + throw new RestException(503, 'Error when retrieve category list : '.$categories->error); + } + + if (is_numeric($result) && $result == 0) // To fix a return of 0 instead of empty array of method getListForItem + { + return array(); + } + + return $result; + } + + /** + * Add a supplier category to a thirdparty + * + * @param int $id Id of thirdparty + * @param int $category_id Id of category + * + * @return mixed + * + * @url POST {id}/supplier_categories/{category_id} + */ + function addSupplierCategory($id, $category_id) + { + if(! DolibarrApiAccess::$user->rights->societe->creer) { + throw new RestException(401); + } + + $result = $this->company->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + } + $category = new Categorie($this->db); + $result = $category->fetch($category_id); + if( ! $result ) { + throw new RestException(404, 'category not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $category->add_type($this->company,'supplier'); + + return $this->_cleanObjectDatas($this->company); + } + + /** + * Remove the link between a category and the thirdparty + * + * @param int $id Id of thirdparty + * @param int $category_id Id of category + * + * @return mixed + * + * @url DELETE {id}/supplier_categories/{category_id} + */ + function deleteSupplierCategory($id, $category_id) + { + if(! DolibarrApiAccess::$user->rights->societe->creer) { + throw new RestException(401); + } + + $result = $this->company->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + } + $category = new Categorie($this->db); + $result = $category->fetch($category_id); + if( ! $result ) { + throw new RestException(404, 'category not found'); + } + + if( ! DolibarrApi::_checkAccessToResource('societe',$this->company->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + if( ! DolibarrApi::_checkAccessToResource('category',$category->id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } + + $category->del_type($this->company,'supplier'); + + return $this->_cleanObjectDatas($this->company); + } + /** + * Get outstanding proposals of thirdparty + * + * @param int $id ID of the thirdparty + * @param string $mode 'customer' or 'supplier' + * + * @url GET {id}/outstandingproposals + * + * @return array List of outstandings proposals of thirdparty + * + * @throws 400 + * @throws 401 + * @throws 404 + */ + function getOutStandingProposals($id, $mode='customer') + { + $obj_ret = array(); - /** - * Get outstanding proposals of thirdparty - * - * @param int $id ID of the thirdparty - * @param string $mode 'customer' or 'supplier' - * - * @url GET {id}/outstandingproposals - * - * @return array List of outstandings proposals of thirdparty - * - * @throws 400 - * @throws 401 - * @throws 404 - */ - function getOutStandingProposals($id, $mode='customer') - { - $obj_ret = array(); + if(! DolibarrApiAccess::$user->rights->societe->lire) { + throw new RestException(401); + } - if(! DolibarrApiAccess::$user->rights->societe->lire) { - throw new RestException(401); - } + if(empty($id)) { + throw new RestException(400, 'Thirdparty ID is mandatory'); + } - if(empty($id)) { - throw new RestException(400, 'Thirdparty ID is mandatory'); - } + if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } - if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } - - $result = $this->company->fetch($id); - if( ! $result ) { - throw new RestException(404, 'Thirdparty not found'); - } + $result = $this->company->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + } $result = $this->company->getOutstandingProposals($mode); @@ -595,240 +756,240 @@ class Thirdparties extends DolibarrApi unset($result['total_ttc']); return $result; - } + } - /** - * Get outstanding orders of thirdparty - * - * @param int $id ID of the thirdparty - * @param string $mode 'customer' or 'supplier' - * - * @url GET {id}/outstandingorders - * - * @return array List of outstandings orders of thirdparty - * - * @throws 400 - * @throws 401 - * @throws 404 - */ - function getOutStandingOrder($id, $mode='customer') - { - $obj_ret = array(); + /** + * Get outstanding orders of thirdparty + * + * @param int $id ID of the thirdparty + * @param string $mode 'customer' or 'supplier' + * + * @url GET {id}/outstandingorders + * + * @return array List of outstandings orders of thirdparty + * + * @throws 400 + * @throws 401 + * @throws 404 + */ + function getOutStandingOrder($id, $mode='customer') + { + $obj_ret = array(); - if(! DolibarrApiAccess::$user->rights->societe->lire) { - throw new RestException(401); - } + if(! DolibarrApiAccess::$user->rights->societe->lire) { + throw new RestException(401); + } - if(empty($id)) { - throw new RestException(400, 'Thirdparty ID is mandatory'); - } + if(empty($id)) { + throw new RestException(400, 'Thirdparty ID is mandatory'); + } - if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } + if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } - $result = $this->company->fetch($id); - if( ! $result ) { - throw new RestException(404, 'Thirdparty not found'); - } + $result = $this->company->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + } - $result = $this->company->getOutstandingOrders($mode); + $result = $this->company->getOutstandingOrders($mode); - unset($result['total_ht']); - unset($result['total_ttc']); + unset($result['total_ht']); + unset($result['total_ttc']); - return $result; - } + return $result; + } - /** - * Get outstanding invoices of thirdparty - * - * @param int $id ID of the thirdparty - * @param string $mode 'customer' or 'supplier' - * - * @url GET {id}/outstandinginvoices - * - * @return array List of outstandings invoices of thirdparty - * - * @throws 400 - * @throws 401 - * @throws 404 - */ - function getOutStandingInvoices($id, $mode='customer') - { - $obj_ret = array(); + /** + * Get outstanding invoices of thirdparty + * + * @param int $id ID of the thirdparty + * @param string $mode 'customer' or 'supplier' + * + * @url GET {id}/outstandinginvoices + * + * @return array List of outstandings invoices of thirdparty + * + * @throws 400 + * @throws 401 + * @throws 404 + */ + function getOutStandingInvoices($id, $mode='customer') + { + $obj_ret = array(); - if(! DolibarrApiAccess::$user->rights->societe->lire) { - throw new RestException(401); - } + if(! DolibarrApiAccess::$user->rights->societe->lire) { + throw new RestException(401); + } - if(empty($id)) { - throw new RestException(400, 'Thirdparty ID is mandatory'); - } + if(empty($id)) { + throw new RestException(400, 'Thirdparty ID is mandatory'); + } - if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } + if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } - $result = $this->company->fetch($id); - if( ! $result ) { - throw new RestException(404, 'Thirdparty not found'); - } + $result = $this->company->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + } - $result = $this->company->getOutstandingBills($mode); + $result = $this->company->getOutstandingBills($mode); - unset($result['total_ht']); - unset($result['total_ttc']); + unset($result['total_ht']); + unset($result['total_ttc']); - return $result; - } + return $result; + } - /** - * Get fixed amount discount of a thirdparty (all sources: deposit, credit note, commercial offers...) - * - * @param int $id ID of the thirdparty - * @param string $filter Filter exceptional discount. "none" will return every discount, "available" returns unapplied discounts, "used" returns applied discounts {@choice none,available,used} - * @param string $sortfield Sort field - * @param string $sortorder Sort order - * - * @url GET {id}/fixedamountdiscounts - * - * @return array List of fixed discount of thirdparty - * - * @throws 400 - * @throws 401 - * @throws 404 - * @throws 503 - */ - function getFixedAmountDiscounts($id, $filter="none", $sortfield = "f.type", $sortorder = 'ASC') - { - $obj_ret = array(); + /** + * Get fixed amount discount of a thirdparty (all sources: deposit, credit note, commercial offers...) + * + * @param int $id ID of the thirdparty + * @param string $filter Filter exceptional discount. "none" will return every discount, "available" returns unapplied discounts, "used" returns applied discounts {@choice none,available,used} + * @param string $sortfield Sort field + * @param string $sortorder Sort order + * + * @url GET {id}/fixedamountdiscounts + * + * @return array List of fixed discount of thirdparty + * + * @throws 400 + * @throws 401 + * @throws 404 + * @throws 503 + */ + function getFixedAmountDiscounts($id, $filter="none", $sortfield = "f.type", $sortorder = 'ASC') + { + $obj_ret = array(); - if(! DolibarrApiAccess::$user->rights->societe->lire) { - throw new RestException(401); - } + if(! DolibarrApiAccess::$user->rights->societe->lire) { + throw new RestException(401); + } - if(empty($id)) { - throw new RestException(400, 'Thirdparty ID is mandatory'); - } + if(empty($id)) { + throw new RestException(400, 'Thirdparty ID is mandatory'); + } - if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } + if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } - $result = $this->company->fetch($id); - if( ! $result ) { - throw new RestException(404, 'Thirdparty not found'); - } + $result = $this->company->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + } - $sql = "SELECT f.facnumber, f.type as factype, re.fk_facture_source, re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc, re.description, re.fk_facture, re.fk_facture_line"; - $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f"; - $sql .= " WHERE f.rowid = re.fk_facture_source AND re.fk_soc = ".$id; - if ($filter == "available") $sql .= " AND re.fk_facture IS NULL AND re.fk_facture_line IS NULL"; - if ($filter == "used") $sql .= " AND (re.fk_facture IS NOT NULL OR re.fk_facture_line IS NOT NULL)"; + $sql = "SELECT f.facnumber, f.type as factype, re.fk_facture_source, re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc, re.description, re.fk_facture, re.fk_facture_line"; + $sql .= " FROM ".MAIN_DB_PREFIX."societe_remise_except as re, ".MAIN_DB_PREFIX."facture as f"; + $sql .= " WHERE f.rowid = re.fk_facture_source AND re.fk_soc = ".$id; + if ($filter == "available") $sql .= " AND re.fk_facture IS NULL AND re.fk_facture_line IS NULL"; + if ($filter == "used") $sql .= " AND (re.fk_facture IS NOT NULL OR re.fk_facture_line IS NOT NULL)"; - $sql.= $this->db->order($sortfield, $sortorder); + $sql.= $this->db->order($sortfield, $sortorder); - $result = $this->db->query($sql); - if( ! $result ) { - throw new RestException(503, $this->db->lasterror()); - } else { - $num = $this->db->num_rows($result); - while ( $obj = $this->db->fetch_object($result) ) { - $obj_ret[] = $obj; - } - } + $result = $this->db->query($sql); + if( ! $result ) { + throw new RestException(503, $this->db->lasterror()); + } else { + $num = $this->db->num_rows($result); + while ( $obj = $this->db->fetch_object($result) ) { + $obj_ret[] = $obj; + } + } - return $obj_ret; - } + return $obj_ret; + } - /** - * Return list of invoices qualified to be replaced by another invoice. - * - * @param int $id Id of thirdparty - * - * @url GET {id}/getinvoicesqualifiedforreplacement - * - * @return array - * @throws 400 - * @throws 401 - * @throws 404 - * @throws 405 - */ - function getInvoicesQualifiedForReplacement($id) { + /** + * Return list of invoices qualified to be replaced by another invoice. + * + * @param int $id Id of thirdparty + * + * @url GET {id}/getinvoicesqualifiedforreplacement + * + * @return array + * @throws 400 + * @throws 401 + * @throws 404 + * @throws 405 + */ + function getInvoicesQualifiedForReplacement($id) { - if(! DolibarrApiAccess::$user->rights->facture->lire) { - throw new RestException(401); - } - if(empty($id)) { - throw new RestException(400, 'Thirdparty ID is mandatory'); - } + if(! DolibarrApiAccess::$user->rights->facture->lire) { + throw new RestException(401); + } + if(empty($id)) { + throw new RestException(400, 'Thirdparty ID is mandatory'); + } - if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } + if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } - /*$result = $this->thirdparty->fetch($id); - if( ! $result ) { - throw new RestException(404, 'Thirdparty not found'); - }*/ + /*$result = $this->thirdparty->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + }*/ - $invoice = new Facture($this->db); - $result = $invoice->list_replacable_invoices($id); - if( $result < 0) { - throw new RestException(405, $this->thirdparty->error); - } + $invoice = new Facture($this->db); + $result = $invoice->list_replacable_invoices($id); + if( $result < 0) { + throw new RestException(405, $this->thirdparty->error); + } - return $result; - } + return $result; + } - /** - * Return list of invoices qualified to be corrected by a credit note. - * Invoices matching the following rules are returned - * (validated + payment on process) or classified (payed completely or payed partialy) + not already replaced + not already a credit note - * - * @param int $id Id of thirdparty - * - * @url GET {id}/getinvoicesqualifiedforcreditnote - * - * @return array - * @throws 400 - * @throws 401 - * @throws 404 - * @throws 405 - */ - function getInvoicesQualifiedForCreditNote($id) { + /** + * Return list of invoices qualified to be corrected by a credit note. + * Invoices matching the following rules are returned + * (validated + payment on process) or classified (payed completely or payed partialy) + not already replaced + not already a credit note + * + * @param int $id Id of thirdparty + * + * @url GET {id}/getinvoicesqualifiedforcreditnote + * + * @return array + * @throws 400 + * @throws 401 + * @throws 404 + * @throws 405 + */ + function getInvoicesQualifiedForCreditNote($id) { - if(! DolibarrApiAccess::$user->rights->facture->lire) { - throw new RestException(401); - } - if(empty($id)) { - throw new RestException(400, 'Thirdparty ID is mandatory'); - } + if(! DolibarrApiAccess::$user->rights->facture->lire) { + throw new RestException(401); + } + if(empty($id)) { + throw new RestException(400, 'Thirdparty ID is mandatory'); + } - if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { - throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); - } + if( ! DolibarrApi::_checkAccessToResource('societe',$id)) { + throw new RestException(401, 'Access not allowed for login '.DolibarrApiAccess::$user->login); + } - /*$result = $this->thirdparty->fetch($id); - if( ! $result ) { - throw new RestException(404, 'Thirdparty not found'); - }*/ + /*$result = $this->thirdparty->fetch($id); + if( ! $result ) { + throw new RestException(404, 'Thirdparty not found'); + }*/ - $invoice = new Facture($this->db); - $result = $invoice->list_qualified_avoir_invoices($id); - if( $result < 0) { - throw new RestException(405, $this->thirdparty->error); - } + $invoice = new Facture($this->db); + $result = $invoice->list_qualified_avoir_invoices($id); + if( $result < 0) { + throw new RestException(405, $this->thirdparty->error); + } - return $result; - } + return $result; + } /** @@ -839,38 +1000,38 @@ class Thirdparties extends DolibarrApi */ function _cleanObjectDatas($object) { - $object = parent::_cleanObjectDatas($object); + $object = parent::_cleanObjectDatas($object); - unset($object->nom); // ->name already defined and nom deprecated + unset($object->nom); // ->name already defined and nom deprecated - unset($object->total_ht); - unset($object->total_tva); - unset($object->total_localtax1); - unset($object->total_localtax2); - unset($object->total_ttc); + unset($object->total_ht); + unset($object->total_tva); + unset($object->total_localtax1); + unset($object->total_localtax2); + unset($object->total_ttc); - unset($object->lines); - unset($object->thirdparty); + unset($object->lines); + unset($object->thirdparty); - return $object; + return $object; } /** - * Validate fields before create or update object - * - * @param array $data Datas to validate - * @return array - * - * @throws RestException - */ - function _validate($data) - { - $thirdparty = array(); - foreach (Thirdparties::$FIELDS as $field) { - if (!isset($data[$field])) - throw new RestException(400, "$field field missing"); - $thirdparty[$field] = $data[$field]; - } - return $thirdparty; - } + * Validate fields before create or update object + * + * @param array $data Datas to validate + * @return array + * + * @throws RestException + */ + function _validate($data) + { + $thirdparty = array(); + foreach (Thirdparties::$FIELDS as $field) { + if (!isset($data[$field])) + throw new RestException(400, "$field field missing"); + $thirdparty[$field] = $data[$field]; + } + return $thirdparty; + } } From 60a848de5a01163d17180478de233c6d80acba33 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 12 Feb 2018 04:05:13 +0100 Subject: [PATCH 043/177] Fix bad list of id for supplier categories --- htdocs/categories/class/categorie.class.php | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 5658460927c..46063c0f8c4 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -896,10 +896,14 @@ class Categorie extends CommonObject $sub_type = $type; $subcol_name = "fk_".$type; - if ($type=="customer" || $type=="supplier") { + if ($type=="customer") { $sub_type="societe"; $subcol_name="fk_soc"; } + if ($type=="supplier") { + $sub_type="fournisseur"; + $subcol_name="fk_soc"; + } if ($type=="contact") { $subcol_name="fk_socpeople"; } From 448fcae02fc36f196883460814f0df8416d2b0c8 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 12 Feb 2018 09:03:53 +0100 Subject: [PATCH 044/177] Fix: move "fournisseur" in $checksoc --- htdocs/core/lib/security.lib.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index 50ce574e271..14ff7bfdf53 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -378,11 +378,11 @@ function checkUserAccessToObject($user, $featuresarray, $objectid=0, $tableandsh if ($feature == 'task') $feature='projet_task'; $check = array('adherent','banque','user','usergroup','produit','service','produit|service','categorie'); // Test on entity only (Objects with no link to company) - $checksoc = array('societe'); // Test for societe object + $checksoc = array('societe','fournisseur'); // Test for societe object $checkother = array('contact','agenda'); // Test on entity and link to third party. Allowed if link is empty (Ex: contacts...). $checkproject = array('projet','project'); // Test for project object $checktask = array('projet_task'); - $nocheck = array('barcode','stock','fournisseur'); // No test + $nocheck = array('barcode','stock'); // No test $checkdefault = 'all other not already defined'; // Test on entity and link to third party. Not allowed if link is empty (Ex: invoice, orders...). // If dbtablename not defined, we use same name for table than module name From 24cc687724758e474d2e772a41532e252ec884e3 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 12 Feb 2018 09:28:41 +0100 Subject: [PATCH 045/177] Fix: you can't check "fournisseur" with checkUserAccessToObject without object ID --- htdocs/core/lib/security.lib.php | 2 +- htdocs/product/fournisseurs.php | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/security.lib.php b/htdocs/core/lib/security.lib.php index 14ff7bfdf53..c204809e9a1 100644 --- a/htdocs/core/lib/security.lib.php +++ b/htdocs/core/lib/security.lib.php @@ -378,7 +378,7 @@ function checkUserAccessToObject($user, $featuresarray, $objectid=0, $tableandsh if ($feature == 'task') $feature='projet_task'; $check = array('adherent','banque','user','usergroup','produit','service','produit|service','categorie'); // Test on entity only (Objects with no link to company) - $checksoc = array('societe','fournisseur'); // Test for societe object + $checksoc = array('societe'); // Test for societe object $checkother = array('contact','agenda'); // Test on entity and link to third party. Allowed if link is empty (Ex: contacts...). $checkproject = array('projet','project'); // Test for project object $checktask = array('projet_task'); diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index 2c49319fc19..9c91b5e11d7 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -51,6 +51,8 @@ $cost_price=GETPOST('cost_price', 'alpha'); $backtopage=GETPOST('backtopage','alpha'); $error=0; +if (!$user->rights->fournisseur->lire) accessforbidden(); + // If socid provided by ajax company selector if (! empty($_REQUEST['search_fourn_id'])) { @@ -63,7 +65,7 @@ if (! empty($_REQUEST['search_fourn_id'])) $fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : '')); $fieldtype = (! empty($ref) ? 'ref' : 'rowid'); if ($user->societe_id) $socid=$user->societe_id; -$result=restrictedArea($user,'produit|service&fournisseur',$fieldvalue,'product&product','','',$fieldtype); +$result=restrictedArea($user,'produit|service',$fieldvalue,'product&product','','',$fieldtype); $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit; $sortfield = GETPOST("sortfield",'alpha'); From 734bd4d2fba75eb19a4246a225177b9d9f0c1994 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 12 Feb 2018 10:15:58 +0100 Subject: [PATCH 046/177] Fix menu visible in dev only --- htdocs/core/menus/standard/auguria.lib.php | 2 +- htdocs/core/menus/standard/eldy.lib.php | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/menus/standard/auguria.lib.php b/htdocs/core/menus/standard/auguria.lib.php index 4dae9628c30..bf00f3d3ba9 100644 --- a/htdocs/core/menus/standard/auguria.lib.php +++ b/htdocs/core/menus/standard/auguria.lib.php @@ -382,7 +382,7 @@ function print_left_auguria_menu($db,$menu_array_before,$menu_array_after,&$tabM if ($objp->nature == 9) $nature="hasnew"; // To enable when page exists - if ($conf->global->MAIN_FEATURES_LEVEL >= 2) + if ($conf->global->MAIN_FEATURES_LEVEL < 2) { if ($nature == 'various' || $nature == 'hasnew') $nature=''; } diff --git a/htdocs/core/menus/standard/eldy.lib.php b/htdocs/core/menus/standard/eldy.lib.php index d2dba66c53c..077b6c8ba64 100644 --- a/htdocs/core/menus/standard/eldy.lib.php +++ b/htdocs/core/menus/standard/eldy.lib.php @@ -993,7 +993,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/accountancy/admin/export.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("ExportOptions"),2, $user->rights->accounting->chartofaccount, '', $mainmenu, 'accountancy_admin_export', 60); // Fiscal year - if ($conf->global->MAIN_FEATURES_LEVEL > 0) // Not yet used. In a future will lock some periods. + if ($conf->global->MAIN_FEATURES_LEVEL > 1) // Not yet used. In a future will lock some periods. { if ($usemenuhider || empty($leftmenu) || preg_match('/accountancy_admin/',$leftmenu)) $newmenu->add("/accountancy/admin/fiscalyear.php?mainmenu=accountancy&leftmenu=accountancy_admin", $langs->trans("FiscalPeriod"), 2, $user->rights->accounting->fiscalyear, '', $mainmenu, 'fiscalyear'); } @@ -1054,7 +1054,7 @@ function print_left_eldy_menu($db,$menu_array_before,$menu_array_after,&$tabMenu if ($objp->nature == 9) $nature="hasnew"; // To enable when page exists - if ($conf->global->MAIN_FEATURES_LEVEL >= 2) + if ($conf->global->MAIN_FEATURES_LEVEL < 2) { if ($nature == 'various' || $nature == 'hasnew') $nature=''; } From 09dfd5eb9f82e602da0dabab303b7d1eba8c6abd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 12 Feb 2018 12:02:01 +0100 Subject: [PATCH 047/177] Fix journalization protection --- htdocs/accountancy/bookkeeping/list.php | 2 +- htdocs/accountancy/customer/lines.php | 4 +- htdocs/accountancy/journal/bankjournal.php | 2 +- .../journal/expensereportsjournal.php | 3 +- .../accountancy/journal/purchasesjournal.php | 164 ++++++++++-------- htdocs/accountancy/journal/sellsjournal.php | 134 ++++++++------ htdocs/langs/en_US/accountancy.lang | 3 +- 7 files changed, 183 insertions(+), 129 deletions(-) diff --git a/htdocs/accountancy/bookkeeping/list.php b/htdocs/accountancy/bookkeeping/list.php index 42328fbc1ed..094dcd81b50 100644 --- a/htdocs/accountancy/bookkeeping/list.php +++ b/htdocs/accountancy/bookkeeping/list.php @@ -730,7 +730,7 @@ if ($num > 0) print ""; print '
'; -// TODO Replace this with mass action +// TODO Replace this with mass delete action print '
'; diff --git a/htdocs/accountancy/customer/lines.php b/htdocs/accountancy/customer/lines.php index 673e927fbeb..2d197de8c9f 100644 --- a/htdocs/accountancy/customer/lines.php +++ b/htdocs/accountancy/customer/lines.php @@ -163,7 +163,7 @@ print '