Ejemplo n.º 1
0
        private void Page_Loaded(object sender, RoutedEventArgs e)
        {
            security_user_view_source = ((CollectionViewSource)(this.FindResource("security_userViewSource")));
            dbContext.security_user.Where(a => a.is_active == true && a.id_company == _entity.company_ID).OrderBy(a => a.name).Load();
            security_user_view_source.Source = dbContext.security_user.Local;

            security_ques_view_source = ((CollectionViewSource)(this.FindResource("securityQuesViewSource")));
            dbContext.security_question.Load();
            security_ques_view_source.Source = dbContext.security_question.Local;

            security_role_view_source = ((CollectionViewSource)(this.FindResource("securityRoleViewSource")));
            dbContext.security_role.Where(a => a.is_active == true && a.id_company == _entity.company_ID).OrderBy(a => a.name).Load();
            security_role_view_source.Source = dbContext.security_role.Local;

            if (!dbContext.security_user.Where(x => x.name == "master").Any())
            {
                security_user security_user = new security_user();
                security_user.State      = EntityState.Added;
                security_user.IsSelected = true;
                if (dbContext.security_role.Where(x => x.is_master).FirstOrDefault() != null)
                {
                    security_user.security_role = dbContext.security_role.Where(x => x.is_master).FirstOrDefault();
                }

                security_user.name = "master";
                dbContext.security_user.Add(security_user);
                security_user_view_source.View.MoveCurrentToLast();
            }
        }
Ejemplo n.º 2
0
        private void btnApprove_Click(object sender, RoutedEventArgs e)
        {
            item_request item_request = item_requestViewSource.View.CurrentItem as item_request;

            //Search User.
            security_user security_user = new security_user();

            //Load User Name and Department.
            if (ItemDB.security_user.Where(x => x.id_user == CurrentSession.Id_User).FirstOrDefault() != null)
            {
                security_user              = ItemDB.security_user.Where(x => x.id_user == CurrentSession.Id_User).FirstOrDefault();
                item_request.request_user  = security_user;
                item_request.security_user = security_user;
                item_request.id_department = security_user.security_role.id_department;
            }

            //Get Branch.
            if (ItemDB.app_branch.Where(x => x.id_branch == CurrentSession.Id_Branch).FirstOrDefault() != null)
            {
                item_request.id_branch = ItemDB.app_branch.Where(x => x.id_branch == CurrentSession.Id_Branch).FirstOrDefault().id_branch;
            }

            item_request.name = security_user.name + " Request";

            ItemDB.SaveChanges();

            //Creates a new Request
            item_request item_request_New = new item_request();

            ItemDB.item_request.Add(item_request_New);
            item_requestViewSource.View.MoveCurrentTo(item_request_New);
        }
Ejemplo n.º 3
0
 private void toolBar_btnSearch_Click(object sender, string query)
 {
     try
     {
         if (!string.IsNullOrEmpty(query))
         {
             security_user_view_source.View.Filter = i =>
             {
                 security_user security_user = i as security_user;
                 if (security_user.name.ToLower().Contains(query.ToLower()))
                 {
                     return(true);
                 }
                 else
                 {
                     return(false);
                 }
             };
         }
         else
         {
             security_user_view_source.View.Filter = null;
         }
     }
     catch (Exception ex)
     {
         toolBar.msgWarning(ex.Message);
     }
 }
Ejemplo n.º 4
0
        private void sync_Users()
        {
            try
            {
                security_role security_role = new security_role();
                security_role.is_active  = true;
                security_role.name       = "Administrador";
                security_role.id_company = id_company;
                dbContext.security_role.Add(security_role);
                dbContext.SaveChanges();
                DataTable dt = exeDT("SELECT * FROM USUARIO");
                foreach (DataRow row in dt.Rows)
                {
                    security_user security_user = new security_user();
                    if (row["DESUSUARIO"].ToString() != "")
                    {
                        security_user.name = row["DESUSUARIO"].ToString();
                    }
                    else
                    {
                        security_user.name = "name";
                    }
                    if (row["PASSUSUARIO"].ToString() != "")
                    {
                        security_user.password = row["PASSUSUARIO"].ToString();
                    }
                    else
                    {
                        security_user.password = "******";
                    }
                    if (row["NOMBRE"].ToString() != "")
                    {
                        security_user.name_full = row["NOMBRE"].ToString();
                    }
                    else
                    {
                        security_user.name_full = "name";
                    }
                    security_user.id_company    = id_company;
                    security_user.is_active     = true;
                    security_user.id_role       = security_role.id_role;
                    security_user.security_role = security_role;

                    dbContext.security_user.Add(security_user);
                }
                dt.Clear();

                IEnumerable <DbEntityValidationResult> validationresult = dbContext.GetValidationErrors();
                if (validationresult.Count() == 0)
                {
                    dbContext.SaveChanges();
                }
            }
            catch
            {
                throw;
            }
        }
Ejemplo n.º 5
0
        private void toolBar_btnNew_Click(object sender)
        {
            // SetIsEnable = true;
            security_user security_user = new security_user();

            security_user.State      = EntityState.Added;
            security_user.IsSelected = true;
            security_user.id_company = CurrentSession.Id_Company;
            if (CurrentSession.User != null)
            {
                security_user.id_created_user = CurrentSession.Id_User;
            }

            dbContext.security_user.Add(security_user);
            security_user_view_source.View.MoveCurrentToLast();
        }
Ejemplo n.º 6
0
 public static security_curd getUserSecurityValues(int UserId, App.Names Application)
 {
     using (db db = new db())
     {
         security_user security_user = db.security_user.Where(x => x.id_user == UserId).FirstOrDefault();
         if (security_user != null)
         {
             int id_role = security_user.id_role;
             return(db.security_curd.Where(x => x.id_role == id_role && x.id_application == Application).FirstOrDefault());
         }
         else
         {
             return(null);
         }
     }
 }
Ejemplo n.º 7
0
        private void toolBar_btnEdit_Click(object sender)
        {
            //// SetIsEnable = true;
            //security_user objsecuser =(security_user)security_user_view_source.View.CurrentItem;
            //objsecuser.State = System.Data.Entity.EntityState.Modified;

            if (security_userDataGrid.SelectedItem != null)
            {
                security_user security_user = (security_user)security_userDataGrid.SelectedItem;
                security_user.IsSelected             = true;
                security_user.State                  = EntityState.Modified;
                dbContext.Entry(security_user).State = EntityState.Modified;
            }
            else
            {
                toolBar.msgWarning("Please Select a Record");
            }
        }
Ejemplo n.º 8
0
        private void toolBar_btnSave_Click(object sender)
        {
            security_user security_user = security_user_view_source.View.CurrentItem as security_user;

            if (dbContext.security_user.Where(x => x.name == security_user.name).Any() && security_user.State == EntityState.Added)
            {
                toolBar.msgWarning("User Already Exists...");
            }
            else
            {
                if (dbContext.SaveChanges() > 0)
                {
                    toolBar.msgSaved(1);

                    if (CurrentSession.Id_User == 0)
                    {
                        CurrentSession.Id_User = security_user.id_user;
                    }

                    security_user_view_source.View.Refresh();
                }
            }
        }
Ejemplo n.º 9
0
        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"); }
        }
Ejemplo n.º 10
0
        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);
        }
Ejemplo n.º 11
0
        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);
        }
Ejemplo n.º 12
0
        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);
        }