Example #1
0
        private void AddCompra()
        {
            _mPedido.Id            = 0;
            _mPedido.Tipo          = "Compras";
            _mPedido.Emissao       = DateTime.Parse(Emissao.Text);
            _mPedido.Chavedeacesso = Id.Text;
            _mPedido.Cliente       = idFornecedor;
            _mPedido.Colaborador   = Settings.Default.user_id;
            //_mPedido.status = 1;
            if (!_mPedido.Save(_mPedido))
            {
                return;
            }

            foreach (dynamic item in produtosID)
            {
                _mPedidoItem.Id          = 0;
                _mPedidoItem.Tipo        = "Produtos";
                _mPedidoItem.Pedido      = _mPedido.GetLastId();
                _mPedidoItem.CProd       = item.Referencia;
                _mPedidoItem.CEan        = item.CodeBarras;
                _mPedidoItem.xProd       = item.Nome;
                _mPedidoItem.Ncm         = item.NCM;
                _mPedidoItem.Item        = item.Id;
                _mPedidoItem.ValorCompra = 0;
                _mPedidoItem.ValorVenda  = item.ValorCompra;
                _mPedidoItem.Medida      = item.Medida;
                _mPedidoItem.Quantidade  = item.EstoqueCompra;
                _mPedidoItem.Total       = item.EstoqueCompra * item.ValorCompra;
                _mPedidoItem.TotalVenda  = item.EstoqueCompra * item.ValorCompra;
                _mPedidoItem.Save(_mPedidoItem, false);
                new Estoque(_mPedidoItem.GetLastId(), Home.pedidoPage, $"Importação de compra").Add().Item();
            }

            foreach (dynamic item in ImportarPagamentos.titulos)
            {
                _mTitulo.Id           = 0;
                _mTitulo.Tipo         = "Pagar";
                _mTitulo.Emissao      = Validation.ConvertDateToSql(Emissao.Text);
                _mTitulo.Id_FormaPgto = Validation.ConvertToInt32(item.FormaPgto) == 15 ? 6 : Validation.ConvertToInt32(item.FormaPgto);
                _mTitulo.Id_Pedido    = _mPedido.GetLastId();
                _mTitulo.Vencimento   = item.Data;
                _mTitulo.Total        = Validation.ConvertToDouble(item.Valor.Replace(".", ","));
                _mTitulo.Recebido     = Validation.ConvertToDouble(item.Valor.Replace(".", ","));
                _mTitulo.Id_Pessoa    = idFornecedor;
                _mTitulo.Obs          = $"Pagamento gerado a partir da importação de compra. Chave de acesso: {item.id} | Número da nota: {item.nr}";
                _mTitulo.Save(_mTitulo, false);

                if (_mPedido.GetLastId() > 0)
                {
                    _mPedido.Id     = _mPedido.GetLastId();
                    _mPedido.status = 1;
                    _mPedido.Save(_mPedido);
                }
            }

            var data = _mPedido.SaveTotais(_mPedidoItem.SumTotais(_mPedido.GetLastId()));

            _mPedido.Save(data);
        }
Example #2
0
        private void FormulaDesconto2(string descontoTotal, int idItem, int countItens = 0)
        {
            _mPedido      = _mPedido.Query().Where("id", idPedido).FirstOrDefault <Model.Pedido>();
            _mPedidoItens = _mPedidoItens.Query().Where("id", idItem).First <PedidoItem>();

            var soma3 = Validation.Round(Validation.ConvertToDouble(descontoTotal) / countItens, 2);

            _mPedidoItens.Id             = idItem;
            _mPedidoItens.Tipo           = "Produtos";
            _mPedidoItens.DescontoPedido = Validation.ConvertToDouble(soma3);
            _mPedidoItens.SomarDescontoTotal();
            _mPedidoItens.SomarTotal();
            _mPedidoItens.Save(_mPedidoItens);
        }
Example #3
0
        private void FormulaFrete(string total, int idItem)
        {
            var dataPedido = _mPedido.Query().Select("id", "total").Where("id", idPedido).First <Model.Pedido>();

            _mPedidoItens = _mPedidoItens.Query().Where("id", idItem).First <PedidoItem>();

            var soma1 = Validation.Round(_mPedidoItens.Total * 100 / dataPedido.Total);
            var soma2 = Validation.Round(soma1 / 100);
            var soma3 = Validation.Round(Validation.ConvertToDouble(total) * soma2);

            _mPedidoItens.Id    = idItem;
            _mPedidoItens.Tipo  = "Produtos";
            _mPedidoItens.Frete = Validation.ConvertToDouble(soma3);
            _mPedidoItens.SomarTotal();
            _mPedidoItens.Save(_mPedidoItens);
        }
Example #4
0
        private void FormulaDesconto(string total, int idItem)
        {
            _mPedido      = _mPedido.Query().Where("id", idPedido).FirstOrDefault <Model.Pedido>();
            _mPedidoItens = _mPedidoItens.Query().Where("id", idItem).First <PedidoItem>();

            //decimal argument = (decimal)_mPedido.Total;
            //int qtdDecimal = BitConverter.GetBytes(decimal.GetBits(argument)[3])[2];
            var qtdDecimall = Validation.GetNumberOfDigits((decimal)_mPedido.Total);
            var qtdD        = qtdDecimall + 1;

            qtdD = 2;

            var soma1 = Validation.Round(_mPedidoItens.Total * 100 / _mPedido.Total, qtdD);
            var soma2 = Validation.Round(soma1 / 100, qtdD);

            if (soma2 == 0)
            {
                soma2 = Validation.Round(soma1 / 100, 3);
            }

            if (soma2 == 0)
            {
                soma2 = Validation.Round(soma1 / 100, 4);
            }

            if (soma2 == 0)
            {
                soma2 = Validation.Round(soma1 / 100, 5);
            }

            var soma3 = Validation.Round(Validation.ConvertToDouble(total) * soma2, qtdD);

            _mPedidoItens.Id             = idItem;
            _mPedidoItens.Tipo           = "Produtos";
            _mPedidoItens.DescontoPedido = Validation.ConvertToDouble(soma3);
            _mPedidoItens.SomarDescontoTotal();
            _mPedidoItens.SomarTotal();
            _mPedidoItens.Save(_mPedidoItens);
        }
Example #5
0
        private void FormulaDevolucao(int idItem)
        {
            _mPedido      = _mPedido.Query().Where("id", idPedido).FirstOrDefault <Model.Pedido>();
            _mPedidoItens = _mPedidoItens.Query().Where("id", idItem).First <PedidoItem>();

            var data = new Model.Pedido().Query().SelectRaw("SUM(PEDIDO.total) as total").Where("tipo", "Devoluções")
                       .Where("excluir", "0").Where("venda", idPedido).FirstOrDefault <Model.Pedido>();

            if (data == null)
            {
                Alert.Message("Opss", "Problema para encontrar total da Troca", Alert.AlertType.warning);
                return;
            }

            var total = Validation.ConvertToDouble(data.Total);
            var soma1 = Validation.Round(_mPedidoItens.Total * 100 / _mPedido.Total);
            var soma2 = Validation.Round(soma1 / 100);
            var soma3 = Validation.Round(Validation.ConvertToDouble(total) * soma2);

            _mPedidoItens.Id = idItem;
            _mPedidoItens.DevolucaoPedido = Validation.ConvertToDouble(soma3);
            _mPedidoItens.SomarTotal();
            _mPedidoItens.Save(_mPedidoItens);
        }
Example #6
0
        /// <summary>
        ///     Manipula todos os eventos do form
        /// </summary>
        private void Eventos()
        {
            Shown += (s, e) =>
            {
                KeyDown   += KeyDowns;
                KeyPreview = true;

                if (IdProduto > 0)
                {
                    _mItem = _mItem.FindById(IdProduto).FirstOrDefault <Item>();
                }
                else
                {
                    return;
                }

                Combos.DataSource    = _mItemCombo.GetCombos(_mItem.Combos);
                Combos.DisplayMember = "Nome";
                Combos.ValueMember   = "Id";

                SetHeadersTableItens(GridListaItens);
                SetHeadersTableItensCategoria(GridListaSelectItens);
            };

            btnCombo.Click += (s, e) =>
            {
                if (Combos.SelectedValue.ToString() == "0")
                {
                    Alert.Message("Opps", "Selecione um combo válido.", Alert.AlertType.error);
                    return;
                }

                listProdutos.Clear();
                listProdutosSelecionados.Clear();
                GridListaItens.Rows.Clear();
                GridListaSelectItens.Rows.Clear();
                SepareIds();
                LoadDataTableItens();
            };

            btnInserir.Click += (s, e) =>
            {
                if (GridListaItens.Rows.Count < 0)
                {
                    return;
                }

                var count = GridListaItens.Rows.Cast <DataGridViewRow>().Count(row => (bool)row.Cells["Incluir"].Value) - 1;

                listProdutosIncluir.Clear();
                foreach (DataGridViewRow row in GridListaItens.Rows)
                {
                    if (!(bool)row.Cells["Incluir"].Value)
                    {
                        continue;
                    }

                    var idItem   = Validation.ConvertToInt32(row.Cells["ID"].Value.ToString());
                    var dataItem = _mItem.FindById(idItem).FirstOrDefault <Item>();

                    var valorVenda = dataItem.ValorVenda - 1.00;

                    var pedidoItem = new PedidoItem();
                    pedidoItem.SetId(0)
                    .SetTipo(dataItem.Tipo)
                    .SetPedidoId(IdPedido)
                    .SetItem(dataItem)
                    .SetQuantidade(1)
                    .SetMedida(dataItem.Medida);
                    pedidoItem.Adicional = row.Cells["AddonSelected"].Value.ToString();

                    if (IdProduto == dataItem.Id)
                    {
                        var valorCombo = Validation.ConvertToDouble(txtComboValor.Text.Replace("Valor do Combo: R$ ", ""));

                        pedidoItem.ValorVenda = valorCombo - count;
                        pedidoItem.Total      = valorCombo - count;
                        pedidoItem.TotalVenda = valorCombo - count;
                    }
                    else
                    {
                        pedidoItem.ValorVenda = dataItem.ValorVenda - valorVenda;
                        pedidoItem.Total      = dataItem.ValorVenda - valorVenda;
                        pedidoItem.TotalVenda = dataItem.ValorVenda - valorVenda;
                    }

                    switch (Home.pedidoPage)
                    {
                    case "Remessas":
                        pedidoItem.Status = "Remessa";
                        break;

                    case "Delivery":
                    case "Balcao":
                        pedidoItem.Status = "FAZENDO";
                        break;
                    }

                    pedidoItem.Save(pedidoItem);

                    listProdutosIncluir.Add(pedidoItem);

                    new Controller.Estoque(pedidoItem.GetLastId(), Home.pedidoPage, "Adicionar Produto").Remove().Item();
                }

                DialogResult = DialogResult.OK;
                Close();
            };

            btnContinuar.Click += (s, e) =>
            {
                DialogResult = DialogResult.Ignore;
                Close();
            };

            GridListaSelectItens.CellClick += (s, e) =>
            {
                if (GridListaSelectItens.Columns[e.ColumnIndex].Name == "Incluir")
                {
                    GridListaItens.Rows.Add(
                        true,
                        GridListaSelectItens.SelectedRows[0].Cells["Photo"].Value,
                        GridListaSelectItens.SelectedRows[0].Cells["ID"].Value,
                        GridListaSelectItens.SelectedRows[0].Cells["Item"].Value,
                        GridListaSelectItens.SelectedRows[0].Cells["Valor"].Value,
                        $"{Validation.FormatPrice(0, true)}",
                        GridListaSelectItens.SelectedRows[0].Cells["Estoque Atual"].Value,
                        "",
                        GridListaSelectItens.SelectedRows[0].Cells["Valor"].Value,
                        Resources.menu20x
                        );

                    GridListaSelectItens.Rows.Clear();
                    LoadDataTableItens();

                    Alert.Message("Pronto", "Item adicionado.", Alert.AlertType.success);
                }
            };

            GridListaSelectItens.CellMouseEnter += (s, e) =>
            {
                if (e.ColumnIndex < 0 || e.RowIndex < 0)
                {
                    return;
                }

                var dataGridView = s as DataGridView;
                if (GridListaSelectItens.Columns[e.ColumnIndex].Name == "Incluir")
                {
                    dataGridView.Cursor = Cursors.Hand;
                }
            };

            GridListaSelectItens.CellMouseLeave += (s, e) =>
            {
                if (e.ColumnIndex < 0 || e.RowIndex < 0)
                {
                    return;
                }

                var dataGridView = s as DataGridView;
                if (GridListaSelectItens.Columns[e.ColumnIndex].Name == "Incluir")
                {
                    dataGridView.Cursor = Cursors.Default;
                }
            };

            GridListaItens.CellClick += (s, e) =>
            {
                if (GridListaItens.Columns[e.ColumnIndex].Name == "Incluir")
                {
                    GridListaItens.SelectedRows[0].Cells["Incluir"].Value = (bool)GridListaItens.SelectedRows[0].Cells["Incluir"].Value == false;
                }

                if (GridListaItens.Columns[e.ColumnIndex].Name == "Adicional")
                {
                    AdicionaisDispon.ValorAddon    = 0;
                    AdicionaisDispon.AddonSelected = GridListaItens.SelectedRows[0].Cells["AddonSelected"].Value != null
                        ? GridListaItens.SelectedRows[0].Cells["AddonSelected"].Value.ToString()
                        : "";
                    AdicionaisDispon.IdPedidoItem = 0;
                    AdicionaisDispon.IdItem       = Validation.ConvertToInt32(GridListaItens.SelectedRows[0].Cells["ID"].Value);
                    var form = new AdicionaisDispon {
                        TopMost = true
                    };
                    if (form.ShowDialog() == DialogResult.OK)
                    {
                        var getValor = Validation.ConvertToDouble(GridListaItens.SelectedRows[0].Cells["Unitario"].Value
                                                                  .ToString().Replace("R$ ", ""));
                        GridListaItens.SelectedRows[0].Cells["Valor Adicional"].Value = Validation.FormatPrice(AdicionaisDispon.ValorAddon, true);
                        GridListaItens.SelectedRows[0].Cells["AddonSelected"].Value   = AdicionaisDispon.AddonSelected;

                        txtComboValor.Text = $"Valor do Combo: {Validation.FormatPrice(ValorCombo + AdicionaisDispon.ValorAddon, true)}";
                    }
                }
            };

            GridListaItens.CellMouseEnter += (s, e) =>
            {
                if (e.ColumnIndex < 0 || e.RowIndex < 0)
                {
                    return;
                }

                var dataGridView = s as DataGridView;
                if (GridListaItens.Columns[e.ColumnIndex].Name == "Incluir" ||
                    GridListaItens.Columns[e.ColumnIndex].Name == "Adicional")
                {
                    dataGridView.Cursor = Cursors.Hand;
                }
            };

            GridListaItens.CellMouseLeave += (s, e) =>
            {
                if (e.ColumnIndex < 0 || e.RowIndex < 0)
                {
                    return;
                }

                var dataGridView = s as DataGridView;
                if (GridListaItens.Columns[e.ColumnIndex].Name == "Incluir" ||
                    GridListaItens.Columns[e.ColumnIndex].Name == "Adicional")
                {
                    dataGridView.Cursor = Cursors.Default;
                }
            };
        }
Example #7
0
        private void ActionEnviar()
        {
            if (IniFile.Read("MesasPreCadastrada", "Comercial") == "False")
            {
                if (string.IsNullOrEmpty(nrMesa.Text))
                {
                    Alert.Message("Oppss", "É necessário informar uma mesa", Alert.AlertType.warning);
                    return;
                }
            }
            else
            {
                if (Mesas.SelectedValue == null)
                {
                    if (nrMesa.Text == "")
                    {
                        Alert.Message("Oppss", "É necessário informar uma mesa", Alert.AlertType.warning);
                        return;
                    }
                }
                else if (Mesas.SelectedValue.ToString() == "0")
                {
                    Alert.Message("Oppss", "É necessário informar uma mesa", Alert.AlertType.warning);
                    return;
                }
            }

            if (GridLista.Rows.Count > 0)
            {
                foreach (DataGridViewRow row in GridLista.Rows)
                {
                    var id       = Validation.ConvertToInt32(row.Cells["ID"].Value);
                    var dataItem = _mItem.FindById(id).WhereFalse("excluir").FirstOrDefault <Item>();
                    if (dataItem != null)
                    {
                        var obs = row.Cells["Observação"].Value.ToString();

                        _mPedidoItem.Id             = 0;
                        _mPedidoItem.Tipo           = "Produtos";
                        _mPedidoItem.Excluir        = 0;
                        _mPedidoItem.Pedido         = 0;
                        _mPedidoItem.Item           = dataItem.Id;
                        _mPedidoItem.CEan           = dataItem.CodeBarras;
                        _mPedidoItem.CProd          = dataItem.Referencia;
                        _mPedidoItem.xProd          = dataItem.Nome;
                        _mPedidoItem.ValorVenda     = Validation.ConvertToDouble(row.Cells["Valor"].Value);
                        _mPedidoItem.Total          = Validation.ConvertToDouble(row.Cells["Valor"].Value);
                        _mPedidoItem.Quantidade     = 1;
                        _mPedidoItem.TotalVenda     = Validation.ConvertToDouble(row.Cells["Valor"].Value);
                        _mPedidoItem.Info_Adicional = obs;
                        _mPedidoItem.Adicional      = row.Cells["AddonSelected"].Value.ToString();
                        _mPedidoItem.Mesa           = IniFile.Read("MesasPreCadastrada", "Comercial") == "True" ? Mesas.Text : nrMesa.Text;
                        _mPedidoItem.Status         = "FAZENDO";
                        _mPedidoItem.Usuario        = Settings.Default.user_id;
                        _mPedidoItem.Save(_mPedidoItem, false);
                    }
                }

                new Controller.Pedido().ImprimirItens(0, _mPedidoItem.GetLastId());

                Alert.Message("Pronto", "Pedido enviado com sucesso.", Alert.AlertType.success);
                DialogResult = DialogResult.OK;
                Close();
            }
        }
Example #8
0
        public async Task ReceberRemessa()
        {
            var response = new RequestApi()
                           .URL(Program.URL_BASE + $"/api/pedido/remessas/{Program.TOKEN}/{idEmpresa}")
                           .Content().Response();

            if (response["error"]?.ToString() == "Nenhum registro encontrado")
            {
                Alert.Message("OPPS", "Não existem remessas.", Alert.AlertType.error);
                return;
            }

            foreach (dynamic item in response)
            {
                if (string.IsNullOrEmpty(item.Value.ToString()))
                {
                    return;
                }

                string idEmpresa = item.Value.pedido.id_empresa;
                int    idUsuario = item.Value.pedido.id_usuario;
                int    idPedido  = item.Value.pedido.id;
                int    idSync    = item.Value.pedido.id_sync;

                var lastId = 0;
                if (item.Value.pedido != null)
                {
                    var createPedido = new Pedido
                    {
                        Id          = 0,
                        Tipo        = "Remessas",
                        Excluir     = 0,
                        Emissao     = item.Value.pedido.emissao,
                        Cliente     = item.Value.pedido.cliente,
                        Colaborador = item.Value.pedido.colaborador,
                        Total       = item.Value.pedido.total,
                        Desconto    = item.Value.pedido.desconto,
                        Frete       = item.Value.pedido.frete,
                        Produtos    = item.Value.pedido.produtos,
                        id_usuario  = item.Value.pedido.id_usuario,
                        campoa      = "RECEBIDO",
                        campob      = item.Value.pedido.campoc,
                        Observacao  = $"Remessa da empresa: {idEmpresa}"
                    };
                    createPedido.Save(createPedido);

                    lastId = createPedido.GetLastId();
                }

                if (item.Value.itens != null)
                {
                    foreach (var data in item.Value.itens)
                    {
                        var createPedidoItem = new PedidoItem();
                        createPedidoItem.Id      = 0;
                        createPedidoItem.Tipo    = "Produtos";
                        createPedidoItem.Excluir = 0;
                        createPedidoItem.Pedido  = lastId;

                        string codebarras = data.Value.cean;
                        double quantidade = data.Value.quantidade;
                        var    dataItem   = new Item().FindAll().WhereFalse("excluir").Where("codebarras", codebarras)
                                            .FirstOrDefault <Item>();
                        var idItem = 0;
                        if (dataItem != null)
                        {
                            var movEstoque = new ItemEstoqueMovimentacao()
                                             .SetUsuario(idUsuario)
                                             .SetQuantidade(quantidade)
                                             .SetTipo("A")
                                             .SetLocal("Remessa de estoque")
                                             .SetObs($"Enviado da empresa: {idEmpresa}")
                                             .SetIdPedido(idPedido)
                                             .SetItem(dataItem);

                            idItem = dataItem.Id;

                            movEstoque.Save(movEstoque);
                        }
                        else
                        {
                            var createItem = new Item
                            {
                                Id          = 0,
                                Excluir     = 0,
                                Tipo        = "Produtos",
                                CodeBarras  = codebarras,
                                Referencia  = data.Value.cprod,
                                Nome        = data.Value.xprod,
                                ValorCompra = data.Value.valorcompra,
                                ValorVenda  = data.Value.valorvenda,
                                Ncm         = data.Value.ncm,
                                ativo       = 0
                            };
                            createItem.Save(createItem);

                            idItem = createItem.GetLastId();

                            var movEstoque = new ItemEstoqueMovimentacao()
                                             .SetUsuario(idUsuario)
                                             .SetQuantidade(quantidade)
                                             .SetTipo("A")
                                             .SetLocal("Remessa de estoque")
                                             .SetObs($"Enviado da empresa: {idEmpresa}")
                                             .SetIdPedido(idPedido)
                                             .SetItem(createItem);

                            movEstoque.Save(movEstoque);
                        }

                        createPedidoItem.Item           = idItem;
                        createPedidoItem.CProd          = data.Value.cprod;
                        createPedidoItem.CEan           = data.Value.cean;
                        createPedidoItem.xProd          = data.Value.xprod;
                        createPedidoItem.Ncm            = data.Value.ncm;
                        createPedidoItem.Cfop           = data.Value.cfop;
                        createPedidoItem.ValorCompra    = data.Value.valorcompra;
                        createPedidoItem.ValorVenda     = data.Value.valorvenda;
                        createPedidoItem.Quantidade     = data.Value.quantidade;
                        createPedidoItem.Medida         = data.Value.medida;
                        createPedidoItem.Total          = data.Value.total;
                        createPedidoItem.Desconto       = data.Value.desconto;
                        createPedidoItem.DescontoItem   = data.Value.descontoitem;
                        createPedidoItem.DescontoPedido = data.Value.descontopedido;
                        createPedidoItem.Frete          = data.Value.frete;
                        createPedidoItem.Icms           = data.Value.icms;
                        createPedidoItem.Federal        = data.Value.federal;
                        createPedidoItem.Estadual       = data.Value.estadual;
                        createPedidoItem.Status         = data.Value.status;
                        createPedidoItem.Save(createPedidoItem, false);
                    }
                }

                dynamic obj = new
                {
                    token      = Program.TOKEN,
                    id_empresa = idEmpresa
                };

                var responseP = new RequestApi().URL(Program.URL_BASE + $"/api/pedido/updateRemessa/{idSync}/RECEBIDO")
                                .Content(obj, Method.POST).Response();
                if (responseP["status"] != "OK")
                {
                    new Log().Add("SYNC", $"{responseP["status"]} | Tabela: pedido - {responseP["message"]}",
                                  Log.LogType.fatal);
                }
            }
        }