2008-10-25 19:27:15 +02:00
|
|
|
<?php
|
2012-03-16 11:12:59 +01:00
|
|
|
/* Copyright (C) 2005-2012 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-06-10 16:05:41 +02:00
|
|
|
* Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
|
2015-09-26 10:37:36 +02:00
|
|
|
* Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
|
2017-04-09 11:29:54 +02:00
|
|
|
* Copyright (C) 2017 Charlie Benke <charlie@patas-monkey.com>
|
2017-07-11 09:26:25 +02:00
|
|
|
* Copyright (C) 2017 ATM-CONSULTING <contact@atm-consulting.fr>
|
2005-12-03 18:18:35 +01: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
|
2013-01-16 15:36:08 +01:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2005-12-03 18:18:35 +01:00
|
|
|
* (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/>.
|
|
|
|
|
* or see https://www.gnu.org/
|
2005-12-03 18:18:35 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2011-10-24 12:59:44 +02:00
|
|
|
* \file htdocs/core/lib/invoice.lib.php
|
2011-10-01 21:55:40 +02:00
|
|
|
* \brief Functions used by invoice module
|
2008-12-11 21:12:44 +01:00
|
|
|
* \ingroup invoice
|
|
|
|
|
*/
|
2008-10-25 19:27:15 +02:00
|
|
|
|
2011-10-01 21:55:40 +02:00
|
|
|
/**
|
|
|
|
|
* Initialize the array of tabs for customer invoice
|
|
|
|
|
*
|
|
|
|
|
* @param Facture $object Invoice object
|
|
|
|
|
* @return array Array of head tabs
|
|
|
|
|
*/
|
2010-12-19 12:05:07 +01:00
|
|
|
function facture_prepare_head($object)
|
2008-10-25 19:27:15 +02:00
|
|
|
{
|
2016-01-23 17:19:34 +01:00
|
|
|
global $db, $langs, $conf;
|
2018-07-26 19:05:34 +02:00
|
|
|
|
2008-10-25 19:27:15 +02:00
|
|
|
$h = 0;
|
|
|
|
|
$head = array();
|
2009-03-12 02:44:02 +01:00
|
|
|
|
2017-03-20 20:58:43 +01:00
|
|
|
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/card.php?facid='.$object->id;
|
2016-08-31 06:27:35 +02:00
|
|
|
$head[$h][1] = $langs->trans('Card');
|
2008-10-25 19:27:15 +02:00
|
|
|
$head[$h][2] = 'compta';
|
|
|
|
|
$h++;
|
2012-12-01 15:45:05 +01:00
|
|
|
|
2012-07-02 19:30:37 +02:00
|
|
|
if (empty($conf->global->MAIN_DISABLE_CONTACTS_TAB))
|
2012-03-17 16:05:58 +01:00
|
|
|
{
|
2019-01-27 11:55:16 +01:00
|
|
|
$nbContact = count($object->liste_contact(-1, 'internal')) + count($object->liste_contact(-1, 'external'));
|
2016-03-10 11:16:12 +01:00
|
|
|
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/contact.php?facid='.$object->id;
|
2012-07-02 19:30:37 +02:00
|
|
|
$head[$h][1] = $langs->trans('ContactsAddresses');
|
2019-11-04 18:25:32 +01:00
|
|
|
if ($nbContact > 0) $head[$h][1].= '<span class="badge marginleftonlyshort">'.$nbContact.'</span>';
|
2012-07-02 19:30:37 +02:00
|
|
|
$head[$h][2] = 'contact';
|
2012-03-17 16:05:58 +01:00
|
|
|
$h++;
|
|
|
|
|
}
|
2008-10-25 19:27:15 +02:00
|
|
|
|
2010-06-14 22:16:56 +02:00
|
|
|
//if ($fac->mode_reglement_code == 'PRE')
|
2012-09-15 10:01:35 +02:00
|
|
|
if (! empty($conf->prelevement->enabled))
|
2008-10-25 19:27:15 +02:00
|
|
|
{
|
2016-03-13 01:20:54 +01:00
|
|
|
$nbStandingOrders=0;
|
|
|
|
|
$sql = "SELECT COUNT(pfd.rowid) as nb";
|
|
|
|
|
$sql .= " FROM ".MAIN_DB_PREFIX."prelevement_facture_demande as pfd";
|
|
|
|
|
$sql .= " WHERE pfd.fk_facture = ".$object->id;
|
|
|
|
|
$resql=$db->query($sql);
|
2018-07-26 19:05:34 +02:00
|
|
|
if ($resql)
|
2016-03-13 01:20:54 +01:00
|
|
|
{
|
|
|
|
|
$obj=$db->fetch_object($resql);
|
|
|
|
|
if ($obj) $nbStandingOrders = $obj->nb;
|
|
|
|
|
}
|
|
|
|
|
else dol_print_error($db);
|
2010-12-19 12:05:07 +01:00
|
|
|
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/prelevement.php?facid='.$object->id;
|
2008-10-25 19:27:15 +02:00
|
|
|
$head[$h][1] = $langs->trans('StandingOrders');
|
2019-11-04 18:25:32 +01:00
|
|
|
if ($nbStandingOrders > 0) $head[$h][1].= '<span class="badge marginleftonlyshort">'.$nbStandingOrders.'</span>';
|
2008-10-25 19:27:15 +02:00
|
|
|
$head[$h][2] = 'standingorders';
|
|
|
|
|
$h++;
|
|
|
|
|
}
|
|
|
|
|
|
2011-01-25 00:35:21 +01:00
|
|
|
// Show more tabs from modules
|
|
|
|
|
// Entries must be declared in modules descriptor with line
|
|
|
|
|
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
|
2012-12-01 15:45:05 +01:00
|
|
|
// $this->tabs = array('entity:-tabname); to remove a tab
|
2019-01-27 11:55:16 +01:00
|
|
|
complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice');
|
2012-12-01 15:45:05 +01:00
|
|
|
|
2012-07-02 19:30:37 +02:00
|
|
|
if (empty($conf->global->MAIN_DISABLE_NOTES_TAB))
|
2012-03-16 11:12:59 +01:00
|
|
|
{
|
2013-07-20 09:07:10 +02:00
|
|
|
$nbNote = 0;
|
|
|
|
|
if(!empty($object->note_private)) $nbNote++;
|
|
|
|
|
if(!empty($object->note_public)) $nbNote++;
|
2012-07-02 19:30:37 +02:00
|
|
|
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/note.php?facid='.$object->id;
|
|
|
|
|
$head[$h][1] = $langs->trans('Notes');
|
2019-11-04 18:25:32 +01:00
|
|
|
if ($nbNote > 0) $head[$h][1].= '<span class="badge marginleftonlyshort">'.$nbNote.'</span>';
|
2012-07-02 19:30:37 +02:00
|
|
|
$head[$h][2] = 'note';
|
2012-03-16 11:12:59 +01:00
|
|
|
$h++;
|
|
|
|
|
}
|
2008-10-25 19:27:15 +02:00
|
|
|
|
2013-07-20 09:07:10 +02:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
|
2016-01-23 17:19:34 +01:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/class/link.class.php';
|
2013-07-20 09:07:10 +02:00
|
|
|
$upload_dir = $conf->facture->dir_output . "/" . dol_sanitizeFileName($object->ref);
|
2019-01-27 11:55:16 +01:00
|
|
|
$nbFiles = count(dol_dir_list($upload_dir, 'files', 0, '', '(\.meta|_preview.*\.png)$'));
|
2016-01-23 17:19:34 +01:00
|
|
|
$nbLinks=Link::count($db, $object->element, $object->id);
|
2010-12-19 12:05:07 +01:00
|
|
|
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/document.php?facid='.$object->id;
|
2008-10-25 19:27:15 +02:00
|
|
|
$head[$h][1] = $langs->trans('Documents');
|
2019-11-04 18:25:32 +01:00
|
|
|
if (($nbFiles+$nbLinks) > 0) $head[$h][1].= '<span class="badge marginleftonlyshort">'.($nbFiles+$nbLinks).'</span>';
|
2008-10-25 19:27:15 +02:00
|
|
|
$head[$h][2] = 'documents';
|
|
|
|
|
$h++;
|
|
|
|
|
|
2010-12-19 12:05:07 +01:00
|
|
|
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/info.php?facid='.$object->id;
|
2008-10-25 19:27:15 +02:00
|
|
|
$head[$h][1] = $langs->trans('Info');
|
|
|
|
|
$head[$h][2] = 'info';
|
|
|
|
|
$h++;
|
|
|
|
|
|
2019-01-27 11:55:16 +01:00
|
|
|
complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice', 'remove');
|
2012-12-01 15:45:05 +01:00
|
|
|
|
2008-10-25 19:27:15 +02:00
|
|
|
return $head;
|
|
|
|
|
}
|
|
|
|
|
|
2013-03-06 03:36:43 +01:00
|
|
|
/**
|
|
|
|
|
* Return array head with list of tabs to view object informations.
|
|
|
|
|
*
|
|
|
|
|
* @return array head array with tabs
|
|
|
|
|
*/
|
2014-12-04 13:20:56 +01:00
|
|
|
function invoice_admin_prepare_head()
|
2013-03-06 03:36:43 +01:00
|
|
|
{
|
|
|
|
|
global $langs, $conf, $user;
|
|
|
|
|
|
|
|
|
|
$h = 0;
|
|
|
|
|
$head = array();
|
|
|
|
|
|
|
|
|
|
$head[$h][0] = DOL_URL_ROOT.'/admin/facture.php';
|
2013-03-24 07:11:44 +01:00
|
|
|
$head[$h][1] = $langs->trans("Miscellaneous");
|
2013-03-06 03:36:43 +01:00
|
|
|
$head[$h][2] = 'general';
|
|
|
|
|
$h++;
|
|
|
|
|
|
2015-09-26 10:37:36 +02:00
|
|
|
$head[$h][0] = DOL_URL_ROOT.'/admin/payment.php';
|
|
|
|
|
$head[$h][1] = $langs->trans("Payments");
|
|
|
|
|
$head[$h][2] = 'payment';
|
|
|
|
|
$h++;
|
2019-10-20 17:17:22 +02:00
|
|
|
|
2013-03-06 03:36:43 +01:00
|
|
|
// Show more tabs from modules
|
|
|
|
|
// Entries must be declared in modules descriptor with line
|
|
|
|
|
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
|
|
|
|
|
// $this->tabs = array('entity:-tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to remove a tab
|
2019-01-27 11:55:16 +01:00
|
|
|
complete_head_from_modules($conf, $langs, null, $head, $h, 'invoice_admin');
|
2013-03-06 03:36:43 +01:00
|
|
|
|
|
|
|
|
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facture_cust_extrafields.php';
|
|
|
|
|
$head[$h][1] = $langs->trans("ExtraFieldsCustomerInvoices");
|
|
|
|
|
$head[$h][2] = 'attributes';
|
|
|
|
|
$h++;
|
|
|
|
|
|
2013-06-10 16:05:41 +02:00
|
|
|
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facturedet_cust_extrafields.php';
|
|
|
|
|
$head[$h][1] = $langs->trans("ExtraFieldsLines");
|
|
|
|
|
$head[$h][2] = 'attributeslines';
|
|
|
|
|
$h++;
|
2018-07-26 19:05:34 +02:00
|
|
|
|
2017-07-11 09:26:25 +02:00
|
|
|
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facture_rec_cust_extrafields.php';
|
|
|
|
|
$head[$h][1] = $langs->trans("ExtraFieldsCustomerInvoicesRec");
|
|
|
|
|
$head[$h][2] = 'attributesrec';
|
|
|
|
|
$h++;
|
2018-07-26 19:05:34 +02:00
|
|
|
|
2017-07-11 09:26:25 +02:00
|
|
|
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/admin/facturedet_rec_cust_extrafields.php';
|
|
|
|
|
$head[$h][1] = $langs->trans("ExtraFieldsLinesRec");
|
|
|
|
|
$head[$h][2] = 'attributeslinesrec';
|
|
|
|
|
$h++;
|
2013-03-06 03:36:43 +01:00
|
|
|
|
2020-01-31 14:54:42 +01:00
|
|
|
$head[$h][0] = DOL_URL_ROOT.'/admin/facture_situation.php';
|
|
|
|
|
$head[$h][1] = $langs->trans("InvoiceSituation");
|
|
|
|
|
$head[$h][2] = 'situation';
|
|
|
|
|
$h++;
|
|
|
|
|
|
2019-01-27 11:55:16 +01:00
|
|
|
complete_head_from_modules($conf, $langs, null, $head, $h, 'invoice_admin', 'remove');
|
2013-03-06 03:36:43 +01:00
|
|
|
|
|
|
|
|
return $head;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
2018-08-31 22:01:13 +02:00
|
|
|
/**
|
|
|
|
|
* Return array head with list of tabs to view object informations.
|
|
|
|
|
*
|
|
|
|
|
* @param Facture $object Invoice object
|
|
|
|
|
* @return array head array with tabs
|
|
|
|
|
*/
|
2017-04-09 11:29:54 +02:00
|
|
|
function invoice_rec_prepare_head($object)
|
|
|
|
|
{
|
|
|
|
|
global $db, $langs, $conf;
|
2018-07-26 19:05:34 +02:00
|
|
|
|
2017-04-09 11:29:54 +02:00
|
|
|
$h = 0;
|
|
|
|
|
$head = array();
|
|
|
|
|
|
2019-11-03 18:58:26 +01:00
|
|
|
$head[$h][0] = DOL_URL_ROOT.'/compta/facture/card-rec.php?id='.$object->id;
|
2017-04-09 11:33:56 +02:00
|
|
|
$head[$h][1] = $langs->trans("CardBill");
|
|
|
|
|
$head[$h][2] = 'card';
|
2017-04-09 11:29:54 +02:00
|
|
|
$h++;
|
|
|
|
|
|
|
|
|
|
// Show more tabs from modules
|
|
|
|
|
// Entries must be declared in modules descriptor with line
|
|
|
|
|
// $this->tabs = array('entity:+tabname:Title:@mymodule:/mymodule/mypage.php?id=__ID__'); to add new tab
|
|
|
|
|
// $this->tabs = array('entity:-tabname); to remove a tab
|
2019-01-27 11:55:16 +01:00
|
|
|
complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice-rec');
|
2017-04-09 11:29:54 +02:00
|
|
|
|
2019-01-27 11:55:16 +01:00
|
|
|
complete_head_from_modules($conf, $langs, $object, $head, $h, 'invoice-rec', 'remove');
|
2017-04-09 11:29:54 +02:00
|
|
|
|
|
|
|
|
return $head;
|
|
|
|
|
}
|