if( $this->getRequestParameter( 'b_control' ) ) { if( !$f_TipoCob ) { throw new Exception( "El Tipo de Cambio no esta ingresado." ); } if( $o_MST_ListaPrecioCabeceraBN->getIdMoneda() == "EX" ) { if( !$f_TipoCob ) { throw new Exception( "El Tipo de Cambio no esta ingresado." ); } } else { $f_TipoCob = 1; } $f_CostoIGV = floatval( $this->getRequestParameter( 'txtCostoIGV' ) ); $f_Costo = floatval( $this->getRequestParameter( 'txtCosto' ) ); if( $this->b_ControlRango) { $a_PrecioVenta = $this->getRequestParameter( 'PrecioVenta' ); $a_MontoIGV = $this->getRequestParameter( 'MontoIGV' ); $a_PrecioVentaIGVPr = $this->getRequestParameter( 'PrecioVentaIGV' ); //$s_IdTipoLista = $this->getRequestParameter( 'IdTipoLista' ); $s_IdRango = $this->s_IdRango; $i_IdTipoPrecio = "1"; foreach ( $a_PrecioVentaIGVPr as $s_IdItem => $a_Data ) { foreach ( $a_Data as $s_IdRangoDet => $s_PrecioIGV ) { $f_PrecioVentaIGV = floatval( $s_PrecioIGV ); $f_MontoIGV = floatval( $a_MontoIGV[$s_IdItem][$s_IdRangoDet] ); $f_PrecioVenta = floatval( $a_PrecioVenta[$s_IdItem][$s_IdRangoDet] ); /*$f_MontoIncImpuestoUnidad = $f_PrecioVentaIGV; $f_PrecioUnitario = round( $f_MontoIncImpuestoUnidad / $f_ValorIGVMasUno, 13 ); $f_MontoImpuestoUnidad = round( $f_PrecioUnitario * $f_ValorIGV, 13 ); $f_MontoImpuestoUnidad = round( $f_MontoImpuestoUnidad, 2 ); $f_PrecioUnitario = round( $f_PrecioUnitario, 2 );*/ $o_MST_ListaPrecioDetalleFN = new MST_ListaPrecioDetalleFN(); $o_MST_ListaPrecioDetalleFN->setIdCompania( myUser::getUser()->getIdBusiness() ); $o_MST_ListaPrecioDetalleFN->setIdSucursal( myUser::getUser()->getIdSucursal() ); $o_MST_ListaPrecioDetalleFN->setIdItem( $s_IdItem ); $o_MST_ListaPrecioDetalleFN->setIdTipoLista( $s_IdTipoLista ); $o_MST_ListaPrecioDetalleFN->setIdRango( $s_IdRango ); $o_MST_ListaPrecioDetalleFN->setIdRangoDetalle( $s_IdRangoDet ); $a_MST_ListaPrecioDetalle = $o_MST_ListaPrecioDetalleFN->select(); $o_DefaultDP = new MST_ListaPrecioDetalleDP(); $o_DefaultDP->setIdCompania( myUser::getUser()->getIdBusiness() ); $o_DefaultDP->setIdSucursal( myUser::getUser()->getIdSucursal() ); $o_DefaultDP->setIdItem( $s_IdItem ); $o_DefaultDP->setIdTipoLista( ( int ) $s_IdTipoLista ); $o_DefaultDP->setIdRango( ( int ) $s_IdRango ); $o_DefaultDP->setIdRangoDetalle( ( int ) $s_IdRangoDet ); $o_DefaultDP->setIdTipoPrecio( $i_IdTipoPrecio ); //$o_DefaultDP->setFechaInicio( $FechaInicio ); //$o_DefaultDP->setFechaFin( $FechaFin ); /*$o_DefaultDP->setPrecioCosto( 0 ); $o_DefaultDP->setPrecioCostoIGV( 0 ); $o_DefaultDP->setPorcentajeUtilidad( 0 );*/ $o_DefaultDP->setPrecioVenta( $f_PrecioVenta ); $o_DefaultDP->setMontoIGV( $f_MontoIGV ); $o_DefaultDP->setPrecioVentaIGV( $f_PrecioVentaIGV ); $o_DefaultDP->setMontoDescuento( 0 ); $o_DefaultDP->setPorcentajeDescuento( 0 ); $o_DefaultDP->setDescuentoFlag( "N" ); $o_DefaultDP->setEstado( "A" ); if( $a_MST_ListaPrecioDetalle ) { //update $i_IdDet = $a_MST_ListaPrecioDetalle[0]->getIdListaPreciDet(); $o_DefaultDP->setIdListaPreciDet( $i_IdDet ); $o_DefaultDP->setFechaModificacion( date( "Y-m-d H:i:s" ) ); $o_DefaultDP->setUsuarioModificacion( myUser::getUser()->getUserId() ); $o_DefaultDP->update(); } else { //insert $i_IdDet = MST_ListaPrecioDetalleDP::recuperarId(); $o_DefaultDP = new MST_ListaPrecioDetalleDP(); $o_DefaultDP->setIdListaPreciDet( $i_IdDet ); $o_DefaultDP->setFechaCreacion( date( "Y-m-d H:i:s" ) ); $o_DefaultDP->setUsuarioCreacion( myUser::getUser()->getUserId() ); $o_DefaultDP->setFechaModificacion( date( "Y-m-d H:i:s" ) ); $o_DefaultDP->setUsuarioModificacion( myUser::getUser()->getUserId() ); $o_DefaultDP->save(); } } } } if( !$this->b_ControlRango) { $a_Data = $this->getRequestParameter( 'a_data_item' ); foreach ( $a_Data as $i_IdTipoPrecio => $a_ValorPorcen ) { $i_IdTipoPrecio = ( string ) $i_IdTipoPrecio; if( floatval( $a_ValorPorcen['precioigv'] ) >= 0 ) { $IdItem = $this->s_IdItem; $PorcentajeUtilidad = floatval( $a_ValorPorcen['utilidad'] ); $PrecioVenta = floatval( $a_ValorPorcen['precio'] ); $MontoIGV = floatval( $a_ValorPorcen['montoigv'] ); $PrecioVentaIGV = floatval( $a_ValorPorcen['precioigv'] ); $o_MST_ListaPrecioDetalleFN = new MST_ListaPrecioDetalleFN(); $o_MST_ListaPrecioDetalleBN = $o_MST_ListaPrecioDetalleFN->selectByPK( myUser::getUser()->getIdBusiness(), myUser::getUser()->getIdSucursal(), $IdItem, $i_IdTipoPrecio ); //$o_MST_ListaPrecioDetalleBN = MST_ListaPrecioDetalleFN::buscarPrecioGeneral( $IdItem ); if( $o_MST_ListaPrecioDetalleBN ) { //SE GUARDA EL LOG $o_MST_ListaPrecioDetalleLogDP = new MST_ListaPrecioDetalleLogDP(); $o_MST_ListaPrecioDetalleLogDP->setIdCompania( $o_MST_ListaPrecioDetalleBN->getIdCompania() ); $o_MST_ListaPrecioDetalleLogDP->setIdSucursal( $o_MST_ListaPrecioDetalleBN->getIdSucursal() ); $o_MST_ListaPrecioDetalleLogDP->setIdItem( $o_MST_ListaPrecioDetalleBN->getIdItem() ); $o_MST_ListaPrecioDetalleLogDP->setIdTipoPrecio( $i_IdTipoPrecio ); //$o_MST_ListaPrecioDetalleLogDP->setFechaInicio( $o_MST_ListaPrecioDetalleBN->getFechaInicio() ); //$o_MST_ListaPrecioDetalleLogDP->setFechaFin( $o_MST_ListaPrecioDetalleBN->getFechaFin() ); $o_MST_ListaPrecioDetalleLogDP->setEstado( $o_MST_ListaPrecioDetalleBN->getEstado() ); $o_MST_ListaPrecioDetalleLogDP->setPrecioCosto( $o_MST_ListaPrecioDetalleBN->getPrecioCosto() ); $o_MST_ListaPrecioDetalleLogDP->setPorcentajeUtilidad( $o_MST_ListaPrecioDetalleBN->getPorcentajeUtilidad() ); $o_MST_ListaPrecioDetalleLogDP->setPrecioVenta( $o_MST_ListaPrecioDetalleBN->getPrecioVenta() ); //$o_MST_ListaPrecioDetalleLogDP->setMontoDescuento( $o_MST_ListaPrecioDetalleBN->getMontoDescuento() ); //$o_MST_ListaPrecioDetalleLogDP->setPorcentajeDescuento( $o_MST_ListaPrecioDetalleBN->getPorcentajeDescuento() ); //$o_MST_ListaPrecioDetalleLogDP->setDescuentoFlag( $o_MST_ListaPrecioDetalleBN->getDescuentoFlag() ); $o_MST_ListaPrecioDetalleLogDP->setFechaCreacion( date( "Y-m-d H:i:s" ) ); $o_MST_ListaPrecioDetalleLogDP->setUsuarioCreacion( $o_MST_ListaPrecioDetalleBN->getUsuarioCreacion() ); $o_MST_ListaPrecioDetalleLogDP->setFechaModificacion( date( "Y-m-d H:i:s" ) ); $o_MST_ListaPrecioDetalleLogDP->setUsuarioModificacion( $o_MST_ListaPrecioDetalleBN->getUsuarioModificacion() ); $o_MST_ListaPrecioDetalleLogDP->save(); } if( $o_MST_ListaPrecioDetalleBN ) { //UPDATE $o_DefaultDP = new MST_ListaPrecioDetalleDP(); $o_DefaultDP->setIdCompania( myUser::getUser()->getIdBusiness() ); $o_DefaultDP->setIdSucursal( myUser::getUser()->getIdSucursal() ); $o_DefaultDP->setIdItem( $IdItem ); $o_DefaultDP->setIdTipoPrecio( $i_IdTipoPrecio ); //$o_DefaultDP->setFechaInicio( $FechaInicio ); //$o_DefaultDP->setFechaFin( $FechaFin ); $o_DefaultDP->setPrecioCosto( $f_Costo ); $o_DefaultDP->setPrecioCostoIGV( $f_CostoIGV ); $o_DefaultDP->setPorcentajeUtilidad( $PorcentajeUtilidad ); $o_DefaultDP->setPrecioVenta( $PrecioVenta ); $o_DefaultDP->setMontoIGV( $MontoIGV ); $o_DefaultDP->setPrecioVentaIGV( $PrecioVentaIGV ); //$o_DefaultDP->setMontoDescuento( $MontoDescuento ); //$o_DefaultDP->setPorcentajeDescuento( $PorcentajeDescuento ); //$o_DefaultDP->setDescuentoFlag( $DescuentoFlag ); $o_DefaultDP->setFechaModificacion( date( "Y-m-d H:i:s" ) ); $o_DefaultDP->setUsuarioModificacion( myUser::getUser()->getUserId() ); //pr( $o_DefaultDP ); $b_Result = $o_DefaultDP->update(); //$i_IdDet = $IdCompania."_".$IdSucursal."_".$IdItem; } else { //INSERT $o_DefaultDP = new MST_ListaPrecioDetalleDP(); $o_DefaultDP->setIdCompania( myUser::getUser()->getIdBusiness() ); $o_DefaultDP->setIdSucursal( myUser::getUser()->getIdSucursal() ); $o_DefaultDP->setIdItem( $IdItem ); $o_DefaultDP->setIdTipoPrecio( $i_IdTipoPrecio ); //$o_DefaultDP->setFechaInicio( $FechaInicio ); //$o_DefaultDP->setFechaFin( $FechaFin ); $o_DefaultDP->setPrecioCosto( $f_Costo ); $o_DefaultDP->setPrecioCostoIGV( $f_CostoIGV ); $o_DefaultDP->setPorcentajeUtilidad( $PorcentajeUtilidad ); $o_DefaultDP->setPrecioVenta( $PrecioVenta ); $o_DefaultDP->setMontoIGV( $MontoIGV ); $o_DefaultDP->setPrecioVentaIGV( $PrecioVentaIGV ); //$o_DefaultDP->setMontoDescuento( $MontoDescuento ); //$o_DefaultDP->setPorcentajeDescuento( $PorcentajeDescuento ); //$o_DefaultDP->setDescuentoFlag( $DescuentoFlag ); $o_DefaultDP->setEstado( "A" ); $o_DefaultDP->setFechaCreacion( date( "Y-m-d H:i:s" ) ); $o_DefaultDP->setUsuarioCreacion( myUser::getUser()->getUserId() ); $o_DefaultDP->setFechaModificacion( date( "Y-m-d H:i:s" ) ); $o_DefaultDP->setUsuarioModificacion( myUser::getUser()->getUserId() ); //pr( $o_DefaultDP ); $b_Result = $o_DefaultDP->save(); //$i_IdDet = $IdCompania."_".$IdSucursal."_".$IdItem; } //ahora se actualiza en la tabla de item como referencia principal $o_ALM_ItemMastDP = new ALM_ItemMastDP(); $o_ALM_ItemMastDP->setIdItem( $IdItem ); if( $o_MST_ListaPrecioCabeceraBN->getIdMoneda() == "LO" ) //MONEDA DE LA LISTA DE PRECIOS ES SOLES { $f_PrecioUnitarioLocal = $f_Costo; $f_PrecioUnitarioDolares = utilMath::fnround( $f_Costo / $f_TipoCob, 2 ); } if( $o_MST_ListaPrecioCabeceraBN->getIdMoneda() == "EX" ) //MONEDA DE LA LISTA DE PRECIOS ES DOLARES { $f_PrecioUnitarioLocal = utilMath::fnround( $f_Costo * $f_TipoCob, 2 ); $f_PrecioUnitarioDolares = $f_Costo; } $o_ALM_ItemMastDP->setPrecioCosto( $f_Costo ); $o_ALM_ItemMastDP->setPrecioVenta( $f_CostoIGV ); $o_ALM_ItemMastDP->setPrecioUnitarioLocal( $f_PrecioUnitarioLocal ); $o_ALM_ItemMastDP->setPrecioUnitarioDolares( $f_PrecioUnitarioDolares ); $o_ALM_ItemMastDP->setUsuarioModificacion( myUser::getUser()->getUserId() ); $o_ALM_ItemMastDP->setFechaModificacion( date( "Y-m-d H:i:s" ) ); $o_ALM_ItemMastDP->update(); $this->b_CerrarWindow = true; } else { //aqui se elimina el tipo de precio $o_DefaultDP = new MST_ListaPrecioDetalleDP(); $o_DefaultDP->setIdCompania( myUser::getUser()->getIdBusiness() ); $o_DefaultDP->setIdSucursal( myUser::getUser()->getIdSucursal() ); $o_DefaultDP->setIdItem( $this->s_IdItem ); $o_DefaultDP->setIdTipoPrecio( $i_IdTipoPrecio ); $o_DefaultDP->delete(); } } } }