/* PRINT **********************************************************************************************************************************************/ // GET: Payments/Print public ActionResult Print(Guid?id) { if (id == null || !UserAccountsController.getUserAccess(Session).Payments_View) { return(RedirectToAction(nameof(HomeController.Index), "Home")); } PayrollPaymentsModel model = get(Session, (Guid)id); ViewBag.InvoiceHeaderText = new BranchesController().get(Helper.getActiveBranchId(Session)).InvoiceHeaderText; ViewData["PayrollPaymentItems"] = PayrollPaymentItemsController.get(Session, null, model.Id, null, null, null); ViewBag.TotalAmount = model.Amount; return(View(model)); }
public void add(List <PayrollPaymentItemsModel> items, PayrollPaymentsModel model) { if (items.Count == 0) { return; } Guid?PayrollPayments_Id = null; foreach (PayrollPaymentItemsModel item in items) { if (item.PayrollPayments_Id != null) { PayrollPayments_Id = item.PayrollPayments_Id; break; } } string log = string.Format("Payment of {0:N0} on {1:dd/MM/yy}", model.Amount, model.Timestamp); if (!string.IsNullOrWhiteSpace(model.Notes)) { log += ", Notes: " + model.Notes; } if (PayrollPayments_Id != null) { log = "Additional " + log; model = get(Session, (Guid)PayrollPayments_Id); } else { model.Id = Guid.NewGuid(); 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 PayrollPayments 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 PayrollPayments (Id, No, Timestamp, UserAccounts_Id, Amount, Branches_Id, Approved, Cancelled, CancelNotes, Notes) VALUES(@Id,@NewNo,@Timestamp,@UserAccounts_Id,@Amount,@Branches_Id,@Approved,@Cancelled,@CancelNotes,@Notes); ", DBConnection.getSqlParameter(PayrollPaymentsModel.COL_Id.Name, model.Id), DBConnection.getSqlParameter(PayrollPaymentsModel.COL_Timestamp.Name, model.Timestamp), DBConnection.getSqlParameter(PayrollPaymentsModel.COL_No.Name, model.No), DBConnection.getSqlParameter(PayrollPaymentsModel.COL_UserAccounts_Id.Name, model.UserAccounts_Id), DBConnection.getSqlParameter(PayrollPaymentsModel.COL_Amount.Name, model.Amount), DBConnection.getSqlParameter(PayrollPaymentsModel.COL_Branches_Id.Name, model.Branches_Id), DBConnection.getSqlParameter(PayrollPaymentsModel.COL_Approved.Name, model.Approved), DBConnection.getSqlParameter(PayrollPaymentsModel.COL_Cancelled.Name, model.Cancelled), DBConnection.getSqlParameter(PayrollPaymentsModel.COL_CancelNotes.Name, model.CancelNotes), DBConnection.getSqlParameter(PayrollPaymentsModel.COL_Notes.Name, model.Notes) ); } ActivityLogsController.Add(db, Session, model.Id, log); PayrollPaymentItemsController.update_PayrollPayments_Id(db, Session, model.Id, items); db.SaveChanges(); }