/**
  * 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');
     }
 }
Exemple #2
0
     $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);
         }
         $tvatx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, $_POST['idprodfournprice']);
         $npr = get_default_npr($object->thirdparty, $mysoc, $productsupplier->id, $_POST['idprodfournprice']);
         $localtax1_tx = get_localtax($tvatx, 1, $mysoc, $object->thirdparty);
         $localtax2_tx = get_localtax($tvatx, 2, $mysoc, $object->thirdparty);
         $type = $productsupplier->type;
         $price_base_type = 'HT';
         // TODO Save the product supplier ref into database into field ref_supplier (must rename field ref into ref_supplier first)
         $result = $object->addline($desc, $productsupplier->fourn_pu, $tvatx, $localtax1_tx, $localtax2_tx, $qty, $idprod, $remise_percent, $date_start, $date_end, 0, $npr, $price_base_type, $type, -1, 0, $array_options, $productsupplier->fk_unit);
     }
     if ($idprod == -2 || $idprod == 0) {
    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) . "/";
            }
            $title .= $productSupplier->fourn_qty . ' ' . ($productSupplier->fourn_qty == 1 ? $langs->trans("Unit") : $langs->trans("Units"));
            } else {
                $db->rollback();
            }
        } else {
            $action = 'add_price';
        }
    }
}
/*
 * view
 */
$form = new Form($db);
if ($id || $ref) {
    if ($action != 're-edit') {
        $product = new ProductFournisseur($db);
        $result = $product->fetch($id, $ref);
        //$result = $product->fetch_fourn_data($_REQUEST["id_fourn"]);
        llxHeader("", "", $langs->trans("CardProduct" . $product->type));
    }
    if ($result) {
        if ($action != 'edit' && $action != 're-edit') {
            $head = product_prepare_head($product);
            $titre = $langs->trans("CardProduct" . $product->type);
            $picto = $product->type == Product::TYPE_SERVICE ? 'service' : 'product';
            dol_fiche_head($head, 'suppliers', $titre, 0, $picto);
            print '<table class="border" width="100%">';
            // Reference
            print '<tr>';
            print '<td width="15%">' . $langs->trans("Ref") . '</td><td colspan="2">';
            print $form->showrefnav($product, 'ref', '', 1, 'ref');
            print '</td>';
	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);
		}
	}
	/**
     *	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;
	}
Exemple #7
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;
		$head[$h][1] = $langs->trans("ProductCard");
Exemple #8
0
                    print '</tr>';
                    print '</form>';
                }
                else // Affichage simple de la ligne
                {
                    print '<tr '.$bc[$var].'>';

                    // Show product and description
                    print '<td>';
                    if ($fac->lines[$i]->fk_product)
                    {
                        print '<a name="'.$objp->rowid.'"></a>'; // ancre pour retourner sur la ligne

                        $product_static=new ProductFournisseur($db);
                        $product_static->fetch($fac->lines[$i]->fk_product);
                        $text=$product_static->getNomUrl(1);
                        $text.= ' - '.$product_static->libelle;
                        $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($fac->lines[$i]->description));
                        print $html->textwithtooltip($text,$description,3,'','',$i);

                        // Show range
                        print_date_range($fac->lines[$i]->date_start,$fac->lines[$i]->date_end);

                        // Add description in form
                        if ($conf->global->PRODUIT_DESC_IN_FORM) print ($fac->lines[$i]->description && $fac->lines[$i]->description!=$product_static->libelle)?'<br>'.dol_htmlentitiesbr($fac->lines[$i]->description):'';
                    }

                    // Description - Editor wysiwyg
                    if (! $fac->lines[$i]->fk_product)
                    {
<?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;
}
Exemple #10
0
         continue;
     }
     $label = !empty($lines[$i]->label) ? $lines[$i]->label : '';
     $desc = !empty($lines[$i]->desc) ? $lines[$i]->desc : $lines[$i]->libelle;
     $product_type = !empty($lines[$i]->product_type) ? $lines[$i]->product_type : 0;
     // Reset fk_parent_line for no child products and special product
     if ($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line) || $lines[$i]->product_type == 9) {
         $fk_parent_line = 0;
     }
     // Extrafields
     if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED) && method_exists($lines[$i], 'fetch_optionals')) {
         $lines[$i]->fetch_optionals($lines[$i]->rowid);
         $array_option = $lines[$i]->array_options;
     }
     $idprod = $productsupplier->find_min_price_product_fournisseur($lines[$i]->fk_product, $lines[$i]->qty);
     $res = $productsupplier->fetch($idProductFourn);
     $result = $object->addline($desc, $lines[$i]->subprice, $lines[$i]->qty, $lines[$i]->tva_tx, $lines[$i]->localtax1_tx, $lines[$i]->localtax2_tx, $lines[$i]->fk_product, $productsupplier->product_fourn_price_id, $productsupplier->ref_fourn, $lines[$i]->remise_percent, 'HT', 0, $lines[$i]->product_type, '', '', null, null, array(), $lines[$i]->fk_unit);
     if ($result < 0) {
         $error++;
         break;
     }
     // Defined the new fk_parent_line
     if ($result > 0 && $lines[$i]->product_type == 9) {
         $fk_parent_line = $result;
     }
 }
 // Hooks
 $parameters = array('objFrom' => $srcobject);
 $reshook = $hookmanager->executeHooks('createFrom', $parameters, $object, $action);
 // Note that $action and $object may have been
 // modified by hook
 /**
  *	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);
 }
 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"><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) {
             $text = img_object($langs->trans('Service'), 'service');
Exemple #14
0
}



/*
 * 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
			 */

			$head=product_prepare_head($product, $user);
Exemple #15
0
 }
 // Ligne en mode update
 if ($action == 'editline' && $user->rights->fournisseur->commande->creer && $_GET["rowid"] == $line->id) {
     print "\n";
     print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '&amp;etat=1&amp;ligne_id=' . $line->id . '" method="post">';
     print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
     print '<input type="hidden" name="action" value="updateligne">';
     print '<input type="hidden" name="id" value="' . $object->id . '">';
     print '<input type="hidden" name="elrowid" value="' . $_GET['rowid'] . '">';
     print '<tr ' . $bc[$var] . '>';
     print '<td>';
     print '<a name="' . $line->id . '"></a>';
     // ancre pour retourner sur la ligne
     if (($conf->product->enabled || $conf->service->enabled) && $line->fk_product > 0) {
         $product_static = new ProductFournisseur($db);
         $product_static->fetch($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 $html->textwithtooltip($text, $description, 3, '', '', $i);
         // Show range
         print_date_range($line->date_start, $line->date_end);
         print '<br>';
     } else {
         print $html->select_type_of_lines($line->product_type, 'type', 1);
         if ($conf->product->enabled && $conf->service->enabled) {
             print '<br>';
         }
     }
     // Description - Editor wysiwyg
     require_once DOL_DOCUMENT_ROOT . "/lib/doleditor.class.php";
Exemple #16
0
    $_GET['id_fourn'] = $_GET['search_fourn_id'];
    $_POST['id_fourn'] = $_POST['search_fourn_id'];
    $_REQUEST['id_fourn'] = $_REQUEST['search_fourn_id'];
}
// Security check
$fieldvalue = !empty($id) ? $id : (!empty($ref) ? $ref : '');
$fieldtype = !empty($ref) ? 'ref' : 'rowid';
if ($user->societe_id) {
    $socid = $user->societe_id;
}
$result = restrictedArea($user, 'produit|service&fournisseur', $fieldvalue, 'product&product', '', '', $fieldtype);
// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
$hookmanager->initHooks(array('pricesuppliercard', 'globalcard'));
$object = new ProductFournisseur($db);
if ($id > 0 || $ref) {
    $object->fetch($id, $ref);
}
$sortfield = GETPOST("sortfield", 'alpha');
$sortorder = GETPOST("sortorder", 'alpha');
if (!$sortfield) {
    $sortfield = "s.nom";
}
if (!$sortorder) {
    $sortorder = "ASC";
}
/*
 * Actions
 */
if ($cancel) {
    $action = '';
}
 /**
  * testCommandeFournisseurCreate
  *
  * @return	void
  */
 public function testCommandeFournisseurCreate()
 {
     global $conf, $user, $langs, $db;
     $conf = $this->savconf;
     $user = $this->savuser;
     $langs = $this->savlangs;
     $db = $this->savdb;
     // Set supplier and product to use
     $socid = 1;
     $societe = new Societe($db);
     $societe->fetch($socid);
     $product = new ProductFournisseur($db);
     $product->fetch(0, 'PIDRESS');
     if ($product->id <= 0) {
         print "\n" . __METHOD__ . " A product with ref PIDRESS must exists into database";
         die;
     }
     $quantity = 10;
     $ref_fourn = 'SUPPLIER_REF_PHPUNIT';
     $tva_tx = 19.6;
     // Create supplier price
     $result = $product->add_fournisseur($user, $societe->id, $ref_fourn, $quantity);
     // This insert record with no value for price. Values are update later with update_buyprice
     $this->assertGreaterThanOrEqual(1, $result);
     $result = $product->update_buyprice($quantity, 10, $user, 'HT', $societe, '', $ref_fourn, $tva_tx, 0, 0);
     $this->assertGreaterThanOrEqual(0, $result);
     // Create supplier order with a too low quantity
     $localobject = new CommandeFournisseur($db);
     $localobject->initAsSpecimen();
     $localobject->lines = array();
     // Overwrite lines of order
     $line = new CommandeFournisseurLigne($db);
     $line->desc = $langs->trans("Description") . " specimen line too low";
     $line->qty = 1;
     // So lower than $quantity
     $line->fk_product = $product->id;
     $line->ref_fourn = $ref_fourn;
     $localobject->lines[] = $line;
     $result = $localobject->create($user);
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertEquals(-1, $result);
     // must be -1 because quantity is lower than minimum of supplier price
     $sql = "DELETE FROM " . MAIN_DB_PREFIX . "commande_fournisseur where ref=''";
     $db->query($sql);
     // Create supplier order
     $localobject2 = new CommandeFournisseur($db);
     $localobject2->initAsSpecimen();
     // This create 5 lines of first product found for socid 1
     $localobject2->lines = array();
     // Overwrite lines of order
     $line = new CommandeFournisseurLigne($db);
     $line->desc = $langs->trans("Description") . " specimen line ok";
     $line->qty = 10;
     // So enough quantity
     $line->fk_product = $product->id;
     $line->ref_fourn = $ref_fourn;
     $localobject2->lines[] = $line;
     $result = $localobject2->create($user);
     print __METHOD__ . " result=" . $result . "\n";
     $this->assertGreaterThanOrEqual(0, $result);
     return $result;
 }