mirror of
https://git.imnavajas.es/jjimenez/safekat.git
synced 2025-07-25 22:52:08 +00:00
trabajando en preciopliego
This commit is contained in:
@ -18,5 +18,10 @@ class Test extends BaseController
|
|||||||
{
|
{
|
||||||
PresupuestoService::test();
|
PresupuestoService::test();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function pruebaJJO()
|
||||||
|
{
|
||||||
|
PresupuestoService::test2();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -349,7 +349,8 @@ class MaquinaModel extends \App\Models\GoBaseModel
|
|||||||
->distinct('t1.id')
|
->distinct('t1.id')
|
||||||
->select(
|
->select(
|
||||||
"t1.id AS maquina_id, t1.nombre AS maquina, t1.ancho_impresion AS ancho_impresion,
|
"t1.id AS maquina_id, t1.nombre AS maquina, t1.ancho_impresion AS ancho_impresion,
|
||||||
t1.alto_impresion AS alto_impresion, t1.is_rotativa AS is rotativa"
|
t1.alto_impresion AS alto_impresion, t1.ancho AS ancho, t1.alto AS alto,
|
||||||
|
t1.is_rotativa AS is rotativa"
|
||||||
)
|
)
|
||||||
->join("lg_maquinas_tarifas_impresion t2", "t1.id = t2.maquina_id", "left")
|
->join("lg_maquinas_tarifas_impresion t2", "t1.id = t2.maquina_id", "left")
|
||||||
->join("lg_maquina_papel_impresion t3", "t1.id = t3.maquina_id", "left")
|
->join("lg_maquina_papel_impresion t3", "t1.id = t3.maquina_id", "left")
|
||||||
|
|||||||
@ -86,6 +86,23 @@ class MaquinasCallesModel extends \App\Models\GoBaseModel
|
|||||||
->groupEnd();
|
->groupEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getCallesForMaquina($maquina_id=-1, $num_formas = 0)
|
||||||
|
{
|
||||||
|
$builder = $this->db
|
||||||
|
->table($this->table . " t1")
|
||||||
|
->select(
|
||||||
|
"t1.formas AS formas,
|
||||||
|
t1.internas AS internas, t1.externas AS externas,"
|
||||||
|
);
|
||||||
|
|
||||||
|
//JJO
|
||||||
|
$builder->where('t1.maquina_id', $maquina_id);
|
||||||
|
$builder->where('t1.formas', $num_formas);
|
||||||
|
$builder->where("t1.is_deleted", 0);
|
||||||
|
|
||||||
|
return $builder->get()->getResultObject();
|
||||||
|
}
|
||||||
|
|
||||||
public function checkDuplicatedFormas($data = [], $id = null){
|
public function checkDuplicatedFormas($data = [], $id = null){
|
||||||
|
|
||||||
helper('general');
|
helper('general');
|
||||||
|
|||||||
@ -1,4 +1,5 @@
|
|||||||
<?php
|
<?php
|
||||||
|
|
||||||
namespace App\Models\Configuracion;
|
namespace App\Models\Configuracion;
|
||||||
|
|
||||||
class PapelImpresionMargenModel extends \App\Models\GoBaseModel
|
class PapelImpresionMargenModel extends \App\Models\GoBaseModel
|
||||||
@ -92,21 +93,22 @@ class PapelImpresionMargenModel extends \App\Models\GoBaseModel
|
|||||||
return empty($search)
|
return empty($search)
|
||||||
? $builder
|
? $builder
|
||||||
: $builder
|
: $builder
|
||||||
->groupStart()
|
->groupStart()
|
||||||
->like("t1.paginas_min", $search)
|
->like("t1.paginas_min", $search)
|
||||||
->orLike("t1.paginas_max", $search)
|
->orLike("t1.paginas_max", $search)
|
||||||
->orLike("t1.margen", $search)
|
->orLike("t1.margen", $search)
|
||||||
->orLike("t1.paginas_min", $search)
|
->orLike("t1.paginas_min", $search)
|
||||||
->orLike("t1.paginas_max", $search)
|
->orLike("t1.paginas_max", $search)
|
||||||
->orLike("t1.margen", $search)
|
->orLike("t1.margen", $search)
|
||||||
->groupEnd();
|
->groupEnd();
|
||||||
}
|
}
|
||||||
|
|
||||||
public function checkIntervals($data = [], $id_linea = null, $papel_impresion_id = null){
|
public function checkIntervals($data = [], $id_linea = null, $papel_impresion_id = null)
|
||||||
|
{
|
||||||
|
|
||||||
helper('general');
|
helper('general');
|
||||||
|
|
||||||
if(floatval($data["paginas_min"])>= floatval($data["paginas_max"])){
|
if (floatval($data["paginas_min"]) >= floatval($data["paginas_max"])) {
|
||||||
return lang('PapelImpresionMargenes.validation.error_paginas_range');
|
return lang('PapelImpresionMargenes.validation.error_paginas_range');
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -119,17 +121,38 @@ class PapelImpresionMargenModel extends \App\Models\GoBaseModel
|
|||||||
|
|
||||||
|
|
||||||
foreach ($rows as $row) {
|
foreach ($rows as $row) {
|
||||||
if (!is_null($id_linea)){
|
if (!is_null($id_linea)) {
|
||||||
if($row->id == $id_linea){
|
if ($row->id == $id_linea) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if(check_overlap(floatval($data["paginas_min"]), floatval($data["paginas_max"]),
|
if (check_overlap(
|
||||||
$row->paginas_min, $row->paginas_max)){
|
floatval($data["paginas_min"]),
|
||||||
return lang('PapelImpresionMargenes.validation.error_paginas_overlap');
|
floatval($data["paginas_max"]),
|
||||||
|
$row->paginas_min,
|
||||||
|
$row->paginas_max
|
||||||
|
)) {
|
||||||
|
return lang('PapelImpresionMargenes.validation.error_paginas_overlap');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function getMargenFormPags($papel_impresion_id = -1, $num_paginas = 0)
|
||||||
|
{
|
||||||
|
$builder = $this->db
|
||||||
|
->table($this->table . " t1")
|
||||||
|
->select(
|
||||||
|
"t1.margen AS margen"
|
||||||
|
);
|
||||||
|
//JJO
|
||||||
|
$builder->where('papel_impresion_id', $papel_impresion_id);
|
||||||
|
$builder->where("t1.is_deleted", 0);
|
||||||
|
$builder->where("t1.paginas_min <=", $num_paginas);
|
||||||
|
$builder->where("t1.paginas_max >=", $num_paginas);
|
||||||
|
|
||||||
|
|
||||||
|
return $builder->get()->getResultArray();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@ -2,16 +2,16 @@
|
|||||||
|
|
||||||
namespace App\Services;
|
namespace App\Services;
|
||||||
|
|
||||||
use App\Controllers\Servicios\Maquetacion;
|
|
||||||
use CodeIgniter\Config\BaseService;
|
use CodeIgniter\Config\BaseService;
|
||||||
|
|
||||||
use App\Models\Configuracion\MaquinaModel;
|
|
||||||
use App\Models\Configuracion\PapelImpresionModel;
|
|
||||||
|
|
||||||
class PresupuestoService extends BaseService
|
class PresupuestoService extends BaseService
|
||||||
{
|
{
|
||||||
|
|
||||||
public static function test(){
|
public static function test()
|
||||||
|
{
|
||||||
$uso = 'interior';
|
$uso = 'interior';
|
||||||
$tipo = 'negro';
|
$tipo = 'negro';
|
||||||
$cantidad = (object)array(
|
$cantidad = (object)array(
|
||||||
@ -22,7 +22,7 @@ class PresupuestoService extends BaseService
|
|||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
$maquina_model = new MaquinaModel();
|
$maquina_model = new \App\Models\Configuracion\MaquinaModel();
|
||||||
|
|
||||||
|
|
||||||
$opciones_papel = array(
|
$opciones_papel = array(
|
||||||
@ -31,13 +31,16 @@ class PresupuestoService extends BaseService
|
|||||||
'sobrecubierta' => 0,
|
'sobrecubierta' => 0,
|
||||||
'rotativa' => 0,
|
'rotativa' => 0,
|
||||||
);
|
);
|
||||||
$papelimpresionmodel = new PapelImpresionModel();
|
$papelimpresionmodel = new \App\Models\Configuracion\PapelImpresionModel();
|
||||||
|
|
||||||
|
echo 'Papeles impresion con gramaje=90';
|
||||||
|
|
||||||
$papeles = $papelimpresionmodel->getIdPapelesImpresionForPresupuesto(
|
$papeles = $papelimpresionmodel->getIdPapelesImpresionForPresupuesto(
|
||||||
papel_generico_id: 4,
|
papel_generico_id: 4,
|
||||||
gramaje: 70,
|
gramaje: 90,
|
||||||
options: $opciones_papel
|
options: $opciones_papel
|
||||||
);
|
);
|
||||||
foreach($papeles as $papel){
|
foreach ($papeles as $papel) {
|
||||||
echo '-------------------------------';
|
echo '-------------------------------';
|
||||||
$maquinas = $maquina_model->getMaquinaImpresionForPresupuesto(
|
$maquinas = $maquina_model->getMaquinaImpresionForPresupuesto(
|
||||||
is_rotativa: $papel->rotativa,
|
is_rotativa: $papel->rotativa,
|
||||||
@ -50,9 +53,75 @@ class PresupuestoService extends BaseService
|
|||||||
var_dump($maquinas);
|
var_dump($maquinas);
|
||||||
echo '</pre>';
|
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]
|
* @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');
|
$tirada = array_get($args, 'tirada');
|
||||||
$merma = array_get($args, 'merma');
|
$merma = array_get($args, 'merma');
|
||||||
$merma_portada = array_get($args, 'merma_portada');
|
$merma_portada = array_get($args, 'merma_portada');
|
||||||
@ -96,5 +166,88 @@ class PresupuestoService extends BaseService
|
|||||||
$tarifa = array_get($args, 'tarifa');
|
$tarifa = array_get($args, 'tarifa');
|
||||||
$cosido = array_get($args, 'cosido', false);
|
$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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user