private void toolBar_btnNew_Click(object sender) { purchase_return purchase_return = dbContext.New(); dbContext.purchase_return.Add(purchase_return); purchaseReturnViewSource.View.MoveCurrentToLast(); }
private void toolBar_btnSearch_Click(object sender, string query) { try { if (!string.IsNullOrEmpty(query)) { purchaseReturnViewSource.View.Filter = i => { purchase_return purchase_return = i as purchase_return; if (purchase_return.contact.name.ToLower().Contains(query.ToLower())) { return(true); } else { return(false); } }; } else { purchaseReturnViewSource.View.Filter = null; } } catch (Exception) { } }
public async void PurchaseInvoice_Click(object sender) { purchase_return _purchase_return = (purchase_return)purchaseReturnViewSource.View.CurrentItem; sbxContact.Text = pnlPurchaseInvoice.selected_purchase_invoice.FirstOrDefault().contact.name; foreach (purchase_invoice item in pnlPurchaseInvoice.selected_purchase_invoice) { _purchase_return.State = EntityState.Modified; _purchase_return.id_condition = item.id_condition; _purchase_return.id_contract = item.id_contract; _purchase_return.id_currencyfx = item.id_currencyfx; _purchase_return.id_purchase_invoice = item.id_purchase_invoice; foreach (purchase_invoice_detail _purchase_invoice_detail in item.purchase_invoice_detail) { if (_purchase_return.purchase_return_detail.Where(x => x.id_item == _purchase_invoice_detail.id_item).Count() == 0) { purchase_return_detail purchase_return_detail = new purchase_return_detail(); purchase_return_detail.id_purchase_invoice_detail = _purchase_invoice_detail.id_purchase_invoice_detail; purchase_return_detail.id_cost_center = _purchase_invoice_detail.id_cost_center; purchase_return_detail.id_location = _purchase_invoice_detail.id_location; if (dbContext.app_location.Where(x => x.id_location == _purchase_invoice_detail.id_location).FirstOrDefault() != null) { purchase_return_detail.app_location = dbContext.app_location.Where(x => x.id_location == _purchase_invoice_detail.id_location).FirstOrDefault(); } purchase_return_detail.purchase_return = _purchase_return; if (dbContext.items.Where(x => x.id_item == _purchase_invoice_detail.id_item).FirstOrDefault() != null) { purchase_return_detail.id_item = _purchase_invoice_detail.id_item; purchase_return_detail.item = dbContext.items.Where(x => x.id_item == _purchase_invoice_detail.id_item).FirstOrDefault(); } purchase_return_detail.item_description = _purchase_invoice_detail.item_description; purchase_return_detail.quantity = _purchase_invoice_detail.quantity - dbContext.purchase_return_detail .Where(x => x.id_purchase_invoice_detail == _purchase_invoice_detail.id_purchase_invoice_detail) .GroupBy(x => x.id_purchase_invoice_detail).Select(x => x.Sum(y => y.quantity)).FirstOrDefault(); purchase_return_detail.id_vat_group = _purchase_invoice_detail.id_vat_group; purchase_return_detail.unit_cost = _purchase_invoice_detail.unit_cost; purchase_return_detail.CurrencyFX_ID = _purchase_return.id_currencyfx; _purchase_return.purchase_return_detail.Add(purchase_return_detail); } dbContext.Entry(_purchase_return).Entity.State = EntityState.Added; crud_modal.Children.Clear(); crud_modal.Visibility = Visibility.Collapsed; purchaseReturnViewSource.View.Refresh(); purchase_returnpurchase_return_detailViewSource.View.Refresh(); } } }
public void Fill_ByPurchaseReturn(purchase_return purchase_return) { this.Type = entity.DebeHaber.TransactionTypes.SalesReturn; this.TransDate = purchase_return.trans_date; this.CompanyName = purchase_return.contact.name; this.Gov_Code = purchase_return.contact.gov_code; this.Comment = purchase_return.comment; this.CurrencyName = purchase_return.app_currencyfx != null ? purchase_return.app_currencyfx.app_currency != null ? purchase_return.app_currencyfx.app_currency.name : "" : ""; this.DocNumber = purchase_return.number; this.DocCode = purchase_return.app_document_range != null ? purchase_return.app_document_range.code : ""; this.DocExpiry = (purchase_return.app_document_range != null ? (DateTime)purchase_return.app_document_range.expire_date : DateTime.Now); }
private void toolBar_btnEdit_Click(object sender) { if (purchase_returnDataGrid.SelectedItem != null) { purchase_return purchase_return = (purchase_return)purchase_returnDataGrid.SelectedItem; purchase_return.IsSelected = true; purchase_return.State = EntityState.Modified; dbContext.Entry(purchase_return).State = EntityState.Modified; } else { toolBar.msgWarning("Please Select an Item"); } }
private void purchasereturnComboBox_MouseDoubleClick(object sender, MouseButtonEventArgs e) { try { if (purchasereturnComboBox.Data != null) { purchase_return purchase_return = (purchase_return)purchasereturnComboBox.Data; purchasereturnComboBox.Text = purchase_return.number; } } catch (Exception ex) { throw ex; } }
private void set_ContactPref(object sender, EventArgs e) { if (sbxContact.ContactID > 0) { contact contact = dbContext.contacts.Where(x => x.id_contact == sbxContact.ContactID).FirstOrDefault(); purchase_return purchase_return = (purchase_return)purchase_returnDataGrid.SelectedItem; purchase_return.id_contact = contact.id_contact; purchase_return.contact = contact; if (purchase_return != null) { ///Start Thread to get Data. Task thread_SecondaryData = Task.Factory.StartNew(() => set_ContactPref_Thread(contact)); } } }
private void calculate_vat(object sender, EventArgs e) { purchase_return purchase_return = (purchase_return)purchase_returnDataGrid.SelectedItem; purchase_return.RaisePropertyChanged("GrandTotal"); //List<purchase_return_detail> purchase_return_detail = purchase_return.purchase_return_detail.ToList(); //dgvvat.ItemsSource = purchase_return_detail // .Join(dbContext.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(); }
private void DeleteCommand_Executed(object sender, ExecutedRoutedEventArgs e) { try { MessageBoxResult result = MessageBox.Show("Are you sure want to Delete?", "Delete", MessageBoxButton.YesNo, MessageBoxImage.Question); if (result == MessageBoxResult.Yes) { purchase_return purchase_return = purchaseReturnViewSource.View.CurrentItem as purchase_return; //DeleteDetailGridRow purchase_return_detailDataGrid.CancelEdit(); dbContext.purchase_return_detail.Remove(e.Parameter as purchase_return_detail); purchase_returnpurchase_return_detailViewSource.View.Refresh(); } } catch (Exception ex) { toolBar.msgError(ex); } }
private void purchasereturnComboBox_MouseDoubleClick(object sender, MouseButtonEventArgs e) { try { try { if (purchasereturnComboBox.Data != null) { CollectionViewSource paymentpayment_detailViewSource = (CollectionViewSource)this.FindResource("paymentpayment_detailViewSource"); payment_detail payment_detail = paymentpayment_detailViewSource.View.CurrentItem as payment_detail; purchase_return purchase_return = (purchase_return)purchasereturnComboBox.Data; purchasereturnComboBox.Text = purchase_return.number; decimal return_value = (purchase_return.GrandTotal - purchase_return.payment_schedual.Where(x => x.id_purchase_return == purchase_return.id_purchase_return).Sum(x => x.debit)); payment_detail.id_purchase_return = purchase_return.id_purchase_return; if (payment_detail.value > return_value) { payment_detail.value = return_value; payment_detail.RaisePropertyChanged("value"); } else { payment_detail.value = payment_detail.value; payment_detail.RaisePropertyChanged("value"); } } } catch (Exception ex) { throw ex; } } catch (Exception ex) { throw ex; } }
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); }
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); }
private void item_Select(object sender, EventArgs e) { try { if (sbxItem.ItemID > 0) { item item = dbContext.items.Where(x => x.id_item == sbxItem.ItemID).FirstOrDefault(); purchase_return purchase_return = purchase_returnDataGrid.SelectedItem as purchase_return; purchase_return_detail purchase_return_detail = purchase_return.purchase_return_detail.Where(a => a.id_item == sbxItem.ItemID).FirstOrDefault(); int id_cost_center = 0; if (purchase_return_detail == null) { purchase_return_detail _purchase_return_detail = new entity.purchase_return_detail(); //Check for contact if (sbxContact.ContactID > 0) { contact contact = dbContext.contacts.Where(x => x.id_contact == sbxContact.ContactID).FirstOrDefault(); if (contact.app_cost_center != null) { app_cost_center app_cost_center = contact.app_cost_center as app_cost_center; if (app_cost_center.is_product == true) { id_cost_center = app_cost_center.id_cost_center; if (id_cost_center > 0) { _purchase_return_detail.id_cost_center = id_cost_center; } } else { if (dbContext.app_cost_center.Where(a => a.is_product == true && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault() != null) { id_cost_center = Convert.ToInt32(dbContext.app_cost_center.Where(a => a.is_product == true && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault().id_cost_center); } if (id_cost_center > 0) { _purchase_return_detail.id_cost_center = id_cost_center; } } } else { if (dbContext.app_cost_center.Where(a => a.is_product == true && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault() != null) { id_cost_center = Convert.ToInt32(dbContext.app_cost_center.Where(a => a.is_product == true && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault().id_cost_center); } if (id_cost_center > 0) { _purchase_return_detail.id_cost_center = id_cost_center; } } } else { if (dbContext.app_cost_center.Where(a => a.is_product == true && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault() != null) { id_cost_center = Convert.ToInt32(dbContext.app_cost_center.Where(a => a.is_product == true && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault().id_cost_center); } if (id_cost_center > 0) { _purchase_return_detail.id_cost_center = id_cost_center; } } if (dbContext.app_vat_group.Where(x => x.is_active == true && x.is_default == true && x.id_company == _entity.company_ID).FirstOrDefault() != null) { _purchase_return_detail.id_vat_group = dbContext.app_vat_group.Where(x => x.is_active == true && x.is_default == true && x.id_company == _entity.company_ID).FirstOrDefault().id_vat_group; } _purchase_return_detail.purchase_return = purchase_return; _purchase_return_detail.item = item; _purchase_return_detail.id_item = sbxItem.ItemID; purchase_return.purchase_return_detail.Add(_purchase_return_detail); } else { purchase_return_detail.quantity += 1; } purchase_returnpurchase_return_detailViewSource.View.Refresh(); //calculate_total(sender, e); calculate_vat(sender, e); } else { //Other purchase_return purchase_return = purchase_returnDataGrid.SelectedItem as purchase_return; purchase_return_detail purchase_return_detail = purchase_return.purchase_return_detail.Where(a => a.item_description == sbxItem.Text).FirstOrDefault(); if (purchase_return_detail == null) { purchase_return_detail _purchase_return_detail = new entity.purchase_return_detail(); int id_cost_center = 0; //Check for contact if (sbxContact.ContactID > 0) { contact contact = dbContext.contacts.Where(x => x.id_contact == sbxContact.ContactID).FirstOrDefault(); if (contact.app_cost_center != null) { app_cost_center app_cost_center = contact.app_cost_center as app_cost_center; if (app_cost_center.is_product == false) { id_cost_center = app_cost_center.id_cost_center; if (id_cost_center > 0) { _purchase_return_detail.id_cost_center = id_cost_center; } } else { if (dbContext.app_cost_center.Where(a => a.is_product == false && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault() != null) { id_cost_center = Convert.ToInt32(dbContext.app_cost_center.Where(a => a.is_product == false && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault().id_cost_center); } if (id_cost_center > 0) { _purchase_return_detail.id_cost_center = id_cost_center; } } } else { if (dbContext.app_cost_center.Where(a => a.is_product == false && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault() != null) { id_cost_center = Convert.ToInt32(dbContext.app_cost_center.Where(a => a.is_product == false && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault().id_cost_center); } if (id_cost_center > 0) { _purchase_return_detail.id_cost_center = id_cost_center; } } } else { if (dbContext.app_cost_center.Where(a => a.is_product == false && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault() != null) { id_cost_center = Convert.ToInt32(dbContext.app_cost_center.Where(a => a.is_product == false && a.is_active == true && a.id_company == _entity.company_ID).FirstOrDefault().id_cost_center); } if (id_cost_center > 0) { _purchase_return_detail.id_cost_center = id_cost_center; } } if (dbContext.app_vat_group.Where(x => x.is_active == true && x.is_default == true && x.id_company == _entity.company_ID).FirstOrDefault() != null) { _purchase_return_detail.id_vat_group = dbContext.app_vat_group.Where(x => x.is_active == true && x.is_default == true && x.id_company == _entity.company_ID).FirstOrDefault().id_vat_group; } _purchase_return_detail.purchase_return = purchase_return; _purchase_return_detail.item_description = sbxItem.Text; _purchase_return_detail.id_item = 0; purchase_return.purchase_return_detail.Add(_purchase_return_detail); } else { purchase_return_detail.quantity += 1; } purchase_returnpurchase_return_detailViewSource.View.Refresh(); calculate_vat(sender, e); } } catch (Exception) { //throw ex; } }
private void purchase_return_detailDataGrid_InitializingNewItem(object sender, InitializingNewItemEventArgs e) { purchase_return_detail purchase_return_detail = (purchase_return_detail)e.NewItem; purchase_return purchase_return = (purchase_return)purchase_returnDataGrid.SelectedItem; }