コード例 #1
0
 public function create(Request $request)
 {
     $orderSale = $this->orderSaleRepo->getModel();
     $var = $request->detOrders;
     $payment = $request->salePayment;
     $saledetPayments = $request->saledetPayments;
     $manager = new OrderSaleManager($orderSale, $request->all());
     $manager->save();
     /*
            if($this->purchaseRepo->validateDate(substr($request->input('fechaEntrega'),0,10))){
                 $order->fechaEntrega = substr($request->input('fechaEntrega'),0,10);
             }else{
                
                 $order->fechaEntrega = null;
             }*/
     $orderSale->save();
     $temporal = $orderSale->id;
     //---create movimiento---
     $movimiento = $request->movimiento;
     $detCashrepo;
     $movimiento['observacion'] = $temporal;
     $detCashrepo = new DetCashRepo();
     $movimientoSave = $detCashrepo->getModel();
     $insertarMovimiento = new DetCashManager($movimientoSave, $movimiento);
     $insertarMovimiento->save();
     $detCash_id = $movimientoSave->id;
     //---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;
     $payment['orderSale_id'] = $temporal;
     $salePaymentrepo = new SalePaymentRepo();
     $paymentSave = $salePaymentrepo->getModel();
     $insertarpayment = new SalePaymentManager($paymentSave, $payment);
     $insertarpayment->save();
     $paymentSave->save();
     $temporal1 = $paymentSave->id;
     //--------------------------
     $saledetPaymentrepo;
     foreach ($saledetPayments as $object1) {
         $object1['salePayment_id'] = $temporal1;
         $object1['detCash_id'] = $detCash_id;
         $saledetPaymentrepo = new SaleDetPaymentRepo();
         $insertar = new SaleDetPaymentManager($saledetPaymentrepo->getModel(), $object1);
         $insertar->save();
         $saledetPaymentrepo = null;
     }
     $detOrderrepox;
     foreach ($var as $object) {
         $object['orderSale_id'] = $temporal;
         $detOrderrepox = new DetOrderSaleRepo();
         $insertar = new DetOrderSaleManager($detOrderrepox->getModel(), $object);
         $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']);
         if (!empty($stockac)) {
             if ($object["equivalencia"] == null) {
                 $object["stockPedidos"] = $stockac->stockPedidos + $object["cantidad"];
                 //
             } else {
                 $object["stockPedidos"] = $stockac->stockPedidos + $object["cantidad"] * $object["equivalencia"];
             }
             $manager = new StockManager($stockac, $object);
             $manager->save();
         } else {
         }
         $stockac = null;
         //-----------------------------------------------------
     }
     return response()->json(['estado' => true, 'nombres' => $orderSale->nombres]);
 }
コード例 #2
0
 public function create(Request $request)
 {
     \DB::beginTransaction();
     $vuelto = $request->input("vuelto");
     $montobrutoventa = $request->input("montoBruto");
     $orderSale = $this->saleRepo->getModel();
     $var = $request->detOrders;
     $payment = $request->salePayment;
     $saledetPayments = $request->saledetPayments;
     $servicePayment = $request->servicePayment;
     $cajaAct = $request->caja;
     //var_dump($cajaAct);die();
     //-------------------------$cajaAct['id']
     //----------------
     if ($request->input("banseraServicio") == true) {
         $varService = $request->service;
         $serviceRepo;
         $varService['estado'] = 5;
         $serviceRepo = new ServiceRepo();
         $serviceSave = $serviceRepo->getModel();
         $brand = $serviceSave->find($varService['id']);
         $manager = new ServiceManager($brand, $varService);
         $manager->save();
     }
     //---create movimiento---
     $movimiento = $request->movimiento;
     $detCashrepo;
     //$movimiento['observacion']=$temporal;
     $detCashrepo = new DetCashRepo();
     $movimientoSave = $detCashrepo->getModel();
     $insertarMovimiento = new DetCashManager($movimientoSave, $movimiento);
     $insertarMovimiento->save();
     $detCash_id = $movimientoSave->id;
     $request->merge(["cash_id" => $cajaAct['id']]);
     $request->merge(['detCash_id' => $detCash_id]);
     $manager = new SaleManager($orderSale, $request->all());
     $manager->save();
     $orderSale->save();
     $temporal = $orderSale->id;
     //---Autualizar Caja---
     $cashrepo;
     $cashrepo = new CashRepo();
     $cajaSave = $cashrepo->getModel();
     //-->$cash1 = $cashrepo->find($cajaAct["id"]);
     //-->$manager1 = new CashManager($cash1,$cajaAct);
     //-->$manager1->save();
     //----------------
     $salePaymentrepo;
     $payment['sale_id'] = $temporal;
     $salePaymentrepo = new SalePaymentRepo();
     $paymentSave = $salePaymentrepo->getModel();
     $insertarpayment = new SalePaymentManager($paymentSave, $payment);
     $insertarpayment->save();
     $paymentSave->save();
     $temporal1 = $paymentSave->id;
     //--------------------------
     $saledetPaymentrepo;
     if ($request->input("banderaservice") == true) {
         foreach ($servicePayment as $object2) {
             $object2['salePayment_id'] = $temporal1;
             $object2['detCash_id'] = $detCash_id;
             $saledetPaymentrepo = new SaleDetPaymentRepo();
             $insertar = new SaleDetPaymentManager($saledetPaymentrepo->getModel(), $object2);
             $insertar->save();
             $saledetPaymentrepo = null;
         }
     }
     foreach ($saledetPayments as $object1) {
         $object1['salePayment_id'] = $temporal1;
         $object1['detCash_id'] = $detCash_id;
         $saledetPaymentrepo = new SaleDetPaymentRepo();
         $insertar = new SaleDetPaymentManager($saledetPaymentrepo->getModel(), $object1);
         $insertar->save();
         $saledetPaymentrepo = null;
     }
     //--------------------------
     //$request->merge(["ingresos"=>floatval($cash->ingresos)+floatval($var["monto"])]);
     $cash1 = $cashrepo->find($cajaAct['id']);
     $request->merge(["ingresos" => floatval($cash1->ingresos) + floatval($movimiento["montoMovimientoTarjeta"]) + floatval($movimiento["montoMovimientoEfectivo"])]);
     $request->merge(['fechaInicio' => $cash1->fechaInicio]);
     $request->merge(['fechaFin' => $cash1->fechaFin]);
     $request->merge(['montoInicial' => $cash1->montoInicial]);
     $request->merge(['gastos' => $cash1->gastos]);
     $request->merge(['montoBruto' => floatval($cash1->montoBruto) + floatval($movimiento["montoMovimientoTarjeta"]) + floatval($movimiento["montoMovimientoEfectivo"])]);
     $request->merge(['montoReal' => $cash1->montoReal]);
     $request->merge(['descuadre' => $cash1->descuadre]);
     $request->merge(['estado' => $cash1->estado]);
     $request->merge(['notas' => $cash1->notas]);
     $request->merge(['cashHeader_id' => $cash1->cashHeader_id]);
     if ($cash1->user_id == auth()->user()->id && $cash1->estado == 1) {
         $request->merge(['user_id' => $cash1->user_id]);
     } else {
         return response()->json(['estado' => 'Usted no tiene permisos sobre esta caja o la caja esta cerrada??']);
     }
     $cashr = new CashManager($cash1, $request->all());
     $cashr->save();
     //--------------------------
     if (!empty($request->input("comprobante"))) {
         ///var_dump("kkdkdkkdsk");die();
         $headInvoiceRepo = new HeadInvoiceRepo();
         $headInvoice = $headInvoiceRepo->getModel();
         $customerRepo = new CustomerRepo();
         $direccion = $customerRepo->find($request->input("customer_id"));
         $fbnumberRepo = new FBnumberRepo();
         $ashHeaderRepo = $this->ashHeaderRepo->comprobarCaja($cash1["id"]);
         $numbers = $fbnumberRepo->find($ashHeaderRepo["id"]);
         $num = $fbnumberRepo->find($ashHeaderRepo["id"]);
         $cajaId = $ashHeaderRepo["id"];
         if ($request->input("tipoDoc") == "F") {
             $request->merge(["numero" => intval($num->numFactura) + 1]);
             $request->merge(["numFactura" => $request->input("numero")]);
             $request->merge(["numTiketFactura" => intval($num->numTiketFactura) + 1]);
             if (!empty($direccion["empresa"])) {
                 $request->merge(["cliente" => $direccion["empresa"]]);
             } else {
                 $request->merge(["cliente" => $direccion["nombres"] . " " . $direccion["apellidos"]]);
             }
             $request->merge(["direccion" => $direccion["direccFiscal"]]);
             $request->merge(["ruc" => $direccion["ruc"]]);
             $inputfbnumber = new FBnumberManager($numbers, $request->only("numFactura", "numTiketFactura"));
             $inputfbnumber->save();
         } elseif ($request->input("tipoDoc") == "B") {
             if (!empty($direccion["nombres"] && strlen($direccion["nombres"]) > 2)) {
                 $request->merge(["cliente" => $direccion["nombres"] . " " . $direccion["apellidos"]]);
             } else {
                 $request->merge(["cliente" => $direccion["empresa"]]);
             }
             $request->merge(["direccion" => $direccion["direccContac"]]);
             $request->merge(["numero" => intval($num->numBoleta) + 1]);
             $request->merge(["numBoleta" => $request->input("numero")]);
             $request->merge(["numTiketBoleta" => intval($num->numTiketBoleta) + 1]);
             $request->merge(["ruc" => $direccion["dni"]]);
             $inputfbnumber = new FBnumberManager($numbers, $request->only("numBoleta", "numTiketBoleta"));
             $inputfbnumber->save();
         }
         if ($request->input("tipoDoc") == "TF") {
             $request->merge(["numero" => intval($num->numTiketFactura) + 1]);
             $request->merge(["numTiketFactura" => intval($num->numTiketFactura) + 1]);
             $request->merge(["cliente" => $direccion["empresa"]]);
             $request->merge(["direccion" => $direccion["direccFiscal"]]);
             $request->merge(["ruc" => $direccion["ruc"]]);
             $inputfbnumber = new FBnumberManager($numbers, $request->only("numTiketFactura"));
             $inputfbnumber->save();
         } elseif ($request->input("tipoDoc") == "TB") {
             $request->merge(["cliente" => $direccion["nombres"] . " " . $direccion["apellidos"]]);
             $request->merge(["direccion" => $direccion["direccContac"]]);
             $request->merge(["numero" => intval($num->numTiketFactura) + 1]);
             $request->merge(["numTiketFactura" => intval($num->numTiketFactura) + 1]);
             $request->merge(["dni" => $direccion["dni"]]);
             $inputfbnumber = new FBnumberManager($numbers, $request->only("numTiketFactura"));
             $inputfbnumber->save();
         }
         $request->merge(["direccion_cliente" => $direccion["direccContac"]]);
         //var_dump($request->input("direccion_cliente"));die();
         $request->merge(["direccion" => $direccion["direccFiscal"]]);
         $request->merge(["subTotal" => $montobrutoventa]);
         $request->merge(["Total" => $request->input("montoTotal")]);
         $request->merge(["venta_id" => $temporal]);
         $request->merge(["cliente_id" => $request->input("customer_id")]);
         $inputheadInvoiceRepo = new HeadInvoiceManager($headInvoice, $request->only('numero', 'cliente', 'direccion_cliente', 'direccion', 'ruc', 'GRemicion', 'subTotal', 'igv', 'Total', 'venta_id', 'cliente_id', 'tipoDoc', 'vuelto'));
         $inputheadInvoiceRepo->save();
         $codigoFactura = $headInvoice->id;
     }
     //----------------
     $detOrderrepox;
     $HeadStockRepo;
     $codigoHeadIS = 0;
     foreach ($var as $object) {
         $object['sale_id'] = $temporal;
         $detOrderrepox = new DetSaleRepo();
         $insertar = new DetSaleManager($detOrderrepox->getModel(), $object);
         $insertar->save();
         $detOrderrepox = null;
         //-------------------------------------
         if ($object['detPre_id'] != 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['NombreProducto'];
             $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["stockActual"] = $stockac->stockActual - $object["cantidad"];
                     //
                 } else {
                     $object["stockActual"] = $stockac->stockActual - $object["cantidad"] * $object["equivalencia"];
                 }
                 $manager = new StockManager($stockac, $object);
                 $manager->save();
                 //$stock=null;
             } else {
             }
             $stockac = null;
         }
         //-----hasta aca-----
         //-----------------------------------------------------
         //Create det Documento Venta
         //-------------------------------------------------------
         if (!empty($codigoFactura)) {
             if (!empty($object["NombreProducto"])) {
                 $object["descripcion"] = $object["NombreProducto"];
             } else {
                 $object["descripcion"] = $object["NombreAtributos"];
             }
             $object["PrecioUnit"] = $object["precioVenta"];
             $object["PrecioVent"] = $object["subTotal"];
             $object["headInvoice_id"] = $codigoFactura;
             $detInvoice = new DetailInvoiceRepo();
             $insertDetInvoice = new DetailInvoiceManager($detInvoice->getModel(), $object);
             $insertDetInvoice->save();
         }
         //------------------------------------------------------
     }
     if (!empty($request->input("comprobante"))) {
         if ($request->input("tipoDoc") == 'TF' || $request->input("tipoDoc") == 'TB') {
             $this->generate_factura($codigoFactura, $vuelto, $cajaId, $cajaAct["id"], $request->input("tipoDoc"), $request->input('descuento'));
         }
     }
     //-----------------Creacion de Cabecera Factura-------
     \DB::commit();
     if (!empty($codigoFactura)) {
         return response()->json(['estado' => true, 'codFactura' => $codigoFactura, 'nombres' => $orderSale->nombres]);
     } else {
         return response()->json(['estado' => true, 'nombres' => $orderSale->nombres]);
     }
 }