Ejemplo n.º 1
0
        public void AttemptModifyFactura()
        {
            if (Catalog)
            {
                FacturaCompraDataMapper        fcdmp = new FacturaCompraDataMapper();
                FacturaCompraDetalleDataMapper fcdDm = new FacturaCompraDetalleDataMapper();

                //Actualizar Factura
                fcdmp.udpateElement(new FACTURA()
                {
                    UNID_FACTURA        = this.SelectedFactura.UnidFactura,
                    FACTURA_NUMERO      = this.NumeroFactura,
                    FECHA_FACTURA       = this.FechaFactura,
                    IS_ACTIVE           = true,
                    IVA_POR             = this.PorIva,
                    UNID_MONEDA         = this.SelectedMoneda.UnidMoneda,
                    UNID_PROVEEDOR      = this.SelectedProveedor.UnidProveedor,
                    NUMERO_PEDIMENTO    = this.NumeroPedimento,
                    UNID_TIPO_PEDIMENTO = this.SelectedTipoPedimento.UnidTipoPedimento,
                    TC = this.TC
                }, this.ActualUser);

                //Generar Array para insertar/actualizar/eliminar las factura detalle
                List <FACTURA_DETALLE> fds = new List <FACTURA_DETALLE>();
                foreach (FacturaCompraDetalleModel det in this.FacturaDetalles)
                {
                    fds.Add(det.ConvertToPoco(det));
                    fds[fds.Count - 1].UNID_FACTURA = this.SelectedFactura.UnidFactura;
                }

                if (fds.Count > 0)
                {
                    fcdDm.udpateElements(fds);
                }
            }

            if (this._SelectedFactura != null)
            {
                this._SelectedFactura.FechaFactura    = this.FechaFactura;
                this._SelectedFactura.Moneda          = this.SelectedMoneda;
                this._SelectedFactura.NumeroFactura   = this.NumeroFactura;
                this._SelectedFactura.NumeroPedimento = this.NumeroPedimento;
                this._SelectedFactura.PorIva          = this.PorIva;
                this._SelectedFactura.Proveedor       = this.SelectedProveedor;
                this._SelectedFactura.IsNew           = this.IsNew;
                this._SelectedFactura.IsModified      = this.IsModified;
                this._SelectedFactura.FacturaDetalle  = this.FacturaDetalles;
                this._SelectedFactura.TC            = this.TC;
                this._SelectedFactura.TipoPedimento = this.SelectedTipoPedimento;
            }
        }
        private void SaveFactura()
        {
            LoteModel lot = null;
            FacturaCompraDataMapper        fcdmp = new FacturaCompraDataMapper();
            FacturaCompraDetalleDataMapper fcdDm = new FacturaCompraDetalleDataMapper();

            //Guardar
            foreach (FacturaCompraModel item in this.Facturas)
            {
                if (item.IsNew)
                {
                    //insertar la nueva factura
                    if (lot == null)
                    {
                        lot          = new LoteModel(new LoteDataMapper());
                        lot.UnidLote = UNID.getNewUNID();
                        lot.UnidPOM  = UNID.getNewUNID();
                        lot.saveLote();
                    }

                    item.UnidLote    = lot.UnidLote;
                    item.UnidFactura = UNID.getNewUNID();
                    item.saveFactura();
                    //factura detalle
                    foreach (FacturaCompraDetalleModel fac in item.FacturaDetalle)
                    {
                        fac.Factura = item;
                        fac.saveFacturaDetalle();
                    }
                }
                else
                {
                    //Actualizar Factura
                    fcdmp.udpateElement(new FACTURA()
                    {
                        UNID_FACTURA        = item.UnidFactura,
                        FACTURA_NUMERO      = item.NumeroFactura,
                        FECHA_FACTURA       = item.FechaFactura,
                        IS_ACTIVE           = item.IsActive,
                        IVA_POR             = item.PorIva,
                        UNID_MONEDA         = item.Moneda.UnidMoneda,
                        UNID_PROVEEDOR      = item.Proveedor.UnidProveedor,
                        NUMERO_PEDIMENTO    = item.NumeroPedimento,
                        UNID_TIPO_PEDIMENTO = item.TipoPedimento.UnidTipoPedimento,
                        TC = item.TC
                    }, this.ActualUser);

                    //Generar Array para insertar/actualizar/eliminar las factura detalle
                    List <FACTURA_DETALLE> fds = new List <FACTURA_DETALLE>();
                    foreach (FacturaCompraDetalleModel det in item.FacturaDetalle)
                    {
                        fds.Add(det.ConvertToPoco(det));
                        fds[fds.Count - 1].UNID_FACTURA = item.UnidFactura;
                    }

                    if (fds.Count > 0)
                    {
                        fcdDm.udpateElements(fds);
                    }
                }
                //Borrar facturas
                fcdmp.deleteFacturas(this._DelFacturas, this.ActualUser);
            } //end foreach
        }     //end func