Beispiel #1
0
        public RespuestaAccion MODIF_PURCHASE_DETAIL(int headId, SV_SYSTEM sistema, bool depreciar, bool con_credito)
        {
            var res = new RespuestaAccion();

            try
            {
                int validity_id = 1;    //Durante las compras nunca se debe cambiar el estado de validacion

                var FindDetail = (from d in _context.TRANSACTIONS_DETAILS
                                  where d.trx_head_id == headId &&
                                  d.system_id == sistema.id
                                  select d).FirstOrDefault();
                if (FindDetail != null)
                {
                    FindDetail.validity_id  = validity_id;
                    FindDetail.allow_credit = con_credito;
                    FindDetail.depreciate   = depreciar;

                    _context.SaveChanges();
                    res.AddResultObj(FindDetail.id, FindDetail.GetType());
                    res.set_ok();
                }
                else
                {
                    res.set(-2, "No se encontro cabecera para modificar");
                }
            }
            catch (Exception ex)
            {
                res.set(-1, ex.StackTrace);
            }
            return(res);
        }
Beispiel #2
0
        public RespuestaAccion CREATE_SALES_DOC(string DocNumber, decimal ExtendedCost, DateTime DocDate, List <C.DisplayVentaPrecio> DetailsList)
        {
            var res = new RespuestaAccion();

            try
            {
                var SalesHeadNew = new SALES_HEAD();
                SalesHeadNew.docventa = DocNumber;
                SalesHeadNew.cost_ext = ExtendedCost;
                SalesHeadNew.docdate  = DocDate;

                _context.SALES_HEAD.AddObject(SalesHeadNew);

                foreach (var d in DetailsList)
                {
                    decimal diferencia = d.PrecioTotal - (d.PrecioUnitario * d.Cantidad);
                    if (diferencia == 0)
                    {
                        var NewSaleDetail = new SALES_DETAIL();
                        NewSaleDetail.SALES_HEAD = SalesHeadNew;
                        NewSaleDetail.part_id    = d.rowIndex;
                        NewSaleDetail.quantity   = d.Cantidad;
                        NewSaleDetail.unit_cost  = d.CostoUnitario;
                        NewSaleDetail.ext_cost   = d.CostoExtend;
                        NewSaleDetail.unit_price = d.PrecioUnitario;
                        NewSaleDetail.ext_price  = d.PrecioTotal;
                        NewSaleDetail.zone_id    = d.Zona.id;
                        NewSaleDetail.subzone_id = d.Subzona.id;
                        NewSaleDetail.kind_id    = d.Clase.id;
                        NewSaleDetail.docline    = DetailsList.IndexOf(d);

                        _context.SALES_DETAIL.AddObject(NewSaleDetail);
                    }
                    else
                    {
                        var NewSaleDetailA = new SALES_DETAIL();
                        NewSaleDetailA.SALES_HEAD = SalesHeadNew;
                        NewSaleDetailA.part_id    = d.rowIndex;
                        NewSaleDetailA.quantity   = 1;
                        NewSaleDetailA.unit_cost  = d.CostoUnitario;
                        NewSaleDetailA.ext_cost   = d.CostoUnitario;
                        NewSaleDetailA.unit_price = d.PrecioUnitario + diferencia;
                        NewSaleDetailA.ext_price  = d.PrecioUnitario + diferencia;
                        NewSaleDetailA.zone_id    = d.Zona.id;
                        NewSaleDetailA.subzone_id = d.Subzona.id;
                        NewSaleDetailA.kind_id    = d.Clase.id;
                        NewSaleDetailA.docline    = DetailsList.IndexOf(d);

                        _context.SALES_DETAIL.AddObject(NewSaleDetailA);

                        var NewSaleDetailB = new SALES_DETAIL();
                        NewSaleDetailB.SALES_HEAD = SalesHeadNew;
                        NewSaleDetailB.part_id    = d.rowIndex;
                        NewSaleDetailB.quantity   = d.Cantidad - 1;
                        NewSaleDetailB.unit_cost  = d.CostoUnitario;
                        NewSaleDetailB.ext_cost   = d.CostoUnitario * NewSaleDetailB.quantity;
                        NewSaleDetailB.unit_price = d.PrecioUnitario;
                        NewSaleDetailB.ext_price  = d.PrecioUnitario * NewSaleDetailB.quantity;
                        NewSaleDetailB.zone_id    = d.Zona.id;
                        NewSaleDetailB.subzone_id = d.Subzona.id;
                        NewSaleDetailB.kind_id    = d.Clase.id;
                        NewSaleDetailB.docline    = DetailsList.IndexOf(d);

                        _context.SALES_DETAIL.AddObject(NewSaleDetailB);
                    }
                }

                _context.SaveChanges();
                res.AddResultObj(SalesHeadNew.id, SalesHeadNew.GetType());
                res.set_ok();
            }
            catch (Exception ex)
            {
                res.set(-1, ex.StackTrace);
            }
            return(res);
        }