Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        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);
            }
        }