Exemple #1
0
        private void ListProducts(object sender, EventArgs e)
        {
            if (InvoiceCode != string.Empty)
            {
                List <sales_invoice_detail> sales_invoice_detailLIST = dbContext.sales_invoice_detail
                                                                       .Where(x => x.sales_invoice.number.Contains(InvoiceCode) &&
                                                                              //Contado (Cash) + Payment Made
                                                                              (
                                                                                  (x.sales_invoice.payment_schedual.Sum(z => z.credit) > 0 && x.sales_invoice.app_contract.app_contract_detail.Sum(z => z.interval) == 0)
                                                                                  ||
                                                                                  //Credit
                                                                                  (x.sales_invoice.app_contract.app_contract_detail.Sum(y => y.interval) > 0)
                                                                              ) &&
                                                                              x.sales_invoice.status == Status.Documents_General.Approved).ToList();

                List <item_movement> item_movementLIST = new List <item_movement>();

                foreach (sales_invoice_detail sales_invoice_detail in sales_invoice_detailLIST.Where(x => x.item.item_product.Count > 0))
                {
                    item_movement item_movement = new entity.item_movement();

                    item_movement.trans_date              = DateTime.Now;
                    item_movement.id_item_product         = sales_invoice_detail.item.item_product.FirstOrDefault().id_item_product;
                    item_movement.item_product            = sales_invoice_detail.item.item_product.FirstOrDefault();
                    item_movement.id_sales_invoice_detail = sales_invoice_detail.id_sales_invoice_detail;
                    item_movement.sales_invoice_detail    = sales_invoice_detail;
                    item_movement.debit     = 0;
                    item_movement.credit    = 0;
                    item_movement.status    = Status.Stock.InStock;
                    item_movement.timestamp = DateTime.Now;
                    item_movement.State     = System.Data.Entity.EntityState.Added;

                    if (sales_invoice_detail.id_location != null || sales_invoice_detail.id_location > 0)
                    {
                        item_movement.id_location = (int)sales_invoice_detail.id_location;
                    }
                    else
                    {
                        //find location code by using checkbox.
                        item_movement.id_location = app_branch.app_location.Where(x => x.is_default).FirstOrDefault().id_location;
                    }

                    if (sales_invoice_detail.item_movement != null)
                    {
                        item_movement.debit = sales_invoice_detail.quantity - sales_invoice_detail.item_movement.Sum(x => x.debit);
                    }
                    else
                    {
                        item_movement.debit = sales_invoice_detail.quantity;
                    }

                    if (item_movement.debit > 0)
                    {
                        item_movementLIST.Add(item_movement);
                    }
                }

                dbContext.item_movement.AddRange(item_movementLIST);
                item_movementViewSource.Source = item_movementLIST;
                item_movementViewSource.View.Refresh();
            }
        }
Exemple #2
0
        /// <summary>
        /// Executes code that will insert Invoiced Items into Movement.
        /// </summary>
        /// <param name="invoice"></param>
        public void Credit_Items_Destination(item_transfer_detail item_transfer_detail, int ID_BranchOrigin, int ID_BranchDestination, bool MoveByTruck)
        {
            entity.Brillo.Logic.Stock stock          = new Brillo.Logic.Stock();
            app_currencyfx            app_currencyfx = base.app_currencyfx.Where(x => x.app_currency.is_priority && x.is_active).FirstOrDefault();
            app_location app_location_dest           = base.app_location.Where(x => x.id_branch == ID_BranchDestination && x.is_default).FirstOrDefault();

            if (MoveByTruck)
            {
                List <entity.Brillo.StockList> Items_InStockLIST;
                entity.Brillo.Stock            stockBrillo = new Brillo.Stock();
                Items_InStockLIST = stockBrillo.MovementForTransfer(item_transfer_detail.id_transfer_detail, item_transfer_detail.id_item_product);

                List <item_movement> item_movement_LIST = new List <entity.item_movement>();
                ///Discount From Destination. Because merchendice is returned to Origin, so it must be discounted from Destintation.
                item_movement_LIST =
                    stock.DebitOnly_MovementLIST(this, Items_InStockLIST, Status.Stock.InStock, App.Names.Transfer, item_transfer_detail.id_transfer, item_transfer_detail.id_transfer_detail,
                                                 app_currencyfx, item_transfer_detail.item_product, app_location_dest, item_transfer_detail.quantity_destination,
                                                 item_transfer_detail.item_transfer.trans_date, stock.comment_Generator(App.Names.Transfer, item_transfer_detail.item_transfer.number != null ? item_transfer_detail.item_transfer.number.ToString() : "", ""));

                base.item_movement.AddRange(item_movement_LIST);

                app_location app_location_origin = base.app_location.Where(x => x.id_branch == ID_BranchOrigin && x.is_default).FirstOrDefault();

                //Credit in Origin only if it is MoveByTruck.
                item_movement item_movement_origin;
                item_movement_origin =
                    stock.CreditOnly_Movement(
                        Status.Stock.InStock,
                        App.Names.Transfer,
                        item_transfer_detail.id_transfer,
                        item_transfer_detail.id_transfer_detail,
                        app_currencyfx,
                        item_transfer_detail.item_product,
                        app_location_origin,
                        item_transfer_detail.quantity_destination,
                        item_transfer_detail.item_transfer.trans_date,
                        0,
                        stock.comment_Generator(App.Names.Transfer, item_transfer_detail.item_transfer.number != null ? item_transfer_detail.item_transfer.number.ToString() : "", ""),
                        null
                        );

                base.item_movement.Add(item_movement_origin);
            }
            else
            {
                //Credit Destination.
                item_movement        item_movement_dest;
                List <item_movement> Items_InStockLIST = base.item_movement.Where(x => x.id_transfer_detail == item_transfer_detail.id_transfer_detail &&
                                                                                  x.id_item_product == item_transfer_detail.id_item_product && x.debit > 0).ToList();
                int count = 1;
                if (Items_InStockLIST.Count() > 0)
                {
                    count = Items_InStockLIST.Count();
                }

                item_movement parent_item_movement = Items_InStockLIST.FirstOrDefault();

                item_movement_dest =
                    stock.CreditOnly_Movement(
                        Status.Stock.InStock,
                        App.Names.Transfer,
                        item_transfer_detail.id_transfer,
                        item_transfer_detail.id_transfer_detail,
                        app_currencyfx,
                        item_transfer_detail.item_product,
                        app_location_dest,
                        item_transfer_detail.quantity_destination,
                        item_transfer_detail.item_transfer.trans_date,
                        Items_InStockLIST.Sum(x => (x.item_movement_value.Sum(y => y.unit_value) / (x.item_movement_value.Count() != 0 ? x.item_movement_value.Count() : 1))) / count,
                        stock.comment_Generator(App.Names.Transfer, item_transfer_detail.item_transfer.number != null ? item_transfer_detail.item_transfer.number.ToString() : "", ""),
                        null
                        );
                item_movement_dest._parent = Items_InStockLIST.FirstOrDefault();
                base.item_movement.Add(item_movement_dest);
            }
        }
Exemple #3
0
        public void ApproveImport()
        {
            foreach (impex impex in base.impex.Local.Where(x => x.status != Status.Documents_General.Approved && x.impex_type == entity.impex._impex_type.Import && x.IsSelected))
            {
                if (impex.Error == null)
                {
                    if (impex.id_impex == 0)
                    {
                        SaveChanges();
                    }

                    //fill up virtual class
                    List <entity.Class.Impex_CostDetail> ImpexImportDetails = Fill_ViewModel(impex);
                    List <impex_expense> impex_expenses = impex.impex_expense.ToList();

                    if (ImpexImportDetails.Count > 0)
                    {
                        //To make sure we have a Purchase Total
                        decimal purchaseTotal = ImpexImportDetails.Sum(i => i.sub_total);
                        if (purchaseTotal != 0)
                        {
                            foreach (entity.Class.Impex_CostDetail Impex_CostDetail in ImpexImportDetails)
                            {
                                //Get total value of a Product Row
                                decimal itemTotal = Impex_CostDetail.quantity * Impex_CostDetail.unit_cost;

                                purchase_invoice purchase_invoice = base.purchase_invoice.Where(x => x.id_purchase_invoice == Impex_CostDetail.id_invoice).FirstOrDefault();
                                item_movement    item_movement    = base.item_movement.Where(x => x.id_purchase_invoice_detail == Impex_CostDetail.id_invoice_detail).FirstOrDefault();

                                foreach (impex_expense _impex_expense in impex_expenses)
                                {
                                    decimal condition_value = _impex_expense.value;

                                    if (condition_value != 0 && itemTotal != 0)
                                    {
                                        //Coeficient is used to get prorated cost of one item
                                        item_movement_value item_movement_detail = new item_movement_value();

                                        decimal Cost = Math.Round(_impex_expense.value / ImpexImportDetails.Sum(x => x.quantity), 2);

                                        //decimal Cost = Impex_CostDetail.unit_cost * coeficient;

                                        //Improve this in future. For now take from Purchase
                                        using (db db = new db())
                                        {
                                            int     ID_CurrencyFX_Default = CurrentSession.CurrencyFX_Default.id_currencyfx;
                                            decimal DefaultCurrency_Cost  = Currency.convert_Values(Cost, purchase_invoice.id_currencyfx, ID_CurrencyFX_Default, null);

                                            item_movement_detail.unit_value    = DefaultCurrency_Cost;
                                            item_movement_detail.id_currencyfx = ID_CurrencyFX_Default;
                                        }

                                        item_movement_detail.comment = _impex_expense.impex_incoterm_condition.name;
                                        if (item_movement != null)
                                        {
                                            item_movement.item_movement_value.Add(item_movement_detail);
                                        }
                                    }
                                }
                            }
                            impex.status = Status.Documents_General.Approved;
                            base.SaveChanges();
                        }
                    }
                }
            }
        }