print $userstatic->getLoginUrl(1);
             print '</td>';
         }
         print "</table>";
     } else {
         print $langs->trans('None');
     }
     print "\n" . '<div class="tabsAction">' . "\n";
     print '<div class="inline-block divButAction"><a class="butAction" href="' . $_SERVER["PHP_SELF"] . '?socid=' . $soc->id . '">' . $langs->trans("Ok") . '</a></div>';
     print "\n</div><br>\n";
 } else {
     // View mode
     // Count total nb of records
     $nbtotalofrecords = 0;
     if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
         $nbtotalofrecords = $prodcustprice->fetch_all('', '', 0, 0, $filter);
     }
     $result = $prodcustprice->fetch_all($sortorder, $sortfield, $conf->liste_limit, $offset, $filter);
     if ($result < 0) {
         setEventMessage($prodcustprice->error, 'errors');
     }
     $option = '&search_soc=' . $search_soc . '&id=' . $object->id;
     print_barre_liste($langs->trans('PriceByCustomer'), $page, $_SERVEUR['PHP_SELF'], $option, $sortfield, $sortorder, '', count($prodcustprice->lines), $nbtotalofrecords);
     if (count($prodcustprice->lines) > 0) {
         print '<form action="' . $_SERVER["PHP_SELF"] . '?id=' . $object->id . '" method="POST">';
         print '<input type="hidden" name="id" value="' . $object->id . '">';
         print '<table class="noborder" width="100%">';
         print '<tr class="liste_titre">';
         print '<td>' . $langs->trans("Product") . '</td>';
         print '<td>' . $langs->trans("AppliedPricesFrom") . '</td>';
         print '<td align="center">' . $langs->trans("PriceBase") . '</td>';
 /**
  * Force update price on child price
  *
  * @param User $user that modifies
  * @param int $forceupdateaffiliate update price on each soc child
  * @return int <0 if KO, >0 if OK
  */
 function setPriceOnAffiliateThirdparty($user, $forceupdateaffiliate)
 {
     $error = 0;
     // Find all susidiaries
     $sql = "SELECT s.rowid";
     $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s";
     $sql .= " WHERE s.parent = " . $this->fk_soc;
     $sql .= " AND s.entity IN (" . getEntity('societe', 1) . ")";
     dol_syslog(get_class($this) . "::setPriceOnAffiliateThirdparty", LOG_DEBUG);
     $resql = $this->db->query($sql);
     if ($resql) {
         $this->lines = array();
         $num = $this->db->num_rows($resql);
         while (($obj = $this->db->fetch_object($resql)) && empty($error)) {
             // find if there is an existing line for the product and the subsidiaries
             $prodsocprice = new Productcustomerprice($this->db);
             $filter = array('t.fk_product' => $this->fk_product, 't.fk_soc' => $obj->rowid);
             $result = $prodsocprice->fetch_all('', '', 0, 0, $filter);
             if ($result < 0) {
                 $error++;
                 $this->error = $prodsocprice->error;
             } else {
                 // There is one line
                 if (count($prodsocprice->lines) > 0) {
                     // If force update => Update
                     if (!empty($forceupdateaffiliate)) {
                         $prodsocpriceupd = new Productcustomerprice($this->db);
                         $prodsocpriceupd->fetch($prodsocprice->lines[0]->id);
                         $prodsocpriceupd->price = $this->price;
                         $prodsocpriceupd->price_min = $this->price_min;
                         $prodsocpriceupd->price_base_type = $this->price_base_type;
                         $prodsocpriceupd->tva_tx = $this->tva_tx;
                         $prodsocpriceupd->recuperableonly = $this->recuperableonly;
                         $resultupd = $prodsocpriceupd->update($user, 0, $forceupdateaffiliate);
                         if ($result < 0) {
                             $error++;
                             $this->error = $prodsocpriceupd->error;
                         }
                     }
                 } else {
                     // If line do not exits then create it
                     $prodsocpricenew = new Productcustomerprice($this->db);
                     $prodsocpricenew->fk_soc = $obj->rowid;
                     $prodsocpricenew->fk_product = $this->fk_product;
                     $prodsocpricenew->price = $this->price;
                     $prodsocpricenew->price_min = $this->price_min;
                     $prodsocpricenew->price_base_type = $this->price_base_type;
                     $prodsocpricenew->tva_tx = $this->tva_tx;
                     $prodsocpricenew->recuperableonly = $this->recuperableonly;
                     $resultupd = $prodsocpricenew->create($user, 0, $forceupdateaffiliate);
                     if ($result < 0) {
                         $error++;
                         $this->error = $prodsocpriceupd->error;
                     }
                 }
             }
         }
         $this->db->free($resql);
         if (empty($error)) {
             return 1;
         } else {
             return -1;
         }
     } else {
         $this->error = "Error " . $this->db->lasterror();
         return -1;
     }
 }
 /**
  *  Return product info
  *  @param 		int		$idProd		Id of Product
  *  @return      array				Product info
  */
 public static function getProductbyId($idProd, $idCust)
 {
     global $db, $conf;
     if ($conf->global->PRODUIT_MULTIPRICES) {
         $sql = "SELECT price_level";
         $sql .= " FROM " . MAIN_DB_PREFIX . "societe";
         $sql .= " WHERE rowid = " . $idCust;
         $res = $db->query($sql);
         if ($res) {
             $obj = $db->fetch_object($res);
             if ($obj->price_level == NULL) {
                 $pricelevel = 1;
             } else {
                 $pricelevel = $obj->price_level;
             }
         }
     } else {
         $pricelevel = 1;
     }
     $function = "getProductbyId";
     $objp = new Product($db);
     $objp->fetch($idProd);
     $ret[0]["id"] = $objp->id;
     $ret[0]["ref"] = $objp->ref;
     $ret[0]["label"] = $objp->label;
     $ret[0]["description"] = $objp->description;
     $ret[0]["fk_product_type"] = $objp->type;
     $ret[0]["diff_price"] = 0;
     if (!empty($objp->multiprices[$pricelevel]) && $objp->multiprices[$pricelevel] > 0) {
         $ret[0]["tva_tx"] = $objp->multiprices_tva_tx[$pricelevel];
         $ret[0]["price_base_type"] = $objp->multiprices_base_type[$pricelevel];
         $ret[0]["price"] = $objp->multiprices[$pricelevel];
         $ret[0]["price_ttc"] = $objp->multiprices_ttc[$pricelevel];
         $ret[0]["price_min"] = $objp->multiprices_min[$pricelevel];
         $ret[0]["price_min_ttc"] = $objp->multiprices_min_ttc[$pricelevel];
     } else {
         if ($conf->global->PRODUIT_CUSTOMER_PRICES) {
             require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php';
             $prodcustprice = new Productcustomerprice($db);
             $filter = array('t.fk_product' => $objp->id, 't.fk_soc' => $idCust);
             $result = $prodcustprice->fetch_all('', '', 0, 0, $filter);
             if ($result >= 0) {
                 if (count($prodcustprice->lines) > 0) {
                     $ret[0]["price"] = $prodcustprice->lines[0]->price;
                     $ret[0]["price_ttc"] = $prodcustprice->lines[0]->price_ttc;
                     $ret[0]["price_min"] = $prodcustprice->lines[0]->price_min;
                     $ret[0]["price_min_ttc"] = $prodcustprice->lines[0]->price_min_ttc;
                     $ret[0]["price_base_type"] = $prodcustprice->lines[0]->price_base_type;
                     $ret[0]["tva_tx"] = $prodcustprice->lines[0]->tva_tx;
                 } else {
                     $ret[0]["price"] = $objp->price;
                     $ret[0]["price_ttc"] = $objp->price_ttc;
                     $ret[0]["price_min"] = $objp->price_min;
                     $ret[0]["price_min_ttc"] = $objp->price_base_type;
                     $ret[0]["price_base_type"] = $objp->price_base_type;
                     $ret[0]["tva_tx"] = $objp->tva_tx;
                 }
             }
         } else {
             $ret[0]["tva_tx"] = $objp->tva_tx;
             $ret[0]["price_base_type"] = $objp->price_base_type;
             $ret[0]["price"] = $objp->price;
             $ret[0]["price_ttc"] = $objp->price_ttc;
             $ret[0]["price_min"] = $objp->price_min;
             $ret[0]["price_min_ttc"] = $objp->price_min_ttc;
             if ($conf->global->PRODUIT_MULTIPRICES) {
                 $ret[0]["diff_price"] = 1;
             }
         }
     }
     $ret[0]["localtax1_tx"] = $objp->localtax1_tx;
     $ret[0]["localtax2_tx"] = $objp->localtax2_tx;
     $ret[0]["image"] = self::getImageProduct($objp->id, false);
     $ret[0]["thumb"] = self::getImageProduct($objp->id, true);
     return Errorcontrol($ret, $function);
 }
示例#4
0
     $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
     $price_min = $prod->multiprices_min[$object->thirdparty->price_level];
     $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
     if (!empty($conf->global->PRODUIT_MULTIPRICES_USE_VAT_PER_LEVEL)) {
         if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) {
             $tva_tx = $prod->multiprices_tva_tx[$object->thirdparty->price_level];
         }
         if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) {
             $tva_npr = $prod->multiprices_recuperableonly[$object->thirdparty->price_level];
         }
     }
 } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
     require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php';
     $prodcustprice = new Productcustomerprice($db);
     $filter = array('t.fk_product' => $prod->id, 't.fk_soc' => $object->thirdparty->id);
     $result = $prodcustprice->fetch_all('', '', 0, 0, $filter);
     if ($result) {
         if (count($prodcustprice->lines) > 0) {
             $pu_ht = price($prodcustprice->lines[0]->price);
             $pu_ttc = price($prodcustprice->lines[0]->price_ttc);
             $price_base_type = $prodcustprice->lines[0]->price_base_type;
             $prod->tva_tx = $prodcustprice->lines[0]->tva_tx;
         }
     }
 }
 // if price ht was forced (ie: from gui when calculated by margin rate and cost price)
 if (!empty($price_ht)) {
     $pu_ht = price2num($price_ht, 'MU');
     $pu_ttc = price2num($pu_ht * (1 + $tva_tx / 100), 'MU');
 } elseif ($tva_tx != $prod->tva_tx) {
     if ($price_base_type != 'HT') {
 /**
  * Adds a product to the order
  *
  * @param Commande $object Order object
  * @param Product $prod Product to add
  * @param int $qty Quantity of the product
  * @throws Exception
  */
 public static function addOrderLine(Commande $object, Product $prod, $qty)
 {
     global $db, $conf, $mysoc, $langs;
     require_once DOL_DOCUMENT_ROOT . '/core/lib/admin.lib.php';
     $tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id);
     $tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id);
     if (!empty($conf->global->PRODUIT_MULTIPRICES) && !empty($object->thirdparty->price_level)) {
         $pu_ht = $prod->multiprices[$object->thirdparty->price_level];
         $pu_ttc = $prod->multiprices_ttc[$object->thirdparty->price_level];
         $price_base_type = $prod->multiprices_base_type[$object->thirdparty->price_level];
         if (isset($prod->multiprices_tva_tx[$object->thirdparty->price_level])) {
             $tva_tx = $prod->multiprices_tva_tx[$object->thirdparty->price_level];
         }
         if (isset($prod->multiprices_recuperableonly[$object->thirdparty->price_level])) {
             $tva_npr = $prod->multiprices_recuperableonly[$object->thirdparty->price_level];
         }
     } elseif (!empty($conf->global->PRODUIT_CUSTOMER_PRICES)) {
         require_once DOL_DOCUMENT_ROOT . '/product/class/productcustomerprice.class.php';
         $prodcustprice = new Productcustomerprice($db);
         $filter = array('t.fk_product' => $prod->id, 't.fk_soc' => $object->thirdparty->id);
         $result = $prodcustprice->fetch_all('', '', 0, 0, $filter);
         if ($result >= 0) {
             if (count($prodcustprice->lines) > 0) {
                 $pu_ht = price($prodcustprice->lines[0]->price);
                 $pu_ttc = price($prodcustprice->lines[0]->price_ttc);
                 $price_base_type = $prodcustprice->lines[0]->price_base_type;
                 $prod->tva_tx = $prodcustprice->lines[0]->tva_tx;
             } else {
                 $pu_ht = $prod->price;
                 $pu_ttc = $prod->price_ttc;
                 $price_base_type = $prod->price_base_type;
             }
         } else {
             throw new Exception($prodcustprice->error);
         }
     } else {
         $pu_ht = $prod->price;
         $pu_ttc = $prod->price_ttc;
         $price_base_type = $prod->price_base_type;
     }
     // if price ht is forced (ie: calculated by margin rate and cost price)
     if (!empty($price_ht)) {
         $pu_ht = price2num($price_ht, 'MU');
         $pu_ttc = price2num($pu_ht * (1 + $tva_tx / 100), 'MU');
     } elseif ($tva_tx != $prod->tva_tx) {
         if ($price_base_type != 'HT') {
             $pu_ht = price2num($pu_ttc / (1 + $tva_tx / 100), 'MU');
         } else {
             $pu_ttc = price2num($pu_ht * (1 + $tva_tx / 100), 'MU');
         }
     }
     // Define output language
     if (!empty($conf->global->MAIN_MULTILANGS) && !empty($conf->global->PRODUIT_TEXTS_IN_THIRDPARTY_LANGUAGE)) {
         $outputlangs = $langs;
         $newlang = '';
         if (empty($newlang) && GETPOST('lang_id')) {
             $newlang = GETPOST('lang_id');
         }
         if (empty($newlang)) {
             $newlang = $object->thirdparty->default_lang;
         }
         if (!empty($newlang)) {
             $outputlangs = new Translate("", $conf);
             $outputlangs->setDefaultLang($newlang);
         }
         $desc = !empty($prod->multilangs[$outputlangs->defaultlang]["description"]) ? $prod->multilangs[$outputlangs->defaultlang]["description"] : $prod->description;
     } else {
         $desc = $prod->description;
     }
     // Add custom code and origin country into description
     if (empty($conf->global->MAIN_PRODUCT_DISABLE_CUSTOMCOUNTRYCODE) && (!empty($prod->customcode) || !empty($prod->country_code))) {
         $tmptxt = '(';
         if (!empty($prod->customcode)) {
             $tmptxt .= $langs->transnoentitiesnoconv("CustomCode") . ': ' . $prod->customcode;
         }
         if (!empty($prod->customcode) && !empty($prod->country_code)) {
             $tmptxt .= ' - ';
         }
         if (!empty($prod->country_code)) {
             $tmptxt .= $langs->transnoentitiesnoconv("CountryOrigin") . ': ' . getCountry($prod->country_code, 0, $db, $langs, 0);
         }
         $tmptxt .= ')';
         $desc = dol_concatdesc($desc, $tmptxt);
     }
     //3.9.0 version added support for price units
     if (versioncompare(versiondolibarrarray(), array(3, 9, 0)) >= 0) {
         $fk_unit = $prod->fk_unit;
     } else {
         $fk_unit = null;
     }
     // Local Taxes
     $localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty);
     $localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty);
     $info_bits = 0;
     if ($tva_npr) {
         $info_bits |= 0x1;
     }
     //Percent remise
     if (!empty($object->thirdparty->remise_percent)) {
         $percent_remise = $object->thirdparty->remise_percent;
     } else {
         $percent_remise = 0;
     }
     // Insert line
     $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $localtax1_tx, $localtax2_tx, $prod->id, $percent_remise, $info_bits, 0, $price_base_type, $pu_ttc, '', '', $prod->type, -1, 0, 0, null, 0, '', 0, $fk_unit);
     if ($result < 0) {
         throw new Exception($langs->trans('ErrorAddOrderLine', $prod->ref));
     }
 }