Example #1
0
     }
 }
 if (!$error) {
     $supplier = new Fournisseur($db);
     $result = $supplier->fetch($id_fourn);
     if (isset($_POST['ref_fourn_price_id'])) {
         $object->fetch_product_fournisseur_price($_POST['ref_fourn_price_id']);
     }
     $ret = $object->update_buyprice($quantity, $_POST["price"], $user, $_POST["price_base_type"], $supplier, $_POST["oselDispo"], $ref_fourn, $tva_tx, $_POST["charges"], $remise_percent, 0, $npr, $delivery_time_days);
     if ($ret < 0) {
         $error++;
         setEventMessage($object->error, $object->errors, 'errors');
     } else {
         if ($price_expression !== '') {
             //Check the expression validity by parsing it
             $priceparser = new PriceParser($db);
             $price_result = $priceparser->parseProductSupplier($id, $price_expression, $quantity, $tva_tx);
             if ($price_result < 0) {
                 //Expression is not valid
                 $error++;
                 setEventMessage($priceparser->translatedError(), 'errors');
             }
         }
         if (!$error && !empty($conf->dynamicprices->enabled)) {
             $ret = $object->setPriceExpression($price_expression);
             if ($ret < 0) {
                 $error++;
                 setEventMessage($object->error, 'errors');
             }
         }
     }
Example #2
0
            }
        } else {
            if ($result < 0) {
                setEventMessages("add find: " . $price_expression->error, $price_expression->errors, 'errors');
            } else {
                setEventMessages($langs->trans("ErrorRecordAlreadyExists"), null, 'errors');
            }
        }
    }
}
if ($action == 'update') {
    if ($eid != 0) {
        $result = $price_expression->find_title($title);
        if ($result == 0 || $result == $eid) {
            //Check the expression validity by parsing it
            $priceparser = new PriceParser($db);
            $price_result = $priceparser->parseProductSupplierExpression($id, $expression, 0, 0);
            if ($price_result < 0) {
                //Expression is not valid
                setEventMessages($priceparser->translatedError(), null, 'errors');
            } else {
                $price_expression->id = $eid;
                $price_expression->title = $title;
                $price_expression->expression = $expression;
                $result = $price_expression->update($user);
                if ($result < 0) {
                    setEventMessages("update: " . $price_expression->error, $price_expression->errors, 'errors');
                } else {
                    setEventMessages($langs->trans("RecordSaved"), null, 'mesgs');
                }
            }
 /**
  *  Load a product in memory from database
  *
  *  @param	int		$id      			Id of product/service to load
  *  @param  string	$ref     			Ref of product/service to load
  *  @param	string	$ref_ext			Ref ext of product/service to load
  *  @param	int		$ignore_expression  Ignores the math expression for calculating price and uses the db value instead
  *  @return int     					<0 if KO, 0 if not found, >0 if OK
  */
 function fetch($id = '', $ref = '', $ref_ext = '', $ignore_expression = 0)
 {
     include_once DOL_DOCUMENT_ROOT . '/core/lib/company.lib.php';
     global $langs, $conf;
     dol_syslog(get_class($this) . "::fetch id=" . $id . " ref=" . $ref . " ref_ext=" . $ref_ext);
     // Check parameters
     if (!$id && !$ref && !$ref_ext) {
         $this->error = 'ErrorWrongParameters';
         dol_print_error(get_class($this) . "::fetch " . $this->error);
         return -1;
     }
     $sql = "SELECT rowid, ref, ref_ext, label, description, url, note, customcode, fk_country, price, price_ttc,";
     $sql .= " price_min, price_min_ttc, price_base_type, tva_tx, recuperableonly as tva_npr, localtax1_tx, localtax2_tx, tosell,";
     $sql .= " tobuy, fk_product_type, duration, seuil_stock_alerte, canvas,";
     $sql .= " weight, weight_units, length, length_units, surface, surface_units, volume, volume_units, barcode, fk_barcode_type, finished,";
     $sql .= " accountancy_code_buy, accountancy_code_sell, stock, pmp,";
     $sql .= " datec, tms, import_key, entity, desiredstock, tobatch, fk_unit";
     $sql .= " , fk_price_expression";
     $sql .= " FROM " . MAIN_DB_PREFIX . "product";
     if ($id) {
         $sql .= " WHERE rowid = " . $this->db->escape($id);
     } else {
         $sql .= " WHERE entity IN (" . getEntity($this->element, 1) . ")";
         if ($ref) {
             $sql .= " AND ref = '" . $this->db->escape($ref) . "'";
         } else {
             if ($ref_ext) {
                 $sql .= " AND ref_ext = '" . $this->db->escape($ref_ext) . "'";
             }
         }
     }
     $resql = $this->db->query($sql);
     if ($resql) {
         if ($this->db->num_rows($resql) > 0) {
             $obj = $this->db->fetch_object($resql);
             $this->id = $obj->rowid;
             $this->ref = $obj->ref;
             $this->ref_ext = $obj->ref_ext;
             $this->label = $obj->label;
             $this->description = $obj->description;
             $this->url = $obj->url;
             $this->note = $obj->note;
             $this->type = $obj->fk_product_type;
             $this->status = $obj->tosell;
             $this->status_buy = $obj->tobuy;
             $this->status_batch = $obj->tobatch;
             $this->customcode = $obj->customcode;
             $this->country_id = $obj->fk_country;
             $this->country_code = getCountry($this->country_id, 2, $this->db);
             $this->price = $obj->price;
             $this->price_ttc = $obj->price_ttc;
             $this->price_min = $obj->price_min;
             $this->price_min_ttc = $obj->price_min_ttc;
             $this->price_base_type = $obj->price_base_type;
             $this->tva_tx = $obj->tva_tx;
             //! French VAT NPR
             $this->tva_npr = $obj->tva_npr;
             //! Spanish local taxes
             $this->localtax1_tx = $obj->localtax1_tx;
             $this->localtax2_tx = $obj->localtax2_tx;
             $this->finished = $obj->finished;
             $this->duration = $obj->duration;
             $this->duration_value = substr($obj->duration, 0, dol_strlen($obj->duration) - 1);
             $this->duration_unit = substr($obj->duration, -1);
             $this->canvas = $obj->canvas;
             $this->weight = $obj->weight;
             $this->weight_units = $obj->weight_units;
             $this->length = $obj->length;
             $this->length_units = $obj->length_units;
             $this->surface = $obj->surface;
             $this->surface_units = $obj->surface_units;
             $this->volume = $obj->volume;
             $this->volume_units = $obj->volume_units;
             $this->barcode = $obj->barcode;
             $this->barcode_type = $obj->fk_barcode_type;
             $this->accountancy_code_buy = $obj->accountancy_code_buy;
             $this->accountancy_code_sell = $obj->accountancy_code_sell;
             $this->seuil_stock_alerte = $obj->seuil_stock_alerte;
             $this->desiredstock = $obj->desiredstock;
             $this->stock_reel = $obj->stock;
             $this->pmp = $obj->pmp;
             $this->date_creation = $obj->datec;
             $this->date_modification = $obj->tms;
             $this->import_key = $obj->import_key;
             $this->entity = $obj->entity;
             $this->ref_ext = $obj->ref_ext;
             $this->fk_price_expression = $obj->fk_price_expression;
             $this->fk_unit = $obj->fk_unit;
             $this->db->free($resql);
             // Retreive all extrafield for current object
             // fetch optionals attributes and labels
             require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php';
             $extrafields = new ExtraFields($this->db);
             $extralabels = $extrafields->fetch_name_optionals_label($this->table_element, true);
             $this->fetch_optionals($this->id, $extralabels);
             // multilangs
             if (!empty($conf->global->MAIN_MULTILANGS)) {
                 $this->getMultiLangs();
             }
             // Load multiprices array
             if (!empty($conf->global->PRODUIT_MULTIPRICES)) {
                 for ($i = 1; $i <= $conf->global->PRODUIT_MULTIPRICES_LIMIT; $i++) {
                     $sql = "SELECT price, price_ttc, price_min, price_min_ttc,";
                     $sql .= " price_base_type, tva_tx, tosell, price_by_qty, rowid, recuperableonly";
                     $sql .= " FROM " . MAIN_DB_PREFIX . "product_price";
                     $sql .= " WHERE entity IN (" . getEntity('productprice', 1) . ")";
                     $sql .= " AND price_level=" . $i;
                     $sql .= " AND fk_product = '" . $this->id . "'";
                     $sql .= " ORDER BY date_price DESC";
                     $sql .= " LIMIT 1";
                     $resql = $this->db->query($sql);
                     if ($resql) {
                         $result = $this->db->fetch_array($resql);
                         $this->multiprices[$i] = $result["price"];
                         $this->multiprices_ttc[$i] = $result["price_ttc"];
                         $this->multiprices_min[$i] = $result["price_min"];
                         $this->multiprices_min_ttc[$i] = $result["price_min_ttc"];
                         $this->multiprices_base_type[$i] = $result["price_base_type"];
                         $this->multiprices_tva_tx[$i] = $result["tva_tx"];
                         $this->multiprices_recuperableonly[$i] = $result["recuperableonly"];
                         // Price by quantity
                         $this->prices_by_qty[$i] = $result["price_by_qty"];
                         $this->prices_by_qty_id[$i] = $result["rowid"];
                         // Récuperation de la liste des prix selon qty si flag positionné
                         if ($this->prices_by_qty[$i] == 1) {
                             $sql = "SELECT rowid,price, unitprice, quantity, remise_percent, remise";
                             $sql .= " FROM " . MAIN_DB_PREFIX . "product_price_by_qty";
                             $sql .= " WHERE fk_product_price = '" . $this->prices_by_qty_id[$i] . "'";
                             $sql .= " ORDER BY quantity ASC";
                             $resultat = array();
                             $resql = $this->db->query($sql);
                             if ($resql) {
                                 $ii = 0;
                                 while ($result = $this->db->fetch_array($resql)) {
                                     $resultat[$ii] = array();
                                     $resultat[$ii]["rowid"] = $result["rowid"];
                                     $resultat[$ii]["price"] = $result["price"];
                                     $resultat[$ii]["unitprice"] = $result["unitprice"];
                                     $resultat[$ii]["quantity"] = $result["quantity"];
                                     $resultat[$ii]["remise_percent"] = $result["remise_percent"];
                                     $resultat[$ii]["remise"] = $result["remise"];
                                     $ii++;
                                 }
                                 $this->prices_by_qty_list[$i] = $resultat;
                             } else {
                                 dol_print_error($this->db);
                                 return -1;
                             }
                         }
                     } else {
                         dol_print_error($this->db);
                         return -1;
                     }
                 }
             } else {
                 if (!empty($conf->global->PRODUIT_CUSTOMER_PRICES_BY_QTY)) {
                     $sql = "SELECT price, price_ttc, price_min, price_min_ttc,";
                     $sql .= " price_base_type, tva_tx, tosell, price_by_qty, rowid";
                     $sql .= " FROM " . MAIN_DB_PREFIX . "product_price";
                     $sql .= " WHERE fk_product = '" . $this->id . "'";
                     $sql .= " ORDER BY date_price DESC";
                     $sql .= " LIMIT 1";
                     $resql = $this->db->query($sql);
                     if ($resql) {
                         $result = $this->db->fetch_array($resql);
                         // Price by quantity
                         $this->prices_by_qty[0] = $result["price_by_qty"];
                         $this->prices_by_qty_id[0] = $result["rowid"];
                         // Récuperation de la liste des prix selon qty si flag positionné
                         if ($this->prices_by_qty[0] == 1) {
                             $sql = "SELECT rowid,price, unitprice, quantity, remise_percent, remise";
                             $sql .= " FROM " . MAIN_DB_PREFIX . "product_price_by_qty";
                             $sql .= " WHERE fk_product_price = '" . $this->prices_by_qty_id[0] . "'";
                             $sql .= " ORDER BY quantity ASC";
                             $resultat = array();
                             $resql = $this->db->query($sql);
                             if ($resql) {
                                 $ii = 0;
                                 while ($result = $this->db->fetch_array($resql)) {
                                     $resultat[$ii] = array();
                                     $resultat[$ii]["rowid"] = $result["rowid"];
                                     $resultat[$ii]["price"] = $result["price"];
                                     $resultat[$ii]["unitprice"] = $result["unitprice"];
                                     $resultat[$ii]["quantity"] = $result["quantity"];
                                     $resultat[$ii]["remise_percent"] = $result["remise_percent"];
                                     $resultat[$ii]["remise"] = $result["remise"];
                                     $ii++;
                                 }
                                 $this->prices_by_qty_list[0] = $resultat;
                             } else {
                                 dol_print_error($this->db);
                                 return -1;
                             }
                         }
                     } else {
                         dol_print_error($this->db);
                         return -1;
                     }
                 }
             }
             if (!empty($this->fk_price_expression) && empty($ignore_expression)) {
                 require_once DOL_DOCUMENT_ROOT . '/product/dynamic_price/class/price_parser.class.php';
                 $priceparser = new PriceParser($this->db);
                 $price_result = $priceparser->parseProduct($this);
                 if ($price_result >= 0) {
                     $this->price = $price_result;
                     //Calculate the VAT
                     $this->price_ttc = price2num($this->price) * (1 + $this->tva_tx / 100);
                     $this->price_ttc = price2num($this->price_ttc, 'MU');
                 }
             }
             // We should not load stock at each fetch. If someone need stock, he must call load_stock after fetch.
             //$res=$this->load_stock();
             // instead we just init the stock_warehouse array
             $this->stock_warehouse = array();
             return 1;
         } else {
             return 0;
         }
     } else {
         dol_print_error($this->db);
         return -1;
     }
 }
Example #4
0
 $product_static->ref = $objp->ref;
 $product_static->label = $objp->label;
 $product_static->type = $objp->fk_product_type;
 $product_static->entity = $objp->entity;
 print $product_static->getNomUrl(1, '', 16);
 print "</td>\n";
 print '<td>' . dol_trunc($objp->label, 32) . '</td>';
 print "<td>";
 print dol_print_date($db->jdate($objp->datem), 'day');
 print "</td>";
 // Sell price
 if (empty($conf->global->PRODUIT_MULTIPRICES)) {
     if (!empty($objp->fk_price_expression)) {
         $product = new Product($db);
         $product->fetch($objp->rowid);
         $priceparser = new PriceParser($db);
         $price_result = $priceparser->parseProduct($product);
         if ($price_result >= 0) {
             $objp->price = $price_result;
         }
     }
     print '<td align="right">';
     if (isset($objp->price_base_type) && $objp->price_base_type == 'TTC') {
         print price($objp->price_ttc) . ' ' . $langs->trans("TTC");
     } else {
         print price($objp->price) . ' ' . $langs->trans("HT");
     }
     print '</td>';
 }
 print '<td align="right" class="nowrap">';
 print $product_static->LibStatut($objp->tosell, 5, 0);
 $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) {
     $num = $db->num_rows($result);
     if ($num) {
         require_once DOL_DOCUMENT_ROOT . '/product/dynamic_price/class/price_parser.class.php';
         $i = 0;
         while ($i < $num) {
             $objp = $db->fetch_object($result);
             if (!empty($objp->fk_supplier_price_expression)) {
                 $priceparser = new PriceParser($db);
                 $price_result = $priceparser->parseProductSupplier($idprod, $objp->fk_supplier_price_expression, $objp->quantity, $objp->tva_tx);
                 if ($price_result >= 0) {
                     $objp->fprice = $price_result;
                     if ($objp->quantity >= 1) {
                         $objp->unitprice = $objp->fprice / $objp->quantity;
                     }
                 }
             }
             $price = $objp->fprice * (1 - $objp->remise_percent / 100);
             $unitprice = $objp->unitprice * (1 - $objp->remise_percent / 100);
             $title = $objp->name . ' - ' . $objp->ref_fourn . ' - ';
             if ($objp->quantity == 1) {
                 $title .= price($price, 0, $langs, 0, 0, -1, $conf->currency) . "/";
             }
             $title .= $objp->quantity . ' ' . ($objp->quantity == 1 ? $langs->trans("Unit") : $langs->trans("Units"));
 /**
  *  Load data into info_box_contents array to show array later.
  *
  *  @param	int		$max        Maximum number of records to load
  *  @return	void
  */
 function loadBox($max = 5)
 {
     global $user, $langs, $db, $conf;
     $this->max = $max;
     include_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
     $productstatic = new Product($db);
     $this->info_box_head = array('text' => $langs->trans("BoxTitleProductsAlertStock", $max));
     if ($user->rights->produit->lire || $user->rights->service->lire) {
         $sql = "SELECT p.rowid, p.label, p.price, p.ref, p.price_base_type, p.price_ttc, p.fk_product_type, p.tms, p.tosell, p.tobuy, p.seuil_stock_alerte,";
         $sql .= " SUM(" . $db->ifsql("s.reel IS NULL", "0", "s.reel") . ") as total_stock";
         $sql .= " FROM " . MAIN_DB_PREFIX . "product as p";
         $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_stock as s on p.rowid = s.fk_product";
         $sql .= ' WHERE p.entity IN (' . getEntity($productstatic->element, 1) . ')';
         $sql .= " AND p.tosell = 1 AND p.seuil_stock_alerte > 0";
         if (empty($user->rights->produit->lire)) {
             $sql .= ' AND p.fk_product_type != 0';
         }
         if (empty($user->rights->service->lire)) {
             $sql .= ' AND p.fk_product_type != 1';
         }
         $sql .= " GROUP BY p.rowid, p.ref, p.label, p.price, p.price_base_type, p.price_ttc, p.fk_product_type, p.tms, p.tosell, p.tobuy, p.seuil_stock_alerte";
         $sql .= " HAVING SUM(" . $db->ifsql("s.reel IS NULL", "0", "s.reel") . ") < p.seuil_stock_alerte";
         $sql .= $db->order('p.seuil_stock_alerte', 'DESC');
         $sql .= $db->plimit($max, 0);
         $result = $db->query($sql);
         if ($result) {
             $langs->load("stocks");
             $num = $db->num_rows($result);
             $line = 0;
             while ($line < $num) {
                 $objp = $db->fetch_object($result);
                 $datem = $db->jdate($objp->tms);
                 // Multilangs
                 if (!empty($conf->global->MAIN_MULTILANGS)) {
                     $sqld = "SELECT label";
                     $sqld .= " FROM " . MAIN_DB_PREFIX . "product_lang";
                     $sqld .= " WHERE fk_product=" . $objp->rowid;
                     $sqld .= " AND lang='" . $langs->getDefaultLang() . "'";
                     $sqld .= " LIMIT 1";
                     $resultd = $db->query($sqld);
                     if ($resultd) {
                         $objtp = $db->fetch_object($resultd);
                         if (isset($objtp->label) && $objtp->label != '') {
                             $objp->label = $objtp->label;
                         }
                     }
                 }
                 $productstatic->id = $objp->rowid;
                 $productstatic->ref = $objp->ref;
                 $productstatic->type = $objp->fk_product_type;
                 $productstatic->label = $objp->label;
                 $this->info_box_contents[$line][] = array('td' => 'align="left"', 'text' => $productstatic->getNomUrl(1), 'asis' => 1);
                 $this->info_box_contents[$line][] = array('td' => 'align="left"', 'text' => $objp->label);
                 if (empty($objp->fk_price_expression)) {
                     $price_base_type = $langs->trans($objp->price_base_type);
                     $price = $objp->price_base_type == 'HT' ? price($objp->price) : ($price = price($objp->price_ttc));
                 } else {
                     $productstatic->fetch($objp->rowid, '', '', 1);
                     $priceparser = new PriceParser($this->db);
                     $price_result = $priceparser->parseProduct($productstatic);
                     if ($price_result >= 0) {
                         if ($objp->price_base_type == 'HT') {
                             $price_base_type = $langs->trans("HT");
                         } else {
                             $price_result = $price_result * (1 + $productstatic->tva_tx / 100);
                             $price_base_type = $langs->trans("TTC");
                         }
                         $price = price($price_result);
                     }
                 }
                 $this->info_box_contents[$line][] = array('td' => 'align="right"', 'text' => $price);
                 $this->info_box_contents[$line][] = array('td' => 'align="left" class="nowrap"', 'text' => $price_base_type);
                 $this->info_box_contents[$line][] = array('td' => 'align="center"', 'text' => $objp->total_stock . ' / ' . $objp->seuil_stock_alerte, 'text2' => img_warning($langs->transnoentitiesnoconv("StockLowerThanLimit")));
                 $this->info_box_contents[$line][] = array('td' => 'align="right" width="18"', 'text' => $productstatic->LibStatut($objp->tosell, 3, 0));
                 $this->info_box_contents[$line][] = array('td' => 'align="right" width="18"', 'text' => $productstatic->LibStatut($objp->tobuy, 3, 1));
                 $line++;
             }
             if ($num == 0) {
                 $this->info_box_contents[$line][0] = array('td' => 'align="center"', 'text' => $langs->trans("NoTooLowStockProducts"));
             }
             $db->free($result);
         } else {
             $this->info_box_contents[0][0] = array('td' => 'align="left"', 'maxlength' => 500, 'text' => $db->error() . ' sql=' . $sql);
         }
     } else {
         $this->info_box_contents[0][0] = array('td' => 'align="left"', 'text' => $langs->trans("ReadPermissionNotAllowed"));
     }
 }
 /**
  *  Load properties for minimum price
  *
  *  @param	int		$prodid	    Product id
  *  @param	int		$qty		Minimum quantity
  *  @return int					<0 if KO, 0=Not found of no product id provided, >0 if OK
  */
 function find_min_price_product_fournisseur($prodid, $qty = 0)
 {
     global $conf;
     if (empty($prodid)) {
         dol_syslog("Warning function find_min_price_product_fournisseur were called with prodid empty. May be a bug.", LOG_WARNING);
         return 0;
     }
     $this->product_fourn_price_id = '';
     $this->product_fourn_id = '';
     $this->fourn_ref = '';
     $this->fourn_price = '';
     $this->fourn_qty = '';
     $this->fourn_remise_percent = '';
     $this->fourn_remise = '';
     $this->fourn_unitprice = '';
     $this->fourn_id = '';
     $this->fourn_name = '';
     $this->delivery_time_days = '';
     $this->id = '';
     $sql = "SELECT s.nom as supplier_name, s.rowid as fourn_id,";
     $sql .= " pfp.rowid as product_fourn_price_id, pfp.ref_fourn,";
     $sql .= " pfp.price, pfp.quantity, pfp.unitprice, pfp.tva_tx, pfp.charges, pfp.unitcharges, ";
     $sql .= " pfp.remise, pfp.remise_percent, pfp.fk_supplier_price_expression, pfp.delivery_time_days";
     $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s, " . MAIN_DB_PREFIX . "product_fournisseur_price as pfp";
     $sql .= " WHERE s.entity IN (" . getEntity('societe', 1) . ")";
     $sql .= " AND pfp.fk_product = " . $prodid;
     $sql .= " AND pfp.fk_soc = s.rowid";
     if ($qty > 0) {
         $sql .= " AND pfp.quantity <= " . $qty;
     }
     dol_syslog(get_class($this) . "::find_min_price_product_fournisseur", LOG_DEBUG);
     $resql = $this->db->query($sql);
     if ($resql) {
         $record_array = array();
         //Store each record to array for later search of min
         while ($record = $this->db->fetch_array($resql)) {
             $record_array[] = $record;
         }
         if (count($record_array) == 0) {
             $this->db->free($resql);
             return 0;
         } else {
             $min = -1;
             foreach ($record_array as $record) {
                 $fourn_price = $record["price"];
                 $fourn_unitprice = $record["unitprice"];
                 if (!empty($record["fk_supplier_price_expression"])) {
                     $priceparser = new PriceParser($this->db);
                     $price_result = $priceparser->parseProductSupplier($prodid, $record["fk_supplier_price_expression"], $record["quantity"], $record["tva_tx"]);
                     if ($price_result >= 0) {
                         $fourn_price = price2num($price_result, 'MU');
                         if ($record["quantity"] != 0) {
                             $fourn_unitprice = price2num($fourn_price / $record["quantity"], 'MU');
                         } else {
                             $fourn_unitprice = $fourn_price;
                         }
                     }
                 }
                 if ($fourn_unitprice < $min || $min == -1) {
                     $this->product_fourn_price_id = $record["product_fourn_price_id"];
                     $this->fourn_ref = $record["ref_fourn"];
                     $this->fourn_price = $fourn_price;
                     $this->fourn_qty = $record["quantity"];
                     $this->fourn_remise_percent = $record["remise_percent"];
                     $this->fourn_remise = $record["remise"];
                     $this->fourn_unitprice = $fourn_unitprice;
                     $this->fourn_charges = $record["charges"];
                     // deprecated
                     $this->fourn_unitcharges = $record["unitcharges"];
                     // deprecated
                     $this->fourn_tva_tx = $record["tva_tx"];
                     $this->fourn_id = $record["fourn_id"];
                     $this->fourn_name = $record["supplier_name"];
                     $this->delivery_time_days = $record["delivery_time_days"];
                     $this->fk_supplier_price_expression = $record["fk_supplier_price_expression"];
                     $this->id = $prodid;
                     $min = $this->fourn_unitprice;
                 }
             }
         }
         $this->db->free($resql);
         return 1;
     } else {
         $this->error = $this->db->error();
         return -1;
     }
 }
Example #8
0
     $newpsq = GETPOST('psqflag');
     $newpsq = empty($newpsq) ? 0 : $newpsq;
 }
 if (!empty($conf->global->PRODUCT_MINIMUM_RECOMMENDED_PRICE) && $newprice_min < $maxpricesupplier) {
     setEventMessage($langs->trans("MinimumPriceLimit", price($maxpricesupplier, 0, '', 1, -1, -1, 'auto')), 'errors');
     $error++;
     $action = 'edit_price';
 }
 if ($newprice < $newprice_min && !empty($object->fk_price_expression)) {
     $newprice = $newprice_min;
     //Set price same as min, the user will not see the
 }
 if ($object->updatePrice($newprice, $newpricebase, $user, $newvat, $newprice_min, $level, $newnpr, $newpsq) > 0) {
     if ($object->fk_price_expression != 0) {
         //Check the expression validity by parsing it
         $priceparser = new PriceParser($db);
         $price_result = $priceparser->parseProduct($object);
         if ($price_result < 0) {
             //Expression is not valid
             $error++;
             $action = 'edit_price';
             setEventMessage($priceparser->translatedError(), 'errors');
         }
     }
     if (empty($error) && !empty($conf->dynamicprices->enabled)) {
         $ret = $object->setPriceExpression($object->fk_price_expression);
         if ($ret < 0) {
             $error++;
             $action = 'edit_price';
             setEventMessage($object->error, 'errors');
         }
Example #9
0
	    
	if (($action == 'update_price') && !$cancel && $object->getRights()->creer)
    {
		$error = 0;
		$pricestoupdate = array();

		$psq = GETPOST('psqflag');
		$psq = empty($newpsq) ? 0 : $newpsq;
		$maxpricesupplier = $object->min_recommended_price();

		if (!empty($conf->dynamicprices->enabled)) {
			$object->fk_price_expression = empty($eid) ? 0 : $eid; //0 discards expression

			if ($object->fk_price_expression != 0) {
				//Check the expression validity by parsing it
				$priceparser = new PriceParser($db);

				if ($priceparser->parseProduct($object) < 0) {
					$error ++;
					setEventMessages($priceparser->translatedError(), null, 'errors');
				}
			}
		}

		// Multiprices
		if (!$error && !empty($conf->global->PRODUIT_MULTIPRICES)) {

			$newprice = GETPOST('price', 'array');
			$newprice_min = GETPOST('price_min', 'array');
			$newpricebase = GETPOST('multiprices_base_type', 'array');
			$newvattx = GETPOST('tva_tx', 'array');
Example #10
0
 /**
  *	Return list of suppliers prices for a product
  *
  *  @param		int		$productid       Id of product
  *  @param      string	$htmlname        Name of HTML field
  *  @return		void
  */
 function select_product_fourn_price($productid, $htmlname = 'productfournpriceid')
 {
     global $langs, $conf;
     $langs->load('stocks');
     $sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration,";
     $sql .= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.unitprice,";
     $sql .= " pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, s.nom as name";
     $sql .= " FROM " . MAIN_DB_PREFIX . "product as p";
     $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "product_fournisseur_price as pfp ON p.rowid = pfp.fk_product";
     $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON pfp.fk_soc = s.rowid";
     $sql .= " WHERE p.entity IN (" . getEntity('product', 1) . ")";
     $sql .= " AND p.tobuy = 1";
     $sql .= " AND s.fournisseur = 1";
     $sql .= " AND p.rowid = " . $productid;
     $sql .= " ORDER BY s.nom, pfp.ref_fourn DESC";
     dol_syslog(get_class($this) . "::select_product_fourn_price", LOG_DEBUG);
     $result = $this->db->query($sql);
     if ($result) {
         $num = $this->db->num_rows($result);
         $form = '<select class="flat" name="' . $htmlname . '">';
         if (!$num) {
             $form .= '<option value="0">-- ' . $langs->trans("NoSupplierPriceDefinedForThisProduct") . ' --</option>';
         } else {
             require_once DOL_DOCUMENT_ROOT . '/product/dynamic_price/class/price_parser.class.php';
             $form .= '<option value="0">&nbsp;</option>';
             $i = 0;
             while ($i < $num) {
                 $objp = $this->db->fetch_object($result);
                 $opt = '<option value="' . $objp->idprodfournprice . '"';
                 //if there is only one supplier, preselect it
                 if ($num == 1) {
                     $opt .= ' selected';
                 }
                 $opt .= '>' . $objp->name . ' - ' . $objp->ref_fourn . ' - ';
                 if (!empty($objp->fk_supplier_price_expression)) {
                     $priceparser = new PriceParser($this->db);
                     $price_result = $priceparser->parseProductSupplier($objp->fk_product, $objp->fk_supplier_price_expression, $objp->quantity, $objp->tva_tx);
                     if ($price_result >= 0) {
                         $objp->fprice = $price_result;
                         if ($objp->quantity >= 1) {
                             $objp->unitprice = $objp->fprice / $objp->quantity;
                         }
                     }
                 }
                 if ($objp->quantity == 1) {
                     $opt .= price($objp->fprice, 1, $langs, 0, 0, -1, $conf->currency) . "/";
                 }
                 $opt .= $objp->quantity . ' ';
                 if ($objp->quantity == 1) {
                     $opt .= $langs->trans("Unit");
                 } else {
                     $opt .= $langs->trans("Units");
                 }
                 if ($objp->quantity > 1) {
                     $opt .= " - ";
                     $opt .= price($objp->unitprice, 1, $langs, 0, 0, -1, $conf->currency) . "/" . $langs->trans("Unit");
                 }
                 if ($objp->duration) {
                     $opt .= " - " . $objp->duration;
                 }
                 $opt .= "</option>\n";
                 $form .= $opt;
                 $i++;
             }
             $form .= '</select>';
             $this->db->free($result);
         }
         return $form;
     } else {
         dol_print_error($this->db);
     }
 }