diff --git a/.scrutinizer.yml b/.scrutinizer.yml index 0ca95ace51d..831aa15c68a 100644 --- a/.scrutinizer.yml +++ b/.scrutinizer.yml @@ -9,6 +9,7 @@ filter: - dev/* - doc/* - test/* + - htdocs/includes/* paths: - htdocs/* - scripts/* diff --git a/ChangeLog b/ChangeLog index a009533f07a..21d3ebc66b3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -6,8 +6,8 @@ WARNING: Do not try to make any Dolibarr upgrade if you are running Mysql version 5.5.40. Mysql version 5.5.40 has a very critical bug making your data beeing definitely lost. -You may also experience troubles with Mysql 5.5.41/42/43 with error "Lost connection" -during migration. +You may also experience troubles with Mysql 5.5.41/42/43 with error "Lost connection" during +migration. Upgrading to any other version or any other database system is abolutely required BEFORE trying make a Dolibarr upgrade. @@ -25,6 +25,8 @@ Dolibarr 4.0 should be compatible with PHP 7 but more feedbacks are still expect Following changes may create regression for some external modules, but were necessary to make Dolibarr better: - Function log() of class CommandeFournisseur has been removed. Using it is no more required. +- Class Resource was renamed into DolResource to avoid conflict with a reserved PHP word. +- Method commonobject->add_thumb() has been renamed into commonobject->addThumbs(). - Method select_type_comptes_financiers() has been renamed into selectTypeOfBankAccount() - Property ->client that was deprecated 6 years ago, is replaced in all core code with ->thirdparty. - File '/core/tpl/document_actions_pre_headers.tpl.php' were renamed into '/core/actions_linkedfiles.inc.php'. @@ -33,7 +35,6 @@ So if you included it into your module, change your code like this to be compati if (! $res) include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_pre_headers.tpl.php'; - ***** ChangeLog for 3.9.1 compared to 3.9.* ***** FIX: #3815 Call to undefined function local_by_date() FIX: #4424 Missing email of user popup in supplier orders area diff --git a/build/exe/doliwamp/doliwamp.iss b/build/exe/doliwamp/doliwamp.iss index a837450f077..8c6130437ac 100644 --- a/build/exe/doliwamp/doliwamp.iss +++ b/build/exe/doliwamp/doliwamp.iss @@ -32,7 +32,7 @@ AppPublisherURL=http://www.nltechno.com AppSupportURL=http://www.dolibarr.org AppUpdatesURL=http://www.dolibarr.org AppComments=DoliWamp includes Dolibarr, Apache, PHP and Mysql softwares. -AppCopyright=Copyright (C) 2008-2015 Laurent Destailleur, NLTechno +AppCopyright=Copyright (C) 2008-2016 Laurent Destailleur, NLTechno DefaultDirName=c:\dolibarr DefaultGroupName=Dolibarr ;LicenseFile=COPYING @@ -80,7 +80,7 @@ Name: "desktopicon"; Description: {cm:CreateDesktopIcon}; GroupDescription: {cm: Name: "{app}\logs" Name: "{app}\tmp" Name: "{app}\dolibarr_documents" -Name: "{app}\bin\apache\apache2.2.11\logs" +Name: "{app}\bin\apache\apache2.4.9\logs" [Files] ; Stop/start @@ -101,10 +101,10 @@ Source: "build\exe\doliwamp\UsedPort.exe"; DestDir: "{app}\"; Flags: ignoreversi ; Put here path of Wampserver applications ; Value OK: apache 2.2.6, php 5.2.5 (5.2.11, 5.3.0 and 5.3.1 fails if php_exif, php_pgsql, php_zip is on), mysql 5.0.45 or 5.1.36 ; Value OK: apache 2.2.11, php 5.3.0 (if no php_exif, php_pgsql, php_zip), mysql 5.0.45 or 5.1.36 -Source: "C:\Program Files\Wamp\apps\phpmyadmin3.2.0.1\*.*"; DestDir: "{app}\apps\phpmyadmin3.2.0.1"; Flags: ignoreversion recursesubdirs; Excludes: "config.inc.php,wampserver.conf,*.log,*_log,darkblue_orange" -Source: "C:\Program Files\Wamp\bin\apache\apache2.2.11\*.*"; DestDir: "{app}\bin\apache\apache2.2.11"; Flags: ignoreversion recursesubdirs; Excludes: "php.ini,httpd.conf,wampserver.conf,*.log,*_log" -Source: "C:\Program Files\Wamp\bin\php\php5.3.0\*.*"; DestDir: "{app}\bin\php\php5.3.0"; Flags: ignoreversion recursesubdirs; Excludes: "php.ini,phpForApache.ini,wampserver.conf,*.log,*_log" -Source: "C:\Program Files\Wamp\bin\mysql\mysql5.0.45\*.*"; DestDir: "{app}\bin\mysql\mysql5.0.45"; Flags: ignoreversion recursesubdirs; Excludes: "my.ini,data\*,wampserver.conf,*.log,*_log,MySQLInstanceConfig.exe" +Source: "C:\Program Files\Wamp\apps\phpmyadmin4.1.14\*.*"; DestDir: "{app}\apps\phpmyadmin4.1.14"; Flags: ignoreversion recursesubdirs; Excludes: "config.inc.php,wampserver.conf,*.log,*_log,darkblue_orange" +Source: "C:\Program Files\Wamp\bin\apache\apache2.4.9\*.*"; DestDir: "{app}\bin\apache\apache2.4.9"; Flags: ignoreversion recursesubdirs; Excludes: "php.ini,httpd.conf,wampserver.conf,*.log,*_log" +Source: "C:\Program Files\Wamp\bin\php\php5.5.12\*.*"; DestDir: "{app}\bin\php\php5.5.12"; Flags: ignoreversion recursesubdirs; Excludes: "php.ini,phpForApache.ini,wampserver.conf,*.log,*_log" +Source: "C:\Program Files\Wamp\bin\mysql\mysql5.6.17\*.*"; DestDir: "{app}\bin\mysql\mysql5.6.17"; Flags: ignoreversion recursesubdirs; Excludes: "my.ini,data\*,wampserver.conf,*.log,*_log,MySQLInstanceConfig.exe" ; Mysql data files (does not overwrite if exists) Source: "build\exe\doliwamp\mysql\*.*"; DestDir: "{app}\bin\mysql\data\mysql"; Flags: onlyifdoesntexist ignoreversion recursesubdirs; Excludes: ".gitignore,.project,CVS\*,Thumbs.db" ; Dolibarr @@ -116,10 +116,10 @@ Source: "*.*"; DestDir: "{app}\www\dolibarr"; Flags: ignoreversion; Excludes: ". ; Config files Source: "build\exe\doliwamp\phpmyadmin.conf.install"; DestDir: "{app}\alias"; Flags: ignoreversion; Source: "build\exe\doliwamp\dolibarr.conf.install"; DestDir: "{app}\alias"; Flags: ignoreversion; -Source: "build\exe\doliwamp\config.inc.php.install"; DestDir: "{app}\apps\phpmyadmin3.2.0.1"; Flags: ignoreversion; -Source: "build\exe\doliwamp\httpd.conf.install"; DestDir: "{app}\bin\apache\apache2.2.11\conf"; Flags: ignoreversion; -Source: "build\exe\doliwamp\my.ini.install"; DestDir: "{app}\bin\mysql\mysql5.0.45"; Flags: ignoreversion; -Source: "build\exe\doliwamp\php.ini.install"; DestDir: "{app}\bin\php\php5.3.0"; Flags: ignoreversion; +Source: "build\exe\doliwamp\config.inc.php.install"; DestDir: "{app}\apps\phpmyadmin4.1.14"; Flags: ignoreversion; +Source: "build\exe\doliwamp\httpd.conf.install"; DestDir: "{app}\bin\apache\apache2.4.9\conf"; Flags: ignoreversion; +Source: "build\exe\doliwamp\my.ini.install"; DestDir: "{app}\bin\mysql\mysql5.5.12"; Flags: ignoreversion; +Source: "build\exe\doliwamp\php.ini.install"; DestDir: "{app}\bin\php\php5.6.17"; Flags: ignoreversion; Source: "build\exe\doliwamp\index.php.install"; DestDir: "{app}\www"; Flags: ignoreversion; Source: "build\exe\doliwamp\install.forced.php.install"; DestDir: "{app}\www\dolibarr\htdocs\install"; Flags: ignoreversion; Source: "build\exe\doliwamp\openssl.conf"; DestDir: "{app}"; Flags: ignoreversion; @@ -195,10 +195,10 @@ end; procedure InitializeWizard(); begin //version des applis, a modifier pour chaque version de WampServer 2 - apacheVersion := '2.2.11'; - phpVersion := '5.3.0' ; - mysqlVersion := '5.0.45'; - phpmyadminVersion := '3.2.0.1'; + apacheVersion := '2.4.9'; + phpVersion := '5.5.12' ; + mysqlVersion := '5.6.17'; + phpmyadminVersion := '4.1.14'; smtpServer := 'localhost'; apachePort := '80'; @@ -329,10 +329,10 @@ begin winPath := ExpandConstant('{win}'); pathWithSlashes := path; StringChange (pathWithSlashes, '\','/'); - datadirold := pathWithSlashes+'/bin/mysql/mysql5.0.45/data'; + datadirold := pathWithSlashes+'/bin/mysql/mysql5.6.17/data'; datadirnew := pathWithSlashes+'/bin/mysql/data'; - exedirold := pathWithSlashes+'/bin/mysql/mysql5.0.45'; - exedirnew := pathWithSlashes+'/bin/mysql/mysql5.0.45'; + exedirold := pathWithSlashes+'/bin/mysql/mysql5.6.17'; + exedirnew := pathWithSlashes+'/bin/mysql/mysql5.6.17'; // If we have a new database version, we should only copy old my.ini file into new directory // and change only all basedir= strings to use new version. Like this, data dir is still correct. @@ -663,6 +663,7 @@ begin //installDir et version de php StringChangeEx (srcContents, 'WAMPROOT', pathWithSlashes, True); StringChangeEx (srcContents, 'WAMPMYSQLPORT', myport, True); + StringChangeEx (srcContents, 'WAMPMYSQLVERSION', myport, True); SaveStringToFile(destFile,srcContents, False); end @@ -1002,7 +1003,7 @@ Filename: "{app}\rundoliwamp.bat"; Description: {cm:LaunchNow}; Flags: shellexec [UninstallDelete] Type: files; Name: "{app}\*.*" -Type: files; Name: "{app}\bin\mysql\mysql5.0.45\*.*" +Type: files; Name: "{app}\bin\mysql\mysql5.6.17\*.*" Type: filesandordirs; Name: "{app}\alias" Type: filesandordirs; Name: "{app}\apps" Type: filesandordirs; Name: "{app}\bin\apache" diff --git a/build/exe/doliwamp/my.ini.install b/build/exe/doliwamp/my.ini.install index 40a764b6038..c855cc27a66 100644 --- a/build/exe/doliwamp/my.ini.install +++ b/build/exe/doliwamp/my.ini.install @@ -69,7 +69,7 @@ port=WAMPMYSQLPORT #Path to installation directory. All paths are usually resolved relative to this. -basedir=WAMPROOT/bin/mysql/mysql5.0.45 +basedir=WAMPROOT/bin/mysql/mysqlWAMPMYSQLVERSION #log file log-error=WAMPROOT/logs/mysql.log @@ -226,7 +226,7 @@ port=WAMPMYSQLPORT #Path to installation directory. All paths are usually resolved relative to this. -basedir=WAMPROOT/bin/mysql/mysql5.0.45 +basedir=WAMPROOT/bin/mysql/mysql5.6.17 #log file log-error=WAMPROOT/logs/mysql.log diff --git a/build/makepack-dolibarr.pl b/build/makepack-dolibarr.pl index b8c4f2fb475..45c8e0a6f42 100755 --- a/build/makepack-dolibarr.pl +++ b/build/makepack-dolibarr.pl @@ -379,7 +379,7 @@ if ($nboftargetok) { print 'Run git tag -a -m "'.$MAJOR.'.'.$MINOR.'.'.$BUILD.'" "'.$MAJOR.'.'.$MINOR.'.'.$BUILD.'"'."\n"; $ret=`git tag -a -m "$MAJOR.$MINOR.$BUILD" "$MAJOR.$MINOR.$BUILD" 2>&1`; - if ($ret =~ /already exists/) + if ($ret =~ /(already exists|existe déjà)/) { print "WARNING: Tag ".$MAJOR.'.'.$MINOR.'.'.$BUILD." already exists. Overwrite (y/N) ? "; $QUESTIONOVERWRITETAG=; @@ -595,9 +595,12 @@ if ($nboftargetok) { if ($target eq 'TGZ') { $NEWDESTI=$DESTI; - mkdir($DESTI.'/standard'); - if (-d $DESTI.'/standard') { $NEWDESTI=$DESTI.'/standard'; } - + if ($NEWPUBLISH =~ /stable/) + { + mkdir($DESTI.'/standard'); + if (-d $DESTI.'/standard') { $NEWDESTI=$DESTI.'/standard'; } + } + print "Remove target $FILENAMETGZ.tgz...\n"; unlink("$NEWDESTI/$FILENAMETGZ.tgz"); @@ -624,8 +627,11 @@ if ($nboftargetok) { if ($target eq 'XZ') { $NEWDESTI=$DESTI; - mkdir($DESTI.'/standard'); - if (-d $DESTI.'/standard') { $NEWDESTI=$DESTI.'/standard'; } + if ($NEWPUBLISH =~ /stable/) + { + mkdir($DESTI.'/standard'); + if (-d $DESTI.'/standard') { $NEWDESTI=$DESTI.'/standard'; } + } print "Remove target $FILENAMEXZ.xz...\n"; unlink("$NEWDESTI/$FILENAMEXZ.xz"); @@ -658,8 +664,11 @@ if ($nboftargetok) { if ($target eq 'ZIP') { $NEWDESTI=$DESTI; - mkdir($DESTI.'/standard'); - if (-d $DESTI.'/standard') { $NEWDESTI=$DESTI.'/standard'; } + if ($NEWPUBLISH =~ /stable/) + { + mkdir($DESTI.'/standard'); + if (-d $DESTI.'/standard') { $NEWDESTI=$DESTI.'/standard'; } + } print "Remove target $FILENAMEZIP.zip...\n"; unlink("$NEWDESTI/$FILENAMEZIP.zip"); @@ -696,8 +705,11 @@ if ($nboftargetok) { if ($target =~ /FEDO/i) { $subdir="package_rpm_redhat-fedora"; } if ($target =~ /MAND/i) { $subdir="package_rpm_mandriva"; } if ($target =~ /OPEN/i) { $subdir="package_rpm_opensuse"; } - mkdir($DESTI.'/'.$subdir); - if (-d $DESTI.'/'.$subdir) { $NEWDESTI=$DESTI.'/'.$subdir; } + if ($NEWPUBLISH =~ /stable/) + { + mkdir($DESTI.'/'.$subdir); + if (-d $DESTI.'/'.$subdir) { $NEWDESTI=$DESTI.'/'.$subdir; } + } if ($RPMDIR eq "") { $RPMDIR=$ENV{'HOME'}."/rpmbuild"; } @@ -779,8 +791,11 @@ if ($nboftargetok) { if ($target eq 'DEB') { $NEWDESTI=$DESTI; - mkdir($DESTI.'/package_debian-ubuntu'); - if (-d $DESTI.'/package_debian-ubuntu') { $NEWDESTI=$DESTI.'/package_debian-ubuntu'; } + if ($NEWPUBLISH =~ /stable/) + { + mkdir($DESTI.'/package_debian-ubuntu'); + if (-d $DESTI.'/package_debian-ubuntu') { $NEWDESTI=$DESTI.'/package_debian-ubuntu'; } + } $olddir=getcwd(); @@ -979,8 +994,11 @@ if ($nboftargetok) { if ($target eq 'APS') { $NEWDESTI=$DESTI; - mkdir($DESTI.'/package_aps'); - if (-d $DESTI.'/package_aps') { $NEWDESTI=$DESTI.'/package_aps'; } + if ($NEWPUBLISH =~ /stable/) + { + mkdir($DESTI.'/package_aps'); + if (-d $DESTI.'/package_aps') { $NEWDESTI=$DESTI.'/package_aps'; } + } $newbuild = $BUILD; $newbuild =~ s/(dev|alpha)/0/gi; # dev @@ -1062,8 +1080,11 @@ if ($nboftargetok) { if ($target eq 'EXEDOLIWAMP') { $NEWDESTI=$DESTI; - mkdir($DESTI.'/package_windows'); - if (-d $DESTI.'/package_windows') { $NEWDESTI=$DESTI.'/package_windows'; } + if ($NEWPUBLISH =~ /stable/) + { + mkdir($DESTI.'/package_windows'); + if (-d $DESTI.'/package_windows') { $NEWDESTI=$DESTI.'/package_windows'; } + } print "Remove target $NEWDESTI/$FILENAMEEXEDOLIWAMP.exe...\n"; unlink "$NEWDESTI/$FILENAMEEXEDOLIWAMP.exe"; @@ -1195,8 +1216,8 @@ if ($nboftargetok) { $command="rsync -s -e 'ssh' \"$file\" \"".$destFolder."\""; print "$command\n"; - my $ret=`$command 2>&1`; - print "$ret\n"; + my $ret2=`$command 2>&1`; + print "$ret2\n"; } } } diff --git a/doc/images/dolibarr_screenshot1_1280x800.png b/doc/images/dolibarr_screenshot1_1280x800.png index 9aa799a10a7..684feb62390 100644 Binary files a/doc/images/dolibarr_screenshot1_1280x800.png and b/doc/images/dolibarr_screenshot1_1280x800.png differ diff --git a/doc/images/dolibarr_screenshot1_300x188.png b/doc/images/dolibarr_screenshot1_300x188.png index 9fab4daa8ef..b849e202206 100644 Binary files a/doc/images/dolibarr_screenshot1_300x188.png and b/doc/images/dolibarr_screenshot1_300x188.png differ diff --git a/doc/images/dolibarr_screenshot1_640x400.png b/doc/images/dolibarr_screenshot1_640x400.png index 3f0d38832e1..9efefcc2405 100644 Binary files a/doc/images/dolibarr_screenshot1_640x400.png and b/doc/images/dolibarr_screenshot1_640x400.png differ diff --git a/htdocs/accountancy/admin/account.php b/htdocs/accountancy/admin/account.php index 94ce450ff30..5bdaa3c5828 100644 --- a/htdocs/accountancy/admin/account.php +++ b/htdocs/accountancy/admin/account.php @@ -147,6 +147,7 @@ if ($result) { print '
'; print '' . $langs->trans("Addanaccount") . ''; + print '' . $langs->trans("ApplyMassCategories") . ''; // print '' . $langs->trans("ImportAccount") . ''; // print '' . $langs->trans("CheckProductAccountancyCode") . ''; print '

'; diff --git a/htdocs/accountancy/admin/card.php b/htdocs/accountancy/admin/card.php index f1f1218f554..0d927b7305b 100644 --- a/htdocs/accountancy/admin/card.php +++ b/htdocs/accountancy/admin/card.php @@ -76,19 +76,17 @@ if ($action == 'add') { $res = $object->create($user); - if ($res == 0) { - } else { - if ($res == - 3) { - $error = 1; - $action = "create"; - } - if ($res == - 4) { - $error = 2; - $action = "create"; - } + if ($res == - 3) { + $error = 1; + $action = "create"; + } + if ($res == - 4) { + $error = 2; + $action = "create"; } } - Header("Location: account.php"); + header("Location: account.php"); + exit; } else if ($action == 'edit') { if (! GETPOST('cancel', 'alpha')) { $result = $object->fetch($id); @@ -134,7 +132,8 @@ if ($action == 'add') { $result = $object->delete($user); if ($result > 0) { - Header("Location: account.php"); + header("Location: account.php"); + exit; } } diff --git a/htdocs/accountancy/admin/categories.php b/htdocs/accountancy/admin/categories.php new file mode 100644 index 00000000000..f0013632b53 --- /dev/null +++ b/htdocs/accountancy/admin/categories.php @@ -0,0 +1,157 @@ + + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/accountancy/admin/categories.php + * \ingroup Advanced accountancy + * \brief Page to assign mass categories to accounts + */ +require '../../main.inc.php'; + +// Class +require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/accountancy/class/accountancycategory.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/html.formaccounting.class.php'; + +$error = 0; + +// Langs +$langs->load("bills"); +$langs->load("accountancy"); + +$mesg = ''; +$action = GETPOST('action'); +$cat_id = GETPOST('account_category'); +$selectcpt = GETPOST('cpt_bk'); +$cpt_id = GETPOST('cptid'); + +if($cat_id == 0){ + $cat_id = null; +} + +$id = GETPOST('id', 'int'); +$rowid = GETPOST('rowid', 'int'); +$cancel = GETPOST('cancel'); + +// Security check +if (! $user->admin) + accessforbidden(); + +$AccCat = new AccountancyCategory($db); + +// si ajout de comptes +if(!empty($selectcpt)){ + $cpts = array(); + $i = 0; + foreach ($selectcpt as $selectedOption){ + $cpts[$i] = "'".$selectedOption."'"; + $i++; + } + + if($AccCat->updateAccAcc($cat_id, $cpts)){ + setEventMessages($langs->trans('Saved'), null, 'mesgs'); + }else{ + setEventMessages($langs->trans('errors'), null, 'errors'); + } + + +} +if ($action == 'delete') { + if($cpt_id){ + if($AccCat->deleteCptCat($cpt_id)){ + setEventMessages($langs->trans('Deleted'), null, 'mesgs'); + }else{ + setEventMessages($langs->trans('errors'), null, 'errors'); + } + } +} + +/* + * View + */ +llxheader('', $langs->trans('AccountAccounting')); + +$formaccounting = new FormAccounting($db); +$form = new Form($db); + + print load_fiche_titre($langs->trans('Categories')); + + print '
' . "\n"; + print ''; + print ''; + + dol_fiche_head(); + + print ''; + // Category + print ''; + print ''; + + + if(!empty($cat_id)){ + $obj = $AccCat->getCptBK($cat_id); + print ''; + print ''; + } + + print '
' . $langs->trans("AccountingCategory") . ''; + $formaccounting->select_accounting_category($cat_id, 'account_category', 1); + print ''; + print '
' . $langs->trans("AddCompteFromBK") . ''; + if(!empty($obj)){ + print ' - '; + } + print '
'; + + dol_fiche_end(); + + print '
'; + +if ($action == 'display' || $action == 'delete') { + + print ''; + + print ''; + + if(!empty($cat_id)){ + $obj = $AccCat->display($cat_id); + $j=1; + if(!empty($obj)){ + foreach ( $obj as $cpt ) { + $var = ! $var; + print ""; + print ''; + print ''; + print $form->formconfirm($_SERVER["PHP_SELF"]."?account_category=$cat_id&cptid=".$cpt->rowid, $langs->trans("DeleteCptCategory"), $langs->trans("ConfirmDeleteCptCategory"), "delete", '', 0, "action-delete".$j); + print ''; + print "\n"; + $j++; + } + } + } + + print "
'.$langs->trans("Numerocompte").''.$langs->trans("Description").'Action
' . length_accountg($cpt->account_number) . '' . $cpt->label . '
"; +} + +llxFooter(); + +$db->close(); \ No newline at end of file diff --git a/htdocs/accountancy/admin/fiscalyear_card.php b/htdocs/accountancy/admin/fiscalyear_card.php index e04cc7132f0..e663557d22c 100644 --- a/htdocs/accountancy/admin/fiscalyear_card.php +++ b/htdocs/accountancy/admin/fiscalyear_card.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2014-2016 Alexandre Spangaro * * 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 @@ -205,8 +205,8 @@ if ($action == 'create') { // Ref print ""; - print '' . $langs->trans("Ref") . ''; - print $object->rowid; + print '' . $langs->trans("Ref") . ''; + print $object->ref; print ''; // Label @@ -252,11 +252,11 @@ if ($action == 'create') { print ''; - $linkback = '' . $langs->trans("BackToList") . ''; + $linkback = '' . $langs->trans("BackToList") . ''; // Ref print ''; @@ -270,16 +270,16 @@ if ($action == 'create') { // Date start print ''; // Date end print ''; // Statut diff --git a/htdocs/accountancy/admin/index.php b/htdocs/accountancy/admin/index.php index c9041e2a848..7c85212ccb8 100644 --- a/htdocs/accountancy/admin/index.php +++ b/htdocs/accountancy/admin/index.php @@ -56,8 +56,9 @@ $list = array ( ); $list_account = array ( - 'ACCOUNTING_ACCOUNT_CUSTOMER', 'ACCOUNTING_ACCOUNT_SUPPLIER', + 'ACCOUNTING_ACCOUNT_CUSTOMER', + 'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT', 'ACCOUNTING_PRODUCT_BUY_ACCOUNT', 'ACCOUNTING_PRODUCT_SOLD_ACCOUNT', 'ACCOUNTING_SERVICE_BUY_ACCOUNT', @@ -67,7 +68,6 @@ $list_account = array ( 'ACCOUNTING_VAT_PAY_ACCOUNT', 'ACCOUNTING_ACCOUNT_SUSPENSE', 'ACCOUNTING_ACCOUNT_TRANSFER_CASH', - 'SALARIES_ACCOUNTING_ACCOUNT_PAYMENT', 'DONATION_ACCOUNTINGACCOUNT' ); @@ -219,10 +219,9 @@ print ""; print "'; } else { - print ''; } @@ -442,7 +428,7 @@ if ($conf->produit->enabled) print "
' . $langs->trans("Ref") . ''; - print $object->rowid; + print $object->ref; print ''; print $linkback; print '
'; - print $form->editfieldkey("Date", 'date_start', $object->date_start, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker'); + print $form->editfieldkey("DateStart", 'date_start', $object->date_start, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker'); print ''; - print $form->editfieldval("Date", 'date_start', $object->date_start, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker'); + print $form->editfieldval("DateStart", 'date_start', $object->date_start, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker'); print '
'; - print $form->editfieldkey("Date", 'date_end', $object->date_end, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker'); + print $form->editfieldkey("DateEnd", 'date_end', $object->date_end, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker'); print ''; - print $form->editfieldval("Date", 'date_end', $object->date_end, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker'); + print $form->editfieldval("DateEnd", 'date_end', $object->date_end, $object, $conf->global->MAIN_EDIT_ALSO_INLINE, 'datepicker'); print '
" . $langs->trans("Selectchartofaccounts") . ""; print ''; @@ -222,96 +329,232 @@ if ($resql) $moreforfilter.=$formother->select_categories(Categorie::TYPE_MEMBER,$search_categ,'search_categ',1); $moreforfilter.=''; } + $parameters=array(); + $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook + if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint; + else $moreforfilter = $hookmanager->resPrint; if (! empty($moreforfilter)) { print '
'; print $moreforfilter; - $parameters=array(); - $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - print '
'; + print ''; } - print ''; + $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage; + $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields + + print '
'."\n"; print ''; if (! empty($conf->global->MAIN_VIEW_LINE_NUMBER)) { print ''; } - print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"d.rowid",$param,"","",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Name")." / ".$langs->trans("Company"),$_SERVER["PHP_SELF"],"d.lastname",$param,"","",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Login"),$_SERVER["PHP_SELF"],"d.login",$param,"","",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"t.libelle",$param,"","",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Person"),$_SERVER["PHP_SELF"],"d.morphy",$param,"","",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("EMail"),$_SERVER["PHP_SELF"],"d.email",$param,"","",$sortfield,$sortorder); - - $parameters=array(); + if (! empty($arrayfields['d.ref']['checked'])) print_liste_field_titre($arrayfields['d.ref']['label'],$_SERVER["PHP_SELF"],'d.rowid','',$param,'',$sortfield,$sortorder); + if (! empty($arrayfields['d.firstname']['checked'])) print_liste_field_titre($arrayfields['d.firstname']['label'],$_SERVER["PHP_SELF"],'d.firstname','',$param,'',$sortfield,$sortorder); + if (! empty($arrayfields['d.lastname']['checked'])) print_liste_field_titre($arrayfields['d.lastname']['label'],$_SERVER["PHP_SELF"],'d.lastname','',$param,'',$sortfield,$sortorder); + if (! empty($arrayfields['d.company']['checked'])) print_liste_field_titre($arrayfields['d.company']['label'],$_SERVER["PHP_SELF"],'d.societe','',$param,'',$sortfield,$sortorder); + if (! empty($arrayfields['d.login']['checked'])) print_liste_field_titre($arrayfields['d.login']['label'],$_SERVER["PHP_SELF"],'d.login','',$param,'',$sortfield,$sortorder); + if (! empty($arrayfields['d.morphy']['checked'])) print_liste_field_titre($arrayfields['d.morphy']['label'],$_SERVER["PHP_SELF"],'d.morphy','',$param,'',$sortfield,$sortorder); + if (! empty($arrayfields['t.libelle']['checked'])) print_liste_field_titre($arrayfields['t.libelle']['label'],$_SERVER["PHP_SELF"],'t.libelle','',$param,'',$sortfield,$sortorder); + if (! empty($arrayfields['d.address']['checked'])) print_liste_field_titre($arrayfields['d.address']['label'],$_SERVER["PHP_SELF"],'d.address','',$param,'',$sortfield,$sortorder); + if (! empty($arrayfields['d.zip']['checked'])) print_liste_field_titre($arrayfields['d.zip']['label'],$_SERVER["PHP_SELF"],'d.zip','',$param,'',$sortfield,$sortorder); + if (! empty($arrayfields['d.town']['checked'])) print_liste_field_titre($arrayfields['d.town']['label'],$_SERVER["PHP_SELF"],'d.town','',$param,'',$sortfield,$sortorder); + if (! empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($langs->trans("StateShort"),$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder); + if (! empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($langs->trans("Country"),$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder); + if (! empty($arrayfields['d.email']['checked'])) print_liste_field_titre($arrayfields['d.email']['label'],$_SERVER["PHP_SELF"],'d.email','',$param,'',$sortfield,$sortorder); + if (! empty($arrayfields['d.datefin']['checked'])) print_liste_field_titre($arrayfields['d.datefin']['label'],$_SERVER["PHP_SELF"],'d.datefin','',$param,'align="center"',$sortfield,$sortorder); + // Extra fields + if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) + { + foreach($extrafields->attribute_label as $key => $val) + { + if (! empty($arrayfields["ef.".$key]['checked'])) + { + $align=$extrafields->getAlignFlag($key); + print_liste_field_titre($extralabels[$key],$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder); + } + } + } + // Hook fields + $parameters=array('arrayfields'=>$arrayfields); $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook print $hookmanager->resPrint; - - print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"d.statut,d.datefin",$param,"","",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("EndSubscription"),$_SERVER["PHP_SELF"],"d.datefin",$param,"",'align="center"',$sortfield,$sortorder); - print_liste_field_titre($langs->trans(""),$_SERVER["PHP_SELF"],"",$param,"",'width="60" align="center"',$sortfield,$sortorder); - print "\n"; + if (! empty($arrayfields['d.datec']['checked'])) print_liste_field_titre($arrayfields['d.datec']['label'],$_SERVER["PHP_SELF"],"d.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder); + if (! empty($arrayfields['d.tms']['checked'])) print_liste_field_titre($arrayfields['d.tms']['label'],$_SERVER["PHP_SELF"],"d.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder); + if (! empty($arrayfields['d.statut']['checked'])) print_liste_field_titre($arrayfields['d.statut']['label'],$_SERVER["PHP_SELF"],"d.statut","",$param,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="right"',$sortfield,$sortorder,'maxwidthsearch '); + print "\n"; // Line for filters fields print ''; - print ''; + // Ref + if (! empty($arrayfields['d.ref']['checked'])) + { + print ''; + } - print ''; + if (! empty($arrayfields['d.firstname']['checked'])) + { + print ''; + } + + if (! empty($arrayfields['d.lastname']['checked'])) + { + print ''; + } + + if (! empty($arrayfields['d.company']['checked'])) + { + print ''; + } + + if (! empty($arrayfields['d.login']['checked'])) + { + print ''; + } + + if (! empty($arrayfields['d.morphy']['checked'])) + { + print ''; + } + + if (! empty($arrayfields['t.libelle']['checked'])) + { + print ''; + } + + if (! empty($arrayfields['d.address']['checked'])) + { + print ''; + } + + if (! empty($arrayfields['d.zip']['checked'])) + { + print ''; + } + if (! empty($arrayfields['d.town']['checked'])) + { + print ''; + } + // State + if (! empty($arrayfields['state.nom']['checked'])) + { + print ''; + } + // Country + if (! empty($arrayfields['country.code_iso']['checked'])) + { + print ''; + } + // Email + if (! empty($arrayfields['d.email']['checked'])) + { + print ''; + } - print ''; - - print ''; - - print ''; + } + // Extra fields + if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) + { + foreach($extrafields->attribute_label as $key => $val) + { + if (! empty($arrayfields["ef.".$key]['checked'])) + { + $align=$extrafields->getAlignFlag($key); + $typeofextrafield=$extrafields->attribute_type[$key]; + print ''; + } + } + } + // Fields from hook + $parameters=array('arrayfields'=>$arrayfields); + $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + // Date creation + if (! empty($arrayfields['d.datec']['checked'])) + { + print ''; + } + // Date modification + if (! empty($arrayfields['d.tms']['checked'])) + { + print ''; + } + // Status + if (! empty($arrayfields['d.statut']['checked'])) + { + print ''; + } + // Action column + print ''; - - print ''; - - print ''; - - $parameters=array(); - $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - - // Status - print ''; - - // Action column - print ''; - + print "\n"; $var=True; while ($i < $num && $i < $conf->liste_limit) { - $objp = $db->fetch_object($resql); + $obj = $db->fetch_object($resql); - $datefin=$db->jdate($objp->datefin); - $memberstatic->id=$objp->rowid; - $memberstatic->ref=$objp->rowid; - $memberstatic->lastname=$objp->lastname; - $memberstatic->firstname=$objp->firstname; - $memberstatic->statut=$objp->statut; + $datefin=$db->jdate($obj->datefin); + $memberstatic->id=$obj->rowid; + $memberstatic->ref=$obj->rowid; + $memberstatic->lastname=$obj->lastname; + $memberstatic->firstname=$obj->firstname; + $memberstatic->societe=$obj->company; + $memberstatic->statut=$obj->statut; $memberstatic->datefin= $datefin; - - if (! empty($objp->fk_soc)) { - $memberstatic->socid = $objp->fk_soc; - $memberstatic->fetch_thirdparty(); + $memberstatic->socid = $obj->fk_soc; + + if (! empty($obj->fk_soc)) { + $memberstatic->fetch_thirdparty(); $companyname=$memberstatic->thirdparty->name; } else { - $companyname=$objp->company; + $companyname=$obj->company; } $var=!$var; @@ -322,85 +565,188 @@ if ($resql) print ''; } - // Ref - print "\n"; - + // Ref + if (! empty($arrayfields['d.ref']['checked'])) + { + print "\n"; + } // Lastname - print "\n"; - - // Login - print "\n"; - - // Type - $membertypestatic->id=$objp->type_id; - $membertypestatic->libelle=$objp->type; - print ''; - - // Moral/Physique - print "\n"; - + if (! empty($arrayfields['d.lastname']['checked'])) + { + print "\n"; + } + // Firstname + if (! empty($arrayfields['d.firstname']['checked'])) + { + print "\n"; + } + // Company + if (! empty($arrayfields['d.company']['checked'])) + { + print "\n"; + } + // Login + if (! empty($arrayfields['d.login']['checked'])) + { + print "\n"; + } + // Moral/Physique + if (! empty($arrayfields['d.morphy']['checked'])) + { + print "\n"; + } + // Type label + if (! empty($arrayfields['t.libelle']['checked'])) + { + $membertypestatic->id=$obj->type_id; + $membertypestatic->libelle=$obj->type; + print ''; + } + // Address + if (! empty($arrayfields['d.address']['checked'])) + { + print ''; + } + // Town + if (! empty($arrayfields['d.town']['checked'])) + { + print ''; + if (! $i) $totalarray['nbfield']++; + } + // Zip + if (! empty($arrayfields['d.zip']['checked'])) + { + print ''; + if (! $i) $totalarray['nbfield']++; + } + // State + if (! empty($arrayfields['state.nom']['checked'])) + { + print "\n"; + if (! $i) $totalarray['nbfield']++; + } + // Country + if (! empty($arrayfields['country.code_iso']['checked'])) + { + print ''; + if (! $i) $totalarray['nbfield']++; + } // EMail - print "\n"; - - $parameters=array('obj' => $obj); - $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook - print $hookmanager->resPrint; - - // Statut - print '"; - + if (! empty($arrayfields['d.email']['checked'])) + { + print "\n"; + } // End of subscription date - if ($datefin) + $datefin=$db->jdate($obj->datefin); + if (! empty($arrayfields['d.datefin']['checked'])) { - print ''; + if ($datefin) + { + print ''; + } + else + { + print ''; + } } - else + // Extra fields + if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { - print ''; + foreach($extrafields->attribute_label as $key => $val) + { + if (! empty($arrayfields["ef.".$key]['checked'])) + { + print 'getAlignFlag($key); + if ($align) print ' align="'.$align.'"'; + print '>'; + $tmpkey='options_'.$key; + print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1); + print ''; + if (! $i) $totalarray['nbfield']++; + } + } } - - // Actions + // Fields from hook + $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj); + $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + // Date creation + if (! empty($arrayfields['d.datec']['checked'])) + { + print ''; + if (! $i) $totalarray['nbfield']++; + } + // Date modification + if (! empty($arrayfields['d.tms']['checked'])) + { + print ''; + if (! $i) $totalarray['nbfield']++; + } + // Status + if (! empty($arrayfields['d.statut']['checked'])) + { + print ''; + if (! $i) $totalarray['nbfield']++; + } + // Action column print '"; - + if (! $i) $totalarray['nbfield']++; + print "\n"; $i++; } diff --git a/htdocs/admin/barcode.php b/htdocs/admin/barcode.php index b7cc6e94bf2..29475d712df 100644 --- a/htdocs/admin/barcode.php +++ b/htdocs/admin/barcode.php @@ -62,21 +62,12 @@ if ($action == 'setcoder') } else if ($action == 'update') { - if (GETPOST('submit_GENBARCODE_LOCATION')) - { - $location = GETPOST('GENBARCODE_LOCATION','alpha'); - $res = dolibarr_set_const($db, "GENBARCODE_LOCATION",$location,'chaine',0,'',$conf->entity); - } - if (GETPOST('submit_PRODUIT_DEFAULT_BARCODE_TYPE')) - { - $coder_id = GETPOST('PRODUIT_DEFAULT_BARCODE_TYPE','alpha'); - $res = dolibarr_set_const($db, "PRODUIT_DEFAULT_BARCODE_TYPE", $coder_id,'chaine',0,'',$conf->entity); - } - if (GETPOST('submit_GENBARCODE_BARCODETYPE_THIRDPARTY')) - { - $coder_id = GETPOST('GENBARCODE_BARCODETYPE_THIRDPARTY','alpha'); - $res = dolibarr_set_const($db, "GENBARCODE_BARCODETYPE_THIRDPARTY", $coder_id,'chaine',0,'',$conf->entity); - } + $location = GETPOST('GENBARCODE_LOCATION','alpha'); + $res = dolibarr_set_const($db, "GENBARCODE_LOCATION",$location,'chaine',0,'',$conf->entity); + $coder_id = GETPOST('PRODUIT_DEFAULT_BARCODE_TYPE','alpha'); + $res = dolibarr_set_const($db, "PRODUIT_DEFAULT_BARCODE_TYPE", $coder_id,'chaine',0,'',$conf->entity); + $coder_id = GETPOST('GENBARCODE_BARCODETYPE_THIRDPARTY','alpha'); + $res = dolibarr_set_const($db, "GENBARCODE_BARCODETYPE_THIRDPARTY", $coder_id,'chaine',0,'',$conf->entity); } else if ($action == 'updateengine') { @@ -195,9 +186,9 @@ $var=true; print '
'; print load_fiche_titre($langs->trans("BarcodeEncodeModule"),'',''); -print ""; -print ''; -print ""; +//print ""; +//print ''; +//print ""; print '
 
 '; + print ''; + print ''; - print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + $listetype=$membertypestatic->liste_array(); + print $form->selectarray("type", $listetype, $type, 1, 0, 0, '', 0, 32); + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print $form->select_country($search_country,'search_country','',0,'maxwidth100'); + print ''; + print ''; - print ''; - print ''; - $listetype=$membertypestatic->liste_array(); - print $form->selectarray("type", $listetype, $type, 1, 0, 0, '', 0, 32); + if (! empty($arrayfields['d.datefin']['checked'])) + { + print ''; + print ''; + if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select'))) + { + $crit=$val; + $tmpkey=preg_replace('/search_options_/','',$key); + $searchclass=''; + if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring'; + if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum'; + print ''; + } + print ''; + print ''; + print ''; + $liststatus=array( + '-1'=>$langs->trans("Draft"), + '1'=>$langs->trans("Validated"), + '0'=>$langs->trans("Resiliated") + ); + print $form->selectarray('statut', $liststatus, $statut, -2); + print ''; + $searchpitco=$form->showFilterAndCheckAddButtons(0); + print $searchpitco; print ' '; - print ' '; - $searchpitco=$form->showFilterAndCheckAddButtons(0); - print $searchpitco; - print '
'.($i+1).'"; - print $memberstatic->getNomUrl(1); - print ""; + print $memberstatic->getNomUrl(1); + print "rowid\">"; - print ((! empty($objp->lastname) || ! empty($objp->firstname)) ? dol_trunc($memberstatic->getFullName($langs)) : ''); - print (((! empty($objp->lastname) || ! empty($objp->firstname)) && ! empty($companyname)) ? ' / ' : ''); - print (! empty($companyname) ? dol_trunc($companyname, 32) : ''); - print "".$objp->login."'; - print $membertypestatic->getNomUrl(1,32); - print '".$memberstatic->getmorphylib($objp->morphy).""; + print $obj->lastname; + print ""; + print $obj->firstname; + print ""; + print $companyname; + print "".$obj->login."".$memberstatic->getmorphylib($obj->morphy)."'; + print $membertypestatic->getNomUrl(1,32); + print ''; + print $obj->address; + print ''; + print $obj->town; + print ''; + print $obj->zip; + print '".$obj->state_name."'; + $tmparray=getCountry($obj->country,'all'); + print $tmparray['label']; + print '".dol_print_email($objp->email,0,0,1)."'; - print $memberstatic->LibStatut($objp->statut,$objp->cotisation,$datefin,2); - print "".dol_print_email($obj->email,0,0,1)."'; - print dol_print_date($datefin,'day'); - if ($memberstatic->hasDelay()) { - print " ".img_warning($langs->trans("SubscriptionLate")); - } - print ''; + print dol_print_date($datefin,'day'); + if ($memberstatic->hasDelay()) { + print " ".img_warning($langs->trans("SubscriptionLate")); + } + print ''; + if ($obj->cotisation == 'yes') + { + print $langs->trans("SubscriptionNotReceived"); + if ($obj->statut > 0) print " ".img_warning(); + } + else + { + print ' '; + } + print ''; - if ($objp->cotisation == 'yes') - { - print $langs->trans("SubscriptionNotReceived"); - if ($objp->statut > 0) print " ".img_warning(); - } - else - { - print ' '; - } - print ''; + print dol_print_date($db->jdate($obj->date_creation), 'dayhour'); + print ''; + print dol_print_date($db->jdate($obj->date_update), 'dayhour'); + print ''; + print $memberstatic->LibStatut($obj->statut,$obj->cotisation,$datefin,2); + print ''; if ($user->rights->adherent->creer) { - print "rowid."&action=edit&backtopage=1\">".img_edit().""; + print "rowid."&action=edit&backtopage=1\">".img_edit().""; } print ' '; - if ($user->rights->adherent->supprimer && $objp->statut == -1) + if ($user->rights->adherent->supprimer && $obj->statut == -1) { - print "rowid."&action=delete&backtopage=1\">".img_picto($langs->trans("Delete"),'disable.png').""; + print "rowid."&action=delete&backtopage=1\">".img_picto($langs->trans("Delete"),'disable.png').""; } - if ($user->rights->adherent->supprimer && $objp->statut == 1) + if ($user->rights->adherent->supprimer && $obj->statut == 1) { - print "rowid."&action=resign&backtopage=1\">".img_picto($langs->trans("Resiliate"),'disable.png').""; + print "rowid."&action=resign&backtopage=1\">".img_picto($langs->trans("Resiliate"),'disable.png').""; } print "
'; print ''; @@ -261,7 +252,7 @@ if ($resql) // Build barcode on disk (not used, this is done to make debug easier) $result=$module->writeBarCode($obj->example,$obj->encoding,'Y'); // Generate on the fly and output barcode with generator - $url=DOL_URL_ROOT.'/viewimage.php?modulepart=barcode&generator='.urlencode($obj->coder).'&code='.urlencode($obj->example).'&encoding='.urlencode($obj->encoding); + $url=DOL_URL_ROOT.'/viewimage.php?modulepart=barcode&generator='.urlencode($obj->coder).'&code='.urlencode($obj->example).'&encoding='.urlencode($obj->encoding); //print $url; print ''; } @@ -296,7 +287,7 @@ if (empty($conf->use_javascript_ajax)) // TODO Implement code behind action updateengine //print '
'; } -print ''; +//print ''; print "
"; @@ -331,9 +322,7 @@ if (! isset($_SERVER['WINDIR'])) $langs->load("errors"); print '
'.$langs->trans("ErrorFileNotFound",$conf->global->GENBARCODE_LOCATION).''; } - print ''; - print ''; - print ''; + print ''; } // Module products @@ -344,10 +333,7 @@ if (! empty($conf->product->enabled)) print ''; print '"; - print ''; + print ''; } // Module thirdparty @@ -358,13 +344,13 @@ if (! empty($conf->societe->enabled)) print ''; print '"; - print ''; + print ''; } print "
'.$langs->trans("SetDefaultBarcodeTypeProducts").''; $formbarcode->select_barcode_type($conf->global->PRODUIT_DEFAULT_BARCODE_TYPE,"PRODUIT_DEFAULT_BARCODE_TYPE",1); - print ''; - print ''; - print "
'.$langs->trans("SetDefaultBarcodeTypeThirdParties").''; print $formbarcode->select_barcode_type($conf->global->GENBARCODE_BARCODETYPE_THIRDPARTY,"GENBARCODE_BARCODETYPE_THIRDPARTY",1); - print ''; - print ''; - print "
\n"; +print '
'; +print ''; +print "
"; print ''; print '
'; @@ -419,13 +405,13 @@ if ($conf->produit->enabled) if ($conf->global->BARCODE_PRODUCT_ADDON_NUM == "$file") { - print '
'; + print ''; print img_picto($langs->trans("Activated"),'switch_on'); print ''; + print ''; print img_picto($langs->trans("Disabled"),'switch_off'); print '
\n"; } -print ''; +//print ''; print "
"; diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php index c9e07677512..ee6cbac057f 100644 --- a/htdocs/admin/company.php +++ b/htdocs/admin/company.php @@ -731,7 +731,9 @@ else $var=!$var; print ''.$langs->trans("CompanyCurrency").''; print currency_name($conf->currency,1); - print ' ('.$langs->getCurrencySymbol($conf->currency).')'; + print ' ('.$conf->currency; + print ($conf->currency != $langs->getCurrencySymbol($conf->currency) ? ' - '.$langs->getCurrencySymbol($conf->currency) : ''); + print ')'; print ''; $var=!$var; diff --git a/htdocs/admin/dict.php b/htdocs/admin/dict.php index ea745e45df7..797b35f7c75 100644 --- a/htdocs/admin/dict.php +++ b/htdocs/admin/dict.php @@ -188,8 +188,8 @@ $tabsql[27]= "SELECT id as rowid, code, libelle, active FROM ".MAIN_DB_PREF $tabsql[28]= "SELECT h.rowid as rowid, h.code, h.label, h.affect, h.delay, h.newbymonth, h.fk_country as country_id, c.code as country_code, c.label as country, h.active FROM ".MAIN_DB_PREFIX."c_holiday_types as h LEFT JOIN ".MAIN_DB_PREFIX."c_country as c ON h.fk_country=c.rowid"; $tabsql[29]= "SELECT rowid as rowid, code, label, percent, position, active FROM ".MAIN_DB_PREFIX."c_lead_status"; $tabsql[30]= "SELECT rowid, code, name, paper_size, orientation, metric, leftmargin, topmargin, nx, ny, spacex, spacey, width, height, font_size, custom_x, custom_y, active FROM ".MAIN_DB_PREFIX."c_format_cards"; -$tabsql[31]= "SELECT s.rowid as rowid, pcg_version, s.fk_pays as country_id, c.code as country_code, c.label as country, s.label, s.active FROM ".MAIN_DB_PREFIX."accounting_system as s, ".MAIN_DB_PREFIX."c_country as c WHERE s.fk_pays=c.rowid and c.active=1"; -$tabsql[32]= "SELECT a.rowid as rowid, a.code as code, a.label, a.range_account, a.position, a.fk_country as country_id, c.code as country_code, c.label as country, a.active FROM ".MAIN_DB_PREFIX."c_accounting_category as a, ".MAIN_DB_PREFIX."c_country as c WHERE a.fk_country=c.rowid and c.active=1"; +$tabsql[31]= "SELECT s.rowid as rowid, pcg_version, s.label, s.active FROM ".MAIN_DB_PREFIX."accounting_system as s"; +$tabsql[32]= "SELECT a.rowid as rowid, a.code as code, a.label, a.range_account, a.sens, a.category_type, a.formula, a.position as position, a.fk_country as country_id, c.code as country_code, c.label as country, a.active FROM ".MAIN_DB_PREFIX."c_accounting_category as a, ".MAIN_DB_PREFIX."c_country as c WHERE a.fk_country=c.rowid and c.active=1"; $tabsql[33]= "SELECT rowid, pos, code, label, active FROM ".MAIN_DB_PREFIX."c_hrm_department"; $tabsql[34]= "SELECT rowid, pos, code, label, c_level, active FROM ".MAIN_DB_PREFIX."c_hrm_function"; @@ -226,7 +226,7 @@ $tabsqlsort[28]="country ASC, code ASC"; $tabsqlsort[29]="position ASC"; $tabsqlsort[30]="code ASC"; $tabsqlsort[31]="pcg_version ASC"; -$tabsqlsort[32]="code ASC, label ASC"; +$tabsqlsort[32]="position ASC"; $tabsqlsort[33]="code ASC"; $tabsqlsort[34]="code ASC"; @@ -262,8 +262,8 @@ $tabfield[27]= "code,libelle"; $tabfield[28]= "code,label,affect,delay,newbymonth,country_id,country"; $tabfield[29]= "code,label,percent,position"; $tabfield[30]= "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y"; -$tabfield[31]= "pcg_version,country_id,country,label"; -$tabfield[32]= "code,label,range,position,country_id,country"; +$tabfield[31]= "pcg_version,label"; +$tabfield[32]= "code,label,range_account,sens,category_type,formula,position,country_id,country"; $tabfield[33]= "code,label"; $tabfield[34]= "code,label"; @@ -299,8 +299,8 @@ $tabfieldvalue[27]= "code,libelle"; $tabfieldvalue[28]= "code,label,affect,delay,newbymonth,country"; $tabfieldvalue[29]= "code,label,percent,position"; $tabfieldvalue[30]= "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y"; -$tabfieldvalue[31]= "pcg_version,country,label"; -$tabfieldvalue[32]= "code,label,range_account,position,country"; +$tabfieldvalue[31]= "pcg_version,label"; +$tabfieldvalue[32]= "code,label,range_account,sens,category_type,formula,position,country"; $tabfieldvalue[33]= "code,label"; $tabfieldvalue[34]= "code,label"; @@ -336,8 +336,8 @@ $tabfieldinsert[27]= "code,libelle"; $tabfieldinsert[28]= "code,label,affect,delay,newbymonth,fk_country"; $tabfieldinsert[29]= "code,label,percent,position"; $tabfieldinsert[30]= "code,name,paper_size,orientation,metric,leftmargin,topmargin,nx,ny,spacex,spacey,width,height,font_size,custom_x,custom_y"; -$tabfieldinsert[31]= "pcg_version,fk_pays,label"; -$tabfieldinsert[32]= "code,label,range_account,position,fk_country"; +$tabfieldinsert[31]= "pcg_version,label"; +$tabfieldinsert[32]= "code,label,range_account,sens,category_type,formula,position,fk_country"; $tabfieldinsert[33]= "code,label"; $tabfieldinsert[34]= "code,label"; @@ -524,6 +524,7 @@ if ($id == 11) 'propal' => $langs->trans('Proposal'), 'commande' => $langs->trans('Order'), 'facture' => $langs->trans('Bill'), + 'resource' => $langs->trans('Resource'), // 'facture_fourn' => $langs->trans('SupplierBill'), 'fichinter' => $langs->trans('InterventionCard') ); @@ -585,6 +586,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify')) if ($value == 'localtax1' && empty($_POST['localtax1_type'])) continue; if ($value == 'localtax2' && empty($_POST['localtax2_type'])) continue; if ($value == 'color' && empty($_POST['color'])) continue; + if ($value == 'formula' && empty($_POST['formula'])) continue; if ((! isset($_POST[$value]) || $_POST[$value]=='') && (! in_array($listfield[$f], array('decalage','module','accountancy_code','accountancy_code_sell','accountancy_code_buy'))) // Fields that are not mandatory ) @@ -605,6 +607,7 @@ if (GETPOST('actionadd') || GETPOST('actionmodify')) if ($fieldnamekey == 'unicode') $fieldnamekey = 'Unicode'; if ($fieldnamekey == 'deductible') $fieldnamekey = 'Deductible'; if ($fieldnamekey == 'sortorder') $fieldnamekey = 'SortOrder'; + if ($fieldnamekey == 'category_type') $fieldnamekey = 'Calculated'; setEventMessages($langs->transnoentities("ErrorFieldRequired", $langs->transnoentities($fieldnamekey)), null, 'errors'); } @@ -999,6 +1002,9 @@ if ($id) if ($fieldlist[$field]=='short_label') { $valuetoshow=$langs->trans("ShortLabel"); } if ($fieldlist[$field]=='type_template') { $valuetoshow=$langs->trans("TypeOfTemplate"); } if ($fieldlist[$field]=='range_account') { $valuetoshow=$langs->trans("Range"); } + if ($fieldlist[$field]=='sens') { $valuetoshow=$langs->trans("Sens"); } + if ($fieldlist[$field]=='category_type') { $valuetoshow=$langs->trans("Calculated"); } + if ($fieldlist[$field]=='formula') { $valuetoshow=$langs->trans("Formula"); } if ($id == 2) // Special cas for state page { @@ -1064,7 +1070,7 @@ if ($id) } print ''; print ""; - + if ($tabname[$id] == MAIN_DB_PREFIX.'c_email_templates') { print '* '.$langs->trans("AvailableVariables").": "; @@ -1167,6 +1173,9 @@ if ($id) if ($fieldlist[$field]=='short_label') { $valuetoshow=$langs->trans("ShortLabel"); } if ($fieldlist[$field]=='type_template') { $valuetoshow=$langs->trans("TypeOfTemplate"); } if ($fieldlist[$field]=='range_account') { $valuetoshow=$langs->trans("Range"); } + if ($fieldlist[$field]=='sens') { $valuetoshow=$langs->trans("Sens"); } + if ($fieldlist[$field]=='category_type') { $valuetoshow=$langs->trans("Calculated"); } + if ($fieldlist[$field]=='formula') { $valuetoshow=$langs->trans("Formula"); } // Affiche nom du champ if ($showfield) @@ -1248,7 +1257,7 @@ if ($id) $valuetoshow=($key != "Country".strtoupper($obj->country_code)?$obj->country_code." - ".$key:$obj->country); } } - else if ($fieldlist[$field]=='recuperableonly' || $fieldlist[$field]=='fdm' || $fieldlist[$field] == 'deductible') { + else if ($fieldlist[$field]=='recuperableonly' || $fieldlist[$field]=='fdm' || $fieldlist[$field] == 'deductible' || $fieldlist[$field] == 'category_type') { $valuetoshow=yn($valuetoshow); $align="center"; } @@ -1618,7 +1627,7 @@ function fieldList($fieldlist, $obj='', $tabname='', $context='') print 'user'; print ''; } - elseif ($fieldlist[$field] == 'recuperableonly' || $fieldlist[$field] == 'fdm' || $fieldlist[$field] == 'deductible') { + elseif ($fieldlist[$field] == 'recuperableonly' || $fieldlist[$field] == 'fdm' || $fieldlist[$field] == 'deductible' || $fieldlist[$field] == 'category_type') { print ''; print $form->selectyesno($fieldlist[$field],(! empty($obj->{$fieldlist[$field]})?$obj->{$fieldlist[$field]}:''),1); print ''; @@ -1697,7 +1706,7 @@ function fieldList($fieldlist, $obj='', $tabname='', $context='') if ($fieldlist[$field]=='position') $size='size="4" '; if ($fieldlist[$field]=='libelle') $size='centpercent'; if ($fieldlist[$field]=='tracking') $class='centpercent'; - if ($fieldlist[$field]=='sortorder') $size='size="2" '; + if ($fieldlist[$field]=='sortorder' || $fieldlist[$field]=='sens' || $fieldlist[$field]=='category_type') $size='size="2" '; print ''; print ''; } diff --git a/htdocs/admin/fckeditor.php b/htdocs/admin/fckeditor.php index b5bd4d045f6..e244941ff58 100644 --- a/htdocs/admin/fckeditor.php +++ b/htdocs/admin/fckeditor.php @@ -189,7 +189,19 @@ else show_skin(null,1); print '
'."\n"; - print load_fiche_titre($langs->trans("TestSubmitForm"),'(mode='.$mode.')',''); + $listofmodes=array('dolibarr_mailings','dolibarr_notes','dolibarr_details','Full'); + $linkstomode=''; + foreach($listofmodes as $newmode) + { + if ($linkstomode) $linkstomode.=' - '; + $linkstomode.=''; + if ($mode == $newmode) $linkstomode.=''; + $linkstomode.=$newmode; + if ($mode == $newmode) $linkstomode.=''; + $linkstomode.=''; + } + $linkstomode.=''; + print load_fiche_titre($langs->trans("TestSubmitForm"),$linkstomode,''); print ''; $uselocalbrowser=true; $readonly=($mode=='dolibarr_readonly'?1:0); diff --git a/htdocs/admin/loan.php b/htdocs/admin/loan.php index 1cc55bd5a36..3213503835d 100644 --- a/htdocs/admin/loan.php +++ b/htdocs/admin/loan.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2014-2016 Alexandre Spangaro * * 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 @@ -26,6 +26,7 @@ require '../main.inc.php'; // Class require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php'; $langs->load("admin"); $langs->load("loan"); @@ -76,6 +77,7 @@ if ($action == 'update') llxHeader(); $form = new Form($db); +if (! empty($conf->accounting->enabled)) $formaccountancy = New FormVentilation($db); $linkback=''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans('ConfigLoan'),$linkback,'title_setup'); @@ -104,7 +106,14 @@ foreach ($list as $key) // Value print ''; - print ''; + if (! empty($conf->accounting->enabled)) + { + print $formaccountancy->select_account($conf->global->$key, $key, 1, '', 1, 1); + } + else + { + print ''; + } print ''; } diff --git a/htdocs/admin/menus/edit.php b/htdocs/admin/menus/edit.php index f4f1bbb96bf..5fc39432c8e 100644 --- a/htdocs/admin/menus/edit.php +++ b/htdocs/admin/menus/edit.php @@ -75,6 +75,7 @@ if ($action == 'update') $menu->perms=$_POST['perms']; $menu->target=$_POST['target']; $menu->user=$_POST['user']; + $menu->fk_menu=$_POST['fk_menu']; $result=$menu->update($user); if ($result > 0) { @@ -275,6 +276,8 @@ if ($action == 'create') print '
'; print ''; + dol_fiche_head(); + print ''; // Id @@ -368,8 +371,10 @@ if ($action == 'create') print '
'; + dol_fiche_end(); + // Boutons - print '
'; + print '
'; print ''; print '     '; print ''; @@ -387,6 +392,8 @@ elseif ($action == 'edit') print ''; print ''; + dol_fiche_head(); + print ''; $menu = new Menubase($db); @@ -416,9 +423,9 @@ elseif ($action == 'edit') // MenuId Parent print ''; + print ''; //$menu_handler //print ''; - print ''; print ''; // Niveau @@ -454,8 +461,10 @@ elseif ($action == 'edit') print '
'.$langs->trans('MenuIdParent').''.$menu->fk_menu.''.$langs->trans('DetailMenuIdParent').'
'; + dol_fiche_end(); + // Bouton - print '
'; + print '
'; print ''; print '     '; print ''; diff --git a/htdocs/admin/pdf.php b/htdocs/admin/pdf.php index 3b968af09c3..b22ad287302 100644 --- a/htdocs/admin/pdf.php +++ b/htdocs/admin/pdf.php @@ -63,6 +63,7 @@ if ($action == 'update') dolibarr_set_const($db, "MAIN_GENERATE_DOCUMENTS_HIDE_DESC", $_POST["MAIN_GENERATE_DOCUMENTS_HIDE_DESC"],'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_GENERATE_DOCUMENTS_HIDE_REF", $_POST["MAIN_GENERATE_DOCUMENTS_HIDE_REF"],'chaine',0,'',$conf->entity); dolibarr_set_const($db, "MAIN_PDF_USE_ISO_LOCATION", $_POST["MAIN_PDF_USE_ISO_LOCATION"],'chaine',0,'',$conf->entity); + dolibarr_set_const($db, "MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS", $_POST["MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS"],'chaine',0,'',$conf->entity); header("Location: ".$_SERVER["PHP_SELF"]."?mainmenu=home&leftmenu=setup"); exit; @@ -94,6 +95,13 @@ $form=new Form($db); $formother=new FormOther($db); $formadmin=new FormAdmin($db); +$arraydetailsforpdffoot = array( + 0 => $langs->trans('NoDetails'), + 1 => $langs->trans('DisplayCompanyInfo'), + 2 => $langs->trans('DisplayManagersInfo'), + 3 => $langs->trans('DisplayCompanyInfoAndManagers') +); + print load_fiche_titre($langs->trans("PDF"),'','title_setup'); print $langs->trans("PDFDesc")."
\n"; @@ -253,7 +261,11 @@ if ($action == 'edit') // Edit print ''.$langs->trans("PlaceCustomerAddressToIsoLocation").''; print $form->selectyesno('MAIN_PDF_USE_ISO_LOCATION',(! empty($conf->global->MAIN_PDF_USE_ISO_LOCATION))?$conf->global->MAIN_PDF_USE_ISO_LOCATION:0,1); print ''; - + + $var=!$var; + print ''.$langs->trans("ShowDetailsInPDFPageFoot").''; + print $form->selectarray('MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS', $arraydetailsforpdffoot, $conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS); + print ''; print ''; @@ -455,6 +467,11 @@ else // Show print ''.$langs->trans("PlaceCustomerAddressToIsoLocation").''; print yn($conf->global->MAIN_PDF_USE_ISO_LOCATION,1); print ''; + + $var=!$var; + print ''.$langs->trans("ShowDetailsInPDFPageFoot").''; + print $arraydetailsforpdffoot[$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS]; + print ''; print ''; diff --git a/htdocs/admin/tools/eaccelerator.php b/htdocs/admin/tools/eaccelerator.php index 588170fbb90..5a142f3e51e 100644 --- a/htdocs/admin/tools/eaccelerator.php +++ b/htdocs/admin/tools/eaccelerator.php @@ -119,19 +119,19 @@ function create_script_table($list) global $sortby,$bc,$langs; $var=true; - if (isset($_GET['order']) && ($_GET['order'] == "asc" || $_GET['order'] =="desc")) { - $order = $_GET['order']; + if (GETPOT('order') == "asc" || GETPOST('order') =="desc") { + $order = GETPOST('order'); } else { $order = "asc"; } - if (isset($_GET['sort'])) { - switch ($_GET['sort']) { + if (GETPOST('order')) { + switch (GETPOST('order')) { case "mtime": case "size": case "reloads": case "hits": - $sortby = $_GET['sort']; + $sortby = GETPOST('sort'); ($order == "asc" ? uasort($list, 'compare') : uasort($list, 'revcompare')); break; default: diff --git a/htdocs/admin/tools/export.php b/htdocs/admin/tools/export.php index b827fe88737..175aaa65665 100644 --- a/htdocs/admin/tools/export.php +++ b/htdocs/admin/tools/export.php @@ -318,7 +318,7 @@ function backup_tables($outputfile, $tables='*') $columns = count($row); for($j=0; $j<$columns; $j++) { // Processing each columns of the row to ensure that we correctly save the value (eg: add quotes for string - in fact we add quotes for everything, it's easier) - if ($row[$j] == null and !is_string($row[$j])) { + if ($row[$j] == null && !is_string($row[$j])) { // IMPORTANT: if the field is NULL we set it NULL $row[$j] = 'NULL'; } elseif(is_string($row[$j]) && $row[$j] == '') { diff --git a/htdocs/admin/websites.php b/htdocs/admin/websites.php index 3db5dd93e49..ecc6b6a0166 100644 --- a/htdocs/admin/websites.php +++ b/htdocs/admin/websites.php @@ -417,14 +417,7 @@ if ($id) if (empty($reshook)) { - if ($tabname[$id] == MAIN_DB_PREFIX.'c_email_templates' && $action == 'edit') - { - fieldList($fieldlist,$obj,$tabname[$id],'hide'); - } - else - { - fieldList($fieldlist,$obj,$tabname[$id],'add'); - } + fieldListWebsites($fieldlist,$obj,$tabname[$id],'add'); } if ($id == 4) print ''; @@ -487,46 +480,9 @@ if ($id) */ $valuetoshow=ucfirst($fieldlist[$field]); // Par defaut $valuetoshow=$langs->trans($valuetoshow); // try to translate - if ($fieldlist[$field]=='source') { $valuetoshow=$langs->trans("Contact"); } - if ($fieldlist[$field]=='price') { $valuetoshow=$langs->trans("PriceUHT"); } - if ($fieldlist[$field]=='taux') { - if ($tabname[$id] != MAIN_DB_PREFIX."c_revenuestamp") $valuetoshow=$langs->trans("Rate"); - else $valuetoshow=$langs->trans("Amount"); - $align='right'; - } - if ($fieldlist[$field]=='localtax1_type') { $valuetoshow=$langs->trans("UseLocalTax")." 2"; $align="center"; $sortable=0; } - if ($fieldlist[$field]=='localtax1') { $valuetoshow=$langs->trans("Rate")." 2"; $sortable=0; } - if ($fieldlist[$field]=='localtax2_type') { $valuetoshow=$langs->trans("UseLocalTax")." 3"; $align="center"; $sortable=0; } - if ($fieldlist[$field]=='localtax2') { $valuetoshow=$langs->trans("Rate")." 3"; $sortable=0; } - if ($fieldlist[$field]=='organization') { $valuetoshow=$langs->trans("Organization"); } if ($fieldlist[$field]=='lang') { $valuetoshow=$langs->trans("Language"); } if ($fieldlist[$field]=='type') { $valuetoshow=$langs->trans("Type"); } if ($fieldlist[$field]=='code') { $valuetoshow=$langs->trans("Code"); } - if ($fieldlist[$field]=='libelle' || $fieldlist[$field]=='label') - { - $valuetoshow=$langs->trans("Label"); - if ($id != 25) $valuetoshow.="*"; - } - if ($fieldlist[$field]=='libelle_facture') { $valuetoshow=$langs->trans("LabelOnDocuments")."*"; } - if ($fieldlist[$field]=='country') { $valuetoshow=$langs->trans("Country"); } - if ($fieldlist[$field]=='recuperableonly') { $valuetoshow=$langs->trans("NPR"); $align="center"; } - if ($fieldlist[$field]=='nbjour') { $valuetoshow=$langs->trans("NbOfDays"); } - if ($fieldlist[$field]=='fdm') { $valuetoshow=$langs->trans("AtEndOfMonth"); } - if ($fieldlist[$field]=='decalage') { $valuetoshow=$langs->trans("Offset"); } - if ($fieldlist[$field]=='width') { $valuetoshow=$langs->trans("Width"); } - if ($fieldlist[$field]=='height') { $valuetoshow=$langs->trans("Height"); } - if ($fieldlist[$field]=='unit') { $valuetoshow=$langs->trans("MeasuringUnit"); } - if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { $showfield=0; } - if ($fieldlist[$field]=='accountancy_code'){ $valuetoshow=$langs->trans("AccountancyCode"); } - if ($fieldlist[$field]=='accountancy_code_sell'){ $valuetoshow=$langs->trans("AccountancyCodeSell"); $sortable=0; } - if ($fieldlist[$field]=='accountancy_code_buy'){ $valuetoshow=$langs->trans("AccountancyCodeBuy"); $sortable=0; } - if ($fieldlist[$field]=='fk_pcg_version') { $valuetoshow=$langs->trans("Pcg_version"); } - if ($fieldlist[$field]=='account_parent') { $valuetoshow=$langs->trans("Accountsparent"); } - if ($fieldlist[$field]=='pcg_type') { $valuetoshow=$langs->trans("Pcg_type"); } - if ($fieldlist[$field]=='pcg_subtype') { $valuetoshow=$langs->trans("Pcg_subtype"); } - if ($fieldlist[$field]=='sortorder') { $valuetoshow=$langs->trans("SortOrder"); } - if ($fieldlist[$field]=='short_label') { $valuetoshow=$langs->trans("ShortLabel"); } - if ($fieldlist[$field]=='type_template') { $valuetoshow=$langs->trans("TypeOfTemplate"); } // Affiche nom du champ if ($showfield) @@ -534,8 +490,6 @@ if ($id) print getTitleFieldOfList($valuetoshow,0,$_SERVER["PHP_SELF"],($sortable?$fieldlist[$field]:''),($page?'page='.$page.'&':'').'&id='.$id,"","align=".$align,$sortfield,$sortorder); } } - // Favorite - Only activated on country dictionary - if ($id == 4) print getTitleFieldOfList($langs->trans("Favorite"),0,$_SERVER["PHP_SELF"],"favorite",($page?'page='.$page.'&':'').'&id='.$id,"",'align="center"',$sortfield,$sortorder); print getTitleFieldOfList($langs->trans("Status"),0,$_SERVER["PHP_SELF"],"status",($page?'page='.$page.'&':'').'&id='.$id,"",'align="center"',$sortfield,$sortorder); print getTitleFieldOfList(''); @@ -562,7 +516,7 @@ if ($id) $reshook=$hookmanager->executeHooks('editDictionaryFieldlist',$parameters,$obj, $tmpaction); // Note that $action and $object may have been modified by some hooks $error=$hookmanager->error; $errors=$hookmanager->errors; - if (empty($reshook)) fieldList($fieldlist,$obj,$tabname[$id],'edit'); + if (empty($reshook)) fieldListWebsites($fieldlist,$obj,$tabname[$id],'edit'); print ' '; print ' '; @@ -582,172 +536,6 @@ if ($id) $showfield=1; $align="left"; $valuetoshow=$obj->$fieldlist[$field]; - if ($value == 'type_template') - { - $valuetoshow = isset($elementList[$valuetoshow])?$elementList[$valuetoshow]:$valuetoshow; - } - if ($value == 'element') - { - $valuetoshow = isset($elementList[$valuetoshow])?$elementList[$valuetoshow]:$valuetoshow; - } - else if ($value == 'source') - { - $valuetoshow = isset($sourceList[$valuetoshow])?$sourceList[$valuetoshow]:$valuetoshow; - } - else if ($valuetoshow=='all') { - $valuetoshow=$langs->trans('All'); - } - else if ($fieldlist[$field]=='country') { - if (empty($obj->country_code)) - { - $valuetoshow='-'; - } - else - { - $key=$langs->trans("Country".strtoupper($obj->country_code)); - $valuetoshow=($key != "Country".strtoupper($obj->country_code)?$obj->country_code." - ".$key:$obj->country); - } - } - else if ($fieldlist[$field]=='recuperableonly' || $fieldlist[$field]=='fdm' || $fieldlist[$field] == 'deductible') { - $valuetoshow=yn($valuetoshow); - $align="center"; - } - else if ($fieldlist[$field]=='price' || preg_match('/^amount/i',$fieldlist[$field])) { - $valuetoshow=price($valuetoshow); - } - else if ($fieldlist[$field]=='libelle_facture') { - $langs->load("bills"); - $key=$langs->trans("PaymentCondition".strtoupper($obj->code)); - $valuetoshow=($obj->code && $key != "PaymentCondition".strtoupper($obj->code)?$key:$obj->$fieldlist[$field]); - $valuetoshow=nl2br($valuetoshow); - } - else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_country') { - $key=$langs->trans("Country".strtoupper($obj->code)); - $valuetoshow=($obj->code && $key != "Country".strtoupper($obj->code)?$key:$obj->$fieldlist[$field]); - } - else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_availability') { - $langs->load("propal"); - $key=$langs->trans("AvailabilityType".strtoupper($obj->code)); - $valuetoshow=($obj->code && $key != "AvailabilityType".strtoupper($obj->code)?$key:$obj->$fieldlist[$field]); - } - else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_actioncomm') { - $key=$langs->trans("Action".strtoupper($obj->code)); - $valuetoshow=($obj->code && $key != "Action".strtoupper($obj->code)?$key:$obj->$fieldlist[$field]); - } - else if (! empty($obj->code_iso) && $fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_currencies') { - $key=$langs->trans("Currency".strtoupper($obj->code_iso)); - $valuetoshow=($obj->code_iso && $key != "Currency".strtoupper($obj->code_iso)?$key:$obj->$fieldlist[$field]); - } - else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_typent') { - $key=$langs->trans(strtoupper($obj->code)); - $valuetoshow=($key != strtoupper($obj->code)?$key:$obj->$fieldlist[$field]); - } - else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_prospectlevel') { - $key=$langs->trans(strtoupper($obj->code)); - $valuetoshow=($key != strtoupper($obj->code)?$key:$obj->$fieldlist[$field]); - } - else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_civility') { - $key=$langs->trans("Civility".strtoupper($obj->code)); - $valuetoshow=($obj->code && $key != "Civility".strtoupper($obj->code)?$key:$obj->$fieldlist[$field]); - } - else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_type_contact') { - $langs->load('agenda'); - $key=$langs->trans("TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code)); - $valuetoshow=($obj->code && $key != "TypeContact_".$obj->element."_".$obj->source."_".strtoupper($obj->code)?$key:$obj->$fieldlist[$field]); - } - else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_payment_term') { - $langs->load("bills"); - $key=$langs->trans("PaymentConditionShort".strtoupper($obj->code)); - $valuetoshow=($obj->code && $key != "PaymentConditionShort".strtoupper($obj->code)?$key:$obj->$fieldlist[$field]); - } - else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_paiement') { - $langs->load("bills"); - $key=$langs->trans("PaymentType".strtoupper($obj->code)); - $valuetoshow=($obj->code && $key != "PaymentType".strtoupper($obj->code)?$key:$obj->$fieldlist[$field]); - } - else if ($fieldlist[$field]=='label' && $tabname[$id]==MAIN_DB_PREFIX.'c_input_reason') { - $key=$langs->trans("DemandReasonType".strtoupper($obj->code)); - $valuetoshow=($obj->code && $key != "DemandReasonType".strtoupper($obj->code)?$key:$obj->$fieldlist[$field]); - } - else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_input_method') { - $langs->load("orders"); - $key=$langs->trans($obj->code); - $valuetoshow=($obj->code && $key != $obj->code)?$key:$obj->$fieldlist[$field]; - } - else if ($fieldlist[$field]=='libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_shipment_mode') { - $langs->load("sendings"); - $key=$langs->trans("SendingMethod".strtoupper($obj->code)); - $valuetoshow=($obj->code && $key != "SendingMethod".strtoupper($obj->code)?$key:$obj->$fieldlist[$field]); - } - else if ($fieldlist[$field] == 'libelle' && $tabname[$id]==MAIN_DB_PREFIX.'c_paper_format') - { - $key = $langs->trans('PaperFormat'.strtoupper($obj->code)); - $valuetoshow = ($obj->code && $key != 'PaperFormat'.strtoupper($obj->code) ? $key : $obj->$fieldlist[$field]); - } - else if ($fieldlist[$field] == 'label' && $tabname[$id] == MAIN_DB_PREFIX.'c_type_fees') - { - $langs->load('trips'); - $key = $langs->trans(strtoupper($obj->code)); - $valuetoshow = ($obj->code && $key != strtoupper($obj->code) ? $key : $obj->$fieldlist[$field]); - } - else if ($fieldlist[$field]=='region_id' || $fieldlist[$field]=='country_id') { - $showfield=0; - } - else if ($fieldlist[$field]=='unicode') { - $valuetoshow = $langs->getCurrencySymbol($obj->code,1); - } - else if ($fieldlist[$field]=='label' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_units') { - $langs->load("products"); - $valuetoshow=$langs->trans($obj->$fieldlist[$field]); - } - else if ($fieldlist[$field]=='short_label' && $tabname[$_GET["id"]]==MAIN_DB_PREFIX.'c_units') { - $langs->load("products"); - $valuetoshow = $langs->trans($obj->$fieldlist[$field]); - } - else if (($fieldlist[$field] == 'unit') && ($tabname[$id] == MAIN_DB_PREFIX.'c_paper_format')) - { - $key = $langs->trans('SizeUnit'.strtolower($obj->unit)); - $valuetoshow = ($obj->code && $key != 'SizeUnit'.strtolower($obj->unit) ? $key : $obj->$fieldlist[$field]); - } - - else if ($fieldlist[$field]=='localtax1_type') { - if ($obj->localtax1 != 0) - $valuetoshow=$localtax_typeList[$valuetoshow]; - else - $valuetoshow = ''; - $align="center"; - } - else if ($fieldlist[$field]=='localtax2_type') { - if ($obj->localtax2 != 0) - $valuetoshow=$localtax_typeList[$valuetoshow]; - else - $valuetoshow = ''; - $align="center"; - } - else if ($fieldlist[$field]=='localtax1') { - $valuetoshow = price($valuetoshow, 0, $langs, 0, 0); - if ($obj->localtax1 == 0) - $valuetoshow = ''; - $align="right"; - } - else if ($fieldlist[$field]=='localtax2') { - $valuetoshow = price($valuetoshow, 0, $langs, 0, 0); - if ($obj->localtax2 == 0) - $valuetoshow = ''; - $align="right"; - } - else if (in_array($fieldlist[$field],array('taux','localtax1','localtax2'))) - { - $valuetoshow = price($valuetoshow, 0, $langs, 0, 0); - $align="right"; - } - else if (in_array($fieldlist[$field],array('recuperableonly'))) - { - $align="center"; - } - else if ($fieldlist[$field]=='accountancy_code' || $fieldlist[$field]=='accountancy_code_sell' || $fieldlist[$field]=='accountancy_code_buy') { - $valuetoshow = length_accountg($valuetoshow); - } // Show value for field if ($showfield) print ''.$valuetoshow.''; @@ -757,16 +545,6 @@ if ($id) // Can an entry be erased or disabled ? $iserasable=1;$isdisable=1; // true by default - if (isset($obj->code) && $id != 10) - { - if (($obj->code == '0' || $obj->code == '' || preg_match('/unknown/i',$obj->code))) { $iserasable = 0; $isdisable = 0; } - else if ($obj->code == 'RECEP') { $iserasable = 0; $isdisable = 0; } - else if ($obj->code == 'EF0') { $iserasable = 0; $isdisable = 0; } - } - - if (isset($obj->type) && in_array($obj->type, array('system', 'systemauto'))) { $iserasable=0; } - if (in_array($obj->code, array('AC_OTH','AC_OTH_AUTO')) || in_array($obj->type, array('systemauto'))) { $isdisable=0; $isdisable = 0; } - $url = $_SERVER["PHP_SELF"].'?'.($page?'page='.$page.'&':'').'sortfield='.$sortfield.'&sortorder='.$sortorder.'&rowid='.(! empty($obj->rowid)?$obj->rowid:(! empty($obj->code)?$obj->code:'')).'&code='.(! empty($obj->code)?urlencode($obj->code):'').'&id='.$id.'&'; // Favorite @@ -823,7 +601,7 @@ $db->close(); * @param string $context 'add'=Output field for the "add form", 'edit'=Output field for the "edit form", 'hide'=Output field for the "add form" but we dont want it to be rendered * @return void */ -function fieldList($fieldlist, $obj='', $tabname='', $context='') +function fieldListWebsites($fieldlist, $obj='', $tabname='', $context='') { global $conf,$langs,$db; global $form; diff --git a/htdocs/api/admin/explorer.php b/htdocs/api/admin/explorer.php index 44a14f99675..66d06e91679 100644 --- a/htdocs/api/admin/explorer.php +++ b/htdocs/api/admin/explorer.php @@ -150,12 +150,30 @@ $linkback=''.$langs->trans("BackToM print load_fiche_titre($langs->trans("ApiSetup"),$linkback,'title_setup'); +// Define $urlwithroot +$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); +$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file +//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current + +// Show message +print '
'; +$message=''; +$url='
'.$urlwithroot.'/api/index.php/login?login='.urlencode($user->login).'&password=yourpassword'; +$message.=$langs->trans("UrlToGetKeyToUseAPIs").':
'; +$message.=img_picto('','object_globe.png').' '.$url; +print $message; +print '
'; +print '
'; + +print $langs->trans("ListOfAvailableAPIs").':
'; foreach($listofapis['v1'] as $key => $val) { + if ($key == 'login') continue; if ($key) { //print $key.' - '.$val['classname'].' - '.$val['fullpath']." - ".DOL_MAIN_URL_ROOT.'/api/index.php/'.strtolower(preg_replace('/Api$/','',$val['classname']))."/xxx
\n"; - $url=DOL_MAIN_URL_ROOT.'/api/index.php/'.$key; + $url=$urlwithroot.'/api/index.php/'.$key; + $url.='?api_key=token'; print img_picto('','object_globe.png').' '.$url."
\n"; } diff --git a/htdocs/api/class/api.class.php b/htdocs/api/class/api.class.php index a5020d4e112..bc5b4378c0c 100644 --- a/htdocs/api/class/api.class.php +++ b/htdocs/api/class/api.class.php @@ -167,6 +167,8 @@ class DolibarrApiInit extends DolibarrApi */ public function login($login, $password, $entity = 0) { + global $conf, $dolibarr_main_authentication, $dolibarr_auto_user; + // Authentication mode if (empty($dolibarr_main_authentication)) $dolibarr_main_authentication = 'http,dolibarr'; diff --git a/htdocs/api/class/api_access.class.php b/htdocs/api/class/api_access.class.php index 9d29c60e26a..bebf9a6667b 100644 --- a/htdocs/api/class/api_access.class.php +++ b/htdocs/api/class/api_access.class.php @@ -70,6 +70,7 @@ class DolibarrApiAccess implements iAuthenticate { global $db; + $login = ''; $stored_key = ''; $userClass = Defaults::$userIdentifierClass; @@ -95,11 +96,15 @@ class DolibarrApiAccess implements iAuthenticate throw new RestException(503, 'Error when fetching user api_key :'.$db->error_msg); } - if ( $stored_key != $_GET['api_key']) { + if ($stored_key != $_GET['api_key']) { $userClass::setCacheIdentifier($_GET['api_key']); return false; } + if (! $login) + { + throw new RestException(503, 'Error when searching logn user fro mapi key'); + } $fuser = new User($db); if(! $fuser->fetch('',$login)) { throw new RestException(503, 'Error when fetching user :'.$fuser->error); @@ -116,16 +121,13 @@ class DolibarrApiAccess implements iAuthenticate else { throw new RestException(401, "Failed to login to API. No parameter 'api_key' provided"); - //dol_syslog("Failed to login to API. No parameter key provided", LOG_DEBUG); - //return false; } - $userClass::setCacheIdentifier(static::$role); - Resources::$accessControlFunction = 'DolibarrApiAccess::verifyAccess'; - - $requirefortest = static::$requires; - if (! is_array($requirefortest)) $requirefortest=explode(',',$requirefortest); - return in_array(static::$role, (array) static::$requirefortest) || static::$role == 'admin'; + $userClass::setCacheIdentifier(static::$role); + Resources::$accessControlFunction = 'DolibarrApiAccess::verifyAccess'; + $requirefortest = static::$requires; + if (! is_array($requirefortest)) $requirefortest=explode(',',$requirefortest); + return in_array(static::$role, (array) $requirefortest) || static::$role == 'admin'; } /** diff --git a/htdocs/api/index.php b/htdocs/api/index.php index d7bcedb5fd7..55a45aea4b9 100644 --- a/htdocs/api/index.php +++ b/htdocs/api/index.php @@ -141,6 +141,8 @@ foreach ($modulesdir as $dir) // TODO If not found, redirect to explorer + +// Call API (we suppose we found it) $api->r->handle(); diff --git a/htdocs/categories/class/api_category.class.php b/htdocs/categories/class/api_category.class.php index e17bb273758..f5a5b1f037d 100644 --- a/htdocs/categories/class/api_category.class.php +++ b/htdocs/categories/class/api_category.class.php @@ -45,6 +45,7 @@ class CategoryApi extends DolibarrApi 2 => 'customer', 3 => 'member', 4 => 'contact', + 5 => 'account', ); /** diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 4cd38a693b6..b602bc0076d 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -9,7 +9,7 @@ * Copyright (C) 2013 Philippe Grand * Copyright (C) 2015 Marcos García * Copyright (C) 2015 Raphaël Doursenaud - * Copyright (C) 2016 Charlie Benke + * Copyright (C) 2016 Charlie Benke * * 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 @@ -49,6 +49,8 @@ class Categorie extends CommonObject const TYPE_MEMBER = 3; const TYPE_CONTACT = 4; const TYPE_USER = 4; // categorie contact and user are same + // bank account + const TYPE_ACCOUNT = 5; /** * @var array ID mapping from type string @@ -62,6 +64,7 @@ class Categorie extends CommonObject 'member' => 3, 'contact' => 4, 'user' => 4, + 'account' => 5, ); /** * @var array Foreign keys mapping from type string @@ -75,6 +78,7 @@ class Categorie extends CommonObject 'member' => 'member', 'contact' => 'socpeople', 'user' => 'user', + 'account' => 'account', ); /** * @var array Category tables mapping from type string @@ -88,6 +92,7 @@ class Categorie extends CommonObject 'member' => 'member', 'contact' => 'contact', 'user' => 'user', + 'account' => 'account', ); /** * @var array Object class mapping from type string @@ -101,6 +106,7 @@ class Categorie extends CommonObject 'member' => 'Adherent', 'contact' => 'Contact', 'user' => 'User', + 'account' => 'Account', ); /** * @var array Object table mapping from type string @@ -114,6 +120,7 @@ class Categorie extends CommonObject 'member' => 'adherent', 'contact' => 'socpeople', 'user' => 'user', + 'account' => 'bank_account', ); public $element='category'; @@ -138,6 +145,8 @@ class Categorie extends CommonObject * @see Categorie::TYPE_CUSTOMER * @see Categorie::TYPE_MEMBER * @see Categorie::TYPE_CONTACT + * @see Categorie::TYPE_USER + * @see Categorie::TYPE_ACCOUNT */ var $type; diff --git a/htdocs/categories/index.php b/htdocs/categories/index.php index 02b83fcaef8..f7102bc44e2 100644 --- a/htdocs/categories/index.php +++ b/htdocs/categories/index.php @@ -53,6 +53,7 @@ elseif ($type == Categorie::TYPE_SUPPLIER) $title=$langs->trans("SuppliersCateg elseif ($type == Categorie::TYPE_CUSTOMER) $title=$langs->trans("CustomersCategoriesArea"); elseif ($type == Categorie::TYPE_MEMBER) $title=$langs->trans("MembersCategoriesArea"); elseif ($type == Categorie::TYPE_CONTACT) $title=$langs->trans("ContactsCategoriesArea"); +elseif ($type == Categorie::TYPE_ACCOUNT) $title=$langs->trans("AccountsCategoriesArea"); else $title=$langs->trans("CategoriesArea"); $arrayofjs=array('/includes/jquery/plugins/jquerytreeview/jquery.treeview.js', '/includes/jquery/plugins/jquerytreeview/lib/jquery.cookie.js'); diff --git a/htdocs/categories/photos.php b/htdocs/categories/photos.php index 783326c1e4f..72c184af113 100644 --- a/htdocs/categories/photos.php +++ b/htdocs/categories/photos.php @@ -93,12 +93,13 @@ $form = new Form($db); if ($object->id) { - $title=$langs->trans("ProductsCategoryShort"); if ($type == Categorie::TYPE_PRODUCT) $title=$langs->trans("ProductsCategoryShort"); elseif ($type == Categorie::TYPE_SUPPLIER) $title=$langs->trans("SuppliersCategoryShort"); elseif ($type == Categorie::TYPE_CUSTOMER) $title=$langs->trans("CustomersCategoryShort"); elseif ($type == Categorie::TYPE_MEMBER) $title=$langs->trans("MembersCategoryShort"); elseif ($type == Categorie::TYPE_CONTACT) $title=$langs->trans("ContactCategoriesShort"); + elseif ($type == Categorie::TYPE_ACCOUNT) $title=$langs->trans("AccountsCategoriesShort"); + else $title=$langs->trans("Category"); $head = categories_prepare_head($object,$type); dol_fiche_head($head, 'photos', $title, 0, 'category'); diff --git a/htdocs/categories/traduction.php b/htdocs/categories/traduction.php index f3969793ef0..9d88098e56b 100644 --- a/htdocs/categories/traduction.php +++ b/htdocs/categories/traduction.php @@ -149,6 +149,7 @@ elseif ($type == Categorie::TYPE_SUPPLIER) $title=$langs->trans("SuppliersCateg elseif ($type == Categorie::TYPE_CUSTOMER) $title=$langs->trans("CustomersCategoryShort"); elseif ($type == Categorie::TYPE_MEMBER) $title=$langs->trans("MembersCategoryShort"); elseif ($type == Categorie::TYPE_CONTACT) $title=$langs->trans("ContactCategoriesShort"); +elseif ($type == Categorie::TYPE_ACCOUNT) $title=$langs->trans("AccountsCategoriesShort"); else $title=$langs->trans("Category"); $head = categories_prepare_head($object,$type); diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php index a1486ff344f..284add47add 100644 --- a/htdocs/categories/viewcat.php +++ b/htdocs/categories/viewcat.php @@ -107,7 +107,14 @@ if ($id > 0 && $removeelem > 0) $tmpobject = new Contact($db); $result = $tmpobject->fetch($removeelem); $elementtype = 'contact'; - } + } + else if ($type == Categorie::TYPE_ACCOUNT && $user->rights->banque->configurer) + { + require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + $tmpobject = new Account($db); + $result = $tmpobject->fetch($removeelem); + $elementtype = 'account'; + } $result=$object->del_type($tmpobject,$elementtype); if ($result < 0) dol_print_error('',$object->error); @@ -169,6 +176,7 @@ elseif ($type == Categorie::TYPE_SUPPLIER) $title=$langs->trans("SuppliersCateg elseif ($type == Categorie::TYPE_CUSTOMER) $title=$langs->trans("CustomersCategoryShort"); elseif ($type == Categorie::TYPE_MEMBER) $title=$langs->trans("MembersCategoryShort"); elseif ($type == Categorie::TYPE_CONTACT) $title=$langs->trans("ContactCategoriesShort"); +elseif ($type == Categorie::TYPE_ACCOUNT) $title=$langs->trans("AccountsCategoriesShort"); else $title=$langs->trans("Category"); $head = categories_prepare_head($object,$type); @@ -580,6 +588,59 @@ if($object->type == Categorie::TYPE_CONTACT) } } +// List of accounts +if ($object->type == Categorie::TYPE_ACCOUNT) +{ + require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; + + $accounts = $object->getObjectsInCateg("account"); + if ($accounts < 0) + { + dol_print_error($db, $accounts->error, $accounts->errors); + } + else + { + print "
"; + print "\n"; + print '\n"; + + if (count($accounts) > 0) + { + $var=true; + foreach ($accounts as $key => $account) + { + $var=!$var; + print "\t\n"; + print '\n"; + print '\n"; + print '\n"; + // Link to delete from category + print '\n"; + } + } + else + { + print ""; + } + print "
'.$langs->trans("Account")."
'; + print $account->getNomUrl(1,0); + print "'.$account->bank."'.$account->number."'; + $typeid=$object->type; + $permission=0; + if ($typeid == Categorie::TYPE_PRODUCT) $permission=($user->rights->produit->creer || $user->rights->service->creer); + if ($typeid == Categorie::TYPE_SUPPLIER) $permission=$user->rights->societe->creer; + if ($typeid == Categorie::TYPE_CUSTOMER) $permission=$user->rights->societe->creer; + if ($typeid == Categorie::TYPE_MEMBER) $permission=$user->rights->adherent->creer; + if ($typeid == Categorie::TYPE_ACCOUNT) $permission=$user->rights->banque->configurer; + if ($permission) + { + print ""; + print img_delete($langs->trans("DeleteFromCat")).' '; + print $langs->trans("DeleteFromCat").""; + } + print "
'.$langs->trans("ThisCategoryHasNoAccount")."
\n"; + } +} llxFooter(); diff --git a/htdocs/comm/action/card.php b/htdocs/comm/action/card.php index 9734602c41d..7a2f231879d 100644 --- a/htdocs/comm/action/card.php +++ b/htdocs/comm/action/card.php @@ -1173,7 +1173,7 @@ if ($id > 0) // Clone event if($action == 'clone') { - $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . GETPOST('id'), $langs->trans('CloneAction'), $langs->trans('ConfirmCloneAction', $object->label), 'confirm_clone', $formquestion, 'yes', 1); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . GETPOST('id'), $langs->trans('CloneAction'), $langs->trans('ConfirmCloneEvent', $object->label), 'confirm_clone', $formquestion, 'yes', 1); print $formconfirm; } diff --git a/htdocs/comm/action/listactions.php b/htdocs/comm/action/listactions.php index cfb3bc92333..31290318742 100644 --- a/htdocs/comm/action/listactions.php +++ b/htdocs/comm/action/listactions.php @@ -309,7 +309,7 @@ if ($resql) print_liste_field_titre($langs->trans("ThirdParty"),$_SERVER["PHP_SELF"],"s.nom",$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("Contact"),$_SERVER["PHP_SELF"],"a.fk_contact",$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("ActionsOwnedBy"),$_SERVER["PHP_SELF"],"",$param,"","",$sortfield,$sortorder); - print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"a.percent",$param,"",'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"a.percent",$param,"",'align="center"',$sortfield,$sortorder); print_liste_field_titre(""); print "\n"; @@ -432,7 +432,7 @@ if ($resql) print ''; // Status/Percent - print ''.$actionstatic->LibStatut($obj->percent,6).''; + print ''.$actionstatic->LibStatut($obj->percent,6).''; print ''; diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index 17098310769..38447c17c5e 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -961,82 +961,84 @@ if ($id > 0) * Barre d'actions */ + print '
'; + $parameters = array(); $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been - - print '
'; - - if (! empty($conf->propal->enabled) && $user->rights->propal->creer && $object->status==1) - { - $langs->load("propal"); - print ''; - } - - if (! empty($conf->commande->enabled) && $user->rights->commande->creer && $object->status==1) - { - $langs->load("orders"); - print ''; - } - - if ($user->rights->contrat->creer && $object->status==1) - { - $langs->load("contracts"); - print ''; - } - - if (! empty($conf->ficheinter->enabled) && $user->rights->ficheinter->creer && $object->status==1) - { - $langs->load("fichinter"); - print ''; - } - - // Add invoice - if ($user->societe_id == 0) - { - if (! empty($conf->deplacement->enabled) && $object->status==1) - { - $langs->load("trips"); - print ''; - } - - if (! empty($conf->facture->enabled)) - { - if ($user->rights->facture->creer && $object->status==1) - { - $langs->load("bills"); - $langs->load("orders"); - - if (! empty($conf->commande->enabled)) - { - if (! empty($orders2invoice) && $orders2invoice > 0) print ''; - else print ''; - } - - if ($object->client != 0) print ''; - else print ''; - - } - else - { - print ''; - } - } - } - - // Add action - if (! empty($conf->agenda->enabled) && ! empty($conf->global->MAIN_REPEATTASKONEACHTAB)) - { - if ($user->rights->agenda->myactions->create) - { - print ''; - } - else - { - print ''; - } - } - + if (empty($reshook)) + { + if (! empty($conf->propal->enabled) && $user->rights->propal->creer && $object->status==1) + { + $langs->load("propal"); + print ''; + } + + if (! empty($conf->commande->enabled) && $user->rights->commande->creer && $object->status==1) + { + $langs->load("orders"); + print ''; + } + + if ($user->rights->contrat->creer && $object->status==1) + { + $langs->load("contracts"); + print ''; + } + + if (! empty($conf->ficheinter->enabled) && $user->rights->ficheinter->creer && $object->status==1) + { + $langs->load("fichinter"); + print ''; + } + + // Add invoice + if ($user->societe_id == 0) + { + if (! empty($conf->deplacement->enabled) && $object->status==1) + { + $langs->load("trips"); + print ''; + } + + if (! empty($conf->facture->enabled)) + { + if ($user->rights->facture->creer && $object->status==1) + { + $langs->load("bills"); + $langs->load("orders"); + + if (! empty($conf->commande->enabled)) + { + if (! empty($orders2invoice) && $orders2invoice > 0) print ''; + else print ''; + } + + if ($object->client != 0) print ''; + else print ''; + + } + else + { + print ''; + } + } + } + + // Add action + if (! empty($conf->agenda->enabled) && ! empty($conf->global->MAIN_REPEATTASKONEACHTAB)) + { + if ($user->rights->agenda->myactions->create) + { + print ''; + } + else + { + print ''; + } + } + } + print '
'; if (! empty($conf->global->MAIN_REPEATCONTACTONEACHTAB)) diff --git a/htdocs/comm/index.php b/htdocs/comm/index.php index 5265f73e595..59aa71b5595 100644 --- a/htdocs/comm/index.php +++ b/htdocs/comm/index.php @@ -87,6 +87,11 @@ if (! empty($conf->commande->enabled) && $user->rights->commande->lire) { $listofsearchfields['search_customer_order']=array('text'=>'CustomerOrder'); } +// Search supplier proposal +if (! empty($conf->supplier_proposal->enabled) && $user->rights->supplier_proposal->lire) +{ + $listofsearchfields['search_supplier_proposal']=array('text'=>'SupplierProposalShort'); +} // Search supplier order if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->commande->lire) { @@ -100,12 +105,7 @@ if (! empty($conf->ficheinter->enabled) && $user->rights->ficheinter->lire) // Search contract if (! empty($conf->contrat->enabled) && $user->rights->contrat->lire) { - $listofsearchfields['search_contract']=array('text'=>'Contrat'); -} -// Search supplier proposal -if (! empty($conf->supplier_proposal->enabled) && $user->rights->supplier_proposal->lire) -{ - $listofsearchfields['search_supplier_proposal']=array('text'=>'SupplierProposalShort'); + $listofsearchfields['search_contract']=array('text'=>'Contract'); } if (count($listofsearchfields)) @@ -197,7 +197,7 @@ if (! empty($conf->propal->enabled) && $user->rights->propal->lire) else { $var=!$var; - print ''.$langs->trans("NoProposal").''; + print ''.$langs->trans("NoProposal").''; } print "
"; @@ -277,7 +277,7 @@ if (! empty($conf->supplier_proposal->enabled) && $user->rights->supplier_propos else { $var=!$var; - print ''.$langs->trans("NoProposal").''; + print ''.$langs->trans("NoProposal").''; } print "
"; @@ -357,7 +357,7 @@ if (! empty($conf->commande->enabled) && $user->rights->commande->lire) else { $var=!$var; - print ''.$langs->trans("NoOrder").''; + print ''.$langs->trans("NoOrder").''; } print "
"; @@ -438,7 +438,7 @@ if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->commande else { $var=!$var; - print ''.$langs->trans("NoSupplierOrder").''; + print ''.$langs->trans("NoSupplierOrder").''; } print "
"; diff --git a/htdocs/comm/mailing/advtargetemailing.php b/htdocs/comm/mailing/advtargetemailing.php new file mode 100644 index 00000000000..be8a63225fe --- /dev/null +++ b/htdocs/comm/mailing/advtargetemailing.php @@ -0,0 +1,979 @@ + + * Copyright (C) 2016 Laurent Destailleur + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/comm/mailing/advtargetemailing.php + * \ingroup mailing + * \brief Page to define emailing targets + */ + +require '../../main.inc.php'; + +require_once DOL_DOCUMENT_ROOT . '/comm/mailing/class/mailing.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/lib/emailing.lib.php'; +require_once DOL_DOCUMENT_ROOT . '/comm/mailing/class/advtargetemailing.class.php'; +require_once DOL_DOCUMENT_ROOT . '/comm/mailing/class/html.formadvtargetemailing.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/modules/mailings/advthirdparties.modules.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php'; +require_once DOL_DOCUMENT_ROOT . '/core/class/html.formother.class.php'; + +// Translations +$langs->load("mails"); +$langs->load("companies"); +if (! empty($conf->categorie->enabled)) { + $langs->load("categories"); +} + +// Security check +if (! $user->rights->mailing->lire || $user->societe_id > 0) + accessforbidden(); + +$sortfield = GETPOST("sortfield", 'alpha'); +$sortorder = GETPOST("sortorder", 'alpha'); +$page = GETPOST("page", 'int'); +if ($page == - 1) { + $page = 0; +} +$offset = $conf->liste_limit * $page; +$pageprev = $page - 1; +$pagenext = $page + 1; +if (! $sortorder) + $sortorder = "ASC"; +if (! $sortfield) + $sortfield = "email"; + +$id = GETPOST('id', 'int'); +$rowid = GETPOST('rowid', 'int'); +$action = GETPOST("action"); +$search_nom = GETPOST("search_nom"); +$search_prenom = GETPOST("search_prenom"); +$search_email = GETPOST("search_email"); +$template_id = GETPOST('template_id', 'int'); + +// Do we click on purge search criteria ? +if (GETPOST("button_removefilter_x")) { + $search_nom = ''; + $search_prenom = ''; + $search_email = ''; +} + +$array_query = array (); + +$object = new Mailing($db); +$advTarget = new AdvanceTargetingMailing($db); +if (empty($template_id)) { + $advTarget->fk_mailing = $id; + $result = $advTarget->fetch_by_mailing(); +} else { + $result = $advTarget->fetch($template_id); +} + +if ($result < 0) { + setEventMessage($advTarget->error, 'errors'); +} else { + if (! empty($advTarget->id)) { + $array_query = json_decode($advTarget->filtervalue, true); + } +} + + +/* + * Actions + */ + +if ($action == 'loadfilter') { + if (! empty($template_id)) { + $result = $advTarget->fetch($template_id); + if ($result < 0) { + setEventMessage($advTarget->error, 'errors'); + } else { + if (! empty($advTarget->id)) { + $array_query = json_decode($advTarget->filtervalue, true); + } + } + } +} + +if ($action == 'add') { + + $user_contact_query = false; + + $array_query = array (); + + // Get extra fields + + foreach ( $_POST as $key => $value ) { + // print '$key='.$key.' $value='.$value.'
'; + if (preg_match("/^options_.*(?query_thirdparty($array_query); + if ($result < 0) { + setEventMessage($advTarget->error, 'errors'); + } + /*} else { + $advTarget->thirdparty_lines = array (); + }*/ + + if ($user_contact_query && ($array_query['type_of_target'] == 1 || $array_query['type_of_target'] == 2)) { + $result = $advTarget->query_contact($array_query); + if ($result < 0) { + setEventMessage($advTarget->error, 'errors'); + } + // If use contact but no result use artefact to so not use socid into add_to_target + if (count($advTarget->contact_lines) == 0) { + $advTarget->contact_lines = array ( + 0 + ); + } + } else { + $advTarget->contact_lines = array (); + } + + if ((count($advTarget->thirdparty_lines) > 0) || (count($advTarget->contact_lines) > 0)) { + // Add targets into database + $obj = new mailing_advthirdparties($db); + $result = $obj->add_to_target($id, $advTarget->thirdparty_lines, $array_query['type_of_target'], $advTarget->contact_lines); + } else { + $result = 0; + } + + if ($result > 0) { + $query_temlate_id = ''; + if (! empty($template_id)) { + $query_temlate_id = '&template_id=' . $template_id; + } + header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id . $query_temlate_id); + exit(); + } + if ($result == 0) { + setEventMessage($langs->trans("WarningNoEMailsAdded"), 'warnings'); + } + if ($result < 0) { + setEventMessage($obj->error, 'errors'); + } +} + +if ($action == 'clear') { + // Chargement de la classe + $classname = "MailingTargets"; + $obj = new $classname($db); + $obj->clear_target($id); + + header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id); + exit(); +} + +if ($action == 'savefilter' || $action == 'createfilter') { + + $template_name = GETPOST('template_name'); + $error = 0; + + if ($action == 'createfilter' && empty($template_name)) { + setEventMessage($langs->trans('ErrorFieldRequired', $langs->trans('AdvTgtOrCreateNewFilter')), 'errors'); + $error ++; + } + + if (empty($error)) { + + $array_query = array (); + + // Get extra fields + foreach ( $_POST as $key => $value ) { + if (preg_match("/^options_.*(?filtervalue = json_encode($array_query); + + if ($action == 'createfilter') { + $advTarget->name = $template_name; + $result = $advTarget->create($user); + if ($result < 0) { + setEventMessage($advTarget->error, 'errors'); + } + } elseif ($action == 'savefilter') { + $result = $advTarget->update($user); + if ($result < 0) { + setEventMessage($advTarget->error, 'errors'); + } + } + $template_id = $advTarget->id; + } +} + +if ($action == 'deletefilter') { + $result = $advTarget->delete($user); + if ($result < 0) { + setEventMessage($advTarget->error, 'errors'); + } + header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id); + exit(); +} + +if ($action == 'delete') { + // Ici, rowid indique le destinataire et id le mailing + $sql = "DELETE FROM " . MAIN_DB_PREFIX . "mailing_cibles WHERE rowid=" . $rowid; + $resql = $db->query($sql); + if ($resql) { + if (! empty($id)) { + $classname = "MailingTargets"; + $obj = new $classname($db); + $obj->update_nb($id); + + header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id); + exit(); + } else { + header("Location: liste.php"); + exit(); + } + } else { + dol_print_error($db); + } +} + +if ($_POST["button_removefilter"]) { + $search_nom = ''; + $search_prenom = ''; + $search_email = ''; +} + + +/* + * View + */ + +$extrajs = array ( + '/includes/jquery/plugins/multiselect/js/ui.multiselect.js' +); +$extracss = array ( + '/includes/jquery/plugins/multiselect/css/ui.multiselect.css', +); + +llxHeader('', $langs->trans("MailAdvTargetRecipients"), '', '', '', '', $extrajs, $extracss); + +print ''; + +$form = new Form($db); +$formadvtargetemaling = new FormAdvTargetEmailing($db); +$formcompany = new FormCompany($db); +$formother = new FormOther($db); + +if ($object->fetch($id) >= 0) { + + $head = emailing_prepare_head($object); + + dol_fiche_head($head, 'advtargets', $langs->trans("Mailing"), 0, 'email'); + + print ''; + + $linkback = '' . $langs->trans("BackToList") . ''; + + print ''; + print ''; + + print ''; + + print ''; + + // Errors to + print ''; + + // Status + print ''; + + // Nb of distinct emails + print ''; + + print '
' . $langs->trans("Ref") . ''; + print $form->showrefnav($object, 'id', $linkback); + print '
' . $langs->trans("MailTitle") . '' . $object->titre . '
' . $langs->trans("MailFrom") . '' . dol_print_email($object->email_from, 0, 0, 0, 0, 1) . '
' . $langs->trans("MailErrorsTo") . '' . dol_print_email($object->email_errorsto, 0, 0, 0, 0, 1); + print '
' . $langs->trans("Status") . '' . $object->getLibStatut(4) . '
'; + print $langs->trans("TotalNbOfDistinctRecipients"); + print ''; + $nbemail = ($object->nbemail ? $object->nbemail : '0'); + if (! empty($conf->global->MAILING_LIMIT_SENDBYWEB) && $conf->global->MAILING_LIMIT_SENDBYWEB < $nbemail) { + $text = $langs->trans('LimitSendingEmailing', $conf->global->MAILING_LIMIT_SENDBYWEB); + print $form->textwithpicto($nbemail, $text, 1, 'warning'); + } else { + print $nbemail; + } + print '
'; + + print "
"; + + // Show email selectors + if ($object->statut == 0 && $user->rights->mailing->creer) { + print_fiche_titre($langs->trans("AdvTgtTitle")); + + print '
' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + + print '' . "\n"; + + print '' . "\n"; + + // Customer name + print '' . "\n"; + + // Code Client + print '' . "\n"; + + // Address Client + print '' . "\n"; + + // Zip Client + print '' . "\n"; + + // City Client + print '' . "\n"; + + // Customer Country + print '' . "\n"; + + // State Customer + print '' . "\n"; + + // Mother Company + print '' . "\n"; + + // Prospect/Customer + $selected = $array_query['cust_typecust']; + print '' . "\n"; + + // Prospection status + print '' . "\n"; + + // Prospection comm status + print '' . "\n"; + + // Customer Type + print '' . "\n"; + + // Staff number + print '' . "\n"; + + // Sales manager + print '' . "\n"; + + // Customer Default Langauge + if (! empty($conf->global->MAIN_MULTILANGS)) { + + print '' . "\n"; + } + + if (! empty($conf->categorie->enabled) && $user->rights->categorie->lire) { + // Customer Categories + print '' . "\n"; + } + + // Standard Extrafield feature + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { + // fetch optionals attributes and labels + dol_include_once('/core/class/extrafields.class.php'); + $extrafields = new ExtraFields($db); + $extralabels = $extrafields->fetch_name_optionals_label('societe'); + foreach ( $extralabels as $key => $val ) { + if ($key != 'ts_nameextra' && $key != 'ts_payeur') { + print '' . "\n"; + } + } + } else { + $std_soc = new Societe($db); + $action_search = 'query'; + // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array + include_once DOL_DOCUMENT_ROOT . '/core/class/hookmanager.class.php'; + $hookmanager = new HookManager($db); + $hookmanager->initHooks(array ( + 'thirdpartycard' + )); + if (! empty($advTarget->id)) { + $parameters = array ( + 'array_query' => $advTarget->filtervalue + ); + } + // Module extrafield feature + $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $std_soc, $action_search); + } + + // State Contact + print '' . "\n"; + + // Civility + print ''; + + // contact name + print '' . "\n"; + print '' . "\n"; + + // Contact Country + print '' . "\n"; + + // Never send mass mailing + print '' . "\n"; + + // Contact Date Create + print '' . "\n"; + + // Contact update Create + print '' . "\n"; + + if (! empty($conf->categorie->enabled) && $user->rights->categorie->lire) { + // Customer Categories + print '' . "\n"; + } + + // Standard Extrafield feature + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { + // fetch optionals attributes and labels + dol_include_once('/core/class/extrafields.class.php'); + $extrafields = new ExtraFields($db); + $extralabels = $extrafields->fetch_name_optionals_label('socpeople'); + foreach ( $extralabels as $key => $val ) { + + print '' . "\n"; + } + } + + print '' . "\n"; + print '' . "\n"; + print '' . "\n"; + print '
' . "\n"; + + print '' . "\n"; + + print '
' . $langs->trans('AdvTgtNameTemplate') . ''; + if (! empty($template_id)) { + $default_template = $template_id; + } else { + $default_template = $advTarget->id; + } + print $formadvtargetemaling->selectAdvtargetemailingTemplate('template_id', $default_template); + print ''; + print ''; + print ''; + print $langs->trans('AdvTgtOrCreateNewFilter'); + print ''; + print ''; + print '' . "\n"; + print '
' . $langs->trans('AdvTgtTypeOfIncude') . ''; + print $form->selectarray('type_of_target', $advTarget->select_target_type, $array_query['type_of_target']); + print '' . "\n"; + print $form->textwithpicto('', $langs->trans("AdvTgtTypeOfIncudeHelp"), 1, 'help'); + print '
' . $langs->trans('ThirdPartyName'); + if (! empty($array_query['cust_name'])) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print '' . "\n"; + print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help'); + print '
' . $langs->trans('CustomerCode'); + if (! empty($array_query['cust_code'])) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print '' . "\n"; + print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help'); + print '
' . $langs->trans('Address'); + if (! empty($array_query['cust_adress'])) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print '' . "\n"; + print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help'); + print '
' . $langs->trans('Zip'); + if (! empty($array_query['cust_zip'])) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print '' . "\n"; + print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help'); + print '
' . $langs->trans('Town'); + if (! empty($array_query['cust_city'])) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print '' . "\n"; + print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help'); + print '
' . $langs->trans("Country"); + if (count($array_query['cust_country']) > 0) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print '' . "\n"; + print $formadvtargetemaling->multiselectCountry('cust_country', $array_query['cust_country']); + print '' . "\n"; + print '
' . $langs->trans('Status') . ' ' . $langs->trans('ThirdParty'); + if (count($array_query['cust_status']) > 0) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print ''; + print $formadvtargetemaling->advMultiselectarray('cust_status', array ( + '0' => $langs->trans('ActivityCeased'), + '1' => $langs->trans('InActivity') + ), $array_query['cust_status']); + print '' . "\n"; + print '
' . $langs->trans("Maison mère"); + if (! empty($array_query['cust_mothercompany'])) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print '' . "\n"; + print ''; + print '' . "\n"; + print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help'); + print '
' . $langs->trans('ProspectCustomer') . ' ' . $langs->trans('ThirdParty'); + if (count($array_query['cust_typecust']) > 0) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print ''; + $options_array = array ( + 2 => $langs->trans('Prospect'), + 3 => $langs->trans('ProspectCustomer'), + 1 => $langs->trans('Customer'), + 0 => $langs->trans('NorProspectNorCustomer') + ); + print $formadvtargetemaling->advMultiselectarray('cust_typecust', $options_array, $array_query['cust_typecust']); + print '' . "\n"; + print '
' . $langs->trans('ProspectLevel'); + if (count($array_query['cust_prospect_status']) > 0) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print ''; + print $formadvtargetemaling->multiselectProspectionStatus($array_query['cust_prospect_status'], 'cust_prospect_status', 1); + print '' . "\n"; + print '
' . $langs->trans('StatusProsp'); + if (count($array_query['cust_comm_status']) > 0) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print ''; + print $formadvtargetemaling->advMultiselectarray('cust_comm_status', $advTarget->type_statuscommprospect, $array_query['cust_comm_status']); + print '' . "\n"; + print '
' . $langs->trans("ThirdPartyType"); + if (count($array_query['cust_typeent']) > 0) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print '' . "\n"; + print $formadvtargetemaling->advMultiselectarray('cust_typeent', $formcompany->typent_array(0, " AND id <> 0"), $array_query['cust_typeent']); + print '' . "\n"; + print '
' . $langs->trans("Staff"); + if (count($array_query['cust_effectif_id']) > 0) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print ''; + print $formadvtargetemaling->advMultiselectarray("cust_effectif_id", $formcompany->effectif_array(0, " AND id <> 0"), $array_query['cust_effectif_id']); + print '' . "\n"; + print '
' . $langs->trans("SalesRepresentatives"); + if (count($array_query['cust_saleman']) > 0) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print '' . "\n"; + print $formadvtargetemaling->multiselectselectSalesRepresentatives('cust_saleman', $array_query['cust_saleman'], $user); + print '' . "\n"; + print '
' . $langs->trans("DefaultLang"); + if (count($array_query['cust_language']) > 0) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print '' . "\n"; + print $formadvtargetemaling->multiselectselectLanguage('cust_language', $array_query['cust_language']); + print '' . "\n"; + print '
' . $langs->trans("CustomersCategoryShort"); + if (count($array_query['cust_categ']) > 0) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print '' . "\n"; + print $formadvtargetemaling->multiselectCustomerCategories('cust_categ', $array_query['cust_categ']); + print '' . "\n"; + print '
' . $extrafields->attribute_label[$key]; + if (! empty($array_query['options_' . $key]) || (is_array($array_query['options_' . $key]) && count($array_query['options_' . $key]) > 0)) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print ''; + if (($extrafields->attribute_type[$key] == 'varchar') || ($extrafields->attribute_type[$key] == 'text')) { + print '' . "\n"; + print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help'); + } elseif (($extrafields->attribute_type[$key] == 'int') || ($extrafields->attribute_type[$key] == 'double')) { + print $langs->trans("AdvTgtMinVal") . ''; + print $langs->trans("AdvTgtMaxVal") . ''; + print '' . "\n"; + print $form->textwithpicto('', $langs->trans("AdvTgtSearchIntHelp"), 1, 'help'); + } elseif (($extrafields->attribute_type[$key] == 'date') || ($extrafields->attribute_type[$key] == 'datetime')) { + + print ''; + print '
' . $langs->trans("AdvTgtStartDt") . ''; + print $form->select_date('', 'options_' . $key . '_st_dt'); + print '' . $langs->trans("AdvTgtEndDt") . ''; + print $form->select_date('', 'options_' . $key . '_end_dt'); + print '
'; + + print '
' . "\n"; + print $form->textwithpicto('', $langs->trans("AdvTgtSearchDtHelp"), 1, 'help'); + } elseif (($extrafields->attribute_type[$key] == 'boolean')) { + print $form->selectarray('options_' . $key, array ( + '' => '', + '1' => $langs->trans('Yes'), + '0' => $langs->trans('No') + ), $array_query['options_' . $key]); + print '' . "\n"; + } elseif (($extrafields->attribute_type[$key] == 'select')) { + print $formadvtargetemaling->advMultiselectarray('options_' . $key, $extrafields->attribute_param[$key]['options'], $array_query['options_' . $key]); + print '' . "\n"; + } elseif (($extrafields->attribute_type[$key] == 'sellist')) { + print $formadvtargetemaling->advMultiselectarraySelllist('options_' . $key, $extrafields->attribute_param[$key]['options'], $array_query['options_' . $key]); + print '' . "\n"; + } else { + + print ''; + print '
'; + if (is_array($array_query['options_' . $key])) { + print $extrafields->showInputField($key, implode(',', $array_query['options_' . $key])); + } else { + print $extrafields->showInputField($key, $array_query['options_' . $key]); + } + print '
'; + + print '
' . "\n"; + } + print '
' . $langs->trans('Status') . ' ' . $langs->trans('Contact'); + if (count($array_query['contact_status']) > 0) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print ''; + print $formadvtargetemaling->advMultiselectarray('contact_status', array ( + '0' => $langs->trans('ActivityCeased'), + '1' => $langs->trans('InActivity') + ), $array_query['contact_status']); + print '' . "\n"; + print $form->textwithpicto('', $langs->trans("AdvTgtContactHelp"), 1, 'help'); + print '
' . $langs->trans("UserTitle"); + if (count($array_query['contact_civility']) > 0) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print ''; + print $formadvtargetemaling->multiselectCivility('contact_civility', $array_query['contact_civility']); + print '
' . $langs->trans('Contact') . ' ' . $langs->trans('Lastname'); + if (! empty($array_query['contact_lastname'])) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print '' . "\n"; + print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help'); + print '
' . $langs->trans('Contact') . ' ' . $langs->trans('Firstname'); + if (! empty($array_query['contact_firstname'])) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print '' . "\n"; + print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help'); + print '
' . $langs->trans('Contact') . ' ' . $langs->trans("Country"); + if (count($array_query['contact_country']) > 0) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print '' . "\n"; + print $formadvtargetemaling->multiselectCountry('contact_country', $array_query['contact_country']); + print '' . "\n"; + print '
' . $langs->trans('Contact') . ' ' . $langs->trans("No_Email"); + if (! empty($array_query['contact_no_email'])) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print '' . "\n"; + print $form->selectarray('contact_no_email', array ( + '' => '', + '1' => $langs->trans('Yes'), + '0' => $langs->trans('No') + ), $array_query['contact_no_email']); + print '' . "\n"; + print '
' . $langs->trans('Contact') . ' ' . $langs->trans("DateCreation"); + if (! empty($array_query['contact_create_st_dt'])) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print '' . "\n"; + print ''; + print '
' . $langs->trans("AdvTgtStartDt") . ''; + print $form->select_date($array_query['contact_create_st_dt'], 'contact_create_st_dt', 0, 0, 1, 'find_customer', 1, 1); + print '' . $langs->trans("AdvTgtEndDt") . ''; + print $form->select_date($array_query['contact_create_end_dt'], 'contact_create_end_dt', 0, 0, 1, 'find_customer', 1, 1); + print '
'; + print '
' . "\n"; + print '
' . $langs->trans('Contact') . ' ' . $langs->trans("DateLastModification"); + if (! empty($array_query['contact_update_st_dt'])) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print '' . "\n"; + print ''; + print '
' . $langs->trans("AdvTgtStartDt") . ''; + print $form->select_date($array_query['contact_update_st_dt'], 'contact_update_st_dt', 0, 0, 1, 'find_customer', 1, 1); + print '' . $langs->trans("AdvTgtEndDt") . ''; + print $form->select_date($array_query['contact_update_end_dt'], 'contact_update_end_dt', 0, 0, 1, 'find_customer', 1, 1); + print '
'; + print '
' . "\n"; + print '
' . $langs->trans("ContactCategoriesShort"); + if (count($array_query['contact_categ']) > 0) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print '' . "\n"; + print $formadvtargetemaling->multiselectContactCategories('contact_categ', $array_query['contact_categ']); + print '' . "\n"; + print '
' . $extrafields->attribute_label[$key]; + if ($array_query['options_' . $key . '_cnct'] != '' || (is_array($array_query['options_' . $key . '_cnct']) && count($array_query['options_' . $key . '_cnct']) > 0)) { + print img_picto($langs->trans('AdvTgtUse'), 'ok.png@advtargetemailing'); + } + print ''; + if (($extrafields->attribute_type[$key] == 'varchar') || ($extrafields->attribute_type[$key] == 'text')) { + print '' . "\n"; + print $form->textwithpicto('', $langs->trans("AdvTgtSearchTextHelp"), 1, 'help'); + } elseif (($extrafields->attribute_type[$key] == 'int') || ($extrafields->attribute_type[$key] == 'double')) { + print $langs->trans("AdvTgtMinVal") . ''; + print $langs->trans("AdvTgtMaxVal") . ''; + print '' . "\n"; + print $form->textwithpicto('', $langs->trans("AdvTgtSearchIntHelp"), 1, 'help'); + } elseif (($extrafields->attribute_type[$key] == 'date') || ($extrafields->attribute_type[$key] == 'datetime')) { + + print ''; + print '
' . $langs->trans("AdvTgtStartDt") . ''; + print $form->select_date('', 'options_' . $key . '_st_dt' . '_cnct'); + print '' . $langs->trans("AdvTgtEndDt") . ''; + print $form->select_date('', 'options_' . $key . '_end_dt' . '_cnct'); + print '
'; + + print '
' . "\n"; + print $form->textwithpicto('', $langs->trans("AdvTgtSearchDtHelp"), 1, 'help'); + } elseif (($extrafields->attribute_type[$key] == 'boolean')) { + print $form->selectarray('options_' . $key . '_cnct', array ( + '' => '', + '1' => $langs->trans('Yes'), + '0' => $langs->trans('No') + ), $array_query['options_' . $key . '_cnct']); + print '' . "\n"; + } elseif (($extrafields->attribute_type[$key] == 'select')) { + print $formadvtargetemaling->advMultiselectarray('options_' . $key . '_cnct', $extrafields->attribute_param[$key]['options'], $array_query['options_' . $key . '_cnct']); + print '' . "\n"; + } elseif (($extrafields->attribute_type[$key] == 'sellist')) { + print $formadvtargetemaling->advMultiselectarraySelllist('options_' . $key . '_cnct', $extrafields->attribute_param[$key]['options'], $array_query['options_' . $key . '_cnct']); + print '' . "\n"; + } else { + + print ''; + print '
'; + if (is_array($array_query['options_' . $key . '_cnct'])) { + print $extrafields->showInputField($key, implode(',', $array_query['options_' . $key . '_cnct']), '', '_cnct'); + } else { + print $extrafields->showInputField($key, $array_query['options_' . $key . '_cnct'], '', '_cnct'); + } + print '
'; + + print '
' . "\n"; + } + print '
' . "\n"; + + print '' . "\n"; + + print '
' . "\n"; + print '' . "\n"; + print '
' . "\n"; + + print '
'; + print ''; + print_titre($langs->trans("ToClearAllRecipientsClickHere")); + print ''; + print ''; + print ''; + print ''; + print '
'; + print '
'; + print '
'; + } + + + if (empty($conf->mailchimp->enabled) || (! empty($conf->mailchimp->enabled) && $object->statut != 3)) + { + // List of recipients (TODO Move code of page cibles.php into a .tpl.php file and make an include here to avoid duplicate content) + } +} + +llxFooter(); +$db->close(); \ No newline at end of file diff --git a/htdocs/comm/mailing/card.php b/htdocs/comm/mailing/card.php index 9a7d0349f41..1a54340e7ce 100644 --- a/htdocs/comm/mailing/card.php +++ b/htdocs/comm/mailing/card.php @@ -948,7 +948,7 @@ else } } - print '

'; + print '
'; } // Affichage formulaire de TEST @@ -1052,20 +1052,25 @@ else print ''; - // Ref - print ''; + $linkback = ''.$langs->trans("BackToList").''; + + print ''; + print ''; + // Topic - print ''; + print ''; // From - print ''; + print ''; // To - print ''; + print ''; // Status - print ''; + print ''; // Nb of distinct emails - print ''; + $notshippable=0; + $warning = 0; + $text_info=''; + $text_warning=''; + $nbprod=0; + if (! empty($arrayfields['c.ref']['checked'])) { print ''; // Show shippable Icon (create subloop, so may be slow) - if ($conf->stock->enabled) + if ($conf->stock->enabled) { - $langs->load("stocks"); - if (($obj->fk_statut > 0) && ($obj->fk_statut < 3)) - { - $notshippable=0; - $warning = 0; - $text_info=''; - $text_warning=''; - $nbprod=0; - + $langs->load("stocks"); + if (($obj->fk_statut > 0) && ($obj->fk_statut < 3)) + { $numlines = count($generic_commande->lines); // Loop on each line of order for ($lig=0; $lig < $numlines; $lig++) { @@ -712,17 +712,19 @@ if ($resql) { $nbprod++; // order contains real products $generic_product->id = $generic_commande->lines[$lig]->fk_product; + + // Get local and virtual stock and store it into cache if (empty($productstat_cache[$generic_commande->lines[$lig]->fk_product])) { - $generic_product->load_stock(); - $generic_product->load_virtual_stock(); + $generic_product->load_stock('nobatch'); + //$generic_product->load_virtual_stock(); Already included into load_stock $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_reel; $productstat_cachevirtual[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_theorique; } else { $generic_product->stock_reel = $productstat_cache[$generic_commande->lines[$lig]->fk_product]['stock_reel']; $generic_product->stock_theorique = $productstat_cachevirtual[$generic_commande->lines[$lig]->fk_product]['stock_reel'] = $generic_product->stock_theorique; } - - if (empty($conf->global->SHIPPABLE_ORDER_ICON_IN_LIST)) // Default code is when this option is not set, setting it create strange result + + if (empty($conf->global->SHIPPABLE_ORDER_ICON_IN_LIST)) // Default code. Default is when this option is not set, setting it create strange result { $text_info .= $generic_commande->lines[$lig]->qty.' X '.$generic_commande->lines[$lig]->ref.' '.dol_trunc($generic_commande->lines[$lig]->product_label, 25); $text_info .= ' - '.$langs->trans("Stock").': '.$generic_product->stock_reel; @@ -795,7 +797,7 @@ if ($resql) { print $form->textwithtooltip('',$text_info,2,1,$text_icon,'',2); } - if ($warning) { + if ($warning) { // Always false in default mode print $form->textwithtooltip('', $langs->trans('NotEnoughForAllOrders').'
'.$text_warning, 2, 1, img_picto('', 'error'),'',2); } print ''; @@ -989,6 +991,7 @@ if ($resql) if (! empty($arrayfields['c.facture']['checked'])) { print ''; + if (! $i) $totalarray['nbfield']++; } // Action column diff --git a/htdocs/compta/bank/card.php b/htdocs/compta/bank/card.php index e2cecacb83c..e6043167b22 100644 --- a/htdocs/compta/bank/card.php +++ b/htdocs/compta/bank/card.php @@ -3,7 +3,7 @@ * Copyright (C) 2003 Jean-Louis Bergamo * Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2009 Regis Houssin - * Copyright (C) 2014-2015 Alexandre Spangaro + * Copyright (C) 2014-2016 Alexandre Spangaro * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2016 Marcos García * @@ -34,8 +34,9 @@ require_once DOL_DOCUMENT_ROOT . '/core/class/html.formcompany.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/html.formbank.class.php'; require_once DOL_DOCUMENT_ROOT . '/compta/bank/class/account.class.php'; require_once DOL_DOCUMENT_ROOT . '/core/class/extrafields.class.php'; -require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; -if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT.'/accountancy/class/html.formventilation.class.php'; +if (! empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; +if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/core/lib/accounting.lib.php'; +if (! empty($conf->accounting->enabled)) require_once DOL_DOCUMENT_ROOT . '/accountancy/class/html.formventilation.class.php'; $langs->load("banks"); $langs->load("bills"); @@ -131,6 +132,10 @@ if ($_POST["action"] == 'add') $id = $account->create($user); if ($id > 0) { + // Category association + $categories = GETPOST('categories'); + $account->setCategories($categories); + $_GET["id"]=$id; // Force chargement page en mode visu } else { @@ -207,6 +212,10 @@ if ($_POST["action"] == 'update' && ! $_POST["cancel"]) $result = $account->update($user); if ($result >= 0) { + // Category association + $categories = GETPOST('categories'); + $account->setCategories($categories); + $_GET["id"]=$_POST["id"]; // Force chargement page en mode visu } else @@ -337,6 +346,20 @@ if ($action == 'create') print ''; print ''; + // Tags-Categories + if ($conf->categorie->enabled) + { + print '"; + } + // Comment print ''; print '\n"; + // Categories + if($conf->categorie->enabled) { + print '"; + } + print ''; print ''; @@ -675,7 +705,13 @@ else print '
'.$langs->trans("Ref").''.$object->id.'
'.$langs->trans("Ref").''; + print $form->showrefnav($object,'id', $linkback); + print '
'.$langs->trans("MailTitle").''.$object->titre.'
'.$langs->trans("MailTitle").''.$object->titre.'
'.$langs->trans("MailFrom").''.dol_print_email($object->email_from,0,0,0,0,1).'
'.$langs->trans("MailFrom").''.dol_print_email($object->email_from,0,0,0,0,1).'
'.$langs->trans("MailErrorsTo").''.dol_print_email($object->email_errorsto,0,0,0,0,1).'
'.$langs->trans("MailErrorsTo").''.dol_print_email($object->email_errorsto,0,0,0,0,1).'
'.$langs->trans("Status").''.$object->getLibStatut(4).'
'.$langs->trans("Status").''.$object->getLibStatut(4).'
'; + print '
'; print $langs->trans("TotalNbOfDistinctRecipients"); print ''; $nbemail = ($object->nbemail?$object->nbemail:img_warning('').' '.$langs->trans("NoTargetYet").''); diff --git a/htdocs/comm/mailing/cibles.php b/htdocs/comm/mailing/cibles.php index 0c133fac6df..2ce7d5c110d 100644 --- a/htdocs/comm/mailing/cibles.php +++ b/htdocs/comm/mailing/cibles.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005-2015 Laurent Destailleur + * Copyright (C) 2005-2016 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin * Copyright (C) 2014 Florian Henry * @@ -227,7 +227,7 @@ if ($object->fetch($id) >= 0) // Show email selectors if ($allowaddtarget && $user->rights->mailing->creer) { - print load_fiche_titre($langs->trans("ToAddRecipientsChooseHere"),($user->admin?info_admin($langs->trans("YouCanAddYourOwnPredefindedListHere"),1):''),''); + print load_fiche_titre($langs->trans("ToAddRecipientsChooseHere"), ($user->admin?info_admin($langs->trans("YouCanAddYourOwnPredefindedListHere"),1):''), 'title_generic'); print ''; print ''; @@ -398,12 +398,12 @@ if ($object->fetch($id) >= 0) print ''; print ''; + $cleartext=''; if ($allowaddtarget) { - $cleartext='
'.$langs->trans("ToClearAllRecipientsClickHere").': '.''; + $cleartext=$langs->trans("ToClearAllRecipientsClickHere").' '.''; } - - print_barre_liste($langs->trans("MailSelectedRecipients").$cleartext,$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,"",$num,$nbtotalofrecords,'',0,'','',$limit); - + print_barre_liste($langs->trans("MailSelectedRecipients"),$page,$_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,$cleartext,$num,$nbtotalofrecords,'title_generic',0,'','',$limit); + print ''; print "\n\n"; @@ -540,7 +540,7 @@ if ($object->fetch($id) >= 0) print ''; } - //Sreach Icon + // Search Icon print '
'; + } print "
'; if ($obj->statut == 0) { diff --git a/htdocs/comm/mailing/class/advtargetemailing.class.php b/htdocs/comm/mailing/class/advtargetemailing.class.php new file mode 100644 index 00000000000..62cf5f2436f --- /dev/null +++ b/htdocs/comm/mailing/class/advtargetemailing.class.php @@ -0,0 +1,777 @@ + +* +* 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 +* the Free Software Foundation, either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +/** + * \file comm/mailing/class/advtargetemailing.class.php + * \ingroup mailing + * \brief This file is an example CRUD class file (Create/Read/Update/Delete) + */ + + +/** + * Class to manage advanced emailing target selector + */ +class AdvanceTargetingMailing extends CommonObject +{ + + var $db; //!< To store db handler + var $error; //!< To return error code (or message) + var $errors = array(); //!< To return several error codes (or messages) + var $element='advtargetemailing'; //!< Id that identify managed objects + var $table_element='advtargetemailing'; //!< Name of table without prefix where object is stored + + var $id; + + var $name; + var $entity; + var $fk_mailing; + var $filtervalue; + var $fk_user_author; + var $datec=''; + var $fk_user_mod; + var $tms=''; + + var $select_target_type = array(); + var $type_statuscommprospect=array(); + var $thirdparty_lines; + var $contact_lines; + + + /** + * Constructor + * + * @param DoliDb $db Database handler + */ + function __construct($db) + { + global $langs; + $langs->load('customers'); + + $this->db = $db; + + $this->select_target_type = array('2'=>$langs->trans('Contacts'),'1'=>$langs->trans('Contacts').'+'.$langs->trans('ThirdParty'), + '3'=>$langs->trans('ThirdParty'), + ); + $this->type_statuscommprospect=array( + -1=>$langs->trans("StatusProspect-1"), + 0=>$langs->trans("StatusProspect0"), + 1=>$langs->trans("StatusProspect1"), + 2=>$langs->trans("StatusProspect2"), + 3=>$langs->trans("StatusProspect3")); + + + return 1; + } + + /** + * Create object into database + * + * @param User $user User that creates + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, Id of created object if OK + */ + function create($user, $notrigger=0) + { + global $conf, $langs; + $error=0; + + // Clean parameters + if (isset($this->fk_mailing)) $this->fk_mailing=trim($this->fk_mailing); + if (isset($this->name)) $this->name=trim($this->name); + if (isset($this->filtervalue)) $this->filtervalue=trim($this->filtervalue); + if (isset($this->fk_user_author)) $this->fk_user_author=trim($this->fk_user_author); + if (isset($this->fk_user_mod)) $this->fk_user_mod=trim($this->fk_user_mod); + + + + // Check parameters + // Put here code to add control on parameters values + + // Insert request + $sql = "INSERT INTO ".MAIN_DB_PREFIX."advtargetemailing("; + + $sql.= "name,"; + $sql.= "entity,"; + $sql.= "fk_mailing,"; + $sql.= "filtervalue,"; + $sql.= "fk_user_author,"; + $sql.= "datec,"; + $sql.= "fk_user_mod"; + + + $sql.= ") VALUES ("; + + $sql.= " ".(! isset($this->name)?'NULL':"'".$this->db->escape($this->name)."'").","; + $sql.= " ".$conf->entity.","; + $sql.= " ".(! isset($this->fk_mailing)?'NULL':"'".$this->fk_mailing."'").","; + $sql.= " ".(! isset($this->filtervalue)?'NULL':"'".$this->db->escape($this->filtervalue)."'").","; + $sql.= " ".$user->id.","; + $sql.= " ".$this->db->idate(dol_now()).","; + $sql.= " ".$user->id; + + + $sql.= ")"; + + $this->db->begin(); + + dol_syslog(get_class($this)."::create sql=".$sql, LOG_DEBUG); + $resql=$this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + + if (! $error) + { + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."advtargetemailing"); + + if (! $notrigger) + { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action calls a trigger. + + //// Call triggers + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_CREATE',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::create ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return $this->id; + } + } + + /** + * Load object in memory from the database + * + * @param int $id Id object + * @return int <0 if KO, >0 if OK + */ + function fetch($id) + { + global $langs; + $sql = "SELECT"; + $sql.= " t.rowid,"; + + $sql.= " t.name,"; + $sql.= " t.entity,"; + $sql.= " t.fk_mailing,"; + $sql.= " t.filtervalue,"; + $sql.= " t.fk_user_author,"; + $sql.= " t.datec,"; + $sql.= " t.fk_user_mod,"; + $sql.= " t.tms"; + + $sql.= " FROM ".MAIN_DB_PREFIX."advtargetemailing as t"; + $sql.= " WHERE t.rowid = ".$id; + + dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + + $this->name = $obj->name; + $this->entity = $obj->entity; + $this->fk_mailing = $obj->fk_mailing; + $this->filtervalue = $obj->filtervalue; + $this->fk_user_author = $obj->fk_user_author; + $this->datec = $this->db->jdate($obj->datec); + $this->fk_user_mod = $obj->fk_user_mod; + $this->tms = $this->db->jdate($obj->tms); + + } + $this->db->free($resql); + + return 1; + } + else + { + $this->error="Error ".$this->db->lasterror(); + dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR); + return -1; + } + } + + /** + * Load object in memory from the database + * + * @param int $id Id object + * @return int <0 if KO, >0 if OK + */ + function fetch_by_mailing($id=0) + { + global $langs; + $sql = "SELECT"; + $sql.= " t.rowid,"; + + $sql.= " t.name,"; + $sql.= " t.entity,"; + $sql.= " t.fk_mailing,"; + $sql.= " t.filtervalue,"; + $sql.= " t.fk_user_author,"; + $sql.= " t.datec,"; + $sql.= " t.fk_user_mod,"; + $sql.= " t.tms"; + + $sql.= " FROM ".MAIN_DB_PREFIX."advtargetemailing as t"; + if (!empty($id)) { + $sql.= " WHERE t.fk_mailing = ".$id; + }else { + $sql.= " WHERE t.fk_mailing = ".$this->fk_mailing; + } + + dol_syslog(get_class($this)."::fetch sql=".$sql, LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + if ($this->db->num_rows($resql)) + { + $obj = $this->db->fetch_object($resql); + + $this->id = $obj->rowid; + + $this->name = $obj->name; + $this->entity = $obj->entity; + $this->fk_mailing = $obj->fk_mailing; + $this->filtervalue = $obj->filtervalue; + $this->fk_user_author = $obj->fk_user_author; + $this->datec = $this->db->jdate($obj->datec); + $this->fk_user_mod = $obj->fk_user_mod; + $this->tms = $this->db->jdate($obj->tms); + + } + $this->db->free($resql); + + return 1; + } + else + { + $this->error="Error ".$this->db->lasterror(); + dol_syslog(get_class($this)."::fetch ".$this->error, LOG_ERR); + return -1; + } + } + + /** + * Update object into database + * + * @param User $user User that modifies + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK + */ + function update($user, $notrigger=0) + { + global $conf, $langs; + $error=0; + + // Clean parameters + if (isset($this->fk_mailing)) $this->fk_mailing=trim($this->fk_mailing); + if (isset($this->name)) $this->name=trim($this->name); + if (isset($this->filtervalue)) $this->filtervalue=trim($this->filtervalue); + if (isset($this->fk_user_author)) $this->fk_user_author=trim($this->fk_user_author); + if (isset($this->fk_user_mod)) $this->fk_user_mod=trim($this->fk_user_mod); + + + + // Check parameters + // Put here code to add a control on parameters values + + // Update request + $sql = "UPDATE ".MAIN_DB_PREFIX."advtargetemailing SET"; + + $sql.= " name=".(isset($this->name)?"'".$this->db->escape($this->name)."'":"''").","; + $sql.= " entity=".$conf->entity.","; + $sql.= " fk_mailing=".(isset($this->fk_mailing)?$this->fk_mailing:"null").","; + $sql.= " filtervalue=".(isset($this->filtervalue)?"'".$this->db->escape($this->filtervalue)."'":"null").","; + $sql.= " fk_user_mod=".$user->id; + + $sql.= " WHERE rowid=".$this->id; + + $this->db->begin(); + + dol_syslog(get_class($this)."::update sql=".$sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + + if (! $error) + { + if (! $notrigger) + { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action calls a trigger. + + //// Call triggers + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::update ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } + } + + /** + * Delete object in database + * + * @param User $user User that deletes + * @param int $notrigger 0=launch triggers after, 1=disable triggers + * @return int <0 if KO, >0 if OK + */ + function delete($user, $notrigger=0) + { + global $conf, $langs; + $error=0; + + $this->db->begin(); + + if (! $error) + { + if (! $notrigger) + { + // Uncomment this and change MYOBJECT to your own tag if you + // want this action calls a trigger. + + //// Call triggers + //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + //$interface=new Interfaces($this->db); + //$result=$interface->run_triggers('MYOBJECT_DELETE',$this,$user,$langs,$conf); + //if ($result < 0) { $error++; $this->errors=$interface->errors; } + //// End call triggers + } + } + + if (! $error) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."advtargetemailing"; + $sql.= " WHERE rowid=".$this->id; + + dol_syslog(get_class($this)."::delete sql=".$sql); + $resql = $this->db->query($sql); + if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + } + + // Commit or rollback + if ($error) + { + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); + $this->error.=($this->error?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->db->commit(); + return 1; + } + } + + + /** + * Save query in database to retreive it + * + * @param User $user User that deletes + * @param array $arrayquery All element to Query + * @return int <0 if KO, >0 if OK + */ + function savequery($user,$arrayquery) + { + global $langs,$conf; + + if (!empty($arrayquery)) { + $result=$this->fetch_by_mailing($this->fk_mailing); + $this->filtervalue=json_encode($arrayquery); + if ($result<0) { + return -1; + } + if (!empty($this->id)) { + $this->update($user); + }else { + $this->create($user); + } + } + } + + + + /** + * Load object in memory from database + * + * @param array $arrayquery All element to Query + * @return int <0 if KO, >0 if OK + */ + function query_thirdparty($arrayquery) + { + global $langs,$conf; + + $sql = "SELECT"; + $sql.= " t.rowid"; + $sql.= " FROM " . MAIN_DB_PREFIX . "societe as t"; + $sql.= " LEFT OUTER JOIN " . MAIN_DB_PREFIX . "societe_extrafields as te ON te.fk_object=t.rowid "; + + $sqlwhere=array(); + + $sqlwhere[]= 't.entity IN ('.getEntity('societe',1).')'; + + if (count($arrayquery)>0) { + + if (array_key_exists('cust_saleman', $arrayquery)) { + $sql.= " LEFT OUTER JOIN " . MAIN_DB_PREFIX . "societe_commerciaux as saleman ON saleman.fk_soc=t.rowid "; + } + if (array_key_exists('cust_categ', $arrayquery)) { + $sql.= " LEFT OUTER JOIN " . MAIN_DB_PREFIX . "categorie_societe as custcateg ON custcateg.fk_societe=t.rowid "; + } + + if (!empty($arrayquery['cust_name'])) { + + $sqlwhere[]= $this->transformToSQL('t.nom',$arrayquery['cust_name']); + } + if (!empty($arrayquery['cust_code'])) { + $sqlwhere[]= $this->transformToSQL('t.code_client',$arrayquery['cust_code']); + } + if (!empty($arrayquery['cust_adress'])) { + $sqlwhere[]= $this->transformToSQL('t.address',$arrayquery['cust_adress']); + } + if (!empty($arrayquery['cust_zip'])) { + $sqlwhere[]= $this->transformToSQL('t.zip',$arrayquery['cust_zip']); + } + if (!empty($arrayquery['cust_city'])) { + $sqlwhere[]= $this->transformToSQL('t.town',$arrayquery['cust_city']); + } + if (!empty($arrayquery['cust_mothercompany'])) { + $str=$this->transformToSQL('nom',$arrayquery['cust_mothercompany']); + $sqlwhere[]= " (t.parent IN (SELECT rowid FROM " . MAIN_DB_PREFIX . "societe WHERE ('.$str.')))"; + } + if (!empty($arrayquery['cust_status']) && count($arrayquery['cust_status'])>0) { + $sqlwhere[]= " (t.status IN (".implode(',',$arrayquery['cust_status'])."))"; + } + if (!empty($arrayquery['cust_typecust']) && count($arrayquery['cust_typecust'])>0) { + $sqlwhere[]= " (t.client IN (".implode(',',$arrayquery['cust_typecust'])."))"; + } + if (!empty($arrayquery['cust_comm_status']) && count($arrayquery['cust_comm_status']>0)) { + $sqlwhere[]= " (t.fk_stcomm IN (".implode(',',$arrayquery['cust_comm_status'])."))"; + } + if (!empty($arrayquery['cust_prospect_status']) && count($arrayquery['cust_prospect_status'])>0) { + $sqlwhere[]= " (t.fk_prospectlevel IN ('".implode("','",$arrayquery['cust_prospect_status'])."'))"; + } + if (!empty($arrayquery['cust_typeent']) && count($arrayquery['cust_typeent'])>0) { + $sqlwhere[]= " (t.fk_typent IN (".implode(',',$arrayquery['cust_typeent'])."))"; + } + if (!empty($arrayquery['cust_saleman']) && count($arrayquery['cust_saleman'])>0) { + $sqlwhere[]= " (saleman.fk_user IN (".implode(',',$arrayquery['cust_saleman'])."))"; + } + if (!empty($arrayquery['cust_country']) && count($arrayquery['cust_country'])>0) { + $sqlwhere[]= " (t.fk_pays IN (".implode(',',$arrayquery['cust_country'])."))"; + } + if (!empty($arrayquery['cust_effectif_id']) && count($arrayquery['cust_effectif_id'])>0) { + $sqlwhere[]= " (t.fk_effectif IN (".implode(',',$arrayquery['cust_effectif_id'])."))"; + } + if (!empty($arrayquery['cust_categ']) && count($arrayquery['cust_categ'])>0) { + $sqlwhere[]= " (custcateg.fk_categorie IN (".implode(',',$arrayquery['cust_categ'])."))"; + } + if (!empty($arrayquery['cust_language']) && count($arrayquery['cust_language'])>0) { + $sqlwhere[]= " (t.default_lang IN ('".implode("','",$arrayquery['cust_language'])."'))"; + } + + //Standard Extrafield feature + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { + // fetch optionals attributes and labels + dol_include_once('/core/class/extrafields.class.php'); + $extrafields = new ExtraFields($this->db); + $extralabels=$extrafields->fetch_name_optionals_label('societe'); + + foreach($extralabels as $key=>$val) { + + if (($extrafields->attribute_type[$key] == 'varchar') || + ($extrafields->attribute_type[$key] == 'text')) { + if (!empty($arrayquery['options_'.$key])) { + $sqlwhere[]= " (te.".$key." LIKE '".$arrayquery['options_'.$key]."')"; + } + } elseif (($extrafields->attribute_type[$key] == 'int') || + ($extrafields->attribute_type[$key] == 'double')) { + if (!empty($arrayquery['options_'.$key.'_max'])) { + $sqlwhere[]= " (te.".$key." >= ".$arrayquery['options_'.$key.'_max']." AND te.".$key." <= ".$arrayquery['options_'.$key.'_min'].")"; + } + } else if (($extrafields->attribute_type[$key] == 'date') || + ($extrafields->attribute_type[$key] == 'datetime')) { + if (!empty($arrayquery['options_'.$key.'_end_dt'])){ + $sqlwhere[]= " (te.".$key." >= '".$this->db->idate($arrayquery['options_'.$key.'_st_dt'])."' AND te.".$key." <= '".$this->db->idate($arrayquery['options_'.$key.'_end_dt'])."')"; + } + }else if ($extrafields->attribute_type[$key] == 'boolean') { + if ($arrayquery['options_'.$key]!=''){ + $sqlwhere[]= " (te.".$key." = ".$arrayquery['options_'.$key].")"; + } + }else{ + if (is_array($arrayquery['options_'.$key])) { + $sqlwhere[]= " (te.".$key." IN ('".implode("','",$arrayquery['options_'.$key])."'))"; + } elseif (!empty($arrayquery['options_'.$key])) { + $sqlwhere[]= " (te.".$key." LIKE '".$arrayquery['options_'.$key]."')"; + } + } + + } + + + } + + if (count($sqlwhere)>0) $sql.= " WHERE ".implode(" AND ",$sqlwhere); + + } + + + dol_syslog(get_class($this) . "::query_thirdparty sql=" . $sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { + $this->thirdparty_lines = array(); + $num = $this->db->num_rows($resql); + $i = 0; + + if ($num) + { + while( $i < $num) + { + $obj = $this->db->fetch_object($resql); + + $this->thirdparty_lines[$i] = $obj->rowid; + + $i++; + } + } + $this->db->free($resql); + + return $num; + } else { + $this->error = "Error " . $this->db->lasterror(); + dol_syslog(get_class($this) . "::query_thirdparty " . $this->error, LOG_ERR); + return -1; + } + } + + /** + * Load object in memory from database + * + * @param array $arrayquery All element to Query + * @return int <0 if KO, >0 if OK + */ + function query_contact($arrayquery) + { + global $langs,$conf; + + $sql = "SELECT"; + $sql.= " t.rowid"; + $sql.= " FROM " . MAIN_DB_PREFIX . "socpeople as t"; + $sql.= " LEFT OUTER JOIN " . MAIN_DB_PREFIX . "socpeople_extrafields as te ON te.fk_object=t.rowid "; + + $sqlwhere=array(); + + $sqlwhere[]= 't.entity IN ('.getEntity('socpeople',1).')'; + + if (count($arrayquery)>0) { + + if (array_key_exists('contact_categ', $arrayquery)) { + $sql.= " LEFT OUTER JOIN " . MAIN_DB_PREFIX . "categorie_contact as contactcateg ON contactcateg.fk_socpeople=t.rowid "; + } + + if (!empty($arrayquery['contact_lastname'])) { + $sqlwhere[]=$this->transformToSQL('t.lastname',$arrayquery['contact_lastname']); + } + if (!empty($arrayquery['contact_firstname'])) { + $sqlwhere[]=$this->transformToSQL('t.firstname',$arrayquery['contact_firstname']); + } + if (!empty($arrayquery['contact_country']) && count($arrayquery['contact_country'])) { + $sqlwhere[]= " (t.fk_pays IN (".implode(',',$arrayquery['contact_country'])."))"; + } + if (!empty($arrayquery['contact_status']) && count($arrayquery['contact_status'])>0) { + $sqlwhere[]= " (t.statut IN (".implode(',',$arrayquery['contact_status'])."))"; + } + if (!empty($arrayquery['contact_civility']) && count($arrayquery['contact_civility'])>0) { + $sqlwhere[]= " (t.civility IN ('".implode("','",$arrayquery['contact_civility'])."'))"; + } + if ($arrayquery['contact_no_email']!='') { + $sqlwhere[]= " (t.no_email='".$arrayquery['contact_no_email']."')"; + } + if ($arrayquery['contact_update_st_dt']!='') { + $sqlwhere[]= " (t.tms >= '".$this->db->idate($arrayquery['contact_update_st_dt'])."' AND t.tms <= '".$this->db->idate($arrayquery['contact_update_end_dt'])."')"; + } + if ($arrayquery['contact_create_st_dt']!='') { + $sqlwhere[]= " (t.datec >= '".$this->db->idate($arrayquery['contact_create_st_dt'])."' AND t.datec <= '".$this->db->idate($arrayquery['contact_create_end_dt'])."')"; + } + if (!empty($arrayquery['contact_categ']) && count($arrayquery['contact_categ'])>0) { + $sqlwhere[]= " (contactcateg.fk_categorie IN (".implode(",",$arrayquery['contact_categ'])."))"; + } + + //Standard Extrafield feature + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) { + // fetch optionals attributes and labels + dol_include_once('/core/class/extrafields.class.php'); + $extrafields = new ExtraFields($this->db); + $extralabels=$extrafields->fetch_name_optionals_label('socpeople'); + + foreach($extralabels as $key=>$val) { + + if (($extrafields->attribute_type[$key] == 'varchar') || + ($extrafields->attribute_type[$key] == 'text')) { + if (!empty($arrayquery['options_'.$key.'_cnct'])) { + $sqlwhere[]= " (te.".$key." LIKE '".$arrayquery['options_'.$key.'_cnct']."')"; + } + } elseif (($extrafields->attribute_type[$key] == 'int') || + ($extrafields->attribute_type[$key] == 'double')) { + if (!empty($arrayquery['options_'.$key.'_max'.'_cnct'])) { + $sqlwhere[]= " (te.".$key." >= ".$arrayquery['options_'.$key.'_max'.'_cnct']." AND te.".$key." <= ".$arrayquery['options_'.$key.'_min'.'_cnct'].")"; + } + } else if (($extrafields->attribute_type[$key] == 'date') || + ($extrafields->attribute_type[$key] == 'datetime')) { + if (!empty($arrayquery['options_'.$key.'_end_dt'.'_cnct'])){ + $sqlwhere[]= " (te.".$key." >= '".$this->db->idate($arrayquery['options_'.$key.'_st_dt'.'_cnct'])."' AND te.".$key." <= '".$this->db->idate($arrayquery['options_'.$key.'_end_dt'.'_cnct'])."')"; + } + }else if ($extrafields->attribute_type[$key] == 'boolean') { + if ($arrayquery['options_'.$key.'_cnct']!=''){ + if ($arrayquery['options_'.$key.'_cnct']==0) { + $sqlwhere[]= " (te.".$key." = ".$arrayquery['options_'.$key.'_cnct']." OR ((te.".$key." IS NULL) AND (te.fk_object IS NOT NULL)))"; + }else { + $sqlwhere[]= " (te.".$key." = ".$arrayquery['options_'.$key.'_cnct'].")"; + } + } + }else{ + if (is_array($arrayquery['options_'.$key.'_cnct'])) { + $sqlwhere[]= " (te.".$key." IN ('".implode("','",$arrayquery['options_'.$key.'_cnct'])."'))"; + } elseif (!empty($arrayquery['options_'.$key.'_cnct'])) { + $sqlwhere[]= " (te.".$key." LIKE '".$arrayquery['options_'.$key.'_cnct']."')"; + } + } + + } + + + } + + if (count($sqlwhere)>0) $sql.= " WHERE ".implode(" AND ",$sqlwhere); + + } + + + dol_syslog(get_class($this) . "::query_contact sql=" . $sql, LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { + $this->contact_lines = array(); + $num = $this->db->num_rows($resql); + $i = 0; + + if ($num) + { + while( $i < $num) + { + $obj = $this->db->fetch_object($resql); + + $this->contact_lines[$i] = $obj->rowid; + + $i++; + } + } + $this->db->free($resql); + + return $num; + } else { + $this->error = "Error " . $this->db->lasterror(); + dol_syslog(get_class($this) . "::query_contact " . $this->error, LOG_ERR); + return -1; + } + } + + + /** + * Parse criteria to return a SQL qury formated + * + * @param string $column_to_test column to test + * @param string $criteria Use %% as magic caracters. For exemple to find all item like jean, joe, jim, you can input j%%, you can also use ; as separator for value, + * and use ! for except this value. + * For exemple jean;joe;jim%%;!jimo;!jima%> will target all jean, joe, start with jim but not jimo and not everythnig taht start by jima + * @return string Sql to use for the where condition + */ + public function transformToSQL($column_to_test,$criteria) { + $return_sql_criteria = '('; + + //This is a multiple value test + if (preg_match('/;/',$criteria)) { + $return_sql_not_like=array(); + $return_sql_like=array(); + + $criteria_array=explode(';',$criteria); + foreach($criteria_array as $inter_criteria) { + if (preg_match('/!/',$inter_criteria)) { + $return_sql_not_like[]= '('.$column_to_test.' NOT LIKE \''.str_replace('!', '', $inter_criteria).'\')'; + } else { + $return_sql_like[]= '('.$column_to_test.' LIKE \''.$inter_criteria.'\')'; + } + } + + if (count($return_sql_like)>0) { + $return_sql_criteria .= '(' . implode (' OR ', $return_sql_like) .')'; + } + if (count($return_sql_not_like)>0) { + $return_sql_criteria .= ' AND (' . implode (' AND ', $return_sql_not_like).')'; + } + + }else { + $return_sql_criteria .= $column_to_test . ' LIKE \''.$this->db->escape($criteria).'\''; + } + + $return_sql_criteria .= ')'; + + return $return_sql_criteria; + } + + +} \ No newline at end of file diff --git a/htdocs/comm/mailing/class/html.formadvtargetemailing.class.php b/htdocs/comm/mailing/class/html.formadvtargetemailing.class.php new file mode 100644 index 00000000000..69fb747f364 --- /dev/null +++ b/htdocs/comm/mailing/class/html.formadvtargetemailing.class.php @@ -0,0 +1,505 @@ + +* +* +* 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 +* the Free Software Foundation; either version 3 of the License, or +* (at your option) any later version. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see . +*/ + +/** + * \file comm/mailing/class/html.formadvtragetemaling.class.php + * \ingroup mailing + * \brief Fichier de la classe des fonctions predefinie de composants html advtargetemaling + */ + +/** + * Class to manage building of HTML components + */ +class FormAdvTargetEmailing extends Form +{ + var $db; + var $error; + + /** + * Constructor + * + * @param DoliDB $db handler + */ + function __construct($db) { + global $langs; + + $this->db = $db; + } + + /** + * Affiche un champs select contenant une liste + * + * @param array $selected_array à preselectionner + * @param string $htmlname select field + * @return string select field + */ + function multiselectProspectionStatus($selected_array = array(), $htmlname = 'cust_prospect_status') { + global $conf, $langs; + $options_array = array (); + + $sql = "SELECT code, label"; + $sql .= " FROM " . MAIN_DB_PREFIX . "c_prospectlevel"; + $sql .= " WHERE active > 0"; + $sql .= " ORDER BY sortorder"; + dol_syslog ( get_class ( $this ) . '::multiselectProspectionStatus sql=' . $sql, LOG_DEBUG ); + $resql = $this->db->query ( $sql ); + if ($resql) { + $num = $this->db->num_rows ( $resql ); + $i = 0; + while ( $i < $num ) { + $obj = $this->db->fetch_object ( $resql ); + + $level = $langs->trans ( $obj->code ); + if ($level == $obj->code) + $level = $langs->trans ( $obj->label ); + $options_array [$obj->code] = $level; + + $i ++; + } + } else { + dol_print_error ( $this->db ); + } + return $this->advMultiselectarray ( $htmlname, $options_array, $selected_array ); + } + + /** + * Return combo list of activated countries, into language of user + * + * @param string $htmlname of html select object + * @param array $selected_array or Code or Label of preselected country + * @return string HTML string with select + */ + function multiselectCountry($htmlname = 'country_id', $selected_array=array()) { + global $conf, $langs; + + $langs->load("dict"); + $maxlength = 0; + + $out = ''; + $countryArray = array(); + $label = array (); + + $options_array = array(); + + $sql = "SELECT rowid, code as code_iso, label"; + $sql .= " FROM " . MAIN_DB_PREFIX . "c_country"; + $sql .= " WHERE active = 1 AND code<>''"; + $sql .= " ORDER BY code ASC"; + + dol_syslog(get_class($this) . "::select_country sql=" . $sql); + $resql = $this->db->query($sql); + if ($resql) { + + $num = $this->db->num_rows($resql); + $i = 0; + if ($num) { + $foundselected = false; + + while ($i < $num) { + $obj = $this->db->fetch_object ( $resql ); + $countryArray [$i] ['rowid'] = $obj->rowid; + $countryArray [$i] ['code_iso'] = $obj->code_iso; + $countryArray [$i] ['label'] = ($obj->code_iso && $langs->transnoentitiesnoconv("Country" . $obj->code_iso ) != "Country" . $obj->code_iso ? $langs->transnoentitiesnoconv ( "Country" . $obj->code_iso ) : ($obj->label != '-' ? $obj->label : '')); + $label[$i] = $countryArray[$i]['label']; + $i ++; + } + + array_multisort($label, SORT_ASC, $countryArray); + + foreach ($countryArray as $row) { + $label = dol_trunc($row['label'], $maxlength, 'middle'); + if ($row['code_iso']) + $label .= ' (' . $row['code_iso'] . ')'; + + $options_array[$row['rowid']] = $label; + } + } + } else { + dol_print_error($this->db); + } + + return $this->advMultiselectarray($htmlname, $options_array, $selected_array); + } + + /** + * Return select list for categories (to use in form search selectors) + * + * @param string $htmlname control name + * @param array $selected_array array of data + * @param User $user User action + * @return string combo list code + */ + function multiselectselectSalesRepresentatives($htmlname, $selected_array, $user) { + + global $conf; + + $options_array = array (); + + $sql_usr = ''; + $sql_usr .= "SELECT DISTINCT u2.rowid, u2.lastname as name, u2.firstname, u2.login"; + $sql_usr .= " FROM " . MAIN_DB_PREFIX . "user as u2, " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; + $sql_usr .= " WHERE u2.entity IN (0," . $conf->entity . ")"; + $sql_usr .= " AND u2.rowid = sc.fk_user "; + + if (! empty ( $conf->global->USER_HIDE_INACTIVE_IN_COMBOBOX )) + $sql_usr .= " AND u2.statut<>0 "; + $sql_usr .= " ORDER BY name ASC"; + // print $sql_usr;exit; + + $resql_usr = $this->db->query ( $sql_usr ); + if ($resql_usr) { + while ( $obj_usr = $this->db->fetch_object ( $resql_usr ) ) { + + $label = $obj_usr->firstname . " " . $obj_usr->name . " (" . $obj_usr->login . ')'; + + $options_array [$obj_usr->rowid] = $label; + + } + $this->db->free ( $resql_usr ); + } else { + dol_print_error ( $this->db ); + } + + return $this->advMultiselectarray ( $htmlname, $options_array, $selected_array ); + } + + /** + * Return select list for categories (to use in form search selectors) + * + * @param string $htmlname of combo list (example: 'search_sale') + * @param array $selected_array selected array + * @return string combo list code + */ + function multiselectselectLanguage($htmlname='', $selected_array=array()) { + + global $conf,$langs; + + $options_array = array (); + + $langs_available=$langs->get_available_languages(DOL_DOCUMENT_ROOT,12); + + foreach ($langs_available as $key => $value) + { + $label = $value; + $options_array[$key] = $label; + } + asort($options_array); + return $this->advMultiselectarray($htmlname, $options_array, $selected_array); + } + + /** + * Return multiselect list of entities for extrafeild type sellist + * + * @param string $htmlname control name + * @param array $sqlqueryparam array + * @param array $selected_array array + * + * @return string HTML combo + */ + function advMultiselectarraySelllist($htmlname, $sqlqueryparam = array(), $selected_array = array()) { + + if (is_array ( $sqlqueryparam )) { + $options_array=array(); + + $param_list = array_keys ( $sqlqueryparam ); + $InfoFieldList = explode ( ":", $param_list [0] ); + + // 0 1 : tableName + // 1 2 : label field name Nom du champ contenant le libelle + // 2 3 : key fields name (if differ of rowid) + // 3 4 : where clause filter on column or table extrafield, syntax field='value' or extra.field=value + + $keyList = 'rowid'; + + if (count ( $InfoFieldList ) >= 3) { + if (strpos ( $InfoFieldList [3], 'extra.' ) !== false) { + $keyList = 'main.' . $InfoFieldList [2] . ' as rowid'; + } else { + $keyList = $InfoFieldList [2] . ' as rowid'; + } + } + + $sql = 'SELECT ' . $keyList . ', ' . $InfoFieldList [1]; + $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList [0]; + if (! empty ( $InfoFieldList [3] )) { + + // We have to join on extrafield table + if (strpos ( $InfoFieldList [3], 'extra' ) !== false) { + $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList [0] . '_extrafields as extra'; + $sql .= ' WHERE extra.fk_object=main.' . $InfoFieldList [2] . ' AND ' . $InfoFieldList [3]; + } else { + $sql .= ' WHERE ' . $InfoFieldList [3]; + } + } + if (! empty($InfoFieldList[1])) { + $sql .= " ORDER BY nom"; + } + // $sql.= ' WHERE entity = '.$conf->entity; + + $options_array = array(); + + dol_syslog(get_class($this) . "::".__METHOD__,LOG_DEBUG); + $resql = $this->db->query($sql); + if ($resql) { + + $num = $this->db->num_rows($resql); + $i = 0; + if ($num) { + while ( $i < $num ) { + $obj = $this->db->fetch_object ( $resql ); + $labeltoshow = dol_trunc ( $obj->$InfoFieldList [1], 90 ); + $options_array[$obj->rowid]=$labeltoshow; + $i ++; + } + } + $this->db->free ( $resql ); + } + } + + return $this->advMultiselectarray($htmlname, $options_array, $selected_array); + } + + /** + * Return combo list with people title + * + * @param string $htmlname Name of HTML select combo field + * @param array $selected_array Array + * @return string HTML combo + */ + function multiselectCivility($htmlname='civilite_id',$selected_array = array()) + { + global $conf,$langs,$user; + $langs->load("dict"); + + $options_array=array(); + + + $sql = "SELECT rowid, code, label as civilite, active FROM ".MAIN_DB_PREFIX."c_civility"; + $sql.= " WHERE active = 1"; + + dol_syslog(get_class($this)."::".__METHOD__,LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + + $num = $this->db->num_rows($resql); + $i = 0; + if ($num) + { + while ($i < $num) + { + $obj = $this->db->fetch_object($resql); + // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut + $label= ($langs->trans("Civility".$obj->code)!="Civility".$obj->code ? $langs->trans("Civility".$obj->code) : ($obj->civilite!='-'?$obj->civilite:'')); + + + $options_array[$obj->code]=$label; + + $i++; + } + } + + } + else + { + dol_print_error($this->db); + } + + return $this->advMultiselectarray ( $htmlname, $options_array, $selected_array ); + } + + /** + * Return multiselect list of entities. + * + * @param string $htmlname select + * @param array $options_array to manage + * @param array $selected_array to manage + * @param int $showempty show empty + * @return string HTML combo + */ + function advMultiselectarray($htmlname, $options_array = array(), $selected_array = array(), $showempty = 0) { + global $conf, $langs; + + $return = ''; + $return .= ''; + $return .= ''; + + if ($showempty) + $return .= ''; + + // Find if keys is in selected array value + if (is_array($selected_array) && count($selected_array)>0) { + $intersect_array = array_intersect_key($options_array, array_flip($selected_array)); + } else { + $intersect_array=array(); + } + + if (count($options_array) > 0) { + foreach ($options_array as $keyoption => $valoption) { + // If key is in intersect table then it have to e selected + $selected = ''; + if (count ( $intersect_array ) > 0) { + if (array_key_exists ( $keyoption, $intersect_array )) { + $selected = ' selected="selected"'; + } + } + $return .= '' . $valoption . ''; + } + } + + $return .= ''; + + return $return; + } + + /** + * Return combo list with customer categories + * + * @param string $htmlname Name of categorie + * @param array $selected_array value selected + * @return string HTML combo + */ + function multiselectCustomerCategories($htmlname='cust_cat',$selected_array = array()) + { + return $this->multiselectCategories($htmlname,$selected_array,2); + } + + /** + * Return combo list with customer contact + * + * @param string $htmlname Name of categorie + * @param array $selected_array value selected + * @return string HTML combo + */ + function multiselectContactCategories($htmlname='contact_cat',$selected_array = array()) + { + return $this->multiselectCategories($htmlname,$selected_array,4); + } + + /** + * Return combo list of categories + * + * @param string $htmlname Name of categorie + * @param array $selected_array value selected + * @param int $type type + * @return string HTML combo + */ + public function multiselectCategories($htmlname='',$selected_array = array(), $type=0) + { + global $conf,$langs,$user; + $langs->load("dict"); + + $options_array=array(); + + $sql = "SELECT rowid, label FROM ".MAIN_DB_PREFIX."categorie"; + $sql.= " WHERE type=".$type; + + dol_syslog(get_class($this)."::".__METHOD__,LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + + $num = $this->db->num_rows($resql); + $i = 0; + if ($num) + { + while ($i < $num) + { + $obj = $this->db->fetch_object($resql); + + $options_array[$obj->rowid]=$obj->label; + + $i++; + } + } + + } + else + { + dol_print_error($this->db); + } + + return $this->advMultiselectarray ( $htmlname, $options_array, $selected_array ); + } + + /** + * selectAdvtargetemailingTemplate + * + * @param string $htmlname control name + * @param integer $selected defaut selected + * @param integer $showempty empty lines + * + * @return string HTML combo + */ + public function selectAdvtargetemailingTemplate($htmlname='template_id',$selected=0,$showempty=0) { + global $conf, $user, $langs; + + $out = ''; + + $sql = "SELECT c.rowid, c.name, c.fk_mailing"; + $sql .= " FROM " . MAIN_DB_PREFIX . "advtargetemailing as c"; + $sql .= " ORDER BY c.name"; + + dol_syslog ( get_class ( $this ) . "::".__METHOD__, LOG_DEBUG ); + $resql = $this->db->query ( $sql ); + if ($resql) { + + + $out .= ''; + } else { + dol_print_error ( $this->db ); + } + $this->db->free ( $resql ); + return $out; + } +} \ No newline at end of file diff --git a/htdocs/comm/propal/class/propal.class.php b/htdocs/comm/propal/class/propal.class.php index 3d43d6b00f2..56c3839dcb6 100644 --- a/htdocs/comm/propal/class/propal.class.php +++ b/htdocs/comm/propal/class/propal.class.php @@ -780,7 +780,7 @@ class Propal extends CommonObject */ function create($user, $notrigger=0) { - global $langs,$conf,$mysoc,$hookmanager; + global $conf,$hookmanager; $error=0; $now=dol_now(); @@ -1080,7 +1080,7 @@ class Propal extends CommonObject */ function createFromClone($socid=0) { - global $db, $user,$langs,$conf,$hookmanager; + global $user,$conf,$hookmanager; dol_include_once('/projet/class/project.class.php'); @@ -1214,7 +1214,6 @@ class Propal extends CommonObject */ function fetch($rowid,$ref='') { - global $conf; $sql = "SELECT p.rowid, p.ref, p.remise, p.remise_percent, p.remise_absolue, p.fk_soc"; $sql.= ", p.total, p.tva, p.localtax1, p.localtax2, p.total_ht"; @@ -1508,7 +1507,7 @@ class Propal extends CommonObject { require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - global $conf,$langs; + global $conf; $error=0; $now=dol_now(); @@ -1868,7 +1867,6 @@ class Propal extends CommonObject */ function reopen($user, $statut, $note='', $notrigger=0) { - global $langs,$conf; $this->statut = $statut; $error=0; @@ -1979,7 +1977,7 @@ class Propal extends CommonObject $outputlangs->setDefaultLang($newlang); } //$ret=$object->fetch($id); // Reload to get new records - $this->generateDocument($modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref); + $this->generateDocument($modelpdf, $outputlangs); } // Call trigger @@ -2082,7 +2080,7 @@ class Propal extends CommonObject */ function liste_array($shortlist=0, $draft=0, $notcurrentuser=0, $socid=0, $limit=0, $offset=0, $sortfield='p.datep', $sortorder='DESC') { - global $conf,$user; + global $user; $ga = array(); @@ -2247,7 +2245,7 @@ class Propal extends CommonObject */ function delete($user, $notrigger=0) { - global $conf,$langs; + global $conf; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $error=0; @@ -2610,7 +2608,7 @@ class Propal extends CommonObject */ function initAsSpecimen() { - global $user,$langs,$conf; + global $langs; // Charge tableau des produits prodids $prodids = array(); @@ -2696,7 +2694,7 @@ class Propal extends CommonObject */ function load_state_board() { - global $conf, $user; + global $user; $this->nb=array(); $clause = "WHERE"; @@ -2741,7 +2739,7 @@ class Propal extends CommonObject */ function getNextNumRef($soc) { - global $conf, $db, $langs; + global $conf,$langs; $langs->load("propal"); if (! empty($conf->global->PROPALE_ADDON)) @@ -2942,7 +2940,7 @@ class Propal extends CommonObject */ public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0) { - global $conf,$user,$langs; + global $conf,$langs; $langs->load("propale"); @@ -3196,7 +3194,7 @@ class PropaleLigne extends CommonObjectLine */ function insert($notrigger=0) { - global $conf,$langs,$user; + global $conf,$user; $error=0; @@ -3332,7 +3330,7 @@ class PropaleLigne extends CommonObjectLine */ function delete() { - global $conf,$langs,$user; + global $conf,$user; $error=0; $this->db->begin(); @@ -3383,7 +3381,7 @@ class PropaleLigne extends CommonObjectLine */ function update($notrigger=0) { - global $conf,$langs,$user; + global $conf,$user; $error=0; diff --git a/htdocs/commande/class/api_commande.class.php b/htdocs/commande/class/api_commande.class.php index 04d78f30a1d..d6a2a3d0f82 100644 --- a/htdocs/commande/class/api_commande.class.php +++ b/htdocs/commande/class/api_commande.class.php @@ -207,9 +207,9 @@ class CommandeApi extends DolibarrApi */ function post($request_data = NULL) { - if(! DolibarrApiAccess::$user->rights->commande->creer) { - throw new RestException(401); - } + if(! DolibarrApiAccess::$user->rights->commande->creer) { + throw new RestException(401, "Insuffisant rights"); + } // Check mandatory fields $result = $this->_validate($request_data); @@ -224,7 +224,7 @@ class CommandeApi extends DolibarrApi $this->commande->lines = $lines; } if(! $this->commande->create(DolibarrApiAccess::$user) ) { - throw new RestException(401); + throw new RestException(500, "Error while creating order"); } return $this->commande->id; diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index c4569418968..a22e937da87 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -3,12 +3,13 @@ * Copyright (C) 2004-2012 Laurent Destailleur * Copyright (C) 2005-2014 Regis Houssin * Copyright (C) 2006 Andre Cianfarani - * Copyright (C) 2010-2015 Juanjo Menent + * Copyright (C) 2010-2016 Juanjo Menent * Copyright (C) 2011 Jean Heimburger * Copyright (C) 2012-2014 Christophe Battarel * Copyright (C) 2012 Cedric Salvador * Copyright (C) 2013 Florian Henry * Copyright (C) 2014-2015 Marcos García + * Copyright (C) 2016 Ferran Marcet * * 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 @@ -203,7 +204,7 @@ class Commande extends CommonOrder */ function getNextNumRef($soc) { - global $db, $langs, $conf; + global $langs, $conf; $langs->load("order"); if (! empty($conf->global->COMMANDE_ADDON)) @@ -238,7 +239,7 @@ class Commande extends CommonOrder } else { - dol_print_error($db,get_class($this)."::getNextNumRef ".$obj->error); + dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error); return ""; } } @@ -499,7 +500,6 @@ class Commande extends CommonOrder */ function set_reopen($user) { - global $conf,$langs; $error=0; if ($this->statut != self::STATUS_CANCELED && $this->statut != self::STATUS_CLOSED) @@ -559,7 +559,7 @@ class Commande extends CommonOrder */ function cloture($user) { - global $conf, $langs; + global $conf; $error=0; @@ -696,7 +696,7 @@ class Commande extends CommonOrder */ function create($user, $notrigger=0) { - global $conf,$langs,$mysoc,$hookmanager; + global $conf,$langs; $error=0; // Clean parameters @@ -970,7 +970,7 @@ class Commande extends CommonOrder */ function createFromClone($socid=0) { - global $conf,$user,$langs,$hookmanager; + global $user,$hookmanager; $error=0; @@ -1060,7 +1060,7 @@ class Commande extends CommonOrder */ function createFromProposal($object) { - global $db, $conf,$user,$langs,$hookmanager; + global $conf,$user,$hookmanager; dol_include_once('/core/class/extrafields.class.php'); @@ -1133,7 +1133,7 @@ class Commande extends CommonOrder // get extrafields from original line $object->fetch_optionals($object->id); - $e = new ExtraFields($db); + $e = new ExtraFields($this->db); $element_extrafields = $e->fetch_name_optionals_label($this->element); foreach($object->array_options as $options_key => $value) { @@ -1494,7 +1494,6 @@ class Commande extends CommonOrder */ function fetch($id, $ref='', $ref_ext='', $ref_int='') { - global $conf; // Check parameters if (empty($id) && empty($ref) && empty($ref_ext) && empty($ref_int)) return -1; @@ -1850,10 +1849,9 @@ class Commande extends CommonOrder * Note: For a dedicated shipment, the fetch_lines load the qty_asked and qty_shipped. This function return qty_shipped cuulated for order * * @param int $filtre_statut Filter on status - * @param int $fk_product Filter on a product * @return int <0 if KO, Nb of lines found if OK */ - function loadExpeditions($filtre_statut=-1, $fk_product=0) + function loadExpeditions($filtre_statut=-1) { $this->expeditions = array(); @@ -1982,7 +1980,6 @@ class Commande extends CommonOrder */ function deleteline($lineid) { - global $user; if ($this->statut == self::STATUS_DRAFT) { @@ -2261,7 +2258,7 @@ class Commande extends CommonOrder */ function liste_array($shortlist=0, $draft=0, $excluser='', $socid=0, $limit=0, $offset=0, $sortfield='c.date_commande', $sortorder='DESC') { - global $conf,$user; + global $user; $ga = array(); @@ -2429,7 +2426,7 @@ class Commande extends CommonOrder */ function classifyBilled(User $user) { - global $conf, $user, $langs; + global $user; $error = 0; $this->db->begin(); @@ -2516,7 +2513,7 @@ class Commande extends CommonOrder */ function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0.0,$txlocaltax2=0.0, $price_base_type='HT', $info_bits=0, $date_start='', $date_end='', $type=0, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=null, $pa_ht=0, $label='', $special_code=0, $array_options=0, $fk_unit=null) { - global $conf, $mysoc; + global $conf, $mysoc, $langs; dol_syslog(get_class($this)."::updateline id=$rowid, desc=$desc, pu=$pu, qty=$qty, remise_percent=$remise_percent, txtva=$txtva, txlocaltax1=$txlocaltax1, txlocaltax2=$txlocaltax2, price_base_type=$price_base_type, info_bits=$info_bits, date_start=$date_start, date_end=$date_end, type=$type, fk_parent_line=$fk_parent_line, pa_ht=$pa_ht, special_code=$special_code"); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; @@ -2585,6 +2582,26 @@ class Commande extends CommonOrder $line = new OrderLine($this->db); $line->fetch($rowid); + if (!empty($line->fk_product)) + { + $product=new Product($this->db); + $result=$product->fetch($line->fk_product); + $product_type=$product->type; + + if (! empty($conf->global->STOCK_MUST_BE_ENOUGH_FOR_ORDER) && $product_type == 0 && $product->stock_reel < $qty) + { + $this->error=$langs->trans('ErrorStockIsNotEnough'); + dol_syslog(get_class($this)."::addline error=Product ".$product->ref.": ".$this->error, LOG_ERR); + $this->db->rollback(); + unset($_POST['productid']); + unset($_POST['tva_tx']); + unset($_POST['price_ht']); + unset($_POST['qty']); + unset($_POST['buying_price']); + return self::STOCK_NOT_ENOUGH_FOR_ORDER; + } + } + $staticline = clone $line; $line->oldline = $staticline; @@ -2677,7 +2694,6 @@ class Commande extends CommonOrder */ function update($user=null, $notrigger=0) { - global $conf, $langs; $error=0; // Clean parameters @@ -3184,7 +3200,7 @@ class Commande extends CommonOrder */ function initAsSpecimen() { - global $user,$langs,$conf; + global $langs; dol_syslog(get_class($this)."::initAsSpecimen"); @@ -3266,7 +3282,7 @@ class Commande extends CommonOrder */ function load_state_board() { - global $conf, $user; + global $user; $this->nb=array(); $clause = "WHERE"; diff --git a/htdocs/commande/index.php b/htdocs/commande/index.php index 0aa828dc77a..fa1b2064ed2 100644 --- a/htdocs/commande/index.php +++ b/htdocs/commande/index.php @@ -216,6 +216,11 @@ if (! empty($conf->commande->enabled)) $i++; } } + else + { + $var=!$var; + print '
'.$langs->trans("NoOrder").'

"; } } diff --git a/htdocs/commande/list.php b/htdocs/commande/list.php index 7aa1dc481e9..5878b640dc7 100644 --- a/htdocs/commande/list.php +++ b/htdocs/commande/list.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2012 Laurent Destailleur + * Copyright (C) 2004-2016 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2012 Juanjo Menent @@ -127,7 +127,7 @@ $arrayfields=array( 'c.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500), 'c.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500), 'c.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000), - 'e.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000, 'enabled'=>(empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) + 'c.facture'=>array('label'=>$langs->trans("Billed"), 'checked'=>1, 'position'=>1000, 'enabled'=>(empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT))) ); // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) @@ -673,6 +673,12 @@ if ($resql) $var=!$var; print '
'; @@ -694,17 +700,11 @@ if ($resql) print ''.yn($obj->billed).'
'.$langs->trans("Web").'
'.$langs->trans("Categories").''; + $cate_arbo = $form->select_all_categories(Categorie::TYPE_ACCOUNT, '', 'parent', 64, 0, 1); + $c = new Categorie($db); + $cats = $c->containing($account->id,Categorie::TYPE_ACCOUNT); + foreach($cats as $cat) { + $arrayselected[] = $cat->id; + } + print $form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, '100%'); + print "
'.$langs->trans("Comment").''; @@ -591,6 +614,13 @@ else if ($account->url) print ''; print "
'.$langs->trans("Categories").''; + print $form->showCategories($account->id,'account',1); + print "
'.$langs->trans("Comment").''.dol_htmlentitiesbr($account->comment).'
'; // Accountancy code print ''; - print ''; + print ''; + } else { + print $account->account_number; + } + print ''; // Accountancy journal if (! empty($conf->accounting->enabled)) @@ -828,6 +864,20 @@ else print ''; + // Tags-Categories + if ($conf->categorie->enabled) + { + print '"; + } + // Comment print ''; print ''; $var=!$var; - print ''; + print ''; print ''; print ''; print ''; diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index a27f13cbb77..27ba03499c8 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -1,7 +1,7 @@ * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2004-2014 Laurent Destailleur + * Copyright (C) 2004-2016 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo * Copyright (C) 2005-2015 Regis Houssin * Copyright (C) 2006 Andre Cianfarani @@ -83,6 +83,7 @@ $search_montant_ht = GETPOST('search_montant_ht', 'alpha'); $search_montant_ttc = GETPOST('search_montant_ttc', 'alpha'); $origin = GETPOST('origin', 'alpha'); $originid = (GETPOST('originid', 'int') ? GETPOST('originid', 'int') : GETPOST('origin_id', 'int')); // For backward compatibility +$fac_rec=GETPOST('fac_rec','int'); // PDF $hidedetails = (GETPOST('hidedetails', 'int') ? GETPOST('hidedetails', 'int') : (! empty($conf->global->MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS) ? 1 : 0)); @@ -126,8 +127,8 @@ if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'e if (empty($reshook)) { if ($cancel) $action=''; - - include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once + + include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once include DOL_DOCUMENT_ROOT.'/core/actions_dellink.inc.php'; // Must be include, not include_once @@ -672,7 +673,7 @@ if (empty($reshook)) /* * Insert new invoice in database - */ + */ else if ($action == 'add' && $user->rights->facture->creer) { if ($socid > 0) $object->socid = GETPOST('socid', 'int'); @@ -722,7 +723,7 @@ if (empty($reshook)) $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha'); $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int'); - + // Proprietes particulieres a facture de remplacement $object->fk_facture_source = $_POST['fac_replacement']; $object->type = Facture::TYPE_REPLACEMENT; @@ -868,6 +869,15 @@ if (empty($reshook)) $object->ref_client = $_POST['ref_client']; $object->ref_int = $_POST['ref_int']; $object->modelpdf = $_POST['model']; + $object->fk_project = $_POST['projectid']; + $object->cond_reglement_id = ($_POST['type'] == 3?1:$_POST['cond_reglement_id']); + $object->mode_reglement_id = $_POST['mode_reglement_id']; + $object->fk_account = GETPOST('fk_account', 'int'); + $object->amount = $_POST['amount']; + $object->remise_absolue = $_POST['remise_absolue']; + $object->remise_percent = $_POST['remise_percent']; + $object->fk_incoterms = GETPOST('incoterm_id', 'int'); + $object->location_incoterms = GETPOST('location_incoterms', 'alpha'); $object->multicurrency_code = GETPOST('multicurrency_code', 'alpha'); $object->multicurrency_tx = GETPOST('originmulticurrency_tx', 'int'); @@ -2073,8 +2083,9 @@ if ($action == 'create') $(document).ready(function() { $("#socid").change(function() { var socid = $(this).val(); + var fac_rec = $(\'#fac_rec\').val(); // reload page - window.location.href = "'.$_SERVER["PHP_SELF"].'?action=create&socid="+socid; + window.location.href = "'.$_SERVER["PHP_SELF"].'?action=create&socid="+socid+"&fac_rec="+fac_rec; }); }); '; @@ -2089,6 +2100,8 @@ if ($action == 'create') $invoice_predefined = new FactureRec($db); $invoice_predefined->fetch(GETPOST('fac_rec','int')); + $dateinvoice = $invoice_predefined->date_when; // To use next gen date by default later + $sql = 'SELECT r.rowid, r.titre, r.total_ttc'; $sql .= ' FROM ' . MAIN_DB_PREFIX . 'facture_rec as r'; $sql .= ' WHERE r.fk_soc = ' . $invoice_predefined->socid; @@ -2102,7 +2115,7 @@ if ($action == 'create') if ($num > 0) { print ''; + print ''; + // Option to reload page to retrieve customer informations. Note, this clear other input + if (!empty($conf->global->RELOAD_PAGE_ON_TEMPLATE_CHANGE)) + { + print ''; + } + print ''; } $db->free($resql); } else { @@ -2329,6 +2357,15 @@ if ($action == 'create') } } + // Template invoice + print '
'; + $tmp=' '; + $text = $tmp.$langs->trans("RepeatableInvoice") . ' '; + //$text.= '('.$langs->trans("YouMustCreateStandardInvoiceFirst").') '; + $desc = $form->textwithpicto($text, $langs->transnoentities("YouMustCreateStandardInvoiceFirstDesc"), 1, 'help', '', 0, 3); + print $desc; + print '
'; + print ''; print ''; @@ -2384,7 +2421,7 @@ if ($action == 'create') $langs->load('projects'); print ''; } @@ -3530,7 +3567,7 @@ else if ($id > 0 || ! empty($ref)) print '
'.$langs->trans("AccountancyCode").''.length_accountg($account->account_number).'
'; + if (! empty($conf->accounting->enabled)) { + print length_accountg($account->account_number).'
url).'">'; print '
'.$langs->trans("Categories").''; + $cate_arbo = $form->select_all_categories(Categorie::TYPE_ACCOUNT, '', 'parent', 64, 0, 1); + $c = new Categorie($db); + $cats = $c->containing($object->id,Categorie::TYPE_ACCOUNT); + foreach($cats as $cat) { + $arrayselected[] = $cat->id; + } + print $form->multiselectarray('categories', $cate_arbo, $arrayselected, '', 0, '', 0, '100%'); + print "
'.$langs->trans("Comment").''; diff --git a/htdocs/compta/bank/class/account.class.php b/htdocs/compta/bank/class/account.class.php index 123f4537a58..92c21742baa 100644 --- a/htdocs/compta/bank/class/account.class.php +++ b/htdocs/compta/bank/class/account.class.php @@ -7,6 +7,7 @@ * Copyright (C) 2013 Florian Henry * Copyright (C) 2015-2016 Marcos García * Copyright (C) 2015 Alexandre Spangaro + * Copyright (C) 2016 Ferran Marcet * * 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 @@ -588,7 +589,7 @@ class Account extends CommonObject { $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."bank_account"); - $result=$this->update(); + $result=$this->update($user); if ($result > 0) { $accline = new AccountLine($this->db); @@ -892,6 +893,49 @@ class Account extends CommonObject } } + /** + * Sets object to supplied categories. + * + * Deletes object from existing categories not supplied. + * Adds it to non existing supplied categories. + * Existing categories are left untouch. + * + * @param int[]|int $categories Category or categories IDs + */ + public function setCategories($categories) { + // Handle single category + if (! is_array($categories)) { + $categories = array($categories); + } + + // Get current categories + require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; + $c = new Categorie($this->db); + $existing = $c->containing($this->id, Categorie::TYPE_ACCOUNT, 'id'); + + // Diff + if (is_array($existing)) { + $to_del = array_diff($existing, $categories); + $to_add = array_diff($categories, $existing); + } else { + $to_del = array(); // Nothing to delete + $to_add = $categories; + } + + // Process + foreach($to_del as $del) { + if ($c->fetch($del) > 0) { + $c->del_type($this, 'account'); + } + } + foreach ($to_add as $add) { + if ($c->fetch($add) > 0) { + $c->add_type($this, 'account'); + } + } + + return; + } /** * Delete bank account from database @@ -1100,15 +1144,19 @@ class Account extends CommonObject */ public static function countAccountToReconcile() { - global $db, $conf, $langs; - - if ($user->societe_id) return 0; // protection pour eviter appel par utilisateur externe + global $db, $conf, $user; + + //Protection against external users + if ($user->societe_id) { + return 0; + } $nb=0; $sql = "SELECT COUNT(ba.rowid) as nb"; $sql.= " FROM ".MAIN_DB_PREFIX."bank_account as ba"; $sql.= " WHERE ba.rappro > 0 and ba.clos = 0"; + $sql.= " AND ba.entity IN (".getEntity('bank_account', 1).")"; if (empty($conf->global->BANK_CAN_RECONCILIATE_CASHACCOUNT)) $sql.= " AND ba.courant != 2"; $resql=$db->query($sql); if ($resql) diff --git a/htdocs/compta/bank/treso.php b/htdocs/compta/bank/treso.php index db7f37cb3e5..0cee6211b49 100644 --- a/htdocs/compta/bank/treso.php +++ b/htdocs/compta/bank/treso.php @@ -136,7 +136,7 @@ if ($_REQUEST["account"] || $_REQUEST["ref"]) print '
'.$langs->trans("RemainderToPay").' 
' . $langs->trans('CreateFromRepeatableInvoice') . ''; - print ''; print ''; while ($i < $num) { @@ -2113,7 +2126,22 @@ if ($action == 'create') print '>' . $objp->titre . ' (' . price($objp->total_ttc) . ' ' . $langs->trans("TTC") . ')'; $i ++; } - print '
' . $langs->trans('Project') . ''; $numprojet = $formproject->select_projects($socid, $projectid, 'projectid', 0); - print '   id).'">' . $langs->trans("AddProject") . ''; + print '   id.($fac_rec?'&fac_rec='.$fac_rec:'')).'">' . $langs->trans("AddProject") . ''; print '
'; print '
'; print $langs->trans('BankAccount'); print ''; - if (($action != 'editbankaccount') && $user->rights->commande->creer && ! empty($object->brouillon)) + if (($action != 'editbankaccount') && $user->rights->facture->creer && ! empty($object->brouillon)) print 'id.'">'.img_edit($langs->trans('SetBankAccount'),1).'
'; print ''; diff --git a/htdocs/compta/facture/class/facture-rec.class.php b/htdocs/compta/facture/class/facture-rec.class.php index 8e4e05037a8..cddd511dbe4 100644 --- a/htdocs/compta/facture/class/facture-rec.class.php +++ b/htdocs/compta/facture/class/facture-rec.class.php @@ -53,7 +53,7 @@ class FactureRec extends CommonInvoice var $propalid; var $date_last_gen; - var $next_gen; + var $date_when; var $nb_gen_done; var $nb_gen_max; @@ -341,6 +341,17 @@ class FactureRec extends CommonInvoice } + /** + * Create an array of invoice lines + * + * @return int >0 if OK, <0 if KO + */ + function getLinesArray() + { + return $this->fetch_lines(); + } + + /** * Recupere les lignes de factures predefinies dans this->lines * @@ -348,17 +359,24 @@ class FactureRec extends CommonInvoice */ function fetch_lines() { - $sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.label as custom_label, l.description, l.price, l.qty, l.tva_tx, '; + $this->lines=array(); + + $sql = 'SELECT l.rowid, l.fk_product, l.product_type, l.label as custom_label, l.description, l.product_type, l.price, l.qty, l.tva_tx, '; $sql.= ' l.remise, l.remise_percent, l.subprice,'; - $sql.= ' l.total_ht, l.total_tva, l.total_ttc,'; + $sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_ttc,'; + //$sql.= ' l.situation_percent, l.fk_prev_id,'; + //$sql.= ' l.localtax1_tx, l.localtax2_tx, l.localtax1_type, l.localtax2_type, l.remise_percent, l.fk_remise_except, l.subprice,'; $sql.= ' l.rang, l.special_code,'; + //$sql.= ' l.info_bits, l.total_ht, l.total_tva, l.total_localtax1, l.total_localtax2, l.total_ttc, l.fk_code_ventilation, l.fk_product_fournisseur_price as fk_fournprice, l.buy_price_ht as pa_ht,'; $sql.= ' l.fk_unit, l.fk_contract_line,'; + //$sql.= ' l.fk_multicurrency, l.multicurrency_code, l.multicurrency_subprice, l.multicurrency_total_ht, l.multicurrency_total_tva, l.multicurrency_total_ttc,'; $sql.= ' p.ref as product_ref, p.fk_product_type as fk_product_type, p.label as product_label, p.description as product_desc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet_rec as l'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON l.fk_product = p.rowid'; $sql.= ' WHERE l.fk_facture = '.$this->id; - - dol_syslog('Facture::fetch_lines', LOG_DEBUG); + $sql.= ' ORDER BY l.rang'; + + dol_syslog('FactureRec::fetch_lines', LOG_DEBUG); $result = $this->db->query($sql); if ($result) { @@ -369,10 +387,13 @@ class FactureRec extends CommonInvoice $objp = $this->db->fetch_object($result); $line = new FactureLigne($this->db); + $line->id = $objp->rowid; $line->rowid = $objp->rowid; $line->label = $objp->custom_label; // Label line $line->desc = $objp->description; // Description line + $line->description = $objp->description; // Description line $line->product_type = $objp->product_type; // Type of line + $line->ref = $objp->product_ref; // Ref product $line->product_ref = $objp->product_ref; // Ref product $line->libelle = $objp->product_label; // deprecated $line->product_label = $objp->product_label; // Label product @@ -384,10 +405,6 @@ class FactureRec extends CommonInvoice $line->remise_percent = $objp->remise_percent; $line->fk_remise_except = $objp->fk_remise_except; $line->fk_product = $objp->fk_product; - $line->date_start = $objp->date_start; - $line->date_end = $objp->date_end; - $line->date_start = $objp->date_start; - $line->date_end = $objp->date_end; $line->info_bits = $objp->info_bits; $line->total_ht = $objp->total_ht; $line->total_tva = $objp->total_tva; @@ -412,7 +429,7 @@ class FactureRec extends CommonInvoice } else { - $this->error=$this->db->error(); + $this->error=$this->db-lasterror(); return -3; } } @@ -904,3 +921,52 @@ class FactureRec extends CommonInvoice } } } + + + +/** + * Class to manage invoice lines of templates. + * Saved into database table llx_facturedet_rec + */ +class FactureLigneRec extends CommonInvoiceLine +{ + + /** + * Delete line in database + * + * @return int <0 if KO, >0 if OK + */ + function delete() + { + global $conf,$langs,$user; + + $error=0; + + $this->db->begin(); + + // Call trigger + /*$result=$this->call_trigger('LINEBILLREC_DELETE',$user); + if ($result < 0) + { + $this->db->rollback(); + return -1; + }*/ + // End call triggers + + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."facturedet_rec WHERE rowid = ".($this->rowid > 0 ? $this->rowid : $this->id); + dol_syslog(get_class($this)."::delete", LOG_DEBUG); + if ($this->db->query($sql) ) + { + $this->db->commit(); + return 1; + } + else + { + $this->error=$this->db->error()." sql=".$sql; + $this->db->rollback(); + return -1; + } + } + +} \ No newline at end of file diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index b7531719646..bea200f2656 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -7,13 +7,14 @@ * Copyright (C) 2005-2014 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2007 Franky Van Liedekerke - * Copyright (C) 2010-2014 Juanjo Menent + * Copyright (C) 2010-2016 Juanjo Menent * Copyright (C) 2012-2014 Christophe Battarel * Copyright (C) 2012-2015 Marcos García * Copyright (C) 2012 Cédric Salvador * Copyright (C) 2012-2014 Raphaël Doursenaud * Copyright (C) 2013 Cedric Gross * Copyright (C) 2013 Florian Henry + * Copyright (C) 2016 Ferran Marcet * * 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 @@ -280,24 +281,27 @@ class Facture extends CommonInvoice $this->socid = $_facrec->socid; - $this->fk_project = $_facrec->fk_project; - $this->fk_account = $_facrec->fk_account; - $this->cond_reglement_id = $_facrec->cond_reglement_id; - $this->mode_reglement_id = $_facrec->mode_reglement_id; + // Fields coming from GUI (priority on template). TODO Value of template should be used as default value on GUI so we can use here always value from GUI + $this->fk_project = GETPOST('projectid','int') > 0 ? GETPOST('projectid','int') : $_facrec->fk_project; + $this->note_public = GETPOST('note_public') ? GETPOST('note_public') : $_facrec->note_public; + $this->note_private = GETPOST('note_private') ? GETPOST('note_private') : $_facrec->note_private; + $this->modelpdf = GETPOST('model') ? GETPOST('model') : $_facrec->modelpdf; + $this->cond_reglement_id = GETPOST('cond_reglement_id') > 0 ? GETPOST('cond_reglement_id') : $_facrec->cond_reglement_id; + $this->mode_reglement_id = GETPOST('mode_reglement_id') > 0 ? GETPOST('mode_reglement_id') : $_facrec->mode_reglement_id; + $this->fk_account = GETPOST('fk_account') > 0 ? GETPOST('fk_account') : $_facrec->fk_account; + + // Fields always coming from template $this->remise_absolue = $_facrec->remise_absolue; $this->remise_percent = $_facrec->remise_percent; $this->fk_incoterms = $_facrec->fk_incoterms; $this->location_incoterms= $_facrec->location_incoterms; - $this->note_public = $_facrec->note_public; - $this->note_private = $_facrec->note_private; - // Clean parameters if (! $this->type) $this->type = self::TYPE_STANDARD; $this->ref_client=trim($this->ref_client); $this->note_public=trim($this->note_public); $this->note_private=trim($this->note_private); - $this->note_private=dol_concatdesc($facture->note_private, $langs->trans("GeneratedFromRecurringInvoice", $_facrec->ref)); + $this->note_private=dol_concatdesc($this->note_private, $langs->trans("GeneratedFromRecurringInvoice", $_facrec->ref)); //if (! $this->remise) $this->remise = 0; if (! $this->mode_reglement_id) $this->mode_reglement_id = 0; @@ -730,7 +734,7 @@ class Facture extends CommonInvoice */ function createFromClone($socid=0) { - global $conf,$user,$langs,$hookmanager; + global $user,$hookmanager; $error=0; @@ -845,7 +849,7 @@ class Facture extends CommonInvoice */ function createFromOrder($object) { - global $conf,$user,$langs,$hookmanager; + global $user,$hookmanager; $error=0; @@ -1285,7 +1289,6 @@ class Facture extends CommonInvoice */ function update($user=null, $notrigger=0) { - global $conf, $langs; $error=0; // Clean parameters @@ -1678,7 +1681,6 @@ class Facture extends CommonInvoice */ function set_paid($user,$close_code='',$close_note='') { - global $conf,$langs; $error=0; if ($this->paye != 1) @@ -1736,7 +1738,6 @@ class Facture extends CommonInvoice */ function set_unpaid($user) { - global $conf,$langs; $error=0; $this->db->begin(); @@ -1786,9 +1787,6 @@ class Facture extends CommonInvoice */ function set_canceled($user,$close_code='',$close_note='') { - global $conf,$langs; - - $error=0; dol_syslog(get_class($this)."::set_canceled rowid=".$this->id, LOG_DEBUG); @@ -2459,6 +2457,7 @@ class Facture extends CommonInvoice */ function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type= self::TYPE_STANDARD, $fk_parent_line=0, $skip_update_total=0, $fk_fournprice=null, $pa_ht=0, $label='', $special_code=0, $array_options=0, $situation_percent=0, $fk_unit = null) { + global $conf,$user; // Deprecation warning if ($label) { dol_syslog(__METHOD__ . ": using line label is deprecated", LOG_WARNING); @@ -2537,6 +2536,19 @@ class Facture extends CommonInvoice $line = new FactureLigne($this->db); $line->fetch($rowid); + if (!empty($line->fk_product)) + { + $product=new Product($this->db); + $result=$product->fetch($line->fk_product); + $product_type=$product->type; + + if (! empty($conf->global->STOCK_MUST_BE_ENOUGH_FOR_INVOICE) && $product_type == 0 && $product->stock_reel < $qty) { + $this->error=$langs->trans('ErrorStockIsNotEnough'); + $this->db->rollback(); + return -3; + } + } + $staticline = clone $line; $line->oldline = $staticline; @@ -2589,7 +2601,7 @@ class Facture extends CommonInvoice $this->line->array_options=$array_options; } - $result=$this->line->update(); + $result=$this->line->update($user); if ($result > 0) { // Reorder if child line @@ -2650,7 +2662,7 @@ class Facture extends CommonInvoice */ function update_percent($line, $percent) { - global $mysoc; + global $mysoc,$user; include_once(DOL_DOCUMENT_ROOT . '/core/lib/price.lib.php'); @@ -2663,7 +2675,7 @@ class Facture extends CommonInvoice $line->total_ttc = $tabprice[2]; $line->total_localtax1 = $tabprice[9]; $line->total_localtax2 = $tabprice[10]; - $line->update(); + $line->update($user); $this->update_price(1); $this->db->commit(); } @@ -2676,7 +2688,6 @@ class Facture extends CommonInvoice */ function deleteline($rowid) { - global $langs, $conf; dol_syslog(get_class($this)."::deleteline rowid=".$rowid, LOG_DEBUG); @@ -2914,7 +2925,7 @@ class Facture extends CommonInvoice */ function getNextNumRef($soc,$mode='next') { - global $conf, $db, $langs; + global $conf, $langs; $langs->load("bills"); // Clean parameters (if not defined or using deprecated value) @@ -2976,7 +2987,7 @@ class Facture extends CommonInvoice * set up mask. */ if ($mode != 'last' && !$numref) { - dol_print_error($db,"Facture::getNextNumRef ".$obj->error); + dol_print_error($this->db,"Facture::getNextNumRef ".$obj->error); return ""; } @@ -3290,7 +3301,6 @@ class Facture extends CommonInvoice */ function demande_prelevement($fuser, $amount=0) { - global $langs; $error=0; @@ -3510,7 +3520,7 @@ class Facture extends CommonInvoice */ function initAsSpecimen($option='') { - global $user,$langs,$conf; + global $langs; $now=dol_now(); $arraynow=dol_getdate($now); @@ -3695,7 +3705,7 @@ class Facture extends CommonInvoice */ public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0) { - global $conf,$user,$langs; + global $conf,$langs; $langs->load("bills"); @@ -3795,7 +3805,6 @@ class Facture extends CommonInvoice */ function setFinal() { - global $conf, $langs, $user; $this->db->begin(); @@ -4259,7 +4268,7 @@ class FactureLigne extends CommonInvoiceLine */ function update($user='',$notrigger=0) { - global $user,$langs,$conf; + global $user,$conf; $error=0; @@ -4385,9 +4394,7 @@ class FactureLigne extends CommonInvoiceLine */ function delete() { - global $conf,$langs,$user; - - $error=0; + global $user; $this->db->begin(); diff --git a/htdocs/compta/facture/fiche-rec.php b/htdocs/compta/facture/fiche-rec.php index 275724d3012..b826e4f266d 100644 --- a/htdocs/compta/facture/fiche-rec.php +++ b/htdocs/compta/facture/fiche-rec.php @@ -32,31 +32,48 @@ require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php'; require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; $langs->load('bills'); $langs->load('compta'); // Security check $id=(GETPOST('facid','int')?GETPOST('facid','int'):GETPOST('id','int')); +$confirm = GETPOST('confirm', 'alpha'); +$cancel = GETPOST('cancel', 'alpha'); +$lineid=GETPOST('lineid','int'); $ref=GETPOST('ref','alpha'); $action=GETPOST('action', 'alpha'); if ($user->societe_id) $socid=$user->societe_id; $objecttype = 'facture_rec'; if ($action == "create" || $action == "add") $objecttype = ''; $result = restrictedArea($user, 'facture', $id, $objecttype); +$projectid = GETPOST('projectid','int'); + +$search_ref=GETPOST('search_ref'); +$search_societe=GETPOST('search_societe'); +$search_montant_ht=GETPOST('search_montant_ht'); +$search_montant_vat=GETPOST('search_montant_vat'); +$search_montant_ttc=GETPOST('search_montant_ttc'); +$day=GETPOST('day'); +$year=GETPOST('year'); +$month=GETPOST('month'); +$day_date_when=GETPOST('day_date_when'); +$year_date_when=GETPOST('year_date_when'); +$month_date_when=GETPOST('month_date_when'); +$search_frequency=GETPOST('search_frequency'); -if ($page == -1) -{ - $page = 0 ; -} $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; -$offset = $limit * $page ; - -if ($sortorder == "") -$sortorder="DESC"; - -if ($sortfield == "") -$sortfield="f.datef"; +$sortfield = GETPOST("sortfield",'alpha'); +$sortorder = GETPOST("sortorder",'alpha'); +$page = GETPOST("page",'int'); +if ($page == -1) { $page = 0; } +$offset = $limit * $page; +if (! $sortorder) $sortorder='DESC'; +if (! $sortfield) $sortfield='f.titre'; +$pageprev = $page - 1; +$pagenext = $page + 1; $object = new FactureRec($db); if (($id > 0 || $ref) && $action != 'create' && $action != 'add') @@ -68,10 +85,48 @@ if (($id > 0 || $ref) && $action != 'create' && $action != 'add') } } +// Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array +$hookmanager->initHooks(array('invoicecard','globalcard')); +$extrafields = new ExtraFields($db); + +// fetch optionals attributes and labels +$extralabels = $extrafields->fetch_name_optionals_label('facturerec'); +$search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_'); + +$permissionnote = $user->rights->facture->creer; // Used by the include of actions_setnotes.inc.php +$permissiondellink=$user->rights->facture->creer; // Used by the include of actions_dellink.inc.php +$permissiontoedit = $user->rights->facture->creer; // Used by the include of actions_lineupdonw.inc.php + +$arrayfields=array( + 'f.titre'=>array('label'=>$langs->trans("Ref"), 'checked'=>1), + 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1), + 'f.total'=>array('label'=>$langs->trans("AmountHT"), 'checked'=>1), + 'f.tva'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>1), + 'f.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>1), + 'f.frequency'=>array('label'=>$langs->trans("RecurringInvoiceTemplate"), 'checked'=>1), + 'f.date_last_gen'=>array('label'=>$langs->trans("DateLastGeneration"), 'checked'=>1), + 'f.date_when'=>array('label'=>$langs->trans("NextDateToExecution"), 'checked'=>1), + 'f.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500), + 'f.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500), +); +// Extra fields +if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) +{ + foreach($extrafields->attribute_label as $key => $val) + { + $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]); + } +} + + /* * Actions */ +// Set note +include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not include_once + +include DOL_DOCUMENT_ROOT.'/core/actions_lineupdown.inc.php'; // Must be include, not include_once // Create predefined invoice if ($action == 'add') @@ -90,7 +145,7 @@ if ($action == 'add') $rehour=GETPOST('rehour'); $remin=GETPOST('remin'); $nb_gen_max=GETPOST('nb_gen_max', 'int'); - if (empty($nb_gen_max)) $nb_gen_max =0; + //if (empty($nb_gen_max)) $nb_gen_max =0; if (GETPOST('frequency')) { @@ -100,7 +155,7 @@ if ($action == 'add') $action = "create"; $error++; } - if ($nb_gen_max == '') + if ($nb_gen_max === '') { setEventMessages($langs->transnoentities("ErrorFieldRequired",$langs->trans("MaxPeriodNumber")), null, 'errors'); $action = "create"; @@ -111,7 +166,8 @@ if ($action == 'add') if (! $error) { $object->titre = GETPOST('titre', 'alpha'); - $object->note_private = GETPOST('note_private'); + $object->note_private = GETPOST('note_private'); + $object->note_public = GETPOST('note_public'); $object->usenewprice = GETPOST('usenewprice'); $object->frequency = $frequency; @@ -119,6 +175,8 @@ if ($action == 'add') $object->nb_gen_max = $nb_gen_max; $object->auto_validate = GETPOST('auto_validate', 'int'); + $object->fk_project = $projectid; + $date_next_execution = dol_mktime($rehour, $remin, 0, $remonth, $reday, $reyear); $object->date_when = $date_next_execution; @@ -233,9 +291,347 @@ elseif ($action == 'setauto_validate' && $user->rights->facture->creer) { $object->setAutoValidate(GETPOST('auto_validate', 'int')); } -// Set note -$permissionnote=$user->rights->facture->creer; // Used by the include of actions_setnotes.inc.php -include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once + +// Delete line +if ($action == 'confirm_deleteline' && $confirm == 'yes' && $user->rights->facture->creer) +{ + $object->fetch($id); + $object->fetch_thirdparty(); + + $db->begin(); + + $line=new FactureLigneRec($db); + + // For triggers + $line->id = $lineid; + + if ($line->delete() > 0) + { + $result=$object->update_price(1); + + if ($result > 0) + { + $db->commit(); + $object->fetch($object->id); // Reload lines + } + else + { + $db->rollback(); + setEventMessages($db->lasterror(), null, 'errors'); + } + } + else + { + $db->rollback(); + setEventMessages($line->error, $line->errors, 'errors'); + } +} + +// Add a new line +if ($action == 'addline' && $user->rights->facture->creer) +{ + $langs->load('errors'); + $error = 0; + + // Set if we used free entry or predefined product + $predef=''; + $product_desc=(GETPOST('dp_desc')?GETPOST('dp_desc'):''); + $price_ht = GETPOST('price_ht'); + if (GETPOST('prod_entry_mode') == 'free') + { + $idprod=0; + $tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); + } + else + { + $idprod=GETPOST('idprod', 'int'); + $tva_tx = ''; + } + + $qty = GETPOST('qty' . $predef); + $remise_percent = GETPOST('remise_percent' . $predef); + + // Extrafields + $extrafieldsline = new ExtraFields($db); + $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); + $array_options = $extrafieldsline->getOptionalsFromPost($extralabelsline, $predef); + // Unset extrafield + if (is_array($extralabelsline)) { + // Get extra fields + foreach ($extralabelsline as $key => $value) { + unset($_POST["options_" . $key . $predef]); + } + } + + if (empty($idprod) && ($price_ht < 0) && ($qty < 0)) { + setEventMessages($langs->trans('ErrorBothFieldCantBeNegative', $langs->transnoentitiesnoconv('UnitPriceHT'), $langs->transnoentitiesnoconv('Qty')), null, 'errors'); + $error ++; + } + if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && GETPOST('type') < 0) { + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), null, 'errors'); + $error ++; + } + if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && (! ($price_ht >= 0) || $price_ht == '')) // Unit price can be 0 but not '' + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), null, 'errors'); + $error ++; + } + if ($qty == '') { + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Qty')), null, 'errors'); + $error ++; + } + if (GETPOST('prod_entry_mode') == 'free' && empty($idprod) && empty($product_desc)) { + setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Description')), null, 'errors'); + $error ++; + } + if ($qty < 0) { + $langs->load("errors"); + setEventMessages($langs->trans('ErrorQtyForCustomerInvoiceCantBeNegative'), null, 'errors'); + $error ++; + } + + if (! $error && ($qty >= 0) && (! empty($product_desc) || ! empty($idprod))) { + $ret = $object->fetch($id); + if ($ret < 0) { + dol_print_error($db, $object->error); + exit(); + } + $ret = $object->fetch_thirdparty(); + + // Clean parameters + $date_start = dol_mktime(GETPOST('date_start' . $predef . 'hour'), GETPOST('date_start' . $predef . 'min'), GETPOST('date_start' . $predef . 'sec'), GETPOST('date_start' . $predef . 'month'), GETPOST('date_start' . $predef . 'day'), GETPOST('date_start' . $predef . 'year')); + $date_end = dol_mktime(GETPOST('date_end' . $predef . 'hour'), GETPOST('date_end' . $predef . 'min'), GETPOST('date_end' . $predef . 'sec'), GETPOST('date_end' . $predef . 'month'), GETPOST('date_end' . $predef . 'day'), GETPOST('date_end' . $predef . 'year')); + $price_base_type = (GETPOST('price_base_type', 'alpha') ? GETPOST('price_base_type', 'alpha') : 'HT'); + + // Define special_code for special lines + $special_code = 0; + // if (empty($_POST['qty'])) $special_code=3; // Options should not exists on invoices + + // Ecrase $pu par celui du produit + // Ecrase $desc par celui du produit + // Ecrase $txtva par celui du produit + // Ecrase $base_price_type par celui du produit + // Replaces $fk_unit with the product's + if (! empty($idprod)) + { + $prod = new Product($db); + $prod->fetch($idprod); + + $label = ((GETPOST('product_label') && GETPOST('product_label') != $prod->label) ? GETPOST('product_label') : ''); + + // Update if prices fields are defined + $tva_tx = get_default_tva($mysoc, $object->thirdparty, $prod->id); + $tva_npr = get_default_npr($mysoc, $object->thirdparty, $prod->id); + if (empty($tva_tx)) $tva_npr=0; + + $pu_ht = $prod->price; + $pu_ttc = $prod->price_ttc; + $price_min = $prod->price_min; + $price_base_type = $prod->price_base_type; + + // We define price for product + 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_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)) // using this option is a bug. kept for backward compatibility + { + 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]; + if (empty($tva_tx)) $tva_npr=0; + } + } + 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'); + } + // 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). + 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'); + } + } + + $desc = ''; + + // 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; + } + + $desc = dol_concatdesc($desc, $product_desc); + + // 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); + } + + $type = $prod->type; + $fk_unit = $prod->fk_unit; + } else { + $pu_ht = price2num($price_ht, 'MU'); + $pu_ttc = price2num(GETPOST('price_ttc'), 'MU'); + $tva_npr = (preg_match('/\*/', $tva_tx) ? 1 : 0); + $tva_tx = str_replace('*', '', $tva_tx); + if (empty($tva_tx)) $tva_npr=0; + $label = (GETPOST('product_label') ? GETPOST('product_label') : ''); + $desc = $product_desc; + $type = GETPOST('type'); + $fk_unit= GETPOST('units', 'alpha'); + } + + // Margin + $fournprice = price2num(GETPOST('fournprice' . $predef) ? GETPOST('fournprice' . $predef) : ''); + $buyingprice = price2num(GETPOST('buying_price' . $predef) != '' ? GETPOST('buying_price' . $predef) : ''); // If buying_price is '0', we must keep this value + + // Local Taxes + $localtax1_tx = get_localtax($tva_tx, 1, $object->thirdparty, $mysoc, $tva_npr); + $localtax2_tx = get_localtax($tva_tx, 2, $object->thirdparty, $mysoc, $tva_npr); + + $info_bits = 0; + if ($tva_npr) + $info_bits |= 0x01; + + if (! empty($price_min) && (price2num($pu_ht) * (1 - price2num($remise_percent) / 100) < price2num($price_min))) { + $mesg = $langs->trans("CantBeLessThanMinPrice", price(price2num($price_min, 'MU'), 0, $langs, 0, 0, - 1, $conf->currency)); + setEventMessages($mesg, null, 'errors'); + } else { + // Insert line + $result = $object->addline($desc, $pu_ht, $qty, $tva_tx, $idprod, $remise_percent, $price_base_type, $info_bits, '', $pu_ttc, $type, - 1, $special_code, $label, $fk_unit); + + if ($result > 0) + { + // Define output language + /*if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) + { + $outputlangs = $langs; + $newlang = ''; + if ($conf->global->MAIN_MULTILANGS && empty($newlang) && GETPOST('lang_id')) $newlang = GETPOST('lang_id','alpha'); + if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $object->thirdparty->default_lang; + if (! empty($newlang)) { + $outputlangs = new Translate("", $conf); + $outputlangs->setDefaultLang($newlang); + } + $model=$object->modelpdf; + $ret = $object->fetch($id); // Reload to get new records + + $result = $object->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref); + if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); + }*/ + $object->fetch($object->id); // Reload lines + + unset($_POST['prod_entry_mode']); + + unset($_POST['qty']); + unset($_POST['type']); + unset($_POST['remise_percent']); + unset($_POST['price_ht']); + unset($_POST['multicurrency_price_ht']); + unset($_POST['price_ttc']); + unset($_POST['tva_tx']); + unset($_POST['product_ref']); + unset($_POST['product_label']); + unset($_POST['product_desc']); + unset($_POST['fournprice']); + unset($_POST['buying_price']); + unset($_POST['np_marginRate']); + unset($_POST['np_markRate']); + unset($_POST['dp_desc']); + unset($_POST['idprod']); + unset($_POST['units']); + + unset($_POST['date_starthour']); + unset($_POST['date_startmin']); + unset($_POST['date_startsec']); + unset($_POST['date_startday']); + unset($_POST['date_startmonth']); + unset($_POST['date_startyear']); + unset($_POST['date_endhour']); + unset($_POST['date_endmin']); + unset($_POST['date_endsec']); + unset($_POST['date_endday']); + unset($_POST['date_endmonth']); + unset($_POST['date_endyear']); + + unset($_POST['situations']); + unset($_POST['progress']); + } else { + setEventMessages($object->error, $object->errors, 'errors'); + } + + $action = ''; + } + } +} + +// Do we click on purge search criteria ? +if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both test are required to be compatible with all browsers +{ + $search_ref=''; + $search_societe=''; + $search_montant_ht=''; + $search_montant_vat=''; + $search_montant_ttc=''; + $day=''; + $year=''; + $month=''; + $day_date_when=''; + $year_date_when=''; + $month_date_when=''; + $search_frequency=''; + $search_array_options=array(); +} @@ -246,6 +642,7 @@ include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, llxHeader('',$langs->trans("RepeatableInvoices"),'ch-facture.html#s-fac-facture-rec'); $form = new Form($db); +$formother = new FormOther($db); $companystatic = new Societe($db); $now = dol_now(); @@ -262,10 +659,13 @@ if ($action == 'create') $object = new Facture($db); // Source invoice $product_static = new Product($db); - + $formproject = new FormProjets($db); + if ($object->fetch($id, $ref) > 0) { - print '
'; + $result = $object->getLinesArray(); + + print ''; print ''; print ''; print ''; @@ -281,21 +681,24 @@ if ($action == 'create') $object->fetch_thirdparty(); // Third party - print ''.$langs->trans("Customer").''.$object->thirdparty->getNomUrl(1,'customer').''; - print ''; - print $langs->trans("Comment"); - print ''; + print ''.$langs->trans("Customer").''.$object->thirdparty->getNomUrl(1,'customer').''; + print ''; // Title print ''.$langs->trans("Title").''; - print ''; - print ''; - - // Note - print ''; - print ''; + print ''; print ''; + // Note public + print ''.$langs->trans("NotePublic").''; + print ''; + print ''; + + // Note private + print ''.$langs->trans("NotePrivate").''; + print ''; + print ''; + // Author print "".$langs->trans("Author")."".$user->getFullName($langs).""; @@ -310,18 +713,16 @@ if ($action == 'create') print ""; // Project - if (! empty($conf->projet->enabled)) - { - print "".$langs->trans("Project").""; - if ($object->fk_project > 0) - { - $project = new Project($db); - $project->fetch($object->fk_project); - print $project->getNomUrl(1); - } - print ""; - } - + if (! empty($conf->projet->enabled) && is_object($object->thirdparty) && $object->thirdparty->id > 0) + { + $projectid = $object->fk_project; + $langs->load('projects'); + print '' . $langs->trans('Project') . ''; + $numprojet = $formproject->select_projects($socid, $projectid, 'projectid', 0); + print '   id).'">' . $langs->trans("AddProject") . ''; + print ''; + } + // Bank account if ($object->fk_account > 0) { @@ -342,7 +743,7 @@ if ($action == 'create') print ''; // Frequency - print ""; @@ -378,6 +779,19 @@ if ($action == 'create') /* * Invoice lines */ + print '
".$form->textwithpicto($langs->trans("Frequency"), $langs->transnoentitiesnoconv('toolTipFrequency')).""; + print '
'.$form->textwithpicto($langs->trans("Frequency"), $langs->transnoentitiesnoconv('toolTipFrequency')).""; print " ".$form->selectarray('unit_frequency', array('d'=>$langs->trans('Day'), 'm'=>$langs->trans('Month'), 'y'=>$langs->trans('Year')), (GETPOST('unit_frequency')?GETPOST('unit_frequency'):'m')); print "
'; + // Show object lines + if (! empty($object->lines)) + { + $disableedit=1; + $disablemove=1; + $disableremove=1; + $ret = $object->printObjectLines('', $mysoc, $soc, $lineid, 0); // No date selector for template invoice + } + + print "
\n"; + + /* print ''; print '
'; @@ -544,7 +958,8 @@ if ($action == 'create') print $db->error(); } print "
"; - + */ + print ''; if ($flag_price_may_change) @@ -580,9 +995,16 @@ else { $object->fetch_thirdparty(); + // Confirmation de la suppression d'une ligne produit + if ($action == 'ask_deleteline') { + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $object->id . '&lineid=' . $lineid, $langs->trans('DeleteProductLine'), $langs->trans('ConfirmDeleteProductLine'), 'confirm_deleteline', '', 'no', 1); + } + + print $formconfirm; + $author = new User($db); $author->fetch($object->user_author); - + $head=array(); $h=0; $head[$h][0] = $_SERVER["PHP_SELF"].'?id='.$object->id; @@ -667,7 +1089,15 @@ else } print ''; + // Note public + print ''; + print $form->editfieldkey($langs->trans("NotePublic"), 'note_public', $object->note_public, $object, $user->rights->facture->creer); + print ''; + print $form->editfieldval($langs->trans("NotePublic"), 'note_public', $object->note_public, $object, $user->rights->facture->creer, 'textarea:'.ROWS_4.':60'); + print ''; + print ''; + // Note private print ''; print $form->editfieldkey($langs->trans("NotePrivate"), 'note_private', $object->note_private, $object, $user->rights->facture->creer); print ''; @@ -851,96 +1281,45 @@ else print '
'; } - /* - * Lines - */ - - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - if ($conf->global->PRODUCT_USE_UNITS) { - print ''; + // Lines + print ' + + + + + '; + + if (! empty($conf->use_javascript_ajax) && $object->statut == 0) { + include DOL_DOCUMENT_ROOT . '/core/tpl/ajaxrow.tpl.php'; } - print ''; - - $num = count($object->lines); - $i = 0; - $var=true; - while ($i < $num) + + print '
'.$langs->trans("Description").''.$langs->trans("VAT").''.$langs->trans("PriceUHT").''.$langs->trans("Qty").''.$langs->trans("ReductionShort").''.$langs->trans("Unit").'
'; + // Show object lines + if (! empty($object->lines)) { - $var=!$var; - - $product_static=new Product($db); - - // Show product and description - $type=(isset($object->lines[$i]->product_type)?$object->lines[$i]->product_type:$object->lines[$i]->fk_product_type); - // Try to enhance type detection using date_start and date_end for free lines when type - // was not saved. - if (! empty($objp->date_start)) $type=1; - if (! empty($objp->date_end)) $type=1; - - // Show line - print ""; - if ($object->lines[$i]->fk_product > 0) - { - print ''; - } - else - { - print ''; - } - print ''; - print ''; - print ''; - print ''; - if ($conf->global->PRODUCT_USE_UNITS) { - print ""; - } - print "\n"; - $i++; + $disableedit=1; + //$disablemove=1; + $ret = $object->printObjectLines($action, $mysoc, $soc, $lineid, 0); // No date selector for template invoice } - print '
'; - print ''; // ancre pour retourner sur la ligne - - // Show product and description - $product_static->type=$object->lines[$i]->fk_product_type; - $product_static->id=$object->lines[$i]->fk_product; - $product_static->ref=$object->lines[$i]->product_ref; - $text=$product_static->getNomUrl(1); - $text.= ' - '.(! empty($object->lines[$i]->label)?$object->lines[$i]->label:$object->lines[$i]->product_label); - $description=(! empty($conf->global->PRODUIT_DESC_IN_FORM)?'':dol_htmlentitiesbr($object->lines[$i]->desc)); - print $form->textwithtooltip($text,$description,3,'','',$i); - - // Show range - print_date_range($object->lines[$i]->date_start, $object->lines[$i]->date_end); - - // Add description in form - if (! empty($conf->global->PRODUIT_DESC_IN_FORM)) - print (! empty($object->lines[$i]->desc) && $object->lines[$i]->desc!=$fac->lines[$i]->product_label)?'
'.dol_htmlentitiesbr($object->lines[$i]->desc):''; - - print '
'; - - if ($type==1) $text = img_object($langs->trans('Service'),'service'); - else $text = img_object($langs->trans('Product'),'product'); - - if (! empty($object->lines[$i]->label)) { - - $text.= ' '.$object->lines[$i]->label.''; - print $form->textwithtooltip($text,dol_htmlentitiesbr($object->lines[$i]->desc),3,'','',$i); - - } else { - - print $text.' '.nl2br($object->lines[$i]->desc); - } - - // Show range - print_date_range($object->lines[$i]->date_start, $object->lines[$i]->date_end); - - print ''.vatrate($object->lines[$i]->tva_tx, 1).''.price($object->lines[$i]->price).''.$object->lines[$i]->qty.''.$object->lines[$i]->remise_percent.' %".$object->lines[$i]->getLabelOfUnit()."
'; + + // Form to add new line + if ($object->statut == 0 && $user->rights->facture->creer && $action != 'valid' && $action != 'editline') + { + if ($action != 'editline') + { + $var = true; + + // Add free products/services + $object->formAddObjectLine(0, $mysoc, $soc); // No date selector for template invoice + + $parameters = array(); + $reshook = $hookmanager->executeHooks('formAddObjectLine', $parameters, $object, $action); // Note that $action and $object may have been modified by hook + } + } + + print "\n"; + + print "
\n"; dol_fiche_end(); @@ -998,15 +1377,47 @@ else $sql.= " FROM ".MAIN_DB_PREFIX."societe as s,".MAIN_DB_PREFIX."facture_rec as f"; $sql.= " WHERE f.fk_soc = s.rowid"; $sql.= " AND f.entity = ".$conf->entity; - if ($socid) $sql .= " AND s.rowid = ".$socid; + if ($search_ref) $sql .= natural_search('f.titre', $search_ref); + if ($search_societe) $sql .= natural_search('s.nom', $search_societe); + if ($search_frequency) $sql .= natural_search('f.frequency', $search_frequency); + if ($search_montant_ht != '') $sql.= natural_search('f.total', $search_montant_ht, 1); + if ($search_montant_vat != '') $sql.= natural_search('f.tva', $search_montant_vat, 1); + if ($search_montant_ttc != '') $sql.= natural_search('f.total_ttc', $search_montant_ttc, 1); + if ($month > 0) + { + if ($year > 0 && empty($day)) + $sql.= " AND f.date_last_gen BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'"; + else if ($year > 0 && ! empty($day)) + $sql.= " AND f.date_last_gen BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'"; + else + $sql.= " AND date_format(f.date_last_gen, '%m') = '".$month."'"; + } + else if ($year > 0) + { + $sql.= " AND f.date_last_gen BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'"; + } + if ($month_date_when > 0) + { + if ($year_date_when > 0 && empty($day_date_when)) + $sql.= " AND f.date_when BETWEEN '".$db->idate(dol_get_first_day($year_date_when,$month_date_when,false))."' AND '".$db->idate(dol_get_last_day($year_date_when,$month_date_when,false))."'"; + else if ($year_date_when > 0 && ! empty($day_date_when)) + $sql.= " AND f.date_date_when_reglement BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month_date_when, $day_date_when, $year_date_when))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month_date_when, $day_date_when, $year_date_when))."'"; + else + $sql.= " AND date_format(f.date_when, '%m') = '".$month_date_when."'"; + } + else if ($year_date_when > 0) + { + $sql.= " AND f.date_when BETWEEN '".$db->idate(dol_get_first_day($year_date_when,1,false))."' AND '".$db->idate(dol_get_last_day($year_date_when,12,false))."'"; + } - $nbtotalofrecords = 0; + $nbtotalofrecords = 0; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) { $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); } - + + $sql.= $db->order($sortfield, $sortorder); $sql.= $db->plimit($limit+1,$offset); $resql = $db->query($sql); @@ -1016,6 +1427,29 @@ else $param='&socid='.$socid; if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit; + if ($day) $param.='&day='.$day; + if ($month) $param.='&month='.$month; + if ($year) $param.='&year=' .$year; + if ($day_date_when) $param.='&day_date_when='.$day_date_when; + if ($month_date_when) $param.='&month_date_when='.$month_date_when; + if ($year_date_when) $param.='&year_date_when=' .$year_date_when; + if ($search_ref) $param.='&search_ref=' .$search_ref; + if ($search_societe) $param.='&search_societe=' .$search_societe; + if ($search_montant_ht != '') $param.='&search_montant_ht='.$search_montant_ht; + if ($search_montant_vat != '') $param.='&search_montant_vat='.$search_montant_vat; + if ($search_montant_ttc != '') $param.='&search_montant_ttc='.$search_montant_ttc; + if ($search_frequency) $param.='&search_frequency=' .$search_frequency; + if ($option) $param.="&option=".$option; + if ($optioncss != '') $param.='&optioncss='.$optioncss; + // Add $param from extra fields + foreach ($search_array_options as $key => $val) + { + $crit=$val; + $tmpkey=preg_replace('/search_options_/','',$key); + if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val); + } + + $massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge"))); print '
'."\n"; if ($optioncss != '') print ''; @@ -1024,25 +1458,133 @@ else print ''; print ''; print ''; - - print_barre_liste($langs->trans("RepeatableInvoices"),$page,$_SERVER['PHP_SELF'],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecord,'title_accountancy.png',0,'','',$limit); + + print_barre_liste($langs->trans("RepeatableInvoices"),$page,$_SERVER['PHP_SELF'],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords,'title_accountancy.png',0,'','',$limit); print $langs->trans("ToCreateAPredefinedInvoice", $langs->transnoentitiesnoconv("ChangeIntoRepeatableInvoice")).'

'; $i = 0; print ''; print ''; - print_liste_field_titre($langs->trans("Ref")); - print_liste_field_titre($langs->trans("Company"),$_SERVER['PHP_SELF'],"s.nom","","&socid=$socid","",$sortfiled,$sortorder); - print_liste_field_titre($langs->trans("AmountHT"),'','','','','align="right"'); - print_liste_field_titre($langs->trans("AmountVAT"),'','','','','align="right"'); - print_liste_field_titre($langs->trans("AmountTTC"),'','','','','align="right"'); - print_liste_field_titre($langs->trans("RecurringInvoiceTemplate"),'','','','','align="center"'); - print_liste_field_titre($langs->trans("DateLastGeneration"),'','','','','align="center"'); - print_liste_field_titre($langs->trans("NextDateToExecution"),'','','','','align="center"'); + print_liste_field_titre($langs->trans("Ref"),$_SERVER['PHP_SELF'],"f.titre","",$param,"",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("ThirdParty"),$_SERVER['PHP_SELF'],"s.nom","",$param,"",$sortfield,$sortorder); + print_liste_field_titre($langs->trans("AmountHT"),$_SERVER['PHP_SELF'],"f.total","",$param,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("AmountVAT"),$_SERVER['PHP_SELF'],"f.tva","",$param,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER['PHP_SELF'],"f.total_ttc","",$param,'align="right"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("RecurringInvoiceTemplate"),$_SERVER['PHP_SELF'],"f.frequency","",$param,'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("DateLastGeneration"),$_SERVER['PHP_SELF'],"f.date_last_gen","",$param,'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("NextDateToExecution"),$_SERVER['PHP_SELF'],"f.date_when","",$param,'align="center"',$sortfield,$sortorder); print_liste_field_titre(''); // Field may contains ling text print "\n"; + + // Filters lines + print ''; + // Ref + if (! empty($arrayfields['f.titre']['checked'])) + { + print ''; + } + // Thirpdarty + if (! empty($arrayfields['s.nom']['checked'])) + { + print ''; + } + if (! empty($arrayfields['f.total']['checked'])) + { + // Amount + print ''; + } + if (! empty($arrayfields['f.tva']['checked'])) + { + // Amount + print ''; + } + if (! empty($arrayfields['f.total_ttc']['checked'])) + { + // Amount + print ''; + } + if (! empty($arrayfields['f.frequency']['checked'])) + { + // Amount + print ''; + } + // Date invoice + if (! empty($arrayfields['f.date_last_gen']['checked'])) + { + print ''; + } + // Date due + if (! empty($arrayfields['f.date_when']['checked'])) + { + print ''; + } + // Extra fields + if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) + { + foreach($extrafields->attribute_label as $key => $val) + { + if (! empty($arrayfields["ef.".$key]['checked'])) + { + $align=$extrafields->getAlignFlag($key); + $typeofextrafield=$extrafields->attribute_type[$key]; + print ''; + } + } + } + // Fields from hook + $parameters=array('arrayfields'=>$arrayfields); + $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook + print $hookmanager->resPrint; + // Date creation + if (! empty($arrayfields['f.datec']['checked'])) + { + print ''; + } + // Date modification + if (! empty($arrayfields['f.tms']['checked'])) + { + print ''; + } + // Action column + print ''; + print "\n"; + + if ($num > 0) { $var=true; @@ -1089,7 +1631,7 @@ else $i++; } } - else print ''; + else print ''; print "
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + //print ''; + print ''; + if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print ''; + print ''; + $formother->select_year($year?$year:-1,'year',1, 20, 5); + print ''; + if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print ''; + print ''; + $formother->select_year($year_date_when?$year_date_when:-1,'year_date_when',1, 20, 5); + print ''; + if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select'))) + { + $crit=$val; + $tmpkey=preg_replace('/search_options_/','',$key); + $searchclass=''; + if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring'; + if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum'; + print ''; + } + print ''; + print ''; + print ''; + $searchpitco=$form->showFilterAndCheckAddButtons(0, 'checkforselect', 1); + print $searchpitco; + print '
'.$langs->trans("NoneF").'
'.$langs->trans("NoneF").'
"; $db->free($resql); diff --git a/htdocs/compta/facture/list.php b/htdocs/compta/facture/list.php index e2883081452..68eb4240226 100644 --- a/htdocs/compta/facture/list.php +++ b/htdocs/compta/facture/list.php @@ -153,6 +153,7 @@ $arrayfields=array( 'f.total_vat'=>array('label'=>$langs->trans("AmountVAT"), 'checked'=>0), 'f.total_ttc'=>array('label'=>$langs->trans("AmountTTC"), 'checked'=>0), 'am'=>array('label'=>$langs->trans("Received"), 'checked'=>0), + 'rtp'=>array('label'=>$langs->trans("Rest"), 'checked'=>0), 'f.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500), 'f.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500), 'f.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000), @@ -694,7 +695,7 @@ if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')'; if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')'; if ($search_company) $sql .= natural_search('s.nom', $search_company); if ($search_montant_ht != '') $sql.= natural_search('f.total', $search_montant_ht, 1); -if ($search_montant_vat != '') $sql.= natural_search('f.total', $search_montant_vat, 1); +if ($search_montant_vat != '') $sql.= natural_search('f.total_vat', $search_montant_vat, 1); if ($search_montant_ttc != '') $sql.= natural_search('f.total_ttc', $search_montant_ttc, 1); if ($search_status != '' && $search_status >= 0) $sql.= " AND f.fk_statut = ".$db->escape($search_status); if ($search_paymentmode > 0) $sql .= " AND f.fk_mode_reglement = ".$search_paymentmode.""; @@ -997,6 +998,7 @@ if ($resql) if (! empty($arrayfields['f.total_vat']['checked'])) print_liste_field_titre($arrayfields['f.total_vat']['label'],$_SERVER['PHP_SELF'],'f.tva','',$param,'align="right"',$sortfield,$sortorder); if (! empty($arrayfields['f.total_ttc']['checked'])) print_liste_field_titre($arrayfields['f.total_ttc']['label'],$_SERVER['PHP_SELF'],'f.total_ttc','',$param,'align="right"',$sortfield,$sortorder); if (! empty($arrayfields['am']['checked'])) print_liste_field_titre($arrayfields['am']['label'],$_SERVER['PHP_SELF'],'am','',$param,'align="right"',$sortfield,$sortorder); + if (! empty($arrayfields['rtp']['checked'])) print_liste_field_titre($arrayfields['rtp']['label'],$_SERVER['PHP_SELF'],'rtp','',$param,'align="right"',$sortfield,$sortorder); // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { @@ -1117,6 +1119,11 @@ if ($resql) print ''; print ''; } + if (! empty($arrayfields['rtp']['checked'])) + { + print ''; + print ''; + } // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) { @@ -1195,6 +1202,7 @@ if ($resql) $facturestatic->date_lim_reglement=$db->jdate($obj->datelimite); $notetoshow=dol_string_nohtmltag(($user->societe_id>0?$obj->note_public:$obj->note_private),1); $paiement = $facturestatic->getSommePaiement(); + $remaintopay = $obj->total_ttc - $paiement; print ''; @@ -1347,6 +1355,14 @@ if ($resql) if (! $i) $totalarray['totalamfield']=$totalarray['nbfield']; $totalarray['totalam'] += $paiement; } + + if (! empty($arrayfields['rtp']['checked'])) + { + print ''; + if (! $i) $totalarray['nbfield']++; + if (! $i) $totalarray['totalrtpfield']=$totalarray['nbfield']; + $totalarray['totalrtp'] += $remaintopay; + } // Extra fields if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) @@ -1425,6 +1441,7 @@ if ($resql) elseif ($totalarray['totalvatfield'] == $i) print ''; elseif ($totalarray['totalttcfield'] == $i) print ''; elseif ($totalarray['totalamfield'] == $i) print ''; + elseif ($totalarray['totalrtpfield'] == $i) print ''; else print ''; } print ''; diff --git a/htdocs/compta/index.php b/htdocs/compta/index.php index 0f513412a93..f0a8c82df1b 100644 --- a/htdocs/compta/index.php +++ b/htdocs/compta/index.php @@ -199,7 +199,7 @@ if (! empty($conf->facture->enabled) && $user->rights->facture->lire) } else { - print ''; + print ''; } print "
'.(! empty($remaintopay)?price($remaintopay,0,$langs):' ').''.price($totalarray['totalvat']).''.price($totalarray['totalttc']).''.price($totalarray['totalam']).''.price($totalarray['totalrtp']).'
'.$langs->trans("NoInvoice").'
'.$langs->trans("NoInvoice").'

"; $db->free($resql); @@ -275,7 +275,7 @@ if (! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture- } else { - print ''.$langs->trans("NoInvoice").''; + print ''.$langs->trans("NoInvoice").''; } print "
"; $db->free($resql); diff --git a/htdocs/compta/resultat/clientfourn.php b/htdocs/compta/resultat/clientfourn.php index 6a31fc02b4c..2d9241301a6 100644 --- a/htdocs/compta/resultat/clientfourn.php +++ b/htdocs/compta/resultat/clientfourn.php @@ -382,7 +382,7 @@ print ''; * Charges sociales non deductibles */ -print ''.$langs->trans("SocialContributions").' ('.$langs->trans("Type").' 0)'; +print ''.$langs->trans("SocialContributionsNondeductibles").''; if ($modecompta == 'CREANCES-DETTES') { @@ -456,7 +456,7 @@ print ''; * Charges sociales deductibles */ -print ''.$langs->trans("SocialContributions").' ('.$langs->trans("Type").' 1)'; +print ''.$langs->trans("SocialContributionsDeductibles").''; if ($modecompta == 'CREANCES-DETTES') { diff --git a/htdocs/compta/stats/cabyprodserv.php b/htdocs/compta/stats/cabyprodserv.php index ca58ff334b5..8e4aabd9339 100644 --- a/htdocs/compta/stats/cabyprodserv.php +++ b/htdocs/compta/stats/cabyprodserv.php @@ -181,6 +181,8 @@ report_header($nom,$nomlink,$period,$periodlink,$description,$builddate,$exportl // SQL request $catotal=0; +$catotal_ht=0; +$qtytotal=0; if ($modecompta == 'CREANCES-DETTES') { @@ -401,6 +403,8 @@ if ($modecompta == 'CREANCES-DETTES') // Total print ''; print ''.$langs->trans("Total").''; + print ''.price($qtytotal).''; + print ' '; print ''.price($catotal_ht).''; print ''.price($catotal).''; print ' '; diff --git a/htdocs/contact/class/contact.class.php b/htdocs/contact/class/contact.class.php index 88cd24af359..259918c5aa9 100644 --- a/htdocs/contact/class/contact.class.php +++ b/htdocs/contact/class/contact.class.php @@ -107,6 +107,47 @@ class Contact extends CommonObject $this->db = $db; $this->statut = 1; // By default, status is enabled } + + /** + * Load indicators into this->nb for board + * + * @return int <0 if KO, >0 if OK + */ + function load_state_board() + { + global $user; + + $this->nb=array(); + $clause = "WHERE"; + + $sql = "SELECT count(sp.rowid) as nb"; + $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as sp"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON (sp.fk_soc = s.rowid)"; + if (!$user->rights->societe->client->voir && !$user->societe_id) + { + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; + $sql.= " WHERE sc.fk_user = " .$user->id; + $clause = "AND"; + } + $sql.= ' '.$clause.' s.entity IN ('.getEntity($this->element, 1).')'; + + $resql=$this->db->query($sql); + if ($resql) + { + while ($obj=$this->db->fetch_object($resql)) + { + $this->nb["contacts"]=$obj->nb; + } + $this->db->free($resql); + return 1; + } + else + { + dol_print_error($this->db); + $this->error=$this->db->lasterror(); + return -1; + } + } /** * Add a contact into database diff --git a/htdocs/contrat/index.php b/htdocs/contrat/index.php index f962a9e82ae..18a60a3429d 100644 --- a/htdocs/contrat/index.php +++ b/htdocs/contrat/index.php @@ -273,7 +273,7 @@ if (! empty($conf->contrat->enabled) && $user->rights->contrat->lire) } else { - print ''.$langs->trans("NoContracts").''; + print ''.$langs->trans("NoContracts").''; } print "
"; $db->free($resql); diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 33c70d57ae6..3ad080d8a55 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -229,12 +229,13 @@ abstract class CommonObject public $mode_reglement_id; /** - * @var string Payment terms ID + * @var int Payment terms ID * @see setPaymentTerms() */ public $cond_reglement_id; /** - * @deprecated + * @var int Payment terms ID + * @deprecated Kept for compatibility * @see cond_reglement_id; */ public $cond_reglement; @@ -3236,7 +3237,9 @@ abstract class CommonObject */ function printObjectLines($action, $seller, $buyer, $selected=0, $dateSelector=0) { - global $conf, $hookmanager, $inputalsopricewithtax, $usemargins, $langs, $user; + global $conf, $hookmanager, $langs, $user; + // TODO We should not use global var for this ! + global $inputalsopricewithtax, $usemargins, $disableedit, $disablemove, $disableremove; // Define usemargins $usemargins=0; @@ -3365,7 +3368,8 @@ abstract class CommonObject function printObjectLine($action,$line,$var,$num,$i,$dateSelector,$seller,$buyer,$selected=0,$extrafieldsline=0) { global $conf,$langs,$user,$object,$hookmanager; - global $form,$bc,$bcdd, $object_rights; + global $form,$bc,$bcdd; + global $object_rights, $disableedit, $disablemove; // TODO We should not use global var for this ! $object_rights = $this->getRights(); @@ -4247,7 +4251,7 @@ abstract class CommonObject if (! empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) return 0; // For avoid conflicts if trigger used - if (! empty($this->array_options) && !empty($this->array_options["options_$key"])) + if (! empty($this->array_options) && isset($this->array_options["options_".$key])) { // Check parameters $langs->load('admin'); @@ -4255,7 +4259,7 @@ abstract class CommonObject $extrafields = new ExtraFields($this->db); $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); - $value=$this->array_options["options_$key"]; + $value=$this->array_options["options_".$key]; $attributeType = $extrafields->attribute_type[$key]; $attributeLabel = $extrafields->attribute_label[$key]; $attributeParam = $extrafields->attribute_param[$key]; @@ -4269,17 +4273,17 @@ abstract class CommonObject } elseif ($value=='') { - $this->array_options["options_$key"] = null; + $this->array_options["options_".$key] = null; } break; case 'price': - $this->array_options["options_$key"] = price2num($this->array_options["options_$key"]); + $this->array_options["options_".$key] = price2num($this->array_options["options_".$key]); break; case 'date': - $this->array_options["options_$key"]=$this->db->idate($this->array_options["options_$key"]); + $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); break; case 'datetime': - $this->array_options["options_$key"]=$this->db->idate($this->array_options["options_$key"]); + $this->array_options["options_".$key]=$this->db->idate($this->array_options["options_".$key]); break; case 'link': $param_list=array_keys($attributeParam ['options']); @@ -4291,13 +4295,13 @@ abstract class CommonObject if ($value) { $object->fetch(0,$value); - $this->array_options["options_$key"]=$object->id; + $this->array_options["options_".$key]=$object->id; } break; } $this->db->begin(); - $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element."_extrafields SET $key='".$this->db->escape($this->array_options["options_$key"])."'"; + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element."_extrafields SET ".$key."='".$this->db->escape($this->array_options["options_".$key])."'"; $sql .= " WHERE fk_object = ".$this->id; $resql = $this->db->query($sql); if (! $resql) @@ -4458,7 +4462,10 @@ abstract class CommonObject { global $user; - return $user->rights->{$this->element}; + $element = $this->element; + if ($element == 'facturerec') $element='facture'; + + return $user->rights->{$element}; } /** @@ -4555,7 +4562,7 @@ abstract class CommonObject $productFournisseur = new ProductFournisseur($this->db); if (($result = $productFournisseur->find_min_price_product_fournisseur($fk_product)) > 0) { - $buyPrice = $productFournisseur->fourn_price; + $buyPrice = $productFournisseur->fourn_unitprice; } else if ($result < 0) { diff --git a/htdocs/core/class/doleditor.class.php b/htdocs/core/class/doleditor.class.php index 8564a18822e..ff31823976e 100644 --- a/htdocs/core/class/doleditor.class.php +++ b/htdocs/core/class/doleditor.class.php @@ -52,7 +52,7 @@ class DolEditor * @param string $content Content of WYSIWIG field * @param int $width Width in pixel of edit area (auto by default) * @param int $height Height in pixel of edit area (200px by default) - * @param string $toolbarname Name of bar set to use ('Full', 'dolibarr_notes[_encoded]', 'dolibarr_details[_encoded]'=the less featured, 'dolibarr_mailings[_encoded]', ') + * @param string $toolbarname Name of bar set to use ('Full', 'dolibarr_notes[_encoded]', 'dolibarr_details[_encoded]'=the less featured, 'dolibarr_mailings[_encoded]', 'dolibarr_readonly') * @param string $toolbarlocation Where bar is stored : * 'In' each window has its own toolbar * 'Out:name' share toolbar into the div called 'name' @@ -148,7 +148,10 @@ class DolEditor { global $conf,$langs; - $found=0; + $fullpage=False; + $disallowAnyContent=empty($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT); // Only predefined list of html tags are allowed + + $found=0; $out=''; if ($this->tool == 'fckeditor') @@ -186,7 +189,8 @@ class DolEditor customConfig : ckeditorConfig, readOnly : '.($this->readonly?'true':'false').', htmlEncodeOutput :'.$htmlencode_force.', - allowedContent :'.(empty($conf->global->FCKEDITOR_ALLOW_ANY_CONTENT)?'false':'true').', + allowedContent :'.($disallowAnyContent?'false':'true').', + fullPage : '.($fullpage?'true':'false').', toolbar: \''.$this->toolbarname.'\', toolbarStartupExpanded: '.($this->toolbarstartexpanded ? 'true' : 'false').', width: '.($this->width ? '\''.$this->width.'\'' : '\'\'').', diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 97645487d45..8d61733e138 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -63,7 +63,7 @@ class ExtraFields var $errno; var $attribute_hidden; - + public static $type2label=array( 'varchar'=>'String', 'text'=>'TextLong', @@ -665,6 +665,7 @@ class ExtraFields $param=$this->attribute_param[$key]; $perms=$this->attribute_perms[$key]; $list=$this->attribute_list[$key]; + $hidden=$this->attribute_hidden[$key]; if (empty($showsize)) { @@ -686,7 +687,7 @@ class ExtraFields if ($showsize > 48) $showsize=48; } } - + if (in_array($type,array('date','datetime'))) { $tmp=explode(',',$size); @@ -823,7 +824,7 @@ class ExtraFields if (strpos($InfoFieldList[4], '$SEL$')!==false) { $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]); } - + // current object id can be use into filter if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) { $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]); @@ -841,14 +842,14 @@ class ExtraFields $sqlwhere.= ' WHERE '.$InfoFieldList[4]; } } - else + else { $sqlwhere.= ' WHERE 1=1'; } // Some tables may have field, some other not. For the moment we disable it. - if (in_array($InfoFieldList[0],array('tablewithentity'))) + if (in_array($InfoFieldList[0],array('tablewithentity'))) { - $sqlwhere.= ' AND entity = '.$conf->entity; + $sqlwhere.= ' AND entity = '.$conf->entity; } $sql.=$sqlwhere; //print $sql; @@ -1007,19 +1008,19 @@ class ExtraFields $sql = 'SELECT ' . $keyList; $sql .= ' FROM ' . MAIN_DB_PREFIX . $InfoFieldList[0]; if (! empty($InfoFieldList[4])) { - + // can use SELECT request if (strpos($InfoFieldList[4], '$SEL$')!==false) { $InfoFieldList[4]=str_replace('$SEL$','SELECT',$InfoFieldList[4]); } - + // current object id can be use into filter if (strpos($InfoFieldList[4], '$ID$')!==false && !empty($objectid)) { $InfoFieldList[4]=str_replace('$ID$',$objectid,$InfoFieldList[4]); } else { $InfoFieldList[4]=str_replace('$ID$','0',$InfoFieldList[4]); } - + // We have to join on extrafield table if (strpos($InfoFieldList[4], 'extra') !== false) { $sql .= ' as main, ' . MAIN_DB_PREFIX . $InfoFieldList[0] . '_extrafields as extra'; @@ -1031,13 +1032,13 @@ class ExtraFields $sqlwhere .= ' WHERE 1=1'; } // Some tables may have field, some other not. For the moment we disable it. - if (in_array($InfoFieldList[0], array ('tablewithentity'))) + if (in_array($InfoFieldList[0], array ('tablewithentity'))) { $sqlwhere .= ' AND entity = ' . $conf->entity; } // $sql.=preg_replace('/^ AND /','',$sqlwhere); // print $sql; - + $sql .= $sqlwhere; dol_syslog(get_class($this) . '::showInputField type=chkbxlst',LOG_DEBUG); $resql = $this->db->query($sql); @@ -1143,6 +1144,9 @@ class ExtraFields $out.='Error bad setup of extrafield'; } } + if (!empty($hidden)) { + $out=''; + } /* Add comments if ($type == 'date') $out.=' (YYYY-MM-DD)'; elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)'; @@ -1171,6 +1175,7 @@ class ExtraFields $params=$this->attribute_param[$key]; $perms=$this->attribute_perms[$key]; $list=$this->attribute_list[$key]; + $hidden=$this->attribute_hidden[$key]; $showsize=0; if ($type == 'date') @@ -1402,10 +1407,14 @@ class ExtraFields $showsize=round($size); if ($showsize > 48) $showsize=48; } - + //print $type.'-'.$size; $out=$value; - + + if (!empty($hidden)) { + $out=''; + } + return $out; } @@ -1422,7 +1431,7 @@ class ExtraFields $type=$this->attribute_type[$key]; $align=''; - + if ($type == 'date') { $align="center"; @@ -1451,10 +1460,10 @@ class ExtraFields { $align="center"; } - + return $align; } - + /** * Return HTML string to print separator extrafield * @@ -1534,7 +1543,7 @@ class ExtraFields return 0; } } - + /** * return array_options array for object by extrafields value (using for data send by forms) * diff --git a/htdocs/core/class/fiscalyear.class.php b/htdocs/core/class/fiscalyear.class.php index 7d4dff8de44..ef990d8edf3 100644 --- a/htdocs/core/class/fiscalyear.class.php +++ b/htdocs/core/class/fiscalyear.class.php @@ -39,6 +39,7 @@ class Fiscalyear extends CommonObject var $label; var $date_start; var $date_end; + var $datec; var $statut; // 0=open, 1=closed var $entity; diff --git a/htdocs/core/class/hookmanager.class.php b/htdocs/core/class/hookmanager.class.php index f92056893b6..484b6518f77 100644 --- a/htdocs/core/class/hookmanager.class.php +++ b/htdocs/core/class/hookmanager.class.php @@ -135,6 +135,7 @@ class HookManager $method, array( 'addMoreActionsButtons', + 'addSearchEntry', 'addStatisticLine', 'deleteFile', 'doActions', diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 697e5e8bdeb..74cd27bc460 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -390,6 +390,7 @@ class Form * @param int $noencodehtmltext Do not encode into html entity the htmltext * @return string Code html du tooltip (texte+picto) * @see Use function textwithpicto if you can. + * TODO Move this as static as soon as everybody use textwithpicto or @Form::textwithtooltip */ function textwithtooltip($text, $htmltext, $tooltipon = 1, $direction = 0, $img = '', $extracss = '', $notabs = 2, $incbefore = '', $noencodehtmltext = 0) { @@ -2057,17 +2058,27 @@ class Form { global $langs,$conf; global $price_level, $status, $finished; - + + $selected_input_value=''; if (! empty($conf->use_javascript_ajax) && ! empty($conf->global->PRODUIT_USE_SEARCH_TO_SELECT)) { + if ($selected > 0) + { + require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; + $producttmpselect = new Product($this->db); + $producttmpselect->fetch($selected); + $selected_input_value=$producttmpselect->ref; + unset($producttmpselect); + } + if (!empty($conf->global->SUPPLIER_ORDER_WITH_NOPRICEDEFINED)) { print ''; } // mode=2 means suppliers products $urloption=($socid > 0?'socid='.$socid.'&':'').'htmlname='.$htmlname.'&outjson=1&price_level='.$price_level.'&type='.$filtertype.'&mode=2&status='.$status.'&finished='.$finished; - print ajax_autocompleter('', $htmlname, DOL_URL_ROOT.'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); - print ($hidelabel?'':$langs->trans("RefOrLabel").' : ').''; + print ajax_autocompleter($selected, $htmlname, DOL_URL_ROOT.'/product/ajax/products.php', $urloption, $conf->global->PRODUIT_USE_SEARCH_TO_SELECT, 0, $ajaxoptions); + print ($hidelabel?'':$langs->trans("RefOrLabel").' : ').''; } else { @@ -2089,7 +2100,7 @@ class Form * @param string $filtertype Filter on product type (''=nofilter, 0=product, 1=service) * @param string $filtre Pour filtre sql * @param string $filterkey Filtre des produits - * @param int $statut -1=Return all products, 0=Products not on sell, 1=Products on sell + * @param int $statut -1=Return all products, 0=Products not on sell, 1=Products on sell (not used here, a filter on tobuy is already hard coded in request) * @param int $outputmode 0=HTML select string, 1=Array * @param int $limit Limit of line number * @return array Array of keys for json @@ -2106,7 +2117,7 @@ class Form $sql = "SELECT p.rowid, p.label, p.ref, p.price, p.duration, p.fk_product_type,"; $sql.= " pfp.ref_fourn, pfp.rowid as idprodfournprice, pfp.price as fprice, pfp.quantity, pfp.remise_percent, pfp.remise, pfp.unitprice,"; $sql.= " pfp.fk_supplier_price_expression, pfp.fk_product, pfp.tva_tx, pfp.fk_soc, s.nom as name,"; - $sql.= " pfp.supplier_reputation"; + $sql.= " pfp.supplier_reputation"; $sql.= " FROM ".MAIN_DB_PREFIX."product as p"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_fournisseur_price as pfp ON p.rowid = pfp.fk_product"; if ($socid) $sql.= " AND pfp.fk_soc = ".$socid; @@ -2390,10 +2401,10 @@ class Form $form.= $opt; $i++; } - $form.= ''; - - $this->db->free($result); } + + $form.= ''; + $this->db->free($result); return $form; } else @@ -5239,7 +5250,7 @@ class Form * * @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') - * @return int <0 if KO, >0 if OK + * @return string <0 if KO, >0 if OK */ function showLinkToObjectBlock($object, $restrictlinksto=array()) { @@ -5457,7 +5468,7 @@ class Form * @param int $option 0 return yes/no, 1 return 1/0 * @param bool $disabled true or false * @param int $useempty 1=Add empty line - * @return mixed See option + * @return string See option */ function selectyesno($htmlname,$value='',$option=0,$disabled=false,$useempty='') { @@ -5799,7 +5810,7 @@ class Form * @param string $include Array list of groups id to include * @param int $enableonly Array list of groups id to be enabled. All other must be disabled * @param int $force_entity 0 or Id of environment to force - * @return void + * @return string * @see select_dolusers */ function select_dolgroups($selected='', $htmlname='groupid', $show_empty=0, $exclude='', $disabled=0, $include='', $enableonly='', $force_entity=0) diff --git a/htdocs/core/class/html.formaccounting.class.php b/htdocs/core/class/html.formaccounting.class.php index 04d643d4b2f..9abf943d948 100644 --- a/htdocs/core/class/html.formaccounting.class.php +++ b/htdocs/core/class/html.formaccounting.class.php @@ -82,7 +82,7 @@ class FormAccounting $sql.= " ORDER BY c.label ASC"; } - dol_syslog("Form::select_accounting_category", LOG_DEBUG); + dol_syslog(get_class($this).'::'.__METHOD__, LOG_DEBUG); $resql=$db->query($sql); if ($resql) { diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index 5af984ba659..f446caa12a2 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -805,6 +805,7 @@ class FormOther $select_week .= ''; } $select_week .= ''; return $select_week; @@ -844,6 +845,7 @@ class FormOther $select_month .= ''; } $select_month .= ''; return $select_month; diff --git a/htdocs/core/class/html.formprojet.class.php b/htdocs/core/class/html.formprojet.class.php index c532fd799bd..f160e4cd500 100644 --- a/htdocs/core/class/html.formprojet.class.php +++ b/htdocs/core/class/html.formprojet.class.php @@ -138,7 +138,7 @@ class FormProjets $sql.= " WHERE p.entity IN (".getEntity('project', 1).")"; if ($projectsListId !== false) $sql.= " AND p.rowid IN (".$projectsListId.")"; if ($socid == 0) $sql.= " AND (p.fk_soc=0 OR p.fk_soc IS NULL)"; - if ($socid > 0) $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)"; + if ($socid > 0 && empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY)) $sql.= " AND (p.fk_soc=".$socid." OR p.fk_soc IS NULL)"; if (!empty($filterkey)) { $sql .= ' AND p.title LIKE "%'.$this->db->escape($filterkey).'%"'; $sql .= ' OR p.ref LIKE "%'.$this->db->escape($filterkey).'%"'; @@ -204,7 +204,7 @@ class FormProjets if ($discard_close == 2) $disabled=1; $labeltoshow.=' - '.$langs->trans("Closed"); } - else if ($socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid)) + else if ( empty($conf->global->PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY) && $socid > 0 && (! empty($obj->fk_soc) && $obj->fk_soc != $socid)) { $disabled=1; $labeltoshow.=' - '.$langs->trans("LinkedToAnotherCompany"); diff --git a/htdocs/core/class/translate.class.php b/htdocs/core/class/translate.class.php index 866b746362b..34858bc3234 100644 --- a/htdocs/core/class/translate.class.php +++ b/htdocs/core/class/translate.class.php @@ -908,7 +908,8 @@ class Translate } /** - * Return a currency code into its symbol + * Return a currency code into its symbol. + * If mb_convert_encoding is not available, return currency code. * * @param string $currency_code Currency code * @param integer $forceloadall 1=Force to load all currencies into cache. We know we need to use all of them. By default read and cache only required currency. diff --git a/htdocs/core/filemanagerdol/browser/default/browser.php b/htdocs/core/filemanagerdol/browser/default/browser.php index f542bdf59b6..15e44621bcf 100644 --- a/htdocs/core/filemanagerdol/browser/default/browser.php +++ b/htdocs/core/filemanagerdol/browser/default/browser.php @@ -19,15 +19,20 @@ * along with this program. If not, see . */ -define('NOTOKENRENEWAL',1); // Disables token renewal +//define('NOTOKENRENEWAL',1); // Disables token renewal +//require '../../../../main.inc.php'; +require '../../connectors/php/config.php'; // This include the define('NOTOKENRENEWAL',1) and the require main.in.php + +global $Config; + + -require '../../../../main.inc.php'; ?> - FCKeditor - Resources Browser + <?php echo $langs->trans("MediaBrowser").' - '.$Config['UserFilesAbsolutePathRelative']; ?> diff --git a/htdocs/core/tpl/objectline_view.tpl.php b/htdocs/core/tpl/objectline_view.tpl.php index c264bac205d..559cae91464 100644 --- a/htdocs/core/tpl/objectline_view.tpl.php +++ b/htdocs/core/tpl/objectline_view.tpl.php @@ -30,7 +30,9 @@ * $senderissupplier (0 by default, 1 for supplier invoices/orders) * $inputalsopricewithtax (0 by default, 1 to also show column with unit price including tax) * $usemargins (0 to disable all margins columns, 1 to show according to margin setup) - * + * $object_rights->creer initialized from = $object->getRights() + * $disableedit, $disablemove, $disableremove + * * $type, $text, $description, $line */ @@ -44,7 +46,6 @@ if (empty($forceall)) $forceall=0; if (empty($senderissupplier)) $senderissupplier=0; if (empty($inputalsopricewithtax)) $inputalsopricewithtax=0; if (empty($usemargins)) $usemargins=0; - ?> @@ -201,9 +202,10 @@ if (empty($usemargins)) $usemargins=0; - statut == 0 && ($object_rights->creer)) { ?> + statut == 0 && ($object_rights->creer)) { ?> - info_bits & 2) == 2) { ?> + info_bits & 2) == 2 || ! empty($disableedit)) { ?> id.'#line_'.$line->id; ?>"> @@ -213,7 +215,7 @@ if (empty($usemargins)) $usemargins=0; situation_counter == 1 || !$this->situation_cycle_ref) { + if (($this->situation_counter == 1 || !$this->situation_cycle_ref) && empty($disableremove)) { print 'id . '">'; print img_delete(); print ''; @@ -221,7 +223,8 @@ if (empty($usemargins)) $usemargins=0; ?> - 1 && empty($conf->browser->phone) && ($this->situation_counter == 1 || !$this->situation_cycle_ref)) { ?> + 1 && empty($conf->browser->phone) && ($this->situation_counter == 1 || !$this->situation_cycle_ref) && empty($disablemove)) { ?> 0) { ?> id; ?>"> @@ -235,7 +238,7 @@ if (empty($usemargins)) $usemargins=0; - browser->phone)?' class="linecolmove tdlineupdown"':' class="linecolmove"'); ?>> + browser->phone) && empty($disablemove)) ?' class="linecolmove tdlineupdown"':' class="linecolmove"'); ?>> diff --git a/htdocs/core/tpl/resource_add.tpl.php b/htdocs/core/tpl/resource_add.tpl.php index e2add5fb266..482dad50085 100644 --- a/htdocs/core/tpl/resource_add.tpl.php +++ b/htdocs/core/tpl/resource_add.tpl.php @@ -13,7 +13,7 @@ $out .= ''; $out .= ''; $out .= ''; $out .= ''; -$out .= ''; +$out .= ''; // Place diff --git a/htdocs/custom/README.md b/htdocs/custom/README.md index 5f15148f685..82f92dfbeff 100644 --- a/htdocs/custom/README.md +++ b/htdocs/custom/README.md @@ -14,11 +14,9 @@ Then create the symbolic link ln -fs ~/git/newmodule/htdocs /path_to_dolibarr/htdocs/custom/newmodule WARNING !!! -You must also enable the custom directory into dolibarr conf/conf.php file by adding the following +Check also that the custom directory into dolibarr conf/conf.php file by adding the following two lines, so dolibarr will also scan this directories to find external external modules: $dolibarr_main_url_root_alt='/custom'; $dolibarr_main_document_root_alt='/path_to_dolibarr/htdocs/custom/'; -(This is not enabled by default because enabling external module may slow down application) - diff --git a/htdocs/document.php b/htdocs/document.php index 1b3d494d1a1..52b1584e7af 100644 --- a/htdocs/document.php +++ b/htdocs/document.php @@ -65,6 +65,7 @@ $entity=GETPOST('entity')?GETPOST('entity','int'):$conf->entity; // Security check if (empty($modulepart)) accessforbidden('Bad value for parameter modulepart'); +if ($modulepart == 'fckeditor') $modulepart='medias'; // For backward compatibility $socid=0; if ($user->societe_id > 0) $socid = $user->societe_id; @@ -97,7 +98,7 @@ if (preg_match('/\.(html|htm)$/i',$original_file)) $attachment = false; if (isset($_GET["attachment"])) $attachment = GETPOST("attachment")?true:false; if (! empty($conf->global->MAIN_DISABLE_FORCE_SAVEAS)) $attachment=false; -// Suppression de la chaine de caractere ../ dans $original_file +// Security: Delete string ../ into $original_file $original_file = str_replace("../","/", $original_file); // Find the subdirectory name as the reference @@ -169,7 +170,6 @@ if (! file_exists($original_file_osencoded)) } // Permissions are ok and file found, so we return it - header('Content-Description: File Transfer'); if ($encoding) header('Content-Encoding: '.$encoding); if ($type) header('Content-Type: '.$type.(preg_match('/text/',$type)?'; charset="'.$conf->file->character_set_client:'')); @@ -183,7 +183,7 @@ header('Pragma: public'); //ob_clean(); //flush(); - + readfile($original_file_osencoded); if (is_object($db)) $db->close(); diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index 4547a94566a..b4b82be7726 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -533,6 +533,12 @@ if (empty($reshook)) $object->set_billed(); } + elseif ($action == 'classifyclosed') + { + $object->fetch($id); + $object->setClosed(); + } + include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; // Actions to send emails @@ -885,6 +891,7 @@ if ($action == 'create') //ship from preselected location $stock = + $product->stock_warehouse[$warehouse_id]->real; // Convert to number $deliverableQty=min($quantityToBeDelivered, $stock); + if ($deliverableQty < 0) $deliverableQty = 0; if (empty($conf->productbatch->enabled) || ! ($product->hasbatch() && is_object($product->stock_warehouse[$warehouse_id]))) { // Quantity to send @@ -1729,69 +1736,80 @@ else if ($id || $ref) { print '
'; - if ($object->statut == 0 && $num_prod > 0) + $parameters = array(); + $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been + // modified by hook + if (empty($reshook)) { - if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->creer)) - || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->shipping_advance->validate))) - { - print ''.$langs->trans("Validate").''; - } - else - { - print ''.$langs->trans("Validate").''; - } - } - // TODO add alternative status - // 0=draft, 1=validated, 2=billed, we miss a status "delivered" (only available on order) - if ($object->statut == 2 && $object->billed && $user->rights->expedition->creer) - { - print ''.$langs->trans("ReOpen").''; + if ($object->statut == 0 && $num_prod > 0) + { + if ((empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->creer)) + || (! empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ! empty($user->rights->expedition->shipping_advance->validate))) + { + print ''.$langs->trans("Validate").''; + } + else + { + print ''.$langs->trans("Validate").''; + } + } + + // TODO add alternative status + // 0=draft, 1=validated, 2=billed, we miss a status "delivered" (only available on order) + if ($object->statut == 2 && $object->billed && $user->rights->expedition->creer) + { + print ''.$langs->trans("ReOpen").''; + } + + // Send + if ($object->statut > 0) + { + if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->expedition->shipping_advance->send) + { + print ''.$langs->trans('SendByMail').''; + } + else print ''.$langs->trans('SendByMail').''; + } + + // Create bill and Close shipment + if (! empty($conf->facture->enabled) && $object->statut > 0) + { + if ($user->rights->facture->creer) + { + print ''.$langs->trans("CreateBill").''; + } + } + + // This is just to generate a delivery receipt + //var_dump($object->linkedObjectsIds['delivery']); + if ($conf->livraison_bon->enabled && ($object->statut == 1 || $object->statut == 2) && $user->rights->expedition->livraison->creer && count($object->linkedObjectsIds['delivery']) == 0) + { + print ''.$langs->trans("CreateDeliveryOrder").''; + } + // Close + if (! empty($conf->facture->enabled) && $object->statut > 0) + { + if ($user->rights->expedition->creer && $object->statut > 0 && ! $object->billed) + { + $label="Close"; $paramaction='classifyclosed'; // = Transferred/Received + // Label here should be "Close" or "ClassifyBilled" if we decided to make bill on shipments instead of orders + if (! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) // TODO Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close. + { + $label="ClassifyBilled"; + $paramaction='classifybilled'; + } + print ''.$langs->trans($label).''; + } + } + + if ($user->rights->expedition->supprimer) + { + print ''.$langs->trans("Delete").''; + } + } - // Send - if ($object->statut > 0) - { - if (empty($conf->global->MAIN_USE_ADVANCED_PERMS) || $user->rights->expedition->shipping_advance->send) - { - print ''.$langs->trans('SendByMail').''; - } - else print ''.$langs->trans('SendByMail').''; - } - - // Create bill and Close shipment - if (! empty($conf->facture->enabled) && $object->statut > 0) - { - if ($user->rights->facture->creer) - { - print ''.$langs->trans("CreateBill").''; - } - } - - // This is just to generate a delivery receipt - //var_dump($object->linkedObjectsIds['delivery']); - if ($conf->livraison_bon->enabled && ($object->statut == 1 || $object->statut == 2) && $user->rights->expedition->livraison->creer && count($object->linkedObjectsIds['delivery']) == 0) - { - print ''.$langs->trans("CreateDeliveryOrder").''; - } - - // Close - if (! empty($conf->facture->enabled) && $object->statut > 0) - { - if ($user->rights->expedition->creer && $object->statut > 0 && ! $object->billed) - { - $label="Close"; - // Label here should be "Close" or "ClassifyBilled" if we decided to make bill on shipments instead of orders - if (! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) $label="ClassifyBilled"; - print ''.$langs->trans($label).''; - } - } - - if ($user->rights->expedition->supprimer) - { - print ''.$langs->trans("Delete").''; - } - print '
'; } diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index a0ba1567c24..35ef726be20 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -3,7 +3,7 @@ * Copyright (C) 2005-2012 Regis Houssin * Copyright (C) 2007 Franky Van Liedekerke * Copyright (C) 2006-2012 Laurent Destailleur - * Copyright (C) 2011-2015 Juanjo Menent + * Copyright (C) 2011-2016 Juanjo Menent * Copyright (C) 2013 Florian Henry * Copyright (C) 2014 Cedric GROSS * Copyright (C) 2014-2015 Marcos García @@ -90,6 +90,7 @@ class Expedition extends CommonObject var $date_creation; var $date_valid; + var $meths; var $listmeths; // List of carriers /** @@ -119,7 +120,7 @@ class Expedition extends CommonObject */ function getNextNumRef($soc) { - global $db, $langs, $conf; + global $langs, $conf; $langs->load("sendings"); if (!empty($conf->global->EXPEDITION_ADDON_NUMBER)) @@ -156,7 +157,7 @@ class Expedition extends CommonObject } else { - dol_print_error($db,get_class($this)."::getNextNumRef ".$obj->error); + dol_print_error($this->db,get_class($this)."::getNextNumRef ".$obj->error); return ""; } } @@ -176,7 +177,7 @@ class Expedition extends CommonObject */ function create($user, $notrigger=0) { - global $conf, $langs, $hookmanager; + global $conf, $hookmanager; $now=dol_now(); @@ -664,7 +665,7 @@ class Expedition extends CommonObject $langs->load("agenda"); // Loop on each product line to add a stock movement - // TODO possibilite d'expedier a partir d'une propale ou autre origine + // TODO in future, shipment lines may not be linked to order line $sql = "SELECT cd.fk_product, cd.subprice,"; $sql.= " ed.rowid, ed.qty, ed.fk_entrepot,"; $sql.= " edb.rowid as edbrowid, edb.eatby, edb.sellby, edb.batch, edb.qty as edbqty, edb.fk_origin_stock"; @@ -738,7 +739,7 @@ class Expedition extends CommonObject if (! $error && ! $notrigger) { // Call trigger - $result=$this->call_trigger('SHIPPING_VALIDATE',$user); + $result=$this->call_trigger('SHIPPING_VALIDATE',$user); // TODO Add option in workflow module on this trigger to close order if sum of shipment = product to ship of order if ($result < 0) { $error++; } // End call triggers } @@ -878,16 +879,14 @@ class Expedition extends CommonObject $product=new Product($this->db); $result=$product->fetch($fk_product); - $product_type=$product->type; if ($entrepot_id > 0) { - $product->load_stock(); - $product_stock = $product->stock_warehouse[$entrepot_id]->real; + $product->load_stock(); + $product_stock = $product->stock_warehouse[$entrepot_id]->real; } - else - { - $product_stock = $product->stock_reel; - } - + else + $product_stock = $product->stock_reel; + + $product_type=$product->type; if ($product_type == 0 && $product_stock < $qty) { $this->error=$langs->trans('ErrorStockIsNotEnough'); @@ -980,7 +979,7 @@ class Expedition extends CommonObject */ function update($user=null, $notrigger=0) { - global $conf, $langs; + global $conf; $error=0; // Clean parameters @@ -1534,7 +1533,7 @@ class Expedition extends CommonObject */ function initAsSpecimen() { - global $user,$langs,$conf; + global $langs; $now=dol_now(); @@ -1646,7 +1645,7 @@ class Expedition extends CommonObject function fetch_delivery_methods() { global $langs; - $meths = array(); + $this->meths = array(); $sql = "SELECT em.rowid, em.code, em.libelle"; $sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode as em"; @@ -1795,13 +1794,12 @@ class Expedition extends CommonObject } /** - * Classify the shipping as invoiced + * Classify the shipping as closed * * @return int <0 if ko, >0 if ok */ - function set_billed() + function setClosed() { - global $conf; $sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=2'; $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0'; @@ -1809,7 +1807,31 @@ class Expedition extends CommonObject $resql=$this->db->query($sql); if ($resql) { - //TODO: Add option/checkbox to set order billed if 100% of order is shipped + // TODO: Add option/checkbox to set order billed if 100% of order is shipped + $this->statut=2; + return 1; + } + else + { + dol_print_error($this->db); + return -1; + } + } + + /** + * Classify the shipping as invoiced (used when WORKFLOW_BILL_ON_SHIPMENT is on) + * + * @return int <0 if ko, >0 if ok + */ + function set_billed() + { + + $sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=2, billed=1'; // TODO Update only billed + $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0'; + + $resql=$this->db->query($sql); + if ($resql) + { $this->statut=2; $this->billed=1; return 1; @@ -1828,7 +1850,6 @@ class Expedition extends CommonObject */ function reOpen() { - global $conf; $sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=1'; $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0'; @@ -1859,7 +1880,7 @@ class Expedition extends CommonObject */ public function generateDocument($modele, $outputlangs,$hidedetails=0, $hidedesc=0, $hideref=0) { - global $conf,$user,$langs; + global $conf,$langs; $langs->load("sendings"); diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index be9d8ab49bd..a946649592a 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -1625,7 +1625,7 @@ else $sql.= ' ctf.code as type_fees_code, ctf.label as type_fees_libelle,'; $sql.= ' pjt.rowid as projet_id, pjt.title as projet_title, pjt.ref as projet_ref'; $sql.= ' FROM '.MAIN_DB_PREFIX.'expensereport_det as fde'; - $sql.= ' INNER JOIN '.MAIN_DB_PREFIX.'c_type_fees as ctf ON fde.fk_c_type_fees=ctf.id'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_type_fees as ctf ON fde.fk_c_type_fees=ctf.id'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pjt ON fde.fk_projet=pjt.rowid'; $sql.= ' WHERE fde.fk_expensereport = '.$object->id; @@ -1691,7 +1691,7 @@ else } print ''; } - print ''.$langs->trans("TF_".strtoupper($objp->type_fees_libelle)).''; + print ''.$langs->trans("TF_".strtoupper(empty($objp->type_fees_libelle)?'OTHER':$objp->type_fees_libelle)).''; print ''.$objp->comments.''; print ''.vatrate($objp->vatrate,true).''; print ''.price($objp->value_unit).''; diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index 2a281bda595..07c3e598818 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -746,7 +746,7 @@ class ExpenseReport extends CommonObject $sql.= ' ctf.code as code_type_fees, ctf.label as libelle_type_fees,'; $sql.= ' p.ref as ref_projet, p.title as title_projet'; $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element_line.' as de'; - $sql.= ' INNER JOIN '.MAIN_DB_PREFIX.'c_type_fees as ctf ON de.fk_c_type_fees = ctf.id'; + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_type_fees as ctf ON de.fk_c_type_fees = ctf.id'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as p ON de.fk_projet = p.rowid'; $sql.= ' WHERE de.'.$this->fk_element.' = '.$this->id; @@ -776,7 +776,7 @@ class ExpenseReport extends CommonObject $deplig->total_tva = $objp->total_tva; $deplig->total_ttc = $objp->total_ttc; - $deplig->type_fees_code = $objp->code_type_fees; + $deplig->type_fees_code = empty($objp->code_type_fees)?'TF_OTHER':$objp->code_type_fees; $deplig->type_fees_libelle = $objp->libelle_type_fees; $deplig->tva_tx = $objp->tva_tx; $deplig->vatrate = $objp->tva_tx; @@ -850,12 +850,9 @@ class ExpenseReport extends CommonObject { global $conf,$langs; + $this->oldref = $this->ref; $expld_car = (empty($conf->global->NDF_EXPLODE_CHAR))?"-":$conf->global->NDF_EXPLODE_CHAR; - // Sélection du numéro de ref suivant - $ref_next = $this->getNextNumRef(); - $ref_number_int = ($this->ref+1)-1; - // Sélection de la date de début de la NDF $sql = 'SELECT date_debut'; $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element; @@ -864,21 +861,59 @@ class ExpenseReport extends CommonObject $objp = $this->db->fetch_object($result); $this->date_debut = $this->db->jdate($objp->date_debut); - // Création du ref_number suivant - if($ref_next) + $update_number_int = false; + + // Create next ref if ref is PROVxx + // Rename directory if dir was a temporary ref + if (preg_match('/^[\(]?PROV/i', $this->ref)) { - $prefix="ER"; - if (! empty($conf->global->EXPENSE_REPORT_PREFIX)) $prefix=$conf->global->EXPENSE_REPORT_PREFIX; - $this->ref = strtoupper($fuser->login).$expld_car.$prefix.$this->ref.$expld_car.dol_print_date($this->date_debut,'%y%m%d'); + // Sélection du numéro de ref suivant + $ref_next = $this->getNextNumRef(); + $ref_number_int = ($this->ref+1)-1; + $update_number_int = true; + // Création du ref_number suivant + if($ref_next) + { + $prefix="ER"; + if (! empty($conf->global->EXPENSE_REPORT_PREFIX)) $prefix=$conf->global->EXPENSE_REPORT_PREFIX; + $this->ref = strtoupper($fuser->login).$expld_car.$prefix.$this->ref.$expld_car.dol_print_date($this->date_debut,'%y%m%d'); + } + require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + // We rename directory in order to avoid losing the attachments + $oldref = dol_sanitizeFileName($this->oldref); + $newref = dol_sanitizeFileName($this->ref); + $dirsource = $conf->expensereport->dir_output.'/'.$oldref; + $dirdest = $conf->expensereport->dir_output.'/'.$newref; + if (file_exists($dirsource)) + { + dol_syslog(get_class($this)."::valid() rename dir ".$dirsource." into ".$dirdest); + + if (@rename($dirsource, $dirdest)) + { + dol_syslog("Rename ok"); + // Rename docs starting with $oldref with $newref + $listoffiles=dol_dir_list($conf->expensereport->dir_output.'/'.$newref, 'files', 1, '^'.preg_quote($oldref,'/')); + foreach($listoffiles as $fileentry) + { + $dirsource=$fileentry['name']; + $dirdest=preg_replace('/^'.preg_quote($oldref,'/').'/',$newref, $dirsource); + $dirsource=$fileentry['path'].'/'.$dirsource; + $dirdest=$fileentry['path'].'/'.$dirdest; + @rename($dirsource, $dirdest); + } + } + } } if ($this->fk_statut != 2) { $now = dol_now(); - + $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - $sql.= " SET ref = '".$this->ref."', fk_statut = 2, fk_user_valid = ".$fuser->id.", date_valid='".$this->db->idate($now)."',"; - $sql.= " ref_number_int = ".$ref_number_int; + $sql.= " SET ref = '".$this->ref."', fk_statut = 2, fk_user_valid = ".$fuser->id.", date_valid='".$this->db->idate($now)."'"; + if ($update_number_int) { + $sql.= ", ref_number_int = ".$ref_number_int; + } $sql.= ' WHERE rowid = '.$this->id; $resql=$this->db->query($sql); @@ -1265,7 +1300,9 @@ class ExpenseReport extends CommonObject $sql.= " FROM ".MAIN_DB_PREFIX."projet as p"; $sql.= " WHERE p.rowid = ".$projet_id; $result = $this->db->query($sql); - $objp_projet = $this->db->fetch_object($result); + if ($result) { + $objp_projet = $this->db->fetch_object($result); + } $ligne->projet_ref = $objp_projet->ref_projet; $ligne->projet_title = $objp_projet->title_projet; diff --git a/htdocs/exports/class/export.class.php b/htdocs/exports/class/export.class.php index 7912b4f189f..6632f050550 100644 --- a/htdocs/exports/class/export.class.php +++ b/htdocs/exports/class/export.class.php @@ -225,7 +225,7 @@ class Export else $i++; if (strpos($key, ' as ')===false) { - $newfield=$key.' as '.str_replace(array('.', '-'),'_',$key); + $newfield=$key.' as '.str_replace(array('.', '-','(',')'),'_',$key); } else { $newfield=$key; } @@ -587,14 +587,14 @@ class Export if ($this->array_export_special[$indice][$key]=='NULLIFNEG') { //$alias=$this->array_export_alias[$indice][$key]; - $alias=str_replace(array('.', '-'),'_',$key); + $alias=str_replace(array('.', '-','(',')'),'_',$key); if ($objp->$alias < 0) $objp->$alias=''; } // Operation ZEROIFNEG if ($this->array_export_special[$indice][$key]=='ZEROIFNEG') { //$alias=$this->array_export_alias[$indice][$key]; - $alias=str_replace(array('.', '-'),'_',$key); + $alias=str_replace(array('.', '-','(',')'),'_',$key); if ($objp->$alias < 0) $objp->$alias='0'; } } diff --git a/htdocs/exports/export.php b/htdocs/exports/export.php index d78a2564e7c..50ca1e09a91 100644 --- a/htdocs/exports/export.php +++ b/htdocs/exports/export.php @@ -35,6 +35,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; $langs->load("exports"); $langs->load("users"); $langs->load("companies"); +$langs->load("projects"); // Everybody should be able to go on this page //if (! $user->admin) diff --git a/htdocs/fichinter/class/fichinter.class.php b/htdocs/fichinter/class/fichinter.class.php index 69f01613f50..66fb1031d6e 100644 --- a/htdocs/fichinter/class/fichinter.class.php +++ b/htdocs/fichinter/class/fichinter.class.php @@ -89,6 +89,46 @@ class Fichinter extends CommonObject $this->statuts_logo[3]='statut4'; } + /** + * Load indicators into this->nb for board + * + * @return int <0 if KO, >0 if OK + */ + function load_state_board() + { + global $user; + + $this->nb=array(); + $clause = "WHERE"; + + $sql = "SELECT count(fi.rowid) as nb"; + $sql.= " FROM ".MAIN_DB_PREFIX."fichinter as fi"; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON fi.fk_soc = s.rowid"; + if (!$user->rights->societe->client->voir && !$user->societe_id) + { + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc"; + $sql.= " WHERE sc.fk_user = " .$user->id; + $clause = "AND"; + } + $sql.= " ".$clause." fi.entity IN (".getEntity($this->element, 1).")"; + + $resql=$this->db->query($sql); + if ($resql) + { + while ($obj=$this->db->fetch_object($resql)) + { + $this->nb["fichinters"]=$obj->nb; + } + $this->db->free($resql); + return 1; + } + else + { + dol_print_error($this->db); + $this->error=$this->db->error(); + return -1; + } + } /** * Create an intervention into data base diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php index 255d7f2cda0..b64a8ee77e4 100644 --- a/htdocs/fourn/card.php +++ b/htdocs/fourn/card.php @@ -518,15 +518,14 @@ if ($object->id > 0) /* * Barre d'actions */ + print '
'; + $parameters = array(); $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been // modified by hook if (empty($reshook)) { - - print '
'; - - if ($user->rights->fournisseur->commande->creer) + if ($user->rights->fournisseur->commande->creer) { $langs->load("orders"); print ''.$langs->trans("AddOrder").''; @@ -562,9 +561,11 @@ if ($object->id > 0) print ''.$langs->trans("AddAction").''; } } - - print '
'; - print '
'; + } + + print '
'; + + print '
'; if (! empty($conf->global->MAIN_REPEATCONTACTONEACHTAB)) { @@ -589,7 +590,6 @@ if ($object->id > 0) // List of done actions show_actions_done($conf,$langs,$db,$object); } - } } else { diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 6f20c509fd8..cb7d0ce6e6f 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -1415,6 +1415,7 @@ class CommandeFournisseur extends CommonOrder $subprice = price2num($pu,'MU'); + // TODO We should use here $this->line=new CommandeFournisseurLigne($this->db); and $this->line->insert(); to work loke other object (proposal, order, invoice) $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseurdet"; $sql.= " (fk_commande, label, description, date_start, date_end,"; $sql.= " fk_product, product_type,"; diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index e209dd741d6..30296bc2e22 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -7,7 +7,7 @@ * Copyright (C) 2010-2015 Juanjo Menent * Copyright (C) 2013 Philippe Grand * Copyright (C) 2013 Florian Henry - * Copyright (C) 2014-2015 Marcos García + * Copyright (C) 2014-2016 Marcos García * Copyright (C) 2015 Bahfir Abbes * Copyright (C) 2015 Ferran Marcet * @@ -694,7 +694,16 @@ class FactureFournisseur extends CommonInvoice dol_syslog(get_class($this)."::update", LOG_DEBUG); $resql = $this->db->query($sql); - if (! $resql) { $error++; $this->errors[]="Error ".$this->db->lasterror(); } + + if (!$resql) { + $error++; + + if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { + $this->errors[] = $langs->trans('ErrorRefAlreadyExists'); + } else { + $this->errors[] = "Error ".$this->db->lasterror(); + } + } if (! $error) { diff --git a/htdocs/fourn/class/fournisseur.product.class.php b/htdocs/fourn/class/fournisseur.product.class.php index 03be7e77d36..48896689dce 100644 --- a/htdocs/fourn/class/fournisseur.product.class.php +++ b/htdocs/fourn/class/fournisseur.product.class.php @@ -613,7 +613,9 @@ class ProductFournisseur extends Product if ($fourn_unitprice < $min || $min == -1) { $this->product_fourn_price_id = $record["product_fourn_price_id"]; - $this->fourn_ref = $record["ref_fourn"]; + $this->ref_supplier = $record["ref_fourn"]; + $this->ref_fourn = $record["ref_fourn"]; // deprecated + $this->fourn_ref = $record["ref_fourn"]; // deprecated $this->fourn_price = $fourn_price; $this->fourn_qty = $record["quantity"]; $this->fourn_remise_percent = $record["remise_percent"]; diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index 8b9c6267b18..8d18914d62c 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -984,9 +984,16 @@ if (empty($reshook)) // If creation from another object of another module (Example: origin=propal, originid=1) if (! empty($origin) && ! empty($originid)) { - $element = 'supplier_proposal'; - $subelement = 'supplier_proposal'; - + if ($origin == 'order' || $origin == 'commande') + { + $element = $subelement = 'commande'; + } + else + { + $element = 'supplier_proposal'; + $subelement = 'supplier_proposal'; + } + $object->origin = $origin; $object->origin_id = $originid; @@ -1046,35 +1053,41 @@ if (empty($reshook)) $lines[$i]->fetch_optionals($lines[$i]->rowid); $array_option = $lines[$i]->array_options; } - - $res = $productsupplier->find_min_price_product_fournisseur($lines[$i]->fk_product, $lines[$i]->qty); - /*if ($productsupplier->id > 0) - { - $res = $productsupplier->fetch($productsupplier->id); - }*/ - - $result = $object->addline( - $desc, - $lines[$i]->subprice, - $lines[$i]->qty, - $lines[$i]->tva_tx, - $lines[$i]->localtax1_tx, - $lines[$i]->localtax2_tx, - $lines[$i]->fk_product, - $productsupplier->product_fourn_price_id, - $productsupplier->ref_fourn, - $lines[$i]->remise_percent, - 'HT', - 0, - $lines[$i]->product_type, - '', - '', - null, - null, - array(), - $lines[$i]->fk_unit - ); + $result = $productsupplier->find_min_price_product_fournisseur($lines[$i]->fk_product, $lines[$i]->qty); + if ($result>0) + { + $tva_tx = $lines[$i]->tva_tx; + + if ($origin=="commande") + { + $soc=new societe($db); + $soc->fetch($socid); + $tva_tx=get_default_tva($soc, $mysoc, $lines[$i]->fk_product, $productsupplier->product_fourn_price_id); + } + + $result = $object->addline( + $desc, + $lines[$i]->subprice, + $lines[$i]->qty, + $tva_tx, + $lines[$i]->localtax1_tx, + $lines[$i]->localtax2_tx, + $lines[$i]->fk_product, + $productsupplier->product_fourn_price_id, + $productsupplier->ref_supplier, + $lines[$i]->remise_percent, + 'HT', + 0, + $lines[$i]->product_type, + '', + '', + null, + null, + array(), + $lines[$i]->fk_unit + ); + } if ($result < 0) { $error++; break; @@ -2771,15 +2784,17 @@ elseif (! empty($object->id)) /** * Boutons actions */ - $parameters = array(); - $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been - // modified by hook - if (empty($reshook)) + + if ($user->societe_id == 0 && $action != 'editline' && $action != 'delete') { - if ($user->societe_id == 0 && $action != 'editline' && $action != 'delete') - { - print '
'; + print '
'; + $parameters = array(); + $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been + // modified by hook + if (empty($reshook)) + { + // Validate if ($object->statut == 0 && $num > 0) { @@ -2961,9 +2976,11 @@ elseif (! empty($object->id)) print ''.$langs->trans("Delete").''; } - print "
"; } + + print "
"; } + print "
"; diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index c1346c357d5..eb6392eba06 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -247,8 +247,11 @@ if (empty($reshook)) // Set supplier ref if ($action == 'setref_supplier' && $user->rights->fournisseur->commande->creer) { - $result=$object->setValueFrom('ref_supplier',GETPOST('ref_supplier','alpha')); - if ($result < 0) dol_print_error($db, $object->error); + $object->ref_supplier = GETPOST('ref_supplier', 'alpha'); + + if ($object->update($user) < 0) { + setEventMessages($object->error, $object->errors, 'errors'); + } } // payments conditions diff --git a/htdocs/fourn/facture/list.php b/htdocs/fourn/facture/list.php index dafe95e419d..42810962275 100644 --- a/htdocs/fourn/facture/list.php +++ b/htdocs/fourn/facture/list.php @@ -225,10 +225,19 @@ if ($search_amount_all_tax != '') $sql .= natural_search('fac.total_ttc', $search_amount_all_tax, 1); } -if ($search_status != '') +if ($search_status != '' && $search_status>=0) { $sql.= " AND fac.fk_statut = ".$search_status; } +if ($filter && $filter != -1) +{ + $aFilter = explode(',', $filter); + foreach ($aFilter as $fil) + { + $filt = explode(':', $fil); + $sql .= ' AND ' . trim($filt[0]) . ' = ' . trim($filt[1]); + } +} $nbtotalofrecords = 0; if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) @@ -265,7 +274,7 @@ if ($resql) if ($search_amount_no_tax) $param.='&search_amount_no_tax='.urlencode($search_amount_no_tax); if ($search_amount_all_tax) $param.='&search_amount_all_tax='.urlencode($search_amount_all_tax); if ($filter && $filter != -1) $param.='&filtre='.urlencode($filter); - if ($optioncss != '') $param.='&optioncss='.$optioncss; + if ($optioncss != '') $param.='&optioncss='.$optioncss; if ($search_status >= 0) $param.="&search_status=".$search_status; print ''; diff --git a/htdocs/hrm/establishment/card.php b/htdocs/hrm/establishment/card.php index fb6f41f4f39..11179d218f8 100644 --- a/htdocs/hrm/establishment/card.php +++ b/htdocs/hrm/establishment/card.php @@ -136,7 +136,7 @@ else if ($action == 'update') $object->country_id = $_POST["country_id"]; $object->fk_user_mod = $user->id; - $result = $object->update(); + $result = $object->update($user); if ($result > 0) { diff --git a/htdocs/includes/jquery/plugins/multiselect/MIT-LICENSE.txt b/htdocs/includes/jquery/plugins/multiselect/MIT-LICENSE.txt new file mode 100755 index 00000000000..1076f8b4b2b --- /dev/null +++ b/htdocs/includes/jquery/plugins/multiselect/MIT-LICENSE.txt @@ -0,0 +1,20 @@ +Copyright (c) 2009 Michael Aufreiter, http://www.quasipartikel.at + +Permission is hereby granted, free of charge, to any person obtaining +a copy of this software and associated documentation files (the +"Software"), to deal in the Software without restriction, including +without limitation the rights to use, copy, modify, merge, publish, +distribute, sublicense, and/or sell copies of the Software, and to +permit persons to whom the Software is furnished to do so, subject to +the following conditions: + +The above copyright notice and this permission notice shall be +included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, +EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF +MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND +NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE +LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION +OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION +WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/htdocs/includes/jquery/plugins/multiselect/css/ui.multiselect.css b/htdocs/includes/jquery/plugins/multiselect/css/ui.multiselect.css new file mode 100755 index 00000000000..2072baa57c4 --- /dev/null +++ b/htdocs/includes/jquery/plugins/multiselect/css/ui.multiselect.css @@ -0,0 +1,144 @@ +/* Multiselect +----------------------------------*/ +.multiselect { + width: 600px; + height: 150px; +} + +.ui-multiselect { + border: solid 1px; + font-size: 0.8em; +} + +.ui-multiselect ul { + -moz-user-select: none; +} + +.ui-multiselect li { + margin: 0; + padding: 0; + cursor: default; + line-height: 20px; + height: 20px; + font-size: 11px; + list-style: none; +} + +.ui-multiselect li a { + color: #999; + text-decoration: none; + padding: 0; + display: block; + float: left; + cursor: pointer; +} + +.ui-multiselect li.ui-draggable-dragging { + padding-left: 10px; +} + +.ui-multiselect div.selected { + position: relative; + padding: 0; + margin: 0; + border: 0; + float: left; +} + +.ui-multiselect ul.selected { + position: relative; + padding: 0; + overflow: auto; + overflow-x: hidden; + background: #fff; + margin: 0; + list-style: none; + border: 0; + position: relative; + width: 100%; +} + +.ui-multiselect ul.selected li { + +} + +.ui-multiselect div.available { + position: relative; + padding: 0; + margin: 0; + border: 0; + float: left; + border-left: 1px solid; +} + +.ui-multiselect ul.available { + position: relative; + padding: 0; + overflow: auto; + overflow-x: hidden; + background: #fff; + margin: 0; + list-style: none; + border: 0; + width: 100%; +} + +.ui-multiselect ul.available li { + padding-left: 10px; +} + +.ui-multiselect .ui-state-default { + border: none; + margin-bottom: 1px; + position: relative; + padding-left: 20px; +} + +.ui-multiselect .ui-state-hover { + border: none; +} + +.ui-multiselect .ui-widget-header { + border: none; + font-size: 11px; + margin-bottom: 1px; +} + +.ui-multiselect .add-all { + float: right; + padding: 7px; +} + +.ui-multiselect .remove-all { + float: right; + padding: 7px; +} + +.ui-multiselect .search { + float: left; + padding: 4px; +} + +.ui-multiselect .count { + float: left; + padding: 7px; +} + +.ui-multiselect li span.ui-icon-arrowthick-2-n-s { + position: absolute; + left: 2px; +} + +.ui-multiselect li a.action { + position: absolute; + right: 2px; + top: 2px; +} + +.ui-multiselect input.search { + height: 14px; + padding: 1px; + opacity: 0.5; + margin: 4px; + width: 100px; +} \ No newline at end of file diff --git a/htdocs/includes/jquery/plugins/multiselect/js/ui.multiselect.js b/htdocs/includes/jquery/plugins/multiselect/js/ui.multiselect.js new file mode 100755 index 00000000000..1234fa7a957 --- /dev/null +++ b/htdocs/includes/jquery/plugins/multiselect/js/ui.multiselect.js @@ -0,0 +1,336 @@ +/* + * jQuery UI Multiselect + * + * Authors: + * Michael Aufreiter (quasipartikel.at) + * Yanick Rochon (yanick.rochon[at]gmail[dot]com) + * + * Dual licensed under the MIT (MIT-LICENSE.txt) + * and GPL (GPL-LICENSE.txt) licenses. + * + * http://www.quasipartikel.at/multiselect/ + * + * + * Depends: + * ui.core.js + * ui.sortable.js + * + * Optional: + * localization (http://plugins.jquery.com/project/localisation) + * scrollTo (http://plugins.jquery.com/project/ScrollTo) + * + * Todo: + * Make batch actions faster + * Implement dynamic insertion through remote calls + */ + + +(function($) { + +$.widget("ui.multiselect", { + options: { + sortable: true, + searchable: true, + doubleClickable: true, + animated: 'fast', + show: 'slideDown', + hide: 'slideUp', + dividerLocation: 0.6, + nodeComparator: function(node1,node2) { + var text1 = node1.text(), + text2 = node2.text(); + return text1 == text2 ? 0 : (text1 < text2 ? -1 : 1); + } + }, + _create: function() { + this.element.hide(); + this.id = this.element.attr("id"); + this.container = $('
').insertAfter(this.element); + this.count = 0; // number of currently selected options + this.selectedContainer = $('
').appendTo(this.container); + this.availableContainer = $('
').appendTo(this.container); + this.selectedActions = $('
0 '+$.ui.multiselect.locale.itemsCount+''+$.ui.multiselect.locale.removeAll+'
').appendTo(this.selectedContainer); + this.availableActions = $('').appendTo(this.availableContainer); + this.selectedList = $('
').bind('selectstart', function(){return false;}).appendTo(this.selectedContainer); + this.availableList = $('
').bind('selectstart', function(){return false;}).appendTo(this.availableContainer); + + var that = this; + + // set dimensions + this.container.width(this.element.width()+1); + this.selectedContainer.width(Math.floor(this.element.width()*this.options.dividerLocation)); + this.availableContainer.width(Math.floor(this.element.width()*(1-this.options.dividerLocation))); + + // fix list height to match
'; diff --git a/htdocs/opensurvey/card.php b/htdocs/opensurvey/card.php index c419a804210..ce941a680c7 100644 --- a/htdocs/opensurvey/card.php +++ b/htdocs/opensurvey/card.php @@ -35,6 +35,8 @@ if (!$user->rights->opensurvey->read) accessforbidden(); // Initialisation des variables $action=GETPOST('action'); +$cancel=GETPOST('cancel'); + $numsondage = ''; if (GETPOST('id')) { @@ -58,98 +60,119 @@ $expiredate=dol_mktime(0, 0, 0, GETPOST('expiremonth'), GETPOST('expireday'), GE * Actions */ +$parameters = array('id' => $numsondage); +$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks +if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); -// Delete -if ($action == 'delete_confirm') +if (empty($reshook)) { - // Security check - if (!$user->rights->opensurvey->write) accessforbidden(); + if ($cancel) $action=''; + + // Delete + if ($action == 'delete_confirm') + { + // Security check + if (!$user->rights->opensurvey->write) accessforbidden(); + + $result=$object->delete($user,'',$numsondage); + + header('Location: '.dol_buildpath('/opensurvey/list.php',1)); + exit(); + } + + // Close + if ($action == 'close') + { + $object->status = Opensurveysondage::STATUS_CLOSED; + $object->update(); + } + + // Reopend + if ($action == 'reopen') + { + $object->status = Opensurveysondage::STATUS_VALIDATED; + $object->update(); + } + + // Update + if ($action == 'update') + { + // Security check + if (!$user->rights->opensurvey->write) accessforbidden(); + + $error=0; + + if (! GETPOST('nouveautitre')) + { + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Title")), null, 'errors'); + $error++; + $action = 'edit'; + } + + if (! $error) + { + $object->titre = GETPOST('nouveautitre'); + $object->commentaires = GETPOST('nouveauxcommentaires'); + $object->mail_admin = GETPOST('nouvelleadresse'); + $object->date_fin = $expiredate; + $object->allow_comments = GETPOST('cancomment') == 'on' ? true : false; + $object->allow_spy = GETPOST('canseeothersvote') == 'on' ? true : false; + $object->mailsonde = GETPOST('mailsonde') == 'on' ? true : false; + + $res=$object->update($user); + if ($res < 0) + { + setEventMessages($object->error, $object->errors, 'errors'); + $action='edit'; + } + } + } - $result=$object->delete($user,'',$numsondage); - - header('Location: '.dol_buildpath('/opensurvey/list.php',1)); - exit(); -} - -// Update -if ($action == 'update') -{ - // Security check - if (!$user->rights->opensurvey->write) accessforbidden(); - - $error=0; - - if (! GETPOST('nouveautitre')) - { - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Title")), null, 'errors'); - $error++; - $action = 'edit'; - } - - if (! $error) - { - $object->titre = GETPOST('nouveautitre'); - $object->commentaires = GETPOST('nouveauxcommentaires'); - $object->mail_admin = GETPOST('nouvelleadresse'); - $object->date_fin = $expiredate; - $object->allow_comments = GETPOST('cancomment') == 'on' ? true : false; - $object->allow_spy = GETPOST('canseeothersvote') == 'on' ? true : false; - $object->mailsonde = GETPOST('mailsonde') == 'on' ? true : false; - - $res=$object->update($user); - if ($res < 0) - { - setEventMessages($object->error, $object->errors, 'errors'); - $action='edit'; - } - } -} - - -// Add comment -if (GETPOST('ajoutcomment')) -{ - $error=0; - - if (! GETPOST('comment')) - { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Comment")), null, 'errors'); - } - if (! GETPOST('commentuser')) - { - $error++; - setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("User")), null, 'errors'); - } - - if (! $error) - { - $comment = GETPOST("comment"); - $comment_user = GETPOST('commentuser'); - - $resql = $object->addComment($comment, $comment_user); - - if (! $resql) - { - setEventMessages($langs->trans('ErrorInsertingComment'), null, 'errors'); - } - } -} - -// Delete comment -$idcomment=GETPOST('deletecomment','int'); -if ($idcomment) -{ - // Security check - if (!$user->rights->opensurvey->write) accessforbidden(); - - $resql = $object->deleteComment($idcomment); -} - -if ($action == 'edit') { - - // Security check - if (!$user->rights->opensurvey->write) accessforbidden(); + // Add comment + if (GETPOST('ajoutcomment')) + { + $error=0; + + if (! GETPOST('comment')) + { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Comment")), null, 'errors'); + } + if (! GETPOST('commentuser')) + { + $error++; + setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("User")), null, 'errors'); + } + + if (! $error) + { + $comment = GETPOST("comment"); + $comment_user = GETPOST('commentuser'); + + $resql = $object->addComment($comment, $comment_user); + + if (! $resql) + { + setEventMessages($langs->trans('ErrorInsertingComment'), null, 'errors'); + } + } + } + + // Delete comment + $idcomment=GETPOST('deletecomment','int'); + if ($idcomment) + { + // Security check + if (!$user->rights->opensurvey->write) accessforbidden(); + + $resql = $object->deleteComment($idcomment); + } + + if ($action == 'edit') { + + // Security check + if (!$user->rights->opensurvey->write) accessforbidden(); + } } @@ -196,7 +219,7 @@ print ''; $linkback = ''.$langs->trans("BackToList").''; // Ref -print ''; +print ''; print ''; @@ -219,6 +242,12 @@ if ($action == 'edit') else print dol_htmlentities($object->titre); print ''; +// Status +print ''; + // Description print ''."\n"; @@ -107,13 +110,14 @@ print ''; print ''; $arraystatus=array(''=>' ','expired'=>$langs->trans("Expired"),'opened'=>$langs->trans("Opened")); print ''; +print ''; print ''; print ''."\n"; -$sql = "SELECT p.id_sondage, p.fk_user_creat, p.format, p.date_fin, p.titre, p.nom_admin,"; +$sql = "SELECT p.id_sondage, p.fk_user_creat, p.format, p.date_fin, p.status, p.titre, p.nom_admin,"; $sql.= " u.login, u.firstname, u.lastname"; $sql.= " FROM ".MAIN_DB_PREFIX."opensurvey_sondage as p"; $sql.= " LEFT OUTER JOIN ".MAIN_DB_PREFIX."user u ON u.rowid = p.fk_user_creat"; @@ -150,6 +154,9 @@ while ($i < min($num,$limit)) } else dol_print_error($db); + $opensurvey_static->id=$obj->id_sondage; + $opensurvey_static->status=$obj->status; + $var=!$var; print ''; print ''; print''."\n"; - + print ''; + print''."\n"; + print''."\n"; print ''."\n"; diff --git a/htdocs/opensurvey/results.php b/htdocs/opensurvey/results.php index 5c14a20de23..93ccd93729b 100644 --- a/htdocs/opensurvey/results.php +++ b/htdocs/opensurvey/results.php @@ -432,7 +432,7 @@ print '
'.$langs->trans('Ref').'
'.$langs->trans('Ref').''; print $form->showrefnav($object, 'id', $linkback, 1, 'id_sondage', 'id_sondage'); print '
'; +print $langs->trans("Status") .''; +print $object->getLibStatut(4); +print '
'.$langs->trans("Description") .''; if ($action == 'edit') @@ -326,7 +355,11 @@ dol_fiche_end(); if ($action == 'edit') { - print '
'; + print '
'; + print ''; + print '   '; + print ''; + print '
'; } print ''."\n"; @@ -340,9 +373,20 @@ print '
'; if ($action != 'edit' && $user->rights->opensurvey->write) { - //Modify button - print ''.$langs->trans("Modify") . ''; + //Modify button + print ''.$langs->trans("Modify") . ''; + if ($object->status == Opensurveysondage::STATUS_VALIDATED) + { + //Close button + print ''.$langs->trans("Close") . ''; + } + if ($object->status == Opensurveysondage::STATUS_CLOSED) + { + //Opened button + print ''.$langs->trans("ReOpen") . ''; + } + //Delete button print ''.$langs->trans('Delete').''; } diff --git a/htdocs/opensurvey/class/opensurveysondage.class.php b/htdocs/opensurvey/class/opensurveysondage.class.php index c3be8fc4793..fecb7904a9c 100644 --- a/htdocs/opensurvey/class/opensurveysondage.class.php +++ b/htdocs/opensurvey/class/opensurveysondage.class.php @@ -56,6 +56,7 @@ class Opensurveysondage extends CommonObject var $titre; var $date_fin=''; + var $status=1; var $format; var $mailsonde; @@ -73,6 +74,22 @@ class Opensurveysondage extends CommonObject */ public $allow_spy; + + /** + * Draft status (not used) + */ + const STATUS_DRAFT = 0; + /** + * Validated/Opened status + */ + const STATUS_VALIDATED = 1; + /** + * Closed + */ + const STATUS_CLOSED = 2; + + + /** * Constructor * @@ -115,6 +132,7 @@ class Opensurveysondage extends CommonObject $sql.= "fk_user_creat,"; $sql.= "titre,"; $sql.= "date_fin,"; + $sql.= "status,"; $sql.= "format,"; $sql.= "mailsonde,"; $sql.= "allow_comments,"; @@ -127,6 +145,7 @@ class Opensurveysondage extends CommonObject $sql.= " ".$user->id.","; $sql.= " '".$this->db->escape($this->titre)."',"; $sql.= " '".$this->db->idate($this->date_fin)."',"; + $sql.= " ".$this->status.","; $sql.= " '".$this->db->escape($this->format)."',"; $sql.= " ".$this->db->escape($this->mailsonde).","; $sql.= " ".$this->db->escape($this->allow_comments).","; @@ -190,6 +209,7 @@ class Opensurveysondage extends CommonObject $sql.= " t.fk_user_creat,"; $sql.= " t.titre,"; $sql.= " t.date_fin,"; + $sql.= " t.status,"; $sql.= " t.format,"; $sql.= " t.mailsonde,"; $sql.= " t.allow_comments,"; @@ -217,6 +237,7 @@ class Opensurveysondage extends CommonObject $this->nom_admin = $obj->nom_admin; $this->titre = $obj->titre; $this->date_fin = $this->db->jdate($obj->date_fin); + $this->status = $obj->status; $this->format = $obj->format; $this->mailsonde = $obj->mailsonde; $this->allow_comments = $obj->allow_comments; @@ -274,6 +295,7 @@ class Opensurveysondage extends CommonObject $sql.= " nom_admin=".(isset($this->nom_admin)?"'".$this->db->escape($this->nom_admin)."'":"null").","; $sql.= " titre=".(isset($this->titre)?"'".$this->db->escape($this->titre)."'":"null").","; $sql.= " date_fin=".(dol_strlen($this->date_fin)!=0 ? "'".$this->db->idate($this->date_fin)."'" : 'null').","; + $sql.= " status=".(isset($this->status)?"'".$this->db->escape($this->status)."'":"null").","; $sql.= " format=".(isset($this->format)?"'".$this->db->escape($this->format)."'":"null").","; $sql.= " mailsonde=".(isset($this->mailsonde)?$this->db->escape($this->mailsonde):"null").","; $sql.= " allow_comments=".$this->db->escape($this->allow_comments).","; @@ -291,15 +313,12 @@ class Opensurveysondage extends CommonObject { if (! $notrigger) { - // Uncomment this and change MYOBJECT to your own tag if you - // want this action calls a trigger. - - //// Call triggers - //include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - //$interface=new Interfaces($this->db); - //$result=$interface->run_triggers('MYOBJECT_MODIFY',$this,$user,$langs,$conf); - //if ($result < 0) { $error++; $this->errors=$interface->errors; } - //// End call triggers + // Call triggers + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers('OPENSURVEY_MODIFY',$this,$user,$langs,$conf); + if ($result < 0) { $error++; $this->errors=$interface->errors; } + // End call triggers } } @@ -321,17 +340,16 @@ class Opensurveysondage extends CommonObject } } - - /** - * Delete object in database - * + /** + * Delete object in database + * * @param User $user User that deletes * @param int $notrigger 0=launch triggers after, 1=disable triggers * @param string $numsondage Num sondage admin to delete - * @return int <0 if KO, >0 if OK - */ - function delete($user, $notrigger, $numsondage) - { + * @return int <0 if KO, >0 if OK + */ + function delete($user, $notrigger, $numsondage) + { global $conf, $langs; $error=0; @@ -428,12 +446,13 @@ class Opensurveysondage extends CommonObject $this->id=0; $this->id_sondage=''; - $this->commentaires=''; + $this->commentaires='Comment of the specimen survey'; $this->mail_admin=''; $this->nom_admin=''; - $this->titre=''; - $this->date_fin=''; - $this->format=''; + $this->titre='This is a specimen survey'; + $this->date_fin=dol_now()+3600*24*10; + $this->status=1; + $this->format='classic'; $this->mailsonde=''; } @@ -518,10 +537,74 @@ class Opensurveysondage extends CommonObject $this->mail_admin = trim($this->mail_admin); $this->nom_admin = trim($this->nom_admin); $this->titre = trim($this->titre); + $this->status = trim($this->status); $this->format = trim($this->format); $this->mailsonde = ($this->mailsonde ? 1 : 0); $this->allow_comments = ($this->allow_comments ? 1 : 0); $this->allow_spy = ($this->allow_spy ? 1 : 0); $this->sujet = trim($this->sujet); } + + + /** + * Return status label of Order + * + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Libelle + */ + function getLibStatut($mode) + { + return $this->LibStatut($this->status,$mode); + } + + /** + * Return label of status + * + * @param int $status Id statut + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto + * @return string Label of status + */ + function LibStatut($status,$mode) + { + global $langs, $conf; + + //print 'x'.$status.'-'.$billed; + if ($mode == 0) + { + if ($status==self::STATUS_DRAFT) return $langs->trans('Draft'); + if ($status==self::STATUS_VALIDATED) return $langs->trans('Opened'); + if ($status==self::STATUS_CLOSED) return $langs->trans('Closed'); + } + elseif ($mode == 1) + { + if ($status==self::STATUS_DRAFT) return $langs->trans('Draft'); + if ($status==self::STATUS_VALIDATED) return $langs->trans('Opened'); + if ($status==self::STATUS_CLOSED) return $langs->trans('Closed'); + } + elseif ($mode == 2) + { + if ($status==self::STATUS_DRAFT) return img_picto($langs->trans('Draft'),'statut0').' '.$langs->trans('Draft'); + if ($status==self::STATUS_VALIDATED) return img_picto($langs->trans('Opened'),'statut1').' '.$langs->trans('Opened'); + if ($status==self::STATUS_CLOSED) return img_picto($langs->trans('Closed'),'statut6').' '.$langs->trans('Closed'); + } + elseif ($mode == 3) + { + if ($status==self::STATUS_DRAFT) return img_picto($langs->trans('Draft'),'statut0'); + if ($status==self::STATUS_VALIDATED) return img_picto($langs->trans('Opened'),'statut1'); + if ($status==self::STATUS_CLOSED) return img_picto($langs->trans('Closed'),'statut6'); + } + elseif ($mode == 4) + { + if ($status==self::STATUS_DRAFT) return img_picto($langs->trans('Draft'),'statut0').' '.$langs->trans('Draft'); + if ($status==self::STATUS_VALIDATED) return img_picto($langs->trans('Opened').$billedtext,'statut1').' '.$langs->trans('Opened'); + if ($status==self::STATUS_CLOSED) return img_picto($langs->trans('Closed'),'statut6').' '.$langs->trans('Closed'); + } + elseif ($mode == 5) + { + if ($status==self::STATUS_DRAFT) return ''.$langs->trans('Draft').' '.img_picto($langs->trans('Draft'),'statut0'); + if ($status==self::STATUS_VALIDATED) return ''.$langs->trans('Opened').' '.img_picto($langs->trans('Opened'),'statut1'); + if ($status==self::STATUS_CLOSED) return ''.$langs->trans('Closed').' '.img_picto($langs->trans('Closed'),'statut6'); + } + } + } diff --git a/htdocs/opensurvey/list.php b/htdocs/opensurvey/list.php index b440b5ee43e..aed5610bee0 100644 --- a/htdocs/opensurvey/list.php +++ b/htdocs/opensurvey/list.php @@ -25,6 +25,7 @@ require_once('../main.inc.php'); require_once(DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php"); require_once(DOL_DOCUMENT_ROOT."/core/lib/files.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/opensurvey/class/opensurveysondage.class.php"); // Security check if (!$user->rights->opensurvey->read) accessforbidden(); @@ -68,6 +69,7 @@ if (GETPOST('button_removefilter')) */ $form=new Form($db); +$opensurvey_static = new Opensurveysondage($db); $now = dol_now(); @@ -96,6 +98,7 @@ print_liste_field_titre($langs->trans("Type")); print_liste_field_titre($langs->trans("Author"), $_SERVER["PHP_SELF"], "u.".$fieldtosortuser,$param,"","",$sortfield,$sortorder); print_liste_field_titre($langs->trans("NbOfVoters")); print_liste_field_titre($langs->trans("ExpireDate"), $_SERVER["PHP_SELF"], "p.date_fin",$param,"",'align="center"',$sortfield,$sortorder); +print_liste_field_titre($langs->trans("Status"), $_SERVER["PHP_SELF"], "p.status",$param,"",'align="center"',$sortfield,$sortorder); print_liste_field_titre(''); print '
'. $form->selectarray('status', $arraystatus, $status).''; $searchpitco=$form->showFilterAndCheckAddButtons(0); print $searchpitco; print '
'; @@ -176,11 +183,13 @@ while ($i < min($num,$limit)) print ''.$nbuser.''.dol_print_date($db->jdate($obj->date_fin),'day'); if ($db->jdate($obj->date_fin) < time()) { print ' ('.$langs->trans("Expired").')'; } print ''.$opensurvey_static->getLibStatut(5).'
'; $linkback = ''.$langs->trans("BackToList").''; // Ref -print ''; +print ''; print ''; diff --git a/htdocs/product/card.php b/htdocs/product/card.php index 841d1b1b73a..92d8a7f4288 100644 --- a/htdocs/product/card.php +++ b/htdocs/product/card.php @@ -8,12 +8,12 @@ * Copyright (C) 2010-2015 Juanjo Menent * Copyright (C) 2013-2014 Marcos García * Copyright (C) 2012-2013 Cédric Salvador - * Copyright (C) 2011-2015 Alexandre Spangaro + * Copyright (C) 2011-2016 Alexandre Spangaro * Copyright (C) 2014 Cédric Gross * Copyright (C) 2014-2015 Ferran Marcet * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2015 Raphaël Doursenaud - * Copyright (C) 2016 Charlie Benke + * Copyright (C) 2016 Charlie Benke * * 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 @@ -1477,22 +1477,24 @@ else // Accountancy sell code print ''; + if (! empty($conf->accounting->enabled)) { + print length_accountg($object->accountancy_code_sell); + } else { + print $object->accountancy_code_sell; + } + print ''; // Accountancy buy code print ''; // Status (to sell) diff --git a/htdocs/product/class/api_product.class.php b/htdocs/product/class/api_product.class.php index 1ce63411cd3..1e485fd6733 100644 --- a/htdocs/product/class/api_product.class.php +++ b/htdocs/product/class/api_product.class.php @@ -18,6 +18,7 @@ use Luracast\Restler\RestException; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; /** * API class for product object @@ -165,6 +166,91 @@ class ProductApi extends DolibarrApi } return $obj_ret; } + + + /** + * List products in a category + * + * Get a list of products + * + * @param int $mode Use this param to filter list (0 for all, 1 for only product, 2 for only service) + * @param int $category Use this param to filter list by category + * @param mixed $to_sell Filter products to sell (1) or not to sell (0) + * @param mixed $to_buy Filter products to nuy (1) or not to buy (0) + * @param string $sortfield Sort field + * @param string $sortorder Sort order + * @param int $limit Limit for list + * @param int $page Page number + * + * @return array Array of product objects + * + * @url GET /product/list/category/{category} + */ + function getByCategory($mode=0, $category=0, $to_sell='', $to_buy='', $sortfield = "p.ref", $sortorder = 'ASC', $limit = 0, $page = 0) { + global $db, $conf; + + $obj_ret = array(); + + $socid = DolibarrApiAccess::$user->societe_id ? DolibarrApiAccess::$user->societe_id : ''; + + $sql = "SELECT rowid, ref, ref_ext"; + $sql.= " FROM ".MAIN_DB_PREFIX."product as p, "; + $sql.= MAIN_DB_PREFIX."categorie_product as c"; + $sql.= ' WHERE p.entity IN ('.getEntity('product', 1).')'; + + // Select products of given category + $sql.= " AND c.fk_categorie = ".$db->escape($category); + $sql.= " AND c.fk_product = p.rowid "; + + // Show products + if ($mode == 1) $sql.= " AND p.fk_product_type = 0"; + // Show services + if ($mode == 2) $sql.= " AND p.fk_product_type = 1"; + // Show product on sell + if ($to_sell) $sql.= " AND p.to_sell = ".$db->escape($to_sell); + // Show product on buy + if ($to_buy) $sql.= " AND p.to_nuy = ".$db->escape($to_nuy); + + $nbtotalofrecords = 0; + if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) + { + $result = $db->query($sql); + $nbtotalofrecords = $db->num_rows($result); + } + + $sql.= $db->order($sortfield, $sortorder); + if ($limit) { + if ($page < 0) + { + $page = 0; + } + $offset = $limit * $page; + + $sql.= $db->plimit($limit + 1, $offset); + } + + $result = $db->query($sql); + if ($result) + { + $num = $db->num_rows($result); + while ($i < $num) + { + $obj = $db->fetch_object($result); + $product_static = new Product($db); + if($product_static->fetch($obj->rowid)) { + $obj_ret[] = parent::_cleanObjectDatas($product_static); + } + $i++; + } + } + else { + throw new RestException(503, 'Error when retrieve product list'); + } + if( ! count($obj_ret)) { + throw new RestException(404, 'No product found'); + } + return $obj_ret; + } /** * Create product object diff --git a/htdocs/product/class/html.formproduct.class.php b/htdocs/product/class/html.formproduct.class.php index 24a7506882b..a69880f7fa5 100644 --- a/htdocs/product/class/html.formproduct.class.php +++ b/htdocs/product/class/html.formproduct.class.php @@ -1,5 +1,6 @@ + * Copyright (C) 2016 Francis Appels * * 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 @@ -53,20 +54,20 @@ class FormProduct * * @param int $fk_product Add quantity of stock in label for product with id fk_product. Nothing if 0. * @param string $batch Add quantity of batch stock in label for product with batch name batch, batch name precedes batch_id. Nothing if ''. - * @param int $fk_product_batch Add quantity of batch stock in label for product with batch id fk_product_batch. Nothing if 0. + * @param int $status additional filter on status other then 1 * @param boolean $sumStock sum total stock of a warehouse, default true * @return int Nb of loaded lines, 0 if already loaded, <0 if KO */ - function loadWarehouses($fk_product=0, $batch = '', $fk_product_batch=0, $sumStock = true) + function loadWarehouses($fk_product=0, $batch = '', $status=null, $sumStock = true) { global $conf, $langs; if (empty($fk_product) && count($this->cache_warehouses)) return 0; // Cache already loaded and we do not want a list with information specific to a product - $sql = "SELECT e.rowid, e.label"; + $sql = "SELECT e.rowid, e.label, e.description"; if (!empty($fk_product)) { - if (!empty($fk_product_batch) || !empty($batch)) + if (!empty($batch)) { $sql.= ", pb.qty as stock"; } @@ -87,13 +88,18 @@ class FormProduct if (!empty($batch)) { $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_batch as pb on pb.fk_product_stock = ps.rowid AND pb.batch = '".$batch."'"; - } else if (!empty($fk_product_batch)) - { - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product_batch as pb on pb.fk_product_stock = ps.rowid AND pb.rowid = '".$fk_product_batch."'"; - } + } } $sql.= " WHERE e.entity IN (".getEntity('stock', 1).")"; - $sql.= " AND e.statut = 1"; + if (!empty($status)) + { + $sql.= " AND e.statut IN (1, ".$status.")"; + } + else + { + $sql.= " AND e.statut = 1"; + } + if ($sumStock && empty($fk_product)) $sql.= " GROUP BY e.rowid, e.label, e.description"; $sql.= " ORDER BY e.label"; @@ -127,7 +133,7 @@ class FormProduct * * @param int $selected Id of preselected warehouse ('' for no value, 'ifone'=select value if one value otherwise no value) * @param string $htmlname Name of html select html - * @param string $filtertype For filter + * @param string $filtertype For filter, additional filter on status other then 1 * @param int $empty 1=Can be empty, 0 if not * @param int $disabled 1=Select is disabled * @param int $fk_product Add quantity of stock in label for product with id fk_product. Nothing if 0. @@ -142,11 +148,11 @@ class FormProduct { global $conf,$langs,$user; - dol_syslog(get_class($this)."::selectWarehouses $selected, $htmlname, $filtertype, $empty, $disabled, $fk_product",LOG_DEBUG); + dol_syslog(get_class($this)."::selectWarehouses $selected, $htmlname, $filtertype, $empty, $disabled, $fk_product, $empty_label, $showstock, $forcecombo, $morecss",LOG_DEBUG); $out=''; - $this->loadWarehouses($fk_product); + $this->loadWarehouses($fk_product, '', + $filtertype); // filter on numeric status $nbofwarehouses=count($this->cache_warehouses); if ($conf->use_javascript_ajax && ! $forcecombo) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 819a5438eda..86a11f57541 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -109,8 +109,10 @@ class Product extends CommonObject var $localtax1_type; var $localtax2_type; - //! Stock + //! Stock real var $stock_reel; + //! Stock virtual + var $stock_theorique; //! Cost price var $cost_price; //! Average price value for product entry into stock (PMP) @@ -1416,7 +1418,7 @@ class Product extends CommonObject $id=$this->id; - dol_syslog(get_class($this)."::update_price id=".$id." newprice=".$newprice." newpricebase=".$newpricebase." newminprice=".$newminprice." level=".$level." npr=".$newnpr," newdefaultvatcode=".$newdefaultvatcode); + dol_syslog(get_class($this)."::update_price id=".$id." newprice=".$newprice." newpricebase=".$newpricebase." newminprice=".$newminprice." level=".$level." npr=".$newnpr." newdefaultvatcode=".$newdefaultvatcode); // Clean parameters if (empty($this->tva_tx)) $this->tva_tx=0; @@ -1848,7 +1850,7 @@ class Product extends CommonObject } } - // We should not load stock at each fetch. If someone need stock, he must call load_stock after fetch. + // We should not load stock during the fetch. If someone need stock of product, he must call load_stock after fetching product. //$res=$this->load_stock(); // instead we just init the stock_warehouse array $this->stock_warehouse = array(); @@ -2845,7 +2847,7 @@ class Product extends CommonObject //print "XXX We add id=".$id." - label=".$label." - nb=".$nb." - multiply=".$multiply." fullpath=".$compl_path.$label."\n"; $this->fetch($id); // Load product - $this->load_stock(); // Load stock + $this->load_stock('nobatch,novirtual'); // Load stock to get true this->stock_reel $this->res[]= array( 'id'=>$id, // Id product 'id_parent'=>$id_parent, @@ -2954,6 +2956,7 @@ class Product extends CommonObject $prods = array (); while ($record = $this->db->fetch_array($res)) { + // $record['id'] = $record['rowid'] = id of father $prods[$record['id']]['id'] = $record['rowid']; $prods[$record['id']]['ref'] = $record['ref']; $prods[$record['id']]['label'] = $record['label']; @@ -2972,45 +2975,15 @@ class Product extends CommonObject } - /** - * Return all direct parent products fo current product - * - * @return array prod - * @see getFather - */ - function getParent() - { - $sql = "SELECT p.rowid, p.label as label, p.ref as ref, pa.fk_product_pere as id, p.fk_product_type, pa.qty"; - $sql.= " FROM ".MAIN_DB_PREFIX."product_association as pa,"; - $sql.= " ".MAIN_DB_PREFIX."product as p"; - $sql.= " WHERE p.rowid = pa.fk_product_pere"; - $sql.= " AND p.rowid = ".$this->id; - - $res = $this->db->query($sql); - if ($res) - { - $prods = array (); - while ($record = $this->db->fetch_array($res)) - { - $prods[$this->db->escape($record['label'])] = array(0=>$record['id']); - } - return $prods; - } - else - { - dol_print_error($this->db); - return -1; - } - } - /** * Return childs of product $id * * @param int $id Id of product to search childs of * @param int $firstlevelonly Return only direct child + * @param int $level Level of recursing call (start to 1) * @return array Prod */ - function getChildsArbo($id, $firstlevelonly=0) + function getChildsArbo($id, $firstlevelonly=0, $level=1) { $sql = "SELECT p.rowid, p.label as label, pa.qty as qty, pa.fk_product_fils as id, p.fk_product_type, pa.incdec"; $sql.= " FROM ".MAIN_DB_PREFIX."product as p"; @@ -3019,13 +2992,18 @@ class Product extends CommonObject $sql.= " AND pa.fk_product_pere = ".$id; $sql.= " AND pa.fk_product_fils != ".$id; // This should not happens, it is to avoid infinite loop if it happens - dol_syslog(get_class($this).'::getChildsArbo', LOG_DEBUG); + dol_syslog(get_class($this).'::getChildsArbo id='.$id.' level='.$level, LOG_DEBUG); + + // Protection against infinite loop + if ($level > 30) return array(); + $res = $this->db->query($sql); if ($res) { $prods = array(); while ($rec = $this->db->fetch_array($res)) { + // TODO Add check to not add ne record if already added $prods[$rec['rowid']]= array( 0=>$rec['id'], 1=>$rec['qty'], @@ -3037,7 +3015,7 @@ class Product extends CommonObject //$prods[$this->db->escape($rec['label'])]= array(0=>$rec['id'],1=>$rec['qty']); if (empty($firstlevelonly)) { - $listofchilds=$this->getChildsArbo($rec['id']); + $listofchilds=$this->getChildsArbo($rec['id'], 0, $level + 1); foreach($listofchilds as $keyChild => $valueChild) { $prods[$rec['rowid']]['childs'][$keyChild] = $valueChild; @@ -3062,10 +3040,13 @@ class Product extends CommonObject */ function get_sousproduits_arbo() { - $parent = $this->getParent(); + //$parent = $this->getParent(); + $parent=array(); + $parent[$this->label]=array(0 => $this->id); + foreach($parent as $key => $value) // key=label, value[0]=id { - foreach($this->getChildsArbo($value[0]) as $keyChild => $valueChild) + foreach($this->getChildsArbo($value[0]) as $keyChild => $valueChild) // Warning. getChildsArbo can gell getChildsArbo recursively. { $parent[$key][$keyChild] = $valueChild; } @@ -3339,15 +3320,18 @@ class Product extends CommonObject /** * Load information about stock of a product into stock_reel, stock_warehouse[] (including stock_warehouse[idwarehouse]->detail_batch for batch products) + * This function need a lot of load. If you use it on list, use a cache to execute it one for each product id. * - * @return int < 0 if KO, > 0 if OK - * @see load_virtual_stock, getBatchInfo + * @param string $option '', 'nobatch' = Do not load batch information, 'novirtual' = Do not load virtual stock + * @return int < 0 if KO, > 0 if OK + * @see load_virtual_stock, getBatchInfo */ - function load_stock() + function load_stock($option='') { $this->stock_reel = 0; $this->stock_warehouse = array(); - + $this->stock_theorique = 0; + $sql = "SELECT ps.rowid, ps.reel, ps.fk_entrepot"; $sql.= " FROM ".MAIN_DB_PREFIX."product_stock as ps"; $sql.= ", ".MAIN_DB_PREFIX."entrepot as w"; @@ -3369,14 +3353,17 @@ class Product extends CommonObject $this->stock_warehouse[$row->fk_entrepot] = new stdClass(); $this->stock_warehouse[$row->fk_entrepot]->real = $row->reel; $this->stock_warehouse[$row->fk_entrepot]->id = $row->rowid; - if ($this->hasbatch()) $this->stock_warehouse[$row->fk_entrepot]->detail_batch=Productbatch::findAll($this->db,$row->rowid,1); + if ((! preg_match('/nobatch/', $option)) && $this->hasbatch()) $this->stock_warehouse[$row->fk_entrepot]->detail_batch=Productbatch::findAll($this->db,$row->rowid,1); $this->stock_reel+=$row->reel; $i++; } } $this->db->free($result); - $this->load_virtual_stock(); // This also load stats_commande_fournisseur, ... + if (! preg_match('/novirtual/', $option)) + { + $this->load_virtual_stock(); // This also load stats_commande_fournisseur, ... + } return 1; } @@ -3388,7 +3375,8 @@ class Product extends CommonObject } /** - * Load information about objects that are delat between physical and virtual stock of a product + * Load value ->stock_theorique of a product. Property this->id must be defined. + * This function need a lot of load. If you use it on list, use a cache to execute it one for each product id. * * @return int < 0 if KO, > 0 if OK * @see load_stock, getBatchInfo @@ -3712,7 +3700,7 @@ class Product extends CommonObject } } - if ($size==1 || $size='small') + if ($size==1 || $size=='small') { if ($nbbyrow > 0) { diff --git a/htdocs/product/class/productbatch.class.php b/htdocs/product/class/productbatch.class.php index d0554309539..749da6d86e2 100644 --- a/htdocs/product/class/productbatch.class.php +++ b/htdocs/product/class/productbatch.class.php @@ -408,8 +408,8 @@ class Productbatch extends CommonObject * Find first detail record that match eather eat-by or sell-by or batch within given warehouse * * @param int $fk_product_stock id product_stock for objet - * @param date $eatby eat-by date for objet - * @param date $sellby sell-by date for objet + * @param date $eatby eat-by date for objet - deprecated: a search must be done on batch number + * @param date $sellby sell-by date for objet - deprecated: a search must be done on batch number * @param string $batch_number batch number for objet * @return int <0 if KO, >0 if OK */ diff --git a/htdocs/product/composition/card.php b/htdocs/product/composition/card.php index f4b3f575eba..25195f6c167 100644 --- a/htdocs/product/composition/card.php +++ b/htdocs/product/composition/card.php @@ -190,25 +190,10 @@ if ($id > 0 || ! empty($ref)) */ if ($user->rights->produit->lire || $user->rights->service->lire) { + dol_banner_tab($object, 'ref', '', ($user->societe_id?0:1), 'ref'); + print '
'.$langs->trans('Ref').'
'.$langs->trans('Ref').''; print $form->showrefnav($object, 'id', $linkback, 1, 'id_sondage', 'id_sondage'); print '
'; - print ''; - print '
'; print $langs->trans("ProductAccountancySellCode"); - print '
'; print '
'; - print length_accountg($object->accountancy_code_sell); - print '
'; - print ''; - print '
'; print $langs->trans("ProductAccountancyBuyCode"); - print '
'; print '
'; - print length_accountg($object->accountancy_code_buy); + if (! empty($conf->accounting->enabled)) { + print length_accountg($object->accountancy_code_buy); + } else { + print $object->accountancy_code_buy; + } print '
'; - print ""; - - $nblignes=6; - if ($object->isProduct() && ! empty($conf->stock->enabled)) $nblignes++; - if ($object->isService()) $nblignes++; - - // Reference - print ''; - - print ''; - - // Label - print ''; - print ''; - // Nature if($object->type!=Product::TYPE_SERVICE) { @@ -265,7 +250,7 @@ if ($id > 0 || ! empty($ref)) print load_fiche_titre($langs->trans("ProductParentList"),'','').'
'; print '
'.$langs->trans("Ref").''; - print $form->showrefnav($object,'ref','',1,'ref'); - print '
'.$langs->trans("Label").''.$object->label.'
'; print ''; - print ''; + print ''; print ''; print ''; print ''; @@ -323,6 +308,7 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; print ''; + print ''; if (! empty($conf->stock->enabled)) print ''; print ''; print ''; @@ -334,10 +320,7 @@ if ($id > 0 || ! empty($ref)) { foreach($prods_arbo as $value) { - $productstatic->id=$value['id']; - $productstatic->type=$value['type']; - $productstatic->label=$value['label']; - $productstatic->entity=$value['entity']; + $productstatic->fetch($value['id']); if ($value['level'] <= 1) { @@ -345,7 +328,6 @@ if ($id > 0 || ! empty($ref)) print ''; $notdefined=0; - $productstatic->ref=$value['ref']; $nb_of_subproduct = $value['nb']; print ''; @@ -355,7 +337,7 @@ if ($id > 0 || ! empty($ref)) print ''; + // Best selling price + $pricesell=$productstatic->price; + if (! empty($conf->global->PRODUIT_MULTIPRICES)) + { + $pricesell='Variable'; + } + $totallinesell=price2num($value['nb'] * ($pricesell), 'MT'); + $totalsell+=$totallinesell; + print ''; + // Stock if (! empty($conf->stock->enabled)) print ''; // Real stock @@ -416,7 +411,7 @@ if ($id > 0 || ! empty($ref)) // Minimum buying price print ''; print ''; + // Minimum selling price + print ''; + + print ''; + // Stock if (! empty($conf->stock->enabled)) print ''; @@ -464,24 +469,22 @@ if ($id > 0 || ! empty($ref)) print load_fiche_titre($langs->trans("ProductToAddSearch"),'',''); print ''; - print '
'.$langs->trans('ParentProduct').''.$langs->trans('ParentProducts').''.$langs->trans('Label').''.$langs->trans('Qty').''.$langs->trans('ComposedProduct').''.$langs->trans('Label').''.$langs->trans('MinSupplierPrice').''.$langs->trans('MinCustomerPrice').''.$langs->trans('Stock').''.$langs->trans('Qty').''.$langs->trans('ComposedProductIncDecStock').'
'.$productstatic->getNomUrl(1,'composition').''; if ($product_fourn->find_min_price_product_fournisseur($productstatic->id) > 0) { - print '   '.$langs->trans("BuyingPriceMinShort").': '; + print $langs->trans("BuyingPriceMinShort").': '; if ($product_fourn->product_fourn_price_id > 0) print $product_fourn->display_price_product_fournisseur(0,0); else { print $langs->trans("NotDefined"); $notdefined++; $atleastonenotdefined++; } } @@ -363,10 +345,23 @@ if ($id > 0 || ! empty($ref)) $totalline=price2num($value['nb'] * ($product_fourn->fourn_unitprice * (1 - $product_fourn->fourn_remise_percent/100) + $product_fourn->fourn_unitcharges - $product_fourn->fourn_remise), 'MT'); $total+=$totalline; + print ''; print ($notdefined?'':($value['nb']> 1 ? $value['nb'].'x' : '').price($product_fourn->fourn_unitprice,'','',0,0,-1,$conf->currency)); print ''; + print ($notdefined?'':($value['nb']> 1 ? $value['nb'].'x' : '').price($pricesell,'','',0,0,-1,$conf->currency)); + print ''.$value['stock'].''; - print $langs->trans("TotalBuyingPriceMin"); + print $langs->trans("TotalBuyingPriceMinShort"); print ''; @@ -424,6 +419,16 @@ if ($id > 0 || ! empty($ref)) print ($atleastonenotdefined?'':price($total,'','',0,0,-1,$conf->currency)); print ''; + print $langs->trans("TotalSellingPriceMinShort"); + print ''; + if ($atleastonenotdefined) print $langs->trans("Unknown").' ('.$langs->trans("SomeSubProductHaveNoPrices").')'; + print ($atleastonenotdefined?'':price($totalsell,'','',0,0,-1,$conf->currency)); + print ' 
'; - print ''; - print ''; + print '
'; + print ''; + print $langs->trans("KeywordFilter").': '; + print '   '; + print '
'; if (! empty($conf->categorie->enabled)) { require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; - print ''; - print ''; + print '
'.$langs->trans("CategoryFilter").': '; + print $form->select_all_categories(Categorie::TYPE_PRODUCT, $parent).'  
'; } - print '
'; - print ''; - print $langs->trans("KeywordFilter").'   '; - print ''; print ''; print ''; - print ''; - print ''; - print '
'.$langs->trans("CategoryFilter").'   '.$form->select_all_categories(Categorie::TYPE_PRODUCT, $parent).'
'; + print '
'; + print ''; + print '
'; print ''; } @@ -494,7 +497,7 @@ if ($id > 0 || ! empty($ref)) print ''; print ''; print ''; - print ''; + print '
'; print ''; print ''; + } // Desired stock if (! empty($arrayfields['p.desiredstock']['checked'])) { @@ -506,11 +525,13 @@ else print ' '; print ''; } - // To batch - if (! empty($arrayfields['p.tobatch']['checked'])) print ''; // Stock if (! empty($arrayfields['p.stock']['checked'])) print ''; - // Accountancy code sell + // Stock + if (! empty($arrayfields['stock_virtual']['checked'])) print ''; + // To batch + if (! empty($arrayfields['p.tobatch']['checked'])) print ''; + // Accountancy code sell if (! empty($arrayfields['p.accountancy_code_sell']['checked'])) print ''; // Accountancy code sell if (! empty($arrayfields['p.accountancy_code_buy']['checked'])) print ''; @@ -591,7 +612,16 @@ else $product_static->status_buy = $objp->tobuy; $product_static->status = $objp->tosell; $product_static->entity = $objp->entity; - + + if (! empty($conf->stock->enabled) && $user->rights->stock->lire && $type != 1) // To optimize call of load_stock + { + if ($objp->fk_product_type != 1) // Not a service + { + $product_static->load_stock('nobatch'); // Load stock_reel + stock_warehouse. This also call load_virtual_stock() + } + } + + $var=!$var; print ''; @@ -672,15 +702,16 @@ else print ''; } - if (! empty($conf->stock->enabled) && $user->rights->stock->lire && $type != 1) // To optimize call of load_stock - { + // Limit alert + if (! empty($arrayfields['p.seuil_stock_alerte']['checked'])) + { + print ''; + } // Desired stock if (! empty($arrayfields['p.desiredstock']['checked'])) { @@ -691,24 +722,35 @@ else } print ''; } - // Desired stock - if (! empty($arrayfields['p.tobatch']['checked'])) - { - print ''; - } // Stock if (! empty($arrayfields['p.stock']['checked'])) { print ''; } + // Stock + if (! empty($arrayfields['stock_virtual']['checked'])) + { + print ''; + } + // Lot/Serial + if (! empty($arrayfields['p.tobatch']['checked'])) + { + print ''; + } // Accountancy code sell if (! empty($arrayfields['p.accountancy_code_sell']['checked'])) print ''; // Accountancy code sell diff --git a/htdocs/product/reassort.php b/htdocs/product/reassort.php index 27f85cd90ab..a3465480b24 100644 --- a/htdocs/product/reassort.php +++ b/htdocs/product/reassort.php @@ -29,6 +29,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; +require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php'; $langs->load("products"); $langs->load("stocks"); @@ -84,6 +85,13 @@ if (! empty($_POST["button_removefilter_x"])) $toolowstock=''; } +// Define virtualdiffersfromphysical +$virtualdiffersfromphysical=0; +if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) +{ + $virtualdiffersfromphysical=1; // According to increase/decrease stock options, virtual and physical stock may differs. +} + /* @@ -97,6 +105,7 @@ if (! empty($_POST["button_removefilter_x"])) * View */ +$form=new Form($db); $htmlother=new FormOther($db); $title=$langs->trans("ProductsAndServices"); @@ -192,11 +201,11 @@ if ($resql) if ($sref || $snom || $sall || GETPOST('search')) { - print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], "&sref=".$sref."&snom=".$snom."&sall=".$sall."&tosell=".$tosell."&tobuy=".$tobuy.(!empty($search_categ) ? '&search_categ='.$search_categ : '').(!empty($toolowstock) ? '&toolowstock='.$toolowstock : ''), $sortfield, $sortorder,'',$num); + print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], "&sref=".$sref."&snom=".$snom."&sall=".$sall."&tosell=".$tosell."&tobuy=".$tobuy.(!empty($search_categ) ? '&search_categ='.$search_categ : '').(!empty($toolowstock) ? '&toolowstock='.$toolowstock : ''), $sortfield, $sortorder,'',$num, 0, 'title_products'); } else { - print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], "&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&type=$type":"").(!empty($search_categ) ? '&search_categ='.$search_categ : '').(!empty($toolowstock) ? '&toolowstock='.$toolowstock : ''), $sortfield, $sortorder,'',$num); + print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], "&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&type=$type":"").(!empty($search_categ) ? '&search_categ='.$search_categ : '').(!empty($toolowstock) ? '&toolowstock='.$toolowstock : ''), $sortfield, $sortorder,'',$num, 0, 'title_products'); } if (! empty($catid)) @@ -242,6 +251,12 @@ if ($resql) $param="&tosell=$tosell&tobuy=$tobuy".(isset($type)?"&type=$type":"")."&fourn_id=$fourn_id&snom=$snom&sref=$sref"; + $formProduct = new FormProduct($db); + $formProduct->loadWarehouses(); + $warehouses_list = $formProduct->cache_warehouses; + $nb_warehouse = count($warehouses_list); + $colspan_warehouse = $nb_warehouse > 1 ? $nb_warehouse+1 : 1; + print '
'.$langs->trans("ComposedProduct").''; print ''.$langs->trans("Label").''; diff --git a/htdocs/product/fournisseurs.php b/htdocs/product/fournisseurs.php index ce6815911e1..6a76055d3fc 100644 --- a/htdocs/product/fournisseurs.php +++ b/htdocs/product/fournisseurs.php @@ -115,7 +115,7 @@ if (empty($reshook)) } } - if ($action == 'remove_pf') + if ($action == 'confirm_remove_pf') { if ($rowid) // id of product supplier price to remove { @@ -285,6 +285,12 @@ if ($id > 0 || $ref) if ($result) { + if ($action == 'ask_remove_pf') { + $form = new Form($db); + $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?id=' . $id . '&rowid=' . $rowid, $langs->trans('DeleteProductBuyPrice'), $langs->trans('ConfirmDeleteProductBuyPrice'), 'confirm_remove_pf', '', 0, 1); + echo $formconfirm; + } + if ($action <> 'edit' && $action <> 're-edit') { $head=product_prepare_head($object); @@ -680,7 +686,7 @@ if ($id > 0 || $ref) if ($user->rights->produit->creer || $user->rights->service->creer) { print ''.img_edit().""; - print ''.img_picto($langs->trans("Remove"),'disable.png').''; + print ''.img_picto($langs->trans("Remove"),'disable.png').''; } print ''; diff --git a/htdocs/product/list.php b/htdocs/product/list.php index 51e453393a0..1d63964be1c 100644 --- a/htdocs/product/list.php +++ b/htdocs/product/list.php @@ -103,6 +103,13 @@ if ($type=='0') $result=restrictedArea($user,'produit','','','','','',$objcanvas else if ($type=='1') $result=restrictedArea($user,'service','','','','','',$objcanvas); else $result=restrictedArea($user,'produit|service','','','','','',$objcanvas); +// Define virtualdiffersfromphysical +$virtualdiffersfromphysical=0; +if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) +{ + $virtualdiffersfromphysical=1; // According to increase/decrease stock options, virtual and physical stock may differs. +} + // List of fields to search into when doing a "search in all" $fieldstosearchall = array( 'p.ref'=>"Ref", @@ -140,9 +147,11 @@ $arrayfields=array( 'p.duration'=>array('label'=>$langs->trans("Duration"), 'checked'=>($contextpage != 'productlist'), 'enabled'=>(! empty($conf->service->enabled))), 'p.sellprice'=>array('label'=>$titlesellprice, 'checked'=>1, 'enabled'=>empty($conf->global->PRODUIT_MULTIPRICES)), 'p.minbuyprice'=>array('label'=>$langs->trans("BuyingPriceMinShort"), 'checked'=>1, 'enabled'=>(! empty($user->rights->fournisseur->lire))), - 'p.desiredstock'=>array('label'=>$langs->trans("DesiredStock"), 'checked'=>1, 'enabled'=>(! empty($conf->stock->enabled) && $user->rights->stock->lire && $contextpage != 'service')), - 'p.tobatch'=>array('label'=>$langs->trans("ManageLotSerial"), 'checked'=>0, 'enabled'=>(! empty($conf->productbatch->enabled))), + 'p.seuil_stock_alerte'=>array('label'=>$langs->trans("StockLimit"), 'checked'=>0, 'enabled'=>(! empty($conf->stock->enabled) && $user->rights->stock->lire && $contextpage != 'service')), + 'p.desiredstock'=>array('label'=>$langs->trans("DesiredStock"), 'checked'=>1, 'enabled'=>(! empty($conf->stock->enabled) && $user->rights->stock->lire && $contextpage != 'service')), 'p.stock'=>array('label'=>$langs->trans("PhysicalStock"), 'checked'=>1, 'enabled'=>(! empty($conf->stock->enabled) && $user->rights->stock->lire && $contextpage != 'service')), + 'stock_virtual'=>array('label'=>$langs->trans("VirtualStock"), 'checked'=>1, 'enabled'=>(! empty($conf->stock->enabled) && $user->rights->stock->lire && $contextpage != 'service' && $virtualdiffersfromphysical)), + 'p.tobatch'=>array('label'=>$langs->trans("ManageLotSerial"), 'checked'=>0, 'enabled'=>(! empty($conf->productbatch->enabled))), 'p.accountancy_code_sell'=>array('label'=>$langs->trans("ProductAccountancySellCode"), 'checked'=>0), 'p.accountancy_code_buy'=>array('label'=>$langs->trans("ProductAccountancyBuyCode"), 'checked'=>0), 'p.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500), @@ -159,6 +168,7 @@ if (is_array($extrafields->attribute_label) && count($extrafields->attribute_lab } } + /* * Actions @@ -425,9 +435,11 @@ else if (! empty($arrayfields['p.duration']['checked'])) print_liste_field_titre($arrayfields['p.duration']['label'], $_SERVER["PHP_SELF"],"p.duration","",$param,"",$sortfield,$sortorder); if (! empty($arrayfields['p.sellprice']['checked'])) print_liste_field_titre($arrayfields['p.sellprice']['label'], $_SERVER["PHP_SELF"],"","",$param,'align="right"',$sortfield,$sortorder); if (! empty($arrayfields['p.minbuyprice']['checked'])) print_liste_field_titre($arrayfields['p.minbuyprice']['label'], $_SERVER["PHP_SELF"],"","",$param,'align="right"',$sortfield,$sortorder); + if (! empty($arrayfields['p.seuil_stock_alerte']['checked'])) print_liste_field_titre($arrayfields['p.seuil_stock_alerte']['label'], $_SERVER["PHP_SELF"],"p.seuil_stock_alerte","",$param,'align="right"',$sortfield,$sortorder); if (! empty($arrayfields['p.desiredstock']['checked'])) print_liste_field_titre($arrayfields['p.desiredstock']['label'], $_SERVER["PHP_SELF"],"p.desiredstock","",$param,'align="right"',$sortfield,$sortorder); - if (! empty($arrayfields['p.tobatch']['checked'])) print_liste_field_titre($arrayfields['p.tobatch']['label'], $_SERVER["PHP_SELF"],"p.tobatch","",$param,'align="center"',$sortfield,$sortorder); if (! empty($arrayfields['p.stock']['checked'])) print_liste_field_titre($arrayfields['p.stock']['label'], $_SERVER["PHP_SELF"],"p.stock","",$param,'align="right"',$sortfield,$sortorder); + if (! empty($arrayfields['stock_virtual']['checked'])) print_liste_field_titre($arrayfields['stock_virtual']['label'], $_SERVER["PHP_SELF"],"","",$param,'align="right"',$sortfield,$sortorder); + if (! empty($arrayfields['p.tobatch']['checked'])) print_liste_field_titre($arrayfields['p.tobatch']['label'], $_SERVER["PHP_SELF"],"p.tobatch","",$param,'align="center"',$sortfield,$sortorder); if (! empty($arrayfields['p.accountancy_code_sell']['checked'])) print_liste_field_titre($arrayfields['p.accountancy_code_sell']['label'], $_SERVER["PHP_SELF"],"p.accountancy_code_sell","",$param,'',$sortfield,$sortorder); if (! empty($arrayfields['p.accountancy_code_buy']['checked'])) print_liste_field_titre($arrayfields['p.accountancy_code_buy']['label'], $_SERVER["PHP_SELF"],"p.accountancy_code_buy","",$param,'',$sortfield,$sortorder); if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) @@ -499,6 +511,13 @@ else print ' '; print ''; } + // Limit for alert + if (! empty($arrayfields['p.seuil_stock_alerte']['checked'])) + { + print ''; + print ' '; + print ''.$form->selectyesno($search_tobatch, '', '', '', 1).'  '.$form->selectyesno($search_tobatch, '', '', '', 1).'
'; if ($objp->fk_product_type != 1) { - $product_static->id = $objp->rowid; - $product_static->load_stock(); + print $objp->seuil_stock_alerte; } - } - + print ''; - print yn($objp->tobatch); - print ''; if ($objp->fk_product_type != 1) { - if ($product_static->stock_reel < $objp->seuil_stock_alerte) print img_warning($langs->trans("StockTooLow")).' '; + if ($objp->seuil_stock_alerte != '' && $product_static->stock_reel < (float) $objp->seuil_stock_alerte) print img_warning($langs->trans("StockTooLow")).' '; print $product_static->stock_reel; } print ''; + if ($objp->fk_product_type != 1) + { + if ($objp->seuil_stock_alerte != '' && $product_static->stock_theorique < (float) $objp->seuil_stock_alerte) print img_warning($langs->trans("StockTooLow")).' '; + print $product_static->stock_theorique; + } + print ''; + print yn($objp->tobatch); + print ''.$objp->accountancy_code_sell.'
'; // Lignes des titres @@ -252,8 +267,20 @@ if ($resql) print_liste_field_titre($langs->trans("StockLimit"), $_SERVER["PHP_SELF"], "p.seuil_stock_alerte",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("DesiredStock"), $_SERVER["PHP_SELF"], "p.desiredstock",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("PhysicalStock"), $_SERVER["PHP_SELF"], "stock_physique",$param,"",'align="right"',$sortfield,$sortorder); - // TODO Add info of running suppliers/customers orders - //print_liste_field_titre($langs->trans("TheoreticalStock"),$_SERVER["PHP_SELF"], "stock_theorique",$param,"",'align="right"',$sortfield,$sortorder); + + /* + * Details per warehouse + */ + + if($nb_warehouse>1) { + + foreach($warehouses_list as &$wh) { + print_liste_field_titre($wh['label'], '', '','','','align="right"'); + } + + } + + if ($virtualdiffersfromphysical) print_liste_field_titre($langs->trans("VirtualStock"),$_SERVER["PHP_SELF"], "stock_theorique",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre(''); print_liste_field_titre($langs->trans("Status").' ('.$langs->trans("Sell").')',$_SERVER["PHP_SELF"], "p.tosell",$param,"",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Status").' ('.$langs->trans("Buy").')',$_SERVER["PHP_SELF"], "p.tobuy",$param,"",'align="right"',$sortfield,$sortorder); @@ -267,59 +294,42 @@ if ($resql) print ''; + // Duration if (! empty($conf->service->enabled) && $type == 1) { print ''; } - // Lot/Serial + // Stock limit print ''; print ''; print ''; + if ($virtualdiffersfromphysical) print ''; print ''; - print ''; - print ''; + print ''; + print ''; print ''; - $product_static=new Product($db); - $var=True; while ($i < min($num,$limit)) { $objp = $db->fetch_object($resql); - // Multilangs - if (! empty($conf->global->MAIN_MULTILANGS)) // si l'option est active - { - $sql = "SELECT label"; - $sql.= " FROM ".MAIN_DB_PREFIX."product_lang"; - $sql.= " WHERE fk_product=".$objp->rowid; - $sql.= " AND lang='". $langs->getDefaultLang() ."'"; - $sql.= " LIMIT 1"; - - $result = $db->query($sql); - if ($result) - { - $objtp = $db->fetch_object($result); - if (! empty($objtp->label)) $objp->label = $objtp->label; - } - } - $var=!$var; print ''; - print ''; + print ''; if (! empty($conf->service->enabled) && $type == 1) { @@ -333,13 +343,40 @@ if ($resql) //print ''; print ''; print ''; + // Real stock print ''; - print ''; - print ''; - print ''; + + /* + * Details per warehouse + */ + + if($nb_warehouse>1) { + + foreach($warehouses_list as &$wh) { + + print ''; + } + + } + + + + // Virtual stock + if ($virtualdiffersfromphysical) + { + print ''; + } + print ''; + print ''; + print ''; print "\n"; $i++; } diff --git a/htdocs/product/reassortlot.php b/htdocs/product/reassortlot.php index 3b77f9c5ba7..b23a1cbf25c 100644 --- a/htdocs/product/reassortlot.php +++ b/htdocs/product/reassortlot.php @@ -100,6 +100,7 @@ if (! empty($_POST["button_removefilter_x"])) * View */ +$form=new Form($db); $htmlother=new FormOther($db); $title=$langs->trans("ProductsAndServices"); @@ -204,11 +205,11 @@ if ($resql) if ($sref || $snom || $sall || GETPOST('search')) { - print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], "&sref=".$sref."&snom=".$snom."&sall=".$sall."&tosell=".$tosell."&tobuy=".$tobuy, $sortfield, $sortorder,'',$num); + print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], "&sref=".$sref."&snom=".$snom."&sall=".$sall."&tosell=".$tosell."&tobuy=".$tobuy, $sortfield, $sortorder,'',$num, 0, 'title_products'); } else { - print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], "&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&type=$type":""), $sortfield, $sortorder,'',$num); + print_barre_liste($texte, $page, $_SERVER["PHP_SELF"], "&sref=$sref&snom=$snom&fourn_id=$fourn_id".(isset($type)?"&type=$type":""), $sortfield, $sortorder,'',$num, 0, 'title_products'); } if (! empty($catid)) diff --git a/htdocs/product/stock/card.php b/htdocs/product/stock/card.php index 430e042c202..f34f4482a49 100644 --- a/htdocs/product/stock/card.php +++ b/htdocs/product/stock/card.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005 Simon Tosser * Copyright (C) 2005-2014 Regis Houssin + * Copyright (C) 2016 Francis Appels * * 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 @@ -53,6 +54,7 @@ $result=restrictedArea($user,'stock'); // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array $hookmanager->initHooks(array('warehousecard','globalcard')); +$object = new Entrepot($db); /* * Actions @@ -61,8 +63,6 @@ $hookmanager->initHooks(array('warehousecard','globalcard')); // Ajout entrepot if ($action == 'add' && $user->rights->stock->creer) { - $object = new Entrepot($db); - $object->ref = GETPOST("ref"); $object->libelle = GETPOST("libelle"); $object->description = GETPOST("desc"); @@ -107,7 +107,6 @@ if ($action == 'add' && $user->rights->stock->creer) // Delete warehouse if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->stock->supprimer) { - $object = new Entrepot($db); $object->fetch($_REQUEST["id"]); $result=$object->delete($user); if ($result > 0) @@ -125,7 +124,6 @@ if ($action == 'confirm_delete' && $confirm == 'yes' && $user->rights->stock->su // Modification entrepot if ($action == 'update' && $cancel <> $langs->trans("Cancel")) { - $object = new Entrepot($db); if ($object->fetch($id)) { $object->libelle = GETPOST("libelle"); @@ -215,11 +213,20 @@ if ($action == 'create') print $form->select_country((!empty($object->country_id)?$object->country_id:$mysoc->country_code),'country_id'); if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1); print ''; - + // Status print ''; @@ -558,8 +565,17 @@ else print ''; diff --git a/htdocs/product/stock/class/entrepot.class.php b/htdocs/product/stock/class/entrepot.class.php index 0f88792f2e4..afcaec0bc6b 100644 --- a/htdocs/product/stock/class/entrepot.class.php +++ b/htdocs/product/stock/class/entrepot.class.php @@ -3,6 +3,7 @@ * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005-2008 Regis Houssin * Copyright (C) 2011 Juanjo Menent + * Copyright (C) 2016 Francis Appels * * 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 @@ -34,18 +35,45 @@ class Entrepot extends CommonObject { public $element='stock'; public $table_element='entrepot'; + + /** + * Warehouse closed, inactive + */ + const STATUS_CLOSED = 0; + + /** + * Warehouse open and operations for customer shipping, supplier dispatch, internal stock transfers/corrections allowed. + */ + const STATUS_OPEN_ALL = 1; + + /** + * Warehouse open and operations for stock transfers/corrections allowed (not for customer shipping and supplier dispatch). + */ + const STATUS_OPEN_INTERNAL = 2; + + /** + * Warehouse open and operations for customer shipping and internal stock transfers/corrections allowed (not for supplier dispatch). + */ + const STATUS_OPEN_SHIPPING = 3; + + /** + * Warehouse open and operations for supplier dispatch internal stock transfers/corrections allowed (not for customer shipping). + */ + const STATUS_OPEN_DISPATCH = 4; + var $libelle; var $description; - //! Statut 1 pour ouvert, 0 pour ferme var $statut; var $lieu; var $address; //! Code Postal var $zip; var $town; - - + + // List of short language codes for status + var $statuts = array(); + /** * Constructor * @@ -53,11 +81,22 @@ class Entrepot extends CommonObject */ function __construct($db) { + global $conf; $this->db = $db; - // List of short language codes for status - $this->statuts[0] = 'Closed2'; - $this->statuts[1] = 'Opened'; + $this->statuts[self::STATUS_CLOSED] = 'Closed2'; + if ($conf->global->ENTREPOT_EXTRA_STATUS) + { + $this->statuts[self::STATUS_OPEN_ALL] = 'OpenAll'; + $this->statuts[self::STATUS_OPEN_INTERNAL] = 'OpenInternal'; + $this->statuts[self::STATUS_OPEN_SHIPPING] = 'OpenShipping'; + $this->statuts[self::STATUS_OPEN_DISPATCH] = 'OpenDispatch'; + } + else + { + $this->statuts[self::STATUS_OPEN_ALL] = 'Opened'; + } + } /** @@ -455,42 +494,40 @@ class Entrepot extends CommonObject function LibStatut($statut,$mode=0) { global $langs; + $langs->load('stocks'); + + $picto = 'statut5'; + $label = $langs->trans($this->statuts[$statut]); + if ($mode == 0) { - $prefix=''; - if ($statut == 0) return $langs->trans($this->statuts[$statut]); - if ($statut == 1) return $langs->trans($this->statuts[$statut]); + return $label; } if ($mode == 1) { - $prefix='Short'; - if ($statut == 0) return $langs->trans($this->statuts[$statut]); - if ($statut == 1) return $langs->trans($this->statuts[$statut]); + return $label; } if ($mode == 2) { - $prefix='Short'; - if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]),'statut5').' '.$langs->trans($this->statuts[$statut]); - if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]); + if ($statut > 0) $picto = 'statut4'; + return img_picto($label, $picto).' '.$label; } if ($mode == 3) { - $prefix='Short'; - if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]),'statut5'); - if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]),'statut4'); + if ($statut > 0) $picto = 'statut4'; + return img_picto($label, $picto).' '.$label; } if ($mode == 4) { - if ($statut == 0) return img_picto($langs->trans($this->statuts[$statut]),'statut5').' '.$langs->trans($this->statuts[$statut]); - if ($statut == 1) return img_picto($langs->trans($this->statuts[$statut]),'statut4').' '.$langs->trans($this->statuts[$statut]); + if ($statut > 0) $picto = 'statut4'; + return img_picto($label, $picto).' '.$label; } if ($mode == 5) { - $prefix='Short'; - if ($statut == 0) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut5'); - if ($statut == 1) return $langs->trans($this->statuts[$statut]).' '.img_picto($langs->trans($this->statuts[$statut]),'statut4'); + if ($statut > 0) $picto = 'statut4'; + return $label.' '.img_picto($label, $picto); } } diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index 652c6d9dc36..944fb3f8dfb 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -220,10 +220,9 @@ class MouvementStock extends CommonObject $oldqty=$product->stock_reel; $oldpmp=$product->pmp; $oldqtywarehouse=0; - //$oldpmpwarehouse=0; // Test if there is already a record for couple (warehouse / product) - $num = 0; + $alreadyarecord = 0; if (! $error) { $sql = "SELECT rowid, reel FROM ".MAIN_DB_PREFIX."product_stock"; @@ -236,9 +235,8 @@ class MouvementStock extends CommonObject $obj = $this->db->fetch_object($resql); if ($obj) { - $num = 1; + $alreadyarecord = 1; $oldqtywarehouse = $obj->reel; - //$oldpmpwarehouse = $obj->pmp; $fk_product_stock = $obj->rowid; } $this->db->free($resql); @@ -252,25 +250,12 @@ class MouvementStock extends CommonObject // Calculate new PMP. $newpmp=0; - //$newpmpwarehouse=0; if (! $error) { // Note: PMP is calculated on stock input only (type of movement = 0 or 3). If type == 0 or 3, qty should be > 0. // Note: Price should always be >0 or 0. PMP should be always >0 (calculated on input) if (($type == 0 || $type == 3) && $price > 0) { - // If we will change PMP for the warehouse we edit and the product, we must first check/clean that PMP is defined - // on every stock entry with old value (so global updated value will match recalculated value from product_stock) - /* $sql = "UPDATE ".MAIN_DB_PREFIX."product_stock SET pmp = ".($oldpmp?$oldpmp:'0'); - $sql.= " WHERE pmp = 0 AND fk_product = ".$fk_product; - dol_syslog(get_class($this)."::_create", LOG_DEBUG); - $resql=$this->db->query($sql); - if (! $resql) - { - $this->errors[]=$this->db->lasterror(); - $error = -4; - } - */ $oldqtytouse=($oldqty >= 0?$oldqty:0); // We make a test on oldpmp>0 to avoid to use normal rule on old data with no pmp field defined if ($oldpmp > 0) $newpmp=price2num((($oldqtytouse * $oldpmp) + ($qty * $price)) / ($oldqtytouse + $qty), 'MU'); @@ -278,13 +263,8 @@ class MouvementStock extends CommonObject { $newpmp=$price; // For this product, PMP was not yet set. We set it to input price. } - /* - $oldqtywarehousetouse=$oldqtywarehouse; - if ($oldpmpwarehouse > 0) $newpmpwarehouse=price2num((($oldqtywarehousetouse * $oldpmpwarehouse) + ($qty * $price)) / ($oldqtywarehousetouse + $qty), 'MU'); - else $newpmpwarehouse=$price; - */ - //print "oldqtytouse=".$oldqtytouse." oldpmp=".$oldpmp." oldqtywarehousetouse=".$oldqtywarehousetouse." oldpmpwarehouse=".$oldpmpwarehouse." "; - //print "qty=".$qty." newpmp=".$newpmp." newpmpwarehouse=".$newpmpwarehouse; + //print "oldqtytouse=".$oldqtytouse." oldpmp=".$oldpmp." oldqtywarehousetouse=".$oldqtywarehousetouse." "; + //print "qty=".$qty." newpmp=".$newpmp; //exit; } else if ($type == 1 || $type == 2) @@ -295,14 +275,13 @@ class MouvementStock extends CommonObject else { $newpmp = $oldpmp; - //$newpmpwarehouse = $oldpmpwarehouse; } } // Update stock quantity if (! $error) { - if ($num > 0) + if ($alreadyarecord > 0) { $sql = "UPDATE ".MAIN_DB_PREFIX."product_stock SET reel = reel + ".$qty; $sql.= " WHERE fk_entrepot = ".$entrepot_id." AND fk_product = ".$fk_product; @@ -339,11 +318,13 @@ class MouvementStock extends CommonObject // Update PMP and denormalized value of stock qty at product level if (! $error) { - $sql = "UPDATE ".MAIN_DB_PREFIX."product SET pmp = ".$newpmp.", stock = ".$this->db->ifsql("stock IS NULL", 0, "stock") . " + ".$qty; + // $sql = "UPDATE ".MAIN_DB_PREFIX."product SET pmp = ".$newpmp.", stock = ".$this->db->ifsql("stock IS NULL", 0, "stock") . " + ".$qty; + // $sql.= " WHERE rowid = ".$fk_product; + // Update pmp + denormalized fields because we change content of produt_stock. Warning: Do not use "SET p.stock", does not works with pgsql + $sql = "UPDATE ".MAIN_DB_PREFIX."product as p SET p.pmp = ".$newpmp.", "; + $sql.= " stock=(SELECT SUM(ps.reel) FROM ".MAIN_DB_PREFIX."product_stock ps WHERE ps.fk_product = p.rowid)"; $sql.= " WHERE rowid = ".$fk_product; - // May be this request is better: - // UPDATE llx_product p SET p.stock= (SELECT SUM(ps.reel) FROM llx_product_stock ps WHERE ps.fk_product = p.rowid); - + print $sql; dol_syslog(get_class($this)."::_create", LOG_DEBUG); $resql=$this->db->query($sql); if (! $resql) @@ -352,6 +333,12 @@ class MouvementStock extends CommonObject $error = -4; } } + + // If stock is now 0, we can remove entry into llx_stock_product, but only if there is no child lines into llx_product_batch (detail of batch, because we can imagine + // having a lot1/qty=X and lot2/qty=-X, so 0 but we must not loose repartition of different lot. + $sql="DELETE FROM ".MAIN_DB_PREFIX."product_stock WHERE reel = 0 AND rowid NOT IN (SELECT fk_product_stock FROM ".MAIN_DB_PREFIX."product_batch as pb)"; + $resql=$this->db->query($sql); + // We do not test error, it can fails if there is child in batch details } // Add movement for sub products (recursive call) @@ -543,7 +530,7 @@ class MouvementStock extends CommonObject * Create or update batch record (update table llx_product_batch) * * @param array|int $dluo Could be either - * - int if id of product_batch + * - int if row id of product_batch table * - or complete array('fk_product_stock'=>, 'eatby'=>, 'sellby'=> , 'batchnumber'=>) * @param int $qty Quantity of product with batch number. May be a negative amount. * @return int <0 if KO, else return productbatch id diff --git a/htdocs/product/stock/massstockmove.php b/htdocs/product/stock/massstockmove.php index 7d62699b425..c7b7ed41034 100644 --- a/htdocs/product/stock/massstockmove.php +++ b/htdocs/product/stock/massstockmove.php @@ -185,7 +185,7 @@ if ($action == 'createmovements') { $result=$product->fetch($id_product); - $product->load_stock(); // Load array product->stock_warehouse + $product->load_stock('novirtual'); // Load array product->stock_warehouse // Define value of products moved $pricesrc=0; diff --git a/htdocs/product/stock/mouvement.php b/htdocs/product/stock/mouvement.php index 190bf676c8a..29ee33c56eb 100644 --- a/htdocs/product/stock/mouvement.php +++ b/htdocs/product/stock/mouvement.php @@ -207,11 +207,10 @@ if ($action == "transfert_stock" && ! $cancel) $db->begin(); - $product->load_stock(); // Load array product->stock_warehouse + $product->load_stock('novirtual'); // Load array product->stock_warehouse // Define value of products moved $pricesrc=0; - //if (isset($product->stock_warehouse[GETPOST("id_entrepot_source")]->pmp)) $pricesrc=$product->stock_warehouse[GETPOST("id_entrepot_source")]->pmp; if (isset($product->pmp)) $pricesrc=$product->pmp; $pricedest=$pricesrc; diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php index de30bc3d0b6..05b0aecf5b6 100644 --- a/htdocs/product/stock/product.php +++ b/htdocs/product/stock/product.php @@ -185,7 +185,7 @@ if ($action == "correct_stock" && ! $cancel) // Transfer stock from a warehouse to another warehouse if ($action == "transfert_stock" && ! $cancel) { - if (! (GETPOST("id_entrepot_source",'int') > 0) || ! (GETPOST("id_entrepot_destination",'int') > 0)) + if (! (GETPOST("id_entrepot",'int') > 0) || ! (GETPOST("id_entrepot_destination",'int') > 0)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Warehouse")), null, 'errors'); $error++; @@ -197,7 +197,7 @@ if ($action == "transfert_stock" && ! $cancel) $error++; $action='transfert'; } - if (GETPOST("id_entrepot_source",'int') == GETPOST("id_entrepot_destination",'int')) + if (GETPOST("id_entrepot",'int') == GETPOST("id_entrepot_destination",'int')) { setEventMessages($langs->trans("ErrorSrcAndTargetWarehouseMustDiffers"), null, 'errors'); $error++; @@ -225,7 +225,7 @@ if ($action == "transfert_stock" && ! $cancel) $db->begin(); - $object->load_stock(); // Load array product->stock_warehouse + $object->load_stock('novirtual'); // Load array product->stock_warehouse // Define value of products moved $pricesrc=0; @@ -254,7 +254,7 @@ if ($action == "transfert_stock" && ! $cancel) } else { - $srcwarehouseid=GETPOST('id_entrepot_source','int'); + $srcwarehouseid=GETPOST('id_entrepot','int'); $batch=GETPOST('batch_number'); $eatby=$d_eatby; $sellby=$d_sellby; @@ -291,7 +291,7 @@ if ($action == "transfert_stock" && ! $cancel) // Remove stock $result1=$object->correct_stock( $user, - GETPOST("id_entrepot_source"), + GETPOST("id_entrepot"), GETPOST("nbpiece"), 1, GETPOST("label"), @@ -390,6 +390,7 @@ if ($id > 0 || $ref) { $object = new Product($db); $result = $object->fetch($id,$ref); + $object->load_stock(); $help_url='EN:Module_Stocks_En|FR:Module_Stock|ES:Módulo_Stocks'; @@ -480,7 +481,6 @@ if ($id > 0 || $ref) print ''; // Real stock - $object->load_stock(); $text_stock_options = ''; $text_stock_options.= (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)?$langs->trans("DeStockOnShipment").'
':''); $text_stock_options.= (! empty($conf->global->STOCK_CALCULATE_ON_VALIDATE_ORDER)?$langs->trans("DeStockOnValidateOrder").'
':''); @@ -702,9 +702,10 @@ if ($resql) $entrepotstatic->id=$obj->rowid; $entrepotstatic->libelle=$obj->label; $entrepotstatic->lieu=$obj->lieu; + $stock_real = round($obj->reel, 10); print '
'; print ''; - print ''; + print ''; // PMP print ''; // Value purchase diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index c31699a12ef..7af08ee6575 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -69,6 +69,13 @@ if (!$sortorder) { $sortorder = 'ASC'; } +// Define virtualdiffersfromphysical +$virtualdiffersfromphysical=0; +if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) +{ + $virtualdiffersfromphysical=1; // According to increase/decrease stock options, virtual and physical stock may differs. +} + /* * Actions @@ -227,20 +234,6 @@ if ($action == 'order' && isset($_POST['valid'])) $form = new Form($db); -$virtualdiffersfromphysical=0; -if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) || ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)) -{ - $virtualdiffersfromphysical=1; // According to increase/decrease stock options, virtual and physical stock may differs. -} - -$usevirtualstock=-1; -if ($virtualdiffersfromphysical) -{ - $usevirtualstock=(! empty($conf->global->STOCK_USE_VIRTUAL_STOCK)?1:0); - if ($mode=='virtual') $usevirtualstock=1; - if ($mode=='physical') $usevirtualstock=0; -} - $title = $langs->trans('Status'); $sql = 'SELECT p.rowid, p.ref, p.label, p.price,'; @@ -557,7 +550,7 @@ while ($i < ($limit ? min($num, $limit) : $num)) //print ''; print ''; - print ''; + print ''; print ''; diff --git a/htdocs/projet/activity/perday.php b/htdocs/projet/activity/perday.php index 7e23fe123d0..ada7e0bb7d4 100644 --- a/htdocs/projet/activity/perday.php +++ b/htdocs/projet/activity/perday.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2015 Laurent Destailleur + * Copyright (C) 2004-2016 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin * Copyright (C) 2010 François Legastelois * @@ -192,9 +192,10 @@ if ($action == 'addtime' && $user->rights->projet->creer) foreach($timespent_duration as $key => $val) { $object->fetch($key); - $object->progress = GETPOST($key . 'progress', 'int'); + $object->progress = GETPOST($key.'progress', 'int'); $object->timespent_duration = $val; $object->timespent_fk_user = $user->id; + $object->timespent_note = GETPOST($key.'note'); if (GETPOST($key."hour") != '' && GETPOST($key."hour") >= 0) // If hour was entered { $object->timespent_date = dol_mktime(GETPOST($key."hour"),GETPOST($key."min"),0,$monthofday,$dayofday,$yearofday); @@ -385,6 +386,7 @@ if ($usertoprocess->id == $user->id) print ''; print ''; print ''; +print ''; print "\n"; // By default, we can edit only tasks we are assigned to diff --git a/htdocs/projet/admin/project.php b/htdocs/projet/admin/project.php index ca351f7d1bb..5233832ea05 100644 --- a/htdocs/projet/admin/project.php +++ b/htdocs/projet/admin/project.php @@ -933,7 +933,22 @@ else print ''; print ""; } -print '
'; print ''; print ''; print ' '; print '      '; - $searchpitco=$form->showFilterAndCheckAddButtons(0); - print $searchpitco; - print ' '; + $searchpitco=$form->showFilterAndCheckAddButtons(0); + print $searchpitco; + print '
'; - $product_static->ref=$objp->ref; - $product_static->id=$objp->rowid; - $product_static->label = $objp->label; - $product_static->type=$objp->fk_product_type; - $product_static->entity=$objp->entity; - print $product_static->getNomUrl(1,'',16); + + $product=new Product($db); + $product->fetch($objp->rowid); + $product->load_stock(); + + print $product->getNomUrl(1,'',16); //if ($objp->stock_theorique < $objp->seuil_stock_alerte) print ' '.img_warning($langs->trans("StockTooLow")); print ''.$objp->label.''.$product->label.''.$objp->stock_theorique.''.$objp->seuil_stock_alerte.''.$objp->desiredstock.''; - if ($objp->seuil_stock_alerte && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; + if ($objp->seuil_stock_alerte != '' && ($objp->stock_physique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; print $objp->stock_physique; print ''.$langs->trans("Movements").''.$product_static->LibStatut($objp->statut,5,0).''.$product_static->LibStatut($objp->tobuy,5,1).''; + print empty($product->stock_warehouse[$wh['id']]->real) ? '0' : $product->stock_warehouse[$wh['id']]->real; + print ''; + if ($objp->seuil_stock_alerte != '' && ($product->stock_theorique < $objp->seuil_stock_alerte)) print img_warning($langs->trans("StockTooLow")).' '; + print $product->stock_theorique; + print ''.$langs->trans("Movements").''.$product->LibStatut($objp->statut,5,0).''.$product->LibStatut($objp->tobuy,5,1).'
'.$langs->trans("Status").''; print ''; print '
'.$langs->trans("Status").''; print ''; print '
'.$entrepotstatic->getNomUrl(1).''.$obj->reel.($obj->reel<0?' '.img_warning():'').''.$stock_real.($stock_real < 0 ?' '.img_warning():'').''.(price2num($object->pmp)?price2num($object->pmp,'MU'):'').''.$prod->getNomUrl(1, '', 16).''.$prod->getNomUrl(1, '').'' . $objp->label . ''.$langs->trans("T else print ''.$langs->trans("TimeSpentByUser").''.$langs->trans("HourStart").''.$langs->trans("Duration").''.$langs->trans("Note").'
'; +print ''; + +$var=!$var; +print ''; +print ''.$langs->trans("AllowToSelectProjectFromOtherCompany").''; + +print ''; +echo ajax_constantonoff('PROJECT_ALLOW_TO_LINK_FROM_OTHER_COMPANY'); +print ''; +print ' '; +print ''; + +print ''; + + + llxFooter(); $db->close(); diff --git a/htdocs/projet/card.php b/htdocs/projet/card.php index 5ef9b0e1ce4..c489910064d 100644 --- a/htdocs/projet/card.php +++ b/htdocs/projet/card.php @@ -852,142 +852,147 @@ else * Boutons actions */ print '
'; - - if ($action != "edit" ) + $parameters = array(); + $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been + // modified by hook + if (empty($reshook)) { - // Modify - if ($object->statut != 2 && $user->rights->projet->creer) - { - if ($userWrite > 0) - { - print ''; - } - else - { - print ''; - } - } - - // Validate - if ($object->statut == 0 && $user->rights->projet->creer) - { - if ($userWrite > 0) - { - print ''; - } - else - { - print ''; - } - } - - // Close - if (($object->statut == 0 || $object->statut == 1) && $user->rights->projet->creer) - { - if ($userWrite > 0) - { - print ''; - } - else - { - print ''; - } - } - - // Reopen - if ($object->statut == 2 && $user->rights->projet->creer) - { - if ($userWrite > 0) - { - print ''; - } - else - { - print ''; - } - } - - // Add button to create objects from project - if (! empty($conf->global->PROJECT_SHOW_CREATE_OBJECT_BUTTON)) - { - if (! empty($conf->propal->enabled) && $user->rights->propal->creer) - { - $langs->load("propal"); - print ''; - } - if (! empty($conf->commande->enabled) && $user->rights->commande->creer) - { - $langs->load("orders"); - print ''; - } - if (! empty($conf->facture->enabled) && $user->rights->facture->creer) - { - $langs->load("bills"); - print ''; - } - if (! empty($conf->supplier_proposal->enabled) && $user->rights->supplier_proposal->creer) - { - $langs->load("supplier_proposal"); - print ''; - } - if (! empty($conf->supplier_order->enabled) && $user->rights->fournisseur->commande->creer) - { - $langs->load("suppliers"); - print ''; - } - if (! empty($conf->supplier_invoice->enabled) && $user->rights->fournisseur->facture->creer) - { - $langs->load("suppliers"); - print ''; - } - if (! empty($conf->ficheinter->enabled) && $user->rights->ficheinter->creer) - { - $langs->load("interventions"); - print ''; - } - if (! empty($conf->contrat->enabled) && $user->rights->contrat->creer) - { - $langs->load("contracts"); - print ''; - } - if (! empty($conf->expensereport->enabled) && $user->rights->expensereport->creer) - { - $langs->load("expensereports"); - $langs->load("trips"); - print ''; - } - if (! empty($conf->don->enabled) && $user->rights->don->creer) - { - $langs->load("donations"); - print ''; - } - } - - // Clone - if ($user->rights->projet->creer) - { - if ($userWrite > 0) - { - print ''; - } - else - { - print ''; - } - } - - // Delete - if ($user->rights->projet->supprimer) - { - if ($userDelete > 0) - { - print ''; - } - else - { - print ''; - } - } + if ($action != "edit" ) + { + // Modify + if ($object->statut != 2 && $user->rights->projet->creer) + { + if ($userWrite > 0) + { + print ''; + } + else + { + print ''; + } + } + + // Validate + if ($object->statut == 0 && $user->rights->projet->creer) + { + if ($userWrite > 0) + { + print ''; + } + else + { + print ''; + } + } + + // Close + if (($object->statut == 0 || $object->statut == 1) && $user->rights->projet->creer) + { + if ($userWrite > 0) + { + print ''; + } + else + { + print ''; + } + } + + // Reopen + if ($object->statut == 2 && $user->rights->projet->creer) + { + if ($userWrite > 0) + { + print ''; + } + else + { + print ''; + } + } + + // Add button to create objects from project + if (! empty($conf->global->PROJECT_SHOW_CREATE_OBJECT_BUTTON)) + { + if (! empty($conf->propal->enabled) && $user->rights->propal->creer) + { + $langs->load("propal"); + print ''; + } + if (! empty($conf->commande->enabled) && $user->rights->commande->creer) + { + $langs->load("orders"); + print ''; + } + if (! empty($conf->facture->enabled) && $user->rights->facture->creer) + { + $langs->load("bills"); + print ''; + } + if (! empty($conf->supplier_proposal->enabled) && $user->rights->supplier_proposal->creer) + { + $langs->load("supplier_proposal"); + print ''; + } + if (! empty($conf->supplier_order->enabled) && $user->rights->fournisseur->commande->creer) + { + $langs->load("suppliers"); + print ''; + } + if (! empty($conf->supplier_invoice->enabled) && $user->rights->fournisseur->facture->creer) + { + $langs->load("suppliers"); + print ''; + } + if (! empty($conf->ficheinter->enabled) && $user->rights->ficheinter->creer) + { + $langs->load("interventions"); + print ''; + } + if (! empty($conf->contrat->enabled) && $user->rights->contrat->creer) + { + $langs->load("contracts"); + print ''; + } + if (! empty($conf->expensereport->enabled) && $user->rights->expensereport->creer) + { + $langs->load("expensereports"); + $langs->load("trips"); + print ''; + } + if (! empty($conf->don->enabled) && $user->rights->don->creer) + { + $langs->load("donations"); + print ''; + } + } + + // Clone + if ($user->rights->projet->creer) + { + if ($userWrite > 0) + { + print ''; + } + else + { + print ''; + } + } + + // Delete + if ($user->rights->projet->supprimer) + { + if ($userDelete > 0) + { + print ''; + } + else + { + print ''; + } + } + } } print "
"; diff --git a/htdocs/projet/tasks/task.php b/htdocs/projet/tasks/task.php index 1a3b1921713..8c1d1fc40cb 100644 --- a/htdocs/projet/tasks/task.php +++ b/htdocs/projet/tasks/task.php @@ -489,31 +489,38 @@ if ($id > 0 || ! empty($ref)) { /* * Actions - */ - print '
'; - - // Modify - if ($user->rights->projet->creer) - { - print ''.$langs->trans('Modify').''; - } - else - { - print ''.$langs->trans('Modify').''; - } - - // Delete - if ($user->rights->projet->supprimer && ! $object->hasChildren()) - { - print ''.$langs->trans('Delete').''; - } - else - { - print ''.$langs->trans('Delete').''; - } - - print '
'; + */ + + print '
'; + $parameters = array(); + $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been + // modified by hook + if (empty($reshook)) + { + // Modify + if ($user->rights->projet->creer) + { + print ''.$langs->trans('Modify').''; + } + else + { + print ''.$langs->trans('Modify').''; + } + + // Delete + if ($user->rights->projet->supprimer && ! $object->hasChildren()) + { + print ''.$langs->trans('Delete').''; + } + else + { + print ''.$langs->trans('Delete').''; + } + + print '
'; + } + print '
'; print ''; // ancre @@ -530,8 +537,6 @@ if ($id > 0 || ! empty($ref)) $somethingshown=$formfile->show_documents('project_task',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf); - - print '
'; } } diff --git a/htdocs/public/opensurvey/studs.php b/htdocs/public/opensurvey/studs.php index 33bd1ba1373..834f17b8b2c 100644 --- a/htdocs/public/opensurvey/studs.php +++ b/htdocs/public/opensurvey/studs.php @@ -46,7 +46,7 @@ if ($result <= 0) dol_print_error('','Failed to get survey id '.$numsondage); $nblignes=$object->fetch_lines(); //If the survey has not yet finished, then it can be modified -$canbemodified = (empty($object->date_fin) || $object->date_fin > dol_now()); +$canbemodified = ((empty($object->date_fin) || $object->date_fin > dol_now()) && $object->status != Opensurveysondage::STATUS_CLOSED); /* diff --git a/htdocs/public/websites/index.php b/htdocs/public/websites/index.php index fb3133df7cc..4625bc1573a 100644 --- a/htdocs/public/websites/index.php +++ b/htdocs/public/websites/index.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2016 Laurent Destailleur * * 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 @@ -16,16 +16,133 @@ */ /** - * \file htdocs/public/paypal/index.php + * \file htdocs/public/websites/index.php * \ingroup core * \brief A redirect page to an error * \author Laurent Destailleur */ +define('NOTOKENRENEWAL',1); // Disables token renewal +define("NOLOGIN",1); +define("NOCSRFCHECK",1); // We accept to go on this page from external web site. +if (! defined('NOREQUIREMENU')) define('NOREQUIREMENU','1'); +if (! defined('NOREQUIREHTML')) define('NOREQUIREHTML','1'); +if (! defined('NOREQUIREAJAX')) define('NOREQUIREAJAX','1'); + +/** + * Header empty + * + * @return void + */ +function llxHeader() { } +/** + * Footer empty + * + * @return void + */ +function llxFooter() { } + require '../../master.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; + + +$error=0; +$website=GETPOST('website', 'alpha'); +$pageid=GETPOST('page', 'alpha')?GETPOST('page', 'alpha'):GETPOST('pageid', 'alpha'); + +$accessallowed = 1; +$type=''; + + +/* + * View + */ $appli=constant('DOL_APPLICATION_TITLE'); if (!empty($conf->global->MAIN_APPLICATION_TITLE)) $appli=$conf->global->MAIN_APPLICATION_TITLE; -print 'Directory with '.$appli.' websites.
'; +//print 'Directory with '.$appli.' websites.
'; + +if (empty($pageid)) +{ + require_once DOL_DOCUMENT_ROOT.'/websites/class/website.class.php'; + require_once DOL_DOCUMENT_ROOT.'/websites/class/websitepage.class.php'; + + $object=new Website($db); + $object->fetch(0, $website); + + $objectpage=new WebsitePage($db); + $array=$objectpage->fetchAll($object->id); + + if (count($array) > 0) + { + $firstrep=reset($array); + $pageid=$firstrep->id; + } +} +if (empty($pageid)) +{ + $langs->load("website"); + print $langs->trans("PreviewOfSiteNotYetAvailable"); + exit; +} + +// Security: Delete string ../ into $original_file +global $dolibarr_main_data_root; + +if ($pageid == 'css') +{ + header('Content-type: text/css'); + // Important: Following code is to avoid page request by browser and PHP CPU at each Dolibarr page access. + //if (empty($dolibarr_nocache)) header('Cache-Control: max-age=3600, public, must-revalidate'); + //else + header('Cache-Control: no-cache'); + $original_file=$dolibarr_main_data_root.'/websites/'.$website.'/styles.css'; +} +else +{ + $original_file=$dolibarr_main_data_root.'/websites/'.$website.'/page'.$pageid.'.tpl.php'; +} + +// Find the subdirectory name as the reference +$refname=basename(dirname($original_file)."/"); + +// Security: +// Limite acces si droits non corrects +if (! $accessallowed) +{ + accessforbidden(); +} + +// Security: +// On interdit les remontees de repertoire ainsi que les pipe dans +// les noms de fichiers. +if (preg_match('/\.\./',$original_file) || preg_match('/[<>|]/',$original_file)) +{ + dol_syslog("Refused to deliver file ".$original_file); + $file=basename($original_file); // Do no show plain path of original_file in shown error message + dol_print_error(0,$langs->trans("ErrorFileNameInvalid",$file)); + exit; +} + +clearstatcache(); + +$filename = basename($original_file); + +// Output file on browser +dol_syslog("index.php include $original_file $filename content-type=$type"); +$original_file_osencoded=dol_osencode($original_file); // New file name encoded in OS encoding charset + +// This test if file exists should be useless. We keep it to find bug more easily +if (! file_exists($original_file_osencoded)) +{ + $langs->load("website"); + print $langs->trans("RequestedPageHasNoContentYet", $pageid); + //dol_print_error(0,$langs->trans("ErrorFileDoesNotExists",$original_file)); + exit; +} + +include_once $original_file_osencoded; + +if (is_object($db)) $db->close(); diff --git a/htdocs/resource/add.php b/htdocs/resource/add.php index 679ef545442..cf13c79560f 100644 --- a/htdocs/resource/add.php +++ b/htdocs/resource/add.php @@ -1,7 +1,7 @@ - * Copyright (C) 2015 Alexandre Spangaro - * Copyright (C) 2015 Laurent Destailleur +/* Copyright (C) 2013 Jean-François Ferry + * Copyright (C) 2015 Alexandre Spangaro + * Copyright (C) 2015 Laurent Destailleur * * 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 @@ -18,15 +18,14 @@ */ /** - * \file resource/add.php - * \ingroup resource - * \brief Page to manage resource object - * Initialy built by build_class_from_table on 2013-07-24 16:03 + * \file resource/add.php + * \ingroup resource + * \brief Page to manage resource object */ require '../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/resource/class/resource.class.php'; +require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php'; require_once DOL_DOCUMENT_ROOT.'/resource/class/html.formresource.class.php'; // Load traductions files required by page @@ -36,15 +35,15 @@ $langs->load("other"); $langs->load("resource"); // Get parameters -$id = GETPOST('id','int'); -$action = GETPOST('action','alpha'); -$cancel = GETPOST('cancel','alpha'); +$id = GETPOST('id','int'); +$action = GETPOST('action','alpha'); +$cancel = GETPOST('cancel','alpha'); if (empty($sortorder)) $sortorder="DESC"; if (empty($sortfield)) $sortfield="t.rowid"; if (empty($arch)) $arch = 0; if ($page == -1) { - $page = 0 ; + $page = 0 ; } $limit = $conf->global->limit; @@ -56,60 +55,60 @@ $pagenext = $page + 1; // Protection if external user if ($user->societe_id > 0) { - accessforbidden(); + accessforbidden(); } -$object = new Resource($db); +$object = new DolResource($db); if ($action == 'confirm_add_resource') { - if (! $cancel) - { - $error=''; + if (! $cancel) + { + $error=''; - $ref=GETPOST('ref','alpha'); - $description=GETPOST('description','alpha'); - $fk_code_type_resource=GETPOST('fk_code_type_resource','alpha'); + $ref=GETPOST('ref','alpha'); + $description=GETPOST('description','alpha'); + $fk_code_type_resource=GETPOST('fk_code_type_resource','alpha'); - if (empty($ref)) - { - $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")); - setEventMessages($mesg, null, 'errors'); - $error++; - } + if (empty($ref)) + { + $mesg=$langs->trans("ErrorFieldRequired",$langs->transnoentities("Ref")); + setEventMessages($mesg, null, 'errors'); + $error++; + } - if (! $error) - { - $object=new Resource($db); - $object->ref=$ref; - $object->description=$description; - $object->fk_code_type_resource=$fk_code_type_resource; + if (! $error) + { + $object=new Dolresource($db); + $object->ref=$ref; + $object->description=$description; + $object->fk_code_type_resource=$fk_code_type_resource; - $result=$object->create($user); - if ($result > 0) - { - // Creation OK - $db->commit(); - setEventMessages($langs->trans('ResourceCreatedWithSuccess'), null, 'mesgs'); - Header("Location: card.php?id=" . $object->id); - return; - } - else - { - // Creation KO - setEventMessages($object->error, $object->errors, 'errors'); - $action = ''; - } - } - else - { - $action = ''; - } - } - else - { - Header("Location: list.php"); - } + $result=$object->create($user); + if ($result > 0) + { + // Creation OK + $db->commit(); + setEventMessages($langs->trans('ResourceCreatedWithSuccess'), null, 'mesgs'); + Header("Location: card.php?id=" . $object->id); + return; + } + else + { + // Creation KO + setEventMessages($object->error, $object->errors, 'errors'); + $action = ''; + } + } + else + { + $action = ''; + } + } + else + { + Header("Location: list.php"); + } } @@ -122,58 +121,58 @@ $formresource = new FormResource($db); if (! $action) { - $pagetitle=$langs->trans('AddResource'); - llxHeader('',$pagetitle,''); - print load_fiche_titre($pagetitle,'','title_generic'); + $pagetitle=$langs->trans('AddResource'); + llxHeader('',$pagetitle,''); + print load_fiche_titre($pagetitle,'','title_generic'); - print '
'; - print ''; + print ''; + print ''; - dol_fiche_head(''); + dol_fiche_head(''); - print ''; + print '
'; - // Ref / label - $field = 'ref'; - print ''; - print ''; - print ''; - print ''; + // Ref / label + $field = 'ref'; + print ''; + print ''; + print ''; + print ''; - // Type - print ''; - print ''; + // Type + print ''; + print ''; - // Description - $field = 'description'; - print ''; - print ''; - print ''; - print ''; + // Description + $field = 'description'; + print ''; + print ''; + print ''; + print ''; - print '
'; - print $langs->trans('ResourceFormLabel_'.$field); - print ''; - print ''; - print '
'; + print $langs->trans('ResourceFormLabel_'.$field); + print ''; + print ''; + print '
'.$langs->trans("ResourceType").''; - $ret = $formresource->select_types_resource($object->fk_code_type_resource, 'fk_code_type_resource', '', 2, 1); - print '
'.$langs->trans("ResourceType").''; + $ret = $formresource->select_types_resource($object->fk_code_type_resource, 'fk_code_type_resource', '', 2, 1); + print '
'; - print $langs->trans('ResourceFormLabel_'.$field); - print ''; - require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor = new DolEditor($field, $$field, 160, '', '', false); - $doleditor->Create(); - print '
'; + print $langs->trans('ResourceFormLabel_'.$field); + print ''; + require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; + $doleditor = new DolEditor($field, $$field, 160, '', '', false); + $doleditor->Create(); + print '
'; + print ''; - dol_fiche_end(''); + dol_fiche_end(''); - echo '
', - '', - '   ', - '', - '
'; + echo '
', + '', + '   ', + '', + '
'; - print '
'; + print ''; } diff --git a/htdocs/resource/card.php b/htdocs/resource/card.php index 31fb6a955b1..163eeab13ce 100644 --- a/htdocs/resource/card.php +++ b/htdocs/resource/card.php @@ -29,7 +29,7 @@ if (! $res) $res=@include("../../main.inc.php"); // For "custom" directory if (! $res) die("Include of main fails"); require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; -require_once 'class/resource.class.php'; +require_once 'class/dolresource.class.php'; require_once 'class/html.formresource.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/resource.lib.php'; @@ -56,7 +56,7 @@ if ($user->societe_id > 0) if( ! $user->rights->resource->read) accessforbidden(); -$object = new Resource($db); +$object = new Dolresource($db); $hookmanager->initHooks(array('resource_card','globalcard')); $parameters=array('resource_id'=>$id); @@ -152,7 +152,7 @@ $formresource = new FormResource($db); if ( $object->fetch($id) > 0 ) { - $head=resourcePrepareHead($object); + $head=resource_prepare_head($object); if ($action == 'edit' ) diff --git a/htdocs/resource/class/resource.class.php b/htdocs/resource/class/dolresource.class.php similarity index 99% rename from htdocs/resource/class/resource.class.php rename to htdocs/resource/class/dolresource.class.php index bfd4f04c3e5..b6b4eec8be2 100644 --- a/htdocs/resource/class/resource.class.php +++ b/htdocs/resource/class/dolresource.class.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2013-2015 Jean-François Ferry * * 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 @@ -28,7 +28,7 @@ require_once DOL_DOCUMENT_ROOT."/core/lib/functions2.lib.php"; /** * DAO Resource object */ -class Resource extends CommonObject +class Dolresource extends CommonObject { var $element='resource'; //!< Id that identify managed objects var $table_element='resource'; //!< Name of table without prefix where object is stored @@ -414,7 +414,7 @@ class Resource extends CommonObject while ($i < $num) { $obj = $this->db->fetch_object($resql); - $line = new Resource($this->db); + $line = new Dolresource($this->db); $line->id = $obj->rowid; $line->ref = $obj->ref; $line->description = $obj->description; @@ -488,7 +488,7 @@ class Resource extends CommonObject while ($i < $num) { $obj = $this->db->fetch_object($resql); - $line = new Resource($this->db); + $line = new Dolresource($this->db); $line->id = $obj->rowid; $line->resource_id = $obj->resource_id; $line->resource_type = $obj->resource_type; @@ -574,7 +574,7 @@ class Resource extends CommonObject while ($i < $num) { $obj = $this->db->fetch_object($resql); - $line = new Resource($this->db); + $line = new Dolresource($this->db); $line->id = $obj->rowid; $line->resource_id = $obj->resource_id; $line->resource_type = $obj->resource_type; diff --git a/htdocs/resource/class/html.formresource.class.php b/htdocs/resource/class/html.formresource.class.php index 4128de6fead..82b0ebe7d1a 100644 --- a/htdocs/resource/class/html.formresource.class.php +++ b/htdocs/resource/class/html.formresource.class.php @@ -1,5 +1,5 @@ +/* Copyright (C) - 2013-2015 Jean-François FERRY * * 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 @@ -17,7 +17,7 @@ */ /** - * \file place/class/html.place.class.php + * \file place/class/html.formresource.class.php * \ingroup core * \brief Class file to manage forms into resource module */ @@ -75,7 +75,7 @@ class FormResource $out=''; $outarray=array(); - $resourcestat = new Resource($this->db); + $resourcestat = new Dolresource($this->db); $resources_used = $resourcestat->fetch_all('ASC', 't.rowid', $limit, $offset, $filter=''); @@ -159,7 +159,7 @@ class FormResource { global $langs,$user; - $resourcestat = new Resource($this->db); + $resourcestat = new Dolresource($this->db); dol_syslog(get_class($this)."::select_types_resource ".$selected.", ".$htmlname.", ".$filtertype.", ".$format,LOG_DEBUG); diff --git a/htdocs/resource/contact.php b/htdocs/resource/contact.php new file mode 100644 index 00000000000..d635ee2e1e6 --- /dev/null +++ b/htdocs/resource/contact.php @@ -0,0 +1,159 @@ + + * Copyright (C) 2007-2009 Laurent Destailleur + * Copyright (C) 2012 Juanjo Menent + * Copyright (C) 2016 Gilles Poirier + + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/resource/contact.php + * \ingroup resource + * \brief Onglet de gestion des contacts des resources + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php'; +require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/resource.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php'; + +$langs->load("resource"); +$langs->load("sendings"); +$langs->load("companies"); + +$id = GETPOST('id','int'); +$ref = GETPOST('ref', 'alpha'); +$action = GETPOST('action','alpha'); + +// Security check +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'resource', $id, 'resource'); + +$object = new DolResource($db); +$result = $object->fetch($id,$ref); + + +/* + * Ajout d'un nouveau contact + */ + +if ($action == 'addcontact' && $user->rights->resource->write) +{ + if ($result > 0 && $id > 0) + { + $contactid = (GETPOST('userid','int') ? GETPOST('userid','int') : GETPOST('contactid','int')); + $result = $object->add_contact($contactid, GETPOST('type','int'), GETPOST('source','alpha')); + } + + if ($result >= 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } + else + { + if ($object->error == 'DB_ERROR_RECORD_ALREADY_EXISTS') { + $langs->load("errors"); + $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType"); + } else { + $mesg = $object->error; + } + + setEventMessage($mesg, 'errors'); + } +} + +// bascule du statut d'un contact +else if ($action == 'swapstatut' && $user->rights->resource->write) +{ + $result=$object->swapContactStatus(GETPOST('ligne','int')); +} + +// Efface un contact +else if ($action == 'deletecontact' && $user->rights->resource->write) +{ + $result = $object->delete_contact(GETPOST('lineid','int')); + + if ($result >= 0) + { + header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id); + exit; + } + else { + dol_print_error($db); + } +} + + +/* + * View + */ + +$form = new Form($db); +$formcompany = new FormCompany($db); +$contactstatic=new Contact($db); +$userstatic=new User($db); + +llxHeader('',$langs->trans("Resource")); + +// Mode vue et edition + +if ($id > 0 || ! empty($ref)) +{ + $soc = new Societe($db); + $soc->fetch($object->socid); + + + $head = resource_prepare_head($object); + dol_fiche_head($head, 'contact', $langs->trans("ResourceSingular"), 0, 'resource@resource'); + + + /* + * Resource synthese pour rappel + */ + print ''; + + print ''; + print ''; + + // Resource type + print ''; + print ''; + print ''; + print ''; + + print '
'.$langs->trans("ResourceFormLabel_ref").''; + $linkback = $objet->ref.' '.$langs->trans("BackToList").''; + print $form->showrefnav($object, 'id', $linkback,1,"rowid"); + print '
' . $langs->trans("ResourceType") . ''; + print $object->type_label; + print '
'; + print '
'; + + print '
'; + + if (! empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_USER)) $hideaddcontactforuser=1; + if (! empty($conf->global->RESOURCE_HIDE_ADD_CONTACT_THIPARTY)) $hideaddcontactforthirdparty=1; + + $permission=1; + // Contacts lines + include DOL_DOCUMENT_ROOT.'/core/tpl/contacts.tpl.php'; +} + + +llxFooter(); +$db->close(); diff --git a/htdocs/resource/document.php b/htdocs/resource/document.php new file mode 100644 index 00000000000..a21bc88c319 --- /dev/null +++ b/htdocs/resource/document.php @@ -0,0 +1,141 @@ + + * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2005 Marc Barilley / Ocebo + * Copyright (C) 2005-2009 Regis Houssin + * Copyright (C) 2005 Simon TOSSER + * Copyright (C) 2011-2012 Juanjo Menent + * Copyright (C) 2013 Cédric Salvador + * Copyright (C) 2016 Gilles Poirier + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/resource/document.php + * \ingroup resource + * \brief Page des documents joints sur les resources + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/resource.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php'; + +$langs->load("other"); +$langs->load("resource"); +$langs->load("companies"); + +$id = GETPOST('id','int'); +$ref = GETPOST('ref', 'alpha'); +$action = GETPOST('action','alpha'); +$confirm = GETPOST('confirm','alpha'); + +// Security check +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'resource', $id, 'resource'); + + +// Get parameters +$sortfield = GETPOST('sortfield','alpha'); +$sortorder = GETPOST('sortorder','alpha'); +$page = GETPOST('page','int'); +if ($page == -1) { $page = 0; } +$offset = $conf->liste_limit * $page; +$pageprev = $page - 1; +$pagenext = $page + 1; +if (! $sortorder) $sortorder="ASC"; +if (! $sortfield) $sortfield="name"; + + +$object = new DolResource($db); +$object->fetch($id, $ref); + +$upload_dir = $conf->resource->dir_output.'/'.dol_sanitizeFileName($object->ref); +$modulepart='resource'; + + +/* + * Actions + */ + +include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php'; + + +/* + * View + */ + +$form = new Form($db); + +llxHeader('',$langs->trans("Resource")); + +if ($object->id) +{ + $object->fetch_thirdparty(); + + $head=resource_prepare_head($object); + + dol_fiche_head($head, 'documents', $langs->trans("ResourceSingular"), 0, 'resource'); + + + // Construit liste des fichiers + $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1); + $totalsize=0; + foreach($filearray as $key => $file) + { + $totalsize+=$file['size']; + } + + + print ''; + + + print ''; + print ''; + + // Resource type + print ''; + print ''; + print ''; + print ''; + + print ''; + print ''; + print '
'.$langs->trans("ResourceFormLabel_ref").''; + $linkback = $objet->ref.' '.$langs->trans("BackToList").''; + print $form->showrefnav($object, 'id', $linkback,1,"rowid"); + print '
' . $langs->trans("ResourceType") . ''; + print $object->type_label; + print '
'.$langs->trans("NbOfAttachedFiles").''.count($filearray).'
'.$langs->trans("TotalSizeOfAttachedFiles").''.$totalsize.' '.$langs->trans("bytes").'
'; + + print ''; + + $modulepart = 'dolresource'; + $permission = $user->rights->resource->write; + $param = '&id=' . $object->id; + include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php'; + +} +else +{ + print $langs->trans("ErrorUnknown"); +} + + +llxFooter(); + +$db->close(); diff --git a/htdocs/resource/element_resource.php b/htdocs/resource/element_resource.php index e4477e1674a..59a95f6f57a 100644 --- a/htdocs/resource/element_resource.php +++ b/htdocs/resource/element_resource.php @@ -1,5 +1,6 @@ +/* Copyright (C) 2013 Jean-François Ferry + * Copyright (C) 2016 Gilles Poirier * * 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 @@ -16,18 +17,18 @@ */ /** - * \file resource/element_resource.php - * \ingroup resource - * \brief Page to show and manage linked resources to an element + * \file resource/element_resource.php + * \ingroup resource + * \brief Page to show and manage linked resources to an element */ $res=0; -$res=@include("../main.inc.php"); // For root directory -if (! $res) $res=@include("../../main.inc.php"); // For "custom" directory +$res=@include("../main.inc.php"); // For root directory +if (! $res) $res=@include("../../main.inc.php"); // For "custom" directory if (! $res) die("Include of main fails"); -require 'class/resource.class.php'; +require 'class/dolresource.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; // Load traductions files requiredby by page @@ -35,92 +36,92 @@ $langs->load("resource"); $langs->load("other"); /* -$sortorder = GETPOST('sortorder','alpha'); -$sortfield = GETPOST('sortfield','alpha'); -$page = GETPOST('page','int'); +$sortorder = GETPOST('sortorder','alpha'); +$sortfield = GETPOST('sortfield','alpha'); +$page = GETPOST('page','int'); */ if( ! $user->rights->resource->read) - accessforbidden(); + accessforbidden(); -$object=new Resource($db); +$object=new Dolresource($db); $hookmanager->initHooks(array('element_resource')); -$object->available_resources = array('resource'); +$object->available_resources = array('dolresource'); // Get parameters -$id = GETPOST('id','int'); -$action = GETPOST('action','alpha'); -$mode = GETPOST('mode','alpha'); -$lineid = GETPOST('lineid','int'); -$element = GETPOST('element','alpha'); // element_type -$element_id = GETPOST('element_id','int'); -$resource_id = GETPOST('fk_resource','int'); -$resource_type = GETPOST('resource_type','alpha'); -$busy = GETPOST('busy','int'); -$mandatory = GETPOST('mandatory','int'); -$cancel = GETPOST('cancel','alpha'); -$confirm = GETPOST('confirm','alpha'); -$socid = GETPOST('socid','int'); +$id = GETPOST('id','int'); +$action = GETPOST('action','alpha'); +$mode = GETPOST('mode','alpha'); +$lineid = GETPOST('lineid','int'); +$element = GETPOST('element','alpha'); // element_type +$element_id = GETPOST('element_id','int'); +$resource_id = GETPOST('fk_resource','int'); +$resource_type = GETPOST('resource_type','alpha'); +$busy = GETPOST('busy','int'); +$mandatory = GETPOST('mandatory','int'); +$cancel = GETPOST('cancel','alpha'); +$confirm = GETPOST('confirm','alpha'); +$socid = GETPOST('socid','int'); -if ($socid > 0) +if ($socid > 0) { $element_id = $socid; $element = 'societe'; } - - + + /* * Actions */ if ($action == 'add_element_resource' && ! $cancel) { - $error++; - $res = 0; - if (! ($resource_id > 0)) - { - $error++; + $error++; + $res = 0; + if (! ($resource_id > 0)) + { + $error++; setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("Resource")), null, 'errors'); $action=''; - } - else - { + } + else + { $objstat = fetchObjectByElement($element_id, $element); - + $res = $objstat->add_element_resource($resource_id, $resource_type, $busy, $mandatory); - } - if (! $error && $res > 0) - { - setEventMessages($langs->trans('ResourceLinkedWithSuccess'), null, 'mesgs'); - header("Location: ".$_SERVER['PHP_SELF'].'?element='.$element.'&element_id='.$element_id); - exit; - } + } + if (! $error && $res > 0) + { + setEventMessages($langs->trans('ResourceLinkedWithSuccess'), null, 'mesgs'); + header("Location: ".$_SERVER['PHP_SELF'].'?element='.$element.'&element_id='.$element_id); + exit; + } } // Update ressource if ($action == 'update_linked_resource' && $user->rights->resource->write && !GETPOST('cancel') ) { - $res = $object->fetch_element_resource($lineid); - if($res) - { - $object->busy = $busy; - $object->mandatory = $mandatory; + $res = $object->fetch_element_resource($lineid); + if($res) + { + $object->busy = $busy; + $object->mandatory = $mandatory; - $result = $object->update_element_resource($user); + $result = $object->update_element_resource($user); - if ($result >= 0) - { - setEventMessages($langs->trans('RessourceLineSuccessfullyUpdated'), null, 'mesgs'); - header("Location: ".$_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id); - exit; - } - else - { - setEventMessages($object->error, $object->errors, 'errors'); - } - } + if ($result >= 0) + { + setEventMessages($langs->trans('RessourceLineSuccessfullyUpdated'), null, 'mesgs'); + header("Location: ".$_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id); + exit; + } + else + { + setEventMessages($object->error, $object->errors, 'errors'); + } + } } // Delete a resource linked to an element @@ -134,7 +135,7 @@ if ($action == 'confirm_delete_linked_resource' && $user->rights->resource->dele header("Location: ".$_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id); exit; } - else + else { setEventMessages($object->error, $object->errors, 'errors'); } @@ -164,149 +165,190 @@ llxHeader('',$pagetitle,''); // Load available resource, declared by modules $ret = count($object->available_resources); if($ret == -1) { - dol_print_error($db,$object->error); - exit; + dol_print_error($db,$object->error); + exit; } if(!$ret) { - print '
'.$langs->trans('NoResourceInDatabase').'
'; + print '
'.$langs->trans('NoResourceInDatabase').'
'; } else { - // Confirmation suppression resource line - if ($action == 'delete_resource') - { - print $form->formconfirm("element_resource.php?element=".$element."&element_id=".$element_id."&id=".$id."&lineid=".$lineid,$langs->trans("DeleteResource"),$langs->trans("ConfirmDeleteResourceElement"),"confirm_delete_linked_resource",'','',1); - } + // Confirmation suppression resource line + if ($action == 'delete_resource') + { + print $form->formconfirm("element_resource.php?element=".$element."&element_id=".$element_id."&id=".$id."&lineid=".$lineid,$langs->trans("DeleteResource"),$langs->trans("ConfirmDeleteResourceElement"),"confirm_delete_linked_resource",'','',1); + } + /* + * Specific to agenda module + */ + if ($element_id && $element == 'action') + { + require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php'; + + $act = fetchObjectByElement($element_id,$element); + if (is_object($act)) + { + + $head=actions_prepare_head($act); + + dol_fiche_head($head, 'resources', $langs->trans("Action"),0,'action'); + + // Affichage fiche action en mode visu + print ''; + + $linkback = ''.$langs->trans("BackToList").''; + + // Ref + print ''; + + // Type + if (! empty($conf->global->AGENDA_USE_EVENT_TYPE)) + { + print ''; + } + + // Title + print ''; + print '
'.$langs->trans("Ref").''; + print $form->showrefnav($act, 'id', $linkback, ($user->societe_id?0:1), 'id', 'ref', ''); + print '
'.$langs->trans("Type").''.$act->type.'
'.$langs->trans("Title").''.$act->label.'
'; + + dol_fiche_end(); + } + } + + /* + * Specific to thirdparty module + */ + if ($element_id && $element == 'societe') + { + $socstatic = fetchObjectByElement($element_id,$element); + if (is_object($socstatic)) + { + $savobject = $object; + + $object = $socstatic; + + require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; + $head = societe_prepare_head($socstatic); + + dol_fiche_head($head, 'resources', $langs->trans("ThirdParty"),0,'company'); + + dol_banner_tab($socstatic, 'socid', '', ($user->societe_id?0:1), 'rowid', 'nom'); + + print '
'; + + print '
'; + print ''; + + // Alias name (commercial, trademark or alias name) + print '"; + + print '
'.$langs->trans('AliasNames').''; + print $socstatic->name_alias; + print "
'; + + print '
'; + + dol_fiche_end(); + + $object = $savobject; + } + } + /* - * Specific to agenda module + * Specific to fichinter module */ - if ($element_id && $element == 'action') + if ($element_id && $element == 'fichinter') { - require_once DOL_DOCUMENT_ROOT.'/core/lib/agenda.lib.php'; + require_once DOL_DOCUMENT_ROOT.'/core/lib/fichinter.lib.php'; - $act = fetchObjectByElement($element_id,$element); - if (is_object($act)) + $fichinter = fetchObjectByElement($element_id, $element); + if (is_object($fichinter)) { - - $head=actions_prepare_head($act); - - dol_fiche_head($head, 'resources', $langs->trans("Action"),0,'action'); + $head=fichinter_prepare_head($fichinter); + dol_fiche_head($head, 'resource', $langs->trans("InterventionCard"),0,'intervention'); // Affichage fiche action en mode visu print ''; - - $linkback = ''.$langs->trans("BackToList").''; + + $linkback = ''.$langs->trans("BackToList").''; // Ref print ''; - // Type - if (! empty($conf->global->AGENDA_USE_EVENT_TYPE)) - { - print ''; - } - // Title - print ''; - print '
'.$langs->trans("Ref").''; - print $form->showrefnav($act, 'id', $linkback, ($user->societe_id?0:1), 'id', 'ref', ''); + print $form->showrefnav($fichinter, 'id', $linkback, ($user->societe_id?0:1), 'ref', 'ref', ''); print '
'.$langs->trans("Type").''.$act->type.'
'.$langs->trans("Title").''.$act->label.'
'; + // Customer + if ( is_null($fichinter->client) ) + $fichinter->fetch_thirdparty(); + + print "".$langs->trans("Company").""; + print ''.$fichinter->client->getNomUrl(1).''; + print ""; dol_fiche_end(); } } - /* - * Specific to thirdparty module - */ - if ($element_id && $element == 'societe') - { - $socstatic = fetchObjectByElement($element_id,$element); - if (is_object($socstatic)) - { - $savobject = $object; - - $object = $socstatic; - - require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; - $head = societe_prepare_head($socstatic); - dol_fiche_head($head, 'resources', $langs->trans("ThirdParty"),0,'company'); + // hook for other elements linked + $parameters=array('element'=>$element, 'element_id'=>$element_id ); + $reshook=$hookmanager->executeHooks('printElementTab',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks + if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors'); - dol_banner_tab($socstatic, 'socid', '', ($user->societe_id?0:1), 'rowid', 'nom'); - - print '
'; - - print '
'; - print ''; - - // Alias name (commercial, trademark or alias name) - print '"; - - print '
'.$langs->trans('AliasNames').''; - print $socstatic->name_alias; - print "
'; - print '
'; - - dol_fiche_end(); - - $object = $savobject; - } - } + //print load_fiche_titre($langs->trans('ResourcesLinkedToElement'),'',''); - //print load_fiche_titre($langs->trans('ResourcesLinkedToElement'),'',''); + foreach ($object->available_resources as $modresources => $resources) + { + $resources=(array) $resources; // To be sure $resources is an array + foreach($resources as $resource_obj) + { + $element_prop = getElementProperties($resource_obj); + + //print '/'.$modresources.'/class/'.$resource_obj.'.class.php
'; + + $path = ''; + if(strpos($resource_obj,'@')) + $path .= '/'.$element_prop['module']; + + $linked_resources = $object->getElementResources($element,$element_id,$resource_obj); - - foreach ($object->available_resources as $modresources => $resources) - { - $resources=(array) $resources; // To be sure $resources is an array - foreach($resources as $resource_obj) - { - $element_prop = getElementProperties($resource_obj); - - //print '/'.$modresources.'/class/'.$resource_obj.'.class.php
'; - - $path = ''; - if(strpos($resource_obj,'@')) - $path .= '/'.$element_prop['module']; - - $linked_resources = $object->getElementResources($element,$element_id,$resource_obj); - - - // If we have a specific template we use it - if(file_exists(dol_buildpath($path.'/core/tpl/resource_'.$element_prop['element'].'_add.tpl.php'))) - { - $res=include dol_buildpath($path.'/core/tpl/resource_'.$element_prop['element'].'_add.tpl.php'); - } - else - { - $res=include DOL_DOCUMENT_ROOT . '/core/tpl/resource_add.tpl.php'; - } + // If we have a specific template we use it + if(file_exists(dol_buildpath($path.'/core/tpl/resource_'.$element_prop['element'].'_add.tpl.php'))) + { + $res=include dol_buildpath($path.'/core/tpl/resource_'.$element_prop['element'].'_add.tpl.php'); + } + else + { + $res=include DOL_DOCUMENT_ROOT . '/core/tpl/resource_add.tpl.php'; + } //var_dump($element_id); - if ($mode != 'add' || $resource_obj != $resource_type) - { - //print load_fiche_titre($langs->trans(ucfirst($element_prop['element']).'Singular')); + if ($mode != 'add' || $resource_obj != $resource_type) + { + //print load_fiche_titre($langs->trans(ucfirst($element_prop['element']).'Singular')); - // If we have a specific template we use it - if(file_exists(dol_buildpath($path.'/core/tpl/resource_'.$element_prop['element'].'_view.tpl.php'))) - { - $res=@include dol_buildpath($path.'/core/tpl/resource_'.$element_prop['element'].'_view.tpl.php'); + // If we have a specific template we use it + if(file_exists(dol_buildpath($path.'/core/tpl/resource_'.$element_prop['element'].'_view.tpl.php'))) + { + $res=@include dol_buildpath($path.'/core/tpl/resource_'.$element_prop['element'].'_view.tpl.php'); - } - else - { - $res=include DOL_DOCUMENT_ROOT . '/core/tpl/resource_view.tpl.php'; - } - } - } - } + } + else + { + $res=include DOL_DOCUMENT_ROOT . '/core/tpl/resource_view.tpl.php'; + } + } + } + } } llxFooter(); diff --git a/htdocs/resource/list.php b/htdocs/resource/list.php index 9bfa7309167..b33bbec259e 100644 --- a/htdocs/resource/list.php +++ b/htdocs/resource/list.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2013-2014 Jean-François Ferry * * 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 @@ -16,34 +16,34 @@ */ /** - * \file resource/index.php - * \ingroup resource - * \brief Page to manage resource objects + * \file resource/index.php + * \ingroup resource + * \brief Page to manage resource objects */ require '../main.inc.php'; -require_once DOL_DOCUMENT_ROOT.'/resource/class/resource.class.php'; +require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php'; -// Load translations files requiredby by page +// Load translations files required by page $langs->load("resource"); $langs->load("companies"); $langs->load("other"); // Get parameters -$id = GETPOST('id','int'); -$action = GETPOST('action','alpha'); +$id = GETPOST('id','int'); +$action = GETPOST('action','alpha'); -$lineid = GETPOST('lineid','int'); -$element = GETPOST('element','alpha'); -$element_id = GETPOST('element_id','int'); -$resource_id = GETPOST('resource_id','int'); +$lineid = GETPOST('lineid','int'); +$element = GETPOST('element','alpha'); +$element_id = GETPOST('element_id','int'); +$resource_id = GETPOST('resource_id','int'); -$sortorder = GETPOST('sortorder','alpha'); -$sortfield = GETPOST('sortfield','alpha'); -$page = GETPOST('page','int'); +$sortorder = GETPOST('sortorder','alpha'); +$sortfield = GETPOST('sortfield','alpha'); +$page = GETPOST('page','int'); -$object = new Resource($db); +$object = new Dolresource($db); $hookmanager->initHooks(array('resource_list')); @@ -52,7 +52,7 @@ if (empty($sortfield)) $sortfield="t.rowid"; if (empty($arch)) $arch = 0; if ($page == -1) { - $page = 0 ; + $page = 0 ; } $limit = GETPOST('limit')?GETPOST('limit','int'):$conf->liste_limit; @@ -61,7 +61,7 @@ $pageprev = $page - 1; $pagenext = $page + 1; if( ! $user->rights->resource->read) - accessforbidden(); + accessforbidden(); /* @@ -86,72 +86,69 @@ llxHeader('',$pagetitle,''); // Confirmation suppression resource line if ($action == 'delete_resource') { - print $form->formconfirm($_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id."&lineid=".$lineid,$langs->trans("DeleteResource"),$langs->trans("ConfirmDeleteResourceElement"),"confirm_delete_resource",'','',1); + print $form->formconfirm($_SERVER['PHP_SELF']."?element=".$element."&element_id=".$element_id."&lineid=".$lineid,$langs->trans("DeleteResource"),$langs->trans("ConfirmDeleteResourceElement"),"confirm_delete_resource",'','',1); } // Load object list $ret = $object->fetch_all($sortorder, $sortfield, $limit, $offset); if($ret == -1) { - dol_print_error($db,$object->error); - exit; + dol_print_error($db,$object->error); + exit; } else { print_barre_liste($pagetitle, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $ret+1, $object->num_all,'title_generic.png'); } if(!$ret) { - print '
'.$langs->trans('NoResourceInDatabase').'
'; + print '
'.$langs->trans('NoResourceInDatabase').'
'; } else { - $var=true; + $var=true; - print ''."\n"; - print ''; - print_liste_field_titre($langs->trans('Id'),$_SERVER['PHP_SELF'],'t.rowid','',$param,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans('Ref'),$_SERVER['PHP_SELF'],'t.ref','',$param,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans('ResourceType'),$_SERVER['PHP_SELF'],'ty.code','',$param,'',$sortfield,$sortorder); - print_liste_field_titre($langs->trans('Action'),"","","","",'width="60" align="center"',"",""); - print "\n"; + print '
'."\n"; + print ''; + print_liste_field_titre($langs->trans('Id'),$_SERVER['PHP_SELF'],'t.rowid','',$param,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans('Ref'),$_SERVER['PHP_SELF'],'t.ref','',$param,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans('ResourceType'),$_SERVER['PHP_SELF'],'ty.code','',$param,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans('Action'),"","","","",'width="60" align="center"',"",""); + print "\n"; - foreach ($object->lines as $resource) - { - $var=!$var; + foreach ($object->lines as $resource) + { + $var=!$var; - $style=''; - if($resource->id == GETPOST('lineid')) - $style='style="background: orange;"'; + $style=''; + if($resource->id == GETPOST('lineid')) + $style='style="background: orange;"'; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; + print ''; - print ''; - } + print ''; + } - print '
'; - print ''.$resource->id.''; - print '
'; + print ''.$resource->id.''; + print ''; - print $resource->ref; - print ''; + print $resource->ref; + print ''; - print $resource->type_label; - print ''; + print $resource->type_label; + print ''; - print ''; - print img_edit(); - print ''; - print ' '; - print ''; - print img_delete(); - print ''; - print ''; + print ''; + print img_edit(); + print ''; + print ' '; + print ''; + print img_delete(); + print ''; + print '
'; + print ''; } - llxFooter(); $db->close(); - - diff --git a/htdocs/resource/note.php b/htdocs/resource/note.php new file mode 100644 index 00000000000..e404a3bdef8 --- /dev/null +++ b/htdocs/resource/note.php @@ -0,0 +1,91 @@ + + * Copyright (C) 2011-2012 Juanjo Menent + * Copyright (C) 2013 Florian Henry + * Copyright (C) 2016 Gilles Poirier + * + * 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 + * the Free Software Foundation; either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +/** + * \file htdocs/resource/note.php + * \ingroup fichinter + * \brief Fiche d'information sur une resource + */ + +require '../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/resource/class/dolresource.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/resource.lib.php'; + +$langs->load('companies'); +$langs->load("interventions"); + +$id = GETPOST('id','int'); +$ref = GETPOST('ref', 'alpha'); +$action=GETPOST('action','alpha'); + +// Security check +if ($user->societe_id) $socid=$user->societe_id; +$result = restrictedArea($user, 'resource', $id, 'resource'); + +$object = new DolResource($db); +$object->fetch($id,$ref); + +$permissionnote=$user->rights->resource->write; // Used by the include of actions_setnotes.inc.php + +/* + * Actions + */ + +include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once + + +/* + * View + */ + +llxHeader(); + +$form = new Form($db); + +if ($id > 0 || ! empty($ref)) +{ + $head = resource_prepare_head($object); + dol_fiche_head($head, 'note', $langs->trans('ResourceSingular'), 0, 'resource@resource'); + + print ''; + print ''; + print ''; + + // Resource type + print ''; + print ''; + print ''; + print ''; print "
'.$langs->trans("ResourceFormLabel_ref").''; + $linkback = $objet->ref.' '.$langs->trans("BackToList").''; + print $form->showrefnav($object, 'id', $linkback,1,"rowid"); + print '
' . $langs->trans("ResourceType") . ''; + print $object->type_label; + print '
"; + + print '
'; + $permission=$user->rights->resource->write; + $cssclass='titlefield'; + include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php'; + + dol_fiche_end(); +} + +llxFooter(); +$db->close(); diff --git a/htdocs/societe/canvas/actions_card_common.class.php b/htdocs/societe/canvas/actions_card_common.class.php index 74a05cba39d..95d5b33e162 100644 --- a/htdocs/societe/canvas/actions_card_common.class.php +++ b/htdocs/societe/canvas/actions_card_common.class.php @@ -23,8 +23,7 @@ */ /** - * \class ActionsCardCommon - * \brief Classe permettant la gestion des tiers par defaut + * Classe permettant la gestion des tiers par defaut */ abstract class ActionsCardCommon { diff --git a/htdocs/societe/class/api_contact.class.php b/htdocs/societe/class/api_contact.class.php index ba7c0d4a211..5144c000b4d 100644 --- a/htdocs/societe/class/api_contact.class.php +++ b/htdocs/societe/class/api_contact.class.php @@ -251,7 +251,7 @@ class ContactApi extends DolibarrApi * * @param int $id Contact ID * @return integer - * + * * @url DELETE contact/{id} */ function delete($id) { diff --git a/htdocs/societe/class/api_thirdparty.class.php b/htdocs/societe/class/api_thirdparty.class.php index 9c65d08ac43..507d95639e6 100644 --- a/htdocs/societe/class/api_thirdparty.class.php +++ b/htdocs/societe/class/api_thirdparty.class.php @@ -370,7 +370,7 @@ class ThirdpartyApi extends DolibarrApi * Delete thirdparty * * @param int $id Thirparty ID - * @return type + * @return integer * * @url DELETE thirdparty/{id} * @url DELETE customer/{id} diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 17f96a93c3c..62364c57644 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -832,7 +832,10 @@ class Societe extends CommonObject $sql .= ",prefix_comm = ".(! empty($this->prefix_comm)?"'".$this->db->escape($this->prefix_comm)."'":"null"); $sql .= ",fk_effectif = ".(! empty($this->effectif_id)?"'".$this->db->escape($this->effectif_id)."'":"null"); - $sql .= ",fk_stcomm='".$this->stcomm_id."'"; + if (isset($this->stcomm_id)) + { + $sql .= ",fk_stcomm='".$this->stcomm_id."'"; + } $sql .= ",fk_typent = ".(! empty($this->typent_id)?"'".$this->db->escape($this->typent_id)."'":"0"); $sql .= ",fk_forme_juridique = ".(! empty($this->forme_juridique_code)?"'".$this->db->escape($this->forme_juridique_code)."'":"null"); @@ -848,7 +851,7 @@ class Societe extends CommonObject $sql .= ",barcode = ".(! empty($this->barcode)?"'".$this->db->escape($this->barcode)."'":"null"); $sql .= ",default_lang = ".(! empty($this->default_lang)?"'".$this->db->escape($this->default_lang)."'":"null"); $sql .= ",logo = ".(! empty($this->logo)?"'".$this->db->escape($this->logo)."'":"null"); - $sql .= ",outstanding_limit= '".($this->outstanding_limit!=''?$this->outstanding_limit:'null')."'"; + $sql .= ",outstanding_limit= ".($this->outstanding_limit!=''?$this->outstanding_limit:'null'); $sql .= ",fk_prospectlevel='".$this->fk_prospectlevel."'"; $sql .= ",webservices_url = ".(! empty($this->webservices_url)?"'".$this->db->escape($this->webservices_url)."'":"null"); diff --git a/htdocs/societe/list.php b/htdocs/societe/list.php index 4e9d0b1ed18..94212594eb2 100644 --- a/htdocs/societe/list.php +++ b/htdocs/societe/list.php @@ -212,6 +212,7 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETP $search_town=""; $search_zip=""; $search_state=""; + $search_country=''; $search_idprof1=''; $search_idprof2=''; $search_idprof3=''; @@ -219,7 +220,6 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETP $search_idprof5=''; $search_idprof6=''; $search_type=''; - $search_country=''; $search_type_thirdparty=''; $search_status=''; $search_stcomm=''; @@ -384,6 +384,7 @@ if ($search_account_supplier_code) $sql.= natural_search("s.code_compta_fourniss if ($search_town) $sql.= natural_search("s.town",$search_town); if ($search_zip) $sql.= natural_search("s.zip",$search_zip); if ($search_state) $sql.= natural_search("state.nom",$search_state); +if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')'; if ($search_idprof1) $sql.= natural_search("s.siren",$search_idprof1); if ($search_idprof2) $sql.= natural_search("s.siret",$search_idprof2); if ($search_idprof3) $sql.= natural_search("s.ape",$search_idprof3); @@ -396,7 +397,6 @@ if ($search_type > 0 && in_array($search_type,array('4'))) $sql .= " AND if ($search_type == '0') $sql .= " AND s.client = 0 AND s.fournisseur = 0"; if ($search_status!='') $sql .= " AND s.status = ".$db->escape($search_status); if (!empty($conf->barcode->enabled) && $search_barcode) $sql.= " AND s.barcode LIKE '%".$db->escape($search_barcode)."%'"; -if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')'; if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')'; if ($search_levels) $sql .= " AND s.fk_prospectlevel IN (".$search_levels.')'; if ($search_stcomm != '' && $search_stcomm != -2) $sql.= natural_search("s.fk_stcomm",$search_stcomm,2); @@ -519,14 +519,15 @@ if ($resql) $moreforfilter.=$formother->select_categories('customer',$search_categ,'search_categ',1); $moreforfilter.=''; } - // If the user can view prospects other than his' - if ($user->rights->societe->client->voir || $socid) - { - $moreforfilter.='
'; - $moreforfilter.=$langs->trans('SalesRepresentatives'). ': '; - $moreforfilter.=$formother->select_salesrepresentatives($search_sale,'search_sale',$user, 0, 1, 'maxwidth300'); - $moreforfilter.='
'; - } + } + + // If the user can view prospects other than his' + if ($user->rights->societe->client->voir || $socid) + { + $moreforfilter.='
'; + $moreforfilter.=$langs->trans('SalesRepresentatives'). ': '; + $moreforfilter.=$formother->select_salesrepresentatives($search_sale,'search_sale',$user, 0, 1, 'maxwidth300'); + $moreforfilter.='
'; } if ($type == 'f') { diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index eedcd449c0d..02543d46993 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -783,10 +783,14 @@ else $modCodeFournisseur = new $module; // Define if customer/prospect or supplier status is set or not - if (GETPOST("type")!='f' && empty($conf->global->THIRDPARTY_NOTCUSTOMERPROSPECT_BY_DEFAULT)) { $object->client=3; } - if (GETPOST("type")=='c') { $object->client=1; } + if (GETPOST("type")!='f') + { + $object->client=-1; + if (! empty($conf->global->THIRDPARTY_CUSTOMERPROSPECT_BY_DEFAULT)) { $object->client=3; } + } + if (GETPOST("type")=='c') { $object->client=3; } // Prospect / Customer if (GETPOST("type")=='p') { $object->client=2; } - if (! empty($conf->fournisseur->enabled) && (GETPOST("type")=='f' || (GETPOST("type")=='' && empty($conf->global->THIRDPARTY_NOTSUPPLIER_BY_DEFAULT)))) { $object->fournisseur=1; } + if (! empty($conf->fournisseur->enabled) && (GETPOST("type")=='f' || (GETPOST("type")=='' && ! empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)))) { $object->fournisseur=1; } $object->name = GETPOST('name', 'alpha'); $object->firstname = GETPOST('firstname', 'alpha'); @@ -983,8 +987,9 @@ else // Prospect/Customer print ''.fieldLabel('ProspectCustomer','customerprospect',1).''; - print ''; if (GETPOST("type") == '') print ''; if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS)) print ''; if (empty($conf->global->SOCIETE_DISABLE_PROSPECTS) && empty($conf->global->SOCIETE_DISABLE_CUSTOMERS)) print ''; @@ -1008,7 +1013,9 @@ else // Supplier print ''; print ''.fieldLabel('Supplier','fournisseur',1).''; - print $form->selectyesno("fournisseur", (isset($_POST['fournisseur'])?GETPOST('fournisseur'):(GETPOST("type") == '' ? -1 : $object->fournisseur)), 1, 0, (GETPOST("type") == '' ? 1 : 0)); + $default = -1; + if (! empty($conf->global->THIRDPARTY_SUPPLIER_BY_DEFAULT)) $default=1; + print $form->selectyesno("fournisseur", (isset($_POST['fournisseur'])?GETPOST('fournisseur'):(GETPOST("type") == '' ? $default : $object->fournisseur)), 1, 0, (GETPOST("type") == '' ? 1 : 0)); print ''; print ''.fieldLabel('SupplierCode','supplier_code').''; print '
'; diff --git a/htdocs/theme/eldy/ckeditor/config.js b/htdocs/theme/eldy/ckeditor/config.js index cffaadfba6e..cf7163671a3 100644 --- a/htdocs/theme/eldy/ckeditor/config.js +++ b/htdocs/theme/eldy/ckeditor/config.js @@ -32,14 +32,12 @@ CKEDITOR.editorConfig = function( config ) ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'], ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'], ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'], - '/', ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'], ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'], ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], ['BidiLtr', 'BidiRtl'], ['Link','Unlink','Anchor'], ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe'], - '/', ['Styles','Format','Font','FontSize'], ['TextColor','BGColor'], ['Maximize', 'ShowBlocks','-','About'] diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index 59238e786f1..162310f4697 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -350,7 +350,7 @@ legend { margin-bottom: 8px; } fieldset { border: 1px solid #AAAAAA !important; } -.button, input[name="sbmtConnexion"] { +.button, .buttonDelete, input[name="sbmtConnexion"] { font-family: ; border-color: #c5c5c5; border-color: rgba(0, 0, 0, 0.15) rgba(0, 0, 0, 0.15) rgba(0, 0, 0, 0.25); @@ -383,17 +383,17 @@ fieldset { border: 1px solid #AAAAAA !important; } -moz-box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.2), 0 1px 2px rgba(0, 0, 0, 0.05); } -.button:focus { +.button:focus, .buttonDelete:focus { -moz-box-shadow: 0px 0px 6px 1px rgba(0, 0, 60, 0.2), 0px 0px 0px rgba(60,60,60,0.1); -webkit-box-shadow: 0px 0px 6px 1px rgba(0, 0, 60, 0.2), 0px 0px 0px rgba(60,60,60,0.1); box-shadow: 0px 0px 6px 1px rgba(0, 0, 60, 0.2), 0px 0px 0px rgba(60,60,60,0.1); } -.button:hover { +.button:hover, .buttonDelete:hover { -moz-box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.2), 0px 0px 0px rgba(60,60,60,0.1); -webkit-box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.2), 0px 0px 0px rgba(60,60,60,0.1); box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.2), 0px 0px 0px rgba(60,60,60,0.1); } -.button:disabled { +.button:disabled, .buttonDelete:disabled { opacity: 0.4; filter: alpha(opacity=40); /* For IE8 and earlier */ box-shadow: none; @@ -1907,31 +1907,16 @@ span.butAction, span.butActionDelete { } .butAction:hover { -/* for bootstrap look - color: #fff; - background-color: #286090; - border-color: #204d74; -*/ -moz-box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.2), 0px 0px 0px rgba(60,60,60,0.1); -webkit-box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.2), 0px 0px 0px rgba(60,60,60,0.1); box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.2), 0px 0px 0px rgba(60,60,60,0.1); } -.butActionDelete, .butActionDelete:link, .butActionDelete:visited, .butActionDelete:hover, .butActionDelete:active { -/* for bootstrap look - color: #fff; - background-color: #d9534f; - border-color: #d43f3a; -*/ - color: #800; +.butActionDelete, .butActionDelete:link, .butActionDelete:visited, .butActionDelete:hover, .butActionDelete:active, .buttonDelete { + color: #800 !important; } .butActionDelete:hover { -/* for bootstrap look - color: #fff; - background-color: #c9302c; - border-color: #ac2925; -*/ -moz-box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.2), 0px 0px 0px rgba(60,60,60,0.1); -webkit-box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.2), 0px 0px 0px rgba(60,60,60,0.1); box-shadow: 0px 0px 6px 1px rgba(0, 0, 0, 0.2), 0px 0px 0px rgba(60,60,60,0.1); @@ -3126,19 +3111,27 @@ td.hidden { .websitebar { border-bottom: 1px solid #888; - height: 30px; + background: #eee; +} +.websitebar .button, .websitebar .buttonDelete +{ + padding: 2px 5px 3px 5px !important; + margin: 2px 4px 2px 4px !important; + line-height: normal; } .websiteselection { display: inline-block; padding-left: 10px; vertical-align: middle; - margin-bottom: 5px; line-height: 29px; } .websitetools { float: right; padding-top: 2px; } +.websiteiframenoborder { + border: 0px; +} /* ============================================================================== */ diff --git a/htdocs/theme/md/ckeditor/config.js b/htdocs/theme/md/ckeditor/config.js index cffaadfba6e..cf7163671a3 100644 --- a/htdocs/theme/md/ckeditor/config.js +++ b/htdocs/theme/md/ckeditor/config.js @@ -32,14 +32,12 @@ CKEDITOR.editorConfig = function( config ) ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'], ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'], ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'], - '/', ['Bold','Italic','Underline','Strike','-','Subscript','Superscript'], ['NumberedList','BulletedList','-','Outdent','Indent','Blockquote','CreateDiv'], ['JustifyLeft','JustifyCenter','JustifyRight','JustifyBlock'], ['BidiLtr', 'BidiRtl'], ['Link','Unlink','Anchor'], ['Image','Flash','Table','HorizontalRule','Smiley','SpecialChar','PageBreak','Iframe'], - '/', ['Styles','Format','Font','FontSize'], ['TextColor','BGColor'], ['Maximize', 'ShowBlocks','-','About'] diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index c45055a96f5..3de39efb50f 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -1913,7 +1913,7 @@ span.butAction, span.butActionDelete { background-repeat: repeat-x } -.butActionDelete { +.butActionDelete, .buttonDelete { color: #ffffff !important; text-shadow: 0 -1px 0 rgba(0, 0, 0, 0.25); background-color: #cc6d00; @@ -2988,19 +2988,27 @@ td.hidden { .websitebar { border-bottom: 1px solid #888; - height: 30px; + background: #eee; +} +.websitebar .button, .websitebar .buttonDelete +{ + padding: 2px 4px 2px 4px !important; + margin: 2px 4px 2px 4px !important; + line-height: normal; } .websiteselection { display: inline-block; padding-left: 10px; vertical-align: middle; - margin-bottom: 5px; line-height: 29px; } .websitetools { float: right; padding-top: 2px; } +.websiteiframenoborder { + border: 0px; +} /* ============================================================================== */ diff --git a/htdocs/user/class/api_user.class.php b/htdocs/user/class/api_user.class.php index d09785d3ccb..af0db5bfb2d 100644 --- a/htdocs/user/class/api_user.class.php +++ b/htdocs/user/class/api_user.class.php @@ -159,8 +159,35 @@ class UserApi extends DolibarrApi if ($this->useraccount->update($id, DolibarrApiAccess::$user, 1, '', '', 'update')) return $this->get($id); - return false; - } + return false; + } + + /** + * add user to group + * + * @param int $id User ID + * @param int $group Group ID + * @return int + * + * @url GET user/{id}/setGroup/{group} + */ + function setGroup($id,$group) { + //if (!DolibarrApiAccess::$user->rights->user->user->supprimer) { + //throw new RestException(401); + //} + $result = $this->useraccount->fetch($id); + if (!$result) + { + throw new RestException(404, 'User not found'); + } + + if (!DolibarrApi::_checkAccessToResource('user', $this->useraccount->id, 'user')) + { + throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); + } + + return $this->useraccount->SetInGroup($group,1); + } /** * Delete account diff --git a/htdocs/viewimage.php b/htdocs/viewimage.php index 949884df6e9..585db4c343e 100644 --- a/htdocs/viewimage.php +++ b/htdocs/viewimage.php @@ -62,7 +62,7 @@ $entity=GETPOST('entity')?GETPOST('entity','int'):$conf->entity; // Security check if (empty($modulepart)) accessforbidden('Bad value for parameter modulepart'); - +if ($modulepart == 'fckeditor') $modulepart='medias'; // For backward compatibility /* @@ -95,7 +95,7 @@ $type = 'application/octet-stream'; if (! empty($_GET["type"])) $type=$_GET["type"]; else $type=dol_mimetype($original_file); -// Suppression de la chaine de caractere ../ dans $original_file +// Security: Delete string ../ into $original_file $original_file = str_replace("../","/", $original_file); // Find the subdirectory name as the reference diff --git a/htdocs/webservices/server_productorservice.php b/htdocs/webservices/server_productorservice.php index 43facbb24fa..aa43dbb185c 100644 --- a/htdocs/webservices/server_productorservice.php +++ b/htdocs/webservices/server_productorservice.php @@ -411,7 +411,8 @@ function getProductOrService($authentication,$id='',$ref='',$ref_ext='',$lang='' 'localtax1_tx' => $product->localtax1_tx, 'localtax2_tx' => $product->localtax2_tx, - 'stock_real' => $product->stock_reel, + 'stock_real' => $product->stock_reel, + 'stock_virtual' => $product->stock_theorique, 'stock_alert' => $product->seuil_stock_alerte, 'pmp' => $product->pmp, 'import_key' => $product->import_key, @@ -572,7 +573,7 @@ function createProductOrService($authentication,$product) require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; $savstockreal=$newobject->stock_reel; - $newobject->load_stock(); // This overwrite ->stock_reel + $newobject->load_stock('novirtual,nobatch'); // This overwrite ->stock_reel, surely 0 because we have just created product $getstockreal = $newobject->stock_reel; if ($savstockreal != $getstockreal) @@ -741,7 +742,7 @@ function updateProductOrService($authentication,$product) require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php'; $savstockreal=$newobject->stock_reel; - $newobject->load_stock(); // This overwrite ->stock_reel + $newobject->load_stock('novirtual,nobatch'); // This overwrite ->stock_reel $getstockreal = $newobject->stock_reel; if ($savstockreal != $getstockreal) diff --git a/htdocs/websites/class/website.class.php b/htdocs/websites/class/website.class.php index 4b6d4e04245..e87e830bb77 100644 --- a/htdocs/websites/class/website.class.php +++ b/htdocs/websites/class/website.class.php @@ -54,16 +54,37 @@ class Website extends CommonObject public $lines = array(); /** + * @var int */ - public $entity; + /** + * @var string + */ public $ref; + /** + * @var string + */ public $description; + /** + * @var int + */ public $status; - public $date_creation = ''; - public $date_modification = ''; + /** + * @var mixed + */ + public $date_creation; + /** + * @var mixed + */ + public $date_modification; + /** + * @var mixed + */ public $tms = ''; - + /** + * @var integer + */ + public $fk_default_home; public $records; /** @@ -122,9 +143,9 @@ class Website extends CommonObject $sql.= 'ref,'; $sql.= 'description,'; $sql.= 'status,'; + $sql.= 'fk_default_home,'; $sql.= 'date_creation,'; $sql.= 'date_modification'; - $sql .= ') VALUES ('; @@ -132,6 +153,7 @@ class Website extends CommonObject $sql .= ' '.(! isset($this->ref)?'NULL':"'".$this->db->escape($this->ref)."'").','; $sql .= ' '.(! isset($this->description)?'NULL':"'".$this->db->escape($this->description)."'").','; $sql .= ' '.(! isset($this->status)?'NULL':$this->status).','; + $sql .= ' '.(! isset($this->fk_default_home)?'NULL':$this->fk_default_home).','; $sql .= ' '.(! isset($this->date_creation) || dol_strlen($this->date_creation)==0?'NULL':"'".$this->db->idate($this->date_creation)."'").','; $sql .= ' '.(! isset($this->date_modification) || dol_strlen($this->date_modification)==0?'NULL':"'".$this->db->idate($this->date_modification)."'"); @@ -191,6 +213,7 @@ class Website extends CommonObject $sql .= " t.ref,"; $sql .= " t.description,"; $sql .= " t.status,"; + $sql .= " t.fk_default_home,"; $sql .= " t.date_creation,"; $sql .= " t.date_modification,"; $sql .= " t.tms"; @@ -213,6 +236,7 @@ class Website extends CommonObject $this->ref = $obj->ref; $this->description = $obj->description; $this->status = $obj->status; + $this->fk_default_home = $obj->fk_default_home; $this->date_creation = $this->db->jdate($obj->date_creation); $this->date_modification = $this->db->jdate($obj->date_modification); $this->tms = $this->db->jdate($obj->tms); @@ -257,6 +281,7 @@ class Website extends CommonObject $sql .= " t.ref,"; $sql .= " t.description,"; $sql .= " t.status,"; + $sql .= " t.fk_default_home,"; $sql .= " t.date_creation,"; $sql .= " t.date_modification,"; $sql .= " t.tms"; @@ -295,6 +320,7 @@ class Website extends CommonObject $line->ref = $obj->ref; $line->description = $obj->description; $line->status = $obj->status; + $line->fk_default_home = $obj->fk_default_home; $line->date_creation = $this->db->jdate($obj->date_creation); $line->date_modification = $this->db->jdate($obj->date_modification); $line->tms = $this->db->jdate($obj->tms); @@ -353,6 +379,7 @@ class Website extends CommonObject $sql .= ' ref = '.(isset($this->ref)?"'".$this->db->escape($this->ref)."'":"null").','; $sql .= ' description = '.(isset($this->description)?"'".$this->db->escape($this->description)."'":"null").','; $sql .= ' status = '.(isset($this->status)?$this->status:"null").','; + $sql .= ' fk_default_home = '.(($this->fk_default_home > 0)?$this->fk_default_home:"null").','; $sql .= ' date_creation = '.(! isset($this->date_creation) || dol_strlen($this->date_creation) != 0 ? "'".$this->db->idate($this->date_creation)."'" : 'null').','; $sql .= ' date_modification = '.(! isset($this->date_modification) || dol_strlen($this->date_modification) != 0 ? "'".$this->db->idate($this->date_modification)."'" : 'null').','; $sql .= ' tms = '.(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : "'".$this->db->idate(dol_now())."'"); @@ -595,13 +622,14 @@ class Website extends CommonObject { $this->id = 0; - $this->entity = ''; - $this->ref = ''; - $this->description = ''; + $this->entity = 1; + $this->ref = 'myspecimenwebsite'; + $this->description = 'A specimen website'; $this->status = ''; - $this->date_creation = ''; - $this->date_modification = ''; - $this->tms = ''; + $this->fk_default_home = null; + $this->date_creation = dol_now(); + $this->date_modification = dol_now(); + $this->tms = dol_now(); } @@ -618,19 +646,36 @@ class WebsiteLine */ public $id; /** - * @var mixed Sample line property 1 + * @var int */ - public $entity; - public $ref; - public $description; - public $status; - public $date_creation = ''; - public $date_modification = ''; - public $tms = ''; - /** - * @var mixed Sample line property 2 + * @var string */ + public $ref; + /** + * @var string + */ + public $description; + /** + * @var int + */ + public $status; + /** + * @var int + */ + public $fk_default_home; + /** + * @var mixed + */ + public $date_creation; + /** + * @var mixed + */ + public $date_modification; + /** + * @var mixed + */ + public $tms = ''; } diff --git a/htdocs/websites/class/websitepage.class.php b/htdocs/websites/class/websitepage.class.php index ac9adf8f480..65e56e030a1 100644 --- a/htdocs/websites/class/websitepage.class.php +++ b/htdocs/websites/class/websitepage.class.php @@ -47,7 +47,7 @@ class WebsitePage extends CommonObject /** */ - + public $fk_website; public $pageurl; public $title; @@ -61,7 +61,7 @@ class WebsitePage extends CommonObject /** */ - + /** * Constructor @@ -87,7 +87,7 @@ class WebsitePage extends CommonObject $error = 0; $now=dol_now(); - + // Clean parameters if (isset($this->fk_website)) { $this->fk_website = trim($this->fk_website); @@ -167,7 +167,7 @@ class WebsitePage extends CommonObject } // Commit or rollback - if ($error) + if ($error) { $this->db->rollback(); @@ -194,7 +194,7 @@ class WebsitePage extends CommonObject $sql = 'SELECT'; $sql .= ' t.rowid,'; - + $sql .= " t.fk_website,"; $sql .= " t.pageurl,"; $sql .= " t.title,"; @@ -205,7 +205,7 @@ class WebsitePage extends CommonObject $sql .= " t.date_creation,"; $sql .= " t.date_modification,"; $sql .= " t.tms"; - + $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element . ' as t'; if (null !== $website_id) { $sql .= ' WHERE t.fk_website = ' . '\'' . $website_id . '\''; @@ -221,7 +221,7 @@ class WebsitePage extends CommonObject $obj = $this->db->fetch_object($resql); $this->id = $obj->rowid; - + $this->fk_website = $obj->fk_website; $this->pageurl = $obj->pageurl; $this->title = $obj->title; @@ -233,7 +233,7 @@ class WebsitePage extends CommonObject $this->date_modification = $this->db->jdate($obj->date_modification); $this->tms = $this->db->jdate($obj->tms); - + } $this->db->free($resql); @@ -253,21 +253,21 @@ class WebsitePage extends CommonObject /** * Load object in memory from the database * - * @param string $sortorder Sort Order - * @param string $sortfield Sort field - * @param int $limit limit - * @param int $offset Offset - * @param array $filter Filter array - * @param string $filtermode Filter mode (AND or OR) - * - * @return array|int int <0 if KO, array of pages if OK + * @param string $websiteid Web site + * @param string $sortorder Sort Order + * @param string $sortfield Sort field + * @param int $limit limit + * @param int $offset Offset + * @param array $filter Filter array + * @param string $filtermode Filter mode (AND or OR) + * @return array|int int <0 if KO, array of pages if OK */ - public function fetchAll($website_id, $sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND') + public function fetchAll($websiteid, $sortorder='', $sortfield='', $limit=0, $offset=0, array $filter = array(), $filtermode='AND') { dol_syslog(__METHOD__, LOG_DEBUG); $records=array(); - + $sql = 'SELECT'; $sql .= ' t.rowid,'; $sql .= " t.fk_website,"; @@ -281,18 +281,22 @@ class WebsitePage extends CommonObject $sql .= " t.date_modification,"; $sql .= " t.tms"; $sql .= ' FROM ' . MAIN_DB_PREFIX . $this->table_element. ' as t'; - $sql .= ' WHERE t.fk_website = '.$website_id; + $sql .= ' WHERE t.fk_website = '.$websiteid; // Manage filter $sqlwhere = array(); if (count($filter) > 0) { foreach ($filter as $key => $value) { - $sqlwhere [] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; + if ($key=='t.rowid' || $key=='t.fk_website') { + $sqlwhere[] = $key . '='. $value; + } else { + $sqlwhere[] = $key . ' LIKE \'%' . $this->db->escape($value) . '%\''; + } } } if (count($sqlwhere) > 0) { $sql .= ' AND ' . implode(' '.$filtermode.' ', $sqlwhere); } - + if (!empty($sortfield)) { $sql .= $this->db->order($sortfield,$sortorder); } @@ -305,9 +309,9 @@ class WebsitePage extends CommonObject if ($resql) { $num = $this->db->num_rows($resql); - while ($obj = $this->db->fetch_object($resql)) + while ($obj = $this->db->fetch_object($resql)) { - $record = new Websitepage($this->db); + $record = new WebsitePage($this->db); $record->id = $obj->rowid; $record->fk_website = $obj->fk_website; @@ -320,7 +324,7 @@ class WebsitePage extends CommonObject $record->date_creation = $this->db->jdate($obj->date_creation); $record->date_modification = $this->db->jdate($obj->date_modification); $record->tms = $this->db->jdate($obj->tms); - + //var_dump($record->id); $records[$record->id] = $record; } $this->db->free($resql); @@ -349,7 +353,7 @@ class WebsitePage extends CommonObject dol_syslog(__METHOD__, LOG_DEBUG); // Clean parameters - + if (isset($this->fk_website)) { $this->fk_website = trim($this->fk_website); } @@ -372,14 +376,14 @@ class WebsitePage extends CommonObject $this->status = trim($this->status); } - + // Check parameters // Put here code to add a control on parameters values // Update request $sql = 'UPDATE ' . MAIN_DB_PREFIX . $this->table_element . ' SET'; - + $sql .= ' fk_website = '.(isset($this->fk_website)?$this->fk_website:"null").','; $sql .= ' pageurl = '.(isset($this->pageurl)?"'".$this->db->escape($this->pageurl)."'":"null").','; $sql .= ' title = '.(isset($this->title)?"'".$this->db->escape($this->title)."'":"null").','; @@ -391,7 +395,7 @@ class WebsitePage extends CommonObject $sql .= ' date_modification = '.(! isset($this->date_modification) || dol_strlen($this->date_modification) != 0 ? "'".$this->db->idate($this->date_modification)."'" : 'null').','; $sql .= ' tms = '.(dol_strlen($this->tms) != 0 ? "'".$this->db->idate($this->tms)."'" : "'".$this->db->idate(dol_now())."'"); - + $sql .= ' WHERE rowid=' . $this->id; $this->db->begin(); @@ -561,7 +565,7 @@ class WebsitePage extends CommonObject $result.= $link . $this->ref . $linkend; return $result; } - + /** * Retourne le libelle du status d'un user (actif, inactif) * @@ -616,8 +620,8 @@ class WebsitePage extends CommonObject if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5'); } } - - + + /** * Initialise object with example values * Id must be 0 if object instance is a specimen @@ -627,7 +631,7 @@ class WebsitePage extends CommonObject public function initAsSpecimen() { $this->id = 0; - + $this->fk_website = ''; $this->pageurl = ''; $this->title = ''; @@ -639,7 +643,7 @@ class WebsitePage extends CommonObject $this->date_modification = ''; $this->tms = ''; - + } } diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index 58a2981d2da..ae29dab196b 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2016 Laurent Destailleur * * 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 @@ -16,11 +16,14 @@ */ /** - * \file htdocs/admin/website.php + * \file htdocs/website/index.php * \ingroup website - * \brief Page to setup the module Website + * \brief Page to website view/edit */ +define('NOSCANPOSTFORINJECTION',1); +define('NOSTYLECHECK',1); + /** * Show HTML header HTML + BODY + Top menu + left menu + DIV @@ -63,6 +66,7 @@ function llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/admin.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; require_once DOL_DOCUMENT_ROOT.'/websites/class/website.class.php'; require_once DOL_DOCUMENT_ROOT.'/websites/class/websitepage.class.php'; @@ -77,12 +81,16 @@ $conf->dol_hide_leftmenu = 1; $error=0; $website=GETPOST('website', 'alpha'); $page=GETPOST('page', 'alpha'); -$pageid=GETPOST('pageid', 'alpha'); +$pageid=GETPOST('pageid', 'int'); $action=GETPOST('action','alpha'); +if (GETPOST('delete')) { $action='delete'; } if (GETPOST('preview')) $action='preview'; if (GETPOST('create')) { $action='create'; } +if (GETPOST('editmedia')) { $action='editmedia'; } +if (GETPOST('editcss')) { $action='editcss'; } if (GETPOST('editmenu')) { $action='editmenu'; } +if (GETPOST('setashome')) { $action='setashome'; } if (GETPOST('editmeta')) { $action='editmeta'; } if (GETPOST('editcontent')) { $action='editcontent'; } @@ -91,15 +99,39 @@ if (empty($action)) $action='preview'; $object=new Website($db); $objectpage=new WebsitePage($db); +$object->fetchAll(); // Init $object->records + +// If website not defined, we take first found +if (empty($website)) +{ + foreach($object->records as $key => $valwebsite) + { + $website=$valwebsite->ref; + break; + } +} if ($website) { $res = $object->fetch(0, $website); } -if ($pageid) + +if ($pageid < 0) $pageid = 0; +if ($pageid > 0 && $action != 'add') { $res = $objectpage->fetch($pageid); } +global $dolibarr_main_data_root; +$pathofwebsite=$dolibarr_main_data_root.'/websites/'.$website; +$filecss=$pathofwebsite.'/styles.css'; +$filetpl=$pathofwebsite.'/page'.$pageid.'.tpl.php'; + +// Define $urlwithroot +$urlwithouturlroot=preg_replace('/'.preg_quote(DOL_URL_ROOT,'/').'$/i','',trim($dolibarr_main_url_root)); +$urlwithroot=$urlwithouturlroot.DOL_URL_ROOT; // This is to use external domain name found into config file +//$urlwithroot=DOL_MAIN_URL_ROOT; // This is to use same domain name than current + + /* * Actions @@ -109,20 +141,20 @@ if ($pageid) if ($action == 'add') { $db->begin(); - + $objectpage->fk_website = $object->id; - + $objectpage->title = GETPOST('WEBSITE_TITLE'); $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME'); $objectpage->description = GETPOST('WEBSITE_DESCRIPTION'); - $objectpage->keyword = GETPOST('WEBSITE_KEYWORD'); - + $objectpage->keywords = GETPOST('WEBSITE_KEYWORD'); + if (empty($objectpage->title)) { setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("WEBSITE_PAGENAME")), null, 'errors'); $error++; } - + if (! $error) { $res = $objectpage->create($user); @@ -135,7 +167,7 @@ if ($action == 'add') if (! $error) { $db->commit(); - setEventMessages($langs->trans("PageAdded"), null, 'mesgs'); + setEventMessages($langs->trans("PageAdded", $objectpage->pageurl), null, 'mesgs'); $action=''; } else @@ -148,27 +180,27 @@ if ($action == 'add') if ($action == 'update') { $db->begin(); - + $res = $object->fetch(0, $website); - + $objectpage->fk_website = $object->id; $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME'); - + $res = $objectpage->fetch(0, $object->fk_website, $objectpage->pageurl); - + if ($res > 0) { $objectpage->title = GETPOST('WEBSITE_TITLE'); $objectpage->description = GETPOST('WEBSITE_DESCRIPTION'); $objectpage->keyword = GETPOST('WEBSITE_KEYWORD'); - + $res = $objectpage->update($user); if (! $res > 0) { $error++; setEventMessages($objectpage->error, $objectpage->errors, 'errors'); } - + if (! $error) { $db->commit(); @@ -186,21 +218,154 @@ if ($action == 'update') } } +// Update page +if ($action == 'delete') +{ + $db->begin(); + + $res = $object->fetch(0, $website); + + $res = $objectpage->fetch($pageid, $object->fk_website); + + if ($res > 0) + { + $res = $objectpage->delete($user); + if (! $res > 0) + { + $error++; + setEventMessages($objectpage->error, $objectpage->errors, 'errors'); + } + + if (! $error) + { + $db->commit(); + setEventMessages($langs->trans("PageDeleted", $objectpage->pageurl, $website), null, 'mesgs'); + + header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website); + exit; + } + else + { + $db->rollback(); + } + } + else + { + dol_print_error($db); + } +} + +// Update css +if ($action == 'updatecss') +{ + $db->begin(); + + $res = $object->fetch(0, $website); + /* + $res = $object->update($user); + if ($res > 0) + { + $db->commit(); + setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + $action=''; + } + else + { + $db->rollback(); + }*/ + + $csscontent = GETPOST('WEBSITE_CSS_INLINE'); + + dol_mkdir($pathofwebsite); + file_put_contents($filecss, $csscontent); + if (! empty($conf->global->MAIN_UMASK)) + @chmod($filecss, octdec($conf->global->MAIN_UMASK)); + + $action='preview'; +} + +// Update page +if ($action == 'setashome') +{ + $db->begin(); + $object->fetch(0, $website); + + $object->fk_default_home = $pageid; + $res = $object->update($user); + if (! $res > 0) + { + $error++; + setEventMessages($objectpage->error, $objectpage->errors, 'errors'); + } + + if (! $error) + { + $db->commit(); + setEventMessages($langs->trans("Saved"), null, 'mesgs'); + $action='preview'; + } + else + { + $db->rollback(); + } +} + +// Update page +if ($action == 'updatemeta') +{ + $db->begin(); + $object->fetch(0, $website); + + $objectpage->fk_website = $object->id; + + $res = $objectpage->fetch($pageid, $object->fk_website); + if ($res > 0) + { + $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME'); + $objectpage->title = GETPOST('WEBSITE_TITLE'); + $objectpage->description = GETPOST('WEBSITE_DESCRIPTION'); + $objectpage->keywords = GETPOST('WEBSITE_KEYWORDS'); + + $res = $objectpage->update($user); + if (! $res > 0) + { + $error++; + setEventMessages($objectpage->error, $objectpage->errors, 'errors'); + } + + if (! $error) + { + $db->commit(); + setEventMessages($langs->trans("Saved"), null, 'mesgs'); + $action='preview'; + } + else + { + $db->rollback(); + } + } + else + { + dol_print_error($db, 'Page not found'); + } +} + // Update page if ($action == 'updatecontent') { $db->begin(); - $object->fetch(0, $website); - + $objectpage->fk_website = $object->id; - $objectpage->pageurl = GETPOST('WEBSITE_PAGENAME'); - - $res = $objectpage->fetch(0, $object->fk_website, $objectpage->pageurl); - + + $res = $objectpage->fetch($pageid, $object->fk_website); if ($res > 0) { $objectpage->content = GETPOST('PAGE_CONTENT'); + + // Clean data. We remove all the head section. + $objectpage->content = preg_replace('//s', '', $objectpage->content); + /* $objectpage->content = preg_replace('//s', '', $objectpage->content); */ $res = $objectpage->update($user); if (! $res > 0) @@ -208,12 +373,20 @@ if ($action == 'updatecontent') $error++; setEventMessages($objectpage->error, $objectpage->errors, 'errors'); } - + if (! $error) { $db->commit(); setEventMessages($langs->trans("Saved"), null, 'mesgs'); - $action=''; + + dol_mkdir($pathofwebsite); + dol_delete_file($filetpl); + file_put_contents($filetpl, $objectpage->content); + if (! empty($conf->global->MAIN_UMASK)) + @chmod($filetpl, octdec($conf->global->MAIN_UMASK)); + + header("Location: ".$_SERVER["PHP_SELF"].'?website='.$website.'&pageid='.$pageid); + exit; } else { @@ -222,7 +395,7 @@ if ($action == 'updatecontent') } else { - dol_print_error($db); + dol_print_error($db, 'Page not found'); } } @@ -244,6 +417,22 @@ if ($action == 'create') { print ''; } +if ($action == 'editcss') +{ + print ''; +} +if ($action == 'editmenu') +{ + print ''; +} +if ($action == 'setashome') +{ + print ''; +} +if ($action == 'editmeta') +{ + print ''; +} if ($action == 'editcontent') { print ''; @@ -252,7 +441,6 @@ if ($action == 'edit') { print ''; } -if ($website) print ''; // Add a margin under toolbar ? @@ -262,53 +450,75 @@ if ($action != 'preview' && $action != 'editcontent') $style=' margin-bottom: 5p print '
'; -$tmp = $object->fetchAll(); if (count($object->records) > 0) { print '
'; print $langs->trans("Website").': '; print '
'; - + + // List of websites print '
'; + $out=''; + $out.=''; + print $out; + print ''; + + if ($website) + { + print ' - '.$langs->trans("RealURL").' '; + $realurl=$urlwithroot.'/public/websites/index.php?website='.$website; + print ' '; + print ''.$langs->trans("ViewSiteInNewTab").''; } - print '
'; - + + // Button for websites print '
'; - - if ($action == 'preview') + + if ($action == 'preview') { $disabled=''; if (empty($user->rights->websites->create)) $disabled=' disabled="disabled"'; + //print ''; + print ''; print ''; print ''; } - //else print ''; + + if (in_array($action, array('editcss','editmenu','create'))) + { + if ($action != 'preview') print ''; + if (preg_match('/^create/',$action)) print ''; + if (preg_match('/^edit/',$action)) print ''; + } print '
'; - - + + // Part for pages if ($website) { print '
'; $array=$objectpage->fetchAll($object->id); + if (! is_array($array) && $array < 0) dol_print_error('', $objectpage->error, $objectpage->errors); + $atleastonepage=(is_array($array) && count($array) > 0); print '
'; print '
'; @@ -317,44 +527,67 @@ if (count($object->records) > 0) print '
'; $out=''; $out.=''; print $out; - print ''; + print ''; + print ''; //print $form->selectarray('page', $array); + + if ($website && $pageid > 0) + { + print ' - '.$langs->trans("RealURL").' '; + $realurl=$urlwithroot.'/public/websites/index.php?website='.$website.'&page='.$pageid; + print ' '; + print ''.$langs->trans("ViewPageInNewTab").''; + } + print '
'; print '
'; print '
'; - + print '
'; - + if ($action == 'preview') { $disabled=''; if (empty($user->rights->websites->create)) $disabled=' disabled="disabled"'; - + if ($pageid > 0) { + if ($object->fk_default_home > 0 && $pageid == $object->fk_default_home) print ''; + else print ''; print ''; print ''; + //print ''.dol_escape_htmltag($langs->trans("EditPageMeta")).''; + //print ''.dol_escape_htmltag($langs->trans("EditPageContent")).''; } } - else print ''; + + if (! in_array($action, array('editcss','editmenu','create'))) + { + if ($action != 'preview') print ''; if (preg_match('/^create/',$action)) print ''; if (preg_match('/^edit/',$action)) print ''; - + } + print '
'; - - } + + } } else { @@ -375,56 +608,112 @@ $head = array(); * Edit mode */ +if ($action == 'editcss') +{ + print '
'; + + print '
'; + + $csscontent = @file_get_contents($filecss); + + dol_fiche_head(); + + print ''; + + print ''; + + print ''; + + /*print '';*/ + + print '
'; + print $langs->trans('WebSite'); + print ''; + print $website; + print '
'; + print $langs->trans('WEBSITE_CSS_INLINE'); + print ''; + print ''; + print '
'; + print $langs->trans('WEBSITE_CSS_URL'); + print ''; + print ''; + print '
'; + + dol_fiche_end(); + + print '
'; + + print '
'; +} + if ($action == 'editmeta' || $action == 'create') { print '
'; + + print '
'; dol_fiche_head(); print ''; - print ''; - if ($action != 'create') { print ''; + $pageurl=dol_escape_htmltag($objectpage->pageurl); + $pagetitle=dol_escape_htmltag($objectpage->title); + $pagedescription=dol_escape_htmltag($objectpage->description); + $pagekeywords=dol_escape_htmltag($objectpage->keywords); } + if (GETPOST('WEBSITE_PAGENAME')) $pageurl=GETPOST('WEBSITE_PAGENAME'); + if (GETPOST('WEBSITE_TITLE')) $pagetitle=GETPOST('WEBSITE_TITLE'); + if (GETPOST('WEBSITE_DESCRIPTION')) $pagedescription=GETPOST('WEBSITE_DESCRIPTION'); + if (GETPOST('WEBSITE_KEYWORDS')) $pagekeywords=GETPOST('WEBSITE_KEYWORDS'); + + print ''; print ''; - + print ''; - + print ''; - + print '
'; - print $langs->trans('WEBSITE_PAGENAME'); - print ''; - print ''; - print '
'; - print $langs->trans('WEBSITE_URL'); + print $langs->trans('WEBSITE_PAGEURL'); print ''; - print '/public/websites/'.$website.'/index.php?pageid='.urlencode($pageid); + print '/public/websites/index.php?website='.urlencode($website).'&pageid='.urlencode($pageid); print '
'; + print $langs->trans('WEBSITE_PAGENAME'); + print ''; + print ''; + print '
'; print $langs->trans('WEBSITE_TITLE'); print ''; - print ''; + print ''; print '
'; print $langs->trans('WEBSITE_DESCRIPTION'); print ''; - print ''; + print ''; print '
'; print $langs->trans('WEBSITE_KEYWORDS'); print ''; - print ''; + print ''; print '
'; - + dol_fiche_end(); - + print '
'; - + print '
'; } +if ($action == 'editmedia') +{ + print '
'.$langs->trans("FeatureNotYetAvailable").''; +} + if ($action == 'editmenu') { print '
'.$langs->trans("FeatureNotYetAvailable").''; @@ -436,7 +725,7 @@ if ($action == 'editcontent') * Editing global variables not related to a specific theme */ require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php'; - $doleditor=new DolEditor('PAGE_CONTENT',$obj->value,'',160,'dolibarr_notes','',false,false,$conf->fckeditor->enabled,5,60); + $doleditor=new DolEditor('PAGE_CONTENT',$objectpage->content,'',500,'Full','',true,true,true,5,60); $doleditor->Create(); } @@ -449,11 +738,46 @@ if ($action == 'preview') if ($pageid > 0) { $objectpage->fetch($pageid); + + print "\n".''."\n"; + - print ''."\n"; - print '
'; - print $objectpage->content; - print '
'; + $csscontent = @file_get_contents($filecss); + + $out=''; + + $out.='
'."\n"; + + $out.=''."\n"; + + $out.=$objectpage->content."\n"; + + $out.='
'; + + print $out; + + /*file_put_contents($filetpl, $out); + if (! empty($conf->global->MAIN_UMASK)) + @chmod($filetpl, octdec($conf->global->MAIN_UMASK)); + + // Output file on browser + dol_syslog("index.php include $filetpl $filename content-type=$type"); + $original_file_osencoded=dol_osencode($filetpl); // New file name encoded in OS encoding charset + + // This test if file exists should be useless. We keep it to find bug more easily + if (! file_exists($original_file_osencoded)) + { + dol_print_error(0,$langs->trans("ErrorFileDoesNotExists",$original_file)); + exit; + } + + //include_once $original_file_osencoded; + */ + + /*print '';*/ } else { @@ -462,7 +786,7 @@ if ($action == 'preview') } } - + llxFooter();