Ejemplo n.º 1
0
        private void app_accountDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            //Account detail.
            app_account objAccount = (app_account)app_accountDataGrid.SelectedItem;

            app_account_detailDataGrid.ItemsSource = objAccount.app_account_detail
                                                     .GroupBy(ad => new { ad.id_currencyfx, ad.id_payment_type })
                                                     .Select(s => new
            {
                cur     = s.Max(ad => ad.app_currencyfx.app_currency.name),
                payType = s.Max(ad => ad.payment_type.name),
                amount  = s.Sum(ad => ad.credit) - s.Sum(ad => ad.debit)
            }).ToList();
            CurrentSession.Id_Account = objAccount.id_account;

            if (frmActive.Children.Count > 0)
            {
                frmActive.Children.RemoveAt(0);
            }

            Configs.AccountActive AccountActive = new AccountActive();
            AccountActive.db = db;
            AccountActive.app_accountViewSource = app_accountViewSource;
            frmActive.Children.Add(AccountActive);
        }
Ejemplo n.º 2
0
        private void toolBar_btnSave_Click(object sender)
        {
            app_account app_account = app_accountViewSource.View.CurrentItem as app_account;

            db.SaveChanges();
            app_account.State = EntityState.Unchanged;
        }
Ejemplo n.º 3
0
        private async void Page_Loaded(object sender, RoutedEventArgs e)
        {
            ///This code will create a new Sale & Payment Information.
            //Task task = Task.Factory.StartNew(() => New_Sale_Payment());
            New_Sale_Payment();

            //PAYMENT TYPE
            await SalesInvoiceDB.payment_type.Where(a => a.is_active == true && a.id_company == CurrentSession.Id_Company && a.payment_behavior == payment_type.payment_behaviours.Normal).LoadAsync();

            CollectionViewSource payment_typeViewSource = (CollectionViewSource)this.FindResource("payment_typeViewSource");

            payment_typeViewSource.Source = SalesInvoiceDB.payment_type.Local;

            cbxSalesRep.ItemsSource = await SalesInvoiceDB.sales_rep.Where(x => x.is_active && x.id_company == CurrentSession.Id_Company).ToListAsync(); //CurrentSession.Get_SalesRep();

            app_currencyViewSource        = (CollectionViewSource)this.FindResource("app_currencyViewSource");
            app_currencyViewSource.Source = CurrentSession.Get_Currency();

            int         Id_Account  = CurrentSession.Id_Account;
            app_account app_account = await SalesInvoiceDB.app_account.Where(x => x.id_account == CurrentSession.Id_Account).FirstOrDefaultAsync();

            if (app_account != null)
            {
                if (app_account.is_active == false)
                {
                    btnAccount_Click(sender, e);
                    frmaccount.Refresh();
                }
            }
        }
Ejemplo n.º 4
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            CollectionViewSource payment_typeViewSource = (CollectionViewSource)this.FindResource("payment_typeViewSource");

            PaymentDB.payment_type.Where(a => a.is_active && a.id_company == CurrentSession.Id_Company).Load();
            //Fix if Payment Type not inserted.
            if (PaymentDB.payment_type.Local.Count == 0)
            {
                entity.payment_type payment_type = new entity.payment_type();
                payment_type.name       = "Cash";
                payment_type.is_active  = true;
                payment_type.is_default = true;

                PaymentDB.payment_type.Add(payment_type);
            }
            payment_typeViewSource.Source = PaymentDB.payment_type.Local;

            CollectionViewSource app_accountViewSource = (CollectionViewSource)this.FindResource("app_accountViewSource");

            PaymentDB.app_account.Where(a => a.is_active && a.id_company == CurrentSession.Id_Company).Load();

            //Fix if Payment Type not inserted.
            if (PaymentDB.app_account.Local.Count == 0)
            {
                entity.app_account app_account = new entity.app_account();
                app_account.name            = "CashBox";
                app_account.code            = "Generic";
                app_account.id_account_type = entity.app_account.app_account_type.Terminal;
                app_account.id_terminal     = CurrentSession.Id_Terminal;
                app_account.is_active       = true;

                PaymentDB.app_account.Add(app_account);
            }
            app_accountViewSource.Source = PaymentDB.app_account.Local;

            if (Mode == Modes.Recievable)
            {
                cbxDocument.ItemsSource  = entity.Brillo.Logic.Range.List_Range(PaymentDB, App.Names.PaymentUtility, CurrentSession.Id_Branch, CurrentSession.Id_Company);
                stackDocument.Visibility = System.Windows.Visibility.Visible;
            }

            paymentViewSource.View.Refresh();
            paymentpayment_detailViewSource.View.Refresh();
            payment payment = paymentViewSource.View.CurrentItem as payment;

            if (payment != null)
            {
                app_account app_account = app_accountViewSource.View.CurrentItem as app_account;
                if (app_account != null)
                {
                    foreach (payment_detail payment_detail in payment.payment_detail)
                    {
                        payment_detail.id_account = app_account.id_account;
                    }
                }
            }
            paymentpayment_detailViewSource.View.Refresh();
        }
Ejemplo n.º 5
0
        private void toolBar_btnEdit_Click(object sender)
        {
            app_account app_account = app_accountViewSource.View.CurrentItem as app_account;

            if (app_account != null)
            {
                app_account.State = EntityState.Modified;
            }
        }
Ejemplo n.º 6
0
        public app_account GenerateDefaultApp_Account()
        {
            app_account app_account = new app_account();

            app_account.name            = "Default";
            app_account.id_account_type = entity.app_account.app_account_type.Terminal;
            app_account.code            = "Default";
            app_account.is_active       = true;
            return(app_account);
        }
Ejemplo n.º 7
0
 public accounting_chart find_Chart(AccountingJournalDB context, app_account app_account)
 {
     if (context.accounting_chart.Where(i => i.id_account == app_account.id_account).FirstOrDefault() != null)
     {
         return(context.accounting_chart.Where(i => i.id_account == app_account.id_account).FirstOrDefault());
     }
     else if (context.accounting_chart.Where(i => i.chartsub_type == accounting_chart.ChartSubType.Cash && i.is_generic == true).FirstOrDefault() != null)
     {
         return(context.accounting_chart.Where(i => i.chartsub_type == accounting_chart.ChartSubType.Cash && i.is_generic == true).FirstOrDefault());
     }
     else
     {
         return(null);
     }
 }
Ejemplo n.º 8
0
        private void sync_Accounts()
        {
            DataTable dt = exeDT("SELECT * FROM CAJA;");

            foreach (DataRow row in dt.Rows)
            {
                app_account app_account = new app_account();
                app_account.name       = (string)row["NUMEROCAJA"];
                app_account.id_company = id_company;
                app_account.is_active  = true;
                dbContext.app_account.Add(app_account);
            }
            dt.Clear();
            dbContext.SaveChanges();
        }
Ejemplo n.º 9
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            // Do not load your data at design time.
            if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            {
                //

                accountsViewSource = (CollectionViewSource)FindResource("accountsViewSource");
                entity.db.app_account.Where(x => x.is_active == true && x.id_company == _settings.company_ID).ToList();
                accountsViewSource.Source = entity.db.app_account.Local;


                cbxAccountType.ItemsSource = Enum.GetValues(typeof(app_account.app_account_type));

                CollectionViewSource app_bankViewSource = (System.Windows.Data.CollectionViewSource) this.FindResource("app_bankViewSource");
                app_bankViewSource.Source = entity.db.app_bank.Where(a => a.is_active == true && a.id_company == _settings.company_ID).OrderBy(a => a.name).ToList();

                CollectionViewSource app_terminalViewSource = (System.Windows.Data.CollectionViewSource) this.FindResource("app_terminalViewSource");
                app_terminalViewSource.Source = entity.db.app_terminal.Where(a => a.is_active == true).OrderBy(a => a.name).ToList();

                CollectionViewSource app_currencyViewSource = (System.Windows.Data.CollectionViewSource) this.FindResource("app_currencyViewSource");
                app_currencyViewSource.Source = entity.db.app_currency.Where(a => a.is_active == true && a.id_company == _settings.company_ID).OrderBy(a => a.name).ToList();
                if (operationMode == Class.clsCommon.Mode.Add)
                {
                    app_account app_account = new app_account();
                    app_account.name      = "account";
                    app_account.is_active = true;
                    entity.db.app_account.Add(app_account);
                    //  entity.db.SaveChanges();

                    accountsViewSource.View.Refresh();
                    accountsViewSource.View.MoveCurrentToLast();
                }
                else
                {
                    accountsViewSource.View.MoveCurrentTo(entity.db.app_account.Where(x => x.id_account == accountobject.id_account).FirstOrDefault());
                    btnDelete.Visibility = System.Windows.Visibility.Visible;
                }
                stackMainAc.DataContext = accountsViewSource;
            }
        }
Ejemplo n.º 10
0
 private void toolBar_btnSearch_Click(object sender, string query)
 {
     if (!string.IsNullOrEmpty(query))
     {
         app_accountViewSource.View.Filter = i =>
         {
             app_account app_account = i as app_account;
             if (app_account.name.ToLower().Contains(query.ToLower()))
             {
                 return(true);
             }
             else
             {
                 return(false);
             }
         };
     }
     else
     {
         app_accountViewSource.View.Filter = null;
     }
 }
Ejemplo n.º 11
0
        private void btnTransfer_Click(object sender, RoutedEventArgs e)
        {
            if (cbxAccountDestination.SelectedItem != null)
            {
                app_account idOriginAccount = ((app_accountViewSource.View.CurrentItem) as app_account); //Credit Account
                app_account idDestiAccount  = cbxAccountDestination.SelectedItem as app_account;         //Debit Account

                if (idOriginAccount.id_account == idDestiAccount.id_account)
                {
                    MessageBox.Show("Please select a different Destination", "Cognitivo ERP", MessageBoxButton.OK, MessageBoxImage.Information);
                    return;
                }

                foreach (Class.clsTransferAmount TransferAmount in listTransferAmt)
                {
                    payment_type payment_type = db.payment_type.Where(x => x.id_payment_type == TransferAmount.id_payment_type).FirstOrDefault();

                    if (idOriginAccount != null && idDestiAccount != null && payment_type != null)
                    {
                        app_account_detail objOriginAcDetail = new app_account_detail();
                        if (db.app_account_session.Where(x => x.id_account == idOriginAccount.id_account && x.is_active).FirstOrDefault() != null)
                        {
                            objOriginAcDetail.id_session = db.app_account_session.Where(x => x.id_account == idOriginAccount.id_account && x.is_active).FirstOrDefault().id_session;
                        }

                        objOriginAcDetail.id_account      = idOriginAccount.id_account;
                        objOriginAcDetail.id_currencyfx   = TransferAmount.id_currencyfx;
                        objOriginAcDetail.id_payment_type = TransferAmount.id_payment_type;
                        objOriginAcDetail.credit          = 0;
                        objOriginAcDetail.debit           = TransferAmount.amount;
                        objOriginAcDetail.comment         = "Transfered to " + idDestiAccount.name + ".";
                        objOriginAcDetail.trans_date      = DateTime.Now;

                        app_account_detail objDestinationAcDetail = new app_account_detail();
                        if (db.app_account_session.Where(x => x.id_account == idDestiAccount.id_account && x.is_active).FirstOrDefault() != null)
                        {
                            objDestinationAcDetail.id_session = db.app_account_session.Where(x => x.id_account == idDestiAccount.id_account && x.is_active).FirstOrDefault().id_session;
                        }

                        objDestinationAcDetail.id_account      = idDestiAccount.id_account;
                        objDestinationAcDetail.id_currencyfx   = TransferAmount.id_currencyfx;
                        objDestinationAcDetail.id_payment_type = TransferAmount.id_payment_type;
                        objDestinationAcDetail.credit          = TransferAmount.amount;
                        objDestinationAcDetail.debit           = 0;
                        objDestinationAcDetail.comment         = "Transfered from " + idOriginAccount.name + ".";
                        objDestinationAcDetail.trans_date      = DateTime.Now;

                        bool is_direct = payment_type.is_direct;
                        if (is_direct)
                        {
                            objOriginAcDetail.status      = entity.Status.Documents_General.Approved;
                            objDestinationAcDetail.status = entity.Status.Documents_General.Approved;
                        }
                        else
                        {
                            objOriginAcDetail.status      = entity.Status.Documents_General.Pending;
                            objDestinationAcDetail.status = entity.Status.Documents_General.Pending;
                        }

                        db.app_account_detail.Add(objOriginAcDetail);
                        db.app_account_detail.Add(objDestinationAcDetail);
                        db.SaveChanges();

                        //Reload Data.
                        cbxAccountDestination.SelectedIndex = 0;
                    }
                }

                listTransferAmt.Clear();
                amount_transferViewSource.View.Refresh();
                app_accountViewSource.View.Refresh();
                app_accountapp_account_detailViewSource.View.Refresh();
                app_account_detail_adjustViewSource.View.Refresh();
                MessageBox.Show("Transfer Completed Successfully!", "Cognitivo ERP", MessageBoxButton.OK, MessageBoxImage.Information);
            }
        }
Ejemplo n.º 12
0
        public void add_paymnet_detail(db db, sales_invoice sales_invoice, object SALDOCUOTA, object IMPORTE)
        {
            if (!(SALDOCUOTA is DBNull))
            {
                decimal      SALDOCUOTAValue = Convert.ToDecimal(SALDOCUOTA);
                payment_type payment_type;
                if (SALDOCUOTAValue < sales_invoice.GrandTotal)
                {
                    if (db.payment_type.Where(x => x.is_default).FirstOrDefault() == null)
                    {
                        payment_type = GenerateDefaultPaymentType();
                        db.payment_type.Add(payment_type);
                        db.SaveChanges();
                    }
                    else
                    {
                        payment_type = db.payment_type.Where(x => x.is_default).FirstOrDefault();
                    }

                    if (IMPORTE is DBNull)
                    {
                        if (sales_invoice.payment_schedual.FirstOrDefault() != null)
                        {
                            payment_schedual payment_schedual = sales_invoice.payment_schedual.FirstOrDefault();
                            decimal          invoice_total    = sales_invoice.GrandTotal;

                            if (invoice_total > 0)
                            {
                                payment_detail payment_detail = new payment_detail();
                                payment_detail.value = invoice_total;

                                if (db.app_account.Where(x => x.id_account_type == app_account.app_account_type.Terminal).FirstOrDefault() != null)
                                {
                                    app_account app_account = db.app_account.Where(x => x.id_account_type == app_account.app_account_type.Terminal).FirstOrDefault();
                                    payment_detail.id_account = app_account.id_account;
                                }
                                else
                                {
                                    app_account app_account = GenerateDefaultApp_Account();
                                    db.app_account.Add(app_account);
                                    payment_detail.app_account = app_account;
                                    payment_detail.id_account  = app_account.id_account;
                                }

                                payment payment = new payment();

                                if (payment_schedual != null)
                                {
                                    payment.id_contact           = payment_schedual.id_contact;
                                    payment.contact              = payment_schedual.contact;
                                    payment_detail.id_currencyfx = payment_schedual.id_currencyfx;

                                    payment_detail.id_payment_type = payment_type.id_payment_type;
                                    payment_detail.payment_type    = payment_type;
                                }

                                payment_detail.App_Name = global::entity.App.Names.SalesInvoice;

                                payment_schedual _payment_schedual = new payment_schedual();
                                _payment_schedual.credit                   = invoice_total;
                                _payment_schedual.parent                   = payment_schedual;
                                _payment_schedual.expire_date              = payment_schedual.expire_date;
                                _payment_schedual.status                   = payment_schedual.status;
                                _payment_schedual.id_contact               = payment_schedual.id_contact;
                                _payment_schedual.id_currencyfx            = payment_schedual.id_currencyfx;
                                _payment_schedual.id_sales_invoice         = payment_schedual.id_sales_invoice;
                                _payment_schedual.trans_date               = payment_schedual.trans_date;
                                _payment_schedual.AccountReceivableBalance = invoice_total;

                                payment_detail.payment_schedual.Add(_payment_schedual);
                                payment.payment_detail.Add(payment_detail);

                                //Add Account Logic. With IF FUnction if payment type is Basic Behaviour. If not ignore.
                                app_account_detail app_account_detail = new app_account_detail();

                                if (db.app_account_session.Where(x => x.id_account == payment_detail.id_account && x.is_active).FirstOrDefault() != null)
                                {
                                    app_account_detail.id_session = db.app_account_session.Where(x => x.id_account == payment_detail.id_account && x.is_active).FirstOrDefault().id_session;
                                }

                                app_account_detail.id_account      = (int)payment_detail.id_account;
                                app_account_detail.id_currencyfx   = payment_schedual.id_currencyfx;
                                app_account_detail.id_payment_type = payment_detail.id_payment_type;
                                app_account_detail.payment_type    = payment_type;
                                app_account_detail.debit           = 0;
                                app_account_detail.credit          = Convert.ToDecimal(payment_detail.value);
                                db.app_account_detail.Add(app_account_detail);

                                try
                                {
                                    db.payments.Add(payment);
                                }
                                catch (Exception ex)
                                {
                                    throw ex;
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 13
0
        public void ZReport(app_account_session app_account_session)
        {
            string Header = string.Empty;
            string Detail = string.Empty;
            string Footer = string.Empty;

            string      CompanyName = string.Empty;
            string      BranchName  = string.Empty;
            app_company app_company = null;

            if (app_account_session.app_company != null)
            {
                CompanyName = app_account_session.app_company.name;
                app_company = app_account_session.app_company;
            }
            else
            {
                using (db db = new db())
                {
                    if (db.app_company.Where(x => x.id_company == app_account_session.id_company).FirstOrDefault() != null)
                    {
                        app_company = db.app_company.Where(x => x.id_company == app_account_session.id_company).FirstOrDefault();
                        CompanyName = app_company.name;
                    }
                }
            }

            string UserName = "";

            if (app_account_session.security_user != null)
            {
                UserName = app_account_session.security_user.name;
            }
            else
            {
                using (db db = new db())
                {
                    if (db.security_user.Where(x => x.id_user == app_account_session.id_user).FirstOrDefault() != null)
                    {
                        security_user security_user = db.security_user.Where(x => x.id_user == app_account_session.id_user).FirstOrDefault();
                        UserName = security_user.name;
                    }
                }
            }
            using (db db = new db())
            {
                if (db.app_branch.Where(x => x.id_branch == CurrentSession.Id_Branch).FirstOrDefault() != null)
                {
                    app_branch app_branch = db.app_branch.Where(x => x.id_branch == CurrentSession.Id_Branch).FirstOrDefault();
                    BranchName = app_branch.name;
                }
            }

            string   SessionID = app_account_session.id_session.ToString();
            DateTime OpenDate  = app_account_session.op_date;
            DateTime CloseDate = DateTime.Now;

            if (app_account_session.cl_date != null)
            {
                CloseDate = (DateTime)app_account_session.cl_date;
            }

            Header =
                "***Z Report***" + "\n"
                + CompanyName + "\t" + BranchName + "\n"
                + "R.U.C.   :" + app_company.gov_code + "\n"
                + app_company.address + "\n"
                + "***" + app_company.alias + "***" + "\n"
                + "Apertura : " + OpenDate + "\n"
                + "Cierre   : " + CloseDate
                + "\n"
                + "--------------------------------" + "\n"
                + "Hora   Factura      / Valor    Moneda" + "\n"
                + "--------------------------------" + "\n";

            string CustomerName = string.Empty;

            foreach (app_account_detail detail in app_account_session.app_account_detail.GroupBy(x => x.id_currencyfx).Select(x => x.FirstOrDefault()).ToList())
            {
                Detail += "Moneda : " + detail.app_currencyfx.app_currency.name + "\n";

                if (detail.tran_type == app_account_detail.tran_types.Open)
                {
                    Detail += "Balance de Apertura : " + Math.Round(detail.credit, 2) + "\n";
                }
                foreach (app_account_detail d in app_account_session.app_account_detail.Where(x => x.tran_type == app_account_detail.tran_types.Transaction && x.id_currencyfx == detail.id_currencyfx).ToList())
                {
                    string AccountName = string.Empty;

                    if (d.app_account == null)
                    {
                        using (db db = new db())
                        {
                            app_account app_account = db.app_account.Where(x => x.id_account == d.id_account).FirstOrDefault();
                            AccountName = app_account.name;
                        }
                    }

                    string currency = string.Empty;
                    if (d.app_currencyfx == null)
                    {
                        using (db db = new db())
                        {
                            currency = db.app_currencyfx.Where(x => x.id_currencyfx == d.id_currencyfx).FirstOrDefault().app_currency.name;
                        }
                    }

                    string InvoiceNumber = string.Empty;
                    string InvoiceTime   = string.Empty;

                    payment_detail payment_detail = d.payment_detail as payment_detail;
                    foreach (payment_schedual payment_schedual in payment_detail.payment_schedual)
                    {
                        if (payment_schedual.sales_invoice.number != null)
                        {
                            if (!(InvoiceNumber.Contains(payment_schedual.sales_invoice.number)))
                            {
                                InvoiceNumber += payment_schedual.sales_invoice.number;
                                InvoiceTime    = payment_schedual.sales_invoice.trans_date.ToShortTimeString();
                            }
                        }
                    }

                    decimal?value = d.credit - d.debit;
                }

                var listvat = app_account_session.app_account_detail.Where(x => x.tran_type == app_account_detail.tran_types.Transaction && x.id_currencyfx == detail.id_currencyfx)
                              .GroupBy(a => new { a.id_payment_type, a.id_currencyfx })
                              .Select(g => new
                {
                    Currencyname    = g.Max(x => x.app_currencyfx).app_currency.name,
                    paymentname     = g.Max(x => x.payment_type).name,
                    id_currencyfx   = g.Key.id_currencyfx,
                    id_payment_type = g.Key.id_payment_type,
                    value           = g.Sum(a => a.credit)
                }).ToList().OrderBy(x => x.id_currencyfx);
                Detail += "Total de Ventas Neto :" + Math.Round(listvat.Sum(x => x.value), 2) + "\n";

                foreach (dynamic item in listvat)
                {
                    Detail += item.paymentname + "\t" + Math.Round(item.value, 2) + "\n";
                }

                foreach (app_account_detail account_detail in app_account_session.app_account_detail.Where(x => x.tran_type == app_account_detail.tran_types.Close && x.id_currencyfx == detail.id_currencyfx).GroupBy(x => x.id_currencyfx).Select(x => x.FirstOrDefault()).ToList())
                {
                    Detail += "Balance de Cierre : " + Math.Round(account_detail.debit, 2);
                    Detail += "\n--------------------------------" + "\n";
                }

                Detail += "\n--------------------------------" + "\n";
            }

            using (db db = new db())
            {
                decimal amount      = 0M;
                int[]   id_schedual = new int[10];
                int     index       = 0;

                foreach (app_account_detail account_detail in db.app_account_detail.Where(x => x.id_session == app_account_session.id_session && x.tran_type == app_account_detail.tran_types.Transaction).ToList())
                {
                    foreach (payment_schedual payment_schedual in account_detail.payment_detail.payment_schedual.ToList())
                    {
                        if (!id_schedual.Contains(payment_schedual.parent.id_payment_schedual))
                        {
                            if (payment_schedual.parent != null)
                            {
                                id_schedual[index] = payment_schedual.parent.id_payment_schedual;
                                amount            += payment_schedual.parent.debit;
                            }
                            else
                            {
                                amount += payment_schedual.credit;
                            }
                        }
                    }
                }

                Detail += "Total de Ventas Neto : " + Math.Round(amount, 2) + " \n";
            }
            Footer += "Cajero/a : " + UserName + " /n";
            Footer += "--------------------------------" + " \n";

            string Text = Header + Detail + Footer;

            Reciept     Reciept = new Reciept();
            PrintDialog pd      = new PrintDialog();

            FlowDocument document = new FlowDocument(new Paragraph(new Run(Text)));

            document.Name        = "ItemMovement";
            document.FontFamily  = new FontFamily("Courier New");
            document.FontSize    = 11.0;
            document.FontStretch = FontStretches.Normal;
            document.FontWeight  = FontWeights.Normal;

            document.PagePadding = new Thickness(20);

            document.PageHeight = double.NaN;
            document.PageWidth  = double.NaN;
            //document.

            //Specify minimum page sizes. Origintally 283, but was too small.
            document.MinPageWidth = 283;
            //Specify maximum page sizes.
            document.MaxPageWidth = 300;

            IDocumentPaginatorSource idpSource = document;

            try
            {
                Nullable <bool> print = pd.ShowDialog();
                if (print == true)
                {
                    pd.PrintDocument(idpSource.DocumentPaginator, Text);
                }
            }
            catch
            { MessageBox.Show("Output (Reciept Printer) not Found Error", "Error 101"); }
        }
Ejemplo n.º 14
0
        public string Payment(payment payment)
        {
            string Header = string.Empty;
            string Detail = string.Empty;
            string Footer = string.Empty;

            string CompanyName = string.Empty;

            app_company app_company = null;

            if (payment.app_company != null)
            {
                CompanyName = payment.app_company.name;
                app_company = payment.app_company;
            }
            else
            {
                using (db db = new db())
                {
                    if (db.app_company.Where(x => x.id_company == payment.id_company).FirstOrDefault() != null)
                    {
                        app_company = db.app_company.Where(x => x.id_company == payment.id_company).FirstOrDefault();
                        CompanyName = app_company.name;
                    }
                }
            }

            string UserName = "";

            if (payment.security_user != null)
            {
                UserName = payment.security_user.name;
            }
            else
            {
                using (db db = new db())
                {
                    if (db.security_user.Where(x => x.id_user == payment.id_user).FirstOrDefault() != null)
                    {
                        security_user security_user = db.security_user.Where(x => x.id_user == payment.id_user).FirstOrDefault();
                        UserName = security_user.name;
                    }
                }
            }



            string   TransNumber = payment.number;
            DateTime TransDate   = payment.trans_date;

            Header =
                CompanyName + "\n"
                + "R.U.C.   :" + app_company.gov_code + "\n"
                + app_company.address + "\n"
                + "***" + app_company.alias + "***" + "\n"
                + "Timbrado : " + payment.app_document_range.code + " Vto: " + payment.app_document_range.expire_date
                + "Fecha    : " + payment.trans_date
                + "\n"
                + "--------------------------------"
                + "Cuenta, Valor, Moneda" + "\n"
                + "--------------------------------" + "\n"
                + "\n";

            string InvoiceNumber = string.Empty;
            string CustomerName  = string.Empty;

            foreach (payment_detail d in payment.payment_detail)
            {
                string AccountName = string.Empty;

                if (d.app_account == null)
                {
                    using (db db = new db())
                    {
                        app_account app_account = db.app_account.Where(x => x.id_account == d.id_account).FirstOrDefault();
                        AccountName = app_account.name;
                    }
                }

                string currency = string.Empty;
                if (d.app_currencyfx == null)
                {
                    using (db db = new db())
                    {
                        currency = db.app_currencyfx.Where(x => x.id_currencyfx == d.id_currencyfx).FirstOrDefault().app_currency.name;
                    }
                }

                decimal?value = d.value;

                Detail = Detail
                         + AccountName + "\n"
                         + value.ToString() + "\t" + currency + "\n";

                if (InvoiceNumber == string.Empty)
                {
                    InvoiceNumber = d.payment_schedual.FirstOrDefault().sales_invoice.number;
                    CustomerName  = d.payment_schedual.FirstOrDefault().contact.name;
                }
            }

            Footer += "Factura  : " + InvoiceNumber + "\n";
            Footer += "--------------------------------" + "\n";

            string Text = Header + Detail + Footer;

            return(Text);
        }
Ejemplo n.º 15
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            if (db == null)
            {
                db = new db();
            }

            if (db.app_account.Where(x => x.id_account == CurrentSession.Id_Account).FirstOrDefault() != null)
            {
                ///Gets the Current
                app_account app_account = db.app_account.Where(x => x.id_account == CurrentSession.Id_Account).FirstOrDefault();
                is_active = app_account.is_active;
                RaisePropertyChanged("is_active");

                ///Assign a Session ID for this block of code.
                int id_session = 0;
                if (db.app_account_session.Where(x => x.id_account == app_account.id_account && x.is_active).FirstOrDefault() != null)
                {
                    id_session = db.app_account_session.Where(x => x.id_account == app_account.id_account && x.is_active).FirstOrDefault().id_session;
                }

                var app_account_detailList = app_account.app_account_detail.Where(x => x.payment_type.payment_behavior == payment_type.payment_behaviours.Normal && x.id_session == id_session)
                                             .GroupBy(ad => new { ad.id_currencyfx, ad.id_payment_type })
                                             .Select(s => new
                {
                    id_currencyfx  = s.Max(ad => ad.app_currencyfx.id_currencyfx),
                    id_paymenttype = s.Max(ad => ad.id_payment_type),
                    cur            = s.Max(ad => ad.app_currencyfx.app_currency.name),
                    payType        = s.Max(ad => ad.payment_type.name),
                    amount         = s.Sum(ad => ad.credit) - s.Sum(ad => ad.debit)
                }).ToList();

                var app_account_detailFinalList = app_account_detailList.GroupBy(ad => new { ad.cur, ad.payType }).Select(s => new
                {
                    id_currencyfx  = s.Max(x => x.id_currencyfx),
                    id_paymenttype = s.Max(x => x.id_paymenttype),
                    cur            = s.Max(ad => ad.cur),
                    payType        = s.Max(ad => ad.payType),
                    amount         = s.Sum(ad => ad.amount)
                }).ToList();

                listOpenAmt = new List <Class.clsTransferAmount>();

                if (app_account_detailFinalList.Count > 0)
                {
                    foreach (dynamic item in app_account_detailFinalList)
                    {
                        Class.clsTransferAmount clsTransferAmount = new Class.clsTransferAmount();
                        clsTransferAmount.PaymentTypeName = item.payType;
                        clsTransferAmount.amount          = item.amount;
                        clsTransferAmount.Currencyfxname  = item.cur;
                        clsTransferAmount.id_payment_type = item.id_paymenttype;
                        clsTransferAmount.id_currencyfx   = item.id_currencyfx;
                        listOpenAmt.Add(clsTransferAmount);
                    }

                    foreach (app_currencyfx app_currencyfx in db.app_currencyfx.Where(x => x.is_active).ToList())
                    {
                        if (listOpenAmt.Where(x => x.id_currencyfx == app_currencyfx.id_currencyfx).FirstOrDefault() == null)
                        {
                            foreach (payment_type payment_type in db.payment_type.Where(x => x.payment_behavior == payment_type.payment_behaviours.Normal).ToList())
                            {
                                Class.clsTransferAmount clsTransferAmount = new Class.clsTransferAmount();
                                clsTransferAmount.PaymentTypeName = payment_type.name;
                                clsTransferAmount.amount          = 0;
                                clsTransferAmount.Currencyfxname  = app_currencyfx.app_currency.name;
                                clsTransferAmount.id_payment_type = payment_type.id_payment_type;
                                clsTransferAmount.id_currencyfx   = app_currencyfx.id_currencyfx;
                                listOpenAmt.Add(clsTransferAmount);
                            }
                        }
                        else
                        {
                            foreach (payment_type payment_type in db.payment_type.Where(x => x.payment_behavior == payment_type.payment_behaviours.Normal).ToList())
                            {
                                if (listOpenAmt.Where(x => x.id_payment_type == payment_type.id_payment_type && x.id_currencyfx == app_currencyfx.id_currencyfx).FirstOrDefault() == null)
                                {
                                    Class.clsTransferAmount clsTransferAmount = new Class.clsTransferAmount();
                                    clsTransferAmount.PaymentTypeName = payment_type.name;
                                    clsTransferAmount.amount          = 0;
                                    clsTransferAmount.Currencyfxname  = app_currencyfx.app_currency.name;
                                    clsTransferAmount.id_payment_type = payment_type.id_payment_type;
                                    clsTransferAmount.id_currencyfx   = app_currencyfx.id_currencyfx;
                                    listOpenAmt.Add(clsTransferAmount);
                                }
                            }
                        }
                    }
                }
                else
                {
                    List <app_currency> app_currencyList = new List <app_currency>();
                    app_currencyList = db.app_currency.ToList();

                    foreach (app_currency app_currency in app_currencyList)
                    {
                        foreach (payment_type payment_type in db.payment_type.Where(x => x.payment_behavior == payment_type.payment_behaviours.Normal).ToList())
                        {
                            Class.clsTransferAmount clsTransferAmount = new Class.clsTransferAmount();
                            clsTransferAmount.PaymentTypeName = payment_type.name;

                            clsTransferAmount.id_payment_type = payment_type.id_payment_type;

                            clsTransferAmount.amount = app_account.app_account_detail.Where(x =>
                                                                                            x.app_currencyfx.id_currency == app_currency.id_currency &&
                                                                                            x.id_payment_type == payment_type.id_payment_type)
                                                       .Sum(x => x.credit - x.debit);

                            clsTransferAmount.Currencyfxname = app_currency.name;
                            clsTransferAmount.id_currencyfx  = db.app_currencyfx.Where(x => x.id_currency == app_currency.id_currency && x.is_active).FirstOrDefault().id_currencyfx;
                            listOpenAmt.Add(clsTransferAmount);
                        }
                    }
                }

                CashDataGrid.ItemsSource = listOpenAmt;
            }
        }
Ejemplo n.º 16
0
        private void btnActivateAccount_Click(object sender, RoutedEventArgs e)
        {
            if (db.app_account.Where(x => x.id_account == CurrentSession.Id_Account).FirstOrDefault() != null)
            {
                //Get the correct Account.
                app_account app_account = db.app_account.Where(x => x.id_account == CurrentSession.Id_Account).FirstOrDefault();

                app_account_session app_account_session = null;

                if (db.app_account_session.Where(x => x.id_account == CurrentSession.Id_Account && x.is_active).FirstOrDefault() != null)
                {
                    app_account_session = db.app_account_session.Where(x => x.id_account == CurrentSession.Id_Account && x.is_active).FirstOrDefault();
                }

                if (app_account_session != null && app_account_session.is_active)
                {
                    ///We need to CLOSE (InActive) the active Session.
                    ///For this we will need...
                    ///- Create Account Details for each type of Closing Balance.
                    ///- Close Session.
                    ///- Keep Account Active. (Previously we used to close Account, now Session handles that.)

                    //Loop through each account and create an Account Detail for the Opening Balance.
                    foreach (Class.clsTransferAmount counted_account_detail in listOpenAmt)
                    {
                        app_account_detail app_account_detail = new global::entity.app_account_detail();
                        app_account_detail.id_session      = app_account_session.id_session;
                        app_account_detail.id_account      = app_account_session.id_account;
                        app_account_detail.id_currencyfx   = counted_account_detail.id_currencyfx;
                        app_account_detail.id_payment_type = counted_account_detail.id_payment_type;
                        app_account_detail.debit           = counted_account_detail.amountCounted;
                        app_account_detail.comment         = "Closing Balance";
                        app_account_detail.tran_type       = app_account_detail.tran_types.Close;
                        app_account_detail.trans_date      = DateTime.Now;

                        //CHECK
                        app_account_detail.id_session = app_account_session.id_session;
                        app_account_session.cl_date   = DateTime.Now;
                        app_account_session.is_active = false;

                        db.app_account_detail.Add(app_account_detail);
                        app_account.is_active = false;
                        //Save Changes
                        db.SaveChanges();

                        is_active = app_account_session.is_active;
                        RaisePropertyChanged("is_active");
                    }

                    if (MessageBox.Show("Session is Closed, thank you for using CognitivoERP! "
                                        + "/n Would you like to Print the Z-Report?", "Print Z-Report?", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
                    {
                        try
                        {
                            entity.Brillo.Logic.Reciept TicketPrint = new entity.Brillo.Logic.Reciept();
                            TicketPrint.ZReport(app_account_session);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show("Error: Trying to print Z-Report : " + ex.Message);
                        }
                    }
                }
                else
                {
                    //We need to OPEN (Activate) the inactive Session..

                    //Create New Session.
                    app_account_session            = new entity.app_account_session();
                    app_account_session.id_account = app_account.id_account;

                    //Loop through each account and create an Account Detail for the Closing Balance.
                    foreach (Class.clsTransferAmount counted_account_detail in listOpenAmt)
                    {
                        app_account_detail app_account_detail = new global::entity.app_account_detail();
                        app_account_detail.id_account      = app_account.id_account;
                        app_account_detail.id_currencyfx   = counted_account_detail.id_currencyfx;
                        app_account_detail.id_payment_type = counted_account_detail.id_payment_type;
                        app_account_detail.credit          = counted_account_detail.amountCounted;
                        app_account_detail.comment         = "Opening Balance";
                        app_account_detail.tran_type       = app_account_detail.tran_types.Open;
                        app_account_detail.trans_date      = DateTime.Now;

                        app_account_session.app_account_detail.Add(app_account_detail);
                        db.app_account_session.Add(app_account_session);
                    }

                    app_account.is_active = true;
                    //Save Changes
                    db.SaveChanges();

                    is_active = app_account_session.is_active;
                    RaisePropertyChanged("is_active");
                    MessageBox.Show("Session is Open, Good Luck!");
                }

                if (app_accountViewSource != null)
                {
                    if (app_accountViewSource.View != null)
                    {
                        app_accountViewSource.View.Refresh();
                    }
                }

                //Reload Data
                db.Entry(app_account).Reload();
            }
        }