From e1cf1070969983619c83866ff3311c2c0398d663 Mon Sep 17 00:00:00 2001 From: abb Date: Fri, 12 Feb 2016 21:51:26 +0100 Subject: [PATCH 001/379] Target object does not need to have all source object extrafields --- htdocs/core/class/commonobject.class.php | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 005f4684322..7cf15af7386 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3921,8 +3921,16 @@ abstract class CommonObject $langs->load('admin'); require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php'; $extrafields = new ExtraFields($this->db); - $extrafields->fetch_name_optionals_label($this->table_element); - + $target_extrafields=$extrafields->fetch_name_optionals_label($this->table_element); + + //Eliminate copied source object extra_fiels that do not exist in target object + $new_array_options=array(); + foreach ($this->array_options as $key => $value) { + if (in_array(substr($key,8), array_keys($target_extrafields))) + $new_array_options[$key] = $value; + } + $this->array_options =$new_array_options; + foreach($this->array_options as $key => $value) { $attributeKey = substr($key,8); // Remove 'options_' prefix From b6e39960b4f2d724723302f2015c9cc24e4f1e0a Mon Sep 17 00:00:00 2001 From: abb Date: Sun, 13 Mar 2016 00:20:29 +0100 Subject: [PATCH 002/379] new:handle user notification in notification module Conflicts: htdocs/core/lib/usergroups.lib.php --- htdocs/core/class/notify.class.php | 36 +++++++++++++++++++++++++----- htdocs/core/lib/usergroups.lib.php | 32 +++++++++++++++++++++++++- htdocs/langs/en_US/companies.lang | 3 ++- htdocs/langs/fr_FR/companies.lang | 1 + 4 files changed, 64 insertions(+), 8 deletions(-) diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index 98a06174595..423e912e1be 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -94,10 +94,11 @@ class Notify * * @param string $notifcode Code of action in llx_c_action_trigger (new usage) or Id of action in llx_c_action_trigger (old usage) * @param int $socid Id of third party or 0 for all thirdparties + * @param int $userid Id of user or 0 for all users * @param Object $object Object the notification is about (need it to check threshold value of some notifications) * @return array|int <0 if KO, array of notifications to send if OK */ - function getNotificationsArray($notifcode,$socid,$object=null) + function getNotificationsArray($notifcode,$socid= 0,$userid= 0,$object=null) { global $conf, $user; @@ -111,7 +112,8 @@ class Notify { $sql = "SELECT a.code, c.email, c.rowid"; $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n,"; - $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; + if ($userid > 0) $sql.= " ".MAIN_DB_PREFIX."user as c,"; + else $sql.= " ".MAIN_DB_PREFIX."socpeople as c,"; $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; $sql.= " ".MAIN_DB_PREFIX."societe as s"; $sql.= " WHERE n.fk_contact = c.rowid"; @@ -124,6 +126,7 @@ class Notify } $sql.= " AND s.entity IN (".getEntity('societe', 1).")"; if ($socid > 0) $sql.= " AND s.rowid = ".$socid; + elseif ($userid > 0) $sql.= " AND u.rowid = ".$userid; dol_syslog(__METHOD__." ".$notifcode.", ".$socid."", LOG_DEBUG); @@ -253,7 +256,7 @@ class Notify $newref=(empty($object->newref)?$object->ref:$object->newref); // Check notification per third party - $sql = "SELECT s.nom, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,"; + $sql = "SELECT 0 as user, c.email, c.rowid as cid, c.lastname, c.firstname, c.default_lang,"; $sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type"; $sql.= " FROM ".MAIN_DB_PREFIX."socpeople as c,"; $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; @@ -265,6 +268,20 @@ class Notify else $sql.= " AND a.code = '".$notifcode."'"; // New usage $sql .= " AND s.rowid = ".$object->socid; + // Check notification per user + $sql.= "\nUNION\n"; + $sql.= "SELECT 1 as user, c.email, c.rowid as cid, c.lastname, c.firstname, '$langs->defaultlang' as default_lang,"; + $sql.= " a.rowid as adid, a.label, a.code, n.rowid, n.type"; + $sql.= " FROM ".MAIN_DB_PREFIX."user as c,"; + $sql.= " ".MAIN_DB_PREFIX."c_action_trigger as a,"; + $sql.= " ".MAIN_DB_PREFIX."notify_def as n,"; + $sql.= " ".MAIN_DB_PREFIX."element_contact as ec"; + $sql.= " WHERE n.fk_user = c.rowid AND a.rowid = n.fk_action"; + $sql.= " AND n.fk_user = ec.fk_socpeople"; + if (is_numeric($notifcode)) $sql.= " AND n.fk_action = ".$notifcode; // Old usage + else $sql.= " AND a.code = '".$notifcode."'"; // New usage + $sql .= " AND ec.element_id = ".$object->id; + $result = $this->db->query($sql); if ($result) { @@ -386,9 +403,16 @@ class Notify ); if ($mailfile->sendfile()) - { - $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, objet_id, email)"; - $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".$object->socid.", ".$obj->cid.", '".$obj->type."', '".$object_type."', ".$object->id.", '".$this->db->escape($obj->email)."')"; + { if ($obj->user==1){ + $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_user, type, objet_type, objet_id, email)"; + $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".$obj->cid.", '".$obj->type."', '".$object_type."', ".$object->id.", '".$this->db->escape($obj->email)."')"; + + } + else { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify (daten, fk_action, fk_soc, fk_contact, type, objet_type, objet_id, email)"; + $sql.= " VALUES ('".$this->db->idate(dol_now())."', ".$notifcodedefid.", ".$object->socid.", ".$obj->cid.", '".$obj->type."', '".$object_type."', ".$object->id.", '".$this->db->escape($obj->email)."')"; + + } if (! $this->db->query($sql)) { dol_print_error($this->db); diff --git a/htdocs/core/lib/usergroups.lib.php b/htdocs/core/lib/usergroups.lib.php index 8b9c6c3406f..0b4e2abbc05 100644 --- a/htdocs/core/lib/usergroups.lib.php +++ b/htdocs/core/lib/usergroups.lib.php @@ -32,7 +32,7 @@ */ function user_prepare_head($object) { - global $db, $langs, $conf, $user; + global $langs, $conf, $user, $db; $langs->load("users"); @@ -88,6 +88,36 @@ function user_prepare_head($object) $h++; } + // Notifications + if ($user->societe_id == 0 && ! empty($conf->notification->enabled)) + { + $nbNote = 0; + $sql = "SELECT COUNT(n.rowid) as nb"; + $sql.= " FROM ".MAIN_DB_PREFIX."notify_def as n"; + $sql.= " WHERE fk_user = ".$object->id; + $resql=$db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + while ($i < $num) + { + $obj = $db->fetch_object($resql); + $nbNote=$obj->nb; + $i++; + } + } + else { + dol_print_error($db); + } + + $head[$h][0] = DOL_URL_ROOT.'/user/notify/card.php?id='.$object->id; + $head[$h][1] = $langs->trans("Notifications"); + if ($nbNote > 0) $head[$h][1].= ' '.$nbNote.''; + $head[$h][2] = 'notify'; + $h++; + } + // Show more tabs from modules // Entries must be declared in modules descriptor with line // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab diff --git a/htdocs/langs/en_US/companies.lang b/htdocs/langs/en_US/companies.lang index 92fef1d9d33..42485f4771a 100644 --- a/htdocs/langs/en_US/companies.lang +++ b/htdocs/langs/en_US/companies.lang @@ -416,6 +416,7 @@ Organization=Organization AutomaticallyGenerated=Automatically generated FiscalYearInformation=Information on the fiscal year FiscalMonthStart=Starting month of the fiscal year +YouMustAssignUserMailFirst=You must create email for this user first to be able to add emails notifications for him. YouMustCreateContactFirst=You must create emails contacts for third party first to be able to add emails notifications. ListSuppliersShort=List of suppliers ListProspectsShort=List of prospects @@ -442,4 +443,4 @@ ThirdpartiesMergeSuccess=Thirdparties have been merged ErrorThirdpartiesMerge=There was an error when deleting the thirdparties. Please check the log. Changes have been reverted. SaleRepresentativeLogin=Login of sale representative SaleRepresentativeFirstname=Firstname of sale representative -SaleRepresentativeLastname=Lastname of sale representative \ No newline at end of file +SaleRepresentativeLastname=Lastname of sale representative diff --git a/htdocs/langs/fr_FR/companies.lang b/htdocs/langs/fr_FR/companies.lang index bdf503511ce..ae6e38d6ea6 100644 --- a/htdocs/langs/fr_FR/companies.lang +++ b/htdocs/langs/fr_FR/companies.lang @@ -416,6 +416,7 @@ Organization=Organisme AutomaticallyGenerated=Généré automatiquement FiscalYearInformation=Information sur l'année fiscale FiscalMonthStart=Mois de début d'exercice +YouMustAssignUserMailFirst=Vous devez créer une adresse email pour cet utilisateur avant de pouvoir lui définir des notifications par emails. YouMustCreateContactFirst=Vous devez créer un contact avec une adresse email sur le tiers avant de pouvoir lui définir des notifications par emails. ListSuppliersShort=Liste fournisseurs ListProspectsShort=Liste prospects From e53510b0c44d0b281102335c7abe00b27809de2d Mon Sep 17 00:00:00 2001 From: abb Date: Sun, 13 Mar 2016 00:20:29 +0100 Subject: [PATCH 003/379] new:handle user notification in notification module --- htdocs/user/notify/card.php | 448 ++++++++++++++++++++++++++++++++++++ 1 file changed, 448 insertions(+) create mode 100644 htdocs/user/notify/card.php diff --git a/htdocs/user/notify/card.php b/htdocs/user/notify/card.php new file mode 100644 index 00000000000..ec7698a4cc9 --- /dev/null +++ b/htdocs/user/notify/card.php @@ -0,0 +1,448 @@ + + * Copyright (C) 2004-2014 Laurent Destailleur + * Copyright (C) 2010-2014 Juanjo Menent + * Copyright (C) 2015 Marcos García + * + * 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/user/notify/card.php + * \ingroup user notification + * \brief Tab for notifications of third party + */ + +require '../../main.inc.php'; +require_once DOL_DOCUMENT_ROOT.'/core/class/notify.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php'; +require_once DOL_DOCUMENT_ROOT.'/core/triggers/interface_50_modNotification_Notification.class.php'; + +$langs->load("companies"); +$langs->load("mails"); +$langs->load("admin"); +$langs->load("other"); + +$id = GETPOST("id",'int'); +$action = GETPOST('action'); +$actionid=GETPOST('actionid'); + +// Security check +if ($user->societe_id) $id=$user->societe_id; +$result = restrictedArea($user, 'societe','',''); + +$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="c.lastname"; + +$now=dol_now(); + + +/* + * Actions + */ + +// Add a notification +if ($action == 'add') +{ + $error=0; + + if ($actionid <= 0) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentitiesnoconv("Action")), 'errors'); + $error++; + } + + if (! $error) + { + $db->begin(); + + $sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def"; + $sql .= " WHERE fk_user=".$id." AND fk_action=".$actionid; + if ($db->query($sql)) + { + $sql = "INSERT INTO ".MAIN_DB_PREFIX."notify_def (datec,fk_user, fk_action)"; + $sql .= " VALUES ('".$db->idate($now)."',".$id.",".$actionid.")"; + + if (! $db->query($sql)) + { + $error++; + dol_print_error($db); + } + } + else + { + dol_print_error($db); + } + + if (! $error) + { + $db->commit(); + } + else + { + $db->rollback(); + } + } +} + +// Remove a notification +if ($action == 'delete') +{ + $sql = "DELETE FROM ".MAIN_DB_PREFIX."notify_def where rowid=".$_GET["actid"]; + $db->query($sql); +} + + + +/* + * View + */ + +$form = new Form($db); + +$object = new User($db); +$result=$object->fetch($id); + +$title=$langs->trans("ThirdParty").' - '.$langs->trans("Notification"); +if (! empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/',$conf->global->MAIN_HTML_TITLE) && $object->name) $title=$object->name.' - '.$langs->trans("Notification"); +$help_url='EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas'; +llxHeader('',$title,$help_url); + + +if ($result > 0) +{ + $langs->load("other"); + + $head = user_prepare_head($object); + + dol_fiche_head($head, 'notify', $langs->trans("User"),0,'user'); + + + print ''; + + // Ref + print ''; + print ''; + print ''."\n"; + + print ''; + print ''; + + // Firstname + print ''; + print ''; + print ''."\n"; + + // EMail + print ''; + print ''; + print "\n"; + + print '
'.$langs->trans("Ref").''; + print $form->showrefnav($object,'id','',$user->rights->user->user->lire || $user->admin); + print '
'.$langs->trans("Lastname").''.$object->lastname.'
'.$langs->trans("Firstname").''.$object->firstname.'
'.$langs->trans("EMail").''.dol_print_email($object->email,0,0,1).'
'; + + dol_fiche_end(); + + // Help + print $langs->trans("NotificationsDesc").'

'; + + print "\n"; + + // Add notification form + print_fiche_titre($langs->trans("AddNewNotification"),'',''); + + print '
'; + print ''; + print ''; + + $param="&id=".$id; + + // Line with titles + print ''; + print ''; + print_liste_field_titre($langs->trans("Target"),$_SERVER["PHP_SELF"],"c.lastname",'',$param,'"width="45%"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Action"),$_SERVER["PHP_SELF"],"a.titre",'',$param,'"width="35%"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"",'',$param,'"width="10%"',$sortfield,$sortorder); + print_liste_field_titre(''); + print "\n"; + + $var=false; +// $listofemails=$object->thirdparty_and_contact_email_array(); + if ($object->email) + { + $actions=array(); + + // Load array of available notifications + $notificationtrigger=new InterfaceNotification($db); + $listofnotifiedevents=$notificationtrigger->getListOfManagedEvents(); + + foreach($listofnotifiedevents as $notifiedevent) + { + $label=($langs->trans("Notify_".$notifiedevent['code'])!="Notify_".$notifiedevent['code']?$langs->trans("Notify_".$notifiedevent['code']):$notifiedevent['label']); + $actions[$notifiedevent['rowid']]=$label; + } + print ''; + print ''; + print ''; + print ''; + print ''; + } + else + { + print ''; + } + + print '
'; + print $object->email; + print ''; + print $form->selectarray("actionid",$actions,'',1); + print ''; + $type=array('email'=>$langs->trans("EMail")); + print $form->selectarray("typeid",$type); + print '
'; + print $langs->trans("YouMustAssignUserMailFirst"); + print '
'; + + print '
'; + print '
'; + + // List of active notifications + print_fiche_titre($langs->trans("ListOfActiveNotifications"),'',''); + $var=true; + + // Line with titles + print ''; + print ''; + print_liste_field_titre($langs->trans("Target"),$_SERVER["PHP_SELF"],"c.lastname",'',$param,'"width="45%"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Action"),$_SERVER["PHP_SELF"],"a.titre",'',$param,'"width="35%"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"",'',$param,'"width="10%"',$sortfield,$sortorder); + print_liste_field_titre('','',''); + print ''; + + $langs->load("errors"); + $langs->load("other"); + + // List of notifications enabled for contacts + $sql = "SELECT n.rowid, n.type,"; + $sql.= " a.code, a.label,"; + $sql.= " c.rowid as userid, c.lastname, c.firstname, c.email"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,"; + $sql.= " ".MAIN_DB_PREFIX."notify_def as n,"; + $sql.= " ".MAIN_DB_PREFIX."user c"; + $sql.= " WHERE a.rowid = n.fk_action"; + $sql.= " AND c.rowid = n.fk_user"; + $sql.= " AND c.rowid = ".$object->id; + + $resql=$db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + + $userstatic=new user($db); + + while ($i < $num) + { + $var = !$var; + + $obj = $db->fetch_object($resql); + + $userstatic->id=$obj->userid; + $userstatic->lastname=$obj->lastname; + $userstatic->firstname=$obj->firstname; + print ''; + print ''; + print ''; + print ''; + print ''; + $i++; + } + $db->free($resql); + } + else + { + dol_print_error($db); + } + + // List of notifications enabled for fixed email + /* + foreach($conf->global as $key => $val) + { + if (! preg_match('/^NOTIFICATION_FIXEDEMAIL_(.*)/', $key, $reg)) continue; + $var = ! $var; + print ''; + print ''; + print ''; + print ''; + print ''; + }*/ + if ($user->admin) + { + $var = ! $var; + print ''; + } + + print '
'.$userstatic->getNomUrl(1); + if ($obj->type == 'email') + { + if (isValidEmail($obj->email)) + { + print ' <'.$obj->email.'>'; + } + else + { + $langs->load("errors"); + print '   '.img_warning().' '.$langs->trans("ErrorBadEMail",$obj->email); + } + } + print ''; + $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label); + print $label; + print ''; + if ($obj->type == 'email') print $langs->trans("Email"); + if ($obj->type == 'sms') print $langs->trans("SMS"); + print ''.img_delete().'
'; + $listtmp=explode(',',$val); + $first=1; + foreach($listtmp as $keyemail => $valemail) + { + if (! $first) print ', '; + $first=0; + $valemail=trim($valemail); + //print $keyemail.' - '.$valemail.' - '.$reg[1].'
'; + if (isValidEmail($valemail, 1)) + { + if ($valemail == '__SUPERVISOREMAIL__') print $valemail; + else print ' <'.$valemail.'>'; + } + else + { + print ' '.img_warning().' '.$langs->trans("ErrorBadEMail",$valemail); + } + } + print '
'; + $notifcode=preg_replace('/_THRESHOLD_.*$/','',$reg[1]); + $notifcodecond=preg_replace('/^.*_(THRESHOLD_)/','$1',$reg[1]); + $label=($langs->trans("Notify_".$notifcode)!="Notify_".$notifcode?$langs->trans("Notify_".$notifcode):$notifcode); + print $label; + if (preg_match('/^THRESHOLD_HIGHER_(.*)$/',$notifcodecond,$regcond) && ($regcond[1] > 0)) + { + print ' - '.$langs->trans("IfAmountHigherThan",$regcond[1]); + } + print ''; + print $langs->trans("Email"); + print ''.$langs->trans("SeeModuleSetup", $langs->transnoentitiesnoconv("Module600Name")).'
'; + print '+ '.$langs->trans("SeeModuleSetup", $langs->transnoentitiesnoconv("Module600Name")).''; + print '
'; + print '
'; + + + // List of notifications done + print_fiche_titre($langs->trans("ListOfNotificationsDone"),'',''); + $var=true; + + // Line with titles + print ''; + print ''; + print_liste_field_titre($langs->trans("Target"),$_SERVER["PHP_SELF"],"c.lastname",'',$param,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Action"),$_SERVER["PHP_SELF"],"a.titre",'',$param,'',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Type"),$_SERVER["PHP_SELF"],"",'',$param,'',$sortfield,$sortorder); + //print_liste_field_titre($langs->trans("Object"),$_SERVER["PHP_SELF"],"",'',$param,'"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans("Date"),$_SERVER["PHP_SELF"],"a.daten",'',$param,'align="right"',$sortfield,$sortorder); + print ''; + + // List + $sql = "SELECT n.rowid, n.daten, n.email, n.objet_type as object_type, n.objet_id as object_id, n.type,"; + $sql.= " c.rowid as id, c.lastname, c.firstname, c.email as contactemail,"; + $sql.= " a.code, a.label"; + $sql.= " FROM ".MAIN_DB_PREFIX."c_action_trigger as a,"; + $sql.= " ".MAIN_DB_PREFIX."notify as n "; + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."user as c ON n.fk_user = c.rowid"; + $sql.= " WHERE a.rowid = n.fk_action"; + $sql.= " AND n.fk_user = ".$object->id; + + $resql=$db->query($sql); + if ($resql) + { + $num = $db->num_rows($resql); + $i = 0; + + $userstatic=new User($db); + + while ($i < $num) + { + $var = !$var; + + $obj = $db->fetch_object($resql); + + print ''; + print ''; + print ''; + // TODO Add link to object here for other types + /*print '';*/ + // print + print''; + print ''; + $i++; + } + $db->free($resql); + } + else + { + dol_print_error($db); + } + + print '
'; + if ($obj->id > 0) + { + $userstatic->id=$obj->id; + $userstatic->lastname=$obj->lastname; + $userstatic->firstname=$obj->firstname; + print $userstatic->getNomUrl(1); + print $obj->email?' <'.$obj->email.'>':$langs->trans("NoMail"); + } + else + { + print $obj->email; + } + print ''; + $label=($langs->trans("Notify_".$obj->code)!="Notify_".$obj->code?$langs->trans("Notify_".$obj->code):$obj->label); + print $label; + print ''; + if ($obj->type == 'email') print $langs->trans("Email"); + if ($obj->type == 'sms') print $langs->trans("Sms"); + print ''; + if ($obj->object_type == 'order') + { + $orderstatic->id=$obj->object_id; + $orderstatic->ref=... + print $orderstatic->getNomUrl(1); + } + print ''.dol_print_date($db->jdate($obj->daten), 'dayhour').'
'; +} +else dol_print_error('','RecordNotFound'); + + +llxFooter(); + +$db->close(); From 3f9126e66370a868eebc60aa43e8815e15924204 Mon Sep 17 00:00:00 2001 From: Bahfir Abbes Date: Mon, 14 Mar 2016 23:29:21 +0100 Subject: [PATCH 004/379] Update card.php --- htdocs/user/notify/card.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/user/notify/card.php b/htdocs/user/notify/card.php index ec7698a4cc9..e631c8d0ab2 100644 --- a/htdocs/user/notify/card.php +++ b/htdocs/user/notify/card.php @@ -1,8 +1,9 @@ * Copyright (C) 2004-2014 Laurent Destailleur - * Copyright (C) 2010-2014 Juanjo Menent + * Copyright (C) 2010-2014 Juanjo Menent * Copyright (C) 2015 Marcos García + * Copyright (C) 2016 Abbes Bahfir * * 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 From a1ed41646eebd606405cf79740402fbb12987637 Mon Sep 17 00:00:00 2001 From: Bahfir Abbes Date: Mon, 21 Mar 2016 19:15:01 +0100 Subject: [PATCH 005/379] moved userid parameter to end of list in getNotificationArray function --- htdocs/core/class/notify.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/class/notify.class.php b/htdocs/core/class/notify.class.php index 423e912e1be..798faefb289 100644 --- a/htdocs/core/class/notify.class.php +++ b/htdocs/core/class/notify.class.php @@ -98,7 +98,7 @@ class Notify * @param Object $object Object the notification is about (need it to check threshold value of some notifications) * @return array|int <0 if KO, array of notifications to send if OK */ - function getNotificationsArray($notifcode,$socid= 0,$userid= 0,$object=null) + function getNotificationsArray($notifcode,$socid= 0,$object=null,$userid= 0) { global $conf, $user; From ab06ffda5847f4c97ae43a5c885553ed14e18dfb Mon Sep 17 00:00:00 2001 From: gauthier Date: Fri, 3 Jun 2016 15:43:05 +0200 Subject: [PATCH 006/379] NEW : select default bank account on thirdparty card --- htdocs/comm/card.php | 32 ++++++++++++++++++- .../install/mysql/migration/4.0.0-4.1.0.sql | 24 ++++++++++++++ htdocs/install/mysql/tables/llx_societe.sql | 1 + htdocs/societe/class/societe.class.php | 5 +-- 4 files changed, 59 insertions(+), 3 deletions(-) create mode 100644 htdocs/install/mysql/migration/4.0.0-4.1.0.sql diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index 256a31fd947..8ead3188ae7 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -46,6 +46,8 @@ if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherent if (! empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; $langs->load("companies"); +$langs->load('banks'); + if (! empty($conf->contrat->enabled)) $langs->load("contracts"); if (! empty($conf->commande->enabled)) $langs->load("orders"); if (! empty($conf->expedition->enabled)) $langs->load("sendings"); @@ -124,7 +126,15 @@ if (empty($reshook)) if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } - // customer preferred shipping method + // Bank account + if ($action == 'setbankaccount' && $user->rights->societe->creer) + { + $object->fetch($id); + $result=$object->setBankAccount(GETPOST('fk_account','int')); + if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); + } + + // customer preferred shipping method if ($action == 'setshippingmethod' && $user->rights->societe->creer) { $object->fetch($id); @@ -337,6 +347,26 @@ if ($id > 0) print ""; print ''; + // Compte bancaire par défaut + print ''; + print ''; + print '
'; + print $langs->trans('BankAccount'); + print ''; + if (($action != 'editbankaccount') && $user->rights->societe->creer) print 'id.'">'.img_edit($langs->trans('SetBankAccount'),1).'
'; + print ''; + if ($action == 'editbankaccount') + { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->fk_account,'fk_account',1); + } + else + { + $form->formSelectAccount($_SERVER['PHP_SELF'].'?socid='.$object->id,$object->fk_account,'none'); + } + print ""; + print ''; + + // Relative discounts (Discounts-Drawbacks-Rebates) print ''; print '\n"; print "\n"; + +$var=!$var; + +print ""; +print ''; + +print '\n"; +print "\n"; + print '
'; print '
'; diff --git a/htdocs/install/mysql/migration/4.0.0-4.1.0.sql b/htdocs/install/mysql/migration/4.0.0-4.1.0.sql new file mode 100644 index 00000000000..10ca20953c3 --- /dev/null +++ b/htdocs/install/mysql/migration/4.0.0-4.1.0.sql @@ -0,0 +1,24 @@ +-- +-- Be carefull to requests order. +-- This file must be loaded by calling /install/index.php page +-- when current version is 4.0.0 or higher. +-- +-- To rename a table: ALTER TABLE llx_table RENAME TO llx_table_new; +-- To add a column: ALTER TABLE llx_table ADD COLUMN newcol varchar(60) NOT NULL DEFAULT '0' AFTER existingcol; +-- To rename a column: ALTER TABLE llx_table CHANGE COLUMN oldname newname varchar(60); +-- To drop a column: ALTER TABLE llx_table DROP COLUMN oldname; +-- To change type of field: ALTER TABLE llx_table MODIFY COLUMN name varchar(60); +-- To drop a foreign key: ALTER TABLE llx_table DROP FOREIGN KEY fk_name; +-- To drop an index: -- VMYSQL4.0 DROP INDEX nomindex on llx_table +-- To drop an index: -- VPGSQL8.0 DROP INDEX nomindex +-- To restrict request to Mysql version x.y minimum use -- VMYSQLx.y +-- To restrict request to Pgsql version x.y minimum use -- VPGSQLx.y +-- To make pk to be auto increment (mysql): VMYSQL4.3 ALTER TABLE llx_c_shipment_mode CHANGE COLUMN rowid rowid INTEGER NOT NULL AUTO_INCREMENT; +-- To make pk to be auto increment (postgres): VPGSQL8.2 NOT POSSIBLE. MUST DELETE/CREATE TABLE +-- To set a field as NULL: VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name DROP NOT NULL; +-- To set a field as default NULL: VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name SET DEFAULT NULL; +-- Note: fields with type BLOB/TEXT can't have default value. +-- -- VPGSQL8.2 DELETE FROM llx_usergroup_user WHERE fk_user NOT IN (SELECT rowid from llx_user); +-- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup); + +ALTER TABLE llx_societe ADD COLUMN fk_account integer; \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_societe.sql b/htdocs/install/mysql/tables/llx_societe.sql index 9822272e7c2..20440b692d7 100644 --- a/htdocs/install/mysql/tables/llx_societe.sql +++ b/htdocs/install/mysql/tables/llx_societe.sql @@ -47,6 +47,7 @@ create table llx_societe town varchar(50), -- town fk_departement integer DEFAULT 0, -- fk_pays integer DEFAULT 0, -- + fk_account integer DEFAULT 0, -- phone varchar(20), -- phone number fax varchar(20), -- fax number url varchar(255), -- diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index cb1d783497c..7e06e5171d3 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1023,7 +1023,7 @@ class Societe extends CommonObject $sql .= ', s.fk_forme_juridique as forme_juridique_code'; $sql .= ', s.webservices_url, s.webservices_key'; $sql .= ', s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur, s.parent, s.barcode'; - $sql .= ', s.fk_departement, s.fk_pays as country_id, s.fk_stcomm, s.remise_client, s.mode_reglement, s.cond_reglement, s.tva_assuj'; + $sql .= ', s.fk_departement, s.fk_pays as country_id, s.fk_stcomm, s.remise_client, s.mode_reglement, s.cond_reglement, s.fk_account, s.tva_assuj'; $sql .= ', s.mode_reglement_supplier, s.cond_reglement_supplier, s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo'; $sql .= ', s.fk_shipping_method'; $sql .= ', s.outstanding_limit, s.import_key, s.canvas, s.fk_incoterms, s.location_incoterms'; @@ -1153,7 +1153,8 @@ class Societe extends CommonObject $this->mode_reglement_supplier_id = $obj->mode_reglement_supplier; $this->cond_reglement_supplier_id = $obj->cond_reglement_supplier; $this->shipping_method_id = ($obj->fk_shipping_method>0)?$obj->fk_shipping_method:null; - + $this->fk_account = $obj->fk_account; + $this->client = $obj->client; $this->fournisseur = $obj->fournisseur; From 41856a920e17b6eb1bb39e393c712b8cea137532 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Fri, 3 Jun 2016 23:41:32 +0200 Subject: [PATCH 007/379] if \n or \r we addquote too --- htdocs/core/modules/export/export_csv.modules.php | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/htdocs/core/modules/export/export_csv.modules.php b/htdocs/core/modules/export/export_csv.modules.php index e8977c11789..83de884e7c3 100644 --- a/htdocs/core/modules/export/export_csv.modules.php +++ b/htdocs/core/modules/export/export_csv.modules.php @@ -307,9 +307,12 @@ class ExportCsv extends ModeleExports //print $charset.' '.$newvalue."\n"; // Rule 1 CSV: No CR, LF in cells + $oldvalue=$newvalue; $newvalue=str_replace("\r",'',$newvalue); $newvalue=str_replace("\n",'\n',$newvalue); - + if($oldvalue != $newvalue) + $addquote=1; + // Rule 2 CSV: If value contains ", we must escape with ", and add " if (preg_match('/"/',$newvalue)) { From 2a8f17bc40744f9ea083098bf04aa9c98c39771c Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Fri, 3 Jun 2016 23:58:37 +0200 Subject: [PATCH 008/379] Update export_csv.modules.php --- htdocs/core/modules/export/export_csv.modules.php | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/htdocs/core/modules/export/export_csv.modules.php b/htdocs/core/modules/export/export_csv.modules.php index 83de884e7c3..04b090f8827 100644 --- a/htdocs/core/modules/export/export_csv.modules.php +++ b/htdocs/core/modules/export/export_csv.modules.php @@ -299,7 +299,9 @@ class ExportCsv extends ModeleExports */ function csv_clean($newvalue, $charset) { + global $conf; $addquote=0; + // Rule Dolibarr: No HTML //print $charset.' '.$newvalue."\n"; @@ -308,10 +310,14 @@ class ExportCsv extends ModeleExports // Rule 1 CSV: No CR, LF in cells $oldvalue=$newvalue; - $newvalue=str_replace("\r",'',$newvalue); + $newvalue=str_replace("\r",'\r',$newvalue); $newvalue=str_replace("\n",'\n',$newvalue); - if($oldvalue != $newvalue) + if ($conf->global->USE_STRICT_CSV_RULES && $oldvalue != $newvalue) + { + // If strict use of CSV rules, we just add quote + $newvalue=$oldvalue; $addquote=1; + } // Rule 2 CSV: If value contains ", we must escape with ", and add " if (preg_match('/"/',$newvalue)) From 3cbbdf5e20aa99f32308c913a583ed452347c8bc Mon Sep 17 00:00:00 2001 From: phf Date: Sat, 4 Jun 2016 18:23:22 +0200 Subject: [PATCH 009/379] Fix #2858 --- htdocs/admin/stock.php | 20 +++++ htdocs/core/modules/modStock.class.php | 4 +- htdocs/langs/en_US/stocks.lang | 2 + htdocs/product/stock/product.php | 117 +++++++++++++++---------- 4 files changed, 94 insertions(+), 49 deletions(-) diff --git a/htdocs/admin/stock.php b/htdocs/admin/stock.php index 87ed5fe64c6..d0a859e1987 100644 --- a/htdocs/admin/stock.php +++ b/htdocs/admin/stock.php @@ -49,6 +49,10 @@ if($action) { $res = dolibarr_set_const($db, "STOCK_USERSTOCK_AUTOCREATE", GETPOST('STOCK_USERSTOCK_AUTOCREATE','alpha'),'chaine',0,'',$conf->entity); } + if ($action == 'STOCK_ALLOW_NEGATIVE_TRANSFER') + { + $res = dolibarr_set_const($db, "STOCK_ALLOW_NEGATIVE_TRANSFER", GETPOST('STOCK_ALLOW_NEGATIVE_TRANSFER','alpha'),'chaine',0,'',$conf->entity); + } // Mode of stock decrease if ($action == 'STOCK_CALCULATE_ON_BILL' || $action == 'STOCK_CALCULATE_ON_VALIDATE_ORDER' @@ -367,6 +371,22 @@ print '' print ''; print "
'.$langs->trans("WarehouseAllowNegativeTransfer").''; +print "
"; +print ''; +print ""; +print $form->selectyesno("STOCK_ALLOW_NEGATIVE_TRANSFER",$conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER,1); +print ''; +print '
'; +print "
'; print '
'; diff --git a/htdocs/core/modules/modStock.class.php b/htdocs/core/modules/modStock.class.php index 8f6840a21b0..5ac13df8ecc 100644 --- a/htdocs/core/modules/modStock.class.php +++ b/htdocs/core/modules/modStock.class.php @@ -70,7 +70,9 @@ class modStock extends DolibarrModules $this->langfiles = array("stocks"); // Constants - $this->const = array(); + $this->const = array( + 0=>array('STOCK_ALLOW_NEGATIVE_TRANSFER','chaine','1','',1) + ); // Boxes $this->boxes = array(); diff --git a/htdocs/langs/en_US/stocks.lang b/htdocs/langs/en_US/stocks.lang index fdd6408accb..fb2a034b9f6 100644 --- a/htdocs/langs/en_US/stocks.lang +++ b/htdocs/langs/en_US/stocks.lang @@ -123,3 +123,5 @@ StockMustBeEnoughForInvoice=Stock level must be enough to add product/service in StockMustBeEnoughForOrder=Stock level must be enough to add product/service into order StockMustBeEnoughForShipment= Stock level must be enough to add product/service into shipment WarehouseMustBeSelectedAtFirstStepWhenProductBatchModuleOn=Source warehouse must be defined here when batch module is on. It will be used to list wich lot/serial is available for product that required lot/serial data for movement. If you want to send products from different warehouses, just make the shipment into several steps. +WarehouseAllowNegativeTransfer=Allow transfer even without stock +qtyToTranferIsNotEnough=You don't have enough stock from your source warehouse \ No newline at end of file diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php index 83ad3088a11..c9ba20e95f5 100644 --- a/htdocs/product/stock/product.php +++ b/htdocs/product/stock/product.php @@ -204,59 +204,80 @@ if ($action == "transfert_stock" && ! $cancel) //print 'price src='.$pricesrc.', price dest='.$pricedest;exit; - $pdluoid=GETPOST('pdluoid','int'); - - if ($pdluoid>0) + $do_tranfer = true; + + if (empty($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER)) { - $pdluo = new Productbatch($db); - $result=$pdluo->fetch($pdluoid); - - if ($result>0 && $pdluo->id) - { - // Remove stock - $result1=$product->correct_stock_batch( - $user, - $pdluo->warehouseid, - GETPOST("nbpiece",'int'), - 1, - GETPOST("label",'san_alpha'), - $pricesrc, - $pdluo->eatby,$pdluo->sellby,$pdluo->batch - ); - // Add stock - $result2=$product->correct_stock_batch( - $user, - GETPOST("id_entrepot_destination",'int'), - GETPOST("nbpiece",'int'), - 0, - GETPOST("label",'san_alpha'), - $pricedest, - $pdluo->eatby,$pdluo->sellby,$pdluo->batch - ); - } + $fk_warehouse_source = GETPOST("id_entrepot_source"); + $nb_unit = GETPOST("nbpiece",'int'); + + if (empty($product->stock_warehouse[$fk_warehouse_source]->real) || $product->stock_warehouse[$fk_warehouse_source]->real < $nb_unit) + { + $do_tranfer = false; + $result1 = $result2 = -1; + $action=''; + $product->error = $langs->trans('qtyToTranferIsNotEnough'); + } } - else + + if ($do_tranfer) { - // Remove stock - $result1=$product->correct_stock( - $user, - GETPOST("id_entrepot_source"), - GETPOST("nbpiece"), - 1, - GETPOST("label"), - $pricesrc - ); + $pdluoid=GETPOST('pdluoid','int'); - // Add stock - $result2=$product->correct_stock( - $user, - GETPOST("id_entrepot_destination"), - GETPOST("nbpiece"), - 0, - GETPOST("label"), - $pricedest - ); + if ($pdluoid>0) + { + $pdluo = new Productbatch($db); + $result=$pdluo->fetch($pdluoid); + + if ($result>0 && $pdluo->id) + { + // Remove stock + $result1=$product->correct_stock_batch( + $user, + $pdluo->warehouseid, + GETPOST("nbpiece",'int'), + 1, + GETPOST("label",'san_alpha'), + $pricesrc, + $pdluo->eatby,$pdluo->sellby,$pdluo->batch + ); + // Add stock + $result2=$product->correct_stock_batch( + $user, + GETPOST("id_entrepot_destination",'int'), + GETPOST("nbpiece",'int'), + 0, + GETPOST("label",'san_alpha'), + $pricedest, + $pdluo->eatby,$pdluo->sellby,$pdluo->batch + ); + } + } + else + { + // Remove stock + $result1=$product->correct_stock( + $user, + GETPOST("id_entrepot_source"), + GETPOST("nbpiece"), + 1, + GETPOST("label"), + $pricesrc + ); + + // Add stock + $result2=$product->correct_stock( + $user, + GETPOST("id_entrepot_destination"), + GETPOST("nbpiece"), + 0, + GETPOST("label"), + $pricedest + ); + } + } + if ($result1 >= 0 && $result2 >= 0) { $db->commit(); From 2f36611cad728c377adff5a247508457221d3e60 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Sat, 4 Jun 2016 19:22:15 +0200 Subject: [PATCH 010/379] Update export_csv.modules.php --- htdocs/core/modules/export/export_csv.modules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/export/export_csv.modules.php b/htdocs/core/modules/export/export_csv.modules.php index 04b090f8827..d11c2cb275f 100644 --- a/htdocs/core/modules/export/export_csv.modules.php +++ b/htdocs/core/modules/export/export_csv.modules.php @@ -312,7 +312,7 @@ class ExportCsv extends ModeleExports $oldvalue=$newvalue; $newvalue=str_replace("\r",'\r',$newvalue); $newvalue=str_replace("\n",'\n',$newvalue); - if ($conf->global->USE_STRICT_CSV_RULES && $oldvalue != $newvalue) + if (! empty($conf->global->USE_STRICT_CSV_RULES && $oldvalue != $newvalue) { // If strict use of CSV rules, we just add quote $newvalue=$oldvalue; From 7cd8e270cc632fe319961e133cc3477234ab8625 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Sat, 4 Jun 2016 19:25:32 +0200 Subject: [PATCH 011/379] Update export_csv.modules.php --- htdocs/core/modules/export/export_csv.modules.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/modules/export/export_csv.modules.php b/htdocs/core/modules/export/export_csv.modules.php index d11c2cb275f..58891ddd2c9 100644 --- a/htdocs/core/modules/export/export_csv.modules.php +++ b/htdocs/core/modules/export/export_csv.modules.php @@ -312,7 +312,7 @@ class ExportCsv extends ModeleExports $oldvalue=$newvalue; $newvalue=str_replace("\r",'\r',$newvalue); $newvalue=str_replace("\n",'\n',$newvalue); - if (! empty($conf->global->USE_STRICT_CSV_RULES && $oldvalue != $newvalue) + if (! empty($conf->global->USE_STRICT_CSV_RULES) && $oldvalue != $newvalue) { // If strict use of CSV rules, we just add quote $newvalue=$oldvalue; From 85740a618ebf64d40b65b9d20da9675f467ba706 Mon Sep 17 00:00:00 2001 From: gauthier Date: Mon, 6 Jun 2016 16:21:05 +0200 Subject: [PATCH 012/379] NEW : add restrictions on standard exports (societe, propal, expedition) --- htdocs/core/modules/modExpedition.class.php | 4 +++- htdocs/core/modules/modPropale.class.php | 4 +++- htdocs/core/modules/modSociete.class.php | 7 +++++-- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/htdocs/core/modules/modExpedition.class.php b/htdocs/core/modules/modExpedition.class.php index 4f7baff0c64..26dbfc5a803 100644 --- a/htdocs/core/modules/modExpedition.class.php +++ b/htdocs/core/modules/modExpedition.class.php @@ -43,7 +43,7 @@ class modExpedition extends DolibarrModules */ function __construct($db) { - global $conf; + global $conf, $user; $this->db = $db; $this->numero = 80; @@ -257,6 +257,7 @@ class modExpedition extends DolibarrModules $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'expedition as c'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'expedition_extrafields as extra ON c.rowid = extra.fk_object,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'societe as s'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'expeditiondet as ed'; @@ -271,6 +272,7 @@ class modExpedition extends DolibarrModules } $this->export_sql_end[$r] .=' WHERE c.fk_soc = s.rowid AND c.rowid = ed.fk_expedition AND ed.fk_origin_line = cd.rowid'; $this->export_sql_end[$r] .=' AND c.entity IN ('.getEntity('shipment',1).')'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; } diff --git a/htdocs/core/modules/modPropale.class.php b/htdocs/core/modules/modPropale.class.php index 32ebb340e71..dd8f819c5eb 100644 --- a/htdocs/core/modules/modPropale.class.php +++ b/htdocs/core/modules/modPropale.class.php @@ -43,7 +43,7 @@ class modPropale extends DolibarrModules */ function __construct($db) { - global $conf; + global $conf, $user; $this->db = $db; $this->numero = 20; @@ -184,6 +184,7 @@ class modPropale extends DolibarrModules include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s '; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'propal as c'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON c.fk_projet = pj.rowid'; @@ -196,6 +197,7 @@ class modPropale extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object'; $this->export_sql_end[$r] .=' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_propal'; $this->export_sql_end[$r] .=' AND c.entity IN ('.getEntity('propal',1).')'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; } diff --git a/htdocs/core/modules/modSociete.class.php b/htdocs/core/modules/modSociete.class.php index baf680f0352..ec60d7aafeb 100644 --- a/htdocs/core/modules/modSociete.class.php +++ b/htdocs/core/modules/modSociete.class.php @@ -43,7 +43,7 @@ class modSociete extends DolibarrModules */ function __construct($db) { - global $conf; + global $conf, $user; $this->db = $db; $this->numero = 1; @@ -274,7 +274,8 @@ class modSociete extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON sc.fk_user = u.rowid'; $this->export_sql_end[$r] .=' WHERE s.entity IN ('.getEntity('societe', 1).')'; - + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; + // Export list of contacts and attributes $r++; $this->export_code[$r]=$this->rights_class.'_'.$r; @@ -295,10 +296,12 @@ class modSociete extends DolibarrModules $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'socpeople as c'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON c.fk_soc = s.rowid'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON c.fk_departement = d.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON c.fk_pays = co.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople_extrafields as extra ON extra.fk_object = c.rowid'; $this->export_sql_end[$r] .=' WHERE c.entity IN ('.getEntity("societe", 1).')'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; // Imports From a2df6dc59f66c4b24e5c2570c6b23f637b119ebe Mon Sep 17 00:00:00 2001 From: gauthier Date: Mon, 6 Jun 2016 17:51:39 +0200 Subject: [PATCH 013/379] NEW : add restrictions on standard exports (agenda, order, deplacement, facture, fournisseur) --- htdocs/core/modules/modAgenda.class.php | 6 +++++- htdocs/core/modules/modCommande.class.php | 4 +++- htdocs/core/modules/modDeplacement.class.php | 10 +++++++++- htdocs/core/modules/modFacture.class.php | 6 +++++- htdocs/core/modules/modFournisseur.class.php | 8 +++++++- 5 files changed, 29 insertions(+), 5 deletions(-) diff --git a/htdocs/core/modules/modAgenda.class.php b/htdocs/core/modules/modAgenda.class.php index 0d0720d7440..b4e12ab3c5a 100644 --- a/htdocs/core/modules/modAgenda.class.php +++ b/htdocs/core/modules/modAgenda.class.php @@ -44,7 +44,7 @@ class modAgenda extends DolibarrModules */ function __construct($db) { - global $conf; + global $conf, $user; $this->db = $db; $this->numero = 2400; @@ -392,10 +392,14 @@ class modAgenda extends DolibarrModules $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'actioncomm as ac'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_actioncomm as cac on ac.fk_action = cac.id'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'actioncomm_resources acr on ac.id = acr.fk_actioncomm'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople as sp on ac.fk_contact = sp.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s on ac.fk_soc = s.rowid'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co on s.fk_pays = co.rowid'; $this->export_sql_end[$r] .=' WHERE ac.entity IN ('.getEntity('agenda',1).')'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND (sc.fk_user = '.$user->id.' OR ac.fk_soc IS NULL)'; + if(!$user->rights->agenda->allactions->read) $this->export_sql_end[$r] .=' AND acr.fk_element = '.$user->id; $this->export_sql_end[$r] .=' ORDER BY ac.datep'; } diff --git a/htdocs/core/modules/modCommande.class.php b/htdocs/core/modules/modCommande.class.php index ec11708641c..be644dca471 100644 --- a/htdocs/core/modules/modCommande.class.php +++ b/htdocs/core/modules/modCommande.class.php @@ -45,7 +45,7 @@ class modCommande extends DolibarrModules */ function __construct($db) { - global $conf; + global $conf, $user; $this->db = $db; $this->numero = 25; @@ -191,6 +191,7 @@ class modCommande extends DolibarrModules include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'commande as c'; @@ -204,6 +205,7 @@ class modCommande extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object'; $this->export_sql_end[$r] .=' WHERE c.fk_soc = s.rowid AND c.rowid = cd.fk_commande'; $this->export_sql_end[$r] .=' AND c.entity IN ('.getEntity('commande',1).')'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; } diff --git a/htdocs/core/modules/modDeplacement.class.php b/htdocs/core/modules/modDeplacement.class.php index 19ef73f37bc..d1fa2e4ad33 100644 --- a/htdocs/core/modules/modDeplacement.class.php +++ b/htdocs/core/modules/modDeplacement.class.php @@ -39,7 +39,7 @@ class modDeplacement extends DolibarrModules */ function __construct($db) { - global $conf; + global $conf, $user; $this->db = $db; $this->numero = 75 ; @@ -124,8 +124,16 @@ class modDeplacement extends DolibarrModules $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'user as u'; $this->export_sql_end[$r] .=', '.MAIN_DB_PREFIX.'deplacement as d'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON d.fk_soc = s.rowid'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' WHERE d.fk_user = u.rowid'; $this->export_sql_end[$r] .=' AND d.entity IN ('.getEntity('deplacement',1).')'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND (sc.fk_user = '.$user->id.' OR d.fk_soc IS NULL)'; + + $childids = $user->getAllChildIds(); + $childids[]=$user->id; + + if (!$user->rights->deplacement->readall && !$user->rights->deplacement->lire_tous) $sql.=' AND d.fk_user IN ('.join(',',$childids).')'; + } diff --git a/htdocs/core/modules/modFacture.class.php b/htdocs/core/modules/modFacture.class.php index c4f9dc20243..b35af14ba6f 100644 --- a/htdocs/core/modules/modFacture.class.php +++ b/htdocs/core/modules/modFacture.class.php @@ -42,7 +42,7 @@ class modFacture extends DolibarrModules */ function __construct($db) { - global $conf; + global $conf, $user; $this->db = $db; $this->numero = 30; @@ -205,6 +205,7 @@ class modFacture extends DolibarrModules include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture as f'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid'; @@ -217,6 +218,7 @@ class modFacture extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product_extrafields as extra3 on p.rowid = extra3.fk_object'; $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture'; $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('facture',1).')'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; $r++; $this->export_code[$r]=$this->rights_class.'_'.$r; @@ -232,6 +234,7 @@ class modFacture extends DolibarrModules include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture as f'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid'; @@ -245,6 +248,7 @@ class modFacture extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'bank_account as ba ON ba.rowid = b.fk_account'; $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('facture',1).')'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; $r++; } diff --git a/htdocs/core/modules/modFournisseur.class.php b/htdocs/core/modules/modFournisseur.class.php index 3cf63b6cfb9..5bc4bddd8cf 100644 --- a/htdocs/core/modules/modFournisseur.class.php +++ b/htdocs/core/modules/modFournisseur.class.php @@ -42,7 +42,7 @@ class modFournisseur extends DolibarrModules */ function __construct($db) { - global $conf; + global $conf, $user; $this->db = $db; $this->numero = 40; @@ -366,6 +366,7 @@ class modFournisseur extends DolibarrModules // End add extra fields line $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture_fourn as f'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)'; @@ -375,6 +376,7 @@ class modFournisseur extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)'; $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_facture_fourn'; $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_invoice',1).')'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; $r++; $this->export_code[$r]=$this->rights_class.'_'.$r; @@ -428,6 +430,7 @@ class modFournisseur extends DolibarrModules // End add extra fields object $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture_fourn as f'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)'; @@ -436,6 +439,7 @@ class modFournisseur extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'paiementfourn as p ON pf.fk_paiementfourn = p.rowid'; $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_invoice',1).')'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; // Order $r++; @@ -532,6 +536,7 @@ class modFournisseur extends DolibarrModules // End add extra fields line $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; + $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'commande_fournisseur as f'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)'; @@ -543,6 +548,7 @@ class modFournisseur extends DolibarrModules $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'product as p on (fd.fk_product = p.rowid)'; $this->export_sql_end[$r] .=' WHERE f.fk_soc = s.rowid AND f.rowid = fd.fk_commande'; $this->export_sql_end[$r] .=' AND f.entity IN ('.getEntity('supplier_order',1).')'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND sc.fk_user = '.$user->id; } From 2aa688e6f2e68e7d9670cb2bd3732a84c827815b Mon Sep 17 00:00:00 2001 From: gauthier Date: Tue, 7 Jun 2016 09:39:48 +0200 Subject: [PATCH 014/379] NEW : tests for LEFT JOIN --- htdocs/core/modules/modAgenda.class.php | 4 ++-- htdocs/core/modules/modCommande.class.php | 2 +- htdocs/core/modules/modDeplacement.class.php | 2 +- htdocs/core/modules/modExpedition.class.php | 2 +- htdocs/core/modules/modFacture.class.php | 4 ++-- htdocs/core/modules/modFournisseur.class.php | 6 +++--- htdocs/core/modules/modPropale.class.php | 2 +- htdocs/core/modules/modSociete.class.php | 2 +- 8 files changed, 12 insertions(+), 12 deletions(-) diff --git a/htdocs/core/modules/modAgenda.class.php b/htdocs/core/modules/modAgenda.class.php index b4e12ab3c5a..8224673f1a2 100644 --- a/htdocs/core/modules/modAgenda.class.php +++ b/htdocs/core/modules/modAgenda.class.php @@ -392,10 +392,10 @@ class modAgenda extends DolibarrModules $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'actioncomm as ac'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_actioncomm as cac on ac.fk_action = cac.id'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'actioncomm_resources acr on ac.id = acr.fk_actioncomm'; + if(!$user->rights->agenda->allactions->read) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'actioncomm_resources acr on ac.id = acr.fk_actioncomm'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople as sp on ac.fk_contact = sp.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s on ac.fk_soc = s.rowid'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co on s.fk_pays = co.rowid'; $this->export_sql_end[$r] .=' WHERE ac.entity IN ('.getEntity('agenda',1).')'; if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND (sc.fk_user = '.$user->id.' OR ac.fk_soc IS NULL)'; diff --git a/htdocs/core/modules/modCommande.class.php b/htdocs/core/modules/modCommande.class.php index be644dca471..7d38a427e1c 100644 --- a/htdocs/core/modules/modCommande.class.php +++ b/htdocs/core/modules/modCommande.class.php @@ -191,7 +191,7 @@ class modCommande extends DolibarrModules include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'commande as c'; diff --git a/htdocs/core/modules/modDeplacement.class.php b/htdocs/core/modules/modDeplacement.class.php index d1fa2e4ad33..c1e9c092ff6 100644 --- a/htdocs/core/modules/modDeplacement.class.php +++ b/htdocs/core/modules/modDeplacement.class.php @@ -124,7 +124,7 @@ class modDeplacement extends DolibarrModules $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'user as u'; $this->export_sql_end[$r] .=', '.MAIN_DB_PREFIX.'deplacement as d'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON d.fk_soc = s.rowid'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' WHERE d.fk_user = u.rowid'; $this->export_sql_end[$r] .=' AND d.entity IN ('.getEntity('deplacement',1).')'; if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' AND (sc.fk_user = '.$user->id.' OR d.fk_soc IS NULL)'; diff --git a/htdocs/core/modules/modExpedition.class.php b/htdocs/core/modules/modExpedition.class.php index 26dbfc5a803..189d31265a4 100644 --- a/htdocs/core/modules/modExpedition.class.php +++ b/htdocs/core/modules/modExpedition.class.php @@ -257,7 +257,7 @@ class modExpedition extends DolibarrModules $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'expedition as c'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'expedition_extrafields as extra ON c.rowid = extra.fk_object,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'societe as s'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'expeditiondet as ed'; diff --git a/htdocs/core/modules/modFacture.class.php b/htdocs/core/modules/modFacture.class.php index b35af14ba6f..794032c59f5 100644 --- a/htdocs/core/modules/modFacture.class.php +++ b/htdocs/core/modules/modFacture.class.php @@ -205,7 +205,7 @@ class modFacture extends DolibarrModules include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture as f'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid'; @@ -234,7 +234,7 @@ class modFacture extends DolibarrModules include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c on s.fk_pays = c.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture as f'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON f.fk_projet = pj.rowid'; diff --git a/htdocs/core/modules/modFournisseur.class.php b/htdocs/core/modules/modFournisseur.class.php index 5bc4bddd8cf..794b6cb50ff 100644 --- a/htdocs/core/modules/modFournisseur.class.php +++ b/htdocs/core/modules/modFournisseur.class.php @@ -366,7 +366,7 @@ class modFournisseur extends DolibarrModules // End add extra fields line $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture_fourn as f'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)'; @@ -430,7 +430,7 @@ class modFournisseur extends DolibarrModules // End add extra fields object $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'facture_fourn as f'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)'; @@ -536,7 +536,7 @@ class modFournisseur extends DolibarrModules // End add extra fields line $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'commande_fournisseur as f'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as project on (f.fk_projet = project.rowid)'; diff --git a/htdocs/core/modules/modPropale.class.php b/htdocs/core/modules/modPropale.class.php index dd8f819c5eb..e9fe448baf7 100644 --- a/htdocs/core/modules/modPropale.class.php +++ b/htdocs/core/modules/modPropale.class.php @@ -184,7 +184,7 @@ class modPropale extends DolibarrModules include DOL_DOCUMENT_ROOT.'/core/extrafieldsinexport.inc.php'; $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'societe as s '; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON s.fk_pays = co.rowid,'; $this->export_sql_end[$r] .=' '.MAIN_DB_PREFIX.'propal as c'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pj ON c.fk_projet = pj.rowid'; diff --git a/htdocs/core/modules/modSociete.class.php b/htdocs/core/modules/modSociete.class.php index ec60d7aafeb..c238470ce6f 100644 --- a/htdocs/core/modules/modSociete.class.php +++ b/htdocs/core/modules/modSociete.class.php @@ -296,7 +296,7 @@ class modSociete extends DolibarrModules $this->export_sql_start[$r]='SELECT DISTINCT '; $this->export_sql_end[$r] =' FROM '.MAIN_DB_PREFIX.'socpeople as c'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON c.fk_soc = s.rowid'; - $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; + if(!$user->rights->societe->client->voir) $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'societe_commerciaux as sc ON sc.fk_soc = s.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON c.fk_departement = d.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as co ON c.fk_pays = co.rowid'; $this->export_sql_end[$r] .=' LEFT JOIN '.MAIN_DB_PREFIX.'socpeople_extrafields as extra ON extra.fk_object = c.rowid'; From 67392fbac5005c4ea1cecd4f045e2312e68e79ab Mon Sep 17 00:00:00 2001 From: phf Date: Tue, 7 Jun 2016 12:27:43 +0200 Subject: [PATCH 015/379] Fix move the code into mouvementstock class --- .../stock/class/mouvementstock.class.php | 13 +- htdocs/product/stock/product.php | 173 ++++++++---------- 2 files changed, 89 insertions(+), 97 deletions(-) diff --git a/htdocs/product/stock/class/mouvementstock.class.php b/htdocs/product/stock/class/mouvementstock.class.php index b9859f9ec9b..accaaba6c30 100644 --- a/htdocs/product/stock/class/mouvementstock.class.php +++ b/htdocs/product/stock/class/mouvementstock.class.php @@ -240,7 +240,7 @@ class MouvementStock extends CommonObject return -1; } } - + // TODO Check qty is ok for stock move. if (! empty($conf->productbatch->enabled) && $product->hasbatch() && ! $skip_batch) { @@ -250,6 +250,17 @@ class MouvementStock extends CommonObject { } + + if (empty($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER) && in_array($type, array(1, 2))) + { + if (empty($product->stock_warehouse[$entrepot_id]->real) || $product->stock_warehouse[$entrepot_id]->real < abs($qty)) + { + $this->error = $langs->trans('qtyToTranferIsNotEnough'); + $this->errors[] = $langs->trans('qtyToTranferIsNotEnough'); + $this->db->rollback(); + return -8; + } + } // Define if we must make the stock change (If product type is a service or if stock is used also for services) $movestock=0; diff --git a/htdocs/product/stock/product.php b/htdocs/product/stock/product.php index 4c92c353027..b7ccc14fc7e 100644 --- a/htdocs/product/stock/product.php +++ b/htdocs/product/stock/product.php @@ -231,117 +231,98 @@ if ($action == "transfert_stock" && ! $cancel) $pricesrc=0; if (isset($object->pmp)) $pricesrc=$object->pmp; $pricedest=$pricesrc; - - $do_tranfer = true; - if (empty($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER)) - { - $fk_warehouse_source = GETPOST("id_entrepot"); - $nb_unit = GETPOST("nbpiece",'int'); - - if (empty($object->stock_warehouse[$fk_warehouse_source]->real) || $object->stock_warehouse[$fk_warehouse_source]->real < $nb_unit) - { - $do_tranfer = false; - $result1 = $result2 = -1; - $action=''; - $object->error = $langs->trans('qtyToTranferIsNotEnough'); - } - } - if ($do_tranfer) + if ($object->hasbatch()) { + $pdluo = new Productbatch($db); - if ($object->hasbatch()) + if ($pdluoid > 0) { - $pdluo = new Productbatch($db); - - if ($pdluoid > 0) + $result=$pdluo->fetch($pdluoid); + if ($result) { - $result=$pdluo->fetch($pdluoid); - if ($result) - { - $srcwarehouseid=$pdluo->warehouseid; - $batch=$pdluo->batch; - $eatby=$pdluo->eatby; - $sellby=$pdluo->sellby; - } - else - { - setEventMessages($pdluo->error, $pdluo->errors, 'errors'); - $error++; - } + $srcwarehouseid=$pdluo->warehouseid; + $batch=$pdluo->batch; + $eatby=$pdluo->eatby; + $sellby=$pdluo->sellby; } else { - $srcwarehouseid=GETPOST('id_entrepot','int'); - $batch=GETPOST('batch_number'); - $eatby=$d_eatby; - $sellby=$d_sellby; - } - - if (! $error) - { - // Remove stock - $result1=$object->correct_stock_batch( - $user, - $srcwarehouseid, - GETPOST("nbpiece",'int'), - 1, - GETPOST("label",'san_alpha'), - $pricesrc, - $eatby,$sellby,$batch, - GETPOST('inventorycode') - ); - if ($result1 < 0) $error++; - } - if (! $error) - { - // Add stock - $result2=$object->correct_stock_batch( - $user, - GETPOST("id_entrepot_destination",'int'), - GETPOST("nbpiece",'int'), - 0, - GETPOST("label",'san_alpha'), - $pricedest, - $eatby,$sellby,$batch, - GETPOST('inventorycode') - ); - if ($result2 < 0) $error++; + setEventMessages($pdluo->error, $pdluo->errors, 'errors'); + $error++; } } else { - if (! $error) - { - // Remove stock - $result1=$object->correct_stock( - $user, - GETPOST("id_entrepot"), - GETPOST("nbpiece"), - 1, - GETPOST("label"), - $pricesrc, - GETPOST('inventorycode') - ); - if ($result1 < 0) $error++; - } - if (! $error) - { - // Add stock - $result2=$object->correct_stock( - $user, - GETPOST("id_entrepot_destination"), - GETPOST("nbpiece"), - 0, - GETPOST("label"), - $pricedest, - GETPOST('inventorycode') - ); - if ($result2 < 0) $error++; - } + $srcwarehouseid=GETPOST('id_entrepot','int'); + $batch=GETPOST('batch_number'); + $eatby=$d_eatby; + $sellby=$d_sellby; } + if (! $error) + { + // Remove stock + $result1=$object->correct_stock_batch( + $user, + $srcwarehouseid, + GETPOST("nbpiece",'int'), + 1, + GETPOST("label",'san_alpha'), + $pricesrc, + $eatby,$sellby,$batch, + GETPOST('inventorycode') + ); + if ($result1 < 0) $error++; + } + if (! $error) + { + // Add stock + $result2=$object->correct_stock_batch( + $user, + GETPOST("id_entrepot_destination",'int'), + GETPOST("nbpiece",'int'), + 0, + GETPOST("label",'san_alpha'), + $pricedest, + $eatby,$sellby,$batch, + GETPOST('inventorycode') + ); + if ($result2 < 0) $error++; + } } + else + { + if (! $error) + { + // Remove stock + $result1=$object->correct_stock( + $user, + GETPOST("id_entrepot"), + GETPOST("nbpiece"), + 1, + GETPOST("label"), + $pricesrc, + GETPOST('inventorycode') + ); + if ($result1 < 0) $error++; + } + if (! $error) + { + // Add stock + $result2=$object->correct_stock( + $user, + GETPOST("id_entrepot_destination"), + GETPOST("nbpiece"), + 0, + GETPOST("label"), + $pricedest, + GETPOST('inventorycode') + ); + if ($result2 < 0) $error++; + } + } + if (! $error && $result1 >= 0 && $result2 >= 0) { From 262dcbea2c0700ec8e8a8c2f3a8b0da6024945d7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fr=C3=A9d=C3=A9ric=20FRANCE?= Date: Tue, 7 Jun 2016 18:08:33 +0200 Subject: [PATCH 016/379] Update commonobject.class.php --- htdocs/core/class/commonobject.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index c26251f2312..b494dc2a030 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -2451,19 +2451,19 @@ abstract class CommonObject { if ($justsource) { - $sql.= "fk_source = '".$sourceid."' AND sourcetype = '".$sourcetype."'"; + $sql.= "fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."'"; if ($withtargettype) $sql.= " AND targettype = '".$targettype."'"; } else if ($justtarget) { - $sql.= "fk_target = '".$targetid."' AND targettype = '".$targettype."'"; + $sql.= "fk_target = ".$targetid." AND targettype = '".$targettype."'"; if ($withsourcetype) $sql.= " AND sourcetype = '".$sourcetype."'"; } } else { - $sql.= "(fk_source = '".$sourceid."' AND sourcetype = '".$sourcetype."')"; - $sql.= " ".$clause." (fk_target = '".$targetid."' AND targettype = '".$targettype."')"; + $sql.= "(fk_source = ".$sourceid." AND sourcetype = '".$sourcetype."')"; + $sql.= " ".$clause." (fk_target = ".$targetid." AND targettype = '".$targettype."')"; } $sql .= ' ORDER BY sourcetype'; //print $sql; From db0cf5f03f37cb0ebf9b48dd3c370a87caac4256 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Thu, 9 Jun 2016 18:48:36 +0200 Subject: [PATCH 017/379] remplace level feacture by hidden function --- htdocs/product/index.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/product/index.php b/htdocs/product/index.php index 2f15b98b562..cb061164e5d 100644 --- a/htdocs/product/index.php +++ b/htdocs/product/index.php @@ -2,7 +2,7 @@ /* Copyright (C) 2001-2006 Rodolphe Quiedeville * Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2014 Regis Houssin - * Copyright (C) 2014 Charles-Fr BENKE + * Copyright (C) 2014-2016 Charlie BENKE * Copyright (C) 2015 Jean-François Ferry * * This program is free software; you can redistribute it and/or modify @@ -347,7 +347,7 @@ else // TODO Move this into a page that should be available into menu "accountancy - report - turnover - per quarter" // Also method used for counting must provide the 2 possible methods like done by all other reports into menu "accountancy - report - turnover": // "commitment engagment" method and "cash accounting" method -if ($conf->global->MAIN_FEATURES_LEVEL) +if ($conf->global->MAIN_SHOW_PRODUCT_ACTIVITY_TRIM) { if (! empty($conf->product->enabled)) activitytrim(0); if (! empty($conf->service->enabled)) activitytrim(1); From e6dabb0422b146b87f7d4f9cdf36c8816bce985b Mon Sep 17 00:00:00 2001 From: gauthier Date: Fri, 10 Jun 2016 12:02:57 +0200 Subject: [PATCH 018/379] NEW : "dorade" expedition model with unit price ht and total ht --- .../expedition/doc/pdf_dorade.modules.php | 1023 +++++++++++++++++ htdocs/langs/fr_FR/sendings.lang | 1 + 2 files changed, 1024 insertions(+) create mode 100644 htdocs/core/modules/expedition/doc/pdf_dorade.modules.php diff --git a/htdocs/core/modules/expedition/doc/pdf_dorade.modules.php b/htdocs/core/modules/expedition/doc/pdf_dorade.modules.php new file mode 100644 index 00000000000..4c035bcef9e --- /dev/null +++ b/htdocs/core/modules/expedition/doc/pdf_dorade.modules.php @@ -0,0 +1,1023 @@ + + * Copyright (C) 2005-2012 Laurent Destailleur + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2014-2015 Marcos García + * + * 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 . + * or see http://www.gnu.org/ + */ + +/** + * \file htdocs/core/modules/expedition/doc/pdf_dorade.modules.php + * \ingroup expedition + * \brief Fichier de la classe permettant de generer les bordereaux envoi au modele Dorade + */ + +require_once DOL_DOCUMENT_ROOT.'/core/modules/expedition/modules_expedition.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; +require_once DOL_DOCUMENT_ROOT.'/core/lib/pdf.lib.php'; + + +/** + * Classe permettant de generer les borderaux envoi au modele Dorade + */ +class pdf_dorade extends ModelePdfExpedition +{ + var $emetteur; // Objet societe qui emet + + + /** + * Constructor + * + * @param DoliDB $db Database handler + */ + function __construct($db=0) + { + global $conf,$langs,$mysoc; + + $this->db = $db; + $this->name = "dorade"; + $this->description = $langs->trans("DocumentModelDorade"); + + $this->type = 'pdf'; + $formatarray=pdf_getFormat(); + $this->page_largeur = $formatarray['width']; + $this->page_hauteur = $formatarray['height']; + $this->format = array($this->page_largeur,$this->page_hauteur); + $this->marge_gauche=isset($conf->global->MAIN_PDF_MARGIN_LEFT)?$conf->global->MAIN_PDF_MARGIN_LEFT:10; + $this->marge_droite=isset($conf->global->MAIN_PDF_MARGIN_RIGHT)?$conf->global->MAIN_PDF_MARGIN_RIGHT:10; + $this->marge_haute =isset($conf->global->MAIN_PDF_MARGIN_TOP)?$conf->global->MAIN_PDF_MARGIN_TOP:10; + $this->marge_basse =isset($conf->global->MAIN_PDF_MARGIN_BOTTOM)?$conf->global->MAIN_PDF_MARGIN_BOTTOM:10; + + $this->option_logo = 1; + + // Recupere emmetteur + $this->emetteur=$mysoc; + if (! $this->emetteur->country_code) $this->emetteur->country_code=substr($langs->defaultlang,-2); // By default if not defined + + // Defini position des colonnes + $this->posxdesc=$this->marge_gauche+1; + $this->posxweightvol=$this->page_largeur - $this->marge_droite - 130; + $this->posxqtyordered=$this->page_largeur - $this->marge_droite - 100; + $this->posxqtytoship=$this->page_largeur - $this->marge_droite - 70; + $this->posxpuht=$this->page_largeur - $this->marge_droite - 40; + $this->posxtotalht=$this->page_largeur - $this->marge_droite - 20; + $this->posxpicture=$this->posxweightvol - (empty($conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH)?20:$conf->global->MAIN_DOCUMENTS_WITH_PICTURE_WIDTH); // width of images + + if ($this->page_largeur < 210) // To work with US executive format + { + $this->posxweightvol-=20; + $this->posxpicture-=20; + $this->posxqtyordered-=20; + $this->posxqtytoship-=20; + } + + if (! empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)) + { + $this->posxweightvol += ($this->posxqtytoship - $this->posxqtyordered); + $this->posxpicture += ($this->posxqtytoship - $this->posxqtyordered); + $this->posxqtyordered = $this->posxqtytoship; + } + } + + /** + * Function to build pdf onto disk + * + * @param Object $object Object expedition to generate (or id if old method) + * @param Translate $outputlangs Lang output object + * @param string $srctemplatepath Full path of source filename for generator using a template file + * @param int $hidedetails Do not show line details + * @param int $hidedesc Do not show desc + * @param int $hideref Do not show ref + * @return int 1=OK, 0=KO + */ + function write_file(&$object,$outputlangs,$srctemplatepath='',$hidedetails=0,$hidedesc=0,$hideref=0) + { + global $user,$conf,$langs,$hookmanager; + + $object->fetch_thirdparty(); + + if (! is_object($outputlangs)) $outputlangs=$langs; + // For backward compatibility with FPDF, force output charset to ISO, because FPDF expect text to be encoded in ISO + if (! empty($conf->global->MAIN_USE_FPDF)) $outputlangs->charset_output='ISO-8859-1'; + + $outputlangs->load("main"); + $outputlangs->load("dict"); + $outputlangs->load("companies"); + $outputlangs->load("bills"); + $outputlangs->load("products"); + $outputlangs->load("propal"); + $outputlangs->load("deliveries"); + $outputlangs->load("sendings"); + $outputlangs->load("productbatch"); + + $nblignes = count($object->lines); + + // Loop on each lines to detect if there is at least one image to show + $realpatharray=array(); + if (! empty($conf->global->MAIN_GENERATE_SHIPMENT_WITH_PICTURE)) + { + $objphoto = new Product($this->db); + + for ($i = 0 ; $i < $nblignes ; $i++) + { + if (empty($object->lines[$i]->fk_product)) continue; + + $objphoto = new Product($this->db); + $objphoto->fetch($object->lines[$i]->fk_product); + + $pdir = get_exdir($object->lines[$i]->fk_product,2,0,0,$objphoto,'product') . $object->lines[$i]->fk_product ."/photos/"; + $dir = $conf->product->dir_output.'/'.$pdir; + + $realpath=''; + + foreach ($objphoto->liste_photos($dir,1) as $key => $obj) + { + if (empty($conf->global->CAT_HIGH_QUALITY_IMAGES)) // If CAT_HIGH_QUALITY_IMAGES not defined, we use thumb if defined and then original photo + { + if ($obj['photo_vignette']) + { + $filename= $obj['photo_vignette']; + } + else + { + $filename=$obj['photo']; + } + } + else + { + $filename=$obj['photo']; + } + + $realpath = $dir.$filename; + break; + } + + if ($realpath) $realpatharray[$i]=$realpath; + } + } + + if (count($realpatharray) == 0) $this->posxpicture=$this->posxweightvol; + + if ($conf->expedition->dir_output) + { + // Definition de $dir et $file + if ($object->specimen) + { + $dir = $conf->expedition->dir_output."/sending"; + $file = $dir . "/SPECIMEN.pdf"; + } + else + { + $expref = dol_sanitizeFileName($object->ref); + $dir = $conf->expedition->dir_output."/sending/" . $expref; + $file = $dir . "/" . $expref . ".pdf"; + } + + if (! file_exists($dir)) + { + if (dol_mkdir($dir) < 0) + { + $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); + return 0; + } + } + + if (file_exists($dir)) + { + // Add pdfgeneration hook + if (! is_object($hookmanager)) + { + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager=new HookManager($this->db); + } + $hookmanager->initHooks(array('pdfgeneration')); + $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); + global $action; + $reshook=$hookmanager->executeHooks('beforePDFCreation',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks + + // Set nblignes with the new facture lines content after hook + $nblignes = count($object->lines); + + $pdf=pdf_getInstance($this->format); + $default_font_size = pdf_getPDFFontSize($outputlangs); + $heightforinfotot = 8; // Height reserved to output the info and total part + $heightforfreetext= (isset($conf->global->MAIN_PDF_FREETEXT_HEIGHT)?$conf->global->MAIN_PDF_FREETEXT_HEIGHT:5); // Height reserved to output the free text on last page + $heightforfooter = $this->marge_basse + 8; // Height reserved to output the footer (value include bottom margin) + $pdf->SetAutoPageBreak(1,0); + + if (class_exists('TCPDF')) + { + $pdf->setPrintHeader(false); + $pdf->setPrintFooter(false); + } + $pdf->SetFont(pdf_getPDFFont($outputlangs)); + // Set path to the background PDF File + if (empty($conf->global->MAIN_DISABLE_FPDI) && ! empty($conf->global->MAIN_ADD_PDF_BACKGROUND)) + { + $pagecount = $pdf->setSourceFile($conf->mycompany->dir_output.'/'.$conf->global->MAIN_ADD_PDF_BACKGROUND); + $tplidx = $pdf->importPage(1); + } + + $pdf->Open(); + $pagenb=0; + $pdf->SetDrawColor(128,128,128); + + if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages(); + + $pdf->SetTitle($outputlangs->convToOutputCharset($object->ref)); + $pdf->SetSubject($outputlangs->transnoentities("Shipment")); + $pdf->SetCreator("Dolibarr ".DOL_VERSION); + $pdf->SetAuthor($outputlangs->convToOutputCharset($user->getFullName($outputlangs))); + $pdf->SetKeyWords($outputlangs->convToOutputCharset($object->ref)." ".$outputlangs->transnoentities("Shipment")); + if (! empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(false); + + $pdf->SetMargins($this->marge_gauche, $this->marge_haute, $this->marge_droite); // Left, Top, Right + + // New page + $pdf->AddPage(); + if (! empty($tplidx)) $pdf->useTemplate($tplidx); + $pagenb++; + $this->_pagehead($pdf, $object, 1, $outputlangs); + $pdf->SetFont('','', $default_font_size - 1); + $pdf->MultiCell(0, 3, ''); // Set interline to 3 + $pdf->SetTextColor(0,0,0); + + $tab_top = 90; + $tab_top_newpage = (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)?42:10); + $tab_height = 130; + $tab_height_newpage = 150; + + // Incoterm + $height_incoterms = 0; + if ($conf->incoterm->enabled) + { + $desc_incoterms = $object->getIncotermsForPDF(); + if ($desc_incoterms) + { + $tab_top = 88; + + $pdf->SetFont('','', $default_font_size - 1); + $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top-1, dol_htmlentitiesbr($desc_incoterms), 0, 1); + $nexY = $pdf->GetY(); + $height_incoterms=$nexY-$tab_top; + + // Rect prend une longueur en 3eme param + $pdf->SetDrawColor(192,192,192); + $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_incoterms+1); + + $tab_top = $nexY+6; + $height_incoterms += 4; + } + } + + if (! empty($object->note_public) || ! empty($object->tracking_number)) + { + $tab_top = 88 + $height_incoterms; + $tab_top_alt = $tab_top; + + $pdf->SetFont('','B', $default_font_size - 2); + $pdf->writeHTMLCell(60, 4, $this->posxdesc-1, $tab_top-1, $outputlangs->transnoentities("TrackingNumber")." : " . $object->tracking_number, 0, 1, false, true, 'L'); + + $tab_top_alt = $pdf->GetY(); + //$tab_top_alt += 1; + + // Tracking number + if (! empty($object->tracking_number)) + { + $object->GetUrlTrackingStatus($object->tracking_number); + if (! empty($object->tracking_url)) + { + if ($object->shipping_method_id > 0) + { + // Get code using getLabelFromKey + $code=$outputlangs->getLabelFromKey($this->db,$object->shipping_method_id,'c_shipment_mode','rowid','code'); + $label=''; + if ($object->tracking_url != $object->tracking_number) $label.=$outputlangs->trans("LinkToTrackYourPackage")."
"; + $label.=$outputlangs->trans("SendingMethod").": ".$outputlangs->trans("SendingMethod".strtoupper($code)); + //var_dump($object->tracking_url != $object->tracking_number);exit; + if ($object->tracking_url != $object->tracking_number) + { + $label.=" : "; + $label.=$object->tracking_url; + } + $pdf->SetFont('','B', $default_font_size - 2); + $pdf->writeHTMLCell(60, 4, $this->posxdesc-1, $tab_top_alt, $label, 0, 1, false, true, 'L'); + + $tab_top_alt = $pdf->GetY(); + } + } + } + + // Notes + if (! empty($object->note_public)) + { + $pdf->SetFont('','', $default_font_size - 1); // Dans boucle pour gerer multi-page + $pdf->writeHTMLCell(190, 3, $this->posxdesc-1, $tab_top_alt, dol_htmlentitiesbr($object->note_public), 0, 1); + } + + $nexY = $pdf->GetY(); + $height_note=$nexY-$tab_top; + + // Rect prend une longueur en 3eme param + $pdf->SetDrawColor(192,192,192); + $pdf->Rect($this->marge_gauche, $tab_top-1, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $height_note+1); + + $tab_height = $tab_height - $height_note; + $tab_top = $nexY+6; + } + else + { + $height_note=0; + } + + $iniY = $tab_top + 7; + $curY = $tab_top + 7; + $nexY = $tab_top + 7; + + $num=count($object->lines); + // Loop on each lines + for ($i = 0; $i < $nblignes; $i++) + { + $curY = $nexY; + $pdf->SetFont('','', $default_font_size - 1); // Into loop to work with multipage + $pdf->SetTextColor(0,0,0); + + // Define size of image if we need it + $imglinesize=array(); + if (! empty($realpatharray[$i])) $imglinesize=pdf_getSizeForImage($realpatharray[$i]); + + $pdf->setTopMargin($tab_top_newpage); + $pdf->setPageOrientation('', 1, $heightforfooter+$heightforfreetext+$heightforinfotot); // The only function to edit the bottom margin of current page to set it. + $pageposbefore=$pdf->getPage(); + + $showpricebeforepagebreak=1; + $posYAfterImage=0; + $posYAfterDescription=0; + + // We start with Photo of product line + if (isset($imglinesize['width']) && isset($imglinesize['height']) && ($curY + $imglinesize['height']) > ($this->page_hauteur-($heightforfooter+$heightforfreetext+$heightforinfotot))) // If photo too high, we moved completely on new page + { + $pdf->AddPage('','',true); + if (! empty($tplidx)) $pdf->useTemplate($tplidx); + if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); + $pdf->setPage($pageposbefore+1); + + $curY = $tab_top_newpage; + $showpricebeforepagebreak=0; + } + + if (isset($imglinesize['width']) && isset($imglinesize['height'])) + { + $curX = $this->posxpicture-1; + $pdf->Image($realpatharray[$i], $curX + (($this->posxweightvol-$this->posxpicture-$imglinesize['width'])/2), $curY, $imglinesize['width'], $imglinesize['height'], '', '', '', 2, 300); // Use 300 dpi + // $pdf->Image does not increase value return by getY, so we save it manually + $posYAfterImage=$curY+$imglinesize['height']; + } + + // Description of product line + $curX = $this->posxdesc-1; + + $pdf->startTransaction(); + pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc); + + $pageposafter=$pdf->getPage(); + if ($pageposafter > $pageposbefore) // There is a pagebreak + { + $pdf->rollbackTransaction(true); + $pageposafter=$pageposbefore; + //print $pageposafter.'-'.$pageposbefore;exit; + $pdf->setPageOrientation('', 1, $heightforfooter); // The only function to edit the bottom margin of current page to set it. + pdf_writelinedesc($pdf,$object,$i,$outputlangs,$this->posxpicture-$curX,3,$curX,$curY,$hideref,$hidedesc); + + $pageposafter=$pdf->getPage(); + $posyafter=$pdf->GetY(); + //var_dump($posyafter); var_dump(($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))); exit; + if ($posyafter > ($this->page_hauteur - ($heightforfooter+$heightforfreetext+$heightforinfotot))) // There is no space left for total+free text + { + if ($i == ($nblignes-1)) // No more lines, and no space left to show total, so we create a new page + { + $pdf->AddPage('','',true); + if (! empty($tplidx)) $pdf->useTemplate($tplidx); + if (empty($conf->global->MAIN_PDF_DONOTREPEAT_HEAD)) $this->_pagehead($pdf, $object, 0, $outputlangs); + $pdf->setPage($pageposafter+1); + } + } + else + { + // We found a page break + $showpricebeforepagebreak=0; + } + } + else // No pagebreak + { + $pdf->commitTransaction(); + } + $posYAfterDescription=$pdf->GetY(); + + $nexY = $pdf->GetY(); + $pageposafter=$pdf->getPage(); + + $pdf->setPage($pageposbefore); + $pdf->setTopMargin($this->marge_haute); + $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. + + // We suppose that a too long description or photo were moved completely on next page + if ($pageposafter > $pageposbefore && empty($showpricebeforepagebreak)) { + $pdf->setPage($pageposafter); $curY = $tab_top_newpage; + } + + // We suppose that a too long description is moved completely on next page + if ($pageposafter > $pageposbefore) { + $pdf->setPage($pageposafter); $curY = $tab_top_newpage; + } + + $pdf->SetFont('','', $default_font_size - 1); // On repositionne la police par defaut + + $pdf->SetXY($this->posxweightvol, $curY); + $weighttxt=''; + if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->weight) + { + $weighttxt=$object->lines[$i]->weight*$object->lines[$i]->qty_shipped.' '.measuring_units_string($object->lines[$i]->weight_units,"weight"); + } + $voltxt=''; + if ($object->lines[$i]->fk_product_type == 0 && $object->lines[$i]->volume) + { + $voltxt=$object->lines[$i]->volume*$object->lines[$i]->qty_shipped.' '.measuring_units_string($object->lines[$i]->volume_units?$object->lines[$i]->volume_units:0,"volume"); + } + + $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 3, $weighttxt.(($weighttxt && $voltxt)?', ':'').$voltxt,'','C'); + + if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)) + { + $pdf->SetXY($this->posxqtyordered, $curY); + $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 3, $object->lines[$i]->qty_asked,'','C'); + } + + $pdf->SetXY($this->posxqtytoship, $curY); + $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 3, $object->lines[$i]->qty_shipped,'','C'); + + $pdf->SetXY($this->posxpuht, $curY); + $pdf->MultiCell(($this->posxtotalht - $this->posxpuht-1), 3, price($object->lines[$i]->subprice, 0, $outputlangs),'','R'); + + $pdf->SetXY($this->posxtotalht, $curY); + $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 3, price($object->lines[$i]->total_ht, 0, $outputlangs),'','R'); + + // Add line + if ($conf->global->MAIN_PDF_DASH_BETWEEN_LINES && $i < ($nblignes - 1)) + { + $pdf->setPage($pageposafter); + $pdf->SetLineStyle(array('dash'=>'1,1','color'=>array(80,80,80))); + //$pdf->SetDrawColor(190,190,200); + $pdf->line($this->marge_gauche, $nexY+1, $this->page_largeur - $this->marge_droite, $nexY+1); + $pdf->SetLineStyle(array('dash'=>0)); + } + + $nexY+=2; // Passe espace entre les lignes + + // Detect if some page were added automatically and output _tableau for past pages + while ($pagenb < $pageposafter) + { + $pdf->setPage($pagenb); + if ($pagenb == 1) + { + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); + } + else + { + $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); + } + $this->_pagefoot($pdf,$object,$outputlangs,1); + $pagenb++; + $pdf->setPage($pagenb); + $pdf->setPageOrientation('', 1, 0); // The only function to edit the bottom margin of current page to set it. + } + if (isset($object->lines[$i+1]->pagebreak) && $object->lines[$i+1]->pagebreak) + { + if ($pagenb == 1) + { + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforfooter, 0, $outputlangs, 0, 1); + } + else + { + $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforfooter, 0, $outputlangs, 1, 1); + } + $this->_pagefoot($pdf,$object,$outputlangs,1); + // New page + $pdf->AddPage(); + if (! empty($tplidx)) $pdf->useTemplate($tplidx); + $pagenb++; + } + } + + // Show square + if ($pagenb == 1) + { + $this->_tableau($pdf, $tab_top, $this->page_hauteur - $tab_top - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 0, 0); + $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; + } + else + { + $this->_tableau($pdf, $tab_top_newpage, $this->page_hauteur - $tab_top_newpage - $heightforinfotot - $heightforfreetext - $heightforfooter, 0, $outputlangs, 1, 0); + $bottomlasttab=$this->page_hauteur - $heightforinfotot - $heightforfreetext - $heightforfooter + 1; + } + + // Affiche zone totaux + $posy=$this->_tableau_tot($pdf, $object, $deja_regle, $bottomlasttab, $outputlangs); + + // Pied de page + $this->_pagefoot($pdf,$object,$outputlangs); + if (method_exists($pdf,'AliasNbPages')) $pdf->AliasNbPages(); + + $pdf->Close(); + + $pdf->Output($file,'F'); + + // Add pdfgeneration hook + if (! is_object($hookmanager)) + { + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager=new HookManager($this->db); + } + $hookmanager->initHooks(array('pdfgeneration')); + $parameters=array('file'=>$file,'object'=>$object,'outputlangs'=>$outputlangs); + global $action; + $reshook=$hookmanager->executeHooks('afterPDFCreation',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + + if (! empty($conf->global->MAIN_UMASK)) + @chmod($file, octdec($conf->global->MAIN_UMASK)); + + return 1; // No error + } + else + { + $this->error=$langs->transnoentities("ErrorCanNotCreateDir",$dir); + return 0; + } + } + else + { + $this->error=$langs->transnoentities("ErrorConstantNotDefined","EXP_OUTPUTDIR"); + return 0; + } + $this->error=$langs->transnoentities("ErrorUnknown"); + return 0; // Erreur par defaut + } + + /** + * Show total to pay + * + * @param PDF $pdf Object PDF + * @param Facture $object Object invoice + * @param int $deja_regle Montant deja regle + * @param int $posy Position depart + * @param Translate $outputlangs Objet langs + * @return int Position pour suite + */ + function _tableau_tot(&$pdf, $object, $deja_regle, $posy, $outputlangs) + { + global $conf,$mysoc; + + $sign=1; + + $default_font_size = pdf_getPDFFontSize($outputlangs); + + $tab2_top = $posy; + $tab2_hl = 4; + $pdf->SetFont('','B', $default_font_size - 1); + + // Tableau total + $col1x = $this->posxweightvol-50; $col2x = $this->posxweightvol; + /*if ($this->page_largeur < 210) // To work with US executive format + { + $col2x-=20; + }*/ + if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)) $largcol2 = ($this->posxqtyordered - $this->posxweightvol); + else $largcol2 = ($this->posxqtytoship - $this->posxweightvol); + + $useborder=0; + $index = 0; + + $totalWeighttoshow=''; + $totalVolumetoshow=''; + + // Load dim data + $tmparray=$object->getTotalWeightVolume(); + $totalWeight=$tmparray['weight']; + $totalVolume=$tmparray['volume']; + $totalOrdered=$tmparray['ordered']; + $totalToShip=$tmparray['toship']; + // Set trueVolume and volume_units not currently stored into database + if ($object->trueWidth && $object->trueHeight && $object->trueDepth) + { + $object->trueVolume=price(($object->trueWidth * $object->trueHeight * $object->trueDepth), 0, $outputlangs, 0, 0); + $object->volume_units=$object->size_units * 3; + } + + if ($totalWeight!='') $totalWeighttoshow=showDimensionInBestUnit($totalWeight, 0, "weight", $outputlangs); + if ($totalVolume!='') $totalVolumetoshow=showDimensionInBestUnit($totalVolume, 0, "volume", $outputlangs); + if ($object->trueWeight) $totalWeighttoshow=showDimensionInBestUnit($object->trueWeight, $object->weight_units, "weight", $outputlangs); + if ($object->trueVolume) $totalVolumetoshow=showDimensionInBestUnit($object->trueVolume, $object->volume_units, "volume", $outputlangs); + + $pdf->SetFillColor(255,255,255); + $pdf->SetXY($col1x, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($col2x-$col1x, $tab2_hl, $outputlangs->transnoentities("Total"), 0, 'L', 1); + + if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)) + { + $pdf->SetXY($this->posxqtyordered, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($this->posxqtytoship - $this->posxqtyordered, $tab2_hl, $totalOrdered, 0, 'C', 1); + } + + //var_dump($object);exit; + + $pdf->SetXY($this->posxqtytoship, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($this->posxpuht - $this->posxqtytoship, $tab2_hl, $totalToShip, 0, 'C', 1); + + $pdf->SetXY($this->posxpuht, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($this->posxtotalht - $this->posxpuht, $tab2_hl, '', 0, 'C', 1); + + $pdf->SetXY($this->posxtotalht, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($this->largeur_page - $this->marge_droite - $this->posxtotalht, $tab2_hl, price($object->total_ht, 0, $outputlangs), 0, 'C', 1); + + // Total Weight + if ($totalWeighttoshow) + { + $pdf->SetXY($col2x-20, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($largcol2+20, $tab2_hl, $totalWeighttoshow, 0, 'R', 1); + + $index++; + } + if ($totalVolumetoshow) + { + $pdf->SetXY($col2x-20, $tab2_top + $tab2_hl * $index); + $pdf->MultiCell($largcol2+20, $tab2_hl, $totalVolumetoshow, 0, 'R', 1); + + $index++; + } + if (! $totalWeighttoshow && ! $totalVolumetoshow) $index++; + + $pdf->SetTextColor(0,0,0); + + return ($tab2_top + ($tab2_hl * $index)); + } + + /** + * Show table for lines + * + * @param PDF $pdf Object PDF + * @param string $tab_top Top position of table + * @param string $tab_height Height of table (rectangle) + * @param int $nexY Y + * @param Translate $outputlangs Langs object + * @param int $hidetop Hide top bar of array + * @param int $hidebottom Hide bottom bar of array + * @return void + */ + function _tableau(&$pdf, $tab_top, $tab_height, $nexY, $outputlangs, $hidetop=0, $hidebottom=0) + { + global $conf; + + // Force to disable hidetop and hidebottom + $hidebottom=0; + if ($hidetop) $hidetop=-1; + + $default_font_size = pdf_getPDFFontSize($outputlangs); + + // Amount in (at tab_top - 1) + $pdf->SetTextColor(0,0,0); + $pdf->SetFont('','',$default_font_size - 2); + + // Output Rect + $this->printRect($pdf,$this->marge_gauche, $tab_top, $this->page_largeur-$this->marge_gauche-$this->marge_droite, $tab_height, $hidetop, $hidebottom); // Rect prend une longueur en 3eme param et 4eme param + + $pdf->SetDrawColor(128,128,128); + $pdf->SetFont('','', $default_font_size - 1); + + if (empty($hidetop)) + { + $pdf->line($this->marge_gauche, $tab_top+5, $this->page_largeur-$this->marge_droite, $tab_top+5); + + $pdf->SetXY($this->posxdesc-1, $tab_top+1); + $pdf->MultiCell($this->posxqtyordered - $this->posxdesc, 2, $outputlangs->transnoentities("Description"), '', 'L'); + } + + $pdf->line($this->posxweightvol-1, $tab_top, $this->posxweightvol-1, $tab_top + $tab_height); + if (empty($hidetop)) + { + $pdf->SetXY($this->posxweightvol-1, $tab_top+1); + $pdf->MultiCell(($this->posxqtyordered - $this->posxweightvol), 2, $outputlangs->transnoentities("WeightVolShort"),'','C'); + } + + if (empty($conf->global->SHIPPING_PDF_HIDE_ORDERED)) + { + $pdf->line($this->posxqtyordered-1, $tab_top, $this->posxqtyordered-1, $tab_top + $tab_height); + if (empty($hidetop)) + { + $pdf->SetXY($this->posxqtyordered, $tab_top+1); + $pdf->MultiCell(($this->posxqtytoship - $this->posxqtyordered), 2, $outputlangs->transnoentities("QtyOrdered"),'','C'); + } + } + + $pdf->line($this->posxqtytoship-1, $tab_top, $this->posxqtytoship-1, $tab_top + $tab_height); + if (empty($hidetop)) + { + $pdf->SetXY($this->posxqtytoship, $tab_top+1); + $pdf->MultiCell(($this->posxpuht - $this->posxqtytoship), 2, $outputlangs->transnoentities("QtyToShip"),'','C'); + } + + $pdf->line($this->posxpuht-1, $tab_top, $this->posxpuht-1, $tab_top + $tab_height); + if (empty($hidetop)) + { + $pdf->SetXY($this->posxpuht-1, $tab_top+1); + $pdf->MultiCell(($this->posxtotalht - $this->posxpuht), 2, $outputlangs->transnoentities("PriceUHT"),'','C'); + } + + $pdf->line($this->posxtotalht-1, $tab_top, $this->posxtotalht-1, $tab_top + $tab_height); + if (empty($hidetop)) + { + $pdf->SetXY($this->posxtotalht-1, $tab_top+1); + $pdf->MultiCell(($this->page_largeur - $this->marge_droite - $this->posxtotalht), 2, $outputlangs->transnoentities("TotalHT"),'','C'); + } + + } + + /** + * Show top header of page. + * + * @param PDF $pdf Object PDF + * @param Object $object Object to show + * @param int $showaddress 0=no, 1=yes + * @param Translate $outputlangs Object lang for output + * @return void + */ + function _pagehead(&$pdf, $object, $showaddress, $outputlangs) + { + global $conf,$langs,$mysoc; + $default_font_size = pdf_getPDFFontSize($outputlangs); + $langs->load("orders"); + + pdf_pagehead($pdf,$outputlangs,$this->page_hauteur); + + // Show Draft Watermark + if($object->statut==0 && (! empty($conf->global->SHIPPING_DRAFT_WATERMARK)) ) + { + pdf_watermark($pdf,$outputlangs,$this->page_hauteur,$this->page_largeur,'mm',$conf->global->SHIPPING_DRAFT_WATERMARK); + } + + //Prepare la suite + $pdf->SetTextColor(0,0,60); + $pdf->SetFont('','B', $default_font_size + 3); + + $w = 110; + $posx=$this->page_largeur-$this->marge_droite-100; + $posy=$this->marge_haute; + + $pdf->SetXY($this->marge_gauche,$posy); + + // Logo + $logo=$conf->mycompany->dir_output.'/logos/'.$this->emetteur->logo; + if ($this->emetteur->logo) + { + if (is_readable($logo)) + { + $height=pdf_getHeightForLogo($logo); + $pdf->Image($logo, $this->marge_gauche, $posy, 0, $height); // width=0 (auto) + } + else + { + $pdf->SetTextColor(200,0,0); + $pdf->SetFont('','B', $default_font_size - 2); + $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorLogoFileNotFound",$logo), 0, 'L'); + $pdf->MultiCell($w, 3, $outputlangs->transnoentities("ErrorGoToGlobalSetup"), 0, 'L'); + } + } + else + { + $text=$this->emetteur->name; + $pdf->MultiCell($w, 4, $outputlangs->convToOutputCharset($text), 0, 'L'); + } + + // Show barcode + if (! empty($conf->barcode->enabled)) + { + $posx=105; + } + else + { + $posx=$this->marge_gauche+3; + } + //$pdf->Rect($this->marge_gauche, $this->marge_haute, $this->page_largeur-$this->marge_gauche-$this->marge_droite, 30); + if (! empty($conf->barcode->enabled)) + { + // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref + //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3); + //$pdf->Image($logo,10, 5, 0, 24); + } + + $pdf->SetDrawColor(128,128,128); + if (! empty($conf->barcode->enabled)) + { + // TODO Build code bar with function writeBarCode of barcode module for sending ref $object->ref + //$pdf->SetXY($this->marge_gauche+3, $this->marge_haute+3); + //$pdf->Image($logo,10, 5, 0, 24); + } + + + $posx=$this->page_largeur - $w - $this->marge_droite; + $posy=$this->marge_haute; + + $pdf->SetFont('','B', $default_font_size + 2); + $pdf->SetXY($posx,$posy); + $pdf->SetTextColor(0,0,60); + $title=$outputlangs->transnoentities("SendingSheet"); + $pdf->MultiCell($w, 4, $title, '', 'R'); + $posy+=1; + + $pdf->SetFont('','', $default_font_size + 1); + + $posy+=4; + $pdf->SetXY($posx,$posy); + $pdf->SetTextColor(0,0,60); + $pdf->MultiCell($w, 4, $outputlangs->transnoentities("RefSending") ." : ".$object->ref, '', 'R'); + + // Date planned delivery + if (! empty($object->date_delivery)) + { + $posy+=4; + $pdf->SetXY($posx,$posy); + $pdf->SetTextColor(0,0,60); + $pdf->MultiCell($w, 4, $outputlangs->transnoentities("DateDeliveryPlanned")." : ".dol_print_date($object->date_delivery,"day",false,$outputlangs,true), '', 'R'); + } + + if (! empty($object->thirdparty->code_client)) + { + $posy+=4; + $pdf->SetXY($posx,$posy); + $pdf->SetTextColor(0,0,60); + $pdf->MultiCell($w, 3, $outputlangs->transnoentities("CustomerCode")." : " . $outputlangs->transnoentities($object->thirdparty->code_client), '', 'R'); + } + + + $pdf->SetFont('','', $default_font_size + 3); + $Yoff=25; + + // Add list of linked orders + // TODO possibility to use with other document (business module,...) + //$object->load_object_linked(); + + $origin = $object->origin; + $origin_id = $object->origin_id; + + // TODO move to external function + if (! empty($conf->$origin->enabled)) + { + $outputlangs->load('orders'); + + $classname = ucfirst($origin); + $linkedobject = new $classname($this->db); + $result=$linkedobject->fetch($origin_id); + if ($result >= 0) + { + $pdf->SetFont('','', $default_font_size - 2); + $text=$linkedobject->ref; + if ($linkedobject->ref_client) $text.=' ('.$linkedobject->ref_client.')'; + $Yoff = $Yoff+8; + $pdf->SetXY($this->page_largeur - $this->marge_droite - $w,$Yoff); + $pdf->MultiCell($w, 2, $outputlangs->transnoentities("RefOrder") ." : ".$outputlangs->transnoentities($text), 0, 'R'); + $Yoff = $Yoff+3; + $pdf->SetXY($this->page_largeur - $this->marge_droite - $w,$Yoff); + $pdf->MultiCell($w, 2, $outputlangs->transnoentities("OrderDate")." : ".dol_print_date($linkedobject->date,"day",false,$outputlangs,true), 0, 'R'); + } + } + + if ($showaddress) + { + // Sender properties + $carac_emetteur=''; + // Add internal contact of origin element if defined + $arrayidcontact=array(); + if (! empty($origin) && is_object($object->$origin)) $arrayidcontact=$object->$origin->getIdContact('internal','SALESREPFOLL'); + if (count($arrayidcontact) > 0) + { + $object->fetch_user(reset($arrayidcontact)); + $carac_emetteur .= ($carac_emetteur ? "\n" : '' ).$outputlangs->transnoentities("Name").": ".$outputlangs->convToOutputCharset($object->user->getFullName($outputlangs))."\n"; + } + + $carac_emetteur .= pdf_build_address($outputlangs, $this->emetteur, $object->thirdparty); + + // Show sender + $posx=$this->marge_gauche; + $posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42; + $hautcadre=40; + if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->page_largeur-$this->marge_droite-80; + + $hautcadre=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 38 : 40; + $widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 82; + + // Show sender frame + $pdf->SetTextColor(0,0,0); + $pdf->SetFont('','', $default_font_size - 2); + $pdf->SetXY($posx,$posy-5); + $pdf->MultiCell(66,5, $outputlangs->transnoentities("Sender").":", 0, 'L'); + $pdf->SetXY($posx,$posy); + $pdf->SetFillColor(230,230,230); + $pdf->MultiCell($widthrecbox, $hautcadre, "", 0, 'R', 1); + $pdf->SetTextColor(0,0,60); + + // Show sender name + $pdf->SetXY($posx+2,$posy+3); + $pdf->SetTextColor(0,0,60); + $pdf->SetFont('','B',$default_font_size); + $pdf->MultiCell($widthrecbox-2, 4, $outputlangs->convToOutputCharset($this->emetteur->name), 0, 'L'); + $posy=$pdf->getY(); + + // Show sender information + $pdf->SetFont('','', $default_font_size - 1); + $pdf->SetXY($posx+2,$posy); + $pdf->SetFont('','', $default_font_size - 1); + $pdf->MultiCell($widthrecbox-2, 4, $carac_emetteur, 0, 'L'); + + + // If SHIPPING contact defined, we use it + $usecontact=false; + $arrayidcontact=$object->$origin->getIdContact('external','SHIPPING'); + if (count($arrayidcontact) > 0) + { + $usecontact=true; + $result=$object->fetch_contact($arrayidcontact[0]); + } + + //Recipient name + // On peut utiliser le nom de la societe du contact + if ($usecontact && !empty($conf->global->MAIN_USE_COMPANY_NAME_OF_CONTACT)) { + $thirdparty = $object->contact; + } else { + $thirdparty = $object->thirdparty; + } + + $carac_client_name= pdfBuildThirdpartyName($thirdparty, $outputlangs); + + $carac_client=pdf_build_address($outputlangs,$this->emetteur,$object->thirdparty,(!empty($object->contact)?$object->contact:null),$usecontact,'targetwithdetails',$object); + + // Show recipient + $widthrecbox=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 92 : 100; + if ($this->page_largeur < 210) $widthrecbox=84; // To work with US executive format + $posy=!empty($conf->global->MAIN_PDF_USE_ISO_LOCATION) ? 40 : 42; + $posx=$this->page_largeur - $this->marge_droite - $widthrecbox; + if (! empty($conf->global->MAIN_INVERT_SENDER_RECIPIENT)) $posx=$this->marge_gauche; + + // Show recipient frame + $pdf->SetTextColor(0,0,0); + $pdf->SetFont('','', $default_font_size - 2); + $pdf->SetXY($posx+2,$posy-5); + $pdf->MultiCell($widthrecbox, 5, $outputlangs->transnoentities("Recipient").":", 0, 'L'); + $pdf->Rect($posx, $posy, $widthrecbox, $hautcadre); + $pdf->SetTextColor(0,0,0); + + // Show recipient name + $pdf->SetXY($posx+2,$posy+3); + $pdf->SetFont('','B', $default_font_size); + $pdf->MultiCell($widthrecbox, 2, $carac_client_name, 0, 'L'); + + $posy = $pdf->getY(); + + // Show recipient information + $pdf->SetFont('','', $default_font_size - 1); + $pdf->SetXY($posx+2,$posy); + $pdf->MultiCell($widthrecbox, 4, $carac_client, 0, 'L'); + } + + $pdf->SetTextColor(0,0,0); + } + + /** + * Show footer of page. Need this->emetteur object + * + * @param PDF $pdf PDF + * @param Object $object Object to show + * @param Translate $outputlangs Object lang for output + * @param int $hidefreetext 1=Hide free text + * @return int Return height of bottom margin including footer text + */ + function _pagefoot(&$pdf,$object,$outputlangs,$hidefreetext=0) + { + global $conf; + $showdetails=$conf->global->MAIN_GENERATE_DOCUMENTS_SHOW_FOOT_DETAILS; + return pdf_pagefoot($pdf,$outputlangs,'SHIPPING_FREE_TEXT',$this->emetteur,$this->marge_basse,$this->marge_gauche,$this->page_hauteur,$object,$showdetails,$hidefreetext); + } + +} + diff --git a/htdocs/langs/fr_FR/sendings.lang b/htdocs/langs/fr_FR/sendings.lang index ee6ee57b453..9662b94ee25 100644 --- a/htdocs/langs/fr_FR/sendings.lang +++ b/htdocs/langs/fr_FR/sendings.lang @@ -51,6 +51,7 @@ GenericTransport=Transporteur générique Enlevement=Enlèvement sur place par le client DocumentModelSimple=Modèle simple DocumentModelMerou=Modèle Merou A5 +DocumentModelDorade=Modèle d'expédition chiffré WarningNoQtyLeftToSend=Alerte, aucun produit en attente d'expédition. StatsOnShipmentsOnlyValidated=Statistiques effectuées sur les expéditions validées uniquement. La date prise en compte est la date de validation (la date de prévision de livraison n'étant pas toujours renseignée). DateDeliveryPlanned=Date prévue de livraison From 6c08fbb630eba853c9cab0a3cfef1f86af1bcd39 Mon Sep 17 00:00:00 2001 From: gauthier Date: Fri, 10 Jun 2016 12:08:50 +0200 Subject: [PATCH 019/379] FIX : langs just in en_US --- htdocs/langs/en_US/sendings.lang | 1 + htdocs/langs/fr_FR/sendings.lang | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/sendings.lang b/htdocs/langs/en_US/sendings.lang index 1ec229af6c5..a36a8a1ae11 100644 --- a/htdocs/langs/en_US/sendings.lang +++ b/htdocs/langs/en_US/sendings.lang @@ -51,6 +51,7 @@ GenericTransport=Generic transport Enlevement=Gotten by customer DocumentModelSimple=Simple document model DocumentModelMerou=Merou A5 model +DocumentModelDorade=Model with amounts WarningNoQtyLeftToSend=Warning, no products waiting to be shipped. StatsOnShipmentsOnlyValidated=Statistics conducted on shipments only validated. Date used is date of validation of shipment (planed delivery date is not always known). DateDeliveryPlanned=Planned date of delivery diff --git a/htdocs/langs/fr_FR/sendings.lang b/htdocs/langs/fr_FR/sendings.lang index 9662b94ee25..ee6ee57b453 100644 --- a/htdocs/langs/fr_FR/sendings.lang +++ b/htdocs/langs/fr_FR/sendings.lang @@ -51,7 +51,6 @@ GenericTransport=Transporteur générique Enlevement=Enlèvement sur place par le client DocumentModelSimple=Modèle simple DocumentModelMerou=Modèle Merou A5 -DocumentModelDorade=Modèle d'expédition chiffré WarningNoQtyLeftToSend=Alerte, aucun produit en attente d'expédition. StatsOnShipmentsOnlyValidated=Statistiques effectuées sur les expéditions validées uniquement. La date prise en compte est la date de validation (la date de prévision de livraison n'étant pas toujours renseignée). DateDeliveryPlanned=Date prévue de livraison From dc224f3c880ed69748093c9175c93ee695a183e3 Mon Sep 17 00:00:00 2001 From: Alexis Algoud Date: Mon, 13 Jun 2016 16:25:27 +0200 Subject: [PATCH 020/379] NEW hook in element overview --- htdocs/projet/element.php | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index fe6fe738110..a69108905bf 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -95,6 +95,8 @@ if ($user->societe_id > 0) $socid=$user->societe_id; $result = restrictedArea($user, 'projet', $projectid, 'projet&project'); +$hookmanager->initHooks(array('projectOverview')); + /* * View */ @@ -347,6 +349,15 @@ $listofreferent=array( 'test'=>$conf->projet->enabled && $user->rights->projet->lire && $conf->salaries->enabled && empty($conf->global->PROJECT_HIDE_TASKS)), ); +$parameters=array('listofreferent'=>$listofreferent); +$resHook = $hookmanager->executeHooks('completeListOfReferent',$parameters,$object,$action); + +if(!empty($hookmanager->resArray)) { + + $listofreferent = array_merge($listofreferent, $hookmanager->resArray); + +} + if ($action=="addelement") { $tablename = GETPOST("tablename"); @@ -435,6 +446,7 @@ foreach ($listofreferent as $key => $value) $element = new $classname($db); $elementarray = $object->get_element_list($key, $tablename, $datefieldname, $dates, $datee); + if (count($elementarray)>0 && is_array($elementarray)) { $total_ht = 0; @@ -450,7 +462,7 @@ foreach ($listofreferent as $key => $value) $element->fetch($idofelement); if ($idofelementuser) $elementuser->fetch($idofelementuser); - if ($tablename != 'expensereport_det') $element->fetch_thirdparty(); + if ($tablename != 'expensereport_det' && method_exists($element, 'fetch_thirdparty')) $element->fetch_thirdparty(); if ($tablename == 'don') $total_ht_by_line=$element->amount; elseif ($tablename == 'projet_task') @@ -676,7 +688,7 @@ foreach ($listofreferent as $key => $value) if ($tablename != 'expensereport_det') { - $element->fetch_thirdparty(); + if(method_exists($element, 'fetch_thirdparty')) $element->fetch_thirdparty(); } else { From a0051a856a93967f881e9e2ea61fdf0fb6e8a3b4 Mon Sep 17 00:00:00 2001 From: gauthier Date: Wed, 15 Jun 2016 17:10:42 +0200 Subject: [PATCH 021/379] NEW : conf to allow payments on different thirdparties bills but same parent company --- htdocs/admin/facture.php | 32 ++++++++++++++++++++++++++++++++ htdocs/compta/paiement.php | 23 +++++++++++++++++++---- htdocs/langs/en_US/bills.lang | 1 + 3 files changed, 52 insertions(+), 4 deletions(-) diff --git a/htdocs/admin/facture.php b/htdocs/admin/facture.php index bae4b0abd88..20d2ade591c 100644 --- a/htdocs/admin/facture.php +++ b/htdocs/admin/facture.php @@ -280,6 +280,24 @@ if ($action == 'set_INVOICE_AUTO_FILLJS') } } +if ($action == 'set_FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS') +{ + $freetext = GETPOST('FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS'); // No alpha here, we want exact string + + $res = dolibarr_set_const($db, "FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS",$freetext,'chaine',0,'',$conf->entity); + + if (! $res > 0) $error++; + + if (! $error) + { + setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); + } + else + { + setEventMessages($langs->trans("Error"), null, 'errors'); + } +} + /* * View @@ -764,6 +782,20 @@ print '\n"; print ''; +// Add js auto fill amount on paiement form +$var=! $var; +print '
'; +print ''; +print ''; +print ''; +print $langs->trans("PaymentOnDifferentThirdBills"); +print ''; +print $form->selectyesno("FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS",$conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS,1); +print ''; +print ''; +print "\n"; +print '
'; + $var=! $var; print '
'; print ''; diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index fa1341dcbc6..8bd38593440 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -33,6 +33,7 @@ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/compta/paiement/class/paiement.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; require_once DOL_DOCUMENT_ROOT.'/compta/bank/class/account.class.php'; +require_once DOL_DOCUMENT_ROOT.'/societe/class/societe.class.php'; $langs->load('companies'); $langs->load('bills'); @@ -518,11 +519,21 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie * List of unpaid invoices */ $sql = 'SELECT f.rowid as facid, f.facnumber, f.total_ttc, f.multicurrency_total_ttc, f.type, '; - $sql.= ' f.datef as df'; + $sql.= ' f.datef as df, f.fk_soc as socid'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facture as f'; - $sql.= ' WHERE f.entity = '.$conf->entity; - $sql.= ' AND f.fk_soc = '.$facture->socid; - $sql.= ' AND f.paye = 0'; + + if(!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS)) { + $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'societe as s ON (f.fk_soc = s.rowid)'; + } + + $sql.= ' WHERE f.entity = '.$conf->entity; + $sql.= ' AND (f.fk_soc = '.$facture->socid; + + if(!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS)) { + $sql.= ' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.'societe WHERE parent = (SELECT parent FROM '.MAIN_DB_PREFIX.'societe WHERE rowid = '.$facture->socid.'))'; + } + + $sql.= ') AND f.paye = 0'; $sql.= ' AND f.fk_statut = 1'; // Statut=0 => not validated, Statut=2 => canceled if ($facture->type != 2) { @@ -583,6 +594,9 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie $objp = $db->fetch_object($resql); $var=!$var; + $soc = new Societe($db); + $soc->fetch($objp->socid); + $invoice=new Facture($db); $invoice->fetch($objp->facid); $paiement = $invoice->getSommePaiement(); @@ -605,6 +619,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie print ''; print $invoice->getNomUrl(1,''); + if($objp->socid != $facture->thirdparty->id) print ' - '.$soc->getNomUrl(1).' '; print "\n"; // Date diff --git a/htdocs/langs/en_US/bills.lang b/htdocs/langs/en_US/bills.lang index f6428f6a49a..6f0b1217f6d 100644 --- a/htdocs/langs/en_US/bills.lang +++ b/htdocs/langs/en_US/bills.lang @@ -311,6 +311,7 @@ LatestRelatedBill=Latest related invoice WarningBillExist=Warning, one or more invoice already exist MergingPDFTool=Merging PDF tool AmountPaymentDistributedOnInvoice=Payment amount distributed on invoice +PaymentOnDifferentThirdBills=Allow payments on different thirdparties bills but same parent company PaymentNote=Payment note ListOfPreviousSituationInvoices=List of previous situation invoices ListOfNextSituationInvoices=List of next situation invoices From b8f51753438fb26c1333a7e471a2216489736033 Mon Sep 17 00:00:00 2001 From: gauthier Date: Wed, 15 Jun 2016 17:16:16 +0200 Subject: [PATCH 022/379] FIX : sql optimisation --- htdocs/compta/paiement.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/paiement.php b/htdocs/compta/paiement.php index 8bd38593440..a9414fcafeb 100644 --- a/htdocs/compta/paiement.php +++ b/htdocs/compta/paiement.php @@ -530,7 +530,7 @@ if ($action == 'create' || $action == 'confirm_paiement' || $action == 'add_paie $sql.= ' AND (f.fk_soc = '.$facture->socid; if(!empty($conf->global->FACTURE_PAYMENTS_ON_DIFFERENT_THIRDPARTIES_BILLS)) { - $sql.= ' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.'societe WHERE parent = (SELECT parent FROM '.MAIN_DB_PREFIX.'societe WHERE rowid = '.$facture->socid.'))'; + $sql.= ' OR f.fk_soc IN (SELECT rowid FROM '.MAIN_DB_PREFIX.'societe WHERE parent = '.$facture->thirdparty->parent.')'; } $sql.= ') AND f.paye = 0'; From c365d14c2c95b4f289b78ab0bb23c81ec4892ddc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Thu, 16 Jun 2016 13:00:38 +0200 Subject: [PATCH 023/379] New: Autoset port and admin user from db type [Usability] Enhance install procedure by automatically suggesting the database port and administrative user on database type selection. --- htdocs/install/fileconf.php | 26 ++++++++++++++++++++++---- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/htdocs/install/fileconf.php b/htdocs/install/fileconf.php index 8d040e06ed4..d0cf9a4a385 100644 --- a/htdocs/install/fileconf.php +++ b/htdocs/install/fileconf.php @@ -369,7 +369,7 @@ if (! empty($force_install_message)) trans("Port"); ?> - value=""> @@ -484,9 +484,27 @@ if (! empty($force_install_message)) '."\n"; diff --git a/htdocs/theme/eldy/ckeditor/config.js b/htdocs/theme/eldy/ckeditor/config.js index cf7163671a3..f47260ccec3 100644 --- a/htdocs/theme/eldy/ckeditor/config.js +++ b/htdocs/theme/eldy/ckeditor/config.js @@ -28,7 +28,9 @@ CKEDITOR.editorConfig = function( config ) config.toolbar_Full = [ - ['Source','-','Save','NewPage','Preview','-','Templates'], + ['Templates','NewPage'], + ['Save'], + ['Source','Maximize','Preview'], ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'], ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'], ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'], diff --git a/htdocs/theme/md/ckeditor/config.js b/htdocs/theme/md/ckeditor/config.js index cf7163671a3..f47260ccec3 100644 --- a/htdocs/theme/md/ckeditor/config.js +++ b/htdocs/theme/md/ckeditor/config.js @@ -28,7 +28,9 @@ CKEDITOR.editorConfig = function( config ) config.toolbar_Full = [ - ['Source','-','Save','NewPage','Preview','-','Templates'], + ['Templates','NewPage'], + ['Save'], + ['Source','Maximize','Preview'], ['Cut','Copy','Paste','PasteText','PasteFromWord','-','Print', 'SpellChecker', 'Scayt'], ['Undo','Redo','-','Find','Replace','-','SelectAll','RemoveFormat'], ['Form', 'Checkbox', 'Radio', 'TextField', 'Textarea', 'Select', 'Button', 'ImageButton', 'HiddenField'], From f256de323e8c07391657b306b422cf0eccf94307 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 14 Jul 2016 12:52:00 +0200 Subject: [PATCH 086/379] Fix management of preview for website module --- htdocs/langs/en_US/website.lang | 2 ++ htdocs/theme/eldy/style.css.php | 6 +++++ htdocs/theme/md/style.css.php | 6 +++++ htdocs/websites/index.php | 47 ++++++++++++++++++++++++++++----- 4 files changed, 54 insertions(+), 7 deletions(-) diff --git a/htdocs/langs/en_US/website.lang b/htdocs/langs/en_US/website.lang index 64e5041061a..a3626c3c5df 100644 --- a/htdocs/langs/en_US/website.lang +++ b/htdocs/langs/en_US/website.lang @@ -21,3 +21,5 @@ ViewSiteInNewTab=View site in new tab ViewPageInNewTab=View page in new tab SetAsHomePage=Set as Home page RealURL=Real URL +ViewWebsiteInProduction=View web site using home URLs +SetHereVirtualHost=If you can set, on your web server, a dedicated virtual host with a root directory on %s, define here the virtual hostname so the preview will be done using this direct access instead of Dolibarr URLs wrapper. diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index 761ce42e0f5..7453a6b1b2f 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -603,6 +603,12 @@ div.myavailability { .minwidth300 { min-width: 300px; } .minwidth400 { min-width: 400px; } .minwidth500 { min-width: 500px; } +.minwidth50imp { min-width: 50px !important; } +.minwidth100imp { min-width: 100px !important; } +.minwidth200imp { min-width: 200px !important; } +.minwidth300imp { min-width: 300px !important; } +.minwidth400imp { min-width: 400px !important; } +.minwidth500imp { min-width: 500px !important; } .maxwidth100 { max-width: 100px; } .maxwidth150 { max-width: 150px; } .maxwidth200 { max-width: 200px; } diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index 92234aeddf3..9d12de74a6d 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -601,6 +601,12 @@ div.myavailability { .minwidth300 { min-width: 300px; } .minwidth400 { min-width: 400px; } .minwidth500 { min-width: 500px; } +.minwidth50imp { min-width: 50px !important; } +.minwidth100imp { min-width: 100px !important; } +.minwidth200imp { min-width: 200px !important; } +.minwidth300imp { min-width: 300px !important; } +.minwidth400imp { min-width: 400px !important; } +.minwidth500imp { min-width: 500px !important; } .maxwidth100 { max-width: 100px; } .maxwidth150 { max-width: 150px; } .maxwidth200 { max-width: 200px; } diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index 19f72486c3f..d61bad409a2 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -454,6 +454,8 @@ print '
'; if (count($object->records) > 0) { + // ***** Part for web sites + print '
'; print $langs->trans("Website").': '; print '
'; @@ -478,15 +480,44 @@ if (count($object->records) > 0) } $out.=''; print $out; - print ''; + print ''; if ($website) { - print ' - '.$langs->trans("RealURL").' '; $realurl=$urlwithroot.'/public/websites/index.php?website='.$website; + $dataroot=DOL_DATA_ROOT.'/websites/'.$website; + // TODO If virtual url defined, we use it + + /*print ' - '.$langs->trans("RealURL").' '; print ' '; - print ''.$langs->trans("ViewSiteInNewTab").''; + print ''.$langs->trans("ViewSiteInNewTab").'';*/ + + print '   '; + + print $langs->trans("ViewWebsiteInProduction").': '; + print ''; + //print ''; + $htmltext=$langs->trans("SetHereVirtualHost", $dataroot); + print $form->textwithpicto('', $htmltext); + print ''.$langs->trans("ViewSiteInNewTab").''; + + // Example : Adding jquery code + if (! empty($conf->use_javascript_ajax)) + { + print ''; + } } + print '
'; // Button for websites @@ -513,7 +544,8 @@ if (count($object->records) > 0) print ''; - // Part for pages + // ***** Part for pages + if ($website) { print ''; @@ -555,7 +587,7 @@ if (count($object->records) > 0) else $out.=''; $out.=''; print $out; - print ''; + print ''; print ''; //print $form->selectarray('page', $array); @@ -563,8 +595,9 @@ if (count($object->records) > 0) { print ' - '.$langs->trans("RealURL").' '; $realurl=$urlwithroot.'/public/websites/index.php?website='.$website.'&page='.$pageid; - print ' '; - print ''.$langs->trans("ViewPageInNewTab").''; + print ' '; + print ''.$langs->trans("ViewPageInNewTab").''; + //print ''; } print ''; From 241fd8db980ee65d2147fdcde621a92c597ab2a3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 14 Jul 2016 15:22:04 +0200 Subject: [PATCH 087/379] Fix css --- htdocs/theme/md/img/info.png | Bin 254 -> 399 bytes htdocs/theme/md/img/title_accountancy.png | Bin 218 -> 679 bytes htdocs/theme/md/img/title_products.png | Bin 107 -> 410 bytes htdocs/theme/md/style.css.php | 5 +++-- 4 files changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/theme/md/img/info.png b/htdocs/theme/md/img/info.png index bb6095bd00a792c96a465b2f14ddacb5bd269a72..a5af4a11e3cdb566747ffa327cf99fe522f894e1 100644 GIT binary patch delta 372 zcmV-)0gL|r0gnTaB!2>8OGiWi|A&vvzW@LL32;bRa{vGf6951U69E94oEQKA00(qQ zO+^Rb2M!GsE^^OP$N&HVAW1|)R4C7tlD|sBP!z_0h6r7S#P02yK#IOVyNG=O!P>6H zNkuy6#K~E7DSd>LO5NHAsOb|#j6-hXtz^(|`+x5F_|CcCIq(PUm_)g> zr~xY`5|@Znl_4E$O%p<{WStR9OMD_uxZ!{b6%M)Olt_7old2N&$+0Yq);=#lLq2k+ zA$z$*jnoK0-e}`8(Cw57B-JX>C(`JT+rmn0%}0vleYu?TBrE( z4}xDj%?4iqUTtaA9JBg}wj zzGz5X>`r;S;_yJo0`Tb4XU&nkZ!g$oK#$#G!DFuTOV~aYhbDDWmP}>C|L_fXfl>4Z SR59BC0000B6m>Me(+u0jC9!B!2>8OGiWi|A&vvzW@LL32;bRa{vGf6951U69E94oEQKA00(qQ zO+^Rb2M!Gp8ZHb|H~;_wI7vi7R7l6=*2_zjQ5XjBpQbr^EA3)qb^*&oDI$uZL=qR> zAcz(&gZ_Y^ZP6xzHZ9z?jJCCC7ez&_ipCOKR8R}8w6sx3^M8_`o;Dvt<><^1w5Vrw zzH<)GdEWOt=Y2o^OB5~fm1FbosBv1I?@HYD=ub2?8WjY=2fmt37Rks0N{vPHvP zt=Vy%%0b$YanpqnQ7q|@E+=h>HP=XrjQd(xZg#usok$SOn-&B!MqIIJk)xGl39M3w zE)BkV;)M~x3V(YXwAKk}*No?izofgMb88DWeY7w8BGvT8_Z>01Zuw1<=4HEkDHDorly5N~=*B$v zTDw}2enUoc`zR>au0@46p6bu!Y+R4e8kI^~m7gIK+MJP;(w!lKHF1)o%(Kby)}}o6 z5_=qVFn<&3R;O&koVSMaQ#2#xz7`FRs`5%&kg&~eb?DXOQ(=YeZCu!b*|@+>c;uXl zLfTQW_4e!3t~u76*5{!Idh>aAzml)A(^+3)Rks}0q%5CSnGN*@VxseZ*4I|3j7R0U ph)R}R9d#*g+4uh1PsBfr9}G3F4iK3kn*aa+00>D%PDHLkV1hr)Ft`8! delta 190 zcmV;v073t!1=<0SB!8hvL_t(|0qxLF3c@fDN8y)oEqF&2ui-JIw*J43;KBo`ROyrq zTBoF&LSDD!8(jJWK$V4W*CT`Zt(;#L!ZSjG>AIMkzP5 svy7oO9tO&YNocO)lUwNc@t4cJ0Cyjc+FLh!AOHXW07*qoM6N<$f;!7or~m)} diff --git a/htdocs/theme/md/img/title_products.png b/htdocs/theme/md/img/title_products.png index 142d71505c8c1a4855394adf3a392990224b3ecf..79c42a93647290818de98c961ff2b379efcd401a 100644 GIT binary patch delta 382 zcmV-^0fGK&ngfs|e*$7lM??VshmXv^00009a7bBm000XU000XU0RWnu7ytkO2XskI zMF-#q4h;?l_g4Yw0003iNkle}3%j&hElqyR8ZyT3~Nf zqA+D9B8)~ep}Y)ND^Q(+IEMmvCTNc7kV$AA0BjR9*J0w-ggjNkuoho@E^LTnIvgYf zol@K!rM6W&{|?H;Ic(meEZ_t14CuvZj*$#>#uMN&0{ZmRre<+Ni4rc>U-qcVBVBB4 zdOUEQ7IZ-mcz4yi<(~62AVo7&yG5FD=NmPBLfsg1Ig%g$lp4q6@Cg7#7R@(fImp4| z9iKcFFl7KZG;=<_P1xG+Ts^mqiJvF@gH*;{T;oEFdkR? cKYX_}1FeIpO9f4V!vFvP07*qoM6N<$f(-PZH2?qr delta 77 zcmbQmoIOFs-N@6$F{FYqnV~VzfJ;U~>O=#d#4`rg|C1S|GtvZ}#vNu^ywOZ58%A)s ZF)}POa(2)VkqTr00#8>zmvv4FO#r3L7is_i diff --git a/htdocs/theme/md/style.css.php b/htdocs/theme/md/style.css.php index 92234aeddf3..e32b53b70d4 100644 --- a/htdocs/theme/md/style.css.php +++ b/htdocs/theme/md/style.css.php @@ -746,7 +746,7 @@ td.showDragHandle { margin-left: 0; } div.login_block { - border-right: none ! important; + /* border-right: none ! important; */ top: inherit !important; } .side-nav { @@ -771,6 +771,7 @@ div.login_block { #id-left { z-index: 201; background: #FFF; + border-right: 1px solid rgba(0,0,0,0.3); global->MAIN_TESTMENUHIDER)) && empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) { ?> top: 50px ! important; @@ -2664,7 +2665,7 @@ div.tabBar .noborder { } span.boxstatstext { - opacity: 0.9; + /* opacity: 0.9; Disabled. This make text on top of left menu in smartphone size */ line-height: 18px; } span.boxstatsindicator { From 258662e6163e03603442908924103ebd5319855a Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 14 Jul 2016 15:31:56 +0200 Subject: [PATCH 088/379] Fix: missing month of update in leave "view log" page. --- htdocs/holiday/define_holiday.php | 3 --- htdocs/holiday/view_log.php | 13 ++++++++++--- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/htdocs/holiday/define_holiday.php b/htdocs/holiday/define_holiday.php index 6af57716648..7a94e686173 100644 --- a/htdocs/holiday/define_holiday.php +++ b/htdocs/holiday/define_holiday.php @@ -169,9 +169,6 @@ if ($lastUpdate) print '
'.$langs->trans("MonthOfLastMonthlyUpdate").': '.$yearLastUpdate.'-'.$monthLastUpdate.''."\n"; } else print $langs->trans('None'); - - - print "
\n"; $result = $holiday->updateBalance(); // Create users into table holiday if they don't exists. TODO Remove this whif we use field into table user. diff --git a/htdocs/holiday/view_log.php b/htdocs/holiday/view_log.php index e4b5070f097..1b0e779488a 100644 --- a/htdocs/holiday/view_log.php +++ b/htdocs/holiday/view_log.php @@ -60,7 +60,14 @@ $log_holiday = $cp->fetchLog('ORDER BY cpl.rowid DESC', " AND date_action BETWEE print load_fiche_titre($langs->trans('LogCP'), '', 'title_hrm.png'); print '
'.$langs->trans('LastUpdateCP').': '."\n"; -if ($cp->getConfCP('lastUpdate')) print ''.dol_print_date($db->jdate($cp->getConfCP('lastUpdate')),'dayhour','tzuser').''; +$lastUpdate = $cp->getConfCP('lastUpdate'); +if ($lastUpdate) +{ + $monthLastUpdate = $lastUpdate[4].$lastUpdate[5]; + $yearLastUpdate = $lastUpdate[0].$lastUpdate[1].$lastUpdate[2].$lastUpdate[3]; + print ''.dol_print_date($db->jdate($cp->getConfCP('lastUpdate')),'dayhour','tzuser').''; + print '
'.$langs->trans("MonthOfLastMonthlyUpdate").': '.$yearLastUpdate.'-'.$monthLastUpdate.''."\n"; +} else print $langs->trans('None'); print "

\n"; @@ -108,8 +115,8 @@ foreach($cp->logs as $logs_CP) if ($log_holiday == '2') { - print ''; - print ''.$langs->trans('None').''; + print ''; + print ''.$langs->trans('NoRecordFound').''; print ''; } From ec03ea8f70a6e2440379c3246cd808fa390e27d4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 14 Jul 2016 15:33:17 +0200 Subject: [PATCH 089/379] Dev branch is now 5.0 alpha --- htdocs/filefunc.inc.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/filefunc.inc.php b/htdocs/filefunc.inc.php index 54053c26606..02b87940916 100644 --- a/htdocs/filefunc.inc.php +++ b/htdocs/filefunc.inc.php @@ -31,7 +31,7 @@ */ if (! defined('DOL_APPLICATION_TITLE')) define('DOL_APPLICATION_TITLE','Dolibarr'); -if (! defined('DOL_VERSION')) define('DOL_VERSION','4.0.0-rc'); +if (! defined('DOL_VERSION')) define('DOL_VERSION','5.0.0-alpha'); if (! defined('EURO')) define('EURO',chr(128)); From ec6640af632ec8bbe1b8d018322928e08ad2cc44 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 14 Jul 2016 15:54:46 +0200 Subject: [PATCH 090/379] Add field virtualhost for website module --- htdocs/install/check.php | 3 +- .../install/mysql/migration/4.0.0-5.0.0.sql | 29 +++++++++++++++++++ htdocs/install/mysql/tables/llx_website.sql | 1 + htdocs/websites/class/website.class.php | 22 ++++++++++++-- 4 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 htdocs/install/mysql/migration/4.0.0-5.0.0.sql diff --git a/htdocs/install/check.php b/htdocs/install/check.php index 9e21b994780..66a9f7f77bb 100644 --- a/htdocs/install/check.php +++ b/htdocs/install/check.php @@ -392,7 +392,8 @@ else array('from'=>'3.6.0', 'to'=>'3.7.0'), array('from'=>'3.7.0', 'to'=>'3.8.0'), array('from'=>'3.8.0', 'to'=>'3.9.0'), - array('from'=>'3.9.0', 'to'=>'4.0.0') + array('from'=>'3.9.0', 'to'=>'4.0.0'), + array('from'=>'4.0.0', 'to'=>'5.0.0') ); $count=0; diff --git a/htdocs/install/mysql/migration/4.0.0-5.0.0.sql b/htdocs/install/mysql/migration/4.0.0-5.0.0.sql new file mode 100644 index 00000000000..849a71c935f --- /dev/null +++ b/htdocs/install/mysql/migration/4.0.0-5.0.0.sql @@ -0,0 +1,29 @@ +-- +-- Be carefull to requests order. +-- This file must be loaded by calling /install/index.php page +-- when current version is 4.0.0 or higher. +-- +-- To rename a table: ALTER TABLE llx_table RENAME TO llx_table_new; +-- To add a column: ALTER TABLE llx_table ADD COLUMN newcol varchar(60) NOT NULL DEFAULT '0' AFTER existingcol; +-- To rename a column: ALTER TABLE llx_table CHANGE COLUMN oldname newname varchar(60); +-- To drop a column: ALTER TABLE llx_table DROP COLUMN oldname; +-- To change type of field: ALTER TABLE llx_table MODIFY COLUMN name varchar(60); +-- To drop a foreign key: ALTER TABLE llx_table DROP FOREIGN KEY fk_name; +-- To drop an index: -- VMYSQL4.0 DROP INDEX nomindex on llx_table +-- To drop an index: -- VPGSQL8.0 DROP INDEX nomindex +-- To restrict request to Mysql version x.y minimum use -- VMYSQLx.y +-- To restrict request to Pgsql version x.y minimum use -- VPGSQLx.y +-- To make pk to be auto increment (mysql): VMYSQL4.3 ALTER TABLE llx_c_shipment_mode CHANGE COLUMN rowid rowid INTEGER NOT NULL AUTO_INCREMENT; +-- To make pk to be auto increment (postgres): VPGSQL8.2 NOT POSSIBLE. MUST DELETE/CREATE TABLE +-- To set a field as NULL: VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name DROP NOT NULL; +-- To set a field as default NULL: VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name SET DEFAULT NULL; +-- Note: fields with type BLOB/TEXT can't have default value. +-- -- VPGSQL8.2 DELETE FROM llx_usergroup_user WHERE fk_user NOT IN (SELECT rowid from llx_user); +-- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup); + + +ALTER TABLE llx_website ADD COLUMN virtualhost varchar(255) after fk_default_home; + + + + diff --git a/htdocs/install/mysql/tables/llx_website.sql b/htdocs/install/mysql/tables/llx_website.sql index 8dd257ffa69..331e6b085bd 100644 --- a/htdocs/install/mysql/tables/llx_website.sql +++ b/htdocs/install/mysql/tables/llx_website.sql @@ -25,6 +25,7 @@ CREATE TABLE llx_website description varchar(255), status integer, fk_default_home integer, + virtualhost varchar(255), date_creation datetime, date_modification datetime, tms timestamp diff --git a/htdocs/websites/class/website.class.php b/htdocs/websites/class/website.class.php index e87e830bb77..a3760a792ce 100644 --- a/htdocs/websites/class/website.class.php +++ b/htdocs/websites/class/website.class.php @@ -85,6 +85,12 @@ class Website extends CommonObject * @var integer */ public $fk_default_home; + /** + * @var string + */ + public $virtualhost; + + public $records; /** @@ -143,7 +149,8 @@ class Website extends CommonObject $sql.= 'ref,'; $sql.= 'description,'; $sql.= 'status,'; - $sql.= 'fk_default_home,'; + $sql.= 'fk_default_home,'; + $sql.= 'virtualhost,'; $sql.= 'date_creation,'; $sql.= 'date_modification'; @@ -154,6 +161,7 @@ class Website extends CommonObject $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->virtualhost)?'NULL':$this->virtualhost).','; $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)."'"); @@ -214,6 +222,7 @@ class Website extends CommonObject $sql .= " t.description,"; $sql .= " t.status,"; $sql .= " t.fk_default_home,"; + $sql .= " t.virtualhost,"; $sql .= " t.date_creation,"; $sql .= " t.date_modification,"; $sql .= " t.tms"; @@ -237,6 +246,7 @@ class Website extends CommonObject $this->description = $obj->description; $this->status = $obj->status; $this->fk_default_home = $obj->fk_default_home; + $this->virtualhost = $obj->virtualhost; $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); @@ -281,7 +291,8 @@ class Website extends CommonObject $sql .= " t.ref,"; $sql .= " t.description,"; $sql .= " t.status,"; - $sql .= " t.fk_default_home,"; + $sql .= " t.fk_default_home,"; + $sql .= " t.virtualhost,"; $sql .= " t.date_creation,"; $sql .= " t.date_modification,"; $sql .= " t.tms"; @@ -321,6 +332,7 @@ class Website extends CommonObject $line->description = $obj->description; $line->status = $obj->status; $line->fk_default_home = $obj->fk_default_home; + $line->virtualhost = $obj->virtualhost; $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); @@ -380,6 +392,7 @@ class Website extends CommonObject $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 .= ' virtualhost = '.(($this->virtualhost != '')?$this->virtualhost:"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())."'"); @@ -627,6 +640,7 @@ class Website extends CommonObject $this->description = 'A specimen website'; $this->status = ''; $this->fk_default_home = null; + $this->virtualhost = 'http://myvirtualhost'; $this->date_creation = dol_now(); $this->date_modification = dol_now(); $this->tms = dol_now(); @@ -665,6 +679,10 @@ class WebsiteLine * @var int */ public $fk_default_home; + /** + * @var string + */ + public $virtualhost; /** * @var mixed */ From ddcf135a9627494abe4b3c7670d9add5c643eaae Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 14 Jul 2016 15:56:35 +0200 Subject: [PATCH 091/379] Prepare 5.0 --- .travis.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 8655b27d4ed..8e1aa2aa10b 100644 --- a/.travis.yml +++ b/.travis.yml @@ -287,10 +287,13 @@ script: php upgrade.php 3.9.0 4.0.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade390400.log php upgrade2.php 3.9.0 4.0.0 MAIN_MODULE_API,MAIN_MODULE_SUPPLIERPROPOSAL > $TRAVIS_BUILD_DIR/upgrade390400-2.log php step5.php 3.9.0 4.0.0 > $TRAVIS_BUILD_DIR/upgrade390400-3.log + php upgrade.php 4.0.0 5.0.0 ignoredbversion > $TRAVIS_BUILD_DIR/upgrade400500.log + php upgrade2.php 4.0.0 5.0.0 MAIN_MODULE_API,MAIN_MODULE_SUPPLIERPROPOSAL > $TRAVIS_BUILD_DIR/upgrade400500-2.log + php step5.php 4.0.0 5.0.0 > $TRAVIS_BUILD_DIR/upgrade400500-3.log cd - set +e echo - #cat $TRAVIS_BUILD_DIR/upgrade390400-2.log + #cat $TRAVIS_BUILD_DIR/upgrade400500-2.log #cat /tmp/dolibarr_install.log - | From 26f27487b951189bb67219504c91c22fddb63371 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Thu, 14 Jul 2016 18:40:49 +0200 Subject: [PATCH 092/379] Add hook for additionnal feature on element tooltip --- htdocs/product/class/product.class.php | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 982b109da99..fb38efb8a07 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3157,6 +3157,17 @@ class Product extends CommonObject $linkclose = '" title="'.str_replace('\n', '', dol_escape_htmltag($label, 1)).'" class="classfortooltip">'; + if (! is_object($hookmanager)) + { + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager=new HookManager($this->db); + } + $hookmanager->initHooks(array('productdao')); + $parameters=array('id'=>$this->id); + $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if ($reshook > 0) $linkclose = $hookmanager->resPrint; + + if ($option == 'supplier') { $link = 'db); + } + $hookmanager->initHooks(array('societedao')); + $parameters=array('id'=>$this->id); + $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + if ($reshook > 0) $linkclose = $hookmanager->resPrint; + } - $link.='>'; + $link.=$linkclose.'>'; $linkend=''; if ($withpicto) $result.=($link.img_object(($notooltip?'':$label), 'company', ($notooltip?'':'class="classfortooltip"')).$linkend); From a5123c06dbe2930c1ef235a0ccc15e2f33ffe00c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Thu, 14 Jul 2016 19:42:04 +0200 Subject: [PATCH 094/379] Save the virtualhost so we can test without entering it each time. --- htdocs/core/ajax/saveinplace.php | 15 ++++++++++++++- htdocs/core/class/genericobject.class.php | 3 +-- htdocs/core/modules/modWebsites.class.php | 2 +- htdocs/websites/index.php | 16 ++++++++++++++-- 4 files changed, 30 insertions(+), 6 deletions(-) diff --git a/htdocs/core/ajax/saveinplace.php b/htdocs/core/ajax/saveinplace.php index 4d0ab65a941..48797dd0432 100644 --- a/htdocs/core/ajax/saveinplace.php +++ b/htdocs/core/ajax/saveinplace.php @@ -35,6 +35,19 @@ $element = GETPOST('element','alpha',2); $table_element = GETPOST('table_element','alpha',2); $fk_element = GETPOST('fk_element','alpha',2); +/* Example: +field:editval_ref_customer (8 first chars will removed to know name of property) +element:contrat +table_element:contrat +fk_element:4 +type:string +value:aaa +loadmethod: +savemethod: +savemethodname: +*/ + + /* * View */ @@ -81,7 +94,7 @@ if (! empty($field) && ! empty($element) && ! empty($table_element) && ! empty($ } else $newelement = $element; - if (! empty($user->rights->$newelement->creer) || ! empty($user->rights->$newelement->write) + if (! empty($user->rights->$newelement->creer) || ! empty($user->rights->$newelement->create) || ! empty($user->rights->$newelement->write) || (isset($subelement) && (! empty($user->rights->$newelement->$subelement->creer) || ! empty($user->rights->$newelement->$subelement->write))) || ($element == 'payment' && $user->rights->facture->paiement) || ($element == 'payment_supplier' && $user->rights->fournisseur->facture->creer)) diff --git a/htdocs/core/class/genericobject.class.php b/htdocs/core/class/genericobject.class.php index 32960664c17..c89b5c31fea 100644 --- a/htdocs/core/class/genericobject.class.php +++ b/htdocs/core/class/genericobject.class.php @@ -24,8 +24,7 @@ require_once DOL_DOCUMENT_ROOT .'/core/class/commonobject.class.php'; /** - * \class GenericObject - * \brief Class of a generic business object + * Class of a generic business object */ class GenericObject extends CommonObject diff --git a/htdocs/core/modules/modWebsites.class.php b/htdocs/core/modules/modWebsites.class.php index 30795c6c0fa..a510e569b60 100644 --- a/htdocs/core/modules/modWebsites.class.php +++ b/htdocs/core/modules/modWebsites.class.php @@ -99,7 +99,7 @@ class modWebsites extends DolibarrModules $this->rights[$r][0] = 10002; $this->rights[$r][1] = 'Create/modify website content'; $this->rights[$r][3] = 0; - $this->rights[$r][4] = 'create'; + $this->rights[$r][4] = 'write'; $r++; $this->rights[$r][0] = 10003; diff --git a/htdocs/websites/index.php b/htdocs/websites/index.php index d61bad409a2..475fe219826 100644 --- a/htdocs/websites/index.php +++ b/htdocs/websites/index.php @@ -486,6 +486,7 @@ if (count($object->records) > 0) { $realurl=$urlwithroot.'/public/websites/index.php?website='.$website; $dataroot=DOL_DATA_ROOT.'/websites/'.$website; + if (! empty($object->virtualhost)) $realurl=$object->virtualhost; // TODO If virtual url defined, we use it /*print ' - '.$langs->trans("RealURL").' '; @@ -507,10 +508,21 @@ if (count($object->records) > 0) print ' @@ -41,5 +38,14 @@ google_ad_height = 60;
+ + + + + + \ No newline at end of file diff --git a/build/doxygen/doxygen_header.html b/build/doxygen/doxygen_header.html index 0c2e189136b..fe316d2081e 100644 --- a/build/doxygen/doxygen_header.html +++ b/build/doxygen/doxygen_header.html @@ -1,6 +1,4 @@ - + @@ -14,7 +12,23 @@ File added into doxygen generated documentation + + + + + +
From 260e296f20f5e4e98c0fc53fd12b3cd1271ab63f Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Mon, 18 Jul 2016 02:05:30 +0200 Subject: [PATCH 147/379] add $result on db->free --- htdocs/societe/index.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/index.php b/htdocs/societe/index.php index 1cc44777438..6e0dcbec113 100644 --- a/htdocs/societe/index.php +++ b/htdocs/societe/index.php @@ -326,7 +326,7 @@ if ($result) $i++; } - $db->free(); + $db->free($result); print "\n"; print "\n"; From bc4674bdcea071f52d6053487467b66b99db7009 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Mon, 18 Jul 2016 07:37:18 +0200 Subject: [PATCH 148/379] fix problem with call update method after fetch on invocie lines --- htdocs/compta/facture/class/facture.class.php | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 0ebe4f9b6ac..157f2ff6c97 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -3487,7 +3487,7 @@ class Facture extends CommonInvoice $response->nbtodolate++; } } - + return $response; } else @@ -3897,7 +3897,7 @@ class Facture extends CommonInvoice global $conf; $now = dol_now(); - + // Paid invoices have status STATUS_CLOSED if ($this->statut != Facture::STATUS_VALIDATED) return false; @@ -4006,6 +4006,10 @@ class FactureLigne extends CommonInvoiceLine $sql.= ' fd.fk_unit,'; $sql.= ' fd.situation_percent, fd.fk_prev_id,'; $sql.= ' p.ref as product_ref, p.label as product_libelle, p.description as product_desc'; + $sql.= ' , multicurrency_subprice'; + $sql.= ' , multicurrency_total_ht'; + $sql.= ' , multicurrency_total_tva'; + $sql.= ' , multicurrency_total_ttc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet as fd'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON fd.fk_product = p.rowid'; $sql.= ' WHERE fd.rowid = '.$rowid; @@ -4056,6 +4060,11 @@ class FactureLigne extends CommonInvoiceLine $this->situation_percent = $objp->situation_percent; $this->fk_prev_id = $objp->fk_prev_id; + $this->multicurrency_subprice = $objp->multicurrency_subprice; + $this->multicurrency_total_ht = $objp->multicurrency_total_ht; + $this->multicurrency_total_tva= $objp->multicurrency_total_tva; + $this->multicurrency_total_ttc= $objp->multicurrency_total_ttc; + $this->db->free($result); return 1; @@ -4309,6 +4318,11 @@ class FactureLigne extends CommonInvoiceLine if (! isset($this->situation_percent) || $this->situation_percent > 100 || (string) $this->situation_percent == '') $this->situation_percent = 100; if (empty($this->pa_ht)) $this->pa_ht=0; + if (empty($this->multicurrency_subprice)) $this->multicurrency_subprice=0; + if (empty($this->multicurrency_total_ht)) $this->multicurrency_total_ht=0; + if (empty($this->multicurrency_total_tva)) $this->multicurrency_total_tva=0; + if (empty($this->multicurrency_total_ttc)) $this->multicurrency_total_ttc=0; + // Check parameters if ($this->product_type < 0) return -1; From d3344f52910d41cc68caeaa530af80f23a27510b Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Mon, 18 Jul 2016 07:48:32 +0200 Subject: [PATCH 149/379] sd --- htdocs/compta/facture/class/facture.class.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/compta/facture/class/facture.class.php b/htdocs/compta/facture/class/facture.class.php index 157f2ff6c97..8eaf544dad9 100644 --- a/htdocs/compta/facture/class/facture.class.php +++ b/htdocs/compta/facture/class/facture.class.php @@ -4006,10 +4006,10 @@ class FactureLigne extends CommonInvoiceLine $sql.= ' fd.fk_unit,'; $sql.= ' fd.situation_percent, fd.fk_prev_id,'; $sql.= ' p.ref as product_ref, p.label as product_libelle, p.description as product_desc'; - $sql.= ' , multicurrency_subprice'; - $sql.= ' , multicurrency_total_ht'; - $sql.= ' , multicurrency_total_tva'; - $sql.= ' , multicurrency_total_ttc'; + $sql.= ' , fd.multicurrency_subprice'; + $sql.= ' , fd.multicurrency_total_ht'; + $sql.= ' , fd.multicurrency_total_tva'; + $sql.= ' , fd.multicurrency_total_ttc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'facturedet as fd'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON fd.fk_product = p.rowid'; $sql.= ' WHERE fd.rowid = '.$rowid; From 5e654e8cb38468e02d84631999d70ddd47c8eec3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 18 Jul 2016 11:49:34 +0200 Subject: [PATCH 150/379] Fix help --- htdocs/langs/en_US/admin.lang | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/langs/en_US/admin.lang b/htdocs/langs/en_US/admin.lang index 369dde1cf1c..8b2d46aedb3 100644 --- a/htdocs/langs/en_US/admin.lang +++ b/htdocs/langs/en_US/admin.lang @@ -1523,7 +1523,7 @@ NoModueToManageStockIncrease=No module able to manage automatic stock increase h YouMayFindNotificationsFeaturesIntoModuleNotification=You may find options for EMail notifications by enabling and configuring the module "Notification". ListOfNotificationsPerContact=List of notifications per contact* ListOfFixedNotifications=List of fixed notifications -GoOntoContactCardToAddMore=Go on the tab "Notifications" of a thirdparty contact to add or remove notifications for contacts/addresses +GoOntoContactCardToAddMore=Go on the tab "Notifications" of a thirdparty to add or remove notifications for contacts/addresses Threshold=Threshold BackupDumpWizard=Wizard to build database backup dump file SomethingMakeInstallFromWebNotPossible=Installation of external module is not possible from the web interface for the following reason: From 135bebd9a03a6a88aa647450cbe9d283c6c95732 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 18 Jul 2016 11:53:13 +0200 Subject: [PATCH 151/379] Sort of sent notification by date desc --- htdocs/user/notify/card.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/user/notify/card.php b/htdocs/user/notify/card.php index 62763c562df..996a6fba370 100644 --- a/htdocs/user/notify/card.php +++ b/htdocs/user/notify/card.php @@ -51,8 +51,8 @@ if ($page == -1) { $page = 0; } $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (! $sortorder) $sortorder="ASC"; -if (! $sortfield) $sortfield="c.lastname"; +if (! $sortorder) $sortorder="DESC"; +if (! $sortfield) $sortfield="a.daten"; $now=dol_now(); From 10cd5ba7305d89b653c75e06ffb222ca7a27b515 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 18 Jul 2016 11:54:35 +0200 Subject: [PATCH 152/379] Fix sort of sent notification by date desc --- htdocs/societe/notify/card.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/societe/notify/card.php b/htdocs/societe/notify/card.php index 40120948a3d..888459c006b 100644 --- a/htdocs/societe/notify/card.php +++ b/htdocs/societe/notify/card.php @@ -51,8 +51,8 @@ if ($page == -1) { $page = 0; } $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; -if (! $sortorder) $sortorder="ASC"; -if (! $sortfield) $sortfield="c.lastname"; +if (! $sortorder) $sortorder="DESC"; +if (! $sortfield) $sortfield="a.daten"; $now=dol_now(); From 621a29d0e0ce77528d6516f49bc0c736f428fed3 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 18 Jul 2016 12:01:25 +0200 Subject: [PATCH 153/379] Fix account may contains text --- htdocs/compta/bank/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/compta/bank/card.php b/htdocs/compta/bank/card.php index 1553ae40b92..d4de4e5efb1 100644 --- a/htdocs/compta/bank/card.php +++ b/htdocs/compta/bank/card.php @@ -89,7 +89,7 @@ if ($_POST["action"] == 'add') $account->proprio = trim($_POST["proprio"]); $account->owner_address = trim($_POST["owner_address"]); - $account_number = GETPOST('account_number','int'); + $account_number = GETPOST('account_number','alpha'); if ($account_number <= 0) { $account->account_number = ''; } else { $account->account_number = $account_number; } $account->accountancy_journal = trim($_POST["accountancy_journal"]); From 2c77a901b30b8a11f084f4460f240519630a0f36 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 18 Jul 2016 12:55:44 +0200 Subject: [PATCH 154/379] Fix to avoid removal of trnaslation key to keep --- dev/translation/sanity_check_en_langfiles.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/dev/translation/sanity_check_en_langfiles.php b/dev/translation/sanity_check_en_langfiles.php index 1912c8b4142..66da0eebb41 100755 --- a/dev/translation/sanity_check_en_langfiles.php +++ b/dev/translation/sanity_check_en_langfiles.php @@ -294,7 +294,9 @@ if ((! empty($_REQUEST['unused']) && $_REQUEST['unused'] == 'true') || (isset($a if (preg_match('/^DescADHERENT_/', $value)) $qualifiedforclean=0; if (preg_match('/^SubmitTranslation/', $value)) $qualifiedforclean=0; if (preg_match('/^ModuleCompanyCode/', $value)) $qualifiedforclean=0; - + // boxes.lang + if (preg_match('/^BoxTitleLast/', $value)) $qualifiedforclean=0; + if (preg_match('/^BoxTitleLatest/', $value)) $qualifiedforclean=0; // main.lang if (preg_match('/^Duration/', $value)) $qualifiedforclean=0; if (preg_match('/^FormatDate/', $value)) $qualifiedforclean=0; From fd7c494cb672e0a2745d89fa68633fd7c2a535bd Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 18 Jul 2016 13:20:04 +0200 Subject: [PATCH 155/379] Add VAT for cyprus --- htdocs/install/mysql/data/llx_00_c_country.sql | 2 +- htdocs/install/mysql/data/llx_c_tva.sql | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/htdocs/install/mysql/data/llx_00_c_country.sql b/htdocs/install/mysql/data/llx_00_c_country.sql index d84826ed5d0..315f3c3092a 100644 --- a/htdocs/install/mysql/data/llx_00_c_country.sql +++ b/htdocs/install/mysql/data/llx_00_c_country.sql @@ -105,7 +105,7 @@ INSERT INTO llx_c_country (rowid,code,code_iso,label,active,favorite) VALUES (74 INSERT INTO llx_c_country (rowid,code,code_iso,label,active,favorite) VALUES (75,'CR','CRI','Costa Rica',1,0); INSERT INTO llx_c_country (rowid,code,code_iso,label,active,favorite) VALUES (76,'HR','HRV','Croatie',1,0); INSERT INTO llx_c_country (rowid,code,code_iso,label,active,favorite) VALUES (77,'CU','CUB','Cuba',1,0); -INSERT INTO llx_c_country (rowid,code,code_iso,label,active,favorite) VALUES (78,'CY','CYP','Chypre',1,0); +INSERT INTO llx_c_country (rowid,code,code_iso,label,active,favorite) VALUES (78,'CY','CYP','Cyprus',1,0); INSERT INTO llx_c_country (rowid,code,code_iso,label,active,favorite) VALUES (79,'CZ','CZE','République Tchèque',1,0); INSERT INTO llx_c_country (rowid,code,code_iso,label,active,favorite) VALUES (80,'DK','DNK','Danemark',1,0); INSERT INTO llx_c_country (rowid,code,code_iso,label,active,favorite) VALUES (81,'DJ','DJI','Djibouti',1,0); diff --git a/htdocs/install/mysql/data/llx_c_tva.sql b/htdocs/install/mysql/data/llx_c_tva.sql index 3d88e6bbcc9..774ffc381fc 100644 --- a/htdocs/install/mysql/data/llx_c_tva.sql +++ b/htdocs/install/mysql/data/llx_c_tva.sql @@ -81,14 +81,18 @@ insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (67 insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (672, 67, '0','0','VAT Rate 0',1); -- CHINA (id country=9) -insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 91, 9, '17','0','VAT standard rate',1); -insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 92, 9, '13','0','VAT reduced rate 0',1); -insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 93, 9, '3','0','VAT super reduced rate 0',1); -insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 94, 9, '0','0','VAT Rate 0',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 91, 9, '17','0','VAT standard rate',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 92, 9, '13','0','VAT reduced rate 0',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 93, 9, '3','0','VAT super reduced rate 0',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 94, 9, '0','0','VAT Rate 0',1); + +-- CYPRUS (id country=78) +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (781, 78, '19','0','VAT standard rate',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (784, 78, '0','0','VAT Rate 0',1); -- DANMERK (id country=80) -insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (801,80, '25','0','VAT standard rate',1); -insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (802,80, '0','0','VAT Rate 0',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (801, 80, '25','0','VAT standard rate',1); +insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values (802, 80, '0','0','VAT Rate 0',1); -- FRANCE (id country=1) insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,note,active) values ( 11, 1, '20','0','VAT standard rate (France hors DOM-TOM)',1); From 038526bb712d77302835904876c8cc04dabaf0c5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 18 Jul 2016 14:40:10 +0200 Subject: [PATCH 156/379] Code comment --- htdocs/install/mysql/tables/llx_product.sql | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/htdocs/install/mysql/tables/llx_product.sql b/htdocs/install/mysql/tables/llx_product.sql index 8b43844498e..1769ec6bd3e 100755 --- a/htdocs/install/mysql/tables/llx_product.sql +++ b/htdocs/install/mysql/tables/llx_product.sql @@ -57,7 +57,7 @@ create table llx_product tosell tinyint DEFAULT 1, -- Product you sell tobuy tinyint DEFAULT 1, -- Product you buy onportal tinyint DEFAULT 0, -- If it is a product you sell and you want to sell it on portal (module website must be on) - tobatch tinyint DEFAULT 0 NOT NULL, -- Is it a product that need a batch or eat-by management + tobatch tinyint DEFAULT 0 NOT NULL, -- Is it a product that need a batch management (eat-by or lot management) fk_product_type integer DEFAULT 0, -- Type of product: 0 for regular product, 1 for service, 9 for other (used by external module) duration varchar(6), seuil_stock_alerte integer DEFAULT 0, @@ -81,8 +81,8 @@ create table llx_product volume_units tinyint DEFAULT NULL, stock real, -- Current physical stock (dernormalized field) pmp double(24,8) DEFAULT 0 NOT NULL, -- To store valuation of stock calculated using average price method, for this product - fifo double(24,8), -- To store valuation of stock calculated using fifo method, for this product - lifo double(24,8), -- To store valuation of stock calculated using lifo method, for this product + fifo double(24,8), -- To store valuation of stock calculated using fifo method, for this product. TODO Not used, should be replaced by stock value stored into movement table. + lifo double(24,8), -- To store valuation of stock calculated using lifo method, for this product. TODO Not used, should be replaced by stock value stored into movement table. canvas varchar(32) DEFAULT NULL, finished tinyint DEFAULT NULL, -- 1=manufactured product, 0=matiere premiere hidden tinyint DEFAULT 0, -- Not used. Deprecated. From 093f1da206834ccc2fed08c9e3cfce7d4e175ea2 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Mon, 18 Jul 2016 15:07:35 +0200 Subject: [PATCH 157/379] Some indenting and hookmanager feature --- htdocs/comm/action/class/actioncomm.class.php | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/htdocs/comm/action/class/actioncomm.class.php b/htdocs/comm/action/class/actioncomm.class.php index ad58f612c1c..406d7b5916c 100644 --- a/htdocs/comm/action/class/actioncomm.class.php +++ b/htdocs/comm/action/class/actioncomm.class.php @@ -1096,24 +1096,36 @@ class ActionComm extends CommonObject */ function getNomUrl($withpicto=0,$maxlength=0,$classname='',$option='',$overwritepicto=0) { - global $conf,$langs; + global $conf,$langs, $hookmanager; - $result=''; - $tooltip = '' . $langs->trans('ShowAction'.$objp->code) . ''; - if (! empty($this->ref)) - $tooltip .= '
' . $langs->trans('Ref') . ': ' . $this->ref; - $label = $this->label; - if (empty($label)) $label=$this->libelle; // For backward compatibility - if (! empty($label)) - $tooltip .= '
' . $langs->trans('Title') . ': ' . $label; - if (! empty($this->location)) - $tooltip .= '
' . $langs->trans('Location') . ': ' . $this->location; + $result=''; + $tooltip = '' . $langs->trans('ShowAction'.$objp->code) . ''; + if (! empty($this->ref)) + $tooltip .= '
' . $langs->trans('Ref') . ': ' . $this->ref; + $label = $this->label; + if (empty($label)) $label=$this->libelle; // For backward compatibility + if (! empty($label)) + $tooltip .= '
' . $langs->trans('Title') . ': ' . $label; + if (! empty($this->location)) + $tooltip .= '
' . $langs->trans('Location') . ': ' . $this->location; + + $linkclose = ' class="'.$classname.' classfortooltip" title="'.dol_escape_htmltag($tooltip, 1).'">'; + if (! is_object($hookmanager)) + { + include_once DOL_DOCUMENT_ROOT.'/core/class/hookmanager.class.php'; + $hookmanager=new HookManager($this->db); + } + $hookmanager->initHooks(array('actiondao')); + $parameters=array('id'=>$this->id); + $reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks + $linkclose = ($hookmanager->resPrint ? $hookmanager->resPrint : $linkclose); - $linkclose = '" title="'.dol_escape_htmltag($tooltip, 1).'">'; - if ($option=='birthday') $link = 'libelle.'-'.$withpicto; if ($withpicto == 2) { From c5ebb8f98305c9696e2feb04b66fc28c115a8d4d Mon Sep 17 00:00:00 2001 From: Juanjo Menent Date: Mon, 18 Jul 2016 18:44:05 +0200 Subject: [PATCH 158/379] Fix bad param name to test if showing selector for suppliers --- htdocs/projet/element.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/projet/element.php b/htdocs/projet/element.php index a28ed69ab23..85ffae8b4b6 100644 --- a/htdocs/projet/element.php +++ b/htdocs/projet/element.php @@ -2,7 +2,7 @@ /* Copyright (C) 2001-2004 Rodolphe Quiedeville * Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin - * Copyright (C) 2012 Juanjo Menent + * Copyright (C) 2012-2016 Juanjo Menent * Copyright (C) 2015 Alexandre Spangaro * Copyright (C) 2015 Marcos García * @@ -581,7 +581,7 @@ foreach ($listofreferent as $key => $value) $addform=''; $idtofilterthirdparty=0; - if (! in_array($tablename, array('facture_fourn', 'commande_fourn'))) $idtofilterthirdparty=$object->thirdparty->id; + if (! in_array($tablename, array('facture_fourn', 'commande_fournisseur'))) $idtofilterthirdparty=$object->thirdparty->id; if (empty($conf->global->PROJECT_LINK_ON_OVERWIEW_DISABLED) && $idtofilterthirdparty > 0) { From 5ea72c8d5664a7adeedde9c37a0e12149e9bf573 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Tue, 19 Jul 2016 07:46:27 +0200 Subject: [PATCH 159/379] FIX : cannot update bank account on invoice if module order not activated --- htdocs/compta/facture.php | 42 +++++++++++++++++++-------------------- 1 file changed, 21 insertions(+), 21 deletions(-) diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 04951cbb6cd..659bcaae7c4 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -407,7 +407,7 @@ if (empty($reshook)) } } } - + $qualified_for_stock_change = 0; if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { $qualified_for_stock_change = $object->hasProductsOrServices(2); @@ -962,7 +962,7 @@ if (empty($reshook)) dol_syslog("Try to find source object origin=" . $object->origin . " originid=" . $object->origin_id . " to add lines or deposit lines"); $result = $srcobject->fetch($object->origin_id); - + // If deposit invoice if ($_POST['type'] == Facture::TYPE_DEPOSIT) { @@ -1130,7 +1130,7 @@ if (empty($reshook)) $error ++; } } - + // Now we create same links to contact than the ones found on origin object if (empty($conf->global->INVOICE_NO_PROPAGATE_CONTACTS_FROM_ORIGIN)) { @@ -1143,24 +1143,24 @@ if (empty($reshook)) } $sqlcontact = "SELECT code, fk_socpeople FROM ".MAIN_DB_PREFIX."element_contact as ec, ".MAIN_DB_PREFIX."c_type_contact as ctc"; $sqlcontact.= " WHERE element_id = ".$originidforcontact." AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$originforcontact."'"; - + $resqlcontact = $db->query($sqlcontact); if ($resqlcontact) { while($objcontact = $db->fetch_object($resqlcontact)) { - //print $objcontact->code.'-'.$objcontact->fk_socpeople."\n"; + //print $objcontact->code.'-'.$objcontact->fk_socpeople."\n"; $object->add_contact($objcontact->fk_socpeople, $objcontact->code); } } - else dol_print_error($resqlcontact); - } + else dol_print_error($resqlcontact); + } } else { setEventMessages($object->error, $object->errors, 'errors'); $error ++; } - } - else + } + else { // If some invoice's lines coming from page $id = $object->create($user); @@ -1317,7 +1317,7 @@ if (empty($reshook)) // Ecrase $txtva par celui du produit // Ecrase $base_price_type par celui du produit // Replaces $fk_unit with the product's - if (! empty($idprod)) + if (! empty($idprod)) { $prod = new Product($db); $prod->fetch($idprod); @@ -1328,7 +1328,7 @@ if (empty($reshook)) $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; @@ -1375,13 +1375,13 @@ if (empty($reshook)) } // 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) + elseif ($tva_tx != $prod->tva_tx) { - if ($price_base_type != 'HT') + if ($price_base_type != 'HT') { $pu_ht = price2num($pu_ttc / (1 + ($tva_tx / 100)), 'MU'); } - else + else { $pu_ttc = price2num($pu_ht * (1 + ($tva_tx / 100)), 'MU'); } @@ -1443,7 +1443,7 @@ if (empty($reshook)) // 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; @@ -1546,7 +1546,7 @@ if (empty($reshook)) // Add buying price $fournprice = price2num(GETPOST('fournprice') ? GETPOST('fournprice') : ''); $buyingprice = price2num(GETPOST('buying_price') != '' ? GETPOST('buying_price') : ''); // If buying_price is '0', we muste keep this value - + // Extrafields $extrafieldsline = new ExtraFields($db); $extralabelsline = $extrafieldsline->fetch_name_optionals_label($object->table_element_line); @@ -2028,7 +2028,7 @@ if ($action == 'create') { $invoice_predefined = new FactureRec($db); $invoice_predefined->fetch(GETPOST('fac_rec','int')); - + $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; @@ -2983,7 +2983,7 @@ else if ($id > 0 || ! empty($ref)) // Remise dispo de type avoir if (! $absolute_discount) print '
'; - // $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filtercreditnote, $resteapayer + // $form->form_remise_dispo($_SERVER["PHP_SELF"].'?facid='.$object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filtercreditnote, $resteapayer $more=' ('.$addcreditnote.')'; $form->form_remise_dispo($_SERVER["PHP_SELF"] . '?facid=' . $object->id, 0, 'remise_id_for_payment', $soc->id, $absolute_creditnote, $filtercreditnote, 0, $more); // We allow credit note even if amount is higher } @@ -3316,7 +3316,7 @@ else if ($id > 0 || ! empty($ref)) 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 ''; @@ -3754,7 +3754,7 @@ else if ($id > 0 || ! empty($ref)) print '
'; } } - + // Create a credit note if (($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA) && $object->statut > 0 && $user->rights->facture->creer) { @@ -3912,7 +3912,7 @@ else if ($id > 0 || ! empty($ref)) { include DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php'; $formmail->frommail=dolAddEmailTrackId($formmail->frommail, 'inv'.$object->id); - } + } $formmail->withfrom = 1; $liste = array(); foreach ($object->thirdparty->thirdparty_and_contact_email_array(1) as $key => $value) { From 07b6c991ffed763e946d9fe6faae0664d9c5395c Mon Sep 17 00:00:00 2001 From: Sergio Sanchis Climent Date: Tue, 19 Jul 2016 12:57:23 +0200 Subject: [PATCH 160/379] Create CommandeFournisseurLigne->insert Create SupplierInvoiceLine->insert --- .../class/fournisseur.commande.class.php | 638 ++++++++++++------ .../fourn/class/fournisseur.facture.class.php | 381 ++++++++--- htdocs/fourn/facture/card.php | 3 +- 3 files changed, 710 insertions(+), 312 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 306dfbbb9a7..f91a7edab67 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -50,89 +50,89 @@ class CommandeFournisseur extends CommonOrder */ protected $table_ref_field = 'ref'; - var $id; + public $id; /** * Supplier order reference * @var string */ - var $ref; - var $ref_supplier; - var $brouillon; - var $statut; // 0=Draft -> 1=Validated -> 2=Approved -> 3=Process runing -> 4=Received partially -> 5=Received totally -> (reopen) 4=Received partially + public $ref; + public $ref_supplier; + public $brouillon; + public $statut; // 0=Draft -> 1=Validated -> 2=Approved -> 3=Process runing -> 4=Received partially -> 5=Received totally -> (reopen) 4=Received partially // -> 7=Canceled/Never received -> (reopen) 3=Process runing // -> 6=Canceled -> (reopen) 2=Approved // -> 9=Refused -> (reopen) 1=Validated // Note: billed or not is on another field "billed" - var $statuts; // List of status - - var $socid; - var $fourn_id; - var $date; - var $date_valid; - var $date_approve; - var $date_approve2; // Used when SUPPLIER_ORDER_DOUBLE_APPROVAL is set - var $date_commande; + public $statuts; // List of status + + public $socid; + public $fourn_id; + public $date; + public $date_valid; + public $date_approve; + public $date_approve2; // Used when SUPPLIER_ORDER_DOUBLE_APPROVAL is set + public $date_commande; /** * Delivery date */ - var $date_livraison; - var $total_ht; - var $total_tva; - var $total_localtax1; // Total Local tax 1 - var $total_localtax2; // Total Local tax 2 - var $total_ttc; - var $source; + public $date_livraison; + public $total_ht; + public $total_tva; + public $total_localtax1; // Total Local tax 1 + public $total_localtax2; // Total Local tax 2 + public $total_ttc; + public $source; /** * @deprecated * @see note_private, note_public */ - var $note; + public $note; public $note_private; public $note_public; - var $model_pdf; - var $fk_project; - var $cond_reglement_id; - var $cond_reglement_code; - var $fk_account; - var $mode_reglement_id; - var $mode_reglement_code; - var $user_author_id; - var $user_valid_id; - var $user_approve_id; - var $user_approve_id2; // Used when SUPPLIER_ORDER_DOUBLE_APPROVAL is set + public $model_pdf; + public $fk_project; + public $cond_reglement_id; + public $cond_reglement_code; + public $fk_account; + public $mode_reglement_id; + public $mode_reglement_code; + public $user_author_id; + public $user_valid_id; + public $user_approve_id; + public $user_approve_id2; // Used when SUPPLIER_ORDER_DOUBLE_APPROVAL is set //Incoterms - var $fk_incoterms; - var $location_incoterms; - var $libelle_incoterms; //Used into tooltip + public $fk_incoterms; + public $location_incoterms; + public $libelle_incoterms; //Used into tooltip - var $extraparams=array(); + public $extraparams=array(); /** * @var CommandeFournisseurLigne[] */ public $lines = array(); //Add for supplier_proposal - var $origin; - var $origin_id; - var $linked_objects=array(); + public $origin; + public $origin_id; + public $linked_objects=array(); // Multicurrency - var $fk_multicurrency; - var $multicurrency_code; - var $multicurrency_tx; - var $multicurrency_total_ht; - var $multicurrency_total_tva; - var $multicurrency_total_ttc; + public $fk_multicurrency; + public $multicurrency_code; + public $multicurrency_tx; + public $multicurrency_total_ht; + public $multicurrency_total_tva; + public $multicurrency_total_ttc; /** * Constructor * * @param DoliDB $db Database handler */ - function __construct($db) + public function __construct($db) { global $conf; @@ -161,7 +161,7 @@ class CommandeFournisseur extends CommonOrder * @param string $ref Ref of object * @return int >0 if OK, <0 if KO, 0 if not found */ - function fetch($id,$ref='') + public function fetch($id,$ref='') { global $conf; @@ -373,7 +373,7 @@ class CommandeFournisseur extends CommonOrder * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, >0 if OK */ - function valid($user,$idwarehouse=0,$notrigger=0) + public function valid($user,$idwarehouse=0,$notrigger=0) { global $langs,$conf; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -492,7 +492,7 @@ class CommandeFournisseur extends CommonOrder * @param int $mode 0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=short label + picto * @return string Label */ - function getLibStatut($mode=0) + public function getLibStatut($mode=0) { return $this->LibStatut($this->statut,$mode,$this->billed); } @@ -584,7 +584,7 @@ class CommandeFournisseur extends CommonOrder * @param string $option On what the link points * @return string Chain with URL */ - function getNomUrl($withpicto=0,$option='') + public function getNomUrl($withpicto=0,$option='') { global $langs, $conf; @@ -620,7 +620,7 @@ class CommandeFournisseur extends CommonOrder * @param Societe $soc company object * @return string free reference for the invoice */ - function getNextNumRef($soc) + public function getNextNumRef($soc) { global $db, $langs, $conf; $langs->load("orders"); @@ -674,8 +674,9 @@ class CommandeFournisseur extends CommonOrder * @param User $user Object user making the change * @return int <0 if KO, >0 if KO */ - function classifyBilled(User $user) + public function classifyBilled(User $user) { + $error=0; $this->db->begin(); $sql = 'UPDATE '.MAIN_DB_PREFIX.'commande_fournisseur SET billed = 1'; @@ -720,7 +721,7 @@ class CommandeFournisseur extends CommonOrder * @param int $secondlevel 0=Standard approval, 1=Second level approval (used when option SUPPLIER_ORDER_DOUBLE_APPROVAL is set) * @return int <0 if KO, >0 if OK */ - function approve($user, $idwarehouse=0, $secondlevel=0) + public function approve($user, $idwarehouse=0, $secondlevel=0) { global $langs,$conf; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -805,6 +806,7 @@ class CommandeFournisseur extends CommonOrder // Product with reference if ($this->lines[$i]->fk_product > 0) { + $this->line = $this->lines[$i]; $mouvP = new MouvementStock($this->db); $mouvP->origin = &$this; // We decrement stock of product (and sub-products) @@ -812,6 +814,7 @@ class CommandeFournisseur extends CommonOrder if (! empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) $up_ht_disc=price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100, 'MU'); $result=$mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans("OrderApprovedInDolibarr",$this->ref)); if ($result < 0) { $error++; } + unset($this->line); } } } @@ -870,7 +873,7 @@ class CommandeFournisseur extends CommonOrder * @param User $user User making action * @return int 0 if Ok, <0 if Ko */ - function refuse($user) + public function refuse($user) { global $conf, $langs; @@ -988,7 +991,7 @@ class CommandeFournisseur extends CommonOrder * @param string $comment Comment * @return int <0 if KO, >0 if OK */ - function commande($user, $date, $methode, $comment='') + public function commande($user, $date, $methode, $comment='') { global $langs; dol_syslog(get_class($this)."::commande"); @@ -1046,7 +1049,7 @@ class CommandeFournisseur extends CommonOrder * @param int $notrigger Disable all triggers * @return int <0 if KO, Id of supplier order if OK */ - function create($user, $notrigger=0) + public function create($user, $notrigger=0) { global $langs,$conf,$hookmanager; @@ -1217,7 +1220,7 @@ class CommandeFournisseur extends CommonOrder * * @return int New id of clone */ - function createFromClone() + public function createFromClone() { global $conf,$user,$langs,$hookmanager; @@ -1304,7 +1307,7 @@ class CommandeFournisseur extends CommonOrder * @param string $fk_unit Code of the unit to use. Null to use the default one * @return int <=0 if KO, >0 if OK */ - function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $fk_product=0, $fk_prod_fourn_price=0, $fourn_ref='', $remise_percent=0.0, $price_base_type='HT', $pu_ttc=0.0, $type=0, $info_bits=0, $notrigger=false, $date_start=null, $date_end=null, $array_options=0, $fk_unit=null) + public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1=0.0, $txlocaltax2=0.0, $fk_product=0, $fk_prod_fourn_price=0, $fourn_ref='', $remise_percent=0.0, $price_base_type='HT', $pu_ttc=0.0, $type=0, $info_bits=0, $notrigger=false, $date_start=null, $date_end=null, $array_options=0, $fk_unit=null) { global $langs,$mysoc,$conf; @@ -1420,77 +1423,80 @@ 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,"; - $sql.= " qty, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice, ref,"; - $sql.= " total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_unit,"; - $sql.= " fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc"; - $sql.= ")"; - $sql.= " VALUES (".$this->id.", '" . $this->db->escape($label) . "','" . $this->db->escape($desc) . "',"; - $sql.= " ".($date_start?"'".$this->db->idate($date_start)."'":"null").","; - $sql.= " ".($date_end?"'".$this->db->idate($date_end)."'":"null").","; - if ($fk_product) { $sql.= $fk_product.","; } - else { $sql.= "null,"; } - $sql.= "'".$product_type."',"; - $sql.= "'".$qty."', ".$txtva.", ".$txlocaltax1.", ".$txlocaltax2; + // Insert line + $this->line=new CommandeFournisseurLigne($this->db); - $sql.= ", '".$localtax1_type."',"; - $sql.= " '".$localtax2_type."'"; + $this->line->context = $this->context; - $sql.= ", ".$remise_percent.",'".price2num($subprice,'MU')."','".$ref."',"; - $sql.= "'".price2num($total_ht)."',"; - $sql.= "'".price2num($total_tva)."',"; - $sql.= "'".price2num($total_localtax1)."',"; - $sql.= "'".price2num($total_localtax2)."',"; - $sql.= "'".price2num($total_ttc)."',"; - $sql.= ($fk_unit ? "'".$this->db->escape($fk_unit)."'":"null"); - $sql.= ", ".$this->fk_multicurrency; - $sql.= ", '".$this->db->escape($this->multicurrency_code)."'"; - $sql.= ", ".price2num($pu_ht * $this->multicurrency_tx); - $sql.= ", ".$multicurrency_total_ht; - $sql.= ", ".$multicurrency_total_tva; - $sql.= ", ".$multicurrency_total_ttc; - $sql.= ")"; + $this->line->fk_commande=$this->id; + $this->line->label=$label; + $this->line->desc=$desc; + $this->line->qty=$qty; + $this->line->tva_tx=$txtva; + $this->line->localtax1_tx=$txlocaltax1; + $this->line->localtax2_tx=$txlocaltax2; + $this->line->localtax1_type = $localtaxes_type[0]; + $this->line->localtax2_type = $localtaxes_type[2]; + $this->line->fk_product=$fk_product; + $this->line->product_type=$product_type; + $this->line->remise_percent=$remise_percent; + $this->line->subprice=$pu_ht; + $this->line->rang=$this->rang; + $this->line->info_bits=$info_bits; + $this->line->total_ht=$total_ht; + $this->line->total_tva=$total_tva; + $this->line->total_localtax1=$total_localtax1; + $this->line->total_localtax2=$total_localtax2; + $this->line->total_ttc=$total_ttc; + $this->line->product_type=$type; + $this->line->special_code=$this->special_code; + $this->line->origin=$this->origin; + $this->line->fk_unit=$fk_unit; - $resql=$this->db->query($sql); - //print $sql; - if ($resql) + $this->line->date_start=$date_start; + $this->line->date_end=$date_end; + + + // Multicurrency + $this->line->fk_multicurrency = $this->fk_multicurrency; + $this->line->multicurrency_code = $this->multicurrency_code; + $this->line->multicurrency_subprice = price2num($pu_ht * $this->multicurrency_tx); + $this->line->multicurrency_total_ht = $multicurrency_total_ht; + $this->line->multicurrency_total_tva = $multicurrency_total_tva; + $this->line->multicurrency_total_ttc = $multicurrency_total_ttc; + + $this->line->subprice=$pu; + $this->line->price=$this->line->subprice; + + $this->line->remise_percent=$remise_percent; + + if (is_array($array_options) && count($array_options)>0) { + $this->line->array_options=$array_options; + } + + $result=$this->line->insert($notrigger); + if ($result > 0) { - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used - { - $linetmp = new CommandeFournisseurLigne($this->db); - $linetmp->id=$this->db->last_insert_id(MAIN_DB_PREFIX.'commande_fournisseurdet'); - $linetmp->array_options = $array_options; - $result=$linetmp->insertExtraFields(); - if ($result < 0) - { - $error++; - } - } + // Reorder if child line + if (! empty($fk_parent_line)) $this->line_order(true,'DESC'); - if (! $error && ! $notrigger) + // Mise a jour informations denormalisees au niveau de la commande meme + $result=$this->update_price(1,'auto'); // This method is designed to add line from user input so total calculation must be done using 'auto' mode. + if ($result > 0) { - global $conf, $langs, $user; - // Call trigger - $result=$this->call_trigger('LINEORDER_SUPPLIER_CREATE',$user); - if ($result < 0) - { - $this->db->rollback(); - return -1; - } - // End call triggers + $this->db->commit(); + return $this->line->id; + } + else + { + $this->db->rollback(); + return -1; } - - $this->update_price('','auto'); - - $this->db->commit(); - return 1; } else { - $this->error=$this->db->error(); + $this->error=$this->line->error; + dol_syslog(get_class($this)."::addline error=".$this->error, LOG_ERR); $this->db->rollback(); return -1; } @@ -1514,7 +1520,7 @@ class CommandeFournisseur extends CommonOrder * @param int $notrigger 1 = notrigger * @return int <0 if KO, >0 if OK */ - function dispatchProduct($user, $product, $qty, $entrepot, $price=0, $comment='', $eatby='', $sellby='', $batch='', $fk_commandefourndet=0, $notrigger=0) + public function dispatchProduct($user, $product, $qty, $entrepot, $price=0, $comment='', $eatby='', $sellby='', $batch='', $fk_commandefourndet=0, $notrigger=0) { global $conf, $langs; @@ -1616,9 +1622,10 @@ class CommandeFournisseur extends CommonOrder * @param int $notrigger 1=Disable call to triggers * @return <0 if KO, >0 if OK */ - function deleteline($idline, $notrigger=0) + public function deleteline($idline, $notrigger=0) { global $user,$langs,$conf; + $error = 0; if ($this->statut != 0) { @@ -1671,7 +1678,7 @@ class CommandeFournisseur extends CommonOrder * @param User $user Object user * @return int <0 if KO, >0 if OK */ - function delete($user='') + public function delete($user='') { global $langs,$conf; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -1822,7 +1829,7 @@ class CommandeFournisseur extends CommonOrder * @param int $status Filter on stats (-1 = no filter, 0 = lines draft to be approved, 1 = approved lines) * @return array Array of lines */ - function getDispachedLines($status=-1) + public function getDispachedLines($status=-1) { $ret = array(); @@ -2048,7 +2055,7 @@ class CommandeFournisseur extends CommonOrder * @param int $comclientid Id of customer order to use as template * @return int <0 if KO, >0 if OK */ - function updateFromCommandeClient($user, $idc, $comclientid) + public function updateFromCommandeClient($user, $idc, $comclientid) { $comclient = new Commande($this->db); $comclient->fetch($comclientid); @@ -2089,7 +2096,7 @@ class CommandeFournisseur extends CommonOrder * @param int $status New status * @return int <0 if KO, >0 if OK */ - function setStatus($user,$status) + public function setStatus($user,$status) { global $conf,$langs; $error=0; @@ -2147,12 +2154,14 @@ class CommandeFournisseur extends CommonOrder * @param string $fk_unit Code of the unit to use. Null to use the default one * @return int < 0 if error, > 0 if ok */ - function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type=0, $notrigger=false, $date_start='', $date_end='', $array_options=0, $fk_unit=null) + public function updateline($rowid, $desc, $pu, $qty, $remise_percent, $txtva, $txlocaltax1=0, $txlocaltax2=0, $price_base_type='HT', $info_bits=0, $type=0, $notrigger=false, $date_start='', $date_end='', $array_options=0, $fk_unit=null) { - global $mysoc; + global $mysoc, $conf; dol_syslog(get_class($this)."::updateline $rowid, $desc, $pu, $qty, $remise_percent, $txtva, $price_base_type, $info_bits, $type, $fk_unit"); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; + $error = 0; + if ($this->brouillon) { $this->db->begin(); @@ -2202,83 +2211,62 @@ class CommandeFournisseur extends CommonOrder $subprice = price2num($pu,'MU'); - // Mise a jour ligne en base - $sql = "UPDATE ".MAIN_DB_PREFIX."commande_fournisseurdet SET"; - $sql.= " description='".$this->db->escape($desc)."'"; - $sql.= ",subprice='".price2num($subprice)."'"; - //$sql.= ",remise='".price2num($remise)."'"; - $sql.= ",remise_percent='".price2num($remise_percent)."'"; - $sql.= ",tva_tx='".price2num($txtva)."'"; - $sql.= ",localtax1_tx='".price2num($txlocaltax1)."'"; - $sql.= ",localtax2_tx='".price2num($txlocaltax2)."'"; - $sql.= ",localtax1_type='".$localtax1_type."'"; - $sql.= ",localtax2_type='".$localtax2_type."'"; - $sql.= ",qty='".price2num($qty)."'"; - $sql.= ",date_start=".(! empty($date_start)?"'".$this->db->idate($date_start)."'":"null"); - $sql.= ",date_end=".(! empty($date_end)?"'".$this->db->idate($date_end)."'":"null"); - $sql.= ",info_bits='".$info_bits."'"; - $sql.= ",total_ht='".price2num($total_ht)."'"; - $sql.= ",total_tva='".price2num($total_tva)."'"; - $sql.= ",total_localtax1='".price2num($total_localtax1)."'"; - $sql.= ",total_localtax2='".price2num($total_localtax2)."'"; - $sql.= ",total_ttc='".price2num($total_ttc)."'"; - $sql.= ",product_type=".$type; - $sql.= ($fk_unit ? ",fk_unit='".$this->db->escape($fk_unit)."'":", fk_unit=null"); - - // Multicurrency - $sql.= " , multicurrency_subprice=".price2num($subprice * $this->multicurrency_tx).""; - $sql.= " , multicurrency_total_ht=".price2num($multicurrency_total_ht).""; - $sql.= " , multicurrency_total_tva=".price2num($multicurrency_total_tva).""; - $sql.= " , multicurrency_total_ttc=".price2num($multicurrency_total_ttc).""; - - $sql.= " WHERE rowid = ".$rowid; + $this->line=new CommandeFournisseurLigne($this->db); + $this->line->fetch($rowid); - dol_syslog(get_class($this)."::updateline", LOG_DEBUG); - $result = $this->db->query($sql); - if ($result > 0) + $this->line->context = $this->context; + + $this->line->fk_commande=$this->id; + //$this->line->label=$label; + $this->line->desc=$desc; + $this->line->qty=$qty; + $this->line->tva_tx=$txtva; + $this->line->localtax1_tx=$txlocaltax1; + $this->line->localtax2_tx=$txlocaltax2; + $this->line->localtax1_type = $localtaxes_type[0]; + $this->line->localtax2_type = $localtaxes_type[2]; + $this->line->remise_percent=$remise_percent; + $this->line->subprice=$pu; + $this->line->rang=$this->rang; + $this->line->info_bits=$info_bits; + $this->line->total_ht=$total_ht; + $this->line->total_tva=$total_tva; + $this->line->total_localtax1=$total_localtax1; + $this->line->total_localtax2=$total_localtax2; + $this->line->total_ttc=$total_ttc; + $this->line->product_type=$type; + $this->line->special_code=$this->special_code; + $this->line->origin=$this->origin; + $this->line->fk_unit=$fk_unit; + + $this->line->date_start=$date_start; + $this->line->date_end=$date_end; + + + // Multicurrency + $this->line->fk_multicurrency = $this->fk_multicurrency; + $this->line->multicurrency_code = $this->multicurrency_code; + $this->line->multicurrency_subprice = price2num($pu_ht * $this->multicurrency_tx); + $this->line->multicurrency_total_ht = $multicurrency_total_ht; + $this->line->multicurrency_total_tva = $multicurrency_total_tva; + $this->line->multicurrency_total_ttc = $multicurrency_total_ttc; + + $this->line->subprice=$pu; + $this->line->price=$this->line->subprice; + + $this->line->remise_percent=$remise_percent; + + if (is_array($array_options) && count($array_options)>0) { + $this->line->array_options=$array_options; + } + + $result=$this->line->update($notrigger); + + + // Mise a jour info denormalisees au niveau facture + if (! $error) { - $this->rowid = $rowid; - if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used - { - $tmpline = new CommandeFournisseurLigne($this->db); - $tmpline->id=$this->rowid; - $tmpline->array_options = $array_options; - $result=$tmpline->insertExtraFields(); - if ($result < 0) - { - $error++; - } - } - - if (! $error && ! $notrigger) - { - global $conf, $langs, $user; - // Call trigger - $result=$this->call_trigger('LINEORDER_SUPPLIER_UPDATE',$user); - if ($result < 0) - { - $this->db->rollback(); - return -1; - } - // End call triggers - } - - // Mise a jour info denormalisees au niveau facture - if (! $error) - { - $this->update_price('','auto'); - } - - if (! $error) - { - $this->db->commit(); - return $result; - } - else - { - $this->db->rollback(); - return -1; - } + $this->update_price('','auto'); } else { @@ -2303,7 +2291,7 @@ class CommandeFournisseur extends CommonOrder * * @return void */ - function initAsSpecimen() + public function initAsSpecimen() { global $user,$langs,$conf; @@ -2385,7 +2373,7 @@ class CommandeFournisseur extends CommonOrder * @param int $id Id de la facture a charger * @return void */ - function info($id) + public function info($id) { $sql = 'SELECT c.rowid, date_creation as datec, tms as datem, date_valid as date_validation, date_approve as datea, date_approve2 as datea2,'; $sql.= ' fk_user_author, fk_user_modif, fk_user_valid, fk_user_approve, fk_user_approve2'; @@ -2523,7 +2511,7 @@ class CommandeFournisseur extends CommonOrder * * @return string */ - function getInputMethod() + public function getInputMethod() { global $db, $langs; @@ -2593,7 +2581,7 @@ class CommandeFournisseur extends CommonOrder * @param Translate $langs Language object * @return Translated string */ - function getMaxDeliveryTimeDay($langs) + public function getMaxDeliveryTimeDay($langs) { if (empty($this->lines)) return ''; @@ -2689,17 +2677,31 @@ class CommandeFournisseur extends CommonOrder */ class CommandeFournisseurLigne extends CommonOrderLine { - public $element='commande_fournisseurdet'; + public $element='commande_fournisseurdet'; public $table_element='commande_fournisseurdet'; + public $oldline; + + /** + * Id of parent order + * @var int + */ + public $fk_commande; + + // From llx_commande_fournisseurdet + public $fk_parent_line; + public $fk_facture; + public $label; + public $rang = 0; + /** * Unit price without taxes * @var float */ public $pu_ht; - var $date_start; - var $date_end; + public $date_start; + public $date_end; // From llx_product_fournisseur_price @@ -2715,7 +2717,9 @@ class CommandeFournisseurLigne extends CommonOrderLine * Supplier reference * @var string */ - public $ref_supplier; + public $ref_supplier; + public $remise; + public $product_libelle; /** @@ -2723,7 +2727,7 @@ class CommandeFournisseurLigne extends CommonOrderLine * * @param DoliDB $db Database handler */ - function __construct($db) + public function __construct($db) { $this->db= $db; } @@ -2734,7 +2738,7 @@ class CommandeFournisseurLigne extends CommonOrderLine * @param int $rowid Id line order * @return int <0 if KO, >0 if OK */ - function fetch($rowid) + public function fetch($rowid) { $sql = 'SELECT cd.rowid, cd.fk_commande, cd.fk_product, cd.product_type, cd.description, cd.qty, cd.tva_tx,'; $sql.= ' cd.localtax1_tx, cd.localtax2_tx,'; @@ -2751,6 +2755,7 @@ class CommandeFournisseurLigne extends CommonOrderLine { $objp = $this->db->fetch_object($result); $this->rowid = $objp->rowid; + $this->id = $objp->rowid; $this->fk_commande = $objp->fk_commande; $this->desc = $objp->description; $this->qty = $objp->qty; @@ -2770,6 +2775,7 @@ class CommandeFournisseurLigne extends CommonOrderLine $this->product_type = $objp->product_type; $this->ref = $objp->product_ref; + $this->product_ref = $objp->product_ref; $this->product_libelle = $objp->product_libelle; $this->product_desc = $objp->product_desc; @@ -2792,7 +2798,7 @@ class CommandeFournisseurLigne extends CommonOrderLine * * @return int <0 si ko, >0 si ok */ - function update_total() + public function update_total() { $this->db->begin(); @@ -2820,5 +2826,209 @@ class CommandeFournisseurLigne extends CommonOrderLine return -2; } } + + /** + * Insert line into database + * + * @param int $notrigger 1 = disable triggers + * @return int <0 if KO, >0 if OK + */ + public function insert($notrigger=0) + { + global $conf, $user; + + $error=0; + + dol_syslog(get_class($this)."::insert rang=".$this->rang); + + // Clean parameters + if (empty($this->tva_tx)) $this->tva_tx=0; + if (empty($this->localtax1_tx)) $this->localtax1_tx=0; + if (empty($this->localtax2_tx)) $this->localtax2_tx=0; + if (empty($this->localtax1_type)) $this->localtax1_type=0; + if (empty($this->localtax2_type)) $this->localtax2_type=0; + if (empty($this->total_localtax1)) $this->total_localtax1=0; + if (empty($this->total_localtax2)) $this->total_localtax2=0; + if (empty($this->rang)) $this->rang=0; + if (empty($this->remise)) $this->remise=0; + if (empty($this->remise_percent)) $this->remise_percent=0; + if (empty($this->info_bits)) $this->info_bits=0; + if (empty($this->special_code)) $this->special_code=0; + if (empty($this->fk_parent_line)) $this->fk_parent_line=0; + if (empty($this->pa_ht)) $this->pa_ht=0; + + + // Check parameters + if ($this->product_type < 0) return -1; + + $this->db->begin(); + + // Insertion dans base de la ligne + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element; + $sql.= " (fk_commande, label, description, date_start, date_end,"; + $sql.= " fk_product, product_type,"; + $sql.= " qty, tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice, ref,"; + $sql.= " total_ht, total_tva, total_localtax1, total_localtax2, total_ttc, fk_unit,"; + $sql.= " fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc"; + $sql.= ")"; + $sql.= " VALUES (".$this->fk_commande.", '" . $this->db->escape($this->product_label) . "','" . $this->db->escape($this->desc) . "',"; + $sql.= " ".($this->date_start?"'".$this->db->idate($this->date_start)."'":"null").","; + $sql.= " ".($this->date_end?"'".$this->db->idate($this->date_end)."'":"null").","; + if ($this->fk_product) { $sql.= $this->fk_product.","; } + else { $sql.= "null,"; } + $sql.= "'".$this->product_type."',"; + $sql.= "'".$this->qty."', ".$this->tva_tx.", ".$this->localtax1_tx.", ".$this->localtax2_tx; + + $sql.= ", '".$this->localtax1_type."',"; + $sql.= " '".$this->localtax2_type."'"; + + $sql.= ", ".$this->remise_percent.",'".price2num($this->subprice,'MU')."','".$this->product_ref."',"; + $sql.= "'".price2num($this->total_ht)."',"; + $sql.= "'".price2num($this->total_tva)."',"; + $sql.= "'".price2num($this->total_localtax1)."',"; + $sql.= "'".price2num($this->total_localtax2)."',"; + $sql.= "'".price2num($this->total_ttc)."',"; + $sql.= ($this->fk_unit ? "'".$this->db->escape($this->fk_unit)."'":"null"); + $sql.= ", ".$this->fk_multicurrency; + $sql.= ", '".$this->db->escape($this->multicurrency_code)."'"; + $sql.= ", ".price2num($this->pu_ht * $this->multicurrency_tx); + $sql.= ", ".$this->multicurrency_total_ht; + $sql.= ", ".$this->multicurrency_total_tva; + $sql.= ", ".$this->multicurrency_total_ttc; + $sql.= ")"; + + dol_syslog(get_class($this)."::insert", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->rowid =$this->id; + + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + + $result=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + + if (! $error && ! $notrigger) + { + // Call trigger + $result=$this->call_trigger('LINEORDER_INSERT',$user); + if ($result < 0) $error++; + // End call triggers + } + + if (!$error) { + $this->db->commit(); + return 1; + } + + foreach($this->errors as $errmsg) + { + dol_syslog(get_class($this)."::delete ".$errmsg, LOG_ERR); + $this->errors[]=($this->errors?', '.$errmsg:$errmsg); + } + $this->db->rollback(); + return -1*$error; + } + else + { + $this->errors[]=$this->db->error(); + $this->db->rollback(); + return -2; + } + } + /** + * Update the line object into db + * + * @param int $notrigger 1 = disable triggers + * @return int <0 si ko, >0 si ok + */ + public function update($notrigger=0) + { + global $conf,$user; + + $error=0; + + // Mise a jour ligne en base + $sql = "UPDATE ".MAIN_DB_PREFIX.$this->table_element." SET"; + $sql.= " description='".$this->db->escape($this->desc)."'"; + $sql.= ",subprice='".price2num($this->subprice)."'"; + //$sql.= ",remise='".price2num($remise)."'"; + $sql.= ",remise_percent='".price2num($this->remise_percent)."'"; + $sql.= ",tva_tx='".price2num($this->tva_tx)."'"; + $sql.= ",localtax1_tx='".price2num($this->total_localtax1)."'"; + $sql.= ",localtax2_tx='".price2num($this->total_localtax2)."'"; + $sql.= ",localtax1_type='".$this->localtax1_type."'"; + $sql.= ",localtax2_type='".$this->localtax2_type."'"; + $sql.= ",qty='".price2num($this->qty)."'"; + $sql.= ",date_start=".(! empty($this->date_start)?"'".$this->db->idate($this->date_start)."'":"null"); + $sql.= ",date_end=".(! empty($this->date_end)?"'".$this->db->idate($this->date_end)."'":"null"); + $sql.= ",info_bits='".$this->info_bits."'"; + $sql.= ",total_ht='".price2num($this->total_ht)."'"; + $sql.= ",total_tva='".price2num($this->total_tva)."'"; + $sql.= ",total_localtax1='".price2num($this->total_localtax1)."'"; + $sql.= ",total_localtax2='".price2num($this->total_localtax2)."'"; + $sql.= ",total_ttc='".price2num($this->total_ttc)."'"; + $sql.= ",product_type=".$this->product_type; + $sql.= ($this->fk_unit ? ",fk_unit='".$this->db->escape($this->fk_unit)."'":", fk_unit=null"); + + // Multicurrency + $sql.= " , multicurrency_subprice=".price2num($this->subprice * $this->multicurrency_tx).""; + $sql.= " , multicurrency_total_ht=".price2num($this->multicurrency_total_ht).""; + $sql.= " , multicurrency_total_tva=".price2num($this->multicurrency_total_tva).""; + $sql.= " , multicurrency_total_ttc=".price2num($this->multicurrency_total_ttc).""; + + $sql.= " WHERE rowid = ".$this->id; + + dol_syslog(get_class($this)."::updateline", LOG_DEBUG); + $result = $this->db->query($sql); + if ($result > 0) + { + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + + $result=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + + if (! $error && ! $notrigger) + { + global $user; + // Call trigger + $result=$this->call_trigger('LINEORDER_SUPPLIER_UPDATE',$user); + if ($result < 0) + { + $this->db->rollback(); + return -1; + } + // End call triggers + } + + if (! $error) + { + $this->db->commit(); + return $result; + } + else + { + $this->db->rollback(); + return -1; + } + } + else + { + $this->error=$this->db->lasterror(); + $this->db->rollback(); + return -1; + } + } } diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index 8c1a86b03a5..aab90ce4b49 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -50,57 +50,57 @@ class FactureFournisseur extends CommonInvoice */ protected $table_ref_field = 'ref'; - var $rowid; - var $ref; - var $product_ref; - var $ref_supplier; - var $socid; + public $rowid; + public $ref; + public $product_ref; + public $ref_supplier; + public $socid; //Check constants for types - var $type = self::TYPE_STANDARD; + public $type = self::TYPE_STANDARD; /** * Supplier invoice status * @var int * @see FactureFournisseur::STATUS_DRAFT, FactureFournisseur::STATUS_VALIDATED, FactureFournisseur::STATUS_PAID, FactureFournisseur::STATUS_ABANDONED */ - var $statut; + public $statut; /** * Set to 1 if the invoice is completely paid, otherwise is 0 * @var int * @deprecated Use statuses stored in self::statut */ - var $paye; + public $paye; - var $author; - var $libelle; - var $datec; // Creation date - var $tms; // Last update date - var $date; // Invoice date - var $date_echeance; // Max payment date - var $amount; - var $remise; - var $tva; - var $localtax1; - var $localtax2; - var $total_ht; - var $total_tva; - var $total_localtax1; - var $total_localtax2; - var $total_ttc; + public $author; + public $libelle; + public $datec; // Creation date + public $tms; // Last update date + public $date; // Invoice date + public $date_echeance; // Max payment date + public $amount; + public $remise; + public $tva; + public $localtax1; + public $localtax2; + public $total_ht; + public $total_tva; + public $total_localtax1; + public $total_localtax2; + public $total_ttc; /** * @deprecated * @see note_private, note_public */ - var $note; - var $note_private; - var $note_public; - var $propalid; - var $cond_reglement_id; - var $cond_reglement_code; - var $fk_account; - var $mode_reglement_id; - var $mode_reglement_code; + public $note; + public $note_private; + public $note_public; + public $propalid; + public $cond_reglement_id; + public $cond_reglement_code; + public $fk_account; + public $mode_reglement_id; + public $mode_reglement_code; /** * Invoice lines @@ -110,29 +110,29 @@ class FactureFournisseur extends CommonInvoice /** * @deprecated */ - var $fournisseur; + public $fournisseur; //Incorterms - var $fk_incoterms; - var $location_incoterms; - var $libelle_incoterms; //Used into tooltip + public $fk_incoterms; + public $location_incoterms; + public $libelle_incoterms; //Used into tooltip - var $extraparams=array(); + public $extraparams=array(); // Multicurrency - var $fk_multicurrency; - var $multicurrency_code; - var $multicurrency_tx; - var $multicurrency_total_ht; - var $multicurrency_total_tva; - var $multicurrency_total_ttc; + public $fk_multicurrency; + public $multicurrency_code; + public $multicurrency_tx; + public $multicurrency_total_ht; + public $multicurrency_total_tva; + public $multicurrency_total_ttc; /** * Constructor * * @param DoliDB $db Database handler */ - function __construct($db) + public function __construct($db) { $this->db = $db; @@ -155,7 +155,7 @@ class FactureFournisseur extends CommonInvoice * @param User $user object utilisateur qui cree * @return int id facture si ok, < 0 si erreur */ - function create($user) + public function create($user) { global $langs,$conf,$hookmanager; @@ -355,7 +355,7 @@ class FactureFournisseur extends CommonInvoice * @param string $ref Ref supplier invoice * @return int <0 if KO, >0 if OK, 0 if not found */ - function fetch($id='',$ref='') + public function fetch($id='',$ref='') { global $langs; @@ -613,7 +613,7 @@ class FactureFournisseur extends CommonInvoice * @param int $notrigger 0=launch triggers after, 1=disable triggers * @return int <0 if KO, >0 if OK */ - function update($user=null, $notrigger=0) + public function update($user=null, $notrigger=0) { global $conf, $langs; $error=0; @@ -741,7 +741,7 @@ class FactureFournisseur extends CommonInvoice * @param int $rowid Id of invoice to delete * @return int <0 if KO, >0 if OK */ - function delete($rowid) + public function delete($rowid) { global $user,$langs,$conf; @@ -955,7 +955,7 @@ class FactureFournisseur extends CommonInvoice * @param int $notrigger 1=Does not execute triggers, 0= execuete triggers * @return int <0 if KO, =0 if nothing to do, >0 if OK */ - function validate($user, $force_number='', $idwarehouse=0, $notrigger=0) + public function validate($user, $force_number='', $idwarehouse=0, $notrigger=0) { global $conf,$langs; @@ -1011,6 +1011,7 @@ class FactureFournisseur extends CommonInvoice { if ($this->lines[$i]->fk_product > 0) { + $this->line = $this->lines[$i]; $mouvP = new MouvementStock($this->db); $mouvP->origin = &$this; // We increase stock for product @@ -1018,6 +1019,7 @@ class FactureFournisseur extends CommonInvoice if (! empty($this->lines[$i]->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) $up_ht_disc=price2num($up_ht_disc * (100 - $this->lines[$i]->remise_percent) / 100, 'MU'); $result=$mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans("InvoiceValidatedInDolibarr",$num)); if ($result < 0) { $error++; } + unset($this->line); } } } @@ -1194,14 +1196,16 @@ class FactureFournisseur extends CommonInvoice * @param int $notrigger Disable triggers * @param array $array_options extrafields array * @param string $fk_unit Code of the unit to use. Null to use the default one + * @param int $origin_id id origin document * @return int >0 if OK, <0 if KO * * FIXME Add field ref (that should be named ref_supplier) and label into update. For example can be filled when product line created from order. */ - function addline($desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0, $rang=-1, $notrigger=false, $array_options=0, $fk_unit=null) + public function addline($desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product=0, $remise_percent=0, $date_start='', $date_end='', $ventil=0, $info_bits='', $price_base_type='HT', $type=0, $rang=-1, $notrigger=false, $array_options=0, $fk_unit=null, $origin_id=0) { dol_syslog(get_class($this)."::addline $desc,$pu,$qty,$txtva,$fk_product,$remise_percent,$date_start,$date_end,$ventil,$info_bits,$price_base_type,$type,$fk_unit", LOG_DEBUG); include_once DOL_DOCUMENT_ROOT.'/core/lib/price.lib.php'; + global $mysoc; // Clean parameters if (empty($remise_percent)) $remise_percent=0; @@ -1220,52 +1224,92 @@ class FactureFournisseur extends CommonInvoice $txlocaltax1=price2num($txlocaltax1); $txlocaltax2=price2num($txlocaltax2); + $localtaxes_type=getLocalTaxesFromRate($txtva,0,$mysoc, $this->thirdparty); + + $tabprice = calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, $type, $this->thirdparty, $localtaxes_type, 100, $this->multicurrency_tx); + $total_ht = $tabprice[0]; + $total_tva = $tabprice[1]; + $total_ttc = $tabprice[2]; + $total_localtax1 = $tabprice[9]; + $total_localtax2 = $tabprice[10]; + + // MultiCurrency + $multicurrency_total_ht = $tabprice[16]; + $multicurrency_total_tva = $tabprice[17]; + $multicurrency_total_ttc = $tabprice[18]; + // Check parameters if ($type < 0) return -1; + // Insert line + $this->line=new SupplierInvoiceLine($this->db); - $this->db->begin(); + $this->line->context = $this->context; - $sql = 'INSERT INTO '.MAIN_DB_PREFIX.'facture_fourn_det (fk_facture_fourn)'; - $sql.= ' VALUES ('.$this->id.')'; - dol_syslog(get_class($this)."::addline", LOG_DEBUG); + $this->line->fk_facture_fourn=$this->id; + //$this->line->label=$label; // deprecated + $this->line->desc=$desc; + $this->line->qty= ($this->type==self::TYPE_CREDIT_NOTE?abs($qty):$qty); // For credit note, quantity is always positive and unit price negative + $this->line->tva_tx=$txtva; + $this->line->localtax1_tx=$txlocaltax1; + $this->line->localtax2_tx=$txlocaltax2; + $this->line->fk_product=$fk_product; + $this->line->product_type=$type; + $this->line->remise_percent=$remise_percent; + $this->line->subprice= ($this->type==self::TYPE_CREDIT_NOTE?-abs($pu):$pu); // For credit note, unit price always negative, always positive otherwise + $this->line->date_start=$date_start; + $this->line->date_end=$date_end; + $this->line->ventil=$ventil; + $this->line->rang=$rang; + $this->line->info_bits=$info_bits; + $this->line->total_ht= (($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_ht):$total_ht); // For credit note and if qty is negative, total is negative + $this->line->total_tva= $total_tva; + $this->line->total_localtax1=$total_localtax1; + $this->line->total_localtax2=$total_localtax2; + $this->line->localtax1_type = $localtaxes_type[0]; + $this->line->localtax2_type = $localtaxes_type[2]; + $this->line->total_ttc= (($this->type==self::TYPE_CREDIT_NOTE||$qty<0)?-abs($total_ttc):$total_ttc); + $this->line->special_code=$this->special_code; + $this->line->fk_parent_line=$this->fk_parent_line; + $this->line->origin=$this->origin; + $this->line->origin_id=$origin_id; + $this->line->fk_unit=$fk_unit; - $resql = $this->db->query($sql); - if ($resql) + // Multicurrency + $this->line->fk_multicurrency = $this->fk_multicurrency; + $this->line->multicurrency_code = $this->multicurrency_code; + $this->line->multicurrency_subprice = price2num($this->line->subprice * $this->multicurrency_tx); + $this->line->multicurrency_total_ht = $multicurrency_total_ht; + $this->line->multicurrency_total_tva = $multicurrency_total_tva; + $this->line->multicurrency_total_ttc = $multicurrency_total_ttc; + + if (is_array($array_options) && count($array_options)>0) { + $this->line->array_options=$array_options; + } + + $result=$this->line->insert($notrigger); + if ($result > 0) { - $idligne = $this->db->last_insert_id(MAIN_DB_PREFIX.'facture_fourn_det'); + // Reorder if child line + if (! empty($fk_parent_line)) $this->line_order(true,'DESC'); - $result=$this->updateline($idligne, $desc, $pu, $txtva, $txlocaltax1, $txlocaltax2, $qty, $fk_product, $price_base_type, $info_bits, $type, $remise_percent, true, '', '', $array_options, $fk_unit); + // Mise a jour informations denormalisees au niveau de la facture meme + $result=$this->update_price(1,'auto',0,$mysoc); // The addline method is designed to add line from user input so total calculation with update_price must be done using 'auto' mode. if ($result > 0) { - $this->rowid = $idligne; - - if (! $notrigger) - { - global $conf, $langs, $user; - // Call trigger - $result=$this->call_trigger('LINEBILL_SUPPLIER_CREATE',$user); - if ($result < 0) - { - $this->db->rollback(); - return -1; - } - // End call triggers - } - $this->db->commit(); - return 1; + return $this->line->id; } else { - dol_syslog("Error after updateline error=".$this->error, LOG_ERR); + $this->error=$this->db->error(); $this->db->rollback(); return -1; } } else { - $this->error=$this->db->lasterror(); + $this->error=$this->line->error; $this->db->rollback(); return -2; } @@ -1293,7 +1337,7 @@ class FactureFournisseur extends CommonInvoice * @param string $fk_unit Code of the unit to use. Null to use the default one * @return int <0 if KO, >0 if OK */ - function updateline($id, $desc, $pu, $vatrate, $txlocaltax1=0, $txlocaltax2=0, $qty=1, $idproduct=0, $price_base_type='HT', $info_bits=0, $type=0, $remise_percent=0, $notrigger=false, $date_start='', $date_end='', $array_options=0, $fk_unit = null) + public function updateline($id, $desc, $pu, $vatrate, $txlocaltax1=0, $txlocaltax2=0, $qty=1, $idproduct=0, $price_base_type='HT', $info_bits=0, $type=0, $remise_percent=0, $notrigger=false, $date_start='', $date_end='', $array_options=0, $fk_unit = null) { global $mysoc; dol_syslog(get_class($this)."::updateline $id,$desc,$pu,$vatrate,$qty,$idproduct,$price_base_type,$info_bits,$type,$remise_percent,$fk_unit", LOG_DEBUG); @@ -1315,6 +1359,8 @@ class FactureFournisseur extends CommonInvoice $txlocaltax1=price2num($txlocaltax1); $txlocaltax2=price2num($txlocaltax2); + $localtaxes_type = array($txlocaltax1,$txlocaltax2); + // Calcul du total TTC et de la TVA pour la ligne a partir de // qty, pu, remise_percent et txtva // TRES IMPORTANT: C'est au moment de l'insertion ligne qu'on doit stocker @@ -1404,7 +1450,7 @@ class FactureFournisseur extends CommonInvoice * @param int $notrigger 1=Does not execute triggers, 0= execute triggers * @return int <0 if KO, >0 if OK */ - function deleteline($rowid, $notrigger=0) + public function deleteline($rowid, $notrigger=0) { if (!$rowid) { $rowid = $this->id; @@ -1434,7 +1480,7 @@ class FactureFournisseur extends CommonInvoice * @param int $id Id de la facture a charger * @return void */ - function info($id) + public function info($id) { $sql = 'SELECT c.rowid, datec, tms as datem, '; $sql.= ' fk_user_author, fk_user_modif, fk_user_valid'; @@ -1543,9 +1589,9 @@ class FactureFournisseur extends CommonInvoice * @param int $max Max length of shown ref * @return string Chaine avec URL */ - function getNomUrl($withpicto=0,$option='',$max=0) + public function getNomUrl($withpicto=0,$option='',$max=0) { - global $langs; + global $langs, $conf; $result=''; $label = '' . $langs->trans("ShowSupplierInvoice") . ''; @@ -1587,7 +1633,7 @@ class FactureFournisseur extends CommonInvoice * @param string $mode 'next' for next value or 'last' for last value * @return string free ref or last ref */ - function getNextNumRef($soc,$mode='next') + public function getNextNumRef($soc,$mode='next') { global $db, $langs, $conf; $langs->load("orders"); @@ -1640,7 +1686,7 @@ class FactureFournisseur extends CommonInvoice * * @return void */ - function initAsSpecimen() + public function initAsSpecimen() { global $langs,$conf; include_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; @@ -1780,7 +1826,7 @@ class FactureFournisseur extends CommonInvoice * @param int $invertdetail Reverse sign of amounts for lines * @return int New id of clone */ - function createFromClone($fromid,$invertdetail=0) + public function createFromClone($fromid,$invertdetail=0) { global $user,$langs; @@ -1942,7 +1988,7 @@ class SupplierInvoiceLine extends CommonObjectLine public $element='facture_fourn_det'; public $table_element='facture_fourn_det'; - var $oldline; + public $oldline; /** * @deprecated @@ -1999,22 +2045,22 @@ class SupplierInvoiceLine extends CommonObjectLine * Id of the corresponding supplier invoice * @var int */ - var $fk_facture_fourn; + public $fk_facture_fourn; /** * Product label * This field may contains label of product (when invoice create from order) * @var string */ - var $label; + public $label; /** * Description of the line * @var string */ - var $description; + public $description; - var $skip_update_total; // Skip update price total for special lines + public $skip_update_total; // Skip update price total for special lines /** * @var int Situation advance percentage @@ -2046,19 +2092,19 @@ class SupplierInvoiceLine extends CommonObjectLine public $localtax2_type; // Multicurrency - var $fk_multicurrency; - var $multicurrency_code; - var $multicurrency_subprice; - var $multicurrency_total_ht; - var $multicurrency_total_tva; - var $multicurrency_total_ttc; + public $fk_multicurrency; + public $multicurrency_code; + public $multicurrency_subprice; + public $multicurrency_total_ht; + public $multicurrency_total_tva; + public $multicurrency_total_ttc; /** * Constructor * * @param DoliDB $db Database handler */ - function __construct($db) + public function __construct($db) { $this->db= $db; } @@ -2292,5 +2338,146 @@ class SupplierInvoiceLine extends CommonObjectLine $this->db->commit(); return 1; } + + /** + * Insert line into database + * + * @param int $notrigger 1 no triggers + * @return int <0 if KO, >0 if OK + */ + public function insert($notrigger=0) + { + global $user,$conf; + + $error=0; + + dol_syslog(get_class($this)."::insert rang=".$this->rang, LOG_DEBUG); + + // Clean parameters + $this->desc=trim($this->desc); + if (empty($this->tva_tx)) $this->tva_tx=0; + if (empty($this->localtax1_tx)) $this->localtax1_tx=0; + if (empty($this->localtax2_tx)) $this->localtax2_tx=0; + if (empty($this->localtax1_type)) $this->localtax1_type=0; + if (empty($this->localtax2_type)) $this->localtax2_type=0; + if (empty($this->total_localtax1)) $this->total_localtax1=0; + if (empty($this->total_localtax2)) $this->total_localtax2=0; + if (empty($this->rang)) $this->rang=0; + if (empty($this->remise_percent)) $this->remise_percent=0; + if (empty($this->info_bits)) $this->info_bits=0; + if (empty($this->subprice)) $this->subprice=0; + if (empty($this->special_code)) $this->special_code=0; + if (empty($this->fk_parent_line)) $this->fk_parent_line=0; + if (! isset($this->situation_percent) || $this->situation_percent > 100 || (string) $this->situation_percent == '') $this->situation_percent = 100; + + if (empty($this->pa_ht)) $this->pa_ht=0; + if (empty($this->multicurrency_subprice)) $this->multicurrency_subprice=0; + if (empty($this->multicurrency_total_ht)) $this->multicurrency_total_ht=0; + if (empty($this->multicurrency_total_tva)) $this->multicurrency_total_tva=0; + if (empty($this->multicurrency_total_ttc)) $this->multicurrency_total_ttc=0; + + + // Check parameters + if ($this->product_type < 0) + { + $this->error='ErrorProductTypeMustBe0orMore'; + return -1; + } + if (! empty($this->fk_product)) + { + // Check product exists + $result=Product::isExistingObject('product', $this->fk_product); + if ($result <= 0) + { + $this->error='ErrorProductIdDoesNotExists'; + return -1; + } + } + + $this->db->begin(); + + // Insertion dans base de la ligne + $sql = 'INSERT INTO '.MAIN_DB_PREFIX.$this->table_element; + $sql.= ' (fk_facture_fourn, fk_parent_line, label, description, qty,'; + $sql.= ' tva_tx, localtax1_tx, localtax2_tx, localtax1_type, localtax2_type,'; + $sql.= ' fk_product, product_type, remise_percent, pu_ht, pu_ttc,'; + $sql.= ' date_start, date_end, fk_code_ventilation, rang, special_code,'; + $sql.= ' info_bits, total_ht, tva, total_ttc, total_localtax1, total_localtax2, fk_unit'; + $sql.= ', fk_multicurrency, multicurrency_code, multicurrency_subprice, multicurrency_total_ht, multicurrency_total_tva, multicurrency_total_ttc'; + $sql.= ')'; + $sql.= " VALUES (".$this->fk_facture_fourn.","; + $sql.= " ".($this->fk_parent_line>0?"'".$this->fk_parent_line."'":"null").","; + $sql.= " ".(! empty($this->label)?"'".$this->db->escape($this->label)."'":"null").","; + $sql.= " '".$this->db->escape($this->desc)."',"; + $sql.= " ".price2num($this->qty).","; + $sql.= " ".price2num($this->tva_tx).","; + $sql.= " ".price2num($this->localtax1_tx).","; + $sql.= " ".price2num($this->localtax2_tx).","; + $sql.= " '".$this->localtax1_type."',"; + $sql.= " '".$this->localtax2_type."',"; + $sql.= ' '.(! empty($this->fk_product)?$this->fk_product:"null").','; + $sql.= " ".$this->product_type.","; + $sql.= " ".price2num($this->remise_percent).","; + $sql.= " ".price2num($this->subprice).","; + $sql.= " ".price2num($this->total_ttc/$this->qty).","; + $sql.= " ".(! empty($this->date_start)?"'".$this->db->idate($this->date_start)."'":"null").","; + $sql.= " ".(! empty($this->date_end)?"'".$this->db->idate($this->date_end)."'":"null").","; + $sql.= ' '.(!empty($this->fk_code_ventilation)?$this->fk_code_ventilation:0).','; + $sql.= ' '.$this->rang.','; + $sql.= ' '.$this->special_code.','; + $sql.= " '".$this->info_bits."',"; + $sql.= " ".price2num($this->total_ht).","; + $sql.= " ".price2num($this->total_tva).","; + $sql.= " ".price2num($this->total_ttc).","; + $sql.= " ".price2num($this->total_localtax1).","; + $sql.= " ".price2num($this->total_localtax2); + $sql .= ", ".(!$this->fk_unit ? 'NULL' : $this->fk_unit); + $sql.= ", ".(int) $this->fk_multicurrency; + $sql.= ", '".$this->db->escape($this->multicurrency_code)."'"; + $sql.= ", ".price2num($this->multicurrency_subprice); + $sql.= ", ".price2num($this->multicurrency_total_ht); + $sql.= ", ".price2num($this->multicurrency_total_tva); + $sql.= ", ".price2num($this->multicurrency_total_ttc); + $sql.= ')'; + + dol_syslog(get_class($this)."::insert", LOG_DEBUG); + $resql=$this->db->query($sql); + if ($resql) + { + $this->id=$this->db->last_insert_id(MAIN_DB_PREFIX.$this->table_element); + $this->rowid=$this->id; + + if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used + { + $result=$this->insertExtraFields(); + if ($result < 0) + { + $error++; + } + } + + if (! $notrigger) + { + // Call trigger + $result=$this->call_trigger('LINEBILL_SUPPLIER_CREATE',$user); + if ($result < 0) + { + $this->db->rollback(); + return -2; + } + // End call triggers + } + + $this->db->commit(); + return $this->id; + + } + else + { + $this->error=$this->db->error(); + $this->db->rollback(); + return -2; + } + } } diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 280664ea421..a8239bcb7fb 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -476,7 +476,8 @@ if (empty($reshook)) $lines[$i]->rang, 0, $lines[$i]->array_options, - $lines[$i]->fk_unit + $lines[$i]->fk_unit, + $lines[$i]->id ); if ($result < 0) From 76f17737be3f83a1ae244914d5bfa3ad5d168743 Mon Sep 17 00:00:00 2001 From: Sergio Sanchis Climent Date: Tue, 19 Jul 2016 13:50:32 +0200 Subject: [PATCH 161/379] change dolsyslog --- htdocs/fourn/class/fournisseur.commande.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index f91a7edab67..233d4e63e58 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -2811,7 +2811,7 @@ class CommandeFournisseurLigne extends CommonOrderLine $sql.= ",total_ttc='".price2num($this->total_ttc)."'"; $sql.= " WHERE rowid = ".$this->rowid; - dol_syslog("CommandeFournisseurLigne.class.php::update_total", LOG_DEBUG); + dol_syslog(get_class($this)."::update_total", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) From c101a6c483adc0c14377e65b77f12f7adfa51bfe Mon Sep 17 00:00:00 2001 From: Sergio Sanchis Climent Date: Tue, 19 Jul 2016 13:56:48 +0200 Subject: [PATCH 162/379] update camel caps to update_total() --- htdocs/fourn/class/fournisseur.commande.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 233d4e63e58..26cfd08775e 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -2798,7 +2798,7 @@ class CommandeFournisseurLigne extends CommonOrderLine * * @return int <0 si ko, >0 si ok */ - public function update_total() + public function updateTotal() { $this->db->begin(); @@ -2811,7 +2811,7 @@ class CommandeFournisseurLigne extends CommonOrderLine $sql.= ",total_ttc='".price2num($this->total_ttc)."'"; $sql.= " WHERE rowid = ".$this->rowid; - dol_syslog(get_class($this)."::update_total", LOG_DEBUG); + dol_syslog(get_class($this)."::updateTotal", LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) From f4705873cb6790437a68e6fdae09f453d403e7d6 Mon Sep 17 00:00:00 2001 From: All3kcis Date: Tue, 19 Jul 2016 15:27:03 +0200 Subject: [PATCH 163/379] Update functions.lib.php Remove useless verification on $level. Second check "in_array" line 624 is sufficient with strict mode. Otherwise "Emerg level" is not possible with "empty($level).. LOG_EMERG = 0... --- htdocs/core/lib/functions.lib.php | 90 +++++++++++++++---------------- 1 file changed, 44 insertions(+), 46 deletions(-) diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index 03b64113ac1..1549a2603b6 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -619,54 +619,52 @@ function dol_syslog($message, $level = LOG_INFO, $ident = 0, $suffixinfilename=' // If syslog module enabled if (empty($conf->syslog->enabled)) return; - if (! empty($level)) + // Test log level + $logLevels = array(LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG); + if (!in_array($level, $logLevels, true)) { - // Test log level - $logLevels = array( LOG_EMERG, LOG_ALERT, LOG_CRIT, LOG_ERR, LOG_WARNING, LOG_NOTICE, LOG_INFO, LOG_DEBUG); - if (!in_array($level, $logLevels)) - { - throw new Exception('Incorrect log level'); - } - if ($level > $conf->global->SYSLOG_LEVEL) return; - - // If adding log inside HTML page is required - if (! empty($_REQUEST['logtohtml']) && (! empty($conf->global->MAIN_ENABLE_LOG_TO_HTML) || ! empty($conf->global->MAIN_LOGTOHTML))) // MAIN_LOGTOHTML kept for backward compatibility - { - $conf->logbuffer[] = dol_print_date(time(),"%Y-%m-%d %H:%M:%S")." ".$message; - } - - //TODO: Remove this. MAIN_ENABLE_LOG_INLINE_HTML should be deprecated and use a log handler dedicated to HTML output - // If enable html log tag enabled and url parameter log defined, we show output log on HTML comments - if (! empty($conf->global->MAIN_ENABLE_LOG_INLINE_HTML) && ! empty($_GET["log"])) - { - print "\n\n\n"; - } - - $data = array( - 'message' => $message, - 'script' => (isset($_SERVER['PHP_SELF'])? basename($_SERVER['PHP_SELF'],'.php') : false), - 'level' => $level, - 'user' => ((is_object($user) && $user->id) ? $user->login : false), - 'ip' => false - ); - - if (! empty($_SERVER["REMOTE_ADDR"])) $data['ip'] = $_SERVER['REMOTE_ADDR']; - // This is when PHP session is ran inside a web server but not inside a client request (example: init code of apache) - else if (! empty($_SERVER['SERVER_ADDR'])) $data['ip'] = $_SERVER['SERVER_ADDR']; - // This is when PHP session is ran outside a web server, like from Windows command line (Not always defined, but useful if OS defined it). - else if (! empty($_SERVER['COMPUTERNAME'])) $data['ip'] = $_SERVER['COMPUTERNAME'].(empty($_SERVER['USERNAME'])?'':'@'.$_SERVER['USERNAME']); - // This is when PHP session is ran outside a web server, like from Linux command line (Not always defined, but usefull if OS defined it). - else if (! empty($_SERVER['LOGNAME'])) $data['ip'] = '???@'.$_SERVER['LOGNAME']; - // Loop on each log handler and send output - foreach ($conf->loghandlers as $loghandlerinstance) - { - if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) continue; - $loghandlerinstance->export($data,$suffixinfilename); - } - unset($data); + throw new Exception('Incorrect log level'); } + if ($level > $conf->global->SYSLOG_LEVEL) return; + + // If adding log inside HTML page is required + if (! empty($_REQUEST['logtohtml']) && (! empty($conf->global->MAIN_ENABLE_LOG_TO_HTML) || ! empty($conf->global->MAIN_LOGTOHTML))) // MAIN_LOGTOHTML kept for backward compatibility + { + $conf->logbuffer[] = dol_print_date(time(),"%Y-%m-%d %H:%M:%S")." ".$message; + } + + //TODO: Remove this. MAIN_ENABLE_LOG_INLINE_HTML should be deprecated and use a log handler dedicated to HTML output + // If enable html log tag enabled and url parameter log defined, we show output log on HTML comments + if (! empty($conf->global->MAIN_ENABLE_LOG_INLINE_HTML) && ! empty($_GET["log"])) + { + print "\n\n\n"; + } + + $data = array( + 'message' => $message, + 'script' => (isset($_SERVER['PHP_SELF'])? basename($_SERVER['PHP_SELF'],'.php') : false), + 'level' => $level, + 'user' => ((is_object($user) && $user->id) ? $user->login : false), + 'ip' => false + ); + + if (! empty($_SERVER["REMOTE_ADDR"])) $data['ip'] = $_SERVER['REMOTE_ADDR']; + // This is when PHP session is ran inside a web server but not inside a client request (example: init code of apache) + else if (! empty($_SERVER['SERVER_ADDR'])) $data['ip'] = $_SERVER['SERVER_ADDR']; + // This is when PHP session is ran outside a web server, like from Windows command line (Not always defined, but useful if OS defined it). + else if (! empty($_SERVER['COMPUTERNAME'])) $data['ip'] = $_SERVER['COMPUTERNAME'].(empty($_SERVER['USERNAME'])?'':'@'.$_SERVER['USERNAME']); + // This is when PHP session is ran outside a web server, like from Linux command line (Not always defined, but usefull if OS defined it). + else if (! empty($_SERVER['LOGNAME'])) $data['ip'] = '???@'.$_SERVER['LOGNAME']; + // Loop on each log handler and send output + foreach ($conf->loghandlers as $loghandlerinstance) + { + if ($restricttologhandler && $loghandlerinstance->code != $restricttologhandler) continue; + $loghandlerinstance->export($data,$suffixinfilename); + } + unset($data); + if (! empty($ident)) { From f54bc367a426ab9629eb47d6c9e0a151c9274449 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Wed, 20 Jul 2016 01:53:06 +0200 Subject: [PATCH 164/379] fix : warning error if no graphfiles append when we have no element present (start from new) --- htdocs/product/stats/card.php | 115 +++++++++++++++++----------------- 1 file changed, 59 insertions(+), 56 deletions(-) diff --git a/htdocs/product/stats/card.php b/htdocs/product/stats/card.php index f9f2fe51b5f..c7ada869ecf 100644 --- a/htdocs/product/stats/card.php +++ b/htdocs/product/stats/card.php @@ -244,7 +244,7 @@ if (! empty($id) || ! empty($ref) || GETPOST('id') == 'all') $px = new DolGraph(); - if (! $error) + if (! $error && count($graphfiles)>0) { $mesg = $px->isGraphKo(); if (! $mesg) @@ -301,64 +301,67 @@ if (! empty($id) || ! empty($ref) || GETPOST('id') == 'all') // Show graphs $i=0; - foreach($graphfiles as $key => $val) + if ( count($graphfiles)>0) { - if (! $graphfiles[$key]['file']) continue; - - if ($graphfiles == 'propal' && ! $user->rights->propale->lire) continue; - if ($graphfiles == 'order' && ! $user->rights->commande->lire) continue; - if ($graphfiles == 'invoices' && ! $user->rights->facture->lire) continue; - if ($graphfiles == 'proposals_suppliers' && ! $user->rights->supplier_proposal->lire) continue; - if ($graphfiles == 'invoices_suppliers' && ! $user->rights->fournisseur->facture->lire) continue; - if ($graphfiles == 'orders_suppliers' && ! $user->rights->fournisseur->commande->lire) continue; - - - if ($i % 2 == 0) + foreach($graphfiles as $key => $val) { - print "\n".'
'."\n"; + if (! $graphfiles[$key]['file']) continue; + + if ($graphfiles == 'propal' && ! $user->rights->propale->lire) continue; + if ($graphfiles == 'order' && ! $user->rights->commande->lire) continue; + if ($graphfiles == 'invoices' && ! $user->rights->facture->lire) continue; + if ($graphfiles == 'proposals_suppliers' && ! $user->rights->supplier_proposal->lire) continue; + if ($graphfiles == 'invoices_suppliers' && ! $user->rights->fournisseur->facture->lire) continue; + if ($graphfiles == 'orders_suppliers' && ! $user->rights->fournisseur->commande->lire) continue; + + + if ($i % 2 == 0) + { + print "\n".'
'."\n"; + } + else + { + print "\n".'
'."\n"; + } + + // Show graph + + print ''; + // Label + print ''; + // Image + print ''; + // Date generation + print ''; + if ($graphfiles[$key]['output'] && ! $px->isGraphKo()) + { + if (file_exists($dir."/".$graphfiles[$key]['file']) && filemtime($dir."/".$graphfiles[$key]['file'])) print ''; + else print ''; + } + else + { + print ''; + } + print ''; + print ''; + print '
'; + print $graphfiles[$key]['label']; + print '
'; + print $graphfiles[$key]['output']; + print '
'.$langs->trans("GeneratedOn",dol_print_date(filemtime($dir."/".$graphfiles[$key]['file']),"dayhour")).''.$langs->trans("GeneratedOn",dol_print_date(dol_now(),"dayhour")).''.($mesg?''.$mesg.'':$langs->trans("ChartNotGenerated")).'id).((string) $type != ''?'&type='.$type:'').'&action=recalcul&mode='.$mode.'">'.img_picto($langs->trans("ReCalculate"),'refresh').'
'; + + if ($i % 2 == 0) + { + print "\n".'
'."\n"; + } + else + { + print "\n".'
'; + print '

'."\n"; + } + + $i++; } - else - { - print "\n".'
'."\n"; - } - - // Show graph - - print ''; - // Label - print ''; - // Image - print ''; - // Date generation - print ''; - if ($graphfiles[$key]['output'] && ! $px->isGraphKo()) - { - if (file_exists($dir."/".$graphfiles[$key]['file']) && filemtime($dir."/".$graphfiles[$key]['file'])) print ''; - else print ''; - } - else - { - print ''; - } - print ''; - print ''; - print '
'; - print $graphfiles[$key]['label']; - print '
'; - print $graphfiles[$key]['output']; - print '
'.$langs->trans("GeneratedOn",dol_print_date(filemtime($dir."/".$graphfiles[$key]['file']),"dayhour")).''.$langs->trans("GeneratedOn",dol_print_date(dol_now(),"dayhour")).''.($mesg?''.$mesg.'':$langs->trans("ChartNotGenerated")).'id).((string) $type != ''?'&type='.$type:'').'&action=recalcul&mode='.$mode.'">'.img_picto($langs->trans("ReCalculate"),'refresh').'
'; - - if ($i % 2 == 0) - { - print "\n".'
'."\n"; - } - else - { - print "\n".'
'; - print '

'."\n"; - } - - $i++; } // div not closed if ($i % 2 == 1) From 01c140ecacb63aacdcfe10a459be5ce926091a0b Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Wed, 20 Jul 2016 02:16:10 +0200 Subject: [PATCH 165/379] FIX External user must not be able to edit its discounts --- htdocs/comm/remx.php | 66 +++++++++++++++++++++++++------------------- 1 file changed, 38 insertions(+), 28 deletions(-) diff --git a/htdocs/comm/remx.php b/htdocs/comm/remx.php index a4aff6d71c1..e358b842d2d 100644 --- a/htdocs/comm/remx.php +++ b/htdocs/comm/remx.php @@ -130,7 +130,7 @@ if ($action == 'confirm_split' && GETPOST("confirm") == 'yes') } } -if ($action == 'setremise') +if ($action == 'setremise' && $user->rights->societe->creer) { //if ($user->rights->societe->creer) //if ($user->rights->facture->creer) @@ -257,38 +257,48 @@ if ($socid > 0) print ''.$langs->trans("CustomerAbsoluteDiscountAllUsers").''; print ''.$remise_all.' '.$langs->trans("Currency".$conf->currency).' '.$langs->trans("HT").''; - print ''.$langs->trans("CustomerAbsoluteDiscountMy").''; - print ''.$remise_user.' '.$langs->trans("Currency".$conf->currency).' '.$langs->trans("HT").''; + if (! empty($user->fk_soc)) // No need to show this for external users + { + print ''.$langs->trans("CustomerAbsoluteDiscountMy").''; + print ''.$remise_user.' '.$langs->trans("Currency".$conf->currency).' '.$langs->trans("HT").''; + } print ''; - print '
'; - - print load_fiche_titre($langs->trans("NewGlobalDiscount"),'',''); - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - print ''; - - print "
'.$langs->trans("AmountHT").''; - print ' '.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("VAT").''; - print $form->load_tva('tva_tx',GETPOST('tva_tx'),$mysoc,$object); - print '
'.$langs->trans("NoteReason").'
"; + if ($user->rights->societe->creer) + { + print '
'; + + print load_fiche_titre($langs->trans("NewGlobalDiscount"),'',''); + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + print "
'.$langs->trans("AmountHT").''; + print ' '.$langs->trans("Currency".$conf->currency).'
'.$langs->trans("VAT").''; + print $form->load_tva('tva_tx',GETPOST('tva_tx'),$mysoc,$object); + print '
'.$langs->trans("NoteReason").'
"; + } + print '
'; dol_fiche_end(); - print '
'; - print ''; - if (! empty($backtopage)) - { - print '     '; - print ''; - } - print '
'; - + if ($user->rights->societe->creer) + { + print '
'; + print ''; + if (! empty($backtopage)) + { + print '     '; + print ''; + } + print '
'; + } + print ''; @@ -414,7 +424,7 @@ if ($socid > 0) print '
'; /* - * Liste ristournes appliquees (=liees a une ligne de facture ou facture) + * List discount consumed (=liees a une ligne de facture ou facture) */ // Remises liees a lignes de factures From 8830264c0e5f4b50cee46e0ba5f75139aa1e2020 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Wed, 20 Jul 2016 02:27:40 +0200 Subject: [PATCH 166/379] tooltip not present on picto, already present in $link and some case they are conflict --- htdocs/product/class/product.class.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index 19d667fd6e9..f3f03c65ac6 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -3185,8 +3185,8 @@ class Product extends CommonObject } if ($withpicto) { - if ($this->type == Product::TYPE_PRODUCT) $result.=($link.img_object($langs->trans("ShowProduct").' '.$this->label, 'product', 'class="classfortooltip"').$linkend.' '); - if ($this->type == Product::TYPE_SERVICE) $result.=($link.img_object($langs->trans("ShowService").' '.$this->label, 'service', 'class="classfortooltip"').$linkend.' '); + if ($this->type == Product::TYPE_PRODUCT) $result.=($link.img_object('', 'product', '').$linkend.' '); + if ($this->type == Product::TYPE_SERVICE) $result.=($link.img_object('', 'service', '').$linkend.' '); } $result.=$link.$newref.$linkend; return $result; From f2a479695eb4e3b18c73fd2f535aace720b0f601 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rapha=C3=ABl=20Doursenaud?= Date: Mon, 22 Feb 2016 18:45:00 +0100 Subject: [PATCH 167/379] New: Improved forced install process Tamper proofed the process by not relying on POST values for forced fields. Disabled all fields set when $force_install_noedit is set. Added a full-featured forced install config file template. On the side: Improved Dolibarr root and url detection. Prevent install locking if install was not successful. Added missing translation on failed administrator creation. Better escaping of posted values. --- htdocs/install/check.php | 19 +- htdocs/install/fileconf.php | 342 +++++++++++++---------- htdocs/install/inc.php | 100 ++++++- htdocs/install/index.php | 7 +- htdocs/install/install.forced.sample.php | 73 +++++ htdocs/install/step1.php | 148 ++++++---- htdocs/install/step2.php | 15 +- htdocs/install/step4.php | 18 +- htdocs/install/step5.php | 75 +++-- htdocs/install/upgrade.php | 10 +- htdocs/install/upgrade2.php | 12 +- htdocs/langs/en_US/install.lang | 3 +- 12 files changed, 542 insertions(+), 280 deletions(-) create mode 100644 htdocs/install/install.forced.sample.php diff --git a/htdocs/install/check.php b/htdocs/install/check.php index 66a9f7f77bb..c2326d58486 100644 --- a/htdocs/install/check.php +++ b/htdocs/install/check.php @@ -1,11 +1,11 @@ - * Copyright (C) 2004-2015 Laurent Destailleur - * Copyright (C) 2005 Marc Barilley / Ocebo - * Copyright (C) 2005-2012 Regis Houssin - * Copyright (C) 2013-2014 Juanjo Menent +/* Copyright (C) 2004-2005 Rodolphe Quiedeville + * Copyright (C) 2004-2015 Laurent Destailleur + * Copyright (C) 2005 Marc Barilley / Ocebo + * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2013-2014 Juanjo Menent * Copyright (C) 2014 Marcos García - * Copyright (C) 2015 Raphaël Doursenaud + * Copyright (C) 2015-2016 Raphaël Doursenaud * * 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,6 +28,8 @@ */ include_once 'inc.php'; +global $langs; + $err = 0; $allowinstall = 0; $allowupgrade = false; @@ -42,7 +44,10 @@ $langs->load("install"); $useforcedwizard=false; $forcedfile="./install.forced.php"; if ($conffile == "/etc/dolibarr/conf.php") $forcedfile="/etc/dolibarr/install.forced.php"; -if (@file_exists($forcedfile)) { $useforcedwizard=true; include_once $forcedfile; } +if (@file_exists($forcedfile)) { + $useforcedwizard = true; + include_once $forcedfile; +} dolibarr_install_syslog("--- check: Dolibarr install/upgrade process started"); diff --git a/htdocs/install/fileconf.php b/htdocs/install/fileconf.php index d0cf9a4a385..1782be430bc 100644 --- a/htdocs/install/fileconf.php +++ b/htdocs/install/fileconf.php @@ -1,10 +1,11 @@ - * Copyright (C) 2004 Eric Seigne - * Copyright (C) 2004-2012 Laurent Destailleur - * Copyright (C) 2004 Benoit Mortier - * Copyright (C) 2004 Sebastien DiCintio - * Copyright (C) 2005-2011 Regis Houssin +/* Copyright (C) 2004 Rodolphe Quiedeville + * Copyright (C) 2004 Eric Seigne + * Copyright (C) 2004-2012 Laurent Destailleur + * Copyright (C) 2004 Benoit Mortier + * Copyright (C) 2004 Sebastien DiCintio + * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2016 Raphaël Doursenaud * * 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,6 +29,8 @@ include_once 'inc.php'; +global $langs; + $err=0; $setuplang=GETPOST("selectlang",'',3)?GETPOST("selectlang",'',3):(isset($_GET["lang"])?$_GET["lang"]:'auto'); @@ -58,12 +61,10 @@ $useforcedwizard=false; $forcedfile="./install.forced.php"; if ($conffile == "/etc/dolibarr/conf.php") $forcedfile="/etc/dolibarr/install.forced.php"; // Must be after inc.php if (@file_exists($forcedfile)) { - $useforcedwizard=true; include_once $forcedfile; + $useforcedwizard = true; + include_once $forcedfile; } -//$force_install_message='This is the message'; -//$force_install_noedit=1; - /* * View @@ -120,37 +121,20 @@ if (! empty($force_install_message)) print $langs->trans("WebPagesDirectory"); print ""; - if(! isset($dolibarr_main_url_root) || dol_strlen($dolibarr_main_url_root) == 0) - { - //print "x".$_SERVER["SCRIPT_FILENAME"]." y".$_SERVER["DOCUMENT_ROOT"]; - - // Si le php fonctionne en CGI, alors SCRIPT_FILENAME vaut le path du php et - // ce n'est pas ce qu'on veut. Dans ce cas, on propose $_SERVER["DOCUMENT_ROOT"] - if (preg_match('/^php$/i',$_SERVER["SCRIPT_FILENAME"]) || preg_match('/[\\/]php$/i',$_SERVER["SCRIPT_FILENAME"]) || preg_match('/php\.exe$/i',$_SERVER["SCRIPT_FILENAME"])) - { - $dolibarr_main_document_root=$_SERVER["DOCUMENT_ROOT"]; - - if (! preg_match('/[\\/]dolibarr[\\/]htdocs$/i',$dolibarr_main_document_root)) - { - $dolibarr_main_document_root.="/dolibarr/htdocs"; - } - } - else - { - $dolibarr_main_document_root = substr($_SERVER["SCRIPT_FILENAME"],0,dol_strlen($_SERVER["SCRIPT_FILENAME"]) - 21); - // Nettoyage du path propose - // Gere les chemins windows avec double "\" - $dolibarr_main_document_root = str_replace('\\\\','/',$dolibarr_main_document_root); - - // Supprime les slash ou antislash de fins - $dolibarr_main_document_root = preg_replace('/[\\/]+$/','',$dolibarr_main_document_root); - } + if (empty($dolibarr_main_url_root)) { + $dolibarr_main_document_root = detect_dolibarr_main_document_root(); } ?> - '; - print ''; - ?> + + + > + trans("WithNoSlashAtTheEnd")."
"; print $langs->trans("Examples").":
"; @@ -167,24 +151,21 @@ if (! empty($force_install_message)) trans("DocumentsDirectory"); ?> - '; - print ''; - ?> + + + > + trans("WithNoSlashAtTheEnd")."
"; print $langs->trans("DirectoryRecommendation")."
"; @@ -199,39 +180,23 @@ if (! empty($force_install_message)) trans("URLRoot"); ?> - '; - print ''; - ?> + + + > + trans("Examples").":
"; ?>