Ya lo resolví, saludos !!
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes Menú
// Incluimos las funciones del sistema
require_once '../administrator/ss-functions.php';
// Revisamos si existe la sesion o si es valida
isuserajax();
// Si el posttext es vacio
if (empty($_POST['descripcion'])){exit();}
// Si es un espacio
if (ctype_space($_POST['descripcion'])){exit();}
// Primero el Año
$theyear = date('Y');
// Ahora el Mes
$themonth = date ('m');
// creamos directorio para el usuario el año
if(!is_dir("../attachments/".$_SESSION['ssid']))
mkdir("../attachments/".$_SESSION['ssid'], 0777);
// creamos directorio para el usuario
if(!is_dir("../attachments/".$_SESSION['ssid']."/".$theyear))
mkdir("../attachments/".$_SESSION['ssid']."/".$theyear, 0777);
// creamos directorio para el usuario el mes
if(!is_dir("../attachments/".$_SESSION['ssid']."/".$theyear."/".$themonth))
mkdir("../attachments/".$_SESSION['ssid']."/".$theyear."/".$themonth, 0777);
//obtenemos el archivo a subir
$file = $_FILES['archivo']['name'];
// Obtenemos la extension
$fileext = new SplFileInfo($file);
$getextension = $fileext->getExtension();
// convertimos extension a minusculas
$extension = strtolower($getextension);
// Aqui sacamos la lista de extensiones
$extensionlst = gettheextattachment();
// Aqui hacemos un explode para cada uno
$extexplode = explode("|", $extensionlst);
// Contamos el total de extensiones
$exttotal = count($extexplode);
for ($i=0; $i < $exttotal; $i++) {
if($extension === $extexplode[$i]){
attachmentfiles($file,$_POST['descripcion']);
exit();
}
}
<!-- ### FORM POST ### -->
<div class="box box-info">
<!-- form start -->
<form id="poster" class="form-horizontal">
<div class="box-body">
<textarea id="thetextpost" name="posttext" class="form-control" rows="3"></textarea>
</div>
<!-- /.box-body -->
</form>
<div class="box-footer">
<button class="btn btn-danger btn-sm pull-left" data-toggle="modal" data-target="#ModalDocumment"> <i class="fa fa-file-archive-o" aria-hidden="true"></i> Archivo</button>
<button class="posterbtn btn btn-info btn-sm pull-right"><i class="fa fa-pencil"></i> Publicar</button>
</div>
<!-- /.box-footer -->
</div>
<!-- ### FORM POST ### -->
<!-- ### COMMENT ### -->
<div id="timeliner">
<?php takemylast6post(); ?>
</div>
<!-- ### COMMENT ### -->
<div id="loaderlinetime" class="col-sm-12 text-center">
<div class="loader-inner ball-pulse-sync"><div></div><div></div><div></div></div>
</div>
</div>
<div id="sidebar" class="col-sm-3">
<?php include 'includes/adsense.html'; ?>
</div>
</div>
<!-- container -->
<!-- Modal -->
<div class="modal fade" id="ModalDocumment" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">×</span></button>
<h4 class="modal-title" id="myModalLabel"><i class="fa fa-upload" aria-hidden="true"></i> Subir Archivo</h4>
</div>
<div class="modal-body">
<div id="thefilattch" class="col-sm-12">
<form id="attachmentfrm">
<label>Descripción:</label>
<textarea class="form-control" name="descripcion" rows="3"></textarea>
<label>Archivo:</label>
<input type="file" name="archivo" class="form-control">
</form>
<p></p>
<p>Solo se aceptan archivos con la extension: <?php validextlist(); ?></p>
</div>
<!-- progress -->
<div id="loadeingarchive" class="progress active">
<div class="progress-bar progress-bar-primary progress-bar-striped" role="progressbar" aria-valuenow="100" aria-valuemin="0" aria-valuemax="100" style="width: 100%">
</div>
</div>
<!-- progress -->
<button type="button" class="uploadarchive btn btn-primary pull-right">Subir Archivo</button>
</div>
</div>
</div>
</div>
// Sacamos las extensiones permitidas para los archivos que se suben
function gettheextattachment(){
// conexion de base de datos
$conexion = Conexion::singleton_conexion();
$SQL = 'SELECT archiveextensions FROM '.SSPREFIX.'socialconfig WHERE id = 1';
$stn = $conexion -> prepare($SQL);
$stn -> execute();
$rstl = $stn -> fetchAll();
if (empty($rstl)){
}else{
foreach ($rstl as $key){
$fileext = $key['archiveextensions'];
return $fileext;
}
}
}
function validextlist(){
// conexion de base de datos
$conexion = Conexion::singleton_conexion();
$SQL = 'SELECT archiveextensions FROM '.SSPREFIX.'socialconfig WHERE id = 1';
$stn = $conexion -> prepare($SQL);
$stn -> execute();
$rstl = $stn -> fetchAll();
if (empty($rstl)){
}else{
foreach ($rstl as $key){
echo '<b>'.str_replace('|', ' / ', $key['archiveextensions']).'</b>';
}
}
}
function formatSizeUnits($bytes){
if ($bytes >= 1073741824)
{
$bytes = number_format($bytes / 1073741824, 2) . ' GB';
}
elseif ($bytes >= 1048576)
{
$bytes = number_format($bytes / 1048576, 2) . ' MB';
}
elseif ($bytes >= 1024)
{
$bytes = number_format($bytes / 1024, 2) . ' kB';
}
elseif ($bytes > 1)
{
$bytes = $bytes . ' bytes';
}
elseif ($bytes == 1)
{
$bytes = $bytes . ' byte';
}
else
{
$bytes = '0 bytes';
}
return $bytes;
}
// Para subir un archivo
function attachmentfiles($file,$description){
// conexion de base de datos
$conexion = Conexion::singleton_conexion();
// Primero el Año
$theyear = date('Y');
// Ahora el Mes
$themonth = date ('m');
// Ahora usamos la sesion del usuario para su respectiva carpeta
$theuser = $_SESSION['ssid'];
// Creamos un alfanumerico aleatorio.
$characters = 'abcdefghijklmnopqrstuvwxyz1234567890ABCDEFGHIJKLMNOPQRSTUVWXYZ';
$string = '';
for ($i = 0; $i < 60; $i++) {
$string .= $characters[rand(0, strlen($characters) - 1)];
}
// Tomamos la fecha y hora con segundos
$fechaseconds = date('Y-m-d h:i:s');
$fechanormal = date('Y-m-d');
// Nuevo nombre del Archivo
$thenewname = sha1($fechaseconds.$theuser.$string);
// Obtenemos la extension
$fileext = new SplFileInfo($file);
$getextension = $fileext->getExtension();
// convertimos extension a minusculas
$extension = strtolower($getextension);
//comprobamos si el archivo ha subido y lo movemos a una su respectiva ruta
if ($file && move_uploaded_file($_FILES['archivo']['tmp_name'],"../attachments/".$theuser."/".$theyear."/".$themonth."/".$thenewname.".".$extension)){
}
// Creamos ruta del temporal
$temporal = "../attachments/".$theuser."/".$theyear."/".$themonth."/".$thenewname.".".$extension;
// Creamos el permalink de la publicacion
$permalink = sha1($string.$fechaseconds);
// Limitamos las publicaciones a tan solo 1000 caracteres
$postparse = substr($description, 0,1000);
// Filtramos para evitar XSS Injection
$filtro = new InputFilter();
$finalpost = $filtro->process($postparse);
// Tamaño del archivo
$filesize = $_FILES['archivo']['size'];
// Nombre del Archivo
$filename = $_FILES['archivo']['name'];
// Revisamos si el resultado es vacio para no tener que postearlo
if (empty($finalpost)){
exit();
}
if (is_null($finalpost)){
exit();
}
// Hacemos el registro del Archivo
$FileAttch = 'INSERT INTO '.SSPREFIX.'attachment (ruta, nombre, usuario, fecha, ext, peso, permalink) VALUES (:ruta, :nombre, :usuario, :fecha, :ext, :peso, :permalink)';
$stnfile = $conexion -> prepare($FileAttch);
$stnfile -> bindParam(':ruta', $temporal ,PDO::PARAM_STR);
$stnfile -> bindParam(':usuario', $_SESSION['ssid'] ,PDO::PARAM_STR);
$stnfile -> bindParam(':nombre', $filename ,PDO::PARAM_INT);
$stnfile -> bindParam(':fecha', $fechaseconds ,PDO::PARAM_STR);
$stnfile -> bindParam(':ext', $extension ,PDO::PARAM_STR);
$stnfile -> bindParam(':peso', $filesize ,PDO::PARAM_STR);
$stnfile -> bindParam(':permalink', $thenewname ,PDO::PARAM_STR);
$stnfile -> execute();
$lastidfile = $conexion -> lastInsertId();
// Post con archivo
$thepostpostarchive = $lastidfile.'|'.$finalpost;
// Como es un post de archivo es 4
$tipo = 4;
$SQL = 'INSERT INTO '.SSPREFIX.'posts (post, usuario, permalink, fecha, tipo) VALUES (:post, :usuario, :permalink, :fecha, :tipo)';
$stn = $conexion -> prepare($SQL);
$stn -> bindParam(':post', $thepostpostarchive ,PDO::PARAM_STR);
$stn -> bindParam(':usuario', $_SESSION['ssid'] ,PDO::PARAM_INT);
$stn -> bindParam(':permalink', $permalink ,PDO::PARAM_STR);
$stn -> bindParam(':fecha', $fechaseconds ,PDO::PARAM_STR);
$stn -> bindParam(':tipo', $tipo ,PDO::PARAM_INT);
$stn -> execute();
$lastid = $conexion -> lastInsertId();
// imagen de perfil
$profileimg = userprofile($_SESSION['ssid']);
// Fecha
$fechastronger = fechastring($fechanormal,$permalink);
echo'
<div id="post-public'.$lastid.'" class="box box-widget">
<div class="box-header with-border">
<div class="user-block">
<img class="img-circle" src="'.$profileimg.'" alt="'.gettheusernamepost().'">
<span class="username"><a href="profile.php?leanserwebmaster">'.gettheusernamepost().'</a></span>
'.$fechastronger.'
</div>
<!-- /.user-block -->
<div class="box-tools">
<button data-post="'.$lastid.'" class="eliminarthispost btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
</div>
<!-- /.box-tools -->
</div>
<!-- /.box-header -->
<div class="box-body">
<!-- post text -->';
$postexplode = explode('|', $thepostpostarchive);
getattachblock($postexplode[0],$postexplode[1]);
echo'<!-- Social sharing buttons -->
<button id="liker'.$lastid.'" type="button" data-target="'.$lastid.'" onclick="thelikeloadtimeclick('.$lastid.');" class="btn btn-default btn-xs"><i class="fa fa-thumbs-o-up"></i> Me gusta</button>
<span id="likecomment'.$lastid.'" class="pull-right text-muted">
</span>
</div>
<!-- /.box-footer -->
<div class="box-footer">
<form class="commentfrm" data-form="'.$lastid.'" id="commentfrm'.$lastid.'">
<img id="mypiccomment" class="img-responsive img-circle img-sm" src="'.$profileimg.'">
<!-- .img-push is used to add margin to elements next to floating images -->
<div class="img-push">
<input type="text" class="form-control input-sm" name="comentario" placeholder="Comentar...">
</div>
</form>
</div>
<!-- /.box-footer -->
<!-- /.box-body -->
<div id="box-commets-body-'.$lastid.'" class="box-footer box-comments">
</div>
</div>
';
$conexion = '';
}
function downloadarchive($permalink){
// conexion de base de datos
$conexion = Conexion::singleton_conexion();
$SQL = 'SELECT * FROM '.SSPREFIX.'attachment WHERE permalink = :permalink LIMIT 1';
$stn = $conexion -> prepare($SQL);
$stn -> bindParam(':permalink', $permalink ,PDO::PARAM_STR);
$stn -> execute();
$rstl = $stn -> fetchAll();
if (empty($rstl)){
header('Location: 404.php');
}else{
foreach ($rstl as $key){
$ruta = str_replace('../', '', $key['ruta']);
$nombre = $key['nombre'];
}
}
header("Content-type: application/octet-stream");
header("Content-Type: application/force-download");
header("Content-Disposition: attachment; filename=\"$nombre\"\n"); readfile($ruta);
}
// Tomamos los ultimos 6 post
function takepostperpermalink($permalink){
// conexion de base de datos
$conexion = Conexion::singleton_conexion();
$SQL = 'SELECT '.SSPREFIX.'usuarios.id AS userid, '.SSPREFIX.'posts.tipo AS posttipo, '.SSPREFIX.'posts.id AS postingid, '.SSPREFIX.'posts.post, '.SSPREFIX.'posts.permalink, '.SSPREFIX.'posts.fecha, '.SSPREFIX.'usuarios.nombre, '.SSPREFIX.'usuarios.apellido, '.SSPREFIX.'usuarios.permalink AS userperma FROM '.SSPREFIX.'posts INNER JOIN '.SSPREFIX.'usuarios ON '.SSPREFIX.'usuarios.id = '.SSPREFIX.'posts.usuario WHERE '.SSPREFIX.'posts.permalink = :permalink ORDER BY '.SSPREFIX.'posts.fecha DESC LIMIT 1';
$stn = $conexion -> prepare($SQL);
$stn -> bindParam(':permalink' , $permalink, PDO::PARAM_INT);
$stn -> execute();
$rstl = $stn -> fetchAll();
if (empty($rstl)){
# code...
}else{
foreach ($rstl as $key){
// imagen de perfil
$profileimg = userprofile($key['userid']);
// Fecha
$fecha = fechastring($key['fecha'],$key['permalink']);
// Imagen de perfil en el post
$perfilactual = userprofile($_SESSION['ssid']);
echo'
<div id="post-public'.$key['postingid'].'" class="box box-widget">
<div class="box-header with-border">
<div class="user-block">
<img class="img-circle" src="'.$profileimg.'" alt="'.$key['nombre'].' '.$key['apellido'].'">
<span class="username"><a href="profile.php?'.$key['userperma'].'">'.$key['nombre'].' '.$key['apellido'].'</a></span>
'.$fecha.'
</div>
<!-- /.user-block -->
</div>
<!-- /.box-header -->
<div class="box-body">
<!-- post text -->';
if ($key['posttipo'] == 1){
profileimageposttake($key['post']);
}elseif ($key['posttipo'] == 3) {
portadaimageposttake($key['post']);
}elseif ($key['posttipo'] == 4) {
$postexplode = explode('|', $key['post']);
getattachblock($postexplode[0],$postexplode[1]);
}else{
echo'<p>'.emoticons($key['post']).'</p>';
}
echo'<!-- Social sharing buttons -->
';
checklike($key['postingid']);
echo'
<span id="likecomment'.$key['postingid'].'" class="pull-right text-muted">
';
checklikeandcomments($key['postingid']);
echo'
</span>
</div>
<!-- /.box-footer -->
<div class="box-footer">
<form class="commentfrm" data-form="'.$key['postingid'].'" id="commentfrm'.$key['postingid'].'">
<img id="mypiccomment" class="img-responsive img-circle img-sm" src="'.$perfilactual.'">
<!-- .img-push is used to add margin to elements next to floating images -->
<div class="img-push">
<input type="text" class="form-control input-sm" name="comentario" placeholder="Comentar...">
</div>
</form>
</div>
<!-- /.box-footer -->
<!-- /.box-body -->
<div id="box-commets-body-'.$key['postingid'].'" class="box-footer box-comments">';
commentsajx($key['postingid'],$key['permalink']);
echo'</div>
</div>
';
}
}
$conexion = '';
}
Cita de: 3n31ch en 14 Mayo 2017, 06:43 AM
Modifica la etiqueta GeSHi y pon PHP pls. (Es muy dificil leer codigo asi).
¿Quieres descontar en la variable o quieres descontar en la base de datos? - (No he descargado la BD y no planeo hacerlo, si posees un modelo relacional seria genial)
Si lo que quieres es descontar de la variable solo tienes que agregar el codigo de los descuentos haciendo restas sobre la variable, por ejemplo:$comision_total -= $pago
Aunque no creo que eso sea lo que quieras, ya que es muy facil.
He de suponer que tienes en la base de datos la cantidad de pagos y la cantidad de utilidades del mes (seleccionando los del ultimo mes), en dicho caso puedes seleccionar directamente la diferencia, o cargar los dos datos y luego restarlos.
Por otro lado, si es cosa de bases de datos ahi necesito el modelo y que bd es.
<?php
$u = null;
if( Session::getUID() != "" && !empty( $_GET["id"] ) ):
$u = UserData::getById( Session::getUID() );
$user = $u->name." ".$u->lastname;
$client_id = $_GET["id"];
$client = ClientData::getById( $client_id );
$cliente = false;
elseif( Session::getUID() != "" && empty( $_GET["id"] ) ):
$u = UserData::getById( Session::getUID() );
$user = $u->name." ".$u->lastname;
$client = ClientData::getByIdUser( $u->id );
$client_id = $client->id;
$cliente = true;
else:
print "<script>window.location='index.php';</script>";
endif;
?>
<div class="row">
<div class="col-md-12">
<h1><i class='fa fa-clock-o'></i> <?php echo $client->name." ".$client->lastname; ?> </h1>
<br>
<?php
$products = array();
if(isset($_GET["start_at"]) && $_GET["start_at"]!="" && isset($_GET["finish_at"]) && $_GET["finish_at"]!=""){
if($_GET["start_at"]<$_GET["finish_at"]){
$products = OperationData::getAllByClientIdAndRange( $client->id,$_GET["start_at"], $_GET["finish_at"] );
}
}
else{
$products = OperationData::getAllByClientId( $client->id );
}
$comision_total = 0;
if( count( $products ) > 0 ){
?>
<br>
<table class="table table-bordered table-hover ">
<thead>
<th>Clave</th>
<th>Precio de Venta</th>
<th>Precio de Costo</th>
<th>Fecha del pedido</th>
<th>Comisión</th>
<?
if( $u->is_admin == 1 ):?>
<th></th>
<?
endif;?>
</thead>
<?php
#echo "<pre>";print_r( $products );echo "</pre>";
foreach($products as $sell):
#$item = $sell->getItem();
$book = BookData::getById( $sell->book_id );
?>
<tr>
<td>
<?php echo $book->isbn; ?>
</td>
<td><?php echo $book->cantidad; ?></td>
<td><?php echo $book->precio_costo; ?></td>
<td><?php echo $sell->start_at; ?></td>
<td>
<?
$comision = $book->cantidad - $book->precio_costo;
if( $comision >= 80 ){
echo '$40';
$comision_total = 40 + $comision_total;
}
else{
echo '$20';
$comision_total = 20 + $comision_total;
}
?>
</td>
<?
if( $u->is_admin == 1 ):?>
<td>
<a href="index.php?action=delorder&id=<?php echo $sell->id;?>" class="btn btn-danger btn-xs">Eliminar</a>
</td>
<?
endif;?>
</tr>
<?php
endforeach; ?>
</table>
<div class="clearfix"></div>
<?php
}
else{
?>
<p class="alert alert-danger">No hay pedidos.</p>
<?php
}
$inventario = OperationData::getInventory( $client->id );
$list_inventario = OperationData::Discount_list( $client->id );
$inventario_sum = OperationData::Discount_sum( $client->id );
$initial_vendedor = ClientData::getById( $client->id );
?>
<div class="row">
<div class="col-lg-3">
Inventario Inicial<br>
<?
if( !$cliente ):?>
<form action="index.php?action=updateinventory" method="post">
<input id="vendedor" type="hidden" name="vendedor" value="<?= $client->id ?>">
<input required id="invetory_initial" type="text" name="invetory_initial" value="<?= $initial_vendedor->initial_inventory ?>">
<button type="submit" class="btn btn-success">Editar</button>
</form>
<?
else:?>
<h3>$<?= $initial_vendedor->initial_inventory ?></h3>
<?
endif;?>
</div>
<div class="col-lg-2">
Pedidos Realizados: <h3> $<?= ( empty( $inventario[0]->total ) ) ? 0 : $inventario[0]->total ?></h3>
</div>
<div class="col-lg-2">
Abonos: <h3> $<?= ( empty( $inventario_sum[0]->total ) ) ? 0 : $inventario_sum[0]->total ?></h3>
</div>
<div class="col-lg-2">
Deuda Total: <h3>$<?= ( ( $initial_vendedor->initial_inventory + $inventario[0]->total ) - $inventario_sum[0]->total ) ?></h3>
</div>
<div class="col-lg-2">
<label><font color='red'>Utilidades:</font></label> <font color='red'><h3> $<?= $comision_total ?></h3></font>
</div><br>
</div>
<?
if( count( $list_inventario ) > 0 ){?>
<div class="row">
<h3 class="col-lg-4 col-lg-offset-4">Lista de Abonos:</h3><br>
<?
if( count( $list_inventario ) > 0 ){
?>
<br>
<table align="center" class="table table-bordered table-hover">
<thead>
<th>Abono:</th>
<th>Fecha del Abono:</th>
</thead>
<?php
foreach($list_inventario as $list_inventario):
?>
<tr>
<td>
<?php echo $list_inventario->discount_valor; ?>
</td>
<td>
<?php echo $list_inventario->discount_date; ?>
</td>
</tr>
<?php
endforeach; ?>
</table>
<?php
}?>
</div>
<?
}
if( !$cliente ):?>
<div>
<form action="index.php?action=addiscount" method="post">
<input id="cliente" name="cliente" type="hidden" value="<?= $client->id ?>">
<label>Abono: </label>
<input required id="discount_n" type="text" name="discount_n">
<button type="submit" class="btn btn-success">Abonar</button>
</form>
</div>
<?
endif;?>
<div class="clearfix"></div>
<br><br><br><br><br><br><br><br><br><br>
</div>
</div>