示例#1
0
        private void filetr_detail()
        {
            app_location   app_location   = app_branchapp_locationViewSource.View.CurrentItem as app_location;
            item_inventory item_inventory = item_inventoryViewSource.View.CurrentItem as item_inventory;

            if (app_location != null)
            {
                if (item_inventoryitem_inventory_detailViewSource != null)
                {
                    if (item_inventoryitem_inventory_detailViewSource.View != null)
                    {
                        item_inventoryitem_inventory_detailViewSource.View.Filter = i =>
                        {
                            item_inventory_detail item_inventory_detail = (item_inventory_detail)i;
                            if (item_inventory_detail.id_location == app_location.id_location && item_inventory_detail.id_inventory == item_inventory.id_inventory)
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        };
                    }
                }
            }

            TextBox_TextChanged(null, null);
        }
示例#2
0
文件: Stock.cs 项目: mercaditu/ERP
        public List <StockList> List(app_branch app_branch, app_location app_location, item_product item_product)
        {
            string query      = @"select 
                                parent.id_movement as MovementID, 
                                parent.trans_date as TransDate, 
                                parent.credit - if( sum(child.debit) > 0, sum(child.debit), 0 ) as QtyBalance, 
                                (select sum(unit_value) from item_movement_value as parent_val where id_movement = parent.id_movement) as Cost

                                from item_movement as parent
                                inner join app_location as loc on parent.id_location = loc.id_location
                                left join item_movement as child on child._parent_id_movement = parent.id_movement

                                where {0} and parent.id_item_product = {1} and parent.status = 2 and parent.debit = 0
                                group by parent.id_movement
                                order by parent.trans_date";
            string WhereQuery = "";

            //This determins if we should bring cost of entire block of
            if (app_location != null)
            {
                WhereQuery = String.Format("parent.id_location = {0}", app_location.id_location);
            }
            else
            {
                WhereQuery = String.Format("loc.id_branch = {0}", app_branch.id_branch);
            }

            query = String.Format(query, WhereQuery, item_product.id_item_product);
            DataTable dt = exeDT(query);

            return(GenerateList(dt));
        }
示例#3
0
        private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            app_location app_location = app_branchapp_locationViewSource.View.CurrentItem as app_location;

            if (app_location != null)
            {
                if (item_inventoryitem_inventory_detailViewSource != null)
                {
                    if (item_inventoryitem_inventory_detailViewSource.View != null)
                    {
                        item_inventoryitem_inventory_detailViewSource.View.Filter = i =>
                        {
                            item_inventory_detail item_inventory_detail = (item_inventory_detail)i;
                            if ((item_inventory_detail.item_product.item.name.ToUpper().Contains(txtsearch.Text.ToUpper()) ||
                                 item_inventory_detail.item_product.item.code.ToUpper().Contains(txtsearch.Text.ToUpper())) &&
                                app_location.id_location == item_inventory_detail.id_location)
                            {
                                return(true);
                            }
                            else
                            {
                                return(false);
                            }
                        };
                    }
                }
            }
        }
示例#4
0
        public app_location GenerateDefaultLocation(app_branch app_branch)
        {
            app_location app_location = new app_location();

            app_location.name       = "Default";
            app_location.id_branch  = app_branch.id_branch;
            app_location.is_default = true;
            app_branch.app_location.Add(app_location);
            return(app_location);
        }
示例#5
0
        private void btnNew_Click(object sender, RoutedEventArgs e)
        {
            crud_modal.Visibility = System.Windows.Visibility.Visible;
            cntrl.location objLocation  = new cntrl.location();
            app_location   app_location = new app_location();

            entity.db.app_location.Add(app_location);
            locationViewSource.View.MoveCurrentToLast();
            objLocation.app_locationViewSource = locationViewSource;
            objLocation._entity = entity;
            crud_modal.Children.Add(objLocation);
        }
示例#6
0
        private void BindItemMovement()
        {
            item_inventory item_inventory = null;
            app_location   app_location   = null;

            item_inventory = (item_inventory)item_inventoryViewSource.View.CurrentItem;
            app_location   = app_branchapp_locationViewSource.View.CurrentItem as app_location;

            if (app_location != null && item_inventory != null)
            {
                if (item_inventory.item_inventory_detail.Where(x => x.id_location == app_location.id_location).Count() == 0)
                {
                    if (app_location != null)
                    {
                        List <item_product>     item_productLIST = InventoryDB.item_product.Where(x => x.id_company == CurrentSession.Id_Company && x.item.is_active).ToList();
                        Class.StockCalculations Stock            = new Class.StockCalculations();
                        List <Class.StockList>  StockList        = Stock.ByBranchLocation(app_location.id_location, DateTime.Now);

                        foreach (item_product i in item_productLIST)
                        {
                            item_inventory_detail item_inventory_detail = new item_inventory_detail();
                            item_inventory_detail.State           = EntityState.Added;
                            item_inventory_detail.item_product    = i;
                            item_inventory_detail.id_item_product = i.id_item_product;

                            item_inventory_detail.app_location = app_location;
                            item_inventory_detail.id_location  = app_location.id_location;
                            item_inventory_detail.timestamp    = DateTime.Now;

                            if (StockList.Where(x => x.ProductID == i.id_item_product).FirstOrDefault() != null)
                            {
                                item_inventory_detail.value_system = StockList.Where(x => x.ProductID == i.id_item_product).FirstOrDefault().Quantity;
                                item_inventory_detail.unit_value   = StockList.Where(x => x.ProductID == i.id_item_product).FirstOrDefault().Cost;
                            }
                            else
                            {
                                item_inventory_detail.value_system = 0;
                            }

                            if (CurrencyID > 0)
                            {
                                item_inventory_detail.id_currencyfx = CurrencyID;
                            }

                            item_inventory.item_inventory_detail.Add(item_inventory_detail);
                        }
                    }
                }

                item_inventoryitem_inventory_detailViewSource.View.Refresh();
                filetr_detail();
            }
        }
示例#7
0
 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_location app_location = app_locationViewSource.View.CurrentItem as entity.app_location;
             app_location.is_active = false;
             btnSave_Click(sender, e);
         }
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
示例#8
0
 public int get_Location(item_product item_product, app_branch app_branch)
 {
     try
     {
         return(get_ProductLocation(item_product, app_branch));
     }
     catch
     {
         app_location app_location = new app_location();
         app_location.id_branch  = app_branch.id_branch;
         app_location.name       = "Default of " + app_branch.name;
         app_location.is_default = true;
         using (db db = new db())
         {
             db.app_location.Add(app_location);
             db.SaveChangesAsync();
             return(app_location.id_location);
         }
     }
 }
示例#9
0
文件: Sales.cs 项目: mercaditu/ERP
        public void sales()
        {
            string sql = " SELECT "
                         + " dbo.VENTAS.CODVENTA, dbo.VENTAS.NUMVENTA, dbo.VENTAS.FECHAVENTA, dbo.VENTAS.PORCENTAJEDESCUENTO,"
                         + " dbo.VENTAS.TOTALEXENTA, dbo.VENTAS.TOTALGRAVADA, dbo.VENTAS.TOTALIVA, dbo.VENTAS.TOTALDESCUENTO,"
                         + " dbo.VENTAS.MODALIDADPAGO, dbo.VENTAS.FECGRA, dbo.VENTAS.ESTADO, dbo.VENTAS.MOTIVOANULADO,"
                         + " dbo.VENTAS.FECHAANULADO, dbo.VENTAS.TIPOVENTA, dbo.VENTAS.TIPOPRECIO, dbo.VENTAS.NUMVENTATIMBRADO,"
                         + " dbo.VENTAS.TOTAL5, dbo.VENTAS.TOTAL10, dbo.VENTAS.CODPRESUPUESTO, dbo.VENTAS.METODO, dbo.VENTAS.ENVIADO,"
                         + " dbo.VENTAS.TOTALGRAVADO5, dbo.VENTAS.TOTALGRAVADO10, dbo.VENTAS.ASENTADO,"
                         + " dbo.VENTAS.TOTALVENTA, dbo.VENDEDOR.DESVENDEDOR, dbo.CLIENTES.NOMBRE, dbo.CLIENTES.RUC,"
                         + " dbo.SUCURSAL.DESSUCURSAL, dbo.VENTAS.COTIZACION1, FACTURACOBRAR_1.FECHAVCTO,"
                         + " dbo.FACTURACOBRAR.FECHAVCTO AS Expr1, dbo.FACTURACOBRAR.SALDOCUOTA, dbo.FACTURACOBRAR.IMPORTECUOTA, "
                         + " dbo.FACTURACOBRAR.COTIZACION, dbo.VENTASFORMACOBRO.IMPORTE, dbo.VENTASFORMACOBRO.DESTIPOCOBRO,"
                         + " dbo.VENTASFORMACOBRO.NUMDEVOLUCION, dbo.VENTASFORMACOBRO.TIPOCOBRO"
                         + " FROM  dbo.SUCURSAL RIGHT OUTER JOIN"
                         + " dbo.FACTURACOBRAR RIGHT OUTER JOIN"
                         + " dbo.VENTAS ON dbo.FACTURACOBRAR.CODVENTA = dbo.VENTAS.CODVENTA LEFT OUTER JOIN"
                         + " dbo.VENTASFORMACOBRO ON dbo.VENTAS.CODVENTA = dbo.VENTASFORMACOBRO.CODVENTA ON dbo.SUCURSAL.CODSUCURSAL = dbo.VENTAS.CODSUCURSAL"
                         + " LEFT OUTER JOIN dbo.VENDEDOR ON dbo.VENTAS.CODVENDEDOR = dbo.VENDEDOR.CODVENDEDOR LEFT OUTER JOIN"
                         + " dbo.CLIENTES ON dbo.VENTAS.CODCLIENTE = dbo.CLIENTES.CODCLIENTE LEFT OUTER JOIN"
                         + " dbo.FACTURACOBRAR AS FACTURACOBRAR_1 ON dbo.VENTAS.CODVENTA = FACTURACOBRAR_1.CODVENTA";

            SqlConnection conn = new SqlConnection(_connString);

            //Counts Total number of Rows we have to process
            SqlCommand cmd = new SqlCommand(sql, conn);

            conn.Open();
            cmd.CommandType = CommandType.Text;
            DataTable dt_sales = exeDT(sql);
            int       count    = (int)dt_sales.Rows.Count;

            conn.Close();

            int value = 0;

            Dispatcher.BeginInvoke((Action)(() => salesMaximum.Text = count.ToString()));
            Dispatcher.BeginInvoke((Action)(() => salesValue.Text = value.ToString()));
            Dispatcher.BeginInvoke((Action)(() => progSales.Maximum = count));
            Dispatcher.BeginInvoke((Action)(() => progSales.Value = value));

            //Sales Invoice Detail
            string sqlDetail = "SELECT"
                               + " dbo.PRODUCTOS.DESPRODUCTO,"           //0
                               + " dbo.VENTASDETALLE.CANTIDADVENTA,"     //1
                               + " dbo.VENTASDETALLE.PRECIOVENTANETO, "  //2
                               + " dbo.VENTASDETALLE.PRECIOVENTALISTA, " //3
                               + " dbo.VENTASDETALLE.COSTOPROMEDIO, "    //4
                               + " dbo.VENTASDETALLE.COSTOULTIMO, "      //5
                               + " dbo.VENTASDETALLE.IVA, "              //6
                               + " dbo.VENTAS.COTIZACION1, "             //7
                               + " dbo.MONEDA.DESMONEDA, "               //8
                               + " dbo.VENTASDETALLE.CODVENTA"
                               + " FROM dbo.VENTAS LEFT OUTER JOIN"
                               + " dbo.MONEDA ON dbo.VENTAS.CODMONEDA = dbo.MONEDA.CODMONEDA LEFT OUTER JOIN"
                               + " dbo.VENTASDETALLE ON dbo.VENTAS.CODVENTA = dbo.VENTASDETALLE.CODVENTA LEFT OUTER JOIN"
                               + " dbo.PRODUCTOS ON dbo.VENTASDETALLE.CODPRODUCTO = dbo.PRODUCTOS.CODPRODUCTO";

            DataTable dt_detail = exeDT(sqlDetail);

            int RoofValue  = 1000;
            int FloorValue = 0;

            //Run a Foreach Lap
            for (int i = FloorValue; i < RoofValue; i++)
            {
                using (SalesInvoiceDB db = new SalesInvoiceDB())
                {
                    db.Configuration.AutoDetectChangesEnabled = false;

                    List <entity.app_vat_group>  VATGroupList       = db.app_vat_group.Where(x => x.id_company == CurrentSession.Id_Company).ToList();
                    List <entity.contact>        ContactList        = db.contacts.Where(x => x.id_company == CurrentSession.Id_Company).ToList();
                    List <entity.sales_rep>      sales_repList      = db.sales_rep.Where(x => x.id_company == CurrentSession.Id_Company).ToList();
                    List <entity.app_branch>     BranchList         = db.app_branch.Where(x => x.id_company == CurrentSession.Id_Company).ToList();
                    List <entity.app_location>   LocationList       = db.app_location.Where(x => x.id_company == CurrentSession.Id_Company).ToList();
                    List <entity.app_terminal>   TerminalList       = db.app_terminal.Where(x => x.id_company == CurrentSession.Id_Company).ToList();
                    List <entity.item>           ItemList           = db.items.Where(x => x.id_company == CurrentSession.Id_Company).ToList();
                    List <entity.app_currencyfx> app_currencyfxList = db.app_currencyfx.Where(x => x.id_company == CurrentSession.Id_Company).ToList();

                    app_condition  app_conditionCrédito = db.app_condition.Where(x => x.name == "Crédito" && x.id_company == id_company).FirstOrDefault();
                    app_condition  app_conditionContado = db.app_condition.Where(x => x.name == "Contado" && x.id_company == id_company).FirstOrDefault();
                    app_currencyfx app_currencyfx       = null;
                    if (app_currencyfxList.Where(x => x.is_active).FirstOrDefault() != null)
                    {
                        app_currencyfx = app_currencyfxList.Where(x => x.is_active).FirstOrDefault();
                    }

                    app_vat_group app_vat_group10 = VATGroupList.Where(x => x.name.Contains("10")).FirstOrDefault();
                    app_vat_group app_vat_group5  = VATGroupList.Where(x => x.name.Contains("5")).FirstOrDefault();
                    app_vat_group app_vat_group0  = VATGroupList.Where(x => x.name.Contains("0")).FirstOrDefault();


                    foreach (DataRow InnerRow in dt_sales.Select("CODVENTA > " + FloorValue + " AND CODVENTA < " + RoofValue + ""))
                    {
                        sales_invoice sales_invoice = new entity.sales_invoice();
                        sales_invoice.State      = EntityState.Added;
                        sales_invoice.status     = Status.Documents_General.Pending;
                        sales_invoice.IsSelected = true;
                        sales_invoice.trans_type = Status.TransactionTypes.Normal;
                        sales_invoice.trans_date = DateTime.Now.AddDays(0);
                        sales_invoice.timestamp  = DateTime.Now;
                        sales_invoice.id_company = id_company;
                        sales_invoice.number     = (InnerRow["NUMVENTA"] is DBNull) ? null : InnerRow["NUMVENTA"].ToString();

                        sales_invoice.trans_date = (InnerRow["FECHAVENTA"] is DBNull) ? DateTime.Now :Convert.ToDateTime(InnerRow["FECHAVENTA"]);

                        //Customer
                        if (!(InnerRow["NOMBRE"] is DBNull))
                        {
                            string  _customer = InnerRow["NOMBRE"].ToString();
                            contact contact   = ContactList.Where(x => x.name == _customer && x.id_company == id_company).FirstOrDefault();

                            if (contact != null)
                            {
                                sales_invoice.id_contact = contact.id_contact;
                                sales_invoice.contact    = contact;
                            }
                        }

                        //Condition (Cash or Credit)
                        if (!(InnerRow["TIPOVENTA"] is DBNull) && Convert.ToByte(InnerRow["TIPOVENTA"]) == 0)
                        {
                            sales_invoice.id_condition = app_conditionContado.id_condition;
                            //Contract...

                            app_contract_detail app_contract_detail =
                                db.app_contract_detail.Where(x => x.id_company == id_company &&
                                                             x.app_contract.id_condition == app_conditionContado.id_condition)
                                .FirstOrDefault();

                            if (app_contract_detail != null)
                            {
                                sales_invoice.app_contract = app_contract_detail.app_contract;
                                sales_invoice.id_contract  = app_contract_detail.id_contract;
                            }
                            else
                            {
                                app_contract app_contract = GenerateDefaultContrat(app_conditionContado, 0);
                                db.app_contract.Add(app_contract);
                                sales_invoice.app_contract = app_contract;
                                sales_invoice.id_contract  = app_contract.id_contract;
                            }
                        }
                        else if (!(InnerRow["TIPOVENTA"] is DBNull) && Convert.ToByte(InnerRow["TIPOVENTA"]) == 1)
                        {
                            sales_invoice.id_condition = app_conditionCrédito.id_condition;

                            //Contract...
                            if (!(InnerRow["FECHAVCTO"] is DBNull))
                            {
                                DateTime _due_date = Convert.ToDateTime(InnerRow["FECHAVCTO"]);
                                int      interval  = (_due_date - sales_invoice.trans_date).Days;

                                app_contract_detail app_contract_detail =
                                    db.app_contract_detail.Where(x =>
                                                                 x.app_contract.id_condition == sales_invoice.id_condition &&
                                                                 x.app_contract.id_company == id_company &&
                                                                 x.interval == interval).FirstOrDefault();

                                if (app_contract_detail != null)
                                {
                                    sales_invoice.app_contract = app_contract_detail.app_contract;
                                    sales_invoice.id_contract  = app_contract_detail.id_contract;
                                }
                                else
                                {
                                    app_contract app_contract = GenerateDefaultContrat(app_conditionCrédito, interval);
                                    db.app_contract.Add(app_contract);
                                    sales_invoice.app_contract = app_contract;
                                    sales_invoice.id_contract  = app_contract.id_contract;
                                }
                            }
                            else
                            {
                                if (db.app_contract.Where(x => x.name == "0 Días").Count() == 0)
                                {
                                    app_contract app_contract = GenerateDefaultContrat(app_conditionCrédito, 0);
                                    db.app_contract.Add(app_contract);
                                    sales_invoice.app_contract = app_contract;
                                    sales_invoice.id_contract  = app_contract.id_contract;
                                }
                                else
                                {
                                    app_contract app_contract = db.app_contract.Where(x => x.name == "0 Días").FirstOrDefault();
                                    sales_invoice.app_contract = app_contract;
                                    sales_invoice.id_contract  = app_contract.id_contract;
                                }
                            }
                        }
                        else
                        {
                            sales_invoice.id_condition = app_conditionContado.id_condition;

                            if (db.app_contract.Where(x => x.name == "0 Días").Count() == 0)
                            {
                                app_contract app_contract = GenerateDefaultContrat(app_conditionContado, 0);
                                db.app_contract.Add(app_contract);
                                sales_invoice.app_contract = app_contract;
                                sales_invoice.id_contract  = app_contract.id_contract;
                            }
                            else
                            {
                                app_contract app_contract = db.app_contract.Where(x => x.name == "0 Días").FirstOrDefault();
                                sales_invoice.app_contract = app_contract;
                                sales_invoice.id_contract  = app_contract.id_contract;
                            }
                        }

                        //Sales Rep
                        if (!(InnerRow["DESVENDEDOR"] is DBNull))
                        {
                            string    _sales_rep = InnerRow["DESVENDEDOR"].ToString();
                            sales_rep sales_rep  = sales_repList.Where(x => x.name == _sales_rep && x.id_company == id_company).FirstOrDefault();
                            sales_invoice.id_sales_rep = sales_rep.id_sales_rep;
                        }

                        int          id_location  = 0;
                        app_location app_location = null;

                        //Branch
                        if (!(InnerRow["DESSUCURSAL"] is DBNull))
                        {
                            //Branch
                            string     _branch    = InnerRow["DESSUCURSAL"].ToString();
                            app_branch app_branch = BranchList.Where(x => x.name == _branch && x.id_company == id_company).FirstOrDefault();
                            sales_invoice.id_branch = app_branch.id_branch;

                            //Location
                            if (LocationList.Where(x => x.id_branch == app_branch.id_branch && x.is_default).FirstOrDefault() != null)
                            {
                                id_location  = LocationList.Where(x => x.id_branch == app_branch.id_branch && x.is_default).FirstOrDefault().id_location;
                                app_location = LocationList.Where(x => x.id_branch == app_branch.id_branch && x.is_default).FirstOrDefault();
                            }


                            //Terminal
                            sales_invoice.id_terminal = TerminalList.Where(x => x.app_branch.id_branch == app_branch.id_branch).FirstOrDefault().id_terminal;
                        }


                        if (app_currencyfx != null)
                        {
                            sales_invoice.id_currencyfx  = app_currencyfx.id_currencyfx;
                            sales_invoice.app_currencyfx = app_currencyfx;
                        }

                        DataTable dt_CurrentDetail = new DataTable();
                        if (dt_detail.Select("CODVENTA =" + InnerRow[0].ToString()).Count() > 0)
                        {
                            dt_CurrentDetail = dt_detail.Select("CODVENTA =" + InnerRow[0].ToString()).CopyToDataTable();
                        }

                        foreach (DataRow row in dt_CurrentDetail.Rows)
                        {
                            //db Related Insertion.
                            sales_invoice_detail sales_invoice_detail = new sales_invoice_detail();

                            string _prod_Name = row["DESPRODUCTO"].ToString();
                            item   item       = ItemList.Where(x => x.name == _prod_Name && x.id_company == id_company).FirstOrDefault();
                            sales_invoice_detail.id_item  = item.id_item;
                            sales_invoice_detail.quantity = Convert.ToDecimal(row["CANTIDADVENTA"]);

                            sales_invoice_detail.id_location  = id_location;
                            sales_invoice_detail.app_location = app_location;

                            string _iva = row["IVA"].ToString();
                            if (_iva == "10.00")
                            {
                                if (app_vat_group10 != null)
                                {
                                    sales_invoice_detail.id_vat_group = app_vat_group10.id_vat_group;
                                }
                            }
                            else if (_iva == "5.00")
                            {
                                if (app_vat_group5 != null)
                                {
                                    sales_invoice_detail.id_vat_group = app_vat_group5.id_vat_group;
                                }
                            }
                            else
                            {
                                if (app_vat_group0 != null)
                                {
                                    sales_invoice_detail.id_vat_group = app_vat_group0.id_vat_group;
                                }
                            }

                            decimal cotiz1 = Convert.ToDecimal((row["COTIZACION1"] is DBNull) ? 1 : Convert.ToDecimal(row["COTIZACION1"]));
                            if (cotiz1 == 0)
                            {
                                cotiz1 = 1;
                            }
                            sales_invoice_detail.unit_price = (Convert.ToDecimal(row["PRECIOVENTANETO"]) / sales_invoice_detail.quantity) / cotiz1;
                            sales_invoice_detail.unit_cost  = Convert.ToDecimal(row["COSTOPROMEDIO"]);

                            //Commit Sales Invoice Detail
                            sales_invoice.sales_invoice_detail.Add(sales_invoice_detail);
                        }

                        if (sales_invoice.Error == null)
                        {
                            sales_invoice.State      = System.Data.Entity.EntityState.Added;
                            sales_invoice.IsSelected = true;
                            db.sales_invoice.Add(sales_invoice);

                            if (!(InnerRow["ESTADO"] is DBNull))
                            {
                                int status = Convert.ToInt32(InnerRow["ESTADO"]);

                                if (status == 0)
                                {
                                    sales_invoice.status = Status.Documents_General.Pending;
                                }
                                else if (status == 1)
                                {
                                    db.Approve(true);
                                    sales_invoice.State      = System.Data.Entity.EntityState.Modified;
                                    sales_invoice.status     = Status.Documents_General.Approved;
                                    sales_invoice.IsSelected = true;

                                    add_paymnet_detail(db, sales_invoice, InnerRow["SALDOCUOTA"], InnerRow["IMPORTE"]);
                                }
                                else if (status == 2)
                                {
                                    sales_invoice.status = Status.Documents_General.Annulled;

                                    if (!(InnerRow["MOTIVOANULADO"] is DBNull))
                                    {
                                        sales_invoice.comment = InnerRow["MOTIVOANULADO"].ToString();
                                    }
                                }

                                try
                                {
                                    db.SaveChanges();
                                    sales_invoice.IsSelected = false;
                                }
                                catch (Exception ex)
                                {
                                    throw ex;
                                }
                            }
                        }
                        else
                        {
                            //Add code to include error contacts into
                            SalesInvoice_ErrorList.Add(sales_invoice);
                        }
                        // }
                        value += 1;
                        Dispatcher.BeginInvoke((Action)(() => progSales.Value = value));
                        Dispatcher.BeginInvoke((Action)(() => salesValue.Text = value.ToString()));
                    }
                }


                FloorValue = RoofValue;
                RoofValue += 1000;
            }
        }
示例#10
0
        public void salesReturn()
        {
            string sql = " SELECT "
                         + " DEVOLUCION.CODDEVOLUCION,"
                         + " CLIENTES.NOMBRE,"
                         + " VENTAS.NUMVENTA,"
                         + " DEVOLUCION.CODCOMPROBANTE,"
                         + " DEVOLUCION.CODVENTA,"
                         + " DEVOLUCION.NUMDEVOLUCION,"
                         + " DEVOLUCION.FECHADEVOLUCION, "
                         + " DEVOLUCION.TOTALEXENTA,"
                         + " DEVOLUCION.TOTALGRAVADA,"
                         + " DEVOLUCION.TOTALIVA,"
                         + " DEVOLUCION.TOTALDEVOLUCION,"
                         + " DEVOLUCION.COTIZACION1,"
                         + " DEVOLUCION.FECGRA,"
                         + " DEVOLUCION.CODVENDEDOR, "
                         + " DEVOLUCION.CODCOMPROBANTERECP,"
                         + " DEVOLUCION.COBRADO,"
                         + " DEVOLUCION.CODDEPOSITO,"
                         + " DEVOLUCION.ESTADO,"
                         + " DEVOLUCION.MOTIVOANULADO,"
                         + " DEVOLUCION.MOTIVODESCARTE, "
                         + " DEVOLUCION.TOTALIVA5,"
                         + " DEVOLUCION.TOTALIVA10,"
                         + " DEVOLUCION.TIPODEVOLUCION,"
                         + " DEVOLUCION.DESCONTARMONTO,"
                         + " MONEDA.DESMONEDA,"
                         + " SUCURSAL.DESSUCURSAL,"
                         + " DEVOLUCION.SALDO, "
                         + " VENDEDOR.DESVENDEDOR"
                         + " FROM DEVOLUCION INNER JOIN"
                         + " CLIENTES ON DEVOLUCION.CODCLIENTE = CLIENTES.CODCLIENTE INNER JOIN"
                         + " MONEDA ON DEVOLUCION.CODMONEDA = MONEDA.CODMONEDA INNER JOIN"
                         + " SUCURSAL ON DEVOLUCION.CODSUCURSAL = SUCURSAL.CODSUCURSAL LEFT OUTER JOIN"
                         + " VENDEDOR ON DEVOLUCION.CODVENDEDOR = VENDEDOR.CODVENDEDOR LEFT OUTER JOIN"
                         + " VENTAS ON CLIENTES.CODCLIENTE = VENTAS.CODCLIENTE AND DEVOLUCION.CODVENTA = VENTAS.CODVENTA ";


            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 DEVOLUCION ";
            cmd.CommandType = CommandType.Text;
            int count = (int)cmd.ExecuteScalar();

            conn.Close();

            int value = 0;

            Dispatcher.BeginInvoke((Action)(() => salesReturnMaximum.Text = count.ToString()));
            Dispatcher.BeginInvoke((Action)(() => salesReturnValue.Text = value.ToString()));
            Dispatcher.BeginInvoke((Action)(() => progSalesReturn.Maximum = count));
            Dispatcher.BeginInvoke((Action)(() => progSalesReturn.Value = value));

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

            foreach (DataRow reader in dt_salesReturn.Rows)
            {
                using (SalesReturnDB db = new SalesReturnDB())
                {
                    db.Configuration.AutoDetectChangesEnabled = false;

                    sales_return sales_return = db.New();
                    sales_return.id_company = id_company;

                    //if ((reader[6] is DBNull))
                    //{
                    //    sales_invoice.is_accounted = false;
                    //}
                    //else
                    //{
                    //    sales_invoice.is_accounted = (Convert.ToByte(reader[23]) == 0) ? false : true;
                    //}


                    //sales_invoice.version = 1;

                    sales_return.number     = (reader["NUMDEVOLUCION"] is DBNull) ? null : reader["NUMDEVOLUCION"].ToString();
                    sales_return.trans_date = Convert.ToDateTime(reader["FECHADEVOLUCION"]);

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

                    //Condition (Cash or Credit)

                    app_condition app_condition = db.app_condition.Where(x => x.name == "Contado").FirstOrDefault();
                    sales_return.id_condition = app_condition.id_condition;
                    if (db.app_contract.Where(x => x.name == "0 Días").Count() == 0)
                    {
                        app_contract app_contract = GenerateDefaultContrat(app_condition, 0);
                        db.app_contract.Add(app_contract);
                        sales_return.app_contract = app_contract;
                        sales_return.id_contract  = app_contract.id_contract;
                    }
                    else
                    {
                        app_contract app_contract = db.app_contract.Where(x => x.name == "0 Días").FirstOrDefault();
                        sales_return.app_contract = app_contract;
                        sales_return.id_contract  = app_contract.id_contract;
                    }



                    int          id_location  = 0;
                    app_location app_location = null;

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

                        //Location
                        id_location  = db.app_location.Where(x => x.id_branch == app_branch.id_branch && x.is_default).FirstOrDefault().id_location;
                        app_location = db.app_location.Where(x => x.id_branch == app_branch.id_branch && x.is_default).FirstOrDefault();
                        //Terminal
                        sales_return.id_terminal = db.app_terminal.Where(x => x.app_branch.id_branch == app_branch.id_branch).FirstOrDefault().id_terminal;
                    }

                    if (!(reader["NUMVENTA"] is DBNull))
                    {
                        string        _salesNumber  = reader["NUMVENTA"].ToString();
                        sales_invoice sales_invoice = db.sales_invoice.Where(x => x.number == _salesNumber).FirstOrDefault();
                        sales_return.id_sales_invoice = sales_invoice.id_sales_invoice;
                        //   sales_return.sales_invoice = sales_invoice;
                    }

                    string _desMoneda = string.Empty;

                    //Sales Invoice Detail
                    string sqlDetail = "SELECT"
                                       + " dbo.PRODUCTOS.DESPRODUCTO,"              //0
                                       + " dbo.DEVOLUCIONDETALLE.CANTIDADDEVUELTA," //1
                                       + " dbo.DEVOLUCIONDETALLE.PRECIONETO, "      //2
                                       + " dbo.DEVOLUCIONDETALLE.COSTOPROMEDIO, "   //4
                                       + " dbo.DEVOLUCIONDETALLE.COSTOULTIMO, "     //5
                                       + " dbo.DEVOLUCIONDETALLE.IVA, "             //6
                                       + " dbo.DEVOLUCION.COTIZACION1 "             //6
                                       + " FROM dbo.DEVOLUCION LEFT OUTER JOIN"
                                       + " dbo.DEVOLUCIONDETALLE ON dbo.DEVOLUCION.CODDEVOLUCION = dbo.DEVOLUCIONDETALLE.CODDEVOLUCION LEFT OUTER JOIN"
                                       + " dbo.PRODUCTOS ON dbo.DEVOLUCIONDETALLE.CODPRODUCTO = dbo.PRODUCTOS.CODPRODUCTO"
                                       + " WHERE (dbo.DEVOLUCIONDETALLE.CODDEVOLUCION = " + reader["CODDEVOLUCION"].ToString() + ")";

                    DataTable dt = exeDT(sqlDetail);
                    foreach (DataRow row in dt.Rows)
                    {
                        //db Related Insertion.
                        sales_return.id_currencyfx  = db.app_currencyfx.Where(x => x.is_active).FirstOrDefault().id_currencyfx;
                        sales_return.app_currencyfx = db.app_currencyfx.Where(x => x.is_active).FirstOrDefault();

                        sales_return_detail sales_return_detail = new sales_return_detail();

                        string _prod_Name = row["DESPRODUCTO"].ToString();
                        item   item       = db.items.Where(x => x.name == _prod_Name && x.id_company == id_company).FirstOrDefault();
                        if (item != null)
                        {
                            sales_return_detail.id_item = item.id_item;
                        }
                        else
                        {
                            value += 1;
                            Dispatcher.BeginInvoke((Action)(() => progSalesReturn.Value = value));
                            Dispatcher.BeginInvoke((Action)(() => salesReturnValue.Text = value.ToString()));
                            continue;
                        }
                        sales_return_detail.id_item  = item.id_item;
                        sales_return_detail.quantity = Convert.ToDecimal(row["CANTIDADDEVUELTA"]);

                        sales_return_detail.id_location  = id_location;
                        sales_return_detail.app_location = app_location;

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

                        decimal cotiz1 = Convert.ToDecimal((row["COTIZACION1"] is DBNull) ? 1 : Convert.ToDecimal(row["COTIZACION1"]));
                        sales_return_detail.unit_price = (Convert.ToDecimal(row["PRECIONETO"]) / sales_return_detail.quantity) / cotiz1;
                        if (!(row["COSTOPROMEDIO"] is DBNull))
                        {
                            sales_return_detail.unit_cost = Convert.ToDecimal(row["COSTOPROMEDIO"]);
                        }


                        //Commit Sales Invoice Detail
                        sales_return.sales_return_detail.Add(sales_return_detail);
                    }
                    sales_return.return_type = Status.ReturnTypes.Bonus;

                    if (sales_return.Error == null)
                    {
                        sales_return.State      = System.Data.Entity.EntityState.Added;
                        sales_return.IsSelected = true;
                        db.sales_return.Add(sales_return);
                        try
                        {
                            db.SaveChanges();
                        }
                        catch (Exception ex)
                        {
                            throw ex;
                        }
                        if (!(reader["ESTADO"] is DBNull))
                        {
                            int status = Convert.ToInt32(reader["ESTADO"]);
                            if (status == 0)
                            {
                                sales_return.status = Status.Documents_General.Pending;
                                if (!(reader[11] is DBNull))
                                {
                                    sales_return.comment = reader[11].ToString();
                                }
                            }
                            else if (status == 1)
                            {
                                sales_return.status = Status.Documents_General.Approved;
                                if (!(reader[11] is DBNull))
                                {
                                    sales_return.comment = reader[11].ToString();
                                }
                                db.Approve();
                            }
                            else if (status == 2)
                            {
                                sales_return.status = Status.Documents_General.Annulled;
                                if (!(reader[11] is DBNull))
                                {
                                    sales_return.comment = reader[11].ToString();
                                }
                                db.Approve();
                                db.Anull();
                            }
                        }


                        value += 1;
                        Dispatcher.BeginInvoke((Action)(() => progSalesReturn.Value = value));
                        Dispatcher.BeginInvoke((Action)(() => salesReturnValue.Text = value.ToString()));
                    }
                    else
                    {
                        //Add code to include error contacts into
                        sales_return_ErrorList.Add(sales_return);
                    }
                }
            }
            // reader.Close();
            //cmd.Dispose();
            conn.Close();

            //_customer_Current = _customer_Max;
        }
示例#11
0
        private void toolBar_btnApprove_Click(object sender)
        {
            item_transfer item_transfer = item_transferViewSource.View.CurrentItem as item_transfer;

            if ((item_transfer.number == null || item_transfer.number == string.Empty) && item_transfer.app_document_range != null)
            {
                entity.Brillo.Logic.Document _Document = new entity.Brillo.Logic.Document();
                if (item_transfer.id_branch > 0)
                {
                    if (dbContext.app_branch.Where(x => x.id_branch == item_transfer.id_branch).FirstOrDefault() != null)
                    {
                        entity.Brillo.Logic.Range.branch_Code = dbContext.app_branch.Where(x => x.id_branch == item_transfer.id_branch).FirstOrDefault().code;
                    }
                }
                if (item_transfer.id_terminal > 0)
                {
                    if (dbContext.app_terminal.Where(x => x.id_terminal == item_transfer.id_terminal).FirstOrDefault() != null)
                    {
                        entity.Brillo.Logic.Range.terminal_Code = dbContext.app_terminal.Where(x => x.id_terminal == item_transfer.id_terminal).FirstOrDefault().code;
                    }
                }
                if (item_transfer.id_user > 0)
                {
                    if (dbContext.security_user.Where(x => x.id_user == item_transfer.id_user).FirstOrDefault() != null)
                    {
                        entity.Brillo.Logic.Range.user_Code = dbContext.security_user.Where(x => x.id_user == item_transfer.id_user).FirstOrDefault().code;
                    }
                }
                if (item_transfer.id_project > 0)
                {
                    if (dbContext.projects.Where(x => x.id_project == item_transfer.id_project).FirstOrDefault() != null)
                    {
                        entity.Brillo.Logic.Range.project_Code = dbContext.projects.Where(x => x.id_project == item_transfer.id_project).FirstOrDefault().code;
                    }
                }

                app_document_range app_document_range = item_transfer.app_document_range;
                item_transfer.number = entity.Brillo.Logic.Range.calc_Range(app_document_range, true);
            }

            item_transfer.user_requested = dbContext.security_user.Where(x => x.id_user == CurrentSession.Id_User).FirstOrDefault();
            item_transfer.user_given     = dbContext.security_user.Where(x => x.id_user == CurrentSession.Id_User).FirstOrDefault();
            item_transfer.status         = Status.Transfer.Approved;

            dbContext.SaveChanges();

            for (int i = 0; i < item_transfer_detailDataGrid.Items.Count; i++)
            {
                entity.Brillo.Logic.Stock stock = new entity.Brillo.Logic.Stock();

                item_transfer_detail item_transfer_detail = (item_transfer_detail)item_transfer_detailDataGrid.Items[i];

                List <entity.Brillo.StockList> Items_InStockLIST;
                app_currencyfx app_currencyfx = ProductMovementDB.app_currencyfx.Where(x => x.app_currency.is_active).FirstOrDefault();
                app_location   app_location   = item_transfer_detail.item_transfer.app_location_origin;

                if (itemMovement.item_movement != null)
                {
                    entity.Brillo.Stock stockBrillo = new entity.Brillo.Stock();
                    Items_InStockLIST = stockBrillo.ScalarMovement(itemMovement.item_movement);
                }
                else
                {
                    entity.Brillo.Stock stockBrillo = new entity.Brillo.Stock();
                    Items_InStockLIST = stockBrillo.List(app_location.app_branch, app_location, item_transfer_detail.item_product);
                }

                ///Debit Movement from Origin.
                List <item_movement> item_movement_originList;
                item_movement_originList = stock.DebitOnly_MovementLIST(ProductMovementDB, Items_InStockLIST, Status.Stock.InStock, entity.App.Names.Movement, item_transfer_detail.id_transfer, item_transfer_detail.id_transfer_detail, app_currencyfx, item_transfer_detail.item_product, app_location,
                                                                        item_transfer_detail.quantity_origin, item_transfer_detail.item_transfer.trans_date, stock.comment_Generator(entity.App.Names.Movement, item_transfer_detail.item_transfer.number != null ? item_transfer_detail.item_transfer.number.ToString() : "", ""));

                ProductMovementDB.item_movement.AddRange(item_movement_originList);

                //Credit Movement to Destination
                item_movement item_movement_dest;
                item_movement parent_item_movement = item_movement_originList.FirstOrDefault();

                List <item_movement_dimension> DimensionList = null;

                if (item_movement_originList.FirstOrDefault().item_movement_dimension.Count() > 0)
                {
                    DimensionList = new List <item_movement_dimension>();
                    foreach (item_movement_dimension item_movement_dimension in item_movement_originList.FirstOrDefault().item_movement_dimension)
                    {
                        item_movement_dimension _item_movement_dimension = new item_movement_dimension();
                        _item_movement_dimension.id_dimension = item_movement_dimension.id_dimension;
                        _item_movement_dimension.value        = item_movement_dimension.value;
                        DimensionList.Add(_item_movement_dimension);
                    }
                }

                item_movement_dest =
                    stock.CreditOnly_Movement(
                        Status.Stock.InStock,
                        entity.App.Names.Movement,
                        item_transfer_detail.id_transfer,
                        item_transfer_detail.id_transfer_detail,
                        app_currencyfx,
                        item_transfer_detail.item_product,
                        item_transfer_detail.item_transfer.app_location_destination,
                        item_transfer_detail.quantity_destination,
                        item_transfer_detail.item_transfer.trans_date,
                        item_movement_originList.Sum(x => (x.item_movement_value.Sum(y => y.unit_value) / (x.item_movement_value.Count() != 0 ? x.item_movement_value.Count() : 1))),
                        stock.comment_Generator(entity.App.Names.Movement, item_transfer_detail.item_transfer.number != null ? item_transfer_detail.item_transfer.number.ToString() : "", ""),
                        DimensionList
                        );
                //item_movement_dest._parent = Items_InStockLIST.FirstOrDefault();
                ProductMovementDB.item_movement.Add(item_movement_dest);
                item_transfer.status = Status.Transfer.Approved;
            }

            if (item_transfer.status == Status.Transfer.Approved && item_transfer.app_document_range != null)
            {
                entity.Brillo.Document.Start.Automatic(item_transfer, item_transfer.app_document_range);
            }

            if (ProductMovementDB.SaveChanges() > 0)
            {
                toolBar.msgSaved(ProductMovementDB.NumberOfRecords);
                itemMovement = new Configs.itemMovement();
            }
        }
示例#12
0
        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();
        }