private void btnCreate_Click(object sender, RoutedEventArgs e) { crud_modal.Visibility = Visibility.Visible; cntrl.company objCompany = new cntrl.company(); UserCurdConditions(ref objCompany); objCompany.EnterMode = cntrl.company.Mode.Add; app_company app_company = new app_company(); entity.db.app_company.Add(app_company); app_companyViewSource.View.MoveCurrentToLast(); objCompany.app_companyViewSource = app_companyViewSource; objCompany.objEntity = entity; crud_modal.Children.Add(objCompany); }
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_company _app_company = app_companyViewSource.View.CurrentItem as entity.app_company; _app_company.is_active = false; btnSave_Click(sender, e); } } catch (Exception ex) { throw ex; } }
public bool VersionEncrypt(CurrentSession.Versions Version) { try { using (db db = new db()) { string _Seats = Version.ToString(); string _Passkey = "^%*@$^$"; string hash = StringCipher.Encrypt(_Seats, _Passkey); app_company app_company = db.app_company.Where(x => x.id_company == CurrentSession.Id_Company).FirstOrDefault(); app_company.seats = hash; db.SaveChanges(); } return(true); } catch { return(false); } }
private void check_createdb() { using (var db = new db()) { bool db_exists = db.Database.Exists(); if (!db_exists) { Dispatcher.BeginInvoke((Action)(() => { myFrame.Navigate(new StartUp()); })); } else { string company_Alias = string.Empty; app_company app_company = db.app_company.Where(x => x.id_company == entity.CurrentSession.Id_Company).FirstOrDefault(); if (app_company != null) { if (!string.IsNullOrEmpty(app_company.alias)) { company_Alias = app_company.alias; } else { company_Alias = app_company.name; } } entity.Properties.Settings Settings = new entity.Properties.Settings(); Settings.company_Name = company_Alias; Dispatcher.BeginInvoke((Action)(() => { Settings.Save(); })); } } }
public void ZReport(app_account_session app_account_session) { string Header = string.Empty; string Detail = string.Empty; string Footer = string.Empty; string CompanyName = string.Empty; string BranchName = string.Empty; app_company app_company = null; if (app_account_session.app_company != null) { CompanyName = app_account_session.app_company.name; app_company = app_account_session.app_company; } else { using (db db = new db()) { if (db.app_company.Where(x => x.id_company == app_account_session.id_company).FirstOrDefault() != null) { app_company = db.app_company.Where(x => x.id_company == app_account_session.id_company).FirstOrDefault(); CompanyName = app_company.name; } } } string UserName = ""; if (app_account_session.security_user != null) { UserName = app_account_session.security_user.name; } else { using (db db = new db()) { if (db.security_user.Where(x => x.id_user == app_account_session.id_user).FirstOrDefault() != null) { security_user security_user = db.security_user.Where(x => x.id_user == app_account_session.id_user).FirstOrDefault(); UserName = security_user.name; } } } using (db db = new db()) { if (db.app_branch.Where(x => x.id_branch == CurrentSession.Id_Branch).FirstOrDefault() != null) { app_branch app_branch = db.app_branch.Where(x => x.id_branch == CurrentSession.Id_Branch).FirstOrDefault(); BranchName = app_branch.name; } } string SessionID = app_account_session.id_session.ToString(); DateTime OpenDate = app_account_session.op_date; DateTime CloseDate = DateTime.Now; if (app_account_session.cl_date != null) { CloseDate = (DateTime)app_account_session.cl_date; } Header = "***Z Report***" + "\n" + CompanyName + "\t" + BranchName + "\n" + "R.U.C. :" + app_company.gov_code + "\n" + app_company.address + "\n" + "***" + app_company.alias + "***" + "\n" + "Apertura : " + OpenDate + "\n" + "Cierre : " + CloseDate + "\n" + "--------------------------------" + "\n" + "Hora Factura / Valor Moneda" + "\n" + "--------------------------------" + "\n"; string CustomerName = string.Empty; foreach (app_account_detail detail in app_account_session.app_account_detail.GroupBy(x => x.id_currencyfx).Select(x => x.FirstOrDefault()).ToList()) { Detail += "Moneda : " + detail.app_currencyfx.app_currency.name + "\n"; if (detail.tran_type == app_account_detail.tran_types.Open) { Detail += "Balance de Apertura : " + Math.Round(detail.credit, 2) + "\n"; } foreach (app_account_detail d in app_account_session.app_account_detail.Where(x => x.tran_type == app_account_detail.tran_types.Transaction && x.id_currencyfx == detail.id_currencyfx).ToList()) { string AccountName = string.Empty; if (d.app_account == null) { using (db db = new db()) { app_account app_account = db.app_account.Where(x => x.id_account == d.id_account).FirstOrDefault(); AccountName = app_account.name; } } string currency = string.Empty; if (d.app_currencyfx == null) { using (db db = new db()) { currency = db.app_currencyfx.Where(x => x.id_currencyfx == d.id_currencyfx).FirstOrDefault().app_currency.name; } } string InvoiceNumber = string.Empty; string InvoiceTime = string.Empty; payment_detail payment_detail = d.payment_detail as payment_detail; foreach (payment_schedual payment_schedual in payment_detail.payment_schedual) { if (payment_schedual.sales_invoice.number != null) { if (!(InvoiceNumber.Contains(payment_schedual.sales_invoice.number))) { InvoiceNumber += payment_schedual.sales_invoice.number; InvoiceTime = payment_schedual.sales_invoice.trans_date.ToShortTimeString(); } } } decimal?value = d.credit - d.debit; } var listvat = app_account_session.app_account_detail.Where(x => x.tran_type == app_account_detail.tran_types.Transaction && x.id_currencyfx == detail.id_currencyfx) .GroupBy(a => new { a.id_payment_type, a.id_currencyfx }) .Select(g => new { Currencyname = g.Max(x => x.app_currencyfx).app_currency.name, paymentname = g.Max(x => x.payment_type).name, id_currencyfx = g.Key.id_currencyfx, id_payment_type = g.Key.id_payment_type, value = g.Sum(a => a.credit) }).ToList().OrderBy(x => x.id_currencyfx); Detail += "Total de Ventas Neto :" + Math.Round(listvat.Sum(x => x.value), 2) + "\n"; foreach (dynamic item in listvat) { Detail += item.paymentname + "\t" + Math.Round(item.value, 2) + "\n"; } foreach (app_account_detail account_detail in app_account_session.app_account_detail.Where(x => x.tran_type == app_account_detail.tran_types.Close && x.id_currencyfx == detail.id_currencyfx).GroupBy(x => x.id_currencyfx).Select(x => x.FirstOrDefault()).ToList()) { Detail += "Balance de Cierre : " + Math.Round(account_detail.debit, 2); Detail += "\n--------------------------------" + "\n"; } Detail += "\n--------------------------------" + "\n"; } using (db db = new db()) { decimal amount = 0M; int[] id_schedual = new int[10]; int index = 0; foreach (app_account_detail account_detail in db.app_account_detail.Where(x => x.id_session == app_account_session.id_session && x.tran_type == app_account_detail.tran_types.Transaction).ToList()) { foreach (payment_schedual payment_schedual in account_detail.payment_detail.payment_schedual.ToList()) { if (!id_schedual.Contains(payment_schedual.parent.id_payment_schedual)) { if (payment_schedual.parent != null) { id_schedual[index] = payment_schedual.parent.id_payment_schedual; amount += payment_schedual.parent.debit; } else { amount += payment_schedual.credit; } } } } Detail += "Total de Ventas Neto : " + Math.Round(amount, 2) + " \n"; } Footer += "Cajero/a : " + UserName + " /n"; Footer += "--------------------------------" + " \n"; string Text = Header + Detail + Footer; Reciept Reciept = new Reciept(); PrintDialog pd = new PrintDialog(); FlowDocument document = new FlowDocument(new Paragraph(new Run(Text))); document.Name = "ItemMovement"; document.FontFamily = new FontFamily("Courier New"); document.FontSize = 11.0; document.FontStretch = FontStretches.Normal; document.FontWeight = FontWeights.Normal; document.PagePadding = new Thickness(20); document.PageHeight = double.NaN; document.PageWidth = double.NaN; //document. //Specify minimum page sizes. Origintally 283, but was too small. document.MinPageWidth = 283; //Specify maximum page sizes. document.MaxPageWidth = 300; IDocumentPaginatorSource idpSource = document; try { Nullable <bool> print = pd.ShowDialog(); if (print == true) { pd.PrintDocument(idpSource.DocumentPaginator, Text); } } catch { MessageBox.Show("Output (Reciept Printer) not Found Error", "Error 101"); } }
public string Payment(payment payment) { string Header = string.Empty; string Detail = string.Empty; string Footer = string.Empty; string CompanyName = string.Empty; app_company app_company = null; if (payment.app_company != null) { CompanyName = payment.app_company.name; app_company = payment.app_company; } else { using (db db = new db()) { if (db.app_company.Where(x => x.id_company == payment.id_company).FirstOrDefault() != null) { app_company = db.app_company.Where(x => x.id_company == payment.id_company).FirstOrDefault(); CompanyName = app_company.name; } } } string UserName = ""; if (payment.security_user != null) { UserName = payment.security_user.name; } else { using (db db = new db()) { if (db.security_user.Where(x => x.id_user == payment.id_user).FirstOrDefault() != null) { security_user security_user = db.security_user.Where(x => x.id_user == payment.id_user).FirstOrDefault(); UserName = security_user.name; } } } string TransNumber = payment.number; DateTime TransDate = payment.trans_date; Header = CompanyName + "\n" + "R.U.C. :" + app_company.gov_code + "\n" + app_company.address + "\n" + "***" + app_company.alias + "***" + "\n" + "Timbrado : " + payment.app_document_range.code + " Vto: " + payment.app_document_range.expire_date + "Fecha : " + payment.trans_date + "\n" + "--------------------------------" + "Cuenta, Valor, Moneda" + "\n" + "--------------------------------" + "\n" + "\n"; string InvoiceNumber = string.Empty; string CustomerName = string.Empty; foreach (payment_detail d in payment.payment_detail) { string AccountName = string.Empty; if (d.app_account == null) { using (db db = new db()) { app_account app_account = db.app_account.Where(x => x.id_account == d.id_account).FirstOrDefault(); AccountName = app_account.name; } } string currency = string.Empty; if (d.app_currencyfx == null) { using (db db = new db()) { currency = db.app_currencyfx.Where(x => x.id_currencyfx == d.id_currencyfx).FirstOrDefault().app_currency.name; } } decimal?value = d.value; Detail = Detail + AccountName + "\n" + value.ToString() + "\t" + currency + "\n"; if (InvoiceNumber == string.Empty) { InvoiceNumber = d.payment_schedual.FirstOrDefault().sales_invoice.number; CustomerName = d.payment_schedual.FirstOrDefault().contact.name; } } Footer += "Factura : " + InvoiceNumber + "\n"; Footer += "--------------------------------" + "\n"; string Text = Header + Detail + Footer; return(Text); }
public string SalesInvoice(sales_invoice sales_invoice) { string Header = string.Empty; string Detail = string.Empty; string Footer = string.Empty; string BranchName = string.Empty; string TerminalName = string.Empty; app_company app_company = null; if (sales_invoice.app_company != null) { app_company = sales_invoice.app_company; } else { using (db db = new db()) { if (db.app_company.Where(x => x.id_company == sales_invoice.id_company).FirstOrDefault() != null) { app_company = db.app_company.Where(x => x.id_company == sales_invoice.id_company).FirstOrDefault(); } } } if (sales_invoice.app_branch != null) { BranchName = sales_invoice.app_branch.name; } else { using (db db = new db()) { app_branch app_branch = db.app_branch.Where(x => x.id_branch == sales_invoice.id_branch).FirstOrDefault(); if (app_branch != null) { BranchName = app_branch.name; } } } string UserGiven = ""; if (sales_invoice.security_user != null) { UserGiven = sales_invoice.security_user.name; } else { using (db db = new db()) { security_user security_user = db.security_user.Where(x => x.id_user == sales_invoice.id_user).FirstOrDefault(); if (security_user != null) { UserGiven = security_user.name; } } } string ContractName = ""; if (sales_invoice.app_contract != null) { ContractName = sales_invoice.app_contract.name; } else { using (db db = new db()) { app_contract app_contract = db.app_contract.Where(x => x.id_contract == sales_invoice.id_contract).FirstOrDefault(); if (app_contract != null) { ContractName = app_contract.name; } } } string ConditionName = ""; if (sales_invoice.app_condition != null) { ConditionName = sales_invoice.app_condition.name; } else { using (db db = new db()) { app_condition app_condition = db.app_condition.Where(x => x.id_condition == sales_invoice.id_condition).FirstOrDefault(); if (app_condition != null) { ConditionName = app_condition.name; } } } string CurrencyName = ""; if (sales_invoice.app_currencyfx != null) { if (sales_invoice.app_currencyfx.app_currency != null) { CurrencyName = sales_invoice.app_currencyfx.app_currency.name; } } else { using (db db = new db()) { app_currencyfx app_currencyfx = db.app_currencyfx.Where(x => x.id_currencyfx == sales_invoice.id_currencyfx).FirstOrDefault(); if (app_currencyfx != null) { CurrencyName = app_currencyfx.app_currency.name; } } } string TransNumber = sales_invoice.number; DateTime TransDate = sales_invoice.trans_date; Header = app_company.name + "\n" + "RUC:" + app_company.gov_code + "\n" + app_company.address + "\n" + "***" + app_company.alias + "***" + "\n" + "Timbrado : " + sales_invoice.app_document_range.code + "\n" + "Vencimiento : " + sales_invoice.app_document_range.expire_date + "\n" + "--------------------------------" + "Descripcion, Cantiad, Precio" + "\n" + "--------------------------------" + "\n" + "\n"; foreach (sales_invoice_detail d in sales_invoice.sales_invoice_detail) { string ItemName = d.item.name; string ItemCode = d.item.code; decimal?Qty = d.quantity; string TaskName = d.item_description; Detail = Detail + ItemName + "\n" + Qty.ToString() + "\t" + ItemCode + "\t" + Math.Round((d.UnitPrice_Vat + d.DiscountVat), 2) + "\n"; } decimal DiscountTotal = sales_invoice.sales_invoice_detail.Sum(x => x.Discount_SubTotal_Vat); Footer = "--------------------------------" + "\n"; Footer += "Total Bruto : " + Math.Round((sales_invoice.GrandTotal + DiscountTotal), 2) + "\n"; Footer += "Total Descuento : -" + Math.Round(sales_invoice.sales_invoice_detail.Sum(x => x.Discount_SubTotal_Vat), 2) + "\n"; Footer += "Total " + CurrencyName + " : " + Math.Round(sales_invoice.GrandTotal, 2) + "\n"; Footer += "Fecha & Hora : " + sales_invoice.trans_date + "\n"; Footer += "Numero de Factura : " + sales_invoice.number + "\n"; Footer += "-------------------------------" + "\n"; if (sales_invoice != null) { List <sales_invoice_detail> sales_invoice_detail = sales_invoice.sales_invoice_detail.ToList(); if (sales_invoice_detail.Count > 0) { using (db db = new db()) { var listvat = sales_invoice_detail .Join(db.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_price * 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 { vatname = g.Key.ad.app_vat_group.name, id_vat = g.Key.id_vat, name = g.Key.name, value = g.Sum(a => a.value * a.ad.quantity) }).ToList(); var VAtList = listvat.GroupBy(x => x.id_vat).Select(g => new { vatname = g.Max(y => y.vatname), id_vat = g.Max(y => y.id_vat), name = g.Max(y => y.name), value = g.Sum(a => a.value) }).ToList(); foreach (dynamic item in VAtList) { Footer += item.vatname + " : " + Math.Round(item.value, 2) + "\n"; } Footer += "Total IVA : " + CurrencyName + " " + Math.Round(VAtList.Sum(x => x.value), 2) + "\n"; } } } Footer += "-------------------------------"; Footer += "Cliente : " + sales_invoice.contact.name + "\n"; Footer += "Documento : " + sales_invoice.contact.gov_code + "\n"; Footer += "Condicion : " + ConditionName + "\n"; Footer += "-------------------------------"; Footer += "Sucursal : " + BranchName + "\n"; Footer += "Terminal : " + TerminalName; if (sales_invoice.id_sales_rep > 0) { string SalesRep_Name = ""; if (sales_invoice.sales_rep == null) { using (db db = new db()) { SalesRep_Name = db.sales_rep.Where(x => x.id_sales_rep == (int)sales_invoice.id_sales_rep).FirstOrDefault().name; } } else { SalesRep_Name = sales_invoice.sales_rep.name; } Footer += "\n"; Footer += "Vendedor/a : " + SalesRep_Name; } Footer += "\n"; Footer += "Cajero/a : " + UserGiven; string Text = Header + Detail + Footer; return(Text); }
public string SalesReturn(sales_return sales_return) { string Header = string.Empty; string Detail = string.Empty; string Footer = string.Empty; string CompanyName = string.Empty; app_company app_company = null; if (sales_return.app_company != null) { CompanyName = sales_return.app_company.name; } else { using (db db = new db()) { if (db.app_company.Where(x => x.id_company == sales_return.id_company).FirstOrDefault() != null) { app_company = db.app_company.Where(x => x.id_company == sales_return.id_company).FirstOrDefault(); CompanyName = app_company.name; } } } string UserGiven = ""; if (sales_return.security_user != null) { UserGiven = sales_return.security_user.name; } else { using (db db = new db()) { if (db.security_user.Where(x => x.id_user == sales_return.id_user).FirstOrDefault() != null) { security_user security_user = db.security_user.Where(x => x.id_user == sales_return.id_user).FirstOrDefault(); UserGiven = security_user.name; } } } string TransNumber = sales_return.number; DateTime TransDate = sales_return.trans_date; string BranchName = sales_return.app_branch.name; Header = CompanyName + "\n" + "RUC:" + app_company.gov_code + "\n" + app_company.address + "\n" + "***" + app_company.alias + "***" + "\n" + "Timbrado: " + sales_return.app_document_range.code + " Vto: " + sales_return.app_document_range.expire_date + "\n" + "--------------------------------" + "Descripcion, Cantiad, Precio" + "\n" + "--------------------------------" + "\n" + "\n"; foreach (sales_return_detail d in sales_return.sales_return_detail) { string ItemName = d.item.name; string ItemCode = d.item.code; decimal?Qty = d.quantity; string TaskName = d.item_description; decimal?UnitPrice_Vat = Math.Round(d.UnitPrice_Vat, 2); Detail = Detail + ItemName + "\n" + Qty.ToString() + "\t" + ItemCode + "\t" + UnitPrice_Vat + "\n"; } Footer = "--------------------------------" + "\n"; Footer += "Total " + sales_return.app_currencyfx.app_currency.name + ": " + sales_return.GrandTotal + "\n"; Footer += "Fecha & Hora: " + sales_return.trans_date + "\n"; Footer += "Numero de Factura: " + sales_return.number + "\n"; Footer += "-------------------------------" + "\n"; if (sales_return != null) { List <sales_return_detail> sales_return_detail = sales_return.sales_return_detail.ToList(); if (sales_return_detail.Count > 0) { using (db db = new db()) { var listvat = sales_return_detail .Join(db.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_price * 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 { vatname = g.Key.ad.app_vat_group.name, id_vat = g.Key.id_vat, name = g.Key.name, value = g.Sum(a => a.value * a.ad.quantity) }).ToList(); var VAtList = listvat.GroupBy(x => x.id_vat).Select(g => new { vatname = g.Max(y => y.vatname), id_vat = g.Max(y => y.id_vat), name = g.Max(y => y.name), value = g.Sum(a => a.value) }).ToList(); foreach (dynamic item in VAtList) { Footer += item.vatname + " : " + Math.Round(item.value, 2) + "\n"; } Footer += "Total IVA: " + sales_return.app_currencyfx.app_currency.name + " " + Math.Round(VAtList.Sum(x => x.value), 2) + "\n"; } } } Footer += "-------------------------------"; Footer += "Cliente : " + sales_return.contact.name + "\n"; Footer += "Documento : " + sales_return.contact.gov_code + "\n"; Footer += "Condicion : " + sales_return.app_condition.name + "\n"; Footer += "-------------------------------"; Footer += "Sucursal : " + sales_return.app_branch.name + " Terminal: " + sales_return.app_terminal.name + "\n"; Footer += "Cajero/a : " + UserGiven; string Text = Header + Detail + Footer; return(Text); }
private void sync_Company() { DataTable dt = exeDT("SELECT * FROM EMPRESA"); DataTable dt_Branch = exeDT("SELECT * FROM SUCURSAL"); DataTable dt_Terminal = exeDT("SELECT * FROM PC"); foreach (DataRow row in dt.Rows) { app_company _app_company = new app_company(); _app_company.name = row["NOMCONTRIBUYENTE"].ToString(); _app_company.alias = row["NOMFANTASIA"].ToString(); if (_app_company.name != null && _app_company.alias != null) { _app_company.name = _app_company.alias; } else { continue; } _app_company.address = (row["DIRECCION"].ToString() == "") ? "Address Placeholder" : row["DIRECCION"].ToString(); _app_company.gov_code = (row["RUCCONTRIBUYENTE"].ToString() == "") ? "GovID Placeholder" : row["RUCCONTRIBUYENTE"].ToString(); dbContext.app_company.Add(_app_company); dbContext.SaveChanges(); id_company = _app_company.id_company; CurrentSession.Id_Company = id_company; Dispatcher.BeginInvoke((Action)(() => { entity.Properties.Settings.Default.company_ID = id_company; entity.Properties.Settings.Default.Save(); } )); sync_Users(); id_user = dbContext.security_user.Where(i => i.id_company == id_company).FirstOrDefault().id_user; CurrentSession.Id_User = id_company; foreach (DataRow row_Branch in dt_Branch.Rows) { app_branch _app_branch = new app_branch(); _app_branch.id_company = id_company; _app_branch.name = row_Branch["DESSUCURSAL"].ToString(); _app_branch.code = row_Branch["SUCURSALTIMBRADO"].ToString(); _app_branch.can_invoice = (row_Branch["TIPOSUCURSAL"].ToString().Contains("Factura")) ? true : false; _app_branch.can_stock = (row_Branch["TIPOSUCURSAL"].ToString().Contains("Stock")) ? true : false; if (_app_branch.can_stock) { app_location app_location = new app_location(); app_location.is_active = true; app_location.is_default = true; app_location.name = "Deposito"; _app_branch.app_location.Add(app_location); } string id_branchString = row_Branch["CODSUCURSAL"].ToString(); foreach (DataRow row_Terminal in dt_Terminal.Select("CODSUCURSAL = " + id_branchString)) { app_terminal app_terminal = new app_terminal(); app_terminal.is_active = true; app_terminal.code = row_Terminal["NUMMAQUINA"].ToString(); app_terminal.name = row_Terminal["NOMBRE"].ToString(); _app_branch.app_terminal.Add(app_terminal); } if (_app_branch.Error == null) { dbContext.app_branch.Add(_app_branch); dbContext.SaveChanges(); } } id_branch = dbContext.app_branch.Where(i => i.id_company == id_company).FirstOrDefault().id_branch; id_terminal = dbContext.app_terminal.Where(i => i.id_company == id_company).FirstOrDefault().id_terminal; Dispatcher.BeginInvoke((Action)(() => { entity.Properties.Settings.Default.branch_ID = id_branch; entity.Properties.Settings.Default.terminal_ID = id_terminal; entity.Properties.Settings.Default.Save(); } )); } dt.Clear(); dt_Branch.Clear(); dt_Terminal.Clear(); }