*Thanks Robert *
*it works fine now but please i have an problem with other Angular Project
and hope that you can help me with that, i have create an invoice with
angular and pass data throw API Controller - i store data in list to let me
save it on database when i need, but when i open new invoice from my PC and
add item's on it before i save it to database i open another invoice from
other PC and when it's open i got the item's from invoice in my pc on it
too - i don't know how to set it to open with empty array in each PC to be
works as it should be ?*
*Angular Code:*
(function () {
var app = angular.module('jqanim', []);
app.controller('InvoiceController', function ($scope, $http) {
$scope.tax = 0.00;
$scope.PercentageDiscount = 0.00;
$scope.MoneyDiscount = 0.00;
$scope.Total = 0.00;
$scope.save = function () {
$http.post("/api/customerService/Post",
$scope.item).success(function (data) {
$scope.orders.push(data);
// Clear AutoComplete Text
$("#Products").data("kendoAutoComplete").value("");
if (window.event.keyCode == 13) {
$("#ProductID").focus();
}
$('#ProductID').prop('readonly', false);
});
};
$scope.saveInvoice = function () {
$http.post("/api/customerService/SaveInvoice", $scope.invoice)
.success(function (data) {
// Clear AutoComplete Text
$("#Customers").data("kendoAutoComplete").value("");
$scope.invoice = [];
$scope.orders = [];
$scope.tax = 0.00;
$scope.PercentageDiscount = 0.00;
$scope.MoneyDiscount = 0.00;
alertify.set('notifier', 'position', 'top-left');
alertify.success('تÙ
ØÙØž اÙÙاتÙرة', 3);
})
.error(function (data) {
alertify.set('notifier', 'position', 'top-right');
alertify.error('ÙÙجد خطأ', 2);
return;
});
};
$scope.remove = function (id, index) {
$http.delete("/api/customerService?id=" + id).success(function
(data) {
$scope.orders.splice(index, 1);
});
};
$http.get("/api/CustomerService/getDetails").success(function
(data) {
$scope.orders = data;
});
$scope.keypress = function (id) {
if (window.event.keyCode == 13) {
$http.get("/api/CustomerService/GetProduct?id=" +
id).success(function (data) {
angular.forEach(data, function (item) {
$("#Products").val(item.ProductName).trigger('change');
$("#SellPrice").val(item.sell_price).trigger('change');
$("#Stock").val(item.stock).trigger('change');
$("#Quantity").focus();
});
});
}
};
});
})();
*my view code:*
<form method="post" ng-submit="save(); item={}">
<table class="table table-striped table-bordered" dir="rtl">
<tr>
<th class="text-center">ÙÙد اÙصÙÙ</th>
<th class="text-center">إسÙ
اÙصÙÙ</th>
<th class="text-center">اÙÙÙ
ÙØ©</th>
<th class="text-center">اÙسعر</th>
<th class="text-center">اÙرصÙد</th>
<th class="text-center">اÙإجÙ
اÙÙ</th>
<th></th>
</tr>
<tr>
<td style="vertical-align:middle;">
@*<input type="number" step="any" class="k-textbox
trv-parameter-editor-number" id="ProductID" ng-model="item.ProductID"
ng-keypress="keypress(item.ProductID,$index)">*@
<input id="ProductID" type="text" placeholder="Øدد
اÙÙÙد" class="text-center form-control" style="width:100px;
font-weight:bold" />
</td>
<td align="center" style="vertical-align:middle;">
<div>
@(Html.Kendo()
.AutoComplete()
.Name("Products")
.DataTextField("ProductName")
.Events(events =>
events.Select("ProductSelect"))
.MinLength(1)
.HtmlAttributes(new { style = "width:450px;
font-weight:bold", ng_model = "item.ProductName" })
.Placeholder("Ø¥Ùتؚ جزء Ù
٠إسÙ
اÙصÙÙ")
.Filter("contains")
.Delay(1)
.DataSource(source =>
{
source.Custom()
.ServerFiltering(true)
.ServerPaging(true)
.Type("aspnetmvc-ajax") //Set this
type if you want to use DataSourceRequest and ToDataSourceResult instances
.Transport(transport =>
{
transport.Read("Virtualization_Read", "Home");
})
.Schema(schema =>
{
schema.Data("Data") //define
the
[data](http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-schema.data)
option
.Total("Total"); //define
the
[total](http://docs.telerik.com/kendo-ui/api/javascript/data/datasource#configuration-schema.total)
option
});
})
.Virtual(v =>
v.ItemHeight(26).ValueMapper("valueMapper"))
)
</div>
</td>
<td align="center" style="vertical-align:middle;">
<input ng-readonly="item.ProductID == '' ||
item.ProductID == null" id="Quantity" name="Quantity" class="text-center
form-control" ng-model="item.Quantity" value="1" size="4" ng:required
ng:validate="integer" placeholder="Øدد اÙÙÙ
ÙØ©" style="width:100px;
font-weight:bold">
</td>
<td align="center" style="vertical-align:middle;">
<input ng-readonly="true" id="SellPrice"
class="text-center form-control" ng-model="item.SellPrice" value="0.00"
ng:required ng:validate="number" size="6" style="width:100px;
font-weight:bold">
</td>
<td align="center" style="vertical-align:middle;">
<input ng-readonly="true" id="Stock" class="text-center
form-control" ng-model="item.Stock" value="0.00" ng:required
ng:validate="number" size="6" style="width:100px; font-weight:bold">
</td>
<td class="text-center" style="vertical-align:middle;
width:100px; font-weight:bold;">
{{item.SellPrice * item.Quantity | currency}}
@Html.TextBox("Total_Item", null, new { ng_model =
"item.Total_Item", @style = "display:none;" })
</td>
<td align="center" style="vertical-align:middle;">
<input ng-disabled="item.Quantity > item.Stock ||
item.Quantity == 0 || item.Quantity == null || item.SellPrice == null"
type="submit" name="submitbtn" value="إضاÙØ©" class="btn btn-primary"
style="font-weight:bold;" />
</td>
</tr>
<tr>
<td colspan="7" class="text-center" style="color:red;
font-weight:bold;">
<div ng-show="item.Quantity > item.Stock">رصÙد اÙصÙÙ Ùا
ÙÙÙÙ</div>
<div ng-show="item.Quantity == 0">غÙر Ù
سÙ
ÙØ ØšÙÙ
ÙØ© Ø£ÙÙ
Ù
Ù 1</div>
</td>
</tr>
</table>
</form>
<br />
@* Details *@
<table class="table table-striped table-bordered" align="center"
dir="rtl" ng-show="(orders).length">
<tr>
<th class="text-center" style="width:100px;">ÙÙد اÙصÙÙ</th>
<th class="text-center">إسÙ
اÙصÙÙ</th>
<th class="text-center" style="width:150px;">اÙÙÙ
ÙØ©</th>
<th class="text-center" style="width:150px;">اÙسعر</th>
<th class="text-center" style="width:150px;">اÙإجÙ
اÙÙ</th>
<th style="width:150px;"></th>
</tr>
<tr ng-repeat="ord in orders">
<td align="center" style="vertical-align:middle;
font-weight:bold;">
{{ord.ProductID}}
</td>
<td align="center" style="vertical-align:middle;
font-weight:bold;">
{{ord.ProductName}}
</td>
<td align="center" style="vertical-align:middle;
font-weight:bold;">
{{ ord.Quantity}}
</td>
<td align="center" style="vertical-align:middle;
font-weight:bold;">
{{ord.SellPrice}}
</td>
<td class="text-center" style="vertical-align:middle;
font-weight:bold;">
{{ord.SellPrice * ord.Quantity | currency}}
</td>
<td align="center" style="vertical-align:middle;">
<input type="submit" name="submitbtn" value="x" class="btn
btn-danger" ng-click="remove(ord.ProductID,$index)"
style="font-weight:bold;" />
</td>
</tr>
</table>
*API Controller Code:*
readonly Model1 db = new Model1();
private static List<Order_Details_VM> listOfOrders;
private static List<Product> listOfProducts;
int statusCode = 0;
public CustomerServiceController()
{
listOfProducts = null;
if (listOfProducts == null)
{
listOfProducts = new List<Product>();
foreach (var pro in db.Products)
{
Product p = new Product();
p.ProductID = pro.ProductID;
p.ProductName = pro.ProductName;
p.sell_price = pro.sell_price;
p.stock = pro.stock;
listOfProducts.Add(p);
}
}
if (listOfOrders == null)
{
listOfOrders = new List<Order_Details_VM>();
}
}
public IHttpActionResult GetDetails()
{
return Ok(listOfOrders);
}
public IHttpActionResult GetProduct(int id)
{
var selectedProduct = listOfProducts.Where(i => i.ProductID ==
id).ToList();
return Ok(selectedProduct);
}
public IHttpActionResult Post(Order_Details_VM newOrderDetails)
{
if (newOrderDetails != null)
{
listOfOrders.Add(newOrderDetails);
return Ok(newOrderDetails);
}
return null;
}
public IHttpActionResult SaveInvoice(Order_VM newOrderMaster)
{
// save on header table to get invoice id
if (newOrderMaster != null)
{
var order = new Order();
order.CustomerID = newOrderMaster.CustomerID;
order.OrderDate = newOrderMaster.OrderDate;
order.Freight = (decimal)newOrderMaster.Total;
//order.type = "ØšÙع";
db.Orders.Add(order);
db.SaveChanges();
newOrderMaster.OrderID = order.OrderID;
}
// loop throw items list to check Stock & add to database with
invoice no
foreach (var item in listOfOrders)
{
item.OrderID = newOrderMaster.OrderID;
// ckeck Stock in online database not in the list
var model = db.Products.Find(item.ProductID);
if (model.stock >= item.Quantity)
{
model.stock = model.stock - item.Quantity;
db.Entry(model).State = EntityState.Modified;
statusCode = 200;
}
else
{
statusCode = 404;
}
if (statusCode == 200)
{
// save to DB
var orderdetails = new Order_Detail();
orderdetails.OrderID = item.OrderID;
orderdetails.ProductID = item.ProductID;
orderdetails.UnitPrice = (decimal)item.SellPrice;
orderdetails.Quantity = item.Quantity;
orderdetails.Quantity_buy = item.Quantity;
orderdetails.Total = item.Total_Item;
db.Order_Details.Add(orderdetails);
db.SaveChanges();
}
else
{
var x = item.ProductName;
}
}
listOfOrders.Clear();
return Ok();
}
public Order_Details_VM Delete(int id)
{
if (id > 0)
{
// here by productis
var selectedCustomer = listOfOrders.Find(p => p.ProductID
== id);
if (selectedCustomer != null)
{
listOfOrders.Remove(selectedCustomer);
return selectedCustomer;
}
} return new Order_Details_VM();
}
*sorry for long code but hope that you can help me please ?*
*Thanks a lot ....*
Post by Robert STAICU*Ok so i made a filter cause you can include it in BaseModule. Think using
5 modules "MenuModule", "TableModule", "UserModule", "LoginModule",
"ExampleModule".*
*You can use this filter in any of 5 modules i exampled to you. You can
have a "BaseModule" that can include filter "orderObjectBy" and all of your
modules are gonna inherit that. *
*My filter basically transform $scope.customersByMonth from object to
array and then sort it. "function(items, filter, reverse)" params are
gonna be:*
*1. $scope.customersByMonth[month] = array of object of month
(params.items)*
*2. 'MyDate' = date of that month(a[0][filter] && b[0][filter]) //filter
being "MyDate" (params.filter)*
*3. if reverse = false or true
(params.reverse)*
*You can console.log() them to see what is going on.*
*I know you can order your data from server, but in this case your data
will be ordered by the front-end. You can do both of them or just one of
them.*
*I suggest doing both of them if you want to make a directive with this
and public it. If you use just for your own scope you can do the server
stuff.*
*If any rows isn't clear just ask. I'll be glad to answer. *
*Have a nice day*
--
You received this message because you are subscribed to the Google Groups "AngularJS" group.
To unsubscribe from this group and stop receiving emails from it, send an email to angular+***@googlegroups.com.
To post to this group, send email to ***@googlegroups.com.
Visit this group at http://groups.google.com/group/angular.
For more options, visit https://groups.google.com/d/optout.