* Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005-2010 Regis Houssin * Copyright (C) 2008 Raphael Bertrand (Resultic) * Copyright (C) 2010 Juanjo Menent * * 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, see . */ /** * \file htdocs/compta/propal.php * \ingroup propale * \brief Page liste des propales (vision compta) * \version $Id: propal.php,v 1.194 2011/08/03 00:46:24 eldy Exp $ */ require('../main.inc.php'); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formfile.class.php"); require_once(DOL_DOCUMENT_ROOT."/core/class/html.formother.class.php"); require_once(DOL_DOCUMENT_ROOT."/comm/propal/class/propal.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/propal.lib.php"); if ($conf->projet->enabled) require_once(DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'); if ($conf->commande->enabled) require_once(DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'); $langs->load('companies'); $langs->load('compta'); $langs->load('orders'); $langs->load('bills'); $sortfield = GETPOST("sortfield",'alpha'); $sortorder = GETPOST("sortorder",'alpha'); $page = GETPOST("page",'int'); if ($page == -1) { $page = 0; } $offset = $conf->liste_limit * $page; $pageprev = $page - 1; $pagenext = $page + 1; $viewstatut=$_GET['viewstatut']; $propal_statut = $_GET['propal_statut']; if($propal_statut != '') $viewstatut=$propal_statut; if (! $sortorder) $sortorder="DESC"; if (! $sortfield) $sortfield="p.datep"; $module='propale'; if (! empty($_GET["socid"])) { $objectid=$_GET["socid"]; $module='societe'; $dbtable=''; } else if (! empty($_GET["id"])) { $objectid=$_GET["id"]; $module='propale'; $dbtable='propal'; } // Security check if ($user->societe_id) $socid=$user->societe_id; $result = restrictedArea($user, $module, $objectid, $dbtable); $object = new Propal($db); /******************************************************************************/ /* Actions */ /******************************************************************************/ if ($_GET["action"] == 'setstatut') { // Close proposal $object->id = $_GET["id"]; $object->cloture($user, $_GET["statut"], $note); } // Set project if ($_POST['action'] == 'classin') { $object->fetch($_GET["id"]); $object->setProject($_POST['projectid']); } /* * View */ $now=gmmktime(); llxHeader(); $html = new Form($db); $htmlother = new FormOther($db); $formfile = new FormFile($db); $societestatic=new Societe($db); $propalstatic=new Propal($db); $now=gmmktime(); $id = $_GET["id"]; $ref= $_GET["ref"]; if ($id > 0 || ! empty($ref)) { if ($mesg) print "$mesg
"; $product_static=new Product($db); $object->fetch($_GET["id"],$_GET["ref"]); $societe = new Societe($db); $societe->fetch($object->socid); $head = propal_prepare_head($object); dol_fiche_head($head, 'compta', $langs->trans('Proposal'), 0, 'propal'); /* * Proposal card */ print ''; $linkback="".$langs->trans("BackToList").""; // Ref print ''; // Ref client print ''; print ''; $rowspan=8; // Company print ''; // Ligne info remises tiers print ''; // Dates print ''; if ($conf->projet->enabled) $rowspan++; //Local taxes if ($mysoc->pays_code=='ES') { if($mysoc->localtax1_assuj=="1") $rowspan++; if($mysoc->localtax2_assuj=="1") $rowspan++; } // Note print ''; print ''; // Date fin propal print ''; print ''; print ''; // Payment term print ''; // Payment mode print ''; print ''; // Project if ($conf->projet->enabled) { $langs->load("projects"); print ''; } else { print '
'.$langs->trans('Ref').''; print $html->showrefnav($object,'ref',$linkback,1,'ref','ref',''); print '
'; print ''; if ($_GET['action'] != 'refclient' && $object->brouillon) print ''; print '
'; print $langs->trans('RefCustomer').''; print ''.img_edit($langs->trans('Modify')).'
'; print '
'; print $object->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->getAvailableDiscounts(); print '. '; if ($absolute_discount) print $langs->trans("CompanyHasAbsoluteDiscount",price($absolute_discount),$langs->trans("Currency".$conf->monnaie)); else print $langs->trans("CompanyHasNoAbsoluteDiscount"); print '.'; print '
'.$langs->trans('Date').''; print dol_print_date($object->date,'daytext'); print ''.$langs->trans('NotePublic').' :
'. nl2br($object->note_public).'
'.$langs->trans('DateEndPropal').''; if ($object->fin_validite) { print dol_print_date($object->fin_validite,'daytext'); if ($object->statut == 1 && $object->fin_validite < ($now - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late")); } else { print $langs->trans("Unknown"); } print '
'; print ''; if ($_GET['action'] != 'editconditions' && $object->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'].'?id='.$object->id,$object->cond_reglement_id,'cond_reglement_id'); } else { $html->form_conditions_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->cond_reglement_id,'none'); } print '
'; print ''; if ($_GET['action'] != 'editmode' && $object->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'].'?id='.$object->id,$object->mode_reglement_id,'mode_reglement_id'); } else { $html->form_modes_reglement($_SERVER['PHP_SELF'].'?id='.$object->id,$object->mode_reglement_id,'none'); } print '
'; print ''; if (1 == 2 && $user->rights->propale->creer) { if ($_GET['action'] != 'classer') print ''; print '
'; print $langs->trans('Project').''.img_edit($langs->trans('SetProject')).'
'; print '
'; if ($_GET['action'] == 'classer') { $html->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'projectid'); } else { $html->form_project($_SERVER['PHP_SELF'].'?id='.$object->id, $object->socid, $object->fk_project, 'none'); } print '
'; if (!empty($object->fk_project)) { print ''; $project = new Project($db); $project->fetch($object->fk_project); print ''; print $project->ref; print ''; print ''; } else { print ' '; } } print ''; } // Amount print ''.$langs->trans('AmountHT').''; print ''.price($object->total_ht).''; print ''.$langs->trans("Currency".$conf->monnaie).''; print ''.$langs->trans('AmountVAT').''.price($object->total_tva).''; print ''.$langs->trans("Currency".$conf->monnaie).''; // Amount Local Taxes if ($mysoc->pays_code=='ES') { if ($mysoc->localtax1_assuj=="1") //Localtax1 RE { print ''.$langs->transcountry("AmountLT1",$mysoc->pays_code).''; print ''.price($object->total_localtax1).''; print ''.$langs->trans("Currency".$conf->monnaie).''; } if ($mysoc->localtax2_assuj=="1") //Localtax2 IRPF { print ''.$langs->transcountry("AmountLT2",$mysoc->pays_code).''; print ''.price($object->total_localtax2).''; print ''.$langs->trans("Currency".$conf->monnaie).''; } } print ''.$langs->trans('AmountTTC').''.price($object->total_ttc).''; print ''.$langs->trans("Currency".$conf->monnaie).''; // Statut print ''.$langs->trans('Status').''.$object->getLibStatut(4).''; print '
'; /* * Lines */ print ''; $sql = 'SELECT pt.rowid, pt.description, pt.price, pt.fk_product, pt.fk_remise_except,'; $sql.= ' pt.qty, pt.tva_tx, pt.remise_percent, pt.subprice, pt.info_bits,'; $sql.= ' pt.total_ht, pt.total_tva, pt.total_ttc,'; $sql.= ' pt.product_type,'; $sql.= ' p.rowid as prodid, p.label as product_label, p.ref, p.fk_product_type, '; $sql.= ' p.description as product_desc'; $sql.= ' FROM '.MAIN_DB_PREFIX.'propaldet as pt'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'product as p ON pt.fk_product=p.rowid'; $sql.= ' WHERE pt.fk_propal = '.$object->id; $sql.= ' ORDER BY pt.rang ASC, pt.rowid'; $resql = $db->query($sql); if ($resql) { $num_lignes = $db->num_rows($resql); $i = 0; $total = 0; 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; // Show product and description $type=$objp->product_type?$objp->product_type:$objp->fk_product_type; // Try to enhance type detection using date_start and date_end for free lines where type // was not saved. if (! empty($objp->date_start)) $type=1; if (! empty($objp->date_end)) $type=1; if ($_GET['action'] != 'editline' || $_GET['rowid'] != $objp->rowid) { print ''; if ($objp->fk_product > 0) { print ''; } else { print '\n"; } print ''; print '\n"; // Qty print ''; if ($objp->remise_percent > 0) { print '\n"; } else { print ''; } print '\n"; print ''; print ''; } $i++; } $db->free($resql); } else { dol_print_error($db); } print '
'.$langs->trans('Description').''.$langs->trans('VAT').''.$langs->trans('PriceUHT').''.$langs->trans('Qty').''.$langs->trans('ReductionShort').''.$langs->trans('AmountHT').'   
'; print ''; // ancre pour retourner sur la ligne; // Show product and description $product_static->type=$objp->fk_product_type; $product_static->id=$objp->fk_product; $product_static->ref=$objp->ref; $product_static->libelle=$objp->product_label; $text=$product_static->getNomUrl(1); $text.= ' - '.$objp->product_label; $description=($conf->global->PRODUIT_DESC_IN_FORM?'':dol_htmlentitiesbr($objp->description)); print $html->textwithtooltip($text,$description,3,'','',$i); // Show range print_date_range($objp->date_start,$objp->date_end); // Add description in form if ($conf->global->PRODUIT_DESC_IN_FORM) { print ($objp->description && $objp->description!=$objp->product_label)?'
'.dol_htmlentitiesbr($objp->description):''; } print '
'; print ''; // ancre pour retourner sur la ligne if (($objp->info_bits & 2) == 2) { print ''; print img_object($langs->trans("ShowReduc"),'reduc').' '.$langs->trans("Discount"); print ''; if ($objp->description) { if ($objp->description == '(CREDIT_NOTE)') { $discount=new DiscountAbsolute($db); $discount->fetch($objp->fk_remise_except); print ' - '.$langs->transnoentities("DiscountFromCreditNote",$discount->getNomUrl(0)); } else { print ' - '.nl2br($objp->description); } } } else { if ($type==1) $text = img_object($langs->trans('Service'),'service'); else $text = img_object($langs->trans('Product'),'product'); print $text.' '.nl2br($objp->description); // Show range print_date_range($objp->date_start,$objp->date_end); } print "'.vatrate($objp->tva_tx).'%'.price($objp->subprice)."'; if (($objp->info_bits & 2) != 2) { print $objp->qty; } else print ' '; print ''.$objp->remise_percent."% '.price($objp->total_ht)." 
'; print ''; /* * Boutons Actions */ print '
'; if ($object->statut <> 4 && $user->societe_id == 0) { if ($object->statut == 2 && $user->rights->facture->creer) { print ''.$langs->trans("BuildBill").''; } $arraypropal=$object->getInvoiceArrayList(); if ($object->statut == 2 && is_array($arraypropal) && sizeof($arraypropal) > 0) { print 'socid.'">'.$langs->trans("ClassifyBilled").''; } } print "
"; print "
\n"; print '
'; /* * Documents generes */ $filename=dol_sanitizeFileName($object->ref); $filedir=$conf->propale->dir_output . "/" . dol_sanitizeFileName($object->ref); $urlsource=$_SERVER["PHP_SELF"]."?id=".$object->id; $genallowed=0; $delallowed=0; $var=true; $somethingshown=$formfile->show_documents('propal',$filename,$filedir,$urlsource,$genallowed,$delallowed); /* * Linked object block */ $somethingshown=$object->showLinkedObjectBlock(); print ''; // List of actions on element include_once(DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php'); $formactions=new FormActions($db); $somethingshown=$formactions->showactions($object,'propal',$socid); print '
'; } else { /** * * Mode List * */ $now=dol_now(); $limit = $conf->liste_limit; $offset = $limit * $page ; $pageprev = $page - 1; $pagenext = $page + 1; $year = $_REQUEST["year"]; $month = $_REQUEST["month"]; $sql = "SELECT s.nom, s.rowid as socid, s.client,"; $sql.= " p.rowid as propalid, p.ref, p.fk_statut,"; $sql.= " p.total_ht, p.tva, p.total,"; $sql.= " p.datep as dp,"; $sql.= " p.fin_validite as dfin"; $sql.= " FROM ".MAIN_DB_PREFIX."societe as s"; $sql.= ", ".MAIN_DB_PREFIX."propal as p"; if (!$user->rights->societe->client->voir && !$socid) $sql.= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; $sql.= " WHERE p.fk_soc = s.rowid"; $sql.= " AND p.entity = ".$conf->entity; if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; if ($socid) $sql.= " AND s.rowid = ".$socid; if ($viewstatut <> '') $sql.= " AND p.fk_statut in ($viewstatut)"; // viewstatut peut etre combinaisons separe par virgules if ($month > 0) { if ($year > 0) $sql.= " AND date_format(p.datep, '%Y-%m') = '".$year."-".$month."'"; else $sql.= " AND date_format(p.datep, '%m') = '".$month."'"; } if ($year > 0) $sql .= " AND date_format(p.datep, '%Y') = '".$year."'"; if (!empty($_GET['search_ref'])) { $sql.= " AND p.ref LIKE '%".$db->escape($_GET['search_ref'])."%'"; } if (!empty($_GET['search_societe'])) { $sql.= " AND s.nom LIKE '%".$db->escape($_GET['search_societe'])."%'"; } if (!empty($_GET['search_montant_ht'])) { $sql.= " AND p.price='".$db->escape($_GET['search_montant_ht'])."'"; } $sql.= " ORDER BY $sortfield $sortorder, p.rowid DESC "; $sql.= $db->plimit($limit + 1,$offset); $result = $db->query($sql); if ($result) { $num = $db->num_rows($result); print_barre_liste($langs->trans("Proposals"), $page, "propal.php","&socid=$socid&month=$month&year=$year&search_ref=$search_ref&search_societe=$search_societe&search_montant_ht=$search_montant_ht".'&viewstatut='.$viewstatut,$sortfield,$sortorder,'',$num); $i = 0; $var=true; print ""; print ''; print_liste_field_titre($langs->trans("Ref"),"propal.php","p.ref","","&year=$year&viewstatut=$viewstatut",'width=20%',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Company"),"propal.php","s.nom","&viewstatut=$viewstatut","",'',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Date"),"propal.php","p.datep","&viewstatut=$viewstatut","",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("AmountHT"),"propal.php","p.price","&viewstatut=$viewstatut","",'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Status"),"propal.php","p.fk_statut","&viewstatut=$viewstatut","",'align="right"',$sortfield,$sortorder); print ''; print "\n"; // Lignes des champs de filtre print ''; print ''; print ''; print ''; print ''; print ''; print ''; print ''; print "\n"; print ''; while ($i < min($num, $limit)) { $objp = $db->fetch_object($result); $var=!$var; print ""; print '\n"; // Societe print ""; // Date print "\n"; // Prix print "\n"; print "\n"; print ""; print "\n"; $i++; } print "
 
'; print ''; print ''; print ''; print ''; print $langs->trans('Month').': '; print ' '.$langs->trans('Year').': '; $syear = $year; if($syear == '') $syear = date("Y"); $htmlother->select_year($syear,'year',1, 20, 5); print ''; print ''; print ''; $html->select_propal_statut($viewstatut); print ''; print '
'; $propalstatic->id=$objp->propalid; $propalstatic->ref=$objp->ref; //Ref print ''; print ''; print ''; print '
'; print $propalstatic->getNomUrl(1, '', "&socid=$socid&viewstatut=$viewstatut&sortfield=$sortfield&$sortorder"); print ''; if ($objp->fk_statut == 1 && $db->jdate($objp->dfin) < ($now - $conf->propal->cloture->warning_delay)) print img_warning($langs->trans("Late")); print ''; $filename=dol_sanitizeFileName($objp->ref); $filedir=$conf->propale->dir_output . '/' . dol_sanitizeFileName($objp->ref); $urlsource=$_SERVER['PHP_SELF'].'?id='.$objp->propalid; $formfile->show_documents('propal',$filename,$filedir,$urlsource,'','','',1,'',1); print '
'; print "
"; $societestatic->nom=$objp->nom; $societestatic->id=$objp->socid; $societestatic->client=$objp->client; print $societestatic->getNomUrl(1,'customer',44); print ""; $y = dol_print_date($db->jdate($objp->dp),"%Y"); $m = dol_print_date($db->jdate($objp->dp),"%m"); $mt = dol_print_date($db->jdate($objp->dp),"%b"); $d = dol_print_date($db->jdate($objp->dp),"%d"); print $d."\n"; print " "; print $mt."\n"; print " "; print $y."".price($objp->total_ht)."".$propalstatic->LibStatut($objp->fk_statut,5)." 
"; $db->free($result); } else { dol_print_error($db); } } $db->close(); llxFooter('$Date: 2011/08/03 00:46:24 $ - $Revision: 1.194 $'); ?>