コード例 #1
0
ファイル: PaymentDB.cs プロジェクト: mercaditu/ERP
        public void Approve(int id_payment_schedual, bool PrintRequire)
        {
            foreach (payment payment in payments.Local.Where(x => x.status != Status.Documents_General.Approved && x.IsSelected))
            {
                if (payment.id_payment == 0)
                {
                    SaveChanges();
                }

                //entity.Brillo.Logic.AccountReceivable AccountReceivable = new entity.Brillo.Logic.AccountReceivable();
                payment_schedual _payment_schedual = payment_schedual.Where(x => x.id_payment_schedual == id_payment_schedual).FirstOrDefault();

                //Creates Balanced Payment Schedual and Account Detail (if necesary).
                MakePayment(_payment_schedual, payment, PrintRequire);
            }
        }
コード例 #2
0
ファイル: PurchaseReturnDB.cs プロジェクト: mercaditu/ERP
        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;
                }
            }
        }
コード例 #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;
                    }
                }
            }
        }
コード例 #4
0
ファイル: PaymentDB.cs プロジェクト: mercaditu/ERP
        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);
            }
        }