예제 #1
0
        public purchase_order New()
        {
            purchase_order purchase_order = new purchase_order();

            purchase_order.State      = EntityState.Added;
            purchase_order.id_range   = Brillo.GetDefault.Return_RangeID(App.Names.PurchaseOrder);
            purchase_order.status     = Status.Documents_General.Pending;
            purchase_order.trans_date = DateTime.Now;
            purchase_order.app_branch = app_branch.Where(x => x.id_branch == CurrentSession.Id_Branch).FirstOrDefault();
            purchase_order.IsSelected = true;

            return(purchase_order);
        }
예제 #2
0
        public void loadPurchaseOrderReport(int id)
        {
            try
            {
                ReportDataSource reportDataSource = new ReportDataSource();
                reportDataSource.Name = "DataSet1"; // Name of the DataSet we set in .rdlc
                purchase_order purchase_order = db.purchase_order.Where(x => x.id_purchase_order == id).FirstOrDefault();
                List <purchase_order_detail> purchase_order_detail = db.purchase_order_detail.Where(x => x.id_purchase_order == purchase_order.id_purchase_order).ToList();

                reportDataSource.Value = purchase_order_detail
                                         .Select(g => new
                {
                    id_sales_return        = g.id_purchase_order,
                    id_sales_return_detail = g.id_purchase_order,
                    sales_return           = g.id_purchase_order_detail,
                    id_company             = g.id_company,
                    add1             = g.purchase_order.contact.address,
                    telephone        = g.purchase_order.contact.telephone,
                    email            = g.purchase_order.contact.email,
                    company_name     = g.app_company.name,
                    item_code        = g.item.code,
                    item_description = g.item.name,
                    Description      = g.item.item_brand != null ? g.item.item_brand.name : "",
                    quantity         = g.quantity,
                    sub_Total        = g.SubTotal,
                    sub_Total_vat    = g.SubTotal_Vat,
                    unit_cost        = g.unit_cost,
                    unit_price       = g.unit_cost,
                    unit_price_vat   = g.UnitCost_Vat,
                    terminale_name   = g.purchase_order.app_terminal.name,
                    code             = g.purchase_order.code,
                    contact_name     = g.purchase_order.contact.name,
                    //project_name = g.sales_budget.project != null ? g.sales_budget.project.name : "",
                    //sales_rep_name = g.purchase_order.sales_rep != null ? g.purchase_order.sales_rep.name : "",
                    trans_date   = g.purchase_order.trans_date,
                    id_vat_group = g.id_vat_group,
                    gov_id       = g.purchase_order.contact.gov_code,
                    //contract = g.sales_return.app_contract.name,
                    //condition = g.sales_return.app_contract.app_condition.name,
                    Number = g.purchase_order.number,
                    //Comment = g.purchase_order.comment
                }).ToList();
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
예제 #3
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;
                }
            }
        }