Fix regression after removing ->brouillon.
This commit is contained in:
parent
f4bf4b31d5
commit
65c4e92e87
1 changed files with 260 additions and 268 deletions
|
|
@ -869,154 +869,149 @@ class FactureRec extends CommonInvoice
|
|||
$txtva = preg_replace('/\s*\(.*\)/', '', $txtva); // Remove code into vatrate.
|
||||
}
|
||||
|
||||
if ($this->suspended == self::STATUS_NOTSUSPENDED) {
|
||||
// Clean parameters
|
||||
$remise_percent = price2num($remise_percent);
|
||||
if (empty($remise_percent)) {
|
||||
$remise_percent = 0;
|
||||
}
|
||||
$qty = price2num($qty);
|
||||
$pu_ht = price2num($pu_ht);
|
||||
$pu_ttc = price2num($pu_ttc);
|
||||
if (!preg_match('/\((.*)\)/', $txtva)) {
|
||||
$txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
|
||||
}
|
||||
$txlocaltax1 = price2num($txlocaltax1);
|
||||
$txlocaltax2 = price2num($txlocaltax2);
|
||||
if (empty($txtva)) {
|
||||
$txtva = 0;
|
||||
}
|
||||
if (empty($txlocaltax1)) {
|
||||
$txlocaltax1 = 0;
|
||||
}
|
||||
if (empty($txlocaltax2)) {
|
||||
$txlocaltax2 = 0;
|
||||
}
|
||||
if (empty($info_bits)) {
|
||||
$info_bits = 0;
|
||||
}
|
||||
|
||||
if ($price_base_type == 'HT') {
|
||||
$pu = $pu_ht;
|
||||
} else {
|
||||
$pu = $pu_ttc;
|
||||
}
|
||||
// Clean parameters
|
||||
$remise_percent = price2num($remise_percent);
|
||||
if (empty($remise_percent)) {
|
||||
$remise_percent = 0;
|
||||
}
|
||||
$qty = price2num($qty);
|
||||
$pu_ht = price2num($pu_ht);
|
||||
$pu_ttc = price2num($pu_ttc);
|
||||
if (!preg_match('/\((.*)\)/', $txtva)) {
|
||||
$txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
|
||||
}
|
||||
$txlocaltax1 = price2num($txlocaltax1);
|
||||
$txlocaltax2 = price2num($txlocaltax2);
|
||||
if (empty($txtva)) {
|
||||
$txtva = 0;
|
||||
}
|
||||
if (empty($txlocaltax1)) {
|
||||
$txlocaltax1 = 0;
|
||||
}
|
||||
if (empty($txlocaltax2)) {
|
||||
$txlocaltax2 = 0;
|
||||
}
|
||||
if (empty($info_bits)) {
|
||||
$info_bits = 0;
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
||||
$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
|
||||
$total_ht = $tabprice[0];
|
||||
$total_tva = $tabprice[1];
|
||||
$total_ttc = $tabprice[2];
|
||||
$total_localtax1 = $tabprice[9];
|
||||
$total_localtax2 = $tabprice[10];
|
||||
$pu_ht = $tabprice[3];
|
||||
|
||||
// MultiCurrency
|
||||
$multicurrency_total_ht = $tabprice[16];
|
||||
$multicurrency_total_tva = $tabprice[17];
|
||||
$multicurrency_total_ttc = $tabprice[18];
|
||||
$pu_ht_devise = $tabprice[19];
|
||||
|
||||
$product_type = $type;
|
||||
if ($fk_product) {
|
||||
$product = new Product($this->db);
|
||||
$result = $product->fetch($fk_product);
|
||||
$product_type = $product->type;
|
||||
}
|
||||
|
||||
// Rank to use
|
||||
$ranktouse = $rang;
|
||||
if ($ranktouse == -1) {
|
||||
$rangmax = $this->line_max(0);
|
||||
$ranktouse = $rangmax + 1;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facturedet_rec (";
|
||||
$sql .= "fk_facture";
|
||||
$sql .= ", label";
|
||||
$sql .= ", description";
|
||||
$sql .= ", price";
|
||||
$sql .= ", qty";
|
||||
$sql .= ", tva_tx";
|
||||
$sql .= ", vat_src_code";
|
||||
$sql .= ", localtax1_tx";
|
||||
$sql .= ", localtax1_type";
|
||||
$sql .= ", localtax2_tx";
|
||||
$sql .= ", localtax2_type";
|
||||
$sql .= ", fk_product";
|
||||
$sql .= ", product_type";
|
||||
$sql .= ", remise_percent";
|
||||
$sql .= ", subprice";
|
||||
$sql .= ", remise";
|
||||
$sql .= ", total_ht";
|
||||
$sql .= ", total_tva";
|
||||
$sql .= ", total_localtax1";
|
||||
$sql .= ", total_localtax2";
|
||||
$sql .= ", total_ttc";
|
||||
$sql .= ", date_start_fill";
|
||||
$sql .= ", date_end_fill";
|
||||
$sql .= ", fk_product_fournisseur_price";
|
||||
$sql .= ", buy_price_ht";
|
||||
$sql .= ", info_bits";
|
||||
$sql .= ", rang";
|
||||
$sql .= ", special_code";
|
||||
$sql .= ", fk_unit";
|
||||
$sql .= ', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
|
||||
$sql .= ") VALUES (";
|
||||
$sql .= " ".((int) $facid);
|
||||
$sql .= ", ".(!empty($label) ? "'".$this->db->escape($label)."'" : "null");
|
||||
$sql .= ", '".$this->db->escape($desc)."'";
|
||||
$sql .= ", ".price2num($pu_ht);
|
||||
$sql .= ", ".price2num($qty);
|
||||
$sql .= ", ".price2num($txtva);
|
||||
$sql .= ", '".$this->db->escape($vat_src_code)."'";
|
||||
$sql .= ", ".price2num($txlocaltax1);
|
||||
$sql .= ", '".$this->db->escape(isset($localtaxes_type[0]) ? $localtaxes_type[0] : '')."'";
|
||||
$sql .= ", ".price2num($txlocaltax2);
|
||||
$sql .= ", '".$this->db->escape(isset($localtaxes_type[2]) ? $localtaxes_type[2] : '')."'";
|
||||
$sql .= ", ".(!empty($fk_product) ? "'".$this->db->escape($fk_product)."'" : "null");
|
||||
$sql .= ", ".((int) $product_type);
|
||||
$sql .= ", ".price2num($remise_percent);
|
||||
$sql .= ", ".price2num($pu_ht);
|
||||
$sql .= ", null";
|
||||
$sql .= ", ".price2num($total_ht);
|
||||
$sql .= ", ".price2num($total_tva);
|
||||
$sql .= ", ".price2num($total_localtax1);
|
||||
$sql .= ", ".price2num($total_localtax2);
|
||||
$sql .= ", ".price2num($total_ttc);
|
||||
$sql .= ", ".(int) $date_start_fill;
|
||||
$sql .= ", ".(int) $date_end_fill;
|
||||
$sql .= ", ".($fk_fournprice > 0 ? $fk_fournprice : 'null');
|
||||
$sql .= ", ".($pa_ht ? price2num($pa_ht) : 0);
|
||||
$sql .= ", ".((int) $info_bits);
|
||||
$sql .= ", ".((int) $ranktouse);
|
||||
$sql .= ", ".((int) $special_code);
|
||||
$sql .= ", ".($fk_unit ? ((int) $fk_unit) : "null");
|
||||
$sql .= ", ".(int) $this->fk_multicurrency;
|
||||
$sql .= ", '".$this->db->escape($this->multicurrency_code)."'";
|
||||
$sql .= ", ".price2num($pu_ht_devise, 'CU');
|
||||
$sql .= ", ".price2num($multicurrency_total_ht, 'CT');
|
||||
$sql .= ", ".price2num($multicurrency_total_tva, 'CT');
|
||||
$sql .= ", ".price2num($multicurrency_total_ttc, 'CT');
|
||||
$sql .= ")";
|
||||
|
||||
dol_syslog(get_class($this)."::addline", LOG_DEBUG);
|
||||
if ($this->db->query($sql)) {
|
||||
$lineId = $this->db->last_insert_id(MAIN_DB_PREFIX."facturedet_rec");
|
||||
$this->id = $facid;
|
||||
$this->update_price(1);
|
||||
return $lineId;
|
||||
} else {
|
||||
$this->error = $this->db->lasterror();
|
||||
return -1;
|
||||
}
|
||||
if ($price_base_type == 'HT') {
|
||||
$pu = $pu_ht;
|
||||
} else {
|
||||
$this->error = 'Recurring Invoice is suspended. adding lines not allowed.';
|
||||
$pu = $pu_ttc;
|
||||
}
|
||||
|
||||
// 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.
|
||||
|
||||
$tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
|
||||
$total_ht = $tabprice[0];
|
||||
$total_tva = $tabprice[1];
|
||||
$total_ttc = $tabprice[2];
|
||||
$total_localtax1 = $tabprice[9];
|
||||
$total_localtax2 = $tabprice[10];
|
||||
$pu_ht = $tabprice[3];
|
||||
|
||||
// MultiCurrency
|
||||
$multicurrency_total_ht = $tabprice[16];
|
||||
$multicurrency_total_tva = $tabprice[17];
|
||||
$multicurrency_total_ttc = $tabprice[18];
|
||||
$pu_ht_devise = $tabprice[19];
|
||||
|
||||
$product_type = $type;
|
||||
if ($fk_product) {
|
||||
$product = new Product($this->db);
|
||||
$result = $product->fetch($fk_product);
|
||||
$product_type = $product->type;
|
||||
}
|
||||
|
||||
// Rank to use
|
||||
$ranktouse = $rang;
|
||||
if ($ranktouse == -1) {
|
||||
$rangmax = $this->line_max(0);
|
||||
$ranktouse = $rangmax + 1;
|
||||
}
|
||||
|
||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."facturedet_rec (";
|
||||
$sql .= "fk_facture";
|
||||
$sql .= ", label";
|
||||
$sql .= ", description";
|
||||
$sql .= ", price";
|
||||
$sql .= ", qty";
|
||||
$sql .= ", tva_tx";
|
||||
$sql .= ", vat_src_code";
|
||||
$sql .= ", localtax1_tx";
|
||||
$sql .= ", localtax1_type";
|
||||
$sql .= ", localtax2_tx";
|
||||
$sql .= ", localtax2_type";
|
||||
$sql .= ", fk_product";
|
||||
$sql .= ", product_type";
|
||||
$sql .= ", remise_percent";
|
||||
$sql .= ", subprice";
|
||||
$sql .= ", remise";
|
||||
$sql .= ", total_ht";
|
||||
$sql .= ", total_tva";
|
||||
$sql .= ", total_localtax1";
|
||||
$sql .= ", total_localtax2";
|
||||
$sql .= ", total_ttc";
|
||||
$sql .= ", date_start_fill";
|
||||
$sql .= ", date_end_fill";
|
||||
$sql .= ", fk_product_fournisseur_price";
|
||||
$sql .= ", buy_price_ht";
|
||||
$sql .= ", info_bits";
|
||||
$sql .= ", rang";
|
||||
$sql .= ", special_code";
|
||||
$sql .= ", fk_unit";
|
||||
$sql .= ', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc';
|
||||
$sql .= ") VALUES (";
|
||||
$sql .= " ".((int) $facid);
|
||||
$sql .= ", ".(!empty($label) ? "'".$this->db->escape($label)."'" : "null");
|
||||
$sql .= ", '".$this->db->escape($desc)."'";
|
||||
$sql .= ", ".price2num($pu_ht);
|
||||
$sql .= ", ".price2num($qty);
|
||||
$sql .= ", ".price2num($txtva);
|
||||
$sql .= ", '".$this->db->escape($vat_src_code)."'";
|
||||
$sql .= ", ".price2num($txlocaltax1);
|
||||
$sql .= ", '".$this->db->escape(isset($localtaxes_type[0]) ? $localtaxes_type[0] : '')."'";
|
||||
$sql .= ", ".price2num($txlocaltax2);
|
||||
$sql .= ", '".$this->db->escape(isset($localtaxes_type[2]) ? $localtaxes_type[2] : '')."'";
|
||||
$sql .= ", ".(!empty($fk_product) ? "'".$this->db->escape($fk_product)."'" : "null");
|
||||
$sql .= ", ".((int) $product_type);
|
||||
$sql .= ", ".price2num($remise_percent);
|
||||
$sql .= ", ".price2num($pu_ht);
|
||||
$sql .= ", null";
|
||||
$sql .= ", ".price2num($total_ht);
|
||||
$sql .= ", ".price2num($total_tva);
|
||||
$sql .= ", ".price2num($total_localtax1);
|
||||
$sql .= ", ".price2num($total_localtax2);
|
||||
$sql .= ", ".price2num($total_ttc);
|
||||
$sql .= ", ".(int) $date_start_fill;
|
||||
$sql .= ", ".(int) $date_end_fill;
|
||||
$sql .= ", ".($fk_fournprice > 0 ? $fk_fournprice : 'null');
|
||||
$sql .= ", ".($pa_ht ? price2num($pa_ht) : 0);
|
||||
$sql .= ", ".((int) $info_bits);
|
||||
$sql .= ", ".((int) $ranktouse);
|
||||
$sql .= ", ".((int) $special_code);
|
||||
$sql .= ", ".($fk_unit ? ((int) $fk_unit) : "null");
|
||||
$sql .= ", ".(int) $this->fk_multicurrency;
|
||||
$sql .= ", '".$this->db->escape($this->multicurrency_code)."'";
|
||||
$sql .= ", ".price2num($pu_ht_devise, 'CU');
|
||||
$sql .= ", ".price2num($multicurrency_total_ht, 'CT');
|
||||
$sql .= ", ".price2num($multicurrency_total_tva, 'CT');
|
||||
$sql .= ", ".price2num($multicurrency_total_ttc, 'CT');
|
||||
$sql .= ")";
|
||||
|
||||
dol_syslog(get_class($this)."::addline", LOG_DEBUG);
|
||||
if ($this->db->query($sql)) {
|
||||
$lineId = $this->db->last_insert_id(MAIN_DB_PREFIX."facturedet_rec");
|
||||
$this->id = $facid;
|
||||
$this->update_price(1);
|
||||
return $lineId;
|
||||
} else {
|
||||
$this->error = $this->db->lasterror();
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
|
@ -1069,131 +1064,128 @@ class FactureRec extends CommonInvoice
|
|||
return -1;
|
||||
}
|
||||
|
||||
if ($this->suspended == self::STATUS_SUSPENDED) {
|
||||
// Clean parameters
|
||||
$remise_percent = price2num($remise_percent);
|
||||
$qty = price2num($qty);
|
||||
if (empty($info_bits)) {
|
||||
$info_bits = 0;
|
||||
}
|
||||
$pu_ht = price2num($pu_ht);
|
||||
$pu_ttc = price2num($pu_ttc);
|
||||
$pu_ht_devise = price2num($pu_ht_devise);
|
||||
if (!preg_match('/\((.*)\)/', $txtva)) {
|
||||
$txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
|
||||
}
|
||||
$txlocaltax1 = price2num($txlocaltax1);
|
||||
$txlocaltax2 = price2num($txlocaltax2);
|
||||
if (empty($txlocaltax1)) {
|
||||
$txlocaltax1 = 0;
|
||||
}
|
||||
if (empty($txlocaltax2)) {
|
||||
$txlocaltax2 = 0;
|
||||
}
|
||||
|
||||
if (empty($this->multicurrency_subprice)) {
|
||||
$this->multicurrency_subprice = 0;
|
||||
}
|
||||
if (empty($this->multicurrency_total_ht)) {
|
||||
$this->multicurrency_total_ht = 0;
|
||||
}
|
||||
if (empty($this->multicurrency_total_tva)) {
|
||||
$this->multicurrency_total_tva = 0;
|
||||
}
|
||||
if (empty($this->multicurrency_total_ttc)) {
|
||||
$this->multicurrency_total_ttc = 0;
|
||||
}
|
||||
|
||||
if ($price_base_type == 'HT') {
|
||||
$pu = $pu_ht;
|
||||
} else {
|
||||
$pu = $pu_ttc;
|
||||
}
|
||||
|
||||
// Calculate total with, without tax and tax from qty, pu, remise_percent and 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, $this->thirdparty, $mysoc);
|
||||
|
||||
// Clean vat code
|
||||
$vat_src_code = '';
|
||||
$reg = array();
|
||||
if (preg_match('/\((.*)\)/', $txtva, $reg)) {
|
||||
$vat_src_code = $reg[1];
|
||||
$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, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
|
||||
|
||||
$total_ht = $tabprice[0];
|
||||
$total_tva = $tabprice[1];
|
||||
$total_ttc = $tabprice[2];
|
||||
$total_localtax1 = $tabprice[9];
|
||||
$total_localtax2 = $tabprice[10];
|
||||
$pu_ht = $tabprice[3];
|
||||
$pu_tva = $tabprice[4];
|
||||
$pu_ttc = $tabprice[5];
|
||||
|
||||
// MultiCurrency
|
||||
$multicurrency_total_ht = $tabprice[16];
|
||||
$multicurrency_total_tva = $tabprice[17];
|
||||
$multicurrency_total_ttc = $tabprice[18];
|
||||
$pu_ht_devise = $tabprice[19];
|
||||
|
||||
$product_type = $type;
|
||||
if ($fk_product) {
|
||||
$product = new Product($this->db);
|
||||
$result = $product->fetch($fk_product);
|
||||
$product_type = $product->type;
|
||||
}
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet_rec SET ";
|
||||
$sql .= "fk_facture = ".((int) $facid);
|
||||
$sql .= ", label=".(!empty($label) ? "'".$this->db->escape($label)."'" : "null");
|
||||
$sql .= ", description='".$this->db->escape($desc)."'";
|
||||
$sql .= ", price=".price2num($pu_ht);
|
||||
$sql .= ", qty=".price2num($qty);
|
||||
$sql .= ", tva_tx=".price2num($txtva);
|
||||
$sql .= ", vat_src_code='".$this->db->escape($vat_src_code)."'";
|
||||
$sql .= ", localtax1_tx=".((float) $txlocaltax1);
|
||||
$sql .= ", localtax1_type='".$this->db->escape($localtaxes_type[0])."'";
|
||||
$sql .= ", localtax2_tx=".((float) $txlocaltax2);
|
||||
$sql .= ", localtax2_type='".$this->db->escape($localtaxes_type[2])."'";
|
||||
$sql .= ", fk_product=".(!empty($fk_product) ? "'".$this->db->escape($fk_product)."'" : "null");
|
||||
$sql .= ", product_type=".((int) $product_type);
|
||||
$sql .= ", remise_percent='".price2num($remise_percent)."'";
|
||||
$sql .= ", subprice='".price2num($pu_ht)."'";
|
||||
$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 .= ", date_start_fill=".((int) $date_start_fill);
|
||||
$sql .= ", date_end_fill=".((int) $date_end_fill);
|
||||
$sql .= ", fk_product_fournisseur_price=".($fk_fournprice > 0 ? $fk_fournprice : 'null');
|
||||
$sql .= ", buy_price_ht=".($pa_ht ? price2num($pa_ht) : 0);
|
||||
$sql .= ", info_bits=".((int) $info_bits);
|
||||
$sql .= ", rang=".((int) $rang);
|
||||
$sql .= ", special_code=".((int) $special_code);
|
||||
$sql .= ", fk_unit=".($fk_unit ? "'".$this->db->escape($fk_unit)."'" : "null");
|
||||
$sql .= ', multicurrency_subprice = '.price2num($pu_ht_devise);
|
||||
$sql .= ', multicurrency_total_ht = '.price2num($multicurrency_total_ht);
|
||||
$sql .= ', multicurrency_total_tva = '.price2num($multicurrency_total_tva);
|
||||
$sql .= ', multicurrency_total_ttc = '.price2num($multicurrency_total_ttc);
|
||||
$sql .= " WHERE rowid = ".((int) $rowid);
|
||||
|
||||
dol_syslog(get_class($this)."::updateline", LOG_DEBUG);
|
||||
if ($this->db->query($sql)) {
|
||||
$this->id = $facid;
|
||||
$this->update_price(1);
|
||||
return 1;
|
||||
} else {
|
||||
$this->error = $this->db->lasterror();
|
||||
return -1;
|
||||
}
|
||||
// Clean parameters
|
||||
$remise_percent = price2num($remise_percent);
|
||||
$qty = price2num($qty);
|
||||
if (empty($info_bits)) {
|
||||
$info_bits = 0;
|
||||
}
|
||||
$pu_ht = price2num($pu_ht);
|
||||
$pu_ttc = price2num($pu_ttc);
|
||||
$pu_ht_devise = price2num($pu_ht_devise);
|
||||
if (!preg_match('/\((.*)\)/', $txtva)) {
|
||||
$txtva = price2num($txtva); // $txtva can have format '5.0(XXX)' or '5'
|
||||
}
|
||||
$txlocaltax1 = price2num($txlocaltax1);
|
||||
$txlocaltax2 = price2num($txlocaltax2);
|
||||
if (empty($txlocaltax1)) {
|
||||
$txlocaltax1 = 0;
|
||||
}
|
||||
if (empty($txlocaltax2)) {
|
||||
$txlocaltax2 = 0;
|
||||
}
|
||||
|
||||
if (empty($this->multicurrency_subprice)) {
|
||||
$this->multicurrency_subprice = 0;
|
||||
}
|
||||
if (empty($this->multicurrency_total_ht)) {
|
||||
$this->multicurrency_total_ht = 0;
|
||||
}
|
||||
if (empty($this->multicurrency_total_tva)) {
|
||||
$this->multicurrency_total_tva = 0;
|
||||
}
|
||||
if (empty($this->multicurrency_total_ttc)) {
|
||||
$this->multicurrency_total_ttc = 0;
|
||||
}
|
||||
|
||||
if ($price_base_type == 'HT') {
|
||||
$pu = $pu_ht;
|
||||
} else {
|
||||
$pu = $pu_ttc;
|
||||
}
|
||||
|
||||
// Calculate total with, without tax and tax from qty, pu, remise_percent and 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, $this->thirdparty, $mysoc);
|
||||
|
||||
// Clean vat code
|
||||
$vat_src_code = '';
|
||||
$reg = array();
|
||||
if (preg_match('/\((.*)\)/', $txtva, $reg)) {
|
||||
$vat_src_code = $reg[1];
|
||||
$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, $mysoc, $localtaxes_type, 100, $this->multicurrency_tx, $pu_ht_devise);
|
||||
|
||||
$total_ht = $tabprice[0];
|
||||
$total_tva = $tabprice[1];
|
||||
$total_ttc = $tabprice[2];
|
||||
$total_localtax1 = $tabprice[9];
|
||||
$total_localtax2 = $tabprice[10];
|
||||
$pu_ht = $tabprice[3];
|
||||
$pu_tva = $tabprice[4];
|
||||
$pu_ttc = $tabprice[5];
|
||||
|
||||
// MultiCurrency
|
||||
$multicurrency_total_ht = $tabprice[16];
|
||||
$multicurrency_total_tva = $tabprice[17];
|
||||
$multicurrency_total_ttc = $tabprice[18];
|
||||
$pu_ht_devise = $tabprice[19];
|
||||
|
||||
$product_type = $type;
|
||||
if ($fk_product) {
|
||||
$product = new Product($this->db);
|
||||
$result = $product->fetch($fk_product);
|
||||
$product_type = $product->type;
|
||||
}
|
||||
|
||||
$sql = "UPDATE ".MAIN_DB_PREFIX."facturedet_rec SET ";
|
||||
$sql .= "fk_facture = ".((int) $facid);
|
||||
$sql .= ", label=".(!empty($label) ? "'".$this->db->escape($label)."'" : "null");
|
||||
$sql .= ", description='".$this->db->escape($desc)."'";
|
||||
$sql .= ", price=".price2num($pu_ht);
|
||||
$sql .= ", qty=".price2num($qty);
|
||||
$sql .= ", tva_tx=".price2num($txtva);
|
||||
$sql .= ", vat_src_code='".$this->db->escape($vat_src_code)."'";
|
||||
$sql .= ", localtax1_tx=".((float) $txlocaltax1);
|
||||
$sql .= ", localtax1_type='".$this->db->escape($localtaxes_type[0])."'";
|
||||
$sql .= ", localtax2_tx=".((float) $txlocaltax2);
|
||||
$sql .= ", localtax2_type='".$this->db->escape($localtaxes_type[2])."'";
|
||||
$sql .= ", fk_product=".(!empty($fk_product) ? "'".$this->db->escape($fk_product)."'" : "null");
|
||||
$sql .= ", product_type=".((int) $product_type);
|
||||
$sql .= ", remise_percent='".price2num($remise_percent)."'";
|
||||
$sql .= ", subprice='".price2num($pu_ht)."'";
|
||||
$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 .= ", date_start_fill=".((int) $date_start_fill);
|
||||
$sql .= ", date_end_fill=".((int) $date_end_fill);
|
||||
$sql .= ", fk_product_fournisseur_price=".($fk_fournprice > 0 ? $fk_fournprice : 'null');
|
||||
$sql .= ", buy_price_ht=".($pa_ht ? price2num($pa_ht) : 0);
|
||||
$sql .= ", info_bits=".((int) $info_bits);
|
||||
$sql .= ", rang=".((int) $rang);
|
||||
$sql .= ", special_code=".((int) $special_code);
|
||||
$sql .= ", fk_unit=".($fk_unit ? "'".$this->db->escape($fk_unit)."'" : "null");
|
||||
$sql .= ', multicurrency_subprice = '.price2num($pu_ht_devise);
|
||||
$sql .= ', multicurrency_total_ht = '.price2num($multicurrency_total_ht);
|
||||
$sql .= ', multicurrency_total_tva = '.price2num($multicurrency_total_tva);
|
||||
$sql .= ', multicurrency_total_ttc = '.price2num($multicurrency_total_ttc);
|
||||
$sql .= " WHERE rowid = ".((int) $rowid);
|
||||
|
||||
dol_syslog(get_class($this)."::updateline", LOG_DEBUG);
|
||||
if ($this->db->query($sql)) {
|
||||
$this->id = $facid;
|
||||
$this->update_price(1);
|
||||
return 1;
|
||||
} else {
|
||||
$this->error = $this->db->lasterror();
|
||||
return -1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue