From 04edcaa89cf2face4f4fa99d9504b8dc0257a5a1 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Tue, 13 Nov 2018 20:20:46 +0100 Subject: [PATCH 1/9] FIX compatibility between proposal sharing and proposalnumber sharing --- htdocs/comm/propal/card.php | 1 + htdocs/comm/propal/class/propal.class.php | 3 ++- htdocs/core/lib/functions2.lib.php | 6 +++--- htdocs/core/modules/propale/mod_propale_marbre.php | 5 +---- htdocs/core/modules/propale/mod_propale_saphir.php | 4 ++-- htdocs/user/class/user.class.php | 4 ++-- 6 files changed, 11 insertions(+), 12 deletions(-) diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 0ef90e7da0a..b472d197657 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -380,6 +380,7 @@ if (empty($reshook)) } } else { $object->ref = GETPOST('ref'); + $object->entity = (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity); $object->ref_client = GETPOST('ref_client'); $object->datep = $datep; $object->date_livraison = $date_delivery; diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 871508f1aa4..f94ea38675a 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -874,6 +874,7 @@ class Propal extends CommonObject $now=dol_now(); // Clean parameters + if (empty($this->entity)) $this->entity = $conf->entity; if (empty($this->date)) $this->date=$this->datep; $this->fin_validite = $this->date + ($this->duree_validite * 24 * 3600); if (empty($this->availability_id)) $this->availability_id=0; @@ -983,7 +984,7 @@ class Propal extends CommonObject $sql.= ", ".($this->fk_project?$this->fk_project:"null"); $sql.= ", ".(int) $this->fk_incoterms; $sql.= ", '".$this->db->escape($this->location_incoterms)."'"; - $sql.= ", ".$conf->entity; + $sql.= ", ".$this->entity; $sql.= ", ".(int) $this->fk_multicurrency; $sql.= ", '".$this->db->escape($this->multicurrency_code)."'"; $sql.= ", ".(double) $this->multicurrency_tx; diff --git a/htdocs/core/lib/functions2.lib.php b/htdocs/core/lib/functions2.lib.php index ee88cd95404..aae70adfb62 100644 --- a/htdocs/core/lib/functions2.lib.php +++ b/htdocs/core/lib/functions2.lib.php @@ -990,7 +990,7 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m if ($bentityon) // only if entity enable $sql.= " AND entity IN (".getEntity($sharetable).")"; else if (! empty($forceentity)) - $sql.= " AND entity = ".(int) $forceentity; + $sql.= " AND entity IN (".$forceentity.")"; if ($where) $sql.=$where; if ($sqlwhere) $sql.=' AND '.$sqlwhere; @@ -1039,7 +1039,7 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m if ($bentityon) // only if entity enable $sql.= " AND entity IN (".getEntity($sharetable).")"; else if (! empty($forceentity)) - $sql.= " AND entity = ".(int) $forceentity; + $sql.= " AND entity IN (".$forceentity.")"; if ($where) $sql.=$where; if ($sqlwhere) $sql.=' AND '.$sqlwhere; @@ -1095,7 +1095,7 @@ function get_next_value($db,$mask,$table,$field,$where='',$objsoc='',$date='',$m if ($bentityon) // only if entity enable $maskrefclient_sql.= " AND entity IN (".getEntity($sharetable).")"; else if (! empty($forceentity)) - $sql.= " AND entity = ".(int) $forceentity; + $sql.= " AND entity IN (".$forceentity.")"; if ($where) $maskrefclient_sql.=$where; //use the same optional where as general mask if ($sqlwhere) $maskrefclient_sql.=' AND '.$sqlwhere; //use the same sqlwhere as general mask $maskrefclient_sql.=' AND (SUBSTRING('.$field.', '.(strpos($maskwithnocode,$maskrefclient)+1).', '.dol_strlen($maskrefclient_maskclientcode).")='".$maskrefclient_clientcode."')"; diff --git a/htdocs/core/modules/propale/mod_propale_marbre.php b/htdocs/core/modules/propale/mod_propale_marbre.php index ef91cf1d2f3..cb1638aec82 100644 --- a/htdocs/core/modules/propale/mod_propale_marbre.php +++ b/htdocs/core/modules/propale/mod_propale_marbre.php @@ -128,15 +128,12 @@ class mod_propale_marbre extends ModeleNumRefPropales { global $db,$conf; - // Use object entity ID - $entity = ((isset($propal->entity) && is_numeric($propal->entity)) ? $propal->entity : $conf->entity); - // D'abord on recupere la valeur max $posindice=8; $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL $sql.= " FROM ".MAIN_DB_PREFIX."propal"; $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; - $sql.= " AND entity = ".$entity; + $sql.= " AND entity IN (".getEntity('proposalnumber', 1, $propal).")"; $resql=$db->query($sql); if ($resql) diff --git a/htdocs/core/modules/propale/mod_propale_saphir.php b/htdocs/core/modules/propale/mod_propale_saphir.php index 47f71b5ffed..c91f9eb529c 100644 --- a/htdocs/core/modules/propale/mod_propale_saphir.php +++ b/htdocs/core/modules/propale/mod_propale_saphir.php @@ -149,8 +149,8 @@ class mod_propale_saphir extends ModeleNumRefPropales return 0; } - // Use object entity ID - $entity = ((isset($propal->entity) && is_numeric($propal->entity)) ? $propal->entity : $conf->entity); + // Get entities + $entity = getEntity('proposalnumber', 1, $propal); $date = $propal->date; diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 9e790437cb7..23f8b09169d 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -764,7 +764,7 @@ class User extends CommonObject // Recuperation des droits utilisateurs + recuperation des droits groupes // D'abord les droits utilisateurs - $sql = "SELECT r.module, r.perms, r.subperms"; + $sql = "SELECT DISTINCT r.module, r.perms, r.subperms"; $sql.= " FROM ".MAIN_DB_PREFIX."user_rights as ur"; $sql.= ", ".MAIN_DB_PREFIX."rights_def as r"; $sql.= " WHERE r.id = ur.fk_id"; @@ -818,7 +818,7 @@ class User extends CommonObject } // Maintenant les droits groupes - $sql = "SELECT r.module, r.perms, r.subperms"; + $sql = "SELECT DISTINCT r.module, r.perms, r.subperms"; $sql.= " FROM ".MAIN_DB_PREFIX."usergroup_rights as gr,"; $sql.= " ".MAIN_DB_PREFIX."usergroup_user as gu,"; $sql.= " ".MAIN_DB_PREFIX."rights_def as r"; From 3294fada3d06ff422dbe168d0b5f3c6b27fac9c9 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 14 Nov 2018 14:59:36 +0100 Subject: [PATCH 2/9] FIX working on invoice sharing (multicompany) --- htdocs/compta/facture/card.php | 192 +++++++++++++++++---------------- 1 file changed, 97 insertions(+), 95 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 2414afd3b97..73f0c87d574 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -109,9 +109,23 @@ if ($id > 0 || ! empty($ref)) { // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('invoicecard','globalcard')); -$permissionnote = $user->rights->facture->creer; // Used by the include of actions_setnotes.inc.php -$permissiondellink=$user->rights->facture->creer; // Used by the include of actions_dellink.inc.php -$permissiontoedit = $user->rights->facture->creer; // Used by the include of actions_lineupdonw.inc.php +$usercanread = $user->rights->facture->lire; +$usercancreate = $user->rights->facture->creer; +$usercanissuepayment = $user->rights->facture->paiement; +$usercandelete = $user->rights->facture->supprimer; +$usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->validate))); +$usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->send); +$usercanreopen = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->reopen); +$usercanunvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($usercancreate)) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->unvalidate))); + +$usercanproductignorepricemin = ((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS)); +$usercancreatemargin = $user->rights->margins->creer; +$usercanreadallmargin = $user->rights->margins->liretous; +$usercancreatewithdrarequest = $user->rights->prelevement->bons->creer; + +$permissionnote = $usercancreate; // Used by the include of actions_setnotes.inc.php +$permissiondellink = $usercancreate; // Used by the include of actions_dellink.inc.php +$permissiontoedit = $usercancreate; // Used by the include of actions_lineupdonw.inc.php // Security check $fieldid = (! empty($ref) ? 'facnumber' : 'rowid'); @@ -147,7 +161,7 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once // Action clone object - if ($action == 'confirm_clone' && $confirm == 'yes' && $user->rights->facture->creer) { + if ($action == 'confirm_clone' && $confirm == 'yes' && $usercancreate) { // if (1 == 0 && empty($_REQUEST["clone_content"]) && empty($_REQUEST["clone_receivers"])) { // $mesgs [] = '
' . $langs->trans("NoCloneOptionsSpecified") . '
'; // } else { @@ -165,7 +179,7 @@ if (empty($reshook)) } // Change status of invoice - else if ($action == 'reopen' && $user->rights->facture->creer) { + else if ($action == 'reopen' && $usercancreate) { $result = $object->fetch($id); if ($object->statut == 2 || ($object->statut == 3 && $object->close_code != 'replaced') || ($object->statut == 1 && $object->paye == 1)) { // ($object->statut == 1 && $object->paye == 1) should not happened but can be found when data are corrupted $result = $object->set_unpaid($user); @@ -194,8 +208,8 @@ if (empty($reshook)) $isErasable=$object->is_erasable(); - if (($user->rights->facture->supprimer && $isErasable > 0) - || ($user->rights->facture->creer && $isErasable == 1)) + if (($usercandelete && $isErasable > 0) + || ($usercancreate && $isErasable == 1)) { $result = $object->delete($user, 0, $idwarehouse); if ($result > 0) { @@ -209,7 +223,7 @@ if (empty($reshook)) } // Delete line - else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->facture->creer) + else if ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) { $object->fetch($id); $object->fetch_thirdparty(); @@ -243,7 +257,7 @@ if (empty($reshook)) } // Delete link of credit note to invoice - else if ($action == 'unlinkdiscount' && $user->rights->facture->creer) + else if ($action == 'unlinkdiscount' && $usercancreate) { $discount = new DiscountAbsolute($db); $result = $discount->fetch(GETPOST("discountid")); @@ -251,7 +265,7 @@ if (empty($reshook)) } // Validation - else if ($action == 'valid' && $user->rights->facture->creer) + else if ($action == 'valid' && $usercancreate) { $object->fetch($id); @@ -271,7 +285,7 @@ if (empty($reshook)) } } - else if ($action == 'set_thirdparty' && $user->rights->facture->creer) + else if ($action == 'set_thirdparty' && $usercancreate) { $object->fetch($id); $object->setValueFrom('fk_soc', $socid, '', null, 'int', '', $user, 'BILL_MODIFY'); @@ -280,13 +294,13 @@ if (empty($reshook)) exit(); } - else if ($action == 'classin' && $user->rights->facture->creer) + else if ($action == 'classin' && $usercancreate) { $object->fetch($id); $object->setProject($_POST['projectid']); } - else if ($action == 'setmode' && $user->rights->facture->creer) + else if ($action == 'setmode' && $usercancreate) { $object->fetch($id); $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); @@ -295,16 +309,16 @@ if (empty($reshook)) } // Multicurrency Code - else if ($action == 'setmulticurrencycode' && $user->rights->facture->creer) { + else if ($action == 'setmulticurrencycode' && $usercancreate) { $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha')); } // Multicurrency rate - else if ($action == 'setmulticurrencyrate' && $user->rights->facture->creer) { + else if ($action == 'setmulticurrencyrate' && $usercancreate) { $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx')), GETPOST('calculation_mode', 'int')); } - else if ($action == 'setinvoicedate' && $user->rights->facture->creer) + else if ($action == 'setinvoicedate' && $usercancreate) { $object->fetch($id); $old_date_lim_reglement = $object->date_lim_reglement; @@ -323,7 +337,7 @@ if (empty($reshook)) if ($result < 0) dol_print_error($db, $object->error); } - else if ($action == 'setdate_pointoftax' && $user->rights->facture->creer) + else if ($action == 'setdate_pointoftax' && $usercancreate) { $object->fetch($id); $date_pointoftax = dol_mktime(12, 0, 0, $_POST['date_pointoftaxmonth'], $_POST['date_pointoftaxday'], $_POST['date_pointoftaxyear']); @@ -332,7 +346,7 @@ if (empty($reshook)) if ($result < 0) dol_print_error($db, $object->error); } - else if ($action == 'setconditions' && $user->rights->facture->creer) + else if ($action == 'setconditions' && $usercancreate) { $object->fetch($id); $object->cond_reglement_code = 0; // To clean property @@ -348,7 +362,7 @@ if (empty($reshook)) if ($result < 0) dol_print_error($db, $object->error); } - else if ($action == 'setpaymentterm' && $user->rights->facture->creer) + else if ($action == 'setpaymentterm' && $usercancreate) { $object->fetch($id); $object->date_lim_reglement = dol_mktime(12, 0, 0, $_POST['paymenttermmonth'], $_POST['paymenttermday'], $_POST['paymenttermyear']); @@ -361,7 +375,7 @@ if (empty($reshook)) dol_print_error($db, $object->error); } - else if ($action == 'setrevenuestamp' && $user->rights->facture->creer) + else if ($action == 'setrevenuestamp' && $usercancreate) { $object->fetch($id); $object->revenuestamp = GETPOST('revenuestamp'); @@ -378,18 +392,18 @@ if (empty($reshook)) } // bank account - else if ($action == 'setbankaccount' && $user->rights->facture->creer) + else if ($action == 'setbankaccount' && $usercancreate) { $result=$object->setBankAccount(GETPOST('fk_account', 'int')); } - else if ($action == 'setremisepercent' && $user->rights->facture->creer) + else if ($action == 'setremisepercent' && $usercancreate) { $object->fetch($id); $result = $object->set_remise($user, $_POST['remise_percent']); } - else if ($action == "setabsolutediscount" && $user->rights->facture->creer) + else if ($action == "setabsolutediscount" && $usercancreate) { // POST[remise_id] or POST[remise_id_for_payment] @@ -447,17 +461,14 @@ if (empty($reshook)) } } - else if ($action == 'setref_client' && $user->rights->facture->creer) + else if ($action == 'setref_client' && $usercancreate) { $object->fetch($id); $object->set_ref_client(GETPOST('ref_client')); } // Classify to validated - else if ($action == 'confirm_valid' && $confirm == 'yes' && - ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->validate))) - ) + else if ($action == 'confirm_valid' && $confirm == 'yes' && $usercanvalidate) { $idwarehouse = GETPOST('idwarehouse','int'); @@ -557,10 +568,7 @@ if (empty($reshook)) } // Go back to draft status (unvalidate) - else if ($action == 'confirm_modif' && - ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->unvalidate))) - ) + else if ($action == 'confirm_modif' && $usercanunvalidate) { $idwarehouse = GETPOST('idwarehouse','int'); @@ -640,13 +648,13 @@ if (empty($reshook)) } // Classify "paid" - else if ($action == 'confirm_paid' && $confirm == 'yes' && $user->rights->facture->paiement) + else if ($action == 'confirm_paid' && $confirm == 'yes' && $usercanissuepayment) { $object->fetch($id); $result = $object->set_paid($user); if ($result<0) setEventMessages($object->error, $object->errors, 'errors'); } // Classif "paid partialy" - else if ($action == 'confirm_paid_partially' && $confirm == 'yes' && $user->rights->facture->paiement) + else if ($action == 'confirm_paid_partially' && $confirm == 'yes' && $usercanissuepayment) { $object->fetch($id); $close_code = GETPOST("close_code",'none'); @@ -671,7 +679,7 @@ if (empty($reshook)) } // Convertir en reduc - else if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $user->rights->facture->creer) + else if ($action == 'confirm_converttoreduc' && $confirm == 'yes' && $usercancreate) { $object->fetch($id); $object->fetch_thirdparty(); @@ -797,7 +805,7 @@ if (empty($reshook)) } // Delete payment - elseif ($action == 'confirm_delete_paiement' && $confirm == 'yes' && $user->rights->facture->creer) + elseif ($action == 'confirm_delete_paiement' && $confirm == 'yes' && $usercancreate) { $object->fetch($id); if ($object->statut == Facture::STATUS_VALIDATED && $object->paye == 0) @@ -817,7 +825,7 @@ if (empty($reshook)) /* * Insert new invoice in database */ - else if ($action == 'add' && $user->rights->facture->creer) + else if ($action == 'add' && $usercancreate) { if ($socid > 0) $object->socid = GETPOST('socid', 'int'); @@ -1634,7 +1642,7 @@ if (empty($reshook)) } // Add a new line - else if ($action == 'addline' && $user->rights->facture->creer) + else if ($action == 'addline' && $usercancreate) { $langs->load('errors'); $error = 0; @@ -1967,7 +1975,7 @@ if (empty($reshook)) if ($tva_npr) $info_bits |= 0x01; - if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS) )&& (! empty($price_min) && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min)))) { + if ($usercanproductignorepricemin && (! empty($price_min) && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min)))) { $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)); setEventMessages($mesg, null, 'errors'); } else { @@ -2039,7 +2047,7 @@ if (empty($reshook)) } } - elseif ($action == 'updateline' && $user->rights->facture->creer && ! GETPOST('cancel','alpha')) + elseif ($action == 'updateline' && $usercancreate && ! GETPOST('cancel','alpha')) { if (! $object->fetch($id) > 0) dol_print_error($db); $object->fetch_thirdparty(); @@ -2130,7 +2138,7 @@ if (empty($reshook)) $label = ((GETPOST('update_label') && GETPOST('product_label')) ? GETPOST('product_label') : ''); // Check price is not lower than minimum (check is done only for standard or replacement invoices) - if (((!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->produit->ignore_price_min_advance)) || empty($conf->global->MAIN_USE_ADVANCED_PERMS) ) && (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT) && $price_min && (price2num($pu_ht) * (1 - price2num(GETPOST('remise_percent')) / 100) < price2num($price_min)))) { + if ($usercanproductignorepricemin && (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT) && $price_min && (price2num($pu_ht) * (1 - price2num(GETPOST('remise_percent')) / 100) < price2num($price_min)))) { setEventMessages($langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)), null, 'errors'); $error++; } @@ -2167,7 +2175,7 @@ if (empty($reshook)) // Update line if (! $error) { - if (empty($user->rights->margins->creer)) + if (empty($usercancreatemargin)) { foreach ($object->lines as &$line) { @@ -2245,7 +2253,7 @@ if (empty($reshook)) } } - else if ($action == 'updatealllines' && $user->rights->facture->creer && $_POST['all_percent'] == $langs->trans('Modifier')) + else if ($action == 'updatealllines' && $usercancreate && $_POST['all_percent'] == $langs->trans('Modifier')) { if (!$object->fetch($id) > 0) dol_print_error($db); if (!is_null(GETPOST('all_progress')) && GETPOST('all_progress') != "") @@ -2262,23 +2270,22 @@ if (empty($reshook)) } } - else if ($action == 'updateline' && $user->rights->facture->creer && $_POST['cancel'] == $langs->trans('Cancel')) { + else if ($action == 'updateline' && $usercancreate && $_POST['cancel'] == $langs->trans('Cancel')) { header('Location: ' . $_SERVER["PHP_SELF"] . '?facid=' . $id); // Pour reaffichage de la fiche en cours d'edition exit(); } // Outing situation invoice from cycle - elseif ($action == 'confirm_situationout' && $confirm == 'yes' && $user->rights->facture->creer) + elseif ($action == 'confirm_situationout' && $confirm == 'yes' && $usercancreate) { $object->fetch($id,'', '','', true); if ($object->statut == Facture::STATUS_VALIDATED && $object->type == Facture::TYPE_SITUATION - && $user->rights->facture->creer + && $usercancreate && !$objectidnext && $object->is_last_in_cycle() - && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->unvalidate))) + && $usercanunvalidate ) { $outingError = 0; @@ -2388,7 +2395,7 @@ if (empty($reshook)) // add lines from objectlinked elseif($action == 'import_lines_from_object' - && $user->rights->facture->creer + && $usercancreate && $object->statut == Facture::STATUS_DRAFT && ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA || $object->type == Facture::TYPE_SITUATION)) { @@ -2481,7 +2488,7 @@ if (empty($reshook)) // Actions to build doc $upload_dir = $conf->facture->dir_output; - $permissioncreate=$user->rights->facture->creer; + $permissioncreate=$usercancreate; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; @@ -2508,7 +2515,7 @@ if (empty($reshook)) $action = 'edit_extras'; } - if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->facture->creer) { + if (! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) { if ($action == 'addcontact') { $result = $object->fetch($id); @@ -3474,11 +3481,10 @@ else if ($id > 0 || ! empty($ref)) $formquestion = array(); // remove situation from cycle if ($object->statut == Facture::STATUS_VALIDATED - && $user->rights->facture->creer + && $usercancreate && !$objectidnext && $object->is_last_in_cycle() - && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->unvalidate))) + && $usercanunvalidate ) { $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $label, $text, 'confirm_situationout', $formquestion, "yes", 1); @@ -3689,8 +3695,8 @@ else if ($id > 0 || ! empty($ref)) $morehtmlref='
'; // Ref customer - $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', 0, 1); - $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->facture->creer, 'string', '', null, null, '', 1); + $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $usercancreate, 'string', '', 0, 1); + $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $usercancreate, 'string', '', null, null, '', 1); // Thirdparty $morehtmlref.='
'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1,'customer'); if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref.=' ('.$langs->trans("OtherBills").')'; @@ -3699,7 +3705,7 @@ else if ($id > 0 || ! empty($ref)) { $langs->load("projects"); $morehtmlref.='
'.$langs->trans('Project') . ' '; - if ($user->rights->facture->creer) + if ($usercancreate) { if ($action != 'classify') $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; @@ -3798,7 +3804,7 @@ else if ($id > 0 || ! empty($ref)) print ''; - if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editinvoicedate' && ! empty($object->brouillon) && $user->rights->facture->creer && empty($conf->global->FAC_FORCE_DATE_VALIDATION)) + if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editinvoicedate' && ! empty($object->brouillon) && $usercancreate && empty($conf->global->FAC_FORCE_DATE_VALIDATION)) print ''; print '
'; print $langs->trans('DateInvoice'); print 'id . '">' . img_edit($langs->trans('SetDate'), 1) . '
'; print ''; @@ -3839,7 +3845,7 @@ else if ($id > 0 || ! empty($ref)) print ''; - if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editconditions' && $user->rights->facture->creer) + if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editconditions' && $usercancreate) print ''; print '
'; print $langs->trans('PaymentConditionsShort'); print 'id . '">' . img_edit($langs->trans('SetConditions'), 1) . '
'; print ''; @@ -3860,7 +3866,7 @@ else if ($id > 0 || ! empty($ref)) print ''; - if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editpaymentterm' && $user->rights->facture->creer) + if ($object->type != Facture::TYPE_CREDIT_NOTE && $action != 'editpaymentterm' && $usercancreate) print ''; print '
'; print $langs->trans('DateMaxPayment'); print 'id . '">' . img_edit($langs->trans('SetDate'), 1) . '
'; print ''; @@ -3884,7 +3890,7 @@ else if ($id > 0 || ! empty($ref)) print ''; - if ($action != 'editmode' && $user->rights->facture->creer) + if ($action != 'editmode' && $usercancreate) print ''; print '
'; print $langs->trans('PaymentMode'); print 'id . '">' . img_edit($langs->trans('SetMode'), 1) . '
'; print ''; @@ -3948,7 +3954,7 @@ else if ($id > 0 || ! empty($ref)) print ''; print '
'; print $langs->trans('BankAccount'); print ''; - if (($action != 'editbankaccount') && $user->rights->facture->creer) + if (($action != 'editbankaccount') && $usercancreate) print 'id.'">'.img_edit($langs->trans('SetBankAccount'),1).'
'; print ''; @@ -3975,7 +3981,7 @@ else if ($id > 0 || ! empty($ref)) print '
'; print $langs->trans('IncotermLabel'); print ''; - if ($user->rights->facture->creer) print ''.img_edit().''; + if ($usercancreate) print ''.img_edit().''; else print ' '; print '
'; print ''; @@ -4049,7 +4055,7 @@ else if ($id > 0 || ! empty($ref)) print ''; - if ($action != 'editrevenuestamp' && ! empty($object->brouillon) && $user->rights->facture->creer) + if ($action != 'editrevenuestamp' && ! empty($object->brouillon) && $usercancreate) { print ''; } @@ -4525,7 +4531,7 @@ else if ($id > 0 || ! empty($ref)) if (! empty($conf->margin->enabled) && empty($user->societe_id)) { print ''; - if ((! empty($conf->global->DISPLAY_MARGIN_RATES) || ! empty($conf->global->DISPLAY_MARK_RATES)) && $user->rights->margins->liretous) { + if ((! empty($conf->global->DISPLAY_MARGIN_RATES) || ! empty($conf->global->DISPLAY_MARK_RATES)) && $usercanreadallmargin) { print ''; } } @@ -4576,7 +4582,7 @@ else if ($id > 0 || ! empty($ref)) $ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 1); // Form to add new line - if ($object->statut == 0 && $user->rights->facture->creer && $action != 'valid' && $action != 'editline' && ($object->is_first() || !$object->situation_cycle_ref)) + if ($object->statut == 0 && $usercancreate && $action != 'valid' && $action != 'editline' && ($object->is_first() || !$object->situation_cycle_ref)) { if ($action != 'editline' && $action != 'selectlines') { @@ -4617,8 +4623,7 @@ else if ($id > 0 || ! empty($ref)) { if (! $objectidnext && $object->is_last_in_cycle()) { - if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->unvalidate))) + if ($usercanunvalidate) { print ''; } else { @@ -4645,7 +4650,7 @@ else if ($id > 0 || ! empty($ref)) || ($object->type == Facture::TYPE_CREDIT_NOTE && empty($discount->id)) || ($object->type == Facture::TYPE_DEPOSIT && empty($discount->id))) && ($object->statut == 2 || $object->statut == 3 || ($object->statut == 1 && $object->paye == 1)) // Condition ($object->statut == 1 && $object->paye == 1) should not happened but can be found due to corrupted data - && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->facture->creer) || (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $user->rights->facture->invoice_advance->reopen))) // A paid invoice (partially or completely) + && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || $usercanreopen)) // A paid invoice (partially or completely) { if (! $objectidnext && $object->close_code != 'replaced') // Not replaced by another invoice { @@ -4657,8 +4662,7 @@ else if ($id > 0 || ! empty($ref)) // Validate if ($object->statut == Facture::STATUS_DRAFT && count($object->lines) > 0 && ((($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA || $object->type == Facture::TYPE_SITUATION) && (! empty($conf->global->FACTURE_ENABLE_NEGATIVE) || $object->total_ttc >= 0)) || ($object->type == Facture::TYPE_CREDIT_NOTE && $object->total_ttc <= 0))) { - if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->validate))) + if ($usercanvalidate) { print ''; } @@ -4669,7 +4673,7 @@ else if ($id > 0 || ! empty($ref)) if ($objectidnext) { print '
' . $langs->trans('SendMail') . '
'; } else { - if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->facture->invoice_advance->send) { + if ($usercansend) { print ''; } else print ''; @@ -4681,7 +4685,7 @@ else if ($id > 0 || ! empty($ref)) { if ($resteapayer > 0) { - if ($user->rights->prelevement->bons->creer) + if ($usercancreatewithdrarequest) { if (! $objectidnext && $object->close_code != 'replaced') // Not replaced by another invoice { @@ -4702,7 +4706,7 @@ else if ($id > 0 || ! empty($ref)) } // Create payment - if ($object->type != Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement) { + if ($object->type != Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $usercanissuepayment) { if ($objectidnext) { print '
' . $langs->trans('DoPayment') . '
'; } else { @@ -4717,7 +4721,7 @@ else if ($id > 0 || ! empty($ref)) // Reverse back money or convert to reduction if ($object->type == Facture::TYPE_CREDIT_NOTE || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_STANDARD) { // For credit note only - if ($object->type == Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement) + if ($object->type == Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $usercanissuepayment) { if ($resteapayer == 0) { @@ -4730,24 +4734,24 @@ else if ($id > 0 || ! empty($ref)) } // For standard invoice with excess received - if ($object->type == Facture::TYPE_STANDARD && empty($object->paye) && ($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits) < 0 && $user->rights->facture->creer && empty($discount->id)) + if ($object->type == Facture::TYPE_STANDARD && empty($object->paye) && ($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits) < 0 && $usercancreate && empty($discount->id)) { print ''; } // For credit note - if ($object->type == Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $user->rights->facture->creer && $object->getSommePaiement() == 0) { + if ($object->type == Facture::TYPE_CREDIT_NOTE && $object->statut == 1 && $object->paye == 0 && $usercancreate && $object->getSommePaiement() == 0) { print ''; } // For deposit invoice - if ($object->type == Facture::TYPE_DEPOSIT && $user->rights->facture->creer && $object->statut > 0 && empty($discount->id)) + if ($object->type == Facture::TYPE_DEPOSIT && $usercancreate && $object->statut > 0 && empty($discount->id)) { print ''; } } // Classify paid - if ($object->statut == 1 && $object->paye == 0 && $user->rights->facture->paiement && (($object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT && $resteapayer <= 0) || ($object->type == Facture::TYPE_CREDIT_NOTE && $resteapayer >= 0)) - || ($object->type == Facture::TYPE_DEPOSIT && $object->paye == 0 && $object->total_ttc > 0 && $resteapayer == 0 && $user->rights->facture->paiement && empty($discount->id)) + if ($object->statut == 1 && $object->paye == 0 && $usercanissuepayment && (($object->type != Facture::TYPE_CREDIT_NOTE && $object->type != Facture::TYPE_DEPOSIT && $resteapayer <= 0) || ($object->type == Facture::TYPE_CREDIT_NOTE && $resteapayer >= 0)) + || ($object->type == Facture::TYPE_DEPOSIT && $object->paye == 0 && $object->total_ttc > 0 && $resteapayer == 0 && $usercanissuepayment && empty($discount->id)) ) { print ''; @@ -4755,7 +4759,7 @@ else if ($id > 0 || ! empty($ref)) // Classify 'closed not completely paid' (possible si validee et pas encore classee payee) - if ($object->statut == 1 && $object->paye == 0 && $resteapayer > 0 && $user->rights->facture->paiement) + if ($object->statut == 1 && $object->paye == 0 && $resteapayer > 0 && $usercanissuepayment) { if ($totalpaye > 0 || $totalcreditnotes > 0) { @@ -4779,13 +4783,13 @@ else if ($id > 0 || ! empty($ref)) } // Clone - if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA) && $user->rights->facture->creer) + if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA) && $usercancreate) { print ''; } // Clone as predefined / Create template - if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA) && $object->statut == 0 && $user->rights->facture->creer) + if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA) && $object->statut == 0 && $usercancreate) { if (! $objectidnext && count($object->lines) > 0) { @@ -4794,7 +4798,7 @@ else if ($id > 0 || ! empty($ref)) } // Create a credit note - if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA) && $object->statut > 0 && $user->rights->facture->creer) + if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA) && $object->statut > 0 && $usercancreate) { if (! $objectidnext) { @@ -4805,14 +4809,13 @@ else if ($id > 0 || ! empty($ref)) // For situation invoice with excess received if ($object->statut > Facture::STATUS_DRAFT && ($object->total_ttc - $totalpaye - $totalcreditnotes - $totaldeposits) > 0 - && $user->rights->facture->creer + && $usercancreate && !$objectidnext && $object->is_last_in_cycle() && $conf->global->INVOICE_USE_SITUATION_CREDIT_NOTE ) { - if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->unvalidate))) + if ($usercanunvalidate) { print ''; } else { @@ -4823,12 +4826,11 @@ else if ($id > 0 || ! empty($ref)) // remove situation from cycle if ($object->statut > Facture::STATUS_DRAFT && $object->type == Facture::TYPE_SITUATION - && $user->rights->facture->creer + && $usercancreate && !$objectidnext && $object->situation_counter > 1 && $object->is_last_in_cycle() - && ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->facture->invoice_advance->unvalidate))) + && $usercanunvalidate ) { if(($object->total_ttc - $totalcreditnotes ) == 0 ) @@ -4842,7 +4844,7 @@ else if ($id > 0 || ! empty($ref)) } // Create next situation invoice - if ($user->rights->facture->creer && ($object->type == 5) && ($object->statut == 1 || $object->statut == 2)) { + if ($usercancreate && ($object->type == 5) && ($object->statut == 1 || $object->statut == 2)) { if ($object->is_last_in_cycle() && $object->situation_final != 1) { print ''; } else if (!$object->is_last_in_cycle()) { @@ -4854,7 +4856,7 @@ else if ($id > 0 || ! empty($ref)) // Delete $isErasable = $object->is_erasable(); - if ($user->rights->facture->supprimer || ($user->rights->facture->creer && $isErasable == 1)) // isErasable = 1 means draft with temporary ref (draft can always be deleted with no need of permissions) + if ($usercandelete || ($usercancreate && $isErasable == 1)) // isErasable = 1 means draft with temporary ref (draft can always be deleted with no need of permissions) { //var_dump($isErasable); if ($isErasable == -4) { @@ -4901,8 +4903,8 @@ else if ($id > 0 || ! empty($ref)) $filename = dol_sanitizeFileName($object->ref); $filedir = $conf->facture->dir_output . '/' . dol_sanitizeFileName($object->ref); $urlsource = $_SERVER['PHP_SELF'] . '?facid=' . $object->id; - $genallowed = $user->rights->facture->lire; - $delallowed = $user->rights->facture->creer; + $genallowed = $usercanread; + $delallowed = $usercancreate; print $formfile->showdocuments('facture', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang); $somethingshown = $formfile->numoffiles; @@ -4911,7 +4913,7 @@ else if ($id > 0 || ! empty($ref)) $linktoelem = $form->showLinkToObjectBlock($object, null, array('invoice')); $compatibleImportElementsList = false; - if($user->rights->facture->creer + if($usercancreate && $object->statut == Facture::STATUS_DRAFT && ($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA || $object->type == Facture::TYPE_SITUATION) ) { From 9ff4b31843835b8e1cd18ecc7c572106ff86bff8 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 14 Nov 2018 15:24:22 +0100 Subject: [PATCH 3/9] FIX compatibility with invoice sharing and invoice number sharing --- .../core/modules/facture/mod_facture_mars.php | 18 ++-- .../modules/facture/mod_facture_mercure.php | 90 +++++++++++++------ .../modules/facture/mod_facture_terre.php | 14 +-- 3 files changed, 78 insertions(+), 44 deletions(-) diff --git a/htdocs/core/modules/facture/mod_facture_mars.php b/htdocs/core/modules/facture/mod_facture_mars.php index 2bdad538ec9..19161ae1325 100644 --- a/htdocs/core/modules/facture/mod_facture_mars.php +++ b/htdocs/core/modules/facture/mod_facture_mars.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005-2015 Regis Houssin + * Copyright (C) 2005-2018 Regis Houssin * Copyright (C) 2013 Juanjo Menent * * This program is free software; you can redistribute it and/or modify @@ -145,19 +145,19 @@ class mod_facture_mars extends ModeleNumRefFactures * Return next value not used or last value used * * @param Societe $objsoc Object third party - * @param Facture $facture Object invoice + * @param Facture $invoice Object invoice * @param string $mode 'next' for next value or 'last' for last value * @return string Value */ - function getNextValue($objsoc,$facture,$mode='next') + function getNextValue($objsoc, $invoice, $mode='next') { global $db; $prefix=$this->prefixinvoice; - if ($facture->type == 1) $prefix=$this->prefixreplacement; - else if ($facture->type == 2) $prefix=$this->prefixcreditnote; - else if ($facture->type == 3) $prefix=$this->prefixdeposit; + if ($invoice->type == 1) $prefix=$this->prefixreplacement; + else if ($invoice->type == 2) $prefix=$this->prefixcreditnote; + else if ($invoice->type == 3) $prefix=$this->prefixdeposit; else $prefix=$this->prefixinvoice; // D'abord on recupere la valeur max @@ -165,7 +165,7 @@ class mod_facture_mars extends ModeleNumRefFactures $sql = "SELECT MAX(CAST(SUBSTRING(facnumber FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL $sql.= " FROM ".MAIN_DB_PREFIX."facture"; $sql.= " WHERE facnumber LIKE '".$prefix."____-%'"; - $sql.= " AND entity IN (".getEntity('invoicenumber').")"; + $sql.= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")"; $resql=$db->query($sql); dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG); @@ -189,7 +189,7 @@ class mod_facture_mars extends ModeleNumRefFactures $sql = "SELECT facnumber as ref"; $sql.= " FROM ".MAIN_DB_PREFIX."facture"; $sql.= " WHERE facnumber LIKE '".$prefix."____-".$num."'"; - $sql.= " AND entity IN (".getEntity('invoicenumber').")"; + $sql.= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")"; dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG); $resql=$db->query($sql); @@ -204,7 +204,7 @@ class mod_facture_mars extends ModeleNumRefFactures } else if ($mode == 'next') { - $date=$facture->date; // This is invoice date (not creation date) + $date=$invoice->date; // This is invoice date (not creation date) $yymm = strftime("%y%m",$date); if ($max >= (pow(10, 4) - 1)) $num=$max+1; // If counter > 9999, we do not format on 4 chars, we take number as it is diff --git a/htdocs/core/modules/facture/mod_facture_mercure.php b/htdocs/core/modules/facture/mod_facture_mercure.php index 95e60c78398..e2e64988b4a 100644 --- a/htdocs/core/modules/facture/mod_facture_mercure.php +++ b/htdocs/core/modules/facture/mod_facture_mercure.php @@ -131,43 +131,77 @@ class mod_facture_mercure extends ModeleNumRefFactures * Return next value * * @param Societe $objsoc Object third party - * @param Facture $facture Object invoice + * @param Facture $invoice Object invoice * @param string $mode 'next' for next value or 'last' for last value * @return string Value if OK, 0 if KO */ - function getNextValue($objsoc,$facture,$mode='next') + function getNextValue($objsoc, $invoice, $mode='next') { - global $db,$conf; + global $db,$conf; - require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; + require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; - // Get Mask value - $mask = ''; - if (is_object($facture) && $facture->type == 1) - { - $mask=$conf->global->FACTURE_MERCURE_MASK_REPLACEMENT; - if (! $mask) - { - $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE; - } - } - else if (is_object($facture) && $facture->type == 2) $mask=$conf->global->FACTURE_MERCURE_MASK_CREDIT; - else if (is_object($facture) && $facture->type == 3) $mask=$conf->global->FACTURE_MERCURE_MASK_DEPOSIT; - else $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE; - if (! $mask) - { - $this->error='NotConfigured'; - return 0; - } + // Get Mask value + $mask = ''; + if (is_object($invoice) && $invoice->type == 1) + { + $constant = 'FACTURE_MERCURE_MASK_REPLACEMENT_'.$invoice->entity; + if (! empty($conf->global->$constant)) { + $mask = $conf->global->$constant; // for multicompany proposal sharing + } else { + $mask=$conf->global->FACTURE_MERCURE_MASK_REPLACEMENT; + } + if (! $mask) + { + $constant = 'FACTURE_MERCURE_MASK_INVOICE_'.$invoice->entity; + if (! empty($conf->global->$constant)) { + $mask = $conf->global->$constant; // for multicompany proposal sharing + } else { + $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE; + } + } + } + else if (is_object($invoice) && $invoice->type == 2){ + $constant = 'FACTURE_MERCURE_MASK_CREDIT_'.$invoice->entity; + if (! empty($conf->global->$constant)) { + $mask = $conf->global->$constant; // for multicompany proposal sharing + } else { + $mask=$conf->global->FACTURE_MERCURE_MASK_CREDIT; + } + } + else if (is_object($invoice) && $invoice->type == 3){ + $constant = 'FACTURE_MERCURE_MASK_DEPOSIT_'.$invoice->entity; + if (! empty($conf->global->$constant)) { + $mask = $conf->global->$constant; // for multicompany proposal sharing + } else { + $mask=$conf->global->FACTURE_MERCURE_MASK_DEPOSIT; + } + } + else { + $constant = 'FACTURE_MERCURE_MASK_INVOICE_'.$invoice->entity; + if (! empty($conf->global->$constant)) { + $mask = $conf->global->$constant; // for multicompany proposal sharing + } else { + $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE; + } + } + if (! $mask) + { + $this->error='NotConfigured'; + return 0; + } - $where=''; - //if ($facture->type == 2) $where.= " AND type = 2"; - //else $where.=" AND type != 2"; + $where=''; + //if ($facture->type == 2) $where.= " AND type = 2"; + //else $where.=" AND type != 2"; - $numFinal=get_next_value($db,$mask,'facture','facnumber',$where,$objsoc,$facture->date,$mode); - if (! preg_match('/([0-9])+/',$numFinal)) $this->error = $numFinal; + // Get entities + $entity = getEntity('invoicenumber', 1, $invoice); - return $numFinal; + $numFinal=get_next_value($db,$mask,'facture','facnumber',$where,$objsoc,$facture->date,$mode,false,null,$entity); + if (! preg_match('/([0-9])+/',$numFinal)) $this->error = $numFinal; + + return $numFinal; } diff --git a/htdocs/core/modules/facture/mod_facture_terre.php b/htdocs/core/modules/facture/mod_facture_terre.php index 4442451984f..1c19d564486 100644 --- a/htdocs/core/modules/facture/mod_facture_terre.php +++ b/htdocs/core/modules/facture/mod_facture_terre.php @@ -163,16 +163,16 @@ class mod_facture_terre extends ModeleNumRefFactures * Return next value not used or last value used * * @param Societe $objsoc Object third party - * @param Facture $facture Object invoice + * @param Facture $invoice Object invoice * @param string $mode 'next' for next value or 'last' for last value * @return string Value */ - function getNextValue($objsoc,$facture,$mode='next') + function getNextValue($objsoc, $invoice, $mode='next') { global $db; - if ($facture->type == 2) $prefix=$this->prefixcreditnote; - else if ($facture->type == 3) $prefix=$this->prefixdeposit; + if ($invoice->type == 2) $prefix=$this->prefixcreditnote; + else if ($invoice->type == 3) $prefix=$this->prefixdeposit; else $prefix=$this->prefixinvoice; // D'abord on recupere la valeur max @@ -180,7 +180,7 @@ class mod_facture_terre extends ModeleNumRefFactures $sql = "SELECT MAX(CAST(SUBSTRING(facnumber FROM ".$posindice.") AS SIGNED)) as max"; // This is standard SQL $sql.= " FROM ".MAIN_DB_PREFIX."facture"; $sql.= " WHERE facnumber LIKE '".$prefix."____-%'"; - $sql.= " AND entity IN (".getEntity('invoicenumber').")"; + $sql.= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")"; $resql=$db->query($sql); dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG); @@ -204,7 +204,7 @@ class mod_facture_terre extends ModeleNumRefFactures $sql = "SELECT facnumber as ref"; $sql.= " FROM ".MAIN_DB_PREFIX."facture"; $sql.= " WHERE facnumber LIKE '".$prefix."____-".$num."'"; - $sql.= " AND entity IN (".getEntity('invoicenumber').")"; + $sql.= " AND entity IN (".getEntity('invoicenumber', 1, $invoice).")"; dol_syslog(get_class($this)."::getNextValue", LOG_DEBUG); $resql=$db->query($sql); @@ -219,7 +219,7 @@ class mod_facture_terre extends ModeleNumRefFactures } else if ($mode == 'next') { - $date=$facture->date; // This is invoice date (not creation date) + $date=$invoice->date; // This is invoice date (not creation date) $yymm = strftime("%y%m",$date); if ($max >= (pow(10, 4) - 1)) $num=$max+1; // If counter > 9999, we do not format on 4 chars, we take number as it is From 93a1e941a410f10c1c83c2b3e501546bfc6cf8ff Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 14 Nov 2018 15:34:39 +0100 Subject: [PATCH 4/9] FIX new method: override constants of current entity --- .../modules/facture/mod_facture_mercure.php | 67 +++++-------------- 1 file changed, 18 insertions(+), 49 deletions(-) diff --git a/htdocs/core/modules/facture/mod_facture_mercure.php b/htdocs/core/modules/facture/mod_facture_mercure.php index e2e64988b4a..15a3d371915 100644 --- a/htdocs/core/modules/facture/mod_facture_mercure.php +++ b/htdocs/core/modules/facture/mod_facture_mercure.php @@ -141,55 +141,24 @@ class mod_facture_mercure extends ModeleNumRefFactures require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; - // Get Mask value - $mask = ''; - if (is_object($invoice) && $invoice->type == 1) - { - $constant = 'FACTURE_MERCURE_MASK_REPLACEMENT_'.$invoice->entity; - if (! empty($conf->global->$constant)) { - $mask = $conf->global->$constant; // for multicompany proposal sharing - } else { - $mask=$conf->global->FACTURE_MERCURE_MASK_REPLACEMENT; - } - if (! $mask) - { - $constant = 'FACTURE_MERCURE_MASK_INVOICE_'.$invoice->entity; - if (! empty($conf->global->$constant)) { - $mask = $conf->global->$constant; // for multicompany proposal sharing - } else { - $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE; - } - } - } - else if (is_object($invoice) && $invoice->type == 2){ - $constant = 'FACTURE_MERCURE_MASK_CREDIT_'.$invoice->entity; - if (! empty($conf->global->$constant)) { - $mask = $conf->global->$constant; // for multicompany proposal sharing - } else { - $mask=$conf->global->FACTURE_MERCURE_MASK_CREDIT; - } - } - else if (is_object($invoice) && $invoice->type == 3){ - $constant = 'FACTURE_MERCURE_MASK_DEPOSIT_'.$invoice->entity; - if (! empty($conf->global->$constant)) { - $mask = $conf->global->$constant; // for multicompany proposal sharing - } else { - $mask=$conf->global->FACTURE_MERCURE_MASK_DEPOSIT; - } - } - else { - $constant = 'FACTURE_MERCURE_MASK_INVOICE_'.$invoice->entity; - if (! empty($conf->global->$constant)) { - $mask = $conf->global->$constant; // for multicompany proposal sharing - } else { - $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE; - } - } - if (! $mask) - { - $this->error='NotConfigured'; - return 0; - } + // Get Mask value + $mask = ''; + if (is_object($invoice) && $invoice->type == 1) + { + $mask=$conf->global->FACTURE_MERCURE_MASK_REPLACEMENT; + if (! $mask) + { + $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE; + } + } + else if (is_object($invoice) && $invoice->type == 2) $mask=$conf->global->FACTURE_MERCURE_MASK_CREDIT; + else if (is_object($invoice) && $invoice->type == 3) $mask=$conf->global->FACTURE_MERCURE_MASK_DEPOSIT; + else $mask=$conf->global->FACTURE_MERCURE_MASK_INVOICE; + if (! $mask) + { + $this->error='NotConfigured'; + return 0; + } $where=''; //if ($facture->type == 2) $where.= " AND type = 2"; From 874e27ef84d106311cb84d718288fe4e41400862 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 14 Nov 2018 15:37:10 +0100 Subject: [PATCH 5/9] FIX multicompany override constants of current entity --- htdocs/core/modules/propale/mod_propale_saphir.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/htdocs/core/modules/propale/mod_propale_saphir.php b/htdocs/core/modules/propale/mod_propale_saphir.php index c91f9eb529c..87fcc7c2920 100644 --- a/htdocs/core/modules/propale/mod_propale_saphir.php +++ b/htdocs/core/modules/propale/mod_propale_saphir.php @@ -134,14 +134,8 @@ class mod_propale_saphir extends ModeleNumRefPropales require_once DOL_DOCUMENT_ROOT .'/core/lib/functions2.lib.php'; - $constant = 'PROPALE_SAPHIR_MASK_'.$propal->entity; - // On defini critere recherche compteur - if (! empty($conf->global->$constant)) { - $mask = $conf->global->$constant; // for multicompany proposal sharing - } else { - $mask = $conf->global->PROPALE_SAPHIR_MASK; - } + $mask = $conf->global->PROPALE_SAPHIR_MASK; if (! $mask) { From 0592e8a31c43a132663cf2e3f6492421cd3d25bd Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 14 Nov 2018 16:44:10 +0100 Subject: [PATCH 6/9] FIX config is override by multicompany module --- htdocs/comm/propal/class/propal.class.php | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index f94ea38675a..0fcdcd47546 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -3429,13 +3429,7 @@ class Propal extends CommonObject global $conf,$langs; $langs->load("propal"); - $constant = 'PROPALE_ADDON_'.$this->entity; - - if (! empty($conf->global->$constant)) { - $classname = $conf->global->$constant; // for multicompany proposal sharing - } else { - $classname = $conf->global->PROPALE_ADDON; - } + $classname = $conf->global->PROPALE_ADDON; if (! empty($classname)) { From 0907a6d6115ebaa82b8b93c20c002d4b6989b9f4 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 14 Nov 2018 16:55:14 +0100 Subject: [PATCH 7/9] FIX wrong object name (travis error) --- htdocs/core/modules/facture/mod_facture_mercure.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/facture/mod_facture_mercure.php b/htdocs/core/modules/facture/mod_facture_mercure.php index 15a3d371915..88217172c76 100644 --- a/htdocs/core/modules/facture/mod_facture_mercure.php +++ b/htdocs/core/modules/facture/mod_facture_mercure.php @@ -167,7 +167,7 @@ class mod_facture_mercure extends ModeleNumRefFactures // Get entities $entity = getEntity('invoicenumber', 1, $invoice); - $numFinal=get_next_value($db,$mask,'facture','facnumber',$where,$objsoc,$facture->date,$mode,false,null,$entity); + $numFinal=get_next_value($db,$mask,'facture','facnumber',$where,$objsoc,$invoice->date,$mode,false,null,$entity); if (! preg_match('/([0-9])+/',$numFinal)) $this->error = $numFinal; return $numFinal; From 976094043b5e5f3c85dfe9ac56cb4f802a897606 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 14 Nov 2018 17:34:27 +0100 Subject: [PATCH 8/9] FIX missing GETPOST('entity') --- htdocs/compta/facture/card.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 73f0c87d574..5d1c5b92f2b 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -877,6 +877,7 @@ if (empty($reshook)) $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha'); $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int'); + $object->entity = (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity); // Proprietes particulieres a facture de remplacement $object->fk_facture_source = $_POST['fac_replacement']; @@ -929,6 +930,7 @@ if (empty($reshook)) $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha'); $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int'); + $object->entity = (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity); // Proprietes particulieres a facture avoir $object->fk_facture_source = $sourceinvoice > 0 ? $sourceinvoice : ''; @@ -1110,6 +1112,7 @@ if (empty($reshook)) $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha'); $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int'); + $object->entity = (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity); // Source facture $object->fac_rec = GETPOST('fac_rec', 'int'); @@ -1160,6 +1163,7 @@ if (empty($reshook)) $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha'); $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int'); + $object->entity = (GETPOSTISSET('entity')?GETPOST('entity', 'int'):$conf->entity); if (GETPOST('type') == Facture::TYPE_SITUATION) { From 6f90516f577922b0ffb394d294c29920ce6af73c Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Thu, 15 Nov 2018 09:40:08 +0100 Subject: [PATCH 9/9] FIX check write permission for multicurrency --- htdocs/compta/facture/card.php | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 5d1c5b92f2b..cafd59569bb 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -3917,15 +3917,12 @@ else if ($id > 0 || ! empty($ref)) print '
'; print $langs->trans('RevenueStamp'); print 'id . '">' . img_edit($langs->trans('SetRevenuStamp'), 1) . '  
'; - if ($action != 'editmulticurrencycode' && ! empty($object->brouillon)) + if ($usercancreate && $action != 'editmulticurrencycode' && ! empty($object->brouillon)) print ''; print '
'; print fieldLabel('Currency','multicurrency_code'); print 'id . '">' . img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1) . '
'; print ''; - if ($action == 'editmulticurrencycode') { - $form->form_multicurrency_code($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_code, 'multicurrency_code'); - } else { - $form->form_multicurrency_code($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_code, 'none'); - } + $htmlname = (($usercancreate && $action == 'editmulticurrencycode')?'multicurrency_code':'none'); + $form->form_multicurrency_code($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_code, $htmlname); print ''; print ''; @@ -3933,7 +3930,7 @@ else if ($id > 0 || ! empty($ref)) print ''; - if ($action != 'editmulticurrencyrate' && ! empty($object->brouillon) && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) + if ($usercancreate && $action != 'editmulticurrencyrate' && ! empty($object->brouillon) && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) print ''; print '
'; print fieldLabel('CurrencyRate','multicurrency_tx'); print 'id . '">' . img_edit($langs->transnoentitiesnoconv('SetMultiCurrencyCode'), 1) . '
'; print ''; @@ -3941,7 +3938,7 @@ else if ($id > 0 || ! empty($ref)) if($action == 'actualizemulticurrencyrate') { list($object->fk_multicurrency, $object->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($object->db, $object->multicurrency_code); } - $form->form_multicurrency_rate($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_tx, 'multicurrency_tx', $object->multicurrency_code); + $form->form_multicurrency_rate($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_tx, ($usercancreate?'multicurrency_tx':'none'), $object->multicurrency_code); } else { $form->form_multicurrency_rate($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->multicurrency_tx, 'none', $object->multicurrency_code); if($object->statut == $object::STATUS_DRAFT && $object->multicurrency_code && $object->multicurrency_code != $conf->currency) {