/**
  *	Update line
  *
  *	@param     	int			$rowid           	Id de la ligne de facture
  *	@param     	string		$desc            	Description de la ligne
  *	@param     	double		$pu              	Prix unitaire
  *	@param     	double		$qty             	Quantity
  *	@param     	double		$remise_percent  	Pourcentage de remise de la ligne
  *	@param     	double		$txtva          	Taux TVA
  *  @param     	double		$txlocaltax1	    Localtax1 tax
  *  @param     	double		$txlocaltax2   		Localtax2 tax
  *  @param     	double		$price_base_type 	Type of price base
  *	@param		int			$info_bits			Miscellaneous informations
  *	@param		int			$type				Type of line (0=product, 1=service)
  *  @param		int			$notrigger			Disable triggers
  *  @param      timestamp   $date_start     	Date start of service
  *  @param      timestamp   $date_end       	Date end of service
  *  @param		array		$array_options		Extrafields array
  * 	@param 		string		$fk_unit 			Code of the unit to use. Null to use the default one
  *	@return    	int         	    			< 0 if error, > 0 if ok
  */
 function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1 = 0, $txlocaltax2 = 0, $price_base_type = 'HT', $info_bits = 0, $type = 0, $notrigger = false, $date_start = '', $date_end = '', $array_options = 0, $fk_unit = null)
 {
     global $mysoc;
     dol_syslog(get_class($this) . "::updateline {$rowid}, {$desc}, {$pu}, {$qty}, {$remise_percent}, {$txtva}, {$price_base_type}, {$info_bits}, {$type}, {$fk_unit}");
     include_once DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php';
     if ($this->brouillon) {
         $this->db->begin();
         // Clean parameters
         if (empty($qty)) {
             $qty = 0;
         }
         if (empty($info_bits)) {
             $info_bits = 0;
         }
         if (empty($txtva)) {
             $txtva = 0;
         }
         if (empty($txlocaltax1)) {
             $txlocaltax1 = 0;
         }
         if (empty($txlocaltax2)) {
             $txlocaltax2 = 0;
         }
         if (empty($remise)) {
             $remise = 0;
         }
         if (empty($remise_percent)) {
             $remise_percent = 0;
         }
         $remise_percent = price2num($remise_percent);
         $qty = price2num($qty);
         if (!$qty) {
             $qty = 1;
         }
         $pu = price2num($pu);
         $txtva = price2num($txtva);
         $txlocaltax1 = price2num($txlocaltax1);
         $txlocaltax2 = price2num($txlocaltax2);
         // Check parameters
         if ($type < 0) {
             return -1;
         }
         // Calcul du total TTC et de la TVA pour la ligne a partir de
         // qty, pu, remise_percent et txtva
         // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker
         // la part ht, tva et ttc, et ce au niveau de la ligne qui a son propre taux tva.
         $localtaxes_type = getLocalTaxesFromRate($txtva, 0, $mysoc, $this->thirdparty);
         $txtva = preg_replace('/\\s*\\(.*\\)/', '', $txtva);
         // Remove code into vatrate.
         $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type);
         $total_ht = $tabprice[0];
         $total_tva = $tabprice[1];
         $total_ttc = $tabprice[2];
         $total_localtax1 = $tabprice[9];
         $total_localtax2 = $tabprice[10];
         $localtax1_type = $localtaxes_type[0];
         $localtax2_type = $localtaxes_type[2];
         $subprice = price2num($pu, 'MU');
         // Mise a jour ligne en base
         $sql = "UPDATE " . MAIN_DB_PREFIX . "commande_fournisseurdet SET";
         $sql .= " description='" . $this->db->escape($desc) . "'";
         $sql .= ",subprice='" . price2num($subprice) . "'";
         //$sql.= ",remise='".price2num($remise)."'";
         $sql .= ",remise_percent='" . price2num($remise_percent) . "'";
         $sql .= ",tva_tx='" . price2num($txtva) . "'";
         $sql .= ",localtax1_tx='" . price2num($txlocaltax1) . "'";
         $sql .= ",localtax2_tx='" . price2num($txlocaltax2) . "'";
         $sql .= ",localtax1_type='" . $localtax1_type . "'";
         $sql .= ",localtax2_type='" . $localtax2_type . "'";
         $sql .= ",qty='" . price2num($qty) . "'";
         $sql .= ",date_start=" . (!empty($date_start) ? "'" . $this->db->idate($date_start) . "'" : "null");
         $sql .= ",date_end=" . (!empty($date_end) ? "'" . $this->db->idate($date_end) . "'" : "null");
         $sql .= ",info_bits='" . $info_bits . "'";
         $sql .= ",total_ht='" . price2num($total_ht) . "'";
         $sql .= ",total_tva='" . price2num($total_tva) . "'";
         $sql .= ",total_localtax1='" . price2num($total_localtax1) . "'";
         $sql .= ",total_localtax2='" . price2num($total_localtax2) . "'";
         $sql .= ",total_ttc='" . price2num($total_ttc) . "'";
         $sql .= ",product_type=" . $type;
         $sql .= $fk_unit ? ",fk_unit='" . $this->db->escape($fk_unit) . "'" : ", fk_unit=null";
         $sql .= " WHERE rowid = " . $rowid;
         dol_syslog(get_class($this) . "::updateline", LOG_DEBUG);
         $result = $this->db->query($sql);
         if ($result > 0) {
             $this->rowid = $rowid;
             if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
                 $tmpline = new CommandeFournisseurLigne($this->db);
                 $tmpline->id = $this->rowid;
                 $tmpline->array_options = $array_options;
                 $result = $tmpline->insertExtraFields();
                 if ($result < 0) {
                     $error++;
                 }
             }
             if (!$error && !$notrigger) {
                 global $conf, $langs, $user;
                 // Call trigger
                 $result = $this->call_trigger('LINEORDER_SUPPLIER_UPDATE', $user);
                 if ($result < 0) {
                     $this->db->rollback();
                     return -1;
                 }
                 // End call triggers
             }
             // Mise a jour info denormalisees au niveau facture
             if (!$error) {
                 $this->update_price('', 'auto');
             }
             if (!$error) {
                 $this->db->commit();
                 return $result;
             } else {
                 $this->db->rollback();
                 return -1;
             }
         } else {
             $this->error = $this->db->lasterror();
             $this->db->rollback();
             return -1;
         }
     } else {
         $this->error = "Order status makes operation forbidden";
         dol_syslog(get_class($this) . "::updateline " . $this->error, LOG_ERR);
         return -2;
     }
 }