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')); }
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')); }
/** * 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!'); }
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')); }