Пример #1
0
 public function selectReportByProduct(Request $request, SaleOrderAjax $saleOrder)
 {
     $input = $request->all();
     if (isset($input['users']) && $input['users'] != "") {
         $saleOrderDetail = SaleOrderDetail::select('pgroups.name AS pgroup_name', 'products.name AS pro_name', 'unit_price', 'products.code', DB::raw("(SELECT CONCAT(SUM(qty),'|',SUM(discount_price_riel),'|',SUM(total_price_riel)) FROM sales_order_details INNER JOIN sales_orders ON sales_orders.id=sales_order_details.sales_order_id WHERE product_id=products.id AND sales_orders.created_by = " . $input['users'] . " AND DATE(sales_order_details.created_at) BETWEEN '" . $input['dateFrom'] . "' AND '" . $input['dateTo'] . "') AS group_amount"))->join('sales_orders', 'sales_orders.id', '=', 'sales_order_details.sales_order_id')->join('users', 'users.id', '=', 'sales_orders.created_by')->join('products', 'products.id', '=', 'sales_order_details.product_id')->join('pgroups', 'pgroups.id', '=', 'products.pgroup_id')->where('sales_orders.is_active', 1)->where('sales_orders.is_book', 0)->where('sales_orders.created_by', $input['users'])->whereBetween(DB::raw('DATE(sales_orders.created_at)'), array($input['dateFrom'], $input['dateTo']))->orderBy('pgroup_name')->groupBy('product_id')->get();
     } else {
         $saleOrderDetail = SaleOrderDetail::select('pgroups.name AS pgroup_name', 'products.name AS pro_name', 'unit_price', 'products.code', DB::raw("(SELECT CONCAT(SUM(qty),'|',SUM(discount_price_riel),'|',SUM(total_price_riel)) FROM sales_order_details WHERE product_id=products.id AND DATE(sales_order_details.created_at) BETWEEN '" . $input['dateFrom'] . "' AND '" . $input['dateTo'] . "') AS group_amount"))->join('sales_orders', 'sales_orders.id', '=', 'sales_order_details.sales_order_id')->join('users', 'users.id', '=', 'sales_orders.created_by')->join('products', 'products.id', '=', 'sales_order_details.product_id')->join('pgroups', 'pgroups.id', '=', 'products.pgroup_id')->where('sales_orders.is_active', 1)->where('sales_orders.is_book', 0)->whereBetween(DB::raw('DATE(sales_orders.created_at)'), array($input['dateFrom'], $input['dateTo']))->orderBy('pgroup_name')->groupBy('product_id')->get();
     }
     return View::make('reports.reportProductResult')->with('saleOrderDetail', $saleOrderDetail);
 }
Пример #2
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!');
 }
Пример #3
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'));
 }