if ($tva_tx != $object->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'); } } if (GETPOST('propalid') > 0) { $result = $propal->addline($desc, $pu_ht, GETPOST('qty'), $tva_tx, $localtax1_tx, $localtax2_tx, $object->id, GETPOST('remise_percent'), $price_base_type, $pu_ttc, 0, 0, -1, 0, 0, 0, 0, '', '', '', 0, $object->fk_unit); if ($result > 0) { header("Location: " . DOL_URL_ROOT . "/comm/propal.php?id=" . $propal->id); return; } setEventMessages($langs->trans("ErrorUnknown") . ": {$result}", null, 'errors'); } elseif (GETPOST('commandeid') > 0) { $result = $commande->addline($desc, $pu_ht, GETPOST('qty'), $tva_tx, $localtax1_tx, $localtax2_tx, $object->id, GETPOST('remise_percent'), '', '', $price_base_type, $pu_ttc, '', '', 0, -1, 0, 0, null, 0, '', 0, $object->fk_unit); if ($result > 0) { header("Location: " . DOL_URL_ROOT . "/commande/card.php?id=" . $commande->id); exit; } } elseif (GETPOST('factureid') > 0) { $result = $facture->addline($desc, $pu_ht, GETPOST('qty'), $tva_tx, $localtax1_tx, $localtax2_tx, $object->id, GETPOST('remise_percent'), '', '', '', '', '', $price_base_type, $pu_ttc, Facture::TYPE_STANDARD, -1, 0, '', 0, 0, null, 0, '', 0, 100, '', $object->fk_unit); if ($result > 0) { header("Location: " . DOL_URL_ROOT . "/compta/facture.php?facid=" . $facture->id); exit; } } } else { $action = ""; setEventMessages($langs->trans("WarningSelectOneDocument"), null, 'warnings'); }
{ $pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU'); } else { $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU'); } } $result = $commande->addline($commande->id, $desc, $pu_ht, $_POST["qty"], $tva_tx, $localtax1_tx, // localtax1 $localtax2_tx, // localtax2 $prod->id, $_POST["remise_percent"], '', '', //Todo: voir si fk_remise_except est encore valable car n'apparait plus dans les propales $price_base_type, $pu_ttc ); if ($result > 0) { Header("Location: ".DOL_URL_ROOT."/commande/fiche.php?id=".$commande->id); exit; } } /*
/** * 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)); } }
$com->note = 'A comment'; $com->source = 1; $com->fk_project = 0; $com->remise_percent = 0; $db->begin(); $result = $com->create($user); if ($result >= 0) { $result = $com->valid($user); if ($result > 0) { $nbp = rand(2, 5); $xnbp = 0; while ($xnbp < $nbp) { $prodid = rand(1, $num_prods); $product = new Product($db); $result = $product->fetch($prodids[$prodid]); $result = $com->addline($product->description, $product->price, rand(1, 5), 0, 0, 0, $prodids[$prodid], 0, 0, 0, $product->price_base_type, $product->price_ttc, '', '', $product->type); if ($result < 0) { dol_print_error($db, $propal->error); } $xnbp++; } $db->commit(); print " OK with ref " . $com->ref . "\n"; } else { print " KO\n"; $db->rollback(); dol_print_error($db, $com->error); } } else { print " KO\n"; $db->rollback();
$pu_ht = price2num($pu_ttc / (1 + ($tva_tx/100)), 'MU'); } else { $pu_ttc = price2num($pu_ht * (1 + ($tva_tx/100)), 'MU'); } } $result = $commande->addline( $commande->id, $desc, $pu_ht, GETPOST('qty'), $tva_tx, $localtax1_tx, // localtax1 $localtax2_tx, // localtax2 $prod->id, GETPOST('remise_percent'), '', '', // TODO voir si fk_remise_except est encore valable car n'apparait plus dans les propales $price_base_type, $pu_ttc ); if ($result > 0) { Header("Location: ".DOL_URL_ROOT."/commande/fiche.php?id=".$commande->id); exit; } }
// If multiprice if ($conf->global->PRODUIT_MULTIPRICES && $soc->price_level) { $pu_ht = $prod->multiprices[$soc->price_level]; $pu_ttc = $prod->multiprices_ttc[$soc->price_level]; $price_base_type = $prod->multiprices_base_type[$soc->price_level]; } // On reevalue prix selon taux tva car taux tva transaction peut etre different // de ceux du produit par defaut (par exemple si pays different entre vendeur et acheteur). if ($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'); } } $result = $commande->addline($commande->id, $desc, $pu_ht, $_POST["qty"], $tva_tx, $localtax1_tx, $localtax2_tx, $prod->id, $_POST["remise_percent"], '', '', $price_base_type, $pu_ttc); if ($result > 0) { Header("Location: " . DOL_URL_ROOT . "/commande/fiche.php?id=" . $commande->id); exit; } } /* * Ajout du produit dans une facture */ if ($action == 'addinfacture' && $user->rights->facture->creer) { $facture = new Facture($db); $result = $facture->fetch($_POST["factureid"]); if ($result <= 0) { dol_print_error($db, $facture->error); exit; }