static function add(&$PDOdb, $fk_product, $qty, $price, $log_type = 'PA', $fk_supplier = 0)
 {
     if (empty($price) || empty($qty)) {
         return false;
     }
     $cpl = new TProductCostPriceLog();
     $cpl->fk_product = $fk_product;
     $cpl->fk_supplier = $fk_supplier;
     $cpl->price = $price;
     $cpl->qty = $qty;
     $cpl->log_type = $log_type;
     return $cpl->save($PDOdb);
 }
    /**
     * Overloading the doActions function : replacing the parent's function with the one below
     *
     * @param   array()         $parameters     Hook metadatas (context, etc...)
     * @param   CommonObject    &$object        The object to process (an invoice if you are in invoice module, a propale in propale's module, etc...)
     * @param   string          &$action        Current action (if set). Generally create or edit or null
     * @param   HookManager     $hookmanager    Hook manager propagated to allow calling another hook
     * @return  int                             < 0 on error, 0 on success, 1 to replace standard code
     */
    function addMoreActionsButtons($parameters, &$object, &$action, $hookmanager)
    {
        $error = 0;
        if (in_array('pricesuppliercard', explode(':', $parameters['context']))) {
            global $conf, $user, $langs;
            if (!empty($conf->global->MANDARIN_TRACE_COST_PRICE) && !empty($user->rights->mandarin->graph->product_cost_price)) {
                define('INC_FROM_DOLIBARR', true);
                dol_include_once('/mandarin/config.php');
                dol_include_once('/mandarin/class/costpricelog.class.php');
                $PDOdb = new TPDOdb();
                $TData = TProductCostPriceLog::getDataForProduct($PDOdb, $object->id);
                if (!empty($TData)) {
                    $l = new TListviewTBS('graphrate');
                    echo $l->renderArray($PDOdb, $TData, array('type' => 'chart', 'curveType' => 'none', 'liste' => array('titre' => $langs->trans('GraphTraceCostPrice')), 'title' => array('PA' => $langs->transnoentities('PricePA'), 'PMP' => $langs->transnoentities('PricePMP'), 'OF' => $langs->transnoentities('PriceOF'))));
                    ?>
					<script type="text/javascript">
						$(document).ready(function() {
							$('#div_query_chartgraphrate').insertAfter('div.fiche:first');
						});
						
					</script>
					<?php 
                }
            }
        }
        if (!$error) {
            return 0;
            // or return 1 to replace standard code
        } else {
            $this->errors[] = 'Error message';
            return -1;
        }
    }
 function logPrice($fk_product, $qty, $price, $log_type, $fk_supplier)
 {
     global $conf;
     if (!empty($conf->global->MANDARIN_TRACE_COST_PRICE)) {
         define('INC_FROM_DOLIBARR', true);
         dol_include_once('/mandarin/config.php');
         dol_include_once('/mandarin/class/costpricelog.class.php');
         $PDOdb = new TPDOdb();
         TProductCostPriceLog::add($PDOdb, $fk_product, $qty, $price, $log_type, $fk_supplier);
     }
 }
if (!$user->admin) {
    accessforbidden();
}
// Parameters
$action = GETPOST('action', 'alpha');
/*
 * Actions
 */
if (preg_match('/set_(.*)/', $action, $reg)) {
    $code = $reg[1];
    if (dolibarr_set_const($db, $code, GETPOST($code) == 'yes' ? 1 : 0, 'entier', 0, '', $conf->entity) > 0) {
        if ($code == 'MANDARIN_TRACE_COST_PRICE' && GETPOST($code) == 'yes') {
            define('INC_FROM_DOLIBARR', true);
            dol_include_once('/mandarin/config.php');
            dol_include_once('/mandarin/class/costpricelog.class.php');
            $o = new TProductCostPriceLog();
            $PDOdb = new TPDOdb();
            //			$PDOdb->debug =true;
            $o->init_db_by_vars($PDOdb);
        }
        header("Location: " . $_SERVER["PHP_SELF"]);
        exit;
    } else {
        dol_print_error($db);
    }
}
if (preg_match('/del_(.*)/', $action, $reg)) {
    $code = $reg[1];
    if (dolibarr_del_const($db, $code, 0) > 0) {
        Header("Location: " . $_SERVER["PHP_SELF"]);
        exit;