Exemple #1
0
 public static function generateInvoiceId()
 {
     //needs recheck
     $invdesc = StockInvoice::orderBy('id', 'DESC')->first();
     if ($invdesc != null) {
         $invDescId = $invdesc->invoice_id;
         $invDescIdNo = substr($invDescId, 7);
         $subinv1 = substr($invDescId, 6);
         $dd = substr($invDescId, 1, 2);
         $mm = substr($invDescId, 3, 2);
         $yy = substr($invDescId, 5, 2);
         //var_dump($invDescId." ".$dd." ".$mm." ".$yy);
         //echo "d1 ".$yy;
         $tz = 'Asia/Dhaka';
         $timestamp = time();
         $dt = new \DateTime("now", new \DateTimeZone($tz));
         //first argument "must" be a string
         $dt->setTimestamp($timestamp);
         //adjust the object to correct timestamp
         $Today = $dt->format('d.m.Y');
         $explodToday = explode(".", $Today);
         $dd2 = $explodToday[0];
         $mm2 = $explodToday[1];
         $yy1 = $explodToday[2];
         $yy2 = substr($yy1, 2);
         //var_dump($dd2." ".$mm2." ".$yy2);
         if ($dd == $dd2 && $yy == $yy2 && $mm == $mm2) {
             $invoiceidd = "C" . $dd2 . $mm2 . $yy2 . ($invDescIdNo + 1);
             //var_dump($invoiceidd);
             return $invoiceidd;
         } else {
             $invoiceidd = "C" . $dd2 . $mm2 . $yy2 . "1";
             return $invoiceidd;
         }
     } else {
         $tz = 'Asia/Dhaka';
         $timestamp = time();
         $dt = new \DateTime("now", new \DateTimeZone($tz));
         //first argument "must" be a string
         $dt->setTimestamp($timestamp);
         //adjust the object to correct timestamp
         $Today = $dt->format('d.m.Y');
         $explodToday = explode(".", $Today);
         $mm2 = $explodToday[1];
         $dd2 = $explodToday[0];
         $yy1 = $explodToday[2];
         $yy2 = substr($yy1, 2);
         $invoiceidd = "C" . $dd2 . $mm2 . $yy2 . "1";
         //var_dump($invoiceidd);
         return $invoiceidd;
     }
 }
 public function getConfirm($invoiceId)
 {
     $stock = StockInvoice::where('invoice_id', '=', $invoiceId)->first();
     $stock->confirmation = 1;
     $stock->save();
     return Redirect::to('stocks/index');
 }
 private function insertStockData($stockInvoces, $import, $invoiceId)
 {
     $stockInvoces->branch_id = $import->branch_id;
     $stockInvoces->status = 'Activate';
     $stockInvoces->user_id = Session::get('user_id');
     $stock_invoices_check = StockInvoice::where('invoice_id', '=', $invoiceId)->get();
     if (empty($stock_invoices_check[0])) {
         $stockInvoces->save();
     }
 }
 public function getSale($invoice_id)
 {
     $saleDetails = SAleDetail::where('invoice_id', '=', $invoice_id)->get();
     $sale = Sale::where('invoice_id', '=', $invoice_id)->get();
     $temp = 0;
     $stockInvoiceId = StockInvoice::generateInvoiceId();
     foreach ($saleDetails as $saleDetail) {
         //$stock->status = "Activate";
         //           $stockDetails->branch_id = Input::get('branch_id');
         //           $stockDetails->product_id = Input::get('product_id');
         //           $stockDetails->entry_type = Input::get('entry_type');
         //           $stockDetails->product_type = Input::get('product_type');
         //           $stockDetails->stock_info_id = Input::get('stock_info_id');
         //           $stockDetails->remarks = Input::get('remarks');
         //           $stockDetails->invoice_id = Input::get('invoice_id');
         //           $stockDetails->quantity = Input::get('product_quantity');
         $stock_Count = StockCount::where('product_id', '=', $saleDetail->product_id)->where('stock_info_id', '=', $saleDetail->stock_info_id)->get();
         if (!empty($stock_Count[0])) {
             if ($stock_Count[0]->product_quantity >= $saleDetail->quantity) {
             } else {
                 $temp++;
                 Session::flash('message', 'You Dont have enough products in Stock');
             }
         } else {
             $temp++;
             Session::flash('message', 'You Dont have This products in This Stock');
         }
     }
     if ($temp == 0) {
         foreach ($saleDetails as $saleDetail) {
             $stockInvoces = new StockInvoice();
             $stockInvoces->branch_id = $saleDetail->branch_id;
             $stockInvoces->status = 'Activate';
             $stockInvoces->remarks = '';
             $stockInvoces->user_id = Session::get('user_id');
             $stockInvoces->invoice_id = $stockInvoiceId;
             $stock_invoices_check = StockInvoice::where('invoice_id', '=', $stockInvoiceId)->get();
             if (empty($stock_invoices_check[0])) {
                 $stockInvoces->save();
             }
             $stock = new StockDetail();
             $stock->branch_id = $saleDetail->branch_id;
             $stock->product_id = $saleDetail->product_id;
             $stock->product_type = $saleDetail->product_type;
             $stock->quantity = $saleDetail->quantity;
             $stock->entry_type = "StockOut";
             $stock->remarks = $saleDetail->remarks;
             $stock->invoice_id = $stockInvoiceId;
             $stock->stock_info_id = $saleDetail->stock_info_id;
             //$stock->status = "Activate";
             //           $stockDetails->branch_id = Input::get('branch_id');
             //           $stockDetails->product_id = Input::get('product_id');
             //           $stockDetails->entry_type = Input::get('entry_type');
             //           $stockDetails->product_type = Input::get('product_type');
             //           $stockDetails->stock_info_id = Input::get('stock_info_id');
             //           $stockDetails->remarks = Input::get('remarks');
             //           $stockDetails->invoice_id = Input::get('invoice_id');
             //           $stockDetails->quantity = Input::get('product_quantity');
             $stock_Count = StockCount::where('product_id', '=', $saleDetail->product_id)->where('stock_info_id', '=', $saleDetail->stock_info_id)->get();
             if (!empty($stock_Count[0])) {
                 if ($stock_Count[0]->product_quantity >= $stock->quantity) {
                     $stock_Count[0]->product_quantity = $stock_Count[0]->product_quantity - $stock->quantity;
                     //$stock->save();
                     $stock_Count[0]->save();
                     $stock->save();
                     $sale[0]->is_sale = 1;
                     $sale[0]->save();
                     //Session::flash('message', 'Stock has been Successfully Created && Product Quantity Subtracted');
                 } else {
                     Session::flash('message', 'You Dont have enough products in Stock');
                 }
             } else {
                 Session::flash('message', 'You Dont have This products in This Stock');
             }
         }
     }
     //        if($temp == 0) {
     //            foreach($saleDetails as $saleDetail)
     //            {
     //                $stock = new Stock();
     //                $stock->branch_id = $saleDetail->branch_id;
     //                $stock->product_id = $saleDetail->product_id;
     //                $stock->product_type = $saleDetail->product_type;
     //                $stock->product_quantity = $saleDetail->quantity;
     //                $stock->entry_type = "StockOut";
     //                $stock->remarks = $saleDetail->remarks;
     //                $stock->user_id = Session::get('user_id');
     //                $stock->stock_info_id = $saleDetail->stock_info_id;
     //                $stock->status = "Activate";
     //
     //                $stockCount = StockCount::where('product_id','=',$saleDetail->product_id)
     //                    ->where('stock_info_id','=',$saleDetail->stock_info_id)
     //                    ->get();
     //
     //
     //
     //                if(!empty($stockCount[0])) {
     //
     //                    if ($stockCount[0]->product_quantity >= $saleDetail->quantity) {
     //
     //                        $stockCount[0]->product_quantity = $stockCount[0]->product_quantity - $saleDetail->quantity;
     //                        $stock->save();
     //                        $stockCount[0]->save();
     //                        $sale[0]->is_sale=1;
     //                        $sale[0]->save();
     //                        //Session::flash('message', 'Stock  has been Successfully Balanced.');
     //                    }
     //                }
     //            }
     //
     //        }
     return Redirect::to('sales/index');
 }