public bool ValidatePaymentType(Data.PaymentTypeData ptd) { // in order to have a valid payment type, all of the required controls // must have a value and all of the payment methods must be valid. if (ptd.payment_type_id == 63) { // validate the transaction number is valid (control_id 87) foreach (var c in ptd.control_data) { if (c.control_id == 87) { var transaction_number = c.value.Trim(); if (transaction_number.Length == 0) { c.error_text = "No transaction number entered"; return(false); } if (transaction_number.Length != 13 || transaction_number.IndexOf('-', 0) != 2 || transaction_number.IndexOf('-', 3) != 7) { c.error_text = "Invalid deposit transaction number format. Please check you entered the receipt number correctly"; return(false); } c.error_text = CheckIfValidSecurityDeposit(transaction_number); if (c.error_text.Length > 0) { return(false); } } } } foreach (Data.ControlData cd in ptd.control_data) { if (!controls_dict[cd.control_id].Validate(cd)) { return(false); } } // this object has been deemed unnecessary //var PaymentMethod = new PaymentMethod(); foreach (Data.PaymentMethodData pmd in ptd.payment_method_data) { if (!pmd.ValidateNew()) { return(false); } } return(true); }
private bool SaveNewReceipt() { var param = new DynamicParameters(); param.Add("@transaction_id", dbType: DbType.Int64, direction: ParameterDirection.Output); param.Add("@created_by_employee_id", created_by_employee_id); param.Add("@username", created_by_username); param.Add("@department_id", department_id); //param.Add("@display_name", display_name); param.Add("@created_by_employee_ip_address", created_by_ip_address); param.Add("@transaction_type", transaction_type.ToUpper()); param.Add("@created_by_display_name", created_by_display_name); param.Add("@received_from", received_from); param.Add("@comment", comment); if (transaction_type.ToUpper() == "R") { total_cash_amount = 0; total_check_count = 0; total_check_amount = 0; param.Add("@child_transaction_id", child_transaction_id); } else { param.Add("@child_transaction_id", null); } param.Add("@total_cash_amount", total_cash_amount); param.Add("@total_check_amount", total_check_amount); param.Add("@total_check_count", total_check_count); StringBuilder query = new StringBuilder(); query.AppendLine(@" USE ClayFinancial; -- SAVE TRANSACTION DATA -- if EXEC ClayFinancial.dbo.insert_new_transaction_data @transaction_id OUTPUT, @department_id, @created_by_employee_id, @transaction_type, @child_transaction_id, @username, @created_by_employee_ip_address, @created_by_display_name, @received_from, @comment, @total_cash_amount, @total_check_amount, @total_check_count; "); query.AppendLine(PaymentTypeData.GetSavePaymentTypeDataQuery()); query.AppendLine(PaymentMethodData.GetSavePaymentMethodsQuery()); query.AppendLine(ControlData.GetSaveControlDataQuery()); // add this to update total_cash_amount, total_check_amount, total_check_count fields if (transaction_type != "C") { query.AppendLine(GetUpdateTransactionTotals(true)); } else { param.Add("@deposit_transaction_id", deposit_transaction_id); query.AppendLine(@" UPDATE data_transaction SET child_transaction_id = @transaction_id WHERE transaction_id = @deposit_transaction_id "); if ((int)my_access >= (int)UserAccess.access_type.finance_level_two) { query.AppendLine(@" OR transaction_id = @transaction_id "); } } // CREATE DATA TABLES var paymentTypeDataTable = PaymentTypeData.GetPaymentTypeDataTable(); var controlDataTable = ControlData.GetControlDataTable(); var paymentMethodDataTable = PaymentMethodData.GetPaymentMethodDataTable(); try { foreach (PaymentTypeData ptd in payment_type_data) { // add payment type data to its data table paymentTypeDataTable.Rows.Add ( ptd.payment_type_id, ptd.payment_type_index ); // add payment method data to its data table foreach (PaymentMethodData pmd in ptd.payment_method_data) { paymentMethodDataTable.Rows.Add ( pmd.cash_amount, pmd.check_amount, pmd.check_count, pmd.check_number, pmd.check_from, pmd.paying_for, ptd.payment_type_id, ptd.payment_type_index ); } // add payment type control data to Control data table foreach (ControlData cd in ptd.control_data) { controlDataTable.Rows.Add ( null, cd.control_id, cd.value, ptd.payment_type_id, ptd.payment_type_index ); } } // add department control data foreach (ControlData cd in department_control_data) { controlDataTable.Rows.Add ( this.department_id, cd.control_id, cd.value, null, null ); } // add tvp to parameter list param.Add("@ControlData", controlDataTable.AsTableValuedParameter("dbo.ControlData")); param.Add("@PaymentMethodData", paymentMethodDataTable.AsTableValuedParameter("dbo.PaymentMethodData")); param.Add("@PaymentTypeData", paymentTypeDataTable.AsTableValuedParameter("dbo.PaymentTypeData")); var tran = Constants.Exec_Query(query.ToString(), param, Constants.ConnectionString.ClayFinancial); transaction_id = param.Get <long>("@transaction_id"); if (transaction_id == -1) { error_text = "There was an issue saving the receipt."; return(false); } return(true); } catch (Exception ex) { new ErrorLog(ex, query.ToString()); return(false); } }
public static TransactionData GetTransactionData(string calling_function, long transaction_id = -1, int employee_id = -1, UserAccess ua = null) { if (transaction_id == -1) { new ErrorLog("Did not get a transaction_id", "", "calling function: " + calling_function, "", ""); } var param = new DynamicParameters(); param.Add("@transaction_id", transaction_id); param.Add("@my_employee_id", ua.employee_id); var query = new StringBuilder(); query.AppendLine(GetTransactionDataQuery()); query.AppendLine(" AND (transaction_id = @transaction_id"); query.AppendLine(" OR transaction_id IN (SELECT child_transaction_id FROM data_transaction WHERE transaction_id = @transaction_id AND child_transaction_id IS NOT NULL))"); if (ua.current_access == UserAccess.access_type.basic) { param.Add("@my_department_id", ua.my_department_id); query.AppendLine(" AND (department_id = @my_department_id OR (created_by_employee_id = @my_employee_id AND can_modify = 1))"); } // TODO: FILL THE REST OF THE TRANSACTION DATA. var transactions = Constants.Get_Data <TransactionData>(query.ToString(), param, Constants.ConnectionString.ClayFinancial); TransactionData td = null; TransactionData child_td = null; foreach (TransactionData t in transactions) { if (t.transaction_id == transaction_id) { td = t; } else { child_td = t; } //if (t.child_transaction_id.HasValue && t.child_transaction_id == transaction_id) child_td = t; } //if(td.child_transaction_id.HasValue && td.child_transaction_id.Value != td.transaction_id) //{ // td.GetChildTransaction(ua.employee_id); //} if (td == null) { new ErrorLog("transaction_id: " + transaction_id, "There was an issue retrieving the transaction.", "Calling function: " + calling_function, "", query.ToString()); return(new TransactionData("There was an issue retrieving the transaction.")); } td.child_transaction = child_td; if (td.transaction_type == "R") { var controls = ControlData.GetActiveTransactionControls(td.transaction_id); var payment_methods = PaymentMethodData.GetActiveTransactionPaymentMethods(td.transaction_id); td.department_control_data = (from c in controls where c.department_id.HasValue select c).ToList(); td.payment_type_data = PaymentTypeData.Get(td.transaction_id, controls, payment_methods); } else { td.GetDepositReceipts(employee_id); if (td.transaction_type == "D" && !td.child_transaction_id.HasValue) { td.can_accept_deposit = false; // here we're going to indicate to the client that it should or should not allow // the viewer to accept this deposit. // the criteria is as follows: // the deposit creator must be different from the receipt creator // the deposit creator must have a lower access level than the receipt creator // or the receipt creator must be finance level 2 or higher if (td.created_by_display_name != ua.display_name) { if ((int)ua.current_access < (int)UserAccess.access_type.finance_level_two) // this will handle the MIS access level { var deposit_creator_ua = UserAccess.GetUserAccessByDisplayName(td.created_by_display_name); td.can_accept_deposit = ((int)deposit_creator_ua.current_access < (int)ua.current_access); } else { td.can_accept_deposit = true; } } } } return(td); }
public static bool SaveChangePaymentTypeData(List <PaymentTypeData> payment_type_data, UserAccess ua, string user_ip_address) { if (!payment_type_data.Any()) { return(false); } var transaction_id = payment_type_data.FirstOrDefault().transaction_id; var param = new DynamicParameters(); param.Add("@transaction_id", payment_type_data.FirstOrDefault().transaction_id); param.Add("@created_by_employee_id", ua.employee_id); param.Add("@username", ua.user_name); param.Add("@created_by_employee_ip_address", user_ip_address); param.Add("@created_by_display_name", ua.display_name); StringBuilder query = new StringBuilder(); query.AppendLine(@" USE ClayFinancial; DECLARE @new_payment_type_data_id BIGINT = -1; DECLARE @transaction_type VARCHAR(1); SET @transaction_type = (SELECT transaction_type FROM data_transaction WHERE transaction_id = @transaction_id); "); query.AppendLine(PaymentTypeData.GetSavePaymentTypeDataQuery()); query.AppendLine(PaymentMethodData.GetSavePaymentMethodsQuery()); query.AppendLine(ControlData.GetSaveControlDataQuery()); // this query needs to be included in order to recalculate the totals for the transaction. // we may need to consider having a transaction_data_changes table to track changes query.AppendLine(TransactionData.GetUpdateTransactionTotals(true)); // CREATE DATA TABLES var controlDataTable = ControlData.GetControlDataTable(); var paymentTypeDataTable = PaymentTypeData.GetPaymentTypeDataTable(); var paymentMethodDataTable = PaymentMethodData.GetPaymentMethodDataTable(); try { foreach (PaymentTypeData ptd in payment_type_data) { // add payment type data to its data table paymentTypeDataTable.Rows.Add ( ptd.payment_type_id, ptd.payment_type_index ); // add payment method data to its data table foreach (PaymentMethodData pmd in ptd.payment_method_data) { paymentMethodDataTable.Rows.Add ( pmd.cash_amount, pmd.check_amount, pmd.check_count, pmd.check_number, pmd.check_from, pmd.paying_for, ptd.payment_type_id, ptd.payment_type_index ); } // add payment type control data to Control data table foreach (ControlData cd in ptd.control_data) { controlDataTable.Rows.Add ( null, cd.control_id, cd.value, ptd.payment_type_id, ptd.payment_type_index ); } } // add tvp to parameter list param.Add("@ControlData", controlDataTable.AsTableValuedParameter("dbo.ControlData")); param.Add("@PaymentMethodData", paymentMethodDataTable.AsTableValuedParameter("dbo.PaymentMethodData")); param.Add("@PaymentTypeData", paymentTypeDataTable.AsTableValuedParameter("dbo.PaymentTypeData")); return(Constants.Exec_Query(query.ToString(), param, Constants.ConnectionString.ClayFinancial) > -1); } catch (Exception ex) { new ErrorLog(ex, query.ToString()); return(false); } }