private function saveInStockTable($idBranch, $idArticle, $amount) { try { // $articleStock = Stock::whereRaw("article_id='". $idArticle ."' and branch_id='". $idBranch ."'")->first(); // $articleStock = Stock::where('article_id', '=', $idArticle)->where('branch_id', '=', $idBranch)->first(); $articleStock = Stock::where('article_id', $idArticle)->where('branch_id', $idBranch)->first(); if (!empty($articleStock)) { $articleStock->stock -= $amount; $articleStock->update(); } #if !empty($ArticleStock) } catch (Exception $e) { die('No se pudo modificar el stock del artículo' . $idArticle . ' en la sucursal ' . $idBranch); } }
private function saveInStockTable($idBranch, $idArticle, $amount) { try { $articleStock = Stock::where('article_id', $idArticle)->where('branch_id', $idBranch)->first(); if (!empty($articleStock)) { $articleStock->stock += $amount; $articleStock->save(); } else { $stockTable = new Stock(); $stockTable->branch_id = $idBranch; $stockTable->article_id = $idArticle; $stockTable->stock = $amount; $stockTable->minstock = 0; $stockTable->save(); } #if !empty($ArticleStock) } catch (Exception $e) { die('No se pudo modificar el stock del artículo' . $idArticle . ' en la sucursal ' . $idBranch); } }
private function saveInStockTable($disminuir, $idBranch, $idArticle, $amount) { try { $articleStock = Stock::where('article_id', $idArticle)->where('branch_id', $idBranch)->first(); if (!empty($articleStock)) { if ($disminuir == true) { $articleStock->stock -= $amount; } else { $articleStock->stock += $amount; } $articleStock->update(); } else { $StockTable = new Stock(); $stock['branch_id'] = $idBranch; $stock['article_id'] = $idArticle; $stock['stock'] = $amount; $stock['minstock'] = 0; $StockTable->create($stock); } #if } catch (Exception $e) { die('No se pudo modificar el stock del artículo' . $idArticle . ' en la sucursal ' . $idBranch); } }
public function post_verifikasipartkeluar() { $id = Input::get('id'); $itempart = Wopart::find($id); $stock = Stock::where('pool_id', '=', Auth::user()->pool_id)->where('sparepart_id', '=', $itempart->sparepart_id)->first(); if ($stock) { if ($stock->qty >= $itempart->qty) { $x = Trackinginventory::create(array('pool_id' => Auth::user()->pool_id, 'sparepart_id' => $itempart->sparepart_id, 'qty' => $itempart->qty * -1, 'user_id' => Auth::user()->id, 'note' => 'Part Keluar melalui WO dengan id wo ' . $itempart->wo_id)); if ($x) { $itempart->telah_dikeluarkan = 1; $itempart->save(); return 'Part berhasil di keluarkan'; } } else { return 'Part gagal di keluarkan mungkin karna stock tidak tercukupi!'; } } else { return 'Part gagal di keluarkan mungkin karna stock tidak tersedia!'; } }
public function getExcelByBranch($idBranch) { $branch = Branche::find($idBranch); if (empty($branch)) { return Redirect::to('branches'); } /** Error reporting */ error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); date_default_timezone_set('America/Bogota'); if (PHP_SAPI == 'cli') { die('Este archivo corre únicamente desde un navegador web.'); } // Create new PHPExcel object $objPHPExcel = new PHPExcel(); // Set document properties $objPHPExcel->getProperties()->setCreator(Auth::user()->name)->setLastModifiedBy(Auth::user()->name)->setTitle("Informe de artículos")->setSubject("Sucursal " . $branch->name)->setDescription("Este documento contiene la lista de artículos de la sucursal " . $branch->name)->setKeywords("artículos, sucursal, " . $branch->name)->setCategory("Archivo generado"); // Datos de sucursal $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'Código de sucursal')->setCellValue('B1', $branch->id)->setCellValue('A2', 'Nombre de sucursal')->setCellValue('B2', $branch->name); // Encabezados con UTF-8 $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A3', 'Código de artículo')->setCellValue('B3', 'Nombre de artículo')->setCellValue('C3', 'Stock físico')->setCellValue('D3', 'Unidad de medida')->setCellValue('E3', 'Precio unitario')->setCellValue('F3', 'Costo unitario')->setCellValue('G3', 'Precio neto')->setCellValue('H3', 'Costo neto')->setCellValue('I3', 'Datos adicionales'); $stocks = Stock::where('branch_id', '=', $branch->id)->get(); $fila = 4; foreach ($stocks as $stock) { // $article = Article::find($stock->article->id); $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A' . $fila, $stock->article->id)->setCellValue('B' . $fila, $stock->article->name)->setCellValue('C' . $fila, $stock->stock)->setCellValue('D' . $fila, $stock->article->unit)->setCellValue('E' . $fila, $stock->article->price)->setCellValue('F' . $fila, $stock->article->cost)->setCellValue('G' . $fila, $stock->article->price * $stock->stock)->setCellValue('H' . $fila, $stock->article->cost * $stock->stock)->setCellValue('I' . $fila, $stock->article->comments); $fila++; } // Rename worksheet $objPHPExcel->getActiveSheet()->setTitle('s' . $branch->id . date('_Ymd')); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); // Redirect output to a client’s web browser (Excel2007) // header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'); // header('Content-Disposition: attachment;filename="s'. $branch->id . date('_YmdHis') .'.xlsx"'); // header('Cache-Control: max-age=0'); $nombre_archivo = 's' . $branch->id . date('_His') . '.xlsx'; $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save(public_path() . '/excel/' . $nombre_archivo); return Redirect::to('branches')->with(array('mensajewell' => 'El archivo ' . $nombre_archivo . ' se ha creado con éxito, si la descarga no inicia automáticamente haga click <a id="descarga" href="' . url('excel/' . $nombre_archivo) . '">aquí</a> para descargarlo.<script>$(document).on("ready", function(){ $(location).attr("href", "' . url('excel/' . $nombre_archivo) . '"); });</script>')); // $objWriter->save('php://output'); // exit; }
function index_delete() { $models = json_decode($this->delete('models')); foreach ($models as $value) { $obj = new Stock(null, $this->entity); $obj->where("id", $value->id)->get(); $data["results"][] = array("data" => $value, "status" => $obj->delete()); } $data["count"] = count($data["results"]); //Response data $this->response($data, 200); }
public function getExcelConMovimientos($idArticle) { $article = Article::find($idArticle); if (empty($article)) { return Redirect::to('articles'); } $fecha1 = Input::get('fecha1'); $fecha2 = Input::get('fecha2'); $movimientos = $article->movimientos($fecha1, $fecha2); /** Error reporting */ error_reporting(E_ALL); ini_set('display_errors', TRUE); ini_set('display_startup_errors', TRUE); date_default_timezone_set('America/Bogota'); if (PHP_SAPI == 'cli') { die('Este archivo corre únicamente desde un navegador web.'); } // Create new PHPExcel object $objPHPExcel = new PHPExcel(); // Set document properties $objPHPExcel->getProperties()->setCreator(Auth::user()->name)->setLastModifiedBy(Auth::user()->name)->setTitle("Movimientos de artículo")->setSubject("Artículo " . $article->name)->setDescription("Este documento contiene los movimientos del artículo " . $article->name)->setKeywords("artículo, sucursal, " . $article->name)->setCategory("Archivo generado"); // Datos de encabezado $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'Movimientos del artículo ' . $article->name . ' desde ' . $fecha1 . ' hasta ' . $fecha2)->setCellValue('A2', 'Fecha')->setCellValue('B2', 'Tipo de remisión')->setCellValue('C2', 'Id remisión')->setCellValue('D2', 'Sucursal')->setCellValue('E2', 'Cantidad')->setCellValue('F2', 'Estado')->setCellValue('G2', 'Comentario del remisionero')->setCellValue('H2', 'Nota reciente')->setCellValue('I2', 'Saldo (opcional)'); $stocks = Stock::where('article_id', '=', $article->id)->get(); // Desde donde inicia el contenido. $fila = 3; foreach ($movimientos as $movimiento) { $fecha = (string) $movimiento['fecha']; $objPHPExcel->setActiveSheetIndex(0)->setCellValue('A' . $fila, $fecha)->setCellValue('B' . $fila, $movimiento['tipo'])->setCellValue('C' . $fila, $movimiento['id'])->setCellValue('D' . $fila, $movimiento['sucursal'])->setCellValue('E' . $fila, $movimiento['cantidad'])->setCellValue('F' . $fila, $movimiento['estado'])->setCellValue('G' . $fila, $movimiento['comentario'])->setCellValue('H' . $fila, $movimiento['nota']); $fila++; } $formula = 'SI(Y(B4="compra";F4<>"cancelado");I3+E4;SI(Y(O(B4="venta";B4="daño";B4="entrega inmediata");F4<>"cancelado");I3-E4;I3))'; //Valor inicial de saldo $objPHPExcel->setActiveSheetIndex(0)->setCellValue('I3', '0')->setCellValue('I4', (string) $formula); // Rename worksheet $objPHPExcel->getActiveSheet()->setTitle('m' . $article->id . date('_Ymd')); // Set active sheet index to the first sheet, so Excel opens this as the first sheet $objPHPExcel->setActiveSheetIndex(0); $nombre_archivo = 'm' . $article->id . date('_His') . '.xlsx'; $objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007'); $objWriter->save(public_path() . '/excel/' . $nombre_archivo); return Redirect::to('articles/search?filterBy=id&search=' . $idArticle)->with(array('mensajewell' => 'El archivo ' . $nombre_archivo . ' se ha creado con éxito, si la descarga no inicia automáticamente haga click <a id="descarga" href="' . url('excel/' . $nombre_archivo) . '">aquí</a> para descargarlo.<script>$(document).on("ready", function(){ $(location).attr("href", "' . url('excel/' . $nombre_archivo) . '"); });</script>')); //Formula para calcular columna de saldo /* =SI( Y(B4="compra";F4<>"cancelado"); I3+E4; SI( Y( O(B4="venta";B4="daño";B4="entrega inmediata"); F4<>"cancelado"); I3-E4; I3 ) ) =SI(Y(B4="compra";F4<>"cancelado");I3+E4;SI(Y(O(B4="venta";B4="daño";B4="entrega inmediata");F4<>"cancelado");I3-E4;I3)) */ }