@@ -80,26 +80,26 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
@@ -81,38 +81,38 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 |
||
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.= "&sall=".urlencode($sall); |
|
266 | - if ($search_ref_exp) $param.= "&search_ref_exp=".urlencode($search_ref_exp); |
|
267 | - if ($search_ref_liv) $param.= "&search_ref_liv=".urlencode($search_ref_liv); |
|
268 | - if ($search_ref_customer) $param.= "&search_ref_customer=".urlencode($search_ref_customer); |
|
269 | - if ($search_company) $param.= "&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.='&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"> </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"> </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.= "&sall=".urlencode($sall); |
|
266 | + if ($search_ref_exp) $param.= "&search_ref_exp=".urlencode($search_ref_exp); |
|
267 | + if ($search_ref_liv) $param.= "&search_ref_liv=".urlencode($search_ref_liv); |
|
268 | + if ($search_ref_customer) $param.= "&search_ref_customer=".urlencode($search_ref_customer); |
|
269 | + if ($search_company) $param.= "&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.='&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"> </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"> </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 |
@@ -61,8 +61,8 @@ |
||
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 |
@@ -205,9 +205,9 @@ discard block |
||
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 |
||
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 |
||
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.'&mode='.$mode.'">'.$oldyear.'</a></td>'; |
|
281 | + print '<tr class="oddeven" height="24">'; |
|
282 | + print '<td align="center"><a href="'.$_SERVER["PHP_SELF"].'?year='.$oldyear.'&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.'&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.'&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>'; |
@@ -32,279 +32,279 @@ discard block |
||
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 |
||
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 |
||
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 |
||
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 | } |
@@ -31,476 +31,476 @@ discard block |
||
31 | 31 | */ |
32 | 32 | class Address |
33 | 33 | { |
34 | - protected $db; |
|
34 | + protected $db; |
|
35 | 35 | |
36 | - /** |
|
37 | - * @var int ID |
|
38 | - */ |
|
39 | - public $id; |
|
36 | + /** |
|
37 | + * @var int ID |
|
38 | + */ |
|
39 | + public $id; |
|
40 | 40 | |
41 | - public $type; |
|
41 | + public $type; |
|
42 | 42 | |
43 | - /** |
|
43 | + /** |
|
44 | 44 | * @var string Address label |
45 | 45 | */ |
46 | 46 | public $label; |
47 | 47 | |
48 | - public $socid; |
|
49 | - public $name; |
|
50 | - |
|
51 | - /** |
|
52 | - * @var string Address |
|
53 | - */ |
|
54 | - public $address; |
|
55 | - |
|
56 | - public $zip; |
|
57 | - public $town; |
|
58 | - public $country_id; |
|
59 | - public $country_code; |
|
60 | - public $phone; |
|
61 | - public $fax; |
|
62 | - public $note; |
|
63 | - |
|
64 | - /** |
|
65 | - * Adresses liees a la societe |
|
66 | - * @var array |
|
67 | - */ |
|
68 | - public $lines; |
|
69 | - |
|
70 | - /** |
|
71 | - * Constructor |
|
72 | - * |
|
73 | - * @param DoliDB $db Database handler |
|
74 | - * @deprecated |
|
75 | - */ |
|
76 | - function __construct($db) |
|
77 | - { |
|
78 | - $this->db = $db; |
|
79 | - } |
|
80 | - |
|
81 | - /** |
|
82 | - * Create address into database |
|
83 | - * |
|
84 | - * @param int $socid Company socid |
|
85 | - * @param User $user Object user making creation |
|
86 | - * @return int 0 if OK, < 0 if KO |
|
87 | - */ |
|
88 | - function create($socid, $user='') |
|
89 | - { |
|
90 | - global $langs,$conf; |
|
91 | - |
|
92 | - // Nettoyage parametres |
|
93 | - $this->name = trim($this->name); |
|
94 | - $this->label = trim($this->label); |
|
95 | - |
|
96 | - dol_syslog(get_class($this)."::create label=".$this->label); |
|
97 | - |
|
98 | - $this->db->begin(); |
|
99 | - |
|
100 | - $result = $this->verify(); |
|
101 | - |
|
102 | - if ($result >= 0) |
|
103 | - { |
|
104 | - $now=dol_now(); |
|
105 | - |
|
106 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_address (label, fk_soc, name, datec, fk_user_creat) "; |
|
107 | - $sql .= " VALUES ('".$this->db->escape($this->label)."', '".$socid."', '".$this->db->escape($this->name)."', '".$this->db->idate($now)."', '".$user->id."')"; |
|
108 | - |
|
109 | - $result=$this->db->query($sql); |
|
110 | - if ($result) |
|
111 | - { |
|
112 | - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_address"); |
|
113 | - |
|
114 | - $ret = $this->update($this->id, $socid, $user); |
|
115 | - |
|
116 | - if ($ret >= 0) |
|
117 | - { |
|
118 | - dol_syslog(get_class($this)."::create success id=".$this->id); |
|
119 | - $this->db->commit(); |
|
120 | - return 0; |
|
121 | - } |
|
122 | - else |
|
123 | - { |
|
124 | - dol_syslog(get_class($this)."::create echec update"); |
|
125 | - $this->db->rollback(); |
|
126 | - return -3; |
|
127 | - } |
|
128 | - } |
|
129 | - else |
|
130 | - |
|
131 | - { |
|
132 | - if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
|
133 | - { |
|
134 | - |
|
135 | - $this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->name); |
|
136 | - } |
|
137 | - |
|
138 | - $this->db->rollback(); |
|
139 | - return -2; |
|
140 | - } |
|
141 | - } |
|
142 | - else |
|
143 | - { |
|
144 | - $this->db->rollback(); |
|
145 | - dol_syslog(get_class($this)."::create echec verify sql=$sql"); |
|
146 | - return -1; |
|
147 | - } |
|
148 | - } |
|
149 | - |
|
150 | - |
|
151 | - /** |
|
152 | - * Verification lors de la modification de l'adresse |
|
153 | - * |
|
154 | - * @return int 0 if OK, <0 if KO |
|
155 | - */ |
|
156 | - function verify() |
|
157 | - { |
|
158 | - $this->label = trim($this->label); |
|
159 | - $this->name = trim($this->name); |
|
160 | - $result = 0; |
|
161 | - if (!$this->name || !$this->label) |
|
162 | - { |
|
163 | - $this->error = "The name of company and the label can not be empty.\n"; |
|
164 | - $result = -2; |
|
165 | - } |
|
166 | - return $result; |
|
167 | - } |
|
168 | - |
|
169 | - |
|
170 | - /** |
|
171 | - * Mise a jour des parametres de l'adresse |
|
172 | - * |
|
173 | - * @param int $id id address |
|
174 | - * @param int $socid id third party |
|
175 | - * @param User $user Utilisateur qui demande la mise a jour |
|
176 | - * @return int <0 if KO, >=0 if OK |
|
177 | - */ |
|
178 | - function update($id, $socid, $user='') |
|
179 | - { |
|
180 | - global $langs; |
|
181 | - |
|
182 | - // Clean parameters |
|
183 | - $this->fk_soc = $socid; |
|
184 | - $this->label = trim($this->label); |
|
185 | - $this->name = trim($this->name); |
|
186 | - $this->address = trim($this->address); |
|
187 | - $this->zip = trim($this->zip); |
|
188 | - $this->town = trim($this->town); |
|
189 | - $this->country_id = trim($this->country_id); |
|
190 | - $this->phone = trim($this->phone); |
|
191 | - $this->phone = preg_replace("/\s/","",$this->phone); |
|
192 | - $this->phone = preg_replace("/\./","",$this->phone); |
|
193 | - $this->fax = trim($this->fax); |
|
194 | - $this->fax = preg_replace("/\s/","",$this->fax); |
|
195 | - $this->fax = preg_replace("/\./","",$this->fax); |
|
196 | - $this->note = trim($this->note); |
|
197 | - |
|
198 | - $result = $this->verify(); // Verifie que name et label obligatoire |
|
199 | - |
|
200 | - if ($result >= 0) |
|
201 | - { |
|
202 | - dol_syslog(get_class($this)."::Update verify ok"); |
|
203 | - |
|
204 | - $this->db->begin(); |
|
205 | - |
|
206 | - $sql = "UPDATE ".MAIN_DB_PREFIX."societe_address"; |
|
207 | - $sql.= " SET label = '" . $this->db->escape($this->label) ."'"; // Champ obligatoire |
|
208 | - $sql.= ", name = '" . $this->db->escape($this->name) ."'"; // Champ obligatoire |
|
209 | - $sql.= ", address = ".($this->address?"'".$this->db->escape($this->address)."'":"null"); |
|
210 | - $sql.= ", zip = ".($this->zip?"'".$this->db->escape($this->zip)."'":"null"); |
|
211 | - $sql.= ", town = ".($this->town?"'".$this->db->escape($this->town)."'":"null"); |
|
212 | - $sql.= ", fk_pays = '" . ($this->country_id?$this->db->escape($this->country_id):'0') ."'"; |
|
213 | - $sql.= ", note = ".($this->note?"'".$this->db->escape($this->note)."'":"null"); |
|
214 | - $sql.= ", phone = ".($this->phone?"'".$this->db->escape($this->phone)."'":"null"); |
|
215 | - $sql.= ", fax = ".($this->fax?"'".$this->db->escape($this->fax)."'":"null"); |
|
216 | - if ($user) $sql .= ",fk_user_modif = '".$user->id."'"; |
|
217 | - $sql .= " WHERE fk_soc = '" . $socid ."' AND rowid = '" . $this->db->escape($id) ."'"; |
|
218 | - |
|
219 | - dol_syslog(get_class($this)."::Update", LOG_DEBUG); |
|
220 | - $resql=$this->db->query($sql); |
|
221 | - if ($resql) |
|
222 | - { |
|
223 | - dol_syslog(get_class($this)."::Update success"); |
|
224 | - $this->db->commit(); |
|
225 | - return 1; |
|
226 | - } |
|
227 | - else |
|
228 | - { |
|
229 | - if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
|
230 | - { |
|
231 | - |
|
232 | - $this->error=$langs->trans("ErrorDuplicateField",$this->name); |
|
233 | - $result=-1; |
|
234 | - } |
|
235 | - else |
|
236 | - { |
|
237 | - $this->error=$this->db->lasterror(); |
|
238 | - $result=-2; |
|
239 | - } |
|
240 | - $this->db->rollback(); |
|
241 | - return $result; |
|
242 | - } |
|
243 | - } |
|
244 | - } |
|
48 | + public $socid; |
|
49 | + public $name; |
|
50 | + |
|
51 | + /** |
|
52 | + * @var string Address |
|
53 | + */ |
|
54 | + public $address; |
|
55 | + |
|
56 | + public $zip; |
|
57 | + public $town; |
|
58 | + public $country_id; |
|
59 | + public $country_code; |
|
60 | + public $phone; |
|
61 | + public $fax; |
|
62 | + public $note; |
|
63 | + |
|
64 | + /** |
|
65 | + * Adresses liees a la societe |
|
66 | + * @var array |
|
67 | + */ |
|
68 | + public $lines; |
|
69 | + |
|
70 | + /** |
|
71 | + * Constructor |
|
72 | + * |
|
73 | + * @param DoliDB $db Database handler |
|
74 | + * @deprecated |
|
75 | + */ |
|
76 | + function __construct($db) |
|
77 | + { |
|
78 | + $this->db = $db; |
|
79 | + } |
|
80 | + |
|
81 | + /** |
|
82 | + * Create address into database |
|
83 | + * |
|
84 | + * @param int $socid Company socid |
|
85 | + * @param User $user Object user making creation |
|
86 | + * @return int 0 if OK, < 0 if KO |
|
87 | + */ |
|
88 | + function create($socid, $user='') |
|
89 | + { |
|
90 | + global $langs,$conf; |
|
91 | + |
|
92 | + // Nettoyage parametres |
|
93 | + $this->name = trim($this->name); |
|
94 | + $this->label = trim($this->label); |
|
95 | + |
|
96 | + dol_syslog(get_class($this)."::create label=".$this->label); |
|
97 | + |
|
98 | + $this->db->begin(); |
|
99 | + |
|
100 | + $result = $this->verify(); |
|
101 | + |
|
102 | + if ($result >= 0) |
|
103 | + { |
|
104 | + $now=dol_now(); |
|
105 | + |
|
106 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_address (label, fk_soc, name, datec, fk_user_creat) "; |
|
107 | + $sql .= " VALUES ('".$this->db->escape($this->label)."', '".$socid."', '".$this->db->escape($this->name)."', '".$this->db->idate($now)."', '".$user->id."')"; |
|
108 | + |
|
109 | + $result=$this->db->query($sql); |
|
110 | + if ($result) |
|
111 | + { |
|
112 | + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_address"); |
|
113 | + |
|
114 | + $ret = $this->update($this->id, $socid, $user); |
|
115 | + |
|
116 | + if ($ret >= 0) |
|
117 | + { |
|
118 | + dol_syslog(get_class($this)."::create success id=".$this->id); |
|
119 | + $this->db->commit(); |
|
120 | + return 0; |
|
121 | + } |
|
122 | + else |
|
123 | + { |
|
124 | + dol_syslog(get_class($this)."::create echec update"); |
|
125 | + $this->db->rollback(); |
|
126 | + return -3; |
|
127 | + } |
|
128 | + } |
|
129 | + else |
|
130 | + |
|
131 | + { |
|
132 | + if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
|
133 | + { |
|
134 | + |
|
135 | + $this->error=$langs->trans("ErrorCompanyNameAlreadyExists",$this->name); |
|
136 | + } |
|
137 | + |
|
138 | + $this->db->rollback(); |
|
139 | + return -2; |
|
140 | + } |
|
141 | + } |
|
142 | + else |
|
143 | + { |
|
144 | + $this->db->rollback(); |
|
145 | + dol_syslog(get_class($this)."::create echec verify sql=$sql"); |
|
146 | + return -1; |
|
147 | + } |
|
148 | + } |
|
149 | + |
|
150 | + |
|
151 | + /** |
|
152 | + * Verification lors de la modification de l'adresse |
|
153 | + * |
|
154 | + * @return int 0 if OK, <0 if KO |
|
155 | + */ |
|
156 | + function verify() |
|
157 | + { |
|
158 | + $this->label = trim($this->label); |
|
159 | + $this->name = trim($this->name); |
|
160 | + $result = 0; |
|
161 | + if (!$this->name || !$this->label) |
|
162 | + { |
|
163 | + $this->error = "The name of company and the label can not be empty.\n"; |
|
164 | + $result = -2; |
|
165 | + } |
|
166 | + return $result; |
|
167 | + } |
|
168 | + |
|
169 | + |
|
170 | + /** |
|
171 | + * Mise a jour des parametres de l'adresse |
|
172 | + * |
|
173 | + * @param int $id id address |
|
174 | + * @param int $socid id third party |
|
175 | + * @param User $user Utilisateur qui demande la mise a jour |
|
176 | + * @return int <0 if KO, >=0 if OK |
|
177 | + */ |
|
178 | + function update($id, $socid, $user='') |
|
179 | + { |
|
180 | + global $langs; |
|
181 | + |
|
182 | + // Clean parameters |
|
183 | + $this->fk_soc = $socid; |
|
184 | + $this->label = trim($this->label); |
|
185 | + $this->name = trim($this->name); |
|
186 | + $this->address = trim($this->address); |
|
187 | + $this->zip = trim($this->zip); |
|
188 | + $this->town = trim($this->town); |
|
189 | + $this->country_id = trim($this->country_id); |
|
190 | + $this->phone = trim($this->phone); |
|
191 | + $this->phone = preg_replace("/\s/","",$this->phone); |
|
192 | + $this->phone = preg_replace("/\./","",$this->phone); |
|
193 | + $this->fax = trim($this->fax); |
|
194 | + $this->fax = preg_replace("/\s/","",$this->fax); |
|
195 | + $this->fax = preg_replace("/\./","",$this->fax); |
|
196 | + $this->note = trim($this->note); |
|
197 | + |
|
198 | + $result = $this->verify(); // Verifie que name et label obligatoire |
|
199 | + |
|
200 | + if ($result >= 0) |
|
201 | + { |
|
202 | + dol_syslog(get_class($this)."::Update verify ok"); |
|
203 | + |
|
204 | + $this->db->begin(); |
|
205 | + |
|
206 | + $sql = "UPDATE ".MAIN_DB_PREFIX."societe_address"; |
|
207 | + $sql.= " SET label = '" . $this->db->escape($this->label) ."'"; // Champ obligatoire |
|
208 | + $sql.= ", name = '" . $this->db->escape($this->name) ."'"; // Champ obligatoire |
|
209 | + $sql.= ", address = ".($this->address?"'".$this->db->escape($this->address)."'":"null"); |
|
210 | + $sql.= ", zip = ".($this->zip?"'".$this->db->escape($this->zip)."'":"null"); |
|
211 | + $sql.= ", town = ".($this->town?"'".$this->db->escape($this->town)."'":"null"); |
|
212 | + $sql.= ", fk_pays = '" . ($this->country_id?$this->db->escape($this->country_id):'0') ."'"; |
|
213 | + $sql.= ", note = ".($this->note?"'".$this->db->escape($this->note)."'":"null"); |
|
214 | + $sql.= ", phone = ".($this->phone?"'".$this->db->escape($this->phone)."'":"null"); |
|
215 | + $sql.= ", fax = ".($this->fax?"'".$this->db->escape($this->fax)."'":"null"); |
|
216 | + if ($user) $sql .= ",fk_user_modif = '".$user->id."'"; |
|
217 | + $sql .= " WHERE fk_soc = '" . $socid ."' AND rowid = '" . $this->db->escape($id) ."'"; |
|
218 | + |
|
219 | + dol_syslog(get_class($this)."::Update", LOG_DEBUG); |
|
220 | + $resql=$this->db->query($sql); |
|
221 | + if ($resql) |
|
222 | + { |
|
223 | + dol_syslog(get_class($this)."::Update success"); |
|
224 | + $this->db->commit(); |
|
225 | + return 1; |
|
226 | + } |
|
227 | + else |
|
228 | + { |
|
229 | + if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') |
|
230 | + { |
|
231 | + |
|
232 | + $this->error=$langs->trans("ErrorDuplicateField",$this->name); |
|
233 | + $result=-1; |
|
234 | + } |
|
235 | + else |
|
236 | + { |
|
237 | + $this->error=$this->db->lasterror(); |
|
238 | + $result=-2; |
|
239 | + } |
|
240 | + $this->db->rollback(); |
|
241 | + return $result; |
|
242 | + } |
|
243 | + } |
|
244 | + } |
|
245 | 245 | |
246 | 246 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
247 | - /** |
|
248 | - * Charge depuis la base toutes les adresses d'une societe |
|
249 | - * |
|
250 | - * @param int $socid Id de la societe a charger en memoire |
|
251 | - * @param User $user Objet de l'utilisateur |
|
252 | - * @return int >0 si ok, <0 si ko |
|
253 | - */ |
|
254 | - function fetch_lines($socid, $user=null) |
|
255 | - { |
|
247 | + /** |
|
248 | + * Charge depuis la base toutes les adresses d'une societe |
|
249 | + * |
|
250 | + * @param int $socid Id de la societe a charger en memoire |
|
251 | + * @param User $user Objet de l'utilisateur |
|
252 | + * @return int >0 si ok, <0 si ko |
|
253 | + */ |
|
254 | + function fetch_lines($socid, $user=null) |
|
255 | + { |
|
256 | 256 | // phpcs:enable |
257 | - global $langs, $conf; |
|
257 | + global $langs, $conf; |
|
258 | 258 | |
259 | - $sql = 'SELECT rowid, nom as name, client, fournisseur'; |
|
260 | - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe'; |
|
261 | - $sql .= ' WHERE rowid = '.$socid; |
|
259 | + $sql = 'SELECT rowid, nom as name, client, fournisseur'; |
|
260 | + $sql .= ' FROM '.MAIN_DB_PREFIX.'societe'; |
|
261 | + $sql .= ' WHERE rowid = '.$socid; |
|
262 | 262 | |
263 | - $resqlsoc=$this->db->query($sql); |
|
264 | - if ($resqlsoc) |
|
265 | - { |
|
266 | - if ($this->db->num_rows($resqlsoc)) |
|
267 | - { |
|
268 | - $obj = $this->db->fetch_object($resqlsoc); |
|
263 | + $resqlsoc=$this->db->query($sql); |
|
264 | + if ($resqlsoc) |
|
265 | + { |
|
266 | + if ($this->db->num_rows($resqlsoc)) |
|
267 | + { |
|
268 | + $obj = $this->db->fetch_object($resqlsoc); |
|
269 | 269 | |
270 | - $this->socname = $obj->name; |
|
271 | - $this->socid = $obj->rowid; |
|
272 | - $this->id = $obj->rowid; |
|
273 | - $this->client = $obj->client; |
|
274 | - $this->fournisseur = $obj->fournisseur; |
|
275 | - } |
|
270 | + $this->socname = $obj->name; |
|
271 | + $this->socid = $obj->rowid; |
|
272 | + $this->id = $obj->rowid; |
|
273 | + $this->client = $obj->client; |
|
274 | + $this->fournisseur = $obj->fournisseur; |
|
275 | + } |
|
276 | 276 | |
277 | - $this->db->free($resqlsoc); |
|
277 | + $this->db->free($resqlsoc); |
|
278 | 278 | |
279 | 279 | $this->lines = array(); |
280 | 280 | |
281 | 281 | // Adresses liees a la societe |
282 | - if ($this->socid) |
|
283 | - { |
|
284 | - $sql = 'SELECT a.rowid as id, a.label, a.name, a.address, a.datec as date_creation, a.tms as date_modification, a.fk_soc'; |
|
285 | - $sql .= ', a.zip, a.town, a.note, a.fk_pays as country_id, a.phone, a.fax'; |
|
286 | - $sql .= ', c.code as country_code, c.label as country'; |
|
287 | - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_address as a'; |
|
288 | - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON a.fk_pays = c.rowid'; |
|
289 | - $sql .= ' WHERE a.fk_soc = '.$this->socid; |
|
290 | - |
|
291 | - $resql=$this->db->query($sql); |
|
292 | - if ($resql) |
|
293 | - { |
|
294 | - $num = $this->db->num_rows($resql); |
|
295 | - $i = 0; |
|
296 | - while ($i < $num) |
|
297 | - { |
|
298 | - $objp = $this->db->fetch_object($resql); |
|
299 | - |
|
300 | - $line = new AddressLine($this->db); |
|
301 | - |
|
302 | - $line->id = $objp->id; |
|
303 | - $line->date_creation = $this->db->jdate($objp->date_creation); |
|
304 | - $line->date_modification = $this->db->jdate($objp->date_modification); |
|
305 | - $line->label = $objp->label; |
|
306 | - $line->name = $objp->name; |
|
307 | - $line->address = $objp->address; |
|
308 | - $line->zip = $objp->zip; |
|
309 | - $line->town = $objp->town; |
|
310 | - $line->country_id = $objp->country_id; |
|
311 | - $line->country_code = $objp->country_id?$objp->country_code:''; |
|
312 | - $line->country = $objp->country_id?($langs->trans('Country'.$objp->country_code)!='Country'.$objp->country_code?$langs->trans('Country'.$objp->country_code):$objp->country):''; |
|
313 | - $line->phone = $objp->phone; |
|
314 | - $line->fax = $objp->fax; |
|
315 | - $line->note = $objp->note; |
|
316 | - |
|
317 | - $this->lines[$i] = $line; |
|
318 | - $i++; |
|
319 | - } |
|
320 | - $this->db->free($resql); |
|
321 | - return $num; |
|
322 | - } |
|
323 | - else |
|
324 | - { |
|
325 | - dol_syslog(get_class($this).'::Fetch Erreur: aucune adresse', LOG_ERR); |
|
326 | - return 0; |
|
327 | - } |
|
328 | - } |
|
329 | - else |
|
330 | - { |
|
331 | - dol_syslog(get_class($this).'::Fetch Erreur: societe inconnue', LOG_ERR); |
|
332 | - return -1; |
|
333 | - } |
|
334 | - } |
|
335 | - else |
|
336 | - { |
|
337 | - $this->error=$this->db->error(); |
|
338 | - } |
|
339 | - } |
|
282 | + if ($this->socid) |
|
283 | + { |
|
284 | + $sql = 'SELECT a.rowid as id, a.label, a.name, a.address, a.datec as date_creation, a.tms as date_modification, a.fk_soc'; |
|
285 | + $sql .= ', a.zip, a.town, a.note, a.fk_pays as country_id, a.phone, a.fax'; |
|
286 | + $sql .= ', c.code as country_code, c.label as country'; |
|
287 | + $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_address as a'; |
|
288 | + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON a.fk_pays = c.rowid'; |
|
289 | + $sql .= ' WHERE a.fk_soc = '.$this->socid; |
|
290 | + |
|
291 | + $resql=$this->db->query($sql); |
|
292 | + if ($resql) |
|
293 | + { |
|
294 | + $num = $this->db->num_rows($resql); |
|
295 | + $i = 0; |
|
296 | + while ($i < $num) |
|
297 | + { |
|
298 | + $objp = $this->db->fetch_object($resql); |
|
299 | + |
|
300 | + $line = new AddressLine($this->db); |
|
301 | + |
|
302 | + $line->id = $objp->id; |
|
303 | + $line->date_creation = $this->db->jdate($objp->date_creation); |
|
304 | + $line->date_modification = $this->db->jdate($objp->date_modification); |
|
305 | + $line->label = $objp->label; |
|
306 | + $line->name = $objp->name; |
|
307 | + $line->address = $objp->address; |
|
308 | + $line->zip = $objp->zip; |
|
309 | + $line->town = $objp->town; |
|
310 | + $line->country_id = $objp->country_id; |
|
311 | + $line->country_code = $objp->country_id?$objp->country_code:''; |
|
312 | + $line->country = $objp->country_id?($langs->trans('Country'.$objp->country_code)!='Country'.$objp->country_code?$langs->trans('Country'.$objp->country_code):$objp->country):''; |
|
313 | + $line->phone = $objp->phone; |
|
314 | + $line->fax = $objp->fax; |
|
315 | + $line->note = $objp->note; |
|
316 | + |
|
317 | + $this->lines[$i] = $line; |
|
318 | + $i++; |
|
319 | + } |
|
320 | + $this->db->free($resql); |
|
321 | + return $num; |
|
322 | + } |
|
323 | + else |
|
324 | + { |
|
325 | + dol_syslog(get_class($this).'::Fetch Erreur: aucune adresse', LOG_ERR); |
|
326 | + return 0; |
|
327 | + } |
|
328 | + } |
|
329 | + else |
|
330 | + { |
|
331 | + dol_syslog(get_class($this).'::Fetch Erreur: societe inconnue', LOG_ERR); |
|
332 | + return -1; |
|
333 | + } |
|
334 | + } |
|
335 | + else |
|
336 | + { |
|
337 | + $this->error=$this->db->error(); |
|
338 | + } |
|
339 | + } |
|
340 | 340 | |
341 | 341 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
342 | - /** |
|
343 | - * Charge depuis la base l'objet adresse |
|
344 | - * |
|
345 | - * @param int $id Id de l'adresse a charger en memoire |
|
346 | - * @param User $user Objet de l'utilisateur |
|
347 | - * @return int >0 si ok, <0 si ko |
|
348 | - */ |
|
349 | - function fetch_address($id, $user=null) |
|
350 | - { |
|
342 | + /** |
|
343 | + * Charge depuis la base l'objet adresse |
|
344 | + * |
|
345 | + * @param int $id Id de l'adresse a charger en memoire |
|
346 | + * @param User $user Objet de l'utilisateur |
|
347 | + * @return int >0 si ok, <0 si ko |
|
348 | + */ |
|
349 | + function fetch_address($id, $user=null) |
|
350 | + { |
|
351 | 351 | // phpcs:enable |
352 | - global $langs; |
|
353 | - global $conf; |
|
354 | - |
|
355 | - $sql = 'SELECT a.rowid, a.fk_soc, a.label, a.name, a.address, a.datec as date_creation, a.tms as date_modification'; |
|
356 | - $sql .= ', a.zip, a.town, a.note, a.fk_pays as country_id, a.phone, a.fax'; |
|
357 | - $sql .= ', c.code as country_code, c.label as country'; |
|
358 | - $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_address as a'; |
|
359 | - $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON a.fk_pays = c.rowid'; |
|
360 | - $sql .= ' WHERE a.rowid = '.$id; |
|
361 | - $resql=$this->db->query($sql); |
|
362 | - if ($resql) |
|
363 | - { |
|
364 | - if ($this->db->num_rows($resql)) |
|
365 | - { |
|
366 | - $obj = $this->db->fetch_object($resql); |
|
367 | - |
|
368 | - $this->id = $obj->rowid; |
|
369 | - $this->socid = $obj->fk_soc; |
|
370 | - |
|
371 | - $this->date_modification = $this->db->jdate($obj->date_modification); |
|
372 | - $this->date_creation = $this->db->jdate($obj->date_creation); |
|
373 | - |
|
374 | - $this->label = $obj->label; |
|
375 | - $this->name = $obj->name; |
|
376 | - $this->address = $obj->address; |
|
377 | - $this->zip = $obj->zip; |
|
378 | - $this->town = $obj->town; |
|
379 | - |
|
380 | - $this->country_id = $obj->country_id; |
|
381 | - $this->country_code = $obj->country_id?$obj->country_code:''; |
|
382 | - $this->country = $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->trans('Country'.$obj->country_code):$obj->country):''; |
|
383 | - |
|
384 | - $this->phone = $obj->phone; |
|
385 | - $this->fax = $obj->fax; |
|
386 | - $this->note = $obj->note; |
|
387 | - |
|
388 | - $result = 1; |
|
389 | - } |
|
390 | - else |
|
391 | - { |
|
392 | - dol_syslog('Erreur Societe::Fetch aucune adresse avec id='.$this->id.' - '.$sql); |
|
393 | - $this->error='Erreur Societe::Fetch aucune adresse avec id='.$this->id.' - '.$sql; |
|
394 | - $result = -2; |
|
395 | - } |
|
396 | - |
|
397 | - $this->db->free($resql); |
|
398 | - } |
|
399 | - else |
|
400 | - { |
|
401 | - dol_syslog('Erreur Societe::Fetch echec', LOG_DEBUG); |
|
402 | - dol_syslog('Erreur Societe::Fetch '.$this->db->error()); |
|
403 | - $this->error=$this->db->error(); |
|
404 | - $result = -3; |
|
405 | - } |
|
406 | - |
|
407 | - return $result; |
|
408 | - } |
|
409 | - |
|
410 | - |
|
411 | - /** |
|
412 | - * Suppression d'une adresse |
|
413 | - * |
|
414 | - * @param int $id id de la societe a supprimer |
|
415 | - * @param int $socid id third party |
|
416 | - * @return <0 KO >0 OK |
|
417 | - */ |
|
418 | - function delete($id,$socid) |
|
419 | - { |
|
420 | - dol_syslog("Address::Delete"); |
|
421 | - |
|
422 | - $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_address"; |
|
423 | - $sql.= " WHERE rowid = ".$id; |
|
424 | - $sql.= " AND fk_soc = ".$socid; |
|
425 | - |
|
426 | - $result = $this->db->query($sql); |
|
427 | - |
|
428 | - if (!$result) { |
|
429 | - return -1; |
|
430 | - } |
|
431 | - |
|
432 | - return 1; |
|
433 | - } |
|
434 | - |
|
435 | - /** |
|
436 | - * Return name of address with link (and eventually picto) |
|
437 | - * Use $this->id, $this->label, $this->socid |
|
438 | - * |
|
439 | - * @param int $withpicto Include picto with link |
|
440 | - * @param string $option Where the link point to |
|
441 | - * @return string String with URL |
|
442 | - */ |
|
443 | - function getNomUrl($withpicto=0,$option='') |
|
444 | - { |
|
445 | - global $langs; |
|
446 | - |
|
447 | - $result=''; |
|
352 | + global $langs; |
|
353 | + global $conf; |
|
354 | + |
|
355 | + $sql = 'SELECT a.rowid, a.fk_soc, a.label, a.name, a.address, a.datec as date_creation, a.tms as date_modification'; |
|
356 | + $sql .= ', a.zip, a.town, a.note, a.fk_pays as country_id, a.phone, a.fax'; |
|
357 | + $sql .= ', c.code as country_code, c.label as country'; |
|
358 | + $sql .= ' FROM '.MAIN_DB_PREFIX.'societe_address as a'; |
|
359 | + $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'c_country as c ON a.fk_pays = c.rowid'; |
|
360 | + $sql .= ' WHERE a.rowid = '.$id; |
|
361 | + $resql=$this->db->query($sql); |
|
362 | + if ($resql) |
|
363 | + { |
|
364 | + if ($this->db->num_rows($resql)) |
|
365 | + { |
|
366 | + $obj = $this->db->fetch_object($resql); |
|
367 | + |
|
368 | + $this->id = $obj->rowid; |
|
369 | + $this->socid = $obj->fk_soc; |
|
370 | + |
|
371 | + $this->date_modification = $this->db->jdate($obj->date_modification); |
|
372 | + $this->date_creation = $this->db->jdate($obj->date_creation); |
|
373 | + |
|
374 | + $this->label = $obj->label; |
|
375 | + $this->name = $obj->name; |
|
376 | + $this->address = $obj->address; |
|
377 | + $this->zip = $obj->zip; |
|
378 | + $this->town = $obj->town; |
|
379 | + |
|
380 | + $this->country_id = $obj->country_id; |
|
381 | + $this->country_code = $obj->country_id?$obj->country_code:''; |
|
382 | + $this->country = $obj->country_id?($langs->trans('Country'.$obj->country_code)!='Country'.$obj->country_code?$langs->trans('Country'.$obj->country_code):$obj->country):''; |
|
383 | + |
|
384 | + $this->phone = $obj->phone; |
|
385 | + $this->fax = $obj->fax; |
|
386 | + $this->note = $obj->note; |
|
387 | + |
|
388 | + $result = 1; |
|
389 | + } |
|
390 | + else |
|
391 | + { |
|
392 | + dol_syslog('Erreur Societe::Fetch aucune adresse avec id='.$this->id.' - '.$sql); |
|
393 | + $this->error='Erreur Societe::Fetch aucune adresse avec id='.$this->id.' - '.$sql; |
|
394 | + $result = -2; |
|
395 | + } |
|
396 | + |
|
397 | + $this->db->free($resql); |
|
398 | + } |
|
399 | + else |
|
400 | + { |
|
401 | + dol_syslog('Erreur Societe::Fetch echec', LOG_DEBUG); |
|
402 | + dol_syslog('Erreur Societe::Fetch '.$this->db->error()); |
|
403 | + $this->error=$this->db->error(); |
|
404 | + $result = -3; |
|
405 | + } |
|
406 | + |
|
407 | + return $result; |
|
408 | + } |
|
409 | + |
|
410 | + |
|
411 | + /** |
|
412 | + * Suppression d'une adresse |
|
413 | + * |
|
414 | + * @param int $id id de la societe a supprimer |
|
415 | + * @param int $socid id third party |
|
416 | + * @return <0 KO >0 OK |
|
417 | + */ |
|
418 | + function delete($id,$socid) |
|
419 | + { |
|
420 | + dol_syslog("Address::Delete"); |
|
421 | + |
|
422 | + $sql = "DELETE FROM ".MAIN_DB_PREFIX."societe_address"; |
|
423 | + $sql.= " WHERE rowid = ".$id; |
|
424 | + $sql.= " AND fk_soc = ".$socid; |
|
425 | + |
|
426 | + $result = $this->db->query($sql); |
|
427 | + |
|
428 | + if (!$result) { |
|
429 | + return -1; |
|
430 | + } |
|
431 | + |
|
432 | + return 1; |
|
433 | + } |
|
434 | + |
|
435 | + /** |
|
436 | + * Return name of address with link (and eventually picto) |
|
437 | + * Use $this->id, $this->label, $this->socid |
|
438 | + * |
|
439 | + * @param int $withpicto Include picto with link |
|
440 | + * @param string $option Where the link point to |
|
441 | + * @return string String with URL |
|
442 | + */ |
|
443 | + function getNomUrl($withpicto=0,$option='') |
|
444 | + { |
|
445 | + global $langs; |
|
446 | + |
|
447 | + $result=''; |
|
448 | 448 | $label = $langs->trans("ShowAddress").': '.$this->label; |
449 | 449 | |
450 | 450 | $link = '<a href="'.DOL_URL_ROOT.'/comm/address.php?id='.$this->id.'&socid='.$this->socid.'" title="'.dol_escape_htmltag($label, 1).'" class="classfortooltip">'; |
451 | - $linkend='</a>'; |
|
451 | + $linkend='</a>'; |
|
452 | 452 | |
453 | 453 | if ($withpicto) $result.=($link.img_object($langs->trans("ShowAddress").': '.$this->label, 'address', 'class="classfortooltip"').$linkend.' '); |
454 | - $result.=$link.$this->label.$linkend; |
|
455 | - return $result; |
|
456 | - } |
|
457 | - |
|
458 | - |
|
459 | - /** |
|
460 | - * Charge les informations d'ordre info dans l'objet societe |
|
461 | - * |
|
462 | - * @param int $id id de la societe a charger |
|
463 | - * @return void |
|
464 | - */ |
|
465 | - function info($id) |
|
466 | - { |
|
467 | - $sql = "SELECT s.rowid, s.nom as name, datec as date_creation, tms as date_modification,"; |
|
468 | - $sql.= " fk_user_creat, fk_user_modif"; |
|
469 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
470 | - $sql.= " WHERE s.rowid = ".$id; |
|
471 | - |
|
472 | - $result=$this->db->query($sql); |
|
473 | - if ($result) |
|
474 | - { |
|
475 | - if ($this->db->num_rows($result)) |
|
476 | - { |
|
477 | - $obj = $this->db->fetch_object($result); |
|
478 | - |
|
479 | - $this->id = $obj->rowid; |
|
480 | - |
|
481 | - if ($obj->fk_user_creat) { |
|
482 | - $cuser = new User($this->db); |
|
483 | - $cuser->fetch($obj->fk_user_creat); |
|
484 | - $this->user_creation = $cuser; |
|
485 | - } |
|
486 | - |
|
487 | - if ($obj->fk_user_modif) { |
|
488 | - $muser = new User($this->db); |
|
489 | - $muser->fetch($obj->fk_user_modif); |
|
490 | - $this->user_modification = $muser; |
|
491 | - } |
|
492 | - $this->ref = $obj->name; |
|
493 | - $this->date_creation = $this->db->jdate($obj->date_creation); |
|
494 | - $this->date_modification = $this->db->jdate($obj->date_modification); |
|
495 | - } |
|
496 | - |
|
497 | - $this->db->free($result); |
|
498 | - } |
|
499 | - else |
|
500 | - { |
|
501 | - dol_print_error($this->db); |
|
502 | - } |
|
503 | - } |
|
454 | + $result.=$link.$this->label.$linkend; |
|
455 | + return $result; |
|
456 | + } |
|
457 | + |
|
458 | + |
|
459 | + /** |
|
460 | + * Charge les informations d'ordre info dans l'objet societe |
|
461 | + * |
|
462 | + * @param int $id id de la societe a charger |
|
463 | + * @return void |
|
464 | + */ |
|
465 | + function info($id) |
|
466 | + { |
|
467 | + $sql = "SELECT s.rowid, s.nom as name, datec as date_creation, tms as date_modification,"; |
|
468 | + $sql.= " fk_user_creat, fk_user_modif"; |
|
469 | + $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; |
|
470 | + $sql.= " WHERE s.rowid = ".$id; |
|
471 | + |
|
472 | + $result=$this->db->query($sql); |
|
473 | + if ($result) |
|
474 | + { |
|
475 | + if ($this->db->num_rows($result)) |
|
476 | + { |
|
477 | + $obj = $this->db->fetch_object($result); |
|
478 | + |
|
479 | + $this->id = $obj->rowid; |
|
480 | + |
|
481 | + if ($obj->fk_user_creat) { |
|
482 | + $cuser = new User($this->db); |
|
483 | + $cuser->fetch($obj->fk_user_creat); |
|
484 | + $this->user_creation = $cuser; |
|
485 | + } |
|
486 | + |
|
487 | + if ($obj->fk_user_modif) { |
|
488 | + $muser = new User($this->db); |
|
489 | + $muser->fetch($obj->fk_user_modif); |
|
490 | + $this->user_modification = $muser; |
|
491 | + } |
|
492 | + $this->ref = $obj->name; |
|
493 | + $this->date_creation = $this->db->jdate($obj->date_creation); |
|
494 | + $this->date_modification = $this->db->jdate($obj->date_modification); |
|
495 | + } |
|
496 | + |
|
497 | + $this->db->free($result); |
|
498 | + } |
|
499 | + else |
|
500 | + { |
|
501 | + dol_print_error($this->db); |
|
502 | + } |
|
503 | + } |
|
504 | 504 | } |
505 | 505 | |
506 | 506 | |
@@ -509,45 +509,45 @@ discard block |
||
509 | 509 | */ |
510 | 510 | class AddressLine |
511 | 511 | { |
512 | - protected $db; |
|
512 | + protected $db; |
|
513 | 513 | |
514 | - /** |
|
515 | - * @var int ID |
|
516 | - */ |
|
517 | - public $id; |
|
514 | + /** |
|
515 | + * @var int ID |
|
516 | + */ |
|
517 | + public $id; |
|
518 | 518 | |
519 | - public $date_creation; |
|
520 | - public $date_modification; |
|
519 | + public $date_creation; |
|
520 | + public $date_modification; |
|
521 | 521 | |
522 | - /** |
|
522 | + /** |
|
523 | 523 | * @var string stock movements label |
524 | 524 | */ |
525 | 525 | public $label; |
526 | 526 | |
527 | - public $name; |
|
528 | - |
|
529 | - /** |
|
530 | - * @var string Address |
|
531 | - */ |
|
532 | - public $address; |
|
533 | - |
|
534 | - public $zip; |
|
535 | - public $town; |
|
536 | - public $country_id; |
|
537 | - public $country_code; |
|
538 | - public $country; |
|
539 | - public $phone; |
|
540 | - public $fax; |
|
541 | - public $note; |
|
542 | - |
|
543 | - |
|
544 | - /** |
|
545 | - * Constructor |
|
546 | - * |
|
547 | - * @param DoliDB $db Database handler |
|
548 | - */ |
|
549 | - function __construct($db) |
|
550 | - { |
|
551 | - $this->db = $db; |
|
552 | - } |
|
527 | + public $name; |
|
528 | + |
|
529 | + /** |
|
530 | + * @var string Address |
|
531 | + */ |
|
532 | + public $address; |
|
533 | + |
|
534 | + public $zip; |
|
535 | + public $town; |
|
536 | + public $country_id; |
|
537 | + public $country_code; |
|
538 | + public $country; |
|
539 | + public $phone; |
|
540 | + public $fax; |
|
541 | + public $note; |
|
542 | + |
|
543 | + |
|
544 | + /** |
|
545 | + * Constructor |
|
546 | + * |
|
547 | + * @param DoliDB $db Database handler |
|
548 | + */ |
|
549 | + function __construct($db) |
|
550 | + { |
|
551 | + $this->db = $db; |
|
552 | + } |
|
553 | 553 | } |
@@ -33,386 +33,386 @@ |
||
33 | 33 | */ |
34 | 34 | class CompanyBankAccount extends Account |
35 | 35 | { |
36 | - var $socid; |
|
37 | - |
|
38 | - var $default_rib; |
|
39 | - var $frstrecur; |
|
40 | - var $rum; |
|
41 | - var $date_rum; |
|
42 | - |
|
43 | - var $datec; |
|
44 | - var $datem; |
|
45 | - |
|
46 | - |
|
47 | - /** |
|
48 | - * Constructor |
|
49 | - * |
|
50 | - * @param DoliDB $db Database handler |
|
51 | - */ |
|
52 | - public function __construct(DoliDB $db) |
|
53 | - { |
|
54 | - $this->db = $db; |
|
55 | - |
|
56 | - $this->socid = 0; |
|
57 | - $this->solde = 0; |
|
58 | - $this->error_number = 0; |
|
59 | - $this->default_rib = 0; |
|
60 | - } |
|
61 | - |
|
62 | - |
|
63 | - /** |
|
64 | - * Create bank information record |
|
65 | - * |
|
66 | - * @param User $user User |
|
67 | - * @param int $notrigger 1=Disable triggers |
|
68 | - * @return int <0 if KO, >= 0 if OK |
|
69 | - */ |
|
70 | - function create(User $user = null, $notrigger=0) |
|
71 | - { |
|
72 | - $now = dol_now(); |
|
73 | - $error = 0; |
|
74 | - // Correct default_rib to be sure to have always one default |
|
75 | - $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_rib where fk_soc = ".$this->socid." AND default_rib = 1 AND type = 'ban'"; |
|
76 | - $result = $this->db->query($sql); |
|
77 | - if ($result) |
|
78 | - { |
|
79 | - $numrows=$this->db->num_rows($result); |
|
80 | - if ($this->default_rib && $numrows > 0) $this->default_rib = 0; |
|
81 | - if (empty($this->default_rib) && $numrows == 0) $this->default_rib = 1; |
|
82 | - } |
|
83 | - |
|
84 | - $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_rib (fk_soc, type, datec)"; |
|
85 | - $sql.= " VALUES (".$this->socid.", 'ban', '".$this->db->idate($now)."')"; |
|
86 | - $resql=$this->db->query($sql); |
|
87 | - if ($resql) |
|
88 | - { |
|
89 | - if ($this->db->affected_rows($resql)) |
|
90 | - { |
|
91 | - $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_rib"); |
|
92 | - |
|
93 | - if (! $notrigger) |
|
94 | - { |
|
95 | - // Call trigger |
|
96 | - $result=$this->call_trigger('COMPANY_RIB_CREATE',$user); |
|
97 | - if ($result < 0) $error++; |
|
98 | - // End call triggers |
|
99 | - |
|
100 | - if (! $error) |
|
101 | - { |
|
102 | - return 1; |
|
103 | - } |
|
104 | - else |
|
105 | - { |
|
106 | - return 0; |
|
107 | - } |
|
108 | - } |
|
109 | - else |
|
110 | - { |
|
111 | - return 1; |
|
112 | - } |
|
113 | - } |
|
114 | - } |
|
115 | - else |
|
116 | - { |
|
117 | - print $this->db->error(); |
|
118 | - return 0; |
|
119 | - } |
|
120 | - } |
|
121 | - |
|
122 | - /** |
|
123 | - * Update bank account |
|
124 | - * |
|
125 | - * @param User $user Object user |
|
126 | - * @param int $notrigger 1=Disable triggers |
|
127 | - * @return int <=0 if KO, >0 if OK |
|
128 | - */ |
|
129 | - function update(User $user = null, $notrigger = 0) |
|
130 | - { |
|
131 | - global $conf; |
|
132 | - $error = 0; |
|
133 | - |
|
134 | - if (! $this->id) return -1; |
|
135 | - |
|
136 | - if (dol_strlen($this->domiciliation) > 255) $this->domiciliation = dol_trunc($this->domiciliation, 254, 'right', 'UTF-8', 1); |
|
137 | - if (dol_strlen($this->owner_address) > 255) $this->owner_address = dol_trunc($this->owner_address, 254, 'right', 'UTF-8', 1); |
|
138 | - |
|
139 | - $sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET"; |
|
140 | - $sql.= " bank = '" .$this->db->escape($this->bank)."'"; |
|
141 | - $sql.= ",code_banque='".$this->db->escape($this->code_banque)."'"; |
|
142 | - $sql.= ",code_guichet='".$this->db->escape($this->code_guichet)."'"; |
|
143 | - $sql.= ",number='".$this->db->escape($this->number)."'"; |
|
144 | - $sql.= ",cle_rib='".$this->db->escape($this->cle_rib)."'"; |
|
145 | - $sql.= ",bic='".$this->db->escape($this->bic)."'"; |
|
146 | - $sql.= ",iban_prefix = '".$this->db->escape($this->iban)."'"; |
|
147 | - $sql.= ",domiciliation='".$this->db->escape($this->domiciliation)."'"; |
|
148 | - $sql.= ",proprio = '".$this->db->escape($this->proprio)."'"; |
|
149 | - $sql.= ",owner_address = '".$this->db->escape($this->owner_address)."'"; |
|
150 | - $sql.= ",default_rib = ".$this->default_rib; |
|
151 | - if ($conf->prelevement->enabled) |
|
152 | - { |
|
153 | - $sql.= ",frstrecur = '".$this->db->escape($this->frstrecur)."'"; |
|
154 | - $sql.= ",rum = '".$this->db->escape($this->rum)."'"; |
|
155 | - $sql.= ",date_rum = ".($this->date_rum ? "'".$this->db->idate($this->date_rum)."'" : "null"); |
|
156 | - } |
|
157 | - if (trim($this->label) != '') |
|
158 | - $sql.= ",label = '".$this->db->escape($this->label)."'"; |
|
159 | - else |
|
160 | - $sql.= ",label = NULL"; |
|
161 | - $sql.= " WHERE rowid = ".$this->id; |
|
162 | - |
|
163 | - $result = $this->db->query($sql); |
|
164 | - if ($result) |
|
165 | - { |
|
166 | - |
|
167 | - |
|
168 | - if (! $notrigger) |
|
169 | - { |
|
170 | - // Call trigger |
|
171 | - $result=$this->call_trigger('COMPANY_RIB_MODIFY',$user); |
|
172 | - if ($result < 0) $error++; |
|
173 | - // End call triggers |
|
174 | - if(! $error ) |
|
175 | - { |
|
176 | - return 1; |
|
177 | - } |
|
178 | - else |
|
179 | - { |
|
180 | - return -1; |
|
181 | - } |
|
182 | - } |
|
183 | - else |
|
184 | - { |
|
185 | - return 1; |
|
186 | - } |
|
187 | - } |
|
188 | - else |
|
189 | - { |
|
190 | - dol_print_error($this->db); |
|
191 | - return -1; |
|
192 | - } |
|
193 | - } |
|
194 | - |
|
195 | - /** |
|
196 | - * Load record from database |
|
197 | - * |
|
198 | - * @param int $id Id of record |
|
199 | - * @param int $socid Id of company. If this is filled, function will return the first entry found (matching $default and $type) |
|
200 | - * @param int $default If id of company filled, we say if we want first record among all (-1), default record (1) or non default record (0) |
|
201 | - * @param int $type If id of company filled, we say if we want record of this type only |
|
202 | - * @return int <0 if KO, >0 if OK |
|
203 | - */ |
|
204 | - function fetch($id, $socid=0, $default=1, $type='ban') |
|
205 | - { |
|
206 | - if (empty($id) && empty($socid)) return -1; |
|
207 | - |
|
208 | - $sql = "SELECT rowid, type, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,"; |
|
209 | - $sql.= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur"; |
|
210 | - $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib"; |
|
211 | - if ($id) $sql.= " WHERE rowid = ".$id; |
|
212 | - if ($socid) |
|
213 | - { |
|
214 | - $sql.= " WHERE fk_soc = ".$socid; |
|
215 | - if ($default > -1) $sql.=" AND default_rib = ".$this->db->escape($default); |
|
216 | - if ($type) $sql.= " AND type ='".$this->db->escape($type)."'"; |
|
217 | - } |
|
218 | - |
|
219 | - $resql = $this->db->query($sql); |
|
220 | - if ($resql) |
|
221 | - { |
|
222 | - if ($this->db->num_rows($resql)) |
|
223 | - { |
|
224 | - $obj = $this->db->fetch_object($resql); |
|
225 | - |
|
226 | - $this->ref = $obj->fk_soc.'-'.$obj->label; // Generate an artificial ref |
|
227 | - |
|
228 | - $this->id = $obj->rowid; |
|
229 | - $this->type = $obj->type; |
|
230 | - $this->socid = $obj->fk_soc; |
|
231 | - $this->bank = $obj->bank; |
|
232 | - $this->code_banque = $obj->code_banque; |
|
233 | - $this->code_guichet = $obj->code_guichet; |
|
234 | - $this->number = $obj->number; |
|
235 | - $this->cle_rib = $obj->cle_rib; |
|
236 | - $this->bic = $obj->bic; |
|
237 | - $this->iban = $obj->iban; |
|
238 | - $this->domiciliation = $obj->domiciliation; |
|
239 | - $this->proprio = $obj->proprio; |
|
240 | - $this->owner_address = $obj->owner_address; |
|
241 | - $this->label = $obj->label; |
|
242 | - $this->default_rib = $obj->default_rib; |
|
243 | - $this->datec = $this->db->jdate($obj->datec); |
|
244 | - $this->datem = $this->db->jdate($obj->datem); |
|
245 | - $this->rum = $obj->rum; |
|
246 | - $this->frstrecur = $obj->frstrecur; |
|
247 | - } |
|
248 | - $this->db->free($resql); |
|
249 | - |
|
250 | - return 1; |
|
251 | - } |
|
252 | - else |
|
253 | - { |
|
254 | - dol_print_error($this->db); |
|
255 | - return -1; |
|
256 | - } |
|
257 | - } |
|
258 | - |
|
259 | - /** |
|
260 | - * Delete a rib from database |
|
261 | - * |
|
262 | - * @param User $user User deleting |
|
263 | - * @param int $notrigger 1=Disable triggers |
|
264 | - * @return int <0 if KO, >0 if OK |
|
265 | - */ |
|
266 | - function delete(User $user = null, $notrigger=0) |
|
267 | - { |
|
268 | - global $conf; |
|
269 | - |
|
270 | - $error = 0; |
|
271 | - |
|
272 | - dol_syslog(get_class($this) . "::delete ".$this->id, LOG_DEBUG); |
|
273 | - |
|
274 | - $this->db->begin(); |
|
275 | - |
|
276 | - if (! $error && ! $notrigger) |
|
277 | - { |
|
278 | - // Call trigger |
|
279 | - $result=$this->call_trigger('COMPANY_RIB_DELETE',$user); |
|
280 | - if ($result < 0) $error++; |
|
281 | - // End call triggers |
|
282 | - } |
|
283 | - |
|
284 | - if (! $error) |
|
285 | - { |
|
286 | - $sql = "DELETE FROM " . MAIN_DB_PREFIX . "societe_rib"; |
|
287 | - $sql .= " WHERE rowid = " . $this->id; |
|
288 | - |
|
289 | - if (! $this->db->query($sql)) |
|
290 | - { |
|
291 | - $error++; |
|
292 | - $this->errors[]=$this->db->lasterror(); |
|
293 | - } |
|
294 | - } |
|
295 | - |
|
296 | - if (! $error) |
|
297 | - { |
|
298 | - $this->db->commit(); |
|
299 | - return 1; |
|
300 | - } |
|
301 | - else |
|
302 | - { |
|
303 | - $this->db->rollback(); |
|
304 | - return -1*$error; |
|
305 | - } |
|
306 | - } |
|
307 | - |
|
308 | - /** |
|
309 | - * Return RIB |
|
310 | - * |
|
311 | - * @param boolean $displayriblabel Prepend or Hide Label |
|
312 | - * @return string RIB |
|
313 | - */ |
|
314 | - public function getRibLabel($displayriblabel = true) |
|
315 | - { |
|
316 | - $rib = ''; |
|
317 | - |
|
318 | - if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib || $this->iban || $this->bic ) { |
|
319 | - |
|
320 | - if ($this->label && $displayriblabel) { |
|
321 | - $rib = $this->label." : "; |
|
322 | - } |
|
323 | - |
|
324 | - $rib .= (string) $this; |
|
325 | - } |
|
326 | - |
|
327 | - return $rib; |
|
328 | - } |
|
329 | - |
|
330 | - /** |
|
331 | - * Set a BAN as Default |
|
332 | - * |
|
333 | - * @param int $rib RIB id |
|
334 | - * @return int 0 if KO, 1 if OK |
|
335 | - */ |
|
336 | - function setAsDefault($rib=0) |
|
337 | - { |
|
338 | - $sql1 = "SELECT rowid as id, fk_soc FROM ".MAIN_DB_PREFIX."societe_rib"; |
|
339 | - $sql1.= " WHERE rowid = ".($rib?$rib:$this->id); |
|
340 | - |
|
341 | - dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG); |
|
342 | - $result1 = $this->db->query($sql1); |
|
343 | - if ($result1) |
|
344 | - { |
|
345 | - if ($this->db->num_rows($result1) == 0) |
|
346 | - { |
|
347 | - return 0; |
|
348 | - } |
|
349 | - else |
|
350 | - { |
|
351 | - $obj = $this->db->fetch_object($result1); |
|
352 | - |
|
353 | - $this->db->begin(); |
|
354 | - |
|
355 | - $sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0"; |
|
356 | - $sql2.= " WHERE type = 'ban' AND fk_soc = ".$obj->fk_soc; |
|
357 | - dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG); |
|
358 | - $result2 = $this->db->query($sql2); |
|
359 | - |
|
360 | - $sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1"; |
|
361 | - $sql3.= " WHERE rowid = ".$obj->id; |
|
362 | - dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG); |
|
363 | - $result3 = $this->db->query($sql3); |
|
364 | - |
|
365 | - if (!$result2 || !$result3) |
|
366 | - { |
|
367 | - dol_print_error($this->db); |
|
368 | - $this->db->rollback(); |
|
369 | - return -1; |
|
370 | - } |
|
371 | - else |
|
372 | - { |
|
373 | - $this->db->commit(); |
|
374 | - return 1; |
|
375 | - } |
|
376 | - } |
|
377 | - } |
|
378 | - else |
|
379 | - { |
|
380 | - dol_print_error($this->db); |
|
381 | - return -1; |
|
382 | - } |
|
383 | - } |
|
384 | - |
|
385 | - /** |
|
386 | - * Initialise an instance with random values. |
|
387 | - * Used to build previews or test instances. |
|
388 | - * id must be 0 if object instance is a specimen. |
|
389 | - * |
|
390 | - * @return void |
|
391 | - */ |
|
392 | - function initAsSpecimen() |
|
393 | - { |
|
394 | - $this->specimen = 1; |
|
395 | - $this->ref = 'CBA'; |
|
396 | - $this->label = 'CustomerCorp Bank account'; |
|
397 | - $this->bank = 'CustomerCorp Bank'; |
|
398 | - $this->courant = Account::TYPE_CURRENT; |
|
399 | - $this->clos = Account::STATUS_OPEN; |
|
400 | - $this->code_banque = '123'; |
|
401 | - $this->code_guichet = '456'; |
|
402 | - $this->number = 'CUST12345'; |
|
403 | - $this->cle_rib = 50; |
|
404 | - $this->bic = 'CC12'; |
|
405 | - $this->iban = 'FR999999999'; |
|
406 | - $this->domiciliation = 'Bank address of customer corp'; |
|
407 | - $this->proprio = 'Owner'; |
|
408 | - $this->owner_address = 'Owner address'; |
|
409 | - $this->country_id = 1; |
|
410 | - |
|
411 | - $this->rum = 'UMR-CU1212-0007-5-1475405262'; |
|
412 | - $this->date_rum =dol_now() - 10000; |
|
413 | - $this->frstrecur = 'FRST'; |
|
414 | - |
|
415 | - $this->socid = 0; |
|
416 | - } |
|
36 | + var $socid; |
|
37 | + |
|
38 | + var $default_rib; |
|
39 | + var $frstrecur; |
|
40 | + var $rum; |
|
41 | + var $date_rum; |
|
42 | + |
|
43 | + var $datec; |
|
44 | + var $datem; |
|
45 | + |
|
46 | + |
|
47 | + /** |
|
48 | + * Constructor |
|
49 | + * |
|
50 | + * @param DoliDB $db Database handler |
|
51 | + */ |
|
52 | + public function __construct(DoliDB $db) |
|
53 | + { |
|
54 | + $this->db = $db; |
|
55 | + |
|
56 | + $this->socid = 0; |
|
57 | + $this->solde = 0; |
|
58 | + $this->error_number = 0; |
|
59 | + $this->default_rib = 0; |
|
60 | + } |
|
61 | + |
|
62 | + |
|
63 | + /** |
|
64 | + * Create bank information record |
|
65 | + * |
|
66 | + * @param User $user User |
|
67 | + * @param int $notrigger 1=Disable triggers |
|
68 | + * @return int <0 if KO, >= 0 if OK |
|
69 | + */ |
|
70 | + function create(User $user = null, $notrigger=0) |
|
71 | + { |
|
72 | + $now = dol_now(); |
|
73 | + $error = 0; |
|
74 | + // Correct default_rib to be sure to have always one default |
|
75 | + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."societe_rib where fk_soc = ".$this->socid." AND default_rib = 1 AND type = 'ban'"; |
|
76 | + $result = $this->db->query($sql); |
|
77 | + if ($result) |
|
78 | + { |
|
79 | + $numrows=$this->db->num_rows($result); |
|
80 | + if ($this->default_rib && $numrows > 0) $this->default_rib = 0; |
|
81 | + if (empty($this->default_rib) && $numrows == 0) $this->default_rib = 1; |
|
82 | + } |
|
83 | + |
|
84 | + $sql = "INSERT INTO ".MAIN_DB_PREFIX."societe_rib (fk_soc, type, datec)"; |
|
85 | + $sql.= " VALUES (".$this->socid.", 'ban', '".$this->db->idate($now)."')"; |
|
86 | + $resql=$this->db->query($sql); |
|
87 | + if ($resql) |
|
88 | + { |
|
89 | + if ($this->db->affected_rows($resql)) |
|
90 | + { |
|
91 | + $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."societe_rib"); |
|
92 | + |
|
93 | + if (! $notrigger) |
|
94 | + { |
|
95 | + // Call trigger |
|
96 | + $result=$this->call_trigger('COMPANY_RIB_CREATE',$user); |
|
97 | + if ($result < 0) $error++; |
|
98 | + // End call triggers |
|
99 | + |
|
100 | + if (! $error) |
|
101 | + { |
|
102 | + return 1; |
|
103 | + } |
|
104 | + else |
|
105 | + { |
|
106 | + return 0; |
|
107 | + } |
|
108 | + } |
|
109 | + else |
|
110 | + { |
|
111 | + return 1; |
|
112 | + } |
|
113 | + } |
|
114 | + } |
|
115 | + else |
|
116 | + { |
|
117 | + print $this->db->error(); |
|
118 | + return 0; |
|
119 | + } |
|
120 | + } |
|
121 | + |
|
122 | + /** |
|
123 | + * Update bank account |
|
124 | + * |
|
125 | + * @param User $user Object user |
|
126 | + * @param int $notrigger 1=Disable triggers |
|
127 | + * @return int <=0 if KO, >0 if OK |
|
128 | + */ |
|
129 | + function update(User $user = null, $notrigger = 0) |
|
130 | + { |
|
131 | + global $conf; |
|
132 | + $error = 0; |
|
133 | + |
|
134 | + if (! $this->id) return -1; |
|
135 | + |
|
136 | + if (dol_strlen($this->domiciliation) > 255) $this->domiciliation = dol_trunc($this->domiciliation, 254, 'right', 'UTF-8', 1); |
|
137 | + if (dol_strlen($this->owner_address) > 255) $this->owner_address = dol_trunc($this->owner_address, 254, 'right', 'UTF-8', 1); |
|
138 | + |
|
139 | + $sql = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET"; |
|
140 | + $sql.= " bank = '" .$this->db->escape($this->bank)."'"; |
|
141 | + $sql.= ",code_banque='".$this->db->escape($this->code_banque)."'"; |
|
142 | + $sql.= ",code_guichet='".$this->db->escape($this->code_guichet)."'"; |
|
143 | + $sql.= ",number='".$this->db->escape($this->number)."'"; |
|
144 | + $sql.= ",cle_rib='".$this->db->escape($this->cle_rib)."'"; |
|
145 | + $sql.= ",bic='".$this->db->escape($this->bic)."'"; |
|
146 | + $sql.= ",iban_prefix = '".$this->db->escape($this->iban)."'"; |
|
147 | + $sql.= ",domiciliation='".$this->db->escape($this->domiciliation)."'"; |
|
148 | + $sql.= ",proprio = '".$this->db->escape($this->proprio)."'"; |
|
149 | + $sql.= ",owner_address = '".$this->db->escape($this->owner_address)."'"; |
|
150 | + $sql.= ",default_rib = ".$this->default_rib; |
|
151 | + if ($conf->prelevement->enabled) |
|
152 | + { |
|
153 | + $sql.= ",frstrecur = '".$this->db->escape($this->frstrecur)."'"; |
|
154 | + $sql.= ",rum = '".$this->db->escape($this->rum)."'"; |
|
155 | + $sql.= ",date_rum = ".($this->date_rum ? "'".$this->db->idate($this->date_rum)."'" : "null"); |
|
156 | + } |
|
157 | + if (trim($this->label) != '') |
|
158 | + $sql.= ",label = '".$this->db->escape($this->label)."'"; |
|
159 | + else |
|
160 | + $sql.= ",label = NULL"; |
|
161 | + $sql.= " WHERE rowid = ".$this->id; |
|
162 | + |
|
163 | + $result = $this->db->query($sql); |
|
164 | + if ($result) |
|
165 | + { |
|
166 | + |
|
167 | + |
|
168 | + if (! $notrigger) |
|
169 | + { |
|
170 | + // Call trigger |
|
171 | + $result=$this->call_trigger('COMPANY_RIB_MODIFY',$user); |
|
172 | + if ($result < 0) $error++; |
|
173 | + // End call triggers |
|
174 | + if(! $error ) |
|
175 | + { |
|
176 | + return 1; |
|
177 | + } |
|
178 | + else |
|
179 | + { |
|
180 | + return -1; |
|
181 | + } |
|
182 | + } |
|
183 | + else |
|
184 | + { |
|
185 | + return 1; |
|
186 | + } |
|
187 | + } |
|
188 | + else |
|
189 | + { |
|
190 | + dol_print_error($this->db); |
|
191 | + return -1; |
|
192 | + } |
|
193 | + } |
|
194 | + |
|
195 | + /** |
|
196 | + * Load record from database |
|
197 | + * |
|
198 | + * @param int $id Id of record |
|
199 | + * @param int $socid Id of company. If this is filled, function will return the first entry found (matching $default and $type) |
|
200 | + * @param int $default If id of company filled, we say if we want first record among all (-1), default record (1) or non default record (0) |
|
201 | + * @param int $type If id of company filled, we say if we want record of this type only |
|
202 | + * @return int <0 if KO, >0 if OK |
|
203 | + */ |
|
204 | + function fetch($id, $socid=0, $default=1, $type='ban') |
|
205 | + { |
|
206 | + if (empty($id) && empty($socid)) return -1; |
|
207 | + |
|
208 | + $sql = "SELECT rowid, type, fk_soc, bank, number, code_banque, code_guichet, cle_rib, bic, iban_prefix as iban, domiciliation, proprio,"; |
|
209 | + $sql.= " owner_address, default_rib, label, datec, tms as datem, rum, frstrecur"; |
|
210 | + $sql.= " FROM ".MAIN_DB_PREFIX."societe_rib"; |
|
211 | + if ($id) $sql.= " WHERE rowid = ".$id; |
|
212 | + if ($socid) |
|
213 | + { |
|
214 | + $sql.= " WHERE fk_soc = ".$socid; |
|
215 | + if ($default > -1) $sql.=" AND default_rib = ".$this->db->escape($default); |
|
216 | + if ($type) $sql.= " AND type ='".$this->db->escape($type)."'"; |
|
217 | + } |
|
218 | + |
|
219 | + $resql = $this->db->query($sql); |
|
220 | + if ($resql) |
|
221 | + { |
|
222 | + if ($this->db->num_rows($resql)) |
|
223 | + { |
|
224 | + $obj = $this->db->fetch_object($resql); |
|
225 | + |
|
226 | + $this->ref = $obj->fk_soc.'-'.$obj->label; // Generate an artificial ref |
|
227 | + |
|
228 | + $this->id = $obj->rowid; |
|
229 | + $this->type = $obj->type; |
|
230 | + $this->socid = $obj->fk_soc; |
|
231 | + $this->bank = $obj->bank; |
|
232 | + $this->code_banque = $obj->code_banque; |
|
233 | + $this->code_guichet = $obj->code_guichet; |
|
234 | + $this->number = $obj->number; |
|
235 | + $this->cle_rib = $obj->cle_rib; |
|
236 | + $this->bic = $obj->bic; |
|
237 | + $this->iban = $obj->iban; |
|
238 | + $this->domiciliation = $obj->domiciliation; |
|
239 | + $this->proprio = $obj->proprio; |
|
240 | + $this->owner_address = $obj->owner_address; |
|
241 | + $this->label = $obj->label; |
|
242 | + $this->default_rib = $obj->default_rib; |
|
243 | + $this->datec = $this->db->jdate($obj->datec); |
|
244 | + $this->datem = $this->db->jdate($obj->datem); |
|
245 | + $this->rum = $obj->rum; |
|
246 | + $this->frstrecur = $obj->frstrecur; |
|
247 | + } |
|
248 | + $this->db->free($resql); |
|
249 | + |
|
250 | + return 1; |
|
251 | + } |
|
252 | + else |
|
253 | + { |
|
254 | + dol_print_error($this->db); |
|
255 | + return -1; |
|
256 | + } |
|
257 | + } |
|
258 | + |
|
259 | + /** |
|
260 | + * Delete a rib from database |
|
261 | + * |
|
262 | + * @param User $user User deleting |
|
263 | + * @param int $notrigger 1=Disable triggers |
|
264 | + * @return int <0 if KO, >0 if OK |
|
265 | + */ |
|
266 | + function delete(User $user = null, $notrigger=0) |
|
267 | + { |
|
268 | + global $conf; |
|
269 | + |
|
270 | + $error = 0; |
|
271 | + |
|
272 | + dol_syslog(get_class($this) . "::delete ".$this->id, LOG_DEBUG); |
|
273 | + |
|
274 | + $this->db->begin(); |
|
275 | + |
|
276 | + if (! $error && ! $notrigger) |
|
277 | + { |
|
278 | + // Call trigger |
|
279 | + $result=$this->call_trigger('COMPANY_RIB_DELETE',$user); |
|
280 | + if ($result < 0) $error++; |
|
281 | + // End call triggers |
|
282 | + } |
|
283 | + |
|
284 | + if (! $error) |
|
285 | + { |
|
286 | + $sql = "DELETE FROM " . MAIN_DB_PREFIX . "societe_rib"; |
|
287 | + $sql .= " WHERE rowid = " . $this->id; |
|
288 | + |
|
289 | + if (! $this->db->query($sql)) |
|
290 | + { |
|
291 | + $error++; |
|
292 | + $this->errors[]=$this->db->lasterror(); |
|
293 | + } |
|
294 | + } |
|
295 | + |
|
296 | + if (! $error) |
|
297 | + { |
|
298 | + $this->db->commit(); |
|
299 | + return 1; |
|
300 | + } |
|
301 | + else |
|
302 | + { |
|
303 | + $this->db->rollback(); |
|
304 | + return -1*$error; |
|
305 | + } |
|
306 | + } |
|
307 | + |
|
308 | + /** |
|
309 | + * Return RIB |
|
310 | + * |
|
311 | + * @param boolean $displayriblabel Prepend or Hide Label |
|
312 | + * @return string RIB |
|
313 | + */ |
|
314 | + public function getRibLabel($displayriblabel = true) |
|
315 | + { |
|
316 | + $rib = ''; |
|
317 | + |
|
318 | + if ($this->code_banque || $this->code_guichet || $this->number || $this->cle_rib || $this->iban || $this->bic ) { |
|
319 | + |
|
320 | + if ($this->label && $displayriblabel) { |
|
321 | + $rib = $this->label." : "; |
|
322 | + } |
|
323 | + |
|
324 | + $rib .= (string) $this; |
|
325 | + } |
|
326 | + |
|
327 | + return $rib; |
|
328 | + } |
|
329 | + |
|
330 | + /** |
|
331 | + * Set a BAN as Default |
|
332 | + * |
|
333 | + * @param int $rib RIB id |
|
334 | + * @return int 0 if KO, 1 if OK |
|
335 | + */ |
|
336 | + function setAsDefault($rib=0) |
|
337 | + { |
|
338 | + $sql1 = "SELECT rowid as id, fk_soc FROM ".MAIN_DB_PREFIX."societe_rib"; |
|
339 | + $sql1.= " WHERE rowid = ".($rib?$rib:$this->id); |
|
340 | + |
|
341 | + dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG); |
|
342 | + $result1 = $this->db->query($sql1); |
|
343 | + if ($result1) |
|
344 | + { |
|
345 | + if ($this->db->num_rows($result1) == 0) |
|
346 | + { |
|
347 | + return 0; |
|
348 | + } |
|
349 | + else |
|
350 | + { |
|
351 | + $obj = $this->db->fetch_object($result1); |
|
352 | + |
|
353 | + $this->db->begin(); |
|
354 | + |
|
355 | + $sql2 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 0"; |
|
356 | + $sql2.= " WHERE type = 'ban' AND fk_soc = ".$obj->fk_soc; |
|
357 | + dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG); |
|
358 | + $result2 = $this->db->query($sql2); |
|
359 | + |
|
360 | + $sql3 = "UPDATE ".MAIN_DB_PREFIX."societe_rib SET default_rib = 1"; |
|
361 | + $sql3.= " WHERE rowid = ".$obj->id; |
|
362 | + dol_syslog(get_class($this).'::setAsDefault', LOG_DEBUG); |
|
363 | + $result3 = $this->db->query($sql3); |
|
364 | + |
|
365 | + if (!$result2 || !$result3) |
|
366 | + { |
|
367 | + dol_print_error($this->db); |
|
368 | + $this->db->rollback(); |
|
369 | + return -1; |
|
370 | + } |
|
371 | + else |
|
372 | + { |
|
373 | + $this->db->commit(); |
|
374 | + return 1; |
|
375 | + } |
|
376 | + } |
|
377 | + } |
|
378 | + else |
|
379 | + { |
|
380 | + dol_print_error($this->db); |
|
381 | + return -1; |
|
382 | + } |
|
383 | + } |
|
384 | + |
|
385 | + /** |
|
386 | + * Initialise an instance with random values. |
|
387 | + * Used to build previews or test instances. |
|
388 | + * id must be 0 if object instance is a specimen. |
|
389 | + * |
|
390 | + * @return void |
|
391 | + */ |
|
392 | + function initAsSpecimen() |
|
393 | + { |
|
394 | + $this->specimen = 1; |
|
395 | + $this->ref = 'CBA'; |
|
396 | + $this->label = 'CustomerCorp Bank account'; |
|
397 | + $this->bank = 'CustomerCorp Bank'; |
|
398 | + $this->courant = Account::TYPE_CURRENT; |
|
399 | + $this->clos = Account::STATUS_OPEN; |
|
400 | + $this->code_banque = '123'; |
|
401 | + $this->code_guichet = '456'; |
|
402 | + $this->number = 'CUST12345'; |
|
403 | + $this->cle_rib = 50; |
|
404 | + $this->bic = 'CC12'; |
|
405 | + $this->iban = 'FR999999999'; |
|
406 | + $this->domiciliation = 'Bank address of customer corp'; |
|
407 | + $this->proprio = 'Owner'; |
|
408 | + $this->owner_address = 'Owner address'; |
|
409 | + $this->country_id = 1; |
|
410 | + |
|
411 | + $this->rum = 'UMR-CU1212-0007-5-1475405262'; |
|
412 | + $this->date_rum =dol_now() - 10000; |
|
413 | + $this->frstrecur = 'FRST'; |
|
414 | + |
|
415 | + $this->socid = 0; |
|
416 | + } |
|
417 | 417 | } |
418 | 418 |
@@ -29,305 +29,305 @@ discard block |
||
29 | 29 | */ |
30 | 30 | class Contacts extends DolibarrApi |
31 | 31 | { |
32 | - /** |
|
33 | - * |
|
34 | - * @var array $FIELDS Mandatory fields, checked when create and update object |
|
35 | - */ |
|
36 | - static $FIELDS = array( |
|
37 | - 'lastname', |
|
38 | - ); |
|
39 | - |
|
40 | - /** |
|
41 | - * @var Contact $contact {@type Contact} |
|
42 | - */ |
|
43 | - public $contact; |
|
44 | - |
|
45 | - /** |
|
46 | - * Constructor |
|
47 | - */ |
|
48 | - function __construct() |
|
49 | - { |
|
50 | - global $db, $conf; |
|
51 | - $this->db = $db; |
|
52 | - |
|
53 | - require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
|
54 | - require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; |
|
55 | - |
|
56 | - $this->contact = new Contact($this->db); |
|
57 | - } |
|
58 | - |
|
59 | - /** |
|
60 | - * Get properties of a contact object |
|
61 | - * |
|
62 | - * Return an array with contact informations |
|
63 | - * |
|
64 | - * @param int $id ID of contact |
|
65 | - * @return array|mixed data without useless information |
|
66 | - * |
|
67 | - * @throws RestException |
|
68 | - */ |
|
69 | - function get($id) |
|
70 | - { |
|
71 | - if (!DolibarrApiAccess::$user->rights->societe->contact->lire) |
|
72 | - { |
|
73 | - throw new RestException(401, 'No permission to read contacts'); |
|
74 | - } |
|
75 | - |
|
76 | - $result = $this->contact->fetch($id); |
|
77 | - if (!$result) |
|
78 | - { |
|
79 | - throw new RestException(404, 'Contact not found'); |
|
80 | - } |
|
81 | - |
|
82 | - if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id, 'socpeople&societe')) |
|
83 | - { |
|
84 | - throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); |
|
85 | - } |
|
86 | - |
|
87 | - return $this->_cleanObjectDatas($this->contact); |
|
88 | - } |
|
89 | - |
|
90 | - /** |
|
91 | - * List contacts |
|
92 | - * |
|
93 | - * Get a list of contacts |
|
94 | - * |
|
95 | - * @param string $sortfield Sort field |
|
96 | - * @param string $sortorder Sort order |
|
97 | - * @param int $limit Limit for list |
|
98 | - * @param int $page Page number |
|
32 | + /** |
|
33 | + * |
|
34 | + * @var array $FIELDS Mandatory fields, checked when create and update object |
|
35 | + */ |
|
36 | + static $FIELDS = array( |
|
37 | + 'lastname', |
|
38 | + ); |
|
39 | + |
|
40 | + /** |
|
41 | + * @var Contact $contact {@type Contact} |
|
42 | + */ |
|
43 | + public $contact; |
|
44 | + |
|
45 | + /** |
|
46 | + * Constructor |
|
47 | + */ |
|
48 | + function __construct() |
|
49 | + { |
|
50 | + global $db, $conf; |
|
51 | + $this->db = $db; |
|
52 | + |
|
53 | + require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php'; |
|
54 | + require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; |
|
55 | + |
|
56 | + $this->contact = new Contact($this->db); |
|
57 | + } |
|
58 | + |
|
59 | + /** |
|
60 | + * Get properties of a contact object |
|
61 | + * |
|
62 | + * Return an array with contact informations |
|
63 | + * |
|
64 | + * @param int $id ID of contact |
|
65 | + * @return array|mixed data without useless information |
|
66 | + * |
|
67 | + * @throws RestException |
|
68 | + */ |
|
69 | + function get($id) |
|
70 | + { |
|
71 | + if (!DolibarrApiAccess::$user->rights->societe->contact->lire) |
|
72 | + { |
|
73 | + throw new RestException(401, 'No permission to read contacts'); |
|
74 | + } |
|
75 | + |
|
76 | + $result = $this->contact->fetch($id); |
|
77 | + if (!$result) |
|
78 | + { |
|
79 | + throw new RestException(404, 'Contact not found'); |
|
80 | + } |
|
81 | + |
|
82 | + if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id, 'socpeople&societe')) |
|
83 | + { |
|
84 | + throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); |
|
85 | + } |
|
86 | + |
|
87 | + return $this->_cleanObjectDatas($this->contact); |
|
88 | + } |
|
89 | + |
|
90 | + /** |
|
91 | + * List contacts |
|
92 | + * |
|
93 | + * Get a list of contacts |
|
94 | + * |
|
95 | + * @param string $sortfield Sort field |
|
96 | + * @param string $sortorder Sort order |
|
97 | + * @param int $limit Limit for list |
|
98 | + * @param int $page Page number |
|
99 | 99 | * @param string $thirdparty_ids Thirdparty ids to filter contacts of. {@example '1' or '1,2,3'} {@pattern /^[0-9,]*$/i} |
100 | 100 | * @param string $sqlfilters Other criteria to filter answers separated by a comma. Syntax example "(t.ref:like:'SO-%') and (t.date_creation:<:'20160101')" |
101 | - * @return array Array of contact objects |
|
101 | + * @return array Array of contact objects |
|
102 | 102 | * |
103 | - * @throws RestException |
|
103 | + * @throws RestException |
|
104 | 104 | */ |
105 | 105 | function index($sortfield = "t.rowid", $sortorder = 'ASC', $limit = 100, $page = 0, $thirdparty_ids = '', $sqlfilters = '') |
106 | 106 | { |
107 | - global $db, $conf; |
|
107 | + global $db, $conf; |
|
108 | 108 | |
109 | - $obj_ret = array(); |
|
109 | + $obj_ret = array(); |
|
110 | 110 | |
111 | - if (!DolibarrApiAccess::$user->rights->societe->contact->lire) |
|
112 | - { |
|
113 | - throw new RestException(401, 'No permission to read contacts'); |
|
114 | - } |
|
111 | + if (!DolibarrApiAccess::$user->rights->societe->contact->lire) |
|
112 | + { |
|
113 | + throw new RestException(401, 'No permission to read contacts'); |
|
114 | + } |
|
115 | 115 | |
116 | 116 | // case of external user, $thirdparty_ids param is ignored and replaced by user's socid |
117 | - $socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids; |
|
118 | - |
|
119 | - // If the internal user must only see his customers, force searching by him |
|
120 | - $search_sale = 0; |
|
121 | - if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) |
|
122 | - $search_sale = DolibarrApiAccess::$user->id; |
|
123 | - |
|
124 | - $sql = "SELECT t.rowid"; |
|
125 | - $sql.= " FROM " . MAIN_DB_PREFIX . "socpeople as t"; |
|
126 | - $sql.= " LEFT JOIN ".MAIN_DB_PREFIX . "socpeople_extrafields as te ON te.fk_object = t.rowid"; |
|
127 | - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) { |
|
128 | - // We need this table joined to the select in order to filter by sale |
|
129 | - $sql.= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; |
|
130 | - } |
|
131 | - $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON t.fk_soc = s.rowid"; |
|
132 | - $sql.= ' WHERE t.entity IN (' . getEntity('socpeople') . ')'; |
|
133 | - if ($socids) $sql.= " AND t.fk_soc IN (" . $socids . ")"; |
|
134 | - |
|
135 | - if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) |
|
136 | - $sql.= " AND t.fk_soc = sc.fk_soc"; |
|
137 | - if ($search_sale > 0) |
|
138 | - $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale |
|
139 | - // Insert sale filter |
|
140 | - if ($search_sale > 0) |
|
141 | - { |
|
142 | - $sql .= " AND sc.fk_user = " . $search_sale; |
|
143 | - } |
|
144 | - // Add sql filters |
|
117 | + $socids = DolibarrApiAccess::$user->socid ? DolibarrApiAccess::$user->socid : $thirdparty_ids; |
|
118 | + |
|
119 | + // If the internal user must only see his customers, force searching by him |
|
120 | + $search_sale = 0; |
|
121 | + if (!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) |
|
122 | + $search_sale = DolibarrApiAccess::$user->id; |
|
123 | + |
|
124 | + $sql = "SELECT t.rowid"; |
|
125 | + $sql.= " FROM " . MAIN_DB_PREFIX . "socpeople as t"; |
|
126 | + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX . "socpeople_extrafields as te ON te.fk_object = t.rowid"; |
|
127 | + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) { |
|
128 | + // We need this table joined to the select in order to filter by sale |
|
129 | + $sql.= ", " . MAIN_DB_PREFIX . "societe_commerciaux as sc"; |
|
130 | + } |
|
131 | + $sql.= " LEFT JOIN " . MAIN_DB_PREFIX . "societe as s ON t.fk_soc = s.rowid"; |
|
132 | + $sql.= ' WHERE t.entity IN (' . getEntity('socpeople') . ')'; |
|
133 | + if ($socids) $sql.= " AND t.fk_soc IN (" . $socids . ")"; |
|
134 | + |
|
135 | + if ((!DolibarrApiAccess::$user->rights->societe->client->voir && !$socids) || $search_sale > 0) |
|
136 | + $sql.= " AND t.fk_soc = sc.fk_soc"; |
|
137 | + if ($search_sale > 0) |
|
138 | + $sql.= " AND s.rowid = sc.fk_soc"; // Join for the needed table to filter by sale |
|
139 | + // Insert sale filter |
|
140 | + if ($search_sale > 0) |
|
141 | + { |
|
142 | + $sql .= " AND sc.fk_user = " . $search_sale; |
|
143 | + } |
|
144 | + // Add sql filters |
|
145 | 145 | if ($sqlfilters) |
146 | 146 | { |
147 | 147 | if (! DolibarrApi::_checkFilters($sqlfilters)) |
148 | 148 | { |
149 | 149 | throw new RestException(503, 'Error when validating parameter sqlfilters '.$sqlfilters); |
150 | 150 | } |
151 | - $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
151 | + $regexstring='\(([^:\'\(\)]+:[^:\'\(\)]+:[^:\(\)]+)\)'; |
|
152 | 152 | $sql.=" AND (".preg_replace_callback('/'.$regexstring.'/', 'DolibarrApi::_forge_criteria_callback', $sqlfilters).")"; |
153 | 153 | } |
154 | 154 | |
155 | - $sql.= $db->order($sortfield, $sortorder); |
|
156 | - |
|
157 | - if ($limit) |
|
158 | - { |
|
159 | - if ($page < 0) |
|
160 | - { |
|
161 | - $page = 0; |
|
162 | - } |
|
163 | - $offset = $limit * $page; |
|
164 | - |
|
165 | - $sql.= $db->plimit($limit + 1, $offset); |
|
166 | - } |
|
167 | - $result = $db->query($sql); |
|
168 | - if ($result) |
|
169 | - { |
|
170 | - $num = $db->num_rows($result); |
|
171 | - $min = min($num, ($limit <= 0 ? $num : $limit)); |
|
172 | - while ($i < $min) |
|
173 | - { |
|
174 | - $obj = $db->fetch_object($result); |
|
175 | - $contact_static = new Contact($db); |
|
176 | - if ($contact_static->fetch($obj->rowid)) |
|
177 | - { |
|
178 | - $obj_ret[] = $this->_cleanObjectDatas($contact_static); |
|
179 | - } |
|
180 | - $i++; |
|
181 | - } |
|
182 | - } |
|
183 | - else { |
|
184 | - throw new RestException(503, 'Error when retrieve contacts : ' . $sql); |
|
185 | - } |
|
186 | - if (!count($obj_ret)) |
|
187 | - { |
|
188 | - throw new RestException(404, 'Contacts not found'); |
|
189 | - } |
|
190 | - return $obj_ret; |
|
191 | - } |
|
192 | - |
|
193 | - /** |
|
194 | - * Create contact object |
|
195 | - * |
|
196 | - * @param array $request_data Request datas |
|
197 | - * @return int ID of contact |
|
198 | - */ |
|
155 | + $sql.= $db->order($sortfield, $sortorder); |
|
156 | + |
|
157 | + if ($limit) |
|
158 | + { |
|
159 | + if ($page < 0) |
|
160 | + { |
|
161 | + $page = 0; |
|
162 | + } |
|
163 | + $offset = $limit * $page; |
|
164 | + |
|
165 | + $sql.= $db->plimit($limit + 1, $offset); |
|
166 | + } |
|
167 | + $result = $db->query($sql); |
|
168 | + if ($result) |
|
169 | + { |
|
170 | + $num = $db->num_rows($result); |
|
171 | + $min = min($num, ($limit <= 0 ? $num : $limit)); |
|
172 | + while ($i < $min) |
|
173 | + { |
|
174 | + $obj = $db->fetch_object($result); |
|
175 | + $contact_static = new Contact($db); |
|
176 | + if ($contact_static->fetch($obj->rowid)) |
|
177 | + { |
|
178 | + $obj_ret[] = $this->_cleanObjectDatas($contact_static); |
|
179 | + } |
|
180 | + $i++; |
|
181 | + } |
|
182 | + } |
|
183 | + else { |
|
184 | + throw new RestException(503, 'Error when retrieve contacts : ' . $sql); |
|
185 | + } |
|
186 | + if (!count($obj_ret)) |
|
187 | + { |
|
188 | + throw new RestException(404, 'Contacts not found'); |
|
189 | + } |
|
190 | + return $obj_ret; |
|
191 | + } |
|
192 | + |
|
193 | + /** |
|
194 | + * Create contact object |
|
195 | + * |
|
196 | + * @param array $request_data Request datas |
|
197 | + * @return int ID of contact |
|
198 | + */ |
|
199 | 199 | function post($request_data = null) |
200 | 200 | { |
201 | - if (!DolibarrApiAccess::$user->rights->societe->contact->creer) |
|
202 | - { |
|
203 | - throw new RestException(401, 'No permission to create/update contacts'); |
|
204 | - } |
|
205 | - // Check mandatory fields |
|
206 | - $result = $this->_validate($request_data); |
|
207 | - |
|
208 | - foreach ($request_data as $field => $value) |
|
209 | - { |
|
210 | - $this->contact->$field = $value; |
|
211 | - } |
|
212 | - if ($this->contact->create(DolibarrApiAccess::$user) < 0) { |
|
213 | - throw new RestException(500, "Error creating contact", array_merge(array($this->contact->error), $this->contact->errors)); |
|
214 | - } |
|
215 | - return $this->contact->id; |
|
216 | - } |
|
217 | - |
|
218 | - /** |
|
219 | - * Update contact |
|
220 | - * |
|
221 | - * @param int $id Id of contact to update |
|
222 | - * @param array $request_data Datas |
|
223 | - * @return int |
|
224 | - */ |
|
201 | + if (!DolibarrApiAccess::$user->rights->societe->contact->creer) |
|
202 | + { |
|
203 | + throw new RestException(401, 'No permission to create/update contacts'); |
|
204 | + } |
|
205 | + // Check mandatory fields |
|
206 | + $result = $this->_validate($request_data); |
|
207 | + |
|
208 | + foreach ($request_data as $field => $value) |
|
209 | + { |
|
210 | + $this->contact->$field = $value; |
|
211 | + } |
|
212 | + if ($this->contact->create(DolibarrApiAccess::$user) < 0) { |
|
213 | + throw new RestException(500, "Error creating contact", array_merge(array($this->contact->error), $this->contact->errors)); |
|
214 | + } |
|
215 | + return $this->contact->id; |
|
216 | + } |
|
217 | + |
|
218 | + /** |
|
219 | + * Update contact |
|
220 | + * |
|
221 | + * @param int $id Id of contact to update |
|
222 | + * @param array $request_data Datas |
|
223 | + * @return int |
|
224 | + */ |
|
225 | 225 | function put($id, $request_data = null) |
226 | 226 | { |
227 | - if (!DolibarrApiAccess::$user->rights->societe->contact->creer) |
|
228 | - { |
|
229 | - throw new RestException(401, 'No permission to create/update contacts'); |
|
230 | - } |
|
231 | - |
|
232 | - $result = $this->contact->fetch($id); |
|
233 | - if (!$result) |
|
234 | - { |
|
235 | - throw new RestException(404, 'Contact not found'); |
|
236 | - } |
|
237 | - |
|
238 | - if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id, 'socpeople&societe')) |
|
239 | - { |
|
240 | - throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); |
|
241 | - } |
|
242 | - |
|
243 | - foreach ($request_data as $field => $value) |
|
244 | - { |
|
227 | + if (!DolibarrApiAccess::$user->rights->societe->contact->creer) |
|
228 | + { |
|
229 | + throw new RestException(401, 'No permission to create/update contacts'); |
|
230 | + } |
|
231 | + |
|
232 | + $result = $this->contact->fetch($id); |
|
233 | + if (!$result) |
|
234 | + { |
|
235 | + throw new RestException(404, 'Contact not found'); |
|
236 | + } |
|
237 | + |
|
238 | + if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id, 'socpeople&societe')) |
|
239 | + { |
|
240 | + throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); |
|
241 | + } |
|
242 | + |
|
243 | + foreach ($request_data as $field => $value) |
|
244 | + { |
|
245 | 245 | if ($field == 'id') continue; |
246 | - $this->contact->$field = $value; |
|
247 | - } |
|
246 | + $this->contact->$field = $value; |
|
247 | + } |
|
248 | 248 | |
249 | - if ($this->contact->update($id, DolibarrApiAccess::$user, 1, '', '', 'update')) |
|
250 | - return $this->get($id); |
|
249 | + if ($this->contact->update($id, DolibarrApiAccess::$user, 1, '', '', 'update')) |
|
250 | + return $this->get($id); |
|
251 | 251 | |
252 | - return false; |
|
253 | - } |
|
252 | + return false; |
|
253 | + } |
|
254 | 254 | |
255 | - /** |
|
256 | - * Delete contact |
|
257 | - * |
|
258 | - * @param int $id Contact ID |
|
259 | - * @return integer |
|
260 | - */ |
|
255 | + /** |
|
256 | + * Delete contact |
|
257 | + * |
|
258 | + * @param int $id Contact ID |
|
259 | + * @return integer |
|
260 | + */ |
|
261 | 261 | function delete($id) |
262 | 262 | { |
263 | - if (!DolibarrApiAccess::$user->rights->societe->contact->supprimer) |
|
264 | - { |
|
265 | - throw new RestException(401, 'No permission to delete contacts'); |
|
266 | - } |
|
267 | - $result = $this->contact->fetch($id); |
|
268 | - if (!$result) |
|
269 | - { |
|
270 | - throw new RestException(404, 'Contact not found'); |
|
271 | - } |
|
272 | - |
|
273 | - if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id, 'socpeople&societe')) |
|
274 | - { |
|
275 | - throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); |
|
276 | - } |
|
277 | - |
|
278 | - return $this->contact->delete($id); |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * Create an user account object from contact (external user) |
|
283 | - * |
|
284 | - * @param int $id Id of contact |
|
285 | - * @param array $request_data Request datas |
|
286 | - * @return int ID of user |
|
287 | - * |
|
288 | - * @url POST {id}/createUser |
|
289 | - */ |
|
263 | + if (!DolibarrApiAccess::$user->rights->societe->contact->supprimer) |
|
264 | + { |
|
265 | + throw new RestException(401, 'No permission to delete contacts'); |
|
266 | + } |
|
267 | + $result = $this->contact->fetch($id); |
|
268 | + if (!$result) |
|
269 | + { |
|
270 | + throw new RestException(404, 'Contact not found'); |
|
271 | + } |
|
272 | + |
|
273 | + if (!DolibarrApi::_checkAccessToResource('contact', $this->contact->id, 'socpeople&societe')) |
|
274 | + { |
|
275 | + throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); |
|
276 | + } |
|
277 | + |
|
278 | + return $this->contact->delete($id); |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * Create an user account object from contact (external user) |
|
283 | + * |
|
284 | + * @param int $id Id of contact |
|
285 | + * @param array $request_data Request datas |
|
286 | + * @return int ID of user |
|
287 | + * |
|
288 | + * @url POST {id}/createUser |
|
289 | + */ |
|
290 | 290 | function createUser($id, $request_data = null) |
291 | 291 | { |
292 | - //if (!DolibarrApiAccess::$user->rights->user->user->creer) { |
|
293 | - //throw new RestException(401); |
|
294 | - //} |
|
295 | - |
|
296 | - if (!isset($request_data["login"])) |
|
297 | - throw new RestException(400, "login field missing"); |
|
298 | - if (!isset($request_data["password"])) |
|
299 | - throw new RestException(400, "password field missing"); |
|
300 | - |
|
301 | - if (!DolibarrApiAccess::$user->rights->societe->contact->lire) { |
|
302 | - throw new RestException(401, 'No permission to read contacts'); |
|
303 | - } |
|
304 | - if (!DolibarrApiAccess::$user->rights->user->user->creer) { |
|
305 | - throw new RestException(401, 'No permission to create user'); |
|
306 | - } |
|
307 | - |
|
308 | - $contact = new Contact($this->db); |
|
309 | - $contact->fetch($id); |
|
310 | - if ($contact->id <= 0) { |
|
311 | - throw new RestException(404, 'Contact not found'); |
|
312 | - } |
|
313 | - |
|
314 | - if (!DolibarrApi::_checkAccessToResource('contact', $contact->id, 'socpeople&societe')) { |
|
315 | - throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); |
|
316 | - } |
|
317 | - |
|
318 | - // Check mandatory fields |
|
319 | - $login = $request_data["login"]; |
|
320 | - $password = $request_data["password"]; |
|
321 | - $useraccount = new User($this->db); |
|
322 | - $result = $useraccount->create_from_contact($contact,$login,$password); |
|
323 | - if ($result <= 0) { |
|
324 | - throw new RestException(500, "User not created"); |
|
325 | - } |
|
326 | - // password parameter not used in create_from_contact |
|
327 | - $useraccount->setPassword($useraccount,$password); |
|
328 | - |
|
329 | - return $result; |
|
330 | - } |
|
292 | + //if (!DolibarrApiAccess::$user->rights->user->user->creer) { |
|
293 | + //throw new RestException(401); |
|
294 | + //} |
|
295 | + |
|
296 | + if (!isset($request_data["login"])) |
|
297 | + throw new RestException(400, "login field missing"); |
|
298 | + if (!isset($request_data["password"])) |
|
299 | + throw new RestException(400, "password field missing"); |
|
300 | + |
|
301 | + if (!DolibarrApiAccess::$user->rights->societe->contact->lire) { |
|
302 | + throw new RestException(401, 'No permission to read contacts'); |
|
303 | + } |
|
304 | + if (!DolibarrApiAccess::$user->rights->user->user->creer) { |
|
305 | + throw new RestException(401, 'No permission to create user'); |
|
306 | + } |
|
307 | + |
|
308 | + $contact = new Contact($this->db); |
|
309 | + $contact->fetch($id); |
|
310 | + if ($contact->id <= 0) { |
|
311 | + throw new RestException(404, 'Contact not found'); |
|
312 | + } |
|
313 | + |
|
314 | + if (!DolibarrApi::_checkAccessToResource('contact', $contact->id, 'socpeople&societe')) { |
|
315 | + throw new RestException(401, 'Access not allowed for login ' . DolibarrApiAccess::$user->login); |
|
316 | + } |
|
317 | + |
|
318 | + // Check mandatory fields |
|
319 | + $login = $request_data["login"]; |
|
320 | + $password = $request_data["password"]; |
|
321 | + $useraccount = new User($this->db); |
|
322 | + $result = $useraccount->create_from_contact($contact,$login,$password); |
|
323 | + if ($result <= 0) { |
|
324 | + throw new RestException(500, "User not created"); |
|
325 | + } |
|
326 | + // password parameter not used in create_from_contact |
|
327 | + $useraccount->setPassword($useraccount,$password); |
|
328 | + |
|
329 | + return $result; |
|
330 | + } |
|
331 | 331 | |
332 | 332 | /** |
333 | 333 | * Get categories for a contact |
@@ -342,25 +342,25 @@ discard block |
||
342 | 342 | * |
343 | 343 | * @url GET {id}/categories |
344 | 344 | */ |
345 | - function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) |
|
346 | - { |
|
347 | - if (! DolibarrApiAccess::$user->rights->categorie->lire) { |
|
348 | - throw new RestException(401); |
|
349 | - } |
|
345 | + function getCategories($id, $sortfield = "s.rowid", $sortorder = 'ASC', $limit = 0, $page = 0) |
|
346 | + { |
|
347 | + if (! DolibarrApiAccess::$user->rights->categorie->lire) { |
|
348 | + throw new RestException(401); |
|
349 | + } |
|
350 | 350 | |
351 | - $categories = new Categorie($this->db); |
|
351 | + $categories = new Categorie($this->db); |
|
352 | 352 | |
353 | - $result = $categories->getListForItem($id, 'contact', $sortfield, $sortorder, $limit, $page); |
|
353 | + $result = $categories->getListForItem($id, 'contact', $sortfield, $sortorder, $limit, $page); |
|
354 | 354 | |
355 | - if (empty($result)) { |
|
356 | - throw new RestException(404, 'No category found'); |
|
357 | - } |
|
355 | + if (empty($result)) { |
|
356 | + throw new RestException(404, 'No category found'); |
|
357 | + } |
|
358 | 358 | |
359 | - if ($result < 0) { |
|
360 | - throw new RestException(503, 'Error when retrieve category list : '.$categories->error); |
|
361 | - } |
|
359 | + if ($result < 0) { |
|
360 | + throw new RestException(503, 'Error when retrieve category list : '.$categories->error); |
|
361 | + } |
|
362 | 362 | |
363 | - return $result; |
|
363 | + return $result; |
|
364 | 364 | } |
365 | 365 | |
366 | 366 | |
@@ -373,38 +373,38 @@ discard block |
||
373 | 373 | function _cleanObjectDatas($object) |
374 | 374 | { |
375 | 375 | |
376 | - $object = parent::_cleanObjectDatas($object); |
|
376 | + $object = parent::_cleanObjectDatas($object); |
|
377 | 377 | |
378 | - unset($object->total_ht); |
|
379 | - unset($object->total_tva); |
|
380 | - unset($object->total_localtax1); |
|
381 | - unset($object->total_localtax2); |
|
382 | - unset($object->total_ttc); |
|
378 | + unset($object->total_ht); |
|
379 | + unset($object->total_tva); |
|
380 | + unset($object->total_localtax1); |
|
381 | + unset($object->total_localtax2); |
|
382 | + unset($object->total_ttc); |
|
383 | 383 | |
384 | - unset($object->note); |
|
385 | - unset($object->lines); |
|
386 | - unset($object->thirdparty); |
|
384 | + unset($object->note); |
|
385 | + unset($object->lines); |
|
386 | + unset($object->thirdparty); |
|
387 | 387 | |
388 | - return $object; |
|
388 | + return $object; |
|
389 | 389 | } |
390 | 390 | |
391 | - /** |
|
392 | - * Validate fields before create or update object |
|
391 | + /** |
|
392 | + * Validate fields before create or update object |
|
393 | 393 | * |
394 | - * @param array|null $data Data to validate |
|
395 | - * @return array |
|
396 | - * @throws RestException |
|
397 | - */ |
|
394 | + * @param array|null $data Data to validate |
|
395 | + * @return array |
|
396 | + * @throws RestException |
|
397 | + */ |
|
398 | 398 | function _validate($data) |
399 | 399 | { |
400 | - $contact = array(); |
|
401 | - foreach (Contacts::$FIELDS as $field) |
|
402 | - { |
|
403 | - if (!isset($data[$field])) |
|
404 | - throw new RestException(400, "$field field missing"); |
|
405 | - $contact[$field] = $data[$field]; |
|
406 | - } |
|
407 | - |
|
408 | - return $contact; |
|
409 | - } |
|
400 | + $contact = array(); |
|
401 | + foreach (Contacts::$FIELDS as $field) |
|
402 | + { |
|
403 | + if (!isset($data[$field])) |
|
404 | + throw new RestException(400, "$field field missing"); |
|
405 | + $contact[$field] = $data[$field]; |
|
406 | + } |
|
407 | + |
|
408 | + return $contact; |
|
409 | + } |
|
410 | 410 | } |
@@ -35,320 +35,320 @@ discard block |
||
35 | 35 | */ |
36 | 36 | class SocieteAccount extends CommonObject |
37 | 37 | { |
38 | - /** |
|
39 | - * @var string ID to identify managed object |
|
40 | - */ |
|
41 | - public $element = 'societeaccount'; |
|
42 | - |
|
43 | - /** |
|
44 | - * @var string Name of table without prefix where object is stored |
|
45 | - */ |
|
46 | - public $table_element = 'societe_account'; |
|
47 | - |
|
48 | - /** |
|
49 | - * @var array Does societeaccount support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe |
|
50 | - */ |
|
51 | - public $ismultientitymanaged = 0; |
|
52 | - |
|
53 | - /** |
|
54 | - * @var string String with name of icon for societeaccount. Must be the part after the 'object_' into object_myobject.png |
|
55 | - */ |
|
56 | - public $picto = 'lock'; |
|
57 | - |
|
58 | - |
|
59 | - /** |
|
60 | - * 'type' if the field format. |
|
61 | - * 'label' the translation key. |
|
62 | - * 'enabled' is a condition when the field must be managed. |
|
63 | - * '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) |
|
64 | - * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0). |
|
65 | - * 'index' if we want an index in database. |
|
66 | - * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...). |
|
67 | - * 'position' is the sort order of field. |
|
68 | - * 'searchall' is 1 if we want to search in this field when making a search from the quick search button. |
|
69 | - * '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). |
|
70 | - * 'help' is a string visible as a tooltip on field |
|
71 | - * 'comment' is not used. You can store here any text of your choice. It is not used by application. |
|
72 | - * 'default' is a default value for creation (can still be replaced by the global setup of default values) |
|
73 | - * 'showoncombobox' if field must be shown into the label of combobox |
|
74 | - */ |
|
75 | - |
|
76 | - // BEGIN MODULEBUILDER PROPERTIES |
|
77 | - /** |
|
78 | - * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. |
|
79 | - */ |
|
80 | - public $fields=array( |
|
81 | - 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'visible'=>-2, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>'Id',), |
|
82 | - 'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>0, 'enabled'=>1, 'position'=>5, 'default'=>1), |
|
83 | - 'key_account' => array('type'=>'varchar(128)', 'label'=>'KeyAccount', 'visible'=>-1, 'enabled'=>1, 'position'=>10, 'notnull'=>1, 'index'=>1, 'searchall'=>1, 'comment'=>'Key account',), |
|
84 | - 'login' => array('type'=>'varchar(64)', 'label'=>'Login', 'visible'=>1, 'enabled'=>1, 'position'=>10), |
|
85 | - 'pass_encoding' => array('type'=>'varchar(24)', 'label'=>'PassEncoding', 'visible'=>0, 'enabled'=>1, 'position'=>30), |
|
86 | - 'pass_crypted' => array('type'=>'varchar(128)', 'label'=>'Password', 'visible'=>1, 'enabled'=>1, 'position'=>31, 'notnull'=>1), |
|
87 | - 'pass_temp' => array('type'=>'varchar(128)', 'label'=>'Temp', 'visible'=>0, 'enabled'=>0, 'position'=>32, 'notnull'=>-1,), |
|
88 | - 'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'visible'=>1, 'enabled'=>1, 'position'=>40, 'notnull'=>-1, 'index'=>1), |
|
89 | - 'site' => array('type'=>'varchar(128)', 'label'=>'Site', 'visible'=>-1, 'enabled'=>1, 'position'=>41), |
|
90 | - 'fk_website' => array('type'=>'integer:Website:website/class/website.class.php', 'label'=>'WebSite', 'visible'=>1, 'enabled'=>1, 'position'=>42, 'notnull'=>-1, 'index'=>1), |
|
91 | - 'date_last_login' => array('type'=>'datetime', 'label'=>'LastConnexion', 'visible'=>2, 'enabled'=>1, 'position'=>50, 'notnull'=>0,), |
|
92 | - 'date_previous_login' => array('type'=>'datetime', 'label'=>'PreviousConnexion', 'visible'=>2, 'enabled'=>1, 'position'=>51, 'notnull'=>0,), |
|
93 | - //'note_public' => array('type'=>'text', 'label'=>'NotePublic', 'visible'=>-1, 'enabled'=>1, 'position'=>45, 'notnull'=>-1,), |
|
94 | - 'note_private' => array('type'=>'text', 'label'=>'NotePrivate', 'visible'=>-1, 'enabled'=>1, 'position'=>46, 'notnull'=>-1,), |
|
95 | - 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1,), |
|
96 | - 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1,), |
|
97 | - 'fk_user_creat' => array('type'=>'integer', 'label'=>'UserAuthor', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1,), |
|
98 | - 'fk_user_modif' => array('type'=>'integer', 'label'=>'UserModif', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>-1,), |
|
99 | - 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'visible'=>-2, 'enabled'=>1, 'position'=>1000, 'notnull'=>-1, 'index'=>1,), |
|
100 | - 'status' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>1000, 'notnull'=>1, 'index'=>1, 'default'=>1, 'arrayofkeyval'=>array('1'=>'Active','0'=>'Disabled')), |
|
101 | - ); |
|
102 | - |
|
103 | - /** |
|
104 | - * @var int ID |
|
105 | - */ |
|
106 | - public $rowid; |
|
107 | - |
|
108 | - /** |
|
109 | - * @var int Entity |
|
110 | - */ |
|
111 | - public $entity; |
|
112 | - |
|
113 | - public $key_account; |
|
114 | - public $login; |
|
115 | - public $pass_encoding; |
|
116 | - public $pass_crypted; |
|
117 | - public $pass_temp; |
|
118 | - |
|
119 | - /** |
|
120 | - * @var int Thirdparty ID |
|
121 | - */ |
|
38 | + /** |
|
39 | + * @var string ID to identify managed object |
|
40 | + */ |
|
41 | + public $element = 'societeaccount'; |
|
42 | + |
|
43 | + /** |
|
44 | + * @var string Name of table without prefix where object is stored |
|
45 | + */ |
|
46 | + public $table_element = 'societe_account'; |
|
47 | + |
|
48 | + /** |
|
49 | + * @var array Does societeaccount support multicompany module ? 0=No test on entity, 1=Test with field entity, 2=Test with link by societe |
|
50 | + */ |
|
51 | + public $ismultientitymanaged = 0; |
|
52 | + |
|
53 | + /** |
|
54 | + * @var string String with name of icon for societeaccount. Must be the part after the 'object_' into object_myobject.png |
|
55 | + */ |
|
56 | + public $picto = 'lock'; |
|
57 | + |
|
58 | + |
|
59 | + /** |
|
60 | + * 'type' if the field format. |
|
61 | + * 'label' the translation key. |
|
62 | + * 'enabled' is a condition when the field must be managed. |
|
63 | + * '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) |
|
64 | + * 'notnull' is set to 1 if not null in database. Set to -1 if we must set data to null if empty ('' or 0). |
|
65 | + * 'index' if we want an index in database. |
|
66 | + * 'foreignkey'=>'tablename.field' if the field is a foreign key (it is recommanded to name the field fk_...). |
|
67 | + * 'position' is the sort order of field. |
|
68 | + * 'searchall' is 1 if we want to search in this field when making a search from the quick search button. |
|
69 | + * '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). |
|
70 | + * 'help' is a string visible as a tooltip on field |
|
71 | + * 'comment' is not used. You can store here any text of your choice. It is not used by application. |
|
72 | + * 'default' is a default value for creation (can still be replaced by the global setup of default values) |
|
73 | + * 'showoncombobox' if field must be shown into the label of combobox |
|
74 | + */ |
|
75 | + |
|
76 | + // BEGIN MODULEBUILDER PROPERTIES |
|
77 | + /** |
|
78 | + * @var array Array with all fields and their property. Do not use it as a static var. It may be modified by constructor. |
|
79 | + */ |
|
80 | + public $fields=array( |
|
81 | + 'rowid' => array('type'=>'integer', 'label'=>'TechnicalID', 'visible'=>-2, 'enabled'=>1, 'position'=>1, 'notnull'=>1, 'index'=>1, 'comment'=>'Id',), |
|
82 | + 'entity' => array('type'=>'integer', 'label'=>'Entity', 'visible'=>0, 'enabled'=>1, 'position'=>5, 'default'=>1), |
|
83 | + 'key_account' => array('type'=>'varchar(128)', 'label'=>'KeyAccount', 'visible'=>-1, 'enabled'=>1, 'position'=>10, 'notnull'=>1, 'index'=>1, 'searchall'=>1, 'comment'=>'Key account',), |
|
84 | + 'login' => array('type'=>'varchar(64)', 'label'=>'Login', 'visible'=>1, 'enabled'=>1, 'position'=>10), |
|
85 | + 'pass_encoding' => array('type'=>'varchar(24)', 'label'=>'PassEncoding', 'visible'=>0, 'enabled'=>1, 'position'=>30), |
|
86 | + 'pass_crypted' => array('type'=>'varchar(128)', 'label'=>'Password', 'visible'=>1, 'enabled'=>1, 'position'=>31, 'notnull'=>1), |
|
87 | + 'pass_temp' => array('type'=>'varchar(128)', 'label'=>'Temp', 'visible'=>0, 'enabled'=>0, 'position'=>32, 'notnull'=>-1,), |
|
88 | + 'fk_soc' => array('type'=>'integer:Societe:societe/class/societe.class.php', 'label'=>'ThirdParty', 'visible'=>1, 'enabled'=>1, 'position'=>40, 'notnull'=>-1, 'index'=>1), |
|
89 | + 'site' => array('type'=>'varchar(128)', 'label'=>'Site', 'visible'=>-1, 'enabled'=>1, 'position'=>41), |
|
90 | + 'fk_website' => array('type'=>'integer:Website:website/class/website.class.php', 'label'=>'WebSite', 'visible'=>1, 'enabled'=>1, 'position'=>42, 'notnull'=>-1, 'index'=>1), |
|
91 | + 'date_last_login' => array('type'=>'datetime', 'label'=>'LastConnexion', 'visible'=>2, 'enabled'=>1, 'position'=>50, 'notnull'=>0,), |
|
92 | + 'date_previous_login' => array('type'=>'datetime', 'label'=>'PreviousConnexion', 'visible'=>2, 'enabled'=>1, 'position'=>51, 'notnull'=>0,), |
|
93 | + //'note_public' => array('type'=>'text', 'label'=>'NotePublic', 'visible'=>-1, 'enabled'=>1, 'position'=>45, 'notnull'=>-1,), |
|
94 | + 'note_private' => array('type'=>'text', 'label'=>'NotePrivate', 'visible'=>-1, 'enabled'=>1, 'position'=>46, 'notnull'=>-1,), |
|
95 | + 'date_creation' => array('type'=>'datetime', 'label'=>'DateCreation', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1,), |
|
96 | + 'tms' => array('type'=>'timestamp', 'label'=>'DateModification', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1,), |
|
97 | + 'fk_user_creat' => array('type'=>'integer', 'label'=>'UserAuthor', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>1,), |
|
98 | + 'fk_user_modif' => array('type'=>'integer', 'label'=>'UserModif', 'visible'=>-2, 'enabled'=>1, 'position'=>500, 'notnull'=>-1,), |
|
99 | + 'import_key' => array('type'=>'varchar(14)', 'label'=>'ImportId', 'visible'=>-2, 'enabled'=>1, 'position'=>1000, 'notnull'=>-1, 'index'=>1,), |
|
100 | + 'status' => array('type'=>'integer', 'label'=>'Status', 'visible'=>1, 'enabled'=>1, 'position'=>1000, 'notnull'=>1, 'index'=>1, 'default'=>1, 'arrayofkeyval'=>array('1'=>'Active','0'=>'Disabled')), |
|
101 | + ); |
|
102 | + |
|
103 | + /** |
|
104 | + * @var int ID |
|
105 | + */ |
|
106 | + public $rowid; |
|
107 | + |
|
108 | + /** |
|
109 | + * @var int Entity |
|
110 | + */ |
|
111 | + public $entity; |
|
112 | + |
|
113 | + public $key_account; |
|
114 | + public $login; |
|
115 | + public $pass_encoding; |
|
116 | + public $pass_crypted; |
|
117 | + public $pass_temp; |
|
118 | + |
|
119 | + /** |
|
120 | + * @var int Thirdparty ID |
|
121 | + */ |
|
122 | 122 | public $fk_soc; |
123 | 123 | |
124 | - public $site; |
|
125 | - public $date_last_login; |
|
126 | - public $date_previous_login; |
|
127 | - public $note_private; |
|
128 | - public $date_creation; |
|
129 | - public $tms; |
|
124 | + public $site; |
|
125 | + public $date_last_login; |
|
126 | + public $date_previous_login; |
|
127 | + public $note_private; |
|
128 | + public $date_creation; |
|
129 | + public $tms; |
|
130 | 130 | |
131 | - /** |
|
131 | + /** |
|
132 | 132 | * @var int ID |
133 | 133 | */ |
134 | - public $fk_user_creat; |
|
134 | + public $fk_user_creat; |
|
135 | 135 | |
136 | - /** |
|
136 | + /** |
|
137 | 137 | * @var int ID |
138 | 138 | */ |
139 | - public $fk_user_modif; |
|
140 | - |
|
141 | - public $import_key; |
|
142 | - |
|
143 | - /** |
|
144 | - * @var int Status |
|
145 | - */ |
|
146 | - public $status; |
|
147 | - |
|
148 | - // END MODULEBUILDER PROPERTIES |
|
149 | - |
|
150 | - |
|
151 | - |
|
152 | - |
|
153 | - // If this object has a subtable with lines |
|
154 | - |
|
155 | - /** |
|
156 | - * @var int Name of subtable line |
|
157 | - */ |
|
158 | - //public $table_element_line = 'societe_accountdet'; |
|
159 | - /** |
|
160 | - * @var int Field with ID of parent key if this field has a parent |
|
161 | - */ |
|
162 | - //public $fk_element = 'fk_societe_account'; |
|
163 | - /** |
|
164 | - * @var int Name of subtable class that manage subtable lines |
|
165 | - */ |
|
166 | - //public $class_element_line = 'societeAccountline'; |
|
167 | - /** |
|
168 | - * @var array Array of child tables (child tables to delete before deleting a record) |
|
169 | - */ |
|
170 | - //protected $childtables=array('societe_accountdet'); |
|
171 | - /** |
|
172 | - * @var societeAccountLine[] Array of subtable lines |
|
173 | - */ |
|
174 | - //public $lines = array(); |
|
175 | - |
|
176 | - |
|
177 | - |
|
178 | - /** |
|
179 | - * Constructor |
|
180 | - * |
|
181 | - * @param DoliDb $db Database handler |
|
182 | - */ |
|
183 | - public function __construct(DoliDB $db) |
|
184 | - { |
|
185 | - global $conf; |
|
186 | - |
|
187 | - $this->db = $db; |
|
188 | - |
|
189 | - if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->fields['rowid']['visible']=0; |
|
190 | - } |
|
191 | - |
|
192 | - /** |
|
193 | - * Create object into database |
|
194 | - * |
|
195 | - * @param User $user User that creates |
|
196 | - * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
197 | - * @return int <0 if KO, Id of created object if OK |
|
198 | - */ |
|
199 | - public function create(User $user, $notrigger = false) |
|
200 | - { |
|
201 | - return $this->createCommon($user, $notrigger); |
|
202 | - } |
|
203 | - |
|
204 | - /** |
|
205 | - * Clone and object into another one |
|
206 | - * |
|
207 | - * @param User $user User that creates |
|
208 | - * @param int $fromid Id of object to clone |
|
209 | - * @return mixed New object created, <0 if KO |
|
210 | - */ |
|
211 | - public function createFromClone(User $user, $fromid) |
|
212 | - { |
|
213 | - global $hookmanager, $langs; |
|
214 | - $error = 0; |
|
215 | - |
|
216 | - dol_syslog(__METHOD__, LOG_DEBUG); |
|
217 | - |
|
218 | - $object = new self($this->db); |
|
219 | - |
|
220 | - $this->db->begin(); |
|
221 | - |
|
222 | - // Load source object |
|
223 | - $object->fetchCommon($fromid); |
|
224 | - // Reset some properties |
|
225 | - unset($object->id); |
|
226 | - unset($object->fk_user_creat); |
|
227 | - unset($object->import_key); |
|
228 | - |
|
229 | - // Clear fields |
|
230 | - $object->ref = "copy_of_".$object->ref; |
|
231 | - $object->title = $langs->trans("CopyOf")." ".$object->title; |
|
232 | - // ... |
|
233 | - |
|
234 | - // Create clone |
|
235 | - $object->context['createfromclone'] = 'createfromclone'; |
|
236 | - $result = $object->createCommon($user); |
|
237 | - if ($result < 0) { |
|
238 | - $error++; |
|
239 | - $this->error = $object->error; |
|
240 | - $this->errors = $object->errors; |
|
241 | - } |
|
242 | - |
|
243 | - // End |
|
244 | - if (!$error) { |
|
245 | - $this->db->commit(); |
|
246 | - return $object; |
|
247 | - } else { |
|
248 | - $this->db->rollback(); |
|
249 | - return -1; |
|
250 | - } |
|
251 | - } |
|
252 | - |
|
253 | - /** |
|
254 | - * Load object in memory from the database |
|
255 | - * |
|
256 | - * @param int $id Id object |
|
257 | - * @param string $ref Ref |
|
258 | - * @return int <0 if KO, 0 if not found, >0 if OK |
|
259 | - */ |
|
260 | - public function fetch($id, $ref = null) |
|
261 | - { |
|
262 | - $result = $this->fetchCommon($id, $ref); |
|
263 | - if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines(); |
|
264 | - return $result; |
|
265 | - } |
|
266 | - |
|
267 | - /** |
|
268 | - * Load object lines in memory from the database |
|
269 | - * |
|
270 | - * @return int <0 if KO, 0 if not found, >0 if OK |
|
271 | - */ |
|
272 | - public function fetchLines() |
|
273 | - { |
|
274 | - $this->lines=array(); |
|
275 | - |
|
276 | - // Load lines with object societeAccountLine |
|
277 | - |
|
278 | - return count($this->lines)?1:0; |
|
279 | - } |
|
280 | - |
|
281 | - /** |
|
282 | - * Try to find the external customer id of a thirdparty for an another site/system. |
|
283 | - * |
|
284 | - * @param int $id Id of third party |
|
285 | - * @param string $site Site (example: 'stripe', '...') |
|
286 | - * @param int $status Status (0=test, 1=live) |
|
287 | - * @return string Stripe customer ref 'cu_xxxxxxxxxxxxx' or '' |
|
288 | - */ |
|
289 | - public function getCustomerAccount($id, $site, $status=0) |
|
290 | - { |
|
291 | - $sql = "SELECT sa.key_account as key_account, sa.entity"; |
|
292 | - $sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa"; |
|
293 | - $sql.= " WHERE sa.fk_soc = " . $id; |
|
294 | - $sql.= " AND sa.entity IN (".getEntity('societe').")"; |
|
295 | - $sql.= " AND sa.site = '".$this->db->escape($site)."' AND sa.status = ".((int) $status); |
|
296 | - $sql.= " AND key_account IS NOT NULL AND key_account <> ''"; |
|
297 | - //$sql.= " ORDER BY sa.key_account DESC"; |
|
298 | - |
|
299 | - dol_syslog(get_class($this) . "::getCustomerAccount Try to find the first system customer id for ".$site." of thirdparty id=".$id." (exemple: cus_.... for stripe)", LOG_DEBUG); |
|
300 | - $result = $this->db->query($sql); |
|
301 | - if ($result) { |
|
302 | - if ($this->db->num_rows($result)) { |
|
303 | - $obj = $this->db->fetch_object($result); |
|
304 | - $key = $obj->key_account; |
|
305 | - } else { |
|
306 | - $key = ''; |
|
307 | - } |
|
308 | - } else { |
|
309 | - $key = ''; |
|
310 | - } |
|
311 | - |
|
312 | - return $key; |
|
313 | - } |
|
314 | - |
|
315 | - /** |
|
316 | - * Update object into database |
|
317 | - * |
|
318 | - * @param User $user User that modifies |
|
319 | - * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
320 | - * @return int <0 if KO, >0 if OK |
|
321 | - */ |
|
322 | - public function update(User $user, $notrigger = false) |
|
323 | - { |
|
324 | - return $this->updateCommon($user, $notrigger); |
|
325 | - } |
|
326 | - |
|
327 | - /** |
|
328 | - * Delete object in database |
|
329 | - * |
|
330 | - * @param User $user User that deletes |
|
331 | - * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
332 | - * @return int <0 if KO, >0 if OK |
|
333 | - */ |
|
334 | - public function delete(User $user, $notrigger = false) |
|
335 | - { |
|
336 | - return $this->deleteCommon($user, $notrigger); |
|
337 | - } |
|
338 | - |
|
339 | - /** |
|
340 | - * Return a link to the object card (with optionaly the picto) |
|
341 | - * |
|
342 | - * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto) |
|
343 | - * @param string $option On what the link point to ('nolink', ...) |
|
139 | + public $fk_user_modif; |
|
140 | + |
|
141 | + public $import_key; |
|
142 | + |
|
143 | + /** |
|
144 | + * @var int Status |
|
145 | + */ |
|
146 | + public $status; |
|
147 | + |
|
148 | + // END MODULEBUILDER PROPERTIES |
|
149 | + |
|
150 | + |
|
151 | + |
|
152 | + |
|
153 | + // If this object has a subtable with lines |
|
154 | + |
|
155 | + /** |
|
156 | + * @var int Name of subtable line |
|
157 | + */ |
|
158 | + //public $table_element_line = 'societe_accountdet'; |
|
159 | + /** |
|
160 | + * @var int Field with ID of parent key if this field has a parent |
|
161 | + */ |
|
162 | + //public $fk_element = 'fk_societe_account'; |
|
163 | + /** |
|
164 | + * @var int Name of subtable class that manage subtable lines |
|
165 | + */ |
|
166 | + //public $class_element_line = 'societeAccountline'; |
|
167 | + /** |
|
168 | + * @var array Array of child tables (child tables to delete before deleting a record) |
|
169 | + */ |
|
170 | + //protected $childtables=array('societe_accountdet'); |
|
171 | + /** |
|
172 | + * @var societeAccountLine[] Array of subtable lines |
|
173 | + */ |
|
174 | + //public $lines = array(); |
|
175 | + |
|
176 | + |
|
177 | + |
|
178 | + /** |
|
179 | + * Constructor |
|
180 | + * |
|
181 | + * @param DoliDb $db Database handler |
|
182 | + */ |
|
183 | + public function __construct(DoliDB $db) |
|
184 | + { |
|
185 | + global $conf; |
|
186 | + |
|
187 | + $this->db = $db; |
|
188 | + |
|
189 | + if (empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) $this->fields['rowid']['visible']=0; |
|
190 | + } |
|
191 | + |
|
192 | + /** |
|
193 | + * Create object into database |
|
194 | + * |
|
195 | + * @param User $user User that creates |
|
196 | + * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
197 | + * @return int <0 if KO, Id of created object if OK |
|
198 | + */ |
|
199 | + public function create(User $user, $notrigger = false) |
|
200 | + { |
|
201 | + return $this->createCommon($user, $notrigger); |
|
202 | + } |
|
203 | + |
|
204 | + /** |
|
205 | + * Clone and object into another one |
|
206 | + * |
|
207 | + * @param User $user User that creates |
|
208 | + * @param int $fromid Id of object to clone |
|
209 | + * @return mixed New object created, <0 if KO |
|
210 | + */ |
|
211 | + public function createFromClone(User $user, $fromid) |
|
212 | + { |
|
213 | + global $hookmanager, $langs; |
|
214 | + $error = 0; |
|
215 | + |
|
216 | + dol_syslog(__METHOD__, LOG_DEBUG); |
|
217 | + |
|
218 | + $object = new self($this->db); |
|
219 | + |
|
220 | + $this->db->begin(); |
|
221 | + |
|
222 | + // Load source object |
|
223 | + $object->fetchCommon($fromid); |
|
224 | + // Reset some properties |
|
225 | + unset($object->id); |
|
226 | + unset($object->fk_user_creat); |
|
227 | + unset($object->import_key); |
|
228 | + |
|
229 | + // Clear fields |
|
230 | + $object->ref = "copy_of_".$object->ref; |
|
231 | + $object->title = $langs->trans("CopyOf")." ".$object->title; |
|
232 | + // ... |
|
233 | + |
|
234 | + // Create clone |
|
235 | + $object->context['createfromclone'] = 'createfromclone'; |
|
236 | + $result = $object->createCommon($user); |
|
237 | + if ($result < 0) { |
|
238 | + $error++; |
|
239 | + $this->error = $object->error; |
|
240 | + $this->errors = $object->errors; |
|
241 | + } |
|
242 | + |
|
243 | + // End |
|
244 | + if (!$error) { |
|
245 | + $this->db->commit(); |
|
246 | + return $object; |
|
247 | + } else { |
|
248 | + $this->db->rollback(); |
|
249 | + return -1; |
|
250 | + } |
|
251 | + } |
|
252 | + |
|
253 | + /** |
|
254 | + * Load object in memory from the database |
|
255 | + * |
|
256 | + * @param int $id Id object |
|
257 | + * @param string $ref Ref |
|
258 | + * @return int <0 if KO, 0 if not found, >0 if OK |
|
259 | + */ |
|
260 | + public function fetch($id, $ref = null) |
|
261 | + { |
|
262 | + $result = $this->fetchCommon($id, $ref); |
|
263 | + if ($result > 0 && ! empty($this->table_element_line)) $this->fetchLines(); |
|
264 | + return $result; |
|
265 | + } |
|
266 | + |
|
267 | + /** |
|
268 | + * Load object lines in memory from the database |
|
269 | + * |
|
270 | + * @return int <0 if KO, 0 if not found, >0 if OK |
|
271 | + */ |
|
272 | + public function fetchLines() |
|
273 | + { |
|
274 | + $this->lines=array(); |
|
275 | + |
|
276 | + // Load lines with object societeAccountLine |
|
277 | + |
|
278 | + return count($this->lines)?1:0; |
|
279 | + } |
|
280 | + |
|
281 | + /** |
|
282 | + * Try to find the external customer id of a thirdparty for an another site/system. |
|
283 | + * |
|
284 | + * @param int $id Id of third party |
|
285 | + * @param string $site Site (example: 'stripe', '...') |
|
286 | + * @param int $status Status (0=test, 1=live) |
|
287 | + * @return string Stripe customer ref 'cu_xxxxxxxxxxxxx' or '' |
|
288 | + */ |
|
289 | + public function getCustomerAccount($id, $site, $status=0) |
|
290 | + { |
|
291 | + $sql = "SELECT sa.key_account as key_account, sa.entity"; |
|
292 | + $sql.= " FROM " . MAIN_DB_PREFIX . "societe_account as sa"; |
|
293 | + $sql.= " WHERE sa.fk_soc = " . $id; |
|
294 | + $sql.= " AND sa.entity IN (".getEntity('societe').")"; |
|
295 | + $sql.= " AND sa.site = '".$this->db->escape($site)."' AND sa.status = ".((int) $status); |
|
296 | + $sql.= " AND key_account IS NOT NULL AND key_account <> ''"; |
|
297 | + //$sql.= " ORDER BY sa.key_account DESC"; |
|
298 | + |
|
299 | + dol_syslog(get_class($this) . "::getCustomerAccount Try to find the first system customer id for ".$site." of thirdparty id=".$id." (exemple: cus_.... for stripe)", LOG_DEBUG); |
|
300 | + $result = $this->db->query($sql); |
|
301 | + if ($result) { |
|
302 | + if ($this->db->num_rows($result)) { |
|
303 | + $obj = $this->db->fetch_object($result); |
|
304 | + $key = $obj->key_account; |
|
305 | + } else { |
|
306 | + $key = ''; |
|
307 | + } |
|
308 | + } else { |
|
309 | + $key = ''; |
|
310 | + } |
|
311 | + |
|
312 | + return $key; |
|
313 | + } |
|
314 | + |
|
315 | + /** |
|
316 | + * Update object into database |
|
317 | + * |
|
318 | + * @param User $user User that modifies |
|
319 | + * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
320 | + * @return int <0 if KO, >0 if OK |
|
321 | + */ |
|
322 | + public function update(User $user, $notrigger = false) |
|
323 | + { |
|
324 | + return $this->updateCommon($user, $notrigger); |
|
325 | + } |
|
326 | + |
|
327 | + /** |
|
328 | + * Delete object in database |
|
329 | + * |
|
330 | + * @param User $user User that deletes |
|
331 | + * @param bool $notrigger false=launch triggers after, true=disable triggers |
|
332 | + * @return int <0 if KO, >0 if OK |
|
333 | + */ |
|
334 | + public function delete(User $user, $notrigger = false) |
|
335 | + { |
|
336 | + return $this->deleteCommon($user, $notrigger); |
|
337 | + } |
|
338 | + |
|
339 | + /** |
|
340 | + * Return a link to the object card (with optionaly the picto) |
|
341 | + * |
|
342 | + * @param int $withpicto Include picto in link (0=No picto, 1=Include picto into link, 2=Only picto) |
|
343 | + * @param string $option On what the link point to ('nolink', ...) |
|
344 | 344 | * @param int $notooltip 1=Disable tooltip |
345 | 345 | * @param string $morecss Add more css on link |
346 | 346 | * @param int $save_lastsearch_value -1=Auto, 0=No save of lastsearch_values when clicking, 1=Save lastsearch_values whenclicking |
347 | - * @return string String with URL |
|
348 | - */ |
|
349 | - function getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1) |
|
350 | - { |
|
351 | - global $db, $conf, $langs; |
|
347 | + * @return string String with URL |
|
348 | + */ |
|
349 | + function getNomUrl($withpicto=0, $option='', $notooltip=0, $morecss='', $save_lastsearch_value=-1) |
|
350 | + { |
|
351 | + global $db, $conf, $langs; |
|
352 | 352 | global $dolibarr_main_authentication, $dolibarr_main_demo; |
353 | 353 | global $menumanager; |
354 | 354 | |
@@ -368,10 +368,10 @@ discard block |
||
368 | 368 | |
369 | 369 | if ($option != 'nolink') |
370 | 370 | { |
371 | - // Add param to save lastsearch_values or not |
|
372 | - $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0); |
|
373 | - if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1; |
|
374 | - if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1'; |
|
371 | + // Add param to save lastsearch_values or not |
|
372 | + $add_save_lastsearch_values=($save_lastsearch_value == 1 ? 1 : 0); |
|
373 | + if ($save_lastsearch_value == -1 && preg_match('/list\.php/',$_SERVER["PHP_SELF"])) $add_save_lastsearch_values=1; |
|
374 | + if ($add_save_lastsearch_values) $url.='&save_lastsearch_values=1'; |
|
375 | 375 | } |
376 | 376 | |
377 | 377 | $linkclose=''; |
@@ -387,152 +387,152 @@ discard block |
||
387 | 387 | } |
388 | 388 | else $linkclose = ($morecss?' class="'.$morecss.'"':''); |
389 | 389 | |
390 | - $linkstart = '<a href="'.$url.'"'; |
|
391 | - $linkstart.=$linkclose.'>'; |
|
392 | - $linkend='</a>'; |
|
393 | - |
|
394 | - $result .= $linkstart; |
|
395 | - 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); |
|
396 | - if ($withpicto != 2) $result.= $this->ref; |
|
397 | - $result .= $linkend; |
|
398 | - |
|
399 | - return $result; |
|
400 | - } |
|
401 | - |
|
402 | - /** |
|
403 | - * Return link to download file from a direct external access |
|
404 | - * |
|
405 | - * @param int $withpicto Add download picto into link |
|
406 | - * @return string HTML link to file |
|
407 | - */ |
|
408 | - function getDirectExternalLink($withpicto=0) |
|
409 | - { |
|
410 | - return 'todo'; |
|
411 | - } |
|
412 | - |
|
413 | - /** |
|
414 | - * Retourne le libelle du status d'un user (actif, inactif) |
|
415 | - * |
|
416 | - * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto |
|
417 | - * @return string Label of status |
|
418 | - */ |
|
419 | - function getLibStatut($mode=0) |
|
420 | - { |
|
421 | - return $this->LibStatut($this->status,$mode); |
|
422 | - } |
|
390 | + $linkstart = '<a href="'.$url.'"'; |
|
391 | + $linkstart.=$linkclose.'>'; |
|
392 | + $linkend='</a>'; |
|
393 | + |
|
394 | + $result .= $linkstart; |
|
395 | + 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); |
|
396 | + if ($withpicto != 2) $result.= $this->ref; |
|
397 | + $result .= $linkend; |
|
398 | + |
|
399 | + return $result; |
|
400 | + } |
|
401 | + |
|
402 | + /** |
|
403 | + * Return link to download file from a direct external access |
|
404 | + * |
|
405 | + * @param int $withpicto Add download picto into link |
|
406 | + * @return string HTML link to file |
|
407 | + */ |
|
408 | + function getDirectExternalLink($withpicto=0) |
|
409 | + { |
|
410 | + return 'todo'; |
|
411 | + } |
|
412 | + |
|
413 | + /** |
|
414 | + * Retourne le libelle du status d'un user (actif, inactif) |
|
415 | + * |
|
416 | + * @param int $mode 0=libelle long, 1=libelle court, 2=Picto + Libelle court, 3=Picto, 4=Picto + Libelle long, 5=Libelle court + Picto |
|
417 | + * @return string Label of status |
|
418 | + */ |
|
419 | + function getLibStatut($mode=0) |
|
420 | + { |
|
421 | + return $this->LibStatut($this->status,$mode); |
|
422 | + } |
|
423 | 423 | |
424 | 424 | // phpcs:disable PEAR.NamingConventions.ValidFunctionName.NotCamelCaps |
425 | - /** |
|
426 | - * Return the status |
|
427 | - * |
|
428 | - * @param int $status Id status |
|
429 | - * @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 |
|
430 | - * @return string Label of status |
|
431 | - */ |
|
432 | - static function LibStatut($status,$mode=0) |
|
433 | - { |
|
425 | + /** |
|
426 | + * Return the status |
|
427 | + * |
|
428 | + * @param int $status Id status |
|
429 | + * @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 |
|
430 | + * @return string Label of status |
|
431 | + */ |
|
432 | + static function LibStatut($status,$mode=0) |
|
433 | + { |
|
434 | 434 | // phpcs:enable |
435 | - global $langs; |
|
436 | - |
|
437 | - if ($mode == 0) |
|
438 | - { |
|
439 | - $prefix=''; |
|
440 | - if ($status == 1) return $langs->trans('Enabled'); |
|
441 | - elseif ($status == 0) return $langs->trans('Disabled'); |
|
442 | - } |
|
443 | - elseif ($mode == 1) |
|
444 | - { |
|
445 | - if ($status == 1) return $langs->trans('Enabled'); |
|
446 | - elseif ($status == 0) return $langs->trans('Disabled'); |
|
447 | - } |
|
448 | - elseif ($mode == 2) |
|
449 | - { |
|
450 | - if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled'); |
|
451 | - elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled'); |
|
452 | - } |
|
453 | - elseif ($mode == 3) |
|
454 | - { |
|
455 | - if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4'); |
|
456 | - elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5'); |
|
457 | - } |
|
458 | - elseif ($mode == 4) |
|
459 | - { |
|
460 | - if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled'); |
|
461 | - elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled'); |
|
462 | - } |
|
463 | - elseif ($mode == 5) |
|
464 | - { |
|
465 | - if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4'); |
|
466 | - elseif ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5'); |
|
467 | - } |
|
468 | - elseif ($mode == 6) |
|
469 | - { |
|
470 | - if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4'); |
|
471 | - elseif ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5'); |
|
472 | - } |
|
473 | - } |
|
474 | - |
|
475 | - /** |
|
476 | - * Charge les informations d'ordre info dans l'objet commande |
|
477 | - * |
|
478 | - * @param int $id Id of order |
|
479 | - * @return void |
|
480 | - */ |
|
481 | - function info($id) |
|
482 | - { |
|
483 | - $sql = 'SELECT rowid, date_creation as datec, tms as datem,'; |
|
484 | - $sql.= ' fk_user_creat, fk_user_modif'; |
|
485 | - $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; |
|
486 | - $sql.= ' WHERE t.rowid = '.$id; |
|
487 | - $result=$this->db->query($sql); |
|
488 | - if ($result) |
|
489 | - { |
|
490 | - if ($this->db->num_rows($result)) |
|
491 | - { |
|
492 | - $obj = $this->db->fetch_object($result); |
|
493 | - $this->id = $obj->rowid; |
|
494 | - if ($obj->fk_user_author) |
|
495 | - { |
|
496 | - $cuser = new User($this->db); |
|
497 | - $cuser->fetch($obj->fk_user_author); |
|
498 | - $this->user_creation = $cuser; |
|
499 | - } |
|
500 | - |
|
501 | - if ($obj->fk_user_valid) |
|
502 | - { |
|
503 | - $vuser = new User($this->db); |
|
504 | - $vuser->fetch($obj->fk_user_valid); |
|
505 | - $this->user_validation = $vuser; |
|
506 | - } |
|
507 | - |
|
508 | - if ($obj->fk_user_cloture) |
|
509 | - { |
|
510 | - $cluser = new User($this->db); |
|
511 | - $cluser->fetch($obj->fk_user_cloture); |
|
512 | - $this->user_cloture = $cluser; |
|
513 | - } |
|
514 | - |
|
515 | - $this->date_creation = $this->db->jdate($obj->datec); |
|
516 | - $this->date_modification = $this->db->jdate($obj->datem); |
|
517 | - $this->date_validation = $this->db->jdate($obj->datev); |
|
518 | - } |
|
519 | - |
|
520 | - $this->db->free($result); |
|
521 | - } |
|
522 | - else |
|
523 | - { |
|
524 | - dol_print_error($this->db); |
|
525 | - } |
|
526 | - } |
|
527 | - |
|
528 | - /** |
|
529 | - * Initialise object with example values |
|
530 | - * Id must be 0 if object instance is a specimen |
|
531 | - * |
|
532 | - * @return void |
|
533 | - */ |
|
534 | - public function initAsSpecimen() |
|
535 | - { |
|
536 | - $this->initAsSpecimenCommon(); |
|
537 | - } |
|
435 | + global $langs; |
|
436 | + |
|
437 | + if ($mode == 0) |
|
438 | + { |
|
439 | + $prefix=''; |
|
440 | + if ($status == 1) return $langs->trans('Enabled'); |
|
441 | + elseif ($status == 0) return $langs->trans('Disabled'); |
|
442 | + } |
|
443 | + elseif ($mode == 1) |
|
444 | + { |
|
445 | + if ($status == 1) return $langs->trans('Enabled'); |
|
446 | + elseif ($status == 0) return $langs->trans('Disabled'); |
|
447 | + } |
|
448 | + elseif ($mode == 2) |
|
449 | + { |
|
450 | + if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled'); |
|
451 | + elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled'); |
|
452 | + } |
|
453 | + elseif ($mode == 3) |
|
454 | + { |
|
455 | + if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4'); |
|
456 | + elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5'); |
|
457 | + } |
|
458 | + elseif ($mode == 4) |
|
459 | + { |
|
460 | + if ($status == 1) return img_picto($langs->trans('Enabled'),'statut4').' '.$langs->trans('Enabled'); |
|
461 | + elseif ($status == 0) return img_picto($langs->trans('Disabled'),'statut5').' '.$langs->trans('Disabled'); |
|
462 | + } |
|
463 | + elseif ($mode == 5) |
|
464 | + { |
|
465 | + if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4'); |
|
466 | + elseif ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5'); |
|
467 | + } |
|
468 | + elseif ($mode == 6) |
|
469 | + { |
|
470 | + if ($status == 1) return $langs->trans('Enabled').' '.img_picto($langs->trans('Enabled'),'statut4'); |
|
471 | + elseif ($status == 0) return $langs->trans('Disabled').' '.img_picto($langs->trans('Disabled'),'statut5'); |
|
472 | + } |
|
473 | + } |
|
474 | + |
|
475 | + /** |
|
476 | + * Charge les informations d'ordre info dans l'objet commande |
|
477 | + * |
|
478 | + * @param int $id Id of order |
|
479 | + * @return void |
|
480 | + */ |
|
481 | + function info($id) |
|
482 | + { |
|
483 | + $sql = 'SELECT rowid, date_creation as datec, tms as datem,'; |
|
484 | + $sql.= ' fk_user_creat, fk_user_modif'; |
|
485 | + $sql.= ' FROM '.MAIN_DB_PREFIX.$this->table_element.' as t'; |
|
486 | + $sql.= ' WHERE t.rowid = '.$id; |
|
487 | + $result=$this->db->query($sql); |
|
488 | + if ($result) |
|
489 | + { |
|
490 | + if ($this->db->num_rows($result)) |
|
491 | + { |
|
492 | + $obj = $this->db->fetch_object($result); |
|
493 | + $this->id = $obj->rowid; |
|
494 | + if ($obj->fk_user_author) |
|
495 | + { |
|
496 | + $cuser = new User($this->db); |
|
497 | + $cuser->fetch($obj->fk_user_author); |
|
498 | + $this->user_creation = $cuser; |
|
499 | + } |
|
500 | + |
|
501 | + if ($obj->fk_user_valid) |
|
502 | + { |
|
503 | + $vuser = new User($this->db); |
|
504 | + $vuser->fetch($obj->fk_user_valid); |
|
505 | + $this->user_validation = $vuser; |
|
506 | + } |
|
507 | + |
|
508 | + if ($obj->fk_user_cloture) |
|
509 | + { |
|
510 | + $cluser = new User($this->db); |
|
511 | + $cluser->fetch($obj->fk_user_cloture); |
|
512 | + $this->user_cloture = $cluser; |
|
513 | + } |
|
514 | + |
|
515 | + $this->date_creation = $this->db->jdate($obj->datec); |
|
516 | + $this->date_modification = $this->db->jdate($obj->datem); |
|
517 | + $this->date_validation = $this->db->jdate($obj->datev); |
|
518 | + } |
|
519 | + |
|
520 | + $this->db->free($result); |
|
521 | + } |
|
522 | + else |
|
523 | + { |
|
524 | + dol_print_error($this->db); |
|
525 | + } |
|
526 | + } |
|
527 | + |
|
528 | + /** |
|
529 | + * Initialise object with example values |
|
530 | + * Id must be 0 if object instance is a specimen |
|
531 | + * |
|
532 | + * @return void |
|
533 | + */ |
|
534 | + public function initAsSpecimen() |
|
535 | + { |
|
536 | + $this->initAsSpecimenCommon(); |
|
537 | + } |
|
538 | 538 | } |