Exemplo n.º 1
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();
        }
Exemplo n.º 2
0
        private void cbxPamentType_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            payment payment = paymentViewSource.View.CurrentItem as payment;

            if (cbxPamentType.SelectedItem != null)
            {
                entity.payment_type payment_type = cbxPamentType.SelectedItem as entity.payment_type;
                if (payment_type != null)
                {
                    if (payment_type.payment_behavior == global::entity.payment_type.payment_behaviours.WithHoldingVAT)
                    {
                        //If payment behaviour is WithHoldingVAT, hide everything.
                        stpaccount.Visibility        = Visibility.Collapsed;
                        stpcreditpurchase.Visibility = Visibility.Collapsed;
                        stpcreditsales.Visibility    = Visibility.Collapsed;
                    }
                    else if (payment_type.payment_behavior == global::entity.payment_type.payment_behaviours.CreditNote)
                    {
                        //If payment behaviour is Credit Note, then hide Account.
                        stpaccount.Visibility = Visibility.Collapsed;

                        //Check Mode.
                        if (Mode == Modes.Payable)
                        {
                            //If Payable, then Hide->Sales and Show->Payment
                            stpcreditsales.Visibility    = Visibility.Collapsed;
                            stpcreditpurchase.Visibility = Visibility.Visible;

                            CollectionViewSource purchase_returnViewSource = this.FindResource("purchase_returnViewSource") as CollectionViewSource;
                            PaymentDB.purchase_return.Where(x => x.id_contact == payment.id_contact).Load();
                            purchase_returnViewSource.Source = PaymentDB.purchase_return.Local;
                        }
                        else
                        {
                            //If Recievable, then Hide->Payment and Show->Sales
                            stpcreditpurchase.Visibility = Visibility.Collapsed;
                            stpcreditsales.Visibility    = Visibility.Visible;

                            CollectionViewSource sales_returnViewSource = this.FindResource("sales_returnViewSource") as CollectionViewSource;
                            PaymentDB.sales_return.Where(x => x.id_contact == payment.id_contact && (x.sales_invoice.GrandTotal - x.GrandTotal) > 0).Load();
                            sales_returnViewSource.Source = PaymentDB.sales_return.Local;
                        }
                    }
                    else
                    {
                        //If paymentbehaviour is not WithHoldingVAT & CreditNote, it must be Normal, so only show Account.
                        stpaccount.Visibility        = Visibility.Visible;
                        stpcreditpurchase.Visibility = Visibility.Collapsed;
                        stpcreditsales.Visibility    = Visibility.Collapsed;
                    }

                    //If PaymentType has Document to print, then show Document. Example, Checks or Bank Transfers.
                    if (payment_type.id_document > 0 && paymentpayment_detailViewSource != null && paymentpayment_detailViewSource.View != null)
                    {
                        stpDetailDocument.Visibility = Visibility.Visible;
                        payment_detail payment_detail = paymentpayment_detailViewSource.View.CurrentItem as payment_detail;
                        payment_detail.id_range = PaymentDB.app_document_range.Where(d => d.id_document == payment_type.id_document && d.is_active == true).Include(i => i.app_document).FirstOrDefault().id_range;
                    }
                    else
                    {
                        stpDetailDocument.Visibility = Visibility.Collapsed;
                    }
                }
            }
        }
Exemplo n.º 3
0
        public void Approve()
        {
            foreach (sales_return sales_return in base.sales_return.Local.Where(x => x.status != Status.Documents_General.Approved))
            {
                if (sales_return.status != Status.Documents_General.Approved &&
                    sales_return.IsSelected &&
                    sales_return.Error == null)
                {
                    if (sales_return.id_sales_return == 0)
                    {
                        SaveChanges();
                    }

                    if (sales_return.status != Status.Documents_General.Approved)
                    {
                        if (sales_return.number == null && sales_return.id_range != null)
                        {
                            Brillo.Logic.Range.branch_Code   = base.app_branch.Where(x => x.id_branch == sales_return.id_branch).FirstOrDefault().code;
                            Brillo.Logic.Range.terminal_Code = base.app_terminal.Where(x => x.id_terminal == sales_return.id_terminal).FirstOrDefault().code;
                            app_document_range app_document_range = base.app_document_range.Where(x => x.id_range == sales_return.id_range).FirstOrDefault();
                            sales_return.number = Brillo.Logic.Range.calc_Range(app_document_range, true);
                            sales_return.RaisePropertyChanged("number");
                            sales_return.is_issued = true;

                            //Save values bofore printing.
                            SaveChanges();

                            Brillo.Document.Start.Automatic(sales_return, app_document_range);
                        }
                        else
                        {
                            sales_return.is_issued = false;
                        }

                        List <payment_schedual> payment_schedualList = new List <payment_schedual>();
                        Brillo.Logic.Payment    _Payment             = new Brillo.Logic.Payment();
                        payment_schedualList = _Payment.insert_Schedual(sales_return);

                        Brillo.Logic.Stock   _Stock            = new Brillo.Logic.Stock();
                        List <item_movement> item_movementList = new List <item_movement>();
                        item_movementList = _Stock.insert_Stock(this, sales_return);

                        if (payment_schedualList != null && payment_schedualList.Count > 0)
                        {
                            payment_schedual.AddRange(payment_schedualList);
                        }
                        if (item_movementList != null && item_movementList.Count > 0)
                        {
                            item_movement.AddRange(item_movementList);
                        }

                        if (sales_return.sales_invoice != null)
                        {
                            payment payment = new payment();
                            payment.id_contact = sales_return.id_contact;
                            payment_detail payment_detailreturn = new payment_detail();
                            // payment_detailreturn.id_account = payment_quick.payment_detail.id_account;
                            payment_detailreturn.id_currencyfx = sales_return.id_currencyfx;

                            //Check for Credit Note PaymentType.
                            if (base.payment_type.Where(x => x.payment_behavior == entity.payment_type.payment_behaviours.CreditNote).FirstOrDefault() != null)
                            {
                                //Gets Payment Type form Database.
                                payment_detailreturn.id_payment_type = base.payment_type.Where(x => x.payment_behavior == entity.payment_type.payment_behaviours.CreditNote).FirstOrDefault().id_payment_type;
                            }
                            else
                            {
                                //In case Payment type doesn not exist, this will create it and try to fix the error.
                                payment_type payment_type = new payment_type();
                                payment_type.payment_behavior = entity.payment_type.payment_behaviours.CreditNote;
                                payment_type.name             = LocExtension.GetLocalizedValue <string>("Cognitivo:local:SalesReturn");
                                base.payment_type.Add(payment_type);

                                payment_detailreturn.payment_type = payment_type;
                            }

                            payment_detailreturn.id_sales_return = sales_return.id_sales_return;
                            payment_detailreturn.value           = sales_return.GrandTotal;

                            payment_schedual payment_schedualReturn = new payment_schedual();
                            payment_schedualReturn.debit         = 0;
                            payment_schedualReturn.credit        = sales_return.GrandTotal;
                            payment_schedualReturn.id_currencyfx = sales_return.id_currencyfx;
                            payment_schedualReturn.sales_return  = sales_return;
                            payment_schedualReturn.trans_date    = sales_return.trans_date;
                            payment_schedualReturn.expire_date   = sales_return.trans_date;
                            payment_schedualReturn.status        = entity.Status.Documents_General.Approved;
                            payment_schedualReturn.id_contact    = sales_return.id_contact;
                            payment_schedualReturn.can_calculate = true;
                            payment_schedualReturn.parent        = sales_return.sales_invoice.payment_schedual.FirstOrDefault();

                            payment_detailreturn.payment_schedual.Add(payment_schedualReturn);
                            payment.payment_detail.Add(payment_detailreturn);
                            base.payments.Add(payment);
                        }

                        sales_return.status = Status.Documents_General.Approved;
                        SaveChanges();
                    }

                    else if (sales_return.Error != null)
                    {
                        sales_return.HasErrors = true;
                    }
                }
            }
        }
Exemplo n.º 4
0
        public void MakePayment(payment_schedual Parent_Schedual, payment payment, bool RequirePrint)
        {
            foreach (payment_detail payment_detail in payment.payment_detail.Where(x => x.IsSelected))
            {
                if (payment_detail.id_payment_schedual > 0)
                {
                    Parent_Schedual = base.payment_schedual.Where(x => x.id_payment_schedual == payment_detail.id_payment_schedual).FirstOrDefault();
                }

                ///Creates counter balanced in payment schedual.
                ///Use this to Balance pending payments.
                payment_schedual balance_payment_schedual = new payment_schedual();

                //Assigns appCurrencyFX ID & Entity
                if (payment_detail.id_currencyfx == 0)
                {
                    payment_detail.id_currencyfx  = app_currencyfx.Where(x => x.app_currency.is_priority && x.is_active).FirstOrDefault().id_currencyfx;
                    payment_detail.app_currencyfx = app_currencyfx.Where(x => x.app_currency.is_priority && x.is_active).FirstOrDefault();
                }

                ///Assigns appCurrencyFX Entity which is needed for Printing.
                if (payment_detail.id_currencyfx > 0 && payment_detail.app_currencyfx == null)
                {
                    payment_detail.app_currencyfx = app_currencyfx.Where(x => x.id_currencyfx == payment_detail.id_currencyfx && x.is_active).FirstOrDefault();
                }

                ///If by chance Payment Type is Blank, will get Default Payment Type.
                if (payment_detail.id_payment_type == 0)
                {
                    payment_detail.id_payment_type = payment_type.Where(x => x.is_default).FirstOrDefault().id_payment_type;
                }

                ///Checks if Account ID is set.
                if (payment_detail.id_account == 0 || payment_detail.id_account == null)
                {
                    payment_detail.id_account = CurrentSession.Id_Account;
                }

                ///Logic for Value in Balance Payment Schedual.
                if (Parent_Schedual.id_purchase_invoice > 0 || Parent_Schedual.id_purchase_order > 0 || Parent_Schedual.id_sales_return > 0)
                {
                    ///If PaymentDetail Value is Negative.
                    ///
                    if (payment_detail.app_currencyfx.id_currency != Parent_Schedual.app_currencyfx.id_currency)
                    {
                        balance_payment_schedual.debit = Math.Abs(Currency.convert_Values(payment_detail.value, payment_detail.id_currencyfx, Parent_Schedual.id_currencyfx, App.Modules.Purchase));
                    }
                    else
                    {
                        balance_payment_schedual.debit = Math.Abs(payment_detail.value);
                    }
                }
                else
                {
                    ///If PaymentDetail Value is Positive.
                    if (payment_detail.app_currencyfx.id_currency != Parent_Schedual.app_currencyfx.id_currency)
                    {
                        balance_payment_schedual.credit = Currency.convert_Values(payment_detail.value, payment_detail.id_currencyfx, Parent_Schedual.id_currencyfx, App.Modules.Sales);
                    }
                    else
                    {
                        balance_payment_schedual.credit = payment_detail.value;
                    }
                }

                balance_payment_schedual.parent        = Parent_Schedual;
                balance_payment_schedual.status        = Status.Documents_General.Approved;
                balance_payment_schedual.id_contact    = Parent_Schedual.id_contact;
                balance_payment_schedual.id_currencyfx = Parent_Schedual.id_currencyfx;
                balance_payment_schedual.trans_date    = payment_detail.trans_date;
                balance_payment_schedual.expire_date   = Parent_Schedual.expire_date;

                string ModuleName = string.Empty;

                ///
                if (Parent_Schedual.id_purchase_invoice != null)
                {
                    balance_payment_schedual.id_purchase_invoice = Parent_Schedual.id_purchase_invoice;
                    ModuleName = "PurchaseInvoice";
                }

                ///

                if (payment_detail.payment_schedual.FirstOrDefault() != null)
                {
                    balance_payment_schedual.id_purchase_order = payment_detail.payment_schedual.FirstOrDefault().id_purchase_order;
                    ModuleName = "PurchaseOrder";
                }

                ///
                if (Parent_Schedual.id_purchase_return != null)
                {
                    balance_payment_schedual.id_purchase_return = Parent_Schedual.id_purchase_return;
                    ModuleName = "PurchaseReturn";
                }

                ///
                if (Parent_Schedual.id_sales_invoice != null)
                {
                    balance_payment_schedual.id_sales_invoice = Parent_Schedual.id_sales_invoice;
                    ModuleName = "SalesInvoice";
                }

                ///
                if (Parent_Schedual.id_sales_order != null)
                {
                    balance_payment_schedual.id_sales_order = Parent_Schedual.id_sales_order;
                    ModuleName = "SalesOrder";
                }

                ///
                if (payment_detail.id_sales_return != null)
                {
                    balance_payment_schedual.id_sales_return = Parent_Schedual.id_sales_return;
                    ModuleName = "SalesReturn";
                }

                //Add Balance Payment Schedual into Context.
                payment_detail.payment_schedual.Add(balance_payment_schedual);


                ///Code to specify Accounts.
                ///
                payment_type _payment_type = payment_type.Where(x => x.id_payment_type == payment_detail.id_payment_type).FirstOrDefault();
                if (_payment_type.payment_behavior == entity.payment_type.payment_behaviours.Normal)
                {
                    ///Creates new Account Detail for each Payment Detail.
                    app_account_detail app_account_detail = new app_account_detail();

                    app_account_detail.id_account        = (int)payment_detail.id_account;
                    app_account_detail.id_currencyfx     = payment_detail.id_currencyfx;
                    app_account_detail.id_payment_type   = payment_detail.id_payment_type;
                    app_account_detail.id_payment_detail = payment_detail.id_payment_detail;
                    app_account_detail.trans_date        = payment_detail.trans_date;

                    if (_payment_type.is_direct)
                    {
                        app_account_detail.status = Status.Documents_General.Approved;
                    }
                    else
                    {
                        app_account_detail.status = Status.Documents_General.Pending;
                    }

                    ///Gets the Session ID necesary for cashier movement.
                    if (base.app_account_session.Where(x => x.id_account == payment_detail.id_account && x.is_active).FirstOrDefault() != null)
                    {
                        app_account_detail.id_session = base.app_account_session.Where(x => x.id_account == payment_detail.id_account && x.is_active).FirstOrDefault().id_session;
                    }

                    //Logic for Account Detail based on Payment Detail Logic.
                    if (Parent_Schedual.id_purchase_invoice > 0 || Parent_Schedual.id_purchase_order > 0 || Parent_Schedual.id_sales_return > 0)
                    {
                        ///If PaymentDetail Value is Negative.
                        app_account_detail.debit = Math.Abs(Convert.ToDecimal(payment_detail.value));
                    }
                    else
                    {
                        ///If PaymentDetail Value is Positive.
                        app_account_detail.credit = Convert.ToDecimal(payment_detail.value);
                    }

                    ///Comment with Module Name and Contact.
                    ///Insert AccountDetail into Context.
                    ///
                    string number = "";
                    if (Parent_Schedual.id_purchase_invoice > 0 || Parent_Schedual.id_purchase_order > 0 || Parent_Schedual.id_sales_return > 0)
                    {
                        if (Parent_Schedual.purchase_invoice != null)
                        {
                            number = Parent_Schedual.purchase_invoice.number;
                        }
                    }
                    else
                    {
                        if (Parent_Schedual.sales_invoice != null)
                        {
                            number = Parent_Schedual.sales_invoice.number;
                        }
                    }
                    app_account_detail.comment   = Brillo.Localize.StringText(ModuleName) + " " + number + " | " + Parent_Schedual.contact.name;
                    app_account_detail.tran_type = app_account_detail.tran_types.Transaction;
                    base.app_account_detail.Add(app_account_detail);
                }
                //pankeel
            }

            payment.status = Status.Documents_General.Approved;
            app_document_range app_document_range = base.app_document_range.Where(x => x.id_range == payment.id_range).FirstOrDefault();

            payment.number = Brillo.Logic.Range.calc_Range(app_document_range, true);
            payment.RaisePropertyChanged("number");
            base.SaveChanges();


            if (RequirePrint)
            {
                entity.Brillo.Document.Start.Automatic(payment, app_document_range);
            }
        }