rowspan="{{cus.MyDate.length+1}}"
<div ng-app="jqanim" ng-controller="ttController"> <table class="table table-bordered"> <tr> <th>CustomerID</th> <th>CustomerName</th> <th>CustomerMonth</th> </tr> <tr ng:repeat="cust in customers"> <td> {{cust.ID}} </td> <td>{{cust.Name}}</td> <td rowspan="{{cus.MyDate.length+1}}"> @* here i need to use rowspan on month value on MyDate ?? *@ {{cust.MyDate | date: "MMMM"}} </td> </tr> </table></div>(function () { var app = angular.module('jqanim', []);
app.controller('ttController', function ($scope, $http) {
$http.get("/api/Test").success(function (data) { $scope.customers = data; });
});})(); private static List<Test> listOfOrders;
public TestController() { if (listOfOrders == null) { listOfOrders = new List<Test> { new Test { ID = 1, Name = "Customer1" , MyDate = new DateTime(2015,01,01)},
new Test { ID = 2, Name = "Customer2" , MyDate = new DateTime(2015,01,01)},
new Test { ID = 3, Name = "Customer3" , MyDate = new DateTime(2015,02,05)},
new Test { ID = 4, Name = "Customer4" , MyDate = new DateTime(2015,01,05)},
new Test { ID = 5, Name = "Customer5" , MyDate = new DateTime(2015,02,05)},
new Test { ID = 6, Name = "Customer6" , MyDate = new DateTime(2015,02,05)},
new Test { ID = 7, Name = "Customer7" , MyDate = new DateTime(2015,02,05)},
new Test { ID = 8, Name = "Customer8" , MyDate = new DateTime(2015,03,05)},
new Test { ID = 9, Name = "Customer9" , MyDate = new DateTime(2015,04,05)} }; } }
public IEnumerable<Test> Get() { return listOfOrders.OrderBy(i => i.MyDate); }$http.get("/api/Test").success(function (data) {
var dataByMonth = [];
data.forEach(itemToMonth);
$scope.customers = dataByMonth;
function itemToMonth(item) {
var month = item.MyDate.getMonth;
dataByMonth[month] = dataByMonth[month] || [];
dataByMonth[month].push(item);
}
});ng-if="$first"
dataByMonth[month] = dataByMonth[month] || []; dataByMonth[month].push(item); item.MyDate = new Date(item.MyDate) var month = item.MyDate.getMonth(); var year = item.MyDate.getFullYear(); dataByMonth[year + '-' + month] = dataByMonth[year + '-' + month] || []; dataByMonth[year + '-' + month].push(item); public IEnumerable<Test> Get() { return listOfOrders.OrderBy(i => i.MyDate).ThenBy(i => i.ID); }(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(); });
}); } };
});})(); <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> 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(); } <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>