public function remove_feedback(Request $request)
 {
     if ($request->ajax()) {
         $factory_item_id = $request->input('factory_item_id');
         $status = $request->input('status');
         $factory_item = Factoryitem::find($factory_item_id);
         if (!empty($factory_item)) {
             $factory_item->status = $status;
             $factory_item->feedback = "";
             $factory_item->save();
         } else {
             return response()->json(0);
         }
         return response()->json(1);
     }
 }
Beispiel #2
0
 public function return_item_ina_to_act(Request $request)
 {
     if ($request->ajax()) {
         $factory_item_id = $request->input('factory_item_id');
         $factory_item = Factoryitem::find($factory_item_id);
         if ($factory_item !== null) {
             $last_update_factory_item = Factoryitem::where('itemsid', $factory_item->itemsid)->where('salesid', $factory_item->salesid)->where('status', 1)->where('sale_product', 1)->orderBy('id', 'DESC')->first();
             if ($last_update_factory_item !== null) {
                 $last_update_factory_item->salesid = NULL;
                 $last_update_factory_item->sale_product = 0;
                 $last_update_factory_item->save();
                 $factory_item->status = 1;
                 $factory_item->save();
                 return response()->json(1);
                 // return successfully
             } else {
                 return response()->json(2);
                 // Not found last inactive
             }
         } else {
             return response()->json(0);
             //Not found thid product.
         }
     }
 }
 public function register(Request $request)
 {
     $invoice_info = Session::get('physcl_sale_invoice_info');
     $grosstotal = $request->input('gross_total');
     $salesamount = DB::table('sales')->where('customerid', $request->input('customersid'))->where('status', 1)->sum('gamount');
     $receiveamount = DB::table('voucher')->where('cid', $request->input('customersid'))->where('vstatus', 1)->whereIn('type', [3, 4, 6, 7, 8, 9])->sum('amount');
     $creditlimit = DB::table('customers')->where('id', $request->input('customersid'))->first();
     $closebalance = $creditlimit->openbalance + $receiveamount - $salesamount;
     //$total=$closebalance+$grosstotal;
     //echo $closebalance;
     //die();
     // echo 'C-'.$creditlimit->creditlimit.'T-'.$total; die();
     //if($closebalance<=$creditlimit->creditlimit){
     //save sales
     $qnt = $request->input('qnt');
     $rate = $request->input('rate');
     $count_row = 0;
     foreach ($qnt as $key => $value) {
         if ($value != '' && $rate[$key] != '') {
             $count_row++;
         }
     }
     if ($count_row > 0) {
         $customer = Customer::find($request->input('customersid'));
         $serial_no = $request->input('serial_no');
         $discount = $request->input('discount');
         $u = new Physicalsale();
         /*
                          $customer = Customer::find($sales->customerid);
         					if($customer->lastdue==0){
         					$sales->previousdue=$customer->openbalance;
         					}else{
         					 $sales->previousdue=$customer->lastdue;	
         					}
         					$sales->presentbalance=$sales->gamount+$sales->previousdue;
         					$customer->lastdue = $sales->presentbalance;
         					$customer->save();				
         */
         $u->name = $request->input('name');
         $u->salesdate = CommonController::date_format($request->input('sales_date'));
         $u->customerid = $request->input('customersid');
         $u->discount = $request->input('discount');
         $u->userid = $request->input('userid');
         if ($customer->bstatus == 0) {
             $u->previousdue = $customer->openbalance;
         } else {
             $u->previousdue = $customer->lastdue;
         }
         $u->presentbalance = $grosstotal + $u->previousdue;
         $u->save();
         $customer->lastdue = $u->presentbalance;
         $customer->bstatus = 1;
         $customer->save();
         $LastInsertId = $u->id;
         //echo $LastInsertId;
         if ($LastInsertId != NULL) {
             // 	//echo $LastInsertId.'<br>';
             $itemid = $request->input('itemid');
             $qnt = $request->input('qnt');
             $measurementid = $request->input('measurementid');
             $rate = $request->input('rate');
             $amount = $request->input('amount');
             $sum = 0;
             foreach ($itemid as $item => $value) {
                 if ($qnt[$item] != '' && $rate[$item] != '') {
                     $u = new Salesdetails();
                     $u->salesid = $LastInsertId;
                     $u->itemid = $value;
                     $u->quantity = $qnt[$item];
                     $u->mesid = $measurementid[$item];
                     $u->rate = $rate[$item];
                     $u->amount = $amount[$item];
                     $u->userid = $request->input('userid');
                     $u->save();
                     $sum = $sum + $amount[$item];
                     if ($invoice_info[$item]->serial_no_exist == 1) {
                         foreach ($invoice_info[$item]->product_slno as $slno_id) {
                             $factory_item = Factoryitem::find($slno_id);
                             $factory_item->salesid = $LastInsertId;
                             $factory_item->sale_product = 1;
                             $factory_item->save();
                         }
                     } else {
                         $sale_product_item = Item::find($value);
                         $sale_product_item->quantity = $sale_product_item->quantity - $qnt[$item];
                         $sale_product_item->save();
                     }
                     // 	$factory_items = Factoryitem::where('itemsid', $value)
                     // 					->where('status', 1)
                     // 					->where('sale_product', 0)
                     // 					->orderBy('id', 'asc')
                     // 					->take($qnt[$item])
                     // 					->get();
                     // foreach ($factory_items as $fac_item) {
                     // 	$fac_item->salesid = $LastInsertId;
                     // 	$fac_item->sale_product = 1;
                     // 	$fac_item->save();
                     // }
                 }
             }
             $dis = $sum - $discount;
             $c = new Customersledger();
             $c->sv = $LastInsertId;
             $c->cid = $request->input('customersid');
             $c->amount = $dis;
             $c->dc = 0;
             $c->save();
             Physicalsale::where('id', $LastInsertId)->update(array('gamount' => $dis));
         }
         if (Session::has('physcl_sale_invoice_info')) {
             Session::forget('physcl_sale_invoice_info');
             Session::forget('physcl_sale_sub_total');
             Session::forget('physcl_sale_discount');
             Session::forget('physcl_sale_gross_total');
             Session::forget('physcl_sale_serial_no');
             Session::forget('physcl_sale_sales_date');
             Session::forget('physcl_sale_customer');
         }
     } else {
         return Redirect('physicalsales/addnew');
     }
     return Redirect('physicalsales');
     //save sales
     //}else{
     //echo '-S'.$salesamount.'-R'.$receiveamount.'-C'.$creditlimit->creditlimit.'-O'.$creditlimit->openbalance.'<br>';
     //    echo 'Total'.$closebalance.'<br>';
     //	echo 'Your Credit is'.$creditlimit->creditlimit;
     // }
     /*
      */
 }