public void add(SaleInvoicesModel model, List <SaleInvoiceItemsModel> SaleInvoiceItems) { model.Branches_Id = Helper.getActiveBranchId(Session); model.Timestamp = Helper.getCurrentDateTime(); model.Due = model.Amount; db.Database.ExecuteSqlCommand(@" -- INCREMENT LAST HEX NUMBER DECLARE @HexLength int = 5, @LastHex_String varchar(5), @NewNo varchar(5) SELECT @LastHex_String = ISNULL(MAX(No),'') From SaleInvoices DECLARE @LastHex_Int int SELECT @LastHex_Int = CONVERT(INT, CONVERT(VARBINARY, REPLICATE('0', LEN(@LastHex_String)%2) + @LastHex_String, 2)) --@LastHex_String length must be even number of digits to convert to int SET @NewNo = RIGHT(CONVERT(NVARCHAR(10), CONVERT(VARBINARY(8), @LastHex_Int + 1), 1),@HexLength) INSERT INTO SaleInvoices (Id, No, Branches_Id, Timestamp, Notes, Customer_UserAccounts_Id, Amount, Due, Cancelled, Approved) VALUES(@Id,@NewNo,@Branches_Id,@Timestamp,@Notes,@Customer_UserAccounts_Id,@Amount,@Due,@Cancelled,@Approved); ", DBConnection.getSqlParameter(SaleInvoicesModel.COL_Id.Name, model.Id), DBConnection.getSqlParameter(SaleInvoicesModel.COL_Branches_Id.Name, model.Branches_Id), DBConnection.getSqlParameter(SaleInvoicesModel.COL_Timestamp.Name, model.Timestamp), DBConnection.getSqlParameter(SaleInvoicesModel.COL_Notes.Name, model.Notes), DBConnection.getSqlParameter(SaleInvoicesModel.COL_Customer_UserAccounts_Id.Name, model.Customer_UserAccounts_Id), DBConnection.getSqlParameter(SaleInvoicesModel.COL_Amount.Name, model.Amount), DBConnection.getSqlParameter(SaleInvoicesModel.COL_Due.Name, model.Due), DBConnection.getSqlParameter(SaleInvoicesModel.COL_Cancelled.Name, model.Cancelled), DBConnection.getSqlParameter(SaleInvoicesModel.COL_Approved.Name, model.Approved) ); ActivityLogsController.AddCreateLog(db, Session, model.Id); db.SaveChanges(); SaleInvoiceItemsController.add(Session, SaleInvoiceItems, model.Id); }
public ActionResult Create(SaleInvoicesModel model, string JsonSaleInvoiceItems, string FILTER_Keyword, string FILTER_PaymentNo, int?FILTER_Cancelled, int?FILTER_Approved, int?FILTER_HasDueAmount, bool?FILTER_chkDateFrom, DateTime?FILTER_DateFrom, bool?FILTER_chkDateTo, DateTime?FILTER_DateTo) { List <SaleInvoiceItemsModel> SaleInvoiceItems = new List <SaleInvoiceItemsModel>(); if (!string.IsNullOrEmpty(JsonSaleInvoiceItems)) { SaleInvoiceItems = JsonConvert.DeserializeObject <List <SaleInvoiceItemsModel> >(JsonSaleInvoiceItems); } string errorMessage = ""; if (ModelState.IsValid) { if (SaleInvoiceItems.Count == 0) { UtilWebMVC.setBootboxMessage(this, "Please add at least 1 item"); } else if (!hasSufficientInventory(SaleInvoiceItems, out errorMessage)) { UtilWebMVC.setBootboxMessage(this, errorMessage); } else { add(model, SaleInvoiceItems); return(RedirectToAction(nameof(Index), new { rss = 1 })); //not working. all filter returns null //return RedirectToAction(nameof(Index), new //{ // FILTER_Keyword = FILTER_Keyword, // FILTER_PaymentNo = FILTER_PaymentNo, // FILTER_Cancelled = FILTER_Cancelled, // FILTER_Approved = FILTER_Approved, // FILTER_chkDateFrom = FILTER_chkDateFrom, // FILTER_DateFrom = FILTER_DateFrom, // FILTER_chkDateTo = FILTER_chkDateTo, // FILTER_DateTo = FILTER_DateTo //}); } } setViewBag(FILTER_Keyword, FILTER_PaymentNo, FILTER_Cancelled, FILTER_Approved, FILTER_HasDueAmount, FILTER_chkDateFrom, FILTER_DateFrom, FILTER_chkDateTo, FILTER_DateTo); ViewData["SaleInvoiceItems"] = SaleInvoiceItems; return(View(model)); }
public JsonResult Ajax_GetDetails(Guid id) { UserAccountRolesModel access = UserAccountsController.getUserAccess(Session); List <SaleInvoiceItemsModel> models = SaleInvoiceItemsController.get_by_SaleInvoices_Id(id); string content = string.Format(@" <div class='table-responsive'> <table class='table table-striped table-bordered'> <!--<thead> <tr> <th>Line</th> <th>Description</th> <th></th> <th></th> <th></th> </tr> </thead>--> <tbody> "); foreach (SaleInvoiceItemsModel model in models) { int voucher = model.VouchersAmount; string subtractions = ""; if (voucher != 0) { subtractions = Util.append(subtractions, string.Format("Voucher: {0:N0}", -1 * voucher), "<br/>"); } if (model.DiscountAmount != 0) { subtractions = Util.append(subtractions, string.Format("Discount: {0:N0}", -1 * model.DiscountAmount), "<br/>"); } if (!string.IsNullOrEmpty(subtractions)) { subtractions += "<br/>"; } string log = model.RowNo.ToString(); if (access.SaleInvoices_TutorTravelCost_View) { log = string.Format("<a href='javascript: void(0)' onclick=\"Log('{0}')\">{1}</a>", model.Id.ToString(), model.RowNo); } string remaining = ""; if (!model.IsClubSubscription) { remaining = string.Format("<br/><strong>Available Hours:</strong> {0:N2}", model.SessionHours_Remaining); } else { DateTime expirationDate = model.StartingDate.AddMonths(model.ExpirationMonth).AddSeconds(-1); int remainingDays = 0; if (expirationDate > DateTime.Now.Date) { remainingDays = (expirationDate - DateTime.Now.Date).Days; } remaining = string.Format("<br/><strong>Expired:</strong> {0:dd/MM/yy} ({1:N0} days)", expirationDate, remainingDays); } content += string.Format(@" <tr> <td class='align-top' style='width:10px;'>{0}</td> <td class='align-top'>{1}{2}{3}{4}</td> <td class='align-top text-right'> Qty: {5:N0} x {6:N0} {7}{8} </td> <td class='align-top text-right'> {9} <strong>{10:N0}</strong> </td> </tr> ", log, model.Description, model.LessonPackages_Id == null ? "" : remaining, !string.IsNullOrWhiteSpace(model.VouchersName) ? string.Format("<br/>Vouchers: {0}", model.VouchersName) : "", !string.IsNullOrWhiteSpace(model.Notes) ? string.Format("<br/>Notes: {0}", model.Notes) : "", model.Qty, model.Price, model.TravelCost > 0 || model.TutorTravelCost > 0 ? string.Format("<br/>Travel: {0:N0}", model.TravelCost) : "", access.SaleInvoices_TutorTravelCost_View && (model.TravelCost > 0 || model.TutorTravelCost > 0) ? string.Format(" (Tutor: {0:N0})", model.TutorTravelCost) : "", subtractions, model.TotalAmount ); } SaleInvoicesModel SaleInvoice = get(id); content += string.Format(@" </tbody></table></div> <div class='mt-2'> <div class='h3 ml-2 float-right font-weight-bold'>TOTAL: {0:N0}</div> {1} </div> ", SaleInvoice.Amount, !string.IsNullOrWhiteSpace(SaleInvoice.Notes) ? string.Format("<div><strong>Notes: </strong>{0}</div>", SaleInvoice.Notes) : "" ); return(Json(new { content = content }, JsonRequestBehavior.AllowGet)); }