* Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin * Copyright (C) 2012 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 3 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/projet/element.php * \ingroup projet facture * \brief Page of project referrers */ require '../main.inc.php'; require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/class/html.formprojet.class.php'; require_once DOL_DOCUMENT_ROOT.'/core/lib/project.lib.php'; if (! empty($conf->propal->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php'; if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php'; if (! empty($conf->facture->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture-rec.class.php'; if (! empty($conf->commande->enabled)) require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php'; if (! empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.facture.class.php'; if (! empty($conf->fournisseur->enabled)) require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.commande.class.php'; if (! empty($conf->contrat->enabled)) require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php'; if (! empty($conf->ficheinter->enabled)) require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php'; if (! empty($conf->deplacement->enabled)) require_once DOL_DOCUMENT_ROOT.'/compta/deplacement/class/deplacement.class.php'; if (! empty($conf->agenda->enabled)) require_once DOL_DOCUMENT_ROOT.'/comm/action/class/actioncomm.class.php'; $langs->load("projects"); $langs->load("companies"); $langs->load("suppliers"); if (! empty($conf->facture->enabled)) $langs->load("bills"); if (! empty($conf->commande->enabled)) $langs->load("orders"); if (! empty($conf->propal->enabled)) $langs->load("propal"); if (! empty($conf->ficheinter->enabled)) $langs->load("interventions"); $projectid=GETPOST('id','int'); $ref=GETPOST('ref','alpha'); $action=GETPOST('action','alpha'); if ($projectid == '' && $ref == '') { dol_print_error('','Bad parameter'); exit; } $mine = $_REQUEST['mode']=='mine' ? 1 : 0; //if (! $user->rights->projet->all->lire) $mine=1; // Special for projects $project = new Project($db); if ($ref) { $project->fetch(0,$ref); $projectid=$project->id; }else { $project->fetch($projectid); } // Security check $socid=0; if ($user->societe_id > 0) $socid=$user->societe_id; $result = restrictedArea($user, 'projet', $projectid); /* * View */ $help_url="EN:Module_Projects|FR:Module_Projets|ES:Módulo_Proyectos"; llxHeader("",$langs->trans("Referers"),$help_url); $form = new Form($db); $formproject=new FormProjets($db); $userstatic=new User($db); $project = new Project($db); $project->fetch($projectid,$ref); $project->societe->fetch($project->societe->id); // To verify role of users $userAccess = $project->restrictedProjectArea($user); $head=project_prepare_head($project); dol_fiche_head($head, 'element', $langs->trans("Project"),0,($project->public?'projectpub':'project')); print ''; $linkback = ''.$langs->trans("BackToList").''; print ''; print ''; print ''; // Visibility print ''; // Statut print ''; print '
'.$langs->trans("Ref").''; // Define a complementary filter for search of next/prev ref. if (! $user->rights->projet->all->lire) { $projectsListId = $project->getProjectsAuthorizedForUser($user,$mine,0); $project->next_prev_filter=" rowid in (".(count($projectsListId)?join(',',array_keys($projectsListId)):'0').")"; } print $form->showrefnav($project, 'ref', $linkback, 1, 'ref', 'ref'); print '
'.$langs->trans("Label").''.$project->title.'
'.$langs->trans("ThirdParty").''; if (! empty($project->societe->id)) print $project->societe->getNomUrl(1); else print ' '; print '
'.$langs->trans("Visibility").''; if ($project->public) print $langs->trans('SharedProject'); else print $langs->trans('PrivateProject'); print '
'.$langs->trans("Status").''.$project->getLibStatut(4).'
'; print ''; /* * Referers types */ $listofreferent=array( 'propal'=>array( 'title'=>"ListProposalsAssociatedProject", 'class'=>'Propal', 'table'=>'propal', 'test'=>$conf->propal->enabled && $user->rights->propale->lire), 'order'=>array( 'title'=>"ListOrdersAssociatedProject", 'class'=>'Commande', 'table'=>'commande', 'test'=>$conf->commande->enabled && $user->rights->commande->lire), 'invoice'=>array( 'title'=>"ListInvoicesAssociatedProject", 'class'=>'Facture', 'margin'=>'add', 'table'=>'facture', 'test'=>$conf->facture->enabled && $user->rights->facture->lire), 'invoice_predefined'=>array( 'title'=>"ListPredefinedInvoicesAssociatedProject", 'class'=>'FactureRec', 'table'=>'facture_rec', 'test'=>$conf->facture->enabled && $user->rights->facture->lire), 'order_supplier'=>array( 'title'=>"ListSupplierOrdersAssociatedProject", 'class'=>'CommandeFournisseur', 'table'=>'commande_fournisseur', 'test'=>$conf->fournisseur->enabled && $user->rights->fournisseur->commande->lire), 'invoice_supplier'=>array( 'title'=>"ListSupplierInvoicesAssociatedProject", 'class'=>'FactureFournisseur', 'margin'=>'minus', 'table'=>'facture_fourn', 'test'=>$conf->fournisseur->enabled && $user->rights->fournisseur->facture->lire), 'contract'=>array( 'title'=>"ListContractAssociatedProject", 'class'=>'Contrat', 'table'=>'contrat', 'test'=>$conf->contrat->enabled && $user->rights->contrat->lire), 'intervention'=>array( 'title'=>"ListFichinterAssociatedProject", 'class'=>'Fichinter', 'table'=>'fichinter', 'disableamount'=>1, 'test'=>$conf->ficheinter->enabled && $user->rights->ficheinter->lire), 'trip'=>array( 'title'=>"ListTripAssociatedProject", 'class'=>'Deplacement', 'table'=>'deplacement', 'margin'=>'minus', 'disableamount'=>1, 'test'=>$conf->deplacement->enabled && $user->rights->deplacement->lire), 'agenda'=>array( 'title'=>"ListActionsAssociatedProject", 'class'=>'ActionComm', 'table'=>'actioncomm', 'disableamount'=>1, 'test'=>$conf->agenda->enabled && $user->rights->agenda->allactions->lire) ); if ($action=="addelement") { $tablename = GETPOST("tablename"); $elementselectid = GETPOST("elementselect"); $result=$project->update_element($tablename, $elementselectid); if ($result<0) { setEventMessage($mailchimp->error,'errors'); } } foreach ($listofreferent as $key => $value) { $title=$value['title']; $classname=$value['class']; $tablename=$value['table']; $qualified=$value['test']; if ($qualified) { print '
'; print_titre($langs->trans($title)); $selectList=$formproject->select_element($tablename); if ($selectList) { print '
'; print ''; print ''; print ''; print ''; print ''; print '
'.$langs->trans("SelectElement").''.$selectList.'
'; print '
'; } print ''; print ''; print ''; print ''; print ''; if (empty($value['disableamount'])) print ''; if (empty($value['disableamount'])) print ''; print ''; print ''; $elementarray = $project->get_element_list($key, $tablename); if (count($elementarray)>0 && is_array($elementarray)) { $var=true; $total_ht = 0; $total_ttc = 0; $num=count($elementarray); for ($i = 0; $i < $num; $i++) { $element = new $classname($db); $element->fetch($elementarray[$i]); $element->fetch_thirdparty(); //print $classname; $var=!$var; print ""; // Ref print '\n"; // Date $date=$element->date; if (empty($date)) $date=$element->datep; if (empty($date)) $date=$element->date_contrat; if (empty($date)) $date=$element->datev; //Fiche inter print ''; // Third party print ''; // Amount if (empty($value['disableamount'])) print ''; // Amount if (empty($value['disableamount'])) print ''; // Status print ''; print ''; $total_ht = $total_ht + $element->total_ht; $total_ttc = $total_ttc + $element->total_ttc; } print ''; if (empty($value['disableamount'])) print ''; if (empty($value['disableamount'])) print ''; print ''; print ''; } print "
'.$langs->trans("Ref").''.$langs->trans("Date").''.$langs->trans("ThirdParty").''.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").''.$langs->trans("Status").'
'; print $element->getNomUrl(1); print "'.dol_print_date($date,'day').''; if (is_object($element->client)) print $element->client->getNomUrl(1,'',48); print ''.(isset($element->total_ht)?price($element->total_ht):' ').''.(isset($element->total_ttc)?price($element->total_ttc):' ').''.$element->getLibStatut(5).'
'.$langs->trans("Number").': '.$i.''.$langs->trans("TotalHT").' : '.price($total_ht).''.$langs->trans("TotalTTC").' : '.price($total_ttc).' 
"; /* * Barre d'action */ print '
'; if ($project->statut > 0) { if ($project->societe->prospect || $project->societe->client) { if ($key == 'propal' && ! empty($conf->propal->enabled) && $user->rights->propale->creer) { print ''.$langs->trans("AddProp").''; } if ($key == 'order' && ! empty($conf->commande->enabled) && $user->rights->commande->creer) { print ''.$langs->trans("AddCustomerOrder").''; } if ($key == 'invoice' && ! empty($conf->facture->enabled) && $user->rights->facture->creer) { print ''.$langs->trans("AddCustomerInvoice").''; } } if ($project->societe->fournisseur) { if ($key == 'order_supplier' && ! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->commande->creer) { print ''.$langs->trans("AddSupplierInvoice").''; } if ($key == 'invoice_supplier' && ! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->creer) { print ''.$langs->trans("AddSupplierOrder").''; } } } print '
'; } } // Margin display of the project print_titre("Margin"); print ''; print ''; print ''; print ''; print ''; print ''; print ''; foreach ($listofreferent as $key => $value) { $title=$value['title']; $classname=$value['class']; $tablename=$value['table']; $qualified=$value['test']; $margin = $value['margin']; if (isset($margin)) { $elementarray = $project->get_element_list($key, $tablename); if (count($elementarray)>0 && is_array($elementarray)) { $var=true; $total_ht = 0; $total_ttc = 0; $num=count($elementarray); for ($i = 0; $i < $num; $i++) { $element = new $classname($db); $element->fetch($elementarray[$i]); $element->fetch_thirdparty(); //print $classname; $total_ht = $total_ht + $element->total_ht; $total_ttc = $total_ttc + $element->total_ttc; } print ''; print ''; print ''; print ''; print ''; print ''; if ($margin=="add") { $margin_ht+= $total_ht; $margin_ttc+= $total_ttc; } else { $margin_ht-= $total_ht; $margin_ttc-= $total_ttc; } } } } // and the margin amount total print ''; print ''; print ''; print ''; print ''; print "
'.$langs->trans("Element").''.$langs->trans("Number").''.$langs->trans("AmountHT").''.$langs->trans("AmountTTC").'
'.$classname.''.$i.''.price($total_ht).''.price($total_ttc).'
'.$langs->trans("Total").''.price($margin_ht).''.price($margin_ttc).'
"; llxFooter(); $db->close();