Esempio n. 1
0
        private void cbxCondition_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            purchase_invoice purchase_invoice = (purchase_invoice)purchase_invoiceDataGrid.SelectedItem;

            //Contract
            if (cbxCondition.SelectedItem != null)
            {
                app_condition app_condition = cbxCondition.SelectedItem as app_condition;
                cbxContract.ItemsSource = PurchaseInvoiceDB.app_contract.Where(a => a.is_active == true &&
                                                                               a.id_company == CurrentSession.Id_Company &&
                                                                               a.id_condition == app_condition.id_condition).ToList();
                //Selects first Item
                if (purchase_invoice != null)
                {
                    if (purchase_invoice.id_contract == 0)
                    {
                        cbxContract.SelectedIndex = 0;
                    }
                    else
                    {
                        cbxContract.SelectedValue = purchase_invoice.id_contract;
                    }
                }
            }
        }
Esempio n. 2
0
        private void toolBar_btnCancel_Click(object sender)
        {
            PurchaseInvoiceDB.CancelAllChanges();
            purchase_invoice purchase_invoice = (purchase_invoice)purchase_invoiceDataGrid.SelectedItem;

            purchase_invoice.State = EntityState.Unchanged;
        }
Esempio n. 3
0
        private void toolBar_btnPrint_Click(object sender, MouseButtonEventArgs e)
        {
            purchase_invoice purchase_invoice = purchase_invoiceDataGrid.SelectedItem as purchase_invoice;

            if (purchase_invoice != null)
            {
                app_document_range app_document_range;

                if (purchase_invoice.app_document_range != null)
                {
                    app_document_range = purchase_invoice.app_document_range;
                }
                else
                {
                    app_document app_document = new entity.app_document();
                    app_document.id_application = entity.App.Names.PurchaseInvoice;
                    app_document.name           = "PurchaseInvoice";

                    app_document_range = new app_document_range();
                    app_document_range.use_default_printer = false;
                    app_document_range.app_document        = app_document;
                }

                entity.Brillo.Document.Start.Manual(purchase_invoice, app_document_range);
            }
            else
            {
                toolBar.msgWarning("Please select");
            }
        }
Esempio n. 4
0
 private void toolBar_btnSearch_Click(object sender, string query)
 {
     try
     {
         if (!string.IsNullOrEmpty(query) && purchase_invoiceViewSource != null)
         {
             purchase_invoiceViewSource.View.Filter = i =>
             {
                 purchase_invoice purchase_invoice = i as purchase_invoice;
                 string           number           = purchase_invoice.number != null ? purchase_invoice.number : "";
                 if (purchase_invoice.contact.name.ToLower().Contains(query.ToLower()) || number.ToLower().Contains(query.ToLower()))
                 {
                     return(true);
                 }
                 else
                 {
                     return(false);
                 }
             };
         }
         else
         {
             purchase_invoiceViewSource.View.Filter = null;
         }
     }
     catch (Exception)
     { }
 }
Esempio n. 5
0
        public accounting_journal Start(AccountingJournalDB AccountingJournalDB, purchase_invoice purchase_invoice)
        {
            ///PURCHASE
            if (purchase_invoice != null &&
                purchase_invoice.accounting_journal == null &&
                purchase_invoice.status == entity.Status.Documents_General.Approved)
            {
                DateTime TransDate = purchase_invoice.trans_date;

                accounting_cycle accounting_cycledb = AccountingJournalDB.accounting_cycle
                                                      .Where(i => i.start_date <= TransDate &&
                                                             i.end_date >= TransDate &&
                                                             i.id_company == Properties.Settings.Default.company_ID)
                                                      .FirstOrDefault();

                if (accounting_cycledb == null)
                {
                    AccountingCycle AccCycle = new AccountingCycle();
                    int             CylceID  = AccCycle.Generate_Cycle(TransDate).id_cycle;
                    accounting_cycledb = AccountingJournalDB.accounting_cycle.Where(x => x.id_cycle == CylceID).FirstOrDefault();
                }

                return(Calculate_PurchaseInvoice(AccountingJournalDB, purchase_invoice, accounting_cycledb));
            }
            return(null);
        }
Esempio n. 6
0
        private void Totals_btnClean_Click(object sender)
        {
            purchase_invoice purchase_invoice = purchase_invoiceViewSource.View.CurrentItem as purchase_invoice;

            if (purchase_invoice != null)
            {
                decimal TrailingDecimals = purchase_invoice.GrandTotal - Math.Floor(purchase_invoice.GrandTotal);
                purchase_invoice.DiscountWithoutPercentage += TrailingDecimals;
            }
        }
Esempio n. 7
0
        private void Hyperlink_PreviewMouseUp(object sender, MouseButtonEventArgs e)
        {
            purchase_invoice purchase_invoice = purchase_invoiceViewSource.View.CurrentItem as purchase_invoice;

            foreach (purchase_invoice_detail purchase_invoice_detail in purchase_invoice.purchase_invoice_detail)
            {
                purchase_invoice_detail.Quantity_Factored = entity.Brillo.ConversionFactor.Factor_Quantity(purchase_invoice_detail.item, purchase_invoice_detail.quantity, purchase_invoice_detail.GetDimensionValue());
                purchase_invoice_detail.RaisePropertyChanged("Quantity_Factored");
            }
        }
Esempio n. 8
0
        private void toolBar_btnNew_Click(object sender)
        {
            InvoiceSetting _pref_PurchaseInvoice = new InvoiceSetting();

            purchase_invoice purchase_invoice = PurchaseInvoiceDB.New();

            purchase_invoice.trans_date = DateTime.Now.AddDays(_pref_PurchaseInvoice.TransDate_OffSet);
            PurchaseInvoiceDB.Entry(purchase_invoice).State = EntityState.Added;

            purchase_invoiceViewSource.View.MoveCurrentToLast();
        }
Esempio n. 9
0
        private void btnRecivePayment_PreviewMouseUp(object sender, MouseButtonEventArgs e)
        {
            purchase_invoice purchase_invoice = purchase_invoiceDataGrid.SelectedItem as purchase_invoice;

            if (purchase_invoice != null)
            {
                crud_modal.Visibility = Visibility.Visible;
                cntrl.Curd.receive_payment recive_payment = new cntrl.Curd.receive_payment();
                recive_payment.purchase_invoice = purchase_invoice;
                crud_modal.Children.Add(recive_payment);
            }
        }
Esempio n. 10
0
 public void Fill_ByPurchase(purchase_invoice purchase_invoice)
 {
     this.Type             = entity.DebeHaber.TransactionTypes.Purchase;
     this.TransDate        = purchase_invoice.trans_date;
     this.CompanyName      = purchase_invoice.contact.name;
     this.Gov_Code         = purchase_invoice.contact.gov_code;
     this.Comment          = purchase_invoice.comment;
     this.CurrencyName     = purchase_invoice.app_currencyfx != null ? purchase_invoice.app_currencyfx.app_currency != null ? purchase_invoice.app_currencyfx.app_currency.name : "" : "";
     this.PaymentCondition = purchase_invoice.app_contract != null ? (purchase_invoice.app_contract.app_contract_detail != null ? purchase_invoice.app_contract.app_contract_detail.Max(x => x.interval) : 0) : 0;
     this.DocNumber        = purchase_invoice.number;
     this.DocCode          = purchase_invoice.code;
 }
Esempio n. 11
0
        private void set_ContactPref(object sender, EventArgs e)
        {
            if (sbxContact.ContactID > 0)
            {
                contact          contact          = PurchaseInvoiceDB.contacts.Where(x => x.id_contact == sbxContact.ContactID).FirstOrDefault();
                purchase_invoice purchase_invoice = (purchase_invoice)purchase_invoiceDataGrid.SelectedItem;
                purchase_invoice.id_contact = contact.id_contact;
                purchase_invoice.contact    = contact;

                ///Start Thread to get Data.
                Task thread_SecondaryData = Task.Factory.StartNew(() => set_ContactPref_Thread(contact));
            }
        }
Esempio n. 12
0
 private void toolBar_btnEdit_Click(object sender)
 {
     if (purchase_invoiceDataGrid.SelectedItem != null)
     {
         purchase_invoice purchase_invoice = (purchase_invoice)purchase_invoiceDataGrid.SelectedItem;
         purchase_invoice.IsSelected = true;
         purchase_invoice.State      = EntityState.Modified;
         PurchaseInvoiceDB.Entry(purchase_invoice).State = EntityState.Modified;
     }
     else
     {
         toolBar.msgWarning("Please Select an Item");
     }
 }
Esempio n. 13
0
        private void GetExpenses_PreviewMouseUp(object sender, EventArgs e)
        {
            if (impexDataGrid.SelectedItem != null)
            {
                if (id_incotermComboBox.SelectedItem != null && pnlPurchaseInvoice.selected_purchase_invoice.FirstOrDefault() != null)
                {
                    impex                        impex           = impexDataGrid.SelectedItem as impex;
                    purchase_invoice             PurchaseInvoice = pnlPurchaseInvoice.selected_purchase_invoice.FirstOrDefault() as purchase_invoice;
                    impex_incoterm               Incoterm        = id_incotermComboBox.SelectedItem as impex_incoterm;
                    List <impex_incoterm_detail> IncotermDetail  = null;

                    if (impex.impex_type == entity.impex._impex_type.Import)
                    {
                        //Only fetch buyer expence
                        IncotermDetail = ImpexDB.impex_incoterm_detail.Where(i => i.id_incoterm == Incoterm.id_incoterm && i.buyer == true).ToList();
                    }
                    if (impex.impex_type == entity.impex._impex_type.Export)
                    {
                        //Only fetch seller expence
                        IncotermDetail = ImpexDB.impex_incoterm_detail.Where(i => i.id_incoterm == Incoterm.id_incoterm && i.seller == true).ToList();
                    }

                    foreach (entity.Class.Impex_Products product in Impex_ProductsLIST)
                    {
                        foreach (var item in IncotermDetail)
                        {
                            impex_expense impex_expense = new impex_expense();
                            impex_expense.State = EntityState.Added;

                            if (ImpexDB.impex_incoterm_condition.Where(x => x.id_incoterm_condition == item.id_incoterm_condition).FirstOrDefault() != null)
                            {
                                impex_expense.impex_incoterm_condition = ImpexDB.impex_incoterm_condition.Where(x => x.id_incoterm_condition == item.id_incoterm_condition).FirstOrDefault();
                            }

                            impex_expense.id_incoterm_condition = item.id_incoterm_condition;
                            impex_expense.id_currencyfx         = PurchaseInvoice.id_currencyfx;
                            impex_expense.id_purchase_invoice   = PurchaseInvoice.id_purchase_invoice;
                            impex_expense.id_item = (int)product.id_item;
                            impex.impex_expense.Add(impex_expense);
                        }
                    }
                    impeximpex_expenseViewSource.View.Refresh();
                    productDataGrid.SelectedIndex = 0;
                }
                else
                {
                    MessageBox.Show("Please select Incoterm, Type and Invoice to get expences.", "Get Expences", MessageBoxButton.OK, MessageBoxImage.Information);
                }
            }
        }
Esempio n. 14
0
        private void sales_invoiceDatagrid_LoadingRowDetails(object sender, DataGridRowDetailsEventArgs e)
        {
            if (_entity.purchase_invoice_detail.Count() > 0)
            {
                purchase_invoice _purchase_invoice = ((System.Windows.Controls.DataGrid)sender).SelectedItem as purchase_invoice;
                int id_purchase_invoice            = _purchase_invoice.id_purchase_invoice;
                System.Windows.Controls.Grid Grid  = e.DetailsElement as System.Windows.Controls.Grid;
                var purchaseInvoice = _purchase_invoice.purchase_invoice_detail;

                if (Grid != null)
                {
                    Grid.DataContext = purchaseInvoice;
                }
            }
        }
Esempio n. 15
0
        private void cbxCurrency_LostFocus(object sender, RoutedEventArgs e)
        {
            purchase_invoice purchase_invoice = purchase_invoiceViewSource.View.CurrentItem as purchase_invoice;

            if (purchase_invoice != null)
            {
                if (purchase_invoice.id_currencyfx > 0)
                {
                    if (PurchaseInvoiceDB.app_currencyfx.Where(x => x.id_currencyfx == purchase_invoice.id_currencyfx).FirstOrDefault() != null)
                    {
                        purchase_invoice.app_currencyfx = PurchaseInvoiceDB.app_currencyfx.Where(x => x.id_currencyfx == purchase_invoice.id_currencyfx).FirstOrDefault();
                    }
                }
            }
            calculate_vat(sender, e);
        }
Esempio n. 16
0
        //private void purchase_invoiceDataGrid_Loaded(object sender, RoutedEventArgs e)
        //{
        //    //calculate_total(sender, e);
        //}

        private void purchase_invoiceDataGrid_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
            try
            {
                purchase_invoice purchase_invoice = (purchase_invoice)purchase_invoiceDataGrid.SelectedItem;
                if (purchase_invoice != null)
                {
                    calculate_vat(sender, e);
                }
                //calculate_total(sender, e);
            }
            catch (Exception ex)
            {
                toolBar.msgError(ex);
            }
        }
Esempio n. 17
0
 private void toolBar_btnDelete_Click(object sender)
 {
     try
     {
         if (MessageBox.Show("Are you sure want to Delete?", "Cognitivo", MessageBoxButton.YesNo, MessageBoxImage.Question) == MessageBoxResult.Yes)
         {
             purchase_invoice purchase_invoice = (purchase_invoice)purchase_invoiceDataGrid.SelectedItem;
             purchase_invoice.is_head    = false;
             purchase_invoice.State      = EntityState.Deleted;
             purchase_invoice.IsSelected = true;
         }
     }
     catch (Exception ex)
     {
         toolBar.msgError(ex);
     }
 }
Esempio n. 18
0
        private void calculate_vat(object sender, EventArgs e)
        {
            purchase_invoice purchase_invoice = (purchase_invoice)purchase_invoiceDataGrid.SelectedItem;

            purchase_invoice.RaisePropertyChanged("GrandTotal");
            if (purchase_invoice != null)
            {
                List <purchase_invoice_detail> purchase_invoice_detail = purchase_invoice.purchase_invoice_detail.ToList();
                dgvvat.ItemsSource = purchase_invoice_detail
                                     .Join(PurchaseInvoiceDB.app_vat_group_details, ad => ad.id_vat_group, cfx => cfx.id_vat_group
                                           , (ad, cfx) => new { name = cfx.app_vat.name, value = ad.unit_cost * cfx.app_vat.coefficient, id_vat = cfx.app_vat.id_vat, ad })
                                     .GroupBy(a => new { a.name, a.id_vat, a.ad })
                                     .Select(g => new
                {
                    id_vat = g.Key.id_vat,
                    name   = g.Key.name,
                    value  = g.Sum(a => a.value * a.ad.quantity)
                }).ToList();
            }
        }
Esempio n. 19
0
        private void DeleteCommand_Executed(object sender, ExecutedRoutedEventArgs e)
        {
            try
            {
                MessageBoxResult result = MessageBox.Show("Are you sure want to Delete?", "Cognitivo ERP", MessageBoxButton.YesNo, MessageBoxImage.Question);
                if (result == MessageBoxResult.Yes)
                {
                    purchase_invoice purchase_invoice = purchase_invoiceViewSource.View.CurrentItem as purchase_invoice;

                    //DeleteDetailGridRow
                    dgvPurchaseDetail.CancelEdit();

                    PurchaseInvoiceDB.purchase_invoice_detail.Remove(e.Parameter as purchase_invoice_detail);
                    purchase_invoicepurchase_invoice_detailViewSource.View.Refresh();
                }
            }
            catch (Exception ex)
            {
                toolBar.msgError(ex);
            }
        }
Esempio n. 20
0
        private void item_Select(object sender, EventArgs e)
        {
            purchase_invoice purchase_invoice = purchase_invoiceViewSource.View.CurrentItem as purchase_invoice;

            if (purchase_invoice != null)
            {
                item    item    = null;
                contact contact = null;

                if (sbxItem.ItemID > 0)
                {
                    item = PurchaseInvoiceDB.items.Where(x => x.id_item == sbxItem.ItemID).FirstOrDefault();
                }

                if (purchase_invoice.id_contact > 0 || sbxContact.ContactID > 0)
                {
                    contact = PurchaseInvoiceDB.contacts.Where(x => x.id_contact == sbxContact.ContactID).FirstOrDefault();
                }

                Task Thread = Task.Factory.StartNew(() => SelectProduct_Thread(sender, e, purchase_invoice, item, contact));
            }
        }
Esempio n. 21
0
 private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
 {
     if (_invoiceList.FirstOrDefault().GetType().BaseType == typeof(sales_invoice))
     {
         sales_invoice sales_invoice = (sales_invoice)_invoiceList.FirstOrDefault();
         if (sales_invoice.GrandTotal > 0)
         {
             if (sales_invoice.vatwithholdingpercentage > 0)
             {
                 percentage = sales_invoice.vatwithholdingpercentage;
                 if (percentage <= 1)
                 {
                     if (sales_invoice.GrandTotal > 0)
                     {
                         lbltotalvat.Content = Math.Round((((sales_invoice.TotalVat * payment_schedual.AccountReceivableBalance) / sales_invoice.GrandTotal)) * percentage, 4);
                     }
                 }
                 else
                 {
                     MessageBox.Show("not Exceed to Hundred %");
                     lbltotalvat.Content = Math.Round((((sales_invoice.TotalVat * payment_schedual.AccountReceivableBalance) / sales_invoice.GrandTotal)), 4);
                 }
             }
             else
             {
                 lbltotalvat.Content = Math.Round((((sales_invoice.TotalVat * payment_schedual.AccountReceivableBalance) / sales_invoice.GrandTotal)), 4);
             }
         }
     }
     else if (_invoiceList.FirstOrDefault().GetType().BaseType == typeof(purchase_invoice))
     {
         purchase_invoice purchase_invoice = (purchase_invoice)_invoiceList.FirstOrDefault();
         if (purchase_invoice.GrandTotal > 0)
         {
             lbltotalvat.Content = Math.Round(((purchase_invoice.TotalVat * payment_schedual.AccountPayableBalance) / purchase_invoice.GrandTotal) * percentage, 4);
         }
     }
 }
Esempio n. 22
0
        private void btnDuplicateInvoice_PreviewMouseUp(object sender, MouseButtonEventArgs e)
        {
            purchase_invoice purchase_invoice = purchase_invoiceViewSource.View.CurrentItem as purchase_invoice;

            if (purchase_invoice != null)
            {
                if (purchase_invoice.id_purchase_invoice != 0)
                {
                    using (db db = new db())
                    {
                        var originalEntity = db.purchase_invoice.AsNoTracking()
                                             .FirstOrDefault(x => x.id_purchase_invoice == purchase_invoice.id_purchase_invoice);
                        db.purchase_invoice.Add(originalEntity);
                        purchase_invoiceViewSource.View.Refresh();
                        purchase_invoiceViewSource.View.MoveCurrentToLast();
                    }
                }
                else
                {
                    toolBar.msgWarning("Please save before duplicating");
                }
            }
        }
Esempio n. 23
0
        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            cbxDocument.ItemsSource = entity.Brillo.Logic.Range.List_Range(PaymentDB, entity.App.Names.PaymentWithHolding, CurrentSession.Id_Branch, CurrentSession.Id_Terminal);

            if (!System.ComponentModel.DesignerProperties.GetIsInDesignMode(this))
            {
                try
                {
                    CollectionViewSource invoiceViewSource = new CollectionViewSource();
                    invoiceViewSource.Source  = _invoiceList;
                    stackMain.DataContext     = invoiceViewSource;
                    DtpTransdate.SelectedDate = DateTime.Now;

                    if (_invoiceList.FirstOrDefault().GetType().BaseType == typeof(sales_invoice))
                    {
                        sales_invoice sales_invoice = (sales_invoice)_invoiceList.FirstOrDefault();
                        if (sales_invoice.GrandTotal > 0)
                        {
                            lbltotalvat.Content = Math.Round((((sales_invoice.TotalVat * payment_schedual.AccountReceivableBalance) / sales_invoice.GrandTotal)) * percentage, 4);
                        }
                    }
                    else if (_invoiceList.FirstOrDefault().GetType().BaseType == typeof(purchase_invoice))
                    {
                        purchase_invoice purchase_invoice = (purchase_invoice)_invoiceList.FirstOrDefault();
                        if (purchase_invoice.GrandTotal > 0)
                        {
                            lbltotalvat.Content = Math.Round(((purchase_invoice.TotalVat * payment_schedual.AccountPayableBalance) / purchase_invoice.GrandTotal) * percentage, 4);
                        }
                    }
                }
                catch (Exception ex)
                {
                    throw ex;
                }
            }
        }
Esempio n. 24
0
        private void btnWithholding_Click(object sender, RoutedEventArgs e)
        {
            List <payment_schedual> PaymentSchedualList = payment_schedualViewSource.View.OfType <payment_schedual>().Where(x => x.IsSelected == true).ToList();

            if (PaymentSchedualList.Count > 0)
            {
                purchase_invoice purchase_invoice = PaymentSchedualList.FirstOrDefault().purchase_invoice;
                if (purchase_invoice.payment_withholding_details.Count() == 0)
                {
                    cntrl.VATWithholding VATWithholding = new cntrl.VATWithholding();
                    VATWithholding.invoiceList = new List <object>();
                    VATWithholding.invoiceList.Add(purchase_invoice);
                    VATWithholding.PaymentDB        = PaymentDB;
                    VATWithholding.payment_schedual = PaymentSchedualList.FirstOrDefault();
                    VATWithholding.percentage       = PaymentSetting.Default.vatwithholdingpercent;
                    crud_modal.Visibility           = System.Windows.Visibility.Visible;
                    crud_modal.Children.Add(VATWithholding);
                }
                else
                {
                    toolbar.msgWarning("Alerady Link With Vat Holding...");
                }
            }
        }
Esempio n. 25
0
        private accounting_journal Calculate_PurchaseInvoice(AccountingJournalDB AccountingJournalDB, purchase_invoice purchase_invoice, accounting_cycle accounting_cycle)
        {
            accounting_journal accounting_journal = new accounting_journal();

            if (purchase_invoice.accounting_journal == null)
            {
                accounting_journal.id_cycle   = accounting_cycle.id_cycle;
                accounting_journal.trans_date = purchase_invoice.trans_date;
                accounting_journal.IsSelected = true;
                accounting_journal.State      = EntityState.Added;
                accounting_journal.comment    = purchase_invoice.comment;

                List <accounting_journal_detail> accounting_journal_detailList = new List <accounting_journal_detail>();
                foreach (purchase_invoice_detail purchase_invoice_detail in purchase_invoice.purchase_invoice_detail.ToList())
                {
                    if (purchase_invoice_detail.app_cost_center.is_product && purchase_invoice_detail.item != null)
                    {
                        List <item_tag_detail> item_tag_detailLIST = purchase_invoice_detail.item.item_tag_detail.ToList();
                        if (item_tag_detailLIST != null)
                        {
                            Asset.Inventory Inventory = new Asset.Inventory();

                            accounting_chart INV_Chart = null;
                            foreach (item_tag_detail item_tag_detail in purchase_invoice_detail.item.item_tag_detail.ToList())
                            {
                                item_tag item_tag = item_tag_detail.item_tag;
                                INV_Chart = Inventory.find_Chart(AccountingJournalDB, item_tag);
                            }

                            if (INV_Chart != null)
                            {
                                accounting_journal_detail INV_accounting_journal = new accounting_journal_detail();
                                INV_accounting_journal.accounting_chart = INV_Chart;
                                INV_accounting_journal.trans_date       = purchase_invoice.trans_date;
                                INV_accounting_journal.debit            = Math.Round(purchase_invoice_detail.SubTotal, 2);
                                INV_accounting_journal.id_currencyfx    = purchase_invoice.app_currencyfx.id_currencyfx;
                                accounting_journal_detailList.Add(INV_accounting_journal);
                            }
                        }
                    }
                    else if (purchase_invoice_detail.app_cost_center.is_fixedasset)
                    {
                        //Ignore
                    }
                    else
                    {
                        Expense.AdministrationExpense AdministrationExpense = new Expense.AdministrationExpense();

                        app_cost_center  app_cost_center = purchase_invoice_detail.app_cost_center;
                        accounting_chart Exp_Chart       = AdministrationExpense.find_Chart(AccountingJournalDB, app_cost_center);
                        if (Exp_Chart != null)
                        {
                            accounting_journal_detail INV_accounting_journal = new accounting_journal_detail();
                            INV_accounting_journal.accounting_chart = Exp_Chart;
                            INV_accounting_journal.trans_date       = purchase_invoice.trans_date;
                            INV_accounting_journal.debit            = Math.Round(purchase_invoice_detail.SubTotal, 2);
                            INV_accounting_journal.id_currencyfx    = purchase_invoice.app_currencyfx.id_currencyfx;
                            accounting_journal_detailList.Add(INV_accounting_journal);
                        }
                    }
                }

                Liability.ValueAddedTax VAT = new Liability.ValueAddedTax();
                foreach (purchase_invoice_detail purchase_invoice_detail in purchase_invoice.purchase_invoice_detail.ToList())
                {
                    foreach (app_vat_group_details app_vat_group in purchase_invoice_detail.app_vat_group.app_vat_group_details)
                    {
                        accounting_chart VAT_Chart = VAT.find_Chart(AccountingJournalDB, app_vat_group.app_vat);
                        if (VAT_Chart != null)
                        {
                            accounting_journal_detail INV_accounting_journal = new accounting_journal_detail();
                            INV_accounting_journal.accounting_chart = VAT_Chart;
                            INV_accounting_journal.trans_date       = purchase_invoice.trans_date;
                            INV_accounting_journal.debit            = Math.Round(Vat.calculate_Vat((purchase_invoice_detail.unit_cost * purchase_invoice_detail.quantity), app_vat_group.app_vat.coefficient), 2);
                            INV_accounting_journal.id_currencyfx    = purchase_invoice.app_currencyfx.id_currencyfx;
                            accounting_journal_detailList.Add(INV_accounting_journal);
                        }
                    }
                }

                List <payment_schedual> payment_schedualLIST = AccountingJournalDB.payment_schedual.Where(x => x.id_purchase_invoice == purchase_invoice.id_purchase_invoice).ToList();

                if (payment_schedualLIST != null)
                {
                    ///For Loop for each Payment Schedual.
                    foreach (payment_schedual payment_schedual in payment_schedualLIST)
                    {
                        ///Example: 1000$ Invoice.
                        ///Example: 600$ Paid & 400$ NotPaid.

                        ///Payment Done -> Ex. 600$
                        if (payment_schedual.payment_detail != null && payment_schedual.debit > 0)
                        {
                            Asset.Cash       CashAccount = new Asset.Cash();
                            accounting_chart AR_Chart    = CashAccount.find_Chart(AccountingJournalDB, payment_schedual.payment_detail.app_account);

                            if (AR_Chart != null)
                            {
                                accounting_journal_detail PAYaccounting_journal_detail = new accounting_journal_detail();
                                PAYaccounting_journal_detail.accounting_chart = AR_Chart;
                                PAYaccounting_journal_detail.trans_date       = payment_schedual.trans_date;
                                PAYaccounting_journal_detail.credit           = payment_schedual.debit;
                                PAYaccounting_journal_detail.id_currencyfx    = payment_schedual.app_currencyfx.id_currencyfx;
                                accounting_journal_detailList.Add(PAYaccounting_journal_detail);
                            }
                        }
                        ///Payment Left -> Ex. 400$
                        else if (payment_schedual.payment_detail == null && payment_schedual.credit > 0)
                        {
                            //Credit Payment
                            Liability.AccountsPayable AccountsPayable = new Liability.AccountsPayable();
                            accounting_chart          AR_Chart        = AccountsPayable.find_Chart(AccountingJournalDB, purchase_invoice.contact);

                            if (AR_Chart != null)
                            {
                                accounting_journal_detail AR_accounting_journal_detail = new accounting_journal_detail();
                                AR_accounting_journal_detail.accounting_chart = AR_Chart;
                                AR_accounting_journal_detail.trans_date       = purchase_invoice.trans_date;
                                AR_accounting_journal_detail.credit           = payment_schedual.credit - payment_schedual.child.Sum(x => x.debit);
                                AR_accounting_journal_detail.id_currencyfx    = purchase_invoice.app_currencyfx.id_currencyfx;
                                accounting_journal_detailList.Add(AR_accounting_journal_detail);
                            }
                        }
                    }
                }

                ///Clean up Duplicate Accounts.
                ///If Duplicate, will sum into first of the same chart it Finds.
                foreach (accounting_journal_detail accounting_journal_detail in accounting_journal_detailList)
                {
                    int id_chart = accounting_journal_detail.accounting_chart.id_chart;
                    if (accounting_journal.accounting_journal_detail.Where(x => x.id_chart == id_chart).Count() == 0)
                    {
                        accounting_journal_detail PAYaccounting_journal_detail = new accounting_journal_detail();
                        PAYaccounting_journal_detail.id_chart         = accounting_journal_detail.accounting_chart.id_chart;
                        PAYaccounting_journal_detail.accounting_chart = accounting_journal_detail.accounting_chart;
                        PAYaccounting_journal_detail.trans_date       = accounting_journal_detail.trans_date;
                        PAYaccounting_journal_detail.credit           = Math.Round(accounting_journal_detail.credit, 2);
                        PAYaccounting_journal_detail.debit            = Math.Round(accounting_journal_detail.debit, 2);
                        PAYaccounting_journal_detail.id_currencyfx    = accounting_journal_detail.id_currencyfx;
                        accounting_journal.accounting_journal_detail.Add(PAYaccounting_journal_detail);
                    }
                    else
                    {
                        accounting_journal_detail PAYaccounting_journal_detail = accounting_journal.accounting_journal_detail.Where(x => x.id_chart == id_chart).FirstOrDefault();
                        PAYaccounting_journal_detail.credit += Math.Round(accounting_journal_detail.credit, 2);
                        PAYaccounting_journal_detail.debit  += Math.Round(accounting_journal_detail.debit, 2);
                    }
                }
                accounting_journal.purchase_invoice.Add(purchase_invoice);
            }

            return(accounting_journal);
        }
Esempio n. 26
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);
                }
            }
        }
Esempio n. 27
0
        public List <payment_schedual> insert_Schedual(object obj_entity)
        {
            List <payment_schedual> payment_schedualList = new List <payment_schedual>();

            //SALES INVOICE
            if (obj_entity as sales_invoice != null)
            {
                sales_invoice sales_invoice = (sales_invoice)obj_entity;
                foreach (app_contract_detail app_contract_detail in sales_invoice.app_contract.app_contract_detail.Where(x => x.is_order == false))
                {
                    payment_schedual payment_schedual = new payment_schedual();
                    payment_schedual.credit        = 0;
                    payment_schedual.debit         = sales_invoice.GrandTotal * app_contract_detail.coefficient;
                    payment_schedual.id_currencyfx = sales_invoice.id_currencyfx;
                    payment_schedual.sales_invoice = sales_invoice;
                    payment_schedual.trans_date    = sales_invoice.trans_date;
                    payment_schedual.expire_date   = sales_invoice.trans_date.AddDays(app_contract_detail.interval);
                    payment_schedual.status        = entity.Status.Documents_General.Approved;
                    payment_schedual.id_contact    = sales_invoice.id_contact;
                    payment_schedualList.Add(payment_schedual);

                    ///Checks if selected Contract has Promissory Note created.
                    if (sales_invoice.app_contract.is_promissory)
                    {
                        payment_promissory_note payment_promissory_note = new payment_promissory_note();
                        //Dates. Transactional (based on Sales Trans) and Expiry (based on Exp of Payment)...
                        payment_promissory_note.trans_date  = sales_invoice.trans_date;
                        payment_promissory_note.expiry_date = sales_invoice.trans_date.AddDays(app_contract_detail.interval);
                        //Navigational Properties...
                        payment_promissory_note.id_branch   = sales_invoice.id_branch;
                        payment_promissory_note.id_terminal = sales_invoice.id_terminal;
                        payment_promissory_note.id_company  = sales_invoice.id_company;
                        payment_promissory_note.id_contact  = sales_invoice.id_contact;
                        //Values...
                        payment_promissory_note.value         = sales_invoice.GrandTotal * app_contract_detail.coefficient;
                        payment_promissory_note.id_currencyfx = sales_invoice.id_currencyfx;
                        payment_promissory_note.status        = entity.Status.Documents.Pending;

                        //Create Payment to control the Promissory Note as Non-Calculated.
                        payment_schedual payment_schedual_promise = new payment_schedual();
                        //Debit Credit
                        payment_schedual_promise.credit = 0;
                        payment_schedual_promise.debit  = sales_invoice.GrandTotal * app_contract_detail.coefficient;
                        //Nav Properties
                        payment_schedual_promise.id_contact    = sales_invoice.id_contact;
                        payment_schedual_promise.id_currencyfx = sales_invoice.id_currencyfx;
                        payment_schedual_promise.sales_invoice = sales_invoice;
                        //Date
                        payment_schedual_promise.trans_date    = sales_invoice.trans_date;
                        payment_schedual_promise.expire_date   = sales_invoice.trans_date.AddDays(app_contract_detail.interval);
                        payment_schedual_promise.can_calculate = false;
                        //Pending so that we can Approve while Printing.
                        payment_schedual_promise.status = entity.Status.Documents_General.Pending;

                        //Adding Payment Schedual into PromissoryNote
                        payment_promissory_note.payment_schedual.Add(payment_schedual_promise);
                        payment_promissory_noteLIST.Add(payment_promissory_note);
                    }
                }

                return(payment_schedualList);
            }

            //SALES RETURN
            else if (obj_entity as sales_return != null)
            {
                sales_return sales_return = (sales_return)obj_entity;

                payment_schedual payment_schedual = new payment_schedual();
                payment_schedual.debit         = sales_return.GrandTotal;
                payment_schedual.credit        = 0;
                payment_schedual.id_currencyfx = sales_return.id_currencyfx;
                payment_schedual.sales_return  = sales_return;
                payment_schedual.trans_date    = sales_return.trans_date;
                payment_schedual.expire_date   = sales_return.trans_date;
                payment_schedual.status        = entity.Status.Documents_General.Approved;
                payment_schedual.id_contact    = sales_return.id_contact;
                payment_schedual.can_calculate = false;
                payment_schedualList.Add(payment_schedual);

                return(payment_schedualList);
            }

            //PURCHASE RETURN
            else if (obj_entity as purchase_return != null)
            {
                purchase_return purchase_return = (purchase_return)obj_entity;

                payment_schedual payment_schedual = new payment_schedual();
                payment_schedual.credit          = purchase_return.GrandTotal;
                payment_schedual.debit           = 0;
                payment_schedual.id_currencyfx   = purchase_return.id_currencyfx;
                payment_schedual.purchase_return = purchase_return;
                payment_schedual.trans_date      = purchase_return.trans_date;
                payment_schedual.expire_date     = purchase_return.trans_date;
                payment_schedual.status          = entity.Status.Documents_General.Approved;
                payment_schedual.id_contact      = purchase_return.id_contact;
                payment_schedual.can_calculate   = false;
                payment_schedualList.Add(payment_schedual);

                return(payment_schedualList);
            }


            //SALES ORDER
            else if (obj_entity as sales_order != null)
            {
                sales_order sales_order = (sales_order)obj_entity;

                foreach (app_contract_detail app_contract_detail in sales_order.app_contract.app_contract_detail.Where(x => x.is_order))
                {
                    payment_schedual payment_schedual = new payment_schedual();
                    payment_schedual.credit        = 0;
                    payment_schedual.debit         = sales_order.GrandTotal * app_contract_detail.coefficient;
                    payment_schedual.id_currencyfx = sales_order.id_currencyfx;
                    payment_schedual.sales_order   = sales_order;
                    payment_schedual.trans_date    = sales_order.trans_date;
                    payment_schedual.expire_date   = sales_order.trans_date.AddDays(app_contract_detail.interval);
                    payment_schedual.status        = entity.Status.Documents_General.Approved;
                    payment_schedual.id_contact    = sales_order.id_contact;
                    payment_schedualList.Add(payment_schedual);
                }
                return(payment_schedualList);
            }



            //PURCHASE INVOICE
            else if (obj_entity as purchase_invoice != null)
            {
                purchase_invoice purchase_invoice = (purchase_invoice)obj_entity;

                foreach (app_contract_detail app_contract_detail in purchase_invoice.app_contract.app_contract_detail.Where(x => x.is_order == false))
                {
                    payment_schedual payment_schedual = new payment_schedual();
                    payment_schedual.credit           = purchase_invoice.GrandTotal * app_contract_detail.coefficient;
                    payment_schedual.debit            = 0;
                    payment_schedual.id_currencyfx    = purchase_invoice.id_currencyfx;
                    payment_schedual.purchase_invoice = purchase_invoice;
                    payment_schedual.trans_date       = purchase_invoice.trans_date;
                    payment_schedual.expire_date      = purchase_invoice.trans_date.AddDays(app_contract_detail.interval);
                    payment_schedual.status           = entity.Status.Documents_General.Pending;
                    payment_schedual.id_contact       = purchase_invoice.id_contact;
                    payment_schedualList.Add(payment_schedual);
                }
                return(payment_schedualList);
            }


            //PURCHASE ORDER
            else if (obj_entity as purchase_order != null)
            {
                purchase_order purchase_order = (purchase_order)obj_entity;

                foreach (app_contract_detail app_contract_detail in purchase_order.app_contract.app_contract_detail.Where(x => x.is_order))
                {
                    payment_schedual payment_schedual = new payment_schedual();
                    payment_schedual.credit         = purchase_order.GrandTotal * app_contract_detail.coefficient;
                    payment_schedual.debit          = 0;
                    payment_schedual.id_currencyfx  = purchase_order.id_currencyfx;
                    payment_schedual.purchase_order = purchase_order;
                    payment_schedual.trans_date     = purchase_order.trans_date;
                    payment_schedual.expire_date    = purchase_order.trans_date.AddDays(app_contract_detail.interval);
                    payment_schedual.status         = entity.Status.Documents_General.Pending;
                    payment_schedual.id_contact     = purchase_order.id_contact;
                    payment_schedualList.Add(payment_schedual);
                }
                return(payment_schedualList);
            }

            return(null);
        }
Esempio n. 28
0
        public List <payment_schedual> revert_Schedual(object obj_entity)
        {
            List <payment_schedual> payment_schedualList = new List <payment_schedual>();

            //SALES INVOICE
            if (obj_entity as sales_invoice != null)
            {
                sales_invoice sales_invoice = (sales_invoice)obj_entity;
                if (sales_invoice.payment_schedual != null)
                {
                    foreach (payment_schedual payment in sales_invoice.payment_schedual)
                    {
                        payment_schedualList.AddRange(update_Status(payment));
                    }
                }
            }
            //SALES ORDER
            else if (obj_entity as sales_order != null)
            {
                sales_order sales_order = (sales_order)obj_entity;
                if (sales_order.payment_schedual != null)
                {
                    foreach (payment_schedual payment in sales_order.payment_schedual)
                    {
                        payment_schedualList.AddRange(update_Status(payment));
                    }
                }
            }
            //PURCHASE INVOICE
            else if (obj_entity as purchase_invoice != null)
            {
                purchase_invoice purchase_invoice = (purchase_invoice)obj_entity;
                if (purchase_invoice.payment_schedual != null)
                {
                    foreach (payment_schedual payment in purchase_invoice.payment_schedual)
                    {
                        payment_schedualList.AddRange(update_Status(payment));
                    }
                }
            }
            //PURCHASE ORDER
            else if (obj_entity as purchase_order != null)
            {
                //If function to liberate paid amount
                purchase_order purchase_order = (purchase_order)obj_entity;
                if (purchase_order.payment_schedual != null)
                {
                    foreach (payment_schedual payment in purchase_order.payment_schedual)
                    {
                        payment_schedualList.AddRange(update_Status(payment));
                    }
                }
            }
            //PURCHASE RETURN
            else if (obj_entity as purchase_return != null)
            {
                //If function to liberate paid amount
                purchase_return purchase_return = (purchase_return)obj_entity;
                if (purchase_return.payment_schedual != null)
                {
                    foreach (payment_schedual payment in purchase_return.payment_schedual)
                    {
                        payment_schedualList.AddRange(update_Status(payment));
                    }
                }
            }
            //SALES RETURN
            else if (obj_entity as sales_return != null)
            {
                //If function to liberate paid amount
                sales_return sales_return = (sales_return)obj_entity;
                if (sales_return.payment_schedual != null)
                {
                    foreach (payment_schedual payment in sales_return.payment_schedual)
                    {
                        payment_schedualList.AddRange(update_Status(payment));
                    }
                }
            }

            return(payment_schedualList);
        }
Esempio n. 29
0
        public void purchase()
        {
            string sql = " SELECT " +
            " COMPRAS.CODCOMPRA, " +        //0
            " COMPRAS.NUMCOMPRA, " +        //1
            " COMPRAS.FECHACOMPRA, " +      //2
            " COMPRAS.TOTALDESCUENTO, " +   //3
            " COMPRAS.TOTALEXENTA, " +      //4
            " COMPRAS.TOTALGRAVADA, " +     //5
            " COMPRAS.TOTALIVA, " +         //6
            " COMPRAS.MODALIDADPAGO, " +    //7
            " COMPRAS.FECGRA, " +           //8
            " COMPRAS.ESTADO, " +           //9
            " COMPRAS.MOTIVOANULADO, " +    //10
            " COMPRAS.FECHACOMPRA, " +      //11
            " COMPRAS.TIMBRADOPROV, " +     //12
            " COMPRAS.TOTALIVA5, " +        //13
            " COMPRAS.TOTALIVA10, " +       //14
            " COMPRAS.METODO, " +           //15
            " COMPRAS.TOTALGRAVADO5, " +    //16
            " COMPRAS.TOTALGRAVADO10, " +   //17
            " COMPRAS.ASENTADO, " +         //18
            " COMPRAS.TOTALCOMPRA, " +      //19
            " PROVEEDOR.NOMBRE, " +         //20
            " PROVEEDOR.RUC_CIN, " +        //21
            " dbo.SUCURSAL.DESSUCURSAL, " +//28
            " COMPRAS.COTIZACION1, " +
            " dbo.FACTURAPAGAR.FECHAVCTO" +
            " FROM  COMPRAS RIGHT OUTER JOIN " +
            " PROVEEDOR ON COMPRAS.CODPROVEEDOR = PROVEEDOR.CODPROVEEDOR" +
            " LEFT OUTER JOIN FACTURAPAGAR ON COMPRAS.CODCOMPRA = FACTURAPAGAR.CODCOMPRA" +
             " RIGHT OUTER JOIN SUCURSAL ON COMPRAS.CODSUCURSAL = SUCURSAL.CODSUCURSAL";

            SqlConnection conn = new SqlConnection(_connString);

            //Counts Total number of Rows we have to process
            SqlCommand cmd = new SqlCommand(sql, conn);
            conn.Open();
            cmd.CommandText = "SELECT COUNT(*) FROM COMPRAS";
            cmd.CommandType = CommandType.Text;
            int count = (int)cmd.ExecuteScalar();
            conn.Close();

            int value = 0;

            Dispatcher.BeginInvoke((Action)(() => purchaseMaximum.Text = count.ToString()));
            Dispatcher.BeginInvoke((Action)(() => purchaseValue.Text = value.ToString()));
            Dispatcher.BeginInvoke((Action)(() => progPurchase.Maximum = count));
            Dispatcher.BeginInvoke((Action)(() => progPurchase.Value = value));

            cmd = new SqlCommand(sql, conn);
            conn.Open();
            cmd.CommandType = CommandType.Text;
            DataTable dt_purchase = exeDT(sql);
            //SqlDataReader reader = cmd.ExecuteReader();

            foreach (DataRow purchaserow in dt_purchase.Rows)
            {
                using (PurchaseInvoiceDB db = new PurchaseInvoiceDB())
                {
                    db.Configuration.AutoDetectChangesEnabled = false;

                    purchase_invoice purchase_invoice = db.New();

                    purchase_invoice.number = purchaserow["NUMCOMPRA"] is DBNull ? null : purchaserow["NUMCOMPRA"].ToString();
                    if (!(purchaserow["FECHACOMPRA"] is DBNull))
                    {
                        purchase_invoice.trans_date = Convert.ToDateTime(purchaserow["FECHACOMPRA"]);
                    }
                    else
                    {
                        continue;
                    }

                    //Supplier
                    if (!(purchaserow["NOMBRE"] is DBNull))
                    {
                        string _customer = purchaserow["NOMBRE"].ToString();
                        contact contact = db.contacts.Where(x => x.name == _customer && x.id_company == id_company).FirstOrDefault();
                        purchase_invoice.id_contact = contact.id_contact;
                    }

                    //Condition (Cash or Credit)
                    if (!(purchaserow["MODALIDADPAGO"] is DBNull) && Convert.ToInt32(purchaserow["MODALIDADPAGO"]) == 0)
                    {
                        app_condition app_condition = db.app_condition.Where(x => x.name == "Contado").FirstOrDefault();
                        purchase_invoice.id_condition = app_condition.id_condition;
                        //Contract...

                        app_contract_detail app_contract_detail = db.app_contract_detail.Where(x => x.app_contract.id_condition == purchase_invoice.id_condition && x.app_contract.id_company == id_company).FirstOrDefault();
                        if (app_contract_detail != null)
                        {
                            purchase_invoice.id_contract = app_contract_detail.id_contract;
                        }
                        else
                        {
                            app_contract app_contract = GenerateDefaultContrat(app_condition, 0);
                            db.app_contract.Add(app_contract);

                            purchase_invoice.app_contract = app_contract;
                            purchase_invoice.id_contract = app_contract.id_contract;
                        }
                    }
                    else if (!(purchaserow["MODALIDADPAGO"] is DBNull) && Convert.ToInt32(purchaserow["MODALIDADPAGO"]) == 1)
                    {
                        app_condition app_condition = db.app_condition.Where(x => x.name == "Crédito" && x.id_company == id_company).FirstOrDefault();
                        purchase_invoice.id_condition = app_condition.id_condition;
                        //Contract...
                        if (!(purchaserow["FECHAVCTO"] is DBNull))
                        {
                            DateTime _due_date = Convert.ToDateTime(purchaserow["FECHAVCTO"]);
                            int interval = (_due_date - purchase_invoice.trans_date).Days;
                            app_contract_detail app_contract_detail = db.app_contract_detail.Where(x => x.app_contract.id_condition == purchase_invoice.id_condition && x.app_contract.id_company == id_company && x.interval == interval).FirstOrDefault();
                            if (app_contract_detail != null)
                            {
                                purchase_invoice.id_contract = app_contract_detail.id_contract;
                            }
                            else
                            {
                                app_contract app_contract = GenerateDefaultContrat(app_condition, interval);
                                db.app_contract.Add(app_contract);

                                purchase_invoice.app_contract = app_contract;
                                purchase_invoice.id_contract = app_contract.id_contract;
                            }
                        }
                    }

                    int id_location = 0;
                    //Branch
                    if (!(purchaserow["DESSUCURSAL"] is DBNull))
                    {
                        //Branch
                        string _branch = purchaserow["DESSUCURSAL"].ToString();
                        app_branch app_branch = db.app_branch.Where(x => x.name == _branch && x.id_company == id_company).FirstOrDefault();
                        purchase_invoice.id_branch = app_branch.id_branch;

                        //Location
                        id_location = db.app_location.Where(x => x.id_branch == app_branch.id_branch && x.is_default).FirstOrDefault().id_location;

                        //Terminal
                        purchase_invoice.id_terminal = db.app_terminal.Where(x => x.app_branch.id_branch == app_branch.id_branch).FirstOrDefault().id_terminal;
                    }

                    string _desMoneda = string.Empty;

                    //Sales Invoice Detail
                    string sqlDetail = "SELECT"
                    + " dbo.PRODUCTOS.DESPRODUCTO as ITEM_DESPRODUCTO," //0
                    + " dbo.COMPRASDETALLE.DESPRODUCTO," //1
                    + " dbo.COMPRASDETALLE.CANTIDADCOMPRA, " //2
                    + " dbo.COMPRASDETALLE.COSTOUNITARIO, " //3
                    + " dbo.COMPRASDETALLE.IVA, " //4
                    + " dbo.COMPRAS.COTIZACION1, " //5
                    + " dbo.MONEDA.DESMONEDA " //6
                    + " FROM dbo.COMPRAS LEFT OUTER JOIN"
                    + " dbo.MONEDA ON dbo.COMPRAS.CODMONEDA = dbo.MONEDA.CODMONEDA LEFT OUTER JOIN"
                    + " dbo.COMPRASDETALLE ON dbo.COMPRAS.CODCOMPRA = dbo.COMPRASDETALLE.CODCOMPRA LEFT OUTER JOIN"
                    + " dbo.PRODUCTOS ON dbo.COMPRASDETALLE.CODPRODUCTO = dbo.PRODUCTOS.CODPRODUCTO"
                    + " WHERE (dbo.COMPRASDETALLE.CODCOMPRA = " + purchaserow["CODCOMPRA"].ToString() + ")";

                    DataTable dt = exeDT(sqlDetail);
                    foreach (DataRow row in dt.Rows)
                    {
                        //db Related Insertion.
                        purchase_invoice.id_currencyfx = 1;

                        purchase_invoice_detail purchase_invoice_detail = new purchase_invoice_detail();

                        string _prod_Name = row["ITEM_DESPRODUCTO"].ToString();
                        if (db.items.Where(x => x.name == _prod_Name && x.id_company == id_company).FirstOrDefault() != null)
                        {
                            //Only if Item Exists
                            item item = db.items.Where(x => x.name == _prod_Name && x.id_company == id_company).FirstOrDefault();
                            purchase_invoice_detail.id_item = item.id_item;
                        }

                        if (row["DESPRODUCTO"] is DBNull)
                        {
                            //If not Item Description, then just continue out of this loop.
                            continue;
                        }

                        purchase_invoice_detail.item_description = row["DESPRODUCTO"].ToString();
                        purchase_invoice_detail.quantity = Convert.ToDecimal(row["CANTIDADCOMPRA"]);

                        purchase_invoice_detail.id_location = id_location;

                        string _iva = row["IVA"].ToString();
                        if (_iva == "10.00")
                        {
                            purchase_invoice_detail.id_vat_group = db.app_vat_group.Where(x => x.name == "10%").FirstOrDefault().id_vat_group;
                        }
                        else if (_iva == "5.00")
                        {
                            purchase_invoice_detail.id_vat_group = db.app_vat_group.Where(x => x.name == "5%").FirstOrDefault().id_vat_group;
                        }
                        else
                        {
                            if (db.app_vat_group.Where(x => x.name == "Excento").FirstOrDefault() != null)
                            {
                                purchase_invoice_detail.id_vat_group = db.app_vat_group.Where(x => x.name == "Excento").FirstOrDefault().id_vat_group;
                            }
                        }

                        decimal cotiz1 = Convert.ToDecimal((row["COTIZACION1"] is DBNull) ? 1 : Convert.ToDecimal(row["COTIZACION1"]));
                        // purchase_invoice_detail.unit_price = (Convert.ToDecimal(row["PRECIOVENTANETO"]) / purchase_invoice_detail.quantity) / cotiz1;

                        if (row["COSTOUNITARIO"] is DBNull)
                        {
                            purchase_invoice_detail.unit_cost = 0;
                        }
                        else
                        {
                            purchase_invoice_detail.unit_cost = Convert.ToDecimal(row["COSTOUNITARIO"]);
                        }
                        //Commit Sales Invoice Detail
                        purchase_invoice.purchase_invoice_detail.Add(purchase_invoice_detail);
                    }

                    if (purchase_invoice.Error == null)
                    {
                        try
                        {
                            purchase_invoice.State = System.Data.Entity.EntityState.Added;
                            purchase_invoice.IsSelected = true;

                            // db.purchase_invoice.Add(purchase_invoice);
                            IEnumerable<DbEntityValidationResult> validationresult = db.GetValidationErrors();
                            if (validationresult.Count() == 0)
                            {
                                db.SaveChanges();
                            }
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }

                        //Sales Brillo
                        //if (reader.GetInt32(10) == 1)
                        //{
                        //    entity.Brillo.Approve.SalesInvoice salesBrillo = new entity.Brillo.Approve.SalesInvoice();
                        //    salesBrillo.Start(ref db, sales_invoice);
                        //    sales_invoice.status = 0; ?????
                        //}
                        //else if (reader.GetInt32(10))
                        //{
                        //    entity.Brillo.Approve.SalesInvoice salesBrillo = new entity.Brillo.Approve.SalesInvoice();
                        //    salesBrillo.Start(ref db, sales_invoice);
                        //    entity.Brillo.Annul.SalesInvoice salesAnullBrillo = new entity.Brillo.Annul.SalesInvoice();
                        //    salesAnullBrillo.Start(ref db, sales_invoice);
                        //    sales_invoice.status = 0; ?????
                        //}

                        value += 1;
                        Dispatcher.BeginInvoke((Action)(() => progPurchase.Value = value));
                        Dispatcher.BeginInvoke((Action)(() =>purchaseValue.Text = value.ToString()));
                    }
                    else
                    {
                        //Add code to include error contacts into
                        purchase_invoice_ErrorList.Add(purchase_invoice);
                    }
                }
            }
               // reader.Close();
            cmd.Dispose();
            conn.Close();

            _customer_Current = _customer_Max;
        }
Esempio n. 30
0
        private void btnSave_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                payment_withholding_tax payment_withholding_tax = new payment_withholding_tax();
                payment_withholding_tax.status     = Status.Documents_General.Pending;
                payment_withholding_tax.id_contact = ((dynamic)_invoiceList.FirstOrDefault()).id_contact;
                if (cbxDocument.SelectedValue != null)
                {
                    payment_withholding_tax.id_range = (int)cbxDocument.SelectedValue;
                }

                payment_withholding_tax.id_currencyfx      = ((dynamic)_invoiceList.FirstOrDefault()).id_currencyfx;
                payment_withholding_tax.withholding_number = txtnumber.Text;
                payment_withholding_tax.value       = (decimal)lbltotalvat.Content;
                payment_withholding_tax.trans_date  = (DateTime)DtpTransdate.SelectedDate;
                payment_withholding_tax.expire_date = (DateTime)DtpTransdate.SelectedDate;


                payment_withholding_details payment_withholding_details = new payment_withholding_details();
                if (_invoiceList.FirstOrDefault().GetType() == typeof(sales_invoice) || _invoiceList.FirstOrDefault().GetType().BaseType == typeof(sales_invoice))
                {
                    sales_invoice sales_invoice = (sales_invoice)_invoiceList.FirstOrDefault();
                    payment_withholding_details.id_sales_invoice = sales_invoice.id_sales_invoice;
                }
                else if (_invoiceList.FirstOrDefault().GetType() == typeof(purchase_invoice) || _invoiceList.FirstOrDefault().GetType().BaseType == typeof(purchase_invoice))
                {
                    purchase_invoice purchase_invoice = (purchase_invoice)_invoiceList.FirstOrDefault();
                    payment_withholding_details.id_purchase_invoice = purchase_invoice.id_purchase_invoice;
                }

                payment_withholding_tax.payment_withholding_details.Add(payment_withholding_details);

                PaymentDB.payment_withholding_tax.Add(payment_withholding_tax);
                payment_schedual _payment_schedual = new payment_schedual();

                if (_invoiceList.FirstOrDefault().GetType().BaseType == typeof(sales_invoice))
                {
                    _payment_schedual.credit = Convert.ToDecimal(lbltotalvat.Content);
                }
                else if (_invoiceList.FirstOrDefault().GetType().BaseType == typeof(purchase_invoice))
                {
                    _payment_schedual.debit = Convert.ToDecimal(lbltotalvat.Content);
                }

                _payment_schedual.parent              = payment_schedual;
                _payment_schedual.expire_date         = payment_schedual.expire_date;
                _payment_schedual.status              = payment_schedual.status;
                _payment_schedual.id_contact          = payment_schedual.id_contact;
                _payment_schedual.id_currencyfx       = payment_schedual.id_currencyfx;
                _payment_schedual.id_purchase_invoice = payment_schedual.id_purchase_invoice;
                _payment_schedual.id_purchase_order   = payment_schedual.id_purchase_order;
                _payment_schedual.id_purchase_return  = payment_schedual.id_purchase_return;
                _payment_schedual.id_sales_invoice    = payment_schedual.id_sales_invoice;
                _payment_schedual.id_sales_order      = payment_schedual.id_sales_order;
                _payment_schedual.id_sales_return     = payment_schedual.id_sales_return;
                _payment_schedual.trans_date          = (DateTime)DtpTransdate.SelectedDate;

                PaymentDB.payment_schedual.Add(_payment_schedual);

                PaymentDB.SaveChanges();

                Grid parentGrid = (Grid)this.Parent;
                parentGrid.Children.Clear();
                parentGrid.Visibility = System.Windows.Visibility.Hidden;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }