setEventMessage($prodcustprice->error, 'mesgs'); } else { setEventMessage($langs->trans('Delete'), 'errors'); } $action = ''; } if ($action == 'update_customer_price_confirm' && !$_POST["cancel"] && ($user->rights->produit->creer || $user->rights->service->creer)) { $prodcustprice->fetch(GETPOST('lineid', 'int')); $update_child_soc = GETPOST('updatechildprice'); // update price by customer $prodcustprice->price = price2num(GETPOST("price"), 'MU'); $prodcustprice->price_min = price2num(GETPOST("price_min"), 'MU'); $prodcustprice->price_base_type = GETPOST("price_base_type", 'alpha'); $prodcustprice->tva_tx = str_replace('*', '', GETPOST("tva_tx")); $prodcustprice->recuperableonly = preg_match('/\\*/', GETPOST("tva_tx")) ? 1 : 0; $result = $prodcustprice->update($user, 0, $update_child_soc); if ($result < 0) { setEventMessage($prodcustprice->error, 'errors'); } else { setEventMessage($langs->trans('Save'), 'mesgs'); } $action = ''; } /* * View */ $form = new Form($db); $soc = new Societe($db); $result = $soc->fetch($socid); llxHeader("", $langs->trans("ThirdParty") . '-' . $langs->trans('PriceByCustomer')); if (!empty($conf->notification->enabled)) {
/** * 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; } }