示例#1
0
        public void Approve()
        {
            foreach (purchase_return purchase_return in base.purchase_return.Local.Where(x => x.IsSelected == true))
            {
                if (purchase_return.Error == null)
                {
                    if (purchase_return.id_purchase_return == 0)
                    {
                        SaveChanges();
                    }

                    if (purchase_return.status != Status.Documents_General.Approved)
                    {
                        List <payment_schedual> payment_schedualList = new List <payment_schedual>();
                        Brillo.Logic.Payment    _Payment             = new Brillo.Logic.Payment();
                        payment_schedualList = _Payment.insert_Schedual(purchase_return);

                        Brillo.Logic.Stock   _Stock            = new Brillo.Logic.Stock();
                        List <item_movement> item_movementList = new List <item_movement>();
                        item_movementList = _Stock.insert_Stock(this, purchase_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 (purchase_return.purchase_invoice != null)
                        {
                            payment payment = new payment();
                            payment.id_contact = purchase_return.id_contact;
                            payment_detail payment_detailreturn = new payment_detail();
                            // payment_detailreturn.id_account = payment_quick.payment_detail.id_account;
                            payment_detailreturn.id_currencyfx = purchase_return.id_currencyfx;
                            if (base.payment_type.Where(x => x.payment_behavior == entity.payment_type.payment_behaviours.CreditNote).FirstOrDefault() != null)
                            {
                                payment_detailreturn.id_payment_type = base.payment_type.Where(x => x.payment_behavior == entity.payment_type.payment_behaviours.CreditNote).FirstOrDefault().id_payment_type;
                            }
                            else
                            {
                                System.Windows.Forms.MessageBox.Show("Please add crditnote payment type...");
                                return;
                            }


                            payment_detailreturn.id_sales_return = purchase_return.id_purchase_return;

                            payment_detailreturn.value = purchase_return.GrandTotal;

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

                            payment_detailreturn.payment_schedual.Add(payment_schedualReturn);
                            payment.payment_detail.Add(payment_detailreturn);
                            base.payments.Add(payment);
                        }
                        purchase_return.status = Status.Documents_General.Approved;
                        SaveChanges();
                    }
                }
                else if (purchase_return.Error != null)
                {
                    purchase_return.HasErrors = true;
                }
            }
        }
示例#2
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;
                    }
                }
            }
        }