From f30c95ad2233c04b9776973cae57869ef360cd58 Mon Sep 17 00:00:00 2001 From: Yoan Mollard Date: Fri, 8 Jul 2022 14:53:46 +0200 Subject: [PATCH 01/14] Create a 3rd party from the self-subscription membership form Only when ADHERENT_DEFAULT_CREATE_THIRDPARTY = 1 --- htdocs/adherents/card.php | 28 ++++---------------------- htdocs/public/members/new.php | 12 ++++++++++- htdocs/societe/class/societe.class.php | 17 ++++++++++++---- 3 files changed, 28 insertions(+), 29 deletions(-) diff --git a/htdocs/adherents/card.php b/htdocs/adherents/card.php index ee195da77be..4ac0d020458 100644 --- a/htdocs/adherents/card.php +++ b/htdocs/adherents/card.php @@ -564,36 +564,16 @@ if (empty($reshook)) { $id = $object->id; } else { $db->rollback(); + setEventMessages($object->error, $object->errors, 'errors'); - if ($object->error) { - setEventMessages($object->error, $object->errors, 'errors'); - } else { - 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/public/members/new.php b/htdocs/public/members/new.php index d29d80cf5d4..ac06a95a2b6 100644 --- a/htdocs/public/members/new.php +++ b/htdocs/public/members/new.php @@ -254,7 +254,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; @@ -375,6 +375,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 7c5773363c4..9d7a666d87d 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -3904,12 +3904,21 @@ class Societe extends CommonObject global $conf, $user, $langs; dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG); - - $name = $socname ? $socname : $member->societe; - if (empty($name)) { - $name = $member->getFullName($langs); + $fullname = $member->getFullName($langs); + + if ($member->morphy == 'mor') { + $socname = $member->company? $member->company : $member->societe; + if (!empty($fullname) && empty($socalias)) { + $socalias = $fullname; + } + } else if(empty($socname) && $member->morphy == 'phy') { + $socname = $fullname; + if (!empty($member->company) && empty($socalias)) { + $socalias = $member->company; + } } + $name = $socname; $alias = $socalias ? $socalias : ''; // Positionne parametres From b0c9f5c3123084b3ac3767d2e27647e414b75108 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Mon, 25 Jul 2022 14:14:28 +0000 Subject: [PATCH 02/14] Fixing style errors. --- htdocs/societe/class/societe.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 9d7a666d87d..68942d5f9ba 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -3905,13 +3905,13 @@ class Societe extends CommonObject dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG); $fullname = $member->getFullName($langs); - + if ($member->morphy == 'mor') { $socname = $member->company? $member->company : $member->societe; if (!empty($fullname) && empty($socalias)) { $socalias = $fullname; } - } else if(empty($socname) && $member->morphy == 'phy') { + } elseif (empty($socname) && $member->morphy == 'phy') { $socname = $fullname; if (!empty($member->company) && empty($socalias)) { $socalias = $member->company; From 8b87bfb693ae29962930dae14f0693185bea7d9a Mon Sep 17 00:00:00 2001 From: Yoan Mollard Date: Thu, 11 Aug 2022 02:41:46 +0200 Subject: [PATCH 03/14] Keep original value of parameter, if any --- htdocs/societe/class/societe.class.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 68942d5f9ba..8de2bbe8bf0 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -3907,12 +3907,16 @@ class Societe extends CommonObject $fullname = $member->getFullName($langs); if ($member->morphy == 'mor') { - $socname = $member->company? $member->company : $member->societe; + if (empty($socname)) { + $socname = $member->company? $member->company : $member->societe; + } if (!empty($fullname) && empty($socalias)) { $socalias = $fullname; } } elseif (empty($socname) && $member->morphy == 'phy') { - $socname = $fullname; + if (empty($socname)) { + $socname = $fullname; + } if (!empty($member->company) && empty($socalias)) { $socalias = $member->company; } From 2d8c6292001acc71638f1935f3d41d552cd0b28d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?This=20Charl=C3=A8ne?= <1179011+defrance@users.noreply.github.com> Date: Thu, 11 Aug 2022 09:01:55 +0200 Subject: [PATCH 04/14] if we set another view list mode, we keep it if we set another view list mode, we keep it (till we change one more time) --- htdocs/admin/modules.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php index 286ccc424e8..517b3e509e7 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'); From 978f1caf1a0c3981839f08558a4398c2646039da Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?This=20Charl=C3=A8ne?= <1179011+defrance@users.noreply.github.com> Date: Thu, 11 Aug 2022 09:03:17 +0200 Subject: [PATCH 05/14] Update admin.lib.php --- htdocs/core/lib/admin.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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); From a4097c9bc17cf47294ecbe31406e1a64ed14b61f Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 11 Aug 2022 07:09:11 +0000 Subject: [PATCH 06/14] Fixing style errors. --- htdocs/admin/modules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/admin/modules.php b/htdocs/admin/modules.php index 517b3e509e7..d04039aefdf 100644 --- a/htdocs/admin/modules.php +++ b/htdocs/admin/modules.php @@ -47,7 +47,7 @@ $langs->loadLangs(array("errors", "admin", "modulebuilder")); 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); + 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); } From c9c5204923f6a7ca73d2133db6c788d8ef6bb3d1 Mon Sep 17 00:00:00 2001 From: Philippe GRAND Date: Thu, 11 Aug 2022 09:39:29 +0200 Subject: [PATCH 07/14] update code for PHP8 compliance --- htdocs/accountancy/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/accountancy/index.php b/htdocs/accountancy/index.php index bd48c205dae..3bbdd82fe59 100644 --- a/htdocs/accountancy/index.php +++ b/htdocs/accountancy/index.php @@ -111,13 +111,13 @@ if (!empty($conf->global->INVOICE_USE_SITUATION) && $conf->global->INVOICE_USE_S '; } - + print load_fiche_titre($langs->trans("AccountancyArea"), $resultboxes['selectboxlist'], 'accountancy', 0, '', '', $showtutorial); 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"; From 3d45d9897ada4514c35969314814631b00a91704 Mon Sep 17 00:00:00 2001 From: stickler-ci Date: Thu, 11 Aug 2022 07:40:32 +0000 Subject: [PATCH 08/14] Fixing style errors. --- htdocs/accountancy/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/accountancy/index.php b/htdocs/accountancy/index.php index 3bbdd82fe59..926097c1509 100644 --- a/htdocs/accountancy/index.php +++ b/htdocs/accountancy/index.php @@ -111,7 +111,7 @@ if (!empty($conf->global->INVOICE_USE_SITUATION) && $conf->global->INVOICE_USE_S '; } - + print load_fiche_titre($langs->trans("AccountancyArea"), $resultboxes['selectboxlist'], 'accountancy', 0, '', '', $showtutorial); print '
'; // hideobject is to start hidden From 75fbebbcb6b560a2dfa1d6b4e0991f89e5a23984 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 11 Aug 2022 10:03:44 +0200 Subject: [PATCH 09/14] token was not refreshing --- htdocs/core/class/CMailFile.class.php | 36 ++++++++++++++++++- .../modules/printing/printgcp.modules.php | 1 - 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index 54573f92c7a..9aa761419a2 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,41 @@ class CMailFile require_once DOL_DOCUMENT_ROOT.'/includes/OAuth/bootstrap.php'; $storage = new DoliStorage($db, $conf); + try { - $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME); + $token_ok = true; + try { + $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME); + } catch (Exception $e) { + $this->errors[] = $e->getMessage(); + $token_ok = false; + } + $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 ($token_ok && $expire) { + try { + $credentials = new Credentials( + getDolGlobalString('OAUTH_'.$conf->global->MAIN_MAIL_SMTPS_OAUTH_SERVICE.'_ID'), + getDolGlobalString('OAUTH_'.$conf->global->MAIN_MAIL_SMTPS_OAUTH_SERVICE.'_SECRET'), + getDolGlobalString('OAUTH_'.$conf->global->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); + } catch (Exception $e) { + $this->errors[] = $e->getMessage(); + } + } if (is_object($tokenobj)) { $this->transport->setAuthMode('XOAUTH2'); $this->transport->setPassword($tokenobj->getAccessToken()); 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 From b748665296de45a4805c6913c651ae88f751d5ae Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 11 Aug 2022 10:16:20 +0200 Subject: [PATCH 10/14] token was not refreshing --- htdocs/core/class/CMailFile.class.php | 42 ++++++++++----------------- 1 file changed, 16 insertions(+), 26 deletions(-) diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index 9aa761419a2..69a5b0ba902 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -984,38 +984,28 @@ class CMailFile $storage = new DoliStorage($db, $conf); try { - $token_ok = true; - try { - $tokenobj = $storage->retrieveAccessToken($OAUTH_SERVICENAME); - } catch (Exception $e) { - $this->errors[] = $e->getMessage(); - $token_ok = false; - } + $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 ($token_ok && $expire) { - try { - $credentials = new Credentials( - getDolGlobalString('OAUTH_'.$conf->global->MAIN_MAIL_SMTPS_OAUTH_SERVICE.'_ID'), - getDolGlobalString('OAUTH_'.$conf->global->MAIN_MAIL_SMTPS_OAUTH_SERVICE.'_SECRET'), - getDolGlobalString('OAUTH_'.$conf->global->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); - } catch (Exception $e) { - $this->errors[] = $e->getMessage(); - } + if (is_object($tokenobj) && $expire) { + $credentials = new Credentials( + getDolGlobalString('OAUTH_'.$conf->global->MAIN_MAIL_SMTPS_OAUTH_SERVICE.'_ID'), + getDolGlobalString('OAUTH_'.$conf->global->MAIN_MAIL_SMTPS_OAUTH_SERVICE.'_SECRET'), + getDolGlobalString('OAUTH_'.$conf->global->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'); From d7bccaa70c6f7ec310a65a9258f9373b7580fc05 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 11 Aug 2022 10:53:15 +0200 Subject: [PATCH 11/14] token was not refreshing --- htdocs/core/class/CMailFile.class.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/core/class/CMailFile.class.php b/htdocs/core/class/CMailFile.class.php index 69a5b0ba902..79291aacdf0 100644 --- a/htdocs/core/class/CMailFile.class.php +++ b/htdocs/core/class/CMailFile.class.php @@ -993,9 +993,9 @@ class CMailFile // Token expired so we refresh it if (is_object($tokenobj) && $expire) { $credentials = new Credentials( - getDolGlobalString('OAUTH_'.$conf->global->MAIN_MAIL_SMTPS_OAUTH_SERVICE.'_ID'), - getDolGlobalString('OAUTH_'.$conf->global->MAIN_MAIL_SMTPS_OAUTH_SERVICE.'_SECRET'), - getDolGlobalString('OAUTH_'.$conf->global->MAIN_MAIL_SMTPS_OAUTH_SERVICE.'_URLAUTHORIZE') + 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); From c14d7a93f95536aa575f886309c99b0336cb6e7f Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Thu, 11 Aug 2022 16:01:29 +0200 Subject: [PATCH 12/14] NEW : add margin infos to takepos invoice lines --- htdocs/takepos/invoice.php | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) 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)) { From 1faa9d8231f439b7ebc9f00f1a32a48ab48ad364 Mon Sep 17 00:00:00 2001 From: Christophe Battarel Date: Thu, 11 Aug 2022 16:29:55 +0200 Subject: [PATCH 13/14] add hook to complete payment --- htdocs/takepos/pay.php | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) 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; +?> +
From 95878e13a7a63e67177334b441863af7a11a4bab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Thu, 11 Aug 2022 16:51:41 +0200 Subject: [PATCH 14/14] doc --- htdocs/core/class/commonobject.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 6d460dfadf0..cbf41d8f75c 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;