Primer commit del sistema avantika sin cambios
This commit is contained in:
184
modules/inventario-wizard.php
Executable file
184
modules/inventario-wizard.php
Executable file
@@ -0,0 +1,184 @@
|
||||
<?php
|
||||
|
||||
$empresa->AuthUser();
|
||||
|
||||
$sucursalId = $_SESSION['idSuc'];
|
||||
|
||||
$step = intval($_GET['step']);
|
||||
|
||||
if($step == 0)
|
||||
$step++;
|
||||
|
||||
if($_POST['type'] == 'uploadFile'){
|
||||
|
||||
$sucursalId = $_POST['sucursalId'];
|
||||
$_SESSION['wizSucId'] = $sucursalId;
|
||||
|
||||
if($_SESSION['xlsFile'] != ''){
|
||||
header('Location: '.WEB_ROOT.'/inventario-wizard/step/2');
|
||||
exit;
|
||||
}
|
||||
|
||||
$tempFile = $_FILES['excelFile']['tmp_name'];
|
||||
|
||||
if($tempFile == ''){
|
||||
|
||||
$errMsg = 'Por favor, seleccione un archivo.';
|
||||
|
||||
}else{
|
||||
|
||||
$fileParts = pathinfo($_FILES['excelFile']['name']);
|
||||
|
||||
if($fileParts['extension'] != 'csv'){
|
||||
|
||||
$errMsg = 'Tipo de archivo invalido. Debe ser .csv';
|
||||
|
||||
}else{
|
||||
|
||||
$targetFolder = DOC_ROOT.'/temp';
|
||||
$timestamp = time();
|
||||
$_SESSION['identificador'] = $timestamp;
|
||||
|
||||
$targetPath = $targetFolder;
|
||||
|
||||
$nomFile = 'excel_'.$timestamp.'.'.$fileParts['extension'];
|
||||
|
||||
$targetFile = rtrim($targetPath,'/').'/'.$nomFile;
|
||||
|
||||
if(move_uploaded_file($_FILES['excelFile']['tmp_name'], $targetFile)){
|
||||
|
||||
$_SESSION['xlsFile'] = $nomFile;
|
||||
|
||||
header('Location: '.WEB_ROOT.'/inventario-wizard/step/2');
|
||||
exit;
|
||||
|
||||
}else{
|
||||
|
||||
$errMsg = 'Ocurrio un error al subir el archivo.';
|
||||
|
||||
}//else
|
||||
|
||||
}//else
|
||||
|
||||
}//else
|
||||
|
||||
}//if
|
||||
|
||||
if($step == 1){
|
||||
|
||||
if($_SESSION['wizSucId'])
|
||||
$sucursalId = $_SESSION['wizSucId'];
|
||||
|
||||
$sucursal->setSucursalId($sucursalId);
|
||||
$nomSuc = $sucursal->GetNameById($sucursalId);
|
||||
$nomSuc = utf8_decode(urldecode($nomSuc));
|
||||
|
||||
$xlsFile = $_SESSION['xlsFile'];
|
||||
|
||||
$sucursal->setRfcId(1);
|
||||
$resSucursales = $sucursal->GetSucursalesByRfc();
|
||||
|
||||
$sucursales = array();
|
||||
foreach($resSucursales as $res){
|
||||
|
||||
$res['nombre'] = utf8_decode(urldecode($res['nombre']));
|
||||
|
||||
$sucursales[] = $res;
|
||||
}
|
||||
|
||||
}elseif($step == 2){
|
||||
|
||||
$sucursalId = $_SESSION['wizSucId'];
|
||||
|
||||
$sucursal->setSucursalId($sucursalId);
|
||||
$nomSuc = $sucursal->GetNameById($sucursalId);
|
||||
$nomSuc = utf8_decode(urldecode($nomSuc));
|
||||
|
||||
$csvFile = DOC_ROOT.'/temp/'.$_SESSION['xlsFile'];
|
||||
|
||||
$file = @fopen($csvFile, 'r');
|
||||
|
||||
if($_SESSION['xlsFile'] == ''){
|
||||
$errMsg = 'No se ha cargado ningún archivo. Por favor, verifique.';
|
||||
}elseif(!$file){
|
||||
$errMsg = 'Ocurrio un error al abrir el archivo';
|
||||
}else{
|
||||
|
||||
$size = filesize($csvFile);
|
||||
|
||||
if(!$size){
|
||||
$errMsg = 'El archivo esta vacio, verifique';
|
||||
}else{
|
||||
|
||||
$db = $util->DBSelect(15);
|
||||
|
||||
$cantProdExisten = 0;
|
||||
$cantProdFaltan = 0;
|
||||
$prodExisten = array();
|
||||
$prodFaltan = array();
|
||||
|
||||
while (( $field = fgetcsv($file,2048,",")) !== false ) { // Mientras hay líneas que leer...
|
||||
|
||||
if($lines >= 1){
|
||||
|
||||
$codigoBarra = trim($field[0]);
|
||||
$stock = trim($field[1]);
|
||||
|
||||
$card['codigoBarra'] = $codigoBarra;
|
||||
$card['stock'] = $stock;
|
||||
|
||||
if($codigoBarra){
|
||||
|
||||
$sql = 'SELECT productoId FROM producto WHERE codigoBarra = "'.$codigoBarra.'"';
|
||||
$db->setQuery($sql);
|
||||
$productoId = $db->GetSingle();
|
||||
|
||||
if($productoId){
|
||||
|
||||
$prodExisten[] = $card;
|
||||
$cantProdExisten += $stock;
|
||||
|
||||
}else{
|
||||
|
||||
$prodFaltan[] = $card;
|
||||
$cantProdFaltan += $stock;
|
||||
|
||||
}//if
|
||||
|
||||
$regs++;
|
||||
|
||||
}//if
|
||||
|
||||
}//if
|
||||
|
||||
$lines++;
|
||||
|
||||
}//while
|
||||
|
||||
if(count($prodFaltan)){
|
||||
$errMsg = 'Debido a que hay productos que no se encuentran en el sistema,
|
||||
<br>primero debe dar da alta esos productos para poder continuar con el proceso.';
|
||||
@unlink($csvFile);
|
||||
$_SESSION['xlsFile'] = '';
|
||||
$_SESSION['wizSucId'] = '';
|
||||
$_SESSION['identificador'] = '';
|
||||
}
|
||||
|
||||
}//else
|
||||
|
||||
}//else
|
||||
|
||||
}//if
|
||||
|
||||
$smarty->assign('errMsg', $errMsg);
|
||||
$smarty->assign('step', $step);
|
||||
$smarty->assign('xlsFile', $xlsFile);
|
||||
$smarty->assign('sucursalId', $sucursalId);
|
||||
$smarty->assign('nomSuc', $nomSuc);
|
||||
$smarty->assign('sucursales', $sucursales);
|
||||
$smarty->assign('cantProdExisten', $cantProdExisten);
|
||||
$smarty->assign('cantProdFaltan', $cantProdFaltan);
|
||||
$smarty->assign('prodExisten', $prodExisten);
|
||||
$smarty->assign('prodFaltan', $prodFaltan);
|
||||
|
||||
?>
|
||||
Reference in New Issue
Block a user