Exemple #1
0
 /**
  *    Ajout d'une ligne remise fixe dans la commande, en base
  *    @param     idremise			Id de la remise fixe
  *    @return    int          		>0 si ok, <0 si ko
  */
 function insert_discount($idremise)
 {
     global $langs;
     include_once DOL_DOCUMENT_ROOT . '/lib/price.lib.php';
     include_once DOL_DOCUMENT_ROOT . '/core/class/discount.class.php';
     $this->db->begin();
     $remise = new DiscountAbsolute($this->db);
     $result = $remise->fetch($idremise);
     if ($result > 0) {
         if ($remise->fk_facture) {
             $this->error = $langs->trans("ErrorDiscountAlreadyUsed");
             $this->db->rollback();
             return -5;
         }
         $line = new OrderLine($this->db);
         $line->fk_commande = $this->id;
         $line->fk_remise_except = $remise->id;
         $line->desc = $remise->description;
         // Description ligne
         $line->tva_tx = $remise->tva_tx;
         $line->subprice = -$remise->amount_ht;
         $line->price = -$remise->amount_ht;
         $line->fk_product = 0;
         // Id produit predefini
         $line->qty = 1;
         $line->remise = 0;
         $line->remise_percent = 0;
         $line->rang = -1;
         $line->info_bits = 2;
         $line->total_ht = -$remise->amount_ht;
         $line->total_tva = -$remise->amount_tva;
         $line->total_ttc = -$remise->amount_ttc;
         $result = $line->insert();
         if ($result > 0) {
             $result = $this->update_price(1);
             if ($result > 0) {
                 $this->db->commit();
                 return 1;
             } else {
                 $this->db->rollback();
                 return -1;
             }
         } else {
             $this->error = $line->error;
             $this->db->rollback();
             return -2;
         }
     } else {
         $this->db->rollback();
         return -2;
     }
 }
    $com->qty = $qty[$i - 1];
    $com->tva_tx = $prod->tva_tx;
    $com->fk_product = $id[$i - 1];
    $com->subprice = round($price[$i - 1] / $vatmult * 100) / 100;
    $com->label = $label[$i - 1];
    $com->rang = '1';
    $com->remise_percent = $dto[$i - 1];
    $com->remise = round($price[$i - 1] * $qty[$i - 1] * $dto[$i - 1]) / 100;
    $com->total_ttc = round(($qty[$i - 1] * $price[$i - 1] - $com->remise) * 100) / 100;
    $com->total_ht = round($com->total_ttc / $vatmult * 100) / 100;
    $com->fk_parent_line = '';
    $com->total_tva = $com->total_ttc - $com->total_ht;
    $com->pa_ht = '1';
    $com->price = $price[$i - 1];
    $com->desc = $notes[$i - 1];
    $result = $com->insert();
}
//UPDATE PRICE
$fieldtva = 'total_tva';
$fieldlocaltax1 = 'total_localtax1';
$fieldlocaltax2 = 'total_localtax2';
$sql = 'SELECT qty, total_ht, ' . $fieldtva . ' as total_tva, total_ttc, ' . $fieldlocaltax1 . ' as total_localtax1, ' . $fieldlocaltax2 . ' as total_localtax2,';
$sql .= ' tva_tx as vatrate, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type';
$sql .= ' FROM ' . MAIN_DB_PREFIX . 'commandedet';
$sql .= ' WHERE fk_commande = ' . $placeid;
$resql = $db->query($sql);
if ($resql) {
    $total_ht = 0;
    $total_tva = 0;
    $total_localtax1 = 0;
    $total_localtax2 = 0;