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["value_date"]); model.PartyCode = Conversion.TryCastString(reader["party_code"]); model.PriceTypeId = Conversion.TryCastInteger(reader["price_type_id"]); model.ReferenceNumber = Conversion.TryCastString(reader["reference_number"]); model.NonTaxableSales = Conversion.TryCastBoolean(reader["non_taxable"]); model.ShippingCompanyId = Conversion.TryCastInteger(reader["shipper_id"]); model.SalesPersonId = Conversion.TryCastInteger(reader["salesperson_id"]); model.StoreId = Conversion.TryCastInteger(reader["store_id"]); model.ShippingAddressCode = Conversion.TryCastString(reader["shipping_address_code"]); model.StatementReference = Conversion.TryCastString(reader["statement_reference"]); } ProductDetail product = new ProductDetail(); product.ItemCode = Conversion.TryCastString(reader["item_code"]); product.ItemName = Conversion.TryCastString(reader["item_name"]); product.Unit = Conversion.TryCastString(reader["unit_name"]); product.Quantity = Conversion.TryCastInteger(reader["quantity"]); product.Price = Conversion.TryCastDecimal(reader["price"]); product.Amount = product.Quantity * product.Price; product.Discount = Conversion.TryCastDecimal(reader["discount"]); product.ShippingCharge = Conversion.TryCastDecimal(reader["shipping_charge"]); product.Subtotal = product.Amount - product.Discount - product.ShippingCharge; product.TaxCode = Conversion.TryCastString(reader["tax_code"]); product.Tax = Conversion.TryCastDecimal(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); }
public static MergeModel GetMergeModel(Collection <int> ids, TranBook book, SubTranBook subBook) { int rowIndex = 0; if (ids == null) { return(new MergeModel()); } if (ids.Count.Equals(0)) { return(new MergeModel()); } MergeModel model = new MergeModel(); foreach (int tranId in ids) { model.AddTransactionIdToCollection(tranId); } model.Book = book; model.SubBook = subBook; using (NpgsqlConnection connection = new NpgsqlConnection(DbConnection.ConnectionString())) { using (NpgsqlCommand command = SalesQuotation.GetSalesQuotationViewCommand(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["value_date"]); model.PartyCode = Conversion.TryCastString(reader["party_code"]); model.PriceTypeId = Conversion.TryCastInteger(reader["price_type_id"]); model.ReferenceNumber = Conversion.TryCastString(reader["reference_number"]); model.StatementReference = Conversion.TryCastString(reader["statement_reference"]); } ProductDetailsModel product = new ProductDetailsModel(); product.ItemCode = Conversion.TryCastString(reader["item_code"]); product.ItemName = Conversion.TryCastString(reader["item_name"]); product.Unit = Conversion.TryCastString(reader["unit_name"]); product.Quantity = Conversion.TryCastInteger(reader["quantity"]); product.Price = Conversion.TryCastDecimal(reader["price"]); product.Amount = product.Quantity * product.Price; product.Discount = Conversion.TryCastDecimal(reader["discount"]); product.Subtotal = product.Amount - product.Discount; product.Rate = Conversion.TryCastDecimal(reader["tax_rate"]); product.Tax = Conversion.TryCastDecimal(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 += "(" + Conversion.GetBookAcronym(book, subBook) + "# " + string.Join(",", ids) + ")"; } return(model); }