diff --git a/htdocs/accountancy/index.php b/htdocs/accountancy/index.php index bd48c205dae..926097c1509 100644 --- a/htdocs/accountancy/index.php +++ b/htdocs/accountancy/index.php @@ -117,7 +117,7 @@ if (!empty($conf->global->INVOICE_USE_SITUATION) && $conf->global->INVOICE_USE_S print '
'; // hideobject is to start hidden print "
\n"; print ''.$langs->trans("AccountancyAreaDescIntro")."
\n"; - if (!empty($user->rights->accounting->chartofaccount)) { + if ($user->hasRight('accounting', 'chartofaccount')) { print "
\n"; print "
\n"; print load_fiche_titre(' '.$langs->trans("AccountancyAreaDescActionOnce"), '', '')."\n"; diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index 5cce7e1345e..c311bf80d1d 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -582,36 +582,15 @@ if (empty($reshook)) { $id = $object->id; } else { $db->rollback(); - - if ($object->error) { - setEventMessages($object->error, $object->errors, 'errors'); - } else { - setEventMessages($object->error, $object->errors, 'errors'); - } + setEventMessages($object->error, $object->errors, 'errors'); } + // Auto-create thirdparty on member creation if (!empty($conf->global->ADHERENT_DEFAULT_CREATE_THIRDPARTY)) { if ($result > 0) { - // User creation + // Create third party out of a member $company = new Societe($db); - - $companyalias = ''; - $fullname = $object->getFullName($langs); - - if ($object->morphy == 'mor') { - $companyname = $object->company; - if (!empty($fullname)) { - $companyalias = $fullname; - } - } else { - $companyname = $fullname; - if (!empty($object->company)) { - $companyalias = $object->company; - } - } - - $result = $company->create_from_member($object, $companyname, $companyalias); - + $result = $company->create_from_member($object); if ($result < 0) { $langs->load("errors"); setEventMessages($langs->trans($company->error), null, 'errors'); diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php index 286ccc424e8..d04039aefdf 100644 --- a/htdocs/admin/modules.php +++ b/htdocs/admin/modules.php @@ -43,10 +43,15 @@ require_once DOL_DOCUMENT_ROOT.'/admin/dolistore/class/dolistore.class.php'; // Load translation files required by the page $langs->loadLangs(array("errors", "admin", "modulebuilder")); -$mode = GETPOSTISSET('mode') ? GETPOST('mode', 'alpha') : (empty($conf->global->MAIN_MODULE_SETUP_ON_LIST_BY_DEFAULT) ? 'commonkanban' : 'common'); -if (empty($mode)) { - $mode = 'common'; +// if we set another view list mode, we keep it (till we change one more time) +if (GETPOSTISSET('mode')) { + $mode = GETPOST('mode', 'alpha'); + if ($mode =='common' || $mode =='commonkanban') + dolibarr_set_const($db, "MAIN_MODULE_SETUP_ON_LIST_BY_DEFAULT", $mode, 'chaine', 0, '', $conf->entity); +} else { + $mode = (empty($conf->global->MAIN_MODULE_SETUP_ON_LIST_BY_DEFAULT) ? 'commonkanban' : $conf->global->MAIN_MODULE_SETUP_ON_LIST_BY_DEFAULT); } + $action = GETPOST('action', 'aZ09'); $value = GETPOST('value', 'alpha'); $page_y = GETPOST('page_y', 'int'); diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index 54573f92c7a..79291aacdf0 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -31,6 +31,7 @@ */ use OAuth\Common\Storage\DoliStorage; +use OAuth\Common\Consumer\Credentials; /** * Class to send emails (with attachments or not) * Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext,$replyto); @@ -981,8 +982,31 @@ class CMailFile require_once DOL_DOCUMENT_ROOT.'/includes/OAuth/bootstrap.php'; $storage = new DoliStorage($db, $conf); + try { $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME); + $expire = false; + // Is token expired or will token expire in the next 30 seconds + if (is_object($tokenobj)) { + $expire = ($tokenobj->getEndOfLife() !== -9002 && $tokenobj->getEndOfLife() !== -9001 && time() > ($tokenobj->getEndOfLife() - 30)); + } + // Token expired so we refresh it + if (is_object($tokenobj) && $expire) { + $credentials = new Credentials( + getDolGlobalString('OAUTH_'.getDolGlobalString('MAIN_MAIL_SMTPS_OAUTH_SERVICE').'_ID'), + getDolGlobalString('OAUTH_'.getDolGlobalString('MAIN_MAIL_SMTPS_OAUTH_SERVICE').'_SECRET'), + getDolGlobalString('OAUTH_'.getDolGlobalString('MAIN_MAIL_SMTPS_OAUTH_SERVICE').'_URLAUTHORIZE') + ); + $serviceFactory = new \OAuth\ServiceFactory(); + $oauthname = explode('-', $OAUTH_SERVICENAME); + // ex service is Google-Emails we need only the first part Google + $apiService = $serviceFactory->createService($oauthname[0], $credentials, $storage, array()); + // il faut sauvegarder le refresh token car google ne le donne qu'une seule fois + $refreshtoken = $tokenobj->getRefreshToken(); + $tokenobj = $apiService->refreshAccessToken($tokenobj); + $tokenobj->setRefreshToken($refreshtoken); + $storage->storeAccessToken($OAUTH_SERVICENAME, $tokenobj); + } if (is_object($tokenobj)) { $this->transport->setAuthMode('XOAUTH2'); $this->transport->setPassword($tokenobj->getAccessToken()); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index a18341cc179..eaba8121505 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -141,7 +141,7 @@ abstract class CommonObject public $linkedObjectsFullLoaded = array(); /** - * @var Object To store a cloned copy of object before to edit it and keep track of old properties + * @var CommonObject To store a cloned copy of object before to edit it and keep track of old properties */ public $oldcopy; diff --git a/htdocs/core/lib/admin.lib.php b/htdocs/core/lib/admin.lib.php index d281d85efae..4067636e676 100644 --- a/htdocs/core/lib/admin.lib.php +++ b/htdocs/core/lib/admin.lib.php @@ -693,7 +693,7 @@ function modules_prepare_head($nbofactivatedmodules, $nboftotalmodules) $h = 0; $head = array(); - $mode = empty($conf->global->MAIN_MODULE_SETUP_ON_LIST_BY_DEFAULT) ? 'commonkanban' : 'common'; + $mode = empty($conf->global->MAIN_MODULE_SETUP_ON_LIST_BY_DEFAULT) ? 'commonkanban' : $conf->global->MAIN_MODULE_SETUP_ON_LIST_BY_DEFAULT; $head[$h][0] = DOL_URL_ROOT."/admin/modules.php?mode=".$mode; if ($nbofactivatedmodules <= (empty($conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING) ? 1 : $conf->global->MAIN_MIN_NB_ENABLED_MODULE_FOR_WARNING)) { // If only minimal initial modules enabled) //$head[$h][1] = $form->textwithpicto($langs->trans("AvailableModules"), $desc); diff --git a/htdocs/core/modules/printing/printgcp.modules.php b/htdocs/core/modules/printing/printgcp.modules.php index 964558de8df..391f5b435d7 100644 --- a/htdocs/core/modules/printing/printgcp.modules.php +++ b/htdocs/core/modules/printing/printgcp.modules.php @@ -137,7 +137,6 @@ class printing_printgcp extends PrintingDriver $this->errors[] = $e->getMessage(); $token_ok = false; } - //var_dump($this->errors);exit; $expire = false; // Is token expired or will token expire in the next 30 seconds diff --git a/htdocs/public/members/new.php b/htdocs/public/members/new.php index bafed2c54eb..87502734f8e 100644 --- a/htdocs/public/members/new.php +++ b/htdocs/public/members/new.php @@ -257,7 +257,7 @@ if (empty($reshook) && $action == 'add') { $public = GETPOSTISSET('public') ? 1 : 0; if (!$error) { - // email a peu pres correct et le login n'existe pas + // E-mail looks OK and login does not exist $adh = new Adherent($db); $adh->statut = -1; $adh->public = $public; @@ -378,6 +378,16 @@ if (empty($reshook) && $action == 'add') { } } + // Auto-create thirdparty on member creation + if (!empty($conf->global->ADHERENT_DEFAULT_CREATE_THIRDPARTY)) { + $company = new Societe($db); + $result = $company->create_from_member($adh); + if ($result < 0) { + $error++; + $errmsg .= join('
', $company->errors); + } + } + if (!empty($backtopage)) { $urlback = $backtopage; } elseif (!empty($conf->global->MEMBER_URL_REDIRECT_SUBSCRIPTION)) { diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 105178e3d65..26415a63332 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -4024,12 +4024,25 @@ class Societe extends CommonObject global $conf, $user, $langs; dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG); + $fullname = $member->getFullName($langs); - $name = $socname ? $socname : $member->societe; - if (empty($name)) { - $name = $member->getFullName($langs); + if ($member->morphy == 'mor') { + if (empty($socname)) { + $socname = $member->company? $member->company : $member->societe; + } + if (!empty($fullname) && empty($socalias)) { + $socalias = $fullname; + } + } elseif (empty($socname) && $member->morphy == 'phy') { + if (empty($socname)) { + $socname = $fullname; + } + if (!empty($member->company) && empty($socalias)) { + $socalias = $member->company; + } } + $name = $socname; $alias = $socalias ? $socalias : ''; // Positionne parametres diff --git a/htdocs/takepos/invoice.php b/htdocs/takepos/invoice.php index 3657ca7f4b6..c3948126b3f 100644 --- a/htdocs/takepos/invoice.php +++ b/htdocs/takepos/invoice.php @@ -564,6 +564,27 @@ if (empty($reshook)) { $line = array('description' => $prod->description, 'price' => $price, 'tva_tx' => $tva_tx, 'locatax1_tx' => $localtax1_tx, 'locatax2_tx' => $localtax2_tx, 'remise_percent' => $customer->remise_percent, 'price_ttc' => $price_ttc, 'array_options' => $array_options); + /* setup of margin calculation */ + if (isset($conf->global->MARGIN_TYPE)) { + if ($conf->global->MARGIN_TYPE == 'pmp' && ! empty($prod->pmp)) { + $line['fk_fournprice'] = null; + $line['pa_ht'] = $prod->pmp; + } elseif ($conf->global->MARGIN_TYPE == 'costprice' && ! empty($prod->cost_price)) { + $line['fk_fournprice'] = null; + $line['pa_ht'] = $prod->cost_price; + } else { + // default is fournprice + require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.product.class.php'; + $pf = new ProductFournisseur($db); + if ($pf->find_min_price_product_fournisseur($idproduct, $qty) > 0) { + $line['fk_fournprice'] = $pf->product_fourn_price_id; + $line['pa_ht'] = $pf->fourn_unitprice_with_discount; + if ($pf->fourn_charges > 0) + $line['pa_ht'] += $pf->fourn_charges / $pf->fourn_qty; + } + } + } + // complete line by hook $parameters = array('prod' => $prod, 'line' => $line); $reshook=$hookmanager->executeHooks('completeTakePosAddLine', $parameters, $invoice, $action); // Note that $action and $line may have been modified by some hooks @@ -575,7 +596,7 @@ if (empty($reshook)) { $line = $hookmanager->resArray; } - $idoflineadded = $invoice->addline($line['description'], $line['price'], $qty, $line['tva_tx'], $line['localtax1_tx'], $line['localtax2_tx'], $idproduct, $line['remise_percent'], '', 0, 0, 0, '', $price_base_type, $line['price_ttc'], $prod->type, -1, 0, '', 0, (!empty($parent_line)) ? $parent_line : '', null, '', '', $line['array_options'], 100, '', null, 0); + $idoflineadded = $invoice->addline($line['description'], $line['price'], $qty, $line['tva_tx'], $line['localtax1_tx'], $line['localtax2_tx'], $idproduct, $line['remise_percent'], '', 0, 0, 0, '', $price_base_type, $line['price_ttc'], $prod->type, -1, 0, '', 0, (!empty($parent_line)) ? $parent_line : '', $line['fk_fournprice'], $line['pa_ht'], '', $line['array_options'], 100, '', null, 0); } if (!empty($conf->global->TAKEPOS_CUSTOMER_DISPLAY)) { diff --git a/htdocs/takepos/pay.php b/htdocs/takepos/pay.php index 24ca8cc782b..af6a4f79d71 100644 --- a/htdocs/takepos/pay.php +++ b/htdocs/takepos/pay.php @@ -130,7 +130,7 @@ if ($invoiceid > 0) { if ($invoice->type != $invoice::TYPE_CREDIT_NOTE) { if (empty($conf->global->$keyforstripeterminalbank)) { ?> const config = {simulated: global->STRIPE_TERMINAL_SIMULATED)) { ?> true false - global->STRIPE_LOCATION)) { ?>, location: 'global->STRIPE_LOCATION; ?>'} + global->STRIPE_LOCATION)) { ?>, location: 'global->STRIPE_LOCATION; ?>'} terminal.discoverReaders(config).then(function(discoverResult) { if (discoverResult.error) { console.log('Failed to discover: ', discoverResult.error); @@ -141,7 +141,7 @@ if ($invoiceid > 0) { // cashier here and let them select which to connect to (see below). selectedReader = discoverResult.discoveredReaders[0]; //console.log('terminal.discoverReaders', selectedReader); // only active for development - + terminal.connectReader(selectedReader).then(function(connectResult) { if (connectResult.error) { document.getElementById("card-present-alert").innerHTML = '
'+connectResult.error.message+'
'; @@ -160,7 +160,7 @@ if ($invoiceid > 0) { terminal.connectReader(getSelectedReader($conf->global->$keyforstripeterminalbank, $stripeacc, $servicestatus)); ?>).then(function(connectResult) { if (connectResult.error) { - document.getElementById("card-present-alert").innerHTML = '
'+connectResult.error.message+'
'; + document.getElementById("card-present-alert").innerHTML = '
'+connectResult.error.message+'
'; console.log('Failed to connect: ', connectResult.error); } else { document.getElementById("card-present-alert").innerHTML = ''; @@ -388,7 +388,7 @@ if ($conf->global->TAKEPOS_NUMPAD == 0) { global->STRIPE_TERMINAL_SIMULATED)) { ?> terminal.setSimulatorConfiguration({testCardNumber: 'global->STRIPE_TERMINAL_SIMULATED; ?>'}); - document.getElementById("card-present-alert").innerHTML = '
trans('PaymentSendToStripeTerminal'); ?>
'; + document.getElementById("card-present-alert").innerHTML = '
trans('PaymentSendToStripeTerminal'); ?>
'; terminal.collectPaymentMethod(client_secret).then(function(result) { if (result.error) { // Placeholder for handling result.error @@ -398,7 +398,7 @@ if ($conf->global->TAKEPOS_NUMPAD == 0) { console.log('terminal.collectPaymentMethod', result.paymentIntent); terminal.processPayment(result.paymentIntent).then(function(result) { if (result.error) { - document.getElementById("card-present-alert").innerHTML = '
'+result.error.message+'
'; + document.getElementById("card-present-alert").innerHTML = '
'+result.error.message+'
'; console.log(result.error) } else if (result.paymentIntent) { paymentIntentId = result.paymentIntent.id; @@ -409,7 +409,7 @@ if ($conf->global->TAKEPOS_NUMPAD == 0) { document.getElementById("card-present-alert").innerHTML = '
'+result.error.message+'
'; console.log("error when capturing paymentIntent", result.error); } else { - document.getElementById("card-present-alert").innerHTML = '
trans('PaymentValidated'); ?>
'; + document.getElementById("card-present-alert").innerHTML = '
trans('PaymentValidated'); ?>
'; console.log("Capture paymentIntent successfull "+paymentIntentId); parent.$("#poslines").load("invoice.php?place=&action=valid&pay=CB&amount="+amountpayed+"&excess="+excess+"&invoiceid="+invoiceid+"&accountid="+accountid, function() { if (amountpayed > || amountpayed == || amountpayed==0 ) { @@ -423,7 +423,7 @@ if ($conf->global->TAKEPOS_NUMPAD == 0) { }); } - }); + }); } }); } @@ -669,6 +669,14 @@ if ($conf->global->TAKEPOS_DELAYED_PAYMENT) { print ''; } ?> + +executeHooks('completePayment', $parameters, $invoice); +print $hookmanager->resPrint; +?> +