Passed
Push — master ( 49af33...3cffbe )
by Alxarafe
21:21
created
dolibarr/htdocs/core/lib/project.lib.php 3 patches
Indentation   +1471 added lines, -1471 removed lines patch added patch discarded remove patch
@@ -35,122 +35,122 @@  discard block
 block discarded – undo
35 35
  */
36 36
 function project_prepare_head($object)
37 37
 {
38
-	global $db, $langs, $conf, $user;
39
-
40
-	$h = 0;
41
-	$head = array();
42
-
43
-	$head[$h][0] = DOL_URL_ROOT.'/projet/card.php?id='.$object->id;
44
-	$head[$h][1] = $langs->trans("Project");
45
-	$head[$h][2] = 'project';
46
-	$h++;
47
-
48
-	$nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
49
-	$head[$h][0] = DOL_URL_ROOT.'/projet/contact.php?id='.$object->id;
50
-	$head[$h][1] = $langs->trans("ProjectContact");
51
-	if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
52
-	$head[$h][2] = 'contact';
53
-	$h++;
54
-
55
-	if (empty($conf->global->PROJECT_HIDE_TASKS))
56
-	{
57
-		// Then tab for sub level of projet, i mean tasks
58
-		$head[$h][0] = DOL_URL_ROOT.'/projet/tasks.php?id='.$object->id;
59
-		$head[$h][1] = $langs->trans("Tasks");
60
-
61
-		require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
62
-		$taskstatic=new Task($db);
63
-		$nbTasks=count($taskstatic->getTasksArray(0, 0, $object->id, 0, 0));
64
-		if ($nbTasks > 0) $head[$h][1].= ' <span class="badge">'.($nbTasks).'</span>';
65
-		$head[$h][2] = 'tasks';
66
-		$h++;
67
-
68
-		$nbTimeSpent=0;
69
-		$sql = "SELECT t.rowid";
70
-		//$sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t, ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."user as u";
71
-		//$sql .= " WHERE t.fk_user = u.rowid AND t.fk_task = pt.rowid";
72
-		$sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t, ".MAIN_DB_PREFIX."projet_task as pt";
73
-		$sql .= " WHERE t.fk_task = pt.rowid";
74
-		$sql .= " AND pt.fk_projet =".$object->id;
75
-		$resql = $db->query($sql);
76
-		if ($resql)
77
-		{
78
-			$obj = $db->fetch_object($resql);
79
-			if ($obj) $nbTimeSpent=1;
80
-		}
81
-		else dol_print_error($db);
82
-
83
-		$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?withproject=1&projectid='.$object->id;
84
-		$head[$h][1] = $langs->trans("TimeSpent");
85
-		if ($nbTimeSpent > 0) $head[$h][1].= ' <span class="badge">...</span>';
86
-		$head[$h][2] = 'timespent';
87
-		$h++;
88
-	}
89
-
90
-	if (! empty($conf->fournisseur->enabled) || ! empty($conf->propal->enabled) || ! empty($conf->commande->enabled)
91
-		|| ! empty($conf->facture->enabled) || ! empty($conf->contrat->enabled)
92
-		|| ! empty($conf->ficheinter->enabled) || ! empty($conf->agenda->enabled) || ! empty($conf->deplacement->enabled))
93
-	{
94
-		$head[$h][0] = DOL_URL_ROOT.'/projet/element.php?id='.$object->id;
95
-		$head[$h][1] = $langs->trans("ProjectOverview");
96
-		$head[$h][2] = 'element';
97
-		$h++;
98
-	}
99
-
100
-	// Show more tabs from modules
101
-	// Entries must be declared in modules descriptor with line
102
-	// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
103
-	// $this->tabs = array('entity:-tabname);   												to remove a tab
104
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'project');
105
-
106
-
107
-	if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
108
-	{
109
-		$nbNote = 0;
110
-		if(!empty($object->note_private)) $nbNote++;
111
-		if(!empty($object->note_public)) $nbNote++;
112
-		$head[$h][0] = DOL_URL_ROOT.'/projet/note.php?id='.$object->id;
113
-		$head[$h][1] = $langs->trans('Notes');
114
-		if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
115
-		$head[$h][2] = 'notes';
116
-		$h++;
117
-	}
118
-
119
-	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
120
-	require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
121
-	$upload_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->ref);
122
-	$nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$'));
123
-	$nbLinks=Link::count($db, $object->element, $object->id);
124
-	$head[$h][0] = DOL_URL_ROOT.'/projet/document.php?id='.$object->id;
125
-	$head[$h][1] = $langs->trans('Documents');
126
-	if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
127
-	$head[$h][2] = 'document';
128
-	$h++;
129
-
130
-	// Manage discussion
131
-	if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT))
132
-	{
133
-		$nbComments = $object->getNbComments();
134
-		$head[$h][0] = DOL_URL_ROOT.'/projet/comment.php?id='.$object->id;
135
-		$head[$h][1] = $langs->trans("CommentLink");
136
-		if ($nbComments > 0) $head[$h][1].= ' <span class="badge">'.$nbComments.'</span>';
137
-		$head[$h][2] = 'project_comment';
138
-		$h++;
139
-	}
140
-
141
-	$head[$h][0] = DOL_URL_ROOT.'/projet/info.php?id='.$object->id;
142
-	$head[$h][1].= $langs->trans("Events");
143
-	if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) ))
144
-	{
145
-		$head[$h][1].= '/';
146
-		$head[$h][1].= $langs->trans("Agenda");
147
-	}
148
-	$head[$h][2] = 'agenda';
149
-	$h++;
150
-
151
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'project','remove');
152
-
153
-	return $head;
38
+    global $db, $langs, $conf, $user;
39
+
40
+    $h = 0;
41
+    $head = array();
42
+
43
+    $head[$h][0] = DOL_URL_ROOT.'/projet/card.php?id='.$object->id;
44
+    $head[$h][1] = $langs->trans("Project");
45
+    $head[$h][2] = 'project';
46
+    $h++;
47
+
48
+    $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
49
+    $head[$h][0] = DOL_URL_ROOT.'/projet/contact.php?id='.$object->id;
50
+    $head[$h][1] = $langs->trans("ProjectContact");
51
+    if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
52
+    $head[$h][2] = 'contact';
53
+    $h++;
54
+
55
+    if (empty($conf->global->PROJECT_HIDE_TASKS))
56
+    {
57
+        // Then tab for sub level of projet, i mean tasks
58
+        $head[$h][0] = DOL_URL_ROOT.'/projet/tasks.php?id='.$object->id;
59
+        $head[$h][1] = $langs->trans("Tasks");
60
+
61
+        require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
62
+        $taskstatic=new Task($db);
63
+        $nbTasks=count($taskstatic->getTasksArray(0, 0, $object->id, 0, 0));
64
+        if ($nbTasks > 0) $head[$h][1].= ' <span class="badge">'.($nbTasks).'</span>';
65
+        $head[$h][2] = 'tasks';
66
+        $h++;
67
+
68
+        $nbTimeSpent=0;
69
+        $sql = "SELECT t.rowid";
70
+        //$sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t, ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."user as u";
71
+        //$sql .= " WHERE t.fk_user = u.rowid AND t.fk_task = pt.rowid";
72
+        $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t, ".MAIN_DB_PREFIX."projet_task as pt";
73
+        $sql .= " WHERE t.fk_task = pt.rowid";
74
+        $sql .= " AND pt.fk_projet =".$object->id;
75
+        $resql = $db->query($sql);
76
+        if ($resql)
77
+        {
78
+            $obj = $db->fetch_object($resql);
79
+            if ($obj) $nbTimeSpent=1;
80
+        }
81
+        else dol_print_error($db);
82
+
83
+        $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?withproject=1&projectid='.$object->id;
84
+        $head[$h][1] = $langs->trans("TimeSpent");
85
+        if ($nbTimeSpent > 0) $head[$h][1].= ' <span class="badge">...</span>';
86
+        $head[$h][2] = 'timespent';
87
+        $h++;
88
+    }
89
+
90
+    if (! empty($conf->fournisseur->enabled) || ! empty($conf->propal->enabled) || ! empty($conf->commande->enabled)
91
+        || ! empty($conf->facture->enabled) || ! empty($conf->contrat->enabled)
92
+        || ! empty($conf->ficheinter->enabled) || ! empty($conf->agenda->enabled) || ! empty($conf->deplacement->enabled))
93
+    {
94
+        $head[$h][0] = DOL_URL_ROOT.'/projet/element.php?id='.$object->id;
95
+        $head[$h][1] = $langs->trans("ProjectOverview");
96
+        $head[$h][2] = 'element';
97
+        $h++;
98
+    }
99
+
100
+    // Show more tabs from modules
101
+    // Entries must be declared in modules descriptor with line
102
+    // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
103
+    // $this->tabs = array('entity:-tabname);   												to remove a tab
104
+    complete_head_from_modules($conf,$langs,$object,$head,$h,'project');
105
+
106
+
107
+    if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
108
+    {
109
+        $nbNote = 0;
110
+        if(!empty($object->note_private)) $nbNote++;
111
+        if(!empty($object->note_public)) $nbNote++;
112
+        $head[$h][0] = DOL_URL_ROOT.'/projet/note.php?id='.$object->id;
113
+        $head[$h][1] = $langs->trans('Notes');
114
+        if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
115
+        $head[$h][2] = 'notes';
116
+        $h++;
117
+    }
118
+
119
+    require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
120
+    require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
121
+    $upload_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->ref);
122
+    $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$'));
123
+    $nbLinks=Link::count($db, $object->element, $object->id);
124
+    $head[$h][0] = DOL_URL_ROOT.'/projet/document.php?id='.$object->id;
125
+    $head[$h][1] = $langs->trans('Documents');
126
+    if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
127
+    $head[$h][2] = 'document';
128
+    $h++;
129
+
130
+    // Manage discussion
131
+    if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_PROJECT))
132
+    {
133
+        $nbComments = $object->getNbComments();
134
+        $head[$h][0] = DOL_URL_ROOT.'/projet/comment.php?id='.$object->id;
135
+        $head[$h][1] = $langs->trans("CommentLink");
136
+        if ($nbComments > 0) $head[$h][1].= ' <span class="badge">'.$nbComments.'</span>';
137
+        $head[$h][2] = 'project_comment';
138
+        $h++;
139
+    }
140
+
141
+    $head[$h][0] = DOL_URL_ROOT.'/projet/info.php?id='.$object->id;
142
+    $head[$h][1].= $langs->trans("Events");
143
+    if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) ))
144
+    {
145
+        $head[$h][1].= '/';
146
+        $head[$h][1].= $langs->trans("Agenda");
147
+    }
148
+    $head[$h][2] = 'agenda';
149
+    $h++;
150
+
151
+    complete_head_from_modules($conf,$langs,$object,$head,$h,'project','remove');
152
+
153
+    return $head;
154 154
 }
155 155
 
156 156
 
@@ -162,86 +162,86 @@  discard block
 block discarded – undo
162 162
  */
163 163
 function task_prepare_head($object)
164 164
 {
165
-	global $db, $langs, $conf, $user;
166
-	$h = 0;
167
-	$head = array();
168
-
169
-	$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/task.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
170
-	$head[$h][1] = $langs->trans("Card");
171
-	$head[$h][2] = 'task_task';
172
-	$h++;
173
-
174
-	$nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
175
-	$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/contact.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
176
-	$head[$h][1] = $langs->trans("TaskRessourceLinks");
177
-	if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
178
-	$head[$h][2] = 'task_contact';
179
-	$h++;
180
-
181
-	// Is there timespent ?
182
-	$nbTimeSpent=0;
183
-	$sql = "SELECT t.rowid";
184
-	//$sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t, ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."user as u";
185
-	//$sql .= " WHERE t.fk_user = u.rowid AND t.fk_task = pt.rowid";
186
-	$sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t";
187
-	$sql .= " WHERE t.fk_task =".$object->id;
188
-	$resql = $db->query($sql);
189
-	if ($resql)
190
-	{
191
-		$obj = $db->fetch_object($resql);
192
-		if ($obj) $nbTimeSpent=1;
193
-	}
194
-	else dol_print_error($db);
195
-
196
-	$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
197
-	$head[$h][1] = $langs->trans("TimeSpent");
198
-	if ($nbTimeSpent > 0) $head[$h][1].= ' <span class="badge">...</span>';
199
-	$head[$h][2] = 'task_time';
200
-	$h++;
201
-
202
-	// Show more tabs from modules
203
-	// Entries must be declared in modules descriptor with line
204
-	// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
205
-	// $this->tabs = array('entity:-tabname);   												to remove a tab
206
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'task');
207
-
208
-	if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
209
-	{
210
-		$nbNote = 0;
211
-		if(!empty($object->note_private)) $nbNote++;
212
-		if(!empty($object->note_public)) $nbNote++;
213
-		$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/note.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
214
-		$head[$h][1] = $langs->trans('Notes');
215
-		if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
216
-		$head[$h][2] = 'task_notes';
217
-		$h++;
218
-	}
219
-
220
-	$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/document.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
221
-	$filesdir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->project->ref) . '/' .dol_sanitizeFileName($object->ref);
222
-	include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
223
-	include_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
224
-	$nbFiles = count(dol_dir_list($filesdir,'files',0,'','(\.meta|_preview.*\.png)$'));
225
-	$nbLinks=Link::count($db, $object->element, $object->id);
226
-	$head[$h][1] = $langs->trans('Documents');
227
-	if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
228
-	$head[$h][2] = 'task_document';
229
-	$h++;
230
-
231
-	// Manage discussion
232
-	if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_TASK))
233
-	{
234
-		$nbComments = $object->getNbComments();
235
-		$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/comment.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
236
-		$head[$h][1] = $langs->trans("CommentLink");
237
-		if ($nbComments > 0) $head[$h][1].= ' <span class="badge">'.$nbComments.'</span>';
238
-		$head[$h][2] = 'task_comment';
239
-		$h++;
240
-	}
241
-
242
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'task','remove');
243
-
244
-	return $head;
165
+    global $db, $langs, $conf, $user;
166
+    $h = 0;
167
+    $head = array();
168
+
169
+    $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/task.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
170
+    $head[$h][1] = $langs->trans("Card");
171
+    $head[$h][2] = 'task_task';
172
+    $h++;
173
+
174
+    $nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
175
+    $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/contact.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
176
+    $head[$h][1] = $langs->trans("TaskRessourceLinks");
177
+    if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
178
+    $head[$h][2] = 'task_contact';
179
+    $h++;
180
+
181
+    // Is there timespent ?
182
+    $nbTimeSpent=0;
183
+    $sql = "SELECT t.rowid";
184
+    //$sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t, ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."user as u";
185
+    //$sql .= " WHERE t.fk_user = u.rowid AND t.fk_task = pt.rowid";
186
+    $sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t";
187
+    $sql .= " WHERE t.fk_task =".$object->id;
188
+    $resql = $db->query($sql);
189
+    if ($resql)
190
+    {
191
+        $obj = $db->fetch_object($resql);
192
+        if ($obj) $nbTimeSpent=1;
193
+    }
194
+    else dol_print_error($db);
195
+
196
+    $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
197
+    $head[$h][1] = $langs->trans("TimeSpent");
198
+    if ($nbTimeSpent > 0) $head[$h][1].= ' <span class="badge">...</span>';
199
+    $head[$h][2] = 'task_time';
200
+    $h++;
201
+
202
+    // Show more tabs from modules
203
+    // Entries must be declared in modules descriptor with line
204
+    // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
205
+    // $this->tabs = array('entity:-tabname);   												to remove a tab
206
+    complete_head_from_modules($conf,$langs,$object,$head,$h,'task');
207
+
208
+    if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
209
+    {
210
+        $nbNote = 0;
211
+        if(!empty($object->note_private)) $nbNote++;
212
+        if(!empty($object->note_public)) $nbNote++;
213
+        $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/note.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
214
+        $head[$h][1] = $langs->trans('Notes');
215
+        if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
216
+        $head[$h][2] = 'task_notes';
217
+        $h++;
218
+    }
219
+
220
+    $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/document.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
221
+    $filesdir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->project->ref) . '/' .dol_sanitizeFileName($object->ref);
222
+    include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
223
+    include_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
224
+    $nbFiles = count(dol_dir_list($filesdir,'files',0,'','(\.meta|_preview.*\.png)$'));
225
+    $nbLinks=Link::count($db, $object->element, $object->id);
226
+    $head[$h][1] = $langs->trans('Documents');
227
+    if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
228
+    $head[$h][2] = 'task_document';
229
+    $h++;
230
+
231
+    // Manage discussion
232
+    if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_TASK))
233
+    {
234
+        $nbComments = $object->getNbComments();
235
+        $head[$h][0] = DOL_URL_ROOT.'/projet/tasks/comment.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
236
+        $head[$h][1] = $langs->trans("CommentLink");
237
+        if ($nbComments > 0) $head[$h][1].= ' <span class="badge">'.$nbComments.'</span>';
238
+        $head[$h][2] = 'task_comment';
239
+        $h++;
240
+    }
241
+
242
+    complete_head_from_modules($conf,$langs,$object,$head,$h,'task','remove');
243
+
244
+    return $head;
245 245
 }
246 246
 
247 247
 /**
@@ -253,33 +253,33 @@  discard block
 block discarded – undo
253 253
  */
254 254
 function project_timesheet_prepare_head($mode, $fuser=null)
255 255
 {
256
-	global $langs, $conf, $user;
257
-	$h = 0;
258
-	$head = array();
259
-
260
-	$h = 0;
261
-
262
-	$param='';
263
-	$param.=($mode?'&mode='.$mode:'');
264
-	if (is_object($fuser) && $fuser->id > 0 && $fuser->id != $user->id) $param.='&search_usertoprocessid='.$fuser->id;
265
-
266
-	if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERWEEK))
267
-	{
268
-		$head[$h][0] = DOL_URL_ROOT."/projet/activity/perweek.php".($param?'?'.$param:'');
269
-		$head[$h][1] = $langs->trans("InputPerWeek");
270
-		$head[$h][2] = 'inputperweek';
271
-		$h++;
272
-	}
273
-
274
-	if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERTIME))
275
-	{
276
-		$head[$h][0] = DOL_URL_ROOT."/projet/activity/perday.php".($param?'?'.$param:'');
277
-		$head[$h][1] = $langs->trans("InputPerDay");
278
-		$head[$h][2] = 'inputperday';
279
-		$h++;
280
-	}
281
-
282
-	/*if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
256
+    global $langs, $conf, $user;
257
+    $h = 0;
258
+    $head = array();
259
+
260
+    $h = 0;
261
+
262
+    $param='';
263
+    $param.=($mode?'&mode='.$mode:'');
264
+    if (is_object($fuser) && $fuser->id > 0 && $fuser->id != $user->id) $param.='&search_usertoprocessid='.$fuser->id;
265
+
266
+    if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERWEEK))
267
+    {
268
+        $head[$h][0] = DOL_URL_ROOT."/projet/activity/perweek.php".($param?'?'.$param:'');
269
+        $head[$h][1] = $langs->trans("InputPerWeek");
270
+        $head[$h][2] = 'inputperweek';
271
+        $h++;
272
+    }
273
+
274
+    if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERTIME))
275
+    {
276
+        $head[$h][0] = DOL_URL_ROOT."/projet/activity/perday.php".($param?'?'.$param:'');
277
+        $head[$h][1] = $langs->trans("InputPerDay");
278
+        $head[$h][2] = 'inputperday';
279
+        $h++;
280
+    }
281
+
282
+    /*if ($conf->global->MAIN_FEATURES_LEVEL >= 2)
283 283
 	{
284 284
 		$head[$h][0] = DOL_URL_ROOT."/projet/activity/perline.php".($param?'?'.$param:'');
285 285
 		$head[$h][1] = $langs->trans("InputDetail");
@@ -287,11 +287,11 @@  discard block
 block discarded – undo
287 287
 		$h++;
288 288
 	}*/
289 289
 
290
-	complete_head_from_modules($conf,$langs,null,$head,$h,'project_timesheet');
290
+    complete_head_from_modules($conf,$langs,null,$head,$h,'project_timesheet');
291 291
 
292
-	complete_head_from_modules($conf,$langs,null,$head,$h,'project_timesheet','remove');
292
+    complete_head_from_modules($conf,$langs,null,$head,$h,'project_timesheet','remove');
293 293
 
294
-	return $head;
294
+    return $head;
295 295
 }
296 296
 
297 297
 
@@ -302,32 +302,32 @@  discard block
 block discarded – undo
302 302
  */
303 303
 function project_admin_prepare_head()
304 304
 {
305
-	global $langs, $conf, $user;
306
-	$h = 0;
307
-	$head = array();
305
+    global $langs, $conf, $user;
306
+    $h = 0;
307
+    $head = array();
308 308
 
309
-	$h = 0;
309
+    $h = 0;
310 310
 
311
-	$head[$h][0] = DOL_URL_ROOT."/projet/admin/project.php";
312
-	$head[$h][1] = $langs->trans("Projects");
313
-	$head[$h][2] = 'project';
314
-	$h++;
311
+    $head[$h][0] = DOL_URL_ROOT."/projet/admin/project.php";
312
+    $head[$h][1] = $langs->trans("Projects");
313
+    $head[$h][2] = 'project';
314
+    $h++;
315 315
 
316
-	complete_head_from_modules($conf,$langs,null,$head,$h,'project_admin');
316
+    complete_head_from_modules($conf,$langs,null,$head,$h,'project_admin');
317 317
 
318
-	$head[$h][0] = DOL_URL_ROOT."/projet/admin/project_extrafields.php";
319
-	$head[$h][1] = $langs->trans("ExtraFieldsProject");
320
-	$head[$h][2] = 'attributes';
321
-	$h++;
318
+    $head[$h][0] = DOL_URL_ROOT."/projet/admin/project_extrafields.php";
319
+    $head[$h][1] = $langs->trans("ExtraFieldsProject");
320
+    $head[$h][2] = 'attributes';
321
+    $h++;
322 322
 
323
-	$head[$h][0] = DOL_URL_ROOT.'/projet/admin/project_task_extrafields.php';
324
-	$head[$h][1] = $langs->trans("ExtraFieldsProjectTask");
325
-	$head[$h][2] = 'attributes_task';
326
-	$h++;
323
+    $head[$h][0] = DOL_URL_ROOT.'/projet/admin/project_task_extrafields.php';
324
+    $head[$h][1] = $langs->trans("ExtraFieldsProjectTask");
325
+    $head[$h][2] = 'attributes_task';
326
+    $h++;
327 327
 
328
-	complete_head_from_modules($conf,$langs,null,$head,$h,'project_admin','remove');
328
+    complete_head_from_modules($conf,$langs,null,$head,$h,'project_admin','remove');
329 329
 
330
-	return $head;
330
+    return $head;
331 331
 }
332 332
 
333 333
 
@@ -349,284 +349,284 @@  discard block
 block discarded – undo
349 349
  */
350 350
 function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$taskrole, $projectsListId='', $addordertick=0, $projectidfortotallink=0, $filterprogresscalc='')
351 351
 {
352
-	global $user, $bc, $langs, $conf, $db;
353
-	global $projectstatic, $taskstatic;
354
-
355
-	$lastprojectid=0;
356
-
357
-	$projectsArrayId=explode(',',$projectsListId);
358
-	if ($filterprogresscalc!=='') {
359
-		foreach ($lines as $key=>$line) {
360
-			if (!empty($line->planned_workload) && !empty($line->duration)) {
361
-				$filterprogresscalc = str_replace(' = ', ' == ', $filterprogresscalc);
362
-				if (!eval($filterprogresscalc)) {
363
-					unset($lines[$key]);
364
-				}
365
-			}
366
-		}
367
-		$lines=array_values($lines);
368
-	}
369
-
370
-	$numlines=count($lines);
371
-
372
-	// We declare counter as global because we want to edit them into recursive call
373
-	global $total_projectlinesa_spent,$total_projectlinesa_planned,$total_projectlinesa_spent_if_planned;
374
-	if ($level == 0)
375
-	{
376
-		$total_projectlinesa_spent=0;
377
-		$total_projectlinesa_planned=0;
378
-		$total_projectlinesa_spent_if_planned=0;
379
-	}
380
-
381
-	for ($i = 0 ; $i < $numlines ; $i++)
382
-	{
383
-		if ($parent == 0 && $level >= 0) $level = 0;              // if $level = -1, we dont' use sublevel recursion, we show all lines
384
-
385
-		// Process line
386
-		// print "i:".$i."-".$lines[$i]->fk_project.'<br>';
387
-
388
-		if ($lines[$i]->fk_parent == $parent || $level < 0)       // if $level = -1, we dont' use sublevel recursion, we show all lines
389
-		{
390
-			// Show task line.
391
-			$showline=1;
392
-			$showlineingray=0;
393
-
394
-			// If there is filters to use
395
-			if (is_array($taskrole))
396
-			{
397
-				// If task not legitimate to show, search if a legitimate task exists later in tree
398
-				if (! isset($taskrole[$lines[$i]->id]) && $lines[$i]->id != $lines[$i]->fk_parent)
399
-				{
400
-					// So search if task has a subtask legitimate to show
401
-					$foundtaskforuserdeeper=0;
402
-					searchTaskInChild($foundtaskforuserdeeper,$lines[$i]->id,$lines,$taskrole);
403
-					//print '$foundtaskforuserpeeper='.$foundtaskforuserdeeper.'<br>';
404
-					if ($foundtaskforuserdeeper > 0)
405
-					{
406
-						$showlineingray=1;		// We will show line but in gray
407
-					}
408
-					else
409
-					{
410
-						$showline=0;			// No reason to show line
411
-					}
412
-				}
413
-			}
414
-			else
415
-			{
416
-				// Caller did not ask to filter on tasks of a specific user (this probably means he want also tasks of all users, into public project
417
-				// or into all other projects if user has permission to).
418
-				if (empty($user->rights->projet->all->lire))
419
-				{
420
-					// User is not allowed on this project and project is not public, so we hide line
421
-					if (! in_array($lines[$i]->fk_project, $projectsArrayId))
422
-					{
423
-						// Note that having a user assigned to a task into a project user has no permission on, should not be possible
424
-						// because assignement on task can be done only on contact of project.
425
-						// If assignement was done and after, was removed from contact of project, then we can hide the line.
426
-						$showline=0;
427
-					}
428
-				}
429
-			}
430
-
431
-			if ($showline)
432
-			{
433
-				// Break on a new project
434
-				if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
435
-				{
436
-					$var = !$var;
437
-					$lastprojectid=$lines[$i]->fk_project;
438
-				}
439
-
440
-				print '<tr '.$bc[$var].' id="row-'.$lines[$i]->id.'">'."\n";
441
-
442
-				if ($showproject)
443
-				{
444
-					// Project ref
445
-					print "<td>";
446
-					//if ($showlineingray) print '<i>';
447
-					$projectstatic->id=$lines[$i]->fk_project;
448
-					$projectstatic->ref=$lines[$i]->projectref;
449
-					$projectstatic->public=$lines[$i]->public;
450
-					$projectstatic->title=$lines[$i]->projectlabel;
451
-					if ($lines[$i]->public || in_array($lines[$i]->fk_project,$projectsArrayId) || ! empty($user->rights->projet->all->lire)) print $projectstatic->getNomUrl(1);
452
-					else print $projectstatic->getNomUrl(1,'nolink');
453
-					//if ($showlineingray) print '</i>';
454
-					print "</td>";
455
-
456
-					// Project status
457
-					print '<td>';
458
-					$projectstatic->statut=$lines[$i]->projectstatus;
459
-					print $projectstatic->getLibStatut(2);
460
-					print "</td>";
461
-				}
462
-
463
-				// Ref of task
464
-				print '<td>';
465
-				if ($showlineingray)
466
-				{
467
-					print '<i>'.img_object('','projecttask').' '.$lines[$i]->ref.'</i>';
468
-				}
469
-				else
470
-				{
471
-					$taskstatic->id=$lines[$i]->id;
472
-					$taskstatic->ref=$lines[$i]->ref;
473
-					$taskstatic->label=($taskrole[$lines[$i]->id]?$langs->trans("YourRole").': '.$taskrole[$lines[$i]->id]:'');
474
-					print $taskstatic->getNomUrl(1,'withproject');
475
-				}
476
-				print '</td>';
477
-
478
-				// Title of task
479
-				print "<td>";
480
-				if ($showlineingray) print '<i>';
481
-				//else print '<a href="'.DOL_URL_ROOT.'/projet/tasks/task.php?id='.$lines[$i]->id.'&withproject=1">';
482
-				for ($k = 0 ; $k < $level ; $k++)
483
-				{
484
-					print "&nbsp; &nbsp; &nbsp;";
485
-				}
486
-				print $lines[$i]->label;
487
-				if ($showlineingray) print '</i>';
488
-				//else print '</a>';
489
-				print "</td>\n";
490
-
491
-				// Date start
492
-				print '<td align="center">';
493
-				print dol_print_date($lines[$i]->date_start,'dayhour');
494
-				print '</td>';
495
-
496
-				// Date end
497
-				print '<td align="center">';
498
-				$taskstatic->projectstatus = $lines[$i]->projectstatus;
499
-				$taskstatic->progress = $lines[$i]->progress;
500
-				$taskstatic->fk_statut = $lines[$i]->status;
501
-				$taskstatic->datee = $lines[$i]->date_end;
502
-				print dol_print_date($lines[$i]->date_end,'dayhour');
503
-				if ($taskstatic->hasDelay()) print img_warning($langs->trans("Late"));
504
-				print '</td>';
505
-
506
-				$plannedworkloadoutputformat='allhourmin';
507
-				$timespentoutputformat='allhourmin';
508
-				if (! empty($conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT)) $plannedworkloadoutputformat=$conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT;
509
-				if (! empty($conf->global->PROJECT_TIMES_SPENT_FORMAT)) $timespentoutputformat=$conf->global->PROJECT_TIME_SPENT_FORMAT;
510
-
511
-				// Planned Workload (in working hours)
512
-				print '<td align="right">';
513
-				$fullhour=convertSecondToTime($lines[$i]->planned_workload,$plannedworkloadoutputformat);
514
-				$workingdelay=convertSecondToTime($lines[$i]->planned_workload,'all',86400,7);	// TODO Replace 86400 and 7 to take account working hours per day and working day per weeks
515
-				if ($lines[$i]->planned_workload != '')
516
-				{
517
-					print $fullhour;
518
-					// TODO Add delay taking account of working hours per day and working day per week
519
-					//if ($workingdelay != $fullhour) print '<br>('.$workingdelay.')';
520
-				}
521
-				//else print '--:--';
522
-				print '</td>';
523
-
524
-				// Time spent
525
-				print '<td align="right">';
526
-				if ($showlineingray) print '<i>';
527
-				else print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.($showproject?'':'&withproject=1').'">';
528
-				if ($lines[$i]->duration) print convertSecondToTime($lines[$i]->duration,$timespentoutputformat);
529
-				else print '--:--';
530
-				if ($showlineingray) print '</i>';
531
-				else print '</a>';
532
-				print '</td>';
533
-
534
-				// Progress calculated (Note: ->duration is time spent)
535
-				print '<td align="right">';
536
-				if ($lines[$i]->planned_workload || $lines[$i]->duration)
537
-				{
538
-					if ($lines[$i]->planned_workload) print round(100 * $lines[$i]->duration / $lines[$i]->planned_workload,2).' %';
539
-					else print '<span class="opacitymedium">'.$langs->trans('WorkloadNotDefined').'</span>';
540
-				}
541
-				print '</td>';
542
-
543
-				// Progress declared
544
-				print '<td align="right">';
545
-				if ($lines[$i]->progress != '')
546
-				{
547
-					print $lines[$i]->progress.' %';
548
-				}
549
-				print '</td>';
550
-
551
-				// Contacts of task
552
-				if (! empty($conf->global->PROJECT_SHOW_CONTACTS_IN_LIST))
553
-				{
554
-					print '<td>';
555
-					foreach(array('internal','external') as $source)
556
-					{
557
-						$tab = $lines[$i]->liste_contact(-1,$source);
558
-						$num=count($tab);
559
-						if (!empty($num)){
560
-							foreach ($tab as $contacttask){
561
-								//var_dump($contacttask);
562
-								if ($source == 'internal') $c = new User($db);
563
-								else $c = new Contact($db);
564
-								$c->fetch($contacttask['id']);
565
-								print $c->getNomUrl(1) . ' (' . $contacttask['libelle'] . ')' . '<br>';
566
-							}
567
-						}
568
-					}
569
-					print '</td>';
570
-				}
571
-
572
-				// Tick to drag and drop
573
-				if ($addordertick)
574
-				{
575
-					print '<td align="center" class="tdlineupdown hideonsmartphone">&nbsp;</td>';
576
-				}
577
-
578
-				print "</tr>\n";
579
-
580
-				if (! $showlineingray) $inc++;
581
-
582
-				if ($level >= 0)    // Call sublevels
583
-				{
584
-					$level++;
585
-					if ($lines[$i]->id) projectLinesa($inc, $lines[$i]->id, $lines, $level, $var, $showproject, $taskrole, $projectsListId, $addordertick);
586
-					$level--;
587
-				}
588
-
589
-				$total_projectlinesa_spent += $lines[$i]->duration;
590
-				$total_projectlinesa_planned += $lines[$i]->planned_workload;
591
-				if ($lines[$i]->planned_workload) $total_projectlinesa_spent_if_planned += $lines[$i]->duration;
592
-			}
593
-		}
594
-		else
595
-		{
596
-			//$level--;
597
-		}
598
-	}
599
-
600
-	if (($total_projectlinesa_planned > 0 || $total_projectlinesa_spent > 0) && $level <= 0)
601
-	{
602
-		print '<tr class="liste_total nodrag nodrop">';
603
-		print '<td class="liste_total">'.$langs->trans("Total").'</td>';
604
-		if ($showproject) print '<td></td><td></td>';
605
-		print '<td></td>';
606
-		print '<td></td>';
607
-		print '<td></td>';
608
-		print '<td align="right" class="nowrap liste_total">';
609
-		print convertSecondToTime($total_projectlinesa_planned, 'allhourmin');
610
-		print '</td>';
611
-		print '<td align="right" class="nowrap liste_total">';
612
-		if ($projectidfortotallink > 0) print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?projectid='.$projectidfortotallink.($showproject?'':'&withproject=1').'">';
613
-		print convertSecondToTime($total_projectlinesa_spent, 'allhourmin');
614
-		if ($projectidfortotallink > 0) print '</a>';
615
-		print '</td>';
616
-		print '<td align="right" class="nowrap liste_total">';
617
-		if ($total_projectlinesa_planned) print round(100 * $total_projectlinesa_spent / $total_projectlinesa_planned,2).' %';
618
-		print '</td>';
619
-		print '<td></td>';
620
-		// Contacts of task
621
-		if (! empty($conf->global->PROJECT_SHOW_CONTACTS_IN_LIST))
622
-		{
623
-			print '<td></td>';
624
-		}
625
-		if ($addordertick) print '<td class="hideonsmartphone"></td>';
626
-		print '</tr>';
627
-	}
628
-
629
-	return $inc;
352
+    global $user, $bc, $langs, $conf, $db;
353
+    global $projectstatic, $taskstatic;
354
+
355
+    $lastprojectid=0;
356
+
357
+    $projectsArrayId=explode(',',$projectsListId);
358
+    if ($filterprogresscalc!=='') {
359
+        foreach ($lines as $key=>$line) {
360
+            if (!empty($line->planned_workload) && !empty($line->duration)) {
361
+                $filterprogresscalc = str_replace(' = ', ' == ', $filterprogresscalc);
362
+                if (!eval($filterprogresscalc)) {
363
+                    unset($lines[$key]);
364
+                }
365
+            }
366
+        }
367
+        $lines=array_values($lines);
368
+    }
369
+
370
+    $numlines=count($lines);
371
+
372
+    // We declare counter as global because we want to edit them into recursive call
373
+    global $total_projectlinesa_spent,$total_projectlinesa_planned,$total_projectlinesa_spent_if_planned;
374
+    if ($level == 0)
375
+    {
376
+        $total_projectlinesa_spent=0;
377
+        $total_projectlinesa_planned=0;
378
+        $total_projectlinesa_spent_if_planned=0;
379
+    }
380
+
381
+    for ($i = 0 ; $i < $numlines ; $i++)
382
+    {
383
+        if ($parent == 0 && $level >= 0) $level = 0;              // if $level = -1, we dont' use sublevel recursion, we show all lines
384
+
385
+        // Process line
386
+        // print "i:".$i."-".$lines[$i]->fk_project.'<br>';
387
+
388
+        if ($lines[$i]->fk_parent == $parent || $level < 0)       // if $level = -1, we dont' use sublevel recursion, we show all lines
389
+        {
390
+            // Show task line.
391
+            $showline=1;
392
+            $showlineingray=0;
393
+
394
+            // If there is filters to use
395
+            if (is_array($taskrole))
396
+            {
397
+                // If task not legitimate to show, search if a legitimate task exists later in tree
398
+                if (! isset($taskrole[$lines[$i]->id]) && $lines[$i]->id != $lines[$i]->fk_parent)
399
+                {
400
+                    // So search if task has a subtask legitimate to show
401
+                    $foundtaskforuserdeeper=0;
402
+                    searchTaskInChild($foundtaskforuserdeeper,$lines[$i]->id,$lines,$taskrole);
403
+                    //print '$foundtaskforuserpeeper='.$foundtaskforuserdeeper.'<br>';
404
+                    if ($foundtaskforuserdeeper > 0)
405
+                    {
406
+                        $showlineingray=1;		// We will show line but in gray
407
+                    }
408
+                    else
409
+                    {
410
+                        $showline=0;			// No reason to show line
411
+                    }
412
+                }
413
+            }
414
+            else
415
+            {
416
+                // Caller did not ask to filter on tasks of a specific user (this probably means he want also tasks of all users, into public project
417
+                // or into all other projects if user has permission to).
418
+                if (empty($user->rights->projet->all->lire))
419
+                {
420
+                    // User is not allowed on this project and project is not public, so we hide line
421
+                    if (! in_array($lines[$i]->fk_project, $projectsArrayId))
422
+                    {
423
+                        // Note that having a user assigned to a task into a project user has no permission on, should not be possible
424
+                        // because assignement on task can be done only on contact of project.
425
+                        // If assignement was done and after, was removed from contact of project, then we can hide the line.
426
+                        $showline=0;
427
+                    }
428
+                }
429
+            }
430
+
431
+            if ($showline)
432
+            {
433
+                // Break on a new project
434
+                if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
435
+                {
436
+                    $var = !$var;
437
+                    $lastprojectid=$lines[$i]->fk_project;
438
+                }
439
+
440
+                print '<tr '.$bc[$var].' id="row-'.$lines[$i]->id.'">'."\n";
441
+
442
+                if ($showproject)
443
+                {
444
+                    // Project ref
445
+                    print "<td>";
446
+                    //if ($showlineingray) print '<i>';
447
+                    $projectstatic->id=$lines[$i]->fk_project;
448
+                    $projectstatic->ref=$lines[$i]->projectref;
449
+                    $projectstatic->public=$lines[$i]->public;
450
+                    $projectstatic->title=$lines[$i]->projectlabel;
451
+                    if ($lines[$i]->public || in_array($lines[$i]->fk_project,$projectsArrayId) || ! empty($user->rights->projet->all->lire)) print $projectstatic->getNomUrl(1);
452
+                    else print $projectstatic->getNomUrl(1,'nolink');
453
+                    //if ($showlineingray) print '</i>';
454
+                    print "</td>";
455
+
456
+                    // Project status
457
+                    print '<td>';
458
+                    $projectstatic->statut=$lines[$i]->projectstatus;
459
+                    print $projectstatic->getLibStatut(2);
460
+                    print "</td>";
461
+                }
462
+
463
+                // Ref of task
464
+                print '<td>';
465
+                if ($showlineingray)
466
+                {
467
+                    print '<i>'.img_object('','projecttask').' '.$lines[$i]->ref.'</i>';
468
+                }
469
+                else
470
+                {
471
+                    $taskstatic->id=$lines[$i]->id;
472
+                    $taskstatic->ref=$lines[$i]->ref;
473
+                    $taskstatic->label=($taskrole[$lines[$i]->id]?$langs->trans("YourRole").': '.$taskrole[$lines[$i]->id]:'');
474
+                    print $taskstatic->getNomUrl(1,'withproject');
475
+                }
476
+                print '</td>';
477
+
478
+                // Title of task
479
+                print "<td>";
480
+                if ($showlineingray) print '<i>';
481
+                //else print '<a href="'.DOL_URL_ROOT.'/projet/tasks/task.php?id='.$lines[$i]->id.'&withproject=1">';
482
+                for ($k = 0 ; $k < $level ; $k++)
483
+                {
484
+                    print "&nbsp; &nbsp; &nbsp;";
485
+                }
486
+                print $lines[$i]->label;
487
+                if ($showlineingray) print '</i>';
488
+                //else print '</a>';
489
+                print "</td>\n";
490
+
491
+                // Date start
492
+                print '<td align="center">';
493
+                print dol_print_date($lines[$i]->date_start,'dayhour');
494
+                print '</td>';
495
+
496
+                // Date end
497
+                print '<td align="center">';
498
+                $taskstatic->projectstatus = $lines[$i]->projectstatus;
499
+                $taskstatic->progress = $lines[$i]->progress;
500
+                $taskstatic->fk_statut = $lines[$i]->status;
501
+                $taskstatic->datee = $lines[$i]->date_end;
502
+                print dol_print_date($lines[$i]->date_end,'dayhour');
503
+                if ($taskstatic->hasDelay()) print img_warning($langs->trans("Late"));
504
+                print '</td>';
505
+
506
+                $plannedworkloadoutputformat='allhourmin';
507
+                $timespentoutputformat='allhourmin';
508
+                if (! empty($conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT)) $plannedworkloadoutputformat=$conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT;
509
+                if (! empty($conf->global->PROJECT_TIMES_SPENT_FORMAT)) $timespentoutputformat=$conf->global->PROJECT_TIME_SPENT_FORMAT;
510
+
511
+                // Planned Workload (in working hours)
512
+                print '<td align="right">';
513
+                $fullhour=convertSecondToTime($lines[$i]->planned_workload,$plannedworkloadoutputformat);
514
+                $workingdelay=convertSecondToTime($lines[$i]->planned_workload,'all',86400,7);	// TODO Replace 86400 and 7 to take account working hours per day and working day per weeks
515
+                if ($lines[$i]->planned_workload != '')
516
+                {
517
+                    print $fullhour;
518
+                    // TODO Add delay taking account of working hours per day and working day per week
519
+                    //if ($workingdelay != $fullhour) print '<br>('.$workingdelay.')';
520
+                }
521
+                //else print '--:--';
522
+                print '</td>';
523
+
524
+                // Time spent
525
+                print '<td align="right">';
526
+                if ($showlineingray) print '<i>';
527
+                else print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.($showproject?'':'&withproject=1').'">';
528
+                if ($lines[$i]->duration) print convertSecondToTime($lines[$i]->duration,$timespentoutputformat);
529
+                else print '--:--';
530
+                if ($showlineingray) print '</i>';
531
+                else print '</a>';
532
+                print '</td>';
533
+
534
+                // Progress calculated (Note: ->duration is time spent)
535
+                print '<td align="right">';
536
+                if ($lines[$i]->planned_workload || $lines[$i]->duration)
537
+                {
538
+                    if ($lines[$i]->planned_workload) print round(100 * $lines[$i]->duration / $lines[$i]->planned_workload,2).' %';
539
+                    else print '<span class="opacitymedium">'.$langs->trans('WorkloadNotDefined').'</span>';
540
+                }
541
+                print '</td>';
542
+
543
+                // Progress declared
544
+                print '<td align="right">';
545
+                if ($lines[$i]->progress != '')
546
+                {
547
+                    print $lines[$i]->progress.' %';
548
+                }
549
+                print '</td>';
550
+
551
+                // Contacts of task
552
+                if (! empty($conf->global->PROJECT_SHOW_CONTACTS_IN_LIST))
553
+                {
554
+                    print '<td>';
555
+                    foreach(array('internal','external') as $source)
556
+                    {
557
+                        $tab = $lines[$i]->liste_contact(-1,$source);
558
+                        $num=count($tab);
559
+                        if (!empty($num)){
560
+                            foreach ($tab as $contacttask){
561
+                                //var_dump($contacttask);
562
+                                if ($source == 'internal') $c = new User($db);
563
+                                else $c = new Contact($db);
564
+                                $c->fetch($contacttask['id']);
565
+                                print $c->getNomUrl(1) . ' (' . $contacttask['libelle'] . ')' . '<br>';
566
+                            }
567
+                        }
568
+                    }
569
+                    print '</td>';
570
+                }
571
+
572
+                // Tick to drag and drop
573
+                if ($addordertick)
574
+                {
575
+                    print '<td align="center" class="tdlineupdown hideonsmartphone">&nbsp;</td>';
576
+                }
577
+
578
+                print "</tr>\n";
579
+
580
+                if (! $showlineingray) $inc++;
581
+
582
+                if ($level >= 0)    // Call sublevels
583
+                {
584
+                    $level++;
585
+                    if ($lines[$i]->id) projectLinesa($inc, $lines[$i]->id, $lines, $level, $var, $showproject, $taskrole, $projectsListId, $addordertick);
586
+                    $level--;
587
+                }
588
+
589
+                $total_projectlinesa_spent += $lines[$i]->duration;
590
+                $total_projectlinesa_planned += $lines[$i]->planned_workload;
591
+                if ($lines[$i]->planned_workload) $total_projectlinesa_spent_if_planned += $lines[$i]->duration;
592
+            }
593
+        }
594
+        else
595
+        {
596
+            //$level--;
597
+        }
598
+    }
599
+
600
+    if (($total_projectlinesa_planned > 0 || $total_projectlinesa_spent > 0) && $level <= 0)
601
+    {
602
+        print '<tr class="liste_total nodrag nodrop">';
603
+        print '<td class="liste_total">'.$langs->trans("Total").'</td>';
604
+        if ($showproject) print '<td></td><td></td>';
605
+        print '<td></td>';
606
+        print '<td></td>';
607
+        print '<td></td>';
608
+        print '<td align="right" class="nowrap liste_total">';
609
+        print convertSecondToTime($total_projectlinesa_planned, 'allhourmin');
610
+        print '</td>';
611
+        print '<td align="right" class="nowrap liste_total">';
612
+        if ($projectidfortotallink > 0) print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?projectid='.$projectidfortotallink.($showproject?'':'&withproject=1').'">';
613
+        print convertSecondToTime($total_projectlinesa_spent, 'allhourmin');
614
+        if ($projectidfortotallink > 0) print '</a>';
615
+        print '</td>';
616
+        print '<td align="right" class="nowrap liste_total">';
617
+        if ($total_projectlinesa_planned) print round(100 * $total_projectlinesa_spent / $total_projectlinesa_planned,2).' %';
618
+        print '</td>';
619
+        print '<td></td>';
620
+        // Contacts of task
621
+        if (! empty($conf->global->PROJECT_SHOW_CONTACTS_IN_LIST))
622
+        {
623
+            print '<td></td>';
624
+        }
625
+        if ($addordertick) print '<td class="hideonsmartphone"></td>';
626
+        print '</tr>';
627
+    }
628
+
629
+    return $inc;
630 630
 }
631 631
 
632 632
 
@@ -649,191 +649,191 @@  discard block
 block discarded – undo
649 649
  */
650 650
 function projectLinesPerAction(&$inc, $parent, $fuser, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, $preselectedday, &$isavailable, $oldprojectforbreak=0)
651 651
 {
652
-	global $conf, $db, $user, $bc, $langs;
653
-	global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
654
-
655
-	$lastprojectid=0;
656
-	$totalforeachline=array();
657
-	$workloadforid=array();
658
-	$lineswithoutlevel0=array();
659
-
660
-	$numlines=count($lines);
661
-
662
-	// Create a smaller array with sublevels only to be used later. This increase dramatically performances.
663
-	if ($parent == 0) // Always and only if at first level
664
-	{
665
-		for ($i = 0 ; $i < $numlines ; $i++)
666
-		{
667
-			if ($lines[$i]->fk_task_parent) $lineswithoutlevel0[]=$lines[$i];
668
-		}
669
-	}
670
-
671
-	if (empty($oldprojectforbreak))
672
-	{
673
-		$oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)?0:-1);	// 0 to start break , -1 no break
674
-	}
675
-
676
-	//dol_syslog('projectLinesPerDay inc='.$inc.' preselectedday='.$preselectedday.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
677
-	for ($i = 0 ; $i < $numlines ; $i++)
678
-	{
679
-		if ($parent == 0) $level = 0;
680
-
681
-		//if ($lines[$i]->fk_task_parent == $parent)
682
-		//{
683
-			// If we want all or we have a role on task, we show it
684
-			if (empty($mine) || ! empty($tasksrole[$lines[$i]->id]))
685
-			{
686
-				//dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
687
-
688
-				// Break on a new project
689
-				if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
690
-				{
691
-					$lastprojectid=$lines[$i]->fk_project;
692
-					if ($preselectedday)
693
-					{
694
-						$projectstatic->id = $lines[$i]->fk_project;
695
-					}
696
-				}
697
-
698
-				if (empty($workloadforid[$projectstatic->id]))
699
-				{
700
-					if ($preselectedday)
701
-					{
702
-						$projectstatic->loadTimeSpent($preselectedday, 0, $fuser->id);	// Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
703
-						$workloadforid[$projectstatic->id]=1;
704
-					}
705
-				}
706
-
707
-				$projectstatic->id=$lines[$i]->fk_project;
708
-				$projectstatic->ref=$lines[$i]->project_ref;
709
-				$projectstatic->title=$lines[$i]->project_label;
710
-				$projectstatic->public=$lines[$i]->public;
711
-
712
-				$taskstatic->id=$lines[$i]->task_id;
713
-				$taskstatic->ref=($lines[$i]->task_ref?$lines[$i]->task_ref:$lines[$i]->task_id);
714
-				$taskstatic->label=$lines[$i]->task_label;
715
-				$taskstatic->date_start=$lines[$i]->date_start;
716
-				$taskstatic->date_end=$lines[$i]->date_end;
717
-
718
-				$thirdpartystatic->id=$lines[$i]->socid;
719
-				$thirdpartystatic->name=$lines[$i]->thirdparty_name;
720
-				$thirdpartystatic->email=$lines[$i]->thirdparty_email;
721
-
722
-				if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id))
723
-				{
724
-					print '<tr class="oddeven trforbreak">'."\n";
725
-					print '<td colspan="11">';
726
-					print $projectstatic->getNomUrl(1,'',0,$langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
727
-					if ($projectstatic->title)
728
-					{
729
-						print ' - ';
730
-						print $projectstatic->title;
731
-					}
732
-					print '</td>';
733
-					print '</tr>';
734
-				}
735
-
736
-				if ($oldprojectforbreak != -1) $oldprojectforbreak = $projectstatic->id;
737
-
738
-				print '<tr class="oddeven">'."\n";
739
-
740
-				// User
741
-				/*
652
+    global $conf, $db, $user, $bc, $langs;
653
+    global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
654
+
655
+    $lastprojectid=0;
656
+    $totalforeachline=array();
657
+    $workloadforid=array();
658
+    $lineswithoutlevel0=array();
659
+
660
+    $numlines=count($lines);
661
+
662
+    // Create a smaller array with sublevels only to be used later. This increase dramatically performances.
663
+    if ($parent == 0) // Always and only if at first level
664
+    {
665
+        for ($i = 0 ; $i < $numlines ; $i++)
666
+        {
667
+            if ($lines[$i]->fk_task_parent) $lineswithoutlevel0[]=$lines[$i];
668
+        }
669
+    }
670
+
671
+    if (empty($oldprojectforbreak))
672
+    {
673
+        $oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)?0:-1);	// 0 to start break , -1 no break
674
+    }
675
+
676
+    //dol_syslog('projectLinesPerDay inc='.$inc.' preselectedday='.$preselectedday.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
677
+    for ($i = 0 ; $i < $numlines ; $i++)
678
+    {
679
+        if ($parent == 0) $level = 0;
680
+
681
+        //if ($lines[$i]->fk_task_parent == $parent)
682
+        //{
683
+            // If we want all or we have a role on task, we show it
684
+            if (empty($mine) || ! empty($tasksrole[$lines[$i]->id]))
685
+            {
686
+                //dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
687
+
688
+                // Break on a new project
689
+                if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
690
+                {
691
+                    $lastprojectid=$lines[$i]->fk_project;
692
+                    if ($preselectedday)
693
+                    {
694
+                        $projectstatic->id = $lines[$i]->fk_project;
695
+                    }
696
+                }
697
+
698
+                if (empty($workloadforid[$projectstatic->id]))
699
+                {
700
+                    if ($preselectedday)
701
+                    {
702
+                        $projectstatic->loadTimeSpent($preselectedday, 0, $fuser->id);	// Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
703
+                        $workloadforid[$projectstatic->id]=1;
704
+                    }
705
+                }
706
+
707
+                $projectstatic->id=$lines[$i]->fk_project;
708
+                $projectstatic->ref=$lines[$i]->project_ref;
709
+                $projectstatic->title=$lines[$i]->project_label;
710
+                $projectstatic->public=$lines[$i]->public;
711
+
712
+                $taskstatic->id=$lines[$i]->task_id;
713
+                $taskstatic->ref=($lines[$i]->task_ref?$lines[$i]->task_ref:$lines[$i]->task_id);
714
+                $taskstatic->label=$lines[$i]->task_label;
715
+                $taskstatic->date_start=$lines[$i]->date_start;
716
+                $taskstatic->date_end=$lines[$i]->date_end;
717
+
718
+                $thirdpartystatic->id=$lines[$i]->socid;
719
+                $thirdpartystatic->name=$lines[$i]->thirdparty_name;
720
+                $thirdpartystatic->email=$lines[$i]->thirdparty_email;
721
+
722
+                if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id))
723
+                {
724
+                    print '<tr class="oddeven trforbreak">'."\n";
725
+                    print '<td colspan="11">';
726
+                    print $projectstatic->getNomUrl(1,'',0,$langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
727
+                    if ($projectstatic->title)
728
+                    {
729
+                        print ' - ';
730
+                        print $projectstatic->title;
731
+                    }
732
+                    print '</td>';
733
+                    print '</tr>';
734
+                }
735
+
736
+                if ($oldprojectforbreak != -1) $oldprojectforbreak = $projectstatic->id;
737
+
738
+                print '<tr class="oddeven">'."\n";
739
+
740
+                // User
741
+                /*
742 742
 				 print '<td class="nowrap">';
743 743
 				 print $fuser->getNomUrl(1, 'withproject', 'time');
744 744
 				 print '</td>';
745 745
 				 */
746 746
 
747
-				// Project
748
-				print "<td>";
749
-				if ($oldprojectforbreak == -1)
750
-				{
751
-					print $projectstatic->getNomUrl(1,'',0,$langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
752
-					print '<br>'.$projectstatic->title;
753
-				}
754
-				print "</td>";
755
-
756
-				// Thirdparty
757
-				print '<td class="tdoverflowmax100">';
758
-				if ($thirdpartystatic->id > 0) print $thirdpartystatic->getNomUrl(1, 'project', 10);
759
-				print '</td>';
760
-
761
-				// Ref
762
-				print '<td>';
763
-				print '<!-- Task id = '.$lines[$i]->id.' -->';
764
-				for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
765
-				print $taskstatic->getNomUrl(1, 'withproject', 'time');
766
-				// Label task
767
-				print '<br>';
768
-				for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
769
-				print $taskstatic->label;
770
-				//print "<br>";
771
-				//for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
772
-				//print get_date_range($lines[$i]->date_start,$lines[$i]->date_end,'',$langs,0);
773
-				print "</td>\n";
774
-
775
-				// Date
776
-				print '<td align="center">';
777
-				print dol_print_date($lines[$i]->timespent_datehour,'day');
778
-				print '</td>';
779
-
780
-				$disabledproject=1;$disabledtask=1;
781
-				//print "x".$lines[$i]->fk_project;
782
-				//var_dump($lines[$i]);
783
-				//var_dump($projectsrole[$lines[$i]->fk_project]);
784
-				// If at least one role for project
785
-				if ($lines[$i]->public || ! empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer)
786
-				{
787
-					$disabledproject=0;
788
-					$disabledtask=0;
789
-				}
790
-				// If $restricteditformytask is on and I have no role on task, i disable edit
791
-				if ($restricteditformytask && empty($tasksrole[$lines[$i]->id]))
792
-				{
793
-					$disabledtask=1;
794
-				}
795
-
796
-				// Hour
797
-				print '<td class="nowrap" align="center">';
798
-				print dol_print_date($lines[$i]->timespent_datehour,'hour');
799
-				print '</td>';
800
-
801
-				$cssonholiday='';
802
-				if (! $isavailable[$preselectedday]['morning'] && ! $isavailable[$preselectedday]['afternoon'])   $cssonholiday.='onholidayallday ';
803
-				elseif (! $isavailable[$preselectedday]['morning'])   $cssonholiday.='onholidaymorning ';
804
-				elseif (! $isavailable[$preselectedday]['afternoon']) $cssonholiday.='onholidayafternoon ';
805
-
806
-				// Duration
807
-				print '<td align="center" class="duration'.($cssonholiday?' '.$cssonholiday:'').'">';
808
-
809
-				$dayWorkLoad = $lines[$i]->timespent_duration;
810
-				$totalforeachline[$preselectedday]+=$lines[$i]->timespent_duration;
811
-
812
-				$alreadyspent='';
813
-				if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($lines[$i]->timespent_duration,'allhourmin');
814
-
815
-				print convertSecondToTime($lines[$i]->timespent_duration,'allhourmin');
816
-
817
-				$modeinput='hours';
818
-
819
-				print '<script type="text/javascript">';
820
-				print "jQuery(document).ready(function () {\n";
821
-				print " 	jQuery('.inputhour, .inputminute').bind('keyup', function(e) { updateTotal(0, '".$modeinput."') });";
822
-				print "})\n";
823
-				print '</script>';
824
-
825
-				print '</td>';
826
-
827
-				// Note
828
-				print '<td align="center">';
829
-				print '<textarea name="'.$lines[$i]->id.'note" rows="'.ROWS_2.'" id="'.$lines[$i]->id.'note"'.($disabledtask?' disabled="disabled"':'').'>';
830
-				print $lines[$i]->timespent_note;
831
-				print '</textarea>';
832
-				print '</td>';
833
-
834
-				// Warning
835
-				print '<td align="right">';
836
-				/*if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("UserIsNotContactOfProject"));
747
+                // Project
748
+                print "<td>";
749
+                if ($oldprojectforbreak == -1)
750
+                {
751
+                    print $projectstatic->getNomUrl(1,'',0,$langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
752
+                    print '<br>'.$projectstatic->title;
753
+                }
754
+                print "</td>";
755
+
756
+                // Thirdparty
757
+                print '<td class="tdoverflowmax100">';
758
+                if ($thirdpartystatic->id > 0) print $thirdpartystatic->getNomUrl(1, 'project', 10);
759
+                print '</td>';
760
+
761
+                // Ref
762
+                print '<td>';
763
+                print '<!-- Task id = '.$lines[$i]->id.' -->';
764
+                for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
765
+                print $taskstatic->getNomUrl(1, 'withproject', 'time');
766
+                // Label task
767
+                print '<br>';
768
+                for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
769
+                print $taskstatic->label;
770
+                //print "<br>";
771
+                //for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
772
+                //print get_date_range($lines[$i]->date_start,$lines[$i]->date_end,'',$langs,0);
773
+                print "</td>\n";
774
+
775
+                // Date
776
+                print '<td align="center">';
777
+                print dol_print_date($lines[$i]->timespent_datehour,'day');
778
+                print '</td>';
779
+
780
+                $disabledproject=1;$disabledtask=1;
781
+                //print "x".$lines[$i]->fk_project;
782
+                //var_dump($lines[$i]);
783
+                //var_dump($projectsrole[$lines[$i]->fk_project]);
784
+                // If at least one role for project
785
+                if ($lines[$i]->public || ! empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer)
786
+                {
787
+                    $disabledproject=0;
788
+                    $disabledtask=0;
789
+                }
790
+                // If $restricteditformytask is on and I have no role on task, i disable edit
791
+                if ($restricteditformytask && empty($tasksrole[$lines[$i]->id]))
792
+                {
793
+                    $disabledtask=1;
794
+                }
795
+
796
+                // Hour
797
+                print '<td class="nowrap" align="center">';
798
+                print dol_print_date($lines[$i]->timespent_datehour,'hour');
799
+                print '</td>';
800
+
801
+                $cssonholiday='';
802
+                if (! $isavailable[$preselectedday]['morning'] && ! $isavailable[$preselectedday]['afternoon'])   $cssonholiday.='onholidayallday ';
803
+                elseif (! $isavailable[$preselectedday]['morning'])   $cssonholiday.='onholidaymorning ';
804
+                elseif (! $isavailable[$preselectedday]['afternoon']) $cssonholiday.='onholidayafternoon ';
805
+
806
+                // Duration
807
+                print '<td align="center" class="duration'.($cssonholiday?' '.$cssonholiday:'').'">';
808
+
809
+                $dayWorkLoad = $lines[$i]->timespent_duration;
810
+                $totalforeachline[$preselectedday]+=$lines[$i]->timespent_duration;
811
+
812
+                $alreadyspent='';
813
+                if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($lines[$i]->timespent_duration,'allhourmin');
814
+
815
+                print convertSecondToTime($lines[$i]->timespent_duration,'allhourmin');
816
+
817
+                $modeinput='hours';
818
+
819
+                print '<script type="text/javascript">';
820
+                print "jQuery(document).ready(function () {\n";
821
+                print " 	jQuery('.inputhour, .inputminute').bind('keyup', function(e) { updateTotal(0, '".$modeinput."') });";
822
+                print "})\n";
823
+                print '</script>';
824
+
825
+                print '</td>';
826
+
827
+                // Note
828
+                print '<td align="center">';
829
+                print '<textarea name="'.$lines[$i]->id.'note" rows="'.ROWS_2.'" id="'.$lines[$i]->id.'note"'.($disabledtask?' disabled="disabled"':'').'>';
830
+                print $lines[$i]->timespent_note;
831
+                print '</textarea>';
832
+                print '</td>';
833
+
834
+                // Warning
835
+                print '<td align="right">';
836
+                /*if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("UserIsNotContactOfProject"));
837 837
 				else if ($disabledtask)
838 838
 				{
839 839
 					$titleassigntask = $langs->trans("AssignTaskToMe");
@@ -841,18 +841,18 @@  discard block
 block discarded – undo
841 841
 
842 842
 					print $form->textwithpicto('',$langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
843 843
 				}*/
844
-				print '</td>';
845
-
846
-				print "</tr>\n";
847
-			}
848
-		//}
849
-		//else
850
-		//{
851
-			//$level--;
852
-		//}
853
-	}
854
-
855
-	return $totalforeachline;
844
+                print '</td>';
845
+
846
+                print "</tr>\n";
847
+            }
848
+        //}
849
+        //else
850
+        //{
851
+            //$level--;
852
+        //}
853
+    }
854
+
855
+    return $totalforeachline;
856 856
 }
857 857
 
858 858
 
@@ -875,273 +875,273 @@  discard block
 block discarded – undo
875 875
  */
876 876
 function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, $preselectedday, &$isavailable, $oldprojectforbreak=0)
877 877
 {
878
-	global $conf, $db, $user, $bc, $langs;
879
-	global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
880
-
881
-	$lastprojectid=0;
882
-	$totalforeachday=array();
883
-	$workloadforid=array();
884
-	$lineswithoutlevel0=array();
885
-
886
-	$numlines=count($lines);
887
-
888
-	// Create a smaller array with sublevels only to be used later. This increase dramatically performances.
889
-	if ($parent == 0) // Always and only if at first level
890
-	{
891
-		for ($i = 0 ; $i < $numlines ; $i++)
892
-		{
893
-			if ($lines[$i]->fk_task_parent) $lineswithoutlevel0[]=$lines[$i];
894
-		}
895
-	}
896
-
897
-	if (empty($oldprojectforbreak))
898
-	{
899
-		$oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)?0:-1);	// 0 to start break , -1 no break
900
-	}
901
-
902
-	//dol_syslog('projectLinesPerDay inc='.$inc.' preselectedday='.$preselectedday.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
903
-	for ($i = 0 ; $i < $numlines ; $i++)
904
-	{
905
-		if ($parent == 0) $level = 0;
906
-
907
-		if ($lines[$i]->fk_task_parent == $parent)
908
-		{
909
-			// If we want all or we have a role on task, we show it
910
-			if (empty($mine) || ! empty($tasksrole[$lines[$i]->id]))
911
-			{
912
-				//dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
913
-
914
-				if ($restricteditformytask == 2 && empty($tasksrole[$lines[$i]->id]))	// we have no role on task and we request to hide such cases
915
-				{
916
-					continue;
917
-				}
918
-
919
-				// Break on a new project
920
-				if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
921
-				{
922
-					$lastprojectid=$lines[$i]->fk_project;
923
-					if ($preselectedday)
924
-					{
925
-						$projectstatic->id = $lines[$i]->fk_project;
926
-					}
927
-				}
928
-
929
-				if (empty($workloadforid[$projectstatic->id]))
930
-				{
931
-					if ($preselectedday)
932
-					{
933
-						$projectstatic->loadTimeSpent($preselectedday, 0, $fuser->id);	// Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
934
-		   				$workloadforid[$projectstatic->id]=1;
935
-					}
936
-				}
937
-
938
-				$projectstatic->id=$lines[$i]->fk_project;
939
-				$projectstatic->ref=$lines[$i]->projectref;
940
-				$projectstatic->title=$lines[$i]->projectlabel;
941
-				$projectstatic->public=$lines[$i]->public;
942
-
943
-				$taskstatic->id=$lines[$i]->id;
944
-				$taskstatic->ref=($lines[$i]->ref?$lines[$i]->ref:$lines[$i]->id);
945
-				$taskstatic->label=$lines[$i]->label;
946
-				$taskstatic->date_start=$lines[$i]->date_start;
947
-				$taskstatic->date_end=$lines[$i]->date_end;
948
-
949
-				$thirdpartystatic->id=$lines[$i]->socid;
950
-				$thirdpartystatic->name=$lines[$i]->thirdparty_name;
951
-				$thirdpartystatic->email=$lines[$i]->thirdparty_email;
952
-
953
-				if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id))
954
-				{
955
-					print '<tr class="oddeven trforbreak">'."\n";
956
-					print '<td colspan="9">';
957
-					print $projectstatic->getNomUrl(1,'',0,'<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
958
-					if ($thirdpartystatic->id > 0) print ' - '.$thirdpartystatic->getNomUrl(1);
959
-					if ($projectstatic->title)
960
-					{
961
-						print ' - ';
962
-						print $projectstatic->title;
963
-					}
964
-					print '</td>';
965
-					print '</tr>';
966
-				}
967
-
968
-				if ($oldprojectforbreak != -1) $oldprojectforbreak = $projectstatic->id;
969
-
970
-				print '<tr class="oddeven">'."\n";
971
-
972
-				// User
973
-				/*
878
+    global $conf, $db, $user, $bc, $langs;
879
+    global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
880
+
881
+    $lastprojectid=0;
882
+    $totalforeachday=array();
883
+    $workloadforid=array();
884
+    $lineswithoutlevel0=array();
885
+
886
+    $numlines=count($lines);
887
+
888
+    // Create a smaller array with sublevels only to be used later. This increase dramatically performances.
889
+    if ($parent == 0) // Always and only if at first level
890
+    {
891
+        for ($i = 0 ; $i < $numlines ; $i++)
892
+        {
893
+            if ($lines[$i]->fk_task_parent) $lineswithoutlevel0[]=$lines[$i];
894
+        }
895
+    }
896
+
897
+    if (empty($oldprojectforbreak))
898
+    {
899
+        $oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)?0:-1);	// 0 to start break , -1 no break
900
+    }
901
+
902
+    //dol_syslog('projectLinesPerDay inc='.$inc.' preselectedday='.$preselectedday.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
903
+    for ($i = 0 ; $i < $numlines ; $i++)
904
+    {
905
+        if ($parent == 0) $level = 0;
906
+
907
+        if ($lines[$i]->fk_task_parent == $parent)
908
+        {
909
+            // If we want all or we have a role on task, we show it
910
+            if (empty($mine) || ! empty($tasksrole[$lines[$i]->id]))
911
+            {
912
+                //dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
913
+
914
+                if ($restricteditformytask == 2 && empty($tasksrole[$lines[$i]->id]))	// we have no role on task and we request to hide such cases
915
+                {
916
+                    continue;
917
+                }
918
+
919
+                // Break on a new project
920
+                if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
921
+                {
922
+                    $lastprojectid=$lines[$i]->fk_project;
923
+                    if ($preselectedday)
924
+                    {
925
+                        $projectstatic->id = $lines[$i]->fk_project;
926
+                    }
927
+                }
928
+
929
+                if (empty($workloadforid[$projectstatic->id]))
930
+                {
931
+                    if ($preselectedday)
932
+                    {
933
+                        $projectstatic->loadTimeSpent($preselectedday, 0, $fuser->id);	// Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
934
+                            $workloadforid[$projectstatic->id]=1;
935
+                    }
936
+                }
937
+
938
+                $projectstatic->id=$lines[$i]->fk_project;
939
+                $projectstatic->ref=$lines[$i]->projectref;
940
+                $projectstatic->title=$lines[$i]->projectlabel;
941
+                $projectstatic->public=$lines[$i]->public;
942
+
943
+                $taskstatic->id=$lines[$i]->id;
944
+                $taskstatic->ref=($lines[$i]->ref?$lines[$i]->ref:$lines[$i]->id);
945
+                $taskstatic->label=$lines[$i]->label;
946
+                $taskstatic->date_start=$lines[$i]->date_start;
947
+                $taskstatic->date_end=$lines[$i]->date_end;
948
+
949
+                $thirdpartystatic->id=$lines[$i]->socid;
950
+                $thirdpartystatic->name=$lines[$i]->thirdparty_name;
951
+                $thirdpartystatic->email=$lines[$i]->thirdparty_email;
952
+
953
+                if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id))
954
+                {
955
+                    print '<tr class="oddeven trforbreak">'."\n";
956
+                    print '<td colspan="9">';
957
+                    print $projectstatic->getNomUrl(1,'',0,'<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
958
+                    if ($thirdpartystatic->id > 0) print ' - '.$thirdpartystatic->getNomUrl(1);
959
+                    if ($projectstatic->title)
960
+                    {
961
+                        print ' - ';
962
+                        print $projectstatic->title;
963
+                    }
964
+                    print '</td>';
965
+                    print '</tr>';
966
+                }
967
+
968
+                if ($oldprojectforbreak != -1) $oldprojectforbreak = $projectstatic->id;
969
+
970
+                print '<tr class="oddeven">'."\n";
971
+
972
+                // User
973
+                /*
974 974
 				print '<td class="nowrap">';
975 975
 				print $fuser->getNomUrl(1, 'withproject', 'time');
976 976
 				print '</td>';
977 977
 				*/
978 978
 
979
-				// Project
980
-				/*print "<td>";
979
+                // Project
980
+                /*print "<td>";
981 981
 				if ($oldprojectforbreak == -1) print $projectstatic->getNomUrl(1,'',0,$langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
982 982
 				print "</td>";*/
983 983
 
984
-				// Thirdparty
985
-				/*print '<td class="tdoverflowmax100">';
984
+                // Thirdparty
985
+                /*print '<td class="tdoverflowmax100">';
986 986
 				if ($thirdpartystatic->id > 0) print $thirdpartystatic->getNomUrl(1, 'project', 10);
987 987
 				print '</td>';*/
988 988
 
989
-				// Ref
990
-				print '<td>';
991
-				print '<!-- Task id = '.$lines[$i]->id.' -->';
992
-				for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
993
-				print $taskstatic->getNomUrl(1, 'withproject', 'time');
994
-				// Label task
995
-				print '<br>';
996
-				for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
997
-				print $taskstatic->label;
998
-				//print "<br>";
999
-				//for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
1000
-				//print get_date_range($lines[$i]->date_start,$lines[$i]->date_end,'',$langs,0);
1001
-				print "</td>\n";
1002
-
1003
-				// Planned Workload
1004
-				print '<td align="right" class="leftborder plannedworkload">';
1005
-				if ($lines[$i]->planned_workload) print convertSecondToTime($lines[$i]->planned_workload,'allhourmin');
1006
-				else print '--:--';
1007
-				print '</td>';
1008
-
1009
-				// Progress declared %
1010
-				print '<td align="right">';
1011
-				print $formother->select_percent($lines[$i]->progress, $lines[$i]->id . 'progress');
1012
-				print '</td>';
1013
-
1014
-				// Time spent by everybody
1015
-				print '<td align="right">';
1016
-				// $lines[$i]->duration is a denormalised field = summ of time spent by everybody for task. What we need is time consummed by user
1017
-				if ($lines[$i]->duration)
1018
-				{
1019
-					print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
1020
-					print convertSecondToTime($lines[$i]->duration,'allhourmin');
1021
-					print '</a>';
1022
-				}
1023
-				else print '--:--';
1024
-				print "</td>\n";
1025
-
1026
-				// Time spent by user
1027
-				print '<td align="right">';
1028
-				$tmptimespent=$taskstatic->getSummaryOfTimeSpent($fuser->id);
1029
-				if ($tmptimespent['total_duration']) print convertSecondToTime($tmptimespent['total_duration'],'allhourmin');
1030
-				else print '--:--';
1031
-				print "</td>\n";
1032
-
1033
-				$disabledproject=1;$disabledtask=1;
1034
-				//print "x".$lines[$i]->fk_project;
1035
-				//var_dump($lines[$i]);
1036
-				//var_dump($projectsrole[$lines[$i]->fk_project]);
1037
-				// If at least one role for project
1038
-				if ($lines[$i]->public || ! empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer)
1039
-				{
1040
-					$disabledproject=0;
1041
-					$disabledtask=0;
1042
-				}
1043
-				// If $restricteditformytask is on and I have no role on task, i disable edit
1044
-				if ($restricteditformytask && empty($tasksrole[$lines[$i]->id]))
1045
-				{
1046
-					$disabledtask=1;
1047
-				}
1048
-
1049
-				// Form to add new time
1050
-				print '<td class="nowrap leftborder" align="center">';
1051
-				$tableCell = $form->selectDate($preselectedday, $lines[$i]->id, 1, 1, 2, "addtime", 0, 0, $disabledtask);
1052
-				print $tableCell;
1053
-				print '</td>';
1054
-
1055
-				$cssonholiday='';
1056
-				if (! $isavailable[$preselectedday]['morning'] && ! $isavailable[$preselectedday]['afternoon'])   $cssonholiday.='onholidayallday ';
1057
-				elseif (! $isavailable[$preselectedday]['morning'])   $cssonholiday.='onholidaymorning ';
1058
-				elseif (! $isavailable[$preselectedday]['afternoon']) $cssonholiday.='onholidayafternoon ';
1059
-
1060
-				global $daytoparse;
1061
-				$tmparray = dol_getdate($daytoparse,true);	// detail of current day
1062
-				$idw = $tmparray['wday'];
1063
-
1064
-				global $numstartworkingday, $numendworkingday;
1065
-				$cssweekend='';
1066
-				if (($idw + 1) < $numstartworkingday || ($idw + 1) > $numendworkingday)	// This is a day is not inside the setup of working days, so we use a week-end css.
1067
-				{
1068
-					$cssweekend='weekend';
1069
-				}
1070
-
1071
-				// Duration
1072
-				print '<td class="center duration'.($cssonholiday?' '.$cssonholiday:'').($cssweekend?' '.$cssweekend:'').'">';
1073
-				$dayWorkLoad = $projectstatic->weekWorkLoadPerTask[$preselectedday][$lines[$i]->id];
1074
-				$totalforeachday[$preselectedday]+=$dayWorkLoad;
1075
-
1076
-				$alreadyspent='';
1077
-				if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($dayWorkLoad,'allhourmin');
1078
-
1079
-				$idw = 0;
1080
-
1081
-				$tableCell='';
1082
-				$tableCell.='<span class="timesheetalreadyrecorded" title="texttoreplace"><input type="text" class="center" size="2" disabled id="timespent['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="'.$alreadyspent.'"></span>';
1083
-				$tableCell.='<span class="hideonsmartphone"> + </span>';
1084
-				//$tableCell.='&nbsp;&nbsp;&nbsp;';
1085
-				$tableCell.=$form->select_duration($lines[$i]->id.'duration','',$disabledtask,'text',0,1);
1086
-				//$tableCell.='&nbsp;<input type="submit" class="button"'.($disabledtask?' disabled':'').' value="'.$langs->trans("Add").'">';
1087
-				print $tableCell;
1088
-
1089
-				$modeinput='hours';
1090
-
1091
-				print '<script type="text/javascript">';
1092
-				print "jQuery(document).ready(function () {\n";
1093
-				print " 	jQuery('.inputhour, .inputminute').bind('keyup', function(e) { updateTotal(0, '".$modeinput."') });";
1094
-				print "})\n";
1095
-				print '</script>';
1096
-
1097
-				print '</td>';
1098
-
1099
-				// Note
1100
-				print '<td align="center">';
1101
-				print '<textarea name="'.$lines[$i]->id.'note" rows="'.ROWS_2.'" id="'.$lines[$i]->id.'note"'.($disabledtask?' disabled="disabled"':'').'>';
1102
-				print '</textarea>';
1103
-				print '</td>';
1104
-
1105
-				// Warning
1106
-				print '<td align="right">';
1107
-   				if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("UserIsNotContactOfProject"));
1108
-   				else if ($disabledtask)
1109
-   				{
1110
-   					$titleassigntask = $langs->trans("AssignTaskToMe");
1111
-   					if ($fuser->id != $user->id) $titleassigntask = $langs->trans("AssignTaskToUser", '...');
1112
-
1113
-   					print $form->textwithpicto('',$langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
1114
-   				}
1115
-				print '</td>';
1116
-
1117
-				print "</tr>\n";
1118
-			}
1119
-
1120
-			$inc++;
1121
-			$level++;
1122
-			if ($lines[$i]->id > 0)
1123
-			{
1124
-				//var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level);
1125
-				//var_dump($totalforeachday);
1126
-				$ret = projectLinesPerDay($inc, $lines[$i]->id, $fuser, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $isavailable, $oldprojectforbreak);
1127
-				//var_dump('ret with parent='.$lines[$i]->id.' level='.$level);
1128
-				//var_dump($ret);
1129
-				foreach($ret as $key => $val)
1130
-				{
1131
-					$totalforeachday[$key]+=$val;
1132
-				}
1133
-				//var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level.' + subtasks');
1134
-				//var_dump($totalforeachday);
1135
-			}
1136
-			$level--;
1137
-		}
1138
-		else
1139
-		{
1140
-			//$level--;
1141
-		}
1142
-	}
1143
-
1144
-	return $totalforeachday;
989
+                // Ref
990
+                print '<td>';
991
+                print '<!-- Task id = '.$lines[$i]->id.' -->';
992
+                for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
993
+                print $taskstatic->getNomUrl(1, 'withproject', 'time');
994
+                // Label task
995
+                print '<br>';
996
+                for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
997
+                print $taskstatic->label;
998
+                //print "<br>";
999
+                //for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
1000
+                //print get_date_range($lines[$i]->date_start,$lines[$i]->date_end,'',$langs,0);
1001
+                print "</td>\n";
1002
+
1003
+                // Planned Workload
1004
+                print '<td align="right" class="leftborder plannedworkload">';
1005
+                if ($lines[$i]->planned_workload) print convertSecondToTime($lines[$i]->planned_workload,'allhourmin');
1006
+                else print '--:--';
1007
+                print '</td>';
1008
+
1009
+                // Progress declared %
1010
+                print '<td align="right">';
1011
+                print $formother->select_percent($lines[$i]->progress, $lines[$i]->id . 'progress');
1012
+                print '</td>';
1013
+
1014
+                // Time spent by everybody
1015
+                print '<td align="right">';
1016
+                // $lines[$i]->duration is a denormalised field = summ of time spent by everybody for task. What we need is time consummed by user
1017
+                if ($lines[$i]->duration)
1018
+                {
1019
+                    print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
1020
+                    print convertSecondToTime($lines[$i]->duration,'allhourmin');
1021
+                    print '</a>';
1022
+                }
1023
+                else print '--:--';
1024
+                print "</td>\n";
1025
+
1026
+                // Time spent by user
1027
+                print '<td align="right">';
1028
+                $tmptimespent=$taskstatic->getSummaryOfTimeSpent($fuser->id);
1029
+                if ($tmptimespent['total_duration']) print convertSecondToTime($tmptimespent['total_duration'],'allhourmin');
1030
+                else print '--:--';
1031
+                print "</td>\n";
1032
+
1033
+                $disabledproject=1;$disabledtask=1;
1034
+                //print "x".$lines[$i]->fk_project;
1035
+                //var_dump($lines[$i]);
1036
+                //var_dump($projectsrole[$lines[$i]->fk_project]);
1037
+                // If at least one role for project
1038
+                if ($lines[$i]->public || ! empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer)
1039
+                {
1040
+                    $disabledproject=0;
1041
+                    $disabledtask=0;
1042
+                }
1043
+                // If $restricteditformytask is on and I have no role on task, i disable edit
1044
+                if ($restricteditformytask && empty($tasksrole[$lines[$i]->id]))
1045
+                {
1046
+                    $disabledtask=1;
1047
+                }
1048
+
1049
+                // Form to add new time
1050
+                print '<td class="nowrap leftborder" align="center">';
1051
+                $tableCell = $form->selectDate($preselectedday, $lines[$i]->id, 1, 1, 2, "addtime", 0, 0, $disabledtask);
1052
+                print $tableCell;
1053
+                print '</td>';
1054
+
1055
+                $cssonholiday='';
1056
+                if (! $isavailable[$preselectedday]['morning'] && ! $isavailable[$preselectedday]['afternoon'])   $cssonholiday.='onholidayallday ';
1057
+                elseif (! $isavailable[$preselectedday]['morning'])   $cssonholiday.='onholidaymorning ';
1058
+                elseif (! $isavailable[$preselectedday]['afternoon']) $cssonholiday.='onholidayafternoon ';
1059
+
1060
+                global $daytoparse;
1061
+                $tmparray = dol_getdate($daytoparse,true);	// detail of current day
1062
+                $idw = $tmparray['wday'];
1063
+
1064
+                global $numstartworkingday, $numendworkingday;
1065
+                $cssweekend='';
1066
+                if (($idw + 1) < $numstartworkingday || ($idw + 1) > $numendworkingday)	// This is a day is not inside the setup of working days, so we use a week-end css.
1067
+                {
1068
+                    $cssweekend='weekend';
1069
+                }
1070
+
1071
+                // Duration
1072
+                print '<td class="center duration'.($cssonholiday?' '.$cssonholiday:'').($cssweekend?' '.$cssweekend:'').'">';
1073
+                $dayWorkLoad = $projectstatic->weekWorkLoadPerTask[$preselectedday][$lines[$i]->id];
1074
+                $totalforeachday[$preselectedday]+=$dayWorkLoad;
1075
+
1076
+                $alreadyspent='';
1077
+                if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($dayWorkLoad,'allhourmin');
1078
+
1079
+                $idw = 0;
1080
+
1081
+                $tableCell='';
1082
+                $tableCell.='<span class="timesheetalreadyrecorded" title="texttoreplace"><input type="text" class="center" size="2" disabled id="timespent['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="'.$alreadyspent.'"></span>';
1083
+                $tableCell.='<span class="hideonsmartphone"> + </span>';
1084
+                //$tableCell.='&nbsp;&nbsp;&nbsp;';
1085
+                $tableCell.=$form->select_duration($lines[$i]->id.'duration','',$disabledtask,'text',0,1);
1086
+                //$tableCell.='&nbsp;<input type="submit" class="button"'.($disabledtask?' disabled':'').' value="'.$langs->trans("Add").'">';
1087
+                print $tableCell;
1088
+
1089
+                $modeinput='hours';
1090
+
1091
+                print '<script type="text/javascript">';
1092
+                print "jQuery(document).ready(function () {\n";
1093
+                print " 	jQuery('.inputhour, .inputminute').bind('keyup', function(e) { updateTotal(0, '".$modeinput."') });";
1094
+                print "})\n";
1095
+                print '</script>';
1096
+
1097
+                print '</td>';
1098
+
1099
+                // Note
1100
+                print '<td align="center">';
1101
+                print '<textarea name="'.$lines[$i]->id.'note" rows="'.ROWS_2.'" id="'.$lines[$i]->id.'note"'.($disabledtask?' disabled="disabled"':'').'>';
1102
+                print '</textarea>';
1103
+                print '</td>';
1104
+
1105
+                // Warning
1106
+                print '<td align="right">';
1107
+                    if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("UserIsNotContactOfProject"));
1108
+                    else if ($disabledtask)
1109
+                    {
1110
+                        $titleassigntask = $langs->trans("AssignTaskToMe");
1111
+                        if ($fuser->id != $user->id) $titleassigntask = $langs->trans("AssignTaskToUser", '...');
1112
+
1113
+                        print $form->textwithpicto('',$langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
1114
+                    }
1115
+                print '</td>';
1116
+
1117
+                print "</tr>\n";
1118
+            }
1119
+
1120
+            $inc++;
1121
+            $level++;
1122
+            if ($lines[$i]->id > 0)
1123
+            {
1124
+                //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level);
1125
+                //var_dump($totalforeachday);
1126
+                $ret = projectLinesPerDay($inc, $lines[$i]->id, $fuser, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $isavailable, $oldprojectforbreak);
1127
+                //var_dump('ret with parent='.$lines[$i]->id.' level='.$level);
1128
+                //var_dump($ret);
1129
+                foreach($ret as $key => $val)
1130
+                {
1131
+                    $totalforeachday[$key]+=$val;
1132
+                }
1133
+                //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level.' + subtasks');
1134
+                //var_dump($totalforeachday);
1135
+            }
1136
+            $level--;
1137
+        }
1138
+        else
1139
+        {
1140
+            //$level--;
1141
+        }
1142
+    }
1143
+
1144
+    return $totalforeachday;
1145 1145
 }
1146 1146
 
1147 1147
 
@@ -1164,263 +1164,263 @@  discard block
 block discarded – undo
1164 1164
  */
1165 1165
 function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, &$isavailable, $oldprojectforbreak=0)
1166 1166
 {
1167
-	global $conf, $db, $user, $bc, $langs;
1168
-	global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
1169
-
1170
-	$numlines=count($lines);
1171
-
1172
-	$lastprojectid=0;
1173
-	$workloadforid=array();
1174
-	$totalforeachday=array();
1175
-	$lineswithoutlevel0=array();
1176
-
1177
-	// Create a smaller array with sublevels only to be used later. This increase dramatically performances.
1178
-	if ($parent == 0) // Always and only if at first level
1179
-	{
1180
-		for ($i = 0 ; $i < $numlines ; $i++)
1181
-		{
1182
-		   if ($lines[$i]->fk_task_parent) $lineswithoutlevel0[]=$lines[$i];
1183
-		}
1184
-	}
1185
-
1186
-	//dol_syslog('projectLinesPerWeek inc='.$inc.' firstdaytoshow='.$firstdaytoshow.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
1187
-
1188
-	if (empty($oldprojectforbreak))
1189
-	{
1190
-		$oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)?0:-1);	// 0 = start break, -1 = never break
1191
-	}
1192
-
1193
-	for ($i = 0 ; $i < $numlines ; $i++)
1194
-	{
1195
-		if ($parent == 0) $level = 0;
1196
-
1197
-		if ($lines[$i]->fk_task_parent == $parent)
1198
-		{
1199
-			// If we want all or we have a role on task, we show it
1200
-			if (empty($mine) || ! empty($tasksrole[$lines[$i]->id]))
1201
-			{
1202
-				//dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
1203
-
1204
-				if ($restricteditformytask == 2 && empty($tasksrole[$lines[$i]->id]))	// we have no role on task and we request to hide such cases
1205
-				{
1206
-					continue;
1207
-				}
1208
-
1209
-				// Break on a new project
1210
-				if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
1211
-				{
1212
-					$lastprojectid=$lines[$i]->fk_project;
1213
-					$projectstatic->id = $lines[$i]->fk_project;
1214
-				}
1215
-
1216
-				//var_dump('--- '.$level.' '.$firstdaytoshow.' '.$fuser->id.' '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
1217
-				//var_dump($projectstatic->weekWorkLoadPerTask);
1218
-				if (empty($workloadforid[$projectstatic->id]))
1219
-				{
1220
-					$projectstatic->loadTimeSpent($firstdaytoshow, 0, $fuser->id);	// Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
1221
-					$workloadforid[$projectstatic->id]=1;
1222
-				}
1223
-				//var_dump($projectstatic->weekWorkLoadPerTask);
1224
-				//var_dump('--- '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
1225
-
1226
-				$projectstatic->id=$lines[$i]->fk_project;
1227
-				$projectstatic->ref=$lines[$i]->projectref;
1228
-				$projectstatic->title=$lines[$i]->projectlabel;
1229
-				$projectstatic->public=$lines[$i]->public;
1230
-				$projectstatic->thirdparty_name=$lines[$i]->thirdparty_name;
1231
-
1232
-				$taskstatic->id=$lines[$i]->id;
1233
-				$taskstatic->ref=($lines[$i]->ref?$lines[$i]->ref:$lines[$i]->id);
1234
-				$taskstatic->label=$lines[$i]->label;
1235
-				$taskstatic->date_start=$lines[$i]->date_start;
1236
-				$taskstatic->date_end=$lines[$i]->date_end;
1237
-
1238
-				$thirdpartystatic->id=$lines[$i]->thirdparty_id;
1239
-				$thirdpartystatic->name=$lines[$i]->thirdparty_name;
1240
-				$thirdpartystatic->email=$lines[$i]->thirdparty_email;
1241
-
1242
-				if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id))
1243
-				{
1244
-					print '<tr class="oddeven trforbreak">'."\n";
1245
-					print '<td colspan="13">';
1246
-					print $projectstatic->getNomUrl(1,'',0,'<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
1247
-					if ($thirdpartystatic->id > 0) print ' - '.$thirdpartystatic->getNomUrl(1);
1248
-					if ($projectstatic->title)
1249
-					{
1250
-						print ' - ';
1251
-						print $projectstatic->title;
1252
-					}
1253
-					print '</td>';
1254
-					print '</tr>';
1255
-				}
1256
-
1257
-				if ($oldprojectforbreak != -1) $oldprojectforbreak = $projectstatic->id;
1258
-
1259
-				print '<tr class="oddeven">'."\n";
1260
-
1261
-				// User
1262
-				/*
1167
+    global $conf, $db, $user, $bc, $langs;
1168
+    global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
1169
+
1170
+    $numlines=count($lines);
1171
+
1172
+    $lastprojectid=0;
1173
+    $workloadforid=array();
1174
+    $totalforeachday=array();
1175
+    $lineswithoutlevel0=array();
1176
+
1177
+    // Create a smaller array with sublevels only to be used later. This increase dramatically performances.
1178
+    if ($parent == 0) // Always and only if at first level
1179
+    {
1180
+        for ($i = 0 ; $i < $numlines ; $i++)
1181
+        {
1182
+            if ($lines[$i]->fk_task_parent) $lineswithoutlevel0[]=$lines[$i];
1183
+        }
1184
+    }
1185
+
1186
+    //dol_syslog('projectLinesPerWeek inc='.$inc.' firstdaytoshow='.$firstdaytoshow.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
1187
+
1188
+    if (empty($oldprojectforbreak))
1189
+    {
1190
+        $oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)?0:-1);	// 0 = start break, -1 = never break
1191
+    }
1192
+
1193
+    for ($i = 0 ; $i < $numlines ; $i++)
1194
+    {
1195
+        if ($parent == 0) $level = 0;
1196
+
1197
+        if ($lines[$i]->fk_task_parent == $parent)
1198
+        {
1199
+            // If we want all or we have a role on task, we show it
1200
+            if (empty($mine) || ! empty($tasksrole[$lines[$i]->id]))
1201
+            {
1202
+                //dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
1203
+
1204
+                if ($restricteditformytask == 2 && empty($tasksrole[$lines[$i]->id]))	// we have no role on task and we request to hide such cases
1205
+                {
1206
+                    continue;
1207
+                }
1208
+
1209
+                // Break on a new project
1210
+                if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
1211
+                {
1212
+                    $lastprojectid=$lines[$i]->fk_project;
1213
+                    $projectstatic->id = $lines[$i]->fk_project;
1214
+                }
1215
+
1216
+                //var_dump('--- '.$level.' '.$firstdaytoshow.' '.$fuser->id.' '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
1217
+                //var_dump($projectstatic->weekWorkLoadPerTask);
1218
+                if (empty($workloadforid[$projectstatic->id]))
1219
+                {
1220
+                    $projectstatic->loadTimeSpent($firstdaytoshow, 0, $fuser->id);	// Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
1221
+                    $workloadforid[$projectstatic->id]=1;
1222
+                }
1223
+                //var_dump($projectstatic->weekWorkLoadPerTask);
1224
+                //var_dump('--- '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
1225
+
1226
+                $projectstatic->id=$lines[$i]->fk_project;
1227
+                $projectstatic->ref=$lines[$i]->projectref;
1228
+                $projectstatic->title=$lines[$i]->projectlabel;
1229
+                $projectstatic->public=$lines[$i]->public;
1230
+                $projectstatic->thirdparty_name=$lines[$i]->thirdparty_name;
1231
+
1232
+                $taskstatic->id=$lines[$i]->id;
1233
+                $taskstatic->ref=($lines[$i]->ref?$lines[$i]->ref:$lines[$i]->id);
1234
+                $taskstatic->label=$lines[$i]->label;
1235
+                $taskstatic->date_start=$lines[$i]->date_start;
1236
+                $taskstatic->date_end=$lines[$i]->date_end;
1237
+
1238
+                $thirdpartystatic->id=$lines[$i]->thirdparty_id;
1239
+                $thirdpartystatic->name=$lines[$i]->thirdparty_name;
1240
+                $thirdpartystatic->email=$lines[$i]->thirdparty_email;
1241
+
1242
+                if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id))
1243
+                {
1244
+                    print '<tr class="oddeven trforbreak">'."\n";
1245
+                    print '<td colspan="13">';
1246
+                    print $projectstatic->getNomUrl(1,'',0,'<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
1247
+                    if ($thirdpartystatic->id > 0) print ' - '.$thirdpartystatic->getNomUrl(1);
1248
+                    if ($projectstatic->title)
1249
+                    {
1250
+                        print ' - ';
1251
+                        print $projectstatic->title;
1252
+                    }
1253
+                    print '</td>';
1254
+                    print '</tr>';
1255
+                }
1256
+
1257
+                if ($oldprojectforbreak != -1) $oldprojectforbreak = $projectstatic->id;
1258
+
1259
+                print '<tr class="oddeven">'."\n";
1260
+
1261
+                // User
1262
+                /*
1263 1263
 				print '<td class="nowrap">';
1264 1264
 				print $fuser->getNomUrl(1, 'withproject', 'time');
1265 1265
 				print '</td>';
1266 1266
 				*/
1267 1267
 
1268
-				// Project
1269
-				/*print '<td class="nowrap">';
1268
+                // Project
1269
+                /*print '<td class="nowrap">';
1270 1270
 				if ($oldprojectforbreak == -1) print $projectstatic->getNomUrl(1,'',0,$langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
1271 1271
 				print "</td>";*/
1272 1272
 
1273
-				// Thirdparty
1274
-				/*print '<td class="tdoverflowmax100">';
1273
+                // Thirdparty
1274
+                /*print '<td class="tdoverflowmax100">';
1275 1275
 				if ($thirdpartystatic->id > 0) print $thirdpartystatic->getNomUrl(1, 'project');
1276 1276
 				print '</td>';*/
1277 1277
 
1278
-				// Ref
1279
-				print '<td class="nowrap">';
1280
-				print '<!-- Task id = '.$lines[$i]->id.' -->';
1281
-				for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
1282
-				print $taskstatic->getNomUrl(1, 'withproject', 'time');
1283
-				// Label task
1284
-				print '<br>';
1285
-				for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
1286
-				//print $taskstatic->getNomUrl(0, 'withproject', 'time');
1287
-				print $taskstatic->label;
1288
-				//print "<br>";
1289
-				//for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
1290
-				//print get_date_range($lines[$i]->date_start,$lines[$i]->date_end,'',$langs,0);
1291
-				print "</td>\n";
1292
-
1293
-				// Planned Workload
1294
-				print '<td align="right" class="leftborder plannedworkload">';
1295
-				if ($lines[$i]->planned_workload) print convertSecondToTime($lines[$i]->planned_workload,'allhourmin');
1296
-				else print '--:--';
1297
-				print '</td>';
1298
-
1299
-				// Progress declared %
1300
-				print '<td align="right">';
1301
-				print $formother->select_percent($lines[$i]->progress, $lines[$i]->id . 'progress');
1302
-				print '</td>';
1303
-
1304
-				// Time spent by everybody
1305
-				print '<td align="right">';
1306
-				// $lines[$i]->duration is a denormalised field = summ of time spent by everybody for task. What we need is time consummed by user
1307
-				if ($lines[$i]->duration)
1308
-				{
1309
-					print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
1310
-					print convertSecondToTime($lines[$i]->duration,'allhourmin');
1311
-					print '</a>';
1312
-				}
1313
-				else print '--:--';
1314
-				print "</td>\n";
1315
-
1316
-				// Time spent by user
1317
-				print '<td align="right">';
1318
-				$tmptimespent=$taskstatic->getSummaryOfTimeSpent($fuser->id);
1319
-				if ($tmptimespent['total_duration']) print convertSecondToTime($tmptimespent['total_duration'],'allhourmin');
1320
-				else print '--:--';
1321
-				print "</td>\n";
1322
-
1323
-				$disabledproject=1;$disabledtask=1;
1324
-				//print "x".$lines[$i]->fk_project;
1325
-				//var_dump($lines[$i]);
1326
-				//var_dump($projectsrole[$lines[$i]->fk_project]);
1327
-				// If at least one role for project
1328
-				if ($lines[$i]->public || ! empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer)
1329
-				{
1330
-					$disabledproject=0;
1331
-					$disabledtask=0;
1332
-				}
1333
-				// If $restricteditformytask is on and I have no role on task, i disable edit
1334
-				if ($restricteditformytask && empty($tasksrole[$lines[$i]->id]))
1335
-				{
1336
-					$disabledtask=1;
1337
-				}
1338
-
1339
-				//var_dump($projectstatic->weekWorkLoadPerTask);
1340
-
1341
-				// Fields to show current time
1342
-				$tableCell=''; $modeinput='hours';
1343
-				for ($idw = 0; $idw < 7; $idw++)
1344
-				{
1345
-					$tmpday=dol_time_plus_duree($firstdaytoshow, $idw, 'd');
1346
-
1347
-					$cssonholiday='';
1348
-					if (! $isavailable[$tmpday]['morning'] && ! $isavailable[$tmpday]['afternoon'])   $cssonholiday.='onholidayallday ';
1349
-					elseif (! $isavailable[$tmpday]['morning'])   $cssonholiday.='onholidaymorning ';
1350
-					elseif (! $isavailable[$tmpday]['afternoon']) $cssonholiday.='onholidayafternoon ';
1351
-
1352
-					$tmparray=dol_getdate($tmpday);
1353
-					$dayWorkLoad = $projectstatic->weekWorkLoadPerTask[$tmpday][$lines[$i]->id];
1354
-					$totalforeachday[$tmpday]+=$dayWorkLoad;
1355
-
1356
-					$alreadyspent='';
1357
-					if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($dayWorkLoad,'allhourmin');
1358
-					$alttitle=$langs->trans("AddHereTimeSpentForDay",$tmparray['day'],$tmparray['mon']);
1359
-
1360
-					global $numstartworkingday, $numendworkingday;
1361
-					$cssweekend='';
1362
-					if (($idw + 1) < $numstartworkingday || ($idw + 1) > $numendworkingday)	// This is a day is not inside the setup of working days, so we use a week-end css.
1363
-					{
1364
-						$cssweekend='weekend';
1365
-					}
1366
-
1367
-					$tableCell ='<td align="center" class="hide'.$idw.($cssonholiday?' '.$cssonholiday:'').($cssweekend?' '.$cssweekend:'').'">';
1368
-					$placeholder='';
1369
-					if ($alreadyspent)
1370
-					{
1371
-						$tableCell.='<span class="timesheetalreadyrecorded" title="texttoreplace"><input type="text" class="center smallpadd" size="2" disabled id="timespent['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="'.$alreadyspent.'"></span>';
1372
-						//$placeholder=' placeholder="00:00"';
1373
-					 	//$tableCell.='+';
1374
-					}
1375
-				  	$tableCell.='<input type="text" alt="'.($disabledtask?'':$alttitle).'" title="'.($disabledtask?'':$alttitle).'" '.($disabledtask?'disabled':$placeholder).' class="center smallpadd" size="2" id="timeadded['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="" cols="2"  maxlength="5"';
1376
-					$tableCell.=' onkeypress="return regexEvent(this,event,\'timeChar\')"';
1377
-				   	$tableCell.=' onkeyup="updateTotal('.$idw.',\''.$modeinput.'\')"';
1378
-				   	$tableCell.=' onblur="regexEvent(this,event,\''.$modeinput.'\'); updateTotal('.$idw.',\''.$modeinput.'\')" />';
1379
-				   	$tableCell.='</td>';
1380
-					print $tableCell;
1381
-				}
1382
-
1383
-				// Warning
1384
-				print '<td align="right">';
1385
-   				if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("UserIsNotContactOfProject"));
1386
-   				else if ($disabledtask)
1387
-   				{
1388
-   					$titleassigntask = $langs->trans("AssignTaskToMe");
1389
-   					if ($fuser->id != $user->id) $titleassigntask = $langs->trans("AssignTaskToUser", '...');
1390
-
1391
-   					print $form->textwithpicto('',$langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
1392
-   				}
1393
-				print '</td>';
1394
-
1395
-				print "</tr>\n";
1396
-			}
1397
-
1398
-			// Call to show task with a lower level (task under the current task)
1399
-			$inc++;
1400
-			$level++;
1401
-			if ($lines[$i]->id > 0)
1402
-			{
1403
-				//var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level);
1404
-				//var_dump($totalforeachday);
1405
-				$ret = projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $isavailable, $oldprojectforbreak);
1406
-				//var_dump('ret with parent='.$lines[$i]->id.' level='.$level);
1407
-				//var_dump($ret);
1408
-				foreach($ret as $key => $val)
1409
-				{
1410
-					$totalforeachday[$key]+=$val;
1411
-				}
1412
-				//var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level.' + subtasks');
1413
-				//var_dump($totalforeachday);
1414
-			}
1415
-			$level--;
1416
-		}
1417
-		else
1418
-		{
1419
-			//$level--;
1420
-		}
1421
-	}
1422
-
1423
-	return $totalforeachday;
1278
+                // Ref
1279
+                print '<td class="nowrap">';
1280
+                print '<!-- Task id = '.$lines[$i]->id.' -->';
1281
+                for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
1282
+                print $taskstatic->getNomUrl(1, 'withproject', 'time');
1283
+                // Label task
1284
+                print '<br>';
1285
+                for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
1286
+                //print $taskstatic->getNomUrl(0, 'withproject', 'time');
1287
+                print $taskstatic->label;
1288
+                //print "<br>";
1289
+                //for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
1290
+                //print get_date_range($lines[$i]->date_start,$lines[$i]->date_end,'',$langs,0);
1291
+                print "</td>\n";
1292
+
1293
+                // Planned Workload
1294
+                print '<td align="right" class="leftborder plannedworkload">';
1295
+                if ($lines[$i]->planned_workload) print convertSecondToTime($lines[$i]->planned_workload,'allhourmin');
1296
+                else print '--:--';
1297
+                print '</td>';
1298
+
1299
+                // Progress declared %
1300
+                print '<td align="right">';
1301
+                print $formother->select_percent($lines[$i]->progress, $lines[$i]->id . 'progress');
1302
+                print '</td>';
1303
+
1304
+                // Time spent by everybody
1305
+                print '<td align="right">';
1306
+                // $lines[$i]->duration is a denormalised field = summ of time spent by everybody for task. What we need is time consummed by user
1307
+                if ($lines[$i]->duration)
1308
+                {
1309
+                    print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
1310
+                    print convertSecondToTime($lines[$i]->duration,'allhourmin');
1311
+                    print '</a>';
1312
+                }
1313
+                else print '--:--';
1314
+                print "</td>\n";
1315
+
1316
+                // Time spent by user
1317
+                print '<td align="right">';
1318
+                $tmptimespent=$taskstatic->getSummaryOfTimeSpent($fuser->id);
1319
+                if ($tmptimespent['total_duration']) print convertSecondToTime($tmptimespent['total_duration'],'allhourmin');
1320
+                else print '--:--';
1321
+                print "</td>\n";
1322
+
1323
+                $disabledproject=1;$disabledtask=1;
1324
+                //print "x".$lines[$i]->fk_project;
1325
+                //var_dump($lines[$i]);
1326
+                //var_dump($projectsrole[$lines[$i]->fk_project]);
1327
+                // If at least one role for project
1328
+                if ($lines[$i]->public || ! empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer)
1329
+                {
1330
+                    $disabledproject=0;
1331
+                    $disabledtask=0;
1332
+                }
1333
+                // If $restricteditformytask is on and I have no role on task, i disable edit
1334
+                if ($restricteditformytask && empty($tasksrole[$lines[$i]->id]))
1335
+                {
1336
+                    $disabledtask=1;
1337
+                }
1338
+
1339
+                //var_dump($projectstatic->weekWorkLoadPerTask);
1340
+
1341
+                // Fields to show current time
1342
+                $tableCell=''; $modeinput='hours';
1343
+                for ($idw = 0; $idw < 7; $idw++)
1344
+                {
1345
+                    $tmpday=dol_time_plus_duree($firstdaytoshow, $idw, 'd');
1346
+
1347
+                    $cssonholiday='';
1348
+                    if (! $isavailable[$tmpday]['morning'] && ! $isavailable[$tmpday]['afternoon'])   $cssonholiday.='onholidayallday ';
1349
+                    elseif (! $isavailable[$tmpday]['morning'])   $cssonholiday.='onholidaymorning ';
1350
+                    elseif (! $isavailable[$tmpday]['afternoon']) $cssonholiday.='onholidayafternoon ';
1351
+
1352
+                    $tmparray=dol_getdate($tmpday);
1353
+                    $dayWorkLoad = $projectstatic->weekWorkLoadPerTask[$tmpday][$lines[$i]->id];
1354
+                    $totalforeachday[$tmpday]+=$dayWorkLoad;
1355
+
1356
+                    $alreadyspent='';
1357
+                    if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($dayWorkLoad,'allhourmin');
1358
+                    $alttitle=$langs->trans("AddHereTimeSpentForDay",$tmparray['day'],$tmparray['mon']);
1359
+
1360
+                    global $numstartworkingday, $numendworkingday;
1361
+                    $cssweekend='';
1362
+                    if (($idw + 1) < $numstartworkingday || ($idw + 1) > $numendworkingday)	// This is a day is not inside the setup of working days, so we use a week-end css.
1363
+                    {
1364
+                        $cssweekend='weekend';
1365
+                    }
1366
+
1367
+                    $tableCell ='<td align="center" class="hide'.$idw.($cssonholiday?' '.$cssonholiday:'').($cssweekend?' '.$cssweekend:'').'">';
1368
+                    $placeholder='';
1369
+                    if ($alreadyspent)
1370
+                    {
1371
+                        $tableCell.='<span class="timesheetalreadyrecorded" title="texttoreplace"><input type="text" class="center smallpadd" size="2" disabled id="timespent['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="'.$alreadyspent.'"></span>';
1372
+                        //$placeholder=' placeholder="00:00"';
1373
+                            //$tableCell.='+';
1374
+                    }
1375
+                        $tableCell.='<input type="text" alt="'.($disabledtask?'':$alttitle).'" title="'.($disabledtask?'':$alttitle).'" '.($disabledtask?'disabled':$placeholder).' class="center smallpadd" size="2" id="timeadded['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="" cols="2"  maxlength="5"';
1376
+                    $tableCell.=' onkeypress="return regexEvent(this,event,\'timeChar\')"';
1377
+                        $tableCell.=' onkeyup="updateTotal('.$idw.',\''.$modeinput.'\')"';
1378
+                        $tableCell.=' onblur="regexEvent(this,event,\''.$modeinput.'\'); updateTotal('.$idw.',\''.$modeinput.'\')" />';
1379
+                        $tableCell.='</td>';
1380
+                    print $tableCell;
1381
+                }
1382
+
1383
+                // Warning
1384
+                print '<td align="right">';
1385
+                    if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("UserIsNotContactOfProject"));
1386
+                    else if ($disabledtask)
1387
+                    {
1388
+                        $titleassigntask = $langs->trans("AssignTaskToMe");
1389
+                        if ($fuser->id != $user->id) $titleassigntask = $langs->trans("AssignTaskToUser", '...');
1390
+
1391
+                        print $form->textwithpicto('',$langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
1392
+                    }
1393
+                print '</td>';
1394
+
1395
+                print "</tr>\n";
1396
+            }
1397
+
1398
+            // Call to show task with a lower level (task under the current task)
1399
+            $inc++;
1400
+            $level++;
1401
+            if ($lines[$i]->id > 0)
1402
+            {
1403
+                //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level);
1404
+                //var_dump($totalforeachday);
1405
+                $ret = projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $isavailable, $oldprojectforbreak);
1406
+                //var_dump('ret with parent='.$lines[$i]->id.' level='.$level);
1407
+                //var_dump($ret);
1408
+                foreach($ret as $key => $val)
1409
+                {
1410
+                    $totalforeachday[$key]+=$val;
1411
+                }
1412
+                //var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level.' + subtasks');
1413
+                //var_dump($totalforeachday);
1414
+            }
1415
+            $level--;
1416
+        }
1417
+        else
1418
+        {
1419
+            //$level--;
1420
+        }
1421
+    }
1422
+
1423
+    return $totalforeachday;
1424 1424
 }
1425 1425
 
1426 1426
 
@@ -1435,29 +1435,29 @@  discard block
 block discarded – undo
1435 1435
  */
1436 1436
 function searchTaskInChild(&$inc, $parent, &$lines, &$taskrole)
1437 1437
 {
1438
-	//print 'Search in line with parent id = '.$parent.'<br>';
1439
-	$numlines=count($lines);
1440
-	for ($i = 0 ; $i < $numlines ; $i++)
1441
-	{
1442
-		// Process line $lines[$i]
1443
-		if ($lines[$i]->fk_parent == $parent && $lines[$i]->id != $lines[$i]->fk_parent)
1444
-		{
1445
-			// If task is legitimate to show, no more need to search deeper
1446
-			if (isset($taskrole[$lines[$i]->id]))
1447
-			{
1448
-				//print 'Found a legitimate task id='.$lines[$i]->id.'<br>';
1449
-				$inc++;
1450
-				return $inc;
1451
-			}
1452
-
1453
-			searchTaskInChild($inc, $lines[$i]->id, $lines, $taskrole);
1454
-			//print 'Found inc='.$inc.'<br>';
1455
-
1456
-			if ($inc > 0) return $inc;
1457
-		}
1458
-	}
1459
-
1460
-	return $inc;
1438
+    //print 'Search in line with parent id = '.$parent.'<br>';
1439
+    $numlines=count($lines);
1440
+    for ($i = 0 ; $i < $numlines ; $i++)
1441
+    {
1442
+        // Process line $lines[$i]
1443
+        if ($lines[$i]->fk_parent == $parent && $lines[$i]->id != $lines[$i]->fk_parent)
1444
+        {
1445
+            // If task is legitimate to show, no more need to search deeper
1446
+            if (isset($taskrole[$lines[$i]->id]))
1447
+            {
1448
+                //print 'Found a legitimate task id='.$lines[$i]->id.'<br>';
1449
+                $inc++;
1450
+                return $inc;
1451
+            }
1452
+
1453
+            searchTaskInChild($inc, $lines[$i]->id, $lines, $taskrole);
1454
+            //print 'Found inc='.$inc.'<br>';
1455
+
1456
+            if ($inc > 0) return $inc;
1457
+        }
1458
+    }
1459
+
1460
+    return $inc;
1461 1461
 }
1462 1462
 
1463 1463
 /**
@@ -1475,235 +1475,235 @@  discard block
 block discarded – undo
1475 1475
  */
1476 1476
 function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks=0, $statut=-1, $listofoppstatus=array(),$hiddenfields=array())
1477 1477
 {
1478
-	global $langs,$conf,$user,$bc;
1479
-
1480
-	require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
1481
-
1482
-	$projectstatic=new Project($db);
1483
-	$thirdpartystatic=new Societe($db);
1484
-
1485
-	$sortfield='';
1486
-	$sortorder='';
1487
-	$project_year_filter=0;
1488
-
1489
-	$title=$langs->trans("Projects");
1490
-	if (strcmp($statut, '') && $statut >= 0) $title=$langs->trans("Projects").' '.$langs->trans($projectstatic->statuts_long[$statut]);
1491
-
1492
-	$arrayidtypeofcontact=array();
1493
-
1494
-	print '<div class="div-table-responsive-no-min">';
1495
-	print '<table class="noborder" width="100%">';
1496
-
1497
-	$sql= " FROM ".MAIN_DB_PREFIX."projet as p";
1498
-	if ($mytasks)
1499
-	{
1500
-		$sql.= ", ".MAIN_DB_PREFIX."projet_task as t";
1501
-		$sql.= ", ".MAIN_DB_PREFIX."element_contact as ec";
1502
-		$sql.= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
1503
-	}
1504
-	else
1505
-	{
1506
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t ON p.rowid = t.fk_projet";
1507
-	}
1508
-	$sql.= " WHERE p.entity IN (".getEntity('project').")";
1509
-	$sql.= " AND p.rowid IN (".$projectsListId.")";
1510
-	if ($socid) $sql.= "  AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
1511
-	if ($mytasks)
1512
-	{
1513
-		$sql.= " AND p.rowid = t.fk_projet";
1514
-		$sql.= " AND ec.element_id = t.rowid";
1515
-		$sql.= " AND ec.fk_socpeople = ".$user->id;
1516
-		$sql.= " AND ec.fk_c_type_contact = ctc.rowid";   // Replace the 2 lines with ec.fk_c_type_contact in $arrayidtypeofcontact
1517
-		$sql.= " AND ctc.element = 'project_task'";
1518
-	}
1519
-	if ($statut >= 0)
1520
-	{
1521
-		$sql.= " AND p.fk_statut = ".$statut;
1522
-	}
1523
-	if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE))
1524
-	{
1525
-		$project_year_filter = GETPOST("project_year_filter");
1526
-		//Check if empty or invalid year. Wildcard ignores the sql check
1527
-		if ($project_year_filter != "*")
1528
-		{
1529
-			if (empty($project_year_filter) || !ctype_digit($project_year_filter))
1530
-			{
1531
-				$project_year_filter = date("Y");
1532
-			}
1533
-			$sql.= " AND (p.dateo IS NULL OR p.dateo <= ".$db->idate(dol_get_last_day($project_year_filter,12,false)).")";
1534
-			$sql.= " AND (p.datee IS NULL OR p.datee >= ".$db->idate(dol_get_first_day($project_year_filter,1,false)).")";
1535
-		}
1536
-	}
1537
-
1538
-	// Get id of project we must show tasks
1539
-	$arrayidofprojects=array();
1540
-	$sql1 = "SELECT p.rowid as projectid";
1541
-	$sql1.= $sql;
1542
-	$resql = $db->query($sql1);
1543
-	if ($resql)
1544
-	{
1545
-		$i=0;
1546
-		$num = $db->num_rows($resql);
1547
-		while ($i < $num)
1548
-		{
1549
-			$objp = $db->fetch_object($resql);
1550
-			$arrayidofprojects[$objp->projectid]=$objp->projectid;
1551
-			$i++;
1552
-		}
1553
-	}
1554
-	else dol_print_error($db);
1555
-	if (empty($arrayidofprojects)) $arrayidofprojects[0]=-1;
1556
-
1557
-	// Get list of project with calculation on tasks
1558
-	$sql2 = "SELECT p.rowid as projectid, p.ref, p.title, p.fk_soc, s.nom as socname, p.fk_user_creat, p.public, p.fk_statut as status, p.fk_opp_status as opp_status, p.opp_amount,";
1559
-	$sql2.= " p.dateo, p.datee,";
1560
-	$sql2.= " COUNT(t.rowid) as nb, SUM(t.planned_workload) as planned_workload, SUM(t.planned_workload * t.progress / 100) as declared_progess_workload";
1561
-	$sql2.= " FROM ".MAIN_DB_PREFIX."projet as p";
1562
-	$sql2.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
1563
-	$sql2.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t ON p.rowid = t.fk_projet";
1564
-	$sql2.= " WHERE p.rowid IN (".join(',',$arrayidofprojects).")";
1565
-	$sql2.= " GROUP BY p.rowid, p.ref, p.title, p.fk_soc, s.nom, p.fk_user_creat, p.public, p.fk_statut, p.fk_opp_status, p.opp_amount, p.dateo, p.datee";
1566
-	$sql2.= " ORDER BY p.title, p.ref";
1567
-
1568
-	$resql = $db->query($sql2);
1569
-	if ($resql)
1570
-	{
1571
-	   $total_task = 0;
1572
-		$total_opp_amount = 0;
1573
-		$ponderated_opp_amount = 0;
1574
-
1575
-		$num = $db->num_rows($resql);
1576
-		$i = 0;
1577
-
1578
-		print '<tr class="liste_titre">';
1579
-		print_liste_field_titre($title.' <span class="badge">'.$num.'</span>',$_SERVER["PHP_SELF"],"","","","",$sortfield,$sortorder);
1580
-		print_liste_field_titre("ThirdParty",$_SERVER["PHP_SELF"],"","","","",$sortfield,$sortorder);
1581
-		if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
1582
-		{
1583
-			print_liste_field_titre("OpportunityAmount","","","","",'align="right"',$sortfield,$sortorder);
1584
-			print_liste_field_titre("OpportunityStatus","","","","",'align="right"',$sortfield,$sortorder);
1585
-		}
1586
-		if (empty($conf->global->PROJECT_HIDE_TASKS))
1587
-		{
1588
-			print_liste_field_titre("Tasks","","","","",'align="right"',$sortfield,$sortorder);
1589
-			if (! in_array('plannedworkload', $hiddenfields))  print_liste_field_titre("PlannedWorkload","","","","",'align="right"',$sortfield,$sortorder);
1590
-			if (! in_array('declaredprogress', $hiddenfields)) print_liste_field_titre("ProgressDeclared","","","","",'align="right"',$sortfield,$sortorder);
1591
-		}
1592
-		print_liste_field_titre("Status","","","","",'align="right"',$sortfield,$sortorder);
1593
-		print "</tr>\n";
1594
-
1595
-		$total_plannedworkload=0;
1596
-		$total_declaredprogressworkload=0;
1597
-		while ($i < $num)
1598
-		{
1599
-			$objp = $db->fetch_object($resql);
1600
-
1601
-			$projectstatic->id = $objp->projectid;
1602
-			$projectstatic->user_author_id = $objp->fk_user_creat;
1603
-			$projectstatic->public = $objp->public;
1604
-
1605
-			// Check is user has read permission on project
1606
-			$userAccess = $projectstatic->restrictedProjectArea($user);
1607
-			if ($userAccess >= 0)
1608
-			{
1609
-				$projectstatic->ref=$objp->ref;
1610
-				$projectstatic->statut = $objp->status;
1611
-				$projectstatic->title = $objp->title;
1612
-				$projectstatic->datee = $db->jdate($objp->datee);
1613
-				$projectstatic->dateo = $db->jdate($objp->dateo);
1614
-
1615
-
1616
-				print '<tr class="oddeven">';
1617
-				print '<td>';
1618
-				print $projectstatic->getNomUrl(1);
1619
-				if (! in_array('projectlabel', $hiddenfields)) print '<br>'.dol_trunc($objp->title,24);
1620
-				print '</td>';
1621
-				print '<td>';
1622
-				if ($objp->fk_soc > 0)
1623
-				{
1624
-					$thirdpartystatic->id=$objp->fk_soc;
1625
-					$thirdpartystatic->ref=$objp->socname;
1626
-					$thirdpartystatic->name=$objp->socname;
1627
-					print $thirdpartystatic->getNomUrl(1);
1628
-				}
1629
-				print '</td>';
1630
-				if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
1631
-				{
1632
-					print '<td align="right">';
1633
-					if ($objp->opp_amount) print price($objp->opp_amount, 0, '', 1, -1, -1, $conf->currency);
1634
-					print '</td>';
1635
-					print '<td align="right">';
1636
-					$code = dol_getIdFromCode($db, $objp->opp_status, 'c_lead_status', 'rowid', 'code');
1637
-					if ($code) print $langs->trans("OppStatus".$code);
1638
-					print '</td>';
1639
-				}
1640
-				if (empty($conf->global->PROJECT_HIDE_TASKS))
1641
-				{
1642
-					print '<td align="right">'.$objp->nb.'</td>';
1643
-
1644
-					$plannedworkload=$objp->planned_workload;
1645
-					$total_plannedworkload+=$plannedworkload;
1646
-					if (! in_array('plannedworkload', $hiddenfields))
1647
-					{
1648
-						print '<td align="right">'.($plannedworkload?convertSecondToTime($plannedworkload):'').'</td>';
1649
-					}
1650
-					if (! in_array('declaredprogress', $hiddenfields))
1651
-					{
1652
-						$declaredprogressworkload=$objp->declared_progess_workload;
1653
-						$total_declaredprogressworkload+=$declaredprogressworkload;
1654
-						print '<td align="right">';
1655
-						//print $objp->planned_workload.'-'.$objp->declared_progess_workload."<br>";
1656
-						print ($plannedworkload?round(100*$declaredprogressworkload/$plannedworkload,0).'%':'');
1657
-						print '</td>';
1658
-					}
1659
-				}
1660
-
1661
-				print '<td align="right">'.$projectstatic->getLibStatut(3).'</td>';
1662
-				print "</tr>\n";
1663
-
1664
-				$total_task = $total_task + $objp->nb;
1665
-				$total_opp_amount = $total_opp_amount + $objp->opp_amount;
1666
-				$ponderated_opp_amount = $ponderated_opp_amount + price2num($listofoppstatus[$objp->opp_status] * $objp->opp_amount / 100);
1667
-			}
1668
-
1669
-			$i++;
1670
-		}
1671
-
1672
-		print '<tr class="liste_total">';
1673
-		print '<td colspan="2">'.$langs->trans("Total")."</td>";
1674
-		if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
1675
-		{
1676
-			print '<td class="liste_total" align="right">'.price($total_opp_amount, 0, '', 1, -1, -1, $conf->currency).'</td>';
1677
-			print '<td class="liste_total" align="right">'.$form->textwithpicto(price($ponderated_opp_amount, 0, '', 1, -1, -1, $conf->currency), $langs->trans("OpportunityPonderatedAmountDesc"), 1).'</td>';
1678
-		}
1679
-		if (empty($conf->global->PROJECT_HIDE_TASKS))
1680
-		{
1681
-			print '<td class="liste_total" align="right">'.$total_task.'</td>';
1682
-			if (! in_array('plannedworkload', $hiddenfields))  print '<td class="liste_total" align="right">'.($total_plannedworkload?convertSecondToTime($total_plannedworkload):'').'</td>';
1683
-			if (! in_array('declaredprogress', $hiddenfields)) print '<td class="liste_total" align="right">'.($total_plannedworkload?round(100*$total_declaredprogressworkload/$total_plannedworkload,0).'%':'').'</td>';
1684
-		}
1685
-		print '<td class="liste_total"></td>';
1686
-		print '</tr>';
1687
-
1688
-		$db->free($resql);
1689
-	}
1690
-	else
1691
-	{
1692
-		dol_print_error($db);
1693
-	}
1694
-
1695
-	print "</table>";
1696
-	print '</div>';
1697
-
1698
-	if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE))
1699
-	{
1700
-		//Add the year filter input
1701
-		print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">';
1702
-		print '<table width="100%">';
1703
-		print '<tr>';
1704
-		print '<td>'.$langs->trans("Year").'</td>';
1705
-		print '<td style="text-align:right"><input type="text" size="4" class="flat" name="project_year_filter" value="'.$project_year_filter.'"/>';
1706
-		print "</tr>\n";
1707
-		print '</table></form>';
1708
-	}
1478
+    global $langs,$conf,$user,$bc;
1479
+
1480
+    require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
1481
+
1482
+    $projectstatic=new Project($db);
1483
+    $thirdpartystatic=new Societe($db);
1484
+
1485
+    $sortfield='';
1486
+    $sortorder='';
1487
+    $project_year_filter=0;
1488
+
1489
+    $title=$langs->trans("Projects");
1490
+    if (strcmp($statut, '') && $statut >= 0) $title=$langs->trans("Projects").' '.$langs->trans($projectstatic->statuts_long[$statut]);
1491
+
1492
+    $arrayidtypeofcontact=array();
1493
+
1494
+    print '<div class="div-table-responsive-no-min">';
1495
+    print '<table class="noborder" width="100%">';
1496
+
1497
+    $sql= " FROM ".MAIN_DB_PREFIX."projet as p";
1498
+    if ($mytasks)
1499
+    {
1500
+        $sql.= ", ".MAIN_DB_PREFIX."projet_task as t";
1501
+        $sql.= ", ".MAIN_DB_PREFIX."element_contact as ec";
1502
+        $sql.= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
1503
+    }
1504
+    else
1505
+    {
1506
+        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t ON p.rowid = t.fk_projet";
1507
+    }
1508
+    $sql.= " WHERE p.entity IN (".getEntity('project').")";
1509
+    $sql.= " AND p.rowid IN (".$projectsListId.")";
1510
+    if ($socid) $sql.= "  AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
1511
+    if ($mytasks)
1512
+    {
1513
+        $sql.= " AND p.rowid = t.fk_projet";
1514
+        $sql.= " AND ec.element_id = t.rowid";
1515
+        $sql.= " AND ec.fk_socpeople = ".$user->id;
1516
+        $sql.= " AND ec.fk_c_type_contact = ctc.rowid";   // Replace the 2 lines with ec.fk_c_type_contact in $arrayidtypeofcontact
1517
+        $sql.= " AND ctc.element = 'project_task'";
1518
+    }
1519
+    if ($statut >= 0)
1520
+    {
1521
+        $sql.= " AND p.fk_statut = ".$statut;
1522
+    }
1523
+    if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE))
1524
+    {
1525
+        $project_year_filter = GETPOST("project_year_filter");
1526
+        //Check if empty or invalid year. Wildcard ignores the sql check
1527
+        if ($project_year_filter != "*")
1528
+        {
1529
+            if (empty($project_year_filter) || !ctype_digit($project_year_filter))
1530
+            {
1531
+                $project_year_filter = date("Y");
1532
+            }
1533
+            $sql.= " AND (p.dateo IS NULL OR p.dateo <= ".$db->idate(dol_get_last_day($project_year_filter,12,false)).")";
1534
+            $sql.= " AND (p.datee IS NULL OR p.datee >= ".$db->idate(dol_get_first_day($project_year_filter,1,false)).")";
1535
+        }
1536
+    }
1537
+
1538
+    // Get id of project we must show tasks
1539
+    $arrayidofprojects=array();
1540
+    $sql1 = "SELECT p.rowid as projectid";
1541
+    $sql1.= $sql;
1542
+    $resql = $db->query($sql1);
1543
+    if ($resql)
1544
+    {
1545
+        $i=0;
1546
+        $num = $db->num_rows($resql);
1547
+        while ($i < $num)
1548
+        {
1549
+            $objp = $db->fetch_object($resql);
1550
+            $arrayidofprojects[$objp->projectid]=$objp->projectid;
1551
+            $i++;
1552
+        }
1553
+    }
1554
+    else dol_print_error($db);
1555
+    if (empty($arrayidofprojects)) $arrayidofprojects[0]=-1;
1556
+
1557
+    // Get list of project with calculation on tasks
1558
+    $sql2 = "SELECT p.rowid as projectid, p.ref, p.title, p.fk_soc, s.nom as socname, p.fk_user_creat, p.public, p.fk_statut as status, p.fk_opp_status as opp_status, p.opp_amount,";
1559
+    $sql2.= " p.dateo, p.datee,";
1560
+    $sql2.= " COUNT(t.rowid) as nb, SUM(t.planned_workload) as planned_workload, SUM(t.planned_workload * t.progress / 100) as declared_progess_workload";
1561
+    $sql2.= " FROM ".MAIN_DB_PREFIX."projet as p";
1562
+    $sql2.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
1563
+    $sql2.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t ON p.rowid = t.fk_projet";
1564
+    $sql2.= " WHERE p.rowid IN (".join(',',$arrayidofprojects).")";
1565
+    $sql2.= " GROUP BY p.rowid, p.ref, p.title, p.fk_soc, s.nom, p.fk_user_creat, p.public, p.fk_statut, p.fk_opp_status, p.opp_amount, p.dateo, p.datee";
1566
+    $sql2.= " ORDER BY p.title, p.ref";
1567
+
1568
+    $resql = $db->query($sql2);
1569
+    if ($resql)
1570
+    {
1571
+        $total_task = 0;
1572
+        $total_opp_amount = 0;
1573
+        $ponderated_opp_amount = 0;
1574
+
1575
+        $num = $db->num_rows($resql);
1576
+        $i = 0;
1577
+
1578
+        print '<tr class="liste_titre">';
1579
+        print_liste_field_titre($title.' <span class="badge">'.$num.'</span>',$_SERVER["PHP_SELF"],"","","","",$sortfield,$sortorder);
1580
+        print_liste_field_titre("ThirdParty",$_SERVER["PHP_SELF"],"","","","",$sortfield,$sortorder);
1581
+        if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
1582
+        {
1583
+            print_liste_field_titre("OpportunityAmount","","","","",'align="right"',$sortfield,$sortorder);
1584
+            print_liste_field_titre("OpportunityStatus","","","","",'align="right"',$sortfield,$sortorder);
1585
+        }
1586
+        if (empty($conf->global->PROJECT_HIDE_TASKS))
1587
+        {
1588
+            print_liste_field_titre("Tasks","","","","",'align="right"',$sortfield,$sortorder);
1589
+            if (! in_array('plannedworkload', $hiddenfields))  print_liste_field_titre("PlannedWorkload","","","","",'align="right"',$sortfield,$sortorder);
1590
+            if (! in_array('declaredprogress', $hiddenfields)) print_liste_field_titre("ProgressDeclared","","","","",'align="right"',$sortfield,$sortorder);
1591
+        }
1592
+        print_liste_field_titre("Status","","","","",'align="right"',$sortfield,$sortorder);
1593
+        print "</tr>\n";
1594
+
1595
+        $total_plannedworkload=0;
1596
+        $total_declaredprogressworkload=0;
1597
+        while ($i < $num)
1598
+        {
1599
+            $objp = $db->fetch_object($resql);
1600
+
1601
+            $projectstatic->id = $objp->projectid;
1602
+            $projectstatic->user_author_id = $objp->fk_user_creat;
1603
+            $projectstatic->public = $objp->public;
1604
+
1605
+            // Check is user has read permission on project
1606
+            $userAccess = $projectstatic->restrictedProjectArea($user);
1607
+            if ($userAccess >= 0)
1608
+            {
1609
+                $projectstatic->ref=$objp->ref;
1610
+                $projectstatic->statut = $objp->status;
1611
+                $projectstatic->title = $objp->title;
1612
+                $projectstatic->datee = $db->jdate($objp->datee);
1613
+                $projectstatic->dateo = $db->jdate($objp->dateo);
1614
+
1615
+
1616
+                print '<tr class="oddeven">';
1617
+                print '<td>';
1618
+                print $projectstatic->getNomUrl(1);
1619
+                if (! in_array('projectlabel', $hiddenfields)) print '<br>'.dol_trunc($objp->title,24);
1620
+                print '</td>';
1621
+                print '<td>';
1622
+                if ($objp->fk_soc > 0)
1623
+                {
1624
+                    $thirdpartystatic->id=$objp->fk_soc;
1625
+                    $thirdpartystatic->ref=$objp->socname;
1626
+                    $thirdpartystatic->name=$objp->socname;
1627
+                    print $thirdpartystatic->getNomUrl(1);
1628
+                }
1629
+                print '</td>';
1630
+                if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
1631
+                {
1632
+                    print '<td align="right">';
1633
+                    if ($objp->opp_amount) print price($objp->opp_amount, 0, '', 1, -1, -1, $conf->currency);
1634
+                    print '</td>';
1635
+                    print '<td align="right">';
1636
+                    $code = dol_getIdFromCode($db, $objp->opp_status, 'c_lead_status', 'rowid', 'code');
1637
+                    if ($code) print $langs->trans("OppStatus".$code);
1638
+                    print '</td>';
1639
+                }
1640
+                if (empty($conf->global->PROJECT_HIDE_TASKS))
1641
+                {
1642
+                    print '<td align="right">'.$objp->nb.'</td>';
1643
+
1644
+                    $plannedworkload=$objp->planned_workload;
1645
+                    $total_plannedworkload+=$plannedworkload;
1646
+                    if (! in_array('plannedworkload', $hiddenfields))
1647
+                    {
1648
+                        print '<td align="right">'.($plannedworkload?convertSecondToTime($plannedworkload):'').'</td>';
1649
+                    }
1650
+                    if (! in_array('declaredprogress', $hiddenfields))
1651
+                    {
1652
+                        $declaredprogressworkload=$objp->declared_progess_workload;
1653
+                        $total_declaredprogressworkload+=$declaredprogressworkload;
1654
+                        print '<td align="right">';
1655
+                        //print $objp->planned_workload.'-'.$objp->declared_progess_workload."<br>";
1656
+                        print ($plannedworkload?round(100*$declaredprogressworkload/$plannedworkload,0).'%':'');
1657
+                        print '</td>';
1658
+                    }
1659
+                }
1660
+
1661
+                print '<td align="right">'.$projectstatic->getLibStatut(3).'</td>';
1662
+                print "</tr>\n";
1663
+
1664
+                $total_task = $total_task + $objp->nb;
1665
+                $total_opp_amount = $total_opp_amount + $objp->opp_amount;
1666
+                $ponderated_opp_amount = $ponderated_opp_amount + price2num($listofoppstatus[$objp->opp_status] * $objp->opp_amount / 100);
1667
+            }
1668
+
1669
+            $i++;
1670
+        }
1671
+
1672
+        print '<tr class="liste_total">';
1673
+        print '<td colspan="2">'.$langs->trans("Total")."</td>";
1674
+        if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
1675
+        {
1676
+            print '<td class="liste_total" align="right">'.price($total_opp_amount, 0, '', 1, -1, -1, $conf->currency).'</td>';
1677
+            print '<td class="liste_total" align="right">'.$form->textwithpicto(price($ponderated_opp_amount, 0, '', 1, -1, -1, $conf->currency), $langs->trans("OpportunityPonderatedAmountDesc"), 1).'</td>';
1678
+        }
1679
+        if (empty($conf->global->PROJECT_HIDE_TASKS))
1680
+        {
1681
+            print '<td class="liste_total" align="right">'.$total_task.'</td>';
1682
+            if (! in_array('plannedworkload', $hiddenfields))  print '<td class="liste_total" align="right">'.($total_plannedworkload?convertSecondToTime($total_plannedworkload):'').'</td>';
1683
+            if (! in_array('declaredprogress', $hiddenfields)) print '<td class="liste_total" align="right">'.($total_plannedworkload?round(100*$total_declaredprogressworkload/$total_plannedworkload,0).'%':'').'</td>';
1684
+        }
1685
+        print '<td class="liste_total"></td>';
1686
+        print '</tr>';
1687
+
1688
+        $db->free($resql);
1689
+    }
1690
+    else
1691
+    {
1692
+        dol_print_error($db);
1693
+    }
1694
+
1695
+    print "</table>";
1696
+    print '</div>';
1697
+
1698
+    if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE))
1699
+    {
1700
+        //Add the year filter input
1701
+        print '<form method="get" action="'.$_SERVER["PHP_SELF"].'">';
1702
+        print '<table width="100%">';
1703
+        print '<tr>';
1704
+        print '<td>'.$langs->trans("Year").'</td>';
1705
+        print '<td style="text-align:right"><input type="text" size="4" class="flat" name="project_year_filter" value="'.$project_year_filter.'"/>';
1706
+        print "</tr>\n";
1707
+        print '</table></form>';
1708
+    }
1709 1709
 }
Please login to merge, or discard this patch.
Spacing   +355 added lines, -355 removed lines patch added patch discarded remove patch
@@ -45,10 +45,10 @@  discard block
 block discarded – undo
45 45
 	$head[$h][2] = 'project';
46 46
 	$h++;
47 47
 
48
-	$nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
48
+	$nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
49 49
 	$head[$h][0] = DOL_URL_ROOT.'/projet/contact.php?id='.$object->id;
50 50
 	$head[$h][1] = $langs->trans("ProjectContact");
51
-	if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
51
+	if ($nbContact > 0) $head[$h][1] .= ' <span class="badge">'.$nbContact.'</span>';
52 52
 	$head[$h][2] = 'contact';
53 53
 	$h++;
54 54
 
@@ -59,13 +59,13 @@  discard block
 block discarded – undo
59 59
 		$head[$h][1] = $langs->trans("Tasks");
60 60
 
61 61
 		require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
62
-		$taskstatic=new Task($db);
63
-		$nbTasks=count($taskstatic->getTasksArray(0, 0, $object->id, 0, 0));
64
-		if ($nbTasks > 0) $head[$h][1].= ' <span class="badge">'.($nbTasks).'</span>';
62
+		$taskstatic = new Task($db);
63
+		$nbTasks = count($taskstatic->getTasksArray(0, 0, $object->id, 0, 0));
64
+		if ($nbTasks > 0) $head[$h][1] .= ' <span class="badge">'.($nbTasks).'</span>';
65 65
 		$head[$h][2] = 'tasks';
66 66
 		$h++;
67 67
 
68
-		$nbTimeSpent=0;
68
+		$nbTimeSpent = 0;
69 69
 		$sql = "SELECT t.rowid";
70 70
 		//$sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t, ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."user as u";
71 71
 		//$sql .= " WHERE t.fk_user = u.rowid AND t.fk_task = pt.rowid";
@@ -76,20 +76,20 @@  discard block
 block discarded – undo
76 76
 		if ($resql)
77 77
 		{
78 78
 			$obj = $db->fetch_object($resql);
79
-			if ($obj) $nbTimeSpent=1;
79
+			if ($obj) $nbTimeSpent = 1;
80 80
 		}
81 81
 		else dol_print_error($db);
82 82
 
83 83
 		$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?withproject=1&projectid='.$object->id;
84 84
 		$head[$h][1] = $langs->trans("TimeSpent");
85
-		if ($nbTimeSpent > 0) $head[$h][1].= ' <span class="badge">...</span>';
85
+		if ($nbTimeSpent > 0) $head[$h][1] .= ' <span class="badge">...</span>';
86 86
 		$head[$h][2] = 'timespent';
87 87
 		$h++;
88 88
 	}
89 89
 
90
-	if (! empty($conf->fournisseur->enabled) || ! empty($conf->propal->enabled) || ! empty($conf->commande->enabled)
91
-		|| ! empty($conf->facture->enabled) || ! empty($conf->contrat->enabled)
92
-		|| ! empty($conf->ficheinter->enabled) || ! empty($conf->agenda->enabled) || ! empty($conf->deplacement->enabled))
90
+	if (!empty($conf->fournisseur->enabled) || !empty($conf->propal->enabled) || !empty($conf->commande->enabled)
91
+		|| !empty($conf->facture->enabled) || !empty($conf->contrat->enabled)
92
+		|| !empty($conf->ficheinter->enabled) || !empty($conf->agenda->enabled) || !empty($conf->deplacement->enabled))
93 93
 	{
94 94
 		$head[$h][0] = DOL_URL_ROOT.'/projet/element.php?id='.$object->id;
95 95
 		$head[$h][1] = $langs->trans("ProjectOverview");
@@ -101,29 +101,29 @@  discard block
 block discarded – undo
101 101
 	// Entries must be declared in modules descriptor with line
102 102
 	// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
103 103
 	// $this->tabs = array('entity:-tabname);   												to remove a tab
104
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'project');
104
+	complete_head_from_modules($conf, $langs, $object, $head, $h, 'project');
105 105
 
106 106
 
107 107
 	if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
108 108
 	{
109 109
 		$nbNote = 0;
110
-		if(!empty($object->note_private)) $nbNote++;
111
-		if(!empty($object->note_public)) $nbNote++;
110
+		if (!empty($object->note_private)) $nbNote++;
111
+		if (!empty($object->note_public)) $nbNote++;
112 112
 		$head[$h][0] = DOL_URL_ROOT.'/projet/note.php?id='.$object->id;
113 113
 		$head[$h][1] = $langs->trans('Notes');
114
-		if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
114
+		if ($nbNote > 0) $head[$h][1] .= ' <span class="badge">'.$nbNote.'</span>';
115 115
 		$head[$h][2] = 'notes';
116 116
 		$h++;
117 117
 	}
118 118
 
119 119
 	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
120 120
 	require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
121
-	$upload_dir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->ref);
122
-	$nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$'));
123
-	$nbLinks=Link::count($db, $object->element, $object->id);
121
+	$upload_dir = $conf->projet->dir_output."/".dol_sanitizeFileName($object->ref);
122
+	$nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
123
+	$nbLinks = Link::count($db, $object->element, $object->id);
124 124
 	$head[$h][0] = DOL_URL_ROOT.'/projet/document.php?id='.$object->id;
125 125
 	$head[$h][1] = $langs->trans('Documents');
126
-	if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
126
+	if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= ' <span class="badge">'.($nbFiles + $nbLinks).'</span>';
127 127
 	$head[$h][2] = 'document';
128 128
 	$h++;
129 129
 
@@ -133,22 +133,22 @@  discard block
 block discarded – undo
133 133
 		$nbComments = $object->getNbComments();
134 134
 		$head[$h][0] = DOL_URL_ROOT.'/projet/comment.php?id='.$object->id;
135 135
 		$head[$h][1] = $langs->trans("CommentLink");
136
-		if ($nbComments > 0) $head[$h][1].= ' <span class="badge">'.$nbComments.'</span>';
136
+		if ($nbComments > 0) $head[$h][1] .= ' <span class="badge">'.$nbComments.'</span>';
137 137
 		$head[$h][2] = 'project_comment';
138 138
 		$h++;
139 139
 	}
140 140
 
141 141
 	$head[$h][0] = DOL_URL_ROOT.'/projet/info.php?id='.$object->id;
142
-	$head[$h][1].= $langs->trans("Events");
143
-	if (! empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read) ))
142
+	$head[$h][1] .= $langs->trans("Events");
143
+	if (!empty($conf->agenda->enabled) && (!empty($user->rights->agenda->myactions->read) || !empty($user->rights->agenda->allactions->read)))
144 144
 	{
145
-		$head[$h][1].= '/';
146
-		$head[$h][1].= $langs->trans("Agenda");
145
+		$head[$h][1] .= '/';
146
+		$head[$h][1] .= $langs->trans("Agenda");
147 147
 	}
148 148
 	$head[$h][2] = 'agenda';
149 149
 	$h++;
150 150
 
151
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'project','remove');
151
+	complete_head_from_modules($conf, $langs, $object, $head, $h, 'project', 'remove');
152 152
 
153 153
 	return $head;
154 154
 }
@@ -166,20 +166,20 @@  discard block
 block discarded – undo
166 166
 	$h = 0;
167 167
 	$head = array();
168 168
 
169
-	$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/task.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
169
+	$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/task.php?id='.$object->id.(GETPOST('withproject') ? '&withproject=1' : '');
170 170
 	$head[$h][1] = $langs->trans("Card");
171 171
 	$head[$h][2] = 'task_task';
172 172
 	$h++;
173 173
 
174
-	$nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
175
-	$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/contact.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
174
+	$nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
175
+	$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/contact.php?id='.$object->id.(GETPOST('withproject') ? '&withproject=1' : '');
176 176
 	$head[$h][1] = $langs->trans("TaskRessourceLinks");
177
-	if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
177
+	if ($nbContact > 0) $head[$h][1] .= ' <span class="badge">'.$nbContact.'</span>';
178 178
 	$head[$h][2] = 'task_contact';
179 179
 	$h++;
180 180
 
181 181
 	// Is there timespent ?
182
-	$nbTimeSpent=0;
182
+	$nbTimeSpent = 0;
183 183
 	$sql = "SELECT t.rowid";
184 184
 	//$sql .= " FROM ".MAIN_DB_PREFIX."projet_task_time as t, ".MAIN_DB_PREFIX."projet_task as pt, ".MAIN_DB_PREFIX."user as u";
185 185
 	//$sql .= " WHERE t.fk_user = u.rowid AND t.fk_task = pt.rowid";
@@ -189,13 +189,13 @@  discard block
 block discarded – undo
189 189
 	if ($resql)
190 190
 	{
191 191
 		$obj = $db->fetch_object($resql);
192
-		if ($obj) $nbTimeSpent=1;
192
+		if ($obj) $nbTimeSpent = 1;
193 193
 	}
194 194
 	else dol_print_error($db);
195 195
 
196
-	$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
196
+	$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?id='.$object->id.(GETPOST('withproject') ? '&withproject=1' : '');
197 197
 	$head[$h][1] = $langs->trans("TimeSpent");
198
-	if ($nbTimeSpent > 0) $head[$h][1].= ' <span class="badge">...</span>';
198
+	if ($nbTimeSpent > 0) $head[$h][1] .= ' <span class="badge">...</span>';
199 199
 	$head[$h][2] = 'task_time';
200 200
 	$h++;
201 201
 
@@ -203,28 +203,28 @@  discard block
 block discarded – undo
203 203
 	// Entries must be declared in modules descriptor with line
204 204
 	// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
205 205
 	// $this->tabs = array('entity:-tabname);   												to remove a tab
206
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'task');
206
+	complete_head_from_modules($conf, $langs, $object, $head, $h, 'task');
207 207
 
208 208
 	if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
209 209
 	{
210 210
 		$nbNote = 0;
211
-		if(!empty($object->note_private)) $nbNote++;
212
-		if(!empty($object->note_public)) $nbNote++;
213
-		$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/note.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
211
+		if (!empty($object->note_private)) $nbNote++;
212
+		if (!empty($object->note_public)) $nbNote++;
213
+		$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/note.php?id='.$object->id.(GETPOST('withproject') ? '&withproject=1' : '');
214 214
 		$head[$h][1] = $langs->trans('Notes');
215
-		if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
215
+		if ($nbNote > 0) $head[$h][1] .= ' <span class="badge">'.$nbNote.'</span>';
216 216
 		$head[$h][2] = 'task_notes';
217 217
 		$h++;
218 218
 	}
219 219
 
220
-	$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/document.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
221
-	$filesdir = $conf->projet->dir_output . "/" . dol_sanitizeFileName($object->project->ref) . '/' .dol_sanitizeFileName($object->ref);
220
+	$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/document.php?id='.$object->id.(GETPOST('withproject') ? '&withproject=1' : '');
221
+	$filesdir = $conf->projet->dir_output."/".dol_sanitizeFileName($object->project->ref).'/'.dol_sanitizeFileName($object->ref);
222 222
 	include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
223 223
 	include_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
224
-	$nbFiles = count(dol_dir_list($filesdir,'files',0,'','(\.meta|_preview.*\.png)$'));
225
-	$nbLinks=Link::count($db, $object->element, $object->id);
224
+	$nbFiles = count(dol_dir_list($filesdir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
225
+	$nbLinks = Link::count($db, $object->element, $object->id);
226 226
 	$head[$h][1] = $langs->trans('Documents');
227
-	if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
227
+	if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= ' <span class="badge">'.($nbFiles + $nbLinks).'</span>';
228 228
 	$head[$h][2] = 'task_document';
229 229
 	$h++;
230 230
 
@@ -232,14 +232,14 @@  discard block
 block discarded – undo
232 232
 	if (!empty($conf->global->PROJECT_ALLOW_COMMENT_ON_TASK))
233 233
 	{
234 234
 		$nbComments = $object->getNbComments();
235
-		$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/comment.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
235
+		$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/comment.php?id='.$object->id.(GETPOST('withproject') ? '&withproject=1' : '');
236 236
 		$head[$h][1] = $langs->trans("CommentLink");
237
-		if ($nbComments > 0) $head[$h][1].= ' <span class="badge">'.$nbComments.'</span>';
237
+		if ($nbComments > 0) $head[$h][1] .= ' <span class="badge">'.$nbComments.'</span>';
238 238
 		$head[$h][2] = 'task_comment';
239 239
 		$h++;
240 240
 	}
241 241
 
242
-	complete_head_from_modules($conf,$langs,$object,$head,$h,'task','remove');
242
+	complete_head_from_modules($conf, $langs, $object, $head, $h, 'task', 'remove');
243 243
 
244 244
 	return $head;
245 245
 }
@@ -251,7 +251,7 @@  discard block
 block discarded – undo
251 251
  * @param   string  $fuser      Filter on user
252 252
  * @return  array				Array of tabs to show
253 253
  */
254
-function project_timesheet_prepare_head($mode, $fuser=null)
254
+function project_timesheet_prepare_head($mode, $fuser = null)
255 255
 {
256 256
 	global $langs, $conf, $user;
257 257
 	$h = 0;
@@ -259,13 +259,13 @@  discard block
 block discarded – undo
259 259
 
260 260
 	$h = 0;
261 261
 
262
-	$param='';
263
-	$param.=($mode?'&mode='.$mode:'');
264
-	if (is_object($fuser) && $fuser->id > 0 && $fuser->id != $user->id) $param.='&search_usertoprocessid='.$fuser->id;
262
+	$param = '';
263
+	$param .= ($mode ? '&mode='.$mode : '');
264
+	if (is_object($fuser) && $fuser->id > 0 && $fuser->id != $user->id) $param .= '&search_usertoprocessid='.$fuser->id;
265 265
 
266 266
 	if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERWEEK))
267 267
 	{
268
-		$head[$h][0] = DOL_URL_ROOT."/projet/activity/perweek.php".($param?'?'.$param:'');
268
+		$head[$h][0] = DOL_URL_ROOT."/projet/activity/perweek.php".($param ? '?'.$param : '');
269 269
 		$head[$h][1] = $langs->trans("InputPerWeek");
270 270
 		$head[$h][2] = 'inputperweek';
271 271
 		$h++;
@@ -273,7 +273,7 @@  discard block
 block discarded – undo
273 273
 
274 274
 	if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERTIME))
275 275
 	{
276
-		$head[$h][0] = DOL_URL_ROOT."/projet/activity/perday.php".($param?'?'.$param:'');
276
+		$head[$h][0] = DOL_URL_ROOT."/projet/activity/perday.php".($param ? '?'.$param : '');
277 277
 		$head[$h][1] = $langs->trans("InputPerDay");
278 278
 		$head[$h][2] = 'inputperday';
279 279
 		$h++;
@@ -287,9 +287,9 @@  discard block
 block discarded – undo
287 287
 		$h++;
288 288
 	}*/
289 289
 
290
-	complete_head_from_modules($conf,$langs,null,$head,$h,'project_timesheet');
290
+	complete_head_from_modules($conf, $langs, null, $head, $h, 'project_timesheet');
291 291
 
292
-	complete_head_from_modules($conf,$langs,null,$head,$h,'project_timesheet','remove');
292
+	complete_head_from_modules($conf, $langs, null, $head, $h, 'project_timesheet', 'remove');
293 293
 
294 294
 	return $head;
295 295
 }
@@ -313,7 +313,7 @@  discard block
 block discarded – undo
313 313
 	$head[$h][2] = 'project';
314 314
 	$h++;
315 315
 
316
-	complete_head_from_modules($conf,$langs,null,$head,$h,'project_admin');
316
+	complete_head_from_modules($conf, $langs, null, $head, $h, 'project_admin');
317 317
 
318 318
 	$head[$h][0] = DOL_URL_ROOT."/projet/admin/project_extrafields.php";
319 319
 	$head[$h][1] = $langs->trans("ExtraFieldsProject");
@@ -325,7 +325,7 @@  discard block
 block discarded – undo
325 325
 	$head[$h][2] = 'attributes_task';
326 326
 	$h++;
327 327
 
328
-	complete_head_from_modules($conf,$langs,null,$head,$h,'project_admin','remove');
328
+	complete_head_from_modules($conf, $langs, null, $head, $h, 'project_admin', 'remove');
329 329
 
330 330
 	return $head;
331 331
 }
@@ -347,15 +347,15 @@  discard block
 block discarded – undo
347 347
  * @param   string      $filterprogresscalc     filter text
348 348
  * @return	void
349 349
  */
350
-function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$taskrole, $projectsListId='', $addordertick=0, $projectidfortotallink=0, $filterprogresscalc='')
350
+function projectLinesa(&$inc, $parent, &$lines, &$level, $var, $showproject, &$taskrole, $projectsListId = '', $addordertick = 0, $projectidfortotallink = 0, $filterprogresscalc = '')
351 351
 {
352 352
 	global $user, $bc, $langs, $conf, $db;
353 353
 	global $projectstatic, $taskstatic;
354 354
 
355
-	$lastprojectid=0;
355
+	$lastprojectid = 0;
356 356
 
357
-	$projectsArrayId=explode(',',$projectsListId);
358
-	if ($filterprogresscalc!=='') {
357
+	$projectsArrayId = explode(',', $projectsListId);
358
+	if ($filterprogresscalc !== '') {
359 359
 		foreach ($lines as $key=>$line) {
360 360
 			if (!empty($line->planned_workload) && !empty($line->duration)) {
361 361
 				$filterprogresscalc = str_replace(' = ', ' == ', $filterprogresscalc);
@@ -364,23 +364,23 @@  discard block
 block discarded – undo
364 364
 				}
365 365
 			}
366 366
 		}
367
-		$lines=array_values($lines);
367
+		$lines = array_values($lines);
368 368
 	}
369 369
 
370
-	$numlines=count($lines);
370
+	$numlines = count($lines);
371 371
 
372 372
 	// We declare counter as global because we want to edit them into recursive call
373
-	global $total_projectlinesa_spent,$total_projectlinesa_planned,$total_projectlinesa_spent_if_planned;
373
+	global $total_projectlinesa_spent, $total_projectlinesa_planned, $total_projectlinesa_spent_if_planned;
374 374
 	if ($level == 0)
375 375
 	{
376
-		$total_projectlinesa_spent=0;
377
-		$total_projectlinesa_planned=0;
378
-		$total_projectlinesa_spent_if_planned=0;
376
+		$total_projectlinesa_spent = 0;
377
+		$total_projectlinesa_planned = 0;
378
+		$total_projectlinesa_spent_if_planned = 0;
379 379
 	}
380 380
 
381
-	for ($i = 0 ; $i < $numlines ; $i++)
381
+	for ($i = 0; $i < $numlines; $i++)
382 382
 	{
383
-		if ($parent == 0 && $level >= 0) $level = 0;              // if $level = -1, we dont' use sublevel recursion, we show all lines
383
+		if ($parent == 0 && $level >= 0) $level = 0; // if $level = -1, we dont' use sublevel recursion, we show all lines
384 384
 
385 385
 		// Process line
386 386
 		// print "i:".$i."-".$lines[$i]->fk_project.'<br>';
@@ -388,26 +388,26 @@  discard block
 block discarded – undo
388 388
 		if ($lines[$i]->fk_parent == $parent || $level < 0)       // if $level = -1, we dont' use sublevel recursion, we show all lines
389 389
 		{
390 390
 			// Show task line.
391
-			$showline=1;
392
-			$showlineingray=0;
391
+			$showline = 1;
392
+			$showlineingray = 0;
393 393
 
394 394
 			// If there is filters to use
395 395
 			if (is_array($taskrole))
396 396
 			{
397 397
 				// If task not legitimate to show, search if a legitimate task exists later in tree
398
-				if (! isset($taskrole[$lines[$i]->id]) && $lines[$i]->id != $lines[$i]->fk_parent)
398
+				if (!isset($taskrole[$lines[$i]->id]) && $lines[$i]->id != $lines[$i]->fk_parent)
399 399
 				{
400 400
 					// So search if task has a subtask legitimate to show
401
-					$foundtaskforuserdeeper=0;
402
-					searchTaskInChild($foundtaskforuserdeeper,$lines[$i]->id,$lines,$taskrole);
401
+					$foundtaskforuserdeeper = 0;
402
+					searchTaskInChild($foundtaskforuserdeeper, $lines[$i]->id, $lines, $taskrole);
403 403
 					//print '$foundtaskforuserpeeper='.$foundtaskforuserdeeper.'<br>';
404 404
 					if ($foundtaskforuserdeeper > 0)
405 405
 					{
406
-						$showlineingray=1;		// We will show line but in gray
406
+						$showlineingray = 1; // We will show line but in gray
407 407
 					}
408 408
 					else
409 409
 					{
410
-						$showline=0;			// No reason to show line
410
+						$showline = 0; // No reason to show line
411 411
 					}
412 412
 				}
413 413
 			}
@@ -418,12 +418,12 @@  discard block
 block discarded – undo
418 418
 				if (empty($user->rights->projet->all->lire))
419 419
 				{
420 420
 					// User is not allowed on this project and project is not public, so we hide line
421
-					if (! in_array($lines[$i]->fk_project, $projectsArrayId))
421
+					if (!in_array($lines[$i]->fk_project, $projectsArrayId))
422 422
 					{
423 423
 						// Note that having a user assigned to a task into a project user has no permission on, should not be possible
424 424
 						// because assignement on task can be done only on contact of project.
425 425
 						// If assignement was done and after, was removed from contact of project, then we can hide the line.
426
-						$showline=0;
426
+						$showline = 0;
427 427
 					}
428 428
 				}
429 429
 			}
@@ -434,7 +434,7 @@  discard block
 block discarded – undo
434 434
 				if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
435 435
 				{
436 436
 					$var = !$var;
437
-					$lastprojectid=$lines[$i]->fk_project;
437
+					$lastprojectid = $lines[$i]->fk_project;
438 438
 				}
439 439
 
440 440
 				print '<tr '.$bc[$var].' id="row-'.$lines[$i]->id.'">'."\n";
@@ -444,18 +444,18 @@  discard block
 block discarded – undo
444 444
 					// Project ref
445 445
 					print "<td>";
446 446
 					//if ($showlineingray) print '<i>';
447
-					$projectstatic->id=$lines[$i]->fk_project;
448
-					$projectstatic->ref=$lines[$i]->projectref;
449
-					$projectstatic->public=$lines[$i]->public;
450
-					$projectstatic->title=$lines[$i]->projectlabel;
451
-					if ($lines[$i]->public || in_array($lines[$i]->fk_project,$projectsArrayId) || ! empty($user->rights->projet->all->lire)) print $projectstatic->getNomUrl(1);
452
-					else print $projectstatic->getNomUrl(1,'nolink');
447
+					$projectstatic->id = $lines[$i]->fk_project;
448
+					$projectstatic->ref = $lines[$i]->projectref;
449
+					$projectstatic->public = $lines[$i]->public;
450
+					$projectstatic->title = $lines[$i]->projectlabel;
451
+					if ($lines[$i]->public || in_array($lines[$i]->fk_project, $projectsArrayId) || !empty($user->rights->projet->all->lire)) print $projectstatic->getNomUrl(1);
452
+					else print $projectstatic->getNomUrl(1, 'nolink');
453 453
 					//if ($showlineingray) print '</i>';
454 454
 					print "</td>";
455 455
 
456 456
 					// Project status
457 457
 					print '<td>';
458
-					$projectstatic->statut=$lines[$i]->projectstatus;
458
+					$projectstatic->statut = $lines[$i]->projectstatus;
459 459
 					print $projectstatic->getLibStatut(2);
460 460
 					print "</td>";
461 461
 				}
@@ -464,14 +464,14 @@  discard block
 block discarded – undo
464 464
 				print '<td>';
465 465
 				if ($showlineingray)
466 466
 				{
467
-					print '<i>'.img_object('','projecttask').' '.$lines[$i]->ref.'</i>';
467
+					print '<i>'.img_object('', 'projecttask').' '.$lines[$i]->ref.'</i>';
468 468
 				}
469 469
 				else
470 470
 				{
471
-					$taskstatic->id=$lines[$i]->id;
472
-					$taskstatic->ref=$lines[$i]->ref;
473
-					$taskstatic->label=($taskrole[$lines[$i]->id]?$langs->trans("YourRole").': '.$taskrole[$lines[$i]->id]:'');
474
-					print $taskstatic->getNomUrl(1,'withproject');
471
+					$taskstatic->id = $lines[$i]->id;
472
+					$taskstatic->ref = $lines[$i]->ref;
473
+					$taskstatic->label = ($taskrole[$lines[$i]->id] ? $langs->trans("YourRole").': '.$taskrole[$lines[$i]->id] : '');
474
+					print $taskstatic->getNomUrl(1, 'withproject');
475 475
 				}
476 476
 				print '</td>';
477 477
 
@@ -479,7 +479,7 @@  discard block
 block discarded – undo
479 479
 				print "<td>";
480 480
 				if ($showlineingray) print '<i>';
481 481
 				//else print '<a href="'.DOL_URL_ROOT.'/projet/tasks/task.php?id='.$lines[$i]->id.'&withproject=1">';
482
-				for ($k = 0 ; $k < $level ; $k++)
482
+				for ($k = 0; $k < $level; $k++)
483 483
 				{
484 484
 					print "&nbsp; &nbsp; &nbsp;";
485 485
 				}
@@ -490,7 +490,7 @@  discard block
 block discarded – undo
490 490
 
491 491
 				// Date start
492 492
 				print '<td align="center">';
493
-				print dol_print_date($lines[$i]->date_start,'dayhour');
493
+				print dol_print_date($lines[$i]->date_start, 'dayhour');
494 494
 				print '</td>';
495 495
 
496 496
 				// Date end
@@ -499,19 +499,19 @@  discard block
 block discarded – undo
499 499
 				$taskstatic->progress = $lines[$i]->progress;
500 500
 				$taskstatic->fk_statut = $lines[$i]->status;
501 501
 				$taskstatic->datee = $lines[$i]->date_end;
502
-				print dol_print_date($lines[$i]->date_end,'dayhour');
502
+				print dol_print_date($lines[$i]->date_end, 'dayhour');
503 503
 				if ($taskstatic->hasDelay()) print img_warning($langs->trans("Late"));
504 504
 				print '</td>';
505 505
 
506
-				$plannedworkloadoutputformat='allhourmin';
507
-				$timespentoutputformat='allhourmin';
508
-				if (! empty($conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT)) $plannedworkloadoutputformat=$conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT;
509
-				if (! empty($conf->global->PROJECT_TIMES_SPENT_FORMAT)) $timespentoutputformat=$conf->global->PROJECT_TIME_SPENT_FORMAT;
506
+				$plannedworkloadoutputformat = 'allhourmin';
507
+				$timespentoutputformat = 'allhourmin';
508
+				if (!empty($conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT)) $plannedworkloadoutputformat = $conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT;
509
+				if (!empty($conf->global->PROJECT_TIMES_SPENT_FORMAT)) $timespentoutputformat = $conf->global->PROJECT_TIME_SPENT_FORMAT;
510 510
 
511 511
 				// Planned Workload (in working hours)
512 512
 				print '<td align="right">';
513
-				$fullhour=convertSecondToTime($lines[$i]->planned_workload,$plannedworkloadoutputformat);
514
-				$workingdelay=convertSecondToTime($lines[$i]->planned_workload,'all',86400,7);	// TODO Replace 86400 and 7 to take account working hours per day and working day per weeks
513
+				$fullhour = convertSecondToTime($lines[$i]->planned_workload, $plannedworkloadoutputformat);
514
+				$workingdelay = convertSecondToTime($lines[$i]->planned_workload, 'all', 86400, 7); // TODO Replace 86400 and 7 to take account working hours per day and working day per weeks
515 515
 				if ($lines[$i]->planned_workload != '')
516 516
 				{
517 517
 					print $fullhour;
@@ -524,8 +524,8 @@  discard block
 block discarded – undo
524 524
 				// Time spent
525 525
 				print '<td align="right">';
526 526
 				if ($showlineingray) print '<i>';
527
-				else print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.($showproject?'':'&withproject=1').'">';
528
-				if ($lines[$i]->duration) print convertSecondToTime($lines[$i]->duration,$timespentoutputformat);
527
+				else print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.($showproject ? '' : '&withproject=1').'">';
528
+				if ($lines[$i]->duration) print convertSecondToTime($lines[$i]->duration, $timespentoutputformat);
529 529
 				else print '--:--';
530 530
 				if ($showlineingray) print '</i>';
531 531
 				else print '</a>';
@@ -535,7 +535,7 @@  discard block
 block discarded – undo
535 535
 				print '<td align="right">';
536 536
 				if ($lines[$i]->planned_workload || $lines[$i]->duration)
537 537
 				{
538
-					if ($lines[$i]->planned_workload) print round(100 * $lines[$i]->duration / $lines[$i]->planned_workload,2).' %';
538
+					if ($lines[$i]->planned_workload) print round(100 * $lines[$i]->duration / $lines[$i]->planned_workload, 2).' %';
539 539
 					else print '<span class="opacitymedium">'.$langs->trans('WorkloadNotDefined').'</span>';
540 540
 				}
541 541
 				print '</td>';
@@ -549,20 +549,20 @@  discard block
 block discarded – undo
549 549
 				print '</td>';
550 550
 
551 551
 				// Contacts of task
552
-				if (! empty($conf->global->PROJECT_SHOW_CONTACTS_IN_LIST))
552
+				if (!empty($conf->global->PROJECT_SHOW_CONTACTS_IN_LIST))
553 553
 				{
554 554
 					print '<td>';
555
-					foreach(array('internal','external') as $source)
555
+					foreach (array('internal', 'external') as $source)
556 556
 					{
557
-						$tab = $lines[$i]->liste_contact(-1,$source);
558
-						$num=count($tab);
559
-						if (!empty($num)){
560
-							foreach ($tab as $contacttask){
557
+						$tab = $lines[$i]->liste_contact(-1, $source);
558
+						$num = count($tab);
559
+						if (!empty($num)) {
560
+							foreach ($tab as $contacttask) {
561 561
 								//var_dump($contacttask);
562 562
 								if ($source == 'internal') $c = new User($db);
563 563
 								else $c = new Contact($db);
564 564
 								$c->fetch($contacttask['id']);
565
-								print $c->getNomUrl(1) . ' (' . $contacttask['libelle'] . ')' . '<br>';
565
+								print $c->getNomUrl(1).' ('.$contacttask['libelle'].')'.'<br>';
566 566
 							}
567 567
 						}
568 568
 					}
@@ -577,7 +577,7 @@  discard block
 block discarded – undo
577 577
 
578 578
 				print "</tr>\n";
579 579
 
580
-				if (! $showlineingray) $inc++;
580
+				if (!$showlineingray) $inc++;
581 581
 
582 582
 				if ($level >= 0)    // Call sublevels
583 583
 				{
@@ -609,16 +609,16 @@  discard block
 block discarded – undo
609 609
 		print convertSecondToTime($total_projectlinesa_planned, 'allhourmin');
610 610
 		print '</td>';
611 611
 		print '<td align="right" class="nowrap liste_total">';
612
-		if ($projectidfortotallink > 0) print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?projectid='.$projectidfortotallink.($showproject?'':'&withproject=1').'">';
612
+		if ($projectidfortotallink > 0) print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?projectid='.$projectidfortotallink.($showproject ? '' : '&withproject=1').'">';
613 613
 		print convertSecondToTime($total_projectlinesa_spent, 'allhourmin');
614 614
 		if ($projectidfortotallink > 0) print '</a>';
615 615
 		print '</td>';
616 616
 		print '<td align="right" class="nowrap liste_total">';
617
-		if ($total_projectlinesa_planned) print round(100 * $total_projectlinesa_spent / $total_projectlinesa_planned,2).' %';
617
+		if ($total_projectlinesa_planned) print round(100 * $total_projectlinesa_spent / $total_projectlinesa_planned, 2).' %';
618 618
 		print '</td>';
619 619
 		print '<td></td>';
620 620
 		// Contacts of task
621
-		if (! empty($conf->global->PROJECT_SHOW_CONTACTS_IN_LIST))
621
+		if (!empty($conf->global->PROJECT_SHOW_CONTACTS_IN_LIST))
622 622
 		{
623 623
 			print '<td></td>';
624 624
 		}
@@ -647,48 +647,48 @@  discard block
 block discarded – undo
647 647
  * @param	int			$oldprojectforbreak		Old project id of last project break
648 648
  * @return  array								Array with time spent for $fuser for each day of week on tasks in $lines and substasks
649 649
  */
650
-function projectLinesPerAction(&$inc, $parent, $fuser, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, $preselectedday, &$isavailable, $oldprojectforbreak=0)
650
+function projectLinesPerAction(&$inc, $parent, $fuser, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, $preselectedday, &$isavailable, $oldprojectforbreak = 0)
651 651
 {
652 652
 	global $conf, $db, $user, $bc, $langs;
653 653
 	global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
654 654
 
655
-	$lastprojectid=0;
656
-	$totalforeachline=array();
657
-	$workloadforid=array();
658
-	$lineswithoutlevel0=array();
655
+	$lastprojectid = 0;
656
+	$totalforeachline = array();
657
+	$workloadforid = array();
658
+	$lineswithoutlevel0 = array();
659 659
 
660
-	$numlines=count($lines);
660
+	$numlines = count($lines);
661 661
 
662 662
 	// Create a smaller array with sublevels only to be used later. This increase dramatically performances.
663 663
 	if ($parent == 0) // Always and only if at first level
664 664
 	{
665
-		for ($i = 0 ; $i < $numlines ; $i++)
665
+		for ($i = 0; $i < $numlines; $i++)
666 666
 		{
667
-			if ($lines[$i]->fk_task_parent) $lineswithoutlevel0[]=$lines[$i];
667
+			if ($lines[$i]->fk_task_parent) $lineswithoutlevel0[] = $lines[$i];
668 668
 		}
669 669
 	}
670 670
 
671 671
 	if (empty($oldprojectforbreak))
672 672
 	{
673
-		$oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)?0:-1);	// 0 to start break , -1 no break
673
+		$oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT) ? 0 : -1); // 0 to start break , -1 no break
674 674
 	}
675 675
 
676 676
 	//dol_syslog('projectLinesPerDay inc='.$inc.' preselectedday='.$preselectedday.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
677
-	for ($i = 0 ; $i < $numlines ; $i++)
677
+	for ($i = 0; $i < $numlines; $i++)
678 678
 	{
679 679
 		if ($parent == 0) $level = 0;
680 680
 
681 681
 		//if ($lines[$i]->fk_task_parent == $parent)
682 682
 		//{
683 683
 			// If we want all or we have a role on task, we show it
684
-			if (empty($mine) || ! empty($tasksrole[$lines[$i]->id]))
684
+			if (empty($mine) || !empty($tasksrole[$lines[$i]->id]))
685 685
 			{
686 686
 				//dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
687 687
 
688 688
 				// Break on a new project
689 689
 				if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
690 690
 				{
691
-					$lastprojectid=$lines[$i]->fk_project;
691
+					$lastprojectid = $lines[$i]->fk_project;
692 692
 					if ($preselectedday)
693 693
 					{
694 694
 						$projectstatic->id = $lines[$i]->fk_project;
@@ -699,31 +699,31 @@  discard block
 block discarded – undo
699 699
 				{
700 700
 					if ($preselectedday)
701 701
 					{
702
-						$projectstatic->loadTimeSpent($preselectedday, 0, $fuser->id);	// Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
703
-						$workloadforid[$projectstatic->id]=1;
702
+						$projectstatic->loadTimeSpent($preselectedday, 0, $fuser->id); // Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
703
+						$workloadforid[$projectstatic->id] = 1;
704 704
 					}
705 705
 				}
706 706
 
707
-				$projectstatic->id=$lines[$i]->fk_project;
708
-				$projectstatic->ref=$lines[$i]->project_ref;
709
-				$projectstatic->title=$lines[$i]->project_label;
710
-				$projectstatic->public=$lines[$i]->public;
707
+				$projectstatic->id = $lines[$i]->fk_project;
708
+				$projectstatic->ref = $lines[$i]->project_ref;
709
+				$projectstatic->title = $lines[$i]->project_label;
710
+				$projectstatic->public = $lines[$i]->public;
711 711
 
712
-				$taskstatic->id=$lines[$i]->task_id;
713
-				$taskstatic->ref=($lines[$i]->task_ref?$lines[$i]->task_ref:$lines[$i]->task_id);
714
-				$taskstatic->label=$lines[$i]->task_label;
715
-				$taskstatic->date_start=$lines[$i]->date_start;
716
-				$taskstatic->date_end=$lines[$i]->date_end;
712
+				$taskstatic->id = $lines[$i]->task_id;
713
+				$taskstatic->ref = ($lines[$i]->task_ref ? $lines[$i]->task_ref : $lines[$i]->task_id);
714
+				$taskstatic->label = $lines[$i]->task_label;
715
+				$taskstatic->date_start = $lines[$i]->date_start;
716
+				$taskstatic->date_end = $lines[$i]->date_end;
717 717
 
718
-				$thirdpartystatic->id=$lines[$i]->socid;
719
-				$thirdpartystatic->name=$lines[$i]->thirdparty_name;
720
-				$thirdpartystatic->email=$lines[$i]->thirdparty_email;
718
+				$thirdpartystatic->id = $lines[$i]->socid;
719
+				$thirdpartystatic->name = $lines[$i]->thirdparty_name;
720
+				$thirdpartystatic->email = $lines[$i]->thirdparty_email;
721 721
 
722 722
 				if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id))
723 723
 				{
724 724
 					print '<tr class="oddeven trforbreak">'."\n";
725 725
 					print '<td colspan="11">';
726
-					print $projectstatic->getNomUrl(1,'',0,$langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
726
+					print $projectstatic->getNomUrl(1, '', 0, $langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
727 727
 					if ($projectstatic->title)
728 728
 					{
729 729
 						print ' - ';
@@ -748,7 +748,7 @@  discard block
 block discarded – undo
748 748
 				print "<td>";
749 749
 				if ($oldprojectforbreak == -1)
750 750
 				{
751
-					print $projectstatic->getNomUrl(1,'',0,$langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
751
+					print $projectstatic->getNomUrl(1, '', 0, $langs->transnoentitiesnoconv("YourRole").': '.$projectsrole[$lines[$i]->fk_project]);
752 752
 					print '<br>'.$projectstatic->title;
753 753
 				}
754 754
 				print "</td>";
@@ -761,11 +761,11 @@  discard block
 block discarded – undo
761 761
 				// Ref
762 762
 				print '<td>';
763 763
 				print '<!-- Task id = '.$lines[$i]->id.' -->';
764
-				for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
764
+				for ($k = 0; $k < $level; $k++) print "&nbsp;&nbsp;&nbsp;";
765 765
 				print $taskstatic->getNomUrl(1, 'withproject', 'time');
766 766
 				// Label task
767 767
 				print '<br>';
768
-				for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
768
+				for ($k = 0; $k < $level; $k++) print "&nbsp;&nbsp;&nbsp;";
769 769
 				print $taskstatic->label;
770 770
 				//print "<br>";
771 771
 				//for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
@@ -774,47 +774,47 @@  discard block
 block discarded – undo
774 774
 
775 775
 				// Date
776 776
 				print '<td align="center">';
777
-				print dol_print_date($lines[$i]->timespent_datehour,'day');
777
+				print dol_print_date($lines[$i]->timespent_datehour, 'day');
778 778
 				print '</td>';
779 779
 
780
-				$disabledproject=1;$disabledtask=1;
780
+				$disabledproject = 1; $disabledtask = 1;
781 781
 				//print "x".$lines[$i]->fk_project;
782 782
 				//var_dump($lines[$i]);
783 783
 				//var_dump($projectsrole[$lines[$i]->fk_project]);
784 784
 				// If at least one role for project
785
-				if ($lines[$i]->public || ! empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer)
785
+				if ($lines[$i]->public || !empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer)
786 786
 				{
787
-					$disabledproject=0;
788
-					$disabledtask=0;
787
+					$disabledproject = 0;
788
+					$disabledtask = 0;
789 789
 				}
790 790
 				// If $restricteditformytask is on and I have no role on task, i disable edit
791 791
 				if ($restricteditformytask && empty($tasksrole[$lines[$i]->id]))
792 792
 				{
793
-					$disabledtask=1;
793
+					$disabledtask = 1;
794 794
 				}
795 795
 
796 796
 				// Hour
797 797
 				print '<td class="nowrap" align="center">';
798
-				print dol_print_date($lines[$i]->timespent_datehour,'hour');
798
+				print dol_print_date($lines[$i]->timespent_datehour, 'hour');
799 799
 				print '</td>';
800 800
 
801
-				$cssonholiday='';
802
-				if (! $isavailable[$preselectedday]['morning'] && ! $isavailable[$preselectedday]['afternoon'])   $cssonholiday.='onholidayallday ';
803
-				elseif (! $isavailable[$preselectedday]['morning'])   $cssonholiday.='onholidaymorning ';
804
-				elseif (! $isavailable[$preselectedday]['afternoon']) $cssonholiday.='onholidayafternoon ';
801
+				$cssonholiday = '';
802
+				if (!$isavailable[$preselectedday]['morning'] && !$isavailable[$preselectedday]['afternoon'])   $cssonholiday .= 'onholidayallday ';
803
+				elseif (!$isavailable[$preselectedday]['morning'])   $cssonholiday .= 'onholidaymorning ';
804
+				elseif (!$isavailable[$preselectedday]['afternoon']) $cssonholiday .= 'onholidayafternoon ';
805 805
 
806 806
 				// Duration
807
-				print '<td align="center" class="duration'.($cssonholiday?' '.$cssonholiday:'').'">';
807
+				print '<td align="center" class="duration'.($cssonholiday ? ' '.$cssonholiday : '').'">';
808 808
 
809 809
 				$dayWorkLoad = $lines[$i]->timespent_duration;
810
-				$totalforeachline[$preselectedday]+=$lines[$i]->timespent_duration;
810
+				$totalforeachline[$preselectedday] += $lines[$i]->timespent_duration;
811 811
 
812
-				$alreadyspent='';
813
-				if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($lines[$i]->timespent_duration,'allhourmin');
812
+				$alreadyspent = '';
813
+				if ($dayWorkLoad > 0) $alreadyspent = convertSecondToTime($lines[$i]->timespent_duration, 'allhourmin');
814 814
 
815
-				print convertSecondToTime($lines[$i]->timespent_duration,'allhourmin');
815
+				print convertSecondToTime($lines[$i]->timespent_duration, 'allhourmin');
816 816
 
817
-				$modeinput='hours';
817
+				$modeinput = 'hours';
818 818
 
819 819
 				print '<script type="text/javascript">';
820 820
 				print "jQuery(document).ready(function () {\n";
@@ -826,7 +826,7 @@  discard block
 block discarded – undo
826 826
 
827 827
 				// Note
828 828
 				print '<td align="center">';
829
-				print '<textarea name="'.$lines[$i]->id.'note" rows="'.ROWS_2.'" id="'.$lines[$i]->id.'note"'.($disabledtask?' disabled="disabled"':'').'>';
829
+				print '<textarea name="'.$lines[$i]->id.'note" rows="'.ROWS_2.'" id="'.$lines[$i]->id.'note"'.($disabledtask ? ' disabled="disabled"' : '').'>';
830 830
 				print $lines[$i]->timespent_note;
831 831
 				print '</textarea>';
832 832
 				print '</td>';
@@ -873,41 +873,41 @@  discard block
 block discarded – undo
873 873
  * @param	int			$oldprojectforbreak		Old project id of last project break
874 874
  * @return  array								Array with time spent for $fuser for each day of week on tasks in $lines and substasks
875 875
  */
876
-function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, $preselectedday, &$isavailable, $oldprojectforbreak=0)
876
+function projectLinesPerDay(&$inc, $parent, $fuser, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, $preselectedday, &$isavailable, $oldprojectforbreak = 0)
877 877
 {
878 878
 	global $conf, $db, $user, $bc, $langs;
879 879
 	global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
880 880
 
881
-	$lastprojectid=0;
882
-	$totalforeachday=array();
883
-	$workloadforid=array();
884
-	$lineswithoutlevel0=array();
881
+	$lastprojectid = 0;
882
+	$totalforeachday = array();
883
+	$workloadforid = array();
884
+	$lineswithoutlevel0 = array();
885 885
 
886
-	$numlines=count($lines);
886
+	$numlines = count($lines);
887 887
 
888 888
 	// Create a smaller array with sublevels only to be used later. This increase dramatically performances.
889 889
 	if ($parent == 0) // Always and only if at first level
890 890
 	{
891
-		for ($i = 0 ; $i < $numlines ; $i++)
891
+		for ($i = 0; $i < $numlines; $i++)
892 892
 		{
893
-			if ($lines[$i]->fk_task_parent) $lineswithoutlevel0[]=$lines[$i];
893
+			if ($lines[$i]->fk_task_parent) $lineswithoutlevel0[] = $lines[$i];
894 894
 		}
895 895
 	}
896 896
 
897 897
 	if (empty($oldprojectforbreak))
898 898
 	{
899
-		$oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)?0:-1);	// 0 to start break , -1 no break
899
+		$oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT) ? 0 : -1); // 0 to start break , -1 no break
900 900
 	}
901 901
 
902 902
 	//dol_syslog('projectLinesPerDay inc='.$inc.' preselectedday='.$preselectedday.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
903
-	for ($i = 0 ; $i < $numlines ; $i++)
903
+	for ($i = 0; $i < $numlines; $i++)
904 904
 	{
905 905
 		if ($parent == 0) $level = 0;
906 906
 
907 907
 		if ($lines[$i]->fk_task_parent == $parent)
908 908
 		{
909 909
 			// If we want all or we have a role on task, we show it
910
-			if (empty($mine) || ! empty($tasksrole[$lines[$i]->id]))
910
+			if (empty($mine) || !empty($tasksrole[$lines[$i]->id]))
911 911
 			{
912 912
 				//dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
913 913
 
@@ -919,7 +919,7 @@  discard block
 block discarded – undo
919 919
 				// Break on a new project
920 920
 				if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
921 921
 				{
922
-					$lastprojectid=$lines[$i]->fk_project;
922
+					$lastprojectid = $lines[$i]->fk_project;
923 923
 					if ($preselectedday)
924 924
 					{
925 925
 						$projectstatic->id = $lines[$i]->fk_project;
@@ -930,31 +930,31 @@  discard block
 block discarded – undo
930 930
 				{
931 931
 					if ($preselectedday)
932 932
 					{
933
-						$projectstatic->loadTimeSpent($preselectedday, 0, $fuser->id);	// Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
934
-		   				$workloadforid[$projectstatic->id]=1;
933
+						$projectstatic->loadTimeSpent($preselectedday, 0, $fuser->id); // Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
934
+		   				$workloadforid[$projectstatic->id] = 1;
935 935
 					}
936 936
 				}
937 937
 
938
-				$projectstatic->id=$lines[$i]->fk_project;
939
-				$projectstatic->ref=$lines[$i]->projectref;
940
-				$projectstatic->title=$lines[$i]->projectlabel;
941
-				$projectstatic->public=$lines[$i]->public;
938
+				$projectstatic->id = $lines[$i]->fk_project;
939
+				$projectstatic->ref = $lines[$i]->projectref;
940
+				$projectstatic->title = $lines[$i]->projectlabel;
941
+				$projectstatic->public = $lines[$i]->public;
942 942
 
943
-				$taskstatic->id=$lines[$i]->id;
944
-				$taskstatic->ref=($lines[$i]->ref?$lines[$i]->ref:$lines[$i]->id);
945
-				$taskstatic->label=$lines[$i]->label;
946
-				$taskstatic->date_start=$lines[$i]->date_start;
947
-				$taskstatic->date_end=$lines[$i]->date_end;
943
+				$taskstatic->id = $lines[$i]->id;
944
+				$taskstatic->ref = ($lines[$i]->ref ? $lines[$i]->ref : $lines[$i]->id);
945
+				$taskstatic->label = $lines[$i]->label;
946
+				$taskstatic->date_start = $lines[$i]->date_start;
947
+				$taskstatic->date_end = $lines[$i]->date_end;
948 948
 
949
-				$thirdpartystatic->id=$lines[$i]->socid;
950
-				$thirdpartystatic->name=$lines[$i]->thirdparty_name;
951
-				$thirdpartystatic->email=$lines[$i]->thirdparty_email;
949
+				$thirdpartystatic->id = $lines[$i]->socid;
950
+				$thirdpartystatic->name = $lines[$i]->thirdparty_name;
951
+				$thirdpartystatic->email = $lines[$i]->thirdparty_email;
952 952
 
953 953
 				if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id))
954 954
 				{
955 955
 					print '<tr class="oddeven trforbreak">'."\n";
956 956
 					print '<td colspan="9">';
957
-					print $projectstatic->getNomUrl(1,'',0,'<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
957
+					print $projectstatic->getNomUrl(1, '', 0, '<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
958 958
 					if ($thirdpartystatic->id > 0) print ' - '.$thirdpartystatic->getNomUrl(1);
959 959
 					if ($projectstatic->title)
960 960
 					{
@@ -989,11 +989,11 @@  discard block
 block discarded – undo
989 989
 				// Ref
990 990
 				print '<td>';
991 991
 				print '<!-- Task id = '.$lines[$i]->id.' -->';
992
-				for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
992
+				for ($k = 0; $k < $level; $k++) print "&nbsp;&nbsp;&nbsp;";
993 993
 				print $taskstatic->getNomUrl(1, 'withproject', 'time');
994 994
 				// Label task
995 995
 				print '<br>';
996
-				for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
996
+				for ($k = 0; $k < $level; $k++) print "&nbsp;&nbsp;&nbsp;";
997 997
 				print $taskstatic->label;
998 998
 				//print "<br>";
999 999
 				//for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
@@ -1002,13 +1002,13 @@  discard block
 block discarded – undo
1002 1002
 
1003 1003
 				// Planned Workload
1004 1004
 				print '<td align="right" class="leftborder plannedworkload">';
1005
-				if ($lines[$i]->planned_workload) print convertSecondToTime($lines[$i]->planned_workload,'allhourmin');
1005
+				if ($lines[$i]->planned_workload) print convertSecondToTime($lines[$i]->planned_workload, 'allhourmin');
1006 1006
 				else print '--:--';
1007 1007
 				print '</td>';
1008 1008
 
1009 1009
 				// Progress declared %
1010 1010
 				print '<td align="right">';
1011
-				print $formother->select_percent($lines[$i]->progress, $lines[$i]->id . 'progress');
1011
+				print $formother->select_percent($lines[$i]->progress, $lines[$i]->id.'progress');
1012 1012
 				print '</td>';
1013 1013
 
1014 1014
 				// Time spent by everybody
@@ -1017,7 +1017,7 @@  discard block
 block discarded – undo
1017 1017
 				if ($lines[$i]->duration)
1018 1018
 				{
1019 1019
 					print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
1020
-					print convertSecondToTime($lines[$i]->duration,'allhourmin');
1020
+					print convertSecondToTime($lines[$i]->duration, 'allhourmin');
1021 1021
 					print '</a>';
1022 1022
 				}
1023 1023
 				else print '--:--';
@@ -1025,25 +1025,25 @@  discard block
 block discarded – undo
1025 1025
 
1026 1026
 				// Time spent by user
1027 1027
 				print '<td align="right">';
1028
-				$tmptimespent=$taskstatic->getSummaryOfTimeSpent($fuser->id);
1029
-				if ($tmptimespent['total_duration']) print convertSecondToTime($tmptimespent['total_duration'],'allhourmin');
1028
+				$tmptimespent = $taskstatic->getSummaryOfTimeSpent($fuser->id);
1029
+				if ($tmptimespent['total_duration']) print convertSecondToTime($tmptimespent['total_duration'], 'allhourmin');
1030 1030
 				else print '--:--';
1031 1031
 				print "</td>\n";
1032 1032
 
1033
-				$disabledproject=1;$disabledtask=1;
1033
+				$disabledproject = 1; $disabledtask = 1;
1034 1034
 				//print "x".$lines[$i]->fk_project;
1035 1035
 				//var_dump($lines[$i]);
1036 1036
 				//var_dump($projectsrole[$lines[$i]->fk_project]);
1037 1037
 				// If at least one role for project
1038
-				if ($lines[$i]->public || ! empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer)
1038
+				if ($lines[$i]->public || !empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer)
1039 1039
 				{
1040
-					$disabledproject=0;
1041
-					$disabledtask=0;
1040
+					$disabledproject = 0;
1041
+					$disabledtask = 0;
1042 1042
 				}
1043 1043
 				// If $restricteditformytask is on and I have no role on task, i disable edit
1044 1044
 				if ($restricteditformytask && empty($tasksrole[$lines[$i]->id]))
1045 1045
 				{
1046
-					$disabledtask=1;
1046
+					$disabledtask = 1;
1047 1047
 				}
1048 1048
 
1049 1049
 				// Form to add new time
@@ -1052,41 +1052,41 @@  discard block
 block discarded – undo
1052 1052
 				print $tableCell;
1053 1053
 				print '</td>';
1054 1054
 
1055
-				$cssonholiday='';
1056
-				if (! $isavailable[$preselectedday]['morning'] && ! $isavailable[$preselectedday]['afternoon'])   $cssonholiday.='onholidayallday ';
1057
-				elseif (! $isavailable[$preselectedday]['morning'])   $cssonholiday.='onholidaymorning ';
1058
-				elseif (! $isavailable[$preselectedday]['afternoon']) $cssonholiday.='onholidayafternoon ';
1055
+				$cssonholiday = '';
1056
+				if (!$isavailable[$preselectedday]['morning'] && !$isavailable[$preselectedday]['afternoon'])   $cssonholiday .= 'onholidayallday ';
1057
+				elseif (!$isavailable[$preselectedday]['morning'])   $cssonholiday .= 'onholidaymorning ';
1058
+				elseif (!$isavailable[$preselectedday]['afternoon']) $cssonholiday .= 'onholidayafternoon ';
1059 1059
 
1060 1060
 				global $daytoparse;
1061
-				$tmparray = dol_getdate($daytoparse,true);	// detail of current day
1061
+				$tmparray = dol_getdate($daytoparse, true); // detail of current day
1062 1062
 				$idw = $tmparray['wday'];
1063 1063
 
1064 1064
 				global $numstartworkingday, $numendworkingday;
1065
-				$cssweekend='';
1065
+				$cssweekend = '';
1066 1066
 				if (($idw + 1) < $numstartworkingday || ($idw + 1) > $numendworkingday)	// This is a day is not inside the setup of working days, so we use a week-end css.
1067 1067
 				{
1068
-					$cssweekend='weekend';
1068
+					$cssweekend = 'weekend';
1069 1069
 				}
1070 1070
 
1071 1071
 				// Duration
1072
-				print '<td class="center duration'.($cssonholiday?' '.$cssonholiday:'').($cssweekend?' '.$cssweekend:'').'">';
1072
+				print '<td class="center duration'.($cssonholiday ? ' '.$cssonholiday : '').($cssweekend ? ' '.$cssweekend : '').'">';
1073 1073
 				$dayWorkLoad = $projectstatic->weekWorkLoadPerTask[$preselectedday][$lines[$i]->id];
1074
-				$totalforeachday[$preselectedday]+=$dayWorkLoad;
1074
+				$totalforeachday[$preselectedday] += $dayWorkLoad;
1075 1075
 
1076
-				$alreadyspent='';
1077
-				if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($dayWorkLoad,'allhourmin');
1076
+				$alreadyspent = '';
1077
+				if ($dayWorkLoad > 0) $alreadyspent = convertSecondToTime($dayWorkLoad, 'allhourmin');
1078 1078
 
1079 1079
 				$idw = 0;
1080 1080
 
1081
-				$tableCell='';
1082
-				$tableCell.='<span class="timesheetalreadyrecorded" title="texttoreplace"><input type="text" class="center" size="2" disabled id="timespent['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="'.$alreadyspent.'"></span>';
1083
-				$tableCell.='<span class="hideonsmartphone"> + </span>';
1081
+				$tableCell = '';
1082
+				$tableCell .= '<span class="timesheetalreadyrecorded" title="texttoreplace"><input type="text" class="center" size="2" disabled id="timespent['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="'.$alreadyspent.'"></span>';
1083
+				$tableCell .= '<span class="hideonsmartphone"> + </span>';
1084 1084
 				//$tableCell.='&nbsp;&nbsp;&nbsp;';
1085
-				$tableCell.=$form->select_duration($lines[$i]->id.'duration','',$disabledtask,'text',0,1);
1085
+				$tableCell .= $form->select_duration($lines[$i]->id.'duration', '', $disabledtask, 'text', 0, 1);
1086 1086
 				//$tableCell.='&nbsp;<input type="submit" class="button"'.($disabledtask?' disabled':'').' value="'.$langs->trans("Add").'">';
1087 1087
 				print $tableCell;
1088 1088
 
1089
-				$modeinput='hours';
1089
+				$modeinput = 'hours';
1090 1090
 
1091 1091
 				print '<script type="text/javascript">';
1092 1092
 				print "jQuery(document).ready(function () {\n";
@@ -1098,19 +1098,19 @@  discard block
 block discarded – undo
1098 1098
 
1099 1099
 				// Note
1100 1100
 				print '<td align="center">';
1101
-				print '<textarea name="'.$lines[$i]->id.'note" rows="'.ROWS_2.'" id="'.$lines[$i]->id.'note"'.($disabledtask?' disabled="disabled"':'').'>';
1101
+				print '<textarea name="'.$lines[$i]->id.'note" rows="'.ROWS_2.'" id="'.$lines[$i]->id.'note"'.($disabledtask ? ' disabled="disabled"' : '').'>';
1102 1102
 				print '</textarea>';
1103 1103
 				print '</td>';
1104 1104
 
1105 1105
 				// Warning
1106 1106
 				print '<td align="right">';
1107
-   				if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("UserIsNotContactOfProject"));
1107
+   				if ((!$lines[$i]->public) && $disabledproject) print $form->textwithpicto('', $langs->trans("UserIsNotContactOfProject"));
1108 1108
    				else if ($disabledtask)
1109 1109
    				{
1110 1110
    					$titleassigntask = $langs->trans("AssignTaskToMe");
1111 1111
    					if ($fuser->id != $user->id) $titleassigntask = $langs->trans("AssignTaskToUser", '...');
1112 1112
 
1113
-   					print $form->textwithpicto('',$langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
1113
+   					print $form->textwithpicto('', $langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
1114 1114
    				}
1115 1115
 				print '</td>';
1116 1116
 
@@ -1126,9 +1126,9 @@  discard block
 block discarded – undo
1126 1126
 				$ret = projectLinesPerDay($inc, $lines[$i]->id, $fuser, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $preselectedday, $isavailable, $oldprojectforbreak);
1127 1127
 				//var_dump('ret with parent='.$lines[$i]->id.' level='.$level);
1128 1128
 				//var_dump($ret);
1129
-				foreach($ret as $key => $val)
1129
+				foreach ($ret as $key => $val)
1130 1130
 				{
1131
-					$totalforeachday[$key]+=$val;
1131
+					$totalforeachday[$key] += $val;
1132 1132
 				}
1133 1133
 				//var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level.' + subtasks');
1134 1134
 				//var_dump($totalforeachday);
@@ -1162,24 +1162,24 @@  discard block
 block discarded – undo
1162 1162
  * @param	int			$oldprojectforbreak		Old project id of last project break
1163 1163
  * @return  array								Array with time spent for $fuser for each day of week on tasks in $lines and substasks
1164 1164
  */
1165
-function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, &$isavailable, $oldprojectforbreak=0)
1165
+function projectLinesPerWeek(&$inc, $firstdaytoshow, $fuser, $parent, $lines, &$level, &$projectsrole, &$tasksrole, $mine, $restricteditformytask, &$isavailable, $oldprojectforbreak = 0)
1166 1166
 {
1167 1167
 	global $conf, $db, $user, $bc, $langs;
1168 1168
 	global $form, $formother, $projectstatic, $taskstatic, $thirdpartystatic;
1169 1169
 
1170
-	$numlines=count($lines);
1170
+	$numlines = count($lines);
1171 1171
 
1172
-	$lastprojectid=0;
1173
-	$workloadforid=array();
1174
-	$totalforeachday=array();
1175
-	$lineswithoutlevel0=array();
1172
+	$lastprojectid = 0;
1173
+	$workloadforid = array();
1174
+	$totalforeachday = array();
1175
+	$lineswithoutlevel0 = array();
1176 1176
 
1177 1177
 	// Create a smaller array with sublevels only to be used later. This increase dramatically performances.
1178 1178
 	if ($parent == 0) // Always and only if at first level
1179 1179
 	{
1180
-		for ($i = 0 ; $i < $numlines ; $i++)
1180
+		for ($i = 0; $i < $numlines; $i++)
1181 1181
 		{
1182
-		   if ($lines[$i]->fk_task_parent) $lineswithoutlevel0[]=$lines[$i];
1182
+		   if ($lines[$i]->fk_task_parent) $lineswithoutlevel0[] = $lines[$i];
1183 1183
 		}
1184 1184
 	}
1185 1185
 
@@ -1187,17 +1187,17 @@  discard block
 block discarded – undo
1187 1187
 
1188 1188
 	if (empty($oldprojectforbreak))
1189 1189
 	{
1190
-		$oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT)?0:-1);	// 0 = start break, -1 = never break
1190
+		$oldprojectforbreak = (empty($conf->global->PROJECT_TIMESHEET_DISABLEBREAK_ON_PROJECT) ? 0 : -1); // 0 = start break, -1 = never break
1191 1191
 	}
1192 1192
 
1193
-	for ($i = 0 ; $i < $numlines ; $i++)
1193
+	for ($i = 0; $i < $numlines; $i++)
1194 1194
 	{
1195 1195
 		if ($parent == 0) $level = 0;
1196 1196
 
1197 1197
 		if ($lines[$i]->fk_task_parent == $parent)
1198 1198
 		{
1199 1199
 			// If we want all or we have a role on task, we show it
1200
-			if (empty($mine) || ! empty($tasksrole[$lines[$i]->id]))
1200
+			if (empty($mine) || !empty($tasksrole[$lines[$i]->id]))
1201 1201
 			{
1202 1202
 				//dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
1203 1203
 
@@ -1209,7 +1209,7 @@  discard block
 block discarded – undo
1209 1209
 				// Break on a new project
1210 1210
 				if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
1211 1211
 				{
1212
-					$lastprojectid=$lines[$i]->fk_project;
1212
+					$lastprojectid = $lines[$i]->fk_project;
1213 1213
 					$projectstatic->id = $lines[$i]->fk_project;
1214 1214
 				}
1215 1215
 
@@ -1217,33 +1217,33 @@  discard block
 block discarded – undo
1217 1217
 				//var_dump($projectstatic->weekWorkLoadPerTask);
1218 1218
 				if (empty($workloadforid[$projectstatic->id]))
1219 1219
 				{
1220
-					$projectstatic->loadTimeSpent($firstdaytoshow, 0, $fuser->id);	// Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
1221
-					$workloadforid[$projectstatic->id]=1;
1220
+					$projectstatic->loadTimeSpent($firstdaytoshow, 0, $fuser->id); // Load time spent from table projet_task_time for the project into this->weekWorkLoad and this->weekWorkLoadPerTask for all days of a week
1221
+					$workloadforid[$projectstatic->id] = 1;
1222 1222
 				}
1223 1223
 				//var_dump($projectstatic->weekWorkLoadPerTask);
1224 1224
 				//var_dump('--- '.$projectstatic->id.' '.$workloadforid[$projectstatic->id]);
1225 1225
 
1226
-				$projectstatic->id=$lines[$i]->fk_project;
1227
-				$projectstatic->ref=$lines[$i]->projectref;
1228
-				$projectstatic->title=$lines[$i]->projectlabel;
1229
-				$projectstatic->public=$lines[$i]->public;
1230
-				$projectstatic->thirdparty_name=$lines[$i]->thirdparty_name;
1226
+				$projectstatic->id = $lines[$i]->fk_project;
1227
+				$projectstatic->ref = $lines[$i]->projectref;
1228
+				$projectstatic->title = $lines[$i]->projectlabel;
1229
+				$projectstatic->public = $lines[$i]->public;
1230
+				$projectstatic->thirdparty_name = $lines[$i]->thirdparty_name;
1231 1231
 
1232
-				$taskstatic->id=$lines[$i]->id;
1233
-				$taskstatic->ref=($lines[$i]->ref?$lines[$i]->ref:$lines[$i]->id);
1234
-				$taskstatic->label=$lines[$i]->label;
1235
-				$taskstatic->date_start=$lines[$i]->date_start;
1236
-				$taskstatic->date_end=$lines[$i]->date_end;
1232
+				$taskstatic->id = $lines[$i]->id;
1233
+				$taskstatic->ref = ($lines[$i]->ref ? $lines[$i]->ref : $lines[$i]->id);
1234
+				$taskstatic->label = $lines[$i]->label;
1235
+				$taskstatic->date_start = $lines[$i]->date_start;
1236
+				$taskstatic->date_end = $lines[$i]->date_end;
1237 1237
 
1238
-				$thirdpartystatic->id=$lines[$i]->thirdparty_id;
1239
-				$thirdpartystatic->name=$lines[$i]->thirdparty_name;
1240
-				$thirdpartystatic->email=$lines[$i]->thirdparty_email;
1238
+				$thirdpartystatic->id = $lines[$i]->thirdparty_id;
1239
+				$thirdpartystatic->name = $lines[$i]->thirdparty_name;
1240
+				$thirdpartystatic->email = $lines[$i]->thirdparty_email;
1241 1241
 
1242 1242
 				if (empty($oldprojectforbreak) || ($oldprojectforbreak != -1 && $oldprojectforbreak != $projectstatic->id))
1243 1243
 				{
1244 1244
 					print '<tr class="oddeven trforbreak">'."\n";
1245 1245
 					print '<td colspan="13">';
1246
-					print $projectstatic->getNomUrl(1,'',0,'<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
1246
+					print $projectstatic->getNomUrl(1, '', 0, '<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
1247 1247
 					if ($thirdpartystatic->id > 0) print ' - '.$thirdpartystatic->getNomUrl(1);
1248 1248
 					if ($projectstatic->title)
1249 1249
 					{
@@ -1278,11 +1278,11 @@  discard block
 block discarded – undo
1278 1278
 				// Ref
1279 1279
 				print '<td class="nowrap">';
1280 1280
 				print '<!-- Task id = '.$lines[$i]->id.' -->';
1281
-				for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
1281
+				for ($k = 0; $k < $level; $k++) print "&nbsp;&nbsp;&nbsp;";
1282 1282
 				print $taskstatic->getNomUrl(1, 'withproject', 'time');
1283 1283
 				// Label task
1284 1284
 				print '<br>';
1285
-				for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
1285
+				for ($k = 0; $k < $level; $k++) print "&nbsp;&nbsp;&nbsp;";
1286 1286
 				//print $taskstatic->getNomUrl(0, 'withproject', 'time');
1287 1287
 				print $taskstatic->label;
1288 1288
 				//print "<br>";
@@ -1292,13 +1292,13 @@  discard block
 block discarded – undo
1292 1292
 
1293 1293
 				// Planned Workload
1294 1294
 				print '<td align="right" class="leftborder plannedworkload">';
1295
-				if ($lines[$i]->planned_workload) print convertSecondToTime($lines[$i]->planned_workload,'allhourmin');
1295
+				if ($lines[$i]->planned_workload) print convertSecondToTime($lines[$i]->planned_workload, 'allhourmin');
1296 1296
 				else print '--:--';
1297 1297
 				print '</td>';
1298 1298
 
1299 1299
 				// Progress declared %
1300 1300
 				print '<td align="right">';
1301
-				print $formother->select_percent($lines[$i]->progress, $lines[$i]->id . 'progress');
1301
+				print $formother->select_percent($lines[$i]->progress, $lines[$i]->id.'progress');
1302 1302
 				print '</td>';
1303 1303
 
1304 1304
 				// Time spent by everybody
@@ -1307,7 +1307,7 @@  discard block
 block discarded – undo
1307 1307
 				if ($lines[$i]->duration)
1308 1308
 				{
1309 1309
 					print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
1310
-					print convertSecondToTime($lines[$i]->duration,'allhourmin');
1310
+					print convertSecondToTime($lines[$i]->duration, 'allhourmin');
1311 1311
 					print '</a>';
1312 1312
 				}
1313 1313
 				else print '--:--';
@@ -1315,80 +1315,80 @@  discard block
 block discarded – undo
1315 1315
 
1316 1316
 				// Time spent by user
1317 1317
 				print '<td align="right">';
1318
-				$tmptimespent=$taskstatic->getSummaryOfTimeSpent($fuser->id);
1319
-				if ($tmptimespent['total_duration']) print convertSecondToTime($tmptimespent['total_duration'],'allhourmin');
1318
+				$tmptimespent = $taskstatic->getSummaryOfTimeSpent($fuser->id);
1319
+				if ($tmptimespent['total_duration']) print convertSecondToTime($tmptimespent['total_duration'], 'allhourmin');
1320 1320
 				else print '--:--';
1321 1321
 				print "</td>\n";
1322 1322
 
1323
-				$disabledproject=1;$disabledtask=1;
1323
+				$disabledproject = 1; $disabledtask = 1;
1324 1324
 				//print "x".$lines[$i]->fk_project;
1325 1325
 				//var_dump($lines[$i]);
1326 1326
 				//var_dump($projectsrole[$lines[$i]->fk_project]);
1327 1327
 				// If at least one role for project
1328
-				if ($lines[$i]->public || ! empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer)
1328
+				if ($lines[$i]->public || !empty($projectsrole[$lines[$i]->fk_project]) || $user->rights->projet->all->creer)
1329 1329
 				{
1330
-					$disabledproject=0;
1331
-					$disabledtask=0;
1330
+					$disabledproject = 0;
1331
+					$disabledtask = 0;
1332 1332
 				}
1333 1333
 				// If $restricteditformytask is on and I have no role on task, i disable edit
1334 1334
 				if ($restricteditformytask && empty($tasksrole[$lines[$i]->id]))
1335 1335
 				{
1336
-					$disabledtask=1;
1336
+					$disabledtask = 1;
1337 1337
 				}
1338 1338
 
1339 1339
 				//var_dump($projectstatic->weekWorkLoadPerTask);
1340 1340
 
1341 1341
 				// Fields to show current time
1342
-				$tableCell=''; $modeinput='hours';
1342
+				$tableCell = ''; $modeinput = 'hours';
1343 1343
 				for ($idw = 0; $idw < 7; $idw++)
1344 1344
 				{
1345
-					$tmpday=dol_time_plus_duree($firstdaytoshow, $idw, 'd');
1345
+					$tmpday = dol_time_plus_duree($firstdaytoshow, $idw, 'd');
1346 1346
 
1347
-					$cssonholiday='';
1348
-					if (! $isavailable[$tmpday]['morning'] && ! $isavailable[$tmpday]['afternoon'])   $cssonholiday.='onholidayallday ';
1349
-					elseif (! $isavailable[$tmpday]['morning'])   $cssonholiday.='onholidaymorning ';
1350
-					elseif (! $isavailable[$tmpday]['afternoon']) $cssonholiday.='onholidayafternoon ';
1347
+					$cssonholiday = '';
1348
+					if (!$isavailable[$tmpday]['morning'] && !$isavailable[$tmpday]['afternoon'])   $cssonholiday .= 'onholidayallday ';
1349
+					elseif (!$isavailable[$tmpday]['morning'])   $cssonholiday .= 'onholidaymorning ';
1350
+					elseif (!$isavailable[$tmpday]['afternoon']) $cssonholiday .= 'onholidayafternoon ';
1351 1351
 
1352
-					$tmparray=dol_getdate($tmpday);
1352
+					$tmparray = dol_getdate($tmpday);
1353 1353
 					$dayWorkLoad = $projectstatic->weekWorkLoadPerTask[$tmpday][$lines[$i]->id];
1354
-					$totalforeachday[$tmpday]+=$dayWorkLoad;
1354
+					$totalforeachday[$tmpday] += $dayWorkLoad;
1355 1355
 
1356
-					$alreadyspent='';
1357
-					if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($dayWorkLoad,'allhourmin');
1358
-					$alttitle=$langs->trans("AddHereTimeSpentForDay",$tmparray['day'],$tmparray['mon']);
1356
+					$alreadyspent = '';
1357
+					if ($dayWorkLoad > 0) $alreadyspent = convertSecondToTime($dayWorkLoad, 'allhourmin');
1358
+					$alttitle = $langs->trans("AddHereTimeSpentForDay", $tmparray['day'], $tmparray['mon']);
1359 1359
 
1360 1360
 					global $numstartworkingday, $numendworkingday;
1361
-					$cssweekend='';
1361
+					$cssweekend = '';
1362 1362
 					if (($idw + 1) < $numstartworkingday || ($idw + 1) > $numendworkingday)	// This is a day is not inside the setup of working days, so we use a week-end css.
1363 1363
 					{
1364
-						$cssweekend='weekend';
1364
+						$cssweekend = 'weekend';
1365 1365
 					}
1366 1366
 
1367
-					$tableCell ='<td align="center" class="hide'.$idw.($cssonholiday?' '.$cssonholiday:'').($cssweekend?' '.$cssweekend:'').'">';
1368
-					$placeholder='';
1367
+					$tableCell = '<td align="center" class="hide'.$idw.($cssonholiday ? ' '.$cssonholiday : '').($cssweekend ? ' '.$cssweekend : '').'">';
1368
+					$placeholder = '';
1369 1369
 					if ($alreadyspent)
1370 1370
 					{
1371
-						$tableCell.='<span class="timesheetalreadyrecorded" title="texttoreplace"><input type="text" class="center smallpadd" size="2" disabled id="timespent['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="'.$alreadyspent.'"></span>';
1371
+						$tableCell .= '<span class="timesheetalreadyrecorded" title="texttoreplace"><input type="text" class="center smallpadd" size="2" disabled id="timespent['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="'.$alreadyspent.'"></span>';
1372 1372
 						//$placeholder=' placeholder="00:00"';
1373 1373
 					 	//$tableCell.='+';
1374 1374
 					}
1375
-				  	$tableCell.='<input type="text" alt="'.($disabledtask?'':$alttitle).'" title="'.($disabledtask?'':$alttitle).'" '.($disabledtask?'disabled':$placeholder).' class="center smallpadd" size="2" id="timeadded['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="" cols="2"  maxlength="5"';
1376
-					$tableCell.=' onkeypress="return regexEvent(this,event,\'timeChar\')"';
1377
-				   	$tableCell.=' onkeyup="updateTotal('.$idw.',\''.$modeinput.'\')"';
1378
-				   	$tableCell.=' onblur="regexEvent(this,event,\''.$modeinput.'\'); updateTotal('.$idw.',\''.$modeinput.'\')" />';
1379
-				   	$tableCell.='</td>';
1375
+				  	$tableCell .= '<input type="text" alt="'.($disabledtask ? '' : $alttitle).'" title="'.($disabledtask ? '' : $alttitle).'" '.($disabledtask ? 'disabled' : $placeholder).' class="center smallpadd" size="2" id="timeadded['.$inc.']['.$idw.']" name="task['.$lines[$i]->id.']['.$idw.']" value="" cols="2"  maxlength="5"';
1376
+					$tableCell .= ' onkeypress="return regexEvent(this,event,\'timeChar\')"';
1377
+				   	$tableCell .= ' onkeyup="updateTotal('.$idw.',\''.$modeinput.'\')"';
1378
+				   	$tableCell .= ' onblur="regexEvent(this,event,\''.$modeinput.'\'); updateTotal('.$idw.',\''.$modeinput.'\')" />';
1379
+				   	$tableCell .= '</td>';
1380 1380
 					print $tableCell;
1381 1381
 				}
1382 1382
 
1383 1383
 				// Warning
1384 1384
 				print '<td align="right">';
1385
-   				if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("UserIsNotContactOfProject"));
1385
+   				if ((!$lines[$i]->public) && $disabledproject) print $form->textwithpicto('', $langs->trans("UserIsNotContactOfProject"));
1386 1386
    				else if ($disabledtask)
1387 1387
    				{
1388 1388
    					$titleassigntask = $langs->trans("AssignTaskToMe");
1389 1389
    					if ($fuser->id != $user->id) $titleassigntask = $langs->trans("AssignTaskToUser", '...');
1390 1390
 
1391
-   					print $form->textwithpicto('',$langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
1391
+   					print $form->textwithpicto('', $langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
1392 1392
    				}
1393 1393
 				print '</td>';
1394 1394
 
@@ -1405,9 +1405,9 @@  discard block
 block discarded – undo
1405 1405
 				$ret = projectLinesPerWeek($inc, $firstdaytoshow, $fuser, $lines[$i]->id, ($parent == 0 ? $lineswithoutlevel0 : $lines), $level, $projectsrole, $tasksrole, $mine, $restricteditformytask, $isavailable, $oldprojectforbreak);
1406 1406
 				//var_dump('ret with parent='.$lines[$i]->id.' level='.$level);
1407 1407
 				//var_dump($ret);
1408
-				foreach($ret as $key => $val)
1408
+				foreach ($ret as $key => $val)
1409 1409
 				{
1410
-					$totalforeachday[$key]+=$val;
1410
+					$totalforeachday[$key] += $val;
1411 1411
 				}
1412 1412
 				//var_dump('totalforeachday after taskid='.$lines[$i]->id.' and previous one on level '.$level.' + subtasks');
1413 1413
 				//var_dump($totalforeachday);
@@ -1436,8 +1436,8 @@  discard block
 block discarded – undo
1436 1436
 function searchTaskInChild(&$inc, $parent, &$lines, &$taskrole)
1437 1437
 {
1438 1438
 	//print 'Search in line with parent id = '.$parent.'<br>';
1439
-	$numlines=count($lines);
1440
-	for ($i = 0 ; $i < $numlines ; $i++)
1439
+	$numlines = count($lines);
1440
+	for ($i = 0; $i < $numlines; $i++)
1441 1441
 	{
1442 1442
 		// Process line $lines[$i]
1443 1443
 		if ($lines[$i]->fk_parent == $parent && $lines[$i]->id != $lines[$i]->fk_parent)
@@ -1473,52 +1473,52 @@  discard block
 block discarded – undo
1473 1473
  * @param   array   $hiddenfields       List of info to not show ('projectlabel', 'declaredprogress', '...', )
1474 1474
  * @return	void
1475 1475
  */
1476
-function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks=0, $statut=-1, $listofoppstatus=array(),$hiddenfields=array())
1476
+function print_projecttasks_array($db, $form, $socid, $projectsListId, $mytasks = 0, $statut = -1, $listofoppstatus = array(), $hiddenfields = array())
1477 1477
 {
1478
-	global $langs,$conf,$user,$bc;
1478
+	global $langs, $conf, $user, $bc;
1479 1479
 
1480 1480
 	require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
1481 1481
 
1482
-	$projectstatic=new Project($db);
1483
-	$thirdpartystatic=new Societe($db);
1482
+	$projectstatic = new Project($db);
1483
+	$thirdpartystatic = new Societe($db);
1484 1484
 
1485
-	$sortfield='';
1486
-	$sortorder='';
1487
-	$project_year_filter=0;
1485
+	$sortfield = '';
1486
+	$sortorder = '';
1487
+	$project_year_filter = 0;
1488 1488
 
1489
-	$title=$langs->trans("Projects");
1490
-	if (strcmp($statut, '') && $statut >= 0) $title=$langs->trans("Projects").' '.$langs->trans($projectstatic->statuts_long[$statut]);
1489
+	$title = $langs->trans("Projects");
1490
+	if (strcmp($statut, '') && $statut >= 0) $title = $langs->trans("Projects").' '.$langs->trans($projectstatic->statuts_long[$statut]);
1491 1491
 
1492
-	$arrayidtypeofcontact=array();
1492
+	$arrayidtypeofcontact = array();
1493 1493
 
1494 1494
 	print '<div class="div-table-responsive-no-min">';
1495 1495
 	print '<table class="noborder" width="100%">';
1496 1496
 
1497
-	$sql= " FROM ".MAIN_DB_PREFIX."projet as p";
1497
+	$sql = " FROM ".MAIN_DB_PREFIX."projet as p";
1498 1498
 	if ($mytasks)
1499 1499
 	{
1500
-		$sql.= ", ".MAIN_DB_PREFIX."projet_task as t";
1501
-		$sql.= ", ".MAIN_DB_PREFIX."element_contact as ec";
1502
-		$sql.= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
1500
+		$sql .= ", ".MAIN_DB_PREFIX."projet_task as t";
1501
+		$sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
1502
+		$sql .= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
1503 1503
 	}
1504 1504
 	else
1505 1505
 	{
1506
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t ON p.rowid = t.fk_projet";
1506
+		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t ON p.rowid = t.fk_projet";
1507 1507
 	}
1508
-	$sql.= " WHERE p.entity IN (".getEntity('project').")";
1509
-	$sql.= " AND p.rowid IN (".$projectsListId.")";
1510
-	if ($socid) $sql.= "  AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
1508
+	$sql .= " WHERE p.entity IN (".getEntity('project').")";
1509
+	$sql .= " AND p.rowid IN (".$projectsListId.")";
1510
+	if ($socid) $sql .= "  AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
1511 1511
 	if ($mytasks)
1512 1512
 	{
1513
-		$sql.= " AND p.rowid = t.fk_projet";
1514
-		$sql.= " AND ec.element_id = t.rowid";
1515
-		$sql.= " AND ec.fk_socpeople = ".$user->id;
1516
-		$sql.= " AND ec.fk_c_type_contact = ctc.rowid";   // Replace the 2 lines with ec.fk_c_type_contact in $arrayidtypeofcontact
1517
-		$sql.= " AND ctc.element = 'project_task'";
1513
+		$sql .= " AND p.rowid = t.fk_projet";
1514
+		$sql .= " AND ec.element_id = t.rowid";
1515
+		$sql .= " AND ec.fk_socpeople = ".$user->id;
1516
+		$sql .= " AND ec.fk_c_type_contact = ctc.rowid"; // Replace the 2 lines with ec.fk_c_type_contact in $arrayidtypeofcontact
1517
+		$sql .= " AND ctc.element = 'project_task'";
1518 1518
 	}
1519 1519
 	if ($statut >= 0)
1520 1520
 	{
1521
-		$sql.= " AND p.fk_statut = ".$statut;
1521
+		$sql .= " AND p.fk_statut = ".$statut;
1522 1522
 	}
1523 1523
 	if (!empty($conf->global->PROJECT_LIMIT_YEAR_RANGE))
1524 1524
 	{
@@ -1530,40 +1530,40 @@  discard block
 block discarded – undo
1530 1530
 			{
1531 1531
 				$project_year_filter = date("Y");
1532 1532
 			}
1533
-			$sql.= " AND (p.dateo IS NULL OR p.dateo <= ".$db->idate(dol_get_last_day($project_year_filter,12,false)).")";
1534
-			$sql.= " AND (p.datee IS NULL OR p.datee >= ".$db->idate(dol_get_first_day($project_year_filter,1,false)).")";
1533
+			$sql .= " AND (p.dateo IS NULL OR p.dateo <= ".$db->idate(dol_get_last_day($project_year_filter, 12, false)).")";
1534
+			$sql .= " AND (p.datee IS NULL OR p.datee >= ".$db->idate(dol_get_first_day($project_year_filter, 1, false)).")";
1535 1535
 		}
1536 1536
 	}
1537 1537
 
1538 1538
 	// Get id of project we must show tasks
1539
-	$arrayidofprojects=array();
1539
+	$arrayidofprojects = array();
1540 1540
 	$sql1 = "SELECT p.rowid as projectid";
1541
-	$sql1.= $sql;
1541
+	$sql1 .= $sql;
1542 1542
 	$resql = $db->query($sql1);
1543 1543
 	if ($resql)
1544 1544
 	{
1545
-		$i=0;
1545
+		$i = 0;
1546 1546
 		$num = $db->num_rows($resql);
1547 1547
 		while ($i < $num)
1548 1548
 		{
1549 1549
 			$objp = $db->fetch_object($resql);
1550
-			$arrayidofprojects[$objp->projectid]=$objp->projectid;
1550
+			$arrayidofprojects[$objp->projectid] = $objp->projectid;
1551 1551
 			$i++;
1552 1552
 		}
1553 1553
 	}
1554 1554
 	else dol_print_error($db);
1555
-	if (empty($arrayidofprojects)) $arrayidofprojects[0]=-1;
1555
+	if (empty($arrayidofprojects)) $arrayidofprojects[0] = -1;
1556 1556
 
1557 1557
 	// Get list of project with calculation on tasks
1558 1558
 	$sql2 = "SELECT p.rowid as projectid, p.ref, p.title, p.fk_soc, s.nom as socname, p.fk_user_creat, p.public, p.fk_statut as status, p.fk_opp_status as opp_status, p.opp_amount,";
1559
-	$sql2.= " p.dateo, p.datee,";
1560
-	$sql2.= " COUNT(t.rowid) as nb, SUM(t.planned_workload) as planned_workload, SUM(t.planned_workload * t.progress / 100) as declared_progess_workload";
1561
-	$sql2.= " FROM ".MAIN_DB_PREFIX."projet as p";
1562
-	$sql2.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
1563
-	$sql2.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t ON p.rowid = t.fk_projet";
1564
-	$sql2.= " WHERE p.rowid IN (".join(',',$arrayidofprojects).")";
1565
-	$sql2.= " GROUP BY p.rowid, p.ref, p.title, p.fk_soc, s.nom, p.fk_user_creat, p.public, p.fk_statut, p.fk_opp_status, p.opp_amount, p.dateo, p.datee";
1566
-	$sql2.= " ORDER BY p.title, p.ref";
1559
+	$sql2 .= " p.dateo, p.datee,";
1560
+	$sql2 .= " COUNT(t.rowid) as nb, SUM(t.planned_workload) as planned_workload, SUM(t.planned_workload * t.progress / 100) as declared_progess_workload";
1561
+	$sql2 .= " FROM ".MAIN_DB_PREFIX."projet as p";
1562
+	$sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
1563
+	$sql2 .= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t ON p.rowid = t.fk_projet";
1564
+	$sql2 .= " WHERE p.rowid IN (".join(',', $arrayidofprojects).")";
1565
+	$sql2 .= " GROUP BY p.rowid, p.ref, p.title, p.fk_soc, s.nom, p.fk_user_creat, p.public, p.fk_statut, p.fk_opp_status, p.opp_amount, p.dateo, p.datee";
1566
+	$sql2 .= " ORDER BY p.title, p.ref";
1567 1567
 
1568 1568
 	$resql = $db->query($sql2);
1569 1569
 	if ($resql)
@@ -1576,24 +1576,24 @@  discard block
 block discarded – undo
1576 1576
 		$i = 0;
1577 1577
 
1578 1578
 		print '<tr class="liste_titre">';
1579
-		print_liste_field_titre($title.' <span class="badge">'.$num.'</span>',$_SERVER["PHP_SELF"],"","","","",$sortfield,$sortorder);
1580
-		print_liste_field_titre("ThirdParty",$_SERVER["PHP_SELF"],"","","","",$sortfield,$sortorder);
1581
-		if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
1579
+		print_liste_field_titre($title.' <span class="badge">'.$num.'</span>', $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
1580
+		print_liste_field_titre("ThirdParty", $_SERVER["PHP_SELF"], "", "", "", "", $sortfield, $sortorder);
1581
+		if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES))
1582 1582
 		{
1583
-			print_liste_field_titre("OpportunityAmount","","","","",'align="right"',$sortfield,$sortorder);
1584
-			print_liste_field_titre("OpportunityStatus","","","","",'align="right"',$sortfield,$sortorder);
1583
+			print_liste_field_titre("OpportunityAmount", "", "", "", "", 'align="right"', $sortfield, $sortorder);
1584
+			print_liste_field_titre("OpportunityStatus", "", "", "", "", 'align="right"', $sortfield, $sortorder);
1585 1585
 		}
1586 1586
 		if (empty($conf->global->PROJECT_HIDE_TASKS))
1587 1587
 		{
1588
-			print_liste_field_titre("Tasks","","","","",'align="right"',$sortfield,$sortorder);
1589
-			if (! in_array('plannedworkload', $hiddenfields))  print_liste_field_titre("PlannedWorkload","","","","",'align="right"',$sortfield,$sortorder);
1590
-			if (! in_array('declaredprogress', $hiddenfields)) print_liste_field_titre("ProgressDeclared","","","","",'align="right"',$sortfield,$sortorder);
1588
+			print_liste_field_titre("Tasks", "", "", "", "", 'align="right"', $sortfield, $sortorder);
1589
+			if (!in_array('plannedworkload', $hiddenfields))  print_liste_field_titre("PlannedWorkload", "", "", "", "", 'align="right"', $sortfield, $sortorder);
1590
+			if (!in_array('declaredprogress', $hiddenfields)) print_liste_field_titre("ProgressDeclared", "", "", "", "", 'align="right"', $sortfield, $sortorder);
1591 1591
 		}
1592
-		print_liste_field_titre("Status","","","","",'align="right"',$sortfield,$sortorder);
1592
+		print_liste_field_titre("Status", "", "", "", "", 'align="right"', $sortfield, $sortorder);
1593 1593
 		print "</tr>\n";
1594 1594
 
1595
-		$total_plannedworkload=0;
1596
-		$total_declaredprogressworkload=0;
1595
+		$total_plannedworkload = 0;
1596
+		$total_declaredprogressworkload = 0;
1597 1597
 		while ($i < $num)
1598 1598
 		{
1599 1599
 			$objp = $db->fetch_object($resql);
@@ -1606,7 +1606,7 @@  discard block
 block discarded – undo
1606 1606
 			$userAccess = $projectstatic->restrictedProjectArea($user);
1607 1607
 			if ($userAccess >= 0)
1608 1608
 			{
1609
-				$projectstatic->ref=$objp->ref;
1609
+				$projectstatic->ref = $objp->ref;
1610 1610
 				$projectstatic->statut = $objp->status;
1611 1611
 				$projectstatic->title = $objp->title;
1612 1612
 				$projectstatic->datee = $db->jdate($objp->datee);
@@ -1616,18 +1616,18 @@  discard block
 block discarded – undo
1616 1616
 				print '<tr class="oddeven">';
1617 1617
 				print '<td>';
1618 1618
 				print $projectstatic->getNomUrl(1);
1619
-				if (! in_array('projectlabel', $hiddenfields)) print '<br>'.dol_trunc($objp->title,24);
1619
+				if (!in_array('projectlabel', $hiddenfields)) print '<br>'.dol_trunc($objp->title, 24);
1620 1620
 				print '</td>';
1621 1621
 				print '<td>';
1622 1622
 				if ($objp->fk_soc > 0)
1623 1623
 				{
1624
-					$thirdpartystatic->id=$objp->fk_soc;
1625
-					$thirdpartystatic->ref=$objp->socname;
1626
-					$thirdpartystatic->name=$objp->socname;
1624
+					$thirdpartystatic->id = $objp->fk_soc;
1625
+					$thirdpartystatic->ref = $objp->socname;
1626
+					$thirdpartystatic->name = $objp->socname;
1627 1627
 					print $thirdpartystatic->getNomUrl(1);
1628 1628
 				}
1629 1629
 				print '</td>';
1630
-				if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
1630
+				if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES))
1631 1631
 				{
1632 1632
 					print '<td align="right">';
1633 1633
 					if ($objp->opp_amount) print price($objp->opp_amount, 0, '', 1, -1, -1, $conf->currency);
@@ -1641,19 +1641,19 @@  discard block
 block discarded – undo
1641 1641
 				{
1642 1642
 					print '<td align="right">'.$objp->nb.'</td>';
1643 1643
 
1644
-					$plannedworkload=$objp->planned_workload;
1645
-					$total_plannedworkload+=$plannedworkload;
1646
-					if (! in_array('plannedworkload', $hiddenfields))
1644
+					$plannedworkload = $objp->planned_workload;
1645
+					$total_plannedworkload += $plannedworkload;
1646
+					if (!in_array('plannedworkload', $hiddenfields))
1647 1647
 					{
1648
-						print '<td align="right">'.($plannedworkload?convertSecondToTime($plannedworkload):'').'</td>';
1648
+						print '<td align="right">'.($plannedworkload ?convertSecondToTime($plannedworkload) : '').'</td>';
1649 1649
 					}
1650
-					if (! in_array('declaredprogress', $hiddenfields))
1650
+					if (!in_array('declaredprogress', $hiddenfields))
1651 1651
 					{
1652
-						$declaredprogressworkload=$objp->declared_progess_workload;
1653
-						$total_declaredprogressworkload+=$declaredprogressworkload;
1652
+						$declaredprogressworkload = $objp->declared_progess_workload;
1653
+						$total_declaredprogressworkload += $declaredprogressworkload;
1654 1654
 						print '<td align="right">';
1655 1655
 						//print $objp->planned_workload.'-'.$objp->declared_progess_workload."<br>";
1656
-						print ($plannedworkload?round(100*$declaredprogressworkload/$plannedworkload,0).'%':'');
1656
+						print ($plannedworkload ?round(100 * $declaredprogressworkload / $plannedworkload, 0).'%' : '');
1657 1657
 						print '</td>';
1658 1658
 					}
1659 1659
 				}
@@ -1671,7 +1671,7 @@  discard block
 block discarded – undo
1671 1671
 
1672 1672
 		print '<tr class="liste_total">';
1673 1673
 		print '<td colspan="2">'.$langs->trans("Total")."</td>";
1674
-		if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
1674
+		if (!empty($conf->global->PROJECT_USE_OPPORTUNITIES))
1675 1675
 		{
1676 1676
 			print '<td class="liste_total" align="right">'.price($total_opp_amount, 0, '', 1, -1, -1, $conf->currency).'</td>';
1677 1677
 			print '<td class="liste_total" align="right">'.$form->textwithpicto(price($ponderated_opp_amount, 0, '', 1, -1, -1, $conf->currency), $langs->trans("OpportunityPonderatedAmountDesc"), 1).'</td>';
@@ -1679,8 +1679,8 @@  discard block
 block discarded – undo
1679 1679
 		if (empty($conf->global->PROJECT_HIDE_TASKS))
1680 1680
 		{
1681 1681
 			print '<td class="liste_total" align="right">'.$total_task.'</td>';
1682
-			if (! in_array('plannedworkload', $hiddenfields))  print '<td class="liste_total" align="right">'.($total_plannedworkload?convertSecondToTime($total_plannedworkload):'').'</td>';
1683
-			if (! in_array('declaredprogress', $hiddenfields)) print '<td class="liste_total" align="right">'.($total_plannedworkload?round(100*$total_declaredprogressworkload/$total_plannedworkload,0).'%':'').'</td>';
1682
+			if (!in_array('plannedworkload', $hiddenfields))  print '<td class="liste_total" align="right">'.($total_plannedworkload ?convertSecondToTime($total_plannedworkload) : '').'</td>';
1683
+			if (!in_array('declaredprogress', $hiddenfields)) print '<td class="liste_total" align="right">'.($total_plannedworkload ?round(100 * $total_declaredprogressworkload / $total_plannedworkload, 0).'%' : '').'</td>';
1684 1684
 		}
1685 1685
 		print '<td class="liste_total"></td>';
1686 1686
 		print '</tr>';
Please login to merge, or discard this patch.
Braces   +327 added lines, -132 removed lines patch added patch discarded remove patch
@@ -48,7 +48,9 @@  discard block
 block discarded – undo
48 48
 	$nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
49 49
 	$head[$h][0] = DOL_URL_ROOT.'/projet/contact.php?id='.$object->id;
50 50
 	$head[$h][1] = $langs->trans("ProjectContact");
51
-	if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
51
+	if ($nbContact > 0) {
52
+	    $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
53
+	}
52 54
 	$head[$h][2] = 'contact';
53 55
 	$h++;
54 56
 
@@ -61,7 +63,9 @@  discard block
 block discarded – undo
61 63
 		require_once DOL_DOCUMENT_ROOT.'/projet/class/task.class.php';
62 64
 		$taskstatic=new Task($db);
63 65
 		$nbTasks=count($taskstatic->getTasksArray(0, 0, $object->id, 0, 0));
64
-		if ($nbTasks > 0) $head[$h][1].= ' <span class="badge">'.($nbTasks).'</span>';
66
+		if ($nbTasks > 0) {
67
+		    $head[$h][1].= ' <span class="badge">'.($nbTasks).'</span>';
68
+		}
65 69
 		$head[$h][2] = 'tasks';
66 70
 		$h++;
67 71
 
@@ -76,13 +80,18 @@  discard block
 block discarded – undo
76 80
 		if ($resql)
77 81
 		{
78 82
 			$obj = $db->fetch_object($resql);
79
-			if ($obj) $nbTimeSpent=1;
83
+			if ($obj) {
84
+			    $nbTimeSpent=1;
85
+			}
86
+		} else {
87
+		    dol_print_error($db);
80 88
 		}
81
-		else dol_print_error($db);
82 89
 
83 90
 		$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?withproject=1&projectid='.$object->id;
84 91
 		$head[$h][1] = $langs->trans("TimeSpent");
85
-		if ($nbTimeSpent > 0) $head[$h][1].= ' <span class="badge">...</span>';
92
+		if ($nbTimeSpent > 0) {
93
+		    $head[$h][1].= ' <span class="badge">...</span>';
94
+		}
86 95
 		$head[$h][2] = 'timespent';
87 96
 		$h++;
88 97
 	}
@@ -107,11 +116,17 @@  discard block
 block discarded – undo
107 116
 	if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
108 117
 	{
109 118
 		$nbNote = 0;
110
-		if(!empty($object->note_private)) $nbNote++;
111
-		if(!empty($object->note_public)) $nbNote++;
119
+		if(!empty($object->note_private)) {
120
+		    $nbNote++;
121
+		}
122
+		if(!empty($object->note_public)) {
123
+		    $nbNote++;
124
+		}
112 125
 		$head[$h][0] = DOL_URL_ROOT.'/projet/note.php?id='.$object->id;
113 126
 		$head[$h][1] = $langs->trans('Notes');
114
-		if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
127
+		if ($nbNote > 0) {
128
+		    $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
129
+		}
115 130
 		$head[$h][2] = 'notes';
116 131
 		$h++;
117 132
 	}
@@ -123,7 +138,9 @@  discard block
 block discarded – undo
123 138
 	$nbLinks=Link::count($db, $object->element, $object->id);
124 139
 	$head[$h][0] = DOL_URL_ROOT.'/projet/document.php?id='.$object->id;
125 140
 	$head[$h][1] = $langs->trans('Documents');
126
-	if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
141
+	if (($nbFiles+$nbLinks) > 0) {
142
+	    $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
143
+	}
127 144
 	$head[$h][2] = 'document';
128 145
 	$h++;
129 146
 
@@ -133,7 +150,9 @@  discard block
 block discarded – undo
133 150
 		$nbComments = $object->getNbComments();
134 151
 		$head[$h][0] = DOL_URL_ROOT.'/projet/comment.php?id='.$object->id;
135 152
 		$head[$h][1] = $langs->trans("CommentLink");
136
-		if ($nbComments > 0) $head[$h][1].= ' <span class="badge">'.$nbComments.'</span>';
153
+		if ($nbComments > 0) {
154
+		    $head[$h][1].= ' <span class="badge">'.$nbComments.'</span>';
155
+		}
137 156
 		$head[$h][2] = 'project_comment';
138 157
 		$h++;
139 158
 	}
@@ -174,7 +193,9 @@  discard block
 block discarded – undo
174 193
 	$nbContact = count($object->liste_contact(-1,'internal')) + count($object->liste_contact(-1,'external'));
175 194
 	$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/contact.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
176 195
 	$head[$h][1] = $langs->trans("TaskRessourceLinks");
177
-	if ($nbContact > 0) $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
196
+	if ($nbContact > 0) {
197
+	    $head[$h][1].= ' <span class="badge">'.$nbContact.'</span>';
198
+	}
178 199
 	$head[$h][2] = 'task_contact';
179 200
 	$h++;
180 201
 
@@ -189,13 +210,18 @@  discard block
 block discarded – undo
189 210
 	if ($resql)
190 211
 	{
191 212
 		$obj = $db->fetch_object($resql);
192
-		if ($obj) $nbTimeSpent=1;
213
+		if ($obj) {
214
+		    $nbTimeSpent=1;
215
+		}
216
+	} else {
217
+	    dol_print_error($db);
193 218
 	}
194
-	else dol_print_error($db);
195 219
 
196 220
 	$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/time.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
197 221
 	$head[$h][1] = $langs->trans("TimeSpent");
198
-	if ($nbTimeSpent > 0) $head[$h][1].= ' <span class="badge">...</span>';
222
+	if ($nbTimeSpent > 0) {
223
+	    $head[$h][1].= ' <span class="badge">...</span>';
224
+	}
199 225
 	$head[$h][2] = 'task_time';
200 226
 	$h++;
201 227
 
@@ -208,11 +234,17 @@  discard block
 block discarded – undo
208 234
 	if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
209 235
 	{
210 236
 		$nbNote = 0;
211
-		if(!empty($object->note_private)) $nbNote++;
212
-		if(!empty($object->note_public)) $nbNote++;
237
+		if(!empty($object->note_private)) {
238
+		    $nbNote++;
239
+		}
240
+		if(!empty($object->note_public)) {
241
+		    $nbNote++;
242
+		}
213 243
 		$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/note.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
214 244
 		$head[$h][1] = $langs->trans('Notes');
215
-		if ($nbNote > 0) $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
245
+		if ($nbNote > 0) {
246
+		    $head[$h][1].= ' <span class="badge">'.$nbNote.'</span>';
247
+		}
216 248
 		$head[$h][2] = 'task_notes';
217 249
 		$h++;
218 250
 	}
@@ -224,7 +256,9 @@  discard block
 block discarded – undo
224 256
 	$nbFiles = count(dol_dir_list($filesdir,'files',0,'','(\.meta|_preview.*\.png)$'));
225 257
 	$nbLinks=Link::count($db, $object->element, $object->id);
226 258
 	$head[$h][1] = $langs->trans('Documents');
227
-	if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
259
+	if (($nbFiles+$nbLinks) > 0) {
260
+	    $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
261
+	}
228 262
 	$head[$h][2] = 'task_document';
229 263
 	$h++;
230 264
 
@@ -234,7 +268,9 @@  discard block
 block discarded – undo
234 268
 		$nbComments = $object->getNbComments();
235 269
 		$head[$h][0] = DOL_URL_ROOT.'/projet/tasks/comment.php?id='.$object->id.(GETPOST('withproject')?'&withproject=1':'');
236 270
 		$head[$h][1] = $langs->trans("CommentLink");
237
-		if ($nbComments > 0) $head[$h][1].= ' <span class="badge">'.$nbComments.'</span>';
271
+		if ($nbComments > 0) {
272
+		    $head[$h][1].= ' <span class="badge">'.$nbComments.'</span>';
273
+		}
238 274
 		$head[$h][2] = 'task_comment';
239 275
 		$h++;
240 276
 	}
@@ -261,7 +297,9 @@  discard block
 block discarded – undo
261 297
 
262 298
 	$param='';
263 299
 	$param.=($mode?'&mode='.$mode:'');
264
-	if (is_object($fuser) && $fuser->id > 0 && $fuser->id != $user->id) $param.='&search_usertoprocessid='.$fuser->id;
300
+	if (is_object($fuser) && $fuser->id > 0 && $fuser->id != $user->id) {
301
+	    $param.='&search_usertoprocessid='.$fuser->id;
302
+	}
265 303
 
266 304
 	if (empty($conf->global->PROJECT_DISABLE_TIMESHEET_PERWEEK))
267 305
 	{
@@ -380,15 +418,20 @@  discard block
 block discarded – undo
380 418
 
381 419
 	for ($i = 0 ; $i < $numlines ; $i++)
382 420
 	{
383
-		if ($parent == 0 && $level >= 0) $level = 0;              // if $level = -1, we dont' use sublevel recursion, we show all lines
421
+		if ($parent == 0 && $level >= 0) {
422
+		    $level = 0;
423
+		}
424
+		// if $level = -1, we dont' use sublevel recursion, we show all lines
384 425
 
385 426
 		// Process line
386 427
 		// print "i:".$i."-".$lines[$i]->fk_project.'<br>';
387 428
 
388
-		if ($lines[$i]->fk_parent == $parent || $level < 0)       // if $level = -1, we dont' use sublevel recursion, we show all lines
429
+		if ($lines[$i]->fk_parent == $parent || $level < 0) {
430
+		    // if $level = -1, we dont' use sublevel recursion, we show all lines
389 431
 		{
390 432
 			// Show task line.
391 433
 			$showline=1;
434
+		}
392 435
 			$showlineingray=0;
393 436
 
394 437
 			// If there is filters to use
@@ -404,14 +447,12 @@  discard block
 block discarded – undo
404 447
 					if ($foundtaskforuserdeeper > 0)
405 448
 					{
406 449
 						$showlineingray=1;		// We will show line but in gray
407
-					}
408
-					else
450
+					} else
409 451
 					{
410 452
 						$showline=0;			// No reason to show line
411 453
 					}
412 454
 				}
413
-			}
414
-			else
455
+			} else
415 456
 			{
416 457
 				// Caller did not ask to filter on tasks of a specific user (this probably means he want also tasks of all users, into public project
417 458
 				// or into all other projects if user has permission to).
@@ -448,8 +489,11 @@  discard block
 block discarded – undo
448 489
 					$projectstatic->ref=$lines[$i]->projectref;
449 490
 					$projectstatic->public=$lines[$i]->public;
450 491
 					$projectstatic->title=$lines[$i]->projectlabel;
451
-					if ($lines[$i]->public || in_array($lines[$i]->fk_project,$projectsArrayId) || ! empty($user->rights->projet->all->lire)) print $projectstatic->getNomUrl(1);
452
-					else print $projectstatic->getNomUrl(1,'nolink');
492
+					if ($lines[$i]->public || in_array($lines[$i]->fk_project,$projectsArrayId) || ! empty($user->rights->projet->all->lire)) {
493
+					    print $projectstatic->getNomUrl(1);
494
+					} else {
495
+					    print $projectstatic->getNomUrl(1,'nolink');
496
+					}
453 497
 					//if ($showlineingray) print '</i>';
454 498
 					print "</td>";
455 499
 
@@ -465,8 +509,7 @@  discard block
 block discarded – undo
465 509
 				if ($showlineingray)
466 510
 				{
467 511
 					print '<i>'.img_object('','projecttask').' '.$lines[$i]->ref.'</i>';
468
-				}
469
-				else
512
+				} else
470 513
 				{
471 514
 					$taskstatic->id=$lines[$i]->id;
472 515
 					$taskstatic->ref=$lines[$i]->ref;
@@ -477,14 +520,18 @@  discard block
 block discarded – undo
477 520
 
478 521
 				// Title of task
479 522
 				print "<td>";
480
-				if ($showlineingray) print '<i>';
523
+				if ($showlineingray) {
524
+				    print '<i>';
525
+				}
481 526
 				//else print '<a href="'.DOL_URL_ROOT.'/projet/tasks/task.php?id='.$lines[$i]->id.'&withproject=1">';
482 527
 				for ($k = 0 ; $k < $level ; $k++)
483 528
 				{
484 529
 					print "&nbsp; &nbsp; &nbsp;";
485 530
 				}
486 531
 				print $lines[$i]->label;
487
-				if ($showlineingray) print '</i>';
532
+				if ($showlineingray) {
533
+				    print '</i>';
534
+				}
488 535
 				//else print '</a>';
489 536
 				print "</td>\n";
490 537
 
@@ -500,13 +547,19 @@  discard block
 block discarded – undo
500 547
 				$taskstatic->fk_statut = $lines[$i]->status;
501 548
 				$taskstatic->datee = $lines[$i]->date_end;
502 549
 				print dol_print_date($lines[$i]->date_end,'dayhour');
503
-				if ($taskstatic->hasDelay()) print img_warning($langs->trans("Late"));
550
+				if ($taskstatic->hasDelay()) {
551
+				    print img_warning($langs->trans("Late"));
552
+				}
504 553
 				print '</td>';
505 554
 
506 555
 				$plannedworkloadoutputformat='allhourmin';
507 556
 				$timespentoutputformat='allhourmin';
508
-				if (! empty($conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT)) $plannedworkloadoutputformat=$conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT;
509
-				if (! empty($conf->global->PROJECT_TIMES_SPENT_FORMAT)) $timespentoutputformat=$conf->global->PROJECT_TIME_SPENT_FORMAT;
557
+				if (! empty($conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT)) {
558
+				    $plannedworkloadoutputformat=$conf->global->PROJECT_PLANNED_WORKLOAD_FORMAT;
559
+				}
560
+				if (! empty($conf->global->PROJECT_TIMES_SPENT_FORMAT)) {
561
+				    $timespentoutputformat=$conf->global->PROJECT_TIME_SPENT_FORMAT;
562
+				}
510 563
 
511 564
 				// Planned Workload (in working hours)
512 565
 				print '<td align="right">';
@@ -523,20 +576,32 @@  discard block
 block discarded – undo
523 576
 
524 577
 				// Time spent
525 578
 				print '<td align="right">';
526
-				if ($showlineingray) print '<i>';
527
-				else print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.($showproject?'':'&withproject=1').'">';
528
-				if ($lines[$i]->duration) print convertSecondToTime($lines[$i]->duration,$timespentoutputformat);
529
-				else print '--:--';
530
-				if ($showlineingray) print '</i>';
531
-				else print '</a>';
579
+				if ($showlineingray) {
580
+				    print '<i>';
581
+				} else {
582
+				    print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.($showproject?'':'&withproject=1').'">';
583
+				}
584
+				if ($lines[$i]->duration) {
585
+				    print convertSecondToTime($lines[$i]->duration,$timespentoutputformat);
586
+				} else {
587
+				    print '--:--';
588
+				}
589
+				if ($showlineingray) {
590
+				    print '</i>';
591
+				} else {
592
+				    print '</a>';
593
+				}
532 594
 				print '</td>';
533 595
 
534 596
 				// Progress calculated (Note: ->duration is time spent)
535 597
 				print '<td align="right">';
536 598
 				if ($lines[$i]->planned_workload || $lines[$i]->duration)
537 599
 				{
538
-					if ($lines[$i]->planned_workload) print round(100 * $lines[$i]->duration / $lines[$i]->planned_workload,2).' %';
539
-					else print '<span class="opacitymedium">'.$langs->trans('WorkloadNotDefined').'</span>';
600
+					if ($lines[$i]->planned_workload) {
601
+					    print round(100 * $lines[$i]->duration / $lines[$i]->planned_workload,2).' %';
602
+					} else {
603
+					    print '<span class="opacitymedium">'.$langs->trans('WorkloadNotDefined').'</span>';
604
+					}
540 605
 				}
541 606
 				print '</td>';
542 607
 
@@ -559,8 +624,11 @@  discard block
 block discarded – undo
559 624
 						if (!empty($num)){
560 625
 							foreach ($tab as $contacttask){
561 626
 								//var_dump($contacttask);
562
-								if ($source == 'internal') $c = new User($db);
563
-								else $c = new Contact($db);
627
+								if ($source == 'internal') {
628
+								    $c = new User($db);
629
+								} else {
630
+								    $c = new Contact($db);
631
+								}
564 632
 								$c->fetch($contacttask['id']);
565 633
 								print $c->getNomUrl(1) . ' (' . $contacttask['libelle'] . ')' . '<br>';
566 634
 							}
@@ -577,21 +645,28 @@  discard block
 block discarded – undo
577 645
 
578 646
 				print "</tr>\n";
579 647
 
580
-				if (! $showlineingray) $inc++;
648
+				if (! $showlineingray) {
649
+				    $inc++;
650
+				}
581 651
 
582
-				if ($level >= 0)    // Call sublevels
652
+				if ($level >= 0) {
653
+				    // Call sublevels
583 654
 				{
584 655
 					$level++;
585
-					if ($lines[$i]->id) projectLinesa($inc, $lines[$i]->id, $lines, $level, $var, $showproject, $taskrole, $projectsListId, $addordertick);
656
+				}
657
+					if ($lines[$i]->id) {
658
+					    projectLinesa($inc, $lines[$i]->id, $lines, $level, $var, $showproject, $taskrole, $projectsListId, $addordertick);
659
+					}
586 660
 					$level--;
587 661
 				}
588 662
 
589 663
 				$total_projectlinesa_spent += $lines[$i]->duration;
590 664
 				$total_projectlinesa_planned += $lines[$i]->planned_workload;
591
-				if ($lines[$i]->planned_workload) $total_projectlinesa_spent_if_planned += $lines[$i]->duration;
665
+				if ($lines[$i]->planned_workload) {
666
+				    $total_projectlinesa_spent_if_planned += $lines[$i]->duration;
667
+				}
592 668
 			}
593
-		}
594
-		else
669
+		} else
595 670
 		{
596 671
 			//$level--;
597 672
 		}
@@ -601,7 +676,9 @@  discard block
 block discarded – undo
601 676
 	{
602 677
 		print '<tr class="liste_total nodrag nodrop">';
603 678
 		print '<td class="liste_total">'.$langs->trans("Total").'</td>';
604
-		if ($showproject) print '<td></td><td></td>';
679
+		if ($showproject) {
680
+		    print '<td></td><td></td>';
681
+		}
605 682
 		print '<td></td>';
606 683
 		print '<td></td>';
607 684
 		print '<td></td>';
@@ -609,12 +686,18 @@  discard block
 block discarded – undo
609 686
 		print convertSecondToTime($total_projectlinesa_planned, 'allhourmin');
610 687
 		print '</td>';
611 688
 		print '<td align="right" class="nowrap liste_total">';
612
-		if ($projectidfortotallink > 0) print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?projectid='.$projectidfortotallink.($showproject?'':'&withproject=1').'">';
689
+		if ($projectidfortotallink > 0) {
690
+		    print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?projectid='.$projectidfortotallink.($showproject?'':'&withproject=1').'">';
691
+		}
613 692
 		print convertSecondToTime($total_projectlinesa_spent, 'allhourmin');
614
-		if ($projectidfortotallink > 0) print '</a>';
693
+		if ($projectidfortotallink > 0) {
694
+		    print '</a>';
695
+		}
615 696
 		print '</td>';
616 697
 		print '<td align="right" class="nowrap liste_total">';
617
-		if ($total_projectlinesa_planned) print round(100 * $total_projectlinesa_spent / $total_projectlinesa_planned,2).' %';
698
+		if ($total_projectlinesa_planned) {
699
+		    print round(100 * $total_projectlinesa_spent / $total_projectlinesa_planned,2).' %';
700
+		}
618 701
 		print '</td>';
619 702
 		print '<td></td>';
620 703
 		// Contacts of task
@@ -622,7 +705,9 @@  discard block
 block discarded – undo
622 705
 		{
623 706
 			print '<td></td>';
624 707
 		}
625
-		if ($addordertick) print '<td class="hideonsmartphone"></td>';
708
+		if ($addordertick) {
709
+		    print '<td class="hideonsmartphone"></td>';
710
+		}
626 711
 		print '</tr>';
627 712
 	}
628 713
 
@@ -660,11 +745,16 @@  discard block
 block discarded – undo
660 745
 	$numlines=count($lines);
661 746
 
662 747
 	// Create a smaller array with sublevels only to be used later. This increase dramatically performances.
663
-	if ($parent == 0) // Always and only if at first level
748
+	if ($parent == 0) {
749
+	    // Always and only if at first level
664 750
 	{
665
-		for ($i = 0 ; $i < $numlines ; $i++)
751
+		for ($i = 0 ;
752
+	}
753
+	$i < $numlines ; $i++)
666 754
 		{
667
-			if ($lines[$i]->fk_task_parent) $lineswithoutlevel0[]=$lines[$i];
755
+			if ($lines[$i]->fk_task_parent) {
756
+			    $lineswithoutlevel0[]=$lines[$i];
757
+			}
668 758
 		}
669 759
 	}
670 760
 
@@ -676,7 +766,9 @@  discard block
 block discarded – undo
676 766
 	//dol_syslog('projectLinesPerDay inc='.$inc.' preselectedday='.$preselectedday.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
677 767
 	for ($i = 0 ; $i < $numlines ; $i++)
678 768
 	{
679
-		if ($parent == 0) $level = 0;
769
+		if ($parent == 0) {
770
+		    $level = 0;
771
+		}
680 772
 
681 773
 		//if ($lines[$i]->fk_task_parent == $parent)
682 774
 		//{
@@ -733,7 +825,9 @@  discard block
 block discarded – undo
733 825
 					print '</tr>';
734 826
 				}
735 827
 
736
-				if ($oldprojectforbreak != -1) $oldprojectforbreak = $projectstatic->id;
828
+				if ($oldprojectforbreak != -1) {
829
+				    $oldprojectforbreak = $projectstatic->id;
830
+				}
737 831
 
738 832
 				print '<tr class="oddeven">'."\n";
739 833
 
@@ -755,17 +849,23 @@  discard block
 block discarded – undo
755 849
 
756 850
 				// Thirdparty
757 851
 				print '<td class="tdoverflowmax100">';
758
-				if ($thirdpartystatic->id > 0) print $thirdpartystatic->getNomUrl(1, 'project', 10);
852
+				if ($thirdpartystatic->id > 0) {
853
+				    print $thirdpartystatic->getNomUrl(1, 'project', 10);
854
+				}
759 855
 				print '</td>';
760 856
 
761 857
 				// Ref
762 858
 				print '<td>';
763 859
 				print '<!-- Task id = '.$lines[$i]->id.' -->';
764
-				for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
860
+				for ($k = 0 ; $k < $level ; $k++) {
861
+				    print "&nbsp;&nbsp;&nbsp;";
862
+				}
765 863
 				print $taskstatic->getNomUrl(1, 'withproject', 'time');
766 864
 				// Label task
767 865
 				print '<br>';
768
-				for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
866
+				for ($k = 0 ; $k < $level ; $k++) {
867
+				    print "&nbsp;&nbsp;&nbsp;";
868
+				}
769 869
 				print $taskstatic->label;
770 870
 				//print "<br>";
771 871
 				//for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
@@ -799,9 +899,13 @@  discard block
 block discarded – undo
799 899
 				print '</td>';
800 900
 
801 901
 				$cssonholiday='';
802
-				if (! $isavailable[$preselectedday]['morning'] && ! $isavailable[$preselectedday]['afternoon'])   $cssonholiday.='onholidayallday ';
803
-				elseif (! $isavailable[$preselectedday]['morning'])   $cssonholiday.='onholidaymorning ';
804
-				elseif (! $isavailable[$preselectedday]['afternoon']) $cssonholiday.='onholidayafternoon ';
902
+				if (! $isavailable[$preselectedday]['morning'] && ! $isavailable[$preselectedday]['afternoon']) {
903
+				    $cssonholiday.='onholidayallday ';
904
+				} elseif (! $isavailable[$preselectedday]['morning']) {
905
+				    $cssonholiday.='onholidaymorning ';
906
+				} elseif (! $isavailable[$preselectedday]['afternoon']) {
907
+				    $cssonholiday.='onholidayafternoon ';
908
+				}
805 909
 
806 910
 				// Duration
807 911
 				print '<td align="center" class="duration'.($cssonholiday?' '.$cssonholiday:'').'">';
@@ -810,7 +914,9 @@  discard block
 block discarded – undo
810 914
 				$totalforeachline[$preselectedday]+=$lines[$i]->timespent_duration;
811 915
 
812 916
 				$alreadyspent='';
813
-				if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($lines[$i]->timespent_duration,'allhourmin');
917
+				if ($dayWorkLoad > 0) {
918
+				    $alreadyspent=convertSecondToTime($lines[$i]->timespent_duration,'allhourmin');
919
+				}
814 920
 
815 921
 				print convertSecondToTime($lines[$i]->timespent_duration,'allhourmin');
816 922
 
@@ -886,11 +992,16 @@  discard block
 block discarded – undo
886 992
 	$numlines=count($lines);
887 993
 
888 994
 	// Create a smaller array with sublevels only to be used later. This increase dramatically performances.
889
-	if ($parent == 0) // Always and only if at first level
995
+	if ($parent == 0) {
996
+	    // Always and only if at first level
890 997
 	{
891
-		for ($i = 0 ; $i < $numlines ; $i++)
998
+		for ($i = 0 ;
999
+	}
1000
+	$i < $numlines ; $i++)
892 1001
 		{
893
-			if ($lines[$i]->fk_task_parent) $lineswithoutlevel0[]=$lines[$i];
1002
+			if ($lines[$i]->fk_task_parent) {
1003
+			    $lineswithoutlevel0[]=$lines[$i];
1004
+			}
894 1005
 		}
895 1006
 	}
896 1007
 
@@ -902,7 +1013,9 @@  discard block
 block discarded – undo
902 1013
 	//dol_syslog('projectLinesPerDay inc='.$inc.' preselectedday='.$preselectedday.' task parent id='.$parent.' level='.$level." count(lines)=".$numlines." count(lineswithoutlevel0)=".count($lineswithoutlevel0));
903 1014
 	for ($i = 0 ; $i < $numlines ; $i++)
904 1015
 	{
905
-		if ($parent == 0) $level = 0;
1016
+		if ($parent == 0) {
1017
+		    $level = 0;
1018
+		}
906 1019
 
907 1020
 		if ($lines[$i]->fk_task_parent == $parent)
908 1021
 		{
@@ -911,10 +1024,12 @@  discard block
 block discarded – undo
911 1024
 			{
912 1025
 				//dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
913 1026
 
914
-				if ($restricteditformytask == 2 && empty($tasksrole[$lines[$i]->id]))	// we have no role on task and we request to hide such cases
1027
+				if ($restricteditformytask == 2 && empty($tasksrole[$lines[$i]->id])) {
1028
+				    // we have no role on task and we request to hide such cases
915 1029
 				{
916 1030
 					continue;
917 1031
 				}
1032
+				}
918 1033
 
919 1034
 				// Break on a new project
920 1035
 				if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
@@ -955,7 +1070,9 @@  discard block
 block discarded – undo
955 1070
 					print '<tr class="oddeven trforbreak">'."\n";
956 1071
 					print '<td colspan="9">';
957 1072
 					print $projectstatic->getNomUrl(1,'',0,'<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
958
-					if ($thirdpartystatic->id > 0) print ' - '.$thirdpartystatic->getNomUrl(1);
1073
+					if ($thirdpartystatic->id > 0) {
1074
+					    print ' - '.$thirdpartystatic->getNomUrl(1);
1075
+					}
959 1076
 					if ($projectstatic->title)
960 1077
 					{
961 1078
 						print ' - ';
@@ -965,7 +1082,9 @@  discard block
 block discarded – undo
965 1082
 					print '</tr>';
966 1083
 				}
967 1084
 
968
-				if ($oldprojectforbreak != -1) $oldprojectforbreak = $projectstatic->id;
1085
+				if ($oldprojectforbreak != -1) {
1086
+				    $oldprojectforbreak = $projectstatic->id;
1087
+				}
969 1088
 
970 1089
 				print '<tr class="oddeven">'."\n";
971 1090
 
@@ -989,11 +1108,15 @@  discard block
 block discarded – undo
989 1108
 				// Ref
990 1109
 				print '<td>';
991 1110
 				print '<!-- Task id = '.$lines[$i]->id.' -->';
992
-				for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
1111
+				for ($k = 0 ; $k < $level ; $k++) {
1112
+				    print "&nbsp;&nbsp;&nbsp;";
1113
+				}
993 1114
 				print $taskstatic->getNomUrl(1, 'withproject', 'time');
994 1115
 				// Label task
995 1116
 				print '<br>';
996
-				for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
1117
+				for ($k = 0 ; $k < $level ; $k++) {
1118
+				    print "&nbsp;&nbsp;&nbsp;";
1119
+				}
997 1120
 				print $taskstatic->label;
998 1121
 				//print "<br>";
999 1122
 				//for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
@@ -1002,8 +1125,11 @@  discard block
 block discarded – undo
1002 1125
 
1003 1126
 				// Planned Workload
1004 1127
 				print '<td align="right" class="leftborder plannedworkload">';
1005
-				if ($lines[$i]->planned_workload) print convertSecondToTime($lines[$i]->planned_workload,'allhourmin');
1006
-				else print '--:--';
1128
+				if ($lines[$i]->planned_workload) {
1129
+				    print convertSecondToTime($lines[$i]->planned_workload,'allhourmin');
1130
+				} else {
1131
+				    print '--:--';
1132
+				}
1007 1133
 				print '</td>';
1008 1134
 
1009 1135
 				// Progress declared %
@@ -1019,15 +1145,19 @@  discard block
 block discarded – undo
1019 1145
 					print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
1020 1146
 					print convertSecondToTime($lines[$i]->duration,'allhourmin');
1021 1147
 					print '</a>';
1148
+				} else {
1149
+				    print '--:--';
1022 1150
 				}
1023
-				else print '--:--';
1024 1151
 				print "</td>\n";
1025 1152
 
1026 1153
 				// Time spent by user
1027 1154
 				print '<td align="right">';
1028 1155
 				$tmptimespent=$taskstatic->getSummaryOfTimeSpent($fuser->id);
1029
-				if ($tmptimespent['total_duration']) print convertSecondToTime($tmptimespent['total_duration'],'allhourmin');
1030
-				else print '--:--';
1156
+				if ($tmptimespent['total_duration']) {
1157
+				    print convertSecondToTime($tmptimespent['total_duration'],'allhourmin');
1158
+				} else {
1159
+				    print '--:--';
1160
+				}
1031 1161
 				print "</td>\n";
1032 1162
 
1033 1163
 				$disabledproject=1;$disabledtask=1;
@@ -1053,9 +1183,13 @@  discard block
 block discarded – undo
1053 1183
 				print '</td>';
1054 1184
 
1055 1185
 				$cssonholiday='';
1056
-				if (! $isavailable[$preselectedday]['morning'] && ! $isavailable[$preselectedday]['afternoon'])   $cssonholiday.='onholidayallday ';
1057
-				elseif (! $isavailable[$preselectedday]['morning'])   $cssonholiday.='onholidaymorning ';
1058
-				elseif (! $isavailable[$preselectedday]['afternoon']) $cssonholiday.='onholidayafternoon ';
1186
+				if (! $isavailable[$preselectedday]['morning'] && ! $isavailable[$preselectedday]['afternoon']) {
1187
+				    $cssonholiday.='onholidayallday ';
1188
+				} elseif (! $isavailable[$preselectedday]['morning']) {
1189
+				    $cssonholiday.='onholidaymorning ';
1190
+				} elseif (! $isavailable[$preselectedday]['afternoon']) {
1191
+				    $cssonholiday.='onholidayafternoon ';
1192
+				}
1059 1193
 
1060 1194
 				global $daytoparse;
1061 1195
 				$tmparray = dol_getdate($daytoparse,true);	// detail of current day
@@ -1063,10 +1197,12 @@  discard block
 block discarded – undo
1063 1197
 
1064 1198
 				global $numstartworkingday, $numendworkingday;
1065 1199
 				$cssweekend='';
1066
-				if (($idw + 1) < $numstartworkingday || ($idw + 1) > $numendworkingday)	// This is a day is not inside the setup of working days, so we use a week-end css.
1200
+				if (($idw + 1) < $numstartworkingday || ($idw + 1) > $numendworkingday) {
1201
+				    // This is a day is not inside the setup of working days, so we use a week-end css.
1067 1202
 				{
1068 1203
 					$cssweekend='weekend';
1069 1204
 				}
1205
+				}
1070 1206
 
1071 1207
 				// Duration
1072 1208
 				print '<td class="center duration'.($cssonholiday?' '.$cssonholiday:'').($cssweekend?' '.$cssweekend:'').'">';
@@ -1074,7 +1210,9 @@  discard block
 block discarded – undo
1074 1210
 				$totalforeachday[$preselectedday]+=$dayWorkLoad;
1075 1211
 
1076 1212
 				$alreadyspent='';
1077
-				if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($dayWorkLoad,'allhourmin');
1213
+				if ($dayWorkLoad > 0) {
1214
+				    $alreadyspent=convertSecondToTime($dayWorkLoad,'allhourmin');
1215
+				}
1078 1216
 
1079 1217
 				$idw = 0;
1080 1218
 
@@ -1104,11 +1242,14 @@  discard block
 block discarded – undo
1104 1242
 
1105 1243
 				// Warning
1106 1244
 				print '<td align="right">';
1107
-   				if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("UserIsNotContactOfProject"));
1108
-   				else if ($disabledtask)
1245
+   				if ((! $lines[$i]->public) && $disabledproject) {
1246
+   				    print $form->textwithpicto('',$langs->trans("UserIsNotContactOfProject"));
1247
+   				} else if ($disabledtask)
1109 1248
    				{
1110 1249
    					$titleassigntask = $langs->trans("AssignTaskToMe");
1111
-   					if ($fuser->id != $user->id) $titleassigntask = $langs->trans("AssignTaskToUser", '...');
1250
+   					if ($fuser->id != $user->id) {
1251
+   					    $titleassigntask = $langs->trans("AssignTaskToUser", '...');
1252
+   					}
1112 1253
 
1113 1254
    					print $form->textwithpicto('',$langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
1114 1255
    				}
@@ -1134,8 +1275,7 @@  discard block
 block discarded – undo
1134 1275
 				//var_dump($totalforeachday);
1135 1276
 			}
1136 1277
 			$level--;
1137
-		}
1138
-		else
1278
+		} else
1139 1279
 		{
1140 1280
 			//$level--;
1141 1281
 		}
@@ -1175,11 +1315,16 @@  discard block
 block discarded – undo
1175 1315
 	$lineswithoutlevel0=array();
1176 1316
 
1177 1317
 	// Create a smaller array with sublevels only to be used later. This increase dramatically performances.
1178
-	if ($parent == 0) // Always and only if at first level
1318
+	if ($parent == 0) {
1319
+	    // Always and only if at first level
1179 1320
 	{
1180
-		for ($i = 0 ; $i < $numlines ; $i++)
1321
+		for ($i = 0 ;
1322
+	}
1323
+	$i < $numlines ; $i++)
1181 1324
 		{
1182
-		   if ($lines[$i]->fk_task_parent) $lineswithoutlevel0[]=$lines[$i];
1325
+		   if ($lines[$i]->fk_task_parent) {
1326
+		       $lineswithoutlevel0[]=$lines[$i];
1327
+		   }
1183 1328
 		}
1184 1329
 	}
1185 1330
 
@@ -1192,7 +1337,9 @@  discard block
 block discarded – undo
1192 1337
 
1193 1338
 	for ($i = 0 ; $i < $numlines ; $i++)
1194 1339
 	{
1195
-		if ($parent == 0) $level = 0;
1340
+		if ($parent == 0) {
1341
+		    $level = 0;
1342
+		}
1196 1343
 
1197 1344
 		if ($lines[$i]->fk_task_parent == $parent)
1198 1345
 		{
@@ -1201,10 +1348,12 @@  discard block
 block discarded – undo
1201 1348
 			{
1202 1349
 				//dol_syslog("projectLinesPerWeek Found line ".$i.", a qualified task (i have role or want to show all tasks) with id=".$lines[$i]->id." project id=".$lines[$i]->fk_project);
1203 1350
 
1204
-				if ($restricteditformytask == 2 && empty($tasksrole[$lines[$i]->id]))	// we have no role on task and we request to hide such cases
1351
+				if ($restricteditformytask == 2 && empty($tasksrole[$lines[$i]->id])) {
1352
+				    // we have no role on task and we request to hide such cases
1205 1353
 				{
1206 1354
 					continue;
1207 1355
 				}
1356
+				}
1208 1357
 
1209 1358
 				// Break on a new project
1210 1359
 				if ($parent == 0 && $lines[$i]->fk_project != $lastprojectid)
@@ -1244,7 +1393,9 @@  discard block
 block discarded – undo
1244 1393
 					print '<tr class="oddeven trforbreak">'."\n";
1245 1394
 					print '<td colspan="13">';
1246 1395
 					print $projectstatic->getNomUrl(1,'',0,'<strong>'.$langs->transnoentitiesnoconv("YourRole").':</strong> '.$projectsrole[$lines[$i]->fk_project]);
1247
-					if ($thirdpartystatic->id > 0) print ' - '.$thirdpartystatic->getNomUrl(1);
1396
+					if ($thirdpartystatic->id > 0) {
1397
+					    print ' - '.$thirdpartystatic->getNomUrl(1);
1398
+					}
1248 1399
 					if ($projectstatic->title)
1249 1400
 					{
1250 1401
 						print ' - ';
@@ -1254,7 +1405,9 @@  discard block
 block discarded – undo
1254 1405
 					print '</tr>';
1255 1406
 				}
1256 1407
 
1257
-				if ($oldprojectforbreak != -1) $oldprojectforbreak = $projectstatic->id;
1408
+				if ($oldprojectforbreak != -1) {
1409
+				    $oldprojectforbreak = $projectstatic->id;
1410
+				}
1258 1411
 
1259 1412
 				print '<tr class="oddeven">'."\n";
1260 1413
 
@@ -1278,11 +1431,15 @@  discard block
 block discarded – undo
1278 1431
 				// Ref
1279 1432
 				print '<td class="nowrap">';
1280 1433
 				print '<!-- Task id = '.$lines[$i]->id.' -->';
1281
-				for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
1434
+				for ($k = 0 ; $k < $level ; $k++) {
1435
+				    print "&nbsp;&nbsp;&nbsp;";
1436
+				}
1282 1437
 				print $taskstatic->getNomUrl(1, 'withproject', 'time');
1283 1438
 				// Label task
1284 1439
 				print '<br>';
1285
-				for ($k = 0 ; $k < $level ; $k++) print "&nbsp;&nbsp;&nbsp;";
1440
+				for ($k = 0 ; $k < $level ; $k++) {
1441
+				    print "&nbsp;&nbsp;&nbsp;";
1442
+				}
1286 1443
 				//print $taskstatic->getNomUrl(0, 'withproject', 'time');
1287 1444
 				print $taskstatic->label;
1288 1445
 				//print "<br>";
@@ -1292,8 +1449,11 @@  discard block
 block discarded – undo
1292 1449
 
1293 1450
 				// Planned Workload
1294 1451
 				print '<td align="right" class="leftborder plannedworkload">';
1295
-				if ($lines[$i]->planned_workload) print convertSecondToTime($lines[$i]->planned_workload,'allhourmin');
1296
-				else print '--:--';
1452
+				if ($lines[$i]->planned_workload) {
1453
+				    print convertSecondToTime($lines[$i]->planned_workload,'allhourmin');
1454
+				} else {
1455
+				    print '--:--';
1456
+				}
1297 1457
 				print '</td>';
1298 1458
 
1299 1459
 				// Progress declared %
@@ -1309,15 +1469,19 @@  discard block
 block discarded – undo
1309 1469
 					print '<a href="'.DOL_URL_ROOT.'/projet/tasks/time.php?id='.$lines[$i]->id.'">';
1310 1470
 					print convertSecondToTime($lines[$i]->duration,'allhourmin');
1311 1471
 					print '</a>';
1472
+				} else {
1473
+				    print '--:--';
1312 1474
 				}
1313
-				else print '--:--';
1314 1475
 				print "</td>\n";
1315 1476
 
1316 1477
 				// Time spent by user
1317 1478
 				print '<td align="right">';
1318 1479
 				$tmptimespent=$taskstatic->getSummaryOfTimeSpent($fuser->id);
1319
-				if ($tmptimespent['total_duration']) print convertSecondToTime($tmptimespent['total_duration'],'allhourmin');
1320
-				else print '--:--';
1480
+				if ($tmptimespent['total_duration']) {
1481
+				    print convertSecondToTime($tmptimespent['total_duration'],'allhourmin');
1482
+				} else {
1483
+				    print '--:--';
1484
+				}
1321 1485
 				print "</td>\n";
1322 1486
 
1323 1487
 				$disabledproject=1;$disabledtask=1;
@@ -1345,24 +1509,32 @@  discard block
 block discarded – undo
1345 1509
 					$tmpday=dol_time_plus_duree($firstdaytoshow, $idw, 'd');
1346 1510
 
1347 1511
 					$cssonholiday='';
1348
-					if (! $isavailable[$tmpday]['morning'] && ! $isavailable[$tmpday]['afternoon'])   $cssonholiday.='onholidayallday ';
1349
-					elseif (! $isavailable[$tmpday]['morning'])   $cssonholiday.='onholidaymorning ';
1350
-					elseif (! $isavailable[$tmpday]['afternoon']) $cssonholiday.='onholidayafternoon ';
1512
+					if (! $isavailable[$tmpday]['morning'] && ! $isavailable[$tmpday]['afternoon']) {
1513
+					    $cssonholiday.='onholidayallday ';
1514
+					} elseif (! $isavailable[$tmpday]['morning']) {
1515
+					    $cssonholiday.='onholidaymorning ';
1516
+					} elseif (! $isavailable[$tmpday]['afternoon']) {
1517
+					    $cssonholiday.='onholidayafternoon ';
1518
+					}
1351 1519
 
1352 1520
 					$tmparray=dol_getdate($tmpday);
1353 1521
 					$dayWorkLoad = $projectstatic->weekWorkLoadPerTask[$tmpday][$lines[$i]->id];
1354 1522
 					$totalforeachday[$tmpday]+=$dayWorkLoad;
1355 1523
 
1356 1524
 					$alreadyspent='';
1357
-					if ($dayWorkLoad > 0) $alreadyspent=convertSecondToTime($dayWorkLoad,'allhourmin');
1525
+					if ($dayWorkLoad > 0) {
1526
+					    $alreadyspent=convertSecondToTime($dayWorkLoad,'allhourmin');
1527
+					}
1358 1528
 					$alttitle=$langs->trans("AddHereTimeSpentForDay",$tmparray['day'],$tmparray['mon']);
1359 1529
 
1360 1530
 					global $numstartworkingday, $numendworkingday;
1361 1531
 					$cssweekend='';
1362
-					if (($idw + 1) < $numstartworkingday || ($idw + 1) > $numendworkingday)	// This is a day is not inside the setup of working days, so we use a week-end css.
1532
+					if (($idw + 1) < $numstartworkingday || ($idw + 1) > $numendworkingday) {
1533
+					    // This is a day is not inside the setup of working days, so we use a week-end css.
1363 1534
 					{
1364 1535
 						$cssweekend='weekend';
1365 1536
 					}
1537
+					}
1366 1538
 
1367 1539
 					$tableCell ='<td align="center" class="hide'.$idw.($cssonholiday?' '.$cssonholiday:'').($cssweekend?' '.$cssweekend:'').'">';
1368 1540
 					$placeholder='';
@@ -1382,11 +1554,14 @@  discard block
 block discarded – undo
1382 1554
 
1383 1555
 				// Warning
1384 1556
 				print '<td align="right">';
1385
-   				if ((! $lines[$i]->public) && $disabledproject) print $form->textwithpicto('',$langs->trans("UserIsNotContactOfProject"));
1386
-   				else if ($disabledtask)
1557
+   				if ((! $lines[$i]->public) && $disabledproject) {
1558
+   				    print $form->textwithpicto('',$langs->trans("UserIsNotContactOfProject"));
1559
+   				} else if ($disabledtask)
1387 1560
    				{
1388 1561
    					$titleassigntask = $langs->trans("AssignTaskToMe");
1389
-   					if ($fuser->id != $user->id) $titleassigntask = $langs->trans("AssignTaskToUser", '...');
1562
+   					if ($fuser->id != $user->id) {
1563
+   					    $titleassigntask = $langs->trans("AssignTaskToUser", '...');
1564
+   					}
1390 1565
 
1391 1566
    					print $form->textwithpicto('',$langs->trans("TaskIsNotAssignedToUser", $titleassigntask));
1392 1567
    				}
@@ -1413,8 +1588,7 @@  discard block
 block discarded – undo
1413 1588
 				//var_dump($totalforeachday);
1414 1589
 			}
1415 1590
 			$level--;
1416
-		}
1417
-		else
1591
+		} else
1418 1592
 		{
1419 1593
 			//$level--;
1420 1594
 		}
@@ -1453,7 +1627,9 @@  discard block
 block discarded – undo
1453 1627
 			searchTaskInChild($inc, $lines[$i]->id, $lines, $taskrole);
1454 1628
 			//print 'Found inc='.$inc.'<br>';
1455 1629
 
1456
-			if ($inc > 0) return $inc;
1630
+			if ($inc > 0) {
1631
+			    return $inc;
1632
+			}
1457 1633
 		}
1458 1634
 	}
1459 1635
 
@@ -1487,7 +1663,9 @@  discard block
 block discarded – undo
1487 1663
 	$project_year_filter=0;
1488 1664
 
1489 1665
 	$title=$langs->trans("Projects");
1490
-	if (strcmp($statut, '') && $statut >= 0) $title=$langs->trans("Projects").' '.$langs->trans($projectstatic->statuts_long[$statut]);
1666
+	if (strcmp($statut, '') && $statut >= 0) {
1667
+	    $title=$langs->trans("Projects").' '.$langs->trans($projectstatic->statuts_long[$statut]);
1668
+	}
1491 1669
 
1492 1670
 	$arrayidtypeofcontact=array();
1493 1671
 
@@ -1500,14 +1678,15 @@  discard block
 block discarded – undo
1500 1678
 		$sql.= ", ".MAIN_DB_PREFIX."projet_task as t";
1501 1679
 		$sql.= ", ".MAIN_DB_PREFIX."element_contact as ec";
1502 1680
 		$sql.= ", ".MAIN_DB_PREFIX."c_type_contact as ctc";
1503
-	}
1504
-	else
1681
+	} else
1505 1682
 	{
1506 1683
 		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."projet_task as t ON p.rowid = t.fk_projet";
1507 1684
 	}
1508 1685
 	$sql.= " WHERE p.entity IN (".getEntity('project').")";
1509 1686
 	$sql.= " AND p.rowid IN (".$projectsListId.")";
1510
-	if ($socid) $sql.= "  AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
1687
+	if ($socid) {
1688
+	    $sql.= "  AND (p.fk_soc IS NULL OR p.fk_soc = 0 OR p.fk_soc = ".$socid.")";
1689
+	}
1511 1690
 	if ($mytasks)
1512 1691
 	{
1513 1692
 		$sql.= " AND p.rowid = t.fk_projet";
@@ -1550,9 +1729,12 @@  discard block
 block discarded – undo
1550 1729
 			$arrayidofprojects[$objp->projectid]=$objp->projectid;
1551 1730
 			$i++;
1552 1731
 		}
1732
+	} else {
1733
+	    dol_print_error($db);
1734
+	}
1735
+	if (empty($arrayidofprojects)) {
1736
+	    $arrayidofprojects[0]=-1;
1553 1737
 	}
1554
-	else dol_print_error($db);
1555
-	if (empty($arrayidofprojects)) $arrayidofprojects[0]=-1;
1556 1738
 
1557 1739
 	// Get list of project with calculation on tasks
1558 1740
 	$sql2 = "SELECT p.rowid as projectid, p.ref, p.title, p.fk_soc, s.nom as socname, p.fk_user_creat, p.public, p.fk_statut as status, p.fk_opp_status as opp_status, p.opp_amount,";
@@ -1586,8 +1768,12 @@  discard block
 block discarded – undo
1586 1768
 		if (empty($conf->global->PROJECT_HIDE_TASKS))
1587 1769
 		{
1588 1770
 			print_liste_field_titre("Tasks","","","","",'align="right"',$sortfield,$sortorder);
1589
-			if (! in_array('plannedworkload', $hiddenfields))  print_liste_field_titre("PlannedWorkload","","","","",'align="right"',$sortfield,$sortorder);
1590
-			if (! in_array('declaredprogress', $hiddenfields)) print_liste_field_titre("ProgressDeclared","","","","",'align="right"',$sortfield,$sortorder);
1771
+			if (! in_array('plannedworkload', $hiddenfields)) {
1772
+			    print_liste_field_titre("PlannedWorkload","","","","",'align="right"',$sortfield,$sortorder);
1773
+			}
1774
+			if (! in_array('declaredprogress', $hiddenfields)) {
1775
+			    print_liste_field_titre("ProgressDeclared","","","","",'align="right"',$sortfield,$sortorder);
1776
+			}
1591 1777
 		}
1592 1778
 		print_liste_field_titre("Status","","","","",'align="right"',$sortfield,$sortorder);
1593 1779
 		print "</tr>\n";
@@ -1616,7 +1802,9 @@  discard block
 block discarded – undo
1616 1802
 				print '<tr class="oddeven">';
1617 1803
 				print '<td>';
1618 1804
 				print $projectstatic->getNomUrl(1);
1619
-				if (! in_array('projectlabel', $hiddenfields)) print '<br>'.dol_trunc($objp->title,24);
1805
+				if (! in_array('projectlabel', $hiddenfields)) {
1806
+				    print '<br>'.dol_trunc($objp->title,24);
1807
+				}
1620 1808
 				print '</td>';
1621 1809
 				print '<td>';
1622 1810
 				if ($objp->fk_soc > 0)
@@ -1630,11 +1818,15 @@  discard block
 block discarded – undo
1630 1818
 				if (! empty($conf->global->PROJECT_USE_OPPORTUNITIES))
1631 1819
 				{
1632 1820
 					print '<td align="right">';
1633
-					if ($objp->opp_amount) print price($objp->opp_amount, 0, '', 1, -1, -1, $conf->currency);
1821
+					if ($objp->opp_amount) {
1822
+					    print price($objp->opp_amount, 0, '', 1, -1, -1, $conf->currency);
1823
+					}
1634 1824
 					print '</td>';
1635 1825
 					print '<td align="right">';
1636 1826
 					$code = dol_getIdFromCode($db, $objp->opp_status, 'c_lead_status', 'rowid', 'code');
1637
-					if ($code) print $langs->trans("OppStatus".$code);
1827
+					if ($code) {
1828
+					    print $langs->trans("OppStatus".$code);
1829
+					}
1638 1830
 					print '</td>';
1639 1831
 				}
1640 1832
 				if (empty($conf->global->PROJECT_HIDE_TASKS))
@@ -1679,15 +1871,18 @@  discard block
 block discarded – undo
1679 1871
 		if (empty($conf->global->PROJECT_HIDE_TASKS))
1680 1872
 		{
1681 1873
 			print '<td class="liste_total" align="right">'.$total_task.'</td>';
1682
-			if (! in_array('plannedworkload', $hiddenfields))  print '<td class="liste_total" align="right">'.($total_plannedworkload?convertSecondToTime($total_plannedworkload):'').'</td>';
1683
-			if (! in_array('declaredprogress', $hiddenfields)) print '<td class="liste_total" align="right">'.($total_plannedworkload?round(100*$total_declaredprogressworkload/$total_plannedworkload,0).'%':'').'</td>';
1874
+			if (! in_array('plannedworkload', $hiddenfields)) {
1875
+			    print '<td class="liste_total" align="right">'.($total_plannedworkload?convertSecondToTime($total_plannedworkload):'').'</td>';
1876
+			}
1877
+			if (! in_array('declaredprogress', $hiddenfields)) {
1878
+			    print '<td class="liste_total" align="right">'.($total_plannedworkload?round(100*$total_declaredprogressworkload/$total_plannedworkload,0).'%':'').'</td>';
1879
+			}
1684 1880
 		}
1685 1881
 		print '<td class="liste_total"></td>';
1686 1882
 		print '</tr>';
1687 1883
 
1688 1884
 		$db->free($resql);
1689
-	}
1690
-	else
1885
+	} else
1691 1886
 	{
1692 1887
 		dol_print_error($db);
1693 1888
 	}
Please login to merge, or discard this patch.
dolibarr/htdocs/core/lib/json.lib.php 3 patches
Indentation   +263 added lines, -263 removed lines patch added patch discarded remove patch
@@ -25,16 +25,16 @@  discard block
 block discarded – undo
25 25
 
26 26
 if (! function_exists('json_encode'))
27 27
 {
28
-	/**
29
-	 * Implement json_encode for PHP that does not have module enabled.
30
-	 *
31
-	 * @param	mixed	$elements		PHP Object to json encode
32
-	 * @return 	string					Json encoded string
33
-	 */
34
-	function json_encode($elements)
35
-	{
36
-		return dol_json_encode($elements);
37
-	}
28
+    /**
29
+     * Implement json_encode for PHP that does not have module enabled.
30
+     *
31
+     * @param	mixed	$elements		PHP Object to json encode
32
+     * @return 	string					Json encoded string
33
+     */
34
+    function json_encode($elements)
35
+    {
36
+        return dol_json_encode($elements);
37
+    }
38 38
 }
39 39
 
40 40
 /**
@@ -47,56 +47,56 @@  discard block
 block discarded – undo
47 47
  */
48 48
 function dol_json_encode($elements)
49 49
 {
50
-	dol_syslog("For better performance, enable the native json in your PHP", LOG_WARNING);
51
-
52
-	$num=0;
53
-	if (is_object($elements))	// Count number of properties for an object
54
-	{
55
-		foreach($elements as $key => $value) $num++;
56
-	}
57
-	else
58
-	{
59
-	    $num=count($elements);
60
-	}
61
-	//var_dump($num);
62
-
63
-	// determine type
64
-	if (is_numeric(key($elements)) && key($elements) == 0)
65
-	{
66
-		// indexed (list)
67
-		$keysofelements=array_keys($elements);	// Elements array mus have key that does not start with 0 and end with num-1, so we will use this later.
68
-		$output = '[';
69
-		for ($i = 0, $last = ($num - 1); $i < $num; $i++)
70
-		{
71
-			if (! isset($elements[$keysofelements[$i]])) continue;
72
-			if (is_array($elements[$keysofelements[$i]]) || is_object($elements[$keysofelements[$i]])) $output.= json_encode($elements[$keysofelements[$i]]);
73
-			else $output .= _val($elements[$keysofelements[$i]]);
74
-			if ($i !== $last) $output.= ',';
75
-		}
76
-		$output.= ']';
77
-	}
78
-	else
79
-	{
80
-		// associative (object)
81
-		$output = '{';
82
-		$last = $num - 1;
83
-		$i = 0;
84
-		$tmpelements=array();
85
-		if (is_array($elements)) $tmpelements=$elements;
86
-		if (is_object($elements)) $tmpelements=get_object_vars($elements);
87
-		foreach($tmpelements as $key => $value)
88
-		{
89
-			$output .= '"'.$key.'":';
90
-			if (is_array($value)) $output.= json_encode($value);
91
-			else $output .= _val($value);
92
-			if ($i !== $last) $output.= ',';
93
-			++$i;
94
-		}
95
-		$output.= '}';
96
-	}
97
-
98
-	// return
99
-	return $output;
50
+    dol_syslog("For better performance, enable the native json in your PHP", LOG_WARNING);
51
+
52
+    $num=0;
53
+    if (is_object($elements))	// Count number of properties for an object
54
+    {
55
+        foreach($elements as $key => $value) $num++;
56
+    }
57
+    else
58
+    {
59
+        $num=count($elements);
60
+    }
61
+    //var_dump($num);
62
+
63
+    // determine type
64
+    if (is_numeric(key($elements)) && key($elements) == 0)
65
+    {
66
+        // indexed (list)
67
+        $keysofelements=array_keys($elements);	// Elements array mus have key that does not start with 0 and end with num-1, so we will use this later.
68
+        $output = '[';
69
+        for ($i = 0, $last = ($num - 1); $i < $num; $i++)
70
+        {
71
+            if (! isset($elements[$keysofelements[$i]])) continue;
72
+            if (is_array($elements[$keysofelements[$i]]) || is_object($elements[$keysofelements[$i]])) $output.= json_encode($elements[$keysofelements[$i]]);
73
+            else $output .= _val($elements[$keysofelements[$i]]);
74
+            if ($i !== $last) $output.= ',';
75
+        }
76
+        $output.= ']';
77
+    }
78
+    else
79
+    {
80
+        // associative (object)
81
+        $output = '{';
82
+        $last = $num - 1;
83
+        $i = 0;
84
+        $tmpelements=array();
85
+        if (is_array($elements)) $tmpelements=$elements;
86
+        if (is_object($elements)) $tmpelements=get_object_vars($elements);
87
+        foreach($tmpelements as $key => $value)
88
+        {
89
+            $output .= '"'.$key.'":';
90
+            if (is_array($value)) $output.= json_encode($value);
91
+            else $output .= _val($value);
92
+            if ($i !== $last) $output.= ',';
93
+            ++$i;
94
+        }
95
+        $output.= '}';
96
+    }
97
+
98
+    // return
99
+    return $output;
100 100
 }
101 101
 
102 102
 /**
@@ -107,8 +107,8 @@  discard block
 block discarded – undo
107 107
  */
108 108
 function _val($val)
109 109
 {
110
-	if (is_string($val))
111
-	{
110
+    if (is_string($val))
111
+    {
112 112
         // STRINGS ARE EXPECTED TO BE IN ASCII OR UTF-8 FORMAT
113 113
         $ascii = '';
114 114
         $strlen_var = strlen($val);
@@ -117,107 +117,107 @@  discard block
 block discarded – undo
117 117
 	     * Iterate over every character in the string,
118 118
 	     * escaping with a slash or encoding to UTF-8 where necessary
119 119
 	     */
120
-	    for ($c = 0; $c < $strlen_var; ++$c) {
121
-
122
-	        $ord_var_c = ord($val{$c});
123
-
124
-	        switch (true) {
125
-	            case $ord_var_c == 0x08:
126
-	                $ascii .= '\b';
127
-	                break;
128
-	            case $ord_var_c == 0x09:
129
-	                $ascii .= '\t';
130
-	                break;
131
-	            case $ord_var_c == 0x0A:
132
-	                $ascii .= '\n';
133
-	                break;
134
-	            case $ord_var_c == 0x0C:
135
-	                $ascii .= '\f';
136
-	                break;
137
-	            case $ord_var_c == 0x0D:
138
-	                $ascii .= '\r';
139
-	                break;
140
-
141
-	            case $ord_var_c == 0x22:
142
-	            case $ord_var_c == 0x2F:
143
-	            case $ord_var_c == 0x5C:
144
-	                // double quote, slash, slosh
145
-	                $ascii .= '\\'.$val{$c};
146
-	                break;
147
-
148
-	            case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
149
-	                // characters U-00000000 - U-0000007F (same as ASCII)
150
-	                $ascii .= $val{$c};
151
-	                break;
152
-
153
-	            case (($ord_var_c & 0xE0) == 0xC0):
154
-	                // characters U-00000080 - U-000007FF, mask 110XXXXX
155
-	                // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
156
-	                $char = pack('C*', $ord_var_c, ord($val{$c + 1}));
157
-	                $c += 1;
158
-	                $utf16 = utf82utf16($char);
159
-	                $ascii .= sprintf('\u%04s', bin2hex($utf16));
160
-	                break;
161
-
162
-	            case (($ord_var_c & 0xF0) == 0xE0):
163
-	                // characters U-00000800 - U-0000FFFF, mask 1110XXXX
164
-	                // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
165
-	                $char = pack('C*', $ord_var_c, ord($val{$c + 1}), ord($val{$c + 2}));
166
-	                $c += 2;
167
-	                $utf16 = utf82utf16($char);
168
-	                $ascii .= sprintf('\u%04s', bin2hex($utf16));
169
-	                break;
170
-
171
-	            case (($ord_var_c & 0xF8) == 0xF0):
172
-	                // characters U-00010000 - U-001FFFFF, mask 11110XXX
173
-	                // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
174
-	                $char = pack('C*', $ord_var_c, ord($val{$c + 1}), ord($val{$c + 2}), ord($val{$c + 3}));
175
-	                $c += 3;
176
-	                $utf16 = utf82utf16($char);
177
-	                $ascii .= sprintf('\u%04s', bin2hex($utf16));
178
-	                break;
179
-
180
-	            case (($ord_var_c & 0xFC) == 0xF8):
181
-	                // characters U-00200000 - U-03FFFFFF, mask 111110XX
182
-	                // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
183
-	                $char = pack('C*', $ord_var_c, ord($val{$c + 1}), ord($val{$c + 2}), ord($val{$c + 3}), ord($val{$c + 4}));
184
-	                $c += 4;
185
-	                $utf16 = utf82utf16($char);
186
-	                $ascii .= sprintf('\u%04s', bin2hex($utf16));
187
-	                break;
188
-
189
-	            case (($ord_var_c & 0xFE) == 0xFC):
190
-	                // characters U-04000000 - U-7FFFFFFF, mask 1111110X
191
-	                // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
192
-	                $char = pack('C*', $ord_var_c, ord($val{$c + 1}), ord($val{$c + 2}), ord($val{$c + 3}), ord($val{$c + 4}), ord($val{$c + 5}));
193
-	                $c += 5;
194
-	                $utf16 = utf82utf16($char);
195
-	                $ascii .= sprintf('\u%04s', bin2hex($utf16));
196
-	                break;
197
-	        }
198
-	    }
199
-
200
-	    return '"'.$ascii.'"';
201
-	}
202
-	elseif (is_int($val)) return sprintf('%d', $val);
203
-	elseif (is_float($val)) return sprintf('%F', $val);
204
-	elseif (is_bool($val)) return ($val ? 'true' : 'false');
205
-	else  return 'null';
120
+        for ($c = 0; $c < $strlen_var; ++$c) {
121
+
122
+            $ord_var_c = ord($val{$c});
123
+
124
+            switch (true) {
125
+                case $ord_var_c == 0x08:
126
+                    $ascii .= '\b';
127
+                    break;
128
+                case $ord_var_c == 0x09:
129
+                    $ascii .= '\t';
130
+                    break;
131
+                case $ord_var_c == 0x0A:
132
+                    $ascii .= '\n';
133
+                    break;
134
+                case $ord_var_c == 0x0C:
135
+                    $ascii .= '\f';
136
+                    break;
137
+                case $ord_var_c == 0x0D:
138
+                    $ascii .= '\r';
139
+                    break;
140
+
141
+                case $ord_var_c == 0x22:
142
+                case $ord_var_c == 0x2F:
143
+                case $ord_var_c == 0x5C:
144
+                    // double quote, slash, slosh
145
+                    $ascii .= '\\'.$val{$c};
146
+                    break;
147
+
148
+                case (($ord_var_c >= 0x20) && ($ord_var_c <= 0x7F)):
149
+                    // characters U-00000000 - U-0000007F (same as ASCII)
150
+                    $ascii .= $val{$c};
151
+                    break;
152
+
153
+                case (($ord_var_c & 0xE0) == 0xC0):
154
+                    // characters U-00000080 - U-000007FF, mask 110XXXXX
155
+                    // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
156
+                    $char = pack('C*', $ord_var_c, ord($val{$c + 1}));
157
+                    $c += 1;
158
+                    $utf16 = utf82utf16($char);
159
+                    $ascii .= sprintf('\u%04s', bin2hex($utf16));
160
+                    break;
161
+
162
+                case (($ord_var_c & 0xF0) == 0xE0):
163
+                    // characters U-00000800 - U-0000FFFF, mask 1110XXXX
164
+                    // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
165
+                    $char = pack('C*', $ord_var_c, ord($val{$c + 1}), ord($val{$c + 2}));
166
+                    $c += 2;
167
+                    $utf16 = utf82utf16($char);
168
+                    $ascii .= sprintf('\u%04s', bin2hex($utf16));
169
+                    break;
170
+
171
+                case (($ord_var_c & 0xF8) == 0xF0):
172
+                    // characters U-00010000 - U-001FFFFF, mask 11110XXX
173
+                    // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
174
+                    $char = pack('C*', $ord_var_c, ord($val{$c + 1}), ord($val{$c + 2}), ord($val{$c + 3}));
175
+                    $c += 3;
176
+                    $utf16 = utf82utf16($char);
177
+                    $ascii .= sprintf('\u%04s', bin2hex($utf16));
178
+                    break;
179
+
180
+                case (($ord_var_c & 0xFC) == 0xF8):
181
+                    // characters U-00200000 - U-03FFFFFF, mask 111110XX
182
+                    // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
183
+                    $char = pack('C*', $ord_var_c, ord($val{$c + 1}), ord($val{$c + 2}), ord($val{$c + 3}), ord($val{$c + 4}));
184
+                    $c += 4;
185
+                    $utf16 = utf82utf16($char);
186
+                    $ascii .= sprintf('\u%04s', bin2hex($utf16));
187
+                    break;
188
+
189
+                case (($ord_var_c & 0xFE) == 0xFC):
190
+                    // characters U-04000000 - U-7FFFFFFF, mask 1111110X
191
+                    // see http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
192
+                    $char = pack('C*', $ord_var_c, ord($val{$c + 1}), ord($val{$c + 2}), ord($val{$c + 3}), ord($val{$c + 4}), ord($val{$c + 5}));
193
+                    $c += 5;
194
+                    $utf16 = utf82utf16($char);
195
+                    $ascii .= sprintf('\u%04s', bin2hex($utf16));
196
+                    break;
197
+            }
198
+        }
199
+
200
+        return '"'.$ascii.'"';
201
+    }
202
+    elseif (is_int($val)) return sprintf('%d', $val);
203
+    elseif (is_float($val)) return sprintf('%F', $val);
204
+    elseif (is_bool($val)) return ($val ? 'true' : 'false');
205
+    else  return 'null';
206 206
 }
207 207
 
208 208
 if (! function_exists('json_decode'))
209 209
 {
210
-	/**
211
-	 * Implement json_decode for PHP that does not support it
212
-	 *
213
-	 * @param	string	$json		Json encoded to PHP Object or Array
214
-	 * @param	bool	$assoc		False return an object, true return an array
215
-	 * @return 	mixed				Object or Array
216
-	 */
217
-	function json_decode($json, $assoc=false)
218
-	{
219
-		return dol_json_decode($json, $assoc);
220
-	}
210
+    /**
211
+     * Implement json_decode for PHP that does not support it
212
+     *
213
+     * @param	string	$json		Json encoded to PHP Object or Array
214
+     * @param	bool	$assoc		False return an object, true return an array
215
+     * @return 	mixed				Object or Array
216
+     */
217
+    function json_decode($json, $assoc=false)
218
+    {
219
+        return dol_json_decode($json, $assoc);
220
+    }
221 221
 }
222 222
 
223 223
 /**
@@ -231,52 +231,52 @@  discard block
 block discarded – undo
231 231
  */
232 232
 function dol_json_decode($json, $assoc=false)
233 233
 {
234
-	dol_syslog("For better performance, enable the native json in your PHP", LOG_WARNING);
234
+    dol_syslog("For better performance, enable the native json in your PHP", LOG_WARNING);
235 235
 
236
-	$comment = false;
236
+    $comment = false;
237 237
 
238 238
     $out='';
239
-	$strLength = strlen($json);    // Must stay strlen and not dol_strlen because we want technical length, not visible length
240
-	for ($i=0; $i<$strLength; $i++)
241
-	{
242
-		if (! $comment)
243
-		{
244
-			if (($json[$i] == '{') || ($json[$i] == '[')) $out.= 'array(';
245
-			else if (($json[$i] == '}') || ($json[$i] == ']')) $out.= ')';
246
-			else if ($json[$i] == ':') $out.= ' => ';
247
-			else $out.=$json[$i];
248
-		}
249
-		else $out.= $json[$i];
250
-		if ($json[$i] == '"' && $json[($i-1)]!="\\") $comment = !$comment;
251
-	}
252
-
253
-	$out=_unval($out);
254
-
255
-	// Return an array
256
-	if ($out != '') eval('$array = '.$out.';');
257
-	else $array=array();
258
-
259
-	// Return an object
260
-	if (! $assoc)
261
-	{
262
-		if (! empty($array))
263
-		{
264
-			$object = false;
265
-			if (count($array)>0) {
266
-				$object = (object) array();
267
-			}
268
-			foreach ($array as $key => $value)
269
-			{
270
-				if ($key) $object->{$key} = $value;
271
-			}
272
-
273
-			return $object;
274
-		}
275
-
276
-		return false;
277
-	}
278
-
279
-	return $array;
239
+    $strLength = strlen($json);    // Must stay strlen and not dol_strlen because we want technical length, not visible length
240
+    for ($i=0; $i<$strLength; $i++)
241
+    {
242
+        if (! $comment)
243
+        {
244
+            if (($json[$i] == '{') || ($json[$i] == '[')) $out.= 'array(';
245
+            else if (($json[$i] == '}') || ($json[$i] == ']')) $out.= ')';
246
+            else if ($json[$i] == ':') $out.= ' => ';
247
+            else $out.=$json[$i];
248
+        }
249
+        else $out.= $json[$i];
250
+        if ($json[$i] == '"' && $json[($i-1)]!="\\") $comment = !$comment;
251
+    }
252
+
253
+    $out=_unval($out);
254
+
255
+    // Return an array
256
+    if ($out != '') eval('$array = '.$out.';');
257
+    else $array=array();
258
+
259
+    // Return an object
260
+    if (! $assoc)
261
+    {
262
+        if (! empty($array))
263
+        {
264
+            $object = false;
265
+            if (count($array)>0) {
266
+                $object = (object) array();
267
+            }
268
+            foreach ($array as $key => $value)
269
+            {
270
+                if ($key) $object->{$key} = $value;
271
+            }
272
+
273
+            return $object;
274
+        }
275
+
276
+        return false;
277
+    }
278
+
279
+    return $array;
280 280
 }
281 281
 
282 282
 /**
@@ -287,14 +287,14 @@  discard block
 block discarded – undo
287 287
  */
288 288
 function _unval($val)
289 289
 {
290
-	while (preg_match('/\\\u([0-9A-F]{2})([0-9A-F]{2})/i', $val, $reg))
291
-	{
292
-	    // single, escaped unicode character
293
-	    $utf16 = chr(hexdec($reg[1])) . chr(hexdec($reg[2]));
294
-	    $utf8  = utf162utf8($utf16);
295
-	    $val=preg_replace('/\\\u'.$reg[1].$reg[2].'/i',$utf8,$val);
296
-	}
297
-	return $val;
290
+    while (preg_match('/\\\u([0-9A-F]{2})([0-9A-F]{2})/i', $val, $reg))
291
+    {
292
+        // single, escaped unicode character
293
+        $utf16 = chr(hexdec($reg[1])) . chr(hexdec($reg[2]));
294
+        $utf8  = utf162utf8($utf16);
295
+        $val=preg_replace('/\\\u'.$reg[1].$reg[2].'/i',$utf8,$val);
296
+    }
297
+    return $val;
298 298
 }
299 299
 
300 300
 /**
@@ -309,35 +309,35 @@  discard block
 block discarded – undo
309 309
  */
310 310
 function utf162utf8($utf16)
311 311
 {
312
-	// oh please oh please oh please oh please oh please
313
-	if(function_exists('mb_convert_encoding')) {
314
-	    return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
315
-	}
316
-
317
-	$bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
318
-
319
-	switch(true) {
320
-    	case ((0x7F & $bytes) == $bytes):
321
-    	// this case should never be reached, because we are in ASCII range
322
-    	// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
323
-    	return chr($bytes);
324
-
325
-    	case (0x07FF & $bytes) == $bytes:
326
-    	// return a 2-byte UTF-8 character
327
-    	// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
328
-    	return chr(0xC0 | (($bytes >> 6) & 0x1F))
329
-    	. chr(0x80 | ($bytes & 0x3F));
330
-
331
-    	case (0xFFFF & $bytes) == $bytes:
332
-    	// return a 3-byte UTF-8 character
333
-    	// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
334
-    	return chr(0xE0 | (($bytes >> 12) & 0x0F))
335
-    	. chr(0x80 | (($bytes >> 6) & 0x3F))
336
-    	. chr(0x80 | ($bytes & 0x3F));
337
-	}
338
-
339
-	// ignoring UTF-32 for now, sorry
340
-	return '';
312
+    // oh please oh please oh please oh please oh please
313
+    if(function_exists('mb_convert_encoding')) {
314
+        return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
315
+    }
316
+
317
+    $bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
318
+
319
+    switch(true) {
320
+        case ((0x7F & $bytes) == $bytes):
321
+        // this case should never be reached, because we are in ASCII range
322
+        // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
323
+        return chr($bytes);
324
+
325
+        case (0x07FF & $bytes) == $bytes:
326
+        // return a 2-byte UTF-8 character
327
+        // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
328
+        return chr(0xC0 | (($bytes >> 6) & 0x1F))
329
+        . chr(0x80 | ($bytes & 0x3F));
330
+
331
+        case (0xFFFF & $bytes) == $bytes:
332
+        // return a 3-byte UTF-8 character
333
+        // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
334
+        return chr(0xE0 | (($bytes >> 12) & 0x0F))
335
+        . chr(0x80 | (($bytes >> 6) & 0x3F))
336
+        . chr(0x80 | ($bytes & 0x3F));
337
+    }
338
+
339
+    // ignoring UTF-32 for now, sorry
340
+    return '';
341 341
 }
342 342
 
343 343
 /**
@@ -352,28 +352,28 @@  discard block
 block discarded – undo
352 352
  */
353 353
 function utf82utf16($utf8)
354 354
 {
355
-	// oh please oh please oh please oh please oh please
356
-	if(function_exists('mb_convert_encoding')) {
357
-	return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
358
-	}
359
-
360
-	switch(strlen($utf8)) {
361
-		case 1:
362
-	        	// this case should never be reached, because we are in ASCII range
363
-		// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
364
-		return $utf8;
365
-
366
-		case 2:
367
-		// return a UTF-16 character from a 2-byte UTF-8 char
368
-		// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
369
-		return chr(0x07 & (ord($utf8{0}) >> 2)) . chr((0xC0 & (ord($utf8{0}) << 6)) | (0x3F & ord($utf8{1})));
370
-
371
-		case 3:
372
-		// return a UTF-16 character from a 3-byte UTF-8 char
373
-		// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
374
-		return chr((0xF0 & (ord($utf8{0}) << 4)) | (0x0F & (ord($utf8{1}) >> 2))) . chr((0xC0 & (ord($utf8{1}) << 6)) | (0x7F & ord($utf8{2})));
375
-	}
376
-
377
-	// ignoring UTF-32 for now, sorry
378
-	return '';
355
+    // oh please oh please oh please oh please oh please
356
+    if(function_exists('mb_convert_encoding')) {
357
+    return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
358
+    }
359
+
360
+    switch(strlen($utf8)) {
361
+        case 1:
362
+                // this case should never be reached, because we are in ASCII range
363
+        // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
364
+        return $utf8;
365
+
366
+        case 2:
367
+        // return a UTF-16 character from a 2-byte UTF-8 char
368
+        // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
369
+        return chr(0x07 & (ord($utf8{0}) >> 2)) . chr((0xC0 & (ord($utf8{0}) << 6)) | (0x3F & ord($utf8{1})));
370
+
371
+        case 3:
372
+        // return a UTF-16 character from a 3-byte UTF-8 char
373
+        // see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
374
+        return chr((0xF0 & (ord($utf8{0}) << 4)) | (0x0F & (ord($utf8{1}) >> 2))) . chr((0xC0 & (ord($utf8{1}) << 6)) | (0x7F & ord($utf8{2})));
375
+    }
376
+
377
+    // ignoring UTF-32 for now, sorry
378
+    return '';
379 379
 }
Please login to merge, or discard this patch.
Spacing   +42 added lines, -42 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  * 		\ingroup	core
24 24
  */
25 25
 
26
-if (! function_exists('json_encode'))
26
+if (!function_exists('json_encode'))
27 27
 {
28 28
 	/**
29 29
 	 * Implement json_encode for PHP that does not have module enabled.
@@ -49,14 +49,14 @@  discard block
 block discarded – undo
49 49
 {
50 50
 	dol_syslog("For better performance, enable the native json in your PHP", LOG_WARNING);
51 51
 
52
-	$num=0;
52
+	$num = 0;
53 53
 	if (is_object($elements))	// Count number of properties for an object
54 54
 	{
55
-		foreach($elements as $key => $value) $num++;
55
+		foreach ($elements as $key => $value) $num++;
56 56
 	}
57 57
 	else
58 58
 	{
59
-	    $num=count($elements);
59
+	    $num = count($elements);
60 60
 	}
61 61
 	//var_dump($num);
62 62
 
@@ -64,16 +64,16 @@  discard block
 block discarded – undo
64 64
 	if (is_numeric(key($elements)) && key($elements) == 0)
65 65
 	{
66 66
 		// indexed (list)
67
-		$keysofelements=array_keys($elements);	// Elements array mus have key that does not start with 0 and end with num-1, so we will use this later.
67
+		$keysofelements = array_keys($elements); // Elements array mus have key that does not start with 0 and end with num-1, so we will use this later.
68 68
 		$output = '[';
69 69
 		for ($i = 0, $last = ($num - 1); $i < $num; $i++)
70 70
 		{
71
-			if (! isset($elements[$keysofelements[$i]])) continue;
72
-			if (is_array($elements[$keysofelements[$i]]) || is_object($elements[$keysofelements[$i]])) $output.= json_encode($elements[$keysofelements[$i]]);
71
+			if (!isset($elements[$keysofelements[$i]])) continue;
72
+			if (is_array($elements[$keysofelements[$i]]) || is_object($elements[$keysofelements[$i]])) $output .= json_encode($elements[$keysofelements[$i]]);
73 73
 			else $output .= _val($elements[$keysofelements[$i]]);
74
-			if ($i !== $last) $output.= ',';
74
+			if ($i !== $last) $output .= ',';
75 75
 		}
76
-		$output.= ']';
76
+		$output .= ']';
77 77
 	}
78 78
 	else
79 79
 	{
@@ -81,18 +81,18 @@  discard block
 block discarded – undo
81 81
 		$output = '{';
82 82
 		$last = $num - 1;
83 83
 		$i = 0;
84
-		$tmpelements=array();
85
-		if (is_array($elements)) $tmpelements=$elements;
86
-		if (is_object($elements)) $tmpelements=get_object_vars($elements);
87
-		foreach($tmpelements as $key => $value)
84
+		$tmpelements = array();
85
+		if (is_array($elements)) $tmpelements = $elements;
86
+		if (is_object($elements)) $tmpelements = get_object_vars($elements);
87
+		foreach ($tmpelements as $key => $value)
88 88
 		{
89 89
 			$output .= '"'.$key.'":';
90
-			if (is_array($value)) $output.= json_encode($value);
90
+			if (is_array($value)) $output .= json_encode($value);
91 91
 			else $output .= _val($value);
92
-			if ($i !== $last) $output.= ',';
92
+			if ($i !== $last) $output .= ',';
93 93
 			++$i;
94 94
 		}
95
-		$output.= '}';
95
+		$output .= '}';
96 96
 	}
97 97
 
98 98
 	// return
@@ -205,7 +205,7 @@  discard block
 block discarded – undo
205 205
 	else  return 'null';
206 206
 }
207 207
 
208
-if (! function_exists('json_decode'))
208
+if (!function_exists('json_decode'))
209 209
 {
210 210
 	/**
211 211
 	 * Implement json_decode for PHP that does not support it
@@ -214,7 +214,7 @@  discard block
 block discarded – undo
214 214
 	 * @param	bool	$assoc		False return an object, true return an array
215 215
 	 * @return 	mixed				Object or Array
216 216
 	 */
217
-	function json_decode($json, $assoc=false)
217
+	function json_decode($json, $assoc = false)
218 218
 	{
219 219
 		return dol_json_decode($json, $assoc);
220 220
 	}
@@ -229,40 +229,40 @@  discard block
 block discarded – undo
229 229
  * @return 	mixed				Object or Array or false on error
230 230
  * @see json_decode()
231 231
  */
232
-function dol_json_decode($json, $assoc=false)
232
+function dol_json_decode($json, $assoc = false)
233 233
 {
234 234
 	dol_syslog("For better performance, enable the native json in your PHP", LOG_WARNING);
235 235
 
236 236
 	$comment = false;
237 237
 
238
-    $out='';
239
-	$strLength = strlen($json);    // Must stay strlen and not dol_strlen because we want technical length, not visible length
240
-	for ($i=0; $i<$strLength; $i++)
238
+    $out = '';
239
+	$strLength = strlen($json); // Must stay strlen and not dol_strlen because we want technical length, not visible length
240
+	for ($i = 0; $i < $strLength; $i++)
241 241
 	{
242
-		if (! $comment)
242
+		if (!$comment)
243 243
 		{
244
-			if (($json[$i] == '{') || ($json[$i] == '[')) $out.= 'array(';
245
-			else if (($json[$i] == '}') || ($json[$i] == ']')) $out.= ')';
246
-			else if ($json[$i] == ':') $out.= ' => ';
247
-			else $out.=$json[$i];
244
+			if (($json[$i] == '{') || ($json[$i] == '[')) $out .= 'array(';
245
+			else if (($json[$i] == '}') || ($json[$i] == ']')) $out .= ')';
246
+			else if ($json[$i] == ':') $out .= ' => ';
247
+			else $out .= $json[$i];
248 248
 		}
249
-		else $out.= $json[$i];
250
-		if ($json[$i] == '"' && $json[($i-1)]!="\\") $comment = !$comment;
249
+		else $out .= $json[$i];
250
+		if ($json[$i] == '"' && $json[($i - 1)] != "\\") $comment = !$comment;
251 251
 	}
252 252
 
253
-	$out=_unval($out);
253
+	$out = _unval($out);
254 254
 
255 255
 	// Return an array
256 256
 	if ($out != '') eval('$array = '.$out.';');
257
-	else $array=array();
257
+	else $array = array();
258 258
 
259 259
 	// Return an object
260
-	if (! $assoc)
260
+	if (!$assoc)
261 261
 	{
262
-		if (! empty($array))
262
+		if (!empty($array))
263 263
 		{
264 264
 			$object = false;
265
-			if (count($array)>0) {
265
+			if (count($array) > 0) {
266 266
 				$object = (object) array();
267 267
 			}
268 268
 			foreach ($array as $key => $value)
@@ -290,9 +290,9 @@  discard block
 block discarded – undo
290 290
 	while (preg_match('/\\\u([0-9A-F]{2})([0-9A-F]{2})/i', $val, $reg))
291 291
 	{
292 292
 	    // single, escaped unicode character
293
-	    $utf16 = chr(hexdec($reg[1])) . chr(hexdec($reg[2]));
293
+	    $utf16 = chr(hexdec($reg[1])).chr(hexdec($reg[2]));
294 294
 	    $utf8  = utf162utf8($utf16);
295
-	    $val=preg_replace('/\\\u'.$reg[1].$reg[2].'/i',$utf8,$val);
295
+	    $val = preg_replace('/\\\u'.$reg[1].$reg[2].'/i', $utf8, $val);
296 296
 	}
297 297
 	return $val;
298 298
 }
@@ -310,13 +310,13 @@  discard block
 block discarded – undo
310 310
 function utf162utf8($utf16)
311 311
 {
312 312
 	// oh please oh please oh please oh please oh please
313
-	if(function_exists('mb_convert_encoding')) {
313
+	if (function_exists('mb_convert_encoding')) {
314 314
 	    return mb_convert_encoding($utf16, 'UTF-8', 'UTF-16');
315 315
 	}
316 316
 
317 317
 	$bytes = (ord($utf16{0}) << 8) | ord($utf16{1});
318 318
 
319
-	switch(true) {
319
+	switch (true) {
320 320
     	case ((0x7F & $bytes) == $bytes):
321 321
     	// this case should never be reached, because we are in ASCII range
322 322
     	// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
@@ -353,11 +353,11 @@  discard block
 block discarded – undo
353 353
 function utf82utf16($utf8)
354 354
 {
355 355
 	// oh please oh please oh please oh please oh please
356
-	if(function_exists('mb_convert_encoding')) {
356
+	if (function_exists('mb_convert_encoding')) {
357 357
 	return mb_convert_encoding($utf8, 'UTF-16', 'UTF-8');
358 358
 	}
359 359
 
360
-	switch(strlen($utf8)) {
360
+	switch (strlen($utf8)) {
361 361
 		case 1:
362 362
 	        	// this case should never be reached, because we are in ASCII range
363 363
 		// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
@@ -366,12 +366,12 @@  discard block
 block discarded – undo
366 366
 		case 2:
367 367
 		// return a UTF-16 character from a 2-byte UTF-8 char
368 368
 		// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
369
-		return chr(0x07 & (ord($utf8{0}) >> 2)) . chr((0xC0 & (ord($utf8{0}) << 6)) | (0x3F & ord($utf8{1})));
369
+		return chr(0x07 & (ord($utf8{0}) >> 2)).chr((0xC0 & (ord($utf8{0}) << 6)) | (0x3F & ord($utf8{1})));
370 370
 
371 371
 		case 3:
372 372
 		// return a UTF-16 character from a 3-byte UTF-8 char
373 373
 		// see: http://www.cl.cam.ac.uk/~mgk25/unicode.html#utf-8
374
-		return chr((0xF0 & (ord($utf8{0}) << 4)) | (0x0F & (ord($utf8{1}) >> 2))) . chr((0xC0 & (ord($utf8{1}) << 6)) | (0x7F & ord($utf8{2})));
374
+		return chr((0xF0 & (ord($utf8{0}) << 4)) | (0x0F & (ord($utf8{1}) >> 2))).chr((0xC0 & (ord($utf8{1}) << 6)) | (0x7F & ord($utf8{2})));
375 375
 	}
376 376
 
377 377
 	// ignoring UTF-32 for now, sorry
Please login to merge, or discard this patch.
Braces   +60 added lines, -27 removed lines patch added patch discarded remove patch
@@ -50,11 +50,12 @@  discard block
 block discarded – undo
50 50
 	dol_syslog("For better performance, enable the native json in your PHP", LOG_WARNING);
51 51
 
52 52
 	$num=0;
53
-	if (is_object($elements))	// Count number of properties for an object
53
+	if (is_object($elements)) {
54
+	    // Count number of properties for an object
54 55
 	{
55 56
 		foreach($elements as $key => $value) $num++;
56 57
 	}
57
-	else
58
+	} else
58 59
 	{
59 60
 	    $num=count($elements);
60 61
 	}
@@ -68,28 +69,43 @@  discard block
 block discarded – undo
68 69
 		$output = '[';
69 70
 		for ($i = 0, $last = ($num - 1); $i < $num; $i++)
70 71
 		{
71
-			if (! isset($elements[$keysofelements[$i]])) continue;
72
-			if (is_array($elements[$keysofelements[$i]]) || is_object($elements[$keysofelements[$i]])) $output.= json_encode($elements[$keysofelements[$i]]);
73
-			else $output .= _val($elements[$keysofelements[$i]]);
74
-			if ($i !== $last) $output.= ',';
72
+			if (! isset($elements[$keysofelements[$i]])) {
73
+			    continue;
74
+			}
75
+			if (is_array($elements[$keysofelements[$i]]) || is_object($elements[$keysofelements[$i]])) {
76
+			    $output.= json_encode($elements[$keysofelements[$i]]);
77
+			} else {
78
+			    $output .= _val($elements[$keysofelements[$i]]);
79
+			}
80
+			if ($i !== $last) {
81
+			    $output.= ',';
82
+			}
75 83
 		}
76 84
 		$output.= ']';
77
-	}
78
-	else
85
+	} else
79 86
 	{
80 87
 		// associative (object)
81 88
 		$output = '{';
82 89
 		$last = $num - 1;
83 90
 		$i = 0;
84 91
 		$tmpelements=array();
85
-		if (is_array($elements)) $tmpelements=$elements;
86
-		if (is_object($elements)) $tmpelements=get_object_vars($elements);
92
+		if (is_array($elements)) {
93
+		    $tmpelements=$elements;
94
+		}
95
+		if (is_object($elements)) {
96
+		    $tmpelements=get_object_vars($elements);
97
+		}
87 98
 		foreach($tmpelements as $key => $value)
88 99
 		{
89 100
 			$output .= '"'.$key.'":';
90
-			if (is_array($value)) $output.= json_encode($value);
91
-			else $output .= _val($value);
92
-			if ($i !== $last) $output.= ',';
101
+			if (is_array($value)) {
102
+			    $output.= json_encode($value);
103
+			} else {
104
+			    $output .= _val($value);
105
+			}
106
+			if ($i !== $last) {
107
+			    $output.= ',';
108
+			}
93 109
 			++$i;
94 110
 		}
95 111
 		$output.= '}';
@@ -198,12 +214,16 @@  discard block
 block discarded – undo
198 214
 	    }
199 215
 
200 216
 	    return '"'.$ascii.'"';
217
+	} elseif (is_int($val)) {
218
+	    return sprintf('%d', $val);
219
+	} elseif (is_float($val)) {
220
+	    return sprintf('%F', $val);
221
+	} elseif (is_bool($val)) {
222
+	    return ($val ? 'true' : 'false');
223
+	} else {
224
+	    return 'null';
225
+	}
201 226
 	}
202
-	elseif (is_int($val)) return sprintf('%d', $val);
203
-	elseif (is_float($val)) return sprintf('%F', $val);
204
-	elseif (is_bool($val)) return ($val ? 'true' : 'false');
205
-	else  return 'null';
206
-}
207 227
 
208 228
 if (! function_exists('json_decode'))
209 229
 {
@@ -241,20 +261,31 @@  discard block
 block discarded – undo
241 261
 	{
242 262
 		if (! $comment)
243 263
 		{
244
-			if (($json[$i] == '{') || ($json[$i] == '[')) $out.= 'array(';
245
-			else if (($json[$i] == '}') || ($json[$i] == ']')) $out.= ')';
246
-			else if ($json[$i] == ':') $out.= ' => ';
247
-			else $out.=$json[$i];
264
+			if (($json[$i] == '{') || ($json[$i] == '[')) {
265
+			    $out.= 'array(';
266
+			} else if (($json[$i] == '}') || ($json[$i] == ']')) {
267
+			    $out.= ')';
268
+			} else if ($json[$i] == ':') {
269
+			    $out.= ' => ';
270
+			} else {
271
+			    $out.=$json[$i];
272
+			}
273
+		} else {
274
+		    $out.= $json[$i];
275
+		}
276
+		if ($json[$i] == '"' && $json[($i-1)]!="\\") {
277
+		    $comment = !$comment;
248 278
 		}
249
-		else $out.= $json[$i];
250
-		if ($json[$i] == '"' && $json[($i-1)]!="\\") $comment = !$comment;
251 279
 	}
252 280
 
253 281
 	$out=_unval($out);
254 282
 
255 283
 	// Return an array
256
-	if ($out != '') eval('$array = '.$out.';');
257
-	else $array=array();
284
+	if ($out != '') {
285
+	    eval('$array = '.$out.';');
286
+	} else {
287
+	    $array=array();
288
+	}
258 289
 
259 290
 	// Return an object
260 291
 	if (! $assoc)
@@ -267,7 +298,9 @@  discard block
 block discarded – undo
267 298
 			}
268 299
 			foreach ($array as $key => $value)
269 300
 			{
270
-				if ($key) $object->{$key} = $value;
301
+				if ($key) {
302
+				    $object->{$key} = $value;
303
+				}
271 304
 			}
272 305
 
273 306
 			return $object;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/lib/doc.lib.php 3 patches
Indentation   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -40,129 +40,129 @@
 block discarded – undo
40 40
  */
41 41
 function doc_getlinedesc($line,$outputlangs,$hideref=0,$hidedesc=0,$issupplierline=0)
42 42
 {
43
-	global $db, $conf, $langs;
43
+    global $db, $conf, $langs;
44 44
 
45
-	$idprod=$line->fk_product;
46
-	$label=(! empty($line->label)?$line->label:(! empty($line->libelle)?$line->libelle:''));
47
-	$desc=(! empty($line->desc)?$line->desc:(! empty($line->description)?$line->description:''));
48
-	$ref_supplier=(! empty($line->ref_supplier)?$line->ref_supplier:(! empty($line->ref_fourn)?$line->ref_fourn:''));    // TODO Not yet saved for supplier invoices, only supplier orders
49
-	$note=(! empty($line->note)?$line->note:'');
45
+    $idprod=$line->fk_product;
46
+    $label=(! empty($line->label)?$line->label:(! empty($line->libelle)?$line->libelle:''));
47
+    $desc=(! empty($line->desc)?$line->desc:(! empty($line->description)?$line->description:''));
48
+    $ref_supplier=(! empty($line->ref_supplier)?$line->ref_supplier:(! empty($line->ref_fourn)?$line->ref_fourn:''));    // TODO Not yet saved for supplier invoices, only supplier orders
49
+    $note=(! empty($line->note)?$line->note:'');
50 50
 
51
-	if ($issupplierline) $prodser = new ProductFournisseur($db);
52
-	else $prodser = new Product($db);
51
+    if ($issupplierline) $prodser = new ProductFournisseur($db);
52
+    else $prodser = new Product($db);
53 53
 
54
-	if ($idprod)
55
-	{
56
-		$prodser->fetch($idprod);
57
-		// If a predefined product and multilang and on other lang, we renamed label with label translated
58
-		if (! empty($conf->global->MAIN_MULTILANGS) && ($outputlangs->defaultlang != $langs->defaultlang))
59
-		{
60
-			if (! empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && $label == $prodser->label)     $label=$prodser->multilangs[$outputlangs->defaultlang]["label"];
61
-			if (! empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && $desc == $prodser->description) $desc=$prodser->multilangs[$outputlangs->defaultlang]["description"];
62
-			if (! empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && $note == $prodser->note)        $note=$prodser->multilangs[$outputlangs->defaultlang]["note"];
63
-		}
64
-	}
54
+    if ($idprod)
55
+    {
56
+        $prodser->fetch($idprod);
57
+        // If a predefined product and multilang and on other lang, we renamed label with label translated
58
+        if (! empty($conf->global->MAIN_MULTILANGS) && ($outputlangs->defaultlang != $langs->defaultlang))
59
+        {
60
+            if (! empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && $label == $prodser->label)     $label=$prodser->multilangs[$outputlangs->defaultlang]["label"];
61
+            if (! empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && $desc == $prodser->description) $desc=$prodser->multilangs[$outputlangs->defaultlang]["description"];
62
+            if (! empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && $note == $prodser->note)        $note=$prodser->multilangs[$outputlangs->defaultlang]["note"];
63
+        }
64
+    }
65 65
 
66
-	// Description short of product line
67
-	$libelleproduitservice=$label;
66
+    // Description short of product line
67
+    $libelleproduitservice=$label;
68 68
 
69
-	// Description long of product line
70
-	if ($desc && ($desc != $label))
71
-	{
72
-		if ($desc == '(CREDIT_NOTE)' && $line->fk_remise_except)
73
-		{
74
-			$discount=new DiscountAbsolute($db);
75
-			$discount->fetch($line->fk_remise_except);
76
-			$sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
77
-			$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$sourceref);
78
-		}
79
-		elseif ($desc == '(DEPOSIT)' && $line->fk_remise_except)
80
-		{
81
-		    $discount=new DiscountAbsolute($db);
82
-		    $discount->fetch($line->fk_remise_except);
83
-		    $sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
84
-		    $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$sourceref);
85
-		    // Add date of deposit
86
-		    if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) $libelleproduitservice.=' ('.dol_print_date($discount->datec,'day','',$outputlangs).')';
87
-		}
88
-		elseif ($desc == '(EXCESS RECEIVED)' && $line->fk_remise_except)
89
-		{
90
-			$discount=new DiscountAbsolute($db);
91
-			$discount->fetch($line->fk_remise_except);
92
-			$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived",$discount->ref_facture_source);
93
-		}
94
-		elseif ($desc == '(EXCESS PAID)' && $line->fk_remise_except)
95
-		{
96
-			$discount=new DiscountAbsolute($db);
97
-			$discount->fetch($line->fk_remise_except);
98
-			$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessPaid",$discount->ref_invoice_supplier_source);
99
-		}
100
-		else
101
-		{
102
-			if ($idprod)
103
-			{
104
-				if (empty($hidedesc)) $libelleproduitservice=dol_concatdesc($libelleproduitservice, $desc);
105
-			}
106
-			else
107
-			{
108
-				$libelleproduitservice=dol_concatdesc($libelleproduitservice, $desc);
109
-			}
110
-		}
111
-	}
69
+    // Description long of product line
70
+    if ($desc && ($desc != $label))
71
+    {
72
+        if ($desc == '(CREDIT_NOTE)' && $line->fk_remise_except)
73
+        {
74
+            $discount=new DiscountAbsolute($db);
75
+            $discount->fetch($line->fk_remise_except);
76
+            $sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
77
+            $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$sourceref);
78
+        }
79
+        elseif ($desc == '(DEPOSIT)' && $line->fk_remise_except)
80
+        {
81
+            $discount=new DiscountAbsolute($db);
82
+            $discount->fetch($line->fk_remise_except);
83
+            $sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
84
+            $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$sourceref);
85
+            // Add date of deposit
86
+            if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) $libelleproduitservice.=' ('.dol_print_date($discount->datec,'day','',$outputlangs).')';
87
+        }
88
+        elseif ($desc == '(EXCESS RECEIVED)' && $line->fk_remise_except)
89
+        {
90
+            $discount=new DiscountAbsolute($db);
91
+            $discount->fetch($line->fk_remise_except);
92
+            $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived",$discount->ref_facture_source);
93
+        }
94
+        elseif ($desc == '(EXCESS PAID)' && $line->fk_remise_except)
95
+        {
96
+            $discount=new DiscountAbsolute($db);
97
+            $discount->fetch($line->fk_remise_except);
98
+            $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessPaid",$discount->ref_invoice_supplier_source);
99
+        }
100
+        else
101
+        {
102
+            if ($idprod)
103
+            {
104
+                if (empty($hidedesc)) $libelleproduitservice=dol_concatdesc($libelleproduitservice, $desc);
105
+            }
106
+            else
107
+            {
108
+                $libelleproduitservice=dol_concatdesc($libelleproduitservice, $desc);
109
+            }
110
+        }
111
+    }
112 112
 
113
-	// If line linked to a product
114
-	if ($idprod)
115
-	{
116
-		// On ajoute la ref
117
-		if ($prodser->ref)
118
-		{
119
-			$prefix_prodserv = "";
120
-			$ref_prodserv = "";
121
-			if (! empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS))   // In standard mode, we do not show this
122
-			{
123
-				if ($prodser->isService())
124
-				{
125
-					$prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." ";
126
-				}
127
-				else
128
-				{
129
-					$prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product")." ";
130
-				}
131
-			}
113
+    // If line linked to a product
114
+    if ($idprod)
115
+    {
116
+        // On ajoute la ref
117
+        if ($prodser->ref)
118
+        {
119
+            $prefix_prodserv = "";
120
+            $ref_prodserv = "";
121
+            if (! empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS))   // In standard mode, we do not show this
122
+            {
123
+                if ($prodser->isService())
124
+                {
125
+                    $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." ";
126
+                }
127
+                else
128
+                {
129
+                    $prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product")." ";
130
+                }
131
+            }
132 132
 
133
-			if (empty($hideref))
134
-			{
135
-				if ($issupplierline) $ref_prodserv = $prodser->ref.' ('.$outputlangs->trans("SupplierRef").' '.$ref_supplier.')';   // Show local ref and supplier ref
136
-				else $ref_prodserv = $prodser->ref; // Show local ref only
133
+            if (empty($hideref))
134
+            {
135
+                if ($issupplierline) $ref_prodserv = $prodser->ref.' ('.$outputlangs->trans("SupplierRef").' '.$ref_supplier.')';   // Show local ref and supplier ref
136
+                else $ref_prodserv = $prodser->ref; // Show local ref only
137 137
 
138
-				$ref_prodserv .= " - ";
139
-			}
138
+                $ref_prodserv .= " - ";
139
+            }
140 140
 
141
-			$libelleproduitservice=$prefix_prodserv.$ref_prodserv.$libelleproduitservice;
142
-		}
143
-	}
141
+            $libelleproduitservice=$prefix_prodserv.$ref_prodserv.$libelleproduitservice;
142
+        }
143
+    }
144 144
 
145
-	if (! empty($line->date_start) || ! empty($line->date_end))
146
-	{
147
-		$format='day';
148
-		// Show duration if exists
149
-		if ($line->date_start && $line->date_end)
150
-		{
151
-			$period='('.$outputlangs->transnoentitiesnoconv('DateFromTo',dol_print_date($line->date_start, $format, false, $outputlangs),dol_print_date($line->date_end, $format, false, $outputlangs)).')';
152
-		}
153
-		if ($line->date_start && ! $line->date_end)
154
-		{
155
-			$period='('.$outputlangs->transnoentitiesnoconv('DateFrom',dol_print_date($line->date_start, $format, false, $outputlangs)).')';
156
-		}
157
-		if (! $line->date_start && $line->date_end)
158
-		{
159
-			$period='('.$outputlangs->transnoentitiesnoconv('DateUntil',dol_print_date($line->date_end, $format, false, $outputlangs)).')';
160
-		}
161
-		//print '>'.$outputlangs->charset_output.','.$period;
162
-		$libelleproduitservice=dol_concatdesc($libelleproduitservice, $period);
163
-		//print $libelleproduitservice;
164
-	}
145
+    if (! empty($line->date_start) || ! empty($line->date_end))
146
+    {
147
+        $format='day';
148
+        // Show duration if exists
149
+        if ($line->date_start && $line->date_end)
150
+        {
151
+            $period='('.$outputlangs->transnoentitiesnoconv('DateFromTo',dol_print_date($line->date_start, $format, false, $outputlangs),dol_print_date($line->date_end, $format, false, $outputlangs)).')';
152
+        }
153
+        if ($line->date_start && ! $line->date_end)
154
+        {
155
+            $period='('.$outputlangs->transnoentitiesnoconv('DateFrom',dol_print_date($line->date_start, $format, false, $outputlangs)).')';
156
+        }
157
+        if (! $line->date_start && $line->date_end)
158
+        {
159
+            $period='('.$outputlangs->transnoentitiesnoconv('DateUntil',dol_print_date($line->date_end, $format, false, $outputlangs)).')';
160
+        }
161
+        //print '>'.$outputlangs->charset_output.','.$period;
162
+        $libelleproduitservice=dol_concatdesc($libelleproduitservice, $period);
163
+        //print $libelleproduitservice;
164
+    }
165 165
 
166
-	return $libelleproduitservice;
166
+    return $libelleproduitservice;
167 167
 }
168 168
 
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -38,15 +38,15 @@  discard block
 block discarded – undo
38 38
  *  @param  int			$issupplierline      Is it a line for a supplier object ?
39 39
  *  @return string       				     String with line
40 40
  */
41
-function doc_getlinedesc($line,$outputlangs,$hideref=0,$hidedesc=0,$issupplierline=0)
41
+function doc_getlinedesc($line, $outputlangs, $hideref = 0, $hidedesc = 0, $issupplierline = 0)
42 42
 {
43 43
 	global $db, $conf, $langs;
44 44
 
45
-	$idprod=$line->fk_product;
46
-	$label=(! empty($line->label)?$line->label:(! empty($line->libelle)?$line->libelle:''));
47
-	$desc=(! empty($line->desc)?$line->desc:(! empty($line->description)?$line->description:''));
48
-	$ref_supplier=(! empty($line->ref_supplier)?$line->ref_supplier:(! empty($line->ref_fourn)?$line->ref_fourn:''));    // TODO Not yet saved for supplier invoices, only supplier orders
49
-	$note=(! empty($line->note)?$line->note:'');
45
+	$idprod = $line->fk_product;
46
+	$label = (!empty($line->label) ? $line->label : (!empty($line->libelle) ? $line->libelle : ''));
47
+	$desc = (!empty($line->desc) ? $line->desc : (!empty($line->description) ? $line->description : ''));
48
+	$ref_supplier = (!empty($line->ref_supplier) ? $line->ref_supplier : (!empty($line->ref_fourn) ? $line->ref_fourn : '')); // TODO Not yet saved for supplier invoices, only supplier orders
49
+	$note = (!empty($line->note) ? $line->note : '');
50 50
 
51 51
 	if ($issupplierline) $prodser = new ProductFournisseur($db);
52 52
 	else $prodser = new Product($db);
@@ -55,57 +55,57 @@  discard block
 block discarded – undo
55 55
 	{
56 56
 		$prodser->fetch($idprod);
57 57
 		// If a predefined product and multilang and on other lang, we renamed label with label translated
58
-		if (! empty($conf->global->MAIN_MULTILANGS) && ($outputlangs->defaultlang != $langs->defaultlang))
58
+		if (!empty($conf->global->MAIN_MULTILANGS) && ($outputlangs->defaultlang != $langs->defaultlang))
59 59
 		{
60
-			if (! empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && $label == $prodser->label)     $label=$prodser->multilangs[$outputlangs->defaultlang]["label"];
61
-			if (! empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && $desc == $prodser->description) $desc=$prodser->multilangs[$outputlangs->defaultlang]["description"];
62
-			if (! empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && $note == $prodser->note)        $note=$prodser->multilangs[$outputlangs->defaultlang]["note"];
60
+			if (!empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && $label == $prodser->label)     $label = $prodser->multilangs[$outputlangs->defaultlang]["label"];
61
+			if (!empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && $desc == $prodser->description) $desc = $prodser->multilangs[$outputlangs->defaultlang]["description"];
62
+			if (!empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && $note == $prodser->note)        $note = $prodser->multilangs[$outputlangs->defaultlang]["note"];
63 63
 		}
64 64
 	}
65 65
 
66 66
 	// Description short of product line
67
-	$libelleproduitservice=$label;
67
+	$libelleproduitservice = $label;
68 68
 
69 69
 	// Description long of product line
70 70
 	if ($desc && ($desc != $label))
71 71
 	{
72 72
 		if ($desc == '(CREDIT_NOTE)' && $line->fk_remise_except)
73 73
 		{
74
-			$discount=new DiscountAbsolute($db);
74
+			$discount = new DiscountAbsolute($db);
75 75
 			$discount->fetch($line->fk_remise_except);
76
-			$sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
77
-			$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$sourceref);
76
+			$sourceref = !empty($discount->discount_type) ? $discount->ref_invoive_supplier_source : $discount->ref_facture_source;
77
+			$libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromCreditNote", $sourceref);
78 78
 		}
79 79
 		elseif ($desc == '(DEPOSIT)' && $line->fk_remise_except)
80 80
 		{
81
-		    $discount=new DiscountAbsolute($db);
81
+		    $discount = new DiscountAbsolute($db);
82 82
 		    $discount->fetch($line->fk_remise_except);
83
-		    $sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
84
-		    $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$sourceref);
83
+		    $sourceref = !empty($discount->discount_type) ? $discount->ref_invoive_supplier_source : $discount->ref_facture_source;
84
+		    $libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromDeposit", $sourceref);
85 85
 		    // Add date of deposit
86
-		    if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) $libelleproduitservice.=' ('.dol_print_date($discount->datec,'day','',$outputlangs).')';
86
+		    if (!empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) $libelleproduitservice .= ' ('.dol_print_date($discount->datec, 'day', '', $outputlangs).')';
87 87
 		}
88 88
 		elseif ($desc == '(EXCESS RECEIVED)' && $line->fk_remise_except)
89 89
 		{
90
-			$discount=new DiscountAbsolute($db);
90
+			$discount = new DiscountAbsolute($db);
91 91
 			$discount->fetch($line->fk_remise_except);
92
-			$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived",$discount->ref_facture_source);
92
+			$libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived", $discount->ref_facture_source);
93 93
 		}
94 94
 		elseif ($desc == '(EXCESS PAID)' && $line->fk_remise_except)
95 95
 		{
96
-			$discount=new DiscountAbsolute($db);
96
+			$discount = new DiscountAbsolute($db);
97 97
 			$discount->fetch($line->fk_remise_except);
98
-			$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessPaid",$discount->ref_invoice_supplier_source);
98
+			$libelleproduitservice = $outputlangs->transnoentitiesnoconv("DiscountFromExcessPaid", $discount->ref_invoice_supplier_source);
99 99
 		}
100 100
 		else
101 101
 		{
102 102
 			if ($idprod)
103 103
 			{
104
-				if (empty($hidedesc)) $libelleproduitservice=dol_concatdesc($libelleproduitservice, $desc);
104
+				if (empty($hidedesc)) $libelleproduitservice = dol_concatdesc($libelleproduitservice, $desc);
105 105
 			}
106 106
 			else
107 107
 			{
108
-				$libelleproduitservice=dol_concatdesc($libelleproduitservice, $desc);
108
+				$libelleproduitservice = dol_concatdesc($libelleproduitservice, $desc);
109 109
 			}
110 110
 		}
111 111
 	}
@@ -118,7 +118,7 @@  discard block
 block discarded – undo
118 118
 		{
119 119
 			$prefix_prodserv = "";
120 120
 			$ref_prodserv = "";
121
-			if (! empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS))   // In standard mode, we do not show this
121
+			if (!empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS))   // In standard mode, we do not show this
122 122
 			{
123 123
 				if ($prodser->isService())
124 124
 				{
@@ -132,34 +132,34 @@  discard block
 block discarded – undo
132 132
 
133 133
 			if (empty($hideref))
134 134
 			{
135
-				if ($issupplierline) $ref_prodserv = $prodser->ref.' ('.$outputlangs->trans("SupplierRef").' '.$ref_supplier.')';   // Show local ref and supplier ref
135
+				if ($issupplierline) $ref_prodserv = $prodser->ref.' ('.$outputlangs->trans("SupplierRef").' '.$ref_supplier.')'; // Show local ref and supplier ref
136 136
 				else $ref_prodserv = $prodser->ref; // Show local ref only
137 137
 
138 138
 				$ref_prodserv .= " - ";
139 139
 			}
140 140
 
141
-			$libelleproduitservice=$prefix_prodserv.$ref_prodserv.$libelleproduitservice;
141
+			$libelleproduitservice = $prefix_prodserv.$ref_prodserv.$libelleproduitservice;
142 142
 		}
143 143
 	}
144 144
 
145
-	if (! empty($line->date_start) || ! empty($line->date_end))
145
+	if (!empty($line->date_start) || !empty($line->date_end))
146 146
 	{
147
-		$format='day';
147
+		$format = 'day';
148 148
 		// Show duration if exists
149 149
 		if ($line->date_start && $line->date_end)
150 150
 		{
151
-			$period='('.$outputlangs->transnoentitiesnoconv('DateFromTo',dol_print_date($line->date_start, $format, false, $outputlangs),dol_print_date($line->date_end, $format, false, $outputlangs)).')';
151
+			$period = '('.$outputlangs->transnoentitiesnoconv('DateFromTo', dol_print_date($line->date_start, $format, false, $outputlangs), dol_print_date($line->date_end, $format, false, $outputlangs)).')';
152 152
 		}
153
-		if ($line->date_start && ! $line->date_end)
153
+		if ($line->date_start && !$line->date_end)
154 154
 		{
155
-			$period='('.$outputlangs->transnoentitiesnoconv('DateFrom',dol_print_date($line->date_start, $format, false, $outputlangs)).')';
155
+			$period = '('.$outputlangs->transnoentitiesnoconv('DateFrom', dol_print_date($line->date_start, $format, false, $outputlangs)).')';
156 156
 		}
157
-		if (! $line->date_start && $line->date_end)
157
+		if (!$line->date_start && $line->date_end)
158 158
 		{
159
-			$period='('.$outputlangs->transnoentitiesnoconv('DateUntil',dol_print_date($line->date_end, $format, false, $outputlangs)).')';
159
+			$period = '('.$outputlangs->transnoentitiesnoconv('DateUntil', dol_print_date($line->date_end, $format, false, $outputlangs)).')';
160 160
 		}
161 161
 		//print '>'.$outputlangs->charset_output.','.$period;
162
-		$libelleproduitservice=dol_concatdesc($libelleproduitservice, $period);
162
+		$libelleproduitservice = dol_concatdesc($libelleproduitservice, $period);
163 163
 		//print $libelleproduitservice;
164 164
 	}
165 165
 
Please login to merge, or discard this patch.
Braces   +37 added lines, -22 removed lines patch added patch discarded remove patch
@@ -48,8 +48,11 @@  discard block
 block discarded – undo
48 48
 	$ref_supplier=(! empty($line->ref_supplier)?$line->ref_supplier:(! empty($line->ref_fourn)?$line->ref_fourn:''));    // TODO Not yet saved for supplier invoices, only supplier orders
49 49
 	$note=(! empty($line->note)?$line->note:'');
50 50
 
51
-	if ($issupplierline) $prodser = new ProductFournisseur($db);
52
-	else $prodser = new Product($db);
51
+	if ($issupplierline) {
52
+	    $prodser = new ProductFournisseur($db);
53
+	} else {
54
+	    $prodser = new Product($db);
55
+	}
53 56
 
54 57
 	if ($idprod)
55 58
 	{
@@ -57,9 +60,15 @@  discard block
 block discarded – undo
57 60
 		// If a predefined product and multilang and on other lang, we renamed label with label translated
58 61
 		if (! empty($conf->global->MAIN_MULTILANGS) && ($outputlangs->defaultlang != $langs->defaultlang))
59 62
 		{
60
-			if (! empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && $label == $prodser->label)     $label=$prodser->multilangs[$outputlangs->defaultlang]["label"];
61
-			if (! empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && $desc == $prodser->description) $desc=$prodser->multilangs[$outputlangs->defaultlang]["description"];
62
-			if (! empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && $note == $prodser->note)        $note=$prodser->multilangs[$outputlangs->defaultlang]["note"];
63
+			if (! empty($prodser->multilangs[$outputlangs->defaultlang]["label"]) && $label == $prodser->label) {
64
+			    $label=$prodser->multilangs[$outputlangs->defaultlang]["label"];
65
+			}
66
+			if (! empty($prodser->multilangs[$outputlangs->defaultlang]["description"]) && $desc == $prodser->description) {
67
+			    $desc=$prodser->multilangs[$outputlangs->defaultlang]["description"];
68
+			}
69
+			if (! empty($prodser->multilangs[$outputlangs->defaultlang]["note"]) && $note == $prodser->note) {
70
+			    $note=$prodser->multilangs[$outputlangs->defaultlang]["note"];
71
+			}
63 72
 		}
64 73
 	}
65 74
 
@@ -75,35 +84,34 @@  discard block
 block discarded – undo
75 84
 			$discount->fetch($line->fk_remise_except);
76 85
 			$sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
77 86
 			$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromCreditNote",$sourceref);
78
-		}
79
-		elseif ($desc == '(DEPOSIT)' && $line->fk_remise_except)
87
+		} elseif ($desc == '(DEPOSIT)' && $line->fk_remise_except)
80 88
 		{
81 89
 		    $discount=new DiscountAbsolute($db);
82 90
 		    $discount->fetch($line->fk_remise_except);
83 91
 		    $sourceref=!empty($discount->discount_type)?$discount->ref_invoive_supplier_source:$discount->ref_facture_source;
84 92
 		    $libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromDeposit",$sourceref);
85 93
 		    // Add date of deposit
86
-		    if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) $libelleproduitservice.=' ('.dol_print_date($discount->datec,'day','',$outputlangs).')';
87
-		}
88
-		elseif ($desc == '(EXCESS RECEIVED)' && $line->fk_remise_except)
94
+		    if (! empty($conf->global->INVOICE_ADD_DEPOSIT_DATE)) {
95
+		        $libelleproduitservice.=' ('.dol_print_date($discount->datec,'day','',$outputlangs).')';
96
+		    }
97
+		} elseif ($desc == '(EXCESS RECEIVED)' && $line->fk_remise_except)
89 98
 		{
90 99
 			$discount=new DiscountAbsolute($db);
91 100
 			$discount->fetch($line->fk_remise_except);
92 101
 			$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessReceived",$discount->ref_facture_source);
93
-		}
94
-		elseif ($desc == '(EXCESS PAID)' && $line->fk_remise_except)
102
+		} elseif ($desc == '(EXCESS PAID)' && $line->fk_remise_except)
95 103
 		{
96 104
 			$discount=new DiscountAbsolute($db);
97 105
 			$discount->fetch($line->fk_remise_except);
98 106
 			$libelleproduitservice=$outputlangs->transnoentitiesnoconv("DiscountFromExcessPaid",$discount->ref_invoice_supplier_source);
99
-		}
100
-		else
107
+		} else
101 108
 		{
102 109
 			if ($idprod)
103 110
 			{
104
-				if (empty($hidedesc)) $libelleproduitservice=dol_concatdesc($libelleproduitservice, $desc);
105
-			}
106
-			else
111
+				if (empty($hidedesc)) {
112
+				    $libelleproduitservice=dol_concatdesc($libelleproduitservice, $desc);
113
+				}
114
+			} else
107 115
 			{
108 116
 				$libelleproduitservice=dol_concatdesc($libelleproduitservice, $desc);
109 117
 			}
@@ -118,13 +126,14 @@  discard block
 block discarded – undo
118 126
 		{
119 127
 			$prefix_prodserv = "";
120 128
 			$ref_prodserv = "";
121
-			if (! empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS))   // In standard mode, we do not show this
129
+			if (! empty($conf->global->PRODUCT_ADD_TYPE_IN_DOCUMENTS)) {
130
+			    // In standard mode, we do not show this
122 131
 			{
123 132
 				if ($prodser->isService())
124 133
 				{
125 134
 					$prefix_prodserv = $outputlangs->transnoentitiesnoconv("Service")." ";
126
-				}
127
-				else
135
+			}
136
+				} else
128 137
 				{
129 138
 					$prefix_prodserv = $outputlangs->transnoentitiesnoconv("Product")." ";
130 139
 				}
@@ -132,8 +141,14 @@  discard block
 block discarded – undo
132 141
 
133 142
 			if (empty($hideref))
134 143
 			{
135
-				if ($issupplierline) $ref_prodserv = $prodser->ref.' ('.$outputlangs->trans("SupplierRef").' '.$ref_supplier.')';   // Show local ref and supplier ref
136
-				else $ref_prodserv = $prodser->ref; // Show local ref only
144
+				if ($issupplierline) {
145
+				    $ref_prodserv = $prodser->ref.' ('.$outputlangs->trans("SupplierRef").' '.$ref_supplier.')';
146
+				}
147
+				// Show local ref and supplier ref
148
+				else {
149
+				    $ref_prodserv = $prodser->ref;
150
+				}
151
+				// Show local ref only
137 152
 
138 153
 				$ref_prodserv .= " - ";
139 154
 			}
Please login to merge, or discard this patch.
dolibarr/htdocs/core/lib/tax.lib.php 3 patches
Indentation   +549 added lines, -549 removed lines patch added patch discarded remove patch
@@ -41,10 +41,10 @@  discard block
 block discarded – undo
41 41
     $h = 0;
42 42
     $head = array();
43 43
 
44
-	$head[$h][0] = DOL_URL_ROOT.'/compta/sociales/card.php?id='.$object->id;
45
-	$head[$h][1] = $langs->trans('Card');
46
-	$head[$h][2] = 'card';
47
-	$h++;
44
+    $head[$h][0] = DOL_URL_ROOT.'/compta/sociales/card.php?id='.$object->id;
45
+    $head[$h][1] = $langs->trans('Card');
46
+    $head[$h][2] = 'card';
47
+    $h++;
48 48
 
49 49
     // Show more tabs from modules
50 50
     // Entries must be declared in modules descriptor with line
@@ -52,16 +52,16 @@  discard block
 block discarded – undo
52 52
     // $this->tabs = array('entity:-tabname);   												to remove a tab
53 53
     complete_head_from_modules($conf,$langs,$object,$head,$h,'tax');
54 54
 
55
-	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
55
+    require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
56 56
     require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
57
-	$upload_dir = $conf->tax->dir_output . "/" . dol_sanitizeFileName($object->ref);
58
-	$nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$'));
57
+    $upload_dir = $conf->tax->dir_output . "/" . dol_sanitizeFileName($object->ref);
58
+    $nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$'));
59 59
     $nbLinks=Link::count($db, $object->element, $object->id);
60
-	$head[$h][0] = DOL_URL_ROOT.'/compta/sociales/document.php?id='.$object->id;
61
-	$head[$h][1] = $langs->trans("Documents");
62
-	if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
63
-	$head[$h][2] = 'documents';
64
-	$h++;
60
+    $head[$h][0] = DOL_URL_ROOT.'/compta/sociales/document.php?id='.$object->id;
61
+    $head[$h][1] = $langs->trans("Documents");
62
+    if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
63
+    $head[$h][2] = 'documents';
64
+    $h++;
65 65
 
66 66
     $head[$h][0] = DOL_URL_ROOT.'/compta/sociales/info.php?id='.$object->id;
67 67
     $head[$h][1] = $langs->trans("Info");
@@ -95,39 +95,39 @@  discard block
 block discarded – undo
95 95
     // If we use date_start and date_end, we must not use $y, $m, $q
96 96
     if (($date_start || $date_end) && (! empty($y) || ! empty($m) || ! empty($q)))
97 97
     {
98
-    	dol_print_error('', 'Bad value of input parameter for tax_by_rate');
98
+        dol_print_error('', 'Bad value of input parameter for tax_by_rate');
99 99
     }
100 100
 
101 101
     $list=array();
102 102
     if ($direction == 'sell')
103 103
     {
104
-    	$invoicetable='facture';
105
-    	$invoicedettable='facturedet';
106
-    	$fk_facture='fk_facture';
107
-    	$fk_facture2='fk_facture';
108
-    	$fk_payment='fk_paiement';
109
-    	$total_tva='total_tva';
110
-    	$paymenttable='paiement';
111
-    	$paymentfacturetable='paiement_facture';
112
-    	$invoicefieldref='ref';
104
+        $invoicetable='facture';
105
+        $invoicedettable='facturedet';
106
+        $fk_facture='fk_facture';
107
+        $fk_facture2='fk_facture';
108
+        $fk_payment='fk_paiement';
109
+        $total_tva='total_tva';
110
+        $paymenttable='paiement';
111
+        $paymentfacturetable='paiement_facture';
112
+        $invoicefieldref='ref';
113 113
     }
114 114
     if ($direction == 'buy')
115 115
     {
116
-    	$invoicetable='facture_fourn';
117
-    	$invoicedettable='facture_fourn_det';
118
-    	$fk_facture='fk_facture_fourn';
119
-    	$fk_facture2='fk_facturefourn';
120
-    	$fk_payment='fk_paiementfourn';
121
-    	$total_tva='tva';
122
-    	$paymenttable='paiementfourn';
123
-    	$paymentfacturetable='paiementfourn_facturefourn';
124
-    	$invoicefieldref='ref';
116
+        $invoicetable='facture_fourn';
117
+        $invoicedettable='facture_fourn_det';
118
+        $fk_facture='fk_facture_fourn';
119
+        $fk_facture2='fk_facturefourn';
120
+        $fk_payment='fk_paiementfourn';
121
+        $total_tva='tva';
122
+        $paymenttable='paiementfourn';
123
+        $paymentfacturetable='paiementfourn_facturefourn';
124
+        $invoicefieldref='ref';
125 125
     }
126 126
 
127 127
     if ( strpos( $type, 'localtax' ) === 0 ) {
128
-    	$f_rate = $type . '_tx';
128
+        $f_rate = $type . '_tx';
129 129
     } else {
130
-    	$f_rate = 'tva_tx';
130
+        $f_rate = 'tva_tx';
131 131
     }
132 132
 
133 133
     $total_localtax1='total_localtax1';
@@ -139,146 +139,146 @@  discard block
 block discarded – undo
139 139
     // Define sql request
140 140
     $sql='';
141 141
     if (($direction == 'sell' && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
142
-    	|| ($direction == 'buy' && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice'))
142
+        || ($direction == 'buy' && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice'))
143 143
     {
144
-    	// Count on delivery date (use invoice date as delivery is unknown)
145
-    	$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
146
-    	$sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
147
-    	$sql.= " d.date_start as date_start, d.date_end as date_end,";
148
-    	$sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
149
-    	$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
150
-    	$sql.= " 0 as payment_id, 0 as payment_amount";
151
-    	$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
152
-    	$sql.= " ".MAIN_DB_PREFIX."societe as s,";
153
-    	$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
154
-    	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
155
-    	$sql.= " WHERE f.entity = " . $conf->entity;
156
-    	$sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely)
157
-    	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
158
-    	else $sql.= " AND f.type IN (0,1,2,3,5)";
159
-    	$sql.= " AND f.rowid = d.".$fk_facture;
160
-    	$sql.= " AND s.rowid = f.fk_soc";
161
-    	if ($y && $m)
162
-    	{
163
-    		$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
164
-    		$sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
165
-    	}
166
-    	else if ($y)
167
-    	{
168
-    		$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,1,false))."'";
169
-    		$sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,12,false))."'";
170
-    	}
171
-    	if ($q) $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
172
-    	if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
173
-    	$sql.= " AND (d.product_type = 0";                              // Limit to products
174
-    	$sql.= " AND d.date_start is null AND d.date_end IS NULL)";     // enhance detection of products
175
-    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
176
-    	$sql.= " ORDER BY d.rowid, d.".$fk_facture;
144
+        // Count on delivery date (use invoice date as delivery is unknown)
145
+        $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
146
+        $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
147
+        $sql.= " d.date_start as date_start, d.date_end as date_end,";
148
+        $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
149
+        $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
150
+        $sql.= " 0 as payment_id, 0 as payment_amount";
151
+        $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
152
+        $sql.= " ".MAIN_DB_PREFIX."societe as s,";
153
+        $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
154
+        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
155
+        $sql.= " WHERE f.entity = " . $conf->entity;
156
+        $sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely)
157
+        if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
158
+        else $sql.= " AND f.type IN (0,1,2,3,5)";
159
+        $sql.= " AND f.rowid = d.".$fk_facture;
160
+        $sql.= " AND s.rowid = f.fk_soc";
161
+        if ($y && $m)
162
+        {
163
+            $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
164
+            $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
165
+        }
166
+        else if ($y)
167
+        {
168
+            $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,1,false))."'";
169
+            $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,12,false))."'";
170
+        }
171
+        if ($q) $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
172
+        if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
173
+        $sql.= " AND (d.product_type = 0";                              // Limit to products
174
+        $sql.= " AND d.date_start is null AND d.date_end IS NULL)";     // enhance detection of products
175
+        if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
176
+        $sql.= " ORDER BY d.rowid, d.".$fk_facture;
177 177
     }
178 178
     else
179 179
     {
180
-    	// Count on payments date
181
-    	$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
182
-    	$sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
183
-    	$sql.= " d.date_start as date_start, d.date_end as date_end,";
184
-    	$sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
185
-    	$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
186
-    	$sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,";
187
-    	$sql.= " pa.datep as datep";
188
-    	$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
189
-    	$sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
190
-    	$sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
191
-    	$sql.= " ".MAIN_DB_PREFIX."societe as s,";
192
-    	$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
193
-    	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
194
-    	$sql.= " WHERE f.entity = " . $conf->entity;
195
-    	$sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
196
-    	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
197
-    	else $sql.= " AND f.type IN (0,1,2,3,5)";
198
-    	$sql.= " AND f.rowid = d.".$fk_facture;
199
-    	$sql.= " AND s.rowid = f.fk_soc";
200
-    	$sql.= " AND pf.".$fk_facture2." = f.rowid";
201
-    	$sql.= " AND pa.rowid = pf.".$fk_payment;
202
-    	if ($y && $m)
203
-    	{
204
-    		$sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
205
-    		$sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
206
-    	}
207
-    	else if ($y)
208
-    	{
209
-    		$sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
210
-    		$sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
211
-    	}
212
-    	if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
213
-    	if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
214
-    	$sql.= " AND (d.product_type = 0";                              // Limit to products
215
-    	$sql.= " AND d.date_start is null AND d.date_end IS NULL)";     // enhance detection of products
216
-    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
217
-    	$sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
180
+        // Count on payments date
181
+        $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
182
+        $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
183
+        $sql.= " d.date_start as date_start, d.date_end as date_end,";
184
+        $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
185
+        $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
186
+        $sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,";
187
+        $sql.= " pa.datep as datep";
188
+        $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
189
+        $sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
190
+        $sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
191
+        $sql.= " ".MAIN_DB_PREFIX."societe as s,";
192
+        $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
193
+        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
194
+        $sql.= " WHERE f.entity = " . $conf->entity;
195
+        $sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
196
+        if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
197
+        else $sql.= " AND f.type IN (0,1,2,3,5)";
198
+        $sql.= " AND f.rowid = d.".$fk_facture;
199
+        $sql.= " AND s.rowid = f.fk_soc";
200
+        $sql.= " AND pf.".$fk_facture2." = f.rowid";
201
+        $sql.= " AND pa.rowid = pf.".$fk_payment;
202
+        if ($y && $m)
203
+        {
204
+            $sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
205
+            $sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
206
+        }
207
+        else if ($y)
208
+        {
209
+            $sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
210
+            $sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
211
+        }
212
+        if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
213
+        if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
214
+        $sql.= " AND (d.product_type = 0";                              // Limit to products
215
+        $sql.= " AND d.date_start is null AND d.date_end IS NULL)";     // enhance detection of products
216
+        if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
217
+        $sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
218 218
     }
219 219
 
220 220
     if (! $sql) return -1;
221 221
     if ($sql == 'TODO') return -2;
222 222
     if ($sql != 'TODO')
223 223
     {
224
-    	dol_syslog("Tax.lib.php::tax_by_thirdparty", LOG_DEBUG);
225
-
226
-    	$resql = $db->query($sql);
227
-    	if ($resql)
228
-    	{
229
-    		$company_id = -1;
230
-    		$oldrowid='';
231
-    		while($assoc = $db->fetch_array($resql))
232
-    		{
233
-    			if (! isset($list[$assoc['company_id']]['totalht']))  $list[$assoc['company_id']]['totalht']=0;
234
-    			if (! isset($list[$assoc['company_id']]['vat']))      $list[$assoc['company_id']]['vat']=0;
235
-    			if (! isset($list[$assoc['company_id']]['localtax1']))      $list[$assoc['company_id']]['localtax1']=0;
236
-    			if (! isset($list[$assoc['company_id']]['localtax2']))      $list[$assoc['company_id']]['localtax2']=0;
237
-
238
-    			if ($assoc['rowid'] != $oldrowid)       // Si rupture sur d.rowid
239
-    			{
240
-    				$oldrowid=$assoc['rowid'];
241
-    				$list[$assoc['company_id']]['totalht']  += $assoc['total_ht'];
242
-    				$list[$assoc['company_id']]['vat']      += $assoc['total_vat'];
243
-    				$list[$assoc['company_id']]['localtax1']      += $assoc['total_localtax1'];
244
-    				$list[$assoc['company_id']]['localtax2']      += $assoc['total_localtax2'];
245
-    			}
246
-    			$list[$assoc['company_id']]['dtotal_ttc'][] = $assoc['total_ttc'];
247
-    			$list[$assoc['company_id']]['dtype'][] = $assoc['dtype'];
248
-    			$list[$assoc['company_id']]['datef'][] = $db->jdate($assoc['datef']);
249
-    			$list[$assoc['company_id']]['datep'][] = $db->jdate($assoc['datep']);
250
-    			$list[$assoc['company_id']]['company_name'][] = $assoc['company_name'];
251
-    			$list[$assoc['company_id']]['company_id'][] = $assoc['company_id'];
252
-    			$list[$assoc['company_id']]['drate'][] = $assoc['rate'];
253
-    			$list[$assoc['company_id']]['ddate_start'][] = $db->jdate($assoc['date_start']);
254
-    			$list[$assoc['company_id']]['ddate_end'][] = $db->jdate($assoc['date_end']);
255
-
256
-    			$list[$assoc['company_id']]['facid'][] = $assoc['facid'];
257
-    			$list[$assoc['company_id']]['facnum'][] = $assoc['facnum'];
258
-    			$list[$assoc['company_id']]['type'][] = $assoc['type'];
259
-    			$list[$assoc['company_id']]['ftotal_ttc'][] = $assoc['ftotal_ttc'];
260
-    			$list[$assoc['company_id']]['descr'][] = $assoc['descr'];
261
-
262
-    			$list[$assoc['company_id']]['totalht_list'][] = $assoc['total_ht'];
263
-    			$list[$assoc['company_id']]['vat_list'][] = $assoc['total_vat'];
264
-    			$list[$assoc['company_id']]['localtax1_list'][] = $assoc['total_localtax1'];
265
-    			$list[$assoc['company_id']]['localtax2_list'][]  = $assoc['total_localtax2'];
266
-
267
-    			$list[$assoc['company_id']]['pid'][] = $assoc['pid'];
268
-    			$list[$assoc['company_id']]['pref'][] = $assoc['pref'];
269
-    			$list[$assoc['company_id']]['ptype'][] = $assoc['ptype'];
270
-
271
-    			$list[$assoc['company_id']]['payment_id'][] = $assoc['payment_id'];
272
-    			$list[$assoc['company_id']]['payment_amount'][] = $assoc['payment_amount'];
273
-
274
-    			$company_id = $assoc['company_id'];
275
-    		}
276
-    	}
277
-    	else
278
-    	{
279
-    		dol_print_error($db);
280
-    		return -3;
281
-    	}
224
+        dol_syslog("Tax.lib.php::tax_by_thirdparty", LOG_DEBUG);
225
+
226
+        $resql = $db->query($sql);
227
+        if ($resql)
228
+        {
229
+            $company_id = -1;
230
+            $oldrowid='';
231
+            while($assoc = $db->fetch_array($resql))
232
+            {
233
+                if (! isset($list[$assoc['company_id']]['totalht']))  $list[$assoc['company_id']]['totalht']=0;
234
+                if (! isset($list[$assoc['company_id']]['vat']))      $list[$assoc['company_id']]['vat']=0;
235
+                if (! isset($list[$assoc['company_id']]['localtax1']))      $list[$assoc['company_id']]['localtax1']=0;
236
+                if (! isset($list[$assoc['company_id']]['localtax2']))      $list[$assoc['company_id']]['localtax2']=0;
237
+
238
+                if ($assoc['rowid'] != $oldrowid)       // Si rupture sur d.rowid
239
+                {
240
+                    $oldrowid=$assoc['rowid'];
241
+                    $list[$assoc['company_id']]['totalht']  += $assoc['total_ht'];
242
+                    $list[$assoc['company_id']]['vat']      += $assoc['total_vat'];
243
+                    $list[$assoc['company_id']]['localtax1']      += $assoc['total_localtax1'];
244
+                    $list[$assoc['company_id']]['localtax2']      += $assoc['total_localtax2'];
245
+                }
246
+                $list[$assoc['company_id']]['dtotal_ttc'][] = $assoc['total_ttc'];
247
+                $list[$assoc['company_id']]['dtype'][] = $assoc['dtype'];
248
+                $list[$assoc['company_id']]['datef'][] = $db->jdate($assoc['datef']);
249
+                $list[$assoc['company_id']]['datep'][] = $db->jdate($assoc['datep']);
250
+                $list[$assoc['company_id']]['company_name'][] = $assoc['company_name'];
251
+                $list[$assoc['company_id']]['company_id'][] = $assoc['company_id'];
252
+                $list[$assoc['company_id']]['drate'][] = $assoc['rate'];
253
+                $list[$assoc['company_id']]['ddate_start'][] = $db->jdate($assoc['date_start']);
254
+                $list[$assoc['company_id']]['ddate_end'][] = $db->jdate($assoc['date_end']);
255
+
256
+                $list[$assoc['company_id']]['facid'][] = $assoc['facid'];
257
+                $list[$assoc['company_id']]['facnum'][] = $assoc['facnum'];
258
+                $list[$assoc['company_id']]['type'][] = $assoc['type'];
259
+                $list[$assoc['company_id']]['ftotal_ttc'][] = $assoc['ftotal_ttc'];
260
+                $list[$assoc['company_id']]['descr'][] = $assoc['descr'];
261
+
262
+                $list[$assoc['company_id']]['totalht_list'][] = $assoc['total_ht'];
263
+                $list[$assoc['company_id']]['vat_list'][] = $assoc['total_vat'];
264
+                $list[$assoc['company_id']]['localtax1_list'][] = $assoc['total_localtax1'];
265
+                $list[$assoc['company_id']]['localtax2_list'][]  = $assoc['total_localtax2'];
266
+
267
+                $list[$assoc['company_id']]['pid'][] = $assoc['pid'];
268
+                $list[$assoc['company_id']]['pref'][] = $assoc['pref'];
269
+                $list[$assoc['company_id']]['ptype'][] = $assoc['ptype'];
270
+
271
+                $list[$assoc['company_id']]['payment_id'][] = $assoc['payment_id'];
272
+                $list[$assoc['company_id']]['payment_amount'][] = $assoc['payment_amount'];
273
+
274
+                $company_id = $assoc['company_id'];
275
+            }
276
+        }
277
+        else
278
+        {
279
+            dol_print_error($db);
280
+            return -3;
281
+        }
282 282
     }
283 283
 
284 284
 
@@ -287,149 +287,149 @@  discard block
 block discarded – undo
287 287
     // Define sql request
288 288
     $sql='';
289 289
     if (($direction == 'sell' && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')
290
-    	|| ($direction == 'buy' && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice'))
290
+        || ($direction == 'buy' && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice'))
291 291
     {
292
-    	// Count on invoice date
293
-    	$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
294
-    	$sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
295
-    	$sql.= " d.date_start as date_start, d.date_end as date_end,";
296
-    	$sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
297
-    	$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
298
-    	$sql.= " 0 as payment_id, 0 as payment_amount";
299
-    	$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
300
-    	$sql.= " ".MAIN_DB_PREFIX."societe as s,";
301
-    	$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
302
-    	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
303
-    	$sql.= " WHERE f.entity = " . $conf->entity;
304
-    	$sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely)
305
-    	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
306
-    	else $sql.= " AND f.type IN (0,1,2,3,5)";
307
-    	$sql.= " AND f.rowid = d.".$fk_facture;
308
-    	$sql.= " AND s.rowid = f.fk_soc";
309
-    	if ($y && $m)
310
-    	{
311
-    		$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
312
-    		$sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
313
-    	}
314
-    	else if ($y)
315
-    	{
316
-    		$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,1,false))."'";
317
-    		$sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,12,false))."'";
318
-    	}
319
-    	if ($q) $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
320
-    	if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
321
-    	$sql.= " AND (d.product_type = 1";                              // Limit to services
322
-    	$sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)";       // enhance detection of service
323
-    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
324
-    	$sql.= " ORDER BY d.rowid, d.".$fk_facture;
292
+        // Count on invoice date
293
+        $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
294
+        $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
295
+        $sql.= " d.date_start as date_start, d.date_end as date_end,";
296
+        $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
297
+        $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
298
+        $sql.= " 0 as payment_id, 0 as payment_amount";
299
+        $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
300
+        $sql.= " ".MAIN_DB_PREFIX."societe as s,";
301
+        $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
302
+        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
303
+        $sql.= " WHERE f.entity = " . $conf->entity;
304
+        $sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely)
305
+        if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
306
+        else $sql.= " AND f.type IN (0,1,2,3,5)";
307
+        $sql.= " AND f.rowid = d.".$fk_facture;
308
+        $sql.= " AND s.rowid = f.fk_soc";
309
+        if ($y && $m)
310
+        {
311
+            $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
312
+            $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
313
+        }
314
+        else if ($y)
315
+        {
316
+            $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,1,false))."'";
317
+            $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,12,false))."'";
318
+        }
319
+        if ($q) $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
320
+        if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
321
+        $sql.= " AND (d.product_type = 1";                              // Limit to services
322
+        $sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)";       // enhance detection of service
323
+        if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
324
+        $sql.= " ORDER BY d.rowid, d.".$fk_facture;
325 325
     }
326 326
     else
327 327
     {
328
-    	// Count on payments date
329
-    	$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
330
-    	$sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
331
-    	$sql.= " d.date_start as date_start, d.date_end as date_end,";
332
-    	$sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
333
-    	$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
334
-    	$sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,";
335
-    	$sql.= " pa.datep as datep";
336
-    	$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
337
-    	$sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
338
-    	$sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
339
-    	$sql.= " ".MAIN_DB_PREFIX."societe as s,";
340
-    	$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
341
-    	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
342
-    	$sql.= " WHERE f.entity = " . $conf->entity;
343
-    	$sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
344
-    	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
345
-    	else $sql.= " AND f.type IN (0,1,2,3,5)";
346
-    	$sql.= " AND f.rowid = d.".$fk_facture;
347
-    	$sql.= " AND s.rowid = f.fk_soc";
348
-    	$sql.= " AND pf.".$fk_facture2." = f.rowid";
349
-    	$sql.= " AND pa.rowid = pf.".$fk_payment;
350
-    	if ($y && $m)
351
-    	{
352
-    		$sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
353
-    		$sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
354
-    	}
355
-    	else if ($y)
356
-    	{
357
-    		$sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
358
-    		$sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
359
-    	}
360
-    	if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
361
-    	if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
362
-    	$sql.= " AND (d.product_type = 1";                              		// Limit to services
363
-    	$sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)";       // enhance detection of service
364
-    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
365
-    	$sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
328
+        // Count on payments date
329
+        $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
330
+        $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
331
+        $sql.= " d.date_start as date_start, d.date_end as date_end,";
332
+        $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
333
+        $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
334
+        $sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,";
335
+        $sql.= " pa.datep as datep";
336
+        $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
337
+        $sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
338
+        $sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
339
+        $sql.= " ".MAIN_DB_PREFIX."societe as s,";
340
+        $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
341
+        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
342
+        $sql.= " WHERE f.entity = " . $conf->entity;
343
+        $sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
344
+        if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
345
+        else $sql.= " AND f.type IN (0,1,2,3,5)";
346
+        $sql.= " AND f.rowid = d.".$fk_facture;
347
+        $sql.= " AND s.rowid = f.fk_soc";
348
+        $sql.= " AND pf.".$fk_facture2." = f.rowid";
349
+        $sql.= " AND pa.rowid = pf.".$fk_payment;
350
+        if ($y && $m)
351
+        {
352
+            $sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
353
+            $sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
354
+        }
355
+        else if ($y)
356
+        {
357
+            $sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
358
+            $sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
359
+        }
360
+        if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
361
+        if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
362
+        $sql.= " AND (d.product_type = 1";                              		// Limit to services
363
+        $sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)";       // enhance detection of service
364
+        if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
365
+        $sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
366 366
     }
367 367
 
368 368
     if (! $sql)
369 369
     {
370
-    	dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR);
371
-    	return -1;  // -1 = Not accountancy module enabled
370
+        dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR);
371
+        return -1;  // -1 = Not accountancy module enabled
372 372
     }
373 373
     if ($sql == 'TODO') return -2; // -2 = Feature not yet available
374 374
     if ($sql != 'TODO')
375 375
     {
376
-    	dol_syslog("Tax.lib.php::tax_by_rate", LOG_DEBUG);
377
-    	$resql = $db->query($sql);
378
-    	if ($resql)
379
-    	{
380
-    		$company_id = -1;
381
-    		$oldrowid='';
382
-    		while($assoc = $db->fetch_array($resql))
383
-    		{
384
-    			if (! isset($list[$assoc['company_id']]['totalht']))  $list[$assoc['company_id']]['totalht']=0;
385
-    			if (! isset($list[$assoc['company_id']]['vat']))      $list[$assoc['company_id']]['vat']=0;
386
-    			if (! isset($list[$assoc['company_id']]['localtax1']))      $list[$assoc['company_id']]['localtax1']=0;
387
-    			if (! isset($list[$assoc['company_id']]['localtax2']))      $list[$assoc['company_id']]['localtax2']=0;
388
-
389
-    			if ($assoc['rowid'] != $oldrowid)       // Si rupture sur d.rowid
390
-    			{
391
-    				$oldrowid=$assoc['rowid'];
392
-    				$list[$assoc['company_id']]['totalht']  += $assoc['total_ht'];
393
-    				$list[$assoc['company_id']]['vat']      += $assoc['total_vat'];
394
-    				$list[$assoc['company_id']]['localtax1']	 += $assoc['total_localtax1'];
395
-    				$list[$assoc['company_id']]['localtax2']	 += $assoc['total_localtax2'];
396
-    			}
397
-    			$list[$assoc['company_id']]['dtotal_ttc'][] = $assoc['total_ttc'];
398
-    			$list[$assoc['company_id']]['dtype'][] = $assoc['dtype'];
399
-    			$list[$assoc['company_id']]['datef'][] = $db->jdate($assoc['datef']);
400
-    			$list[$assoc['company_id']]['datep'][] = $db->jdate($assoc['datep']);
401
-    			$list[$assoc['company_id']]['company_name'][] = $assoc['company_name'];
402
-    			$list[$assoc['company_id']]['company_id'][] = $assoc['company_id'];
403
-    			$list[$assoc['company_id']]['drate'][] = $assoc['rate'];
404
-    			$list[$assoc['company_id']]['ddate_start'][] = $db->jdate($assoc['date_start']);
405
-    			$list[$assoc['company_id']]['ddate_end'][] = $db->jdate($assoc['date_end']);
406
-
407
-    			$list[$assoc['company_id']]['facid'][] = $assoc['facid'];
408
-    			$list[$assoc['company_id']]['facnum'][] = $assoc['facnum'];
409
-    			$list[$assoc['company_id']]['type'][] = $assoc['type'];
410
-    			$list[$assoc['company_id']]['ftotal_ttc'][] = $assoc['ftotal_ttc'];
411
-    			$list[$assoc['company_id']]['descr'][] = $assoc['descr'];
412
-
413
-    			$list[$assoc['company_id']]['totalht_list'][] = $assoc['total_ht'];
414
-    			$list[$assoc['company_id']]['vat_list'][] = $assoc['total_vat'];
415
-    			$list[$assoc['company_id']]['localtax1_list'][] = $assoc['total_localtax1'];
416
-    			$list[$assoc['company_id']]['localtax2_list'][] = $assoc['total_localtax2'];
417
-
418
-    			$list[$assoc['company_id']]['pid'][] = $assoc['pid'];
419
-    			$list[$assoc['company_id']]['pref'][] = $assoc['pref'];
420
-    			$list[$assoc['company_id']]['ptype'][] = $assoc['ptype'];
421
-
422
-    			$list[$assoc['company_id']]['payment_id'][] = $assoc['payment_id'];
423
-    			$list[$assoc['company_id']]['payment_amount'][] = $assoc['payment_amount'];
424
-
425
-    			$company_id = $assoc['company_id'];
426
-    		}
427
-    	}
428
-    	else
429
-    	{
430
-    		dol_print_error($db);
431
-    		return -3;
432
-    	}
376
+        dol_syslog("Tax.lib.php::tax_by_rate", LOG_DEBUG);
377
+        $resql = $db->query($sql);
378
+        if ($resql)
379
+        {
380
+            $company_id = -1;
381
+            $oldrowid='';
382
+            while($assoc = $db->fetch_array($resql))
383
+            {
384
+                if (! isset($list[$assoc['company_id']]['totalht']))  $list[$assoc['company_id']]['totalht']=0;
385
+                if (! isset($list[$assoc['company_id']]['vat']))      $list[$assoc['company_id']]['vat']=0;
386
+                if (! isset($list[$assoc['company_id']]['localtax1']))      $list[$assoc['company_id']]['localtax1']=0;
387
+                if (! isset($list[$assoc['company_id']]['localtax2']))      $list[$assoc['company_id']]['localtax2']=0;
388
+
389
+                if ($assoc['rowid'] != $oldrowid)       // Si rupture sur d.rowid
390
+                {
391
+                    $oldrowid=$assoc['rowid'];
392
+                    $list[$assoc['company_id']]['totalht']  += $assoc['total_ht'];
393
+                    $list[$assoc['company_id']]['vat']      += $assoc['total_vat'];
394
+                    $list[$assoc['company_id']]['localtax1']	 += $assoc['total_localtax1'];
395
+                    $list[$assoc['company_id']]['localtax2']	 += $assoc['total_localtax2'];
396
+                }
397
+                $list[$assoc['company_id']]['dtotal_ttc'][] = $assoc['total_ttc'];
398
+                $list[$assoc['company_id']]['dtype'][] = $assoc['dtype'];
399
+                $list[$assoc['company_id']]['datef'][] = $db->jdate($assoc['datef']);
400
+                $list[$assoc['company_id']]['datep'][] = $db->jdate($assoc['datep']);
401
+                $list[$assoc['company_id']]['company_name'][] = $assoc['company_name'];
402
+                $list[$assoc['company_id']]['company_id'][] = $assoc['company_id'];
403
+                $list[$assoc['company_id']]['drate'][] = $assoc['rate'];
404
+                $list[$assoc['company_id']]['ddate_start'][] = $db->jdate($assoc['date_start']);
405
+                $list[$assoc['company_id']]['ddate_end'][] = $db->jdate($assoc['date_end']);
406
+
407
+                $list[$assoc['company_id']]['facid'][] = $assoc['facid'];
408
+                $list[$assoc['company_id']]['facnum'][] = $assoc['facnum'];
409
+                $list[$assoc['company_id']]['type'][] = $assoc['type'];
410
+                $list[$assoc['company_id']]['ftotal_ttc'][] = $assoc['ftotal_ttc'];
411
+                $list[$assoc['company_id']]['descr'][] = $assoc['descr'];
412
+
413
+                $list[$assoc['company_id']]['totalht_list'][] = $assoc['total_ht'];
414
+                $list[$assoc['company_id']]['vat_list'][] = $assoc['total_vat'];
415
+                $list[$assoc['company_id']]['localtax1_list'][] = $assoc['total_localtax1'];
416
+                $list[$assoc['company_id']]['localtax2_list'][] = $assoc['total_localtax2'];
417
+
418
+                $list[$assoc['company_id']]['pid'][] = $assoc['pid'];
419
+                $list[$assoc['company_id']]['pref'][] = $assoc['pref'];
420
+                $list[$assoc['company_id']]['ptype'][] = $assoc['ptype'];
421
+
422
+                $list[$assoc['company_id']]['payment_id'][] = $assoc['payment_id'];
423
+                $list[$assoc['company_id']]['payment_amount'][] = $assoc['payment_amount'];
424
+
425
+                $company_id = $assoc['company_id'];
426
+            }
427
+        }
428
+        else
429
+        {
430
+            dol_print_error($db);
431
+            return -3;
432
+        }
433 433
     }
434 434
 
435 435
 
@@ -437,104 +437,104 @@  discard block
 block discarded – undo
437 437
 
438 438
     if ($direction == 'buy')		// buy only for expense reports
439 439
     {
440
-    	// Define sql request
441
-    	$sql='';
442
-
443
-    	// Count on payments date
444
-    	$sql = "SELECT d.rowid, d.product_type as dtype, e.rowid as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.total_tva as total_vat, e.note_private as descr,";
445
-    	$sql .=" d.total_localtax1 as total_localtax1, d.total_localtax2 as total_localtax2, ";
446
-    	$sql.= " e.date_debut as date_start, e.date_fin as date_end, e.fk_user_author,";
447
-    	$sql.= " e.ref as facnum, e.total_ttc as ftotal_ttc, e.date_create, d.fk_c_type_fees as type,";
448
-    	$sql.= " p.fk_bank as payment_id, p.amount as payment_amount, p.rowid as pid, e.ref as pref";
449
-    	$sql.= " FROM ".MAIN_DB_PREFIX."expensereport as e";
450
-    	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport_det as d ON d.fk_expensereport = e.rowid ";
451
-    	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."payment_expensereport as p ON p.fk_expensereport = e.rowid ";
452
-    	$sql.= " WHERE e.entity = " . $conf->entity;
453
-    	$sql.= " AND e.fk_statut in (6)";
454
-    	if ($y && $m)
455
-    	{
456
-    		$sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
457
-    		$sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
458
-    	}
459
-    	else if ($y)
460
-    	{
461
-    		$sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
462
-    		$sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
463
-    	}
464
-    	if ($q) $sql.= " AND (date_format(p.datep,'%m') > ".(($q-1)*3)." AND date_format(p.datep,'%m') <= ".($q*3).")";
465
-    	if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
466
-    	$sql.= " AND (d.product_type = -1";
467
-    	$sql.= " OR e.date_debut is NOT null OR e.date_fin IS NOT NULL)";       // enhance detection of service
468
-    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.total_tva <> 0)";
469
-    	$sql.= " ORDER BY e.rowid";
470
-
471
-    	if (! $sql)
472
-    	{
473
-    		dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR);
474
-    		return -1;  // -1 = Not accountancy module enabled
475
-    	}
476
-    	if ($sql == 'TODO') return -2; // -2 = Feature not yet available
477
-    	if ($sql != 'TODO')
478
-    	{
479
-    		dol_syslog("Tax.lib.php::tax_by_rate", LOG_DEBUG);
480
-    		$resql = $db->query($sql);
481
-    		if ($resql)
482
-    		{
483
-    			$company_id = -1;
484
-    			$oldrowid='';
485
-    			while($assoc = $db->fetch_array($resql))
486
-    			{
487
-    				if (! isset($list[$assoc['company_id']]['totalht']))  $list[$assoc['company_id']]['totalht']=0;
488
-    				if (! isset($list[$assoc['company_id']]['vat']))      $list[$assoc['company_id']]['vat']=0;
489
-    				if (! isset($list[$assoc['company_id']]['localtax1']))      $list[$assoc['company_id']]['localtax1']=0;
490
-    				if (! isset($list[$assoc['company_id']]['localtax2']))      $list[$assoc['company_id']]['localtax2']=0;
491
-
492
-    				if ($assoc['rowid'] != $oldrowid)       // Si rupture sur d.rowid
493
-    				{
494
-    					$oldrowid=$assoc['rowid'];
495
-    					$list[$assoc['company_id']]['totalht']  += $assoc['total_ht'];
496
-    					$list[$assoc['company_id']]['vat'] += $assoc['total_vat'];
497
-    					$list[$assoc['company_id']]['localtax1']	 += $assoc['total_localtax1'];
498
-    					$list[$assoc['company_id']]['localtax2']	 += $assoc['total_localtax2'];
499
-    				}
500
-
501
-    				$list[$assoc['company_id']]['dtotal_ttc'][] = $assoc['total_ttc'];
502
-    				$list[$assoc['company_id']]['dtype'][] = 'ExpenseReportPayment';
503
-    				$list[$assoc['company_id']]['datef'][] = $assoc['datef'];
504
-    				$list[$assoc['company_id']]['company_name'][] = '';
505
-    				$list[$assoc['company_id']]['company_id'][] = '';
506
-    				$list[$assoc['company_id']]['user_id'][] = $assoc['fk_user_author'];
507
-    				$list[$assoc['company_id']]['drate'][] = $assoc['rate'];
508
-    				$list[$assoc['company_id']]['ddate_start'][] = $db->jdate($assoc['date_start']);
509
-    				$list[$assoc['company_id']]['ddate_end'][] = $db->jdate($assoc['date_end']);
510
-
511
-    				$list[$assoc['company_id']]['facid'][] = $assoc['facid'];
512
-    				$list[$assoc['company_id']]['facnum'][] = $assoc['facnum'];
513
-    				$list[$assoc['company_id']]['type'][] = $assoc['type'];
514
-    				$list[$assoc['company_id']]['ftotal_ttc'][] = $assoc['ftotal_ttc'];
515
-    				$list[$assoc['company_id']]['descr'][] = $assoc['descr'];
516
-
517
-    				$list[$assoc['company_id']]['totalht_list'][] = $assoc['total_ht'];
518
-    				$list[$assoc['company_id']]['vat_list'][] = $assoc['total_vat'];
519
-    				$list[$assoc['company_id']]['localtax1_list'][] = $assoc['total_localtax1'];
520
-    				$list[$assoc['company_id']]['localtax2_list'][] = $assoc['total_localtax2'];
521
-
522
-    				$list[$assoc['company_id']]['pid'][] = $assoc['pid'];
523
-    				$list[$assoc['company_id']]['pref'][] = $assoc['pref'];
524
-    				$list[$assoc['company_id']]['ptype'][] = 'ExpenseReportPayment';
525
-
526
-    				$list[$assoc['company_id']]['payment_id'][] = $assoc['payment_id'];
527
-    				$list[$assoc['company_id']]['payment_amount'][] = $assoc['payment_amount'];
528
-
529
-    				$company_id = $assoc['company_id'];
530
-    			}
531
-    		}
532
-    		else
533
-    		{
534
-    			dol_print_error($db);
535
-    			return -3;
536
-    		}
537
-    	}
440
+        // Define sql request
441
+        $sql='';
442
+
443
+        // Count on payments date
444
+        $sql = "SELECT d.rowid, d.product_type as dtype, e.rowid as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.total_tva as total_vat, e.note_private as descr,";
445
+        $sql .=" d.total_localtax1 as total_localtax1, d.total_localtax2 as total_localtax2, ";
446
+        $sql.= " e.date_debut as date_start, e.date_fin as date_end, e.fk_user_author,";
447
+        $sql.= " e.ref as facnum, e.total_ttc as ftotal_ttc, e.date_create, d.fk_c_type_fees as type,";
448
+        $sql.= " p.fk_bank as payment_id, p.amount as payment_amount, p.rowid as pid, e.ref as pref";
449
+        $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as e";
450
+        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport_det as d ON d.fk_expensereport = e.rowid ";
451
+        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."payment_expensereport as p ON p.fk_expensereport = e.rowid ";
452
+        $sql.= " WHERE e.entity = " . $conf->entity;
453
+        $sql.= " AND e.fk_statut in (6)";
454
+        if ($y && $m)
455
+        {
456
+            $sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
457
+            $sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
458
+        }
459
+        else if ($y)
460
+        {
461
+            $sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
462
+            $sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
463
+        }
464
+        if ($q) $sql.= " AND (date_format(p.datep,'%m') > ".(($q-1)*3)." AND date_format(p.datep,'%m') <= ".($q*3).")";
465
+        if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
466
+        $sql.= " AND (d.product_type = -1";
467
+        $sql.= " OR e.date_debut is NOT null OR e.date_fin IS NOT NULL)";       // enhance detection of service
468
+        if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.total_tva <> 0)";
469
+        $sql.= " ORDER BY e.rowid";
470
+
471
+        if (! $sql)
472
+        {
473
+            dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR);
474
+            return -1;  // -1 = Not accountancy module enabled
475
+        }
476
+        if ($sql == 'TODO') return -2; // -2 = Feature not yet available
477
+        if ($sql != 'TODO')
478
+        {
479
+            dol_syslog("Tax.lib.php::tax_by_rate", LOG_DEBUG);
480
+            $resql = $db->query($sql);
481
+            if ($resql)
482
+            {
483
+                $company_id = -1;
484
+                $oldrowid='';
485
+                while($assoc = $db->fetch_array($resql))
486
+                {
487
+                    if (! isset($list[$assoc['company_id']]['totalht']))  $list[$assoc['company_id']]['totalht']=0;
488
+                    if (! isset($list[$assoc['company_id']]['vat']))      $list[$assoc['company_id']]['vat']=0;
489
+                    if (! isset($list[$assoc['company_id']]['localtax1']))      $list[$assoc['company_id']]['localtax1']=0;
490
+                    if (! isset($list[$assoc['company_id']]['localtax2']))      $list[$assoc['company_id']]['localtax2']=0;
491
+
492
+                    if ($assoc['rowid'] != $oldrowid)       // Si rupture sur d.rowid
493
+                    {
494
+                        $oldrowid=$assoc['rowid'];
495
+                        $list[$assoc['company_id']]['totalht']  += $assoc['total_ht'];
496
+                        $list[$assoc['company_id']]['vat'] += $assoc['total_vat'];
497
+                        $list[$assoc['company_id']]['localtax1']	 += $assoc['total_localtax1'];
498
+                        $list[$assoc['company_id']]['localtax2']	 += $assoc['total_localtax2'];
499
+                    }
500
+
501
+                    $list[$assoc['company_id']]['dtotal_ttc'][] = $assoc['total_ttc'];
502
+                    $list[$assoc['company_id']]['dtype'][] = 'ExpenseReportPayment';
503
+                    $list[$assoc['company_id']]['datef'][] = $assoc['datef'];
504
+                    $list[$assoc['company_id']]['company_name'][] = '';
505
+                    $list[$assoc['company_id']]['company_id'][] = '';
506
+                    $list[$assoc['company_id']]['user_id'][] = $assoc['fk_user_author'];
507
+                    $list[$assoc['company_id']]['drate'][] = $assoc['rate'];
508
+                    $list[$assoc['company_id']]['ddate_start'][] = $db->jdate($assoc['date_start']);
509
+                    $list[$assoc['company_id']]['ddate_end'][] = $db->jdate($assoc['date_end']);
510
+
511
+                    $list[$assoc['company_id']]['facid'][] = $assoc['facid'];
512
+                    $list[$assoc['company_id']]['facnum'][] = $assoc['facnum'];
513
+                    $list[$assoc['company_id']]['type'][] = $assoc['type'];
514
+                    $list[$assoc['company_id']]['ftotal_ttc'][] = $assoc['ftotal_ttc'];
515
+                    $list[$assoc['company_id']]['descr'][] = $assoc['descr'];
516
+
517
+                    $list[$assoc['company_id']]['totalht_list'][] = $assoc['total_ht'];
518
+                    $list[$assoc['company_id']]['vat_list'][] = $assoc['total_vat'];
519
+                    $list[$assoc['company_id']]['localtax1_list'][] = $assoc['total_localtax1'];
520
+                    $list[$assoc['company_id']]['localtax2_list'][] = $assoc['total_localtax2'];
521
+
522
+                    $list[$assoc['company_id']]['pid'][] = $assoc['pid'];
523
+                    $list[$assoc['company_id']]['pref'][] = $assoc['pref'];
524
+                    $list[$assoc['company_id']]['ptype'][] = 'ExpenseReportPayment';
525
+
526
+                    $list[$assoc['company_id']]['payment_id'][] = $assoc['payment_id'];
527
+                    $list[$assoc['company_id']]['payment_amount'][] = $assoc['payment_amount'];
528
+
529
+                    $company_id = $assoc['company_id'];
530
+                }
531
+            }
532
+            else
533
+            {
534
+                dol_print_error($db);
535
+                return -3;
536
+            }
537
+        }
538 538
     }
539 539
 
540 540
     return $list;
@@ -563,7 +563,7 @@  discard block
 block discarded – undo
563 563
     // If we use date_start and date_end, we must not use $y, $m, $q
564 564
     if (($date_start || $date_end) && (! empty($y) || ! empty($m) || ! empty($q)))
565 565
     {
566
-    	dol_print_error('', 'Bad value of input parameter for tax_by_rate');
566
+        dol_print_error('', 'Bad value of input parameter for tax_by_rate');
567 567
     }
568 568
 
569 569
     $list=array();
@@ -593,14 +593,14 @@  discard block
 block discarded – undo
593 593
         $invoicefieldref='ref';
594 594
     }
595 595
 
596
-	if ( strpos( $type, 'localtax' ) === 0 ) {
597
-		$f_rate = $type . '_tx';
598
-	} else {
599
-		$f_rate = 'tva_tx';
600
-	}
596
+    if ( strpos( $type, 'localtax' ) === 0 ) {
597
+        $f_rate = $type . '_tx';
598
+    } else {
599
+        $f_rate = 'tva_tx';
600
+    }
601 601
 
602
-	$total_localtax1='total_localtax1';
603
-	$total_localtax2='total_localtax2';
602
+    $total_localtax1='total_localtax1';
603
+    $total_localtax2='total_localtax2';
604 604
 
605 605
 
606 606
     // CAS DES BIENS/PRODUITS
@@ -608,7 +608,7 @@  discard block
 block discarded – undo
608 608
     // Define sql request
609 609
     $sql='';
610 610
     if (($direction == 'sell' && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
611
-    	|| ($direction == 'buy' && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice'))
611
+        || ($direction == 'buy' && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice'))
612 612
     {
613 613
         // Count on delivery date (use invoice date as delivery is unknown)
614 614
         $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
@@ -646,44 +646,44 @@  discard block
 block discarded – undo
646 646
     }
647 647
     else
648 648
     {
649
-    	// Count on payments date
650
-    	$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
651
-    	$sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
652
-    	$sql.= " d.date_start as date_start, d.date_end as date_end,";
653
-    	$sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
654
-    	$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
655
-    	$sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,";
656
-    	$sql.= " pa.datep as datep";
657
-    	$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
658
-    	$sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
659
-    	$sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
660
-    	$sql.= " ".MAIN_DB_PREFIX."societe as s,";
661
-    	$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
662
-    	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
663
-    	$sql.= " WHERE f.entity = " . $conf->entity;
664
-    	$sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
665
-    	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
666
-    	else $sql.= " AND f.type IN (0,1,2,3,5)";
667
-    	$sql.= " AND f.rowid = d.".$fk_facture;
668
-    	$sql.= " AND s.rowid = f.fk_soc";
669
-    	$sql.= " AND pf.".$fk_facture2." = f.rowid";
670
-    	$sql.= " AND pa.rowid = pf.".$fk_payment;
671
-    	if ($y && $m)
672
-    	{
673
-    		$sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
674
-    		$sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
675
-    	}
676
-    	else if ($y)
677
-    	{
678
-    		$sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
679
-    		$sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
680
-    	}
681
-    	if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
682
-    	if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
683
-    	$sql.= " AND (d.product_type = 0";                              // Limit to products
684
-    	$sql.= " AND d.date_start is null AND d.date_end IS NULL)";     // enhance detection of products
685
-    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
686
-    	$sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
649
+        // Count on payments date
650
+        $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
651
+        $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
652
+        $sql.= " d.date_start as date_start, d.date_end as date_end,";
653
+        $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
654
+        $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
655
+        $sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,";
656
+        $sql.= " pa.datep as datep";
657
+        $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
658
+        $sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
659
+        $sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
660
+        $sql.= " ".MAIN_DB_PREFIX."societe as s,";
661
+        $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
662
+        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
663
+        $sql.= " WHERE f.entity = " . $conf->entity;
664
+        $sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
665
+        if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
666
+        else $sql.= " AND f.type IN (0,1,2,3,5)";
667
+        $sql.= " AND f.rowid = d.".$fk_facture;
668
+        $sql.= " AND s.rowid = f.fk_soc";
669
+        $sql.= " AND pf.".$fk_facture2." = f.rowid";
670
+        $sql.= " AND pa.rowid = pf.".$fk_payment;
671
+        if ($y && $m)
672
+        {
673
+            $sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
674
+            $sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
675
+        }
676
+        else if ($y)
677
+        {
678
+            $sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
679
+            $sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
680
+        }
681
+        if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
682
+        if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
683
+        $sql.= " AND (d.product_type = 0";                              // Limit to products
684
+        $sql.= " AND d.date_start is null AND d.date_end IS NULL)";     // enhance detection of products
685
+        if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
686
+        $sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
687 687
     }
688 688
 
689 689
     if (! $sql) return -1;
@@ -699,8 +699,8 @@  discard block
 block discarded – undo
699 699
             $oldrowid='';
700 700
             while($assoc = $db->fetch_array($resql))
701 701
             {
702
-            	// Code to avoid warnings when array entry not defined
703
-            	if (! isset($list[$assoc['rate']]['totalht']))   $list[$assoc['rate']]['totalht']=0;
702
+                // Code to avoid warnings when array entry not defined
703
+                if (! isset($list[$assoc['rate']]['totalht']))   $list[$assoc['rate']]['totalht']=0;
704 704
                 if (! isset($list[$assoc['rate']]['vat']))       $list[$assoc['rate']]['vat']=0;
705 705
                 if (! isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0;
706 706
                 if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=0;
@@ -756,7 +756,7 @@  discard block
 block discarded – undo
756 756
     // Define sql request
757 757
     $sql='';
758 758
     if (($direction == 'sell' && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')
759
-    	|| ($direction == 'buy' && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice'))
759
+        || ($direction == 'buy' && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice'))
760 760
     {
761 761
         // Count on invoice date
762 762
         $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
@@ -772,7 +772,7 @@  discard block
 block discarded – undo
772 772
         $sql.= " WHERE f.entity = " . $conf->entity;
773 773
         $sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely)
774 774
         if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
775
-		else $sql.= " AND f.type IN (0,1,2,3,5)";
775
+        else $sql.= " AND f.type IN (0,1,2,3,5)";
776 776
         $sql.= " AND f.rowid = d.".$fk_facture;
777 777
         $sql.= " AND s.rowid = f.fk_soc";
778 778
         if ($y && $m)
@@ -811,7 +811,7 @@  discard block
 block discarded – undo
811 811
         $sql.= " WHERE f.entity = " . $conf->entity;
812 812
         $sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
813 813
         if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
814
-		else $sql.= " AND f.type IN (0,1,2,3,5)";
814
+        else $sql.= " AND f.type IN (0,1,2,3,5)";
815 815
         $sql.= " AND f.rowid = d.".$fk_facture;
816 816
         $sql.= " AND s.rowid = f.fk_soc";
817 817
         $sql.= " AND pf.".$fk_facture2." = f.rowid";
@@ -850,10 +850,10 @@  discard block
 block discarded – undo
850 850
             $oldrowid='';
851 851
             while($assoc = $db->fetch_array($resql))
852 852
             {
853
-            	// Code to avoid warnings when array entry not defined
854
-            	if (! isset($list[$assoc['rate']]['totalht']))   $list[$assoc['rate']]['totalht']=0;
853
+                // Code to avoid warnings when array entry not defined
854
+                if (! isset($list[$assoc['rate']]['totalht']))   $list[$assoc['rate']]['totalht']=0;
855 855
                 if (! isset($list[$assoc['rate']]['vat']))       $list[$assoc['rate']]['vat']=0;
856
-				if (! isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0;
856
+                if (! isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0;
857 857
                 if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=0;
858 858
 
859 859
                 if ($assoc['rowid'] != $oldrowid)       // Si rupture sur d.rowid
@@ -904,108 +904,108 @@  discard block
 block discarded – undo
904 904
 
905 905
     // CASE OF EXPENSE REPORT
906 906
 
907
-	if ($direction == 'buy')		// buy only for expense reports
908
-	{
909
-		// Define sql request
910
-		$sql='';
911
-
912
-		// Count on payments date
913
-		$sql = "SELECT d.rowid, d.product_type as dtype, e.rowid as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.total_tva as total_vat, e.note_private as descr,";
914
-		$sql .=" d.total_localtax1 as total_localtax1, d.total_localtax2 as total_localtax2, ";
915
-		$sql.= " e.date_debut as date_start, e.date_fin as date_end, e.fk_user_author,";
916
-		$sql.= " e.ref as facnum, e.total_ttc as ftotal_ttc, e.date_create, d.fk_c_type_fees as type,";
917
-		$sql.= " p.fk_bank as payment_id, p.amount as payment_amount, p.rowid as pid, e.ref as pref";
918
-		$sql.= " FROM ".MAIN_DB_PREFIX."expensereport as e ";
919
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport_det as d ON d.fk_expensereport = e.rowid ";
920
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."payment_expensereport as p ON p.fk_expensereport = e.rowid ";
921
-		$sql.= " WHERE e.entity = " . $conf->entity;
922
-		$sql.= " AND e.fk_statut in (6)";
923
-		if ($y && $m)
924
-		{
925
-			$sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
926
-			$sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
927
-		}
928
-		else if ($y)
929
-		{
930
-			$sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
931
-			$sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
932
-		}
933
-		if ($q) $sql.= " AND (date_format(p.datep,'%m') > ".(($q-1)*3)." AND date_format(p.datep,'%m') <= ".($q*3).")";
934
-		if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
935
-		$sql.= " AND (d.product_type = -1";
936
-		$sql.= " OR e.date_debut is NOT null OR e.date_fin IS NOT NULL)";       // enhance detection of service
937
-		if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.total_tva <> 0)";
938
-		$sql.= " ORDER BY e.rowid";
939
-
940
-		if (! $sql)
941
-		{
942
-			dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR);
943
-			return -1;  // -1 = Not accountancy module enabled
944
-		}
945
-		if ($sql == 'TODO') return -2; // -2 = Feature not yet available
946
-		if ($sql != 'TODO')
947
-		{
948
-			dol_syslog("Tax.lib.php::tax_by_rate", LOG_DEBUG);
949
-			$resql = $db->query($sql);
950
-			if ($resql)
951
-			{
952
-				$rate = -1;
953
-				$oldrowid='';
954
-				while($assoc = $db->fetch_array($resql))
955
-				{
956
-					// Code to avoid warnings when array entry not defined
957
-					if (! isset($list[$assoc['rate']]['totalht']))   $list[$assoc['rate']]['totalht']=0;
958
-					if (! isset($list[$assoc['rate']]['vat']))       $list[$assoc['rate']]['vat']=0;
959
-					if (! isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0;
960
-					if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=0;
961
-
962
-					if ($assoc['rowid'] != $oldrowid)       // Si rupture sur d.rowid
963
-					{
964
-						$oldrowid=$assoc['rowid'];
965
-						$list[$assoc['rate']]['totalht']   += $assoc['total_ht'];
907
+    if ($direction == 'buy')		// buy only for expense reports
908
+    {
909
+        // Define sql request
910
+        $sql='';
911
+
912
+        // Count on payments date
913
+        $sql = "SELECT d.rowid, d.product_type as dtype, e.rowid as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.total_tva as total_vat, e.note_private as descr,";
914
+        $sql .=" d.total_localtax1 as total_localtax1, d.total_localtax2 as total_localtax2, ";
915
+        $sql.= " e.date_debut as date_start, e.date_fin as date_end, e.fk_user_author,";
916
+        $sql.= " e.ref as facnum, e.total_ttc as ftotal_ttc, e.date_create, d.fk_c_type_fees as type,";
917
+        $sql.= " p.fk_bank as payment_id, p.amount as payment_amount, p.rowid as pid, e.ref as pref";
918
+        $sql.= " FROM ".MAIN_DB_PREFIX."expensereport as e ";
919
+        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport_det as d ON d.fk_expensereport = e.rowid ";
920
+        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."payment_expensereport as p ON p.fk_expensereport = e.rowid ";
921
+        $sql.= " WHERE e.entity = " . $conf->entity;
922
+        $sql.= " AND e.fk_statut in (6)";
923
+        if ($y && $m)
924
+        {
925
+            $sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
926
+            $sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
927
+        }
928
+        else if ($y)
929
+        {
930
+            $sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
931
+            $sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
932
+        }
933
+        if ($q) $sql.= " AND (date_format(p.datep,'%m') > ".(($q-1)*3)." AND date_format(p.datep,'%m') <= ".($q*3).")";
934
+        if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
935
+        $sql.= " AND (d.product_type = -1";
936
+        $sql.= " OR e.date_debut is NOT null OR e.date_fin IS NOT NULL)";       // enhance detection of service
937
+        if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.total_tva <> 0)";
938
+        $sql.= " ORDER BY e.rowid";
939
+
940
+        if (! $sql)
941
+        {
942
+            dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR);
943
+            return -1;  // -1 = Not accountancy module enabled
944
+        }
945
+        if ($sql == 'TODO') return -2; // -2 = Feature not yet available
946
+        if ($sql != 'TODO')
947
+        {
948
+            dol_syslog("Tax.lib.php::tax_by_rate", LOG_DEBUG);
949
+            $resql = $db->query($sql);
950
+            if ($resql)
951
+            {
952
+                $rate = -1;
953
+                $oldrowid='';
954
+                while($assoc = $db->fetch_array($resql))
955
+                {
956
+                    // Code to avoid warnings when array entry not defined
957
+                    if (! isset($list[$assoc['rate']]['totalht']))   $list[$assoc['rate']]['totalht']=0;
958
+                    if (! isset($list[$assoc['rate']]['vat']))       $list[$assoc['rate']]['vat']=0;
959
+                    if (! isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0;
960
+                    if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=0;
961
+
962
+                    if ($assoc['rowid'] != $oldrowid)       // Si rupture sur d.rowid
963
+                    {
964
+                        $oldrowid=$assoc['rowid'];
965
+                        $list[$assoc['rate']]['totalht']   += $assoc['total_ht'];
966 966
                         $list[$assoc['rate']]['vat']       += $assoc['total_vat'];
967
-						$list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1'];
968
-						$list[$assoc['rate']]['localtax2'] += $assoc['total_localtax2'];
969
-					}
970
-
971
-					$list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc'];
972
-					$list[$assoc['rate']]['dtype'][] = 'ExpenseReportPayment';
973
-					$list[$assoc['rate']]['datef'][] = $assoc['datef'];
974
-					$list[$assoc['rate']]['company_name'][] = '';
975
-					$list[$assoc['rate']]['company_id'][] = '';
976
-					$list[$assoc['rate']]['user_id'][] = $assoc['fk_user_author'];
977
-					$list[$assoc['rate']]['ddate_start'][] = $db->jdate($assoc['date_start']);
978
-					$list[$assoc['rate']]['ddate_end'][] = $db->jdate($assoc['date_end']);
979
-
980
-					$list[$assoc['rate']]['facid'][] = $assoc['facid'];
981
-					$list[$assoc['rate']]['facnum'][] = $assoc['facnum'];
982
-					$list[$assoc['rate']]['type'][] = $assoc['type'];
983
-					$list[$assoc['rate']]['ftotal_ttc'][] = $assoc['ftotal_ttc'];
984
-					$list[$assoc['rate']]['descr'][] = $assoc['descr'];
985
-
986
-					$list[$assoc['rate']]['totalht_list'][] = $assoc['total_ht'];
987
-					$list[$assoc['rate']]['vat_list'][] = $assoc['total_vat'];
988
-					$list[$assoc['rate']]['localtax1_list'][] = $assoc['total_localtax1'];
989
-					$list[$assoc['rate']]['localtax2_list'][] = $assoc['total_localtax2'];
990
-
991
-					$list[$assoc['rate']]['pid'][] = $assoc['pid'];
992
-					$list[$assoc['rate']]['pref'][] = $assoc['pref'];
993
-					$list[$assoc['rate']]['ptype'][] = 'ExpenseReportPayment';
994
-
995
-					$list[$assoc['rate']]['payment_id'][] = $assoc['payment_id'];
996
-					$list[$assoc['rate']]['payment_amount'][] = $assoc['payment_amount'];
997
-
998
-					$rate = $assoc['rate'];
999
-				}
1000
-			}
1001
-			else
1002
-			{
1003
-				dol_print_error($db);
1004
-				return -3;
1005
-			}
1006
-		}
1007
-	}
1008
-
1009
-	return $list;
967
+                        $list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1'];
968
+                        $list[$assoc['rate']]['localtax2'] += $assoc['total_localtax2'];
969
+                    }
970
+
971
+                    $list[$assoc['rate']]['dtotal_ttc'][] = $assoc['total_ttc'];
972
+                    $list[$assoc['rate']]['dtype'][] = 'ExpenseReportPayment';
973
+                    $list[$assoc['rate']]['datef'][] = $assoc['datef'];
974
+                    $list[$assoc['rate']]['company_name'][] = '';
975
+                    $list[$assoc['rate']]['company_id'][] = '';
976
+                    $list[$assoc['rate']]['user_id'][] = $assoc['fk_user_author'];
977
+                    $list[$assoc['rate']]['ddate_start'][] = $db->jdate($assoc['date_start']);
978
+                    $list[$assoc['rate']]['ddate_end'][] = $db->jdate($assoc['date_end']);
979
+
980
+                    $list[$assoc['rate']]['facid'][] = $assoc['facid'];
981
+                    $list[$assoc['rate']]['facnum'][] = $assoc['facnum'];
982
+                    $list[$assoc['rate']]['type'][] = $assoc['type'];
983
+                    $list[$assoc['rate']]['ftotal_ttc'][] = $assoc['ftotal_ttc'];
984
+                    $list[$assoc['rate']]['descr'][] = $assoc['descr'];
985
+
986
+                    $list[$assoc['rate']]['totalht_list'][] = $assoc['total_ht'];
987
+                    $list[$assoc['rate']]['vat_list'][] = $assoc['total_vat'];
988
+                    $list[$assoc['rate']]['localtax1_list'][] = $assoc['total_localtax1'];
989
+                    $list[$assoc['rate']]['localtax2_list'][] = $assoc['total_localtax2'];
990
+
991
+                    $list[$assoc['rate']]['pid'][] = $assoc['pid'];
992
+                    $list[$assoc['rate']]['pref'][] = $assoc['pref'];
993
+                    $list[$assoc['rate']]['ptype'][] = 'ExpenseReportPayment';
994
+
995
+                    $list[$assoc['rate']]['payment_id'][] = $assoc['payment_id'];
996
+                    $list[$assoc['rate']]['payment_amount'][] = $assoc['payment_amount'];
997
+
998
+                    $rate = $assoc['rate'];
999
+                }
1000
+            }
1001
+            else
1002
+            {
1003
+                dol_print_error($db);
1004
+                return -3;
1005
+            }
1006
+        }
1007
+    }
1008
+
1009
+    return $list;
1010 1010
 }
1011 1011
 
Please login to merge, or discard this patch.
Spacing   +381 added lines, -381 removed lines patch added patch discarded remove patch
@@ -50,16 +50,16 @@  discard block
 block discarded – undo
50 50
     // Entries must be declared in modules descriptor with line
51 51
     // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
52 52
     // $this->tabs = array('entity:-tabname);   												to remove a tab
53
-    complete_head_from_modules($conf,$langs,$object,$head,$h,'tax');
53
+    complete_head_from_modules($conf, $langs, $object, $head, $h, 'tax');
54 54
 
55 55
 	require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
56 56
     require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
57
-	$upload_dir = $conf->tax->dir_output . "/" . dol_sanitizeFileName($object->ref);
58
-	$nbFiles = count(dol_dir_list($upload_dir,'files',0,'','(\.meta|_preview.*\.png)$'));
59
-    $nbLinks=Link::count($db, $object->element, $object->id);
57
+	$upload_dir = $conf->tax->dir_output."/".dol_sanitizeFileName($object->ref);
58
+	$nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
59
+    $nbLinks = Link::count($db, $object->element, $object->id);
60 60
 	$head[$h][0] = DOL_URL_ROOT.'/compta/sociales/document.php?id='.$object->id;
61 61
 	$head[$h][1] = $langs->trans("Documents");
62
-	if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
62
+	if (($nbFiles + $nbLinks) > 0) $head[$h][1] .= ' <span class="badge">'.($nbFiles + $nbLinks).'</span>';
63 63
 	$head[$h][2] = 'documents';
64 64
 	$h++;
65 65
 
@@ -68,7 +68,7 @@  discard block
 block discarded – undo
68 68
     $head[$h][2] = 'info';
69 69
     $h++;
70 70
 
71
-    complete_head_from_modules($conf,$langs,$object,$head,$h,'tax','remove');
71
+    complete_head_from_modules($conf, $langs, $object, $head, $h, 'tax', 'remove');
72 72
 
73 73
     return $head;
74 74
 }
@@ -88,136 +88,136 @@  discard block
 block discarded – undo
88 88
  *  @param  int		$q           	Quarter
89 89
  *  @return array       			Array with details of VATs (per third parties), -1 if no accountancy module, -2 if not yet developped, -3 if error
90 90
  */
91
-function tax_by_thirdparty($type, $db, $y, $date_start, $date_end, $modetax, $direction, $m=0, $q=0)
91
+function tax_by_thirdparty($type, $db, $y, $date_start, $date_end, $modetax, $direction, $m = 0, $q = 0)
92 92
 {
93 93
     global $conf;
94 94
 
95 95
     // If we use date_start and date_end, we must not use $y, $m, $q
96
-    if (($date_start || $date_end) && (! empty($y) || ! empty($m) || ! empty($q)))
96
+    if (($date_start || $date_end) && (!empty($y) || !empty($m) || !empty($q)))
97 97
     {
98 98
     	dol_print_error('', 'Bad value of input parameter for tax_by_rate');
99 99
     }
100 100
 
101
-    $list=array();
101
+    $list = array();
102 102
     if ($direction == 'sell')
103 103
     {
104
-    	$invoicetable='facture';
105
-    	$invoicedettable='facturedet';
106
-    	$fk_facture='fk_facture';
107
-    	$fk_facture2='fk_facture';
108
-    	$fk_payment='fk_paiement';
109
-    	$total_tva='total_tva';
110
-    	$paymenttable='paiement';
111
-    	$paymentfacturetable='paiement_facture';
112
-    	$invoicefieldref='ref';
104
+    	$invoicetable = 'facture';
105
+    	$invoicedettable = 'facturedet';
106
+    	$fk_facture = 'fk_facture';
107
+    	$fk_facture2 = 'fk_facture';
108
+    	$fk_payment = 'fk_paiement';
109
+    	$total_tva = 'total_tva';
110
+    	$paymenttable = 'paiement';
111
+    	$paymentfacturetable = 'paiement_facture';
112
+    	$invoicefieldref = 'ref';
113 113
     }
114 114
     if ($direction == 'buy')
115 115
     {
116
-    	$invoicetable='facture_fourn';
117
-    	$invoicedettable='facture_fourn_det';
118
-    	$fk_facture='fk_facture_fourn';
119
-    	$fk_facture2='fk_facturefourn';
120
-    	$fk_payment='fk_paiementfourn';
121
-    	$total_tva='tva';
122
-    	$paymenttable='paiementfourn';
123
-    	$paymentfacturetable='paiementfourn_facturefourn';
124
-    	$invoicefieldref='ref';
116
+    	$invoicetable = 'facture_fourn';
117
+    	$invoicedettable = 'facture_fourn_det';
118
+    	$fk_facture = 'fk_facture_fourn';
119
+    	$fk_facture2 = 'fk_facturefourn';
120
+    	$fk_payment = 'fk_paiementfourn';
121
+    	$total_tva = 'tva';
122
+    	$paymenttable = 'paiementfourn';
123
+    	$paymentfacturetable = 'paiementfourn_facturefourn';
124
+    	$invoicefieldref = 'ref';
125 125
     }
126 126
 
127
-    if ( strpos( $type, 'localtax' ) === 0 ) {
128
-    	$f_rate = $type . '_tx';
127
+    if (strpos($type, 'localtax') === 0) {
128
+    	$f_rate = $type.'_tx';
129 129
     } else {
130 130
     	$f_rate = 'tva_tx';
131 131
     }
132 132
 
133
-    $total_localtax1='total_localtax1';
134
-    $total_localtax2='total_localtax2';
133
+    $total_localtax1 = 'total_localtax1';
134
+    $total_localtax2 = 'total_localtax2';
135 135
 
136 136
 
137 137
     // CAS DES BIENS/PRODUITS
138 138
 
139 139
     // Define sql request
140
-    $sql='';
140
+    $sql = '';
141 141
     if (($direction == 'sell' && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
142 142
     	|| ($direction == 'buy' && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice'))
143 143
     {
144 144
     	// Count on delivery date (use invoice date as delivery is unknown)
145 145
     	$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
146
-    	$sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
147
-    	$sql.= " d.date_start as date_start, d.date_end as date_end,";
148
-    	$sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
149
-    	$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
150
-    	$sql.= " 0 as payment_id, 0 as payment_amount";
151
-    	$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
152
-    	$sql.= " ".MAIN_DB_PREFIX."societe as s,";
153
-    	$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
154
-    	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
155
-    	$sql.= " WHERE f.entity = " . $conf->entity;
156
-    	$sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely)
157
-    	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
158
-    	else $sql.= " AND f.type IN (0,1,2,3,5)";
159
-    	$sql.= " AND f.rowid = d.".$fk_facture;
160
-    	$sql.= " AND s.rowid = f.fk_soc";
146
+    	$sql .= " d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
147
+    	$sql .= " d.date_start as date_start, d.date_end as date_end,";
148
+    	$sql .= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
149
+    	$sql .= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
150
+    	$sql .= " 0 as payment_id, 0 as payment_amount";
151
+    	$sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
152
+    	$sql .= " ".MAIN_DB_PREFIX."societe as s,";
153
+    	$sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
154
+    	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
155
+    	$sql .= " WHERE f.entity = ".$conf->entity;
156
+    	$sql .= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely)
157
+    	if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .= " AND f.type IN (0,1,2,5)";
158
+    	else $sql .= " AND f.type IN (0,1,2,3,5)";
159
+    	$sql .= " AND f.rowid = d.".$fk_facture;
160
+    	$sql .= " AND s.rowid = f.fk_soc";
161 161
     	if ($y && $m)
162 162
     	{
163
-    		$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
164
-    		$sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
163
+    		$sql .= " AND f.datef >= '".$db->idate(dol_get_first_day($y, $m, false))."'";
164
+    		$sql .= " AND f.datef <= '".$db->idate(dol_get_last_day($y, $m, false))."'";
165 165
     	}
166 166
     	else if ($y)
167 167
     	{
168
-    		$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,1,false))."'";
169
-    		$sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,12,false))."'";
168
+    		$sql .= " AND f.datef >= '".$db->idate(dol_get_first_day($y, 1, false))."'";
169
+    		$sql .= " AND f.datef <= '".$db->idate(dol_get_last_day($y, 12, false))."'";
170 170
     	}
171
-    	if ($q) $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
172
-    	if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
173
-    	$sql.= " AND (d.product_type = 0";                              // Limit to products
174
-    	$sql.= " AND d.date_start is null AND d.date_end IS NULL)";     // enhance detection of products
175
-    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
176
-    	$sql.= " ORDER BY d.rowid, d.".$fk_facture;
171
+    	if ($q) $sql .= " AND (date_format(f.datef,'%m') > ".(($q - 1) * 3)." AND date_format(f.datef,'%m') <= ".($q * 3).")";
172
+    	if ($date_start && $date_end) $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
173
+    	$sql .= " AND (d.product_type = 0"; // Limit to products
174
+    	$sql .= " AND d.date_start is null AND d.date_end IS NULL)"; // enhance detection of products
175
+    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql .= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
176
+    	$sql .= " ORDER BY d.rowid, d.".$fk_facture;
177 177
     }
178 178
     else
179 179
     {
180 180
     	// Count on payments date
181 181
     	$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
182
-    	$sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
183
-    	$sql.= " d.date_start as date_start, d.date_end as date_end,";
184
-    	$sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
185
-    	$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
186
-    	$sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,";
187
-    	$sql.= " pa.datep as datep";
188
-    	$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
189
-    	$sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
190
-    	$sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
191
-    	$sql.= " ".MAIN_DB_PREFIX."societe as s,";
192
-    	$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
193
-    	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
194
-    	$sql.= " WHERE f.entity = " . $conf->entity;
195
-    	$sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
196
-    	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
197
-    	else $sql.= " AND f.type IN (0,1,2,3,5)";
198
-    	$sql.= " AND f.rowid = d.".$fk_facture;
199
-    	$sql.= " AND s.rowid = f.fk_soc";
200
-    	$sql.= " AND pf.".$fk_facture2." = f.rowid";
201
-    	$sql.= " AND pa.rowid = pf.".$fk_payment;
182
+    	$sql .= " d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
183
+    	$sql .= " d.date_start as date_start, d.date_end as date_end,";
184
+    	$sql .= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
185
+    	$sql .= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
186
+    	$sql .= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,";
187
+    	$sql .= " pa.datep as datep";
188
+    	$sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
189
+    	$sql .= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
190
+    	$sql .= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
191
+    	$sql .= " ".MAIN_DB_PREFIX."societe as s,";
192
+    	$sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
193
+    	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
194
+    	$sql .= " WHERE f.entity = ".$conf->entity;
195
+    	$sql .= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
196
+    	if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .= " AND f.type IN (0,1,2,5)";
197
+    	else $sql .= " AND f.type IN (0,1,2,3,5)";
198
+    	$sql .= " AND f.rowid = d.".$fk_facture;
199
+    	$sql .= " AND s.rowid = f.fk_soc";
200
+    	$sql .= " AND pf.".$fk_facture2." = f.rowid";
201
+    	$sql .= " AND pa.rowid = pf.".$fk_payment;
202 202
     	if ($y && $m)
203 203
     	{
204
-    		$sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
205
-    		$sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
204
+    		$sql .= " AND pa.datep >= '".$db->idate(dol_get_first_day($y, $m, false))."'";
205
+    		$sql .= " AND pa.datep <= '".$db->idate(dol_get_last_day($y, $m, false))."'";
206 206
     	}
207 207
     	else if ($y)
208 208
     	{
209
-    		$sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
210
-    		$sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
209
+    		$sql .= " AND pa.datep >= '".$db->idate(dol_get_first_day($y, 1, false))."'";
210
+    		$sql .= " AND pa.datep <= '".$db->idate(dol_get_last_day($y, 12, false))."'";
211 211
     	}
212
-    	if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
213
-    	if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
214
-    	$sql.= " AND (d.product_type = 0";                              // Limit to products
215
-    	$sql.= " AND d.date_start is null AND d.date_end IS NULL)";     // enhance detection of products
216
-    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
217
-    	$sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
212
+    	if ($q) $sql .= " AND (date_format(pa.datep,'%m') > ".(($q - 1) * 3)." AND date_format(pa.datep,'%m') <= ".($q * 3).")";
213
+    	if ($date_start && $date_end) $sql .= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
214
+    	$sql .= " AND (d.product_type = 0"; // Limit to products
215
+    	$sql .= " AND d.date_start is null AND d.date_end IS NULL)"; // enhance detection of products
216
+    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql .= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
217
+    	$sql .= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
218 218
     }
219 219
 
220
-    if (! $sql) return -1;
220
+    if (!$sql) return -1;
221 221
     if ($sql == 'TODO') return -2;
222 222
     if ($sql != 'TODO')
223 223
     {
@@ -227,17 +227,17 @@  discard block
 block discarded – undo
227 227
     	if ($resql)
228 228
     	{
229 229
     		$company_id = -1;
230
-    		$oldrowid='';
231
-    		while($assoc = $db->fetch_array($resql))
230
+    		$oldrowid = '';
231
+    		while ($assoc = $db->fetch_array($resql))
232 232
     		{
233
-    			if (! isset($list[$assoc['company_id']]['totalht']))  $list[$assoc['company_id']]['totalht']=0;
234
-    			if (! isset($list[$assoc['company_id']]['vat']))      $list[$assoc['company_id']]['vat']=0;
235
-    			if (! isset($list[$assoc['company_id']]['localtax1']))      $list[$assoc['company_id']]['localtax1']=0;
236
-    			if (! isset($list[$assoc['company_id']]['localtax2']))      $list[$assoc['company_id']]['localtax2']=0;
233
+    			if (!isset($list[$assoc['company_id']]['totalht']))  $list[$assoc['company_id']]['totalht'] = 0;
234
+    			if (!isset($list[$assoc['company_id']]['vat']))      $list[$assoc['company_id']]['vat'] = 0;
235
+    			if (!isset($list[$assoc['company_id']]['localtax1']))      $list[$assoc['company_id']]['localtax1'] = 0;
236
+    			if (!isset($list[$assoc['company_id']]['localtax2']))      $list[$assoc['company_id']]['localtax2'] = 0;
237 237
 
238 238
     			if ($assoc['rowid'] != $oldrowid)       // Si rupture sur d.rowid
239 239
     			{
240
-    				$oldrowid=$assoc['rowid'];
240
+    				$oldrowid = $assoc['rowid'];
241 241
     				$list[$assoc['company_id']]['totalht']  += $assoc['total_ht'];
242 242
     				$list[$assoc['company_id']]['vat']      += $assoc['total_vat'];
243 243
     				$list[$assoc['company_id']]['localtax1']      += $assoc['total_localtax1'];
@@ -262,7 +262,7 @@  discard block
 block discarded – undo
262 262
     			$list[$assoc['company_id']]['totalht_list'][] = $assoc['total_ht'];
263 263
     			$list[$assoc['company_id']]['vat_list'][] = $assoc['total_vat'];
264 264
     			$list[$assoc['company_id']]['localtax1_list'][] = $assoc['total_localtax1'];
265
-    			$list[$assoc['company_id']]['localtax2_list'][]  = $assoc['total_localtax2'];
265
+    			$list[$assoc['company_id']]['localtax2_list'][] = $assoc['total_localtax2'];
266 266
 
267 267
     			$list[$assoc['company_id']]['pid'][] = $assoc['pid'];
268 268
     			$list[$assoc['company_id']]['pref'][] = $assoc['pref'];
@@ -285,90 +285,90 @@  discard block
 block discarded – undo
285 285
     // CAS DES SERVICES
286 286
 
287 287
     // Define sql request
288
-    $sql='';
288
+    $sql = '';
289 289
     if (($direction == 'sell' && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')
290 290
     	|| ($direction == 'buy' && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice'))
291 291
     {
292 292
     	// Count on invoice date
293 293
     	$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
294
-    	$sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
295
-    	$sql.= " d.date_start as date_start, d.date_end as date_end,";
296
-    	$sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
297
-    	$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
298
-    	$sql.= " 0 as payment_id, 0 as payment_amount";
299
-    	$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
300
-    	$sql.= " ".MAIN_DB_PREFIX."societe as s,";
301
-    	$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
302
-    	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
303
-    	$sql.= " WHERE f.entity = " . $conf->entity;
304
-    	$sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely)
305
-    	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
306
-    	else $sql.= " AND f.type IN (0,1,2,3,5)";
307
-    	$sql.= " AND f.rowid = d.".$fk_facture;
308
-    	$sql.= " AND s.rowid = f.fk_soc";
294
+    	$sql .= " d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
295
+    	$sql .= " d.date_start as date_start, d.date_end as date_end,";
296
+    	$sql .= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
297
+    	$sql .= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
298
+    	$sql .= " 0 as payment_id, 0 as payment_amount";
299
+    	$sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
300
+    	$sql .= " ".MAIN_DB_PREFIX."societe as s,";
301
+    	$sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
302
+    	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
303
+    	$sql .= " WHERE f.entity = ".$conf->entity;
304
+    	$sql .= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely)
305
+    	if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .= " AND f.type IN (0,1,2,5)";
306
+    	else $sql .= " AND f.type IN (0,1,2,3,5)";
307
+    	$sql .= " AND f.rowid = d.".$fk_facture;
308
+    	$sql .= " AND s.rowid = f.fk_soc";
309 309
     	if ($y && $m)
310 310
     	{
311
-    		$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
312
-    		$sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
311
+    		$sql .= " AND f.datef >= '".$db->idate(dol_get_first_day($y, $m, false))."'";
312
+    		$sql .= " AND f.datef <= '".$db->idate(dol_get_last_day($y, $m, false))."'";
313 313
     	}
314 314
     	else if ($y)
315 315
     	{
316
-    		$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,1,false))."'";
317
-    		$sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,12,false))."'";
316
+    		$sql .= " AND f.datef >= '".$db->idate(dol_get_first_day($y, 1, false))."'";
317
+    		$sql .= " AND f.datef <= '".$db->idate(dol_get_last_day($y, 12, false))."'";
318 318
     	}
319
-    	if ($q) $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
320
-    	if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
321
-    	$sql.= " AND (d.product_type = 1";                              // Limit to services
322
-    	$sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)";       // enhance detection of service
323
-    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
324
-    	$sql.= " ORDER BY d.rowid, d.".$fk_facture;
319
+    	if ($q) $sql .= " AND (date_format(f.datef,'%m') > ".(($q - 1) * 3)." AND date_format(f.datef,'%m') <= ".($q * 3).")";
320
+    	if ($date_start && $date_end) $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
321
+    	$sql .= " AND (d.product_type = 1"; // Limit to services
322
+    	$sql .= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)"; // enhance detection of service
323
+    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql .= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
324
+    	$sql .= " ORDER BY d.rowid, d.".$fk_facture;
325 325
     }
326 326
     else
327 327
     {
328 328
     	// Count on payments date
329 329
     	$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
330
-    	$sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
331
-    	$sql.= " d.date_start as date_start, d.date_end as date_end,";
332
-    	$sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
333
-    	$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
334
-    	$sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,";
335
-    	$sql.= " pa.datep as datep";
336
-    	$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
337
-    	$sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
338
-    	$sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
339
-    	$sql.= " ".MAIN_DB_PREFIX."societe as s,";
340
-    	$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
341
-    	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
342
-    	$sql.= " WHERE f.entity = " . $conf->entity;
343
-    	$sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
344
-    	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
345
-    	else $sql.= " AND f.type IN (0,1,2,3,5)";
346
-    	$sql.= " AND f.rowid = d.".$fk_facture;
347
-    	$sql.= " AND s.rowid = f.fk_soc";
348
-    	$sql.= " AND pf.".$fk_facture2." = f.rowid";
349
-    	$sql.= " AND pa.rowid = pf.".$fk_payment;
330
+    	$sql .= " d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
331
+    	$sql .= " d.date_start as date_start, d.date_end as date_end,";
332
+    	$sql .= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
333
+    	$sql .= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
334
+    	$sql .= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,";
335
+    	$sql .= " pa.datep as datep";
336
+    	$sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
337
+    	$sql .= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
338
+    	$sql .= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
339
+    	$sql .= " ".MAIN_DB_PREFIX."societe as s,";
340
+    	$sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
341
+    	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
342
+    	$sql .= " WHERE f.entity = ".$conf->entity;
343
+    	$sql .= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
344
+    	if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .= " AND f.type IN (0,1,2,5)";
345
+    	else $sql .= " AND f.type IN (0,1,2,3,5)";
346
+    	$sql .= " AND f.rowid = d.".$fk_facture;
347
+    	$sql .= " AND s.rowid = f.fk_soc";
348
+    	$sql .= " AND pf.".$fk_facture2." = f.rowid";
349
+    	$sql .= " AND pa.rowid = pf.".$fk_payment;
350 350
     	if ($y && $m)
351 351
     	{
352
-    		$sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
353
-    		$sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
352
+    		$sql .= " AND pa.datep >= '".$db->idate(dol_get_first_day($y, $m, false))."'";
353
+    		$sql .= " AND pa.datep <= '".$db->idate(dol_get_last_day($y, $m, false))."'";
354 354
     	}
355 355
     	else if ($y)
356 356
     	{
357
-    		$sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
358
-    		$sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
357
+    		$sql .= " AND pa.datep >= '".$db->idate(dol_get_first_day($y, 1, false))."'";
358
+    		$sql .= " AND pa.datep <= '".$db->idate(dol_get_last_day($y, 12, false))."'";
359 359
     	}
360
-    	if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
361
-    	if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
362
-    	$sql.= " AND (d.product_type = 1";                              		// Limit to services
363
-    	$sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)";       // enhance detection of service
364
-    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
365
-    	$sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
360
+    	if ($q) $sql .= " AND (date_format(pa.datep,'%m') > ".(($q - 1) * 3)." AND date_format(pa.datep,'%m') <= ".($q * 3).")";
361
+    	if ($date_start && $date_end) $sql .= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
362
+    	$sql .= " AND (d.product_type = 1"; // Limit to services
363
+    	$sql .= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)"; // enhance detection of service
364
+    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql .= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
365
+    	$sql .= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
366 366
     }
367 367
 
368
-    if (! $sql)
368
+    if (!$sql)
369 369
     {
370
-    	dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR);
371
-    	return -1;  // -1 = Not accountancy module enabled
370
+    	dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql, LOG_ERR);
371
+    	return -1; // -1 = Not accountancy module enabled
372 372
     }
373 373
     if ($sql == 'TODO') return -2; // -2 = Feature not yet available
374 374
     if ($sql != 'TODO')
@@ -378,17 +378,17 @@  discard block
 block discarded – undo
378 378
     	if ($resql)
379 379
     	{
380 380
     		$company_id = -1;
381
-    		$oldrowid='';
382
-    		while($assoc = $db->fetch_array($resql))
381
+    		$oldrowid = '';
382
+    		while ($assoc = $db->fetch_array($resql))
383 383
     		{
384
-    			if (! isset($list[$assoc['company_id']]['totalht']))  $list[$assoc['company_id']]['totalht']=0;
385
-    			if (! isset($list[$assoc['company_id']]['vat']))      $list[$assoc['company_id']]['vat']=0;
386
-    			if (! isset($list[$assoc['company_id']]['localtax1']))      $list[$assoc['company_id']]['localtax1']=0;
387
-    			if (! isset($list[$assoc['company_id']]['localtax2']))      $list[$assoc['company_id']]['localtax2']=0;
384
+    			if (!isset($list[$assoc['company_id']]['totalht']))  $list[$assoc['company_id']]['totalht'] = 0;
385
+    			if (!isset($list[$assoc['company_id']]['vat']))      $list[$assoc['company_id']]['vat'] = 0;
386
+    			if (!isset($list[$assoc['company_id']]['localtax1']))      $list[$assoc['company_id']]['localtax1'] = 0;
387
+    			if (!isset($list[$assoc['company_id']]['localtax2']))      $list[$assoc['company_id']]['localtax2'] = 0;
388 388
 
389 389
     			if ($assoc['rowid'] != $oldrowid)       // Si rupture sur d.rowid
390 390
     			{
391
-    				$oldrowid=$assoc['rowid'];
391
+    				$oldrowid = $assoc['rowid'];
392 392
     				$list[$assoc['company_id']]['totalht']  += $assoc['total_ht'];
393 393
     				$list[$assoc['company_id']]['vat']      += $assoc['total_vat'];
394 394
     				$list[$assoc['company_id']]['localtax1']	 += $assoc['total_localtax1'];
@@ -438,40 +438,40 @@  discard block
 block discarded – undo
438 438
     if ($direction == 'buy')		// buy only for expense reports
439 439
     {
440 440
     	// Define sql request
441
-    	$sql='';
441
+    	$sql = '';
442 442
 
443 443
     	// Count on payments date
444 444
     	$sql = "SELECT d.rowid, d.product_type as dtype, e.rowid as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.total_tva as total_vat, e.note_private as descr,";
445
-    	$sql .=" d.total_localtax1 as total_localtax1, d.total_localtax2 as total_localtax2, ";
446
-    	$sql.= " e.date_debut as date_start, e.date_fin as date_end, e.fk_user_author,";
447
-    	$sql.= " e.ref as facnum, e.total_ttc as ftotal_ttc, e.date_create, d.fk_c_type_fees as type,";
448
-    	$sql.= " p.fk_bank as payment_id, p.amount as payment_amount, p.rowid as pid, e.ref as pref";
449
-    	$sql.= " FROM ".MAIN_DB_PREFIX."expensereport as e";
450
-    	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport_det as d ON d.fk_expensereport = e.rowid ";
451
-    	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."payment_expensereport as p ON p.fk_expensereport = e.rowid ";
452
-    	$sql.= " WHERE e.entity = " . $conf->entity;
453
-    	$sql.= " AND e.fk_statut in (6)";
445
+    	$sql .= " d.total_localtax1 as total_localtax1, d.total_localtax2 as total_localtax2, ";
446
+    	$sql .= " e.date_debut as date_start, e.date_fin as date_end, e.fk_user_author,";
447
+    	$sql .= " e.ref as facnum, e.total_ttc as ftotal_ttc, e.date_create, d.fk_c_type_fees as type,";
448
+    	$sql .= " p.fk_bank as payment_id, p.amount as payment_amount, p.rowid as pid, e.ref as pref";
449
+    	$sql .= " FROM ".MAIN_DB_PREFIX."expensereport as e";
450
+    	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport_det as d ON d.fk_expensereport = e.rowid ";
451
+    	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."payment_expensereport as p ON p.fk_expensereport = e.rowid ";
452
+    	$sql .= " WHERE e.entity = ".$conf->entity;
453
+    	$sql .= " AND e.fk_statut in (6)";
454 454
     	if ($y && $m)
455 455
     	{
456
-    		$sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
457
-    		$sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
456
+    		$sql .= " AND p.datep >= '".$db->idate(dol_get_first_day($y, $m, false))."'";
457
+    		$sql .= " AND p.datep <= '".$db->idate(dol_get_last_day($y, $m, false))."'";
458 458
     	}
459 459
     	else if ($y)
460 460
     	{
461
-    		$sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
462
-    		$sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
461
+    		$sql .= " AND p.datep >= '".$db->idate(dol_get_first_day($y, 1, false))."'";
462
+    		$sql .= " AND p.datep <= '".$db->idate(dol_get_last_day($y, 12, false))."'";
463 463
     	}
464
-    	if ($q) $sql.= " AND (date_format(p.datep,'%m') > ".(($q-1)*3)." AND date_format(p.datep,'%m') <= ".($q*3).")";
465
-    	if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
466
-    	$sql.= " AND (d.product_type = -1";
467
-    	$sql.= " OR e.date_debut is NOT null OR e.date_fin IS NOT NULL)";       // enhance detection of service
468
-    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.total_tva <> 0)";
469
-    	$sql.= " ORDER BY e.rowid";
470
-
471
-    	if (! $sql)
464
+    	if ($q) $sql .= " AND (date_format(p.datep,'%m') > ".(($q - 1) * 3)." AND date_format(p.datep,'%m') <= ".($q * 3).")";
465
+    	if ($date_start && $date_end) $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
466
+    	$sql .= " AND (d.product_type = -1";
467
+    	$sql .= " OR e.date_debut is NOT null OR e.date_fin IS NOT NULL)"; // enhance detection of service
468
+    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql .= " AND (d.".$f_rate." <> 0 OR d.total_tva <> 0)";
469
+    	$sql .= " ORDER BY e.rowid";
470
+
471
+    	if (!$sql)
472 472
     	{
473
-    		dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR);
474
-    		return -1;  // -1 = Not accountancy module enabled
473
+    		dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql, LOG_ERR);
474
+    		return -1; // -1 = Not accountancy module enabled
475 475
     	}
476 476
     	if ($sql == 'TODO') return -2; // -2 = Feature not yet available
477 477
     	if ($sql != 'TODO')
@@ -481,18 +481,18 @@  discard block
 block discarded – undo
481 481
     		if ($resql)
482 482
     		{
483 483
     			$company_id = -1;
484
-    			$oldrowid='';
485
-    			while($assoc = $db->fetch_array($resql))
484
+    			$oldrowid = '';
485
+    			while ($assoc = $db->fetch_array($resql))
486 486
     			{
487
-    				if (! isset($list[$assoc['company_id']]['totalht']))  $list[$assoc['company_id']]['totalht']=0;
488
-    				if (! isset($list[$assoc['company_id']]['vat']))      $list[$assoc['company_id']]['vat']=0;
489
-    				if (! isset($list[$assoc['company_id']]['localtax1']))      $list[$assoc['company_id']]['localtax1']=0;
490
-    				if (! isset($list[$assoc['company_id']]['localtax2']))      $list[$assoc['company_id']]['localtax2']=0;
487
+    				if (!isset($list[$assoc['company_id']]['totalht']))  $list[$assoc['company_id']]['totalht'] = 0;
488
+    				if (!isset($list[$assoc['company_id']]['vat']))      $list[$assoc['company_id']]['vat'] = 0;
489
+    				if (!isset($list[$assoc['company_id']]['localtax1']))      $list[$assoc['company_id']]['localtax1'] = 0;
490
+    				if (!isset($list[$assoc['company_id']]['localtax2']))      $list[$assoc['company_id']]['localtax2'] = 0;
491 491
 
492 492
     				if ($assoc['rowid'] != $oldrowid)       // Si rupture sur d.rowid
493 493
     				{
494
-    					$oldrowid=$assoc['rowid'];
495
-    					$list[$assoc['company_id']]['totalht']  += $assoc['total_ht'];
494
+    					$oldrowid = $assoc['rowid'];
495
+    					$list[$assoc['company_id']]['totalht'] += $assoc['total_ht'];
496 496
     					$list[$assoc['company_id']]['vat'] += $assoc['total_vat'];
497 497
     					$list[$assoc['company_id']]['localtax1']	 += $assoc['total_localtax1'];
498 498
     					$list[$assoc['company_id']]['localtax2']	 += $assoc['total_localtax2'];
@@ -556,137 +556,137 @@  discard block
 block discarded – undo
556 556
  *  @param  int		$m           	Month
557 557
  *  @return array       			Array with details of VATs (per rate), -1 if no accountancy module, -2 if not yet developped, -3 if error
558 558
  */
559
-function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $direction, $m=0)
559
+function tax_by_rate($type, $db, $y, $q, $date_start, $date_end, $modetax, $direction, $m = 0)
560 560
 {
561 561
     global $conf;
562 562
 
563 563
     // If we use date_start and date_end, we must not use $y, $m, $q
564
-    if (($date_start || $date_end) && (! empty($y) || ! empty($m) || ! empty($q)))
564
+    if (($date_start || $date_end) && (!empty($y) || !empty($m) || !empty($q)))
565 565
     {
566 566
     	dol_print_error('', 'Bad value of input parameter for tax_by_rate');
567 567
     }
568 568
 
569
-    $list=array();
569
+    $list = array();
570 570
 
571 571
     if ($direction == 'sell')
572 572
     {
573
-        $invoicetable='facture';
574
-        $invoicedettable='facturedet';
575
-        $fk_facture='fk_facture';
576
-        $fk_facture2='fk_facture';
577
-        $fk_payment='fk_paiement';
578
-        $total_tva='total_tva';
579
-        $paymenttable='paiement';
580
-        $paymentfacturetable='paiement_facture';
581
-        $invoicefieldref='ref';
573
+        $invoicetable = 'facture';
574
+        $invoicedettable = 'facturedet';
575
+        $fk_facture = 'fk_facture';
576
+        $fk_facture2 = 'fk_facture';
577
+        $fk_payment = 'fk_paiement';
578
+        $total_tva = 'total_tva';
579
+        $paymenttable = 'paiement';
580
+        $paymentfacturetable = 'paiement_facture';
581
+        $invoicefieldref = 'ref';
582 582
     }
583 583
     else
584 584
     {
585
-        $invoicetable='facture_fourn';
586
-        $invoicedettable='facture_fourn_det';
587
-        $fk_facture='fk_facture_fourn';
588
-        $fk_facture2='fk_facturefourn';
589
-        $fk_payment='fk_paiementfourn';
590
-        $total_tva='tva';
591
-        $paymenttable='paiementfourn';
592
-        $paymentfacturetable='paiementfourn_facturefourn';
593
-        $invoicefieldref='ref';
585
+        $invoicetable = 'facture_fourn';
586
+        $invoicedettable = 'facture_fourn_det';
587
+        $fk_facture = 'fk_facture_fourn';
588
+        $fk_facture2 = 'fk_facturefourn';
589
+        $fk_payment = 'fk_paiementfourn';
590
+        $total_tva = 'tva';
591
+        $paymenttable = 'paiementfourn';
592
+        $paymentfacturetable = 'paiementfourn_facturefourn';
593
+        $invoicefieldref = 'ref';
594 594
     }
595 595
 
596
-	if ( strpos( $type, 'localtax' ) === 0 ) {
597
-		$f_rate = $type . '_tx';
596
+	if (strpos($type, 'localtax') === 0) {
597
+		$f_rate = $type.'_tx';
598 598
 	} else {
599 599
 		$f_rate = 'tva_tx';
600 600
 	}
601 601
 
602
-	$total_localtax1='total_localtax1';
603
-	$total_localtax2='total_localtax2';
602
+	$total_localtax1 = 'total_localtax1';
603
+	$total_localtax2 = 'total_localtax2';
604 604
 
605 605
 
606 606
     // CAS DES BIENS/PRODUITS
607 607
 
608 608
     // Define sql request
609
-    $sql='';
609
+    $sql = '';
610 610
     if (($direction == 'sell' && $conf->global->TAX_MODE_SELL_PRODUCT == 'invoice')
611 611
     	|| ($direction == 'buy' && $conf->global->TAX_MODE_BUY_PRODUCT == 'invoice'))
612 612
     {
613 613
         // Count on delivery date (use invoice date as delivery is unknown)
614 614
         $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
615
-        $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
616
-        $sql.= " d.date_start as date_start, d.date_end as date_end,";
617
-        $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
618
-        $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
619
-        $sql.= " 0 as payment_id, 0 as payment_amount";
620
-        $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
621
-        $sql.= " ".MAIN_DB_PREFIX."societe as s,";
622
-        $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
623
-        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
624
-        $sql.= " WHERE f.entity = " . $conf->entity;
625
-        $sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely)
626
-        if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
627
-        else $sql.= " AND f.type IN (0,1,2,3,5)";
628
-        $sql.= " AND f.rowid = d.".$fk_facture;
629
-        $sql.= " AND s.rowid = f.fk_soc";
615
+        $sql .= " d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
616
+        $sql .= " d.date_start as date_start, d.date_end as date_end,";
617
+        $sql .= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
618
+        $sql .= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
619
+        $sql .= " 0 as payment_id, 0 as payment_amount";
620
+        $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
621
+        $sql .= " ".MAIN_DB_PREFIX."societe as s,";
622
+        $sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
623
+        $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
624
+        $sql .= " WHERE f.entity = ".$conf->entity;
625
+        $sql .= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely)
626
+        if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .= " AND f.type IN (0,1,2,5)";
627
+        else $sql .= " AND f.type IN (0,1,2,3,5)";
628
+        $sql .= " AND f.rowid = d.".$fk_facture;
629
+        $sql .= " AND s.rowid = f.fk_soc";
630 630
         if ($y && $m)
631 631
         {
632
-            $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
633
-            $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
632
+            $sql .= " AND f.datef >= '".$db->idate(dol_get_first_day($y, $m, false))."'";
633
+            $sql .= " AND f.datef <= '".$db->idate(dol_get_last_day($y, $m, false))."'";
634 634
         }
635 635
         else if ($y)
636 636
         {
637
-            $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,1,false))."'";
638
-            $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,12,false))."'";
637
+            $sql .= " AND f.datef >= '".$db->idate(dol_get_first_day($y, 1, false))."'";
638
+            $sql .= " AND f.datef <= '".$db->idate(dol_get_last_day($y, 12, false))."'";
639 639
         }
640
-        if ($q) $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
641
-        if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
642
-        $sql.= " AND (d.product_type = 0";                              // Limit to products
643
-        $sql.= " AND d.date_start is null AND d.date_end IS NULL)";     // enhance detection of products
644
-        if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
645
-        $sql.= " ORDER BY d.rowid, d.".$fk_facture;
640
+        if ($q) $sql .= " AND (date_format(f.datef,'%m') > ".(($q - 1) * 3)." AND date_format(f.datef,'%m') <= ".($q * 3).")";
641
+        if ($date_start && $date_end) $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
642
+        $sql .= " AND (d.product_type = 0"; // Limit to products
643
+        $sql .= " AND d.date_start is null AND d.date_end IS NULL)"; // enhance detection of products
644
+        if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql .= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
645
+        $sql .= " ORDER BY d.rowid, d.".$fk_facture;
646 646
     }
647 647
     else
648 648
     {
649 649
     	// Count on payments date
650 650
     	$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
651
-    	$sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
652
-    	$sql.= " d.date_start as date_start, d.date_end as date_end,";
653
-    	$sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
654
-    	$sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
655
-    	$sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,";
656
-    	$sql.= " pa.datep as datep";
657
-    	$sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
658
-    	$sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
659
-    	$sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
660
-    	$sql.= " ".MAIN_DB_PREFIX."societe as s,";
661
-    	$sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
662
-    	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
663
-    	$sql.= " WHERE f.entity = " . $conf->entity;
664
-    	$sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
665
-    	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
666
-    	else $sql.= " AND f.type IN (0,1,2,3,5)";
667
-    	$sql.= " AND f.rowid = d.".$fk_facture;
668
-    	$sql.= " AND s.rowid = f.fk_soc";
669
-    	$sql.= " AND pf.".$fk_facture2." = f.rowid";
670
-    	$sql.= " AND pa.rowid = pf.".$fk_payment;
651
+    	$sql .= " d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
652
+    	$sql .= " d.date_start as date_start, d.date_end as date_end,";
653
+    	$sql .= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
654
+    	$sql .= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
655
+    	$sql .= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,";
656
+    	$sql .= " pa.datep as datep";
657
+    	$sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
658
+    	$sql .= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
659
+    	$sql .= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
660
+    	$sql .= " ".MAIN_DB_PREFIX."societe as s,";
661
+    	$sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
662
+    	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
663
+    	$sql .= " WHERE f.entity = ".$conf->entity;
664
+    	$sql .= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
665
+    	if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .= " AND f.type IN (0,1,2,5)";
666
+    	else $sql .= " AND f.type IN (0,1,2,3,5)";
667
+    	$sql .= " AND f.rowid = d.".$fk_facture;
668
+    	$sql .= " AND s.rowid = f.fk_soc";
669
+    	$sql .= " AND pf.".$fk_facture2." = f.rowid";
670
+    	$sql .= " AND pa.rowid = pf.".$fk_payment;
671 671
     	if ($y && $m)
672 672
     	{
673
-    		$sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
674
-    		$sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
673
+    		$sql .= " AND pa.datep >= '".$db->idate(dol_get_first_day($y, $m, false))."'";
674
+    		$sql .= " AND pa.datep <= '".$db->idate(dol_get_last_day($y, $m, false))."'";
675 675
     	}
676 676
     	else if ($y)
677 677
     	{
678
-    		$sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
679
-    		$sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
678
+    		$sql .= " AND pa.datep >= '".$db->idate(dol_get_first_day($y, 1, false))."'";
679
+    		$sql .= " AND pa.datep <= '".$db->idate(dol_get_last_day($y, 12, false))."'";
680 680
     	}
681
-    	if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
682
-    	if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
683
-    	$sql.= " AND (d.product_type = 0";                              // Limit to products
684
-    	$sql.= " AND d.date_start is null AND d.date_end IS NULL)";     // enhance detection of products
685
-    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
686
-    	$sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
681
+    	if ($q) $sql .= " AND (date_format(pa.datep,'%m') > ".(($q - 1) * 3)." AND date_format(pa.datep,'%m') <= ".($q * 3).")";
682
+    	if ($date_start && $date_end) $sql .= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
683
+    	$sql .= " AND (d.product_type = 0"; // Limit to products
684
+    	$sql .= " AND d.date_start is null AND d.date_end IS NULL)"; // enhance detection of products
685
+    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql .= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
686
+    	$sql .= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
687 687
     }
688 688
 
689
-    if (! $sql) return -1;
689
+    if (!$sql) return -1;
690 690
     if ($sql == 'TODO') return -2;
691 691
     if ($sql != 'TODO')
692 692
     {
@@ -696,18 +696,18 @@  discard block
 block discarded – undo
696 696
         if ($resql)
697 697
         {
698 698
             $rate = -1;
699
-            $oldrowid='';
700
-            while($assoc = $db->fetch_array($resql))
699
+            $oldrowid = '';
700
+            while ($assoc = $db->fetch_array($resql))
701 701
             {
702 702
             	// Code to avoid warnings when array entry not defined
703
-            	if (! isset($list[$assoc['rate']]['totalht']))   $list[$assoc['rate']]['totalht']=0;
704
-                if (! isset($list[$assoc['rate']]['vat']))       $list[$assoc['rate']]['vat']=0;
705
-                if (! isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0;
706
-                if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=0;
703
+            	if (!isset($list[$assoc['rate']]['totalht']))   $list[$assoc['rate']]['totalht'] = 0;
704
+                if (!isset($list[$assoc['rate']]['vat']))       $list[$assoc['rate']]['vat'] = 0;
705
+                if (!isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1'] = 0;
706
+                if (!isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2'] = 0;
707 707
 
708 708
                 if ($assoc['rowid'] != $oldrowid)       // Si rupture sur d.rowid
709 709
                 {
710
-                    $oldrowid=$assoc['rowid'];
710
+                    $oldrowid = $assoc['rowid'];
711 711
                     $list[$assoc['rate']]['totalht']   += $assoc['total_ht'];
712 712
                     $list[$assoc['rate']]['vat']       += $assoc['total_vat'];
713 713
                     $list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1'];
@@ -754,90 +754,90 @@  discard block
 block discarded – undo
754 754
     // CAS DES SERVICES
755 755
 
756 756
     // Define sql request
757
-    $sql='';
757
+    $sql = '';
758 758
     if (($direction == 'sell' && $conf->global->TAX_MODE_SELL_SERVICE == 'invoice')
759 759
     	|| ($direction == 'buy' && $conf->global->TAX_MODE_BUY_SERVICE == 'invoice'))
760 760
     {
761 761
         // Count on invoice date
762 762
         $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
763
-        $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
764
-        $sql.= " d.date_start as date_start, d.date_end as date_end,";
765
-        $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
766
-        $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
767
-        $sql.= " 0 as payment_id, 0 as payment_amount";
768
-        $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
769
-        $sql.= " ".MAIN_DB_PREFIX."societe as s,";
770
-        $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d" ;
771
-        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
772
-        $sql.= " WHERE f.entity = " . $conf->entity;
773
-        $sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely)
774
-        if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
775
-		else $sql.= " AND f.type IN (0,1,2,3,5)";
776
-        $sql.= " AND f.rowid = d.".$fk_facture;
777
-        $sql.= " AND s.rowid = f.fk_soc";
763
+        $sql .= " d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
764
+        $sql .= " d.date_start as date_start, d.date_end as date_end,";
765
+        $sql .= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
766
+        $sql .= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
767
+        $sql .= " 0 as payment_id, 0 as payment_amount";
768
+        $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
769
+        $sql .= " ".MAIN_DB_PREFIX."societe as s,";
770
+        $sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
771
+        $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
772
+        $sql .= " WHERE f.entity = ".$conf->entity;
773
+        $sql .= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely)
774
+        if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .= " AND f.type IN (0,1,2,5)";
775
+		else $sql .= " AND f.type IN (0,1,2,3,5)";
776
+        $sql .= " AND f.rowid = d.".$fk_facture;
777
+        $sql .= " AND s.rowid = f.fk_soc";
778 778
         if ($y && $m)
779 779
         {
780
-            $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
781
-            $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
780
+            $sql .= " AND f.datef >= '".$db->idate(dol_get_first_day($y, $m, false))."'";
781
+            $sql .= " AND f.datef <= '".$db->idate(dol_get_last_day($y, $m, false))."'";
782 782
         }
783 783
         else if ($y)
784 784
         {
785
-            $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,1,false))."'";
786
-            $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,12,false))."'";
785
+            $sql .= " AND f.datef >= '".$db->idate(dol_get_first_day($y, 1, false))."'";
786
+            $sql .= " AND f.datef <= '".$db->idate(dol_get_last_day($y, 12, false))."'";
787 787
         }
788
-        if ($q) $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
789
-        if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
790
-        $sql.= " AND (d.product_type = 1";                              // Limit to services
791
-        $sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)";       // enhance detection of service
792
-        if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
793
-        $sql.= " ORDER BY d.rowid, d.".$fk_facture;
788
+        if ($q) $sql .= " AND (date_format(f.datef,'%m') > ".(($q - 1) * 3)." AND date_format(f.datef,'%m') <= ".($q * 3).")";
789
+        if ($date_start && $date_end) $sql .= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
790
+        $sql .= " AND (d.product_type = 1"; // Limit to services
791
+        $sql .= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)"; // enhance detection of service
792
+        if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql .= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
793
+        $sql .= " ORDER BY d.rowid, d.".$fk_facture;
794 794
     }
795 795
     else
796 796
     {
797 797
         // Count on payments date
798 798
         $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
799
-        $sql .=" d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
800
-        $sql.= " d.date_start as date_start, d.date_end as date_end,";
801
-        $sql.= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
802
-        $sql.= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
803
-        $sql.= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,";
804
-        $sql.= " pa.datep as datep";
805
-        $sql.= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
806
-        $sql.= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
807
-        $sql.= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
808
-        $sql.= " ".MAIN_DB_PREFIX."societe as s,";
809
-        $sql.= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
810
-        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
811
-        $sql.= " WHERE f.entity = " . $conf->entity;
812
-        $sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
813
-        if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
814
-		else $sql.= " AND f.type IN (0,1,2,3,5)";
815
-        $sql.= " AND f.rowid = d.".$fk_facture;
816
-        $sql.= " AND s.rowid = f.fk_soc";
817
-        $sql.= " AND pf.".$fk_facture2." = f.rowid";
818
-        $sql.= " AND pa.rowid = pf.".$fk_payment;
799
+        $sql .= " d.".$total_localtax1." as total_localtax1, d.".$total_localtax2." as total_localtax2, ";
800
+        $sql .= " d.date_start as date_start, d.date_end as date_end,";
801
+        $sql .= " f.".$invoicefieldref." as facnum, f.type, f.total_ttc as ftotal_ttc, f.datef, s.nom as company_name, s.rowid as company_id,";
802
+        $sql .= " p.rowid as pid, p.ref as pref, p.fk_product_type as ptype,";
803
+        $sql .= " pf.".$fk_payment." as payment_id, pf.amount as payment_amount,";
804
+        $sql .= " pa.datep as datep";
805
+        $sql .= " FROM ".MAIN_DB_PREFIX.$invoicetable." as f,";
806
+        $sql .= " ".MAIN_DB_PREFIX.$paymentfacturetable." as pf,";
807
+        $sql .= " ".MAIN_DB_PREFIX.$paymenttable." as pa,";
808
+        $sql .= " ".MAIN_DB_PREFIX."societe as s,";
809
+        $sql .= " ".MAIN_DB_PREFIX.$invoicedettable." as d";
810
+        $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
811
+        $sql .= " WHERE f.entity = ".$conf->entity;
812
+        $sql .= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
813
+        if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql .= " AND f.type IN (0,1,2,5)";
814
+		else $sql .= " AND f.type IN (0,1,2,3,5)";
815
+        $sql .= " AND f.rowid = d.".$fk_facture;
816
+        $sql .= " AND s.rowid = f.fk_soc";
817
+        $sql .= " AND pf.".$fk_facture2." = f.rowid";
818
+        $sql .= " AND pa.rowid = pf.".$fk_payment;
819 819
         if ($y && $m)
820 820
         {
821
-            $sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
822
-            $sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
821
+            $sql .= " AND pa.datep >= '".$db->idate(dol_get_first_day($y, $m, false))."'";
822
+            $sql .= " AND pa.datep <= '".$db->idate(dol_get_last_day($y, $m, false))."'";
823 823
         }
824 824
         else if ($y)
825 825
         {
826
-            $sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
827
-            $sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
826
+            $sql .= " AND pa.datep >= '".$db->idate(dol_get_first_day($y, 1, false))."'";
827
+            $sql .= " AND pa.datep <= '".$db->idate(dol_get_last_day($y, 12, false))."'";
828 828
         }
829
-        if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
830
-        if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
831
-        $sql.= " AND (d.product_type = 1";                              		// Limit to services
832
-        $sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)";       // enhance detection of service
833
-        if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
834
-        $sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
829
+        if ($q) $sql .= " AND (date_format(pa.datep,'%m') > ".(($q - 1) * 3)." AND date_format(pa.datep,'%m') <= ".($q * 3).")";
830
+        if ($date_start && $date_end) $sql .= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
831
+        $sql .= " AND (d.product_type = 1"; // Limit to services
832
+        $sql .= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)"; // enhance detection of service
833
+        if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql .= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
834
+        $sql .= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
835 835
     }
836 836
 
837
-    if (! $sql)
837
+    if (!$sql)
838 838
     {
839
-        dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR);
840
-        return -1;  // -1 = Not accountancy module enabled
839
+        dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql, LOG_ERR);
840
+        return -1; // -1 = Not accountancy module enabled
841 841
     }
842 842
     if ($sql == 'TODO') return -2; // -2 = Feature not yet available
843 843
     if ($sql != 'TODO')
@@ -847,18 +847,18 @@  discard block
 block discarded – undo
847 847
         if ($resql)
848 848
         {
849 849
             $rate = -1;
850
-            $oldrowid='';
851
-            while($assoc = $db->fetch_array($resql))
850
+            $oldrowid = '';
851
+            while ($assoc = $db->fetch_array($resql))
852 852
             {
853 853
             	// Code to avoid warnings when array entry not defined
854
-            	if (! isset($list[$assoc['rate']]['totalht']))   $list[$assoc['rate']]['totalht']=0;
855
-                if (! isset($list[$assoc['rate']]['vat']))       $list[$assoc['rate']]['vat']=0;
856
-				if (! isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0;
857
-                if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=0;
854
+            	if (!isset($list[$assoc['rate']]['totalht']))   $list[$assoc['rate']]['totalht'] = 0;
855
+                if (!isset($list[$assoc['rate']]['vat']))       $list[$assoc['rate']]['vat'] = 0;
856
+				if (!isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1'] = 0;
857
+                if (!isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2'] = 0;
858 858
 
859 859
                 if ($assoc['rowid'] != $oldrowid)       // Si rupture sur d.rowid
860 860
                 {
861
-                    $oldrowid=$assoc['rowid'];
861
+                    $oldrowid = $assoc['rowid'];
862 862
                     $list[$assoc['rate']]['totalht']   += $assoc['total_ht'];
863 863
                     $list[$assoc['rate']]['vat']       += $assoc['total_vat'];
864 864
                     $list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1'];
@@ -907,40 +907,40 @@  discard block
 block discarded – undo
907 907
 	if ($direction == 'buy')		// buy only for expense reports
908 908
 	{
909 909
 		// Define sql request
910
-		$sql='';
910
+		$sql = '';
911 911
 
912 912
 		// Count on payments date
913 913
 		$sql = "SELECT d.rowid, d.product_type as dtype, e.rowid as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.total_tva as total_vat, e.note_private as descr,";
914
-		$sql .=" d.total_localtax1 as total_localtax1, d.total_localtax2 as total_localtax2, ";
915
-		$sql.= " e.date_debut as date_start, e.date_fin as date_end, e.fk_user_author,";
916
-		$sql.= " e.ref as facnum, e.total_ttc as ftotal_ttc, e.date_create, d.fk_c_type_fees as type,";
917
-		$sql.= " p.fk_bank as payment_id, p.amount as payment_amount, p.rowid as pid, e.ref as pref";
918
-		$sql.= " FROM ".MAIN_DB_PREFIX."expensereport as e ";
919
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport_det as d ON d.fk_expensereport = e.rowid ";
920
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."payment_expensereport as p ON p.fk_expensereport = e.rowid ";
921
-		$sql.= " WHERE e.entity = " . $conf->entity;
922
-		$sql.= " AND e.fk_statut in (6)";
914
+		$sql .= " d.total_localtax1 as total_localtax1, d.total_localtax2 as total_localtax2, ";
915
+		$sql .= " e.date_debut as date_start, e.date_fin as date_end, e.fk_user_author,";
916
+		$sql .= " e.ref as facnum, e.total_ttc as ftotal_ttc, e.date_create, d.fk_c_type_fees as type,";
917
+		$sql .= " p.fk_bank as payment_id, p.amount as payment_amount, p.rowid as pid, e.ref as pref";
918
+		$sql .= " FROM ".MAIN_DB_PREFIX."expensereport as e ";
919
+		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."expensereport_det as d ON d.fk_expensereport = e.rowid ";
920
+		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."payment_expensereport as p ON p.fk_expensereport = e.rowid ";
921
+		$sql .= " WHERE e.entity = ".$conf->entity;
922
+		$sql .= " AND e.fk_statut in (6)";
923 923
 		if ($y && $m)
924 924
 		{
925
-			$sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
926
-			$sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
925
+			$sql .= " AND p.datep >= '".$db->idate(dol_get_first_day($y, $m, false))."'";
926
+			$sql .= " AND p.datep <= '".$db->idate(dol_get_last_day($y, $m, false))."'";
927 927
 		}
928 928
 		else if ($y)
929 929
 		{
930
-			$sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
931
-			$sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
930
+			$sql .= " AND p.datep >= '".$db->idate(dol_get_first_day($y, 1, false))."'";
931
+			$sql .= " AND p.datep <= '".$db->idate(dol_get_last_day($y, 12, false))."'";
932 932
 		}
933
-		if ($q) $sql.= " AND (date_format(p.datep,'%m') > ".(($q-1)*3)." AND date_format(p.datep,'%m') <= ".($q*3).")";
934
-		if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
935
-		$sql.= " AND (d.product_type = -1";
936
-		$sql.= " OR e.date_debut is NOT null OR e.date_fin IS NOT NULL)";       // enhance detection of service
937
-		if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.total_tva <> 0)";
938
-		$sql.= " ORDER BY e.rowid";
939
-
940
-		if (! $sql)
933
+		if ($q) $sql .= " AND (date_format(p.datep,'%m') > ".(($q - 1) * 3)." AND date_format(p.datep,'%m') <= ".($q * 3).")";
934
+		if ($date_start && $date_end) $sql .= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
935
+		$sql .= " AND (d.product_type = -1";
936
+		$sql .= " OR e.date_debut is NOT null OR e.date_fin IS NOT NULL)"; // enhance detection of service
937
+		if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql .= " AND (d.".$f_rate." <> 0 OR d.total_tva <> 0)";
938
+		$sql .= " ORDER BY e.rowid";
939
+
940
+		if (!$sql)
941 941
 		{
942
-			dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR);
943
-			return -1;  // -1 = Not accountancy module enabled
942
+			dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql, LOG_ERR);
943
+			return -1; // -1 = Not accountancy module enabled
944 944
 		}
945 945
 		if ($sql == 'TODO') return -2; // -2 = Feature not yet available
946 946
 		if ($sql != 'TODO')
@@ -950,20 +950,20 @@  discard block
 block discarded – undo
950 950
 			if ($resql)
951 951
 			{
952 952
 				$rate = -1;
953
-				$oldrowid='';
954
-				while($assoc = $db->fetch_array($resql))
953
+				$oldrowid = '';
954
+				while ($assoc = $db->fetch_array($resql))
955 955
 				{
956 956
 					// Code to avoid warnings when array entry not defined
957
-					if (! isset($list[$assoc['rate']]['totalht']))   $list[$assoc['rate']]['totalht']=0;
958
-					if (! isset($list[$assoc['rate']]['vat']))       $list[$assoc['rate']]['vat']=0;
959
-					if (! isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0;
960
-					if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=0;
957
+					if (!isset($list[$assoc['rate']]['totalht']))   $list[$assoc['rate']]['totalht'] = 0;
958
+					if (!isset($list[$assoc['rate']]['vat']))       $list[$assoc['rate']]['vat'] = 0;
959
+					if (!isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1'] = 0;
960
+					if (!isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2'] = 0;
961 961
 
962 962
 					if ($assoc['rowid'] != $oldrowid)       // Si rupture sur d.rowid
963 963
 					{
964
-						$oldrowid=$assoc['rowid'];
964
+						$oldrowid = $assoc['rowid'];
965 965
 						$list[$assoc['rate']]['totalht']   += $assoc['total_ht'];
966
-                        $list[$assoc['rate']]['vat']       += $assoc['total_vat'];
966
+                        $list[$assoc['rate']]['vat'] += $assoc['total_vat'];
967 967
 						$list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1'];
968 968
 						$list[$assoc['rate']]['localtax2'] += $assoc['total_localtax2'];
969 969
 					}
Please login to merge, or discard this patch.
Braces   +278 added lines, -129 removed lines patch added patch discarded remove patch
@@ -59,7 +59,9 @@  discard block
 block discarded – undo
59 59
     $nbLinks=Link::count($db, $object->element, $object->id);
60 60
 	$head[$h][0] = DOL_URL_ROOT.'/compta/sociales/document.php?id='.$object->id;
61 61
 	$head[$h][1] = $langs->trans("Documents");
62
-	if (($nbFiles+$nbLinks) > 0) $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
62
+	if (($nbFiles+$nbLinks) > 0) {
63
+	    $head[$h][1].= ' <span class="badge">'.($nbFiles+$nbLinks).'</span>';
64
+	}
63 65
 	$head[$h][2] = 'documents';
64 66
 	$h++;
65 67
 
@@ -154,28 +156,35 @@  discard block
 block discarded – undo
154 156
     	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
155 157
     	$sql.= " WHERE f.entity = " . $conf->entity;
156 158
     	$sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely)
157
-    	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
158
-    	else $sql.= " AND f.type IN (0,1,2,3,5)";
159
+    	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
160
+    	    $sql.= " AND f.type IN (0,1,2,5)";
161
+    	} else {
162
+    	    $sql.= " AND f.type IN (0,1,2,3,5)";
163
+    	}
159 164
     	$sql.= " AND f.rowid = d.".$fk_facture;
160 165
     	$sql.= " AND s.rowid = f.fk_soc";
161 166
     	if ($y && $m)
162 167
     	{
163 168
     		$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
164 169
     		$sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
165
-    	}
166
-    	else if ($y)
170
+    	} else if ($y)
167 171
     	{
168 172
     		$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,1,false))."'";
169 173
     		$sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,12,false))."'";
170 174
     	}
171
-    	if ($q) $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
172
-    	if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
175
+    	if ($q) {
176
+    	    $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
177
+    	}
178
+    	if ($date_start && $date_end) {
179
+    	    $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
180
+    	}
173 181
     	$sql.= " AND (d.product_type = 0";                              // Limit to products
174 182
     	$sql.= " AND d.date_start is null AND d.date_end IS NULL)";     // enhance detection of products
175
-    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
183
+    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) {
184
+    	    $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
185
+    	}
176 186
     	$sql.= " ORDER BY d.rowid, d.".$fk_facture;
177
-    }
178
-    else
187
+    } else
179 188
     {
180 189
     	// Count on payments date
181 190
     	$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
@@ -193,8 +202,11 @@  discard block
 block discarded – undo
193 202
     	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
194 203
     	$sql.= " WHERE f.entity = " . $conf->entity;
195 204
     	$sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
196
-    	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
197
-    	else $sql.= " AND f.type IN (0,1,2,3,5)";
205
+    	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
206
+    	    $sql.= " AND f.type IN (0,1,2,5)";
207
+    	} else {
208
+    	    $sql.= " AND f.type IN (0,1,2,3,5)";
209
+    	}
198 210
     	$sql.= " AND f.rowid = d.".$fk_facture;
199 211
     	$sql.= " AND s.rowid = f.fk_soc";
200 212
     	$sql.= " AND pf.".$fk_facture2." = f.rowid";
@@ -203,22 +215,31 @@  discard block
 block discarded – undo
203 215
     	{
204 216
     		$sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
205 217
     		$sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
206
-    	}
207
-    	else if ($y)
218
+    	} else if ($y)
208 219
     	{
209 220
     		$sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
210 221
     		$sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
211 222
     	}
212
-    	if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
213
-    	if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
223
+    	if ($q) {
224
+    	    $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
225
+    	}
226
+    	if ($date_start && $date_end) {
227
+    	    $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
228
+    	}
214 229
     	$sql.= " AND (d.product_type = 0";                              // Limit to products
215 230
     	$sql.= " AND d.date_start is null AND d.date_end IS NULL)";     // enhance detection of products
216
-    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
231
+    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) {
232
+    	    $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
233
+    	}
217 234
     	$sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
218 235
     }
219 236
 
220
-    if (! $sql) return -1;
221
-    if ($sql == 'TODO') return -2;
237
+    if (! $sql) {
238
+        return -1;
239
+    }
240
+    if ($sql == 'TODO') {
241
+        return -2;
242
+    }
222 243
     if ($sql != 'TODO')
223 244
     {
224 245
     	dol_syslog("Tax.lib.php::tax_by_thirdparty", LOG_DEBUG);
@@ -230,14 +251,24 @@  discard block
 block discarded – undo
230 251
     		$oldrowid='';
231 252
     		while($assoc = $db->fetch_array($resql))
232 253
     		{
233
-    			if (! isset($list[$assoc['company_id']]['totalht']))  $list[$assoc['company_id']]['totalht']=0;
234
-    			if (! isset($list[$assoc['company_id']]['vat']))      $list[$assoc['company_id']]['vat']=0;
235
-    			if (! isset($list[$assoc['company_id']]['localtax1']))      $list[$assoc['company_id']]['localtax1']=0;
236
-    			if (! isset($list[$assoc['company_id']]['localtax2']))      $list[$assoc['company_id']]['localtax2']=0;
254
+    			if (! isset($list[$assoc['company_id']]['totalht'])) {
255
+    			    $list[$assoc['company_id']]['totalht']=0;
256
+    			}
257
+    			if (! isset($list[$assoc['company_id']]['vat'])) {
258
+    			    $list[$assoc['company_id']]['vat']=0;
259
+    			}
260
+    			if (! isset($list[$assoc['company_id']]['localtax1'])) {
261
+    			    $list[$assoc['company_id']]['localtax1']=0;
262
+    			}
263
+    			if (! isset($list[$assoc['company_id']]['localtax2'])) {
264
+    			    $list[$assoc['company_id']]['localtax2']=0;
265
+    			}
237 266
 
238
-    			if ($assoc['rowid'] != $oldrowid)       // Si rupture sur d.rowid
267
+    			if ($assoc['rowid'] != $oldrowid) {
268
+    			    // Si rupture sur d.rowid
239 269
     			{
240 270
     				$oldrowid=$assoc['rowid'];
271
+    			}
241 272
     				$list[$assoc['company_id']]['totalht']  += $assoc['total_ht'];
242 273
     				$list[$assoc['company_id']]['vat']      += $assoc['total_vat'];
243 274
     				$list[$assoc['company_id']]['localtax1']      += $assoc['total_localtax1'];
@@ -273,8 +304,7 @@  discard block
 block discarded – undo
273 304
 
274 305
     			$company_id = $assoc['company_id'];
275 306
     		}
276
-    	}
277
-    	else
307
+    	} else
278 308
     	{
279 309
     		dol_print_error($db);
280 310
     		return -3;
@@ -302,28 +332,35 @@  discard block
 block discarded – undo
302 332
     	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
303 333
     	$sql.= " WHERE f.entity = " . $conf->entity;
304 334
     	$sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely)
305
-    	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
306
-    	else $sql.= " AND f.type IN (0,1,2,3,5)";
335
+    	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
336
+    	    $sql.= " AND f.type IN (0,1,2,5)";
337
+    	} else {
338
+    	    $sql.= " AND f.type IN (0,1,2,3,5)";
339
+    	}
307 340
     	$sql.= " AND f.rowid = d.".$fk_facture;
308 341
     	$sql.= " AND s.rowid = f.fk_soc";
309 342
     	if ($y && $m)
310 343
     	{
311 344
     		$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
312 345
     		$sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
313
-    	}
314
-    	else if ($y)
346
+    	} else if ($y)
315 347
     	{
316 348
     		$sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,1,false))."'";
317 349
     		$sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,12,false))."'";
318 350
     	}
319
-    	if ($q) $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
320
-    	if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
351
+    	if ($q) {
352
+    	    $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
353
+    	}
354
+    	if ($date_start && $date_end) {
355
+    	    $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
356
+    	}
321 357
     	$sql.= " AND (d.product_type = 1";                              // Limit to services
322 358
     	$sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)";       // enhance detection of service
323
-    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
359
+    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) {
360
+    	    $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
361
+    	}
324 362
     	$sql.= " ORDER BY d.rowid, d.".$fk_facture;
325
-    }
326
-    else
363
+    } else
327 364
     {
328 365
     	// Count on payments date
329 366
     	$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
@@ -341,8 +378,11 @@  discard block
 block discarded – undo
341 378
     	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
342 379
     	$sql.= " WHERE f.entity = " . $conf->entity;
343 380
     	$sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
344
-    	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
345
-    	else $sql.= " AND f.type IN (0,1,2,3,5)";
381
+    	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
382
+    	    $sql.= " AND f.type IN (0,1,2,5)";
383
+    	} else {
384
+    	    $sql.= " AND f.type IN (0,1,2,3,5)";
385
+    	}
346 386
     	$sql.= " AND f.rowid = d.".$fk_facture;
347 387
     	$sql.= " AND s.rowid = f.fk_soc";
348 388
     	$sql.= " AND pf.".$fk_facture2." = f.rowid";
@@ -351,17 +391,22 @@  discard block
 block discarded – undo
351 391
     	{
352 392
     		$sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
353 393
     		$sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
354
-    	}
355
-    	else if ($y)
394
+    	} else if ($y)
356 395
     	{
357 396
     		$sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
358 397
     		$sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
359 398
     	}
360
-    	if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
361
-    	if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
399
+    	if ($q) {
400
+    	    $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
401
+    	}
402
+    	if ($date_start && $date_end) {
403
+    	    $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
404
+    	}
362 405
     	$sql.= " AND (d.product_type = 1";                              		// Limit to services
363 406
     	$sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)";       // enhance detection of service
364
-    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
407
+    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) {
408
+    	    $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
409
+    	}
365 410
     	$sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
366 411
     }
367 412
 
@@ -370,7 +415,10 @@  discard block
 block discarded – undo
370 415
     	dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR);
371 416
     	return -1;  // -1 = Not accountancy module enabled
372 417
     }
373
-    if ($sql == 'TODO') return -2; // -2 = Feature not yet available
418
+    if ($sql == 'TODO') {
419
+        return -2;
420
+    }
421
+    // -2 = Feature not yet available
374 422
     if ($sql != 'TODO')
375 423
     {
376 424
     	dol_syslog("Tax.lib.php::tax_by_rate", LOG_DEBUG);
@@ -381,14 +429,24 @@  discard block
 block discarded – undo
381 429
     		$oldrowid='';
382 430
     		while($assoc = $db->fetch_array($resql))
383 431
     		{
384
-    			if (! isset($list[$assoc['company_id']]['totalht']))  $list[$assoc['company_id']]['totalht']=0;
385
-    			if (! isset($list[$assoc['company_id']]['vat']))      $list[$assoc['company_id']]['vat']=0;
386
-    			if (! isset($list[$assoc['company_id']]['localtax1']))      $list[$assoc['company_id']]['localtax1']=0;
387
-    			if (! isset($list[$assoc['company_id']]['localtax2']))      $list[$assoc['company_id']]['localtax2']=0;
432
+    			if (! isset($list[$assoc['company_id']]['totalht'])) {
433
+    			    $list[$assoc['company_id']]['totalht']=0;
434
+    			}
435
+    			if (! isset($list[$assoc['company_id']]['vat'])) {
436
+    			    $list[$assoc['company_id']]['vat']=0;
437
+    			}
438
+    			if (! isset($list[$assoc['company_id']]['localtax1'])) {
439
+    			    $list[$assoc['company_id']]['localtax1']=0;
440
+    			}
441
+    			if (! isset($list[$assoc['company_id']]['localtax2'])) {
442
+    			    $list[$assoc['company_id']]['localtax2']=0;
443
+    			}
388 444
 
389
-    			if ($assoc['rowid'] != $oldrowid)       // Si rupture sur d.rowid
445
+    			if ($assoc['rowid'] != $oldrowid) {
446
+    			    // Si rupture sur d.rowid
390 447
     			{
391 448
     				$oldrowid=$assoc['rowid'];
449
+    			}
392 450
     				$list[$assoc['company_id']]['totalht']  += $assoc['total_ht'];
393 451
     				$list[$assoc['company_id']]['vat']      += $assoc['total_vat'];
394 452
     				$list[$assoc['company_id']]['localtax1']	 += $assoc['total_localtax1'];
@@ -424,8 +482,7 @@  discard block
 block discarded – undo
424 482
 
425 483
     			$company_id = $assoc['company_id'];
426 484
     		}
427
-    	}
428
-    	else
485
+    	} else
429 486
     	{
430 487
     		dol_print_error($db);
431 488
     		return -3;
@@ -435,10 +492,12 @@  discard block
 block discarded – undo
435 492
 
436 493
     // CASE OF EXPENSE REPORT
437 494
 
438
-    if ($direction == 'buy')		// buy only for expense reports
495
+    if ($direction == 'buy') {
496
+        // buy only for expense reports
439 497
     {
440 498
     	// Define sql request
441 499
     	$sql='';
500
+    }
442 501
 
443 502
     	// Count on payments date
444 503
     	$sql = "SELECT d.rowid, d.product_type as dtype, e.rowid as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.total_tva as total_vat, e.note_private as descr,";
@@ -455,17 +514,22 @@  discard block
 block discarded – undo
455 514
     	{
456 515
     		$sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
457 516
     		$sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
458
-    	}
459
-    	else if ($y)
517
+    	} else if ($y)
460 518
     	{
461 519
     		$sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
462 520
     		$sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
463 521
     	}
464
-    	if ($q) $sql.= " AND (date_format(p.datep,'%m') > ".(($q-1)*3)." AND date_format(p.datep,'%m') <= ".($q*3).")";
465
-    	if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
522
+    	if ($q) {
523
+    	    $sql.= " AND (date_format(p.datep,'%m') > ".(($q-1)*3)." AND date_format(p.datep,'%m') <= ".($q*3).")";
524
+    	}
525
+    	if ($date_start && $date_end) {
526
+    	    $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
527
+    	}
466 528
     	$sql.= " AND (d.product_type = -1";
467 529
     	$sql.= " OR e.date_debut is NOT null OR e.date_fin IS NOT NULL)";       // enhance detection of service
468
-    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.total_tva <> 0)";
530
+    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) {
531
+    	    $sql.= " AND (d.".$f_rate." <> 0 OR d.total_tva <> 0)";
532
+    	}
469 533
     	$sql.= " ORDER BY e.rowid";
470 534
 
471 535
     	if (! $sql)
@@ -473,7 +537,10 @@  discard block
 block discarded – undo
473 537
     		dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR);
474 538
     		return -1;  // -1 = Not accountancy module enabled
475 539
     	}
476
-    	if ($sql == 'TODO') return -2; // -2 = Feature not yet available
540
+    	if ($sql == 'TODO') {
541
+    	    return -2;
542
+    	}
543
+    	// -2 = Feature not yet available
477 544
     	if ($sql != 'TODO')
478 545
     	{
479 546
     		dol_syslog("Tax.lib.php::tax_by_rate", LOG_DEBUG);
@@ -484,14 +551,24 @@  discard block
 block discarded – undo
484 551
     			$oldrowid='';
485 552
     			while($assoc = $db->fetch_array($resql))
486 553
     			{
487
-    				if (! isset($list[$assoc['company_id']]['totalht']))  $list[$assoc['company_id']]['totalht']=0;
488
-    				if (! isset($list[$assoc['company_id']]['vat']))      $list[$assoc['company_id']]['vat']=0;
489
-    				if (! isset($list[$assoc['company_id']]['localtax1']))      $list[$assoc['company_id']]['localtax1']=0;
490
-    				if (! isset($list[$assoc['company_id']]['localtax2']))      $list[$assoc['company_id']]['localtax2']=0;
554
+    				if (! isset($list[$assoc['company_id']]['totalht'])) {
555
+    				    $list[$assoc['company_id']]['totalht']=0;
556
+    				}
557
+    				if (! isset($list[$assoc['company_id']]['vat'])) {
558
+    				    $list[$assoc['company_id']]['vat']=0;
559
+    				}
560
+    				if (! isset($list[$assoc['company_id']]['localtax1'])) {
561
+    				    $list[$assoc['company_id']]['localtax1']=0;
562
+    				}
563
+    				if (! isset($list[$assoc['company_id']]['localtax2'])) {
564
+    				    $list[$assoc['company_id']]['localtax2']=0;
565
+    				}
491 566
 
492
-    				if ($assoc['rowid'] != $oldrowid)       // Si rupture sur d.rowid
567
+    				if ($assoc['rowid'] != $oldrowid) {
568
+    				    // Si rupture sur d.rowid
493 569
     				{
494 570
     					$oldrowid=$assoc['rowid'];
571
+    				}
495 572
     					$list[$assoc['company_id']]['totalht']  += $assoc['total_ht'];
496 573
     					$list[$assoc['company_id']]['vat'] += $assoc['total_vat'];
497 574
     					$list[$assoc['company_id']]['localtax1']	 += $assoc['total_localtax1'];
@@ -528,8 +605,7 @@  discard block
 block discarded – undo
528 605
 
529 606
     				$company_id = $assoc['company_id'];
530 607
     			}
531
-    		}
532
-    		else
608
+    		} else
533 609
     		{
534 610
     			dol_print_error($db);
535 611
     			return -3;
@@ -579,8 +655,7 @@  discard block
 block discarded – undo
579 655
         $paymenttable='paiement';
580 656
         $paymentfacturetable='paiement_facture';
581 657
         $invoicefieldref='ref';
582
-    }
583
-    else
658
+    } else
584 659
     {
585 660
         $invoicetable='facture_fourn';
586 661
         $invoicedettable='facture_fourn_det';
@@ -623,28 +698,35 @@  discard block
 block discarded – undo
623 698
         $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
624 699
         $sql.= " WHERE f.entity = " . $conf->entity;
625 700
         $sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely)
626
-        if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
627
-        else $sql.= " AND f.type IN (0,1,2,3,5)";
701
+        if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
702
+            $sql.= " AND f.type IN (0,1,2,5)";
703
+        } else {
704
+            $sql.= " AND f.type IN (0,1,2,3,5)";
705
+        }
628 706
         $sql.= " AND f.rowid = d.".$fk_facture;
629 707
         $sql.= " AND s.rowid = f.fk_soc";
630 708
         if ($y && $m)
631 709
         {
632 710
             $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
633 711
             $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
634
-        }
635
-        else if ($y)
712
+        } else if ($y)
636 713
         {
637 714
             $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,1,false))."'";
638 715
             $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,12,false))."'";
639 716
         }
640
-        if ($q) $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
641
-        if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
717
+        if ($q) {
718
+            $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
719
+        }
720
+        if ($date_start && $date_end) {
721
+            $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
722
+        }
642 723
         $sql.= " AND (d.product_type = 0";                              // Limit to products
643 724
         $sql.= " AND d.date_start is null AND d.date_end IS NULL)";     // enhance detection of products
644
-        if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
725
+        if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) {
726
+            $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
727
+        }
645 728
         $sql.= " ORDER BY d.rowid, d.".$fk_facture;
646
-    }
647
-    else
729
+    } else
648 730
     {
649 731
     	// Count on payments date
650 732
     	$sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
@@ -662,8 +744,11 @@  discard block
 block discarded – undo
662 744
     	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
663 745
     	$sql.= " WHERE f.entity = " . $conf->entity;
664 746
     	$sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
665
-    	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
666
-    	else $sql.= " AND f.type IN (0,1,2,3,5)";
747
+    	if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
748
+    	    $sql.= " AND f.type IN (0,1,2,5)";
749
+    	} else {
750
+    	    $sql.= " AND f.type IN (0,1,2,3,5)";
751
+    	}
667 752
     	$sql.= " AND f.rowid = d.".$fk_facture;
668 753
     	$sql.= " AND s.rowid = f.fk_soc";
669 754
     	$sql.= " AND pf.".$fk_facture2." = f.rowid";
@@ -672,22 +757,31 @@  discard block
 block discarded – undo
672 757
     	{
673 758
     		$sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
674 759
     		$sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
675
-    	}
676
-    	else if ($y)
760
+    	} else if ($y)
677 761
     	{
678 762
     		$sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
679 763
     		$sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
680 764
     	}
681
-    	if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
682
-    	if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
765
+    	if ($q) {
766
+    	    $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
767
+    	}
768
+    	if ($date_start && $date_end) {
769
+    	    $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
770
+    	}
683 771
     	$sql.= " AND (d.product_type = 0";                              // Limit to products
684 772
     	$sql.= " AND d.date_start is null AND d.date_end IS NULL)";     // enhance detection of products
685
-    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
773
+    	if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) {
774
+    	    $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
775
+    	}
686 776
     	$sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
687 777
     }
688 778
 
689
-    if (! $sql) return -1;
690
-    if ($sql == 'TODO') return -2;
779
+    if (! $sql) {
780
+        return -1;
781
+    }
782
+    if ($sql == 'TODO') {
783
+        return -2;
784
+    }
691 785
     if ($sql != 'TODO')
692 786
     {
693 787
         dol_syslog("Tax.lib.php::tax_by_rate", LOG_DEBUG);
@@ -700,14 +794,24 @@  discard block
 block discarded – undo
700 794
             while($assoc = $db->fetch_array($resql))
701 795
             {
702 796
             	// Code to avoid warnings when array entry not defined
703
-            	if (! isset($list[$assoc['rate']]['totalht']))   $list[$assoc['rate']]['totalht']=0;
704
-                if (! isset($list[$assoc['rate']]['vat']))       $list[$assoc['rate']]['vat']=0;
705
-                if (! isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0;
706
-                if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=0;
797
+            	if (! isset($list[$assoc['rate']]['totalht'])) {
798
+            	    $list[$assoc['rate']]['totalht']=0;
799
+            	}
800
+                if (! isset($list[$assoc['rate']]['vat'])) {
801
+                    $list[$assoc['rate']]['vat']=0;
802
+                }
803
+                if (! isset($list[$assoc['rate']]['localtax1'])) {
804
+                    $list[$assoc['rate']]['localtax1']=0;
805
+                }
806
+                if (! isset($list[$assoc['rate']]['localtax2'])) {
807
+                    $list[$assoc['rate']]['localtax2']=0;
808
+                }
707 809
 
708
-                if ($assoc['rowid'] != $oldrowid)       // Si rupture sur d.rowid
810
+                if ($assoc['rowid'] != $oldrowid) {
811
+                    // Si rupture sur d.rowid
709 812
                 {
710 813
                     $oldrowid=$assoc['rowid'];
814
+                }
711 815
                     $list[$assoc['rate']]['totalht']   += $assoc['total_ht'];
712 816
                     $list[$assoc['rate']]['vat']       += $assoc['total_vat'];
713 817
                     $list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1'];
@@ -742,8 +846,7 @@  discard block
 block discarded – undo
742 846
 
743 847
                 $rate = $assoc['rate'];
744 848
             }
745
-        }
746
-        else
849
+        } else
747 850
         {
748 851
             dol_print_error($db);
749 852
             return -3;
@@ -771,28 +874,35 @@  discard block
 block discarded – undo
771 874
         $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
772 875
         $sql.= " WHERE f.entity = " . $conf->entity;
773 876
         $sql.= " AND f.fk_statut in (1,2)"; // Validated or paid (partially or completely)
774
-        if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
775
-		else $sql.= " AND f.type IN (0,1,2,3,5)";
877
+        if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
878
+            $sql.= " AND f.type IN (0,1,2,5)";
879
+        } else {
880
+		    $sql.= " AND f.type IN (0,1,2,3,5)";
881
+		}
776 882
         $sql.= " AND f.rowid = d.".$fk_facture;
777 883
         $sql.= " AND s.rowid = f.fk_soc";
778 884
         if ($y && $m)
779 885
         {
780 886
             $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
781 887
             $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
782
-        }
783
-        else if ($y)
888
+        } else if ($y)
784 889
         {
785 890
             $sql.= " AND f.datef >= '".$db->idate(dol_get_first_day($y,1,false))."'";
786 891
             $sql.= " AND f.datef <= '".$db->idate(dol_get_last_day($y,12,false))."'";
787 892
         }
788
-        if ($q) $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
789
-        if ($date_start && $date_end) $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
893
+        if ($q) {
894
+            $sql.= " AND (date_format(f.datef,'%m') > ".(($q-1)*3)." AND date_format(f.datef,'%m') <= ".($q*3).")";
895
+        }
896
+        if ($date_start && $date_end) {
897
+            $sql.= " AND f.datef >= '".$db->idate($date_start)."' AND f.datef <= '".$db->idate($date_end)."'";
898
+        }
790 899
         $sql.= " AND (d.product_type = 1";                              // Limit to services
791 900
         $sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)";       // enhance detection of service
792
-        if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
901
+        if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) {
902
+            $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
903
+        }
793 904
         $sql.= " ORDER BY d.rowid, d.".$fk_facture;
794
-    }
795
-    else
905
+    } else
796 906
     {
797 907
         // Count on payments date
798 908
         $sql = "SELECT d.rowid, d.product_type as dtype, d.".$fk_facture." as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.".$total_tva." as total_vat, d.description as descr,";
@@ -810,8 +920,11 @@  discard block
 block discarded – undo
810 920
         $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p on d.fk_product = p.rowid";
811 921
         $sql.= " WHERE f.entity = " . $conf->entity;
812 922
         $sql.= " AND f.fk_statut in (1,2)"; // Paid (partially or completely)
813
-        if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) $sql.= " AND f.type IN (0,1,2,5)";
814
-		else $sql.= " AND f.type IN (0,1,2,3,5)";
923
+        if (! empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS)) {
924
+            $sql.= " AND f.type IN (0,1,2,5)";
925
+        } else {
926
+		    $sql.= " AND f.type IN (0,1,2,3,5)";
927
+		}
815 928
         $sql.= " AND f.rowid = d.".$fk_facture;
816 929
         $sql.= " AND s.rowid = f.fk_soc";
817 930
         $sql.= " AND pf.".$fk_facture2." = f.rowid";
@@ -820,17 +933,22 @@  discard block
 block discarded – undo
820 933
         {
821 934
             $sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
822 935
             $sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
823
-        }
824
-        else if ($y)
936
+        } else if ($y)
825 937
         {
826 938
             $sql.= " AND pa.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
827 939
             $sql.= " AND pa.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
828 940
         }
829
-        if ($q) $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
830
-        if ($date_start && $date_end) $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
941
+        if ($q) {
942
+            $sql.= " AND (date_format(pa.datep,'%m') > ".(($q-1)*3)." AND date_format(pa.datep,'%m') <= ".($q*3).")";
943
+        }
944
+        if ($date_start && $date_end) {
945
+            $sql.= " AND pa.datep >= '".$db->idate($date_start)."' AND pa.datep <= '".$db->idate($date_end)."'";
946
+        }
831 947
         $sql.= " AND (d.product_type = 1";                              		// Limit to services
832 948
         $sql.= " OR d.date_start is NOT null OR d.date_end IS NOT NULL)";       // enhance detection of service
833
-        if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
949
+        if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) {
950
+            $sql.= " AND (d.".$f_rate." <> 0 OR d.".$total_tva." <> 0)";
951
+        }
834 952
         $sql.= " ORDER BY d.rowid, d.".$fk_facture.", pf.rowid";
835 953
     }
836 954
 
@@ -839,7 +957,10 @@  discard block
 block discarded – undo
839 957
         dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR);
840 958
         return -1;  // -1 = Not accountancy module enabled
841 959
     }
842
-    if ($sql == 'TODO') return -2; // -2 = Feature not yet available
960
+    if ($sql == 'TODO') {
961
+        return -2;
962
+    }
963
+    // -2 = Feature not yet available
843 964
     if ($sql != 'TODO')
844 965
     {
845 966
         dol_syslog("Tax.lib.php::tax_by_rate", LOG_DEBUG);
@@ -851,14 +972,24 @@  discard block
 block discarded – undo
851 972
             while($assoc = $db->fetch_array($resql))
852 973
             {
853 974
             	// Code to avoid warnings when array entry not defined
854
-            	if (! isset($list[$assoc['rate']]['totalht']))   $list[$assoc['rate']]['totalht']=0;
855
-                if (! isset($list[$assoc['rate']]['vat']))       $list[$assoc['rate']]['vat']=0;
856
-				if (! isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0;
857
-                if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=0;
975
+            	if (! isset($list[$assoc['rate']]['totalht'])) {
976
+            	    $list[$assoc['rate']]['totalht']=0;
977
+            	}
978
+                if (! isset($list[$assoc['rate']]['vat'])) {
979
+                    $list[$assoc['rate']]['vat']=0;
980
+                }
981
+				if (! isset($list[$assoc['rate']]['localtax1'])) {
982
+				    $list[$assoc['rate']]['localtax1']=0;
983
+				}
984
+                if (! isset($list[$assoc['rate']]['localtax2'])) {
985
+                    $list[$assoc['rate']]['localtax2']=0;
986
+                }
858 987
 
859
-                if ($assoc['rowid'] != $oldrowid)       // Si rupture sur d.rowid
988
+                if ($assoc['rowid'] != $oldrowid) {
989
+                    // Si rupture sur d.rowid
860 990
                 {
861 991
                     $oldrowid=$assoc['rowid'];
992
+                }
862 993
                     $list[$assoc['rate']]['totalht']   += $assoc['total_ht'];
863 994
                     $list[$assoc['rate']]['vat']       += $assoc['total_vat'];
864 995
                     $list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1'];
@@ -893,8 +1024,7 @@  discard block
 block discarded – undo
893 1024
 
894 1025
                 $rate = $assoc['rate'];
895 1026
             }
896
-        }
897
-        else
1027
+        } else
898 1028
         {
899 1029
             dol_print_error($db);
900 1030
             return -3;
@@ -904,10 +1034,12 @@  discard block
 block discarded – undo
904 1034
 
905 1035
     // CASE OF EXPENSE REPORT
906 1036
 
907
-	if ($direction == 'buy')		// buy only for expense reports
1037
+	if ($direction == 'buy') {
1038
+	    // buy only for expense reports
908 1039
 	{
909 1040
 		// Define sql request
910 1041
 		$sql='';
1042
+	}
911 1043
 
912 1044
 		// Count on payments date
913 1045
 		$sql = "SELECT d.rowid, d.product_type as dtype, e.rowid as facid, d.$f_rate as rate, d.total_ht as total_ht, d.total_ttc as total_ttc, d.total_tva as total_vat, e.note_private as descr,";
@@ -924,17 +1056,22 @@  discard block
 block discarded – undo
924 1056
 		{
925 1057
 			$sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,$m,false))."'";
926 1058
 			$sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,$m,false))."'";
927
-		}
928
-		else if ($y)
1059
+		} else if ($y)
929 1060
 		{
930 1061
 			$sql.= " AND p.datep >= '".$db->idate(dol_get_first_day($y,1,false))."'";
931 1062
 			$sql.= " AND p.datep <= '".$db->idate(dol_get_last_day($y,12,false))."'";
932 1063
 		}
933
-		if ($q) $sql.= " AND (date_format(p.datep,'%m') > ".(($q-1)*3)." AND date_format(p.datep,'%m') <= ".($q*3).")";
934
-		if ($date_start && $date_end) $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
1064
+		if ($q) {
1065
+		    $sql.= " AND (date_format(p.datep,'%m') > ".(($q-1)*3)." AND date_format(p.datep,'%m') <= ".($q*3).")";
1066
+		}
1067
+		if ($date_start && $date_end) {
1068
+		    $sql.= " AND p.datep >= '".$db->idate($date_start)."' AND p.datep <= '".$db->idate($date_end)."'";
1069
+		}
935 1070
 		$sql.= " AND (d.product_type = -1";
936 1071
 		$sql.= " OR e.date_debut is NOT null OR e.date_fin IS NOT NULL)";       // enhance detection of service
937
-		if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) $sql.= " AND (d.".$f_rate." <> 0 OR d.total_tva <> 0)";
1072
+		if (empty($conf->global->MAIN_INCLUDE_ZERO_VAT_IN_REPORTS)) {
1073
+		    $sql.= " AND (d.".$f_rate." <> 0 OR d.total_tva <> 0)";
1074
+		}
938 1075
 		$sql.= " ORDER BY e.rowid";
939 1076
 
940 1077
 		if (! $sql)
@@ -942,7 +1079,10 @@  discard block
 block discarded – undo
942 1079
 			dol_syslog("Tax.lib.php::tax_by_rate no accountancy module enabled".$sql,LOG_ERR);
943 1080
 			return -1;  // -1 = Not accountancy module enabled
944 1081
 		}
945
-		if ($sql == 'TODO') return -2; // -2 = Feature not yet available
1082
+		if ($sql == 'TODO') {
1083
+		    return -2;
1084
+		}
1085
+		// -2 = Feature not yet available
946 1086
 		if ($sql != 'TODO')
947 1087
 		{
948 1088
 			dol_syslog("Tax.lib.php::tax_by_rate", LOG_DEBUG);
@@ -954,14 +1094,24 @@  discard block
 block discarded – undo
954 1094
 				while($assoc = $db->fetch_array($resql))
955 1095
 				{
956 1096
 					// Code to avoid warnings when array entry not defined
957
-					if (! isset($list[$assoc['rate']]['totalht']))   $list[$assoc['rate']]['totalht']=0;
958
-					if (! isset($list[$assoc['rate']]['vat']))       $list[$assoc['rate']]['vat']=0;
959
-					if (! isset($list[$assoc['rate']]['localtax1'])) $list[$assoc['rate']]['localtax1']=0;
960
-					if (! isset($list[$assoc['rate']]['localtax2'])) $list[$assoc['rate']]['localtax2']=0;
1097
+					if (! isset($list[$assoc['rate']]['totalht'])) {
1098
+					    $list[$assoc['rate']]['totalht']=0;
1099
+					}
1100
+					if (! isset($list[$assoc['rate']]['vat'])) {
1101
+					    $list[$assoc['rate']]['vat']=0;
1102
+					}
1103
+					if (! isset($list[$assoc['rate']]['localtax1'])) {
1104
+					    $list[$assoc['rate']]['localtax1']=0;
1105
+					}
1106
+					if (! isset($list[$assoc['rate']]['localtax2'])) {
1107
+					    $list[$assoc['rate']]['localtax2']=0;
1108
+					}
961 1109
 
962
-					if ($assoc['rowid'] != $oldrowid)       // Si rupture sur d.rowid
1110
+					if ($assoc['rowid'] != $oldrowid) {
1111
+					    // Si rupture sur d.rowid
963 1112
 					{
964 1113
 						$oldrowid=$assoc['rowid'];
1114
+					}
965 1115
 						$list[$assoc['rate']]['totalht']   += $assoc['total_ht'];
966 1116
                         $list[$assoc['rate']]['vat']       += $assoc['total_vat'];
967 1117
 						$list[$assoc['rate']]['localtax1'] += $assoc['total_localtax1'];
@@ -997,8 +1147,7 @@  discard block
 block discarded – undo
997 1147
 
998 1148
 					$rate = $assoc['rate'];
999 1149
 				}
1000
-			}
1001
-			else
1150
+			} else
1002 1151
 			{
1003 1152
 				dol_print_error($db);
1004 1153
 				return -3;
Please login to merge, or discard this patch.
dolibarr/htdocs/core/lib/ajax.lib.php 3 patches
Indentation   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -55,11 +55,11 @@  discard block
 block discarded – undo
55 55
 
56 56
     // Input search_htmlname is original field
57 57
     // Input htmlname is a second input field used when using ajax autocomplete.
58
-	$script = '<input type="hidden" name="'.$htmlname.'" id="'.$htmlname.'" value="'.$selected.'" />';
58
+    $script = '<input type="hidden" name="'.$htmlname.'" id="'.$htmlname.'" value="'.$selected.'" />';
59 59
 
60
-	$script.= '<!-- Javascript code for autocomplete of field '.$htmlname.' -->'."\n";
61
-	$script.= '<script type="text/javascript">'."\n";
62
-	$script.= '$(document).ready(function() {
60
+    $script.= '<!-- Javascript code for autocomplete of field '.$htmlname.' -->'."\n";
61
+    $script.= '<script type="text/javascript">'."\n";
62
+    $script.= '$(document).ready(function() {
63 63
 					var autoselect = '.$autoselect.';
64 64
 					var options = '.json_encode($ajaxoptions).';
65 65
 
@@ -202,9 +202,9 @@  discard block
 block discarded – undo
202 202
 					};
203 203
 
204 204
   				});';
205
-	$script.= '</script>';
205
+    $script.= '</script>';
206 206
 
207
-	return $script;
207
+    return $script;
208 208
 }
209 209
 
210 210
 /**
@@ -223,9 +223,9 @@  discard block
 block discarded – undo
223 223
  */
224 224
 function ajax_multiautocompleter($htmlname, $fields, $url, $option='', $minLength=2, $autoselect=0)
225 225
 {
226
-	$script = '<!-- Autocomplete -->'."\n";
227
-	$script.= '<script type="text/javascript">';
228
-	$script.= 'jQuery(document).ready(function() {
226
+    $script = '<!-- Autocomplete -->'."\n";
227
+    $script.= '<script type="text/javascript">';
228
+    $script.= 'jQuery(document).ready(function() {
229 229
 					var fields = '.json_encode($fields).';
230 230
 					var nboffields = fields.length;
231 231
 					var autoselect = '.$autoselect.';
@@ -314,9 +314,9 @@  discard block
 block discarded – undo
314 314
     					}
315 315
 					});
316 316
   				});';
317
-	$script.= '</script>';
317
+    $script.= '</script>';
318 318
 
319
-	return $script;
319
+    return $script;
320 320
 }
321 321
 
322 322
 /**
@@ -330,12 +330,12 @@  discard block
 block discarded – undo
330 330
  */
331 331
 function ajax_dialog($title,$message,$w=350,$h=150)
332 332
 {
333
-	global $langs;
333
+    global $langs;
334 334
 
335
-	$newtitle=dol_textishtml($title)?dol_string_nohtmltag($title,1):$title;
336
-	$msg= '<div id="dialog-info" title="'.dol_escape_htmltag($newtitle).'">';
337
-	$msg.= $message;
338
-	$msg.= '</div>'."\n";
335
+    $newtitle=dol_textishtml($title)?dol_string_nohtmltag($title,1):$title;
336
+    $msg= '<div id="dialog-info" title="'.dol_escape_htmltag($newtitle).'">';
337
+    $msg.= $message;
338
+    $msg.= '</div>'."\n";
339 339
     $msg.= '<script type="text/javascript">
340 340
     jQuery(function() {
341 341
         jQuery("#dialog-info").dialog({
@@ -373,17 +373,17 @@  discard block
 block discarded – undo
373 373
  */
374 374
 function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve')
375 375
 {
376
-	global $conf;
376
+    global $conf;
377 377
 
378
-	// select2 disabled for smartphones with standard browser.
379
-	// TODO With select2 v4, it seems ok, except that responsive style on table become crazy when scrolling at end of array)
380
-	if (! empty($conf->browser->layout) && $conf->browser->layout == 'phone') return '';
378
+    // select2 disabled for smartphones with standard browser.
379
+    // TODO With select2 v4, it seems ok, except that responsive style on table become crazy when scrolling at end of array)
380
+    if (! empty($conf->browser->layout) && $conf->browser->layout == 'phone') return '';
381 381
 
382
-	if (! empty($conf->global->MAIN_DISABLE_AJAX_COMBOX)) return '';
383
-	if (empty($conf->use_javascript_ajax)) return '';
384
-	if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && ! defined('REQUIRE_JQUERY_MULTISELECT')) return '';
382
+    if (! empty($conf->global->MAIN_DISABLE_AJAX_COMBOX)) return '';
383
+    if (empty($conf->use_javascript_ajax)) return '';
384
+    if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && ! defined('REQUIRE_JQUERY_MULTISELECT')) return '';
385 385
 
386
-	if (empty($minLengthToAutocomplete)) $minLengthToAutocomplete=0;
386
+    if (empty($minLengthToAutocomplete)) $minLengthToAutocomplete=0;
387 387
 
388 388
     $tmpplugin='select2';
389 389
     $msg="\n".'<!-- JS CODE TO ENABLE '.$tmpplugin.' for id = '.$htmlname.' -->
@@ -410,12 +410,12 @@  discard block
 block discarded – undo
410 410
 					},
411 411
 					dropdownCssClass: \'ui-dialog\'
412 412
 				})';
413
-	if ($forcefocus) $msg.= '.select2(\'focus\')';
414
-	$msg.= ';'."\n";
413
+    if ($forcefocus) $msg.= '.select2(\'focus\')';
414
+    $msg.= ';'."\n";
415 415
 
416
-	if (is_array($events) && count($events))    // If an array of js events to do were provided.
417
-	{
418
-		$msg.= '
416
+    if (is_array($events) && count($events))    // If an array of js events to do were provided.
417
+    {
418
+        $msg.= '
419 419
 			jQuery("#'.$htmlname.'").change(function () {
420 420
 				var obj = '.json_encode($events).';
421 421
 		   		$.each(obj, function(key,values) {
@@ -462,9 +462,9 @@  discard block
 block discarded – undo
462 462
 						}
463 463
 				);
464 464
 			}';
465
-	}
465
+    }
466 466
 
467
-	$msg.= '});'."\n";
467
+    $msg.= '});'."\n";
468 468
     $msg.= "</script>\n";
469 469
 
470 470
     return $msg;
@@ -482,18 +482,18 @@  discard block
 block discarded – undo
482 482
  */
483 483
 function ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0)
484 484
 {
485
-	global $conf, $langs;
486
-
487
-	$entity = ((isset($entity) && is_numeric($entity) && $entity >= 0) ? $entity : $conf->entity);
488
-
489
-	if (empty($conf->use_javascript_ajax))
490
-	{
491
-		if (empty($conf->global->$code)) print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_'.$code.'&entity='.$entity.'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
492
-		else print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_'.$code.'&entity='.$entity.'">'.img_picto($langs->trans("Enabled"),'on').'</a>';
493
-	}
494
-	else
495
-	{
496
-		$out= "\n<!-- Ajax code to switch constant ".$code." -->".'
485
+    global $conf, $langs;
486
+
487
+    $entity = ((isset($entity) && is_numeric($entity) && $entity >= 0) ? $entity : $conf->entity);
488
+
489
+    if (empty($conf->use_javascript_ajax))
490
+    {
491
+        if (empty($conf->global->$code)) print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_'.$code.'&entity='.$entity.'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
492
+        else print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_'.$code.'&entity='.$entity.'">'.img_picto($langs->trans("Enabled"),'on').'</a>';
493
+    }
494
+    else
495
+    {
496
+        $out= "\n<!-- Ajax code to switch constant ".$code." -->".'
497 497
 		<script type="text/javascript">
498 498
 			$(document).ready(function() {
499 499
 				var input = '.json_encode($input).';
@@ -528,13 +528,13 @@  discard block
 block discarded – undo
528 528
 			});
529 529
 		</script>'."\n";
530 530
 
531
-		$out.= '<div id="confirm_'.$code.'" title="" style="display: none;"></div>';
532
-		$out.= '<span id="set_'.$code.'" class="linkobject '.(! empty($conf->global->$code)?'hideobject':'').'">'.($revertonoff?img_picto($langs->trans("Enabled"),'switch_on'):img_picto($langs->trans("Disabled"),'switch_off')).'</span>';
533
-		$out.= '<span id="del_'.$code.'" class="linkobject '.(! empty($conf->global->$code)?'':'hideobject').'">'.($revertonoff?img_picto($langs->trans("Disabled"),'switch_off'):img_picto($langs->trans("Enabled"),'switch_on')).'</span>';
534
-		$out.="\n";
535
-	}
531
+        $out.= '<div id="confirm_'.$code.'" title="" style="display: none;"></div>';
532
+        $out.= '<span id="set_'.$code.'" class="linkobject '.(! empty($conf->global->$code)?'hideobject':'').'">'.($revertonoff?img_picto($langs->trans("Enabled"),'switch_on'):img_picto($langs->trans("Disabled"),'switch_off')).'</span>';
533
+        $out.= '<span id="del_'.$code.'" class="linkobject '.(! empty($conf->global->$code)?'':'hideobject').'">'.($revertonoff?img_picto($langs->trans("Disabled"),'switch_off'):img_picto($langs->trans("Enabled"),'switch_on')).'</span>';
534
+        $out.="\n";
535
+    }
536 536
 
537
-	return $out;
537
+    return $out;
538 538
 }
539 539
 
540 540
 /**
Please login to merge, or discard this patch.
Spacing   +49 added lines, -49 removed lines patch added patch discarded remove patch
@@ -43,23 +43,23 @@  discard block
 block discarded – undo
43 43
  *                                      - Ex: array('option_disabled'=> id to disable and warning to show if we select a disabled value (this is possible when using autocomplete ajax)
44 44
  *	@return string              		Script
45 45
  */
46
-function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLength=2, $autoselect=0, $ajaxoptions=array())
46
+function ajax_autocompleter($selected, $htmlname, $url, $urloption = '', $minLength = 2, $autoselect = 0, $ajaxoptions = array())
47 47
 {
48
-    if (empty($minLength)) $minLength=1;
48
+    if (empty($minLength)) $minLength = 1;
49 49
 
50
-    $dataforrenderITem='ui-autocomplete';
51
-    $dataforitem='ui-autocomplete-item';
50
+    $dataforrenderITem = 'ui-autocomplete';
51
+    $dataforitem = 'ui-autocomplete-item';
52 52
     // Allow two constant to use other values for backward compatibility
53
-    if (defined('JS_QUERY_AUTOCOMPLETE_RENDERITEM')) $dataforrenderITem=constant('JS_QUERY_AUTOCOMPLETE_RENDERITEM');
54
-    if (defined('JS_QUERY_AUTOCOMPLETE_ITEM'))       $dataforitem=constant('JS_QUERY_AUTOCOMPLETE_ITEM');
53
+    if (defined('JS_QUERY_AUTOCOMPLETE_RENDERITEM')) $dataforrenderITem = constant('JS_QUERY_AUTOCOMPLETE_RENDERITEM');
54
+    if (defined('JS_QUERY_AUTOCOMPLETE_ITEM'))       $dataforitem = constant('JS_QUERY_AUTOCOMPLETE_ITEM');
55 55
 
56 56
     // Input search_htmlname is original field
57 57
     // Input htmlname is a second input field used when using ajax autocomplete.
58 58
 	$script = '<input type="hidden" name="'.$htmlname.'" id="'.$htmlname.'" value="'.$selected.'" />';
59 59
 
60
-	$script.= '<!-- Javascript code for autocomplete of field '.$htmlname.' -->'."\n";
61
-	$script.= '<script type="text/javascript">'."\n";
62
-	$script.= '$(document).ready(function() {
60
+	$script .= '<!-- Javascript code for autocomplete of field '.$htmlname.' -->'."\n";
61
+	$script .= '<script type="text/javascript">'."\n";
62
+	$script .= '$(document).ready(function() {
63 63
 					var autoselect = '.$autoselect.';
64 64
 					var options = '.json_encode($ajaxoptions).';
65 65
 
@@ -109,7 +109,7 @@  discard block
 block discarded – undo
109 109
                     });
110 110
     				$("input#search_'.$htmlname.'").autocomplete({
111 111
     					source: function( request, response ) {
112
-    						$.get("'.$url.($urloption?'?'.$urloption:'').'", { '.$htmlname.': request.term }, function(data){
112
+    						$.get("'.$url.($urloption ? '?'.$urloption : '').'", { '.$htmlname.': request.term }, function(data){
113 113
 								if (data != null)
114 114
 								{
115 115
 									response($.map( data, function(item) {
@@ -133,7 +133,7 @@  discard block
 block discarded – undo
133 133
 										return { label: label, value: item.value, id: item.key, update: update, textarea: textarea, disabled: item.disabled }
134 134
 									}));
135 135
 								}
136
-								else console.error("Error: Ajax url '.$url.($urloption?'?'.$urloption:'').' has returned an empty page. Should be an empty json array.");
136
+								else console.error("Error: Ajax url '.$url.($urloption ? '?'.$urloption : '').' has returned an empty page. Should be an empty json array.");
137 137
 							}, "json");
138 138
 						},
139 139
 						dataType: "json",
@@ -202,7 +202,7 @@  discard block
 block discarded – undo
202 202
 					};
203 203
 
204 204
   				});';
205
-	$script.= '</script>';
205
+	$script .= '</script>';
206 206
 
207 207
 	return $script;
208 208
 }
@@ -221,11 +221,11 @@  discard block
 block discarded – undo
221 221
  *	@param	int		$autoselect			Automatic selection if just one value
222 222
  *	@return string              		Script
223 223
  */
224
-function ajax_multiautocompleter($htmlname, $fields, $url, $option='', $minLength=2, $autoselect=0)
224
+function ajax_multiautocompleter($htmlname, $fields, $url, $option = '', $minLength = 2, $autoselect = 0)
225 225
 {
226 226
 	$script = '<!-- Autocomplete -->'."\n";
227
-	$script.= '<script type="text/javascript">';
228
-	$script.= 'jQuery(document).ready(function() {
227
+	$script .= '<script type="text/javascript">';
228
+	$script .= 'jQuery(document).ready(function() {
229 229
 					var fields = '.json_encode($fields).';
230 230
 					var nboffields = fields.length;
231 231
 					var autoselect = '.$autoselect.';
@@ -235,7 +235,7 @@  discard block
 block discarded – undo
235 235
     					dataType: "json",
236 236
     					minLength: '.$minLength.',
237 237
     					source: function( request, response ) {
238
-    						jQuery.getJSON( "'.$url.($option?'?'.$option:'').'", { '.$htmlname.': request.term }, function(data){
238
+    						jQuery.getJSON( "'.$url.($option ? '?'.$option : '').'", { '.$htmlname.': request.term }, function(data){
239 239
 								response( jQuery.map( data, function( item ) {
240 240
 									if (autoselect == 1 && data.length == 1) {
241 241
 										jQuery("#'.$htmlname.'").val(item.value);
@@ -314,7 +314,7 @@  discard block
 block discarded – undo
314 314
     					}
315 315
 					});
316 316
   				});';
317
-	$script.= '</script>';
317
+	$script .= '</script>';
318 318
 
319 319
 	return $script;
320 320
 }
@@ -328,15 +328,15 @@  discard block
 block discarded – undo
328 328
  *	@param	int		$h			height of dialog box
329 329
  *	@return	void
330 330
  */
331
-function ajax_dialog($title,$message,$w=350,$h=150)
331
+function ajax_dialog($title, $message, $w = 350, $h = 150)
332 332
 {
333 333
 	global $langs;
334 334
 
335
-	$newtitle=dol_textishtml($title)?dol_string_nohtmltag($title,1):$title;
336
-	$msg= '<div id="dialog-info" title="'.dol_escape_htmltag($newtitle).'">';
337
-	$msg.= $message;
338
-	$msg.= '</div>'."\n";
339
-    $msg.= '<script type="text/javascript">
335
+	$newtitle = dol_textishtml($title) ?dol_string_nohtmltag($title, 1) : $title;
336
+	$msg = '<div id="dialog-info" title="'.dol_escape_htmltag($newtitle).'">';
337
+	$msg .= $message;
338
+	$msg .= '</div>'."\n";
339
+    $msg .= '<script type="text/javascript">
340 340
     jQuery(function() {
341 341
         jQuery("#dialog-info").dialog({
342 342
 	        resizable: false,
@@ -352,7 +352,7 @@  discard block
 block discarded – undo
352 352
 	});
353 353
 	</script>';
354 354
 
355
-    $msg.= "\n";
355
+    $msg .= "\n";
356 356
 
357 357
     return $msg;
358 358
 }
@@ -371,25 +371,25 @@  discard block
 block discarded – undo
371 371
  * @return	string								Return html string to convert a select field into a combo, or '' if feature has been disabled for some reason.
372 372
  * @see selectArrayAjax of html.form.class
373 373
  */
374
-function ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve')
374
+function ajax_combobox($htmlname, $events = array(), $minLengthToAutocomplete = 0, $forcefocus = 0, $widthTypeOfAutocomplete = 'resolve')
375 375
 {
376 376
 	global $conf;
377 377
 
378 378
 	// select2 disabled for smartphones with standard browser.
379 379
 	// TODO With select2 v4, it seems ok, except that responsive style on table become crazy when scrolling at end of array)
380
-	if (! empty($conf->browser->layout) && $conf->browser->layout == 'phone') return '';
380
+	if (!empty($conf->browser->layout) && $conf->browser->layout == 'phone') return '';
381 381
 
382
-	if (! empty($conf->global->MAIN_DISABLE_AJAX_COMBOX)) return '';
382
+	if (!empty($conf->global->MAIN_DISABLE_AJAX_COMBOX)) return '';
383 383
 	if (empty($conf->use_javascript_ajax)) return '';
384
-	if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && ! defined('REQUIRE_JQUERY_MULTISELECT')) return '';
384
+	if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && !defined('REQUIRE_JQUERY_MULTISELECT')) return '';
385 385
 
386
-	if (empty($minLengthToAutocomplete)) $minLengthToAutocomplete=0;
386
+	if (empty($minLengthToAutocomplete)) $minLengthToAutocomplete = 0;
387 387
 
388
-    $tmpplugin='select2';
389
-    $msg="\n".'<!-- JS CODE TO ENABLE '.$tmpplugin.' for id = '.$htmlname.' -->
388
+    $tmpplugin = 'select2';
389
+    $msg = "\n".'<!-- JS CODE TO ENABLE '.$tmpplugin.' for id = '.$htmlname.' -->
390 390
           <script type="text/javascript">
391 391
         	$(document).ready(function () {
392
-        		$(\''.(preg_match('/^\./',$htmlname)?$htmlname:'#'.$htmlname).'\').'.$tmpplugin.'({
392
+        		$(\''.(preg_match('/^\./', $htmlname) ? $htmlname : '#'.$htmlname).'\').'.$tmpplugin.'({
393 393
         		    dir: \'ltr\',
394 394
         			width: \''.$widthTypeOfAutocomplete.'\',		/* off or resolve */
395 395
 					minimumInputLength: '.$minLengthToAutocomplete.',
@@ -410,12 +410,12 @@  discard block
 block discarded – undo
410 410
 					},
411 411
 					dropdownCssClass: \'ui-dialog\'
412 412
 				})';
413
-	if ($forcefocus) $msg.= '.select2(\'focus\')';
414
-	$msg.= ';'."\n";
413
+	if ($forcefocus) $msg .= '.select2(\'focus\')';
414
+	$msg .= ';'."\n";
415 415
 
416 416
 	if (is_array($events) && count($events))    // If an array of js events to do were provided.
417 417
 	{
418
-		$msg.= '
418
+		$msg .= '
419 419
 			jQuery("#'.$htmlname.'").change(function () {
420 420
 				var obj = '.json_encode($events).';
421 421
 		   		$.each(obj, function(key,values) {
@@ -464,8 +464,8 @@  discard block
 block discarded – undo
464 464
 			}';
465 465
 	}
466 466
 
467
-	$msg.= '});'."\n";
468
-    $msg.= "</script>\n";
467
+	$msg .= '});'."\n";
468
+    $msg .= "</script>\n";
469 469
 
470 470
     return $msg;
471 471
 }
@@ -480,7 +480,7 @@  discard block
 block discarded – undo
480 480
  *  @param	bool	$strict			Use only "disabled" with delConstant and "enabled" with setConstant
481 481
  * 	@return	string
482 482
  */
483
-function ajax_constantonoff($code, $input=array(), $entity=null, $revertonoff=0, $strict=0)
483
+function ajax_constantonoff($code, $input = array(), $entity = null, $revertonoff = 0, $strict = 0)
484 484
 {
485 485
 	global $conf, $langs;
486 486
 
@@ -488,12 +488,12 @@  discard block
 block discarded – undo
488 488
 
489 489
 	if (empty($conf->use_javascript_ajax))
490 490
 	{
491
-		if (empty($conf->global->$code)) print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_'.$code.'&entity='.$entity.'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
492
-		else print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_'.$code.'&entity='.$entity.'">'.img_picto($langs->trans("Enabled"),'on').'</a>';
491
+		if (empty($conf->global->$code)) print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_'.$code.'&entity='.$entity.'">'.img_picto($langs->trans("Disabled"), 'off').'</a>';
492
+		else print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_'.$code.'&entity='.$entity.'">'.img_picto($langs->trans("Enabled"), 'on').'</a>';
493 493
 	}
494 494
 	else
495 495
 	{
496
-		$out= "\n<!-- Ajax code to switch constant ".$code." -->".'
496
+		$out = "\n<!-- Ajax code to switch constant ".$code." -->".'
497 497
 		<script type="text/javascript">
498 498
 			$(document).ready(function() {
499 499
 				var input = '.json_encode($input).';
@@ -528,10 +528,10 @@  discard block
 block discarded – undo
528 528
 			});
529 529
 		</script>'."\n";
530 530
 
531
-		$out.= '<div id="confirm_'.$code.'" title="" style="display: none;"></div>';
532
-		$out.= '<span id="set_'.$code.'" class="linkobject '.(! empty($conf->global->$code)?'hideobject':'').'">'.($revertonoff?img_picto($langs->trans("Enabled"),'switch_on'):img_picto($langs->trans("Disabled"),'switch_off')).'</span>';
533
-		$out.= '<span id="del_'.$code.'" class="linkobject '.(! empty($conf->global->$code)?'':'hideobject').'">'.($revertonoff?img_picto($langs->trans("Disabled"),'switch_off'):img_picto($langs->trans("Enabled"),'switch_on')).'</span>';
534
-		$out.="\n";
531
+		$out .= '<div id="confirm_'.$code.'" title="" style="display: none;"></div>';
532
+		$out .= '<span id="set_'.$code.'" class="linkobject '.(!empty($conf->global->$code) ? 'hideobject' : '').'">'.($revertonoff ?img_picto($langs->trans("Enabled"), 'switch_on') : img_picto($langs->trans("Disabled"), 'switch_off')).'</span>';
533
+		$out .= '<span id="del_'.$code.'" class="linkobject '.(!empty($conf->global->$code) ? '' : 'hideobject').'">'.($revertonoff ?img_picto($langs->trans("Disabled"), 'switch_off') : img_picto($langs->trans("Enabled"), 'switch_on')).'</span>';
534
+		$out .= "\n";
535 535
 	}
536 536
 
537 537
 	return $out;
@@ -548,11 +548,11 @@  discard block
 block discarded – undo
548 548
  *  @param  array   $input      Array of type->list of CSS element to switch. Example: array('disabled'=>array(0=>'cssid'))
549 549
  *  @return string              html for button on/off
550 550
  */
551
-function ajax_object_onoff($object, $code, $field, $text_on, $text_off, $input=array())
551
+function ajax_object_onoff($object, $code, $field, $text_on, $text_off, $input = array())
552 552
 {
553 553
     global $langs;
554 554
 
555
-    $out= '<script type="text/javascript">
555
+    $out = '<script type="text/javascript">
556 556
         $(function() {
557 557
             var input = '.json_encode($input).';
558 558
 
@@ -617,8 +617,8 @@  discard block
 block discarded – undo
617 617
             });
618 618
         });
619 619
     </script>';
620
-    $out.= '<span id="set_'.$code.'_'.$object->id.'" class="linkobject '.($object->$code==1?'hideobject':'').'">'.img_picto($langs->trans($text_off),'switch_off').'</span>';
621
-    $out.= '<span id="del_'.$code.'_'.$object->id.'" class="linkobject '.($object->$code==1?'':'hideobject').'">'.img_picto($langs->trans($text_on),'switch_on').'</span>';
620
+    $out .= '<span id="set_'.$code.'_'.$object->id.'" class="linkobject '.($object->$code == 1 ? 'hideobject' : '').'">'.img_picto($langs->trans($text_off), 'switch_off').'</span>';
621
+    $out .= '<span id="del_'.$code.'_'.$object->id.'" class="linkobject '.($object->$code == 1 ? '' : 'hideobject').'">'.img_picto($langs->trans($text_on), 'switch_on').'</span>';
622 622
 
623 623
     return $out;
624 624
 }
Please login to merge, or discard this patch.
Braces   +36 added lines, -14 removed lines patch added patch discarded remove patch
@@ -45,13 +45,19 @@  discard block
 block discarded – undo
45 45
  */
46 46
 function ajax_autocompleter($selected, $htmlname, $url, $urloption='', $minLength=2, $autoselect=0, $ajaxoptions=array())
47 47
 {
48
-    if (empty($minLength)) $minLength=1;
48
+    if (empty($minLength)) {
49
+        $minLength=1;
50
+    }
49 51
 
50 52
     $dataforrenderITem='ui-autocomplete';
51 53
     $dataforitem='ui-autocomplete-item';
52 54
     // Allow two constant to use other values for backward compatibility
53
-    if (defined('JS_QUERY_AUTOCOMPLETE_RENDERITEM')) $dataforrenderITem=constant('JS_QUERY_AUTOCOMPLETE_RENDERITEM');
54
-    if (defined('JS_QUERY_AUTOCOMPLETE_ITEM'))       $dataforitem=constant('JS_QUERY_AUTOCOMPLETE_ITEM');
55
+    if (defined('JS_QUERY_AUTOCOMPLETE_RENDERITEM')) {
56
+        $dataforrenderITem=constant('JS_QUERY_AUTOCOMPLETE_RENDERITEM');
57
+    }
58
+    if (defined('JS_QUERY_AUTOCOMPLETE_ITEM')) {
59
+        $dataforitem=constant('JS_QUERY_AUTOCOMPLETE_ITEM');
60
+    }
55 61
 
56 62
     // Input search_htmlname is original field
57 63
     // Input htmlname is a second input field used when using ajax autocomplete.
@@ -377,13 +383,23 @@  discard block
 block discarded – undo
377 383
 
378 384
 	// select2 disabled for smartphones with standard browser.
379 385
 	// TODO With select2 v4, it seems ok, except that responsive style on table become crazy when scrolling at end of array)
380
-	if (! empty($conf->browser->layout) && $conf->browser->layout == 'phone') return '';
386
+	if (! empty($conf->browser->layout) && $conf->browser->layout == 'phone') {
387
+	    return '';
388
+	}
381 389
 
382
-	if (! empty($conf->global->MAIN_DISABLE_AJAX_COMBOX)) return '';
383
-	if (empty($conf->use_javascript_ajax)) return '';
384
-	if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && ! defined('REQUIRE_JQUERY_MULTISELECT')) return '';
390
+	if (! empty($conf->global->MAIN_DISABLE_AJAX_COMBOX)) {
391
+	    return '';
392
+	}
393
+	if (empty($conf->use_javascript_ajax)) {
394
+	    return '';
395
+	}
396
+	if (empty($conf->global->MAIN_USE_JQUERY_MULTISELECT) && ! defined('REQUIRE_JQUERY_MULTISELECT')) {
397
+	    return '';
398
+	}
385 399
 
386
-	if (empty($minLengthToAutocomplete)) $minLengthToAutocomplete=0;
400
+	if (empty($minLengthToAutocomplete)) {
401
+	    $minLengthToAutocomplete=0;
402
+	}
387 403
 
388 404
     $tmpplugin='select2';
389 405
     $msg="\n".'<!-- JS CODE TO ENABLE '.$tmpplugin.' for id = '.$htmlname.' -->
@@ -410,10 +426,13 @@  discard block
 block discarded – undo
410 426
 					},
411 427
 					dropdownCssClass: \'ui-dialog\'
412 428
 				})';
413
-	if ($forcefocus) $msg.= '.select2(\'focus\')';
429
+	if ($forcefocus) {
430
+	    $msg.= '.select2(\'focus\')';
431
+	}
414 432
 	$msg.= ';'."\n";
415 433
 
416
-	if (is_array($events) && count($events))    // If an array of js events to do were provided.
434
+	if (is_array($events) && count($events)) {
435
+	    // If an array of js events to do were provided.
417 436
 	{
418 437
 		$msg.= '
419 438
 			jQuery("#'.$htmlname.'").change(function () {
@@ -463,6 +482,7 @@  discard block
 block discarded – undo
463 482
 				);
464 483
 			}';
465 484
 	}
485
+	}
466 486
 
467 487
 	$msg.= '});'."\n";
468 488
     $msg.= "</script>\n";
@@ -488,10 +508,12 @@  discard block
 block discarded – undo
488 508
 
489 509
 	if (empty($conf->use_javascript_ajax))
490 510
 	{
491
-		if (empty($conf->global->$code)) print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_'.$code.'&entity='.$entity.'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
492
-		else print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_'.$code.'&entity='.$entity.'">'.img_picto($langs->trans("Enabled"),'on').'</a>';
493
-	}
494
-	else
511
+		if (empty($conf->global->$code)) {
512
+		    print '<a href="'.$_SERVER['PHP_SELF'].'?action=set_'.$code.'&entity='.$entity.'">'.img_picto($langs->trans("Disabled"),'off').'</a>';
513
+		} else {
514
+		    print '<a href="'.$_SERVER['PHP_SELF'].'?action=del_'.$code.'&entity='.$entity.'">'.img_picto($langs->trans("Enabled"),'on').'</a>';
515
+		}
516
+	} else
495 517
 	{
496 518
 		$out= "\n<!-- Ajax code to switch constant ".$code." -->".'
497 519
 		<script type="text/javascript">
Please login to merge, or discard this patch.
dolibarr/htdocs/core/lib/invoice2.lib.php 3 patches
Indentation   +203 added lines, -203 removed lines patch added patch discarded remove patch
@@ -50,234 +50,234 @@
 block discarded – undo
50 50
  */
51 51
 function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, $usestdout, $regenerate=0, $filesuffix='', $paymentbankid='', $thirdpartiesid='', $fileprefix='mergedpdf')
52 52
 {
53
-	$sql = "SELECT DISTINCT f.rowid, f.ref";
54
-	$sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
55
-	$sqlwhere='';
56
-	$sqlorder='';
57
-	if (in_array('all',$filter))
58
-	{
59
-		$sqlorder = " ORDER BY f.ref ASC";
60
-	}
61
-	if (in_array('date',$filter))
62
-	{
63
-		if (empty($sqlwhere)) $sqlwhere=' WHERE ';
64
-		else $sqlwhere.=" AND";
65
-		$sqlwhere.= " f.fk_statut > 0";
66
-		$sqlwhere.= " AND f.datef >= '".$db->idate($dateafterdate)."'";
67
-		$sqlwhere.= " AND f.datef <= '".$db->idate($datebeforedate)."'";
68
-		$sqlorder = " ORDER BY f.datef ASC";
69
-	}
70
-	if (in_array('nopayment',$filter))
71
-	{
72
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
73
-		if (empty($sqlwhere)) $sqlwhere=' WHERE ';
74
-		else $sqlwhere.=" AND";
75
-		$sqlwhere.= " f.fk_statut > 0";
76
-		$sqlwhere.= " AND pf.fk_paiement IS NULL";
77
-	}
78
-	if (in_array('payments',$filter) || in_array('bank',$filter))
79
-	{
80
-		$sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
81
-		if (in_array('bank',$filter)) $sql.= ", ".MAIN_DB_PREFIX."bank as b";
82
-		if (empty($sqlwhere)) $sqlwhere=' WHERE ';
83
-		else $sqlwhere.=" AND";
84
-		$sqlwhere.= " f.fk_statut > 0";
85
-		$sqlwhere.= " AND f.rowid = pf.fk_facture";
86
-		$sqlwhere.= " AND pf.fk_paiement = p.rowid";
87
-		if (in_array('payments',$filter))
88
-		{
89
-			$sqlwhere.= " AND p.datep >= '".$db->idate($paymentdateafter)."'";
90
-			$sqlwhere.= " AND p.datep <= '".$db->idate($paymentdatebefore)."'";
91
-		}
92
-		if (in_array('bank',$filter))
93
-		{
94
-			$sqlwhere.= " AND p.fk_bank = b.rowid";
95
-			$sqlwhere.= " AND b.fk_account = ".$paymentbankid;
96
-		}
97
-		$sqlorder = " ORDER BY p.datep ASC";
98
-	}
99
-	if (in_array('nodeposit',$filter))
100
-	{
101
-	    if (empty($sqlwhere)) $sqlwhere=' WHERE ';
102
-	    else $sqlwhere.=" AND";
103
-	    $sqlwhere.=' type <> 3';
104
-	}
105
-	if (in_array('noreplacement',$filter))
106
-	{
107
-	    if (empty($sqlwhere)) $sqlwhere=' WHERE ';
108
-	    else $sqlwhere.=" AND";
109
-	    $sqlwhere.=' type <> 1';
110
-	}
111
-	if (in_array('nocreditnote',$filter))
112
-	{
113
-	    if (empty($sqlwhere)) $sqlwhere=' WHERE ';
114
-	    else $sqlwhere.=" AND";
115
-	    $sqlwhere.=' type <> 2';
116
-	}
117
-	if (in_array('excludethirdparties',$filter) && is_array($thirdpartiesid))
118
-	{
119
-	    if (empty($sqlwhere)) $sqlwhere=' WHERE ';
120
-	    else $sqlwhere.=" AND";
121
-	    $sqlwhere.=' f.fk_soc NOT IN ('.join(',',$thirdpartiesid).')';
122
-	}
123
-	if (in_array('onlythirdparties',$filter) && is_array($thirdpartiesid))
124
-	{
125
-	    if (empty($sqlwhere)) $sqlwhere=' WHERE ';
126
-	    else $sqlwhere.=" AND";
127
-	    $sqlwhere.=' f.fk_soc IN ('.join(',',$thirdpartiesid).')';
128
-	}
129
-	if ($sqlwhere) $sql.=$sqlwhere;
130
-	if ($sqlorder) $sql.=$sqlorder;
53
+    $sql = "SELECT DISTINCT f.rowid, f.ref";
54
+    $sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
55
+    $sqlwhere='';
56
+    $sqlorder='';
57
+    if (in_array('all',$filter))
58
+    {
59
+        $sqlorder = " ORDER BY f.ref ASC";
60
+    }
61
+    if (in_array('date',$filter))
62
+    {
63
+        if (empty($sqlwhere)) $sqlwhere=' WHERE ';
64
+        else $sqlwhere.=" AND";
65
+        $sqlwhere.= " f.fk_statut > 0";
66
+        $sqlwhere.= " AND f.datef >= '".$db->idate($dateafterdate)."'";
67
+        $sqlwhere.= " AND f.datef <= '".$db->idate($datebeforedate)."'";
68
+        $sqlorder = " ORDER BY f.datef ASC";
69
+    }
70
+    if (in_array('nopayment',$filter))
71
+    {
72
+        $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
73
+        if (empty($sqlwhere)) $sqlwhere=' WHERE ';
74
+        else $sqlwhere.=" AND";
75
+        $sqlwhere.= " f.fk_statut > 0";
76
+        $sqlwhere.= " AND pf.fk_paiement IS NULL";
77
+    }
78
+    if (in_array('payments',$filter) || in_array('bank',$filter))
79
+    {
80
+        $sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
81
+        if (in_array('bank',$filter)) $sql.= ", ".MAIN_DB_PREFIX."bank as b";
82
+        if (empty($sqlwhere)) $sqlwhere=' WHERE ';
83
+        else $sqlwhere.=" AND";
84
+        $sqlwhere.= " f.fk_statut > 0";
85
+        $sqlwhere.= " AND f.rowid = pf.fk_facture";
86
+        $sqlwhere.= " AND pf.fk_paiement = p.rowid";
87
+        if (in_array('payments',$filter))
88
+        {
89
+            $sqlwhere.= " AND p.datep >= '".$db->idate($paymentdateafter)."'";
90
+            $sqlwhere.= " AND p.datep <= '".$db->idate($paymentdatebefore)."'";
91
+        }
92
+        if (in_array('bank',$filter))
93
+        {
94
+            $sqlwhere.= " AND p.fk_bank = b.rowid";
95
+            $sqlwhere.= " AND b.fk_account = ".$paymentbankid;
96
+        }
97
+        $sqlorder = " ORDER BY p.datep ASC";
98
+    }
99
+    if (in_array('nodeposit',$filter))
100
+    {
101
+        if (empty($sqlwhere)) $sqlwhere=' WHERE ';
102
+        else $sqlwhere.=" AND";
103
+        $sqlwhere.=' type <> 3';
104
+    }
105
+    if (in_array('noreplacement',$filter))
106
+    {
107
+        if (empty($sqlwhere)) $sqlwhere=' WHERE ';
108
+        else $sqlwhere.=" AND";
109
+        $sqlwhere.=' type <> 1';
110
+    }
111
+    if (in_array('nocreditnote',$filter))
112
+    {
113
+        if (empty($sqlwhere)) $sqlwhere=' WHERE ';
114
+        else $sqlwhere.=" AND";
115
+        $sqlwhere.=' type <> 2';
116
+    }
117
+    if (in_array('excludethirdparties',$filter) && is_array($thirdpartiesid))
118
+    {
119
+        if (empty($sqlwhere)) $sqlwhere=' WHERE ';
120
+        else $sqlwhere.=" AND";
121
+        $sqlwhere.=' f.fk_soc NOT IN ('.join(',',$thirdpartiesid).')';
122
+    }
123
+    if (in_array('onlythirdparties',$filter) && is_array($thirdpartiesid))
124
+    {
125
+        if (empty($sqlwhere)) $sqlwhere=' WHERE ';
126
+        else $sqlwhere.=" AND";
127
+        $sqlwhere.=' f.fk_soc IN ('.join(',',$thirdpartiesid).')';
128
+    }
129
+    if ($sqlwhere) $sql.=$sqlwhere;
130
+    if ($sqlorder) $sql.=$sqlorder;
131 131
 
132
-	//print $sql; exit;
133
-	dol_syslog("scripts/invoices/rebuild_merge.php:", LOG_DEBUG);
132
+    //print $sql; exit;
133
+    dol_syslog("scripts/invoices/rebuild_merge.php:", LOG_DEBUG);
134 134
 
135
-	if ($usestdout) print '--- start'."\n";
135
+    if ($usestdout) print '--- start'."\n";
136 136
 
137
-	// Start of transaction
138
-	//$db->begin();
137
+    // Start of transaction
138
+    //$db->begin();
139 139
 
140
-	$error = 0;
141
-	$result = 0;
142
-	$files = array() ;		// liste les fichiers
140
+    $error = 0;
141
+    $result = 0;
142
+    $files = array() ;		// liste les fichiers
143 143
 
144
-	dol_syslog("scripts/invoices/rebuild_merge.php", LOG_DEBUG);
145
-	if ( $resql=$db->query($sql) )
146
-	{
147
-	    $num = $db->num_rows($resql);
148
-	    $cpt = 0;
149
-	    $oldemail = '';
150
-	    $message = '';
151
-	    $total = '';
144
+    dol_syslog("scripts/invoices/rebuild_merge.php", LOG_DEBUG);
145
+    if ( $resql=$db->query($sql) )
146
+    {
147
+        $num = $db->num_rows($resql);
148
+        $cpt = 0;
149
+        $oldemail = '';
150
+        $message = '';
151
+        $total = '';
152 152
 
153
-	    if ($num)
154
-	    {
155
-	    	// First loop on each resultset to build PDF
156
-	    	// -----------------------------------------
153
+        if ($num)
154
+        {
155
+            // First loop on each resultset to build PDF
156
+            // -----------------------------------------
157 157
 
158
-	        while ($cpt < $num)
159
-	        {
160
-	            $obj = $db->fetch_object($resql);
158
+            while ($cpt < $num)
159
+            {
160
+                $obj = $db->fetch_object($resql);
161 161
 
162
-				$fac = new Facture($db);
163
-				$result=$fac->fetch($obj->rowid);
164
-				if ($result > 0)
165
-				{
166
-					$outputlangs = $langs;
167
-					if (! empty($newlangid))
168
-					{
169
-						if ($outputlangs->defaultlang != $newlangid)
170
-						{
171
-							$outputlangs = new Translate("",$conf);
172
-							$outputlangs->setDefaultLang($newlangid);
173
-						}
174
-					}
175
-					$filename=$conf->facture->dir_output.'/'.$fac->ref.'/'.$fac->ref.'.pdf';
176
-					if ($regenerate || ! dol_is_file($filename))
177
-					{
178
-	            	    if ($usestdout) print "Build PDF for invoice ".$obj->ref." - Lang = ".$outputlangs->defaultlang."\n";
179
-	    				$result= $fac->generateDocument($regenerate?$regenerate:$fac->modelpdf, $outputlangs);
180
-					}
181
-					else {
182
-					    if ($usestdout) print "PDF for invoice ".$obj->ref." already exists\n";
183
-					}
162
+                $fac = new Facture($db);
163
+                $result=$fac->fetch($obj->rowid);
164
+                if ($result > 0)
165
+                {
166
+                    $outputlangs = $langs;
167
+                    if (! empty($newlangid))
168
+                    {
169
+                        if ($outputlangs->defaultlang != $newlangid)
170
+                        {
171
+                            $outputlangs = new Translate("",$conf);
172
+                            $outputlangs->setDefaultLang($newlangid);
173
+                        }
174
+                    }
175
+                    $filename=$conf->facture->dir_output.'/'.$fac->ref.'/'.$fac->ref.'.pdf';
176
+                    if ($regenerate || ! dol_is_file($filename))
177
+                    {
178
+                        if ($usestdout) print "Build PDF for invoice ".$obj->ref." - Lang = ".$outputlangs->defaultlang."\n";
179
+                        $result= $fac->generateDocument($regenerate?$regenerate:$fac->modelpdf, $outputlangs);
180
+                    }
181
+                    else {
182
+                        if ($usestdout) print "PDF for invoice ".$obj->ref." already exists\n";
183
+                    }
184 184
 
185
-					// Add file into files array
186
-					$files[] = $filename;
187
-				}
185
+                    // Add file into files array
186
+                    $files[] = $filename;
187
+                }
188 188
 
189
-				if ($result <= 0)
190
-				{
191
-					$error++;
192
-					if ($usestdout) print "Error: Failed to build PDF for invoice ".($fac->ref?$fac->ref:' id '.$obj->rowid)."\n";
193
-					else dol_syslog("Failed to build PDF for invoice ".($fac->ref?$fac->ref:' id '.$obj->rowid), LOG_ERR);
194
-				}
189
+                if ($result <= 0)
190
+                {
191
+                    $error++;
192
+                    if ($usestdout) print "Error: Failed to build PDF for invoice ".($fac->ref?$fac->ref:' id '.$obj->rowid)."\n";
193
+                    else dol_syslog("Failed to build PDF for invoice ".($fac->ref?$fac->ref:' id '.$obj->rowid), LOG_ERR);
194
+                }
195 195
 
196
-	            $cpt++;
197
-	        }
196
+                $cpt++;
197
+            }
198 198
 
199 199
 
200
-	        // Define format of output PDF
201
-	        $formatarray=pdf_getFormat($langs);
202
-	        $page_largeur = $formatarray['width'];
203
-	        $page_hauteur = $formatarray['height'];
204
-	        $format = array($page_largeur,$page_hauteur);
200
+            // Define format of output PDF
201
+            $formatarray=pdf_getFormat($langs);
202
+            $page_largeur = $formatarray['width'];
203
+            $page_hauteur = $formatarray['height'];
204
+            $format = array($page_largeur,$page_hauteur);
205 205
 
206
-	        if ($usestdout) print "Using output PDF format ".join('x',$format)."\n";
207
-	        else dol_syslog("Using output PDF format ".join('x',$format), LOG_ERR);
206
+            if ($usestdout) print "Using output PDF format ".join('x',$format)."\n";
207
+            else dol_syslog("Using output PDF format ".join('x',$format), LOG_ERR);
208 208
 
209 209
 
210
-	        // Now, build a merged files with all files in $files array
211
-			//---------------------------------------------------------
210
+            // Now, build a merged files with all files in $files array
211
+            //---------------------------------------------------------
212 212
 
213
-	        // Create empty PDF
214
-	        $pdf=pdf_getInstance($format);
215
-	        if (class_exists('TCPDF'))
216
-	        {
217
-	            $pdf->setPrintHeader(false);
218
-	            $pdf->setPrintFooter(false);
219
-	        }
220
-	        $pdf->SetFont(pdf_getPDFFont($langs));
213
+            // Create empty PDF
214
+            $pdf=pdf_getInstance($format);
215
+            if (class_exists('TCPDF'))
216
+            {
217
+                $pdf->setPrintHeader(false);
218
+                $pdf->setPrintFooter(false);
219
+            }
220
+            $pdf->SetFont(pdf_getPDFFont($langs));
221 221
 
222
-	        if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false);
223
-			//$pdf->SetCompression(false);
222
+            if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false);
223
+            //$pdf->SetCompression(false);
224 224
 
225
-			// Add all others
226
-			foreach($files as $file)
227
-			{
228
-	            if ($usestdout) print "Merge PDF file for invoice ".$file."\n";
229
-	            else dol_syslog("Merge PDF file for invoice ".$file);
225
+            // Add all others
226
+            foreach($files as $file)
227
+            {
228
+                if ($usestdout) print "Merge PDF file for invoice ".$file."\n";
229
+                else dol_syslog("Merge PDF file for invoice ".$file);
230 230
 
231
-				// Charge un document PDF depuis un fichier.
232
-				$pagecount = $pdf->setSourceFile($file);
233
-				for ($i = 1; $i <= $pagecount; $i++)
234
-	            {
235
-	                 $tplidx = $pdf->importPage($i);
236
-	                 $s = $pdf->getTemplatesize($tplidx);
237
-	                 $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
238
-	                 $pdf->useTemplate($tplidx);
239
-	            }
240
-			}
231
+                // Charge un document PDF depuis un fichier.
232
+                $pagecount = $pdf->setSourceFile($file);
233
+                for ($i = 1; $i <= $pagecount; $i++)
234
+                {
235
+                        $tplidx = $pdf->importPage($i);
236
+                        $s = $pdf->getTemplatesize($tplidx);
237
+                        $pdf->AddPage($s['h'] > $s['w'] ? 'P' : 'L');
238
+                        $pdf->useTemplate($tplidx);
239
+                }
240
+            }
241 241
 
242
-			// Create output dir if not exists
243
-			dol_mkdir($diroutputpdf);
242
+            // Create output dir if not exists
243
+            dol_mkdir($diroutputpdf);
244 244
 
245
-			// Save merged file
246
-			$filename=$fileprefix;
247
-			if (empty($filename)) $filename='mergedpdf';
248
-			if (! empty($filesuffix)) $filename.='_'.$filesuffix;
249
-			$file=$diroutputpdf.'/'.$filename.'.pdf';
245
+            // Save merged file
246
+            $filename=$fileprefix;
247
+            if (empty($filename)) $filename='mergedpdf';
248
+            if (! empty($filesuffix)) $filename.='_'.$filesuffix;
249
+            $file=$diroutputpdf.'/'.$filename.'.pdf';
250 250
 
251
-			if (! $error && $pagecount)
252
-			{
253
-				$pdf->Output($file,'F');
254
-				if (! empty($conf->global->MAIN_UMASK))
255
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
256
-			}
251
+            if (! $error && $pagecount)
252
+            {
253
+                $pdf->Output($file,'F');
254
+                if (! empty($conf->global->MAIN_UMASK))
255
+                    @chmod($file, octdec($conf->global->MAIN_UMASK));
256
+            }
257 257
 
258
-			if ($usestdout)
259
-			{
260
-				if (! $error) print "Merged PDF has been built in ".$file."\n";
261
-				else print "Can't build PDF ".$file."\n";
262
-			}
258
+            if ($usestdout)
259
+            {
260
+                if (! $error) print "Merged PDF has been built in ".$file."\n";
261
+                else print "Can't build PDF ".$file."\n";
262
+            }
263 263
 
264
-			$result = 1;
265
-	    }
266
-	    else
267
-	    {
268
-	        if ($usestdout) print "No invoices found for criteria.\n";
269
-	        else dol_syslog("No invoices found for criteria");
270
-	        $result = 0;
271
-	    }
272
-	}
273
-	else
274
-	{
275
-	    dol_print_error($db);
276
-	    dol_syslog("scripts/invoices/rebuild_merge.php: Error");
277
-	    $error++;
278
-	}
264
+            $result = 1;
265
+        }
266
+        else
267
+        {
268
+            if ($usestdout) print "No invoices found for criteria.\n";
269
+            else dol_syslog("No invoices found for criteria");
270
+            $result = 0;
271
+        }
272
+    }
273
+    else
274
+    {
275
+        dol_print_error($db);
276
+        dol_syslog("scripts/invoices/rebuild_merge.php: Error");
277
+        $error++;
278
+    }
279 279
 
280
-	if ($error) return -1;
281
-	else return $result;
280
+    if ($error) return -1;
281
+    else return $result;
282 282
 }
283 283
 
Please login to merge, or discard this patch.
Spacing   +77 added lines, -77 removed lines patch added patch discarded remove patch
@@ -48,86 +48,86 @@  discard block
 block discarded – undo
48 48
  * @param	string		$fileprefix				Prefix to add into filename of generated PDF
49 49
  * @return	int									Error code
50 50
  */
51
-function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, $usestdout, $regenerate=0, $filesuffix='', $paymentbankid='', $thirdpartiesid='', $fileprefix='mergedpdf')
51
+function rebuild_merge_pdf($db, $langs, $conf, $diroutputpdf, $newlangid, $filter, $dateafterdate, $datebeforedate, $paymentdateafter, $paymentdatebefore, $usestdout, $regenerate = 0, $filesuffix = '', $paymentbankid = '', $thirdpartiesid = '', $fileprefix = 'mergedpdf')
52 52
 {
53 53
 	$sql = "SELECT DISTINCT f.rowid, f.ref";
54
-	$sql.= " FROM ".MAIN_DB_PREFIX."facture as f";
55
-	$sqlwhere='';
56
-	$sqlorder='';
57
-	if (in_array('all',$filter))
54
+	$sql .= " FROM ".MAIN_DB_PREFIX."facture as f";
55
+	$sqlwhere = '';
56
+	$sqlorder = '';
57
+	if (in_array('all', $filter))
58 58
 	{
59 59
 		$sqlorder = " ORDER BY f.ref ASC";
60 60
 	}
61
-	if (in_array('date',$filter))
61
+	if (in_array('date', $filter))
62 62
 	{
63
-		if (empty($sqlwhere)) $sqlwhere=' WHERE ';
64
-		else $sqlwhere.=" AND";
65
-		$sqlwhere.= " f.fk_statut > 0";
66
-		$sqlwhere.= " AND f.datef >= '".$db->idate($dateafterdate)."'";
67
-		$sqlwhere.= " AND f.datef <= '".$db->idate($datebeforedate)."'";
63
+		if (empty($sqlwhere)) $sqlwhere = ' WHERE ';
64
+		else $sqlwhere .= " AND";
65
+		$sqlwhere .= " f.fk_statut > 0";
66
+		$sqlwhere .= " AND f.datef >= '".$db->idate($dateafterdate)."'";
67
+		$sqlwhere .= " AND f.datef <= '".$db->idate($datebeforedate)."'";
68 68
 		$sqlorder = " ORDER BY f.datef ASC";
69 69
 	}
70
-	if (in_array('nopayment',$filter))
70
+	if (in_array('nopayment', $filter))
71 71
 	{
72
-		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
73
-		if (empty($sqlwhere)) $sqlwhere=' WHERE ';
74
-		else $sqlwhere.=" AND";
75
-		$sqlwhere.= " f.fk_statut > 0";
76
-		$sqlwhere.= " AND pf.fk_paiement IS NULL";
72
+		$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
73
+		if (empty($sqlwhere)) $sqlwhere = ' WHERE ';
74
+		else $sqlwhere .= " AND";
75
+		$sqlwhere .= " f.fk_statut > 0";
76
+		$sqlwhere .= " AND pf.fk_paiement IS NULL";
77 77
 	}
78
-	if (in_array('payments',$filter) || in_array('bank',$filter))
78
+	if (in_array('payments', $filter) || in_array('bank', $filter))
79 79
 	{
80
-		$sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
81
-		if (in_array('bank',$filter)) $sql.= ", ".MAIN_DB_PREFIX."bank as b";
82
-		if (empty($sqlwhere)) $sqlwhere=' WHERE ';
83
-		else $sqlwhere.=" AND";
84
-		$sqlwhere.= " f.fk_statut > 0";
85
-		$sqlwhere.= " AND f.rowid = pf.fk_facture";
86
-		$sqlwhere.= " AND pf.fk_paiement = p.rowid";
87
-		if (in_array('payments',$filter))
80
+		$sql .= ", ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
81
+		if (in_array('bank', $filter)) $sql .= ", ".MAIN_DB_PREFIX."bank as b";
82
+		if (empty($sqlwhere)) $sqlwhere = ' WHERE ';
83
+		else $sqlwhere .= " AND";
84
+		$sqlwhere .= " f.fk_statut > 0";
85
+		$sqlwhere .= " AND f.rowid = pf.fk_facture";
86
+		$sqlwhere .= " AND pf.fk_paiement = p.rowid";
87
+		if (in_array('payments', $filter))
88 88
 		{
89
-			$sqlwhere.= " AND p.datep >= '".$db->idate($paymentdateafter)."'";
90
-			$sqlwhere.= " AND p.datep <= '".$db->idate($paymentdatebefore)."'";
89
+			$sqlwhere .= " AND p.datep >= '".$db->idate($paymentdateafter)."'";
90
+			$sqlwhere .= " AND p.datep <= '".$db->idate($paymentdatebefore)."'";
91 91
 		}
92
-		if (in_array('bank',$filter))
92
+		if (in_array('bank', $filter))
93 93
 		{
94
-			$sqlwhere.= " AND p.fk_bank = b.rowid";
95
-			$sqlwhere.= " AND b.fk_account = ".$paymentbankid;
94
+			$sqlwhere .= " AND p.fk_bank = b.rowid";
95
+			$sqlwhere .= " AND b.fk_account = ".$paymentbankid;
96 96
 		}
97 97
 		$sqlorder = " ORDER BY p.datep ASC";
98 98
 	}
99
-	if (in_array('nodeposit',$filter))
99
+	if (in_array('nodeposit', $filter))
100 100
 	{
101
-	    if (empty($sqlwhere)) $sqlwhere=' WHERE ';
102
-	    else $sqlwhere.=" AND";
103
-	    $sqlwhere.=' type <> 3';
101
+	    if (empty($sqlwhere)) $sqlwhere = ' WHERE ';
102
+	    else $sqlwhere .= " AND";
103
+	    $sqlwhere .= ' type <> 3';
104 104
 	}
105
-	if (in_array('noreplacement',$filter))
105
+	if (in_array('noreplacement', $filter))
106 106
 	{
107
-	    if (empty($sqlwhere)) $sqlwhere=' WHERE ';
108
-	    else $sqlwhere.=" AND";
109
-	    $sqlwhere.=' type <> 1';
107
+	    if (empty($sqlwhere)) $sqlwhere = ' WHERE ';
108
+	    else $sqlwhere .= " AND";
109
+	    $sqlwhere .= ' type <> 1';
110 110
 	}
111
-	if (in_array('nocreditnote',$filter))
111
+	if (in_array('nocreditnote', $filter))
112 112
 	{
113
-	    if (empty($sqlwhere)) $sqlwhere=' WHERE ';
114
-	    else $sqlwhere.=" AND";
115
-	    $sqlwhere.=' type <> 2';
113
+	    if (empty($sqlwhere)) $sqlwhere = ' WHERE ';
114
+	    else $sqlwhere .= " AND";
115
+	    $sqlwhere .= ' type <> 2';
116 116
 	}
117
-	if (in_array('excludethirdparties',$filter) && is_array($thirdpartiesid))
117
+	if (in_array('excludethirdparties', $filter) && is_array($thirdpartiesid))
118 118
 	{
119
-	    if (empty($sqlwhere)) $sqlwhere=' WHERE ';
120
-	    else $sqlwhere.=" AND";
121
-	    $sqlwhere.=' f.fk_soc NOT IN ('.join(',',$thirdpartiesid).')';
119
+	    if (empty($sqlwhere)) $sqlwhere = ' WHERE ';
120
+	    else $sqlwhere .= " AND";
121
+	    $sqlwhere .= ' f.fk_soc NOT IN ('.join(',', $thirdpartiesid).')';
122 122
 	}
123
-	if (in_array('onlythirdparties',$filter) && is_array($thirdpartiesid))
123
+	if (in_array('onlythirdparties', $filter) && is_array($thirdpartiesid))
124 124
 	{
125
-	    if (empty($sqlwhere)) $sqlwhere=' WHERE ';
126
-	    else $sqlwhere.=" AND";
127
-	    $sqlwhere.=' f.fk_soc IN ('.join(',',$thirdpartiesid).')';
125
+	    if (empty($sqlwhere)) $sqlwhere = ' WHERE ';
126
+	    else $sqlwhere .= " AND";
127
+	    $sqlwhere .= ' f.fk_soc IN ('.join(',', $thirdpartiesid).')';
128 128
 	}
129
-	if ($sqlwhere) $sql.=$sqlwhere;
130
-	if ($sqlorder) $sql.=$sqlorder;
129
+	if ($sqlwhere) $sql .= $sqlwhere;
130
+	if ($sqlorder) $sql .= $sqlorder;
131 131
 
132 132
 	//print $sql; exit;
133 133
 	dol_syslog("scripts/invoices/rebuild_merge.php:", LOG_DEBUG);
@@ -139,10 +139,10 @@  discard block
 block discarded – undo
139 139
 
140 140
 	$error = 0;
141 141
 	$result = 0;
142
-	$files = array() ;		// liste les fichiers
142
+	$files = array(); // liste les fichiers
143 143
 
144 144
 	dol_syslog("scripts/invoices/rebuild_merge.php", LOG_DEBUG);
145
-	if ( $resql=$db->query($sql) )
145
+	if ($resql = $db->query($sql))
146 146
 	{
147 147
 	    $num = $db->num_rows($resql);
148 148
 	    $cpt = 0;
@@ -160,23 +160,23 @@  discard block
 block discarded – undo
160 160
 	            $obj = $db->fetch_object($resql);
161 161
 
162 162
 				$fac = new Facture($db);
163
-				$result=$fac->fetch($obj->rowid);
163
+				$result = $fac->fetch($obj->rowid);
164 164
 				if ($result > 0)
165 165
 				{
166 166
 					$outputlangs = $langs;
167
-					if (! empty($newlangid))
167
+					if (!empty($newlangid))
168 168
 					{
169 169
 						if ($outputlangs->defaultlang != $newlangid)
170 170
 						{
171
-							$outputlangs = new Translate("",$conf);
171
+							$outputlangs = new Translate("", $conf);
172 172
 							$outputlangs->setDefaultLang($newlangid);
173 173
 						}
174 174
 					}
175
-					$filename=$conf->facture->dir_output.'/'.$fac->ref.'/'.$fac->ref.'.pdf';
176
-					if ($regenerate || ! dol_is_file($filename))
175
+					$filename = $conf->facture->dir_output.'/'.$fac->ref.'/'.$fac->ref.'.pdf';
176
+					if ($regenerate || !dol_is_file($filename))
177 177
 					{
178 178
 	            	    if ($usestdout) print "Build PDF for invoice ".$obj->ref." - Lang = ".$outputlangs->defaultlang."\n";
179
-	    				$result= $fac->generateDocument($regenerate?$regenerate:$fac->modelpdf, $outputlangs);
179
+	    				$result = $fac->generateDocument($regenerate ? $regenerate : $fac->modelpdf, $outputlangs);
180 180
 					}
181 181
 					else {
182 182
 					    if ($usestdout) print "PDF for invoice ".$obj->ref." already exists\n";
@@ -189,8 +189,8 @@  discard block
 block discarded – undo
189 189
 				if ($result <= 0)
190 190
 				{
191 191
 					$error++;
192
-					if ($usestdout) print "Error: Failed to build PDF for invoice ".($fac->ref?$fac->ref:' id '.$obj->rowid)."\n";
193
-					else dol_syslog("Failed to build PDF for invoice ".($fac->ref?$fac->ref:' id '.$obj->rowid), LOG_ERR);
192
+					if ($usestdout) print "Error: Failed to build PDF for invoice ".($fac->ref ? $fac->ref : ' id '.$obj->rowid)."\n";
193
+					else dol_syslog("Failed to build PDF for invoice ".($fac->ref ? $fac->ref : ' id '.$obj->rowid), LOG_ERR);
194 194
 				}
195 195
 
196 196
 	            $cpt++;
@@ -198,20 +198,20 @@  discard block
 block discarded – undo
198 198
 
199 199
 
200 200
 	        // Define format of output PDF
201
-	        $formatarray=pdf_getFormat($langs);
201
+	        $formatarray = pdf_getFormat($langs);
202 202
 	        $page_largeur = $formatarray['width'];
203 203
 	        $page_hauteur = $formatarray['height'];
204
-	        $format = array($page_largeur,$page_hauteur);
204
+	        $format = array($page_largeur, $page_hauteur);
205 205
 
206
-	        if ($usestdout) print "Using output PDF format ".join('x',$format)."\n";
207
-	        else dol_syslog("Using output PDF format ".join('x',$format), LOG_ERR);
206
+	        if ($usestdout) print "Using output PDF format ".join('x', $format)."\n";
207
+	        else dol_syslog("Using output PDF format ".join('x', $format), LOG_ERR);
208 208
 
209 209
 
210 210
 	        // Now, build a merged files with all files in $files array
211 211
 			//---------------------------------------------------------
212 212
 
213 213
 	        // Create empty PDF
214
-	        $pdf=pdf_getInstance($format);
214
+	        $pdf = pdf_getInstance($format);
215 215
 	        if (class_exists('TCPDF'))
216 216
 	        {
217 217
 	            $pdf->setPrintHeader(false);
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
 			//$pdf->SetCompression(false);
224 224
 
225 225
 			// Add all others
226
-			foreach($files as $file)
226
+			foreach ($files as $file)
227 227
 			{
228 228
 	            if ($usestdout) print "Merge PDF file for invoice ".$file."\n";
229 229
 	            else dol_syslog("Merge PDF file for invoice ".$file);
@@ -243,21 +243,21 @@  discard block
 block discarded – undo
243 243
 			dol_mkdir($diroutputpdf);
244 244
 
245 245
 			// Save merged file
246
-			$filename=$fileprefix;
247
-			if (empty($filename)) $filename='mergedpdf';
248
-			if (! empty($filesuffix)) $filename.='_'.$filesuffix;
249
-			$file=$diroutputpdf.'/'.$filename.'.pdf';
246
+			$filename = $fileprefix;
247
+			if (empty($filename)) $filename = 'mergedpdf';
248
+			if (!empty($filesuffix)) $filename .= '_'.$filesuffix;
249
+			$file = $diroutputpdf.'/'.$filename.'.pdf';
250 250
 
251
-			if (! $error && $pagecount)
251
+			if (!$error && $pagecount)
252 252
 			{
253
-				$pdf->Output($file,'F');
254
-				if (! empty($conf->global->MAIN_UMASK))
253
+				$pdf->Output($file, 'F');
254
+				if (!empty($conf->global->MAIN_UMASK))
255 255
 					@chmod($file, octdec($conf->global->MAIN_UMASK));
256 256
 			}
257 257
 
258 258
 			if ($usestdout)
259 259
 			{
260
-				if (! $error) print "Merged PDF has been built in ".$file."\n";
260
+				if (!$error) print "Merged PDF has been built in ".$file."\n";
261 261
 				else print "Can't build PDF ".$file."\n";
262 262
 			}
263 263
 
Please login to merge, or discard this patch.
Braces   +104 added lines, -46 removed lines patch added patch discarded remove patch
@@ -60,8 +60,11 @@  discard block
 block discarded – undo
60 60
 	}
61 61
 	if (in_array('date',$filter))
62 62
 	{
63
-		if (empty($sqlwhere)) $sqlwhere=' WHERE ';
64
-		else $sqlwhere.=" AND";
63
+		if (empty($sqlwhere)) {
64
+		    $sqlwhere=' WHERE ';
65
+		} else {
66
+		    $sqlwhere.=" AND";
67
+		}
65 68
 		$sqlwhere.= " f.fk_statut > 0";
66 69
 		$sqlwhere.= " AND f.datef >= '".$db->idate($dateafterdate)."'";
67 70
 		$sqlwhere.= " AND f.datef <= '".$db->idate($datebeforedate)."'";
@@ -70,17 +73,25 @@  discard block
 block discarded – undo
70 73
 	if (in_array('nopayment',$filter))
71 74
 	{
72 75
 		$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."paiement_facture as pf ON f.rowid = pf.fk_facture";
73
-		if (empty($sqlwhere)) $sqlwhere=' WHERE ';
74
-		else $sqlwhere.=" AND";
76
+		if (empty($sqlwhere)) {
77
+		    $sqlwhere=' WHERE ';
78
+		} else {
79
+		    $sqlwhere.=" AND";
80
+		}
75 81
 		$sqlwhere.= " f.fk_statut > 0";
76 82
 		$sqlwhere.= " AND pf.fk_paiement IS NULL";
77 83
 	}
78 84
 	if (in_array('payments',$filter) || in_array('bank',$filter))
79 85
 	{
80 86
 		$sql.= ", ".MAIN_DB_PREFIX."paiement_facture as pf, ".MAIN_DB_PREFIX."paiement as p";
81
-		if (in_array('bank',$filter)) $sql.= ", ".MAIN_DB_PREFIX."bank as b";
82
-		if (empty($sqlwhere)) $sqlwhere=' WHERE ';
83
-		else $sqlwhere.=" AND";
87
+		if (in_array('bank',$filter)) {
88
+		    $sql.= ", ".MAIN_DB_PREFIX."bank as b";
89
+		}
90
+		if (empty($sqlwhere)) {
91
+		    $sqlwhere=' WHERE ';
92
+		} else {
93
+		    $sqlwhere.=" AND";
94
+		}
84 95
 		$sqlwhere.= " f.fk_statut > 0";
85 96
 		$sqlwhere.= " AND f.rowid = pf.fk_facture";
86 97
 		$sqlwhere.= " AND pf.fk_paiement = p.rowid";
@@ -98,41 +109,62 @@  discard block
 block discarded – undo
98 109
 	}
99 110
 	if (in_array('nodeposit',$filter))
100 111
 	{
101
-	    if (empty($sqlwhere)) $sqlwhere=' WHERE ';
102
-	    else $sqlwhere.=" AND";
112
+	    if (empty($sqlwhere)) {
113
+	        $sqlwhere=' WHERE ';
114
+	    } else {
115
+	        $sqlwhere.=" AND";
116
+	    }
103 117
 	    $sqlwhere.=' type <> 3';
104 118
 	}
105 119
 	if (in_array('noreplacement',$filter))
106 120
 	{
107
-	    if (empty($sqlwhere)) $sqlwhere=' WHERE ';
108
-	    else $sqlwhere.=" AND";
121
+	    if (empty($sqlwhere)) {
122
+	        $sqlwhere=' WHERE ';
123
+	    } else {
124
+	        $sqlwhere.=" AND";
125
+	    }
109 126
 	    $sqlwhere.=' type <> 1';
110 127
 	}
111 128
 	if (in_array('nocreditnote',$filter))
112 129
 	{
113
-	    if (empty($sqlwhere)) $sqlwhere=' WHERE ';
114
-	    else $sqlwhere.=" AND";
130
+	    if (empty($sqlwhere)) {
131
+	        $sqlwhere=' WHERE ';
132
+	    } else {
133
+	        $sqlwhere.=" AND";
134
+	    }
115 135
 	    $sqlwhere.=' type <> 2';
116 136
 	}
117 137
 	if (in_array('excludethirdparties',$filter) && is_array($thirdpartiesid))
118 138
 	{
119
-	    if (empty($sqlwhere)) $sqlwhere=' WHERE ';
120
-	    else $sqlwhere.=" AND";
139
+	    if (empty($sqlwhere)) {
140
+	        $sqlwhere=' WHERE ';
141
+	    } else {
142
+	        $sqlwhere.=" AND";
143
+	    }
121 144
 	    $sqlwhere.=' f.fk_soc NOT IN ('.join(',',$thirdpartiesid).')';
122 145
 	}
123 146
 	if (in_array('onlythirdparties',$filter) && is_array($thirdpartiesid))
124 147
 	{
125
-	    if (empty($sqlwhere)) $sqlwhere=' WHERE ';
126
-	    else $sqlwhere.=" AND";
148
+	    if (empty($sqlwhere)) {
149
+	        $sqlwhere=' WHERE ';
150
+	    } else {
151
+	        $sqlwhere.=" AND";
152
+	    }
127 153
 	    $sqlwhere.=' f.fk_soc IN ('.join(',',$thirdpartiesid).')';
128 154
 	}
129
-	if ($sqlwhere) $sql.=$sqlwhere;
130
-	if ($sqlorder) $sql.=$sqlorder;
155
+	if ($sqlwhere) {
156
+	    $sql.=$sqlwhere;
157
+	}
158
+	if ($sqlorder) {
159
+	    $sql.=$sqlorder;
160
+	}
131 161
 
132 162
 	//print $sql; exit;
133 163
 	dol_syslog("scripts/invoices/rebuild_merge.php:", LOG_DEBUG);
134 164
 
135
-	if ($usestdout) print '--- start'."\n";
165
+	if ($usestdout) {
166
+	    print '--- start'."\n";
167
+	}
136 168
 
137 169
 	// Start of transaction
138 170
 	//$db->begin();
@@ -175,11 +207,14 @@  discard block
 block discarded – undo
175 207
 					$filename=$conf->facture->dir_output.'/'.$fac->ref.'/'.$fac->ref.'.pdf';
176 208
 					if ($regenerate || ! dol_is_file($filename))
177 209
 					{
178
-	            	    if ($usestdout) print "Build PDF for invoice ".$obj->ref." - Lang = ".$outputlangs->defaultlang."\n";
210
+	            	    if ($usestdout) {
211
+	            	        print "Build PDF for invoice ".$obj->ref." - Lang = ".$outputlangs->defaultlang."\n";
212
+	            	    }
179 213
 	    				$result= $fac->generateDocument($regenerate?$regenerate:$fac->modelpdf, $outputlangs);
180
-					}
181
-					else {
182
-					    if ($usestdout) print "PDF for invoice ".$obj->ref." already exists\n";
214
+					} else {
215
+					    if ($usestdout) {
216
+					        print "PDF for invoice ".$obj->ref." already exists\n";
217
+					    }
183 218
 					}
184 219
 
185 220
 					// Add file into files array
@@ -189,8 +224,11 @@  discard block
 block discarded – undo
189 224
 				if ($result <= 0)
190 225
 				{
191 226
 					$error++;
192
-					if ($usestdout) print "Error: Failed to build PDF for invoice ".($fac->ref?$fac->ref:' id '.$obj->rowid)."\n";
193
-					else dol_syslog("Failed to build PDF for invoice ".($fac->ref?$fac->ref:' id '.$obj->rowid), LOG_ERR);
227
+					if ($usestdout) {
228
+					    print "Error: Failed to build PDF for invoice ".($fac->ref?$fac->ref:' id '.$obj->rowid)."\n";
229
+					} else {
230
+					    dol_syslog("Failed to build PDF for invoice ".($fac->ref?$fac->ref:' id '.$obj->rowid), LOG_ERR);
231
+					}
194 232
 				}
195 233
 
196 234
 	            $cpt++;
@@ -203,8 +241,11 @@  discard block
 block discarded – undo
203 241
 	        $page_hauteur = $formatarray['height'];
204 242
 	        $format = array($page_largeur,$page_hauteur);
205 243
 
206
-	        if ($usestdout) print "Using output PDF format ".join('x',$format)."\n";
207
-	        else dol_syslog("Using output PDF format ".join('x',$format), LOG_ERR);
244
+	        if ($usestdout) {
245
+	            print "Using output PDF format ".join('x',$format)."\n";
246
+	        } else {
247
+	            dol_syslog("Using output PDF format ".join('x',$format), LOG_ERR);
248
+	        }
208 249
 
209 250
 
210 251
 	        // Now, build a merged files with all files in $files array
@@ -219,14 +260,19 @@  discard block
 block discarded – undo
219 260
 	        }
220 261
 	        $pdf->SetFont(pdf_getPDFFont($langs));
221 262
 
222
-	        if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) $pdf->SetCompression(false);
263
+	        if ($conf->global->MAIN_DISABLE_PDF_COMPRESSION) {
264
+	            $pdf->SetCompression(false);
265
+	        }
223 266
 			//$pdf->SetCompression(false);
224 267
 
225 268
 			// Add all others
226 269
 			foreach($files as $file)
227 270
 			{
228
-	            if ($usestdout) print "Merge PDF file for invoice ".$file."\n";
229
-	            else dol_syslog("Merge PDF file for invoice ".$file);
271
+	            if ($usestdout) {
272
+	                print "Merge PDF file for invoice ".$file."\n";
273
+	            } else {
274
+	                dol_syslog("Merge PDF file for invoice ".$file);
275
+	            }
230 276
 
231 277
 				// Charge un document PDF depuis un fichier.
232 278
 				$pagecount = $pdf->setSourceFile($file);
@@ -244,40 +290,52 @@  discard block
 block discarded – undo
244 290
 
245 291
 			// Save merged file
246 292
 			$filename=$fileprefix;
247
-			if (empty($filename)) $filename='mergedpdf';
248
-			if (! empty($filesuffix)) $filename.='_'.$filesuffix;
293
+			if (empty($filename)) {
294
+			    $filename='mergedpdf';
295
+			}
296
+			if (! empty($filesuffix)) {
297
+			    $filename.='_'.$filesuffix;
298
+			}
249 299
 			$file=$diroutputpdf.'/'.$filename.'.pdf';
250 300
 
251 301
 			if (! $error && $pagecount)
252 302
 			{
253 303
 				$pdf->Output($file,'F');
254
-				if (! empty($conf->global->MAIN_UMASK))
255
-					@chmod($file, octdec($conf->global->MAIN_UMASK));
304
+				if (! empty($conf->global->MAIN_UMASK)) {
305
+									@chmod($file, octdec($conf->global->MAIN_UMASK));
306
+				}
256 307
 			}
257 308
 
258 309
 			if ($usestdout)
259 310
 			{
260
-				if (! $error) print "Merged PDF has been built in ".$file."\n";
261
-				else print "Can't build PDF ".$file."\n";
311
+				if (! $error) {
312
+				    print "Merged PDF has been built in ".$file."\n";
313
+				} else {
314
+				    print "Can't build PDF ".$file."\n";
315
+				}
262 316
 			}
263 317
 
264 318
 			$result = 1;
265
-	    }
266
-	    else
319
+	    } else
267 320
 	    {
268
-	        if ($usestdout) print "No invoices found for criteria.\n";
269
-	        else dol_syslog("No invoices found for criteria");
321
+	        if ($usestdout) {
322
+	            print "No invoices found for criteria.\n";
323
+	        } else {
324
+	            dol_syslog("No invoices found for criteria");
325
+	        }
270 326
 	        $result = 0;
271 327
 	    }
272
-	}
273
-	else
328
+	} else
274 329
 	{
275 330
 	    dol_print_error($db);
276 331
 	    dol_syslog("scripts/invoices/rebuild_merge.php: Error");
277 332
 	    $error++;
278 333
 	}
279 334
 
280
-	if ($error) return -1;
281
-	else return $result;
282
-}
335
+	if ($error) {
336
+	    return -1;
337
+	} else {
338
+	    return $result;
339
+	}
340
+	}
283 341
 
Please login to merge, or discard this patch.
dolibarr/htdocs/core/lib/prelevement.lib.php 3 patches
Indentation   +24 added lines, -24 removed lines patch added patch discarded remove patch
@@ -33,31 +33,31 @@  discard block
 block discarded – undo
33 33
  */
34 34
 function prelevement_prepare_head(BonPrelevement $object)
35 35
 {
36
-	global $langs, $conf, $user;
37
-	$langs->load("withdrawals");
36
+    global $langs, $conf, $user;
37
+    $langs->load("withdrawals");
38 38
 
39
-	$h = 0;
40
-	$head = array();
39
+    $h = 0;
40
+    $head = array();
41 41
 
42
-	$head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/card.php?id='.$object->id;
43
-	$head[$h][1] = $langs->trans("Card");
44
-	$head[$h][2] = 'prelevement';
45
-	$h++;
42
+    $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/card.php?id='.$object->id;
43
+    $head[$h][1] = $langs->trans("Card");
44
+    $head[$h][2] = 'prelevement';
45
+    $h++;
46 46
 
47
-	$head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/factures.php?id='.$object->id;
48
-	$head[$h][1] = $langs->trans("Bills");
49
-	$head[$h][2] = 'invoices';
50
-	$h++;
47
+    $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/factures.php?id='.$object->id;
48
+    $head[$h][1] = $langs->trans("Bills");
49
+    $head[$h][2] = 'invoices';
50
+    $h++;
51 51
 
52
-	$head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/fiche-rejet.php?id='.$object->id;
53
-	$head[$h][1] = $langs->trans("Rejects");
54
-	$head[$h][2] = 'rejects';
55
-	$h++;
52
+    $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/fiche-rejet.php?id='.$object->id;
53
+    $head[$h][1] = $langs->trans("Rejects");
54
+    $head[$h][2] = 'rejects';
55
+    $h++;
56 56
 
57
-	$head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/fiche-stat.php?id='.$object->id;
58
-	$head[$h][1] = $langs->trans("Statistics");
59
-	$head[$h][2] = 'statistics';
60
-	$h++;
57
+    $head[$h][0] = DOL_URL_ROOT.'/compta/prelevement/fiche-stat.php?id='.$object->id;
58
+    $head[$h][1] = $langs->trans("Statistics");
59
+    $head[$h][2] = 'statistics';
60
+    $h++;
61 61
 
62 62
     // Show more tabs from modules
63 63
     // Entries must be declared in modules descriptor with line
@@ -77,10 +77,10 @@  discard block
 block discarded – undo
77 77
  */
78 78
 function prelevement_check_config()
79 79
 {
80
-	global $conf;
81
-	if(empty($conf->global->PRELEVEMENT_ID_BANKACCOUNT)) return -1;
82
-	if(empty($conf->global->PRELEVEMENT_ICS)) return -1;
80
+    global $conf;
81
+    if(empty($conf->global->PRELEVEMENT_ID_BANKACCOUNT)) return -1;
82
+    if(empty($conf->global->PRELEVEMENT_ICS)) return -1;
83 83
     if(empty($conf->global->PRELEVEMENT_USER)) return -1;
84
-	return 0;
84
+    return 0;
85 85
 }
86 86
 
Please login to merge, or discard this patch.
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -63,9 +63,9 @@  discard block
 block discarded – undo
63 63
     // Entries must be declared in modules descriptor with line
64 64
     // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__');   to add new tab
65 65
     // $this->tabs = array('entity:-tabname);   												to remove a tab
66
-    complete_head_from_modules($conf,$langs,$object,$head,$h,'prelevement');
66
+    complete_head_from_modules($conf, $langs, $object, $head, $h, 'prelevement');
67 67
 
68
-    complete_head_from_modules($conf,$langs,$object,$head,$h,'prelevement','remove');
68
+    complete_head_from_modules($conf, $langs, $object, $head, $h, 'prelevement', 'remove');
69 69
 
70 70
     return $head;
71 71
 }
@@ -78,9 +78,9 @@  discard block
 block discarded – undo
78 78
 function prelevement_check_config()
79 79
 {
80 80
 	global $conf;
81
-	if(empty($conf->global->PRELEVEMENT_ID_BANKACCOUNT)) return -1;
82
-	if(empty($conf->global->PRELEVEMENT_ICS)) return -1;
83
-    if(empty($conf->global->PRELEVEMENT_USER)) return -1;
81
+	if (empty($conf->global->PRELEVEMENT_ID_BANKACCOUNT)) return -1;
82
+	if (empty($conf->global->PRELEVEMENT_ICS)) return -1;
83
+    if (empty($conf->global->PRELEVEMENT_USER)) return -1;
84 84
 	return 0;
85 85
 }
86 86
 
Please login to merge, or discard this patch.
Braces   +9 added lines, -3 removed lines patch added patch discarded remove patch
@@ -78,9 +78,15 @@
 block discarded – undo
78 78
 function prelevement_check_config()
79 79
 {
80 80
 	global $conf;
81
-	if(empty($conf->global->PRELEVEMENT_ID_BANKACCOUNT)) return -1;
82
-	if(empty($conf->global->PRELEVEMENT_ICS)) return -1;
83
-    if(empty($conf->global->PRELEVEMENT_USER)) return -1;
81
+	if(empty($conf->global->PRELEVEMENT_ID_BANKACCOUNT)) {
82
+	    return -1;
83
+	}
84
+	if(empty($conf->global->PRELEVEMENT_ICS)) {
85
+	    return -1;
86
+	}
87
+    if(empty($conf->global->PRELEVEMENT_USER)) {
88
+        return -1;
89
+    }
84 90
 	return 0;
85 91
 }
86 92
 
Please login to merge, or discard this patch.
dolibarr/htdocs/core/lib/barcode.lib.php 3 patches
Indentation   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -226,8 +226,8 @@  discard block
 block discarded – undo
226 226
     return array(
227 227
         "error" => '',
228 228
         "encoding" => $encoding,
229
-		"bars" => $line,
230
-		"text" => $text
229
+        "bars" => $line,
230
+        "text" => $text
231 231
     );
232 232
 }
233 233
 
@@ -271,16 +271,16 @@  discard block
 block discarded – undo
271 271
     }
272 272
     //var_dump($bars);
273 273
     $ret=array(
274
-		"bars" => trim($bars),
275
-		"text" => trim($text),
276
-		"encoding" => trim($encoding),
277
-    	"error" => ""
274
+        "bars" => trim($bars),
275
+        "text" => trim($text),
276
+        "encoding" => trim($encoding),
277
+        "error" => ""
278 278
     );
279 279
     //var_dump($ret);
280 280
     if (preg_match('/permission denied/i',$ret['bars']))
281 281
     {
282
-    	$ret['error']=$ret['bars']; $ret['bars']='';
283
-    	return $ret;
282
+        $ret['error']=$ret['bars']; $ret['bars']='';
283
+        return $ret;
284 284
     }
285 285
     if (!$ret['bars']) return false;
286 286
     if (!$ret['text']) return false;
Please login to merge, or discard this patch.
Spacing   +113 added lines, -113 removed lines patch added patch discarded remove patch
@@ -27,18 +27,18 @@  discard block
 block discarded – undo
27 27
 /* ******************************************************************** */
28 28
 /*                          COLORS                                      */
29 29
 /* ******************************************************************** */
30
-$bar_color=array(0,0,0);
31
-$bg_color=array(255,255,255);
32
-$text_color=array(0,0,0);
30
+$bar_color = array(0, 0, 0);
31
+$bg_color = array(255, 255, 255);
32
+$text_color = array(0, 0, 0);
33 33
 
34 34
 
35 35
 /* ******************************************************************** */
36 36
 /*                          FONT FILE                                   */
37 37
 /* ******************************************************************** */
38
-if (defined('DOL_DEFAULT_TTF_BOLD')) $font_loc=constant('DOL_DEFAULT_TTF_BOLD');
38
+if (defined('DOL_DEFAULT_TTF_BOLD')) $font_loc = constant('DOL_DEFAULT_TTF_BOLD');
39 39
 // Automatic-Detection of Font if running Windows
40 40
 // @CHANGE LDR
41
-if (isset($_SERVER['WINDIR']) && @file_exists($_SERVER['WINDIR'])) $font_loc=$_SERVER['WINDIR'].'\Fonts\arialbd.ttf';
41
+if (isset($_SERVER['WINDIR']) && @file_exists($_SERVER['WINDIR'])) $font_loc = $_SERVER['WINDIR'].'\Fonts\arialbd.ttf';
42 42
 if (empty($font_loc)) die('DOL_DEFAULT_TTF_BOLD must de defined with full path to a TTF font.');
43 43
 
44 44
 
@@ -50,7 +50,7 @@  discard block
 block discarded – undo
50 50
 * genbarcode is needed to render encodings other than EAN-12/EAN-13/ISBN
51 51
 */
52 52
 
53
-if (defined('PHP-BARCODE_PATH_COMMAND')) $genbarcode_loc=constant('PHP-BARCODE_PATH_COMMAND');
53
+if (defined('PHP-BARCODE_PATH_COMMAND')) $genbarcode_loc = constant('PHP-BARCODE_PATH_COMMAND');
54 54
 else $genbarcode_loc = $conf->global->GENBARCODE_LOCATION;
55 55
 
56 56
 
@@ -65,20 +65,20 @@  discard block
 block discarded – undo
65 65
  * @param	string	       $mode		'png' or 'jpg' ...
66 66
  * @return	array|string   $bars		array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info) or string with error message
67 67
  */
68
-function barcode_print($code, $encoding="ANY", $scale = 2 ,$mode = "png")
68
+function barcode_print($code, $encoding = "ANY", $scale = 2, $mode = "png")
69 69
 {
70 70
     dol_syslog("barcode.lib.php::barcode_print $code $encoding $scale $mode");
71 71
 
72
-    $bars=barcode_encode($code,$encoding);
73
-    if (! $bars || ! empty($bars['error']))
72
+    $bars = barcode_encode($code, $encoding);
73
+    if (!$bars || !empty($bars['error']))
74 74
     {
75 75
         // Return error message instead of array
76
-        if (empty($bars['error'])) $error='Bad Value '.$code.' for encoding '.$encoding;
77
-        else $error=$bars['error'];
76
+        if (empty($bars['error'])) $error = 'Bad Value '.$code.' for encoding '.$encoding;
77
+        else $error = $bars['error'];
78 78
         dol_syslog('barcode.lib.php::barcode_print '.$error, LOG_ERR);
79 79
         return $error;
80 80
     }
81
-    if (! $mode) $mode="png";
81
+    if (!$mode) $mode = "png";
82 82
     //if (preg_match("/^(text|txt|plain)$/i",$mode)) print barcode_outtext($bars['text'],$bars['bars']);
83 83
     //elseif (preg_match("/^(html|htm)$/i",$mode)) print barcode_outhtml($bars['text'],$bars['bars'], $scale,0, 0);
84 84
     //else
@@ -108,7 +108,7 @@  discard block
 block discarded – undo
108 108
  * @param	string	$encoding	Encoding
109 109
  * @return	array				array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info)
110 110
  */
111
-function barcode_encode($code,$encoding)
111
+function barcode_encode($code, $encoding)
112 112
 {
113 113
     global $genbarcode_loc;
114 114
 
@@ -116,23 +116,23 @@  discard block
 block discarded – undo
116 116
     (preg_match("/^ean$/i", $encoding))
117 117
 
118 118
     || (($encoding) && (preg_match("/^isbn$/i", $encoding))
119
-    && (( strlen($code)==9 || strlen($code)==10) ||
120
-    (((preg_match("/^978/", $code) && strlen($code)==12) ||
121
-    (strlen($code)==13)))))
119
+    && ((strlen($code) == 9 || strlen($code) == 10) ||
120
+    (((preg_match("/^978/", $code) && strlen($code) == 12) ||
121
+    (strlen($code) == 13)))))
122 122
 
123
-    || (( !isset($encoding) || !$encoding || (preg_match("/^ANY$/i", $encoding) ))
123
+    || ((!isset($encoding) || !$encoding || (preg_match("/^ANY$/i", $encoding)))
124 124
     && (preg_match("/^[0-9]{12,13}$/", $code)))
125 125
     )
126 126
     {
127 127
         /* use built-in EAN-Encoder */
128 128
         dol_syslog("barcode.lib.php::barcode_encode Use barcode_encode_ean");
129
-        $bars=barcode_encode_ean($code, $encoding);
129
+        $bars = barcode_encode_ean($code, $encoding);
130 130
     }
131 131
     else if (file_exists($genbarcode_loc))	// For example C39
132 132
     {
133 133
         /* use genbarcode */
134 134
         dol_syslog("barcode.lib.php::barcode_encode Use genbarcode ".$genbarcode_loc." code=".$code." encoding=".$encoding);
135
-        $bars=barcode_encode_genbarcode($code, $encoding);
135
+        $bars = barcode_encode_genbarcode($code, $encoding);
136 136
     }
137 137
     else
138 138
     {
@@ -160,14 +160,14 @@  discard block
 block discarded – undo
160 160
  */
161 161
 function barcode_gen_ean_sum($ean)
162 162
 {
163
-    $even=true; $esum=0; $osum=0;
164
-    $ln=strlen($ean)-1;
165
-    for ($i=$ln; $i>=0; $i--)
163
+    $even = true; $esum = 0; $osum = 0;
164
+    $ln = strlen($ean) - 1;
165
+    for ($i = $ln; $i >= 0; $i--)
166 166
     {
167
-        if ($even) $esum+=$ean[$i];	else $osum+=$ean[$i];
168
-        $even=!$even;
167
+        if ($even) $esum += $ean[$i]; else $osum += $ean[$i];
168
+        $even = !$even;
169 169
     }
170
-    return (10-((3*$esum+$osum)%10))%10;
170
+    return (10 - ((3 * $esum + $osum) % 10)) % 10;
171 171
 }
172 172
 
173 173
 /**
@@ -179,48 +179,48 @@  discard block
 block discarded – undo
179 179
  */
180 180
 function barcode_encode_ean($ean, $encoding = "EAN-13")
181 181
 {
182
-    $digits=array(3211,2221,2122,1411,1132,1231,1114,1312,1213,3112);
183
-    $mirror=array("000000","001011","001101","001110","010011","011001","011100","010101","010110","011010");
184
-    $guards=array("9a1a","1a1a1","a1a");
182
+    $digits = array(3211, 2221, 2122, 1411, 1132, 1231, 1114, 1312, 1213, 3112);
183
+    $mirror = array("000000", "001011", "001101", "001110", "010011", "011001", "011100", "010101", "010110", "011010");
184
+    $guards = array("9a1a", "1a1a1", "a1a");
185 185
 
186
-    $ean=trim($ean);
187
-    if (preg_match("/[^0-9]/i",$ean))
186
+    $ean = trim($ean);
187
+    if (preg_match("/[^0-9]/i", $ean))
188 188
     {
189 189
         return array("error"=>"Invalid encoding/code. encoding=".$encoding." code=".$ean." (not a numeric)", "text"=>"Invalid encoding/code. encoding=".$encoding." code=".$ean." (not a numeric)");
190 190
     }
191
-    $encoding=strtoupper($encoding);
192
-    if ($encoding=="ISBN")
191
+    $encoding = strtoupper($encoding);
192
+    if ($encoding == "ISBN")
193 193
     {
194
-        if (!preg_match("/^978/", $ean)) $ean="978".$ean;
194
+        if (!preg_match("/^978/", $ean)) $ean = "978".$ean;
195 195
     }
196
-    if (preg_match("/^978/", $ean)) $encoding="ISBN";
197
-    if (strlen($ean)<12 || strlen($ean)>13)
196
+    if (preg_match("/^978/", $ean)) $encoding = "ISBN";
197
+    if (strlen($ean) < 12 || strlen($ean) > 13)
198 198
     {
199 199
         return array("error"=>"Invalid encoding/code. encoding=".$encoding." code=".$ean." (must have 12/13 numbers)", "text"=>"Invalid encoding/code. encoding=".$encoding." code=".$ean." (must have 12/13 numbers)");
200 200
     }
201 201
 
202
-    $ean=substr($ean,0,12);
203
-    $eansum=barcode_gen_ean_sum($ean);
204
-    $ean.=$eansum;
205
-    $line=$guards[0];
206
-    for ($i=1;$i<13;$i++)
202
+    $ean = substr($ean, 0, 12);
203
+    $eansum = barcode_gen_ean_sum($ean);
204
+    $ean .= $eansum;
205
+    $line = $guards[0];
206
+    for ($i = 1; $i < 13; $i++)
207 207
     {
208
-        $str=$digits[$ean[$i]];
209
-        if ($i<7 && $mirror[$ean[0]][$i-1]==1) $line.=strrev($str); else $line.=$str;
210
-        if ($i==6) $line.=$guards[1];
208
+        $str = $digits[$ean[$i]];
209
+        if ($i < 7 && $mirror[$ean[0]][$i - 1] == 1) $line .= strrev($str); else $line .= $str;
210
+        if ($i == 6) $line .= $guards[1];
211 211
     }
212
-    $line.=$guards[2];
212
+    $line .= $guards[2];
213 213
 
214 214
     /* create text */
215
-    $pos=0;
216
-    $text="";
217
-    for ($a=0;$a<13;$a++)
215
+    $pos = 0;
216
+    $text = "";
217
+    for ($a = 0; $a < 13; $a++)
218 218
     {
219
-        if ($a>0) $text.=" ";
220
-        $text.="$pos:12:{$ean[$a]}";
221
-        if ($a==0) $pos+=12;
222
-        else if ($a==6) $pos+=12;
223
-        else $pos+=7;
219
+        if ($a > 0) $text .= " ";
220
+        $text .= "$pos:12:{$ean[$a]}";
221
+        if ($a == 0) $pos += 12;
222
+        else if ($a == 6) $pos += 12;
223
+        else $pos += 7;
224 224
     }
225 225
 
226 226
     return array(
@@ -238,30 +238,30 @@  discard block
 block discarded – undo
238 238
  * @param	string	$encoding	Encoding
239 239
  * @return	array				array('encoding': the encoding which has been used, 'bars': the bars, 'text': text-positioning info)
240 240
  */
241
-function barcode_encode_genbarcode($code,$encoding)
241
+function barcode_encode_genbarcode($code, $encoding)
242 242
 {
243 243
     global $genbarcode_loc;
244 244
 
245 245
     // Clean parameters
246
-    if (preg_match("/^ean$/i", $encoding) && strlen($code)==13) $code=substr($code,0,12);
247
-    if (!$encoding) $encoding="ANY";
248
-    $encoding=preg_replace("/[\\\|]/", "_", $encoding);
249
-    $code=preg_replace("/[\\\|]/", "_", $code);
246
+    if (preg_match("/^ean$/i", $encoding) && strlen($code) == 13) $code = substr($code, 0, 12);
247
+    if (!$encoding) $encoding = "ANY";
248
+    $encoding = preg_replace("/[\\\|]/", "_", $encoding);
249
+    $code = preg_replace("/[\\\|]/", "_", $code);
250 250
 
251
-    $command=escapeshellarg($genbarcode_loc);
251
+    $command = escapeshellarg($genbarcode_loc);
252 252
     //$paramclear=" \"".str_replace("\"", "\\\"",$code)."\" \"".str_replace("\"", "\\\"",strtoupper($encoding))."\"";
253
-    $paramclear=" ".escapeshellarg($code)." ".escapeshellarg(strtoupper($encoding));
253
+    $paramclear = " ".escapeshellarg($code)." ".escapeshellarg(strtoupper($encoding));
254 254
 
255
-    $fullcommandclear=$command." ".$paramclear." 2>&1";
255
+    $fullcommandclear = $command." ".$paramclear." 2>&1";
256 256
     //print $fullcommandclear."<br>\n";exit;
257 257
 
258 258
     dol_syslog("Run command ".$fullcommandclear);
259
-    $fp=popen($fullcommandclear, "r");
259
+    $fp = popen($fullcommandclear, "r");
260 260
     if ($fp)
261 261
     {
262
-        $bars=fgets($fp, 1024);
263
-        $text=fgets($fp, 1024);
264
-        $encoding=fgets($fp, 1024);
262
+        $bars = fgets($fp, 1024);
263
+        $text = fgets($fp, 1024);
264
+        $encoding = fgets($fp, 1024);
265 265
         pclose($fp);
266 266
     }
267 267
     else
@@ -270,16 +270,16 @@  discard block
 block discarded – undo
270 270
         return false;
271 271
     }
272 272
     //var_dump($bars);
273
-    $ret=array(
273
+    $ret = array(
274 274
 		"bars" => trim($bars),
275 275
 		"text" => trim($text),
276 276
 		"encoding" => trim($encoding),
277 277
     	"error" => ""
278 278
     );
279 279
     //var_dump($ret);
280
-    if (preg_match('/permission denied/i',$ret['bars']))
280
+    if (preg_match('/permission denied/i', $ret['bars']))
281 281
     {
282
-    	$ret['error']=$ret['bars']; $ret['bars']='';
282
+    	$ret['error'] = $ret['bars']; $ret['bars'] = '';
283 283
     	return $ret;
284 284
     }
285 285
     if (!$ret['bars']) return false;
@@ -310,101 +310,101 @@  discard block
 block discarded – undo
310 310
     //var_dump($font_loc);
311 311
 
312 312
     /* set defaults */
313
-    if ($scale<1) $scale=2;
314
-    $total_y=(int) $total_y;
315
-    if ($total_y<1) $total_y=(int) $scale * 60;
313
+    if ($scale < 1) $scale = 2;
314
+    $total_y = (int) $total_y;
315
+    if ($total_y < 1) $total_y = (int) $scale * 60;
316 316
     if (!$space)
317
-    $space=array('top'=>2*$scale,'bottom'=>2*$scale,'left'=>2*$scale,'right'=>2*$scale);
317
+    $space = array('top'=>2 * $scale, 'bottom'=>2 * $scale, 'left'=>2 * $scale, 'right'=>2 * $scale);
318 318
 
319 319
     /* count total width */
320
-    $xpos=0;
321
-    $width=true;
322
-    $ln=strlen($bars);
323
-    for ($i=0; $i<$ln; $i++)
320
+    $xpos = 0;
321
+    $width = true;
322
+    $ln = strlen($bars);
323
+    for ($i = 0; $i < $ln; $i++)
324 324
     {
325
-        $val=strtolower($bars[$i]);
325
+        $val = strtolower($bars[$i]);
326 326
         if ($width)
327 327
         {
328
-            $xpos+=$val*$scale;
329
-            $width=false;
328
+            $xpos += $val * $scale;
329
+            $width = false;
330 330
             continue;
331 331
         }
332 332
         if (preg_match("/[a-z]/", $val))
333 333
         {
334 334
             /* tall bar */
335
-            $val=ord($val)-ord('a')+1;
335
+            $val = ord($val) - ord('a') + 1;
336 336
         }
337
-        $xpos+=$val*$scale;
338
-        $width=true;
337
+        $xpos += $val * $scale;
338
+        $width = true;
339 339
     }
340 340
 
341 341
     /* allocate the image */
342
-    $total_x=( $xpos )+$space['right']+$space['right'];
343
-    $xpos=$space['left'];
344
-    if (! function_exists("imagecreate"))
342
+    $total_x = ($xpos) + $space['right'] + $space['right'];
343
+    $xpos = $space['left'];
344
+    if (!function_exists("imagecreate"))
345 345
     {
346 346
         print "You don't have the gd2 extension enabled<br>\n";
347 347
         return "";
348 348
     }
349
-    $im=imagecreate($total_x, $total_y);
349
+    $im = imagecreate($total_x, $total_y);
350 350
     /* create two images */
351
-    $col_bg=ImageColorAllocate($im,$bg_color[0],$bg_color[1],$bg_color[2]);
352
-    $col_bar=ImageColorAllocate($im,$bar_color[0],$bar_color[1],$bar_color[2]);
353
-    $col_text=ImageColorAllocate($im,$text_color[0],$text_color[1],$text_color[2]);
354
-    $height=round($total_y-($scale*10));
355
-    $height2=round($total_y-$space['bottom']);
351
+    $col_bg = ImageColorAllocate($im, $bg_color[0], $bg_color[1], $bg_color[2]);
352
+    $col_bar = ImageColorAllocate($im, $bar_color[0], $bar_color[1], $bar_color[2]);
353
+    $col_text = ImageColorAllocate($im, $text_color[0], $text_color[1], $text_color[2]);
354
+    $height = round($total_y - ($scale * 10));
355
+    $height2 = round($total_y - $space['bottom']);
356 356
 
357 357
     /* paint the bars */
358
-    $width=true;
359
-    $ln=strlen($bars);
360
-    for ($i=0; $i<$ln; $i++)
358
+    $width = true;
359
+    $ln = strlen($bars);
360
+    for ($i = 0; $i < $ln; $i++)
361 361
     {
362
-        $val=strtolower($bars[$i]);
362
+        $val = strtolower($bars[$i]);
363 363
         if ($width)
364 364
         {
365
-            $xpos+=$val*$scale;
366
-            $width=false;
365
+            $xpos += $val * $scale;
366
+            $width = false;
367 367
             continue;
368 368
         }
369 369
         if (preg_match("/[a-z]/", $val))
370 370
         {
371 371
             /* tall bar */
372
-            $val=ord($val)-ord('a')+1;
373
-            $h=$height2;
374
-        } else $h=$height;
375
-        imagefilledrectangle($im, $xpos, $space['top'], $xpos+($val*$scale)-1, $h, $col_bar);
376
-        $xpos+=$val*$scale;
377
-        $width=true;
372
+            $val = ord($val) - ord('a') + 1;
373
+            $h = $height2;
374
+        } else $h = $height;
375
+        imagefilledrectangle($im, $xpos, $space['top'], $xpos + ($val * $scale) - 1, $h, $col_bar);
376
+        $xpos += $val * $scale;
377
+        $width = true;
378 378
     }
379 379
 
380
-    $chars=explode(" ", $text);
380
+    $chars = explode(" ", $text);
381 381
     reset($chars);
382
-    while (list($n, $v)=each($chars))
382
+    while (list($n, $v) = each($chars))
383 383
     {
384 384
         if (trim($v))
385 385
         {
386
-            $inf=explode(":", $v);
387
-            $fontsize=$scale*($inf[1]/1.8);
388
-            $fontheight=$total_y-($fontsize/2.7)+2;
389
-            imagettftext($im, $fontsize, 0, $space['left']+($scale*$inf[0])+2, $fontheight, $col_text, $font_loc, $inf[2]);
386
+            $inf = explode(":", $v);
387
+            $fontsize = $scale * ($inf[1] / 1.8);
388
+            $fontheight = $total_y - ($fontsize / 2.7) + 2;
389
+            imagettftext($im, $fontsize, 0, $space['left'] + ($scale * $inf[0]) + 2, $fontheight, $col_text, $font_loc, $inf[2]);
390 390
         }
391 391
     }
392 392
 
393 393
     /* output the image */
394
-    $mode=strtolower($mode);
395
-    if ($mode=='jpg' || $mode=='jpeg')
394
+    $mode = strtolower($mode);
395
+    if ($mode == 'jpg' || $mode == 'jpeg')
396 396
     {
397 397
         header("Content-Type: image/jpeg; name=\"barcode.jpg\"");
398 398
         imagejpeg($im);
399 399
     }
400
-    else if ($mode=='gif')
400
+    else if ($mode == 'gif')
401 401
     {
402 402
         header("Content-Type: image/gif; name=\"barcode.gif\"");
403 403
         imagegif($im);
404 404
     }
405
-    else if (! empty($filebarcode))    // To wxrite into  afile onto disk
405
+    else if (!empty($filebarcode))    // To wxrite into  afile onto disk
406 406
     {
407
-        imagepng($im,$filebarcode);
407
+        imagepng($im, $filebarcode);
408 408
     }
409 409
     else
410 410
     {
Please login to merge, or discard this patch.
Braces   +87 added lines, -38 removed lines patch added patch discarded remove patch
@@ -35,11 +35,17 @@  discard block
 block discarded – undo
35 35
 /* ******************************************************************** */
36 36
 /*                          FONT FILE                                   */
37 37
 /* ******************************************************************** */
38
-if (defined('DOL_DEFAULT_TTF_BOLD')) $font_loc=constant('DOL_DEFAULT_TTF_BOLD');
38
+if (defined('DOL_DEFAULT_TTF_BOLD')) {
39
+    $font_loc=constant('DOL_DEFAULT_TTF_BOLD');
40
+}
39 41
 // Automatic-Detection of Font if running Windows
40 42
 // @CHANGE LDR
41
-if (isset($_SERVER['WINDIR']) && @file_exists($_SERVER['WINDIR'])) $font_loc=$_SERVER['WINDIR'].'\Fonts\arialbd.ttf';
42
-if (empty($font_loc)) die('DOL_DEFAULT_TTF_BOLD must de defined with full path to a TTF font.');
43
+if (isset($_SERVER['WINDIR']) && @file_exists($_SERVER['WINDIR'])) {
44
+    $font_loc=$_SERVER['WINDIR'].'\Fonts\arialbd.ttf';
45
+}
46
+if (empty($font_loc)) {
47
+    die('DOL_DEFAULT_TTF_BOLD must de defined with full path to a TTF font.');
48
+}
43 49
 
44 50
 
45 51
 /* ******************************************************************** */
@@ -50,8 +56,11 @@  discard block
 block discarded – undo
50 56
 * genbarcode is needed to render encodings other than EAN-12/EAN-13/ISBN
51 57
 */
52 58
 
53
-if (defined('PHP-BARCODE_PATH_COMMAND')) $genbarcode_loc=constant('PHP-BARCODE_PATH_COMMAND');
54
-else $genbarcode_loc = $conf->global->GENBARCODE_LOCATION;
59
+if (defined('PHP-BARCODE_PATH_COMMAND')) {
60
+    $genbarcode_loc=constant('PHP-BARCODE_PATH_COMMAND');
61
+} else {
62
+    $genbarcode_loc = $conf->global->GENBARCODE_LOCATION;
63
+}
55 64
 
56 65
 
57 66
 
@@ -73,12 +82,17 @@  discard block
 block discarded – undo
73 82
     if (! $bars || ! empty($bars['error']))
74 83
     {
75 84
         // Return error message instead of array
76
-        if (empty($bars['error'])) $error='Bad Value '.$code.' for encoding '.$encoding;
77
-        else $error=$bars['error'];
85
+        if (empty($bars['error'])) {
86
+            $error='Bad Value '.$code.' for encoding '.$encoding;
87
+        } else {
88
+            $error=$bars['error'];
89
+        }
78 90
         dol_syslog('barcode.lib.php::barcode_print '.$error, LOG_ERR);
79 91
         return $error;
80 92
     }
81
-    if (! $mode) $mode="png";
93
+    if (! $mode) {
94
+        $mode="png";
95
+    }
82 96
     //if (preg_match("/^(text|txt|plain)$/i",$mode)) print barcode_outtext($bars['text'],$bars['bars']);
83 97
     //elseif (preg_match("/^(html|htm)$/i",$mode)) print barcode_outhtml($bars['text'],$bars['bars'], $scale,0, 0);
84 98
     //else
@@ -127,14 +141,14 @@  discard block
 block discarded – undo
127 141
         /* use built-in EAN-Encoder */
128 142
         dol_syslog("barcode.lib.php::barcode_encode Use barcode_encode_ean");
129 143
         $bars=barcode_encode_ean($code, $encoding);
130
-    }
131
-    else if (file_exists($genbarcode_loc))	// For example C39
144
+    } else if (file_exists($genbarcode_loc)) {
145
+        // For example C39
132 146
     {
133 147
         /* use genbarcode */
134 148
         dol_syslog("barcode.lib.php::barcode_encode Use genbarcode ".$genbarcode_loc." code=".$code." encoding=".$encoding);
135
-        $bars=barcode_encode_genbarcode($code, $encoding);
136 149
     }
137
-    else
150
+        $bars=barcode_encode_genbarcode($code, $encoding);
151
+    } else
138 152
     {
139 153
         print "barcode_encode needs an external programm for encodings other then EAN/ISBN (code=".$code.", encoding=".$encoding.")<BR>\n";
140 154
         print "<UL>\n";
@@ -164,7 +178,11 @@  discard block
 block discarded – undo
164 178
     $ln=strlen($ean)-1;
165 179
     for ($i=$ln; $i>=0; $i--)
166 180
     {
167
-        if ($even) $esum+=$ean[$i];	else $osum+=$ean[$i];
181
+        if ($even) {
182
+            $esum+=$ean[$i];
183
+        } else {
184
+            $osum+=$ean[$i];
185
+        }
168 186
         $even=!$even;
169 187
     }
170 188
     return (10-((3*$esum+$osum)%10))%10;
@@ -191,9 +209,13 @@  discard block
 block discarded – undo
191 209
     $encoding=strtoupper($encoding);
192 210
     if ($encoding=="ISBN")
193 211
     {
194
-        if (!preg_match("/^978/", $ean)) $ean="978".$ean;
212
+        if (!preg_match("/^978/", $ean)) {
213
+            $ean="978".$ean;
214
+        }
215
+    }
216
+    if (preg_match("/^978/", $ean)) {
217
+        $encoding="ISBN";
195 218
     }
196
-    if (preg_match("/^978/", $ean)) $encoding="ISBN";
197 219
     if (strlen($ean)<12 || strlen($ean)>13)
198 220
     {
199 221
         return array("error"=>"Invalid encoding/code. encoding=".$encoding." code=".$ean." (must have 12/13 numbers)", "text"=>"Invalid encoding/code. encoding=".$encoding." code=".$ean." (must have 12/13 numbers)");
@@ -206,8 +228,14 @@  discard block
 block discarded – undo
206 228
     for ($i=1;$i<13;$i++)
207 229
     {
208 230
         $str=$digits[$ean[$i]];
209
-        if ($i<7 && $mirror[$ean[0]][$i-1]==1) $line.=strrev($str); else $line.=$str;
210
-        if ($i==6) $line.=$guards[1];
231
+        if ($i<7 && $mirror[$ean[0]][$i-1]==1) {
232
+            $line.=strrev($str);
233
+        } else {
234
+            $line.=$str;
235
+        }
236
+        if ($i==6) {
237
+            $line.=$guards[1];
238
+        }
211 239
     }
212 240
     $line.=$guards[2];
213 241
 
@@ -216,11 +244,17 @@  discard block
 block discarded – undo
216 244
     $text="";
217 245
     for ($a=0;$a<13;$a++)
218 246
     {
219
-        if ($a>0) $text.=" ";
247
+        if ($a>0) {
248
+            $text.=" ";
249
+        }
220 250
         $text.="$pos:12:{$ean[$a]}";
221
-        if ($a==0) $pos+=12;
222
-        else if ($a==6) $pos+=12;
223
-        else $pos+=7;
251
+        if ($a==0) {
252
+            $pos+=12;
253
+        } else if ($a==6) {
254
+            $pos+=12;
255
+        } else {
256
+            $pos+=7;
257
+        }
224 258
     }
225 259
 
226 260
     return array(
@@ -243,8 +277,12 @@  discard block
 block discarded – undo
243 277
     global $genbarcode_loc;
244 278
 
245 279
     // Clean parameters
246
-    if (preg_match("/^ean$/i", $encoding) && strlen($code)==13) $code=substr($code,0,12);
247
-    if (!$encoding) $encoding="ANY";
280
+    if (preg_match("/^ean$/i", $encoding) && strlen($code)==13) {
281
+        $code=substr($code,0,12);
282
+    }
283
+    if (!$encoding) {
284
+        $encoding="ANY";
285
+    }
248 286
     $encoding=preg_replace("/[\\\|]/", "_", $encoding);
249 287
     $code=preg_replace("/[\\\|]/", "_", $code);
250 288
 
@@ -263,8 +301,7 @@  discard block
 block discarded – undo
263 301
         $text=fgets($fp, 1024);
264 302
         $encoding=fgets($fp, 1024);
265 303
         pclose($fp);
266
-    }
267
-    else
304
+    } else
268 305
     {
269 306
         dol_syslog("barcode.lib.php::barcode_encode_genbarcode failed to run popen ".$fullcommandclear, LOG_ERR);
270 307
         return false;
@@ -282,9 +319,15 @@  discard block
 block discarded – undo
282 319
     	$ret['error']=$ret['bars']; $ret['bars']='';
283 320
     	return $ret;
284 321
     }
285
-    if (!$ret['bars']) return false;
286
-    if (!$ret['text']) return false;
287
-    if (!$ret['encoding']) return false;
322
+    if (!$ret['bars']) {
323
+        return false;
324
+    }
325
+    if (!$ret['text']) {
326
+        return false;
327
+    }
328
+    if (!$ret['encoding']) {
329
+        return false;
330
+    }
288 331
     return $ret;
289 332
 }
290 333
 
@@ -310,11 +353,16 @@  discard block
 block discarded – undo
310 353
     //var_dump($font_loc);
311 354
 
312 355
     /* set defaults */
313
-    if ($scale<1) $scale=2;
356
+    if ($scale<1) {
357
+        $scale=2;
358
+    }
314 359
     $total_y=(int) $total_y;
315
-    if ($total_y<1) $total_y=(int) $scale * 60;
316
-    if (!$space)
317
-    $space=array('top'=>2*$scale,'bottom'=>2*$scale,'left'=>2*$scale,'right'=>2*$scale);
360
+    if ($total_y<1) {
361
+        $total_y=(int) $scale * 60;
362
+    }
363
+    if (!$space) {
364
+        $space=array('top'=>2*$scale,'bottom'=>2*$scale,'left'=>2*$scale,'right'=>2*$scale);
365
+    }
318 366
 
319 367
     /* count total width */
320 368
     $xpos=0;
@@ -371,7 +419,9 @@  discard block
 block discarded – undo
371 419
             /* tall bar */
372 420
             $val=ord($val)-ord('a')+1;
373 421
             $h=$height2;
374
-        } else $h=$height;
422
+        } else {
423
+            $h=$height;
424
+        }
375 425
         imagefilledrectangle($im, $xpos, $space['top'], $xpos+($val*$scale)-1, $h, $col_bar);
376 426
         $xpos+=$val*$scale;
377 427
         $width=true;
@@ -396,17 +446,16 @@  discard block
 block discarded – undo
396 446
     {
397 447
         header("Content-Type: image/jpeg; name=\"barcode.jpg\"");
398 448
         imagejpeg($im);
399
-    }
400
-    else if ($mode=='gif')
449
+    } else if ($mode=='gif')
401 450
     {
402 451
         header("Content-Type: image/gif; name=\"barcode.gif\"");
403 452
         imagegif($im);
404
-    }
405
-    else if (! empty($filebarcode))    // To wxrite into  afile onto disk
453
+    } else if (! empty($filebarcode)) {
454
+        // To wxrite into  afile onto disk
406 455
     {
407 456
         imagepng($im,$filebarcode);
408 457
     }
409
-    else
458
+    } else
410 459
     {
411 460
         header("Content-Type: image/png; name=\"barcode.png\"");
412 461
         imagepng($im);
Please login to merge, or discard this patch.
dolibarr/htdocs/core/lib/accounting.lib.php 3 patches
Indentation   +54 added lines, -54 removed lines patch added patch discarded remove patch
@@ -31,25 +31,25 @@  discard block
 block discarded – undo
31 31
  */
32 32
 function accounting_prepare_head(AccountingAccount $object)
33 33
 {
34
-	global $langs, $conf;
34
+    global $langs, $conf;
35 35
 
36
-	$h = 0;
37
-	$head = array ();
36
+    $h = 0;
37
+    $head = array ();
38 38
 
39
-	$head[$h][0] = DOL_URL_ROOT.'/accountancy/admin/card.php?id=' . $object->id;
40
-	$head[$h][1] = $langs->trans("Card");
41
-	$head[$h][2] = 'card';
42
-	$h ++;
39
+    $head[$h][0] = DOL_URL_ROOT.'/accountancy/admin/card.php?id=' . $object->id;
40
+    $head[$h][1] = $langs->trans("Card");
41
+    $head[$h][2] = 'card';
42
+    $h ++;
43 43
 
44
-	// Show more tabs from modules
45
-	// Entries must be declared in modules descriptor with line
46
-	// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
47
-	// $this->tabs = array('entity:-tabname); to remove a tab
48
-	complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_account');
44
+    // Show more tabs from modules
45
+    // Entries must be declared in modules descriptor with line
46
+    // $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
47
+    // $this->tabs = array('entity:-tabname); to remove a tab
48
+    complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_account');
49 49
 
50
-	complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_account', 'remove');
50
+    complete_head_from_modules($conf, $langs, $object, $head, $h, 'accounting_account', 'remove');
51 51
 
52
-	return $head;
52
+    return $head;
53 53
 }
54 54
 
55 55
 /**
@@ -60,9 +60,9 @@  discard block
 block discarded – undo
60 60
  */
61 61
 function clean_account($account)
62 62
 {
63
-	$account = rtrim($account,"0");
63
+    $account = rtrim($account,"0");
64 64
 
65
-	return $account;
65
+    return $account;
66 66
 }
67 67
 
68 68
 /**
@@ -73,31 +73,31 @@  discard block
 block discarded – undo
73 73
  */
74 74
 function length_accountg($account)
75 75
 {
76
-	global $conf;
76
+    global $conf;
77 77
 
78
-	if ($account < 0 || empty($account)) return '';
78
+    if ($account < 0 || empty($account)) return '';
79 79
 
80
-	if (! empty($conf->global->ACCOUNTING_MANAGE_ZERO)) return $account;
80
+    if (! empty($conf->global->ACCOUNTING_MANAGE_ZERO)) return $account;
81 81
 
82
-	$g = $conf->global->ACCOUNTING_LENGTH_GACCOUNT;
83
-	if (! empty($g)) {
84
-		// Clean parameters
85
-		$i = strlen($account);
82
+    $g = $conf->global->ACCOUNTING_LENGTH_GACCOUNT;
83
+    if (! empty($g)) {
84
+        // Clean parameters
85
+        $i = strlen($account);
86 86
 
87
-		if ($i >= 1) {
88
-			while ( $i < $g ) {
89
-				$account .= '0';
87
+        if ($i >= 1) {
88
+            while ( $i < $g ) {
89
+                $account .= '0';
90 90
 
91
-				$i ++;
92
-			}
91
+                $i ++;
92
+            }
93 93
 
94
-			return $account;
95
-		} else {
96
-			return $account;
97
-		}
98
-	} else {
99
-		return $account;
100
-	}
94
+            return $account;
95
+        } else {
96
+            return $account;
97
+        }
98
+    } else {
99
+        return $account;
100
+    }
101 101
 }
102 102
 
103 103
 /**
@@ -108,31 +108,31 @@  discard block
 block discarded – undo
108 108
  */
109 109
 function length_accounta($accounta)
110 110
 {
111
-	global $conf, $langs;
111
+    global $conf, $langs;
112 112
 
113
-	if ($accounta < 0 || empty($accounta)) return '';
113
+    if ($accounta < 0 || empty($accounta)) return '';
114 114
 
115
-	if (! empty($conf->global->ACCOUNTING_MANAGE_ZERO)) return $accounta;
115
+    if (! empty($conf->global->ACCOUNTING_MANAGE_ZERO)) return $accounta;
116 116
 
117
-	$a = $conf->global->ACCOUNTING_LENGTH_AACCOUNT;
118
-	if (! empty($a)) {
119
-		// Clean parameters
120
-		$i = strlen($accounta);
117
+    $a = $conf->global->ACCOUNTING_LENGTH_AACCOUNT;
118
+    if (! empty($a)) {
119
+        // Clean parameters
120
+        $i = strlen($accounta);
121 121
 
122
-		if ($i >= 1) {
123
-			while ( $i < $a ) {
124
-				$accounta .= '0';
122
+        if ($i >= 1) {
123
+            while ( $i < $a ) {
124
+                $accounta .= '0';
125 125
 
126
-				$i ++;
127
-			}
126
+                $i ++;
127
+            }
128 128
 
129
-			return $accounta;
130
-		} else {
131
-			return $accounta;
132
-		}
133
-	} else {
134
-		return $accounta;
135
-	}
129
+            return $accounta;
130
+        } else {
131
+            return $accounta;
132
+        }
133
+    } else {
134
+        return $accounta;
135
+    }
136 136
 }
137 137
 
138 138
 
Please login to merge, or discard this patch.
Spacing   +20 added lines, -20 removed lines patch added patch discarded remove patch
@@ -34,12 +34,12 @@  discard block
 block discarded – undo
34 34
 	global $langs, $conf;
35 35
 
36 36
 	$h = 0;
37
-	$head = array ();
37
+	$head = array();
38 38
 
39
-	$head[$h][0] = DOL_URL_ROOT.'/accountancy/admin/card.php?id=' . $object->id;
39
+	$head[$h][0] = DOL_URL_ROOT.'/accountancy/admin/card.php?id='.$object->id;
40 40
 	$head[$h][1] = $langs->trans("Card");
41 41
 	$head[$h][2] = 'card';
42
-	$h ++;
42
+	$h++;
43 43
 
44 44
 	// Show more tabs from modules
45 45
 	// Entries must be declared in modules descriptor with line
@@ -60,7 +60,7 @@  discard block
 block discarded – undo
60 60
  */
61 61
 function clean_account($account)
62 62
 {
63
-	$account = rtrim($account,"0");
63
+	$account = rtrim($account, "0");
64 64
 
65 65
 	return $account;
66 66
 }
@@ -77,18 +77,18 @@  discard block
 block discarded – undo
77 77
 
78 78
 	if ($account < 0 || empty($account)) return '';
79 79
 
80
-	if (! empty($conf->global->ACCOUNTING_MANAGE_ZERO)) return $account;
80
+	if (!empty($conf->global->ACCOUNTING_MANAGE_ZERO)) return $account;
81 81
 
82 82
 	$g = $conf->global->ACCOUNTING_LENGTH_GACCOUNT;
83
-	if (! empty($g)) {
83
+	if (!empty($g)) {
84 84
 		// Clean parameters
85 85
 		$i = strlen($account);
86 86
 
87 87
 		if ($i >= 1) {
88
-			while ( $i < $g ) {
88
+			while ($i < $g) {
89 89
 				$account .= '0';
90 90
 
91
-				$i ++;
91
+				$i++;
92 92
 			}
93 93
 
94 94
 			return $account;
@@ -112,18 +112,18 @@  discard block
 block discarded – undo
112 112
 
113 113
 	if ($accounta < 0 || empty($accounta)) return '';
114 114
 
115
-	if (! empty($conf->global->ACCOUNTING_MANAGE_ZERO)) return $accounta;
115
+	if (!empty($conf->global->ACCOUNTING_MANAGE_ZERO)) return $accounta;
116 116
 
117 117
 	$a = $conf->global->ACCOUNTING_LENGTH_AACCOUNT;
118
-	if (! empty($a)) {
118
+	if (!empty($a)) {
119 119
 		// Clean parameters
120 120
 		$i = strlen($accounta);
121 121
 
122 122
 		if ($i >= 1) {
123
-			while ( $i < $a ) {
123
+			while ($i < $a) {
124 124
 				$accounta .= '0';
125 125
 
126
-				$i ++;
126
+				$i++;
127 127
 			}
128 128
 
129 129
 			return $accounta;
@@ -152,17 +152,17 @@  discard block
 block discarded – undo
152 152
  *  @param  string              $varlink        Add a variable into the address of the page
153 153
  *	@return	void
154 154
  */
155
-function journalHead($nom,$variante,$period,$periodlink,$description,$builddate,$exportlink='',$moreparam=array(),$calcmode='', $varlink='')
155
+function journalHead($nom, $variante, $period, $periodlink, $description, $builddate, $exportlink = '', $moreparam = array(), $calcmode = '', $varlink = '')
156 156
 {
157 157
     global $langs;
158 158
 
159
-    if (empty($hselected)) $hselected='report';
159
+    if (empty($hselected)) $hselected = 'report';
160 160
 
161 161
     print "\n\n<!-- debut cartouche journal -->\n";
162 162
 
163
-    if(! empty($varlink)) $varlink = '?'.$varlink;
163
+    if (!empty($varlink)) $varlink = '?'.$varlink;
164 164
 
165
-    $h=0;
165
+    $h = 0;
166 166
     $head[$h][0] = $_SERVER["PHP_SELF"].$varlink;
167 167
     $head[$h][1] = $langs->trans("Journalization");
168 168
     $head[$h][2] = 'journal';
@@ -171,7 +171,7 @@  discard block
 block discarded – undo
171 171
 
172 172
     dol_fiche_head($head, 'journal');
173 173
 
174
-    foreach($moreparam as $key => $value)
174
+    foreach ($moreparam as $key => $value)
175 175
     {
176 176
         print '<input type="hidden" name="'.$key.'" value="'.$value.'">';
177 177
     }
@@ -180,7 +180,7 @@  discard block
 block discarded – undo
180 180
     // Ligne de titre
181 181
     print '<tr>';
182 182
     print '<td width="110">'.$langs->trans("Name").'</td>';
183
-    if (! $variantexxx) print '<td colspan="3">';
183
+    if (!$variantexxx) print '<td colspan="3">';
184 184
     else print '<td>';
185 185
     print $nom;
186 186
     if ($variantexxx) print '</td><td colspan="2">'.$variantexxx;
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
     {
193 193
         print '<tr>';
194 194
         print '<td width="110">'.$langs->trans("CalculationMode").'</td>';
195
-        if (! $variante) print '<td colspan="3">';
195
+        if (!$variante) print '<td colspan="3">';
196 196
         else print '<td>';
197 197
         print $calcmode;
198 198
         if ($variante) print '</td><td colspan="2">'.$variante;
@@ -203,7 +203,7 @@  discard block
 block discarded – undo
203 203
     // Ligne de la periode d'analyse du rapport
204 204
     print '<tr>';
205 205
     print '<td>'.$langs->trans("ReportPeriod").'</td>';
206
-    if (! $periodlink) print '<td colspan="3">';
206
+    if (!$periodlink) print '<td colspan="3">';
207 207
     else print '<td>';
208 208
     if ($period) print $period;
209 209
     if ($periodlink) print '</td><td colspan="2">'.$periodlink;
Please login to merge, or discard this patch.
Braces   +45 added lines, -16 removed lines patch added patch discarded remove patch
@@ -75,9 +75,13 @@  discard block
 block discarded – undo
75 75
 {
76 76
 	global $conf;
77 77
 
78
-	if ($account < 0 || empty($account)) return '';
78
+	if ($account < 0 || empty($account)) {
79
+	    return '';
80
+	}
79 81
 
80
-	if (! empty($conf->global->ACCOUNTING_MANAGE_ZERO)) return $account;
82
+	if (! empty($conf->global->ACCOUNTING_MANAGE_ZERO)) {
83
+	    return $account;
84
+	}
81 85
 
82 86
 	$g = $conf->global->ACCOUNTING_LENGTH_GACCOUNT;
83 87
 	if (! empty($g)) {
@@ -110,9 +114,13 @@  discard block
 block discarded – undo
110 114
 {
111 115
 	global $conf, $langs;
112 116
 
113
-	if ($accounta < 0 || empty($accounta)) return '';
117
+	if ($accounta < 0 || empty($accounta)) {
118
+	    return '';
119
+	}
114 120
 
115
-	if (! empty($conf->global->ACCOUNTING_MANAGE_ZERO)) return $accounta;
121
+	if (! empty($conf->global->ACCOUNTING_MANAGE_ZERO)) {
122
+	    return $accounta;
123
+	}
116 124
 
117 125
 	$a = $conf->global->ACCOUNTING_LENGTH_AACCOUNT;
118 126
 	if (! empty($a)) {
@@ -156,11 +164,15 @@  discard block
 block discarded – undo
156 164
 {
157 165
     global $langs;
158 166
 
159
-    if (empty($hselected)) $hselected='report';
167
+    if (empty($hselected)) {
168
+        $hselected='report';
169
+    }
160 170
 
161 171
     print "\n\n<!-- debut cartouche journal -->\n";
162 172
 
163
-    if(! empty($varlink)) $varlink = '?'.$varlink;
173
+    if(! empty($varlink)) {
174
+        $varlink = '?'.$varlink;
175
+    }
164 176
 
165 177
     $h=0;
166 178
     $head[$h][0] = $_SERVER["PHP_SELF"].$varlink;
@@ -180,10 +192,15 @@  discard block
 block discarded – undo
180 192
     // Ligne de titre
181 193
     print '<tr>';
182 194
     print '<td width="110">'.$langs->trans("Name").'</td>';
183
-    if (! $variantexxx) print '<td colspan="3">';
184
-    else print '<td>';
195
+    if (! $variantexxx) {
196
+        print '<td colspan="3">';
197
+    } else {
198
+        print '<td>';
199
+    }
185 200
     print $nom;
186
-    if ($variantexxx) print '</td><td colspan="2">'.$variantexxx;
201
+    if ($variantexxx) {
202
+        print '</td><td colspan="2">'.$variantexxx;
203
+    }
187 204
     print '</td>';
188 205
     print '</tr>';
189 206
 
@@ -192,10 +209,15 @@  discard block
 block discarded – undo
192 209
     {
193 210
         print '<tr>';
194 211
         print '<td width="110">'.$langs->trans("CalculationMode").'</td>';
195
-        if (! $variante) print '<td colspan="3">';
196
-        else print '<td>';
212
+        if (! $variante) {
213
+            print '<td colspan="3">';
214
+        } else {
215
+            print '<td>';
216
+        }
197 217
         print $calcmode;
198
-        if ($variante) print '</td><td colspan="2">'.$variante;
218
+        if ($variante) {
219
+            print '</td><td colspan="2">'.$variante;
220
+        }
199 221
         print '</td>';
200 222
         print '</tr>';
201 223
     }
@@ -203,10 +225,17 @@  discard block
 block discarded – undo
203 225
     // Ligne de la periode d'analyse du rapport
204 226
     print '<tr>';
205 227
     print '<td>'.$langs->trans("ReportPeriod").'</td>';
206
-    if (! $periodlink) print '<td colspan="3">';
207
-    else print '<td>';
208
-    if ($period) print $period;
209
-    if ($periodlink) print '</td><td colspan="2">'.$periodlink;
228
+    if (! $periodlink) {
229
+        print '<td colspan="3">';
230
+    } else {
231
+        print '<td>';
232
+    }
233
+    if ($period) {
234
+        print $period;
235
+    }
236
+    if ($periodlink) {
237
+        print '</td><td colspan="2">'.$periodlink;
238
+    }
210 239
     print '</td>';
211 240
     print '</tr>';
212 241
 
Please login to merge, or discard this patch.