2004-10-19 22:19:58 +02:00
< ? php
2004-01-30 11:32:21 +01:00
/* Copyright ( C ) 2001 - 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
2004-02-10 23:16:57 +01:00
* Copyright ( C ) 2004 Laurent Destailleur < eldy @ users . sourceforge . net >
2004-12-22 21:17:18 +01:00
* Copyright ( C ) 2004 Eric Seigne < eric . seigne @ ryxeo . com >
2002-04-30 12:44:42 +02:00
*
* This program is free software ; you can redistribute it and / or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation ; either version 2 of the License , or
* ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
*
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 59 Temple Place - Suite 330 , Boston , MA 02111 - 1307 , USA .
*
2003-03-23 16:37:36 +01:00
* $Id $
* $Source $
*
2002-04-30 12:44:42 +02:00
*/
2003-09-05 08:58:58 +02:00
2005-01-16 18:42:20 +01:00
/** \file htdocs / comm / propal . php
\ingroup propale
\brief Page liste des propales
2003-09-05 08:58:58 +02:00
*/
2003-09-11 22:18:51 +02:00
require ( " ./pre.inc.php " );
2002-04-30 12:44:42 +02:00
2004-10-30 00:17:32 +02:00
$langs -> load ( " companies " );
2004-11-07 16:14:09 +01:00
$langs -> load ( " propal " );
$langs -> load ( " bills " );
2004-10-30 00:17:32 +02:00
2003-08-06 14:40:53 +02:00
$user -> getrights ( 'propale' );
2004-10-30 00:17:32 +02:00
2003-08-06 14:40:53 +02:00
if ( ! $user -> rights -> propale -> lire )
accessforbidden ();
2002-04-30 12:44:42 +02:00
/*
* Modules optionnels
*/
2003-09-11 22:18:51 +02:00
require ( " ../project.class.php " );
require ( " ./propal_model_pdf.class.php " );
require ( " ../propal.class.php " );
require ( " ../actioncomm.class.php " );
require ( " ../lib/CMailFile.class.php " );
2003-09-01 14:40:50 +02:00
2003-03-23 16:37:36 +01:00
/*
2004-11-26 00:23:20 +01:00
* S<EFBFBD> curit<EFBFBD> acc<EFBFBD> s client
2003-03-23 16:37:36 +01:00
*/
if ( $user -> societe_id > 0 )
{
$action = '' ;
$socidp = $user -> societe_id ;
}
2002-12-12 18:04:27 +01:00
/******************************************************************************/
/* Actions */
/******************************************************************************/
2002-04-30 12:44:42 +02:00
2004-11-07 16:14:09 +01:00
if ( $_POST [ " action " ] == 'confirm_delete' && $_POST [ " confirm " ] == 'yes' )
2003-09-12 14:58:58 +02:00
{
2004-11-26 00:23:20 +01:00
if ( $user -> rights -> propale -> supprimer )
2003-09-12 14:58:58 +02:00
{
2004-07-27 10:26:49 +02:00
$propal = new Propal ( $db , 0 , $_GET [ " propalid " ]);
2004-07-27 11:45:52 +02:00
$propal -> delete ( $user );
2003-09-12 14:58:58 +02:00
$propalid = 0 ;
$brouillon = 1 ;
}
Header ( " Location: propal.php " );
}
2004-07-13 19:40:42 +02:00
if ( $_POST [ " action " ] == 'add' )
2002-12-12 18:04:27 +01:00
{
2003-11-27 12:39:08 +01:00
$propal = new Propal ( $db , $_GET [ " socidp " ]);
2002-12-12 18:04:27 +01:00
2003-11-19 15:52:09 +01:00
$propal -> datep = mktime ( 12 , 1 , 1 ,
2004-07-13 19:40:42 +02:00
$_POST [ " remonth " ],
$_POST [ " reday " ],
$_POST [ " reyear " ]);
2003-11-19 15:52:09 +01:00
2004-07-13 19:40:42 +02:00
$propal -> duree_validite = $_POST [ " duree_validite " ];
2003-07-07 18:28:55 +02:00
2004-07-13 19:40:42 +02:00
$propal -> contactid = $_POST [ " contactidp " ];
$propal -> projetidp = $_POST [ " projetidp " ];
2004-07-15 11:38:09 +02:00
$propal -> modelpdf = $_POST [ " modelpdf " ];
$propal -> author = $user -> id ;
$propal -> note = $_POST [ " note " ];
2002-12-12 18:04:27 +01:00
2004-07-13 19:40:42 +02:00
$propal -> ref = $_POST [ " ref " ];
2002-12-12 18:04:27 +01:00
2003-09-23 14:03:08 +02:00
for ( $i = 1 ; $i <= PROPALE_NEW_FORM_NB_PRODUCT ; $i ++ )
{
$xid = " idprod " . $i ;
$xqty = " qty " . $i ;
2003-09-23 19:50:20 +02:00
$xremise = " remise " . $i ;
2003-09-23 14:03:08 +02:00
2004-07-13 19:40:42 +02:00
$propal -> add_product ( $_POST [ $xid ], $_POST [ $xqty ], $_POST [ $xremise ]);
2003-09-23 14:03:08 +02:00
}
2002-12-12 18:04:27 +01:00
$id = $propal -> create ();
/*
* Generation
*/
if ( $id )
{
2004-07-13 19:40:42 +02:00
propale_pdf_create ( $db , $id , $_POST [ " modelpdf " ]);
2004-08-20 11:11:28 +02:00
Header ( " Location: propal.php?propalid= $id " );
2002-12-12 18:04:27 +01:00
}
}
2004-10-30 00:17:32 +02:00
if ( $_GET [ " action " ] == 'pdf' )
2003-06-19 15:12:27 +02:00
{
2004-12-23 18:53:27 +01:00
$propal = new Propal ( $db );
$propal -> fetch ( $_GET [ " propalid " ]);
propale_pdf_create ( $db , $_GET [ " propalid " ], $propal -> modelpdf );
2003-06-19 15:12:27 +02:00
}
2002-12-12 18:04:27 +01:00
2004-07-13 19:40:42 +02:00
if ( $_POST [ " action " ] == 'setstatut' && $user -> rights -> propale -> cloturer )
2002-12-12 18:04:27 +01:00
{
2002-05-01 02:11:24 +02:00
/*
* Cloture de la propale
*/
$propal = new Propal ( $db );
2003-11-27 12:39:08 +01:00
$propal -> fetch ( $_GET [ " propalid " ]);
2004-07-13 19:40:42 +02:00
$propal -> cloture ( $user , $_POST [ " statut " ], $_POST [ " note " ]);
2002-12-12 18:04:27 +01:00
}
2003-06-20 11:50:11 +02:00
2003-11-19 15:52:09 +01:00
if ( $_GET [ " action " ] == 'commande' )
{
/*
* Cloture de la propale
*/
$propal = new Propal ( $db );
$propal -> fetch ( $propalid );
$propal -> create_commande ( $user );
}
2004-07-20 17:19:54 +02:00
if ( $_GET [ " action " ] == 'modif' && $user -> rights -> propale -> creer )
2003-06-20 16:23:17 +02:00
{
/*
* Repasse la propale en mode brouillon
*/
$propal = new Propal ( $db );
2004-07-20 17:19:54 +02:00
$propal -> fetch ( $_GET [ " propalid " ]);
2003-06-20 16:23:17 +02:00
$propal -> reopen ( $user -> id );
}
2005-01-11 21:26:22 +01:00
if ( $_POST [ " addligne " ] == $langs -> trans ( " Add " ) && $user -> rights -> propale -> creer )
2003-06-20 11:50:11 +02:00
{
/*
* Ajout d ' une ligne produit dans la propale
*/
2004-07-13 19:40:42 +02:00
if ( $_POST [ " idprod " ])
2003-06-20 11:50:11 +02:00
{
$propal = new Propal ( $db );
2004-07-15 11:38:09 +02:00
$propal -> fetch ( $_GET [ " propalid " ]);
2004-07-13 19:40:42 +02:00
$propal -> insert_product ( $_POST [ " idprod " ], $_POST [ " qty " ], $_POST [ " remise " ]);
2003-11-27 12:39:08 +01:00
propale_pdf_create ( $db , $_GET [ " propalid " ], $propal -> modelpdf );
2003-06-20 11:50:11 +02:00
}
}
2005-01-11 21:26:22 +01:00
if ( $_POST [ " addproduct " ] == $langs -> trans ( " Add " ) && $user -> rights -> propale -> creer )
2003-08-30 13:45:47 +02:00
{
/*
* Ajout d ' une ligne produit dans la propale
*/
2004-07-15 11:38:09 +02:00
if ( strlen ( $_POST [ " np_desc " ]) && strlen ( $_POST [ " np_price " ]))
2003-09-05 21:36:37 +02:00
{
2004-07-15 11:38:09 +02:00
2003-09-05 21:36:37 +02:00
$propal = new Propal ( $db );
2004-07-15 11:38:09 +02:00
$propal -> fetch ( $_GET [ " propalid " ]);
2003-10-09 00:58:53 +02:00
2004-07-13 19:40:42 +02:00
$propal -> insert_product_generic ( $_POST [ " np_desc " ],
$_POST [ " np_price " ],
$_POST [ " np_qty " ],
$_POST [ " np_tva_tx " ],
$_POST [ " np_remise " ]);
2003-09-05 21:36:37 +02:00
}
}
2004-07-13 19:40:42 +02:00
if ( $_POST [ " action " ] == 'setremise' && $user -> rights -> propale -> creer )
2003-09-05 21:36:37 +02:00
{
2003-08-30 13:45:47 +02:00
$propal = new Propal ( $db );
2004-07-13 19:40:42 +02:00
$propal -> fetch ( $_GET [ " propalid " ]);
$propal -> set_remise ( $user , $_POST [ " remise " ]);
2003-11-27 12:39:08 +01:00
propale_pdf_create ( $db , $_GET [ " propalid " ], $propal -> modelpdf );
2003-08-30 13:45:47 +02:00
}
2004-07-13 19:40:42 +02:00
if ( $_POST [ " action " ] == 'setpdfmodel' && $user -> rights -> propale -> creer )
2003-09-06 17:13:29 +02:00
{
2004-07-13 19:40:42 +02:00
$propal = new Propal ( $db , 0 , $_GET [ " propalid " ]);
$propal -> set_pdf_model ( $user , $_POST [ " modelpdf " ]);
propale_pdf_create ( $db , $_GET [ " propalid " ], $_POST [ " modelpdf " ]);
2003-09-06 17:13:29 +02:00
}
2003-08-30 13:45:47 +02:00
2004-07-15 11:38:09 +02:00
if ( $_GET [ " action " ] == 'del_ligne' && $user -> rights -> propale -> creer )
2003-06-20 11:50:11 +02:00
{
/*
* Supprime une ligne produit dans la propale
*/
$propal = new Propal ( $db );
2004-07-15 11:38:09 +02:00
$propal -> fetch ( $_GET [ " propalid " ]);
$propal -> delete_product ( $_GET [ " ligne " ]);
2003-11-27 12:39:08 +01:00
propale_pdf_create ( $db , $_GET [ " propalid " ], $propal -> modelpdf );
2003-06-20 11:50:11 +02:00
}
2003-11-27 12:39:08 +01:00
if ( $_GET [ " valid " ] == 1 && $user -> rights -> propale -> valider )
2003-09-05 21:36:37 +02:00
{
$propal = new Propal ( $db );
2003-11-27 12:39:08 +01:00
$propal -> fetch ( $_GET [ " propalid " ]);
$propal -> update_price ( $_GET [ " propalid " ]);
propale_pdf_create ( $db , $_GET [ " propalid " ], $propal -> modelpdf );
2003-09-05 21:36:37 +02:00
$propal -> valid ( $user );
}
2002-12-12 18:04:27 +01:00
2004-10-30 00:17:32 +02:00
2003-09-12 14:58:58 +02:00
llxHeader ();
2004-10-30 00:17:32 +02:00
2002-05-04 01:01:45 +02:00
/*
2004-10-30 00:17:32 +02:00
* Affichage fiche propal en mode visu
2002-05-04 01:01:45 +02:00
*
*/
2003-11-27 12:39:08 +01:00
if ( $_GET [ " propalid " ])
2003-06-28 16:33:27 +02:00
{
2003-09-12 14:58:58 +02:00
$html = new Form ( $db );
2002-05-04 01:01:45 +02:00
$propal = new Propal ( $db );
2003-11-27 12:39:08 +01:00
$propal -> fetch ( $_GET [ " propalid " ]);
2002-04-30 12:44:42 +02:00
2004-03-05 16:48:09 +01:00
$societe = new Societe ( $db );
$societe -> fetch ( $propal -> soc_id );
2004-11-07 16:14:09 +01:00
$h = 0 ;
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/comm/propal.php?propalid=' . $propal -> id ;
2004-11-26 00:23:20 +01:00
$head [ $h ][ 1 ] = $langs -> trans ( " Card " );
2004-11-07 16:14:09 +01:00
$hselected = $h ;
$h ++ ;
2004-03-05 16:48:09 +01:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/comm/propal/note.php?propalid=' . $propal -> id ;
2004-10-30 00:17:32 +02:00
$head [ $h ][ 1 ] = $langs -> trans ( " Note " );
2004-07-20 16:02:49 +02:00
$h ++ ;
2004-11-07 16:14:09 +01:00
2004-07-20 16:02:49 +02:00
$head [ $h ][ 0 ] = DOL_URL_ROOT . '/comm/propal/info.php?propalid=' . $propal -> id ;
2004-10-30 00:17:32 +02:00
$head [ $h ][ 1 ] = $langs -> trans ( " Info " );
2004-11-07 16:14:09 +01:00
$h ++ ;
2004-03-05 16:48:09 +01:00
2004-11-26 00:23:20 +01:00
dolibarr_fiche_head ( $head , $hselected , $langs -> trans ( " Prop " ) . " : $propal->ref " );
2003-09-12 14:58:58 +02:00
/*
2003-10-21 18:28:02 +02:00
* Confirmation de la suppression de la propale
2003-09-12 14:58:58 +02:00
*
*/
2004-07-27 10:26:49 +02:00
if ( $_GET [ " action " ] == 'delete' )
2003-09-12 14:58:58 +02:00
{
2005-01-16 20:11:47 +01:00
$html -> form_confirm ( " propal.php?propalid= $propal->id " , $langs -> trans ( " DeleteProp " ), $langs -> trans ( " ConfirmDeleteProp " ), " confirm_delete " );
print '<br>' ;
2003-09-12 14:58:58 +02:00
}
2002-04-30 12:44:42 +02:00
/*
*
*/
2002-05-01 02:11:24 +02:00
$sql = " SELECT s.nom, s.idp, p.price, p.fk_projet,p.remise, p.tva, p.total, p.ref, " . $db -> pdate ( " p.datep " ) . " as dp, c.id as statut, c.label as lst, p.note, 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 " ;
2004-01-30 11:32:21 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " propal as p, " . MAIN_DB_PREFIX . " c_propalst as c, " . MAIN_DB_PREFIX . " socpeople as x " ;
2003-11-27 12:39:08 +01:00
$sql .= " WHERE p.fk_soc = s.idp AND p.fk_statut = c.id AND x.idp = p.fk_soc_contact AND p.rowid = $propal->id " ;
2002-04-30 12:44:42 +02:00
2003-06-28 16:33:27 +02:00
if ( $socidp )
{
$sql .= " AND s.idp = $socidp " ;
}
2003-03-23 16:37:36 +01:00
2002-04-30 12:44:42 +02:00
$result = $db -> query ( $sql );
2002-12-12 17:11:54 +01:00
if ( $result )
{
2004-10-23 18:55:07 +02:00
$obj = $db -> fetch_object ( $result );
2002-04-30 12:44:42 +02:00
2002-12-12 17:11:54 +01:00
if ( $db -> num_rows ())
{
$color1 = " #e0e0e0 " ;
2004-07-20 17:19:54 +02:00
if ( $propal -> brouillon == 1 && $user -> rights -> propale -> creer )
{
/* la form est ouverte avant la table pour respect des normes */
print '<form action="propal.php?propalid=' . $propal -> id . '" method="post">' ;
print '<input type="hidden" name="action" value="setremise">' ;
}
2004-10-30 00:17:32 +02:00
print " <table class= \" border \" width= \" 100% \" > " ;
2005-01-16 20:11:47 +01:00
$rowspan = 4 ;
2004-11-26 00:23:20 +01:00
print '<tr><td>' . $langs -> trans ( " Company " ) . '</td><td colspan="3">' ;
2004-03-05 16:48:09 +01:00
if ( $societe -> client == 1 )
2004-03-04 18:47:20 +01:00
{
2004-03-05 16:48:09 +01:00
$url = 'fiche.php?socid=' . $societe -> id ;
2004-03-04 18:47:20 +01:00
}
else
{
2004-03-05 16:48:09 +01:00
$url = DOL_URL_ROOT . '/comm/prospect/fiche.php?socid=' . $societe -> id ;
2004-03-04 18:47:20 +01:00
}
2004-03-05 16:48:09 +01:00
print '<a href="' . $url . '">' . $societe -> nom . '</a></td>' ;
2004-11-26 00:23:20 +01:00
print '<td align="left">' . $langs -> trans ( " Status " ) . '</td><td align="left">' . $obj -> lst . '</td></tr>' ;
2003-06-21 14:58:04 +02:00
2004-10-30 00:17:32 +02:00
print '<tr><td>' . $langs -> trans ( " Date " ) . '</td><td colspan="3">' . strftime ( " %A %d %B %Y " , $propal -> date );
2003-11-19 15:52:09 +01:00
if ( $propal -> fin_validite )
{
print " ( " . strftime ( " %d %B %Y " , $propal -> fin_validite ) . " ) " ;
}
print '</td>' ;
2003-06-21 14:58:04 +02:00
2004-08-02 04:12:01 +02:00
print '<td>' . $langs -> trans ( " Author " ) . '</td><td>' ;
2003-06-21 14:58:04 +02:00
$author = new User ( $db , $obj -> fk_user_author );
$author -> fetch ( '' );
print $author -> fullname . '</td></tr>' ;
2002-12-12 17:11:54 +01:00
2005-01-16 20:11:47 +01:00
$langs -> load ( " mails " );
print " <tr><td> " . $langs -> trans ( " MailTo " ) . " </td><td colspan= \" 3 \" > $obj->firstname $obj->name " . ( $obj -> email ? " < $obj->email > " : " " ) . " </td> " ;
2003-06-21 14:58:04 +02:00
2005-01-16 20:11:47 +01:00
if ( $conf -> projet -> enabled && $propal -> projet_id ) $rowspan ++ ;
print '<td valign="top" colspan="2" width="50%" rowspan="' . $rowspan . '">' . $langs -> trans ( " Note " ) . ' :<br>' . nl2br ( $propal -> note ) . " </td></tr> " ;
2003-06-21 14:58:04 +02:00
2005-01-16 20:11:47 +01:00
if ( $conf -> projet -> enabled && $propal -> projet_id )
2002-12-12 17:11:54 +01:00
{
2004-10-30 00:17:32 +02:00
$langs -> load ( " projects " );
2002-12-12 17:11:54 +01:00
$projet = new Project ( $db );
2004-03-05 16:48:09 +01:00
$projet -> fetch ( $propal -> projet_id );
2004-10-30 00:17:32 +02:00
print '<tr><td>' . $langs -> trans ( " Projects " ) . '</td><td colspan="3">' ;
2003-09-07 19:41:33 +02:00
print '<a href="../projet/fiche.php?id=' . $projet -> id . '">' ;
2002-12-12 17:11:54 +01:00
print $projet -> title . '</a></td></tr>' ;
}
2003-06-21 14:58:04 +02:00
2002-12-12 17:11:54 +01:00
/*
*
*/
2004-07-20 17:19:54 +02:00
if ( $propal -> brouillon == 1 && $user -> rights -> propale -> creer )
{
print '<tr><td>Remise <a href="propal/aideremise.php?propalid=' . $propal -> id . '">?</a></td>' ;
print '<td align="right"><input type="text" name="remise" size="3" value="' . $propal -> remise_percent . '">%</td>' ;
2004-10-30 00:17:32 +02:00
print '<td><input type="submit" value="' . $langs -> trans ( " Save " ) . '"></td>' ;
2004-07-20 17:19:54 +02:00
}
else
{
print '<tr><td>Remise</td>' ;
print '<td align="right">' . $propal -> remise_percent . ' %</td><td> </td>' ;
}
print '<td align="right">' . price ( $propal -> remise ) . ' euros</td></tr>' ;
2002-12-12 17:11:54 +01:00
/*
*
*/
2004-10-30 00:17:32 +02:00
print '<tr><td>' . $langs -> trans ( " AmountHT " ) . '</td><td align="right">' . price ( $obj -> price + $obj -> remise ) . ' euros</td>' ;
print '<td align="right">' . $langs -> trans ( " VAT " ) . '</td><td align="right">' . price ( $propal -> total_tva ) . ' euros</td></tr>' ;
2003-09-05 21:43:41 +02:00
2002-12-12 17:11:54 +01:00
/*
*
*/
2004-07-31 15:34:32 +02:00
print '<tr><td>' . $langs -> trans ( " TotalHT " ) . '</td><td align="right"><b>' . price ( $obj -> price ) . '</b> euros</td>' ;
print '<td align="right">' . $langs -> trans ( " TotalTTC " ) . '</td><td align="right"><b>' . price ( $propal -> total_ttc ) . '</b> euros</td></tr>' ;
2002-12-12 17:11:54 +01:00
/*
*
*/
2003-06-21 14:58:04 +02:00
2004-11-07 16:14:09 +01:00
print " </table><br> " ;
2002-12-12 17:11:54 +01:00
2004-07-20 17:19:54 +02:00
if ( $propal -> brouillon == 1 && $user -> rights -> propale -> creer )
{
print " </form> " ;
}
2003-11-27 12:39:08 +01:00
if ( $_GET [ " action " ] == 'statut' )
2002-12-12 17:11:54 +01:00
{
2004-07-13 19:40:42 +02:00
print " <form action= \" propal.php?propalid= $propal->id\ " method = \ " post \" > " ;
2004-11-07 16:14:09 +01:00
print '<br><table class="border">' ;
2003-11-07 11:49:04 +01:00
print '<tr><td>Cl<43> turer comme : <input type="hidden" name="action" value="setstatut">' ;
2002-12-12 17:11:54 +01:00
print " <select name= \" statut \" > " ;
print " <option value= \" 2 \" >Sign<67> e " ;
print " <option value= \" 3 \" >Non Sign<67> e " ;
print '</select>' ;
2004-08-29 21:03:50 +02:00
print '</td></tr><tr><td>' . $langs -> trans ( " Comments " ) . ' : <br><textarea cols="60" rows="6" wrap="soft" name="note">' ;
2003-09-09 15:10:49 +02:00
print $obj -> note ;
print '</textarea></td></tr><tr><td align="center"><input type="submit" value="Valider"></td>' ;
print " </tr></table></form> " ;
2002-12-12 17:11:54 +01:00
}
/*
* Produits
*/
2004-11-07 16:14:09 +01:00
print_titre ( $langs -> trans ( " ProductsAndServices " ));
2003-11-27 12:39:08 +01:00
print '<form action="propal.php?propalid=' . $propal -> id . '" method="post">' ;
2004-11-07 16:14:09 +01:00
print '<table class="noborder" width="100%">' ;
print " <tr class= \" liste_titre \" > " ;
print '<td>' . $langs -> trans ( " Ref " ) . '</td><td>' . $langs -> trans ( " ProductOrService " ) . '</td>' ;
print '<td align="center">' . $langs -> trans ( " VAT " ) . '</td><td align="center">' . $langs -> trans ( " Qty " ) . '</td><td align="center">Remise</td><td align="right">P.U.</td>' ;
2004-11-07 16:45:38 +01:00
print " <td> </td> " ;
2004-03-05 16:48:09 +01:00
print " </tr> \n " ;
2003-06-20 11:50:11 +02:00
2003-09-23 19:50:20 +02:00
$sql = " SELECT pt.rowid, p.label as product, p.ref, pt.price, pt.qty, p.rowid as prodid, pt.tva_tx, pt.remise_percent, pt.subprice " ;
2004-01-30 11:32:21 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " propaldet as pt, " . MAIN_DB_PREFIX . " product as p WHERE pt.fk_product = p.rowid AND pt.fk_propal = $propal->id " ;
2003-09-23 19:55:31 +02:00
$sql .= " ORDER BY pt.rowid ASC " ;
2002-12-12 17:11:54 +01:00
$result = $db -> query ( $sql );
if ( $result )
{
$num = $db -> num_rows ();
2003-06-20 11:50:11 +02:00
$i = 0 ;
2002-12-12 17:11:54 +01:00
$var = True ;
while ( $i < $num )
{
2004-10-23 18:55:07 +02:00
$objp = $db -> fetch_object ( $result );
2002-12-12 17:11:54 +01:00
$var =! $var ;
2004-11-07 16:14:09 +01:00
print " <tr $bc[$var] > " ;
2003-09-23 19:50:20 +02:00
print " <td>[ $objp->ref ]</td> \n " ;
2003-10-14 17:30:39 +02:00
print '<td><a href="' . DOL_URL_ROOT . '/product/fiche.php?id=' . $objp -> prodid . '">' . $objp -> product . '</a></td>' ;
2003-09-04 23:29:25 +02:00
print '<td align="center">' . $objp -> tva_tx . ' %</td>' ;
2003-08-30 14:10:37 +02:00
print " <td align= \" center \" > " . $objp -> qty . " </td> \n " ;
2003-10-09 00:58:53 +02:00
print '<td align="center">' . $objp -> remise_percent . ' %</td>' ;
2003-09-23 19:50:20 +02:00
print '<td align="right">' . price ( $objp -> subprice ) . '</td>' ;
2004-03-05 16:48:09 +01:00
if ( $propal -> statut == 0 && $user -> rights -> propale -> creer )
2003-06-20 11:50:11 +02:00
{
2003-11-27 12:39:08 +01:00
print '<td align="center"><a href="propal.php?propalid=' . $propal -> id . '&ligne=' . $objp -> rowid . '&action=del_ligne">' ;
2003-11-09 18:24:14 +01:00
print img_delete ();
print '</a></td>' ;
2003-06-20 11:50:11 +02:00
}
2004-11-07 16:45:38 +01:00
else {
print '<td> </td>' ;
}
2002-12-12 17:11:54 +01:00
print " </tr> " ;
2003-06-20 11:50:11 +02:00
2002-12-12 17:11:54 +01:00
$i ++ ;
}
}
2003-08-30 13:45:47 +02:00
2003-10-09 00:58:53 +02:00
$sql = " SELECT pt.rowid, pt.description, pt.price, pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice " ;
2004-01-30 11:32:21 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " propaldet as pt WHERE pt.fk_propal = $propal->id AND pt.fk_product = 0 " ;
2003-08-30 13:45:47 +02:00
2004-11-07 16:45:38 +01:00
$result = $db -> query ( $sql );
if ( $result )
2003-08-30 13:45:47 +02:00
{
$num = $db -> num_rows ();
$i = 0 ;
while ( $i < $num )
2004-11-07 16:45:38 +01:00
{
$objp = $db -> fetch_object ( $result );
2003-08-30 13:45:47 +02:00
$var =! $var ;
2004-11-07 16:14:09 +01:00
print " <tr $bc[$var] ><td> </td> \n " ;
2003-08-30 13:45:47 +02:00
print '<td>' . $objp -> description . '</td>' ;
2003-09-04 23:29:25 +02:00
print '<td align="center">' . $objp -> tva_tx . ' %</td>' ;
print " <td align= \" center \" > " . $objp -> qty . " </td> \n " ;
2003-09-23 19:50:20 +02:00
print '<td align="center">' . $objp -> remise_percent . ' %</td>' ;
2004-11-07 16:14:09 +01:00
print " <td align= \" right \" > " . price ( $objp -> subprice ) . " </td> " ;
2004-03-05 16:48:09 +01:00
if ( $propal -> statut == 0 && $user -> rights -> propale -> creer )
2003-08-30 13:45:47 +02:00
{
2003-11-27 12:39:08 +01:00
print '<td align="center"><a href="propal.php?propalid=' . $propal -> id . '&ligne=' . $objp -> rowid . '&action=del_ligne">' ;
2003-11-19 15:52:09 +01:00
print img_delete ();
print '</a></td>' ;
2003-08-30 13:45:47 +02:00
}
else
{
2004-11-07 16:45:38 +01:00
print '<td> </td>' ;
2003-08-30 13:45:47 +02:00
}
print " </tr> " ;
$i ++ ;
2004-11-07 16:45:38 +01:00
}
2003-08-30 13:45:47 +02:00
}
2004-03-05 16:48:09 +01:00
if ( $propal -> statut == 0 && $user -> rights -> propale -> creer )
2003-06-20 11:50:11 +02:00
{
2004-01-30 11:32:21 +01:00
$sql = " SELECT p.rowid,p.label,p.ref,p.price FROM " . MAIN_DB_PREFIX . " product as p WHERE p.envente=1 ORDER BY p.nbvente DESC LIMIT 20 " ;
2004-10-23 18:55:07 +02:00
$result = $db -> query ( $sql );
2003-06-20 11:50:11 +02:00
if ( $result )
{
2004-10-23 18:55:07 +02:00
$opt = " <option value= \" 0 \" selected></option> " ;
2003-06-20 11:50:11 +02:00
$num = $db -> num_rows (); $i = 0 ;
while ( $i < $num )
2004-11-07 16:45:38 +01:00
{
2004-10-23 18:55:07 +02:00
$objp = $db -> fetch_object ( $result );
2003-09-23 19:50:20 +02:00
$opt .= " <option value= \" $objp->rowid\ " > [ $objp -> ref ] " .substr( $objp->label ,0,40). " </ option > \n " ;
2003-06-20 11:50:11 +02:00
$i ++ ;
2004-11-07 16:45:38 +01:00
}
$db -> free ();
}
else
{
dolibarr_print_error ( $db );
}
2004-11-07 16:14:09 +01:00
2003-08-30 13:45:47 +02:00
/*
2004-11-07 16:14:09 +01:00
* Ligne d ' ajout de produits / services personalis<EFBFBD>
2003-08-30 13:45:47 +02:00
*/
$var =! $var ;
2003-10-24 10:09:48 +02:00
2004-12-22 21:17:18 +01:00
print " <tr " . $bc [ $var ] . " > \n " ;
print " <td> </td> \n " ;
print " <td><textarea cols= \" 50 \" name= \" np_desc \" ></textarea></td> \n " ;
print " <td align= \" center \" > " ;
print $html -> select_tva ( " np_tva_tx " , $conf -> defaulttx ) . " </td> \n " ;
print " <td align= \" center \" ><input type= \" text \" size= \" 3 \" value= \" 1 \" name= \" np_qty \" ></td> \n " ;
print " <td align= \" center \" ><input type= \" text \" size= \" 3 \" value= \" " . $societe -> remise_client . " \" name= \" np_remise \" > %</td> \n " ;
print " <td align= \" right \" ><input type= \" text \" size= \" 6 \" name= \" np_price \" ></td> \n " ;
print " <td align= \" center \" ><input type= \" submit \" value= \" " . $langs -> trans ( " Add " ) . " \" name= \" addproduct \" ></td> \n " ;
print " </tr> " ;
2003-08-30 13:45:47 +02:00
2003-09-23 19:50:20 +02:00
/*
2004-11-07 16:14:09 +01:00
* Ligne d ' ajout de produits / services pr<EFBFBD> d<EFBFBD> finis
2003-09-23 19:50:20 +02:00
*/
2003-08-30 13:45:47 +02:00
$var =! $var ;
2004-11-07 16:45:38 +01:00
print " <tr $bc[$var] ><td> </td><td colspan= \" 2 \" ><select name= \" idprod \" > " . $opt . " </select></td> " ;
2003-08-30 13:45:47 +02:00
print '<td align="center"><input type="text" size="3" name="qty" value="1"></td>' ;
2004-08-20 11:11:28 +02:00
print '<td align="center"><input type="text" size="3" name="remise" value="' . $societe -> remise_client . '"> %</td>' ;
2003-09-23 19:50:20 +02:00
print '<td> </td>' ;
2004-07-31 14:52:37 +02:00
print '<td align="center"><input type="submit" value="' . $langs -> trans ( " Add " ) . '" name="addligne"></td>' ;
2003-06-20 11:50:11 +02:00
print " </tr> \n " ;
}
2004-11-07 16:45:38 +01:00
2002-12-12 17:11:54 +01:00
print " </table> " ;
2004-11-07 16:14:09 +01:00
print '</form><br>' ;
2003-06-20 11:50:11 +02:00
2004-11-07 16:45:38 +01:00
}
2004-11-07 16:14:09 +01:00
print '</div>' ;
2004-07-20 17:19:54 +02:00
2004-11-07 16:45:38 +01:00
2002-12-12 17:11:54 +01:00
/*
2004-11-07 16:14:09 +01:00
* Barre d ' actions
2002-12-12 17:11:54 +01:00
*/
2004-03-05 16:48:09 +01:00
if ( $propal -> statut < 2 )
2003-06-20 11:50:11 +02:00
{
2004-03-05 16:48:09 +01:00
print '<p><div class="tabsAction">' ;
2003-07-25 02:04:44 +02:00
2004-11-07 16:14:09 +01:00
// Valid
2004-03-05 16:48:09 +01:00
if ( $propal -> statut == 0 )
2003-07-25 02:04:44 +02:00
{
2004-11-07 16:14:09 +01:00
if ( $user -> rights -> propale -> valider )
2003-08-11 21:12:13 +02:00
{
2004-11-07 16:14:09 +01:00
print " <a class= \" tabAction \" href= \" propal.php?propalid= $propal->id &valid=1 \" > " . $langs -> trans ( " Valid " ) . " </a> " ;
2003-08-11 21:12:13 +02:00
}
2004-03-05 16:48:09 +01:00
2003-07-25 02:04:44 +02:00
}
2004-11-07 16:14:09 +01:00
// Save
if ( $propal -> statut == 1 )
2003-07-25 02:04:44 +02:00
{
2004-11-07 16:14:09 +01:00
if ( $user -> rights -> propale -> creer )
2003-07-25 02:04:44 +02:00
{
2004-11-07 16:45:38 +01:00
print " <a class= \" tabAction \" href= \" propal.php?propalid= $propal->id &action=modif \" > " . $langs -> trans ( " Edit " ) . " </a> " ;
2003-07-25 02:04:44 +02:00
}
2004-11-07 16:14:09 +01:00
}
2004-03-05 16:48:09 +01:00
2004-11-07 16:14:09 +01:00
// Build PDF
2004-03-05 16:48:09 +01:00
if ( $propal -> statut < 2 && $user -> rights -> propale -> creer )
2003-06-20 11:50:11 +02:00
{
2004-11-07 16:14:09 +01:00
print '<a class="tabAction" href="propal.php?propalid=' . $propal -> id . '&action=pdf">' . $langs -> trans ( " BuildPDF " ) . '</a>' ;
2004-07-13 19:40:42 +02:00
}
2004-11-07 16:14:09 +01:00
// Send
2004-03-05 16:48:09 +01:00
if ( $propal -> statut == 1 )
2003-06-20 11:50:11 +02:00
{
2003-08-11 21:12:13 +02:00
if ( $user -> rights -> propale -> envoyer )
{
2004-12-23 18:53:27 +01:00
$file = $conf -> propal -> dir_output . " / $obj->ref / $obj->ref .pdf " ;
if ( file_exists ( $file ))
{
print " <a class= \" tabAction \" href= \" propal.php?propalid= $propal->id &action=presend \" > " . $langs -> trans ( " Send " ) . " </a> " ;
}
2003-07-25 02:04:44 +02:00
}
2003-06-20 11:50:11 +02:00
}
2004-11-07 16:14:09 +01:00
// Delete
2004-03-05 16:48:09 +01:00
if ( $propal -> statut == 0 )
2003-07-25 02:04:44 +02:00
{
2004-11-07 16:14:09 +01:00
if ( $user -> rights -> propale -> supprimer )
2003-08-11 21:12:13 +02:00
{
2004-12-23 18:53:27 +01:00
print " <a class= \" butDelete \" href= \" propal.php?propalid= $propal->id &action=delete \" > " . $langs -> trans ( " Delete " ) . " </a> " ;
2003-08-11 21:12:13 +02:00
}
2003-07-25 02:04:44 +02:00
}
2004-11-07 16:14:09 +01:00
// Close
if ( $propal -> statut != 0 )
2003-07-25 02:04:44 +02:00
{
2004-11-07 16:14:09 +01:00
if ( $propal -> statut == 1 && $user -> rights -> propale -> cloturer )
2003-08-11 21:12:13 +02:00
{
2004-11-07 16:14:09 +01:00
print " <a class= \" tabAction \" href= \" propal.php?propalid= $propal->id &action=statut \" > " . $langs -> trans ( " Close " ) . " </a> " ;
2003-08-11 21:12:13 +02:00
}
2004-11-07 16:14:09 +01:00
}
2004-11-07 16:45:38 +01:00
print " </div> " ;
}
2004-03-05 16:48:09 +01:00
2003-09-01 14:45:26 +02:00
2002-12-12 17:11:54 +01:00
/*
2003-09-01 14:45:26 +02:00
* Envoi de la propale par mail
2002-12-12 17:11:54 +01:00
*
*/
2004-07-21 12:12:50 +02:00
if ( $_GET [ " action " ] == 'send' )
2003-06-20 11:50:11 +02:00
{
2004-12-23 18:53:27 +01:00
$file = $conf -> propal -> dir_output . " / $propal->ref / $propal->ref .pdf " ;
2003-06-20 11:50:11 +02:00
if ( file_exists ( $file ))
{
2002-12-12 17:11:54 +01:00
2004-03-05 16:48:09 +01:00
$subject = " Notre proposition commerciale $propal->ref " ;
2004-01-08 12:43:33 +01:00
$filepath [ 0 ] = $file ;
2004-03-05 16:48:09 +01:00
$filename [ 0 ] = " $propal->ref .pdf " ;
2004-01-08 12:43:33 +01:00
$mimetype [ 0 ] = " application/pdf " ;
$filepath [ 1 ] = $_FILES [ 'addedfile' ][ 'tmp_name' ];
$filename [ 1 ] = $_FILES [ 'addedfile' ][ 'name' ];
$mimetype [ 1 ] = $_FILES [ 'addedfile' ][ 'type' ];
2005-01-11 21:26:22 +01:00
$from = $_POST [ " fromname " ] . " < " . $_POST [ " frommail " ] . " > " ;
$replyto = $_POST [ " replytoname " ] . " < " . $_POST [ " replytomail " ] . " > " ;
2002-12-12 17:11:54 +01:00
2005-01-11 21:26:22 +01:00
$mailfile = new CMailFile ( $subject , $_POST [ " sendto " ], $from , $_POST [ " message " ], $filepath , $mimetype , $filename , $sendtocc );
2002-12-12 17:11:54 +01:00
2003-08-31 01:38:13 +02:00
if ( ! $mailfile -> sendfile () )
{
2003-06-20 11:50:11 +02:00
print " <b>!! erreur d'envoi " ;
}
}
/*
* Enregistre l ' action
*
*/
2003-09-01 14:40:50 +02:00
$actioncomm = new ActionComm ( $db );
$actioncomm -> priority = 2 ;
$actioncomm -> type = 3 ;
$actioncomm -> date = $db -> idate ( time ());
$actioncomm -> percent = 100 ;
$actioncomm -> contact = $propal -> contactid ;
$actioncomm -> user = $user ;
$actioncomm -> societe = $propal -> socidp ;
$actioncomm -> propalrowid = $propal -> id ;
2004-07-21 12:12:50 +02:00
$actioncomm -> note = " Envoy<EFBFBD> e <20> " . $_POST [ " sendto " ];
2003-09-01 14:40:50 +02:00
$actioncomm -> add ( $user );
2003-06-20 11:50:11 +02:00
}
2004-11-07 16:14:09 +01:00
2003-06-20 11:50:11 +02:00
/*
*
*/
2003-10-24 10:09:48 +02:00
if ( $propal -> brouillon == 1 )
{
2003-11-27 12:39:08 +01:00
print '<form action="propal.php?propalid=' . $propal -> id . '" method="post">' ;
2003-10-24 10:09:48 +02:00
print '<input type="hidden" name="action" value="setpdfmodel">' ;
}
2004-12-23 18:53:27 +01:00
print '<table width="100%"><tr><td width="50%" valign="top">' ;
2004-11-07 16:14:09 +01:00
print_titre ( '<a href="propal/document.php?id=' . $propal -> id . '">' . $langs -> trans ( " Document " ) . '</a>' );
2003-10-24 10:09:48 +02:00
2004-04-27 16:02:52 +02:00
/*
*
*/
2004-11-07 16:14:09 +01:00
print '<table class="border" width="100%">' ;
2004-12-23 18:53:27 +01:00
$file = $conf -> propal -> dir_output . " / $propal->ref / $propal->ref .pdf " ;
2004-12-31 18:03:56 +01:00
$relativepath = " $propal->ref / $propal->ref .pdf " ;
$var = true ;
2003-06-20 11:50:11 +02:00
if ( file_exists ( $file ))
{
2004-12-31 18:03:56 +01:00
print " <tr $bc[$var] ><td> " . $langs -> trans ( " Propal " ) . " PDF</td> " ;
2004-07-12 11:52:54 +02:00
2004-12-31 18:03:56 +01:00
print '<td><a href="' . DOL_URL_ROOT . '/document.php?modulepart=propal&file=' . urlencode ( $relativepath ) . '">' . $propal -> ref . '.pdf</a></td>' ;
2004-04-27 16:02:52 +02:00
print '<td align="right">' . filesize ( $file ) . ' bytes</td>' ;
2004-07-12 11:52:54 +02:00
print '<td align="right">' . strftime ( " %d %B %Y %H:%M:%S " , filemtime ( $file )) . '</td></tr>' ;
2004-04-27 16:02:52 +02:00
}
2004-07-13 19:40:42 +02:00
if ( $propal -> brouillon == 1 && $user -> rights -> propale -> creer )
2003-09-06 17:13:29 +02:00
{
2004-12-31 18:03:56 +01:00
print " <tr $bc[$var] ><td>Mod<6F> le</td><td align= \" right \" > " ;
2003-09-06 17:13:29 +02:00
$html = new Form ( $db );
$modelpdf = new Propal_Model_pdf ( $db );
$html -> select_array ( " modelpdf " , $modelpdf -> liste_array (), $propal -> modelpdf );
2004-11-07 16:14:09 +01:00
print '</td><td colspan="2"><input type="submit" value="' . $langs -> trans ( " Save " ) . '">' ;
2003-10-24 10:09:48 +02:00
print '</td></tr>' ;
2003-09-06 17:13:29 +02:00
}
2003-06-20 11:50:11 +02:00
print " </table> \n " ;
2004-11-07 16:14:09 +01:00
2003-11-19 15:52:09 +01:00
/*
2004-12-22 21:17:18 +01:00
* Si le module commandes est activ<EFBFBD> ...
2003-11-19 15:52:09 +01:00
*/
2004-12-22 21:17:18 +01:00
if ( $conf -> commande -> enabled ) {
$nb_commande = sizeof ( $propal -> commande_liste_array ());
if ( $nb_commande > 0 )
{
$coms = $propal -> commande_liste_array ();
print '<br><table class="border" width="100%">' ;
if ( $nb_commande == 1 )
{
print " <tr><td>Commande rattach<63> e : " ;
print '<a href="' . DOL_URL_ROOT . '/commande/fiche.php?id=' . $coms [ 0 ] . '">' ;
print img_file ();
print '</a> <a href="' . DOL_URL_ROOT . '/commande/fiche.php?id=' . $coms [ 0 ] . '">' . $coms [ 0 ] . " </a> " ;
print " </td></tr> \n " ;
}
else
{
print " <tr><td>Commandes rattach<63> es</td></tr> \n " ;
for ( $i = 0 ; $i < $nb_commande ; $i ++ )
{
print '<tr><td><a href="' . DOL_URL_ROOT . '/commande/fiche.php?id=' . $coms [ $i ] . '">' . $coms [ $i ] . " </a></td> \n " ;
print " </tr> \n " ;
}
}
print " </table> " ;
}
}
2004-07-20 16:02:49 +02:00
2004-07-13 19:40:42 +02:00
// print '<a href="propal.php?propalid=$propalid&action=commande\">G<> n<EFBFBD> rer</a>";
2003-06-20 11:50:11 +02:00
/*
*
*/
print " </td><td valign= \" top \" width= \" 50% \" > " ;
/*
*
*/
$sql = " SELECT " . $db -> pdate ( " a.datea " ) . " as da, note, fk_user_author " ;
2004-01-30 11:32:21 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " actioncomm as a WHERE a.fk_soc = $obj->idp AND a.propalrowid = $propal->id " ;
2003-06-20 11:50:11 +02:00
if ( $db -> query ( $sql ) )
{
$num = $db -> num_rows ();
$i = 0 ; $total = 0 ;
2003-09-16 21:53:09 +02:00
if ( $num > 0 )
2003-06-20 11:50:11 +02:00
{
2003-09-16 21:53:09 +02:00
print_titre ( " Propale envoy<6F> e " );
2004-11-07 16:14:09 +01:00
print '<table class="border" width="100%">' ;
print " <tr><td> " . $langs -> trans ( " Date " ) . " </td><td> " . $langs -> trans ( " Author " ) . " </td></tr> \n " ;
2003-09-16 21:53:09 +02:00
while ( $i < $num )
{
2004-10-23 18:55:07 +02:00
$objp = $db -> fetch_object ();
print " <tr><td> " . strftime ( " %d %B %Y %H:%M:%S " , $objp -> da ) . " </td> \n " ;
2003-09-16 21:53:09 +02:00
$authoract = new User ( $db );
$authoract -> id = $objp -> fk_user_author ;
$authoract -> fetch ( '' );
2004-10-23 18:55:07 +02:00
print " <td> $authoract->code </td></tr> \n " ;
2003-09-16 21:53:09 +02:00
print " <tr><td colspan= \" 2 \" > $objp->note </td></tr> " ;
$i ++ ;
}
print " </table> " ;
2003-06-20 11:50:11 +02:00
}
$db -> free ();
}
else
{
2004-12-23 18:53:27 +01:00
dolibarr_print_error ( $db );
2003-06-20 11:50:11 +02:00
}
/*
*
*/
print " </td></tr></table> " ;
2003-10-24 10:09:48 +02:00
if ( $propal -> brouillon == 1 )
{
print '</form>' ;
}
2004-11-07 16:14:09 +01:00
2003-06-20 11:50:11 +02:00
/*
*
*
*/
2004-07-21 12:12:50 +02:00
if ( $_GET [ " action " ] == 'presend' )
2003-06-20 11:50:11 +02:00
{
2003-06-24 13:34:59 +02:00
$replytoname = $user -> fullname ;
$replytomail = $user -> email ;
2003-06-20 11:50:11 +02:00
$from_name = $user -> fullname ; //$conf->propal->fromtoname;
$from_mail = $user -> email ; //conf->propal->fromtomail;
2004-03-05 16:48:09 +01:00
$message = " Veuillez trouver ci-joint notre proposition commerciale $propal->ref\n\nCordialement\n\n " ;
2004-01-08 12:43:33 +01:00
2004-12-22 21:17:18 +01:00
2004-07-13 19:40:42 +02:00
print " <form method= \" post \" ENCTYPE= \" multipart/form-data \" action= \" propal.php?propalid= $propal->id &action=send \" > \n " ;
2004-07-21 12:12:50 +02:00
print '<input type="hidden" name="replytoname" value="' . $replytoname . '">' ;
print '<input type="hidden" name="replytomail" value="' . $replytomail . '">' ;
2004-01-08 12:43:33 +01:00
print '<input type="hidden" name="max_file_size" value="2000000">' ;
2003-06-20 11:50:11 +02:00
print_titre ( " Envoyer la propale par mail " );
2004-11-28 17:03:12 +01:00
2005-01-11 21:26:22 +01:00
// Cr<43> <72> 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=array_merge(array(" "),$soc->contact_email_array());
$formmail -> withto = ucfirst ( strtolower ( $obj -> firstname )) . " " . ucfirst ( strtolower ( $obj -> name )) . " < $obj->email > " ;
$formmail -> withcc = 1 ;
$formmail -> withtopic = 1 ;
$formmail -> withfile = 1 ;
$formmail -> withbody = 1 ;
// Tableau des substitutions
$formmail -> substit [ " __PROPREF__ " ] = $propal -> ref ;
// Tableau des param<61> tres compl<70> 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 ();
2003-06-20 11:50:11 +02:00
}
}
else
2003-06-19 15:12:27 +02:00
{
2004-10-30 00:17:32 +02:00
dolibarr_print_error ( $db );
2004-07-20 16:02:49 +02:00
}
2004-10-30 00:17:32 +02:00
}
else
{
2003-09-03 15:49:34 +02:00
/****************************************************************************
* *
* *
* Mode Liste des propales *
* *
* *
****************************************************************************/
2002-07-29 12:26:12 +02:00
2004-07-30 10:14:15 +02:00
$sortorder = $_GET [ " sortorder " ];
$sortfield = $_GET [ " sortfield " ];
$page = $_GET [ " page " ];
$viewstatut = $_GET [ " viewstatut " ];
2003-05-25 18:37:00 +02:00
if ( $sortfield == " " )
{
$sortfield = " p.datep " ;
}
if ( $sortorder == " " )
{
$sortorder = " DESC " ;
}
2002-07-29 12:26:12 +02:00
2003-06-24 22:52:25 +02:00
$limit = $conf -> liste_limit ;
2004-07-30 10:14:15 +02:00
$offset = $limit * $page ;
$pageprev = $page - 1 ;
$pagenext = $page + 1 ;
2002-07-29 12:26:12 +02:00
2004-03-04 15:57:49 +01:00
$sql = " SELECT s.nom, s.idp, s.client, p.rowid as propalid, p.price, p.ref, " . $db -> pdate ( " p.datep " ) . " as dp, " . $db -> pdate ( " p.fin_validite " ) . " as dfv, c.label as statut, c.id as statutid " ;
2005-01-16 18:42:20 +01:00
$sql .= " FROM " . MAIN_DB_PREFIX . " societe as s, " . MAIN_DB_PREFIX . " propal as p, " . MAIN_DB_PREFIX . " c_propalst as c " ;
$sql .= " WHERE p.fk_soc = s.idp AND p.fk_statut = c.id " ;
2002-04-30 12:44:42 +02:00
2005-01-16 18:42:20 +01:00
if ( $_GET [ " socidp " ])
2003-06-21 14:58:04 +02:00
{
2005-01-16 18:42:20 +01:00
$sql .= " AND s.idp = " . $_GET [ " socidp " ];
2003-06-21 14:58:04 +02:00
}
2003-11-27 12:39:08 +01:00
if ( $_GET [ " viewstatut " ] <> '' )
2003-06-21 14:58:04 +02:00
{
2003-11-27 12:39:08 +01:00
$sql .= " AND c.id = " . $_GET [ " viewstatut " ];
2003-06-21 14:58:04 +02:00
}
if ( $month > 0 )
{
$sql .= " AND date_format(p.datep, '%Y-%m') = ' $year - $month ' " ;
}
if ( $year > 0 )
{
$sql .= " AND date_format(p.datep, '%Y') = $year " ;
}
2002-04-30 12:44:42 +02:00
2004-07-13 19:40:42 +02:00
if ( strlen ( $_POST [ " sf_ref " ]) > 0 )
2003-09-03 15:49:34 +02:00
{
2004-07-13 19:40:42 +02:00
$sql .= " AND p.ref like '% " . $_POST [ " sf_ref " ] . " %' " ;
2003-09-03 15:49:34 +02:00
}
2003-05-17 17:38:34 +02:00
$sql .= " ORDER BY $sortfield $sortorder " ;
2003-07-10 15:21:41 +02:00
$sql .= $db -> plimit ( $limit + 1 , $offset );
2002-04-30 12:44:42 +02:00
2003-06-21 14:58:04 +02:00
if ( $db -> query ( $sql ) )
{
$num = $db -> num_rows ();
2004-07-30 10:14:15 +02:00
print_barre_liste ( " Propositions commerciales " , $page , " propal.php " , " &socidp= $socidp " , $sortfield , $sortorder , '' , $num );
2003-07-10 15:21:41 +02:00
2003-06-21 14:58:04 +02:00
$i = 0 ;
2004-10-31 14:00:04 +01:00
print '<table class="noborder" width="100%">' ;
2003-06-21 14:58:04 +02:00
2004-08-02 04:58:38 +02:00
print '<tr class="liste_titre">' ;
2004-10-31 14:00:04 +01:00
print_liste_field_titre ( $langs -> trans ( " Ref " ), " propal.php " , " p.ref " , " " , " &socidp= $socidp &viewstatut= $viewstatut " , 'width="15%"' , $sortfield );
print_liste_field_titre ( $langs -> trans ( " Company " ), " propal.php " , " s.nom " , " " , " &socidp= $socidp &viewstatut= $viewstatut " , 'width="30%"' , $sortfield );
print_liste_field_titre ( $langs -> trans ( " Date " ), " propal.php " , " p.datep " , " " , " &socidp= $socidp &viewstatut= $viewstatut " , 'width="25%" align="right" colspan="2"' , $sortfield );
print_liste_field_titre ( $langs -> trans ( " Price " ), " propal.php " , " p.price " , " " , " &socidp= $socidp &viewstatut= $viewstatut " , ' width="20%" align="right"' , $sortfield );
print_liste_field_titre ( $langs -> trans ( " Status " ), " propal.php " , " p.fk_statut " , " " , " &socidp= $socidp &viewstatut= $viewstatut " , 'width="10%" align="center"' , $sortfield );
2003-06-21 16:56:17 +02:00
print " </tr> \n " ;
2004-10-23 18:55:07 +02:00
$var = true ;
2002-04-30 12:44:42 +02:00
2003-07-10 20:09:12 +02:00
while ( $i < min ( $num , $limit ))
2003-06-21 14:58:04 +02:00
{
2004-10-23 18:55:07 +02:00
$objp = $db -> fetch_object ();
2003-11-19 15:52:09 +01:00
$now = time ();
2003-06-21 14:58:04 +02:00
$var =! $var ;
2004-02-09 10:29:51 +01:00
print " <tr $bc[$var] > " ;
print '<td><a href="propal.php?propalid=' . $objp -> propalid . '">' ;
print img_file ();
2004-12-31 18:03:56 +01:00
print " </a> <a href= \" propal.php?propalid= $objp->propalid\ " > $objp -> ref </ a ></ td > \n " ;
2004-03-04 15:57:49 +01:00
if ( $objp -> client == 1 )
{
2004-12-23 18:53:27 +01:00
$url = DOL_URL_ROOT . '/comm/fiche.php?socid=' . $objp -> idp ;
2004-03-04 15:57:49 +01:00
}
else
{
$url = DOL_URL_ROOT . '/comm/prospect/fiche.php?socid=' . $objp -> idp ;
}
print '<td><a href="' . $url . '">' . $objp -> nom . '</a></td>' ;
2003-11-19 15:52:09 +01:00
if ( $now > $objp -> dfv && $objp -> dfv > 0 )
2003-06-21 14:58:04 +02:00
{
2003-11-19 15:52:09 +01:00
print " <td> " . strftime ( " %d %b %Y " , $objp -> dfv ) . " </td> " ;
2003-06-21 14:58:04 +02:00
}
else
{
print " <td> </td> " ;
}
2004-10-23 18:55:07 +02:00
print " <td align= \" right \" > " ;
2003-06-21 14:58:04 +02:00
$y = strftime ( " %Y " , $objp -> dp );
$m = strftime ( " %m " , $objp -> dp );
print strftime ( " %d " , $objp -> dp ) . " \n " ;
2003-10-14 17:30:39 +02:00
print " <a href= \" propal.php?year= $y &month= $m\ " > " ;
2003-06-21 14:58:04 +02:00
print strftime ( " %B " , $objp -> dp ) . " </a> \n " ;
2003-09-11 22:18:51 +02:00
print " <a href= \" propal.php?year= $y\ " > " ;
2004-10-30 00:17:32 +02:00
print strftime ( " %Y " , $objp -> dp ) . " </a></td> \n " ;
2003-06-21 14:58:04 +02:00
2004-10-23 18:55:07 +02:00
print " <td align= \" right \" > " . price ( $objp -> price ) . " </td> \n " ;
print " <td align= \" center \" > $objp->statut </td> \n " ;
print " </tr> \n " ;
2003-06-21 14:58:04 +02:00
$total = $total + $objp -> price ;
$subtotal = $subtotal + $objp -> price ;
$i ++ ;
}
2003-09-01 14:45:26 +02:00
print " </table> " ;
2003-06-21 14:58:04 +02:00
$db -> free ();
2002-04-30 12:44:42 +02:00
}
2003-05-17 17:38:34 +02:00
else
{
2004-10-30 00:17:32 +02:00
dolibarr_print_error ( $db );
2003-05-17 17:38:34 +02:00
}
2002-04-30 12:44:42 +02:00
}
$db -> close ();
2004-10-30 00:17:32 +02:00
2002-04-30 12:44:42 +02:00
llxFooter ( " <em>Dernière modification $Date $ révision $Revision $ </em> " );
2004-10-30 00:17:32 +02:00
2002-04-30 12:44:42 +02:00
?>