Beispiel #1
0
        public void Approve(bool IsDiscountStock)
        {
            NumberOfRecords = 0;

            foreach (sales_packing sales_packing in base.sales_packing.Local)
            {
                if (sales_packing.IsSelected && sales_packing.Error == null)
                {
                    if (sales_packing.id_sales_packing == 0)
                    {
                        SaveChanges();
                    }

                    if (sales_packing.status != Status.Documents_General.Approved)
                    {
                        if (IsDiscountStock)
                        {
                            Brillo.Logic.Stock   _Stock            = new Brillo.Logic.Stock();
                            List <item_movement> item_movementList = new List <item_movement>();
                            item_movementList = _Stock.insert_Stock(this, sales_packing);

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

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

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

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

                    NumberOfRecords += 1;
                }

                if (sales_packing.Error != null)
                {
                    sales_packing.HasErrors = true;
                }
            }
        }
Beispiel #2
0
        public bool Approve()
        {
            NumberOfRecords = 0;
            foreach (sales_budget sales_budget in base.sales_budget.Local.Where(x => x.status != Status.Documents_General.Approved))
            {
                if (sales_budget.status != Status.Documents_General.Approved &&
                    sales_budget.IsSelected &&
                    sales_budget.Error == null)
                {
                    if (sales_budget.id_sales_budget == 0)
                    {
                        SaveChanges();
                    }

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

                            Brillo.Document.Start.Automatic(sales_budget, app_document_range);

                            //Save Changes before Printing, so that all fields show up.
                            sales_budget.status    = Status.Documents_General.Approved;
                            sales_budget.timestamp = DateTime.Now;
                            SaveChanges();
                        }
                        else
                        {
                            sales_budget.is_issued = false;
                            sales_budget.status    = Status.Documents_General.Approved;
                            sales_budget.timestamp = DateTime.Now;
                            SaveChanges();
                        }
                    }

                    NumberOfRecords        += 1;
                    sales_budget.IsSelected = false;
                }

                if (sales_budget.Error != null)
                {
                    sales_budget.HasErrors = true;
                }
            }

            return(true);
        }
Beispiel #3
0
        //private void add_CRM(purchase_packing purchase_packing)
        //{
        //    if (purchase_packing.id_purchase_packing == 0 || purchase_packing == null)
        //    {
        //        crm_opportunity crm_opportunity = new crm_opportunity();
        //        crm_opportunity.id_contact = purchase_packing.id_contact;

        //        crm_opportunity.purchase_packing.Add(purchase_packing);
        //        base.crm_opportunity.Add(crm_opportunity);
        //    }
        //    else
        //    {
        //        crm_opportunity crm_opportunity = sales_order.Where(x => x.id_sales_order == purchase_packing.id_purchase_packing).FirstOrDefault().crm_opportunity;
        //        crm_opportunity.purchase_packing.Add(purchase_packing);
        //        base.crm_opportunity.Attach(crm_opportunity);
        //    }
        //}

        public void Approve(bool IsDiscountStock)
        {
            NumberOfRecords = 0;

            foreach (purchase_packing purchase_packing in base.purchase_packing.Local)
            {
                if (purchase_packing.IsSelected && purchase_packing.Error == null)
                {
                    if (purchase_packing.id_purchase_packing == 0)
                    {
                        SaveChanges();
                    }

                    if (purchase_packing.status != Status.Documents_General.Approved)
                    {
                        if (IsDiscountStock)
                        {
                            Brillo.Logic.Stock   _Stock            = new Brillo.Logic.Stock();
                            List <item_movement> item_movementList = new List <item_movement>();
                            item_movementList = _Stock.insert_Stock(this, purchase_packing);

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

                        if (purchase_packing.number == null && purchase_packing.id_range > 0)
                        {
                            Brillo.Logic.Range.branch_Code = base.app_branch.Where(x => x.id_branch == purchase_packing.id_branch).FirstOrDefault().code;
                            app_document_range app_document_range = base.app_document_range.Where(x => x.id_range == purchase_packing.id_range).FirstOrDefault();
                            purchase_packing.number = Brillo.Logic.Range.calc_Range(app_document_range, true);
                            purchase_packing.RaisePropertyChanged("number");
                        }


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

                    NumberOfRecords += 1;
                }

                if (purchase_packing.Error != null)
                {
                    purchase_packing.HasErrors = true;
                }
            }
        }
Beispiel #4
0
        public void Approve()
        {
            foreach (payment_promissory_note payment_promissory_note in base.payment_promissory_note.Local.Where(x =>
                                                                                                                 x.status == Status.Documents.Pending &&
                                                                                                                 x.IsSelected && x.Error == null))
            {
                payment_promissory_note.status = Status.Documents.Issued;
                app_document_range app_document_range = base.app_document_range.Where(x => x.id_range == payment_promissory_note.id_range).FirstOrDefault();
                payment_promissory_note.note_number = Brillo.Logic.Range.calc_Range(app_document_range, true);
                payment_promissory_note.RaisePropertyChanged("note_number");
                entity.Brillo.Document.Start.Automatic(payment_promissory_note, payment_promissory_note.app_document_range);
            }

            base.SaveChanges();
        }
Beispiel #5
0
        /// <summary>
        /// Creates an instance of Payment entity with corresponding data needed.
        /// </summary>
        /// <param name="Is_PaymentRecievable">Specify if Payment being created is meant to Recieve (Sales) then True., Payable (Purchase) then False.</param>
        /// <returns>Payment Instance ready for use.</returns>
        public payment New(bool Is_PaymentRecievable)
        {
            payment payment = new entity.payment();

            payment.status = Status.Documents_General.Pending;
            payment.State  = EntityState.Added;

            if (Is_PaymentRecievable)
            {
                payment.id_range = GetDefault.Return_RangeID(entity.App.Names.PaymentUtility);
                app_document_range _app_document_range = app_document_range.Where(x => x.id_range == payment.id_range).FirstOrDefault();
                if (_app_document_range != null)
                {
                    payment.app_document_range = _app_document_range;
                }
            }

            payment.IsSelected = true;
            return(payment);
        }
Beispiel #6
0
        public sales_invoice New(int TransDate_OffSet, bool IsMigration)
        {
            sales_invoice sales_invoice = new sales_invoice();

            sales_invoice.State      = EntityState.Added;
            sales_invoice.status     = Status.Documents_General.Pending;
            sales_invoice.IsSelected = true;
            sales_invoice.trans_type = Status.TransactionTypes.Normal;
            sales_invoice.trans_date = DateTime.Now.AddDays(TransDate_OffSet);
            sales_invoice.timestamp  = DateTime.Now;

            //Navigation Properties
            sales_invoice.id_currencyfx = Brillo.Currency.get_DefaultFX(this).id_currencyfx;

            sales_invoice.app_branch = app_branch.Where(x => x.id_branch == CurrentSession.Id_Branch).FirstOrDefault();

            //This is to skip query code in case of Migration. Helps speed up migrations.
            if (IsMigration == false)
            {
                app_document_range app_document_range = entity.Brillo.Logic.Range.List_Range(this, entity.App.Names.SalesInvoice, CurrentSession.Id_Branch, CurrentSession.Id_Terminal).FirstOrDefault();
                if (app_document_range != null)
                {
                    //Gets List of Ranges avaiable for this Document.
                    sales_invoice.id_range = app_document_range.id_range;
                }

                app_contract _app_contract = app_contract.Where(x => x.is_active && x.id_company == CurrentSession.Id_Company && x.is_default && x.app_contract_detail.Sum(y => y.coefficient) > 0).FirstOrDefault();
                if (_app_contract != null)
                {
                    app_condition _app_condition = _app_contract.app_condition;
                    if (_app_condition != null)
                    {
                        sales_invoice.app_condition = _app_condition;
                        sales_invoice.app_contract  = _app_contract;
                    }
                }
            }

            return(sales_invoice);
        }
Beispiel #7
0
        public bool Approve(bool IsDiscountStock)
        {
            NumberOfRecords = 0;
            foreach (sales_invoice invoice in sales_invoice.Local.Where(x =>
                                                                        x.status != Status.Documents_General.Approved &&
                                                                        x.IsSelected && x.Error == null))
            {
                SpiltInvoice(invoice);
            }

            foreach (sales_invoice invoice in sales_invoice.Local.Where(x =>
                                                                        x.status != Status.Documents_General.Approved &&
                                                                        x.IsSelected && x.Error == null))
            {
                if (invoice.id_sales_invoice == 0)
                {
                    SaveChanges();
                }
                if (Check_CreditLimit(invoice))
                {
                    //Logic
                    List <payment_schedual> payment_schedualList = new List <payment_schedual>();
                    Brillo.Logic.Payment    _Payment             = new Brillo.Logic.Payment();
                    payment_schedualList = _Payment.insert_Schedual(invoice);

                    //Save Promisory Note first, because it is referenced in Payment Schedual
                    if (_Payment.payment_promissory_noteLIST != null && _Payment.payment_promissory_noteLIST.Count > 0)
                    {
                        payment_promissory_note.AddRange(_Payment.payment_promissory_noteLIST);
                    }

                    //Payment Schedual
                    if (payment_schedualList != null && payment_schedualList.Count > 0)
                    {
                        payment_schedual.AddRange(payment_schedualList);
                    }
                    //Item Movement
                    if (IsDiscountStock)
                    {
                        Insert_Items_2_Movement(invoice);
                    }

                    if ((invoice.number == null || invoice.number == string.Empty) && invoice.id_range > 0)
                    {
                        if (invoice.id_branch > 0)
                        {
                            Brillo.Logic.Range.branch_Code = app_branch.Where(x => x.id_branch == invoice.id_branch).FirstOrDefault().code;
                        }
                        if (invoice.id_terminal > 0)
                        {
                            Brillo.Logic.Range.terminal_Code = app_terminal.Where(x => x.id_terminal == invoice.id_terminal).FirstOrDefault().code;
                        }

                        app_document_range app_document_range = base.app_document_range.Where(x => x.id_range == invoice.id_range).FirstOrDefault();

                        invoice.is_issued = true;
                        invoice.number    = Brillo.Logic.Range.calc_Range(app_document_range, true);
                        invoice.RaisePropertyChanged("number");
                        invoice.status    = Status.Documents_General.Approved;
                        invoice.timestamp = DateTime.Now;



                        //Generate BarCode

                        //Save Changes before Printing, so that all fields show up.
                        SaveChanges();

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

                        invoice.status    = Status.Documents_General.Approved;
                        invoice.timestamp = DateTime.Now;

                        SaveChanges();
                    }

                    NumberOfRecords   += 1;
                    invoice.IsSelected = false;
                }
                return(true);
            }

            return(false);
        }
Beispiel #8
0
        public bool Approve()
        {
            NumberOfRecords = 0;

            foreach (purchase_order purchase_order in base.purchase_order.Local.Where(x => x.IsSelected == true))
            {
                if (purchase_order.Error == null)
                {
                    if (purchase_order.id_purchase_order == 0)
                    {
                        SaveChanges();
                    }

                    if (purchase_order.status != Status.Documents_General.Approved)
                    {
                        if (purchase_order.number == null && purchase_order.id_range != null)
                        {
                            //Brillo.Logic.Document _Document = new Brillo.Logic.Document();
                            Brillo.Logic.Range.branch_Code   = base.app_branch.Where(x => x.id_branch == purchase_order.id_branch).FirstOrDefault().code;
                            Brillo.Logic.Range.terminal_Code = base.app_terminal.Where(x => x.id_terminal == purchase_order.id_terminal).FirstOrDefault().code;
                            app_document_range app_document_range = base.app_document_range.Where(x => x.id_range == purchase_order.id_range).FirstOrDefault();
                            purchase_order.number = Brillo.Logic.Range.calc_Range(app_document_range, true);
                            purchase_order.RaisePropertyChanged("number");
                            purchase_order.is_issued = true;
                        }
                        else
                        {
                            purchase_order.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(purchase_order);

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

                        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);
                        }

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

                    if (purchase_order.is_issued)
                    {
                        app_document_range app_document_range = base.app_document_range.Where(x => x.id_range == purchase_order.id_range).FirstOrDefault();
                        Brillo.Document.Start.Automatic(purchase_order, app_document_range);
                    }

                    NumberOfRecords          += 1;
                    purchase_order.IsSelected = false;
                }
                else if (purchase_order.Error != null)
                {
                    purchase_order.HasErrors = true;
                }
            }

            return(true);
        }
Beispiel #9
0
        public int ApproveDestination(int ID_BranchOrigin, int ID_BranchDestination, bool MoveByTruck)
        {
            NumberOfRecords = 0;

            foreach (item_transfer item_transfer in base.item_transfer.Local.Where(x => x.IsSelected))
            {
                foreach (item_transfer_detail item_transfer_detail in item_transfer.item_transfer_detail.Where(x => x.IsSelected && x.status != Status.Documents_General.Approved))
                {
                    if (item_transfer_detail.item_product != null)
                    {
                        Credit_Items_Destination(item_transfer_detail, ID_BranchOrigin, ID_BranchDestination, MoveByTruck);

                        NumberOfRecords += 1;

                        item_transfer_detail.status = Status.Documents_General.Approved;
                        item_transfer_detail.RaisePropertyChanged("status");
                        item_transfer.status = Status.Transfer.Approved;
                        item_transfer.RaisePropertyChanged("status");
                    }
                }

                ///Print Document only if
                if ((item_transfer.number == null || item_transfer.number == string.Empty) && item_transfer.id_range > 0)
                {
                    if (item_transfer.id_branch > 0)
                    {
                        if (base.app_branch.Where(x => x.id_branch == item_transfer.id_branch).FirstOrDefault() != null)
                        {
                            Brillo.Logic.Range.branch_Code = base.app_branch.Where(x => x.id_branch == item_transfer.id_branch).FirstOrDefault().code;
                        }
                    }

                    if (item_transfer.id_terminal > 0)
                    {
                        if (base.app_terminal.Where(x => x.id_terminal == item_transfer.id_terminal).FirstOrDefault() != null)
                        {
                            Brillo.Logic.Range.terminal_Code = base.app_terminal.Where(x => x.id_terminal == item_transfer.id_terminal).FirstOrDefault().code;
                        }
                    }

                    if (item_transfer.id_user > 0)
                    {
                        if (base.security_user.Where(x => x.id_user == item_transfer.id_user).FirstOrDefault() != null)
                        {
                            Brillo.Logic.Range.user_Code = base.security_user.Where(x => x.id_user == item_transfer.id_user).FirstOrDefault().code;
                        }
                    }

                    if (item_transfer.id_project > 0)
                    {
                        if (base.projects.Where(x => x.id_project == item_transfer.id_project).FirstOrDefault() != null)
                        {
                            Brillo.Logic.Range.project_Code = base.projects.Where(x => x.id_project == item_transfer.id_project).FirstOrDefault().code;
                        }
                    }

                    app_document_range app_document_range = base.app_document_range.Where(x => x.id_range == item_transfer.id_range).FirstOrDefault();
                    item_transfer.number = Brillo.Logic.Range.calc_Range(app_document_range, true);
                    item_transfer.RaisePropertyChanged("number");
                }
            }

            base.SaveChanges();

            return(NumberOfRecords);
        }
Beispiel #10
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;
                    }
                }
            }
        }
Beispiel #11
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);
            }
        }
Beispiel #12
0
        public void Approve()
        {
            NumberOfRecords = 0;

            foreach (purchase_tender purchase_tender in base.purchase_tender.Local.Where(x => x.IsSelected == true))
            {
                if (purchase_tender.id_purchase_tender == 0)
                {
                    SaveChanges();
                }

                if (purchase_tender.status != Status.Documents_General.Approved)
                {
                    foreach (purchase_tender_contact purchase_tender_contact in purchase_tender.purchase_tender_contact_detail)
                    {
                        purchase_order purchase_order = new purchase_order();

                        purchase_order.id_purchase_tender = purchase_tender.id_purchase_tender;
                        purchase_order.id_department      = purchase_tender.id_department;
                        purchase_order.id_currencyfx      = purchase_tender_contact.id_currencyfx;
                        purchase_order.recieve_date_est   = purchase_tender_contact.recieve_date_est;

                        purchase_order.id_contact   = purchase_tender_contact.id_contact;
                        purchase_order.contact      = purchase_tender_contact.contact;
                        purchase_order.id_contract  = purchase_tender_contact.id_contract;
                        purchase_order.id_condition = purchase_tender_contact.id_condition;
                        purchase_order.id_project   = purchase_tender.id_project;
                        purchase_order.project      = purchase_tender.project;

                        ///Don't approve if there is nothing selected. Sometimes Users make mistakes.
                        if (purchase_tender_contact.purchase_tender_detail.Where(x => x.IsSelected).Count() == 0)
                        {
                            return;
                        }

                        ///Reject all non selected Details.
                        foreach (purchase_tender_detail purchase_tender_detail in purchase_tender_contact.purchase_tender_detail.Where(x => x.IsSelected == false))
                        {
                            purchase_tender_detail.status = Status.Documents_General.Rejected;
                        }

                        ///Approve all selected Details.
                        foreach (purchase_tender_detail purchase_tender_detail in purchase_tender_contact.purchase_tender_detail.Where(x => x.IsSelected))
                        {
                            purchase_order_detail purchase_order_detail = new purchase_order_detail();
                            purchase_order_detail.purchase_tender_detail    = purchase_tender_detail;
                            purchase_order_detail.id_purchase_tender_detail = purchase_tender_detail.id_purchase_tender_detail;

                            if (purchase_tender_detail.purchase_tender_item.item != null)
                            {
                                purchase_order_detail.item             = purchase_tender_detail.purchase_tender_item.item;
                                purchase_order_detail.id_item          = purchase_tender_detail.purchase_tender_item.id_item;
                                purchase_order_detail.item_description = purchase_tender_detail.purchase_tender_item.item_description;

                                app_cost_center app_cost_center = base.app_cost_center.Where(x => x.is_active == true && x.is_product).FirstOrDefault();
                                if (app_cost_center != null)
                                {
                                    purchase_order_detail.id_cost_center = app_cost_center.id_cost_center;
                                }
                                else
                                {
                                    app_cost_center            = new app_cost_center();
                                    app_cost_center.name       = "Merchandise";
                                    app_cost_center.is_product = true;
                                    base.app_cost_center.Add(app_cost_center);
                                    purchase_order_detail.app_cost_center = app_cost_center;
                                }
                            }
                            else
                            {
                                purchase_order_detail.item_description = purchase_tender_detail.purchase_tender_item.item_description;

                                app_cost_center app_cost_center = base.app_cost_center.Where(x => x.is_active == true && x.is_administrative).FirstOrDefault();
                                if (app_cost_center != null)
                                {
                                    purchase_order_detail.id_cost_center = app_cost_center.id_cost_center;
                                }
                                else
                                {
                                    app_cost_center      = new app_cost_center();
                                    app_cost_center.name = "Administrative";
                                    app_cost_center.is_administrative = true;
                                    base.app_cost_center.Add(app_cost_center);
                                    purchase_order_detail.app_cost_center = app_cost_center;
                                }
                            }

                            purchase_order_detail.unit_cost    = purchase_tender_detail.unit_cost;
                            purchase_order_detail.quantity     = purchase_tender_detail.quantity;
                            purchase_order_detail.id_vat_group = purchase_tender_detail.id_vat_group;

                            foreach (purchase_tender_dimension purchase_tender_dimension in purchase_tender_detail.purchase_tender_item.purchase_tender_dimension)
                            {
                                purchase_order_dimension purchase_order_dimension = new purchase_order_dimension();
                                purchase_order_dimension.id_company = CurrentSession.Id_Company;

                                purchase_order_dimension.id_dimension   = purchase_tender_dimension.id_dimension;
                                purchase_order_dimension.id_measurement = purchase_tender_dimension.id_measurement;
                                purchase_order_dimension.value          = purchase_tender_dimension.value;
                                purchase_order_detail.purchase_order_dimension.Add(purchase_order_dimension);
                            }

                            purchase_order.purchase_order_detail.Add(purchase_order_detail);
                            purchase_tender_detail.IsSelected = false;
                            purchase_tender_detail.status     = Status.Documents_General.Approved;
                        }

                        NumberOfRecords += 1;
                        base.purchase_order.Add(purchase_order);
                    }

                    if (base.app_document_range.Where(x => x.app_document.id_application == App.Names.PurchaseTender).FirstOrDefault() != null)
                    {
                        purchase_tender.id_range = base.app_document_range.Where(x => x.app_document.id_application == App.Names.PurchaseTender).FirstOrDefault().id_range;
                        app_document_range app_document_range = base.app_document_range.Where(x => x.id_range == purchase_tender.id_range).FirstOrDefault();
                        purchase_tender.number = Brillo.Logic.Range.calc_Range(app_document_range, true);
                        purchase_tender.RaisePropertyChanged("number");
                    }

                    purchase_tender.status = Status.Documents_General.Approved;
                    SaveChanges();
                    purchase_tender.IsSelected = false;
                }
            }
        }
Beispiel #13
0
        public bool Approve()
        {
            foreach (sales_order sales_order in base.sales_order.Local.Where(x => x.status != Status.Documents_General.Approved))
            {
                NumberOfRecords = 0;

                if (sales_order.status != Status.Documents_General.Approved &&
                    sales_order.IsSelected &&
                    sales_order.Error == null)
                {
                    if (sales_order.id_sales_order == 0)
                    {
                        SaveChanges();
                    }

                    if (sales_order.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(sales_order);

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

                        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_order.number == null && sales_order.id_range != null)
                        {
                            Brillo.Logic.Range.branch_Code   = base.app_branch.Where(x => x.id_branch == sales_order.id_branch).FirstOrDefault().code;
                            Brillo.Logic.Range.terminal_Code = base.app_terminal.Where(x => x.id_terminal == sales_order.id_terminal).FirstOrDefault().code;
                            app_document_range app_document_range = base.app_document_range.Where(x => x.id_range == sales_order.id_range).FirstOrDefault();
                            sales_order.number = Brillo.Logic.Range.calc_Range(app_document_range, true);
                            sales_order.RaisePropertyChanged("number");
                            sales_order.is_issued = true;

                            //Save Changes before Printing, so that all fields show up.
                            sales_order.status    = Status.Documents_General.Approved;
                            sales_order.timestamp = DateTime.Now;
                            SaveChanges();

                            Brillo.Document.Start.Automatic(sales_order, app_document_range);
                        }
                        else
                        {
                            sales_order.is_issued = false;
                            sales_order.status    = Status.Documents_General.Approved;
                            sales_order.timestamp = DateTime.Now;
                            SaveChanges();
                        }


                        item_request item_request = new item_request();
                        item_request.name    = sales_order.contact.name;
                        item_request.comment = sales_order.comment;


                        item_request.id_sales_order = sales_order.id_sales_order;
                        item_request.id_branch      = sales_order.id_branch;


                        item_request.request_date = (DateTime)sales_order.delivery_date;

                        foreach (sales_order_detail data in sales_order.sales_order_detail.Where(x => x.IsSelected))
                        {
                            item_request_detail item_request_detail = new entity.item_request_detail();
                            item_request_detail.date_needed_by        = (DateTime)sales_order.delivery_date;
                            item_request_detail.id_sales_order_detail = data.id_sales_order_detail;
                            item_request_detail.urgency = entity.item_request_detail.Urgencies.Medium;
                            int idItem = data.item.id_item;
                            item_request_detail.id_item = idItem;
                            item item = base.items.Where(x => x.id_item == idItem).FirstOrDefault();
                            if (item != null)
                            {
                                item_request_detail.item    = item;
                                item_request_detail.comment = item_request_detail.item.name;
                            }


                            item_request_detail.quantity = data.quantity;

                            foreach (item_dimension item_dimension in item.item_dimension)
                            {
                                item_request_dimension item_request_dimension = new item_request_dimension();
                                item_request_dimension.id_dimension    = item_dimension.id_app_dimension;
                                item_request_dimension.app_dimension   = item_dimension.app_dimension;
                                item_request_dimension.id_measurement  = item_dimension.id_measurement;
                                item_request_dimension.app_measurement = item_dimension.app_measurement;
                                item_request_dimension.value           = item_dimension.value;
                                item_request_detail.item_request_dimension.Add(item_request_dimension);
                            }

                            item_request.item_request_detail.Add(item_request_detail);
                        }
                        base.item_request.Add(item_request);
                        SaveChanges();
                    }

                    NumberOfRecords       += 1;
                    sales_order.IsSelected = false;
                }

                if (sales_order.Error != null)
                {
                    sales_order.HasErrors = true;
                }
            }

            return(true);
        }