Example #1
0
 /**
  *	Insert line into database
  *
  *	@param      int		$notrigger		1 no triggers
  *	@return		int						<0 if KO, >0 if OK
  */
 function insert($notrigger = 0)
 {
     global $langs, $user, $conf;
     $error = 0;
     dol_syslog(get_class($this) . "::insert rang=" . $this->rang, LOG_DEBUG);
     // Clean parameters
     $this->desc = trim($this->desc);
     if (empty($this->tva_tx)) {
         $this->tva_tx = 0;
     }
     if (empty($this->localtax1_tx)) {
         $this->localtax1_tx = 0;
     }
     if (empty($this->localtax2_tx)) {
         $this->localtax2_tx = 0;
     }
     if (empty($this->localtax1_type)) {
         $this->localtax1_type = 0;
     }
     if (empty($this->localtax2_type)) {
         $this->localtax2_type = 0;
     }
     if (empty($this->total_localtax1)) {
         $this->total_localtax1 = 0;
     }
     if (empty($this->total_localtax2)) {
         $this->total_localtax2 = 0;
     }
     if (empty($this->rang)) {
         $this->rang = 0;
     }
     if (empty($this->remise_percent)) {
         $this->remise_percent = 0;
     }
     if (empty($this->info_bits)) {
         $this->info_bits = 0;
     }
     if (empty($this->subprice)) {
         $this->subprice = 0;
     }
     if (empty($this->special_code)) {
         $this->special_code = 0;
     }
     if (empty($this->fk_parent_line)) {
         $this->fk_parent_line = 0;
     }
     if (empty($this->pa_ht)) {
         $this->pa_ht = 0;
     }
     // si prix d'achat non renseigne et utilise pour calcul des marges alors prix achat = prix vente
     if ($this->pa_ht == 0) {
         if ($this->subprice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) {
             $this->pa_ht = $this->subprice * (1 - $this->remise_percent / 100);
         }
     }
     // Check parameters
     if ($this->product_type < 0) {
         $this->error = 'ErrorProductTypeMustBe0orMore';
         return -1;
     }
     if (!empty($this->fk_product)) {
         // Check product exists
         $result = Product::isExistingObject('product', $this->fk_product);
         if ($result <= 0) {
             $this->error = 'ErrorProductIdDoesNotExists';
             return -1;
         }
     }
     // POS or by external module, take lowest buying price
     if (!empty($this->fk_product) && empty($this->fk_fournprice) && empty($this->pa_ht)) {
         include_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php';
         $productFournisseur = new ProductFournisseur($this->db);
         $productFournisseur->find_min_price_product_fournisseur($this->fk_product);
         $this->fk_fournprice = $productFournisseur->product_fourn_price_id;
     }
     $this->db->begin();
     // Insertion dans base de la ligne
     $sql = 'INSERT INTO ' . MAIN_DB_PREFIX . 'facturedet';
     $sql .= ' (fk_facture, fk_parent_line, label, description, qty,';
     $sql .= ' tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,';
     $sql .= ' fk_product, product_type, remise_percent, subprice, fk_remise_except,';
     $sql .= ' date_start, date_end, fk_code_ventilation, ';
     $sql .= ' rang, special_code, fk_product_fournisseur_price, buy_price_ht,';
     $sql .= ' info_bits, total_ht, total_tva, total_ttc, total_localtax1, total_localtax2)';
     $sql .= " VALUES (" . $this->fk_facture . ",";
     $sql .= " " . ($this->fk_parent_line > 0 ? "'" . $this->fk_parent_line . "'" : "null") . ",";
     $sql .= " " . (!empty($this->label) ? "'" . $this->db->escape($this->label) . "'" : "null") . ",";
     $sql .= " '" . $this->db->escape($this->desc) . "',";
     $sql .= " " . price2num($this->qty) . ",";
     $sql .= " " . price2num($this->tva_tx) . ",";
     $sql .= " " . price2num($this->localtax1_tx) . ",";
     $sql .= " " . price2num($this->localtax2_tx) . ",";
     $sql .= " '" . $this->localtax1_type . "',";
     $sql .= " '" . $this->localtax2_type . "',";
     $sql .= ' ' . (!empty($this->fk_product) ? $this->fk_product : "null") . ',';
     $sql .= " " . $this->product_type . ",";
     $sql .= " " . price2num($this->remise_percent) . ",";
     $sql .= " " . price2num($this->subprice) . ",";
     $sql .= ' ' . (!empty($this->fk_remise_except) ? $this->fk_remise_except : "null") . ',';
     $sql .= " " . (!empty($this->date_start) ? "'" . $this->db->idate($this->date_start) . "'" : "null") . ",";
     $sql .= " " . (!empty($this->date_end) ? "'" . $this->db->idate($this->date_end) . "'" : "null") . ",";
     $sql .= ' ' . $this->fk_code_ventilation . ',';
     $sql .= ' ' . $this->rang . ',';
     $sql .= ' ' . $this->special_code . ',';
     $sql .= ' ' . (!empty($this->fk_fournprice) ? $this->fk_fournprice : "null") . ',';
     $sql .= ' ' . price2num($this->pa_ht) . ',';
     $sql .= " '" . $this->info_bits . "',";
     $sql .= " " . price2num($this->total_ht) . ",";
     $sql .= " " . price2num($this->total_tva) . ",";
     $sql .= " " . price2num($this->total_ttc) . ",";
     $sql .= " " . price2num($this->total_localtax1) . ",";
     $sql .= " " . price2num($this->total_localtax2);
     $sql .= ')';
     dol_syslog(get_class($this) . "::insert", LOG_DEBUG);
     $resql = $this->db->query($sql);
     if ($resql) {
         $this->rowid = $this->db->last_insert_id(MAIN_DB_PREFIX . 'facturedet');
         if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
             $this->id = $this->rowid;
             $result = $this->insertExtraFields();
             if ($result < 0) {
                 $error++;
             }
         }
         // Si fk_remise_except defini, on lie la remise a la facture
         // ce qui la flague comme "consommee".
         if ($this->fk_remise_except) {
             $discount = new DiscountAbsolute($this->db);
             $result = $discount->fetch($this->fk_remise_except);
             if ($result >= 0) {
                 // Check if discount was found
                 if ($result > 0) {
                     // Check if discount not already affected to another invoice
                     if ($discount->fk_facture) {
                         $this->error = $langs->trans("ErrorDiscountAlreadyUsed", $discount->id);
                         dol_syslog(get_class($this) . "::insert Error " . $this->error, LOG_ERR);
                         $this->db->rollback();
                         return -3;
                     } else {
                         $result = $discount->link_to_invoice($this->rowid, 0);
                         if ($result < 0) {
                             $this->error = $discount->error;
                             dol_syslog(get_class($this) . "::insert Error " . $this->error, LOG_ERR);
                             $this->db->rollback();
                             return -3;
                         }
                     }
                 } else {
                     $this->error = $langs->trans("ErrorADiscountThatHasBeenRemovedIsIncluded");
                     dol_syslog(get_class($this) . "::insert Error " . $this->error, LOG_ERR);
                     $this->db->rollback();
                     return -3;
                 }
             } else {
                 $this->error = $discount->error;
                 dol_syslog(get_class($this) . "::insert Error " . $this->error, LOG_ERR);
                 $this->db->rollback();
                 return -3;
             }
         }
         if (!$notrigger) {
             // Call trigger
             $result = $this->call_trigger('LINEBILL_INSERT', $user);
             if ($result < 0) {
                 $this->db->rollback();
                 return -2;
             }
             // End call triggers
         }
         $this->db->commit();
         return $this->rowid;
     } else {
         $this->error = $this->db->error();
         $this->db->rollback();
         return -2;
     }
 }
Example #2
0
     print '<tr><td>' . $langs->trans("ManageLotSerial") . '</td><td>';
     print $product->getLibStatut(0, 2);
     print '</td></tr>';
 }
 // PMP
 print '<tr><td>' . $langs->trans("AverageUnitPricePMP") . '</td>';
 print '<td>';
 if ($product->pmp > 0) {
     print price($product->pmp) . ' ' . $langs->trans("HT");
 }
 print '</td>';
 print '</tr>';
 // Minimum Price
 print '<tr><td>' . $langs->trans("BuyingPriceMin") . '</td>';
 print '<td colspan="2">';
 $product_fourn = new ProductFournisseur($db);
 if ($product_fourn->find_min_price_product_fournisseur($product->id) > 0) {
     if ($product_fourn->product_fourn_price_id > 0) {
         print $product_fourn->display_price_product_fournisseur();
     } else {
         print $langs->trans("NotDefined");
     }
 }
 print '</td></tr>';
 $object = $product;
 if (empty($conf->global->PRODUIT_MULTIPRICES)) {
     // Price
     print '<tr><td>' . $langs->trans("SellingPrice") . '</td><td>';
     if ($object->price_base_type == 'TTC') {
         print price($object->price_ttc) . ' ' . $langs->trans($object->price_base_type);
     } else {
Example #3
0
        if (!empty($TProduct)) {
            foreach ($TProduct as $id_product => $row) {
                if ($row['qty'] > 0) {
                    $object->update_sousproduit($id, $id_product, $row['qty'], isset($row['incdec']) ? 1 : 0);
                } else {
                    $object->del_sousproduit($id, $id_product);
                }
            }
        }
        $action = '';
    }
}
/*
 * View
 */
$product_fourn = new ProductFournisseur($db);
$productstatic = new Product($db);
$form = new Form($db);
// action recherche des produits par mot-cle et/ou par categorie
if ($action == 'search') {
    $current_lang = $langs->getDefaultLang();
    $sql = 'SELECT DISTINCT p.rowid, p.ref, p.label, p.barcode, p.price, p.price_ttc, p.price_base_type,';
    $sql .= ' p.fk_product_type, p.tms as datem';
    if (!empty($conf->global->MAIN_MULTILANGS)) {
        $sql .= ', pl.label as labelm, pl.description as descriptionm';
    }
    $sql .= ' FROM ' . MAIN_DB_PREFIX . 'product as p';
    $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'categorie_product as cp ON p.rowid = cp.fk_product';
    if (!empty($conf->global->MAIN_MULTILANGS)) {
        $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_lang as pl ON pl.fk_product = p.rowid AND lang='" . $current_lang . "'";
    }
Example #4
0
 /**
  *  Update a proposal line
  *
  *  @param      int			$rowid           	Id de la ligne
  *  @param      float		$pu		     	  	Prix unitaire (HT ou TTC selon price_base_type)
  *  @param      float		$qty            	Quantity
  *  @param      float		$remise_percent  	Remise effectuee sur le produit
  *  @param      float		$txtva	          	Taux de TVA
  * 	@param	  	float		$txlocaltax1		Local tax 1 rate
  *  @param	  	float		$txlocaltax2		Local tax 2 rate
  *  @param      string		$desc            	Description
  *	@param	  	string		$price_base_type	HT ou TTC
  *	@param      int			$info_bits        	Miscellaneous informations
  *	@param		int			$special_code		Special code (also used by externals modules!)
  * 	@param		int			$fk_parent_line		Id of parent line (0 in most cases, used by modules adding sublevels into lines).
  * 	@param		int			$skip_update_total	Keep fields total_xxx to 0 (used for special lines by some modules)
  *  @param		int			$fk_fournprice		Id of origin supplier price
  *  @param		int			$pa_ht				Price (without tax) of product when it was bought
  *  @param		string		$label				???
  *  @param		int			$type				0/1=Product/service
  *	@param      int			$date_start       	Start date of the line
  *	@param      int			$date_end         	End date of the line
  *  @param		array		$array_option		extrafields array
  *  @return     int     		        		0 if OK, <0 if KO
  */
 function updateline($rowid, $pu, $qty, $remise_percent, $txtva, $txlocaltax1 = 0.0, $txlocaltax2 = 0.0, $desc = '', $price_base_type = 'HT', $info_bits = 0, $special_code = 0, $fk_parent_line = 0, $skip_update_total = 0, $fk_fournprice = 0, $pa_ht = 0, $label = '', $type = 0, $date_start = '', $date_end = '', $array_option = 0)
 {
     global $mysoc;
     dol_syslog(get_class($this) . "::updateLine rowid={$rowid}, pu={$pu}, qty={$qty}, remise_percent={$remise_percent}, txtva={$txtva}, desc={$desc}, price_base_type={$price_base_type}, info_bits={$info_bits}, special_code={$special_code}, fk_parent_line={$fk_parent_line}, pa_ht={$a_ht}, type={$type}, date_start={$date_start}, date_end={$date_end}");
     include_once DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php';
     // Clean parameters
     $remise_percent = price2num($remise_percent);
     $qty = price2num($qty);
     $pu = price2num($pu);
     $txtva = price2num($txtva);
     $txlocaltax1 = price2num($txlocaltax1);
     $txlocaltax2 = price2num($txlocaltax2);
     $pa_ht = price2num($pa_ht);
     if (empty($qty) && empty($special_code)) {
         $special_code = 3;
     }
     // Set option tag
     if (!empty($qty) && $special_code == 3) {
         $special_code = 0;
     }
     // Remove option tag
     if ($this->statut == 0) {
         $this->db->begin();
         // 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, $this->thirdparty, $mysoc);
         $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $mysoc, $localtaxes_type);
         $total_ht = $tabprice[0];
         $total_tva = $tabprice[1];
         $total_ttc = $tabprice[2];
         $total_localtax1 = $tabprice[9];
         $total_localtax2 = $tabprice[10];
         // Anciens indicateurs: $price, $remise (a ne plus utiliser)
         $price = $pu;
         if ($remise_percent > 0) {
             $remise = round($pu * $remise_percent / 100, 2);
             $price = $pu - $remise;
         }
         // Update line
         $this->line = new PropaleLigne($this->db);
         $this->line->context = $this->context;
         // Stock previous line records
         $staticline = new PropaleLigne($this->db);
         $staticline->fetch($rowid);
         $this->line->oldline = $staticline;
         // Reorder if fk_parent_line change
         if (!empty($fk_parent_line) && !empty($staticline->fk_parent_line) && $fk_parent_line != $staticline->fk_parent_line) {
             $rangmax = $this->line_max($fk_parent_line);
             $this->line->rang = $rangmax + 1;
         }
         $this->line->rowid = $rowid;
         $this->line->label = $label;
         $this->line->desc = $desc;
         $this->line->qty = $qty;
         $this->line->product_type = $type;
         $this->line->tva_tx = $txtva;
         $this->line->localtax1_tx = $txlocaltax1;
         $this->line->localtax2_tx = $txlocaltax2;
         $this->line->localtax1_type = $localtaxes_type[0];
         $this->line->localtax2_type = $localtaxes_type[2];
         $this->line->remise_percent = $remise_percent;
         $this->line->subprice = $pu;
         $this->line->info_bits = $info_bits;
         $this->line->total_ht = $total_ht;
         $this->line->total_tva = $total_tva;
         $this->line->total_localtax1 = $total_localtax1;
         $this->line->total_localtax2 = $total_localtax2;
         $this->line->total_ttc = $total_ttc;
         $this->line->special_code = $special_code;
         $this->line->fk_parent_line = $fk_parent_line;
         $this->line->skip_update_total = $skip_update_total;
         // infos marge
         if (!empty($fk_product) && empty($fk_fournprice) && empty($pa_ht)) {
             // by external module, take lowest buying price
             include_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php';
             $productFournisseur = new ProductFournisseur($this->db);
             $productFournisseur->find_min_price_product_fournisseur($fk_product);
             $this->line->fk_fournprice = $productFournisseur->product_fourn_price_id;
         } else {
             $this->line->fk_fournprice = $fk_fournprice;
         }
         $this->line->pa_ht = $pa_ht;
         $this->line->date_start = $date_start;
         $this->line->date_end = $date_end;
         // TODO deprecated
         $this->line->price = $price;
         $this->line->remise = $remise;
         if (is_array($array_option) && count($array_option) > 0) {
             $this->line->array_options = $array_option;
         }
         $result = $this->line->update();
         if ($result > 0) {
             // Reorder if child line
             if (!empty($fk_parent_line)) {
                 $this->line_order(true, 'DESC');
             }
             $this->update_price(1);
             $this->fk_propal = $this->id;
             $this->rowid = $rowid;
             $this->db->commit();
             return $result;
         } else {
             $this->error = $this->line->error;
             $this->db->rollback();
             return -1;
         }
     } else {
         dol_syslog(get_class($this) . "::updateline Erreur -2 Propal en mode incompatible pour cette action");
         return -2;
     }
 }
Example #5
0
 }
 if (GETPOST('prod_entry_mode') == 'free' && GETPOST('price_ht') === '' && GETPOST('price_ttc') === '') {
     setEventMessages($langs->trans($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('UnitPrice'))), null, 'errors');
     $error++;
 }
 if (GETPOST('prod_entry_mode') == 'free' && !GETPOST('dp_desc')) {
     setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), null, 'errors');
     $error++;
 }
 if (!GETPOST('qty')) {
     setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors');
     $error++;
 }
 if (GETPOST('prod_entry_mode') != 'free') {
     $idprod = 0;
     $productsupplier = new ProductFournisseur($db);
     if (GETPOST('idprodfournprice') == -1 || GETPOST('idprodfournprice') == '') {
         $idprod = -2;
     }
     // Same behaviour than with combolist. When not select idprodfournprice is now -2 (to avoid conflict with next action that may return -1)
     if (GETPOST('idprodfournprice') > 0) {
         $idprod = $productsupplier->get_buyprice(GETPOST('idprodfournprice'), $qty);
         // Just to see if a price exists for the quantity. Not used to found vat.
     }
     //Replaces $fk_unit with the product's
     if ($idprod > 0) {
         $result = $productsupplier->fetch($idprod);
         $label = $productsupplier->label;
         $desc = $productsupplier->description;
         if (trim($product_desc) != trim($desc)) {
             $desc = dol_concatdesc($desc, $product_desc);
if (!defined('NOREQUIRESOC')) {
    define('NOREQUIRESOC', '1');
}
//if (! defined('NOREQUIRETRAN'))  define('NOREQUIRETRAN','1');
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php';
$idprod = GETPOST('idprod', 'int');
$prices = array();
$langs->load('stocks');
/*
 * View
*/
top_httphead();
//print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";
if ($idprod > 0) {
    $producttmp = new ProductFournisseur($db);
    $producttmp->fetch($idprod);
    $sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration,";
    $sql .= " pfp.ref_fourn,";
    $sql .= " pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.remise_percent, pfp.quantity, pfp.unitprice, pfp.charges, pfp.unitcharges,";
    $sql .= " pfp.fk_supplier_price_expression, pfp.tva_tx, s.nom as name";
    $sql .= " FROM " . MAIN_DB_PREFIX . "product_fournisseur_price as pfp";
    $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product as p ON p.rowid = pfp.fk_product";
    $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON s.rowid = pfp.fk_soc";
    $sql .= " WHERE pfp.fk_product = " . $idprod;
    $sql .= " AND p.tobuy = 1";
    $sql .= " AND s.fournisseur = 1";
    $sql .= " ORDER BY s.nom, pfp.ref_fourn DESC";
    dol_syslog("Ajax::getSupplierPrices", LOG_DEBUG);
    $result = $db->query($sql);
    if ($result) {
 /**
  * Return minimum product recommended price
  *
  * @return	int			Minimum recommanded price that is higher price among all suppliers * PRODUCT_MINIMUM_RECOMMENDED_PRICE
  */
 function min_recommended_price()
 {
     global $conf;
     $maxpricesupplier = 0;
     if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE)) {
         require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php';
         $product_fourn = new ProductFournisseur($this->db);
         $product_fourn_list = $product_fourn->list_product_fournisseur_price($this->id, '', '');
         if (is_array($product_fourn_list) && count($product_fourn_list) > 0) {
             foreach ($product_fourn_list as $productfourn) {
                 if ($productfourn->fourn_unitprice > $maxpricesupplier) {
                     $maxpricesupplier = $productfourn->fourn_unitprice;
                 }
             }
             $maxpricesupplier *= $conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE;
         }
     }
     return $maxpricesupplier;
 }
Example #8
0
 /**
  *	Calculates supplier product price based on product id and string expression
  *
  *	@param	int					$product_id    	The Product id to get information
  *	@param	string 				$expression     The expression to parse
  *	@param	int					$quantity     	Supplier Min quantity
  *	@param	int					$tva_tx     	Supplier VAT rate
  *	@param	array 				$extra_values   Any aditional values for expression
  *  @return int 				> 0 if OK, < 1 if KO
  */
 public function parseProductSupplierExpression($product_id, $expression, $quantity = null, $tva_tx = null, $extra_values = array())
 {
     //Get the product data
     $product = new ProductFournisseur($this->db);
     $product->fetch($product_id, '', '', 1);
     //Accessible values by expressions
     $extra_values = array_merge($extra_values, array("supplier_quantity" => $quantity, "supplier_tva_tx" => $tva_tx));
     return $this->parseExpression($product, $expression, $extra_values);
 }
Example #9
0
 /**
  * define buy price if not defined
  *	set buy price = sell price if ForceBuyingPriceIfNull configured,
  *	 else if calculation MARGIN_TYPE = 'pmp' and pmp is calculated, set pmp as buyprice
  *	 else set min buy price as buy price
  *	 
  * @param float		$unitPrice		 product unit price
  * @param float		$discountPercent line discount percent
  * @param int		$fk_product		 product id
  *
  * @return	float <0 if ko, buyprice if ok
  */
 public function defineBuyPrice($unitPrice = 0, $discountPercent = 0, $fk_product = 0)
 {
     global $conf;
     $buyPrice = 0;
     if ($unitPrice > 0 && (isset($conf->global->ForceBuyingPriceIfNull) && $conf->global->ForceBuyingPriceIfNull == 1)) {
         $buyPrice = $unitPrice * (1 - $discountPercent / 100);
     } else {
         // Get PMP
         if (!empty($fk_product)) {
             if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == 'pmp') {
                 require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
                 $product = new Product($this->db);
                 $result = $product->fetch($fk_product);
                 if ($result <= 0) {
                     $this->errors[] = 'ErrorProductIdDoesNotExists';
                     return -1;
                 }
                 if ($product->pmp > 0) {
                     $buyPrice = $product->pmp;
                 }
                 // TODO add option to set PMP of product
             } else {
                 if (isset($conf->global->MARGIN_TYPE) && $conf->global->MARGIN_TYPE == '1') {
                     require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php';
                     $productFournisseur = new ProductFournisseur($this->db);
                     if (($result = $productFournisseur->find_min_price_product_fournisseur($fk_product)) > 0) {
                         $buyPrice = $productFournisseur->fourn_price;
                     } else {
                         if ($result < 0) {
                             $this->errors[] = $productFournisseur->error;
                             return -2;
                         }
                     }
                 }
             }
         }
     }
     return $buyPrice;
 }
Example #10
0
 print '<td class="liste_titre"><input type="text" class="flat" size="10" name="search_invoice" value="' . $search_invoice . '"></td>';
 print '<td class="liste_titre"><input type="text" class="flat" size="15" name="search_ref" value="' . $search_ref . '"></td>';
 print '<td class="liste_titre"><input type="text" class="flat" size="20" name="search_label" value="' . $search_label . '"></td>';
 print '<td class="liste_titre"><input type="text" class="flat" size="20" name="search_desc" value="' . $search_desc . '"></td>';
 print '<td class="liste_titre" align="right"><input type="text" class="flat" size="10" name="search_amount" value="' . $search_amount . '"></td>';
 print '<td class="liste_titre" align="center"><input type="text" class="flat" size="5" name="search_vat" value="' . $search_vat . '">%</td>';
 print '<td class="liste_titre" align="center">&nbsp;</td>';
 print '<td class="liste_titre">&nbsp;</td>';
 print '<td align="right" colspan="2" class="liste_titre">';
 print '<input type="image" class="liste_titre" src="' . img_picto($langs->trans("Search"), 'search.png', '', '', 1) . '" name="button_search" value="' . dol_escape_htmltag($langs->trans("Search")) . '" title="' . dol_escape_htmltag($langs->trans("Search")) . '">';
 print '&nbsp;';
 print '<input type="image" class="liste_titre" src="' . img_picto($langs->trans("Search"), 'searchclear.png', '', '', 1) . '" name="button_removefilter" value="' . dol_escape_htmltag($langs->trans("RemoveFilter")) . '" title="' . dol_escape_htmltag($langs->trans("RemoveFilter")) . '">';
 print '</td>';
 print '</tr>';
 $facturefourn_static = new FactureFournisseur($db);
 $productfourn_static = new ProductFournisseur($db);
 $form = new Form($db);
 $var = True;
 while ($i < min($num_lines, $limit)) {
     $objp = $db->fetch_object($result);
     $var = !$var;
     // product_type: 0 = service ? 1 = product
     // if product does not exist we use the value of product_type provided in facturedet to define if this is a product or service
     // issue : if we change product_type value in product DB it should differ from the value stored in facturedet DB !
     $objp->code_buy_l = '';
     $objp->code_buy_p = '';
     $objp->aarowid_suggest = '';
     $code_buy_p_l_differ = '';
     $code_buy_p_notset = '';
     $objp->aarowid_suggest = $objp->aarowid;
     if (!empty($objp->code_buy)) {
Example #11
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);
}
 /**
  *
  * @param unknown $object
  * @return boolean
  */
 static function checkContractFourn(&$object)
 {
     global $conf, $langs, $db;
     if (empty($conf->global->GRAPEFRUIT_CONTRACT_DEFAUL_FOURN) || $conf->global->GRAPEFRUIT_CONTRACT_DEFAUL_FOURN < 0) {
         return true;
     }
     dol_include_once('/fourn/class/fournisseur.product.class.php');
     foreach ($object->lines as &$line) {
         if (empty($line->fk_fournprice) && $line->fk_product > 0) {
             $p_static = new ProductFournisseur($db);
             $TPrice = $p_static->list_product_fournisseur_price($line->fk_product);
             foreach ($TPrice as &$price) {
                 if ($price->fourn_id == $conf->global->GRAPEFRUIT_CONTRACT_DEFAUL_FOURN) {
                     // TODO AA updateline sur contrat, là j'ai la flemme, no comment
                     $db->query("UPDATE " . MAIN_DB_PREFIX . "contratdet\n\t\t\t\t\t\tSET fk_product_fournisseur_price=" . $price->product_fourn_price_id . ",buy_price_ht=" . $price->fourn_price / $price->fourn_qty . "\n\t\t\t\t\t\tWHERE rowid=" . $line->id);
                     break;
                 }
             }
         }
     }
 }
 function import2Dolibarr($object, $typeimport)
 {
     global $conf;
     global $langs;
     $this->process_msg = '';
     $error = 0;
     $fp = @fopen($this->filename, "r");
     if ($fp) {
         switch ($object) {
             case 'ImportStock':
                 $doliprod = new Product($this->db);
                 $i = 0;
                 while ($ligne = fgetcsv($fp, 1000, ";")) {
                     $doliprod->id = '';
                     $i++;
                     if ($this->firstline && $i == 1) {
                         continue;
                     }
                     if ($conf->global->IMPORT_BARCODE) {
                         $ligne[0] = $this->get_product_by_barcode($ligne[0]);
                     }
                     if ($doliprod->fetch('', $ligne[0]) <= 0) {
                         $this->process_msg .= $langs->trans("ErrProdNoExist", $ligne[0], $doliprod->error) . "\n";
                     } else {
                         $pid = $doliprod->id;
                         $doliprod->ref = $ligne[0];
                         $entrepot = $ligne[1];
                         $newstock = $ligne[2];
                         $price = $ligne[3];
                         if ($conf->global->IMPORT_TOTAL_STOCK) {
                             $doliprod->load_stock();
                             dol_syslog("stock produit " . $doliprod->stock_warehouse[$entrepot]->real . " entrepot " . $entrepot . " " . $doliprod->stock_reel, LOG_DEBUG);
                             // correction de stock
                             $delta = 0;
                             if ($newstock > $doliprod->stock_warehouse[$entrepot]->real) {
                                 $delta = $newstock - $doliprod->stock_warehouse[$entrepot]->real;
                                 $sens = 0;
                             } elseif ($newstock < $doliprod->stock_warehouse[$entrepot]->real) {
                                 $delta = $doliprod->stock_warehouse[$entrepot]->real - $newstock;
                                 $sens = 1;
                             }
                             if ($delta) {
                                 $res = $doliprod->correct_stock($this->user, $entrepot, $delta, $sens, $langs->trans("StockCorrection"), $price);
                                 if ($res < 0) {
                                     $this->process_msg .= $langs->trans("ErrMovStock", $ligne[0], $doliprod->error) . "\n";
                                     $error++;
                                 }
                             }
                             dol_syslog("maj stock delta = " . $delta . " sens " . $sens, LOG_DEBUG);
                         } else {
                             $res = $doliprod->correct_stock($this->user, $entrepot, abs($newstock), $newstock > 0 ? 0 : 1, $langs->trans("StockCorrection"), $price);
                             if ($res < 0) {
                                 $this->process_msg .= $langs->trans("ErrMovStock", $ligne[0], $doliprod->error) . "\n";
                                 $error++;
                             }
                         }
                     }
                 }
                 break;
             case 'ImportProduct':
                 //$doliprod = new Product($this->db);
                 $i = 0;
                 while ($ligne = fgetcsv($fp, 1000, ";")) {
                     $i++;
                     $doliprod = new Product($this->db);
                     $doliprod->id = '';
                     if ($this->firstline && $i == 1) {
                         continue;
                     }
                     if ($doliprod->fetch('', $ligne[0]) < 0) {
                         $this->process_msg .= $langs->trans("ErrProdNoExist", $ligne[0], $doliprod->error) . "\n";
                     } else {
                         $pid = $doliprod->id;
                         $doliprod->ref = $ligne[0];
                         if (!empty($ligne[1])) {
                             $doliprod->libelle = $ligne[1];
                         }
                         if (!empty($ligne[2])) {
                             $doliprod->status = $ligne[2];
                         }
                         $doliprod->status_buy = 1;
                         if (!empty($ligne[3])) {
                             $doliprod->description = $ligne[3];
                         }
                         if (!empty($ligne[4])) {
                             $doliprod->price = $ligne[4];
                         }
                         if (!empty($ligne[5])) {
                             $doliprod->tva_tx = $ligne[5];
                         }
                         if (!empty($ligne[6])) {
                             $doliprod->weight = $ligne[6];
                         }
                         if (!empty($ligne[7])) {
                             $doliprod->volume = $ligne[7];
                         }
                         if (!empty($ligne[9])) {
                             $doliprod->barcode = $ligne[9];
                         }
                         if (!empty($ligne[9])) {
                             $doliprod->barcode_type = dol_getIdFromCode($this->db, $ligne[10], 'c_barcode_type', 'libelle', 'rowid');
                         }
                         if (!empty($ligne[10])) {
                             $doliprod->type = $ligne[11];
                         }
                         $doliprod->price_base_type = 'HT';
                         $this->db->begin;
                         switch ($typeimport) {
                             case 'C':
                                 if ($pid > 0) {
                                     if ($doliprod->update($pid, $this->user) < 0) {
                                         $this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error) . "\n";
                                         $error++;
                                     }
                                     if ($doliprod->updatePrice($doliprod->price, $doliprod->price_base_type, $this->user) < 0) {
                                         $this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error) . "\n";
                                         $error++;
                                     }
                                 } else {
                                     if ($doliprod->create($this->user) < 0) {
                                         $this->process_msg .= $langs->trans("ErrProductCreate", $ligne[0], $doliprod->error) . "\n";
                                         $error++;
                                     } else {
                                         // image et code barre
                                         if ($ligne[8]) {
                                             $this->add_photo_web($conf->produit->dir_output, $ligne[8], $doliprod->id);
                                         }
                                         /*if ($ligne[9]) {
                                         			if ($doliprod->setValueFrom('fk_barcode_type', 2) < 0){
                                         				$this->process_msg .= $langs->trans("ErrProductCreate", $ligne[0], $doliprod->error)."\n"; // TODO paramétrer
                                         				$error++;
                                         			}
                                         			if ($doliprod->setValueFrom('barcode', $ligne[9]) < 0 ){
                                         				$this->process_msg .= $langs->trans("ErrProductCreate", $ligne[0], $doliprod->error)."\n";
                                         				$error++;
                                         			}
                                         		}*/
                                     }
                                 }
                                 break;
                                 /*case 'M':
                                 		if ($pid>0) 
                                 		{
                                 			if ($doliprod->update($pid, $this->user) < 0){
                                 				$this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n";
                                 				$error++;
                                 			}
                                 			if (version_compare(DOL_VERSION, 3.5) >= 0){
                                 				if ($doliprod->updatePrice($doliprod->price, $doliprod->price_base_type, $this->user) < 0){
                                 					$this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n";
                                 					$error++;
                                 				}
                                 			}
                                 			else{
                                 				if ($doliprod->updatePrice($doliprod->id, $doliprod->price, $doliprod->price_base_type, $this->user) < 0){
                                 					$this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n";
                                 					$error++;
                                 				}
                                 			}
                                 		}
                                 		else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ErrProdNoExist", $ligne[0])."\n";
                                 		break;*/
                             /*case 'M':
                             		if ($pid>0) 
                             		{
                             			if ($doliprod->update($pid, $this->user) < 0){
                             				$this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n";
                             				$error++;
                             			}
                             			if (version_compare(DOL_VERSION, 3.5) >= 0){
                             				if ($doliprod->updatePrice($doliprod->price, $doliprod->price_base_type, $this->user) < 0){
                             					$this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n";
                             					$error++;
                             				}
                             			}
                             			else{
                             				if ($doliprod->updatePrice($doliprod->id, $doliprod->price, $doliprod->price_base_type, $this->user) < 0){
                             					$this->process_msg .= $langs->trans("ErrProductUpdate", $ligne[0], $doliprod->error)."\n";
                             					$error++;
                             				}
                             			}
                             		}
                             		else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ErrProdNoExist", $ligne[0])."\n";
                             		break;*/
                             case 'D':
                                 if ($pid > 0) {
                                     if ($doliprod->delete($pid) < 0) {
                                         $this->process_msg .= $langs->trans("ErrProductDelete", $ligne[0], $doliprod->error) . "\n";
                                         $error++;
                                     }
                                 } else {
                                     $this->process_msg .= $langs->trans("Untreated", $i) . ' ' . $langs->trans("ErrProdNoExist", $ligne[0]) . "\n";
                                 }
                         }
                         if (!$error) {
                             $this->db->commit();
                         } else {
                             $this->db->rollback();
                         }
                     }
                 }
                 // while
                 break;
             case 'ImportThirtdparty':
                 $i = 0;
                 //$societe = new Societe($this->db);
                 while ($ligne = fgetcsv($fp, 1000, ";")) {
                     $i++;
                     $societe = new Societe($this->db);
                     if ($this->firstline && $i == 1) {
                         continue;
                     }
                     if (!$ligne[0]) {
                         $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrNameRequired") . "\n";
                         continue;
                     }
                     // vérifier par code_client
                     if ($ligne[13]) {
                         $sid = $this->get_socbyclientcode($ligne[13]);
                     } else {
                         if ($ligne[14]) {
                             $sid = $this->get_socbysuplliercode($ligne[14]);
                         }
                     }
                     if ($sid > 0) {
                         $societe->fetch($sid);
                     } else {
                         $sid = $societe->fetch('', $ligne[0]);
                     }
                     if ($ligne[12]) {
                         $pid = dol_getIdFromCode($this->db, $ligne[12], "c_pays", "code", "rowid");
                     } else {
                         $pid = '';
                     }
                     if ($pid <= 0) {
                         $pid = '';
                     }
                     $did = '';
                     $societe->id = $sid;
                     $societe->name = $ligne[0];
                     $societe->particulier = 0;
                     //Société
                     $societe->address = $ligne[1] . "\n" . $ligne[2] . "\n" . $ligne[3];
                     $societe->zip = $ligne[4];
                     $societe->town = $ligne[5];
                     $societe->state_id = $did;
                     if ($ligne[12]) {
                         $societe->country_code = $ligne[12];
                     }
                     $societe->country_id = $pid;
                     dol_syslog("codes {$pid} " . $lige[12], LOG_DEBUG);
                     $societe->phone = $ligne[6];
                     $societe->fax = $ligne[7];
                     $societe->email = $ligne[8];
                     $societe->url = $ligne[9];
                     $societe->idprof1 = $ligne[10];
                     switch ($ligne[11]) {
                         case '0':
                             $societe->fournisseur = 0;
                             $societe->client = $ligne[11];
                             break;
                         case '1':
                             $societe->fournisseur = 0;
                             $societe->client = $ligne[11];
                             break;
                         case '2':
                             $societe->fournisseur = 0;
                             $societe->client = $ligne[11];
                             break;
                         case '10':
                             $societe->client = 0;
                             $societe->fournisseur = 1;
                             break;
                         default:
                             break;
                     }
                     if ($ligne[13]) {
                         $societe->code_client = $ligne[13];
                     }
                     if ($ligne[14]) {
                         $societe->code_fournisseur = $ligne[14];
                     }
                     /*if ($ligne[15]) $societe->array_options["options_zone"]=$ligne[15];
                     				if (!empty($ligne[16])) $societe->array_options["options_CA"]=$ligne[16];
                     
                     				if (!empty($ligne[17]))
                     				{
                     					   if ($ligne[17] <= 5) $societe->effectif_id = 1;
                     					   elseif ($ligne[17] <= 10) $societe->effectif_id = 2;
                     					   elseif ($ligne[17] <= 50) $societe->effectif_id = 3;
                     					   elseif ($ligne[17] <= 100) $societe->effectif_id = 4;
                     					   elseif ($ligne[17] <= 500) $societe->effectif_id = 5;
                     					   else $societe->effectif_id = 7;
                     				}
                     				dol_syslog("effectif " . $lige[17].'  '.$societe->effectif_id." ".print_r($societe->array_options, true), LOG_DEBUG);*/
                     $this->db->begin;
                     switch ($typeimport) {
                         case 'C':
                             if ($sid > 0) {
                                 if ($societe->update($sid, $this->user) < 0) {
                                     $this->process_msg .= $langs->trans("ErrCompanyUpdate", $ligne[0], $societe->error) . "\n";
                                     $error++;
                                 }
                             } elseif ($societe->create($this->user) < 0) {
                                 $this->process_msg .= $langs->trans("ErrCompanyCreate", $ligne[0], $societe->error) . "\n";
                                 $error++;
                             }
                             break;
                             /*case 'M':
                             		if ($sid>0) 
                             		{
                             			if ($societe->update($sid, $this->user) < 0){
                             				$this->process_msg .= $langs->trans("ErrCompanyUpdate", $ligne[0], $societe->error)."\n";
                             				$error++;
                             			}
                             		}
                             		else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("CompanyNoExist", $ligne[0])."\n";
                             		break;*/
                         /*case 'M':
                         		if ($sid>0) 
                         		{
                         			if ($societe->update($sid, $this->user) < 0){
                         				$this->process_msg .= $langs->trans("ErrCompanyUpdate", $ligne[0], $societe->error)."\n";
                         				$error++;
                         			}
                         		}
                         		else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("CompanyNoExist", $ligne[0])."\n";
                         		break;*/
                         case 'D':
                             if ($sid > 0) {
                                 if ($societe->delete($sid) < 0) {
                                     $this->process_msg .= $langs->trans("ErrCompanyDelete", $ligne[0], $societe->error) . "\n";
                                     $error++;
                                 }
                             } else {
                                 $this->process_msg .= $langs->trans("Untreated", $i) . ' ' . $langs->trans("CompanyNoExist", $ligne[0]) . "\n";
                             }
                     }
                     if (!$error) {
                         $this->db->commit();
                     } else {
                         $this->db->rollback();
                     }
                 }
                 break;
             case 'ImportContact':
                 $i = 0;
                 //$contact=new Contact($this->db);
                 //$societe = new Societe($this->db);
                 while ($ligne = fgetcsv($fp, 1000, ";")) {
                     $i++;
                     $contact = new Contact($this->db);
                     $societe = new Societe($this->db);
                     if ($this->firstline && $i == 1) {
                         continue;
                     }
                     //if ($societe->fetch('',$ligne[0]) < 0 ) $this->process_msg .= "erreur lecture Société "."\n";
                     if ($ligne[0]) {
                         $socid = $this->get_socbyclientcode($ligne[0]);
                     } else {
                         if ($ligne[1]) {
                             $socid = $this->get_socbysuplliercode($ligne[1]);
                         }
                     }
                     if ($socid < 0) {
                         $this->process_msg .= $i . " " . $langs->trans("ErrCompanyRequired") . "\n";
                     } else {
                         $societe->fetch($socid);
                     }
                     if (!$societe->id) {
                         $this->process_msg .= $langs->trans("ErrCompanyNoExist", $ligne[0] . " " . $ligne[1]) . "\n";
                         continue;
                     }
                     if (empty($ligne[2])) {
                         $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrNameRequired") . "\n";
                         continue;
                     }
                     $contactid = $this->get_contact_id($socid, $ligne[2], $ligne[3]);
                     $contact->id = $contactid;
                     $contact->civilite_id = $ligne[4];
                     $contact->lastname = $ligne[2];
                     $contact->firstname = $ligne[3];
                     if ($ligne[5] || $ligne[6] || $ligne[7]) {
                         $contact->address = $ligne[5] . "\n" . $ligne[6] . "\n" . $ligne[7];
                     } else {
                         $contact->address = $societe->address;
                     }
                     if ($ligne[8]) {
                         $contact->zip = $ligne[8];
                     } else {
                         $contact->zip = $societe->zip;
                     }
                     if ($ligne[9]) {
                         $contact->town = $ligne[9];
                     } else {
                         $contact->town = $societe->town;
                     }
                     if ($ligne[10]) {
                         $pid = dol_getIdFromCode($this->db, $ligne[10], "c_pays", "code", "rowid");
                         if ($pid <= 0) {
                             $pid = '';
                         }
                         $contact->country_id = $pid;
                         $contact->country_code = $ligne[10];
                     } else {
                         $contact->country_id = $societe->country_id;
                         $contact->country_code = $societe->country_code;
                     }
                     $contact->socid = $socid;
                     // fk_soc
                     $contact->status = 1;
                     $contact->email = $ligne[11];
                     $contact->phone_pro = $ligne[12];
                     $contact->fax = $ligne[13];
                     $contact->phone_mobile = $ligne[14];
                     $contact->priv = 0;
                     $this->db - begin;
                     switch ($typeimport) {
                         case 'C':
                             if ($contactid > 0) {
                                 if ($contact->update($contactid, $this->user) < 0) {
                                     $this->process_msg .= $langs->trans("ErrContactUpdate", $ligne[2], $contact->error) . "\n";
                                     $error++;
                                 }
                             } elseif ($contact->create($this->user) < 0) {
                                 $this->process_msg .= $langs->trans("ErrContactCreate", $ligne[2], $contact->error) . "\n";
                                 $error++;
                             }
                             break;
                             /*case 'M':
                             		if ($contactid>0) 
                             		{
                             			if ($contact->update($contactid, $this->user) < 0){
                             				$this->process_msg .= $langs->trans("ErrContactUpdate", $ligne[2], $contact->error)."\n";
                             				$error++;
                             			}
                             		}
                             		else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ContactNoExist", $ligne[2])."\n";
                             		break;*/
                         /*case 'M':
                         		if ($contactid>0) 
                         		{
                         			if ($contact->update($contactid, $this->user) < 0){
                         				$this->process_msg .= $langs->trans("ErrContactUpdate", $ligne[2], $contact->error)."\n";
                         				$error++;
                         			}
                         		}
                         		else $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ContactNoExist", $ligne[2])."\n";
                         		break;*/
                         case 'D':
                             if ($contactid > 0) {
                                 if ($contact->delete($contactid) < 0) {
                                     $this->process_msg .= $langs->trans("ErrContactDelete", $ligne[2], $contact->error) . "\n";
                                     $error++;
                                 }
                             } else {
                                 $this->process_msg .= $langs->trans("Untreated", $i) . ' ' . $langs->trans("ContactNoExist", $ligne[2]) . "\n";
                             }
                     }
                     if (!$error) {
                         $this->db->commit();
                     } else {
                         $this->db->rollback();
                     }
                 }
                 break;
                 /*case 'ImportActions':
                 			$i=0;
                 			$contact=new Contact($this->db);
                 			$societe = new Societe($this->db);
                 			$actioncomm = new ActionComm($this->db);
                 			$actuser = new User($this->db);
                 			
                 			while ($ligne = fgetcsv($fp,1000,";"))
                 			{
                 				$i++;
                 				if ($this->firstline && $i== 1) continue;
                 				
                 				//if ($societe->fetch('',$ligne[0]) < 0 ) $this->process_msg .= "erreur lecture Société "."\n";
                 				//else $socid = $societe->id;
                 				$socid = $this->get_socbyclientcode($ligne[0]);
                 				if ($socid < 0 ) $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ErrCompanyRequired")."\n";
                 				else $societe->fetch($socid);
                 				$socid = $societe->id;
                 				
                 				if (!$socid) 
                 				{
                 					$this->process_msg .= $langs->trans("ErrCompanyNoExist", $ligne[0])."\n";
                 					continue;
                 				}
                 								
                 				//action sur un contact de la soc
                 				if ($ligne[1])
                 				{
                 					$contactid = $this->get_contact_id($socid, $ligne[1], $ligne[2]) ;
                 					
                 					if ($contactid < 0) {
                 						$this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ContactNoExist", $ligne[1].' '. $ligne[2])."\n";
                 						// réinitialiser ??
                 						continue;
                 					}
                 					else $contact->fetch($contactid);
                 					
                 				}
                 				
                 
                 				$usertodo = '';
                 				if ($ligne[9])
                 				{
                 					$usertodo=new User($this->db);
                 					if ( $usertodo->fetch('',$ligne[9]) < 0 ) $this->process_msg .= $langs->trans("ErrUserNoExist", $ligne[9])."\n";
                 				}
                 				$userdone= '' ;
                 				if ($ligne[10])
                 				{
                 					$usertodo=new User($this->db);
                 					if ( $usertodo->fetch('',$ligne[10]) < 0 ) $this->process_msg .= $langs->trans("ErrUserNoExist", $ligne[10])."\n";
                 					
                 				}
                 				$datep = '';
                 				if ($ligne[6])
                 				{
                 					// voir date
                 					$n = sscanf($ligne[6],"%02d/%02d/%04d", $d_day, $d_mon, $d_year);
                 					if ($n==3) $datep=dol_mktime(12, 0, 0, $d_mon, $d_day, $d_year);
                 					if (!$datep) $this->process_msg .= $langs->trans("ErrDateConversion", $ligne[6])."\n";
                 				}
                 				else $datep ='';
                 				$datef='';
                 				if ($ligne[7])
                 				{
                 					// voir la date
                 					$n = sscanf($ligne[7],"%02d/%02d/%04d", $d_day, $d_mon, $d_year);
                 					if ($n==3)$datef=dol_mktime(12, 0, 0, $d_mon, $d_day, $d_year);
                 					if (!$datef) $this->process_msg .= $langs->trans("ErrDateConversion", $ligne[7])."\n";
                 				}
                 				else $datef ='';
                 				//$datef='';
                 				$actioncomm->societe = $societe;
                 				if ($ligne[1]) $actioncomm->contact = $contact;
                 				else $actioncomm->contact = '';
                 				$actioncomm->type_code = $ligne[3];
                 				$actioncomm->priority = $ligne[4];
                 				$actioncomm->location = '' ;
                 				$actioncomm->label = $ligne[5];
                 				$actioncomm->datep = $datep;
                 				$actioncomm->datef = $datef;
                 				$actioncomm->percentage = $ligne[8];
                 				$actioncomm->usertodo = $usertodo;
                 				$actioncomm->userdone = $userdone;
                 				$actioncomm->note =$ligne[11];
                 				
                 				switch ($typeimport)
                 				{					
                 				case 'C':
                 					$this->db->begin();
                 					if ($actioncomm->add($this->user) < 0) 
                 					{ 
                 						$this->process_msg .= $langs->trans("ErrActionCreate", $ligne[5], $actioncomm->error)."\n";
                 						$this->db->rollback();
                 					}
                 					else $this->db->commit();
                 					break;
                 				case 'M':
                 					$this->db->begin();
                 					if($actioncomm->update($user) < 0){
                 						$this->process_msg .= $langs->trans("ErrActionUpdate", $ligne[5], $actioncomm->error)."\n";
                 						$this->db->rollback();
                 					}
                 					else $this->db->commit();
                 					break;
                 				case 'D':
                 					$this->db->begin();
                 					if($actioncomm->delete() < 0){
                 						$this->process_msg .= $langs->trans("ErrActionDelete", $ligne[5], $actioncomm->error)."\n";
                 						$this->db->rollback();
                 					}
                 					else $this->db->commit();
                 					break;
                 				}
                 			}
                 				
                 			break;*/
             /*case 'ImportActions':
             			$i=0;
             			$contact=new Contact($this->db);
             			$societe = new Societe($this->db);
             			$actioncomm = new ActionComm($this->db);
             			$actuser = new User($this->db);
             			
             			while ($ligne = fgetcsv($fp,1000,";"))
             			{
             				$i++;
             				if ($this->firstline && $i== 1) continue;
             				
             				//if ($societe->fetch('',$ligne[0]) < 0 ) $this->process_msg .= "erreur lecture Société "."\n";
             				//else $socid = $societe->id;
             				$socid = $this->get_socbyclientcode($ligne[0]);
             				if ($socid < 0 ) $this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ErrCompanyRequired")."\n";
             				else $societe->fetch($socid);
             				$socid = $societe->id;
             				
             				if (!$socid) 
             				{
             					$this->process_msg .= $langs->trans("ErrCompanyNoExist", $ligne[0])."\n";
             					continue;
             				}
             								
             				//action sur un contact de la soc
             				if ($ligne[1])
             				{
             					$contactid = $this->get_contact_id($socid, $ligne[1], $ligne[2]) ;
             					
             					if ($contactid < 0) {
             						$this->process_msg .= $langs->trans("Untreated", $i).' '.$langs->trans("ContactNoExist", $ligne[1].' '. $ligne[2])."\n";
             						// réinitialiser ??
             						continue;
             					}
             					else $contact->fetch($contactid);
             					
             				}
             				
             
             				$usertodo = '';
             				if ($ligne[9])
             				{
             					$usertodo=new User($this->db);
             					if ( $usertodo->fetch('',$ligne[9]) < 0 ) $this->process_msg .= $langs->trans("ErrUserNoExist", $ligne[9])."\n";
             				}
             				$userdone= '' ;
             				if ($ligne[10])
             				{
             					$usertodo=new User($this->db);
             					if ( $usertodo->fetch('',$ligne[10]) < 0 ) $this->process_msg .= $langs->trans("ErrUserNoExist", $ligne[10])."\n";
             					
             				}
             				$datep = '';
             				if ($ligne[6])
             				{
             					// voir date
             					$n = sscanf($ligne[6],"%02d/%02d/%04d", $d_day, $d_mon, $d_year);
             					if ($n==3) $datep=dol_mktime(12, 0, 0, $d_mon, $d_day, $d_year);
             					if (!$datep) $this->process_msg .= $langs->trans("ErrDateConversion", $ligne[6])."\n";
             				}
             				else $datep ='';
             				$datef='';
             				if ($ligne[7])
             				{
             					// voir la date
             					$n = sscanf($ligne[7],"%02d/%02d/%04d", $d_day, $d_mon, $d_year);
             					if ($n==3)$datef=dol_mktime(12, 0, 0, $d_mon, $d_day, $d_year);
             					if (!$datef) $this->process_msg .= $langs->trans("ErrDateConversion", $ligne[7])."\n";
             				}
             				else $datef ='';
             				//$datef='';
             				$actioncomm->societe = $societe;
             				if ($ligne[1]) $actioncomm->contact = $contact;
             				else $actioncomm->contact = '';
             				$actioncomm->type_code = $ligne[3];
             				$actioncomm->priority = $ligne[4];
             				$actioncomm->location = '' ;
             				$actioncomm->label = $ligne[5];
             				$actioncomm->datep = $datep;
             				$actioncomm->datef = $datef;
             				$actioncomm->percentage = $ligne[8];
             				$actioncomm->usertodo = $usertodo;
             				$actioncomm->userdone = $userdone;
             				$actioncomm->note =$ligne[11];
             				
             				switch ($typeimport)
             				{					
             				case 'C':
             					$this->db->begin();
             					if ($actioncomm->add($this->user) < 0) 
             					{ 
             						$this->process_msg .= $langs->trans("ErrActionCreate", $ligne[5], $actioncomm->error)."\n";
             						$this->db->rollback();
             					}
             					else $this->db->commit();
             					break;
             				case 'M':
             					$this->db->begin();
             					if($actioncomm->update($user) < 0){
             						$this->process_msg .= $langs->trans("ErrActionUpdate", $ligne[5], $actioncomm->error)."\n";
             						$this->db->rollback();
             					}
             					else $this->db->commit();
             					break;
             				case 'D':
             					$this->db->begin();
             					if($actioncomm->delete() < 0){
             						$this->process_msg .= $langs->trans("ErrActionDelete", $ligne[5], $actioncomm->error)."\n";
             						$this->db->rollback();
             					}
             					else $this->db->commit();
             					break;
             				}
             			}
             				
             			break;*/
             case 'Importtarif':
                 // ref four
                 $i = 0;
                 $this->process_msg = '';
                 $error = 0;
                 /*$doliprod = new Product($this->db);
                 		$product = new ProductFournisseur($this->db);
                 		$societe = new Societe($this->db);*/
                 while ($ligne = fgetcsv($fp, 1000, ";")) {
                     $doliprod->id = '';
                     $i++;
                     $doliprod = new Product($this->db);
                     $product = new ProductFournisseur($this->db);
                     $societe = new Societe($this->db);
                     if ($this->firstline && $i == 1) {
                         continue;
                     }
                     // recherche du fournisseur
                     if ($societe->fetch('', $ligne[2]) > 0) {
                         $sid = $societe->id;
                     } else {
                         $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrComppanyNoExist", $ligne[2]) . "\n";
                         $sid = '';
                     }
                     if ($doliprod->fetch('', $ligne[0]) > 0) {
                         $pid = $doliprod->id;
                     } else {
                         $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrProductNoExist", $ligne[0], $doliprod->error) . "\n";
                         $pid = '';
                     }
                     if ($sid > 0 && $pid > 0) {
                         $result = $product->fetch($doliprod->id);
                         if ($result > 0) {
                             $this->db->begin();
                             switch ($typeimport) {
                                 case 'C':
                                     $ret = $product->add_fournisseur($this->user, $sid, $ligne[1], $ligne[3]);
                                     if ($ret < 0 && $ret != -3) {
                                         $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrCreatePrice", $product->error) . "\n";
                                         $error++;
                                     }
                                     $ret = $product->update_buyprice($ligne[3], $ligne[4], $this->user, 'HT', $supplier, '', $ligne[1], $ligne[5]);
                                     if ($ret < 0 && $ret != -3) {
                                         $this->process_msg .= $langs->trans("Untreated", $i) . " " . $langs->trans("ErrCreatePrice", $product->error) . "\n";
                                         $error++;
                                     }
                                     break;
                                     /*case 'M':
                                     		{
                                     			// gestion du prix obligatoire
                                     			$supplier=new Fournisseur($this->db);
                                     			$result=$supplier->fetch($sid);
                                     			
                                     			$ret=$product->update_buyprice($ligne[3], $ligne[4] , $this->user, 'HT', $supplier, '', $ligne[1], $ligne[5] );
                                     			if ($ret < 0)
                                     			{
                                     				$this->process_msg .= $langs->trans("Untreated", $i)." ".$langs->trans("Qty").$ligne[3]. ", ".$langs->trans("Price").$ligne[4]." ".$langs->trans("ErrUpdatePrice", $product->error)."\n";
                                     				$error ++;
                                     			}
                                     			
                                     		}
                                     		break;*/
                                 /*case 'M':
                                 		{
                                 			// gestion du prix obligatoire
                                 			$supplier=new Fournisseur($this->db);
                                 			$result=$supplier->fetch($sid);
                                 			
                                 			$ret=$product->update_buyprice($ligne[3], $ligne[4] , $this->user, 'HT', $supplier, '', $ligne[1], $ligne[5] );
                                 			if ($ret < 0)
                                 			{
                                 				$this->process_msg .= $langs->trans("Untreated", $i)." ".$langs->trans("Qty").$ligne[3]. ", ".$langs->trans("Price").$ligne[4]." ".$langs->trans("ErrUpdatePrice", $product->error)."\n";
                                 				$error ++;
                                 			}
                                 			
                                 		}
                                 		break;*/
                                 case 'D':
                                     // suprresion de la ligne avec le même nb d'article et le même prix
                                     $sql = "SELECT pfp.rowid FROM " . MAIN_DB_PREFIX . "product_fournisseur_price as pfp";
                                     $sql .= " WHERE pfp.quantity = '" . $ligne[3] . "' AND pfp.ref_fourn = '" . $ligne[1];
                                     $sql .= "' AND pfp.fk_soc = '" . $sid . "' AND pfp.fk_product='" . $pid . "'";
                                     $sql .= " AND pfp.entity = " . $conf->entity;
                                     $resql = $this->db->query($sql);
                                     if ($resql) {
                                         $obj = $this->db->fetch_object($resql);
                                         if ($obj->rowid > 0) {
                                             $result = $product->remove_product_fournisseur_price($obj->rowid);
                                         } else {
                                             $this->process_msg .= $langs->trans("Untreated", $i) . ' ' . $langs->trans("ErrDeletePrice", $product->error) . "\n";
                                             $error++;
                                         }
                                     } else {
                                         $this->process_msg .= "Error SQL= " . $sql . "\n";
                                         $error++;
                                     }
                                     break;
                             }
                             //switch
                         }
                         if (!$error) {
                             $this->db->commit();
                         } else {
                             $this->db->rollback();
                         }
                     }
                     // fournisseur trouvé
                 }
                 // traitement ligne
                 // while reffour
                 break;
         }
         // fin switch
         fclose($fp);
     } else {
         $this->error = $langs->trans("ErrOpenFile") . $nomfich;
         $error = -1;
     }
     return $error;
 }
     print '<td align="right" class="nowrap"><input size="4" name="puttc" type="text" value=""></td>';
     print '<td align="right"><input size="1" name="qty" type="text" value="' . $object->lines[$i]->qty . '"></td>';
     print '<td align="right" class="nowrap"><input size="1" name="remise_percent" type="text" value="' . $object->lines[$i]->remise_percent . '"><span class="hideonsmartphone">%</span></td>';
     print '<td align="right" class="nowrap">&nbsp;</td>';
     print '<td align="right" class="nowrap">&nbsp;</td>';
     print '<td align="center" colspan="2"><input type="submit" class="button" name="save" value="' . $langs->trans('Save') . '">';
     print '<br><input type="submit" class="button" name="cancel" value="' . $langs->trans('Cancel') . '"></td>';
     print '</tr>';
 } else {
     print '<tr id="row-' . $object->lines[$i]->rowid . '" ' . $bc[$var] . '>';
     // Show product and description
     print '<td>';
     if ($object->lines[$i]->fk_product) {
         print '<a name="' . $object->lines[$i]->rowid . '"></a>';
         // ancre pour retourner sur la ligne
         $product_static = new ProductFournisseur($db);
         $product_static->fetch($object->lines[$i]->fk_product);
         $text = $product_static->getNomUrl(1);
         $text .= ' - ' . $product_static->libelle;
         $description = $conf->global->PRODUIT_DESC_IN_FORM ? '' : dol_htmlentitiesbr($object->lines[$i]->description);
         print $form->textwithtooltip($text, $description, 3, '', '', $i);
         // Show range
         print_date_range($date_start, $date_end);
         // Add description in form
         if (!empty($conf->global->PRODUIT_DESC_IN_FORM)) {
             print $object->lines[$i]->description && $object->lines[$i]->description != $product_static->libelle ? '<br>' . dol_htmlentitiesbr($object->lines[$i]->description) : '';
         }
     }
     // Description - Editor wysiwyg
     if (!$object->lines[$i]->fk_product) {
         if ($type == 1) {
         print '</a></td>';
     } else {
         print '<td>&nbsp;</td><td>&nbsp;</td>';
     }
     print "</tr>";
 }
 // Edit line
 if ($action == 'edit_line' && $user->rights->fournisseur->commande->creer && $_GET["rowid"] == $line->id) {
     print "\n";
     print '<tr ' . $bc[$var] . '>';
     print '<td>';
     print '<input type="hidden" name="elrowid" value="' . $_GET['rowid'] . '">';
     print '<a name="' . $line->id . '"></a>';
     // ancre pour retourner sur la ligne
     if ((!empty($conf->product->enabled) || !empty($conf->service->enabled)) && $line->fk_product > 0) {
         $product_static = new ProductFournisseur($db);
         $product_static->fetch_opt($line->fk_product);
         $text = $product_static->getNomUrl(1, 'supplier');
         $text .= ' - ' . $product_static->libelle;
         $description = $conf->global->PRODUIT_DESC_IN_FORM ? '' : dol_htmlentitiesbr($line->description);
         print $form->textwithtooltip($text, $description, 3, '', '', $i);
         // Show range
         print_date_range($date_start, $date_end);
         print '<br>';
     } else {
         $forceall = 1;
         // For suppliers, we always show all types
         print $form->select_type_of_lines($line->product_type, 'type', 1, 0, $forceall);
         if ($forceall || !empty($conf->product->enabled) && !empty($conf->service->enabled) || empty($conf->product->enabled) && empty($conf->service->enabled)) {
             print '<br>';
         }
<?php

require "../config.php";
dol_include_once('/product/class/product.class.php');
dol_include_once('/fourn/class/fournisseur.product.class.php');
$get = GETPOST('get');
$put = GETPOST('put');
switch ($put) {
    case 'updateprice':
        ob_start();
        $product = new ProductFournisseur($db);
        $id_prod = (int) GETPOST('idprod');
        $ref_search = GETPOST('ref_search');
        $product->fetch($id_prod, $ref_search);
        $npr = preg_match('/\\*/', GETPOST('tvatx')) ? 1 : 0;
        $fourn = new Fournisseur($db);
        $fourn->fetch(GETPOST('fk_supplier'));
        $ret = $product->update_buyprice(GETPOST('qty'), GETPOST("price"), $user, 'HT', $fourn, 1, GETPOST('ref'), GETPOST('tvatx'), 0, 0, 0);
        $res = $db->query("SELECT MAX(rowid) as 'rowid' FROM " . MAIN_DB_PREFIX . "product_fournisseur_price WHERE fk_product=" . $product->id);
        $obj = $db->fetch_object($res);
        ob_clean();
        if ($ret != 0) {
            print json_encode(array('id' => $ret, 'error' => $product->error));
        } else {
            print json_encode(array('id' => $obj->rowid, 'error' => '', 'dp_desc' => $product->description));
        }
        break;
}
	/**
     *	Add or update supplier price according to result of proposal
     *
	 *	@param     User	    $user       Object user
	 *  @return    int                  > 0 if OK
     */
	function updateOrCreatePriceFournisseur($user)
	{
		$productsupplier = new ProductFournisseur($this->db);

		dol_syslog(get_class($this)."::updateOrCreatePriceFournisseur", LOG_DEBUG);
		foreach ($this->lines as $product) 
		{
			if ($product->subprice <= 0) continue;

			$idProductFourn = $productsupplier->find_min_price_product_fournisseur($product->fk_product, $product->qty);
			$res = $productsupplier->fetch($idProductFourn);

			if ($productsupplier->id) {
				if ($productsupplier->fourn_qty == $product->qty) {
					$this->updatePriceFournisseur($productsupplier->product_fourn_price_id, $product, $user);
				} else {
					$this->createPriceFournisseur($product, $user);
				}
			} else {
				$this->createPriceFournisseur($product, $user);
			}
		}
		
		return 1;
	}
Example #18
0
     if ($status_code != "OK") {
         if ($status_code == "NOT_FOUND") {
             setEventMessages($line_id . $langs->trans("SupplierMissingRef") . " '" . $ref_supplier . "'", null, 'warnings');
         } else {
             setEventMessages($line_id . $langs->trans("ResponseNonOK") . " '" . $status_code . "' - '" . $result_product["result"]["result_label"] . "'", null, 'errors');
             $error_occurred = true;
             break;
         }
     }
 }
 // Ensure that price is equal and warn user if it's not
 $supplier_price = price($result_product["product"]["price_net"]);
 //Price of client tab in supplier dolibarr
 $local_price = NULL;
 //Price of supplier as stated in product suppliers tab on this dolibarr, NULL if not found
 $product_fourn = new ProductFournisseur($db);
 $product_fourn_list = $product_fourn->list_product_fournisseur_price($line->fk_product);
 if (count($product_fourn_list) > 0) {
     foreach ($product_fourn_list as $product_fourn_line) {
         //Only accept the line where the supplier is the same at this order and has the same ref
         if ($product_fourn_line->fourn_id == $object->socid && $product_fourn_line->fourn_ref == $ref_supplier) {
             $local_price = price($product_fourn_line->fourn_price);
         }
     }
 }
 if ($local_price != NULL && $local_price != $supplier_price) {
     setEventMessages($line_id . $langs->trans("RemotePriceMismatch") . " " . $supplier_price . " - " . $local_price, null, 'warnings');
 }
 // Check if is in sale
 if (empty($result_product["product"]["status_tosell"])) {
     setEventMessages($line_id . $langs->trans("ProductStatusNotOnSellShort") . " '" . $ref_supplier . "'", null, 'warnings');
Example #19
0
if (!defined('NOREQUIRESOC')) {
    define('NOREQUIRESOC', '1');
}
//if (! defined('NOREQUIRETRAN'))  define('NOREQUIRETRAN','1');
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php';
$idprod = GETPOST('idprod', 'int');
$prices = array();
$langs->load('stocks');
/*
 * View
 */
top_httphead();
//print '<!-- Ajax page called with url '.$_SERVER["PHP_SELF"].'?'.$_SERVER["QUERY_STRING"].' -->'."\n";
if ($idprod > 0) {
    $producttmp = new ProductFournisseur($db);
    $producttmp->fetch($idprod);
    $sorttouse = 's.nom, pfp.quantity, pfp.price';
    if (GETPOST('bestpricefirst')) {
        $sorttouse = 'pfp.unitprice, s.nom, pfp.quantity, pfp.price';
    }
    $productSupplierArray = $producttmp->list_product_fournisseur_price($idprod, $sorttouse);
    // We list all price per supplier, and then firstly with the lower quantity. So we can choose first one with enough quantity into list.
    if (is_array($productSupplierArray)) {
        foreach ($productSupplierArray as $productSupplier) {
            $price = $productSupplier->fourn_price * (1 - $productSupplier->fourn_remise_percent / 100);
            $unitprice = $productSupplier->fourn_unitprice * (1 - $productSupplier->fourn_remise_percent / 100);
            $title = $productSupplier->fourn_name . ' - ' . $productSupplier->fourn_ref . ' - ';
            if ($productSupplier->fourn_qty == 1) {
                $title .= price($price, 0, $langs, 0, 0, -1, $conf->currency) . "/";
            }
Example #20
0
	Header('Location :fourn.php?id='.$product->id.'&id_fourn='.$_GET["id_fourn"]);
}



llxHeader("","",$langs->trans("CardProduct0"));

/*
 * Fiche produit
 */
if ($_GET["id"])
{
	if ($_GET["action"] <> 're-edit')
	{
		$product = new ProductFournisseur($db);
		$result = $product->fetch($_GET["id"], $_GET["id_fourn"]);
		$product->get_buyprice($_GET["id_fourn"],1);
	}

	if ( $result == 0)
	{


		/*
		 *  En mode visu
		 */

		$h=0;

		$head[$h][0] = DOL_URL_ROOT."/fourn/product/fiche.php?id=".$product->id;
 /**
  * Return the max number delivery delay in day
  *
  * @param	Translate	$langs		Language object
  * @return 							Translated string
  */
 function getMaxDeliveryTimeDay($langs)
 {
     if (empty($this->lines)) {
         return '';
     }
     $obj = new ProductFournisseur($this->db);
     $nb = 0;
     foreach ($this->lines as $line) {
         if ($line->fk_product > 0) {
             $idp = $obj->find_min_price_product_fournisseur($line->fk_product, $line->qty);
             if ($idp) {
                 $obj->fetch($idp);
                 if ($obj->delivery_time_days > $nb) {
                     $nb = $obj->delivery_time_days;
                 }
             }
         }
     }
     if ($nb === 0) {
         return '';
     } else {
         return $nb . ' ' . $langs->trans('Days');
     }
 }
Example #22
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);
}
Example #23
0
require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
require_once DOL_DOCUMENT_ROOT . '/core/lib/product.lib.php';
require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.product.class.php';
$langs->load("admin");
$langs->load("products");
// Security check
if (!$user->admin) {
    accessforbidden();
}
$action = GETPOST('action', 'alpha');
$oldvatrate = GETPOST('oldvatrate');
$newvatrate = GETPOST('newvatrate');
//$price_base_type=GETPOST('price_base_type');
$objectstatic = new Product($db);
$objectstatic2 = new ProductFournisseur($db);
/*
 * Actions
 */
if ($action == 'convert') {
    $error = 0;
    if ($oldvatrate == $newvatrate) {
        $langs->load("errors");
        setEventMessage($langs->trans("ErrorNewValueCantMatchOldValue"), 'errors');
        $error++;
    }
    if (!$error) {
        $country_id = $mysoc->country_id;
        // TODO Allow to choose country into form
        $nbrecordsmodified = 0;
        $db->begin();
Example #24
0
				print '<tr class="liste_titre">';
				print_liste_field_titre($langs->trans("Suppliers"),$_SERVER["PHP_SELF"],"s.nom","",$param,"",$sortfield,$sortorder);
				print '<td class="liste_titre">'.$langs->trans("SupplierRef").'</td>';
				if (!empty($conf->global->FOURN_PRODUCT_AVAILABILITY)) print_liste_field_titre($langs->trans("Availability"),$_SERVER["PHP_SELF"],"pfp.fk_availability","",$param,"",$sortfield,$sortorder);
				print_liste_field_titre($langs->trans("QtyMin"),$_SERVER["PHP_SELF"],"pfp.quantity","",$param,'align="right"',$sortfield,$sortorder);
				print '<td class="liste_titre" align="right">'.$langs->trans("VATRate").'</td>';
				print '<td class="liste_titre" align="right">'.$langs->trans("PriceQtyMinHT").'</td>';
				// Charges ????
				if (! empty($conf->margin->enabled)) print '<td align="right">'.$langs->trans("Charges").'</td>';
				print_liste_field_titre($langs->trans("UnitPriceHT"),$_SERVER["PHP_SELF"],"pfp.unitprice","",$param,'align="right"',$sortfield,$sortorder);
				// Charges ????
				if (! empty($conf->margin->enabled)) print '<td align="right">'.$langs->trans("UnitCharges").'</td>';
				print '<td class="liste_titre"></td>';
				print "</tr>\n";

				$product_fourn = new ProductFournisseur($db);
				$product_fourn_list = $product_fourn->list_product_fournisseur_price($product->id);

				if (count($product_fourn_list)>0)
				{
					$var=true;

					foreach($product_fourn_list as $productfourn)
					{
						$var=!$var;

						print "<tr ".$bc[$var].">";

						print '<td>'.$productfourn->getSocNomUrl(1).'</td>';

						// Supplier
Example #25
0
	exit;
}



/*
 * view
 */

$html = new Form($db);

if ($_GET["id"] || $_GET["ref"])
{
	if ($_GET["action"] <> 're-edit')
	{
		$product = new ProductFournisseur($db);
		$result = $product->fetch($_GET["id"],$_GET["ref"]);
		$result = $product->fetch_fourn_data($_REQUEST["id_fourn"]);
		//print 'eeeee'.$_GET["socid"];exit;
		llxHeader("","",$langs->trans("CardProduct".$product->type));
	}

	if ( $result )
	{

		if ($_GET["action"] <> 'edit' && $_GET["action"] <> 're-edit')
		{
			/*
			 *  En mode visu
			 */
Example #26
0
	function ProductCommande($user, $fk_product)
	{
		include_once(DOL_DOCUMENT_ROOT."/fourn/fournisseur.commande.class.php");
		include_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");

		$commf = new CommandeFournisseur($this->db);

		$nbc = $this->nb_open_commande();

		dol_syslog("Fournisseur::ProductCommande : nbc = ".$nbc);

		if ($nbc == 0)
		{
			if ( $this->create_commande($user) == 0 )
			{
				$idc = $this->single_open_commande;
			}
		}
		elseif ($nbc == 1)
		{

			$idc = $this->single_open_commande;
		}

		if ($idc > 0)
		{
			$prod = new ProductFournisseur($this->db);
			$prod->fetch($fk_product);
			$prod->fetch_fourn_data($this->id);

			$commf->fetch($idc);
			$commf->addline("Toto",120,1,$prod->tva, $prod->id, 0, $prod->ref_fourn);
		}
	}
Example #27
0
 }
 print_liste_field_titre($langs->trans("QtyMin"), $_SERVER["PHP_SELF"], "pfp.quantity", "", $param, 'align="right"', $sortfield, $sortorder);
 print_liste_field_titre($langs->trans("VATRate"), $_SERVER["PHP_SELF"], '', '', $param, 'align="right"', $sortfield, $sortorder);
 print_liste_field_titre($langs->trans("PriceQtyMinHT"), $_SERVER["PHP_SELF"], '', '', $param, 'align="right"', $sortfield, $sortorder);
 print_liste_field_titre($langs->trans("UnitPriceHT"), $_SERVER["PHP_SELF"], "pfp.unitprice", "", $param, 'align="right"', $sortfield, $sortorder);
 print_liste_field_titre($langs->trans("DiscountQtyMin"), $_SERVER["PHP_SELF"], '', '', $param, 'align="right"', $sortfield, $sortorder);
 print_liste_field_titre($langs->trans("NbDaysToDelivery"), $_SERVER["PHP_SELF"], "pfp.delivery_time_days", "", $param, 'align="right"', $sortfield, $sortorder);
 // Charges ????
 if ($conf->global->PRODUCT_CHARGES) {
     if (!empty($conf->margin->enabled)) {
         print_liste_field_titre($langs->trans("UnitCharges"));
     }
 }
 print_liste_field_titre('');
 print "</tr>\n";
 $product_fourn = new ProductFournisseur($db);
 $product_fourn_list = $product_fourn->list_product_fournisseur_price($object->id, $sortfield, $sortorder);
 if (count($product_fourn_list) > 0) {
     $var = true;
     foreach ($product_fourn_list as $productfourn) {
         $var = !$var;
         print "<tr " . $bc[$var] . ">";
         print '<td>' . $productfourn->getSocNomUrl(1, 'supplier') . '</td>';
         // Supplier
         print '<td align="left">' . $productfourn->fourn_ref . '</td>';
         //Availability
         if (!empty($conf->global->FOURN_PRODUCT_AVAILABILITY)) {
             $form->load_cache_availability();
             $availability = $form->cache_availability[$productfourn->fk_availability]['label'];
             print '<td align="left">' . $availability . '</td>';
         }
Example #28
0
 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;
 }
Example #29
0
     print '<td class="liste_titre" align="center">';
     print $form->selectarray('tosell', array('0' => $langs->trans('ProductStatusNotOnSellShort'), '1' => $langs->trans('ProductStatusOnSellShort')), $tosell, 1);
     print '</td >';
 }
 if (!empty($arrayfields['p.tobuy']['checked'])) {
     print '<td class="liste_titre" align="center">';
     print $form->selectarray('tobuy', array('0' => $langs->trans('ProductStatusNotOnBuyShort'), '1' => $langs->trans('ProductStatusOnBuyShort')), $tobuy, 1);
     print '</td>';
 }
 print '<td class="liste_titre nowrap" align="right">';
 print '<input type="image" class="liste_titre" name="button_search" src="' . img_picto($langs->trans("Search"), 'search.png', '', '', 1) . '" value="' . dol_escape_htmltag($langs->trans("Search")) . '" title="' . dol_escape_htmltag($langs->trans("Search")) . '">';
 print '<input type="image" class="liste_titre" name="button_removefilter" src="' . img_picto($langs->trans("RemoveFilter"), 'searchclear.png', '', '', 1) . '" value="' . dol_escape_htmltag($langs->trans("RemoveFilter")) . '" title="' . dol_escape_htmltag($langs->trans("RemoveFilter")) . '">';
 print '</td>';
 print '</tr>';
 $product_static = new Product($db);
 $product_fourn = new ProductFournisseur($db);
 $var = true;
 while ($i < min($num, $limit)) {
     $objp = $db->fetch_object($resql);
     // Multilangs
     if (!empty($conf->global->MAIN_MULTILANGS)) {
         $sql = "SELECT label";
         $sql .= " FROM " . MAIN_DB_PREFIX . "product_lang";
         $sql .= " WHERE fk_product=" . $objp->rowid;
         $sql .= " AND lang='" . $langs->getDefaultLang() . "'";
         $sql .= " LIMIT 1";
         $result = $db->query($sql);
         if ($result) {
             $objtp = $db->fetch_object($result);
             if (!empty($objtp->label)) {
                 $objp->label = $objtp->label;
Example #30
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;
}