trabajando en preciopliego

This commit is contained in:
Jaime Jiménez
2023-09-25 13:47:49 +02:00
parent d9afa9a1ef
commit 089df469e7
5 changed files with 232 additions and 33 deletions

View File

@ -2,16 +2,16 @@
namespace App\Services;
use App\Controllers\Servicios\Maquetacion;
use CodeIgniter\Config\BaseService;
use App\Models\Configuracion\MaquinaModel;
use App\Models\Configuracion\PapelImpresionModel;
class PresupuestoService extends BaseService
{
public static function test(){
public static function test()
{
$uso = 'interior';
$tipo = 'negro';
$cantidad = (object)array(
@ -22,8 +22,8 @@ class PresupuestoService extends BaseService
);
$maquina_model = new MaquinaModel();
$maquina_model = new \App\Models\Configuracion\MaquinaModel();
$opciones_papel = array(
'bn' => 1,
@ -31,13 +31,16 @@ class PresupuestoService extends BaseService
'sobrecubierta' => 0,
'rotativa' => 0,
);
$papelimpresionmodel = new PapelImpresionModel();
$papelimpresionmodel = new \App\Models\Configuracion\PapelImpresionModel();
echo 'Papeles impresion con gramaje=90';
$papeles = $papelimpresionmodel->getIdPapelesImpresionForPresupuesto(
papel_generico_id: 4,
gramaje: 70,
gramaje: 90,
options: $opciones_papel
);
foreach($papeles as $papel){
foreach ($papeles as $papel) {
echo '-------------------------------';
$maquinas = $maquina_model->getMaquinaImpresionForPresupuesto(
is_rotativa: $papel->rotativa,
@ -50,9 +53,75 @@ class PresupuestoService extends BaseService
var_dump($maquinas);
echo '</pre>';
}
}
/*public static function test2()
{
$uso = 'interior';
$tipo = 'negro';
$cantidad = (object)array(
'paginas' => 100,
'tirada' => 50,
'merma' => 5,
'merma_portada' => 1,
);
$maquina_model = new \App\Models\Configuracion\MaquinaModel();
$opciones_papel = array(
'bn' => 1,
'cubierta' => 0,
'sobrecubierta' => 0,
'rotativa' => 0,
);
$papelimpresionmodel = new \App\Models\Configuracion\PapelImpresionModel();
$papeles = $papelimpresionmodel->getIdPapelesImpresionForPresupuesto(
papel_generico_id: 4,
gramaje: 70,
options: $opciones_papel
);
foreach ($papeles as $papel) {
echo '-------------------------------';
$maquinas = $maquina_model->getMaquinaImpresionForPresupuesto(
is_rotativa: $papel->rotativa,
tarifa_tipo: 'negro',
papel_impresion_id: $papel->id
);
foreach ($maquinas as $maquina) {
if ($maquina->maquina == 'C1100-ByN') {
$formas = PresupuestoService::getNumFormasPlanaInterior(
maquina: $maquina,
ancho: 165.0,
alto: 148.0,
isCosido: true
);
$precio_pliego = PresupuestoService::getPrecioPliego($maquina, $papel);
echo '<pre>';
echo '<p>Para papel impresion: ' . $papel->nombre . '</p>';
echo '';
var_dump($maquina);
var_dump($formas);
var_dump($precio_pliego);
echo '</pre>';
}
}
}
}*/
public static function test2(){
$papel = (object) array('id' => 529, 'gramaje'=>80, "precio_tonelada"=>10);
$maquina = (object) array('alto' => 120, 'ancho'=>200);
echo PresupuestoService::getPrecioPliego($maquina, $papel,2);
}
@ -80,9 +149,10 @@ class PresupuestoService extends BaseService
*
* @return [type]
*/
public function getCostesLinea($uso, $tipo, $datos_cantidad, $maquina, $temp){
public function getCostesLinea($uso, $tipo, $datos_cantidad, $maquina, $temp)
{
$tipo = array_get($args, 'tipo') ;
$tipo = array_get($args, 'tipo');
$tirada = array_get($args, 'tirada');
$merma = array_get($args, 'merma');
$merma_portada = array_get($args, 'merma_portada');
@ -96,5 +166,88 @@ class PresupuestoService extends BaseService
$tarifa = array_get($args, 'tarifa');
$cosido = array_get($args, 'cosido', false);
}
private static function getNumFormasPlanaInterior($maquina, $ancho, $alto, $isCosido)
{
$anchoForCalculo = $isCosido ? $ancho * 2 : $ancho;
// horizontales
$h1 = floor($maquina->ancho_impresion / $anchoForCalculo);
$v1 = floor($maquina->alto_impresion / $alto);
$formas_h = $h1 * $v1; //p1
// verticales
$h2 = floor($maquina->ancho_impresion / $alto);
$v2 = floor($maquina->alto_impresion / $anchoForCalculo);
$formas_v = $h2 * $v2; //p2
// hay que iterar hasta que las formas entren o el num_formas sean ==0
// se checkea que entran en el numero de calles
// se obtiene la configuracion de las calles para esa maquina
$good_configuration = false;
do {
$num_formas = ($formas_h > $formas_v) ? $formas_h : $formas_v;
$num_formas = $isCosido ? $num_formas * 2 : $num_formas;
// solo hay calles para 2 formas o mas
if ((($formas_h > $formas_v) ? $h1 : $h2) > 1) {
var_dump($formas_v);
var_dump($formas_h);
var_dump($h1);
var_dump(($formas_h > $formas_v));
$calles = (new \App\Models\Configuracion\MaquinasCallesModel())->getCallesForMaquina($maquina->maquina_id, ($formas_h > $formas_v) ? $h1 : $h2)[0];
// se calcula el tamaño necesario para el numero de formas + el numero de calles internas
$size_needed = (($formas_h > $formas_v) ? $anchoForCalculo : $alto) * (($formas_h > $formas_v) ? $h1 : $h2) +
((($formas_h > $formas_v) ? $h1 : $h2) - 1) * $calles->internas;
// si el tamaño calculado entra en el area de impresion
if ($size_needed <= $maquina->ancho_impresion)
$good_configuration = true;
// en caso contrario se resta una forma donde corresponda para iterar otra vez
else {
if ($formas_h > $formas_v) {
$formas_h = ($formas_h - 1 > 0) ? $formas_h - 1 : 0;
} else {
$formas_v = ($formas_v - 1 > 0) ? $formas_v - 1 : 0;
}
}
}
// Si solo hay una forma, tiene que entrar en el ancho de impresion
else if ((($formas_h > $formas_v) ? $h1 : $h2) == 1) {
if ((($formas_h > $formas_v) ? $h1 : $h2) < $maquina->ancho_impresion) {
$good_configuration = true;
}
}
} while ($num_formas != 0 && !$good_configuration);
// si no hay formas se devuelve n/a
if ($num_formas == 0) {
$response['num_formas']['posicion_formas'] = 'n/a'; // not available
}
else if ($formas_h > $formas_v) {
$response['num_formas']['posicion_formas'] = 'h';
$response['num_formas']['num_formas_horizontales'] = $h1;
$response['num_formas']['num_formas_verticales'] = $v1;
} else {
$response['num_formas']['posicion_formas'] = 'v';
$response['num_formas']['num_formas_horizontales'] = $h2;
$response['num_formas']['num_formas_verticales'] = $v2;
}
return $response;
}
private static function getPrecioPliego($maquina, $papel_impresion, $paginas)
{
$margen = (new \App\Models\Configuracion\PapelImpresionMargenModel())->getMargenFormPags($papel_impresion->id, $paginas);
if(count($margen)>0){
$peso_por_pliego = $maquina->alto * $maquina->ancho * $papel_impresion->gramaje / 1000000;
$precio_pliego = $papel_impresion->precio_tonelada*(1+(intVal($margen[0]['margen'])/100)) / 1000000 * $peso_por_pliego;
return round($precio_pliego * 1.04, 6);
}
return -1;
}
}