private void btnNew_Click(object sender, RoutedEventArgs e) { crud_modal.Visibility = Visibility.Visible; cntrl.Curd.cost_center cost_center = new cntrl.Curd.cost_center(); app_cost_center app_cost_center = new app_cost_center(); entity.db.app_cost_center.Add(app_cost_center); cost_centerViewSource.View.MoveCurrentToLast(); cost_center.app_cost_centerViewSource = cost_centerViewSource; cost_center.entity = entity; crud_modal.Children.Add(cost_center); }
private void btnDelete_Click(object sender, RoutedEventArgs e) { try { MessageBoxResult res = MessageBox.Show("Are you sure want to Delete?", "Cognitivo", MessageBoxButton.YesNo, MessageBoxImage.Question); if (res == MessageBoxResult.Yes) { app_cost_center app_cost_center = app_cost_centerViewSource.View.CurrentItem as entity.app_cost_center; app_cost_center.is_active = false; btnSave_Click(sender, e); } } catch (Exception ex) { throw ex; } }
private void sync_CostCenter() { DataTable dt = exeDT("SELECT * FROM CENTROCOSTO"); foreach (DataRow row in dt.Rows) { app_cost_center app_cost_center = new app_cost_center(); app_cost_center.name = (string)row["DESCENTRO"]; app_cost_center.is_product = Convert.ToBoolean(row["ENLAZADO"]); app_cost_center.is_administrative = Convert.ToBoolean(row["COSTOFIJO"]); app_cost_center.id_company = id_company; app_cost_center.is_active = true; dbContext.app_cost_center.Add(app_cost_center); } dt.Clear(); dbContext.SaveChanges(); }
public accounting_chart find_Chart(AccountingJournalDB context, app_cost_center app_cost_center) { if (context.accounting_chart.Where(i => i.id_cost_center == app_cost_center.id_cost_center).FirstOrDefault() != null) { return(context.accounting_chart.Where(i => i.id_cost_center == app_cost_center.id_cost_center).FirstOrDefault()); } else if (context.accounting_chart.Where(i => i.chartsub_type == accounting_chart.ChartSubType.AdministrationExpense && i.is_generic == true).FirstOrDefault() != null) { return(context.accounting_chart.Where(i => i.chartsub_type == accounting_chart.ChartSubType.AdministrationExpense && i.is_generic == true).FirstOrDefault()); } else { return(null); } //accounting_journal __accounting_journal = new accounting_journal(); //__accounting_journal.id_chart = accounting_chart.id_chart; //__accounting_journal.debit = sales_invoice.invoice_Total; }
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); }
private void SelectProduct_Thread(object sender, EventArgs e, purchase_order purchase_order, item item, contact contact) { purchase_order_detail purchase_order_detail = new purchase_order_detail(); purchase_order_detail.purchase_order = purchase_order; Cognitivo.Purchase.OrderSetting OrderSetting = new Cognitivo.Purchase.OrderSetting(); //ItemLink if (item != null) { if (purchase_order.purchase_order_detail.Where(a => a.id_item == item.id_item).FirstOrDefault() != null || OrderSetting.AllowDuplicateItems) { //Item Exists in Context, so add to sum. purchase_order_detail _purchase_order_detail = purchase_order.purchase_order_detail.Where(a => a.id_item == item.id_item).FirstOrDefault(); _purchase_order_detail.quantity += 1; //Return because Item exists, and will +1 in Quantity return; } else { //If Item Exists in previous purchase... then get Last Cost. Problem, will get in stored value, in future we will need to add logic to convert into current currency. if (PurchaseOrderDB.purchase_invoice_detail .Where(x => x.id_item == item.id_item && x.purchase_invoice.id_contact == purchase_order.id_contact) .OrderByDescending(y => y.purchase_invoice.trans_date) .FirstOrDefault() != null) { purchase_order_detail.unit_cost = PurchaseOrderDB.purchase_invoice_detail .Where(x => x.id_item == item.id_item && x.purchase_invoice.id_contact == purchase_order.id_contact) .OrderByDescending(y => y.purchase_invoice.trans_date) .FirstOrDefault().unit_cost; } //Item DOES NOT Exist in Context purchase_order_detail.item = item; purchase_order_detail.id_item = item.id_item; purchase_order_detail.item_description = item.name; purchase_order_detail.quantity = 1; } } else { Dispatcher.BeginInvoke((Action)(() => { purchase_order_detail.item_description = sbxItem.Text; })); } //Cost Center if (contact != null && contact.app_cost_center != null) { app_cost_center app_cost_center = contact.app_cost_center; if (app_cost_center.id_cost_center > 0) { purchase_order_detail.id_cost_center = app_cost_center.id_cost_center; } } else { if (item != null) { int id_cost_center = 0; if (item.item_product != null) { if (PurchaseOrderDB.app_cost_center.Where(a => a.is_product == true && a.is_active == true && a.id_company == CurrentSession.Id_Company).FirstOrDefault() != null) { id_cost_center = Convert.ToInt32(PurchaseOrderDB.app_cost_center.Where(a => a.is_product == true && a.is_active == true && a.id_company == CurrentSession.Id_Company).FirstOrDefault().id_cost_center); } if (id_cost_center > 0) { purchase_order_detail.id_cost_center = id_cost_center; } } else if (item.item_asset != null) { if (PurchaseOrderDB.app_cost_center.Where(a => a.is_fixedasset == true && a.is_active == true && a.id_company == CurrentSession.Id_Company).FirstOrDefault() != null) { id_cost_center = Convert.ToInt32(PurchaseOrderDB.app_cost_center.Where(a => a.is_fixedasset == true && a.is_active == true && a.id_company == CurrentSession.Id_Company).FirstOrDefault().id_cost_center); } if (id_cost_center > 0) { purchase_order_detail.id_cost_center = id_cost_center; } } } else { int id_cost_center = 0; if (PurchaseOrderDB.app_cost_center.Where(a => a.is_administrative == true && a.is_active == true && a.id_company == CurrentSession.Id_Company).FirstOrDefault() != null) { id_cost_center = Convert.ToInt32(PurchaseOrderDB.app_cost_center.Where(a => a.is_administrative == true && a.is_active == true && a.id_company == CurrentSession.Id_Company).FirstOrDefault().id_cost_center); } if (id_cost_center > 0) { purchase_order_detail.id_cost_center = id_cost_center; } } } //VAT if (item != null) { if (item.id_vat_group > 0) { purchase_order_detail.id_vat_group = item.id_vat_group; } } else if (PurchaseOrderDB.app_vat_group.Where(x => x.is_active == true && x.is_default == true && x.id_company == CurrentSession.Id_Company).FirstOrDefault() != null) { purchase_order_detail.id_vat_group = PurchaseOrderDB.app_vat_group.Where(x => x.is_active == true && x.is_default == true && x.id_company == CurrentSession.Id_Company).FirstOrDefault().id_vat_group; } Dispatcher.BeginInvoke((Action)(() => { purchase_order.purchase_order_detail.Add(purchase_order_detail); purchase_orderpurchase_order_detailViewSource.View.Refresh(); calculate_vat(sender, e); })); }
private void SelectProduct_Thread(object sender, EventArgs e, purchase_invoice purchase_invoice, item item, contact contact) { purchase_invoice_detail purchase_invoice_detail = new purchase_invoice_detail(); purchase_invoice_detail.purchase_invoice = purchase_invoice; Cognitivo.Purchase.InvoiceSetting InvoiceSetting = new Cognitivo.Purchase.InvoiceSetting(); //ItemLink if (item != null) { purchase_invoice_detail detail_withitem = purchase_invoice.purchase_invoice_detail.Where(a => a.id_item == item.id_item).FirstOrDefault(); if (detail_withitem != null && InvoiceSetting.AllowDuplicateItems) { //Item Exists in Context, so add to sum. purchase_invoice_detail _purchase_invoice_detail = detail_withitem; _purchase_invoice_detail.quantity += 1; //Return because Item exists, and will +1 in Quantity return; } else { //If Item Exists in previous purchase... then get Last Cost. Problem, will get in stored value, in future we will need to add logic to convert into current currency. purchase_invoice_detail _purchase_invoice_detail = PurchaseInvoiceDB.purchase_invoice_detail .Where(x => x.id_item == item.id_item && x.purchase_invoice.id_contact == purchase_invoice.id_contact) .OrderByDescending(y => y.purchase_invoice.trans_date) .FirstOrDefault(); if (_purchase_invoice_detail != null) { purchase_invoice_detail.unit_cost = _purchase_invoice_detail.unit_cost; } //Item DOES NOT Exist in Context purchase_invoice_detail.item = item; purchase_invoice_detail.id_item = item.id_item; purchase_invoice_detail.item_description = item.name; purchase_invoice_detail.quantity = 1; } foreach (item_dimension item_dimension in item.item_dimension) { purchase_invoice_dimension purchase_invoice_dimension = new purchase_invoice_dimension(); purchase_invoice_dimension.id_dimension = item_dimension.id_app_dimension; purchase_invoice_dimension.app_dimension = item_dimension.app_dimension; purchase_invoice_dimension.id_measurement = item_dimension.id_measurement; purchase_invoice_dimension.app_measurement = item_dimension.app_measurement; purchase_invoice_dimension.purchase_invoice_detail = purchase_invoice_detail; purchase_invoice_dimension.value = item_dimension.value; purchase_invoice_detail.purchase_invoice_dimension.Add(purchase_invoice_dimension); } } else { Dispatcher.BeginInvoke((Action)(() => { purchase_invoice_detail.item_description = sbxItem.Text; })); } //Cost Center if (contact != null && contact.app_cost_center != null) { app_cost_center app_cost_center = contact.app_cost_center; if (app_cost_center.id_cost_center > 0) { purchase_invoice_detail.id_cost_center = app_cost_center.id_cost_center; } } else { Dispatcher.BeginInvoke((Action)(() => { //If Contact does not exist, and If product exist, then take defualt Product Cost Center. Else, bring Administrative if (item != null) { int id_cost_center = 0; if (item.item_product != null) { app_cost_center app_cost_center = PurchaseInvoiceDB.app_cost_center.Where(a => a.is_product && a.is_active && a.id_company == CurrentSession.Id_Company).FirstOrDefault(); if (app_cost_center != null) { id_cost_center = Convert.ToInt32(app_cost_center.id_cost_center); } if (id_cost_center > 0) { purchase_invoice_detail.id_cost_center = id_cost_center; } } else if (item.item_asset != null) { app_cost_center app_cost_center = PurchaseInvoiceDB.app_cost_center.Where(a => a.is_fixedasset == true && a.is_active == true && a.id_company == CurrentSession.Id_Company).FirstOrDefault(); if (app_cost_center != null) { id_cost_center = Convert.ToInt32(app_cost_center.id_cost_center); } if (id_cost_center > 0) { purchase_invoice_detail.id_cost_center = id_cost_center; } } } else { int id_cost_center = 0; app_cost_center app_cost_center = PurchaseInvoiceDB.app_cost_center.Where(a => a.is_administrative == true && a.is_active == true && a.id_company == CurrentSession.Id_Company).FirstOrDefault(); if (app_cost_center != null) { id_cost_center = Convert.ToInt32(app_cost_center.id_cost_center); } if (id_cost_center > 0) { purchase_invoice_detail.id_cost_center = id_cost_center; } } })); } //VAT if (item != null) { if (item.id_vat_group > 0) { purchase_invoice_detail.id_vat_group = item.id_vat_group; } } else if (PurchaseInvoiceDB.app_vat_group.Where(x => x.is_active && x.is_default && x.id_company == CurrentSession.Id_Company).Any()) { purchase_invoice_detail.id_vat_group = PurchaseInvoiceDB.app_vat_group.Where(x => x.is_active && x.is_default && x.id_company == CurrentSession.Id_Company).FirstOrDefault().id_vat_group; } Dispatcher.BeginInvoke((Action)(() => { purchase_invoice.purchase_invoice_detail.Add(purchase_invoice_detail); purchase_invoicepurchase_invoice_detailViewSource.View.Refresh(); calculate_vat(null, null); })); }
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; } }
public void supplier() { string sql = " SELECT dbo.PROVEEDOR.NUMPROVEEDOR, dbo.PROVEEDOR.NOMBRE, dbo.PROVEEDOR.RUC_CIN, dbo.PROVEEDOR.DIRECCION, dbo.PROVEEDOR.TELEFONO, dbo.PROVEEDOR.EMAIL, dbo.PROVEEDOR.observacion, dbo.PROVEEDOR.CLIENTE_ID, dbo.PROVEEDOR.CONTACTO1, dbo.PROVEEDOR.CONTACTO2, dbo.PROVEEDOR.EMAILCONT1," + " dbo.PROVEEDOR.EMAILCONT2, dbo.PROVEEDOR.TELCONT1, dbo.PROVEEDOR.TELCONT2, dbo.PROVEEDOR.CELCONT1, dbo.PROVEEDOR.CELCONT2, dbo.PROVEEDOR.DIRECCIONCONT1, dbo.PROVEEDOR.DIRECCIONCONT2, dbo.PROVEEDOR.FORMAPAGO," + " dbo.PROVEEDOR.ESTADO, dbo.PROVEEDOR.DIASVENCIMIENTO, " + " dbo.CATEGORIAPROVEEDOR.DESCATEGORIAPROVEEDOR, dbo.CENTROCOSTO.DESCENTRO, dbo.MONEDA.DESMONEDA," + " (select DESZONA from ZONA where ZONA.CODZONA=PROVEEDOR.CODZONA) as DESZONA,(select DESCIUDAD from CIUDAD where CIUDAD.CODCIUDAD=PROVEEDOR.CODCIUDAD) as DESCIUDAD,(select DESPAIS from PAIS where PAIS.CODPAIS=PROVEEDOR.CODPAIS) as DESPAIS" + " FROM dbo.PROVEEDOR LEFT OUTER JOIN" + " dbo.CENTROCOSTO ON dbo.PROVEEDOR.CODCENTRO = dbo.CENTROCOSTO.CODCENTRO LEFT OUTER JOIN" + " dbo.MONEDA ON dbo.PROVEEDOR.CODMONEDA = dbo.MONEDA.CODMONEDA LEFT OUTER JOIN" + " dbo.CATEGORIAPROVEEDOR ON dbo.PROVEEDOR.CODCATEGORIAPROVEEDOR = dbo.CATEGORIAPROVEEDOR.CODCATEGORIAPROVEEDOR"; 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 PROVEEDOR"; cmd.CommandType = CommandType.Text; int count = (int)cmd.ExecuteScalar(); conn.Close(); int value = 0; Dispatcher.BeginInvoke((Action)(() => progSupplier.Maximum = count)); Dispatcher.BeginInvoke((Action)(() => progSupplier.Value = value)); Dispatcher.BeginInvoke((Action)(() => supplierMaximum.Text = count.ToString())); Dispatcher.BeginInvoke((Action)(() => supplierValue.Text = value.ToString())); cmd = new SqlCommand(sql, conn); conn.Open(); cmd.CommandType = CommandType.Text; // SqlDataReader reader = cmd.ExecuteReader(); DataTable dt_supplier = exeDT(sql); foreach (DataRow reader in dt_supplier.Rows) { using (entity.db db = new entity.db()) { db.Configuration.AutoDetectChangesEnabled = false; contact contacts = new contact(); contacts.id_company = id_company; if (!(reader[1] is DBNull)) { contacts.name = reader[1].ToString(); } else { continue; } if (!(reader[0] is DBNull)) { string str = reader[0].ToString(); contacts.code = str; } else { contacts.code = "0"; } contacts.gov_code = ((reader[2] is DBNull) || reader[2].ToString() == string.Empty) ? "xxx" : reader[2].ToString(); contacts.is_active = true; contacts.is_customer = false; contacts.is_supplier = true; contacts.is_employee = false; contacts.address = (reader[3] is DBNull) ? null : reader[3].ToString(); contacts.telephone = (reader[4] is DBNull) ? null : reader[4].ToString(); contacts.email = (reader[5] is DBNull) ? null : reader[5].ToString(); int _dias = Convert.ToInt32((reader["DIASVENCIMIENTO"] is DBNull) ? 0 : reader["DIASVENCIMIENTO"]); string contrat_name = _dias + " " + "Días"; if (db.app_contract.Where(x => x.name == contrat_name).FirstOrDefault() != null) { app_contract app_contract = db.app_contract.Where(x => x.name == contrat_name).FirstOrDefault(); contacts.id_contract = app_contract.id_contract; contacts.app_contract = app_contract; } //db Related Insertion. if (!(reader[22] is DBNull)) { string CdC = reader[22].ToString(); app_cost_center app_cost_center = db.app_cost_center.Where(x => x.name == CdC && x.id_company == id_company).FirstOrDefault(); contacts.id_cost_center = app_cost_center.id_cost_center; } contacts.id_contact_role = db.contact_role.Where(x => x.is_principal == true && x.id_company == id_company).FirstOrDefault().id_contact_role; if (!(reader[23] is DBNull)) { string fx = reader[23].ToString(); app_currency app_currency = db.app_currency.Where(x => x.name == fx && x.id_company == id_company).FirstOrDefault(); contacts.id_currency = (int)app_currency.id_currency; } if (!(reader["DESZONA"] is DBNull)) { string name = (string)reader["DESZONA"]; app_geography _app_geography = db.app_geography.Where(x => x.name == name).FirstOrDefault(); if (_app_geography != null) { contacts.app_geography = _app_geography; contacts.id_geography = _app_geography.id_geography; } } else if (!(reader["DESCIUDAD"] is DBNull)) { string name = (string)reader["DESCIUDAD"]; app_geography _app_geography = db.app_geography.Where(x => x.name == name).FirstOrDefault(); if (_app_geography != null) { contacts.app_geography = _app_geography; contacts.id_geography = _app_geography.id_geography; } } else if (!(reader["DESPAIS"] is DBNull)) { string name = (string)reader["DESPAIS"]; app_geography _app_geography = db.app_geography.Where(x => x.name == name).FirstOrDefault(); if (_app_geography != null) { contacts.app_geography = _app_geography; contacts.id_geography = _app_geography.id_geography; } } if (contacts.Error == null) { try { db.contacts.Add(contacts); db.SaveChanges(); value += 1; Dispatcher.BeginInvoke((Action)(() => progSupplier.Value = value)); Dispatcher.BeginInvoke((Action)(() => supplierValue.Text = value.ToString())); } catch { throw; } } //db.Dispose(); } } //cmd.Dispose(); conn.Close(); _supplier_Current = _supplier_Max; }