From 0fc2f008bdb982188f0e1e41bb42edb3ee93fe95 Mon Sep 17 00:00:00 2001 From: bagtaib Date: Mon, 29 Aug 2022 11:24:42 +0100 Subject: [PATCH 1/4] first try --- htdocs/public/partnership/new.php | 71 ++++++++++++++++++++----------- 1 file changed, 46 insertions(+), 25 deletions(-) diff --git a/htdocs/public/partnership/new.php b/htdocs/public/partnership/new.php index 9178d37ddc6..4d30f42b0db 100644 --- a/htdocs/public/partnership/new.php +++ b/htdocs/public/partnership/new.php @@ -67,7 +67,7 @@ $backtopage = GETPOST('backtopage', 'alpha'); $action = GETPOST('action', 'aZ09'); // Load translation files -$langs->loadLangs(array("main", "members", "companies", "install", "other")); +$langs->loadLangs(array("main", "members", "partnership", "companies", "install", "other")); // Security check if (empty($conf->partnership->enabled)) { @@ -178,10 +178,10 @@ if (empty($reshook) && $action == 'add') { $db->begin(); - /*if (GETPOST('typeid') <= 0) { + if (GETPOST('partnershiptype', 'int') <= 0) { $error++; $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Type"))."
\n"; - }*/ + } if (!GETPOST('societe')) { $error++; $errmsg .= $langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("societe"))."
\n"; @@ -208,7 +208,6 @@ if (empty($reshook) && $action == 'add') { if (!$error) { $partnership = new Partnership($db); - $partnershipt = new PartnershipType($db); // We try to find the thirdparty or the member if (getDolGlobalString('PARTNERSHIP_IS_MANAGED_FOR', 'thirdparty') == 'thirdparty') { @@ -217,29 +216,51 @@ if (empty($reshook) && $action == 'add') { $partnership->fk_soc = 0; } - $partnership->status = 0; - $partnership->note_private = GETPOST('note_private'); - $partnership->date_creation = dol_now(); + $partnership->status = 0; + $partnership->note_private = GETPOST('note_private'); + $partnership->date_creation = dol_now(); $partnership->date_partnership_start = dol_now(); - $partnership->fk_user_creat = 0; - - /*$partnershipt->fetch(0, 'default'); - if ($partnershipt->id > 0) { - $partnership->fk_type = $partnershipt->id; - }*/ - $partnership->fk_type = GETPOST('partnershiptype', 'int'); - - //$partnership->firstname = GETPOST('firstname'); - //$partnership->lastname = GETPOST('lastname'); - //$partnership->address = GETPOST('address'); - //$partnership->zip = GETPOST('zipcode'); - //$partnership->town = GETPOST('town'); - //$partnership->email = GETPOST('email'); - //$partnership->country_id = GETPOST('country_id', 'int'); - //$partnership->state_id = GETPOST('state_id', 'int'); - //$partnership->typeid = $conf->global->PARTNERSHIP_NEWFORM_FORCETYPE ? $conf->global->PARTNERSHIP_NEWFORM_FORCETYPE : GETPOST('typeid', 'int'); + $partnership->fk_user_creat = 0; + $partnership->fk_type = GETPOST('partnershiptype', 'int'); + //$partnership->typeid = $conf->global->PARTNERSHIP_NEWFORM_FORCETYPE ? $conf->global->PARTNERSHIP_NEWFORM_FORCETYPE : GETPOST('typeid', 'int'); // test if societe already exist + $company = new Societe($db); + $result = $company->fetch(0, GETPOST('societe')); + if ($result == 0) { // si il ya pas d'entree sur le nom on teste l'email + $result1 = $company->fetch(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, GETPOST('email')); + if ($result1 > 0) { + $error++; + $errmsg = $langs->trans("already exists please rewrite your company name"); + } else { + //create thirdparty + $company = new Societe($db); + + $company->name = GETPOST('societe'); + $company->address = GETPOST('address'); + $company->zip = GETPOST('zipcode'); + $company->town = GETPOST('town'); + $company->email = GETPOST('email'); + $company->country_id = GETPOST('country_id', 'int'); + $company->state_id = GETPOST('state_id', 'int'); + $company->name_alias = dolGetFirstLastname(GETPOST('firstname'), GETPOST('lastname')); + + $resultat=$company->create($user); + if ($resultat < 0) { + $error++; + $errmsg .= join('
', $company->errors); + } + + $partnership->fk_soc = $company->id; + } + } elseif ($result == -2) { + $error++; + $errmsg = $langs->trans('more than one entry exist for this company please contact us to complete your partnership request'); + } else { + $partnership->fk_soc = $company->id; + } + + /* $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE nom='".$db->escape(GETPOST('societe'))."'"; $result = $db->query($sql); if ($result) { @@ -280,7 +301,7 @@ if (empty($reshook) && $action == 'add') { } else { $company = $db->fetch_object($result); $partnership->fk_soc = $company->rowid; - } + }*/ // Fill array 'array_options' with data from add form $extrafields->fetch_name_optionals_label($partnership->table_element); From 825fee4f79998d7dfd6bf4795b7acb5d29684ae1 Mon Sep 17 00:00:00 2001 From: bagtaib Date: Tue, 30 Aug 2022 00:36:29 +0100 Subject: [PATCH 2/4] update company fields if already exists --- htdocs/langs/en_US/companies.lang | 2 + htdocs/langs/en_US/partnership.lang | 1 + htdocs/public/partnership/new.php | 68 ++++++++++------------------- 3 files changed, 27 insertions(+), 44 deletions(-) diff --git a/htdocs/langs/en_US/companies.lang b/htdocs/langs/en_US/companies.lang index 996c98c203a..2ef90f89600 100644 --- a/htdocs/langs/en_US/companies.lang +++ b/htdocs/langs/en_US/companies.lang @@ -498,3 +498,5 @@ RestOfEurope=Rest of Europe (EEC) OutOfEurope=Out of Europe (EEC) CurrentOutstandingBillLate=Current outstanding bill late BecarefullChangeThirdpartyBeforeAddProductToInvoice=Be carefull, depending on your product price settings, you should change thirdparty before adding product to POS. +EmailAlreadyExistsPleaseRewriteYourCompanyName=email already exists please rewrite your company name +TwoRecordsOfCompanyName=more than one record exists for this company please contact us to complete your partnership request" \ No newline at end of file diff --git a/htdocs/langs/en_US/partnership.lang b/htdocs/langs/en_US/partnership.lang index 5c85e4d7830..6490bf23d8b 100644 --- a/htdocs/langs/en_US/partnership.lang +++ b/htdocs/langs/en_US/partnership.lang @@ -28,6 +28,7 @@ PartnershipCheckBacklink=Partnership: Check referring backlink # Menu # NewPartnership=New Partnership +NewPartnershipbyWeb= Your partnership was added successfully. ListOfPartnerships=List of partnership # diff --git a/htdocs/public/partnership/new.php b/htdocs/public/partnership/new.php index 4d30f42b0db..a50892c9e08 100644 --- a/htdocs/public/partnership/new.php +++ b/htdocs/public/partnership/new.php @@ -231,7 +231,7 @@ if (empty($reshook) && $action == 'add') { $result1 = $company->fetch(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, GETPOST('email')); if ($result1 > 0) { $error++; - $errmsg = $langs->trans("already exists please rewrite your company name"); + $errmsg = $langs->trans("EmailAlreadyExistsPleaseRewriteYourCompanyName"); } else { //create thirdparty $company = new Societe($db); @@ -255,53 +255,33 @@ if (empty($reshook) && $action == 'add') { } } elseif ($result == -2) { $error++; - $errmsg = $langs->trans('more than one entry exist for this company please contact us to complete your partnership request'); + $errmsg = $langs->trans("TwoRecordsOfCompanyName"); } else { $partnership->fk_soc = $company->id; - } - - /* - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE nom='".$db->escape(GETPOST('societe'))."'"; - $result = $db->query($sql); - if ($result) { - $num = $db->num_rows($result); - } - if ($num = 0) { // si il ya pas d'entree sur le nom on teste l'email - $sql1 = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe WHERE email='".$db->escape(GETPOST('email'))."'"; - $result1 = $db->query($sql1); - if ($result1) { - $num1 = $db->num_rows($result1); + // update thirdparty fields + if (empty($company->address)) { + $company->address = GETPOST('address'); } - if ($num1 != 0) { - $error++; - $errmsg = "email already exists please rewrite your company name"; - } else { - //create thirdparty - $company = new Societe($db); - - $company->address = GETPOST('address'); - $company->zip = GETPOST('zipcode'); - $company->town = GETPOST('town'); - $company->email = GETPOST('email'); - $company->country_id = GETPOST('country_id', 'int'); - $company->state_id = GETPOST('state_id', 'int'); - $company->name_alias = dolGetFirstLastname(GETPOST('firstname'), GETPOST('lastname')); - - $resultat=$company->create($user); - if ($resultat < 0) { - $error++; - $errmsg .= join('
', $company->errors); - } - - $partnership->fk_soc = $company->id; + if (empty($company->zip)) { + $company->zip = GETPOST('zipcode'); } - } elseif ($num > 1) { - $error++; - $errmsg = 'more than one entry exist for this company please contact us to complete your partnership request'; - } else { - $company = $db->fetch_object($result); - $partnership->fk_soc = $company->rowid; - }*/ + if (empty($company->town)) { + $company->town = GETPOST('town'); + } + if (empty($company->country_id)) { + $company->country_id = GETPOST('country_id', 'int'); + } + if (empty($company->email)) { + $company->email = GETPOST('email'); + } + if (empty($company->state_id)) { + $company->state_id = GETPOST('state_id', 'int'); + } + if (empty($company->name_alias)) { + $company->name_alias = dolGetFirstLastname(GETPOST('firstname'), GETPOST('lastname')); + } + $company->update(0); + } // Fill array 'array_options' with data from add form $extrafields->fetch_name_optionals_label($partnership->table_element); From 630c81772836c8771fa8b82780860e35436b894a Mon Sep 17 00:00:00 2001 From: UT from dolibit <45215329+dolibit-ut@users.noreply.github.com> Date: Tue, 30 Aug 2022 09:47:56 +0200 Subject: [PATCH 3/4] Update agenda.php --- htdocs/contact/agenda.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/htdocs/contact/agenda.php b/htdocs/contact/agenda.php index 5f07922b2e4..29706f48b49 100644 --- a/htdocs/contact/agenda.php +++ b/htdocs/contact/agenda.php @@ -29,6 +29,8 @@ * \brief Card of a contact */ + +// Load Dolibarr environment require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; @@ -49,12 +51,14 @@ $langs->loadLangs(array('companies', 'users', 'other', 'commercial')); $mesg = ''; $error = 0; $errors = array(); +// Get parameters $action = (GETPOST('action', 'alpha') ? GETPOST('action', 'alpha') : 'view'); $confirm = GETPOST('confirm', 'alpha'); $backtopage = GETPOST('backtopage', 'alpha'); $id = GETPOST('id', 'int'); $socid = GETPOST('socid', 'int'); +// Initialize objects $object = new Contact($db); $extrafields = new ExtraFields($db); From ae3a70a88686ee8fcdb2e32cdd20f604c8dcae0c Mon Sep 17 00:00:00 2001 From: UT from dolibit <45215329+dolibit-ut@users.noreply.github.com> Date: Tue, 30 Aug 2022 09:54:09 +0200 Subject: [PATCH 4/4] Update info.php --- htdocs/contact/info.php | 2 ++ 1 file changed, 2 insertions(+) diff --git a/htdocs/contact/info.php b/htdocs/contact/info.php index 4cea1cae85b..64688635179 100644 --- a/htdocs/contact/info.php +++ b/htdocs/contact/info.php @@ -23,6 +23,8 @@ * \brief Onglet info d'un contact */ + +// Load Dolibarr environment require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';