/[dolibarr]/dolibarr/htdocs/comm/propal.php
ViewVC logotype

Diff of /dolibarr/htdocs/comm/propal.php

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.98 by eldy, Mon Jul 18 21:24:42 2005 UTC revision 1.99 by rodolphe, Tue Aug 2 07:23:45 2005 UTC
# Line 1  Line 1 
1  <?php  <?php
2  /* Copyright (C) 2001-2004 Rodolphe Quiedeville  <rodolphe@quiedeville.org>  /* Copyright (C) 2001-2005 Rodolphe Quiedeville  <rodolphe@quiedeville.org>
3   * Copyright (C) 2004-2005 Laurent Destailleur   <eldy@users.sourceforge.net>   * Copyright (C) 2004-2005 Laurent Destailleur   <eldy@users.sourceforge.net>
4   * Copyright (C) 2004      Eric Seigne           <eric.seigne@ryxeo.com>   * Copyright (C) 2004      Eric Seigne           <eric.seigne@ryxeo.com>
5   * Copyright (C) 2005      Marc Barilley / Ocebo <marc@ocebo.com>   * Copyright (C) 2005      Marc Barilley / Ocebo <marc@ocebo.com>
# Line 71  $form=new Form($db); Line 71  $form=new Form($db);
71    
72  if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes')  if ($_POST['action'] == 'confirm_delete' && $_POST['confirm'] == 'yes')
73  {  {
74          if ($user->rights->propale->supprimer)    if ($user->rights->propale->supprimer)
75          {      {
76                  $propal = new Propal($db, 0, $_GET['propalid']);        $propal = new Propal($db, 0, $_GET['propalid']);
77                  $propal->delete($user);        $propal->delete($user);
78                  $propalid = 0;        $propalid = 0;
79                  $brouillon = 1;        $brouillon = 1;
80          }      }
81          Header('Location: propal.php');    Header('Location: propal.php');
82  }  }
83    
84    
85  if ($_POST['action'] == 'add')  if ($_POST['action'] == 'add')
86  {  {
87          $propal = new Propal($db, $_GET['socidp']);    $propal = new Propal($db, $_GET['socidp']);
88          $propal->datep = mktime(12, 1 , 1, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);    $propal->datep = mktime(12, 1 , 1, $_POST['remonth'], $_POST['reday'], $_POST['reyear']);
89      
90          $propal->duree_validite = $_POST['duree_validite'];    $propal->duree_validite = $_POST['duree_validite'];
91      
92          $propal->contactid = $_POST['contactidp'];    $propal->contactid = $_POST['contactidp'];
93          $propal->projetidp = $_POST['projetidp'];    $propal->projetidp = $_POST['projetidp'];
94          $propal->modelpdf  = $_POST['modelpdf'];    $propal->modelpdf  = $_POST['modelpdf'];
95          $propal->author    = $user->id;    $propal->author    = $user->id;
96          $propal->note      = $_POST['note'];    $propal->note      = $_POST['note'];
97      
98          $propal->ref = $_POST['ref'];    $propal->ref = $_POST['ref'];
99      
100          for ($i = 1 ; $i <= PROPALE_NEW_FORM_NB_PRODUCT ; $i++)    for ($i = 1 ; $i <= PROPALE_NEW_FORM_NB_PRODUCT ; $i++)
101          {      {
102                  $xid = 'idprod'.$i;        $xid = 'idprod'.$i;
103                  $xqty = 'qty'.$i;        $xqty = 'qty'.$i;
104                  $xremise = 'remise'.$i;        $xremise = 'remise'.$i;
105                  $propal->add_product($_POST[$xid],$_POST[$xqty],$_POST[$xremise]);        $propal->add_product($_POST[$xid],$_POST[$xqty],$_POST[$xremise]);
106          }      }
107      
108          $id = $propal->create();    $id = $propal->create();
109      
110          /*    /*
111           *   Generation     *   Generation
112           */     */
113          if ($id)    if ($id)
114          {      {
115                  propale_pdf_create($db, $id, $_POST['modelpdf']);        propale_pdf_create($db, $id, $_POST['modelpdf']);
116                  Header ('Location: propal.php?propalid='.$id);        Header ('Location: propal.php?propalid='.$id);
117          }      }
118  }  }
119    
120  if ($_GET['action'] == 'pdf')  if ($_GET['action'] == 'pdf')
121  {  {
122          $propal = new Propal($db);    $propal = new Propal($db);
123          $propal->fetch($_GET['propalid']);    $propal->fetch($_GET['propalid']);
124          propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf);    propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf);
125  }  }
126    
127  if ($_POST['action'] == 'setstatut' && $user->rights->propale->cloturer)  if ($_POST['action'] == 'setstatut' && $user->rights->propale->cloturer)
128  {  {
129          /*    /*
130           *  Cloture de la propale     *  Cloture de la propale
131           */     */
132          $propal = new Propal($db);    $propal = new Propal($db);
133          $propal->fetch($_GET['propalid']);    $propal->fetch($_GET['propalid']);
134          $propal->cloture($user, $_POST['statut'], $_POST['note']);    $propal->cloture($user, $_POST['statut'], $_POST['note']);
135  }  }
136    
137  /*  /*
# Line 140  if ($_POST['action'] == 'setstatut' && $ Line 140  if ($_POST['action'] == 'setstatut' && $
140   */   */
141  if ($_POST['action'] == 'send')  if ($_POST['action'] == 'send')
142  {  {
143          $langs->load('mails');    $langs->load('mails');
144          $propal= new Propal($db);    $propal= new Propal($db);
145          if ( $propal->fetch($_POST['propalid']) )    if ( $propal->fetch($_POST['propalid']) )
146          {      {
147                  $propalref = sanitize_string($propal->ref);        $propalref = sanitize_string($propal->ref);
148                  $file = $conf->propal->dir_output . '/' . $propalref . '/' . $propalref . '.pdf';        $file = $conf->propal->dir_output . '/' . $propalref . '/' . $propalref . '.pdf';
149                  if (is_readable($file))        if (is_readable($file))
150            {
151              $soc = new Societe($db, $propal->socidp);
152              if ($_POST['sendto'])
153                {
154                  // Le destinataire a été fourni via le champ libre
155                  $sendto = $_POST['sendto'];
156                  $sendtoid = 0;
157                }
158              elseif ($_POST['receiver'])
159                {
160                  // Le destinataire a été fourni via la liste déroulante
161                  $sendto = $soc->contact_get_email($_POST['receiver']);
162                  $sendtoid = $_POST['receiver'];
163                }
164    
165              if (strlen($sendto))
166                {
167                  $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';
168                  $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';
169                  $message = $_POST['message'];
170                  if ($_POST['action'] == 'send')
171                  {                  {
172                          $soc = new Societe($db, $propal->socidp);                    $subject = $langs->trans('Propal').' '.$propal->ref;
173                          if ($_POST['sendto'])                    $actiontypeid=3;
174                          {                    $actionmsg ='Mail envoyé par '.$from.' à '.$sendto.'.<br>';
175                                  // Le destinataire a été fourni via le champ libre                    if ($message)
176                                  $sendto = $_POST['sendto'];                      {
177                                  $sendtoid = 0;                        $actionmsg.='Texte utilisé dans le corps du message:<br>';
178                          }                        $actionmsg.=$message;
179                          elseif ($_POST['receiver'])                      }
180                          {                    $actionmsg2='Envoi Propal par mail';
181                                  // Le destinataire a été fourni via la liste déroulante                  }
182                                  $sendto = $soc->contact_get_email($_POST['receiver']);                /*
183                                  $sendtoid = $_POST['receiver'];                  if ($_POST["action"] == 'relance')
184                          }                  {
185                    $subject = "Relance facture $propal->ref";
186                          if (strlen($sendto))                  $actiontypeid=10;
187                          {                  $actionmsg="Mail envoyé par $from à $sendto.<br>";
188                                  $from = $_POST['fromname'] . ' <' . $_POST['frommail'] .'>';                  if ($message)
189                                  $replyto = $_POST['replytoname']. ' <' . $_POST['replytomail'].'>';                  {
190                                  $message = $_POST['message'];                  $actionmsg.="Texte utilisé dans le corps du message:<br>";
191                                  if ($_POST['action'] == 'send')                  $actionmsg.=$message;
192                                  {                  }
193                                          $subject = $langs->trans('Propal').' '.$propal->ref;                  $actionmsg2="Relance Facture par mail";
194                                          $actiontypeid=3;                  }
195                                          $actionmsg ='Mail envoyé par '.$from.' à '.$sendto.'.<br>';                */
196                                          if ($message)                $filepath[0] = $file;
197                                          {                $filename[0] = $propal->ref.'.pdf';
198                                                  $actionmsg.='Texte utilisé dans le corps du message:<br>';                $mimetype[0] = 'application/pdf';
199                                                  $actionmsg.=$message;                if ($_FILES['addedfile']['tmp_name'])
200                                          }                  {
201                                          $actionmsg2='Envoi Propal par mail';                    $filepath[1] = $_FILES['addedfile']['tmp_name'];
202                                  }                    $filename[1] = $_FILES['addedfile']['name'];
203                                  /*                    $mimetype[1] = $_FILES['addedfile']['type'];
                                 if ($_POST["action"] == 'relance')  
                                 {  
                                         $subject = "Relance facture $propal->ref";  
                                         $actiontypeid=10;  
                                         $actionmsg="Mail envoyé par $from à $sendto.<br>";  
                                         if ($message)  
                                         {  
                                                 $actionmsg.="Texte utilisé dans le corps du message:<br>";  
                                                 $actionmsg.=$message;  
                                         }  
                                         $actionmsg2="Relance Facture par mail";  
                                 }  
                                 */  
                                 $filepath[0] = $file;  
                                 $filename[0] = $propal->ref.'.pdf';  
                                 $mimetype[0] = 'application/pdf';  
                                 if ($_FILES['addedfile']['tmp_name'])  
                                 {  
                                 $filepath[1] = $_FILES['addedfile']['tmp_name'];  
                                 $filename[1] = $_FILES['addedfile']['name'];  
                                 $mimetype[1] = $_FILES['addedfile']['type'];  
204                  }                  }
205                                  // Envoi de la facture                // Envoi de la facture
206                                  $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc);                $mailfile = new CMailFile($subject,$sendto,$from,$message,$filepath,$mimetype,$filename,$sendtocc);
207                                  if ($mailfile->sendfile())                if ($mailfile->sendfile())
208                                  {                  {
209                                          $msg='<div class="ok">'.$langs->trans('MailSuccessfulySent',$from,$sendto).'.</div>';                    $msg='<div class="ok">'.$langs->trans('MailSuccessfulySent',$from,$sendto).'.</div>';
210                                          // Insertion action                    // Insertion action
211                                          include_once('../contact.class.php');                    include_once('../contact.class.php');
212                                          $actioncomm = new ActionComm($db);                    $actioncomm = new ActionComm($db);
213                                          $actioncomm->type_id     = $actiontypeid;                    $actioncomm->type_id     = $actiontypeid;
214                                          $actioncomm->label       = $actionmsg2;                    $actioncomm->label       = $actionmsg2;
215                                          $actioncomm->note        = $actionmsg;                    $actioncomm->note        = $actionmsg;
216                                          $actioncomm->date        = time();  // L'action est faite maintenant                    $actioncomm->date        = time();  // L'action est faite maintenant
217                                          $actioncomm->percent     = 100;                    $actioncomm->percent     = 100;
218                                          $actioncomm->contact     = new Contact($db,$sendtoid);                    $actioncomm->contact     = new Contact($db,$sendtoid);
219                                          $actioncomm->societe     = new Societe($db,$propal->socidp);                    $actioncomm->societe     = new Societe($db,$propal->socidp);
220                                          $actioncomm->user        = $user;   // User qui a fait l'action                    $actioncomm->user        = $user;   // User qui a fait l'action
221                                          $actioncomm->propalrowid = $propal->id;                    $actioncomm->propalrowid = $propal->id;
222                                          $ret=$actioncomm->add($user);       // User qui saisi l'action                    $ret=$actioncomm->add($user);       // User qui saisi l'action
223                                          if ($ret < 0)                    if ($ret < 0)
224                                          {                      {
225                                                  dolibarr_print_error($db);                        dolibarr_print_error($db);
226                                          }                      }
227                                          else                    else
228                                          {                      {
229                                                  // Renvoie sur la fiche                        // Renvoie sur la fiche
230                                                  Header('Location: propal.php?propalid='.$propal->id.'&msg='.urlencode($msg));                        Header('Location: propal.php?propalid='.$propal->id.'&msg='.urlencode($msg));
231                                                  exit;                        exit;
232                                          }                      }
                                 }  
                                 else  
                                 {  
                                         $msg='<div class="error">'.$langs->trans('ErrorFailedToSendMail',$from,$sendto).' - '.$actioncomm->error.'</div>';  
                                 }  
                         }  
                         else  
                         {  
                                 $msg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').' !</div>';  
                                 dolibarr_syslog('Le mail du destinataire est vide');  
                         }  
233                  }                  }
234                  else                else
235                  {                  {
236                          dolibarr_syslog('Impossible de lire :'.$file);                    $msg='<div class="error">'.$langs->trans('ErrorFailedToSendMail',$from,$sendto).' - '.$actioncomm->error.'</div>';
237                  }                  }
238          }              }
239          else            else
240          {              {
241                  dolibarr_syslog('Impossible de lire les données de la propale. Le fichier propal n\'a peut-être pas été généré.');                $msg='<div class="error">'.$langs->trans('ErrorMailRecipientIsEmpty').' !</div>';
242          }                dolibarr_syslog('Le mail du destinataire est vide');
243                }
244            }
245          else
246            {
247              dolibarr_syslog('Impossible de lire :'.$file);
248            }
249        }
250      else
251        {
252          dolibarr_syslog('Impossible de lire les données de la propale. Le fichier propal n\'a peut-être pas été généré.');
253        }
254  }  }
255    
256  if ($_GET['action'] == 'commande')  if ($_GET['action'] == 'commande')
257  {  {
258          /*    /*
259           *  Cloture de la propale     *  Cloture de la propale
260           */     */
261          $propal = new Propal($db);    $propal = new Propal($db);
262          $propal->fetch($propalid);    $propal->fetch($propalid);
263          $propal->create_commande($user);    $propal->create_commande($user);
264  }  }
265    
266  if ($_GET['action'] == 'modif' && $user->rights->propale->creer)  if ($_GET['action'] == 'modif' && $user->rights->propale->creer)
267  {  {
268          /*    /*
269           *  Repasse la propale en mode brouillon     *  Repasse la propale en mode brouillon
270           */     */
271          $propal = new Propal($db);    $propal = new Propal($db);
272          $propal->fetch($_GET['propalid']);    $propal->fetch($_GET['propalid']);
273          $propal->reopen($user->id);    $propal->reopen($user->id);
274  }  }
275    
276  if ($_POST['addligne'] == $langs->trans('Add') && $user->rights->propale->creer)  if ($_POST['addligne'] == $langs->trans('Add') && $user->rights->propale->creer)
277  {  {
278          /*    /*
279           *  Ajout d'une ligne produit dans la propale     *  Ajout d'une ligne produit dans la propale
280           */     */
281          if ($_POST['idprod'])    if ($_POST['idprod'])
282          {      {
283                  $propal = new Propal($db);        $propal = new Propal($db);
284                  $propal->fetch($_GET['propalid']);        $propal->fetch($_GET['propalid']);
285                  $propal->insert_product($_POST['idprod'], $_POST['qty'], $_POST['remise']);        $propal->insert_product($_POST['idprod'], $_POST['qty'], $_POST['remise']);
286                  propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf);        propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf);
287          }      }
288  }  }
289    
290  if ($_POST['addproduct'] == $langs->trans('Add') && $user->rights->propale->creer)  if ($_POST['action'] == 'updateligne' && $user->rights->propale->creer)
291  {  {
292          /*    /*
293           *  Ajout d'une ligne produit dans la propale     *  Mise à jour d'une ligne dans la propale
294           */     */
295          if (strlen($_POST['np_desc']) && strlen($_POST['np_price']))  
296          {    $propal = new Propal($db);
297                  $propal = new Propal($db);    $propal->fetch($_GET['propalid']);
298                  $propal->fetch($_GET['propalid']);    $propal->UpdateLigne($_POST['ligne'], $_POST['subprice'], $_POST['qty'], $_POST['remise']);
299                  $propal->insert_product_generic(  
300                          $_POST['np_desc'],    propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf);
                         $_POST['np_price'],  
                         $_POST['np_qty'],  
                         $_POST['np_tva_tx'],  
                         $_POST['np_remise']);  
         }  
301  }  }
302    
303  if ($_POST['action'] == 'setremise' && $user->rights->propale->creer)  if ($_POST['addproduct'] == $langs->trans('Add') && $user->rights->propale->creer)
304  {  {
305          $propal = new Propal($db);    /*
306          $propal->fetch($_GET['propalid']);     *  Ajout d'une ligne produit dans la propale
307          $propal->set_remise($user, $_POST['remise']);     */
308          propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf);    if (strlen($_POST['np_desc']) && strlen($_POST['np_price']))
309        {
310          $propal = new Propal($db);
311          $propal->fetch($_GET['propalid']);
312          $propal->insert_product_generic(
313                                          $_POST['np_desc'],
314                                          $_POST['np_price'],
315                                          $_POST['np_qty'],
316                                          $_POST['np_tva_tx'],
317                                          $_POST['np_remise']);
318        }
319  }  }
320    
321    
322  if ($_POST['action'] == 'setpdfmodel' && $user->rights->propale->creer)  if ($_POST['action'] == 'setpdfmodel' && $user->rights->propale->creer)
323  {  {
324          $propal = new Propal($db, 0, $_GET['propalid']);    $propal = new Propal($db, 0, $_GET['propalid']);
325          $propal->set_pdf_model($user, $_POST['modelpdf']);    $propal->set_pdf_model($user, $_POST['modelpdf']);
326          propale_pdf_create($db, $_GET['propalid'], $_POST['modelpdf']);    propale_pdf_create($db, $_GET['propalid'], $_POST['modelpdf']);
327  }  }
328    
329    
330  if ($_GET['action'] == 'del_ligne' && $user->rights->propale->creer)  if ($_GET['action'] == 'del_ligne' && $user->rights->propale->creer)
331  {  {
332          /*    /*
333           *  Supprime une ligne produit dans la propale     *  Supprime une ligne produit dans la propale
334           */     */
335          $propal = new Propal($db);    $propal = new Propal($db);
336          $propal->fetch($_GET['propalid']);    $propal->fetch($_GET['propalid']);
337          $propal->delete_product($_GET['ligne']);    $propal->delete_product($_GET['ligne']);
338          propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf);    propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf);
339  }  }
340    
341  if ($_GET['valid'] == 1 && $user->rights->propale->valider)  if ($_GET['valid'] == 1 && $user->rights->propale->valider)
342  {  {
343          $propal = new Propal($db);    $propal = new Propal($db);
344          $propal->fetch($_GET['propalid']);    $propal->fetch($_GET['propalid']);
345          $propal->update_price($_GET['propalid']);    $propal->update_price($_GET['propalid']);
346          propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf);    propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf);
347          $propal->valid($user);    $propal->valid($user);
348    }
349    
350    if ($_POST['action'] == 'setremise' && $user->rights->propale->creer)
351    {
352      $propal = new Propal($db);
353      $propal->fetch($_GET['propalid']);
354      $propal->set_remise($user, $_POST['remise']);
355      propale_pdf_create($db, $_GET['propalid'], $propal->modelpdf);
356  }  }
357    
358  if ($_POST['action'] == 'set_project')  if ($_POST['action'] == 'set_project')
359  {  {
360          $propal = new Propal($db);    $propal = new Propal($db);
361          $propal->fetch($_GET['propalid']);    $propal->fetch($_GET['propalid']);
362          $propal->set_project($user, $_POST['projetidp']);    $propal->set_project($user, $_POST['projetidp']);
363  }  }
364    
365  if ($_POST['action'] == 'set_contact')  if ($_POST['action'] == 'set_contact')
366  {  {
367          $propal = new Propal($db);    $propal = new Propal($db);
368          $propal->fetch($_GET['propalid']);    $propal->fetch($_GET['propalid']);
369          $propal->set_contact($user, $_POST['contactidp']);    $propal->set_contact($user, $_POST['contactidp']);
370  }  }
371    
372    
# Line 365  llxHeader(); Line 379  llxHeader();
379   */   */
380  if ($_GET['propalid'])  if ($_GET['propalid'])
381  {  {
382          if ($msg) print "$msg<br>";    if ($msg) print "$msg<br>";
383          $html = new Form($db);    $html = new Form($db);
   
         $propal = new Propal($db);  
         $propal->fetch($_GET['propalid']);  
   
         $societe = new Societe($db);  
         $societe->fetch($propal->soc_id);  
         $h=0;  
   
         $head[$h][0] = DOL_URL_ROOT.'/comm/propal.php?propalid='.$propal->id;  
         $head[$h][1] = $langs->trans('CommercialCard');  
         $hselected=$h;  
         $h++;  
   
         $head[$h][0] = DOL_URL_ROOT.'/compta/propal.php?propalid='.$propal->id;  
         $head[$h][1] = $langs->trans('AccountancyCard');  
         $h++;  
   
         $head[$h][0] = DOL_URL_ROOT.'/comm/propal/note.php?propalid='.$propal->id;  
         $head[$h][1] = $langs->trans('Note');  
         $h++;  
   
         $head[$h][0] = DOL_URL_ROOT.'/comm/propal/info.php?propalid='.$propal->id;  
         $head[$h][1] = $langs->trans('Info');  
         $h++;  
   
         $head[$h][0] = DOL_URL_ROOT.'/comm/propal/document.php?propalid='.$propal->id;  
         $head[$h][1] = $langs->trans('Documents');  
         $h++;  
   
         dolibarr_fiche_head($head, $hselected, $langs->trans('Proposal').': '.$propal->ref);  
   
         /*  
          * Confirmation de la suppression de la propale  
          *  
          */  
         if ($_GET['action'] == 'delete')  
         {  
                 $html->form_confirm('propal.php?propalid='.$propal->id, $langs->trans('DeleteProp'), $langs->trans('ConfirmDeleteProp'), 'confirm_delete');  
                 print '<br>';  
         }  
   
384    
385          /*    $propal = new Propal($db);
386           * Fiche propal    $propal->fetch($_GET['propalid']);
          *  
          */  
         $sql = 'SELECT s.nom, s.idp, p.price, p.fk_projet, p.remise, p.tva, p.total, p.ref, p.fk_statut, '.$db->pdate('p.datep').' as dp, p.note,';  
         $sql.= ' x.firstname, x.name, x.fax, x.phone, x.email, p.fk_user_author, p.fk_user_valid, p.fk_user_cloture, p.datec, p.date_valid, p.date_cloture';  
         $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p, '.MAIN_DB_PREFIX.'socpeople as x';  
         $sql.= ' WHERE p.fk_soc = s.idp AND p.fk_soc_contact = x.idp AND p.rowid = '.$propal->id;  
         if ($socidp) $sql .= ' AND s.idp = '.$socidp;  
387    
388          $result = $db->query($sql);    $societe = new Societe($db);
389          if ($result)    $societe->fetch($propal->soc_id);
390          {    $h=0;
391                  if ($db->num_rows($result))  
392      $head[$h][0] = DOL_URL_ROOT.'/comm/propal.php?propalid='.$propal->id;
393      $head[$h][1] = $langs->trans('CommercialCard');
394      $hselected=$h;
395      $h++;
396    
397      $head[$h][0] = DOL_URL_ROOT.'/compta/propal.php?propalid='.$propal->id;
398      $head[$h][1] = $langs->trans('AccountancyCard');
399      $h++;
400    
401      $head[$h][0] = DOL_URL_ROOT.'/comm/propal/note.php?propalid='.$propal->id;
402      $head[$h][1] = $langs->trans('Note');
403      $h++;
404    
405      $head[$h][0] = DOL_URL_ROOT.'/comm/propal/info.php?propalid='.$propal->id;
406      $head[$h][1] = $langs->trans('Info');
407      $h++;
408    
409      $head[$h][0] = DOL_URL_ROOT.'/comm/propal/document.php?propalid='.$propal->id;
410      $head[$h][1] = $langs->trans('Documents');
411      $h++;
412    
413      dolibarr_fiche_head($head, $hselected, $langs->trans('Proposal').': '.$propal->ref);
414    
415      /*
416       * Confirmation de la suppression de la propale
417       *
418       */
419      if ($_GET['action'] == 'delete')
420        {
421          $html->form_confirm('propal.php?propalid='.$propal->id, $langs->trans('DeleteProp'), $langs->trans('ConfirmDeleteProp'), 'confirm_delete');
422          print '<br>';
423        }
424    
425    
426      /*
427       * Fiche propal
428       *
429       */
430      $sql = 'SELECT s.nom, s.idp, p.price, p.fk_projet, p.remise, p.tva, p.total, p.ref, p.fk_statut, '.$db->pdate('p.datep').' as dp, p.note,';
431      $sql.= ' x.firstname, x.name, x.fax, x.phone, x.email, p.fk_user_author, p.fk_user_valid, p.fk_user_cloture, p.datec, p.date_valid, p.date_cloture';
432      $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p, '.MAIN_DB_PREFIX.'socpeople as x';
433      $sql.= ' WHERE p.fk_soc = s.idp AND p.fk_soc_contact = x.idp AND p.rowid = '.$propal->id;
434      if ($socidp) $sql .= ' AND s.idp = '.$socidp;
435    
436      $result = $db->query($sql);
437      if ($result)
438        {
439          if ($db->num_rows($result))
440            {
441              $obj = $db->fetch_object($result);
442    
443              $societe = new Societe($db);
444              $societe->fetch($obj->idp);
445    
446              print '<table class="border" width="100%">';
447              $rowspan=6;
448              print '<tr><td>'.$langs->trans('Company').'</td><td colspan="3">';
449              if ($societe->client == 1)
450                {
451                  $url ='fiche.php?socid='.$societe->id;
452                }
453              else
454                {
455                  $url = DOL_URL_ROOT.'/comm/prospect/fiche.php?socid='.$societe->id;
456                }
457              print '<a href="'.$url.'">'.$societe->nom.'</a></td>';
458              print '<td align="left">Conditions de réglement</td>';
459              print '<td>'.'&nbsp;'.'</td>';
460              print '</tr>';
461    
462              print '<tr><td>'.$langs->trans('Date').'</td><td colspan="3">';
463              print dolibarr_print_date($propal->date,'%a %e %B %Y');
464              print '</td>';
465    
466              print '<td>'.$langs->trans('DateEndPropal').'</td><td>';
467              if ($propal->fin_validite)
468                {
469                  print dolibarr_print_date($propal->fin_validite);
470                }
471              else {
472                print $langs->trans("Unknown");  
473              }
474              print '</td>';
475              print '</tr>';
476    
477              // Destinataire
478              $langs->load('mails');
479              print '<tr>';
480              print '<td>'.$langs->trans('MailTo').'</td>';
481    
482              $dests=$societe->contact_array($societe->id);
483              $numdest = count($dests);
484              if ($numdest==0)
485                {
486                  print '<td colspan="3">';
487                  print '<font class="error">Cette societe n\'a pas de contact, veuillez en créer un avant de faire votre proposition commerciale</font><br>';
488                  print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?socid='.$societe->id.'&amp;action=create&amp;backtoreferer=1">'.$langs->trans('AddContact').'</a>';
489                  print '</td>';
490                }
491              else
492                {
493                  if ($propal->statut == 0 && $user->rights->propale->creer)
494                  {                  {
495                          $obj = $db->fetch_object($result);                    print '<td colspan="2">';
496                      print '<form action="propal.php?propalid='.$propal->id.'" method="post">';
497                          $societe = new Societe($db);                    print '<input type="hidden" name="action" value="set_contact">';
498                          $societe->fetch($obj->idp);                    $form->select_contacts($societe->id, $propal->contactid, 'contactidp');
499                      print '</td><td>';
500                          print '<table class="border" width="100%">';                    print '<input type="submit" value="'.$langs->trans('Modify').'">';
501                          $rowspan=6;                    print '</form>';
502                          print '<tr><td>'.$langs->trans('Company').'</td><td colspan="3">';                    print '</td>';
                         if ($societe->client == 1)  
                         {  
                                 $url ='fiche.php?socid='.$societe->id;  
                         }  
                         else  
                         {  
                                 $url = DOL_URL_ROOT.'/comm/prospect/fiche.php?socid='.$societe->id;  
                         }  
                         print '<a href="'.$url.'">'.$societe->nom.'</a></td>';  
                         print '<td align="left">Conditions de réglement</td>';  
                         print '<td>'.'&nbsp;'.'</td>';  
                         print '</tr>';  
   
                         print '<tr><td>'.$langs->trans('Date').'</td><td colspan="3">';  
                         print dolibarr_print_date($propal->date);  
                         print '</td>';  
   
                         print '<td>'.$langs->trans('DateEndPropal').'</td><td>';  
                         if ($propal->fin_validite)  
                         {  
                                 print dolibarr_print_date($propal->fin_validite);  
                         }  
                         else {  
                             print $langs->trans("Unknown");    
                         }  
                         print '</td>';  
                         print '</tr>';  
   
             // Destinataire  
                         $langs->load('mails');  
                         print '<tr>';  
                         print '<td>'.$langs->trans('MailTo').'</td>';  
   
                         $dests=$societe->contact_array($societe->id);  
                         $numdest = count($dests);  
                         if ($numdest==0)  
                         {  
                         print '<td colspan="3">';  
                                 print '<font class="error">Cette societe n\'a pas de contact, veuillez en créer un avant de faire votre proposition commerciale</font><br>';  
                                 print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?socid='.$societe->id.'&amp;action=create&amp;backtoreferer=1">'.$langs->trans('AddContact').'</a>';  
                 print '</td>';  
                         }  
                         else  
                         {  
                                 if ($propal->statut == 0 && $user->rights->propale->creer)  
                                 {  
                                 print '<td colspan="2">';  
                                         print '<form action="propal.php?propalid='.$propal->id.'" method="post">';  
                                         print '<input type="hidden" name="action" value="set_contact">';  
                                         $form->select_contacts($societe->id, $propal->contactid, 'contactidp');  
                     print '</td><td>';  
                                         print '<input type="submit" value="'.$langs->trans('Modify').'">';  
                                         print '</form>';  
                     print '</td>';  
                                 }  
                                 else  
                                 {  
                                         if (!empty($propal->contactid))  
                                         {  
                                 print '<td colspan="3">';  
                                                 require_once(DOL_DOCUMENT_ROOT.'/contact.class.php');  
                                                 $contact=new Contact($db);  
                                                 $contact->fetch($propal->contactid);  
                                                 print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$propal->contactid.'" title="'.$langs->trans('ShowContact').'">';  
                                                 print $contact->firstname.' '.$contact->name;  
                                                 print '</a>';  
                         print '</td>';  
                                         }  
                                         else {  
                                     print '<td colspan="3">&nbsp;</td>';  
                     }  
                                 }  
                         }  
                         print '</td>';  
   
                         if ($conf->projet->enabled)  
                                 $rowspan++;  
   
                         print '<td valign="top" colspan="2" width="50%" rowspan="'.$rowspan.'">'.$langs->trans('Note').' :<br>'. nl2br($propal->note).'</td></tr>';  
   
                         if ($conf->projet->enabled)  
                         {  
                         print '<tr><td>'.$langs->trans('Project').'</td>';  
                                 $langs->load('projects');  
                                 $numprojet = $societe->has_projects();  
                                 if (! $numprojet)  
                                 {  
                                 print '<td colspan="2">';  
                                         print $langs->trans("NoProject").'</td><td>';  
                                         print '<a href=../projet/fiche.php?socidp='.$societe->id.'&action=create>'.$langs->trans('AddProject').'</a>';  
                                         print '</td>';  
                                 }  
                                 else  
                                 {  
                                         if ($propal->statut == 0 && $user->rights->propale->creer)  
                                         {  
                                     print '<td colspan="2">';  
                                                 print '<form action="propal.php?propalid='.$propal->id.'" method="post">';  
                                                 print '<input type="hidden" name="action" value="set_project">';  
                                                 $form->select_projects($societe->id, $propal->projetidp, 'projetidp');  
                                                 print '</td><td>';  
                                                 print '<input type="submit" value="'.$langs->trans('Modify').'">';  
                                                 print '</form>';  
                                                 print '</td>';  
                                         }  
                                         else  
                                         {  
                                                 if (!empty($propal->projetidp))  
                                                 {  
                                             print '<td colspan="3">';  
                                                         $proj = new Project($db);  
                                                         $proj->fetch($propal->projetidp);  
                                                         print '<a href="../projet/fiche.php?id='.$propal->projetidp.'" title="'.$langs->trans('ShowProject').'">';  
                                                         print $proj->title;  
                                                         print '</a>';  
                                                         print '</td>';  
                                                 }  
                                                 else {  
                                             print '<td colspan="3">&nbsp;</td>';  
                         }  
                                         }  
                                 }  
                         print '</tr>';  
                         }  
   
                         print '<tr><td height="10" nowrap>'.$langs->trans('GlobalDiscount').'</td>';  
                         if ($propal->brouillon == 1 && $user->rights->propale->creer)  
                         {  
                                 print '<form action="propal.php?propalid='.$propal->id.'" method="post">';  
                                 print '<input type="hidden" name="action" value="setremise">';  
                                 print '<td colspan="2"><input type="text" name="remise" size="3" value="'.$propal->remise_percent.'">% ';  
                                 print '</td><td>';  
                                 print '<input type="submit" value="'.$langs->trans('Modify').'">';  
                                 print ' <a href="propal/aideremise.php?propalid='.$propal->id.'">?</a>';  
                                 print '</td>';  
                                 print '</form>';  
                         }  
                         else  
                         {  
                                 print '<td colspan="3">'.$propal->remise_percent.'%</td>';  
                         }  
                         print '</tr>';  
   
                         print '<tr><td height="10">'.$langs->trans('AmountHT').'</td>';  
                         print '<td align="right" colspan="2"><b>'.price($obj->price).'</b></td>';  
                         print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';  
   
                         print '<tr><td height="10">'.$langs->trans('VAT').'</td><td align="right" colspan="2">'.price($propal->total_tva).'</td>';  
                         print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';  
                         print '<tr><td height="10">'.$langs->trans('AmountTTC').'</td><td align="right" colspan="2">'.price($propal->total_ttc).'</td>';  
                         print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';  
                         print '<tr><td height="10">'.$langs->trans('Status').'</td><td align="left" colspan="3">'.$propal->getLibStatut().'</td></tr>';  
                         print '</table><br>';  
                         if ($propal->brouillon == 1 && $user->rights->propale->creer)  
                         {  
                                 print '</form>';  
                         }  
   
                         /*  
                          * Lignes de propale  
                          *  
                          */  
                         $sql = 'SELECT pt.rowid, pt.description, pt.price, pt.fk_product, pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, p.label as product, p.ref, p.fk_product_type, p.rowid as prodid';  
                         $sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product=p.rowid';  
                         $sql .= ' WHERE pt.fk_propal = '.$propal->id;  
                         $sql .= ' ORDER BY pt.rowid ASC';  
                         $result = $db->query($sql);  
                         if ($result)  
                         {  
                                 $num_lignes = $db->num_rows($result);  
                                 $i = 0;  
                                 $total = 0;  
   
                                 print '<table class="noborder" width="100%">';  
                                 if ($num_lignes)  
                                 {  
                                         print '<tr class="liste_titre">';  
                                         print '<td width="54%">'.$langs->trans('Description').'</td>';  
                                         print '<td width="8%" align="right">'.$langs->trans('VAT').'</td>';  
                                         print '<td width="12%" align="right">'.$langs->trans('PriceUHT').'</td>';  
                                         print '<td width="8%" align="right">'.$langs->trans('Qty').'</td>';  
                                         print '<td width="8%" align="right">'.$langs->trans('Discount').'</td>';  
                                         print '<td width="10%" align="right">'.$langs->trans('AmountHT').'</td>';  
                                         print '<td>&nbsp;</td><td>&nbsp;</td>';  
                                         print "</tr>\n";  
                                 }  
                                 $var=True;  
                                 while ($i < $num_lignes)  
                                 {  
                                         $objp = $db->fetch_object($result);  
                                         $var=!$var;  
                                         if ($_GET['action'] != 'editline' || $_GET['rowid'] != $objp->rowid)  
                                         {  
                                                 print '<tr '.$bc[$var].'>';  
                                                 if ($objp->fk_product > 0)  
                                                 {  
                                                         print '<td><a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">';  
                                                         if ($objp->fk_product_type)  
                                                                 print img_object($langs->trans('ShowService'),'service');  
                                                         else  
                                                                 print img_object($langs->trans('ShowProduct'),'product');  
                                                         print ' '.stripslashes(nl2br($objp->description?$objp->description:$objp->product)).'</a>';  
                                                         if ($objp->date_start && $objp->date_end)  
                                                         {  
                                                                 print ' (Du '.dolibarr_print_date($objp->date_start).' au '.dolibarr_print_date($objp->date_end).')';  
                                                         }  
                                                         if ($objp->date_start && ! $objp->date_end)  
                                                         {  
                                                                 print ' (A partir du '.dolibarr_print_date($objp->date_start).')';  
                                                         }  
                                                         if (! $objp->date_start && $objp->date_end)  
                                                         {  
                                                                 print " (Jusqu'au ".dolibarr_print_date($objp->date_end).')';  
                                                         }  
                                                         print '</td>';  
                                                 }  
                                                 else  
                                                 {  
                                                         print '<td>'.stripslashes(nl2br($objp->description));  
                                                         if ($objp->date_start && $objp->date_end)  
                                                         {  
                                                                 print ' (Du '.dolibarr_print_date($objp->date_start).' au '.dolibarr_print_date($objp->date_end).')';  
                                                         }  
                                                         if ($objp->date_start && ! $objp->date_end)  
                                                         {  
                                                                 print ' (A partir du '.dolibarr_print_date($objp->date_start).')';  
                                                         }  
                                                         if (! $objp->date_start && $objp->date_end)  
                                                         {  
                                                                 print " (Jusqu'au ".dolibarr_print_date($objp->date_end).')';  
                                                         }  
                                                         print "</td>\n";  
                                                 }  
                                                 print '<td align="right">'.$objp->tva_tx.' %</td>';  
                                                 print '<td align="right">'.price($objp->subprice)."</td>\n";  
                                                 print '<td align="right">'.$objp->qty.'</td>';  
                                                 if ($objp->remise_percent > 0)  
                                                 {  
                                                         print '<td align="right">'.$objp->remise_percent." %</td>\n";  
                                                 }  
                                                 else  
                                                 {  
                                                         print '<td>&nbsp;</td>';  
                                                 }  
                                                 print '<td align="right">'.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100)."</td>\n";  
   
                                                 // Icone d'edition et suppression  
                                                 if ($propal->statut == 0  && $user->rights->propale->creer)  
                                                 {  
                                                         print '<td align="right"><a href="propal.php?propalid='.$propal->id.'&amp;action=editline&amp;ligne='.$objp->rowid.'">';  
                                                         print img_edit();  
                                                         print '</a></td>';  
                                                         print '<td align="right"><a href="propal.php?propalid='.$propal->id.'&amp;action=del_ligne&amp;ligne='.$objp->rowid.'">';  
                                                         print img_delete();  
                                                         print '</a></td>';  
                                                 }  
                                                 else  
                                                 {  
                                                         print '<td>&nbsp;</td><td>&nbsp;</td>';  
                                                 }  
                                                 print '</tr>';  
                                         }  
                                         // Update ligne de propal  
                                         // \todo  
   
   
                                         $total = $total + ($objp->qty * $objp->price);  
                                         $i++;  
                                 }  
                                 $db->free($result);  
                         }  
                         else  
                         {  
                                 dolibarr_print_error($db);  
                         }  
   
                         /*  
                          * Ajouter une ligne  
                          *  
                          */  
                         if ($propal->statut == 0 && $user->rights->propale->creer)  
                         {  
                                 print '<form action="propal.php?propalid='.$propal->id.'" method="post">';  
                                 print '<tr class="liste_titre">';  
                                 print '<td width="54%">'.$langs->trans('Description').'</td>';  
                                 print '<td width="8%" align="right">'.$langs->trans('VAT').'</td>';  
                                 print '<td width="12%" align="right">'.$langs->trans('PriceUHT').'</td>';  
                                 print '<td width="8%" align="right">'.$langs->trans('Qty').'</td>';  
                                 print '<td width="8%" align="right">'.$langs->trans('Discount').'</td>';  
                                 print '<td>&nbsp;</td>';  
                                 print '<td>&nbsp;</td>';  
                                 print '<td>&nbsp;</td>';  
                                 print "</tr>\n";  
                                 print '<input type="hidden" name="propid" value="'.$propal->id.'">';  
                                 print '<input type="hidden" name="action" value="addligne">';  
   
                                 // Ajout produit produits/services personalisés  
                                 $var=true;  
                                 print '<tr '.$bc[$var].">\n";  
                                 print '  <td><textarea cols="50" name="np_desc"></textarea></td>';  
                                 print '  <td align="center">';  
                                 print $html->select_tva('np_tva_tx', $conf->defaulttx) . "</td>\n";  
                                 print '  <td align="right"><input type="text" size="6" name="np_price"></td>';  
                                 print '  <td align="right"><input type="text" size="3" value="1" name="np_qty"></td>';  
                                 print '  <td align="right"><input type="text" size="3" value="'.$societe->remise_client.'" name="np_remise"> %</td>';  
                                 print '  <td align="center" colspan="3"><input type="submit" value="'.$langs->trans('Add').'" name="addproduct"></td>';  
                                 print '</tr>';  
   
                                 // Ajout de produits/services prédéfinis  
                                 $var=!$var;  
                                 print '<tr '.$bc[$var].'>';  
                                 print '<td colspan="2">';  
                                 $html->select_produits('','idprod','',20);  
                                 print '</td>';  
                                 print '<td>&nbsp;</td>';  
                                 print '<td align="right"><input type="text" size="3" name="qty" value="1"></td>';  
                                 print '<td align="right"><input type="text" size="3" name="remise" value="'.$societe->remise_client.'"> %</td>';  
                                 print '<td align="center" colspan="3"><input type="submit" value="'.$langs->trans("Add").'" name="addligne"></td>';  
                                 print "</tr>\n";  
                                 print '</form>';  
                         }  
   
                         print '</table>';  
   
503                  }                  }
504          }                else
         else  
         {  
                 dolibarr_print_error($db);  
         }  
   
         print '</div>';  
   
     /*  
      * Formulaire cloture (signé ou non)  
      */  
         if ($_GET['action'] == 'statut')  
         {  
                 print '<form action="propal.php?propalid='.$propal->id.'" method="post">';  
                 print '<table class="border" width="100%">';  
                 print '<tr><td>'.$langs->trans("CloseAs").': ';  
                 print '<input type="hidden" name="action" value="setstatut">';  
                 print '<select name="statut">';  
                 print '<option value="2">'.$propal->labelstatut[2].'</option>';  
                 print '<option value="3">'.$propal->labelstatut[3].'</option>';  
                 print '</select>';  
                 print '</td></tr><tr><td>'.$langs->trans('Note').': <br><textarea cols="60" rows="4" wrap="soft" name="note">';  
                 print $obj->note;  
                 print '</textarea></td></tr><tr><td align="center"><input type="submit" value="'.$langs->trans('Valid').'"></td>';  
                 print '</tr></table></form>';  
         }  
   
   
         /*  
          * Barre d'actions  
          */  
         if ($propal->statut < 2)  
         {  
                 print '<div class="tabsAction">';  
   
                 // Valid  
                 if ($propal->statut == 0)  
                 {  
                         if ($user->rights->propale->valider)  
                         {  
                                 print '<a class="butAction" href="propal.php?propalid='.$propal->id.'&amp;valid=1">'.$langs->trans('Valid').'</a>';  
                         }  
                 }  
   
                 // Save  
                 if ($propal->statut == 1)  
505                  {                  {
506                          if ($user->rights->propale->creer)                    if (!empty($propal->contactid))
507                          {                      {
508                                  print '<a class="butAction" href="propal.php?propalid='.$propal->id.'&amp;action=modif">'.$langs->trans('Edit').'</a>';                        print '<td colspan="3">';
509                          }                        require_once(DOL_DOCUMENT_ROOT.'/contact.class.php');
510                          $contact=new Contact($db);
511                          $contact->fetch($propal->contactid);
512                          print '<a href="'.DOL_URL_ROOT.'/contact/fiche.php?id='.$propal->contactid.'" title="'.$langs->trans('ShowContact').'">';
513                          print $contact->firstname.' '.$contact->name;
514                          print '</a>';
515                          print '</td>';
516                        }
517                      else {
518                        print '<td colspan="3">&nbsp;</td>';
519                      }
520                  }                  }
521                }
522              print '</td>';
523    
524                  // Build PDF            if ($conf->projet->enabled)
525                  if ($propal->statut < 2 && $user->rights->propale->creer)              $rowspan++;
                 {  
                         print '<a class="butAction" href="propal.php?propalid='.$propal->id.'&amp;action=pdf">'.$langs->trans('BuildPDF').'</a>';  
                 }            
526    
527                  // Send            print '<td valign="top" colspan="2" width="50%" rowspan="'.$rowspan.'">'.$langs->trans('Note').' :<br>'. nl2br($propal->note).'</td></tr>';
                 if ($propal->statut == 1)  
                 {  
                         if ($user->rights->propale->envoyer)  
                         {  
                                 $propref = sanitize_string($obj->ref);  
                                 $file = $conf->propal->dir_output . '/'.$propref.'/'.$propref.'.pdf';  
                                 if (file_exists($file))  
                                 {  
                                         print '<a class="butAction" href="propal.php?propalid='.$propal->id.'&amp;action=presend">'.$langs->trans('Send').'</a>';  
                                 }  
                         }  
                 }  
528    
529                  // Close            if ($conf->projet->enabled)
530                  if ($propal->statut != 0)              {
531                  print '<tr><td>'.$langs->trans('Project').'</td>';
532                  $langs->load('projects');
533                  $numprojet = $societe->has_projects();
534                  if (! $numprojet)
535                  {                  {
536                          if ($propal->statut == 1 && $user->rights->propale->cloturer)                    print '<td colspan="2">';
537                          {                    print $langs->trans("NoProject").'</td><td>';
538                                  print '<a class="butAction" href="propal.php?propalid='.$propal->id.'&amp;action=statut">'.$langs->trans('Close').'</a>';                    print '<a href=../projet/fiche.php?socidp='.$societe->id.'&action=create>'.$langs->trans('AddProject').'</a>';
539                          }                    print '</td>';
540                  }                  }
541                  else
                 // Delete  
                 if ($propal->statut == 0)  
542                  {                  {
543                          if ($user->rights->propale->supprimer)                    if ($propal->statut == 0 && $user->rights->propale->creer)
544                          {                      {
545                                  print '<a class="butActionDelete" href="propal.php?propalid='.$propal->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';                        print '<td colspan="2">';
546                          }                        print '<form action="propal.php?propalid='.$propal->id.'" method="post">';
547                          print '<input type="hidden" name="action" value="set_project">';
548                          $form->select_projects($societe->id, $propal->projetidp, 'projetidp');
549                          print '</td><td>';
550                          print '<input type="submit" value="'.$langs->trans('Modify').'">';
551                          print '</form>';
552                          print '</td>';
553                        }
554                      else
555                        {
556                          if (!empty($propal->projetidp))
557                            {
558                              print '<td colspan="3">';
559                              $proj = new Project($db);
560                              $proj->fetch($propal->projetidp);
561                              print '<a href="../projet/fiche.php?id='.$propal->projetidp.'" title="'.$langs->trans('ShowProject').'">';
562                              print $proj->title;
563                              print '</a>';
564                              print '</td>';
565                            }
566                          else {
567                            print '<td colspan="3">&nbsp;</td>';
568                          }
569                        }
570                  }                  }
571                  print '</tr>';
572                }
573    
574                  print '</div>';            print '<tr><td height="10" nowrap>'.$langs->trans('GlobalDiscount').'</td>';
575          }            if ($propal->brouillon == 1 && $user->rights->propale->creer)
576                {
577                  print '<form action="propal.php?propalid='.$propal->id.'" method="post">';
578          print '<table width="100%"><tr><td width="50%" valign="top">';                print '<input type="hidden" name="action" value="setremise">';
579                  print '<td colspan="2"><input type="text" name="remise" size="3" value="'.$propal->remise_percent.'">% ';
580                  print '</td><td>';
581                  print '<input type="submit" value="'.$langs->trans('Modify').'">';
582                  print ' <a href="propal/aideremise.php?propalid='.$propal->id.'">?</a>';
583                  print '</td>';
584                  print '</form>';
585                }
586              else
587                {
588                  print '<td colspan="3">'.$propal->remise_percent.'%</td>';
589                }
590              print '</tr>';
591    
592              print '<tr><td height="10">'.$langs->trans('AmountHT').'</td>';
593              print '<td align="right" colspan="2"><b>'.price($propal->price).'</b></td>';
594              print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
595    
596              print '<tr><td height="10">'.$langs->trans('VAT').'</td><td align="right" colspan="2">'.price($propal->total_tva).'</td>';
597              print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
598              print '<tr><td height="10">'.$langs->trans('AmountTTC').'</td><td align="right" colspan="2">'.price($propal->total_ttc).'</td>';
599              print '<td>'.$langs->trans("Currency".$conf->monnaie).'</td></tr>';
600              print '<tr><td height="10">'.$langs->trans('Status').'</td><td align="left" colspan="3">'.$propal->getLibStatut().'</td></tr>';
601              print '</table><br>';
602              if ($propal->brouillon == 1 && $user->rights->propale->creer)
603                {
604                  print '</form>';
605                }
606    
607              /*
608               * Lignes de propale
609               *
610               */
611              $sql = 'SELECT pt.rowid, pt.description, pt.price, pt.fk_product, pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, p.label as product, p.ref, p.fk_product_type, p.rowid as prodid';
612              $sql .= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product=p.rowid';
613              $sql .= ' WHERE pt.fk_propal = '.$propal->id;
614              $sql .= ' ORDER BY pt.rowid ASC';
615              $result = $db->query($sql);
616              if ($result)
617                {
618                  $num_lignes = $db->num_rows($result);
619                  $i = 0;
620                  $total = 0;
621    
622          /*                print '<table class="noborder" width="100%">';
623           * Documents                if ($num_lignes)
          */  
         if ($propal->brouillon == 1)  
         {  
                 print '<form action="propal.php?propalid='.$propal->id.'" method="post">';  
                 print '<input type="hidden" name="action" value="setpdfmodel">';  
         }  
         print_titre($langs->trans('Documents'));  
   
         print '<table class="border" width="100%">';  
         $propref = sanitize_string($propal->ref);  
         $file = $conf->propal->dir_output . '/'.$propref.'/'.$propref.'.pdf';  
         $relativepath = $propref.'/'.$propref.'.pdf';  
   
         $var=true;  
   
         if (file_exists($file))  
         {  
                 print '<tr '.$bc[$var].'><td>'.$langs->trans('Propal').' PDF</td>';  
                 print '<td><a href="'.DOL_URL_ROOT . '/document.php?modulepart=propal&file='.urlencode($relativepath).'">'.$propal->ref.'.pdf</a></td>';  
                 print '<td align="right">'.filesize($file). ' bytes</td>';  
                 print '<td align="right">'.strftime('%d %B %Y %H:%M:%S',filemtime($file)).'</td></tr>';  
         }  
   
         if ($propal->brouillon == 1 && $user->rights->propale->creer)  
         {  
                 print '<tr '.$bc[$var].'><td>Modèle</td><td align="right">';  
                 $html = new Form($db);  
                 $modelpdf = new Propal_Model_pdf($db);  
                 $html->select_array('modelpdf',$modelpdf->liste_array(),$propal->modelpdf);  
                 print '</td><td colspan="2"><input type="submit" value="'.$langs->trans('Save').'">';  
                 print '</td></tr>';  
         }  
         print "</table>\n";  
   
         if ($propal->brouillon == 1)  
         {  
                 print '</form>';  
         }  
   
   
         /*  
          * Commandes rattachées  
          */  
         if($conf->commande->enabled)  
         {  
         $coms = $propal->associated_orders();  
                 if (sizeof($coms) > 0)  
624                  {                  {
625                  print '<br>';                    print '<tr class="liste_titre">';
626                  print_titre($langs->trans('RelatedOrders'));                    print '<td width="54%">'.$langs->trans('Description').'</td>';
627                          print '<table class="noborder" width="100%">';                    print '<td width="8%" align="right">'.$langs->trans('VAT').'</td>';
628                      print '<tr class="liste_titre">';                    print '<td width="12%" align="right">'.$langs->trans('PriceUHT').'</td>';
629                      print '<td>'.$langs->trans("Ref").'</td>';                    print '<td width="8%" align="right">'.$langs->trans('Qty').'</td>';
630                      print '<td align="center">'.$langs->trans("Date").'</td>';                    print '<td width="8%" align="right">'.$langs->trans('Discount').'</td>';
631                      print '<td align="right">'.$langs->trans("Price").'</td>';                    print '<td width="10%" align="right">'.$langs->trans('AmountHT').'</td>';
632                      print '</tr>';                    print '<td>&nbsp;</td><td>&nbsp;</td>';
633                  $var=true;                    print "</tr>\n";
                 for ($i = 0 ; $i < sizeof($coms) ; $i++)  
                         {  
                             $var=!$var;  
                                 print '<tr '.$bc[$var].'><td>';  
                                 print '<a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$coms[$i]->id.'">'.img_object($langs->trans("ShowOrder"),"order").' '.$coms[$i]->ref."</a></td>\n";  
                                 print '<td align="center">'.dolibarr_print_date($coms[$i]->date).'</td>';  
                                 print '<td align="right">'.$coms[$i]->total_ttc.'</td>';  
                                 print "</tr>\n";  
                         }  
                         print '</table>';  
634                  }                  }
635          }                $var=True;
636                  while ($i < $num_lignes)
637                    {
638                      $objp = $db->fetch_object($result);
639                      $var=!$var;
640                      if ($_GET['action'] != 'editline' || $_GET['rowid'] != $objp->rowid)
641                        {
642                          print '<tr '.$bc[$var].'>';
643                          if ($objp->fk_product > 0)
644                            {
645                              print '<td><a href="'.DOL_URL_ROOT.'/product/fiche.php?id='.$objp->fk_product.'">';
646                              if ($objp->fk_product_type)
647                                print img_object($langs->trans('ShowService'),'service');
648                              else
649                                print img_object($langs->trans('ShowProduct'),'product');
650                              print ' '.stripslashes(nl2br($objp->description?$objp->description:$objp->product)).'</a>';
651                              if ($objp->date_start && $objp->date_end)
652                                {
653                                  print ' (Du '.dolibarr_print_date($objp->date_start).' au '.dolibarr_print_date($objp->date_end).')';
654                                }
655                              if ($objp->date_start && ! $objp->date_end)
656                                {
657                                  print ' (A partir du '.dolibarr_print_date($objp->date_start).')';
658                                }
659                              if (! $objp->date_start && $objp->date_end)
660                                {
661                                  print " (Jusqu'au ".dolibarr_print_date($objp->date_end).')';
662                                }
663                              print '</td>';
664                            }
665                          else
666                            {
667                              print '<td>'.stripslashes(nl2br($objp->description));
668                              if ($objp->date_start && $objp->date_end)
669                                {
670                                  print ' (Du '.dolibarr_print_date($objp->date_start).' au '.dolibarr_print_date($objp->date_end).')';
671                                }
672                              if ($objp->date_start && ! $objp->date_end)
673                                {
674                                  print ' (A partir du '.dolibarr_print_date($objp->date_start).')';
675                                }
676                              if (! $objp->date_start && $objp->date_end)
677                                {
678                                  print " (Jusqu'au ".dolibarr_print_date($objp->date_end).')';
679                                }
680                              print "</td>\n";
681                            }
682                          print '<td align="right">'.$objp->tva_tx.' %</td>';
683                          print '<td align="right">'.price($objp->subprice)."</td>\n";
684                          print '<td align="right">'.$objp->qty.'</td>';
685                          if ($objp->remise_percent > 0)
686                            {
687                              print '<td align="right">'.$objp->remise_percent." %</td>\n";
688                            }
689                          else
690                            {
691                              print '<td>&nbsp;</td>';
692                            }
693                          print '<td align="right">'.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100)."</td>\n";
694    
695                          // Icone d'edition et suppression
696                          if ($propal->statut == 0  && $user->rights->propale->creer)
697                            {
698                              print '<td align="right"><a href="propal.php?propalid='.$propal->id.'&amp;action=editline&amp;ligne='.$objp->rowid.'">';
699                              print img_edit();
700                              print '</a></td>';
701                              print '<td align="right"><a href="propal.php?propalid='.$propal->id.'&amp;action=del_ligne&amp;ligne='.$objp->rowid.'">';
702                              print img_delete();
703                              print '</a></td>';
704                            }
705                          else
706                            {
707                              print '<td>&nbsp;</td><td>&nbsp;</td>';
708                            }
709                          print '</tr>';
710                        }
711                      // Update ligne de propal
712                      // \todo
713    
714                      if ($propal->statut == 0 && $user->rights->propale->creer && $_GET["action"] == 'editline' && $_GET["ligne"] == $objp->rowid)
715                        {
716                          print '<form action="propal.php?propalid='.$propal->id.'" method="post">';
717                          print '<input type="hidden" name="action" value="updateligne">';
718                          print '<input type="hidden" name="ligne" value="'.$_GET["ligne"].'">';
719                          print '<tr '.$bc[$var].'>';
720                          print '<td colspan="2">&nbsp;</td>';
721                          print '<td align="right"><input name="subprice" type="text" size="6" value="'.$objp->subprice.'"></td>';
722                          print '<td align="right"><input name="qty" type="text" size="3" value="'.$objp->qty.'"></td>';
723                          print '<td align="right"><input name="remise" type="text" size="4" value="'.$objp->remise_percent.'"> %</td>';
724                          print '<td>&nbsp;</td>';
725                          print '<td align="center" colspan="2"><input type="submit"></td>';
726                          print '</tr></form>';
727    
728          print '</td><td valign="top" width="50%">';                      }
729                      //
730    
731          /*                    $total = $total + ($objp->qty * $objp->price);
732           * Liste des actions propres à la propal                    $i++;
733           */                  }
734          $sql = 'SELECT id, '.$db->pdate('a.datea'). ' as da, label, note, fk_user_author' ;                $db->free($result);
735          $sql .= ' FROM '.MAIN_DB_PREFIX.'actioncomm as a';              }
736          $sql .= ' WHERE a.fk_soc = '.$obj->idp.' AND a.propalrowid = '.$propal->id ;            else
737          $result = $db->query($sql);              {
738          if ($result)                dolibarr_print_error($db);
739          {              }
740                  $num = $db->num_rows($result);  
741                  if ($num)            /*
742               * Ajouter une ligne
743               *
744               */
745              if ($propal->statut == 0 && $user->rights->propale->creer && $_GET["action"] <> 'editline')
746                {
747                  print '<form action="propal.php?propalid='.$propal->id.'" method="post">';
748                  print '<tr class="liste_titre">';
749                  print '<td width="54%">'.$langs->trans('Description').'</td>';
750                  print '<td width="8%" align="right">'.$langs->trans('VAT').'</td>';
751                  print '<td width="12%" align="right">'.$langs->trans('PriceUHT').'</td>';
752                  print '<td width="8%" align="right">'.$langs->trans('Qty').'</td>';
753                  print '<td width="8%" align="right">'.$langs->trans('Discount').'</td>';
754                  print '<td>&nbsp;</td>';
755                  print '<td>&nbsp;</td>';
756                  print '<td>&nbsp;</td>';
757                  print "</tr>\n";
758                  print '<input type="hidden" name="propid" value="'.$propal->id.'">';
759                  print '<input type="hidden" name="action" value="addligne">';
760    
761                  // Ajout produit produits/services personalisés
762                  $var=true;
763                  print '<tr '.$bc[$var].">\n";
764                  print '  <td><textarea cols="50" name="np_desc"></textarea></td>';
765                  print '  <td align="center">';
766                  print $html->select_tva('np_tva_tx', $conf->defaulttx) . "</td>\n";
767                  print '  <td align="right"><input type="text" size="6" name="np_price"></td>';
768                  print '  <td align="right"><input type="text" size="3" value="1" name="np_qty"></td>';
769                  print '  <td align="right"><input type="text" size="3" value="'.$societe->remise_client.'" name="np_remise"> %</td>';
770                  print '  <td align="center" colspan="3"><input type="submit" value="'.$langs->trans('Add').'" name="addproduct"></td>';
771                  print '</tr>';
772                  
773                  // Ajout de produits/services prédéfinis
774                  $var=!$var;
775                  print '<tr '.$bc[$var].'>';
776                  print '<td colspan="2">';
777                  $html->select_produits('','idprod','',20);
778                  print '</td>';
779                  print '<td>&nbsp;</td>';
780                  print '<td align="right"><input type="text" size="3" name="qty" value="1"></td>';
781                  print '<td align="right"><input type="text" size="3" name="remise" value="'.$societe->remise_client.'"> %</td>';
782                  print '<td align="center" colspan="3"><input type="submit" value="'.$langs->trans("Add").'" name="addligne"></td>';
783                  print "</tr>\n";
784                  print '</form>';
785                }
786              
787              print '</table>';
788              
789            }
790        }
791      else
792        {
793          dolibarr_print_error($db);
794        }
795      
796      print '</div>';
797    
798      /*
799       * Formulaire cloture (signé ou non)
800       */
801      if ($_GET['action'] == 'statut')
802        {
803          print '<form action="propal.php?propalid='.$propal->id.'" method="post">';
804          print '<table class="border" width="100%">';
805          print '<tr><td>'.$langs->trans("CloseAs").': ';
806          print '<input type="hidden" name="action" value="setstatut">';
807          print '<select name="statut">';
808          print '<option value="2">'.$propal->labelstatut[2].'</option>';
809          print '<option value="3">'.$propal->labelstatut[3].'</option>';
810          print '</select>';
811          print '</td></tr><tr><td>'.$langs->trans('Note').': <br><textarea cols="60" rows="4" wrap="soft" name="note">';
812          print $obj->note;
813          print '</textarea></td></tr><tr><td align="center"><input type="submit" value="'.$langs->trans('Valid').'"></td>';
814          print '</tr></table></form>';
815        }
816    
817    
818      /*
819       * Barre d'actions
820       */
821      if ($propal->statut < 2)
822        {
823          print '<div class="tabsAction">';
824    
825          // Valid
826          if ($propal->statut == 0)
827            {
828              if ($user->rights->propale->valider)
829                {
830                  print '<a class="butAction" href="propal.php?propalid='.$propal->id.'&amp;valid=1">'.$langs->trans('Valid').'</a>';
831                }
832            }
833    
834          // Save
835          if ($propal->statut == 1)
836            {
837              if ($user->rights->propale->creer)
838                {
839                  print '<a class="butAction" href="propal.php?propalid='.$propal->id.'&amp;action=modif">'.$langs->trans('Edit').'</a>';
840                }
841            }
842    
843          // Build PDF
844          if ($propal->statut < 2 && $user->rights->propale->creer)
845            {
846              print '<a class="butAction" href="propal.php?propalid='.$propal->id.'&amp;action=pdf">'.$langs->trans('BuildPDF').'</a>';
847            }          
848    
849          // Send
850          if ($propal->statut == 1)
851            {
852              if ($user->rights->propale->envoyer)
853                {
854                  $propref = sanitize_string($obj->ref);
855                  $file = $conf->propal->dir_output . '/'.$propref.'/'.$propref.'.pdf';
856                  if (file_exists($file))
857                  {                  {
858                          print_titre($langs->trans('ActionsOnPropal'));                    print '<a class="butAction" href="propal.php?propalid='.$propal->id.'&amp;action=presend">'.$langs->trans('Send').'</a>';
                         $i = 0;  
                         $total = 0;  
                         $var=true;  
   
                         print '<table class="border" width="100%">';  
                         print '<tr '.$bc[$var].'><td>'.$langs->trans('Ref').'</td><td>'.$langs->trans('Date').'</td><td>'.$langs->trans('Action').'</td><td>'.$langs->trans('By').'</td></tr>';  
                         print "\n";  
   
                         while ($i < $num)  
                         {  
                                 $objp = $db->fetch_object($result);  
                                 $var=!$var;  
                                 print '<tr '.$bc[$var].'>';  
                                 print '<td><a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?id='.$objp->id.'">'.img_object($langs->trans('ShowTask'),'task').' '.$objp->id.'</a></td>';  
                                 print '<td>'.dolibarr_print_date($objp->da)."</td>\n";  
                                 print '<td>'.stripslashes($objp->label).'</td>';  
                                 $authoract = new User($db);  
                                 $authoract->id = $objp->fk_user_author;  
                                 $authoract->fetch('');  
                                 print '<td>'.$authoract->code.'</td>';  
                                 print "</tr>\n";  
                                 $i++;  
                         }  
                         print '</table>';  
859                  }                  }
860                }
861          }          }
         else  
         {  
                 dolibarr_print_error($db);  
         }  
   
         print '</td></tr></table>';  
   
   
862    
863          /*        // Close
864           * Action presend        if ($propal->statut != 0)
          *  
          */  
         if ($_GET['action'] == 'presend')  
865          {          {
866          print '<br>';            if ($propal->statut == 1 && $user->rights->propale->cloturer)
867          print_titre($langs->trans('SendPropalByMail'));              {
868                  print '<a class="butAction" href="propal.php?propalid='.$propal->id.'&amp;action=statut">'.$langs->trans('Close').'</a>';
869                }
870            }
871    
872          // Delete
873          if ($propal->statut == 0)
874            {
875              if ($user->rights->propale->supprimer)
876                {
877                  print '<a class="butActionDelete" href="propal.php?propalid='.$propal->id.'&amp;action=delete">'.$langs->trans('Delete').'</a>';
878                }
879            }
880    
881          print '</div>';
882        }
883    
884    
885      print '<table width="100%"><tr><td width="50%" valign="top">';
886    
887      /*
888       * Documents
889       */
890      if ($propal->brouillon == 1)
891        {
892          print '<form action="propal.php?propalid='.$propal->id.'" method="post">';
893          print '<input type="hidden" name="action" value="setpdfmodel">';
894        }
895      print_titre($langs->trans('Documents'));
896    
897      print '<table class="border" width="100%">';
898      $propref = sanitize_string($propal->ref);
899      $file = $conf->propal->dir_output . '/'.$propref.'/'.$propref.'.pdf';
900      $relativepath = $propref.'/'.$propref.'.pdf';
901    
902      $var=true;
903    
904      if (file_exists($file))
905        {
906          print '<tr '.$bc[$var].'><td>'.$langs->trans('Propal').' PDF</td>';
907          print '<td><a href="'.DOL_URL_ROOT . '/document.php?modulepart=propal&file='.urlencode($relativepath).'">'.$propal->ref.'.pdf</a></td>';
908          print '<td align="right">'.filesize($file). ' bytes</td>';
909          print '<td align="right">'.strftime('%d %B %Y %H:%M:%S',filemtime($file)).'</td></tr>';
910        }
911    
912      if ($propal->brouillon == 1 && $user->rights->propale->creer)
913        {
914          print '<tr '.$bc[$var].'><td>Modèle</td><td align="right">';
915          $html = new Form($db);
916          $modelpdf = new Propal_Model_pdf($db);
917          $html->select_array('modelpdf',$modelpdf->liste_array(),$propal->modelpdf);
918          print '</td><td colspan="2"><input type="submit" value="'.$langs->trans('Save').'">';
919          print '</td></tr>';
920        }
921      print "</table>\n";
922    
923      if ($propal->brouillon == 1)
924        {
925          print '</form>';
926        }
927    
928    
929      /*
930       * Commandes rattachées
931       */
932      if($conf->commande->enabled)
933        {
934          $coms = $propal->associated_orders();
935          if (sizeof($coms) > 0)
936            {
937              print '<br>';
938              print_titre($langs->trans('RelatedOrders'));
939              print '<table class="noborder" width="100%">';
940              print '<tr class="liste_titre">';
941              print '<td>'.$langs->trans("Ref").'</td>';
942              print '<td align="center">'.$langs->trans("Date").'</td>';
943              print '<td align="right">'.$langs->trans("Price").'</td>';
944              print '</tr>';
945              $var=true;
946              for ($i = 0 ; $i < sizeof($coms) ; $i++)
947                {
948                  $var=!$var;
949                  print '<tr '.$bc[$var].'><td>';
950                  print '<a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$coms[$i]->id.'">'.img_object($langs->trans("ShowOrder"),"order").' '.$coms[$i]->ref."</a></td>\n";
951                  print '<td align="center">'.dolibarr_print_date($coms[$i]->date).'</td>';
952                  print '<td align="right">'.$coms[$i]->total_ttc.'</td>';
953                  print "</tr>\n";
954                }
955              print '</table>';
956            }
957        }
958    
959      print '</td><td valign="top" width="50%">';
960    
961      /*
962       * Liste des actions propres à la propal
963       */
964      $sql = 'SELECT id, '.$db->pdate('a.datea'). ' as da, label, note, fk_user_author' ;
965      $sql .= ' FROM '.MAIN_DB_PREFIX.'actioncomm as a';
966      $sql .= ' WHERE a.fk_soc = '.$obj->idp.' AND a.propalrowid = '.$propal->id ;
967      $result = $db->query($sql);
968      if ($result)
969        {
970          $num = $db->num_rows($result);
971          if ($num)
972            {
973              print_titre($langs->trans('ActionsOnPropal'));
974              $i = 0;
975              $total = 0;
976              $var=true;
977    
978              print '<table class="border" width="100%">';
979              print '<tr '.$bc[$var].'><td>'.$langs->trans('Ref').'</td><td>'.$langs->trans('Date').'</td><td>'.$langs->trans('Action').'</td><td>'.$langs->trans('By').'</td></tr>';
980              print "\n";
981    
982              while ($i < $num)
983                {
984                  $objp = $db->fetch_object($result);
985                  $var=!$var;
986                  print '<tr '.$bc[$var].'>';
987                  print '<td><a href="'.DOL_URL_ROOT.'/comm/action/fiche.php?id='.$objp->id.'">'.img_object($langs->trans('ShowTask'),'task').' '.$objp->id.'</a></td>';
988                  print '<td>'.dolibarr_print_date($objp->da)."</td>\n";
989                  print '<td>'.stripslashes($objp->label).'</td>';
990                  $authoract = new User($db);
991                  $authoract->id = $objp->fk_user_author;
992                  $authoract->fetch('');
993                  print '<td>'.$authoract->code.'</td>';
994                  print "</tr>\n";
995                  $i++;
996                }
997              print '</table>';
998            }
999        }
1000      else
1001        {
1002          dolibarr_print_error($db);
1003        }
1004    
1005      print '</td></tr></table>';
1006    
1007    
1008    
1009      /*
1010       * Action presend
1011       *
1012       */
1013      if ($_GET['action'] == 'presend')
1014        {
1015          print '<br>';
1016          print_titre($langs->trans('SendPropalByMail'));
1017    
1018          $liste[0]="&nbsp;";
1019          foreach ($societe->contact_email_array() as $key=>$value) {
1020            $liste[$key]=$value;
1021          }
1022    
1023          // Créé l'objet formulaire mail
1024          include_once('../html.formmail.class.php');
1025          $formmail = new FormMail($db);
1026          $formmail->fromname = $user->fullname;
1027          $formmail->frommail = $user->email;
1028          $formmail->withfrom=1;
1029          $formmail->withto=$liste;
1030          $formmail->withcc=1;
1031          $formmail->withtopic=$langs->trans('SendPropalRef','__PROPREF__');
1032          $formmail->withfile=1;
1033          $formmail->withbody=1;
1034          // Tableau des substitutions
1035          $formmail->substit['__PROPREF__']=$propal->ref;
1036          // Tableau des paramètres complémentaires
1037          $formmail->param['action']='send';
1038          $formmail->param['models']='propal_send';
1039          $formmail->param['propalid']=$propal->id;
1040          $formmail->param['returnurl']=DOL_URL_ROOT.'/comm/propal.php?propalid='.$propal->id;
1041    
1042          $liste[0]="&nbsp;";        $formmail->show_form();
1043          foreach ($societe->contact_email_array() as $key=>$value) {      }
             $liste[$key]=$value;  
         }  
   
                 // Créé l'objet formulaire mail  
                 include_once('../html.formmail.class.php');  
                 $formmail = new FormMail($db);  
                 $formmail->fromname = $user->fullname;  
                 $formmail->frommail = $user->email;  
                 $formmail->withfrom=1;  
         $formmail->withto=$liste;  
                 $formmail->withcc=1;  
                 $formmail->withtopic=$langs->trans('SendPropalRef','__PROPREF__');  
                 $formmail->withfile=1;  
                 $formmail->withbody=1;  
                 // Tableau des substitutions  
                 $formmail->substit['__PROPREF__']=$propal->ref;  
                 // Tableau des paramètres complémentaires  
                 $formmail->param['action']='send';  
                 $formmail->param['models']='propal_send';  
                 $formmail->param['propalid']=$propal->id;  
                 $formmail->param['returnurl']=DOL_URL_ROOT.'/comm/propal.php?propalid='.$propal->id;  
   
                 $formmail->show_form();  
         }  
1044    
1045  }  }
1046  else  else
1047  {  {
1048          /****************************************************************************    /****************************************************************************
1049           *                                                                          *     *                                                                          *
1050           *                         Mode Liste des propales                          *     *                         Mode Liste des propales                          *
1051           *                                                                          *     *                                                                          *
1052           ****************************************************************************/     ****************************************************************************/
1053    
1054          $sortorder=$_GET['sortorder'];    $sortorder=$_GET['sortorder'];
1055          $sortfield=$_GET['sortfield'];    $sortfield=$_GET['sortfield'];
1056          $page=$_GET['page'];    $page=$_GET['page'];
1057          $viewstatut=$_GET['viewstatut'];    $viewstatut=$_GET['viewstatut'];
1058    
1059          if (! $sortfield) $sortfield='p.datep';    if (! $sortfield) $sortfield='p.datep';
1060          if (! $sortorder) $sortorder='DESC';    if (! $sortorder) $sortorder='DESC';
1061          $limit = $conf->liste_limit;    $limit = $conf->liste_limit;
1062          $offset = $limit * $page ;    $offset = $limit * $page ;
1063          $pageprev = $page - 1;    $pageprev = $page - 1;
1064          $pagenext = $page + 1;    $pagenext = $page + 1;
1065    
1066          $sql = 'SELECT s.nom, s.idp, s.client, p.rowid as propalid, p.price, p.ref, p.fk_statut, '.$db->pdate('p.datep').' as dp,'.$db->pdate('p.fin_validite').' as dfv';    $sql = 'SELECT s.nom, s.idp, s.client, p.rowid as propalid, p.price, p.ref, p.fk_statut, '.$db->pdate('p.datep').' as dp,'.$db->pdate('p.fin_validite').' as dfv';
1067          $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p';    $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p';
1068          $sql.= ' WHERE p.fk_soc = s.idp';    $sql.= ' WHERE p.fk_soc = s.idp';
1069    
1070          if (!empty($_GET['search_ref']))    if (!empty($_GET['search_ref']))
1071          {      {
1072                  $sql .= " AND p.ref LIKE '%".$_GET['search_ref']."%'";        $sql .= " AND p.ref LIKE '%".$_GET['search_ref']."%'";
1073          }      }
1074          if (!empty($_GET['search_societe']))    if (!empty($_GET['search_societe']))
1075          {      {
1076                  $sql .= " AND s.nom LIKE '%".$_GET['search_societe']."%'";        $sql .= " AND s.nom LIKE '%".$_GET['search_societe']."%'";
1077          }      }
1078          if (!empty($_GET['search_montant_ht']))    if (!empty($_GET['search_montant_ht']))
1079          {      {
1080                  $sql .= " AND p.price='".$_GET['search_montant_ht']."'";        $sql .= " AND p.price='".$_GET['search_montant_ht']."'";
1081          }      }
1082          if ($_GET['socidp'])    if ($_GET['socidp'])
1083          {      {
1084                  $sql .= ' AND s.idp = '.$_GET['socidp'];        $sql .= ' AND s.idp = '.$_GET['socidp'];
1085          }      }
1086          if ($_GET['viewstatut'] <> '')    if ($_GET['viewstatut'] <> '')
1087          {      {
1088                  $sql .= ' AND p.fk_statut in ('.$_GET['viewstatut'].')';        $sql .= ' AND p.fk_statut in ('.$_GET['viewstatut'].')';
1089          }      }
1090          if ($month > 0)    if ($month > 0)
1091          {      {
1092                  $sql .= " AND date_format(p.datep, '%Y-%m') = '$year-$month'";        $sql .= " AND date_format(p.datep, '%Y-%m') = '$year-$month'";
1093          }      }
1094          if ($year > 0)    if ($year > 0)
1095          {      {
1096                  $sql .= " AND date_format(p.datep, '%Y') = $year";        $sql .= " AND date_format(p.datep, '%Y') = $year";
1097          }      }
1098          if (strlen($_POST['sf_ref']) > 0)    if (strlen($_POST['sf_ref']) > 0)
1099          {      {
1100                  $sql .= " AND p.ref like '%".$_POST["sf_ref"] . "%'";        $sql .= " AND p.ref like '%".$_POST["sf_ref"] . "%'";
1101          }      }
1102          $sql .= ' ORDER BY '.$sortfield.' '.$sortorder.', p.ref DESC';    $sql .= ' ORDER BY '.$sortfield.' '.$sortorder.', p.ref DESC';
1103          $sql .= $db->plimit($limit + 1,$offset);    $sql .= $db->plimit($limit + 1,$offset);
1104          $result=$db->query($sql);    $result=$db->query($sql);
1105    
1106          if ($result)    if ($result)
1107          {      {
1108                  $num = $db->num_rows($result);        $num = $db->num_rows($result);
1109                  print_barre_liste($langs->trans('ListOfProposals'), $page,'propal.php','&amp;socidp='.$socidp,$sortfield,$sortorder,'',$num);        print_barre_liste($langs->trans('ListOfProposals'), $page,'propal.php','&amp;socidp='.$socidp,$sortfield,$sortorder,'',$num);
1110                  $i = 0;        $i = 0;
1111                  print '<table class="noborder" width="100%">';        print '<table class="noborder" width="100%">';
1112                  print '<tr class="liste_titre">';        print '<tr class="liste_titre">';
1113                  print_liste_field_titre($langs->trans('Ref'),'propal.php','p.ref','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut,'',$sortfield);        print_liste_field_titre($langs->trans('Ref'),'propal.php','p.ref','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut,'',$sortfield);
1114                  print_liste_field_titre($langs->trans('Company'),'propal.php','s.nom','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut,'',$sortfield);        print_liste_field_titre($langs->trans('Company'),'propal.php','s.nom','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut,'',$sortfield);
1115                  print_liste_field_titre($langs->trans('Date'),'propal.php','p.datep','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut, 'align="center"',$sortfield);        print_liste_field_titre($langs->trans('Date'),'propal.php','p.datep','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut, 'align="center"',$sortfield);
1116                  print_liste_field_titre($langs->trans('DateEndPropalShort'),'propal.php','dfv','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut, 'align="center"',$sortfield);        print_liste_field_titre($langs->trans('DateEndPropalShort'),'propal.php','dfv','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut, 'align="center"',$sortfield);
1117                  print_liste_field_titre($langs->trans('Price'),'propal.php','p.price','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut, 'align="right"',$sortfield);        print_liste_field_titre($langs->trans('Price'),'propal.php','p.price','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut, 'align="right"',$sortfield);
1118                  print_liste_field_titre($langs->trans('Status'),'propal.php','p.fk_statut','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut,'align="center"',$sortfield);        print_liste_field_titre($langs->trans('Status'),'propal.php','p.fk_statut','','&amp;socidp='.$socidp.'&amp;viewstatut='.$viewstatut,'align="center"',$sortfield);
1119                  print "</tr>\n";        print "</tr>\n";
1120                  // Lignes des champs de filtre        // Lignes des champs de filtre
1121                  print '<form method="get" action="propal.php">';        print '<form method="get" action="propal.php">';
1122                  print '<tr class="liste_titre">';        print '<tr class="liste_titre">';
1123                  print '<td valign="right">';        print '<td valign="right">';
1124                  print '<input class="flat" size="10" type="text" name="search_ref" value="'.$_GET['search_ref'].'">';        print '<input class="flat" size="10" type="text" name="search_ref" value="'.$_GET['search_ref'].'">';
1125                  print '</td>';        print '</td>';
1126                  print '<td align="left">';        print '<td align="left">';
1127                  print '<input class="flat" type="text" size="40" name="search_societe" value="'.$_GET['search_societe'].'">';        print '<input class="flat" type="text" size="40" name="search_societe" value="'.$_GET['search_societe'].'">';
1128                  print '</td>';        print '</td>';
1129                  print '<td colspan="2">&nbsp;</td>';        print '<td colspan="2">&nbsp;</td>';
1130                  print '<td align="right">';        print '<td align="right">';
1131                  print '<input class="flat" type="text" size="10" name="search_montant_ht" value="'.$_GET['search_montant_ht'].'">';        print '<input class="flat" type="text" size="10" name="search_montant_ht" value="'.$_GET['search_montant_ht'].'">';
1132                  print '</td>';        print '</td>';
1133          print '<td class="liste_titre" align="right"><input class="liste_titre" type="image" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" alt="'.$langs->trans("Search").'">';        print '<td class="liste_titre" align="right"><input class="liste_titre" type="image" src="'.DOL_URL_ROOT.'/theme/'.$conf->theme.'/img/search.png" alt="'.$langs->trans("Search").'">';
1134                  print '</td>';        print '</td>';
1135                  print "</tr>\n";        print "</tr>\n";
1136                  print '</form>';        print '</form>';
1137    
1138                  $var=true;        $var=true;
1139    
1140                  while ($i < min($num,$limit))        while ($i < min($num,$limit))
1141                  {          {
1142                          $objp = $db->fetch_object($result);            $objp = $db->fetch_object($result);
1143                          $now = time();            $now = time();
1144                          $var=!$var;            $var=!$var;
1145                          print '<tr '.$bc[$var].'>';            print '<tr '.$bc[$var].'>';
1146                          print '<td><a href="propal.php?propalid='.$objp->propalid.'">'.img_object($langs->trans('ShowPropal'),'propal').' '.$objp->ref."</a></td>\n";            print '<td><a href="propal.php?propalid='.$objp->propalid.'">'.img_object($langs->trans('ShowPropal'),'propal').' '.$objp->ref."</a></td>\n";
1147    
1148                          if ($objp->client == 1)            if ($objp->client == 1)
1149                          {              {
1150                                  $url = DOL_URL_ROOT.'/comm/fiche.php?socid='.$objp->idp;                $url = DOL_URL_ROOT.'/comm/fiche.php?socid='.$objp->idp;
1151                          }              }
1152                          else            else
1153                          {              {
1154                                  $url = DOL_URL_ROOT.'/comm/prospect/fiche.php?socid='.$objp->idp;                $url = DOL_URL_ROOT.'/comm/prospect/fiche.php?socid='.$objp->idp;
1155                          }              }
1156                          print '<td><a href="'.$url.'">'.img_object($langs->trans('ShowCompany'),'company').' '.$objp->nom.'</a></td>';            print '<td><a href="'.$url.'">'.img_object($langs->trans('ShowCompany'),'company').' '.$objp->nom.'</a></td>';
1157    
1158                          // Date propale            // Date propale
1159                          print '<td align="center">';            print '<td align="center">';
1160                          $y = strftime('%Y',$objp->dp);            $y = strftime('%Y',$objp->dp);
1161                          $m = strftime('%m',$objp->dp);            $m = strftime('%m',$objp->dp);
1162    
1163                          print strftime('%d',$objp->dp)."\n";            print strftime('%d',$objp->dp)."\n";
1164                          print ' <a href="propal.php?year='.$y.'&amp;month='.$m.'">';            print ' <a href="propal.php?year='.$y.'&amp;month='.$m.'">';
1165                          print dolibarr_print_date($objp->dp,'%b')."</a>\n";            print dolibarr_print_date($objp->dp,'%b')."</a>\n";
1166                          print ' <a href="propal.php?year='.$y.'">';            print ' <a href="propal.php?year='.$y.'">';
1167                          print strftime('%Y',$objp->dp)."</a></td>\n";                  print strftime('%Y',$objp->dp)."</a></td>\n";      
1168    
1169              // Date fin validite            // Date fin validite
1170                          if ( $now > $objp->dfv && $objp->dfv > 0 )            if ( $now > $objp->dfv && $objp->dfv > 0 )
1171                          {              {
1172                                  print '<td align="center">'.dolibarr_print_date($objp->dfv).'</td>';                print '<td align="center">'.dolibarr_print_date($objp->dfv).'</td>';
1173                          }              }
1174                          else            else
1175                          {              {
1176                                  print '<td>&nbsp;</td>';                print '<td>&nbsp;</td>';
1177                          }              }
1178    
1179                          print '<td align="right">'.price($objp->price)."</td>\n";            print '<td align="right">'.price($objp->price)."</td>\n";
1180                          $propal=New Propal($db);            $propal=New Propal($db);
1181                          print '<td align="center">'.$propal->LibStatut($objp->fk_statut,0)."</td>\n";            print '<td align="center">'.$propal->LibStatut($objp->fk_statut,0)."</td>\n";
1182                          print "</tr>\n";            print "</tr>\n";
1183    
1184                          $total = $total + $objp->price;            $total = $total + $objp->price;
1185                          $subtotal = $subtotal + $objp->price;            $subtotal = $subtotal + $objp->price;
1186    
1187                          $i++;            $i++;
1188                  }          }
1189                  print '</table>';        print '</table>';
1190                  $db->free($result);        $db->free($result);
1191          }      }
1192          else    else
1193          {      {
1194                  dolibarr_print_error($db);        dolibarr_print_error($db);
1195          }      }
1196  }  }
1197  $db->close();  $db->close();
1198    

Legend:
Removed from v.1.98  
changed lines
  Added in v.1.99

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26