How to insert multiple data into the database using a single method - javascript

As the title suggests, I would like to insert data into 03 tables (products, products_order, orders).
Indeed, I would like
1- I want to recover the stock_products and subtract from the order's quantity of products (stock_actuel = stock_actuel - quantity)
2- In the products_order table, we record the identifier the product identifier with the price of each product, the quantity and the total amount.
3-In the order table, we record the order informations such as number, dates etc.
All this in a single store or create.
here is what i did and it doesn't work.
public function store(Request $request, $id)
{
// update stockproduit
// $stockproduit = Produits::find($id);
$produits = collect($request->produits->stockproduit)->transform(function ($stockproduit){
$stockproduit['stock_actuel'] = $stockproduit['stock_actuel'] - $stockproduit['quantity'];
$stockproduit->update();
});
$commande = new RestauCommande;
$commande->produit_id = 'cmde-' .$id;
$produits = collect($request->produits)->transform(function ($produit) {
$produit['total'] = $produit['quantity'] * $produit['prix'];
return new CommandesProduits($produit);
});
$data = $request->except('produits');
// $data->made_by = $request->get('users_id');
// $data->tables_id = $request->get('users_id');
$data['sub_total'] = $produits->sum('total');
$data['grand_total'] = $data['sub_total'] - $data['remise'];
// $data['clients_id'] = $client->id->$request->get('clients_id');
$data = RestauCommande::create($data);
$commande->produits()->saveMany($produits);
return response()
->json([
'La Commande a été créée avec succès' => true,
'id' => $commande->id,
]);
}
My vue
<b-modal
id="modalShow"
title="Commandes"
ref="myModalRefProduit"
hide-footer
size="lg"
>
<div>
<div class="container mt-12">
<div class="row col-md-14">
<form #submit.prevent="store" enctype="multipart/form-data">
<div class="col-md-12 mx-auto">
<table
class="table table-responsive rounded table-striped table-sm"
>
<thead>
<tr>
<th scope="col">#</th>
<!-- <th scope="col"></th> -->
<th scope="col">Produit</th>
<th scope="col">Quantité</th>
<th scope="col">Prix</th>
<th scope="col">Total</th>
<th scope="col">Action</th>
</tr>
</thead>
<tbody>
<tr v-for="(produit, id) in cart" v-bind:key="produit.id">
<th scope="row">{{ id + 1 }}</th>
<td>
<input
class="form-control"
type="hidden"
placeholder=""
v-model="users_id"
required
autofocus
/>
</td>
<td>{{ produit.nom }}</td>
<td>
<center>{{ produit.quantity }}</center>
</td>
<td>{{ produit.prix }}</td>
<td>{{ produit.quantity * produit.prix }}</td>
<td>
<div class="cart-icons">
<button v-on:click="cartPlusOne(produit)">
<i class="fa fa-plus"></i>
</button>
<button v-on:click="cartMinusOne(produit, id)">
<i class="fa fa-minus"></i>
</button>
<button
v-on:click="cartRemoveItem(id)"
title="supprimer le produit"
>
<i class="fa fa-trash"></i>
</button>
</div>
</td>
</tr>
<tr class="font-weight-bold">
<td style colspan="4" align="right">Total</td>
<td>{{ cartTotalAmount }}</td>
</tr>
</tbody>
</table>
<div class="container">
<div class="row">
<div class="col-md-4 pl-0">
<b-button
v-on:click="store()"
variant="outline-success btn-sm btn-block"
>Valider</b-button
>
</div>
<div class="col-md-4 pr-0">
<b-button
v-on:click="$refs.myModalRefProduit.hide()"
variant="outline-dark btn-sm btn-block"
>Annuler</b-button
>
</div>
</div>
</div>
</div>
</form>
</div>
</div>
</div>
<center></center>
</b-modal>
the script
store() {
// alert ('test')
const data = new FormData();
data.append(
"made_by",
document.querySelector("meta[name='users_id']").getAttribute("content")
);
axios
.post("/api/commander", data )
.then((response) => {
this.produits = response.data;
// this.loading = false;
// this.form.reset();
// window.location = response.data.redirect;
})
// .then(location.reload())
.catch(function (error) {
console.log(error);
});
},
This is the error i get
Error: Request failed with status code 405
Thank you in advance.

Related

Unable to edit data on the same view page laravel

I want to update the business hour on the same page. There are other answer that I review in the stackoverflow but I still cannot manage. Help really appreciated.
Model
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class Hour extends Model
{
public $table = 'biz_hour';
protected $primaryKey = 'day_id';
protected $fillable = [
'day_id', 'day_name', 'start_time', 'end_time', 'day_off'
];
public $timestamps = false;
}
Controller
public function update(Request $request, Hour $biz_hour)
{
$request->validate([
'start_time' => 'required',
]);
$start_time = \App\Models\Hour::find($biz_hour);
['start_time' => $request->start_time];
foreach($biz_hour as $biz_hour){
$start_time->save();
}
return redirect('start_time');
//$biz_hour->update($request->all());
//return redirect()->route('biz_hour.index');
}
Biz_hour.blade.php
<div class="table-responsive">
<table class="table">
<thead class="text-uppercase">
<tr>
<th scope="col">Day</th>
<th scope="col">Start Time</th>
<th scope="col">End Time</th>
<th scope="col">is Day off?</th>
</tr>
</thead>
#foreach($biz_hour as $biz_hour)
<form action="{{ route('biz_hour.update',$biz_hour->day_id) }}" method="POST">
#csrf
#method('PUT')
<tbody>
<tr>
<th scope="row"><br>{{$biz_hour->day_name}}</th>
<td><div class="form-group">
<input class="form-control" type="time" value={{ Carbon::parse($biz_hour->start_time)->format('h:i') }} name="start_time"></div>
</td>
<td><div class="form-group">
<input class="form-control" type="time" value={{$biz_hour->end_time}} name="end_time"></div>
</td>
<td><br><label class="switch">
<input type="checkbox">
<span class="slider round"></span>
</label></td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
<div class="main-content-inner">
<div class="col-lg-6 mt-5">
<button type="submit" class="btn btn-primary mb-3" name="upload">Save</button>
</div>
</div>
</form>
After clicking save button, the page only refresh but the data is not sent to the database. Thanks in advance.
Update is not done because you actually didn't assign the new start_time for the start_time you wanted to update.
Try this
public function update(Request $request, Hour $biz_hour)
{
$request->validate([
'start_time' => 'required',
]);
$start_time = \App\Models\Hour::find($biz_hour);
$start_time->start_time => $request->start_time;
foreach($biz_hour as $biz_hour){
$start_time->save();
}
return redirect()->back()->with('status', 'updated');
}

Defer in my app.js in laravel is not letting my javascript code work

Even though I have my entire code in javascript until I remove the defer from my app.js it does not work. Is there a reason for it?
Edit
I added my whole blade.php file here the javascript in at the bottom is being extended from my add.blade.php file. The javascript code is also yielded from my add.blade.php file.
Here is my blade file
#extends('layouts.app')
#section('style')
<link href="{{ asset('css/Admin/sql-data-viewer.css') }}" rel="stylesheet">
#endsection
#section('content')
<?php ?>
<section class="data-viewer">
<div class="d-flex justify-content-between px-3">
<h3>Select Banner to change</h3>
<button type="button" class="btn add-data text-white rounded-pill">Add Banner <i class="fas fa-plus"></i></button>
</div>
<form method="post">
#csrf
#method('DELETE')
#if(session()->has('message'))
<div class="alert alert-success">
{{ session()->get('message') }}
</div>
#endif
<div class="delete pl-3 mt-3 mb-3">
<label for="deleteSelected">Action:</label>
<select name="deleteSelected" id="deleteSelected" class="#error('deleteSelected') is-invalid #enderror" name="deleteSelected" >
<option disabled selected>---------</option>
<option>Delete Selected Banner</option>
</select>
<button formaction="{{ route('banners.delete') }}" type="submit" class="go" id="deleleGo" onclick="deleteBtn()">Go</button>
<span id="selected">0</span> of {{$showCounts}} selected
#error('deleteSelected')
<span class="invalid-feedback" role="alert">
<strong>{{ $message }}</strong>
</span>
#enderror
</div>
<table class="table table-hover table-striped table-dark">
<div id="selectError"><p>You must check at least one checkbox</p></div>
<thead>
<tr>
<th scope="col"><input type="checkbox" id="checkHead" class="selectall"></th>
<th scope="col">Id</th>
<th scope="col">Image</th>
<th scope="col">Caption Heading</th>
<th scope="col">Caption Description</th>
</tr>
</thead>
<tbody>
#foreach ($banners as $banner)
<tr>
<th scope="row"><input type="checkbox" name="ids[]" class="selectbox" value="{{ $banner->id }}" onchange="change()"></th>
<td onClick="location.href='{{URL::current()}}/{{Str::slug($banner->id) }}/edit'" style="cursor: pointer">{{$banner->id}}</td>
<td onClick="location.href='{{URL::current()}}/{{Str::slug($banner->id) }}/edit'" style="cursor: pointer"><img src="/storage/{{$banner->Banner_Image}}" alt="{{$banner->Caption_Heading}}" class="img-thumbnail" width="70px" height="100px"></td>
<td onClick="location.href='{{URL::current()}}/{{Str::slug($banner->id) }}/edit'" style="cursor: pointer">{{$banner->Caption_Heading}}</td>
<td onClick="location.href='{{URL::current()}}/{{Str::slug($banner->id) }}/edit'" style="cursor: pointer">{{$banner->Caption_Description}}</td>
</tr>
#endforeach
</tbody>
</table>
</form>
</section>
#endsection
#section('script')
<script>
const all = document.getElementById("checkHead");
all.addEventListener('click',toogle);
function toogle() {
const isChecked = all.checked;
Array.from(document.getElementsByTagName('input')).forEach(element =>{
element.checked = isChecked;
});
}
function change(){
var total = document.getElementsByClassName('selectbox').length;
var number = document.querySelectorAll('.selectbox:checked').length;
if(total === number){
document.getElementById("checkHead").checked = true;
} else{
document.getElementById("checkHead").checked = false;
}
document.getElementById("selected").innerHTML = number;
}
function deleteBtn(){
checked = document.querySelectorAll("input[type=checkbox]:checked").length;
if(!checked) {
var a = document.getElementById("selectError").style.display = "block";
return false;
}
};
</script>
#endsection
It is probably happening because you are trying to get an element which is not there at the time this script runs. Make sure you include the javascript on bottom of the page if you don't want to defer it.

appending url with $location.search() and setting true ng-show expression not working simultaneously

As I have an input field for search having ng-model as 'search'. for this input i update url with $location.search({search:$scope.search}). after updating url i set expression under ng-show to true.
this thing are not working simultaneously.
js
app.controller('searchCtrl', function ($rootScope, $scope, $http, $cookies, $localStorage, $filter, $routeParams, $location, $window, $route) {
console.log("in search ctrl");
$scope.srchfn = function () {
console.log("in srchfn")
console.log("localStorage.getItem('user_name') " + localStorage.getItem('user_name'));
var srchdata = {
user_name: localStorage.getItem('user_name'),
token: localStorage.getItem('token'),
};
srchdata.search_trans = $scope.search;
$http.post('http://...../search_trans', srchdata).
success(function (data, status, header, config) {
console.log("data: %j", data);
if (data.success == 1) {
console.log("search success");
console.log("data.trans.tranid " + data.trans.tranid);
$scope.tranid = data.trans.tranid;
$scope.dateTime = data.trans.dateTime;
$scope.refid = data.trans.refid;
$scope.amount = data.trans.amount;
$scope.status = data.trans.status;
$scope.type = data.trans.type;
$scope.creditVpa = data.trans.creditVpa;
$scope.remarks = data.trans.remarks;
$scope.debitVpa = data.trans.debitVpa;
$scope.debitAccount = data.trans.debitAccount;
// I am asking about these next two lines
$scope.showuser = true;
$location.search({ search: srchdata.search_trans });
}
else if (data.success == -1) {
console.log("transactions not found");
}
else {
console.log("there is some error");
}
}).
error(function (data, status, header, config) {
console.log("data: %j", data);
});
};
});
html
<div class="row">
<div style="margin-left: 24px;" ng-hide="hidesearch1" ng-controller='searchCtrl'>
<h3 style="padding-left: 15px;">Dashboard</h3>
<form class="form-inline" ng-submit="srchfn()">
<div class="container">
<div class="row">
<div class="col-md-4">
<div class="form-group">
<input type="text" ng-model="search" style="border-radius: 0;" class="form-control sbsz searchcls" placeholder="Search" ng-enter="srchfn()">
<button type="submit" style="visibility: hidden;"></button>
</div>
</div>
</div>
</div>
</form>
<table class="table table-striped table-bordered" style="max-width: 1100px; margin-top: 20px; margin-left: 15px;" ng-show="showuser" id="searchTblId">
<thead>
<tr>
<th ng-click="sort('id')">
Id
<span class="glyphicon sort-icon" ng-show="sortKey=='id'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>
</th>
<th ng-click="sort('date')">
Date
<span class="glyphicon sort-icon" type="date" ng-show="sortKey=='date'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>
</th>
<th ng-click="sort('crn')">
CRN
<span class="glyphicon sort-icon" ng-show="sortKey=='crn'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>
</th>
<th ng-click="sort('amount')">
Amount
<span class="glyphicon sort-icon" ng-show="sortKey=='amount'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>
</th>
<th ng-click="sort('status')">
Status
<span class="glyphicon sort-icon" ng-show="sortKey=='status'" ng-class="{'glyphicon-chevron-up':reverse,'glyphicon-chevron-down':!reverse}"></span>
</th>
</tr>
</thead>
<tbody>
<tr ng-click="isOpen=!isOpen">
<td>{{tranid}}</td>
<td><span style="font-weight:600;">{{dateTime | date : "dd.MM.y"}}&nbsp&nbsp&nbsp</span>{{dateTime | date : "h:mm a"}}</td>
<td>{{refid}}</td>
<td class="dsbld">{{amount | currency:"₹"}}</td>
<!--<td>{{user.status}}</td>-->
<td style="text-align:center;" ng-class="{
'rcolr': status === 'F',
'ocolr': status === 'P',
'gcolr': status === 'C'}">
{{status}}
</td>
</tr>
<tr ng-if="isOpen">
<td colspan="6">
<!-- <h3>user details are as:</h3> -->
<div class="u_detail01">
<div class="item l">
<strong>Mobile No:</strong>{{mobile_no}}<br>
<strong>Type:</strong> {{type}}<br>
<strong>credit vpa:</strong> {{creditVpa}}<br>
</div>
<div class="item r">
<strong>Debit vpa:</strong> {{debitVpa}}<br>
<strong>Debit Account:</strong> {{debitAccount}}<br>
<strong>Remarks:</strong> {{remarks}}
<!-- <button ng-click="opnfn()">Note</button> -->
</div>
</div>
<!-- <div ng-if="noteClicked" style="align-self:center;">
<textarea cols="20" rows="5" placeholder="Notes" autofocus="true" style="width: 400px; border: 1px solid #ccc; margin-top: 20px; padding: 15px 10px; outline: none;"></textarea><br/>
<button ng-click="savefn()">Save</button>
<label id="sent to server"></label>
</div> -->
</td>
</tr>
</tbody>
</table>
</div>
</div>

Shows the live search result/s in the table using AJAX/Jquery in Laravel

I would like to implement the live search through my table but I'm not using datatable in here. I copied the js that I've found in the internet and when I tried to search something, it doesnt return any result. Why? Can anyone help me?
My view
#extends('layout.default')
#section('content')
<br><br>
<br><br>
<div class="container">
<h4>Live Search using Laravel</h4>
<div class="col-md-6 col-lg-6 pull-right" >
<p class="pull-right">Click on the zip logo to download the file:<p>
<a href="/live_search_laravel.zip" download="live-search(laravel).zip">
<br><br>
<img border="0" src="/images/ziplogo.png" class="pull-right" alt="AngularJS" width="50" height="42">
</a>
</div>
</div>
<br>
<div class="col-md-7 col-lg-6 pull-right">
<input type="text" class = "form-control" id="search" placeholder="Live Search"></input>
</div>
<br><br>
<div class="col-md-12 col-sm-6 col-xs-12">
<div class="x_panel">
<div class="x_content">
<table class="table table-hover">
<thead>
<tr>
<th>
Change File Name
</th>
<th>
Original File Name
</th>
<th>
File Extension
</th>
<th>
Category
</th>
</tr>
</thead>
<tbody>
#foreach($data as $filename)
<tr>
<td>
{{ $filename->rs_filename }}
</td>
<td>
{{ $filename->original_filename }}
</td>
<td>
{{ $filename->file_extension }}
</td>
<td>
#if($filename->category=="1")
{{ "Laravel" }}
#endif
</td>
</tr>
#endforeach
</tbody>
</table>
</div>
</div>
</div>
#stop
#section('select2_js')
<script type="text/javascript" src="/js/live_search_laravel/select2.js"></script>
#stop
My JS
$("#search").on("keyup", function() {
var value = $(this).val();
$("table tr").each(function(index) {
if (index !== 0) {
$row = $(this);
var id = $row.find("th:first").text();
if (id.indexOf(value) !== 0) {
$row.hide();
}
else {
$row.show();
}
}
});
});

AngularJs filter search after user press 'entrer'

I am going to implement a searchbox wherein user will input the string on the searchbox and will be filtered when button is clicked/submitted/pressed enter.
I am retrieving so much data from my database and it makes my app loads very slow. So I need to make the search not retrieve all the data (causes logged of computer).
Ok .. So here's my view
<div data-ng-app="PRApp">
<div data-ng-controller="PRCtrl" class="ng-scope">
<div class="row">
<div class="row">
<form data-ng-submit="changeDate()">
<div class="col-xs-4">
<h4><b>Search by Date :</b></h4>
<div class="col-xs-10">
<div class="input-group">
<span class="input-group-addon">
<span data-ng-click="show=!show" class="glyphicon glyphicon-calendar"></span>
</span>
<input data-show="{{show}}" type="text" name="filter_fromDate" datepicker data-ng-model="filter_fromDate"
class="form-control" placeholder="mm/dd/yyyy" data-ng-minlength="10" />
</div>
</div>
<br />
<br />
<div class="col-xs-10">
<div class="input-group">
<span class="input-group-addon">
<span data-ng-click="show=!show" class="glyphicon glyphicon-calendar"></span>
</span>
<input data-show="{{show}}" type="text" name="filter_toDate" datepicker data-ng-model="filter_toDate"
class="form-control" placeholder="mm/dd/yyyy" data-ng-minlength="10" />
</div>
</div>
<br />
<br />
<div class="col-xs-10">
<input type="submit" class="btn btn-primary btn-sm" value="GO" />
</div>
</div>
</form>
<div class="col-xs-4">
</div>
<div class="col-xs-4">
<div class="col-xs-10">
<h4><b>Search :</b></h4>
<div class="input-group">
<span class="input-group-addon">
<span class="glyphicon glyphicon-search"></span>
</span>
<input type="text" name="search" data-ng-model="filter" class="form-control" placeholder="Search here (e.g. 151234 or Pille)" />
</div>
<br />
</div>
<div class="btn-group" role="group">
<button data-ng-click="exportData()" class ="btn btn-warning"><i class ="glyphicon glyphicon-export"></i>Export to Excel </button>
</div>
</div>
</div>
</div>
<h2 data-ng-show="models == null ">Loading ...</h2>
<br />
<div id="exportable">
<table data-ng-show="models != null" class="table table-striped table-bordered table-hover"
id="PRTable">
<tr class="titlerow">
<th>
<a href="#" data-ng-click="sorting='RequestDate'; reverse = !reverse">PR Date <span
data-ng-show="sorting == 'RequestDate'"></span>
</a>
</th>
<th>
<a href="#" data-ng-click="sorting='RequestID '; reverse = !reverse">PR # <span data-ng-show="sorting == 'RequestID '">
</span>
</a>
</th>
<th>
<a href="#" data-ng-click="sorting='PARNumber '; reverse = !reverse">PAR # <span
data-ng-show="sorting == 'PARNumber '"></span>
</a>
</th>
<th>
<a href="#" data-ng-click="sorting='ProgramName '; reverse = !reverse">Program <span
data-ng-show="sorting == 'ProgramName '"></span>
</a>
</th>
<th>
<a href="#" data-ng-click="sorting='FullName '; reverse = !reverse">Requestor <span
data-ng-show="sorting == 'FullName '"></span>
</a>
</th>
<th>
<a href="#" data-ng-click="sorting='PONo'; reverse = !reverse">PO #
</a>
</th>
<th>
<a href="#" data-ng-click="sorting='StatusID '; reverse = !reverse">PRStatus<span
data-ng-show="sorting == 'StatusID '"></span>
</a>
</th>
<th>
<a href="#" data-ng-click="sorting='Amount '; reverse = !reverse">Total Amount<span
data-ng-show="sorting == 'Amount '"></span>
</a>
</th>
<th>
<a href="#" data-ng-click="sorting='Amount '; reverse = !reverse">Last Action<span
data-ng-show="sorting == 'Amount '"></span>
</a>
</th>
</tr>
<tr data-ng-repeat="model in models | orderBy: sorting:reverse | filter : filter ">
<td>{{jsonDatetotext(model.RequestDate) | date:'MM/dd/yyyy'}}</td>
<td>
<a href="#" data-toggle="modal" data-target="#basicModalContent" data-ng-click="getSelectedPR(model)">
{{model.RequestID}}
</a>
</td>
<td>{{model.PARNumber }}</td>
<td>{{model.ProgramName }}</td>
<td>{{model.FullName }}</td>
<td>{{model.PONo}}</td>
<td>{{StatusList[model.StatusID] | uppercase}}</td>
<td class="totalAmount"><span class="pull-right">{{model.TotalAmount | number:2}}</span>
</td>
<td>{{model.LastBy | lowercase}}</td>
</tr>
<tr>
<td colspan="9" ><h3><b>Total Amount : </b><span class="pull-right">{{models | sumbykey : 'TotalAmount' | number:2}}</span></h3> </td>
</tr>
</table>
</div>
<!-- /.Modal Na ni -->
<div class="modal fade" id="basicModalContent" tabindex="-1" role="dialog" aria-labelledby="myModalLabel"
aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
</div>
<div class="modal-body" id="exportablePRItems">
<div class="table-responsive">
<table class="table table-striped table-bordered table-hover" id="dataTables-example">
<thead>
<tr>
<th>PR #
</th>
<th>Item Description
</th>
<th>Supplier
</th>
<th>Account
</th>
<th>Currency
</th>
<th>Amount
</th>
<th>(USD) Amount
</th>
</tr>
</thead>
<tbody data-ng-repeat="selectedPR in selectedModal.ItemList">
<tr>
<td>{{selectedPR.RequestID}}</td>
<td>{{selectedPR.PartDesc}}</td>
<td>{{selectedPR.SupplierID }}</td>
<td>{{selectedPR.AccountType}}</td>
<td>{{selectedPR.CurrName }}</td>
<td data-ng-model="amount" class="amount">{{selectedPR.Amount | number:2}}</td>
<td>{{selectedPR.AmountUSD}}</td>
</tr>
</tbody>
<tr>
<td><span class="pull-right"><i class="glyphicon glyphicon-plus-sign"></i></span></td>
<td colspan="6"><b>Total Amount : </b>{{selectedModal.ItemList | sumbykey : 'Amount' | number:2}} </td>
</tr>
</table>
</div>
<footer>
<br />
<button data-ng-click="exportDataItems()" class ="btn btn-warning"><i class ="glyphicon glyphicon-export"></i>Export Item </button></footer>
</div>
<div class="modal-footer">
<button id="btnModalCancel" type="button" class="btn btn-default" data-dismiss="modal">
Close</button>
</div>
</div>
<!-- /.modal-content -->
<!-- /.modal-dialog -->
</div>
</div>
</div>
</div>
.
And here is my angular:
<script type="text/javascript">
var PRApp = angular.module('PRApp', []);
PRApp.controller('PRCtrl', ['$scope', '$http', function (scope, http) {
http.get('GetList').success(function (data) {
scope.models = data;
scope.selectedModal = null;
});
scope.getStatus = http.get('GetStatusList').success(function (status) {
scope.StatusList = status
});
scope.getSelectedPR = function (PR) {
scope.selectedModal = PR;
};
//scope.totalPrice = function () {
// var total = 0;
// var amounts = this.closest('td').find('.totalAmount').text();
// angular.forEach($scope.models.data, function (item) {
// total += $(amounts).parseInt;
// })
// return total;
//}
// scope.searchHere = 'Search here ... '
scope.isEmpty = function (items) {
return angular.isArray(items) && items.length === 0;
};
function GetbyDate(fr, t) {
var from = new Date(t)
};
scope.changeDate = function () {
scope.models = null;
http.get('GetReportList?from=' + scope.filter_fromDate + '&to=' + scope.filter_toDate).success(
function (data) {
scope.models = data;
});
}
scope.jsonDatetotext = function (jsondate) {
// jsondate format: /Date(#############)/
// substr(6) will remove '/Date('
// parseInt will convert remaing string '#############' to int and ignores ')/'
return new Date(parseInt(jsondate.substr(6)));
};
scope.exportData = function () {
var date = new Date();
var d = date.getFullYear() + '-' + date.getMonth() + 1 + '-' + date.getDate();
var blob = new Blob([document.getElementById('exportable').innerHTML], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
});
saveAs(blob, "Report_" + d + ".xls");
};
scope.exportDataItems = function () {
var date = new Date();
var d = date.getFullYear() + '-' + date.getMonth() + 1 + '-' + date.getDate();
var blob = new Blob([document.getElementById('exportablePRItems').innerHTML], {
type: "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet;charset=utf-8"
});
saveAs(blob, "Items_"+ d +".xls");
};
}]);
PRApp.directive('datepicker', function () {
return {
require: 'ngModel',
link: function (scope, el, attr, ngModel) {
attr.$observe("show", function (val) {
if (val == 'true') {
$(el).datepicker("show");
}
else {
$(el).datepicker("hide");
}
});
$(el).datepicker({
minDate: '-5Y',
maxDate: 0,
dateFormat: 'MM d, yy',
onSelect: function (dateText) {
scope.$apply(function () {
ngModel.$setViewValue(dateText);
});
}
});
}
};
});
PRApp.filter('sumbykey', function () {
return function (data, key) {
if (typeof (data) === 'undefined' || typeof (key) === 'undefined') {
return 0;
}
var sum = 0.00;
for (var i = data.length - 1; i >= 0; i--) {
sum += parseFloat(data[i][key]);
}
return sum;
};
});
</script>
You can use server side paging. See the example here

Categories