if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, 'societe','',''); /* * Actions */ if($_GET["socid"] && $_GET["commid"]) { if ($user->rights->societe->creer) { $soc = new Societe($db); $soc->id = $_GET["socid"]; $soc->fetch($_GET["socid"]); $soc->add_commercial($user, $_GET["commid"]); Header("Location: commerciaux.php?socid=".$soc->id); exit; } else { Header("Location: commerciaux.php?socid=".$_GET["socid"]); exit; } } if($_GET["socid"] && $_GET["delcommid"]) { if ($user->rights->societe->creer) {
/** * Create a thirdparty * * @param array $authentication Array of authentication information * @param Societe $thirdparty Thirdparty * @return array Array result */ function createThirdParty($authentication, $thirdparty) { global $db, $conf, $langs; $now = dol_now(); dol_syslog("Function: createThirdParty login="******"Name is mandatory."; } if (!$error) { include_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php'; $newobject = new Societe($db); $newobject->ref = $thirdparty['ref']; $newobject->name = $thirdparty['ref']; $newobject->ref_ext = $thirdparty['ref_ext']; $newobject->status = $thirdparty['status']; $newobject->client = $thirdparty['client']; $newobject->fournisseur = $thirdparty['supplier']; $newobject->code_client = $thirdparty['customer_code']; $newobject->code_fournisseur = $thirdparty['supplier_code']; $newobject->code_compta = $thirdparty['customer_code_accountancy']; $newobject->code_compta_fournisseur = $thirdparty['supplier_code_accountancy']; $newobject->date_creation = $now; $newobject->note_private = $thirdparty['note_private']; $newobject->note_public = $thirdparty['note_public']; $newobject->address = $thirdparty['address']; $newobject->zip = $thirdparty['zip']; $newobject->town = $thirdparty['town']; $newobject->country_id = $thirdparty['country_id']; if ($thirdparty['country_code']) { $newobject->country_id = getCountry($thirdparty['country_code'], 3); } $newobject->province_id = $thirdparty['province_id']; //if ($thirdparty['province_code']) $newobject->province_code=getCountry($thirdparty['province_code'],3); $newobject->phone = $thirdparty['phone']; $newobject->fax = $thirdparty['fax']; $newobject->email = $thirdparty['email']; $newobject->url = $thirdparty['url']; $newobject->idprof1 = $thirdparty['profid1']; $newobject->idprof2 = $thirdparty['profid2']; $newobject->idprof3 = $thirdparty['profid3']; $newobject->idprof4 = $thirdparty['profid4']; $newobject->idprof5 = $thirdparty['profid5']; $newobject->idprof6 = $thirdparty['profid6']; $newobject->capital = $thirdparty['capital']; $newobject->barcode = $thirdparty['barcode']; $newobject->tva_assuj = $thirdparty['vat_used']; $newobject->tva_intra = $thirdparty['vat_number']; $newobject->canvas = $thirdparty['canvas']; $newobject->particulier = $thirdparty['individual']; //Retreive all extrafield for thirdsparty // fetch optionals attributes and labels $extrafields = new ExtraFields($db); $extralabels = $extrafields->fetch_name_optionals_label('societe', true); foreach ($extrafields->attribute_label as $key => $label) { $key = 'options_' . $key; $newobject->array_options[$key] = $thirdparty[$key]; } $db->begin(); $result = $newobject->create($fuser); if ($newobject->particulier && $result > 0) { $newobject->firstname = $thirdparty['firstname']; $newobject->name_bis = $thirdparty['lastname']; $result = $newobject->create_individual($fuser); } if ($result <= 0) { $error++; } if (!$error) { $db->commit(); // Patch to add capability to associate (one) sale representative if ($thirdparty['commid'] && $thirdparty['commid'] > 0) { $newobject->add_commercial($fuser, $thirdparty["commid"]); } $objectresp = array('result' => array('result_code' => 'OK', 'result_label' => ''), 'id' => $newobject->id, 'ref' => $newobject->ref); } else { $db->rollback(); $error++; $errorcode = 'KO'; $errorlabel = $newobject->error; } } if ($error) { $objectresp = array('result' => array('result_code' => $errorcode, 'result_label' => $errorlabel)); } return $objectresp; }