diff --git a/htdocs/comm/propal/card.php b/htdocs/comm/propal/card.php index 8b52aedcaad..2ae67888658 100644 --- a/htdocs/comm/propal/card.php +++ b/htdocs/comm/propal/card.php @@ -380,7 +380,6 @@ 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 4767db0e5ad..c5164b4e4ec 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -890,7 +890,6 @@ 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; @@ -1000,7 +999,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.= ", ".$this->entity; + $sql.= ", ".setEntity($this); $sql.= ", ".(int) $this->fk_multicurrency; $sql.= ", '".$this->db->escape($this->multicurrency_code)."'"; $sql.= ", ".(double) $this->multicurrency_tx; @@ -1083,7 +1082,7 @@ class Propal extends CommonObject $vatrate = $line->tva_tx; if ($line->vat_src_code && ! preg_match('/\(.*\)/', $vatrate)) $vatrate.=' ('.$line->vat_src_code.')'; - $result = $this->addline( + $result = $this->addline( $line->desc, $line->subprice, $line->qty, @@ -1130,7 +1129,7 @@ class Propal extends CommonObject $sql = "UPDATE ".MAIN_DB_PREFIX."propal"; $sql.= " SET fk_delivery_address = ".$this->fk_delivery_address; $sql.= " WHERE ref = '".$this->db->escape($this->ref)."'"; - $sql.= " AND entity = ".$conf->entity; + $sql.= " AND entity = ".setEntity($this); $result=$this->db->query($sql); } diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php index c6af61acab9..2964ff98690 100644 --- a/htdocs/comm/propal/list.php +++ b/htdocs/comm/propal/list.php @@ -1062,7 +1062,7 @@ if ($resql) // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; // Fields from hook - $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj); + $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i); $reshook=$hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; // Date creation diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 0f875b68f22..a44054cdfd0 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -96,9 +96,17 @@ include DOL_DOCUMENT_ROOT.'/core/actions_fetchobject.inc.php'; // Must be inclu // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context $hookmanager->initHooks(array('ordercard','globalcard')); -$permissionnote = $user->rights->commande->creer; // Used by the include of actions_setnotes.inc.php -$permissiondellink = $user->rights->commande->creer; // Used by the include of actions_dellink.inc.php -$permissionedit = $user->rights->commande->creer; // Used by the include of actions_lineupdown.inc.php +$usercanread = $user->rights->commande->lire; +$usercancreate = $user->rights->commande->creer; +$usercanclose = $user->rights->commande->cloturer; +$usercandelete = $user->rights->commande->supprimer; +$usercanvalidate = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->order_advance->validate))); +$usercancancel = ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && $usercancreate) || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->order_advance->annuler))); +$usercansend = (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->commande->order_advance->send); + +$permissionnote = $usercancreate; // Used by the include of actions_setnotes.inc.php +$permissiondellink = $usercancreate; // Used by the include of actions_dellink.inc.php +$permissionedit = $usercancreate; // Used by the include of actions_lineupdown.inc.php /* @@ -129,7 +137,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->commande->creer) + if ($action == 'confirm_clone' && $confirm == 'yes' && $usercancreate) { if (1==0 && ! GETPOST('clone_content') && ! GETPOST('clone_receivers')) { @@ -159,7 +167,7 @@ if (empty($reshook)) } // Reopen a closed order - elseif ($action == 'reopen' && $user->rights->commande->creer) + elseif ($action == 'reopen' && $usercancreate) { if ($object->statut == Commande::STATUS_CANCELED || $object->statut == Commande::STATUS_CLOSED) { @@ -176,7 +184,7 @@ if (empty($reshook)) } // Remove order - elseif ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->commande->supprimer) + elseif ($action == 'confirm_delete' && $confirm == 'yes' && $usercandelete) { $result = $object->delete($user); if ($result > 0) @@ -191,7 +199,7 @@ if (empty($reshook)) } // Remove a product line - elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->commande->creer) + elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) { $result = $object->deleteline($user, $lineid); if ($result > 0) @@ -222,13 +230,13 @@ if (empty($reshook)) } // Link to a project - elseif ($action == 'classin' && $user->rights->commande->creer) + elseif ($action == 'classin' && $usercancreate) { $object->setProject(GETPOST('projectid', 'int')); } // Add order - elseif ($action == 'add' && $user->rights->commande->creer) + elseif ($action == 'add' && $usercancreate) { $datecommande = dol_mktime(12, 0, 0, GETPOST('remonth'), GETPOST('reday'), GETPOST('reyear')); $datelivraison = dol_mktime(12, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year')); @@ -481,7 +489,7 @@ if (empty($reshook)) } } - elseif ($action == 'classifybilled' && $user->rights->commande->creer) + elseif ($action == 'classifybilled' && $usercancreate) { $ret=$object->classifyBilled($user); @@ -489,7 +497,7 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } - elseif ($action == 'classifyunbilled' && $user->rights->commande->creer) + elseif ($action == 'classifyunbilled' && $usercancreate) { $ret=$object->classifyUnBilled(); if ($ret < 0) { @@ -498,7 +506,7 @@ if (empty($reshook)) } // Positionne ref commande client - elseif ($action == 'setref_client' && $user->rights->commande->creer) { + elseif ($action == 'setref_client' && $usercancreate) { $result = $object->set_ref_client($user, GETPOST('ref_client')); if ($result < 0) { @@ -506,7 +514,7 @@ if (empty($reshook)) } } - elseif ($action == 'setremise' && $user->rights->commande->creer) { + elseif ($action == 'setremise' && $usercancreate) { $result = $object->set_remise($user, GETPOST('remise')); if ($result < 0) { @@ -514,7 +522,7 @@ if (empty($reshook)) } } - elseif ($action == 'setabsolutediscount' && $user->rights->commande->creer) { + elseif ($action == 'setabsolutediscount' && $usercancreate) { if (GETPOST('remise_id')) { if ($object->id > 0) { $object->insert_discount(GETPOST('remise_id')); @@ -524,7 +532,7 @@ if (empty($reshook)) } } - elseif ($action == 'setdate' && $user->rights->commande->creer) { + elseif ($action == 'setdate' && $usercancreate) { // print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year']; $date = dol_mktime(0, 0, 0, GETPOST('order_month'), GETPOST('order_day'), GETPOST('order_year')); @@ -534,7 +542,7 @@ if (empty($reshook)) } } - elseif ($action == 'setdate_livraison' && $user->rights->commande->creer) { + elseif ($action == 'setdate_livraison' && $usercancreate) { // print "x ".$_POST['liv_month'].", ".$_POST['liv_day'].", ".$_POST['liv_year']; $datelivraison = dol_mktime(0, 0, 0, GETPOST('liv_month'), GETPOST('liv_day'), GETPOST('liv_year')); @@ -544,35 +552,35 @@ if (empty($reshook)) } } - elseif ($action == 'setmode' && $user->rights->commande->creer) { + elseif ($action == 'setmode' && $usercancreate) { $result = $object->setPaymentMethods(GETPOST('mode_reglement_id', 'int')); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } // Multicurrency Code - elseif ($action == 'setmulticurrencycode' && $user->rights->commande->creer) { + elseif ($action == 'setmulticurrencycode' && $usercancreate) { $result = $object->setMulticurrencyCode(GETPOST('multicurrency_code', 'alpha')); } // Multicurrency rate - elseif ($action == 'setmulticurrencyrate' && $user->rights->commande->creer) { + elseif ($action == 'setmulticurrencyrate' && $usercancreate) { $result = $object->setMulticurrencyRate(price2num(GETPOST('multicurrency_tx'))); } - elseif ($action == 'setavailability' && $user->rights->commande->creer) { + elseif ($action == 'setavailability' && $usercancreate) { $result = $object->availability(GETPOST('availability_id')); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } - elseif ($action == 'setdemandreason' && $user->rights->commande->creer) { + elseif ($action == 'setdemandreason' && $usercancreate) { $result = $object->demand_reason(GETPOST('demand_reason_id')); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } - elseif ($action == 'setconditions' && $user->rights->commande->creer) { + elseif ($action == 'setconditions' && $usercancreate) { $result = $object->setPaymentTerms(GETPOST('cond_reglement_id', 'int')); if ($result < 0) { dol_print_error($db, $object->error); @@ -604,7 +612,7 @@ if (empty($reshook)) } // bank account - elseif ($action == 'setbankaccount' && $user->rights->commande->creer) { + elseif ($action == 'setbankaccount' && $usercancreate) { $result=$object->setBankAccount(GETPOST('fk_account', 'int')); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); @@ -612,7 +620,7 @@ if (empty($reshook)) } // shipping method - elseif ($action == 'setshippingmethod' && $user->rights->commande->creer) { + elseif ($action == 'setshippingmethod' && $usercancreate) { $result = $object->setShippingMethod(GETPOST('shipping_method_id', 'int')); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); @@ -620,23 +628,23 @@ if (empty($reshook)) } // warehouse - elseif ($action == 'setwarehouse' && $user->rights->commande->creer) { + elseif ($action == 'setwarehouse' && $usercancreate) { $result = $object->setWarehouse(GETPOST('warehouse_id', 'int')); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } } - elseif ($action == 'setremisepercent' && $user->rights->commande->creer) { + elseif ($action == 'setremisepercent' && $usercancreate) { $result = $object->set_remise($user, GETPOST('remise_percent')); } - elseif ($action == 'setremiseabsolue' && $user->rights->commande->creer) { + elseif ($action == 'setremiseabsolue' && $usercancreate) { $result = $object->set_remise_absolue($user, GETPOST('remise_absolue')); } // Add a new line - elseif ($action == 'addline' && $user->rights->commande->creer) + elseif ($action == 'addline' && $usercancreate) { $langs->load('errors'); $error = 0; @@ -999,7 +1007,7 @@ if (empty($reshook)) /* * Update a line */ - elseif ($action == 'updateline' && $user->rights->commande->creer && GETPOST('save')) + elseif ($action == 'updateline' && $usercancreate && GETPOST('save')) { // Clean parameters $date_start=''; @@ -1133,15 +1141,12 @@ if (empty($reshook)) setEventMessages($object->error, $object->errors, 'errors'); } } - } elseif ($action == 'updateline' && $user->rights->commande->creer && GETPOST('cancel', 'alpha') == $langs->trans('Cancel')) { + } elseif ($action == 'updateline' && $usercancreate && GETPOST('cancel', 'alpha') == $langs->trans('Cancel')) { header('Location: ' . $_SERVER['PHP_SELF'] . '?id=' . $object->id); // Pour reaffichage de la fiche en cours d'edition exit(); } - elseif ($action == 'confirm_validate' && $confirm == 'yes' && - ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->order_advance->validate))) - ) + elseif ($action == 'confirm_validate' && $confirm == 'yes' && $usercanvalidate) { $idwarehouse = GETPOST('idwarehouse'); @@ -1195,7 +1200,7 @@ if (empty($reshook)) } // Go back to draft status - elseif ($action == 'confirm_modif' && $user->rights->commande->creer) { + elseif ($action == 'confirm_modif' && $usercancreate) { $idwarehouse = GETPOST('idwarehouse'); $qualified_for_stock_change=0; @@ -1243,17 +1248,14 @@ if (empty($reshook)) } } - elseif ($action == 'confirm_shipped' && $confirm == 'yes' && $user->rights->commande->cloturer) { + elseif ($action == 'confirm_shipped' && $confirm == 'yes' && $usercanclose) { $result = $object->cloture($user); if ($result < 0) { setEventMessages($object->error, $object->errors, 'errors'); } } - elseif ($action == 'confirm_cancel' && $confirm == 'yes' && - ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->order_advance->validate))) - ) + elseif ($action == 'confirm_cancel' && $confirm == 'yes' && $usercanvalidate) { $idwarehouse = GETPOST('idwarehouse'); @@ -1310,7 +1312,7 @@ if (empty($reshook)) if ($error) $action = 'edit_extras'; } - if ($action == 'set_thirdparty' && $user->rights->commande->creer) + if ($action == 'set_thirdparty' && $usercancreate) { $object->fetch($id); $object->setValueFrom('fk_soc', $socid, '', '', 'date', '', $user, 'ORDER_MODIFY'); @@ -1321,7 +1323,7 @@ if (empty($reshook)) // add lines from objectlinked if($action == 'import_lines_from_object' - && $user->rights->commande->creer + && $usercancreate && $object->statut == Commande::STATUS_DRAFT ) { @@ -1405,8 +1407,8 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; // Actions to build doc - $upload_dir = $conf->commande->dir_output; - $permissioncreate = $user->rights->commande->creer; + $upload_dir = $conf->commande->multidir_output[$object->entity]; + $permissioncreate = $usercancreate; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; // Actions to send emails @@ -1417,7 +1419,7 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; - if (! $error && ! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $user->rights->commande->creer) + if (! $error && ! empty($conf->global->MAIN_DISABLE_CONTACTS_TAB) && $usercancreate) { if ($action == 'addcontact') { @@ -1478,7 +1480,7 @@ $formmargin = new FormMargin($db); if (! empty($conf->projet->enabled)) { $formproject = new FormProjets($db); } // Mode creation -if ($action == 'create' && $user->rights->commande->creer) +if ($action == 'create' && $usercancreate) { print load_fiche_titre($langs->trans('CreateOrder'), '', 'title_commercial.png'); @@ -2069,8 +2071,8 @@ if ($action == 'create' && $user->rights->commande->creer) $morehtmlref='
'; // Ref customer - $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->commande->creer, 'string', '', 0, 1); - $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, $user->rights->commande->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') . ' : ' . $soc->getNomUrl(1); if (empty($conf->global->MAIN_DISABLE_OTHER_LINK) && $object->thirdparty->id > 0) $morehtmlref.=' ('.$langs->trans("OtherOrders").')'; @@ -2079,7 +2081,7 @@ if ($action == 'create' && $user->rights->commande->creer) { $langs->load("projects"); $morehtmlref.='
'.$langs->trans('Project') . ' '; - if ($user->rights->commande->creer) + if ($usercancreate) { if ($action != 'classify') $morehtmlref.='' . img_edit($langs->transnoentitiesnoconv('SetProject')) . ' : '; @@ -2159,7 +2161,7 @@ if ($action == 'create' && $user->rights->commande->creer) // Date print ''; - $editenable = $user->rights->commande->creer && $object->statut == Commande::STATUS_DRAFT; + $editenable = $usercancreate && $object->statut == Commande::STATUS_DRAFT; print $form->editfieldkey("Date", 'date', '', $object, $editenable); print ''; if ($action == 'editdate') { @@ -2180,7 +2182,7 @@ if ($action == 'create' && $user->rights->commande->creer) // Delivery date planed print ''; - $editenable = $user->rights->commande->creer; + $editenable = $usercancreate; print $form->editfieldkey("DateDeliveryPlanned", 'date_livraison', '', $object, $editenable); print ''; if ($action == 'editdate_livraison') { @@ -2202,7 +2204,7 @@ if ($action == 'create' && $user->rights->commande->creer) // Shipping Method if (! empty($conf->expedition->enabled)) { print ''; - $editenable = $user->rights->commande->creer; + $editenable = $usercancreate; print $form->editfieldkey("SendingMethod", 'shippingmethod', '', $object, $editenable); print ''; if ($action == 'editshippingmethod') { @@ -2220,7 +2222,7 @@ if ($action == 'create' && $user->rights->commande->creer) require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; $formproduct=new FormProduct($db); print ''; - $editenable = $user->rights->commande->creer; + $editenable = $usercancreate; print $form->editfieldkey("Warehouse", 'warehouse', '', $object, $editenable); print ''; if ($action == 'editwarehouse') { @@ -2234,7 +2236,7 @@ if ($action == 'create' && $user->rights->commande->creer) // Terms of payment print ''; - $editenable = $user->rights->commande->creer; + $editenable = $usercancreate; print $form->editfieldkey("PaymentConditionsShort", 'conditions', '', $object, $editenable); print ''; if ($action == 'editconditions') { @@ -2248,7 +2250,7 @@ if ($action == 'create' && $user->rights->commande->creer) // Mode of payment print ''; - $editenable = $user->rights->commande->creer; + $editenable = $usercancreate; print $form->editfieldkey("PaymentMode", 'mode', '', $object, $editenable); print ''; if ($action == 'editmode') { @@ -2264,7 +2266,7 @@ if ($action == 'create' && $user->rights->commande->creer) // Multicurrency code print ''; print ''; - $editenable = $user->rights->commande->creer && $object->statut == Commande::STATUS_DRAFT; + $editenable = $usercancreate && $object->statut == Commande::STATUS_DRAFT; print $form->editfieldkey("Currency", 'multicurrencycode', '', $object, $editenable); print ''; if ($action == 'editmulticurrencycode') { @@ -2277,7 +2279,7 @@ if ($action == 'create' && $user->rights->commande->creer) // Multicurrency rate print ''; print ''; - $editenable = $user->rights->commande->creer && $object->multicurrency_code && $object->multicurrency_code != $conf->currency && $object->statut == Commande::STATUS_DRAFT; + $editenable = $usercancreate && $object->multicurrency_code && $object->multicurrency_code != $conf->currency && $object->statut == Commande::STATUS_DRAFT; print $form->editfieldkey("CurrencyRate", 'multicurrencyrate', '', $object, $editenable); print ''; if ($action == 'editmulticurrencyrate' || $action == 'actualizemulticurrencyrate') { @@ -2298,7 +2300,7 @@ if ($action == 'create' && $user->rights->commande->creer) // Delivery delay print ''; - $editenable = $user->rights->commande->creer; + $editenable = $usercancreate; print $form->editfieldkey("AvailabilityPeriod", 'availability', '', $object, $editenable); print ''; if ($action == 'editavailability') { @@ -2310,7 +2312,7 @@ if ($action == 'create' && $user->rights->commande->creer) // Source reason (why we have an ordrer) print ''; - $editenable = $user->rights->commande->creer; + $editenable = $usercancreate; print $form->editfieldkey("Channel", 'demandreason', '', $object, $editenable); print ''; if ($action == 'editdemandreason') { @@ -2323,7 +2325,7 @@ if ($action == 'create' && $user->rights->commande->creer) // TODO Order mode (how we receive order). Not yet implemented /* print ''; - $editenable = $user->rights->commande->creer; + $editenable = $usercancreate; print $form->editfieldkey("SourceMode", 'inputmode', '', $object, $editenable); print ''; if ($action == 'editinputmode') { @@ -2355,7 +2357,7 @@ if ($action == 'create' && $user->rights->commande->creer) // Incoterms if (!empty($conf->incoterm->enabled)) { print ''; - $editenable = $user->rights->commande->creer; + $editenable = $usercancreate; print $form->editfieldkey("IncotermLabel", 'incoterm', '', $object, $editenable); print ''; print ''; @@ -2373,7 +2375,7 @@ if ($action == 'create' && $user->rights->commande->creer) // Bank Account if (! empty($conf->global->BANK_ASK_PAYMENT_BANK_DURING_ORDER) && ! empty($conf->banque->enabled)) { print ''; - $editenable = $user->rights->commande->creer; + $editenable = $usercancreate; print $form->editfieldkey("BankAccount", 'bankaccount', '', $object, $editenable); print ''; if ($action == 'editbankaccount') { @@ -2497,7 +2499,7 @@ if ($action == 'create' && $user->rights->commande->creer) /* * Form to add new line */ - if ($object->statut == Commande::STATUS_DRAFT && $user->rights->commande->creer && $action != 'selectlines') + if ($object->statut == Commande::STATUS_DRAFT && $usercancreate && $action != 'selectlines') { if ($action != 'editline') { @@ -2528,22 +2530,19 @@ if ($action == 'create' && $user->rights->commande->creer) if (empty($reshook)) { // Send if ($object->statut > Commande::STATUS_DRAFT) { - if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->commande->order_advance->send)) { + if ($usercansend) { print '
' . $langs->trans('SendMail') . '
'; } else print '
' . $langs->trans('SendMail') . '
'; } // Valid - if ($object->statut == Commande::STATUS_DRAFT && $object->total_ttc >= 0 && $numlines > 0 && - ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->order_advance->validate))) - ) + if ($object->statut == Commande::STATUS_DRAFT && $object->total_ttc >= 0 && $numlines > 0 && $usercanvalidate) { print '
' . $langs->trans('Validate') . '
'; } // Edit - if ($object->statut == Commande::STATUS_VALIDATED && $user->rights->commande->creer) { + if ($object->statut == Commande::STATUS_VALIDATED && $usercancreate) { print '
' . $langs->trans('Modify') . '
'; } // Create event @@ -2597,12 +2596,12 @@ if ($action == 'create' && $user->rights->commande->creer) } // Reopen a closed order - if (($object->statut == Commande::STATUS_CLOSED || $object->statut == Commande::STATUS_CANCELED) && $user->rights->commande->creer) { + if (($object->statut == Commande::STATUS_CLOSED || $object->statut == Commande::STATUS_CANCELED) && $usercancreate) { print '
' . $langs->trans('ReOpen') . '
'; } // Set to shipped - if (($object->statut == Commande::STATUS_VALIDATED || $object->statut == Commande::STATUS_SHIPMENTONPROCESS) && $user->rights->commande->cloturer) { + if (($object->statut == Commande::STATUS_VALIDATED || $object->statut == Commande::STATUS_SHIPMENTONPROCESS) && $usercanclose) { print '
' . $langs->trans('ClassifyShipped') . '
'; } @@ -2612,31 +2611,28 @@ if ($action == 'create' && $user->rights->commande->creer) if (! empty($conf->facture->enabled) && $user->rights->facture->creer && empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) { print '
' . $langs->trans("CreateBill") . '
'; } - if ($user->rights->commande->creer && $object->statut >= Commande::STATUS_VALIDATED && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) { + if ($usercancreate && $object->statut >= Commande::STATUS_VALIDATED && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) { print '
' . $langs->trans("ClassifyBilled") . '
'; } } if ($object->statut > Commande::STATUS_DRAFT && $object->billed) { - if ($user->rights->commande->creer && $object->statut >= Commande::STATUS_VALIDATED && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) { + if ($usercancreate && $object->statut >= Commande::STATUS_VALIDATED && empty($conf->global->WORKFLOW_DISABLE_CLASSIFY_BILLED_FROM_ORDER) && empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) { print '
' . $langs->trans("ClassifyUnBilled") . '
'; } } // Clone - if ($user->rights->commande->creer) { + if ($usercancreate) { print '
' . $langs->trans("ToClone") . '
'; } // Cancel order - if ($object->statut == Commande::STATUS_VALIDATED && - ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->cloturer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->commande->order_advance->annuler))) - ) + if ($object->statut == Commande::STATUS_VALIDATED && (! empty($usercanclose) || ! empty($usercancancel))) { print '
' . $langs->trans('Cancel') . '
'; } // Delete order - if ($user->rights->commande->supprimer) { + if ($usercandelete) { if ($numshipping == 0) { print '
' . $langs->trans('Delete') . '
'; } else { @@ -2659,18 +2655,18 @@ if ($action == 'create' && $user->rights->commande->creer) // Documents $comref = dol_sanitizeFileName($object->ref); $relativepath = $comref . '/' . $comref . '.pdf'; - $filedir = $conf->commande->dir_output . '/' . $comref; + $filedir = $conf->commande->multidir_output[$object->entity] . '/' . $comref; $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id; - $genallowed = $user->rights->commande->lire; - $delallowed = $user->rights->commande->creer; - print $formfile->showdocuments('commande', $comref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang); + $genallowed = $usercanread; + $delallowed = $usercancreate; + print $formfile->showdocuments('commande', $comref, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang, '', $object); // Show links to link elements $linktoelem = $form->showLinkToObjectBlock($object, null, array('order')); $compatibleImportElementsList = false; - if($user->rights->commande->creer + if($usercancreate && $object->statut == Commande::STATUS_DRAFT) { $compatibleImportElementsList = array('commande','propal'); // import from linked elements @@ -2707,7 +2703,7 @@ if ($action == 'create' && $user->rights->commande->creer) // Presend form $modelmail='order_send'; $defaulttopic='SendOrderRef'; - $diroutput = $conf->commande->dir_output; + $diroutput = $conf->commande->multidir_output[$object->entity]; $trackid = 'ord'.$object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index 23d9db8f246..01f41b7cdbc 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -433,8 +433,8 @@ class Commande extends CommonOrder // We rename directory ($this->ref = old ref, $num = new ref) in order not to lose the attachments $oldref = dol_sanitizeFileName($this->ref); $newref = dol_sanitizeFileName($num); - $dirsource = $conf->commande->dir_output.'/'.$oldref; - $dirdest = $conf->commande->dir_output.'/'.$newref; + $dirsource = $conf->commande->multidir_output[$this->entity].'/'.$oldref; + $dirdest = $conf->commande->multidir_output[$this->entity].'/'.$newref; if (! $error && file_exists($dirsource)) { dol_syslog(get_class($this)."::valid() rename dir ".$dirsource." into ".$dirdest); @@ -443,7 +443,7 @@ class Commande extends CommonOrder { dol_syslog("Rename ok"); // Rename docs starting with $oldref with $newref - $listoffiles=dol_dir_list($conf->commande->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/')); + $listoffiles=dol_dir_list($conf->commande->multidir_output[$this->entity].'/'.$newref, 'files', 1, '^'.preg_quote($oldref, '/')); foreach($listoffiles as $fileentry) { $dirsource=$fileentry['name']; @@ -865,7 +865,7 @@ class Commande extends CommonOrder $sql.= ", ".($this->remise_percent>0?$this->db->escape($this->remise_percent):0); $sql.= ", ".(int) $this->fk_incoterms; $sql.= ", '".$this->db->escape($this->location_incoterms)."'"; - $sql.= ", ".$conf->entity; + $sql.= ", ".setEntity($this); $sql.= ", ".($this->module_source ? "'".$this->db->escape($this->module_source)."'" : "null"); $sql.= ", ".($this->pos_source != '' ? "'".$this->db->escape($this->pos_source)."'" : "null"); $sql.= ", ".(int) $this->fk_multicurrency; @@ -1238,6 +1238,7 @@ class Commande extends CommonOrder $this->lines[$i] = $line; } + $this->entity = $object->entity; $this->socid = $object->socid; $this->fk_project = $object->fk_project; $this->cond_reglement_id = $object->cond_reglement_id; @@ -3335,10 +3336,10 @@ class Commande extends CommonOrder { // Remove directory with files $comref = dol_sanitizeFileName($this->ref); - if ($conf->commande->dir_output && !empty($this->ref)) + if ($conf->commande->multidir_output[$this->entity] && !empty($this->ref)) { - $dir = $conf->commande->dir_output . "/" . $comref ; - $file = $conf->commande->dir_output . "/" . $comref . "/" . $comref . ".pdf"; + $dir = $conf->commande->multidir_output[$this->entity] . "/" . $comref ; + $file = $conf->commande->multidir_output[$this->entity] . "/" . $comref . "/" . $comref . ".pdf"; if (file_exists($file)) // We must delete all files before deleting directory { dol_delete_preview($this); diff --git a/htdocs/commande/document.php b/htdocs/commande/document.php index 37cbc70cd40..ec6ed2fd91b 100644 --- a/htdocs/commande/document.php +++ b/htdocs/commande/document.php @@ -72,7 +72,7 @@ $object = new Commande($db); if ($object->fetch($id)) { $object->fetch_thirdparty(); - $upload_dir = $conf->commande->dir_output . "/" . dol_sanitizeFileName($object->ref); + $upload_dir = $conf->commande->multidir_output[$object->entity] . "/" . dol_sanitizeFileName($object->ref); } include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php'; @@ -92,7 +92,7 @@ if ($id > 0 || ! empty($ref)) { $object->fetch_thirdparty(); - $upload_dir = $conf->commande->dir_output.'/'.dol_sanitizeFileName($object->ref); + $upload_dir = $conf->commande->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref); $head = commande_prepare_head($object); dol_fiche_head($head, 'documents', $langs->trans('CustomerOrder'), -1, 'order'); @@ -174,7 +174,7 @@ if ($id > 0 || ! empty($ref)) $modulepart = 'commande'; $permission = $user->rights->commande->creer; $permtoedit = $user->rights->commande->creer; - $param = '&id=' . $object->id; + $param = '&id=' . $object->id.'&entity=' . (! empty($object->entity)?$object->entity:$conf->entity); include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; } else diff --git a/htdocs/commande/index.php b/htdocs/commande/index.php index a0e87bf63a3..160b6f70627 100644 --- a/htdocs/commande/index.php +++ b/htdocs/commande/index.php @@ -241,7 +241,7 @@ $max=5; * Last modified orders */ -$sql = "SELECT c.rowid, c.ref, c.fk_statut, c.facture, c.date_cloture as datec, c.tms as datem,"; +$sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut, c.facture, c.date_cloture as datec, c.tms as datem,"; $sql.= " s.nom as name, s.rowid as socid"; $sql.= ", s.client"; $sql.= ", s.code_client"; @@ -297,7 +297,7 @@ if ($resql) print ''; $filename=dol_sanitizeFileName($obj->ref); - $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref); + $filedir=$conf->commande->multidir_output[$obj->entity] . '/' . dol_sanitizeFileName($obj->ref); $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid; print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir); print ''; @@ -323,7 +323,7 @@ else dol_print_error($db); */ if (! empty($conf->commande->enabled)) { - $sql = "SELECT c.rowid, c.ref, c.fk_statut, c.facture, s.nom as name, s.rowid as socid"; + $sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut, c.facture, s.nom as name, s.rowid as socid"; $sql.= ", s.client"; $sql.= ", s.code_client"; $sql.= ", s.canvas"; @@ -377,7 +377,7 @@ if (! empty($conf->commande->enabled)) print ''; $filename=dol_sanitizeFileName($obj->ref); - $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref); + $filedir=$conf->commande->multidir_output[$obj->entity] . '/' . dol_sanitizeFileName($obj->ref); $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid; print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir); print ''; @@ -405,7 +405,7 @@ if (! empty($conf->commande->enabled)) */ if (! empty($conf->commande->enabled)) { - $sql = "SELECT c.rowid, c.ref, c.fk_statut, c.facture, s.nom as name, s.rowid as socid"; + $sql = "SELECT c.rowid, c.entity, c.ref, c.fk_statut, c.facture, s.nom as name, s.rowid as socid"; $sql.= ", s.client"; $sql.= ", s.code_client"; $sql.= ", s.canvas"; @@ -459,7 +459,7 @@ if (! empty($conf->commande->enabled)) print ''; $filename=dol_sanitizeFileName($obj->ref); - $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref); + $filedir=$conf->commande->multidir_output[$obj->entity] . '/' . dol_sanitizeFileName($obj->ref); $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid; print $formfile->getDocumentsLink($commandestatic->element, $filename, $filedir); print ''; diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index a25d863176e..66a3862bd2c 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -91,7 +91,7 @@ $id = (GETPOST('orderid')?GETPOST('orderid', 'int'):GETPOST('id', 'int')); if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'commande', $id, ''); -$diroutputmassaction=$conf->commande->dir_output . '/temp/massgeneration/'.$user->id; +$diroutputmassaction=$conf->commande->multidir_output[$conf->entity] . '/temp/massgeneration/'.$user->id; // Load variable for pagination $limit = GETPOST('limit', 'int')?GETPOST('limit', 'int'):$conf->liste_limit; @@ -218,7 +218,7 @@ if (empty($reshook)) $objectlabel='Orders'; $permtoread = $user->rights->commande->lire; $permtodelete = $user->rights->commande->supprimer; - $uploaddir = $conf->commande->dir_output; + $uploaddir = $conf->commande->multidir_output[$conf->entity]; $trigger_name='ORDER_SENTBYMAIL'; include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php'; } @@ -934,7 +934,7 @@ if ($resql) print ''; $filename=dol_sanitizeFileName($obj->ref); - $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($obj->ref); + $filedir=$conf->commande->multidir_output[$conf->entity] . '/' . dol_sanitizeFileName($obj->ref); $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid; print $formfile->getDocumentsLink($generic_commande->element, $filename, $filedir); print ''; @@ -1081,7 +1081,7 @@ if ($resql) // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; // Fields from hook - $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj); + $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i); $reshook=$hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; // Date creation diff --git a/htdocs/commande/orderstoinvoice.php b/htdocs/commande/orderstoinvoice.php index 33acc2b4969..fa983e46f8e 100644 --- a/htdocs/commande/orderstoinvoice.php +++ b/htdocs/commande/orderstoinvoice.php @@ -548,7 +548,7 @@ if (($action != 'create' && $action != 'add') || ($action == 'create' && $error) '; $filename=dol_sanitizeFileName($objp->ref); - $filedir=$conf->commande->dir_output . '/' . dol_sanitizeFileName($objp->ref); + $filedir=$conf->commande->multidir_output[$objp->entity] . '/' . dol_sanitizeFileName($objp->ref); $urlsource=$_SERVER['PHP_SELF'].'?id='.$objp->rowid; print $formfile->getDocumentsLink($generic_commande->element, $filename, $filedir); print ''; diff --git a/htdocs/compta/facture/card.php b/htdocs/compta/facture/card.php index bfa21a9c759..9c4a10a19ad 100644 --- a/htdocs/compta/facture/card.php +++ b/htdocs/compta/facture/card.php @@ -945,7 +945,6 @@ 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']; @@ -979,7 +978,7 @@ if (empty($reshook)) if (! $error) { - if(!empty($originentity)){ + if (!empty($originentity)) { $object->entity = $originentity; } $object->socid = GETPOST('socid', 'int'); @@ -1001,7 +1000,6 @@ 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 : ''; @@ -1183,7 +1181,6 @@ 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'); @@ -1234,7 +1231,6 @@ 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) { @@ -2491,7 +2487,7 @@ if (empty($reshook)) include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php'; // Actions to build doc - $upload_dir = $conf->facture->dir_output; + $upload_dir = $conf->facture->multidir_output[$object->entity]; $permissioncreate=$usercancreate; include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php'; @@ -5136,12 +5132,12 @@ elseif ($id > 0 || ! empty($ref)) // Documents generes $filename = dol_sanitizeFileName($object->ref); - $filedir = $conf->facture->dir_output . '/' . dol_sanitizeFileName($object->ref); + $filedir = $conf->facture->multidir_output[$object->entity] . '/' . dol_sanitizeFileName($object->ref); $urlsource = $_SERVER['PHP_SELF'] . '?facid=' . $object->id; $genallowed = $usercanread; $delallowed = $usercancreate; - print $formfile->showdocuments('facture', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang); + print $formfile->showdocuments('facture', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', '', '', $soc->default_lang, '', $object); $somethingshown = $formfile->numoffiles; // Show links to link elements @@ -5188,7 +5184,7 @@ elseif ($id > 0 || ! empty($ref)) // Presend form $modelmail='facture_send'; $defaulttopic='SendBillRef'; - $diroutput = $conf->facture->dir_output; + $diroutput = $conf->facture->multidir_output[$object->entity]; $trackid = 'inv'.$object->id; include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php'; diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 7f5dde15c59..1b9cc3db566 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -318,7 +318,6 @@ class Facture extends CommonInvoice if (! $this->cond_reglement_id) $this->cond_reglement_id = 0; if (! $this->mode_reglement_id) $this->mode_reglement_id = 0; $this->brouillon = 1; - if (empty($this->entity)) $this->entity = $conf->entity; // Multicurrency (test on $this->multicurrency_tx because we should take the default rate only if not using origin rate) if (!empty($this->multicurrency_code) && empty($this->multicurrency_tx)) list($this->fk_multicurrency,$this->multicurrency_tx) = MultiCurrency::getIdAndTxFromCode($this->db, $this->multicurrency_code); @@ -493,7 +492,7 @@ class Facture extends CommonInvoice $sql.= ")"; $sql.= " VALUES ("; $sql.= "'(PROV)'"; - $sql.= ", ".$this->entity; + $sql.= ", ".setEntity($this); $sql.= ", ".($this->ref_ext?"'".$this->db->escape($this->ref_ext)."'":"null"); $sql.= ", '".$this->db->escape($this->type)."'"; $sql.= ", '".$socid."'"; @@ -936,8 +935,8 @@ class Facture extends CommonInvoice $facture->remise_absolue = $this->remise_absolue; $facture->remise_percent = $this->remise_percent; - $facture->origin = $this->origin; - $facture->origin_id = $this->origin_id; + $facture->origin = $this->origin; + $facture->origin_id = $this->origin_id; $facture->lines = $this->lines; // Array of lines of invoice $facture->products = $this->lines; // Tant que products encore utilise @@ -1624,7 +1623,11 @@ class Facture extends CommonInvoice $this->tab_previous_situation_invoice = array(); $this->tab_next_situation_invoice = array(); - $sql = 'SELECT rowid, situation_counter FROM '.MAIN_DB_PREFIX.'facture WHERE rowid <> '.$this->id.' AND entity = '.$conf->entity.' AND situation_cycle_ref = '.(int) $this->situation_cycle_ref.' ORDER BY situation_counter ASC'; + $sql = 'SELECT rowid, situation_counter FROM '.MAIN_DB_PREFIX.'facture'; + $sql.= ' WHERE rowid <> '.$this->id; + $sql.= ' AND entity = '.$this->entity; + $sql.= ' AND situation_cycle_ref = '.(int) $this->situation_cycle_ref; + $sql.= ' ORDER BY situation_counter ASC'; dol_syslog(get_class($this).'::fetchPreviousNextSituationInvoice ', LOG_DEBUG); $result = $this->db->query($sql); @@ -3700,11 +3703,11 @@ class Facture extends CommonInvoice $sql.= " AND ff.type IS NULL"; // Renvoi vrai si pas facture de remplacement $sql.= " AND f.type != ".self::TYPE_CREDIT_NOTE; // Type non 2 si facture non avoir - if($conf->global->INVOICE_USE_SITUATION_CREDIT_NOTE){ + if (! empty($conf->global->INVOICE_USE_SITUATION_CREDIT_NOTE)) { // Select the last situation invoice $sqlSit = 'SELECT MAX(fs.rowid)'; $sqlSit.= " FROM ".MAIN_DB_PREFIX."facture as fs"; - $sqlSit.= " WHERE fs.entity = ".$conf->entity; + $sqlSit.= " WHERE fs.entity IN (".getEntity('invoice').")"; $sqlSit.= " AND fs.type = ".self::TYPE_SITUATION; $sqlSit.= " AND fs.fk_statut in (".self::STATUS_VALIDATED.",".self::STATUS_CLOSED.")"; $sqlSit.= " GROUP BY fs.situation_cycle_ref"; @@ -4230,7 +4233,7 @@ class Facture extends CommonInvoice public function newCycle() { $sql = 'SELECT max(situation_cycle_ref) FROM ' . MAIN_DB_PREFIX . 'facture as f'; - $sql.= " WHERE f.entity in (".getEntity('invoice', 0).")"; + $sql.= " WHERE f.entity IN (".getEntity('invoice', 0).")"; $resql = $this->db->query($sql); if ($resql) { if ($resql->num_rows > 0) @@ -4274,8 +4277,8 @@ class Facture extends CommonInvoice global $conf; $sql = 'SELECT rowid FROM ' . MAIN_DB_PREFIX . 'facture'; - $sql .= ' where situation_cycle_ref = ' . $this->situation_cycle_ref; - $sql .= ' and situation_counter < ' . $this->situation_counter; + $sql .= ' WHERE situation_cycle_ref = ' . $this->situation_cycle_ref; + $sql .= ' AND situation_counter < ' . $this->situation_counter; $sql .= ' AND entity = '. ($this->entity > 0 ? $this->entity : $conf->entity); $resql = $this->db->query($sql); $res = array(); @@ -4356,7 +4359,9 @@ class Facture extends CommonInvoice if (!empty($this->situation_cycle_ref)) { // No point in testing anything if we're not inside a cycle - $sql = 'SELECT max(situation_counter) FROM ' . MAIN_DB_PREFIX . 'facture WHERE situation_cycle_ref = ' . $this->situation_cycle_ref . ' AND entity = ' . ($this->entity > 0 ? $this->entity : $conf->entity); + $sql = 'SELECT max(situation_counter) FROM ' . MAIN_DB_PREFIX . 'facture'; + $sql.= ' WHERE situation_cycle_ref = ' . $this->situation_cycle_ref; + $sql.= ' AND entity = ' . ($this->entity > 0 ? $this->entity : $conf->entity); $resql = $this->db->query($sql); if ($resql && $resql->num_rows > 0) { diff --git a/htdocs/compta/facture/document.php b/htdocs/compta/facture/document.php index 44f69f512bd..9a8f308a0d1 100644 --- a/htdocs/compta/facture/document.php +++ b/htdocs/compta/facture/document.php @@ -97,7 +97,7 @@ if ($id > 0 || ! empty($ref)) { $object->fetch_thirdparty(); - $upload_dir = $conf->facture->dir_output.'/'.dol_sanitizeFileName($object->ref); + $upload_dir = $conf->facture->multidir_output[$object->entity].'/'.dol_sanitizeFileName($object->ref); $head = facture_prepare_head($object); dol_fiche_head($head, 'documents', $langs->trans('InvoiceCustomer'), -1, 'bill'); diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index eca39ade98c..71e0de738fa 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -1231,7 +1231,7 @@ if ($resql) // Extra fields include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php'; // Fields from hook - $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj); + $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i); $reshook=$hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; // Date creation diff --git a/htdocs/core/class/conf.class.php b/htdocs/core/class/conf.class.php index 0d76b83cb8a..3088d8a95ce 100644 --- a/htdocs/core/class/conf.class.php +++ b/htdocs/core/class/conf.class.php @@ -327,6 +327,9 @@ class Conf } // For mycompany storage + $this->mycompany->multidir_output = array($this->entity => $rootfordata."/mycompany"); + $this->mycompany->multidir_temp = array($this->entity => $rootfordata."/mycompany/temp"); + // For backward compatibility $this->mycompany->dir_output=$rootfordata."/mycompany"; $this->mycompany->dir_temp=$rootfordata."/mycompany/temp"; diff --git a/htdocs/core/class/html.formfile.class.php b/htdocs/core/class/html.formfile.class.php index 5f63d4db66c..729ea18ba1d 100644 --- a/htdocs/core/class/html.formfile.class.php +++ b/htdocs/core/class/html.formfile.class.php @@ -1258,7 +1258,7 @@ class FormFile print ''; } // Preview link - if (! $editline) print $this->showPreview($file, $modulepart, $filepath); + if (! $editline) print $this->showPreview($file, $modulepart, $filepath, 0, '&entity='.(! empty($object->entity)?$object->entity:$conf->entity)); print "\n"; diff --git a/htdocs/core/lib/files.lib.php b/htdocs/core/lib/files.lib.php index b93483b4072..c7573af557a 100644 --- a/htdocs/core/lib/files.lib.php +++ b/htdocs/core/lib/files.lib.php @@ -2263,10 +2263,10 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, $original_file=$conf->adherent->dir_output.'/'.$original_file; } // Wrapping pour les apercu factures - elseif ($modulepart == 'apercufacture' && !empty($conf->facture->dir_output)) + elseif ($modulepart == 'apercufacture' && !empty($conf->facture->multidir_output[$entity])) { if ($fuser->rights->facture->{$lire}) $accessallowed=1; - $original_file=$conf->facture->dir_output.'/'.$original_file; + $original_file=$conf->facture->multidir_output[$entity].'/'.$original_file; } // Wrapping pour les apercu propal elseif ($modulepart == 'apercupropal' && !empty($conf->propal->multidir_output[$entity])) @@ -2275,10 +2275,10 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, $original_file=$conf->propal->multidir_output[$entity].'/'.$original_file; } // Wrapping pour les apercu commande - elseif ($modulepart == 'apercucommande' && !empty($conf->commande->dir_output)) + elseif ($modulepart == 'apercucommande' && !empty($conf->commande->multidir_output[$entity])) { if ($fuser->rights->commande->{$lire}) $accessallowed=1; - $original_file=$conf->commande->dir_output.'/'.$original_file; + $original_file=$conf->commande->multidir_output[$entity].'/'.$original_file; } // Wrapping pour les apercu intervention elseif (($modulepart == 'apercufichinter' || $modulepart == 'apercuficheinter') && !empty($conf->ficheinter->dir_output)) @@ -2474,13 +2474,13 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, } // Wrapping for invoices - elseif (($modulepart == 'facture' || $modulepart == 'invoice') && !empty($conf->facture->dir_output)) + elseif (($modulepart == 'facture' || $modulepart == 'invoice') && !empty($conf->facture->multidir_output[$entity])) { if ($fuser->rights->facture->{$lire} || preg_match('/^specimen/i', $original_file)) { $accessallowed=1; } - $original_file=$conf->facture->dir_output.'/'.$original_file; + $original_file=$conf->facture->multidir_output[$entity].'/'.$original_file; $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."facture WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; } // Wrapping for mass actions @@ -2498,7 +2498,7 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, { $accessallowed=1; } - $original_file=$conf->commande->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; + $original_file=$conf->commande->multidir_output[$entity].'/temp/massgeneration/'.$user->id.'/'.$original_file; } elseif ($modulepart == 'massfilesarea_sendings') { @@ -2514,7 +2514,7 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, { $accessallowed=1; } - $original_file=$conf->facture->dir_output.'/temp/massgeneration/'.$user->id.'/'.$original_file; + $original_file=$conf->facture->multidir_output[$entity].'/temp/massgeneration/'.$user->id.'/'.$original_file; } elseif ($modulepart == 'massfilesarea_expensereport') { @@ -2598,13 +2598,13 @@ function dol_check_secure_access_document($modulepart, $original_file, $entity, } // Wrapping pour les commandes - elseif (($modulepart == 'commande' || $modulepart == 'order') && !empty($conf->commande->dir_output)) + elseif (($modulepart == 'commande' || $modulepart == 'order') && !empty($conf->commande->multidir_output[$entity])) { if ($fuser->rights->commande->{$lire} || preg_match('/^specimen/i', $original_file)) { $accessallowed=1; } - $original_file=$conf->commande->dir_output.'/'.$original_file; + $original_file=$conf->commande->multidir_output[$entity].'/'.$original_file; $sqlprotectagainstexternals = "SELECT fk_soc as fk_soc FROM ".MAIN_DB_PREFIX."commande WHERE ref='".$db->escape($refname)."' AND entity=".$conf->entity; } diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index e34c3e3b7b5..6c8c1797f7d 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -5,7 +5,7 @@ * Copyright (C) 2004 Sebastien Di Cintio * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2004 Christophe Combelles - * Copyright (C) 2005-2017 Regis Houssin + * Copyright (C) 2005-2019 Regis Houssin * Copyright (C) 2008 Raphael Bertrand (Resultic) * Copyright (C) 2010-2018 Juanjo Menent * Copyright (C) 2013 Cédric Salvador @@ -75,7 +75,7 @@ function getDoliDBInstance($type, $host, $user, $pass, $name, $port) * @param int $shared 0=Return id of current entity only, * 1=Return id of current entity + shared entities (default) * @param object $currentobject Current object if needed - * @return mixed Entity id(s) to use + * @return mixed Entity id(s) to use ( eg. entity IN ('.getEntity(elementname).')' ) */ function getEntity($element, $shared = 1, $currentobject = null) { @@ -95,6 +95,26 @@ function getEntity($element, $shared = 1, $currentobject = null) } } +/** + * Set entity id to use when to create an object + * + * @param object $currentobject Current object + * @return mixed Entity id to use ( eg. entity = '.setEntity($object) ) + */ +function setEntity($currentobject) +{ + global $conf, $mc; + + if (is_object($mc)) + { + return $mc->setEntity($currentobject); + } + else + { + return ((is_object($currentobject) && $currentobject->id > 0 && $currentobject->entity > 0) ? $currentobject->entity : $conf->entity); + } +} + /** * Return information about user browser * diff --git a/htdocs/core/lib/order.lib.php b/htdocs/core/lib/order.lib.php index 6e276dcf8f4..5727ececb5e 100644 --- a/htdocs/core/lib/order.lib.php +++ b/htdocs/core/lib/order.lib.php @@ -96,7 +96,7 @@ function commande_prepare_head(Commande $object) require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php'; - $upload_dir = $conf->commande->dir_output . "/" . dol_sanitizeFileName($object->ref); + $upload_dir = $conf->commande->multidir_output[$object->entity] . "/" . dol_sanitizeFileName($object->ref); $nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$')); $nbLinks=Link::count($db, $object->element, $object->id); $head[$h][0] = DOL_URL_ROOT.'/commande/document.php?id='.$object->id; diff --git a/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php b/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php index 5685a839314..eced22d03d8 100644 --- a/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php +++ b/htdocs/core/modules/commande/doc/doc_generic_order_odt.modules.php @@ -244,7 +244,7 @@ class doc_generic_order_odt extends ModelePDFCommandes } } - $dir = $conf->commande->dir_output; + $dir = $conf->commande->multidir_output[$object->entity]; $objectref = dol_sanitizeFileName($object->ref); if (! preg_match('/specimen/i', $objectref)) $dir.= "/" . $objectref; $file = $dir . "/" . $objectref . ".odt"; diff --git a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php index 1dff7d5050b..a885ebb536a 100644 --- a/htdocs/core/modules/commande/doc/pdf_einstein.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_einstein.modules.php @@ -239,13 +239,13 @@ class pdf_einstein extends ModelePDFCommandes // Definition of $dir and $file if ($object->specimen) { - $dir = $conf->commande->dir_output; + $dir = $conf->commande->multidir_output[$conf->entity]; $file = $dir . "/SPECIMEN.pdf"; } else { $objectref = dol_sanitizeFileName($object->ref); - $dir = $conf->commande->dir_output . "/" . $objectref; + $dir = $conf->commande->multidir_output[$object->entity] . "/" . $objectref; $file = $dir . "/" . $objectref . ".pdf"; } @@ -290,7 +290,7 @@ class pdf_einstein extends ModelePDFCommandes // Set path to the background PDF File if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) { - $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); + $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[$object->entity].'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); $tplidx = $pdf->importPage(1); } @@ -1258,7 +1258,7 @@ class pdf_einstein extends ModelePDFCommandes // Logo if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO)) { - $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo; + $logo=$conf->mycompany->multidir_output[$object->entity].'/logos/'.$this->emetteur->logo; if ($this->emetteur->logo) { if (is_readable($logo)) diff --git a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php index 4ca0cf36391..638ece9baf0 100644 --- a/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php +++ b/htdocs/core/modules/commande/doc/pdf_eratosthene.modules.php @@ -281,13 +281,13 @@ class pdf_eratosthene extends ModelePDFCommandes // Definition of $dir and $file if ($object->specimen) { - $dir = $conf->commande->dir_output; + $dir = $conf->commande->multidir_output[$conf->entity]; $file = $dir . "/SPECIMEN.pdf"; } else { $objectref = dol_sanitizeFileName($object->ref); - $dir = $conf->commande->dir_output . "/" . $objectref; + $dir = $conf->commande->multidir_output[$object->entity] . "/" . $objectref; $file = $dir . "/" . $objectref . ".pdf"; } @@ -331,7 +331,7 @@ class pdf_eratosthene extends ModelePDFCommandes // Set path to the background PDF File if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) { - $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); + $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[$object->entity].'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); $tplidx = $pdf->importPage(1); } @@ -1393,7 +1393,7 @@ class pdf_eratosthene extends ModelePDFCommandes // Logo if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO)) { - $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo; + $logo=$conf->mycompany->multidir_output[$object->entity].'/logos/'.$this->emetteur->logo; if ($this->emetteur->logo) { if (is_readable($logo)) diff --git a/htdocs/core/modules/commande/mod_commande_marbre.php b/htdocs/core/modules/commande/mod_commande_marbre.php index 28d488eb6fb..160a07635f4 100644 --- a/htdocs/core/modules/commande/mod_commande_marbre.php +++ b/htdocs/core/modules/commande/mod_commande_marbre.php @@ -121,7 +121,7 @@ class mod_commande_marbre extends ModeleNumRefCommandes $sql = "SELECT MAX(CAST(SUBSTRING(ref FROM ".$posindice.") AS SIGNED)) as max"; $sql.= " FROM ".MAIN_DB_PREFIX."commande"; $sql.= " WHERE ref LIKE '".$db->escape($this->prefix)."____-%'"; - $sql.= " AND entity = ".$conf->entity; + $sql.= " AND entity IN (".getEntity('ordernumber', 1, $object).")"; $resql=$db->query($sql); if ($resql) diff --git a/htdocs/core/modules/commande/mod_commande_saphir.php b/htdocs/core/modules/commande/mod_commande_saphir.php index 892a279cbe8..4f9931f35e9 100644 --- a/htdocs/core/modules/commande/mod_commande_saphir.php +++ b/htdocs/core/modules/commande/mod_commande_saphir.php @@ -137,9 +137,12 @@ class mod_commande_saphir extends ModeleNumRefCommandes return 0; } + // Get entities + $entity = getEntity('ordernumber', 1, $object); + $date = ($object->date_commande ? $object->date_commande : $object->date); - $numFinal=get_next_value($db, $mask, 'commande', 'ref', '', $objsoc, $date); + $numFinal=get_next_value($db, $mask, 'commande', 'ref', '', $objsoc, $date, 'next', false, null, $entity); return $numFinal; } diff --git a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php index acc88a1e96a..9b8d3c6b0f7 100644 --- a/htdocs/core/modules/facture/doc/pdf_crabe.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_crabe.modules.php @@ -342,7 +342,7 @@ class pdf_crabe extends ModelePDFFactures // Set path to the background PDF File if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) { - $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); + $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[$object->entity].'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); $tplidx = $pdf->importPage(1); } @@ -1611,7 +1611,7 @@ class pdf_crabe extends ModelePDFFactures // Logo if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO)) { - $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo; + $logo=$conf->mycompany->multidir_output[$object->entity].'/logos/'.$this->emetteur->logo; if ($this->emetteur->logo) { if (is_readable($logo)) diff --git a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php index 26e2b1824d8..5b508f37f68 100644 --- a/htdocs/core/modules/facture/doc/pdf_sponge.modules.php +++ b/htdocs/core/modules/facture/doc/pdf_sponge.modules.php @@ -352,7 +352,7 @@ class pdf_sponge extends ModelePDFFactures // Set path to the background PDF File if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) { - $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); + $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[$object->entity].'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); $tplidx = $pdf->importPage(1); } @@ -1843,7 +1843,7 @@ class pdf_sponge extends ModelePDFFactures // Logo if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO)) { - $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo; + $logo=$conf->mycompany->multidir_output[$object->entity].'/logos/'.$this->emetteur->logo; if ($this->emetteur->logo) { if (is_readable($logo)) diff --git a/htdocs/core/modules/propale/doc/pdf_azur.modules.php b/htdocs/core/modules/propale/doc/pdf_azur.modules.php index 4ad23a1704e..c489e23b52f 100644 --- a/htdocs/core/modules/propale/doc/pdf_azur.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_azur.modules.php @@ -344,7 +344,7 @@ class pdf_azur extends ModelePDFPropales // Set path to the background PDF File if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) { - $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); + $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[$object->entity].'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); $tplidx = $pdf->importPage(1); } @@ -1459,7 +1459,7 @@ class pdf_azur extends ModelePDFPropales // Logo if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO)) { - $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo; + $logo=$conf->mycompany->multidir_output[$object->entity].'/logos/'.$this->emetteur->logo; if ($this->emetteur->logo) { if (is_readable($logo)) diff --git a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php index 3ddc8a45a52..2d26f2fc03b 100644 --- a/htdocs/core/modules/propale/doc/pdf_cyan.modules.php +++ b/htdocs/core/modules/propale/doc/pdf_cyan.modules.php @@ -330,7 +330,7 @@ class pdf_cyan extends ModelePDFPropales // Set path to the background PDF File if (! empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) { - $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); + $pagecount = $pdf->setSourceFile($conf->mycompany->multidir_output[$object->entity].'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); $tplidx = $pdf->importPage(1); } @@ -1505,7 +1505,7 @@ class pdf_cyan extends ModelePDFPropales // Logo if (empty($conf->global->PDF_DISABLE_MYCOMPANY_LOGO)) { - $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo; + $logo=$conf->mycompany->multidir_output[$object->entity].'/logos/'.$this->emetteur->logo; if ($this->emetteur->logo) { if (is_readable($logo))