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.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('orders', 'sendings', 'companies', 'bills', 'propal', 'deliveries', 'products', 'other'));

$action     = GETPOST('action', 'alpha');
$massaction = GETPOST('massaction', 'alpha');
$toselect   = GETPOST('toselect', 'array');
$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'report'; // To manage different context of search
$backtopage = GETPOST('backtopage', 'alpha');
$costcenter = GETPOST('costcenter', 'alpha');
$optioncss  = GETPOST('optioncss', 'alpha');
$search_categ  = GETPOST('search_categ', 'int');
$id		= GETPOST('id', 'int'); // For this page, id can also be 'all'


// Load variable for pagination
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
$sortfield = GETPOST('sortfield', 'aZ09comma');
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
if (empty($page) || $page == -1) {
	$page = 0;
}     // If $page is not defined, or '' or -1
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
if (!$sortorder) {
	$sortorder = "DESC";
}
if (!$sortfield) {
	$sortfield = 'c.ref';
}

$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'));

$search_ref = GETPOST('search_ref', 'alpha');

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

// Both test are required to be compatible with all browsers
if (GETPOST("button_search_x") || GETPOST("button_search")) {
	$action = 'search';
} elseif (GETPOST("button_update") ) {
	$action = 'update';
}

/*
 * Actions
 */

if (GETPOST('cancel', 'alpha')) {
	$action = 'list'; $massaction = '';
}
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
	$massaction = '';
}

$error =0;
if ( $action == 'update' ) {
	$db->begin();
	foreach (GETPOST('socid') as $fksoc => $fksocid) {
		$cursorsocid = $fksocid;
		
		$sql = "DELETE FROM ".MAIN_DB_PREFIX."autogestion_supplier WHERE fk_supplier = ".$id." AND fk_soc = ".$cursorsocid."" ;
		$result = $db->query($sql);
		if ($result) {
			$mode_reglement_id = (!empty(GETPOST('mode_reglement_id')[$cursorsocid]) ? GETPOST('mode_reglement_id')[$cursorsocid]: 'null');
			$cond_reglement_id = (!empty(GETPOST('cond_reglement_id')[$cursorsocid]) ? GETPOST('cond_reglement_id')[$cursorsocid]: 'null');
			$shipping_method_id = (!empty(GETPOST('shipping_method_id')[$cursorsocid]) ? GETPOST('shipping_method_id')[$cursorsocid]: 'null');

			$sql = "INSERT INTO ".MAIN_DB_PREFIX."autogestion_supplier " ;
			$sql .="( `fk_supplier`, `fk_soc`, `date_creation`, `tms`, `fk_user_creat`, `mode_reglement`, `cond_reglement`, `fk_shipping_method`) VALUES";
			$sql .="(".$id.",".$cursorsocid.",now(),now(),".$user->id.",".$mode_reglement_id .",".$cond_reglement_id.",".$shipping_method_id.")";
			
			$result = $db->query($sql);
			if (!$result) {
				$error ++;
				$errors[] = $db->lasterror;
			}
	
		}else{
			$error ++;
			$errors[] = $db->lasterror();
		}

	}

	if (!$error){
		$db->commit();
	}else{
		setEventMessages($error, $errors, 'errors');
		$db->rollback();
	}
}

$hookmanager->initHooks(array('AutoGestionSupplierlist'));


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


$form = new Form($db);
$htmlother = new FormOther($db);


$title = $langs->trans("ThirdParty").' - '.$langs->trans("Report");
if (!empty($conf->global->MAIN_HTML_TITLE) && preg_match('/thirdpartynameonly/', $conf->global->MAIN_HTML_TITLE) && $object->name) {
	$title = $object->name.' - '.$langs->trans("Report");
}
$help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
llxHeader('', $title, $help_url);

//$res = $object->fetch_optionals();
//if ($res < 0) { dol_print_error($db); exit; }

$head = societe_prepare_head($object);



	print dol_get_fiche_head($head, 'Report', $langs->trans("ThirdParty"), -1, 'company');

	$linkback = '<a href="'.DOL_URL_ROOT.'/societe/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';

	dol_banner_tab($object, 'socid', $linkback, ($user->socid ? 0 : 1), 'rowid', 'nom');

	$cssclass = 'titlefield';

	$param = '&id='.$object->id;
	if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
		$param .= '&contextpage='.$contextpage;
	}
	if ($limit > 0 && $limit != $conf->liste_limit) {
		$param .= '&limit='.$limit;
	}
	if ($search_ref != '') {
		$param .= '&search_ref='.urlencode($search_ref);
	}
	if (!empty($startdate)) {
		$param .= '&startdatemonth='.GETPOST('startdatemonth', 'int').'&startdateday='.GETPOST('startdateday', 'int').'&startdateyear='.GETPOST('startdateyear', 'int');
	}
	if (!empty($enddate)) {
		$param .= '&enddatemonth='.GETPOST('enddatemonth', 'int').'&enddateday='.GETPOST('enddateday', 'int').'&enddateyear='.GETPOST('enddateyear', 'int');
	}
	if ($optioncss != '') {
		$param .= '&optioncss='.$optioncss;
	}



	if ($object->client == Societe::CUSTOMER ) {
		$userstatic = new User($db);
		$commandestatic = new Commande($db);
		$invoicestatic = new Facture($db);
		$contactstatic = new Contact($db);

		print '<form method="post" name="sel" action="'.$_SERVER['PHP_SELF'].'">';
		print '<input type="hidden" name="token" value="'.newToken().'">';
		print '<input type="hidden" name="id" value="'.$object->id.'">';

		print '<table class="border centpercent">';

		// Agrupar centros de costo
			print '<tr><td class="titlefield">'.$langs->trans("Centros de Costo").'</td><td>';
			print '<select class="flat" name="costcenter">';
			print '<option value="0" ></option>';
			$minsql = "SELECT costcenter from ". MAIN_DB_PREFIX . "autogestion_user WHERE fk_soc = ".$object->id." GROUP BY costcenter;";

			$rs = $db->query($minsql);

			while ($valrs = $db->fetch_object($rs)){
				if ($costcenter == md5($valrs->costcenter))
					print '<option value="'.md5($valrs->costcenter).'" selected>'.$valrs->costcenter.'</option>';
				else
					print '<option value="'.md5($valrs->costcenter).'" >'.$valrs->costcenter.'</option>';
			}
			print '</select>';
			print '</td></tr>';


		print '<tr><td class="titlefield">'.$langs->trans('DateStart').' ('.$langs->trans("DateValidation").')</td>';
		print '<td>';
		print $form->selectDate($startdate, 'startdate', '', '', 1, "sel", 1, 1);
		print '</td>';
		print '<td>'.$langs->trans('DateEnd').' ('.$langs->trans("DateValidation").')</td>';
		print '<td>';
		print $form->selectDate($enddate, 'enddate', '', '', 1, "sel", 1, 1);
		print '</td>';
		print '<td style="text-align: center;">';
		print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans('Refresh')).'" name="button_search" />';
		print '</td>';
		print '</tr>';
		print '<tr><td colspan=5 style="text-align: left"><a href="report_print.php?tipo=excel&id='.$id.'&&startdate='.$startdate.'&enddate='.$enddate.'" target="popup">Descargar detalle Excel</a></td></tr>';
		print "</table>";

		print dol_get_fiche_end();


		$arrayfields = array();
		$massactionbutton = '';

		$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 ";
		$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 .= " 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);
		}
		// if ($search_categ > 0) {
		// 	$categ = new Categorie($db);
		// 	$categ->fetch($search_categ);
		// 	$listofprodids = $categ->getObjectsInCateg('product', 1);
		// 	$sql .= ' AND d.fk_product IN ('.$db->sanitize((is_array($listofprodids) && count($listofprodids)) ? join(',', $listofprodids) : '0').')';
		// }
		// $sql .= " AND d.buy_price_ht IS NOT NULL";
		$sql .= $db->order($sortfield, $sortorder);

		$nbtotalofrecords = '';
		if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
			dol_syslog(__FILE__, LOG_DEBUG);
			$result = $db->query($sql);
			$nbtotalofrecords = $db->num_rows($result);
			if (($page * $limit) > $nbtotalofrecords) {	// if total resultset is smaller then paging size (filtering), goto and load page 0
				$page = 0;
				$offset = 0;
			}
		}

		$sql .= $db->plimit($limit + 1, $offset);

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

			print '<br>';
			print_barre_liste($langs->trans("List"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '');

			$moreforfilter = '';

			$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
			//$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage);	// This also change content of $arrayfields
			//if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
			$selectedfields = '';

			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 "</tr>\n";

			$i = 0;
			while ($i < min($num, $limit)) {
				$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>';

				print "</tr>\n";

				$i++;
			}

			print "</table>";

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


		print '<div class="center">'."\n";
		print '<input type="submit" class="button" name="button_update" id="button_update" value="'.$langs->trans("Update").'">';
		print '</div>';

		print '</form>';
	}elseif ($object->fournisseur == Societe::SUPPLIER){
		$Socientestatic = new Societe($db);

		print '<form method="post" name="sel" action="'.$_SERVER['PHP_SELF'].'">';
		print '<input type="hidden" name="token" value="'.newToken().'">';
		print '<input type="hidden" name="action" value="update">';
		print '<input type="hidden" name="id" value="'.$object->id.'">';

		print '<table class="border centpercent" >';

		$sql = "SELECT s.rowid, sp.fk_supplier, sp.mode_reglement, sp.cond_reglement, sp.fk_shipping_method ";
		$sql .= " FROM ".MAIN_DB_PREFIX."societe s LEFT JOIN ".MAIN_DB_PREFIX."autogestion_supplier sp on (s.rowid = sp.fk_soc and sp.fk_supplier = ". (int) $object->id ."  )  ";
		$sql .= " WHERE s.client =1 and s.fournisseur = 0 and s.rowid != ". (int) $object->id;

		$nbtotalofrecords = '';
		if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
			dol_syslog(__FILE__, LOG_DEBUG);
			$result = $db->query($sql);
			$nbtotalofrecords = $db->num_rows($result);
			if (($page * $limit) > $nbtotalofrecords) {	// if total resultset is smaller then paging size (filtering), goto and load page 0
				$page = 0;
				$offset = 0;
			}
		}

		$sql .= $db->plimit($limit + 1, $offset);
		$result = $db->query($sql);
		if ($result) {
			$num = $db->num_rows($result);

			print '<br>';
			print_barre_liste($langs->trans("List"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '');

			$moreforfilter = '';

			$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
			//$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage);	// This also change content of $arrayfields
			//if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
			$selectedfields = '';

			print '<div class="div-table-responsive">';
			print '<table class="noborder centpercent liste">';
			print '<tr class="liste_titre">';
			print_liste_field_titre($langs->trans('Customer'), $_SERVER["PHP_SELF"], "s.rowid", "", $param, '', $sortfield, $sortorder);
			print_liste_field_titre($langs->trans('PaymentRule'), $_SERVER["PHP_SELF"], "sp.mode_reglement", "", $param, '', $sortfield, $sortorder);
			print_liste_field_titre($langs->trans('PaymentConditionsShort'), $_SERVER["PHP_SELF"], "sp.cond_reglement", "", $param, '', $sortfield, $sortorder);
			print_liste_field_titre($langs->trans('SendingMethod'), $_SERVER["PHP_SELF"], "sp.fk_shipping_method", "", $param, '', $sortfield, $sortorder);

			print "</tr>\n";

			$i = 0;
			while ($i < min($num, $limit)) {
				$objp = $db->fetch_object($result);
				print '<tr class="oddeven">';
				print '<input type="hidden" name="socid[]" value="'.$objp->rowid .'">';
				print '<td class="left">';
				$Socientestatic->fetch( $objp->rowid);
				print $Socientestatic->getNomUrl(1,"",75);
				print '</td>';
				print '<td class="left">';
				print $form->select_types_paiements($objp->mode_reglement, 'mode_reglement_id['. $objp->rowid.']', 'CRDT', 0, 1, 0, 0, 1, 'maxwidth200 widthcentpercentminusx', 1);
				print '</td>';
				print '<td class="left">';
				print $form->getSelectConditionsPaiements($objp->cond_reglement, 'cond_reglement_id['. $objp->rowid.']', 1, 1, 0, 'maxwidth200 widthcentpercentminusx');
				print '</td>';
				print '<td class="right">';
				print $form->selectShippingMethod($objp->fk_shipping_method, 'shipping_method_id['. $objp->rowid.']', '', 1, '', 0, 'maxwidth200 widthcentpercentminusx');
				print '</td>';

				print "</tr>\n";

				$i++;
			}

			print "</table>";
			print '<input type="submit" class="button" name="button_update" id="button_update" value="'.$langs->trans("Update").'">';
			print "</div>";
		} else {
			dol_print_error($db);
		}

		print "</table>";

		print "</div>";
		print '<div class="center">'."\n";
		print '</div>';

		print '</form>';
	}
$db->free($result);

// End of page
llxFooter();
$db->close();

Hry