private void Facturacion_Load(object sender, EventArgs e)
 {
     cmbTipoIdentificacion.DataSource = _billData.GetIdentificationType();
     cmbTipoIdentificacion.ValueMember = "Id";
     cmbTipoIdentificacion.DisplayMember = "Description";
     _bill = new BillModel {
         Id = Guid.NewGuid(),
         BillNumber = _billData.GetBillNumber(),
         DateEvent = DateTime.Now
     };
     lblNumeroFactura.Text = _bill.BillNumber.ToString().PadLeft(8, '0');
     _billTaxes = _billData.GetBillTaxes();
     _billTaxes.ForEach(x => x.IdBill = _bill.Id);
     dtgImpuestos.DataSource = _billTaxes;
     lblGranTotal.Text = "$0,00";
     txtSubTotal.Text = string.Format("{0:0.00}", 0.00);
     txtDescuentoFinal.Text = string.Format("{0:0.00}", 0.00);
     txtDescuentoCliente.Text = string.Format("{0:0.00}", 0.00);
 }
        public BillSaveModel GetBillData(BillModel bill)
        {
            try
            {
                using (FacturandoEntities context = new FacturandoEntities())
                {
                    BillSaveModel result = new BillSaveModel();
                    result.Bill = bill;
                    result.BillDetail = context.BillDetail
                        .Where(x => x.IdBill == result.Bill.Id)
                        .Select(x => new BillDetailModel
                        {
                            Id = x.Id,
                            IdBill = x.IdBill,
                            IdProduct = x.IdProduct.Value,
                            Product = string.Concat(x.Product.Description, " ", x.Product.UnitMeasure.Description),
                            Quantity = x.Quantity,
                            Total = x.Total,
                            UnitPrice = x.UnitPrice != null ? x.UnitPrice.Value : 0
                        }).ToList();

                    result.Client = context.Client
                        .Where(x => x.Id == result.Bill.IdClient)
                        .Select(x => new ClientModel
                        {
                            Id = x.Id,
                            Adress = x.Address,
                            DateEvent = x.DateEvent != null ? x.DateEvent.Value : DateTime.MinValue,
                            DiscountPercent = x.DisccountPercent,
                            Email = x.Email,
                            IdentificationNumber = x.IdentificationNumber,
                            IdIdentificationType = x.IdIdentificationType.Value,
                            Name = x.Name,
                            Phone = x.Phone
                        }).FirstOrDefault();

                    result.BillTaxes = context.BillTaxes
                        .Where(x => x.IdBill == result.Bill.Id)
                        .Select(x => new BillTaxesModel
                        {
                            Id = x.Id,
                            Description = x.Tax.Description,
                            IdBill = x.IdBill.Value,
                            IdTax = x.IdTax.Value,
                            PercentageValue = x.Tax.PercentageValue,
                            Total = x.Total
                        }).ToList();

                    return result;

                }
            }
            catch (Exception)
            {
                throw;
            }
        }
        private void ClearControls()
        {
            _billData = new BillData();
            _inventoryData = new InventoryData();
            _client = null;
            _billDetail = new List<BillDetailModel>();
            _bill = new BillModel();
            _billTaxes = new List<BillTaxesModel>();
            _billSaveModel = new BillSaveModel();

            _bill = new BillModel
            {
                Id = Guid.NewGuid(),
                BillNumber = _billData.GetBillNumber(),
                DateEvent = DateTime.Now
            };
            lblNumeroFactura.Text = _bill.BillNumber.ToString().PadLeft(8, '0');
            _billTaxes = _billData.GetBillTaxes();
            _billTaxes.ForEach(x => x.IdBill = _bill.Id);
            dtgImpuestos.DataSource = _billTaxes;
            lblGranTotal.Text = "$0,00";
            txtSubTotal.Text = string.Format("{0:0.00}", 0.00);
            txtDescuentoFinal.Text = string.Format("{0:0.00}", 0.00);
            txtDescuentoCliente.Text = string.Format("{0:0.00}", 0.00);
            dtgDetalleFactura.DataSource = new List<BillDetailModel>();
            txtIdentificacionCliente.Text = string.Empty;
            txtNombreCliente.Text = string.Empty;
            txtDireccion.Text = string.Empty;
            txtTelefono.Text = string.Empty;
            txtEmail.Text = string.Empty;
            txtCodigoBarras.Text = string.Empty;
            txtNombreProducto.Text = string.Empty;
            lstProducto.DataSource = new List<InventoryModel>();
            btnBuscarProducto.Enabled = false;
            btnFacturar.Enabled = false;
        }