Esempio n. 1
0
 /**
  *	Load invoice line from database
  *
  *	@param	int		$rowid      id of invoice line to get
  *	@return	int					<0 if KO, >0 if OK
  */
 function fetch($rowid)
 {
     $sql = 'SELECT fd.rowid, fd.fk_facture, fd.fk_parent_line, fd.fk_product, fd.product_type, fd.label as custom_label, fd.description, fd.price, fd.qty, fd.tva_tx,';
     $sql .= ' fd.localtax1_tx, fd. localtax2_tx, fd.remise, fd.remise_percent, fd.fk_remise_except, fd.subprice,';
     $sql .= ' fd.date_start as date_start, fd.date_end as date_end, fd.fk_product_fournisseur_price as fk_fournprice, fd.buy_price_ht as pa_ht,';
     $sql .= ' fd.info_bits, fd.special_code, fd.total_ht, fd.total_tva, fd.total_ttc, fd.total_localtax1, fd.total_localtax2, fd.rang,';
     $sql .= ' fd.fk_code_ventilation,';
     $sql .= ' fd.fk_unit,';
     $sql .= ' fd.situation_percent, fd.fk_prev_id,';
     $sql .= ' p.ref as product_ref, p.label as product_libelle, p.description as product_desc';
     $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facturedet as fd';
     $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product as p ON fd.fk_product = p.rowid';
     $sql .= ' WHERE fd.rowid = ' . $rowid;
     $result = $this->db->query($sql);
     if ($result) {
         $objp = $this->db->fetch_object($result);
         $this->rowid = $objp->rowid;
         $this->fk_facture = $objp->fk_facture;
         $this->fk_parent_line = $objp->fk_parent_line;
         $this->label = $objp->custom_label;
         $this->desc = $objp->description;
         $this->qty = $objp->qty;
         $this->subprice = $objp->subprice;
         $this->tva_tx = $objp->tva_tx;
         $this->localtax1_tx = $objp->localtax1_tx;
         $this->localtax2_tx = $objp->localtax2_tx;
         $this->remise_percent = $objp->remise_percent;
         $this->fk_remise_except = $objp->fk_remise_except;
         $this->fk_product = $objp->fk_product;
         $this->product_type = $objp->product_type;
         $this->date_start = $this->db->jdate($objp->date_start);
         $this->date_end = $this->db->jdate($objp->date_end);
         $this->info_bits = $objp->info_bits;
         $this->special_code = $objp->special_code;
         $this->total_ht = $objp->total_ht;
         $this->total_tva = $objp->total_tva;
         $this->total_localtax1 = $objp->total_localtax1;
         $this->total_localtax2 = $objp->total_localtax2;
         $this->total_ttc = $objp->total_ttc;
         $this->fk_code_ventilation = $objp->fk_code_ventilation;
         $this->rang = $objp->rang;
         $this->fk_fournprice = $objp->fk_fournprice;
         $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $this->fk_fournprice, $objp->pa_ht);
         $this->pa_ht = $marginInfos[0];
         $this->marge_tx = $marginInfos[1];
         $this->marque_tx = $marginInfos[2];
         $this->ref = $objp->product_ref;
         // deprecated
         $this->product_ref = $objp->product_ref;
         $this->libelle = $objp->product_libelle;
         // deprecated
         $this->product_label = $objp->product_libelle;
         $this->product_desc = $objp->product_desc;
         $this->fk_unit = $objp->fk_unit;
         $this->situation_percent = $objp->situation_percent;
         $this->fk_prev_id = $objp->fk_prev_id;
         $this->db->free($result);
         return 1;
     } else {
         return -1;
     }
 }
Esempio n. 2
0
 /**
  *	Retrieve the propal line object
  *
  *	@param	int		$rowid		Propal line id
  *	@return	int					<0 if KO, >0 if OK
  */
 function fetch($rowid)
 {
     $sql = 'SELECT pd.rowid, pd.fk_propal, pd.fk_parent_line, pd.fk_product, pd.label as custom_label, pd.description, pd.price, pd.qty, pd.tva_tx,';
     $sql .= ' pd.remise, pd.remise_percent, pd.fk_remise_except, pd.subprice,';
     $sql .= ' pd.info_bits, pd.total_ht, pd.total_tva, pd.total_ttc, pd.fk_product_fournisseur_price as fk_fournprice, pd.buy_price_ht as pa_ht, pd.special_code, pd.rang,';
     $sql .= ' pd.localtax1_tx, pd.localtax2_tx, pd.total_localtax1, pd.total_localtax2,';
     $sql .= ' p.ref as product_ref, p.label as product_label, p.description as product_desc,';
     $sql .= ' pd.date_start, pd.date_end, pd.product_type';
     $sql .= ' FROM ' . MAIN_DB_PREFIX . 'propaldet as pd';
     $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'product as p ON pd.fk_product = p.rowid';
     $sql .= ' WHERE pd.rowid = ' . $rowid;
     $result = $this->db->query($sql);
     if ($result) {
         $objp = $this->db->fetch_object($result);
         $this->rowid = $objp->rowid;
         $this->fk_propal = $objp->fk_propal;
         $this->fk_parent_line = $objp->fk_parent_line;
         $this->label = $objp->custom_label;
         $this->desc = $objp->description;
         $this->qty = $objp->qty;
         $this->price = $objp->price;
         // deprecated
         $this->subprice = $objp->subprice;
         $this->tva_tx = $objp->tva_tx;
         $this->remise = $objp->remise;
         $this->remise_percent = $objp->remise_percent;
         $this->fk_remise_except = $objp->fk_remise_except;
         $this->fk_product = $objp->fk_product;
         $this->info_bits = $objp->info_bits;
         $this->total_ht = $objp->total_ht;
         $this->total_tva = $objp->total_tva;
         $this->total_ttc = $objp->total_ttc;
         $this->fk_fournprice = $objp->fk_fournprice;
         $marginInfos = getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $this->fk_fournprice, $objp->pa_ht);
         $this->pa_ht = $marginInfos[0];
         $this->marge_tx = $marginInfos[1];
         $this->marque_tx = $marginInfos[2];
         $this->special_code = $objp->special_code;
         $this->product_type = $objp->product_type;
         $this->rang = $objp->rang;
         $this->ref = $objp->product_ref;
         // deprecated
         $this->product_ref = $objp->product_ref;
         $this->libelle = $objp->product_label;
         // deprecated
         $this->product_label = $objp->product_label;
         $this->product_desc = $objp->product_desc;
         $this->date_start = $this->db->jdate($objp->date_start);
         $this->date_end = $this->db->jdate($objp->date_end);
         $this->db->free($result);
     } else {
         dol_print_error($this->db);
     }
 }
Esempio n. 3
0
 /**
  *    	Load object in memory from database
  *
  *    	@param	int		$id         Id object
  * 		@param	string	$ref		Ref of contract
  *    	@return int         		<0 if KO, >0 if OK
  */
 function fetch($id, $ref = '')
 {
     global $langs, $user;
     // Check parameters
     if (empty($id) && empty($ref)) {
         return -1;
     }
     $sql = "SELECT";
     $sql .= " t.rowid,";
     $sql .= " t.tms,";
     $sql .= " t.fk_contrat,";
     $sql .= " t.fk_product,";
     $sql .= " t.statut,";
     $sql .= " t.label,";
     // This field is not used. Only label of product
     $sql .= " p.ref as product_ref,";
     $sql .= " p.label as product_label,";
     $sql .= " p.description as product_desc,";
     $sql .= " t.description,";
     $sql .= " t.date_commande,";
     $sql .= " t.date_ouverture_prevue as date_ouverture_prevue,";
     $sql .= " t.date_ouverture as date_ouverture,";
     $sql .= " t.date_fin_validite as date_fin_validite,";
     $sql .= " t.date_cloture as date_cloture,";
     $sql .= " t.tva_tx,";
     $sql .= " t.localtax1_tx,";
     $sql .= " t.localtax2_tx,";
     $sql .= " t.qty,";
     $sql .= " t.remise_percent,";
     $sql .= " t.remise,";
     $sql .= " t.fk_remise_except,";
     $sql .= " t.subprice,";
     $sql .= " t.price_ht,";
     $sql .= " t.total_ht,";
     $sql .= " t.total_tva,";
     $sql .= " t.total_localtax1,";
     $sql .= " t.total_localtax2,";
     $sql .= " t.total_ttc,";
     $sql .= " t.fk_product_fournisseur_price as fk_fournprice,";
     $sql .= " t.buy_price_ht as pa_ht,";
     $sql .= " t.info_bits,";
     $sql .= " t.fk_user_author,";
     $sql .= " t.fk_user_ouverture,";
     $sql .= " t.fk_user_cloture,";
     $sql .= " t.commentaire";
     $sql .= " FROM " . MAIN_DB_PREFIX . "contratdet as t LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = t.fk_product";
     if ($id) {
         $sql .= " WHERE t.rowid = " . $id;
     }
     if ($ref) {
         $sql .= " WHERE t.rowid = '" . $this->db->escape($ref) . "'";
     }
     dol_syslog(get_class($this) . "::fetch", LOG_DEBUG);
     $resql = $this->db->query($sql);
     if ($resql) {
         if ($this->db->num_rows($resql)) {
             $obj = $this->db->fetch_object($resql);
             $this->id = $obj->rowid;
             $this->ref = $obj->rowid;
             $this->tms = $this->db->jdate($obj->tms);
             $this->fk_contrat = $obj->fk_contrat;
             $this->fk_product = $obj->fk_product;
             $this->statut = $obj->statut;
             $this->product_ref = $obj->product_ref;
             $this->product_label = $obj->product_label;
             $this->product_description = $obj->product_description;
             $this->label = $obj->label;
             // deprecated. We do not use this field. Only ref and label of product, and description of contract line
             $this->description = $obj->description;
             $this->date_commande = $this->db->jdate($obj->date_commande);
             $this->date_ouverture_prevue = $this->db->jdate($obj->date_ouverture_prevue);
             $this->date_ouverture = $this->db->jdate($obj->date_ouverture);
             $this->date_fin_validite = $this->db->jdate($obj->date_fin_validite);
             $this->date_cloture = $this->db->jdate($obj->date_cloture);
             $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->remise = $obj->remise;
             $this->fk_remise_except = $obj->fk_remise_except;
             $this->subprice = $obj->subprice;
             $this->price_ht = $obj->price_ht;
             $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->info_bits = $obj->info_bits;
             $this->fk_user_author = $obj->fk_user_author;
             $this->fk_user_ouverture = $obj->fk_user_ouverture;
             $this->fk_user_cloture = $obj->fk_user_cloture;
             $this->commentaire = $obj->commentaire;
             $this->fk_fournprice = $obj->fk_fournprice;
             $marginInfos = getMarginInfos($obj->subprice, $obj->remise_percent, $obj->tva_tx, $obj->localtax1_tx, $obj->localtax2_tx, $this->fk_fournprice, $obj->pa_ht);
             $this->pa_ht = $marginInfos[0];
         }
         $this->db->free($resql);
         return 1;
     } else {
         $this->error = "Error " . $this->db->lasterror();
         return -1;
     }
 }
Esempio n. 4
0
 /**
  * testGetMarginInfos
  *
  * @return	void
  */
 public function testGetMarginInfos()
 {
     global $conf, $user, $langs, $db;
     $conf = $this->savconf;
     $user = $this->savuser;
     $langs = $this->savlangs;
     $db = $this->savdb;
     $result = getMarginInfos(10, 0, 19.6, 0, 0, 0, 8);
     //var_dump($result);
     print __METHOD__ . " result[0]=" . $result[0] . "\n";
     $this->assertEquals(8, $result[0]);
     print __METHOD__ . " result[1]=" . $result[1] . "\n";
     $this->assertEquals(25, $result[1]);
     print __METHOD__ . " result[2]=" . $result[2] . "\n";
     $this->assertEquals(20, $result[2]);
     $result = getMarginInfos(10, 10, 19.6, 0, 0, 0, 8);
     var_dump($result);
     print __METHOD__ . " result[0]=" . $result[0] . "\n";
     $this->assertEquals(8, $result[0]);
     print __METHOD__ . " result[1]=" . $result[1] . "\n";
     $this->assertEquals(12.5, $result[1]);
     print __METHOD__ . " result[2]=" . $result[2] . "\n";
     $this->assertEquals(1 / 9 * 100, $result[2]);
     return 0;
 }