public function edit(Request $request)
 {
     $detorderSale = $this->detSeparateSaleRepo->find($request->id);
     $manager = new DetSeparateSaleManager($detorderSale, $request->all());
     $manager->save();
     $stokRepo;
     $stokRepo = new StockRepo();
     $cajaSave = $stokRepo->getModel();
     $stockOri = $stokRepo->find($request->id);
     $stock = $stokRepo->find($request->idStock);
     if ($request->estad == true) {
         $stock->stockSeparados = $stock->stockSeparados - $request->canPendiente;
     } else {
         $stock->stockSeparados = $stock->stockSeparados + $request->canPendiente;
     }
     $stock->save();
     //var_dump($stock);die();
     //$manager1 = new StockManager($stockOri,$stock);
     //$manager1->save();
     return response()->json(['estado' => true, 'nombre' => $detorderSale->nombre]);
 }
示例#2
0
 public function createSeparateSale(Request $request)
 {
     \DB::beginTransaction();
     //----------------------
     $orderRepo;
     $orderRepo = new SeparateSaleRepo();
     $cajaSave = $orderRepo->getModel();
     $cash1 = $orderRepo->find($request->id);
     $manager1 = new SeparateSaleManager($cash1, $request->all());
     $manager1->save();
     //---------------------
     $var = $request->detOrders;
     $request->merge(array('estado' => '0'));
     //$request->merge(array('estado' => '0'));
     $orderSale = $this->saleRepo->getModel();
     $manager = new SaleManager($orderSale, $request->all());
     $manager->save();
     $orderSale->save();
     $temporal = $orderSale->id;
     //----------------------
     $detOrderrepox;
     $montoventa = 0;
     $HeadStockRepo;
     $codigoHeadIS = 0;
     foreach ($var as $object) {
         //------Actualizar pedido------
         //$cajaAct = $request->caja;
         //var_dump($object);die();
         $saleDet;
         $saleDet = new DetSeparateSaleRepo();
         //$object=$saleDet->getModel();
         $saled = $saleDet->find($object['id']);
         //var_dump($saled);die();
         $manager2 = new DetSeparateSaleManager($saled, $object);
         $manager2->save();
         //-----------------------------
         $object['sale_id'] = $temporal;
         $object['cantidad'] = $object['parteEntregado'];
         $object['subTotal'] = $object['precioVenta'] * $object['parteEntregado'];
         $montoventa = $montoventa + $object['subTotal'];
         $detOrderrepox = new DetSaleRepo();
         $insertar = new DetSaleManager($detOrderrepox->getModel(), $object);
         if ($object['parteEntregado'] > 0) {
             $insertar->save();
         }
         $detOrderrepox = null;
         //-------------------------------------
         $stockmodel = new StockRepo();
         $object['warehouse_id'] = $object['idAlmacen'];
         $object["variant_id"] = $object['vari'];
         $stockac = $stockmodel->encontrar($object["variant_id"], $object['warehouse_id']);
         //var_dump($stockac);die();
         //--------------reporte stock------------
         if ($codigoHeadIS === 0) {
             $object["warehouses_id"] = $object['idAlmacen'];
             //$object["cantidad_llegado"]=$cantidaCalculada;
             //$object['descripcion']='Entrada por compra';
             $object['tipo'] = 'Venta';
             $object["user_id"] = auth()->user()->id;
             $object["Fecha"] = $request->input("fechaPedido");
             $HeadStockRepo = new HeadInputStockRepo();
             $HeadStock = $HeadStockRepo->getModel();
             $HeadStockinsert = new HeadInputStockManager($HeadStock, $object);
             $HeadStockinsert->save();
             $codigoHeadIS = $HeadStock->id;
         }
         $object['headInputStock_id'] = $codigoHeadIS;
         $object["producto"] = $object['nameProducto'] . "(" . $object['NombreAtributos'] . ")";
         $object["cantidad_llegado"] = $object['cantidad'];
         $object['descripcion'] = 'Salida por Venta';
         $inputRepo;
         $inputRepo = new InputStockRepo();
         $inputstock = $inputRepo->getModel();
         $inputInsert = new InputStockManager($inputstock, $object);
         $inputInsert->save();
         //---------------------------------------
         if (!empty($stockac)) {
             if ($object["equivalencia"] == null) {
                 $object["stockSeparados"] = $stockac->stockSeparados - $object["cantidad"];
                 $object["stockActual"] = $stockac->stockActual - $object["cantidad"];
                 //
             } else {
                 $object["stockActual"] = $stockac->stockActual - $object["cantidad"] * $object["equivalencia"];
                 $object["stockSeparados"] = $stockac->stockSeparados - $object["cantidad"] * $object["equivalencia"];
             }
             $manager = new StockManager($stockac, $object);
             $manager->save();
             //$stock=null;
         } else {
         }
         $stockac = null;
         //-----------------------------------------------------
     }
     $subTotal = $montoventa / 1.18;
     $montoIgv = $montoventa - $subTotal;
     $request->merge(array('montoTotal' => $montoventa));
     $request->merge(array('igv' => $montoIgv));
     $request->merge(array('montoBruto' => $subTotal));
     $sales = $this->saleRepo->find($temporal);
     $manager = new SaleManager($sales, $request->all());
     $manager->save();
     \DB::commit();
     return response()->json(['estado' => true, 'nombres' => $orderSale->nombres]);
 }
 public function edit(Request $request)
 {
     $varDetOrders = $request->detOrder;
     $detOrderSaleRepo;
     foreach ($varDetOrders as $object) {
         $detOrderSaleRepo = new DetSeparateSaleRepo();
         $detorderSale = $detOrderSaleRepo->find($object['id']);
         $manager = new DetSeparateSaleManager($detorderSale, $object);
         $manager->save();
         $stokRepo;
         $stokRepo = new StockRepo();
         $cajaSave = $stokRepo->getModel();
         $stockOri = $stokRepo->find($object['id']);
         $stock = $stokRepo->find($object['idStock']);
         if ($object['estad'] == true) {
             $stock->stockSeparados = $stock->stockSeparados - $object['canPendiente'];
         } else {
             $stock->stockSeparados = $stock->stockSeparados + $object['canPendiente'];
         }
         $stock->save();
     }
     $orderSale = $this->separateSaleRepo->find($request->id);
     $manager = new SeparateSaleManager($orderSale, $request->all());
     $manager->save();
     return response()->json(['estado' => true, 'nombre' => $orderSale->nombre]);
 }