Test Failed
Push — master ( e0c20c...b8c830 )
by Alxarafe
39:29
created
dolibarr/htdocs/expedition/document.php 3 patches
Indentation   +94 added lines, -94 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
35 35
 require_once DOL_DOCUMENT_ROOT .'/expedition/class/expedition.class.php';
36 36
 if (! empty($conf->projet->enabled)) {
37
-	require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
37
+    require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
38 38
 }
39 39
 
40 40
 // Load translation files required by the page
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 // Security check
49 49
 if ($user->societe_id)
50 50
 {
51
-	$socid = $user->societe_id;
51
+    $socid = $user->societe_id;
52 52
 }
53 53
 $result=restrictedArea($user,'expedition',$id,'');
54 54
 
@@ -71,8 +71,8 @@  discard block
 block discarded – undo
71 71
  */
72 72
 if ($object->fetch($id))
73 73
 {
74
-	$object->fetch_thirdparty();
75
-	$upload_dir = $conf->expedition->dir_output . "/sending/" . dol_sanitizeFileName($object->ref);
74
+    $object->fetch_thirdparty();
75
+    $upload_dir = $conf->expedition->dir_output . "/sending/" . dol_sanitizeFileName($object->ref);
76 76
 }
77 77
 
78 78
 include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
@@ -87,102 +87,102 @@  discard block
 block discarded – undo
87 87
 $form = new Form($db);
88 88
 
89 89
 if ($id > 0 || ! empty($ref)){
90
-	if ($object->fetch($id, $ref)){
91
-		$object->fetch_thirdparty();
90
+    if ($object->fetch($id, $ref)){
91
+        $object->fetch_thirdparty();
92 92
 
93
-		$upload_dir = $conf->expedition->dir_output.'/sending/'.dol_sanitizeFileName($object->ref);
93
+        $upload_dir = $conf->expedition->dir_output.'/sending/'.dol_sanitizeFileName($object->ref);
94 94
 
95
-		$head = shipping_prepare_head($object);
96
-		dol_fiche_head($head, 'documents', $langs->trans("Shipment"), -1, 'sending');
95
+        $head = shipping_prepare_head($object);
96
+        dol_fiche_head($head, 'documents', $langs->trans("Shipment"), -1, 'sending');
97 97
 	
98 98
 
99
-		// Build file list
100
-		$filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
101
-		$totalsize=0;
102
-		foreach($filearray as $key => $file){
103
-		    $totalsize+=$file['size'];
104
-		}
105
-
106
-		// Shipment card
107
-		$linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">'.$langs->trans("BackToList").'</a>';
108
-
109
-
110
-		$morehtmlref='<div class="refidno">';
111
-		// Ref customer
112
-		$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
113
-		$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
114
-		// Thirdparty
115
-		$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
116
-
117
-		// Project
118
-		if (! empty($conf->projet->enabled)) {
119
-			$langs->load("projects");
120
-			$morehtmlref .= '<br>' . $langs->trans('Project') . ' ';
121
-			if (0) {    // Do not change on shipment
122
-				if ($action != 'classify') {
123
-					$morehtmlref .= '<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
124
-				}
125
-				if ($action == 'classify') {
126
-					// $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
127
-					$morehtmlref .= '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '">';
128
-					$morehtmlref .= '<input type="hidden" name="action" value="classin">';
129
-					$morehtmlref .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
130
-					$morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
131
-					$morehtmlref .= '<input type="submit" class="button" value="' . $langs->trans("Modify") . '">';
132
-					$morehtmlref .= '</form>';
133
-				} else {
134
-					$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
135
-				}
136
-			} else {
137
-				// We don't have project on shipment, so we will use the project or source object instead
138
-				// TODO Add project on shipment
139
-				$morehtmlref .= ' : ';
140
-				if (! empty($objectsrc->fk_project)) {
141
-					$proj = new Project($db);
142
-					$proj->fetch($objectsrc->fk_project);
143
-					$morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $objectsrc->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
144
-					$morehtmlref .= $proj->ref;
145
-					$morehtmlref .= '</a>';
146
-				} else {
147
-					$morehtmlref .= '';
148
-				}
149
-			}
150
-		}
151
-		$morehtmlref.='</div>';
152
-
153
-		// Order card
154
-
155
-		$linkback = '<a href="' . DOL_URL_ROOT . '/expedition/list.php' . (! empty($socid) ? '?socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
156
-
157
-		dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
158
-
159
-		print '<div class="fichecenter">';
160
-		print '<div class="underbanner clearboth"></div>';
161
-
162
-		print '<table class="border" width="100%">';
163
-
164
-		print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
165
-		print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize,1,1).'</td></tr>';
166
-
167
-		print "</table>\n";
168
-
169
-		print "</div>\n";
170
-
171
-		print dol_fiche_end();
172
-
173
-		$modulepart = 'expedition';
174
-		$permission = $user->rights->expedition->creer;
175
-		$permtoedit = $user->rights->expedition->creer;
176
-		$param = '&id=' . $object->id;
177
-		include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
178
-	}
179
-	else{
180
-		dol_print_error($db);
181
-	}
99
+        // Build file list
100
+        $filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
101
+        $totalsize=0;
102
+        foreach($filearray as $key => $file){
103
+            $totalsize+=$file['size'];
104
+        }
105
+
106
+        // Shipment card
107
+        $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">'.$langs->trans("BackToList").'</a>';
108
+
109
+
110
+        $morehtmlref='<div class="refidno">';
111
+        // Ref customer
112
+        $morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
113
+        $morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
114
+        // Thirdparty
115
+        $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
116
+
117
+        // Project
118
+        if (! empty($conf->projet->enabled)) {
119
+            $langs->load("projects");
120
+            $morehtmlref .= '<br>' . $langs->trans('Project') . ' ';
121
+            if (0) {    // Do not change on shipment
122
+                if ($action != 'classify') {
123
+                    $morehtmlref .= '<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
124
+                }
125
+                if ($action == 'classify') {
126
+                    // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
127
+                    $morehtmlref .= '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '">';
128
+                    $morehtmlref .= '<input type="hidden" name="action" value="classin">';
129
+                    $morehtmlref .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
130
+                    $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
131
+                    $morehtmlref .= '<input type="submit" class="button" value="' . $langs->trans("Modify") . '">';
132
+                    $morehtmlref .= '</form>';
133
+                } else {
134
+                    $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
135
+                }
136
+            } else {
137
+                // We don't have project on shipment, so we will use the project or source object instead
138
+                // TODO Add project on shipment
139
+                $morehtmlref .= ' : ';
140
+                if (! empty($objectsrc->fk_project)) {
141
+                    $proj = new Project($db);
142
+                    $proj->fetch($objectsrc->fk_project);
143
+                    $morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $objectsrc->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
144
+                    $morehtmlref .= $proj->ref;
145
+                    $morehtmlref .= '</a>';
146
+                } else {
147
+                    $morehtmlref .= '';
148
+                }
149
+            }
150
+        }
151
+        $morehtmlref.='</div>';
152
+
153
+        // Order card
154
+
155
+        $linkback = '<a href="' . DOL_URL_ROOT . '/expedition/list.php' . (! empty($socid) ? '?socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
156
+
157
+        dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
158
+
159
+        print '<div class="fichecenter">';
160
+        print '<div class="underbanner clearboth"></div>';
161
+
162
+        print '<table class="border" width="100%">';
163
+
164
+        print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
165
+        print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize,1,1).'</td></tr>';
166
+
167
+        print "</table>\n";
168
+
169
+        print "</div>\n";
170
+
171
+        print dol_fiche_end();
172
+
173
+        $modulepart = 'expedition';
174
+        $permission = $user->rights->expedition->creer;
175
+        $permtoedit = $user->rights->expedition->creer;
176
+        $param = '&id=' . $object->id;
177
+        include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
178
+    }
179
+    else{
180
+        dol_print_error($db);
181
+    }
182 182
 }
183 183
 else{
184
-	header('Location: index.php');
185
-	exit;
184
+    header('Location: index.php');
185
+    exit;
186 186
 }
187 187
 
188 188
 // End of page
Please login to merge, or discard this patch.
Spacing   +41 added lines, -41 removed lines patch added patch discarded remove patch
@@ -32,17 +32,17 @@  discard block
 block discarded – undo
32 32
 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
33 33
 require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php';
34 34
 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
35
-require_once DOL_DOCUMENT_ROOT .'/expedition/class/expedition.class.php';
36
-if (! empty($conf->projet->enabled)) {
37
-	require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php';
35
+require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
36
+if (!empty($conf->projet->enabled)) {
37
+	require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
38 38
 }
39 39
 
40 40
 // Load translation files required by the page
41 41
 $langs->loadLangs(array('companies', 'other'));
42 42
 
43
-$action		= GETPOST('action','aZ09');
43
+$action		= GETPOST('action', 'aZ09');
44 44
 $confirm	= GETPOST('confirm');
45
-$id			= GETPOST('id','int');
45
+$id			= GETPOST('id', 'int');
46 46
 $ref		= GETPOST('ref');
47 47
 
48 48
 // Security check
@@ -50,18 +50,18 @@  discard block
 block discarded – undo
50 50
 {
51 51
 	$socid = $user->societe_id;
52 52
 }
53
-$result=restrictedArea($user,'expedition',$id,'');
53
+$result = restrictedArea($user, 'expedition', $id, '');
54 54
 
55 55
 // Get parameters
56
-$sortfield = GETPOST("sortfield",'alpha');
57
-$sortorder = GETPOST("sortorder",'alpha');
58
-$page = GETPOST("page",'int');
56
+$sortfield = GETPOST("sortfield", 'alpha');
57
+$sortorder = GETPOST("sortorder", 'alpha');
58
+$page = GETPOST("page", 'int');
59 59
 if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
60 60
 $offset = $conf->liste_limit * $page;
61 61
 $pageprev = $page - 1;
62 62
 $pagenext = $page + 1;
63
-if (! $sortorder) $sortorder="ASC";
64
-if (! $sortfield) $sortfield="name";
63
+if (!$sortorder) $sortorder = "ASC";
64
+if (!$sortfield) $sortfield = "name";
65 65
 
66 66
 $object = new Expedition($db);
67 67
 
@@ -72,22 +72,22 @@  discard block
 block discarded – undo
72 72
 if ($object->fetch($id))
73 73
 {
74 74
 	$object->fetch_thirdparty();
75
-	$upload_dir = $conf->expedition->dir_output . "/sending/" . dol_sanitizeFileName($object->ref);
75
+	$upload_dir = $conf->expedition->dir_output."/sending/".dol_sanitizeFileName($object->ref);
76 76
 }
77 77
 
78
-include_once DOL_DOCUMENT_ROOT . '/core/actions_linkedfiles.inc.php';
78
+include_once DOL_DOCUMENT_ROOT.'/core/actions_linkedfiles.inc.php';
79 79
 
80 80
 
81 81
 /*
82 82
  * View
83 83
  */
84 84
 
85
-llxHeader('',$langs->trans('Order'),'EN:Customers_Orders|FR:expeditions_Clients|ES:Pedidos de clientes');
85
+llxHeader('', $langs->trans('Order'), 'EN:Customers_Orders|FR:expeditions_Clients|ES:Pedidos de clientes');
86 86
 
87 87
 $form = new Form($db);
88 88
 
89
-if ($id > 0 || ! empty($ref)){
90
-	if ($object->fetch($id, $ref)){
89
+if ($id > 0 || !empty($ref)) {
90
+	if ($object->fetch($id, $ref)) {
91 91
 		$object->fetch_thirdparty();
92 92
 
93 93
 		$upload_dir = $conf->expedition->dir_output.'/sending/'.dol_sanitizeFileName($object->ref);
@@ -97,50 +97,50 @@  discard block
 block discarded – undo
97 97
 	
98 98
 
99 99
 		// Build file list
100
-		$filearray=dol_dir_list($upload_dir,"files",0,'','(\.meta|_preview.*\.png)$',$sortfield,(strtolower($sortorder)=='desc'?SORT_DESC:SORT_ASC),1);
101
-		$totalsize=0;
102
-		foreach($filearray as $key => $file){
103
-		    $totalsize+=$file['size'];
100
+		$filearray = dol_dir_list($upload_dir, "files", 0, '', '(\.meta|_preview.*\.png)$', $sortfield, (strtolower($sortorder) == 'desc' ?SORT_DESC:SORT_ASC), 1);
101
+		$totalsize = 0;
102
+		foreach ($filearray as $key => $file) {
103
+		    $totalsize += $file['size'];
104 104
 		}
105 105
 
106 106
 		// Shipment card
107
-		$linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">'.$langs->trans("BackToList").'</a>';
107
+		$linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
108 108
 
109 109
 
110
-		$morehtmlref='<div class="refidno">';
110
+		$morehtmlref = '<div class="refidno">';
111 111
 		// Ref customer
112
-		$morehtmlref.=$form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
113
-		$morehtmlref.=$form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
112
+		$morehtmlref .= $form->editfieldkey("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', 0, 1);
113
+		$morehtmlref .= $form->editfieldval("RefCustomer", 'ref_client', $object->ref_client, $object, 0, 'string', '', null, null, '', 1);
114 114
 		// Thirdparty
115
-		$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
115
+		$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
116 116
 
117 117
 		// Project
118
-		if (! empty($conf->projet->enabled)) {
118
+		if (!empty($conf->projet->enabled)) {
119 119
 			$langs->load("projects");
120
-			$morehtmlref .= '<br>' . $langs->trans('Project') . ' ';
120
+			$morehtmlref .= '<br>'.$langs->trans('Project').' ';
121 121
 			if (0) {    // Do not change on shipment
122 122
 				if ($action != 'classify') {
123
-					$morehtmlref .= '<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
123
+					$morehtmlref .= '<a href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
124 124
 				}
125 125
 				if ($action == 'classify') {
126 126
 					// $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
127
-					$morehtmlref .= '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '">';
127
+					$morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
128 128
 					$morehtmlref .= '<input type="hidden" name="action" value="classin">';
129
-					$morehtmlref .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
129
+					$morehtmlref .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
130 130
 					$morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
131
-					$morehtmlref .= '<input type="submit" class="button" value="' . $langs->trans("Modify") . '">';
131
+					$morehtmlref .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
132 132
 					$morehtmlref .= '</form>';
133 133
 				} else {
134
-					$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
134
+					$morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
135 135
 				}
136 136
 			} else {
137 137
 				// We don't have project on shipment, so we will use the project or source object instead
138 138
 				// TODO Add project on shipment
139 139
 				$morehtmlref .= ' : ';
140
-				if (! empty($objectsrc->fk_project)) {
140
+				if (!empty($objectsrc->fk_project)) {
141 141
 					$proj = new Project($db);
142 142
 					$proj->fetch($objectsrc->fk_project);
143
-					$morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $objectsrc->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
143
+					$morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$objectsrc->fk_project.'" title="'.$langs->trans('ShowProject').'">';
144 144
 					$morehtmlref .= $proj->ref;
145 145
 					$morehtmlref .= '</a>';
146 146
 				} else {
@@ -148,11 +148,11 @@  discard block
 block discarded – undo
148 148
 				}
149 149
 			}
150 150
 		}
151
-		$morehtmlref.='</div>';
151
+		$morehtmlref .= '</div>';
152 152
 
153 153
 		// Order card
154 154
 
155
-		$linkback = '<a href="' . DOL_URL_ROOT . '/expedition/list.php' . (! empty($socid) ? '?socid=' . $socid : '') . '">' . $langs->trans("BackToList") . '</a>';
155
+		$linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php'.(!empty($socid) ? '?socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
156 156
 
157 157
 		dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
158 158
 
@@ -162,7 +162,7 @@  discard block
 block discarded – undo
162 162
 		print '<table class="border" width="100%">';
163 163
 
164 164
 		print '<tr><td class="titlefield">'.$langs->trans("NbOfAttachedFiles").'</td><td colspan="3">'.count($filearray).'</td></tr>';
165
-		print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize,1,1).'</td></tr>';
165
+		print '<tr><td>'.$langs->trans("TotalSizeOfAttachedFiles").'</td><td colspan="3">'.dol_print_size($totalsize, 1, 1).'</td></tr>';
166 166
 
167 167
 		print "</table>\n";
168 168
 
@@ -173,14 +173,14 @@  discard block
 block discarded – undo
173 173
 		$modulepart = 'expedition';
174 174
 		$permission = $user->rights->expedition->creer;
175 175
 		$permtoedit = $user->rights->expedition->creer;
176
-		$param = '&id=' . $object->id;
177
-		include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
176
+		$param = '&id='.$object->id;
177
+		include_once DOL_DOCUMENT_ROOT.'/core/tpl/document_actions_post_headers.tpl.php';
178 178
 	}
179
-	else{
179
+	else {
180 180
 		dol_print_error($db);
181 181
 	}
182 182
 }
183
-else{
183
+else {
184 184
 	header('Location: index.php');
185 185
 	exit;
186 186
 }
Please login to merge, or discard this patch.
Braces   +8 added lines, -6 removed lines patch added patch discarded remove patch
@@ -60,8 +60,12 @@  discard block
 block discarded – undo
60 60
 $offset = $conf->liste_limit * $page;
61 61
 $pageprev = $page - 1;
62 62
 $pagenext = $page + 1;
63
-if (! $sortorder) $sortorder="ASC";
64
-if (! $sortfield) $sortfield="name";
63
+if (! $sortorder) {
64
+    $sortorder="ASC";
65
+}
66
+if (! $sortfield) {
67
+    $sortfield="name";
68
+}
65 69
 
66 70
 $object = new Expedition($db);
67 71
 
@@ -175,12 +179,10 @@  discard block
 block discarded – undo
175 179
 		$permtoedit = $user->rights->expedition->creer;
176 180
 		$param = '&id=' . $object->id;
177 181
 		include_once DOL_DOCUMENT_ROOT . '/core/tpl/document_actions_post_headers.tpl.php';
178
-	}
179
-	else{
182
+	} else{
180 183
 		dol_print_error($db);
181 184
 	}
182
-}
183
-else{
185
+} else{
184 186
 	header('Location: index.php');
185 187
 	exit;
186 188
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/expedition/note.php 3 patches
Indentation   +13 added lines, -13 removed lines patch added patch discarded remove patch
@@ -91,19 +91,19 @@  discard block
 block discarded – undo
91 91
 if ($id > 0 || ! empty($ref))
92 92
 {
93 93
 
94
-	$head=shipping_prepare_head($object);
95
-	dol_fiche_head($head, 'note', $langs->trans("Shipment"), -1, 'sending');
94
+    $head=shipping_prepare_head($object);
95
+    dol_fiche_head($head, 'note', $langs->trans("Shipment"), -1, 'sending');
96 96
 
97 97
 
98
-	// Shipment card
99
-	$linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">'.$langs->trans("BackToList").'</a>';
98
+    // Shipment card
99
+    $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">'.$langs->trans("BackToList").'</a>';
100 100
 
101
-	$morehtmlref='<div class="refidno">';
102
-	// Ref customer shipment
103
-	$morehtmlref.=$form->editfieldkey("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', 0, 1);
104
-	$morehtmlref.=$form->editfieldval("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', null, null, '', 1);
105
-	// Thirdparty
106
-	$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
101
+    $morehtmlref='<div class="refidno">';
102
+    // Ref customer shipment
103
+    $morehtmlref.=$form->editfieldkey("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', 0, 1);
104
+    $morehtmlref.=$form->editfieldval("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', null, null, '', 1);
105
+    // Thirdparty
106
+    $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
107 107
     // Project
108 108
     if (! empty($conf->projet->enabled)) {
109 109
         $langs->load("projects");
@@ -146,10 +146,10 @@  discard block
 block discarded – undo
146 146
 
147 147
     print '<div class="underbanner clearboth"></div>';
148 148
 
149
-	$cssclass='titlefield';
150
-	include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php';
149
+    $cssclass='titlefield';
150
+    include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php';
151 151
 
152
-	dol_fiche_end();
152
+    dol_fiche_end();
153 153
 }
154 154
 
155 155
 // End of page
Please login to merge, or discard this patch.
Spacing   +32 added lines, -32 removed lines patch added patch discarded remove patch
@@ -27,7 +27,7 @@  discard block
 block discarded – undo
27 27
 require '../main.inc.php';
28 28
 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';
29 29
 require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php';
30
-if (! empty($conf->projet->enabled)) {
30
+if (!empty($conf->projet->enabled)) {
31 31
     require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
32 32
     require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
33 33
 }
@@ -35,17 +35,17 @@  discard block
 block discarded – undo
35 35
 // Load translation files required by the page
36 36
 $langs->loadLangs(array('sendings', 'companies', 'bills', 'deliveries', 'orders', 'stocks', 'other', 'propal'));
37 37
 
38
-$id=(GETPOST('id','int')?GETPOST('id','int'):GETPOST('facid','int'));  // For backward compatibility
39
-$ref=GETPOST('ref','alpha');
40
-$action=GETPOST('action','alpha');
38
+$id = (GETPOST('id', 'int') ?GETPOST('id', 'int') : GETPOST('facid', 'int')); // For backward compatibility
39
+$ref = GETPOST('ref', 'alpha');
40
+$action = GETPOST('action', 'alpha');
41 41
 
42 42
 // Security check
43
-$socid='';
44
-if ($user->societe_id) $socid=$user->societe_id;
45
-$result=restrictedArea($user, $origin, $origin_id);
43
+$socid = '';
44
+if ($user->societe_id) $socid = $user->societe_id;
45
+$result = restrictedArea($user, $origin, $origin_id);
46 46
 
47 47
 $object = new Expedition($db);
48
-if ($id > 0 || ! empty($ref))
48
+if ($id > 0 || !empty($ref))
49 49
 {
50 50
     $object->fetch($id, $ref);
51 51
     $object->fetch_thirdparty();
@@ -58,26 +58,26 @@  discard block
 block discarded – undo
58 58
     }
59 59
 
60 60
     // Linked documents
61
-    if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
61
+    if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled))
62 62
     {
63
-        $objectsrc=new Commande($db);
63
+        $objectsrc = new Commande($db);
64 64
         $objectsrc->fetch($object->$typeobject->id);
65 65
     }
66
-    if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
66
+    if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled))
67 67
     {
68
-        $objectsrc=new Propal($db);
68
+        $objectsrc = new Propal($db);
69 69
         $objectsrc->fetch($object->$typeobject->id);
70 70
     }
71 71
 }
72 72
 
73
-$permissionnote=$user->rights->expedition->creer;	// Used by the include of actions_setnotes.inc.php
73
+$permissionnote = $user->rights->expedition->creer; // Used by the include of actions_setnotes.inc.php
74 74
 
75 75
 
76 76
 /*
77 77
  * Actions
78 78
  */
79 79
 
80
-include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php';	// Must be include, not includ_once
80
+include DOL_DOCUMENT_ROOT.'/core/actions_setnotes.inc.php'; // Must be include, not includ_once
81 81
 
82 82
 
83 83
 /*
@@ -88,49 +88,49 @@  discard block
 block discarded – undo
88 88
 
89 89
 $form = new Form($db);
90 90
 
91
-if ($id > 0 || ! empty($ref))
91
+if ($id > 0 || !empty($ref))
92 92
 {
93 93
 
94
-	$head=shipping_prepare_head($object);
94
+	$head = shipping_prepare_head($object);
95 95
 	dol_fiche_head($head, 'note', $langs->trans("Shipment"), -1, 'sending');
96 96
 
97 97
 
98 98
 	// Shipment card
99
-	$linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">'.$langs->trans("BackToList").'</a>';
99
+	$linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
100 100
 
101
-	$morehtmlref='<div class="refidno">';
101
+	$morehtmlref = '<div class="refidno">';
102 102
 	// Ref customer shipment
103
-	$morehtmlref.=$form->editfieldkey("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', 0, 1);
104
-	$morehtmlref.=$form->editfieldval("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', null, null, '', 1);
103
+	$morehtmlref .= $form->editfieldkey("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', 0, 1);
104
+	$morehtmlref .= $form->editfieldval("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', null, null, '', 1);
105 105
 	// Thirdparty
106
-	$morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
106
+	$morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
107 107
     // Project
108
-    if (! empty($conf->projet->enabled)) {
108
+    if (!empty($conf->projet->enabled)) {
109 109
         $langs->load("projects");
110
-        $morehtmlref .= '<br>' . $langs->trans('Project') . ' ';
110
+        $morehtmlref .= '<br>'.$langs->trans('Project').' ';
111 111
         if (0) {    // Do not change on shipment
112 112
             if ($action != 'classify') {
113
-                $morehtmlref .= '<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
113
+                $morehtmlref .= '<a href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
114 114
             }
115 115
             if ($action == 'classify') {
116 116
                 // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
117
-                $morehtmlref .= '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '">';
117
+                $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
118 118
                 $morehtmlref .= '<input type="hidden" name="action" value="classin">';
119
-                $morehtmlref .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
119
+                $morehtmlref .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
120 120
                 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
121
-                $morehtmlref .= '<input type="submit" class="button" value="' . $langs->trans("Modify") . '">';
121
+                $morehtmlref .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
122 122
                 $morehtmlref .= '</form>';
123 123
             } else {
124
-                $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
124
+                $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
125 125
             }
126 126
         } else {
127 127
             // We don't have project on shipment, so we will use the project or source object instead
128 128
             // TODO Add project on shipment
129 129
             $morehtmlref .= ' : ';
130
-            if (! empty($objectsrc->fk_project)) {
130
+            if (!empty($objectsrc->fk_project)) {
131 131
                 $proj = new Project($db);
132 132
                 $proj->fetch($objectsrc->fk_project);
133
-                $morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $objectsrc->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
133
+                $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$objectsrc->fk_project.'" title="'.$langs->trans('ShowProject').'">';
134 134
                 $morehtmlref .= $proj->ref;
135 135
                 $morehtmlref .= '</a>';
136 136
             } else {
@@ -138,7 +138,7 @@  discard block
 block discarded – undo
138 138
             }
139 139
         }
140 140
     }
141
-    $morehtmlref.='</div>';
141
+    $morehtmlref .= '</div>';
142 142
 
143 143
 
144 144
     dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
 
147 147
     print '<div class="underbanner clearboth"></div>';
148 148
 
149
-	$cssclass='titlefield';
149
+	$cssclass = 'titlefield';
150 150
 	include DOL_DOCUMENT_ROOT.'/core/tpl/notes.tpl.php';
151 151
 
152 152
 	dol_fiche_end();
Please login to merge, or discard this patch.
Braces   +3 added lines, -1 removed lines patch added patch discarded remove patch
@@ -41,7 +41,9 @@
 block discarded – undo
41 41
 
42 42
 // Security check
43 43
 $socid='';
44
-if ($user->societe_id) $socid=$user->societe_id;
44
+if ($user->societe_id) {
45
+    $socid=$user->societe_id;
46
+}
45 47
 $result=restrictedArea($user, $origin, $origin_id);
46 48
 
47 49
 $object = new Expedition($db);
Please login to merge, or discard this patch.
dolibarr/htdocs/expedition/index.php 3 patches
Indentation   +130 added lines, -130 removed lines patch added patch discarded remove patch
@@ -72,9 +72,9 @@  discard block
 block discarded – undo
72 72
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
73 73
 if (!$user->rights->societe->client->voir && !$socid)
74 74
 {
75
-	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
76
-	$sql.= $clause." sc.fk_user = " .$user->id;
77
-	$clause = " AND ";
75
+    $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
76
+    $sql.= $clause." sc.fk_user = " .$user->id;
77
+    $clause = " AND ";
78 78
 }
79 79
 $sql.= $clause." e.fk_statut = 0";
80 80
 $sql.= " AND e.entity IN (".getEntity('expedition').")";
@@ -83,34 +83,34 @@  discard block
 block discarded – undo
83 83
 $resql=$db->query($sql);
84 84
 if ($resql)
85 85
 {
86
-	$num = $db->num_rows($resql);
87
-	if ($num)
88
-	{
89
-		print '<table class="noborder" width="100%">';
90
-		print '<tr class="liste_titre">';
91
-		print '<th colspan="3">'.$langs->trans("SendingsToValidate").'</th></tr>';
92
-		$i = 0;
93
-		while ($i < $num)
94
-		{
95
-			$obj = $db->fetch_object($resql);
96
-
97
-			$shipment->id=$obj->rowid;
98
-			$shipment->ref=$obj->ref;
99
-			$shipment->ref_customer=$obj->ref_customer;
100
-
101
-			print '<tr class="oddeven"><td class="nowrap">';
102
-			print $shipment->getNomUrl(1);
103
-			print "</td>";
104
-			print '<td>';
105
-			print '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.$obj->name.'</a>';
106
-			print '</td>';
107
-			print '<td>';
108
-			if ($obj->commande_id) print '<a href="'.DOL_URL_ROOT.'/commande/card.php?id='.$obj->commande_id.'">'.$obj->commande_ref.'</a>';
109
-			print '</td></tr>';
110
-			$i++;
111
-		}
112
-		print "</table><br>";
113
-	}
86
+    $num = $db->num_rows($resql);
87
+    if ($num)
88
+    {
89
+        print '<table class="noborder" width="100%">';
90
+        print '<tr class="liste_titre">';
91
+        print '<th colspan="3">'.$langs->trans("SendingsToValidate").'</th></tr>';
92
+        $i = 0;
93
+        while ($i < $num)
94
+        {
95
+            $obj = $db->fetch_object($resql);
96
+
97
+            $shipment->id=$obj->rowid;
98
+            $shipment->ref=$obj->ref;
99
+            $shipment->ref_customer=$obj->ref_customer;
100
+
101
+            print '<tr class="oddeven"><td class="nowrap">';
102
+            print $shipment->getNomUrl(1);
103
+            print "</td>";
104
+            print '<td>';
105
+            print '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.$obj->name.'</a>';
106
+            print '</td>';
107
+            print '<td>';
108
+            if ($obj->commande_id) print '<a href="'.DOL_URL_ROOT.'/commande/card.php?id='.$obj->commande_id.'">'.$obj->commande_ref.'</a>';
109
+            print '</td></tr>';
110
+            $i++;
111
+        }
112
+        print "</table><br>";
113
+    }
114 114
 }
115 115
 
116 116
 
@@ -131,43 +131,43 @@  discard block
 block discarded – undo
131 131
 $resql=$db->query($sql);
132 132
 if ($resql)
133 133
 {
134
-	$num = $db->num_rows($resql);
135
-	if ($num)
136
-	{
137
-		$langs->load("orders");
138
-
139
-		$i = 0;
140
-		print '<table class="noborder" width="100%">';
141
-		print '<tr class="liste_titre">';
142
-		print '<th colspan="3">'.$langs->trans("OrdersToProcess").'</th></tr>';
143
-		while ($i < $num)
144
-		{
145
-			$obj = $db->fetch_object($resql);
146
-
147
-			$orderstatic->id=$obj->rowid;
148
-			$orderstatic->ref=$obj->ref;
149
-			$orderstatic->ref_customer=$obj->ref_customer;
150
-			$orderstatic->statut=$obj->fk_statut;
151
-			$orderstatic->billed=0;
152
-
153
-			$companystatic->name=$obj->name;
154
-			$companystatic->id=$obj->socid;
155
-
156
-			print '<tr class="oddeven">';
157
-			print '<td class="nowrap">';
158
-			print $orderstatic->getNomUrl(1);
159
-			print '</td>';
160
-			print '<td>';
161
-			print $companystatic->getNomUrl(1,'customer',32);
162
-			print '</td>';
163
-			print '<td align="right">';
164
-			print $orderstatic->getLibStatut(3);
165
-			print '</td>';
166
-			print '</tr>';
167
-			$i++;
168
-		}
169
-		print "</table><br>";
170
-	}
134
+    $num = $db->num_rows($resql);
135
+    if ($num)
136
+    {
137
+        $langs->load("orders");
138
+
139
+        $i = 0;
140
+        print '<table class="noborder" width="100%">';
141
+        print '<tr class="liste_titre">';
142
+        print '<th colspan="3">'.$langs->trans("OrdersToProcess").'</th></tr>';
143
+        while ($i < $num)
144
+        {
145
+            $obj = $db->fetch_object($resql);
146
+
147
+            $orderstatic->id=$obj->rowid;
148
+            $orderstatic->ref=$obj->ref;
149
+            $orderstatic->ref_customer=$obj->ref_customer;
150
+            $orderstatic->statut=$obj->fk_statut;
151
+            $orderstatic->billed=0;
152
+
153
+            $companystatic->name=$obj->name;
154
+            $companystatic->id=$obj->socid;
155
+
156
+            print '<tr class="oddeven">';
157
+            print '<td class="nowrap">';
158
+            print $orderstatic->getNomUrl(1);
159
+            print '</td>';
160
+            print '<td>';
161
+            print $companystatic->getNomUrl(1,'customer',32);
162
+            print '</td>';
163
+            print '<td align="right">';
164
+            print $orderstatic->getLibStatut(3);
165
+            print '</td>';
166
+            print '</tr>';
167
+            $i++;
168
+        }
169
+        print "</table><br>";
170
+    }
171 171
 }
172 172
 
173 173
 
@@ -191,42 +191,42 @@  discard block
 block discarded – undo
191 191
 $resql = $db->query($sql);
192 192
 if ( $resql )
193 193
 {
194
-	$langs->load("orders");
195
-
196
-	$num = $db->num_rows($resql);
197
-	if ($num)
198
-	{
199
-		$i = 0;
200
-		print '<table class="noborder" width="100%">';
201
-		print '<tr class="liste_titre">';
202
-		print '<th colspan="3">'.$langs->trans("OrdersInProcess").'</th></tr>';
203
-		while ($i < $num)
204
-		{
205
-			$obj = $db->fetch_object($resql);
206
-
207
-		    $orderstatic->id=$obj->rowid;
208
-			$orderstatic->ref=$obj->ref;
209
-			$orderstatic->ref_customer=$obj->ref_customer;
210
-			$orderstatic->statut=$obj->status;
194
+    $langs->load("orders");
195
+
196
+    $num = $db->num_rows($resql);
197
+    if ($num)
198
+    {
199
+        $i = 0;
200
+        print '<table class="noborder" width="100%">';
201
+        print '<tr class="liste_titre">';
202
+        print '<th colspan="3">'.$langs->trans("OrdersInProcess").'</th></tr>';
203
+        while ($i < $num)
204
+        {
205
+            $obj = $db->fetch_object($resql);
206
+
207
+            $orderstatic->id=$obj->rowid;
208
+            $orderstatic->ref=$obj->ref;
209
+            $orderstatic->ref_customer=$obj->ref_customer;
210
+            $orderstatic->statut=$obj->status;
211 211
             $orderstatic->billed=$obj->billed;
212 212
 
213 213
             $companystatic->name=$obj->name;
214
-			$companystatic->id=$obj->socid;
215
-
216
-			print '<tr class="oddeven"><td>';
217
-			print $orderstatic->getNomUrl(1);
218
-			print '</td>';
219
-			print '<td>';
220
-			print $companystatic->getNomUrl(1,'customer');
221
-			print '</td>';
214
+            $companystatic->id=$obj->socid;
215
+
216
+            print '<tr class="oddeven"><td>';
217
+            print $orderstatic->getNomUrl(1);
218
+            print '</td>';
219
+            print '<td>';
220
+            print $companystatic->getNomUrl(1,'customer');
221
+            print '</td>';
222 222
             print '<td align="right">';
223 223
             print $orderstatic->getLibStatut(3);
224 224
             print '</td>';
225 225
             print '</tr>';
226
-			$i++;
227
-		}
228
-		print "</table><br>";
229
-	}
226
+            $i++;
227
+        }
228
+        print "</table><br>";
229
+    }
230 230
 }
231 231
 else dol_print_error($db);
232 232
 
@@ -252,39 +252,39 @@  discard block
 block discarded – undo
252 252
 $resql = $db->query($sql);
253 253
 if ($resql)
254 254
 {
255
-	$num = $db->num_rows($resql);
256
-	if ($num)
257
-	{
258
-		$i = 0;
259
-		print '<table class="noborder" width="100%">';
260
-		print '<tr class="liste_titre">';
261
-		print '<th colspan="3">'.$langs->trans("LastSendings", $num).'</th></tr>';
262
-		while ($i < $num)
263
-		{
264
-			$obj = $db->fetch_object($resql);
265
-
266
-			$shipment->id=$obj->rowid;
267
-			$shipment->ref=$obj->ref;
268
-			$shipment->ref_customer=$obj->ref_customer;
269
-
270
-			print '<tr class="oddeven"><td>';
271
-			print $shipment->getNomUrl(1);
272
-			print '</td>';
273
-			print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.'</a></td>';
274
-			print '<td>';
275
-			if ($obj->commande_id > 0)
276
-			{
277
-				$orderstatic->id=$obj->commande_id;
278
-				$orderstatic->ref=$obj->commande_ref;
279
-				print $orderstatic->getNomUrl(1);
280
-			}
281
-			else print '&nbsp;';
282
-			print '</td></tr>';
283
-			$i++;
284
-		}
285
-		print "</table><br>";
286
-	}
287
-	$db->free($resql);
255
+    $num = $db->num_rows($resql);
256
+    if ($num)
257
+    {
258
+        $i = 0;
259
+        print '<table class="noborder" width="100%">';
260
+        print '<tr class="liste_titre">';
261
+        print '<th colspan="3">'.$langs->trans("LastSendings", $num).'</th></tr>';
262
+        while ($i < $num)
263
+        {
264
+            $obj = $db->fetch_object($resql);
265
+
266
+            $shipment->id=$obj->rowid;
267
+            $shipment->ref=$obj->ref;
268
+            $shipment->ref_customer=$obj->ref_customer;
269
+
270
+            print '<tr class="oddeven"><td>';
271
+            print $shipment->getNomUrl(1);
272
+            print '</td>';
273
+            print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.'</a></td>';
274
+            print '<td>';
275
+            if ($obj->commande_id > 0)
276
+            {
277
+                $orderstatic->id=$obj->commande_id;
278
+                $orderstatic->ref=$obj->commande_ref;
279
+                print $orderstatic->getNomUrl(1);
280
+            }
281
+            else print '&nbsp;';
282
+            print '</td></tr>';
283
+            $i++;
284
+        }
285
+        print "</table><br>";
286
+    }
287
+    $db->free($resql);
288 288
 }
289 289
 else dol_print_error($db);
290 290
 
Please login to merge, or discard this patch.
Spacing   +76 added lines, -76 removed lines patch added patch discarded remove patch
@@ -34,12 +34,12 @@  discard block
 block discarded – undo
34 34
  *	View
35 35
  */
36 36
 
37
-$orderstatic=new Commande($db);
38
-$companystatic=new Societe($db);
39
-$shipment=new Expedition($db);
37
+$orderstatic = new Commande($db);
38
+$companystatic = new Societe($db);
39
+$shipment = new Expedition($db);
40 40
 
41
-$helpurl='EN:Module_Shipments|FR:Module_Exp&eacute;ditions|ES:M&oacute;dulo_Expediciones';
42
-llxHeader('',$langs->trans("Shipment"),$helpurl);
41
+$helpurl = 'EN:Module_Shipments|FR:Module_Exp&eacute;ditions|ES:M&oacute;dulo_Expediciones';
42
+llxHeader('', $langs->trans("Shipment"), $helpurl);
43 43
 
44 44
 print load_fiche_titre($langs->trans("SendingsArea"));
45 45
 
@@ -47,7 +47,7 @@  discard block
 block discarded – undo
47 47
 print '<div class="fichecenter"><div class="fichethirdleft">';
48 48
 
49 49
 
50
-if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS))     // This is useless due to the global search combo
50
+if (!empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS))     // This is useless due to the global search combo
51 51
 {
52 52
     print '<form method="post" action="list.php">';
53 53
     print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
@@ -64,23 +64,23 @@  discard block
 block discarded – undo
64 64
 $clause = " WHERE ";
65 65
 
66 66
 $sql = "SELECT e.rowid, e.ref, e.ref_customer,";
67
-$sql.= " s.nom as name, s.rowid as socid,";
68
-$sql.= " c.ref as commande_ref, c.rowid as commande_id";
69
-$sql.= " FROM ".MAIN_DB_PREFIX."expedition as e";
70
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'shipping'";
71
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid";
72
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
67
+$sql .= " s.nom as name, s.rowid as socid,";
68
+$sql .= " c.ref as commande_ref, c.rowid as commande_id";
69
+$sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
70
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'shipping'";
71
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid";
72
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
73 73
 if (!$user->rights->societe->client->voir && !$socid)
74 74
 {
75
-	$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
76
-	$sql.= $clause." sc.fk_user = " .$user->id;
75
+	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
76
+	$sql .= $clause." sc.fk_user = ".$user->id;
77 77
 	$clause = " AND ";
78 78
 }
79
-$sql.= $clause." e.fk_statut = 0";
80
-$sql.= " AND e.entity IN (".getEntity('expedition').")";
81
-if ($socid) $sql.= " AND c.fk_soc = ".$socid;
79
+$sql .= $clause." e.fk_statut = 0";
80
+$sql .= " AND e.entity IN (".getEntity('expedition').")";
81
+if ($socid) $sql .= " AND c.fk_soc = ".$socid;
82 82
 
83
-$resql=$db->query($sql);
83
+$resql = $db->query($sql);
84 84
 if ($resql)
85 85
 {
86 86
 	$num = $db->num_rows($resql);
@@ -94,9 +94,9 @@  discard block
 block discarded – undo
94 94
 		{
95 95
 			$obj = $db->fetch_object($resql);
96 96
 
97
-			$shipment->id=$obj->rowid;
98
-			$shipment->ref=$obj->ref;
99
-			$shipment->ref_customer=$obj->ref_customer;
97
+			$shipment->id = $obj->rowid;
98
+			$shipment->ref = $obj->ref;
99
+			$shipment->ref_customer = $obj->ref_customer;
100 100
 
101 101
 			print '<tr class="oddeven"><td class="nowrap">';
102 102
 			print $shipment->getNomUrl(1);
@@ -118,17 +118,17 @@  discard block
 block discarded – undo
118 118
  * Commandes a traiter
119 119
  */
120 120
 $sql = "SELECT c.rowid, c.ref, c.ref_client as ref_customer, c.fk_statut, s.nom as name, s.rowid as socid";
121
-$sql.= " FROM ".MAIN_DB_PREFIX."commande as c,";
122
-$sql.= " ".MAIN_DB_PREFIX."societe as s";
123
-if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
124
-$sql.= " WHERE c.fk_soc = s.rowid";
125
-$sql.= " AND c.entity = ".$conf->entity;
126
-$sql.= " AND c.fk_statut = 1";
127
-if ($socid) $sql.= " AND c.fk_soc = ".$socid;
128
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
129
-$sql.= " ORDER BY c.rowid ASC";
130
-
131
-$resql=$db->query($sql);
121
+$sql .= " FROM ".MAIN_DB_PREFIX."commande as c,";
122
+$sql .= " ".MAIN_DB_PREFIX."societe as s";
123
+if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
124
+$sql .= " WHERE c.fk_soc = s.rowid";
125
+$sql .= " AND c.entity = ".$conf->entity;
126
+$sql .= " AND c.fk_statut = 1";
127
+if ($socid) $sql .= " AND c.fk_soc = ".$socid;
128
+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
129
+$sql .= " ORDER BY c.rowid ASC";
130
+
131
+$resql = $db->query($sql);
132 132
 if ($resql)
133 133
 {
134 134
 	$num = $db->num_rows($resql);
@@ -144,21 +144,21 @@  discard block
 block discarded – undo
144 144
 		{
145 145
 			$obj = $db->fetch_object($resql);
146 146
 
147
-			$orderstatic->id=$obj->rowid;
148
-			$orderstatic->ref=$obj->ref;
149
-			$orderstatic->ref_customer=$obj->ref_customer;
150
-			$orderstatic->statut=$obj->fk_statut;
151
-			$orderstatic->billed=0;
147
+			$orderstatic->id = $obj->rowid;
148
+			$orderstatic->ref = $obj->ref;
149
+			$orderstatic->ref_customer = $obj->ref_customer;
150
+			$orderstatic->statut = $obj->fk_statut;
151
+			$orderstatic->billed = 0;
152 152
 
153
-			$companystatic->name=$obj->name;
154
-			$companystatic->id=$obj->socid;
153
+			$companystatic->name = $obj->name;
154
+			$companystatic->id = $obj->socid;
155 155
 
156 156
 			print '<tr class="oddeven">';
157 157
 			print '<td class="nowrap">';
158 158
 			print $orderstatic->getNomUrl(1);
159 159
 			print '</td>';
160 160
 			print '<td>';
161
-			print $companystatic->getNomUrl(1,'customer',32);
161
+			print $companystatic->getNomUrl(1, 'customer', 32);
162 162
 			print '</td>';
163 163
 			print '<td align="right">';
164 164
 			print $orderstatic->getLibStatut(3);
@@ -179,17 +179,17 @@  discard block
 block discarded – undo
179 179
  * Commandes en traitement
180 180
  */
181 181
 $sql = "SELECT c.rowid, c.ref, c.ref_client as ref_customer, c.fk_statut as status, c.facture as billed, s.nom as name, s.rowid as socid";
182
-$sql.= " FROM ".MAIN_DB_PREFIX."commande as c,";
183
-$sql.= " ".MAIN_DB_PREFIX."societe as s";
184
-if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
185
-$sql.= " WHERE c.fk_soc = s.rowid";
186
-$sql.= " AND c.entity = ".$conf->entity;
187
-$sql.= " AND c.fk_statut = 2";
188
-if ($socid) $sql.= " AND c.fk_soc = ".$socid;
189
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
182
+$sql .= " FROM ".MAIN_DB_PREFIX."commande as c,";
183
+$sql .= " ".MAIN_DB_PREFIX."societe as s";
184
+if (!$user->rights->societe->client->voir && !$socid) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
185
+$sql .= " WHERE c.fk_soc = s.rowid";
186
+$sql .= " AND c.entity = ".$conf->entity;
187
+$sql .= " AND c.fk_statut = 2";
188
+if ($socid) $sql .= " AND c.fk_soc = ".$socid;
189
+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".$user->id;
190 190
 
191 191
 $resql = $db->query($sql);
192
-if ( $resql )
192
+if ($resql)
193 193
 {
194 194
 	$langs->load("orders");
195 195
 
@@ -204,20 +204,20 @@  discard block
 block discarded – undo
204 204
 		{
205 205
 			$obj = $db->fetch_object($resql);
206 206
 
207
-		    $orderstatic->id=$obj->rowid;
208
-			$orderstatic->ref=$obj->ref;
209
-			$orderstatic->ref_customer=$obj->ref_customer;
210
-			$orderstatic->statut=$obj->status;
211
-            $orderstatic->billed=$obj->billed;
207
+		    $orderstatic->id = $obj->rowid;
208
+			$orderstatic->ref = $obj->ref;
209
+			$orderstatic->ref_customer = $obj->ref_customer;
210
+			$orderstatic->statut = $obj->status;
211
+            $orderstatic->billed = $obj->billed;
212 212
 
213
-            $companystatic->name=$obj->name;
214
-			$companystatic->id=$obj->socid;
213
+            $companystatic->name = $obj->name;
214
+			$companystatic->id = $obj->socid;
215 215
 
216 216
 			print '<tr class="oddeven"><td>';
217 217
 			print $orderstatic->getNomUrl(1);
218 218
 			print '</td>';
219 219
 			print '<td>';
220
-			print $companystatic->getNomUrl(1,'customer');
220
+			print $companystatic->getNomUrl(1, 'customer');
221 221
 			print '</td>';
222 222
             print '<td align="right">';
223 223
             print $orderstatic->getLibStatut(3);
@@ -235,19 +235,19 @@  discard block
 block discarded – undo
235 235
  * Last shipments
236 236
  */
237 237
 $sql = "SELECT e.rowid, e.ref, e.ref_customer,";
238
-$sql.= " s.nom as name, s.rowid as socid,";
239
-$sql.= " c.ref as commande_ref, c.rowid as commande_id";
240
-$sql.= " FROM ".MAIN_DB_PREFIX."expedition as e";
241
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'shipping' AND el.sourcetype IN ('commande')";
242
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid AND el.sourcetype IN ('commande') AND el.targettype = 'shipping'";
243
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
244
-if (! $user->rights->societe->client->voir && ! $socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
245
-$sql.= " WHERE e.entity IN (".getEntity('expedition').")";
246
-if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND sc.fk_user = " .$user->id;
247
-$sql.= " AND e.fk_statut = 1";
248
-if ($socid) $sql.= " AND c.fk_soc = ".$socid;
249
-$sql.= " ORDER BY e.date_delivery DESC";
250
-$sql.= $db->plimit(5, 0);
238
+$sql .= " s.nom as name, s.rowid as socid,";
239
+$sql .= " c.ref as commande_ref, c.rowid as commande_id";
240
+$sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
241
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'shipping' AND el.sourcetype IN ('commande')";
242
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid AND el.sourcetype IN ('commande') AND el.targettype = 'shipping'";
243
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
244
+if (!$user->rights->societe->client->voir && !$socid) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
245
+$sql .= " WHERE e.entity IN (".getEntity('expedition').")";
246
+if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND sc.fk_user = ".$user->id;
247
+$sql .= " AND e.fk_statut = 1";
248
+if ($socid) $sql .= " AND c.fk_soc = ".$socid;
249
+$sql .= " ORDER BY e.date_delivery DESC";
250
+$sql .= $db->plimit(5, 0);
251 251
 
252 252
 $resql = $db->query($sql);
253 253
 if ($resql)
@@ -263,19 +263,19 @@  discard block
 block discarded – undo
263 263
 		{
264 264
 			$obj = $db->fetch_object($resql);
265 265
 
266
-			$shipment->id=$obj->rowid;
267
-			$shipment->ref=$obj->ref;
268
-			$shipment->ref_customer=$obj->ref_customer;
266
+			$shipment->id = $obj->rowid;
267
+			$shipment->ref = $obj->ref;
268
+			$shipment->ref_customer = $obj->ref_customer;
269 269
 
270 270
 			print '<tr class="oddeven"><td>';
271 271
 			print $shipment->getNomUrl(1);
272 272
 			print '</td>';
273
-			print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.'</a></td>';
273
+			print '<td><a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"), "company").' '.$obj->name.'</a></td>';
274 274
 			print '<td>';
275 275
 			if ($obj->commande_id > 0)
276 276
 			{
277
-				$orderstatic->id=$obj->commande_id;
278
-				$orderstatic->ref=$obj->commande_ref;
277
+				$orderstatic->id = $obj->commande_id;
278
+				$orderstatic->ref = $obj->commande_ref;
279 279
 				print $orderstatic->getNomUrl(1);
280 280
 			}
281 281
 			else print '&nbsp;';
Please login to merge, or discard this patch.
Braces   +42 added lines, -15 removed lines patch added patch discarded remove patch
@@ -47,9 +47,11 @@  discard block
 block discarded – undo
47 47
 print '<div class="fichecenter"><div class="fichethirdleft">';
48 48
 
49 49
 
50
-if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS))     // This is useless due to the global search combo
50
+if (! empty($conf->global->MAIN_SEARCH_FORM_ON_HOME_AREAS)) {
51
+    // This is useless due to the global search combo
51 52
 {
52 53
     print '<form method="post" action="list.php">';
54
+}
53 55
     print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
54 56
     print '<table class="noborder nohover" width="100%">';
55 57
     print '<tr class="liste_titre"><td colspan="3">'.$langs->trans("Search").'</td></tr>';
@@ -78,7 +80,9 @@  discard block
 block discarded – undo
78 80
 }
79 81
 $sql.= $clause." e.fk_statut = 0";
80 82
 $sql.= " AND e.entity IN (".getEntity('expedition').")";
81
-if ($socid) $sql.= " AND c.fk_soc = ".$socid;
83
+if ($socid) {
84
+    $sql.= " AND c.fk_soc = ".$socid;
85
+}
82 86
 
83 87
 $resql=$db->query($sql);
84 88
 if ($resql)
@@ -105,7 +109,9 @@  discard block
 block discarded – undo
105 109
 			print '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$obj->socid.'">'.$obj->name.'</a>';
106 110
 			print '</td>';
107 111
 			print '<td>';
108
-			if ($obj->commande_id) print '<a href="'.DOL_URL_ROOT.'/commande/card.php?id='.$obj->commande_id.'">'.$obj->commande_ref.'</a>';
112
+			if ($obj->commande_id) {
113
+			    print '<a href="'.DOL_URL_ROOT.'/commande/card.php?id='.$obj->commande_id.'">'.$obj->commande_ref.'</a>';
114
+			}
109 115
 			print '</td></tr>';
110 116
 			$i++;
111 117
 		}
@@ -120,12 +126,18 @@  discard block
 block discarded – undo
120 126
 $sql = "SELECT c.rowid, c.ref, c.ref_client as ref_customer, c.fk_statut, s.nom as name, s.rowid as socid";
121 127
 $sql.= " FROM ".MAIN_DB_PREFIX."commande as c,";
122 128
 $sql.= " ".MAIN_DB_PREFIX."societe as s";
123
-if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
129
+if (!$user->rights->societe->client->voir && !$socid) {
130
+    $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
131
+}
124 132
 $sql.= " WHERE c.fk_soc = s.rowid";
125 133
 $sql.= " AND c.entity = ".$conf->entity;
126 134
 $sql.= " AND c.fk_statut = 1";
127
-if ($socid) $sql.= " AND c.fk_soc = ".$socid;
128
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
135
+if ($socid) {
136
+    $sql.= " AND c.fk_soc = ".$socid;
137
+}
138
+if (!$user->rights->societe->client->voir && !$socid) {
139
+    $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
140
+}
129 141
 $sql.= " ORDER BY c.rowid ASC";
130 142
 
131 143
 $resql=$db->query($sql);
@@ -181,12 +193,18 @@  discard block
 block discarded – undo
181 193
 $sql = "SELECT c.rowid, c.ref, c.ref_client as ref_customer, c.fk_statut as status, c.facture as billed, s.nom as name, s.rowid as socid";
182 194
 $sql.= " FROM ".MAIN_DB_PREFIX."commande as c,";
183 195
 $sql.= " ".MAIN_DB_PREFIX."societe as s";
184
-if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
196
+if (!$user->rights->societe->client->voir && !$socid) {
197
+    $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
198
+}
185 199
 $sql.= " WHERE c.fk_soc = s.rowid";
186 200
 $sql.= " AND c.entity = ".$conf->entity;
187 201
 $sql.= " AND c.fk_statut = 2";
188
-if ($socid) $sql.= " AND c.fk_soc = ".$socid;
189
-if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
202
+if ($socid) {
203
+    $sql.= " AND c.fk_soc = ".$socid;
204
+}
205
+if (!$user->rights->societe->client->voir && !$socid) {
206
+    $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
207
+}
190 208
 
191 209
 $resql = $db->query($sql);
192 210
 if ( $resql )
@@ -227,8 +245,9 @@  discard block
 block discarded – undo
227 245
 		}
228 246
 		print "</table><br>";
229 247
 	}
248
+} else {
249
+    dol_print_error($db);
230 250
 }
231
-else dol_print_error($db);
232 251
 
233 252
 
234 253
 /*
@@ -241,11 +260,17 @@  discard block
 block discarded – undo
241 260
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as el ON e.rowid = el.fk_target AND el.targettype = 'shipping' AND el.sourcetype IN ('commande')";
242 261
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande as c ON el.fk_source = c.rowid AND el.sourcetype IN ('commande') AND el.targettype = 'shipping'";
243 262
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
244
-if (! $user->rights->societe->client->voir && ! $socid) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
263
+if (! $user->rights->societe->client->voir && ! $socid) {
264
+    $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON e.fk_soc = sc.fk_soc";
265
+}
245 266
 $sql.= " WHERE e.entity IN (".getEntity('expedition').")";
246
-if (! $user->rights->societe->client->voir && ! $socid) $sql.= " AND sc.fk_user = " .$user->id;
267
+if (! $user->rights->societe->client->voir && ! $socid) {
268
+    $sql.= " AND sc.fk_user = " .$user->id;
269
+}
247 270
 $sql.= " AND e.fk_statut = 1";
248
-if ($socid) $sql.= " AND c.fk_soc = ".$socid;
271
+if ($socid) {
272
+    $sql.= " AND c.fk_soc = ".$socid;
273
+}
249 274
 $sql.= " ORDER BY e.date_delivery DESC";
250 275
 $sql.= $db->plimit(5, 0);
251 276
 
@@ -277,16 +302,18 @@  discard block
 block discarded – undo
277 302
 				$orderstatic->id=$obj->commande_id;
278 303
 				$orderstatic->ref=$obj->commande_ref;
279 304
 				print $orderstatic->getNomUrl(1);
305
+			} else {
306
+			    print '&nbsp;';
280 307
 			}
281
-			else print '&nbsp;';
282 308
 			print '</td></tr>';
283 309
 			$i++;
284 310
 		}
285 311
 		print "</table><br>";
286 312
 	}
287 313
 	$db->free($resql);
314
+} else {
315
+    dol_print_error($db);
288 316
 }
289
-else dol_print_error($db);
290 317
 
291 318
 
292 319
 print '</div></div></div>';
Please login to merge, or discard this patch.
dolibarr/htdocs/expedition/contact.php 3 patches
Indentation   +93 added lines, -93 removed lines patch added patch discarded remove patch
@@ -80,26 +80,26 @@  discard block
 block discarded – undo
80 80
 {
81 81
     if ($result > 0 && $id > 0)
82 82
     {
83
-  		$result = $objectsrc->add_contact(GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'), $_POST["type"], $_POST["source"]);
83
+            $result = $objectsrc->add_contact(GETPOST('userid') ? GETPOST('userid') : GETPOST('contactid'), $_POST["type"], $_POST["source"]);
84 84
     }
85 85
 
86
-	if ($result >= 0)
87
-	{
88
-		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
89
-		exit;
90
-	}
91
-	else
92
-	{
93
-		if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
94
-		{
95
-			$langs->load("errors");
96
-			$mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
97
-		} else {
98
-			$mesg = $objectsrc->error;
99
-			$mesgs = $objectsrc->errors;
100
-		}
101
-		setEventMessages($mesg, $mesgs, 'errors');
102
-	}
86
+    if ($result >= 0)
87
+    {
88
+        header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
89
+        exit;
90
+    }
91
+    else
92
+    {
93
+        if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
94
+        {
95
+            $langs->load("errors");
96
+            $mesg = $langs->trans("ErrorThisContactIsAlreadyDefinedAsThisType");
97
+        } else {
98
+            $mesg = $objectsrc->error;
99
+            $mesgs = $objectsrc->errors;
100
+        }
101
+        setEventMessages($mesg, $mesgs, 'errors');
102
+    }
103 103
 }
104 104
 
105 105
 // bascule du statut d'un contact
@@ -111,16 +111,16 @@  discard block
 block discarded – undo
111 111
 // Efface un contact
112 112
 else if ($action == 'deletecontact' && $user->rights->expedition->creer)
113 113
 {
114
-	$result = $objectsrc->delete_contact(GETPOST("lineid"));
115
-
116
-	if ($result >= 0)
117
-	{
118
-		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
119
-		exit;
120
-	}
121
-	else {
122
-		dol_print_error($db);
123
-	}
114
+    $result = $objectsrc->delete_contact(GETPOST("lineid"));
115
+
116
+    if ($result >= 0)
117
+    {
118
+        header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
119
+        exit;
120
+    }
121
+    else {
122
+        dol_print_error($db);
123
+    }
124 124
 }
125 125
 /*
126 126
 else if ($action == 'setaddress' && $user->rights->expedition->creer)
@@ -152,20 +152,20 @@  discard block
 block discarded – undo
152 152
 
153 153
 if ($id > 0 || ! empty($ref))
154 154
 {
155
-	$langs->trans("OrderCard");
155
+    $langs->trans("OrderCard");
156 156
 
157
-	$head = shipping_prepare_head($object);
158
-	dol_fiche_head($head, 'contact', $langs->trans("Shipment"), -1, 'sending');
157
+    $head = shipping_prepare_head($object);
158
+    dol_fiche_head($head, 'contact', $langs->trans("Shipment"), -1, 'sending');
159 159
 
160 160
 
161
-	// Shipment card
162
-	$linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">'.$langs->trans("BackToList").'</a>';
161
+    // Shipment card
162
+    $linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">'.$langs->trans("BackToList").'</a>';
163 163
 
164
-	$morehtmlref='<div class="refidno">';
165
-	// Ref customer shipment
166
-	$morehtmlref.=$form->editfieldkey("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', 0, 1);
167
-	$morehtmlref.=$form->editfieldval("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', null, null, '', 1);
168
-	// Thirdparty
164
+    $morehtmlref='<div class="refidno">';
165
+    // Ref customer shipment
166
+    $morehtmlref.=$form->editfieldkey("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', 0, 1);
167
+    $morehtmlref.=$form->editfieldval("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', null, null, '', 1);
168
+    // Thirdparty
169 169
     $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
170 170
     // Project
171 171
     if (! empty($conf->projet->enabled)) {
@@ -201,70 +201,70 @@  discard block
 block discarded – undo
201 201
             }
202 202
         }
203 203
     }
204
-	$morehtmlref.='</div>';
204
+    $morehtmlref.='</div>';
205 205
 
206 206
 
207
-	dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
207
+    dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
208 208
 
209 209
 
210
-	print '<div class="fichecenter">';
210
+    print '<div class="fichecenter">';
211 211
     //print '<div class="fichehalfleft">';
212
-	print '<div class="underbanner clearboth"></div>';
212
+    print '<div class="underbanner clearboth"></div>';
213 213
 
214 214
     print '<table class="border centpercent">';
215 215
 
216 216
     // Linked documents
217
-	if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
218
-	{
219
-	    print '<tr><td class="titlefield">';
220
-	    $objectsrc=new Commande($db);
221
-	    $objectsrc->fetch($object->$typeobject->id);
222
-	    print $langs->trans("RefOrder").'</td>';
223
-	    print '<td colspan="3">';
224
-	    print $objectsrc->getNomUrl(1,'commande');
225
-	    print "</td>\n";
226
-	    print '</tr>';
227
-	}
228
-	if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
229
-	{
230
-	    print '<tr><td class="titlefield">';
231
-	    $objectsrc=new Propal($db);
232
-	    $objectsrc->fetch($object->$typeobject->id);
233
-	    print $langs->trans("RefProposal").'</td>';
234
-	    print '<td colspan="3">';
235
-	    print $objectsrc->getNomUrl(1,'expedition');
236
-	    print "</td>\n";
237
-	    print '</tr>';
238
-	}
239
-
240
-	print "</table>";
241
-
242
-
243
-	//print '</div>';
244
-	//print '<div class="fichehalfright">';
245
-	//print '<div class="ficheaddleft">';
246
-	//print '<div class="underbanner clearboth"></div>';
247
-
248
-
249
-	//print '</div>';
250
-	//print '</div>';
251
-	print '</div>';
252
-
253
-	print '<div class="clearboth"></div>';
254
-
255
-
256
-	dol_fiche_end();
257
-
258
-	// Lignes de contacts
259
-	echo '<br>';
260
-
261
-	// Contacts lines (modules that overwrite templates must declare this into descriptor)
262
-	$dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
263
-	foreach($dirtpls as $reldir)
264
-	{
265
-	    $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
266
-	    if ($res) break;
267
-	}
217
+    if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
218
+    {
219
+        print '<tr><td class="titlefield">';
220
+        $objectsrc=new Commande($db);
221
+        $objectsrc->fetch($object->$typeobject->id);
222
+        print $langs->trans("RefOrder").'</td>';
223
+        print '<td colspan="3">';
224
+        print $objectsrc->getNomUrl(1,'commande');
225
+        print "</td>\n";
226
+        print '</tr>';
227
+    }
228
+    if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
229
+    {
230
+        print '<tr><td class="titlefield">';
231
+        $objectsrc=new Propal($db);
232
+        $objectsrc->fetch($object->$typeobject->id);
233
+        print $langs->trans("RefProposal").'</td>';
234
+        print '<td colspan="3">';
235
+        print $objectsrc->getNomUrl(1,'expedition');
236
+        print "</td>\n";
237
+        print '</tr>';
238
+    }
239
+
240
+    print "</table>";
241
+
242
+
243
+    //print '</div>';
244
+    //print '<div class="fichehalfright">';
245
+    //print '<div class="ficheaddleft">';
246
+    //print '<div class="underbanner clearboth"></div>';
247
+
248
+
249
+    //print '</div>';
250
+    //print '</div>';
251
+    print '</div>';
252
+
253
+    print '<div class="clearboth"></div>';
254
+
255
+
256
+    dol_fiche_end();
257
+
258
+    // Lignes de contacts
259
+    echo '<br>';
260
+
261
+    // Contacts lines (modules that overwrite templates must declare this into descriptor)
262
+    $dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
263
+    foreach($dirtpls as $reldir)
264
+    {
265
+        $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
266
+        if ($res) break;
267
+    }
268 268
 }
269 269
 
270 270
 // End of page
Please login to merge, or discard this patch.
Spacing   +40 added lines, -40 removed lines patch added patch discarded remove patch
@@ -29,7 +29,7 @@  discard block
 block discarded – undo
29 29
 require_once DOL_DOCUMENT_ROOT.'/core/lib/sendings.lib.php';
30 30
 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
31 31
 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
32
-if (! empty($conf->projet->enabled)) {
32
+if (!empty($conf->projet->enabled)) {
33 33
     require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
34 34
     require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php';
35 35
 }
@@ -37,16 +37,16 @@  discard block
 block discarded – undo
37 37
 // Load translation files required by the page
38 38
 $langs->loadLangs(array('orders', 'sendings', 'companies'));
39 39
 
40
-$id=GETPOST('id','int');
41
-$ref=GETPOST('ref','alpha');
42
-$action=GETPOST('action','alpha');
40
+$id = GETPOST('id', 'int');
41
+$ref = GETPOST('ref', 'alpha');
42
+$action = GETPOST('action', 'alpha');
43 43
 
44 44
 // Security check
45
-if ($user->societe_id) $socid=$user->societe_id;
46
-$result = restrictedArea($user, 'expedition', $id,'');
45
+if ($user->societe_id) $socid = $user->societe_id;
46
+$result = restrictedArea($user, 'expedition', $id, '');
47 47
 
48 48
 $object = new Expedition($db);
49
-if ($id > 0 || ! empty($ref))
49
+if ($id > 0 || !empty($ref))
50 50
 {
51 51
     $object->fetch($id, $ref);
52 52
     $object->fetch_thirdparty();
@@ -59,14 +59,14 @@  discard block
 block discarded – undo
59 59
     }
60 60
 
61 61
     // Linked documents
62
-    if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
62
+    if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled))
63 63
     {
64
-        $objectsrc=new Commande($db);
64
+        $objectsrc = new Commande($db);
65 65
         $objectsrc->fetch($object->$typeobject->id);
66 66
     }
67
-    if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
67
+    if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled))
68 68
     {
69
-        $objectsrc=new Propal($db);
69
+        $objectsrc = new Propal($db);
70 70
         $objectsrc->fetch($object->$typeobject->id);
71 71
     }
72 72
 }
@@ -105,7 +105,7 @@  discard block
 block discarded – undo
105 105
 // bascule du statut d'un contact
106 106
 else if ($action == 'swapstatut' && $user->rights->expedition->creer)
107 107
 {
108
-    $result=$objectsrc->swapContactStatus(GETPOST('ligne'));
108
+    $result = $objectsrc->swapContactStatus(GETPOST('ligne'));
109 109
 }
110 110
 
111 111
 // Efface un contact
@@ -135,13 +135,13 @@  discard block
 block discarded – undo
135 135
  * View
136 136
  */
137 137
 
138
-llxHeader('',$langs->trans('Order'),'EN:Customers_Orders|FR:expeditions_Clients|ES:Pedidos de clientes');
138
+llxHeader('', $langs->trans('Order'), 'EN:Customers_Orders|FR:expeditions_Clients|ES:Pedidos de clientes');
139 139
 
140 140
 $form = new Form($db);
141 141
 $formcompany = new FormCompany($db);
142 142
 $formother = new FormOther($db);
143
-$contactstatic=new Contact($db);
144
-$userstatic=new User($db);
143
+$contactstatic = new Contact($db);
144
+$userstatic = new User($db);
145 145
 
146 146
 
147 147
 /* *************************************************************************** */
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 /*                                                                             */
151 151
 /* *************************************************************************** */
152 152
 
153
-if ($id > 0 || ! empty($ref))
153
+if ($id > 0 || !empty($ref))
154 154
 {
155 155
 	$langs->trans("OrderCard");
156 156
 
@@ -159,41 +159,41 @@  discard block
 block discarded – undo
159 159
 
160 160
 
161 161
 	// Shipment card
162
-	$linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1' . (! empty($socid) ? '&socid=' . $socid : '') . '">'.$langs->trans("BackToList").'</a>';
162
+	$linkback = '<a href="'.DOL_URL_ROOT.'/expedition/list.php?restore_lastsearch_values=1'.(!empty($socid) ? '&socid='.$socid : '').'">'.$langs->trans("BackToList").'</a>';
163 163
 
164
-	$morehtmlref='<div class="refidno">';
164
+	$morehtmlref = '<div class="refidno">';
165 165
 	// Ref customer shipment
166
-	$morehtmlref.=$form->editfieldkey("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', 0, 1);
167
-	$morehtmlref.=$form->editfieldval("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', null, null, '', 1);
166
+	$morehtmlref .= $form->editfieldkey("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', 0, 1);
167
+	$morehtmlref .= $form->editfieldval("RefCustomer", '', $object->ref_customer, $object, $user->rights->expedition->creer, 'string', '', null, null, '', 1);
168 168
 	// Thirdparty
169
-    $morehtmlref.='<br>'.$langs->trans('ThirdParty') . ' : ' . $object->thirdparty->getNomUrl(1);
169
+    $morehtmlref .= '<br>'.$langs->trans('ThirdParty').' : '.$object->thirdparty->getNomUrl(1);
170 170
     // Project
171
-    if (! empty($conf->projet->enabled)) {
171
+    if (!empty($conf->projet->enabled)) {
172 172
         $langs->load("projects");
173
-        $morehtmlref .= '<br>' . $langs->trans('Project') . ' ';
173
+        $morehtmlref .= '<br>'.$langs->trans('Project').' ';
174 174
         if (0) {    // Do not change on shipment
175 175
             if ($action != 'classify') {
176
-                $morehtmlref .= '<a href="' . $_SERVER['PHP_SELF'] . '?action=classify&amp;id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
176
+                $morehtmlref .= '<a href="'.$_SERVER['PHP_SELF'].'?action=classify&amp;id='.$object->id.'">'.img_edit($langs->transnoentitiesnoconv('SetProject')).'</a> : ';
177 177
             }
178 178
             if ($action == 'classify') {
179 179
                 // $morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
180
-                $morehtmlref .= '<form method="post" action="' . $_SERVER['PHP_SELF'] . '?id=' . $object->id . '">';
180
+                $morehtmlref .= '<form method="post" action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'">';
181 181
                 $morehtmlref .= '<input type="hidden" name="action" value="classin">';
182
-                $morehtmlref .= '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
182
+                $morehtmlref .= '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
183 183
                 $morehtmlref .= $formproject->select_projects($object->socid, $object->fk_project, 'projectid', $maxlength, 0, 1, 0, 1, 0, 0, '', 1);
184
-                $morehtmlref .= '<input type="submit" class="button" value="' . $langs->trans("Modify") . '">';
184
+                $morehtmlref .= '<input type="submit" class="button" value="'.$langs->trans("Modify").'">';
185 185
                 $morehtmlref .= '</form>';
186 186
             } else {
187
-                $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
187
+                $morehtmlref .= $form->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none', 0, 0, 0, 1);
188 188
             }
189 189
         } else {
190 190
             // We don't have project on shipment, so we will use the project or source object instead
191 191
             // TODO Add project on shipment
192 192
             $morehtmlref .= ' : ';
193
-            if (! empty($objectsrc->fk_project)) {
193
+            if (!empty($objectsrc->fk_project)) {
194 194
                 $proj = new Project($db);
195 195
                 $proj->fetch($objectsrc->fk_project);
196
-                $morehtmlref .= '<a href="' . DOL_URL_ROOT . '/projet/card.php?id=' . $objectsrc->fk_project . '" title="' . $langs->trans('ShowProject') . '">';
196
+                $morehtmlref .= '<a href="'.DOL_URL_ROOT.'/projet/card.php?id='.$objectsrc->fk_project.'" title="'.$langs->trans('ShowProject').'">';
197 197
                 $morehtmlref .= $proj->ref;
198 198
                 $morehtmlref .= '</a>';
199 199
             } else {
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
             }
202 202
         }
203 203
     }
204
-	$morehtmlref.='</div>';
204
+	$morehtmlref .= '</div>';
205 205
 
206 206
 
207 207
 	dol_banner_tab($object, 'ref', $linkback, 1, 'ref', 'ref', $morehtmlref);
@@ -214,25 +214,25 @@  discard block
 block discarded – undo
214 214
     print '<table class="border centpercent">';
215 215
 
216 216
     // Linked documents
217
-	if ($typeobject == 'commande' && $object->$typeobject->id && ! empty($conf->commande->enabled))
217
+	if ($typeobject == 'commande' && $object->$typeobject->id && !empty($conf->commande->enabled))
218 218
 	{
219 219
 	    print '<tr><td class="titlefield">';
220
-	    $objectsrc=new Commande($db);
220
+	    $objectsrc = new Commande($db);
221 221
 	    $objectsrc->fetch($object->$typeobject->id);
222 222
 	    print $langs->trans("RefOrder").'</td>';
223 223
 	    print '<td colspan="3">';
224
-	    print $objectsrc->getNomUrl(1,'commande');
224
+	    print $objectsrc->getNomUrl(1, 'commande');
225 225
 	    print "</td>\n";
226 226
 	    print '</tr>';
227 227
 	}
228
-	if ($typeobject == 'propal' && $object->$typeobject->id && ! empty($conf->propal->enabled))
228
+	if ($typeobject == 'propal' && $object->$typeobject->id && !empty($conf->propal->enabled))
229 229
 	{
230 230
 	    print '<tr><td class="titlefield">';
231
-	    $objectsrc=new Propal($db);
231
+	    $objectsrc = new Propal($db);
232 232
 	    $objectsrc->fetch($object->$typeobject->id);
233 233
 	    print $langs->trans("RefProposal").'</td>';
234 234
 	    print '<td colspan="3">';
235
-	    print $objectsrc->getNomUrl(1,'expedition');
235
+	    print $objectsrc->getNomUrl(1, 'expedition');
236 236
 	    print "</td>\n";
237 237
 	    print '</tr>';
238 238
 	}
@@ -259,10 +259,10 @@  discard block
 block discarded – undo
259 259
 	echo '<br>';
260 260
 
261 261
 	// Contacts lines (modules that overwrite templates must declare this into descriptor)
262
-	$dirtpls=array_merge($conf->modules_parts['tpl'],array('/core/tpl'));
263
-	foreach($dirtpls as $reldir)
262
+	$dirtpls = array_merge($conf->modules_parts['tpl'], array('/core/tpl'));
263
+	foreach ($dirtpls as $reldir)
264 264
 	{
265
-	    $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
265
+	    $res = @include dol_buildpath($reldir.'/contacts.tpl.php');
266 266
 	    if ($res) break;
267 267
 	}
268 268
 }
Please login to merge, or discard this patch.
Braces   +8 added lines, -6 removed lines patch added patch discarded remove patch
@@ -42,7 +42,9 @@  discard block
 block discarded – undo
42 42
 $action=GETPOST('action','alpha');
43 43
 
44 44
 // Security check
45
-if ($user->societe_id) $socid=$user->societe_id;
45
+if ($user->societe_id) {
46
+    $socid=$user->societe_id;
47
+}
46 48
 $result = restrictedArea($user, 'expedition', $id,'');
47 49
 
48 50
 $object = new Expedition($db);
@@ -87,8 +89,7 @@  discard block
 block discarded – undo
87 89
 	{
88 90
 		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
89 91
 		exit;
90
-	}
91
-	else
92
+	} else
92 93
 	{
93 94
 		if ($objectsrc->error == 'DB_ERROR_RECORD_ALREADY_EXISTS')
94 95
 		{
@@ -117,8 +118,7 @@  discard block
 block discarded – undo
117 118
 	{
118 119
 		header("Location: ".$_SERVER['PHP_SELF']."?id=".$object->id);
119 120
 		exit;
120
-	}
121
-	else {
121
+	} else {
122 122
 		dol_print_error($db);
123 123
 	}
124 124
 }
@@ -263,7 +263,9 @@  discard block
 block discarded – undo
263 263
 	foreach($dirtpls as $reldir)
264 264
 	{
265 265
 	    $res=@include dol_buildpath($reldir.'/contacts.tpl.php');
266
-	    if ($res) break;
266
+	    if ($res) {
267
+	        break;
268
+	    }
267 269
 	}
268 270
 }
269 271
 
Please login to merge, or discard this patch.
dolibarr/htdocs/expedition/list.php 3 patches
Indentation   +430 added lines, -430 removed lines patch added patch discarded remove patch
@@ -81,38 +81,38 @@  discard block
 block discarded – undo
81 81
 
82 82
 // List of fields to search into when doing a "search in all"
83 83
 $fieldstosearchall = array(
84
-	'e.ref'=>"Ref",
85
-	's.nom'=>"ThirdParty",
86
-	'e.note_public'=>'NotePublic',
84
+    'e.ref'=>"Ref",
85
+    's.nom'=>"ThirdParty",
86
+    'e.note_public'=>'NotePublic',
87 87
 );
88 88
 if (empty($user->socid)) $fieldstosearchall["e.note_private"]="NotePrivate";
89 89
 
90 90
 $checkedtypetiers=0;
91 91
 $arrayfields=array(
92
-	'e.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
93
-	'e.ref_customer'=>array('label'=>$langs->trans("RefCustomer"), 'checked'=>1),
94
-	's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
95
-	's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1),
96
-	's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1),
97
-	'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),
98
-	'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),
99
-	'typent.code'=>array('label'=>$langs->trans("ThirdPartyType"), 'checked'=>$checkedtypetiers),
100
-	'e.date_delivery'=>array('label'=>$langs->trans("DateDeliveryPlanned"), 'checked'=>1),
101
-	'e.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
102
-	'e.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
103
-	'e.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
104
-	'l.ref'=>array('label'=>$langs->trans("DeliveryRef"), 'checked'=>1, 'enabled'=>(empty($conf->livraison_bon->enabled)?0:1)),
105
-	'l.date_delivery'=>array('label'=>$langs->trans("DateReceived"), 'checked'=>1, 'enabled'=>(empty($conf->livraison_bon->enabled)?0:1)),
106
-	'e.billed'=>array('label'=>$langs->trans("Billed"), 'checked'=>1, 'position'=>1000, 'enabled'=>(!empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)))
92
+    'e.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
93
+    'e.ref_customer'=>array('label'=>$langs->trans("RefCustomer"), 'checked'=>1),
94
+    's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
95
+    's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>1),
96
+    's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1),
97
+    'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),
98
+    'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),
99
+    'typent.code'=>array('label'=>$langs->trans("ThirdPartyType"), 'checked'=>$checkedtypetiers),
100
+    'e.date_delivery'=>array('label'=>$langs->trans("DateDeliveryPlanned"), 'checked'=>1),
101
+    'e.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
102
+    'e.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
103
+    'e.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
104
+    'l.ref'=>array('label'=>$langs->trans("DeliveryRef"), 'checked'=>1, 'enabled'=>(empty($conf->livraison_bon->enabled)?0:1)),
105
+    'l.date_delivery'=>array('label'=>$langs->trans("DateReceived"), 'checked'=>1, 'enabled'=>(empty($conf->livraison_bon->enabled)?0:1)),
106
+    'e.billed'=>array('label'=>$langs->trans("Billed"), 'checked'=>1, 'position'=>1000, 'enabled'=>(!empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)))
107 107
 );
108 108
 
109 109
 // Extra fields
110 110
 if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
111 111
 {
112
-	foreach($extrafields->attribute_label as $key => $val)
113
-	{
114
-		if (! empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key])!=3 && $extrafields->attribute_perms[$key]));
115
-	}
112
+    foreach($extrafields->attribute_label as $key => $val)
113
+    {
114
+        if (! empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key])!=3 && $extrafields->attribute_perms[$key]));
115
+    }
116 116
 }
117 117
 
118 118
 
@@ -132,36 +132,36 @@  discard block
 block discarded – undo
132 132
 // Purge search criteria
133 133
 if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
134 134
 {
135
-	$search_ref_exp='';
136
-	$search_ref_liv='';
137
-	$search_ref_customer='';
138
-	$search_company='';
139
-	$search_town='';
140
-	$search_zip="";
141
-	$search_state="";
142
-	$search_type='';
143
-	$search_country='';
144
-	$search_type_thirdparty='';
145
-	$search_billed='';
146
-	$viewstatut='';
147
-	$search_array_options=array();
135
+    $search_ref_exp='';
136
+    $search_ref_liv='';
137
+    $search_ref_customer='';
138
+    $search_company='';
139
+    $search_town='';
140
+    $search_zip="";
141
+    $search_state="";
142
+    $search_type='';
143
+    $search_country='';
144
+    $search_type_thirdparty='';
145
+    $search_billed='';
146
+    $viewstatut='';
147
+    $search_array_options=array();
148 148
 }
149 149
 
150 150
 if (empty($reshook))
151 151
 {
152
-	// Mass actions. Controls on number of lines checked
153
-	$maxformassaction=1000;
154
-	$numtoselect = (is_array($toselect)?count($toselect):0);
155
-	if (! empty($massaction) && $numtoselect < 1)
156
-	{
157
-		$error++;
158
-		setEventMessages($langs->trans("NoLineChecked"), null, "warnings");
159
-	}
160
-	if (! $error && $numtoselect > $maxformassaction)
161
-	{
162
-		setEventMessages($langs->trans('TooManyRecordForMassAction',$maxformassaction), null, 'errors');
163
-		$error++;
164
-	}
152
+    // Mass actions. Controls on number of lines checked
153
+    $maxformassaction=1000;
154
+    $numtoselect = (is_array($toselect)?count($toselect):0);
155
+    if (! empty($massaction) && $numtoselect < 1)
156
+    {
157
+        $error++;
158
+        setEventMessages($langs->trans("NoLineChecked"), null, "warnings");
159
+    }
160
+    if (! $error && $numtoselect > $maxformassaction)
161
+    {
162
+        setEventMessages($langs->trans('TooManyRecordForMassAction',$maxformassaction), null, 'errors');
163
+        $error++;
164
+    }
165 165
 }
166 166
 
167 167
 
@@ -200,20 +200,20 @@  discard block
 block discarded – undo
200 200
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.rowid = ee.fk_target";
201 201
 if (!$user->rights->societe->client->voir && !$socid)	// Internal user with no permission to see all
202 202
 {
203
-	$sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
203
+    $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
204 204
 }
205 205
 $sql.= " WHERE e.entity IN (".getEntity('expedition').")";
206 206
 if (!$user->rights->societe->client->voir && !$socid)	// Internal user with no permission to see all
207 207
 {
208
-	$sql.= " AND e.fk_soc = sc.fk_soc";
209
-	$sql.= " AND sc.fk_user = " .$user->id;
208
+    $sql.= " AND e.fk_soc = sc.fk_soc";
209
+    $sql.= " AND sc.fk_user = " .$user->id;
210 210
 }
211 211
 if ($socid)
212 212
 {
213
-	$sql.= " AND e.fk_soc = ".$socid;
213
+    $sql.= " AND e.fk_soc = ".$socid;
214 214
 }
215 215
 if ($viewstatut <> '' && $viewstatut >= 0) {
216
-	$sql.= " AND e.fk_statut = ".$viewstatut;
216
+    $sql.= " AND e.fk_statut = ".$viewstatut;
217 217
 }
218 218
 if ($search_ref_customer != '') $sql.=natural_search('e.ref_customer', $search_ref_customer);
219 219
 if ($search_billed != '' && $search_billed >= 0) $sql.=' AND e.billed = '.$search_billed;
@@ -240,13 +240,13 @@  discard block
 block discarded – undo
240 240
 $nbtotalofrecords = '';
241 241
 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
242 242
 {
243
-	$result = $db->query($sql);
244
-	$nbtotalofrecords = $db->num_rows($result);
245
-	if (($page * $limit) > $nbtotalofrecords)	// if total resultset is smaller then paging size (filtering), goto and load page 0
246
-	{
247
-		$page = 0;
248
-		$offset = 0;
249
-	}
243
+    $result = $db->query($sql);
244
+    $nbtotalofrecords = $db->num_rows($result);
245
+    if (($page * $limit) > $nbtotalofrecords)	// if total resultset is smaller then paging size (filtering), goto and load page 0
246
+    {
247
+        $page = 0;
248
+        $offset = 0;
249
+    }
250 250
 }
251 251
 
252 252
 $sql.= $db->plimit($limit + 1,$offset);
@@ -255,382 +255,382 @@  discard block
 block discarded – undo
255 255
 $resql=$db->query($sql);
256 256
 if ($resql)
257 257
 {
258
-	$num = $db->num_rows($resql);
259
-
260
-	$expedition = new Expedition($db);
261
-
262
-	$param='';
263
-	if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
264
-	if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
265
-	if ($sall) $param.= "&amp;sall=".urlencode($sall);
266
-	if ($search_ref_exp)  $param.= "&amp;search_ref_exp=".urlencode($search_ref_exp);
267
-	if ($search_ref_liv)  $param.= "&amp;search_ref_liv=".urlencode($search_ref_liv);
268
-	if ($search_ref_customer) $param.= "&amp;search_ref_customer=".urlencode($search_ref_customer);
269
-	if ($search_company)   $param.= "&amp;search_company=".urlencode($search_company);
270
-	if ($search_town)      $param.= '&search_town='.urlencode($search_town);
271
-	if ($search_zip)       $param.= '&search_zip='.urlencode($search_zip);
272
-	if ($viewstatut != '') $param.= '&viewstatut='.urlencode($viewstatut);
273
-	if ($optioncss != '')  $param.='&amp;optioncss='.urlencode($optioncss);
274
-	// Add $param from extra fields
275
-	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
276
-
277
-	//$massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
278
-
279
-	$newcardbutton='';
280
-	if ($user->rights->expedition->creer)
281
-	{
282
-		$newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/expedition/card.php?action=create2"><span class="valignmiddle">'.$langs->trans('NewSending').'</span>';
283
-		$newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
284
-		$newcardbutton.= '</a>';
285
-	}
286
-
287
-	$i = 0;
288
-	print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
289
-	if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
290
-	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
291
-	print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
292
-	print '<input type="hidden" name="action" value="list">';
293
-	print '<input type="hidden" name="page" value="'.$page.'">';
294
-	print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
295
-	print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
296
-
297
-	print_barre_liste($langs->trans('ListOfSendings'), $page, $_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num, $nbtotalofrecords, '', 0, $newcardbutton, '', $limit);
298
-
299
-	if ($sall)
300
-	{
301
-		foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
302
-		print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall).'</div>';
303
-	}
304
-
305
-	$moreforfilter='';
306
-	if (! empty($moreforfilter))
307
-	{
308
-		print '<div class="liste_titre liste_titre_bydiv centpercent">';
309
-		print $moreforfilter;
310
-		$parameters=array('type'=>$type);
311
-		$reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters);    // Note that $action and $object may have been modified by hook
312
-		print $hookmanager->resPrint;
313
-		print '</div>';
314
-	}
315
-
316
-	$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
317
-	$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage);	// This also change content of $arrayfields
318
-
319
-	print '<div class="div-table-responsive">';
320
-	print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
321
-
322
-	// Lignes des champs de filtre
323
-	print '<tr class="liste_titre_filter">';
324
-	// Ref
325
-	if (! empty($arrayfields['e.ref']['checked']))
326
-	{
327
-		print '<td class="liste_titre">';
328
-		print '<input class="flat" size="6" type="text" name="search_ref_exp" value="'.$search_ref_exp.'">';
329
-		print '</td>';
330
-	}
331
-	// Ref customer
332
-	if (! empty($arrayfields['e.ref_customer']['checked']))
333
-	{
334
-		print '<td class="liste_titre">';
335
-		print '<input class="flat" size="6" type="text" name="search_ref_customer" value="'.$search_ref_customer.'">';
336
-		print '</td>';
337
-	}
338
-	// Thirdparty
339
-	if (! empty($arrayfields['s.nom']['checked']))
340
-	{
341
-		print '<td class="liste_titre" align="left">';
342
-		print '<input class="flat" type="text" size="8" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
343
-		print '</td>';
344
-	}
345
-	// Town
346
-	if (! empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
347
-	// Zip
348
-	if (! empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
349
-	// State
350
-	if (! empty($arrayfields['state.nom']['checked']))
351
-	{
352
-		print '<td class="liste_titre">';
353
-		print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
354
-		print '</td>';
355
-	}
356
-	// Country
357
-	if (! empty($arrayfields['country.code_iso']['checked']))
358
-	{
359
-		print '<td class="liste_titre" align="center">';
360
-		print $form->select_country($search_country,'search_country','',0,'maxwidth100');
361
-		print '</td>';
362
-	}
363
-	// Company type
364
-	if (! empty($arrayfields['typent.code']['checked']))
365
-	{
366
-		print '<td class="liste_titre maxwidthonsmartphone" align="center">';
367
-		print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
368
-		print '</td>';
369
-	}
370
-	// Date delivery planned
371
-	if (! empty($arrayfields['e.date_delivery']['checked']))
372
-	{
373
-		print '<td class="liste_titre">&nbsp;</td>';
374
-	}
375
-	if (! empty($arrayfields['l.ref']['checked']))
376
-	{
377
-		// Delivery ref
378
-		print '<td class="liste_titre">';
379
-		print '<input class="flat" size="10" type="text" name="search_ref_liv" value="'.$search_ref_liv.'"';
380
-		print '</td>';
381
-	}
382
-	if (! empty($arrayfields['l.date_delivery']['checked']))
383
-	{
384
-		// Date received
385
-		print '<td class="liste_titre">&nbsp;</td>';
386
-	}
387
-	// Extra fields
388
-	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
389
-
390
-	// Fields from hook
391
-	$parameters=array('arrayfields'=>$arrayfields);
392
-	$reshook=$hookmanager->executeHooks('printFieldListOption',$parameters);    // Note that $action and $object may have been modified by hook
393
-	print $hookmanager->resPrint;
394
-	// Date creation
395
-	if (! empty($arrayfields['e.datec']['checked']))
396
-	{
397
-		print '<td class="liste_titre">';
398
-		print '</td>';
399
-	}
400
-	// Date modification
401
-	if (! empty($arrayfields['e.tms']['checked']))
402
-	{
403
-		print '<td class="liste_titre">';
404
-		print '</td>';
405
-	}
406
-	// Status
407
-	if (! empty($arrayfields['e.fk_statut']['checked']))
408
-	{
409
-		print '<td class="liste_titre maxwidthonsmartphone" align="right">';
410
-		print $form->selectarray('viewstatut', array('0'=>$langs->trans('StatusSendingDraftShort'),'1'=>$langs->trans('StatusSendingValidatedShort'),'2'=>$langs->trans('StatusSendingProcessedShort')),$viewstatut,1);
411
-		print '</td>';
412
-	}
413
-	// Status billed
414
-	if (! empty($arrayfields['e.billed']['checked']))
415
-	{
416
-		print '<td class="liste_titre maxwidthonsmartphone" align="center">';
417
-		print $form->selectyesno('search_billed', $search_billed, 1, 0, 1);
418
-		print '</td>';
419
-	}
420
-	// Action column
421
-	print '<td class="liste_titre" align="middle">';
422
-	$searchpicto=$form->showFilterAndCheckAddButtons(0);
423
-	print $searchpicto;
424
-	print '</td>';
425
-	print "</tr>\n";
426
-
427
-	print '<tr class="liste_titre">';
428
-	if (! empty($arrayfields['e.ref']['checked']))            print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"],"e.ref","",$param,'',$sortfield,$sortorder);
429
-	if (! empty($arrayfields['e.ref_customer']['checked']))   print_liste_field_titre($arrayfields['e.ref_customer']['label'], $_SERVER["PHP_SELF"],"e.ref_customer","",$param,'',$sortfield,$sortorder);
430
-	if (! empty($arrayfields['s.nom']['checked']))            print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"],"s.nom", "", $param,'align="left"',$sortfield,$sortorder);
431
-	if (! empty($arrayfields['s.town']['checked']))           print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
432
-	if (! empty($arrayfields['s.zip']['checked']))            print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
433
-	if (! empty($arrayfields['state.nom']['checked']))        print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
434
-	if (! empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'],$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder);
435
-	if (! empty($arrayfields['typent.code']['checked']))      print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
436
-	if (! empty($arrayfields['e.date_delivery']['checked']))  print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"],"e.date_delivery","",$param, 'align="center"',$sortfield,$sortorder);
437
-	if (! empty($arrayfields['l.ref']['checked']))            print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"],"l.ref","",$param, '',$sortfield,$sortorder);
438
-	if (! empty($arrayfields['l.date_delivery']['checked']))  print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"],"l.date_delivery","",$param, 'align="center"',$sortfield,$sortorder);
439
-	// Extra fields
440
-	if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
441
-	{
442
-		foreach($extrafields->attribute_label as $key => $val)
443
-		{
444
-			if (! empty($arrayfields["ef.".$key]['checked']))
445
-			{
446
-				$align=$extrafields->getAlignFlag($key);
447
-				$sortonfield = "ef.".$key;
448
-				if (! empty($extrafields->attribute_computed[$key])) $sortonfield='';
449
-				print_liste_field_titre($extralabels[$key],$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
450
-			}
451
-		}
452
-	}
453
-	// Hook fields
454
-	$parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder);
455
-	$reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters);    // Note that $action and $object may have been modified by hook
456
-	print $hookmanager->resPrint;
457
-	if (! empty($arrayfields['e.datec']['checked']))  print_liste_field_titre($arrayfields['e.datec']['label'],$_SERVER["PHP_SELF"],"e.date_creation","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
458
-	if (! empty($arrayfields['e.tms']['checked']))    print_liste_field_titre($arrayfields['e.tms']['label'],$_SERVER["PHP_SELF"],"e.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
459
-	if (! empty($arrayfields['e.fk_statut']['checked'])) print_liste_field_titre($arrayfields['e.fk_statut']['label'],$_SERVER["PHP_SELF"],"e.fk_statut","",$param,'align="right"',$sortfield,$sortorder);
460
-	if (! empty($arrayfields['e.billed']['checked'])) print_liste_field_titre($arrayfields['e.billed']['label'],$_SERVER["PHP_SELF"],"e.billed","",$param,'align="center"',$sortfield,$sortorder);
461
-	print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
462
-	print "</tr>\n";
463
-
464
-	$i=0;
465
-	$totalarray=array();
466
-	while ($i < min($num,$limit))
467
-	{
468
-		$obj = $db->fetch_object($resql);
469
-
470
-		$shipment->id=$obj->rowid;
471
-		$shipment->ref=$obj->ref;
472
-
473
-		$companystatic->id=$obj->socid;
474
-		$companystatic->ref=$obj->name;
475
-		$companystatic->name=$obj->name;
476
-
477
-
478
-		print '<tr class="oddeven">';
479
-
480
-		// Ref
481
-		if (! empty($arrayfields['e.ref']['checked']))
482
-		{
483
-			print "<td>";
484
-			print $shipment->getNomUrl(1);
485
-			print "</td>\n";
486
-			if (! $i) $totalarray['nbfield']++;
487
-		}
488
-
489
-		// Ref customer
490
-		if (! empty($arrayfields['e.ref_customer']['checked']))
491
-		{
492
-			print "<td>";
493
-			print $obj->ref_customer;
494
-			print "</td>\n";
495
-			if (! $i) $totalarray['nbfield']++;
496
-		}
497
-
498
-		// Third party
499
-		if (! empty($arrayfields['s.nom']['checked']))
500
-		{
501
-			print '<td>';
502
-			print $companystatic->getNomUrl(1);
503
-			print '</td>';
504
-			if (! $i) $totalarray['nbfield']++;
505
-		}
506
-		// Town
507
-		if (! empty($arrayfields['s.town']['checked']))
508
-		{
509
-			print '<td class="nocellnopadd">';
510
-			print $obj->town;
511
-			print '</td>';
512
-			if (! $i) $totalarray['nbfield']++;
513
-		}
514
-		// Zip
515
-		if (! empty($arrayfields['s.zip']['checked']))
516
-		{
517
-			print '<td class="nocellnopadd">';
518
-			print $obj->zip;
519
-			print '</td>';
520
-			if (! $i) $totalarray['nbfield']++;
521
-		}
522
-		// State
523
-		if (! empty($arrayfields['state.nom']['checked']))
524
-		{
525
-			print "<td>".$obj->state_name."</td>\n";
526
-			if (! $i) $totalarray['nbfield']++;
527
-		}
528
-		// Country
529
-		if (! empty($arrayfields['country.code_iso']['checked']))
530
-		{
531
-			print '<td align="center">';
532
-			$tmparray=getCountry($obj->fk_pays,'all');
533
-			print $tmparray['label'];
534
-			print '</td>';
535
-			if (! $i) $totalarray['nbfield']++;
536
-		}
537
-		// Type ent
538
-		if (! empty($arrayfields['typent.code']['checked']))
539
-		{
540
-			print '<td align="center">';
541
-			if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
542
-			print $typenArray[$obj->typent_code];
543
-			print '</td>';
544
-			if (! $i) $totalarray['nbfield']++;
545
-		}
546
-
547
-		// Date delivery planed
548
-		if (! empty($arrayfields['e.date_delivery']['checked']))
549
-		{
550
-			print '<td align="center">';
551
-			print dol_print_date($db->jdate($obj->date_livraison),"day");
552
-			/*$now = time();
258
+    $num = $db->num_rows($resql);
259
+
260
+    $expedition = new Expedition($db);
261
+
262
+    $param='';
263
+    if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
264
+    if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
265
+    if ($sall) $param.= "&amp;sall=".urlencode($sall);
266
+    if ($search_ref_exp)  $param.= "&amp;search_ref_exp=".urlencode($search_ref_exp);
267
+    if ($search_ref_liv)  $param.= "&amp;search_ref_liv=".urlencode($search_ref_liv);
268
+    if ($search_ref_customer) $param.= "&amp;search_ref_customer=".urlencode($search_ref_customer);
269
+    if ($search_company)   $param.= "&amp;search_company=".urlencode($search_company);
270
+    if ($search_town)      $param.= '&search_town='.urlencode($search_town);
271
+    if ($search_zip)       $param.= '&search_zip='.urlencode($search_zip);
272
+    if ($viewstatut != '') $param.= '&viewstatut='.urlencode($viewstatut);
273
+    if ($optioncss != '')  $param.='&amp;optioncss='.urlencode($optioncss);
274
+    // Add $param from extra fields
275
+    include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
276
+
277
+    //$massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
278
+
279
+    $newcardbutton='';
280
+    if ($user->rights->expedition->creer)
281
+    {
282
+        $newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/expedition/card.php?action=create2"><span class="valignmiddle">'.$langs->trans('NewSending').'</span>';
283
+        $newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
284
+        $newcardbutton.= '</a>';
285
+    }
286
+
287
+    $i = 0;
288
+    print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
289
+    if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
290
+    print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
291
+    print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
292
+    print '<input type="hidden" name="action" value="list">';
293
+    print '<input type="hidden" name="page" value="'.$page.'">';
294
+    print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
295
+    print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
296
+
297
+    print_barre_liste($langs->trans('ListOfSendings'), $page, $_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num, $nbtotalofrecords, '', 0, $newcardbutton, '', $limit);
298
+
299
+    if ($sall)
300
+    {
301
+        foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
302
+        print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall).'</div>';
303
+    }
304
+
305
+    $moreforfilter='';
306
+    if (! empty($moreforfilter))
307
+    {
308
+        print '<div class="liste_titre liste_titre_bydiv centpercent">';
309
+        print $moreforfilter;
310
+        $parameters=array('type'=>$type);
311
+        $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters);    // Note that $action and $object may have been modified by hook
312
+        print $hookmanager->resPrint;
313
+        print '</div>';
314
+    }
315
+
316
+    $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
317
+    $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage);	// This also change content of $arrayfields
318
+
319
+    print '<div class="div-table-responsive">';
320
+    print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
321
+
322
+    // Lignes des champs de filtre
323
+    print '<tr class="liste_titre_filter">';
324
+    // Ref
325
+    if (! empty($arrayfields['e.ref']['checked']))
326
+    {
327
+        print '<td class="liste_titre">';
328
+        print '<input class="flat" size="6" type="text" name="search_ref_exp" value="'.$search_ref_exp.'">';
329
+        print '</td>';
330
+    }
331
+    // Ref customer
332
+    if (! empty($arrayfields['e.ref_customer']['checked']))
333
+    {
334
+        print '<td class="liste_titre">';
335
+        print '<input class="flat" size="6" type="text" name="search_ref_customer" value="'.$search_ref_customer.'">';
336
+        print '</td>';
337
+    }
338
+    // Thirdparty
339
+    if (! empty($arrayfields['s.nom']['checked']))
340
+    {
341
+        print '<td class="liste_titre" align="left">';
342
+        print '<input class="flat" type="text" size="8" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
343
+        print '</td>';
344
+    }
345
+    // Town
346
+    if (! empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
347
+    // Zip
348
+    if (! empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
349
+    // State
350
+    if (! empty($arrayfields['state.nom']['checked']))
351
+    {
352
+        print '<td class="liste_titre">';
353
+        print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
354
+        print '</td>';
355
+    }
356
+    // Country
357
+    if (! empty($arrayfields['country.code_iso']['checked']))
358
+    {
359
+        print '<td class="liste_titre" align="center">';
360
+        print $form->select_country($search_country,'search_country','',0,'maxwidth100');
361
+        print '</td>';
362
+    }
363
+    // Company type
364
+    if (! empty($arrayfields['typent.code']['checked']))
365
+    {
366
+        print '<td class="liste_titre maxwidthonsmartphone" align="center">';
367
+        print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
368
+        print '</td>';
369
+    }
370
+    // Date delivery planned
371
+    if (! empty($arrayfields['e.date_delivery']['checked']))
372
+    {
373
+        print '<td class="liste_titre">&nbsp;</td>';
374
+    }
375
+    if (! empty($arrayfields['l.ref']['checked']))
376
+    {
377
+        // Delivery ref
378
+        print '<td class="liste_titre">';
379
+        print '<input class="flat" size="10" type="text" name="search_ref_liv" value="'.$search_ref_liv.'"';
380
+        print '</td>';
381
+    }
382
+    if (! empty($arrayfields['l.date_delivery']['checked']))
383
+    {
384
+        // Date received
385
+        print '<td class="liste_titre">&nbsp;</td>';
386
+    }
387
+    // Extra fields
388
+    include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
389
+
390
+    // Fields from hook
391
+    $parameters=array('arrayfields'=>$arrayfields);
392
+    $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters);    // Note that $action and $object may have been modified by hook
393
+    print $hookmanager->resPrint;
394
+    // Date creation
395
+    if (! empty($arrayfields['e.datec']['checked']))
396
+    {
397
+        print '<td class="liste_titre">';
398
+        print '</td>';
399
+    }
400
+    // Date modification
401
+    if (! empty($arrayfields['e.tms']['checked']))
402
+    {
403
+        print '<td class="liste_titre">';
404
+        print '</td>';
405
+    }
406
+    // Status
407
+    if (! empty($arrayfields['e.fk_statut']['checked']))
408
+    {
409
+        print '<td class="liste_titre maxwidthonsmartphone" align="right">';
410
+        print $form->selectarray('viewstatut', array('0'=>$langs->trans('StatusSendingDraftShort'),'1'=>$langs->trans('StatusSendingValidatedShort'),'2'=>$langs->trans('StatusSendingProcessedShort')),$viewstatut,1);
411
+        print '</td>';
412
+    }
413
+    // Status billed
414
+    if (! empty($arrayfields['e.billed']['checked']))
415
+    {
416
+        print '<td class="liste_titre maxwidthonsmartphone" align="center">';
417
+        print $form->selectyesno('search_billed', $search_billed, 1, 0, 1);
418
+        print '</td>';
419
+    }
420
+    // Action column
421
+    print '<td class="liste_titre" align="middle">';
422
+    $searchpicto=$form->showFilterAndCheckAddButtons(0);
423
+    print $searchpicto;
424
+    print '</td>';
425
+    print "</tr>\n";
426
+
427
+    print '<tr class="liste_titre">';
428
+    if (! empty($arrayfields['e.ref']['checked']))            print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"],"e.ref","",$param,'',$sortfield,$sortorder);
429
+    if (! empty($arrayfields['e.ref_customer']['checked']))   print_liste_field_titre($arrayfields['e.ref_customer']['label'], $_SERVER["PHP_SELF"],"e.ref_customer","",$param,'',$sortfield,$sortorder);
430
+    if (! empty($arrayfields['s.nom']['checked']))            print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"],"s.nom", "", $param,'align="left"',$sortfield,$sortorder);
431
+    if (! empty($arrayfields['s.town']['checked']))           print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
432
+    if (! empty($arrayfields['s.zip']['checked']))            print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
433
+    if (! empty($arrayfields['state.nom']['checked']))        print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
434
+    if (! empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'],$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder);
435
+    if (! empty($arrayfields['typent.code']['checked']))      print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
436
+    if (! empty($arrayfields['e.date_delivery']['checked']))  print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"],"e.date_delivery","",$param, 'align="center"',$sortfield,$sortorder);
437
+    if (! empty($arrayfields['l.ref']['checked']))            print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"],"l.ref","",$param, '',$sortfield,$sortorder);
438
+    if (! empty($arrayfields['l.date_delivery']['checked']))  print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"],"l.date_delivery","",$param, 'align="center"',$sortfield,$sortorder);
439
+    // Extra fields
440
+    if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
441
+    {
442
+        foreach($extrafields->attribute_label as $key => $val)
443
+        {
444
+            if (! empty($arrayfields["ef.".$key]['checked']))
445
+            {
446
+                $align=$extrafields->getAlignFlag($key);
447
+                $sortonfield = "ef.".$key;
448
+                if (! empty($extrafields->attribute_computed[$key])) $sortonfield='';
449
+                print_liste_field_titre($extralabels[$key],$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
450
+            }
451
+        }
452
+    }
453
+    // Hook fields
454
+    $parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder);
455
+    $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters);    // Note that $action and $object may have been modified by hook
456
+    print $hookmanager->resPrint;
457
+    if (! empty($arrayfields['e.datec']['checked']))  print_liste_field_titre($arrayfields['e.datec']['label'],$_SERVER["PHP_SELF"],"e.date_creation","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
458
+    if (! empty($arrayfields['e.tms']['checked']))    print_liste_field_titre($arrayfields['e.tms']['label'],$_SERVER["PHP_SELF"],"e.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
459
+    if (! empty($arrayfields['e.fk_statut']['checked'])) print_liste_field_titre($arrayfields['e.fk_statut']['label'],$_SERVER["PHP_SELF"],"e.fk_statut","",$param,'align="right"',$sortfield,$sortorder);
460
+    if (! empty($arrayfields['e.billed']['checked'])) print_liste_field_titre($arrayfields['e.billed']['label'],$_SERVER["PHP_SELF"],"e.billed","",$param,'align="center"',$sortfield,$sortorder);
461
+    print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
462
+    print "</tr>\n";
463
+
464
+    $i=0;
465
+    $totalarray=array();
466
+    while ($i < min($num,$limit))
467
+    {
468
+        $obj = $db->fetch_object($resql);
469
+
470
+        $shipment->id=$obj->rowid;
471
+        $shipment->ref=$obj->ref;
472
+
473
+        $companystatic->id=$obj->socid;
474
+        $companystatic->ref=$obj->name;
475
+        $companystatic->name=$obj->name;
476
+
477
+
478
+        print '<tr class="oddeven">';
479
+
480
+        // Ref
481
+        if (! empty($arrayfields['e.ref']['checked']))
482
+        {
483
+            print "<td>";
484
+            print $shipment->getNomUrl(1);
485
+            print "</td>\n";
486
+            if (! $i) $totalarray['nbfield']++;
487
+        }
488
+
489
+        // Ref customer
490
+        if (! empty($arrayfields['e.ref_customer']['checked']))
491
+        {
492
+            print "<td>";
493
+            print $obj->ref_customer;
494
+            print "</td>\n";
495
+            if (! $i) $totalarray['nbfield']++;
496
+        }
497
+
498
+        // Third party
499
+        if (! empty($arrayfields['s.nom']['checked']))
500
+        {
501
+            print '<td>';
502
+            print $companystatic->getNomUrl(1);
503
+            print '</td>';
504
+            if (! $i) $totalarray['nbfield']++;
505
+        }
506
+        // Town
507
+        if (! empty($arrayfields['s.town']['checked']))
508
+        {
509
+            print '<td class="nocellnopadd">';
510
+            print $obj->town;
511
+            print '</td>';
512
+            if (! $i) $totalarray['nbfield']++;
513
+        }
514
+        // Zip
515
+        if (! empty($arrayfields['s.zip']['checked']))
516
+        {
517
+            print '<td class="nocellnopadd">';
518
+            print $obj->zip;
519
+            print '</td>';
520
+            if (! $i) $totalarray['nbfield']++;
521
+        }
522
+        // State
523
+        if (! empty($arrayfields['state.nom']['checked']))
524
+        {
525
+            print "<td>".$obj->state_name."</td>\n";
526
+            if (! $i) $totalarray['nbfield']++;
527
+        }
528
+        // Country
529
+        if (! empty($arrayfields['country.code_iso']['checked']))
530
+        {
531
+            print '<td align="center">';
532
+            $tmparray=getCountry($obj->fk_pays,'all');
533
+            print $tmparray['label'];
534
+            print '</td>';
535
+            if (! $i) $totalarray['nbfield']++;
536
+        }
537
+        // Type ent
538
+        if (! empty($arrayfields['typent.code']['checked']))
539
+        {
540
+            print '<td align="center">';
541
+            if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
542
+            print $typenArray[$obj->typent_code];
543
+            print '</td>';
544
+            if (! $i) $totalarray['nbfield']++;
545
+        }
546
+
547
+        // Date delivery planed
548
+        if (! empty($arrayfields['e.date_delivery']['checked']))
549
+        {
550
+            print '<td align="center">';
551
+            print dol_print_date($db->jdate($obj->date_livraison),"day");
552
+            /*$now = time();
553 553
     		if ( ($now - $db->jdate($obj->date_expedition)) > $conf->warnings->lim && $obj->statutid == 1 )
554 554
     		{
555 555
     		}*/
556
-			print "</td>\n";
557
-		}
558
-
559
-		if (! empty($arrayfields['l.ref']['checked']) || ! empty($arrayfields['l.date_delivery']['checked']))
560
-		{
561
-			$shipment->fetchObjectLinked($shipment->id,$shipment->element);
562
-			$receiving='';
563
-			if (is_array($shipment->linkedObjects['delivery']) && count($shipment->linkedObjects['delivery']) > 0) $receiving=reset($shipment->linkedObjects['delivery']);
564
-
565
-			if (! empty($arrayfields['l.ref']['checked']))
566
-			{
567
-				// Ref
568
-				print '<td>';
569
-				print !empty($receiving) ? $receiving->getNomUrl($db) : '';
570
-				print '</td>';
571
-			}
572
-
573
-			if (! empty($arrayfields['l.date_delivery']['checked']))
574
-			{
575
-				// Date received
576
-				print '<td align="center">';
577
-				print dol_print_date($db->jdate($obj->date_reception),"day");
578
-				print '</td>'."\n";
579
-			}
580
-		}
581
-
582
-		// Extra fields
583
-		include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
584
-		// Fields from hook
585
-		$parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
586
-		$reshook=$hookmanager->executeHooks('printFieldListValue',$parameters);    // Note that $action and $object may have been modified by hook
587
-		print $hookmanager->resPrint;
588
-		// Date creation
589
-		if (! empty($arrayfields['e.datec']['checked']))
590
-		{
591
-			print '<td align="center" class="nowrap">';
592
-			print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
593
-			print '</td>';
594
-			if (! $i) $totalarray['nbfield']++;
595
-		}
596
-		// Date modification
597
-		if (! empty($arrayfields['e.tms']['checked']))
598
-		{
599
-			print '<td align="center" class="nowrap">';
600
-			print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
601
-			print '</td>';
602
-			if (! $i) $totalarray['nbfield']++;
603
-		}
604
-		// Status
605
-		if (! empty($arrayfields['e.fk_statut']['checked']))
606
-		{
607
-			print '<td align="right" class="nowrap">'.$shipment->LibStatut($obj->fk_statut,5).'</td>';
608
-			if (! $i) $totalarray['nbfield']++;
609
-		}
610
-		// Billed
611
-		if (! empty($arrayfields['e.billed']['checked']))
612
-		{
613
-			print '<td align="center">'.yn($obj->billed).'</td>';
614
-			if (! $i) $totalarray['nbfield']++;
615
-		}
616
-
617
-		// Action column
618
-		print '<td></td>';
619
-		if (! $i) $totalarray['nbfield']++;
620
-
621
-		print "</tr>\n";
622
-
623
-		$i++;
624
-	}
625
-
626
-	print "</table>";
627
-	print "</div>";
628
-	print '</form>';
629
-	$db->free($resql);
556
+            print "</td>\n";
557
+        }
558
+
559
+        if (! empty($arrayfields['l.ref']['checked']) || ! empty($arrayfields['l.date_delivery']['checked']))
560
+        {
561
+            $shipment->fetchObjectLinked($shipment->id,$shipment->element);
562
+            $receiving='';
563
+            if (is_array($shipment->linkedObjects['delivery']) && count($shipment->linkedObjects['delivery']) > 0) $receiving=reset($shipment->linkedObjects['delivery']);
564
+
565
+            if (! empty($arrayfields['l.ref']['checked']))
566
+            {
567
+                // Ref
568
+                print '<td>';
569
+                print !empty($receiving) ? $receiving->getNomUrl($db) : '';
570
+                print '</td>';
571
+            }
572
+
573
+            if (! empty($arrayfields['l.date_delivery']['checked']))
574
+            {
575
+                // Date received
576
+                print '<td align="center">';
577
+                print dol_print_date($db->jdate($obj->date_reception),"day");
578
+                print '</td>'."\n";
579
+            }
580
+        }
581
+
582
+        // Extra fields
583
+        include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
584
+        // Fields from hook
585
+        $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
586
+        $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters);    // Note that $action and $object may have been modified by hook
587
+        print $hookmanager->resPrint;
588
+        // Date creation
589
+        if (! empty($arrayfields['e.datec']['checked']))
590
+        {
591
+            print '<td align="center" class="nowrap">';
592
+            print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
593
+            print '</td>';
594
+            if (! $i) $totalarray['nbfield']++;
595
+        }
596
+        // Date modification
597
+        if (! empty($arrayfields['e.tms']['checked']))
598
+        {
599
+            print '<td align="center" class="nowrap">';
600
+            print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
601
+            print '</td>';
602
+            if (! $i) $totalarray['nbfield']++;
603
+        }
604
+        // Status
605
+        if (! empty($arrayfields['e.fk_statut']['checked']))
606
+        {
607
+            print '<td align="right" class="nowrap">'.$shipment->LibStatut($obj->fk_statut,5).'</td>';
608
+            if (! $i) $totalarray['nbfield']++;
609
+        }
610
+        // Billed
611
+        if (! empty($arrayfields['e.billed']['checked']))
612
+        {
613
+            print '<td align="center">'.yn($obj->billed).'</td>';
614
+            if (! $i) $totalarray['nbfield']++;
615
+        }
616
+
617
+        // Action column
618
+        print '<td></td>';
619
+        if (! $i) $totalarray['nbfield']++;
620
+
621
+        print "</tr>\n";
622
+
623
+        $i++;
624
+    }
625
+
626
+    print "</table>";
627
+    print "</div>";
628
+    print '</form>';
629
+    $db->free($resql);
630 630
 }
631 631
 else
632 632
 {
633
-	dol_print_error($db);
633
+    dol_print_error($db);
634 634
 }
635 635
 
636 636
 // End of page
Please login to merge, or discard this patch.
Spacing   +210 added lines, -210 removed lines patch added patch discarded remove patch
@@ -31,43 +31,43 @@  discard block
 block discarded – undo
31 31
 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
32 32
 
33 33
 // Load translation files required by the page
34
-$langs->loadLangs(array("sendings","deliveries",'companies','bills'));
34
+$langs->loadLangs(array("sendings", "deliveries", 'companies', 'bills'));
35 35
 
36
-$contextpage= GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'shipmentlist';   // To manage different context of search
36
+$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'shipmentlist'; // To manage different context of search
37 37
 
38
-$socid=GETPOST('socid','int');
38
+$socid = GETPOST('socid', 'int');
39 39
 // Security check
40
-$expeditionid = GETPOST('id','int');
41
-if ($user->societe_id) $socid=$user->societe_id;
42
-$result = restrictedArea($user, 'expedition',$expeditionid,'');
40
+$expeditionid = GETPOST('id', 'int');
41
+if ($user->societe_id) $socid = $user->societe_id;
42
+$result = restrictedArea($user, 'expedition', $expeditionid, '');
43 43
 
44
-$diroutputmassaction=$conf->expedition->dir_output . '/temp/massgeneration/'.$user->id;
44
+$diroutputmassaction = $conf->expedition->dir_output.'/temp/massgeneration/'.$user->id;
45 45
 
46 46
 $search_ref_exp = GETPOST("search_ref_exp", 'alpha');
47 47
 $search_ref_liv = GETPOST('search_ref_liv', 'alpha');
48 48
 $search_ref_customer = GETPOST('search_ref_customer', 'alpha');
49 49
 $search_company = GETPOST("search_company", 'alpha');
50
-$search_town=GETPOST('search_town','alpha');
51
-$search_zip=GETPOST('search_zip','alpha');
52
-$search_state=trim(GETPOST("search_state"));
53
-$search_country=GETPOST("search_country",'int');
54
-$search_type_thirdparty=GETPOST("search_type_thirdparty",'int');
55
-$search_billed=GETPOST("search_billed",'int');
56
-$sall = trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml'));
57
-$optioncss = GETPOST('optioncss','alpha');
58
-
59
-$limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
60
-$sortfield = GETPOST('sortfield','alpha');
61
-$sortorder = GETPOST('sortorder','alpha');
62
-$page = GETPOST('page','int');
63
-if (! $sortfield) $sortfield="e.ref";
64
-if (! $sortorder) $sortorder="DESC";
50
+$search_town = GETPOST('search_town', 'alpha');
51
+$search_zip = GETPOST('search_zip', 'alpha');
52
+$search_state = trim(GETPOST("search_state"));
53
+$search_country = GETPOST("search_country", 'int');
54
+$search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
55
+$search_billed = GETPOST("search_billed", 'int');
56
+$sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
57
+$optioncss = GETPOST('optioncss', 'alpha');
58
+
59
+$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
60
+$sortfield = GETPOST('sortfield', 'alpha');
61
+$sortorder = GETPOST('sortorder', 'alpha');
62
+$page = GETPOST('page', 'int');
63
+if (!$sortfield) $sortfield = "e.ref";
64
+if (!$sortorder) $sortorder = "DESC";
65 65
 if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
66 66
 $offset = $limit * $page;
67 67
 $pageprev = $page - 1;
68 68
 $pagenext = $page + 1;
69 69
 
70
-$viewstatut=GETPOST('viewstatut');
70
+$viewstatut = GETPOST('viewstatut');
71 71
 
72 72
 $object = new Expedition($db);
73 73
 
@@ -77,7 +77,7 @@  discard block
 block discarded – undo
77 77
 
78 78
 // fetch optionals attributes and labels
79 79
 $extralabels = $extrafields->fetch_name_optionals_label('expedition');
80
-$search_array_options=$extrafields->getOptionalsFromPost($object->table_element,'','search_');
80
+$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
81 81
 
82 82
 // List of fields to search into when doing a "search in all"
83 83
 $fieldstosearchall = array(
@@ -85,10 +85,10 @@  discard block
 block discarded – undo
85 85
 	's.nom'=>"ThirdParty",
86 86
 	'e.note_public'=>'NotePublic',
87 87
 );
88
-if (empty($user->socid)) $fieldstosearchall["e.note_private"]="NotePrivate";
88
+if (empty($user->socid)) $fieldstosearchall["e.note_private"] = "NotePrivate";
89 89
 
90
-$checkedtypetiers=0;
91
-$arrayfields=array(
90
+$checkedtypetiers = 0;
91
+$arrayfields = array(
92 92
 	'e.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
93 93
 	'e.ref_customer'=>array('label'=>$langs->trans("RefCustomer"), 'checked'=>1),
94 94
 	's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
@@ -101,17 +101,17 @@  discard block
 block discarded – undo
101 101
 	'e.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
102 102
 	'e.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
103 103
 	'e.fk_statut'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
104
-	'l.ref'=>array('label'=>$langs->trans("DeliveryRef"), 'checked'=>1, 'enabled'=>(empty($conf->livraison_bon->enabled)?0:1)),
105
-	'l.date_delivery'=>array('label'=>$langs->trans("DateReceived"), 'checked'=>1, 'enabled'=>(empty($conf->livraison_bon->enabled)?0:1)),
104
+	'l.ref'=>array('label'=>$langs->trans("DeliveryRef"), 'checked'=>1, 'enabled'=>(empty($conf->livraison_bon->enabled) ? 0 : 1)),
105
+	'l.date_delivery'=>array('label'=>$langs->trans("DateReceived"), 'checked'=>1, 'enabled'=>(empty($conf->livraison_bon->enabled) ? 0 : 1)),
106 106
 	'e.billed'=>array('label'=>$langs->trans("Billed"), 'checked'=>1, 'position'=>1000, 'enabled'=>(!empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)))
107 107
 );
108 108
 
109 109
 // Extra fields
110 110
 if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
111 111
 {
112
-	foreach($extrafields->attribute_label as $key => $val)
112
+	foreach ($extrafields->attribute_label as $key => $val)
113 113
 	{
114
-		if (! empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key])!=3 && $extrafields->attribute_perms[$key]));
114
+		if (!empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key] = array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key] < 0) ? 0 : 1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key]) != 3 && $extrafields->attribute_perms[$key]));
115 115
 	}
116 116
 }
117 117
 
@@ -120,46 +120,46 @@  discard block
 block discarded – undo
120 120
  * Actions
121 121
  */
122 122
 
123
-if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
124
-if (! GETPOST('confirmmassaction','alpha')) { $massaction=''; }
123
+if (GETPOST('cancel', 'alpha')) { $action = 'list'; $massaction = ''; }
124
+if (!GETPOST('confirmmassaction', 'alpha')) { $massaction = ''; }
125 125
 
126
-$parameters=array('socid'=>$socid);
127
-$reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
126
+$parameters = array('socid'=>$socid);
127
+$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
128 128
 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
129 129
 
130 130
 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
131 131
 
132 132
 // Purge search criteria
133
-if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
133
+if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) // All tests are required to be compatible with all browsers
134 134
 {
135
-	$search_ref_exp='';
136
-	$search_ref_liv='';
137
-	$search_ref_customer='';
138
-	$search_company='';
139
-	$search_town='';
140
-	$search_zip="";
141
-	$search_state="";
142
-	$search_type='';
143
-	$search_country='';
144
-	$search_type_thirdparty='';
145
-	$search_billed='';
146
-	$viewstatut='';
147
-	$search_array_options=array();
135
+	$search_ref_exp = '';
136
+	$search_ref_liv = '';
137
+	$search_ref_customer = '';
138
+	$search_company = '';
139
+	$search_town = '';
140
+	$search_zip = "";
141
+	$search_state = "";
142
+	$search_type = '';
143
+	$search_country = '';
144
+	$search_type_thirdparty = '';
145
+	$search_billed = '';
146
+	$viewstatut = '';
147
+	$search_array_options = array();
148 148
 }
149 149
 
150 150
 if (empty($reshook))
151 151
 {
152 152
 	// Mass actions. Controls on number of lines checked
153
-	$maxformassaction=1000;
154
-	$numtoselect = (is_array($toselect)?count($toselect):0);
155
-	if (! empty($massaction) && $numtoselect < 1)
153
+	$maxformassaction = 1000;
154
+	$numtoselect = (is_array($toselect) ?count($toselect) : 0);
155
+	if (!empty($massaction) && $numtoselect < 1)
156 156
 	{
157 157
 		$error++;
158 158
 		setEventMessages($langs->trans("NoLineChecked"), null, "warnings");
159 159
 	}
160
-	if (! $error && $numtoselect > $maxformassaction)
160
+	if (!$error && $numtoselect > $maxformassaction)
161 161
 	{
162
-		setEventMessages($langs->trans('TooManyRecordForMassAction',$maxformassaction), null, 'errors');
162
+		setEventMessages($langs->trans('TooManyRecordForMassAction', $maxformassaction), null, 'errors');
163 163
 		$error++;
164 164
 	}
165 165
 }
@@ -171,55 +171,55 @@  discard block
 block discarded – undo
171 171
  * View
172 172
  */
173 173
 
174
-$form=new Form($db);
175
-$companystatic=new Societe($db);
176
-$shipment=new Expedition($db);
177
-$formcompany=new FormCompany($db);
174
+$form = new Form($db);
175
+$companystatic = new Societe($db);
176
+$shipment = new Expedition($db);
177
+$formcompany = new FormCompany($db);
178 178
 
179
-$helpurl='EN:Module_Shipments|FR:Module_Exp&eacute;ditions|ES:M&oacute;dulo_Expediciones';
180
-llxHeader('',$langs->trans('ListOfSendings'),$helpurl);
179
+$helpurl = 'EN:Module_Shipments|FR:Module_Exp&eacute;ditions|ES:M&oacute;dulo_Expediciones';
180
+llxHeader('', $langs->trans('ListOfSendings'), $helpurl);
181 181
 
182 182
 $sql = "SELECT e.rowid, e.ref, e.ref_customer, e.date_expedition as date_expedition, e.date_delivery as date_livraison, l.date_delivery as date_reception, e.fk_statut, e.billed,";
183
-$sql.= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, ';
184
-$sql.= " typent.code as typent_code,";
185
-$sql.= " state.code_departement as state_code, state.nom as state_name,";
186
-$sql.= ' e.date_creation as date_creation, e.tms as date_update';
183
+$sql .= ' s.rowid as socid, s.nom as name, s.town, s.zip, s.fk_pays, s.client, s.code_client, ';
184
+$sql .= " typent.code as typent_code,";
185
+$sql .= " state.code_departement as state_code, state.nom as state_name,";
186
+$sql .= ' e.date_creation as date_creation, e.tms as date_update';
187 187
 // Add fields from extrafields
188
-foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
188
+foreach ($extrafields->attribute_label as $key => $val) $sql .= ($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
189 189
 // Add fields from hooks
190
-$parameters=array();
191
-$reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters);    // Note that $action and $object may have been modified by hook
192
-$sql.=$hookmanager->resPrint;
193
-$sql.= " FROM ".MAIN_DB_PREFIX."expedition as e";
194
-if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expedition_extrafields as ef on (e.rowid = ef.fk_object)";
195
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
196
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
197
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
198
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
199
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'shipping' AND ee.targettype = 'delivery'";
200
-$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.rowid = ee.fk_target";
190
+$parameters = array();
191
+$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
192
+$sql .= $hookmanager->resPrint;
193
+$sql .= " FROM ".MAIN_DB_PREFIX."expedition as e";
194
+if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."expedition_extrafields as ef on (e.rowid = ef.fk_object)";
195
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
196
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
197
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
198
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
199
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'shipping' AND ee.targettype = 'delivery'";
200
+$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.rowid = ee.fk_target";
201 201
 if (!$user->rights->societe->client->voir && !$socid)	// Internal user with no permission to see all
202 202
 {
203
-	$sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
203
+	$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
204 204
 }
205
-$sql.= " WHERE e.entity IN (".getEntity('expedition').")";
205
+$sql .= " WHERE e.entity IN (".getEntity('expedition').")";
206 206
 if (!$user->rights->societe->client->voir && !$socid)	// Internal user with no permission to see all
207 207
 {
208
-	$sql.= " AND e.fk_soc = sc.fk_soc";
209
-	$sql.= " AND sc.fk_user = " .$user->id;
208
+	$sql .= " AND e.fk_soc = sc.fk_soc";
209
+	$sql .= " AND sc.fk_user = ".$user->id;
210 210
 }
211 211
 if ($socid)
212 212
 {
213
-	$sql.= " AND e.fk_soc = ".$socid;
213
+	$sql .= " AND e.fk_soc = ".$socid;
214 214
 }
215 215
 if ($viewstatut <> '' && $viewstatut >= 0) {
216
-	$sql.= " AND e.fk_statut = ".$viewstatut;
216
+	$sql .= " AND e.fk_statut = ".$viewstatut;
217 217
 }
218
-if ($search_ref_customer != '') $sql.=natural_search('e.ref_customer', $search_ref_customer);
219
-if ($search_billed != '' && $search_billed >= 0) $sql.=' AND e.billed = '.$search_billed;
220
-if ($search_town)  $sql.= natural_search('s.town', $search_town);
221
-if ($search_zip)   $sql.= natural_search("s.zip",$search_zip);
222
-if ($search_state) $sql.= natural_search("state.nom",$search_state);
218
+if ($search_ref_customer != '') $sql .= natural_search('e.ref_customer', $search_ref_customer);
219
+if ($search_billed != '' && $search_billed >= 0) $sql .= ' AND e.billed = '.$search_billed;
220
+if ($search_town)  $sql .= natural_search('s.town', $search_town);
221
+if ($search_zip)   $sql .= natural_search("s.zip", $search_zip);
222
+if ($search_state) $sql .= natural_search("state.nom", $search_state);
223 223
 if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')';
224 224
 if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')';
225 225
 if ($search_ref_exp) $sql .= natural_search('e.ref', $search_ref_exp);
@@ -231,11 +231,11 @@  discard block
 block discarded – undo
231 231
 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
232 232
 
233 233
 // Add where from hooks
234
-$parameters=array();
235
-$reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters);    // Note that $action and $object may have been modified by hook
236
-$sql.=$hookmanager->resPrint;
234
+$parameters = array();
235
+$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
236
+$sql .= $hookmanager->resPrint;
237 237
 
238
-$sql.= $db->order($sortfield,$sortorder);
238
+$sql .= $db->order($sortfield, $sortorder);
239 239
 
240 240
 $nbtotalofrecords = '';
241 241
 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
@@ -249,39 +249,39 @@  discard block
 block discarded – undo
249 249
 	}
250 250
 }
251 251
 
252
-$sql.= $db->plimit($limit + 1,$offset);
252
+$sql .= $db->plimit($limit + 1, $offset);
253 253
 
254 254
 //print $sql;
255
-$resql=$db->query($sql);
255
+$resql = $db->query($sql);
256 256
 if ($resql)
257 257
 {
258 258
 	$num = $db->num_rows($resql);
259 259
 
260 260
 	$expedition = new Expedition($db);
261 261
 
262
-	$param='';
263
-	if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
264
-	if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
265
-	if ($sall) $param.= "&amp;sall=".urlencode($sall);
266
-	if ($search_ref_exp)  $param.= "&amp;search_ref_exp=".urlencode($search_ref_exp);
267
-	if ($search_ref_liv)  $param.= "&amp;search_ref_liv=".urlencode($search_ref_liv);
268
-	if ($search_ref_customer) $param.= "&amp;search_ref_customer=".urlencode($search_ref_customer);
269
-	if ($search_company)   $param.= "&amp;search_company=".urlencode($search_company);
270
-	if ($search_town)      $param.= '&search_town='.urlencode($search_town);
271
-	if ($search_zip)       $param.= '&search_zip='.urlencode($search_zip);
272
-	if ($viewstatut != '') $param.= '&viewstatut='.urlencode($viewstatut);
273
-	if ($optioncss != '')  $param.='&amp;optioncss='.urlencode($optioncss);
262
+	$param = '';
263
+	if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param .= '&contextpage='.urlencode($contextpage);
264
+	if ($limit > 0 && $limit != $conf->liste_limit) $param .= '&limit='.urlencode($limit);
265
+	if ($sall) $param .= "&amp;sall=".urlencode($sall);
266
+	if ($search_ref_exp)  $param .= "&amp;search_ref_exp=".urlencode($search_ref_exp);
267
+	if ($search_ref_liv)  $param .= "&amp;search_ref_liv=".urlencode($search_ref_liv);
268
+	if ($search_ref_customer) $param .= "&amp;search_ref_customer=".urlencode($search_ref_customer);
269
+	if ($search_company)   $param .= "&amp;search_company=".urlencode($search_company);
270
+	if ($search_town)      $param .= '&search_town='.urlencode($search_town);
271
+	if ($search_zip)       $param .= '&search_zip='.urlencode($search_zip);
272
+	if ($viewstatut != '') $param .= '&viewstatut='.urlencode($viewstatut);
273
+	if ($optioncss != '')  $param .= '&amp;optioncss='.urlencode($optioncss);
274 274
 	// Add $param from extra fields
275 275
 	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
276 276
 
277 277
 	//$massactionbutton=$form->selectMassAction('', $massaction == 'presend' ? array() : array('presend'=>$langs->trans("SendByMail"), 'builddoc'=>$langs->trans("PDFMerge")));
278 278
 
279
-	$newcardbutton='';
279
+	$newcardbutton = '';
280 280
 	if ($user->rights->expedition->creer)
281 281
 	{
282
-		$newcardbutton='<a class="butActionNew" href="'.DOL_URL_ROOT.'/expedition/card.php?action=create2"><span class="valignmiddle">'.$langs->trans('NewSending').'</span>';
283
-		$newcardbutton.= '<span class="fa fa-plus-circle valignmiddle"></span>';
284
-		$newcardbutton.= '</a>';
282
+		$newcardbutton = '<a class="butActionNew" href="'.DOL_URL_ROOT.'/expedition/card.php?action=create2"><span class="valignmiddle">'.$langs->trans('NewSending').'</span>';
283
+		$newcardbutton .= '<span class="fa fa-plus-circle valignmiddle"></span>';
284
+		$newcardbutton .= '</a>';
285 285
 	}
286 286
 
287 287
 	$i = 0;
@@ -294,92 +294,92 @@  discard block
 block discarded – undo
294 294
 	print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
295 295
 	print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
296 296
 
297
-	print_barre_liste($langs->trans('ListOfSendings'), $page, $_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num, $nbtotalofrecords, '', 0, $newcardbutton, '', $limit);
297
+	print_barre_liste($langs->trans('ListOfSendings'), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, $newcardbutton, '', $limit);
298 298
 
299 299
 	if ($sall)
300 300
 	{
301
-		foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
302
-		print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall).'</div>';
301
+		foreach ($fieldstosearchall as $key => $val) $fieldstosearchall[$key] = $langs->trans($val);
302
+		print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
303 303
 	}
304 304
 
305
-	$moreforfilter='';
306
-	if (! empty($moreforfilter))
305
+	$moreforfilter = '';
306
+	if (!empty($moreforfilter))
307 307
 	{
308 308
 		print '<div class="liste_titre liste_titre_bydiv centpercent">';
309 309
 		print $moreforfilter;
310
-		$parameters=array('type'=>$type);
311
-		$reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters);    // Note that $action and $object may have been modified by hook
310
+		$parameters = array('type'=>$type);
311
+		$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
312 312
 		print $hookmanager->resPrint;
313 313
 		print '</div>';
314 314
 	}
315 315
 
316
-	$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
317
-	$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage);	// This also change content of $arrayfields
316
+	$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
317
+	$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
318 318
 
319 319
 	print '<div class="div-table-responsive">';
320
-	print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
320
+	print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
321 321
 
322 322
 	// Lignes des champs de filtre
323 323
 	print '<tr class="liste_titre_filter">';
324 324
 	// Ref
325
-	if (! empty($arrayfields['e.ref']['checked']))
325
+	if (!empty($arrayfields['e.ref']['checked']))
326 326
 	{
327 327
 		print '<td class="liste_titre">';
328 328
 		print '<input class="flat" size="6" type="text" name="search_ref_exp" value="'.$search_ref_exp.'">';
329 329
 		print '</td>';
330 330
 	}
331 331
 	// Ref customer
332
-	if (! empty($arrayfields['e.ref_customer']['checked']))
332
+	if (!empty($arrayfields['e.ref_customer']['checked']))
333 333
 	{
334 334
 		print '<td class="liste_titre">';
335 335
 		print '<input class="flat" size="6" type="text" name="search_ref_customer" value="'.$search_ref_customer.'">';
336 336
 		print '</td>';
337 337
 	}
338 338
 	// Thirdparty
339
-	if (! empty($arrayfields['s.nom']['checked']))
339
+	if (!empty($arrayfields['s.nom']['checked']))
340 340
 	{
341 341
 		print '<td class="liste_titre" align="left">';
342 342
 		print '<input class="flat" type="text" size="8" name="search_company" value="'.dol_escape_htmltag($search_company).'">';
343 343
 		print '</td>';
344 344
 	}
345 345
 	// Town
346
-	if (! empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
346
+	if (!empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
347 347
 	// Zip
348
-	if (! empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
348
+	if (!empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
349 349
 	// State
350
-	if (! empty($arrayfields['state.nom']['checked']))
350
+	if (!empty($arrayfields['state.nom']['checked']))
351 351
 	{
352 352
 		print '<td class="liste_titre">';
353 353
 		print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
354 354
 		print '</td>';
355 355
 	}
356 356
 	// Country
357
-	if (! empty($arrayfields['country.code_iso']['checked']))
357
+	if (!empty($arrayfields['country.code_iso']['checked']))
358 358
 	{
359 359
 		print '<td class="liste_titre" align="center">';
360
-		print $form->select_country($search_country,'search_country','',0,'maxwidth100');
360
+		print $form->select_country($search_country, 'search_country', '', 0, 'maxwidth100');
361 361
 		print '</td>';
362 362
 	}
363 363
 	// Company type
364
-	if (! empty($arrayfields['typent.code']['checked']))
364
+	if (!empty($arrayfields['typent.code']['checked']))
365 365
 	{
366 366
 		print '<td class="liste_titre maxwidthonsmartphone" align="center">';
367
-		print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
367
+		print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT));
368 368
 		print '</td>';
369 369
 	}
370 370
 	// Date delivery planned
371
-	if (! empty($arrayfields['e.date_delivery']['checked']))
371
+	if (!empty($arrayfields['e.date_delivery']['checked']))
372 372
 	{
373 373
 		print '<td class="liste_titre">&nbsp;</td>';
374 374
 	}
375
-	if (! empty($arrayfields['l.ref']['checked']))
375
+	if (!empty($arrayfields['l.ref']['checked']))
376 376
 	{
377 377
 		// Delivery ref
378 378
 		print '<td class="liste_titre">';
379 379
 		print '<input class="flat" size="10" type="text" name="search_ref_liv" value="'.$search_ref_liv.'"';
380 380
 		print '</td>';
381 381
 	}
382
-	if (! empty($arrayfields['l.date_delivery']['checked']))
382
+	if (!empty($arrayfields['l.date_delivery']['checked']))
383 383
 	{
384 384
 		// Date received
385 385
 		print '<td class="liste_titre">&nbsp;</td>';
@@ -388,30 +388,30 @@  discard block
 block discarded – undo
388 388
 	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
389 389
 
390 390
 	// Fields from hook
391
-	$parameters=array('arrayfields'=>$arrayfields);
392
-	$reshook=$hookmanager->executeHooks('printFieldListOption',$parameters);    // Note that $action and $object may have been modified by hook
391
+	$parameters = array('arrayfields'=>$arrayfields);
392
+	$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
393 393
 	print $hookmanager->resPrint;
394 394
 	// Date creation
395
-	if (! empty($arrayfields['e.datec']['checked']))
395
+	if (!empty($arrayfields['e.datec']['checked']))
396 396
 	{
397 397
 		print '<td class="liste_titre">';
398 398
 		print '</td>';
399 399
 	}
400 400
 	// Date modification
401
-	if (! empty($arrayfields['e.tms']['checked']))
401
+	if (!empty($arrayfields['e.tms']['checked']))
402 402
 	{
403 403
 		print '<td class="liste_titre">';
404 404
 		print '</td>';
405 405
 	}
406 406
 	// Status
407
-	if (! empty($arrayfields['e.fk_statut']['checked']))
407
+	if (!empty($arrayfields['e.fk_statut']['checked']))
408 408
 	{
409 409
 		print '<td class="liste_titre maxwidthonsmartphone" align="right">';
410
-		print $form->selectarray('viewstatut', array('0'=>$langs->trans('StatusSendingDraftShort'),'1'=>$langs->trans('StatusSendingValidatedShort'),'2'=>$langs->trans('StatusSendingProcessedShort')),$viewstatut,1);
410
+		print $form->selectarray('viewstatut', array('0'=>$langs->trans('StatusSendingDraftShort'), '1'=>$langs->trans('StatusSendingValidatedShort'), '2'=>$langs->trans('StatusSendingProcessedShort')), $viewstatut, 1);
411 411
 		print '</td>';
412 412
 	}
413 413
 	// Status billed
414
-	if (! empty($arrayfields['e.billed']['checked']))
414
+	if (!empty($arrayfields['e.billed']['checked']))
415 415
 	{
416 416
 		print '<td class="liste_titre maxwidthonsmartphone" align="center">';
417 417
 		print $form->selectyesno('search_billed', $search_billed, 1, 0, 1);
@@ -419,136 +419,136 @@  discard block
 block discarded – undo
419 419
 	}
420 420
 	// Action column
421 421
 	print '<td class="liste_titre" align="middle">';
422
-	$searchpicto=$form->showFilterAndCheckAddButtons(0);
422
+	$searchpicto = $form->showFilterAndCheckAddButtons(0);
423 423
 	print $searchpicto;
424 424
 	print '</td>';
425 425
 	print "</tr>\n";
426 426
 
427 427
 	print '<tr class="liste_titre">';
428
-	if (! empty($arrayfields['e.ref']['checked']))            print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"],"e.ref","",$param,'',$sortfield,$sortorder);
429
-	if (! empty($arrayfields['e.ref_customer']['checked']))   print_liste_field_titre($arrayfields['e.ref_customer']['label'], $_SERVER["PHP_SELF"],"e.ref_customer","",$param,'',$sortfield,$sortorder);
430
-	if (! empty($arrayfields['s.nom']['checked']))            print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"],"s.nom", "", $param,'align="left"',$sortfield,$sortorder);
431
-	if (! empty($arrayfields['s.town']['checked']))           print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
432
-	if (! empty($arrayfields['s.zip']['checked']))            print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
433
-	if (! empty($arrayfields['state.nom']['checked']))        print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
434
-	if (! empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'],$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder);
435
-	if (! empty($arrayfields['typent.code']['checked']))      print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
436
-	if (! empty($arrayfields['e.date_delivery']['checked']))  print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"],"e.date_delivery","",$param, 'align="center"',$sortfield,$sortorder);
437
-	if (! empty($arrayfields['l.ref']['checked']))            print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"],"l.ref","",$param, '',$sortfield,$sortorder);
438
-	if (! empty($arrayfields['l.date_delivery']['checked']))  print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"],"l.date_delivery","",$param, 'align="center"',$sortfield,$sortorder);
428
+	if (!empty($arrayfields['e.ref']['checked']))            print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"], "e.ref", "", $param, '', $sortfield, $sortorder);
429
+	if (!empty($arrayfields['e.ref_customer']['checked']))   print_liste_field_titre($arrayfields['e.ref_customer']['label'], $_SERVER["PHP_SELF"], "e.ref_customer", "", $param, '', $sortfield, $sortorder);
430
+	if (!empty($arrayfields['s.nom']['checked']))            print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, 'align="left"', $sortfield, $sortorder);
431
+	if (!empty($arrayfields['s.town']['checked']))           print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
432
+	if (!empty($arrayfields['s.zip']['checked']))            print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
433
+	if (!empty($arrayfields['state.nom']['checked']))        print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
434
+	if (!empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, 'align="center"', $sortfield, $sortorder);
435
+	if (!empty($arrayfields['typent.code']['checked']))      print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, 'align="center"', $sortfield, $sortorder);
436
+	if (!empty($arrayfields['e.date_delivery']['checked']))  print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"], "e.date_delivery", "", $param, 'align="center"', $sortfield, $sortorder);
437
+	if (!empty($arrayfields['l.ref']['checked']))            print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"], "l.ref", "", $param, '', $sortfield, $sortorder);
438
+	if (!empty($arrayfields['l.date_delivery']['checked']))  print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"], "l.date_delivery", "", $param, 'align="center"', $sortfield, $sortorder);
439 439
 	// Extra fields
440 440
 	if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
441 441
 	{
442
-		foreach($extrafields->attribute_label as $key => $val)
442
+		foreach ($extrafields->attribute_label as $key => $val)
443 443
 		{
444
-			if (! empty($arrayfields["ef.".$key]['checked']))
444
+			if (!empty($arrayfields["ef.".$key]['checked']))
445 445
 			{
446
-				$align=$extrafields->getAlignFlag($key);
446
+				$align = $extrafields->getAlignFlag($key);
447 447
 				$sortonfield = "ef.".$key;
448
-				if (! empty($extrafields->attribute_computed[$key])) $sortonfield='';
449
-				print_liste_field_titre($extralabels[$key],$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
448
+				if (!empty($extrafields->attribute_computed[$key])) $sortonfield = '';
449
+				print_liste_field_titre($extralabels[$key], $_SERVER["PHP_SELF"], $sortonfield, "", $param, ($align ? 'align="'.$align.'"' : ''), $sortfield, $sortorder);
450 450
 			}
451 451
 		}
452 452
 	}
453 453
 	// Hook fields
454
-	$parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder);
455
-	$reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters);    // Note that $action and $object may have been modified by hook
454
+	$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
455
+	$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
456 456
 	print $hookmanager->resPrint;
457
-	if (! empty($arrayfields['e.datec']['checked']))  print_liste_field_titre($arrayfields['e.datec']['label'],$_SERVER["PHP_SELF"],"e.date_creation","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
458
-	if (! empty($arrayfields['e.tms']['checked']))    print_liste_field_titre($arrayfields['e.tms']['label'],$_SERVER["PHP_SELF"],"e.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
459
-	if (! empty($arrayfields['e.fk_statut']['checked'])) print_liste_field_titre($arrayfields['e.fk_statut']['label'],$_SERVER["PHP_SELF"],"e.fk_statut","",$param,'align="right"',$sortfield,$sortorder);
460
-	if (! empty($arrayfields['e.billed']['checked'])) print_liste_field_titre($arrayfields['e.billed']['label'],$_SERVER["PHP_SELF"],"e.billed","",$param,'align="center"',$sortfield,$sortorder);
461
-	print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
457
+	if (!empty($arrayfields['e.datec']['checked']))  print_liste_field_titre($arrayfields['e.datec']['label'], $_SERVER["PHP_SELF"], "e.date_creation", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
458
+	if (!empty($arrayfields['e.tms']['checked']))    print_liste_field_titre($arrayfields['e.tms']['label'], $_SERVER["PHP_SELF"], "e.tms", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
459
+	if (!empty($arrayfields['e.fk_statut']['checked'])) print_liste_field_titre($arrayfields['e.fk_statut']['label'], $_SERVER["PHP_SELF"], "e.fk_statut", "", $param, 'align="right"', $sortfield, $sortorder);
460
+	if (!empty($arrayfields['e.billed']['checked'])) print_liste_field_titre($arrayfields['e.billed']['label'], $_SERVER["PHP_SELF"], "e.billed", "", $param, 'align="center"', $sortfield, $sortorder);
461
+	print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
462 462
 	print "</tr>\n";
463 463
 
464
-	$i=0;
465
-	$totalarray=array();
466
-	while ($i < min($num,$limit))
464
+	$i = 0;
465
+	$totalarray = array();
466
+	while ($i < min($num, $limit))
467 467
 	{
468 468
 		$obj = $db->fetch_object($resql);
469 469
 
470
-		$shipment->id=$obj->rowid;
471
-		$shipment->ref=$obj->ref;
470
+		$shipment->id = $obj->rowid;
471
+		$shipment->ref = $obj->ref;
472 472
 
473
-		$companystatic->id=$obj->socid;
474
-		$companystatic->ref=$obj->name;
475
-		$companystatic->name=$obj->name;
473
+		$companystatic->id = $obj->socid;
474
+		$companystatic->ref = $obj->name;
475
+		$companystatic->name = $obj->name;
476 476
 
477 477
 
478 478
 		print '<tr class="oddeven">';
479 479
 
480 480
 		// Ref
481
-		if (! empty($arrayfields['e.ref']['checked']))
481
+		if (!empty($arrayfields['e.ref']['checked']))
482 482
 		{
483 483
 			print "<td>";
484 484
 			print $shipment->getNomUrl(1);
485 485
 			print "</td>\n";
486
-			if (! $i) $totalarray['nbfield']++;
486
+			if (!$i) $totalarray['nbfield']++;
487 487
 		}
488 488
 
489 489
 		// Ref customer
490
-		if (! empty($arrayfields['e.ref_customer']['checked']))
490
+		if (!empty($arrayfields['e.ref_customer']['checked']))
491 491
 		{
492 492
 			print "<td>";
493 493
 			print $obj->ref_customer;
494 494
 			print "</td>\n";
495
-			if (! $i) $totalarray['nbfield']++;
495
+			if (!$i) $totalarray['nbfield']++;
496 496
 		}
497 497
 
498 498
 		// Third party
499
-		if (! empty($arrayfields['s.nom']['checked']))
499
+		if (!empty($arrayfields['s.nom']['checked']))
500 500
 		{
501 501
 			print '<td>';
502 502
 			print $companystatic->getNomUrl(1);
503 503
 			print '</td>';
504
-			if (! $i) $totalarray['nbfield']++;
504
+			if (!$i) $totalarray['nbfield']++;
505 505
 		}
506 506
 		// Town
507
-		if (! empty($arrayfields['s.town']['checked']))
507
+		if (!empty($arrayfields['s.town']['checked']))
508 508
 		{
509 509
 			print '<td class="nocellnopadd">';
510 510
 			print $obj->town;
511 511
 			print '</td>';
512
-			if (! $i) $totalarray['nbfield']++;
512
+			if (!$i) $totalarray['nbfield']++;
513 513
 		}
514 514
 		// Zip
515
-		if (! empty($arrayfields['s.zip']['checked']))
515
+		if (!empty($arrayfields['s.zip']['checked']))
516 516
 		{
517 517
 			print '<td class="nocellnopadd">';
518 518
 			print $obj->zip;
519 519
 			print '</td>';
520
-			if (! $i) $totalarray['nbfield']++;
520
+			if (!$i) $totalarray['nbfield']++;
521 521
 		}
522 522
 		// State
523
-		if (! empty($arrayfields['state.nom']['checked']))
523
+		if (!empty($arrayfields['state.nom']['checked']))
524 524
 		{
525 525
 			print "<td>".$obj->state_name."</td>\n";
526
-			if (! $i) $totalarray['nbfield']++;
526
+			if (!$i) $totalarray['nbfield']++;
527 527
 		}
528 528
 		// Country
529
-		if (! empty($arrayfields['country.code_iso']['checked']))
529
+		if (!empty($arrayfields['country.code_iso']['checked']))
530 530
 		{
531 531
 			print '<td align="center">';
532
-			$tmparray=getCountry($obj->fk_pays,'all');
532
+			$tmparray = getCountry($obj->fk_pays, 'all');
533 533
 			print $tmparray['label'];
534 534
 			print '</td>';
535
-			if (! $i) $totalarray['nbfield']++;
535
+			if (!$i) $totalarray['nbfield']++;
536 536
 		}
537 537
 		// Type ent
538
-		if (! empty($arrayfields['typent.code']['checked']))
538
+		if (!empty($arrayfields['typent.code']['checked']))
539 539
 		{
540 540
 			print '<td align="center">';
541
-			if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
541
+			if (count($typenArray) == 0) $typenArray = $formcompany->typent_array(1);
542 542
 			print $typenArray[$obj->typent_code];
543 543
 			print '</td>';
544
-			if (! $i) $totalarray['nbfield']++;
544
+			if (!$i) $totalarray['nbfield']++;
545 545
 		}
546 546
 
547 547
 		// Date delivery planed
548
-		if (! empty($arrayfields['e.date_delivery']['checked']))
548
+		if (!empty($arrayfields['e.date_delivery']['checked']))
549 549
 		{
550 550
 			print '<td align="center">';
551
-			print dol_print_date($db->jdate($obj->date_livraison),"day");
551
+			print dol_print_date($db->jdate($obj->date_livraison), "day");
552 552
 			/*$now = time();
553 553
     		if ( ($now - $db->jdate($obj->date_expedition)) > $conf->warnings->lim && $obj->statutid == 1 )
554 554
     		{
@@ -556,13 +556,13 @@  discard block
 block discarded – undo
556 556
 			print "</td>\n";
557 557
 		}
558 558
 
559
-		if (! empty($arrayfields['l.ref']['checked']) || ! empty($arrayfields['l.date_delivery']['checked']))
559
+		if (!empty($arrayfields['l.ref']['checked']) || !empty($arrayfields['l.date_delivery']['checked']))
560 560
 		{
561
-			$shipment->fetchObjectLinked($shipment->id,$shipment->element);
562
-			$receiving='';
563
-			if (is_array($shipment->linkedObjects['delivery']) && count($shipment->linkedObjects['delivery']) > 0) $receiving=reset($shipment->linkedObjects['delivery']);
561
+			$shipment->fetchObjectLinked($shipment->id, $shipment->element);
562
+			$receiving = '';
563
+			if (is_array($shipment->linkedObjects['delivery']) && count($shipment->linkedObjects['delivery']) > 0) $receiving = reset($shipment->linkedObjects['delivery']);
564 564
 
565
-			if (! empty($arrayfields['l.ref']['checked']))
565
+			if (!empty($arrayfields['l.ref']['checked']))
566 566
 			{
567 567
 				// Ref
568 568
 				print '<td>';
@@ -570,11 +570,11 @@  discard block
 block discarded – undo
570 570
 				print '</td>';
571 571
 			}
572 572
 
573
-			if (! empty($arrayfields['l.date_delivery']['checked']))
573
+			if (!empty($arrayfields['l.date_delivery']['checked']))
574 574
 			{
575 575
 				// Date received
576 576
 				print '<td align="center">';
577
-				print dol_print_date($db->jdate($obj->date_reception),"day");
577
+				print dol_print_date($db->jdate($obj->date_reception), "day");
578 578
 				print '</td>'."\n";
579 579
 			}
580 580
 		}
@@ -582,41 +582,41 @@  discard block
 block discarded – undo
582 582
 		// Extra fields
583 583
 		include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
584 584
 		// Fields from hook
585
-		$parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
586
-		$reshook=$hookmanager->executeHooks('printFieldListValue',$parameters);    // Note that $action and $object may have been modified by hook
585
+		$parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj);
586
+		$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
587 587
 		print $hookmanager->resPrint;
588 588
 		// Date creation
589
-		if (! empty($arrayfields['e.datec']['checked']))
589
+		if (!empty($arrayfields['e.datec']['checked']))
590 590
 		{
591 591
 			print '<td align="center" class="nowrap">';
592 592
 			print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
593 593
 			print '</td>';
594
-			if (! $i) $totalarray['nbfield']++;
594
+			if (!$i) $totalarray['nbfield']++;
595 595
 		}
596 596
 		// Date modification
597
-		if (! empty($arrayfields['e.tms']['checked']))
597
+		if (!empty($arrayfields['e.tms']['checked']))
598 598
 		{
599 599
 			print '<td align="center" class="nowrap">';
600 600
 			print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
601 601
 			print '</td>';
602
-			if (! $i) $totalarray['nbfield']++;
602
+			if (!$i) $totalarray['nbfield']++;
603 603
 		}
604 604
 		// Status
605
-		if (! empty($arrayfields['e.fk_statut']['checked']))
605
+		if (!empty($arrayfields['e.fk_statut']['checked']))
606 606
 		{
607
-			print '<td align="right" class="nowrap">'.$shipment->LibStatut($obj->fk_statut,5).'</td>';
608
-			if (! $i) $totalarray['nbfield']++;
607
+			print '<td align="right" class="nowrap">'.$shipment->LibStatut($obj->fk_statut, 5).'</td>';
608
+			if (!$i) $totalarray['nbfield']++;
609 609
 		}
610 610
 		// Billed
611
-		if (! empty($arrayfields['e.billed']['checked']))
611
+		if (!empty($arrayfields['e.billed']['checked']))
612 612
 		{
613 613
 			print '<td align="center">'.yn($obj->billed).'</td>';
614
-			if (! $i) $totalarray['nbfield']++;
614
+			if (!$i) $totalarray['nbfield']++;
615 615
 		}
616 616
 
617 617
 		// Action column
618 618
 		print '<td></td>';
619
-		if (! $i) $totalarray['nbfield']++;
619
+		if (!$i) $totalarray['nbfield']++;
620 620
 
621 621
 		print "</tr>\n";
622 622
 
Please login to merge, or discard this patch.
Braces   +208 added lines, -71 removed lines patch added patch discarded remove patch
@@ -38,7 +38,9 @@  discard block
 block discarded – undo
38 38
 $socid=GETPOST('socid','int');
39 39
 // Security check
40 40
 $expeditionid = GETPOST('id','int');
41
-if ($user->societe_id) $socid=$user->societe_id;
41
+if ($user->societe_id) {
42
+    $socid=$user->societe_id;
43
+}
42 44
 $result = restrictedArea($user, 'expedition',$expeditionid,'');
43 45
 
44 46
 $diroutputmassaction=$conf->expedition->dir_output . '/temp/massgeneration/'.$user->id;
@@ -60,8 +62,12 @@  discard block
 block discarded – undo
60 62
 $sortfield = GETPOST('sortfield','alpha');
61 63
 $sortorder = GETPOST('sortorder','alpha');
62 64
 $page = GETPOST('page','int');
63
-if (! $sortfield) $sortfield="e.ref";
64
-if (! $sortorder) $sortorder="DESC";
65
+if (! $sortfield) {
66
+    $sortfield="e.ref";
67
+}
68
+if (! $sortorder) {
69
+    $sortorder="DESC";
70
+}
65 71
 if (empty($page) || $page == -1) { $page = 0; }     // If $page is not defined, or '' or -1
66 72
 $offset = $limit * $page;
67 73
 $pageprev = $page - 1;
@@ -85,7 +91,9 @@  discard block
 block discarded – undo
85 91
 	's.nom'=>"ThirdParty",
86 92
 	'e.note_public'=>'NotePublic',
87 93
 );
88
-if (empty($user->socid)) $fieldstosearchall["e.note_private"]="NotePrivate";
94
+if (empty($user->socid)) {
95
+    $fieldstosearchall["e.note_private"]="NotePrivate";
96
+}
89 97
 
90 98
 $checkedtypetiers=0;
91 99
 $arrayfields=array(
@@ -111,7 +119,9 @@  discard block
 block discarded – undo
111 119
 {
112 120
 	foreach($extrafields->attribute_label as $key => $val)
113 121
 	{
114
-		if (! empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key])!=3 && $extrafields->attribute_perms[$key]));
122
+		if (! empty($extrafields->attribute_list[$key])) {
123
+		    $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key])!=3 && $extrafields->attribute_perms[$key]));
124
+		}
115 125
 	}
116 126
 }
117 127
 
@@ -125,14 +135,18 @@  discard block
 block discarded – undo
125 135
 
126 136
 $parameters=array('socid'=>$socid);
127 137
 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action);    // Note that $action and $object may have been modified by some hooks
128
-if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
138
+if ($reshook < 0) {
139
+    setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
140
+}
129 141
 
130 142
 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
131 143
 
132 144
 // Purge search criteria
133
-if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) // All tests are required to be compatible with all browsers
145
+if (GETPOST('button_removefilter_x','alpha') || GETPOST('button_removefilter.x','alpha') || GETPOST('button_removefilter','alpha')) {
146
+    // All tests are required to be compatible with all browsers
134 147
 {
135 148
 	$search_ref_exp='';
149
+}
136 150
 	$search_ref_liv='';
137 151
 	$search_ref_customer='';
138 152
 	$search_company='';
@@ -185,27 +199,35 @@  discard block
 block discarded – undo
185 199
 $sql.= " state.code_departement as state_code, state.nom as state_name,";
186 200
 $sql.= ' e.date_creation as date_creation, e.tms as date_update';
187 201
 // Add fields from extrafields
188
-foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
202
+foreach ($extrafields->attribute_label as $key => $val) {
203
+    $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
204
+}
189 205
 // Add fields from hooks
190 206
 $parameters=array();
191 207
 $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters);    // Note that $action and $object may have been modified by hook
192 208
 $sql.=$hookmanager->resPrint;
193 209
 $sql.= " FROM ".MAIN_DB_PREFIX."expedition as e";
194
-if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expedition_extrafields as ef on (e.rowid = ef.fk_object)";
210
+if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) {
211
+    $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."expedition_extrafields as ef on (e.rowid = ef.fk_object)";
212
+}
195 213
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = e.fk_soc";
196 214
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
197 215
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
198 216
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
199 217
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."element_element as ee ON e.rowid = ee.fk_source AND ee.sourcetype = 'shipping' AND ee.targettype = 'delivery'";
200 218
 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."livraison as l ON l.rowid = ee.fk_target";
201
-if (!$user->rights->societe->client->voir && !$socid)	// Internal user with no permission to see all
219
+if (!$user->rights->societe->client->voir && !$socid) {
220
+    // Internal user with no permission to see all
202 221
 {
203 222
 	$sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
204 223
 }
224
+}
205 225
 $sql.= " WHERE e.entity IN (".getEntity('expedition').")";
206
-if (!$user->rights->societe->client->voir && !$socid)	// Internal user with no permission to see all
226
+if (!$user->rights->societe->client->voir && !$socid) {
227
+    // Internal user with no permission to see all
207 228
 {
208 229
 	$sql.= " AND e.fk_soc = sc.fk_soc";
230
+}
209 231
 	$sql.= " AND sc.fk_user = " .$user->id;
210 232
 }
211 233
 if ($socid)
@@ -215,17 +237,39 @@  discard block
 block discarded – undo
215 237
 if ($viewstatut <> '' && $viewstatut >= 0) {
216 238
 	$sql.= " AND e.fk_statut = ".$viewstatut;
217 239
 }
218
-if ($search_ref_customer != '') $sql.=natural_search('e.ref_customer', $search_ref_customer);
219
-if ($search_billed != '' && $search_billed >= 0) $sql.=' AND e.billed = '.$search_billed;
220
-if ($search_town)  $sql.= natural_search('s.town', $search_town);
221
-if ($search_zip)   $sql.= natural_search("s.zip",$search_zip);
222
-if ($search_state) $sql.= natural_search("state.nom",$search_state);
223
-if ($search_country) $sql .= " AND s.fk_pays IN (".$search_country.')';
224
-if ($search_type_thirdparty) $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')';
225
-if ($search_ref_exp) $sql .= natural_search('e.ref', $search_ref_exp);
226
-if ($search_ref_liv) $sql .= natural_search('l.ref', $search_ref_liv);
227
-if ($search_company) $sql .= natural_search('s.nom', $search_company);
228
-if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall);
240
+if ($search_ref_customer != '') {
241
+    $sql.=natural_search('e.ref_customer', $search_ref_customer);
242
+}
243
+if ($search_billed != '' && $search_billed >= 0) {
244
+    $sql.=' AND e.billed = '.$search_billed;
245
+}
246
+if ($search_town) {
247
+    $sql.= natural_search('s.town', $search_town);
248
+}
249
+if ($search_zip) {
250
+    $sql.= natural_search("s.zip",$search_zip);
251
+}
252
+if ($search_state) {
253
+    $sql.= natural_search("state.nom",$search_state);
254
+}
255
+if ($search_country) {
256
+    $sql .= " AND s.fk_pays IN (".$search_country.')';
257
+}
258
+if ($search_type_thirdparty) {
259
+    $sql .= " AND s.fk_typent IN (".$search_type_thirdparty.')';
260
+}
261
+if ($search_ref_exp) {
262
+    $sql .= natural_search('e.ref', $search_ref_exp);
263
+}
264
+if ($search_ref_liv) {
265
+    $sql .= natural_search('l.ref', $search_ref_liv);
266
+}
267
+if ($search_company) {
268
+    $sql .= natural_search('s.nom', $search_company);
269
+}
270
+if ($sall) {
271
+    $sql .= natural_search(array_keys($fieldstosearchall), $sall);
272
+}
229 273
 
230 274
 // Add where from extra fields
231 275
 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
@@ -242,9 +286,11 @@  discard block
 block discarded – undo
242 286
 {
243 287
 	$result = $db->query($sql);
244 288
 	$nbtotalofrecords = $db->num_rows($result);
245
-	if (($page * $limit) > $nbtotalofrecords)	// if total resultset is smaller then paging size (filtering), goto and load page 0
289
+	if (($page * $limit) > $nbtotalofrecords) {
290
+	    // if total resultset is smaller then paging size (filtering), goto and load page 0
246 291
 	{
247 292
 		$page = 0;
293
+	}
248 294
 		$offset = 0;
249 295
 	}
250 296
 }
@@ -260,17 +306,39 @@  discard block
 block discarded – undo
260 306
 	$expedition = new Expedition($db);
261 307
 
262 308
 	$param='';
263
-	if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
264
-	if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.urlencode($limit);
265
-	if ($sall) $param.= "&amp;sall=".urlencode($sall);
266
-	if ($search_ref_exp)  $param.= "&amp;search_ref_exp=".urlencode($search_ref_exp);
267
-	if ($search_ref_liv)  $param.= "&amp;search_ref_liv=".urlencode($search_ref_liv);
268
-	if ($search_ref_customer) $param.= "&amp;search_ref_customer=".urlencode($search_ref_customer);
269
-	if ($search_company)   $param.= "&amp;search_company=".urlencode($search_company);
270
-	if ($search_town)      $param.= '&search_town='.urlencode($search_town);
271
-	if ($search_zip)       $param.= '&search_zip='.urlencode($search_zip);
272
-	if ($viewstatut != '') $param.= '&viewstatut='.urlencode($viewstatut);
273
-	if ($optioncss != '')  $param.='&amp;optioncss='.urlencode($optioncss);
309
+	if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
310
+	    $param.='&contextpage='.urlencode($contextpage);
311
+	}
312
+	if ($limit > 0 && $limit != $conf->liste_limit) {
313
+	    $param.='&limit='.urlencode($limit);
314
+	}
315
+	if ($sall) {
316
+	    $param.= "&amp;sall=".urlencode($sall);
317
+	}
318
+	if ($search_ref_exp) {
319
+	    $param.= "&amp;search_ref_exp=".urlencode($search_ref_exp);
320
+	}
321
+	if ($search_ref_liv) {
322
+	    $param.= "&amp;search_ref_liv=".urlencode($search_ref_liv);
323
+	}
324
+	if ($search_ref_customer) {
325
+	    $param.= "&amp;search_ref_customer=".urlencode($search_ref_customer);
326
+	}
327
+	if ($search_company) {
328
+	    $param.= "&amp;search_company=".urlencode($search_company);
329
+	}
330
+	if ($search_town) {
331
+	    $param.= '&search_town='.urlencode($search_town);
332
+	}
333
+	if ($search_zip) {
334
+	    $param.= '&search_zip='.urlencode($search_zip);
335
+	}
336
+	if ($viewstatut != '') {
337
+	    $param.= '&viewstatut='.urlencode($viewstatut);
338
+	}
339
+	if ($optioncss != '') {
340
+	    $param.='&amp;optioncss='.urlencode($optioncss);
341
+	}
274 342
 	// Add $param from extra fields
275 343
 	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
276 344
 
@@ -286,7 +354,9 @@  discard block
 block discarded – undo
286 354
 
287 355
 	$i = 0;
288 356
 	print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">'."\n";
289
-	if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
357
+	if ($optioncss != '') {
358
+	    print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
359
+	}
290 360
 	print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
291 361
 	print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
292 362
 	print '<input type="hidden" name="action" value="list">';
@@ -298,7 +368,9 @@  discard block
 block discarded – undo
298 368
 
299 369
 	if ($sall)
300 370
 	{
301
-		foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
371
+		foreach($fieldstosearchall as $key => $val) {
372
+		    $fieldstosearchall[$key]=$langs->trans($val);
373
+		}
302 374
 		print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall).'</div>';
303 375
 	}
304 376
 
@@ -343,9 +415,13 @@  discard block
 block discarded – undo
343 415
 		print '</td>';
344 416
 	}
345 417
 	// Town
346
-	if (! empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
418
+	if (! empty($arrayfields['s.town']['checked'])) {
419
+	    print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
420
+	}
347 421
 	// Zip
348
-	if (! empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
422
+	if (! empty($arrayfields['s.zip']['checked'])) {
423
+	    print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
424
+	}
349 425
 	// State
350 426
 	if (! empty($arrayfields['state.nom']['checked']))
351 427
 	{
@@ -425,17 +501,39 @@  discard block
 block discarded – undo
425 501
 	print "</tr>\n";
426 502
 
427 503
 	print '<tr class="liste_titre">';
428
-	if (! empty($arrayfields['e.ref']['checked']))            print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"],"e.ref","",$param,'',$sortfield,$sortorder);
429
-	if (! empty($arrayfields['e.ref_customer']['checked']))   print_liste_field_titre($arrayfields['e.ref_customer']['label'], $_SERVER["PHP_SELF"],"e.ref_customer","",$param,'',$sortfield,$sortorder);
430
-	if (! empty($arrayfields['s.nom']['checked']))            print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"],"s.nom", "", $param,'align="left"',$sortfield,$sortorder);
431
-	if (! empty($arrayfields['s.town']['checked']))           print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
432
-	if (! empty($arrayfields['s.zip']['checked']))            print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
433
-	if (! empty($arrayfields['state.nom']['checked']))        print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
434
-	if (! empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'],$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder);
435
-	if (! empty($arrayfields['typent.code']['checked']))      print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
436
-	if (! empty($arrayfields['e.date_delivery']['checked']))  print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"],"e.date_delivery","",$param, 'align="center"',$sortfield,$sortorder);
437
-	if (! empty($arrayfields['l.ref']['checked']))            print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"],"l.ref","",$param, '',$sortfield,$sortorder);
438
-	if (! empty($arrayfields['l.date_delivery']['checked']))  print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"],"l.date_delivery","",$param, 'align="center"',$sortfield,$sortorder);
504
+	if (! empty($arrayfields['e.ref']['checked'])) {
505
+	    print_liste_field_titre($arrayfields['e.ref']['label'], $_SERVER["PHP_SELF"],"e.ref","",$param,'',$sortfield,$sortorder);
506
+	}
507
+	if (! empty($arrayfields['e.ref_customer']['checked'])) {
508
+	    print_liste_field_titre($arrayfields['e.ref_customer']['label'], $_SERVER["PHP_SELF"],"e.ref_customer","",$param,'',$sortfield,$sortorder);
509
+	}
510
+	if (! empty($arrayfields['s.nom']['checked'])) {
511
+	    print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"],"s.nom", "", $param,'align="left"',$sortfield,$sortorder);
512
+	}
513
+	if (! empty($arrayfields['s.town']['checked'])) {
514
+	    print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
515
+	}
516
+	if (! empty($arrayfields['s.zip']['checked'])) {
517
+	    print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
518
+	}
519
+	if (! empty($arrayfields['state.nom']['checked'])) {
520
+	    print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
521
+	}
522
+	if (! empty($arrayfields['country.code_iso']['checked'])) {
523
+	    print_liste_field_titre($arrayfields['country.code_iso']['label'],$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder);
524
+	}
525
+	if (! empty($arrayfields['typent.code']['checked'])) {
526
+	    print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
527
+	}
528
+	if (! empty($arrayfields['e.date_delivery']['checked'])) {
529
+	    print_liste_field_titre($arrayfields['e.date_delivery']['label'], $_SERVER["PHP_SELF"],"e.date_delivery","",$param, 'align="center"',$sortfield,$sortorder);
530
+	}
531
+	if (! empty($arrayfields['l.ref']['checked'])) {
532
+	    print_liste_field_titre($arrayfields['l.ref']['label'], $_SERVER["PHP_SELF"],"l.ref","",$param, '',$sortfield,$sortorder);
533
+	}
534
+	if (! empty($arrayfields['l.date_delivery']['checked'])) {
535
+	    print_liste_field_titre($arrayfields['l.date_delivery']['label'], $_SERVER["PHP_SELF"],"l.date_delivery","",$param, 'align="center"',$sortfield,$sortorder);
536
+	}
439 537
 	// Extra fields
440 538
 	if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
441 539
 	{
@@ -445,7 +543,9 @@  discard block
 block discarded – undo
445 543
 			{
446 544
 				$align=$extrafields->getAlignFlag($key);
447 545
 				$sortonfield = "ef.".$key;
448
-				if (! empty($extrafields->attribute_computed[$key])) $sortonfield='';
546
+				if (! empty($extrafields->attribute_computed[$key])) {
547
+				    $sortonfield='';
548
+				}
449 549
 				print_liste_field_titre($extralabels[$key],$_SERVER["PHP_SELF"],$sortonfield,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
450 550
 			}
451 551
 		}
@@ -454,10 +554,18 @@  discard block
 block discarded – undo
454 554
 	$parameters=array('arrayfields'=>$arrayfields,'param'=>$param,'sortfield'=>$sortfield,'sortorder'=>$sortorder);
455 555
 	$reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters);    // Note that $action and $object may have been modified by hook
456 556
 	print $hookmanager->resPrint;
457
-	if (! empty($arrayfields['e.datec']['checked']))  print_liste_field_titre($arrayfields['e.datec']['label'],$_SERVER["PHP_SELF"],"e.date_creation","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
458
-	if (! empty($arrayfields['e.tms']['checked']))    print_liste_field_titre($arrayfields['e.tms']['label'],$_SERVER["PHP_SELF"],"e.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
459
-	if (! empty($arrayfields['e.fk_statut']['checked'])) print_liste_field_titre($arrayfields['e.fk_statut']['label'],$_SERVER["PHP_SELF"],"e.fk_statut","",$param,'align="right"',$sortfield,$sortorder);
460
-	if (! empty($arrayfields['e.billed']['checked'])) print_liste_field_titre($arrayfields['e.billed']['label'],$_SERVER["PHP_SELF"],"e.billed","",$param,'align="center"',$sortfield,$sortorder);
557
+	if (! empty($arrayfields['e.datec']['checked'])) {
558
+	    print_liste_field_titre($arrayfields['e.datec']['label'],$_SERVER["PHP_SELF"],"e.date_creation","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
559
+	}
560
+	if (! empty($arrayfields['e.tms']['checked'])) {
561
+	    print_liste_field_titre($arrayfields['e.tms']['label'],$_SERVER["PHP_SELF"],"e.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
562
+	}
563
+	if (! empty($arrayfields['e.fk_statut']['checked'])) {
564
+	    print_liste_field_titre($arrayfields['e.fk_statut']['label'],$_SERVER["PHP_SELF"],"e.fk_statut","",$param,'align="right"',$sortfield,$sortorder);
565
+	}
566
+	if (! empty($arrayfields['e.billed']['checked'])) {
567
+	    print_liste_field_titre($arrayfields['e.billed']['label'],$_SERVER["PHP_SELF"],"e.billed","",$param,'align="center"',$sortfield,$sortorder);
568
+	}
461 569
 	print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
462 570
 	print "</tr>\n";
463 571
 
@@ -483,7 +591,9 @@  discard block
 block discarded – undo
483 591
 			print "<td>";
484 592
 			print $shipment->getNomUrl(1);
485 593
 			print "</td>\n";
486
-			if (! $i) $totalarray['nbfield']++;
594
+			if (! $i) {
595
+			    $totalarray['nbfield']++;
596
+			}
487 597
 		}
488 598
 
489 599
 		// Ref customer
@@ -492,7 +602,9 @@  discard block
 block discarded – undo
492 602
 			print "<td>";
493 603
 			print $obj->ref_customer;
494 604
 			print "</td>\n";
495
-			if (! $i) $totalarray['nbfield']++;
605
+			if (! $i) {
606
+			    $totalarray['nbfield']++;
607
+			}
496 608
 		}
497 609
 
498 610
 		// Third party
@@ -501,7 +613,9 @@  discard block
 block discarded – undo
501 613
 			print '<td>';
502 614
 			print $companystatic->getNomUrl(1);
503 615
 			print '</td>';
504
-			if (! $i) $totalarray['nbfield']++;
616
+			if (! $i) {
617
+			    $totalarray['nbfield']++;
618
+			}
505 619
 		}
506 620
 		// Town
507 621
 		if (! empty($arrayfields['s.town']['checked']))
@@ -509,7 +623,9 @@  discard block
 block discarded – undo
509 623
 			print '<td class="nocellnopadd">';
510 624
 			print $obj->town;
511 625
 			print '</td>';
512
-			if (! $i) $totalarray['nbfield']++;
626
+			if (! $i) {
627
+			    $totalarray['nbfield']++;
628
+			}
513 629
 		}
514 630
 		// Zip
515 631
 		if (! empty($arrayfields['s.zip']['checked']))
@@ -517,13 +633,17 @@  discard block
 block discarded – undo
517 633
 			print '<td class="nocellnopadd">';
518 634
 			print $obj->zip;
519 635
 			print '</td>';
520
-			if (! $i) $totalarray['nbfield']++;
636
+			if (! $i) {
637
+			    $totalarray['nbfield']++;
638
+			}
521 639
 		}
522 640
 		// State
523 641
 		if (! empty($arrayfields['state.nom']['checked']))
524 642
 		{
525 643
 			print "<td>".$obj->state_name."</td>\n";
526
-			if (! $i) $totalarray['nbfield']++;
644
+			if (! $i) {
645
+			    $totalarray['nbfield']++;
646
+			}
527 647
 		}
528 648
 		// Country
529 649
 		if (! empty($arrayfields['country.code_iso']['checked']))
@@ -532,16 +652,22 @@  discard block
 block discarded – undo
532 652
 			$tmparray=getCountry($obj->fk_pays,'all');
533 653
 			print $tmparray['label'];
534 654
 			print '</td>';
535
-			if (! $i) $totalarray['nbfield']++;
655
+			if (! $i) {
656
+			    $totalarray['nbfield']++;
657
+			}
536 658
 		}
537 659
 		// Type ent
538 660
 		if (! empty($arrayfields['typent.code']['checked']))
539 661
 		{
540 662
 			print '<td align="center">';
541
-			if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
663
+			if (count($typenArray)==0) {
664
+			    $typenArray = $formcompany->typent_array(1);
665
+			}
542 666
 			print $typenArray[$obj->typent_code];
543 667
 			print '</td>';
544
-			if (! $i) $totalarray['nbfield']++;
668
+			if (! $i) {
669
+			    $totalarray['nbfield']++;
670
+			}
545 671
 		}
546 672
 
547 673
 		// Date delivery planed
@@ -560,7 +686,9 @@  discard block
 block discarded – undo
560 686
 		{
561 687
 			$shipment->fetchObjectLinked($shipment->id,$shipment->element);
562 688
 			$receiving='';
563
-			if (is_array($shipment->linkedObjects['delivery']) && count($shipment->linkedObjects['delivery']) > 0) $receiving=reset($shipment->linkedObjects['delivery']);
689
+			if (is_array($shipment->linkedObjects['delivery']) && count($shipment->linkedObjects['delivery']) > 0) {
690
+			    $receiving=reset($shipment->linkedObjects['delivery']);
691
+			}
564 692
 
565 693
 			if (! empty($arrayfields['l.ref']['checked']))
566 694
 			{
@@ -591,7 +719,9 @@  discard block
 block discarded – undo
591 719
 			print '<td align="center" class="nowrap">';
592 720
 			print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
593 721
 			print '</td>';
594
-			if (! $i) $totalarray['nbfield']++;
722
+			if (! $i) {
723
+			    $totalarray['nbfield']++;
724
+			}
595 725
 		}
596 726
 		// Date modification
597 727
 		if (! empty($arrayfields['e.tms']['checked']))
@@ -599,24 +729,32 @@  discard block
 block discarded – undo
599 729
 			print '<td align="center" class="nowrap">';
600 730
 			print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
601 731
 			print '</td>';
602
-			if (! $i) $totalarray['nbfield']++;
732
+			if (! $i) {
733
+			    $totalarray['nbfield']++;
734
+			}
603 735
 		}
604 736
 		// Status
605 737
 		if (! empty($arrayfields['e.fk_statut']['checked']))
606 738
 		{
607 739
 			print '<td align="right" class="nowrap">'.$shipment->LibStatut($obj->fk_statut,5).'</td>';
608
-			if (! $i) $totalarray['nbfield']++;
740
+			if (! $i) {
741
+			    $totalarray['nbfield']++;
742
+			}
609 743
 		}
610 744
 		// Billed
611 745
 		if (! empty($arrayfields['e.billed']['checked']))
612 746
 		{
613 747
 			print '<td align="center">'.yn($obj->billed).'</td>';
614
-			if (! $i) $totalarray['nbfield']++;
748
+			if (! $i) {
749
+			    $totalarray['nbfield']++;
750
+			}
615 751
 		}
616 752
 
617 753
 		// Action column
618 754
 		print '<td></td>';
619
-		if (! $i) $totalarray['nbfield']++;
755
+		if (! $i) {
756
+		    $totalarray['nbfield']++;
757
+		}
620 758
 
621 759
 		print "</tr>\n";
622 760
 
@@ -627,8 +765,7 @@  discard block
 block discarded – undo
627 765
 	print "</div>";
628 766
 	print '</form>';
629 767
 	$db->free($resql);
630
-}
631
-else
768
+} else
632 769
 {
633 770
 	dol_print_error($db);
634 771
 }
Please login to merge, or discard this patch.
dolibarr/htdocs/expedition/stats/month.php 2 patches
Indentation   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -61,8 +61,8 @@
 block discarded – undo
61 61
     $px->SetHeight($HEIGHT);
62 62
     $px->SetYLabel($langs->trans("NbOfOrders"));
63 63
     $px->SetShading(3);
64
-	$px->SetHorizTickIncrement(1);
65
-	$px->SetPrecisionY(0);
64
+    $px->SetHorizTickIncrement(1);
65
+    $px->SetPrecisionY(0);
66 66
     $px->draw($filename,$fileurl);
67 67
 }
68 68
 
Please login to merge, or discard this patch.
Spacing   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -36,8 +36,8 @@  discard block
 block discarded – undo
36 36
 
37 37
 llxHeader();
38 38
 
39
-$WIDTH=DolGraph::getDefaultGraphSizeForStats('width');
40
-$HEIGHT=DolGraph::getDefaultGraphSizeForStats('height');
39
+$WIDTH = DolGraph::getDefaultGraphSizeForStats('width');
40
+$HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
41 41
 
42 42
 $mesg = '';
43 43
 
@@ -53,7 +53,7 @@  discard block
 block discarded – undo
53 53
 
54 54
 $px = new DolGraph();
55 55
 $mesg = $px->isGraphKo();
56
-if (! $mesg)
56
+if (!$mesg)
57 57
 {
58 58
     $px->SetData($data);
59 59
     $px->SetMaxValue($px->GetCeilMaxValue());
@@ -63,7 +63,7 @@  discard block
 block discarded – undo
63 63
     $px->SetShading(3);
64 64
 	$px->SetHorizTickIncrement(1);
65 65
 	$px->SetPrecisionY(0);
66
-    $px->draw($filename,$fileurl);
66
+    $px->draw($filename, $fileurl);
67 67
 }
68 68
 
69 69
 print '<table class="border" width="100%">';
Please login to merge, or discard this patch.
dolibarr/htdocs/expedition/stats/index.php 3 patches
Indentation   +50 added lines, -50 removed lines patch added patch discarded remove patch
@@ -205,9 +205,9 @@  discard block
 block discarded – undo
205 205
 $data = $stats->getAllByYear();
206 206
 $arrayyears=array();
207 207
 foreach($data as $val) {
208
-	if (! empty($val['year'])) {
209
-		$arrayyears[$val['year']]=$val['year'];
210
-	}
208
+    if (! empty($val['year'])) {
209
+        $arrayyears[$val['year']]=$val['year'];
210
+    }
211 211
 }
212 212
 if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear;
213 213
 
@@ -230,33 +230,33 @@  discard block
 block discarded – undo
230 230
 
231 231
 //if (empty($socid))
232 232
 //{
233
-	// Show filter box
234
-	print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
235
-	print '<input type="hidden" name="mode" value="'.$mode.'">';
236
-
237
-	print '<table class="noborder" width="100%">';
238
-	print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
239
-	// Company
240
-	print '<tr><td align="left">'.$langs->trans("ThirdParty").'</td><td align="left">';
241
-	if ($mode == 'customer') $filter='s.client in (1,2,3)';
242
-	if ($mode == 'supplier') $filter='s.fournisseur = 1';
243
-	print $form->select_company($socid,'socid',$filter,1,0,0,array(),0,'','style="width: 95%"');
244
-	print '</td></tr>';
245
-	// User
246
-	print '<tr><td align="left">'.$langs->trans("CreatedBy").'</td><td align="left">';
247
-	print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
248
-	print '</td></tr>';
249
-	// Year
250
-	print '<tr><td align="left">'.$langs->trans("Year").'</td><td align="left">';
251
-	if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
252
-	if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear;
253
-	arsort($arrayyears);
254
-	print $form->selectarray('year',$arrayyears,$year,0);
255
-	print '</td></tr>';
256
-	print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
257
-	print '</table>';
258
-	print '</form>';
259
-	print '<br><br>';
233
+    // Show filter box
234
+    print '<form name="stats" method="POST" action="'.$_SERVER["PHP_SELF"].'">';
235
+    print '<input type="hidden" name="mode" value="'.$mode.'">';
236
+
237
+    print '<table class="noborder" width="100%">';
238
+    print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
239
+    // Company
240
+    print '<tr><td align="left">'.$langs->trans("ThirdParty").'</td><td align="left">';
241
+    if ($mode == 'customer') $filter='s.client in (1,2,3)';
242
+    if ($mode == 'supplier') $filter='s.fournisseur = 1';
243
+    print $form->select_company($socid,'socid',$filter,1,0,0,array(),0,'','style="width: 95%"');
244
+    print '</td></tr>';
245
+    // User
246
+    print '<tr><td align="left">'.$langs->trans("CreatedBy").'</td><td align="left">';
247
+    print $form->select_dolusers($userid, 'userid', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
248
+    print '</td></tr>';
249
+    // Year
250
+    print '<tr><td align="left">'.$langs->trans("Year").'</td><td align="left">';
251
+    if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
252
+    if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear;
253
+    arsort($arrayyears);
254
+    print $form->selectarray('year',$arrayyears,$year,0);
255
+    print '</td></tr>';
256
+    print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
257
+    print '</table>';
258
+    print '</form>';
259
+    print '<br><br>';
260 260
 //}
261 261
 
262 262
 
@@ -272,31 +272,31 @@  discard block
 block discarded – undo
272 272
 $oldyear=0;
273 273
 foreach ($data as $val)
274 274
 {
275
-	$year = $val['year'];
276
-	while (! empty($year) && $oldyear > $year+1)
277
-	{ // If we have empty year
278
-		$oldyear--;
275
+    $year = $val['year'];
276
+    while (! empty($year) && $oldyear > $year+1)
277
+    { // If we have empty year
278
+        $oldyear--;
279 279
 
280 280
 
281
-		print '<tr class="oddeven" height="24">';
282
-		print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.'">'.$oldyear.'</a></td>';
281
+        print '<tr class="oddeven" height="24">';
282
+        print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&amp;mode='.$mode.'">'.$oldyear.'</a></td>';
283 283
 
284
-		print '<td align="right">0</td>';
285
-		/*print '<td align="right">0</td>';
284
+        print '<td align="right">0</td>';
285
+        /*print '<td align="right">0</td>';
286 286
 		print '<td align="right">0</td>';*/
287
-		print '</tr>';
288
-	}
289
-
290
-	print '<tr class="oddeven" height="24">';
291
-	print '<td align="center">';
292
-	if ($year) print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.'">'.$year.'</a>';
293
-	else print $langs->trans("ValidationDateNotDefinedEvenIfShipmentValidated");
294
-	print '</td>';
295
-	print '<td align="right">'.$val['nb'].'</td>';
296
-	/*print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
287
+        print '</tr>';
288
+    }
289
+
290
+    print '<tr class="oddeven" height="24">';
291
+    print '<td align="center">';
292
+    if ($year) print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.'">'.$year.'</a>';
293
+    else print $langs->trans("ValidationDateNotDefinedEvenIfShipmentValidated");
294
+    print '</td>';
295
+    print '<td align="right">'.$val['nb'].'</td>';
296
+    /*print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
297 297
 	print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';*/
298
-	print '</tr>';
299
-	$oldyear=$year;
298
+    print '</tr>';
299
+    $oldyear=$year;
300 300
 }
301 301
 
302 302
 print '</table>';
Please login to merge, or discard this patch.
Spacing   +35 added lines, -35 removed lines patch added patch discarded remove patch
@@ -28,11 +28,11 @@  discard block
 block discarded – undo
28 28
 require_once DOL_DOCUMENT_ROOT.'/expedition/class/expeditionstats.class.php';
29 29
 require_once DOL_DOCUMENT_ROOT.'/core/class/dolgraph.class.php';
30 30
 
31
-$WIDTH=DolGraph::getDefaultGraphSizeForStats('width');
32
-$HEIGHT=DolGraph::getDefaultGraphSizeForStats('height');
31
+$WIDTH = DolGraph::getDefaultGraphSizeForStats('width');
32
+$HEIGHT = DolGraph::getDefaultGraphSizeForStats('height');
33 33
 
34
-$userid=GETPOST('userid','int');
35
-$socid=GETPOST('socid','int');
34
+$userid = GETPOST('userid', 'int');
35
+$socid = GETPOST('socid', 'int');
36 36
 // Security check
37 37
 if ($user->societe_id > 0)
38 38
 {
@@ -40,11 +40,11 @@  discard block
 block discarded – undo
40 40
     $socid = $user->societe_id;
41 41
 }
42 42
 
43
-$nowyear=strftime("%Y", dol_now());
44
-$year = GETPOST('year')>0?GETPOST('year'):$nowyear;
43
+$nowyear = strftime("%Y", dol_now());
44
+$year = GETPOST('year') > 0 ?GETPOST('year') : $nowyear;
45 45
 //$startyear=$year-2;
46
-$startyear=$year-1;
47
-$endyear=$year;
46
+$startyear = $year - 1;
47
+$endyear = $year;
48 48
 
49 49
 // Load translation files required by the page
50 50
 $langs->loadLangs(array('sendings', 'other', 'companies'));
@@ -54,7 +54,7 @@  discard block
 block discarded – undo
54 54
  * View
55 55
  */
56 56
 
57
-$form=new Form($db);
57
+$form = new Form($db);
58 58
 
59 59
 llxHeader();
60 60
 
@@ -63,10 +63,10 @@  discard block
 block discarded – undo
63 63
 
64 64
 dol_mkdir($dir);
65 65
 
66
-$stats = new ExpeditionStats($db, $socid, $mode, ($userid>0?$userid:0));
66
+$stats = new ExpeditionStats($db, $socid, $mode, ($userid > 0 ? $userid : 0));
67 67
 
68 68
 // Build graphic number of object
69
-$data = $stats->getNbByMonthWithPrevYear($endyear,$startyear);
69
+$data = $stats->getNbByMonthWithPrevYear($endyear, $startyear);
70 70
 //var_dump($data);exit;
71 71
 // $data = array(array('Lib',val1,val2,val3),...)
72 72
 
@@ -86,29 +86,29 @@  discard block
 block discarded – undo
86 86
 
87 87
 $px1 = new DolGraph();
88 88
 $mesg = $px1->isGraphKo();
89
-if (! $mesg)
89
+if (!$mesg)
90 90
 {
91 91
     $px1->SetData($data);
92 92
     $px1->SetPrecisionY(0);
93
-    $i=$startyear;$legend=array();
93
+    $i = $startyear; $legend = array();
94 94
     while ($i <= $endyear)
95 95
     {
96
-        $legend[]=$i;
96
+        $legend[] = $i;
97 97
         $i++;
98 98
     }
99 99
     $px1->SetLegend($legend);
100 100
     $px1->SetMaxValue($px1->GetCeilMaxValue());
101
-    $px1->SetMinValue(min(0,$px1->GetFloorMinValue()));
101
+    $px1->SetMinValue(min(0, $px1->GetFloorMinValue()));
102 102
     $px1->SetWidth($WIDTH);
103 103
     $px1->SetHeight($HEIGHT);
104 104
     $px1->SetYLabel($langs->trans("NbOfSendings"));
105 105
     $px1->SetShading(3);
106 106
     $px1->SetHorizTickIncrement(1);
107 107
     $px1->SetPrecisionY(0);
108
-    $px1->mode='depth';
108
+    $px1->mode = 'depth';
109 109
     $px1->SetTitle($langs->trans("NumberOfShipmentsByMonth"));
110 110
 
111
-    $px1->draw($filenamenb,$fileurlnb);
111
+    $px1->draw($filenamenb, $fileurlnb);
112 112
 }
113 113
 
114 114
 // Build graphic amount of object
@@ -203,24 +203,24 @@  discard block
 block discarded – undo
203 203
 
204 204
 // Show array
205 205
 $data = $stats->getAllByYear();
206
-$arrayyears=array();
207
-foreach($data as $val) {
208
-	if (! empty($val['year'])) {
209
-		$arrayyears[$val['year']]=$val['year'];
206
+$arrayyears = array();
207
+foreach ($data as $val) {
208
+	if (!empty($val['year'])) {
209
+		$arrayyears[$val['year']] = $val['year'];
210 210
 	}
211 211
 }
212
-if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear;
212
+if (!count($arrayyears)) $arrayyears[$nowyear] = $nowyear;
213 213
 
214
-$h=0;
214
+$h = 0;
215 215
 $head = array();
216
-$head[$h][0] = DOL_URL_ROOT . '/expedition/stats/index.php?mode='.$mode;
216
+$head[$h][0] = DOL_URL_ROOT.'/expedition/stats/index.php?mode='.$mode;
217 217
 $head[$h][1] = $langs->trans("ByMonthYear");
218 218
 $head[$h][2] = 'byyear';
219 219
 $h++;
220 220
 
221
-$type='shipment_stats';
221
+$type = 'shipment_stats';
222 222
 
223
-complete_head_from_modules($conf,$langs,null,$head,$h,$type);
223
+complete_head_from_modules($conf, $langs, null, $head, $h, $type);
224 224
 
225 225
 dol_fiche_head($head, 'byyear', $langs->trans("Statistics"), -1);
226 226
 
@@ -238,9 +238,9 @@  discard block
 block discarded – undo
238 238
 	print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
239 239
 	// Company
240 240
 	print '<tr><td align="left">'.$langs->trans("ThirdParty").'</td><td align="left">';
241
-	if ($mode == 'customer') $filter='s.client in (1,2,3)';
242
-	if ($mode == 'supplier') $filter='s.fournisseur = 1';
243
-	print $form->select_company($socid,'socid',$filter,1,0,0,array(),0,'','style="width: 95%"');
241
+	if ($mode == 'customer') $filter = 's.client in (1,2,3)';
242
+	if ($mode == 'supplier') $filter = 's.fournisseur = 1';
243
+	print $form->select_company($socid, 'socid', $filter, 1, 0, 0, array(), 0, '', 'style="width: 95%"');
244 244
 	print '</td></tr>';
245 245
 	// User
246 246
 	print '<tr><td align="left">'.$langs->trans("CreatedBy").'</td><td align="left">';
@@ -248,10 +248,10 @@  discard block
 block discarded – undo
248 248
 	print '</td></tr>';
249 249
 	// Year
250 250
 	print '<tr><td align="left">'.$langs->trans("Year").'</td><td align="left">';
251
-	if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
252
-	if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear;
251
+	if (!in_array($year, $arrayyears)) $arrayyears[$year] = $year;
252
+	if (!in_array($nowyear, $arrayyears)) $arrayyears[$nowyear] = $nowyear;
253 253
 	arsort($arrayyears);
254
-	print $form->selectarray('year',$arrayyears,$year,0);
254
+	print $form->selectarray('year', $arrayyears, $year, 0);
255 255
 	print '</td></tr>';
256 256
 	print '<tr><td align="center" colspan="2"><input type="submit" name="submit" class="button" value="'.$langs->trans("Refresh").'"></td></tr>';
257 257
 	print '</table>';
@@ -269,11 +269,11 @@  discard block
 block discarded – undo
269 269
 print '<td align="center">'.$langs->trans("AmountAverage").'</td>';*/
270 270
 print '</tr>';
271 271
 
272
-$oldyear=0;
272
+$oldyear = 0;
273 273
 foreach ($data as $val)
274 274
 {
275 275
 	$year = $val['year'];
276
-	while (! empty($year) && $oldyear > $year+1)
276
+	while (!empty($year) && $oldyear > $year + 1)
277 277
 	{ // If we have empty year
278 278
 		$oldyear--;
279 279
 
@@ -296,7 +296,7 @@  discard block
 block discarded – undo
296 296
 	/*print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
297 297
 	print '<td align="right">'.price(price2num($val['avg'],'MT'),1).'</td>';*/
298 298
 	print '</tr>';
299
-	$oldyear=$year;
299
+	$oldyear = $year;
300 300
 }
301 301
 
302 302
 print '</table>';
Please login to merge, or discard this patch.
Braces   +35 added lines, -16 removed lines patch added patch discarded remove patch
@@ -74,15 +74,22 @@  discard block
 block discarded – undo
74 74
 if (!$user->rights->societe->client->voir || $user->societe_id)
75 75
 {
76 76
     $filenamenb = $dir.'/shipmentsnbinyear-'.$user->id.'-'.$year.'.png';
77
-    if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsnbinyear-'.$user->id.'-'.$year.'.png';
78
-    if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsnbinyear-'.$user->id.'-'.$year.'.png';
79
-}
80
-else
77
+    if ($mode == 'customer') {
78
+        $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsnbinyear-'.$user->id.'-'.$year.'.png';
79
+    }
80
+    if ($mode == 'supplier') {
81
+        $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsnbinyear-'.$user->id.'-'.$year.'.png';
82
+    }
83
+    } else
81 84
 {
82 85
     $filenamenb = $dir.'/shipmentsnbinyear-'.$year.'.png';
83
-    if ($mode == 'customer') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsnbinyear-'.$year.'.png';
84
-    if ($mode == 'supplier') $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsnbinyear-'.$year.'.png';
85
-}
86
+    if ($mode == 'customer') {
87
+        $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstats&file=shipmentsnbinyear-'.$year.'.png';
88
+    }
89
+    if ($mode == 'supplier') {
90
+        $fileurlnb = DOL_URL_ROOT.'/viewimage.php?modulepart=shipmentstatssupplier&file=shipmentsnbinyear-'.$year.'.png';
91
+    }
92
+    }
86 93
 
87 94
 $px1 = new DolGraph();
88 95
 $mesg = $px1->isGraphKo();
@@ -209,7 +216,9 @@  discard block
 block discarded – undo
209 216
 		$arrayyears[$val['year']]=$val['year'];
210 217
 	}
211 218
 }
212
-if (! count($arrayyears)) $arrayyears[$nowyear]=$nowyear;
219
+if (! count($arrayyears)) {
220
+    $arrayyears[$nowyear]=$nowyear;
221
+}
213 222
 
214 223
 $h=0;
215 224
 $head = array();
@@ -238,8 +247,12 @@  discard block
 block discarded – undo
238 247
 	print '<tr class="liste_titre"><td class="liste_titre" colspan="2">'.$langs->trans("Filter").'</td></tr>';
239 248
 	// Company
240 249
 	print '<tr><td align="left">'.$langs->trans("ThirdParty").'</td><td align="left">';
241
-	if ($mode == 'customer') $filter='s.client in (1,2,3)';
242
-	if ($mode == 'supplier') $filter='s.fournisseur = 1';
250
+	if ($mode == 'customer') {
251
+	    $filter='s.client in (1,2,3)';
252
+	}
253
+	if ($mode == 'supplier') {
254
+	    $filter='s.fournisseur = 1';
255
+	}
243 256
 	print $form->select_company($socid,'socid',$filter,1,0,0,array(),0,'','style="width: 95%"');
244 257
 	print '</td></tr>';
245 258
 	// User
@@ -248,8 +261,12 @@  discard block
 block discarded – undo
248 261
 	print '</td></tr>';
249 262
 	// Year
250 263
 	print '<tr><td align="left">'.$langs->trans("Year").'</td><td align="left">';
251
-	if (! in_array($year,$arrayyears)) $arrayyears[$year]=$year;
252
-	if (! in_array($nowyear,$arrayyears)) $arrayyears[$nowyear]=$nowyear;
264
+	if (! in_array($year,$arrayyears)) {
265
+	    $arrayyears[$year]=$year;
266
+	}
267
+	if (! in_array($nowyear,$arrayyears)) {
268
+	    $arrayyears[$nowyear]=$nowyear;
269
+	}
253 270
 	arsort($arrayyears);
254 271
 	print $form->selectarray('year',$arrayyears,$year,0);
255 272
 	print '</td></tr>';
@@ -289,8 +306,11 @@  discard block
 block discarded – undo
289 306
 
290 307
 	print '<tr class="oddeven" height="24">';
291 308
 	print '<td align="center">';
292
-	if ($year) print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.'">'.$year.'</a>';
293
-	else print $langs->trans("ValidationDateNotDefinedEvenIfShipmentValidated");
309
+	if ($year) {
310
+	    print '<a href="'.$_SERVER["PHP_SELF"].'?year='.$year.'&amp;mode='.$mode.'">'.$year.'</a>';
311
+	} else {
312
+	    print $langs->trans("ValidationDateNotDefinedEvenIfShipmentValidated");
313
+	}
294 314
 	print '</td>';
295 315
 	print '<td align="right">'.$val['nb'].'</td>';
296 316
 	/*print '<td align="right">'.price(price2num($val['total'],'MT'),1).'</td>';
@@ -308,8 +328,7 @@  discard block
 block discarded – undo
308 328
 
309 329
 // Show graphs
310 330
 print '<table class="border" width="100%"><tr class="pair nohover"><td align="center">';
311
-if ($mesg) { print $mesg; }
312
-else {
331
+if ($mesg) { print $mesg; } else {
313 332
     print $px1->show();
314 333
     print "<br>\n";
315 334
     /*print $px2->show();
Please login to merge, or discard this patch.
dolibarr/htdocs/societe/class/companypaymentmode.class.php 3 patches
Indentation   +495 added lines, -495 removed lines patch added patch discarded remove patch
@@ -32,279 +32,279 @@  discard block
 block discarded – undo
32 32
  */
33 33
 class CompanyPaymentMode extends CommonObject
34 34
 {
35
-	/**
36
-	 * @var string ID to identify managed object
37
-	 */
38
-	public $element = 'companypaymentmode';
39
-
40
-	/**
41
-	 * @var string Name of table without prefix where object is stored
42
-	 */
43
-	public $table_element = 'societe_rib';
44
-
45
-	/**
46
-	 * @var int  Does companypaymentmode support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
47
-	 */
48
-	public $ismultientitymanaged = 2;
49
-
50
-	/**
51
-	 * @var int  Does companypaymentmode support extrafields ? 0=No, 1=Yes
52
-	 */
53
-	public $isextrafieldmanaged = 0;
54
-
55
-	/**
56
-	 * @var string String with name of icon for companypaymentmode. Must be the part after the 'object_' into object_companypaymentmode.png
57
-	 */
58
-	public $picto = 'generic';
59
-
60
-
61
-	/**
62
-	 *  'type' if the field format.
63
-	 *  'label' the translation key.
64
-	 *  'enabled' is a condition when the field must be managed.
65
-	 *  'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only. Using a negative value means field is not shown by default on list but can be selected for viewing)
66
-	 *  'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
67
-	 *  'index' if we want an index in database.
68
-	 *  'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
69
-	 *  'position' is the sort order of field.
70
-	 *  'searchall' is 1 if we want to search in this field when making a search from the quick search button.
71
-	 *  'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
72
-	 *  'help' is a string visible as a tooltip on field
73
-	 *  'comment' is not used. You can store here any text of your choice. It is not used by application.
74
-	 *  'default' is a default value for creation (can still be replaced by the global setup of default values)
75
-	 *  'showoncombobox' if field must be shown into the label of combobox
76
-	 */
77
-
78
-	// BEGIN MODULEBUILDER PROPERTIES
79
-	/**
80
-	 * @var array  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
81
-	 */
82
-	public $fields=array(
83
-		'rowid' =>array('type'=>'integer', 'label'=>'Rowid', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>10),
84
-		'fk_soc' =>array('type'=>'integer', 'label'=>'Fk soc', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>15),
85
-		'label' =>array('type'=>'varchar(30)', 'label'=>'Label', 'enabled'=>1, 'visible'=>-2, 'position'=>30),
86
-		'bank' =>array('type'=>'varchar(255)', 'label'=>'Bank', 'enabled'=>1, 'visible'=>-2, 'position'=>35),
87
-		'code_banque' =>array('type'=>'varchar(128)', 'label'=>'Code banque', 'enabled'=>1, 'visible'=>-2, 'position'=>40),
88
-		'code_guichet' =>array('type'=>'varchar(6)', 'label'=>'Code guichet', 'enabled'=>1, 'visible'=>-2, 'position'=>45),
89
-		'number' =>array('type'=>'varchar(255)', 'label'=>'Number', 'enabled'=>1, 'visible'=>-2, 'position'=>50),
90
-		'cle_rib' =>array('type'=>'varchar(5)', 'label'=>'Cle rib', 'enabled'=>1, 'visible'=>-2, 'position'=>55),
91
-		'bic' =>array('type'=>'varchar(20)', 'label'=>'Bic', 'enabled'=>1, 'visible'=>-2, 'position'=>60),
92
-		'iban_prefix' =>array('type'=>'varchar(34)', 'label'=>'Iban prefix', 'enabled'=>1, 'visible'=>-2, 'position'=>65),
93
-		'domiciliation' =>array('type'=>'varchar(255)', 'label'=>'Domiciliation', 'enabled'=>1, 'visible'=>-2, 'position'=>70),
94
-		'proprio' =>array('type'=>'varchar(60)', 'label'=>'Proprio', 'enabled'=>1, 'visible'=>-2, 'position'=>75),
95
-		'owner_address' =>array('type'=>'text', 'label'=>'Owner address', 'enabled'=>1, 'visible'=>-2, 'position'=>80),
96
-		'default_rib' =>array('type'=>'tinyint(4)', 'label'=>'Default rib', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>85),
97
-		'rum' =>array('type'=>'varchar(32)', 'label'=>'Rum', 'enabled'=>1, 'visible'=>-2, 'position'=>90),
98
-		'date_rum' =>array('type'=>'date', 'label'=>'Date rum', 'enabled'=>1, 'visible'=>-2, 'position'=>95),
99
-		'frstrecur' =>array('type'=>'varchar(16)', 'label'=>'Frstrecur', 'enabled'=>1, 'visible'=>-2, 'position'=>100),
100
-		'type' =>array('type'=>'varchar(32)', 'label'=>'Type', 'enabled'=>1, 'visible'=>-2, 'position'=>110),
101
-		'last_four' =>array('type'=>'varchar(4)', 'label'=>'Last four', 'enabled'=>1, 'visible'=>-2, 'position'=>115),
102
-		'card_type' =>array('type'=>'varchar(255)', 'label'=>'Card type', 'enabled'=>1, 'visible'=>-2, 'position'=>120),
103
-		'cvn' =>array('type'=>'varchar(255)', 'label'=>'Cvn', 'enabled'=>1, 'visible'=>-2, 'position'=>125),
104
-		'exp_date_month' =>array('type'=>'integer', 'label'=>'Exp date month', 'enabled'=>1, 'visible'=>-2, 'position'=>130),
105
-		'exp_date_year' =>array('type'=>'integer', 'label'=>'Exp date year', 'enabled'=>1, 'visible'=>-2, 'position'=>135),
106
-		'country_code' =>array('type'=>'varchar(10)', 'label'=>'Country code', 'enabled'=>1, 'visible'=>-2, 'position'=>140),
107
-		'approved' =>array('type'=>'integer', 'label'=>'Approved', 'enabled'=>1, 'visible'=>-2, 'position'=>145),
108
-		'email' =>array('type'=>'varchar(255)', 'label'=>'Email', 'enabled'=>1, 'visible'=>-2, 'position'=>150),
109
-		'max_total_amount_of_all_payments' =>array('type'=>'double(24,8)', 'label'=>'Max total amount of all payments', 'enabled'=>1, 'visible'=>-2, 'position'=>155),
110
-		'preapproval_key' =>array('type'=>'varchar(255)', 'label'=>'Preapproval key', 'enabled'=>1, 'visible'=>-2, 'position'=>160),
111
-		'total_amount_of_all_payments' =>array('type'=>'double(24,8)', 'label'=>'Total amount of all payments', 'enabled'=>1, 'visible'=>-2, 'position'=>165),
112
-		'stripe_card_ref' =>array('type'=>'varchar(128)', 'label'=>'Stripe card ref', 'enabled'=>1, 'visible'=>-2, 'position'=>170),
113
-		'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>175),
114
-		'starting_date' =>array('type'=>'date', 'label'=>'Starting date', 'enabled'=>1, 'visible'=>-2, 'position'=>180),
115
-		'ending_date' =>array('type'=>'date', 'label'=>'Ending date', 'enabled'=>1, 'visible'=>-2, 'position'=>185),
116
-		'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>20),
117
-		'tms' =>array('type'=>'timestamp', 'label'=>'Tms', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>25),
118
-		'import_key' =>array('type'=>'varchar(14)', 'label'=>'Import key', 'enabled'=>1, 'visible'=>-2, 'position'=>105),
119
-	//'aaa' =>array('type'=>'date', 'label'=>'Ending date', 'enabled'=>0, 'visible'=>-2, 'position'=>185),
120
-	);
121
-
122
-	/**
123
-	 * @var int ID
124
-	 */
125
-	public $rowid;
126
-
127
-	/**
128
-	 * @var int Thirdparty ID
129
-	 */
35
+    /**
36
+     * @var string ID to identify managed object
37
+     */
38
+    public $element = 'companypaymentmode';
39
+
40
+    /**
41
+     * @var string Name of table without prefix where object is stored
42
+     */
43
+    public $table_element = 'societe_rib';
44
+
45
+    /**
46
+     * @var int  Does companypaymentmode support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
47
+     */
48
+    public $ismultientitymanaged = 2;
49
+
50
+    /**
51
+     * @var int  Does companypaymentmode support extrafields ? 0=No, 1=Yes
52
+     */
53
+    public $isextrafieldmanaged = 0;
54
+
55
+    /**
56
+     * @var string String with name of icon for companypaymentmode. Must be the part after the 'object_' into object_companypaymentmode.png
57
+     */
58
+    public $picto = 'generic';
59
+
60
+
61
+    /**
62
+     *  'type' if the field format.
63
+     *  'label' the translation key.
64
+     *  'enabled' is a condition when the field must be managed.
65
+     *  'visible' says if field is visible in list (Examples: 0=Not visible, 1=Visible on list and create/update/view forms, 2=Visible on list only. Using a negative value means field is not shown by default on list but can be selected for viewing)
66
+     *  'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0).
67
+     *  'index' if we want an index in database.
68
+     *  'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...).
69
+     *  'position' is the sort order of field.
70
+     *  'searchall' is 1 if we want to search in this field when making a search from the quick search button.
71
+     *  'isameasure' must be set to 1 if you want to have a total on list for this field. Field type must be summable like integer or double(24,8).
72
+     *  'help' is a string visible as a tooltip on field
73
+     *  'comment' is not used. You can store here any text of your choice. It is not used by application.
74
+     *  'default' is a default value for creation (can still be replaced by the global setup of default values)
75
+     *  'showoncombobox' if field must be shown into the label of combobox
76
+     */
77
+
78
+    // BEGIN MODULEBUILDER PROPERTIES
79
+    /**
80
+     * @var array  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
81
+     */
82
+    public $fields=array(
83
+        'rowid' =>array('type'=>'integer', 'label'=>'Rowid', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>10),
84
+        'fk_soc' =>array('type'=>'integer', 'label'=>'Fk soc', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>15),
85
+        'label' =>array('type'=>'varchar(30)', 'label'=>'Label', 'enabled'=>1, 'visible'=>-2, 'position'=>30),
86
+        'bank' =>array('type'=>'varchar(255)', 'label'=>'Bank', 'enabled'=>1, 'visible'=>-2, 'position'=>35),
87
+        'code_banque' =>array('type'=>'varchar(128)', 'label'=>'Code banque', 'enabled'=>1, 'visible'=>-2, 'position'=>40),
88
+        'code_guichet' =>array('type'=>'varchar(6)', 'label'=>'Code guichet', 'enabled'=>1, 'visible'=>-2, 'position'=>45),
89
+        'number' =>array('type'=>'varchar(255)', 'label'=>'Number', 'enabled'=>1, 'visible'=>-2, 'position'=>50),
90
+        'cle_rib' =>array('type'=>'varchar(5)', 'label'=>'Cle rib', 'enabled'=>1, 'visible'=>-2, 'position'=>55),
91
+        'bic' =>array('type'=>'varchar(20)', 'label'=>'Bic', 'enabled'=>1, 'visible'=>-2, 'position'=>60),
92
+        'iban_prefix' =>array('type'=>'varchar(34)', 'label'=>'Iban prefix', 'enabled'=>1, 'visible'=>-2, 'position'=>65),
93
+        'domiciliation' =>array('type'=>'varchar(255)', 'label'=>'Domiciliation', 'enabled'=>1, 'visible'=>-2, 'position'=>70),
94
+        'proprio' =>array('type'=>'varchar(60)', 'label'=>'Proprio', 'enabled'=>1, 'visible'=>-2, 'position'=>75),
95
+        'owner_address' =>array('type'=>'text', 'label'=>'Owner address', 'enabled'=>1, 'visible'=>-2, 'position'=>80),
96
+        'default_rib' =>array('type'=>'tinyint(4)', 'label'=>'Default rib', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>85),
97
+        'rum' =>array('type'=>'varchar(32)', 'label'=>'Rum', 'enabled'=>1, 'visible'=>-2, 'position'=>90),
98
+        'date_rum' =>array('type'=>'date', 'label'=>'Date rum', 'enabled'=>1, 'visible'=>-2, 'position'=>95),
99
+        'frstrecur' =>array('type'=>'varchar(16)', 'label'=>'Frstrecur', 'enabled'=>1, 'visible'=>-2, 'position'=>100),
100
+        'type' =>array('type'=>'varchar(32)', 'label'=>'Type', 'enabled'=>1, 'visible'=>-2, 'position'=>110),
101
+        'last_four' =>array('type'=>'varchar(4)', 'label'=>'Last four', 'enabled'=>1, 'visible'=>-2, 'position'=>115),
102
+        'card_type' =>array('type'=>'varchar(255)', 'label'=>'Card type', 'enabled'=>1, 'visible'=>-2, 'position'=>120),
103
+        'cvn' =>array('type'=>'varchar(255)', 'label'=>'Cvn', 'enabled'=>1, 'visible'=>-2, 'position'=>125),
104
+        'exp_date_month' =>array('type'=>'integer', 'label'=>'Exp date month', 'enabled'=>1, 'visible'=>-2, 'position'=>130),
105
+        'exp_date_year' =>array('type'=>'integer', 'label'=>'Exp date year', 'enabled'=>1, 'visible'=>-2, 'position'=>135),
106
+        'country_code' =>array('type'=>'varchar(10)', 'label'=>'Country code', 'enabled'=>1, 'visible'=>-2, 'position'=>140),
107
+        'approved' =>array('type'=>'integer', 'label'=>'Approved', 'enabled'=>1, 'visible'=>-2, 'position'=>145),
108
+        'email' =>array('type'=>'varchar(255)', 'label'=>'Email', 'enabled'=>1, 'visible'=>-2, 'position'=>150),
109
+        'max_total_amount_of_all_payments' =>array('type'=>'double(24,8)', 'label'=>'Max total amount of all payments', 'enabled'=>1, 'visible'=>-2, 'position'=>155),
110
+        'preapproval_key' =>array('type'=>'varchar(255)', 'label'=>'Preapproval key', 'enabled'=>1, 'visible'=>-2, 'position'=>160),
111
+        'total_amount_of_all_payments' =>array('type'=>'double(24,8)', 'label'=>'Total amount of all payments', 'enabled'=>1, 'visible'=>-2, 'position'=>165),
112
+        'stripe_card_ref' =>array('type'=>'varchar(128)', 'label'=>'Stripe card ref', 'enabled'=>1, 'visible'=>-2, 'position'=>170),
113
+        'status' =>array('type'=>'integer', 'label'=>'Status', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>175),
114
+        'starting_date' =>array('type'=>'date', 'label'=>'Starting date', 'enabled'=>1, 'visible'=>-2, 'position'=>180),
115
+        'ending_date' =>array('type'=>'date', 'label'=>'Ending date', 'enabled'=>1, 'visible'=>-2, 'position'=>185),
116
+        'datec' =>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'position'=>20),
117
+        'tms' =>array('type'=>'timestamp', 'label'=>'Tms', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>25),
118
+        'import_key' =>array('type'=>'varchar(14)', 'label'=>'Import key', 'enabled'=>1, 'visible'=>-2, 'position'=>105),
119
+    //'aaa' =>array('type'=>'date', 'label'=>'Ending date', 'enabled'=>0, 'visible'=>-2, 'position'=>185),
120
+    );
121
+
122
+    /**
123
+     * @var int ID
124
+     */
125
+    public $rowid;
126
+
127
+    /**
128
+     * @var int Thirdparty ID
129
+     */
130 130
     public $fk_soc;
131 131
 
132
-	/**
132
+    /**
133 133
      * @var string company payment mode label
134 134
      */
135 135
     public $label;
136 136
 
137
-	public $bank;
138
-	public $code_banque;
139
-	public $code_guichet;
140
-	public $number;
141
-	public $cle_rib;
142
-	public $bic;
143
-	public $iban_prefix;
144
-	public $domiciliation;
145
-	public $proprio;
146
-	public $owner_address;
147
-	public $default_rib;
148
-	public $rum;
149
-	public $date_rum;
150
-	public $frstrecur;
151
-	public $type;
152
-	public $last_four;
153
-	public $card_type;
154
-	public $cvn;
155
-	public $exp_date_month;
156
-	public $exp_date_year;
157
-	public $country_code;
158
-	public $approved;
159
-	public $email;
160
-	public $max_total_amount_of_all_payments;
161
-	public $preapproval_key;
162
-	public $total_amount_of_all_payments;
163
-	public $stripe_card_ref;
164
-
165
-	/**
166
-	 * @var int Status
167
-	 */
168
-	public $status;
169
-
170
-	public $starting_date;
171
-	public $ending_date;
172
-	public $datec;
173
-	public $tms;
174
-	public $import_key;
175
-	// END MODULEBUILDER PROPERTIES
176
-
177
-
178
-
179
-	// If this object has a subtable with lines
180
-
181
-	/**
182
-	 * @var int    Name of subtable line
183
-	 */
184
-	//public $table_element_line = 'companypaymentmodedet';
185
-	/**
186
-	 * @var int    Field with ID of parent key if this field has a parent
187
-	 */
188
-	//public $fk_element = 'fk_companypaymentmode';
189
-	/**
190
-	 * @var int    Name of subtable class that manage subtable lines
191
-	 */
192
-	//public $class_element_line = 'CompanyPaymentModeline';
193
-	/**
194
-	 * @var array  Array of child tables (child tables to delete before deleting a record)
195
-	 */
196
-	//protected $childtables=array('companypaymentmodedet');
197
-	/**
198
-	 * @var CompanyPaymentModeLine[]     Array of subtable lines
199
-	 */
200
-	//public $lines = array();
201
-
202
-
203
-
204
-	/**
205
-	 * Constructor
206
-	 *
207
-	 * @param DoliDb $db Database handler
208
-	 */
209
-	public function __construct(DoliDB $db)
210
-	{
211
-		global $conf;
212
-
213
-		$this->db = $db;
214
-
215
-		if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible']=0;
216
-		if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled']=0;
217
-	}
218
-
219
-	/**
220
-	 * Create object into database
221
-	 *
222
-	 * @param  User $user      User that creates
223
-	 * @param  bool $notrigger false=launch triggers after, true=disable triggers
224
-	 * @return int             <0 if KO, Id of created object if OK
225
-	 */
226
-	public function create(User $user, $notrigger = false)
227
-	{
228
-		$idpayment =  $this->createCommon($user, $notrigger);
229
-
230
-		return $idpayment;
231
-	}
232
-
233
-	/**
234
-	 * Clone and object into another one
235
-	 *
236
-	 * @param  	User 	$user      	User that creates
237
-	 * @param  	int 	$fromid     Id of object to clone
238
-	 * @return 	mixed 				New object created, <0 if KO
239
-	 */
240
-	public function createFromClone(User $user, $fromid)
241
-	{
242
-		global $hookmanager, $langs;
243
-	    $error = 0;
244
-
245
-	    dol_syslog(__METHOD__, LOG_DEBUG);
246
-
247
-	    $object = new self($this->db);
248
-
249
-	    $this->db->begin();
250
-
251
-	    // Load source object
252
-	    $object->fetchCommon($fromid);
253
-	    // Reset some properties
254
-	    unset($object->id);
255
-	    unset($object->fk_user_creat);
256
-	    unset($object->import_key);
257
-
258
-	    // Clear fields
259
-	    $object->ref = "copy_of_".$object->ref;
260
-	    $object->title = $langs->trans("CopyOf")." ".$object->title;
261
-	    // ...
262
-
263
-	    // Create clone
264
-		$object->context['createfromclone'] = 'createfromclone';
265
-	    $result = $object->createCommon($user);
266
-	    if ($result < 0) {
267
-	        $error++;
268
-	        $this->error = $object->error;
269
-	        $this->errors = $object->errors;
270
-	    }
271
-
272
-	    // End
273
-	    if (!$error) {
274
-	        $this->db->commit();
275
-	        return $object;
276
-	    } else {
277
-	        $this->db->rollback();
278
-	        return -1;
279
-	    }
280
-	}
281
-
282
-	/**
283
-	 * Load object in memory from the database
284
-	 *
285
-	 * @param 	int    	$id   	Id object
286
-	 * @param 	string 	$ref  	Ref
287
-	 * @param	int		$socid	Id of company to get first default payment mode
288
-	 * @param	string	$type	Filter on type ('ban', 'card', ...)
289
-	 * @return 	int         	<0 if KO, 0 if not found, >0 if OK
290
-	 */
291
-	public function fetch($id, $ref = null, $socid = 0, $type = '')
292
-	{
293
-		$morewhere = '';
294
-		if ($socid) $morewhere.= " AND fk_soc  = ".$this->db->escape($socid)." AND default_rib = 1";
295
-		if ($type)  $morewhere.= " AND type = '".$this->db->escape($type)."'";
296
-
297
-		$result = $this->fetchCommon($id, $ref, $morewhere);
298
-		if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines();
299
-		return $result;
300
-	}
301
-
302
-	/**
303
-	 * Load object lines in memory from the database
304
-	 *
305
-	 * @return int         <0 if KO, 0 if not found, >0 if OK
306
-	 */
307
-	/*public function fetchLines()
137
+    public $bank;
138
+    public $code_banque;
139
+    public $code_guichet;
140
+    public $number;
141
+    public $cle_rib;
142
+    public $bic;
143
+    public $iban_prefix;
144
+    public $domiciliation;
145
+    public $proprio;
146
+    public $owner_address;
147
+    public $default_rib;
148
+    public $rum;
149
+    public $date_rum;
150
+    public $frstrecur;
151
+    public $type;
152
+    public $last_four;
153
+    public $card_type;
154
+    public $cvn;
155
+    public $exp_date_month;
156
+    public $exp_date_year;
157
+    public $country_code;
158
+    public $approved;
159
+    public $email;
160
+    public $max_total_amount_of_all_payments;
161
+    public $preapproval_key;
162
+    public $total_amount_of_all_payments;
163
+    public $stripe_card_ref;
164
+
165
+    /**
166
+     * @var int Status
167
+     */
168
+    public $status;
169
+
170
+    public $starting_date;
171
+    public $ending_date;
172
+    public $datec;
173
+    public $tms;
174
+    public $import_key;
175
+    // END MODULEBUILDER PROPERTIES
176
+
177
+
178
+
179
+    // If this object has a subtable with lines
180
+
181
+    /**
182
+     * @var int    Name of subtable line
183
+     */
184
+    //public $table_element_line = 'companypaymentmodedet';
185
+    /**
186
+     * @var int    Field with ID of parent key if this field has a parent
187
+     */
188
+    //public $fk_element = 'fk_companypaymentmode';
189
+    /**
190
+     * @var int    Name of subtable class that manage subtable lines
191
+     */
192
+    //public $class_element_line = 'CompanyPaymentModeline';
193
+    /**
194
+     * @var array  Array of child tables (child tables to delete before deleting a record)
195
+     */
196
+    //protected $childtables=array('companypaymentmodedet');
197
+    /**
198
+     * @var CompanyPaymentModeLine[]     Array of subtable lines
199
+     */
200
+    //public $lines = array();
201
+
202
+
203
+
204
+    /**
205
+     * Constructor
206
+     *
207
+     * @param DoliDb $db Database handler
208
+     */
209
+    public function __construct(DoliDB $db)
210
+    {
211
+        global $conf;
212
+
213
+        $this->db = $db;
214
+
215
+        if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible']=0;
216
+        if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled']=0;
217
+    }
218
+
219
+    /**
220
+     * Create object into database
221
+     *
222
+     * @param  User $user      User that creates
223
+     * @param  bool $notrigger false=launch triggers after, true=disable triggers
224
+     * @return int             <0 if KO, Id of created object if OK
225
+     */
226
+    public function create(User $user, $notrigger = false)
227
+    {
228
+        $idpayment =  $this->createCommon($user, $notrigger);
229
+
230
+        return $idpayment;
231
+    }
232
+
233
+    /**
234
+     * Clone and object into another one
235
+     *
236
+     * @param  	User 	$user      	User that creates
237
+     * @param  	int 	$fromid     Id of object to clone
238
+     * @return 	mixed 				New object created, <0 if KO
239
+     */
240
+    public function createFromClone(User $user, $fromid)
241
+    {
242
+        global $hookmanager, $langs;
243
+        $error = 0;
244
+
245
+        dol_syslog(__METHOD__, LOG_DEBUG);
246
+
247
+        $object = new self($this->db);
248
+
249
+        $this->db->begin();
250
+
251
+        // Load source object
252
+        $object->fetchCommon($fromid);
253
+        // Reset some properties
254
+        unset($object->id);
255
+        unset($object->fk_user_creat);
256
+        unset($object->import_key);
257
+
258
+        // Clear fields
259
+        $object->ref = "copy_of_".$object->ref;
260
+        $object->title = $langs->trans("CopyOf")." ".$object->title;
261
+        // ...
262
+
263
+        // Create clone
264
+        $object->context['createfromclone'] = 'createfromclone';
265
+        $result = $object->createCommon($user);
266
+        if ($result < 0) {
267
+            $error++;
268
+            $this->error = $object->error;
269
+            $this->errors = $object->errors;
270
+        }
271
+
272
+        // End
273
+        if (!$error) {
274
+            $this->db->commit();
275
+            return $object;
276
+        } else {
277
+            $this->db->rollback();
278
+            return -1;
279
+        }
280
+    }
281
+
282
+    /**
283
+     * Load object in memory from the database
284
+     *
285
+     * @param 	int    	$id   	Id object
286
+     * @param 	string 	$ref  	Ref
287
+     * @param	int		$socid	Id of company to get first default payment mode
288
+     * @param	string	$type	Filter on type ('ban', 'card', ...)
289
+     * @return 	int         	<0 if KO, 0 if not found, >0 if OK
290
+     */
291
+    public function fetch($id, $ref = null, $socid = 0, $type = '')
292
+    {
293
+        $morewhere = '';
294
+        if ($socid) $morewhere.= " AND fk_soc  = ".$this->db->escape($socid)." AND default_rib = 1";
295
+        if ($type)  $morewhere.= " AND type = '".$this->db->escape($type)."'";
296
+
297
+        $result = $this->fetchCommon($id, $ref, $morewhere);
298
+        if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines();
299
+        return $result;
300
+    }
301
+
302
+    /**
303
+     * Load object lines in memory from the database
304
+     *
305
+     * @return int         <0 if KO, 0 if not found, >0 if OK
306
+     */
307
+    /*public function fetchLines()
308 308
 	{
309 309
 		$this->lines=array();
310 310
 
@@ -313,43 +313,43 @@  discard block
 block discarded – undo
313 313
 		return count($this->lines)?1:0;
314 314
 	}*/
315 315
 
316
-	/**
317
-	 * Update object into database
318
-	 *
319
-	 * @param  User $user      User that modifies
320
-	 * @param  bool $notrigger false=launch triggers after, true=disable triggers
321
-	 * @return int             <0 if KO, >0 if OK
322
-	 */
323
-	public function update(User $user, $notrigger = false)
324
-	{
325
-		return $this->updateCommon($user, $notrigger);
326
-	}
327
-
328
-	/**
329
-	 * Delete object in database
330
-	 *
331
-	 * @param User $user       User that deletes
332
-	 * @param bool $notrigger  false=launch triggers after, true=disable triggers
333
-	 * @return int             <0 if KO, >0 if OK
334
-	 */
335
-	public function delete(User $user, $notrigger = false)
336
-	{
337
-		return $this->deleteCommon($user, $notrigger);
338
-	}
339
-
340
-	/**
341
-	 *  Return a link to the object card (with optionaly the picto)
342
-	 *
343
-	 *	@param	int		$withpicto					Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
344
-	 *	@param	string	$option						On what the link point to ('nolink', ...)
316
+    /**
317
+     * Update object into database
318
+     *
319
+     * @param  User $user      User that modifies
320
+     * @param  bool $notrigger false=launch triggers after, true=disable triggers
321
+     * @return int             <0 if KO, >0 if OK
322
+     */
323
+    public function update(User $user, $notrigger = false)
324
+    {
325
+        return $this->updateCommon($user, $notrigger);
326
+    }
327
+
328
+    /**
329
+     * Delete object in database
330
+     *
331
+     * @param User $user       User that deletes
332
+     * @param bool $notrigger  false=launch triggers after, true=disable triggers
333
+     * @return int             <0 if KO, >0 if OK
334
+     */
335
+    public function delete(User $user, $notrigger = false)
336
+    {
337
+        return $this->deleteCommon($user, $notrigger);
338
+    }
339
+
340
+    /**
341
+     *  Return a link to the object card (with optionaly the picto)
342
+     *
343
+     *	@param	int		$withpicto					Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto)
344
+     *	@param	string	$option						On what the link point to ('nolink', ...)
345 345
      *  @param	int  	$notooltip					1=Disable tooltip
346 346
      *  @param  string  $morecss            		Add more css on link
347 347
      *  @param  int     $save_lastsearch_value    	-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
348
-	 *	@return	string								String with URL
349
-	 */
350
-	function getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
351
-	{
352
-		global $db, $conf, $langs;
348
+     *	@return	string								String with URL
349
+     */
350
+    function getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
351
+    {
352
+        global $db, $conf, $langs;
353 353
         global $dolibarr_main_authentication, $dolibarr_main_demo;
354 354
         global $menumanager;
355 355
 
@@ -366,10 +366,10 @@  discard block
 block discarded – undo
366 366
 
367 367
         if ($option != 'nolink')
368 368
         {
369
-	        // Add param to save lastsearch_values or not
370
-	        $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
371
-	        if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
372
-	        if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
369
+            // Add param to save lastsearch_values or not
370
+            $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
371
+            if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
372
+            if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
373 373
         }
374 374
 
375 375
         $linkclose='';
@@ -385,197 +385,197 @@  discard block
 block discarded – undo
385 385
         }
386 386
         else $linkclose = ($morecss?' class="'.$morecss.'"':'');
387 387
 
388
-		$linkstart = '<a href="'.$url.'"';
389
-		$linkstart.=$linkclose.'>';
390
-		$linkend='</a>';
391
-
392
-		$result .= $linkstart;
393
-		if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
394
-		if ($withpicto != 2) $result.= $this->ref;
395
-		$result .= $linkend;
396
-		//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
397
-
398
-		return $result;
399
-	}
400
-
401
-	/**
402
-	 * Set a Payment mode as Default
403
-	 *
404
-	 * @param   int     $id    		Payment mode ID
405
-	 * @param	string	$alltypes	1=The default is for all payment types instead of per type
406
-	 * @return  int             	0 if KO, 1 if OK
407
-	 */
408
-	function setAsDefault($id=0, $alltypes=0)
409
-	{
410
-		$sql1 = "SELECT rowid as id, fk_soc, type FROM ".MAIN_DB_PREFIX."societe_rib";
411
-		$sql1.= " WHERE rowid = ".($id?$id:$this->id);
412
-
413
-		dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
414
-		$result1 = $this->db->query($sql1);
415
-		if ($result1)
416
-		{
417
-			if ($this->db->num_rows($result1) == 0)
418
-			{
419
-				return 0;
420
-			}
421
-			else
422
-			{
423
-				$obj = $this->db->fetch_object($result1);
424
-
425
-				$type = '';
426
-				if (empty($alltypes)) $type = $obj->type;
427
-
428
-				$this->db->begin();
429
-
430
-				$sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0";
431
-				$sql2.= " WHERE default_rib <> 0 AND fk_soc = ".$obj->fk_soc;
432
-				if ($type) $sql2.= " AND type = '".$this->db->escape($type)."'";
433
-				dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
434
-				$result2 = $this->db->query($sql2);
435
-
436
-				$sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1";
437
-				$sql3.= " WHERE rowid = ".$obj->id;
438
-				if ($type) $sql3.= " AND type = '".$this->db->escape($type)."'";
439
-				dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
440
-				$result3 = $this->db->query($sql3);
441
-
442
-				if (!$result2 || !$result3)
443
-				{
444
-					dol_print_error($this->db);
445
-					$this->db->rollback();
446
-					return -1;
447
-				}
448
-				else
449
-				{
450
-					$this->db->commit();
451
-					return 1;
452
-				}
453
-			}
454
-		}
455
-		else
456
-		{
457
-			dol_print_error($this->db);
458
-			return -1;
459
-		}
460
-	}
461
-
462
-	/**
463
-	 *  Retourne le libelle du status d'un user (actif, inactif)
464
-	 *
465
-	 *  @param	int		$mode          0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
466
-	 *  @return	string 			       Label of status
467
-	 */
468
-	function getLibStatut($mode=0)
469
-	{
470
-		return $this->LibStatut($this->status,$mode);
471
-	}
388
+        $linkstart = '<a href="'.$url.'"';
389
+        $linkstart.=$linkclose.'>';
390
+        $linkend='</a>';
391
+
392
+        $result .= $linkstart;
393
+        if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
394
+        if ($withpicto != 2) $result.= $this->ref;
395
+        $result .= $linkend;
396
+        //if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
397
+
398
+        return $result;
399
+    }
400
+
401
+    /**
402
+     * Set a Payment mode as Default
403
+     *
404
+     * @param   int     $id    		Payment mode ID
405
+     * @param	string	$alltypes	1=The default is for all payment types instead of per type
406
+     * @return  int             	0 if KO, 1 if OK
407
+     */
408
+    function setAsDefault($id=0, $alltypes=0)
409
+    {
410
+        $sql1 = "SELECT rowid as id, fk_soc, type FROM ".MAIN_DB_PREFIX."societe_rib";
411
+        $sql1.= " WHERE rowid = ".($id?$id:$this->id);
412
+
413
+        dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
414
+        $result1 = $this->db->query($sql1);
415
+        if ($result1)
416
+        {
417
+            if ($this->db->num_rows($result1) == 0)
418
+            {
419
+                return 0;
420
+            }
421
+            else
422
+            {
423
+                $obj = $this->db->fetch_object($result1);
424
+
425
+                $type = '';
426
+                if (empty($alltypes)) $type = $obj->type;
427
+
428
+                $this->db->begin();
429
+
430
+                $sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0";
431
+                $sql2.= " WHERE default_rib <> 0 AND fk_soc = ".$obj->fk_soc;
432
+                if ($type) $sql2.= " AND type = '".$this->db->escape($type)."'";
433
+                dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
434
+                $result2 = $this->db->query($sql2);
435
+
436
+                $sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1";
437
+                $sql3.= " WHERE rowid = ".$obj->id;
438
+                if ($type) $sql3.= " AND type = '".$this->db->escape($type)."'";
439
+                dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
440
+                $result3 = $this->db->query($sql3);
441
+
442
+                if (!$result2 || !$result3)
443
+                {
444
+                    dol_print_error($this->db);
445
+                    $this->db->rollback();
446
+                    return -1;
447
+                }
448
+                else
449
+                {
450
+                    $this->db->commit();
451
+                    return 1;
452
+                }
453
+            }
454
+        }
455
+        else
456
+        {
457
+            dol_print_error($this->db);
458
+            return -1;
459
+        }
460
+    }
461
+
462
+    /**
463
+     *  Retourne le libelle du status d'un user (actif, inactif)
464
+     *
465
+     *  @param	int		$mode          0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
466
+     *  @return	string 			       Label of status
467
+     */
468
+    function getLibStatut($mode=0)
469
+    {
470
+        return $this->LibStatut($this->status,$mode);
471
+    }
472 472
 
473 473
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
474
-	/**
475
-	 *  Return the status
476
-	 *
477
-	 *  @param	int		$status        	Id status
478
-	 *  @param  int		$mode          	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
479
-	 *  @return string 			       	Label of status
480
-	 */
481
-	static function LibStatut($status,$mode=0)
482
-	{
474
+    /**
475
+     *  Return the status
476
+     *
477
+     *  @param	int		$status        	Id status
478
+     *  @param  int		$mode          	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
479
+     *  @return string 			       	Label of status
480
+     */
481
+    static function LibStatut($status,$mode=0)
482
+    {
483 483
         // phpcs:enable
484
-		global $langs;
485
-
486
-		if ($mode == 0 || $mode == 1)
487
-		{
488
-			if ($status == 1) return $langs->trans('Enabled');
489
-			if ($status == 0) return $langs->trans('Disabled');
490
-		}
491
-		elseif ($mode == 2)
492
-		{
493
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
494
-			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
495
-		}
496
-		elseif ($mode == 3)
497
-		{
498
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4');
499
-			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5');
500
-		}
501
-		elseif ($mode == 4)
502
-		{
503
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
504
-			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
505
-		}
506
-		elseif ($mode == 5)
507
-		{
508
-			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
509
-			if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
510
-		}
511
-		elseif ($mode == 6)
512
-		{
513
-			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
514
-			if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
515
-		}
516
-	}
517
-
518
-	/**
519
-	 *	Charge les informations d'ordre info dans l'objet commande
520
-	 *
521
-	 *	@param  int		$id       Id of order
522
-	 *	@return	void
523
-	 */
524
-	function info($id)
525
-	{
526
-		$sql = 'SELECT rowid, date_creation as datec, tms as datem,';
527
-		$sql.= ' fk_user_creat, fk_user_modif';
528
-		$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
529
-		$sql.= ' WHERE t.rowid = '.$id;
530
-		$result=$this->db->query($sql);
531
-		if ($result)
532
-		{
533
-			if ($this->db->num_rows($result))
534
-			{
535
-				$obj = $this->db->fetch_object($result);
536
-				$this->id = $obj->rowid;
537
-				if ($obj->fk_user_author)
538
-				{
539
-					$cuser = new User($this->db);
540
-					$cuser->fetch($obj->fk_user_author);
541
-					$this->user_creation   = $cuser;
542
-				}
543
-
544
-				if ($obj->fk_user_valid)
545
-				{
546
-					$vuser = new User($this->db);
547
-					$vuser->fetch($obj->fk_user_valid);
548
-					$this->user_validation = $vuser;
549
-				}
550
-
551
-				if ($obj->fk_user_cloture)
552
-				{
553
-					$cluser = new User($this->db);
554
-					$cluser->fetch($obj->fk_user_cloture);
555
-					$this->user_cloture   = $cluser;
556
-				}
557
-
558
-				$this->date_creation     = $this->db->jdate($obj->datec);
559
-				$this->date_modification = $this->db->jdate($obj->datem);
560
-				$this->date_validation   = $this->db->jdate($obj->datev);
561
-			}
562
-
563
-			$this->db->free($result);
564
-		}
565
-		else
566
-		{
567
-			dol_print_error($this->db);
568
-		}
569
-	}
570
-
571
-	/**
572
-	 * Initialise object with example values
573
-	 * Id must be 0 if object instance is a specimen
574
-	 *
575
-	 * @return void
576
-	 */
577
-	public function initAsSpecimen()
578
-	{
579
-		$this->initAsSpecimenCommon();
580
-	}
484
+        global $langs;
485
+
486
+        if ($mode == 0 || $mode == 1)
487
+        {
488
+            if ($status == 1) return $langs->trans('Enabled');
489
+            if ($status == 0) return $langs->trans('Disabled');
490
+        }
491
+        elseif ($mode == 2)
492
+        {
493
+            if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
494
+            if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
495
+        }
496
+        elseif ($mode == 3)
497
+        {
498
+            if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4');
499
+            if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5');
500
+        }
501
+        elseif ($mode == 4)
502
+        {
503
+            if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
504
+            if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
505
+        }
506
+        elseif ($mode == 5)
507
+        {
508
+            if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
509
+            if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
510
+        }
511
+        elseif ($mode == 6)
512
+        {
513
+            if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
514
+            if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
515
+        }
516
+    }
517
+
518
+    /**
519
+     *	Charge les informations d'ordre info dans l'objet commande
520
+     *
521
+     *	@param  int		$id       Id of order
522
+     *	@return	void
523
+     */
524
+    function info($id)
525
+    {
526
+        $sql = 'SELECT rowid, date_creation as datec, tms as datem,';
527
+        $sql.= ' fk_user_creat, fk_user_modif';
528
+        $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
529
+        $sql.= ' WHERE t.rowid = '.$id;
530
+        $result=$this->db->query($sql);
531
+        if ($result)
532
+        {
533
+            if ($this->db->num_rows($result))
534
+            {
535
+                $obj = $this->db->fetch_object($result);
536
+                $this->id = $obj->rowid;
537
+                if ($obj->fk_user_author)
538
+                {
539
+                    $cuser = new User($this->db);
540
+                    $cuser->fetch($obj->fk_user_author);
541
+                    $this->user_creation   = $cuser;
542
+                }
543
+
544
+                if ($obj->fk_user_valid)
545
+                {
546
+                    $vuser = new User($this->db);
547
+                    $vuser->fetch($obj->fk_user_valid);
548
+                    $this->user_validation = $vuser;
549
+                }
550
+
551
+                if ($obj->fk_user_cloture)
552
+                {
553
+                    $cluser = new User($this->db);
554
+                    $cluser->fetch($obj->fk_user_cloture);
555
+                    $this->user_cloture   = $cluser;
556
+                }
557
+
558
+                $this->date_creation     = $this->db->jdate($obj->datec);
559
+                $this->date_modification = $this->db->jdate($obj->datem);
560
+                $this->date_validation   = $this->db->jdate($obj->datev);
561
+            }
562
+
563
+            $this->db->free($result);
564
+        }
565
+        else
566
+        {
567
+            dol_print_error($this->db);
568
+        }
569
+    }
570
+
571
+    /**
572
+     * Initialise object with example values
573
+     * Id must be 0 if object instance is a specimen
574
+     *
575
+     * @return void
576
+     */
577
+    public function initAsSpecimen()
578
+    {
579
+        $this->initAsSpecimenCommon();
580
+    }
581 581
 }
Please login to merge, or discard this patch.
Spacing   +53 added lines, -53 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
  */
24 24
 
25 25
 // Put here all includes required by your class file
26
-require_once DOL_DOCUMENT_ROOT . '/core/class/commonobject.class.php';
26
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
27 27
 //require_once DOL_DOCUMENT_ROOT . '/societe/class/societe.class.php';
28 28
 //require_once DOL_DOCUMENT_ROOT . '/product/class/product.class.php';
29 29
 
@@ -79,7 +79,7 @@  discard block
 block discarded – undo
79 79
 	/**
80 80
 	 * @var array  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
81 81
 	 */
82
-	public $fields=array(
82
+	public $fields = array(
83 83
 		'rowid' =>array('type'=>'integer', 'label'=>'Rowid', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>10),
84 84
 		'fk_soc' =>array('type'=>'integer', 'label'=>'Fk soc', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>15),
85 85
 		'label' =>array('type'=>'varchar(30)', 'label'=>'Label', 'enabled'=>1, 'visible'=>-2, 'position'=>30),
@@ -212,8 +212,8 @@  discard block
 block discarded – undo
212 212
 
213 213
 		$this->db = $db;
214 214
 
215
-		if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible']=0;
216
-		if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled']=0;
215
+		if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible'] = 0;
216
+		if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled'] = 0;
217 217
 	}
218 218
 
219 219
 	/**
@@ -225,7 +225,7 @@  discard block
 block discarded – undo
225 225
 	 */
226 226
 	public function create(User $user, $notrigger = false)
227 227
 	{
228
-		$idpayment =  $this->createCommon($user, $notrigger);
228
+		$idpayment = $this->createCommon($user, $notrigger);
229 229
 
230 230
 		return $idpayment;
231 231
 	}
@@ -291,11 +291,11 @@  discard block
 block discarded – undo
291 291
 	public function fetch($id, $ref = null, $socid = 0, $type = '')
292 292
 	{
293 293
 		$morewhere = '';
294
-		if ($socid) $morewhere.= " AND fk_soc  = ".$this->db->escape($socid)." AND default_rib = 1";
295
-		if ($type)  $morewhere.= " AND type = '".$this->db->escape($type)."'";
294
+		if ($socid) $morewhere .= " AND fk_soc  = ".$this->db->escape($socid)." AND default_rib = 1";
295
+		if ($type)  $morewhere .= " AND type = '".$this->db->escape($type)."'";
296 296
 
297 297
 		$result = $this->fetchCommon($id, $ref, $morewhere);
298
-		if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines();
298
+		if ($result > 0 && !empty($this->table_element_line)) $this->fetchLines();
299 299
 		return $result;
300 300
 	}
301 301
 
@@ -347,51 +347,51 @@  discard block
 block discarded – undo
347 347
      *  @param  int     $save_lastsearch_value    	-1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
348 348
 	 *	@return	string								String with URL
349 349
 	 */
350
-	function getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1)
350
+	function getNomUrl($withpicto = 0, $option = '', $notooltip = 0, $morecss = '', $save_lastsearch_value = -1)
351 351
 	{
352 352
 		global $db, $conf, $langs;
353 353
         global $dolibarr_main_authentication, $dolibarr_main_demo;
354 354
         global $menumanager;
355 355
 
356
-        if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
356
+        if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
357 357
 
358 358
         $result = '';
359 359
         $companylink = '';
360 360
 
361
-        $label = '<u>' . $langs->trans("CompanyPaymentMode") . '</u>';
362
-        $label.= '<br>';
363
-        $label.= '<b>' . $langs->trans('Ref') . ':</b> ' . $this->ref;
361
+        $label = '<u>'.$langs->trans("CompanyPaymentMode").'</u>';
362
+        $label .= '<br>';
363
+        $label .= '<b>'.$langs->trans('Ref').':</b> '.$this->ref;
364 364
 
365
-        $url = dol_buildpath('/monmodule/companypaymentmode_card.php',1).'?id='.$this->id;
365
+        $url = dol_buildpath('/monmodule/companypaymentmode_card.php', 1).'?id='.$this->id;
366 366
 
367 367
         if ($option != 'nolink')
368 368
         {
369 369
 	        // Add param to save lastsearch_values or not
370
-	        $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
371
-	        if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
372
-	        if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
370
+	        $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
371
+	        if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
372
+	        if ($add_save_lastsearch_values) $url .= '&save_lastsearch_values=1';
373 373
         }
374 374
 
375
-        $linkclose='';
375
+        $linkclose = '';
376 376
         if (empty($notooltip))
377 377
         {
378
-            if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
378
+            if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
379 379
             {
380
-                $label=$langs->trans("ShowCompanyPaymentMode");
381
-                $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
380
+                $label = $langs->trans("ShowCompanyPaymentMode");
381
+                $linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
382 382
             }
383
-            $linkclose.=' title="'.dol_escape_htmltag($label, 1).'"';
384
-            $linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
383
+            $linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
384
+            $linkclose .= ' class="classfortooltip'.($morecss ? ' '.$morecss : '').'"';
385 385
         }
386
-        else $linkclose = ($morecss?' class="'.$morecss.'"':'');
386
+        else $linkclose = ($morecss ? ' class="'.$morecss.'"' : '');
387 387
 
388 388
 		$linkstart = '<a href="'.$url.'"';
389
-		$linkstart.=$linkclose.'>';
390
-		$linkend='</a>';
389
+		$linkstart .= $linkclose.'>';
390
+		$linkend = '</a>';
391 391
 
392 392
 		$result .= $linkstart;
393
-		if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
394
-		if ($withpicto != 2) $result.= $this->ref;
393
+		if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
394
+		if ($withpicto != 2) $result .= $this->ref;
395 395
 		$result .= $linkend;
396 396
 		//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
397 397
 
@@ -405,10 +405,10 @@  discard block
 block discarded – undo
405 405
 	 * @param	string	$alltypes	1=The default is for all payment types instead of per type
406 406
 	 * @return  int             	0 if KO, 1 if OK
407 407
 	 */
408
-	function setAsDefault($id=0, $alltypes=0)
408
+	function setAsDefault($id = 0, $alltypes = 0)
409 409
 	{
410 410
 		$sql1 = "SELECT rowid as id, fk_soc, type FROM ".MAIN_DB_PREFIX."societe_rib";
411
-		$sql1.= " WHERE rowid = ".($id?$id:$this->id);
411
+		$sql1 .= " WHERE rowid = ".($id ? $id : $this->id);
412 412
 
413 413
 		dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
414 414
 		$result1 = $this->db->query($sql1);
@@ -428,14 +428,14 @@  discard block
 block discarded – undo
428 428
 				$this->db->begin();
429 429
 
430 430
 				$sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0";
431
-				$sql2.= " WHERE default_rib <> 0 AND fk_soc = ".$obj->fk_soc;
432
-				if ($type) $sql2.= " AND type = '".$this->db->escape($type)."'";
431
+				$sql2 .= " WHERE default_rib <> 0 AND fk_soc = ".$obj->fk_soc;
432
+				if ($type) $sql2 .= " AND type = '".$this->db->escape($type)."'";
433 433
 				dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
434 434
 				$result2 = $this->db->query($sql2);
435 435
 
436 436
 				$sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1";
437
-				$sql3.= " WHERE rowid = ".$obj->id;
438
-				if ($type) $sql3.= " AND type = '".$this->db->escape($type)."'";
437
+				$sql3 .= " WHERE rowid = ".$obj->id;
438
+				if ($type) $sql3 .= " AND type = '".$this->db->escape($type)."'";
439 439
 				dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
440 440
 				$result3 = $this->db->query($sql3);
441 441
 
@@ -465,9 +465,9 @@  discard block
 block discarded – undo
465 465
 	 *  @param	int		$mode          0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
466 466
 	 *  @return	string 			       Label of status
467 467
 	 */
468
-	function getLibStatut($mode=0)
468
+	function getLibStatut($mode = 0)
469 469
 	{
470
-		return $this->LibStatut($this->status,$mode);
470
+		return $this->LibStatut($this->status, $mode);
471 471
 	}
472 472
 
473 473
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -478,7 +478,7 @@  discard block
 block discarded – undo
478 478
 	 *  @param  int		$mode          	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto, 6=Long label + Picto
479 479
 	 *  @return string 			       	Label of status
480 480
 	 */
481
-	static function LibStatut($status,$mode=0)
481
+	static function LibStatut($status, $mode = 0)
482 482
 	{
483 483
         // phpcs:enable
484 484
 		global $langs;
@@ -490,28 +490,28 @@  discard block
 block discarded – undo
490 490
 		}
491 491
 		elseif ($mode == 2)
492 492
 		{
493
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
494
-			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
493
+			if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4').' '.$langs->trans('Enabled');
494
+			if ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5').' '.$langs->trans('Disabled');
495 495
 		}
496 496
 		elseif ($mode == 3)
497 497
 		{
498
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4');
499
-			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5');
498
+			if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4');
499
+			if ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5');
500 500
 		}
501 501
 		elseif ($mode == 4)
502 502
 		{
503
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
504
-			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
503
+			if ($status == 1) return img_picto($langs->trans('Enabled'), 'statut4').' '.$langs->trans('Enabled');
504
+			if ($status == 0) return img_picto($langs->trans('Disabled'), 'statut5').' '.$langs->trans('Disabled');
505 505
 		}
506 506
 		elseif ($mode == 5)
507 507
 		{
508
-			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
509
-			if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
508
+			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'), 'statut4');
509
+			if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'), 'statut5');
510 510
 		}
511 511
 		elseif ($mode == 6)
512 512
 		{
513
-			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
514
-			if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
513
+			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'), 'statut4');
514
+			if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'), 'statut5');
515 515
 		}
516 516
 	}
517 517
 
@@ -524,10 +524,10 @@  discard block
 block discarded – undo
524 524
 	function info($id)
525 525
 	{
526 526
 		$sql = 'SELECT rowid, date_creation as datec, tms as datem,';
527
-		$sql.= ' fk_user_creat, fk_user_modif';
528
-		$sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
529
-		$sql.= ' WHERE t.rowid = '.$id;
530
-		$result=$this->db->query($sql);
527
+		$sql .= ' fk_user_creat, fk_user_modif';
528
+		$sql .= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t';
529
+		$sql .= ' WHERE t.rowid = '.$id;
530
+		$result = $this->db->query($sql);
531 531
 		if ($result)
532 532
 		{
533 533
 			if ($this->db->num_rows($result))
@@ -538,7 +538,7 @@  discard block
 block discarded – undo
538 538
 				{
539 539
 					$cuser = new User($this->db);
540 540
 					$cuser->fetch($obj->fk_user_author);
541
-					$this->user_creation   = $cuser;
541
+					$this->user_creation = $cuser;
542 542
 				}
543 543
 
544 544
 				if ($obj->fk_user_valid)
@@ -552,7 +552,7 @@  discard block
 block discarded – undo
552 552
 				{
553 553
 					$cluser = new User($this->db);
554 554
 					$cluser->fetch($obj->fk_user_cloture);
555
-					$this->user_cloture   = $cluser;
555
+					$this->user_cloture = $cluser;
556 556
 				}
557 557
 
558 558
 				$this->date_creation     = $this->db->jdate($obj->datec);
Please login to merge, or discard this patch.
Braces   +87 added lines, -44 removed lines patch added patch discarded remove patch
@@ -212,8 +212,12 @@  discard block
 block discarded – undo
212 212
 
213 213
 		$this->db = $db;
214 214
 
215
-		if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) $this->fields['rowid']['visible']=0;
216
-		if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) $this->fields['entity']['enabled']=0;
215
+		if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID) && isset($this->fields['rowid'])) {
216
+		    $this->fields['rowid']['visible']=0;
217
+		}
218
+		if (empty($conf->multicompany->enabled) && isset($this->fields['entity'])) {
219
+		    $this->fields['entity']['enabled']=0;
220
+		}
217 221
 	}
218 222
 
219 223
 	/**
@@ -291,11 +295,17 @@  discard block
 block discarded – undo
291 295
 	public function fetch($id, $ref = null, $socid = 0, $type = '')
292 296
 	{
293 297
 		$morewhere = '';
294
-		if ($socid) $morewhere.= " AND fk_soc  = ".$this->db->escape($socid)." AND default_rib = 1";
295
-		if ($type)  $morewhere.= " AND type = '".$this->db->escape($type)."'";
298
+		if ($socid) {
299
+		    $morewhere.= " AND fk_soc  = ".$this->db->escape($socid)." AND default_rib = 1";
300
+		}
301
+		if ($type) {
302
+		    $morewhere.= " AND type = '".$this->db->escape($type)."'";
303
+		}
296 304
 
297 305
 		$result = $this->fetchCommon($id, $ref, $morewhere);
298
-		if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines();
306
+		if ($result > 0 && ! empty($this->table_element_line)) {
307
+		    $this->fetchLines();
308
+		}
299 309
 		return $result;
300 310
 	}
301 311
 
@@ -353,7 +363,10 @@  discard block
 block discarded – undo
353 363
         global $dolibarr_main_authentication, $dolibarr_main_demo;
354 364
         global $menumanager;
355 365
 
356
-        if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
366
+        if (! empty($conf->dol_no_mouse_hover)) {
367
+            $notooltip=1;
368
+        }
369
+        // Force disable tooltips
357 370
 
358 371
         $result = '';
359 372
         $companylink = '';
@@ -368,8 +381,12 @@  discard block
 block discarded – undo
368 381
         {
369 382
 	        // Add param to save lastsearch_values or not
370 383
 	        $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
371
-	        if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
372
-	        if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1';
384
+	        if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) {
385
+	            $add_save_lastsearch_values=1;
386
+	        }
387
+	        if ($add_save_lastsearch_values) {
388
+	            $url.='&save_lastsearch_values=1';
389
+	        }
373 390
         }
374 391
 
375 392
         $linkclose='';
@@ -382,16 +399,21 @@  discard block
 block discarded – undo
382 399
             }
383 400
             $linkclose.=' title="'.dol_escape_htmltag($label, 1).'"';
384 401
             $linkclose.=' class="classfortooltip'.($morecss?' '.$morecss:'').'"';
402
+        } else {
403
+            $linkclose = ($morecss?' class="'.$morecss.'"':'');
385 404
         }
386
-        else $linkclose = ($morecss?' class="'.$morecss.'"':'');
387 405
 
388 406
 		$linkstart = '<a href="'.$url.'"';
389 407
 		$linkstart.=$linkclose.'>';
390 408
 		$linkend='</a>';
391 409
 
392 410
 		$result .= $linkstart;
393
-		if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
394
-		if ($withpicto != 2) $result.= $this->ref;
411
+		if ($withpicto) {
412
+		    $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip"'), 0, 0, $notooltip?0:1);
413
+		}
414
+		if ($withpicto != 2) {
415
+		    $result.= $this->ref;
416
+		}
395 417
 		$result .= $linkend;
396 418
 		//if ($withpicto != 2) $result.=(($addlabel && $this->label) ? $sep . dol_trunc($this->label, ($addlabel > 1 ? $addlabel : 0)) : '');
397 419
 
@@ -417,25 +439,30 @@  discard block
 block discarded – undo
417 439
 			if ($this->db->num_rows($result1) == 0)
418 440
 			{
419 441
 				return 0;
420
-			}
421
-			else
442
+			} else
422 443
 			{
423 444
 				$obj = $this->db->fetch_object($result1);
424 445
 
425 446
 				$type = '';
426
-				if (empty($alltypes)) $type = $obj->type;
447
+				if (empty($alltypes)) {
448
+				    $type = $obj->type;
449
+				}
427 450
 
428 451
 				$this->db->begin();
429 452
 
430 453
 				$sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0";
431 454
 				$sql2.= " WHERE default_rib <> 0 AND fk_soc = ".$obj->fk_soc;
432
-				if ($type) $sql2.= " AND type = '".$this->db->escape($type)."'";
455
+				if ($type) {
456
+				    $sql2.= " AND type = '".$this->db->escape($type)."'";
457
+				}
433 458
 				dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
434 459
 				$result2 = $this->db->query($sql2);
435 460
 
436 461
 				$sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1";
437 462
 				$sql3.= " WHERE rowid = ".$obj->id;
438
-				if ($type) $sql3.= " AND type = '".$this->db->escape($type)."'";
463
+				if ($type) {
464
+				    $sql3.= " AND type = '".$this->db->escape($type)."'";
465
+				}
439 466
 				dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG);
440 467
 				$result3 = $this->db->query($sql3);
441 468
 
@@ -444,15 +471,13 @@  discard block
 block discarded – undo
444 471
 					dol_print_error($this->db);
445 472
 					$this->db->rollback();
446 473
 					return -1;
447
-				}
448
-				else
474
+				} else
449 475
 				{
450 476
 					$this->db->commit();
451 477
 					return 1;
452 478
 				}
453 479
 			}
454
-		}
455
-		else
480
+		} else
456 481
 		{
457 482
 			dol_print_error($this->db);
458 483
 			return -1;
@@ -485,33 +510,52 @@  discard block
 block discarded – undo
485 510
 
486 511
 		if ($mode == 0 || $mode == 1)
487 512
 		{
488
-			if ($status == 1) return $langs->trans('Enabled');
489
-			if ($status == 0) return $langs->trans('Disabled');
490
-		}
491
-		elseif ($mode == 2)
513
+			if ($status == 1) {
514
+			    return $langs->trans('Enabled');
515
+			}
516
+			if ($status == 0) {
517
+			    return $langs->trans('Disabled');
518
+			}
519
+		} elseif ($mode == 2)
492 520
 		{
493
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
494
-			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
495
-		}
496
-		elseif ($mode == 3)
521
+			if ($status == 1) {
522
+			    return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
523
+			}
524
+			if ($status == 0) {
525
+			    return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
526
+			}
527
+		} elseif ($mode == 3)
497 528
 		{
498
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4');
499
-			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5');
500
-		}
501
-		elseif ($mode == 4)
529
+			if ($status == 1) {
530
+			    return img_picto($langs->trans('Enabled'),'statut4');
531
+			}
532
+			if ($status == 0) {
533
+			    return img_picto($langs->trans('Disabled'),'statut5');
534
+			}
535
+		} elseif ($mode == 4)
502 536
 		{
503
-			if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
504
-			if ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
505
-		}
506
-		elseif ($mode == 5)
537
+			if ($status == 1) {
538
+			    return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled');
539
+			}
540
+			if ($status == 0) {
541
+			    return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled');
542
+			}
543
+		} elseif ($mode == 5)
507 544
 		{
508
-			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
509
-			if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
510
-		}
511
-		elseif ($mode == 6)
545
+			if ($status == 1) {
546
+			    return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
547
+			}
548
+			if ($status == 0) {
549
+			    return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
550
+			}
551
+		} elseif ($mode == 6)
512 552
 		{
513
-			if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
514
-			if ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
553
+			if ($status == 1) {
554
+			    return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4');
555
+			}
556
+			if ($status == 0) {
557
+			    return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5');
558
+			}
515 559
 		}
516 560
 	}
517 561
 
@@ -561,8 +605,7 @@  discard block
 block discarded – undo
561 605
 			}
562 606
 
563 607
 			$this->db->free($result);
564
-		}
565
-		else
608
+		} else
566 609
 		{
567 610
 			dol_print_error($this->db);
568 611
 		}
Please login to merge, or discard this patch.
dolibarr/htdocs/societe/class/societe.class.php 3 patches
Indentation   +3920 added lines, -3920 removed lines patch added patch discarded remove patch
@@ -42,313 +42,313 @@  discard block
 block discarded – undo
42 42
  */
43 43
 class Societe extends CommonObject
44 44
 {
45
-	/**
46
-	 * @var string ID to identify managed object
47
-	 */
48
-	public $element='societe';
49
-
50
-	/**
51
-	 * @var string Name of table without prefix where object is stored
52
-	 */
53
-	public $table_element = 'societe';
54
-
55
-	/**
56
-	 * @var int Field with ID of parent key if this field has a parent
57
-	 */
58
-	public $fk_element='fk_soc';
59
-
60
-	public $fieldsforcombobox='nom,name_alias';
61
-	protected $childtables=array("supplier_proposal"=>'SupplierProposal',"propal"=>'Proposal',"commande"=>'Order',"facture"=>'Invoice',"facture_rec"=>'RecurringInvoiceTemplate',"contrat"=>'Contract',"fichinter"=>'Fichinter',"facture_fourn"=>'SupplierInvoice',"commande_fournisseur"=>'SupplierOrder',"projet"=>'Project',"expedition"=>'Shipment',"prelevement_lignes"=>'DirectDebitRecord');    // To test if we can delete object
62
-	protected $childtablesoncascade=array("societe_prices", "societe_log", "societe_address", "product_fournisseur_price", "product_customer_price_log", "product_customer_price", "socpeople", "adherent", "societe_rib", "societe_remise", "societe_remise_except", "societe_commerciaux", "categorie", "notify", "notify_def", "actioncomm");
63
-	public $picto = 'company';
64
-
65
-	/**
66
-	 * 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
67
-	 * @var int
68
-	 */
69
-	public $ismultientitymanaged = 1;
70
-
71
-	/**
72
-	 * 0=Default, 1=View may be restricted to sales representative only if no permission to see all or to company of external user if external user
73
-	 * @var integer
74
-	 */
75
-	public $restrictiononfksoc = 1;
76
-
77
-
78
-	// BEGIN MODULEBUILDER PROPERTIES
79
-	/**
80
-	 * @var array  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
81
-	 */
82
-	public $fields=array(
83
-		'rowid'         =>array('type'=>'integer',      'label'=>'TechnicalID',      'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'index'=>1, 'position'=>1, 'comment'=>'Id'),
84
-		'nom'           =>array('type'=>'varchar(128)', 'label'=>'Name',             'enabled'=>1, 'visible'=>1,  'notnull'=>1,  'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
85
-		'name_alias'    =>array('type'=>'varchar(128)', 'label'=>'Name',             'enabled'=>1, 'visible'=>1,  'notnull'=>1,  'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
86
-		'entity'        =>array('type'=>'integer',      'label'=>'Entity',           'enabled'=>1, 'visible'=>0,  'default'=>1,  'notnull'=>1,  'index'=>1, 'position'=>20),
87
-		'note_public'   =>array('type'=>'text',			'label'=>'NotePublic',		 'enabled'=>1, 'visible'=>0,  'position'=>60),
88
-		'note_private'  =>array('type'=>'text',			'label'=>'NotePrivate',		 'enabled'=>1, 'visible'=>0,  'position'=>61),
89
-		'datec'			=>array('type'=>'datetime',     'label'=>'DateCreation',     'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'position'=>500),
90
-		'tms'           =>array('type'=>'timestamp',    'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'position'=>501),
91
-		//'date_valid'    =>array('type'=>'datetime',     'label'=>'DateCreation',     'enabled'=>1, 'visible'=>-2, 'position'=>502),
92
-		'fk_user_creat' =>array('type'=>'integer',      'label'=>'UserAuthor',       'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'position'=>510),
93
-		'fk_user_modif' =>array('type'=>'integer',      'label'=>'UserModif',        'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511),
94
-		//'fk_user_valid' =>array('type'=>'integer',      'label'=>'UserValidation',        'enabled'=>1, 'visible'=>-1, 'position'=>512),
95
-		'import_key'    =>array('type'=>'varchar(14)',  'label'=>'ImportId',         'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>1,  'position'=>1000),
96
-	);
97
-
98
-
99
-	/**
100
-	 * @var int Entity
101
-	 */
102
-	public $entity;
103
-
104
-	/**
105
-	 * Thirdparty name
106
-	 * @var string
107
-	 * @deprecated Use $name instead
108
-	 * @see $name
109
-	 */
110
-	public $nom;
111
-
112
-	/**
113
-	 * @var string name
114
-	 */
115
-	public $name;
116
-
117
-	/**
118
-	 * Alias names (commercial, trademark or alias names)
119
-	 * @var string
120
-	 */
121
-	public $name_alias;
122
-
123
-	public $particulier;
124
-
125
-	/**
126
-	 * @var string Address
127
-	 */
128
-	public $address;
129
-
130
-	public $zip;
131
-	public $town;
132
-
133
-	/**
134
-	 * Thirdparty status : 0=activity ceased, 1= in activity
135
-	 * @var int
136
-	 */
137
-	public $status=1;
138
-
139
-	/**
140
-	 * Id of department
141
-	 * @var int
142
-	 */
143
-	public $state_id;
144
-	public $state_code;
145
-	public $state;
146
-
147
-	/**
148
-	 * Id of region
149
-	 * @var int
150
-	 */
151
-	public $region_code;
152
-	public $region;
153
-
154
-	/**
155
-	 * State code
156
-	 * @var string
157
-	 * @deprecated Use state_code instead
158
-	 * @see $state_code
159
-	 */
160
-	public $departement_code;
161
-
162
-	/**
163
-	 * @var string
164
-	 * @deprecated Use state instead
165
-	 * @see $state
166
-	 */
167
-	public $departement;
168
-
169
-	/**
170
-	 * @var string
171
-	 * @deprecated Use country instead
172
-	 * @see $country
173
-	 */
174
-	public $pays;
175
-
176
-	/**
177
-	 * Phone number
178
-	 * @var string
179
-	 */
180
-	public $phone;
181
-	/**
182
-	 * Fax number
183
-	 * @var string
184
-	 */
185
-	public $fax;
186
-	/**
187
-	 * Email
188
-	 * @var string
189
-	 */
190
-	public $email;
191
-	/**
192
-	 * Skype username
193
-	 * @var string
194
-	 */
195
-	public $skype;
196
-	/**
197
-	 * Twitter username
198
-	 * @var string
199
-	 */
200
-	public $twitter;
201
-	/**
202
-	 * Facebook username
203
-	 * @var string
204
-	 */
205
-	public $facebook;
206
-	/**
207
-	 * Webpage
208
-	 * @var string
209
-	 */
210
-	public $url;
211
-
212
-	//! barcode
213
-	/**
214
-	 * Barcode value
215
-	 * @var string
216
-	 */
217
-	public $barcode;
218
-
219
-	// 6 professional id (usage depends on country)
220
-
221
-	/**
222
-	 * Professional ID 1 (Ex: Siren in France)
223
-	 * @var string
224
-	 */
225
-	public $idprof1;
226
-
227
-	/**
228
-	 * Professional ID 2 (Ex: Siret in France)
229
-	 * @var string
230
-	 */
231
-	public $idprof2;
232
-
233
-	/**
234
-	 * Professional ID 3 (Ex: Ape in France)
235
-	 * @var string
236
-	 */
237
-	public $idprof3;
238
-
239
-	/**
240
-	 * Professional ID 4 (Ex: RCS in France)
241
-	 * @var string
242
-	 */
243
-	public $idprof4;
244
-
245
-	/**
246
-	 * Professional ID 5
247
-	 * @var string
248
-	 */
249
-	public $idprof5;
250
-
251
-	/**
252
-	 * Professional ID 6
253
-	 * @var string
254
-	 */
255
-	public $idprof6;
256
-
257
-	public $prefix_comm;
258
-
259
-	public $tva_assuj=1;
260
-	/**
261
-	 * Intracommunitary VAT ID
262
-	 * @var string
263
-	 */
264
-	public $tva_intra;
265
-
266
-	// Local taxes
267
-	public $localtax1_assuj;
268
-	public $localtax1_value;
269
-	public $localtax2_assuj;
270
-	public $localtax2_value;
271
-
272
-	public $managers;
273
-	public $capital;
274
-	public $typent_id=0;
275
-	public $typent_code;
276
-	public $effectif;
277
-	public $effectif_id=0;
278
-	public $forme_juridique_code;
279
-	public $forme_juridique=0;
280
-
281
-	public $remise_percent;
282
-	public $remise_supplier_percent;
283
-	public $mode_reglement_supplier_id;
284
-	public $cond_reglement_supplier_id;
285
-
286
-	/**
45
+    /**
46
+     * @var string ID to identify managed object
47
+     */
48
+    public $element='societe';
49
+
50
+    /**
51
+     * @var string Name of table without prefix where object is stored
52
+     */
53
+    public $table_element = 'societe';
54
+
55
+    /**
56
+     * @var int Field with ID of parent key if this field has a parent
57
+     */
58
+    public $fk_element='fk_soc';
59
+
60
+    public $fieldsforcombobox='nom,name_alias';
61
+    protected $childtables=array("supplier_proposal"=>'SupplierProposal',"propal"=>'Proposal',"commande"=>'Order',"facture"=>'Invoice',"facture_rec"=>'RecurringInvoiceTemplate',"contrat"=>'Contract',"fichinter"=>'Fichinter',"facture_fourn"=>'SupplierInvoice',"commande_fournisseur"=>'SupplierOrder',"projet"=>'Project',"expedition"=>'Shipment',"prelevement_lignes"=>'DirectDebitRecord');    // To test if we can delete object
62
+    protected $childtablesoncascade=array("societe_prices", "societe_log", "societe_address", "product_fournisseur_price", "product_customer_price_log", "product_customer_price", "socpeople", "adherent", "societe_rib", "societe_remise", "societe_remise_except", "societe_commerciaux", "categorie", "notify", "notify_def", "actioncomm");
63
+    public $picto = 'company';
64
+
65
+    /**
66
+     * 0=No test on entity, 1=Test with field entity, 2=Test with link by societe
67
+     * @var int
68
+     */
69
+    public $ismultientitymanaged = 1;
70
+
71
+    /**
72
+     * 0=Default, 1=View may be restricted to sales representative only if no permission to see all or to company of external user if external user
73
+     * @var integer
74
+     */
75
+    public $restrictiononfksoc = 1;
76
+
77
+
78
+    // BEGIN MODULEBUILDER PROPERTIES
79
+    /**
80
+     * @var array  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
81
+     */
82
+    public $fields=array(
83
+        'rowid'         =>array('type'=>'integer',      'label'=>'TechnicalID',      'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'index'=>1, 'position'=>1, 'comment'=>'Id'),
84
+        'nom'           =>array('type'=>'varchar(128)', 'label'=>'Name',             'enabled'=>1, 'visible'=>1,  'notnull'=>1,  'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
85
+        'name_alias'    =>array('type'=>'varchar(128)', 'label'=>'Name',             'enabled'=>1, 'visible'=>1,  'notnull'=>1,  'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
86
+        'entity'        =>array('type'=>'integer',      'label'=>'Entity',           'enabled'=>1, 'visible'=>0,  'default'=>1,  'notnull'=>1,  'index'=>1, 'position'=>20),
87
+        'note_public'   =>array('type'=>'text',			'label'=>'NotePublic',		 'enabled'=>1, 'visible'=>0,  'position'=>60),
88
+        'note_private'  =>array('type'=>'text',			'label'=>'NotePrivate',		 'enabled'=>1, 'visible'=>0,  'position'=>61),
89
+        'datec'			=>array('type'=>'datetime',     'label'=>'DateCreation',     'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'position'=>500),
90
+        'tms'           =>array('type'=>'timestamp',    'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'position'=>501),
91
+        //'date_valid'    =>array('type'=>'datetime',     'label'=>'DateCreation',     'enabled'=>1, 'visible'=>-2, 'position'=>502),
92
+        'fk_user_creat' =>array('type'=>'integer',      'label'=>'UserAuthor',       'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'position'=>510),
93
+        'fk_user_modif' =>array('type'=>'integer',      'label'=>'UserModif',        'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511),
94
+        //'fk_user_valid' =>array('type'=>'integer',      'label'=>'UserValidation',        'enabled'=>1, 'visible'=>-1, 'position'=>512),
95
+        'import_key'    =>array('type'=>'varchar(14)',  'label'=>'ImportId',         'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>1,  'position'=>1000),
96
+    );
97
+
98
+
99
+    /**
100
+     * @var int Entity
101
+     */
102
+    public $entity;
103
+
104
+    /**
105
+     * Thirdparty name
106
+     * @var string
107
+     * @deprecated Use $name instead
108
+     * @see $name
109
+     */
110
+    public $nom;
111
+
112
+    /**
113
+     * @var string name
114
+     */
115
+    public $name;
116
+
117
+    /**
118
+     * Alias names (commercial, trademark or alias names)
119
+     * @var string
120
+     */
121
+    public $name_alias;
122
+
123
+    public $particulier;
124
+
125
+    /**
126
+     * @var string Address
127
+     */
128
+    public $address;
129
+
130
+    public $zip;
131
+    public $town;
132
+
133
+    /**
134
+     * Thirdparty status : 0=activity ceased, 1= in activity
135
+     * @var int
136
+     */
137
+    public $status=1;
138
+
139
+    /**
140
+     * Id of department
141
+     * @var int
142
+     */
143
+    public $state_id;
144
+    public $state_code;
145
+    public $state;
146
+
147
+    /**
148
+     * Id of region
149
+     * @var int
150
+     */
151
+    public $region_code;
152
+    public $region;
153
+
154
+    /**
155
+     * State code
156
+     * @var string
157
+     * @deprecated Use state_code instead
158
+     * @see $state_code
159
+     */
160
+    public $departement_code;
161
+
162
+    /**
163
+     * @var string
164
+     * @deprecated Use state instead
165
+     * @see $state
166
+     */
167
+    public $departement;
168
+
169
+    /**
170
+     * @var string
171
+     * @deprecated Use country instead
172
+     * @see $country
173
+     */
174
+    public $pays;
175
+
176
+    /**
177
+     * Phone number
178
+     * @var string
179
+     */
180
+    public $phone;
181
+    /**
182
+     * Fax number
183
+     * @var string
184
+     */
185
+    public $fax;
186
+    /**
187
+     * Email
188
+     * @var string
189
+     */
190
+    public $email;
191
+    /**
192
+     * Skype username
193
+     * @var string
194
+     */
195
+    public $skype;
196
+    /**
197
+     * Twitter username
198
+     * @var string
199
+     */
200
+    public $twitter;
201
+    /**
202
+     * Facebook username
203
+     * @var string
204
+     */
205
+    public $facebook;
206
+    /**
207
+     * Webpage
208
+     * @var string
209
+     */
210
+    public $url;
211
+
212
+    //! barcode
213
+    /**
214
+     * Barcode value
215
+     * @var string
216
+     */
217
+    public $barcode;
218
+
219
+    // 6 professional id (usage depends on country)
220
+
221
+    /**
222
+     * Professional ID 1 (Ex: Siren in France)
223
+     * @var string
224
+     */
225
+    public $idprof1;
226
+
227
+    /**
228
+     * Professional ID 2 (Ex: Siret in France)
229
+     * @var string
230
+     */
231
+    public $idprof2;
232
+
233
+    /**
234
+     * Professional ID 3 (Ex: Ape in France)
235
+     * @var string
236
+     */
237
+    public $idprof3;
238
+
239
+    /**
240
+     * Professional ID 4 (Ex: RCS in France)
241
+     * @var string
242
+     */
243
+    public $idprof4;
244
+
245
+    /**
246
+     * Professional ID 5
247
+     * @var string
248
+     */
249
+    public $idprof5;
250
+
251
+    /**
252
+     * Professional ID 6
253
+     * @var string
254
+     */
255
+    public $idprof6;
256
+
257
+    public $prefix_comm;
258
+
259
+    public $tva_assuj=1;
260
+    /**
261
+     * Intracommunitary VAT ID
262
+     * @var string
263
+     */
264
+    public $tva_intra;
265
+
266
+    // Local taxes
267
+    public $localtax1_assuj;
268
+    public $localtax1_value;
269
+    public $localtax2_assuj;
270
+    public $localtax2_value;
271
+
272
+    public $managers;
273
+    public $capital;
274
+    public $typent_id=0;
275
+    public $typent_code;
276
+    public $effectif;
277
+    public $effectif_id=0;
278
+    public $forme_juridique_code;
279
+    public $forme_juridique=0;
280
+
281
+    public $remise_percent;
282
+    public $remise_supplier_percent;
283
+    public $mode_reglement_supplier_id;
284
+    public $cond_reglement_supplier_id;
285
+
286
+    /**
287 287
      * @var int ID
288 288
      */
289
-	public $fk_prospectlevel;
290
-
291
-	public $name_bis;
292
-
293
-	//Log data
294
-
295
-	/**
296
-	 * Date of last update
297
-	 * @var string
298
-	 */
299
-	public $date_modification;
300
-	/**
301
-	 * User that made last update
302
-	 * @var string
303
-	 */
304
-	public $user_modification;
305
-	/**
306
-	 * Date of creation
307
-	 * @var string
308
-	 */
309
-	public $date_creation;
310
-	/**
311
-	 * User that created the thirdparty
312
-	 * @var User
313
-	 */
314
-	public $user_creation;
315
-
316
-
317
-	public $specimen;
318
-
319
-	/**
320
-	 * 0=no customer, 1=customer, 2=prospect, 3=customer and prospect
321
-	 * @var int
322
-	 */
323
-	public $client=0;
324
-	/**
325
-	 * 0=no prospect, 1=prospect
326
-	 * @var int
327
-	 */
328
-	public $prospect=0;
329
-	/**
330
-	 * 0=no supplier, 1=supplier
331
-	 * @var int
332
-	 */
333
-	public $fournisseur;
334
-
335
-	/**
336
-	 * Client code. E.g: CU2014-003
337
-	 * @var string
338
-	 */
339
-	public $code_client;
340
-
341
-	/**
342
-	 * Supplier code. E.g: SU2014-003
343
-	 * @var string
344
-	 */
345
-	public $code_fournisseur;
346
-
347
-	/**
348
-	 * Accounting code for client
349
-	 * @var string
350
-	 */
351
-	public $code_compta;
289
+    public $fk_prospectlevel;
290
+
291
+    public $name_bis;
292
+
293
+    //Log data
294
+
295
+    /**
296
+     * Date of last update
297
+     * @var string
298
+     */
299
+    public $date_modification;
300
+    /**
301
+     * User that made last update
302
+     * @var string
303
+     */
304
+    public $user_modification;
305
+    /**
306
+     * Date of creation
307
+     * @var string
308
+     */
309
+    public $date_creation;
310
+    /**
311
+     * User that created the thirdparty
312
+     * @var User
313
+     */
314
+    public $user_creation;
315
+
316
+
317
+    public $specimen;
318
+
319
+    /**
320
+     * 0=no customer, 1=customer, 2=prospect, 3=customer and prospect
321
+     * @var int
322
+     */
323
+    public $client=0;
324
+    /**
325
+     * 0=no prospect, 1=prospect
326
+     * @var int
327
+     */
328
+    public $prospect=0;
329
+    /**
330
+     * 0=no supplier, 1=supplier
331
+     * @var int
332
+     */
333
+    public $fournisseur;
334
+
335
+    /**
336
+     * Client code. E.g: CU2014-003
337
+     * @var string
338
+     */
339
+    public $code_client;
340
+
341
+    /**
342
+     * Supplier code. E.g: SU2014-003
343
+     * @var string
344
+     */
345
+    public $code_fournisseur;
346
+
347
+    /**
348
+     * Accounting code for client
349
+     * @var string
350
+     */
351
+    public $code_compta;
352 352
 
353 353
     /**
354 354
      * Accounting code for client
@@ -356,3795 +356,3795 @@  discard block
 block discarded – undo
356 356
      */
357 357
     public $code_compta_client;
358 358
 
359
-	/**
360
-	 * Accounting code for suppliers
361
-	 * @var string
362
-	 */
363
-	public $code_compta_fournisseur;
364
-
365
-	/**
366
-	 * @var string
367
-	 * @deprecated Note is split in public and private notes
368
-	 * @see $note_public, $note_private
369
-	 */
370
-	public $note;
371
-
372
-	/**
373
-	 * Private note
374
-	 * @var string
375
-	 */
376
-	public $note_private;
377
-
378
-	/**
379
-	 * Public note
380
-	 * @var string
381
-	 */
382
-	public $note_public;
383
-
384
-	//! code statut prospect
385
-	public $stcomm_id;
386
-	public $statut_commercial;
387
-
388
-	/**
389
-	 * Assigned price level
390
-	 * @var int
391
-	 */
392
-	public $price_level;
393
-	public $outstanding_limit;
394
-
395
-	/**
396
-	 * Min order amounts
397
-	 */
398
-	public $order_min_amount;
399
-	public $supplier_order_min_amount;
400
-
401
-	/**
402
-	 * Id of sales representative to link (used for thirdparty creation). Not filled by a fetch, because we can have several sales representatives.
403
-	 * @var int
404
-	 */
405
-	public $commercial_id;
406
-	/**
407
-	 * Id of parent thirdparty (if one)
408
-	 * @var int
409
-	 */
410
-	public $parent;
411
-	/**
412
-	 * Default language code of thirdparty (en_US, ...)
413
-	 * @var string
414
-	 */
415
-	public $default_lang;
416
-
417
-	/**
418
-	 * @var string Ref
419
-	 */
420
-	public $ref;
421
-
422
-	public $ref_int;
423
-	/**
424
-	 * External user reference.
425
-	 * This is to allow external systems to store their id and make self-developed synchronizing functions easier to
426
-	 * build.
427
-	 * @var string
428
-	 */
429
-	public $ref_ext;
430
-
431
-	/**
432
-	 * Import key.
433
-	 * Set when the thirdparty has been created through an import process. This is to relate those created thirdparties
434
-	 * to an import process
435
-	 * @var string
436
-	 */
437
-	public $import_key;
438
-
439
-	/**
440
-	 * Supplier WebServices URL
441
-	 * @var string
442
-	 */
443
-	public $webservices_url;
444
-
445
-	/**
446
-	 * Supplier WebServices Key
447
-	 * @var string
448
-	 */
449
-	public $webservices_key;
450
-
451
-	public $logo;
452
-	public $logo_small;
453
-	public $logo_mini;
454
-
455
-	public $array_options;
456
-
457
-	// Incoterms
458
-	/**
359
+    /**
360
+     * Accounting code for suppliers
361
+     * @var string
362
+     */
363
+    public $code_compta_fournisseur;
364
+
365
+    /**
366
+     * @var string
367
+     * @deprecated Note is split in public and private notes
368
+     * @see $note_public, $note_private
369
+     */
370
+    public $note;
371
+
372
+    /**
373
+     * Private note
374
+     * @var string
375
+     */
376
+    public $note_private;
377
+
378
+    /**
379
+     * Public note
380
+     * @var string
381
+     */
382
+    public $note_public;
383
+
384
+    //! code statut prospect
385
+    public $stcomm_id;
386
+    public $statut_commercial;
387
+
388
+    /**
389
+     * Assigned price level
390
+     * @var int
391
+     */
392
+    public $price_level;
393
+    public $outstanding_limit;
394
+
395
+    /**
396
+     * Min order amounts
397
+     */
398
+    public $order_min_amount;
399
+    public $supplier_order_min_amount;
400
+
401
+    /**
402
+     * Id of sales representative to link (used for thirdparty creation). Not filled by a fetch, because we can have several sales representatives.
403
+     * @var int
404
+     */
405
+    public $commercial_id;
406
+    /**
407
+     * Id of parent thirdparty (if one)
408
+     * @var int
409
+     */
410
+    public $parent;
411
+    /**
412
+     * Default language code of thirdparty (en_US, ...)
413
+     * @var string
414
+     */
415
+    public $default_lang;
416
+
417
+    /**
418
+     * @var string Ref
419
+     */
420
+    public $ref;
421
+
422
+    public $ref_int;
423
+    /**
424
+     * External user reference.
425
+     * This is to allow external systems to store their id and make self-developed synchronizing functions easier to
426
+     * build.
427
+     * @var string
428
+     */
429
+    public $ref_ext;
430
+
431
+    /**
432
+     * Import key.
433
+     * Set when the thirdparty has been created through an import process. This is to relate those created thirdparties
434
+     * to an import process
435
+     * @var string
436
+     */
437
+    public $import_key;
438
+
439
+    /**
440
+     * Supplier WebServices URL
441
+     * @var string
442
+     */
443
+    public $webservices_url;
444
+
445
+    /**
446
+     * Supplier WebServices Key
447
+     * @var string
448
+     */
449
+    public $webservices_key;
450
+
451
+    public $logo;
452
+    public $logo_small;
453
+    public $logo_mini;
454
+
455
+    public $array_options;
456
+
457
+    // Incoterms
458
+    /**
459 459
      * @var int ID
460 460
      */
461
-	public $fk_incoterms;
461
+    public $fk_incoterms;
462 462
 
463
-	public $location_incoterms;
464
-	public $libelle_incoterms;  //Used into tooltip
463
+    public $location_incoterms;
464
+    public $libelle_incoterms;  //Used into tooltip
465 465
 
466
-	// Multicurrency
467
-	/**
466
+    // Multicurrency
467
+    /**
468 468
      * @var int ID
469 469
      */
470
-	public $fk_multicurrency;
471
-
472
-	public $multicurrency_code;
473
-
474
-
475
-	// END MODULEBUILDER PROPERTIES
476
-
477
-
478
-	/**
479
-	 *    Constructor
480
-	 *
481
-	 *    @param	DoliDB		$db		Database handler
482
-	 */
483
-	public function __construct($db)
484
-	{
485
-		$this->db = $db;
486
-
487
-		$this->client = 0;
488
-		$this->prospect = 0;
489
-		$this->fournisseur = 0;
490
-		$this->typent_id  = 0;
491
-		$this->effectif_id  = 0;
492
-		$this->forme_juridique_code  = 0;
493
-		$this->tva_assuj = 1;
494
-		$this->status = 1;
495
-	}
496
-
497
-
498
-	/**
499
-	 *    Create third party in database.
500
-	 *    $this->code_client = -1 and $this->code_fournisseur = -1 means automatic assignement.
501
-	 *
502
-	 *    @param	User	$user       Object of user that ask creation
503
-	 *    @return   int         		>= 0 if OK, < 0 if KO
504
-	 */
505
-	function create(User $user)
506
-	{
507
-		global $langs,$conf,$mysoc;
508
-
509
-		$error=0;
510
-
511
-		// Clean parameters
512
-		if (empty($this->status)) $this->status=0;
513
-		$this->name=$this->name?trim($this->name):trim($this->nom);
514
-		if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name=ucwords($this->name);
515
-		$this->nom=$this->name; // For backward compatibility
516
-		if (empty($this->client))      $this->client=0;
517
-		if (empty($this->fournisseur)) $this->fournisseur=0;
518
-		$this->import_key = trim($this->import_key);
519
-
520
-		if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
521
-		if (empty($this->fk_multicurrency))
522
-		{
523
-			$this->multicurrency_code = '';
524
-			$this->fk_multicurrency = 0;
525
-		}
526
-
527
-		dol_syslog(get_class($this)."::create ".$this->name);
528
-
529
-		$now=dol_now();
530
-
531
-		$this->db->begin();
532
-
533
-		// For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
534
-		if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this,0);
535
-		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this,1);
536
-
537
-		// Check more parameters (including mandatory setup
538
-		// If error, this->errors[] is filled
539
-		$result = $this->verify();
540
-
541
-		if ($result >= 0)
542
-		{
543
-			$this->entity = ((isset($this->entity) && is_numeric($this->entity))?$this->entity:$conf->entity);
544
-
545
-			$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, name_alias, entity, datec, fk_user_creat, canvas, status, ref_int, ref_ext, fk_stcomm, fk_incoterms, location_incoterms ,import_key, fk_multicurrency, multicurrency_code)";
546
-			$sql.= " VALUES ('".$this->db->escape($this->name)."', '".$this->db->escape($this->name_alias)."', ".$this->db->escape($this->entity).", '".$this->db->idate($now)."'";
547
-			$sql.= ", ".(! empty($user->id) ? "'".$user->id."'":"null");
548
-			$sql.= ", ".(! empty($this->canvas) ? "'".$this->db->escape($this->canvas)."'":"null");
549
-			$sql.= ", ".$this->status;
550
-			$sql.= ", ".(! empty($this->ref_int) ? "'".$this->db->escape($this->ref_int)."'":"null");
551
-			$sql.= ", ".(! empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'":"null");
552
-			$sql.= ", 0";
553
-			$sql.= ", ".(int) $this->fk_incoterms;
554
-			$sql.= ", '".$this->db->escape($this->location_incoterms)."'";
555
-			$sql.= ", ".(! empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'":"null");
556
-			$sql.= ", ".(int) $this->fk_multicurrency;
557
-			$sql.= ", '".$this->db->escape($this->multicurrency_code)."')";
558
-
559
-			dol_syslog(get_class($this)."::create", LOG_DEBUG);
560
-			$result=$this->db->query($sql);
561
-			if ($result)
562
-			{
563
-				$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe");
564
-
565
-				$ret = $this->update($this->id,$user,0,1,1,'add');
566
-
567
-				// Ajout du commercial affecte
568
-				if ($this->commercial_id != '' && $this->commercial_id != -1)
569
-				{
570
-					$this->add_commercial($user, $this->commercial_id);
571
-				}
572
-				// si un commercial cree un client il lui est affecte automatiquement
573
-				elseif (empty($user->rights->societe->client->voir))
574
-				{
575
-					$this->add_commercial($user, $user->id);
576
-				}
577
-
578
-				if ($ret >= 0)
579
-				{
580
-					// Call trigger
581
-					$result=$this->call_trigger('COMPANY_CREATE',$user);
582
-					if ($result < 0) $error++;
583
-					// End call triggers
584
-				}
585
-				else $error++;
586
-
587
-				if (! $error)
588
-				{
589
-					dol_syslog(get_class($this)."::Create success id=".$this->id);
590
-					$this->db->commit();
591
-					return $this->id;
592
-				}
593
-				else
594
-				{
595
-					dol_syslog(get_class($this)."::Create echec update ".$this->error." ".join(',',$this->errors), LOG_ERR);
596
-					$this->db->rollback();
597
-					return -4;
598
-				}
599
-			}
600
-			else
601
-			{
602
-				if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
603
-				{
604
-					$this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->name);    // duplicate on a field (code or profid or ...)
605
-					$result=-1;
606
-				}
607
-				else
608
-				{
609
-					$this->error=$this->db->lasterror();
610
-					$result=-2;
611
-				}
612
-				$this->db->rollback();
613
-				return $result;
614
-			}
615
-		}
616
-		else
617
-		{
618
-			$this->db->rollback();
619
-			dol_syslog(get_class($this)."::Create fails verify ".join(',',$this->errors), LOG_WARNING);
620
-			return -3;
621
-		}
622
-	}
470
+    public $fk_multicurrency;
471
+
472
+    public $multicurrency_code;
473
+
474
+
475
+    // END MODULEBUILDER PROPERTIES
476
+
477
+
478
+    /**
479
+     *    Constructor
480
+     *
481
+     *    @param	DoliDB		$db		Database handler
482
+     */
483
+    public function __construct($db)
484
+    {
485
+        $this->db = $db;
486
+
487
+        $this->client = 0;
488
+        $this->prospect = 0;
489
+        $this->fournisseur = 0;
490
+        $this->typent_id  = 0;
491
+        $this->effectif_id  = 0;
492
+        $this->forme_juridique_code  = 0;
493
+        $this->tva_assuj = 1;
494
+        $this->status = 1;
495
+    }
496
+
497
+
498
+    /**
499
+     *    Create third party in database.
500
+     *    $this->code_client = -1 and $this->code_fournisseur = -1 means automatic assignement.
501
+     *
502
+     *    @param	User	$user       Object of user that ask creation
503
+     *    @return   int         		>= 0 if OK, < 0 if KO
504
+     */
505
+    function create(User $user)
506
+    {
507
+        global $langs,$conf,$mysoc;
508
+
509
+        $error=0;
510
+
511
+        // Clean parameters
512
+        if (empty($this->status)) $this->status=0;
513
+        $this->name=$this->name?trim($this->name):trim($this->nom);
514
+        if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name=ucwords($this->name);
515
+        $this->nom=$this->name; // For backward compatibility
516
+        if (empty($this->client))      $this->client=0;
517
+        if (empty($this->fournisseur)) $this->fournisseur=0;
518
+        $this->import_key = trim($this->import_key);
519
+
520
+        if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
521
+        if (empty($this->fk_multicurrency))
522
+        {
523
+            $this->multicurrency_code = '';
524
+            $this->fk_multicurrency = 0;
525
+        }
526
+
527
+        dol_syslog(get_class($this)."::create ".$this->name);
528
+
529
+        $now=dol_now();
530
+
531
+        $this->db->begin();
532
+
533
+        // For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
534
+        if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this,0);
535
+        if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this,1);
536
+
537
+        // Check more parameters (including mandatory setup
538
+        // If error, this->errors[] is filled
539
+        $result = $this->verify();
540
+
541
+        if ($result >= 0)
542
+        {
543
+            $this->entity = ((isset($this->entity) && is_numeric($this->entity))?$this->entity:$conf->entity);
544
+
545
+            $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, name_alias, entity, datec, fk_user_creat, canvas, status, ref_int, ref_ext, fk_stcomm, fk_incoterms, location_incoterms ,import_key, fk_multicurrency, multicurrency_code)";
546
+            $sql.= " VALUES ('".$this->db->escape($this->name)."', '".$this->db->escape($this->name_alias)."', ".$this->db->escape($this->entity).", '".$this->db->idate($now)."'";
547
+            $sql.= ", ".(! empty($user->id) ? "'".$user->id."'":"null");
548
+            $sql.= ", ".(! empty($this->canvas) ? "'".$this->db->escape($this->canvas)."'":"null");
549
+            $sql.= ", ".$this->status;
550
+            $sql.= ", ".(! empty($this->ref_int) ? "'".$this->db->escape($this->ref_int)."'":"null");
551
+            $sql.= ", ".(! empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'":"null");
552
+            $sql.= ", 0";
553
+            $sql.= ", ".(int) $this->fk_incoterms;
554
+            $sql.= ", '".$this->db->escape($this->location_incoterms)."'";
555
+            $sql.= ", ".(! empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'":"null");
556
+            $sql.= ", ".(int) $this->fk_multicurrency;
557
+            $sql.= ", '".$this->db->escape($this->multicurrency_code)."')";
558
+
559
+            dol_syslog(get_class($this)."::create", LOG_DEBUG);
560
+            $result=$this->db->query($sql);
561
+            if ($result)
562
+            {
563
+                $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe");
564
+
565
+                $ret = $this->update($this->id,$user,0,1,1,'add');
566
+
567
+                // Ajout du commercial affecte
568
+                if ($this->commercial_id != '' && $this->commercial_id != -1)
569
+                {
570
+                    $this->add_commercial($user, $this->commercial_id);
571
+                }
572
+                // si un commercial cree un client il lui est affecte automatiquement
573
+                elseif (empty($user->rights->societe->client->voir))
574
+                {
575
+                    $this->add_commercial($user, $user->id);
576
+                }
577
+
578
+                if ($ret >= 0)
579
+                {
580
+                    // Call trigger
581
+                    $result=$this->call_trigger('COMPANY_CREATE',$user);
582
+                    if ($result < 0) $error++;
583
+                    // End call triggers
584
+                }
585
+                else $error++;
586
+
587
+                if (! $error)
588
+                {
589
+                    dol_syslog(get_class($this)."::Create success id=".$this->id);
590
+                    $this->db->commit();
591
+                    return $this->id;
592
+                }
593
+                else
594
+                {
595
+                    dol_syslog(get_class($this)."::Create echec update ".$this->error." ".join(',',$this->errors), LOG_ERR);
596
+                    $this->db->rollback();
597
+                    return -4;
598
+                }
599
+            }
600
+            else
601
+            {
602
+                if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
603
+                {
604
+                    $this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->name);    // duplicate on a field (code or profid or ...)
605
+                    $result=-1;
606
+                }
607
+                else
608
+                {
609
+                    $this->error=$this->db->lasterror();
610
+                    $result=-2;
611
+                }
612
+                $this->db->rollback();
613
+                return $result;
614
+            }
615
+        }
616
+        else
617
+        {
618
+            $this->db->rollback();
619
+            dol_syslog(get_class($this)."::Create fails verify ".join(',',$this->errors), LOG_WARNING);
620
+            return -3;
621
+        }
622
+    }
623 623
 
624 624
 
625 625
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
626
-	/**
627
-	 * Create a contact/address from thirdparty
628
-	 *
629
-	 * @param 	User	$user		Object user
630
-	 * @return 	int					<0 if KO, >0 if OK
631
-	 */
632
-	function create_individual(User $user)
633
-	{
626
+    /**
627
+     * Create a contact/address from thirdparty
628
+     *
629
+     * @param 	User	$user		Object user
630
+     * @return 	int					<0 if KO, >0 if OK
631
+     */
632
+    function create_individual(User $user)
633
+    {
634 634
         // phpcs:enable
635
-		require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
636
-		$contact=new Contact($this->db);
637
-
638
-		$contact->name              = $this->name_bis;
639
-		$contact->firstname         = $this->firstname;
640
-		$contact->civility_id       = $this->civility_id;
641
-		$contact->socid             = $this->id;	// fk_soc
642
-		$contact->statut            = 1;
643
-		$contact->priv              = 0;
644
-		$contact->country_id        = $this->country_id;
645
-		$contact->state_id          = $this->state_id;
646
-		$contact->address           = $this->address;
647
-		$contact->email             = $this->email;
648
-		$contact->zip               = $this->zip;
649
-		$contact->town              = $this->town;
650
-		$contact->phone_pro         = $this->phone;
651
-
652
-		$result = $contact->create($user);
653
-		if ($result < 0)
654
-		{
655
-			$this->error = $contact->error;
656
-			$this->errors = $contact->errors;
657
-			dol_syslog(get_class($this)."::create_individual ERROR:" . $this->error, LOG_ERR);
658
-		}
659
-
660
-		return $result;
661
-	}
662
-
663
-	/**
664
-	 *    Check properties of third party are ok (like name, third party codes, ...)
665
-	 *    Used before an add or update.
666
-	 *
667
-	 *    @return     int		0 if OK, <0 if KO
668
-	 */
669
-	function verify()
670
-	{
671
-		global $conf, $langs, $mysoc;
672
-
673
-		$error = 0;
674
-		$this->errors=array();
675
-
676
-		$result = 0;
677
-		$this->name	= trim($this->name);
678
-		$this->nom=$this->name; // For backward compatibility
679
-
680
-		if (! $this->name)
681
-		{
682
-			$this->errors[] = 'ErrorBadThirdPartyName';
683
-			$result = -2;
684
-		}
685
-
686
-		if ($this->client)
687
-		{
688
-			$rescode = $this->check_codeclient();
689
-			if ($rescode <> 0)
690
-			{
691
-				if ($rescode == -1)
692
-				{
693
-					$this->errors[] = 'ErrorBadCustomerCodeSyntax';
694
-				}
695
-				elseif ($rescode == -2)
696
-				{
697
-					$this->errors[] = 'ErrorCustomerCodeRequired';
698
-				}
699
-				elseif ($rescode == -3)
700
-				{
701
-					$this->errors[] = 'ErrorCustomerCodeAlreadyUsed';
702
-				}
703
-				elseif ($rescode == -4)
704
-				{
705
-					$this->errors[] = 'ErrorPrefixRequired';
706
-				}
707
-				$result = -3;
708
-			}
709
-		}
710
-
711
-		if ($this->fournisseur)
712
-		{
713
-			$rescode = $this->check_codefournisseur();
714
-			if ($rescode <> 0)
715
-			{
716
-				if ($rescode == -1)
717
-				{
718
-					$this->errors[] = 'ErrorBadSupplierCodeSyntax';
719
-				}
720
-				elseif ($rescode == -2)
721
-				{
722
-					$this->errors[] = 'ErrorSupplierCodeRequired';
723
-				}
724
-				elseif ($rescode == -3)
725
-				{
726
-					$this->errors[] = 'ErrorSupplierCodeAlreadyUsed';
727
-				}
728
-				elseif ($rescode == -5)
729
-				{
730
-					$this->errors[] = 'ErrorprefixRequired';
731
-				}
732
-				$result = -3;
733
-			}
734
-		}
735
-
736
-		// Check for duplicate or mandatory fields defined into setup
737
-		$array_to_check=array('IDPROF1','IDPROF2','IDPROF3','IDPROF4','IDPROF5','IDPROF6','EMAIL');
738
-		foreach($array_to_check as $key)
739
-		{
740
-			$keymin=strtolower($key);
741
-			$i=(int) preg_replace('/[^0-9]/','',$key);
742
-			$vallabel=$this->$keymin;
743
-
744
-			if ($i > 0)
745
-			{
746
-				if ($this->isACompany())
747
-				{
748
-					// Check for unicity
749
-					if ($vallabel && $this->id_prof_verifiable($i))
750
-					{
751
-						if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0)))
752
-						{
753
-							$langs->load("errors");
754
-							$error++; $this->errors[] = $langs->transcountry('ProfId'.$i, $this->country_code)." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')';
755
-						}
756
-					}
757
-
758
-					// Check for mandatory prof id (but only if country is other than ours)
759
-					if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id)
760
-					{
761
-						$idprof_mandatory ='SOCIETE_'.$key.'_MANDATORY';
762
-						if (! $vallabel && ! empty($conf->global->$idprof_mandatory))
763
-						{
764
-							$langs->load("errors");
765
-							$error++;
766
-							$this->errors[] = $langs->trans("ErrorProdIdIsMandatory", $langs->transcountry('ProfId'.$i, $this->country_code)).' ('.$langs->trans("ForbiddenBySetupRules").')';
767
-						}
768
-					}
769
-				}
770
-			}
771
-			else
772
-			{
773
-				//var_dump($conf->global->SOCIETE_EMAIL_UNIQUE);
774
-				//var_dump($conf->global->SOCIETE_EMAIL_MANDATORY);
775
-				if ($key == 'EMAIL')
776
-				{
777
-					// Check for unicity
778
-					if ($vallabel && ! empty($conf->global->SOCIETE_EMAIL_UNIQUE))
779
-					{
780
-						if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0)))
781
-						{
782
-							$langs->load("errors");
783
-							$error++; $this->errors[] = $langs->trans('Email')." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')';
784
-						}
785
-					}
786
-
787
-					// Check for mandatory
788
-					if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY) && ! isValidEMail($this->email))
789
-					{
790
-						$langs->load("errors");
791
-						$error++;
792
-						$this->errors[] = $langs->trans("ErrorBadEMail", $this->email).' ('.$langs->trans("ForbiddenBySetupRules").')';
793
-					}
794
-				}
795
-			}
796
-		}
797
-
798
-		if ($error) $result = -4;
799
-
800
-		return $result;
801
-	}
802
-
803
-	/**
804
-	 *      Update parameters of third party
805
-	 *
806
-	 *      @param	int		$id              			Id of company (deprecated, use 0 here and call update on an object loaded by a fetch)
807
-	 *      @param  User	$user            			Utilisateur qui demande la mise a jour
808
-	 *      @param  int		$call_trigger    			0=no, 1=yes
809
-	 *		@param	int		$allowmodcodeclient			Inclut modif code client et code compta
810
-	 *		@param	int		$allowmodcodefournisseur	Inclut modif code fournisseur et code compta fournisseur
811
-	 *		@param	string	$action						'add' or 'update' or 'merge'
812
-	 *		@param	int		$nosyncmember				Do not synchronize info of linked member
813
-	 *      @return int  			           			<0 if KO, >=0 if OK
814
-	 */
815
-	function update($id, $user='', $call_trigger=1, $allowmodcodeclient=0, $allowmodcodefournisseur=0, $action='update', $nosyncmember=1)
816
-	{
817
-		global $langs,$conf,$hookmanager;
818
-
819
-		require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
820
-
821
-		if (empty($id)) $id = $this->id;
822
-
823
-		$error=0;
824
-
825
-		dol_syslog(get_class($this)."::Update id=".$id." call_trigger=".$call_trigger." allowmodcodeclient=".$allowmodcodeclient." allowmodcodefournisseur=".$allowmodcodefournisseur);
826
-
827
-		$now=dol_now();
828
-
829
-		// Clean parameters
830
-		$this->id			= $id;
831
-		$this->entity		= ((isset($this->entity) && is_numeric($this->entity))?$this->entity:$conf->entity);
832
-		$this->name			= $this->name?trim($this->name):trim($this->nom);
833
-		$this->nom			= $this->name;	// For backward compatibility
834
-		$this->name_alias	= trim($this->name_alias);
835
-		$this->ref_ext		= trim($this->ref_ext);
836
-		$this->address		= $this->address?trim($this->address):trim($this->address);
837
-		$this->zip			= $this->zip?trim($this->zip):trim($this->zip);
838
-		$this->town			= $this->town?trim($this->town):trim($this->town);
839
-		$this->state_id		= trim($this->state_id);
840
-		$this->country_id	= ($this->country_id > 0)?$this->country_id:0;
841
-		$this->phone		= trim($this->phone);
842
-		$this->phone		= preg_replace("/\s/","",$this->phone);
843
-		$this->phone		= preg_replace("/\./","",$this->phone);
844
-		$this->fax			= trim($this->fax);
845
-		$this->fax			= preg_replace("/\s/","",$this->fax);
846
-		$this->fax			= preg_replace("/\./","",$this->fax);
847
-		$this->email		= trim($this->email);
848
-		$this->skype		= trim($this->skype);
849
-		$this->twitter		= trim($this->twitter);
850
-		$this->facebook		= trim($this->facebook);
851
-		$this->url			= $this->url?clean_url($this->url,0):'';
852
-		$this->note_private = trim($this->note_private);
853
-		$this->note_public  = trim($this->note_public);
854
-		$this->idprof1		= trim($this->idprof1);
855
-		$this->idprof2		= trim($this->idprof2);
856
-		$this->idprof3		= trim($this->idprof3);
857
-		$this->idprof4		= trim($this->idprof4);
858
-		$this->idprof5		= (! empty($this->idprof5)?trim($this->idprof5):'');
859
-		$this->idprof6		= (! empty($this->idprof6)?trim($this->idprof6):'');
860
-		$this->prefix_comm	= trim($this->prefix_comm);
861
-		$this->outstanding_limit = price2num($this->outstanding_limit);
862
-		$this->order_min_amount = price2num($this->order_min_amount);
863
-		$this->supplier_order_min_amount = price2num($this->supplier_order_min_amount);
864
-
865
-		$this->tva_assuj	= trim($this->tva_assuj);
866
-		$this->tva_intra	= dol_sanitizeFileName($this->tva_intra,'');
867
-		if (empty($this->status)) $this->status = 0;
868
-
869
-		if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
870
-		if (empty($this->fk_multicurrency))
871
-		{
872
-			$this->multicurrency_code = '';
873
-			$this->fk_multicurrency = 0;
874
-		}
875
-
876
-		// Local taxes
877
-		$this->localtax1_assuj=trim($this->localtax1_assuj);
878
-		$this->localtax2_assuj=trim($this->localtax2_assuj);
879
-
880
-		$this->localtax1_value=trim($this->localtax1_value);
881
-		$this->localtax2_value=trim($this->localtax2_value);
882
-
883
-		if ($this->capital != '') $this->capital=price2num(trim($this->capital));
884
-		if (! is_numeric($this->capital)) $this->capital = '';     // '' = undef
885
-
886
-		$this->effectif_id=trim($this->effectif_id);
887
-		$this->forme_juridique_code=trim($this->forme_juridique_code);
888
-
889
-		//Gencod
890
-		$this->barcode=trim($this->barcode);
891
-
892
-		// For automatic creation
893
-		if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this,0);
894
-		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this,1);
895
-
896
-		$this->code_compta=trim($this->code_compta);
897
-		$this->code_compta_fournisseur=trim($this->code_compta_fournisseur);
898
-
899
-		// Check parameters. More tests are done later in the ->verify()
900
-		if (! is_numeric($this->client) && ! is_numeric($this->fournisseur))
901
-		{
902
-			$langs->load("errors");
903
-			$this->error = $langs->trans("BadValueForParameterClientOrSupplier");
904
-			return -1;
905
-		}
906
-
907
-		$customer=false;
908
-		if (! empty($allowmodcodeclient) && ! empty($this->client))
909
-		{
910
-			// Attention get_codecompta peut modifier le code suivant le module utilise
911
-			if (empty($this->code_compta))
912
-			{
913
-				$ret=$this->get_codecompta('customer');
914
-				if ($ret < 0) return -1;
915
-			}
916
-
917
-			$customer=true;
918
-		}
919
-
920
-		$supplier=false;
921
-		if (! empty($allowmodcodefournisseur) && ! empty($this->fournisseur))
922
-		{
923
-			// Attention get_codecompta peut modifier le code suivant le module utilise
924
-			if (empty($this->code_compta_fournisseur))
925
-			{
926
-				$ret=$this->get_codecompta('supplier');
927
-				if ($ret < 0) return -1;
928
-			}
929
-
930
-			$supplier=true;
931
-		}
932
-
933
-		//Web services
934
-		$this->webservices_url = $this->webservices_url?clean_url($this->webservices_url,0):'';
935
-		$this->webservices_key = trim($this->webservices_key);
936
-
937
-		//Incoterms
938
-		$this->fk_incoterms = (int) $this->fk_incoterms;
939
-		$this->location_incoterms = trim($this->location_incoterms);
940
-
941
-		$this->db->begin();
942
-
943
-		// Check name is required and codes are ok or unique.
944
-		// If error, this->errors[] is filled
945
-		$result = 0;
946
-		if ($action != 'add' && $action != 'merge')
947
-		{
948
-			// We don't check when update called during a create because verify was already done.
949
-			// For a merge, we suppose source data is clean and a customer code of a deleted thirdparty must be accepted into a target thirdparty with empty code without duplicate error
950
-			$result = $this->verify();
951
-
952
-			// If there is only one error and error is ErrorBadCustomerCodeSyntax and we don't change customer code, we allow the update
953
-			// So we can update record that were using and old numbering rule.
954
-			if (is_array($this->errors))
955
-			{
956
-				if (in_array('ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client)
957
-				{
958
-					if (($key = array_search('ErrorBadCustomerCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]);	// Remove error message
959
-				}
960
-				if (in_array('ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur)
961
-				{
962
-					if (($key = array_search('ErrorBadSupplierCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]);	// Remove error message
963
-				}
964
-				if (empty($this->errors))	// If there is no more error, we can make like if there is no error at all
965
-				{
966
-					$result = 0;
967
-				}
968
-			}
969
-		}
970
-
971
-		if ($result >= 0)
972
-		{
973
-			dol_syslog(get_class($this)."::update verify ok or not done");
974
-
975
-			$sql  = "UPDATE ".MAIN_DB_PREFIX."societe SET ";
976
-			$sql .= "entity = " . $this->db->escape($this->entity);
977
-			$sql .= ",nom = '" . $this->db->escape($this->name) ."'"; // Required
978
-			$sql .= ",name_alias = '" . $this->db->escape($this->name_alias) ."'";
979
-			$sql .= ",ref_ext = " .(! empty($this->ref_ext)?"'".$this->db->escape($this->ref_ext) ."'":"null");
980
-			$sql .= ",address = '" . $this->db->escape($this->address) ."'";
981
-
982
-			$sql .= ",zip = ".(! empty($this->zip)?"'".$this->db->escape($this->zip)."'":"null");
983
-			$sql .= ",town = ".(! empty($this->town)?"'".$this->db->escape($this->town)."'":"null");
984
-
985
-			$sql .= ",fk_departement = '" . (! empty($this->state_id)?$this->state_id:'0') ."'";
986
-			$sql .= ",fk_pays = '" . (! empty($this->country_id)?$this->country_id:'0') ."'";
987
-
988
-			$sql .= ",phone = ".(! empty($this->phone)?"'".$this->db->escape($this->phone)."'":"null");
989
-			$sql .= ",fax = ".(! empty($this->fax)?"'".$this->db->escape($this->fax)."'":"null");
990
-			$sql .= ",email = ".(! empty($this->email)?"'".$this->db->escape($this->email)."'":"null");
991
-			$sql .= ",skype = ".(! empty($this->skype)?"'".$this->db->escape($this->skype)."'":"null");
992
-			$sql .= ",twitter = ".(! empty($this->twitter)?"'".$this->db->escape($this->twitter)."'":"null");
993
-			$sql .= ",facebook = ".(! empty($this->facebook)?"'".$this->db->escape($this->facebook)."'":"null");
994
-			$sql .= ",url = ".(! empty($this->url)?"'".$this->db->escape($this->url)."'":"null");
995
-
996
-			$sql .= ",parent = " . ($this->parent > 0 ? $this->parent : "null");
997
-
998
-			$sql .= ",note_private = ".(! empty($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null");
999
-			$sql .= ",note_public = ".(! empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null");
1000
-
1001
-			$sql .= ",siren   = '". $this->db->escape($this->idprof1) ."'";
1002
-			$sql .= ",siret   = '". $this->db->escape($this->idprof2) ."'";
1003
-			$sql .= ",ape     = '". $this->db->escape($this->idprof3) ."'";
1004
-			$sql .= ",idprof4 = '". $this->db->escape($this->idprof4) ."'";
1005
-			$sql .= ",idprof5 = '". $this->db->escape($this->idprof5) ."'";
1006
-			$sql .= ",idprof6 = '". $this->db->escape($this->idprof6) ."'";
1007
-
1008
-			$sql .= ",tva_assuj = ".($this->tva_assuj!=''?"'".$this->db->escape($this->tva_assuj)."'":"null");
1009
-			$sql .= ",tva_intra = '" . $this->db->escape($this->tva_intra) ."'";
1010
-			$sql .= ",status = " .$this->status;
1011
-
1012
-			// Local taxes
1013
-			$sql .= ",localtax1_assuj = ".($this->localtax1_assuj!=''?"'".$this->db->escape($this->localtax1_assuj)."'":"null");
1014
-			$sql .= ",localtax2_assuj = ".($this->localtax2_assuj!=''?"'".$this->db->escape($this->localtax2_assuj)."'":"null");
1015
-			if($this->localtax1_assuj==1)
1016
-			{
1017
-				if($this->localtax1_value!='')
1018
-				{
1019
-					$sql .=",localtax1_value =".$this->localtax1_value;
1020
-				}
1021
-				else $sql .=",localtax1_value =0.000";
1022
-			}
1023
-			else $sql .=",localtax1_value =0.000";
1024
-
1025
-			if($this->localtax2_assuj==1)
1026
-			{
1027
-				if($this->localtax2_value!='')
1028
-				{
1029
-					$sql .=",localtax2_value =".$this->localtax2_value;
1030
-				}
1031
-				else $sql .=",localtax2_value =0.000";
1032
-			}
1033
-			else $sql .=",localtax2_value =0.000";
1034
-
1035
-			$sql .= ",capital = ".($this->capital == '' ? "null" : $this->capital);
1036
-
1037
-			$sql .= ",prefix_comm = ".(! empty($this->prefix_comm)?"'".$this->db->escape($this->prefix_comm)."'":"null");
1038
-
1039
-			$sql .= ",fk_effectif = ".(! empty($this->effectif_id)?"'".$this->db->escape($this->effectif_id)."'":"null");
1040
-			if (isset($this->stcomm_id))
1041
-			{
1042
-				$sql .= ",fk_stcomm=".(!empty($this->stcomm_id)  ? $this->stcomm_id : "0");
1043
-			}
1044
-			$sql .= ",fk_typent = ".(! empty($this->typent_id)?"'".$this->db->escape($this->typent_id)."'":"0");
1045
-
1046
-			$sql .= ",fk_forme_juridique = ".(! empty($this->forme_juridique_code)?"'".$this->db->escape($this->forme_juridique_code)."'":"null");
1047
-
1048
-			$sql .= ",mode_reglement = ".(! empty($this->mode_reglement_id)?"'".$this->db->escape($this->mode_reglement_id)."'":"null");
1049
-			$sql .= ",cond_reglement = ".(! empty($this->cond_reglement_id)?"'".$this->db->escape($this->cond_reglement_id)."'":"null");
1050
-			$sql .= ",mode_reglement_supplier = ".(! empty($this->mode_reglement_supplier_id)?"'".$this->db->escape($this->mode_reglement_supplier_id)."'":"null");
1051
-			$sql .= ",cond_reglement_supplier = ".(! empty($this->cond_reglement_supplier_id)?"'".$this->db->escape($this->cond_reglement_supplier_id)."'":"null");
1052
-			$sql .= ",fk_shipping_method = ".(! empty($this->shipping_method_id)?"'".$this->db->escape($this->shipping_method_id)."'":"null");
1053
-
1054
-			$sql .= ",client = " . (! empty($this->client)?$this->client:0);
1055
-			$sql .= ",fournisseur = " . (! empty($this->fournisseur)?$this->fournisseur:0);
1056
-			$sql .= ",barcode = ".(! empty($this->barcode)?"'".$this->db->escape($this->barcode)."'":"null");
1057
-			$sql .= ",default_lang = ".(! empty($this->default_lang)?"'".$this->db->escape($this->default_lang)."'":"null");
1058
-			$sql .= ",logo = ".(! empty($this->logo)?"'".$this->db->escape($this->logo)."'":"null");
1059
-			$sql .= ",outstanding_limit= ".($this->outstanding_limit!=''?$this->outstanding_limit:'null');
1060
-			$sql .= ",order_min_amount= ".($this->order_min_amount!=''?$this->order_min_amount:'null');
1061
-			$sql .= ",supplier_order_min_amount= ".($this->supplier_order_min_amount!=''?$this->supplier_order_min_amount:'null');
1062
-			$sql .= ",fk_prospectlevel='".$this->db->escape($this->fk_prospectlevel)."'";
1063
-
1064
-			$sql .= ",webservices_url = ".(! empty($this->webservices_url)?"'".$this->db->escape($this->webservices_url)."'":"null");
1065
-			$sql .= ",webservices_key = ".(! empty($this->webservices_key)?"'".$this->db->escape($this->webservices_key)."'":"null");
1066
-
1067
-			//Incoterms
1068
-			$sql.= ", fk_incoterms = ".$this->fk_incoterms;
1069
-			$sql.= ", location_incoterms = ".(! empty($this->location_incoterms)?"'".$this->db->escape($this->location_incoterms)."'":"null");
1070
-
1071
-			if ($customer)
1072
-			{
1073
-				$sql .= ", code_client = ".(! empty($this->code_client)?"'".$this->db->escape($this->code_client)."'":"null");
1074
-				$sql .= ", code_compta = ".(! empty($this->code_compta)?"'".$this->db->escape($this->code_compta)."'":"null");
1075
-			}
1076
-
1077
-			if ($supplier)
1078
-			{
1079
-				$sql .= ", code_fournisseur = ".(! empty($this->code_fournisseur)?"'".$this->db->escape($this->code_fournisseur)."'":"null");
1080
-				$sql .= ", code_compta_fournisseur = ".(! empty($this->code_compta_fournisseur)?"'".$this->db->escape($this->code_compta_fournisseur)."'":"null");
1081
-			}
1082
-			$sql .= ", fk_user_modif = ".($user->id > 0 ? $user->id:"null");
1083
-			$sql .= ", fk_multicurrency = ".(int) $this->fk_multicurrency;
1084
-			$sql .= ", multicurrency_code = '".$this->db->escape($this->multicurrency_code)."'";
1085
-			$sql .= " WHERE rowid = " . (int) $id;
1086
-
1087
-			$resql=$this->db->query($sql);
1088
-			if ($resql)
1089
-			{
1090
-				if (is_object($this->oldcopy))	// If we have information on old values
1091
-				{
1092
-					if ($this->oldcopy->country_id != $this->country_id)
1093
-					{
1094
-						unset($this->country_code);
1095
-						unset($this->country);
1096
-					}
1097
-					if ($this->oldcopy->state_id != $this->state_id)
1098
-					{
1099
-						unset($this->state_code);
1100
-						unset($this->state);
1101
-					}
1102
-				}
1103
-				else
1104
-				{
1105
-					unset($this->country_code);	// We clean this, in the doubt, because it may have been changed after an update of country_id
1106
-					unset($this->country);
1107
-					unset($this->state_code);
1108
-					unset($this->state);
1109
-				}
1110
-
1111
-				$nbrowsaffected = $this->db->affected_rows($resql);
1112
-
1113
-				if (! $error && $nbrowsaffected)
1114
-				{
1115
-					// Update information on linked member if it is an update
1116
-					if (! $nosyncmember && ! empty($conf->adherent->enabled))
1117
-					{
1118
-						require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
1119
-
1120
-						dol_syslog(get_class($this)."::update update linked member");
1121
-
1122
-						$lmember=new Adherent($this->db);
1123
-						$result=$lmember->fetch(0, 0, $this->id);
1124
-
1125
-						if ($result > 0)
1126
-						{
1127
-							$lmember->societe=$this->name;
1128
-							//$lmember->firstname=$this->firstname?$this->firstname:$lmember->firstname;	// We keep firstname and lastname of member unchanged
1129
-							//$lmember->lastname=$this->lastname?$this->lastname:$lmember->lastname;		// We keep firstname and lastname of member unchanged
1130
-							$lmember->address=$this->address;
1131
-							$lmember->email=$this->email;
1132
-							$lmember->skype=$this->skype;
1133
-							$lmember->twitter=$this->twitter;
1134
-							$lmember->facebook=$this->facebook;
1135
-							$lmember->phone=$this->phone;
1136
-
1137
-							$result=$lmember->update($user,0,1,1,1);	// Use nosync to 1 to avoid cyclic updates
1138
-							if ($result < 0)
1139
-							{
1140
-								$this->error=$lmember->error;
1141
-								dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
1142
-								$error++;
1143
-							}
1144
-						}
1145
-						elseif ($result < 0)
1146
-						{
1147
-							$this->error=$lmember->error;
1148
-							$error++;
1149
-						}
1150
-					}
1151
-				}
1152
-
1153
-				$action='update';
1154
-
1155
-				// Actions on extra fields
1156
-				if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
1157
-				{
1158
-					$result=$this->insertExtraFields();
1159
-					if ($result < 0)
1160
-					{
1161
-						$error++;
1162
-					}
1163
-				}
1164
-
1165
-				if (! $error && $call_trigger)
1166
-				{
1167
-					// Call trigger
1168
-					$result=$this->call_trigger('COMPANY_MODIFY',$user);
1169
-					if ($result < 0) $error++;
1170
-					// End call triggers
1171
-				}
1172
-
1173
-				if (! $error)
1174
-				{
1175
-					dol_syslog(get_class($this)."::Update success");
1176
-					$this->db->commit();
1177
-					return 1;
1178
-				}
1179
-				else
1180
-				{
1181
-					$this->db->rollback();
1182
-					return -1;
1183
-				}
1184
-			}
1185
-			else
1186
-			{
1187
-				if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
1188
-				{
1189
-					// Doublon
1190
-					$this->error = $langs->trans("ErrorDuplicateField");
1191
-					$result = -1;
1192
-				}
1193
-				else
1194
-				{
1195
-					$this->error = $this->db->lasterror();
1196
-					$result = -2;
1197
-				}
1198
-				$this->db->rollback();
1199
-				return $result;
1200
-			}
1201
-		}
1202
-		else
1203
-	   {
1204
-			$this->db->rollback();
1205
-			dol_syslog(get_class($this)."::Update fails verify ".join(',',$this->errors), LOG_WARNING);
1206
-			return -3;
1207
-		}
1208
-	}
1209
-
1210
-	/**
1211
-	 *    Load a third party from database into memory
1212
-	 *
1213
-	 *    @param	int		$rowid			Id of third party to load
1214
-	 *    @param    string	$ref			Reference of third party, name (Warning, this can return several records)
1215
-	 *    @param    string	$ref_ext       	External reference of third party (Warning, this information is a free field not provided by Dolibarr)
1216
-	 *    @param    string	$ref_int       	Internal reference of third party (not used by dolibarr)
1217
-	 *    @param    string	$idprof1		Prof id 1 of third party (Warning, this can return several records)
1218
-	 *    @param    string	$idprof2		Prof id 2 of third party (Warning, this can return several records)
1219
-	 *    @param    string	$idprof3		Prof id 3 of third party (Warning, this can return several records)
1220
-	 *    @param    string	$idprof4		Prof id 4 of third party (Warning, this can return several records)
1221
-	 *    @param    string	$idprof5		Prof id 5 of third party (Warning, this can return several records)
1222
-	 *    @param    string	$idprof6		Prof id 6 of third party (Warning, this can return several records)
1223
-	 *    @param    string	$email   		Email of third party (Warning, this can return several records)
1224
-	 *    @param    string	$ref_alias 		Name_alias of third party (Warning, this can return several records)
1225
-	 *    @return   int						>0 if OK, <0 if KO or if two records found for same ref or idprof, 0 if not found.
1226
-	 */
1227
-	function fetch($rowid, $ref='', $ref_ext='', $ref_int='', $idprof1='',$idprof2='',$idprof3='',$idprof4='',$idprof5='',$idprof6='', $email='', $ref_alias='')
1228
-	{
1229
-		global $langs;
1230
-		global $conf;
1231
-
1232
-		if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($ref_int) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) return -1;
1233
-
1234
-		$sql = 'SELECT s.rowid, s.nom as name, s.name_alias, s.entity, s.ref_ext, s.ref_int, s.address, s.datec as date_creation, s.prefix_comm';
1235
-		$sql .= ', s.status';
1236
-		$sql .= ', s.price_level';
1237
-		$sql .= ', s.tms as date_modification, s.fk_user_creat, s.fk_user_modif';
1238
-		$sql .= ', s.phone, s.fax, s.email, s.skype, s.twitter, s.facebook, s.url, s.zip, s.town, s.note_private, s.note_public, s.model_pdf, s.client, s.fournisseur';
1239
-		$sql .= ', s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6';
1240
-		$sql .= ', s.capital, s.tva_intra';
1241
-		$sql .= ', s.fk_typent as typent_id';
1242
-		$sql .= ', s.fk_effectif as effectif_id';
1243
-		$sql .= ', s.fk_forme_juridique as forme_juridique_code';
1244
-		$sql .= ', s.webservices_url, s.webservices_key';
1245
-		$sql .= ', s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur, s.parent, s.barcode';
1246
-		$sql .= ', s.fk_departement, s.fk_pays as country_id, s.fk_stcomm, s.remise_client, s.remise_supplier, s.mode_reglement, s.cond_reglement, s.fk_account, s.tva_assuj';
1247
-		$sql .= ', s.mode_reglement_supplier, s.cond_reglement_supplier, s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo';
1248
-		$sql .= ', s.fk_shipping_method';
1249
-		$sql .= ', s.outstanding_limit, s.import_key, s.canvas, s.fk_incoterms, s.location_incoterms';
1250
-		$sql .= ', s.order_min_amount, s.supplier_order_min_amount';
1251
-		$sql .= ', s.fk_multicurrency, s.multicurrency_code';
1252
-		$sql .= ', fj.libelle as forme_juridique';
1253
-		$sql .= ', e.libelle as effectif';
1254
-		$sql .= ', c.code as country_code, c.label as country';
1255
-		$sql .= ', d.code_departement as state_code, d.nom as state';
1256
-		$sql .= ', st.libelle as stcomm';
1257
-		$sql .= ', te.code as typent_code';
1258
-		$sql .= ', i.libelle as libelle_incoterms';
1259
-		$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
1260
-		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as e ON s.fk_effectif = e.id';
1261
-		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid';
1262
-		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id';
1263
-		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code';
1264
-		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
1265
-		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as te ON s.fk_typent = te.id';
1266
-		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON s.fk_incoterms = i.rowid';
1267
-
1268
-		$sql .= ' WHERE s.entity IN ('.getEntity($this->element).')';
1269
-		if ($rowid)     $sql .= ' AND s.rowid = '.$rowid;
1270
-		if ($ref)       $sql .= " AND s.nom = '".$this->db->escape($ref)."'";
1271
-		if ($ref_alias) $sql .= " AND s.nom_alias = '".$this->db->escape($ref_alias)."'";
1272
-		if ($ref_ext)   $sql .= " AND s.ref_ext = '".$this->db->escape($ref_ext)."'";
1273
-		if ($ref_int)   $sql .= " AND s.ref_int = '".$this->db->escape($ref_int)."'";
1274
-		if ($idprof1)   $sql .= " AND s.siren = '".$this->db->escape($idprof1)."'";
1275
-		if ($idprof2)   $sql .= " AND s.siret = '".$this->db->escape($idprof2)."'";
1276
-		if ($idprof3)   $sql .= " AND s.ape = '".$this->db->escape($idprof3)."'";
1277
-		if ($idprof4)   $sql .= " AND s.idprof4 = '".$this->db->escape($idprof4)."'";
1278
-		if ($idprof5)   $sql .= " AND s.idprof5 = '".$this->db->escape($idprof5)."'";
1279
-		if ($idprof6)   $sql .= " AND s.idprof6 = '".$this->db->escape($idprof6)."'";
1280
-		if ($email)     $sql .= " AND s.email = '".$this->db->escape($email)."'";
1281
-
1282
-		$resql=$this->db->query($sql);
1283
-		if ($resql)
1284
-		{
1285
-			$num=$this->db->num_rows($resql);
1286
-			if ($num > 1)
1287
-			{
1288
-				$this->error='Fetch found several records. Rename one of tirdparties to avoid duplicate.';
1289
-				dol_syslog($this->error, LOG_ERR);
1290
-				$result = -2;
1291
-			}
1292
-			elseif ($num)   // $num = 1
1293
-			{
1294
-				$obj = $this->db->fetch_object($resql);
1295
-
1296
-				$this->id           = $obj->rowid;
1297
-				$this->entity       = $obj->entity;
1298
-				$this->canvas		= $obj->canvas;
1299
-
1300
-				$this->ref          = $obj->rowid;
1301
-				$this->name 		= $obj->name;
1302
-				$this->nom          = $obj->name;		// deprecated
1303
-				$this->name_alias = $obj->name_alias;
1304
-				$this->ref_ext      = $obj->ref_ext;
1305
-				$this->ref_int      = $obj->ref_int;
1306
-
1307
-				$this->date_creation     = $this->db->jdate($obj->date_creation);
1308
-				$this->date_modification = $this->db->jdate($obj->date_modification);
1309
-				$this->user_creation     = $obj->fk_user_creat;
1310
-				$this->user_modification = $obj->fk_user_modif;
1311
-
1312
-				$this->address 		= $obj->address;
1313
-				$this->zip 			= $obj->zip;
1314
-				$this->town 		= $obj->town;
1315
-
1316
-				$this->country_id   = $obj->country_id;
1317
-				$this->country_code = $obj->country_id?$obj->country_code:'';
1318
-				$this->country 		= $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->transnoentities('Country'.$obj->country_code):$obj->country):'';
1319
-
1320
-				$this->state_id     = $obj->fk_departement;
1321
-				$this->state_code   = $obj->state_code;
1322
-				$this->state        = ($obj->state!='-'?$obj->state:'');
1323
-
1324
-				$transcode=$langs->trans('StatusProspect'.$obj->fk_stcomm);
1325
-				$libelle=($transcode!='StatusProspect'.$obj->fk_stcomm?$transcode:$obj->stcomm);
1326
-				$this->stcomm_id = $obj->fk_stcomm;     // id statut commercial
1327
-				$this->statut_commercial = $libelle;    // libelle statut commercial
1328
-
1329
-				$this->email = $obj->email;
1330
-				$this->skype = $obj->skype;
1331
-				$this->twitter = $obj->twitter;
1332
-				$this->facebook = $obj->facebook;
1333
-				$this->url = $obj->url;
1334
-				$this->phone = $obj->phone;
1335
-				$this->fax = $obj->fax;
1336
-
1337
-				$this->parent    = $obj->parent;
1338
-
1339
-				$this->idprof1		= $obj->idprof1;
1340
-				$this->idprof2		= $obj->idprof2;
1341
-				$this->idprof3		= $obj->idprof3;
1342
-				$this->idprof4		= $obj->idprof4;
1343
-				$this->idprof5		= $obj->idprof5;
1344
-				$this->idprof6		= $obj->idprof6;
1345
-
1346
-				$this->capital   = $obj->capital;
1347
-
1348
-				$this->code_client = $obj->code_client;
1349
-				$this->code_fournisseur = $obj->code_fournisseur;
1350
-
1351
-				$this->code_compta = $obj->code_compta;
1352
-				$this->code_compta_fournisseur = $obj->code_compta_fournisseur;
1353
-
1354
-				$this->barcode = $obj->barcode;
1355
-
1356
-				$this->tva_assuj      = $obj->tva_assuj;
1357
-				$this->tva_intra      = $obj->tva_intra;
1358
-				$this->status = $obj->status;
1359
-
1360
-				// Local Taxes
1361
-				$this->localtax1_assuj      = $obj->localtax1_assuj;
1362
-				$this->localtax2_assuj      = $obj->localtax2_assuj;
1363
-
1364
-				$this->localtax1_value		= $obj->localtax1_value;
1365
-				$this->localtax2_value		= $obj->localtax2_value;
1366
-
1367
-				$this->typent_id      = $obj->typent_id;
1368
-				$this->typent_code    = $obj->typent_code;
1369
-
1370
-				$this->effectif_id    = $obj->effectif_id;
1371
-				$this->effectif       = $obj->effectif_id?$obj->effectif:'';
1372
-
1373
-				$this->forme_juridique_code= $obj->forme_juridique_code;
1374
-				$this->forme_juridique     = $obj->forme_juridique_code?$obj->forme_juridique:'';
1375
-
1376
-				$this->fk_prospectlevel = $obj->fk_prospectlevel;
1377
-
1378
-				$this->prefix_comm = $obj->prefix_comm;
1379
-
1380
-				$this->remise_percent		= $obj->remise_client;
1381
-				$this->remise_supplier_percent		= $obj->remise_supplier;
1382
-				$this->mode_reglement_id 	= $obj->mode_reglement;
1383
-				$this->cond_reglement_id 	= $obj->cond_reglement;
1384
-				$this->mode_reglement_supplier_id 	= $obj->mode_reglement_supplier;
1385
-				$this->cond_reglement_supplier_id 	= $obj->cond_reglement_supplier;
1386
-				$this->shipping_method_id   = ($obj->fk_shipping_method>0)?$obj->fk_shipping_method:null;
1387
-				$this->fk_account			= $obj->fk_account;
1388
-
1389
-				$this->client      = $obj->client;
1390
-				$this->fournisseur = $obj->fournisseur;
1391
-
1392
-				$this->note = $obj->note_private; // TODO Deprecated for backward comtability
1393
-				$this->note_private = $obj->note_private;
1394
-				$this->note_public = $obj->note_public;
1395
-				$this->modelpdf = $obj->model_pdf;
1396
-				$this->default_lang = $obj->default_lang;
1397
-				$this->logo = $obj->logo;
1398
-
1399
-				$this->webservices_url = $obj->webservices_url;
1400
-				$this->webservices_key = $obj->webservices_key;
1401
-
1402
-				$this->outstanding_limit		= $obj->outstanding_limit;
1403
-				$this->order_min_amount			= $obj->order_min_amount;
1404
-				$this->supplier_order_min_amount	= $obj->supplier_order_min_amount;
1405
-
1406
-				// multiprix
1407
-				$this->price_level = $obj->price_level;
1408
-
1409
-				$this->import_key = $obj->import_key;
1410
-
1411
-				//Incoterms
1412
-				$this->fk_incoterms = $obj->fk_incoterms;
1413
-				$this->location_incoterms = $obj->location_incoterms;
1414
-				$this->libelle_incoterms = $obj->libelle_incoterms;
1415
-
1416
-				// multicurrency
1417
-				$this->fk_multicurrency = $obj->fk_multicurrency;
1418
-				$this->multicurrency_code = $obj->multicurrency_code;
1419
-
1420
-				$result = 1;
1421
-
1422
-				// fetch optionals attributes and labels
1423
-				$this->fetch_optionals();
1424
-			}
1425
-			else
1426
-			{
1427
-				$result = 0;
1428
-			}
1429
-
1430
-			$this->db->free($resql);
1431
-		}
1432
-		else
1433
-		{
1434
-			$this->error=$this->db->lasterror();
1435
-			$result = -3;
1436
-		}
1437
-
1438
-		// Use first price level if level not defined for third party
1439
-		if (! empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->price_level)) $this->price_level=1;
1440
-
1441
-		return $result;
1442
-	}
1443
-
1444
-	/**
1445
-	 *    Delete a third party from database and all its dependencies (contacts, rib...)
1446
-	 *
1447
-	 *    @param	int		$id             Id of third party to delete
1448
-	 *    @param    User    $fuser          User who ask to delete thirparty
1449
-	 *    @param    int		$call_trigger   0=No, 1=yes
1450
-	 *    @return	int						<0 if KO, 0 if nothing done, >0 if OK
1451
-	 */
1452
-	function delete($id, User $fuser=null, $call_trigger=1)
1453
-	{
1454
-		global $langs, $conf, $user;
1455
-
1456
-		if (empty($fuser)) $fuser=$user;
1457
-
1458
-		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1459
-
1460
-		$entity=isset($this->entity)?$this->entity:$conf->entity;
1461
-
1462
-		dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1463
-		$error = 0;
1464
-
1465
-		// Test if child exists
1466
-		$objectisused = $this->isObjectUsed($id);
1467
-		if (empty($objectisused))
1468
-		{
1469
-			$this->db->begin();
1470
-
1471
-			// User is mandatory for trigger call
1472
-			if (! $error && $call_trigger)
1473
-			{
1474
-				// Call trigger
1475
-				$result=$this->call_trigger('COMPANY_DELETE',$fuser);
1476
-				if ($result < 0) $error++;
1477
-				// End call triggers
1478
-			}
1479
-
1480
-			if (! $error)
1481
-			{
1482
-				require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1483
-				$static_cat = new Categorie($this->db);
1484
-				$toute_categs = array();
1485
-
1486
-				// Fill $toute_categs array with an array of (type => array of ("Categorie" instance))
1487
-				if ($this->client || $this->prospect)
1488
-				{
1489
-					$toute_categs['customer'] = $static_cat->containing($this->id,Categorie::TYPE_CUSTOMER);
1490
-				}
1491
-				if ($this->fournisseur)
1492
-				{
1493
-					$toute_categs['supplier'] = $static_cat->containing($this->id,Categorie::TYPE_SUPPLIER);
1494
-				}
1495
-
1496
-				// Remove each "Categorie"
1497
-				foreach ($toute_categs as $type => $categs_type)
1498
-				{
1499
-					foreach ($categs_type as $cat)
1500
-					{
1501
-						$cat->del_type($this, $type);
1502
-					}
1503
-				}
1504
-			}
1505
-
1506
-			foreach ($this->childtablesoncascade as $tabletodelete)
1507
-			{
1508
-				if (! $error)
1509
-				{
1510
-					$sql = "DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete;
1511
-					$sql.= " WHERE fk_soc = " . $id;
1512
-					if (! $this->db->query($sql))
1513
-					{
1514
-						$error++;
1515
-						$this->errors[] = $this->db->lasterror();
1516
-					}
1517
-				}
1518
-			}
1519
-
1520
-			// Removed extrafields
1521
-			if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
1522
-			{
1523
-				$result=$this->deleteExtraFields();
1524
-				if ($result < 0)
1525
-				{
1526
-					$error++;
1527
-					dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR);
1528
-				}
1529
-			}
1530
-
1531
-			// Remove links to subsidiaries companies
1532
-			if (! $error)
1533
-			{
1534
-				$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
1535
-				$sql.= " SET parent = NULL";
1536
-				$sql.= " WHERE parent = " . $id;
1537
-				if (! $this->db->query($sql))
1538
-				{
1539
-					$error++;
1540
-					$this->errors[] = $this->db->lasterror();
1541
-				}
1542
-			}
1543
-
1544
-			// Remove third party
1545
-			if (! $error)
1546
-			{
1547
-				$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe";
1548
-				$sql.= " WHERE rowid = " . $id;
1549
-				if (! $this->db->query($sql))
1550
-				{
1551
-					$error++;
1552
-					$this->errors[] = $this->db->lasterror();
1553
-				}
1554
-			}
1555
-
1556
-			if (! $error)
1557
-			{
1558
-				$this->db->commit();
1559
-
1560
-				// Delete directory
1561
-				if (! empty($conf->societe->multidir_output[$entity]))
1562
-				{
1563
-					$docdir = $conf->societe->multidir_output[$entity] . "/" . $id;
1564
-					if (dol_is_dir($docdir))
1565
-					{
1566
-						dol_delete_dir_recursive($docdir);
1567
-					}
1568
-				}
1569
-
1570
-				return 1;
1571
-			}
1572
-			else
1573
-			{
1574
-				dol_syslog($this->error, LOG_ERR);
1575
-				$this->db->rollback();
1576
-				return -1;
1577
-			}
1578
-		}
1579
-		else dol_syslog("Can't remove thirdparty with id ".$id.". There is ".$objectisused." childs", LOG_WARNING);
1580
-		return 0;
1581
-	}
635
+        require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
636
+        $contact=new Contact($this->db);
637
+
638
+        $contact->name              = $this->name_bis;
639
+        $contact->firstname         = $this->firstname;
640
+        $contact->civility_id       = $this->civility_id;
641
+        $contact->socid             = $this->id;	// fk_soc
642
+        $contact->statut            = 1;
643
+        $contact->priv              = 0;
644
+        $contact->country_id        = $this->country_id;
645
+        $contact->state_id          = $this->state_id;
646
+        $contact->address           = $this->address;
647
+        $contact->email             = $this->email;
648
+        $contact->zip               = $this->zip;
649
+        $contact->town              = $this->town;
650
+        $contact->phone_pro         = $this->phone;
651
+
652
+        $result = $contact->create($user);
653
+        if ($result < 0)
654
+        {
655
+            $this->error = $contact->error;
656
+            $this->errors = $contact->errors;
657
+            dol_syslog(get_class($this)."::create_individual ERROR:" . $this->error, LOG_ERR);
658
+        }
659
+
660
+        return $result;
661
+    }
662
+
663
+    /**
664
+     *    Check properties of third party are ok (like name, third party codes, ...)
665
+     *    Used before an add or update.
666
+     *
667
+     *    @return     int		0 if OK, <0 if KO
668
+     */
669
+    function verify()
670
+    {
671
+        global $conf, $langs, $mysoc;
672
+
673
+        $error = 0;
674
+        $this->errors=array();
675
+
676
+        $result = 0;
677
+        $this->name	= trim($this->name);
678
+        $this->nom=$this->name; // For backward compatibility
679
+
680
+        if (! $this->name)
681
+        {
682
+            $this->errors[] = 'ErrorBadThirdPartyName';
683
+            $result = -2;
684
+        }
685
+
686
+        if ($this->client)
687
+        {
688
+            $rescode = $this->check_codeclient();
689
+            if ($rescode <> 0)
690
+            {
691
+                if ($rescode == -1)
692
+                {
693
+                    $this->errors[] = 'ErrorBadCustomerCodeSyntax';
694
+                }
695
+                elseif ($rescode == -2)
696
+                {
697
+                    $this->errors[] = 'ErrorCustomerCodeRequired';
698
+                }
699
+                elseif ($rescode == -3)
700
+                {
701
+                    $this->errors[] = 'ErrorCustomerCodeAlreadyUsed';
702
+                }
703
+                elseif ($rescode == -4)
704
+                {
705
+                    $this->errors[] = 'ErrorPrefixRequired';
706
+                }
707
+                $result = -3;
708
+            }
709
+        }
710
+
711
+        if ($this->fournisseur)
712
+        {
713
+            $rescode = $this->check_codefournisseur();
714
+            if ($rescode <> 0)
715
+            {
716
+                if ($rescode == -1)
717
+                {
718
+                    $this->errors[] = 'ErrorBadSupplierCodeSyntax';
719
+                }
720
+                elseif ($rescode == -2)
721
+                {
722
+                    $this->errors[] = 'ErrorSupplierCodeRequired';
723
+                }
724
+                elseif ($rescode == -3)
725
+                {
726
+                    $this->errors[] = 'ErrorSupplierCodeAlreadyUsed';
727
+                }
728
+                elseif ($rescode == -5)
729
+                {
730
+                    $this->errors[] = 'ErrorprefixRequired';
731
+                }
732
+                $result = -3;
733
+            }
734
+        }
735
+
736
+        // Check for duplicate or mandatory fields defined into setup
737
+        $array_to_check=array('IDPROF1','IDPROF2','IDPROF3','IDPROF4','IDPROF5','IDPROF6','EMAIL');
738
+        foreach($array_to_check as $key)
739
+        {
740
+            $keymin=strtolower($key);
741
+            $i=(int) preg_replace('/[^0-9]/','',$key);
742
+            $vallabel=$this->$keymin;
743
+
744
+            if ($i > 0)
745
+            {
746
+                if ($this->isACompany())
747
+                {
748
+                    // Check for unicity
749
+                    if ($vallabel && $this->id_prof_verifiable($i))
750
+                    {
751
+                        if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0)))
752
+                        {
753
+                            $langs->load("errors");
754
+                            $error++; $this->errors[] = $langs->transcountry('ProfId'.$i, $this->country_code)." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')';
755
+                        }
756
+                    }
757
+
758
+                    // Check for mandatory prof id (but only if country is other than ours)
759
+                    if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id)
760
+                    {
761
+                        $idprof_mandatory ='SOCIETE_'.$key.'_MANDATORY';
762
+                        if (! $vallabel && ! empty($conf->global->$idprof_mandatory))
763
+                        {
764
+                            $langs->load("errors");
765
+                            $error++;
766
+                            $this->errors[] = $langs->trans("ErrorProdIdIsMandatory", $langs->transcountry('ProfId'.$i, $this->country_code)).' ('.$langs->trans("ForbiddenBySetupRules").')';
767
+                        }
768
+                    }
769
+                }
770
+            }
771
+            else
772
+            {
773
+                //var_dump($conf->global->SOCIETE_EMAIL_UNIQUE);
774
+                //var_dump($conf->global->SOCIETE_EMAIL_MANDATORY);
775
+                if ($key == 'EMAIL')
776
+                {
777
+                    // Check for unicity
778
+                    if ($vallabel && ! empty($conf->global->SOCIETE_EMAIL_UNIQUE))
779
+                    {
780
+                        if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0)))
781
+                        {
782
+                            $langs->load("errors");
783
+                            $error++; $this->errors[] = $langs->trans('Email')." ".$langs->trans("ErrorProdIdAlreadyExist", $vallabel).' ('.$langs->trans("ForbiddenBySetupRules").')';
784
+                        }
785
+                    }
786
+
787
+                    // Check for mandatory
788
+                    if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY) && ! isValidEMail($this->email))
789
+                    {
790
+                        $langs->load("errors");
791
+                        $error++;
792
+                        $this->errors[] = $langs->trans("ErrorBadEMail", $this->email).' ('.$langs->trans("ForbiddenBySetupRules").')';
793
+                    }
794
+                }
795
+            }
796
+        }
797
+
798
+        if ($error) $result = -4;
799
+
800
+        return $result;
801
+    }
802
+
803
+    /**
804
+     *      Update parameters of third party
805
+     *
806
+     *      @param	int		$id              			Id of company (deprecated, use 0 here and call update on an object loaded by a fetch)
807
+     *      @param  User	$user            			Utilisateur qui demande la mise a jour
808
+     *      @param  int		$call_trigger    			0=no, 1=yes
809
+     *		@param	int		$allowmodcodeclient			Inclut modif code client et code compta
810
+     *		@param	int		$allowmodcodefournisseur	Inclut modif code fournisseur et code compta fournisseur
811
+     *		@param	string	$action						'add' or 'update' or 'merge'
812
+     *		@param	int		$nosyncmember				Do not synchronize info of linked member
813
+     *      @return int  			           			<0 if KO, >=0 if OK
814
+     */
815
+    function update($id, $user='', $call_trigger=1, $allowmodcodeclient=0, $allowmodcodefournisseur=0, $action='update', $nosyncmember=1)
816
+    {
817
+        global $langs,$conf,$hookmanager;
818
+
819
+        require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
820
+
821
+        if (empty($id)) $id = $this->id;
822
+
823
+        $error=0;
824
+
825
+        dol_syslog(get_class($this)."::Update id=".$id." call_trigger=".$call_trigger." allowmodcodeclient=".$allowmodcodeclient." allowmodcodefournisseur=".$allowmodcodefournisseur);
826
+
827
+        $now=dol_now();
828
+
829
+        // Clean parameters
830
+        $this->id			= $id;
831
+        $this->entity		= ((isset($this->entity) && is_numeric($this->entity))?$this->entity:$conf->entity);
832
+        $this->name			= $this->name?trim($this->name):trim($this->nom);
833
+        $this->nom			= $this->name;	// For backward compatibility
834
+        $this->name_alias	= trim($this->name_alias);
835
+        $this->ref_ext		= trim($this->ref_ext);
836
+        $this->address		= $this->address?trim($this->address):trim($this->address);
837
+        $this->zip			= $this->zip?trim($this->zip):trim($this->zip);
838
+        $this->town			= $this->town?trim($this->town):trim($this->town);
839
+        $this->state_id		= trim($this->state_id);
840
+        $this->country_id	= ($this->country_id > 0)?$this->country_id:0;
841
+        $this->phone		= trim($this->phone);
842
+        $this->phone		= preg_replace("/\s/","",$this->phone);
843
+        $this->phone		= preg_replace("/\./","",$this->phone);
844
+        $this->fax			= trim($this->fax);
845
+        $this->fax			= preg_replace("/\s/","",$this->fax);
846
+        $this->fax			= preg_replace("/\./","",$this->fax);
847
+        $this->email		= trim($this->email);
848
+        $this->skype		= trim($this->skype);
849
+        $this->twitter		= trim($this->twitter);
850
+        $this->facebook		= trim($this->facebook);
851
+        $this->url			= $this->url?clean_url($this->url,0):'';
852
+        $this->note_private = trim($this->note_private);
853
+        $this->note_public  = trim($this->note_public);
854
+        $this->idprof1		= trim($this->idprof1);
855
+        $this->idprof2		= trim($this->idprof2);
856
+        $this->idprof3		= trim($this->idprof3);
857
+        $this->idprof4		= trim($this->idprof4);
858
+        $this->idprof5		= (! empty($this->idprof5)?trim($this->idprof5):'');
859
+        $this->idprof6		= (! empty($this->idprof6)?trim($this->idprof6):'');
860
+        $this->prefix_comm	= trim($this->prefix_comm);
861
+        $this->outstanding_limit = price2num($this->outstanding_limit);
862
+        $this->order_min_amount = price2num($this->order_min_amount);
863
+        $this->supplier_order_min_amount = price2num($this->supplier_order_min_amount);
864
+
865
+        $this->tva_assuj	= trim($this->tva_assuj);
866
+        $this->tva_intra	= dol_sanitizeFileName($this->tva_intra,'');
867
+        if (empty($this->status)) $this->status = 0;
868
+
869
+        if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
870
+        if (empty($this->fk_multicurrency))
871
+        {
872
+            $this->multicurrency_code = '';
873
+            $this->fk_multicurrency = 0;
874
+        }
875
+
876
+        // Local taxes
877
+        $this->localtax1_assuj=trim($this->localtax1_assuj);
878
+        $this->localtax2_assuj=trim($this->localtax2_assuj);
879
+
880
+        $this->localtax1_value=trim($this->localtax1_value);
881
+        $this->localtax2_value=trim($this->localtax2_value);
882
+
883
+        if ($this->capital != '') $this->capital=price2num(trim($this->capital));
884
+        if (! is_numeric($this->capital)) $this->capital = '';     // '' = undef
885
+
886
+        $this->effectif_id=trim($this->effectif_id);
887
+        $this->forme_juridique_code=trim($this->forme_juridique_code);
888
+
889
+        //Gencod
890
+        $this->barcode=trim($this->barcode);
891
+
892
+        // For automatic creation
893
+        if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this,0);
894
+        if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this,1);
895
+
896
+        $this->code_compta=trim($this->code_compta);
897
+        $this->code_compta_fournisseur=trim($this->code_compta_fournisseur);
898
+
899
+        // Check parameters. More tests are done later in the ->verify()
900
+        if (! is_numeric($this->client) && ! is_numeric($this->fournisseur))
901
+        {
902
+            $langs->load("errors");
903
+            $this->error = $langs->trans("BadValueForParameterClientOrSupplier");
904
+            return -1;
905
+        }
906
+
907
+        $customer=false;
908
+        if (! empty($allowmodcodeclient) && ! empty($this->client))
909
+        {
910
+            // Attention get_codecompta peut modifier le code suivant le module utilise
911
+            if (empty($this->code_compta))
912
+            {
913
+                $ret=$this->get_codecompta('customer');
914
+                if ($ret < 0) return -1;
915
+            }
916
+
917
+            $customer=true;
918
+        }
919
+
920
+        $supplier=false;
921
+        if (! empty($allowmodcodefournisseur) && ! empty($this->fournisseur))
922
+        {
923
+            // Attention get_codecompta peut modifier le code suivant le module utilise
924
+            if (empty($this->code_compta_fournisseur))
925
+            {
926
+                $ret=$this->get_codecompta('supplier');
927
+                if ($ret < 0) return -1;
928
+            }
929
+
930
+            $supplier=true;
931
+        }
932
+
933
+        //Web services
934
+        $this->webservices_url = $this->webservices_url?clean_url($this->webservices_url,0):'';
935
+        $this->webservices_key = trim($this->webservices_key);
936
+
937
+        //Incoterms
938
+        $this->fk_incoterms = (int) $this->fk_incoterms;
939
+        $this->location_incoterms = trim($this->location_incoterms);
940
+
941
+        $this->db->begin();
942
+
943
+        // Check name is required and codes are ok or unique.
944
+        // If error, this->errors[] is filled
945
+        $result = 0;
946
+        if ($action != 'add' && $action != 'merge')
947
+        {
948
+            // We don't check when update called during a create because verify was already done.
949
+            // For a merge, we suppose source data is clean and a customer code of a deleted thirdparty must be accepted into a target thirdparty with empty code without duplicate error
950
+            $result = $this->verify();
951
+
952
+            // If there is only one error and error is ErrorBadCustomerCodeSyntax and we don't change customer code, we allow the update
953
+            // So we can update record that were using and old numbering rule.
954
+            if (is_array($this->errors))
955
+            {
956
+                if (in_array('ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client)
957
+                {
958
+                    if (($key = array_search('ErrorBadCustomerCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]);	// Remove error message
959
+                }
960
+                if (in_array('ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur)
961
+                {
962
+                    if (($key = array_search('ErrorBadSupplierCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]);	// Remove error message
963
+                }
964
+                if (empty($this->errors))	// If there is no more error, we can make like if there is no error at all
965
+                {
966
+                    $result = 0;
967
+                }
968
+            }
969
+        }
970
+
971
+        if ($result >= 0)
972
+        {
973
+            dol_syslog(get_class($this)."::update verify ok or not done");
974
+
975
+            $sql  = "UPDATE ".MAIN_DB_PREFIX."societe SET ";
976
+            $sql .= "entity = " . $this->db->escape($this->entity);
977
+            $sql .= ",nom = '" . $this->db->escape($this->name) ."'"; // Required
978
+            $sql .= ",name_alias = '" . $this->db->escape($this->name_alias) ."'";
979
+            $sql .= ",ref_ext = " .(! empty($this->ref_ext)?"'".$this->db->escape($this->ref_ext) ."'":"null");
980
+            $sql .= ",address = '" . $this->db->escape($this->address) ."'";
981
+
982
+            $sql .= ",zip = ".(! empty($this->zip)?"'".$this->db->escape($this->zip)."'":"null");
983
+            $sql .= ",town = ".(! empty($this->town)?"'".$this->db->escape($this->town)."'":"null");
984
+
985
+            $sql .= ",fk_departement = '" . (! empty($this->state_id)?$this->state_id:'0') ."'";
986
+            $sql .= ",fk_pays = '" . (! empty($this->country_id)?$this->country_id:'0') ."'";
987
+
988
+            $sql .= ",phone = ".(! empty($this->phone)?"'".$this->db->escape($this->phone)."'":"null");
989
+            $sql .= ",fax = ".(! empty($this->fax)?"'".$this->db->escape($this->fax)."'":"null");
990
+            $sql .= ",email = ".(! empty($this->email)?"'".$this->db->escape($this->email)."'":"null");
991
+            $sql .= ",skype = ".(! empty($this->skype)?"'".$this->db->escape($this->skype)."'":"null");
992
+            $sql .= ",twitter = ".(! empty($this->twitter)?"'".$this->db->escape($this->twitter)."'":"null");
993
+            $sql .= ",facebook = ".(! empty($this->facebook)?"'".$this->db->escape($this->facebook)."'":"null");
994
+            $sql .= ",url = ".(! empty($this->url)?"'".$this->db->escape($this->url)."'":"null");
995
+
996
+            $sql .= ",parent = " . ($this->parent > 0 ? $this->parent : "null");
997
+
998
+            $sql .= ",note_private = ".(! empty($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null");
999
+            $sql .= ",note_public = ".(! empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null");
1000
+
1001
+            $sql .= ",siren   = '". $this->db->escape($this->idprof1) ."'";
1002
+            $sql .= ",siret   = '". $this->db->escape($this->idprof2) ."'";
1003
+            $sql .= ",ape     = '". $this->db->escape($this->idprof3) ."'";
1004
+            $sql .= ",idprof4 = '". $this->db->escape($this->idprof4) ."'";
1005
+            $sql .= ",idprof5 = '". $this->db->escape($this->idprof5) ."'";
1006
+            $sql .= ",idprof6 = '". $this->db->escape($this->idprof6) ."'";
1007
+
1008
+            $sql .= ",tva_assuj = ".($this->tva_assuj!=''?"'".$this->db->escape($this->tva_assuj)."'":"null");
1009
+            $sql .= ",tva_intra = '" . $this->db->escape($this->tva_intra) ."'";
1010
+            $sql .= ",status = " .$this->status;
1011
+
1012
+            // Local taxes
1013
+            $sql .= ",localtax1_assuj = ".($this->localtax1_assuj!=''?"'".$this->db->escape($this->localtax1_assuj)."'":"null");
1014
+            $sql .= ",localtax2_assuj = ".($this->localtax2_assuj!=''?"'".$this->db->escape($this->localtax2_assuj)."'":"null");
1015
+            if($this->localtax1_assuj==1)
1016
+            {
1017
+                if($this->localtax1_value!='')
1018
+                {
1019
+                    $sql .=",localtax1_value =".$this->localtax1_value;
1020
+                }
1021
+                else $sql .=",localtax1_value =0.000";
1022
+            }
1023
+            else $sql .=",localtax1_value =0.000";
1024
+
1025
+            if($this->localtax2_assuj==1)
1026
+            {
1027
+                if($this->localtax2_value!='')
1028
+                {
1029
+                    $sql .=",localtax2_value =".$this->localtax2_value;
1030
+                }
1031
+                else $sql .=",localtax2_value =0.000";
1032
+            }
1033
+            else $sql .=",localtax2_value =0.000";
1034
+
1035
+            $sql .= ",capital = ".($this->capital == '' ? "null" : $this->capital);
1036
+
1037
+            $sql .= ",prefix_comm = ".(! empty($this->prefix_comm)?"'".$this->db->escape($this->prefix_comm)."'":"null");
1038
+
1039
+            $sql .= ",fk_effectif = ".(! empty($this->effectif_id)?"'".$this->db->escape($this->effectif_id)."'":"null");
1040
+            if (isset($this->stcomm_id))
1041
+            {
1042
+                $sql .= ",fk_stcomm=".(!empty($this->stcomm_id)  ? $this->stcomm_id : "0");
1043
+            }
1044
+            $sql .= ",fk_typent = ".(! empty($this->typent_id)?"'".$this->db->escape($this->typent_id)."'":"0");
1045
+
1046
+            $sql .= ",fk_forme_juridique = ".(! empty($this->forme_juridique_code)?"'".$this->db->escape($this->forme_juridique_code)."'":"null");
1047
+
1048
+            $sql .= ",mode_reglement = ".(! empty($this->mode_reglement_id)?"'".$this->db->escape($this->mode_reglement_id)."'":"null");
1049
+            $sql .= ",cond_reglement = ".(! empty($this->cond_reglement_id)?"'".$this->db->escape($this->cond_reglement_id)."'":"null");
1050
+            $sql .= ",mode_reglement_supplier = ".(! empty($this->mode_reglement_supplier_id)?"'".$this->db->escape($this->mode_reglement_supplier_id)."'":"null");
1051
+            $sql .= ",cond_reglement_supplier = ".(! empty($this->cond_reglement_supplier_id)?"'".$this->db->escape($this->cond_reglement_supplier_id)."'":"null");
1052
+            $sql .= ",fk_shipping_method = ".(! empty($this->shipping_method_id)?"'".$this->db->escape($this->shipping_method_id)."'":"null");
1053
+
1054
+            $sql .= ",client = " . (! empty($this->client)?$this->client:0);
1055
+            $sql .= ",fournisseur = " . (! empty($this->fournisseur)?$this->fournisseur:0);
1056
+            $sql .= ",barcode = ".(! empty($this->barcode)?"'".$this->db->escape($this->barcode)."'":"null");
1057
+            $sql .= ",default_lang = ".(! empty($this->default_lang)?"'".$this->db->escape($this->default_lang)."'":"null");
1058
+            $sql .= ",logo = ".(! empty($this->logo)?"'".$this->db->escape($this->logo)."'":"null");
1059
+            $sql .= ",outstanding_limit= ".($this->outstanding_limit!=''?$this->outstanding_limit:'null');
1060
+            $sql .= ",order_min_amount= ".($this->order_min_amount!=''?$this->order_min_amount:'null');
1061
+            $sql .= ",supplier_order_min_amount= ".($this->supplier_order_min_amount!=''?$this->supplier_order_min_amount:'null');
1062
+            $sql .= ",fk_prospectlevel='".$this->db->escape($this->fk_prospectlevel)."'";
1063
+
1064
+            $sql .= ",webservices_url = ".(! empty($this->webservices_url)?"'".$this->db->escape($this->webservices_url)."'":"null");
1065
+            $sql .= ",webservices_key = ".(! empty($this->webservices_key)?"'".$this->db->escape($this->webservices_key)."'":"null");
1066
+
1067
+            //Incoterms
1068
+            $sql.= ", fk_incoterms = ".$this->fk_incoterms;
1069
+            $sql.= ", location_incoterms = ".(! empty($this->location_incoterms)?"'".$this->db->escape($this->location_incoterms)."'":"null");
1070
+
1071
+            if ($customer)
1072
+            {
1073
+                $sql .= ", code_client = ".(! empty($this->code_client)?"'".$this->db->escape($this->code_client)."'":"null");
1074
+                $sql .= ", code_compta = ".(! empty($this->code_compta)?"'".$this->db->escape($this->code_compta)."'":"null");
1075
+            }
1076
+
1077
+            if ($supplier)
1078
+            {
1079
+                $sql .= ", code_fournisseur = ".(! empty($this->code_fournisseur)?"'".$this->db->escape($this->code_fournisseur)."'":"null");
1080
+                $sql .= ", code_compta_fournisseur = ".(! empty($this->code_compta_fournisseur)?"'".$this->db->escape($this->code_compta_fournisseur)."'":"null");
1081
+            }
1082
+            $sql .= ", fk_user_modif = ".($user->id > 0 ? $user->id:"null");
1083
+            $sql .= ", fk_multicurrency = ".(int) $this->fk_multicurrency;
1084
+            $sql .= ", multicurrency_code = '".$this->db->escape($this->multicurrency_code)."'";
1085
+            $sql .= " WHERE rowid = " . (int) $id;
1086
+
1087
+            $resql=$this->db->query($sql);
1088
+            if ($resql)
1089
+            {
1090
+                if (is_object($this->oldcopy))	// If we have information on old values
1091
+                {
1092
+                    if ($this->oldcopy->country_id != $this->country_id)
1093
+                    {
1094
+                        unset($this->country_code);
1095
+                        unset($this->country);
1096
+                    }
1097
+                    if ($this->oldcopy->state_id != $this->state_id)
1098
+                    {
1099
+                        unset($this->state_code);
1100
+                        unset($this->state);
1101
+                    }
1102
+                }
1103
+                else
1104
+                {
1105
+                    unset($this->country_code);	// We clean this, in the doubt, because it may have been changed after an update of country_id
1106
+                    unset($this->country);
1107
+                    unset($this->state_code);
1108
+                    unset($this->state);
1109
+                }
1110
+
1111
+                $nbrowsaffected = $this->db->affected_rows($resql);
1112
+
1113
+                if (! $error && $nbrowsaffected)
1114
+                {
1115
+                    // Update information on linked member if it is an update
1116
+                    if (! $nosyncmember && ! empty($conf->adherent->enabled))
1117
+                    {
1118
+                        require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
1119
+
1120
+                        dol_syslog(get_class($this)."::update update linked member");
1121
+
1122
+                        $lmember=new Adherent($this->db);
1123
+                        $result=$lmember->fetch(0, 0, $this->id);
1124
+
1125
+                        if ($result > 0)
1126
+                        {
1127
+                            $lmember->societe=$this->name;
1128
+                            //$lmember->firstname=$this->firstname?$this->firstname:$lmember->firstname;	// We keep firstname and lastname of member unchanged
1129
+                            //$lmember->lastname=$this->lastname?$this->lastname:$lmember->lastname;		// We keep firstname and lastname of member unchanged
1130
+                            $lmember->address=$this->address;
1131
+                            $lmember->email=$this->email;
1132
+                            $lmember->skype=$this->skype;
1133
+                            $lmember->twitter=$this->twitter;
1134
+                            $lmember->facebook=$this->facebook;
1135
+                            $lmember->phone=$this->phone;
1136
+
1137
+                            $result=$lmember->update($user,0,1,1,1);	// Use nosync to 1 to avoid cyclic updates
1138
+                            if ($result < 0)
1139
+                            {
1140
+                                $this->error=$lmember->error;
1141
+                                dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
1142
+                                $error++;
1143
+                            }
1144
+                        }
1145
+                        elseif ($result < 0)
1146
+                        {
1147
+                            $this->error=$lmember->error;
1148
+                            $error++;
1149
+                        }
1150
+                    }
1151
+                }
1152
+
1153
+                $action='update';
1154
+
1155
+                // Actions on extra fields
1156
+                if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
1157
+                {
1158
+                    $result=$this->insertExtraFields();
1159
+                    if ($result < 0)
1160
+                    {
1161
+                        $error++;
1162
+                    }
1163
+                }
1164
+
1165
+                if (! $error && $call_trigger)
1166
+                {
1167
+                    // Call trigger
1168
+                    $result=$this->call_trigger('COMPANY_MODIFY',$user);
1169
+                    if ($result < 0) $error++;
1170
+                    // End call triggers
1171
+                }
1172
+
1173
+                if (! $error)
1174
+                {
1175
+                    dol_syslog(get_class($this)."::Update success");
1176
+                    $this->db->commit();
1177
+                    return 1;
1178
+                }
1179
+                else
1180
+                {
1181
+                    $this->db->rollback();
1182
+                    return -1;
1183
+                }
1184
+            }
1185
+            else
1186
+            {
1187
+                if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
1188
+                {
1189
+                    // Doublon
1190
+                    $this->error = $langs->trans("ErrorDuplicateField");
1191
+                    $result = -1;
1192
+                }
1193
+                else
1194
+                {
1195
+                    $this->error = $this->db->lasterror();
1196
+                    $result = -2;
1197
+                }
1198
+                $this->db->rollback();
1199
+                return $result;
1200
+            }
1201
+        }
1202
+        else
1203
+        {
1204
+            $this->db->rollback();
1205
+            dol_syslog(get_class($this)."::Update fails verify ".join(',',$this->errors), LOG_WARNING);
1206
+            return -3;
1207
+        }
1208
+    }
1209
+
1210
+    /**
1211
+     *    Load a third party from database into memory
1212
+     *
1213
+     *    @param	int		$rowid			Id of third party to load
1214
+     *    @param    string	$ref			Reference of third party, name (Warning, this can return several records)
1215
+     *    @param    string	$ref_ext       	External reference of third party (Warning, this information is a free field not provided by Dolibarr)
1216
+     *    @param    string	$ref_int       	Internal reference of third party (not used by dolibarr)
1217
+     *    @param    string	$idprof1		Prof id 1 of third party (Warning, this can return several records)
1218
+     *    @param    string	$idprof2		Prof id 2 of third party (Warning, this can return several records)
1219
+     *    @param    string	$idprof3		Prof id 3 of third party (Warning, this can return several records)
1220
+     *    @param    string	$idprof4		Prof id 4 of third party (Warning, this can return several records)
1221
+     *    @param    string	$idprof5		Prof id 5 of third party (Warning, this can return several records)
1222
+     *    @param    string	$idprof6		Prof id 6 of third party (Warning, this can return several records)
1223
+     *    @param    string	$email   		Email of third party (Warning, this can return several records)
1224
+     *    @param    string	$ref_alias 		Name_alias of third party (Warning, this can return several records)
1225
+     *    @return   int						>0 if OK, <0 if KO or if two records found for same ref or idprof, 0 if not found.
1226
+     */
1227
+    function fetch($rowid, $ref='', $ref_ext='', $ref_int='', $idprof1='',$idprof2='',$idprof3='',$idprof4='',$idprof5='',$idprof6='', $email='', $ref_alias='')
1228
+    {
1229
+        global $langs;
1230
+        global $conf;
1231
+
1232
+        if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($ref_int) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) return -1;
1233
+
1234
+        $sql = 'SELECT s.rowid, s.nom as name, s.name_alias, s.entity, s.ref_ext, s.ref_int, s.address, s.datec as date_creation, s.prefix_comm';
1235
+        $sql .= ', s.status';
1236
+        $sql .= ', s.price_level';
1237
+        $sql .= ', s.tms as date_modification, s.fk_user_creat, s.fk_user_modif';
1238
+        $sql .= ', s.phone, s.fax, s.email, s.skype, s.twitter, s.facebook, s.url, s.zip, s.town, s.note_private, s.note_public, s.model_pdf, s.client, s.fournisseur';
1239
+        $sql .= ', s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4, s.idprof5, s.idprof6';
1240
+        $sql .= ', s.capital, s.tva_intra';
1241
+        $sql .= ', s.fk_typent as typent_id';
1242
+        $sql .= ', s.fk_effectif as effectif_id';
1243
+        $sql .= ', s.fk_forme_juridique as forme_juridique_code';
1244
+        $sql .= ', s.webservices_url, s.webservices_key';
1245
+        $sql .= ', s.code_client, s.code_fournisseur, s.code_compta, s.code_compta_fournisseur, s.parent, s.barcode';
1246
+        $sql .= ', s.fk_departement, s.fk_pays as country_id, s.fk_stcomm, s.remise_client, s.remise_supplier, s.mode_reglement, s.cond_reglement, s.fk_account, s.tva_assuj';
1247
+        $sql .= ', s.mode_reglement_supplier, s.cond_reglement_supplier, s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo';
1248
+        $sql .= ', s.fk_shipping_method';
1249
+        $sql .= ', s.outstanding_limit, s.import_key, s.canvas, s.fk_incoterms, s.location_incoterms';
1250
+        $sql .= ', s.order_min_amount, s.supplier_order_min_amount';
1251
+        $sql .= ', s.fk_multicurrency, s.multicurrency_code';
1252
+        $sql .= ', fj.libelle as forme_juridique';
1253
+        $sql .= ', e.libelle as effectif';
1254
+        $sql .= ', c.code as country_code, c.label as country';
1255
+        $sql .= ', d.code_departement as state_code, d.nom as state';
1256
+        $sql .= ', st.libelle as stcomm';
1257
+        $sql .= ', te.code as typent_code';
1258
+        $sql .= ', i.libelle as libelle_incoterms';
1259
+        $sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
1260
+        $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_effectif as e ON s.fk_effectif = e.id';
1261
+        $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON s.fk_pays = c.rowid';
1262
+        $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_stcomm as st ON s.fk_stcomm = st.id';
1263
+        $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_forme_juridique as fj ON s.fk_forme_juridique = fj.code';
1264
+        $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as d ON s.fk_departement = d.rowid';
1265
+        $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as te ON s.fk_typent = te.id';
1266
+        $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON s.fk_incoterms = i.rowid';
1267
+
1268
+        $sql .= ' WHERE s.entity IN ('.getEntity($this->element).')';
1269
+        if ($rowid)     $sql .= ' AND s.rowid = '.$rowid;
1270
+        if ($ref)       $sql .= " AND s.nom = '".$this->db->escape($ref)."'";
1271
+        if ($ref_alias) $sql .= " AND s.nom_alias = '".$this->db->escape($ref_alias)."'";
1272
+        if ($ref_ext)   $sql .= " AND s.ref_ext = '".$this->db->escape($ref_ext)."'";
1273
+        if ($ref_int)   $sql .= " AND s.ref_int = '".$this->db->escape($ref_int)."'";
1274
+        if ($idprof1)   $sql .= " AND s.siren = '".$this->db->escape($idprof1)."'";
1275
+        if ($idprof2)   $sql .= " AND s.siret = '".$this->db->escape($idprof2)."'";
1276
+        if ($idprof3)   $sql .= " AND s.ape = '".$this->db->escape($idprof3)."'";
1277
+        if ($idprof4)   $sql .= " AND s.idprof4 = '".$this->db->escape($idprof4)."'";
1278
+        if ($idprof5)   $sql .= " AND s.idprof5 = '".$this->db->escape($idprof5)."'";
1279
+        if ($idprof6)   $sql .= " AND s.idprof6 = '".$this->db->escape($idprof6)."'";
1280
+        if ($email)     $sql .= " AND s.email = '".$this->db->escape($email)."'";
1281
+
1282
+        $resql=$this->db->query($sql);
1283
+        if ($resql)
1284
+        {
1285
+            $num=$this->db->num_rows($resql);
1286
+            if ($num > 1)
1287
+            {
1288
+                $this->error='Fetch found several records. Rename one of tirdparties to avoid duplicate.';
1289
+                dol_syslog($this->error, LOG_ERR);
1290
+                $result = -2;
1291
+            }
1292
+            elseif ($num)   // $num = 1
1293
+            {
1294
+                $obj = $this->db->fetch_object($resql);
1295
+
1296
+                $this->id           = $obj->rowid;
1297
+                $this->entity       = $obj->entity;
1298
+                $this->canvas		= $obj->canvas;
1299
+
1300
+                $this->ref          = $obj->rowid;
1301
+                $this->name 		= $obj->name;
1302
+                $this->nom          = $obj->name;		// deprecated
1303
+                $this->name_alias = $obj->name_alias;
1304
+                $this->ref_ext      = $obj->ref_ext;
1305
+                $this->ref_int      = $obj->ref_int;
1306
+
1307
+                $this->date_creation     = $this->db->jdate($obj->date_creation);
1308
+                $this->date_modification = $this->db->jdate($obj->date_modification);
1309
+                $this->user_creation     = $obj->fk_user_creat;
1310
+                $this->user_modification = $obj->fk_user_modif;
1311
+
1312
+                $this->address 		= $obj->address;
1313
+                $this->zip 			= $obj->zip;
1314
+                $this->town 		= $obj->town;
1315
+
1316
+                $this->country_id   = $obj->country_id;
1317
+                $this->country_code = $obj->country_id?$obj->country_code:'';
1318
+                $this->country 		= $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->transnoentities('Country'.$obj->country_code):$obj->country):'';
1319
+
1320
+                $this->state_id     = $obj->fk_departement;
1321
+                $this->state_code   = $obj->state_code;
1322
+                $this->state        = ($obj->state!='-'?$obj->state:'');
1323
+
1324
+                $transcode=$langs->trans('StatusProspect'.$obj->fk_stcomm);
1325
+                $libelle=($transcode!='StatusProspect'.$obj->fk_stcomm?$transcode:$obj->stcomm);
1326
+                $this->stcomm_id = $obj->fk_stcomm;     // id statut commercial
1327
+                $this->statut_commercial = $libelle;    // libelle statut commercial
1328
+
1329
+                $this->email = $obj->email;
1330
+                $this->skype = $obj->skype;
1331
+                $this->twitter = $obj->twitter;
1332
+                $this->facebook = $obj->facebook;
1333
+                $this->url = $obj->url;
1334
+                $this->phone = $obj->phone;
1335
+                $this->fax = $obj->fax;
1336
+
1337
+                $this->parent    = $obj->parent;
1338
+
1339
+                $this->idprof1		= $obj->idprof1;
1340
+                $this->idprof2		= $obj->idprof2;
1341
+                $this->idprof3		= $obj->idprof3;
1342
+                $this->idprof4		= $obj->idprof4;
1343
+                $this->idprof5		= $obj->idprof5;
1344
+                $this->idprof6		= $obj->idprof6;
1345
+
1346
+                $this->capital   = $obj->capital;
1347
+
1348
+                $this->code_client = $obj->code_client;
1349
+                $this->code_fournisseur = $obj->code_fournisseur;
1350
+
1351
+                $this->code_compta = $obj->code_compta;
1352
+                $this->code_compta_fournisseur = $obj->code_compta_fournisseur;
1353
+
1354
+                $this->barcode = $obj->barcode;
1355
+
1356
+                $this->tva_assuj      = $obj->tva_assuj;
1357
+                $this->tva_intra      = $obj->tva_intra;
1358
+                $this->status = $obj->status;
1359
+
1360
+                // Local Taxes
1361
+                $this->localtax1_assuj      = $obj->localtax1_assuj;
1362
+                $this->localtax2_assuj      = $obj->localtax2_assuj;
1363
+
1364
+                $this->localtax1_value		= $obj->localtax1_value;
1365
+                $this->localtax2_value		= $obj->localtax2_value;
1366
+
1367
+                $this->typent_id      = $obj->typent_id;
1368
+                $this->typent_code    = $obj->typent_code;
1369
+
1370
+                $this->effectif_id    = $obj->effectif_id;
1371
+                $this->effectif       = $obj->effectif_id?$obj->effectif:'';
1372
+
1373
+                $this->forme_juridique_code= $obj->forme_juridique_code;
1374
+                $this->forme_juridique     = $obj->forme_juridique_code?$obj->forme_juridique:'';
1375
+
1376
+                $this->fk_prospectlevel = $obj->fk_prospectlevel;
1377
+
1378
+                $this->prefix_comm = $obj->prefix_comm;
1379
+
1380
+                $this->remise_percent		= $obj->remise_client;
1381
+                $this->remise_supplier_percent		= $obj->remise_supplier;
1382
+                $this->mode_reglement_id 	= $obj->mode_reglement;
1383
+                $this->cond_reglement_id 	= $obj->cond_reglement;
1384
+                $this->mode_reglement_supplier_id 	= $obj->mode_reglement_supplier;
1385
+                $this->cond_reglement_supplier_id 	= $obj->cond_reglement_supplier;
1386
+                $this->shipping_method_id   = ($obj->fk_shipping_method>0)?$obj->fk_shipping_method:null;
1387
+                $this->fk_account			= $obj->fk_account;
1388
+
1389
+                $this->client      = $obj->client;
1390
+                $this->fournisseur = $obj->fournisseur;
1391
+
1392
+                $this->note = $obj->note_private; // TODO Deprecated for backward comtability
1393
+                $this->note_private = $obj->note_private;
1394
+                $this->note_public = $obj->note_public;
1395
+                $this->modelpdf = $obj->model_pdf;
1396
+                $this->default_lang = $obj->default_lang;
1397
+                $this->logo = $obj->logo;
1398
+
1399
+                $this->webservices_url = $obj->webservices_url;
1400
+                $this->webservices_key = $obj->webservices_key;
1401
+
1402
+                $this->outstanding_limit		= $obj->outstanding_limit;
1403
+                $this->order_min_amount			= $obj->order_min_amount;
1404
+                $this->supplier_order_min_amount	= $obj->supplier_order_min_amount;
1405
+
1406
+                // multiprix
1407
+                $this->price_level = $obj->price_level;
1408
+
1409
+                $this->import_key = $obj->import_key;
1410
+
1411
+                //Incoterms
1412
+                $this->fk_incoterms = $obj->fk_incoterms;
1413
+                $this->location_incoterms = $obj->location_incoterms;
1414
+                $this->libelle_incoterms = $obj->libelle_incoterms;
1415
+
1416
+                // multicurrency
1417
+                $this->fk_multicurrency = $obj->fk_multicurrency;
1418
+                $this->multicurrency_code = $obj->multicurrency_code;
1419
+
1420
+                $result = 1;
1421
+
1422
+                // fetch optionals attributes and labels
1423
+                $this->fetch_optionals();
1424
+            }
1425
+            else
1426
+            {
1427
+                $result = 0;
1428
+            }
1429
+
1430
+            $this->db->free($resql);
1431
+        }
1432
+        else
1433
+        {
1434
+            $this->error=$this->db->lasterror();
1435
+            $result = -3;
1436
+        }
1437
+
1438
+        // Use first price level if level not defined for third party
1439
+        if (! empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->price_level)) $this->price_level=1;
1440
+
1441
+        return $result;
1442
+    }
1443
+
1444
+    /**
1445
+     *    Delete a third party from database and all its dependencies (contacts, rib...)
1446
+     *
1447
+     *    @param	int		$id             Id of third party to delete
1448
+     *    @param    User    $fuser          User who ask to delete thirparty
1449
+     *    @param    int		$call_trigger   0=No, 1=yes
1450
+     *    @return	int						<0 if KO, 0 if nothing done, >0 if OK
1451
+     */
1452
+    function delete($id, User $fuser=null, $call_trigger=1)
1453
+    {
1454
+        global $langs, $conf, $user;
1455
+
1456
+        if (empty($fuser)) $fuser=$user;
1457
+
1458
+        require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1459
+
1460
+        $entity=isset($this->entity)?$this->entity:$conf->entity;
1461
+
1462
+        dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1463
+        $error = 0;
1464
+
1465
+        // Test if child exists
1466
+        $objectisused = $this->isObjectUsed($id);
1467
+        if (empty($objectisused))
1468
+        {
1469
+            $this->db->begin();
1470
+
1471
+            // User is mandatory for trigger call
1472
+            if (! $error && $call_trigger)
1473
+            {
1474
+                // Call trigger
1475
+                $result=$this->call_trigger('COMPANY_DELETE',$fuser);
1476
+                if ($result < 0) $error++;
1477
+                // End call triggers
1478
+            }
1479
+
1480
+            if (! $error)
1481
+            {
1482
+                require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1483
+                $static_cat = new Categorie($this->db);
1484
+                $toute_categs = array();
1485
+
1486
+                // Fill $toute_categs array with an array of (type => array of ("Categorie" instance))
1487
+                if ($this->client || $this->prospect)
1488
+                {
1489
+                    $toute_categs['customer'] = $static_cat->containing($this->id,Categorie::TYPE_CUSTOMER);
1490
+                }
1491
+                if ($this->fournisseur)
1492
+                {
1493
+                    $toute_categs['supplier'] = $static_cat->containing($this->id,Categorie::TYPE_SUPPLIER);
1494
+                }
1495
+
1496
+                // Remove each "Categorie"
1497
+                foreach ($toute_categs as $type => $categs_type)
1498
+                {
1499
+                    foreach ($categs_type as $cat)
1500
+                    {
1501
+                        $cat->del_type($this, $type);
1502
+                    }
1503
+                }
1504
+            }
1505
+
1506
+            foreach ($this->childtablesoncascade as $tabletodelete)
1507
+            {
1508
+                if (! $error)
1509
+                {
1510
+                    $sql = "DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete;
1511
+                    $sql.= " WHERE fk_soc = " . $id;
1512
+                    if (! $this->db->query($sql))
1513
+                    {
1514
+                        $error++;
1515
+                        $this->errors[] = $this->db->lasterror();
1516
+                    }
1517
+                }
1518
+            }
1519
+
1520
+            // Removed extrafields
1521
+            if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
1522
+            {
1523
+                $result=$this->deleteExtraFields();
1524
+                if ($result < 0)
1525
+                {
1526
+                    $error++;
1527
+                    dol_syslog(get_class($this)."::delete error -3 ".$this->error, LOG_ERR);
1528
+                }
1529
+            }
1530
+
1531
+            // Remove links to subsidiaries companies
1532
+            if (! $error)
1533
+            {
1534
+                $sql = "UPDATE ".MAIN_DB_PREFIX."societe";
1535
+                $sql.= " SET parent = NULL";
1536
+                $sql.= " WHERE parent = " . $id;
1537
+                if (! $this->db->query($sql))
1538
+                {
1539
+                    $error++;
1540
+                    $this->errors[] = $this->db->lasterror();
1541
+                }
1542
+            }
1543
+
1544
+            // Remove third party
1545
+            if (! $error)
1546
+            {
1547
+                $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe";
1548
+                $sql.= " WHERE rowid = " . $id;
1549
+                if (! $this->db->query($sql))
1550
+                {
1551
+                    $error++;
1552
+                    $this->errors[] = $this->db->lasterror();
1553
+                }
1554
+            }
1555
+
1556
+            if (! $error)
1557
+            {
1558
+                $this->db->commit();
1559
+
1560
+                // Delete directory
1561
+                if (! empty($conf->societe->multidir_output[$entity]))
1562
+                {
1563
+                    $docdir = $conf->societe->multidir_output[$entity] . "/" . $id;
1564
+                    if (dol_is_dir($docdir))
1565
+                    {
1566
+                        dol_delete_dir_recursive($docdir);
1567
+                    }
1568
+                }
1569
+
1570
+                return 1;
1571
+            }
1572
+            else
1573
+            {
1574
+                dol_syslog($this->error, LOG_ERR);
1575
+                $this->db->rollback();
1576
+                return -1;
1577
+            }
1578
+        }
1579
+        else dol_syslog("Can't remove thirdparty with id ".$id.". There is ".$objectisused." childs", LOG_WARNING);
1580
+        return 0;
1581
+    }
1582 1582
 
1583 1583
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1584
-	/**
1585
-	 *  Define third party as a customer
1586
-	 *
1587
-	 *	@return		int		<0 if KO, >0 if OK
1588
-	 */
1589
-	function set_as_client()
1590
-	{
1584
+    /**
1585
+     *  Define third party as a customer
1586
+     *
1587
+     *	@return		int		<0 if KO, >0 if OK
1588
+     */
1589
+    function set_as_client()
1590
+    {
1591 1591
         // phpcs:enable
1592
-		if ($this->id)
1593
-		{
1594
-			$newclient=1;
1595
-			if ($this->client == 2 || $this->client == 3) $newclient=3;	//If prospect, we keep prospect tag
1596
-			$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
1597
-			$sql.= " SET client = ".$newclient;
1598
-			$sql.= " WHERE rowid = " . $this->id;
1599
-
1600
-			$resql=$this->db->query($sql);
1601
-			if ($resql)
1602
-			{
1603
-				$this->client = $newclient;
1604
-				return 1;
1605
-			}
1606
-			else return -1;
1607
-		}
1608
-		return 0;
1609
-	}
1592
+        if ($this->id)
1593
+        {
1594
+            $newclient=1;
1595
+            if ($this->client == 2 || $this->client == 3) $newclient=3;	//If prospect, we keep prospect tag
1596
+            $sql = "UPDATE ".MAIN_DB_PREFIX."societe";
1597
+            $sql.= " SET client = ".$newclient;
1598
+            $sql.= " WHERE rowid = " . $this->id;
1599
+
1600
+            $resql=$this->db->query($sql);
1601
+            if ($resql)
1602
+            {
1603
+                $this->client = $newclient;
1604
+                return 1;
1605
+            }
1606
+            else return -1;
1607
+        }
1608
+        return 0;
1609
+    }
1610 1610
 
1611 1611
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1612
-	/**
1613
-	 *  Definit la societe comme un client
1614
-	 *
1615
-	 *  @param	float	$remise		Valeur en % de la remise
1616
-	 *  @param  string	$note		Note/Motif de modification de la remise
1617
-	 *  @param  User	$user		Utilisateur qui definie la remise
1618
-	 *	@return	int					<0 if KO, >0 if OK
1619
-	 */
1620
-	function set_remise_client($remise, $note, User $user)
1621
-	{
1612
+    /**
1613
+     *  Definit la societe comme un client
1614
+     *
1615
+     *  @param	float	$remise		Valeur en % de la remise
1616
+     *  @param  string	$note		Note/Motif de modification de la remise
1617
+     *  @param  User	$user		Utilisateur qui definie la remise
1618
+     *	@return	int					<0 if KO, >0 if OK
1619
+     */
1620
+    function set_remise_client($remise, $note, User $user)
1621
+    {
1622 1622
         // phpcs:enable
1623
-		global $conf, $langs;
1624
-
1625
-		// Nettoyage parametres
1626
-		$note=trim($note);
1627
-		if (! $note)
1628
-		{
1629
-			$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("NoteReason"));
1630
-			return -2;
1631
-		}
1632
-
1633
-		dol_syslog(get_class($this)."::set_remise_client ".$remise.", ".$note.", ".$user->id);
1634
-
1635
-		if ($this->id)
1636
-		{
1637
-			$this->db->begin();
1638
-
1639
-			$now=dol_now();
1640
-
1641
-			// Positionne remise courante
1642
-			$sql = "UPDATE ".MAIN_DB_PREFIX."societe ";
1643
-			$sql.= " SET remise_client = '".$this->db->escape($remise)."'";
1644
-			$sql.= " WHERE rowid = " . $this->id;
1645
-			$resql=$this->db->query($sql);
1646
-			if (! $resql)
1647
-			{
1648
-				$this->db->rollback();
1649
-				$this->error=$this->db->error();
1650
-				return -1;
1651
-			}
1652
-
1653
-			// Ecrit trace dans historique des remises
1654
-			$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise";
1655
-			$sql.= " (entity, datec, fk_soc, remise_client, note, fk_user_author)";
1656
-			$sql.= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',";
1657
-			$sql.= " '".$this->db->escape($note)."',";
1658
-			$sql.= " ".$user->id;
1659
-			$sql.= ")";
1660
-
1661
-			$resql=$this->db->query($sql);
1662
-			if (! $resql)
1663
-			{
1664
-				$this->db->rollback();
1665
-				$this->error=$this->db->lasterror();
1666
-				return -1;
1667
-			}
1668
-
1669
-			$this->db->commit();
1670
-			return 1;
1671
-		}
1672
-	}
1623
+        global $conf, $langs;
1624
+
1625
+        // Nettoyage parametres
1626
+        $note=trim($note);
1627
+        if (! $note)
1628
+        {
1629
+            $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("NoteReason"));
1630
+            return -2;
1631
+        }
1632
+
1633
+        dol_syslog(get_class($this)."::set_remise_client ".$remise.", ".$note.", ".$user->id);
1634
+
1635
+        if ($this->id)
1636
+        {
1637
+            $this->db->begin();
1638
+
1639
+            $now=dol_now();
1640
+
1641
+            // Positionne remise courante
1642
+            $sql = "UPDATE ".MAIN_DB_PREFIX."societe ";
1643
+            $sql.= " SET remise_client = '".$this->db->escape($remise)."'";
1644
+            $sql.= " WHERE rowid = " . $this->id;
1645
+            $resql=$this->db->query($sql);
1646
+            if (! $resql)
1647
+            {
1648
+                $this->db->rollback();
1649
+                $this->error=$this->db->error();
1650
+                return -1;
1651
+            }
1652
+
1653
+            // Ecrit trace dans historique des remises
1654
+            $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise";
1655
+            $sql.= " (entity, datec, fk_soc, remise_client, note, fk_user_author)";
1656
+            $sql.= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',";
1657
+            $sql.= " '".$this->db->escape($note)."',";
1658
+            $sql.= " ".$user->id;
1659
+            $sql.= ")";
1660
+
1661
+            $resql=$this->db->query($sql);
1662
+            if (! $resql)
1663
+            {
1664
+                $this->db->rollback();
1665
+                $this->error=$this->db->lasterror();
1666
+                return -1;
1667
+            }
1668
+
1669
+            $this->db->commit();
1670
+            return 1;
1671
+        }
1672
+    }
1673 1673
 
1674 1674
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1675
-	/**
1676
-	 *  Definit la societe comme un client
1677
-	 *
1678
-	 *  @param	float	$remise		Valeur en % de la remise
1679
-	 *  @param  string	$note		Note/Motif de modification de la remise
1680
-	 *  @param  User	$user		Utilisateur qui definie la remise
1681
-	 *	@return	int					<0 if KO, >0 if OK
1682
-	 */
1683
-	function set_remise_supplier($remise, $note, User $user)
1684
-	{
1675
+    /**
1676
+     *  Definit la societe comme un client
1677
+     *
1678
+     *  @param	float	$remise		Valeur en % de la remise
1679
+     *  @param  string	$note		Note/Motif de modification de la remise
1680
+     *  @param  User	$user		Utilisateur qui definie la remise
1681
+     *	@return	int					<0 if KO, >0 if OK
1682
+     */
1683
+    function set_remise_supplier($remise, $note, User $user)
1684
+    {
1685 1685
         // phpcs:enable
1686
-		global $conf, $langs;
1687
-
1688
-		// Nettoyage parametres
1689
-		$note=trim($note);
1690
-		if (! $note)
1691
-		{
1692
-			$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("NoteReason"));
1693
-			return -2;
1694
-		}
1695
-
1696
-		dol_syslog(get_class($this)."::set_remise_supplier ".$remise.", ".$note.", ".$user->id);
1697
-
1698
-		if ($this->id)
1699
-		{
1700
-			$this->db->begin();
1701
-
1702
-			$now=dol_now();
1703
-
1704
-			// Positionne remise courante
1705
-			$sql = "UPDATE ".MAIN_DB_PREFIX."societe ";
1706
-			$sql.= " SET remise_supplier = '".$this->db->escape($remise)."'";
1707
-			$sql.= " WHERE rowid = " . $this->id;
1708
-			$resql=$this->db->query($sql);
1709
-			if (! $resql)
1710
-			{
1711
-				$this->db->rollback();
1712
-				$this->error=$this->db->error();
1713
-				return -1;
1714
-			}
1715
-
1716
-			// Ecrit trace dans historique des remises
1717
-			$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_supplier";
1718
-			$sql.= " (entity, datec, fk_soc, remise_supplier, note, fk_user_author)";
1719
-			$sql.= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',";
1720
-			$sql.= " '".$this->db->escape($note)."',";
1721
-			$sql.= " ".$user->id;
1722
-			$sql.= ")";
1723
-
1724
-			$resql=$this->db->query($sql);
1725
-			if (! $resql)
1726
-			{
1727
-				$this->db->rollback();
1728
-				$this->error=$this->db->lasterror();
1729
-				return -1;
1730
-			}
1731
-
1732
-			$this->db->commit();
1733
-			return 1;
1734
-		}
1735
-	}
1686
+        global $conf, $langs;
1687
+
1688
+        // Nettoyage parametres
1689
+        $note=trim($note);
1690
+        if (! $note)
1691
+        {
1692
+            $this->error=$langs->trans("ErrorFieldRequired",$langs->trans("NoteReason"));
1693
+            return -2;
1694
+        }
1695
+
1696
+        dol_syslog(get_class($this)."::set_remise_supplier ".$remise.", ".$note.", ".$user->id);
1697
+
1698
+        if ($this->id)
1699
+        {
1700
+            $this->db->begin();
1701
+
1702
+            $now=dol_now();
1703
+
1704
+            // Positionne remise courante
1705
+            $sql = "UPDATE ".MAIN_DB_PREFIX."societe ";
1706
+            $sql.= " SET remise_supplier = '".$this->db->escape($remise)."'";
1707
+            $sql.= " WHERE rowid = " . $this->id;
1708
+            $resql=$this->db->query($sql);
1709
+            if (! $resql)
1710
+            {
1711
+                $this->db->rollback();
1712
+                $this->error=$this->db->error();
1713
+                return -1;
1714
+            }
1715
+
1716
+            // Ecrit trace dans historique des remises
1717
+            $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_supplier";
1718
+            $sql.= " (entity, datec, fk_soc, remise_supplier, note, fk_user_author)";
1719
+            $sql.= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',";
1720
+            $sql.= " '".$this->db->escape($note)."',";
1721
+            $sql.= " ".$user->id;
1722
+            $sql.= ")";
1723
+
1724
+            $resql=$this->db->query($sql);
1725
+            if (! $resql)
1726
+            {
1727
+                $this->db->rollback();
1728
+                $this->error=$this->db->lasterror();
1729
+                return -1;
1730
+            }
1731
+
1732
+            $this->db->commit();
1733
+            return 1;
1734
+        }
1735
+    }
1736 1736
 
1737 1737
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1738
-	/**
1739
-	 *    	Add a discount for third party
1740
-	 *
1741
-	 *    	@param	float	$remise     	Amount of discount
1742
-	 *    	@param  User	$user       	User adding discount
1743
-	 *    	@param  string	$desc			Reason of discount
1744
-	 *      @param  float	$tva_tx     	VAT rate
1745
-	 *      @param	int		$discount_type	0 => customer discount, 1 => supplier discount
1746
-	 *		@return	int					<0 if KO, id of discount record if OK
1747
-	 */
1748
-	function set_remise_except($remise, User $user, $desc, $tva_tx=0, $discount_type=0)
1749
-	{
1738
+    /**
1739
+     *    	Add a discount for third party
1740
+     *
1741
+     *    	@param	float	$remise     	Amount of discount
1742
+     *    	@param  User	$user       	User adding discount
1743
+     *    	@param  string	$desc			Reason of discount
1744
+     *      @param  float	$tva_tx     	VAT rate
1745
+     *      @param	int		$discount_type	0 => customer discount, 1 => supplier discount
1746
+     *		@return	int					<0 if KO, id of discount record if OK
1747
+     */
1748
+    function set_remise_except($remise, User $user, $desc, $tva_tx=0, $discount_type=0)
1749
+    {
1750 1750
         // phpcs:enable
1751
-		global $langs;
1752
-
1753
-		// Clean parameters
1754
-		$remise = price2num($remise);
1755
-		$desc = trim($desc);
1756
-
1757
-		// Check parameters
1758
-		if (! $remise > 0)
1759
-		{
1760
-			$this->error=$langs->trans("ErrorWrongValueForParameter","1");
1761
-			return -1;
1762
-		}
1763
-		if (! $desc)
1764
-		{
1765
-			$this->error=$langs->trans("ErrorWrongValueForParameter","3");
1766
-			return -2;
1767
-		}
1768
-
1769
-		if ($this->id)
1770
-		{
1771
-			require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
1772
-
1773
-			$discount = new DiscountAbsolute($this->db);
1774
-			$discount->fk_soc=$this->id;
1775
-
1776
-			$discount->discount_type=$discount_type;
1777
-
1778
-			$discount->amount_ht=$discount->multicurrency_amount_ht=price2num($remise,'MT');
1779
-			$discount->amount_tva=$discount->multicurrency_amount_tva=price2num($remise*$tva_tx/100,'MT');
1780
-			$discount->amount_ttc=$discount->multicurrency_amount_ttc=price2num($discount->amount_ht+$discount->amount_tva,'MT');
1781
-
1782
-			$discount->tva_tx=price2num($tva_tx,'MT');
1783
-			$discount->description=$desc;
1784
-
1785
-			$result=$discount->create($user);
1786
-			if ($result > 0)
1787
-			{
1788
-				return $result;
1789
-			}
1790
-			else
1791
-			{
1792
-				$this->error=$discount->error;
1793
-				return -3;
1794
-			}
1795
-		}
1796
-		else return 0;
1797
-	}
1798
-
1799
-	/**
1800
-	 *  Renvoie montant TTC des reductions/avoirs en cours disponibles de la societe
1801
-	 *
1802
-	 *	@param	User	$user			Filtre sur un user auteur des remises
1803
-	 * 	@param	string	$filter			Filtre autre
1804
-	 * 	@param	integer	$maxvalue		Filter on max value for discount
1805
-	 * 	@param	int		$discount_type	0 => customer discount, 1 => supplier discount
1806
-	 *	@return	int					<0 if KO, Credit note amount otherwise
1807
-	 */
1808
-	function getAvailableDiscounts($user='',$filter='',$maxvalue=0,$discount_type=0)
1809
-	{
1810
-		require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
1811
-
1812
-		$discountstatic=new DiscountAbsolute($this->db);
1813
-		$result=$discountstatic->getAvailableDiscounts($this,$user,$filter,$maxvalue,$discount_type);
1814
-		if ($result >= 0)
1815
-		{
1816
-			return $result;
1817
-		}
1818
-		else
1819
-		{
1820
-			$this->error=$discountstatic->error;
1821
-			return -1;
1822
-		}
1823
-	}
1824
-
1825
-	/**
1826
-	 *  Return array of sales representatives
1827
-	 *
1828
-	 *  @param	User	$user		Object user
1829
-	 *  @param	int		$mode		0=Array with properties, 1=Array of id.
1830
-	 *  @return array       		Array of sales representatives of third party
1831
-	 */
1832
-	function getSalesRepresentatives(User $user, $mode=0)
1833
-	{
1834
-		global $conf;
1835
-
1836
-		$reparray=array();
1837
-
1838
-		$sql = "SELECT DISTINCT u.rowid, u.login, u.lastname, u.firstname, u.email, u.statut, u.entity, u.photo";
1839
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."user as u";
1840
-		if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
1841
-		{
1842
-			$sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1843
-			$sql.= " WHERE ((ug.fk_user = sc.fk_user";
1844
-			$sql.= " AND ug.entity = ".$conf->entity.")";
1845
-			$sql.= " OR u.admin = 1)";
1846
-		}
1847
-		else
1848
-			$sql.= " WHERE entity in (0, ".$conf->entity.")";
1849
-
1850
-		$sql.= " AND u.rowid = sc.fk_user AND sc.fk_soc = ".$this->id;
1851
-
1852
-		$resql = $this->db->query($sql);
1853
-		if ($resql)
1854
-		{
1855
-			$num = $this->db->num_rows($resql);
1856
-			$i=0;
1857
-			while ($i < $num)
1858
-			{
1859
-				$obj = $this->db->fetch_object($resql);
1860
-
1861
-				if (empty($mode))
1862
-				{
1863
-					$reparray[$i]['id']=$obj->rowid;
1864
-					$reparray[$i]['lastname']=$obj->lastname;
1865
-					$reparray[$i]['firstname']=$obj->firstname;
1866
-					$reparray[$i]['email']=$obj->email;
1867
-					$reparray[$i]['statut']=$obj->statut;
1868
-					$reparray[$i]['entity']=$obj->entity;
1869
-					$reparray[$i]['login']=$obj->login;
1870
-					$reparray[$i]['photo']=$obj->photo;
1871
-				}
1872
-				else
1873
-				{
1874
-					$reparray[]=$obj->rowid;
1875
-				}
1876
-				$i++;
1877
-			}
1878
-			return $reparray;
1879
-		}
1880
-		else {
1881
-			dol_print_error($this->db);
1882
-			return -1;
1883
-		}
1884
-	}
1751
+        global $langs;
1752
+
1753
+        // Clean parameters
1754
+        $remise = price2num($remise);
1755
+        $desc = trim($desc);
1756
+
1757
+        // Check parameters
1758
+        if (! $remise > 0)
1759
+        {
1760
+            $this->error=$langs->trans("ErrorWrongValueForParameter","1");
1761
+            return -1;
1762
+        }
1763
+        if (! $desc)
1764
+        {
1765
+            $this->error=$langs->trans("ErrorWrongValueForParameter","3");
1766
+            return -2;
1767
+        }
1768
+
1769
+        if ($this->id)
1770
+        {
1771
+            require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
1772
+
1773
+            $discount = new DiscountAbsolute($this->db);
1774
+            $discount->fk_soc=$this->id;
1775
+
1776
+            $discount->discount_type=$discount_type;
1777
+
1778
+            $discount->amount_ht=$discount->multicurrency_amount_ht=price2num($remise,'MT');
1779
+            $discount->amount_tva=$discount->multicurrency_amount_tva=price2num($remise*$tva_tx/100,'MT');
1780
+            $discount->amount_ttc=$discount->multicurrency_amount_ttc=price2num($discount->amount_ht+$discount->amount_tva,'MT');
1781
+
1782
+            $discount->tva_tx=price2num($tva_tx,'MT');
1783
+            $discount->description=$desc;
1784
+
1785
+            $result=$discount->create($user);
1786
+            if ($result > 0)
1787
+            {
1788
+                return $result;
1789
+            }
1790
+            else
1791
+            {
1792
+                $this->error=$discount->error;
1793
+                return -3;
1794
+            }
1795
+        }
1796
+        else return 0;
1797
+    }
1798
+
1799
+    /**
1800
+     *  Renvoie montant TTC des reductions/avoirs en cours disponibles de la societe
1801
+     *
1802
+     *	@param	User	$user			Filtre sur un user auteur des remises
1803
+     * 	@param	string	$filter			Filtre autre
1804
+     * 	@param	integer	$maxvalue		Filter on max value for discount
1805
+     * 	@param	int		$discount_type	0 => customer discount, 1 => supplier discount
1806
+     *	@return	int					<0 if KO, Credit note amount otherwise
1807
+     */
1808
+    function getAvailableDiscounts($user='',$filter='',$maxvalue=0,$discount_type=0)
1809
+    {
1810
+        require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
1811
+
1812
+        $discountstatic=new DiscountAbsolute($this->db);
1813
+        $result=$discountstatic->getAvailableDiscounts($this,$user,$filter,$maxvalue,$discount_type);
1814
+        if ($result >= 0)
1815
+        {
1816
+            return $result;
1817
+        }
1818
+        else
1819
+        {
1820
+            $this->error=$discountstatic->error;
1821
+            return -1;
1822
+        }
1823
+    }
1824
+
1825
+    /**
1826
+     *  Return array of sales representatives
1827
+     *
1828
+     *  @param	User	$user		Object user
1829
+     *  @param	int		$mode		0=Array with properties, 1=Array of id.
1830
+     *  @return array       		Array of sales representatives of third party
1831
+     */
1832
+    function getSalesRepresentatives(User $user, $mode=0)
1833
+    {
1834
+        global $conf;
1835
+
1836
+        $reparray=array();
1837
+
1838
+        $sql = "SELECT DISTINCT u.rowid, u.login, u.lastname, u.firstname, u.email, u.statut, u.entity, u.photo";
1839
+        $sql.= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."user as u";
1840
+        if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
1841
+        {
1842
+            $sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1843
+            $sql.= " WHERE ((ug.fk_user = sc.fk_user";
1844
+            $sql.= " AND ug.entity = ".$conf->entity.")";
1845
+            $sql.= " OR u.admin = 1)";
1846
+        }
1847
+        else
1848
+            $sql.= " WHERE entity in (0, ".$conf->entity.")";
1849
+
1850
+        $sql.= " AND u.rowid = sc.fk_user AND sc.fk_soc = ".$this->id;
1851
+
1852
+        $resql = $this->db->query($sql);
1853
+        if ($resql)
1854
+        {
1855
+            $num = $this->db->num_rows($resql);
1856
+            $i=0;
1857
+            while ($i < $num)
1858
+            {
1859
+                $obj = $this->db->fetch_object($resql);
1860
+
1861
+                if (empty($mode))
1862
+                {
1863
+                    $reparray[$i]['id']=$obj->rowid;
1864
+                    $reparray[$i]['lastname']=$obj->lastname;
1865
+                    $reparray[$i]['firstname']=$obj->firstname;
1866
+                    $reparray[$i]['email']=$obj->email;
1867
+                    $reparray[$i]['statut']=$obj->statut;
1868
+                    $reparray[$i]['entity']=$obj->entity;
1869
+                    $reparray[$i]['login']=$obj->login;
1870
+                    $reparray[$i]['photo']=$obj->photo;
1871
+                }
1872
+                else
1873
+                {
1874
+                    $reparray[]=$obj->rowid;
1875
+                }
1876
+                $i++;
1877
+            }
1878
+            return $reparray;
1879
+        }
1880
+        else {
1881
+            dol_print_error($this->db);
1882
+            return -1;
1883
+        }
1884
+    }
1885 1885
 
1886 1886
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1887
-	/**
1888
-	 * Set the price level
1889
-	 *
1890
-	 * @param 	int		$price_level	Level of price
1891
-	 * @param 	User	$user			Use making change
1892
-	 * @return	int						<0 if KO, >0 if OK
1893
-	 */
1894
-	function set_price_level($price_level, User $user)
1895
-	{
1887
+    /**
1888
+     * Set the price level
1889
+     *
1890
+     * @param 	int		$price_level	Level of price
1891
+     * @param 	User	$user			Use making change
1892
+     * @return	int						<0 if KO, >0 if OK
1893
+     */
1894
+    function set_price_level($price_level, User $user)
1895
+    {
1896 1896
         // phpcs:enable
1897
-		if ($this->id)
1898
-		{
1899
-			$now=dol_now();
1900
-
1901
-			$sql  = "UPDATE ".MAIN_DB_PREFIX."societe";
1902
-			$sql .= " SET price_level = '".$this->db->escape($price_level)."'";
1903
-			$sql .= " WHERE rowid = " . $this->id;
1904
-
1905
-			if (! $this->db->query($sql))
1906
-			{
1907
-				dol_print_error($this->db);
1908
-				return -1;
1909
-			}
1910
-
1911
-			$sql  = "INSERT INTO ".MAIN_DB_PREFIX."societe_prices";
1912
-			$sql .= " (datec, fk_soc, price_level, fk_user_author)";
1913
-			$sql .= " VALUES ('".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($price_level)."', ".$user->id.")";
1914
-
1915
-			if (! $this->db->query($sql))
1916
-			{
1917
-				dol_print_error($this->db);
1918
-				return -1;
1919
-			}
1920
-			return 1;
1921
-		}
1922
-		return -1;
1923
-	}
1897
+        if ($this->id)
1898
+        {
1899
+            $now=dol_now();
1900
+
1901
+            $sql  = "UPDATE ".MAIN_DB_PREFIX."societe";
1902
+            $sql .= " SET price_level = '".$this->db->escape($price_level)."'";
1903
+            $sql .= " WHERE rowid = " . $this->id;
1904
+
1905
+            if (! $this->db->query($sql))
1906
+            {
1907
+                dol_print_error($this->db);
1908
+                return -1;
1909
+            }
1910
+
1911
+            $sql  = "INSERT INTO ".MAIN_DB_PREFIX."societe_prices";
1912
+            $sql .= " (datec, fk_soc, price_level, fk_user_author)";
1913
+            $sql .= " VALUES ('".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($price_level)."', ".$user->id.")";
1914
+
1915
+            if (! $this->db->query($sql))
1916
+            {
1917
+                dol_print_error($this->db);
1918
+                return -1;
1919
+            }
1920
+            return 1;
1921
+        }
1922
+        return -1;
1923
+    }
1924 1924
 
1925 1925
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1926
-	/**
1927
-	 *	Add link to sales representative
1928
-	 *
1929
-	 *	@param	User	$user		Object user
1930
-	 *	@param	int		$commid		Id of user
1931
-	 *	@return	void
1932
-	 */
1933
-	function add_commercial(User $user, $commid)
1934
-	{
1926
+    /**
1927
+     *	Add link to sales representative
1928
+     *
1929
+     *	@param	User	$user		Object user
1930
+     *	@param	int		$commid		Id of user
1931
+     *	@return	void
1932
+     */
1933
+    function add_commercial(User $user, $commid)
1934
+    {
1935 1935
         // phpcs:enable
1936
-		$error=0;
1936
+        $error=0;
1937 1937
 
1938 1938
 
1939
-		if ($this->id > 0 && $commid > 0)
1940
-		{
1941
-			$sql = "DELETE FROM  ".MAIN_DB_PREFIX."societe_commerciaux";
1942
-			$sql.= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid;
1939
+        if ($this->id > 0 && $commid > 0)
1940
+        {
1941
+            $sql = "DELETE FROM  ".MAIN_DB_PREFIX."societe_commerciaux";
1942
+            $sql.= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid;
1943 1943
 
1944
-			$this->db->query($sql);
1944
+            $this->db->query($sql);
1945 1945
 
1946
-			$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_commerciaux";
1947
-			$sql.= " ( fk_soc, fk_user )";
1948
-			$sql.= " VALUES (".$this->id.",".$commid.")";
1946
+            $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_commerciaux";
1947
+            $sql.= " ( fk_soc, fk_user )";
1948
+            $sql.= " VALUES (".$this->id.",".$commid.")";
1949 1949
 
1950
-			if (! $this->db->query($sql) )
1951
-			{
1952
-				dol_syslog(get_class($this)."::add_commercial Erreur");
1953
-			}
1954
-			else {
1955
-				$this->context=array('commercial_modified'=>$commid);
1950
+            if (! $this->db->query($sql) )
1951
+            {
1952
+                dol_syslog(get_class($this)."::add_commercial Erreur");
1953
+            }
1954
+            else {
1955
+                $this->context=array('commercial_modified'=>$commid);
1956 1956
 
1957
-				$result=$this->call_trigger('COMPANY_LINK_SALE_REPRESENTATIVE',$user);
1957
+                $result=$this->call_trigger('COMPANY_LINK_SALE_REPRESENTATIVE',$user);
1958 1958
                 if ($result < 0) $error++;
1959
-			}
1960
-		}
1961
-	}
1959
+            }
1960
+        }
1961
+    }
1962 1962
 
1963 1963
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
1964
-	/**
1965
-	 *	Add link to sales representative
1966
-	 *
1967
-	 *	@param	User	$user		Object user
1968
-	 *	@param	int		$commid		Id of user
1969
-	 *	@return	void
1970
-	 */
1971
-	function del_commercial(User $user, $commid)
1972
-	{
1964
+    /**
1965
+     *	Add link to sales representative
1966
+     *
1967
+     *	@param	User	$user		Object user
1968
+     *	@param	int		$commid		Id of user
1969
+     *	@return	void
1970
+     */
1971
+    function del_commercial(User $user, $commid)
1972
+    {
1973 1973
         // phpcs:enable
1974
-		$error=0;
1975
-		$this->context=array('commercial_modified'=>$commid);
1974
+        $error=0;
1975
+        $this->context=array('commercial_modified'=>$commid);
1976 1976
 
1977
-		$result=$this->call_trigger('COMPANY_UNLINK_SALE_REPRESENTATIVE',$user);
1977
+        $result=$this->call_trigger('COMPANY_UNLINK_SALE_REPRESENTATIVE',$user);
1978 1978
         if ($result < 0) $error++;
1979 1979
 
1980
-		if ($this->id > 0 && $commid > 0)
1981
-		{
1982
-			$sql  = "DELETE FROM  ".MAIN_DB_PREFIX."societe_commerciaux ";
1983
-			$sql .= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid;
1984
-
1985
-			if (! $this->db->query($sql) )
1986
-			{
1987
-				dol_syslog(get_class($this)."::del_commercial Erreur");
1988
-			}
1989
-		}
1990
-	}
1991
-
1992
-
1993
-	/**
1994
-	 *    	Return a link on thirdparty (with picto)
1995
-	 *
1996
-	 *		@param	int		$withpicto		          Add picto into link (0=No picto, 1=Include picto with link, 2=Picto only)
1997
-	 *		@param	string	$option			          Target of link ('', 'customer', 'prospect', 'supplier', 'project')
1998
-	 *		@param	int		$maxlen			          Max length of name
1999
-	 *      @param	int  	$notooltip		          1=Disable tooltip
2000
-	 *      @param  int     $save_lastsearch_value    -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
2001
-	 *		@return	string					          String with URL
2002
-	 */
2003
-	function getNomUrl($withpicto=0, $option='', $maxlen=0, $notooltip=0, $save_lastsearch_value=-1)
2004
-	{
2005
-		global $conf, $langs, $hookmanager;
2006
-
2007
-		if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
2008
-
2009
-		$name=$this->name?$this->name:$this->nom;
2010
-
2011
-		if(!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)){
2012
-
2013
-             if(empty($option) && $this->client > 0) $option = 'customer';
2014
-             if(empty($option) && $this->fournisseur > 0) $option = 'supplier';
2015
-         }
2016
-
2017
-
2018
-		if (! empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto)))
2019
-		{
2020
-			$code = '';
2021
-			if (($this->client) && (! empty ( $this->code_client ))
2022
-				&& ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1
2023
-				|| $conf->global->SOCIETE_ADD_REF_IN_LIST == 2
2024
-				)
2025
-			)
2026
-			{
2027
-				$code = $this->code_client . ' - ';
2028
-			}
2029
-
2030
-			if (($this->fournisseur) && (! empty ( $this->code_fournisseur ))
2031
-				&& ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1
2032
-				|| $conf->global->SOCIETE_ADD_REF_IN_LIST == 3
2033
-				)
2034
-			)
2035
-			{
2036
-				$code .= $this->code_fournisseur . ' - ';
2037
-			}
2038
-
2039
-			if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1)
2040
-			{
2041
-				$name =$code.' '.$name;
2042
-			}
2043
-			else
2044
-			{
2045
-				$name =$code;
2046
-			}
2047
-		}
2048
-
2049
-		if (!empty($this->name_alias)) $name .= ' ('.$this->name_alias.')';
2050
-
2051
-		$result=''; $label='';
2052
-		$linkstart=''; $linkend='';
2053
-
2054
-		if (! empty($this->logo) && class_exists('Form'))
2055
-		{
2056
-			$label.= '<div class="photointooltip">';
2057
-			$label.= Form::showphoto('societe', $this, 0, 40, 0, 'photowithmargin', 'mini', 0);	// Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
2058
-			$label.= '</div><div style="clear: both;"></div>';
2059
-		}
2060
-
2061
-		$label.= '<div class="centpercent">';
2062
-
2063
-		if ($option == 'customer' || $option == 'compta' || $option == 'category' || $option == 'category_supplier')
2064
-		{
2065
-		   $label.= '<u>' . $langs->trans("ShowCustomer") . '</u>';
2066
-		   $linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id;
2067
-		}
2068
-		elseif ($option == 'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
2069
-		{
2070
-			$label.= '<u>' . $langs->trans("ShowProspect") . '</u>';
2071
-			$linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id;
2072
-		}
2073
-		elseif ($option == 'supplier')
2074
-		{
2075
-			$label.= '<u>' . $langs->trans("ShowSupplier") . '</u>';
2076
-			$linkstart = '<a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$this->id;
2077
-		}
2078
-		elseif ($option == 'agenda')
2079
-		{
2080
-			$label.= '<u>' . $langs->trans("ShowAgenda") . '</u>';
2081
-			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/agenda.php?socid='.$this->id;
2082
-		}
2083
-		elseif ($option == 'project')
2084
-		{
2085
-			$label.= '<u>' . $langs->trans("ShowProject") . '</u>';
2086
-			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/project.php?socid='.$this->id;
2087
-		}
2088
-		elseif ($option == 'margin')
2089
-		{
2090
-			$label.= '<u>' . $langs->trans("ShowMargin") . '</u>';
2091
-			$linkstart = '<a href="'.DOL_URL_ROOT.'/margin/tabs/thirdpartyMargins.php?socid='.$this->id.'&type=1';
2092
-		}
2093
-		elseif ($option == 'contact')
2094
-		{
2095
-			$label.= '<u>' . $langs->trans("ShowContacts") . '</u>';
2096
-			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/contact.php?socid='.$this->id;
2097
-		}
2098
-		elseif ($option == 'ban')
2099
-		{
2100
-			$label.= '<u>' . $langs->trans("ShowBan") . '</u>';
2101
-			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$this->id;
2102
-		}
2103
-
2104
-		// By default
2105
-		if (empty($linkstart))
2106
-		{
2107
-			$label.= '<u>' . $langs->trans("ShowCompany") . '</u>';
2108
-			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$this->id;
2109
-		}
2110
-
2111
-		if (! empty($this->name))
2112
-		{
2113
-			$label.= '<br><b>' . $langs->trans('Name') . ':</b> '. $this->name;
2114
-			if (! empty($this->name_alias)) $label.=' ('.$this->name_alias.')';
2115
-			$label.= '<br><b>' . $langs->trans('Email') . ':</b> '. $this->email;
2116
-		}
2117
-		if (! empty($this->country_code))
2118
-			$label.= '<br><b>' . $langs->trans('Country') . ':</b> '. $this->country_code;
2119
-		if (! empty($this->tva_intra) || (! empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'vatnumber') !== false))
2120
-			$label.= '<br><b>' . $langs->trans('VATIntra') . ':</b> '. $this->tva_intra;
2121
-		if (! empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP))
2122
-		{
2123
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid1') !== false) $label.= '<br><b>' . $langs->trans('ProfId1'.$this->country_code) . ':</b> '. $this->idprof1;
2124
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid2') !== false) $label.= '<br><b>' . $langs->trans('ProfId2'.$this->country_code) . ':</b> '. $this->idprof2;
2125
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid3') !== false) $label.= '<br><b>' . $langs->trans('ProfId3'.$this->country_code) . ':</b> '. $this->idprof3;
2126
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid4') !== false) $label.= '<br><b>' . $langs->trans('ProfId4'.$this->country_code) . ':</b> '. $this->idprof4;
2127
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid5') !== false) $label.= '<br><b>' . $langs->trans('ProfId5'.$this->country_code) . ':</b> '. $this->idprof5;
2128
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid6') !== false) $label.= '<br><b>' . $langs->trans('ProfId6'.$this->country_code) . ':</b> '. $this->idprof6;
2129
-		}
2130
-		if (! empty($this->code_client) && ($this->client == 1 || $this->client == 3))
2131
-			$label.= '<br><b>' . $langs->trans('CustomerCode') . ':</b> '. $this->code_client;
2132
-		if (! empty($this->code_fournisseur) && $this->fournisseur)
2133
-			$label.= '<br><b>' . $langs->trans('SupplierCode') . ':</b> '. $this->code_fournisseur;
2134
-		if (! empty($conf->accounting->enabled) && ($this->client == 1 || $this->client == 3))
2135
-			$label.= '<br><b>' . $langs->trans('CustomerAccountancyCode') . ':</b> '. ($this->code_compta ? $this->code_compta : $this->code_compta_client);
2136
-		if (! empty($conf->accounting->enabled) && $this->fournisseur)
2137
-			$label.= '<br><b>' . $langs->trans('SupplierAccountancyCode') . ':</b> '. $this->code_compta_fournisseur;
2138
-
2139
-		$label.= '</div>';
2140
-
2141
-		// Add type of canvas
2142
-		$linkstart.=(!empty($this->canvas)?'&canvas='.$this->canvas:'');
2143
-		// Add param to save lastsearch_values or not
2144
-		$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
2145
-		if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
2146
-		if ($add_save_lastsearch_values) $linkstart.='&save_lastsearch_values=1';
2147
-		$linkstart.='"';
2148
-
2149
-		$linkclose='';
2150
-		if (empty($notooltip))
2151
-		{
2152
-			if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
2153
-			{
2154
-				$label=$langs->trans("ShowCompany");
2155
-				$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
2156
-			}
2157
-			$linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
2158
-			$linkclose.=' class="classfortooltip refurl"';
2159
-
2160
-		 	/*
1980
+        if ($this->id > 0 && $commid > 0)
1981
+        {
1982
+            $sql  = "DELETE FROM  ".MAIN_DB_PREFIX."societe_commerciaux ";
1983
+            $sql .= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid;
1984
+
1985
+            if (! $this->db->query($sql) )
1986
+            {
1987
+                dol_syslog(get_class($this)."::del_commercial Erreur");
1988
+            }
1989
+        }
1990
+    }
1991
+
1992
+
1993
+    /**
1994
+     *    	Return a link on thirdparty (with picto)
1995
+     *
1996
+     *		@param	int		$withpicto		          Add picto into link (0=No picto, 1=Include picto with link, 2=Picto only)
1997
+     *		@param	string	$option			          Target of link ('', 'customer', 'prospect', 'supplier', 'project')
1998
+     *		@param	int		$maxlen			          Max length of name
1999
+     *      @param	int  	$notooltip		          1=Disable tooltip
2000
+     *      @param  int     $save_lastsearch_value    -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
2001
+     *		@return	string					          String with URL
2002
+     */
2003
+    function getNomUrl($withpicto=0, $option='', $maxlen=0, $notooltip=0, $save_lastsearch_value=-1)
2004
+    {
2005
+        global $conf, $langs, $hookmanager;
2006
+
2007
+        if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
2008
+
2009
+        $name=$this->name?$this->name:$this->nom;
2010
+
2011
+        if(!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)){
2012
+
2013
+                if(empty($option) && $this->client > 0) $option = 'customer';
2014
+                if(empty($option) && $this->fournisseur > 0) $option = 'supplier';
2015
+            }
2016
+
2017
+
2018
+        if (! empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto)))
2019
+        {
2020
+            $code = '';
2021
+            if (($this->client) && (! empty ( $this->code_client ))
2022
+                && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1
2023
+                || $conf->global->SOCIETE_ADD_REF_IN_LIST == 2
2024
+                )
2025
+            )
2026
+            {
2027
+                $code = $this->code_client . ' - ';
2028
+            }
2029
+
2030
+            if (($this->fournisseur) && (! empty ( $this->code_fournisseur ))
2031
+                && ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1
2032
+                || $conf->global->SOCIETE_ADD_REF_IN_LIST == 3
2033
+                )
2034
+            )
2035
+            {
2036
+                $code .= $this->code_fournisseur . ' - ';
2037
+            }
2038
+
2039
+            if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1)
2040
+            {
2041
+                $name =$code.' '.$name;
2042
+            }
2043
+            else
2044
+            {
2045
+                $name =$code;
2046
+            }
2047
+        }
2048
+
2049
+        if (!empty($this->name_alias)) $name .= ' ('.$this->name_alias.')';
2050
+
2051
+        $result=''; $label='';
2052
+        $linkstart=''; $linkend='';
2053
+
2054
+        if (! empty($this->logo) && class_exists('Form'))
2055
+        {
2056
+            $label.= '<div class="photointooltip">';
2057
+            $label.= Form::showphoto('societe', $this, 0, 40, 0, 'photowithmargin', 'mini', 0);	// Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
2058
+            $label.= '</div><div style="clear: both;"></div>';
2059
+        }
2060
+
2061
+        $label.= '<div class="centpercent">';
2062
+
2063
+        if ($option == 'customer' || $option == 'compta' || $option == 'category' || $option == 'category_supplier')
2064
+        {
2065
+            $label.= '<u>' . $langs->trans("ShowCustomer") . '</u>';
2066
+            $linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id;
2067
+        }
2068
+        elseif ($option == 'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
2069
+        {
2070
+            $label.= '<u>' . $langs->trans("ShowProspect") . '</u>';
2071
+            $linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id;
2072
+        }
2073
+        elseif ($option == 'supplier')
2074
+        {
2075
+            $label.= '<u>' . $langs->trans("ShowSupplier") . '</u>';
2076
+            $linkstart = '<a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$this->id;
2077
+        }
2078
+        elseif ($option == 'agenda')
2079
+        {
2080
+            $label.= '<u>' . $langs->trans("ShowAgenda") . '</u>';
2081
+            $linkstart = '<a href="'.DOL_URL_ROOT.'/societe/agenda.php?socid='.$this->id;
2082
+        }
2083
+        elseif ($option == 'project')
2084
+        {
2085
+            $label.= '<u>' . $langs->trans("ShowProject") . '</u>';
2086
+            $linkstart = '<a href="'.DOL_URL_ROOT.'/societe/project.php?socid='.$this->id;
2087
+        }
2088
+        elseif ($option == 'margin')
2089
+        {
2090
+            $label.= '<u>' . $langs->trans("ShowMargin") . '</u>';
2091
+            $linkstart = '<a href="'.DOL_URL_ROOT.'/margin/tabs/thirdpartyMargins.php?socid='.$this->id.'&type=1';
2092
+        }
2093
+        elseif ($option == 'contact')
2094
+        {
2095
+            $label.= '<u>' . $langs->trans("ShowContacts") . '</u>';
2096
+            $linkstart = '<a href="'.DOL_URL_ROOT.'/societe/contact.php?socid='.$this->id;
2097
+        }
2098
+        elseif ($option == 'ban')
2099
+        {
2100
+            $label.= '<u>' . $langs->trans("ShowBan") . '</u>';
2101
+            $linkstart = '<a href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$this->id;
2102
+        }
2103
+
2104
+        // By default
2105
+        if (empty($linkstart))
2106
+        {
2107
+            $label.= '<u>' . $langs->trans("ShowCompany") . '</u>';
2108
+            $linkstart = '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$this->id;
2109
+        }
2110
+
2111
+        if (! empty($this->name))
2112
+        {
2113
+            $label.= '<br><b>' . $langs->trans('Name') . ':</b> '. $this->name;
2114
+            if (! empty($this->name_alias)) $label.=' ('.$this->name_alias.')';
2115
+            $label.= '<br><b>' . $langs->trans('Email') . ':</b> '. $this->email;
2116
+        }
2117
+        if (! empty($this->country_code))
2118
+            $label.= '<br><b>' . $langs->trans('Country') . ':</b> '. $this->country_code;
2119
+        if (! empty($this->tva_intra) || (! empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'vatnumber') !== false))
2120
+            $label.= '<br><b>' . $langs->trans('VATIntra') . ':</b> '. $this->tva_intra;
2121
+        if (! empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP))
2122
+        {
2123
+            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid1') !== false) $label.= '<br><b>' . $langs->trans('ProfId1'.$this->country_code) . ':</b> '. $this->idprof1;
2124
+            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid2') !== false) $label.= '<br><b>' . $langs->trans('ProfId2'.$this->country_code) . ':</b> '. $this->idprof2;
2125
+            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid3') !== false) $label.= '<br><b>' . $langs->trans('ProfId3'.$this->country_code) . ':</b> '. $this->idprof3;
2126
+            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid4') !== false) $label.= '<br><b>' . $langs->trans('ProfId4'.$this->country_code) . ':</b> '. $this->idprof4;
2127
+            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid5') !== false) $label.= '<br><b>' . $langs->trans('ProfId5'.$this->country_code) . ':</b> '. $this->idprof5;
2128
+            if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid6') !== false) $label.= '<br><b>' . $langs->trans('ProfId6'.$this->country_code) . ':</b> '. $this->idprof6;
2129
+        }
2130
+        if (! empty($this->code_client) && ($this->client == 1 || $this->client == 3))
2131
+            $label.= '<br><b>' . $langs->trans('CustomerCode') . ':</b> '. $this->code_client;
2132
+        if (! empty($this->code_fournisseur) && $this->fournisseur)
2133
+            $label.= '<br><b>' . $langs->trans('SupplierCode') . ':</b> '. $this->code_fournisseur;
2134
+        if (! empty($conf->accounting->enabled) && ($this->client == 1 || $this->client == 3))
2135
+            $label.= '<br><b>' . $langs->trans('CustomerAccountancyCode') . ':</b> '. ($this->code_compta ? $this->code_compta : $this->code_compta_client);
2136
+        if (! empty($conf->accounting->enabled) && $this->fournisseur)
2137
+            $label.= '<br><b>' . $langs->trans('SupplierAccountancyCode') . ':</b> '. $this->code_compta_fournisseur;
2138
+
2139
+        $label.= '</div>';
2140
+
2141
+        // Add type of canvas
2142
+        $linkstart.=(!empty($this->canvas)?'&canvas='.$this->canvas:'');
2143
+        // Add param to save lastsearch_values or not
2144
+        $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
2145
+        if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
2146
+        if ($add_save_lastsearch_values) $linkstart.='&save_lastsearch_values=1';
2147
+        $linkstart.='"';
2148
+
2149
+        $linkclose='';
2150
+        if (empty($notooltip))
2151
+        {
2152
+            if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
2153
+            {
2154
+                $label=$langs->trans("ShowCompany");
2155
+                $linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
2156
+            }
2157
+            $linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
2158
+            $linkclose.=' class="classfortooltip refurl"';
2159
+
2160
+                /*
2161 2161
 			$hookmanager->initHooks(array('thirdpartydao'));
2162 2162
 			$parameters=array('id'=>$this->id);
2163 2163
 			$reshook=$hookmanager->executeHooks('getnomurltooltip',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
2164 2164
 			if ($reshook > 0) $linkclose = $hookmanager->resPrint;
2165 2165
 			*/
2166
-		}
2167
-		$linkstart.=$linkclose.'>';
2168
-		$linkend='</a>';
2169
-
2170
-		global $user;
2171
-		if (! $user->rights->societe->client->voir && $user->societe_id > 0 && $this->id != $user->societe_id)
2172
-		{
2173
-			$linkstart='';
2174
-			$linkend='';
2175
-		}
2176
-
2177
-		$result.=$linkstart;
2178
-		if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip valigntextbottom"'), 0, 0, $notooltip?0:1);
2179
-		if ($withpicto != 2) $result.=($maxlen?dol_trunc($name,$maxlen):$name);
2180
-		$result.=$linkend;
2181
-
2182
-		global $action;
2183
-		$hookmanager->initHooks(array('thirdpartydao'));
2184
-		$parameters=array('id'=>$this->id, 'getnomurl'=>$result);
2185
-		$reshook=$hookmanager->executeHooks('getNomUrl',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
2186
-		if ($reshook > 0) $result = $hookmanager->resPrint;
2187
-		else $result .= $hookmanager->resPrint;
2188
-
2189
-		return $result;
2190
-	}
2191
-
2192
-	/**
2193
-	 *    Return label of status (activity, closed)
2194
-	 *
2195
-	 *    @param	int		$mode       0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
2196
-	 *    @return   string        		Libelle
2197
-	 */
2198
-	function getLibStatut($mode=0)
2199
-	{
2200
-		return $this->LibStatut($this->status,$mode);
2201
-	}
2166
+        }
2167
+        $linkstart.=$linkclose.'>';
2168
+        $linkend='</a>';
2169
+
2170
+        global $user;
2171
+        if (! $user->rights->societe->client->voir && $user->societe_id > 0 && $this->id != $user->societe_id)
2172
+        {
2173
+            $linkstart='';
2174
+            $linkend='';
2175
+        }
2176
+
2177
+        $result.=$linkstart;
2178
+        if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip valigntextbottom"'), 0, 0, $notooltip?0:1);
2179
+        if ($withpicto != 2) $result.=($maxlen?dol_trunc($name,$maxlen):$name);
2180
+        $result.=$linkend;
2181
+
2182
+        global $action;
2183
+        $hookmanager->initHooks(array('thirdpartydao'));
2184
+        $parameters=array('id'=>$this->id, 'getnomurl'=>$result);
2185
+        $reshook=$hookmanager->executeHooks('getNomUrl',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
2186
+        if ($reshook > 0) $result = $hookmanager->resPrint;
2187
+        else $result .= $hookmanager->resPrint;
2188
+
2189
+        return $result;
2190
+    }
2191
+
2192
+    /**
2193
+     *    Return label of status (activity, closed)
2194
+     *
2195
+     *    @param	int		$mode       0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
2196
+     *    @return   string        		Libelle
2197
+     */
2198
+    function getLibStatut($mode=0)
2199
+    {
2200
+        return $this->LibStatut($this->status,$mode);
2201
+    }
2202 2202
 
2203 2203
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2204
-	/**
2205
-	 *  Renvoi le libelle d'un statut donne
2206
-	 *
2207
-	 *  @param	int		$statut         Id statut
2208
-	 *  @param	int		$mode           0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto, 6=Long label + Picto
2209
-	 *  @return	string          		Libelle du statut
2210
-	 */
2211
-	function LibStatut($statut,$mode=0)
2212
-	{
2204
+    /**
2205
+     *  Renvoi le libelle d'un statut donne
2206
+     *
2207
+     *  @param	int		$statut         Id statut
2208
+     *  @param	int		$mode           0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto, 6=Long label + Picto
2209
+     *  @return	string          		Libelle du statut
2210
+     */
2211
+    function LibStatut($statut,$mode=0)
2212
+    {
2213 2213
         // phpcs:enable
2214
-		global $langs;
2215
-		$langs->load('companies');
2216
-
2217
-		if ($mode == 0)
2218
-		{
2219
-			if ($statut==0) return $langs->trans("ActivityCeased");
2220
-			elseif ($statut==1) return $langs->trans("InActivity");
2221
-		}
2222
-		elseif ($mode == 1)
2223
-		{
2224
-			if ($statut==0) return $langs->trans("ActivityCeased");
2225
-			elseif ($statut==1) return $langs->trans("InActivity");
2226
-		}
2227
-		elseif ($mode == 2)
2228
-		{
2229
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2230
-			elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2231
-		}
2232
-		elseif ($mode == 3)
2233
-		{
2234
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2235
-			elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2236
-		}
2237
-		elseif ($mode == 4)
2238
-		{
2239
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2240
-			elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2241
-		}
2242
-		elseif ($mode == 5)
2243
-		{
2244
-			if ($statut==0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2245
-			elseif ($statut==1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2246
-		}
2247
-		elseif ($mode == 6)
2248
-		{
2249
-			if ($statut==0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2250
-			elseif ($statut==1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2251
-		}
2252
-	}
2214
+        global $langs;
2215
+        $langs->load('companies');
2216
+
2217
+        if ($mode == 0)
2218
+        {
2219
+            if ($statut==0) return $langs->trans("ActivityCeased");
2220
+            elseif ($statut==1) return $langs->trans("InActivity");
2221
+        }
2222
+        elseif ($mode == 1)
2223
+        {
2224
+            if ($statut==0) return $langs->trans("ActivityCeased");
2225
+            elseif ($statut==1) return $langs->trans("InActivity");
2226
+        }
2227
+        elseif ($mode == 2)
2228
+        {
2229
+            if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2230
+            elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2231
+        }
2232
+        elseif ($mode == 3)
2233
+        {
2234
+            if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2235
+            elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2236
+        }
2237
+        elseif ($mode == 4)
2238
+        {
2239
+            if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2240
+            elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2241
+        }
2242
+        elseif ($mode == 5)
2243
+        {
2244
+            if ($statut==0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2245
+            elseif ($statut==1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2246
+        }
2247
+        elseif ($mode == 6)
2248
+        {
2249
+            if ($statut==0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2250
+            elseif ($statut==1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2251
+        }
2252
+    }
2253 2253
 
2254 2254
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2255
-	/**
2256
-	 *    Return list of contacts emails existing for third party
2257
-	 *
2258
-	 *	  @param	  int		$addthirdparty		1=Add also a record for thirdparty email
2259
-	 *    @return     array       					Array of contacts emails
2260
-	 */
2261
-	function thirdparty_and_contact_email_array($addthirdparty=0)
2262
-	{
2255
+    /**
2256
+     *    Return list of contacts emails existing for third party
2257
+     *
2258
+     *	  @param	  int		$addthirdparty		1=Add also a record for thirdparty email
2259
+     *    @return     array       					Array of contacts emails
2260
+     */
2261
+    function thirdparty_and_contact_email_array($addthirdparty=0)
2262
+    {
2263 2263
         // phpcs:enable
2264
-		global $langs;
2265
-
2266
-		$contact_emails = $this->contact_property_array('email',1);
2267
-		if ($this->email && $addthirdparty)
2268
-		{
2269
-			if (empty($this->name)) $this->name=$this->nom;
2270
-			$contact_emails['thirdparty']=$langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->email.">";
2271
-		}
2272
-		//var_dump($contact_emails)
2273
-		return $contact_emails;
2274
-	}
2264
+        global $langs;
2265
+
2266
+        $contact_emails = $this->contact_property_array('email',1);
2267
+        if ($this->email && $addthirdparty)
2268
+        {
2269
+            if (empty($this->name)) $this->name=$this->nom;
2270
+            $contact_emails['thirdparty']=$langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->email.">";
2271
+        }
2272
+        //var_dump($contact_emails)
2273
+        return $contact_emails;
2274
+    }
2275 2275
 
2276 2276
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2277
-	/**
2278
-	 *    Return list of contacts mobile phone existing for third party
2279
-	 *
2280
-	 *    @return     array       Array of contacts emails
2281
-	 */
2282
-	function thirdparty_and_contact_phone_array()
2283
-	{
2277
+    /**
2278
+     *    Return list of contacts mobile phone existing for third party
2279
+     *
2280
+     *    @return     array       Array of contacts emails
2281
+     */
2282
+    function thirdparty_and_contact_phone_array()
2283
+    {
2284 2284
         // phpcs:enable
2285
-		global $langs;
2285
+        global $langs;
2286 2286
 
2287
-		$contact_phone = $this->contact_property_array('mobile');
2287
+        $contact_phone = $this->contact_property_array('mobile');
2288 2288
 
2289
-		if (! empty($this->phone))	// If a phone of thirdparty is defined, we add it ot mobile of contacts
2290
-		{
2291
-			if (empty($this->name)) $this->name=$this->nom;
2292
-			// TODO: Tester si tel non deja present dans tableau contact
2293
-			$contact_phone['thirdparty']=$langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->phone.">";
2294
-		}
2295
-		return $contact_phone;
2296
-	}
2289
+        if (! empty($this->phone))	// If a phone of thirdparty is defined, we add it ot mobile of contacts
2290
+        {
2291
+            if (empty($this->name)) $this->name=$this->nom;
2292
+            // TODO: Tester si tel non deja present dans tableau contact
2293
+            $contact_phone['thirdparty']=$langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->phone.">";
2294
+        }
2295
+        return $contact_phone;
2296
+    }
2297 2297
 
2298 2298
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2299
-	/**
2300
-	 *  Return list of contacts emails or mobile existing for third party
2301
-	 *
2302
-	 *  @param	string	$mode       		'email' or 'mobile'
2303
-	 * 	@param	int		$hidedisabled		1=Hide contact if disabled
2304
-	 *  @return array       				Array of contacts emails or mobile. Example: array(id=>'Name <email>')
2305
-	 */
2306
-	function contact_property_array($mode='email', $hidedisabled=0)
2307
-	{
2299
+    /**
2300
+     *  Return list of contacts emails or mobile existing for third party
2301
+     *
2302
+     *  @param	string	$mode       		'email' or 'mobile'
2303
+     * 	@param	int		$hidedisabled		1=Hide contact if disabled
2304
+     *  @return array       				Array of contacts emails or mobile. Example: array(id=>'Name <email>')
2305
+     */
2306
+    function contact_property_array($mode='email', $hidedisabled=0)
2307
+    {
2308 2308
         // phpcs:enable
2309
-		global $langs;
2310
-
2311
-		$contact_property = array();
2312
-
2313
-
2314
-		$sql = "SELECT rowid, email, statut, phone_mobile, lastname, poste, firstname";
2315
-		$sql.= " FROM ".MAIN_DB_PREFIX."socpeople";
2316
-		$sql.= " WHERE fk_soc = ".$this->id;
2317
-
2318
-		$resql=$this->db->query($sql);
2319
-		if ($resql)
2320
-		{
2321
-			$nump = $this->db->num_rows($resql);
2322
-			if ($nump)
2323
-			{
2324
-				$sepa="("; $sepb=")";
2325
-				if ($mode == 'email')
2326
-				{
2327
-					//$sepa="&lt;"; $sepb="&gt;";
2328
-					$sepa="<"; $sepb=">";
2329
-				}
2330
-				$i = 0;
2331
-				while ($i < $nump)
2332
-				{
2333
-					$obj = $this->db->fetch_object($resql);
2334
-					if ($mode == 'email') $property=$obj->email;
2335
-					else if ($mode == 'mobile') $property=$obj->phone_mobile;
2336
-					else $property=$obj->$mode;
2337
-
2338
-					// Show all contact. If hidedisabled is 1, showonly contacts with status = 1
2339
-					if ($obj->statut == 1 || empty($hidedisabled))
2340
-					{
2341
-						if (empty($property))
2342
-						{
2343
-							if ($mode == 'email') $property=$langs->transnoentitiesnoconv("NoEMail");
2344
-							else if ($mode == 'mobile') $property=$langs->transnoentitiesnoconv("NoMobilePhone");
2345
-						}
2346
-
2347
-						if (!empty($obj->poste))
2348
-						{
2349
-							$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname,$obj->lastname)).($obj->poste?" - ".$obj->poste:"").(($mode != 'poste' && $property)?" ".$sepa.$property.$sepb:'');
2350
-						}
2351
-						else
2352
-						{
2353
-							$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname,$obj->lastname)).(($mode != 'poste' && $property)?" ".$sepa.$property.$sepb:'');
2354
-						}
2355
-					}
2356
-					$i++;
2357
-				}
2358
-			}
2359
-		}
2360
-		else
2361
-		{
2362
-			dol_print_error($this->db);
2363
-		}
2364
-		return $contact_property;
2365
-	}
2309
+        global $langs;
2310
+
2311
+        $contact_property = array();
2312
+
2313
+
2314
+        $sql = "SELECT rowid, email, statut, phone_mobile, lastname, poste, firstname";
2315
+        $sql.= " FROM ".MAIN_DB_PREFIX."socpeople";
2316
+        $sql.= " WHERE fk_soc = ".$this->id;
2317
+
2318
+        $resql=$this->db->query($sql);
2319
+        if ($resql)
2320
+        {
2321
+            $nump = $this->db->num_rows($resql);
2322
+            if ($nump)
2323
+            {
2324
+                $sepa="("; $sepb=")";
2325
+                if ($mode == 'email')
2326
+                {
2327
+                    //$sepa="&lt;"; $sepb="&gt;";
2328
+                    $sepa="<"; $sepb=">";
2329
+                }
2330
+                $i = 0;
2331
+                while ($i < $nump)
2332
+                {
2333
+                    $obj = $this->db->fetch_object($resql);
2334
+                    if ($mode == 'email') $property=$obj->email;
2335
+                    else if ($mode == 'mobile') $property=$obj->phone_mobile;
2336
+                    else $property=$obj->$mode;
2337
+
2338
+                    // Show all contact. If hidedisabled is 1, showonly contacts with status = 1
2339
+                    if ($obj->statut == 1 || empty($hidedisabled))
2340
+                    {
2341
+                        if (empty($property))
2342
+                        {
2343
+                            if ($mode == 'email') $property=$langs->transnoentitiesnoconv("NoEMail");
2344
+                            else if ($mode == 'mobile') $property=$langs->transnoentitiesnoconv("NoMobilePhone");
2345
+                        }
2346
+
2347
+                        if (!empty($obj->poste))
2348
+                        {
2349
+                            $contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname,$obj->lastname)).($obj->poste?" - ".$obj->poste:"").(($mode != 'poste' && $property)?" ".$sepa.$property.$sepb:'');
2350
+                        }
2351
+                        else
2352
+                        {
2353
+                            $contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname,$obj->lastname)).(($mode != 'poste' && $property)?" ".$sepa.$property.$sepb:'');
2354
+                        }
2355
+                    }
2356
+                    $i++;
2357
+                }
2358
+            }
2359
+        }
2360
+        else
2361
+        {
2362
+            dol_print_error($this->db);
2363
+        }
2364
+        return $contact_property;
2365
+    }
2366 2366
 
2367 2367
 
2368 2368
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2369
-	/**
2370
-	 *    Renvoie la liste des contacts de cette societe
2371
-	 *
2372
-	 *    @return     array      tableau des contacts
2373
-	 */
2374
-	function contact_array()
2375
-	{
2369
+    /**
2370
+     *    Renvoie la liste des contacts de cette societe
2371
+     *
2372
+     *    @return     array      tableau des contacts
2373
+     */
2374
+    function contact_array()
2375
+    {
2376 2376
         // phpcs:enable
2377
-		$contacts = array();
2378
-
2379
-		$sql = "SELECT rowid, lastname, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id;
2380
-		$resql=$this->db->query($sql);
2381
-		if ($resql)
2382
-		{
2383
-			$nump = $this->db->num_rows($resql);
2384
-			if ($nump)
2385
-			{
2386
-				$i = 0;
2387
-				while ($i < $nump)
2388
-				{
2389
-					$obj = $this->db->fetch_object($resql);
2390
-					$contacts[$obj->rowid] = dolGetFirstLastname($obj->firstname,$obj->lastname);
2391
-					$i++;
2392
-				}
2393
-			}
2394
-		}
2395
-		else
2396
-		{
2397
-			dol_print_error($this->db);
2398
-		}
2399
-		return $contacts;
2400
-	}
2377
+        $contacts = array();
2378
+
2379
+        $sql = "SELECT rowid, lastname, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id;
2380
+        $resql=$this->db->query($sql);
2381
+        if ($resql)
2382
+        {
2383
+            $nump = $this->db->num_rows($resql);
2384
+            if ($nump)
2385
+            {
2386
+                $i = 0;
2387
+                while ($i < $nump)
2388
+                {
2389
+                    $obj = $this->db->fetch_object($resql);
2390
+                    $contacts[$obj->rowid] = dolGetFirstLastname($obj->firstname,$obj->lastname);
2391
+                    $i++;
2392
+                }
2393
+            }
2394
+        }
2395
+        else
2396
+        {
2397
+            dol_print_error($this->db);
2398
+        }
2399
+        return $contacts;
2400
+    }
2401 2401
 
2402 2402
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2403
-	/**
2404
-	 *    Renvoie la liste des contacts de cette societe
2405
-	 *
2406
-	 *    @return    array    $contacts    tableau des contacts
2407
-	 */
2408
-	function contact_array_objects()
2409
-	{
2403
+    /**
2404
+     *    Renvoie la liste des contacts de cette societe
2405
+     *
2406
+     *    @return    array    $contacts    tableau des contacts
2407
+     */
2408
+    function contact_array_objects()
2409
+    {
2410 2410
         // phpcs:enable
2411
-		require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
2412
-		$contacts = array();
2413
-
2414
-		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id;
2415
-		$resql=$this->db->query($sql);
2416
-		if ($resql)
2417
-		{
2418
-			$nump = $this->db->num_rows($resql);
2419
-			if ($nump)
2420
-			{
2421
-				$i = 0;
2422
-				while ($i < $nump)
2423
-				{
2424
-					$obj = $this->db->fetch_object($resql);
2425
-					$contact = new Contact($this->db);
2426
-					$contact->fetch($obj->rowid);
2427
-					$contacts[] = $contact;
2428
-					$i++;
2429
-				}
2430
-			}
2431
-		}
2432
-		else
2433
-		{
2434
-			dol_print_error($this->db);
2435
-		}
2436
-		return $contacts;
2437
-	}
2411
+        require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
2412
+        $contacts = array();
2413
+
2414
+        $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id;
2415
+        $resql=$this->db->query($sql);
2416
+        if ($resql)
2417
+        {
2418
+            $nump = $this->db->num_rows($resql);
2419
+            if ($nump)
2420
+            {
2421
+                $i = 0;
2422
+                while ($i < $nump)
2423
+                {
2424
+                    $obj = $this->db->fetch_object($resql);
2425
+                    $contact = new Contact($this->db);
2426
+                    $contact->fetch($obj->rowid);
2427
+                    $contacts[] = $contact;
2428
+                    $i++;
2429
+                }
2430
+            }
2431
+        }
2432
+        else
2433
+        {
2434
+            dol_print_error($this->db);
2435
+        }
2436
+        return $contacts;
2437
+    }
2438 2438
 
2439 2439
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2440
-	/**
2441
-	 *  Return property of contact from its id
2442
-	 *
2443
-	 *  @param	int		$rowid      id of contact
2444
-	 *  @param  string	$mode       'email' or 'mobile'
2445
-	 *  @return string  			Email of contact with format: "Full name <email>"
2446
-	 */
2447
-	function contact_get_property($rowid,$mode)
2448
-	{
2440
+    /**
2441
+     *  Return property of contact from its id
2442
+     *
2443
+     *  @param	int		$rowid      id of contact
2444
+     *  @param  string	$mode       'email' or 'mobile'
2445
+     *  @return string  			Email of contact with format: "Full name <email>"
2446
+     */
2447
+    function contact_get_property($rowid,$mode)
2448
+    {
2449 2449
         // phpcs:enable
2450
-		$contact_property='';
2450
+        $contact_property='';
2451 2451
 
2452
-		if (empty($rowid)) return '';
2452
+        if (empty($rowid)) return '';
2453 2453
 
2454
-		$sql = "SELECT rowid, email, phone_mobile, lastname, firstname";
2455
-		$sql.= " FROM ".MAIN_DB_PREFIX."socpeople";
2456
-		$sql.= " WHERE rowid = '".$rowid."'";
2454
+        $sql = "SELECT rowid, email, phone_mobile, lastname, firstname";
2455
+        $sql.= " FROM ".MAIN_DB_PREFIX."socpeople";
2456
+        $sql.= " WHERE rowid = '".$rowid."'";
2457 2457
 
2458
-		$resql=$this->db->query($sql);
2459
-		if ($resql)
2460
-		{
2461
-			$nump = $this->db->num_rows($resql);
2458
+        $resql=$this->db->query($sql);
2459
+        if ($resql)
2460
+        {
2461
+            $nump = $this->db->num_rows($resql);
2462 2462
 
2463
-			if ($nump)
2464
-			{
2465
-				$obj = $this->db->fetch_object($resql);
2463
+            if ($nump)
2464
+            {
2465
+                $obj = $this->db->fetch_object($resql);
2466 2466
 
2467
-				if ($mode == 'email') $contact_property = dol_string_nospecial(dolGetFirstLastname($obj->firstname, $obj->lastname), ' ', array(","))." <".$obj->email.">";
2468
-				else if ($mode == 'mobile') $contact_property = $obj->phone_mobile;
2469
-			}
2470
-			return $contact_property;
2471
-		}
2472
-		else
2473
-		{
2474
-			dol_print_error($this->db);
2475
-		}
2476
-	}
2467
+                if ($mode == 'email') $contact_property = dol_string_nospecial(dolGetFirstLastname($obj->firstname, $obj->lastname), ' ', array(","))." <".$obj->email.">";
2468
+                else if ($mode == 'mobile') $contact_property = $obj->phone_mobile;
2469
+            }
2470
+            return $contact_property;
2471
+        }
2472
+        else
2473
+        {
2474
+            dol_print_error($this->db);
2475
+        }
2476
+    }
2477 2477
 
2478 2478
 
2479 2479
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2480
-	/**
2481
-	 *  Return bank number property of thirdparty (label or rum)
2482
-	 *
2483
-	 *	@param	string	$mode	'label' or 'rum' or 'format'
2484
-	 *  @return	string			Bank number
2485
-	 */
2486
-	function display_rib($mode='label')
2487
-	{
2480
+    /**
2481
+     *  Return bank number property of thirdparty (label or rum)
2482
+     *
2483
+     *	@param	string	$mode	'label' or 'rum' or 'format'
2484
+     *  @return	string			Bank number
2485
+     */
2486
+    function display_rib($mode='label')
2487
+    {
2488 2488
         // phpcs:enable
2489
-		require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
2490
-
2491
-		$bac = new CompanyBankAccount($this->db);
2492
-		$bac->fetch(0,$this->id);
2493
-
2494
-		if ($mode == 'label')
2495
-		{
2496
-			return $bac->getRibLabel(true);
2497
-		}
2498
-		elseif ($mode == 'rum')
2499
-		{
2500
-			if (empty($bac->rum))
2501
-			{
2502
-				require_once DOL_DOCUMENT_ROOT . '/compta/prelevement/class/bonprelevement.class.php';
2503
-				$prelevement = new BonPrelevement($this->db);
2504
-				$bac->fetch_thirdparty();
2505
-				$bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id);
2506
-			}
2507
-			return $bac->rum;
2508
-		}
2509
-		elseif ($mode == 'format')
2510
-		{
2511
-			return $bac->frstrecur;
2512
-		}
2513
-
2514
-		return 'BadParameterToFunctionDisplayRib';
2515
-	}
2489
+        require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
2490
+
2491
+        $bac = new CompanyBankAccount($this->db);
2492
+        $bac->fetch(0,$this->id);
2493
+
2494
+        if ($mode == 'label')
2495
+        {
2496
+            return $bac->getRibLabel(true);
2497
+        }
2498
+        elseif ($mode == 'rum')
2499
+        {
2500
+            if (empty($bac->rum))
2501
+            {
2502
+                require_once DOL_DOCUMENT_ROOT . '/compta/prelevement/class/bonprelevement.class.php';
2503
+                $prelevement = new BonPrelevement($this->db);
2504
+                $bac->fetch_thirdparty();
2505
+                $bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id);
2506
+            }
2507
+            return $bac->rum;
2508
+        }
2509
+        elseif ($mode == 'format')
2510
+        {
2511
+            return $bac->frstrecur;
2512
+        }
2513
+
2514
+        return 'BadParameterToFunctionDisplayRib';
2515
+    }
2516 2516
 
2517 2517
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2518
-	/**
2519
-	 * Return Array of RIB
2520
-	 *
2521
-	 * @return     array|int        0 if KO, Array of CompanyBanckAccount if OK
2522
-	 */
2523
-	function get_all_rib()
2524
-	{
2518
+    /**
2519
+     * Return Array of RIB
2520
+     *
2521
+     * @return     array|int        0 if KO, Array of CompanyBanckAccount if OK
2522
+     */
2523
+    function get_all_rib()
2524
+    {
2525 2525
         // phpcs:enable
2526
-		require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
2527
-		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_rib WHERE type='ban' AND fk_soc = ".$this->id;
2528
-		$result = $this->db->query($sql);
2529
-		if (!$result) {
2530
-			$this->error++;
2531
-			$this->errors[] = $this->db->lasterror;
2532
-			return 0;
2533
-		} else {
2534
-			$num_rows = $this->db->num_rows($result);
2535
-			$rib_array = array();
2536
-			if ($num_rows) {
2537
-				while ($obj = $this->db->fetch_object($result)) {
2538
-					$rib = new CompanyBankAccount($this->db);
2539
-					$rib->fetch($obj->rowid);
2540
-					$rib_array[] = $rib;
2541
-				}
2542
-			}
2543
-			return $rib_array;
2544
-		}
2545
-	}
2526
+        require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
2527
+        $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_rib WHERE type='ban' AND fk_soc = ".$this->id;
2528
+        $result = $this->db->query($sql);
2529
+        if (!$result) {
2530
+            $this->error++;
2531
+            $this->errors[] = $this->db->lasterror;
2532
+            return 0;
2533
+        } else {
2534
+            $num_rows = $this->db->num_rows($result);
2535
+            $rib_array = array();
2536
+            if ($num_rows) {
2537
+                while ($obj = $this->db->fetch_object($result)) {
2538
+                    $rib = new CompanyBankAccount($this->db);
2539
+                    $rib->fetch($obj->rowid);
2540
+                    $rib_array[] = $rib;
2541
+                }
2542
+            }
2543
+            return $rib_array;
2544
+        }
2545
+    }
2546 2546
 
2547 2547
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2548
-	/**
2549
-	 *  Attribut un code client a partir du module de controle des codes.
2550
-	 *  Return value is stored into this->code_client
2551
-	 *
2552
-	 *	@param	Societe		$objsoc		Object thirdparty
2553
-	 *	@param	int			$type		Should be 0 to say customer
2554
-	 *  @return void
2555
-	 */
2556
-	function get_codeclient($objsoc=0,$type=0)
2557
-	{
2548
+    /**
2549
+     *  Attribut un code client a partir du module de controle des codes.
2550
+     *  Return value is stored into this->code_client
2551
+     *
2552
+     *	@param	Societe		$objsoc		Object thirdparty
2553
+     *	@param	int			$type		Should be 0 to say customer
2554
+     *  @return void
2555
+     */
2556
+    function get_codeclient($objsoc=0,$type=0)
2557
+    {
2558 2558
         // phpcs:enable
2559
-		global $conf;
2560
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2561
-		{
2562
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2563
-
2564
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2565
-			foreach ($dirsociete as $dirroot)
2566
-			{
2567
-				$res=dol_include_once($dirroot.$module.'.php');
2568
-				if ($res) break;
2569
-			}
2570
-			$mod = new $module();
2571
-
2572
-			$this->code_client = $mod->getNextValue($objsoc,$type);
2573
-			$this->prefixCustomerIsRequired = $mod->prefixIsRequired;
2574
-
2575
-			dol_syslog(get_class($this)."::get_codeclient code_client=".$this->code_client." module=".$module);
2576
-		}
2577
-	}
2559
+        global $conf;
2560
+        if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2561
+        {
2562
+            $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2563
+
2564
+            $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2565
+            foreach ($dirsociete as $dirroot)
2566
+            {
2567
+                $res=dol_include_once($dirroot.$module.'.php');
2568
+                if ($res) break;
2569
+            }
2570
+            $mod = new $module();
2571
+
2572
+            $this->code_client = $mod->getNextValue($objsoc,$type);
2573
+            $this->prefixCustomerIsRequired = $mod->prefixIsRequired;
2574
+
2575
+            dol_syslog(get_class($this)."::get_codeclient code_client=".$this->code_client." module=".$module);
2576
+        }
2577
+    }
2578 2578
 
2579 2579
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2580
-	/**
2581
-	 *  Attribut un code fournisseur a partir du module de controle des codes.
2582
-	 *  Return value is stored into this->code_fournisseur
2583
-	 *
2584
-	 *	@param	Societe		$objsoc		Object thirdparty
2585
-	 *	@param	int			$type		Should be 1 to say supplier
2586
-	 *  @return void
2587
-	 */
2588
-	function get_codefournisseur($objsoc=0,$type=1)
2589
-	{
2580
+    /**
2581
+     *  Attribut un code fournisseur a partir du module de controle des codes.
2582
+     *  Return value is stored into this->code_fournisseur
2583
+     *
2584
+     *	@param	Societe		$objsoc		Object thirdparty
2585
+     *	@param	int			$type		Should be 1 to say supplier
2586
+     *  @return void
2587
+     */
2588
+    function get_codefournisseur($objsoc=0,$type=1)
2589
+    {
2590 2590
         // phpcs:enable
2591
-		global $conf;
2592
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2593
-		{
2594
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2591
+        global $conf;
2592
+        if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2593
+        {
2594
+            $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2595 2595
 
2596
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2597
-			foreach ($dirsociete as $dirroot)
2598
-			{
2599
-				$res=dol_include_once($dirroot.$module.'.php');
2600
-				if ($res) break;
2601
-			}
2602
-			$mod = new $module();
2596
+            $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2597
+            foreach ($dirsociete as $dirroot)
2598
+            {
2599
+                $res=dol_include_once($dirroot.$module.'.php');
2600
+                if ($res) break;
2601
+            }
2602
+            $mod = new $module();
2603 2603
 
2604
-			$this->code_fournisseur = $mod->getNextValue($objsoc,$type);
2604
+            $this->code_fournisseur = $mod->getNextValue($objsoc,$type);
2605 2605
 
2606
-			dol_syslog(get_class($this)."::get_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$module);
2607
-		}
2608
-	}
2606
+            dol_syslog(get_class($this)."::get_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$module);
2607
+        }
2608
+    }
2609 2609
 
2610 2610
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2611
-	/**
2612
-	 *    Verifie si un code client est modifiable en fonction des parametres
2613
-	 *    du module de controle des codes.
2614
-	 *
2615
-	 *    @return     int		0=No, 1=Yes
2616
-	 */
2617
-	function codeclient_modifiable()
2618
-	{
2611
+    /**
2612
+     *    Verifie si un code client est modifiable en fonction des parametres
2613
+     *    du module de controle des codes.
2614
+     *
2615
+     *    @return     int		0=No, 1=Yes
2616
+     */
2617
+    function codeclient_modifiable()
2618
+    {
2619 2619
         // phpcs:enable
2620
-		global $conf;
2621
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2622
-		{
2623
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2624
-
2625
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2626
-			foreach ($dirsociete as $dirroot)
2627
-			{
2628
-				$res=dol_include_once($dirroot.$module.'.php');
2629
-				if ($res) break;
2630
-			}
2631
-
2632
-			$mod = new $module();
2633
-
2634
-			dol_syslog(get_class($this)."::codeclient_modifiable code_client=".$this->code_client." module=".$module);
2635
-			if ($mod->code_modifiable_null && ! $this->code_client) return 1;
2636
-			if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) return 1;
2637
-			if ($mod->code_modifiable) return 1;	// A mettre en dernier
2638
-			return 0;
2639
-		}
2640
-		else
2641
-		{
2642
-			return 0;
2643
-		}
2644
-	}
2620
+        global $conf;
2621
+        if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2622
+        {
2623
+            $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2624
+
2625
+            $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2626
+            foreach ($dirsociete as $dirroot)
2627
+            {
2628
+                $res=dol_include_once($dirroot.$module.'.php');
2629
+                if ($res) break;
2630
+            }
2631
+
2632
+            $mod = new $module();
2633
+
2634
+            dol_syslog(get_class($this)."::codeclient_modifiable code_client=".$this->code_client." module=".$module);
2635
+            if ($mod->code_modifiable_null && ! $this->code_client) return 1;
2636
+            if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) return 1;
2637
+            if ($mod->code_modifiable) return 1;	// A mettre en dernier
2638
+            return 0;
2639
+        }
2640
+        else
2641
+        {
2642
+            return 0;
2643
+        }
2644
+    }
2645 2645
 
2646 2646
 
2647 2647
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2648
-	/**
2649
-	 *    Verifie si un code fournisseur est modifiable dans configuration du module de controle des codes
2650
-	 *
2651
-	 *    @return     int		0=No, 1=Yes
2652
-	 */
2653
-	function codefournisseur_modifiable()
2654
-	{
2648
+    /**
2649
+     *    Verifie si un code fournisseur est modifiable dans configuration du module de controle des codes
2650
+     *
2651
+     *    @return     int		0=No, 1=Yes
2652
+     */
2653
+    function codefournisseur_modifiable()
2654
+    {
2655 2655
         // phpcs:enable
2656
-		global $conf;
2657
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2658
-		{
2659
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2660
-
2661
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2662
-			foreach ($dirsociete as $dirroot)
2663
-			{
2664
-				$res=dol_include_once($dirroot.$module.'.php');
2665
-				if ($res) break;
2666
-			}
2667
-
2668
-			$mod = new $module();
2669
-
2670
-			dol_syslog(get_class($this)."::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur." module=".$module);
2671
-			if ($mod->code_modifiable_null && ! $this->code_fournisseur) return 1;
2672
-			if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) return 1;
2673
-			if ($mod->code_modifiable) return 1;	// A mettre en dernier
2674
-			return 0;
2675
-		}
2676
-		else
2677
-		{
2678
-			return 0;
2679
-		}
2680
-	}
2656
+        global $conf;
2657
+        if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2658
+        {
2659
+            $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2660
+
2661
+            $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2662
+            foreach ($dirsociete as $dirroot)
2663
+            {
2664
+                $res=dol_include_once($dirroot.$module.'.php');
2665
+                if ($res) break;
2666
+            }
2667
+
2668
+            $mod = new $module();
2669
+
2670
+            dol_syslog(get_class($this)."::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur." module=".$module);
2671
+            if ($mod->code_modifiable_null && ! $this->code_fournisseur) return 1;
2672
+            if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) return 1;
2673
+            if ($mod->code_modifiable) return 1;	// A mettre en dernier
2674
+            return 0;
2675
+        }
2676
+        else
2677
+        {
2678
+            return 0;
2679
+        }
2680
+    }
2681 2681
 
2682 2682
 
2683 2683
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2684
-	/**
2685
-	 *  Check customer code
2686
-	 *
2687
-	 *  @return     int				0 if OK
2688
-	 * 								-1 ErrorBadCustomerCodeSyntax
2689
-	 * 								-2 ErrorCustomerCodeRequired
2690
-	 * 								-3 ErrorCustomerCodeAlreadyUsed
2691
-	 * 								-4 ErrorPrefixRequired
2692
-	 */
2693
-	function check_codeclient()
2694
-	{
2684
+    /**
2685
+     *  Check customer code
2686
+     *
2687
+     *  @return     int				0 if OK
2688
+     * 								-1 ErrorBadCustomerCodeSyntax
2689
+     * 								-2 ErrorCustomerCodeRequired
2690
+     * 								-3 ErrorCustomerCodeAlreadyUsed
2691
+     * 								-4 ErrorPrefixRequired
2692
+     */
2693
+    function check_codeclient()
2694
+    {
2695 2695
         // phpcs:enable
2696
-		global $conf;
2697
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2698
-		{
2699
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2700
-
2701
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2702
-			foreach ($dirsociete as $dirroot)
2703
-			{
2704
-				$res=dol_include_once($dirroot.$module.'.php');
2705
-				if ($res) break;
2706
-			}
2707
-
2708
-			$mod = new $module();
2709
-
2710
-		   	dol_syslog(get_class($this)."::check_codeclient code_client=".$this->code_client." module=".$module);
2711
-		   	$result = $mod->verif($this->db, $this->code_client, $this, 0);
2712
-			return $result;
2713
-		}
2714
-		else
2715
-		{
2716
-			return 0;
2717
-		}
2718
-	}
2696
+        global $conf;
2697
+        if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2698
+        {
2699
+            $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2700
+
2701
+            $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2702
+            foreach ($dirsociete as $dirroot)
2703
+            {
2704
+                $res=dol_include_once($dirroot.$module.'.php');
2705
+                if ($res) break;
2706
+            }
2707
+
2708
+            $mod = new $module();
2709
+
2710
+                dol_syslog(get_class($this)."::check_codeclient code_client=".$this->code_client." module=".$module);
2711
+                $result = $mod->verif($this->db, $this->code_client, $this, 0);
2712
+            return $result;
2713
+        }
2714
+        else
2715
+        {
2716
+            return 0;
2717
+        }
2718
+    }
2719 2719
 
2720 2720
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2721
-	/**
2722
-	 *    Check supplier code
2723
-	 *
2724
-	 *    @return     int		0 if OK
2725
-	 * 							-1 ErrorBadCustomerCodeSyntax
2726
-	 * 							-2 ErrorCustomerCodeRequired
2727
-	 * 							-3 ErrorCustomerCodeAlreadyUsed
2728
-	 * 							-4 ErrorPrefixRequired
2729
-	 */
2730
-	function check_codefournisseur()
2731
-	{
2721
+    /**
2722
+     *    Check supplier code
2723
+     *
2724
+     *    @return     int		0 if OK
2725
+     * 							-1 ErrorBadCustomerCodeSyntax
2726
+     * 							-2 ErrorCustomerCodeRequired
2727
+     * 							-3 ErrorCustomerCodeAlreadyUsed
2728
+     * 							-4 ErrorPrefixRequired
2729
+     */
2730
+    function check_codefournisseur()
2731
+    {
2732 2732
         // phpcs:enable
2733
-		global $conf;
2734
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2735
-		{
2736
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2737
-
2738
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2739
-			foreach ($dirsociete as $dirroot)
2740
-			{
2741
-				$res=dol_include_once($dirroot.$module.'.php');
2742
-				if ($res) break;
2743
-			}
2744
-
2745
-			$mod = new $module();
2746
-
2747
-			dol_syslog(get_class($this)."::check_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$module);
2748
-			$result = $mod->verif($this->db, $this->code_fournisseur, $this, 1);
2749
-			return $result;
2750
-		}
2751
-		else
2752
-		{
2753
-			return 0;
2754
-		}
2755
-	}
2733
+        global $conf;
2734
+        if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2735
+        {
2736
+            $module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2737
+
2738
+            $dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2739
+            foreach ($dirsociete as $dirroot)
2740
+            {
2741
+                $res=dol_include_once($dirroot.$module.'.php');
2742
+                if ($res) break;
2743
+            }
2744
+
2745
+            $mod = new $module();
2746
+
2747
+            dol_syslog(get_class($this)."::check_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$module);
2748
+            $result = $mod->verif($this->db, $this->code_fournisseur, $this, 1);
2749
+            return $result;
2750
+        }
2751
+        else
2752
+        {
2753
+            return 0;
2754
+        }
2755
+    }
2756 2756
 
2757 2757
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2758
-	/**
2759
-	 *    	Renvoie un code compta, suivant le module de code compta.
2760
-	 *      Peut etre identique a celui saisit ou genere automatiquement.
2761
-	 *      A ce jour seule la generation automatique est implementee
2762
-	 *
2763
-	 *    	@param	string	$type		Type of thirdparty ('customer' or 'supplier')
2764
-	 *		@return	string				Code compta si ok, 0 si aucun, <0 si ko
2765
-	 */
2766
-	function get_codecompta($type)
2767
-	{
2758
+    /**
2759
+     *    	Renvoie un code compta, suivant le module de code compta.
2760
+     *      Peut etre identique a celui saisit ou genere automatiquement.
2761
+     *      A ce jour seule la generation automatique est implementee
2762
+     *
2763
+     *    	@param	string	$type		Type of thirdparty ('customer' or 'supplier')
2764
+     *		@return	string				Code compta si ok, 0 si aucun, <0 si ko
2765
+     */
2766
+    function get_codecompta($type)
2767
+    {
2768 2768
         // phpcs:enable
2769
-		global $conf;
2770
-
2771
-		if (! empty($conf->global->SOCIETE_CODECOMPTA_ADDON))
2772
-		{
2773
-			$res=false;
2774
-			$dirsociete=array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2775
-			foreach ($dirsociete as $dirroot)
2776
-			{
2777
-				$res=dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.'.php');
2778
-				if ($res) break;
2779
-			}
2780
-
2781
-			if ($res)
2782
-			{
2783
-				$classname = $conf->global->SOCIETE_CODECOMPTA_ADDON;
2784
-				$mod = new $classname;
2785
-
2786
-				// Defini code compta dans $mod->code
2787
-				$result = $mod->get_code($this->db, $this, $type);
2788
-
2789
-				if ($type == 'customer') $this->code_compta = $mod->code;
2790
-				else if ($type == 'supplier') $this->code_compta_fournisseur = $mod->code;
2791
-
2792
-				return $result;
2793
-			}
2794
-			else
2795
-			{
2796
-				$this->error = 'ErrorAccountancyCodeNotDefined';
2797
-				return -1;
2798
-			}
2799
-		}
2800
-		else
2801
-		{
2802
-			if ($type == 'customer') $this->code_compta = '';
2803
-			else if ($type == 'supplier') $this->code_compta_fournisseur = '';
2804
-
2805
-			return 0;
2806
-		}
2807
-	}
2769
+        global $conf;
2770
+
2771
+        if (! empty($conf->global->SOCIETE_CODECOMPTA_ADDON))
2772
+        {
2773
+            $res=false;
2774
+            $dirsociete=array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2775
+            foreach ($dirsociete as $dirroot)
2776
+            {
2777
+                $res=dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.'.php');
2778
+                if ($res) break;
2779
+            }
2780
+
2781
+            if ($res)
2782
+            {
2783
+                $classname = $conf->global->SOCIETE_CODECOMPTA_ADDON;
2784
+                $mod = new $classname;
2785
+
2786
+                // Defini code compta dans $mod->code
2787
+                $result = $mod->get_code($this->db, $this, $type);
2788
+
2789
+                if ($type == 'customer') $this->code_compta = $mod->code;
2790
+                else if ($type == 'supplier') $this->code_compta_fournisseur = $mod->code;
2791
+
2792
+                return $result;
2793
+            }
2794
+            else
2795
+            {
2796
+                $this->error = 'ErrorAccountancyCodeNotDefined';
2797
+                return -1;
2798
+            }
2799
+        }
2800
+        else
2801
+        {
2802
+            if ($type == 'customer') $this->code_compta = '';
2803
+            else if ($type == 'supplier') $this->code_compta_fournisseur = '';
2804
+
2805
+            return 0;
2806
+        }
2807
+    }
2808 2808
 
2809 2809
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2810
-	/**
2811
-	 *    Define parent commany of current company
2812
-	 *
2813
-	 *    @param	int		$id     Id of thirdparty to set or '' to remove
2814
-	 *    @return	int     		<0 if KO, >0 if OK
2815
-	 */
2816
-	function set_parent($id)
2817
-	{
2810
+    /**
2811
+     *    Define parent commany of current company
2812
+     *
2813
+     *    @param	int		$id     Id of thirdparty to set or '' to remove
2814
+     *    @return	int     		<0 if KO, >0 if OK
2815
+     */
2816
+    function set_parent($id)
2817
+    {
2818 2818
         // phpcs:enable
2819
-		if ($this->id)
2820
-		{
2821
-			$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
2822
-			$sql.= " SET parent = ".($id > 0 ? $id : "null");
2823
-			$sql.= " WHERE rowid = " . $this->id;
2824
-			dol_syslog(get_class($this).'::set_parent', LOG_DEBUG);
2825
-			$resql=$this->db->query($sql);
2826
-			if ($resql)
2827
-			{
2828
-				$this->parent = $id;
2829
-				return 1;
2830
-			}
2831
-			else
2832
-			{
2833
-				return -1;
2834
-			}
2835
-		}
2836
-		else return -1;
2837
-	}
2819
+        if ($this->id)
2820
+        {
2821
+            $sql = "UPDATE ".MAIN_DB_PREFIX."societe";
2822
+            $sql.= " SET parent = ".($id > 0 ? $id : "null");
2823
+            $sql.= " WHERE rowid = " . $this->id;
2824
+            dol_syslog(get_class($this).'::set_parent', LOG_DEBUG);
2825
+            $resql=$this->db->query($sql);
2826
+            if ($resql)
2827
+            {
2828
+                $this->parent = $id;
2829
+                return 1;
2830
+            }
2831
+            else
2832
+            {
2833
+                return -1;
2834
+            }
2835
+        }
2836
+        else return -1;
2837
+    }
2838 2838
 
2839 2839
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2840
-	/**
2841
-	 *  Returns if a profid sould be verified
2842
-	 *
2843
-	 *  @param	int		$idprof		1,2,3,4,5,6 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm,5=idprof5,6=idprof6)
2844
-	 *  @return boolean         	true , false
2845
-	 */
2846
-	function id_prof_verifiable($idprof)
2847
-	{
2840
+    /**
2841
+     *  Returns if a profid sould be verified
2842
+     *
2843
+     *  @param	int		$idprof		1,2,3,4,5,6 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm,5=idprof5,6=idprof6)
2844
+     *  @return boolean         	true , false
2845
+     */
2846
+    function id_prof_verifiable($idprof)
2847
+    {
2848 2848
         // phpcs:enable
2849
-		global $conf;
2850
-
2851
-	 	switch($idprof)
2852
-		{
2853
-			case 1:
2854
-				$ret=(!$conf->global->SOCIETE_IDPROF1_UNIQUE?false:true);
2855
-				break;
2856
-			case 2:
2857
-				$ret=(!$conf->global->SOCIETE_IDPROF2_UNIQUE?false:true);
2858
-				break;
2859
-			case 3:
2860
-				$ret=(!$conf->global->SOCIETE_IDPROF3_UNIQUE?false:true);
2861
-				break;
2862
-			case 4:
2863
-				$ret=(!$conf->global->SOCIETE_IDPROF4_UNIQUE?false:true);
2864
-				break;
2865
-			case 5:
2866
-				$ret=(!$conf->global->SOCIETE_IDPROF5_UNIQUE?false:true);
2867
-				break;
2868
-			case 6:
2869
-				$ret=(!$conf->global->SOCIETE_IDPROF6_UNIQUE?false:true);
2870
-				break;
2871
-			default:
2872
-				$ret=false;
2873
-		}
2874
-
2875
-		return $ret;
2876
-	}
2849
+        global $conf;
2850
+
2851
+            switch($idprof)
2852
+        {
2853
+            case 1:
2854
+                $ret=(!$conf->global->SOCIETE_IDPROF1_UNIQUE?false:true);
2855
+                break;
2856
+            case 2:
2857
+                $ret=(!$conf->global->SOCIETE_IDPROF2_UNIQUE?false:true);
2858
+                break;
2859
+            case 3:
2860
+                $ret=(!$conf->global->SOCIETE_IDPROF3_UNIQUE?false:true);
2861
+                break;
2862
+            case 4:
2863
+                $ret=(!$conf->global->SOCIETE_IDPROF4_UNIQUE?false:true);
2864
+                break;
2865
+            case 5:
2866
+                $ret=(!$conf->global->SOCIETE_IDPROF5_UNIQUE?false:true);
2867
+                break;
2868
+            case 6:
2869
+                $ret=(!$conf->global->SOCIETE_IDPROF6_UNIQUE?false:true);
2870
+                break;
2871
+            default:
2872
+                $ret=false;
2873
+        }
2874
+
2875
+        return $ret;
2876
+    }
2877 2877
 
2878 2878
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2879
-	/**
2880
-	 *    Verify if a profid exists into database for others thirds
2881
-	 *
2882
-	 *    @param	string	$idprof		'idprof1','idprof2','idprof3','idprof4','idprof5','idprof6','email' (Example: idprof1=siren, idprof2=siret, idprof3=naf, idprof4=rcs/rm)
2883
-	 *    @param	string	$value		Value of profid
2884
-	 *    @param	int		$socid		Id of thirdparty to exclude (if update)
2885
-	 *    @return   boolean				True if exists, False if not
2886
-	 */
2887
-	function id_prof_exists($idprof, $value, $socid=0)
2888
-	{
2879
+    /**
2880
+     *    Verify if a profid exists into database for others thirds
2881
+     *
2882
+     *    @param	string	$idprof		'idprof1','idprof2','idprof3','idprof4','idprof5','idprof6','email' (Example: idprof1=siren, idprof2=siret, idprof3=naf, idprof4=rcs/rm)
2883
+     *    @param	string	$value		Value of profid
2884
+     *    @param	int		$socid		Id of thirdparty to exclude (if update)
2885
+     *    @return   boolean				True if exists, False if not
2886
+     */
2887
+    function id_prof_exists($idprof, $value, $socid=0)
2888
+    {
2889 2889
         // phpcs:enable
2890
-		$field = $idprof;
2891
-
2892
-	 	switch($idprof)	// For backward compatibility
2893
-		{
2894
-			case '1':
2895
-			case 'idprof1':
2896
-				$field="siren";
2897
-				break;
2898
-			case '2':
2899
-			case 'idprof2':
2900
-				$field="siret";
2901
-				break;
2902
-			case '3':
2903
-			case 'idprof3':
2904
-				$field="ape";
2905
-				break;
2906
-			case '4':
2907
-			case 'idprof4':
2908
-				$field="idprof4";
2909
-				break;
2910
-			case '5':
2911
-				$field="idprof5";
2912
-				break;
2913
-			case '6':
2914
-				$field="idprof6";
2915
-				break;
2916
-	 	}
2917
-
2918
-		 //Verify duplicate entries
2919
-		$sql  = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$value."' AND entity IN (".getEntity('societe').")";
2920
-		if($socid) $sql .= " AND rowid <> ".$socid;
2921
-		$resql = $this->db->query($sql);
2922
-		if ($resql)
2923
-		{
2924
-			$obj = $this->db->fetch_object($resql);
2925
-			$count = $obj->idprof;
2926
-		}
2927
-		else
2928
-		{
2929
-			$count = 0;
2930
-			print $this->db->error();
2931
-		}
2932
-		$this->db->free($resql);
2933
-
2934
-		if ($count > 0) return true;
2935
-		else return false;
2936
-	}
2890
+        $field = $idprof;
2891
+
2892
+            switch($idprof)	// For backward compatibility
2893
+        {
2894
+            case '1':
2895
+            case 'idprof1':
2896
+                $field="siren";
2897
+                break;
2898
+            case '2':
2899
+            case 'idprof2':
2900
+                $field="siret";
2901
+                break;
2902
+            case '3':
2903
+            case 'idprof3':
2904
+                $field="ape";
2905
+                break;
2906
+            case '4':
2907
+            case 'idprof4':
2908
+                $field="idprof4";
2909
+                break;
2910
+            case '5':
2911
+                $field="idprof5";
2912
+                break;
2913
+            case '6':
2914
+                $field="idprof6";
2915
+                break;
2916
+            }
2917
+
2918
+            //Verify duplicate entries
2919
+        $sql  = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$value."' AND entity IN (".getEntity('societe').")";
2920
+        if($socid) $sql .= " AND rowid <> ".$socid;
2921
+        $resql = $this->db->query($sql);
2922
+        if ($resql)
2923
+        {
2924
+            $obj = $this->db->fetch_object($resql);
2925
+            $count = $obj->idprof;
2926
+        }
2927
+        else
2928
+        {
2929
+            $count = 0;
2930
+            print $this->db->error();
2931
+        }
2932
+        $this->db->free($resql);
2933
+
2934
+        if ($count > 0) return true;
2935
+        else return false;
2936
+    }
2937 2937
 
2938 2938
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
2939
-	/**
2940
-	 *  Verifie la validite d'un identifiant professionnel en fonction du pays de la societe (siren, siret, ...)
2941
-	 *
2942
-	 *  @param	int			$idprof         1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm)
2943
-	 *  @param  Societe		$soc            Objet societe
2944
-	 *  @return int             			<=0 if KO, >0 if OK
2945
-	 *  TODO better to have this in a lib than into a business class
2946
-	 */
2947
-	function id_prof_check($idprof,$soc)
2948
-	{
2939
+    /**
2940
+     *  Verifie la validite d'un identifiant professionnel en fonction du pays de la societe (siren, siret, ...)
2941
+     *
2942
+     *  @param	int			$idprof         1,2,3,4 (Exemple: 1=siren,2=siret,3=naf,4=rcs/rm)
2943
+     *  @param  Societe		$soc            Objet societe
2944
+     *  @return int             			<=0 if KO, >0 if OK
2945
+     *  TODO better to have this in a lib than into a business class
2946
+     */
2947
+    function id_prof_check($idprof,$soc)
2948
+    {
2949 2949
         // phpcs:enable
2950
-		global $conf;
2951
-
2952
-		$ok=1;
2953
-
2954
-		if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) return 1;
2955
-
2956
-		// Verifie SIREN si pays FR
2957
-		if ($idprof == 1 && $soc->country_code == 'FR')
2958
-		{
2959
-			$chaine=trim($this->idprof1);
2960
-			$chaine=preg_replace('/(\s)/','',$chaine);
2961
-
2962
-			if (!is_numeric($chaine)) return -1;
2963
-			if (dol_strlen($chaine) != 9) return -1;
2964
-
2965
-			// on prend chaque chiffre un par un
2966
-			// si son index (position dans la chaîne en commence à 0 au premier caractère) est impair
2967
-			// on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9
2968
-			// on ajoute cette valeur à la somme totale
2969
-
2970
-			for ($index = 0; $index < 9; $index ++)
2971
-			{
2972
-				$number = (int) $siren[$index];
2973
-				if (($index % 2) != 0) { if (($number *= 2) > 9) $number -= 9; }
2974
-				$sum += $number;
2975
-			}
2976
-
2977
-			// le numéro est valide si la somme des chiffres est multiple de 10
2978
-			if (($sum % 10) != 0) return -1;
2979
-		}
2980
-
2981
-		// Verifie SIRET si pays FR
2982
-		if ($idprof == 2 && $soc->country_code == 'FR')
2983
-		{
2984
-			$chaine=trim($this->idprof2);
2985
-			$chaine=preg_replace('/(\s)/','',$chaine);
2986
-
2987
-			if (!is_numeric($chaine)) return -1;
2988
-			if (dol_strlen($chaine) != 14) return -1;
2989
-
2990
-			// on prend chaque chiffre un par un
2991
-			// si son index (position dans la chaîne en commence à 0 au premier caractère) est pair
2992
-			// on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9
2993
-			// on ajoute cette valeur à la somme totale
2994
-
2995
-			for ($index = 0; $index < 14; $index ++)
2996
-			{
2997
-				$number = (int) $chaine[$index];
2998
-				if (($index % 2) == 0) { if (($number *= 2) > 9) $number -= 9; }
2999
-				$sum += $number;
3000
-			}
3001
-
3002
-			// le numéro est valide si la somme des chiffres est multiple de 10
3003
-			if (($sum % 10) != 0) return -1;
3004
-		}
3005
-
3006
-		//Verify CIF/NIF/NIE if pays ES
3007
-		//Returns: 1 if NIF ok, 2 if CIF ok, 3 if NIE ok, -1 if NIF bad, -2 if CIF bad, -3 if NIE bad, 0 if unexpected bad
3008
-		if ($idprof == 1 && $soc->country_code == 'ES')
3009
-		{
3010
-			$string=trim($this->idprof1);
3011
-			$string=preg_replace('/(\s)/','',$string);
3012
-			$string = strtoupper($string);
3013
-
3014
-			for ($i = 0; $i < 9; $i ++)
3015
-			$num[$i] = substr($string, $i, 1);
3016
-
3017
-			//Check format
3018
-			if (!preg_match('/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $string))
3019
-			return 0;
3020
-
3021
-			//Check NIF
3022
-			if (preg_match('/(^[0-9]{8}[A-Z]{1}$)/', $string))
3023
-				if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1))
3024
-				return 1;
3025
-				else
3026
-				return -1;
3027
-
3028
-			//algorithm checking type code CIF
3029
-			$sum = $num[2] + $num[4] + $num[6];
3030
-			for ($i = 1; $i < 8; $i += 2)
3031
-			$sum += intval(substr((2 * $num[$i]),0,1)) + intval(substr((2 * $num[$i]),1,1));
3032
-			$n = 10 - substr($sum, strlen($sum) - 1, 1);
3033
-
3034
-			//Chek special NIF
3035
-			if (preg_match('/^[KLM]{1}/', $string))
3036
-				if ($num[8] == chr(64 + $n) || $num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1))
3037
-				return 1;
3038
-				else
3039
-				return -1;
3040
-
3041
-			//Check CIF
3042
-			if (preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $string))
3043
-				if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1))
3044
-				return 2;
3045
-				else
3046
-				return -2;
3047
-
3048
-			//Check NIE T
3049
-			if (preg_match('/^[T]{1}/', $string))
3050
-				if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $string))
3051
-				return 3;
3052
-				else
3053
-				return -3;
3054
-
3055
-			//Check NIE XYZ
3056
-			if (preg_match('/^[XYZ]{1}/', $string))
3057
-				if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X','Y','Z'), array('0','1','2'), $string), 0, 8) % 23, 1))
3058
-				return 3;
3059
-				else
3060
-				return -3;
3061
-
3062
-			//Can not be verified
3063
-			return -4;
3064
-		}
3065
-
3066
-		//Verify NIF if country is PT
3067
-		//Returns: 1 if NIF ok, -1 if NIF bad, 0 if unexpected bad
3068
-		if ($idprof == 1 && $soc->country_code == 'PT')
3069
-		{
3070
-			$string=trim($this->idprof1);
3071
-			$string=preg_replace('/(\s)/','',$string);
3072
-
3073
-			for ($i = 0; $i < 9; $i ++) {
3074
-				$num[$i] = substr($string, $i, 1);
3075
-			}
3076
-
3077
-			//Check NIF
3078
-			if (preg_match('/(^[0-9]{9}$)/', $string)) {
3079
-				return 1;
3080
-			}
3081
-			else {
3082
-				return -1;
3083
-			}
3084
-		}
3085
-
3086
-		return $ok;
3087
-	}
2950
+        global $conf;
2951
+
2952
+        $ok=1;
2953
+
2954
+        if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) return 1;
2955
+
2956
+        // Verifie SIREN si pays FR
2957
+        if ($idprof == 1 && $soc->country_code == 'FR')
2958
+        {
2959
+            $chaine=trim($this->idprof1);
2960
+            $chaine=preg_replace('/(\s)/','',$chaine);
2961
+
2962
+            if (!is_numeric($chaine)) return -1;
2963
+            if (dol_strlen($chaine) != 9) return -1;
2964
+
2965
+            // on prend chaque chiffre un par un
2966
+            // si son index (position dans la chaîne en commence à 0 au premier caractère) est impair
2967
+            // on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9
2968
+            // on ajoute cette valeur à la somme totale
2969
+
2970
+            for ($index = 0; $index < 9; $index ++)
2971
+            {
2972
+                $number = (int) $siren[$index];
2973
+                if (($index % 2) != 0) { if (($number *= 2) > 9) $number -= 9; }
2974
+                $sum += $number;
2975
+            }
2976
+
2977
+            // le numéro est valide si la somme des chiffres est multiple de 10
2978
+            if (($sum % 10) != 0) return -1;
2979
+        }
2980
+
2981
+        // Verifie SIRET si pays FR
2982
+        if ($idprof == 2 && $soc->country_code == 'FR')
2983
+        {
2984
+            $chaine=trim($this->idprof2);
2985
+            $chaine=preg_replace('/(\s)/','',$chaine);
2986
+
2987
+            if (!is_numeric($chaine)) return -1;
2988
+            if (dol_strlen($chaine) != 14) return -1;
2989
+
2990
+            // on prend chaque chiffre un par un
2991
+            // si son index (position dans la chaîne en commence à 0 au premier caractère) est pair
2992
+            // on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9
2993
+            // on ajoute cette valeur à la somme totale
2994
+
2995
+            for ($index = 0; $index < 14; $index ++)
2996
+            {
2997
+                $number = (int) $chaine[$index];
2998
+                if (($index % 2) == 0) { if (($number *= 2) > 9) $number -= 9; }
2999
+                $sum += $number;
3000
+            }
3001
+
3002
+            // le numéro est valide si la somme des chiffres est multiple de 10
3003
+            if (($sum % 10) != 0) return -1;
3004
+        }
3005
+
3006
+        //Verify CIF/NIF/NIE if pays ES
3007
+        //Returns: 1 if NIF ok, 2 if CIF ok, 3 if NIE ok, -1 if NIF bad, -2 if CIF bad, -3 if NIE bad, 0 if unexpected bad
3008
+        if ($idprof == 1 && $soc->country_code == 'ES')
3009
+        {
3010
+            $string=trim($this->idprof1);
3011
+            $string=preg_replace('/(\s)/','',$string);
3012
+            $string = strtoupper($string);
3013
+
3014
+            for ($i = 0; $i < 9; $i ++)
3015
+            $num[$i] = substr($string, $i, 1);
3016
+
3017
+            //Check format
3018
+            if (!preg_match('/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $string))
3019
+            return 0;
3020
+
3021
+            //Check NIF
3022
+            if (preg_match('/(^[0-9]{8}[A-Z]{1}$)/', $string))
3023
+                if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1))
3024
+                return 1;
3025
+                else
3026
+                return -1;
3027
+
3028
+            //algorithm checking type code CIF
3029
+            $sum = $num[2] + $num[4] + $num[6];
3030
+            for ($i = 1; $i < 8; $i += 2)
3031
+            $sum += intval(substr((2 * $num[$i]),0,1)) + intval(substr((2 * $num[$i]),1,1));
3032
+            $n = 10 - substr($sum, strlen($sum) - 1, 1);
3033
+
3034
+            //Chek special NIF
3035
+            if (preg_match('/^[KLM]{1}/', $string))
3036
+                if ($num[8] == chr(64 + $n) || $num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1))
3037
+                return 1;
3038
+                else
3039
+                return -1;
3040
+
3041
+            //Check CIF
3042
+            if (preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $string))
3043
+                if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1))
3044
+                return 2;
3045
+                else
3046
+                return -2;
3047
+
3048
+            //Check NIE T
3049
+            if (preg_match('/^[T]{1}/', $string))
3050
+                if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $string))
3051
+                return 3;
3052
+                else
3053
+                return -3;
3054
+
3055
+            //Check NIE XYZ
3056
+            if (preg_match('/^[XYZ]{1}/', $string))
3057
+                if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X','Y','Z'), array('0','1','2'), $string), 0, 8) % 23, 1))
3058
+                return 3;
3059
+                else
3060
+                return -3;
3061
+
3062
+            //Can not be verified
3063
+            return -4;
3064
+        }
3065
+
3066
+        //Verify NIF if country is PT
3067
+        //Returns: 1 if NIF ok, -1 if NIF bad, 0 if unexpected bad
3068
+        if ($idprof == 1 && $soc->country_code == 'PT')
3069
+        {
3070
+            $string=trim($this->idprof1);
3071
+            $string=preg_replace('/(\s)/','',$string);
3072
+
3073
+            for ($i = 0; $i < 9; $i ++) {
3074
+                $num[$i] = substr($string, $i, 1);
3075
+            }
3076
+
3077
+            //Check NIF
3078
+            if (preg_match('/(^[0-9]{9}$)/', $string)) {
3079
+                return 1;
3080
+            }
3081
+            else {
3082
+                return -1;
3083
+            }
3084
+        }
3085
+
3086
+        return $ok;
3087
+    }
3088 3088
 
3089 3089
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
3090
-	/**
3091
-	 *   Return an url to check online a professional id or empty string
3092
-	 *
3093
-	 *   @param		int		$idprof         1,2,3,4 (Example: 1=siren,2=siret,3=naf,4=rcs/rm)
3094
-	 *   @param 	Societe	$thirdparty     Object thirdparty
3095
-	 *   @return	string          		Url or empty string if no URL known
3096
-	 *   TODO better in a lib than into business class
3097
-	 */
3098
-	function id_prof_url($idprof,$thirdparty)
3099
-	{
3090
+    /**
3091
+     *   Return an url to check online a professional id or empty string
3092
+     *
3093
+     *   @param		int		$idprof         1,2,3,4 (Example: 1=siren,2=siret,3=naf,4=rcs/rm)
3094
+     *   @param 	Societe	$thirdparty     Object thirdparty
3095
+     *   @return	string          		Url or empty string if no URL known
3096
+     *   TODO better in a lib than into business class
3097
+     */
3098
+    function id_prof_url($idprof,$thirdparty)
3099
+    {
3100 3100
         // phpcs:enable
3101
-		global $conf,$langs,$hookmanager;
3101
+        global $conf,$langs,$hookmanager;
3102 3102
 
3103
-		$url='';
3104
-		$action = '';
3103
+        $url='';
3104
+        $action = '';
3105 3105
 
3106
-		$hookmanager->initHooks(array('idprofurl'));
3107
-		$parameters=array('idprof'=>$idprof, 'company'=>$thirdparty);
3108
-		$reshook=$hookmanager->executeHooks('getIdProfUrl',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
3109
-		if (empty($reshook)) {
3110
-			if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
3111
-				return '';
3112
-			}
3106
+        $hookmanager->initHooks(array('idprofurl'));
3107
+        $parameters=array('idprof'=>$idprof, 'company'=>$thirdparty);
3108
+        $reshook=$hookmanager->executeHooks('getIdProfUrl',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
3109
+        if (empty($reshook)) {
3110
+            if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
3111
+                return '';
3112
+            }
3113 3113
 
3114
-			// TODO Move links to validate professional ID into a dictionary table "country" + "link"
3114
+            // TODO Move links to validate professional ID into a dictionary table "country" + "link"
3115 3115
             $strippedIdProf1 = str_replace(' ', '', $thirdparty->idprof1);
3116
-			if ($idprof == 1 && $thirdparty->country_code == 'FR') {
3117
-				$url='http://www.societe.com/cgi-bin/search?champs='.$strippedIdProf1;    // See also http://avis-situation-sirene.insee.fr/
3118
-			}
3119
-			if ($idprof == 1 && ($thirdparty->country_code == 'GB' || $thirdparty->country_code == 'UK')) {
3120
-				$url='https://beta.companieshouse.gov.uk/company/'.$strippedIdProf1;
3121
-			}
3122
-			if ($idprof == 1 && $thirdparty->country_code == 'ES') {
3123
-				$url='http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$strippedIdProf1;
3124
-			}
3125
-			if ($idprof == 1 && $thirdparty->country_code == 'IN') {
3126
-				$url='http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$strippedIdProf1.';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
3127
-			}
3128
-			if ($idprof == 1 && $thirdparty->country_code == 'PT') {
3129
-				$url='http://www.nif.pt/'.$strippedIdProf1;
3130
-			}
3131
-
3132
-			if ($url) {
3133
-				return '<a target="_blank" href="'.$url.'">'.$langs->trans("Check").'</a>';
3134
-			}
3135
-		}
3136
-		else {
3137
-			return $hookmanager->resPrint;
3138
-		}
3139
-
3140
-		return '';
3141
-	}
3116
+            if ($idprof == 1 && $thirdparty->country_code == 'FR') {
3117
+                $url='http://www.societe.com/cgi-bin/search?champs='.$strippedIdProf1;    // See also http://avis-situation-sirene.insee.fr/
3118
+            }
3119
+            if ($idprof == 1 && ($thirdparty->country_code == 'GB' || $thirdparty->country_code == 'UK')) {
3120
+                $url='https://beta.companieshouse.gov.uk/company/'.$strippedIdProf1;
3121
+            }
3122
+            if ($idprof == 1 && $thirdparty->country_code == 'ES') {
3123
+                $url='http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$strippedIdProf1;
3124
+            }
3125
+            if ($idprof == 1 && $thirdparty->country_code == 'IN') {
3126
+                $url='http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$strippedIdProf1.';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
3127
+            }
3128
+            if ($idprof == 1 && $thirdparty->country_code == 'PT') {
3129
+                $url='http://www.nif.pt/'.$strippedIdProf1;
3130
+            }
3131
+
3132
+            if ($url) {
3133
+                return '<a target="_blank" href="'.$url.'">'.$langs->trans("Check").'</a>';
3134
+            }
3135
+        }
3136
+        else {
3137
+            return $hookmanager->resPrint;
3138
+        }
3139
+
3140
+        return '';
3141
+    }
3142 3142
 
3143 3143
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
3144
-	/**
3145
-	 *   Indique si la societe a des projets
3146
-	 *
3147
-	 *   @return     bool	   true si la societe a des projets, false sinon
3148
-	 */
3149
-	function has_projects()
3150
-	{
3144
+    /**
3145
+     *   Indique si la societe a des projets
3146
+     *
3147
+     *   @return     bool	   true si la societe a des projets, false sinon
3148
+     */
3149
+    function has_projects()
3150
+    {
3151 3151
         // phpcs:enable
3152
-		$sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = ' . $this->id;
3153
-		$resql = $this->db->query($sql);
3154
-		if ($resql)
3155
-		{
3156
-			$obj = $this->db->fetch_object($resql);
3157
-			$count = $obj->numproj;
3158
-		}
3159
-		else
3160
-		{
3161
-			$count = 0;
3162
-			print $this->db->error();
3163
-		}
3164
-		$this->db->free($resql);
3165
-		return ($count > 0);
3166
-	}
3167
-
3168
-
3169
-	/**
3170
-	 *  Load information for tab info
3171
-	 *
3172
-	 *  @param  int		$id     Id of thirdparty to load
3173
-	 *  @return	void
3174
-	 */
3175
-	function info($id)
3176
-	{
3177
-		$sql = "SELECT s.rowid, s.nom as name, s.datec as date_creation, tms as date_modification,";
3178
-		$sql.= " fk_user_creat, fk_user_modif";
3179
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
3180
-		$sql.= " WHERE s.rowid = ".$id;
3181
-
3182
-		$result=$this->db->query($sql);
3183
-		if ($result)
3184
-		{
3185
-			if ($this->db->num_rows($result))
3186
-			{
3187
-				$obj = $this->db->fetch_object($result);
3188
-
3189
-				$this->id = $obj->rowid;
3190
-
3191
-				if ($obj->fk_user_creat) {
3192
-					$cuser = new User($this->db);
3193
-					$cuser->fetch($obj->fk_user_creat);
3194
-					$this->user_creation     = $cuser;
3195
-				}
3196
-
3197
-				if ($obj->fk_user_modif) {
3198
-					$muser = new User($this->db);
3199
-					$muser->fetch($obj->fk_user_modif);
3200
-					$this->user_modification = $muser;
3201
-				}
3202
-
3203
-				$this->ref			     = $obj->name;
3204
-				$this->date_creation     = $this->db->jdate($obj->date_creation);
3205
-				$this->date_modification = $this->db->jdate($obj->date_modification);
3206
-			}
3207
-
3208
-			$this->db->free($result);
3209
-		}
3210
-		else
3211
-		{
3212
-			dol_print_error($this->db);
3213
-		}
3214
-	}
3215
-
3216
-	/**
3217
-	 *  Return if third party is a company (Business) or an end user (Consumer)
3218
-	 *
3219
-	 *  @return    boolean     true=is a company, false=a and user
3220
-	 */
3221
-	function isACompany()
3222
-	{
3223
-		global $conf;
3224
-
3225
-		// Define if third party is treated as company (or not) when nature is unknown
3226
-		$isacompany=empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES)?0:1; // 0 by default
3227
-		if (! empty($this->tva_intra)) $isacompany=1;
3228
-		else if (! empty($this->typent_code) && $this->typent_code != 'TE_UNKNOWN')
3229
-		{
3230
-			// TODO Add a field is_a_company into dictionary
3231
-			if (preg_match('/^TE_PRIVATE/', $this->typent_code)) $isacompany=0;
3232
-			else $isacompany=1;
3233
-		}
3234
-
3235
-		return $isacompany;
3236
-	}
3237
-
3238
-	/**
3239
-	 *  Return if a company is inside the EEC (European Economic Community)
3240
-	 *
3241
-	 *  @return     boolean		true = country inside EEC, false = country outside EEC
3242
-	 */
3243
-	function isInEEC()
3244
-	{
3245
-		require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
3246
-		return isInEEC($this);
3247
-	}
3152
+        $sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = ' . $this->id;
3153
+        $resql = $this->db->query($sql);
3154
+        if ($resql)
3155
+        {
3156
+            $obj = $this->db->fetch_object($resql);
3157
+            $count = $obj->numproj;
3158
+        }
3159
+        else
3160
+        {
3161
+            $count = 0;
3162
+            print $this->db->error();
3163
+        }
3164
+        $this->db->free($resql);
3165
+        return ($count > 0);
3166
+    }
3167
+
3168
+
3169
+    /**
3170
+     *  Load information for tab info
3171
+     *
3172
+     *  @param  int		$id     Id of thirdparty to load
3173
+     *  @return	void
3174
+     */
3175
+    function info($id)
3176
+    {
3177
+        $sql = "SELECT s.rowid, s.nom as name, s.datec as date_creation, tms as date_modification,";
3178
+        $sql.= " fk_user_creat, fk_user_modif";
3179
+        $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
3180
+        $sql.= " WHERE s.rowid = ".$id;
3181
+
3182
+        $result=$this->db->query($sql);
3183
+        if ($result)
3184
+        {
3185
+            if ($this->db->num_rows($result))
3186
+            {
3187
+                $obj = $this->db->fetch_object($result);
3188
+
3189
+                $this->id = $obj->rowid;
3190
+
3191
+                if ($obj->fk_user_creat) {
3192
+                    $cuser = new User($this->db);
3193
+                    $cuser->fetch($obj->fk_user_creat);
3194
+                    $this->user_creation     = $cuser;
3195
+                }
3196
+
3197
+                if ($obj->fk_user_modif) {
3198
+                    $muser = new User($this->db);
3199
+                    $muser->fetch($obj->fk_user_modif);
3200
+                    $this->user_modification = $muser;
3201
+                }
3202
+
3203
+                $this->ref			     = $obj->name;
3204
+                $this->date_creation     = $this->db->jdate($obj->date_creation);
3205
+                $this->date_modification = $this->db->jdate($obj->date_modification);
3206
+            }
3207
+
3208
+            $this->db->free($result);
3209
+        }
3210
+        else
3211
+        {
3212
+            dol_print_error($this->db);
3213
+        }
3214
+    }
3215
+
3216
+    /**
3217
+     *  Return if third party is a company (Business) or an end user (Consumer)
3218
+     *
3219
+     *  @return    boolean     true=is a company, false=a and user
3220
+     */
3221
+    function isACompany()
3222
+    {
3223
+        global $conf;
3224
+
3225
+        // Define if third party is treated as company (or not) when nature is unknown
3226
+        $isacompany=empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES)?0:1; // 0 by default
3227
+        if (! empty($this->tva_intra)) $isacompany=1;
3228
+        else if (! empty($this->typent_code) && $this->typent_code != 'TE_UNKNOWN')
3229
+        {
3230
+            // TODO Add a field is_a_company into dictionary
3231
+            if (preg_match('/^TE_PRIVATE/', $this->typent_code)) $isacompany=0;
3232
+            else $isacompany=1;
3233
+        }
3234
+
3235
+        return $isacompany;
3236
+    }
3237
+
3238
+    /**
3239
+     *  Return if a company is inside the EEC (European Economic Community)
3240
+     *
3241
+     *  @return     boolean		true = country inside EEC, false = country outside EEC
3242
+     */
3243
+    function isInEEC()
3244
+    {
3245
+        require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
3246
+        return isInEEC($this);
3247
+    }
3248 3248
 
3249 3249
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
3250
-	/**
3251
-	 *  Charge la liste des categories fournisseurs
3252
-	 *
3253
-	 *  @return    int      0 if success, <> 0 if error
3254
-	 */
3255
-	function LoadSupplierCateg()
3256
-	{
3250
+    /**
3251
+     *  Charge la liste des categories fournisseurs
3252
+     *
3253
+     *  @return    int      0 if success, <> 0 if error
3254
+     */
3255
+    function LoadSupplierCateg()
3256
+    {
3257 3257
         // phpcs:enable
3258
-		$this->SupplierCategories = array();
3259
-		$sql = "SELECT rowid, label";
3260
-		$sql.= " FROM ".MAIN_DB_PREFIX."categorie";
3261
-		$sql.= " WHERE type = ".Categorie::TYPE_SUPPLIER;
3262
-
3263
-		$resql=$this->db->query($sql);
3264
-		if ($resql)
3265
-		{
3266
-			while ($obj = $this->db->fetch_object($resql) )
3267
-			{
3268
-				$this->SupplierCategories[$obj->rowid] = $obj->label;
3269
-			}
3270
-			return 0;
3271
-		}
3272
-		else
3273
-		{
3274
-			return -1;
3275
-		}
3276
-	}
3258
+        $this->SupplierCategories = array();
3259
+        $sql = "SELECT rowid, label";
3260
+        $sql.= " FROM ".MAIN_DB_PREFIX."categorie";
3261
+        $sql.= " WHERE type = ".Categorie::TYPE_SUPPLIER;
3262
+
3263
+        $resql=$this->db->query($sql);
3264
+        if ($resql)
3265
+        {
3266
+            while ($obj = $this->db->fetch_object($resql) )
3267
+            {
3268
+                $this->SupplierCategories[$obj->rowid] = $obj->label;
3269
+            }
3270
+            return 0;
3271
+        }
3272
+        else
3273
+        {
3274
+            return -1;
3275
+        }
3276
+    }
3277 3277
 
3278 3278
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
3279
-	/**
3280
-	 *  Insert link supplier - category
3281
-	 *
3282
-	 *	@param	int		$categorie_id		Id of category
3283
-	 *  @return int      					0 if success, <> 0 if error
3284
-	 */
3285
-	function AddFournisseurInCategory($categorie_id)
3286
-	{
3279
+    /**
3280
+     *  Insert link supplier - category
3281
+     *
3282
+     *	@param	int		$categorie_id		Id of category
3283
+     *  @return int      					0 if success, <> 0 if error
3284
+     */
3285
+    function AddFournisseurInCategory($categorie_id)
3286
+    {
3287 3287
         // phpcs:enable
3288
-		if ($categorie_id > 0 && $this->id > 0)
3289
-		{
3290
-			$sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_fournisseur (fk_categorie, fk_soc) ";
3291
-			$sql.= " VALUES (".$categorie_id.", ".$this->id.")";
3288
+        if ($categorie_id > 0 && $this->id > 0)
3289
+        {
3290
+            $sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_fournisseur (fk_categorie, fk_soc) ";
3291
+            $sql.= " VALUES (".$categorie_id.", ".$this->id.")";
3292 3292
 
3293
-			if ($resql=$this->db->query($sql)) return 0;
3294
-		}
3295
-		else
3296
-		{
3297
-			return 0;
3298
-		}
3299
-		return -1;
3300
-	}
3293
+            if ($resql=$this->db->query($sql)) return 0;
3294
+        }
3295
+        else
3296
+        {
3297
+            return 0;
3298
+        }
3299
+        return -1;
3300
+    }
3301 3301
 
3302 3302
 
3303 3303
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
3304
-	/**
3305
-	 *  Create a third party into database from a member object
3306
-	 *
3307
-	 *  @param	Adherent	$member			Object member
3308
-	 * 	@param	string		$socname		Name of third party to force
3309
-	 *	@param	string		$socalias		Alias name of third party to force
3310
-	 *  @param	string		$customercode	Customer code
3311
-	 *  @return int							<0 if KO, id of created account if OK
3312
-	 */
3313
-	function create_from_member(Adherent $member, $socname='', $socalias='', $customercode='')
3314
-	{
3304
+    /**
3305
+     *  Create a third party into database from a member object
3306
+     *
3307
+     *  @param	Adherent	$member			Object member
3308
+     * 	@param	string		$socname		Name of third party to force
3309
+     *	@param	string		$socalias		Alias name of third party to force
3310
+     *  @param	string		$customercode	Customer code
3311
+     *  @return int							<0 if KO, id of created account if OK
3312
+     */
3313
+    function create_from_member(Adherent $member, $socname='', $socalias='', $customercode='')
3314
+    {
3315 3315
         // phpcs:enable
3316
-		global $user,$langs;
3317
-
3318
-		dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG);
3319
-
3320
-		$name = $socname?$socname:$member->societe;
3321
-		if (empty($name)) $name=$member->getFullName($langs);
3322
-
3323
-		$alias = $socalias?$socalias:'';
3324
-
3325
-		// Positionne parametres
3326
-		$this->nom=$name;				// TODO deprecated
3327
-		$this->name=$name;
3328
-		$this->name_alias=$alias;
3329
-		$this->address=$member->address;
3330
-		$this->zip=$member->zip;
3331
-		$this->town=$member->town;
3332
-		$this->country_code=$member->country_code;
3333
-		$this->country_id=$member->country_id;
3334
-		$this->phone=$member->phone;       // Prof phone
3335
-		$this->email=$member->email;
3336
-		$this->skype=$member->skype;
3337
-		$this->twitter=$member->twitter;
3338
-		$this->facebook=$member->facebook;
3339
-
3340
-		$this->client = 1;				// A member is a customer by default
3341
-		$this->code_client = ($customercode?$customercode:-1);
3342
-		$this->code_fournisseur = -1;
3343
-
3344
-		$this->db->begin();
3345
-
3346
-		// Cree et positionne $this->id
3347
-		$result=$this->create($user);
3348
-		if ($result >= 0)
3349
-		{
3350
-			$sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
3351
-			$sql.= " SET fk_soc=".$this->id;
3352
-			$sql.= " WHERE rowid=".$member->id;
3353
-
3354
-			$resql=$this->db->query($sql);
3355
-			if ($resql)
3356
-			{
3357
-				$this->db->commit();
3358
-				return $this->id;
3359
-			}
3360
-			else
3361
-			{
3362
-				$this->error=$this->db->error();
3363
-
3364
-				$this->db->rollback();
3365
-				return -1;
3366
-			}
3367
-		}
3368
-		else
3369
-		{
3370
-			// $this->error deja positionne
3371
-			dol_syslog(get_class($this)."::create_from_member - 2 - ".$this->error." - ".join(',',$this->errors), LOG_ERR);
3372
-
3373
-			$this->db->rollback();
3374
-			return $result;
3375
-		}
3376
-	}
3377
-
3378
-	/**
3379
-	 * 	Set properties with value into $conf
3380
-	 *
3381
-	 * 	@param	Conf	$conf		Conf object (possibility to use another entity)
3382
-	 * 	@return	void
3383
-	 */
3384
-	function setMysoc(Conf $conf)
3385
-	{
3386
-		global $langs;
3387
-
3388
-		$this->id=0;
3389
-		$this->name=empty($conf->global->MAIN_INFO_SOCIETE_NOM)?'':$conf->global->MAIN_INFO_SOCIETE_NOM;
3390
-		$this->address=empty($conf->global->MAIN_INFO_SOCIETE_ADDRESS)?'':$conf->global->MAIN_INFO_SOCIETE_ADDRESS;
3391
-		$this->zip=empty($conf->global->MAIN_INFO_SOCIETE_ZIP)?'':$conf->global->MAIN_INFO_SOCIETE_ZIP;
3392
-		$this->town=empty($conf->global->MAIN_INFO_SOCIETE_TOWN)?'':$conf->global->MAIN_INFO_SOCIETE_TOWN;
3393
-		$this->state_id=empty($conf->global->MAIN_INFO_SOCIETE_STATE)?'':$conf->global->MAIN_INFO_SOCIETE_STATE;
3394
-		$this->region_code=empty($conf->global->MAIN_INFO_SOCIETE_REGION)?'':$conf->global->MAIN_INFO_SOCIETE_REGION;
3395
-		$this->object=empty($conf->global->MAIN_INFO_SOCIETE_OBJECT)?'':$conf->global->MAIN_INFO_SOCIETE_OBJECT;
3396
-
3397
-		$this->note_private=empty($conf->global->MAIN_INFO_SOCIETE_NOTE)?'':$conf->global->MAIN_INFO_SOCIETE_NOTE;
3398
-
3399
-		$this->nom=$this->name; 									// deprecated
3400
-
3401
-		// We define country_id, country_code and country
3402
-		$country_id=$country_code=$country_label='';
3403
-		if (! empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY))
3404
-		{
3405
-			$tmp=explode(':',$conf->global->MAIN_INFO_SOCIETE_COUNTRY);
3406
-			$country_id=$tmp[0];
3407
-			if (! empty($tmp[1]))   // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label"
3408
-			{
3409
-				$country_code=$tmp[1];
3410
-				$country_label=$tmp[2];
3411
-			}
3412
-			else                    // For backward compatibility
3413
-			{
3414
-				dol_syslog("Your country setup use an old syntax. Reedit it using setup area.", LOG_ERR);
3415
-				include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
3416
-				$country_code=getCountry($country_id,2,$this->db);  // This need a SQL request, but it's the old feature that should not be used anymore
3417
-				$country_label=getCountry($country_id,0,$this->db);  // This need a SQL request, but it's the old feature that should not be used anymore
3418
-			}
3419
-		}
3420
-		$this->country_id=$country_id;
3421
-		$this->country_code=$country_code;
3422
-		$this->country=$country_label;
3423
-		if (is_object($langs)) $this->country=($langs->trans('Country'.$country_code)!='Country'.$country_code)?$langs->trans('Country'.$country_code):$country_label;
3424
-
3425
-		$this->phone=empty($conf->global->MAIN_INFO_SOCIETE_TEL)?'':$conf->global->MAIN_INFO_SOCIETE_TEL;
3426
-		$this->fax=empty($conf->global->MAIN_INFO_SOCIETE_FAX)?'':$conf->global->MAIN_INFO_SOCIETE_FAX;
3427
-		$this->url=empty($conf->global->MAIN_INFO_SOCIETE_WEB)?'':$conf->global->MAIN_INFO_SOCIETE_WEB;
3428
-		// Id prof generiques
3429
-		$this->idprof1=empty($conf->global->MAIN_INFO_SIREN)?'':$conf->global->MAIN_INFO_SIREN;
3430
-		$this->idprof2=empty($conf->global->MAIN_INFO_SIRET)?'':$conf->global->MAIN_INFO_SIRET;
3431
-		$this->idprof3=empty($conf->global->MAIN_INFO_APE)?'':$conf->global->MAIN_INFO_APE;
3432
-		$this->idprof4=empty($conf->global->MAIN_INFO_RCS)?'':$conf->global->MAIN_INFO_RCS;
3433
-		$this->idprof5=empty($conf->global->MAIN_INFO_PROFID5)?'':$conf->global->MAIN_INFO_PROFID5;
3434
-		$this->idprof6=empty($conf->global->MAIN_INFO_PROFID6)?'':$conf->global->MAIN_INFO_PROFID6;
3435
-		$this->tva_intra=empty($conf->global->MAIN_INFO_TVAINTRA)?'':$conf->global->MAIN_INFO_TVAINTRA;	// VAT number, not necessarly INTRA.
3436
-		$this->managers=empty($conf->global->MAIN_INFO_SOCIETE_MANAGERS)?'':$conf->global->MAIN_INFO_SOCIETE_MANAGERS;
3437
-		$this->capital=empty($conf->global->MAIN_INFO_CAPITAL)?'':$conf->global->MAIN_INFO_CAPITAL;
3438
-		$this->forme_juridique_code=empty($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE)?'':$conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE;
3439
-		$this->email=empty($conf->global->MAIN_INFO_SOCIETE_MAIL)?'':$conf->global->MAIN_INFO_SOCIETE_MAIL;
3440
-		$this->logo=empty($conf->global->MAIN_INFO_SOCIETE_LOGO)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO;
3441
-		$this->logo_small=empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL;
3442
-		$this->logo_mini=empty($conf->global->MAIN_INFO_SOCIETE_LOGO_MINI)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
3443
-
3444
-		// Define if company use vat or not
3445
-		$this->tva_assuj=$conf->global->FACTURE_TVAOPTION;
3446
-
3447
-		// Define if company use local taxes
3448
-		$this->localtax1_assuj=((isset($conf->global->FACTURE_LOCAL_TAX1_OPTION) && ($conf->global->FACTURE_LOCAL_TAX1_OPTION=='1' || $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on'))?1:0);
3449
-		$this->localtax2_assuj=((isset($conf->global->FACTURE_LOCAL_TAX2_OPTION) && ($conf->global->FACTURE_LOCAL_TAX2_OPTION=='1' || $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on'))?1:0);
3450
-	}
3451
-
3452
-	/**
3453
-	 *  Initialise an instance with random values.
3454
-	 *  Used to build previews or test instances.
3455
-	 *	id must be 0 if object instance is a specimen.
3456
-	 *
3457
-	 *  @return	void
3458
-	 */
3459
-	function initAsSpecimen()
3460
-	{
3461
-		$now=dol_now();
3462
-
3463
-		// Initialize parameters
3464
-		$this->id=0;
3465
-		$this->name = 'THIRDPARTY SPECIMEN '.dol_print_date($now,'dayhourlog');
3466
-		$this->nom = $this->name;   // For backward compatibility
3467
-		$this->ref_ext = 'Ref ext';
3468
-		$this->specimen=1;
3469
-		$this->address='21 jump street';
3470
-		$this->zip='99999';
3471
-		$this->town='MyTown';
3472
-		$this->state_id=1;
3473
-		$this->state_code='AA';
3474
-		$this->state='MyState';
3475
-		$this->country_id=1;
3476
-		$this->country_code='FR';
3477
-		$this->email='[email protected]';
3478
-		$this->skype='tom.hanson';
3479
-		$this->twitter='tomhanson';
3480
-		$this->facebook='tomhanson';
3481
-		$this->url='http://www.specimen.com';
3482
-
3483
-		$this->phone='0909090901';
3484
-		$this->fax='0909090909';
3485
-
3486
-		$this->code_client='CC-'.dol_print_date($now,'dayhourlog');
3487
-		$this->code_fournisseur='SC-'.dol_print_date($now,'dayhourlog');
3488
-		$this->capital=10000;
3489
-		$this->client=1;
3490
-		$this->prospect=1;
3491
-		$this->fournisseur=1;
3492
-		$this->tva_assuj=1;
3493
-		$this->tva_intra='EU1234567';
3494
-		$this->note_public='This is a comment (public)';
3495
-		$this->note_private='This is a comment (private)';
3496
-
3497
-		$this->idprof1='idprof1';
3498
-		$this->idprof2='idprof2';
3499
-		$this->idprof3='idprof3';
3500
-		$this->idprof4='idprof4';
3501
-		$this->idprof5='idprof5';
3502
-		$this->idprof6='idprof6';
3503
-	}
3504
-
3505
-	/**
3506
-	 *  Check if we must use localtax feature or not according to country (country of $mysoc in most cases).
3507
-	 *
3508
-	 *	@param		int		$localTaxNum	To get info for only localtax1 or localtax2
3509
-	 *  @return		boolean					true or false
3510
-	 */
3511
-	function useLocalTax($localTaxNum=0)
3512
-	{
3513
-		$sql  = "SELECT t.localtax1, t.localtax2";
3514
-		$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
3515
-		$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'";
3516
-		$sql .= " AND t.active = 1";
3517
-		if (empty($localTaxNum))   $sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
3518
-		elseif ($localTaxNum == 1) $sql .= " AND t.localtax1_type <> '0'";
3519
-		elseif ($localTaxNum == 2) $sql .= " AND t.localtax2_type <> '0'";
3520
-
3521
-		dol_syslog("useLocalTax", LOG_DEBUG);
3522
-		$resql=$this->db->query($sql);
3523
-		if ($resql)
3524
-		{
3525
-   			return ($this->db->num_rows($resql) > 0);
3526
-		}
3527
-		else return false;
3528
-	}
3529
-
3530
-	/**
3531
-	 *  Check if we must use NPR Vat (french stupid rule) or not according to country (country of $mysoc in most cases).
3532
-	 *
3533
-	 *  @return		boolean					true or false
3534
-	 */
3535
-	function useNPR()
3536
-	{
3537
-		$sql  = "SELECT t.rowid";
3538
-		$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
3539
-		$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'";
3540
-		$sql .= " AND t.active = 1 AND t.recuperableonly = 1";
3541
-
3542
-		dol_syslog("useNPR", LOG_DEBUG);
3543
-		$resql=$this->db->query($sql);
3544
-		if ($resql)
3545
-		{
3546
-			return ($this->db->num_rows($resql) > 0);
3547
-		}
3548
-		else return false;
3549
-	}
3550
-
3551
-	/**
3552
-	 *  Check if we must use revenue stamps feature or not according to country (country of $mysocin most cases).
3553
-	 *
3554
-	 *  @return		boolean			true or false
3555
-	 */
3556
-	function useRevenueStamp()
3557
-	{
3558
-		$sql  = "SELECT COUNT(*) as nb";
3559
-		$sql .= " FROM ".MAIN_DB_PREFIX."c_revenuestamp as r, ".MAIN_DB_PREFIX."c_country as c";
3560
-		$sql .= " WHERE r.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'";
3561
-		$sql .= " AND r.active = 1";
3562
-
3563
-		dol_syslog("useRevenueStamp", LOG_DEBUG);
3564
-		$resql=$this->db->query($sql);
3565
-		if ($resql)
3566
-		{
3567
-			$obj=$this->db->fetch_object($resql);
3568
-   			return (($obj->nb > 0)?true:false);
3569
-		}
3570
-		else
3571
-		{
3572
-			$this->error=$this->db->lasterror();
3573
-			return false;
3574
-		}
3575
-	}
3576
-
3577
-	/**
3578
-	 *	Return prostect level
3579
-	 *
3580
-	 *  @return     string        Libelle
3581
-	 */
3582
-	function getLibProspLevel()
3583
-	{
3584
-		return $this->LibProspLevel($this->fk_prospectlevel);
3585
-	}
3316
+        global $user,$langs;
3317
+
3318
+        dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG);
3319
+
3320
+        $name = $socname?$socname:$member->societe;
3321
+        if (empty($name)) $name=$member->getFullName($langs);
3322
+
3323
+        $alias = $socalias?$socalias:'';
3324
+
3325
+        // Positionne parametres
3326
+        $this->nom=$name;				// TODO deprecated
3327
+        $this->name=$name;
3328
+        $this->name_alias=$alias;
3329
+        $this->address=$member->address;
3330
+        $this->zip=$member->zip;
3331
+        $this->town=$member->town;
3332
+        $this->country_code=$member->country_code;
3333
+        $this->country_id=$member->country_id;
3334
+        $this->phone=$member->phone;       // Prof phone
3335
+        $this->email=$member->email;
3336
+        $this->skype=$member->skype;
3337
+        $this->twitter=$member->twitter;
3338
+        $this->facebook=$member->facebook;
3339
+
3340
+        $this->client = 1;				// A member is a customer by default
3341
+        $this->code_client = ($customercode?$customercode:-1);
3342
+        $this->code_fournisseur = -1;
3343
+
3344
+        $this->db->begin();
3345
+
3346
+        // Cree et positionne $this->id
3347
+        $result=$this->create($user);
3348
+        if ($result >= 0)
3349
+        {
3350
+            $sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
3351
+            $sql.= " SET fk_soc=".$this->id;
3352
+            $sql.= " WHERE rowid=".$member->id;
3353
+
3354
+            $resql=$this->db->query($sql);
3355
+            if ($resql)
3356
+            {
3357
+                $this->db->commit();
3358
+                return $this->id;
3359
+            }
3360
+            else
3361
+            {
3362
+                $this->error=$this->db->error();
3363
+
3364
+                $this->db->rollback();
3365
+                return -1;
3366
+            }
3367
+        }
3368
+        else
3369
+        {
3370
+            // $this->error deja positionne
3371
+            dol_syslog(get_class($this)."::create_from_member - 2 - ".$this->error." - ".join(',',$this->errors), LOG_ERR);
3372
+
3373
+            $this->db->rollback();
3374
+            return $result;
3375
+        }
3376
+    }
3377
+
3378
+    /**
3379
+     * 	Set properties with value into $conf
3380
+     *
3381
+     * 	@param	Conf	$conf		Conf object (possibility to use another entity)
3382
+     * 	@return	void
3383
+     */
3384
+    function setMysoc(Conf $conf)
3385
+    {
3386
+        global $langs;
3387
+
3388
+        $this->id=0;
3389
+        $this->name=empty($conf->global->MAIN_INFO_SOCIETE_NOM)?'':$conf->global->MAIN_INFO_SOCIETE_NOM;
3390
+        $this->address=empty($conf->global->MAIN_INFO_SOCIETE_ADDRESS)?'':$conf->global->MAIN_INFO_SOCIETE_ADDRESS;
3391
+        $this->zip=empty($conf->global->MAIN_INFO_SOCIETE_ZIP)?'':$conf->global->MAIN_INFO_SOCIETE_ZIP;
3392
+        $this->town=empty($conf->global->MAIN_INFO_SOCIETE_TOWN)?'':$conf->global->MAIN_INFO_SOCIETE_TOWN;
3393
+        $this->state_id=empty($conf->global->MAIN_INFO_SOCIETE_STATE)?'':$conf->global->MAIN_INFO_SOCIETE_STATE;
3394
+        $this->region_code=empty($conf->global->MAIN_INFO_SOCIETE_REGION)?'':$conf->global->MAIN_INFO_SOCIETE_REGION;
3395
+        $this->object=empty($conf->global->MAIN_INFO_SOCIETE_OBJECT)?'':$conf->global->MAIN_INFO_SOCIETE_OBJECT;
3396
+
3397
+        $this->note_private=empty($conf->global->MAIN_INFO_SOCIETE_NOTE)?'':$conf->global->MAIN_INFO_SOCIETE_NOTE;
3398
+
3399
+        $this->nom=$this->name; 									// deprecated
3400
+
3401
+        // We define country_id, country_code and country
3402
+        $country_id=$country_code=$country_label='';
3403
+        if (! empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY))
3404
+        {
3405
+            $tmp=explode(':',$conf->global->MAIN_INFO_SOCIETE_COUNTRY);
3406
+            $country_id=$tmp[0];
3407
+            if (! empty($tmp[1]))   // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label"
3408
+            {
3409
+                $country_code=$tmp[1];
3410
+                $country_label=$tmp[2];
3411
+            }
3412
+            else                    // For backward compatibility
3413
+            {
3414
+                dol_syslog("Your country setup use an old syntax. Reedit it using setup area.", LOG_ERR);
3415
+                include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
3416
+                $country_code=getCountry($country_id,2,$this->db);  // This need a SQL request, but it's the old feature that should not be used anymore
3417
+                $country_label=getCountry($country_id,0,$this->db);  // This need a SQL request, but it's the old feature that should not be used anymore
3418
+            }
3419
+        }
3420
+        $this->country_id=$country_id;
3421
+        $this->country_code=$country_code;
3422
+        $this->country=$country_label;
3423
+        if (is_object($langs)) $this->country=($langs->trans('Country'.$country_code)!='Country'.$country_code)?$langs->trans('Country'.$country_code):$country_label;
3424
+
3425
+        $this->phone=empty($conf->global->MAIN_INFO_SOCIETE_TEL)?'':$conf->global->MAIN_INFO_SOCIETE_TEL;
3426
+        $this->fax=empty($conf->global->MAIN_INFO_SOCIETE_FAX)?'':$conf->global->MAIN_INFO_SOCIETE_FAX;
3427
+        $this->url=empty($conf->global->MAIN_INFO_SOCIETE_WEB)?'':$conf->global->MAIN_INFO_SOCIETE_WEB;
3428
+        // Id prof generiques
3429
+        $this->idprof1=empty($conf->global->MAIN_INFO_SIREN)?'':$conf->global->MAIN_INFO_SIREN;
3430
+        $this->idprof2=empty($conf->global->MAIN_INFO_SIRET)?'':$conf->global->MAIN_INFO_SIRET;
3431
+        $this->idprof3=empty($conf->global->MAIN_INFO_APE)?'':$conf->global->MAIN_INFO_APE;
3432
+        $this->idprof4=empty($conf->global->MAIN_INFO_RCS)?'':$conf->global->MAIN_INFO_RCS;
3433
+        $this->idprof5=empty($conf->global->MAIN_INFO_PROFID5)?'':$conf->global->MAIN_INFO_PROFID5;
3434
+        $this->idprof6=empty($conf->global->MAIN_INFO_PROFID6)?'':$conf->global->MAIN_INFO_PROFID6;
3435
+        $this->tva_intra=empty($conf->global->MAIN_INFO_TVAINTRA)?'':$conf->global->MAIN_INFO_TVAINTRA;	// VAT number, not necessarly INTRA.
3436
+        $this->managers=empty($conf->global->MAIN_INFO_SOCIETE_MANAGERS)?'':$conf->global->MAIN_INFO_SOCIETE_MANAGERS;
3437
+        $this->capital=empty($conf->global->MAIN_INFO_CAPITAL)?'':$conf->global->MAIN_INFO_CAPITAL;
3438
+        $this->forme_juridique_code=empty($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE)?'':$conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE;
3439
+        $this->email=empty($conf->global->MAIN_INFO_SOCIETE_MAIL)?'':$conf->global->MAIN_INFO_SOCIETE_MAIL;
3440
+        $this->logo=empty($conf->global->MAIN_INFO_SOCIETE_LOGO)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO;
3441
+        $this->logo_small=empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL;
3442
+        $this->logo_mini=empty($conf->global->MAIN_INFO_SOCIETE_LOGO_MINI)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
3443
+
3444
+        // Define if company use vat or not
3445
+        $this->tva_assuj=$conf->global->FACTURE_TVAOPTION;
3446
+
3447
+        // Define if company use local taxes
3448
+        $this->localtax1_assuj=((isset($conf->global->FACTURE_LOCAL_TAX1_OPTION) && ($conf->global->FACTURE_LOCAL_TAX1_OPTION=='1' || $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on'))?1:0);
3449
+        $this->localtax2_assuj=((isset($conf->global->FACTURE_LOCAL_TAX2_OPTION) && ($conf->global->FACTURE_LOCAL_TAX2_OPTION=='1' || $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on'))?1:0);
3450
+    }
3451
+
3452
+    /**
3453
+     *  Initialise an instance with random values.
3454
+     *  Used to build previews or test instances.
3455
+     *	id must be 0 if object instance is a specimen.
3456
+     *
3457
+     *  @return	void
3458
+     */
3459
+    function initAsSpecimen()
3460
+    {
3461
+        $now=dol_now();
3462
+
3463
+        // Initialize parameters
3464
+        $this->id=0;
3465
+        $this->name = 'THIRDPARTY SPECIMEN '.dol_print_date($now,'dayhourlog');
3466
+        $this->nom = $this->name;   // For backward compatibility
3467
+        $this->ref_ext = 'Ref ext';
3468
+        $this->specimen=1;
3469
+        $this->address='21 jump street';
3470
+        $this->zip='99999';
3471
+        $this->town='MyTown';
3472
+        $this->state_id=1;
3473
+        $this->state_code='AA';
3474
+        $this->state='MyState';
3475
+        $this->country_id=1;
3476
+        $this->country_code='FR';
3477
+        $this->email='[email protected]';
3478
+        $this->skype='tom.hanson';
3479
+        $this->twitter='tomhanson';
3480
+        $this->facebook='tomhanson';
3481
+        $this->url='http://www.specimen.com';
3482
+
3483
+        $this->phone='0909090901';
3484
+        $this->fax='0909090909';
3485
+
3486
+        $this->code_client='CC-'.dol_print_date($now,'dayhourlog');
3487
+        $this->code_fournisseur='SC-'.dol_print_date($now,'dayhourlog');
3488
+        $this->capital=10000;
3489
+        $this->client=1;
3490
+        $this->prospect=1;
3491
+        $this->fournisseur=1;
3492
+        $this->tva_assuj=1;
3493
+        $this->tva_intra='EU1234567';
3494
+        $this->note_public='This is a comment (public)';
3495
+        $this->note_private='This is a comment (private)';
3496
+
3497
+        $this->idprof1='idprof1';
3498
+        $this->idprof2='idprof2';
3499
+        $this->idprof3='idprof3';
3500
+        $this->idprof4='idprof4';
3501
+        $this->idprof5='idprof5';
3502
+        $this->idprof6='idprof6';
3503
+    }
3504
+
3505
+    /**
3506
+     *  Check if we must use localtax feature or not according to country (country of $mysoc in most cases).
3507
+     *
3508
+     *	@param		int		$localTaxNum	To get info for only localtax1 or localtax2
3509
+     *  @return		boolean					true or false
3510
+     */
3511
+    function useLocalTax($localTaxNum=0)
3512
+    {
3513
+        $sql  = "SELECT t.localtax1, t.localtax2";
3514
+        $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
3515
+        $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'";
3516
+        $sql .= " AND t.active = 1";
3517
+        if (empty($localTaxNum))   $sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
3518
+        elseif ($localTaxNum == 1) $sql .= " AND t.localtax1_type <> '0'";
3519
+        elseif ($localTaxNum == 2) $sql .= " AND t.localtax2_type <> '0'";
3520
+
3521
+        dol_syslog("useLocalTax", LOG_DEBUG);
3522
+        $resql=$this->db->query($sql);
3523
+        if ($resql)
3524
+        {
3525
+                return ($this->db->num_rows($resql) > 0);
3526
+        }
3527
+        else return false;
3528
+    }
3529
+
3530
+    /**
3531
+     *  Check if we must use NPR Vat (french stupid rule) or not according to country (country of $mysoc in most cases).
3532
+     *
3533
+     *  @return		boolean					true or false
3534
+     */
3535
+    function useNPR()
3536
+    {
3537
+        $sql  = "SELECT t.rowid";
3538
+        $sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
3539
+        $sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'";
3540
+        $sql .= " AND t.active = 1 AND t.recuperableonly = 1";
3541
+
3542
+        dol_syslog("useNPR", LOG_DEBUG);
3543
+        $resql=$this->db->query($sql);
3544
+        if ($resql)
3545
+        {
3546
+            return ($this->db->num_rows($resql) > 0);
3547
+        }
3548
+        else return false;
3549
+    }
3550
+
3551
+    /**
3552
+     *  Check if we must use revenue stamps feature or not according to country (country of $mysocin most cases).
3553
+     *
3554
+     *  @return		boolean			true or false
3555
+     */
3556
+    function useRevenueStamp()
3557
+    {
3558
+        $sql  = "SELECT COUNT(*) as nb";
3559
+        $sql .= " FROM ".MAIN_DB_PREFIX."c_revenuestamp as r, ".MAIN_DB_PREFIX."c_country as c";
3560
+        $sql .= " WHERE r.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'";
3561
+        $sql .= " AND r.active = 1";
3562
+
3563
+        dol_syslog("useRevenueStamp", LOG_DEBUG);
3564
+        $resql=$this->db->query($sql);
3565
+        if ($resql)
3566
+        {
3567
+            $obj=$this->db->fetch_object($resql);
3568
+                return (($obj->nb > 0)?true:false);
3569
+        }
3570
+        else
3571
+        {
3572
+            $this->error=$this->db->lasterror();
3573
+            return false;
3574
+        }
3575
+    }
3576
+
3577
+    /**
3578
+     *	Return prostect level
3579
+     *
3580
+     *  @return     string        Libelle
3581
+     */
3582
+    function getLibProspLevel()
3583
+    {
3584
+        return $this->LibProspLevel($this->fk_prospectlevel);
3585
+    }
3586 3586
 
3587 3587
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
3588
-	/**
3589
-	 *  Return label of prospect level
3590
-	 *
3591
-	 *  @param	int		$fk_prospectlevel   	Prospect level
3592
-	 *  @return string        					label of level
3593
-	 */
3594
-	function LibProspLevel($fk_prospectlevel)
3595
-	{
3588
+    /**
3589
+     *  Return label of prospect level
3590
+     *
3591
+     *  @param	int		$fk_prospectlevel   	Prospect level
3592
+     *  @return string        					label of level
3593
+     */
3594
+    function LibProspLevel($fk_prospectlevel)
3595
+    {
3596 3596
         // phpcs:enable
3597
-		global $langs;
3597
+        global $langs;
3598 3598
 
3599
-		$lib=$langs->trans("ProspectLevel".$fk_prospectlevel);
3600
-		// If lib not found in language file, we get label from cache/databse
3601
-		if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel))
3602
-		{
3603
-			$lib=$langs->getLabelFromKey($this->db,$fk_prospectlevel,'c_prospectlevel','code','label');
3604
-		}
3605
-		return $lib;
3606
-	}
3599
+        $lib=$langs->trans("ProspectLevel".$fk_prospectlevel);
3600
+        // If lib not found in language file, we get label from cache/databse
3601
+        if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel))
3602
+        {
3603
+            $lib=$langs->getLabelFromKey($this->db,$fk_prospectlevel,'c_prospectlevel','code','label');
3604
+        }
3605
+        return $lib;
3606
+    }
3607 3607
 
3608 3608
 
3609 3609
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
3610
-	/**
3611
-	 *  Set prospect level
3612
-	 *
3613
-	 *  @param  User	$user		Utilisateur qui definie la remise
3614
-	 *	@return	int					<0 if KO, >0 if OK
3615
-	 * @deprecated Use update function instead
3616
-	 */
3617
-	function set_prospect_level(User $user)
3618
-	{
3610
+    /**
3611
+     *  Set prospect level
3612
+     *
3613
+     *  @param  User	$user		Utilisateur qui definie la remise
3614
+     *	@return	int					<0 if KO, >0 if OK
3615
+     * @deprecated Use update function instead
3616
+     */
3617
+    function set_prospect_level(User $user)
3618
+    {
3619 3619
         // phpcs:enable
3620
-		return $this->update($this->id, $user);
3621
-	}
3622
-
3623
-	/**
3624
-	 *  Return status of prospect
3625
-	 *
3626
-	 *  @param	int		$mode       0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long
3627
-	 *  @param	string	$label		Label to use for status for added status
3628
-	 *  @return string        		Libelle
3629
-	 */
3630
-	function getLibProspCommStatut($mode=0, $label='')
3631
-	{
3632
-		return $this->LibProspCommStatut($this->stcomm_id, $mode, $label);
3633
-	}
3620
+        return $this->update($this->id, $user);
3621
+    }
3622
+
3623
+    /**
3624
+     *  Return status of prospect
3625
+     *
3626
+     *  @param	int		$mode       0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long
3627
+     *  @param	string	$label		Label to use for status for added status
3628
+     *  @return string        		Libelle
3629
+     */
3630
+    function getLibProspCommStatut($mode=0, $label='')
3631
+    {
3632
+        return $this->LibProspCommStatut($this->stcomm_id, $mode, $label);
3633
+    }
3634 3634
 
3635 3635
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
3636
-	/**
3637
-	 *  Return label of a given status
3638
-	 *
3639
-	 *  @param	int|string	$statut        	Id or code for prospection status
3640
-	 *  @param  int			$mode          	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
3641
-	 *  @param	string		$label			Label to use for status for added status
3642
-	 *  @return string       	 			Libelle du statut
3643
-	 */
3644
-	function LibProspCommStatut($statut, $mode=0, $label='')
3645
-	{
3636
+    /**
3637
+     *  Return label of a given status
3638
+     *
3639
+     *  @param	int|string	$statut        	Id or code for prospection status
3640
+     *  @param  int			$mode          	0=long label, 1=short label, 2=Picto + short label, 3=Picto, 4=Picto + long label, 5=Short label + Picto
3641
+     *  @param	string		$label			Label to use for status for added status
3642
+     *  @return string       	 			Libelle du statut
3643
+     */
3644
+    function LibProspCommStatut($statut, $mode=0, $label='')
3645
+    {
3646 3646
         // phpcs:enable
3647
-		global $langs;
3648
-		$langs->load('customers');
3649
-
3650
-		if ($mode == 2)
3651
-		{
3652
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3653
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3654
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3655
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3656
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3657
-			else
3658
-			{
3659
-				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
3660
-			}
3661
-		}
3662
-		if ($mode == 3)
3663
-		{
3664
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1);
3665
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0);
3666
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1);
3667
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2);
3668
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3);
3669
-			else
3670
-			{
3671
-				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0);
3672
-			}
3673
-		}
3674
-		if ($mode == 4)
3675
-		{
3676
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3677
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3678
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3679
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3680
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3681
-			else
3682
-			{
3683
-				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
3684
-			}
3685
-		}
3686
-
3687
-		return "Error, mode/status not found";
3688
-	}
3647
+        global $langs;
3648
+        $langs->load('customers');
3649
+
3650
+        if ($mode == 2)
3651
+        {
3652
+            if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3653
+            elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3654
+            elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3655
+            elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3656
+            elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3657
+            else
3658
+            {
3659
+                return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
3660
+            }
3661
+        }
3662
+        if ($mode == 3)
3663
+        {
3664
+            if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1);
3665
+            elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0);
3666
+            elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1);
3667
+            elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2);
3668
+            elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3);
3669
+            else
3670
+            {
3671
+                return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0);
3672
+            }
3673
+        }
3674
+        if ($mode == 4)
3675
+        {
3676
+            if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3677
+            elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3678
+            elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3679
+            elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3680
+            elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3681
+            else
3682
+            {
3683
+                return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
3684
+            }
3685
+        }
3686
+
3687
+        return "Error, mode/status not found";
3688
+    }
3689 3689
 
3690 3690
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
3691
-	/**
3692
-	 *  Set outstanding value
3693
-	 *
3694
-	 *  @param  User	$user		User making change
3695
-	 *	@return	int					<0 if KO, >0 if OK
3696
-	 * @deprecated Use update function instead
3697
-	 */
3698
-	function set_OutstandingBill(User $user)
3699
-	{
3691
+    /**
3692
+     *  Set outstanding value
3693
+     *
3694
+     *  @param  User	$user		User making change
3695
+     *	@return	int					<0 if KO, >0 if OK
3696
+     * @deprecated Use update function instead
3697
+     */
3698
+    function set_OutstandingBill(User $user)
3699
+    {
3700 3700
         // phpcs:enable
3701
-		return $this->update($this->id, $user);
3702
-	}
3703
-
3704
-	/**
3705
-	 *  Return amount of order not paid and total
3706
-	 *
3707
-	 *  @param     string      $mode    'customer' or 'supplier'
3708
-	 *  @return    array				array('opened'=>Amount, 'total'=>Total amount)
3709
-	 */
3710
-	function getOutstandingProposals($mode='customer')
3711
-	{
3712
-		$table='propal';
3713
-		if ($mode == 'supplier') $table = 'supplier_proposal';
3714
-
3715
-		$sql  = "SELECT rowid, total_ht, total as total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f";
3716
-		$sql .= " WHERE fk_soc = ". $this->id;
3717
-		if ($mode == 'supplier') {
3718
-			$sql .= " AND entity IN (".getEntity('supplier_proposal').")";
3719
-		} else {
3720
-			$sql .= " AND entity IN (".getEntity('propal').")";
3721
-		}
3722
-
3723
-		dol_syslog("getOutstandingProposals", LOG_DEBUG);
3724
-		$resql=$this->db->query($sql);
3725
-		if ($resql)
3726
-		{
3727
-			$outstandingOpened = 0;
3728
-			$outstandingTotal = 0;
3729
-			$outstandingTotalIncTax = 0;
3730
-			while($obj=$this->db->fetch_object($resql)) {
3731
-				$outstandingTotal+= $obj->total_ht;
3732
-				$outstandingTotalIncTax+= $obj->total_ttc;
3733
-				if ($obj->fk_statut != 0)    // Not a draft
3734
-				{
3735
-					$outstandingOpened+=$obj->total_ttc;
3736
-				}
3737
-			}
3738
-			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3739
-		}
3740
-		else
3741
-			return array();
3742
-	}
3743
-
3744
-	/**
3745
-	 *  Return amount of order not paid and total
3746
-	 *
3747
-	 *  @param     string      $mode    'customer' or 'supplier'
3748
-	 *  @return		array				array('opened'=>Amount, 'total'=>Total amount)
3749
-	 */
3750
-	function getOutstandingOrders($mode='customer')
3751
-	{
3752
-		$table='commande';
3753
-		if ($mode == 'supplier') $table = 'commande_fournisseur';
3754
-
3755
-		$sql  = "SELECT rowid, total_ht, total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f";
3756
-		$sql .= " WHERE fk_soc = ". $this->id;
3757
-		if ($mode == 'supplier') {
3758
-			$sql .= " AND entity IN (".getEntity('supplier_order').")";
3759
-		} else {
3760
-			$sql .= " AND entity IN (".getEntity('commande').")";
3761
-		}
3762
-
3763
-		dol_syslog("getOutstandingOrders", LOG_DEBUG);
3764
-		$resql=$this->db->query($sql);
3765
-		if ($resql)
3766
-		{
3767
-			$outstandingOpened = 0;
3768
-			$outstandingTotal = 0;
3769
-			$outstandingTotalIncTax = 0;
3770
-			while($obj=$this->db->fetch_object($resql)) {
3771
-				$outstandingTotal+= $obj->total_ht;
3772
-				$outstandingTotalIncTax+= $obj->total_ttc;
3773
-				if ($obj->fk_statut != 0)    // Not a draft
3774
-				{
3775
-					$outstandingOpened+=$obj->total_ttc;
3776
-				}
3777
-			}
3778
-			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3779
-		}
3780
-		else
3781
-			return array();
3782
-	}
3783
-
3784
-	/**
3785
-	 *  Return amount of bill not paid and total
3786
-	 *
3787
-	 *  @param     string      $mode    'customer' or 'supplier'
3788
-	 *  @return		array				array('opened'=>Amount, 'total'=>Total amount)
3789
-	 */
3790
-	function getOutstandingBills($mode='customer')
3791
-	{
3792
-		$table='facture';
3793
-		if ($mode == 'supplier') $table = 'facture_fourn';
3794
-
3795
-		/* Accurate value of remain to pay is to sum remaintopay for each invoice
3701
+        return $this->update($this->id, $user);
3702
+    }
3703
+
3704
+    /**
3705
+     *  Return amount of order not paid and total
3706
+     *
3707
+     *  @param     string      $mode    'customer' or 'supplier'
3708
+     *  @return    array				array('opened'=>Amount, 'total'=>Total amount)
3709
+     */
3710
+    function getOutstandingProposals($mode='customer')
3711
+    {
3712
+        $table='propal';
3713
+        if ($mode == 'supplier') $table = 'supplier_proposal';
3714
+
3715
+        $sql  = "SELECT rowid, total_ht, total as total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f";
3716
+        $sql .= " WHERE fk_soc = ". $this->id;
3717
+        if ($mode == 'supplier') {
3718
+            $sql .= " AND entity IN (".getEntity('supplier_proposal').")";
3719
+        } else {
3720
+            $sql .= " AND entity IN (".getEntity('propal').")";
3721
+        }
3722
+
3723
+        dol_syslog("getOutstandingProposals", LOG_DEBUG);
3724
+        $resql=$this->db->query($sql);
3725
+        if ($resql)
3726
+        {
3727
+            $outstandingOpened = 0;
3728
+            $outstandingTotal = 0;
3729
+            $outstandingTotalIncTax = 0;
3730
+            while($obj=$this->db->fetch_object($resql)) {
3731
+                $outstandingTotal+= $obj->total_ht;
3732
+                $outstandingTotalIncTax+= $obj->total_ttc;
3733
+                if ($obj->fk_statut != 0)    // Not a draft
3734
+                {
3735
+                    $outstandingOpened+=$obj->total_ttc;
3736
+                }
3737
+            }
3738
+            return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3739
+        }
3740
+        else
3741
+            return array();
3742
+    }
3743
+
3744
+    /**
3745
+     *  Return amount of order not paid and total
3746
+     *
3747
+     *  @param     string      $mode    'customer' or 'supplier'
3748
+     *  @return		array				array('opened'=>Amount, 'total'=>Total amount)
3749
+     */
3750
+    function getOutstandingOrders($mode='customer')
3751
+    {
3752
+        $table='commande';
3753
+        if ($mode == 'supplier') $table = 'commande_fournisseur';
3754
+
3755
+        $sql  = "SELECT rowid, total_ht, total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f";
3756
+        $sql .= " WHERE fk_soc = ". $this->id;
3757
+        if ($mode == 'supplier') {
3758
+            $sql .= " AND entity IN (".getEntity('supplier_order').")";
3759
+        } else {
3760
+            $sql .= " AND entity IN (".getEntity('commande').")";
3761
+        }
3762
+
3763
+        dol_syslog("getOutstandingOrders", LOG_DEBUG);
3764
+        $resql=$this->db->query($sql);
3765
+        if ($resql)
3766
+        {
3767
+            $outstandingOpened = 0;
3768
+            $outstandingTotal = 0;
3769
+            $outstandingTotalIncTax = 0;
3770
+            while($obj=$this->db->fetch_object($resql)) {
3771
+                $outstandingTotal+= $obj->total_ht;
3772
+                $outstandingTotalIncTax+= $obj->total_ttc;
3773
+                if ($obj->fk_statut != 0)    // Not a draft
3774
+                {
3775
+                    $outstandingOpened+=$obj->total_ttc;
3776
+                }
3777
+            }
3778
+            return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3779
+        }
3780
+        else
3781
+            return array();
3782
+    }
3783
+
3784
+    /**
3785
+     *  Return amount of bill not paid and total
3786
+     *
3787
+     *  @param     string      $mode    'customer' or 'supplier'
3788
+     *  @return		array				array('opened'=>Amount, 'total'=>Total amount)
3789
+     */
3790
+    function getOutstandingBills($mode='customer')
3791
+    {
3792
+        $table='facture';
3793
+        if ($mode == 'supplier') $table = 'facture_fourn';
3794
+
3795
+        /* Accurate value of remain to pay is to sum remaintopay for each invoice
3796 3796
 		 $paiement = $invoice->getSommePaiement();
3797 3797
 		 $creditnotes=$invoice->getSumCreditNotesUsed();
3798 3798
 		 $deposits=$invoice->getSumDepositsUsed();
3799 3799
 		 $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
3800 3800
 		 $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
3801 3801
 		 */
3802
-		if ($mode == 'supplier') $sql  = "SELECT rowid, total_ht as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3803
-		else $sql  = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3804
-		$sql .= " WHERE fk_soc = ". $this->id;
3805
-		if ($mode == 'supplier') {
3806
-			$sql .= " AND entity IN (".getEntity('facture_fourn').")";
3807
-		} else {
3808
-			$sql .= " AND entity IN (".getEntity('invoice').")";
3809
-		}
3810
-
3811
-		dol_syslog("getOutstandingBills", LOG_DEBUG);
3812
-		$resql=$this->db->query($sql);
3813
-		if ($resql)
3814
-		{
3815
-			$outstandingOpened = 0;
3816
-			$outstandingTotal = 0;
3817
-			$outstandingTotalIncTax = 0;
3818
-			if ($mode == 'supplier')
3819
-			{
3820
-				require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
3821
-				$tmpobject=new FactureFournisseur($this->db);
3822
-			}
3823
-			else
3824
-			{
3825
-				require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
3826
-				$tmpobject=new Facture($this->db);
3827
-			}
3828
-			while($obj=$this->db->fetch_object($resql)) {
3829
-				$tmpobject->id=$obj->rowid;
3830
-				if ($obj->fk_statut != 0                                           // Not a draft
3831
-					&& ! ($obj->fk_statut == 3 && $obj->close_code == 'replaced')  // Not a replaced invoice
3832
-					)
3833
-				{
3834
-					$outstandingTotal+= $obj->total_ht;
3835
-					$outstandingTotalIncTax+= $obj->total_ttc;
3836
-				}
3837
-				if ($obj->paye == 0
3838
-					&& $obj->fk_statut != 0    // Not a draft
3839
-					&& $obj->fk_statut != 3	   // Not abandonned
3840
-					&& $obj->fk_statut != 2)   // Not classified as paid
3841
-				//$sql .= " AND (fk_statut <> 3 OR close_code <> 'abandon')";		// Not abandonned for undefined reason
3842
-				{
3843
-					$paiement = $tmpobject->getSommePaiement();
3844
-					$creditnotes = $tmpobject->getSumCreditNotesUsed();
3845
-					$deposits = $tmpobject->getSumDepositsUsed();
3846
-					$outstandingOpened+=$obj->total_ttc - $paiement - $creditnotes - $deposits;
3847
-				}
3848
-			}
3849
-			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3850
-		}
3851
-		else
3852
-		{
3853
-			return array();
3854
-		}
3855
-	}
3802
+        if ($mode == 'supplier') $sql  = "SELECT rowid, total_ht as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3803
+        else $sql  = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3804
+        $sql .= " WHERE fk_soc = ". $this->id;
3805
+        if ($mode == 'supplier') {
3806
+            $sql .= " AND entity IN (".getEntity('facture_fourn').")";
3807
+        } else {
3808
+            $sql .= " AND entity IN (".getEntity('invoice').")";
3809
+        }
3810
+
3811
+        dol_syslog("getOutstandingBills", LOG_DEBUG);
3812
+        $resql=$this->db->query($sql);
3813
+        if ($resql)
3814
+        {
3815
+            $outstandingOpened = 0;
3816
+            $outstandingTotal = 0;
3817
+            $outstandingTotalIncTax = 0;
3818
+            if ($mode == 'supplier')
3819
+            {
3820
+                require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
3821
+                $tmpobject=new FactureFournisseur($this->db);
3822
+            }
3823
+            else
3824
+            {
3825
+                require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
3826
+                $tmpobject=new Facture($this->db);
3827
+            }
3828
+            while($obj=$this->db->fetch_object($resql)) {
3829
+                $tmpobject->id=$obj->rowid;
3830
+                if ($obj->fk_statut != 0                                           // Not a draft
3831
+                    && ! ($obj->fk_statut == 3 && $obj->close_code == 'replaced')  // Not a replaced invoice
3832
+                    )
3833
+                {
3834
+                    $outstandingTotal+= $obj->total_ht;
3835
+                    $outstandingTotalIncTax+= $obj->total_ttc;
3836
+                }
3837
+                if ($obj->paye == 0
3838
+                    && $obj->fk_statut != 0    // Not a draft
3839
+                    && $obj->fk_statut != 3	   // Not abandonned
3840
+                    && $obj->fk_statut != 2)   // Not classified as paid
3841
+                //$sql .= " AND (fk_statut <> 3 OR close_code <> 'abandon')";		// Not abandonned for undefined reason
3842
+                {
3843
+                    $paiement = $tmpobject->getSommePaiement();
3844
+                    $creditnotes = $tmpobject->getSumCreditNotesUsed();
3845
+                    $deposits = $tmpobject->getSumDepositsUsed();
3846
+                    $outstandingOpened+=$obj->total_ttc - $paiement - $creditnotes - $deposits;
3847
+                }
3848
+            }
3849
+            return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3850
+        }
3851
+        else
3852
+        {
3853
+            return array();
3854
+        }
3855
+    }
3856 3856
 
3857 3857
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
3858
-	/**
3859
-	 *  Return amount of bill not paid
3860
-	 *
3861
-	 *  @return		int				Amount in debt for thirdparty
3862
-	 *  @deprecated
3863
-	 *  @see getOutstandingBills()
3864
-	 */
3865
-	function get_OutstandingBill()
3866
-	{
3858
+    /**
3859
+     *  Return amount of bill not paid
3860
+     *
3861
+     *  @return		int				Amount in debt for thirdparty
3862
+     *  @deprecated
3863
+     *  @see getOutstandingBills()
3864
+     */
3865
+    function get_OutstandingBill()
3866
+    {
3867 3867
         // phpcs:enable
3868
-		/* Accurate value of remain to pay is to sum remaintopay for each invoice
3868
+        /* Accurate value of remain to pay is to sum remaintopay for each invoice
3869 3869
 	     $paiement = $invoice->getSommePaiement();
3870 3870
 	     $creditnotes=$invoice->getSumCreditNotesUsed();
3871 3871
 	     $deposits=$invoice->getSumDepositsUsed();
3872 3872
 	     $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
3873 3873
 	     $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
3874 3874
 	     */
3875
-		$sql  = "SELECT rowid, total_ttc FROM ".MAIN_DB_PREFIX."facture as f";
3876
-		$sql .= " WHERE fk_soc = ". $this->id;
3877
-		$sql .= " AND paye = 0";
3878
-		$sql .= " AND fk_statut <> 0";	// Not a draft
3879
-		//$sql .= " AND (fk_statut <> 3 OR close_code <> 'abandon')";		// Not abandonned for undefined reason
3880
-		$sql .= " AND fk_statut <> 3";		// Not abandonned
3881
-		$sql .= " AND fk_statut <> 2";		// Not clasified as paid
3882
-
3883
-		dol_syslog("get_OutstandingBill", LOG_DEBUG);
3884
-		$resql=$this->db->query($sql);
3885
-		if ($resql)
3886
-		{
3887
-			$outstandingAmount = 0;
3888
-			require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
3889
-			$tmpobject=new Facture($this->db);
3890
-			while($obj=$this->db->fetch_object($resql)) {
3891
-				$tmpobject->id=$obj->rowid;
3892
-				$paiement = $tmpobject->getSommePaiement();
3893
-				$creditnotes = $tmpobject->getSumCreditNotesUsed();
3894
-				$deposits = $tmpobject->getSumDepositsUsed();
3895
-				$outstandingAmount+= $obj->total_ttc - $paiement - $creditnotes - $deposits;
3896
-			}
3897
-			return $outstandingAmount;
3898
-		}
3899
-		else
3900
-			return 0;
3901
-	}
3902
-
3903
-	/**
3904
-	 * Return label of status customer is prospect/customer
3905
-	 *
3906
-	 * @return   string        	Label
3907
-	 */
3908
-	function getLibCustProspStatut()
3909
-	{
3910
-		return $this->LibCustProspStatut($this->client);
3911
-	}
3875
+        $sql  = "SELECT rowid, total_ttc FROM ".MAIN_DB_PREFIX."facture as f";
3876
+        $sql .= " WHERE fk_soc = ". $this->id;
3877
+        $sql .= " AND paye = 0";
3878
+        $sql .= " AND fk_statut <> 0";	// Not a draft
3879
+        //$sql .= " AND (fk_statut <> 3 OR close_code <> 'abandon')";		// Not abandonned for undefined reason
3880
+        $sql .= " AND fk_statut <> 3";		// Not abandonned
3881
+        $sql .= " AND fk_statut <> 2";		// Not clasified as paid
3882
+
3883
+        dol_syslog("get_OutstandingBill", LOG_DEBUG);
3884
+        $resql=$this->db->query($sql);
3885
+        if ($resql)
3886
+        {
3887
+            $outstandingAmount = 0;
3888
+            require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
3889
+            $tmpobject=new Facture($this->db);
3890
+            while($obj=$this->db->fetch_object($resql)) {
3891
+                $tmpobject->id=$obj->rowid;
3892
+                $paiement = $tmpobject->getSommePaiement();
3893
+                $creditnotes = $tmpobject->getSumCreditNotesUsed();
3894
+                $deposits = $tmpobject->getSumDepositsUsed();
3895
+                $outstandingAmount+= $obj->total_ttc - $paiement - $creditnotes - $deposits;
3896
+            }
3897
+            return $outstandingAmount;
3898
+        }
3899
+        else
3900
+            return 0;
3901
+    }
3902
+
3903
+    /**
3904
+     * Return label of status customer is prospect/customer
3905
+     *
3906
+     * @return   string        	Label
3907
+     */
3908
+    function getLibCustProspStatut()
3909
+    {
3910
+        return $this->LibCustProspStatut($this->client);
3911
+    }
3912 3912
 
3913 3913
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
3914
-	/**
3915
-	 *  Renvoi le libelle d'un statut donne
3916
-	 *
3917
-	 *  @param	int		$statut         Id statut
3918
-	 *  @return	string          		Libelle du statut
3919
-	 */
3920
-	function LibCustProspStatut($statut)
3921
-	{
3914
+    /**
3915
+     *  Renvoi le libelle d'un statut donne
3916
+     *
3917
+     *  @param	int		$statut         Id statut
3918
+     *  @return	string          		Libelle du statut
3919
+     */
3920
+    function LibCustProspStatut($statut)
3921
+    {
3922 3922
         // phpcs:enable
3923
-		global $langs;
3924
-		$langs->load('companies');
3925
-
3926
-		if ($statut==0) return $langs->trans("NorProspectNorCustomer");
3927
-		if ($statut==1) return $langs->trans("Customer");
3928
-		if ($statut==2) return $langs->trans("Prospect");
3929
-		if ($statut==3) return $langs->trans("ProspectCustomer");
3930
-	}
3931
-
3932
-
3933
-	/**
3934
-	 *  Create a document onto disk according to template module.
3935
-	 *
3936
-	 *	@param	string		$modele			Generator to use. Caller must set it to obj->modelpdf or GETPOST('modelpdf') for example.
3937
-	 *	@param	Translate	$outputlangs	objet lang a utiliser pour traduction
3938
-	 *  @param  int			$hidedetails    Hide details of lines
3939
-	 *  @param  int			$hidedesc       Hide description
3940
-	 *  @param  int			$hideref        Hide ref
3941
-	 *  @param  null|array  $moreparams     Array to provide more information
3942
-	 *	@return int        					<0 if KO, >0 if OK
3943
-	 */
3944
-	public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
3945
-	{
3946
-		global $conf,$user,$langs;
3947
-
3948
-		if (! empty($moreparams) && ! empty($moreparams['use_companybankid']))
3949
-		{
3950
-			$modelpath = "core/modules/bank/doc/";
3951
-
3952
-			include_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
3953
-			$companybankaccount = new CompanyBankAccount($this->db);
3954
-			$result = $companybankaccount->fetch($moreparams['use_companybankid']);
3955
-			if (! $result) dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
3956
-			$result=$companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3957
-		}
3958
-		else
3959
-		{
3960
-			// Positionne le modele sur le nom du modele a utiliser
3961
-			if (! dol_strlen($modele))
3962
-			{
3963
-				if (! empty($conf->global->COMPANY_ADDON_PDF))
3964
-				{
3965
-					$modele = $conf->global->COMPANY_ADDON_PDF;
3966
-				}
3967
-				else
3968
-				{
3969
-					print $langs->trans("Error")." ".$langs->trans("Error_COMPANY_ADDON_PDF_NotDefined");
3970
-					return 0;
3971
-				}
3972
-			}
3973
-
3974
-			$modelpath = "core/modules/societe/doc/";
3975
-
3976
-			$result=$this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3977
-		}
3978
-
3979
-		return $result;
3980
-	}
3981
-
3982
-
3983
-	/**
3984
-	 * Sets object to supplied categories.
3985
-	 *
3986
-	 * Deletes object from existing categories not supplied.
3987
-	 * Adds it to non existing supplied categories.
3988
-	 * Existing categories are left untouch.
3989
-	 *
3990
-	 * @param 	int[]|int 	$categories 	Category ID or array of Categories IDs
3991
-	 * @param 	string 		$type 			Category type ('customer' or 'supplier')
3992
-	 * @return	int							<0 if KO, >0 if OK
3993
-	 */
3994
-	public function setCategories($categories, $type)
3995
-	{
3996
-		require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
3997
-
3998
-		// Decode type
3999
-		if ($type == 'customer') {
4000
-			$type_id = Categorie::TYPE_CUSTOMER;
4001
-			$type_text = 'customer';
4002
-		} elseif ($type == 'supplier') {
4003
-			$type_id = Categorie::TYPE_SUPPLIER;
4004
-			$type_text = 'supplier';
4005
-		} else {
4006
-			dol_syslog(__METHOD__ . ': Type ' . $type .  'is an unknown company category type. Done nothing.', LOG_ERR);
4007
-			return -1;
4008
-		}
4009
-
4010
-		// Handle single category
4011
-		if (!is_array($categories)) {
4012
-			$categories = array($categories);
4013
-		}
4014
-
4015
-		// Get current categories
4016
-		$c = new Categorie($this->db);
4017
-		$existing = $c->containing($this->id, $type_id, 'id');
4018
-
4019
-		// Diff
4020
-		if (is_array($existing)) {
4021
-			$to_del = array_diff($existing, $categories);
4022
-			$to_add = array_diff($categories, $existing);
4023
-		} else {
4024
-			$to_del = array(); // Nothing to delete
4025
-			$to_add = $categories;
4026
-		}
4027
-
4028
-		$error = 0;
4029
-
4030
-		// Process
4031
-		foreach ($to_del as $del) {
4032
-			if ($c->fetch($del) > 0) {
4033
-				$c->del_type($this, $type_text);
4034
-			}
4035
-		}
4036
-		foreach ($to_add as $add) {
4037
-			if ($c->fetch($add) > 0)
4038
-			{
4039
-				$result = $c->add_type($this, $type_text);
4040
-				if ($result < 0)
4041
-				{
4042
-					$error++;
4043
-					$this->error = $c->error;
4044
-					$this->errors = $c->errors;
4045
-					break;
4046
-				}
4047
-			}
4048
-		}
4049
-
4050
-		return $error ? -1 : 1;
4051
-	}
4052
-
4053
-	/**
4054
-	 * Sets sales representatives of the thirdparty
4055
-	 *
4056
-	 * @param 	int[]|int 	$salesrep	 	User ID or array of user IDs
4057
-	 * @return	int							<0 if KO, >0 if OK
4058
-	 */
4059
-	public function setSalesRep($salesrep)
4060
-	{
4061
-		global $user;
4062
-
4063
-		// Handle single user
4064
-		if (!is_array($salesrep)) {
4065
-			$salesrep = array($salesrep);
4066
-		}
4067
-
4068
-		// Get current users
4069
-		$existing = $this->getSalesRepresentatives($user, 1);
4070
-
4071
-		// Diff
4072
-		if (is_array($existing)) {
4073
-			$to_del = array_diff($existing, $salesrep);
4074
-			$to_add = array_diff($salesrep, $existing);
4075
-		} else {
4076
-			$to_del = array(); // Nothing to delete
4077
-			$to_add = $salesrep;
4078
-		}
4079
-
4080
-		$error = 0;
4081
-
4082
-		// Process
4083
-		foreach ($to_del as $del) {
4084
-			$this->del_commercial($user, $del);
4085
-		}
4086
-		foreach ($to_add as $add) {
4087
-			$result = $this->add_commercial($user, $add);
4088
-			if ($result < 0)
4089
-			{
4090
-				$error++;
4091
-				$this->error = $c->error;
4092
-				$this->errors = $c->errors;
4093
-				break;
4094
-			}
4095
-		}
4096
-
4097
-		return $error ? -1 : 1;
4098
-	}
4099
-
4100
-
4101
-	/**
4102
-	 * Function used to replace a thirdparty id with another one.
4103
-	 * It must be used within a transaction to avoid trouble
4104
-	 *
4105
-	 * @param 	DoliDB 	$db 		Database handler
4106
-	 * @param 	int 	$origin_id 	Old thirdparty id (will be removed)
4107
-	 * @param 	int 	$dest_id 	New thirdparty id
4108
-	 * @return 	bool				True if success, False if error
4109
-	 */
4110
-	public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
4111
-	{
4112
-		if ($origin_id == $dest_id)
4113
-		{
4114
-			dol_syslog('Error: Try to merge a thirdparty into itself');
4115
-			return false;
4116
-		}
4117
-
4118
-		/**
4119
-		 * Thirdparty commercials cannot be the same in both thirdparties so we look for them and remove some to avoid duplicate.
4120
-		 * Because this function is meant to be executed within a transaction, we won't take care of begin/commit.
4121
-		 */
4122
-		$sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'societe_commerciaux ';
4123
-		$sql .= ' WHERE fk_soc = '.(int) $dest_id.' AND fk_user IN ( ';
4124
-		$sql .= ' SELECT fk_user ';
4125
-		$sql .= ' FROM '.MAIN_DB_PREFIX.'societe_commerciaux ';
4126
-		$sql .= ' WHERE fk_soc = '.(int) $origin_id.') ';
3923
+        global $langs;
3924
+        $langs->load('companies');
4127 3925
 
4128
-		$query = $db->query($sql);
3926
+        if ($statut==0) return $langs->trans("NorProspectNorCustomer");
3927
+        if ($statut==1) return $langs->trans("Customer");
3928
+        if ($statut==2) return $langs->trans("Prospect");
3929
+        if ($statut==3) return $langs->trans("ProspectCustomer");
3930
+    }
4129 3931
 
4130
-		while ($result = $db->fetch_object($query)) {
4131
-			$db->query('DELETE FROM '.MAIN_DB_PREFIX.'societe_commerciaux WHERE rowid = '.$result->rowid);
4132
-		}
4133 3932
 
4134
-		/**
4135
-		 * llx_societe_extrafields table must not be here because we don't care about the old thirdparty data
4136
-		 * Do not include llx_societe because it will be replaced later
4137
-		 */
4138
-		$tables = array(
4139
-			'societe_address',
4140
-			'societe_commerciaux',
4141
-			'societe_log',
4142
-			'societe_prices',
4143
-			'societe_remise',
4144
-			'societe_remise_except',
4145
-			'societe_rib'
4146
-		);
4147
-
4148
-		return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
4149
-	}
3933
+    /**
3934
+     *  Create a document onto disk according to template module.
3935
+     *
3936
+     *	@param	string		$modele			Generator to use. Caller must set it to obj->modelpdf or GETPOST('modelpdf') for example.
3937
+     *	@param	Translate	$outputlangs	objet lang a utiliser pour traduction
3938
+     *  @param  int			$hidedetails    Hide details of lines
3939
+     *  @param  int			$hidedesc       Hide description
3940
+     *  @param  int			$hideref        Hide ref
3941
+     *  @param  null|array  $moreparams     Array to provide more information
3942
+     *	@return int        					<0 if KO, >0 if OK
3943
+     */
3944
+    public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
3945
+    {
3946
+        global $conf,$user,$langs;
3947
+
3948
+        if (! empty($moreparams) && ! empty($moreparams['use_companybankid']))
3949
+        {
3950
+            $modelpath = "core/modules/bank/doc/";
3951
+
3952
+            include_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
3953
+            $companybankaccount = new CompanyBankAccount($this->db);
3954
+            $result = $companybankaccount->fetch($moreparams['use_companybankid']);
3955
+            if (! $result) dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
3956
+            $result=$companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3957
+        }
3958
+        else
3959
+        {
3960
+            // Positionne le modele sur le nom du modele a utiliser
3961
+            if (! dol_strlen($modele))
3962
+            {
3963
+                if (! empty($conf->global->COMPANY_ADDON_PDF))
3964
+                {
3965
+                    $modele = $conf->global->COMPANY_ADDON_PDF;
3966
+                }
3967
+                else
3968
+                {
3969
+                    print $langs->trans("Error")." ".$langs->trans("Error_COMPANY_ADDON_PDF_NotDefined");
3970
+                    return 0;
3971
+                }
3972
+            }
3973
+
3974
+            $modelpath = "core/modules/societe/doc/";
3975
+
3976
+            $result=$this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3977
+        }
3978
+
3979
+        return $result;
3980
+    }
3981
+
3982
+
3983
+    /**
3984
+     * Sets object to supplied categories.
3985
+     *
3986
+     * Deletes object from existing categories not supplied.
3987
+     * Adds it to non existing supplied categories.
3988
+     * Existing categories are left untouch.
3989
+     *
3990
+     * @param 	int[]|int 	$categories 	Category ID or array of Categories IDs
3991
+     * @param 	string 		$type 			Category type ('customer' or 'supplier')
3992
+     * @return	int							<0 if KO, >0 if OK
3993
+     */
3994
+    public function setCategories($categories, $type)
3995
+    {
3996
+        require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
3997
+
3998
+        // Decode type
3999
+        if ($type == 'customer') {
4000
+            $type_id = Categorie::TYPE_CUSTOMER;
4001
+            $type_text = 'customer';
4002
+        } elseif ($type == 'supplier') {
4003
+            $type_id = Categorie::TYPE_SUPPLIER;
4004
+            $type_text = 'supplier';
4005
+        } else {
4006
+            dol_syslog(__METHOD__ . ': Type ' . $type .  'is an unknown company category type. Done nothing.', LOG_ERR);
4007
+            return -1;
4008
+        }
4009
+
4010
+        // Handle single category
4011
+        if (!is_array($categories)) {
4012
+            $categories = array($categories);
4013
+        }
4014
+
4015
+        // Get current categories
4016
+        $c = new Categorie($this->db);
4017
+        $existing = $c->containing($this->id, $type_id, 'id');
4018
+
4019
+        // Diff
4020
+        if (is_array($existing)) {
4021
+            $to_del = array_diff($existing, $categories);
4022
+            $to_add = array_diff($categories, $existing);
4023
+        } else {
4024
+            $to_del = array(); // Nothing to delete
4025
+            $to_add = $categories;
4026
+        }
4027
+
4028
+        $error = 0;
4029
+
4030
+        // Process
4031
+        foreach ($to_del as $del) {
4032
+            if ($c->fetch($del) > 0) {
4033
+                $c->del_type($this, $type_text);
4034
+            }
4035
+        }
4036
+        foreach ($to_add as $add) {
4037
+            if ($c->fetch($add) > 0)
4038
+            {
4039
+                $result = $c->add_type($this, $type_text);
4040
+                if ($result < 0)
4041
+                {
4042
+                    $error++;
4043
+                    $this->error = $c->error;
4044
+                    $this->errors = $c->errors;
4045
+                    break;
4046
+                }
4047
+            }
4048
+        }
4049
+
4050
+        return $error ? -1 : 1;
4051
+    }
4052
+
4053
+    /**
4054
+     * Sets sales representatives of the thirdparty
4055
+     *
4056
+     * @param 	int[]|int 	$salesrep	 	User ID or array of user IDs
4057
+     * @return	int							<0 if KO, >0 if OK
4058
+     */
4059
+    public function setSalesRep($salesrep)
4060
+    {
4061
+        global $user;
4062
+
4063
+        // Handle single user
4064
+        if (!is_array($salesrep)) {
4065
+            $salesrep = array($salesrep);
4066
+        }
4067
+
4068
+        // Get current users
4069
+        $existing = $this->getSalesRepresentatives($user, 1);
4070
+
4071
+        // Diff
4072
+        if (is_array($existing)) {
4073
+            $to_del = array_diff($existing, $salesrep);
4074
+            $to_add = array_diff($salesrep, $existing);
4075
+        } else {
4076
+            $to_del = array(); // Nothing to delete
4077
+            $to_add = $salesrep;
4078
+        }
4079
+
4080
+        $error = 0;
4081
+
4082
+        // Process
4083
+        foreach ($to_del as $del) {
4084
+            $this->del_commercial($user, $del);
4085
+        }
4086
+        foreach ($to_add as $add) {
4087
+            $result = $this->add_commercial($user, $add);
4088
+            if ($result < 0)
4089
+            {
4090
+                $error++;
4091
+                $this->error = $c->error;
4092
+                $this->errors = $c->errors;
4093
+                break;
4094
+            }
4095
+        }
4096
+
4097
+        return $error ? -1 : 1;
4098
+    }
4099
+
4100
+
4101
+    /**
4102
+     * Function used to replace a thirdparty id with another one.
4103
+     * It must be used within a transaction to avoid trouble
4104
+     *
4105
+     * @param 	DoliDB 	$db 		Database handler
4106
+     * @param 	int 	$origin_id 	Old thirdparty id (will be removed)
4107
+     * @param 	int 	$dest_id 	New thirdparty id
4108
+     * @return 	bool				True if success, False if error
4109
+     */
4110
+    public static function replaceThirdparty(DoliDB $db, $origin_id, $dest_id)
4111
+    {
4112
+        if ($origin_id == $dest_id)
4113
+        {
4114
+            dol_syslog('Error: Try to merge a thirdparty into itself');
4115
+            return false;
4116
+        }
4117
+
4118
+        /**
4119
+         * Thirdparty commercials cannot be the same in both thirdparties so we look for them and remove some to avoid duplicate.
4120
+         * Because this function is meant to be executed within a transaction, we won't take care of begin/commit.
4121
+         */
4122
+        $sql = 'SELECT rowid FROM '.MAIN_DB_PREFIX.'societe_commerciaux ';
4123
+        $sql .= ' WHERE fk_soc = '.(int) $dest_id.' AND fk_user IN ( ';
4124
+        $sql .= ' SELECT fk_user ';
4125
+        $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_commerciaux ';
4126
+        $sql .= ' WHERE fk_soc = '.(int) $origin_id.') ';
4127
+
4128
+        $query = $db->query($sql);
4129
+
4130
+        while ($result = $db->fetch_object($query)) {
4131
+            $db->query('DELETE FROM '.MAIN_DB_PREFIX.'societe_commerciaux WHERE rowid = '.$result->rowid);
4132
+        }
4133
+
4134
+        /**
4135
+         * llx_societe_extrafields table must not be here because we don't care about the old thirdparty data
4136
+         * Do not include llx_societe because it will be replaced later
4137
+         */
4138
+        $tables = array(
4139
+            'societe_address',
4140
+            'societe_commerciaux',
4141
+            'societe_log',
4142
+            'societe_prices',
4143
+            'societe_remise',
4144
+            'societe_remise_except',
4145
+            'societe_rib'
4146
+        );
4147
+
4148
+        return CommonObject::commonReplaceThirdparty($db, $origin_id, $dest_id, $tables);
4149
+    }
4150 4150
 }
Please login to merge, or discard this patch.
Spacing   +798 added lines, -798 removed lines patch added patch discarded remove patch
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
 	/**
46 46
 	 * @var string ID to identify managed object
47 47
 	 */
48
-	public $element='societe';
48
+	public $element = 'societe';
49 49
 
50 50
 	/**
51 51
 	 * @var string Name of table without prefix where object is stored
@@ -55,11 +55,11 @@  discard block
 block discarded – undo
55 55
 	/**
56 56
 	 * @var int Field with ID of parent key if this field has a parent
57 57
 	 */
58
-	public $fk_element='fk_soc';
58
+	public $fk_element = 'fk_soc';
59 59
 
60
-	public $fieldsforcombobox='nom,name_alias';
61
-	protected $childtables=array("supplier_proposal"=>'SupplierProposal',"propal"=>'Proposal',"commande"=>'Order',"facture"=>'Invoice',"facture_rec"=>'RecurringInvoiceTemplate',"contrat"=>'Contract',"fichinter"=>'Fichinter',"facture_fourn"=>'SupplierInvoice',"commande_fournisseur"=>'SupplierOrder',"projet"=>'Project',"expedition"=>'Shipment',"prelevement_lignes"=>'DirectDebitRecord');    // To test if we can delete object
62
-	protected $childtablesoncascade=array("societe_prices", "societe_log", "societe_address", "product_fournisseur_price", "product_customer_price_log", "product_customer_price", "socpeople", "adherent", "societe_rib", "societe_remise", "societe_remise_except", "societe_commerciaux", "categorie", "notify", "notify_def", "actioncomm");
60
+	public $fieldsforcombobox = 'nom,name_alias';
61
+	protected $childtables = array("supplier_proposal"=>'SupplierProposal', "propal"=>'Proposal', "commande"=>'Order', "facture"=>'Invoice', "facture_rec"=>'RecurringInvoiceTemplate', "contrat"=>'Contract', "fichinter"=>'Fichinter', "facture_fourn"=>'SupplierInvoice', "commande_fournisseur"=>'SupplierOrder', "projet"=>'Project', "expedition"=>'Shipment', "prelevement_lignes"=>'DirectDebitRecord'); // To test if we can delete object
62
+	protected $childtablesoncascade = array("societe_prices", "societe_log", "societe_address", "product_fournisseur_price", "product_customer_price_log", "product_customer_price", "socpeople", "adherent", "societe_rib", "societe_remise", "societe_remise_except", "societe_commerciaux", "categorie", "notify", "notify_def", "actioncomm");
63 63
 	public $picto = 'company';
64 64
 
65 65
 	/**
@@ -79,20 +79,20 @@  discard block
 block discarded – undo
79 79
 	/**
80 80
 	 * @var array  Array with all fields and their property. Do not use it as a static var. It may be modified by constructor.
81 81
 	 */
82
-	public $fields=array(
83
-		'rowid'         =>array('type'=>'integer',      'label'=>'TechnicalID',      'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'index'=>1, 'position'=>1, 'comment'=>'Id'),
84
-		'nom'           =>array('type'=>'varchar(128)', 'label'=>'Name',             'enabled'=>1, 'visible'=>1,  'notnull'=>1,  'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
85
-		'name_alias'    =>array('type'=>'varchar(128)', 'label'=>'Name',             'enabled'=>1, 'visible'=>1,  'notnull'=>1,  'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
86
-		'entity'        =>array('type'=>'integer',      'label'=>'Entity',           'enabled'=>1, 'visible'=>0,  'default'=>1,  'notnull'=>1,  'index'=>1, 'position'=>20),
87
-		'note_public'   =>array('type'=>'text',			'label'=>'NotePublic',		 'enabled'=>1, 'visible'=>0,  'position'=>60),
88
-		'note_private'  =>array('type'=>'text',			'label'=>'NotePrivate',		 'enabled'=>1, 'visible'=>0,  'position'=>61),
89
-		'datec'			=>array('type'=>'datetime',     'label'=>'DateCreation',     'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'position'=>500),
90
-		'tms'           =>array('type'=>'timestamp',    'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'position'=>501),
82
+	public $fields = array(
83
+		'rowid'         =>array('type'=>'integer', 'label'=>'TechnicalID', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'index'=>1, 'position'=>1, 'comment'=>'Id'),
84
+		'nom'           =>array('type'=>'varchar(128)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
85
+		'name_alias'    =>array('type'=>'varchar(128)', 'label'=>'Name', 'enabled'=>1, 'visible'=>1, 'notnull'=>1, 'showoncombobox'=>1, 'index'=>1, 'position'=>10, 'searchall'=>1, 'comment'=>'Reference of object'),
86
+		'entity'        =>array('type'=>'integer', 'label'=>'Entity', 'enabled'=>1, 'visible'=>0, 'default'=>1, 'notnull'=>1, 'index'=>1, 'position'=>20),
87
+		'note_public'   =>array('type'=>'text', 'label'=>'NotePublic', 'enabled'=>1, 'visible'=>0, 'position'=>60),
88
+		'note_private'  =>array('type'=>'text', 'label'=>'NotePrivate', 'enabled'=>1, 'visible'=>0, 'position'=>61),
89
+		'datec'			=>array('type'=>'datetime', 'label'=>'DateCreation', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>500),
90
+		'tms'           =>array('type'=>'timestamp', 'label'=>'DateModification', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>501),
91 91
 		//'date_valid'    =>array('type'=>'datetime',     'label'=>'DateCreation',     'enabled'=>1, 'visible'=>-2, 'position'=>502),
92
-		'fk_user_creat' =>array('type'=>'integer',      'label'=>'UserAuthor',       'enabled'=>1, 'visible'=>-2, 'notnull'=>1,  'position'=>510),
93
-		'fk_user_modif' =>array('type'=>'integer',      'label'=>'UserModif',        'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511),
92
+		'fk_user_creat' =>array('type'=>'integer', 'label'=>'UserAuthor', 'enabled'=>1, 'visible'=>-2, 'notnull'=>1, 'position'=>510),
93
+		'fk_user_modif' =>array('type'=>'integer', 'label'=>'UserModif', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'position'=>511),
94 94
 		//'fk_user_valid' =>array('type'=>'integer',      'label'=>'UserValidation',        'enabled'=>1, 'visible'=>-1, 'position'=>512),
95
-		'import_key'    =>array('type'=>'varchar(14)',  'label'=>'ImportId',         'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>1,  'position'=>1000),
95
+		'import_key'    =>array('type'=>'varchar(14)', 'label'=>'ImportId', 'enabled'=>1, 'visible'=>-2, 'notnull'=>-1, 'index'=>1, 'position'=>1000),
96 96
 	);
97 97
 
98 98
 
@@ -134,7 +134,7 @@  discard block
 block discarded – undo
134 134
 	 * Thirdparty status : 0=activity ceased, 1= in activity
135 135
 	 * @var int
136 136
 	 */
137
-	public $status=1;
137
+	public $status = 1;
138 138
 
139 139
 	/**
140 140
 	 * Id of department
@@ -256,7 +256,7 @@  discard block
 block discarded – undo
256 256
 
257 257
 	public $prefix_comm;
258 258
 
259
-	public $tva_assuj=1;
259
+	public $tva_assuj = 1;
260 260
 	/**
261 261
 	 * Intracommunitary VAT ID
262 262
 	 * @var string
@@ -271,12 +271,12 @@  discard block
 block discarded – undo
271 271
 
272 272
 	public $managers;
273 273
 	public $capital;
274
-	public $typent_id=0;
274
+	public $typent_id = 0;
275 275
 	public $typent_code;
276 276
 	public $effectif;
277
-	public $effectif_id=0;
277
+	public $effectif_id = 0;
278 278
 	public $forme_juridique_code;
279
-	public $forme_juridique=0;
279
+	public $forme_juridique = 0;
280 280
 
281 281
 	public $remise_percent;
282 282
 	public $remise_supplier_percent;
@@ -320,12 +320,12 @@  discard block
 block discarded – undo
320 320
 	 * 0=no customer, 1=customer, 2=prospect, 3=customer and prospect
321 321
 	 * @var int
322 322
 	 */
323
-	public $client=0;
323
+	public $client = 0;
324 324
 	/**
325 325
 	 * 0=no prospect, 1=prospect
326 326
 	 * @var int
327 327
 	 */
328
-	public $prospect=0;
328
+	public $prospect = 0;
329 329
 	/**
330 330
 	 * 0=no supplier, 1=supplier
331 331
 	 * @var int
@@ -461,7 +461,7 @@  discard block
 block discarded – undo
461 461
 	public $fk_incoterms;
462 462
 
463 463
 	public $location_incoterms;
464
-	public $libelle_incoterms;  //Used into tooltip
464
+	public $libelle_incoterms; //Used into tooltip
465 465
 
466 466
 	// Multicurrency
467 467
 	/**
@@ -487,9 +487,9 @@  discard block
 block discarded – undo
487 487
 		$this->client = 0;
488 488
 		$this->prospect = 0;
489 489
 		$this->fournisseur = 0;
490
-		$this->typent_id  = 0;
491
-		$this->effectif_id  = 0;
492
-		$this->forme_juridique_code  = 0;
490
+		$this->typent_id = 0;
491
+		$this->effectif_id = 0;
492
+		$this->forme_juridique_code = 0;
493 493
 		$this->tva_assuj = 1;
494 494
 		$this->status = 1;
495 495
 	}
@@ -504,17 +504,17 @@  discard block
 block discarded – undo
504 504
 	 */
505 505
 	function create(User $user)
506 506
 	{
507
-		global $langs,$conf,$mysoc;
507
+		global $langs, $conf, $mysoc;
508 508
 
509
-		$error=0;
509
+		$error = 0;
510 510
 
511 511
 		// Clean parameters
512
-		if (empty($this->status)) $this->status=0;
513
-		$this->name=$this->name?trim($this->name):trim($this->nom);
514
-		if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name=ucwords($this->name);
515
-		$this->nom=$this->name; // For backward compatibility
516
-		if (empty($this->client))      $this->client=0;
517
-		if (empty($this->fournisseur)) $this->fournisseur=0;
512
+		if (empty($this->status)) $this->status = 0;
513
+		$this->name = $this->name ?trim($this->name) : trim($this->nom);
514
+		if (!empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name = ucwords($this->name);
515
+		$this->nom = $this->name; // For backward compatibility
516
+		if (empty($this->client))      $this->client = 0;
517
+		if (empty($this->fournisseur)) $this->fournisseur = 0;
518 518
 		$this->import_key = trim($this->import_key);
519 519
 
520 520
 		if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
@@ -526,13 +526,13 @@  discard block
 block discarded – undo
526 526
 
527 527
 		dol_syslog(get_class($this)."::create ".$this->name);
528 528
 
529
-		$now=dol_now();
529
+		$now = dol_now();
530 530
 
531 531
 		$this->db->begin();
532 532
 
533 533
 		// For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
534
-		if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this,0);
535
-		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this,1);
534
+		if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this, 0);
535
+		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this, 1);
536 536
 
537 537
 		// Check more parameters (including mandatory setup
538 538
 		// If error, this->errors[] is filled
@@ -540,29 +540,29 @@  discard block
 block discarded – undo
540 540
 
541 541
 		if ($result >= 0)
542 542
 		{
543
-			$this->entity = ((isset($this->entity) && is_numeric($this->entity))?$this->entity:$conf->entity);
543
+			$this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
544 544
 
545 545
 			$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe (nom, name_alias, entity, datec, fk_user_creat, canvas, status, ref_int, ref_ext, fk_stcomm, fk_incoterms, location_incoterms ,import_key, fk_multicurrency, multicurrency_code)";
546
-			$sql.= " VALUES ('".$this->db->escape($this->name)."', '".$this->db->escape($this->name_alias)."', ".$this->db->escape($this->entity).", '".$this->db->idate($now)."'";
547
-			$sql.= ", ".(! empty($user->id) ? "'".$user->id."'":"null");
548
-			$sql.= ", ".(! empty($this->canvas) ? "'".$this->db->escape($this->canvas)."'":"null");
549
-			$sql.= ", ".$this->status;
550
-			$sql.= ", ".(! empty($this->ref_int) ? "'".$this->db->escape($this->ref_int)."'":"null");
551
-			$sql.= ", ".(! empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'":"null");
552
-			$sql.= ", 0";
553
-			$sql.= ", ".(int) $this->fk_incoterms;
554
-			$sql.= ", '".$this->db->escape($this->location_incoterms)."'";
555
-			$sql.= ", ".(! empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'":"null");
556
-			$sql.= ", ".(int) $this->fk_multicurrency;
557
-			$sql.= ", '".$this->db->escape($this->multicurrency_code)."')";
546
+			$sql .= " VALUES ('".$this->db->escape($this->name)."', '".$this->db->escape($this->name_alias)."', ".$this->db->escape($this->entity).", '".$this->db->idate($now)."'";
547
+			$sql .= ", ".(!empty($user->id) ? "'".$user->id."'" : "null");
548
+			$sql .= ", ".(!empty($this->canvas) ? "'".$this->db->escape($this->canvas)."'" : "null");
549
+			$sql .= ", ".$this->status;
550
+			$sql .= ", ".(!empty($this->ref_int) ? "'".$this->db->escape($this->ref_int)."'" : "null");
551
+			$sql .= ", ".(!empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null");
552
+			$sql .= ", 0";
553
+			$sql .= ", ".(int) $this->fk_incoterms;
554
+			$sql .= ", '".$this->db->escape($this->location_incoterms)."'";
555
+			$sql .= ", ".(!empty($this->import_key) ? "'".$this->db->escape($this->import_key)."'" : "null");
556
+			$sql .= ", ".(int) $this->fk_multicurrency;
557
+			$sql .= ", '".$this->db->escape($this->multicurrency_code)."')";
558 558
 
559 559
 			dol_syslog(get_class($this)."::create", LOG_DEBUG);
560
-			$result=$this->db->query($sql);
560
+			$result = $this->db->query($sql);
561 561
 			if ($result)
562 562
 			{
563 563
 				$this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe");
564 564
 
565
-				$ret = $this->update($this->id,$user,0,1,1,'add');
565
+				$ret = $this->update($this->id, $user, 0, 1, 1, 'add');
566 566
 
567 567
 				// Ajout du commercial affecte
568 568
 				if ($this->commercial_id != '' && $this->commercial_id != -1)
@@ -578,13 +578,13 @@  discard block
 block discarded – undo
578 578
 				if ($ret >= 0)
579 579
 				{
580 580
 					// Call trigger
581
-					$result=$this->call_trigger('COMPANY_CREATE',$user);
581
+					$result = $this->call_trigger('COMPANY_CREATE', $user);
582 582
 					if ($result < 0) $error++;
583 583
 					// End call triggers
584 584
 				}
585 585
 				else $error++;
586 586
 
587
-				if (! $error)
587
+				if (!$error)
588 588
 				{
589 589
 					dol_syslog(get_class($this)."::Create success id=".$this->id);
590 590
 					$this->db->commit();
@@ -592,7 +592,7 @@  discard block
 block discarded – undo
592 592
 				}
593 593
 				else
594 594
 				{
595
-					dol_syslog(get_class($this)."::Create echec update ".$this->error." ".join(',',$this->errors), LOG_ERR);
595
+					dol_syslog(get_class($this)."::Create echec update ".$this->error." ".join(',', $this->errors), LOG_ERR);
596 596
 					$this->db->rollback();
597 597
 					return -4;
598 598
 				}
@@ -601,13 +601,13 @@  discard block
 block discarded – undo
601 601
 			{
602 602
 				if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
603 603
 				{
604
-					$this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->name);    // duplicate on a field (code or profid or ...)
605
-					$result=-1;
604
+					$this->error = $langs->trans("ErrorCompanyNameAlreadyExists", $this->name); // duplicate on a field (code or profid or ...)
605
+					$result = -1;
606 606
 				}
607 607
 				else
608 608
 				{
609
-					$this->error=$this->db->lasterror();
610
-					$result=-2;
609
+					$this->error = $this->db->lasterror();
610
+					$result = -2;
611 611
 				}
612 612
 				$this->db->rollback();
613 613
 				return $result;
@@ -616,7 +616,7 @@  discard block
 block discarded – undo
616 616
 		else
617 617
 		{
618 618
 			$this->db->rollback();
619
-			dol_syslog(get_class($this)."::Create fails verify ".join(',',$this->errors), LOG_WARNING);
619
+			dol_syslog(get_class($this)."::Create fails verify ".join(',', $this->errors), LOG_WARNING);
620 620
 			return -3;
621 621
 		}
622 622
 	}
@@ -633,12 +633,12 @@  discard block
 block discarded – undo
633 633
 	{
634 634
         // phpcs:enable
635 635
 		require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
636
-		$contact=new Contact($this->db);
636
+		$contact = new Contact($this->db);
637 637
 
638 638
 		$contact->name              = $this->name_bis;
639 639
 		$contact->firstname         = $this->firstname;
640 640
 		$contact->civility_id       = $this->civility_id;
641
-		$contact->socid             = $this->id;	// fk_soc
641
+		$contact->socid             = $this->id; // fk_soc
642 642
 		$contact->statut            = 1;
643 643
 		$contact->priv              = 0;
644 644
 		$contact->country_id        = $this->country_id;
@@ -654,7 +654,7 @@  discard block
 block discarded – undo
654 654
 		{
655 655
 			$this->error = $contact->error;
656 656
 			$this->errors = $contact->errors;
657
-			dol_syslog(get_class($this)."::create_individual ERROR:" . $this->error, LOG_ERR);
657
+			dol_syslog(get_class($this)."::create_individual ERROR:".$this->error, LOG_ERR);
658 658
 		}
659 659
 
660 660
 		return $result;
@@ -671,13 +671,13 @@  discard block
 block discarded – undo
671 671
 		global $conf, $langs, $mysoc;
672 672
 
673 673
 		$error = 0;
674
-		$this->errors=array();
674
+		$this->errors = array();
675 675
 
676 676
 		$result = 0;
677
-		$this->name	= trim($this->name);
678
-		$this->nom=$this->name; // For backward compatibility
677
+		$this->name = trim($this->name);
678
+		$this->nom = $this->name; // For backward compatibility
679 679
 
680
-		if (! $this->name)
680
+		if (!$this->name)
681 681
 		{
682 682
 			$this->errors[] = 'ErrorBadThirdPartyName';
683 683
 			$result = -2;
@@ -734,12 +734,12 @@  discard block
 block discarded – undo
734 734
 		}
735 735
 
736 736
 		// Check for duplicate or mandatory fields defined into setup
737
-		$array_to_check=array('IDPROF1','IDPROF2','IDPROF3','IDPROF4','IDPROF5','IDPROF6','EMAIL');
738
-		foreach($array_to_check as $key)
737
+		$array_to_check = array('IDPROF1', 'IDPROF2', 'IDPROF3', 'IDPROF4', 'IDPROF5', 'IDPROF6', 'EMAIL');
738
+		foreach ($array_to_check as $key)
739 739
 		{
740
-			$keymin=strtolower($key);
741
-			$i=(int) preg_replace('/[^0-9]/','',$key);
742
-			$vallabel=$this->$keymin;
740
+			$keymin = strtolower($key);
741
+			$i = (int) preg_replace('/[^0-9]/', '', $key);
742
+			$vallabel = $this->$keymin;
743 743
 
744 744
 			if ($i > 0)
745 745
 			{
@@ -758,8 +758,8 @@  discard block
 block discarded – undo
758 758
 					// Check for mandatory prof id (but only if country is other than ours)
759 759
 					if ($mysoc->country_id > 0 && $this->country_id == $mysoc->country_id)
760 760
 					{
761
-						$idprof_mandatory ='SOCIETE_'.$key.'_MANDATORY';
762
-						if (! $vallabel && ! empty($conf->global->$idprof_mandatory))
761
+						$idprof_mandatory = 'SOCIETE_'.$key.'_MANDATORY';
762
+						if (!$vallabel && !empty($conf->global->$idprof_mandatory))
763 763
 						{
764 764
 							$langs->load("errors");
765 765
 							$error++;
@@ -775,7 +775,7 @@  discard block
 block discarded – undo
775 775
 				if ($key == 'EMAIL')
776 776
 				{
777 777
 					// Check for unicity
778
-					if ($vallabel && ! empty($conf->global->SOCIETE_EMAIL_UNIQUE))
778
+					if ($vallabel && !empty($conf->global->SOCIETE_EMAIL_UNIQUE))
779 779
 					{
780 780
 						if ($this->id_prof_exists($keymin, $vallabel, ($this->id > 0 ? $this->id : 0)))
781 781
 						{
@@ -785,7 +785,7 @@  discard block
 block discarded – undo
785 785
 					}
786 786
 
787 787
 					// Check for mandatory
788
-					if (! empty($conf->global->SOCIETE_EMAIL_MANDATORY) && ! isValidEMail($this->email))
788
+					if (!empty($conf->global->SOCIETE_EMAIL_MANDATORY) && !isValidEMail($this->email))
789 789
 					{
790 790
 						$langs->load("errors");
791 791
 						$error++;
@@ -812,58 +812,58 @@  discard block
 block discarded – undo
812 812
 	 *		@param	int		$nosyncmember				Do not synchronize info of linked member
813 813
 	 *      @return int  			           			<0 if KO, >=0 if OK
814 814
 	 */
815
-	function update($id, $user='', $call_trigger=1, $allowmodcodeclient=0, $allowmodcodefournisseur=0, $action='update', $nosyncmember=1)
815
+	function update($id, $user = '', $call_trigger = 1, $allowmodcodeclient = 0, $allowmodcodefournisseur = 0, $action = 'update', $nosyncmember = 1)
816 816
 	{
817
-		global $langs,$conf,$hookmanager;
817
+		global $langs, $conf, $hookmanager;
818 818
 
819 819
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
820 820
 
821 821
 		if (empty($id)) $id = $this->id;
822 822
 
823
-		$error=0;
823
+		$error = 0;
824 824
 
825 825
 		dol_syslog(get_class($this)."::Update id=".$id." call_trigger=".$call_trigger." allowmodcodeclient=".$allowmodcodeclient." allowmodcodefournisseur=".$allowmodcodefournisseur);
826 826
 
827
-		$now=dol_now();
827
+		$now = dol_now();
828 828
 
829 829
 		// Clean parameters
830
-		$this->id			= $id;
831
-		$this->entity		= ((isset($this->entity) && is_numeric($this->entity))?$this->entity:$conf->entity);
832
-		$this->name			= $this->name?trim($this->name):trim($this->nom);
833
-		$this->nom			= $this->name;	// For backward compatibility
834
-		$this->name_alias	= trim($this->name_alias);
830
+		$this->id = $id;
831
+		$this->entity = ((isset($this->entity) && is_numeric($this->entity)) ? $this->entity : $conf->entity);
832
+		$this->name = $this->name ?trim($this->name) : trim($this->nom);
833
+		$this->nom = $this->name; // For backward compatibility
834
+		$this->name_alias = trim($this->name_alias);
835 835
 		$this->ref_ext		= trim($this->ref_ext);
836
-		$this->address		= $this->address?trim($this->address):trim($this->address);
837
-		$this->zip			= $this->zip?trim($this->zip):trim($this->zip);
838
-		$this->town			= $this->town?trim($this->town):trim($this->town);
839
-		$this->state_id		= trim($this->state_id);
840
-		$this->country_id	= ($this->country_id > 0)?$this->country_id:0;
836
+		$this->address		= $this->address ?trim($this->address) : trim($this->address);
837
+		$this->zip = $this->zip ?trim($this->zip) : trim($this->zip);
838
+		$this->town			= $this->town ?trim($this->town) : trim($this->town);
839
+		$this->state_id = trim($this->state_id);
840
+		$this->country_id = ($this->country_id > 0) ? $this->country_id : 0;
841 841
 		$this->phone		= trim($this->phone);
842
-		$this->phone		= preg_replace("/\s/","",$this->phone);
843
-		$this->phone		= preg_replace("/\./","",$this->phone);
842
+		$this->phone		= preg_replace("/\s/", "", $this->phone);
843
+		$this->phone		= preg_replace("/\./", "", $this->phone);
844 844
 		$this->fax			= trim($this->fax);
845
-		$this->fax			= preg_replace("/\s/","",$this->fax);
846
-		$this->fax			= preg_replace("/\./","",$this->fax);
845
+		$this->fax			= preg_replace("/\s/", "", $this->fax);
846
+		$this->fax			= preg_replace("/\./", "", $this->fax);
847 847
 		$this->email		= trim($this->email);
848 848
 		$this->skype		= trim($this->skype);
849
-		$this->twitter		= trim($this->twitter);
850
-		$this->facebook		= trim($this->facebook);
851
-		$this->url			= $this->url?clean_url($this->url,0):'';
849
+		$this->twitter = trim($this->twitter);
850
+		$this->facebook = trim($this->facebook);
851
+		$this->url = $this->url ?clean_url($this->url, 0) : '';
852 852
 		$this->note_private = trim($this->note_private);
853 853
 		$this->note_public  = trim($this->note_public);
854 854
 		$this->idprof1		= trim($this->idprof1);
855 855
 		$this->idprof2		= trim($this->idprof2);
856 856
 		$this->idprof3		= trim($this->idprof3);
857 857
 		$this->idprof4		= trim($this->idprof4);
858
-		$this->idprof5		= (! empty($this->idprof5)?trim($this->idprof5):'');
859
-		$this->idprof6		= (! empty($this->idprof6)?trim($this->idprof6):'');
860
-		$this->prefix_comm	= trim($this->prefix_comm);
858
+		$this->idprof5		= (!empty($this->idprof5) ?trim($this->idprof5) : '');
859
+		$this->idprof6		= (!empty($this->idprof6) ?trim($this->idprof6) : '');
860
+		$this->prefix_comm = trim($this->prefix_comm);
861 861
 		$this->outstanding_limit = price2num($this->outstanding_limit);
862 862
 		$this->order_min_amount = price2num($this->order_min_amount);
863 863
 		$this->supplier_order_min_amount = price2num($this->supplier_order_min_amount);
864 864
 
865 865
 		$this->tva_assuj	= trim($this->tva_assuj);
866
-		$this->tva_intra	= dol_sanitizeFileName($this->tva_intra,'');
866
+		$this->tva_intra	= dol_sanitizeFileName($this->tva_intra, '');
867 867
 		if (empty($this->status)) $this->status = 0;
868 868
 
869 869
 		if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
@@ -874,64 +874,64 @@  discard block
 block discarded – undo
874 874
 		}
875 875
 
876 876
 		// Local taxes
877
-		$this->localtax1_assuj=trim($this->localtax1_assuj);
878
-		$this->localtax2_assuj=trim($this->localtax2_assuj);
877
+		$this->localtax1_assuj = trim($this->localtax1_assuj);
878
+		$this->localtax2_assuj = trim($this->localtax2_assuj);
879 879
 
880
-		$this->localtax1_value=trim($this->localtax1_value);
881
-		$this->localtax2_value=trim($this->localtax2_value);
880
+		$this->localtax1_value = trim($this->localtax1_value);
881
+		$this->localtax2_value = trim($this->localtax2_value);
882 882
 
883
-		if ($this->capital != '') $this->capital=price2num(trim($this->capital));
884
-		if (! is_numeric($this->capital)) $this->capital = '';     // '' = undef
883
+		if ($this->capital != '') $this->capital = price2num(trim($this->capital));
884
+		if (!is_numeric($this->capital)) $this->capital = ''; // '' = undef
885 885
 
886
-		$this->effectif_id=trim($this->effectif_id);
887
-		$this->forme_juridique_code=trim($this->forme_juridique_code);
886
+		$this->effectif_id = trim($this->effectif_id);
887
+		$this->forme_juridique_code = trim($this->forme_juridique_code);
888 888
 
889 889
 		//Gencod
890
-		$this->barcode=trim($this->barcode);
890
+		$this->barcode = trim($this->barcode);
891 891
 
892 892
 		// For automatic creation
893
-		if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this,0);
894
-		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this,1);
893
+		if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this, 0);
894
+		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this, 1);
895 895
 
896
-		$this->code_compta=trim($this->code_compta);
897
-		$this->code_compta_fournisseur=trim($this->code_compta_fournisseur);
896
+		$this->code_compta = trim($this->code_compta);
897
+		$this->code_compta_fournisseur = trim($this->code_compta_fournisseur);
898 898
 
899 899
 		// Check parameters. More tests are done later in the ->verify()
900
-		if (! is_numeric($this->client) && ! is_numeric($this->fournisseur))
900
+		if (!is_numeric($this->client) && !is_numeric($this->fournisseur))
901 901
 		{
902 902
 			$langs->load("errors");
903 903
 			$this->error = $langs->trans("BadValueForParameterClientOrSupplier");
904 904
 			return -1;
905 905
 		}
906 906
 
907
-		$customer=false;
908
-		if (! empty($allowmodcodeclient) && ! empty($this->client))
907
+		$customer = false;
908
+		if (!empty($allowmodcodeclient) && !empty($this->client))
909 909
 		{
910 910
 			// Attention get_codecompta peut modifier le code suivant le module utilise
911 911
 			if (empty($this->code_compta))
912 912
 			{
913
-				$ret=$this->get_codecompta('customer');
913
+				$ret = $this->get_codecompta('customer');
914 914
 				if ($ret < 0) return -1;
915 915
 			}
916 916
 
917
-			$customer=true;
917
+			$customer = true;
918 918
 		}
919 919
 
920
-		$supplier=false;
921
-		if (! empty($allowmodcodefournisseur) && ! empty($this->fournisseur))
920
+		$supplier = false;
921
+		if (!empty($allowmodcodefournisseur) && !empty($this->fournisseur))
922 922
 		{
923 923
 			// Attention get_codecompta peut modifier le code suivant le module utilise
924 924
 			if (empty($this->code_compta_fournisseur))
925 925
 			{
926
-				$ret=$this->get_codecompta('supplier');
926
+				$ret = $this->get_codecompta('supplier');
927 927
 				if ($ret < 0) return -1;
928 928
 			}
929 929
 
930
-			$supplier=true;
930
+			$supplier = true;
931 931
 		}
932 932
 
933 933
 		//Web services
934
-		$this->webservices_url = $this->webservices_url?clean_url($this->webservices_url,0):'';
934
+		$this->webservices_url = $this->webservices_url ?clean_url($this->webservices_url, 0) : '';
935 935
 		$this->webservices_key = trim($this->webservices_key);
936 936
 
937 937
 		//Incoterms
@@ -955,11 +955,11 @@  discard block
 block discarded – undo
955 955
 			{
956 956
 				if (in_array('ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client)
957 957
 				{
958
-					if (($key = array_search('ErrorBadCustomerCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]);	// Remove error message
958
+					if (($key = array_search('ErrorBadCustomerCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]); // Remove error message
959 959
 				}
960 960
 				if (in_array('ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur)
961 961
 				{
962
-					if (($key = array_search('ErrorBadSupplierCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]);	// Remove error message
962
+					if (($key = array_search('ErrorBadSupplierCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]); // Remove error message
963 963
 				}
964 964
 				if (empty($this->errors))	// If there is no more error, we can make like if there is no error at all
965 965
 				{
@@ -973,118 +973,118 @@  discard block
 block discarded – undo
973 973
 			dol_syslog(get_class($this)."::update verify ok or not done");
974 974
 
975 975
 			$sql  = "UPDATE ".MAIN_DB_PREFIX."societe SET ";
976
-			$sql .= "entity = " . $this->db->escape($this->entity);
977
-			$sql .= ",nom = '" . $this->db->escape($this->name) ."'"; // Required
978
-			$sql .= ",name_alias = '" . $this->db->escape($this->name_alias) ."'";
979
-			$sql .= ",ref_ext = " .(! empty($this->ref_ext)?"'".$this->db->escape($this->ref_ext) ."'":"null");
980
-			$sql .= ",address = '" . $this->db->escape($this->address) ."'";
981
-
982
-			$sql .= ",zip = ".(! empty($this->zip)?"'".$this->db->escape($this->zip)."'":"null");
983
-			$sql .= ",town = ".(! empty($this->town)?"'".$this->db->escape($this->town)."'":"null");
984
-
985
-			$sql .= ",fk_departement = '" . (! empty($this->state_id)?$this->state_id:'0') ."'";
986
-			$sql .= ",fk_pays = '" . (! empty($this->country_id)?$this->country_id:'0') ."'";
987
-
988
-			$sql .= ",phone = ".(! empty($this->phone)?"'".$this->db->escape($this->phone)."'":"null");
989
-			$sql .= ",fax = ".(! empty($this->fax)?"'".$this->db->escape($this->fax)."'":"null");
990
-			$sql .= ",email = ".(! empty($this->email)?"'".$this->db->escape($this->email)."'":"null");
991
-			$sql .= ",skype = ".(! empty($this->skype)?"'".$this->db->escape($this->skype)."'":"null");
992
-			$sql .= ",twitter = ".(! empty($this->twitter)?"'".$this->db->escape($this->twitter)."'":"null");
993
-			$sql .= ",facebook = ".(! empty($this->facebook)?"'".$this->db->escape($this->facebook)."'":"null");
994
-			$sql .= ",url = ".(! empty($this->url)?"'".$this->db->escape($this->url)."'":"null");
995
-
996
-			$sql .= ",parent = " . ($this->parent > 0 ? $this->parent : "null");
997
-
998
-			$sql .= ",note_private = ".(! empty($this->note_private)?"'".$this->db->escape($this->note_private)."'":"null");
999
-			$sql .= ",note_public = ".(! empty($this->note_public)?"'".$this->db->escape($this->note_public)."'":"null");
1000
-
1001
-			$sql .= ",siren   = '". $this->db->escape($this->idprof1) ."'";
1002
-			$sql .= ",siret   = '". $this->db->escape($this->idprof2) ."'";
1003
-			$sql .= ",ape     = '". $this->db->escape($this->idprof3) ."'";
1004
-			$sql .= ",idprof4 = '". $this->db->escape($this->idprof4) ."'";
1005
-			$sql .= ",idprof5 = '". $this->db->escape($this->idprof5) ."'";
1006
-			$sql .= ",idprof6 = '". $this->db->escape($this->idprof6) ."'";
1007
-
1008
-			$sql .= ",tva_assuj = ".($this->tva_assuj!=''?"'".$this->db->escape($this->tva_assuj)."'":"null");
1009
-			$sql .= ",tva_intra = '" . $this->db->escape($this->tva_intra) ."'";
1010
-			$sql .= ",status = " .$this->status;
976
+			$sql .= "entity = ".$this->db->escape($this->entity);
977
+			$sql .= ",nom = '".$this->db->escape($this->name)."'"; // Required
978
+			$sql .= ",name_alias = '".$this->db->escape($this->name_alias)."'";
979
+			$sql .= ",ref_ext = ".(!empty($this->ref_ext) ? "'".$this->db->escape($this->ref_ext)."'" : "null");
980
+			$sql .= ",address = '".$this->db->escape($this->address)."'";
981
+
982
+			$sql .= ",zip = ".(!empty($this->zip) ? "'".$this->db->escape($this->zip)."'" : "null");
983
+			$sql .= ",town = ".(!empty($this->town) ? "'".$this->db->escape($this->town)."'" : "null");
984
+
985
+			$sql .= ",fk_departement = '".(!empty($this->state_id) ? $this->state_id : '0')."'";
986
+			$sql .= ",fk_pays = '".(!empty($this->country_id) ? $this->country_id : '0')."'";
987
+
988
+			$sql .= ",phone = ".(!empty($this->phone) ? "'".$this->db->escape($this->phone)."'" : "null");
989
+			$sql .= ",fax = ".(!empty($this->fax) ? "'".$this->db->escape($this->fax)."'" : "null");
990
+			$sql .= ",email = ".(!empty($this->email) ? "'".$this->db->escape($this->email)."'" : "null");
991
+			$sql .= ",skype = ".(!empty($this->skype) ? "'".$this->db->escape($this->skype)."'" : "null");
992
+			$sql .= ",twitter = ".(!empty($this->twitter) ? "'".$this->db->escape($this->twitter)."'" : "null");
993
+			$sql .= ",facebook = ".(!empty($this->facebook) ? "'".$this->db->escape($this->facebook)."'" : "null");
994
+			$sql .= ",url = ".(!empty($this->url) ? "'".$this->db->escape($this->url)."'" : "null");
995
+
996
+			$sql .= ",parent = ".($this->parent > 0 ? $this->parent : "null");
997
+
998
+			$sql .= ",note_private = ".(!empty($this->note_private) ? "'".$this->db->escape($this->note_private)."'" : "null");
999
+			$sql .= ",note_public = ".(!empty($this->note_public) ? "'".$this->db->escape($this->note_public)."'" : "null");
1000
+
1001
+			$sql .= ",siren   = '".$this->db->escape($this->idprof1)."'";
1002
+			$sql .= ",siret   = '".$this->db->escape($this->idprof2)."'";
1003
+			$sql .= ",ape     = '".$this->db->escape($this->idprof3)."'";
1004
+			$sql .= ",idprof4 = '".$this->db->escape($this->idprof4)."'";
1005
+			$sql .= ",idprof5 = '".$this->db->escape($this->idprof5)."'";
1006
+			$sql .= ",idprof6 = '".$this->db->escape($this->idprof6)."'";
1007
+
1008
+			$sql .= ",tva_assuj = ".($this->tva_assuj != '' ? "'".$this->db->escape($this->tva_assuj)."'" : "null");
1009
+			$sql .= ",tva_intra = '".$this->db->escape($this->tva_intra)."'";
1010
+			$sql .= ",status = ".$this->status;
1011 1011
 
1012 1012
 			// Local taxes
1013
-			$sql .= ",localtax1_assuj = ".($this->localtax1_assuj!=''?"'".$this->db->escape($this->localtax1_assuj)."'":"null");
1014
-			$sql .= ",localtax2_assuj = ".($this->localtax2_assuj!=''?"'".$this->db->escape($this->localtax2_assuj)."'":"null");
1015
-			if($this->localtax1_assuj==1)
1013
+			$sql .= ",localtax1_assuj = ".($this->localtax1_assuj != '' ? "'".$this->db->escape($this->localtax1_assuj)."'" : "null");
1014
+			$sql .= ",localtax2_assuj = ".($this->localtax2_assuj != '' ? "'".$this->db->escape($this->localtax2_assuj)."'" : "null");
1015
+			if ($this->localtax1_assuj == 1)
1016 1016
 			{
1017
-				if($this->localtax1_value!='')
1017
+				if ($this->localtax1_value != '')
1018 1018
 				{
1019
-					$sql .=",localtax1_value =".$this->localtax1_value;
1019
+					$sql .= ",localtax1_value =".$this->localtax1_value;
1020 1020
 				}
1021
-				else $sql .=",localtax1_value =0.000";
1021
+				else $sql .= ",localtax1_value =0.000";
1022 1022
 			}
1023
-			else $sql .=",localtax1_value =0.000";
1023
+			else $sql .= ",localtax1_value =0.000";
1024 1024
 
1025
-			if($this->localtax2_assuj==1)
1025
+			if ($this->localtax2_assuj == 1)
1026 1026
 			{
1027
-				if($this->localtax2_value!='')
1027
+				if ($this->localtax2_value != '')
1028 1028
 				{
1029
-					$sql .=",localtax2_value =".$this->localtax2_value;
1029
+					$sql .= ",localtax2_value =".$this->localtax2_value;
1030 1030
 				}
1031
-				else $sql .=",localtax2_value =0.000";
1031
+				else $sql .= ",localtax2_value =0.000";
1032 1032
 			}
1033
-			else $sql .=",localtax2_value =0.000";
1033
+			else $sql .= ",localtax2_value =0.000";
1034 1034
 
1035 1035
 			$sql .= ",capital = ".($this->capital == '' ? "null" : $this->capital);
1036 1036
 
1037
-			$sql .= ",prefix_comm = ".(! empty($this->prefix_comm)?"'".$this->db->escape($this->prefix_comm)."'":"null");
1037
+			$sql .= ",prefix_comm = ".(!empty($this->prefix_comm) ? "'".$this->db->escape($this->prefix_comm)."'" : "null");
1038 1038
 
1039
-			$sql .= ",fk_effectif = ".(! empty($this->effectif_id)?"'".$this->db->escape($this->effectif_id)."'":"null");
1039
+			$sql .= ",fk_effectif = ".(!empty($this->effectif_id) ? "'".$this->db->escape($this->effectif_id)."'" : "null");
1040 1040
 			if (isset($this->stcomm_id))
1041 1041
 			{
1042
-				$sql .= ",fk_stcomm=".(!empty($this->stcomm_id)  ? $this->stcomm_id : "0");
1042
+				$sql .= ",fk_stcomm=".(!empty($this->stcomm_id) ? $this->stcomm_id : "0");
1043 1043
 			}
1044
-			$sql .= ",fk_typent = ".(! empty($this->typent_id)?"'".$this->db->escape($this->typent_id)."'":"0");
1045
-
1046
-			$sql .= ",fk_forme_juridique = ".(! empty($this->forme_juridique_code)?"'".$this->db->escape($this->forme_juridique_code)."'":"null");
1047
-
1048
-			$sql .= ",mode_reglement = ".(! empty($this->mode_reglement_id)?"'".$this->db->escape($this->mode_reglement_id)."'":"null");
1049
-			$sql .= ",cond_reglement = ".(! empty($this->cond_reglement_id)?"'".$this->db->escape($this->cond_reglement_id)."'":"null");
1050
-			$sql .= ",mode_reglement_supplier = ".(! empty($this->mode_reglement_supplier_id)?"'".$this->db->escape($this->mode_reglement_supplier_id)."'":"null");
1051
-			$sql .= ",cond_reglement_supplier = ".(! empty($this->cond_reglement_supplier_id)?"'".$this->db->escape($this->cond_reglement_supplier_id)."'":"null");
1052
-			$sql .= ",fk_shipping_method = ".(! empty($this->shipping_method_id)?"'".$this->db->escape($this->shipping_method_id)."'":"null");
1053
-
1054
-			$sql .= ",client = " . (! empty($this->client)?$this->client:0);
1055
-			$sql .= ",fournisseur = " . (! empty($this->fournisseur)?$this->fournisseur:0);
1056
-			$sql .= ",barcode = ".(! empty($this->barcode)?"'".$this->db->escape($this->barcode)."'":"null");
1057
-			$sql .= ",default_lang = ".(! empty($this->default_lang)?"'".$this->db->escape($this->default_lang)."'":"null");
1058
-			$sql .= ",logo = ".(! empty($this->logo)?"'".$this->db->escape($this->logo)."'":"null");
1059
-			$sql .= ",outstanding_limit= ".($this->outstanding_limit!=''?$this->outstanding_limit:'null');
1060
-			$sql .= ",order_min_amount= ".($this->order_min_amount!=''?$this->order_min_amount:'null');
1061
-			$sql .= ",supplier_order_min_amount= ".($this->supplier_order_min_amount!=''?$this->supplier_order_min_amount:'null');
1044
+			$sql .= ",fk_typent = ".(!empty($this->typent_id) ? "'".$this->db->escape($this->typent_id)."'" : "0");
1045
+
1046
+			$sql .= ",fk_forme_juridique = ".(!empty($this->forme_juridique_code) ? "'".$this->db->escape($this->forme_juridique_code)."'" : "null");
1047
+
1048
+			$sql .= ",mode_reglement = ".(!empty($this->mode_reglement_id) ? "'".$this->db->escape($this->mode_reglement_id)."'" : "null");
1049
+			$sql .= ",cond_reglement = ".(!empty($this->cond_reglement_id) ? "'".$this->db->escape($this->cond_reglement_id)."'" : "null");
1050
+			$sql .= ",mode_reglement_supplier = ".(!empty($this->mode_reglement_supplier_id) ? "'".$this->db->escape($this->mode_reglement_supplier_id)."'" : "null");
1051
+			$sql .= ",cond_reglement_supplier = ".(!empty($this->cond_reglement_supplier_id) ? "'".$this->db->escape($this->cond_reglement_supplier_id)."'" : "null");
1052
+			$sql .= ",fk_shipping_method = ".(!empty($this->shipping_method_id) ? "'".$this->db->escape($this->shipping_method_id)."'" : "null");
1053
+
1054
+			$sql .= ",client = ".(!empty($this->client) ? $this->client : 0);
1055
+			$sql .= ",fournisseur = ".(!empty($this->fournisseur) ? $this->fournisseur : 0);
1056
+			$sql .= ",barcode = ".(!empty($this->barcode) ? "'".$this->db->escape($this->barcode)."'" : "null");
1057
+			$sql .= ",default_lang = ".(!empty($this->default_lang) ? "'".$this->db->escape($this->default_lang)."'" : "null");
1058
+			$sql .= ",logo = ".(!empty($this->logo) ? "'".$this->db->escape($this->logo)."'" : "null");
1059
+			$sql .= ",outstanding_limit= ".($this->outstanding_limit != '' ? $this->outstanding_limit : 'null');
1060
+			$sql .= ",order_min_amount= ".($this->order_min_amount != '' ? $this->order_min_amount : 'null');
1061
+			$sql .= ",supplier_order_min_amount= ".($this->supplier_order_min_amount != '' ? $this->supplier_order_min_amount : 'null');
1062 1062
 			$sql .= ",fk_prospectlevel='".$this->db->escape($this->fk_prospectlevel)."'";
1063 1063
 
1064
-			$sql .= ",webservices_url = ".(! empty($this->webservices_url)?"'".$this->db->escape($this->webservices_url)."'":"null");
1065
-			$sql .= ",webservices_key = ".(! empty($this->webservices_key)?"'".$this->db->escape($this->webservices_key)."'":"null");
1064
+			$sql .= ",webservices_url = ".(!empty($this->webservices_url) ? "'".$this->db->escape($this->webservices_url)."'" : "null");
1065
+			$sql .= ",webservices_key = ".(!empty($this->webservices_key) ? "'".$this->db->escape($this->webservices_key)."'" : "null");
1066 1066
 
1067 1067
 			//Incoterms
1068
-			$sql.= ", fk_incoterms = ".$this->fk_incoterms;
1069
-			$sql.= ", location_incoterms = ".(! empty($this->location_incoterms)?"'".$this->db->escape($this->location_incoterms)."'":"null");
1068
+			$sql .= ", fk_incoterms = ".$this->fk_incoterms;
1069
+			$sql .= ", location_incoterms = ".(!empty($this->location_incoterms) ? "'".$this->db->escape($this->location_incoterms)."'" : "null");
1070 1070
 
1071 1071
 			if ($customer)
1072 1072
 			{
1073
-				$sql .= ", code_client = ".(! empty($this->code_client)?"'".$this->db->escape($this->code_client)."'":"null");
1074
-				$sql .= ", code_compta = ".(! empty($this->code_compta)?"'".$this->db->escape($this->code_compta)."'":"null");
1073
+				$sql .= ", code_client = ".(!empty($this->code_client) ? "'".$this->db->escape($this->code_client)."'" : "null");
1074
+				$sql .= ", code_compta = ".(!empty($this->code_compta) ? "'".$this->db->escape($this->code_compta)."'" : "null");
1075 1075
 			}
1076 1076
 
1077 1077
 			if ($supplier)
1078 1078
 			{
1079
-				$sql .= ", code_fournisseur = ".(! empty($this->code_fournisseur)?"'".$this->db->escape($this->code_fournisseur)."'":"null");
1080
-				$sql .= ", code_compta_fournisseur = ".(! empty($this->code_compta_fournisseur)?"'".$this->db->escape($this->code_compta_fournisseur)."'":"null");
1079
+				$sql .= ", code_fournisseur = ".(!empty($this->code_fournisseur) ? "'".$this->db->escape($this->code_fournisseur)."'" : "null");
1080
+				$sql .= ", code_compta_fournisseur = ".(!empty($this->code_compta_fournisseur) ? "'".$this->db->escape($this->code_compta_fournisseur)."'" : "null");
1081 1081
 			}
1082
-			$sql .= ", fk_user_modif = ".($user->id > 0 ? $user->id:"null");
1082
+			$sql .= ", fk_user_modif = ".($user->id > 0 ? $user->id : "null");
1083 1083
 			$sql .= ", fk_multicurrency = ".(int) $this->fk_multicurrency;
1084 1084
 			$sql .= ", multicurrency_code = '".$this->db->escape($this->multicurrency_code)."'";
1085
-			$sql .= " WHERE rowid = " . (int) $id;
1085
+			$sql .= " WHERE rowid = ".(int) $id;
1086 1086
 
1087
-			$resql=$this->db->query($sql);
1087
+			$resql = $this->db->query($sql);
1088 1088
 			if ($resql)
1089 1089
 			{
1090 1090
 				if (is_object($this->oldcopy))	// If we have information on old values
@@ -1102,7 +1102,7 @@  discard block
 block discarded – undo
1102 1102
 				}
1103 1103
 				else
1104 1104
 				{
1105
-					unset($this->country_code);	// We clean this, in the doubt, because it may have been changed after an update of country_id
1105
+					unset($this->country_code); // We clean this, in the doubt, because it may have been changed after an update of country_id
1106 1106
 					unset($this->country);
1107 1107
 					unset($this->state_code);
1108 1108
 					unset($this->state);
@@ -1110,67 +1110,67 @@  discard block
 block discarded – undo
1110 1110
 
1111 1111
 				$nbrowsaffected = $this->db->affected_rows($resql);
1112 1112
 
1113
-				if (! $error && $nbrowsaffected)
1113
+				if (!$error && $nbrowsaffected)
1114 1114
 				{
1115 1115
 					// Update information on linked member if it is an update
1116
-					if (! $nosyncmember && ! empty($conf->adherent->enabled))
1116
+					if (!$nosyncmember && !empty($conf->adherent->enabled))
1117 1117
 					{
1118 1118
 						require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
1119 1119
 
1120 1120
 						dol_syslog(get_class($this)."::update update linked member");
1121 1121
 
1122
-						$lmember=new Adherent($this->db);
1123
-						$result=$lmember->fetch(0, 0, $this->id);
1122
+						$lmember = new Adherent($this->db);
1123
+						$result = $lmember->fetch(0, 0, $this->id);
1124 1124
 
1125 1125
 						if ($result > 0)
1126 1126
 						{
1127
-							$lmember->societe=$this->name;
1127
+							$lmember->societe = $this->name;
1128 1128
 							//$lmember->firstname=$this->firstname?$this->firstname:$lmember->firstname;	// We keep firstname and lastname of member unchanged
1129 1129
 							//$lmember->lastname=$this->lastname?$this->lastname:$lmember->lastname;		// We keep firstname and lastname of member unchanged
1130
-							$lmember->address=$this->address;
1131
-							$lmember->email=$this->email;
1132
-							$lmember->skype=$this->skype;
1133
-							$lmember->twitter=$this->twitter;
1134
-							$lmember->facebook=$this->facebook;
1135
-							$lmember->phone=$this->phone;
1136
-
1137
-							$result=$lmember->update($user,0,1,1,1);	// Use nosync to 1 to avoid cyclic updates
1130
+							$lmember->address = $this->address;
1131
+							$lmember->email = $this->email;
1132
+							$lmember->skype = $this->skype;
1133
+							$lmember->twitter = $this->twitter;
1134
+							$lmember->facebook = $this->facebook;
1135
+							$lmember->phone = $this->phone;
1136
+
1137
+							$result = $lmember->update($user, 0, 1, 1, 1); // Use nosync to 1 to avoid cyclic updates
1138 1138
 							if ($result < 0)
1139 1139
 							{
1140
-								$this->error=$lmember->error;
1141
-								dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
1140
+								$this->error = $lmember->error;
1141
+								dol_syslog(get_class($this)."::update ".$this->error, LOG_ERR);
1142 1142
 								$error++;
1143 1143
 							}
1144 1144
 						}
1145 1145
 						elseif ($result < 0)
1146 1146
 						{
1147
-							$this->error=$lmember->error;
1147
+							$this->error = $lmember->error;
1148 1148
 							$error++;
1149 1149
 						}
1150 1150
 					}
1151 1151
 				}
1152 1152
 
1153
-				$action='update';
1153
+				$action = 'update';
1154 1154
 
1155 1155
 				// Actions on extra fields
1156
-				if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
1156
+				if (!$error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
1157 1157
 				{
1158
-					$result=$this->insertExtraFields();
1158
+					$result = $this->insertExtraFields();
1159 1159
 					if ($result < 0)
1160 1160
 					{
1161 1161
 						$error++;
1162 1162
 					}
1163 1163
 				}
1164 1164
 
1165
-				if (! $error && $call_trigger)
1165
+				if (!$error && $call_trigger)
1166 1166
 				{
1167 1167
 					// Call trigger
1168
-					$result=$this->call_trigger('COMPANY_MODIFY',$user);
1168
+					$result = $this->call_trigger('COMPANY_MODIFY', $user);
1169 1169
 					if ($result < 0) $error++;
1170 1170
 					// End call triggers
1171 1171
 				}
1172 1172
 
1173
-				if (! $error)
1173
+				if (!$error)
1174 1174
 				{
1175 1175
 					dol_syslog(get_class($this)."::Update success");
1176 1176
 					$this->db->commit();
@@ -1202,7 +1202,7 @@  discard block
 block discarded – undo
1202 1202
 		else
1203 1203
 	   {
1204 1204
 			$this->db->rollback();
1205
-			dol_syslog(get_class($this)."::Update fails verify ".join(',',$this->errors), LOG_WARNING);
1205
+			dol_syslog(get_class($this)."::Update fails verify ".join(',', $this->errors), LOG_WARNING);
1206 1206
 			return -3;
1207 1207
 		}
1208 1208
 	}
@@ -1224,7 +1224,7 @@  discard block
 block discarded – undo
1224 1224
 	 *    @param    string	$ref_alias 		Name_alias of third party (Warning, this can return several records)
1225 1225
 	 *    @return   int						>0 if OK, <0 if KO or if two records found for same ref or idprof, 0 if not found.
1226 1226
 	 */
1227
-	function fetch($rowid, $ref='', $ref_ext='', $ref_int='', $idprof1='',$idprof2='',$idprof3='',$idprof4='',$idprof5='',$idprof6='', $email='', $ref_alias='')
1227
+	function fetch($rowid, $ref = '', $ref_ext = '', $ref_int = '', $idprof1 = '', $idprof2 = '', $idprof3 = '', $idprof4 = '', $idprof5 = '', $idprof6 = '', $email = '', $ref_alias = '')
1228 1228
 	{
1229 1229
 		global $langs;
1230 1230
 		global $conf;
@@ -1279,13 +1279,13 @@  discard block
 block discarded – undo
1279 1279
 		if ($idprof6)   $sql .= " AND s.idprof6 = '".$this->db->escape($idprof6)."'";
1280 1280
 		if ($email)     $sql .= " AND s.email = '".$this->db->escape($email)."'";
1281 1281
 
1282
-		$resql=$this->db->query($sql);
1282
+		$resql = $this->db->query($sql);
1283 1283
 		if ($resql)
1284 1284
 		{
1285
-			$num=$this->db->num_rows($resql);
1285
+			$num = $this->db->num_rows($resql);
1286 1286
 			if ($num > 1)
1287 1287
 			{
1288
-				$this->error='Fetch found several records. Rename one of tirdparties to avoid duplicate.';
1288
+				$this->error = 'Fetch found several records. Rename one of tirdparties to avoid duplicate.';
1289 1289
 				dol_syslog($this->error, LOG_ERR);
1290 1290
 				$result = -2;
1291 1291
 			}
@@ -1295,11 +1295,11 @@  discard block
 block discarded – undo
1295 1295
 
1296 1296
 				$this->id           = $obj->rowid;
1297 1297
 				$this->entity       = $obj->entity;
1298
-				$this->canvas		= $obj->canvas;
1298
+				$this->canvas = $obj->canvas;
1299 1299
 
1300 1300
 				$this->ref          = $obj->rowid;
1301
-				$this->name 		= $obj->name;
1302
-				$this->nom          = $obj->name;		// deprecated
1301
+				$this->name = $obj->name;
1302
+				$this->nom          = $obj->name; // deprecated
1303 1303
 				$this->name_alias = $obj->name_alias;
1304 1304
 				$this->ref_ext      = $obj->ref_ext;
1305 1305
 				$this->ref_int      = $obj->ref_int;
@@ -1309,22 +1309,22 @@  discard block
 block discarded – undo
1309 1309
 				$this->user_creation     = $obj->fk_user_creat;
1310 1310
 				$this->user_modification = $obj->fk_user_modif;
1311 1311
 
1312
-				$this->address 		= $obj->address;
1312
+				$this->address = $obj->address;
1313 1313
 				$this->zip 			= $obj->zip;
1314 1314
 				$this->town 		= $obj->town;
1315 1315
 
1316 1316
 				$this->country_id   = $obj->country_id;
1317
-				$this->country_code = $obj->country_id?$obj->country_code:'';
1318
-				$this->country 		= $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->transnoentities('Country'.$obj->country_code):$obj->country):'';
1317
+				$this->country_code = $obj->country_id ? $obj->country_code : '';
1318
+				$this->country = $obj->country_id ? ($langs->trans('Country'.$obj->country_code) != 'Country'.$obj->country_code ? $langs->transnoentities('Country'.$obj->country_code) : $obj->country) : '';
1319 1319
 
1320 1320
 				$this->state_id     = $obj->fk_departement;
1321 1321
 				$this->state_code   = $obj->state_code;
1322
-				$this->state        = ($obj->state!='-'?$obj->state:'');
1322
+				$this->state        = ($obj->state != '-' ? $obj->state : '');
1323 1323
 
1324
-				$transcode=$langs->trans('StatusProspect'.$obj->fk_stcomm);
1325
-				$libelle=($transcode!='StatusProspect'.$obj->fk_stcomm?$transcode:$obj->stcomm);
1326
-				$this->stcomm_id = $obj->fk_stcomm;     // id statut commercial
1327
-				$this->statut_commercial = $libelle;    // libelle statut commercial
1324
+				$transcode = $langs->trans('StatusProspect'.$obj->fk_stcomm);
1325
+				$libelle = ($transcode != 'StatusProspect'.$obj->fk_stcomm ? $transcode : $obj->stcomm);
1326
+				$this->stcomm_id = $obj->fk_stcomm; // id statut commercial
1327
+				$this->statut_commercial = $libelle; // libelle statut commercial
1328 1328
 
1329 1329
 				$this->email = $obj->email;
1330 1330
 				$this->skype = $obj->skype;
@@ -1334,7 +1334,7 @@  discard block
 block discarded – undo
1334 1334
 				$this->phone = $obj->phone;
1335 1335
 				$this->fax = $obj->fax;
1336 1336
 
1337
-				$this->parent    = $obj->parent;
1337
+				$this->parent = $obj->parent;
1338 1338
 
1339 1339
 				$this->idprof1		= $obj->idprof1;
1340 1340
 				$this->idprof2		= $obj->idprof2;
@@ -1343,7 +1343,7 @@  discard block
 block discarded – undo
1343 1343
 				$this->idprof5		= $obj->idprof5;
1344 1344
 				$this->idprof6		= $obj->idprof6;
1345 1345
 
1346
-				$this->capital   = $obj->capital;
1346
+				$this->capital = $obj->capital;
1347 1347
 
1348 1348
 				$this->code_client = $obj->code_client;
1349 1349
 				$this->code_fournisseur = $obj->code_fournisseur;
@@ -1368,23 +1368,23 @@  discard block
 block discarded – undo
1368 1368
 				$this->typent_code    = $obj->typent_code;
1369 1369
 
1370 1370
 				$this->effectif_id    = $obj->effectif_id;
1371
-				$this->effectif       = $obj->effectif_id?$obj->effectif:'';
1371
+				$this->effectif       = $obj->effectif_id ? $obj->effectif : '';
1372 1372
 
1373
-				$this->forme_juridique_code= $obj->forme_juridique_code;
1374
-				$this->forme_juridique     = $obj->forme_juridique_code?$obj->forme_juridique:'';
1373
+				$this->forme_juridique_code = $obj->forme_juridique_code;
1374
+				$this->forme_juridique     = $obj->forme_juridique_code ? $obj->forme_juridique : '';
1375 1375
 
1376 1376
 				$this->fk_prospectlevel = $obj->fk_prospectlevel;
1377 1377
 
1378 1378
 				$this->prefix_comm = $obj->prefix_comm;
1379 1379
 
1380
-				$this->remise_percent		= $obj->remise_client;
1381
-				$this->remise_supplier_percent		= $obj->remise_supplier;
1380
+				$this->remise_percent = $obj->remise_client;
1381
+				$this->remise_supplier_percent = $obj->remise_supplier;
1382 1382
 				$this->mode_reglement_id 	= $obj->mode_reglement;
1383 1383
 				$this->cond_reglement_id 	= $obj->cond_reglement;
1384 1384
 				$this->mode_reglement_supplier_id 	= $obj->mode_reglement_supplier;
1385 1385
 				$this->cond_reglement_supplier_id 	= $obj->cond_reglement_supplier;
1386
-				$this->shipping_method_id   = ($obj->fk_shipping_method>0)?$obj->fk_shipping_method:null;
1387
-				$this->fk_account			= $obj->fk_account;
1386
+				$this->shipping_method_id = ($obj->fk_shipping_method > 0) ? $obj->fk_shipping_method : null;
1387
+				$this->fk_account = $obj->fk_account;
1388 1388
 
1389 1389
 				$this->client      = $obj->client;
1390 1390
 				$this->fournisseur = $obj->fournisseur;
@@ -1401,7 +1401,7 @@  discard block
 block discarded – undo
1401 1401
 
1402 1402
 				$this->outstanding_limit		= $obj->outstanding_limit;
1403 1403
 				$this->order_min_amount			= $obj->order_min_amount;
1404
-				$this->supplier_order_min_amount	= $obj->supplier_order_min_amount;
1404
+				$this->supplier_order_min_amount = $obj->supplier_order_min_amount;
1405 1405
 
1406 1406
 				// multiprix
1407 1407
 				$this->price_level = $obj->price_level;
@@ -1431,12 +1431,12 @@  discard block
 block discarded – undo
1431 1431
 		}
1432 1432
 		else
1433 1433
 		{
1434
-			$this->error=$this->db->lasterror();
1434
+			$this->error = $this->db->lasterror();
1435 1435
 			$result = -3;
1436 1436
 		}
1437 1437
 
1438 1438
 		// Use first price level if level not defined for third party
1439
-		if (! empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->price_level)) $this->price_level=1;
1439
+		if (!empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->price_level)) $this->price_level = 1;
1440 1440
 
1441 1441
 		return $result;
1442 1442
 	}
@@ -1449,15 +1449,15 @@  discard block
 block discarded – undo
1449 1449
 	 *    @param    int		$call_trigger   0=No, 1=yes
1450 1450
 	 *    @return	int						<0 if KO, 0 if nothing done, >0 if OK
1451 1451
 	 */
1452
-	function delete($id, User $fuser=null, $call_trigger=1)
1452
+	function delete($id, User $fuser = null, $call_trigger = 1)
1453 1453
 	{
1454 1454
 		global $langs, $conf, $user;
1455 1455
 
1456
-		if (empty($fuser)) $fuser=$user;
1456
+		if (empty($fuser)) $fuser = $user;
1457 1457
 
1458 1458
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1459 1459
 
1460
-		$entity=isset($this->entity)?$this->entity:$conf->entity;
1460
+		$entity = isset($this->entity) ? $this->entity : $conf->entity;
1461 1461
 
1462 1462
 		dol_syslog(get_class($this)."::delete", LOG_DEBUG);
1463 1463
 		$error = 0;
@@ -1469,15 +1469,15 @@  discard block
 block discarded – undo
1469 1469
 			$this->db->begin();
1470 1470
 
1471 1471
 			// User is mandatory for trigger call
1472
-			if (! $error && $call_trigger)
1472
+			if (!$error && $call_trigger)
1473 1473
 			{
1474 1474
 				// Call trigger
1475
-				$result=$this->call_trigger('COMPANY_DELETE',$fuser);
1475
+				$result = $this->call_trigger('COMPANY_DELETE', $fuser);
1476 1476
 				if ($result < 0) $error++;
1477 1477
 				// End call triggers
1478 1478
 			}
1479 1479
 
1480
-			if (! $error)
1480
+			if (!$error)
1481 1481
 			{
1482 1482
 				require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1483 1483
 				$static_cat = new Categorie($this->db);
@@ -1486,11 +1486,11 @@  discard block
 block discarded – undo
1486 1486
 				// Fill $toute_categs array with an array of (type => array of ("Categorie" instance))
1487 1487
 				if ($this->client || $this->prospect)
1488 1488
 				{
1489
-					$toute_categs['customer'] = $static_cat->containing($this->id,Categorie::TYPE_CUSTOMER);
1489
+					$toute_categs['customer'] = $static_cat->containing($this->id, Categorie::TYPE_CUSTOMER);
1490 1490
 				}
1491 1491
 				if ($this->fournisseur)
1492 1492
 				{
1493
-					$toute_categs['supplier'] = $static_cat->containing($this->id,Categorie::TYPE_SUPPLIER);
1493
+					$toute_categs['supplier'] = $static_cat->containing($this->id, Categorie::TYPE_SUPPLIER);
1494 1494
 				}
1495 1495
 
1496 1496
 				// Remove each "Categorie"
@@ -1505,11 +1505,11 @@  discard block
 block discarded – undo
1505 1505
 
1506 1506
 			foreach ($this->childtablesoncascade as $tabletodelete)
1507 1507
 			{
1508
-				if (! $error)
1508
+				if (!$error)
1509 1509
 				{
1510 1510
 					$sql = "DELETE FROM ".MAIN_DB_PREFIX.$tabletodelete;
1511
-					$sql.= " WHERE fk_soc = " . $id;
1512
-					if (! $this->db->query($sql))
1511
+					$sql .= " WHERE fk_soc = ".$id;
1512
+					if (!$this->db->query($sql))
1513 1513
 					{
1514 1514
 						$error++;
1515 1515
 						$this->errors[] = $this->db->lasterror();
@@ -1518,9 +1518,9 @@  discard block
 block discarded – undo
1518 1518
 			}
1519 1519
 
1520 1520
 			// Removed extrafields
1521
-			if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
1521
+			if ((!$error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
1522 1522
 			{
1523
-				$result=$this->deleteExtraFields();
1523
+				$result = $this->deleteExtraFields();
1524 1524
 				if ($result < 0)
1525 1525
 				{
1526 1526
 					$error++;
@@ -1529,12 +1529,12 @@  discard block
 block discarded – undo
1529 1529
 			}
1530 1530
 
1531 1531
 			// Remove links to subsidiaries companies
1532
-			if (! $error)
1532
+			if (!$error)
1533 1533
 			{
1534 1534
 				$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
1535
-				$sql.= " SET parent = NULL";
1536
-				$sql.= " WHERE parent = " . $id;
1537
-				if (! $this->db->query($sql))
1535
+				$sql .= " SET parent = NULL";
1536
+				$sql .= " WHERE parent = ".$id;
1537
+				if (!$this->db->query($sql))
1538 1538
 				{
1539 1539
 					$error++;
1540 1540
 					$this->errors[] = $this->db->lasterror();
@@ -1542,25 +1542,25 @@  discard block
 block discarded – undo
1542 1542
 			}
1543 1543
 
1544 1544
 			// Remove third party
1545
-			if (! $error)
1545
+			if (!$error)
1546 1546
 			{
1547 1547
 				$sql = "DELETE FROM ".MAIN_DB_PREFIX."societe";
1548
-				$sql.= " WHERE rowid = " . $id;
1549
-				if (! $this->db->query($sql))
1548
+				$sql .= " WHERE rowid = ".$id;
1549
+				if (!$this->db->query($sql))
1550 1550
 				{
1551 1551
 					$error++;
1552 1552
 					$this->errors[] = $this->db->lasterror();
1553 1553
 				}
1554 1554
 			}
1555 1555
 
1556
-			if (! $error)
1556
+			if (!$error)
1557 1557
 			{
1558 1558
 				$this->db->commit();
1559 1559
 
1560 1560
 				// Delete directory
1561
-				if (! empty($conf->societe->multidir_output[$entity]))
1561
+				if (!empty($conf->societe->multidir_output[$entity]))
1562 1562
 				{
1563
-					$docdir = $conf->societe->multidir_output[$entity] . "/" . $id;
1563
+					$docdir = $conf->societe->multidir_output[$entity]."/".$id;
1564 1564
 					if (dol_is_dir($docdir))
1565 1565
 					{
1566 1566
 						dol_delete_dir_recursive($docdir);
@@ -1591,13 +1591,13 @@  discard block
 block discarded – undo
1591 1591
         // phpcs:enable
1592 1592
 		if ($this->id)
1593 1593
 		{
1594
-			$newclient=1;
1595
-			if ($this->client == 2 || $this->client == 3) $newclient=3;	//If prospect, we keep prospect tag
1594
+			$newclient = 1;
1595
+			if ($this->client == 2 || $this->client == 3) $newclient = 3; //If prospect, we keep prospect tag
1596 1596
 			$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
1597
-			$sql.= " SET client = ".$newclient;
1598
-			$sql.= " WHERE rowid = " . $this->id;
1597
+			$sql .= " SET client = ".$newclient;
1598
+			$sql .= " WHERE rowid = ".$this->id;
1599 1599
 
1600
-			$resql=$this->db->query($sql);
1600
+			$resql = $this->db->query($sql);
1601 1601
 			if ($resql)
1602 1602
 			{
1603 1603
 				$this->client = $newclient;
@@ -1623,10 +1623,10 @@  discard block
 block discarded – undo
1623 1623
 		global $conf, $langs;
1624 1624
 
1625 1625
 		// Nettoyage parametres
1626
-		$note=trim($note);
1627
-		if (! $note)
1626
+		$note = trim($note);
1627
+		if (!$note)
1628 1628
 		{
1629
-			$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("NoteReason"));
1629
+			$this->error = $langs->trans("ErrorFieldRequired", $langs->trans("NoteReason"));
1630 1630
 			return -2;
1631 1631
 		}
1632 1632
 
@@ -1636,33 +1636,33 @@  discard block
 block discarded – undo
1636 1636
 		{
1637 1637
 			$this->db->begin();
1638 1638
 
1639
-			$now=dol_now();
1639
+			$now = dol_now();
1640 1640
 
1641 1641
 			// Positionne remise courante
1642 1642
 			$sql = "UPDATE ".MAIN_DB_PREFIX."societe ";
1643
-			$sql.= " SET remise_client = '".$this->db->escape($remise)."'";
1644
-			$sql.= " WHERE rowid = " . $this->id;
1645
-			$resql=$this->db->query($sql);
1646
-			if (! $resql)
1643
+			$sql .= " SET remise_client = '".$this->db->escape($remise)."'";
1644
+			$sql .= " WHERE rowid = ".$this->id;
1645
+			$resql = $this->db->query($sql);
1646
+			if (!$resql)
1647 1647
 			{
1648 1648
 				$this->db->rollback();
1649
-				$this->error=$this->db->error();
1649
+				$this->error = $this->db->error();
1650 1650
 				return -1;
1651 1651
 			}
1652 1652
 
1653 1653
 			// Ecrit trace dans historique des remises
1654 1654
 			$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise";
1655
-			$sql.= " (entity, datec, fk_soc, remise_client, note, fk_user_author)";
1656
-			$sql.= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',";
1657
-			$sql.= " '".$this->db->escape($note)."',";
1658
-			$sql.= " ".$user->id;
1659
-			$sql.= ")";
1660
-
1661
-			$resql=$this->db->query($sql);
1662
-			if (! $resql)
1655
+			$sql .= " (entity, datec, fk_soc, remise_client, note, fk_user_author)";
1656
+			$sql .= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',";
1657
+			$sql .= " '".$this->db->escape($note)."',";
1658
+			$sql .= " ".$user->id;
1659
+			$sql .= ")";
1660
+
1661
+			$resql = $this->db->query($sql);
1662
+			if (!$resql)
1663 1663
 			{
1664 1664
 				$this->db->rollback();
1665
-				$this->error=$this->db->lasterror();
1665
+				$this->error = $this->db->lasterror();
1666 1666
 				return -1;
1667 1667
 			}
1668 1668
 
@@ -1686,10 +1686,10 @@  discard block
 block discarded – undo
1686 1686
 		global $conf, $langs;
1687 1687
 
1688 1688
 		// Nettoyage parametres
1689
-		$note=trim($note);
1690
-		if (! $note)
1689
+		$note = trim($note);
1690
+		if (!$note)
1691 1691
 		{
1692
-			$this->error=$langs->trans("ErrorFieldRequired",$langs->trans("NoteReason"));
1692
+			$this->error = $langs->trans("ErrorFieldRequired", $langs->trans("NoteReason"));
1693 1693
 			return -2;
1694 1694
 		}
1695 1695
 
@@ -1699,33 +1699,33 @@  discard block
 block discarded – undo
1699 1699
 		{
1700 1700
 			$this->db->begin();
1701 1701
 
1702
-			$now=dol_now();
1702
+			$now = dol_now();
1703 1703
 
1704 1704
 			// Positionne remise courante
1705 1705
 			$sql = "UPDATE ".MAIN_DB_PREFIX."societe ";
1706
-			$sql.= " SET remise_supplier = '".$this->db->escape($remise)."'";
1707
-			$sql.= " WHERE rowid = " . $this->id;
1708
-			$resql=$this->db->query($sql);
1709
-			if (! $resql)
1706
+			$sql .= " SET remise_supplier = '".$this->db->escape($remise)."'";
1707
+			$sql .= " WHERE rowid = ".$this->id;
1708
+			$resql = $this->db->query($sql);
1709
+			if (!$resql)
1710 1710
 			{
1711 1711
 				$this->db->rollback();
1712
-				$this->error=$this->db->error();
1712
+				$this->error = $this->db->error();
1713 1713
 				return -1;
1714 1714
 			}
1715 1715
 
1716 1716
 			// Ecrit trace dans historique des remises
1717 1717
 			$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_remise_supplier";
1718
-			$sql.= " (entity, datec, fk_soc, remise_supplier, note, fk_user_author)";
1719
-			$sql.= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',";
1720
-			$sql.= " '".$this->db->escape($note)."',";
1721
-			$sql.= " ".$user->id;
1722
-			$sql.= ")";
1723
-
1724
-			$resql=$this->db->query($sql);
1725
-			if (! $resql)
1718
+			$sql .= " (entity, datec, fk_soc, remise_supplier, note, fk_user_author)";
1719
+			$sql .= " VALUES (".$conf->entity.", '".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($remise)."',";
1720
+			$sql .= " '".$this->db->escape($note)."',";
1721
+			$sql .= " ".$user->id;
1722
+			$sql .= ")";
1723
+
1724
+			$resql = $this->db->query($sql);
1725
+			if (!$resql)
1726 1726
 			{
1727 1727
 				$this->db->rollback();
1728
-				$this->error=$this->db->lasterror();
1728
+				$this->error = $this->db->lasterror();
1729 1729
 				return -1;
1730 1730
 			}
1731 1731
 
@@ -1745,7 +1745,7 @@  discard block
 block discarded – undo
1745 1745
 	 *      @param	int		$discount_type	0 => customer discount, 1 => supplier discount
1746 1746
 	 *		@return	int					<0 if KO, id of discount record if OK
1747 1747
 	 */
1748
-	function set_remise_except($remise, User $user, $desc, $tva_tx=0, $discount_type=0)
1748
+	function set_remise_except($remise, User $user, $desc, $tva_tx = 0, $discount_type = 0)
1749 1749
 	{
1750 1750
         // phpcs:enable
1751 1751
 		global $langs;
@@ -1755,14 +1755,14 @@  discard block
 block discarded – undo
1755 1755
 		$desc = trim($desc);
1756 1756
 
1757 1757
 		// Check parameters
1758
-		if (! $remise > 0)
1758
+		if (!$remise > 0)
1759 1759
 		{
1760
-			$this->error=$langs->trans("ErrorWrongValueForParameter","1");
1760
+			$this->error = $langs->trans("ErrorWrongValueForParameter", "1");
1761 1761
 			return -1;
1762 1762
 		}
1763
-		if (! $desc)
1763
+		if (!$desc)
1764 1764
 		{
1765
-			$this->error=$langs->trans("ErrorWrongValueForParameter","3");
1765
+			$this->error = $langs->trans("ErrorWrongValueForParameter", "3");
1766 1766
 			return -2;
1767 1767
 		}
1768 1768
 
@@ -1771,25 +1771,25 @@  discard block
 block discarded – undo
1771 1771
 			require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
1772 1772
 
1773 1773
 			$discount = new DiscountAbsolute($this->db);
1774
-			$discount->fk_soc=$this->id;
1774
+			$discount->fk_soc = $this->id;
1775 1775
 
1776
-			$discount->discount_type=$discount_type;
1776
+			$discount->discount_type = $discount_type;
1777 1777
 
1778
-			$discount->amount_ht=$discount->multicurrency_amount_ht=price2num($remise,'MT');
1779
-			$discount->amount_tva=$discount->multicurrency_amount_tva=price2num($remise*$tva_tx/100,'MT');
1780
-			$discount->amount_ttc=$discount->multicurrency_amount_ttc=price2num($discount->amount_ht+$discount->amount_tva,'MT');
1778
+			$discount->amount_ht = $discount->multicurrency_amount_ht = price2num($remise, 'MT');
1779
+			$discount->amount_tva = $discount->multicurrency_amount_tva = price2num($remise * $tva_tx / 100, 'MT');
1780
+			$discount->amount_ttc = $discount->multicurrency_amount_ttc = price2num($discount->amount_ht + $discount->amount_tva, 'MT');
1781 1781
 
1782
-			$discount->tva_tx=price2num($tva_tx,'MT');
1783
-			$discount->description=$desc;
1782
+			$discount->tva_tx = price2num($tva_tx, 'MT');
1783
+			$discount->description = $desc;
1784 1784
 
1785
-			$result=$discount->create($user);
1785
+			$result = $discount->create($user);
1786 1786
 			if ($result > 0)
1787 1787
 			{
1788 1788
 				return $result;
1789 1789
 			}
1790 1790
 			else
1791 1791
 			{
1792
-				$this->error=$discount->error;
1792
+				$this->error = $discount->error;
1793 1793
 				return -3;
1794 1794
 			}
1795 1795
 		}
@@ -1805,19 +1805,19 @@  discard block
 block discarded – undo
1805 1805
 	 * 	@param	int		$discount_type	0 => customer discount, 1 => supplier discount
1806 1806
 	 *	@return	int					<0 if KO, Credit note amount otherwise
1807 1807
 	 */
1808
-	function getAvailableDiscounts($user='',$filter='',$maxvalue=0,$discount_type=0)
1808
+	function getAvailableDiscounts($user = '', $filter = '', $maxvalue = 0, $discount_type = 0)
1809 1809
 	{
1810 1810
 		require_once DOL_DOCUMENT_ROOT.'/core/class/discount.class.php';
1811 1811
 
1812
-		$discountstatic=new DiscountAbsolute($this->db);
1813
-		$result=$discountstatic->getAvailableDiscounts($this,$user,$filter,$maxvalue,$discount_type);
1812
+		$discountstatic = new DiscountAbsolute($this->db);
1813
+		$result = $discountstatic->getAvailableDiscounts($this, $user, $filter, $maxvalue, $discount_type);
1814 1814
 		if ($result >= 0)
1815 1815
 		{
1816 1816
 			return $result;
1817 1817
 		}
1818 1818
 		else
1819 1819
 		{
1820
-			$this->error=$discountstatic->error;
1820
+			$this->error = $discountstatic->error;
1821 1821
 			return -1;
1822 1822
 		}
1823 1823
 	}
@@ -1829,49 +1829,49 @@  discard block
 block discarded – undo
1829 1829
 	 *  @param	int		$mode		0=Array with properties, 1=Array of id.
1830 1830
 	 *  @return array       		Array of sales representatives of third party
1831 1831
 	 */
1832
-	function getSalesRepresentatives(User $user, $mode=0)
1832
+	function getSalesRepresentatives(User $user, $mode = 0)
1833 1833
 	{
1834 1834
 		global $conf;
1835 1835
 
1836
-		$reparray=array();
1836
+		$reparray = array();
1837 1837
 
1838 1838
 		$sql = "SELECT DISTINCT u.rowid, u.login, u.lastname, u.firstname, u.email, u.statut, u.entity, u.photo";
1839
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."user as u";
1840
-		if (! empty($conf->multicompany->enabled) && ! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
1839
+		$sql .= " FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc, ".MAIN_DB_PREFIX."user as u";
1840
+		if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))
1841 1841
 		{
1842
-			$sql.= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1843
-			$sql.= " WHERE ((ug.fk_user = sc.fk_user";
1844
-			$sql.= " AND ug.entity = ".$conf->entity.")";
1845
-			$sql.= " OR u.admin = 1)";
1842
+			$sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
1843
+			$sql .= " WHERE ((ug.fk_user = sc.fk_user";
1844
+			$sql .= " AND ug.entity = ".$conf->entity.")";
1845
+			$sql .= " OR u.admin = 1)";
1846 1846
 		}
1847 1847
 		else
1848
-			$sql.= " WHERE entity in (0, ".$conf->entity.")";
1848
+			$sql .= " WHERE entity in (0, ".$conf->entity.")";
1849 1849
 
1850
-		$sql.= " AND u.rowid = sc.fk_user AND sc.fk_soc = ".$this->id;
1850
+		$sql .= " AND u.rowid = sc.fk_user AND sc.fk_soc = ".$this->id;
1851 1851
 
1852 1852
 		$resql = $this->db->query($sql);
1853 1853
 		if ($resql)
1854 1854
 		{
1855 1855
 			$num = $this->db->num_rows($resql);
1856
-			$i=0;
1856
+			$i = 0;
1857 1857
 			while ($i < $num)
1858 1858
 			{
1859 1859
 				$obj = $this->db->fetch_object($resql);
1860 1860
 
1861 1861
 				if (empty($mode))
1862 1862
 				{
1863
-					$reparray[$i]['id']=$obj->rowid;
1864
-					$reparray[$i]['lastname']=$obj->lastname;
1865
-					$reparray[$i]['firstname']=$obj->firstname;
1866
-					$reparray[$i]['email']=$obj->email;
1867
-					$reparray[$i]['statut']=$obj->statut;
1868
-					$reparray[$i]['entity']=$obj->entity;
1869
-					$reparray[$i]['login']=$obj->login;
1870
-					$reparray[$i]['photo']=$obj->photo;
1863
+					$reparray[$i]['id'] = $obj->rowid;
1864
+					$reparray[$i]['lastname'] = $obj->lastname;
1865
+					$reparray[$i]['firstname'] = $obj->firstname;
1866
+					$reparray[$i]['email'] = $obj->email;
1867
+					$reparray[$i]['statut'] = $obj->statut;
1868
+					$reparray[$i]['entity'] = $obj->entity;
1869
+					$reparray[$i]['login'] = $obj->login;
1870
+					$reparray[$i]['photo'] = $obj->photo;
1871 1871
 				}
1872 1872
 				else
1873 1873
 				{
1874
-					$reparray[]=$obj->rowid;
1874
+					$reparray[] = $obj->rowid;
1875 1875
 				}
1876 1876
 				$i++;
1877 1877
 			}
@@ -1896,13 +1896,13 @@  discard block
 block discarded – undo
1896 1896
         // phpcs:enable
1897 1897
 		if ($this->id)
1898 1898
 		{
1899
-			$now=dol_now();
1899
+			$now = dol_now();
1900 1900
 
1901 1901
 			$sql  = "UPDATE ".MAIN_DB_PREFIX."societe";
1902 1902
 			$sql .= " SET price_level = '".$this->db->escape($price_level)."'";
1903
-			$sql .= " WHERE rowid = " . $this->id;
1903
+			$sql .= " WHERE rowid = ".$this->id;
1904 1904
 
1905
-			if (! $this->db->query($sql))
1905
+			if (!$this->db->query($sql))
1906 1906
 			{
1907 1907
 				dol_print_error($this->db);
1908 1908
 				return -1;
@@ -1912,7 +1912,7 @@  discard block
 block discarded – undo
1912 1912
 			$sql .= " (datec, fk_soc, price_level, fk_user_author)";
1913 1913
 			$sql .= " VALUES ('".$this->db->idate($now)."', ".$this->id.", '".$this->db->escape($price_level)."', ".$user->id.")";
1914 1914
 
1915
-			if (! $this->db->query($sql))
1915
+			if (!$this->db->query($sql))
1916 1916
 			{
1917 1917
 				dol_print_error($this->db);
1918 1918
 				return -1;
@@ -1933,28 +1933,28 @@  discard block
 block discarded – undo
1933 1933
 	function add_commercial(User $user, $commid)
1934 1934
 	{
1935 1935
         // phpcs:enable
1936
-		$error=0;
1936
+		$error = 0;
1937 1937
 
1938 1938
 
1939 1939
 		if ($this->id > 0 && $commid > 0)
1940 1940
 		{
1941 1941
 			$sql = "DELETE FROM  ".MAIN_DB_PREFIX."societe_commerciaux";
1942
-			$sql.= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid;
1942
+			$sql .= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid;
1943 1943
 
1944 1944
 			$this->db->query($sql);
1945 1945
 
1946 1946
 			$sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_commerciaux";
1947
-			$sql.= " ( fk_soc, fk_user )";
1948
-			$sql.= " VALUES (".$this->id.",".$commid.")";
1947
+			$sql .= " ( fk_soc, fk_user )";
1948
+			$sql .= " VALUES (".$this->id.",".$commid.")";
1949 1949
 
1950
-			if (! $this->db->query($sql) )
1950
+			if (!$this->db->query($sql))
1951 1951
 			{
1952 1952
 				dol_syslog(get_class($this)."::add_commercial Erreur");
1953 1953
 			}
1954 1954
 			else {
1955
-				$this->context=array('commercial_modified'=>$commid);
1955
+				$this->context = array('commercial_modified'=>$commid);
1956 1956
 
1957
-				$result=$this->call_trigger('COMPANY_LINK_SALE_REPRESENTATIVE',$user);
1957
+				$result = $this->call_trigger('COMPANY_LINK_SALE_REPRESENTATIVE', $user);
1958 1958
                 if ($result < 0) $error++;
1959 1959
 			}
1960 1960
 		}
@@ -1971,10 +1971,10 @@  discard block
 block discarded – undo
1971 1971
 	function del_commercial(User $user, $commid)
1972 1972
 	{
1973 1973
         // phpcs:enable
1974
-		$error=0;
1975
-		$this->context=array('commercial_modified'=>$commid);
1974
+		$error = 0;
1975
+		$this->context = array('commercial_modified'=>$commid);
1976 1976
 
1977
-		$result=$this->call_trigger('COMPANY_UNLINK_SALE_REPRESENTATIVE',$user);
1977
+		$result = $this->call_trigger('COMPANY_UNLINK_SALE_REPRESENTATIVE', $user);
1978 1978
         if ($result < 0) $error++;
1979 1979
 
1980 1980
 		if ($this->id > 0 && $commid > 0)
@@ -1982,7 +1982,7 @@  discard block
 block discarded – undo
1982 1982
 			$sql  = "DELETE FROM  ".MAIN_DB_PREFIX."societe_commerciaux ";
1983 1983
 			$sql .= " WHERE fk_soc = ".$this->id." AND fk_user =".$commid;
1984 1984
 
1985
-			if (! $this->db->query($sql) )
1985
+			if (!$this->db->query($sql))
1986 1986
 			{
1987 1987
 				dol_syslog(get_class($this)."::del_commercial Erreur");
1988 1988
 			}
@@ -2000,162 +2000,162 @@  discard block
 block discarded – undo
2000 2000
 	 *      @param  int     $save_lastsearch_value    -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking
2001 2001
 	 *		@return	string					          String with URL
2002 2002
 	 */
2003
-	function getNomUrl($withpicto=0, $option='', $maxlen=0, $notooltip=0, $save_lastsearch_value=-1)
2003
+	function getNomUrl($withpicto = 0, $option = '', $maxlen = 0, $notooltip = 0, $save_lastsearch_value = -1)
2004 2004
 	{
2005 2005
 		global $conf, $langs, $hookmanager;
2006 2006
 
2007
-		if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
2007
+		if (!empty($conf->dol_no_mouse_hover)) $notooltip = 1; // Force disable tooltips
2008 2008
 
2009
-		$name=$this->name?$this->name:$this->nom;
2009
+		$name = $this->name ? $this->name : $this->nom;
2010 2010
 
2011
-		if(!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)){
2011
+		if (!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)) {
2012 2012
 
2013
-             if(empty($option) && $this->client > 0) $option = 'customer';
2014
-             if(empty($option) && $this->fournisseur > 0) $option = 'supplier';
2013
+             if (empty($option) && $this->client > 0) $option = 'customer';
2014
+             if (empty($option) && $this->fournisseur > 0) $option = 'supplier';
2015 2015
          }
2016 2016
 
2017 2017
 
2018
-		if (! empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto)))
2018
+		if (!empty($conf->global->SOCIETE_ADD_REF_IN_LIST) && (!empty($withpicto)))
2019 2019
 		{
2020 2020
 			$code = '';
2021
-			if (($this->client) && (! empty ( $this->code_client ))
2021
+			if (($this->client) && (!empty ($this->code_client))
2022 2022
 				&& ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1
2023 2023
 				|| $conf->global->SOCIETE_ADD_REF_IN_LIST == 2
2024 2024
 				)
2025 2025
 			)
2026 2026
 			{
2027
-				$code = $this->code_client . ' - ';
2027
+				$code = $this->code_client.' - ';
2028 2028
 			}
2029 2029
 
2030
-			if (($this->fournisseur) && (! empty ( $this->code_fournisseur ))
2030
+			if (($this->fournisseur) && (!empty ($this->code_fournisseur))
2031 2031
 				&& ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1
2032 2032
 				|| $conf->global->SOCIETE_ADD_REF_IN_LIST == 3
2033 2033
 				)
2034 2034
 			)
2035 2035
 			{
2036
-				$code .= $this->code_fournisseur . ' - ';
2036
+				$code .= $this->code_fournisseur.' - ';
2037 2037
 			}
2038 2038
 
2039 2039
 			if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1)
2040 2040
 			{
2041
-				$name =$code.' '.$name;
2041
+				$name = $code.' '.$name;
2042 2042
 			}
2043 2043
 			else
2044 2044
 			{
2045
-				$name =$code;
2045
+				$name = $code;
2046 2046
 			}
2047 2047
 		}
2048 2048
 
2049 2049
 		if (!empty($this->name_alias)) $name .= ' ('.$this->name_alias.')';
2050 2050
 
2051
-		$result=''; $label='';
2052
-		$linkstart=''; $linkend='';
2051
+		$result = ''; $label = '';
2052
+		$linkstart = ''; $linkend = '';
2053 2053
 
2054
-		if (! empty($this->logo) && class_exists('Form'))
2054
+		if (!empty($this->logo) && class_exists('Form'))
2055 2055
 		{
2056
-			$label.= '<div class="photointooltip">';
2057
-			$label.= Form::showphoto('societe', $this, 0, 40, 0, 'photowithmargin', 'mini', 0);	// Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
2058
-			$label.= '</div><div style="clear: both;"></div>';
2056
+			$label .= '<div class="photointooltip">';
2057
+			$label .= Form::showphoto('societe', $this, 0, 40, 0, 'photowithmargin', 'mini', 0); // Important, we must force height so image will have height tags and if image is inside a tooltip, the tooltip manager can calculate height and position correctly the tooltip.
2058
+			$label .= '</div><div style="clear: both;"></div>';
2059 2059
 		}
2060 2060
 
2061
-		$label.= '<div class="centpercent">';
2061
+		$label .= '<div class="centpercent">';
2062 2062
 
2063 2063
 		if ($option == 'customer' || $option == 'compta' || $option == 'category' || $option == 'category_supplier')
2064 2064
 		{
2065
-		   $label.= '<u>' . $langs->trans("ShowCustomer") . '</u>';
2065
+		   $label .= '<u>'.$langs->trans("ShowCustomer").'</u>';
2066 2066
 		   $linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id;
2067 2067
 		}
2068 2068
 		elseif ($option == 'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
2069 2069
 		{
2070
-			$label.= '<u>' . $langs->trans("ShowProspect") . '</u>';
2070
+			$label .= '<u>'.$langs->trans("ShowProspect").'</u>';
2071 2071
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id;
2072 2072
 		}
2073 2073
 		elseif ($option == 'supplier')
2074 2074
 		{
2075
-			$label.= '<u>' . $langs->trans("ShowSupplier") . '</u>';
2075
+			$label .= '<u>'.$langs->trans("ShowSupplier").'</u>';
2076 2076
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$this->id;
2077 2077
 		}
2078 2078
 		elseif ($option == 'agenda')
2079 2079
 		{
2080
-			$label.= '<u>' . $langs->trans("ShowAgenda") . '</u>';
2080
+			$label .= '<u>'.$langs->trans("ShowAgenda").'</u>';
2081 2081
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/agenda.php?socid='.$this->id;
2082 2082
 		}
2083 2083
 		elseif ($option == 'project')
2084 2084
 		{
2085
-			$label.= '<u>' . $langs->trans("ShowProject") . '</u>';
2085
+			$label .= '<u>'.$langs->trans("ShowProject").'</u>';
2086 2086
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/project.php?socid='.$this->id;
2087 2087
 		}
2088 2088
 		elseif ($option == 'margin')
2089 2089
 		{
2090
-			$label.= '<u>' . $langs->trans("ShowMargin") . '</u>';
2090
+			$label .= '<u>'.$langs->trans("ShowMargin").'</u>';
2091 2091
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/margin/tabs/thirdpartyMargins.php?socid='.$this->id.'&type=1';
2092 2092
 		}
2093 2093
 		elseif ($option == 'contact')
2094 2094
 		{
2095
-			$label.= '<u>' . $langs->trans("ShowContacts") . '</u>';
2095
+			$label .= '<u>'.$langs->trans("ShowContacts").'</u>';
2096 2096
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/contact.php?socid='.$this->id;
2097 2097
 		}
2098 2098
 		elseif ($option == 'ban')
2099 2099
 		{
2100
-			$label.= '<u>' . $langs->trans("ShowBan") . '</u>';
2100
+			$label .= '<u>'.$langs->trans("ShowBan").'</u>';
2101 2101
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$this->id;
2102 2102
 		}
2103 2103
 
2104 2104
 		// By default
2105 2105
 		if (empty($linkstart))
2106 2106
 		{
2107
-			$label.= '<u>' . $langs->trans("ShowCompany") . '</u>';
2107
+			$label .= '<u>'.$langs->trans("ShowCompany").'</u>';
2108 2108
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/card.php?socid='.$this->id;
2109 2109
 		}
2110 2110
 
2111
-		if (! empty($this->name))
2111
+		if (!empty($this->name))
2112 2112
 		{
2113
-			$label.= '<br><b>' . $langs->trans('Name') . ':</b> '. $this->name;
2114
-			if (! empty($this->name_alias)) $label.=' ('.$this->name_alias.')';
2115
-			$label.= '<br><b>' . $langs->trans('Email') . ':</b> '. $this->email;
2116
-		}
2117
-		if (! empty($this->country_code))
2118
-			$label.= '<br><b>' . $langs->trans('Country') . ':</b> '. $this->country_code;
2119
-		if (! empty($this->tva_intra) || (! empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'vatnumber') !== false))
2120
-			$label.= '<br><b>' . $langs->trans('VATIntra') . ':</b> '. $this->tva_intra;
2121
-		if (! empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP))
2113
+			$label .= '<br><b>'.$langs->trans('Name').':</b> '.$this->name;
2114
+			if (!empty($this->name_alias)) $label .= ' ('.$this->name_alias.')';
2115
+			$label .= '<br><b>'.$langs->trans('Email').':</b> '.$this->email;
2116
+		}
2117
+		if (!empty($this->country_code))
2118
+			$label .= '<br><b>'.$langs->trans('Country').':</b> '.$this->country_code;
2119
+		if (!empty($this->tva_intra) || (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'vatnumber') !== false))
2120
+			$label .= '<br><b>'.$langs->trans('VATIntra').':</b> '.$this->tva_intra;
2121
+		if (!empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP))
2122 2122
 		{
2123
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid1') !== false) $label.= '<br><b>' . $langs->trans('ProfId1'.$this->country_code) . ':</b> '. $this->idprof1;
2124
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid2') !== false) $label.= '<br><b>' . $langs->trans('ProfId2'.$this->country_code) . ':</b> '. $this->idprof2;
2125
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid3') !== false) $label.= '<br><b>' . $langs->trans('ProfId3'.$this->country_code) . ':</b> '. $this->idprof3;
2126
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid4') !== false) $label.= '<br><b>' . $langs->trans('ProfId4'.$this->country_code) . ':</b> '. $this->idprof4;
2127
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid5') !== false) $label.= '<br><b>' . $langs->trans('ProfId5'.$this->country_code) . ':</b> '. $this->idprof5;
2128
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid6') !== false) $label.= '<br><b>' . $langs->trans('ProfId6'.$this->country_code) . ':</b> '. $this->idprof6;
2129
-		}
2130
-		if (! empty($this->code_client) && ($this->client == 1 || $this->client == 3))
2131
-			$label.= '<br><b>' . $langs->trans('CustomerCode') . ':</b> '. $this->code_client;
2132
-		if (! empty($this->code_fournisseur) && $this->fournisseur)
2133
-			$label.= '<br><b>' . $langs->trans('SupplierCode') . ':</b> '. $this->code_fournisseur;
2134
-		if (! empty($conf->accounting->enabled) && ($this->client == 1 || $this->client == 3))
2135
-			$label.= '<br><b>' . $langs->trans('CustomerAccountancyCode') . ':</b> '. ($this->code_compta ? $this->code_compta : $this->code_compta_client);
2136
-		if (! empty($conf->accounting->enabled) && $this->fournisseur)
2137
-			$label.= '<br><b>' . $langs->trans('SupplierAccountancyCode') . ':</b> '. $this->code_compta_fournisseur;
2138
-
2139
-		$label.= '</div>';
2123
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid1') !== false) $label .= '<br><b>'.$langs->trans('ProfId1'.$this->country_code).':</b> '.$this->idprof1;
2124
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid2') !== false) $label .= '<br><b>'.$langs->trans('ProfId2'.$this->country_code).':</b> '.$this->idprof2;
2125
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid3') !== false) $label .= '<br><b>'.$langs->trans('ProfId3'.$this->country_code).':</b> '.$this->idprof3;
2126
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid4') !== false) $label .= '<br><b>'.$langs->trans('ProfId4'.$this->country_code).':</b> '.$this->idprof4;
2127
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid5') !== false) $label .= '<br><b>'.$langs->trans('ProfId5'.$this->country_code).':</b> '.$this->idprof5;
2128
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid6') !== false) $label .= '<br><b>'.$langs->trans('ProfId6'.$this->country_code).':</b> '.$this->idprof6;
2129
+		}
2130
+		if (!empty($this->code_client) && ($this->client == 1 || $this->client == 3))
2131
+			$label .= '<br><b>'.$langs->trans('CustomerCode').':</b> '.$this->code_client;
2132
+		if (!empty($this->code_fournisseur) && $this->fournisseur)
2133
+			$label .= '<br><b>'.$langs->trans('SupplierCode').':</b> '.$this->code_fournisseur;
2134
+		if (!empty($conf->accounting->enabled) && ($this->client == 1 || $this->client == 3))
2135
+			$label .= '<br><b>'.$langs->trans('CustomerAccountancyCode').':</b> '.($this->code_compta ? $this->code_compta : $this->code_compta_client);
2136
+		if (!empty($conf->accounting->enabled) && $this->fournisseur)
2137
+			$label .= '<br><b>'.$langs->trans('SupplierAccountancyCode').':</b> '.$this->code_compta_fournisseur;
2138
+
2139
+		$label .= '</div>';
2140 2140
 
2141 2141
 		// Add type of canvas
2142
-		$linkstart.=(!empty($this->canvas)?'&canvas='.$this->canvas:'');
2142
+		$linkstart .= (!empty($this->canvas) ? '&canvas='.$this->canvas : '');
2143 2143
 		// Add param to save lastsearch_values or not
2144
-		$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
2145
-		if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
2146
-		if ($add_save_lastsearch_values) $linkstart.='&save_lastsearch_values=1';
2147
-		$linkstart.='"';
2144
+		$add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2145
+		if ($save_lastsearch_value == -1 && preg_match('/list\.php/', $_SERVER["PHP_SELF"])) $add_save_lastsearch_values = 1;
2146
+		if ($add_save_lastsearch_values) $linkstart .= '&save_lastsearch_values=1';
2147
+		$linkstart .= '"';
2148 2148
 
2149
-		$linkclose='';
2149
+		$linkclose = '';
2150 2150
 		if (empty($notooltip))
2151 2151
 		{
2152
-			if (! empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
2152
+			if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER))
2153 2153
 			{
2154
-				$label=$langs->trans("ShowCompany");
2155
-				$linkclose.=' alt="'.dol_escape_htmltag($label, 1).'"';
2154
+				$label = $langs->trans("ShowCompany");
2155
+				$linkclose .= ' alt="'.dol_escape_htmltag($label, 1).'"';
2156 2156
 			}
2157
-			$linkclose.= ' title="'.dol_escape_htmltag($label, 1).'"';
2158
-			$linkclose.=' class="classfortooltip refurl"';
2157
+			$linkclose .= ' title="'.dol_escape_htmltag($label, 1).'"';
2158
+			$linkclose .= ' class="classfortooltip refurl"';
2159 2159
 
2160 2160
 		 	/*
2161 2161
 			$hookmanager->initHooks(array('thirdpartydao'));
@@ -2164,25 +2164,25 @@  discard block
 block discarded – undo
2164 2164
 			if ($reshook > 0) $linkclose = $hookmanager->resPrint;
2165 2165
 			*/
2166 2166
 		}
2167
-		$linkstart.=$linkclose.'>';
2168
-		$linkend='</a>';
2167
+		$linkstart .= $linkclose.'>';
2168
+		$linkend = '</a>';
2169 2169
 
2170 2170
 		global $user;
2171
-		if (! $user->rights->societe->client->voir && $user->societe_id > 0 && $this->id != $user->societe_id)
2171
+		if (!$user->rights->societe->client->voir && $user->societe_id > 0 && $this->id != $user->societe_id)
2172 2172
 		{
2173
-			$linkstart='';
2174
-			$linkend='';
2173
+			$linkstart = '';
2174
+			$linkend = '';
2175 2175
 		}
2176 2176
 
2177
-		$result.=$linkstart;
2178
-		if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip valigntextbottom"'), 0, 0, $notooltip?0:1);
2179
-		if ($withpicto != 2) $result.=($maxlen?dol_trunc($name,$maxlen):$name);
2180
-		$result.=$linkend;
2177
+		$result .= $linkstart;
2178
+		if ($withpicto) $result .= img_object(($notooltip ? '' : $label), ($this->picto ? $this->picto : 'generic'), ($notooltip ? (($withpicto != 2) ? 'class="paddingright"' : '') : 'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip valigntextbottom"'), 0, 0, $notooltip ? 0 : 1);
2179
+		if ($withpicto != 2) $result .= ($maxlen ?dol_trunc($name, $maxlen) : $name);
2180
+		$result .= $linkend;
2181 2181
 
2182 2182
 		global $action;
2183 2183
 		$hookmanager->initHooks(array('thirdpartydao'));
2184
-		$parameters=array('id'=>$this->id, 'getnomurl'=>$result);
2185
-		$reshook=$hookmanager->executeHooks('getNomUrl',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
2184
+		$parameters = array('id'=>$this->id, 'getnomurl'=>$result);
2185
+		$reshook = $hookmanager->executeHooks('getNomUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
2186 2186
 		if ($reshook > 0) $result = $hookmanager->resPrint;
2187 2187
 		else $result .= $hookmanager->resPrint;
2188 2188
 
@@ -2195,9 +2195,9 @@  discard block
 block discarded – undo
2195 2195
 	 *    @param	int		$mode       0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto
2196 2196
 	 *    @return   string        		Libelle
2197 2197
 	 */
2198
-	function getLibStatut($mode=0)
2198
+	function getLibStatut($mode = 0)
2199 2199
 	{
2200
-		return $this->LibStatut($this->status,$mode);
2200
+		return $this->LibStatut($this->status, $mode);
2201 2201
 	}
2202 2202
 
2203 2203
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -2208,7 +2208,7 @@  discard block
 block discarded – undo
2208 2208
 	 *  @param	int		$mode           0=Long label, 1=Short label, 2=Picto + Short label, 3=Picto, 4=Picto + Long label, 5=Short label + Picto, 6=Long label + Picto
2209 2209
 	 *  @return	string          		Libelle du statut
2210 2210
 	 */
2211
-	function LibStatut($statut,$mode=0)
2211
+	function LibStatut($statut, $mode = 0)
2212 2212
 	{
2213 2213
         // phpcs:enable
2214 2214
 		global $langs;
@@ -2216,38 +2216,38 @@  discard block
 block discarded – undo
2216 2216
 
2217 2217
 		if ($mode == 0)
2218 2218
 		{
2219
-			if ($statut==0) return $langs->trans("ActivityCeased");
2220
-			elseif ($statut==1) return $langs->trans("InActivity");
2219
+			if ($statut == 0) return $langs->trans("ActivityCeased");
2220
+			elseif ($statut == 1) return $langs->trans("InActivity");
2221 2221
 		}
2222 2222
 		elseif ($mode == 1)
2223 2223
 		{
2224
-			if ($statut==0) return $langs->trans("ActivityCeased");
2225
-			elseif ($statut==1) return $langs->trans("InActivity");
2224
+			if ($statut == 0) return $langs->trans("ActivityCeased");
2225
+			elseif ($statut == 1) return $langs->trans("InActivity");
2226 2226
 		}
2227 2227
 		elseif ($mode == 2)
2228 2228
 		{
2229
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2230
-			elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2229
+			if ($statut == 0) return img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2230
+			elseif ($statut == 1) return img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2231 2231
 		}
2232 2232
 		elseif ($mode == 3)
2233 2233
 		{
2234
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2235
-			elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2234
+			if ($statut == 0) return img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"');
2235
+			elseif ($statut == 1) return img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"');
2236 2236
 		}
2237 2237
 		elseif ($mode == 4)
2238 2238
 		{
2239
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2240
-			elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2239
+			if ($statut == 0) return img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2240
+			elseif ($statut == 1) return img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2241 2241
 		}
2242 2242
 		elseif ($mode == 5)
2243 2243
 		{
2244
-			if ($statut==0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2245
-			elseif ($statut==1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2244
+			if ($statut == 0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"');
2245
+			elseif ($statut == 1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"');
2246 2246
 		}
2247 2247
 		elseif ($mode == 6)
2248 2248
 		{
2249
-			if ($statut==0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2250
-			elseif ($statut==1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2249
+			if ($statut == 0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"), 'statut5', 'class="pictostatus"');
2250
+			elseif ($statut == 1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"), 'statut4', 'class="pictostatus"');
2251 2251
 		}
2252 2252
 	}
2253 2253
 
@@ -2258,16 +2258,16 @@  discard block
 block discarded – undo
2258 2258
 	 *	  @param	  int		$addthirdparty		1=Add also a record for thirdparty email
2259 2259
 	 *    @return     array       					Array of contacts emails
2260 2260
 	 */
2261
-	function thirdparty_and_contact_email_array($addthirdparty=0)
2261
+	function thirdparty_and_contact_email_array($addthirdparty = 0)
2262 2262
 	{
2263 2263
         // phpcs:enable
2264 2264
 		global $langs;
2265 2265
 
2266
-		$contact_emails = $this->contact_property_array('email',1);
2266
+		$contact_emails = $this->contact_property_array('email', 1);
2267 2267
 		if ($this->email && $addthirdparty)
2268 2268
 		{
2269
-			if (empty($this->name)) $this->name=$this->nom;
2270
-			$contact_emails['thirdparty']=$langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->email.">";
2269
+			if (empty($this->name)) $this->name = $this->nom;
2270
+			$contact_emails['thirdparty'] = $langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name, 16)." <".$this->email.">";
2271 2271
 		}
2272 2272
 		//var_dump($contact_emails)
2273 2273
 		return $contact_emails;
@@ -2286,11 +2286,11 @@  discard block
 block discarded – undo
2286 2286
 
2287 2287
 		$contact_phone = $this->contact_property_array('mobile');
2288 2288
 
2289
-		if (! empty($this->phone))	// If a phone of thirdparty is defined, we add it ot mobile of contacts
2289
+		if (!empty($this->phone))	// If a phone of thirdparty is defined, we add it ot mobile of contacts
2290 2290
 		{
2291
-			if (empty($this->name)) $this->name=$this->nom;
2291
+			if (empty($this->name)) $this->name = $this->nom;
2292 2292
 			// TODO: Tester si tel non deja present dans tableau contact
2293
-			$contact_phone['thirdparty']=$langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->phone.">";
2293
+			$contact_phone['thirdparty'] = $langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name, 16)." <".$this->phone.">";
2294 2294
 		}
2295 2295
 		return $contact_phone;
2296 2296
 	}
@@ -2303,7 +2303,7 @@  discard block
 block discarded – undo
2303 2303
 	 * 	@param	int		$hidedisabled		1=Hide contact if disabled
2304 2304
 	 *  @return array       				Array of contacts emails or mobile. Example: array(id=>'Name <email>')
2305 2305
 	 */
2306
-	function contact_property_array($mode='email', $hidedisabled=0)
2306
+	function contact_property_array($mode = 'email', $hidedisabled = 0)
2307 2307
 	{
2308 2308
         // phpcs:enable
2309 2309
 		global $langs;
@@ -2312,45 +2312,45 @@  discard block
 block discarded – undo
2312 2312
 
2313 2313
 
2314 2314
 		$sql = "SELECT rowid, email, statut, phone_mobile, lastname, poste, firstname";
2315
-		$sql.= " FROM ".MAIN_DB_PREFIX."socpeople";
2316
-		$sql.= " WHERE fk_soc = ".$this->id;
2315
+		$sql .= " FROM ".MAIN_DB_PREFIX."socpeople";
2316
+		$sql .= " WHERE fk_soc = ".$this->id;
2317 2317
 
2318
-		$resql=$this->db->query($sql);
2318
+		$resql = $this->db->query($sql);
2319 2319
 		if ($resql)
2320 2320
 		{
2321 2321
 			$nump = $this->db->num_rows($resql);
2322 2322
 			if ($nump)
2323 2323
 			{
2324
-				$sepa="("; $sepb=")";
2324
+				$sepa = "("; $sepb = ")";
2325 2325
 				if ($mode == 'email')
2326 2326
 				{
2327 2327
 					//$sepa="&lt;"; $sepb="&gt;";
2328
-					$sepa="<"; $sepb=">";
2328
+					$sepa = "<"; $sepb = ">";
2329 2329
 				}
2330 2330
 				$i = 0;
2331 2331
 				while ($i < $nump)
2332 2332
 				{
2333 2333
 					$obj = $this->db->fetch_object($resql);
2334
-					if ($mode == 'email') $property=$obj->email;
2335
-					else if ($mode == 'mobile') $property=$obj->phone_mobile;
2336
-					else $property=$obj->$mode;
2334
+					if ($mode == 'email') $property = $obj->email;
2335
+					else if ($mode == 'mobile') $property = $obj->phone_mobile;
2336
+					else $property = $obj->$mode;
2337 2337
 
2338 2338
 					// Show all contact. If hidedisabled is 1, showonly contacts with status = 1
2339 2339
 					if ($obj->statut == 1 || empty($hidedisabled))
2340 2340
 					{
2341 2341
 						if (empty($property))
2342 2342
 						{
2343
-							if ($mode == 'email') $property=$langs->transnoentitiesnoconv("NoEMail");
2344
-							else if ($mode == 'mobile') $property=$langs->transnoentitiesnoconv("NoMobilePhone");
2343
+							if ($mode == 'email') $property = $langs->transnoentitiesnoconv("NoEMail");
2344
+							else if ($mode == 'mobile') $property = $langs->transnoentitiesnoconv("NoMobilePhone");
2345 2345
 						}
2346 2346
 
2347 2347
 						if (!empty($obj->poste))
2348 2348
 						{
2349
-							$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname,$obj->lastname)).($obj->poste?" - ".$obj->poste:"").(($mode != 'poste' && $property)?" ".$sepa.$property.$sepb:'');
2349
+							$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname, $obj->lastname)).($obj->poste ? " - ".$obj->poste : "").(($mode != 'poste' && $property) ? " ".$sepa.$property.$sepb : '');
2350 2350
 						}
2351 2351
 						else
2352 2352
 						{
2353
-							$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname,$obj->lastname)).(($mode != 'poste' && $property)?" ".$sepa.$property.$sepb:'');
2353
+							$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname, $obj->lastname)).(($mode != 'poste' && $property) ? " ".$sepa.$property.$sepb : '');
2354 2354
 						}
2355 2355
 					}
2356 2356
 					$i++;
@@ -2377,7 +2377,7 @@  discard block
 block discarded – undo
2377 2377
 		$contacts = array();
2378 2378
 
2379 2379
 		$sql = "SELECT rowid, lastname, firstname FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id;
2380
-		$resql=$this->db->query($sql);
2380
+		$resql = $this->db->query($sql);
2381 2381
 		if ($resql)
2382 2382
 		{
2383 2383
 			$nump = $this->db->num_rows($resql);
@@ -2387,7 +2387,7 @@  discard block
 block discarded – undo
2387 2387
 				while ($i < $nump)
2388 2388
 				{
2389 2389
 					$obj = $this->db->fetch_object($resql);
2390
-					$contacts[$obj->rowid] = dolGetFirstLastname($obj->firstname,$obj->lastname);
2390
+					$contacts[$obj->rowid] = dolGetFirstLastname($obj->firstname, $obj->lastname);
2391 2391
 					$i++;
2392 2392
 				}
2393 2393
 			}
@@ -2408,11 +2408,11 @@  discard block
 block discarded – undo
2408 2408
 	function contact_array_objects()
2409 2409
 	{
2410 2410
         // phpcs:enable
2411
-		require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
2411
+		require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
2412 2412
 		$contacts = array();
2413 2413
 
2414 2414
 		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."socpeople WHERE fk_soc = ".$this->id;
2415
-		$resql=$this->db->query($sql);
2415
+		$resql = $this->db->query($sql);
2416 2416
 		if ($resql)
2417 2417
 		{
2418 2418
 			$nump = $this->db->num_rows($resql);
@@ -2444,18 +2444,18 @@  discard block
 block discarded – undo
2444 2444
 	 *  @param  string	$mode       'email' or 'mobile'
2445 2445
 	 *  @return string  			Email of contact with format: "Full name <email>"
2446 2446
 	 */
2447
-	function contact_get_property($rowid,$mode)
2447
+	function contact_get_property($rowid, $mode)
2448 2448
 	{
2449 2449
         // phpcs:enable
2450
-		$contact_property='';
2450
+		$contact_property = '';
2451 2451
 
2452 2452
 		if (empty($rowid)) return '';
2453 2453
 
2454 2454
 		$sql = "SELECT rowid, email, phone_mobile, lastname, firstname";
2455
-		$sql.= " FROM ".MAIN_DB_PREFIX."socpeople";
2456
-		$sql.= " WHERE rowid = '".$rowid."'";
2455
+		$sql .= " FROM ".MAIN_DB_PREFIX."socpeople";
2456
+		$sql .= " WHERE rowid = '".$rowid."'";
2457 2457
 
2458
-		$resql=$this->db->query($sql);
2458
+		$resql = $this->db->query($sql);
2459 2459
 		if ($resql)
2460 2460
 		{
2461 2461
 			$nump = $this->db->num_rows($resql);
@@ -2483,13 +2483,13 @@  discard block
 block discarded – undo
2483 2483
 	 *	@param	string	$mode	'label' or 'rum' or 'format'
2484 2484
 	 *  @return	string			Bank number
2485 2485
 	 */
2486
-	function display_rib($mode='label')
2486
+	function display_rib($mode = 'label')
2487 2487
 	{
2488 2488
         // phpcs:enable
2489
-		require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
2489
+		require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
2490 2490
 
2491 2491
 		$bac = new CompanyBankAccount($this->db);
2492
-		$bac->fetch(0,$this->id);
2492
+		$bac->fetch(0, $this->id);
2493 2493
 
2494 2494
 		if ($mode == 'label')
2495 2495
 		{
@@ -2499,7 +2499,7 @@  discard block
 block discarded – undo
2499 2499
 		{
2500 2500
 			if (empty($bac->rum))
2501 2501
 			{
2502
-				require_once DOL_DOCUMENT_ROOT . '/compta/prelevement/class/bonprelevement.class.php';
2502
+				require_once DOL_DOCUMENT_ROOT.'/compta/prelevement/class/bonprelevement.class.php';
2503 2503
 				$prelevement = new BonPrelevement($this->db);
2504 2504
 				$bac->fetch_thirdparty();
2505 2505
 				$bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id);
@@ -2523,7 +2523,7 @@  discard block
 block discarded – undo
2523 2523
 	function get_all_rib()
2524 2524
 	{
2525 2525
         // phpcs:enable
2526
-		require_once DOL_DOCUMENT_ROOT . '/societe/class/companybankaccount.class.php';
2526
+		require_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
2527 2527
 		$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_rib WHERE type='ban' AND fk_soc = ".$this->id;
2528 2528
 		$result = $this->db->query($sql);
2529 2529
 		if (!$result) {
@@ -2553,23 +2553,23 @@  discard block
 block discarded – undo
2553 2553
 	 *	@param	int			$type		Should be 0 to say customer
2554 2554
 	 *  @return void
2555 2555
 	 */
2556
-	function get_codeclient($objsoc=0,$type=0)
2556
+	function get_codeclient($objsoc = 0, $type = 0)
2557 2557
 	{
2558 2558
         // phpcs:enable
2559 2559
 		global $conf;
2560
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2560
+		if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2561 2561
 		{
2562
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2562
+			$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2563 2563
 
2564
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2564
+			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2565 2565
 			foreach ($dirsociete as $dirroot)
2566 2566
 			{
2567
-				$res=dol_include_once($dirroot.$module.'.php');
2567
+				$res = dol_include_once($dirroot.$module.'.php');
2568 2568
 				if ($res) break;
2569 2569
 			}
2570 2570
 			$mod = new $module();
2571 2571
 
2572
-			$this->code_client = $mod->getNextValue($objsoc,$type);
2572
+			$this->code_client = $mod->getNextValue($objsoc, $type);
2573 2573
 			$this->prefixCustomerIsRequired = $mod->prefixIsRequired;
2574 2574
 
2575 2575
 			dol_syslog(get_class($this)."::get_codeclient code_client=".$this->code_client." module=".$module);
@@ -2585,23 +2585,23 @@  discard block
 block discarded – undo
2585 2585
 	 *	@param	int			$type		Should be 1 to say supplier
2586 2586
 	 *  @return void
2587 2587
 	 */
2588
-	function get_codefournisseur($objsoc=0,$type=1)
2588
+	function get_codefournisseur($objsoc = 0, $type = 1)
2589 2589
 	{
2590 2590
         // phpcs:enable
2591 2591
 		global $conf;
2592
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2592
+		if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2593 2593
 		{
2594
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2594
+			$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2595 2595
 
2596
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2596
+			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2597 2597
 			foreach ($dirsociete as $dirroot)
2598 2598
 			{
2599
-				$res=dol_include_once($dirroot.$module.'.php');
2599
+				$res = dol_include_once($dirroot.$module.'.php');
2600 2600
 				if ($res) break;
2601 2601
 			}
2602 2602
 			$mod = new $module();
2603 2603
 
2604
-			$this->code_fournisseur = $mod->getNextValue($objsoc,$type);
2604
+			$this->code_fournisseur = $mod->getNextValue($objsoc, $type);
2605 2605
 
2606 2606
 			dol_syslog(get_class($this)."::get_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$module);
2607 2607
 		}
@@ -2618,23 +2618,23 @@  discard block
 block discarded – undo
2618 2618
 	{
2619 2619
         // phpcs:enable
2620 2620
 		global $conf;
2621
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2621
+		if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2622 2622
 		{
2623
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2623
+			$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2624 2624
 
2625
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2625
+			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2626 2626
 			foreach ($dirsociete as $dirroot)
2627 2627
 			{
2628
-				$res=dol_include_once($dirroot.$module.'.php');
2628
+				$res = dol_include_once($dirroot.$module.'.php');
2629 2629
 				if ($res) break;
2630 2630
 			}
2631 2631
 
2632 2632
 			$mod = new $module();
2633 2633
 
2634 2634
 			dol_syslog(get_class($this)."::codeclient_modifiable code_client=".$this->code_client." module=".$module);
2635
-			if ($mod->code_modifiable_null && ! $this->code_client) return 1;
2635
+			if ($mod->code_modifiable_null && !$this->code_client) return 1;
2636 2636
 			if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) return 1;
2637
-			if ($mod->code_modifiable) return 1;	// A mettre en dernier
2637
+			if ($mod->code_modifiable) return 1; // A mettre en dernier
2638 2638
 			return 0;
2639 2639
 		}
2640 2640
 		else
@@ -2654,23 +2654,23 @@  discard block
 block discarded – undo
2654 2654
 	{
2655 2655
         // phpcs:enable
2656 2656
 		global $conf;
2657
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2657
+		if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2658 2658
 		{
2659
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2659
+			$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2660 2660
 
2661
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2661
+			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2662 2662
 			foreach ($dirsociete as $dirroot)
2663 2663
 			{
2664
-				$res=dol_include_once($dirroot.$module.'.php');
2664
+				$res = dol_include_once($dirroot.$module.'.php');
2665 2665
 				if ($res) break;
2666 2666
 			}
2667 2667
 
2668 2668
 			$mod = new $module();
2669 2669
 
2670 2670
 			dol_syslog(get_class($this)."::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur." module=".$module);
2671
-			if ($mod->code_modifiable_null && ! $this->code_fournisseur) return 1;
2671
+			if ($mod->code_modifiable_null && !$this->code_fournisseur) return 1;
2672 2672
 			if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) return 1;
2673
-			if ($mod->code_modifiable) return 1;	// A mettre en dernier
2673
+			if ($mod->code_modifiable) return 1; // A mettre en dernier
2674 2674
 			return 0;
2675 2675
 		}
2676 2676
 		else
@@ -2694,14 +2694,14 @@  discard block
 block discarded – undo
2694 2694
 	{
2695 2695
         // phpcs:enable
2696 2696
 		global $conf;
2697
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2697
+		if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2698 2698
 		{
2699
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2699
+			$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2700 2700
 
2701
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2701
+			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2702 2702
 			foreach ($dirsociete as $dirroot)
2703 2703
 			{
2704
-				$res=dol_include_once($dirroot.$module.'.php');
2704
+				$res = dol_include_once($dirroot.$module.'.php');
2705 2705
 				if ($res) break;
2706 2706
 			}
2707 2707
 
@@ -2731,14 +2731,14 @@  discard block
 block discarded – undo
2731 2731
 	{
2732 2732
         // phpcs:enable
2733 2733
 		global $conf;
2734
-		if (! empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2734
+		if (!empty($conf->global->SOCIETE_CODECLIENT_ADDON))
2735 2735
 		{
2736
-			$module=$conf->global->SOCIETE_CODECLIENT_ADDON;
2736
+			$module = $conf->global->SOCIETE_CODECLIENT_ADDON;
2737 2737
 
2738
-			$dirsociete=array_merge(array('/core/modules/societe/'),$conf->modules_parts['societe']);
2738
+			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2739 2739
 			foreach ($dirsociete as $dirroot)
2740 2740
 			{
2741
-				$res=dol_include_once($dirroot.$module.'.php');
2741
+				$res = dol_include_once($dirroot.$module.'.php');
2742 2742
 				if ($res) break;
2743 2743
 			}
2744 2744
 
@@ -2768,13 +2768,13 @@  discard block
 block discarded – undo
2768 2768
         // phpcs:enable
2769 2769
 		global $conf;
2770 2770
 
2771
-		if (! empty($conf->global->SOCIETE_CODECOMPTA_ADDON))
2771
+		if (!empty($conf->global->SOCIETE_CODECOMPTA_ADDON))
2772 2772
 		{
2773
-			$res=false;
2774
-			$dirsociete=array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2773
+			$res = false;
2774
+			$dirsociete = array_merge(array('/core/modules/societe/'), $conf->modules_parts['societe']);
2775 2775
 			foreach ($dirsociete as $dirroot)
2776 2776
 			{
2777
-				$res=dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.'.php');
2777
+				$res = dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.'.php');
2778 2778
 				if ($res) break;
2779 2779
 			}
2780 2780
 
@@ -2819,10 +2819,10 @@  discard block
 block discarded – undo
2819 2819
 		if ($this->id)
2820 2820
 		{
2821 2821
 			$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
2822
-			$sql.= " SET parent = ".($id > 0 ? $id : "null");
2823
-			$sql.= " WHERE rowid = " . $this->id;
2822
+			$sql .= " SET parent = ".($id > 0 ? $id : "null");
2823
+			$sql .= " WHERE rowid = ".$this->id;
2824 2824
 			dol_syslog(get_class($this).'::set_parent', LOG_DEBUG);
2825
-			$resql=$this->db->query($sql);
2825
+			$resql = $this->db->query($sql);
2826 2826
 			if ($resql)
2827 2827
 			{
2828 2828
 				$this->parent = $id;
@@ -2848,28 +2848,28 @@  discard block
 block discarded – undo
2848 2848
         // phpcs:enable
2849 2849
 		global $conf;
2850 2850
 
2851
-	 	switch($idprof)
2851
+	 	switch ($idprof)
2852 2852
 		{
2853 2853
 			case 1:
2854
-				$ret=(!$conf->global->SOCIETE_IDPROF1_UNIQUE?false:true);
2854
+				$ret = (!$conf->global->SOCIETE_IDPROF1_UNIQUE ?false:true);
2855 2855
 				break;
2856 2856
 			case 2:
2857
-				$ret=(!$conf->global->SOCIETE_IDPROF2_UNIQUE?false:true);
2857
+				$ret = (!$conf->global->SOCIETE_IDPROF2_UNIQUE ?false:true);
2858 2858
 				break;
2859 2859
 			case 3:
2860
-				$ret=(!$conf->global->SOCIETE_IDPROF3_UNIQUE?false:true);
2860
+				$ret = (!$conf->global->SOCIETE_IDPROF3_UNIQUE ?false:true);
2861 2861
 				break;
2862 2862
 			case 4:
2863
-				$ret=(!$conf->global->SOCIETE_IDPROF4_UNIQUE?false:true);
2863
+				$ret = (!$conf->global->SOCIETE_IDPROF4_UNIQUE ?false:true);
2864 2864
 				break;
2865 2865
 			case 5:
2866
-				$ret=(!$conf->global->SOCIETE_IDPROF5_UNIQUE?false:true);
2866
+				$ret = (!$conf->global->SOCIETE_IDPROF5_UNIQUE ?false:true);
2867 2867
 				break;
2868 2868
 			case 6:
2869
-				$ret=(!$conf->global->SOCIETE_IDPROF6_UNIQUE?false:true);
2869
+				$ret = (!$conf->global->SOCIETE_IDPROF6_UNIQUE ?false:true);
2870 2870
 				break;
2871 2871
 			default:
2872
-				$ret=false;
2872
+				$ret = false;
2873 2873
 		}
2874 2874
 
2875 2875
 		return $ret;
@@ -2884,40 +2884,40 @@  discard block
 block discarded – undo
2884 2884
 	 *    @param	int		$socid		Id of thirdparty to exclude (if update)
2885 2885
 	 *    @return   boolean				True if exists, False if not
2886 2886
 	 */
2887
-	function id_prof_exists($idprof, $value, $socid=0)
2887
+	function id_prof_exists($idprof, $value, $socid = 0)
2888 2888
 	{
2889 2889
         // phpcs:enable
2890 2890
 		$field = $idprof;
2891 2891
 
2892
-	 	switch($idprof)	// For backward compatibility
2892
+	 	switch ($idprof)	// For backward compatibility
2893 2893
 		{
2894 2894
 			case '1':
2895 2895
 			case 'idprof1':
2896
-				$field="siren";
2896
+				$field = "siren";
2897 2897
 				break;
2898 2898
 			case '2':
2899 2899
 			case 'idprof2':
2900
-				$field="siret";
2900
+				$field = "siret";
2901 2901
 				break;
2902 2902
 			case '3':
2903 2903
 			case 'idprof3':
2904
-				$field="ape";
2904
+				$field = "ape";
2905 2905
 				break;
2906 2906
 			case '4':
2907 2907
 			case 'idprof4':
2908
-				$field="idprof4";
2908
+				$field = "idprof4";
2909 2909
 				break;
2910 2910
 			case '5':
2911
-				$field="idprof5";
2911
+				$field = "idprof5";
2912 2912
 				break;
2913 2913
 			case '6':
2914
-				$field="idprof6";
2914
+				$field = "idprof6";
2915 2915
 				break;
2916 2916
 	 	}
2917 2917
 
2918 2918
 		 //Verify duplicate entries
2919
-		$sql  = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$value."' AND entity IN (".getEntity('societe').")";
2920
-		if($socid) $sql .= " AND rowid <> ".$socid;
2919
+		$sql = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$value."' AND entity IN (".getEntity('societe').")";
2920
+		if ($socid) $sql .= " AND rowid <> ".$socid;
2921 2921
 		$resql = $this->db->query($sql);
2922 2922
 		if ($resql)
2923 2923
 		{
@@ -2944,20 +2944,20 @@  discard block
 block discarded – undo
2944 2944
 	 *  @return int             			<=0 if KO, >0 if OK
2945 2945
 	 *  TODO better to have this in a lib than into a business class
2946 2946
 	 */
2947
-	function id_prof_check($idprof,$soc)
2947
+	function id_prof_check($idprof, $soc)
2948 2948
 	{
2949 2949
         // phpcs:enable
2950 2950
 		global $conf;
2951 2951
 
2952
-		$ok=1;
2952
+		$ok = 1;
2953 2953
 
2954
-		if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) return 1;
2954
+		if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) return 1;
2955 2955
 
2956 2956
 		// Verifie SIREN si pays FR
2957 2957
 		if ($idprof == 1 && $soc->country_code == 'FR')
2958 2958
 		{
2959
-			$chaine=trim($this->idprof1);
2960
-			$chaine=preg_replace('/(\s)/','',$chaine);
2959
+			$chaine = trim($this->idprof1);
2960
+			$chaine = preg_replace('/(\s)/', '', $chaine);
2961 2961
 
2962 2962
 			if (!is_numeric($chaine)) return -1;
2963 2963
 			if (dol_strlen($chaine) != 9) return -1;
@@ -2967,7 +2967,7 @@  discard block
 block discarded – undo
2967 2967
 			// on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9
2968 2968
 			// on ajoute cette valeur à la somme totale
2969 2969
 
2970
-			for ($index = 0; $index < 9; $index ++)
2970
+			for ($index = 0; $index < 9; $index++)
2971 2971
 			{
2972 2972
 				$number = (int) $siren[$index];
2973 2973
 				if (($index % 2) != 0) { if (($number *= 2) > 9) $number -= 9; }
@@ -2981,8 +2981,8 @@  discard block
 block discarded – undo
2981 2981
 		// Verifie SIRET si pays FR
2982 2982
 		if ($idprof == 2 && $soc->country_code == 'FR')
2983 2983
 		{
2984
-			$chaine=trim($this->idprof2);
2985
-			$chaine=preg_replace('/(\s)/','',$chaine);
2984
+			$chaine = trim($this->idprof2);
2985
+			$chaine = preg_replace('/(\s)/', '', $chaine);
2986 2986
 
2987 2987
 			if (!is_numeric($chaine)) return -1;
2988 2988
 			if (dol_strlen($chaine) != 14) return -1;
@@ -2992,7 +2992,7 @@  discard block
 block discarded – undo
2992 2992
 			// on double sa valeur et si cette dernière est supérieure à 9, on lui retranche 9
2993 2993
 			// on ajoute cette valeur à la somme totale
2994 2994
 
2995
-			for ($index = 0; $index < 14; $index ++)
2995
+			for ($index = 0; $index < 14; $index++)
2996 2996
 			{
2997 2997
 				$number = (int) $chaine[$index];
2998 2998
 				if (($index % 2) == 0) { if (($number *= 2) > 9) $number -= 9; }
@@ -3007,11 +3007,11 @@  discard block
 block discarded – undo
3007 3007
 		//Returns: 1 if NIF ok, 2 if CIF ok, 3 if NIE ok, -1 if NIF bad, -2 if CIF bad, -3 if NIE bad, 0 if unexpected bad
3008 3008
 		if ($idprof == 1 && $soc->country_code == 'ES')
3009 3009
 		{
3010
-			$string=trim($this->idprof1);
3011
-			$string=preg_replace('/(\s)/','',$string);
3010
+			$string = trim($this->idprof1);
3011
+			$string = preg_replace('/(\s)/', '', $string);
3012 3012
 			$string = strtoupper($string);
3013 3013
 
3014
-			for ($i = 0; $i < 9; $i ++)
3014
+			for ($i = 0; $i < 9; $i++)
3015 3015
 			$num[$i] = substr($string, $i, 1);
3016 3016
 
3017 3017
 			//Check format
@@ -3028,7 +3028,7 @@  discard block
 block discarded – undo
3028 3028
 			//algorithm checking type code CIF
3029 3029
 			$sum = $num[2] + $num[4] + $num[6];
3030 3030
 			for ($i = 1; $i < 8; $i += 2)
3031
-			$sum += intval(substr((2 * $num[$i]),0,1)) + intval(substr((2 * $num[$i]),1,1));
3031
+			$sum += intval(substr((2 * $num[$i]), 0, 1)) + intval(substr((2 * $num[$i]), 1, 1));
3032 3032
 			$n = 10 - substr($sum, strlen($sum) - 1, 1);
3033 3033
 
3034 3034
 			//Chek special NIF
@@ -3054,7 +3054,7 @@  discard block
 block discarded – undo
3054 3054
 
3055 3055
 			//Check NIE XYZ
3056 3056
 			if (preg_match('/^[XYZ]{1}/', $string))
3057
-				if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X','Y','Z'), array('0','1','2'), $string), 0, 8) % 23, 1))
3057
+				if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X', 'Y', 'Z'), array('0', '1', '2'), $string), 0, 8) % 23, 1))
3058 3058
 				return 3;
3059 3059
 				else
3060 3060
 				return -3;
@@ -3067,10 +3067,10 @@  discard block
 block discarded – undo
3067 3067
 		//Returns: 1 if NIF ok, -1 if NIF bad, 0 if unexpected bad
3068 3068
 		if ($idprof == 1 && $soc->country_code == 'PT')
3069 3069
 		{
3070
-			$string=trim($this->idprof1);
3071
-			$string=preg_replace('/(\s)/','',$string);
3070
+			$string = trim($this->idprof1);
3071
+			$string = preg_replace('/(\s)/', '', $string);
3072 3072
 
3073
-			for ($i = 0; $i < 9; $i ++) {
3073
+			for ($i = 0; $i < 9; $i++) {
3074 3074
 				$num[$i] = substr($string, $i, 1);
3075 3075
 			}
3076 3076
 
@@ -3095,38 +3095,38 @@  discard block
 block discarded – undo
3095 3095
 	 *   @return	string          		Url or empty string if no URL known
3096 3096
 	 *   TODO better in a lib than into business class
3097 3097
 	 */
3098
-	function id_prof_url($idprof,$thirdparty)
3098
+	function id_prof_url($idprof, $thirdparty)
3099 3099
 	{
3100 3100
         // phpcs:enable
3101
-		global $conf,$langs,$hookmanager;
3101
+		global $conf, $langs, $hookmanager;
3102 3102
 
3103
-		$url='';
3103
+		$url = '';
3104 3104
 		$action = '';
3105 3105
 
3106 3106
 		$hookmanager->initHooks(array('idprofurl'));
3107
-		$parameters=array('idprof'=>$idprof, 'company'=>$thirdparty);
3108
-		$reshook=$hookmanager->executeHooks('getIdProfUrl',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
3107
+		$parameters = array('idprof'=>$idprof, 'company'=>$thirdparty);
3108
+		$reshook = $hookmanager->executeHooks('getIdProfUrl', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
3109 3109
 		if (empty($reshook)) {
3110
-			if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
3110
+			if (!empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
3111 3111
 				return '';
3112 3112
 			}
3113 3113
 
3114 3114
 			// TODO Move links to validate professional ID into a dictionary table "country" + "link"
3115 3115
             $strippedIdProf1 = str_replace(' ', '', $thirdparty->idprof1);
3116 3116
 			if ($idprof == 1 && $thirdparty->country_code == 'FR') {
3117
-				$url='http://www.societe.com/cgi-bin/search?champs='.$strippedIdProf1;    // See also http://avis-situation-sirene.insee.fr/
3117
+				$url = 'http://www.societe.com/cgi-bin/search?champs='.$strippedIdProf1; // See also http://avis-situation-sirene.insee.fr/
3118 3118
 			}
3119 3119
 			if ($idprof == 1 && ($thirdparty->country_code == 'GB' || $thirdparty->country_code == 'UK')) {
3120
-				$url='https://beta.companieshouse.gov.uk/company/'.$strippedIdProf1;
3120
+				$url = 'https://beta.companieshouse.gov.uk/company/'.$strippedIdProf1;
3121 3121
 			}
3122 3122
 			if ($idprof == 1 && $thirdparty->country_code == 'ES') {
3123
-				$url='http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$strippedIdProf1;
3123
+				$url = 'http://www.e-informa.es/servlet/app/portal/ENTP/screen/SProducto/prod/ETIQUETA_EMPRESA/nif/'.$strippedIdProf1;
3124 3124
 			}
3125 3125
 			if ($idprof == 1 && $thirdparty->country_code == 'IN') {
3126
-				$url='http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$strippedIdProf1.';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
3126
+				$url = 'http://www.tinxsys.com/TinxsysInternetWeb/dealerControllerServlet?tinNumber='.$strippedIdProf1.';&searchBy=TIN&backPage=searchByTin_Inter.jsp';
3127 3127
 			}
3128 3128
 			if ($idprof == 1 && $thirdparty->country_code == 'PT') {
3129
-				$url='http://www.nif.pt/'.$strippedIdProf1;
3129
+				$url = 'http://www.nif.pt/'.$strippedIdProf1;
3130 3130
 			}
3131 3131
 
3132 3132
 			if ($url) {
@@ -3149,7 +3149,7 @@  discard block
 block discarded – undo
3149 3149
 	function has_projects()
3150 3150
 	{
3151 3151
         // phpcs:enable
3152
-		$sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = ' . $this->id;
3152
+		$sql = 'SELECT COUNT(*) as numproj FROM '.MAIN_DB_PREFIX.'projet WHERE fk_soc = '.$this->id;
3153 3153
 		$resql = $this->db->query($sql);
3154 3154
 		if ($resql)
3155 3155
 		{
@@ -3175,11 +3175,11 @@  discard block
 block discarded – undo
3175 3175
 	function info($id)
3176 3176
 	{
3177 3177
 		$sql = "SELECT s.rowid, s.nom as name, s.datec as date_creation, tms as date_modification,";
3178
-		$sql.= " fk_user_creat, fk_user_modif";
3179
-		$sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
3180
-		$sql.= " WHERE s.rowid = ".$id;
3178
+		$sql .= " fk_user_creat, fk_user_modif";
3179
+		$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
3180
+		$sql .= " WHERE s.rowid = ".$id;
3181 3181
 
3182
-		$result=$this->db->query($sql);
3182
+		$result = $this->db->query($sql);
3183 3183
 		if ($result)
3184 3184
 		{
3185 3185
 			if ($this->db->num_rows($result))
@@ -3191,7 +3191,7 @@  discard block
 block discarded – undo
3191 3191
 				if ($obj->fk_user_creat) {
3192 3192
 					$cuser = new User($this->db);
3193 3193
 					$cuser->fetch($obj->fk_user_creat);
3194
-					$this->user_creation     = $cuser;
3194
+					$this->user_creation = $cuser;
3195 3195
 				}
3196 3196
 
3197 3197
 				if ($obj->fk_user_modif) {
@@ -3200,7 +3200,7 @@  discard block
 block discarded – undo
3200 3200
 					$this->user_modification = $muser;
3201 3201
 				}
3202 3202
 
3203
-				$this->ref			     = $obj->name;
3203
+				$this->ref = $obj->name;
3204 3204
 				$this->date_creation     = $this->db->jdate($obj->date_creation);
3205 3205
 				$this->date_modification = $this->db->jdate($obj->date_modification);
3206 3206
 			}
@@ -3223,13 +3223,13 @@  discard block
 block discarded – undo
3223 3223
 		global $conf;
3224 3224
 
3225 3225
 		// Define if third party is treated as company (or not) when nature is unknown
3226
-		$isacompany=empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES)?0:1; // 0 by default
3227
-		if (! empty($this->tva_intra)) $isacompany=1;
3228
-		else if (! empty($this->typent_code) && $this->typent_code != 'TE_UNKNOWN')
3226
+		$isacompany = empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES) ? 0 : 1; // 0 by default
3227
+		if (!empty($this->tva_intra)) $isacompany = 1;
3228
+		else if (!empty($this->typent_code) && $this->typent_code != 'TE_UNKNOWN')
3229 3229
 		{
3230 3230
 			// TODO Add a field is_a_company into dictionary
3231
-			if (preg_match('/^TE_PRIVATE/', $this->typent_code)) $isacompany=0;
3232
-			else $isacompany=1;
3231
+			if (preg_match('/^TE_PRIVATE/', $this->typent_code)) $isacompany = 0;
3232
+			else $isacompany = 1;
3233 3233
 		}
3234 3234
 
3235 3235
 		return $isacompany;
@@ -3257,13 +3257,13 @@  discard block
 block discarded – undo
3257 3257
         // phpcs:enable
3258 3258
 		$this->SupplierCategories = array();
3259 3259
 		$sql = "SELECT rowid, label";
3260
-		$sql.= " FROM ".MAIN_DB_PREFIX."categorie";
3261
-		$sql.= " WHERE type = ".Categorie::TYPE_SUPPLIER;
3260
+		$sql .= " FROM ".MAIN_DB_PREFIX."categorie";
3261
+		$sql .= " WHERE type = ".Categorie::TYPE_SUPPLIER;
3262 3262
 
3263
-		$resql=$this->db->query($sql);
3263
+		$resql = $this->db->query($sql);
3264 3264
 		if ($resql)
3265 3265
 		{
3266
-			while ($obj = $this->db->fetch_object($resql) )
3266
+			while ($obj = $this->db->fetch_object($resql))
3267 3267
 			{
3268 3268
 				$this->SupplierCategories[$obj->rowid] = $obj->label;
3269 3269
 			}
@@ -3288,9 +3288,9 @@  discard block
 block discarded – undo
3288 3288
 		if ($categorie_id > 0 && $this->id > 0)
3289 3289
 		{
3290 3290
 			$sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_fournisseur (fk_categorie, fk_soc) ";
3291
-			$sql.= " VALUES (".$categorie_id.", ".$this->id.")";
3291
+			$sql .= " VALUES (".$categorie_id.", ".$this->id.")";
3292 3292
 
3293
-			if ($resql=$this->db->query($sql)) return 0;
3293
+			if ($resql = $this->db->query($sql)) return 0;
3294 3294
 		}
3295 3295
 		else
3296 3296
 		{
@@ -3310,48 +3310,48 @@  discard block
 block discarded – undo
3310 3310
 	 *  @param	string		$customercode	Customer code
3311 3311
 	 *  @return int							<0 if KO, id of created account if OK
3312 3312
 	 */
3313
-	function create_from_member(Adherent $member, $socname='', $socalias='', $customercode='')
3313
+	function create_from_member(Adherent $member, $socname = '', $socalias = '', $customercode = '')
3314 3314
 	{
3315 3315
         // phpcs:enable
3316
-		global $user,$langs;
3316
+		global $user, $langs;
3317 3317
 
3318 3318
 		dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG);
3319 3319
 
3320
-		$name = $socname?$socname:$member->societe;
3321
-		if (empty($name)) $name=$member->getFullName($langs);
3320
+		$name = $socname ? $socname : $member->societe;
3321
+		if (empty($name)) $name = $member->getFullName($langs);
3322 3322
 
3323
-		$alias = $socalias?$socalias:'';
3323
+		$alias = $socalias ? $socalias : '';
3324 3324
 
3325 3325
 		// Positionne parametres
3326
-		$this->nom=$name;				// TODO deprecated
3327
-		$this->name=$name;
3328
-		$this->name_alias=$alias;
3329
-		$this->address=$member->address;
3330
-		$this->zip=$member->zip;
3331
-		$this->town=$member->town;
3332
-		$this->country_code=$member->country_code;
3333
-		$this->country_id=$member->country_id;
3334
-		$this->phone=$member->phone;       // Prof phone
3335
-		$this->email=$member->email;
3336
-		$this->skype=$member->skype;
3337
-		$this->twitter=$member->twitter;
3338
-		$this->facebook=$member->facebook;
3339
-
3340
-		$this->client = 1;				// A member is a customer by default
3341
-		$this->code_client = ($customercode?$customercode:-1);
3326
+		$this->nom = $name; // TODO deprecated
3327
+		$this->name = $name;
3328
+		$this->name_alias = $alias;
3329
+		$this->address = $member->address;
3330
+		$this->zip = $member->zip;
3331
+		$this->town = $member->town;
3332
+		$this->country_code = $member->country_code;
3333
+		$this->country_id = $member->country_id;
3334
+		$this->phone = $member->phone; // Prof phone
3335
+		$this->email = $member->email;
3336
+		$this->skype = $member->skype;
3337
+		$this->twitter = $member->twitter;
3338
+		$this->facebook = $member->facebook;
3339
+
3340
+		$this->client = 1; // A member is a customer by default
3341
+		$this->code_client = ($customercode ? $customercode : -1);
3342 3342
 		$this->code_fournisseur = -1;
3343 3343
 
3344 3344
 		$this->db->begin();
3345 3345
 
3346 3346
 		// Cree et positionne $this->id
3347
-		$result=$this->create($user);
3347
+		$result = $this->create($user);
3348 3348
 		if ($result >= 0)
3349 3349
 		{
3350 3350
 			$sql = "UPDATE ".MAIN_DB_PREFIX."adherent";
3351
-			$sql.= " SET fk_soc=".$this->id;
3352
-			$sql.= " WHERE rowid=".$member->id;
3351
+			$sql .= " SET fk_soc=".$this->id;
3352
+			$sql .= " WHERE rowid=".$member->id;
3353 3353
 
3354
-			$resql=$this->db->query($sql);
3354
+			$resql = $this->db->query($sql);
3355 3355
 			if ($resql)
3356 3356
 			{
3357 3357
 				$this->db->commit();
@@ -3359,7 +3359,7 @@  discard block
 block discarded – undo
3359 3359
 			}
3360 3360
 			else
3361 3361
 			{
3362
-				$this->error=$this->db->error();
3362
+				$this->error = $this->db->error();
3363 3363
 
3364 3364
 				$this->db->rollback();
3365 3365
 				return -1;
@@ -3368,7 +3368,7 @@  discard block
 block discarded – undo
3368 3368
 		else
3369 3369
 		{
3370 3370
 			// $this->error deja positionne
3371
-			dol_syslog(get_class($this)."::create_from_member - 2 - ".$this->error." - ".join(',',$this->errors), LOG_ERR);
3371
+			dol_syslog(get_class($this)."::create_from_member - 2 - ".$this->error." - ".join(',', $this->errors), LOG_ERR);
3372 3372
 
3373 3373
 			$this->db->rollback();
3374 3374
 			return $result;
@@ -3385,68 +3385,68 @@  discard block
 block discarded – undo
3385 3385
 	{
3386 3386
 		global $langs;
3387 3387
 
3388
-		$this->id=0;
3389
-		$this->name=empty($conf->global->MAIN_INFO_SOCIETE_NOM)?'':$conf->global->MAIN_INFO_SOCIETE_NOM;
3390
-		$this->address=empty($conf->global->MAIN_INFO_SOCIETE_ADDRESS)?'':$conf->global->MAIN_INFO_SOCIETE_ADDRESS;
3391
-		$this->zip=empty($conf->global->MAIN_INFO_SOCIETE_ZIP)?'':$conf->global->MAIN_INFO_SOCIETE_ZIP;
3392
-		$this->town=empty($conf->global->MAIN_INFO_SOCIETE_TOWN)?'':$conf->global->MAIN_INFO_SOCIETE_TOWN;
3393
-		$this->state_id=empty($conf->global->MAIN_INFO_SOCIETE_STATE)?'':$conf->global->MAIN_INFO_SOCIETE_STATE;
3394
-		$this->region_code=empty($conf->global->MAIN_INFO_SOCIETE_REGION)?'':$conf->global->MAIN_INFO_SOCIETE_REGION;
3395
-		$this->object=empty($conf->global->MAIN_INFO_SOCIETE_OBJECT)?'':$conf->global->MAIN_INFO_SOCIETE_OBJECT;
3388
+		$this->id = 0;
3389
+		$this->name = empty($conf->global->MAIN_INFO_SOCIETE_NOM) ? '' : $conf->global->MAIN_INFO_SOCIETE_NOM;
3390
+		$this->address = empty($conf->global->MAIN_INFO_SOCIETE_ADDRESS) ? '' : $conf->global->MAIN_INFO_SOCIETE_ADDRESS;
3391
+		$this->zip = empty($conf->global->MAIN_INFO_SOCIETE_ZIP) ? '' : $conf->global->MAIN_INFO_SOCIETE_ZIP;
3392
+		$this->town = empty($conf->global->MAIN_INFO_SOCIETE_TOWN) ? '' : $conf->global->MAIN_INFO_SOCIETE_TOWN;
3393
+		$this->state_id = empty($conf->global->MAIN_INFO_SOCIETE_STATE) ? '' : $conf->global->MAIN_INFO_SOCIETE_STATE;
3394
+		$this->region_code = empty($conf->global->MAIN_INFO_SOCIETE_REGION) ? '' : $conf->global->MAIN_INFO_SOCIETE_REGION;
3395
+		$this->object = empty($conf->global->MAIN_INFO_SOCIETE_OBJECT) ? '' : $conf->global->MAIN_INFO_SOCIETE_OBJECT;
3396 3396
 
3397
-		$this->note_private=empty($conf->global->MAIN_INFO_SOCIETE_NOTE)?'':$conf->global->MAIN_INFO_SOCIETE_NOTE;
3397
+		$this->note_private = empty($conf->global->MAIN_INFO_SOCIETE_NOTE) ? '' : $conf->global->MAIN_INFO_SOCIETE_NOTE;
3398 3398
 
3399
-		$this->nom=$this->name; 									// deprecated
3399
+		$this->nom = $this->name; // deprecated
3400 3400
 
3401 3401
 		// We define country_id, country_code and country
3402
-		$country_id=$country_code=$country_label='';
3403
-		if (! empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY))
3402
+		$country_id = $country_code = $country_label = '';
3403
+		if (!empty($conf->global->MAIN_INFO_SOCIETE_COUNTRY))
3404 3404
 		{
3405
-			$tmp=explode(':',$conf->global->MAIN_INFO_SOCIETE_COUNTRY);
3406
-			$country_id=$tmp[0];
3407
-			if (! empty($tmp[1]))   // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label"
3405
+			$tmp = explode(':', $conf->global->MAIN_INFO_SOCIETE_COUNTRY);
3406
+			$country_id = $tmp[0];
3407
+			if (!empty($tmp[1]))   // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label"
3408 3408
 			{
3409
-				$country_code=$tmp[1];
3410
-				$country_label=$tmp[2];
3409
+				$country_code = $tmp[1];
3410
+				$country_label = $tmp[2];
3411 3411
 			}
3412 3412
 			else                    // For backward compatibility
3413 3413
 			{
3414 3414
 				dol_syslog("Your country setup use an old syntax. Reedit it using setup area.", LOG_ERR);
3415 3415
 				include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
3416
-				$country_code=getCountry($country_id,2,$this->db);  // This need a SQL request, but it's the old feature that should not be used anymore
3417
-				$country_label=getCountry($country_id,0,$this->db);  // This need a SQL request, but it's the old feature that should not be used anymore
3416
+				$country_code = getCountry($country_id, 2, $this->db); // This need a SQL request, but it's the old feature that should not be used anymore
3417
+				$country_label = getCountry($country_id, 0, $this->db); // This need a SQL request, but it's the old feature that should not be used anymore
3418 3418
 			}
3419 3419
 		}
3420
-		$this->country_id=$country_id;
3421
-		$this->country_code=$country_code;
3422
-		$this->country=$country_label;
3423
-		if (is_object($langs)) $this->country=($langs->trans('Country'.$country_code)!='Country'.$country_code)?$langs->trans('Country'.$country_code):$country_label;
3420
+		$this->country_id = $country_id;
3421
+		$this->country_code = $country_code;
3422
+		$this->country = $country_label;
3423
+		if (is_object($langs)) $this->country = ($langs->trans('Country'.$country_code) != 'Country'.$country_code) ? $langs->trans('Country'.$country_code) : $country_label;
3424 3424
 
3425
-		$this->phone=empty($conf->global->MAIN_INFO_SOCIETE_TEL)?'':$conf->global->MAIN_INFO_SOCIETE_TEL;
3426
-		$this->fax=empty($conf->global->MAIN_INFO_SOCIETE_FAX)?'':$conf->global->MAIN_INFO_SOCIETE_FAX;
3427
-		$this->url=empty($conf->global->MAIN_INFO_SOCIETE_WEB)?'':$conf->global->MAIN_INFO_SOCIETE_WEB;
3425
+		$this->phone = empty($conf->global->MAIN_INFO_SOCIETE_TEL) ? '' : $conf->global->MAIN_INFO_SOCIETE_TEL;
3426
+		$this->fax = empty($conf->global->MAIN_INFO_SOCIETE_FAX) ? '' : $conf->global->MAIN_INFO_SOCIETE_FAX;
3427
+		$this->url = empty($conf->global->MAIN_INFO_SOCIETE_WEB) ? '' : $conf->global->MAIN_INFO_SOCIETE_WEB;
3428 3428
 		// Id prof generiques
3429
-		$this->idprof1=empty($conf->global->MAIN_INFO_SIREN)?'':$conf->global->MAIN_INFO_SIREN;
3430
-		$this->idprof2=empty($conf->global->MAIN_INFO_SIRET)?'':$conf->global->MAIN_INFO_SIRET;
3431
-		$this->idprof3=empty($conf->global->MAIN_INFO_APE)?'':$conf->global->MAIN_INFO_APE;
3432
-		$this->idprof4=empty($conf->global->MAIN_INFO_RCS)?'':$conf->global->MAIN_INFO_RCS;
3433
-		$this->idprof5=empty($conf->global->MAIN_INFO_PROFID5)?'':$conf->global->MAIN_INFO_PROFID5;
3434
-		$this->idprof6=empty($conf->global->MAIN_INFO_PROFID6)?'':$conf->global->MAIN_INFO_PROFID6;
3435
-		$this->tva_intra=empty($conf->global->MAIN_INFO_TVAINTRA)?'':$conf->global->MAIN_INFO_TVAINTRA;	// VAT number, not necessarly INTRA.
3436
-		$this->managers=empty($conf->global->MAIN_INFO_SOCIETE_MANAGERS)?'':$conf->global->MAIN_INFO_SOCIETE_MANAGERS;
3437
-		$this->capital=empty($conf->global->MAIN_INFO_CAPITAL)?'':$conf->global->MAIN_INFO_CAPITAL;
3438
-		$this->forme_juridique_code=empty($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE)?'':$conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE;
3439
-		$this->email=empty($conf->global->MAIN_INFO_SOCIETE_MAIL)?'':$conf->global->MAIN_INFO_SOCIETE_MAIL;
3440
-		$this->logo=empty($conf->global->MAIN_INFO_SOCIETE_LOGO)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO;
3441
-		$this->logo_small=empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL;
3442
-		$this->logo_mini=empty($conf->global->MAIN_INFO_SOCIETE_LOGO_MINI)?'':$conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
3429
+		$this->idprof1 = empty($conf->global->MAIN_INFO_SIREN) ? '' : $conf->global->MAIN_INFO_SIREN;
3430
+		$this->idprof2 = empty($conf->global->MAIN_INFO_SIRET) ? '' : $conf->global->MAIN_INFO_SIRET;
3431
+		$this->idprof3 = empty($conf->global->MAIN_INFO_APE) ? '' : $conf->global->MAIN_INFO_APE;
3432
+		$this->idprof4 = empty($conf->global->MAIN_INFO_RCS) ? '' : $conf->global->MAIN_INFO_RCS;
3433
+		$this->idprof5 = empty($conf->global->MAIN_INFO_PROFID5) ? '' : $conf->global->MAIN_INFO_PROFID5;
3434
+		$this->idprof6 = empty($conf->global->MAIN_INFO_PROFID6) ? '' : $conf->global->MAIN_INFO_PROFID6;
3435
+		$this->tva_intra = empty($conf->global->MAIN_INFO_TVAINTRA) ? '' : $conf->global->MAIN_INFO_TVAINTRA; // VAT number, not necessarly INTRA.
3436
+		$this->managers = empty($conf->global->MAIN_INFO_SOCIETE_MANAGERS) ? '' : $conf->global->MAIN_INFO_SOCIETE_MANAGERS;
3437
+		$this->capital = empty($conf->global->MAIN_INFO_CAPITAL) ? '' : $conf->global->MAIN_INFO_CAPITAL;
3438
+		$this->forme_juridique_code = empty($conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE) ? '' : $conf->global->MAIN_INFO_SOCIETE_FORME_JURIDIQUE;
3439
+		$this->email = empty($conf->global->MAIN_INFO_SOCIETE_MAIL) ? '' : $conf->global->MAIN_INFO_SOCIETE_MAIL;
3440
+		$this->logo = empty($conf->global->MAIN_INFO_SOCIETE_LOGO) ? '' : $conf->global->MAIN_INFO_SOCIETE_LOGO;
3441
+		$this->logo_small = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL) ? '' : $conf->global->MAIN_INFO_SOCIETE_LOGO_SMALL;
3442
+		$this->logo_mini = empty($conf->global->MAIN_INFO_SOCIETE_LOGO_MINI) ? '' : $conf->global->MAIN_INFO_SOCIETE_LOGO_MINI;
3443 3443
 
3444 3444
 		// Define if company use vat or not
3445
-		$this->tva_assuj=$conf->global->FACTURE_TVAOPTION;
3445
+		$this->tva_assuj = $conf->global->FACTURE_TVAOPTION;
3446 3446
 
3447 3447
 		// Define if company use local taxes
3448
-		$this->localtax1_assuj=((isset($conf->global->FACTURE_LOCAL_TAX1_OPTION) && ($conf->global->FACTURE_LOCAL_TAX1_OPTION=='1' || $conf->global->FACTURE_LOCAL_TAX1_OPTION=='localtax1on'))?1:0);
3449
-		$this->localtax2_assuj=((isset($conf->global->FACTURE_LOCAL_TAX2_OPTION) && ($conf->global->FACTURE_LOCAL_TAX2_OPTION=='1' || $conf->global->FACTURE_LOCAL_TAX2_OPTION=='localtax2on'))?1:0);
3448
+		$this->localtax1_assuj = ((isset($conf->global->FACTURE_LOCAL_TAX1_OPTION) && ($conf->global->FACTURE_LOCAL_TAX1_OPTION == '1' || $conf->global->FACTURE_LOCAL_TAX1_OPTION == 'localtax1on')) ? 1 : 0);
3449
+		$this->localtax2_assuj = ((isset($conf->global->FACTURE_LOCAL_TAX2_OPTION) && ($conf->global->FACTURE_LOCAL_TAX2_OPTION == '1' || $conf->global->FACTURE_LOCAL_TAX2_OPTION == 'localtax2on')) ? 1 : 0);
3450 3450
 	}
3451 3451
 
3452 3452
 	/**
@@ -3458,48 +3458,48 @@  discard block
 block discarded – undo
3458 3458
 	 */
3459 3459
 	function initAsSpecimen()
3460 3460
 	{
3461
-		$now=dol_now();
3461
+		$now = dol_now();
3462 3462
 
3463 3463
 		// Initialize parameters
3464
-		$this->id=0;
3465
-		$this->name = 'THIRDPARTY SPECIMEN '.dol_print_date($now,'dayhourlog');
3466
-		$this->nom = $this->name;   // For backward compatibility
3464
+		$this->id = 0;
3465
+		$this->name = 'THIRDPARTY SPECIMEN '.dol_print_date($now, 'dayhourlog');
3466
+		$this->nom = $this->name; // For backward compatibility
3467 3467
 		$this->ref_ext = 'Ref ext';
3468
-		$this->specimen=1;
3469
-		$this->address='21 jump street';
3470
-		$this->zip='99999';
3471
-		$this->town='MyTown';
3472
-		$this->state_id=1;
3473
-		$this->state_code='AA';
3474
-		$this->state='MyState';
3475
-		$this->country_id=1;
3476
-		$this->country_code='FR';
3477
-		$this->email='[email protected]';
3478
-		$this->skype='tom.hanson';
3479
-		$this->twitter='tomhanson';
3480
-		$this->facebook='tomhanson';
3481
-		$this->url='http://www.specimen.com';
3482
-
3483
-		$this->phone='0909090901';
3484
-		$this->fax='0909090909';
3485
-
3486
-		$this->code_client='CC-'.dol_print_date($now,'dayhourlog');
3487
-		$this->code_fournisseur='SC-'.dol_print_date($now,'dayhourlog');
3488
-		$this->capital=10000;
3489
-		$this->client=1;
3490
-		$this->prospect=1;
3491
-		$this->fournisseur=1;
3492
-		$this->tva_assuj=1;
3493
-		$this->tva_intra='EU1234567';
3494
-		$this->note_public='This is a comment (public)';
3495
-		$this->note_private='This is a comment (private)';
3496
-
3497
-		$this->idprof1='idprof1';
3498
-		$this->idprof2='idprof2';
3499
-		$this->idprof3='idprof3';
3500
-		$this->idprof4='idprof4';
3501
-		$this->idprof5='idprof5';
3502
-		$this->idprof6='idprof6';
3468
+		$this->specimen = 1;
3469
+		$this->address = '21 jump street';
3470
+		$this->zip = '99999';
3471
+		$this->town = 'MyTown';
3472
+		$this->state_id = 1;
3473
+		$this->state_code = 'AA';
3474
+		$this->state = 'MyState';
3475
+		$this->country_id = 1;
3476
+		$this->country_code = 'FR';
3477
+		$this->email = '[email protected]';
3478
+		$this->skype = 'tom.hanson';
3479
+		$this->twitter = 'tomhanson';
3480
+		$this->facebook = 'tomhanson';
3481
+		$this->url = 'http://www.specimen.com';
3482
+
3483
+		$this->phone = '0909090901';
3484
+		$this->fax = '0909090909';
3485
+
3486
+		$this->code_client = 'CC-'.dol_print_date($now, 'dayhourlog');
3487
+		$this->code_fournisseur = 'SC-'.dol_print_date($now, 'dayhourlog');
3488
+		$this->capital = 10000;
3489
+		$this->client = 1;
3490
+		$this->prospect = 1;
3491
+		$this->fournisseur = 1;
3492
+		$this->tva_assuj = 1;
3493
+		$this->tva_intra = 'EU1234567';
3494
+		$this->note_public = 'This is a comment (public)';
3495
+		$this->note_private = 'This is a comment (private)';
3496
+
3497
+		$this->idprof1 = 'idprof1';
3498
+		$this->idprof2 = 'idprof2';
3499
+		$this->idprof3 = 'idprof3';
3500
+		$this->idprof4 = 'idprof4';
3501
+		$this->idprof5 = 'idprof5';
3502
+		$this->idprof6 = 'idprof6';
3503 3503
 	}
3504 3504
 
3505 3505
 	/**
@@ -3508,7 +3508,7 @@  discard block
 block discarded – undo
3508 3508
 	 *	@param		int		$localTaxNum	To get info for only localtax1 or localtax2
3509 3509
 	 *  @return		boolean					true or false
3510 3510
 	 */
3511
-	function useLocalTax($localTaxNum=0)
3511
+	function useLocalTax($localTaxNum = 0)
3512 3512
 	{
3513 3513
 		$sql  = "SELECT t.localtax1, t.localtax2";
3514 3514
 		$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
@@ -3519,7 +3519,7 @@  discard block
 block discarded – undo
3519 3519
 		elseif ($localTaxNum == 2) $sql .= " AND t.localtax2_type <> '0'";
3520 3520
 
3521 3521
 		dol_syslog("useLocalTax", LOG_DEBUG);
3522
-		$resql=$this->db->query($sql);
3522
+		$resql = $this->db->query($sql);
3523 3523
 		if ($resql)
3524 3524
 		{
3525 3525
    			return ($this->db->num_rows($resql) > 0);
@@ -3540,7 +3540,7 @@  discard block
 block discarded – undo
3540 3540
 		$sql .= " AND t.active = 1 AND t.recuperableonly = 1";
3541 3541
 
3542 3542
 		dol_syslog("useNPR", LOG_DEBUG);
3543
-		$resql=$this->db->query($sql);
3543
+		$resql = $this->db->query($sql);
3544 3544
 		if ($resql)
3545 3545
 		{
3546 3546
 			return ($this->db->num_rows($resql) > 0);
@@ -3561,15 +3561,15 @@  discard block
 block discarded – undo
3561 3561
 		$sql .= " AND r.active = 1";
3562 3562
 
3563 3563
 		dol_syslog("useRevenueStamp", LOG_DEBUG);
3564
-		$resql=$this->db->query($sql);
3564
+		$resql = $this->db->query($sql);
3565 3565
 		if ($resql)
3566 3566
 		{
3567
-			$obj=$this->db->fetch_object($resql);
3568
-   			return (($obj->nb > 0)?true:false);
3567
+			$obj = $this->db->fetch_object($resql);
3568
+   			return (($obj->nb > 0) ?true:false);
3569 3569
 		}
3570 3570
 		else
3571 3571
 		{
3572
-			$this->error=$this->db->lasterror();
3572
+			$this->error = $this->db->lasterror();
3573 3573
 			return false;
3574 3574
 		}
3575 3575
 	}
@@ -3596,11 +3596,11 @@  discard block
 block discarded – undo
3596 3596
         // phpcs:enable
3597 3597
 		global $langs;
3598 3598
 
3599
-		$lib=$langs->trans("ProspectLevel".$fk_prospectlevel);
3599
+		$lib = $langs->trans("ProspectLevel".$fk_prospectlevel);
3600 3600
 		// If lib not found in language file, we get label from cache/databse
3601 3601
 		if ($lib == $langs->trans("ProspectLevel".$fk_prospectlevel))
3602 3602
 		{
3603
-			$lib=$langs->getLabelFromKey($this->db,$fk_prospectlevel,'c_prospectlevel','code','label');
3603
+			$lib = $langs->getLabelFromKey($this->db, $fk_prospectlevel, 'c_prospectlevel', 'code', 'label');
3604 3604
 		}
3605 3605
 		return $lib;
3606 3606
 	}
@@ -3627,7 +3627,7 @@  discard block
 block discarded – undo
3627 3627
 	 *  @param	string	$label		Label to use for status for added status
3628 3628
 	 *  @return string        		Libelle
3629 3629
 	 */
3630
-	function getLibProspCommStatut($mode=0, $label='')
3630
+	function getLibProspCommStatut($mode = 0, $label = '')
3631 3631
 	{
3632 3632
 		return $this->LibProspCommStatut($this->stcomm_id, $mode, $label);
3633 3633
 	}
@@ -3641,7 +3641,7 @@  discard block
 block discarded – undo
3641 3641
 	 *  @param	string		$label			Label to use for status for added status
3642 3642
 	 *  @return string       	 			Libelle du statut
3643 3643
 	 */
3644
-	function LibProspCommStatut($statut, $mode=0, $label='')
3644
+	function LibProspCommStatut($statut, $mode = 0, $label = '')
3645 3645
 	{
3646 3646
         // phpcs:enable
3647 3647
 		global $langs;
@@ -3649,11 +3649,11 @@  discard block
 block discarded – undo
3649 3649
 
3650 3650
 		if ($mode == 2)
3651 3651
 		{
3652
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3653
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3654
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3655
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3656
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3652
+			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"), -1).' '.$langs->trans("StatusProspect-1");
3653
+			elseif ($statut == '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3654
+			elseif ($statut == '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3655
+			elseif ($statut == '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3656
+			elseif ($statut == '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3657 3657
 			else
3658 3658
 			{
3659 3659
 				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
@@ -3661,11 +3661,11 @@  discard block
 block discarded – undo
3661 3661
 		}
3662 3662
 		if ($mode == 3)
3663 3663
 		{
3664
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1);
3665
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0);
3666
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1);
3667
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2);
3668
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3);
3664
+			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"), -1);
3665
+			elseif ($statut == '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0);
3666
+			elseif ($statut == '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1);
3667
+			elseif ($statut == '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2);
3668
+			elseif ($statut == '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3);
3669 3669
 			else
3670 3670
 			{
3671 3671
 				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0);
@@ -3673,11 +3673,11 @@  discard block
 block discarded – undo
3673 3673
 		}
3674 3674
 		if ($mode == 4)
3675 3675
 		{
3676
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3677
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3678
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3679
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3680
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3676
+			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"), -1).' '.$langs->trans("StatusProspect-1");
3677
+			elseif ($statut == '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3678
+			elseif ($statut == '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3679
+			elseif ($statut == '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3680
+			elseif ($statut == '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3681 3681
 			else
3682 3682
 			{
3683 3683
 				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
@@ -3707,13 +3707,13 @@  discard block
 block discarded – undo
3707 3707
 	 *  @param     string      $mode    'customer' or 'supplier'
3708 3708
 	 *  @return    array				array('opened'=>Amount, 'total'=>Total amount)
3709 3709
 	 */
3710
-	function getOutstandingProposals($mode='customer')
3710
+	function getOutstandingProposals($mode = 'customer')
3711 3711
 	{
3712
-		$table='propal';
3712
+		$table = 'propal';
3713 3713
 		if ($mode == 'supplier') $table = 'supplier_proposal';
3714 3714
 
3715 3715
 		$sql  = "SELECT rowid, total_ht, total as total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f";
3716
-		$sql .= " WHERE fk_soc = ". $this->id;
3716
+		$sql .= " WHERE fk_soc = ".$this->id;
3717 3717
 		if ($mode == 'supplier') {
3718 3718
 			$sql .= " AND entity IN (".getEntity('supplier_proposal').")";
3719 3719
 		} else {
@@ -3721,21 +3721,21 @@  discard block
 block discarded – undo
3721 3721
 		}
3722 3722
 
3723 3723
 		dol_syslog("getOutstandingProposals", LOG_DEBUG);
3724
-		$resql=$this->db->query($sql);
3724
+		$resql = $this->db->query($sql);
3725 3725
 		if ($resql)
3726 3726
 		{
3727 3727
 			$outstandingOpened = 0;
3728 3728
 			$outstandingTotal = 0;
3729 3729
 			$outstandingTotalIncTax = 0;
3730
-			while($obj=$this->db->fetch_object($resql)) {
3731
-				$outstandingTotal+= $obj->total_ht;
3732
-				$outstandingTotalIncTax+= $obj->total_ttc;
3730
+			while ($obj = $this->db->fetch_object($resql)) {
3731
+				$outstandingTotal += $obj->total_ht;
3732
+				$outstandingTotalIncTax += $obj->total_ttc;
3733 3733
 				if ($obj->fk_statut != 0)    // Not a draft
3734 3734
 				{
3735
-					$outstandingOpened+=$obj->total_ttc;
3735
+					$outstandingOpened += $obj->total_ttc;
3736 3736
 				}
3737 3737
 			}
3738
-			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3738
+			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes'
3739 3739
 		}
3740 3740
 		else
3741 3741
 			return array();
@@ -3747,13 +3747,13 @@  discard block
 block discarded – undo
3747 3747
 	 *  @param     string      $mode    'customer' or 'supplier'
3748 3748
 	 *  @return		array				array('opened'=>Amount, 'total'=>Total amount)
3749 3749
 	 */
3750
-	function getOutstandingOrders($mode='customer')
3750
+	function getOutstandingOrders($mode = 'customer')
3751 3751
 	{
3752
-		$table='commande';
3752
+		$table = 'commande';
3753 3753
 		if ($mode == 'supplier') $table = 'commande_fournisseur';
3754 3754
 
3755 3755
 		$sql  = "SELECT rowid, total_ht, total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f";
3756
-		$sql .= " WHERE fk_soc = ". $this->id;
3756
+		$sql .= " WHERE fk_soc = ".$this->id;
3757 3757
 		if ($mode == 'supplier') {
3758 3758
 			$sql .= " AND entity IN (".getEntity('supplier_order').")";
3759 3759
 		} else {
@@ -3761,21 +3761,21 @@  discard block
 block discarded – undo
3761 3761
 		}
3762 3762
 
3763 3763
 		dol_syslog("getOutstandingOrders", LOG_DEBUG);
3764
-		$resql=$this->db->query($sql);
3764
+		$resql = $this->db->query($sql);
3765 3765
 		if ($resql)
3766 3766
 		{
3767 3767
 			$outstandingOpened = 0;
3768 3768
 			$outstandingTotal = 0;
3769 3769
 			$outstandingTotalIncTax = 0;
3770
-			while($obj=$this->db->fetch_object($resql)) {
3771
-				$outstandingTotal+= $obj->total_ht;
3772
-				$outstandingTotalIncTax+= $obj->total_ttc;
3770
+			while ($obj = $this->db->fetch_object($resql)) {
3771
+				$outstandingTotal += $obj->total_ht;
3772
+				$outstandingTotalIncTax += $obj->total_ttc;
3773 3773
 				if ($obj->fk_statut != 0)    // Not a draft
3774 3774
 				{
3775
-					$outstandingOpened+=$obj->total_ttc;
3775
+					$outstandingOpened += $obj->total_ttc;
3776 3776
 				}
3777 3777
 			}
3778
-			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3778
+			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes'
3779 3779
 		}
3780 3780
 		else
3781 3781
 			return array();
@@ -3787,9 +3787,9 @@  discard block
 block discarded – undo
3787 3787
 	 *  @param     string      $mode    'customer' or 'supplier'
3788 3788
 	 *  @return		array				array('opened'=>Amount, 'total'=>Total amount)
3789 3789
 	 */
3790
-	function getOutstandingBills($mode='customer')
3790
+	function getOutstandingBills($mode = 'customer')
3791 3791
 	{
3792
-		$table='facture';
3792
+		$table = 'facture';
3793 3793
 		if ($mode == 'supplier') $table = 'facture_fourn';
3794 3794
 
3795 3795
 		/* Accurate value of remain to pay is to sum remaintopay for each invoice
@@ -3799,9 +3799,9 @@  discard block
 block discarded – undo
3799 3799
 		 $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
3800 3800
 		 $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
3801 3801
 		 */
3802
-		if ($mode == 'supplier') $sql  = "SELECT rowid, total_ht as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3803
-		else $sql  = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3804
-		$sql .= " WHERE fk_soc = ". $this->id;
3802
+		if ($mode == 'supplier') $sql = "SELECT rowid, total_ht as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3803
+		else $sql = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3804
+		$sql .= " WHERE fk_soc = ".$this->id;
3805 3805
 		if ($mode == 'supplier') {
3806 3806
 			$sql .= " AND entity IN (".getEntity('facture_fourn').")";
3807 3807
 		} else {
@@ -3809,7 +3809,7 @@  discard block
 block discarded – undo
3809 3809
 		}
3810 3810
 
3811 3811
 		dol_syslog("getOutstandingBills", LOG_DEBUG);
3812
-		$resql=$this->db->query($sql);
3812
+		$resql = $this->db->query($sql);
3813 3813
 		if ($resql)
3814 3814
 		{
3815 3815
 			$outstandingOpened = 0;
@@ -3818,21 +3818,21 @@  discard block
 block discarded – undo
3818 3818
 			if ($mode == 'supplier')
3819 3819
 			{
3820 3820
 				require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
3821
-				$tmpobject=new FactureFournisseur($this->db);
3821
+				$tmpobject = new FactureFournisseur($this->db);
3822 3822
 			}
3823 3823
 			else
3824 3824
 			{
3825 3825
 				require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
3826
-				$tmpobject=new Facture($this->db);
3826
+				$tmpobject = new Facture($this->db);
3827 3827
 			}
3828
-			while($obj=$this->db->fetch_object($resql)) {
3829
-				$tmpobject->id=$obj->rowid;
3828
+			while ($obj = $this->db->fetch_object($resql)) {
3829
+				$tmpobject->id = $obj->rowid;
3830 3830
 				if ($obj->fk_statut != 0                                           // Not a draft
3831
-					&& ! ($obj->fk_statut == 3 && $obj->close_code == 'replaced')  // Not a replaced invoice
3831
+					&& !($obj->fk_statut == 3 && $obj->close_code == 'replaced')  // Not a replaced invoice
3832 3832
 					)
3833 3833
 				{
3834
-					$outstandingTotal+= $obj->total_ht;
3835
-					$outstandingTotalIncTax+= $obj->total_ttc;
3834
+					$outstandingTotal += $obj->total_ht;
3835
+					$outstandingTotalIncTax += $obj->total_ttc;
3836 3836
 				}
3837 3837
 				if ($obj->paye == 0
3838 3838
 					&& $obj->fk_statut != 0    // Not a draft
@@ -3843,10 +3843,10 @@  discard block
 block discarded – undo
3843 3843
 					$paiement = $tmpobject->getSommePaiement();
3844 3844
 					$creditnotes = $tmpobject->getSumCreditNotesUsed();
3845 3845
 					$deposits = $tmpobject->getSumDepositsUsed();
3846
-					$outstandingOpened+=$obj->total_ttc - $paiement - $creditnotes - $deposits;
3846
+					$outstandingOpened += $obj->total_ttc - $paiement - $creditnotes - $deposits;
3847 3847
 				}
3848 3848
 			}
3849
-			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3849
+			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax); // 'opened' is 'incl taxes'
3850 3850
 		}
3851 3851
 		else
3852 3852
 		{
@@ -3873,26 +3873,26 @@  discard block
 block discarded – undo
3873 3873
 	     $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
3874 3874
 	     */
3875 3875
 		$sql  = "SELECT rowid, total_ttc FROM ".MAIN_DB_PREFIX."facture as f";
3876
-		$sql .= " WHERE fk_soc = ". $this->id;
3876
+		$sql .= " WHERE fk_soc = ".$this->id;
3877 3877
 		$sql .= " AND paye = 0";
3878
-		$sql .= " AND fk_statut <> 0";	// Not a draft
3878
+		$sql .= " AND fk_statut <> 0"; // Not a draft
3879 3879
 		//$sql .= " AND (fk_statut <> 3 OR close_code <> 'abandon')";		// Not abandonned for undefined reason
3880
-		$sql .= " AND fk_statut <> 3";		// Not abandonned
3881
-		$sql .= " AND fk_statut <> 2";		// Not clasified as paid
3880
+		$sql .= " AND fk_statut <> 3"; // Not abandonned
3881
+		$sql .= " AND fk_statut <> 2"; // Not clasified as paid
3882 3882
 
3883 3883
 		dol_syslog("get_OutstandingBill", LOG_DEBUG);
3884
-		$resql=$this->db->query($sql);
3884
+		$resql = $this->db->query($sql);
3885 3885
 		if ($resql)
3886 3886
 		{
3887 3887
 			$outstandingAmount = 0;
3888 3888
 			require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
3889
-			$tmpobject=new Facture($this->db);
3890
-			while($obj=$this->db->fetch_object($resql)) {
3891
-				$tmpobject->id=$obj->rowid;
3889
+			$tmpobject = new Facture($this->db);
3890
+			while ($obj = $this->db->fetch_object($resql)) {
3891
+				$tmpobject->id = $obj->rowid;
3892 3892
 				$paiement = $tmpobject->getSommePaiement();
3893 3893
 				$creditnotes = $tmpobject->getSumCreditNotesUsed();
3894 3894
 				$deposits = $tmpobject->getSumDepositsUsed();
3895
-				$outstandingAmount+= $obj->total_ttc - $paiement - $creditnotes - $deposits;
3895
+				$outstandingAmount += $obj->total_ttc - $paiement - $creditnotes - $deposits;
3896 3896
 			}
3897 3897
 			return $outstandingAmount;
3898 3898
 		}
@@ -3923,10 +3923,10 @@  discard block
 block discarded – undo
3923 3923
 		global $langs;
3924 3924
 		$langs->load('companies');
3925 3925
 
3926
-		if ($statut==0) return $langs->trans("NorProspectNorCustomer");
3927
-		if ($statut==1) return $langs->trans("Customer");
3928
-		if ($statut==2) return $langs->trans("Prospect");
3929
-		if ($statut==3) return $langs->trans("ProspectCustomer");
3926
+		if ($statut == 0) return $langs->trans("NorProspectNorCustomer");
3927
+		if ($statut == 1) return $langs->trans("Customer");
3928
+		if ($statut == 2) return $langs->trans("Prospect");
3929
+		if ($statut == 3) return $langs->trans("ProspectCustomer");
3930 3930
 	}
3931 3931
 
3932 3932
 
@@ -3941,26 +3941,26 @@  discard block
 block discarded – undo
3941 3941
 	 *  @param  null|array  $moreparams     Array to provide more information
3942 3942
 	 *	@return int        					<0 if KO, >0 if OK
3943 3943
 	 */
3944
-	public function generateDocument($modele, $outputlangs, $hidedetails=0, $hidedesc=0, $hideref=0, $moreparams=null)
3944
+	public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams = null)
3945 3945
 	{
3946
-		global $conf,$user,$langs;
3946
+		global $conf, $user, $langs;
3947 3947
 
3948
-		if (! empty($moreparams) && ! empty($moreparams['use_companybankid']))
3948
+		if (!empty($moreparams) && !empty($moreparams['use_companybankid']))
3949 3949
 		{
3950 3950
 			$modelpath = "core/modules/bank/doc/";
3951 3951
 
3952 3952
 			include_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
3953 3953
 			$companybankaccount = new CompanyBankAccount($this->db);
3954 3954
 			$result = $companybankaccount->fetch($moreparams['use_companybankid']);
3955
-			if (! $result) dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
3956
-			$result=$companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3955
+			if (!$result) dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
3956
+			$result = $companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3957 3957
 		}
3958 3958
 		else
3959 3959
 		{
3960 3960
 			// Positionne le modele sur le nom du modele a utiliser
3961
-			if (! dol_strlen($modele))
3961
+			if (!dol_strlen($modele))
3962 3962
 			{
3963
-				if (! empty($conf->global->COMPANY_ADDON_PDF))
3963
+				if (!empty($conf->global->COMPANY_ADDON_PDF))
3964 3964
 				{
3965 3965
 					$modele = $conf->global->COMPANY_ADDON_PDF;
3966 3966
 				}
@@ -3973,7 +3973,7 @@  discard block
 block discarded – undo
3973 3973
 
3974 3974
 			$modelpath = "core/modules/societe/doc/";
3975 3975
 
3976
-			$result=$this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3976
+			$result = $this->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3977 3977
 		}
3978 3978
 
3979 3979
 		return $result;
@@ -3993,7 +3993,7 @@  discard block
 block discarded – undo
3993 3993
 	 */
3994 3994
 	public function setCategories($categories, $type)
3995 3995
 	{
3996
-		require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
3996
+		require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
3997 3997
 
3998 3998
 		// Decode type
3999 3999
 		if ($type == 'customer') {
@@ -4003,7 +4003,7 @@  discard block
 block discarded – undo
4003 4003
 			$type_id = Categorie::TYPE_SUPPLIER;
4004 4004
 			$type_text = 'supplier';
4005 4005
 		} else {
4006
-			dol_syslog(__METHOD__ . ': Type ' . $type .  'is an unknown company category type. Done nothing.', LOG_ERR);
4006
+			dol_syslog(__METHOD__.': Type '.$type.'is an unknown company category type. Done nothing.', LOG_ERR);
4007 4007
 			return -1;
4008 4008
 		}
4009 4009
 
Please login to merge, or discard this patch.
Braces   +588 added lines, -352 removed lines patch added patch discarded remove patch
@@ -509,15 +509,25 @@  discard block
 block discarded – undo
509 509
 		$error=0;
510 510
 
511 511
 		// Clean parameters
512
-		if (empty($this->status)) $this->status=0;
512
+		if (empty($this->status)) {
513
+		    $this->status=0;
514
+		}
513 515
 		$this->name=$this->name?trim($this->name):trim($this->nom);
514
-		if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) $this->name=ucwords($this->name);
516
+		if (! empty($conf->global->MAIN_FIRST_TO_UPPER)) {
517
+		    $this->name=ucwords($this->name);
518
+		}
515 519
 		$this->nom=$this->name; // For backward compatibility
516
-		if (empty($this->client))      $this->client=0;
517
-		if (empty($this->fournisseur)) $this->fournisseur=0;
520
+		if (empty($this->client)) {
521
+		    $this->client=0;
522
+		}
523
+		if (empty($this->fournisseur)) {
524
+		    $this->fournisseur=0;
525
+		}
518 526
 		$this->import_key = trim($this->import_key);
519 527
 
520
-		if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
528
+		if (!empty($this->multicurrency_code)) {
529
+		    $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
530
+		}
521 531
 		if (empty($this->fk_multicurrency))
522 532
 		{
523 533
 			$this->multicurrency_code = '';
@@ -531,8 +541,12 @@  discard block
 block discarded – undo
531 541
 		$this->db->begin();
532 542
 
533 543
 		// For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts)
534
-		if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this,0);
535
-		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this,1);
544
+		if ($this->code_client == -1 || $this->code_client === 'auto') {
545
+		    $this->get_codeclient($this,0);
546
+		}
547
+		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') {
548
+		    $this->get_codefournisseur($this,1);
549
+		}
536 550
 
537 551
 		// Check more parameters (including mandatory setup
538 552
 		// If error, this->errors[] is filled
@@ -579,32 +593,32 @@  discard block
 block discarded – undo
579 593
 				{
580 594
 					// Call trigger
581 595
 					$result=$this->call_trigger('COMPANY_CREATE',$user);
582
-					if ($result < 0) $error++;
596
+					if ($result < 0) {
597
+					    $error++;
598
+					}
583 599
 					// End call triggers
600
+				} else {
601
+				    $error++;
584 602
 				}
585
-				else $error++;
586 603
 
587 604
 				if (! $error)
588 605
 				{
589 606
 					dol_syslog(get_class($this)."::Create success id=".$this->id);
590 607
 					$this->db->commit();
591 608
 					return $this->id;
592
-				}
593
-				else
609
+				} else
594 610
 				{
595 611
 					dol_syslog(get_class($this)."::Create echec update ".$this->error." ".join(',',$this->errors), LOG_ERR);
596 612
 					$this->db->rollback();
597 613
 					return -4;
598 614
 				}
599
-			}
600
-			else
615
+			} else
601 616
 			{
602 617
 				if ($this->db->lasterrno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
603 618
 				{
604 619
 					$this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->name);    // duplicate on a field (code or profid or ...)
605 620
 					$result=-1;
606
-				}
607
-				else
621
+				} else
608 622
 				{
609 623
 					$this->error=$this->db->lasterror();
610 624
 					$result=-2;
@@ -612,8 +626,7 @@  discard block
 block discarded – undo
612 626
 				$this->db->rollback();
613 627
 				return $result;
614 628
 			}
615
-		}
616
-		else
629
+		} else
617 630
 		{
618 631
 			$this->db->rollback();
619 632
 			dol_syslog(get_class($this)."::Create fails verify ".join(',',$this->errors), LOG_WARNING);
@@ -691,16 +704,13 @@  discard block
 block discarded – undo
691 704
 				if ($rescode == -1)
692 705
 				{
693 706
 					$this->errors[] = 'ErrorBadCustomerCodeSyntax';
694
-				}
695
-				elseif ($rescode == -2)
707
+				} elseif ($rescode == -2)
696 708
 				{
697 709
 					$this->errors[] = 'ErrorCustomerCodeRequired';
698
-				}
699
-				elseif ($rescode == -3)
710
+				} elseif ($rescode == -3)
700 711
 				{
701 712
 					$this->errors[] = 'ErrorCustomerCodeAlreadyUsed';
702
-				}
703
-				elseif ($rescode == -4)
713
+				} elseif ($rescode == -4)
704 714
 				{
705 715
 					$this->errors[] = 'ErrorPrefixRequired';
706 716
 				}
@@ -716,16 +726,13 @@  discard block
 block discarded – undo
716 726
 				if ($rescode == -1)
717 727
 				{
718 728
 					$this->errors[] = 'ErrorBadSupplierCodeSyntax';
719
-				}
720
-				elseif ($rescode == -2)
729
+				} elseif ($rescode == -2)
721 730
 				{
722 731
 					$this->errors[] = 'ErrorSupplierCodeRequired';
723
-				}
724
-				elseif ($rescode == -3)
732
+				} elseif ($rescode == -3)
725 733
 				{
726 734
 					$this->errors[] = 'ErrorSupplierCodeAlreadyUsed';
727
-				}
728
-				elseif ($rescode == -5)
735
+				} elseif ($rescode == -5)
729 736
 				{
730 737
 					$this->errors[] = 'ErrorprefixRequired';
731 738
 				}
@@ -767,8 +774,7 @@  discard block
 block discarded – undo
767 774
 						}
768 775
 					}
769 776
 				}
770
-			}
771
-			else
777
+			} else
772 778
 			{
773 779
 				//var_dump($conf->global->SOCIETE_EMAIL_UNIQUE);
774 780
 				//var_dump($conf->global->SOCIETE_EMAIL_MANDATORY);
@@ -795,7 +801,9 @@  discard block
 block discarded – undo
795 801
 			}
796 802
 		}
797 803
 
798
-		if ($error) $result = -4;
804
+		if ($error) {
805
+		    $result = -4;
806
+		}
799 807
 
800 808
 		return $result;
801 809
 	}
@@ -818,7 +826,9 @@  discard block
 block discarded – undo
818 826
 
819 827
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
820 828
 
821
-		if (empty($id)) $id = $this->id;
829
+		if (empty($id)) {
830
+		    $id = $this->id;
831
+		}
822 832
 
823 833
 		$error=0;
824 834
 
@@ -864,9 +874,13 @@  discard block
 block discarded – undo
864 874
 
865 875
 		$this->tva_assuj	= trim($this->tva_assuj);
866 876
 		$this->tva_intra	= dol_sanitizeFileName($this->tva_intra,'');
867
-		if (empty($this->status)) $this->status = 0;
877
+		if (empty($this->status)) {
878
+		    $this->status = 0;
879
+		}
868 880
 
869
-		if (!empty($this->multicurrency_code)) $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
881
+		if (!empty($this->multicurrency_code)) {
882
+		    $this->fk_multicurrency = MultiCurrency::getIdFromCode($this->db, $this->multicurrency_code);
883
+		}
870 884
 		if (empty($this->fk_multicurrency))
871 885
 		{
872 886
 			$this->multicurrency_code = '';
@@ -880,8 +894,13 @@  discard block
 block discarded – undo
880 894
 		$this->localtax1_value=trim($this->localtax1_value);
881 895
 		$this->localtax2_value=trim($this->localtax2_value);
882 896
 
883
-		if ($this->capital != '') $this->capital=price2num(trim($this->capital));
884
-		if (! is_numeric($this->capital)) $this->capital = '';     // '' = undef
897
+		if ($this->capital != '') {
898
+		    $this->capital=price2num(trim($this->capital));
899
+		}
900
+		if (! is_numeric($this->capital)) {
901
+		    $this->capital = '';
902
+		}
903
+		// '' = undef
885 904
 
886 905
 		$this->effectif_id=trim($this->effectif_id);
887 906
 		$this->forme_juridique_code=trim($this->forme_juridique_code);
@@ -890,8 +909,12 @@  discard block
 block discarded – undo
890 909
 		$this->barcode=trim($this->barcode);
891 910
 
892 911
 		// For automatic creation
893
-		if ($this->code_client == -1 || $this->code_client === 'auto')           $this->get_codeclient($this,0);
894
-		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') $this->get_codefournisseur($this,1);
912
+		if ($this->code_client == -1 || $this->code_client === 'auto') {
913
+		    $this->get_codeclient($this,0);
914
+		}
915
+		if ($this->code_fournisseur == -1 || $this->code_fournisseur === 'auto') {
916
+		    $this->get_codefournisseur($this,1);
917
+		}
895 918
 
896 919
 		$this->code_compta=trim($this->code_compta);
897 920
 		$this->code_compta_fournisseur=trim($this->code_compta_fournisseur);
@@ -911,7 +934,9 @@  discard block
 block discarded – undo
911 934
 			if (empty($this->code_compta))
912 935
 			{
913 936
 				$ret=$this->get_codecompta('customer');
914
-				if ($ret < 0) return -1;
937
+				if ($ret < 0) {
938
+				    return -1;
939
+				}
915 940
 			}
916 941
 
917 942
 			$customer=true;
@@ -924,7 +949,9 @@  discard block
 block discarded – undo
924 949
 			if (empty($this->code_compta_fournisseur))
925 950
 			{
926 951
 				$ret=$this->get_codecompta('supplier');
927
-				if ($ret < 0) return -1;
952
+				if ($ret < 0) {
953
+				    return -1;
954
+				}
928 955
 			}
929 956
 
930 957
 			$supplier=true;
@@ -955,16 +982,24 @@  discard block
 block discarded – undo
955 982
 			{
956 983
 				if (in_array('ErrorBadCustomerCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_client == $this->code_client)
957 984
 				{
958
-					if (($key = array_search('ErrorBadCustomerCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]);	// Remove error message
985
+					if (($key = array_search('ErrorBadCustomerCodeSyntax', $this->errors)) !== false) {
986
+					    unset($this->errors[$key]);
987
+					}
988
+					// Remove error message
959 989
 				}
960 990
 				if (in_array('ErrorBadSupplierCodeSyntax', $this->errors) && is_object($this->oldcopy) && $this->oldcopy->code_fournisseur == $this->code_fournisseur)
961 991
 				{
962
-					if (($key = array_search('ErrorBadSupplierCodeSyntax', $this->errors)) !== false) unset($this->errors[$key]);	// Remove error message
992
+					if (($key = array_search('ErrorBadSupplierCodeSyntax', $this->errors)) !== false) {
993
+					    unset($this->errors[$key]);
994
+					}
995
+					// Remove error message
963 996
 				}
964
-				if (empty($this->errors))	// If there is no more error, we can make like if there is no error at all
997
+				if (empty($this->errors)) {
998
+				    // If there is no more error, we can make like if there is no error at all
965 999
 				{
966 1000
 					$result = 0;
967 1001
 				}
1002
+				}
968 1003
 			}
969 1004
 		}
970 1005
 
@@ -1017,20 +1052,24 @@  discard block
 block discarded – undo
1017 1052
 				if($this->localtax1_value!='')
1018 1053
 				{
1019 1054
 					$sql .=",localtax1_value =".$this->localtax1_value;
1055
+				} else {
1056
+				    $sql .=",localtax1_value =0.000";
1020 1057
 				}
1021
-				else $sql .=",localtax1_value =0.000";
1058
+			} else {
1059
+			    $sql .=",localtax1_value =0.000";
1022 1060
 			}
1023
-			else $sql .=",localtax1_value =0.000";
1024 1061
 
1025 1062
 			if($this->localtax2_assuj==1)
1026 1063
 			{
1027 1064
 				if($this->localtax2_value!='')
1028 1065
 				{
1029 1066
 					$sql .=",localtax2_value =".$this->localtax2_value;
1067
+				} else {
1068
+				    $sql .=",localtax2_value =0.000";
1030 1069
 				}
1031
-				else $sql .=",localtax2_value =0.000";
1070
+			} else {
1071
+			    $sql .=",localtax2_value =0.000";
1032 1072
 			}
1033
-			else $sql .=",localtax2_value =0.000";
1034 1073
 
1035 1074
 			$sql .= ",capital = ".($this->capital == '' ? "null" : $this->capital);
1036 1075
 
@@ -1087,11 +1126,13 @@  discard block
 block discarded – undo
1087 1126
 			$resql=$this->db->query($sql);
1088 1127
 			if ($resql)
1089 1128
 			{
1090
-				if (is_object($this->oldcopy))	// If we have information on old values
1129
+				if (is_object($this->oldcopy)) {
1130
+				    // If we have information on old values
1091 1131
 				{
1092 1132
 					if ($this->oldcopy->country_id != $this->country_id)
1093 1133
 					{
1094 1134
 						unset($this->country_code);
1135
+				}
1095 1136
 						unset($this->country);
1096 1137
 					}
1097 1138
 					if ($this->oldcopy->state_id != $this->state_id)
@@ -1099,8 +1140,7 @@  discard block
 block discarded – undo
1099 1140
 						unset($this->state_code);
1100 1141
 						unset($this->state);
1101 1142
 					}
1102
-				}
1103
-				else
1143
+				} else
1104 1144
 				{
1105 1145
 					unset($this->country_code);	// We clean this, in the doubt, because it may have been changed after an update of country_id
1106 1146
 					unset($this->country);
@@ -1141,8 +1181,7 @@  discard block
 block discarded – undo
1141 1181
 								dol_syslog(get_class($this)."::update ".$this->error,LOG_ERR);
1142 1182
 								$error++;
1143 1183
 							}
1144
-						}
1145
-						elseif ($result < 0)
1184
+						} elseif ($result < 0)
1146 1185
 						{
1147 1186
 							$this->error=$lmember->error;
1148 1187
 							$error++;
@@ -1153,9 +1192,11 @@  discard block
 block discarded – undo
1153 1192
 				$action='update';
1154 1193
 
1155 1194
 				// Actions on extra fields
1156
-				if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
1195
+				if (! $error && empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) {
1196
+				    // For avoid conflicts if trigger used
1157 1197
 				{
1158 1198
 					$result=$this->insertExtraFields();
1199
+				}
1159 1200
 					if ($result < 0)
1160 1201
 					{
1161 1202
 						$error++;
@@ -1166,7 +1207,9 @@  discard block
 block discarded – undo
1166 1207
 				{
1167 1208
 					// Call trigger
1168 1209
 					$result=$this->call_trigger('COMPANY_MODIFY',$user);
1169
-					if ($result < 0) $error++;
1210
+					if ($result < 0) {
1211
+					    $error++;
1212
+					}
1170 1213
 					// End call triggers
1171 1214
 				}
1172 1215
 
@@ -1175,22 +1218,19 @@  discard block
 block discarded – undo
1175 1218
 					dol_syslog(get_class($this)."::Update success");
1176 1219
 					$this->db->commit();
1177 1220
 					return 1;
1178
-				}
1179
-				else
1221
+				} else
1180 1222
 				{
1181 1223
 					$this->db->rollback();
1182 1224
 					return -1;
1183 1225
 				}
1184
-			}
1185
-			else
1226
+			} else
1186 1227
 			{
1187 1228
 				if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
1188 1229
 				{
1189 1230
 					// Doublon
1190 1231
 					$this->error = $langs->trans("ErrorDuplicateField");
1191 1232
 					$result = -1;
1192
-				}
1193
-				else
1233
+				} else
1194 1234
 				{
1195 1235
 					$this->error = $this->db->lasterror();
1196 1236
 					$result = -2;
@@ -1198,8 +1238,7 @@  discard block
 block discarded – undo
1198 1238
 				$this->db->rollback();
1199 1239
 				return $result;
1200 1240
 			}
1201
-		}
1202
-		else
1241
+		} else
1203 1242
 	   {
1204 1243
 			$this->db->rollback();
1205 1244
 			dol_syslog(get_class($this)."::Update fails verify ".join(',',$this->errors), LOG_WARNING);
@@ -1229,7 +1268,9 @@  discard block
 block discarded – undo
1229 1268
 		global $langs;
1230 1269
 		global $conf;
1231 1270
 
1232
-		if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($ref_int) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) return -1;
1271
+		if (empty($rowid) && empty($ref) && empty($ref_ext) && empty($ref_int) && empty($idprof1) && empty($idprof2) && empty($idprof3) && empty($idprof4) && empty($idprof5) && empty($idprof6) && empty($email)) {
1272
+		    return -1;
1273
+		}
1233 1274
 
1234 1275
 		$sql = 'SELECT s.rowid, s.nom as name, s.name_alias, s.entity, s.ref_ext, s.ref_int, s.address, s.datec as date_creation, s.prefix_comm';
1235 1276
 		$sql .= ', s.status';
@@ -1266,18 +1307,42 @@  discard block
 block discarded – undo
1266 1307
 		$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_incoterms as i ON s.fk_incoterms = i.rowid';
1267 1308
 
1268 1309
 		$sql .= ' WHERE s.entity IN ('.getEntity($this->element).')';
1269
-		if ($rowid)     $sql .= ' AND s.rowid = '.$rowid;
1270
-		if ($ref)       $sql .= " AND s.nom = '".$this->db->escape($ref)."'";
1271
-		if ($ref_alias) $sql .= " AND s.nom_alias = '".$this->db->escape($ref_alias)."'";
1272
-		if ($ref_ext)   $sql .= " AND s.ref_ext = '".$this->db->escape($ref_ext)."'";
1273
-		if ($ref_int)   $sql .= " AND s.ref_int = '".$this->db->escape($ref_int)."'";
1274
-		if ($idprof1)   $sql .= " AND s.siren = '".$this->db->escape($idprof1)."'";
1275
-		if ($idprof2)   $sql .= " AND s.siret = '".$this->db->escape($idprof2)."'";
1276
-		if ($idprof3)   $sql .= " AND s.ape = '".$this->db->escape($idprof3)."'";
1277
-		if ($idprof4)   $sql .= " AND s.idprof4 = '".$this->db->escape($idprof4)."'";
1278
-		if ($idprof5)   $sql .= " AND s.idprof5 = '".$this->db->escape($idprof5)."'";
1279
-		if ($idprof6)   $sql .= " AND s.idprof6 = '".$this->db->escape($idprof6)."'";
1280
-		if ($email)     $sql .= " AND s.email = '".$this->db->escape($email)."'";
1310
+		if ($rowid) {
1311
+		    $sql .= ' AND s.rowid = '.$rowid;
1312
+		}
1313
+		if ($ref) {
1314
+		    $sql .= " AND s.nom = '".$this->db->escape($ref)."'";
1315
+		}
1316
+		if ($ref_alias) {
1317
+		    $sql .= " AND s.nom_alias = '".$this->db->escape($ref_alias)."'";
1318
+		}
1319
+		if ($ref_ext) {
1320
+		    $sql .= " AND s.ref_ext = '".$this->db->escape($ref_ext)."'";
1321
+		}
1322
+		if ($ref_int) {
1323
+		    $sql .= " AND s.ref_int = '".$this->db->escape($ref_int)."'";
1324
+		}
1325
+		if ($idprof1) {
1326
+		    $sql .= " AND s.siren = '".$this->db->escape($idprof1)."'";
1327
+		}
1328
+		if ($idprof2) {
1329
+		    $sql .= " AND s.siret = '".$this->db->escape($idprof2)."'";
1330
+		}
1331
+		if ($idprof3) {
1332
+		    $sql .= " AND s.ape = '".$this->db->escape($idprof3)."'";
1333
+		}
1334
+		if ($idprof4) {
1335
+		    $sql .= " AND s.idprof4 = '".$this->db->escape($idprof4)."'";
1336
+		}
1337
+		if ($idprof5) {
1338
+		    $sql .= " AND s.idprof5 = '".$this->db->escape($idprof5)."'";
1339
+		}
1340
+		if ($idprof6) {
1341
+		    $sql .= " AND s.idprof6 = '".$this->db->escape($idprof6)."'";
1342
+		}
1343
+		if ($email) {
1344
+		    $sql .= " AND s.email = '".$this->db->escape($email)."'";
1345
+		}
1281 1346
 
1282 1347
 		$resql=$this->db->query($sql);
1283 1348
 		if ($resql)
@@ -1288,10 +1353,11 @@  discard block
 block discarded – undo
1288 1353
 				$this->error='Fetch found several records. Rename one of tirdparties to avoid duplicate.';
1289 1354
 				dol_syslog($this->error, LOG_ERR);
1290 1355
 				$result = -2;
1291
-			}
1292
-			elseif ($num)   // $num = 1
1356
+			} elseif ($num) {
1357
+			    // $num = 1
1293 1358
 			{
1294 1359
 				$obj = $this->db->fetch_object($resql);
1360
+			}
1295 1361
 
1296 1362
 				$this->id           = $obj->rowid;
1297 1363
 				$this->entity       = $obj->entity;
@@ -1421,22 +1487,22 @@  discard block
 block discarded – undo
1421 1487
 
1422 1488
 				// fetch optionals attributes and labels
1423 1489
 				$this->fetch_optionals();
1424
-			}
1425
-			else
1490
+			} else
1426 1491
 			{
1427 1492
 				$result = 0;
1428 1493
 			}
1429 1494
 
1430 1495
 			$this->db->free($resql);
1431
-		}
1432
-		else
1496
+		} else
1433 1497
 		{
1434 1498
 			$this->error=$this->db->lasterror();
1435 1499
 			$result = -3;
1436 1500
 		}
1437 1501
 
1438 1502
 		// Use first price level if level not defined for third party
1439
-		if (! empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->price_level)) $this->price_level=1;
1503
+		if (! empty($conf->global->PRODUIT_MULTIPRICES) && empty($this->price_level)) {
1504
+		    $this->price_level=1;
1505
+		}
1440 1506
 
1441 1507
 		return $result;
1442 1508
 	}
@@ -1453,7 +1519,9 @@  discard block
 block discarded – undo
1453 1519
 	{
1454 1520
 		global $langs, $conf, $user;
1455 1521
 
1456
-		if (empty($fuser)) $fuser=$user;
1522
+		if (empty($fuser)) {
1523
+		    $fuser=$user;
1524
+		}
1457 1525
 
1458 1526
 		require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
1459 1527
 
@@ -1473,7 +1541,9 @@  discard block
 block discarded – undo
1473 1541
 			{
1474 1542
 				// Call trigger
1475 1543
 				$result=$this->call_trigger('COMPANY_DELETE',$fuser);
1476
-				if ($result < 0) $error++;
1544
+				if ($result < 0) {
1545
+				    $error++;
1546
+				}
1477 1547
 				// End call triggers
1478 1548
 			}
1479 1549
 
@@ -1518,9 +1588,11 @@  discard block
 block discarded – undo
1518 1588
 			}
1519 1589
 
1520 1590
 			// Removed extrafields
1521
-			if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) // For avoid conflicts if trigger used
1591
+			if ((! $error) && (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED))) {
1592
+			    // For avoid conflicts if trigger used
1522 1593
 			{
1523 1594
 				$result=$this->deleteExtraFields();
1595
+			}
1524 1596
 				if ($result < 0)
1525 1597
 				{
1526 1598
 					$error++;
@@ -1568,15 +1640,15 @@  discard block
 block discarded – undo
1568 1640
 				}
1569 1641
 
1570 1642
 				return 1;
1571
-			}
1572
-			else
1643
+			} else
1573 1644
 			{
1574 1645
 				dol_syslog($this->error, LOG_ERR);
1575 1646
 				$this->db->rollback();
1576 1647
 				return -1;
1577 1648
 			}
1649
+		} else {
1650
+		    dol_syslog("Can't remove thirdparty with id ".$id.". There is ".$objectisused." childs", LOG_WARNING);
1578 1651
 		}
1579
-		else dol_syslog("Can't remove thirdparty with id ".$id.". There is ".$objectisused." childs", LOG_WARNING);
1580 1652
 		return 0;
1581 1653
 	}
1582 1654
 
@@ -1592,7 +1664,10 @@  discard block
 block discarded – undo
1592 1664
 		if ($this->id)
1593 1665
 		{
1594 1666
 			$newclient=1;
1595
-			if ($this->client == 2 || $this->client == 3) $newclient=3;	//If prospect, we keep prospect tag
1667
+			if ($this->client == 2 || $this->client == 3) {
1668
+			    $newclient=3;
1669
+			}
1670
+			//If prospect, we keep prospect tag
1596 1671
 			$sql = "UPDATE ".MAIN_DB_PREFIX."societe";
1597 1672
 			$sql.= " SET client = ".$newclient;
1598 1673
 			$sql.= " WHERE rowid = " . $this->id;
@@ -1602,8 +1677,9 @@  discard block
 block discarded – undo
1602 1677
 			{
1603 1678
 				$this->client = $newclient;
1604 1679
 				return 1;
1680
+			} else {
1681
+			    return -1;
1605 1682
 			}
1606
-			else return -1;
1607 1683
 		}
1608 1684
 		return 0;
1609 1685
 	}
@@ -1786,14 +1862,14 @@  discard block
 block discarded – undo
1786 1862
 			if ($result > 0)
1787 1863
 			{
1788 1864
 				return $result;
1789
-			}
1790
-			else
1865
+			} else
1791 1866
 			{
1792 1867
 				$this->error=$discount->error;
1793 1868
 				return -3;
1794 1869
 			}
1870
+		} else {
1871
+		    return 0;
1795 1872
 		}
1796
-		else return 0;
1797 1873
 	}
1798 1874
 
1799 1875
 	/**
@@ -1814,8 +1890,7 @@  discard block
 block discarded – undo
1814 1890
 		if ($result >= 0)
1815 1891
 		{
1816 1892
 			return $result;
1817
-		}
1818
-		else
1893
+		} else
1819 1894
 		{
1820 1895
 			$this->error=$discountstatic->error;
1821 1896
 			return -1;
@@ -1843,9 +1918,9 @@  discard block
 block discarded – undo
1843 1918
 			$sql.= " WHERE ((ug.fk_user = sc.fk_user";
1844 1919
 			$sql.= " AND ug.entity = ".$conf->entity.")";
1845 1920
 			$sql.= " OR u.admin = 1)";
1921
+		} else {
1922
+					$sql.= " WHERE entity in (0, ".$conf->entity.")";
1846 1923
 		}
1847
-		else
1848
-			$sql.= " WHERE entity in (0, ".$conf->entity.")";
1849 1924
 
1850 1925
 		$sql.= " AND u.rowid = sc.fk_user AND sc.fk_soc = ".$this->id;
1851 1926
 
@@ -1868,16 +1943,14 @@  discard block
 block discarded – undo
1868 1943
 					$reparray[$i]['entity']=$obj->entity;
1869 1944
 					$reparray[$i]['login']=$obj->login;
1870 1945
 					$reparray[$i]['photo']=$obj->photo;
1871
-				}
1872
-				else
1946
+				} else
1873 1947
 				{
1874 1948
 					$reparray[]=$obj->rowid;
1875 1949
 				}
1876 1950
 				$i++;
1877 1951
 			}
1878 1952
 			return $reparray;
1879
-		}
1880
-		else {
1953
+		} else {
1881 1954
 			dol_print_error($this->db);
1882 1955
 			return -1;
1883 1956
 		}
@@ -1950,12 +2023,13 @@  discard block
 block discarded – undo
1950 2023
 			if (! $this->db->query($sql) )
1951 2024
 			{
1952 2025
 				dol_syslog(get_class($this)."::add_commercial Erreur");
1953
-			}
1954
-			else {
2026
+			} else {
1955 2027
 				$this->context=array('commercial_modified'=>$commid);
1956 2028
 
1957 2029
 				$result=$this->call_trigger('COMPANY_LINK_SALE_REPRESENTATIVE',$user);
1958
-                if ($result < 0) $error++;
2030
+                if ($result < 0) {
2031
+                    $error++;
2032
+                }
1959 2033
 			}
1960 2034
 		}
1961 2035
 	}
@@ -1975,7 +2049,9 @@  discard block
 block discarded – undo
1975 2049
 		$this->context=array('commercial_modified'=>$commid);
1976 2050
 
1977 2051
 		$result=$this->call_trigger('COMPANY_UNLINK_SALE_REPRESENTATIVE',$user);
1978
-        if ($result < 0) $error++;
2052
+        if ($result < 0) {
2053
+            $error++;
2054
+        }
1979 2055
 
1980 2056
 		if ($this->id > 0 && $commid > 0)
1981 2057
 		{
@@ -2004,14 +2080,21 @@  discard block
 block discarded – undo
2004 2080
 	{
2005 2081
 		global $conf, $langs, $hookmanager;
2006 2082
 
2007
-		if (! empty($conf->dol_no_mouse_hover)) $notooltip=1;   // Force disable tooltips
2083
+		if (! empty($conf->dol_no_mouse_hover)) {
2084
+		    $notooltip=1;
2085
+		}
2086
+		// Force disable tooltips
2008 2087
 
2009 2088
 		$name=$this->name?$this->name:$this->nom;
2010 2089
 
2011 2090
 		if(!empty($conf->global->SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD)){
2012 2091
 
2013
-             if(empty($option) && $this->client > 0) $option = 'customer';
2014
-             if(empty($option) && $this->fournisseur > 0) $option = 'supplier';
2092
+             if(empty($option) && $this->client > 0) {
2093
+                 $option = 'customer';
2094
+             }
2095
+             if(empty($option) && $this->fournisseur > 0) {
2096
+                 $option = 'supplier';
2097
+             }
2015 2098
          }
2016 2099
 
2017 2100
 
@@ -2039,14 +2122,15 @@  discard block
 block discarded – undo
2039 2122
 			if ($conf->global->SOCIETE_ADD_REF_IN_LIST == 1)
2040 2123
 			{
2041 2124
 				$name =$code.' '.$name;
2042
-			}
2043
-			else
2125
+			} else
2044 2126
 			{
2045 2127
 				$name =$code;
2046 2128
 			}
2047 2129
 		}
2048 2130
 
2049
-		if (!empty($this->name_alias)) $name .= ' ('.$this->name_alias.')';
2131
+		if (!empty($this->name_alias)) {
2132
+		    $name .= ' ('.$this->name_alias.')';
2133
+		}
2050 2134
 
2051 2135
 		$result=''; $label='';
2052 2136
 		$linkstart=''; $linkend='';
@@ -2064,38 +2148,31 @@  discard block
 block discarded – undo
2064 2148
 		{
2065 2149
 		   $label.= '<u>' . $langs->trans("ShowCustomer") . '</u>';
2066 2150
 		   $linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id;
2067
-		}
2068
-		elseif ($option == 'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
2151
+		} elseif ($option == 'prospect' && empty($conf->global->SOCIETE_DISABLE_PROSPECTS))
2069 2152
 		{
2070 2153
 			$label.= '<u>' . $langs->trans("ShowProspect") . '</u>';
2071 2154
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/comm/card.php?socid='.$this->id;
2072
-		}
2073
-		elseif ($option == 'supplier')
2155
+		} elseif ($option == 'supplier')
2074 2156
 		{
2075 2157
 			$label.= '<u>' . $langs->trans("ShowSupplier") . '</u>';
2076 2158
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/fourn/card.php?socid='.$this->id;
2077
-		}
2078
-		elseif ($option == 'agenda')
2159
+		} elseif ($option == 'agenda')
2079 2160
 		{
2080 2161
 			$label.= '<u>' . $langs->trans("ShowAgenda") . '</u>';
2081 2162
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/agenda.php?socid='.$this->id;
2082
-		}
2083
-		elseif ($option == 'project')
2163
+		} elseif ($option == 'project')
2084 2164
 		{
2085 2165
 			$label.= '<u>' . $langs->trans("ShowProject") . '</u>';
2086 2166
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/project.php?socid='.$this->id;
2087
-		}
2088
-		elseif ($option == 'margin')
2167
+		} elseif ($option == 'margin')
2089 2168
 		{
2090 2169
 			$label.= '<u>' . $langs->trans("ShowMargin") . '</u>';
2091 2170
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/margin/tabs/thirdpartyMargins.php?socid='.$this->id.'&type=1';
2092
-		}
2093
-		elseif ($option == 'contact')
2171
+		} elseif ($option == 'contact')
2094 2172
 		{
2095 2173
 			$label.= '<u>' . $langs->trans("ShowContacts") . '</u>';
2096 2174
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/contact.php?socid='.$this->id;
2097
-		}
2098
-		elseif ($option == 'ban')
2175
+		} elseif ($option == 'ban')
2099 2176
 		{
2100 2177
 			$label.= '<u>' . $langs->trans("ShowBan") . '</u>';
2101 2178
 			$linkstart = '<a href="'.DOL_URL_ROOT.'/societe/paymentmodes.php?socid='.$this->id;
@@ -2111,30 +2188,50 @@  discard block
 block discarded – undo
2111 2188
 		if (! empty($this->name))
2112 2189
 		{
2113 2190
 			$label.= '<br><b>' . $langs->trans('Name') . ':</b> '. $this->name;
2114
-			if (! empty($this->name_alias)) $label.=' ('.$this->name_alias.')';
2191
+			if (! empty($this->name_alias)) {
2192
+			    $label.=' ('.$this->name_alias.')';
2193
+			}
2115 2194
 			$label.= '<br><b>' . $langs->trans('Email') . ':</b> '. $this->email;
2116 2195
 		}
2117
-		if (! empty($this->country_code))
2118
-			$label.= '<br><b>' . $langs->trans('Country') . ':</b> '. $this->country_code;
2119
-		if (! empty($this->tva_intra) || (! empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'vatnumber') !== false))
2120
-			$label.= '<br><b>' . $langs->trans('VATIntra') . ':</b> '. $this->tva_intra;
2196
+		if (! empty($this->country_code)) {
2197
+					$label.= '<br><b>' . $langs->trans('Country') . ':</b> '. $this->country_code;
2198
+		}
2199
+		if (! empty($this->tva_intra) || (! empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP) && strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'vatnumber') !== false)) {
2200
+					$label.= '<br><b>' . $langs->trans('VATIntra') . ':</b> '. $this->tva_intra;
2201
+		}
2121 2202
 		if (! empty($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP))
2122 2203
 		{
2123
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid1') !== false) $label.= '<br><b>' . $langs->trans('ProfId1'.$this->country_code) . ':</b> '. $this->idprof1;
2124
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid2') !== false) $label.= '<br><b>' . $langs->trans('ProfId2'.$this->country_code) . ':</b> '. $this->idprof2;
2125
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid3') !== false) $label.= '<br><b>' . $langs->trans('ProfId3'.$this->country_code) . ':</b> '. $this->idprof3;
2126
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid4') !== false) $label.= '<br><b>' . $langs->trans('ProfId4'.$this->country_code) . ':</b> '. $this->idprof4;
2127
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid5') !== false) $label.= '<br><b>' . $langs->trans('ProfId5'.$this->country_code) . ':</b> '. $this->idprof5;
2128
-			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid6') !== false) $label.= '<br><b>' . $langs->trans('ProfId6'.$this->country_code) . ':</b> '. $this->idprof6;
2129
-		}
2130
-		if (! empty($this->code_client) && ($this->client == 1 || $this->client == 3))
2131
-			$label.= '<br><b>' . $langs->trans('CustomerCode') . ':</b> '. $this->code_client;
2132
-		if (! empty($this->code_fournisseur) && $this->fournisseur)
2133
-			$label.= '<br><b>' . $langs->trans('SupplierCode') . ':</b> '. $this->code_fournisseur;
2134
-		if (! empty($conf->accounting->enabled) && ($this->client == 1 || $this->client == 3))
2135
-			$label.= '<br><b>' . $langs->trans('CustomerAccountancyCode') . ':</b> '. ($this->code_compta ? $this->code_compta : $this->code_compta_client);
2136
-		if (! empty($conf->accounting->enabled) && $this->fournisseur)
2137
-			$label.= '<br><b>' . $langs->trans('SupplierAccountancyCode') . ':</b> '. $this->code_compta_fournisseur;
2204
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid1') !== false) {
2205
+			    $label.= '<br><b>' . $langs->trans('ProfId1'.$this->country_code) . ':</b> '. $this->idprof1;
2206
+			}
2207
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid2') !== false) {
2208
+			    $label.= '<br><b>' . $langs->trans('ProfId2'.$this->country_code) . ':</b> '. $this->idprof2;
2209
+			}
2210
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid3') !== false) {
2211
+			    $label.= '<br><b>' . $langs->trans('ProfId3'.$this->country_code) . ':</b> '. $this->idprof3;
2212
+			}
2213
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid4') !== false) {
2214
+			    $label.= '<br><b>' . $langs->trans('ProfId4'.$this->country_code) . ':</b> '. $this->idprof4;
2215
+			}
2216
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid5') !== false) {
2217
+			    $label.= '<br><b>' . $langs->trans('ProfId5'.$this->country_code) . ':</b> '. $this->idprof5;
2218
+			}
2219
+			if (strpos($conf->global->SOCIETE_SHOW_FIELD_IN_TOOLTIP, 'profid6') !== false) {
2220
+			    $label.= '<br><b>' . $langs->trans('ProfId6'.$this->country_code) . ':</b> '. $this->idprof6;
2221
+			}
2222
+		}
2223
+		if (! empty($this->code_client) && ($this->client == 1 || $this->client == 3)) {
2224
+					$label.= '<br><b>' . $langs->trans('CustomerCode') . ':</b> '. $this->code_client;
2225
+		}
2226
+		if (! empty($this->code_fournisseur) && $this->fournisseur) {
2227
+					$label.= '<br><b>' . $langs->trans('SupplierCode') . ':</b> '. $this->code_fournisseur;
2228
+		}
2229
+		if (! empty($conf->accounting->enabled) && ($this->client == 1 || $this->client == 3)) {
2230
+					$label.= '<br><b>' . $langs->trans('CustomerAccountancyCode') . ':</b> '. ($this->code_compta ? $this->code_compta : $this->code_compta_client);
2231
+		}
2232
+		if (! empty($conf->accounting->enabled) && $this->fournisseur) {
2233
+					$label.= '<br><b>' . $langs->trans('SupplierAccountancyCode') . ':</b> '. $this->code_compta_fournisseur;
2234
+		}
2138 2235
 
2139 2236
 		$label.= '</div>';
2140 2237
 
@@ -2142,8 +2239,12 @@  discard block
 block discarded – undo
2142 2239
 		$linkstart.=(!empty($this->canvas)?'&canvas='.$this->canvas:'');
2143 2240
 		// Add param to save lastsearch_values or not
2144 2241
 		$add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0);
2145
-		if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1;
2146
-		if ($add_save_lastsearch_values) $linkstart.='&save_lastsearch_values=1';
2242
+		if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) {
2243
+		    $add_save_lastsearch_values=1;
2244
+		}
2245
+		if ($add_save_lastsearch_values) {
2246
+		    $linkstart.='&save_lastsearch_values=1';
2247
+		}
2147 2248
 		$linkstart.='"';
2148 2249
 
2149 2250
 		$linkclose='';
@@ -2175,16 +2276,23 @@  discard block
 block discarded – undo
2175 2276
 		}
2176 2277
 
2177 2278
 		$result.=$linkstart;
2178
-		if ($withpicto) $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip valigntextbottom"'), 0, 0, $notooltip?0:1);
2179
-		if ($withpicto != 2) $result.=($maxlen?dol_trunc($name,$maxlen):$name);
2279
+		if ($withpicto) {
2280
+		    $result.=img_object(($notooltip?'':$label), ($this->picto?$this->picto:'generic'), ($notooltip?(($withpicto != 2) ? 'class="paddingright"' : ''):'class="'.(($withpicto != 2) ? 'paddingright ' : '').'classfortooltip valigntextbottom"'), 0, 0, $notooltip?0:1);
2281
+		}
2282
+		if ($withpicto != 2) {
2283
+		    $result.=($maxlen?dol_trunc($name,$maxlen):$name);
2284
+		}
2180 2285
 		$result.=$linkend;
2181 2286
 
2182 2287
 		global $action;
2183 2288
 		$hookmanager->initHooks(array('thirdpartydao'));
2184 2289
 		$parameters=array('id'=>$this->id, 'getnomurl'=>$result);
2185 2290
 		$reshook=$hookmanager->executeHooks('getNomUrl',$parameters,$this,$action);    // Note that $action and $object may have been modified by some hooks
2186
-		if ($reshook > 0) $result = $hookmanager->resPrint;
2187
-		else $result .= $hookmanager->resPrint;
2291
+		if ($reshook > 0) {
2292
+		    $result = $hookmanager->resPrint;
2293
+		} else {
2294
+		    $result .= $hookmanager->resPrint;
2295
+		}
2188 2296
 
2189 2297
 		return $result;
2190 2298
 	}
@@ -2216,38 +2324,53 @@  discard block
 block discarded – undo
2216 2324
 
2217 2325
 		if ($mode == 0)
2218 2326
 		{
2219
-			if ($statut==0) return $langs->trans("ActivityCeased");
2220
-			elseif ($statut==1) return $langs->trans("InActivity");
2221
-		}
2222
-		elseif ($mode == 1)
2327
+			if ($statut==0) {
2328
+			    return $langs->trans("ActivityCeased");
2329
+			} elseif ($statut==1) {
2330
+			    return $langs->trans("InActivity");
2331
+			}
2332
+		} elseif ($mode == 1)
2223 2333
 		{
2224
-			if ($statut==0) return $langs->trans("ActivityCeased");
2225
-			elseif ($statut==1) return $langs->trans("InActivity");
2226
-		}
2227
-		elseif ($mode == 2)
2334
+			if ($statut==0) {
2335
+			    return $langs->trans("ActivityCeased");
2336
+			} elseif ($statut==1) {
2337
+			    return $langs->trans("InActivity");
2338
+			}
2339
+		} elseif ($mode == 2)
2228 2340
 		{
2229
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2230
-			elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2231
-		}
2232
-		elseif ($mode == 3)
2341
+			if ($statut==0) {
2342
+			    return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2343
+			} elseif ($statut==1) {
2344
+			    return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2345
+			}
2346
+		} elseif ($mode == 3)
2233 2347
 		{
2234
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2235
-			elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2236
-		}
2237
-		elseif ($mode == 4)
2348
+			if ($statut==0) {
2349
+			    return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2350
+			} elseif ($statut==1) {
2351
+			    return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2352
+			}
2353
+		} elseif ($mode == 4)
2238 2354
 		{
2239
-			if ($statut==0) return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2240
-			elseif ($statut==1) return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2241
-		}
2242
-		elseif ($mode == 5)
2355
+			if ($statut==0) {
2356
+			    return img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"').' '.$langs->trans("ActivityCeased");
2357
+			} elseif ($statut==1) {
2358
+			    return img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"').' '.$langs->trans("InActivity");
2359
+			}
2360
+		} elseif ($mode == 5)
2243 2361
 		{
2244
-			if ($statut==0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2245
-			elseif ($statut==1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2246
-		}
2247
-		elseif ($mode == 6)
2362
+			if ($statut==0) {
2363
+			    return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2364
+			} elseif ($statut==1) {
2365
+			    return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2366
+			}
2367
+		} elseif ($mode == 6)
2248 2368
 		{
2249
-			if ($statut==0) return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2250
-			elseif ($statut==1) return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2369
+			if ($statut==0) {
2370
+			    return '<span class="hideonsmartphone">'.$langs->trans("ActivityCeased").'</span> '.img_picto($langs->trans("ActivityCeased"),'statut5', 'class="pictostatus"');
2371
+			} elseif ($statut==1) {
2372
+			    return '<span class="hideonsmartphone">'.$langs->trans("InActivity").'</span> '.img_picto($langs->trans("InActivity"),'statut4', 'class="pictostatus"');
2373
+			}
2251 2374
 		}
2252 2375
 	}
2253 2376
 
@@ -2266,7 +2389,9 @@  discard block
 block discarded – undo
2266 2389
 		$contact_emails = $this->contact_property_array('email',1);
2267 2390
 		if ($this->email && $addthirdparty)
2268 2391
 		{
2269
-			if (empty($this->name)) $this->name=$this->nom;
2392
+			if (empty($this->name)) {
2393
+			    $this->name=$this->nom;
2394
+			}
2270 2395
 			$contact_emails['thirdparty']=$langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->email.">";
2271 2396
 		}
2272 2397
 		//var_dump($contact_emails)
@@ -2286,9 +2411,11 @@  discard block
 block discarded – undo
2286 2411
 
2287 2412
 		$contact_phone = $this->contact_property_array('mobile');
2288 2413
 
2289
-		if (! empty($this->phone))	// If a phone of thirdparty is defined, we add it ot mobile of contacts
2414
+		if (! empty($this->phone)) {
2415
+		    // If a phone of thirdparty is defined, we add it ot mobile of contacts
2290 2416
 		{
2291 2417
 			if (empty($this->name)) $this->name=$this->nom;
2418
+		}
2292 2419
 			// TODO: Tester si tel non deja present dans tableau contact
2293 2420
 			$contact_phone['thirdparty']=$langs->transnoentitiesnoconv("ThirdParty").': '.dol_trunc($this->name,16)." <".$this->phone.">";
2294 2421
 		}
@@ -2331,24 +2458,30 @@  discard block
 block discarded – undo
2331 2458
 				while ($i < $nump)
2332 2459
 				{
2333 2460
 					$obj = $this->db->fetch_object($resql);
2334
-					if ($mode == 'email') $property=$obj->email;
2335
-					else if ($mode == 'mobile') $property=$obj->phone_mobile;
2336
-					else $property=$obj->$mode;
2461
+					if ($mode == 'email') {
2462
+					    $property=$obj->email;
2463
+					} else if ($mode == 'mobile') {
2464
+					    $property=$obj->phone_mobile;
2465
+					} else {
2466
+					    $property=$obj->$mode;
2467
+					}
2337 2468
 
2338 2469
 					// Show all contact. If hidedisabled is 1, showonly contacts with status = 1
2339 2470
 					if ($obj->statut == 1 || empty($hidedisabled))
2340 2471
 					{
2341 2472
 						if (empty($property))
2342 2473
 						{
2343
-							if ($mode == 'email') $property=$langs->transnoentitiesnoconv("NoEMail");
2344
-							else if ($mode == 'mobile') $property=$langs->transnoentitiesnoconv("NoMobilePhone");
2474
+							if ($mode == 'email') {
2475
+							    $property=$langs->transnoentitiesnoconv("NoEMail");
2476
+							} else if ($mode == 'mobile') {
2477
+							    $property=$langs->transnoentitiesnoconv("NoMobilePhone");
2478
+							}
2345 2479
 						}
2346 2480
 
2347 2481
 						if (!empty($obj->poste))
2348 2482
 						{
2349 2483
 							$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname,$obj->lastname)).($obj->poste?" - ".$obj->poste:"").(($mode != 'poste' && $property)?" ".$sepa.$property.$sepb:'');
2350
-						}
2351
-						else
2484
+						} else
2352 2485
 						{
2353 2486
 							$contact_property[$obj->rowid] = trim(dolGetFirstLastname($obj->firstname,$obj->lastname)).(($mode != 'poste' && $property)?" ".$sepa.$property.$sepb:'');
2354 2487
 						}
@@ -2356,8 +2489,7 @@  discard block
 block discarded – undo
2356 2489
 					$i++;
2357 2490
 				}
2358 2491
 			}
2359
-		}
2360
-		else
2492
+		} else
2361 2493
 		{
2362 2494
 			dol_print_error($this->db);
2363 2495
 		}
@@ -2391,8 +2523,7 @@  discard block
 block discarded – undo
2391 2523
 					$i++;
2392 2524
 				}
2393 2525
 			}
2394
-		}
2395
-		else
2526
+		} else
2396 2527
 		{
2397 2528
 			dol_print_error($this->db);
2398 2529
 		}
@@ -2428,8 +2559,7 @@  discard block
 block discarded – undo
2428 2559
 					$i++;
2429 2560
 				}
2430 2561
 			}
2431
-		}
2432
-		else
2562
+		} else
2433 2563
 		{
2434 2564
 			dol_print_error($this->db);
2435 2565
 		}
@@ -2449,7 +2579,9 @@  discard block
 block discarded – undo
2449 2579
         // phpcs:enable
2450 2580
 		$contact_property='';
2451 2581
 
2452
-		if (empty($rowid)) return '';
2582
+		if (empty($rowid)) {
2583
+		    return '';
2584
+		}
2453 2585
 
2454 2586
 		$sql = "SELECT rowid, email, phone_mobile, lastname, firstname";
2455 2587
 		$sql.= " FROM ".MAIN_DB_PREFIX."socpeople";
@@ -2464,12 +2596,14 @@  discard block
 block discarded – undo
2464 2596
 			{
2465 2597
 				$obj = $this->db->fetch_object($resql);
2466 2598
 
2467
-				if ($mode == 'email') $contact_property = dol_string_nospecial(dolGetFirstLastname($obj->firstname, $obj->lastname), ' ', array(","))." <".$obj->email.">";
2468
-				else if ($mode == 'mobile') $contact_property = $obj->phone_mobile;
2599
+				if ($mode == 'email') {
2600
+				    $contact_property = dol_string_nospecial(dolGetFirstLastname($obj->firstname, $obj->lastname), ' ', array(","))." <".$obj->email.">";
2601
+				} else if ($mode == 'mobile') {
2602
+				    $contact_property = $obj->phone_mobile;
2603
+				}
2469 2604
 			}
2470 2605
 			return $contact_property;
2471
-		}
2472
-		else
2606
+		} else
2473 2607
 		{
2474 2608
 			dol_print_error($this->db);
2475 2609
 		}
@@ -2494,8 +2628,7 @@  discard block
 block discarded – undo
2494 2628
 		if ($mode == 'label')
2495 2629
 		{
2496 2630
 			return $bac->getRibLabel(true);
2497
-		}
2498
-		elseif ($mode == 'rum')
2631
+		} elseif ($mode == 'rum')
2499 2632
 		{
2500 2633
 			if (empty($bac->rum))
2501 2634
 			{
@@ -2505,8 +2638,7 @@  discard block
 block discarded – undo
2505 2638
 				$bac->rum = $prelevement->buildRumNumber($bac->thirdparty->code_client, $bac->datec, $bac->id);
2506 2639
 			}
2507 2640
 			return $bac->rum;
2508
-		}
2509
-		elseif ($mode == 'format')
2641
+		} elseif ($mode == 'format')
2510 2642
 		{
2511 2643
 			return $bac->frstrecur;
2512 2644
 		}
@@ -2565,7 +2697,9 @@  discard block
 block discarded – undo
2565 2697
 			foreach ($dirsociete as $dirroot)
2566 2698
 			{
2567 2699
 				$res=dol_include_once($dirroot.$module.'.php');
2568
-				if ($res) break;
2700
+				if ($res) {
2701
+				    break;
2702
+				}
2569 2703
 			}
2570 2704
 			$mod = new $module();
2571 2705
 
@@ -2597,7 +2731,9 @@  discard block
 block discarded – undo
2597 2731
 			foreach ($dirsociete as $dirroot)
2598 2732
 			{
2599 2733
 				$res=dol_include_once($dirroot.$module.'.php');
2600
-				if ($res) break;
2734
+				if ($res) {
2735
+				    break;
2736
+				}
2601 2737
 			}
2602 2738
 			$mod = new $module();
2603 2739
 
@@ -2626,18 +2762,26 @@  discard block
 block discarded – undo
2626 2762
 			foreach ($dirsociete as $dirroot)
2627 2763
 			{
2628 2764
 				$res=dol_include_once($dirroot.$module.'.php');
2629
-				if ($res) break;
2765
+				if ($res) {
2766
+				    break;
2767
+				}
2630 2768
 			}
2631 2769
 
2632 2770
 			$mod = new $module();
2633 2771
 
2634 2772
 			dol_syslog(get_class($this)."::codeclient_modifiable code_client=".$this->code_client." module=".$module);
2635
-			if ($mod->code_modifiable_null && ! $this->code_client) return 1;
2636
-			if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) return 1;
2637
-			if ($mod->code_modifiable) return 1;	// A mettre en dernier
2773
+			if ($mod->code_modifiable_null && ! $this->code_client) {
2774
+			    return 1;
2775
+			}
2776
+			if ($mod->code_modifiable_invalide && $this->check_codeclient() < 0) {
2777
+			    return 1;
2778
+			}
2779
+			if ($mod->code_modifiable) {
2780
+			    return 1;
2781
+			}
2782
+			// A mettre en dernier
2638 2783
 			return 0;
2639
-		}
2640
-		else
2784
+		} else
2641 2785
 		{
2642 2786
 			return 0;
2643 2787
 		}
@@ -2662,18 +2806,26 @@  discard block
 block discarded – undo
2662 2806
 			foreach ($dirsociete as $dirroot)
2663 2807
 			{
2664 2808
 				$res=dol_include_once($dirroot.$module.'.php');
2665
-				if ($res) break;
2809
+				if ($res) {
2810
+				    break;
2811
+				}
2666 2812
 			}
2667 2813
 
2668 2814
 			$mod = new $module();
2669 2815
 
2670 2816
 			dol_syslog(get_class($this)."::codefournisseur_modifiable code_founisseur=".$this->code_fournisseur." module=".$module);
2671
-			if ($mod->code_modifiable_null && ! $this->code_fournisseur) return 1;
2672
-			if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) return 1;
2673
-			if ($mod->code_modifiable) return 1;	// A mettre en dernier
2817
+			if ($mod->code_modifiable_null && ! $this->code_fournisseur) {
2818
+			    return 1;
2819
+			}
2820
+			if ($mod->code_modifiable_invalide && $this->check_codefournisseur() < 0) {
2821
+			    return 1;
2822
+			}
2823
+			if ($mod->code_modifiable) {
2824
+			    return 1;
2825
+			}
2826
+			// A mettre en dernier
2674 2827
 			return 0;
2675
-		}
2676
-		else
2828
+		} else
2677 2829
 		{
2678 2830
 			return 0;
2679 2831
 		}
@@ -2702,7 +2854,9 @@  discard block
 block discarded – undo
2702 2854
 			foreach ($dirsociete as $dirroot)
2703 2855
 			{
2704 2856
 				$res=dol_include_once($dirroot.$module.'.php');
2705
-				if ($res) break;
2857
+				if ($res) {
2858
+				    break;
2859
+				}
2706 2860
 			}
2707 2861
 
2708 2862
 			$mod = new $module();
@@ -2710,8 +2864,7 @@  discard block
 block discarded – undo
2710 2864
 		   	dol_syslog(get_class($this)."::check_codeclient code_client=".$this->code_client." module=".$module);
2711 2865
 		   	$result = $mod->verif($this->db, $this->code_client, $this, 0);
2712 2866
 			return $result;
2713
-		}
2714
-		else
2867
+		} else
2715 2868
 		{
2716 2869
 			return 0;
2717 2870
 		}
@@ -2739,7 +2892,9 @@  discard block
 block discarded – undo
2739 2892
 			foreach ($dirsociete as $dirroot)
2740 2893
 			{
2741 2894
 				$res=dol_include_once($dirroot.$module.'.php');
2742
-				if ($res) break;
2895
+				if ($res) {
2896
+				    break;
2897
+				}
2743 2898
 			}
2744 2899
 
2745 2900
 			$mod = new $module();
@@ -2747,8 +2902,7 @@  discard block
 block discarded – undo
2747 2902
 			dol_syslog(get_class($this)."::check_codefournisseur code_fournisseur=".$this->code_fournisseur." module=".$module);
2748 2903
 			$result = $mod->verif($this->db, $this->code_fournisseur, $this, 1);
2749 2904
 			return $result;
2750
-		}
2751
-		else
2905
+		} else
2752 2906
 		{
2753 2907
 			return 0;
2754 2908
 		}
@@ -2775,7 +2929,9 @@  discard block
 block discarded – undo
2775 2929
 			foreach ($dirsociete as $dirroot)
2776 2930
 			{
2777 2931
 				$res=dol_include_once($dirroot.$conf->global->SOCIETE_CODECOMPTA_ADDON.'.php');
2778
-				if ($res) break;
2932
+				if ($res) {
2933
+				    break;
2934
+				}
2779 2935
 			}
2780 2936
 
2781 2937
 			if ($res)
@@ -2786,21 +2942,25 @@  discard block
 block discarded – undo
2786 2942
 				// Defini code compta dans $mod->code
2787 2943
 				$result = $mod->get_code($this->db, $this, $type);
2788 2944
 
2789
-				if ($type == 'customer') $this->code_compta = $mod->code;
2790
-				else if ($type == 'supplier') $this->code_compta_fournisseur = $mod->code;
2945
+				if ($type == 'customer') {
2946
+				    $this->code_compta = $mod->code;
2947
+				} else if ($type == 'supplier') {
2948
+				    $this->code_compta_fournisseur = $mod->code;
2949
+				}
2791 2950
 
2792 2951
 				return $result;
2793
-			}
2794
-			else
2952
+			} else
2795 2953
 			{
2796 2954
 				$this->error = 'ErrorAccountancyCodeNotDefined';
2797 2955
 				return -1;
2798 2956
 			}
2799
-		}
2800
-		else
2957
+		} else
2801 2958
 		{
2802
-			if ($type == 'customer') $this->code_compta = '';
2803
-			else if ($type == 'supplier') $this->code_compta_fournisseur = '';
2959
+			if ($type == 'customer') {
2960
+			    $this->code_compta = '';
2961
+			} else if ($type == 'supplier') {
2962
+			    $this->code_compta_fournisseur = '';
2963
+			}
2804 2964
 
2805 2965
 			return 0;
2806 2966
 		}
@@ -2827,13 +2987,13 @@  discard block
 block discarded – undo
2827 2987
 			{
2828 2988
 				$this->parent = $id;
2829 2989
 				return 1;
2830
-			}
2831
-			else
2990
+			} else
2832 2991
 			{
2833 2992
 				return -1;
2834 2993
 			}
2994
+		} else {
2995
+		    return -1;
2835 2996
 		}
2836
-		else return -1;
2837 2997
 	}
2838 2998
 
2839 2999
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -2917,22 +3077,26 @@  discard block
 block discarded – undo
2917 3077
 
2918 3078
 		 //Verify duplicate entries
2919 3079
 		$sql  = "SELECT COUNT(*) as idprof FROM ".MAIN_DB_PREFIX."societe WHERE ".$field." = '".$value."' AND entity IN (".getEntity('societe').")";
2920
-		if($socid) $sql .= " AND rowid <> ".$socid;
3080
+		if($socid) {
3081
+		    $sql .= " AND rowid <> ".$socid;
3082
+		}
2921 3083
 		$resql = $this->db->query($sql);
2922 3084
 		if ($resql)
2923 3085
 		{
2924 3086
 			$obj = $this->db->fetch_object($resql);
2925 3087
 			$count = $obj->idprof;
2926
-		}
2927
-		else
3088
+		} else
2928 3089
 		{
2929 3090
 			$count = 0;
2930 3091
 			print $this->db->error();
2931 3092
 		}
2932 3093
 		$this->db->free($resql);
2933 3094
 
2934
-		if ($count > 0) return true;
2935
-		else return false;
3095
+		if ($count > 0) {
3096
+		    return true;
3097
+		} else {
3098
+		    return false;
3099
+		}
2936 3100
 	}
2937 3101
 
2938 3102
     // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps
@@ -2951,7 +3115,9 @@  discard block
 block discarded – undo
2951 3115
 
2952 3116
 		$ok=1;
2953 3117
 
2954
-		if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) return 1;
3118
+		if (! empty($conf->global->MAIN_DISABLEPROFIDRULES)) {
3119
+		    return 1;
3120
+		}
2955 3121
 
2956 3122
 		// Verifie SIREN si pays FR
2957 3123
 		if ($idprof == 1 && $soc->country_code == 'FR')
@@ -2959,8 +3125,12 @@  discard block
 block discarded – undo
2959 3125
 			$chaine=trim($this->idprof1);
2960 3126
 			$chaine=preg_replace('/(\s)/','',$chaine);
2961 3127
 
2962
-			if (!is_numeric($chaine)) return -1;
2963
-			if (dol_strlen($chaine) != 9) return -1;
3128
+			if (!is_numeric($chaine)) {
3129
+			    return -1;
3130
+			}
3131
+			if (dol_strlen($chaine) != 9) {
3132
+			    return -1;
3133
+			}
2964 3134
 
2965 3135
 			// on prend chaque chiffre un par un
2966 3136
 			// si son index (position dans la chaîne en commence à 0 au premier caractère) est impair
@@ -2970,12 +3140,17 @@  discard block
 block discarded – undo
2970 3140
 			for ($index = 0; $index < 9; $index ++)
2971 3141
 			{
2972 3142
 				$number = (int) $siren[$index];
2973
-				if (($index % 2) != 0) { if (($number *= 2) > 9) $number -= 9; }
3143
+				if (($index % 2) != 0) { if (($number *= 2) > 9) {
3144
+				    $number -= 9;
3145
+				}
3146
+				}
2974 3147
 				$sum += $number;
2975 3148
 			}
2976 3149
 
2977 3150
 			// le numéro est valide si la somme des chiffres est multiple de 10
2978
-			if (($sum % 10) != 0) return -1;
3151
+			if (($sum % 10) != 0) {
3152
+			    return -1;
3153
+			}
2979 3154
 		}
2980 3155
 
2981 3156
 		// Verifie SIRET si pays FR
@@ -2984,8 +3159,12 @@  discard block
 block discarded – undo
2984 3159
 			$chaine=trim($this->idprof2);
2985 3160
 			$chaine=preg_replace('/(\s)/','',$chaine);
2986 3161
 
2987
-			if (!is_numeric($chaine)) return -1;
2988
-			if (dol_strlen($chaine) != 14) return -1;
3162
+			if (!is_numeric($chaine)) {
3163
+			    return -1;
3164
+			}
3165
+			if (dol_strlen($chaine) != 14) {
3166
+			    return -1;
3167
+			}
2989 3168
 
2990 3169
 			// on prend chaque chiffre un par un
2991 3170
 			// si son index (position dans la chaîne en commence à 0 au premier caractère) est pair
@@ -2995,12 +3174,17 @@  discard block
 block discarded – undo
2995 3174
 			for ($index = 0; $index < 14; $index ++)
2996 3175
 			{
2997 3176
 				$number = (int) $chaine[$index];
2998
-				if (($index % 2) == 0) { if (($number *= 2) > 9) $number -= 9; }
3177
+				if (($index % 2) == 0) { if (($number *= 2) > 9) {
3178
+				    $number -= 9;
3179
+				}
3180
+				}
2999 3181
 				$sum += $number;
3000 3182
 			}
3001 3183
 
3002 3184
 			// le numéro est valide si la somme des chiffres est multiple de 10
3003
-			if (($sum % 10) != 0) return -1;
3185
+			if (($sum % 10) != 0) {
3186
+			    return -1;
3187
+			}
3004 3188
 		}
3005 3189
 
3006 3190
 		//Verify CIF/NIF/NIE if pays ES
@@ -3011,53 +3195,61 @@  discard block
 block discarded – undo
3011 3195
 			$string=preg_replace('/(\s)/','',$string);
3012 3196
 			$string = strtoupper($string);
3013 3197
 
3014
-			for ($i = 0; $i < 9; $i ++)
3015
-			$num[$i] = substr($string, $i, 1);
3198
+			for ($i = 0; $i < 9; $i ++) {
3199
+						$num[$i] = substr($string, $i, 1);
3200
+			}
3016 3201
 
3017 3202
 			//Check format
3018
-			if (!preg_match('/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $string))
3019
-			return 0;
3203
+			if (!preg_match('/((^[A-Z]{1}[0-9]{7}[A-Z0-9]{1}$|^[T]{1}[A-Z0-9]{8}$)|^[0-9]{8}[A-Z]{1}$)/', $string)) {
3204
+						return 0;
3205
+			}
3020 3206
 
3021 3207
 			//Check NIF
3022
-			if (preg_match('/(^[0-9]{8}[A-Z]{1}$)/', $string))
3023
-				if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1))
3208
+			if (preg_match('/(^[0-9]{8}[A-Z]{1}$)/', $string)) {
3209
+							if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 0, 8) % 23, 1))
3024 3210
 				return 1;
3025
-				else
3026
-				return -1;
3211
+			} else {
3212
+								return -1;
3213
+				}
3027 3214
 
3028 3215
 			//algorithm checking type code CIF
3029 3216
 			$sum = $num[2] + $num[4] + $num[6];
3030
-			for ($i = 1; $i < 8; $i += 2)
3031
-			$sum += intval(substr((2 * $num[$i]),0,1)) + intval(substr((2 * $num[$i]),1,1));
3217
+			for ($i = 1; $i < 8; $i += 2) {
3218
+						$sum += intval(substr((2 * $num[$i]),0,1)) + intval(substr((2 * $num[$i]),1,1));
3219
+			}
3032 3220
 			$n = 10 - substr($sum, strlen($sum) - 1, 1);
3033 3221
 
3034 3222
 			//Chek special NIF
3035
-			if (preg_match('/^[KLM]{1}/', $string))
3036
-				if ($num[8] == chr(64 + $n) || $num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1))
3223
+			if (preg_match('/^[KLM]{1}/', $string)) {
3224
+							if ($num[8] == chr(64 + $n) || $num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr($string, 1, 8) % 23, 1))
3037 3225
 				return 1;
3038
-				else
3039
-				return -1;
3226
+			} else {
3227
+								return -1;
3228
+				}
3040 3229
 
3041 3230
 			//Check CIF
3042
-			if (preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $string))
3043
-				if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1))
3231
+			if (preg_match('/^[ABCDEFGHJNPQRSUVW]{1}/', $string)) {
3232
+							if ($num[8] == chr(64 + $n) || $num[8] == substr($n, strlen($n) - 1, 1))
3044 3233
 				return 2;
3045
-				else
3046
-				return -2;
3234
+			} else {
3235
+								return -2;
3236
+				}
3047 3237
 
3048 3238
 			//Check NIE T
3049
-			if (preg_match('/^[T]{1}/', $string))
3050
-				if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $string))
3239
+			if (preg_match('/^[T]{1}/', $string)) {
3240
+							if ($num[8] == preg_match('/^[T]{1}[A-Z0-9]{8}$/', $string))
3051 3241
 				return 3;
3052
-				else
3053
-				return -3;
3242
+			} else {
3243
+								return -3;
3244
+				}
3054 3245
 
3055 3246
 			//Check NIE XYZ
3056
-			if (preg_match('/^[XYZ]{1}/', $string))
3057
-				if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X','Y','Z'), array('0','1','2'), $string), 0, 8) % 23, 1))
3247
+			if (preg_match('/^[XYZ]{1}/', $string)) {
3248
+							if ($num[8] == substr('TRWAGMYFPDXBNJZSQVHLCKE', substr(str_replace(array('X','Y','Z'), array('0','1','2'), $string), 0, 8) % 23, 1))
3058 3249
 				return 3;
3059
-				else
3060
-				return -3;
3250
+			} else {
3251
+								return -3;
3252
+				}
3061 3253
 
3062 3254
 			//Can not be verified
3063 3255
 			return -4;
@@ -3077,8 +3269,7 @@  discard block
 block discarded – undo
3077 3269
 			//Check NIF
3078 3270
 			if (preg_match('/(^[0-9]{9}$)/', $string)) {
3079 3271
 				return 1;
3080
-			}
3081
-			else {
3272
+			} else {
3082 3273
 				return -1;
3083 3274
 			}
3084 3275
 		}
@@ -3132,8 +3323,7 @@  discard block
 block discarded – undo
3132 3323
 			if ($url) {
3133 3324
 				return '<a target="_blank" href="'.$url.'">'.$langs->trans("Check").'</a>';
3134 3325
 			}
3135
-		}
3136
-		else {
3326
+		} else {
3137 3327
 			return $hookmanager->resPrint;
3138 3328
 		}
3139 3329
 
@@ -3155,8 +3345,7 @@  discard block
 block discarded – undo
3155 3345
 		{
3156 3346
 			$obj = $this->db->fetch_object($resql);
3157 3347
 			$count = $obj->numproj;
3158
-		}
3159
-		else
3348
+		} else
3160 3349
 		{
3161 3350
 			$count = 0;
3162 3351
 			print $this->db->error();
@@ -3206,8 +3395,7 @@  discard block
 block discarded – undo
3206 3395
 			}
3207 3396
 
3208 3397
 			$this->db->free($result);
3209
-		}
3210
-		else
3398
+		} else
3211 3399
 		{
3212 3400
 			dol_print_error($this->db);
3213 3401
 		}
@@ -3224,12 +3412,16 @@  discard block
 block discarded – undo
3224 3412
 
3225 3413
 		// Define if third party is treated as company (or not) when nature is unknown
3226 3414
 		$isacompany=empty($conf->global->MAIN_UNKNOWN_CUSTOMERS_ARE_COMPANIES)?0:1; // 0 by default
3227
-		if (! empty($this->tva_intra)) $isacompany=1;
3228
-		else if (! empty($this->typent_code) && $this->typent_code != 'TE_UNKNOWN')
3415
+		if (! empty($this->tva_intra)) {
3416
+		    $isacompany=1;
3417
+		} else if (! empty($this->typent_code) && $this->typent_code != 'TE_UNKNOWN')
3229 3418
 		{
3230 3419
 			// TODO Add a field is_a_company into dictionary
3231
-			if (preg_match('/^TE_PRIVATE/', $this->typent_code)) $isacompany=0;
3232
-			else $isacompany=1;
3420
+			if (preg_match('/^TE_PRIVATE/', $this->typent_code)) {
3421
+			    $isacompany=0;
3422
+			} else {
3423
+			    $isacompany=1;
3424
+			}
3233 3425
 		}
3234 3426
 
3235 3427
 		return $isacompany;
@@ -3268,8 +3460,7 @@  discard block
 block discarded – undo
3268 3460
 				$this->SupplierCategories[$obj->rowid] = $obj->label;
3269 3461
 			}
3270 3462
 			return 0;
3271
-		}
3272
-		else
3463
+		} else
3273 3464
 		{
3274 3465
 			return -1;
3275 3466
 		}
@@ -3290,9 +3481,10 @@  discard block
 block discarded – undo
3290 3481
 			$sql = "INSERT INTO ".MAIN_DB_PREFIX."categorie_fournisseur (fk_categorie, fk_soc) ";
3291 3482
 			$sql.= " VALUES (".$categorie_id.", ".$this->id.")";
3292 3483
 
3293
-			if ($resql=$this->db->query($sql)) return 0;
3294
-		}
3295
-		else
3484
+			if ($resql=$this->db->query($sql)) {
3485
+			    return 0;
3486
+			}
3487
+		} else
3296 3488
 		{
3297 3489
 			return 0;
3298 3490
 		}
@@ -3318,7 +3510,9 @@  discard block
 block discarded – undo
3318 3510
 		dol_syslog(get_class($this)."::create_from_member", LOG_DEBUG);
3319 3511
 
3320 3512
 		$name = $socname?$socname:$member->societe;
3321
-		if (empty($name)) $name=$member->getFullName($langs);
3513
+		if (empty($name)) {
3514
+		    $name=$member->getFullName($langs);
3515
+		}
3322 3516
 
3323 3517
 		$alias = $socalias?$socalias:'';
3324 3518
 
@@ -3356,16 +3550,14 @@  discard block
 block discarded – undo
3356 3550
 			{
3357 3551
 				$this->db->commit();
3358 3552
 				return $this->id;
3359
-			}
3360
-			else
3553
+			} else
3361 3554
 			{
3362 3555
 				$this->error=$this->db->error();
3363 3556
 
3364 3557
 				$this->db->rollback();
3365 3558
 				return -1;
3366 3559
 			}
3367
-		}
3368
-		else
3560
+		} else
3369 3561
 		{
3370 3562
 			// $this->error deja positionne
3371 3563
 			dol_syslog(get_class($this)."::create_from_member - 2 - ".$this->error." - ".join(',',$this->errors), LOG_ERR);
@@ -3404,12 +3596,13 @@  discard block
 block discarded – undo
3404 3596
 		{
3405 3597
 			$tmp=explode(':',$conf->global->MAIN_INFO_SOCIETE_COUNTRY);
3406 3598
 			$country_id=$tmp[0];
3407
-			if (! empty($tmp[1]))   // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label"
3599
+			if (! empty($tmp[1])) {
3600
+			    // If $conf->global->MAIN_INFO_SOCIETE_COUNTRY is "id:code:label"
3408 3601
 			{
3409 3602
 				$country_code=$tmp[1];
3410
-				$country_label=$tmp[2];
3411 3603
 			}
3412
-			else                    // For backward compatibility
3604
+				$country_label=$tmp[2];
3605
+			} else                    // For backward compatibility
3413 3606
 			{
3414 3607
 				dol_syslog("Your country setup use an old syntax. Reedit it using setup area.", LOG_ERR);
3415 3608
 				include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
@@ -3420,7 +3613,9 @@  discard block
 block discarded – undo
3420 3613
 		$this->country_id=$country_id;
3421 3614
 		$this->country_code=$country_code;
3422 3615
 		$this->country=$country_label;
3423
-		if (is_object($langs)) $this->country=($langs->trans('Country'.$country_code)!='Country'.$country_code)?$langs->trans('Country'.$country_code):$country_label;
3616
+		if (is_object($langs)) {
3617
+		    $this->country=($langs->trans('Country'.$country_code)!='Country'.$country_code)?$langs->trans('Country'.$country_code):$country_label;
3618
+		}
3424 3619
 
3425 3620
 		$this->phone=empty($conf->global->MAIN_INFO_SOCIETE_TEL)?'':$conf->global->MAIN_INFO_SOCIETE_TEL;
3426 3621
 		$this->fax=empty($conf->global->MAIN_INFO_SOCIETE_FAX)?'':$conf->global->MAIN_INFO_SOCIETE_FAX;
@@ -3514,17 +3709,22 @@  discard block
 block discarded – undo
3514 3709
 		$sql .= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c";
3515 3710
 		$sql .= " WHERE t.fk_pays = c.rowid AND c.code = '".$this->db->escape($this->country_code)."'";
3516 3711
 		$sql .= " AND t.active = 1";
3517
-		if (empty($localTaxNum))   $sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
3518
-		elseif ($localTaxNum == 1) $sql .= " AND t.localtax1_type <> '0'";
3519
-		elseif ($localTaxNum == 2) $sql .= " AND t.localtax2_type <> '0'";
3712
+		if (empty($localTaxNum)) {
3713
+		    $sql .= " AND (t.localtax1_type <> '0' OR t.localtax2_type <> '0')";
3714
+		} elseif ($localTaxNum == 1) {
3715
+		    $sql .= " AND t.localtax1_type <> '0'";
3716
+		} elseif ($localTaxNum == 2) {
3717
+		    $sql .= " AND t.localtax2_type <> '0'";
3718
+		}
3520 3719
 
3521 3720
 		dol_syslog("useLocalTax", LOG_DEBUG);
3522 3721
 		$resql=$this->db->query($sql);
3523 3722
 		if ($resql)
3524 3723
 		{
3525 3724
    			return ($this->db->num_rows($resql) > 0);
3725
+		} else {
3726
+		    return false;
3526 3727
 		}
3527
-		else return false;
3528 3728
 	}
3529 3729
 
3530 3730
 	/**
@@ -3544,8 +3744,9 @@  discard block
 block discarded – undo
3544 3744
 		if ($resql)
3545 3745
 		{
3546 3746
 			return ($this->db->num_rows($resql) > 0);
3747
+		} else {
3748
+		    return false;
3547 3749
 		}
3548
-		else return false;
3549 3750
 	}
3550 3751
 
3551 3752
 	/**
@@ -3566,8 +3767,7 @@  discard block
 block discarded – undo
3566 3767
 		{
3567 3768
 			$obj=$this->db->fetch_object($resql);
3568 3769
    			return (($obj->nb > 0)?true:false);
3569
-		}
3570
-		else
3770
+		} else
3571 3771
 		{
3572 3772
 			$this->error=$this->db->lasterror();
3573 3773
 			return false;
@@ -3649,36 +3849,51 @@  discard block
 block discarded – undo
3649 3849
 
3650 3850
 		if ($mode == 2)
3651 3851
 		{
3652
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3653
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3654
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3655
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3656
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3657
-			else
3852
+			if ($statut == '-1' || $statut == 'ST_NO') {
3853
+			    return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3854
+			} elseif ($statut ==  '0' || $statut == 'ST_NEVER') {
3855
+			    return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3856
+			} elseif ($statut ==  '1' || $statut == 'ST_TODO') {
3857
+			    return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3858
+			} elseif ($statut ==  '2' || $statut == 'ST_PEND') {
3859
+			    return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3860
+			} elseif ($statut ==  '3' || $statut == 'ST_DONE') {
3861
+			    return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3862
+			} else
3658 3863
 			{
3659 3864
 				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
3660 3865
 			}
3661 3866
 		}
3662 3867
 		if ($mode == 3)
3663 3868
 		{
3664
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1);
3665
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0);
3666
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1);
3667
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2);
3668
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3);
3669
-			else
3869
+			if ($statut == '-1' || $statut == 'ST_NO') {
3870
+			    return img_action($langs->trans("StatusProspect-1"),-1);
3871
+			} elseif ($statut ==  '0' || $statut == 'ST_NEVER') {
3872
+			    return img_action($langs->trans("StatusProspect0"), 0);
3873
+			} elseif ($statut ==  '1' || $statut == 'ST_TODO') {
3874
+			    return img_action($langs->trans("StatusProspect1"), 1);
3875
+			} elseif ($statut ==  '2' || $statut == 'ST_PEND') {
3876
+			    return img_action($langs->trans("StatusProspect2"), 2);
3877
+			} elseif ($statut ==  '3' || $statut == 'ST_DONE') {
3878
+			    return img_action($langs->trans("StatusProspect3"), 3);
3879
+			} else
3670 3880
 			{
3671 3881
 				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0);
3672 3882
 			}
3673 3883
 		}
3674 3884
 		if ($mode == 4)
3675 3885
 		{
3676
-			if ($statut == '-1' || $statut == 'ST_NO')         return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3677
-			elseif ($statut ==  '0' || $statut == 'ST_NEVER') return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3678
-			elseif ($statut ==  '1' || $statut == 'ST_TODO')  return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3679
-			elseif ($statut ==  '2' || $statut == 'ST_PEND')  return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3680
-			elseif ($statut ==  '3' || $statut == 'ST_DONE')  return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3681
-			else
3886
+			if ($statut == '-1' || $statut == 'ST_NO') {
3887
+			    return img_action($langs->trans("StatusProspect-1"),-1).' '.$langs->trans("StatusProspect-1");
3888
+			} elseif ($statut ==  '0' || $statut == 'ST_NEVER') {
3889
+			    return img_action($langs->trans("StatusProspect0"), 0).' '.$langs->trans("StatusProspect0");
3890
+			} elseif ($statut ==  '1' || $statut == 'ST_TODO') {
3891
+			    return img_action($langs->trans("StatusProspect1"), 1).' '.$langs->trans("StatusProspect1");
3892
+			} elseif ($statut ==  '2' || $statut == 'ST_PEND') {
3893
+			    return img_action($langs->trans("StatusProspect2"), 2).' '.$langs->trans("StatusProspect2");
3894
+			} elseif ($statut ==  '3' || $statut == 'ST_DONE') {
3895
+			    return img_action($langs->trans("StatusProspect3"), 3).' '.$langs->trans("StatusProspect3");
3896
+			} else
3682 3897
 			{
3683 3898
 				return img_action(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label, 0).' '.(($langs->trans("StatusProspect".$statut) != "StatusProspect".$statut) ? $langs->trans("StatusProspect".$statut) : $label);
3684 3899
 			}
@@ -3710,7 +3925,9 @@  discard block
 block discarded – undo
3710 3925
 	function getOutstandingProposals($mode='customer')
3711 3926
 	{
3712 3927
 		$table='propal';
3713
-		if ($mode == 'supplier') $table = 'supplier_proposal';
3928
+		if ($mode == 'supplier') {
3929
+		    $table = 'supplier_proposal';
3930
+		}
3714 3931
 
3715 3932
 		$sql  = "SELECT rowid, total_ht, total as total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f";
3716 3933
 		$sql .= " WHERE fk_soc = ". $this->id;
@@ -3730,15 +3947,17 @@  discard block
 block discarded – undo
3730 3947
 			while($obj=$this->db->fetch_object($resql)) {
3731 3948
 				$outstandingTotal+= $obj->total_ht;
3732 3949
 				$outstandingTotalIncTax+= $obj->total_ttc;
3733
-				if ($obj->fk_statut != 0)    // Not a draft
3950
+				if ($obj->fk_statut != 0) {
3951
+				    // Not a draft
3734 3952
 				{
3735 3953
 					$outstandingOpened+=$obj->total_ttc;
3736 3954
 				}
3955
+				}
3737 3956
 			}
3738 3957
 			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3958
+		} else {
3959
+					return array();
3739 3960
 		}
3740
-		else
3741
-			return array();
3742 3961
 	}
3743 3962
 
3744 3963
 	/**
@@ -3750,7 +3969,9 @@  discard block
 block discarded – undo
3750 3969
 	function getOutstandingOrders($mode='customer')
3751 3970
 	{
3752 3971
 		$table='commande';
3753
-		if ($mode == 'supplier') $table = 'commande_fournisseur';
3972
+		if ($mode == 'supplier') {
3973
+		    $table = 'commande_fournisseur';
3974
+		}
3754 3975
 
3755 3976
 		$sql  = "SELECT rowid, total_ht, total_ttc, fk_statut FROM ".MAIN_DB_PREFIX.$table." as f";
3756 3977
 		$sql .= " WHERE fk_soc = ". $this->id;
@@ -3770,15 +3991,17 @@  discard block
 block discarded – undo
3770 3991
 			while($obj=$this->db->fetch_object($resql)) {
3771 3992
 				$outstandingTotal+= $obj->total_ht;
3772 3993
 				$outstandingTotalIncTax+= $obj->total_ttc;
3773
-				if ($obj->fk_statut != 0)    // Not a draft
3994
+				if ($obj->fk_statut != 0) {
3995
+				    // Not a draft
3774 3996
 				{
3775 3997
 					$outstandingOpened+=$obj->total_ttc;
3776 3998
 				}
3999
+				}
3777 4000
 			}
3778 4001
 			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
4002
+		} else {
4003
+					return array();
3779 4004
 		}
3780
-		else
3781
-			return array();
3782 4005
 	}
3783 4006
 
3784 4007
 	/**
@@ -3790,7 +4013,9 @@  discard block
 block discarded – undo
3790 4013
 	function getOutstandingBills($mode='customer')
3791 4014
 	{
3792 4015
 		$table='facture';
3793
-		if ($mode == 'supplier') $table = 'facture_fourn';
4016
+		if ($mode == 'supplier') {
4017
+		    $table = 'facture_fourn';
4018
+		}
3794 4019
 
3795 4020
 		/* Accurate value of remain to pay is to sum remaintopay for each invoice
3796 4021
 		 $paiement = $invoice->getSommePaiement();
@@ -3799,8 +4024,11 @@  discard block
 block discarded – undo
3799 4024
 		 $alreadypayed=price2num($paiement + $creditnotes + $deposits,'MT');
3800 4025
 		 $remaintopay=price2num($invoice->total_ttc - $paiement - $creditnotes - $deposits,'MT');
3801 4026
 		 */
3802
-		if ($mode == 'supplier') $sql  = "SELECT rowid, total_ht as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
3803
-		else $sql  = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
4027
+		if ($mode == 'supplier') {
4028
+		    $sql  = "SELECT rowid, total_ht as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
4029
+		} else {
4030
+		    $sql  = "SELECT rowid, total as total_ht, total_ttc, paye, fk_statut, close_code FROM ".MAIN_DB_PREFIX.$table." as f";
4031
+		}
3804 4032
 		$sql .= " WHERE fk_soc = ". $this->id;
3805 4033
 		if ($mode == 'supplier') {
3806 4034
 			$sql .= " AND entity IN (".getEntity('facture_fourn').")";
@@ -3819,8 +4047,7 @@  discard block
 block discarded – undo
3819 4047
 			{
3820 4048
 				require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php';
3821 4049
 				$tmpobject=new FactureFournisseur($this->db);
3822
-			}
3823
-			else
4050
+			} else
3824 4051
 			{
3825 4052
 				require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
3826 4053
 				$tmpobject=new Facture($this->db);
@@ -3837,18 +4064,19 @@  discard block
 block discarded – undo
3837 4064
 				if ($obj->paye == 0
3838 4065
 					&& $obj->fk_statut != 0    // Not a draft
3839 4066
 					&& $obj->fk_statut != 3	   // Not abandonned
3840
-					&& $obj->fk_statut != 2)   // Not classified as paid
4067
+					&& $obj->fk_statut != 2) {
4068
+				    // Not classified as paid
3841 4069
 				//$sql .= " AND (fk_statut <> 3 OR close_code <> 'abandon')";		// Not abandonned for undefined reason
3842 4070
 				{
3843 4071
 					$paiement = $tmpobject->getSommePaiement();
4072
+				}
3844 4073
 					$creditnotes = $tmpobject->getSumCreditNotesUsed();
3845 4074
 					$deposits = $tmpobject->getSumDepositsUsed();
3846 4075
 					$outstandingOpened+=$obj->total_ttc - $paiement - $creditnotes - $deposits;
3847 4076
 				}
3848 4077
 			}
3849 4078
 			return array('opened'=>$outstandingOpened, 'total_ht'=>$outstandingTotal, 'total_ttc'=>$outstandingTotalIncTax);	// 'opened' is 'incl taxes'
3850
-		}
3851
-		else
4079
+		} else
3852 4080
 		{
3853 4081
 			return array();
3854 4082
 		}
@@ -3895,9 +4123,9 @@  discard block
 block discarded – undo
3895 4123
 				$outstandingAmount+= $obj->total_ttc - $paiement - $creditnotes - $deposits;
3896 4124
 			}
3897 4125
 			return $outstandingAmount;
4126
+		} else {
4127
+					return 0;
3898 4128
 		}
3899
-		else
3900
-			return 0;
3901 4129
 	}
3902 4130
 
3903 4131
 	/**
@@ -3923,10 +4151,18 @@  discard block
 block discarded – undo
3923 4151
 		global $langs;
3924 4152
 		$langs->load('companies');
3925 4153
 
3926
-		if ($statut==0) return $langs->trans("NorProspectNorCustomer");
3927
-		if ($statut==1) return $langs->trans("Customer");
3928
-		if ($statut==2) return $langs->trans("Prospect");
3929
-		if ($statut==3) return $langs->trans("ProspectCustomer");
4154
+		if ($statut==0) {
4155
+		    return $langs->trans("NorProspectNorCustomer");
4156
+		}
4157
+		if ($statut==1) {
4158
+		    return $langs->trans("Customer");
4159
+		}
4160
+		if ($statut==2) {
4161
+		    return $langs->trans("Prospect");
4162
+		}
4163
+		if ($statut==3) {
4164
+		    return $langs->trans("ProspectCustomer");
4165
+		}
3930 4166
 	}
3931 4167
 
3932 4168
 
@@ -3952,10 +4188,11 @@  discard block
 block discarded – undo
3952 4188
 			include_once DOL_DOCUMENT_ROOT.'/societe/class/companybankaccount.class.php';
3953 4189
 			$companybankaccount = new CompanyBankAccount($this->db);
3954 4190
 			$result = $companybankaccount->fetch($moreparams['use_companybankid']);
3955
-			if (! $result) dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
4191
+			if (! $result) {
4192
+			    dol_print_error($this->db, $companybankaccount->error, $companybankaccount->errors);
4193
+			}
3956 4194
 			$result=$companybankaccount->commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
3957
-		}
3958
-		else
4195
+		} else
3959 4196
 		{
3960 4197
 			// Positionne le modele sur le nom du modele a utiliser
3961 4198
 			if (! dol_strlen($modele))
@@ -3963,8 +4200,7 @@  discard block
 block discarded – undo
3963 4200
 				if (! empty($conf->global->COMPANY_ADDON_PDF))
3964 4201
 				{
3965 4202
 					$modele = $conf->global->COMPANY_ADDON_PDF;
3966
-				}
3967
-				else
4203
+				} else
3968 4204
 				{
3969 4205
 					print $langs->trans("Error")." ".$langs->trans("Error_COMPANY_ADDON_PDF_NotDefined");
3970 4206
 					return 0;
Please login to merge, or discard this patch.