Exemplo n.º 1
0
        /// <summary>
        /// Insere um novo produto na saída
        /// </summary>
        /// <param name="saidaProduto"></param>
        /// <param name="saida"></param>
        /// <returns></returns>
        public Int64 Inserir(SaidaProduto saidaProduto, Saida saida)
        {
            if (saidaProduto.Quantidade == 0)
            {
                throw new NegocioException("A quantidade do produto não pode ser igual a zero.");
            }
            else if (saidaProduto.ValorVendaAVista <= 0)
            {
                throw new NegocioException("O preço de venda do produto deve ser maior que zero.");
            }
            else if (saida.TipoSaida.Equals(Saida.TIPO_VENDA))
            {
                throw new NegocioException("Não é possível inserir produtos de uma Venda cujo Comprovante Fiscal já foi emitido.");
            }
            else if (saida.TipoSaida.Equals(Saida.TIPO_REMESSA_DEPOSITO) && string.IsNullOrEmpty(saida.Nfe))
            {
                throw new NegocioException("Não é possível inserir produtos em uma transferência para depósito cuja nota fiscal já foi emitida.");
            }
            else if (saida.TipoSaida.Equals(Saida.TIPO_RETORNO_DEPOSITO) && string.IsNullOrEmpty(saida.Nfe))
            {
                throw new NegocioException("Não é possível inserir produtos em um retorno de depósito cuja nota fiscal já foi emitida.");
            }
            else if (saida.TipoSaida.Equals(Saida.TIPO_DEVOLUCAO_FORNECEDOR) && string.IsNullOrEmpty(saida.Nfe))
            {
                throw new NegocioException("Não é possível inserir produtos em uma devolução para fornecedor cuja nota fiscal já foi emitida.");
            }

            SaidaProdutoE _saidaProdutoE = new SaidaProdutoE();

            Atribuir(saidaProduto, _saidaProdutoE);

            repSaidaProduto.Inserir(_saidaProdutoE);
            repSaidaProduto.SaveChanges();
            return(_saidaProdutoE.codSaidaProduto);
        }
Exemplo n.º 2
0
 /// <summary>
 /// Atribui entidade para entidade persistente
 /// </summary>
 /// <param name="saidaProduto"></param>
 /// <param name="_saidaProdutoE"></param>
 private static void Atribuir(SaidaProduto saidaProduto, SaidaProdutoE _saidaProdutoE)
 {
     _saidaProdutoE.baseCalculoICMS      = saidaProduto.BaseCalculoICMS;
     _saidaProdutoE.baseCalculoICMSSubst = saidaProduto.BaseCalculoICMSSubst;
     _saidaProdutoE.codProduto           = saidaProduto.CodProduto;
     _saidaProdutoE.codSaida             = saidaProduto.CodSaida;
     _saidaProdutoE.data_validade        = saidaProduto.DataValidade;
     _saidaProdutoE.desconto             = saidaProduto.Desconto;
     _saidaProdutoE.quantidade           = saidaProduto.Quantidade;
     _saidaProdutoE.subtotal             = saidaProduto.Subtotal;
     _saidaProdutoE.subtotalAVista       = saidaProduto.SubtotalAVista;
     _saidaProdutoE.valorICMS            = saidaProduto.ValorICMS;
     _saidaProdutoE.valorICMSSubst       = saidaProduto.ValorICMSSubst;
     _saidaProdutoE.valorIPI             = saidaProduto.ValorIPI;
     _saidaProdutoE.valorVenda           = saidaProduto.ValorVenda;
     _saidaProdutoE.codCST = saidaProduto.CodCST;
     _saidaProdutoE.cfop   = saidaProduto.CodCfop;
 }