Example #1
0
        {
            require_once(DOL_DOCUMENT_ROOT.'/core/modules/societe/modules_societe.class.php');

            $object->load($socid);

            // Define output language
            $outputlangs = $langs;
            $newlang='';
            if ($conf->global->MAIN_MULTILANGS && empty($newlang) && ! empty($_REQUEST['lang_id'])) $newlang=$_REQUEST['lang_id'];
            if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$fac->client->default_lang;
            if (! empty($newlang))
            {
                $outputlangs = new Translate("",$conf);
                $outputlangs->setDefaultLang($newlang);
            }
            $result=thirdparty_doc_create($db, $object, '', $_REQUEST['model'], $outputlangs);
            if ($result <= 0)
            {
                dol_print_error($db,$result);
                exit;
            }
            else
            {
                Header('Location: '.$_SERVER["PHP_SELF"].'?socid='.$object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
                exit;
            }
        }
    }

    // Remove file in doc form
    else if ($action == 'remove_file')
Example #2
0
         require_once DOL_DOCUMENT_ROOT . '/core/modules/societe/modules_societe.class.php';
         $object->fetch($socid);
         // Define output language
         $outputlangs = $langs;
         $newlang = '';
         if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) {
             $newlang = GETPOST('lang_id');
         }
         if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
             $newlang = $fac->client->default_lang;
         }
         if (!empty($newlang)) {
             $outputlangs = new Translate("", $conf);
             $outputlangs->setDefaultLang($newlang);
         }
         $result = thirdparty_doc_create($db, $object, '', GETPOST('model', 'alpha'), $outputlangs);
         if ($result <= 0) {
             dol_print_error($db, $result);
             exit;
         }
     }
 } else {
     if ($action == 'remove_file') {
         if ($object->fetch($socid)) {
             require_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php';
             $langs->load("other");
             $upload_dir = $conf->societe->dir_output;
             $file = $upload_dir . '/' . GETPOST('file');
             $ret = dol_delete_file($file, 0, 0, 0, $object);
             if ($ret) {
                 setEventMessage($langs->trans("FileWasRemoved", GETPOST('urlfile')));
 /**
  *	Load data control
  *
  *	@param	int		$action	Action code
  *	@return	void
  */
 function doActions(&$action)
 {
     global $conf, $user, $langs;
     if ($_POST["getcustomercode"]) {
         // We defined value code_client
         $_POST["code_client"] = "Acompleter";
     }
     if ($_POST["getsuppliercode"]) {
         // We defined value code_fournisseur
         $_POST["code_fournisseur"] = "Acompleter";
     }
     // Add new third party
     if (!$_POST["getcustomercode"] && !$_POST["getsuppliercode"] && ($action == 'add' || $action == 'update')) {
         require_once DOL_DOCUMENT_ROOT . '/core/lib/functions2.lib.php';
         $error = 0;
         if (GETPOST("private") == 1) {
             $this->object->particulier = GETPOST("private");
             $this->object->name = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION) ? trim($_POST["firstname"] . ' ' . $_POST["lastname"]) : trim($_POST["lastname"] . ' ' . $_POST["firstname"]);
             $this->object->civility_id = $_POST["civility_id"];
             // Add non official properties
             $this->object->name_bis = $_POST["lastname"];
             $this->object->firstname = $_POST["firstname"];
         } else {
             $this->object->name = $_POST["nom"];
         }
         $this->object->address = $_POST["adresse"];
         $this->object->zip = $_POST["zipcode"];
         $this->object->town = $_POST["town"];
         $this->object->country_id = $_POST["country_id"];
         $this->object->state_id = $_POST["state_id"];
         $this->object->phone = $_POST["tel"];
         $this->object->fax = $_POST["fax"];
         $this->object->email = trim($_POST["email"]);
         $this->object->url = $_POST["url"];
         $this->object->idprof1 = $_POST["idprof1"];
         $this->object->idprof2 = $_POST["idprof2"];
         $this->object->idprof3 = $_POST["idprof3"];
         $this->object->idprof4 = $_POST["idprof4"];
         $this->object->prefix_comm = $_POST["prefix_comm"];
         $this->object->code_client = $_POST["code_client"];
         $this->object->code_fournisseur = $_POST["code_fournisseur"];
         $this->object->capital = $_POST["capital"];
         $this->object->barcode = $_POST["barcode"];
         $this->object->canvas = GETPOST("canvas");
         $this->object->tva_assuj = $_POST["assujtva_value"];
         // Local Taxes
         $this->object->localtax1_assuj = $_POST["localtax1assuj_value"];
         $this->object->localtax2_assuj = $_POST["localtax2assuj_value"];
         $this->object->tva_intra = $_POST["tva_intra"];
         $this->object->forme_juridique_code = $_POST["forme_juridique_code"];
         $this->object->effectif_id = $_POST["effectif_id"];
         if (GETPOST("private") == 1) {
             $this->object->typent_id = dol_getIdFromCode($db, 'TE_PRIVATE', 'c_typent');
         } else {
             $this->object->typent_id = $_POST["typent_id"];
         }
         $this->object->client = $_POST["client"];
         $this->object->fournisseur = $_POST["fournisseur"];
         $this->object->commercial_id = $_POST["commercial_id"];
         $this->object->default_lang = $_POST["default_lang"];
         // Check parameters
         if (empty($_POST["cancel"])) {
             if (!empty($this->object->email) && !isValidEMail($this->object->email)) {
                 $error = 1;
                 $langs->load("errors");
                 $this->error = $langs->trans("ErrorBadEMail", $this->object->email);
                 $action = $action == 'add' ? 'create' : 'edit';
             }
             if (!empty($this->object->url) && !isValidUrl($this->object->url)) {
                 $error = 1;
                 $langs->load("errors");
                 $this->error = $langs->trans("ErrorBadUrl", $this->object->url);
                 $action = $action == 'add' ? 'create' : 'edit';
             }
             if ($this->object->fournisseur && !$conf->fournisseur->enabled) {
                 $error = 1;
                 $langs->load("errors");
                 $this->error = $langs->trans("ErrorSupplierModuleNotEnabled");
                 $action = $action == 'add' ? 'create' : 'edit';
             }
         }
         if (!$error) {
             if ($action == 'add') {
                 $this->db->begin();
                 if (empty($this->object->client)) {
                     $this->object->code_client = '';
                 }
                 if (empty($this->object->fournisseur)) {
                     $this->object->code_fournisseur = '';
                 }
                 $result = $this->object->create($user);
                 if ($result >= 0) {
                     if ($this->object->particulier) {
                         dol_syslog(get_class($this) . "::doActions This thirdparty is a personal people", LOG_DEBUG);
                         $contact = new Contact($this->db);
                         $contact->civility_id = $this->object->civility_id;
                         $contact->name = $this->object->name_bis;
                         $contact->firstname = $this->object->firstname;
                         $contact->address = $this->object->address;
                         $contact->zip = $this->object->zip;
                         $contact->town = $this->object->town;
                         $contact->country_id = $this->object->country_id;
                         $contact->socid = $this->object->id;
                         // fk_soc
                         $contact->status = 1;
                         $contact->email = $this->object->email;
                         $contact->priv = 0;
                         $result = $contact->create($user);
                     }
                 } else {
                     $this->errors = $this->object->errors;
                 }
                 if ($result >= 0) {
                     $this->db->commit();
                     if ($this->object->client == 1) {
                         header("Location: " . DOL_URL_ROOT . "/comm/fiche.php?socid=" . $this->object->id);
                         return;
                     } else {
                         if ($this->object->fournisseur == 1) {
                             header("Location: " . DOL_URL_ROOT . "/fourn/fiche.php?socid=" . $this->object->id);
                             return;
                         } else {
                             header("Location: " . $_SERVER["PHP_SELF"] . "?socid=" . $this->object->id);
                             return;
                         }
                     }
                     exit;
                 } else {
                     $this->db->rollback();
                     $this->errors = $this->object->errors;
                     $action = 'create';
                 }
             }
             if ($action == 'update') {
                 if ($_POST["cancel"]) {
                     header("Location: " . $_SERVER["PHP_SELF"] . "?socid=" . $this->object->id);
                     exit;
                 }
                 $oldsoccanvas = dol_clone($this->object);
                 // To avoid setting code if third party is not concerned. But if it had values, we keep them.
                 if (empty($this->object->client) && empty($oldsoccanvas->code_client)) {
                     $this->object->code_client = '';
                 }
                 if (empty($this->object->fournisseur) && empty($oldsoccanvas->code_fournisseur)) {
                     $this->object->code_fournisseur = '';
                 }
                 $result = $this->object->update($this->object->id, $user, 1, $oldsoccanvas->codeclient_modifiable(), $oldsoccanvas->codefournisseur_modifiable());
                 if ($result >= 0) {
                     header("Location: " . $_SERVER["PHP_SELF"] . "?socid=" . $this->object->id);
                     exit;
                 } else {
                     $reload = 0;
                     $this->errors = $this->object->errors;
                     $action = "edit";
                 }
             }
         }
     }
     if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes') {
         $result = $this->object->delete($this->object->id);
         if ($result >= 0) {
             header("Location: " . DOL_URL_ROOT . "/societe/societe.php?delsoc=" . $this->object->nom . "");
             exit;
         } else {
             $reload = 0;
             $this->errors = $this->object->errors;
             $action = '';
         }
     }
     /*
      * Generate document
      */
     if ($action == 'builddoc') {
         if (is_numeric(GETPOST('model'))) {
             $this->error = $langs->trans("ErrorFieldRequired", $langs->transnoentities("Model"));
         } else {
             require_once DOL_DOCUMENT_ROOT . '/core/modules/societe/modules_societe.class.php';
             $this->object->fetch_thirdparty();
             // Define output language
             $outputlangs = $langs;
             $newlang = '';
             if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) {
                 $newlang = GETPOST('lang_id');
             }
             if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
                 $newlang = $this->object->default_lang;
             }
             if (!empty($newlang)) {
                 $outputlangs = new Translate("", $conf);
                 $outputlangs->setDefaultLang($newlang);
             }
             $result = thirdparty_doc_create($this->db, $this->object->id, '', GETPOST('model', 'alpha'), $outputlangs);
             if ($result <= 0) {
                 dol_print_error($this->db, $result);
                 exit;
             }
         }
     }
 }
    /**
     *    Load data control
     */
    function doActions($socid)
    {
        global $conf, $user, $langs;

        if ($_POST["getcustomercode"])
        {
            // We defined value code_client
            $_POST["code_client"]="Acompleter";
        }

        if ($_POST["getsuppliercode"])
        {
            // We defined value code_fournisseur
            $_POST["code_fournisseur"]="Acompleter";
        }

        // Add new third party
        if ((! $_POST["getcustomercode"] && ! $_POST["getsuppliercode"])
        && ($_POST["action"] == 'add' || $_POST["action"] == 'update'))
        {
            require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php");
            $error=0;

            if ($_POST["action"] == 'update')
            {
                // Load properties of company
                $this->object->fetch($socid);
            }

            if ($_REQUEST["private"] == 1)
            {
                $this->object->particulier           = $_REQUEST["private"];

                $this->object->nom                   = empty($conf->global->MAIN_FIRSTNAME_NAME_POSITION)?trim($_POST["prenom"].' '.$_POST["nom"]):trim($_POST["nom"].' '.$_POST["prenom"]);
                $this->object->nom_particulier       = $_POST["nom"];
                $this->object->prenom                = $_POST["prenom"];
                $this->object->civilite_id           = $_POST["civilite_id"];
            }
            else
            {
                $this->object->nom                   = $_POST["nom"];
            }

            $this->object->address                  = $_POST["adresse"];
            $this->object->adresse                  = $_POST["adresse"]; // TODO obsolete
            $this->object->cp                       = $_POST["zipcode"];
            $this->object->ville                    = $_POST["town"];
            $this->object->pays_id                  = $_POST["pays_id"];
            $this->object->departement_id           = $_POST["departement_id"];
            $this->object->tel                      = $_POST["tel"];
            $this->object->fax                      = $_POST["fax"];
            $this->object->email                    = trim($_POST["email"]);
            $this->object->url                      = $_POST["url"];
            $this->object->siren                    = $_POST["idprof1"];
            $this->object->siret                    = $_POST["idprof2"];
            $this->object->ape                      = $_POST["idprof3"];
            $this->object->idprof4                  = $_POST["idprof4"];
            $this->object->prefix_comm              = $_POST["prefix_comm"];
            $this->object->code_client              = $_POST["code_client"];
            $this->object->code_fournisseur         = $_POST["code_fournisseur"];
            $this->object->capital                  = $_POST["capital"];
            $this->object->gencod                   = $_POST["gencod"];
            $this->object->canvas                   = $_REQUEST["canvas"];

            $this->object->tva_assuj                = $_POST["assujtva_value"];

            // Local Taxes
            $this->object->localtax1_assuj          = $_POST["localtax1assuj_value"];
            $this->object->localtax2_assuj          = $_POST["localtax2assuj_value"];
            $this->object->tva_intra                = $_POST["tva_intra"];

            $this->object->forme_juridique_code     = $_POST["forme_juridique_code"];
            $this->object->effectif_id              = $_POST["effectif_id"];
            if ($_REQUEST["private"] == 1)
            {
                $this->object->typent_id            = 8; // TODO predict another method if the field "special" change of rowid
            }
            else
            {
                $this->object->typent_id            = $_POST["typent_id"];
            }
            $this->object->client                   = $_POST["client"];
            $this->object->fournisseur              = $_POST["fournisseur"];
            $this->object->fournisseur_categorie    = $_POST["fournisseur_categorie"];

            $this->object->commercial_id            = $_POST["commercial_id"];
            $this->object->default_lang             = $_POST["default_lang"];

            // Check parameters
            if (empty($_POST["cancel"]))
            {
                if (! empty($this->object->email) && ! isValidEMail($this->object->email))
                {
                    $error = 1;
                    $langs->load("errors");
                    $this->error = $langs->trans("ErrorBadEMail",$this->object->email);
                    $_GET["action"] = $_POST["action"]=='add'?'create':'edit';
                }
                if (! empty($this->object->url) && ! isValidUrl($this->object->url))
                {
                    $error = 1;
                    $langs->load("errors");
                    $this->error = $langs->trans("ErrorBadUrl",$this->object->url);
                    $_GET["action"] = $_POST["action"]=='add'?'create':'edit';
                }
                if ($this->object->fournisseur && ! $conf->fournisseur->enabled)
                {
                    $error = 1;
                    $langs->load("errors");
                    $this->error = $langs->trans("ErrorSupplierModuleNotEnabled");
                    $_GET["action"] = $_POST["action"]=='add'?'create':'edit';
                }
            }

            if (! $error)
            {
                if ($_POST["action"] == 'add')
                {
                    $this->db->begin();

                    if (empty($this->object->client))      $this->object->code_client='';
                    if (empty($this->object->fournisseur)) $this->object->code_fournisseur='';

                    $result = $this->object->create($user);
                    if ($result >= 0)
                    {
                        if ($this->object->particulier)
                        {
                            dol_syslog("This thirdparty is a personal people",LOG_DEBUG);
                            $contact=new Contact($this->db);

                            $contact->civilite_id   = $this->object->civilite_id;
                            $contact->name          = $this->object->nom_particulier;
                            $contact->firstname     = $this->object->prenom;
                            $contact->address       = $this->object->address;
                            $contact->cp            = $this->object->cp;
                            $contact->ville         = $this->object->ville;
                            $contact->fk_pays       = $this->object->fk_pays;
                            $contact->socid         = $this->object->id;                // fk_soc
                            $contact->status        = 1;
                            $contact->email         = $this->object->email;
                            $contact->priv          = 0;

                            $result=$contact->create($user);
                        }
                    }
                    else
                    {
                        $this->errors=$this->object->errors;
                    }

                    if ($result >= 0)
                    {
                        $this->db->commit();

                        if ( $this->object->client == 1 )
                        {
                            Header("Location: ".DOL_URL_ROOT."/comm/fiche.php?socid=".$this->object->id);
                            return;
                        }
                        else
                        {
                            if (  $this->object->fournisseur == 1 )
                            {
                                Header("Location: ".DOL_URL_ROOT."/fourn/fiche.php?socid=".$this->object->id);
                                return;
                            }
                            else
                            {
                                Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$this->object->id);
                                return;
                            }
                        }
                        exit;
                    }
                    else
                    {
                        $this->db->rollback();

                        $this->errors=$this->object->errors;
                        $_GET["action"]='create';
                    }
                }

                if ($_POST["action"] == 'update')
                {
                    if ($_POST["cancel"])
                    {
                        Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
                        exit;
                    }

                    $oldsoccanvas = new Canvas($this->db);
                    $oldsoccanvas->getCanvas('thirdparty','card',$this->object->canvas);
                    $result=$oldsoccanvas->control->object->fetch($socid);

                    // To avoid setting code if third party is not concerned. But if it had values, we keep them.
                    if (empty($this->object->client) && empty($oldsoccanvas->control->object->code_client))             $this->object->code_client='';
                    if (empty($this->object->fournisseur)&& empty($oldsoccanvas->control->object->code_fournisseur))    $this->object->code_fournisseur='';                    //var_dump($soccanvas);exit;

                    $result = $this->object->update($socid,$user,1,$oldsoccanvas->control->object->codeclient_modifiable(),$oldsoccanvas->control->object->codefournisseur_modifiable());
                    if ($result >= 0)
                    {
                        Header("Location: ".$_SERVER["PHP_SELF"]."?socid=".$socid);
                        exit;
                    }
                    else
                    {
                        $this->object->id = $socid;
                        $reload = 0;
                        $this->errors = $this->object->errors;
                        $_GET["action"]="edit";
                    }
                }
            }
        }

        if (GETPOST("action") == 'confirm_delete' && GETPOST("confirm") == 'yes')
        {
            $this->object->fetch($socid);

            $result = $this->object->delete($socid);

            if ($result >= 0)
            {
                Header("Location: ".DOL_URL_ROOT."/societe/societe.php?delsoc=".$this->object->nom."");
                exit;
            }
            else
            {
                $reload = 0;
                $this->errors=$this->object->errors;
                $_GET["action"]='';
            }
        }

        /*
         * Generate document
         */
        if (GETPOST('action') == 'builddoc')    // En get ou en post
        {
            if (is_numeric(GETPOST('model')))
            {
                $this->error=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Model"));
            }
            else
            {
                require_once(DOL_DOCUMENT_ROOT.'/includes/modules/societe/modules_societe.class.php');

                $this->object->fetch($socid);
                $this->object->fetch_thirdparty();

                // Define output language
                $outputlangs = $langs;
                $newlang='';
                if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id') ) $newlang=GETPOST('lang_id');
                if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang=$this->object->default_lang;
                if (! empty($newlang))
                {
                    $outputlangs = new Translate("",$conf);
                    $outputlangs->setDefaultLang($newlang);
                }
                $result=thirdparty_doc_create($this->db, $this->object->id, '', GETPOST('model'), $outputlangs);
                if ($result <= 0)
                {
                    dol_print_error($this->db,$result);
                    exit;
                }
                else
                {
                    Header ('Location: '.$_SERVER["PHP_SELF"].'?socid='.$this->object->id.(empty($conf->global->MAIN_JUMP_TAG)?'':'#builddoc'));
                    exit;
                }
            }
        }
    }