/// <summary>
        /// Get incomeOrder with a new Id
        /// The IncomeOrder should Have The main info of thist variables:
        /// SupplierId , DataTimeOfTheOrder, StoreId, StaffId,TotalPrice
        /// </summary>
        /// <param name="incomeOrder"></param>
        /// <param name="db"></param>
        /// <returns></returns>
        public static IncomeOrderModel GetEmptyIncomeOrderFromTheDatabase(IncomeOrderModel incomeOrder, string db)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnVal(db)))
            {
                var p = new DynamicParameters();
                p.Add("@SupplierId", incomeOrder.Supplier.Id);
                if (!string.IsNullOrWhiteSpace(incomeOrder.BillNumber))
                {
                    p.Add("@BillNumber", incomeOrder.BillNumber);
                }
                else
                {
                    p.Add("@BillNumber", null);
                }

                p.Add("@TotalPrice", incomeOrder.GetTotalPrice);
                p.Add("@Date", incomeOrder.Date);
                p.Add("@StoreId", incomeOrder.Store.Id);
                p.Add("@StaffId", incomeOrder.Staff.Id);

                if (!string.IsNullOrWhiteSpace(incomeOrder.Details))
                {
                    p.Add("@Details", incomeOrder.Details);
                }
                else
                {
                    p.Add("@Details", null);
                }

                p.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
                connection.Execute("dbo.spIncomeOrder_CreateIncomeOrder", p, commandType: CommandType.StoredProcedure);
                incomeOrder.Id = p.Get <int>("@Id");
            }
            return(incomeOrder);
        }
Exemple #2
0
        /// <summary>
        /// Calculate the Total Paid Value if this IncomeOrder
        /// </summary>
        /// <param name="incomeOrder"></param>
        /// <returns></returns>
        public static decimal GetTotalPaid(IncomeOrderModel incomeOrder)
        {
            decimal paid = new decimal();

            foreach (IncomeOrderPaymentModel incomeOrderPayment in incomeOrder.IncomeOrderPayments)
            {
                paid += incomeOrderPayment.Paid;
            }

            return(paid);
        }
Exemple #3
0
 /// <summary>
 /// -OLD- Loop throw each IncomeOrderProduct in the IncomeOrder
 /// save each one in the IncomeOrderProdcut table with tha Id of the IncomeOrder
 /// </summary>
 /// <param name="order"> IncomeOrder Model Has An Id From IncomeOrder.GetEmptyIncomeOrder </param>
 /// <param name="db"> Database Connection Name </param>
 public static void SaveIncomeOrderProductListToTheDatabase(IncomeOrderModel incomeOrder, string db)
 {
     using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnVal(db)))
     {
         foreach (IncomeOrderProductModel incomeOrderProduct in incomeOrder.IncomeOrderProducts)
         {
             var o = new DynamicParameters();
             o.Add("@IncomeOrderId", incomeOrder.Id);
             o.Add("@ProductId", incomeOrderProduct.Product.Id);
             o.Add("@IncomePrice", incomeOrderProduct.IncomePrice);
             o.Add("@Quantity", incomeOrderProduct.Quantity);
             connection.Execute("dbo.spIncomeOrderProduct_Create", o, commandType: CommandType.StoredProcedure);
         }
     }
 }
Exemple #4
0
        /// <summary>
        /// Add the new incomeOrderProduct to the database
        /// return the incomeOrderProduct with the new id
        /// </summary>
        /// <param name="incomeOrderProduct"></param>
        /// <param name="incomeOrder"></param>
        /// <param name="db"></param>
        /// <returns></returns>
        public static IncomeOrderProductModel AddIncomeOrderProductToTheDatabase(IncomeOrderProductModel incomeOrderProduct, IncomeOrderModel incomeOrder, string db)
        {
            using (IDbConnection connection = new System.Data.SqlClient.SqlConnection(GlobalConfig.CnnVal(db)))
            {
                var p = new DynamicParameters();
                p.Add("@IncomeOrderId", incomeOrder.Id);
                p.Add("@ProductId", incomeOrderProduct.Product.Id);
                p.Add("@IncomePrice", incomeOrderProduct.IncomePrice);
                p.Add("@Quantity", incomeOrderProduct.Quantity);
                p.Add("@Id", 0, dbType: DbType.Int32, direction: ParameterDirection.Output);
                connection.Execute("dbo.spIncomeOrderProduct_Create", p, commandType: CommandType.StoredProcedure);
                incomeOrderProduct.Id = p.Get <int>("@Id");
            }

            return(incomeOrderProduct);
        }
Exemple #5
0
 /// <summary>
 /// Calculate the to total not paid price that the supplier of the IncomeORder should take
 /// </summary>
 /// <param name="incomeOrder"></param>
 /// <returns></returns>
 public static decimal GetTotalNotPaid(IncomeOrderModel incomeOrder)
 {
     return(incomeOrder.GetTotalPrice - incomeOrder.GetTotalPaid);
 }