Exemplo n.º 1
0
        $result = $object_ligne->insert();
        if ($result > 0) {
            $db->commit();
            header("Location: " . $_SERVER["PHP_SELF"] . "?id=" . $id);
            exit;
        } else {
            dol_print_error($db, $object->error);
            $db->rollback();
        }
    }
    $action = '';
}
if ($action == 'confirm_delete_line' && GETPOST("confirm") == "yes") {
    $object = new ExpenseReport($db);
    $object->fetch($id);
    $object_ligne = new ExpenseReportLine($db);
    $object_ligne->fetch(GETPOST("rowid"));
    $total_ht = $object_ligne->total_ht;
    $total_tva = $object_ligne->total_tva;
    $result = $object->deleteline(GETPOST("rowid"));
    if ($result >= 0) {
        if ($result > 0) {
            // Define output language
            if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
                $outputlangs = $langs;
                $newlang = '';
                if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) {
                    $newlang = GETPOST('lang_id', 'alpha');
                }
                if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
                    $newlang = $object->thirdparty->default_lang;
 /**
  * updateline
  *
  * @param   int         $rowid                  Line to edit
  * @param   int         $type_fees_id           Type payment
  * @param   int         $projet_id              Project id
  * @param   double      $vatrate                Vat rate
  * @param   string      $comments               Description
  * @param   real        $qty                    Qty
  * @param   double      $value_unit             Value init
  * @param   int         $date                   Date
  * @param   int         $expensereport_id       Expense report id
  * @return  int                                 <0 if KO, >0 if OK
  */
 function updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty, $value_unit, $date, $expensereport_id)
 {
     global $user;
     if ($this->fk_statut == 0 || $this->fk_statut == 99) {
         $this->db->begin();
         // calcul de tous les totaux de la ligne
         $total_ttc = price2num($qty * $value_unit, 'MT');
         $tx_tva = $vatrate / 100;
         $tx_tva = $tx_tva + 1;
         $total_ht = price2num($total_ttc / $tx_tva, 'MT');
         $total_tva = price2num($total_ttc - $total_ht, 'MT');
         // fin calculs
         $ligne = new ExpenseReportLine($this->db);
         $ligne->comments = $comments;
         $ligne->qty = $qty;
         $ligne->value_unit = $value_unit;
         $ligne->date = $date;
         $ligne->fk_expensereport = $expensereport_id;
         $ligne->fk_c_type_fees = $type_fees_id;
         $ligne->fk_projet = $projet_id;
         $ligne->total_ht = $total_ht;
         $ligne->total_tva = $total_tva;
         $ligne->total_ttc = $total_ttc;
         $ligne->vatrate = price2num($vatrate);
         $ligne->rowid = $rowid;
         // Select des infos sur le type fees
         $sql = "SELECT c.code as code_type_fees, c.label as libelle_type_fees";
         $sql .= " FROM " . MAIN_DB_PREFIX . "c_type_fees as c";
         $sql .= " WHERE c.id = " . $type_fees_id;
         $result = $this->db->query($sql);
         $objp_fees = $this->db->fetch_object($result);
         $ligne->type_fees_code = $objp_fees->code_type_fees;
         $ligne->type_fees_libelle = $objp_fees->libelle_type_fees;
         // Select des informations du projet
         $sql = "SELECT p.ref as ref_projet, p.title as title_projet";
         $sql .= " FROM " . MAIN_DB_PREFIX . "projet as p";
         $sql .= " WHERE p.rowid = " . $projet_id;
         $result = $this->db->query($sql);
         $objp_projet = $this->db->fetch_object($result);
         $ligne->projet_ref = $objp_projet->ref_projet;
         $ligne->projet_title = $objp_projet->title_projet;
         $result = $ligne->update($user);
         if ($result > 0) {
             $this->db->commit();
             return 1;
         } else {
             $this->error = $ligne->error;
             $this->errors = $ligne->errors;
             $this->db->rollback();
             return -2;
         }
     }
 }