public function create_debit($id)
 {
     $enterprise = Enterprise::find($id);
     $debit = DebitOrder::where('enterprise_id', $enterprise->id)->orderBy('fecha_debito', 'DESC')->first();
     $now = date('Y-m-d H:m:s');
     $debit_status = $this->status;
     if ($debit) {
         #existe un ultimo debito
         $amount = SaleOrder::where('enterprise_id', $enterprise->id)->whereBetween('created_at', array($debit->created_at, $now))->sum('total');
         $period = sprintf('%s - %s ', date("d/m/Y", strtotime($debit->created_at)), date("d/m/Y", strtotime($now)));
     } else {
         $last_payment = '0000-00-00 00:00:00';
         $amount = SaleOrder::where('enterprise_id', $enterprise->id)->whereBetween('created_at', array($last_payment, $now))->sum('total');
         $period = sprintf('Desde inicio hasta %s', date("d/m/Y", strtotime($now)));
     }
     return view('debits.create', compact('enterprise', 'debit_status', 'period', 'amount'));
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     $this->validate($request, SaleOrder::$rules);
     $serial = str_pad(SaleOrder::count(), 6, '0', STR_PAD_LEFT);
     $data = array_merge($request->all(), array('fecha_emision' => date('Y-m-d'), 'nro_orden' => $serial, 'enterprise_id' => Auth::user()->enterprise[0]->id));
     $order = SaleOrder::create($data);
     foreach ($request->input('products') as $p) {
         $producto = new OrderProduct();
         $producto->nombre = $p['nombre'];
         $producto->cantidad = $p['cantidad'];
         $producto->monto = $p['monto'];
         $producto->total = $p['total'];
         $producto->sale_order_id = $order->id;
         $producto->save();
     }
     //echo "<pre>"; print_r($request->all()); echo "</pre>";
     return redirect()->route('sale-point.orden-venta.create')->with('message', '<div class="alert alert-success" style="margin-top:15px">Orden creada con Éxito</div>');
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function update($id)
 {
     $sale_order = SaleOrder::findOrFail($id);
     //        $sale_order->fill($request->all());
     if ($sale_order->status != 'cancel') {
         $sale_order->status = "cancel";
         $sale_order->save();
         Session::flash('message', $sale_order->name . ' was canceled !');
         return \Redirect::route('sales.index');
     } else {
         Session::flash('message', ' dont is possible cancel the sale order it was canceled!');
         return redirect()->route('sales.index');
     }
 }
Example #4
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function destroy($id)
 {
     $saleOrders = SaleOrder::where('id', $id)->first();
     $products = SaleOrderDetail::whereSalesOrderId($id)->get();
     if ($saleOrders->is_pos == 1) {
         foreach ($products as $product) {
             Inventory::wherePointOfSalesId($id)->delete();
             $fields = ['product_id' => $product->product_id, 'location_id' => \Auth::user()->location];
             $checkIfSaleExistingProduct = InventoryTotal::where($fields)->first();
             $inventoryTotalDetail = $inventoryTotals = array();
             $inventoryTotals = new InventoryTotal();
             $inventoryTotal['total_qty'] = $checkIfSaleExistingProduct['total_qty'] + $product->qty * $product->conversion;
             $inventoryTotal['created_by'] = \Auth::user()->id;
             $inventoryTotal['updated_by'] = \Auth::user()->id;
             $inventoryTotals->where($fields)->update($inventoryTotal);
             $inventoryTotalDetails = new InventoryTotalDetail();
             $fieldNews = ['product_id' => $product->product_id, 'location_id' => \Auth::user()->location, 'date' => date('Y-m-d')];
             $checkIfSaleExistingProductInventoryDetail = InventoryTotalDetail::where($fieldNews)->first();
             $inventoryTotalDetail['total_pos'] = $checkIfSaleExistingProductInventoryDetail['total_qty'] - $product->qty * $product->conversion;
             $inventoryTotalDetail['created_by'] = \Auth::user()->id;
             $inventoryTotalDetail['updated_by'] = \Auth::user()->id;
             $inventoryTotalDetails->where($fieldNews)->update($inventoryTotalDetail);
         }
     } else {
         Inventory::whereSalesOrderId($id)->delete();
     }
     SaleOrderReceipt::whereSalesOrderId($id)->delete();
     SaleOrderDetail::whereSalesOrderId($id)->delete();
     $saleOrders = SaleOrder::find($id);
     $saleOrders->delete();
     return Redirect::route('saleOrders.index')->with('flash_notice', 'You are successfully delete!');
 }
Example #5
0
 public function printReceipt($sales_order_id, $footer)
 {
     $saleOrder = SaleOrder::where('sales_orders.id', $sales_order_id)->first();
     $saleOrderReceipts = SaleOrderReceipt::where('sales_order_id', $sales_order_id)->get();
     $saleOrderDetail = SaleOrderDetail::join('products', 'products.id', '=', 'sales_order_details.product_id')->whereSales_order_id($sales_order_id)->get();
     return view('/layout/printReceipt', compact('saleOrderDetail', 'saleOrder', 'footer', 'saleOrderReceipts'));
 }
 public function create_payment($id)
 {
     $enterprise = Enterprise::find($id);
     $payment = PaymentOrder::where('enterprise_id', $enterprise->id)->orderBy('fecha_pago', 'DESC')->first();
     $now = date('Y-m-d');
     $payments_methods = $this->payments_methods;
     $payment_status = $this->payment_status;
     if ($payment) {
         //Existe el ultimo pago
         $last_payment = $payment->fecha_pago;
         $next_payment = date('Y-m-d', strtotime($last_payment . " + " . $payment->enterprise->plan->periodo->tiempo . " " . $payment->enterprise->plan->periodo->lapso));
         if ($now >= $next_payment) {
             //La fecha actual es igual o mayor a la del proximo pago
             //hay que generar una orden de pago
             if ($payment->enterprise->plan->costo > 0) {
                 //Cobro por plan
                 $to_pay = $payment->enterprise->plan->costo;
                 $last_order = '0000-00-00 00:00:00';
                 $period = sprintf('Pago mes: %s ', date("m/Y", strtotime($next_payment)));
             } else {
                 //Cobro por porcentaje
                 //Monto entre la fecha de la ultima venta de la ultima orden de pago
                 //y la ultima venta del periodo a cobrar
                 $last_order = SaleOrder::where('enterprise_id', $enterprise->id)->orderBy('created_at', 'DESC')->first();
                 $amount = SaleOrder::where('enterprise_id', $enterprise->id)->whereBetween('created_at', array($payment->ultimo_corte, $last_order->created_at))->sum('total');
                 $to_pay = $amount * ($payment->enterprise->plan->porcentaje / 100);
                 $period = sprintf('%s - %s ', date("d/m/Y", strtotime($last_payment)), date("d/m/Y", strtotime($now)));
             }
         } else {
             //Caso de uso para cuando no hay que generar orden de pago
             //es decir no se ha cumplido el periodo de pago del plan
             return redirect()->route('admin.pagos.listado', $id)->with('message', '<div class="alert alert-warning" style="margin-top:15px">No hay pagos pendientes por facturar</div>');
         }
     } else {
         //Primera vez que la empresa paga
         if ($enterprise->plan->costo > 0) {
             //Cobro por plan
             $to_pay = $enterprise->plan->costo;
             $last_order = '0000-00-00 00:00:00';
             $period = sprintf('Primer pago %s', date("m/Y", strtotime($now)));
         } else {
             //Cobro por porcentaje
             //Monto entre la fecha de la ultima venta de la ultima orden de pago
             //y la ultima venta del periodo a cobrar
             $last_order = SaleOrder::where('enterprise_id', $enterprise->id)->orderBy('created_at', 'DESC')->first();
             $amount = SaleOrder::where('enterprise_id', $enterprise->id)->whereBetween('created_at', array('0000-00-00 00:00:00', $last_order->created_at))->sum('total');
             $to_pay = $amount * ($enterprise->plan->porcentaje / 100);
             $period = sprintf('Desde inicio hasta %s', date("d/m/Y", strtotime($now)));
         }
     }
     $description = sprintf('%s: %s %s', $enterprise->plan->nombre, $enterprise->plan->tiempo_membresia, $this->tiempo[$enterprise->plan->unidad_tiempo]);
     return view('payments.create', compact('enterprise', 'payments_methods', 'payment_status', 'period', 'to_pay', 'last_order', 'description'));
 }