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 9178d37ddc6..a50892c9e08 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,47 +216,27 @@ 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 - $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); - } - if ($num1 != 0) { + $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 = "email already exists please rewrite your company name"; + $errmsg = $langs->trans("EmailAlreadyExistsPleaseRewriteYourCompanyName"); } else { //create thirdparty $company = new Societe($db); + $company->name = GETPOST('societe'); $company->address = GETPOST('address'); $company->zip = GETPOST('zipcode'); $company->town = GETPOST('town'); @@ -274,12 +253,34 @@ if (empty($reshook) && $action == 'add') { $partnership->fk_soc = $company->id; } - } elseif ($num > 1) { + } elseif ($result == -2) { $error++; - $errmsg = 'more than one entry exist for this company please contact us to complete your partnership request'; + $errmsg = $langs->trans("TwoRecordsOfCompanyName"); } else { - $company = $db->fetch_object($result); - $partnership->fk_soc = $company->rowid; + $partnership->fk_soc = $company->id; + // update thirdparty fields + if (empty($company->address)) { + $company->address = GETPOST('address'); + } + if (empty($company->zip)) { + $company->zip = GETPOST('zipcode'); + } + 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