Exemple #1
0
 }
 $fourn = new Fournisseur($db);
 // Change supplier prices
 $sql = 'SELECT pfp.rowid, pfp.fk_soc, pfp.price as price, pfp.quantity as qty, pfp.fk_availability, pfp.ref_fourn';
 $sql .= ' FROM ' . MAIN_DB_PREFIX . 'product_fournisseur_price as pfp, ' . MAIN_DB_PREFIX . 'societe as s';
 $sql .= ' WHERE pfp.fk_soc = s.rowid AND pfp.entity IN (' . getEntity('product', 1) . ')';
 $sql .= " AND tva_tx = '" . $db->escape($oldvatrate) . "'";
 $sql .= " AND s.fk_pays = '" . $country_id . "'";
 //print $sql;
 $resql = $db->query($sql);
 if ($resql) {
     $num = $db->num_rows($resql);
     $i = 0;
     while ($i < $num) {
         $obj = $db->fetch_object($resql);
         $ret = $objectstatic2->fetch_product_fournisseur_price($obj->rowid);
         if ($ret > 0) {
             $ret = 0;
             $retm = 0;
             $updatelevel1 = false;
             $price_base_type = 'HT';
             //$price_base_type = $objectstatic2->price_base_type;	// Get price_base_type of product/service to keep the same for update
             //if ($price_base_type == 'TTC')
             //{
             //	$newprice=price2num($objectstatic2->price_ttc,'MU');    // Second param must be MU (we want a unit price so 'MU'. If unit price was on 4 decimal, we must keep 4 decimals)
             //	$newminprice=$objectstatic2->price_min_ttc;
             //}
             //else
             //{
             $newprice = price2num($obj->price, 'MU');
             // Second param must be MU (we want a unit price so 'MU'. If unit price was on 4 decimal, we must keep 4 decimals)
Exemple #2
0
 }
 print '</td></tr>';
 // Vat rate
 $default_vat = '';
 // We don't have supplier, so we try to guess.
 // For this we build a fictive supplier with same properties than user but using vat)
 $mysoc2 = clone $mysoc;
 $mysoc2->name = 'Fictive seller with same country';
 $mysoc2->tva_assuj = 1;
 $default_vat = get_default_tva($mysoc2, $mysoc, $object->id, 0);
 print '<tr><td class="fieldrequired">' . $langs->trans("VATRateForSupplierProduct") . '</td>';
 print '<td>';
 //print $form->load_tva('tva_tx',$object->tva_tx,$supplier,$mysoc);    // Do not use list here as it may be any vat rates for any country
 if (!empty($rowid)) {
     $tmpproductsupplier = new ProductFournisseur($db);
     $tmpproductsupplier->fetch_product_fournisseur_price($rowid, 1);
     $default_vat = $tmpproductsupplier->fourn_tva_tx;
 } else {
     if (empty($default_vat)) {
         $default_vat = $object->tva_tx;
     }
 }
 print '<input type="text" class="flat" size="5" name="tva_tx" value="' . (GETPOST("tva_tx") ? vatrate(GETPOST("tva_tx")) : ($default_vat != '' ? vatrate($default_vat) : '')) . '">';
 print '</td></tr>';
 if (!empty($conf->dynamicprices->enabled)) {
     // Price mode selector
     print '<tr><td class="fieldrequired">' . $langs->trans("PriceMode") . '</td><td>';
     $price_expression = new PriceExpression($db);
     $price_expression_list = array(0 => $langs->trans("PriceNumeric"));
     //Put the numeric mode as first option
     foreach ($price_expression->list_price_expression() as $entry) {
         $error++;
         $product->fetch($product->product_id_already_linked);
         $productLink = $product->getNomUrl(1, 'supplier');
         setEventMessage($langs->trans("ReferenceSupplierIsAlreadyAssociatedWithAProduct", $productLink), 'errors');
     } else {
         if ($ret < 0) {
             $error++;
             setEventMessage($product->error, 'errors');
         }
     }
 }
 if (!$error) {
     $supplier = new Fournisseur($db);
     $result = $supplier->fetch($id_fourn);
     if (isset($_POST['ref_fourn_price_id'])) {
         $product->fetch_product_fournisseur_price($_POST['ref_fourn_price_id']);
     }
     $ret = $product->update_buyprice($quantity, $_POST["price"], $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx, $_POST["charges"], $remise_percent, 0, $npr, $delivery_time_days);
     if ($ret < 0) {
         $error++;
         setEventMessage($product->error, $product->errors, 'errors');
     } else {
         if ($price_expression !== '') {
             //Check the expression validity by parsing it
             $priceparser = new PriceParser($db);
             $price_result = $priceparser->parseProductSupplier($id, $price_expression, $quantity, $tva_tx);
             if ($price_result < 0) {
                 //Expression is not valid
                 $error++;
                 setEventMessage($priceparser->translatedError(), 'errors');
             }
 function getMarginInfos($force_price = false)
 {
     global $conf;
     require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php';
     $marginInfos = array('pa_products' => 0, 'pv_products' => 0, 'margin_on_products' => 0, 'margin_rate_products' => '', 'mark_rate_products' => '', 'pa_services' => 0, 'pv_services' => 0, 'margin_on_services' => 0, 'margin_rate_services' => '', 'mark_rate_services' => '', 'pa_total' => 0, 'pv_total' => 0, 'total_margin' => 0, 'total_margin_rate' => '', 'total_mark_rate' => '');
     foreach ($this->lines as $line) {
         if (isset($line->fk_fournprice) && !$force_price) {
             $product = new ProductFournisseur($this->db);
             if ($product->fetch_product_fournisseur_price($line->fk_fournprice)) {
                 $line->pa_ht = $product->fourn_unitprice;
             }
             if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == "2" && $product->fourn_unitcharges > 0) {
                 $line->pa_ht += $product->fourn_unitcharges;
             }
         }
         // si prix d'achat non renseigné et devrait l'être, alors prix achat = prix vente
         if ((!isset($line->pa_ht) || $line->pa_ht == 0) && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) {
             $line->pa_ht = $line->subprice * (1 - $line->remise_percent / 100);
         }
         // calcul des marges
         if (isset($line->fk_remise_except) && isset($conf->global->MARGIN_METHODE_FOR_DISCOUNT)) {
             // remise
             if ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '1') {
                 // remise globale considérée comme produit
                 $marginInfos['pa_products'] += $line->pa_ht != 0 ? $line->pa_ht : $line->subprice * (1 - $line->remise_percent / 100);
                 $marginInfos['pv_products'] += $line->subprice * (1 - $line->remise_percent / 100);
                 $marginInfos['pa_total'] += $line->pa_ht != 0 ? $line->pa_ht : $line->subprice * (1 - $line->remise_percent / 100);
                 $marginInfos['pv_total'] += $line->subprice * (1 - $line->remise_percent / 100);
             } elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '2') {
                 // remise globale considérée comme service
                 $marginInfos['pa_services'] += $line->pa_ht != 0 ? $line->pa_ht : $line->subprice * (1 - $line->remise_percent / 100);
                 $marginInfos['pv_services'] += $line->subprice * (1 - $line->remise_percent / 100);
                 $marginInfos['pa_total'] += $line->pa_ht != 0 ? $line->pa_ht : $line->subprice * (1 - $line->remise_percent / 100);
                 $marginInfos['pv_total'] += $line->subprice * (1 - $line->remise_percent / 100);
             } elseif ($conf->global->MARGIN_METHODE_FOR_DISCOUNT == '3') {
                 // remise globale prise en compte uniqt sur total
                 $marginInfos['pa_total'] += $line->pa_ht != 0 ? $line->pa_ht : $line->subprice * (1 - $line->remise_percent / 100);
                 $marginInfos['pv_total'] += $line->subprice * (1 - $line->remise_percent / 100);
             }
         } else {
             $type = $line->product_type ? $line->product_type : $line->fk_product_type;
             if ($type == 0) {
                 // product
                 $marginInfos['pa_products'] += $line->qty * $line->pa_ht;
                 $marginInfos['pv_products'] += $line->qty * $line->subprice * (1 - $line->remise_percent / 100);
                 $marginInfos['pa_total'] += $line->qty * $line->pa_ht;
                 $marginInfos['pv_total'] += $line->qty * $line->subprice * (1 - $line->remise_percent / 100);
             } elseif ($type == 1) {
                 // service
                 $marginInfos['pa_services'] += $line->qty * $line->pa_ht;
                 $marginInfos['pv_services'] += $line->qty * $line->subprice * (1 - $line->remise_percent / 100);
                 $marginInfos['pa_total'] += $line->qty * $line->pa_ht;
                 $marginInfos['pv_total'] += $line->qty * $line->subprice * (1 - $line->remise_percent / 100);
             }
         }
     }
     $marginInfos['margin_on_products'] = $marginInfos['pv_products'] - $marginInfos['pa_products'];
     if ($marginInfos['pa_products'] > 0) {
         $marginInfos['margin_rate_products'] = 100 * round($marginInfos['margin_on_products'] / $marginInfos['pa_products'], 5);
     }
     if ($marginInfos['pv_products'] > 0) {
         $marginInfos['mark_rate_products'] = 100 * round($marginInfos['margin_on_products'] / $marginInfos['pv_products'], 5);
     }
     $marginInfos['margin_on_services'] = $marginInfos['pv_services'] - $marginInfos['pa_services'];
     if ($marginInfos['pa_services'] > 0) {
         $marginInfos['margin_rate_services'] = 100 * round($marginInfos['margin_on_services'] / $marginInfos['pa_services'], 5);
     }
     if ($marginInfos['pv_services'] > 0) {
         $marginInfos['mark_rate_services'] = 100 * round($marginInfos['margin_on_services'] / $marginInfos['pv_services'], 5);
     }
     $marginInfos['total_margin'] = $marginInfos['pv_total'] - $marginInfos['pa_total'];
     if ($marginInfos['pa_total'] > 0) {
         $marginInfos['total_margin_rate'] = 100 * round($marginInfos['total_margin'] / $marginInfos['pa_total'], 5);
     }
     if ($marginInfos['pv_total'] > 0) {
         $marginInfos['total_mark_rate'] = 100 * round($marginInfos['total_margin'] / $marginInfos['pv_total'], 5);
     }
     return $marginInfos;
 }
Exemple #5
0
/**
 * getMarginInfos
 *
 * @param 	float 	$pvht				Buying price with tax
 * @param 	float	$remise_percent		Discount percent
 * @param 	float	$tva_tx				Vat rate
 * @param 	float	$localtax1_tx		Vat rate special 1
 * @param 	float	$localtax2_tx		Vat rate special 2
 * @param 	int		$fk_pa				???
 * @param 	float	$paht				Buying price without tax
 * @return	array						Array of margin info
 */
function getMarginInfos($pvht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $paht)
{
  global $db, $conf;

  $marge_tx_ret='';
  $marque_tx_ret='';

  if($fk_pa > 0) {
  	require_once DOL_DOCUMENT_ROOT."/fourn/class/fournisseur.product.class.php";
  	$product = new ProductFournisseur($db);
  	if ($product->fetch_product_fournisseur_price($fk_pa)) {
  		$paht_ret = $product->fourn_unitprice;
  		if ($conf->global->MARGIN_TYPE == "2" && $product->fourn_unitcharges > 0)
  			$paht_ret += $product->fourn_unitcharges;
  	}
  	else
  		$paht_ret = $paht;
  }
  else
  	$paht_ret	= $paht;

  require_once(DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php');
  // calcul pu_ht remisés
  $tabprice=calcul_price_total(1, $pvht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, 0, 'HT');
  $pu_ht_remise = $tabprice[0];
  // calcul taux marge
  if ($paht_ret != 0)
  	$marge_tx_ret = round((100 * ($pu_ht_remise - $paht_ret)) / $paht_ret, 3);
  // calcul taux marque
  if ($pu_ht_remise != 0)
  	$marque_tx_ret = round((100 * ($pu_ht_remise - $paht_ret)) / $pu_ht_remise, 3);

  return array($paht_ret, $marge_tx_ret, $marque_tx_ret);
}
Exemple #6
0
/**
 * Return an array with margins information of a line
 *
 * @param 	float 	$pvht				Selling price without tax
 * @param 	float	$remise_percent		Discount percent on line
 * @param 	float	$tva_tx				Vat rate (not used)
 * @param 	float	$localtax1_tx		Vat rate special 1 (not used)
 * @param 	float	$localtax2_tx		Vat rate special 2 (not used)
 * @param 	int		$fk_pa				Id of buying price (prefer set this to 0 and provide $paht instead. With id, buying price may have change)
 * @param 	float	$paht				Buying price without tax
 * @return	array						Array of margin info
 */
function getMarginInfos($pvht, $remise_percent, $tva_tx, $localtax1_tx, $localtax2_tx, $fk_pa, $paht)
{
    global $db, $conf;
    $marge_tx_ret = '';
    $marque_tx_ret = '';
    if ($fk_pa > 0) {
        require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php';
        $product = new ProductFournisseur($db);
        if ($product->fetch_product_fournisseur_price($fk_pa)) {
            $paht_ret = $product->fourn_unitprice * (1 - $product->fourn_remise_percent / 100);
            if ($conf->global->MARGIN_TYPE == "2" && $product->fourn_unitcharges > 0) {
                $paht_ret += $product->fourn_unitcharges;
            }
        } else {
            $paht_ret = $paht;
        }
    } else {
        $paht_ret = $paht;
    }
    // Calculate selling unit price including line discount
    // We don't use calculate_price, because this function is dedicated to calculation of total with accuracy of total. We need an accuracy of a unit price.
    // Also we must not apply rounding on non decimal rule defined by option MAIN_ROUNDING_RULE_TOT
    $pu_ht_remise = $pvht * (1 - $remise_percent / 100);
    $pu_ht_remise = price2num($pu_ht_remise, 'MU');
    // calcul marge
    if ($pu_ht_remise < 0) {
        $marge = -1 * (abs($pu_ht_remise) - $paht_ret);
    } else {
        $marge = $pu_ht_remise - $paht_ret;
    }
    // calcul taux marge
    if ($paht_ret != 0) {
        $marge_tx_ret = 100 * $marge / $paht_ret;
    }
    // calcul taux marque
    if ($pu_ht_remise != 0) {
        $marque_tx_ret = 100 * $marge / $pu_ht_remise;
    }
    return array($paht_ret, $marge_tx_ret, $marque_tx_ret);
}
Exemple #7
0
/**
 *	Fonction qui renvoie si tva doit etre tva percue recuperable
 *
 *	@param	Societe		$thirdparty_seller    	Thirdparty seller
 *	@param  Societe		$thirdparty_buyer   	Thirdparty buyer
 *  @param  int			$idprod                 Id product
 *  @param	int			$idprodfournprice		Id supplier price for product
 *	@return float       			        	0 or 1
 *  @see get_default_tva, get_default_localtax
 */
function get_default_npr($thirdparty_seller, $thirdparty_buyer, $idprod = 0, $idprodfournprice = 0)
{
    global $db;
    if ($idprodfournprice > 0) {
        if (!class_exists('ProductFournisseur')) {
            require DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php';
        }
        $prodprice = new ProductFournisseur($db);
        $prodprice->fetch_product_fournisseur_price($idprodfournprice);
        return $prodprice->fourn_tva_npr;
    } elseif ($idprod > 0) {
        if (!class_exists('Product')) {
            require DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
        }
        $prod = new Product($db);
        $prod->fetch($idprod);
        return $prod->tva_npr;
    }
    return 0;
}