I have this methods, but the information does not reach the database, please help me,I do not know why the information is not sent to the controlle.
When I send the correctly completed data they are not loading to the database, but it does pass through the controller, since it returns to the previous route. The data object can be viewed in the console.
It's the Controller. The controller is fine, because I call it in another section and the information is added correctly.
public function store($data){
$billing=new OSbilling();
$billing->order_id=$data['order_id'];
$billing->billing_number=$data['billing_number'];
$billing->billed_timene=$data['billed_timene'];
$billing->billed_travel=$data['billed_travel'];
$billing->billed_hours=$data['billed_hours'];
$billing->price=$data['price'];
$billing->type=$data['type'];
$billing->created_at=strtotime(Kusher::GetActualDate());
if(isset($data['created_at'])){
$billing->created_at=$data['created_at'];
}
if($billing->save()){
return '200';
}
return '500';
}
When I send the correctly completed data they are not loading to the database, but it does pass through the controller, since it returns to the previous route. The data object can be viewed in the console.
public function postStorefast($obj){
$array=Input::all();
$this->store($array);
$order=OrderService::find(Input::get('order_id'));
$billings=OSbilling::whereRaw('order_id='.$order->id)->get();
$total_hours=0;
foreach ($billings as $key => $billing) {
$total_hours=$total_hours+$billing->billed_hours;;
}
$possible_hours=$order->execute_hours-$total_hours;
if($possible_hours<=0 && $possible_hours >= 0 ){
$OL=new OSorderLogsController();
$log=array(
"order_id"=>$order->id,
"status_id"=>"6",
"user_id"=>Auth::id(),
"notes"=>"");
$OL->postSave($log);
$order->status = 6;
$order->save();
}
return Redirect::back();
}
Here is the HTML
<div class="row">
<div class="col-xs-12">
<div class="block">
<div class="block-title">
<h2>Creación de facturas</h2>
</div>
<div class="block-content">
<div class="row">
<div id="app">
<div class="col-xs-12">
<div class="form-group">
<label class="col-md-2 text-right">Buscar orden (por OS u OSI)</label>
<input type="text" v-model="term" @keyup.enter="search">
<button v-on:click="search">Buscar</button>
</div>
</div>
<div class="col-xs-12 table-responsive" v-if="ordersFound.length > 0">
<hr>
<small>
En esta tabla puedes agregar las ordenes que se van a facturar
</small>
<table class="table table-bordered" >
<thead>
<tr>
<th>OSI</th>
<th>OS</th>
<th>Profesional</th>
<th>Actividad</th>
<th>Desplazamiento real</th>
<th>Valor ARL real</th>
<th>Valor ARL</th>
<th>Horas/Unidades posibles</th>
<th>Selección</th>
</tr>
</thead>
<tbody>
<tr v-for="of in ordersFound">
<td>{[{of.id}]} </td>
<td>{[{of.order_number}]} </td>
<td>{[{of.profesional}]} </td>
<td>{[{of.activity}]} </td>
<td>{[{of.travel_price}]} </td>
<td>{[{of.real_arl_price}]} </td>
<td>{[{of.arl_value_timene}]} </td>
<td> {[{ of.possible_hours}]} </td>
<td><button class="btn btn-success" @click="add(of)">Agregar</button></td>
</tr>
</tbody>
</table>
</div>
<div class="col-xs-12 table-responsive" v-if="ordersSelected.length > 0">
<hr>
<h2>
Ordenes a facturar
</h2>
<small>
En esta tabla puedes modificar los valores de las ordenes
</small>
<div>
<div class="form-group">
<label class="col-md-2 text-right"> Fecha factura</label>
<input type="date" v-model="fechaFactura">
</div>
<div class="form-group">
<label class="col-md-2 text-right"> Número factura</label>
<input type="text" v-model="numeroFactura">
</div>
</div>
<table class="table table-bordered">
<thead>
<tr>
<th>OSI</th>
<th>OS</th>
<th>Profesional</th>
<th>Actividad</th>
<th>Desplazamiento Real</th>
<th>Valor ARL real</th>
<th>Valor ARL tiempo no efectivo</th>
<th>Cantidad Desplazamiento</th>
<th>Número de horas <br>/ Unidades</th>
<th>Valor a facturar</th>
<th>Selección</th>
</tr>
</thead>
<tbody>
<tr v-for="(os, index) in ordersSelected">
<td>{[{os.id}]} </td>
<td>{[{os.order_number}]} </td>
<td>{[{os.profesional}]} </td>
<td>{[{os.activity}]} </td>
<td>{[{os.travel_price}]} </td>
<td>{[{os.real_arl_price}]} </td>
<td>{[{os.arl_value_timene}]} </td>
<td>{[{os.travel_quantity}]} </td>
{{Form::open(array('action'=>'OSbillingsController@postStore'))}}
<td><input class="form-control" type="number" :max="os.possible_hours" min="1" v-model="os.input_hours"> </td>
<!-- Calculo facturacion total -->
<td>
{[{(os.input_hours * os.real_arl_price) +(os.arl_value_timene*os.hours_not_efective) +(os.travel_quantity*os.travel_price) }]}
<input
class="form-control"
type="hidden" min="0" v-model="os.input_price"> </td>
<td><input type="checkbox" v-model="os.selected"></td>
</tr>
<tr>
<td colspan="9" class="text-right">
<button class="btn btn-default" @click="bill">Crear facturas</button>
</td>
</tr>
</table>
{{Form::close()}}
</div>
</div>
</div>
</div>
</div>
</div>
</div>
And here is vue js
<script src="https://unpkg.com/vue@2.4.4/dist/vue.js "></script>
<script src="https://cdn.jsdelivr.net/npm/vue-resource@1.3.4"></script>
<script>
var app = new Vue({
el: '#app',
data: {
term: '',
ordersFound: [],
ordersSelected: [],
numeroFactura: '',
fechaFactura: '',
},
methods: {
search: function () {
this.$http.post('http://safe.potatokoosh.com/cpanel/order/billings/ordersearch', {term: this.term})
.then(ok => {
this.ordersFound = ok.body
if (ok.body.length < 1) {
alert("No se encontró nada facturable.")
}
})
},
calcPrice: function (order, index) {
order = order[index]
let arl_price = (parseInt(order.real_arl_price) * this.ordersSelected[index].input_hours)
let timene_price = (parseInt(order.arl_value_timene) * parseInt(order.hours_not_efective))
this.ordersSelected[index].input_price = ((this.ordersSelected[index].possible_hours * order.real_arl_price) +(order.arl_value_timene*order.hours_not_efective) +(order.travel_quantity*order.travel_price))
},
add: function (order) {
var found = 0
for(var i = 0; i < this.ordersSelected.length; i++) {
if (this.ordersSelected[i].id === order.id) {
found++
break
}
}
if (found === 0) {
this.ordersSelected.push(order)
}
this.calcPrice(this.ordersSelected, found);
},
bill: function (order, index) {
if (this.numeroFactura === '') {
return alert("Por favor escribe número de factura")
}
if (this.fechaFactura === '') {
return alert("Por favor escribe fecha de factura")
}
var obj = {};
for(var i = 0; i < this.ordersSelected.length; i++) {
if (this.ordersSelected[i].selected !== true) {
continue
}
if (this.ordersSelected[i].input_hours < 1) {
this.ordersSelected[i].selected = false
continue
}
if (this.ordersSelected[i].input_price < 1) {
this.ordersSelected[i].selected = false
continue
}
obj = {
'order_id': this.ordersSelected[i].id,
'billing_number': this.numeroFactura,
'billed_hours': this.ordersSelected[i].input_hours,
'price': this.ordersSelected[i].input_price,
'created_at': this.fechaFactura,
'type': '1'
},
console.log(obj)
this.$http.post('http://safe.potatokoosh.com/cpanel/order/billings/postStorefast')
.then(function (response) {
that.ordersSelected[i] = response.data;
}).
catch(function (error) {
console.log('Error: ' + error)});
}
this.ordersSelected = []
this.ordersFound = []
this.term = ''
this.numeroFactura = ''
this.fechaFactura = ''
}
},
delimiters: ["{[{","}]}"]
})
</script>
You can just in your request
add the json which is your v-model in the body request, but the request have to be POST, PUT, PATCH.
in axios you do something like this
axios.post('/users', this.user).then(response => response);
In your controller, you will receive it like an array because laravel parses the object. and you can get it like this
$request->user['name'] //for example