/**
  *  Load data control
  *
  *  @param	string	$action    Type of action
  *  @param	int		$id			Id of object
  *	@return	void
  */
 function doActions(&$action, $id)
 {
     global $conf, $user, $langs;
     // Creation utilisateur depuis Adherent
     if ($action == 'confirm_create_user' && GETPOST("confirm") == 'yes') {
         // Recuperation adherent actuel
         $result = $this->object->fetch($id);
         if ($result > 0) {
             $this->db->begin();
             // Creation user
             $nuser = new User($this->db);
             $result = $nuser->create_from_member($this->object, $_POST["login"]);
             if ($result > 0) {
                 $result2 = $nuser->setPassword($user, $_POST["password"], 0, 1, 1);
                 if ($result2) {
                     $this->db->commit();
                 } else {
                     $this->db->rollback();
                 }
             } else {
                 $this->errors[] = $nuser->error;
                 $this->db->rollback();
             }
         } else {
             $this->errors = $this->object->errors;
         }
     }
     // Creation adherent
     if ($action == 'add') {
         $this->assign_post();
         if (!$_POST["name"]) {
             array_push($this->errors, $langs->trans("ErrorFieldRequired", $langs->transnoentities("Lastname") . ' / ' . $langs->transnoentities("Label")));
             $action = 'create';
         }
         if ($_POST["name"]) {
             $id = $this->object->create($user);
             if ($id > 0) {
                 header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
                 exit;
             } else {
                 $this->errors = $this->object->errors;
                 $action = 'create';
             }
         }
     }
     if ($action == 'confirm_delete' && GETPOST("confirm") == 'yes') {
         $result = $this->object->fetch($id);
         $this->object->old_name = $_POST["old_name"];
         $this->object->old_firstname = $_POST["old_firstname"];
         $result = $this->object->delete();
         if ($result > 0) {
             header("Location: list.php");
             exit;
         } else {
             $this->errors = $this->object->errors;
         }
     }
     if ($action == 'update') {
         if ($_POST["cancel"]) {
             header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $this->object->id);
             exit;
         }
         if (empty($_POST["name"])) {
             $this->error = array($langs->trans("ErrorFieldRequired", $langs->transnoentities("Name") . ' / ' . $langs->transnoentities("Label")));
             $action = 'edit';
         }
         if (empty($this->error)) {
             $this->object->fetch($_POST["adherentid"]);
             $this->object->oldcopy = clone $this->object;
             $this->assign_post();
             $result = $this->object->update($_POST["adherentid"], $user);
             if ($result > 0) {
                 header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $this->object->id);
                 exit;
             } else {
                 $this->errors = $this->object->errors;
                 $action = 'edit';
             }
         }
     }
 }
Exemplo n.º 2
0
/**
 * Mise a jour des totaux lignes de commande fournisseur
 *
 * @param	DoliDB		$db		Database handler
 * @param	Translate	$langs	Object langs
 * @param	Conf		$conf	Object conf
 * @return	void
 */
function migrate_price_commande_fournisseur($db, $langs, $conf)
{
    $db->begin();
    print '<tr><td colspan="4">';
    print '<br>';
    print '<b>' . $langs->trans('MigrationSupplierOrder') . "</b><br>\n";
    // Liste des lignes commande non a jour
    $sql = "SELECT cd.rowid, cd.qty, cd.subprice, cd.remise_percent, cd.tva_tx as tva_taux, cd.info_bits,";
    $sql .= " c.rowid as commandeid, c.remise_percent as remise_percent_global";
    $sql .= " FROM " . MAIN_DB_PREFIX . "commande_fournisseurdet as cd, " . MAIN_DB_PREFIX . "commande_fournisseur as c";
    $sql .= " WHERE cd.fk_commande = c.rowid";
    $sql .= " AND ((cd.total_ttc = 0 AND cd.remise_percent != 100) or cd.total_ttc IS NULL)";
    dolibarr_install_syslog("upgrade2::migrate_price_commande_fournisseur", LOG_DEBUG);
    $resql = $db->query($sql);
    if ($resql) {
        $num = $db->num_rows($resql);
        $i = 0;
        if ($num) {
            while ($i < $num) {
                $obj = $db->fetch_object($resql);
                $rowid = $obj->rowid;
                $qty = $obj->qty;
                $pu = $obj->subprice;
                $txtva = $obj->tva_taux;
                $remise_percent = $obj->remise_percent;
                $remise_percent_global = $obj->remise_percent_global;
                $info_bits = $obj->info_bits;
                // On met a jour les 3 nouveaux champs
                $commandeligne = new CommandeFournisseurLigne($db);
                $commandeligne->fetch($rowid);
                $result = calcul_price_total($qty, $pu, $remise_percent, $txtva, 0, 0, $remise_percent_global, 'HT', $info_bits, 0);
                $total_ht = $result[0];
                $total_tva = $result[1];
                $total_ttc = $result[2];
                $commandeligne->total_ht = $total_ht;
                $commandeligne->total_tva = $total_tva;
                $commandeligne->total_ttc = $total_ttc;
                dolibarr_install_syslog("upgrade2: Line {$rowid}: commandeid={$obj->rowid} pu={$pu} qty={$qty} tva_taux={$txtva} remise_percent={$remise_percent} remise_global={$remise_percent_global} -> {$total_ht}, {$total_tva}, {$total_ttc}");
                print ". ";
                $commandeligne->update_total();
                /* On touche pas a facture mere
                   $commande = new Commande($db);
                   $commande->id = $obj->rowid;
                   if ( $commande->fetch($commande->id) >= 0 )
                   {
                   if ( $commande->update_price() > 0 )
                   {
                   print ". ";
                   }
                   else
                   {
                   print "Error id=".$commande->id;
                   }
                   }
                   else
                   {
                   print "Error #3";
                   }
                   */
                $i++;
            }
        } else {
            print $langs->trans("AlreadyDone");
        }
        $db->free($resql);
        /*
        $sql = "DELETE FROM ".MAIN_DB_PREFIX."commande_fournisseurdet";
        $sql.= " WHERE subprice = 0 and total_ttc = 0 and total_tva = 0 and total_ht = 0";
        $resql=$db->query($sql);
        if (! $resql)
        {
        dol_print_error($db);
        }
        */
        $db->commit();
    } else {
        print "Error #1 " . $db->error();
        $db->rollback();
    }
    print '<br>';
    print '</td></tr>';
}