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..0fcdcd47546 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; @@ -3428,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)) { diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index 2414afd3b97..cafd59569bb 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'); @@ -869,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']; @@ -921,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 : ''; @@ -1102,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'); @@ -1152,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) { @@ -1634,7 +1646,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 +1979,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 +2051,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 +2142,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 +2179,7 @@ if (empty($reshook)) // Update line if (! $error) { - if (empty($user->rights->margins->creer)) + if (empty($usercancreatemargin)) { foreach ($object->lines as &$line) { @@ -2245,7 +2257,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 +2274,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 +2399,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 +2492,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 +2519,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 +3485,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 +3699,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 +3709,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 +3808,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 +3849,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 +3870,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 +3894,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 ''; @@ -3907,15 +3917,12 @@ else if ($id > 0 || ! empty($ref)) print ''; - 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 ''; @@ -3923,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 ''; @@ -3931,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) { @@ -3948,7 +3955,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 +3982,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 +4056,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 +4532,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 +4583,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 +4624,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 '
' . $langs->trans('Modify') . '
'; } else { @@ -4645,7 +4651,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 +4663,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 '
' . $langs->trans('Validate') . '
'; } @@ -4669,7 +4674,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 '
' . $langs->trans('SendMail') . '
'; } else print '
' . $langs->trans('SendMail') . '
'; @@ -4681,7 +4686,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 +4707,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 +4722,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 +4735,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 '
'.$langs->trans('ConvertExcessReceivedToReduc').'
'; } // 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 '
' . $langs->trans('ConvertToReduc') . '
'; } // 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 '
'.$langs->trans('ConvertToReduc').'
'; } } // 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 '
'.$langs->trans('ClassifyPaid').'
'; @@ -4755,7 +4760,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 +4784,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 '
' . $langs->trans("ToClone") . '
'; } // 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 +4799,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 +4810,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 '
' . $langs->trans("CreateCreditNote") . '
'; } else { @@ -4823,12 +4827,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 +4845,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 '
' . $langs->trans('CreateNextSituationInvoice') . '
'; } else if (!$object->is_last_in_cycle()) { @@ -4854,7 +4857,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 +4904,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 +4914,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) ) { 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/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..88217172c76 100644 --- a/htdocs/core/modules/facture/mod_facture_mercure.php +++ b/htdocs/core/modules/facture/mod_facture_mercure.php @@ -131,19 +131,19 @@ 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) + if (is_object($invoice) && $invoice->type == 1) { $mask=$conf->global->FACTURE_MERCURE_MASK_REPLACEMENT; if (! $mask) @@ -151,8 +151,8 @@ class mod_facture_mercure extends ModeleNumRefFactures $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 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) { @@ -160,14 +160,17 @@ class mod_facture_mercure extends ModeleNumRefFactures 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,$invoice->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 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..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) { @@ -149,8 +143,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";
'; print $langs->trans('RevenueStamp'); print 'id . '">' . img_edit($langs->trans('SetRevenuStamp'), 1) . '