Ejemplo n.º 1
0
 /////
 if ($idprod > 0) {
     if (!$optimizar) {
         $res = $productsupplier->fetch($idprod);
         $label = $productsupplier->libelle;
         $desc = $productsupplier->description;
         if (trim($product_desc) != trim($desc)) {
             $desc = dol_concatdesc($desc, $product_desc);
         }
         $tva_tx = get_default_tva($object->thirdparty, $mysoc, $productsupplier->id, $idpfp);
         $type = $productsupplier->type;
         // Local Taxes
         $localtax1_tx = get_localtax($tva_tx, 1, $mysoc, $object->thirdparty);
         $localtax2_tx = get_localtax($tva_tx, 2, $mysoc, $object->thirdparty);
         $saltar = false;
         $result = $object->addline($desc, $productsupplier->fourn_pu, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $productsupplier->id, $idpfp, $productsupplier->fourn_ref, $remise_percent, 'HT', $type);
     } else {
         $total_ht = (double) $pfp_price;
         $total_tva = (double) $pfp_price * 16 / 100;
         $total_ttc = $total_ht + $total_tva;
         $sql = "INSERT INTO " . MAIN_DB_PREFIX . "commande_fournisseurdet";
         $sql .= " (fk_commande, label, description, date_start, date_end,";
         $sql .= " fk_product, product_type,";
         $sql .= " qty, tva_tx, remise_percent, subprice, ref,";
         $sql .= " total_ht, total_tva, total_ttc";
         $sql .= ")";
         $sql .= " VALUES (" . $object->id . ", '" . $p_label . "','" . $p_desc . "',";
         $sql .= " null,";
         $sql .= " null,";
         // Check:
         if ($idprod) {
Ejemplo n.º 2
0
	function ProductCommande($user, $fk_product)
	{
		include_once(DOL_DOCUMENT_ROOT."/fourn/fournisseur.commande.class.php");
		include_once(DOL_DOCUMENT_ROOT."/product/class/product.class.php");

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

		$nbc = $this->nb_open_commande();

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

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

			$idc = $this->single_open_commande;
		}

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

			$commf->fetch($idc);
			$commf->addline("Toto",120,1,$prod->tva, $prod->id, 0, $prod->ref_fourn);
		}
	}
Ejemplo n.º 3
0
 $i = 0;
 $orders = array();
 $suppliersid = array_keys($suppliers);
 foreach ($suppliers as $supplier) {
     $order = new CommandeFournisseur($db);
     // Check if an order for the supplier exists
     $sql = "SELECT rowid FROM " . MAIN_DB_PREFIX . "commande_fournisseur";
     $sql .= " WHERE fk_soc = " . $suppliersid[$i];
     $sql .= " AND source = 42 AND fk_statut = 0";
     $sql .= " ORDER BY date_creation DESC";
     $resql = $db->query($sql);
     if ($resql && $db->num_rows($resql) > 0) {
         $obj = $db->fetch_object($resql);
         $order->fetch($obj->rowid);
         foreach ($supplier['lines'] as $line) {
             $result = $order->addline($line->desc, $line->subprice, $line->qty, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->fk_product, 0, $line->ref_fourn, $line->remise_percent, 'HT', 0, $line->info_bits);
         }
         if ($result < 0) {
             $fail++;
             $msg = $langs->trans('OrderFail') . "&nbsp;:&nbsp;";
             $msg .= $order->error;
             setEventMessages($msg, null, 'errors');
         } else {
             $id = $result;
         }
     } else {
         $order->socid = $suppliersid[$i];
         $order->fetch_thirdparty();
         //trick to know which orders have been generated this way
         $order->source = 42;
         foreach ($supplier['lines'] as $line) {
Ejemplo n.º 4
0
     		}*/
     if ($idprod > 0) {
         $res = $product->fetch($idprod);
         // cas special pour lequel on a les meme reference que le fournisseur
         // $label = '['.$nv_prod->ref.'] - '. $nv_prod->libelle;
         $label = $product->libelle;
         $desc = $product->description;
         $desc .= $product->description && $_POST['np_desc'] ? "\n" : "";
         $desc .= $_POST['np_desc'];
         $remise_percent = $_POST["remise_percent"] ? $_POST["remise_percent"] : $_POST["p_remise_percent"];
         $tva_tx = get_default_tva($object->thirdparty, $mysoc, $product->id);
         $type = $product->type;
         // Local Taxes
         $localtax1_tx = get_localtax($tva_tx, 1, $mysoc);
         $localtax2_tx = get_localtax($tva_tx, 2, $mysoc);
         $result = $object->addline($desc, $pu, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $product->id, $_POST['idprodfournprice'], $product->fourn_ref, $remise_percent, 'HT', $type);
     }
     if ($idprod == -1) {
         // Quantity too low
         $langs->load("errors");
         $mesg = '<div class="error">' . $langs->trans("ErrorQtyTooLowForThisSupplier") . '</div>';
     }
 } else {
     $type = $_POST["type"];
     $desc = $_POST['dp_desc'];
     $tva_tx = price2num($_POST['tva_tx']);
     // Local Taxes
     $localtax1_tx = get_localtax($tva_tx, 1, $object->client);
     $localtax2_tx = get_localtax($tva_tx, 2, $object->client);
     if (!$_POST['dp_desc']) {
         $mesg = '<div class="error">' . $langs->trans("ErrorFieldRequired", $langs->transnoentities("Label")) . '</div>';
 private function addCommandeFourn(&$PDOdb, $ofLigne, $resultatSQL)
 {
     global $db, $user;
     dol_include_once("fourn/class/fournisseur.commande.class.php");
     // On cherche s'il existe une commande pour ce fournisseur
     $sql = "SELECT rowid";
     $sql .= " FROM " . MAIN_DB_PREFIX . "commande_fournisseur";
     $sql .= " WHERE fk_soc = " . $resultatSQL->fk_soc;
     $sql .= " AND fk_statut = 0";
     //uniquement brouillon
     $sql .= " ORDER BY rowid DESC";
     $sql .= " LIMIT 1";
     $resql = $db->query($sql);
     $res = $db->fetch_object($resql);
     if ($res) {
         // Il existe une commande, on la charge
         $com = new CommandeFournisseur($db);
         $com->fetch($res->rowid);
     } else {
         // Il n'existe aucune commande pour ce fournisseur donc on en crée une nouvelle
         $com = new CommandeFournisseur($db);
         $com->socid = $resultatSQL->fk_soc;
         $com->create($user);
     }
     // On cherche si ce produit existe déjà dans la commande, si oui, : "updateline"
     foreach ($com->lines as $line) {
         if ($line->fk_product == $resultatSQL->fk_product) {
             $com->updateline($line->id, $line->desc, $line->subprice, $line->qty + $ofLigne->qty, $line->remise_percent, $line->tva_tx);
             $done = true;
             break;
         }
     }
     if (!$done) {
         // Si le produit n'existe pas déjà dans la commande, on l'ajoute à cette commande
         $com->addline($desc, $resultatSQL->price / $resultatSQL->quantity, $ofLigne->qty, $txtva, 0, 0, $resultatSQL->fk_product, $resultatSQL->rowid);
     }
     //Création association element_element entre la commande fournisseur et l'OF
     $this->addElementElement($PDOdb, $com, $ofLigne);
 }