Пример #1
0
 private void productDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
 {
     entity.Class.Impex_Products clsProductDetail = productDataGrid.SelectedItem as entity.Class.Impex_Products;
     if (impeximpex_expenseViewSource != null)
     {
         if (impeximpex_expenseViewSource.View != null)
         {
             impeximpex_expenseViewSource.View.Filter = i =>
             {
                 impex_expense impex_expense = (impex_expense)i;
                 if (impex_expense.id_item == clsProductDetail.id_item)
                 {
                     return(true);
                 }
                 else
                 {
                     return(false);
                 }
             };
         }
     }
 }
Пример #2
0
        private void getProratedCostCounted(purchase_invoice purchase_invoice, bool isNew)
        {
            impex impex = impexDataGrid.SelectedItem as impex;

            if (isNew == true)
            {
                //impex import invoice.
                if (impex.impex_import.Where(x => x.id_purchase_invoice == purchase_invoice.id_purchase_invoice).Count() > 0)
                {
                    //Update
                    impex_import impex_import = impex.impex_import.First();
                    impex_import.id_purchase_invoice = purchase_invoice.id_purchase_invoice;
                    impex_import.purchase_invoice    = purchase_invoice;
                }
                else
                {
                    //Insert
                    impex_import impex_import = new impex_import();
                    impex_import.id_purchase_invoice = purchase_invoice.id_purchase_invoice;
                    impex_import.purchase_invoice    = purchase_invoice;
                    impex.impex_import.Add(impex_import);
                }
            }
            else
            {
                //Impex datagrid selection change.
                if (purchase_invoice == null)
                {
                    impex_import impex_import = impex.impex_import.First();
                    purchase_invoice = impex_import.purchase_invoice;
                }
            }


            //Get expences
            List <impex_expense> impex_expense = impex.impex_expense.ToList();
            decimal totalExpense = 0;

            foreach (var item in impex_expense)
            {
                totalExpense += item.value;
            }

            if (purchase_invoice != null)
            {
                //Insert Purchase Invoice Detail
                List <purchase_invoice_detail> purchase_invoice_detail = purchase_invoice.purchase_invoice_detail.ToList();

                decimal TotalInvoiceAmount = 0;

                foreach (var item in purchase_invoice_detail)
                {
                    TotalInvoiceAmount += (item.quantity * item.UnitCost_Vat);
                }

                if (Impex_ProductsLIST.Where(x => x.id_item == 0).Count() == 0)
                {
                    entity.Class.Impex_Products ImpexImportProductDetails = new entity.Class.Impex_Products();
                    ImpexImportProductDetails.id_item = 0;
                    ImpexImportProductDetails.item    = "ALL";
                    Impex_ProductsLIST.Add(ImpexImportProductDetails);
                }

                foreach (purchase_invoice_detail _purchase_invoice_detail in purchase_invoice_detail.Where(x => x.item != null && x.item.item_product != null))
                {
                    int id_item = (int)_purchase_invoice_detail.id_item;

                    if (Impex_ProductsLIST.Where(x => x.id_item == id_item).Count() == 0)
                    {
                        entity.Class.Impex_Products ImpexImportProductDetails = new entity.Class.Impex_Products();
                        ImpexImportProductDetails.id_item = (int)_purchase_invoice_detail.id_item;
                        ImpexImportProductDetails.item    = ImpexDB.items.Where(a => a.id_item == _purchase_invoice_detail.id_item).FirstOrDefault().name;
                        Impex_ProductsLIST.Add(ImpexImportProductDetails);
                    }

                    entity.Class.Impex_CostDetail ImpexImportDetails = new entity.Class.Impex_CostDetail();
                    ImpexImportDetails.number            = _purchase_invoice_detail.purchase_invoice.number;
                    ImpexImportDetails.id_item           = (int)_purchase_invoice_detail.id_item;
                    ImpexImportDetails.item              = ImpexDB.items.Where(a => a.id_item == _purchase_invoice_detail.id_item).FirstOrDefault().name;
                    ImpexImportDetails.quantity          = _purchase_invoice_detail.quantity;
                    ImpexImportDetails.unit_cost         = _purchase_invoice_detail.unit_cost;
                    ImpexImportDetails.id_invoice        = _purchase_invoice_detail.id_purchase_invoice;
                    ImpexImportDetails.id_invoice_detail = _purchase_invoice_detail.id_purchase_invoice_detail;

                    if (totalExpense > 0)
                    {
                        ImpexImportDetails.prorated_cost = Math.Round(_purchase_invoice_detail.unit_cost + (totalExpense / purchase_invoice_detail.Sum(x => x.quantity)), 2);
                    }

                    decimal SubTotal = (_purchase_invoice_detail.quantity * ImpexImportDetails.prorated_cost);
                    ImpexImportDetails.sub_total = Math.Round(SubTotal, 2);
                    Impex_CostDetailLIST.Add(ImpexImportDetails);
                }
            }
        }