Example #1
0
 public void AddViewToCollection(ProductDetail product)
 {
     this.view.Add(product);
 }
Example #2
0
        public static MergeModel GetMergeModel(string catalog, Collection<long> ids, TranBook tranBook, SubTranBook subTranBook)
        {
            int rowIndex = 0;

            if (ids == null)
            {
                return new MergeModel();
            }

            if (ids.Count.Equals(0))
            {
                return new MergeModel();
            }

            MergeModel model = new MergeModel();

            foreach (long tranId in ids)
            {
                model.AddTransactionIdToCollection(tranId);
            }

            model.Book = tranBook;
            model.SubBook = subTranBook;

            using (NpgsqlConnection connection = new NpgsqlConnection(DbConnection.GetConnectionString(catalog)))
            {
                using (NpgsqlCommand command = GetViewCommand(tranBook, subTranBook, ids))
                {
                    command.Connection = connection;
                    command.Connection.Open();
                    NpgsqlDataReader reader = command.ExecuteReader(CommandBehavior.CloseConnection);

                    if (!reader.HasRows)
                    {
                        return new MergeModel();
                    }

                    while (reader.Read())
                    {
                        if (rowIndex.Equals(0))
                        {
                            model.ValueDate = Conversion.TryCastDate(Reader(reader,"value_date"));
                            model.PartyCode = Conversion.TryCastString(Reader(reader,"party_code"));
                            model.PriceTypeId = Conversion.TryCastInteger(Reader(reader,"price_type_id"));
                            model.ReferenceNumber = Conversion.TryCastString(Reader(reader,"reference_number"));
                            model.NonTaxableSales = Conversion.TryCastBoolean(Reader(reader, "non_taxable"));
                            model.ShippingCompanyId = Conversion.TryCastInteger(Reader(reader,"shipper_id"));
                            model.SalesPersonId = Conversion.TryCastInteger(Reader(reader,"salesperson_id"));
                            model.StoreId = Conversion.TryCastInteger(Reader(reader,"store_id"));
                            model.ShippingAddressCode = Conversion.TryCastString(Reader(reader,"shipping_address_code"));
                            model.StatementReference = Conversion.TryCastString(Reader(reader,"statement_reference"));
                        }

                        ProductDetail product = new ProductDetail();

                        product.ItemCode = Conversion.TryCastString(Reader(reader,"item_code"));
                        product.ItemName = Conversion.TryCastString(Reader(reader,"item_name"));
                        product.Unit = Conversion.TryCastString(Reader(reader,"unit_name"));

                        product.Quantity = Conversion.TryCastInteger(Reader(reader,"quantity"));
                        product.Price = Conversion.TryCastDecimal(Reader(reader,"price"));
                        product.Amount = product.Quantity * product.Price;

                        product.Discount = Conversion.TryCastDecimal(Reader(reader,"discount"));
                        product.ShippingCharge = Conversion.TryCastDecimal(Reader(reader,"shipping_charge"));
                        product.Subtotal = product.Amount - product.Discount - product.ShippingCharge;

                        product.TaxCode = Conversion.TryCastString(Reader(reader,"tax_code"));
                        product.Tax = Conversion.TryCastDecimal(Reader(reader,"tax"));
                        product.Total = product.Subtotal + product.Tax;

                        model.AddViewToCollection(product);

                        rowIndex++;
                    }
                }
            }

            if (ids.Count > 0)
            {
                if (!string.IsNullOrWhiteSpace(model.StatementReference))
                {
                    model.StatementReference += Environment.NewLine;
                }

                model.StatementReference += "(" +
                                            Entities.Helpers.TransactionBookHelper.GetBookAcronym(tranBook, subTranBook) +
                                            "# " + string.Join(",", ids) + ")";
            }

            return model;
        }