Skip to content
Snippets Groups Projects
Commit ab01c409 authored by Laurent Destailleur's avatar Laurent Destailleur
Browse files

Merge pull request #3143 from marcosgdf/more-oop

Created function SupplierInvoiceLine::fetch and SupplierInvoiceLine::delete
parents 42b4eaae 9415bdd8
No related branches found
No related tags found
No related merge requests found
...@@ -504,39 +504,41 @@ class FactureFournisseur extends CommonInvoice ...@@ -504,39 +504,41 @@ class FactureFournisseur extends CommonInvoice
{ {
$obj = $this->db->fetch_object($resql_rows); $obj = $this->db->fetch_object($resql_rows);
$this->lines[$i] = new SupplierInvoiceLine($this->db); $line = new SupplierInvoiceLine($this->db);
$this->lines[$i]->id = $obj->rowid; $line->id = $obj->rowid;
$this->lines[$i]->rowid = $obj->rowid; $line->rowid = $obj->rowid;
$this->lines[$i]->description = $obj->description; $line->description = $obj->description;
$this->lines[$i]->product_ref = $obj->product_ref; // Internal reference $line->product_ref = $obj->product_ref;
$this->lines[$i]->ref = $obj->product_ref; // deprecated. $line->ref = $obj->product_ref;
$this->lines[$i]->ref_supplier = $obj->ref_supplier; // Reference product supplier TODO Rename field ref to ref_supplier into table llx_facture_fourn_det and llx_commande_fournisseurdet and update fields it into updateline $line->ref_supplier = $obj->ref_supplier;
$this->lines[$i]->libelle = $obj->label; // Deprecated $line->libelle = $obj->label;
$this->lines[$i]->label = $obj->label; // This field may contains label of product (when invoice create from order) $line->label = $obj->label;
$this->lines[$i]->product_desc = $obj->product_desc; // Description du produit $line->product_desc = $obj->product_desc;
$this->lines[$i]->subprice = $obj->pu_ht; $line->subprice = $obj->pu_ht;
$this->lines[$i]->pu_ht = $obj->pu_ht; $line->pu_ht = $obj->pu_ht;
$this->lines[$i]->pu_ttc = $obj->pu_ttc; $line->pu_ttc = $obj->pu_ttc;
$this->lines[$i]->tva_tx = $obj->tva_tx; $line->tva_tx = $obj->tva_tx;
$this->lines[$i]->localtax1_tx = $obj->localtax1_tx; $line->localtax1_tx = $obj->localtax1_tx;
$this->lines[$i]->localtax2_tx = $obj->localtax2_tx; $line->localtax2_tx = $obj->localtax2_tx;
$this->lines[$i]->qty = $obj->qty; $line->qty = $obj->qty;
$this->lines[$i]->remise_percent = $obj->remise_percent; $line->remise_percent = $obj->remise_percent;
$this->lines[$i]->tva = $obj->total_tva; $line->tva = $obj->total_tva;
$this->lines[$i]->total_ht = $obj->total_ht; $line->total_ht = $obj->total_ht;
$this->lines[$i]->total_tva = $obj->total_tva; $line->total_tva = $obj->total_tva;
$this->lines[$i]->total_localtax1 = $obj->total_localtax1; $line->total_localtax1 = $obj->total_localtax1;
$this->lines[$i]->total_localtax2 = $obj->total_localtax2; $line->total_localtax2 = $obj->total_localtax2;
$this->lines[$i]->total_ttc = $obj->total_ttc; $line->total_ttc = $obj->total_ttc;
$this->lines[$i]->fk_product = $obj->fk_product; $line->fk_product = $obj->fk_product;
$this->lines[$i]->product_type = $obj->product_type; $line->product_type = $obj->product_type;
$this->lines[$i]->product_label = $obj->label; $line->product_label = $obj->label;
$this->lines[$i]->info_bits = $obj->info_bits; $line->info_bits = $obj->info_bits;
$this->lines[$i]->fk_parent_line = $obj->fk_parent_line; $line->fk_parent_line = $obj->fk_parent_line;
$this->lines[$i]->special_code = $obj->special_code; $line->special_code = $obj->special_code;
$this->lines[$i]->rang = $obj->rang; $line->rang = $obj->rang;
$this->lines[$i]->fk_unit = $obj->fk_unit; $line->fk_unit = $obj->fk_unit;
$this->lines[$i] = $line;
$i++; $i++;
} }
...@@ -1368,53 +1370,25 @@ class FactureFournisseur extends CommonInvoice ...@@ -1368,53 +1370,25 @@ class FactureFournisseur extends CommonInvoice
*/ */
function deleteline($rowid, $notrigger=0) function deleteline($rowid, $notrigger=0)
{ {
global $user, $langs, $conf; if (!$rowid) {
$rowid = $this->id;
}
if (! $rowid) $rowid=$this->id; $line = new SupplierInvoiceLine($this->db);
dol_syslog(get_class($this)."::delete rowid=".$rowid, LOG_DEBUG); if ($line->fetch($rowid) < 1) {
return -1;
}
$error=0; $res = $line->delete($notrigger);
$this->db->begin();
if (! $error && ! $notrigger) if ($res < 1) {
{ $this->errors[] = $line->error;
// Call trigger } else {
$result=$this->call_trigger('LINEBILL_SUPPLIER_DELETE',$user); $res = $this->update_price();
if ($result < 0) $error++; }
// End call triggers
}
if (! $error) return $res;
{
// Supprime ligne
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn_det ';
$sql.= ' WHERE rowid = '.$rowid;
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql = $this->db->query($sql);
if (! $resql)
{
$error++;
$this->error=$this->db->lasterror();
}
}
if (! $error)
{
// Mise a jour prix facture
$result=$this->update_price();
}
if (! $error)
{
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
return -1;
}
} }
...@@ -1905,13 +1879,26 @@ class SupplierInvoiceLine extends CommonObjectLine ...@@ -1905,13 +1879,26 @@ class SupplierInvoiceLine extends CommonObjectLine
* @see product_ref * @see product_ref
*/ */
public $ref; public $ref;
/**
* Internal ref
* @var string
*/
public $product_ref; public $product_ref;
/**
* Reference product supplier
* TODO Rename field ref to ref_supplier into table llx_facture_fourn_det and llx_commande_fournisseurdet and update fields it into updateline
* @var string
*/
public $ref_supplier; public $ref_supplier;
/** /**
* @deprecated * @deprecated
* @see label * @see label
*/ */
public $libelle; public $libelle;
/**
* Product description
* @var string
*/
public $product_desc; public $product_desc;
/** /**
...@@ -1946,6 +1933,7 @@ class SupplierInvoiceLine extends CommonObjectLine ...@@ -1946,6 +1933,7 @@ class SupplierInvoiceLine extends CommonObjectLine
/** /**
* Product label * Product label
* This field may contains label of product (when invoice create from order)
* @var string * @var string
*/ */
var $label; var $label;
...@@ -1968,6 +1956,24 @@ class SupplierInvoiceLine extends CommonObjectLine ...@@ -1968,6 +1956,24 @@ class SupplierInvoiceLine extends CommonObjectLine
*/ */
public $fk_prev_id; public $fk_prev_id;
public $tva_tx;
public $localtax1_tx;
public $localtax2_tx;
public $qty;
public $remise_percent;
public $total_ht;
public $total_ttc;
public $total_localtax1;
public $total_localtax2;
public $fk_product;
public $product_type;
public $product_label;
public $info_bits;
public $fk_parent_line;
public $special_code;
public $rang;
/** /**
* Constructor * Constructor
* *
...@@ -1978,6 +1984,116 @@ class SupplierInvoiceLine extends CommonObjectLine ...@@ -1978,6 +1984,116 @@ class SupplierInvoiceLine extends CommonObjectLine
$this->db= $db; $this->db= $db;
} }
/**
* Retrieves a supplier invoice line
*
* @param int $rowid Line id
* @return int <0 KO; 0 NOT FOUND; 1 OK
*/
public function fetch($rowid)
{
$sql = 'SELECT f.rowid, f.ref as ref_supplier, f.description, f.pu_ht, f.pu_ttc, f.qty, f.remise_percent, f.tva_tx';
$sql.= ', f.localtax1_tx, f.localtax2_tx, f.total_localtax1, f.total_localtax2 ';
$sql.= ', f.total_ht, f.tva as total_tva, f.total_ttc, f.fk_product, f.product_type, f.info_bits, f.rang, f.special_code, f.fk_parent_line, f.fk_unit';
$sql.= ', p.rowid as product_id, p.ref as product_ref, p.label as label, p.description as product_desc';
$sql.= ' FROM '.MAIN_DB_PREFIX.'facture_fourn_det as f';
$sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON f.fk_product = p.rowid';
$sql.= ' WHERE rowid = '.$rowid;
$sql.= ' ORDER BY f.rang, f.rowid';
$query = $this->db->query($sql);
if (!$query) {
$this->errors[] = $this->db->error();
return -1;
}
if (!$this->db->num_rows($query)) {
return 0;
}
$obj = $this->db->fetch_object($query);
$this->id = $obj->rowid;
$this->rowid = $obj->rowid;
$this->description = $obj->description;
$this->product_ref = $obj->product_ref;
$this->ref = $obj->product_ref;
$this->ref_supplier = $obj->ref_supplier;
$this->libelle = $obj->label;
$this->label = $obj->label;
$this->product_desc = $obj->product_desc;
$this->subprice = $obj->pu_ht;
$this->pu_ht = $obj->pu_ht;
$this->pu_ttc = $obj->pu_ttc;
$this->tva_tx = $obj->tva_tx;
$this->localtax1_tx = $obj->localtax1_tx;
$this->localtax2_tx = $obj->localtax2_tx;
$this->qty = $obj->qty;
$this->remise_percent = $obj->remise_percent;
$this->tva = $obj->total_tva;
$this->total_ht = $obj->total_ht;
$this->total_tva = $obj->total_tva;
$this->total_localtax1 = $obj->total_localtax1;
$this->total_localtax2 = $obj->total_localtax2;
$this->total_ttc = $obj->total_ttc;
$this->fk_product = $obj->fk_product;
$this->product_type = $obj->product_type;
$this->product_label = $obj->label;
$this->info_bits = $obj->info_bits;
$this->fk_parent_line = $obj->fk_parent_line;
$this->special_code = $obj->special_code;
$this->rang = $obj->rang;
$this->fk_unit = $obj->fk_unit;
return 1;
}
/**
* Deletes a line
*
* @param bool|int $notrigger
* @return int -1 KO; 1 OK
*/
public function delete($notrigger = 0)
{
global $user;
dol_syslog(get_class($this)."::deleteline rowid=".$this->id, LOG_DEBUG);
$error = 0;
$this->db->begin();
if (!$notrigger) {
if ($this->call_trigger('LINEBILL_SUPPLIER_DELETE',$user) < 0) {
$error++;
}
}
if (!$error) {
// Supprime ligne
$sql = 'DELETE FROM '.MAIN_DB_PREFIX.'facture_fourn_det ';
$sql .= ' WHERE rowid = '.$this->id;
dol_syslog(get_class($this)."::delete", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql) {
$error++;
$this->error = $this->db->lasterror();
}
}
if (! $error)
{
$this->db->commit();
return 1;
}
else
{
$this->db->rollback();
return -1;
}
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment