public function edit(Request $request)
 {
     $detorderSale = $this->detOrderSaleRepo->find($request->id);
     $manager = new DetOrderSaleManager($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->stockPedidos = $stock->stockPedidos - $request->canPendiente;
     } else {
         $stock->stockPedidos = $stock->stockPedidos + $request->canPendiente;
     }
     $stock->save();
     //var_dump($stock);die();
     //$manager1 = new StockManager($stockOri,$stock);
     //$manager1->save();
     return response()->json(['estado' => true, 'nombre' => $detorderSale->nombre]);
 }
 public function edit(Request $request)
 {
     $varDetOrders = $request->detOrder;
     $varPayment = $request->payment;
     $movimiento = $request->movimiento;
     if ($movimiento['montoMovimientoEfectivo'] > 0) {
         //---create movimiento---
         //var_dump($request->movimiento);die();
         $detCashrepo;
         $movimiento['observacion'] = "temporal";
         $detCashrepo = new DetCashRepo();
         $movimientoSave = $detCashrepo->getModel();
         $insertarMovimiento = new DetCashManager($movimientoSave, $movimiento);
         $insertarMovimiento->save();
         //---Autualizar Caja---
         $cajaAct = $request->caja;
         $cashrepo;
         $cashrepo = new CashRepo();
         $cajaSave = $cashrepo->getModel();
         $cash1 = $cashrepo->find($cajaAct["id"]);
         $manager1 = new CashManager($cash1, $cajaAct);
         $manager1->save();
         //----------------
         $salePaymentRepo;
         $salePaymentRepo = new SalePaymentRepo();
         $payment = $salePaymentRepo->find($varPayment['id']);
         $manager = new SalePaymentManager($payment, $varPayment);
         $manager->save();
     }
     $detOrderSaleRepo;
     foreach ($varDetOrders as $object) {
         $detOrderSaleRepo = new DetOrderSaleRepo();
         $detorderSale = $detOrderSaleRepo->find($object['id']);
         $manager = new DetOrderSaleManager($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->stockPedidos = $stock->stockPedidos - $object['canPendiente'];
         } else {
             $stock->stockPedidos = $stock->stockPedidos + $object['canPendiente'];
         }
         $stock->save();
     }
     $orderSale = $this->orderSaleRepo->find($request->id);
     $manager = new OrderSaleManager($orderSale, $request->all());
     $manager->save();
     return response()->json(['estado' => true, 'nombre' => $orderSale->nombre]);
 }
Esempio n. 3
0
 public function createSale(Request $request)
 {
     \DB::beginTransaction();
     //----------------------
     $orderRepo;
     $orderRepo = new OrderSaleRepo();
     $cajaSave = $orderRepo->getModel();
     $cash1 = $orderRepo->find($request->id);
     $manager1 = new OrderSaleManager($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 DetOrderSaleRepo();
         //$object=$saleDet->getModel();
         $saled = $saleDet->find($object['id']);
         //var_dump($saled);die();
         $manager2 = new DetOrderSaleManager($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["stockPedidos"] = $stockac->stockPedidos - $object["cantidad"];
                 $object["stockActual"] = $stockac->stockActual - $object["cantidad"];
                 //
             } else {
                 $object["stockActual"] = $stockac->stockActual - $object["cantidad"] * $object["equivalencia"];
                 $object["stockPedidos"] = $stockac->stockPedidos - $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]);
 }