[ Index ] |
|
Code source de Dolibarr 2.0.1 |
1 <?PHP 2 /* Copyright (C) 2004-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> 3 * 4 * This program is free software; you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation; either version 2 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 17 * 18 * $Id: lignetel.class.php,v 1.32 2005/12/01 09:49:09 rodolphe Exp $ 19 * $Source: /cvsroot/dolibarr/dolibarr/htdocs/telephonie/lignetel.class.php,v $ 20 * 21 */ 22 23 class LigneTel { 24 var $db; 25 var $id; 26 var $ligne; 27 28 function LigneTel($DB, $id=0) 29 { 30 global $config; 31 32 $this->db = $DB; 33 $this->error_message = ''; 34 $this->statuts[-1] = "En attente"; 35 $this->statuts[1] = "A commander"; 36 $this->statuts[2] = "Commandée"; 37 $this->statuts[3] = "Activée"; 38 $this->statuts[4] = "A résilier"; 39 $this->statuts[5] = "Résiliation demandée"; 40 $this->statuts[6] = "Résiliée"; 41 $this->statuts[7] = "Rejetée"; 42 $this->statuts[8] = "En transfert"; 43 $this->statuts[9] = "Commande en cours"; 44 45 return 1; 46 } 47 /* 48 * 49 * 50 */ 51 function update($user) 52 { 53 $sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_societe_ligne"; 54 $sql .= " SET "; 55 $sql .= " ligne = '$this->numero', "; 56 $sql .= " fk_fournisseur = $this->fournisseur, "; 57 $sql .= " fk_concurrent = $this->concurrent, "; 58 $sql .= " note = '$this->note'"; 59 $sql .= " WHERE rowid = $this->id"; 60 61 if ( $this->db->query($sql) ) 62 { 63 return 1; 64 } 65 else 66 { 67 print $this->db->error(); 68 print $sql ; 69 return 0; 70 } 71 } 72 /* 73 * Infos complémentaires 74 * 75 */ 76 function update_infoc($user) 77 { 78 79 $sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_societe_ligne"; 80 $sql .= " SET "; 81 $sql .= " code_analytique = '".$this->code_analytique."' "; 82 83 $sql .= " WHERE rowid = ".$this->id; 84 85 if ( $this->db->query($sql) ) 86 { 87 return 1; 88 } 89 else 90 { 91 print $this->db->error(); 92 print $sql ; 93 return 0; 94 } 95 } 96 /* 97 * 98 * 99 */ 100 function send_mail($user, $commentaire, $statut) 101 { 102 /* 103 * Envoi mail au commercial responsable 104 * 105 */ 106 107 $comm = new User($this->db,$this->commercial_id); 108 $comm->fetch(); 109 110 $soc = new Societe($this->db); 111 $soc->fetch($this->socid); 112 113 $subject = "Evénement sur la ligne ".$this->numero; 114 $sendto = $comm->prenom . " " .$comm->nom . "<".$comm->email.">"; 115 $from = "Dolibarr <dolibarr@ibreizh.net>"; 116 117 $message = "Bonjour,\n\n"; 118 $message .= "Nous vous informons de l'événement suivant :\n\n"; 119 120 $message .= "Ligne numéro : ".$this->numero."\n"; 121 $message .= "Société : ".$soc->nom."\n"; 122 123 if ($statut == 6) 124 { 125 $message .= "Evénement : Désactivation\n"; 126 } 127 128 if ($statut == 3) 129 { 130 $message .= "Evénement : Activation\n"; 131 132 } 133 134 if (strlen($commentaire)) 135 { 136 $message .= "Commentaire : ".$commentaire; 137 } 138 139 $message .= "\n\n--\n"; 140 $message .= "Ceci est un message automatique envoyé par Dolibarr\n"; 141 $message .= "Vous ne pouvez pas y répondre."; 142 143 $mailfile = new DolibarrMail($subject, 144 $sendto, 145 $from, 146 $message); 147 $mailfile->sendfile(); 148 } 149 /* 150 * 151 * 152 */ 153 function SetRemise($user, $remise, $comment) 154 { 155 $remise = ereg_replace(",",".", $remise); 156 157 if (strlen(trim($remise)) <> 0 && is_numeric($remise)) 158 { 159 160 if (!$this->db->begin()) 161 { 162 dolibarr_syslog("LigneTel::SetRemise Error -5"); 163 $error++; 164 } 165 166 if (!$error) 167 { 168 169 $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_societe_ligne_remise"; 170 $sql .= " (tms, fk_ligne, remise, fk_user, comment)"; 171 $sql .= " VALUES (now(),"; 172 $sql .= " $this->id,'$remise',$user->id, '$comment')"; 173 174 if (! $this->db->query($sql) ) 175 { 176 dolibarr_syslog("LigneTel::SetRemise Error -3"); 177 $error++; 178 } 179 } 180 181 if (!$error) 182 { 183 $sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_societe_ligne"; 184 $sql .= " SET remise = '$remise'"; 185 $sql .= " WHERE rowid = $this->id"; 186 187 if (! $this->db->query($sql) ) 188 { 189 dolibarr_syslog("LigneTel::SetRemise Error -4"); 190 $error++; 191 } 192 } 193 194 if (!$error) 195 { 196 $this->db->commit(); 197 return 0; 198 } 199 else 200 { 201 $this->db->rollback(); 202 return -1; 203 } 204 } 205 else 206 { 207 dolibarr_syslog("LigneTel::SetRemise Error -2"); 208 return -2; 209 } 210 } 211 212 /* 213 * 214 * 215 */ 216 function create($user) 217 { 218 if (strlen(trim($this->numero)) == 10) 219 { 220 /* 221 * fk_commercial est encore définit pour supporter la migration en douceur 222 * à terme cette colonne sera supprimé 223 * 224 */ 225 226 $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_societe_ligne"; 227 $sql .= " (datec,fk_soc, fk_client_comm, ligne, fk_soc_facture, fk_fournisseur, note, remise, fk_commercial, fk_commercial_sign, fk_commercial_suiv, statut, fk_user_creat, fk_concurrent, fk_contrat)"; 228 $sql .= " VALUES ("; 229 $sql .= "now(),$this->client,$this->client_comm,'$this->numero',$this->client_facture,$this->fournisseur, '$this->note','$this->remise',$this->commercial_sign, $this->commercial_sign, $this->commercial_suiv, -1,$user->id, $this->concurrent, $this->contrat)"; 230 231 if ( $this->db->query($sql) ) 232 { 233 $this->id = $this->db->last_insert_id(MAIN_DB_PREFIX."telephonie_societe_ligne"); 234 235 $this->SetRemise($user, $this->remise, 'Remise initiale'); 236 237 $this->DefineClientOption(); 238 239 if ($this->techno == 'voip' && $this->id) 240 { 241 $sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_societe_ligne"; 242 $sql .= " SET statut = 3, techno='voip'"; 243 $sql .= " WHERE rowid=".$this->id; 244 $this->db->query($sql); 245 } 246 247 248 return 0; 249 } 250 else 251 { 252 $lex = new LigneTel($this->db); 253 if ($lex->fetch($this->numero) == 1) 254 { 255 $this->error_message = "Echec de la création de la ligne, cette ligne existe déjà !"; 256 dolibarr_syslog("LigneTel::Create Error -3"); 257 return -3; 258 } 259 else 260 { 261 $this->error_message = "Echec de la création de la ligne"; 262 dolibarr_syslog("LigneTel::Create Error -1"); 263 dolibarr_syslog("LigneTel::Create ".$this->db->error()); 264 dolibarr_syslog("LigneTel::Create $sql"); 265 return -1; 266 } 267 } 268 } 269 else 270 { 271 $this->error_message = "Echec de la création de la ligne, le numéro de la ligne est incorrect !"; 272 dolibarr_syslog("LigneTel::Create Error -2"); 273 return -2; 274 } 275 } 276 /* 277 * 278 * 279 */ 280 function DefineClientOption() 281 { 282 283 $sql = "SELECT propriete, valeur"; 284 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_societe_options"; 285 $sql .= " WHERE type= 'ligne'"; 286 $sql .= " AND fk_client_comm = '".$this->client_comm."'"; 287 288 $resql = $this->db->query($sql); 289 290 if ($resql) 291 { 292 $num = $this->db->num_rows($resql); 293 $i = 0; 294 295 while ($i < $num) 296 { 297 $obj = $this->db->fetch_object($resql); 298 299 $sqlu = "UPDATE ".MAIN_DB_PREFIX."telephonie_societe_ligne"; 300 $sqlu .= " SET ".$obj->propriete." = '".$obj->valeur."'"; 301 $sqlu .= " WHERE rowid = '".$this->id."'"; 302 303 $resqlu = $this->db->query($sqlu); 304 305 if (!$resqlu) 306 { 307 dolibarr_syslog("LigneTel::DefineClientOption Error"); 308 dolibarr_syslog("LigneTel::DefineClientOption $sqlu"); 309 } 310 311 312 $i++; 313 } 314 } 315 else 316 { 317 dolibarr_syslog("LigneTel::DefineClientOption Error"); 318 } 319 } 320 /* 321 * 322 * 323 */ 324 function fetch_by_id($id) 325 { 326 return $this->fetch(0, $id); 327 } 328 /* 329 * 330 * 331 */ 332 function fetch($ligne, $id = 0) 333 { 334 335 $sql = "SELECT rowid, fk_client_comm, fk_soc, fk_soc_facture, fk_fournisseur"; 336 $sql .= " , ligne, remise, note, statut, isfacturable"; 337 $sql .= " , mode_paiement, fk_concurrent, code_analytique"; 338 $sql .= " , fk_user_creat, fk_user_commande"; 339 $sql .= " , fk_contrat "; 340 $sql .= " , fk_commercial_suiv, fk_commercial_sign"; 341 $sql .= " , pdfdetail, techno, support"; 342 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne as tl"; 343 344 if ($id > 0) 345 { 346 $sql .= " WHERE tl.rowid = ".$id; 347 } 348 else 349 { 350 $sql .= " WHERE tl.ligne = ".$ligne; 351 } 352 353 $resql = $this->db->query($sql); 354 355 if ($resql) 356 { 357 if ($this->db->num_rows($resql)) 358 { 359 $obj = $this->db->fetch_object($resql); 360 361 $this->id = $obj->rowid; 362 $this->socid = $obj->fk_soc; 363 $this->numero = $obj->ligne; 364 $this->contrat = $obj->fk_contrat; 365 $this->remise = $obj->remise; 366 $this->client_comm_id = $obj->fk_client_comm; 367 $this->client_id = $obj->fk_soc; 368 $this->client_facture_id = $obj->fk_soc_facture; 369 $this->fournisseur_id = $obj->fk_fournisseur; 370 $this->commercial_id = $obj->fk_commercial_suiv; 371 $this->commercial_sign_id = $obj->fk_commercial_sign; 372 $this->commercial_suiv_id = $obj->fk_commercial_suiv; 373 $this->concurrent_id = $obj->fk_concurrent; 374 $this->statut = $obj->statut; 375 $this->mode_paiement = $obj->mode_paiement; 376 $this->code_analytique = $obj->code_analytique; 377 $this->techno = $obj->techno; 378 $this->support = $obj->support; 379 $this->user_creat = $obj->fk_user_creat; 380 $this->user_commande = $obj->fk_user_commande; 381 382 if ($obj->isfacturable == 'oui') 383 { 384 $this->facturable = 1; 385 } 386 else 387 { 388 $this->facturable = 0; 389 } 390 391 $this->note = stripslashes($obj->note); 392 $this->pdfdetail = $obj->pdfdetail; 393 $result = 1; 394 } 395 else 396 { 397 $result = -2; 398 } 399 400 $this->db->free($resql); 401 } 402 else 403 { 404 /* Erreur select SQL */ 405 print $this->db->error(); 406 $result = -1; 407 } 408 409 return $result; 410 } 411 412 /** 413 * 414 * 415 * 416 */ 417 function print_concurrent_nom() 418 { 419 $sql = "SELECT nom"; 420 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_concurrents"; 421 $sql .= " WHERE rowid=".$this->concurrent_id; 422 423 424 if ($this->db->query($sql)) 425 { 426 if ($this->db->num_rows()) 427 { 428 $row = $this->db->fetch_row(0); 429 430 return $row[0]; 431 } 432 } 433 } 434 435 /** 436 * Change le statut de la ligne en a commander 437 * 438 */ 439 function set_a_commander($user) 440 { 441 if ($this->statut == -1) 442 { 443 $this->set_statut( $user, 1, $datea, $commentaire); 444 } 445 } 446 447 /** 448 * Transfer la ligne 449 * 450 */ 451 function transfer($user, $fourn_id) 452 { 453 if ($this->statut == 3) 454 { 455 $this->change_fournisseur($user,$fourn_id); 456 $this->set_statut($user, 8); 457 } 458 } 459 460 function change_fournisseur($user, $fourn_id) 461 { 462 $sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_societe_ligne"; 463 $sql .= " SET fk_fournisseur = ".$fourn_id ; 464 $sql .= " WHERE rowid = ".$this->id; 465 466 $resql = $this->db->query($sql); 467 468 $this->fournisseur_id = $fourn_id; 469 } 470 471 472 /** 473 * Change le statut de la ligne en En attente 474 * 475 */ 476 function set_en_attente($user) 477 { 478 if ($this->statut == 1) 479 { 480 $this->set_statut($user, -1, $datea, $commentaire); 481 } 482 } 483 484 /** 485 * Change le statut de la ligne 486 * 487 */ 488 function set_statut($user, $statut, $datea='', $commentaire='', $fourn=0) 489 { 490 if ($statut == 6 || $statut == 3) 491 { 492 $this->send_mail($user, $commentaire, $statut); 493 } 494 495 496 $sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_societe_ligne"; 497 $sql .= " SET statut = ".$statut ; 498 $sql .= " WHERE rowid =".$this->id; 499 500 if ($fourn > 0) 501 { 502 $sql .= " AND fk_fournisseur =".$fourn; 503 $this->fournisseur_id = $fourn; 504 } 505 506 $this->db->query($sql); 507 508 if ($statut == 2) 509 { 510 $sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_societe_ligne"; 511 $sql .= " SET date_commande = now()"; 512 $sql .= ", date_commande_last = now()"; 513 $sql .= ", fk_user_commande=".$user->id; 514 $sql .= " WHERE rowid =".$this->id; 515 $sql .= " AND date_commande IS NULL"; 516 517 if ($fourn > 0) 518 { 519 $sql .= " AND fk_fournisseur =".$fourn; 520 } 521 522 $this->db->query($sql); 523 524 $sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_societe_ligne"; 525 $sql .= " SET date_commande_last = now()"; 526 $sql .= ", fk_user_commande=".$user->id; 527 $sql .= " WHERE rowid =".$this->id; 528 529 if ($fourn > 0) 530 { 531 $sql .= " AND fk_fournisseur =".$fourn; 532 } 533 534 $this->db->query($sql); 535 } 536 537 if ($datea) 538 { 539 $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_societe_ligne_statut"; 540 $sql .= " (tms,fk_ligne, fk_user, statut, comment,fk_fournisseur) "; 541 $sql .= " VALUES ($datea,$this->id, $user->id, $statut, '$commentaire',$this->fournisseur_id)"; 542 543 $this->db->query($sql); 544 /* 545 * Mise à jour des logs 546 * 547 */ 548 $sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_ligne_statistique"; 549 $sql .= " SET nb = nb - 1"; 550 $sql .= " WHERE statut = ".$this->statut; 551 $sql .= " AND dates >= '".$datea ."'"; 552 553 $this->db->query($sql); 554 555 $sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_ligne_statistique"; 556 $sql .= " SET nb = nb + 1"; 557 $sql .= " WHERE statut = ".$statut; 558 $sql .= " AND dates >= '".$datea ."'"; 559 560 $this->db->query($sql); 561 } 562 else 563 { 564 $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_societe_ligne_statut"; 565 $sql .= " (tms, fk_ligne, fk_user, statut, comment,fk_fournisseur) "; 566 $sql .= " VALUES (now(), $this->id, $user->id, $statut, '$commentaire',$this->fournisseur_id)"; 567 568 $this->db->query($sql); 569 } 570 571 572 $sql = "SELECT distinct statut, count(*) FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne GROUP BY statut"; 573 574 if ($this->db->query($sql)) 575 { 576 $num = $this->db->num_rows(); 577 $i = 0; 578 $sl = array(); 579 while ($i < $num) 580 { 581 $row = $this->db->fetch_row($i); 582 $sl[$i] = $row; 583 $i++; 584 } 585 586 $i = 0; 587 588 /* Nettoyage des logs */ 589 590 $sql = "DELETE FROM ".MAIN_DB_PREFIX."telephonie_ligne_statistique"; 591 $sql .= " WHERE dates = now()"; 592 if (!$this->db->query($sql)) 593 { 594 print $sql; 595 } 596 597 /* Insertion des nouveaux logs */ 598 599 while ($i < $num) 600 { 601 $row = $sl[$i]; 602 603 $sql = "REPLACE INTO ".MAIN_DB_PREFIX."telephonie_ligne_statistique"; 604 $sql .= " VALUES (now(),".$row[0].",".$row[1].")"; 605 if (!$this->db->query($sql)) 606 { 607 print $sql; 608 } 609 $i++; 610 } 611 } 612 else 613 { 614 print $sql; 615 } 616 617 $this->log_clients(); 618 619 620 /* Mise à jour du contrat associé */ 621 622 if ($this->contrat > 0) 623 { 624 require_once (DOL_DOCUMENT_ROOT."/telephonie/telephonie.contrat.class.php"); 625 $contrat = new TelephonieContrat($this->db); 626 $contrat->id = $this->contrat; 627 $contrat->update_statut(); 628 } 629 630 return 0; 631 } 632 /* 633 * 634 * 635 */ 636 function log_clients() 637 { 638 $sql = "SELECT distinct s.idp "; 639 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne as l"; 640 $sql .= " , ".MAIN_DB_PREFIX."societe as s"; 641 $sql .= " WHERE l.statut = 3 AND s.idp = l.fk_soc "; 642 643 if ($this->db->query($sql)) 644 { 645 $num = $this->db->num_rows(); 646 $nbclients = $num; 647 $i = 0; 648 649 /* Insertion des nouveaux logs */ 650 651 $sql = "REPLACE INTO ".MAIN_DB_PREFIX."telephonie_client_statistique"; 652 $sql .= " VALUES (now(),'nbclient',".$num.")"; 653 if (!$this->db->query($sql)) 654 { 655 print $sql; 656 } 657 } 658 else 659 { 660 print $sql; 661 } 662 /* 663 * nbligne active / client 664 * 665 */ 666 667 $sql = "SELECT count(*) "; 668 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne as l"; 669 $sql .= " WHERE l.statut = 3"; 670 671 if ($this->db->query($sql)) 672 { 673 $num = $this->db->num_rows(); 674 675 $row = $this->db->fetch_row(0); 676 677 /* Insertion des nouveaux logs */ 678 679 if ($nbclients > 0) 680 { 681 $nblapc = ereg_replace(",",".",round($row[0]/$nbclients,3)); 682 } 683 684 $sql = "REPLACE INTO ".MAIN_DB_PREFIX."telephonie_client_statistique"; 685 $sql .= " VALUES (now(),'nblapc','".$nblapc."')"; 686 if (!$this->db->query($sql)) 687 { 688 print $sql; 689 } 690 } 691 else 692 { 693 print $sql; 694 } 695 696 697 return 0; 698 699 } 700 /* 701 * 702 * 703 */ 704 function add_contact($cid) 705 { 706 707 $sql = "INSERT INTO ".MAIN_DB_PREFIX."telephonie_contact_facture"; 708 $sql .= " (fk_ligne, fk_contact) "; 709 $sql .= " VALUES ($this->id, $cid )"; 710 711 $this->db->query($sql); 712 } 713 /* 714 * 715 * 716 * 717 */ 718 function delete($user) 719 { 720 $erro = 0; 721 if ($this->statut == -1) 722 { 723 724 if ($this->db->begin()) 725 { 726 $sql = "DELETE FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne_remise"; 727 $sql .= " WHERE fk_ligne=".$this->id; 728 729 if (!$this->db->query($sql)) 730 { 731 dolibarr_syslog("LigneTel::Delete Error -5"); 732 $error++; 733 } 734 735 $sql = "DELETE FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne_statut"; 736 $sql .= " WHERE fk_ligne=".$this->id; 737 738 if (!$this->db->query($sql)) 739 { 740 dolibarr_syslog("LigneTel::Delete Error -4"); 741 $error++; 742 } 743 744 $sql = "DELETE FROM ".MAIN_DB_PREFIX."telephonie_contact_facture"; 745 $sql .= " WHERE fk_ligne=".$this->id; 746 747 if (!$this->db->query($sql)) 748 { 749 dolibarr_syslog("LigneTel::Delete Error -3"); 750 $error++; 751 } 752 753 $sql = "DELETE FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne"; 754 $sql .= " WHERE rowid =".$this->id; 755 756 if (!$this->db->query($sql)) 757 { 758 dolibarr_syslog("LigneTel::Delete Error -2"); 759 $error++; 760 } 761 762 /*****/ 763 764 if (!$error) 765 { 766 $this->db->commit(); 767 return 0; 768 } 769 else 770 { 771 $this->db->rollback(); 772 return -1; 773 } 774 } 775 776 } 777 } 778 /* 779 * 780 * 781 */ 782 function del_contact($cid) 783 { 784 785 $sql = "DELETE FROM ".MAIN_DB_PREFIX."telephonie_contact_facture"; 786 $sql .= " WHERE fk_ligne=$this->id AND fk_contact=$cid ;"; 787 788 return $this->db->query($sql); 789 } 790 /* 791 * 792 */ 793 function get_contact_facture() 794 { 795 $this->contact_facture_id = array(); 796 $res = array(); 797 $resid = array(); 798 799 800 $sql = "SELECT c.idp, c.name, c.firstname, c.email "; 801 $sql .= "FROM ".MAIN_DB_PREFIX."socpeople as c"; 802 $sql .= ",".MAIN_DB_PREFIX."telephonie_contact_facture as cf"; 803 $sql .= " WHERE c.idp = cf.fk_contact AND cf.fk_ligne = ".$this->id." ORDER BY name "; 804 805 if ( $this->db->query( $sql) ) 806 { 807 $num = $this->db->num_rows(); 808 if ( $num > 0 ) 809 { 810 $i = 0; 811 while ($i < $num) 812 { 813 $row = $this->db->fetch_row($i); 814 815 array_push($res, $row[1] . " " . $row[2] . " <".$row[3].">"); 816 array_push($resid, $row[0]); 817 $i++; 818 } 819 820 $this->db->free(); 821 } 822 823 } 824 $this->contact_facture_id = $resid; 825 return $res; 826 } 827 /** 828 * Recupére le numéro d'une ligne depuis une facture comptable 829 * 830 */ 831 832 function fetch_by_facture_number($facnumber) 833 { 834 $sql = "SELECT fk_ligne, fk_facture "; 835 $sql .= " FROM ".MAIN_DB_PREFIX."telephonie_facture"; 836 $sql .= " WHERE fk_facture = ".$facnumber; 837 838 $resql = $this->db->query($sql); 839 840 if ($resql) 841 { 842 if ($this->db->num_rows($resql)) 843 { 844 $row = $this->db->fetch_row($resql); 845 846 $this->id = $row[0]; 847 848 return 0; 849 } 850 else 851 { 852 return -1; 853 } 854 $this->db->free($resql); 855 } 856 else 857 { 858 return -2; 859 } 860 } 861 862 function ChangeContrat($user, $contrat_id) 863 { 864 $sql = "UPDATE ".MAIN_DB_PREFIX."telephonie_societe_ligne"; 865 $sql .= " SET fk_contrat = ".$contrat_id ; 866 $sql .= " WHERE rowid = ".$this->id; 867 868 $resql = $this->db->query($sql); 869 870 return 0; 871 } 872 873 /** 874 * \brief Charge indicateurs this->nb de tableau de bord 875 * \return int <0 si ko, >0 si ok 876 */ 877 function load_state_board($user) 878 { 879 $this->nb=array(); 880 881 $sql = "SELECT count(rowid) as nb"; 882 $sql.= " FROM ".MAIN_DB_PREFIX."telephonie_societe_ligne "; 883 $sql.= " WHERE fk_commercial_sign = ".$user->id; 884 $resql=$this->db->query($sql); 885 if ($resql) 886 { 887 while ($obj=$this->db->fetch_object($resql)) 888 { 889 $this->nb["sign"] = $obj->nb; 890 } 891 return 1; 892 } 893 else 894 { 895 dolibarr_print_error($this->db); 896 $this->error=$this->db->error(); 897 return -1; 898 } 899 } 900 } 901 ?>
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Mon Nov 26 12:29:37 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |