diff --git a/ChangeLog b/ChangeLog index 68ccd4e50df71cfb65b2ffdcfe9c6c6489c52c5f..c52a486523cefdfafd50694147d28ee3e1aa3e1b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -132,6 +132,7 @@ NEW: Use ellipsis truncation on too large left menu text NEW: When a new field to show into lists is selected, the form is automatically submited and field added. NEW: When creating a template invoice from a draft invoice, if there is link to contract on draft invoice, link is kept on template invoice. NEW: When emailing is not sent completely, show progression. +NEW: Add entity field in llx_societe_remise_except and llx_societe_remise For developers: NEW: Add a css class style called 'reposition', so when clicking on a link with this class will move scrollbarr to be placed at same page location. diff --git a/htdocs/comm/remise.php b/htdocs/comm/remise.php index a5c0a89f29dff645be483be76ed96bc344d27bcd..4ea377a44878e394fb395cedec053977adb2118a 100644 --- a/htdocs/comm/remise.php +++ b/htdocs/comm/remise.php @@ -100,8 +100,8 @@ if ($socid > 0) $head = societe_prepare_head($object); - - + + print '<form method="POST" action="remise.php?id='.$object->id.'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="action" value="setremise">'; @@ -110,9 +110,9 @@ if ($socid > 0) dol_fiche_head($head, 'relativediscount', $langs->trans("ThirdParty"),0,'company'); dol_banner_tab($object, 'socid', '', ($user->societe_id?0:1), 'rowid', 'nom'); - + print '<div class="fichecenter">'; - + print '<div class="underbanner clearboth"></div>'; print '<table class="border centpercent">'; @@ -138,9 +138,9 @@ if ($socid > 0) print "</table>"; print '</div>'; - + dol_fiche_end(); - + print '<div class="center">'; print '<input type="submit" class="button" value="'.$langs->trans("Modify").'">'; if (! empty($backtopage)) @@ -161,7 +161,8 @@ if ($socid > 0) $sql = "SELECT rc.rowid, rc.remise_client as remise_percent, rc.note, rc.datec as dc,"; $sql.= " u.login, u.rowid as user_id"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise as rc, ".MAIN_DB_PREFIX."user as u"; - $sql.= " WHERE rc.fk_soc =". $object->id; + $sql.= " WHERE rc.fk_soc = " . $object->id; + $sql.= " AND rc.entity = " . $conf->entity; $sql.= " AND u.rowid = rc.fk_user_author"; $sql.= " ORDER BY rc.datec DESC"; diff --git a/htdocs/comm/remx.php b/htdocs/comm/remx.php index 0b9d85dba49fbc1a9bb0bde94cc941ed81e38cf1..23a4cd67d378fbb172837156eb2c52923a49a2e9 100644 --- a/htdocs/comm/remx.php +++ b/htdocs/comm/remx.php @@ -248,7 +248,8 @@ if ($socid > 0) $remise_all=$remise_user=0; $sql = "SELECT SUM(rc.amount_ht) as amount, rc.fk_user"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc"; - $sql.= " WHERE rc.fk_soc =". $object->id; + $sql.= " WHERE rc.fk_soc = " . $object->id; + $sql.= " AND rc.entity = " . $conf->entity; $sql.= " AND (fk_facture_line IS NULL AND fk_facture IS NULL)"; $sql.= " GROUP BY rc.fk_user"; $resql=$db->query($sql); @@ -327,7 +328,8 @@ if ($socid > 0) $sql.= " fa.facnumber as ref, fa.type as type"; $sql.= " FROM ".MAIN_DB_PREFIX."user as u, ".MAIN_DB_PREFIX."societe_remise_except as rc"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as fa ON rc.fk_facture_source = fa.rowid"; - $sql.= " WHERE rc.fk_soc =". $object->id; + $sql.= " WHERE rc.fk_soc = " . $object->id; + $sql.= " AND rc.entity = " . $conf->entity; $sql.= " AND u.rowid = rc.fk_user"; $sql.= " AND (rc.fk_facture_line IS NULL AND rc.fk_facture IS NULL)"; $sql.= " ORDER BY rc.datec DESC"; diff --git a/htdocs/core/class/discount.class.php b/htdocs/core/class/discount.class.php index e256dbfb649912de730f27b91a12b1613488fdb9..9a59801f720fbaafdc84276a5a80bc1221725e28 100644 --- a/htdocs/core/class/discount.class.php +++ b/htdocs/core/class/discount.class.php @@ -66,6 +66,8 @@ class DiscountAbsolute */ function fetch($rowid,$fk_facture_source=0) { + global $conf; + // Check parameters if (! $rowid && ! $fk_facture_source) { @@ -81,9 +83,9 @@ class DiscountAbsolute $sql.= " f.facnumber as ref_facture_source"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as sr"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."facture as f ON sr.fk_facture_source = f.rowid"; - $sql.= " WHERE"; - if ($rowid) $sql.= " sr.rowid=".$rowid; - if ($fk_facture_source) $sql.= " sr.fk_facture_source=".$fk_facture_source; + $sql.= " WHERE sr.entity = " . $conf->entity; + if ($rowid) $sql.= " AND sr.rowid=".$rowid; + if ($fk_facture_source) $sql.= " AND sr.fk_facture_source=".$fk_facture_source; dol_syslog(get_class($this)."::fetch", LOG_DEBUG); $resql = $this->db->query($sql); @@ -150,11 +152,11 @@ class DiscountAbsolute // Insert request $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_except"; - $sql.= " (datec, fk_soc, fk_user, description,"; + $sql.= " (entity, datec, fk_soc, fk_user, description,"; $sql.= " amount_ht, amount_tva, amount_ttc, tva_tx,"; $sql.= " fk_facture_source"; $sql.= ")"; - $sql.= " VALUES ('".$this->db->idate($this->datec!=''?$this->datec:dol_now())."', ".$this->fk_soc.", ".$user->id.", '".$this->db->escape($this->description)."',"; + $sql.= " VALUES (".$conf->entity.", '".$this->db->idate($this->datec!=''?$this->datec:dol_now())."', ".$this->fk_soc.", ".$user->id.", '".$this->db->escape($this->description)."',"; $sql.= " ".$this->amount_ht.", ".$this->amount_tva.", ".$this->amount_ttc.", ".$this->tva_tx.","; $sql.= " ".($this->fk_facture_source?"'".$this->fk_facture_source."'":"null"); $sql.= ")"; @@ -343,10 +345,13 @@ class DiscountAbsolute */ function getAvailableDiscounts($company='', $user='',$filter='', $maxvalue=0) { + global $conf; + $sql = "SELECT SUM(rc.amount_ttc) as amount"; // $sql = "SELECT rc.amount_ttc as amount"; $sql.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as rc"; - $sql.= " WHERE (rc.fk_facture IS NULL AND rc.fk_facture_line IS NULL)"; // Available + $sql.= " WHERE rc.entity = " . $conf->entity; + $sql.= " AND (rc.fk_facture IS NULL AND rc.fk_facture_line IS NULL)"; // Available if (is_object($company)) $sql.= " AND rc.fk_soc = ".$company->id; if (is_object($user)) $sql.= " AND rc.fk_user = ".$user->id; if ($filter) $sql.=' AND ('.$filter.')'; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 4cff2dcc89e7d2875670b0dd1dacbc06fc251e86..66175d60ecd321a33247678744d761c8ca6ed55d 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -1118,7 +1118,8 @@ class Form $sql = "SELECT re.rowid, re.amount_ht, re.amount_tva, re.amount_ttc,"; $sql.= " re.description, re.fk_facture_source"; $sql.= " FROM ".MAIN_DB_PREFIX ."societe_remise_except as re"; - $sql.= " WHERE fk_soc = ".(int) $socid; + $sql.= " WHERE re.fk_soc = ".(int) $socid; + $sql.= " AND re.entity = " . $conf->entity; if ($filter) $sql.= " AND ".$filter; $sql.= " ORDER BY re.description ASC"; @@ -5166,9 +5167,9 @@ class Form print '<br>'; print load_fiche_titre($langs->trans('RelatedObjects'), $morehtmlright, ''); - + print '<table class="noborder allwidth">'; - + print '<tr class="liste_titre">'; print '<td>'.$langs->trans("Type").'</td>'; print '<td>'.$langs->trans("Ref").'</td>'; @@ -5178,9 +5179,9 @@ class Form print '<td align="right">'.$langs->trans("Status").'</td>'; print '<td></td>'; print '</tr>'; - + $numoutput=0; - + foreach($object->linkedObjects as $objecttype => $objects) { $tplpath = $element = $subelement = $objecttype; @@ -5240,7 +5241,7 @@ class Form foreach($dirtpls as $reldir) { $res=@include dol_buildpath($reldir.'/'.$tplname.'.tpl.php'); - if ($res) + if ($res) { $numoutput++; break; @@ -5252,7 +5253,7 @@ class Form { print '<tr><td class="opacitymedium" colspan="7">'.$langs->trans("None").'</td></tr>'; } - + print '</table>'; return $num; @@ -5261,7 +5262,7 @@ class Form /** * Show block with links to link to other objects. - * + * * @param CommonObject $object Object we want to show links to * @param array $restrictlinksto Restrict links to some elements, for exemple array('order') or array('supplier_order'). null or array() if no restriction. * @param array $excludelinksto Do not show links of this type, for exemple array('order') or array('supplier_order'). null or array() if no exclusion. @@ -5286,12 +5287,12 @@ class Form 'order_supplier'=>array('enabled'=>$conf->fournisseur->commande->enabled , 'perms'=>1, 'label'=>'LinkToSupplierOrder', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."commande_fournisseur as t WHERE t.fk_soc = s.rowid AND t.fk_soc = ".$object->thirdparty->id), 'invoice_supplier'=>array('enabled'=>$conf->fournisseur->facture->enabled , 'perms'=>1, 'label'=>'LinkToSupplierInvoice', 'sql'=>"SELECT s.rowid as socid, s.nom as name, s.client, t.rowid, t.ref, t.ref_supplier, t.total_ht FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."facture_fourn as t WHERE t.fk_soc = s.rowid AND t.fk_soc = ".$object->thirdparty->id) ); - + foreach($possiblelinks as $key => $possiblelink) { $num = 0; - + if (! empty($possiblelink['perms']) && (empty($restrictlinksto) || in_array($key, $restrictlinksto)) && (empty($excludelinksto) || ! in_array($key, $excludelinksto))) { print '<div id="'.$key.'list"'.(empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)?' style="display:none"':'').'>'; @@ -5301,7 +5302,7 @@ class Form { $num = $this->db->num_rows($resqllist); $i = 0; - + print '<br><form action="'.$_SERVER["PHP_SELF"].'" method="POST" name="formlinked'.$key.'">'; print '<input type="hidden" name="id" value="'.$object->id.'">'; print '<input type="hidden" name="action" value="addlink">'; @@ -5317,7 +5318,7 @@ class Form while ($i < $num) { $objp = $this->db->fetch_object($resqlorderlist); - + $var = ! $var; print '<tr ' . $bc [$var] . '>'; print '<td aling="left">'; @@ -5332,7 +5333,7 @@ class Form } print '</table>'; print '<div class="center"><input type="submit" class="button" value="' . $langs->trans('ToLink') . '"> <input type="submit" class="button" name="cancel" value="' . $langs->trans('Cancel') . '"></div>'; - + print '</form>'; $this->db->free($resqllist); } else { @@ -5341,8 +5342,8 @@ class Form print '</div>'; if ($num > 0) { - } - + } + //$linktoelem.=($linktoelem?' ':''); if ($num > 0) $linktoelem.='<li><a href="#linkto'.$key.'" class="linkto dropdowncloseonclick" rel="'.$key.'">' . $langs->trans($possiblelink['label']) .' ('.$num.')</a></li>'; //else $linktoelem.=$langs->trans($possiblelink['label']); @@ -5360,7 +5361,7 @@ class Form </div> </dd> </dl>'; - + print '<!-- Add js to show linkto box --> <script type="text/javascript" language="javascript"> jQuery(document).ready(function() { @@ -5372,7 +5373,7 @@ class Form }); </script> '; - + return $linktoelem; } @@ -5667,7 +5668,7 @@ class Form { if ($file && file_exists($dir."/".$file)) { - if ($addlinktofullsize) + if ($addlinktofullsize) { $urladvanced=getAdvancedPreviewUrl($modulepart, $originalfile); if ($urladvanced) $ret.='<a href="'.$urladvanced.'">'; @@ -5678,7 +5679,7 @@ class Form } else if ($altfile && file_exists($dir."/".$altfile)) { - if ($addlinktofullsize) + if ($addlinktofullsize) { $urladvanced=getAdvancedPreviewUrl($modulepart, $originalfile); if ($urladvanced) $ret.='<a href="'.$urladvanced.'">'; diff --git a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql index a9ce468a14cdade3c13095a0a6ad568feae8b7c9..961eee1f01a651978cf1f3074d76729a763136e9 100644 --- a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql +++ b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql @@ -329,6 +329,9 @@ ALTER TABLE llx_paiement_facture ADD COLUMN multicurrency_amount double(24,8) DE ALTER TABLE llx_paiementfourn ADD COLUMN multicurrency_amount double(24,8) DEFAULT 0; ALTER TABLE llx_paiementfourn_facturefourn ADD COLUMN multicurrency_amount double(24,8) DEFAULT 0; +ALTER TABLE llx_societe_remise ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER rowid; + +ALTER TABLE llx_societe_remise_except ADD COLUMN entity integer DEFAULT 1 NOT NULL AFTER rowid; ALTER TABLE llx_societe_remise_except ADD COLUMN multicurrency_amount_ht double(24,8) DEFAULT 0 NOT NULL; ALTER TABLE llx_societe_remise_except ADD COLUMN multicurrency_amount_tva double(24,8) DEFAULT 0 NOT NULL; ALTER TABLE llx_societe_remise_except ADD COLUMN multicurrency_amount_ttc double(24,8) DEFAULT 0 NOT NULL; diff --git a/htdocs/install/mysql/tables/llx_societe_remise.sql b/htdocs/install/mysql/tables/llx_societe_remise.sql index 14b4ea85639458fea05702be89a734ba87756c6f..a9d41fcd5021444047918c300964d88461114020 100644 --- a/htdocs/install/mysql/tables/llx_societe_remise.sql +++ b/htdocs/install/mysql/tables/llx_societe_remise.sql @@ -1,6 +1,6 @@ -- ======================================================================== -- Copyright (C) 2000-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org> --- Copyright (C) 2011 Regis Houssin <regis.houssin@capnetworks.com> +-- Copyright (C) 2011-2016 Regis Houssin <regis.houssin@capnetworks.com> -- -- This program is free software; you can redistribute it and/or modify -- it under the terms of the GNU General Public License as published by @@ -21,13 +21,14 @@ create table llx_societe_remise ( - rowid integer AUTO_INCREMENT PRIMARY KEY, - fk_soc integer NOT NULL, - tms timestamp, - datec datetime, -- creation date - fk_user_author integer, -- creation user - remise_client double(6,3) DEFAULT 0 NOT NULL, -- discount - note text + rowid integer AUTO_INCREMENT PRIMARY KEY, + entity integer DEFAULT 1 NOT NULL, -- multi company id + fk_soc integer NOT NULL, + tms timestamp, + datec datetime, -- creation date + fk_user_author integer, -- creation user + remise_client double(6,3) DEFAULT 0 NOT NULL, -- discount + note text )ENGINE=innodb; diff --git a/htdocs/install/mysql/tables/llx_societe_remise_except.sql b/htdocs/install/mysql/tables/llx_societe_remise_except.sql index f17d17670d22c405eaa229280afba5d0b9139ac6..4c55e34425cf8c8d0b6219e5e976f441c0fc9fc2 100644 --- a/htdocs/install/mysql/tables/llx_societe_remise_except.sql +++ b/htdocs/install/mysql/tables/llx_societe_remise_except.sql @@ -21,18 +21,19 @@ create table llx_societe_remise_except ( - rowid integer AUTO_INCREMENT PRIMARY KEY, - fk_soc integer NOT NULL, -- client - datec datetime, - amount_ht double(24,8) NOT NULL, - amount_tva double(24,8) DEFAULT 0 NOT NULL, - amount_ttc double(24,8) DEFAULT 0 NOT NULL, - tva_tx double(6,3) DEFAULT 0 NOT NULL, - fk_user integer NOT NULL, - fk_facture_line integer, - fk_facture integer, - fk_facture_source integer, - description text NOT NULL, + rowid integer AUTO_INCREMENT PRIMARY KEY, + entity integer DEFAULT 1 NOT NULL, -- multi company id + fk_soc integer NOT NULL, -- client + datec datetime, + amount_ht double(24,8) NOT NULL, + amount_tva double(24,8) DEFAULT 0 NOT NULL, + amount_ttc double(24,8) DEFAULT 0 NOT NULL, + tva_tx double(6,3) DEFAULT 0 NOT NULL, + fk_user integer NOT NULL, + fk_facture_line integer, + fk_facture integer, + fk_facture_source integer, + description text NOT NULL, multicurrency_amount_ht double(24,8) DEFAULT 0 NOT NULL, multicurrency_amount_tva double(24,8) DEFAULT 0 NOT NULL, multicurrency_amount_ttc double(24,8) DEFAULT 0 NOT NULL diff --git a/htdocs/install/upgrade2.php b/htdocs/install/upgrade2.php index 74e3af982499c6daf64e89ec2b1676d2e9fa1bad..6167510e5275b0e4a1ceb84208e0bb912bf2546a 100644 --- a/htdocs/install/upgrade2.php +++ b/htdocs/install/upgrade2.php @@ -397,14 +397,20 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action'))) // Reload menus (this must be always and only into last targeted version) migrate_reload_menu($db,$langs,$conf,$versionto); } - + // Scripts for last version $afterversionarray=explode('.','3.9.9'); $beforeversionarray=explode('.','4.0.9'); if (versioncompare($versiontoarray,$afterversionarray) >= 0 && versioncompare($versiontoarray,$beforeversionarray) <= 0) { + // Migrate to add entity value into llx_societe_remise + migrate_remise_entity($db,$langs,$conf); + + // Migrate to add entity value into llx_societe_remise_except + migrate_remise_except_entity($db,$langs,$conf); + migrate_directories($db,$langs,$conf,'/fckeditor','/medias'); - + // Reload modules (this must be always and only into last targeted version) $listofmodule=array( 'MAIN_MODULE_BARCODE'=>'newboxdefonly', @@ -413,12 +419,12 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action'))) 'MAIN_MODULE_PRINTING'=>'newboxdefonly', ); migrate_reload_modules($db,$langs,$conf,$listofmodule); - + // Reload menus (this must be always and only into last targeted version) migrate_reload_menu($db,$langs,$conf,$versionto); } - + // Can force activation of some module during migration with third paramater = MAIN_MODULE_XXX,MAIN_MODULE_YYY,... if ($enablemodules) { @@ -431,8 +437,8 @@ if (! GETPOST("action") || preg_match('/upgrade/i',GETPOST('action'))) } migrate_reload_modules($db,$langs,$conf,$listofmodules,1); } - - + + print '<tr><td colspan="4"><br>'.$langs->trans("MigrationFinished").'</td></tr>'; // On commit dans tous les cas. @@ -1329,10 +1335,10 @@ function migrate_paiementfourn_facturefourn($db,$langs,$conf) function migrate_price_facture($db,$langs,$conf) { $err=0; - + $tmpmysoc=new Societe($db); $tmpmysoc->setMysoc($conf); - + $db->begin(); print '<tr><td colspan="4">'; @@ -1449,7 +1455,7 @@ function migrate_price_propal($db,$langs,$conf) { $tmpmysoc=new Societe($db); $tmpmysoc->setMysoc($conf); - + $db->begin(); print '<tr><td colspan="4">'; @@ -1648,7 +1654,7 @@ function migrate_price_commande($db,$langs,$conf) $tmpmysoc=new Societe($db); $tmpmysoc->setMysoc($conf); - + print '<tr><td colspan="4">'; print '<br>'; @@ -1762,10 +1768,10 @@ function migrate_price_commande($db,$langs,$conf) function migrate_price_commande_fournisseur($db,$langs,$conf) { $db->begin(); - + $tmpmysoc=new Societe($db); $tmpmysoc->setMysoc($conf); - + print '<tr><td colspan="4">'; print '<br>'; @@ -3659,6 +3665,196 @@ function migrate_event_assignement($db,$langs,$conf) print '</td></tr>'; } +/** + * Migrate to add entity value into llx_societe_remise + * + * @param DoliDB $db Database handler + * @param Translate $langs Object langs + * @param Conf $conf Object conf + * @return void + */ +function migrate_remise_entity($db,$langs,$conf) +{ + print '<tr><td colspan="4">'; + + print '<br>'; + print '<b>'.$langs->trans('MigrationRemiseEntity')."</b><br>\n"; + + $error = 0; + + dolibarr_install_syslog("upgrade2::migrate_remise_entity"); + + $db->begin(); + + $sqlSelect = "SELECT sr.rowid, s.entity"; + $sqlSelect.= " FROM ".MAIN_DB_PREFIX."societe_remise as sr, ".MAIN_DB_PREFIX."societe as s"; + $sqlSelect.= " WHERE sr.fk_soc = s.rowid"; + + //print $sqlSelect; + + $resql = $db->query($sqlSelect); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); + + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); + + $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."societe_remise SET"; + $sqlUpdate.= " entity = " . $obj->entity; + $sqlUpdate.= " WHERE rowid = " . $obj->rowid; + + $result=$db->query($sqlUpdate); + if (! $result) + { + $error++; + dol_print_error($db); + } + + print ". "; + $i++; + } + } + else + { + print $langs->trans('AlreadyDone')."<br>\n"; + } + + if (! $error) + { + $db->commit(); + } + else + { + $db->rollback(); + } + } + else + { + dol_print_error($db); + $db->rollback(); + } + + + print '</td></tr>'; +} + +/** + * Migrate to add entity value into llx_societe_remise_except + * + * @param DoliDB $db Database handler + * @param Translate $langs Object langs + * @param Conf $conf Object conf + * @return void + */ +function migrate_remise_except_entity($db,$langs,$conf) +{ + print '<tr><td colspan="4">'; + + print '<br>'; + print '<b>'.$langs->trans('MigrationRemiseExceptEntity')."</b><br>\n"; + + $error = 0; + + dolibarr_install_syslog("upgrade2::migrate_remise_except_entity"); + + $db->begin(); + + $sqlSelect = "SELECT sr.rowid, sr.fk_soc, sr.fk_facture_source, sr.fk_facture, sr.fk_facture_line"; + $sqlSelect.= " FROM ".MAIN_DB_PREFIX."societe_remise_except as sr"; + //print $sqlSelect; + + $resql = $db->query($sqlSelect); + if ($resql) + { + $i = 0; + $num = $db->num_rows($resql); + + if ($num) + { + while ($i < $num) + { + $obj = $db->fetch_object($resql); + + if (!empty($obj->fk_facture_source) || !empty($obj->fk_facture)) + { + $fk_facture = (!empty($obj->fk_facture_source) ? $obj->fk_facture_source : $obj->fk_facture); + + $sqlSelect2 = "SELECT f.entity"; + $sqlSelect2.= " FROM ".MAIN_DB_PREFIX."facture as f"; + $sqlSelect2.= " WHERE f.rowid = " . $fk_facture; + } + else if (!empty($obj->fk_facture_line)) + { + $sqlSelect2 = "SELECT f.entity"; + $sqlSelect2.= " FROM ".MAIN_DB_PREFIX."facture as f, ".MAIN_DB_PREFIX."facturedet as fd"; + $sqlSelect2.= " WHERE fd.rowid = " . $obj->fk_facture_line; + $sqlSelect2.= " AND fd.fk_facture = f.rowid"; + } + else + { + $sqlSelect2 = "SELECT s.entity"; + $sqlSelect2.= " FROM ".MAIN_DB_PREFIX."societe as s"; + $sqlSelect2.= " WHERE s.rowid = " . $obj->fk_soc; + } + + $resql2 = $db->query($sqlSelect2); + if ($resql2) + { + if ($db->num_rows($resql2) > 0) + { + $obj2 = $db->fetch_object($resql2); + + $sqlUpdate = "UPDATE ".MAIN_DB_PREFIX."societe_remise_except SET"; + $sqlUpdate.= " entity = " . $obj2->entity; + $sqlUpdate.= " WHERE rowid = " . $obj->rowid; + + $result=$db->query($sqlUpdate); + if (! $result) + { + $error++; + dol_print_error($db); + } + } + } + else + { + $error++; + dol_print_error($db); + } + + print ". "; + $i++; + } + } + else + { + print $langs->trans('AlreadyDone')."<br>\n"; + } + + if (! $error) + { + $db->commit(); + } + else + { + $db->rollback(); + } + } + else + { + dol_print_error($db); + $db->rollback(); + } + + + print '</td></tr>'; +} + /** * Migration directory * @@ -3826,7 +4022,7 @@ function migrate_reload_modules($db,$langs,$conf,$listofmodule=array(),$force=0) if (empty($moduletoreload) || (empty($conf->global->$moduletoreload) && ! $force)) continue; // Discard reload if module not enabled $mod=null; - + if ($moduletoreload == 'MAIN_MODULE_AGENDA') { dolibarr_install_syslog("upgrade2::migrate_reload_modules Reactivate Agenda module"); @@ -3999,7 +4195,7 @@ function migrate_reload_modules($db,$langs,$conf,$listofmodule=array(),$force=0) } if (! empty($mod) && is_object($mod)) - { + { print '<tr><td colspan="4">'; print '<b>'.$langs->trans('Upgrade').'</b>: '; print $langs->trans('MigrationReloadModule').' '.$mod->getName(); // We keep getName outside of trans because getName is already encoded/translated @@ -4031,7 +4227,7 @@ function migrate_reload_menu($db,$langs,$conf,$versionto) $versiontoarray=explode('.',$versionto); - // Migration required when target version is between + // Migration required when target version is between $afterversionarray=explode('.','2.8.9'); $beforeversionarray=explode('.','2.9.9'); if (versioncompare($versiontoarray,$afterversionarray) >= 0 && versioncompare($versiontoarray,$beforeversionarray) <= 0) @@ -4039,7 +4235,7 @@ function migrate_reload_menu($db,$langs,$conf,$versionto) $listofmenuhandler['auguria']=1; // We set here only dynamic menu handlers } - // Migration required when target version is between + // Migration required when target version is between $afterversionarray=explode('.','3.1.9'); $beforeversionarray=explode('.','3.2.9'); if (versioncompare($versiontoarray,$afterversionarray) >= 0 && versioncompare($versiontoarray,$beforeversionarray) <= 0) @@ -4054,7 +4250,7 @@ function migrate_reload_menu($db,$langs,$conf,$versionto) { $listofmenuhandler['auguria']=1; // We set here only dynamic menu handlers } - + foreach ($listofmenuhandler as $key => $val) { print '<tr><td colspan="4">'; diff --git a/htdocs/langs/en_US/install.lang b/htdocs/langs/en_US/install.lang index 69711cb77cc1184aeb474b7e3a4e89b84bca3cb9..cbe453ef24560823612e09eecd907c4cb1f8ca94 100644 --- a/htdocs/langs/en_US/install.lang +++ b/htdocs/langs/en_US/install.lang @@ -191,6 +191,8 @@ MigrationActioncommElement=Update data on actions MigrationPaymentMode=Data migration for payment mode MigrationCategorieAssociation=Migration of categories MigrationEvents=Migration of events to add event owner into assignement table +MigrationRemiseEntity=Update entity field value of llx_societe_remise +MigrationRemiseExceptEntity=Update entity field value of llx_societe_remise_except MigrationReloadModule=Reload module %s ShowNotAvailableOptions=Show not available options HideNotAvailableOptions=Hide not available options diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 61b3ccae46977080cc028536b9eb3e4a5e0295d8..3bd03e0673e6dcd7ed9729dcbe16959e462c469e 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1166,7 +1166,7 @@ class Societe extends CommonObject $this->cond_reglement_supplier_id = $obj->cond_reglement_supplier; $this->shipping_method_id = ($obj->fk_shipping_method>0)?$obj->fk_shipping_method:null; $this->fk_account = $obj->fk_account; - + $this->client = $obj->client; $this->fournisseur = $obj->fournisseur; @@ -1431,6 +1431,18 @@ class Societe extends CommonObject } } + // Remove societe_remise + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_remise"; + $sql.= " WHERE fk_soc = " . $id; + if (! $this->db->query($sql)) + { + $error++; + $this->error = $this->db->lasterror(); + } + } + // Remove societe_remise_except if (! $error) { @@ -1542,7 +1554,7 @@ class Societe extends CommonObject */ function set_remise_client($remise, $note, User $user) { - global $langs; + global $conf, $langs; // Nettoyage parametres $note=trim($note); @@ -1574,8 +1586,8 @@ class Societe extends CommonObject // Ecrit trace dans historique des remises $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise"; - $sql.= " (datec, fk_soc, remise_client, note, fk_user_author)"; - $sql.= " VALUES ('".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',"; + $sql.= " (entity, datec, fk_soc, remise_client, note, fk_user_author)"; + $sql.= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',"; $sql.= " '".$this->db->escape($note)."',"; $sql.= " ".$user->id; $sql.= ")"; @@ -1922,7 +1934,7 @@ class Societe extends CommonObject } $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"'; $linkclose.=' class="classfortooltip"'; - + if (! is_object($hookmanager)) { include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; @@ -2760,7 +2772,7 @@ class Societe extends CommonObject $url=''; $action = ''; - + $hookmanager->initHooks(array('idprofurl')); $parameters=array('idprof'=>$idprof, 'company'=>$thirdparty); $reshook=$hookmanager->executeHooks('getIdProfUrl',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks @@ -2773,14 +2785,14 @@ class Societe extends CommonObject //if ($idprof == 1 && ($thirdparty->country_code == 'GB' || $thirdparty->country_code == 'UK')) $url='http://www.companieshouse.gov.uk/WebCHeck/findinfolink/'; // Link no more valid if ($idprof == 1 && $thirdparty->country_code == 'ES') $url='http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$thirdparty->idprof1; if ($idprof == 1 && $thirdparty->country_code == 'IN') $url='http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$thirdparty->idprof1.';&searchBy=TIN&backPage=searchByTin_Inter.jsp'; - + if ($url) return '<a target="_blank" href="'.$url.'">'.$langs->trans("Check").'</a>'; } else { return $hookmanager->resPrint; } - + return ''; } @@ -3508,9 +3520,9 @@ class Societe extends CommonObject */ $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'societe_commerciaux '; $sql .= ' WHERE fk_soc = '.(int) $dest_id.' AND fk_user IN ( '; - $sql = ' SELECT fk_user '; - $sql = ' FROM '.MAIN_DB_PREFIX.'societe_commerciaux '; - $sql = ' WHERE fk_soc = '.(int) $origin_id.') '; + $sql .= ' SELECT fk_user '; + $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_commerciaux '; + $sql .= ' WHERE fk_soc = '.(int) $origin_id.') '; $query = $db->query($sql);