Пример #1
0
 public void Dispose()
 {
     _invoiceController?.Dispose();
     _employeeController?.Dispose();
     _autofacContainer?.Dispose();
     _paymentController?.Dispose();
     _payoutController?.Dispose();
 }
Пример #2
0
        /* public bool verificaData()
         * {
         *   Invoice ivlast = _invoiceController.ListALLAsNoTracking().LastOrDefault();
         *   if(ivlast != null)
         *   {
         *       if(ivlast.DataCadastro > DateTime.Now)
         *       {
         *           MessageBox.Show("Verifique se a data do Sistema está correta..!");
         *           return false;
         *       }
         *   }
         *   return true;
         * }*/



        public void salvar()
        {
            //Series serie = _serieController.ListALLAsNoTracking()[cmbSerie.SelectedIndex];
            try
            {
                CalcCodigoFaturaAtual();
                obs = txtDescricao.Text;
                string   invoiceNo = getInvoiceTypeTipo() + " " + _serieController.ListALLAsNoTracking()[cmbSerie.SelectedIndex].Serie + "/" + _codigoFaturaAtual;
                DateTime dataAtual = DateTime.Now;

                //string GrossTotal = (TotalIva + totalIncidencia).ToString("F").Replace(',', '.');
                string GrossTotal = (totGeral).ToString("F3").Replace(',', '.');
                //   string dadosHash2 = dataAtual.ToString("yyyy-MM-dd") + ";" + dataAtual.ToString("yyyy-MM-ddTHH:mm") + ";" + invoiceNo + ";" + (TotalIva + totalIncidencia).ToString("N2").Replace(",", ".") + ";";
                string dadosHash = dataAtual.ToString("yyyy-MM-dd") + ";" + dataAtual.ToString("yyyy-MM-ddTHH:mm:ss") + ";" + invoiceNo + ";" + GrossTotal + ";";
                dadosHash += lastInvoice != null ? lastInvoice.Hash : "";
                //dadosHash = lastInvoice != null ? dadosHash + lastInvoice.Hash : dadosHash;

                string Hash = Methods.gerarHash(dadosHash, invoiceNo);

                Invoice invoice = new Invoice()
                {
                    InvoiceDate      = dataAtual.ToString("yyyy-MM-dd"),
                    Codigo           = _codigoFaturaAtual,
                    ClienteId        = ClienteID,
                    SeriesId         = idSerie,
                    InvoiceNo        = invoiceNo,
                    TipoDocumentoId  = idTipoDocumento,
                    Desconto         = totDescontoProducts,
                    Observacao       = obs,
                    TotalImposto     = TotalIva,
                    TotalIncidencia  = totalIncidencia,
                    TotalLiquidar    = cmbInvoiceType.Text == "FT" ? totalIncidencia + TotalIva : 0,
                    UserId           = UserCurrent.getCurrentUser().Id,
                    Troco            = troco,
                    ValorPago        = valorPago,
                    FormaPagamentoId = cmbInvoiceType.Text == "FT" ? "CD" : cmbInvoiceType.Text == "PP" || cmbInvoiceType.Text == "FP" ? null : _paymentWays.ListALLAsNoTracking()[cmbPaymentMechanism.SelectedIndex].Id,
                    DataCadastro     = dataAtual,
                    Hash             = Hash,
                    DataVencimento   = dtVencimento.Enabled ? dtVencimento.Value : DateTime.Now,
                };
                _invoiceController.insert(invoice);

                invoice = _invoiceController.getForInvoiceNo(invoiceNo);
                int idFatura = invoice != null ? invoice.Id : 0;

                if (idFatura == 0)
                {
                    MessageBox.Show("Fatura Nula");
                }
                _invoiceController.Dispose();
                _invoiceController = new InvoiceController();

                /*string dadosHash = invoice.InvoiceDate + ";" + invoice.DataCadastro.ToString("yyyy-MM-ddTHH:mm:ss") + ";" + invoice.InvoiceNo + ";" + invoice.TotalGeral.ToString("N2").Replace(",", ".") + ";";
                 * string dadosHash2 = invoice.InvoiceDate + ";" + invoice.DataCadastro.ToString("yyyy-MM-ddTHH:mm") + ";" + invoice.InvoiceNo + ";" + invoice.TotalGeral.ToString("N2").Replace(",", ".") + ";";
                 * dadosHash = lastInvoice != null ? dadosHash2 + lastInvoice.Hash : dadosHash;
                 * invoice.Hash = Methods.gerarHash(dadosHash);*/


                CurrentAccountSystem currentAccountSystem = _currentAcountSystemController.ListALL()[cmbConta.SelectedIndex];
                currentAccountSystem.Saldo += invoice.TotalGeral;
                _currentAcountSystemController.update(currentAccountSystem);



                foreach (var item in __listaSelected)
                {
                    Stock stock = _stock.getStockArmazemProduct(item.ProdutoId, item.Stock.ArmazemId);
                    stock.Quantidade -= item.Quantidade;
                    _stock.update(stock);

                    string  movitoISE = null;
                    Product product   = _products.getOne(item.ProdutoId);
                    if (product.MotivoISEId != null)
                    {
                        movitoISE = product.MotivoISE.MencaoFatura;
                    }


                    ProductSales productSale = new ProductSales()
                    {
                        Preco             = item.Preco,
                        FaturaId          = idFatura,
                        ProductId         = item.ProdutoId,
                        Desconto          = item.Desconto,
                        Descricao_Produto = product.Descricao,
                        Quantidade        = item.Quantidade,
                        StockId           = item.StockId,
                        Taxa          = product.CodigoTaxa.Taxa,
                        Unidade       = product.UnidadeBase.Simbolo,
                        MotivoISEId   = product.MotivoISEId,
                        MotivoIsencao = movitoISE,
                    };

                    _sales.insert(productSale);
                }

                __listaSelected.Clear();
                gdvControlProducts.DataSource = __listaSelected;
                gdvControlProducts.RefreshDataSource();
                CalcCodigoFaturaAtual();
                print(idFatura);
            }
            catch (Exception error)
            {
                MessageBox.Show(error.Message);
            }
        }