public void GetChildTransaction(int my_employee_id) { if (!child_transaction_id.HasValue) { return; } var param = new DynamicParameters(); param.Add("@child_transaction_id", child_transaction_id); param.Add("@my_employee_id", my_employee_id); var query = new StringBuilder(); query.AppendLine(GetTransactionDataQuery()) .AppendLine(" AND TD.transaction_id = @child_transaction_id"); var transactions = Constants.Get_Data <TransactionData>(query.ToString(), param, Constants.ConnectionString.ClayFinancial); if (transactions == null) { return; } child_transaction = transactions.First(); }
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); }
private bool ValidateDepartmentControls(Data.TransactionData transactionData) { // things to validate here: // department controls are all required. // every control in controls_dict for this class needs to be present // every control in controls must have a valid value. Dictionary <int, Control> c = new Dictionary <int, Control>(); foreach (ControlData control in transactionData.department_control_data) { c[control.control_id] = controls_dict[control.control_id]; } var controlids = (from cid in transactionData.department_control_data select cid.control_id).ToList(); // This was returning 0 when there was 1. // var distinctControlIds = controlids.Distinct(); // The IEnumerable list did not seem to be working correctly. // Created explicit List<int> variable. List <int> distinctControlIds = new List <int>(); distinctControlIds.AddRange((from id in controlids select id).ToList().Distinct()); // Todo make sure error text is set in the object being passed to this function if (controlids.Count() != distinctControlIds.Count()) { transactionData.error_text = "Invalid department information found."; return(false); } // if this works, it will mean we won't need the two commented out sections // of code. if (!controlids.SequenceEqual(c.Keys)) { transactionData.error_text = "Missing department information"; return(false); } //// let's make sure every department control is present in department_controls //foreach (int key in controls_dict.Keys) //{ // if (!distinctControlIds.Contains(key)) // { // transactionData.error_text = "Missing department information: " + controls_dict[key].label; // return false; // } //} // now we validate each department control foreach (Data.ControlData cd in transactionData.department_control_data) { // if one of our department controls isn't found in our controls_dict object, // it means that the client has an extra control //if (!controls_dict.ContainsKey(cd.control_id)) //{ // transactionData.error_text = "Invalid Department information found."; // return false; //} var control = controls_dict[cd.control_id]; if (!control.Validate(cd)) { transactionData.error_text = "There was a problem with some of the data entered."; return(false); } } // Validate the payment types if (transactionData.payment_type_data.Count(pt => pt.payment_type_id == 62) > 1) { transactionData.error_text = "Can not have two Rental - Security Deposit on the same receipt"; return(false); } foreach (PaymentTypeData ptd in transactionData.payment_type_data) { if (!payment_types_dict[ptd.payment_type_id].ValidatePaymentType(ptd)) { transactionData.error_text = "There was a problem with some of the payment types"; return(false); } } return(true); }
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); } }
public bool SavePaymentMethod() { // AN EDITED METHOD WILL HAVE A REASON AND PRIOR PAYMENT METHOD DATA ID var param = new DynamicParameters(); param.Add("@payment_method_data_id", payment_method_data_id); param.Add("@prior_payment_method_data_id", payment_method_data_id); // changed param.Add("@transaction_payment_type_id", transaction_payment_type_id); param.Add("@transaction_id", transaction_id); param.Add("@cash_amount", cash_amount); param.Add("@check_amount", check_amount); param.Add("@check_count", check_count); param.Add("@check_number", check_number); param.Add("@check_from", check_from); param.Add("@paying_for", paying_for); param.Add("@transaction_type", "R"); param.Add("@reason_for_change", reason_for_change); param.Add("@username", username); //param.Add("@added_after_save", payment_method_data_id == -1); var query = new StringBuilder(); query.AppendLine(@" -- THIS WILL ONLY HAPPEN IF THIS IS AN EDIT BECAUSE @prior ID WILL BE -1 OTHERWISE IF @prior_payment_method_data_id > -1 BEGIN UPDATE data_payment_method SET is_active = 0 WHERE payment_method_data_id = @prior_payment_method_data_id; END INSERT INTO data_payment_method ( prior_payment_method_data_id ,transaction_payment_type_id ,transaction_id ,cash_amount ,check_amount ,check_count ,check_number ,check_from ,paying_for ,is_active ,added_after_save ) VALUES ( CASE WHEN @prior_payment_method_data_id = -1 THEN NULL ELSE @prior_payment_method_data_id END ,@transaction_payment_type_id ,@transaction_id ,@cash_amount ,@check_amount ,@check_count ,@check_number ,@check_from ,@paying_for ,1 -- newest one is always active -- NEW PAYMENT METHODS ARE ALWAYS ADDED AFTER SAVE, Edits are not ,CASE WHEN @prior_payment_method_data_id = -1 THEN 1 ELSE 0 END ) SET @payment_method_data_id = SCOPE_IDENTITY(); INSERT INTO data_changes_payment_method ( original_payment_method_data_id ,new_payment_method_data_id ,modified_by ,reason_for_change ) SELECT ISNULL(original_payment_method_data_id, @prior_payment_method_data_id) ,@payment_method_data_id ,@username ,@reason_for_change FROM data_payment_method D LEFT OUTER JOIN data_changes_payment_method C ON D.payment_method_data_id = C.new_payment_method_data_id WHERE D.payment_method_data_id=@prior_payment_method_data_id; "); query.AppendLine(TransactionData.GetUpdateTransactionTotals(true)); var i = Constants.Exec_Query(query.ToString(), param, Constants.ConnectionString.ClayFinancial); return(i > 0); }