* Copyright (C) 2004-2006 Destailleur Laurent * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005-2006 Regis Houssin * * 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. * * $Id$ * $Source$ */ /** \file htdocs/compta/propal.php \ingroup propale \brief Page liste des propales (vision compta) */ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/propal.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/propal.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/CMailFile.class.php"); if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT.'/project.class.php'); if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT.'/commande/commande.class.php'); $user->getrights('facture'); $user->getrights('propale'); if (!$user->rights->propale->lire) accessforbidden(); $langs->load('companies'); $langs->load('compta'); $langs->load('orders'); $page=$_GET["page"]; $sortorder=$_GET["sortorder"]; $sortfield=$_GET["sortfield"]; if (! $sortorder) $sortorder="ASC"; if (! $sortfield) $sortfield="nom"; if ($page == -1) { $page = 0 ; } $offset = $conf->liste_limit * $page ; $pageprev = $page - 1; $pagenext = $page + 1; // Sécurité accés client $socidp=''; if ($_GET["socidp"]) { $socidp=$_GET["socidp"]; } if ($user->societe_id > 0) { $action = ''; $socidp = $user->societe_id; } /******************************************************************************/ /* Actions */ /******************************************************************************/ if ($_GET["action"] == 'setstatut') { /* * Classée la facture comme facturée */ $propal = new Propal($db); $propal->id = $_GET["propalid"]; $propal->cloture($user, $_GET["statut"], $note); } if ( $action == 'delete' ) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."propal WHERE rowid = $propalid;"; if ( $db->query($sql) ) { $sql = "DELETE FROM ".MAIN_DB_PREFIX."propaldet WHERE fk_propal = $propalid ;"; if ( $db->query($sql) ) { print '
'.$langs->trans("Deleted").'
'; } else { dolibarr_print_error($db); } } else { dolibarr_print_error($db); } $propalid = 0; $brouillon = 1; } llxHeader(); $html = new Form($db); /* * * Mode fiche * */ if ($_GET["propalid"] > 0) { if ($mesg) print "$mesg
"; $propal = new Propal($db); $propal->fetch($_GET['propalid']); $societe = new Societe($db); $societe->fetch($propal->socidp); $head = propal_prepare_head($propal); dolibarr_fiche_head($head, 'compta', $langs->trans('Proposal')); /* * Fiche propal * */ print ''; // Ref print ''; // Ref client print ''; print ''; $rowspan=8; // Société print ''; // Ligne info remises tiers print ''; // Dates print ''; if ($conf->projet->enabled) $rowspan++; // Note print ''; print ''; // Date fin propal print ''; print ''; print ''; // Conditions et modes de réglement print ''; // Mode de paiement print ''; print ''; // Projet if ($conf->projet->enabled) { $langs->load("projects"); print ''; $numprojet = $societe->has_projects(); if (! $numprojet) { print ''; } else { if ($propal->statut == 0 && $user->rights->propale->creer) { print ''; } else { if (!empty($propal->projetidp)) { print ''; } else { print ''; } } } print ''; } // Amount print ''; print ''; print ''; print ''; print ''; print ''; print ''; // Statut print ''; print '
'.$langs->trans('Ref').''.$propal->ref_url.'
'; print ''; if ($_GET['action'] != 'refclient' && $propal->brouillon) print ''; print '
'; print $langs->trans('RefCustomer').''; print ''.img_edit($langs->trans('Edit')).'
'; print '
'; print $propal->ref_client; print '
'.$langs->trans('Company').''.$societe->getNomUrl(1).'
'.$langs->trans('Discounts').''; if ($societe->remise_client) print $langs->trans("CompanyHasRelativeDiscount",$societe->remise_client); else print $langs->trans("CompanyHasNoRelativeDiscount"); $absolute_discount=$societe->getCurrentDiscount(); print '. '; if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",$absolute_discount,$langs->trans("Currency".$conf->monnaie)); else print $langs->trans("CompanyHasNoAbsoluteDiscount"); print '.'; print '
'.$langs->trans('Date').''; print dolibarr_print_date($propal->date,'%a %d %B %Y'); print ''.$langs->trans('NotePublic').' :
'. nl2br($propal->note_public).'
'.$langs->trans('DateEndPropal').''; if ($propal->fin_validite) { print dolibarr_print_date($propal->fin_validite,'%a %d %B %Y'); if ($propal->statut == 1 && $propal->fin_validite < (time() - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late")); } else { print $langs->trans("Unknown"); } print '
'; print ''; if ($_GET['action'] != 'editconditions' && $propal->brouillon) print ''; print '
'; print $langs->trans('PaymentConditionsShort'); print 'id.'">'.img_edit($langs->trans('SetConditions'),1).'
'; print '
'; if ($_GET['action'] == 'editconditions') { $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->cond_reglement_id,'cond_reglement_id'); } else { $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->cond_reglement_id,'none'); } print '
'; print ''; if ($_GET['action'] != 'editmode' && $propal->brouillon) print ''; print '
'; print $langs->trans('PaymentMode'); print 'id.'">'.img_edit($langs->trans('SetMode'),1).'
'; print '
'; if ($_GET['action'] == 'editmode') { $html->form_modes_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->mode_reglement_id,'mode_reglement_id'); } else { $html->form_modes_reglement($_SERVER['PHP_SELF'].'?propalid='.$propal->id,$propal->mode_reglement_id,'none'); } print '
'.$langs->trans('Project').''; print $langs->trans("NoProject").''; print 'id.'&action=create>'.$langs->trans('AddProject').''; print ''; $html->select_projects($societe->id, $propal->projetidp, 'projetidp'); print ''; $proj = new Project($db); $proj->fetch($propal->projetidp); print ''; print $proj->title; print ''; print ' 
'.$langs->trans('AmountHT').''.price($propal->price).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('AmountVAT').''.price($propal->total_tva).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('AmountTTC').''.price($propal->total_ttc).''.$langs->trans("Currency".$conf->monnaie).'
'.$langs->trans('Status').''.$propal->getLibStatut(4).'

'; /* * 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.rang ASC'; $resql = $db->query($sql); if ($resql) { $num_lignes = $db->num_rows($resql); $i = 0; $total = 0; print ''; if ($num_lignes) { print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; } $var=true; while ($i < $num_lignes) { $objp = $db->fetch_object($resql); $var=!$var; if ($_GET['action'] != 'editline' || $_GET['rowid'] != $objp->rowid) { print ''; if ($objp->fk_product > 0) { print ''; } else { print '\n"; } print ''; print '\n"; print ''; if ($objp->remise_percent > 0) { print '\n"; } else { print ''; } print '\n"; print ''; print ''; } $total = $total + ($objp->qty * $objp->price); $i++; } $db->free($resql); } else { dolibarr_print_error($db); } /* * Lignes de remise */ // Réductions relatives (Remises-Ristournes-Rabbais) /* Une réduction doit s'appliquer obligatoirement sur des lignes de factures et non globalement $var=!$var; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if ($_GET['action'] != 'editrelativediscount') { if ($propal->brouillon && $user->rights->propale->creer) { print ''; } else { print ''; } if ($propal->brouillon && $user->rights->propale->creer && $propal->remise_percent) { print ''; } else { print ''; } print ''; } else { print ''; } print ''; print ''; */ // Remise absolue /* Les remises absolues doivent s'appliquer par ajout de lignes spécialisées $var=!$var; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; if ($_GET['action'] != 'editabsolutediscount') { if ($propal->brouillon && $user->rights->propale->creer) { print ''; } else { print ''; } if ($propal->brouillon && $user->rights->propale->creer && $propal->remise_absolue) { print ''; } else { print ''; } print ''; } else { print ''; } print ''; print ''; */ print '
'.$langs->trans('Description').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('Qty').''.$langs->trans('Discount').''.$langs->trans('AmountHT').'   
'; if ($objp->fk_product_type) print img_object($langs->trans('ShowService'),'service'); else print img_object($langs->trans('ShowProduct'),'product'); print ' '.$objp->ref.' - '.stripslashes(nl2br($objp->product)); 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 ($objp->description && $objp->description!=$objp->product)?'
'.stripslashes(nl2br($objp->description)):''; print '
'.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 "'.$objp->tva_tx.'%'.price($objp->subprice)."'.$objp->qty.''.$objp->remise_percent."% '.price($objp->subprice*$objp->qty*(100-$objp->remise_percent)/100)." 
'; print $langs->trans('CustomerRelativeDiscount'); if ($propal->brouillon) print ' ('.($soc->remise_client?$langs->trans("CompanyHasRelativeDiscount",$soc->remise_client):$langs->trans("CompanyHasNoRelativeDiscount")).')'; print '   '; if ($_GET['action'] == 'editrelativediscount') { print '%'; } else { print $propal->remise_percent?$propal->remise_percent.'%':' '; } print ''; if ($_GET['action'] != 'editrelativediscount') print $propal->remise_percent?'-'.price($propal->remise_percent*$total/100):$langs->trans("DiscountNone"); else print ' '; print 'id.'">'.img_edit($langs->trans('SetRelativeDiscount'),1).' rowid.'">'; print img_delete(); print '  
'; print $langs->trans('CustomerAbsoluteDiscount'); if ($propal->brouillon) print ' ('.($avoir_en_cours?$langs->trans("CompanyHasAbsoluteDiscount",$avoir_en_cours,$langs->trans("Currency".$conf->monnaie)):$langs->trans("CompanyHasNoAbsoluteDiscount")).')'; print '    '; if ($_GET['action'] == 'editabsolutediscount') { print '-'; } else { print $propal->remise_absolue?'-'.price($propal->remise_absolue):$langs->trans("DiscountNone"); } print 'id.'">'.img_edit($langs->trans('SetAbsoluteDiscount'),1).' rowid.'">'; print img_delete(); print '  
'; print ''; /* * Boutons Actions */ if ($propal->statut <> 4 && $user->societe_id == 0) { print '
'; if ($propal->statut == 2 && $user->rights->facture->creer) { print '".$langs->trans("BuildBill").""; } if ($propal->statut == 2 && sizeof($propal->getFactureListeArray())) { print '".$langs->trans("ClassifyBilled").""; } print "
"; print "
\n"; } print '
'; /* * Documents générés */ $filename=sanitize_string($propal->ref); $filedir=$conf->propal->dir_output . "/" . sanitize_string($propal->ref); $urlsource=$_SERVER["PHP_SELF"]."?propalid=".$propal->id; $genallowed=0; $delallowed=0; $var=true; $somethingshown=$html->show_documents('propal',$filename,$filedir,$urlsource,$genallowed,$delallowed); /* * Commandes rattachées */ if($conf->commande->enabled) { $coms = $propal->associated_orders(); if (sizeof($coms) > 0) { require_once(DOL_DOCUMENT_ROOT.'/commande/commande.class.php'); $staticcommande=new Commande($db); $total=0; if ($somethingshown) { print '
'; $somethingshown=1; } print_titre($langs->trans('RelatedOrders')); print ''; print ''; print ''; print ''; print ''; print ''; print ''; $var=true; for ($i = 0 ; $i < sizeof($coms) ; $i++) { $var=!$var; print '\n"; print ''; print ''; print ''; print "\n"; $total = $total + $objp->total; } print '
'.$langs->trans("Ref").''.$langs->trans("Date").''.$langs->trans("Price").''.$langs->trans("Status").'
'; print ''.img_object($langs->trans("ShowOrder"),"order").' '.$coms[$i]->ref."'.dolibarr_print_date($coms[$i]->date).''.price($coms[$i]->total_ttc).''.$staticcommande->LibStatut($coms[$i]->statut,$coms[$i]->facturee,3).'
'; } } /* * Factures associees */ $sql = "SELECT f.facnumber, f.total,".$db->pdate("f.datef")." as df, f.rowid as facid, f.fk_user_author, f.fk_statut, f.paye"; $sql .= " FROM ".MAIN_DB_PREFIX."facture as f"; if (!$conf->commande->enabled) { $sql .= ", ".MAIN_DB_PREFIX."fa_pr as fp"; $sql .= " WHERE fp.fk_facture = f.rowid AND fp.fk_propal = ".$propal->id; } else { $sql .= ", ".MAIN_DB_PREFIX."co_pr as cp, ".MAIN_DB_PREFIX."co_fa as cf"; $sql .= " WHERE cp.fk_propale = ".$propal->id." AND cf.fk_commande = cp.fk_commande AND cf.fk_facture = f.rowid"; } $resql = $db->query($sql); if ($resql) { $num_fac_asso = $db->num_rows($resql); $i = 0; $total = 0; if ($somethingshown) { print '
'; $somethingshown=1; } if ($num_fac_asso > 1) print_titre($langs->trans("RelatedBills")); else print_titre($langs->trans("RelatedBill")); print ''; print ""; print ''; print ''; print ''; print ''; print "\n"; require_once(DOL_DOCUMENT_ROOT.'/facture.class.php'); $staticfacture=new Facture($db); $var=True; while ($i < $num_fac_asso) { $objp = $db->fetch_object(); $var=!$var; print ""; print ''; print ''; print ''; print ''; print ""; $total = $total + $objp->total; $i++; } print ""; print ""; print "\n"; print "
'.$langs->trans("Ref").''.$langs->trans("Date").''.$langs->trans("Price").''.$langs->trans("Status").'
'.img_object($langs->trans("ShowBill"),"bill").' '.$objp->facnumber.''.dolibarr_print_date($objp->df).''.price($objp->total).''.$staticfacture->LibStatut($objp->paye,$objp->fk_statut,3).'
".$langs->trans("TotalHT")."".price($total)." 
"; $db->free(); } print '
'; /* * Liste des actions propres à la propal */ $sql = 'SELECT id, '.$db->pdate('a.datea'). ' as da, label, note, fk_user_author' ; $sql .= ' FROM '.MAIN_DB_PREFIX.'actioncomm as a'; $sql .= ' WHERE a.fk_soc = '.$societe->id.' AND a.propalrowid = '.$propal->id ; $resql = $db->query($sql); if ($resql) { $num = $db->num_rows($resql); if ($num) { print_titre($langs->trans('ActionsOnPropal')); $i = 0; $total = 0; $var=true; print ''; print ''; print "\n"; while ($i < $num) { $objp = $db->fetch_object($resql); $var=!$var; print ''; print ''; print '\n"; print ''; $authoract = new User($db); $authoract->id = $objp->fk_user_author; $authoract->fetch(''); print ''; print "\n"; $i++; } print '
'.$langs->trans('Ref').''.$langs->trans('Date').''.$langs->trans('Action').''.$langs->trans('By').'
'.img_object($langs->trans('ShowTask'),'task').' '.$objp->id.''.dolibarr_print_date($objp->da)."'.stripslashes($objp->label).''.$authoract->code.'
'; } } else { dolibarr_print_error($db); } print '
'; } else { /** * * Mode Liste des propales * */ if (! $sortfield) $sortfield="p.datep"; if (! $sortorder) $sortorder="DESC"; if ($page == -1) $page = 0 ; $limit = $conf->liste_limit; $offset = $limit * $page ; $pageprev = $page - 1; $pagenext = $page + 1; $sql = "SELECT s.nom, s.idp, p.rowid as propalid, p.price, p.ref, p.fk_statut, "; $sql.= $db->pdate("p.datep")." as dp, "; $sql.= $db->pdate("p.fin_validite")." as dfin"; if (!$user->rights->commercial->client->voir && !$socidp) $sql .= ", sc.fk_soc, sc.fk_user"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s, ".MAIN_DB_PREFIX."propal as p"; if (!$user->rights->commercial->client->voir && !$socidp) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE p.fk_soc = s.idp"; if (!$user->rights->commercial->client->voir && !$socidp) $sql .= " AND s.idp = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socidp) $sql .= " AND s.idp = $socidp"; if ($viewstatut <> '') $sql .= " AND p.fk_statut in ($viewstatut)"; // viewstatut peut etre combinaisons séparé par virgules if ($month > 0) $sql .= " AND date_format(p.datep, '%Y-%m') = '$year-$month'"; if ($year > 0) $sql .= " AND date_format(p.datep, '%Y') = $year"; $sql .= " ORDER BY $sortfield $sortorder, p.rowid DESC "; $sql .= $db->plimit($limit + 1,$offset); if ( $db->query($sql) ) { $num = $db->num_rows(); $propalstatic=new Propal($db); print_barre_liste($langs->trans("Proposals"), $page, "propal.php","&socidp=$socidp",$sortfield,$sortorder,'',$num); $i = 0; $var=true; print ""; print ''; print_liste_field_titre($langs->trans("Ref"),"propal.php","p.ref","","&year=$year&viewstatut=$viewstatut",'',$sortfield); print_liste_field_titre($langs->trans("Company"),"propal.php","s.nom","&viewstatut=$viewstatut","",'',$sortfield); print_liste_field_titre($langs->trans("Date"),"propal.php","p.datep","&viewstatut=$viewstatut","",'align="right"',$sortfield); print_liste_field_titre($langs->trans("Price"),"propal.php","p.price","&viewstatut=$viewstatut","",'align="right"',$sortfield); print_liste_field_titre($langs->trans("Status"),"propal.php","p.fk_statut","&viewstatut=$viewstatut","",'align="right"',$sortfield); print "\n"; while ($i < min($num, $limit)) { $objp = $db->fetch_object(); $var=!$var; print ""; // Ref print '\n"; // Societe print "\n"; // Date print "\n"; // Prix print "\n"; print "\n"; print "\n"; $i++; } print "
'.img_object($langs->trans("ShowPropal"),"propal").' '; print $objp->ref.""; if ($objp->fk_statut==1 && $obj->dfin < time() - $conf->propal->cloture->warning_delay) { print " ".img_warning($langs->trans("Late")); } print "idp\">".dolibarr_trunc($objp->nom,44).""; $y = strftime("%Y",$objp->dp); $m = strftime("%m",$objp->dp); print strftime("%d",$objp->dp)."\n"; print " "; print strftime("%B",$objp->dp)."\n"; print " "; print strftime("%Y",$objp->dp)."".price($objp->price)."".$propalstatic->LibStatut($objp->fk_statut,5)."
"; $db->free(); } else { dolibarr_print_error($db); } } $db->close(); llxFooter('$Date$ - $Revision$'); ?>