Heray-Was-Here
Server : Apache
System : Linux mail.lomejor.cr 6.8.0-1059-azure #65~22.04.1-Ubuntu SMP Thu May 28 16:59:19 UTC 2026 x86_64
User : www-data ( 33)
PHP Version : 8.2.31
Disable Function : NONE
Directory :  /var/www/dev/htdocs/custom/autogestion/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/dev/htdocs/custom/autogestion/report_print.php
<?php
/* Copyright (C) 2012-2013	Christophe Battarel	<christophe.battarel@altairis.fr>
 * Copyright (C) 2014		Ferran Marcet		<fmarcet@2byte.es>
 * Copyright (C) 2015       Marcos García       <marcosgdf@gmail.com>
 * Copyright (C) 2016       Florian Henry       <florian.henry@open-concept.pro>
 *
 * 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 <https://www.gnu.org/licenses/>.
 */

/**
 * \file htdocs/margin/checkMargins.php
 * \ingroup margin
 * \brief Check margins
 */
if (false === (@include '../../main.inc.php')) {  // From htdocs directory
	require '../../../main.inc.php'; // From "custom" directory
}
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/margin/lib/margins.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/product.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';

global $langs, $conf;
// Load translation files required by the page
$langs->loadLangs(array('companies', 'bills', 'products', 'margins'));

$mesg = '';

if(GETPOST('tipo')=='excel'){
	header("Content-type: application/ms-excel");
	header("Content-disposition: attachment; filename=det_ag".date('dmYHms').".xls");
}

$id		= GETPOST('id', 'int'); // For this page, id can also be 'all'
$costcenter = GETPOST('costcenter', 'alpha');

$startdate = $enddate = '';

$startdate = dol_mktime(0, 0, 0, GETPOST('startdatemonth', 'int'), GETPOST('startdateday', 'int'), GETPOST('startdateyear', 'int'));
$enddate = dol_mktime(23, 59, 59, GETPOST('enddatemonth', 'int'), GETPOST('enddateday', 'int'), GETPOST('enddateyear', 'int'));


// Security check
if ( !$user->rights->autogestion->admin ){
	$result = restrictedArea($user, 'margins');
}

/*
 * Actions
 */

/*
 * View
 */
$object = new Societe($db);
if($id){
	$object->fetch($id);
}

$userstatic = new User($db);
$commandestatic = new Commande($db);
$invoicestatic = new Facture($db);
$contactstatic = new Contact($db);
$productstatic = new Product($db);


$invoice_status_except_list = array(Facture::STATUS_DRAFT, Facture::STATUS_ABANDONED);
$sql = "SELECT";
$sql .= " c.rowid, f.rowid fk_facture, c.date_commande, c.date_valid, c.fk_user_author, ec.fk_socpeople, sp.poste, c.total_ttc tot_pedido, f.total_ht, f.total_tva, f.total_ttc, au.costcenter, p.label, fd.fk_product, fd.qty, fd.total_ttc linea_ttc";
$sql .= " FROM ".MAIN_DB_PREFIX."commande as c ";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element cf on ( cf.fk_source = c.rowid AND cf.targettype = 'facture' AND cf.sourcetype = 'commande') ";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_contact ec on ( ec.fk_c_type_contact = 102 AND ec.element_id = c.rowid  ) ";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."facture f ON (cf.fk_target = f.rowid) ";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."facturedet fd ON (fd.fk_facture = f.rowid) ";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."product p ON (p.rowid = fd.fk_product) ";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u ON (c.fk_user_author = u.rowid) ";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."socpeople as sp ON (sp.rowid = ec.fk_socpeople) ";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."autogestion_user as au ON (au.fk_contact = ec.fk_socpeople) ";
$sql .= " WHERE c.entity IN (".getEntity('invoice').") ";
$sql .= " AND c.fk_soc = ".$id." ";

if (!empty($startdate)) {
	$sql .= " AND c.date_commande >= '".$db->idate($startdate)."'";
}
if (!empty($enddate)) {
	$sql .= " AND c.date_commande <= '".$db->idate($enddate)."'";
}
if (!empty($costcenter)) {
	$sql .= " AND md5(au.costcenter) = '". $costcenter ."'";
}
if ($search_ref) {
	$sql .= natural_search('c.ref', $search_ref);
}

$sql .= $db->order($sortfield, $sortorder);

$result = $db->query($sql);

if ($result) {
	$num = $db->num_rows($result);

	print '<br>';

	print '<div class="div-table-responsive">';
	print '<table class="noborder centpercent liste">';
	print '<tr class="liste_titre">';
	print_liste_field_titre("Fecha Pedido", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
	print_liste_field_titre("Pedido", $_SERVER["PHP_SELF"], "c.ref", "", $param, '', $sortfield, $sortorder);
	print_liste_field_titre("Fecha Factura", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
	print_liste_field_titre("Factura", $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder);
	print_liste_field_titre("Creado por", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
	print_liste_field_titre("Pedido por", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
	print_liste_field_titre("Ubicacion", $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
	print_liste_field_titre("Monto Pedido", $_SERVER["PHP_SELF"], "s.address", "", $param, '', $sortfield, $sortorder);
	print_liste_field_titre("Monto Factura", $_SERVER["PHP_SELF"], "s.address", "", $param, '', $sortfield, $sortorder);
	print_liste_field_titre("IVA", $_SERVER["PHP_SELF"], "s.town", "", $param, '', $sortfield, $sortorder);
	print_liste_field_titre("Total", $_SERVER["PHP_SELF"], "s.fk_departement", "", $param, '', $sortfield, $sortorder );
	print_liste_field_titre("CC", $_SERVER["PHP_SELF"], "s.phone", "", $param, '', $sortfield, $sortorder );
	print_liste_field_titre("Porducto", $_SERVER["PHP_SELF"], "s.phone", "", $param, '', $sortfield, $sortorder );
	print_liste_field_titre("Descripcion", $_SERVER["PHP_SELF"], "s.phone", "", $param, '', $sortfield, $sortorder );
	print_liste_field_titre("Cantidad", $_SERVER["PHP_SELF"], "s.phone", "", $param, '', $sortfield, $sortorder );
	print_liste_field_titre("Precio +IVA", $_SERVER["PHP_SELF"], "s.phone", "", $param, '', $sortfield, $sortorder );
	print "</tr>\n";

	$i = 0;
	while ($i < $num) {
		$objp = $db->fetch_object($result);

		print '<tr class="oddeven">';
		print '<td class="left">';
		print $objp->date_commande; 
		print '</td>';
		print '<td class="left">';
		$commandestatic->fetch($objp->rowid);
		print $commandestatic->getNomUrl(1, '', '', 0, 1, 1);
		print '</td>';
		print '<td class="left">';
		print $objp->date_valid; 
		print '</td>';
		print '<td class="left">';
		$invoicestatic->fetch($objp->fk_facture);
		print $invoicestatic->getNomUrl(1, '', '', 0, 1, 1);
		print '</td>';
		print '<td class="left">';
		$userstatic->fetch( $objp->fk_user_author);
		print $userstatic->getNomUrl(1, '');
		print '</td>';
		$contactstatic = new Contact($db);
		print '<td class="left">';
		$contactstatic->fetch( $objp->fk_socpeople);
		print $contactstatic->getNomUrl(1, '');
		print '</td>';
		print '<td class="left">';
		print $objp->poste; 
		print '</td>';
		print '<td class="right">';
		print price($objp->tot_pedido, 0, $langs, 0, 0, -1, $conf->currency); 
		print '</td>';
		print '<td class="right">';
		print price($objp->total_ht, 0, $langs, 0, 0, -1, $conf->currency);
		print '</td>';
		print '<td class="right">';
		print price($objp->total_tva, 0, $langs, 0, 0, -1, $conf->currency);
		print '</td>';
		print '<td class="right">';
		print price($objp->total_ttc, 0, $langs, 0, 0, -1, $conf->currency);
		print '</td>';
		print '<td class="left">';
		print $objp->costcenter;
		print '</td>';
		$productstatic = new Product($db);
		print '<td class="left">';
		$productstatic->fetch( $objp->fk_product);
		print $productstatic->getNomUrl(1, '');
		print '</td>';
		print '<td class="right">';
		print $objp->label;
		print '</td>';
		print '<td class="right">';
		print $objp->qty;
		print '</td>';
		print '<td class="right">';
		print price($objp->linea_ttc, 0, $langs, 0, 0, -1, $conf->currency);
		print '</td>';

		print "</tr>\n";

		$i++;
	}

	print "</table>";

	print "</div>";
} else {
	dol_print_error($db);
}
$db->free($result);

$db->close();

Hry