2006-09-05 03:31:09 +02:00
< ? php
2012-03-18 11:13:01 +01:00
/* Copyright ( C ) 2004 Rodolphe Quiedeville < rodolphe @ quiedeville . org >
* Copyright ( C ) 2004 - 2011 Laurent Destailleur < eldy @ users . sourceforge . net >
2018-10-27 14:43:12 +02:00
* Copyright ( C ) 2005 - 2012 Regis Houssin < regis . houssin @ inodbox . com >
2013-04-09 17:18:07 +02:00
* Copyright ( C ) 2013 Florian Henry < florian . henry @ open - concept . pro >
2021-05-07 21:28:35 +02:00
* Copyright ( C ) 2017 Ferran Marcet < fmarcet @ 2 byte . es >
* Copyright ( C ) 2021 Frédéric France < frederic . france @ netlogic . fr >
2013-04-09 17:18:07 +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 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
2019-09-23 21:55:30 +02:00
* along with this program . If not , see < https :// www . gnu . org / licenses />.
2011-12-12 14:19:21 +01:00
*/
2006-09-05 03:31:09 +02:00
/**
2009-07-19 17:39:25 +02:00
* \file htdocs / fourn / facture / note . php
* \ingroup facture
2014-07-20 19:35:00 +02:00
* \brief Fiche de notes sur une facture fournisseur
*/
2006-09-05 03:31:09 +02:00
2012-08-22 23:24:21 +02:00
require '../../main.inc.php' ;
2012-08-22 23:11:24 +02:00
require_once DOL_DOCUMENT_ROOT . '/core/lib/fourn.lib.php' ;
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.class.php' ;
require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.facture.class.php' ;
2022-06-14 17:53:17 +02:00
if ( ! empty ( $conf -> project -> enabled )) {
2019-11-13 19:35:39 +01:00
require_once DOL_DOCUMENT_ROOT . '/projet/class/project.class.php' ;
2017-12-26 12:13:35 +01:00
}
2006-09-05 03:31:09 +02:00
2018-10-01 08:22:23 +02:00
$langs -> loadLangs ( array ( " bills " , " companies " ));
2006-09-05 03:31:09 +02:00
2019-01-27 11:55:16 +01:00
$id = ( GETPOST ( 'id' , 'int' ) ? GETPOST ( 'id' , 'int' ) : GETPOST ( 'facid' , 'int' ));
$ref = GETPOST ( 'ref' , 'alpha' );
2020-09-16 19:39:50 +02:00
$action = GETPOST ( 'action' , 'aZ09' );
2006-09-05 03:31:09 +02:00
2009-04-27 22:37:50 +02:00
// Security check
2021-02-25 23:21:30 +01:00
if ( $user -> socid ) {
$socid = $user -> socid ;
}
2021-07-09 18:36:21 +02:00
// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
$hookmanager -> initHooks ( array ( 'invoicesuppliernote' ));
2012-03-18 00:59:24 +01:00
$result = restrictedArea ( $user , 'fournisseur' , $id , 'facture_fourn' , 'facture' );
2006-09-05 03:31:09 +02:00
2011-12-12 14:19:21 +01:00
$object = new FactureFournisseur ( $db );
2013-07-14 01:29:26 +02:00
$object -> fetch ( $id , $ref );
2011-12-12 14:19:21 +01:00
2021-04-12 07:37:34 +02:00
$permissionnote = ( $user -> rights -> fournisseur -> facture -> creer || $user -> rights -> supplier_invoice -> creer ); // Used by the include of actions_setnotes.inc.php
2006-09-05 03:31:09 +02:00
2014-01-11 13:33:30 +01:00
/*
* Actions
*/
2006-09-05 03:31:09 +02:00
2021-07-09 18:36:21 +02:00
$reshook = $hookmanager -> executeHooks ( 'doActions' , array (), $object , $action ); // Note that $action and $object may have been modified by some hooks
2021-07-11 09:48:33 +02:00
if ( $reshook < 0 ) {
2021-07-09 18:36:21 +02:00
setEventMessages ( $hookmanager -> error , $hookmanager -> errors , 'errors' );
2021-07-11 09:48:33 +02:00
}
2021-07-11 09:49:05 +02:00
if ( empty ( $reshook )) {
2021-07-09 18:36:21 +02:00
include DOL_DOCUMENT_ROOT . '/core/actions_setnotes.inc.php' ; // Must be include, not include_once
2021-07-11 09:48:33 +02:00
}
2006-09-05 03:31:09 +02:00
2011-12-12 14:19:21 +01:00
// Set label
2021-04-12 07:37:34 +02:00
if ( $action == 'setlabel' && ( $user -> rights -> fournisseur -> facture -> creer || $user -> rights -> supplier_invoice -> creer )) {
2022-02-22 23:44:56 +01:00
$object -> label = GETPOST ( 'label' );
2020-04-10 10:59:32 +02:00
$result = $object -> update ( $user );
2021-02-25 23:21:30 +01:00
if ( $result < 0 ) {
dol_print_error ( $db );
}
2011-12-12 14:19:21 +01:00
}
2006-09-05 03:31:09 +02:00
2009-07-19 17:39:25 +02:00
/*
* View
2013-07-14 01:29:26 +02:00
*/
2006-09-05 03:31:09 +02:00
2011-11-08 10:18:45 +01:00
$form = new Form ( $db );
2006-09-05 03:31:09 +02:00
2019-11-13 19:35:39 +01:00
$title = $langs -> trans ( 'SupplierInvoice' ) . " - " . $langs -> trans ( 'Notes' );
2016-08-31 07:05:23 +02:00
$helpurl = " EN:Module_Suppliers_Invoices|FR:Module_Fournisseurs_Factures|ES:Módulo_Facturas_de_proveedores " ;
llxHeader ( '' , $title , $helpurl );
2009-07-19 17:39:25 +02:00
2021-02-25 23:21:30 +01:00
if ( $object -> id > 0 ) {
2013-04-09 17:18:07 +02:00
$object -> fetch_thirdparty ();
2020-04-10 10:59:32 +02:00
$alreadypaid = $object -> getSommePaiement ();
2017-10-03 14:50:52 +02:00
2013-04-09 17:18:07 +02:00
$head = facturefourn_prepare_head ( $object );
2020-04-10 10:59:32 +02:00
$titre = $langs -> trans ( 'SupplierInvoice' );
2020-12-23 23:16:27 +01:00
print dol_get_fiche_head ( $head , 'note' , $titre , - 1 , 'supplier_invoice' );
2013-04-09 17:18:07 +02:00
2016-12-23 07:37:34 +01:00
// Supplier invoice card
2020-10-31 14:32:18 +01:00
$linkback = '<a href="' . DOL_URL_ROOT . '/fourn/facture/list.php?restore_lastsearch_values=1' . ( ! empty ( $socid ) ? '&socid=' . $socid : '' ) . '">' . $langs -> trans ( " BackToList " ) . '</a>' ;
$morehtmlref = '<div class="refidno">' ;
// Ref supplier
$morehtmlref .= $form -> editfieldkey ( " RefSupplier " , 'ref_supplier' , $object -> ref_supplier , $object , 0 , 'string' , '' , 0 , 1 );
$morehtmlref .= $form -> editfieldval ( " RefSupplier " , 'ref_supplier' , $object -> ref_supplier , $object , 0 , 'string' , '' , null , null , '' , 1 );
// Thirdparty
$morehtmlref .= '<br>' . $langs -> trans ( 'ThirdParty' ) . ' : ' . $object -> thirdparty -> getNomUrl ( 1 );
2021-02-25 23:21:30 +01:00
if ( empty ( $conf -> global -> MAIN_DISABLE_OTHER_LINK ) && $object -> thirdparty -> id > 0 ) {
$morehtmlref .= ' (<a href="' . DOL_URL_ROOT . '/fourn/facture/list.php?socid=' . $object -> thirdparty -> id . '&search_company=' . urlencode ( $object -> thirdparty -> name ) . '">' . $langs -> trans ( " OtherBills " ) . '</a>)' ;
}
2020-10-31 14:32:18 +01:00
// Project
2022-06-14 17:53:17 +02:00
if ( ! empty ( $conf -> project -> enabled )) {
2020-10-31 14:32:18 +01:00
$langs -> load ( " projects " );
$morehtmlref .= '<br>' . $langs -> trans ( 'Project' ) . ' ' ;
2021-04-12 09:47:16 +02:00
if ( $user -> rights -> fournisseur -> commande -> creer || $user -> rights -> supplier_order -> creer ) {
2020-10-31 14:32:18 +01:00
if ( $action != 'classify' ) {
2021-09-18 22:09:55 +02:00
// $morehtmlref.='<a class="editfielda" href="' . $_SERVER['PHP_SELF'] . '?action=classify&token='.newToken().'&id=' . $object->id . '">' . img_edit($langs->transnoentitiesnoconv('SetProject')) . '</a> : ';
2020-04-10 10:59:32 +02:00
$morehtmlref .= ' : ' ;
2019-10-27 09:51:15 +01:00
}
if ( $action == 'classify' ) {
2020-10-31 14:32:18 +01:00
//$morehtmlref.=$form->form_project($_SERVER['PHP_SELF'] . '?id=' . $object->id, $object->socid, $object->fk_project, 'projectid', 0, 0, 1, 1);
$morehtmlref .= '<form method="post" action="' . $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id . '">' ;
$morehtmlref .= '<input type="hidden" name="action" value="classin">' ;
$morehtmlref .= '<input type="hidden" name="token" value="' . newToken () . '">' ;
$morehtmlref .= $formproject -> select_projects ( $object -> socid , $object -> fk_project , 'projectid' , $maxlength , 0 , 1 , 0 , 1 , 0 , 0 , '' , 1 );
$morehtmlref .= '<input type="submit" class="button valignmiddle" value="' . $langs -> trans ( " Modify " ) . '">' ;
$morehtmlref .= '</form>' ;
} else {
$morehtmlref .= $form -> form_project ( $_SERVER [ 'PHP_SELF' ] . '?id=' . $object -> id , $object -> socid , $object -> fk_project , 'none' , 0 , 0 , 0 , 1 );
}
} else {
if ( ! empty ( $object -> fk_project )) {
$proj = new Project ( $db );
$proj -> fetch ( $object -> fk_project );
2021-10-29 09:40:38 +02:00
$morehtmlref .= ' : ' . $proj -> getNomUrl ( 1 );
if ( $proj -> title ) {
$morehtmlref .= ' - ' . $proj -> title ;
}
2020-10-31 14:32:18 +01:00
} else {
$morehtmlref .= '' ;
}
}
}
$morehtmlref .= '</div>' ;
2022-05-22 17:09:08 +02:00
$object -> totalpaid = $alreadypaid ; // To give a chance to dol_banner_tab to use already paid amount to show correct status
2020-10-31 14:32:18 +01:00
dol_banner_tab ( $object , 'ref' , $linkback , 1 , 'ref' , 'ref' , $morehtmlref );
print '<div class="fichecenter">' ;
print '<div class="underbanner clearboth"></div>' ;
2013-04-09 17:18:07 +02:00
2020-01-15 19:49:45 +01:00
print '<table class="border centpercent tableforfield">' ;
2017-05-05 12:33:49 +02:00
2020-10-31 14:32:18 +01:00
// Type
2016-12-23 07:37:34 +01:00
print '<tr><td class="titlefield">' . $langs -> trans ( 'Type' ) . '</td><td>' ;
2021-05-07 21:28:35 +02:00
print '<span class="badgeneutral">' ;
2013-04-09 17:18:07 +02:00
print $object -> getLibType ();
2021-05-07 21:28:35 +02:00
print '</span>' ;
2021-02-25 23:21:30 +01:00
if ( $object -> type == FactureFournisseur :: TYPE_REPLACEMENT ) {
2019-11-13 19:35:39 +01:00
$facreplaced = new FactureFournisseur ( $db );
2013-04-09 17:18:07 +02:00
$facreplaced -> fetch ( $object -> fk_facture_source );
2019-01-27 11:55:16 +01:00
print ' (' . $langs -> transnoentities ( " ReplaceInvoice " , $facreplaced -> getNomUrl ( 1 )) . ')' ;
2013-04-09 17:18:07 +02:00
}
2021-02-25 23:21:30 +01:00
if ( $object -> type == FactureFournisseur :: TYPE_CREDIT_NOTE ) {
2019-11-13 19:35:39 +01:00
$facusing = new FactureFournisseur ( $db );
2013-04-09 17:18:07 +02:00
$facusing -> fetch ( $object -> fk_facture_source );
2019-01-27 11:55:16 +01:00
print ' (' . $langs -> transnoentities ( " CorrectInvoice " , $facusing -> getNomUrl ( 1 )) . ')' ;
2013-04-09 17:18:07 +02:00
}
2019-11-13 19:35:39 +01:00
$facidavoir = $object -> getListIdAvoirFromInvoice ();
2021-02-25 23:21:30 +01:00
if ( count ( $facidavoir ) > 0 ) {
2021-05-07 21:28:35 +02:00
$invoicecredits = array ();
foreach ( $facidavoir as $facid ) {
2019-11-13 19:35:39 +01:00
$facavoir = new FactureFournisseur ( $db );
2021-05-07 21:28:35 +02:00
$facavoir -> fetch ( $facid );
$invoicecredits [] = $facavoir -> getNomUrl ( 1 );
2013-04-09 17:18:07 +02:00
}
2021-05-07 21:28:35 +02:00
print ' (' . $langs -> transnoentities ( " InvoiceHasAvoir " ) . implode ( ',' , $invoicecredits ) . ')' ;
2013-04-09 17:18:07 +02:00
}
2022-09-05 17:31:30 +02:00
/*
2021-02-25 23:21:30 +01:00
if ( $facidnext > 0 ) {
2019-11-13 19:35:39 +01:00
$facthatreplace = new FactureFournisseur ( $db );
2013-04-09 17:18:07 +02:00
$facthatreplace -> fetch ( $facidnext );
2019-01-27 11:55:16 +01:00
print ' (' . $langs -> transnoentities ( " ReplacedByInvoice " , $facthatreplace -> getNomUrl ( 1 )) . ')' ;
2013-04-09 17:18:07 +02:00
}
2022-09-05 17:31:30 +02:00
*/
2013-04-09 17:18:07 +02:00
print '</td></tr>' ;
// Label
2019-01-27 11:55:16 +01:00
print '<tr><td>' . $form -> editfieldkey ( " Label " , 'label' , $object -> label , $object , 0 ) . '</td><td>' ;
print $form -> editfieldval ( " Label " , 'label' , $object -> label , $object , 0 );
2014-07-20 19:35:00 +02:00
print '</td></tr>' ;
2013-04-09 17:18:07 +02:00
2015-04-06 16:13:23 +02:00
// Amount
2019-01-27 11:55:16 +01:00
print '<tr><td>' . $langs -> trans ( 'AmountHT' ) . '</td><td>' . price ( $object -> total_ht , 1 , $langs , 0 , - 1 , - 1 , $conf -> currency ) . '</td></tr>' ;
print '<tr><td>' . $langs -> trans ( 'AmountVAT' ) . '</td><td>' . price ( $object -> total_tva , 1 , $langs , 0 , - 1 , - 1 , $conf -> currency ) . '</td></tr>' ;
2015-04-06 16:13:23 +02:00
// Amount Local Taxes
//TODO: Place into a function to control showing by country or study better option
2022-09-05 17:31:30 +02:00
if ( $mysoc -> localtax1_assuj == " 1 " ) { //Localtax1
print '<tr><td>' . $langs -> transcountry ( " AmountLT1 " , $mysoc -> country_code ) . '</td>' ;
2019-01-27 11:55:16 +01:00
print '<td>' . price ( $object -> total_localtax1 , 1 , $langs , 0 , - 1 , - 1 , $conf -> currency ) . '</td>' ;
2015-04-06 16:13:23 +02:00
print '</tr>' ;
}
2022-09-05 17:31:30 +02:00
if ( $mysoc -> localtax2_assuj == " 1 " ) { //Localtax2
print '<tr><td>' . $langs -> transcountry ( " AmountLT2 " , $mysoc -> country_code ) . '</td>' ;
2019-01-27 11:55:16 +01:00
print '<td>' . price ( $object -> total_localtax2 , 1 , $langs , 0 , - 1 , - 1 , $conf -> currency ) . '</td>' ;
2015-04-06 16:13:23 +02:00
print '</tr>' ;
}
2019-01-27 11:55:16 +01:00
print '<tr><td>' . $langs -> trans ( 'AmountTTC' ) . '</td><td>' . price ( $object -> total_ttc , 1 , $langs , 0 , - 1 , - 1 , $conf -> currency ) . '</td></tr>' ;
2015-04-06 16:13:23 +02:00
2013-04-09 17:18:07 +02:00
print " </table> " ;
print '<br>' ;
2020-10-31 14:32:18 +01:00
print '<div class="underbanner clearboth"></div>' ;
2019-11-13 19:35:39 +01:00
$cssclass = " titlefield " ;
2013-04-09 17:18:07 +02:00
include DOL_DOCUMENT_ROOT . '/core/tpl/notes.tpl.php' ;
2020-10-27 18:19:31 +01:00
print dol_get_fiche_end ();
2006-09-05 03:31:09 +02:00
}
2018-08-12 22:40:47 +02:00
// End of page
2011-08-27 16:24:16 +02:00
llxFooter ();
2012-03-18 00:59:24 +01:00
$db -> close ();