示例#1
0
 public function registermbank(Request $request)
 {
     $v = new Voucher();
     $v->vnno = $request->input('vnno');
     $v->vdate = CommonController::date_format($request->input('vdate'));
     $v->amount = $request->input('amount');
     $v->amount = $request->input('camount');
     $v->status = 1;
     $v->type = 9;
     $v->cid = $request->input('cid');
     $v->userid = $request->input('userid');
     $v->save();
     $LastInsertId = $v->id;
     if ($LastInsertId != NULL) {
         $m = new Vouchermbank();
         $m->vid = $LastInsertId;
         $m->mbankno = $request->input('mbankno');
         $m->cid = $request->input('cid');
         $m->userid = $request->input('userid');
         $m->save();
     }
     $c = new Customersledger();
     $c->rv = $LastInsertId;
     $c->cid = $request->input('cid');
     $c->amount = $request->input('camount');
     $c->save();
     return redirect('voucher');
 }
 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;
     // }
     /*
      */
 }